lexical 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,22 +9,22 @@ import type { EditorConfig, LexicalEditor, Spread } from '../LexicalEditor';
9
9
  import type { DOMConversionMap, DOMExportOutput, NodeKey, SerializedLexicalNode } from '../LexicalNode';
10
10
  import type { GridSelection, NodeSelection, RangeSelection } from '../LexicalSelection';
11
11
  import { LexicalNode } from '../LexicalNode';
12
- export declare type SerializedTextNode = Spread<{
12
+ export type SerializedTextNode = Spread<{
13
13
  detail: number;
14
14
  format: number;
15
15
  mode: TextModeType;
16
16
  style: string;
17
17
  text: string;
18
18
  }, SerializedLexicalNode>;
19
- export declare type TextDetailType = 'directionless' | 'unmergable';
20
- export declare type TextFormatType = 'bold' | 'underline' | 'strikethrough' | 'italic' | 'highlight' | 'code' | 'subscript' | 'superscript';
21
- export declare type TextModeType = 'normal' | 'token' | 'segmented';
22
- export declare type TextMark = {
19
+ export type TextDetailType = 'directionless' | 'unmergable';
20
+ export type TextFormatType = 'bold' | 'underline' | 'strikethrough' | 'italic' | 'highlight' | 'code' | 'subscript' | 'superscript';
21
+ export type TextModeType = 'normal' | 'token' | 'segmented';
22
+ export type TextMark = {
23
23
  end: null | number;
24
24
  id: string;
25
25
  start: null | number;
26
26
  };
27
- export declare type TextMarks = Array<TextMark>;
27
+ export type TextMarks = Array<TextMark>;
28
28
  /** @noInheritDoc */
29
29
  export declare class TextNode extends LexicalNode {
30
30
  __text: string;
@@ -39,18 +39,93 @@ export declare class TextNode extends LexicalNode {
39
39
  static getType(): string;
40
40
  static clone(node: TextNode): TextNode;
41
41
  constructor(text: string, key?: NodeKey);
42
+ /**
43
+ * Returns a 32-bit integer that represents the TextFormatTypes currently applied to the
44
+ * TextNode. You probably don't want to use this method directly - consider using TextNode.hasFormat instead.
45
+ *
46
+ * @returns a number representing the format of the text node.
47
+ */
42
48
  getFormat(): number;
49
+ /**
50
+ * Returns a 32-bit integer that represents the TextDetailTypes currently applied to the
51
+ * TextNode. You probably don't want to use this method directly - consider using TextNode.isDirectionless
52
+ * or TextNode.isUnmergeable instead.
53
+ *
54
+ * @returns a number representing the detail of the text node.
55
+ */
43
56
  getDetail(): number;
57
+ /**
58
+ * Returns the mode (TextModeType) of the TextNode, which may be "normal", "token", or "segmented"
59
+ *
60
+ * @returns TextModeType.
61
+ */
44
62
  getMode(): TextModeType;
63
+ /**
64
+ * Returns the styles currently applied to the node. This is analogous to CSSText in the DOM.
65
+ *
66
+ * @returns CSSText-like string of styles applied to the underlying DOM node.
67
+ */
45
68
  getStyle(): string;
69
+ /**
70
+ * Returns whether or not the node is in "token" mode. TextNodes in token mode can be navigated through character-by-character
71
+ * with a RangeSelection, but are deleted as a single entity (not invdividually by character).
72
+ *
73
+ * @returns true if the node is in token mode, false otherwise.
74
+ */
46
75
  isToken(): boolean;
76
+ /**
77
+ *
78
+ * @returns true if Lexical detects that an IME or other 3rd-party script is attempting to
79
+ * mutate the TextNode, false otherwise.
80
+ */
47
81
  isComposing(): boolean;
82
+ /**
83
+ * Returns whether or not the node is in "segemented" mode. TextNodes in segemented mode can be navigated through character-by-character
84
+ * with a RangeSelection, but are deleted in space-delimited "segments".
85
+ *
86
+ * @returns true if the node is in segmented mode, false otherwise.
87
+ */
48
88
  isSegmented(): boolean;
89
+ /**
90
+ * Returns whether or not the node is "directionless". Directionless nodes don't respect changes between RTL and LTR modes.
91
+ *
92
+ * @returns true if the node is directionless, false otherwise.
93
+ */
49
94
  isDirectionless(): boolean;
95
+ /**
96
+ * Returns whether or not the node is unmergeable. In some scenarios, Lexical tries to merge
97
+ * adjacent TextNodes into a single TextNode. If a TextNode is unmergeable, this won't happen.
98
+ *
99
+ * @returns true if the node is unmergeable, false otherwise.
100
+ */
50
101
  isUnmergeable(): boolean;
102
+ /**
103
+ * Returns whether or not the node has the provided format applied. Use this with the human-readable TextFormatType
104
+ * string values to get the format of a TextNode.
105
+ *
106
+ * @param type - the TextFormatType to check for.
107
+ *
108
+ * @returns true if the node has the provided format, false otherwise.
109
+ */
51
110
  hasFormat(type: TextFormatType): boolean;
111
+ /**
112
+ * Returns whether or not the node is simple text. Simple text is defined as a TextNode that has the string type "text"
113
+ * (i.e., not a subclass) and has no mode applied to it (i.e., not segmented or token).
114
+ *
115
+ * @returns true if the node is simple text, false otherwise.
116
+ */
52
117
  isSimpleText(): boolean;
118
+ /**
119
+ * Returns the text content of the node as a string.
120
+ *
121
+ * @returns a string representing the text content of the node.
122
+ */
53
123
  getTextContent(): string;
124
+ /**
125
+ * Returns the format flags applied to the node as a 32-bit integer.
126
+ *
127
+ * @returns a number representing the TextFormatTypes applied to the node.
128
+ */
54
129
  getFormatFlags(type: TextFormatType, alignWithFormat: null | number): number;
55
130
  createDOM(config: EditorConfig): HTMLElement;
56
131
  updateDOM(prevNode: TextNode, dom: HTMLElement, config: EditorConfig): boolean;
@@ -59,20 +134,134 @@ export declare class TextNode extends LexicalNode {
59
134
  exportDOM(editor: LexicalEditor): DOMExportOutput;
60
135
  exportJSON(): SerializedTextNode;
61
136
  selectionTransform(prevSelection: null | RangeSelection | NodeSelection | GridSelection, nextSelection: RangeSelection): void;
137
+ /**
138
+ * Sets the node format to the provided TextFormatType or 32-bit integer. Note that the TextFormatType
139
+ * version of the argument can only specify one format and doing so will remove all other formats that
140
+ * may be applied to the node. For toggling behavior, consider using {@link TextNode.toggleFormat}
141
+ *
142
+ * @param format - TextFormatType or 32-bit integer representing the node format.
143
+ *
144
+ * @returns this TextNode.
145
+ * // TODO 0.12 This should just be a `string`.
146
+ */
62
147
  setFormat(format: TextFormatType | number): this;
148
+ /**
149
+ * Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType
150
+ * version of the argument can only specify one detail value and doing so will remove all other detail values that
151
+ * may be applied to the node. For toggling behavior, consider using {@link TextNode.toggleDirectionless}
152
+ * or {@link TextNode.togglerUnmergeable}
153
+ *
154
+ * @param detail - TextDetailType or 32-bit integer representing the node detail.
155
+ *
156
+ * @returns this TextNode.
157
+ * // TODO 0.12 This should just be a `string`.
158
+ */
63
159
  setDetail(detail: TextDetailType | number): this;
160
+ /**
161
+ * Sets the node style to the provided CSSText-like string. Set this property as you
162
+ * would an HTMLElement style attribute to apply inline styles to the underlying DOM Element.
163
+ *
164
+ * @param style - CSSText to be applied to the underlying HTMLElement.
165
+ *
166
+ * @returns this TextNode.
167
+ */
64
168
  setStyle(style: string): this;
169
+ /**
170
+ * Applies the provided format to this TextNode if it's not present. Removes it if it is present.
171
+ * Prefer using this method to turn specific formats on and off.
172
+ *
173
+ * @param type - TextFormatType to toggle.
174
+ *
175
+ * @returns this TextNode.
176
+ */
65
177
  toggleFormat(type: TextFormatType): this;
178
+ /**
179
+ * Toggles the directionless detail value of the node. Prefer using this method over setDetail.
180
+ *
181
+ * @returns this TextNode.
182
+ */
66
183
  toggleDirectionless(): this;
184
+ /**
185
+ * Toggles the unmergeable detail value of the node. Prefer using this method over setDetail.
186
+ *
187
+ * @returns this TextNode.
188
+ */
67
189
  toggleUnmergeable(): this;
190
+ /**
191
+ * Sets the mode of the node.
192
+ *
193
+ * @returns this TextNode.
194
+ */
68
195
  setMode(type: TextModeType): this;
196
+ /**
197
+ * Sets the text content of the node.
198
+ *
199
+ * @param text - the string to set as the text value of the node.
200
+ *
201
+ * @returns this TextNode.
202
+ */
69
203
  setTextContent(text: string): this;
204
+ /**
205
+ * Sets the current Lexical selection to be a RangeSelection with anchor and focus on this TextNode at the provided offsets.
206
+ *
207
+ * @param _anchorOffset - the offset at which the Selection anchor will be placed.
208
+ * @param _focusOffset - the offset at which the Selection focus will be placed.
209
+ *
210
+ * @returns the new RangeSelection.
211
+ */
70
212
  select(_anchorOffset?: number, _focusOffset?: number): RangeSelection;
213
+ /**
214
+ * Inserts the provided text into this TextNode at the provided offset, deleting the number of characters
215
+ * specified. Can optionally calculate a new selection after the operation is complete.
216
+ *
217
+ * @param offset - the offset at which the splice operation should begin.
218
+ * @param delCount - the number of characters to delete, starting from the offset.
219
+ * @param newText - the text to insert into the TextNode at the offset.
220
+ * @param moveSelection - optional, whether or not to move selection to the end of the inserted substring.
221
+ *
222
+ * @returns this TextNode.
223
+ */
71
224
  spliceText(offset: number, delCount: number, newText: string, moveSelection?: boolean): TextNode;
225
+ /**
226
+ * This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes
227
+ * when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt
228
+ * to insert text into this node. If false, it will insert the text in a new sibling node.
229
+ *
230
+ * @returns true if text can be inserted before the node, false otherwise.
231
+ */
72
232
  canInsertTextBefore(): boolean;
233
+ /**
234
+ * This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes
235
+ * when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt
236
+ * to insert text into this node. If false, it will insert the text in a new sibling node.
237
+ *
238
+ * @returns true if text can be inserted after the node, false otherwise.
239
+ */
73
240
  canInsertTextAfter(): boolean;
241
+ /**
242
+ * Splits this TextNode at the provided character offsets, forming new TextNodes from the substrings
243
+ * formed by the split, and inserting those new TextNodes into the editor, replacing the one that was split.
244
+ *
245
+ * @param splitOffsets - rest param of the text content character offsets at which this node should be split.
246
+ *
247
+ * @returns an Array containing the newly-created TextNodes.
248
+ */
74
249
  splitText(...splitOffsets: Array<number>): Array<TextNode>;
250
+ /**
251
+ * Merges the target TextNode into this TextNode, removing the target node.
252
+ *
253
+ * @param target - the TextNode to merge into this one.
254
+ *
255
+ * @returns this TextNode.
256
+ */
75
257
  mergeWithSibling(target: TextNode): TextNode;
258
+ /**
259
+ * This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes
260
+ * when used with the registerLexicalTextEntity function. If you're using registerLexicalTextEntity, the
261
+ * node class that you create and replace matched text with should return true from this method.
262
+ *
263
+ * @returns true if the node is to be treated as a "text entity", false otherwise.
264
+ */
76
265
  isTextEntity(): boolean;
77
266
  }
78
267
  export declare function findParentPreDOMNode(node: Node): Node | null;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "rich-text"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.11.0",
12
+ "version": "0.11.2",
13
13
  "main": "Lexical.js",
14
14
  "repository": {
15
15
  "type": "git",