@webiny/lexical-nodes 5.44.1-beta.0 → 5.45.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.
- package/FontColorNode.d.ts +6 -6
- package/FontColorNode.js +102 -145
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.d.ts +29 -17
- package/HeadingNode.js +184 -152
- package/HeadingNode.js.map +1 -1
- package/ImageNode.d.ts +1 -11
- package/ImageNode.js +119 -190
- package/ImageNode.js.map +1 -1
- package/LinkNode.d.ts +2 -2
- package/LinkNode.js +249 -346
- package/LinkNode.js.map +1 -1
- package/ListItemNode.d.ts +4 -3
- package/ListItemNode.js +275 -354
- package/ListItemNode.js.map +1 -1
- package/ListNode.d.ts +28 -14
- package/ListNode.js +170 -209
- package/ListNode.js.map +1 -1
- package/ParagraphNode.d.ts +28 -16
- package/ParagraphNode.js +143 -179
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.d.ts +26 -19
- package/QuoteNode.js +102 -188
- package/QuoteNode.js.map +1 -1
- package/README.md +9 -4
- package/components/ImageNode/ImageComponent.d.ts +2 -7
- package/components/ImageNode/ImageComponent.js +72 -166
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.d.ts +1 -8
- package/components/ImageNode/ImageResizer.js +74 -89
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.d.ts +4 -0
- package/generateInitialLexicalValue.js +27 -0
- package/generateInitialLexicalValue.js.map +1 -0
- package/index.d.ts +19 -23
- package/index.js +50 -233
- package/index.js.map +1 -1
- package/package.json +16 -20
- package/prepareLexicalState.d.ts +2 -0
- package/prepareLexicalState.js +53 -0
- package/prepareLexicalState.js.map +1 -0
- package/types.d.ts +4 -5
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/clearNodeFormating.d.ts +1 -1
- package/utils/clearNodeFormating.js +12 -18
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.d.ts +4 -4
- package/utils/formatList.js +171 -208
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.d.ts +2 -2
- package/utils/formatToHeading.js +8 -15
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.d.ts +1 -1
- package/utils/formatToParagraph.js +8 -16
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.d.ts +1 -1
- package/utils/formatToQuote.js +8 -15
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.d.ts +11 -0
- package/utils/getStyleId.js +14 -0
- package/utils/getStyleId.js.map +1 -0
- package/utils/listNode.d.ts +2 -2
- package/utils/listNode.js +37 -50
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.d.ts +1 -1
- package/utils/toggleLink.js +41 -45
- package/utils/toggleLink.js.map +1 -1
- package/TypographyNode.d.ts +0 -39
- package/TypographyNode.js +0 -146
- package/TypographyNode.js.map +0 -1
- package/components/ImageNode/ContentEditable.css +0 -22
- package/components/ImageNode/ContentEditable.d.ts +0 -12
- package/components/ImageNode/ContentEditable.js +0 -26
- package/components/ImageNode/ContentEditable.js.map +0 -1
- package/components/ImageNode/ImageComponent.css +0 -43
- package/components/ImageNode/Placeholder.css +0 -20
- package/components/ImageNode/Placeholder.d.ts +0 -15
- package/components/ImageNode/Placeholder.js +0 -30
- package/components/ImageNode/Placeholder.js.map +0 -1
- package/components/ImageNode/SharedHistoryContext.d.ts +0 -10
- package/components/ImageNode/SharedHistoryContext.js +0 -27
- package/components/ImageNode/SharedHistoryContext.js.map +0 -1
package/LinkNode.js
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.$createAutoLinkNode = $createAutoLinkNode;
|
|
8
|
-
exports.$createLinkNode = $createLinkNode;
|
|
9
|
-
exports.$isAutoLinkNode = $isAutoLinkNode;
|
|
10
|
-
exports.$isLinkNode = $isLinkNode;
|
|
11
|
-
exports.TOGGLE_LINK_COMMAND = exports.LinkNode = exports.AutoLinkNode = void 0;
|
|
12
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
16
|
-
var _superPropGet2 = _interopRequireDefault(require("@babel/runtime/helpers/superPropGet"));
|
|
17
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
18
|
-
var _utils = require("@lexical/utils");
|
|
19
|
-
var _lexical = require("lexical");
|
|
20
1
|
/** @module @lexical/link */
|
|
21
2
|
/**
|
|
22
3
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -26,279 +7,219 @@ var _lexical = require("lexical");
|
|
|
26
7
|
*
|
|
27
8
|
*/
|
|
28
9
|
|
|
29
|
-
|
|
10
|
+
import { $applyNodeReplacement, $isElementNode, $isRangeSelection, createCommand, ElementNode, addClassNamesToElement, isHTMLAnchorElement } from "lexical";
|
|
11
|
+
const SUPPORTED_URL_PROTOCOLS = new Set(["http:", "https:", "mailto:", "sms:", "tel:"]);
|
|
30
12
|
|
|
31
13
|
/** @noInheritDoc */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return element;
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "updateDOM",
|
|
77
|
-
value: function updateDOM(prevNode, anchor) {
|
|
78
|
-
var url = this.__url;
|
|
79
|
-
var target = this.__target;
|
|
80
|
-
var rel = this.__rel;
|
|
81
|
-
var title = this.__title;
|
|
82
|
-
var alt = this.__alt;
|
|
83
|
-
if (url !== prevNode.__url) {
|
|
84
|
-
anchor.href = url;
|
|
85
|
-
}
|
|
86
|
-
if (target !== prevNode.__target) {
|
|
87
|
-
if (target) {
|
|
88
|
-
anchor.target = target;
|
|
89
|
-
} else {
|
|
90
|
-
anchor.removeAttribute("target");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (rel !== prevNode.__rel) {
|
|
94
|
-
if (rel) {
|
|
95
|
-
anchor.rel = rel;
|
|
96
|
-
} else {
|
|
97
|
-
anchor.removeAttribute("rel");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (title !== prevNode.__title) {
|
|
101
|
-
if (title) {
|
|
102
|
-
anchor.title = title;
|
|
103
|
-
} else {
|
|
104
|
-
anchor.removeAttribute("title");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (alt !== prevNode.__alt) {
|
|
108
|
-
if (alt) {
|
|
109
|
-
anchor.setAttribute("alt", alt);
|
|
110
|
-
} else {
|
|
111
|
-
anchor.removeAttribute("alt");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}, {
|
|
117
|
-
key: "sanitizeUrl",
|
|
118
|
-
value: function sanitizeUrl(url) {
|
|
119
|
-
try {
|
|
120
|
-
var parsedUrl = new URL(url);
|
|
121
|
-
// eslint-disable-next-line no-script-url
|
|
122
|
-
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
123
|
-
return "about:blank";
|
|
124
|
-
}
|
|
125
|
-
} catch (_unused) {
|
|
126
|
-
return url;
|
|
127
|
-
}
|
|
128
|
-
return url;
|
|
129
|
-
}
|
|
130
|
-
}, {
|
|
131
|
-
key: "exportJSON",
|
|
132
|
-
value: function exportJSON() {
|
|
133
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _superPropGet2.default)(LinkNode, "exportJSON", this, 3)([])), {}, {
|
|
134
|
-
rel: this.getRel(),
|
|
135
|
-
target: this.getTarget(),
|
|
136
|
-
title: this.getTitle(),
|
|
137
|
-
alt: this.getAlt(),
|
|
138
|
-
type: "link",
|
|
139
|
-
url: this.getURL(),
|
|
140
|
-
version: 1
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}, {
|
|
144
|
-
key: "getURL",
|
|
145
|
-
value: function getURL() {
|
|
146
|
-
return this.getLatest().__url;
|
|
147
|
-
}
|
|
148
|
-
}, {
|
|
149
|
-
key: "setURL",
|
|
150
|
-
value: function setURL(url) {
|
|
151
|
-
var writable = this.getWritable();
|
|
152
|
-
writable.__url = url;
|
|
153
|
-
}
|
|
154
|
-
}, {
|
|
155
|
-
key: "getTarget",
|
|
156
|
-
value: function getTarget() {
|
|
157
|
-
return this.getLatest().__target;
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "setTarget",
|
|
161
|
-
value: function setTarget(target) {
|
|
162
|
-
var writable = this.getWritable();
|
|
163
|
-
writable.__target = target;
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
key: "getRel",
|
|
167
|
-
value: function getRel() {
|
|
168
|
-
return this.getLatest().__rel;
|
|
169
|
-
}
|
|
170
|
-
}, {
|
|
171
|
-
key: "setRel",
|
|
172
|
-
value: function setRel(rel) {
|
|
173
|
-
var writable = this.getWritable();
|
|
174
|
-
writable.__rel = rel;
|
|
14
|
+
export class LinkNode extends ElementNode {
|
|
15
|
+
/** @internal */
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
|
|
25
|
+
static getType() {
|
|
26
|
+
return "wby-link";
|
|
27
|
+
}
|
|
28
|
+
static clone(node) {
|
|
29
|
+
return new LinkNode(node.__url, {
|
|
30
|
+
rel: node.__rel,
|
|
31
|
+
target: node.__target,
|
|
32
|
+
title: node.__title,
|
|
33
|
+
alt: node.__alt
|
|
34
|
+
}, node.__key);
|
|
35
|
+
}
|
|
36
|
+
constructor(url, attributes = {}, key) {
|
|
37
|
+
super(key);
|
|
38
|
+
const {
|
|
39
|
+
target = null,
|
|
40
|
+
rel = null,
|
|
41
|
+
title = null,
|
|
42
|
+
alt = null
|
|
43
|
+
} = attributes;
|
|
44
|
+
this.__url = url;
|
|
45
|
+
this.__target = target;
|
|
46
|
+
this.__rel = rel;
|
|
47
|
+
this.__title = title;
|
|
48
|
+
this.__alt = alt;
|
|
49
|
+
}
|
|
50
|
+
createDOM(config) {
|
|
51
|
+
const element = document.createElement("a");
|
|
52
|
+
element.href = this.sanitizeUrl(this.__url);
|
|
53
|
+
if (this.__target !== null) {
|
|
54
|
+
element.target = this.__target;
|
|
175
55
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
value: function getTitle() {
|
|
179
|
-
return this.getLatest().__title;
|
|
56
|
+
if (this.__rel !== null) {
|
|
57
|
+
element.rel = this.__rel;
|
|
180
58
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
value: function setTitle(title) {
|
|
184
|
-
var writable = this.getWritable();
|
|
185
|
-
writable.__title = title;
|
|
59
|
+
if (this.__title !== null) {
|
|
60
|
+
element.title = this.__title;
|
|
186
61
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
value: function getAlt() {
|
|
190
|
-
return this.__alt;
|
|
62
|
+
if (this.__alt) {
|
|
63
|
+
element.setAttribute("alt", this.__alt);
|
|
191
64
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
65
|
+
addClassNamesToElement(element, config.theme.link);
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
updateDOM(prevNode, anchor) {
|
|
69
|
+
const url = this.__url;
|
|
70
|
+
const target = this.__target;
|
|
71
|
+
const rel = this.__rel;
|
|
72
|
+
const title = this.__title;
|
|
73
|
+
const alt = this.__alt;
|
|
74
|
+
if (url !== prevNode.__url) {
|
|
75
|
+
anchor.href = url;
|
|
197
76
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if ((0, _lexical.$isElementNode)(element)) {
|
|
204
|
-
var linkNode = $createLinkNode(this.__url, {
|
|
205
|
-
rel: this.__rel,
|
|
206
|
-
target: this.__target,
|
|
207
|
-
title: this.__title,
|
|
208
|
-
alt: this.__alt
|
|
209
|
-
});
|
|
210
|
-
element.append(linkNode);
|
|
211
|
-
return linkNode;
|
|
77
|
+
if (target !== prevNode.__target) {
|
|
78
|
+
if (target) {
|
|
79
|
+
anchor.target = target;
|
|
80
|
+
} else {
|
|
81
|
+
anchor.removeAttribute("target");
|
|
212
82
|
}
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
}, {
|
|
216
|
-
key: "canInsertTextBefore",
|
|
217
|
-
value: function canInsertTextBefore() {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
}, {
|
|
221
|
-
key: "canInsertTextAfter",
|
|
222
|
-
value: function canInsertTextAfter() {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
}, {
|
|
226
|
-
key: "canBeEmpty",
|
|
227
|
-
value: function canBeEmpty() {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
}, {
|
|
231
|
-
key: "isInline",
|
|
232
|
-
value: function isInline() {
|
|
233
|
-
return true;
|
|
234
83
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
84
|
+
if (rel !== prevNode.__rel) {
|
|
85
|
+
if (rel) {
|
|
86
|
+
anchor.rel = rel;
|
|
87
|
+
} else {
|
|
88
|
+
anchor.removeAttribute("rel");
|
|
240
89
|
}
|
|
241
|
-
var anchorNode = selection.anchor.getNode();
|
|
242
|
-
var focusNode = selection.focus.getNode();
|
|
243
|
-
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
|
|
244
90
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/** @internal */
|
|
252
|
-
|
|
253
|
-
/** @internal */
|
|
254
|
-
|
|
255
|
-
/** @internal */
|
|
256
|
-
|
|
257
|
-
function getType() {
|
|
258
|
-
return "link";
|
|
91
|
+
if (title !== prevNode.__title) {
|
|
92
|
+
if (title) {
|
|
93
|
+
anchor.title = title;
|
|
94
|
+
} else {
|
|
95
|
+
anchor.removeAttribute("title");
|
|
96
|
+
}
|
|
259
97
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
title: node.__title,
|
|
267
|
-
alt: node.__alt
|
|
268
|
-
}, node.__key);
|
|
98
|
+
if (alt !== prevNode.__alt) {
|
|
99
|
+
if (alt) {
|
|
100
|
+
anchor.setAttribute("alt", alt);
|
|
101
|
+
} else {
|
|
102
|
+
anchor.removeAttribute("alt");
|
|
103
|
+
}
|
|
269
104
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
static importDOM() {
|
|
108
|
+
return {
|
|
109
|
+
a: () => ({
|
|
110
|
+
conversion: convertAnchorElement,
|
|
111
|
+
priority: 1
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
static importJSON(serializedNode) {
|
|
116
|
+
const node = $createLinkNode(serializedNode.url, {
|
|
117
|
+
rel: serializedNode.rel,
|
|
118
|
+
target: serializedNode.target,
|
|
119
|
+
title: serializedNode.title,
|
|
120
|
+
alt: serializedNode.alt
|
|
121
|
+
});
|
|
122
|
+
node.setFormat(serializedNode.format);
|
|
123
|
+
node.setIndent(serializedNode.indent);
|
|
124
|
+
node.setDirection(serializedNode.direction);
|
|
125
|
+
return node;
|
|
126
|
+
}
|
|
127
|
+
sanitizeUrl(url) {
|
|
128
|
+
try {
|
|
129
|
+
const parsedUrl = new URL(url);
|
|
130
|
+
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
131
|
+
return "about:blank";
|
|
132
|
+
}
|
|
133
|
+
} catch {
|
|
134
|
+
return url;
|
|
281
135
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
136
|
+
return url;
|
|
137
|
+
}
|
|
138
|
+
exportJSON() {
|
|
139
|
+
return {
|
|
140
|
+
...super.exportJSON(),
|
|
141
|
+
rel: this.getRel(),
|
|
142
|
+
target: this.getTarget(),
|
|
143
|
+
title: this.getTitle(),
|
|
144
|
+
alt: this.getAlt(),
|
|
145
|
+
type: "wby-link",
|
|
146
|
+
url: this.getURL()
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
getURL() {
|
|
150
|
+
return this.getLatest().__url;
|
|
151
|
+
}
|
|
152
|
+
setURL(url) {
|
|
153
|
+
const writable = this.getWritable();
|
|
154
|
+
writable.__url = url;
|
|
155
|
+
}
|
|
156
|
+
getTarget() {
|
|
157
|
+
return this.getLatest().__target;
|
|
158
|
+
}
|
|
159
|
+
setTarget(target) {
|
|
160
|
+
const writable = this.getWritable();
|
|
161
|
+
writable.__target = target;
|
|
162
|
+
}
|
|
163
|
+
getRel() {
|
|
164
|
+
return this.getLatest().__rel;
|
|
165
|
+
}
|
|
166
|
+
setRel(rel) {
|
|
167
|
+
const writable = this.getWritable();
|
|
168
|
+
writable.__rel = rel;
|
|
169
|
+
}
|
|
170
|
+
getTitle() {
|
|
171
|
+
return this.getLatest().__title;
|
|
172
|
+
}
|
|
173
|
+
setTitle(title) {
|
|
174
|
+
const writable = this.getWritable();
|
|
175
|
+
writable.__title = title;
|
|
176
|
+
}
|
|
177
|
+
getAlt() {
|
|
178
|
+
return this.__alt;
|
|
179
|
+
}
|
|
180
|
+
setAlt(text) {
|
|
181
|
+
const writable = super.getWritable();
|
|
182
|
+
writable.__alt = text;
|
|
183
|
+
}
|
|
184
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
185
|
+
const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
|
|
186
|
+
if ($isElementNode(element)) {
|
|
187
|
+
const linkNode = $createLinkNode(this.__url, {
|
|
188
|
+
rel: this.__rel,
|
|
189
|
+
target: this.__target,
|
|
190
|
+
title: this.__title,
|
|
191
|
+
alt: this.__alt
|
|
290
192
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
node.setDirection(serializedNode.direction);
|
|
294
|
-
return node;
|
|
193
|
+
element.append(linkNode);
|
|
194
|
+
return linkNode;
|
|
295
195
|
}
|
|
296
|
-
|
|
297
|
-
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
canInsertTextBefore() {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
canInsertTextAfter() {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
canBeEmpty() {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
isInline() {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
extractWithChild(_, selection) {
|
|
211
|
+
if (!$isRangeSelection(selection)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const anchorNode = selection.anchor.getNode();
|
|
215
|
+
const focusNode = selection.focus.getNode();
|
|
216
|
+
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
298
219
|
function convertAnchorElement(domNode) {
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
220
|
+
let node = null;
|
|
221
|
+
if (isHTMLAnchorElement(domNode)) {
|
|
222
|
+
const content = domNode.textContent;
|
|
302
223
|
if (content !== null && content !== "" || domNode.children.length > 0) {
|
|
303
224
|
node = $createLinkNode(domNode.getAttribute("href") || "", {
|
|
304
225
|
rel: domNode.getAttribute("rel"),
|
|
@@ -309,7 +230,7 @@ function convertAnchorElement(domNode) {
|
|
|
309
230
|
}
|
|
310
231
|
}
|
|
311
232
|
return {
|
|
312
|
-
node
|
|
233
|
+
node
|
|
313
234
|
};
|
|
314
235
|
}
|
|
315
236
|
|
|
@@ -319,8 +240,8 @@ function convertAnchorElement(domNode) {
|
|
|
319
240
|
* @param attributes - Optional HTML a tag attributes { target, rel, title }
|
|
320
241
|
* @returns The LinkNode.
|
|
321
242
|
*/
|
|
322
|
-
function $createLinkNode(url, attributes) {
|
|
323
|
-
return
|
|
243
|
+
export function $createLinkNode(url, attributes) {
|
|
244
|
+
return $applyNodeReplacement(new LinkNode(url, attributes));
|
|
324
245
|
}
|
|
325
246
|
|
|
326
247
|
/**
|
|
@@ -328,76 +249,58 @@ function $createLinkNode(url, attributes) {
|
|
|
328
249
|
* @param node - The node to be checked.
|
|
329
250
|
* @returns true if node is a LinkNode, false otherwise.
|
|
330
251
|
*/
|
|
331
|
-
function $isLinkNode(node) {
|
|
252
|
+
export function $isLinkNode(node) {
|
|
332
253
|
return node instanceof LinkNode;
|
|
333
254
|
}
|
|
334
255
|
// Custom node type to override `canInsertTextAfter` that will
|
|
335
256
|
// allow typing within the link
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
rel: node.__rel,
|
|
376
|
-
target: node.__target,
|
|
377
|
-
title: node.__title
|
|
378
|
-
}, node.__key);
|
|
379
|
-
}
|
|
380
|
-
}, {
|
|
381
|
-
key: "importJSON",
|
|
382
|
-
value: function importJSON(serializedNode) {
|
|
383
|
-
var node = $createAutoLinkNode(serializedNode.url, {
|
|
384
|
-
rel: serializedNode.rel,
|
|
385
|
-
target: serializedNode.target,
|
|
386
|
-
title: serializedNode.title
|
|
257
|
+
export class AutoLinkNode extends LinkNode {
|
|
258
|
+
static getType() {
|
|
259
|
+
return "autolink";
|
|
260
|
+
}
|
|
261
|
+
static clone(node) {
|
|
262
|
+
return new AutoLinkNode(node.__url, {
|
|
263
|
+
rel: node.__rel,
|
|
264
|
+
target: node.__target,
|
|
265
|
+
title: node.__title
|
|
266
|
+
}, node.__key);
|
|
267
|
+
}
|
|
268
|
+
static importJSON(serializedNode) {
|
|
269
|
+
const node = $createAutoLinkNode(serializedNode.url, {
|
|
270
|
+
rel: serializedNode.rel,
|
|
271
|
+
target: serializedNode.target,
|
|
272
|
+
title: serializedNode.title
|
|
273
|
+
});
|
|
274
|
+
node.setFormat(serializedNode.format);
|
|
275
|
+
node.setIndent(serializedNode.indent);
|
|
276
|
+
node.setDirection(serializedNode.direction);
|
|
277
|
+
return node;
|
|
278
|
+
}
|
|
279
|
+
static importDOM() {
|
|
280
|
+
// TODO: Should link node should handle the import over autolink?
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
exportJSON() {
|
|
284
|
+
return {
|
|
285
|
+
...super.exportJSON(),
|
|
286
|
+
type: "autolink"
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
290
|
+
const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
|
|
291
|
+
if ($isElementNode(element)) {
|
|
292
|
+
const linkNode = $createAutoLinkNode(this.__url, {
|
|
293
|
+
rel: this.__rel,
|
|
294
|
+
target: this.__target,
|
|
295
|
+
title: this.__title
|
|
387
296
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
node.setDirection(serializedNode.direction);
|
|
391
|
-
return node;
|
|
392
|
-
}
|
|
393
|
-
}, {
|
|
394
|
-
key: "importDOM",
|
|
395
|
-
value: function importDOM() {
|
|
396
|
-
// TODO: Should link node should handle the import over autolink?
|
|
397
|
-
return null;
|
|
297
|
+
element.append(linkNode);
|
|
298
|
+
return linkNode;
|
|
398
299
|
}
|
|
399
|
-
|
|
400
|
-
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
401
304
|
/**
|
|
402
305
|
* Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
|
|
403
306
|
* during typing, which is especially useful when a button to generate a LinkNode is not practical.
|
|
@@ -405,8 +308,8 @@ var AutoLinkNode = exports.AutoLinkNode = /*#__PURE__*/function (_LinkNode) {
|
|
|
405
308
|
* @param attributes - Optional HTML a tag attributes. { target, rel, title }
|
|
406
309
|
* @returns The LinkNode.
|
|
407
310
|
*/
|
|
408
|
-
function $createAutoLinkNode(url, attributes) {
|
|
409
|
-
return
|
|
311
|
+
export function $createAutoLinkNode(url, attributes) {
|
|
312
|
+
return $applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
410
313
|
}
|
|
411
314
|
|
|
412
315
|
/**
|
|
@@ -414,9 +317,9 @@ function $createAutoLinkNode(url, attributes) {
|
|
|
414
317
|
* @param node - The node to be checked.
|
|
415
318
|
* @returns true if node is an AutoLinkNode, false otherwise.
|
|
416
319
|
*/
|
|
417
|
-
function $isAutoLinkNode(node) {
|
|
320
|
+
export function $isAutoLinkNode(node) {
|
|
418
321
|
return node instanceof AutoLinkNode;
|
|
419
322
|
}
|
|
420
|
-
|
|
323
|
+
export const TOGGLE_LINK_COMMAND = createCommand("TOGGLE_LINK_COMMAND");
|
|
421
324
|
|
|
422
325
|
//# sourceMappingURL=LinkNode.js.map
|