|
| 1 | +--- |
| 2 | +title: Suggestion |
| 3 | +docs: |
| 4 | + - route: /docs/components/suggestion-leaf |
| 5 | + title: Suggestion Leaf |
| 6 | + - route: /docs/components/suggestion-toolbar-button |
| 7 | + title: Suggestion Toolbar Button |
| 8 | + - route: /docs/components/block-suggestion |
| 9 | + title: Block suggestion |
| 10 | + - route: /docs/components/block-discussion |
| 11 | + title: Block discussion |
| 12 | + - route: /docs/components/suggestion-line-break |
| 13 | + title: Suggestion line break |
| 14 | +--- |
| 15 | + |
| 16 | +<ComponentPreview name="comments-demo" /> |
| 17 | + |
| 18 | +<PackageInfo> |
| 19 | + |
| 20 | +## Features |
| 21 | + |
| 22 | +- Add suggestions as text marks |
| 23 | +- Add block suggestions |
| 24 | +- Track suggestion state and users |
| 25 | +- Undo/redo suggestion changes |
| 26 | +- Note: This is an experimental feature and the API is subject to change. |
| 27 | + |
| 28 | +</PackageInfo> |
| 29 | + |
| 30 | +## Installation |
| 31 | +```bash |
| 32 | +npm install @udecode/plate-suggestion |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +```tsx |
| 38 | +import { SuggestionPlugin } from '@udecode/plate-suggestion/react'; |
| 39 | + |
| 40 | +const editor = createPlateEditor({ |
| 41 | + plugins: [ |
| 42 | + // ...otherPlugins, |
| 43 | + suggestionPlugin.configure({ |
| 44 | + render: { belowNodes: SuggestionBelowNodes as any }, |
| 45 | + }), |
| 46 | + ], |
| 47 | +}); |
| 48 | +``` |
| 49 | +## Keyboard Shortcuts |
| 50 | + |
| 51 | +<KeyTable> |
| 52 | + <KeyTableItem hotkey="Cmd + Shift + S"> |
| 53 | + Add a suggestion on the selected text. |
| 54 | + </KeyTableItem> |
| 55 | +</KeyTable> |
| 56 | + |
| 57 | +## Examples |
| 58 | + |
| 59 | +### Plate UI |
| 60 | + |
| 61 | +Refer to the preview above. |
| 62 | + |
| 63 | +### Plate Plus |
| 64 | + |
| 65 | +<ComponentPreviewPro name="comments-pro" /> |
| 66 | + |
| 67 | +## Plugins |
| 68 | + |
| 69 | +### `SuggestionPlugin` |
| 70 | + |
| 71 | +## API |
| 72 | + |
| 73 | +### `editor.api.suggestion.addSuggestion` |
| 74 | + |
| 75 | +Adds a new suggestion. |
| 76 | + |
| 77 | +<API name="addSuggestion"> |
| 78 | +<APIParameters> |
| 79 | + <APIItem name="value" type="WithPartial<TSuggestion, 'id' | 'userId'>"> |
| 80 | + The suggestion value to add. |
| 81 | + </APIItem> |
| 82 | +</APIParameters> |
| 83 | +</API> |
| 84 | + |
| 85 | +### `editor.api.suggestion.dataList` |
| 86 | + |
| 87 | +Gets an array of suggestion data from a text node. |
| 88 | + |
| 89 | +<API name="dataList"> |
| 90 | +<APIParameters> |
| 91 | + <APIItem name="node" type="TSuggestionText"> |
| 92 | + The suggestion text node. |
| 93 | + </APIItem> |
| 94 | +</APIParameters> |
| 95 | +<APIReturns type="TInlineSuggestionData[]"> |
| 96 | + Array of suggestion data. |
| 97 | +</APIReturns> |
| 98 | +</API> |
| 99 | + |
| 100 | +### `editor.api.suggestion.isBlockSuggestion` |
| 101 | + |
| 102 | +Checks if a node is a block suggestion element. |
| 103 | + |
| 104 | +<API name="isBlockSuggestion"> |
| 105 | +<APIParameters> |
| 106 | + <APIItem name="node" type="TElement"> |
| 107 | + The node to check. |
| 108 | + </APIItem> |
| 109 | +</APIParameters> |
| 110 | +<APIReturns type="node is TSuggestionElement"> |
| 111 | + Whether the node is a block suggestion. |
| 112 | +</APIReturns> |
| 113 | +</API> |
| 114 | + |
| 115 | +### `editor.api.suggestion.node` |
| 116 | + |
| 117 | +Gets a suggestion node entry. |
| 118 | + |
| 119 | +<API name="node"> |
| 120 | +<APIOptions type="EditorNodesOptions & { id?: string; isText?: boolean }" optional> |
| 121 | + Options for finding the node. |
| 122 | +</APIOptions> |
| 123 | +<APIReturns type="NodeEntry<TSuggestionElement | TSuggestionText> | undefined"> |
| 124 | + The suggestion node entry if found. |
| 125 | +</APIReturns> |
| 126 | +</API> |
| 127 | + |
| 128 | +### `editor.api.suggestion.nodeId` |
| 129 | + |
| 130 | +Gets the ID of a suggestion from a node. |
| 131 | + |
| 132 | +<API name="nodeId"> |
| 133 | +<APIParameters> |
| 134 | + <APIItem name="node" type="TElement | TSuggestionText"> |
| 135 | + The node to get ID from. |
| 136 | + </APIItem> |
| 137 | +</APIParameters> |
| 138 | +<APIReturns type="string | undefined"> |
| 139 | + The suggestion ID if found. |
| 140 | +</APIReturns> |
| 141 | +</API> |
| 142 | + |
| 143 | +### `editor.api.suggestion.nodes` |
| 144 | + |
| 145 | +Gets all suggestion node entries matching the options. |
| 146 | + |
| 147 | +<API name="nodes"> |
| 148 | +<APIOptions type="EditorNodesOptions" optional> |
| 149 | + Options for finding the nodes. |
| 150 | +</APIOptions> |
| 151 | +<APIReturns type="NodeEntry<TElement | TSuggestionText>[]"> |
| 152 | + Array of suggestion node entries. |
| 153 | +</APIReturns> |
| 154 | +</API> |
| 155 | + |
| 156 | +### `editor.api.suggestion.removeSuggestion` |
| 157 | + |
| 158 | +Removes a suggestion by ID. |
| 159 | + |
| 160 | +<API name="removeSuggestion"> |
| 161 | +<APIParameters> |
| 162 | + <APIItem name="id" type="string | null"> |
| 163 | + The ID of the suggestion to remove. |
| 164 | + </APIItem> |
| 165 | +</APIParameters> |
| 166 | +</API> |
| 167 | + |
| 168 | +### `editor.api.suggestion.suggestionData` |
| 169 | + |
| 170 | +Gets suggestion data from a node. |
| 171 | + |
| 172 | +<API name="suggestionData"> |
| 173 | +<APIParameters> |
| 174 | + <APIItem name="node" type="TElement | TSuggestionText"> |
| 175 | + The node to get suggestion data from. |
| 176 | + </APIItem> |
| 177 | +</APIParameters> |
| 178 | +<APIReturns type="TInlineSuggestionData | TSuggestionElement['suggestion'] | undefined"> |
| 179 | + The suggestion data if found. |
| 180 | +</APIReturns> |
| 181 | +</API> |
| 182 | + |
| 183 | +### `editor.api.suggestion.updateSuggestion` |
| 184 | + |
| 185 | +Updates a suggestion by ID. |
| 186 | + |
| 187 | +<API name="updateSuggestion"> |
| 188 | +<APIParameters> |
| 189 | + <APIItem name="id" type="string | null"> |
| 190 | + The ID of the suggestion to update. |
| 191 | + </APIItem> |
| 192 | + <APIItem name="value" type="Partial<TSuggestion>"> |
| 193 | + The updated suggestion values. |
| 194 | + </APIItem> |
| 195 | +</APIParameters> |
| 196 | +</API> |
| 197 | + |
| 198 | +### `editor.api.suggestion.withoutSuggestions` |
| 199 | + |
| 200 | +Executes a function with suggestions temporarily disabled. |
| 201 | + |
| 202 | +<API name="withoutSuggestions"> |
| 203 | +<APIParameters> |
| 204 | + <APIItem name="fn" type="() => void"> |
| 205 | + The function to execute. |
| 206 | + </APIItem> |
| 207 | +</APIParameters> |
| 208 | +</API> |
| 209 | + |
| 210 | +## Types |
| 211 | + |
| 212 | +### `TSuggestionText` |
| 213 | + |
| 214 | +Interface for text nodes that can contain suggestions. |
| 215 | + |
| 216 | +<API name="TSuggestionText"> |
| 217 | +<APIAttributes> |
| 218 | + <APIItem name="suggestion" type="boolean" optional> |
| 219 | + Indicates whether this is a suggestion. |
| 220 | + </APIItem> |
| 221 | + <APIItem name="suggestion_<id>" type="TInlineSuggestionData" optional> |
| 222 | + Contains suggestion data. Multiple suggestions can be present in a single text node. |
| 223 | + </APIItem> |
| 224 | +</APIAttributes> |
| 225 | +</API> |
0 commit comments