({
children,
selection,
}: {
children?: V;
selection?: Editor['selection'];
} = {})
| 147 | }; |
| 148 | |
| 149 | export const createEditor = <V extends Value>({ |
| 150 | children, |
| 151 | selection, |
| 152 | }: { |
| 153 | children?: V; |
| 154 | selection?: Editor['selection']; |
| 155 | } = {}) => { |
| 156 | const editor = createSlateEditor() as any as Editor & LegacyEditorMethods; |
| 157 | |
| 158 | if (children) { |
| 159 | editor.children = children; |
| 160 | } |
| 161 | if (selection) { |
| 162 | editor.selection = selection; |
| 163 | } |
| 164 | |
| 165 | Object.assign(editor, { |
| 166 | apply: bindFirst(apply, editor as any), |
| 167 | isElementReadOnly: editor.isElementReadOnly, |
| 168 | isInline: editor.isInline, |
| 169 | isSelectable: editor.isSelectable, |
| 170 | isVoid: editor.isVoid, |
| 171 | markableVoid: editor.markableVoid, |
| 172 | onChange: editor.onChange, |
| 173 | }); |
| 174 | |
| 175 | Object.assign(editor, { |
| 176 | addMark: bindFirst(addMark, editor), |
| 177 | deleteBackward: bindFirst(deleteBackward, editor), |
| 178 | deleteForward: bindFirst(deleteForward, editor), |
| 179 | deleteFragment: bindFirst(deleteFragment, editor), |
| 180 | getDirtyPaths: bindFirst(getDirtyPaths, editor as any), |
| 181 | getFragment: bindFirst(getFragment, editor), |
| 182 | insertBreak: bindFirst(insertBreak, editor), |
| 183 | insertFragment: bindFirst(insertFragment, editor), |
| 184 | insertNode: bindFirst(insertNode, editor), |
| 185 | insertSoftBreak: bindFirst(insertSoftBreak, editor as any), |
| 186 | insertText: bindFirst(insertText, editor), |
| 187 | normalizeNode: bindFirst(normalizeNode, editor as any), |
| 188 | removeMark: bindFirst(removeEditorMark, editor as any), |
| 189 | shouldNormalize: bindFirst(shouldNormalize, editor as any), |
| 190 | }); |
| 191 | |
| 192 | Object.assign(editor, { |
| 193 | above: bindFirst(above, editor), |
| 194 | after: bindFirst(getPointAfter, editor), |
| 195 | before: bindFirst(getPointBefore, editor), |
| 196 | collapse: bindFirst(collapseSelection, editor), |
| 197 | delete: bindFirst(deleteText, editor), |
| 198 | deselect: bindFirst(deselect, editor), |
| 199 | deselectDOM: bindFirst(deselectDOM, editor), |
| 200 | edges: bindFirst(getEdgePoints, editor), |
| 201 | elementReadOnly: bindFirst(isElementReadOnly, editor), |
| 202 | end: bindFirst(getEndPoint, editor), |
| 203 | first: bindFirst(getFirstNode, editor), |
| 204 | fragment: bindFirst(getFragment, editor), |
| 205 | getMarks: bindFirst(getMarks, editor), |
| 206 | hasBlocks: bindFirst(hasBlocks, editor), |
searching dependent graphs…