Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Sep 17, 2023
1 parent 2a4fc79 commit 30c1546
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .changeset/core-major.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
- [**Breaking**] Remove `firstChildren` prop from `PlateContent`. Render instead these components before `PlateContent`.
- [**Breaking**] Remove `editableRef` prop from `PlateContent`. Use `ref` instead.
- [**Breaking**] Remove `withPlateProvider`.
- [**Breaking**] Rename `usePlate` to `usePlateActions`.
- [**Breaking**] Rename `usePlateEditorRef` to `useEditorRef`.
- [**Breaking**] Rename `usePlateEditorState` to `useEditorState`.
- [**Breaking**] Rename `usePlateReadOnly` to `useEditorReadOnly`. This hook can be used below `Plate` while `useReadOnly` can only be used in node components.
Expand All @@ -37,4 +36,4 @@
- Add `useEditorVersion` hook. Version incremented on each editor change.
- Add `useSelectionVersion` hook. Version incremented on each selection change.
- Fix `editor.reset` should now reset the editor without mutating the ref so it does not remount `PlateContent`. Default is using `resetEditor`. If you need to replace the editor ref, use `useReplaceEditor`.
- [Type] Remove generic from `TEditableProps`, `RenderElementFn`
- [Type] Remove generic from `TEditableProps`, `RenderElementFn`, `RenderAfterEditable`
4 changes: 2 additions & 2 deletions apps/www/content/docs/accessing-editor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ const CustomEffect = () => {

export default () => (
<Plate>
<PlateContent />

<CustomEffect />

<PlateContent />
</Plate>
);
```
Expand Down
67 changes: 32 additions & 35 deletions apps/www/content/docs/api/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Hook to get the element from a node component.
<APIItem name="pluginKey" type="string" optional>
The plugin key.

- **Default:** `SCOPE_ELEMENT`.
- **Default:** the closest element key.

</APIItem>
</APIParameters>
Expand All @@ -327,44 +327,15 @@ The value of the element as a TElement.

### useEditorRef

Get the Slate editor reference.
Get the Slate editor reference without re-rendering.

- Does not re-render on editor change.
- Does not support nested editors.
- Should be used inside `Plate`.

<APIReturns>

A `PlateEditor` object, which is the Slate editor.

</APIReturns>

### useEditorState

Get the Slate editor reference.

- Re-renders on editor change.
- Does not support nested editors.
- Should be used inside `Plate`.

<APIReturns>

A `PlateEditor` object, which is the Slate editor.

</APIReturns>

### useEditorRef

Get the Slate editor reference.

- Does not re-render on editor change.
- Supports nested editors.
- Should be used inside `Plate`.
- Note the reference does not change when the editor changes.

<APIParameters>
<APIItem name="id" type="PlateId" optional>
The ID of the plate editor. Useful only when nesting editors.
The ID of the plate editor. Useful only when nesting editors. Default is using the closest editor id.
</APIItem>
</APIParameters>
<APIReturns>
Expand All @@ -375,7 +346,7 @@ A `PlateEditor` object, which is the Slate editor.

### useEditorState

Get the Slate editor reference which .
Get the Slate editor reference with re-rendering.

- Re-renders on editor change.
- Supports nested editors.
Expand All @@ -384,7 +355,7 @@ Get the Slate editor reference which .

<APIParameters>
<APIItem name="id" type="PlateId" optional>
The ID of the plate editor.
The ID of the plate editor. Default is using the closest editor id.
</APIItem>
</APIParameters>
<APIReturns>
Expand All @@ -410,7 +381,7 @@ The `readOnly` state of the editor.

### useEditorSelection

Get the editor's selection which is updated on each editor change.
Get the editor's selection. Memoized so it does not re-render if the range is the same.

<APIParameters>
<APIItem name="id" type="PlateId" optional>
Expand All @@ -419,6 +390,28 @@ Get the editor's selection which is updated on each editor change.
</APIParameters>
<APIReturns>The current selection in the editor.</APIReturns>

### useEditorVersion

Get the version of the editor value. That version is incremented on each editor change.

<APIParameters>
<APIItem name="id" type="PlateId" optional>
The ID of the plate editor.
</APIItem>
</APIParameters>
<APIReturns>The current version of the editor value.</APIReturns>

### useSelectionVersion

Get the version of the editor selection. That version is incremented on each selection change (the range being different).

<APIParameters>
<APIItem name="id" type="PlateId" optional>
The ID of the plate editor.
</APIItem>
</APIParameters>
<APIReturns>The current version of the editor selection.</APIReturns>

## Core plugins

### createDeserializeAstPlugin
Expand Down Expand Up @@ -449,6 +442,10 @@ Creates a plugin that merges and registers all the inline types and void types f

Creates a plugin that overrides the default `insertData` function in the editor, which is called when data is being pasted or dragged into the editor.

### createLengthPlugin

Creates a plugin that enforces a maximum length for the editor.

### createNodeFactoryPlugin

Creates a plugin that overrides the default `blockFactory` and `childrenFactory` functions in the editor. These functions are used to generate the default blocks and children for the editor.
Expand Down
Loading

0 comments on commit 30c1546

Please sign in to comment.