-
-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fengjue
committed
Mar 24, 2024
1 parent
3dd1934
commit 3374f5a
Showing
20 changed files
with
296 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/www/src/registry/default/plate-ui/indent-todo-toolbar-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
useIndentTodoToolBarButton, | ||
useIndentTodoToolBarButtonState, | ||
} from '@udecode/plate-indent-list'; | ||
import { withRef } from '@udecode/react-utils'; | ||
|
||
import { Icons } from '@/components/icons'; | ||
|
||
import { ToolbarButton } from './toolbar'; | ||
|
||
export const IndentTodoToolbarButton = withRef<typeof ToolbarButton>( | ||
(rest, ref) => { | ||
const state = useIndentTodoToolBarButtonState({ nodeType: 'todo' }); | ||
const { props } = useIndentTodoToolBarButton(state); | ||
|
||
return ( | ||
<ToolbarButton ref={ref} tooltip="Todo" {...props} {...rest}> | ||
<Icons.todo /> | ||
</ToolbarButton> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PlateEditor, someNode, Value } from '@udecode/plate-common'; | ||
|
||
import { | ||
KEY_LIST_CHECKED, | ||
KEY_LIST_STYLE_TYPE, | ||
KEY_TODO_STYLE_TYPE, | ||
} from '../index'; | ||
|
||
export const someIndentTodo = <V extends Value>( | ||
editor: PlateEditor<V>, | ||
type: string | ||
) => { | ||
return someNode(editor, { | ||
at: editor.selection!, | ||
match: (n) => { | ||
const list = n[KEY_LIST_STYLE_TYPE]; | ||
const isHasProperty = n.hasOwnProperty(KEY_LIST_CHECKED); | ||
return n.type === 'p' && isHasProperty && list === KEY_TODO_STYLE_TYPE; | ||
}, | ||
}); | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/indent-list/src/hooks/useIndentTodoToolbarButton.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEditorRef, useEditorSelector } from '@udecode/plate-common'; | ||
|
||
import { ListStyleType, toggleIndentList } from '../index'; | ||
import { someIndentTodo } from './someIndentTodo'; | ||
|
||
export const useIndentTodoToolBarButtonState = ({ | ||
nodeType = ListStyleType.Disc, | ||
}: { nodeType?: string } = {}) => { | ||
const pressed = useEditorSelector( | ||
(editor) => someIndentTodo(editor, nodeType), | ||
[nodeType] | ||
); | ||
return { | ||
pressed, | ||
nodeType, | ||
}; | ||
}; | ||
|
||
export const useIndentTodoToolBarButton = ({ | ||
nodeType, | ||
pressed, | ||
}: ReturnType<typeof useIndentTodoToolBarButtonState>) => { | ||
const editor = useEditorRef(); | ||
return { | ||
props: { | ||
pressed, | ||
onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.preventDefault(); | ||
}, | ||
onClick: () => { | ||
toggleIndentList(editor, { | ||
listStyleType: nodeType, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.