Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Jan 13, 2025
1 parent 1ed8ce0 commit 887d1bd
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 3 deletions.
49 changes: 49 additions & 0 deletions apps/www/content/docs/en/ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,52 @@ Special undo operation for AI changes:

- Undoes the last operation if it was AI-generated
- Removes the redo stack entry to prevent redoing AI operations

### useAIChatEditor

A hook that creates an editor for AI chat responses, registers it in the AI chat plugin, and deserializes markdown content with block-level memoization.

<APIParameters>
<APIItem name="content" type="string">
The markdown content to deserialize into the editor.
</APIItem>
<APIItem name="options" type="object" optional>
<APISubList>
<APISubListItem parent="options" name="memoize" type="boolean" optional>
Enable block-level memoization with `_memo` property. Defaults to true.
</APISubListItem>
<APISubListItem parent="options" name="parser" type="ParseMarkdownBlocksOptions" optional>
Options for the markdown token parser. Can filter out specific token types.
</APISubListItem>
<APISubListItem parent="options" name="processor" type="(processor: Processor) => Processor" optional>
Function to customize the markdown processor.
</APISubListItem>
<APISubListItem parent="options" name="...editorOptions" type="Partial<CreatePlateEditorOptions>" optional>
Additional options passed to `usePlateEditor`.
</APISubListItem>
</APISubList>
</APIItem>

<APIReturns>
<APIItem type="PlateEditor">
The configured editor instance with deserialized content.
</APIItem>
</APIReturns>

```tsx
const AIChatEditor = ({ content }: { content: string }) => {
const aiEditor = useAIChatEditor(content, {
plugins: [
// Your editor plugins
MarkdownPlugin,
// etc...
],
// Optional markdown parser options
parser: {
exclude: ['space'],
},
});

return <Editor editor={aiEditor} />;
};
```
73 changes: 73 additions & 0 deletions apps/www/content/docs/en/block-selection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ A set of IDs for the currently selected blocks.
- **Default:** `new Set()`
</APIItem>
<APIItem name="anchorId" type="string | null" optional>
(Internal) The ID of the anchor block in the current selection. Used for shift-based selection.
- **Default:** `null`
</APIItem>
<APIItem name="isSelectable" type="(element: TElement, path: Path) => boolean" optional>
Function to determine if a block element is selectable.
- **Default:** `() => true`
</APIItem>
</APIOptions>
### BlockMenuPlugin
Expand Down Expand Up @@ -371,3 +383,64 @@ Returns fragment prop for the currently selected blocks.
### useSelectionArea
A hook that initializes and manages the selection area functionality.
### editor.api.blockSelection.isSelectable
Checks if a block element is selectable.
<APIParameters>
<APIItem name="element" type="TElement">
The block element to check.
</APIItem>
<APIItem name="path" type="Path">
The path to the block element.
</APIItem>
</APIParameters>
<APIReturns>
<APIItem type="boolean">
Returns true if the block is selectable.
</APIItem>
</APIReturns>
### editor.api.blockSelection.moveSelection
Moves the selection up or down to the next selectable block.
<APIParameters>
<APIItem name="direction" type="'up' | 'down'">
The direction to move the selection.
</APIItem>
</APIParameters>
When moving up:
- Gets the previous selectable block from the top-most selected block
- Sets it as the new anchor
- Clears previous selection and selects only this block
When moving down:
- Gets the next selectable block from the bottom-most selected block
- Sets it as the new anchor
- Clears previous selection and selects only this block
### editor.api.blockSelection.shiftSelection
Expands or shrinks the selection based on the anchor block.
<APIParameters>
<APIItem name="direction" type="'up' | 'down'">
The direction to expand/shrink the selection.
</APIItem>
</APIParameters>
For SHIFT + DOWN:
- If anchor is top-most: Expands down by adding block below bottom-most
- Otherwise: Shrinks from top-most (unless top-most is the anchor)
For SHIFT + UP:
- If anchor is bottom-most: Expands up by adding block above top-most
- Otherwise: Shrinks from bottom-most (unless bottom-most is the anchor)
The anchor block always remains selected. If no anchor is set, it defaults to:
- Bottom-most block for SHIFT + UP
- Top-most block for SHIFT + DOWN
6 changes: 3 additions & 3 deletions apps/www/src/registry/default/components/editor/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ const fakeStreamText = ({
// Create 3 blocks with different lengths
const blocks = [
Array.from({ length: chunkCount }, () => ({
delay: faker.number.int({ max: 150, min: 50 }),
delay: faker.number.int({ max: 100, min: 30 }),
texts: faker.lorem.words({ max: 3, min: 1 }) + ' ',
})),
Array.from({ length: chunkCount + 2 }, () => ({
delay: faker.number.int({ max: 150, min: 50 }),
delay: faker.number.int({ max: 100, min: 30 }),
texts: faker.lorem.words({ max: 3, min: 1 }) + ' ',
})),
Array.from({ length: chunkCount + 4 }, () => ({
delay: faker.number.int({ max: 150, min: 50 }),
delay: faker.number.int({ max: 100, min: 30 }),
texts: faker.lorem.words({ max: 3, min: 1 }) + ' ',
})),
];
Expand Down

0 comments on commit 887d1bd

Please sign in to comment.