From fa8e0c7efd5b566cbb44d52370568b25e1d8132b Mon Sep 17 00:00:00 2001 From: zbeyens Date: Mon, 2 Sep 2024 14:45:31 +0200 Subject: [PATCH 1/6] fix plugin.node.component --- .changeset/sour-beds-sort.md | 5 +++++ packages/core/src/lib/utils/resolvePlugin.ts | 4 ++++ packages/core/src/lib/utils/resolvePlugins.ts | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/sour-beds-sort.md diff --git a/.changeset/sour-beds-sort.md b/.changeset/sour-beds-sort.md new file mode 100644 index 0000000000..fc11e32067 --- /dev/null +++ b/.changeset/sour-beds-sort.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-core': patch +--- + +Fix plugin.node.component should work like plugin.render.node diff --git a/packages/core/src/lib/utils/resolvePlugin.ts b/packages/core/src/lib/utils/resolvePlugin.ts index 5c76fcb7f5..4222b01575 100644 --- a/packages/core/src/lib/utils/resolvePlugin.ts +++ b/packages/core/src/lib/utils/resolvePlugin.ts @@ -77,6 +77,10 @@ export const resolvePlugin =

( if (plugin.plugins) { plugin.plugins = plugin.plugins.map((p) => resolvePlugin(editor, p)); } + // TODO React + if ((plugin as any).node?.component) { + (plugin as any).render.node = (plugin as any).node.component; + } validatePlugin(editor, plugin); diff --git a/packages/core/src/lib/utils/resolvePlugins.ts b/packages/core/src/lib/utils/resolvePlugins.ts index 897218aa19..7e4c9a8e8d 100644 --- a/packages/core/src/lib/utils/resolvePlugins.ts +++ b/packages/core/src/lib/utils/resolvePlugins.ts @@ -319,11 +319,13 @@ export const resolvePluginOverrides = (editor: SlateEditor) => { // TODO react if ( componentOverrides[p.key] && - (!(p as any).render.node || + ((!(p as any).render.node && !(p as any).node.component) || componentOverrides[p.key].priority > p.priority) ) { (updatedPlugin as any).render.node = componentOverrides[p.key].component; + (updatedPlugin as any).node.component = + componentOverrides[p.key].component; } // Apply enabled overrides From 97f322df1389217ca95681ef53e10bb33881b92a Mon Sep 17 00:00:00 2001 From: zbeyens Date: Mon, 2 Sep 2024 15:42:37 +0200 Subject: [PATCH 2/6] fix --- packages/core/src/lib/utils/resolvePlugin.ts | 3 +++ .../react/plugin/createPlatePlugin.spec.ts | 20 +++++++++++++++++++ .../core/src/react/plugin/toPlatePlugin.ts | 5 ++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/core/src/lib/utils/resolvePlugin.ts b/packages/core/src/lib/utils/resolvePlugin.ts index 4222b01575..a26db685c9 100644 --- a/packages/core/src/lib/utils/resolvePlugin.ts +++ b/packages/core/src/lib/utils/resolvePlugin.ts @@ -81,6 +81,9 @@ export const resolvePlugin =

( if ((plugin as any).node?.component) { (plugin as any).render.node = (plugin as any).node.component; } + if ((plugin as any).render?.node) { + (plugin as any).node.component = (plugin as any).render.node; + } validatePlugin(editor, plugin); diff --git a/packages/core/src/react/plugin/createPlatePlugin.spec.ts b/packages/core/src/react/plugin/createPlatePlugin.spec.ts index 57e50e345c..a5ac84cfe1 100644 --- a/packages/core/src/react/plugin/createPlatePlugin.spec.ts +++ b/packages/core/src/react/plugin/createPlatePlugin.spec.ts @@ -28,6 +28,26 @@ describe('withComponent method', () => { expect(resolvedPlugin.render.node).not.toBe(OriginalComponent); expect(resolvedPlugin.render.node).toBe(NewComponent); + expect(resolvedPlugin.node.component).not.toBe(OriginalComponent); + expect(resolvedPlugin.node.component).toBe(NewComponent); + }); + + it('should override an existing component with node.component', () => { + const OriginalComponent: NodeComponent = () => null; + const NewComponent: NodeComponent = () => null; + + const basePlugin = createPlatePlugin({ + key: 'testPlugin', + node: { component: OriginalComponent }, + }); + + const pluginWithNewComponent = basePlugin.withComponent(NewComponent); + const resolvedPlugin = resolvePluginTest(pluginWithNewComponent); + + expect(resolvedPlugin.render.node).not.toBe(OriginalComponent); + expect(resolvedPlugin.render.node).toBe(NewComponent); + expect(resolvedPlugin.node.component).not.toBe(OriginalComponent); + expect(resolvedPlugin.node.component).toBe(NewComponent); }); it('extendEditorApi', () => { diff --git a/packages/core/src/react/plugin/toPlatePlugin.ts b/packages/core/src/react/plugin/toPlatePlugin.ts index d5bdbf0790..378e1afc00 100644 --- a/packages/core/src/react/plugin/toPlatePlugin.ts +++ b/packages/core/src/react/plugin/toPlatePlugin.ts @@ -86,7 +86,10 @@ export function toPlatePlugin< }); plugin.withComponent = (component) => { - return plugin.extend({ render: { node: component } }) as any; + return plugin.extend({ + node: { component }, + render: { node: component }, + }) as any; }; if (!extendConfig) return plugin as any; From 182a70056be7c281cae13dba9faa83b43efe703a Mon Sep 17 00:00:00 2001 From: zbeyens Date: Mon, 2 Sep 2024 15:42:51 +0200 Subject: [PATCH 3/6] fix --- .changeset/witty-oranges-punch.md | 5 ++++ .../www/content/docs/components/changelog.mdx | 7 +++++ .../default/floating-toolbar-buttons.json | 2 +- .../playground-floating-toolbar-buttons.tsx | 2 +- .../default/example/playground-demo.tsx | 4 ++- .../plate-ui/floating-toolbar-buttons.tsx | 3 -- .../floating/src/hooks/useFloatingToolbar.ts | 28 +++++++++++-------- .../plate-ui/floating-toolbar-buttons.tsx | 2 +- 8 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 .changeset/witty-oranges-punch.md diff --git a/.changeset/witty-oranges-punch.md b/.changeset/witty-oranges-punch.md new file mode 100644 index 0000000000..0d84a26b29 --- /dev/null +++ b/.changeset/witty-oranges-punch.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-floating': patch +--- + +Fix: add state.showWhenReadOnly prop to show the toolbar when read-only diff --git a/apps/www/content/docs/components/changelog.mdx b/apps/www/content/docs/components/changelog.mdx index bc66c4c788..deb6f59522 100644 --- a/apps/www/content/docs/components/changelog.mdx +++ b/apps/www/content/docs/components/changelog.mdx @@ -8,8 +8,15 @@ Since Plate UI is not a component library, a changelog is maintained here. Use the [CLI](https://platejs.org/docs/components/cli) to install the latest version of the components. +## September 2024 #14 + +### September 10 #14.1 + +- fix `floating-toolbar`: show toolbar when readOnly + ## August 2024 #13 + ### August 27 #13.3 - Migrate to Plate 37 diff --git a/apps/www/public/registry/styles/default/floating-toolbar-buttons.json b/apps/www/public/registry/styles/default/floating-toolbar-buttons.json index 2b8bf5c576..4a7ac94865 100644 --- a/apps/www/public/registry/styles/default/floating-toolbar-buttons.json +++ b/apps/www/public/registry/styles/default/floating-toolbar-buttons.json @@ -4,7 +4,7 @@ ], "files": [ { - "content": "import React from 'react';\n\nimport {\n BoldPlugin,\n CodePlugin,\n ItalicPlugin,\n StrikethroughPlugin,\n UnderlinePlugin,\n} from '@udecode/plate-basic-marks/react';\nimport { useEditorReadOnly } from '@udecode/plate-common/react';\n\nimport { Icons } from '@/components/icons';\n\nimport { MarkToolbarButton } from './mark-toolbar-button';\nimport { MoreDropdownMenu } from './more-dropdown-menu';\nimport { TurnIntoDropdownMenu } from './turn-into-dropdown-menu';\n\nexport function FloatingToolbarButtons() {\n const readOnly = useEditorReadOnly();\n\n return (\n <>\n {!readOnly && (\n <>\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n )}\n\n \n \n );\n}\n", + "content": "import React from 'react';\n\nimport {\n BoldPlugin,\n CodePlugin,\n ItalicPlugin,\n StrikethroughPlugin,\n UnderlinePlugin,\n} from '@udecode/plate-basic-marks/react';\nimport { useEditorReadOnly } from '@udecode/plate-common/react';\n\nimport { Icons } from '@/components/icons';\n\nimport { MarkToolbarButton } from './mark-toolbar-button';\nimport { TurnIntoDropdownMenu } from './turn-into-dropdown-menu';\n\nexport function FloatingToolbarButtons() {\n const readOnly = useEditorReadOnly();\n\n return (\n <>\n {!readOnly && (\n <>\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n )}\n \n );\n}\n", "name": "floating-toolbar-buttons.tsx" } ], diff --git a/apps/www/src/components/plate-ui/playground-floating-toolbar-buttons.tsx b/apps/www/src/components/plate-ui/playground-floating-toolbar-buttons.tsx index 332017e321..c39c4f8d08 100644 --- a/apps/www/src/components/plate-ui/playground-floating-toolbar-buttons.tsx +++ b/apps/www/src/components/plate-ui/playground-floating-toolbar-buttons.tsx @@ -60,7 +60,7 @@ export function PlaygroundFloatingToolbarButtons({ id }: { id?: ValueId }) { {isEnabled('comment', id) && } - + {!readOnly && } ); } diff --git a/apps/www/src/registry/default/example/playground-demo.tsx b/apps/www/src/registry/default/example/playground-demo.tsx index 4b36347b6c..e70b547ac6 100644 --- a/apps/www/src/registry/default/example/playground-demo.tsx +++ b/apps/www/src/registry/default/example/playground-demo.tsx @@ -375,7 +375,9 @@ export default function PlaygroundDemo({ /> {enabled['floating-toolbar'] && ( - + {enabled['floating-toolbar-buttons'] && ( )} diff --git a/apps/www/src/registry/default/plate-ui/floating-toolbar-buttons.tsx b/apps/www/src/registry/default/plate-ui/floating-toolbar-buttons.tsx index 7c1ff6bc27..f3f39e1e5b 100644 --- a/apps/www/src/registry/default/plate-ui/floating-toolbar-buttons.tsx +++ b/apps/www/src/registry/default/plate-ui/floating-toolbar-buttons.tsx @@ -12,7 +12,6 @@ import { useEditorReadOnly } from '@udecode/plate-common/react'; import { Icons } from '@/components/icons'; import { MarkToolbarButton } from './mark-toolbar-button'; -import { MoreDropdownMenu } from './more-dropdown-menu'; import { TurnIntoDropdownMenu } from './turn-into-dropdown-menu'; export function FloatingToolbarButtons() { @@ -47,8 +46,6 @@ export function FloatingToolbarButtons() { )} - - ); } diff --git a/packages/floating/src/hooks/useFloatingToolbar.ts b/packages/floating/src/hooks/useFloatingToolbar.ts index e5e3aa6201..98d5cb6fdb 100644 --- a/packages/floating/src/hooks/useFloatingToolbar.ts +++ b/packages/floating/src/hooks/useFloatingToolbar.ts @@ -5,7 +5,10 @@ import { isSelectionExpanded, mergeProps, } from '@udecode/plate-common'; -import { useEditorSelector } from '@udecode/plate-common/react'; +import { + useEditorReadOnly, + useEditorSelector, +} from '@udecode/plate-common/react'; import { useFocused } from 'slate-react'; import { @@ -17,7 +20,7 @@ import { export type FloatingToolbarState = { floatingOptions?: UseVirtualFloatingOptions; hideToolbar?: boolean; - ignoreReadOnly?: boolean; + showWhenReadOnly?: boolean; }; export const useFloatingToolbarState = ({ @@ -25,13 +28,14 @@ export const useFloatingToolbarState = ({ floatingOptions, focusedEditorId, hideToolbar, - ignoreReadOnly, + showWhenReadOnly, }: { editorId: string; focusedEditorId: null | string; } & FloatingToolbarState) => { const selectionExpanded = useEditorSelector(isSelectionExpanded, []); const selectionText = useEditorSelector(getSelectionText, []); + const readOnly = useEditorReadOnly(); const focused = useFocused(); @@ -57,14 +61,15 @@ export const useFloatingToolbarState = ({ focused, focusedEditorId, hideToolbar, - ignoreReadOnly, mousedown, open, + readOnly, selectionExpanded, selectionText, setMousedown, setOpen, setWaitForCollapsedSelection, + showWhenReadOnly, waitForCollapsedSelection, }; }; @@ -74,20 +79,21 @@ export const useFloatingToolbar = ({ floating, focusedEditorId, hideToolbar, - ignoreReadOnly, mousedown, open, + readOnly, selectionExpanded, selectionText, setMousedown, setOpen, setWaitForCollapsedSelection, + showWhenReadOnly, waitForCollapsedSelection, }: ReturnType) => { // On refocus, the editor keeps the previous selection, // so we need to wait it's collapsed at the new position before displaying the floating toolbar. React.useEffect(() => { - if (!(editorId === focusedEditorId) || ignoreReadOnly) { + if (!(editorId === focusedEditorId)) { setWaitForCollapsedSelection(true); } if (!selectionExpanded) { @@ -96,7 +102,6 @@ export const useFloatingToolbar = ({ }, [ editorId, focusedEditorId, - ignoreReadOnly, selectionExpanded, setWaitForCollapsedSelection, ]); @@ -106,7 +111,6 @@ export const useFloatingToolbar = ({ const mousedown = () => setMousedown(true); document.addEventListener('mouseup', mouseup); - document.addEventListener('mousedown', mousedown); return () => { @@ -122,13 +126,14 @@ export const useFloatingToolbar = ({ !selectionExpanded || !selectionText || (mousedown && !open) || - hideToolbar + hideToolbar || + (readOnly && !showWhenReadOnly) ) { setOpen(false); } else if ( selectionText && selectionExpanded && - !waitForCollapsedSelection + (!waitForCollapsedSelection || readOnly) ) { setOpen(true); } @@ -137,12 +142,13 @@ export const useFloatingToolbar = ({ editorId, focusedEditorId, hideToolbar, - ignoreReadOnly, + showWhenReadOnly, selectionExpanded, selectionText, mousedown, waitForCollapsedSelection, open, + readOnly, ]); const { update } = floating; diff --git a/templates/plate-playground-template/src/components/plate-ui/floating-toolbar-buttons.tsx b/templates/plate-playground-template/src/components/plate-ui/floating-toolbar-buttons.tsx index c17c6615c9..f05f66130f 100644 --- a/templates/plate-playground-template/src/components/plate-ui/floating-toolbar-buttons.tsx +++ b/templates/plate-playground-template/src/components/plate-ui/floating-toolbar-buttons.tsx @@ -53,7 +53,7 @@ export function FloatingToolbarButtons() { - + {!readOnly && } ); } From feaba6973ac7b219b578497b41178e6ca6aeeee4 Mon Sep 17 00:00:00 2001 From: zbeyens Date: Mon, 2 Sep 2024 15:52:51 +0200 Subject: [PATCH 4/6] fix doc --- apps/www/content/docs/autoformat.mdx | 12 +----------- .../content/docs/components/blockquote-element.mdx | 2 +- .../content/docs/components/code-block-element.mdx | 2 +- apps/www/content/docs/components/code-leaf.mdx | 2 +- .../content/docs/components/code-line-element.mdx | 2 +- .../content/docs/components/code-syntax-leaf.mdx | 2 +- .../www/content/docs/components/column-element.mdx | 2 +- .../docs/components/column-group-element.mdx | 2 +- apps/www/content/docs/components/comment-leaf.mdx | 2 +- .../content/docs/components/comments-popover.mdx | 1 - apps/www/content/docs/components/date-element.mdx | 2 +- apps/www/content/docs/components/draggable.mdx | 2 +- .../docs/components/emoji-input-element.mdx | 2 +- .../content/docs/components/excalidraw-element.mdx | 2 +- .../content/docs/components/heading-element.mdx | 2 +- .../www/content/docs/components/highlight-leaf.mdx | 2 +- apps/www/content/docs/components/hr-element.mdx | 2 +- apps/www/content/docs/components/image-element.mdx | 2 +- apps/www/content/docs/components/kbd-leaf.mdx | 2 +- apps/www/content/docs/components/link-element.mdx | 2 +- .../docs/components/link-floating-toolbar.mdx | 2 +- apps/www/content/docs/components/list-element.mdx | 2 +- .../docs/components/media-embed-element.mdx | 2 +- .../content/docs/components/mention-element.mdx | 2 +- .../docs/components/mention-input-element.mdx | 2 +- .../content/docs/components/paragraph-element.mdx | 2 +- .../content/docs/components/table-cell-element.mdx | 2 +- apps/www/content/docs/components/table-element.mdx | 2 +- .../content/docs/components/table-row-element.mdx | 2 +- .../content/docs/components/todo-list-element.mdx | 2 +- .../www/content/docs/components/toggle-element.mdx | 2 +- apps/www/public/registry/index.json | 11 +++++++++++ .../registry/styles/default/date-element.json | 14 ++++++++++++++ apps/www/src/__registry__/index.tsx | 9 +++++++++ apps/www/src/registry/ui.ts | 7 +++++++ 35 files changed, 71 insertions(+), 41 deletions(-) create mode 100644 apps/www/public/registry/styles/default/date-element.json diff --git a/apps/www/content/docs/autoformat.mdx b/apps/www/content/docs/autoformat.mdx index 24e5a97874..299456a16e 100644 --- a/apps/www/content/docs/autoformat.mdx +++ b/apps/www/content/docs/autoformat.mdx @@ -58,32 +58,22 @@ const plugins = [ ### `autoformatRules` - + ### `autoformatBlocks` - - ### `autoformatIndentLists` If using the [Indent List plugin](/docs/indent-list), you can use the following rules: - - ### `autoformatLists` If using the [List plugin](/docs/list), you can use the following rules: - - ### `autoformatMarks` - - ### `autoformatUtils` - - ## API ### AutoformatPlugin diff --git a/apps/www/content/docs/components/blockquote-element.mdx b/apps/www/content/docs/components/blockquote-element.mdx index 573150da8b..f16f06a01e 100644 --- a/apps/www/content/docs/components/blockquote-element.mdx +++ b/apps/www/content/docs/components/blockquote-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/code-block-element.mdx b/apps/www/content/docs/components/code-block-element.mdx index 63ca5db9f6..7a02272741 100644 --- a/apps/www/content/docs/components/code-block-element.mdx +++ b/apps/www/content/docs/components/code-block-element.mdx @@ -63,4 +63,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/code-leaf.mdx b/apps/www/content/docs/components/code-leaf.mdx index 98dd1d7e38..def5247a7f 100644 --- a/apps/www/content/docs/components/code-leaf.mdx +++ b/apps/www/content/docs/components/code-leaf.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/code-line-element.mdx b/apps/www/content/docs/components/code-line-element.mdx index 37379ff681..dab5552a98 100644 --- a/apps/www/content/docs/components/code-line-element.mdx +++ b/apps/www/content/docs/components/code-line-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/code-syntax-leaf.mdx b/apps/www/content/docs/components/code-syntax-leaf.mdx index a71504deba..48cf341a9f 100644 --- a/apps/www/content/docs/components/code-syntax-leaf.mdx +++ b/apps/www/content/docs/components/code-syntax-leaf.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/column-element.mdx b/apps/www/content/docs/components/column-element.mdx index a977fa2ac2..2d8c43f828 100644 --- a/apps/www/content/docs/components/column-element.mdx +++ b/apps/www/content/docs/components/column-element.mdx @@ -62,4 +62,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/column-group-element.mdx b/apps/www/content/docs/components/column-group-element.mdx index 86dacba7da..57057ae451 100644 --- a/apps/www/content/docs/components/column-group-element.mdx +++ b/apps/www/content/docs/components/column-group-element.mdx @@ -64,4 +64,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/comment-leaf.mdx b/apps/www/content/docs/components/comment-leaf.mdx index 499d29ae73..2aae6cf00a 100644 --- a/apps/www/content/docs/components/comment-leaf.mdx +++ b/apps/www/content/docs/components/comment-leaf.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/comments-popover.mdx b/apps/www/content/docs/components/comments-popover.mdx index 8f8b53e031..5fc38ec946 100644 --- a/apps/www/content/docs/components/comments-popover.mdx +++ b/apps/www/content/docs/components/comments-popover.mdx @@ -77,4 +77,3 @@ Update the import paths to match your project setup. - diff --git a/apps/www/content/docs/components/date-element.mdx b/apps/www/content/docs/components/date-element.mdx index bb09b1f636..f7cdaf198c 100644 --- a/apps/www/content/docs/components/date-element.mdx +++ b/apps/www/content/docs/components/date-element.mdx @@ -41,7 +41,7 @@ Copy and paste the following code into your project. - + diff --git a/apps/www/content/docs/components/draggable.mdx b/apps/www/content/docs/components/draggable.mdx index 4d9ed1ed08..951d2ad0b8 100644 --- a/apps/www/content/docs/components/draggable.mdx +++ b/apps/www/content/docs/components/draggable.mdx @@ -106,4 +106,4 @@ import { HTML5Backend } from 'react-dnd-html5-backend'; ## Examples - \ No newline at end of file + \ No newline at end of file diff --git a/apps/www/content/docs/components/emoji-input-element.mdx b/apps/www/content/docs/components/emoji-input-element.mdx index 49a74b1d8c..d660f9babc 100644 --- a/apps/www/content/docs/components/emoji-input-element.mdx +++ b/apps/www/content/docs/components/emoji-input-element.mdx @@ -60,4 +60,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/excalidraw-element.mdx b/apps/www/content/docs/components/excalidraw-element.mdx index 1e58412f56..71ae390f50 100644 --- a/apps/www/content/docs/components/excalidraw-element.mdx +++ b/apps/www/content/docs/components/excalidraw-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/heading-element.mdx b/apps/www/content/docs/components/heading-element.mdx index 8f9da3d56c..7410014254 100644 --- a/apps/www/content/docs/components/heading-element.mdx +++ b/apps/www/content/docs/components/heading-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/highlight-leaf.mdx b/apps/www/content/docs/components/highlight-leaf.mdx index e4c8ca6e9d..c61e57da5d 100644 --- a/apps/www/content/docs/components/highlight-leaf.mdx +++ b/apps/www/content/docs/components/highlight-leaf.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/hr-element.mdx b/apps/www/content/docs/components/hr-element.mdx index c7b3674efb..6d3ddf0aa3 100644 --- a/apps/www/content/docs/components/hr-element.mdx +++ b/apps/www/content/docs/components/hr-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/image-element.mdx b/apps/www/content/docs/components/image-element.mdx index 0232a45a8c..848a0b6d72 100644 --- a/apps/www/content/docs/components/image-element.mdx +++ b/apps/www/content/docs/components/image-element.mdx @@ -68,4 +68,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/kbd-leaf.mdx b/apps/www/content/docs/components/kbd-leaf.mdx index 3d0ba9e427..cf8833e5f6 100644 --- a/apps/www/content/docs/components/kbd-leaf.mdx +++ b/apps/www/content/docs/components/kbd-leaf.mdx @@ -58,4 +58,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/link-element.mdx b/apps/www/content/docs/components/link-element.mdx index 399017dbce..adb031a0ae 100644 --- a/apps/www/content/docs/components/link-element.mdx +++ b/apps/www/content/docs/components/link-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/link-floating-toolbar.mdx b/apps/www/content/docs/components/link-floating-toolbar.mdx index a3eb8d9b54..626bc7053c 100644 --- a/apps/www/content/docs/components/link-floating-toolbar.mdx +++ b/apps/www/content/docs/components/link-floating-toolbar.mdx @@ -71,4 +71,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/list-element.mdx b/apps/www/content/docs/components/list-element.mdx index 7137f83833..cd0c8e24f8 100644 --- a/apps/www/content/docs/components/list-element.mdx +++ b/apps/www/content/docs/components/list-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/media-embed-element.mdx b/apps/www/content/docs/components/media-embed-element.mdx index cf7e408795..665096621d 100644 --- a/apps/www/content/docs/components/media-embed-element.mdx +++ b/apps/www/content/docs/components/media-embed-element.mdx @@ -67,4 +67,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/mention-element.mdx b/apps/www/content/docs/components/mention-element.mdx index a299795bee..52fba89dd1 100644 --- a/apps/www/content/docs/components/mention-element.mdx +++ b/apps/www/content/docs/components/mention-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/mention-input-element.mdx b/apps/www/content/docs/components/mention-input-element.mdx index f2ec269df9..8ea4aff31f 100644 --- a/apps/www/content/docs/components/mention-input-element.mdx +++ b/apps/www/content/docs/components/mention-input-element.mdx @@ -60,4 +60,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/paragraph-element.mdx b/apps/www/content/docs/components/paragraph-element.mdx index eb10fac0c3..9a08453256 100644 --- a/apps/www/content/docs/components/paragraph-element.mdx +++ b/apps/www/content/docs/components/paragraph-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/table-cell-element.mdx b/apps/www/content/docs/components/table-cell-element.mdx index b3bdc4d7ea..00d5be52fc 100644 --- a/apps/www/content/docs/components/table-cell-element.mdx +++ b/apps/www/content/docs/components/table-cell-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/table-element.mdx b/apps/www/content/docs/components/table-element.mdx index 766eed0463..734b727d72 100644 --- a/apps/www/content/docs/components/table-element.mdx +++ b/apps/www/content/docs/components/table-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/table-row-element.mdx b/apps/www/content/docs/components/table-row-element.mdx index 9a65f2a208..531a334ab1 100644 --- a/apps/www/content/docs/components/table-row-element.mdx +++ b/apps/www/content/docs/components/table-row-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/todo-list-element.mdx b/apps/www/content/docs/components/todo-list-element.mdx index 75cb91aa0f..2037005c29 100644 --- a/apps/www/content/docs/components/todo-list-element.mdx +++ b/apps/www/content/docs/components/todo-list-element.mdx @@ -59,4 +59,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/content/docs/components/toggle-element.mdx b/apps/www/content/docs/components/toggle-element.mdx index 17e2003459..f4bfcb4f44 100644 --- a/apps/www/content/docs/components/toggle-element.mdx +++ b/apps/www/content/docs/components/toggle-element.mdx @@ -60,4 +60,4 @@ Update the import paths to match your project setup. - + diff --git a/apps/www/public/registry/index.json b/apps/www/public/registry/index.json index 3e4f813225..d3f60d1c21 100644 --- a/apps/www/public/registry/index.json +++ b/apps/www/public/registry/index.json @@ -181,6 +181,17 @@ "registryDependencies": [], "type": "components:plate-ui" }, + { + "dependencies": [ + "@udecode/plate-date" + ], + "files": [ + "plate-ui/date-element.tsx" + ], + "name": "date-element", + "registryDependencies": [], + "type": "components:plate-ui" + }, { "dependencies": [ "@radix-ui/react-slot" diff --git a/apps/www/public/registry/styles/default/date-element.json b/apps/www/public/registry/styles/default/date-element.json new file mode 100644 index 0000000000..0989040bda --- /dev/null +++ b/apps/www/public/registry/styles/default/date-element.json @@ -0,0 +1,14 @@ +{ + "dependencies": [ + "@udecode/plate-date" + ], + "files": [ + { + "content": "'use client';\n\nimport { cn, withRef } from '@udecode/cn';\nimport { setNodes } from '@udecode/plate-common';\nimport { PlateElement, findNodePath } from '@udecode/plate-common/react';\n\nimport { Calendar } from './calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from './popover';\n\nexport const DateElement = withRef(\n ({ children, className, ...props }, ref) => {\n const { editor, element } = props;\n\n return (\n \n \n \n \n {element.date ? (\n (() => {\n const today = new Date();\n const elementDate = new Date(element.date as string);\n const isToday =\n elementDate.getDate() === today.getDate() &&\n elementDate.getMonth() === today.getMonth() &&\n elementDate.getFullYear() === today.getFullYear();\n\n const isYesterday =\n new Date(\n today.setDate(today.getDate() - 1)\n ).toDateString() === elementDate.toDateString();\n const isTomorrow =\n new Date(\n today.setDate(today.getDate() + 2)\n ).toDateString() === elementDate.toDateString();\n\n if (isToday) return 'Today';\n if (isYesterday) return 'Yesterday';\n if (isTomorrow) return 'Tomorrow';\n\n return elementDate.toLocaleDateString(undefined, {\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n });\n })()\n ) : (\n Pick a date\n )}\n \n \n \n {\n if (!date) return;\n\n setNodes(\n editor,\n { date: date.toDateString() },\n { at: findNodePath(editor, element) }\n );\n }}\n selected={new Date(element.date as string)}\n />\n \n \n {children}\n \n );\n }\n);\n", + "name": "date-element.tsx" + } + ], + "name": "date-element", + "registryDependencies": [], + "type": "components:plate-ui" +} \ No newline at end of file diff --git a/apps/www/src/__registry__/index.tsx b/apps/www/src/__registry__/index.tsx index 387824dab5..3e26e10ffe 100644 --- a/apps/www/src/__registry__/index.tsx +++ b/apps/www/src/__registry__/index.tsx @@ -308,6 +308,15 @@ export const Index: Record = { subcategory: "undefined", component: React.lazy(() => import('@/registry/default/plate-ui/blockquote-element')), }, + 'date-element': { + name: 'date-element', + type: 'components:plate-ui', + registryDependencies: [], + files: ['registry/default/plate-ui/date-element.tsx'], + category: "undefined", + subcategory: "undefined", + component: React.lazy(() => import('@/registry/default/plate-ui/date-element')), + }, 'button': { name: 'button', type: 'components:plate-ui', diff --git a/apps/www/src/registry/ui.ts b/apps/www/src/registry/ui.ts index 40605a5de1..e467c7187b 100644 --- a/apps/www/src/registry/ui.ts +++ b/apps/www/src/registry/ui.ts @@ -133,6 +133,13 @@ export const ui: Registry = [ registryDependencies: [], type: 'components:plate-ui', }, + { + dependencies: ['@udecode/plate-date'], + files: ['plate-ui/date-element.tsx'], + name: 'date-element', + registryDependencies: [], + type: 'components:plate-ui', + }, { dependencies: ['@radix-ui/react-slot'], files: ['plate-ui/button.tsx'], From 2ff8ccc268fc75bb1fb00e48c1c531d5c919d353 Mon Sep 17 00:00:00 2001 From: Ziad Beyens Date: Mon, 2 Sep 2024 15:54:18 +0200 Subject: [PATCH 5/6] Update witty-oranges-punch.md --- .changeset/witty-oranges-punch.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/witty-oranges-punch.md b/.changeset/witty-oranges-punch.md index 0d84a26b29..8a9628efdf 100644 --- a/.changeset/witty-oranges-punch.md +++ b/.changeset/witty-oranges-punch.md @@ -2,4 +2,5 @@ '@udecode/plate-floating': patch --- -Fix: add state.showWhenReadOnly prop to show the toolbar when read-only +- Fixes #3492 +- Add `state.showWhenReadOnly` prop to show the toolbar when read-only From 40621e8595717252bbb919d6c256ca05643d5e3c Mon Sep 17 00:00:00 2001 From: zbeyens Date: Mon, 2 Sep 2024 16:24:45 +0200 Subject: [PATCH 6/6] doc --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 34d6205323..f9098f7194 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -181,7 +181,7 @@ No software is without bugs. If you encounter a problem, please follow these ste ### Reproductions -The best way to help us understand and fix your issue is to provide a minimal reproduction of the problem. You can do this using **[our CodeSandbox](https://codesandbox.io/p/devbox/dgfyh7)**. +The best way to help us understand and fix your issue is to provide a minimal reproduction of the problem. You can do this using **[our CodeSandbox](https://codesandbox.io/p/github/udecode/plate-template/main)**. ### Responding to questions