Skip to content

Commit f7f59ef

Browse files
authored
Merge pull request #3616 from udecode/refactor/selection
BlockMenuPlugin
2 parents 62b686d + 344994a commit f7f59ef

File tree

106 files changed

+1473
-1376
lines changed

Some content is hidden

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

106 files changed

+1473
-1376
lines changed

.changeset/afraid-coins-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/plate-ai': patch
3+
---
4+
5+
WIP

.changeset/great-bottles-exist.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@udecode/plate-floating': patch
3+
---
4+
5+
- `getSelectionBoundingClientRect` is now returning the bounding client rect of the editor selection instead of the dom selection. This is more robust for cases like floating toolbar.
6+
- Update floating toolbar position on value change, in addition to selection change.
7+
- Return `clickOutsideRef` from `useFloatingToolbar` so it can be used to close the toolbar when clicking outside of it. Use `ignore-click-outside/toolbar` class to ignore clicks outside of the toolbar.

.changeset/honest-lamps-work.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/slate-react': patch
3+
---
4+
5+
- Add `setNode`

.changeset/lovely-ads-push.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@udecode/plate-selection': minor
3+
---
4+
5+
- Add `useBlockSelectionNodes`, `useBlockSelectionFragment`, `useBlockSelectionFragmentProp`
6+
- `BlockSelectionPlugin`:
7+
- Make `setSelectedIds` options optional
8+
- Rename option `getSelectedBlocks` -> `getNodes`
9+
- Extend api: `duplicate`, `removeNodes`, `select`, `setNodes`, `setTexts`
10+
- Rename `BlockContextMenuPlugin` to `BlockMenuPlugin`
11+
- `BlockMenuPlugin` options:
12+
- `position`
13+
- `openId`
14+
- `BlockMenuPlugin` api:
15+
- `hide`
16+
- `show`
17+
- `showContextMenu`

.changeset/quick-swans-repeat.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@udecode/plate-core': patch
3+
---
4+
5+
`PlateContent`:
6+
7+
- When `disabled=true`, `readOnly` should be `true`
8+
- Add prop `aria-disabled=true` and `data-readonly=true` when `readOnly=true`
9+
- Add class `slate-editor`, `ignore-click-outside/toolbar` (used by floating toolbar)

.changeset/rotten-hornets-fly.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@udecode/plate-utils': patch
3+
---
4+
5+
- Update `useMarkToolbarButton().props.onClick`: focus editor after toggle mark
6+
- Add `useSelectionCollapsed`, `useSelectionExpanded`, `useSelectionWithinBlock`, `useSelectionAcrossBlocks`
7+
- Add `useSelectionFragment`, `useSelectionFragmentProp`

.changeset/serious-baboons-study.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@udecode/slate-utils': patch
3+
---
4+
5+
- Add queries `getBlocks`, `getFragmentProp`, `getSelectionFragment`
6+
- Add transforms `duplicateBlocks`, `removeEmptyPreviousBlock`, `selectNodes`, `setBlockAboveNode`, `setBlockNodes`
7+
- Add utils `unwrapStructuralNodes`

.changeset/sixty-wombats-roll.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/plate-link': patch
3+
---
4+
5+
Floating patch

apps/www/content/docs/api/core.mdx

+85
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,91 @@ Get the version of the editor selection. That version is incremented on each sel
308308
</APIParameters>
309309
<APIReturns>The current version of the editor selection.</APIReturns>
310310

311+
### useSelectionCollapsed
312+
313+
Returns whether the current selection is collapsed (i.e., the selection is a single point).
314+
315+
<APIReturns>
316+
A boolean value indicating if the selection is collapsed.
317+
</APIReturns>
318+
319+
### useSelectionExpanded
320+
321+
Returns whether the current selection is expanded (i.e., the selection has a non-zero range).
322+
323+
<APIReturns>
324+
A boolean value indicating if the selection is expanded.
325+
</APIReturns>
326+
327+
### useSelectionWithinBlock
328+
329+
Returns whether the current selection is within a single block.
330+
331+
<APIReturns>
332+
A boolean value indicating if the selection is within a single block.
333+
</APIReturns>
334+
335+
### useSelectionAcrossBlocks
336+
337+
Returns whether the current selection spans across multiple blocks.
338+
339+
<APIReturns>
340+
A boolean value indicating if the selection spans across multiple blocks.
341+
</APIReturns>
342+
343+
### useSelectionFragment
344+
345+
Returns the fragment of the current selection, optionally unwrapping structural nodes.
346+
347+
<APIParameters>
348+
<APIItem name="options" type="GetSelectionFragmentOptions" optional>
349+
Options for getting the selection fragment.
350+
<APISubList>
351+
<APISubListItem parent="options" name="structuralTypes" type="string[]" optional>
352+
Array of structural types to unwrap from the fragment.
353+
</APISubListItem>
354+
</APISubList>
355+
</APIItem>
356+
</APIParameters>
357+
358+
<APIReturns>
359+
An array of `TElement` representing the fragment of the current selection. Returns an empty array if the selection is not expanded or if no fragment is found.
360+
</APIReturns>
361+
362+
### useSelectionFragmentProp
363+
364+
Returns a prop value derived from the current selection fragment.
365+
366+
<APIParameters>
367+
<APIItem name="options" type="GetSelectionFragmentOptions & GetFragmentPropOptions" optional>
368+
<APISubList>
369+
<APISubListItem parent="options" name="structuralTypes" type="string[]" optional>
370+
Array of structural types to unwrap from the fragment.
371+
</APISubListItem>
372+
<APISubListItem parent="options" name="key" type="string" optional>
373+
The key of the property to extract from each node.
374+
</APISubListItem>
375+
<APISubListItem parent="options" name="defaultValue" type="string" optional>
376+
The default value to return if no valid prop is found.
377+
</APISubListItem>
378+
<APISubListItem parent="options" name="getProp" type="(node: TElement | TText) => any" optional>
379+
Custom function to extract the prop value from a node.
380+
</APISubListItem>
381+
<APISubListItem parent="options" name="mode" type="'all' | 'block' | 'text'" optional>
382+
Determines how to traverse the fragment:
383+
- 'all': Check both block and text nodes
384+
- 'block': Only check block nodes
385+
- 'text': Only check text nodes
386+
Default is 'block'.
387+
</APISubListItem>
388+
</APISubList>
389+
</APIItem>
390+
</APIParameters>
391+
392+
<APIReturns>
393+
A value derived from the fragment nodes, or undefined if no consistent value is found across the specified nodes.
394+
</APIReturns>
395+
311396
## Core plugins
312397

313398
### DebugPlugin

apps/www/content/docs/api/slate-react.mdx

+41
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,44 @@ Find the corresponding documentation in the <Link href="https://docs.slatejs.org
5858
### `toSlatePoint`
5959

6060
### `toSlateRange`
61+
62+
## Transforms
63+
64+
### focusEditorEdge
65+
66+
Focuses the editor at a specified edge (start or end).
67+
68+
<APIParameters>
69+
<APIItem name="editor" type="TEditor">
70+
The editor instance.
71+
</APIItem>
72+
<APIItem name="options" type="object" optional>
73+
<APISubList>
74+
<APISubListItem parent="options" name="edge" type="'start' | 'end'" optional>
75+
The edge to focus on.
76+
- 'start': Focus at the beginning of the editor.
77+
- 'end': Focus at the end of the editor.
78+
Default is 'start'.
79+
</APISubListItem>
80+
</APISubList>
81+
</APIItem>
82+
</APIParameters>
83+
84+
### setNode
85+
86+
Sets properties on a specific node in the editor.
87+
88+
<APIParameters>
89+
<APIItem name="editor" type="TEditor">
90+
The editor instance.
91+
</APIItem>
92+
<APIItem name="node" type="NodeOf<E>">
93+
The node to update.
94+
</APIItem>
95+
<APIItem name="props" type="Partial<TNodeProps<N>>">
96+
The properties to set on the node.
97+
</APIItem>
98+
<APIItem name="options" type="Omit<SetNodesOptions<E>, 'at'>" optional>
99+
Options for setting nodes, excluding the 'at' property.
100+
</APIItem>
101+
</APIParameters>

apps/www/content/docs/api/slate-utils.mdx

+146
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ Returns the block above the specified location.
4545

4646
</APIReturns>
4747

48+
### getBlocks
49+
50+
Retrieves block-level node entries from the editor.
51+
52+
<APIParameters>
53+
<APIItem name="editor" type="TEditor">
54+
The editor to search for block-level nodes.
55+
</APIItem>
56+
<APIItem name="options" type="GetNodeEntriesOptions<E>" optional>
57+
Options for getting node entries.
58+
</APIItem>
59+
</APIParameters>
60+
61+
<APIReturns>
62+
An array of block-level node entries.
63+
</APIReturns>
64+
4865
### getChildren
4966

5067
Returns the children node entries of a node entry.
@@ -79,6 +96,40 @@ Returns the edge blocks above a specified location.
7996
location, or `null` if not found.
8097
</APIReturns>
8198

99+
### getFragmentProp
100+
101+
Retrieves a consistent property value from a fragment of nodes.
102+
103+
<APIParameters>
104+
<APIItem name="fragment" type="TElement[]">
105+
The fragment of nodes to search for the property.
106+
</APIItem>
107+
<APIItem name="options" type="GetFragmentPropOptions" optional>
108+
<APISubList>
109+
<APISubListItem parent="options" name="key" type="string" optional>
110+
The key of the property to extract from each node.
111+
</APISubListItem>
112+
<APISubListItem parent="options" name="defaultValue" type="string" optional>
113+
The default value to return if no valid prop is found.
114+
</APISubListItem>
115+
<APISubListItem parent="options" name="getProp" type="(node: TElement | TText) => any" optional>
116+
Custom function to extract the prop value from a node.
117+
</APISubListItem>
118+
<APISubListItem parent="options" name="mode" type="'all' | 'block' | 'text'" optional>
119+
Determines how to traverse the fragment:
120+
- 'all': Check both block and text nodes
121+
- 'block': Only check block nodes
122+
- 'text': Only check text nodes
123+
Default is 'block'.
124+
</APISubListItem>
125+
</APISubList>
126+
</APIItem>
127+
</APIParameters>
128+
129+
<APIReturns>
130+
The consistent property value found in the fragment, or undefined if no consistent value is found.
131+
</APIReturns>
132+
82133
### getLastChild
83134

84135
Returns the last child of a node or `null` if no children.
@@ -356,6 +407,27 @@ Gets the range from the start of the block above a location to the location.
356407
`undefined` if no such block exists.
357408
</APIReturns>
358409

410+
### getSelectionFragment
411+
412+
Retrieves the fragment of the current selection, optionally unwrapping structural nodes.
413+
414+
<APIParameters>
415+
<APIItem name="editor" type="TEditor">
416+
The editor to get the selection fragment from.
417+
</APIItem>
418+
<APIItem name="options" type="GetSelectionFragmentOptions" optional>
419+
<APISubList>
420+
<APISubListItem parent="options" name="structuralTypes" type="string[]" optional>
421+
Array of structural types to unwrap from the fragment.
422+
</APISubListItem>
423+
</APISubList>
424+
</APIItem>
425+
</APIParameters>
426+
427+
<APIReturns>
428+
An array of `TElement` representing the fragment of the current selection. Returns an empty array if the selection is not expanded or if no fragment is found.
429+
</APIReturns>
430+
359431
### getSelectionText
360432

361433
Gets the selected text from the editor.
@@ -635,6 +707,19 @@ Queries the editor state.
635707

636708
## Transforms
637709

710+
### duplicateBlocks
711+
712+
Duplicates the given blocks and inserts them after the last block in the selection.
713+
714+
<APIParameters>
715+
<APIItem name="editor" type="TEditor">
716+
The editor instance.
717+
</APIItem>
718+
<APIItem name="blocks" type="TNodeEntry[]">
719+
An array of node entries representing the blocks to duplicate.
720+
</APIItem>
721+
</APIParameters>
722+
638723
### insertElements
639724

640725
Inserts nodes at a location in the document.
@@ -750,6 +835,67 @@ Selects the end point of the block above the selection.
750835
</APIItem>
751836
</APIParameters>
752837

838+
### selectNodes
839+
840+
Selects the range encompassing the given nodes.
841+
842+
<APIParameters>
843+
<APIItem name="editor" type="TEditor">
844+
The editor instance.
845+
</APIItem>
846+
<APIItem name="nodes" type="TNodeEntry[]">
847+
An array of node entries to select.
848+
</APIItem>
849+
</APIParameters>
850+
851+
### setBlockAboveNode
852+
853+
Sets properties on the block above the current selection.
854+
855+
<APIParameters>
856+
<APIItem name="editor" type="TEditor">
857+
The editor instance.
858+
</APIItem>
859+
<APIItem name="props" type="Partial<TNodeProps<N>>">
860+
The properties to set on the block.
861+
</APIItem>
862+
<APIItem name="options" type="Omit<SetNodesOptions<E>, 'at'>" optional>
863+
Options for setting nodes, excluding the 'at' property.
864+
</APIItem>
865+
</APIParameters>
866+
867+
### setBlockAboveTexts
868+
869+
Sets properties on the lowest-level nodes within the block above the current selection.
870+
871+
<APIParameters>
872+
<APIItem name="editor" type="TEditor">
873+
The editor instance.
874+
</APIItem>
875+
<APIItem name="props" type="Partial<TNodeProps<N>>">
876+
The properties to set on the text nodes.
877+
</APIItem>
878+
<APIItem name="options" type="Omit<SetNodesOptions<E>, 'at'>" optional>
879+
Options for setting nodes, excluding the 'at' property.
880+
</APIItem>
881+
</APIParameters>
882+
883+
### setBlockNodes
884+
885+
Sets properties on all block nodes that match the given options.
886+
887+
<APIParameters>
888+
<APIItem name="editor" type="TEditor">
889+
The editor instance.
890+
</APIItem>
891+
<APIItem name="props" type="Partial<TNodeProps<N>>">
892+
The properties to set on the matching block nodes.
893+
</APIItem>
894+
<APIItem name="options" type="GetNodeEntriesOptions<E>" optional>
895+
Options for getting node entries to update.
896+
</APIItem>
897+
</APIParameters>
898+
753899
### setMarks
754900

755901
Sets marks to selected text.

0 commit comments

Comments
 (0)