MCPcopy
hub / github.com/udecode/plate / createEditor

Function createEditor

packages/slate/src/create-editor.ts:149–353  ·  view source on GitHub ↗
({
  children,
  selection,
}: {
  children?: V;
  selection?: Editor['selection'];
} = {})

Source from the content-addressed store, hash-verified

147 };
148
149export 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),

Callers 15

createPlateEditorFunction · 0.90
createStaticEditorFunction · 0.90
isType.spec.tsxFile · 0.90
withEditorRootFunction · 0.90
createSlateEditorFunction · 0.90
withSlate.spec.tsFile · 0.90

Calls 4

bindFirstFunction · 0.90
syncLegacyMethodsFunction · 0.90
createSlateEditorFunction · 0.85
noopFunction · 0.70

Tested by 5

withEditorRootFunction · 0.72
createHistoryEditorFunction · 0.72
createHistoryEditorFunction · 0.72
createNestedEditorFunction · 0.72
createTestEditorFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…