Skip to content

Commit ab6420e

Browse files
authored
Merge pull request #4090 from udecode/feat/below-root-nodes
PlatePlugin: belowRootNodes
2 parents e764d84 + 3bbb0b7 commit ab6420e

File tree

137 files changed

+396
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+396
-532
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@udecode/plate-utils': patch
3+
'@udecode/plate-core': patch
4+
---
5+
6+
Add `belowRootNodes` render option to render content below root element but above children. Similar to `belowNodes` but renders directly in the element rather than wrapping. This is used in `PlateElement` to render the `BlockSelection` component below the root element.

apps/www/content/docs/en/api/core/plate-plugin.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ Renders a component before the Editable component.
165165
<APISubListItem parent="render" name="belowNodes" type="RenderNodeWrapper<WithAnyKey<C>>" optional>
166166
Create a function that generates a React node below all other plugins' node React node, but above their children.
167167
</APISubListItem>
168+
<APISubListItem parent="render" name="belowRootNodes" type="(props: PlateRenderElementProps<TElement, C>) => React.ReactNode" optional>
169+
Renders a component after the direct children of the root element. This differs from `belowNodes` in that it's the direct child of `PlateElement` rather than wrapping the children that could be nested. This is useful when you need components relative to the root element. Note: this is not used in Plate Core but in `PlateElement`. If you're not using `PlateElement`, you'll need to use this plugin field on your own.
170+
</APISubListItem>
168171
<APISubListItem parent="render" name="node" type="NodeComponent" optional>
169172
Renders the node component.
170173
</APISubListItem>

apps/www/content/docs/en/block-selection.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ Style the selection area by adding the `.slate-selection-area` class to your edi
170170
171171
To determine if an element is selected, use `useBlockSelected` hook. You can render a visual indicator around selected blocks using our [BlockSelection](/docs/components/block-selection) component or create your own.
172172
173-
This component should be rendered inside each block element for consistent selection feedback. Plate UI is doing it in [PlateElement](/docs/components/plate-element).
173+
This component should be rendered inside each block element for consistent selection feedback. Plate UI is doing it by configuring the plugin this way:
174+
175+
```tsx
176+
render: {
177+
belowRootNodes: (props) => {
178+
if (!props.className?.includes('slate-selectable')) return null;
179+
180+
return <BlockSelection />;
181+
},
182+
},
183+
```
174184
175185
## Plugins
176186

apps/www/content/docs/en/components/changelog.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ Plate 45 - new comments & suggestions UI
2626
- NEW `block-suggestion`
2727
- NEW `suggestion-leaf`
2828
- NEW `suggestion-line-break`
29+
- Remove `plate-element`, import `PlateElement` from `@udecode/plate/react` instead. Add in `block-selection-plugins`:
30+
```tsx
31+
render: {
32+
belowRootNodes: (props) => {
33+
if (!props.className?.includes('slate-selectable')) return null;
34+
35+
return <BlockSelection />;
36+
},
37+
},
38+
```
2939

3040
### February 3 #19.1
3141

apps/www/public/r/index.json

Lines changed: 23 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
}
5959
],
6060
"name": "blockquote-element",
61-
"registryDependencies": [
62-
"plate-element"
63-
],
61+
"registryDependencies": [],
6462
"type": "registry:ui"
6563
},
6664
{
@@ -102,8 +100,7 @@
102100
],
103101
"name": "code-block-element",
104102
"registryDependencies": [
105-
"command",
106-
"plate-element"
103+
"command"
107104
],
108105
"type": "registry:ui"
109106
},
@@ -165,9 +162,7 @@
165162
}
166163
],
167164
"name": "code-line-element",
168-
"registryDependencies": [
169-
"plate-element"
170-
],
165+
"registryDependencies": [],
171166
"type": "registry:ui"
172167
},
173168
{
@@ -234,8 +229,7 @@
234229
],
235230
"name": "column-element",
236231
"registryDependencies": [
237-
"resizable",
238-
"plate-element"
232+
"resizable"
239233
],
240234
"type": "registry:ui"
241235
},
@@ -270,8 +264,7 @@
270264
"name": "column-group-element",
271265
"registryDependencies": [
272266
"command",
273-
"resizable",
274-
"plate-element"
267+
"resizable"
275268
],
276269
"type": "registry:ui"
277270
},
@@ -363,8 +356,7 @@
363356
],
364357
"name": "date-element",
365358
"registryDependencies": [
366-
"calendar",
367-
"plate-element"
359+
"calendar"
368360
],
369361
"type": "registry:ui"
370362
},
@@ -433,7 +425,6 @@
433425
],
434426
"name": "inline-equation-element",
435427
"registryDependencies": [
436-
"plate-element",
437428
"popover"
438429
],
439430
"type": "registry:ui"
@@ -495,7 +486,6 @@
495486
"name": "emoji-input-element",
496487
"registryDependencies": [
497488
"inline-combobox",
498-
"plate-element",
499489
"use-debounce"
500490
],
501491
"type": "registry:ui"
@@ -519,9 +509,7 @@
519509
}
520510
],
521511
"name": "excalidraw-element",
522-
"registryDependencies": [
523-
"plate-element"
524-
],
512+
"registryDependencies": [],
525513
"type": "registry:ui"
526514
},
527515
{
@@ -579,9 +567,7 @@
579567
}
580568
],
581569
"name": "heading-element",
582-
"registryDependencies": [
583-
"plate-element"
584-
],
570+
"registryDependencies": [],
585571
"type": "registry:ui"
586572
},
587573
{
@@ -639,9 +625,7 @@
639625
}
640626
],
641627
"name": "hr-element",
642-
"registryDependencies": [
643-
"plate-element"
644-
],
628+
"registryDependencies": [],
645629
"type": "registry:ui"
646630
},
647631
{
@@ -681,8 +665,7 @@
681665
"registryDependencies": [
682666
"media-popover",
683667
"caption",
684-
"resizable",
685-
"plate-element"
668+
"resizable"
686669
],
687670
"type": "registry:ui"
688671
},
@@ -774,9 +757,7 @@
774757
}
775758
],
776759
"name": "link-element",
777-
"registryDependencies": [
778-
"plate-element"
779-
],
760+
"registryDependencies": [],
780761
"type": "registry:ui"
781762
},
782763
{
@@ -801,9 +782,7 @@
801782
}
802783
],
803784
"name": "list-element",
804-
"registryDependencies": [
805-
"plate-element"
806-
],
785+
"registryDependencies": [],
807786
"type": "registry:ui"
808787
},
809788
{
@@ -838,8 +817,7 @@
838817
],
839818
"name": "media-audio-element",
840819
"registryDependencies": [
841-
"caption",
842-
"plate-element"
820+
"caption"
843821
],
844822
"type": "registry:ui"
845823
},
@@ -878,8 +856,7 @@
878856
"registryDependencies": [
879857
"media-popover",
880858
"caption",
881-
"resizable",
882-
"plate-element"
859+
"resizable"
883860
],
884861
"type": "registry:ui"
885862
},
@@ -915,8 +892,7 @@
915892
],
916893
"name": "media-file-element",
917894
"registryDependencies": [
918-
"caption",
919-
"plate-element"
895+
"caption"
920896
],
921897
"type": "registry:ui"
922898
},
@@ -948,7 +924,6 @@
948924
],
949925
"name": "media-placeholder-element",
950926
"registryDependencies": [
951-
"plate-element",
952927
"spinner",
953928
"uploadthing"
954929
],
@@ -993,8 +968,7 @@
993968
"registryDependencies": [
994969
"media-popover",
995970
"caption",
996-
"resizable",
997-
"plate-element"
971+
"resizable"
998972
],
999973
"type": "registry:ui"
1000974
},
@@ -1028,7 +1002,6 @@
10281002
],
10291003
"name": "mention-element",
10301004
"registryDependencies": [
1031-
"plate-element",
10321005
"use-mounted"
10331006
],
10341007
"type": "registry:ui"
@@ -1059,8 +1032,7 @@
10591032
],
10601033
"name": "mention-input-element",
10611034
"registryDependencies": [
1062-
"inline-combobox",
1063-
"plate-element"
1035+
"inline-combobox"
10641036
],
10651037
"type": "registry:ui"
10661038
},
@@ -1092,9 +1064,7 @@
10921064
}
10931065
],
10941066
"name": "paragraph-element",
1095-
"registryDependencies": [
1096-
"plate-element"
1097-
],
1067+
"registryDependencies": [],
10981068
"type": "registry:ui"
10991069
},
11001070
{
@@ -1154,7 +1124,6 @@
11541124
"name": "slash-input-element",
11551125
"registryDependencies": [
11561126
"inline-combobox",
1157-
"plate-element",
11581127
"transforms"
11591128
],
11601129
"type": "registry:ui"
@@ -1189,8 +1158,7 @@
11891158
],
11901159
"name": "table-cell-element",
11911160
"registryDependencies": [
1192-
"resizable",
1193-
"plate-element"
1161+
"resizable"
11941162
],
11951163
"type": "registry:ui"
11961164
},
@@ -1230,8 +1198,7 @@
12301198
],
12311199
"name": "table-element",
12321200
"registryDependencies": [
1233-
"dropdown-menu",
1234-
"plate-element"
1201+
"dropdown-menu"
12351202
],
12361203
"type": "registry:ui"
12371204
},
@@ -1262,9 +1229,7 @@
12621229
}
12631230
],
12641231
"name": "table-row-element",
1265-
"registryDependencies": [
1266-
"plate-element"
1267-
],
1232+
"registryDependencies": [],
12681233
"type": "registry:ui"
12691234
},
12701235
{
@@ -1348,8 +1313,7 @@
13481313
],
13491314
"name": "todo-list-element",
13501315
"registryDependencies": [
1351-
"checkbox",
1352-
"plate-element"
1316+
"checkbox"
13531317
],
13541318
"type": "registry:ui"
13551319
},
@@ -1380,8 +1344,7 @@
13801344
],
13811345
"name": "toggle-element",
13821346
"registryDependencies": [
1383-
"button",
1384-
"plate-element"
1347+
"button"
13851348
],
13861349
"type": "registry:ui"
13871350
},
@@ -1880,7 +1843,6 @@
18801843
"name": "block-context-menu",
18811844
"registryDependencies": [
18821845
"calendar",
1883-
"plate-element",
18841846
"context-menu",
18851847
"use-is-touch-device"
18861848
],
@@ -3155,34 +3117,6 @@
31553117
"registryDependencies": [],
31563118
"type": "registry:ui"
31573119
},
3158-
{
3159-
"dependencies": [
3160-
"@udecode/plate-selection"
3161-
],
3162-
"doc": {
3163-
"description": "A base element with block selection support.",
3164-
"docs": [
3165-
{
3166-
"route": "/docs/block-selection"
3167-
}
3168-
],
3169-
"examples": [
3170-
"basic-nodes-demo"
3171-
],
3172-
"label": "New"
3173-
},
3174-
"files": [
3175-
{
3176-
"path": "plate-ui/plate-element.tsx",
3177-
"type": "registry:ui"
3178-
}
3179-
],
3180-
"name": "plate-element",
3181-
"registryDependencies": [
3182-
"block-selection"
3183-
],
3184-
"type": "registry:ui"
3185-
},
31863120
{
31873121
"dependencies": [
31883122
"react-resizable-panels"

apps/www/public/r/styles/default/ai-demo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"path": "components/editor/plugins/editor-plugins.tsx",
39-
"content": "'use client';\n\nimport emojiMartData from '@emoji-mart/data';\nimport { CalloutPlugin } from '@udecode/plate-callout/react';\nimport { DatePlugin } from '@udecode/plate-date/react';\nimport { DocxPlugin } from '@udecode/plate-docx';\nimport { EmojiPlugin } from '@udecode/plate-emoji/react';\nimport {\n FontBackgroundColorPlugin,\n FontColorPlugin,\n FontSizePlugin,\n} from '@udecode/plate-font/react';\nimport { HighlightPlugin } from '@udecode/plate-highlight/react';\nimport { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';\nimport { JuicePlugin } from '@udecode/plate-juice';\nimport { KbdPlugin } from '@udecode/plate-kbd/react';\nimport { ColumnPlugin } from '@udecode/plate-layout/react';\nimport { MarkdownPlugin } from '@udecode/plate-markdown';\nimport { SlashPlugin } from '@udecode/plate-slash-command/react';\nimport { TogglePlugin } from '@udecode/plate-toggle/react';\nimport { TrailingBlockPlugin } from '@udecode/plate-trailing-block';\n\nimport { FixedToolbarPlugin } from '@/components/editor/plugins/fixed-toolbar-plugin';\nimport { FloatingToolbarPlugin } from '@/components/editor/plugins/floating-toolbar-plugin';\n\nimport { aiPlugins } from './ai-plugins';\nimport { alignPlugin } from './align-plugin';\nimport { autoformatPlugin } from './autoformat-plugin';\nimport { basicNodesPlugins } from './basic-nodes-plugins';\nimport { blockMenuPlugins } from './block-menu-plugins';\nimport { commentsPlugin } from './comments-plugin';\nimport { cursorOverlayPlugin } from './cursor-overlay-plugin';\nimport { deletePlugins } from './delete-plugins';\nimport { dndPlugins } from './dnd-plugins';\nimport { equationPlugins } from './equation-plugins';\nimport { exitBreakPlugin } from './exit-break-plugin';\nimport { indentListPlugins } from './indent-list-plugins';\nimport { lineHeightPlugin } from './line-height-plugin';\nimport { linkPlugin } from './link-plugin';\nimport { mediaPlugins } from './media-plugins';\nimport { mentionPlugin } from './mention-plugin';\nimport { resetBlockTypePlugin } from './reset-block-type-plugin';\nimport { skipMarkPlugin } from './skip-mark-plugin';\nimport { softBreakPlugin } from './soft-break-plugin';\nimport { suggestionPlugin } from './suggestion-plugin';\nimport { tablePlugin } from './table-plugin';\nimport { tocPlugin } from './toc-plugin';\n\nexport const viewPlugins = [\n ...basicNodesPlugins,\n HorizontalRulePlugin,\n linkPlugin,\n DatePlugin,\n mentionPlugin,\n tablePlugin,\n TogglePlugin,\n tocPlugin,\n ...mediaPlugins,\n ...equationPlugins,\n CalloutPlugin,\n ColumnPlugin,\n\n // Marks\n FontColorPlugin,\n FontBackgroundColorPlugin,\n FontSizePlugin,\n HighlightPlugin,\n KbdPlugin,\n skipMarkPlugin,\n\n // Block Style\n alignPlugin,\n ...indentListPlugins,\n lineHeightPlugin,\n\n // Collaboration\n commentsPlugin,\n suggestionPlugin,\n] as const;\n\nexport const editorPlugins = [\n // AI\n ...aiPlugins,\n\n // Nodes\n ...viewPlugins,\n\n // Functionality\n SlashPlugin,\n autoformatPlugin,\n cursorOverlayPlugin,\n ...blockMenuPlugins,\n ...dndPlugins,\n EmojiPlugin.configure({ options: { data: emojiMartData as any } }),\n exitBreakPlugin,\n resetBlockTypePlugin,\n ...deletePlugins,\n softBreakPlugin,\n TrailingBlockPlugin,\n\n // Deserialization\n DocxPlugin,\n MarkdownPlugin.configure({ options: { indentList: true } }),\n JuicePlugin,\n\n // UI\n FixedToolbarPlugin,\n FloatingToolbarPlugin,\n];\n",
39+
"content": "'use client';\n\nimport emojiMartData from '@emoji-mart/data';\nimport { CalloutPlugin } from '@udecode/plate-callout/react';\nimport { DatePlugin } from '@udecode/plate-date/react';\nimport { DocxPlugin } from '@udecode/plate-docx';\nimport { EmojiPlugin } from '@udecode/plate-emoji/react';\nimport {\n FontBackgroundColorPlugin,\n FontColorPlugin,\n FontSizePlugin,\n} from '@udecode/plate-font/react';\nimport { HighlightPlugin } from '@udecode/plate-highlight/react';\nimport { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';\nimport { JuicePlugin } from '@udecode/plate-juice';\nimport { KbdPlugin } from '@udecode/plate-kbd/react';\nimport { ColumnPlugin } from '@udecode/plate-layout/react';\nimport { MarkdownPlugin } from '@udecode/plate-markdown';\nimport { SlashPlugin } from '@udecode/plate-slash-command/react';\nimport { TogglePlugin } from '@udecode/plate-toggle/react';\nimport { TrailingBlockPlugin } from '@udecode/plate-trailing-block';\n\nimport { FixedToolbarPlugin } from '@/components/editor/plugins/fixed-toolbar-plugin';\nimport { FloatingToolbarPlugin } from '@/components/editor/plugins/floating-toolbar-plugin';\nimport { BlockDiscussion } from '@/components/plate-ui/block-discussion';\nimport { SuggestionBelowNodes } from '@/components/plate-ui/suggestion-line-break';\n\nimport { aiPlugins } from './ai-plugins';\nimport { alignPlugin } from './align-plugin';\nimport { autoformatPlugin } from './autoformat-plugin';\nimport { basicNodesPlugins } from './basic-nodes-plugins';\nimport { blockMenuPlugins } from './block-menu-plugins';\nimport { commentsPlugin } from './comments-plugin';\nimport { cursorOverlayPlugin } from './cursor-overlay-plugin';\nimport { deletePlugins } from './delete-plugins';\nimport { dndPlugins } from './dnd-plugins';\nimport { equationPlugins } from './equation-plugins';\nimport { exitBreakPlugin } from './exit-break-plugin';\nimport { indentListPlugins } from './indent-list-plugins';\nimport { lineHeightPlugin } from './line-height-plugin';\nimport { linkPlugin } from './link-plugin';\nimport { mediaPlugins } from './media-plugins';\nimport { mentionPlugin } from './mention-plugin';\nimport { resetBlockTypePlugin } from './reset-block-type-plugin';\nimport { skipMarkPlugin } from './skip-mark-plugin';\nimport { softBreakPlugin } from './soft-break-plugin';\nimport { suggestionPlugin } from './suggestion-plugin';\nimport { tablePlugin } from './table-plugin';\nimport { tocPlugin } from './toc-plugin';\n\nexport const viewPlugins = [\n ...basicNodesPlugins,\n HorizontalRulePlugin,\n linkPlugin,\n DatePlugin,\n mentionPlugin,\n tablePlugin,\n TogglePlugin,\n tocPlugin,\n ...mediaPlugins,\n ...equationPlugins,\n CalloutPlugin,\n ColumnPlugin,\n\n // Marks\n FontColorPlugin,\n FontBackgroundColorPlugin,\n FontSizePlugin,\n HighlightPlugin,\n KbdPlugin,\n skipMarkPlugin,\n\n // Block Style\n alignPlugin,\n ...indentListPlugins,\n lineHeightPlugin,\n\n // Collaboration\n commentsPlugin.configure({\n render: { aboveNodes: BlockDiscussion as any },\n }),\n suggestionPlugin.configure({\n render: { belowNodes: SuggestionBelowNodes as any },\n }),\n] as const;\n\nexport const editorPlugins = [\n // AI\n ...aiPlugins,\n\n // Nodes\n ...viewPlugins,\n\n // Functionality\n SlashPlugin,\n autoformatPlugin,\n cursorOverlayPlugin,\n ...blockMenuPlugins,\n ...dndPlugins,\n EmojiPlugin.configure({ options: { data: emojiMartData as any } }),\n exitBreakPlugin,\n resetBlockTypePlugin,\n ...deletePlugins,\n softBreakPlugin,\n TrailingBlockPlugin,\n\n // Deserialization\n DocxPlugin,\n MarkdownPlugin.configure({ options: { indentList: true } }),\n JuicePlugin,\n\n // UI\n FixedToolbarPlugin,\n FloatingToolbarPlugin,\n];\n",
4040
"type": "registry:example",
4141
"target": "components/editor-plugins.tsx"
4242
}

0 commit comments

Comments
 (0)