@webiny/lexical-nodes 5.38.0-beta.0

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.
Files changed (72) hide show
  1. package/FontColorNode.d.ts +43 -0
  2. package/FontColorNode.js +125 -0
  3. package/FontColorNode.js.map +1 -0
  4. package/HeadingNode.d.ts +32 -0
  5. package/HeadingNode.js +193 -0
  6. package/HeadingNode.js.map +1 -0
  7. package/ImageNode.d.ts +58 -0
  8. package/ImageNode.js +217 -0
  9. package/ImageNode.js.map +1 -0
  10. package/LICENSE +21 -0
  11. package/LinkNode.d.ts +106 -0
  12. package/LinkNode.js +531 -0
  13. package/LinkNode.js.map +1 -0
  14. package/ListItemNode.d.ts +44 -0
  15. package/ListItemNode.js +442 -0
  16. package/ListItemNode.js.map +1 -0
  17. package/ListNode.d.ts +42 -0
  18. package/ListNode.js +290 -0
  19. package/ListNode.js.map +1 -0
  20. package/ParagraphNode.d.ts +31 -0
  21. package/ParagraphNode.js +220 -0
  22. package/ParagraphNode.js.map +1 -0
  23. package/QuoteNode.d.ts +33 -0
  24. package/QuoteNode.js +227 -0
  25. package/QuoteNode.js.map +1 -0
  26. package/README.md +6 -0
  27. package/TypographyNode.d.ts +41 -0
  28. package/TypographyNode.js +153 -0
  29. package/TypographyNode.js.map +1 -0
  30. package/components/ImageNode/ContentEditable.css +22 -0
  31. package/components/ImageNode/ContentEditable.d.ts +12 -0
  32. package/components/ImageNode/ContentEditable.js +26 -0
  33. package/components/ImageNode/ContentEditable.js.map +1 -0
  34. package/components/ImageNode/ImageComponent.css +43 -0
  35. package/components/ImageNode/ImageComponent.d.ts +16 -0
  36. package/components/ImageNode/ImageComponent.js +254 -0
  37. package/components/ImageNode/ImageComponent.js.map +1 -0
  38. package/components/ImageNode/ImageResizer.d.ts +26 -0
  39. package/components/ImageNode/ImageResizer.js +215 -0
  40. package/components/ImageNode/ImageResizer.js.map +1 -0
  41. package/components/ImageNode/Placeholder.css +20 -0
  42. package/components/ImageNode/Placeholder.d.ts +15 -0
  43. package/components/ImageNode/Placeholder.js +30 -0
  44. package/components/ImageNode/Placeholder.js.map +1 -0
  45. package/components/ImageNode/SharedHistoryContext.d.ts +11 -0
  46. package/components/ImageNode/SharedHistoryContext.js +28 -0
  47. package/components/ImageNode/SharedHistoryContext.js.map +1 -0
  48. package/index.d.ts +22 -0
  49. package/index.js +226 -0
  50. package/index.js.map +1 -0
  51. package/package.json +32 -0
  52. package/types.d.ts +15 -0
  53. package/types.js +7 -0
  54. package/types.js.map +1 -0
  55. package/utils/clearNodeFormating.d.ts +2 -0
  56. package/utils/clearNodeFormating.js +30 -0
  57. package/utils/clearNodeFormating.js.map +1 -0
  58. package/utils/formatList.d.ts +19 -0
  59. package/utils/formatList.js +449 -0
  60. package/utils/formatList.js.map +1 -0
  61. package/utils/formatToHeading.d.ts +3 -0
  62. package/utils/formatToHeading.js +27 -0
  63. package/utils/formatToHeading.js.map +1 -0
  64. package/utils/formatToParagraph.d.ts +2 -0
  65. package/utils/formatToParagraph.js +22 -0
  66. package/utils/formatToParagraph.js.map +1 -0
  67. package/utils/formatToQuote.d.ts +2 -0
  68. package/utils/formatToQuote.js +27 -0
  69. package/utils/formatToQuote.js.map +1 -0
  70. package/utils/listNode.d.ts +11 -0
  71. package/utils/listNode.js +109 -0
  72. package/utils/listNode.js.map +1 -0
package/ImageNode.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard3 = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.$createImageNode = $createImageNode;
9
+ exports.$isImageNode = $isImageNode;
10
+ exports.ImageNode = void 0;
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
+ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
15
+ var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
16
+ var _react = _interopRequireWildcard3(require("react"));
17
+ var _lexical = require("lexical");
18
+ /**
19
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ *
24
+ */
25
+
26
+ var ImageComponent = /*#__PURE__*/_react.default.lazy(
27
+ // @ts-ignore
28
+ function () {
29
+ return Promise.resolve().then(function () {
30
+ return (0, _interopRequireWildcard2.default)(require("./components/ImageNode/ImageComponent"));
31
+ });
32
+ });
33
+ var ImageNode = /*#__PURE__*/function (_DecoratorNode) {
34
+ (0, _inherits2.default)(ImageNode, _DecoratorNode);
35
+ var _super = (0, _createSuper2.default)(ImageNode);
36
+ function ImageNode(props, key) {
37
+ var _this;
38
+ (0, _classCallCheck2.default)(this, ImageNode);
39
+ _this = _super.call(this, key);
40
+ _this.__id = props.id;
41
+ _this.__src = props.src;
42
+ _this.__altText = props.altText;
43
+ _this.__maxWidth = props.maxWidth;
44
+ _this.__width = props.width || "inherit";
45
+ _this.__height = props.height || "inherit";
46
+ _this.__showCaption = props.showCaption || false;
47
+ _this.__caption = props.caption || (0, _lexical.createEditor)();
48
+ _this.__captionsEnabled = props.captionsEnabled || props.captionsEnabled === undefined;
49
+ return _this;
50
+ }
51
+ (0, _createClass2.default)(ImageNode, [{
52
+ key: "exportDOM",
53
+ value: function exportDOM() {
54
+ var element = document.createElement("img");
55
+ element.setAttribute("id", this.__id);
56
+ element.setAttribute("src", this.__src);
57
+ element.setAttribute("alt", this.__altText);
58
+ element.setAttribute("width", this.__width.toString());
59
+ element.setAttribute("height", this.__height.toString());
60
+ return {
61
+ element: element
62
+ };
63
+ }
64
+
65
+ /**
66
+ * Control how an HTMLElement is represented in Lexical.
67
+ * DOM data comes from clipboard or parsing HTML to nodes with the available lexical functions.
68
+ * (@see @lexical/html package: https://github.com/facebook/lexical/blob/main/packages/lexical-html/README.md).
69
+ */
70
+ }, {
71
+ key: "exportJSON",
72
+ value: function exportJSON() {
73
+ return {
74
+ id: this.__id,
75
+ altText: this.getAltText(),
76
+ caption: this.__caption.toJSON(),
77
+ height: this.__height === "inherit" ? 0 : this.__height,
78
+ maxWidth: this.__maxWidth,
79
+ showCaption: this.__showCaption,
80
+ src: this.getSrc(),
81
+ type: "image",
82
+ version: 1,
83
+ width: this.__width === "inherit" ? 0 : this.__width
84
+ };
85
+ }
86
+ }, {
87
+ key: "setWidthAndHeight",
88
+ value: function setWidthAndHeight(width, height) {
89
+ var writable = this.getWritable();
90
+ writable.__width = width;
91
+ writable.__height = height;
92
+ }
93
+ }, {
94
+ key: "setShowCaption",
95
+ value: function setShowCaption(showCaption) {
96
+ var writable = this.getWritable();
97
+ writable.__showCaption = showCaption;
98
+ }
99
+
100
+ // View
101
+ }, {
102
+ key: "createDOM",
103
+ value: function createDOM(config) {
104
+ var span = document.createElement("span");
105
+ var theme = config.theme;
106
+ var className = theme.image;
107
+ if (className !== undefined) {
108
+ span.className = className;
109
+ }
110
+ return span;
111
+ }
112
+ }, {
113
+ key: "updateDOM",
114
+ value: function updateDOM() {
115
+ return false;
116
+ }
117
+ }, {
118
+ key: "getSrc",
119
+ value: function getSrc() {
120
+ return this.__src;
121
+ }
122
+ }, {
123
+ key: "getAltText",
124
+ value: function getAltText() {
125
+ return this.__altText;
126
+ }
127
+ }, {
128
+ key: "decorate",
129
+ value: function decorate() {
130
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
131
+ fallback: null
132
+ }, /*#__PURE__*/_react.default.createElement(ImageComponent, {
133
+ id: this.__id,
134
+ src: this.__src,
135
+ altText: this.__altText,
136
+ width: this.__width,
137
+ height: this.__height,
138
+ maxWidth: this.__maxWidth,
139
+ nodeKey: this.getKey(),
140
+ showCaption: this.__showCaption,
141
+ caption: this.__caption,
142
+ captionsEnabled: this.__captionsEnabled,
143
+ resizable: true
144
+ }));
145
+ }
146
+ }], [{
147
+ key: "getType",
148
+ value:
149
+ // Captions cannot yet be used within editor cells
150
+
151
+ function getType() {
152
+ return "image";
153
+ }
154
+ }, {
155
+ key: "clone",
156
+ value: function clone(node) {
157
+ return new ImageNode({
158
+ id: node.__id,
159
+ src: node.__src,
160
+ altText: node.__altText,
161
+ maxWidth: node.__maxWidth,
162
+ width: node.__width,
163
+ height: node.__height,
164
+ showCaption: node.__showCaption,
165
+ caption: node.__caption,
166
+ captionsEnabled: node.__captionsEnabled
167
+ }, node.__key);
168
+ }
169
+ }, {
170
+ key: "importJSON",
171
+ value: function importJSON(serializedNode) {
172
+ var id = serializedNode.id,
173
+ altText = serializedNode.altText,
174
+ height = serializedNode.height,
175
+ width = serializedNode.width,
176
+ maxWidth = serializedNode.maxWidth,
177
+ caption = serializedNode.caption,
178
+ src = serializedNode.src,
179
+ showCaption = serializedNode.showCaption;
180
+ var node = $createImageNode({
181
+ id: id,
182
+ altText: altText,
183
+ height: height,
184
+ maxWidth: maxWidth,
185
+ showCaption: showCaption,
186
+ src: src,
187
+ width: width
188
+ });
189
+ var nestedEditor = node.__caption;
190
+ var editorState = nestedEditor.parseEditorState(caption.editorState);
191
+ if (!editorState.isEmpty()) {
192
+ nestedEditor.setEditorState(editorState);
193
+ }
194
+ return node;
195
+ }
196
+ }, {
197
+ key: "importDOM",
198
+ value: function importDOM() {
199
+ /**
200
+ * By returning 'null' value, we are preventing image node to be created.
201
+ * Example of how to implement and create the node:
202
+ * https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/ImageNode.tsx#L94
203
+ */
204
+ return null;
205
+ }
206
+ }]);
207
+ return ImageNode;
208
+ }(_lexical.DecoratorNode);
209
+ exports.ImageNode = ImageNode;
210
+ function $createImageNode(props, key) {
211
+ return (0, _lexical.$applyNodeReplacement)(new ImageNode(props, key));
212
+ }
213
+ function $isImageNode(node) {
214
+ return node instanceof ImageNode;
215
+ }
216
+
217
+ //# sourceMappingURL=ImageNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard3","require","_lexical","ImageComponent","React","lazy","Promise","resolve","then","_interopRequireWildcard2","default","ImageNode","_DecoratorNode","_inherits2","_super","_createSuper2","props","key","_this","_classCallCheck2","call","__id","id","__src","src","__altText","altText","__maxWidth","maxWidth","__width","width","__height","height","__showCaption","showCaption","__caption","caption","createEditor","__captionsEnabled","captionsEnabled","undefined","_createClass2","value","exportDOM","element","document","createElement","setAttribute","toString","exportJSON","getAltText","toJSON","getSrc","type","version","setWidthAndHeight","writable","getWritable","setShowCaption","createDOM","config","span","theme","className","image","updateDOM","decorate","Suspense","fallback","nodeKey","getKey","resizable","getType","clone","node","__key","importJSON","serializedNode","$createImageNode","nestedEditor","editorState","parseEditorState","isEmpty","setEditorState","importDOM","DecoratorNode","exports","$applyNodeReplacement","$isImageNode"],"sources":["ImageNode.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport React, { Suspense } from \"react\";\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedEditor,\n SerializedLexicalNode,\n Spread\n} from \"lexical\";\nimport { $applyNodeReplacement, createEditor, DecoratorNode } from \"lexical\";\n\nconst ImageComponent = React.lazy(\n // @ts-ignore\n () => import(\"./components/ImageNode/ImageComponent\")\n);\n\nexport type SerializedImageNode = Spread<\n {\n id: string;\n altText: string;\n caption: SerializedEditor;\n height?: number;\n maxWidth: number;\n showCaption: boolean;\n src: string;\n width?: number;\n },\n SerializedLexicalNode\n>;\n\nexport interface ImageNodeProps {\n id: string;\n src: string;\n altText: string;\n maxWidth: number;\n width?: \"inherit\" | number;\n height?: \"inherit\" | number;\n showCaption?: boolean;\n caption?: LexicalEditor;\n captionsEnabled?: boolean;\n}\n\nexport class ImageNode extends DecoratorNode<JSX.Element> {\n __id: string;\n __src: string;\n __altText: string;\n __width: \"inherit\" | number;\n __height: \"inherit\" | number;\n __maxWidth: number;\n __showCaption: boolean;\n __caption: LexicalEditor;\n // Captions cannot yet be used within editor cells\n __captionsEnabled: boolean;\n\n static override getType(): string {\n return \"image\";\n }\n\n static override clone(node: ImageNode): ImageNode {\n return new ImageNode(\n {\n id: node.__id,\n src: node.__src,\n altText: node.__altText,\n maxWidth: node.__maxWidth,\n width: node.__width,\n height: node.__height,\n showCaption: node.__showCaption,\n caption: node.__caption,\n captionsEnabled: node.__captionsEnabled\n },\n node.__key\n );\n }\n\n static override importJSON(serializedNode: SerializedImageNode): ImageNode {\n const { id, altText, height, width, maxWidth, caption, src, showCaption } = serializedNode;\n const node = $createImageNode({\n id,\n altText,\n height,\n maxWidth,\n showCaption,\n src,\n width\n });\n const nestedEditor = node.__caption;\n const editorState = nestedEditor.parseEditorState(caption.editorState);\n if (!editorState.isEmpty()) {\n nestedEditor.setEditorState(editorState);\n }\n return node;\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement(\"img\");\n element.setAttribute(\"id\", this.__id);\n element.setAttribute(\"src\", this.__src);\n element.setAttribute(\"alt\", this.__altText);\n element.setAttribute(\"width\", this.__width.toString());\n element.setAttribute(\"height\", this.__height.toString());\n return { element };\n }\n\n /**\n * Control how an HTMLElement is represented in Lexical.\n * DOM data comes from clipboard or parsing HTML to nodes with the available lexical functions.\n * (@see @lexical/html package: https://github.com/facebook/lexical/blob/main/packages/lexical-html/README.md).\n */\n static importDOM(): DOMConversionMap | null {\n /**\n * By returning 'null' value, we are preventing image node to be created.\n * Example of how to implement and create the node:\n * https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/ImageNode.tsx#L94\n */\n return null;\n }\n\n constructor(props: ImageNodeProps, key?: NodeKey) {\n super(key);\n this.__id = props.id;\n this.__src = props.src;\n this.__altText = props.altText;\n this.__maxWidth = props.maxWidth;\n this.__width = props.width || \"inherit\";\n this.__height = props.height || \"inherit\";\n this.__showCaption = props.showCaption || false;\n this.__caption = props.caption || createEditor();\n this.__captionsEnabled = props.captionsEnabled || props.captionsEnabled === undefined;\n }\n\n override exportJSON(): SerializedImageNode {\n return {\n id: this.__id,\n altText: this.getAltText(),\n caption: this.__caption.toJSON(),\n height: this.__height === \"inherit\" ? 0 : this.__height,\n maxWidth: this.__maxWidth,\n showCaption: this.__showCaption,\n src: this.getSrc(),\n type: \"image\",\n version: 1,\n width: this.__width === \"inherit\" ? 0 : this.__width\n };\n }\n\n setWidthAndHeight(width: \"inherit\" | number, height: \"inherit\" | number): void {\n const writable = this.getWritable();\n writable.__width = width;\n writable.__height = height;\n }\n\n setShowCaption(showCaption: boolean): void {\n const writable = this.getWritable();\n writable.__showCaption = showCaption;\n }\n\n // View\n override createDOM(config: EditorConfig): HTMLElement {\n const span = document.createElement(\"span\");\n const theme = config.theme;\n const className = theme.image;\n if (className !== undefined) {\n span.className = className;\n }\n return span;\n }\n\n override updateDOM(): false {\n return false;\n }\n\n getSrc(): string {\n return this.__src;\n }\n\n getAltText(): string {\n return this.__altText;\n }\n\n override decorate(): JSX.Element {\n return (\n <Suspense fallback={null}>\n <ImageComponent\n id={this.__id}\n src={this.__src}\n altText={this.__altText}\n width={this.__width}\n height={this.__height}\n maxWidth={this.__maxWidth}\n nodeKey={this.getKey()}\n showCaption={this.__showCaption}\n caption={this.__caption}\n captionsEnabled={this.__captionsEnabled}\n resizable={true}\n />\n </Suspense>\n );\n }\n}\n\nexport function $createImageNode(props: ImageNodeProps, key?: string): ImageNode {\n return $applyNodeReplacement(new ImageNode(props, key));\n}\n\nexport function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode {\n return node instanceof ImageNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAOA,IAAAA,MAAA,GAAAC,wBAAA,CAAAC,OAAA;AAYA,IAAAC,QAAA,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iny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LinkNode.d.ts ADDED
@@ -0,0 +1,106 @@
1
+ /** @module @lexical/link */
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ */
9
+ import type { DOMConversionMap, EditorConfig, GridSelection, LexicalCommand, LexicalNode, NodeKey, NodeSelection, RangeSelection, SerializedElementNode } from "lexical";
10
+ import { ElementNode, Spread } from "lexical";
11
+ export declare type LinkAttributes = {
12
+ rel?: null | string;
13
+ target?: null | string;
14
+ title?: null | string;
15
+ alt?: null | string;
16
+ };
17
+ declare global {
18
+ interface HTMLAnchorElement {
19
+ alt?: string;
20
+ }
21
+ }
22
+ export declare type SerializedLinkNode = Spread<{
23
+ url: string;
24
+ }, Spread<LinkAttributes, SerializedElementNode>>;
25
+ /** @noInheritDoc */
26
+ export declare class LinkNode extends ElementNode {
27
+ /** @internal */
28
+ __url: string;
29
+ /** @internal */
30
+ __target: null | string;
31
+ /** @internal */
32
+ __rel: null | string;
33
+ /** @internal */
34
+ __title: null | string;
35
+ /** @internal */
36
+ __alt: null | string;
37
+ static getType(): string;
38
+ static clone(node: LinkNode): LinkNode;
39
+ constructor(url: string, attributes?: LinkAttributes, key?: NodeKey);
40
+ createDOM(config: EditorConfig): HTMLAnchorElement;
41
+ updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement): boolean;
42
+ static importDOM(): DOMConversionMap | null;
43
+ static importJSON(serializedNode: SerializedLinkNode | SerializedAutoLinkNode): LinkNode;
44
+ sanitizeUrl(url: string): string;
45
+ exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
46
+ getURL(): string;
47
+ setURL(url: string): void;
48
+ getTarget(): null | string;
49
+ setTarget(target: null | string): void;
50
+ getRel(): null | string;
51
+ setRel(rel: null | string): void;
52
+ getTitle(): null | string;
53
+ setTitle(title: null | string): void;
54
+ insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
55
+ canInsertTextBefore(): false;
56
+ canInsertTextAfter(): false;
57
+ canBeEmpty(): false;
58
+ isInline(): true;
59
+ extractWithChild(_: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection): boolean;
60
+ }
61
+ /**
62
+ * Takes a URL and creates a LinkNode.
63
+ * @param url - The URL the LinkNode should direct to.
64
+ * @param attributes - Optional HTML a tag attributes { target, rel, title }
65
+ * @returns The LinkNode.
66
+ */
67
+ export declare function $createLinkNode(url: string, attributes?: LinkAttributes): LinkNode;
68
+ /**
69
+ * Determines if node is a LinkNode.
70
+ * @param node - The node to be checked.
71
+ * @returns true if node is a LinkNode, false otherwise.
72
+ */
73
+ export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
74
+ export declare type SerializedAutoLinkNode = SerializedLinkNode;
75
+ export declare class AutoLinkNode extends LinkNode {
76
+ static getType(): string;
77
+ static clone(node: AutoLinkNode): AutoLinkNode;
78
+ static importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode;
79
+ static importDOM(): null;
80
+ exportJSON(): SerializedAutoLinkNode;
81
+ insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
82
+ }
83
+ /**
84
+ * Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
85
+ * during typing, which is especially useful when a button to generate a LinkNode is not practical.
86
+ * @param url - The URL the LinkNode should direct to.
87
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
88
+ * @returns The LinkNode.
89
+ */
90
+ export declare function $createAutoLinkNode(url: string, attributes?: LinkAttributes): AutoLinkNode;
91
+ /**
92
+ * Determines if node is an AutoLinkNode.
93
+ * @param node - The node to be checked.
94
+ * @returns true if node is an AutoLinkNode, false otherwise.
95
+ */
96
+ export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
97
+ export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
98
+ url: string;
99
+ } & LinkAttributes) | null>;
100
+ /**
101
+ * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
102
+ * but saves any children and brings them up to the parent node.
103
+ * @param url - The URL the link directs to.
104
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
105
+ */
106
+ export declare function toggleLink(url: null | string, attributes?: LinkAttributes): void;