From faba38f88e0eca7d9bcf1c66f1920cbbae4d4411 Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Mon, 29 Mar 2021 23:47:34 -0700 Subject: [PATCH] docs: Add sections to Editor documentation --- docs/api/editor.md | 233 ++++++++++++++++++++++++--------------------- 1 file changed, 123 insertions(+), 110 deletions(-) diff --git a/docs/api/editor.md b/docs/api/editor.md index bd423a680..d93d3d05a 100644 --- a/docs/api/editor.md +++ b/docs/api/editor.md @@ -46,19 +46,19 @@ Creates a new, empty `Editor` object. ## Static methods +- [Retrieval methods](#retrieval-methods) +- [Manipulation methods](#manipulation-methods) +- [Check methods](#check-methods) +- [Normalization methods](#normalization-methods) + +### Retrieval methods + ###### `Editor.above(editor: Editor, options?): NodeEntry | undefined` Get the ancestor above a location in the document. Options: `{at?: Location, match?: NodeMatch, mode?: 'highest' | 'lowest', voids?: boolean}` -###### `Editor.addMark(editor: Editor, key: string, value: any): void` - -Add a custom property to the leaf text nodes in the current selection. - -If the selection is currently collapsed, the marks will be added to the -`editor.marks` property instead, and applied when text is inserted next. - ###### `Editor.after(editor: Editor, at: Location, options?): Point | undefined` Get the point after a location. @@ -71,22 +71,6 @@ Get the point before a location. Options: `{distance?: number, unit?: 'offset' | 'character' | 'word' | 'line' | 'block', voids?: boolean}` -###### `Editor.deleteBackward(editor: Editor, options?): void` - -Delete content in the editor backward from the current selection. - -Options: `{unit?: 'character' | 'word' | 'line' | 'block'}` - -###### `Editor.deleteForward(editor: Editor, options?): void` - -Delete content in the editor forward from the current selection. - -Options: `{unit?: 'character' | 'word' | 'line' | 'block'}` - -###### `Editor.deleteFragment(editor: Editor): void` - -Delete the content in the current selection. - ###### `Editor.edges(editor: Editor, at: Location): [Point, Point]` Get the start and end points of a location. @@ -103,76 +87,6 @@ Get the first node at a location. Get the fragment at a location. -###### `Editor.hasBlocks(editor: Editor, element: Element): boolean` - -Check if a node has block children. - -###### `Editor.hasInlines(editor: Editor, element: Element): boolean` - -Check if a node has inline and text children. - -###### `Editor.hasTexts(editor: Editor, element: Element): boolean` - -Check if a node has text children. - -###### `Editor.insertBreak(editor: Editor): void` - -Insert a block break at the current selection. - -###### `Editor.insertFragment(editor: Editor, fragment: Node[]): void` - -Insert a fragment at the current selection. - -If the selection is currently expanded, it will be deleted first. - -###### `Editor.insertNode(editor: Editor, node: Node): void` - -Insert a node at the current selection. - -If the selection is currently expanded, it will be deleted first. - -###### `Editor.insertText(editor: Editor, text: string): void` - -Insert text at the current selection. - -If the selection is currently expanded, it will be deleted first. - -###### `Editor.isBlock(editor: Editor, value: any): value is Element` - -Check if a value is a block `Element` object. - -###### `Editor.isEditor(value: any): value is Editor` - -Check if a value is an `Editor` object. - -###### `Editor.isEnd(editor: Editor, point: Point, at: Location): boolean` - -Check if a point is the end point of a location. - -###### `Editor.isEdge(editor: Editor, point: Point, at: Location): boolean` - -Check if a point is an edge of a location. - -###### `Editor.isEmpty(editor: Editor, element: Element): boolean` - -Check if an element is empty, accounting for void nodes. - -###### `Editor.isInline(editor: Editor, value: any): value is Element` - -Check if a value is an inline `Element` object. - -###### `Editor.isNormalizing(editor: Editor): boolean` - -Check if the editor is currently normalizing after each operation. - -###### `Editor.isStart(editor: Editor, point: Point, at: Location): boolean` - -Check if a point is the start point of a location. - -###### `Editor.isVoid(editor: Editor, value: any): value is Element` - -Check if a value is a void `Element` object. - ###### `Editor.last(editor: Editor, at: Location): NodeEntry` Get the last node at a location. @@ -207,12 +121,6 @@ Iterate through all of the nodes in the Editor. Options: `{at?: Location | Span, match?: NodeMatch, mode?: 'all' | 'highest' | 'lowest', universal?: boolean, reverse?: boolean, voids?: boolean}` -###### `Editor.normalize(editor: Editor, options?): void` - -Normalize any dirty objects in the editor. - -Options: `{force?: boolean}` - ###### `Editor.parent(editor: Editor, at: Location, options?): NodeEntry` Get the parent node of a location. @@ -289,14 +197,6 @@ Options: `{affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null}` Get the set of currently tracked range refs of the editor. -###### `Editor.removeMark(editor: Editor, key: string): void` - -Remove a custom property from all of the leaf text nodes in the current -selection. - -If the selection is currently collapsed, the removal will be stored on -`editor.marks` and applied to the text inserted next. - ###### `Editor.start(editor: Editor, at: Location): Point` Get the start point of a location. @@ -310,17 +210,130 @@ string, regardless of content, unless you pass in true for the voids option Options: : `{voids?: boolean}` +###### `Editor.void(editor: Editor, options?): NodeEntry | undefined` + +Match a void node in the current branch of the editor. + +Options: `{at?: Location, mode?: 'highest' | 'lowest', voids?: boolean}` + +### Manipulation methods + +###### `Editor.addMark(editor: Editor, key: string, value: any): void` + +Add a custom property to the leaf text nodes in the current selection. + +If the selection is currently collapsed, the marks will be added to the +`editor.marks` property instead, and applied when text is inserted next. + +###### `Editor.deleteBackward(editor: Editor, options?): void` + +Delete content in the editor backward from the current selection. + +Options: `{unit?: 'character' | 'word' | 'line' | 'block'}` + +###### `Editor.deleteForward(editor: Editor, options?): void` + +Delete content in the editor forward from the current selection. + +Options: `{unit?: 'character' | 'word' | 'line' | 'block'}` + +###### `Editor.deleteFragment(editor: Editor): void` + +Delete the content in the current selection. + +###### `Editor.insertBreak(editor: Editor): void` + +Insert a block break at the current selection. + +###### `Editor.insertFragment(editor: Editor, fragment: Node[]): void` + +Insert a fragment at the current selection. + +If the selection is currently expanded, it will be deleted first. + +###### `Editor.insertNode(editor: Editor, node: Node): void` + +Insert a node at the current selection. + +If the selection is currently expanded, it will be deleted first. + +###### `Editor.insertText(editor: Editor, text: string): void` + +Insert text at the current selection. + +If the selection is currently expanded, it will be deleted first. + +###### `Editor.removeMark(editor: Editor, key: string): void` + +Remove a custom property from all of the leaf text nodes in the current +selection. + +If the selection is currently collapsed, the removal will be stored on +`editor.marks` and applied to the text inserted next. + ###### `Editor.unhangRange(editor: Editor, range: Range, options?): Range` Convert a range into a non-hanging one. Options: `{voids?: boolean}` -###### `Editor.void(editor: Editor, options?): NodeEntry | undefined` +### Check methods -Match a void node in the current branch of the editor. +###### `Editor.hasBlocks(editor: Editor, element: Element): boolean` -Options: `{at?: Location, mode?: 'highest' | 'lowest', voids?: boolean}` +Check if a node has block children. + +###### `Editor.hasInlines(editor: Editor, element: Element): boolean` + +Check if a node has inline and text children. + +###### `Editor.hasTexts(editor: Editor, element: Element): boolean` + +Check if a node has text children. + +###### `Editor.isBlock(editor: Editor, value: any): value is Element` + +Check if a value is a block `Element` object. + +###### `Editor.isEditor(value: any): value is Editor` + +Check if a value is an `Editor` object. + +###### `Editor.isEnd(editor: Editor, point: Point, at: Location): boolean` + +Check if a point is the end point of a location. + +###### `Editor.isEdge(editor: Editor, point: Point, at: Location): boolean` + +Check if a point is an edge of a location. + +###### `Editor.isEmpty(editor: Editor, element: Element): boolean` + +Check if an element is empty, accounting for void nodes. + +###### `Editor.isInline(editor: Editor, value: any): value is Element` + +Check if a value is an inline `Element` object. + +###### `Editor.isNormalizing(editor: Editor): boolean` + +Check if the editor is currently normalizing after each operation. + +###### `Editor.isStart(editor: Editor, point: Point, at: Location): boolean` + +Check if a point is the start point of a location. + +###### `Editor.isVoid(editor: Editor, value: any): value is Element` + +Check if a value is a void `Element` object. + +### Normalization methods + +###### `Editor.normalize(editor: Editor, options?): void` + +Normalize any dirty objects in the editor. + +Options: `{force?: boolean}` ###### `Editor.withoutNormalizing(editor: Editor, fn: () => void): void`