@webiny/lexical-nodes 6.0.0-beta.0 → 6.0.0-rc.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 +24 -22
- package/FontColorNode.js +114 -103
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.d.ts +30 -20
- package/HeadingNode.js +185 -176
- package/HeadingNode.js.map +1 -1
- package/ImageNode.d.ts +2 -12
- package/ImageNode.js +119 -193
- package/ImageNode.js.map +1 -1
- package/LinkNode.d.ts +6 -6
- package/LinkNode.js +249 -347
- package/LinkNode.js.map +1 -1
- package/ListItemNode.d.ts +6 -5
- package/ListItemNode.js +275 -352
- package/ListItemNode.js.map +1 -1
- package/ListNode.d.ts +32 -19
- package/ListNode.js +170 -210
- package/ListNode.js.map +1 -1
- package/ParagraphNode.d.ts +30 -20
- package/ParagraphNode.js +144 -201
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.d.ts +27 -20
- package/QuoteNode.js +102 -208
- 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 +80 -95
- 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 +22 -19
- package/prepareLexicalState.d.ts +2 -0
- package/prepareLexicalState.js +53 -0
- package/prepareLexicalState.js.map +1 -0
- package/types.d.ts +5 -9
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/clearNodeFormating.d.ts +2 -2
- 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 +10 -17
- 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 +14 -4
- package/utils/listNode.js +43 -49
- 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 -147
- 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,23 +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 _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
17
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
var _utils = require("@lexical/utils");
|
|
20
|
-
var _lexical = require("lexical");
|
|
21
1
|
/** @module @lexical/link */
|
|
22
2
|
/**
|
|
23
3
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -27,279 +7,219 @@ var _lexical = require("lexical");
|
|
|
27
7
|
*
|
|
28
8
|
*/
|
|
29
9
|
|
|
30
|
-
|
|
10
|
+
import { $applyNodeReplacement, $isElementNode, $isRangeSelection, createCommand, ElementNode, addClassNamesToElement, isHTMLAnchorElement } from "lexical";
|
|
11
|
+
const SUPPORTED_URL_PROTOCOLS = new Set(["http:", "https:", "mailto:", "sms:", "tel:"]);
|
|
31
12
|
|
|
32
13
|
/** @noInheritDoc */
|
|
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
|
-
|
|
74
|
-
return element;
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "updateDOM",
|
|
78
|
-
value: function updateDOM(prevNode, anchor) {
|
|
79
|
-
var url = this.__url;
|
|
80
|
-
var target = this.__target;
|
|
81
|
-
var rel = this.__rel;
|
|
82
|
-
var title = this.__title;
|
|
83
|
-
var alt = this.__alt;
|
|
84
|
-
if (url !== prevNode.__url) {
|
|
85
|
-
anchor.href = url;
|
|
86
|
-
}
|
|
87
|
-
if (target !== prevNode.__target) {
|
|
88
|
-
if (target) {
|
|
89
|
-
anchor.target = target;
|
|
90
|
-
} else {
|
|
91
|
-
anchor.removeAttribute("target");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (rel !== prevNode.__rel) {
|
|
95
|
-
if (rel) {
|
|
96
|
-
anchor.rel = rel;
|
|
97
|
-
} else {
|
|
98
|
-
anchor.removeAttribute("rel");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (title !== prevNode.__title) {
|
|
102
|
-
if (title) {
|
|
103
|
-
anchor.title = title;
|
|
104
|
-
} else {
|
|
105
|
-
anchor.removeAttribute("title");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (alt !== prevNode.__alt) {
|
|
109
|
-
if (alt) {
|
|
110
|
-
anchor.setAttribute("alt", alt);
|
|
111
|
-
} else {
|
|
112
|
-
anchor.removeAttribute("alt");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "sanitizeUrl",
|
|
119
|
-
value: function sanitizeUrl(url) {
|
|
120
|
-
try {
|
|
121
|
-
var parsedUrl = new URL(url);
|
|
122
|
-
// eslint-disable-next-line no-script-url
|
|
123
|
-
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
124
|
-
return "about:blank";
|
|
125
|
-
}
|
|
126
|
-
} catch (_unused) {
|
|
127
|
-
return url;
|
|
128
|
-
}
|
|
129
|
-
return url;
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
key: "exportJSON",
|
|
133
|
-
value: function exportJSON() {
|
|
134
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(LinkNode.prototype), "exportJSON", this).call(this)), {}, {
|
|
135
|
-
rel: this.getRel(),
|
|
136
|
-
target: this.getTarget(),
|
|
137
|
-
title: this.getTitle(),
|
|
138
|
-
alt: this.getAlt(),
|
|
139
|
-
type: "link",
|
|
140
|
-
url: this.getURL(),
|
|
141
|
-
version: 1
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}, {
|
|
145
|
-
key: "getURL",
|
|
146
|
-
value: function getURL() {
|
|
147
|
-
return this.getLatest().__url;
|
|
148
|
-
}
|
|
149
|
-
}, {
|
|
150
|
-
key: "setURL",
|
|
151
|
-
value: function setURL(url) {
|
|
152
|
-
var writable = this.getWritable();
|
|
153
|
-
writable.__url = url;
|
|
154
|
-
}
|
|
155
|
-
}, {
|
|
156
|
-
key: "getTarget",
|
|
157
|
-
value: function getTarget() {
|
|
158
|
-
return this.getLatest().__target;
|
|
159
|
-
}
|
|
160
|
-
}, {
|
|
161
|
-
key: "setTarget",
|
|
162
|
-
value: function setTarget(target) {
|
|
163
|
-
var writable = this.getWritable();
|
|
164
|
-
writable.__target = target;
|
|
165
|
-
}
|
|
166
|
-
}, {
|
|
167
|
-
key: "getRel",
|
|
168
|
-
value: function getRel() {
|
|
169
|
-
return this.getLatest().__rel;
|
|
170
|
-
}
|
|
171
|
-
}, {
|
|
172
|
-
key: "setRel",
|
|
173
|
-
value: function setRel(rel) {
|
|
174
|
-
var writable = this.getWritable();
|
|
175
|
-
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;
|
|
176
55
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
value: function getTitle() {
|
|
180
|
-
return this.getLatest().__title;
|
|
56
|
+
if (this.__rel !== null) {
|
|
57
|
+
element.rel = this.__rel;
|
|
181
58
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
value: function setTitle(title) {
|
|
185
|
-
var writable = this.getWritable();
|
|
186
|
-
writable.__title = title;
|
|
59
|
+
if (this.__title !== null) {
|
|
60
|
+
element.title = this.__title;
|
|
187
61
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
value: function getAlt() {
|
|
191
|
-
return this.__alt;
|
|
62
|
+
if (this.__alt) {
|
|
63
|
+
element.setAttribute("alt", this.__alt);
|
|
192
64
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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;
|
|
198
76
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if ((0, _lexical.$isElementNode)(element)) {
|
|
205
|
-
var linkNode = $createLinkNode(this.__url, {
|
|
206
|
-
rel: this.__rel,
|
|
207
|
-
target: this.__target,
|
|
208
|
-
title: this.__title,
|
|
209
|
-
alt: this.__alt
|
|
210
|
-
});
|
|
211
|
-
element.append(linkNode);
|
|
212
|
-
return linkNode;
|
|
77
|
+
if (target !== prevNode.__target) {
|
|
78
|
+
if (target) {
|
|
79
|
+
anchor.target = target;
|
|
80
|
+
} else {
|
|
81
|
+
anchor.removeAttribute("target");
|
|
213
82
|
}
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
}, {
|
|
217
|
-
key: "canInsertTextBefore",
|
|
218
|
-
value: function canInsertTextBefore() {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
}, {
|
|
222
|
-
key: "canInsertTextAfter",
|
|
223
|
-
value: function canInsertTextAfter() {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
}, {
|
|
227
|
-
key: "canBeEmpty",
|
|
228
|
-
value: function canBeEmpty() {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
}, {
|
|
232
|
-
key: "isInline",
|
|
233
|
-
value: function isInline() {
|
|
234
|
-
return true;
|
|
235
83
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
84
|
+
if (rel !== prevNode.__rel) {
|
|
85
|
+
if (rel) {
|
|
86
|
+
anchor.rel = rel;
|
|
87
|
+
} else {
|
|
88
|
+
anchor.removeAttribute("rel");
|
|
241
89
|
}
|
|
242
|
-
var anchorNode = selection.anchor.getNode();
|
|
243
|
-
var focusNode = selection.focus.getNode();
|
|
244
|
-
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
|
|
245
90
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
/** @internal */
|
|
253
|
-
|
|
254
|
-
/** @internal */
|
|
255
|
-
|
|
256
|
-
/** @internal */
|
|
257
|
-
|
|
258
|
-
function getType() {
|
|
259
|
-
return "link";
|
|
91
|
+
if (title !== prevNode.__title) {
|
|
92
|
+
if (title) {
|
|
93
|
+
anchor.title = title;
|
|
94
|
+
} else {
|
|
95
|
+
anchor.removeAttribute("title");
|
|
96
|
+
}
|
|
260
97
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
title: node.__title,
|
|
268
|
-
alt: node.__alt
|
|
269
|
-
}, node.__key);
|
|
98
|
+
if (alt !== prevNode.__alt) {
|
|
99
|
+
if (alt) {
|
|
100
|
+
anchor.setAttribute("alt", alt);
|
|
101
|
+
} else {
|
|
102
|
+
anchor.removeAttribute("alt");
|
|
103
|
+
}
|
|
270
104
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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;
|
|
282
135
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
|
291
192
|
});
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
node.setDirection(serializedNode.direction);
|
|
295
|
-
return node;
|
|
193
|
+
element.append(linkNode);
|
|
194
|
+
return linkNode;
|
|
296
195
|
}
|
|
297
|
-
|
|
298
|
-
}
|
|
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
|
+
}
|
|
299
219
|
function convertAnchorElement(domNode) {
|
|
300
|
-
|
|
301
|
-
if (
|
|
302
|
-
|
|
220
|
+
let node = null;
|
|
221
|
+
if (isHTMLAnchorElement(domNode)) {
|
|
222
|
+
const content = domNode.textContent;
|
|
303
223
|
if (content !== null && content !== "" || domNode.children.length > 0) {
|
|
304
224
|
node = $createLinkNode(domNode.getAttribute("href") || "", {
|
|
305
225
|
rel: domNode.getAttribute("rel"),
|
|
@@ -310,7 +230,7 @@ function convertAnchorElement(domNode) {
|
|
|
310
230
|
}
|
|
311
231
|
}
|
|
312
232
|
return {
|
|
313
|
-
node
|
|
233
|
+
node
|
|
314
234
|
};
|
|
315
235
|
}
|
|
316
236
|
|
|
@@ -320,8 +240,8 @@ function convertAnchorElement(domNode) {
|
|
|
320
240
|
* @param attributes - Optional HTML a tag attributes { target, rel, title }
|
|
321
241
|
* @returns The LinkNode.
|
|
322
242
|
*/
|
|
323
|
-
function $createLinkNode(url, attributes) {
|
|
324
|
-
return
|
|
243
|
+
export function $createLinkNode(url, attributes) {
|
|
244
|
+
return $applyNodeReplacement(new LinkNode(url, attributes));
|
|
325
245
|
}
|
|
326
246
|
|
|
327
247
|
/**
|
|
@@ -329,76 +249,58 @@ function $createLinkNode(url, attributes) {
|
|
|
329
249
|
* @param node - The node to be checked.
|
|
330
250
|
* @returns true if node is a LinkNode, false otherwise.
|
|
331
251
|
*/
|
|
332
|
-
function $isLinkNode(node) {
|
|
252
|
+
export function $isLinkNode(node) {
|
|
333
253
|
return node instanceof LinkNode;
|
|
334
254
|
}
|
|
335
255
|
// Custom node type to override `canInsertTextAfter` that will
|
|
336
256
|
// allow typing within the link
|
|
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
|
-
|
|
376
|
-
rel: node.__rel,
|
|
377
|
-
target: node.__target,
|
|
378
|
-
title: node.__title
|
|
379
|
-
}, node.__key);
|
|
380
|
-
}
|
|
381
|
-
}, {
|
|
382
|
-
key: "importJSON",
|
|
383
|
-
value: function importJSON(serializedNode) {
|
|
384
|
-
var node = $createAutoLinkNode(serializedNode.url, {
|
|
385
|
-
rel: serializedNode.rel,
|
|
386
|
-
target: serializedNode.target,
|
|
387
|
-
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
|
|
388
296
|
});
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
node.setDirection(serializedNode.direction);
|
|
392
|
-
return node;
|
|
393
|
-
}
|
|
394
|
-
}, {
|
|
395
|
-
key: "importDOM",
|
|
396
|
-
value: function importDOM() {
|
|
397
|
-
// TODO: Should link node should handle the import over autolink?
|
|
398
|
-
return null;
|
|
297
|
+
element.append(linkNode);
|
|
298
|
+
return linkNode;
|
|
399
299
|
}
|
|
400
|
-
|
|
401
|
-
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
402
304
|
/**
|
|
403
305
|
* Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
|
|
404
306
|
* during typing, which is especially useful when a button to generate a LinkNode is not practical.
|
|
@@ -406,8 +308,8 @@ var AutoLinkNode = exports.AutoLinkNode = /*#__PURE__*/function (_LinkNode) {
|
|
|
406
308
|
* @param attributes - Optional HTML a tag attributes. { target, rel, title }
|
|
407
309
|
* @returns The LinkNode.
|
|
408
310
|
*/
|
|
409
|
-
function $createAutoLinkNode(url, attributes) {
|
|
410
|
-
return
|
|
311
|
+
export function $createAutoLinkNode(url, attributes) {
|
|
312
|
+
return $applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
411
313
|
}
|
|
412
314
|
|
|
413
315
|
/**
|
|
@@ -415,9 +317,9 @@ function $createAutoLinkNode(url, attributes) {
|
|
|
415
317
|
* @param node - The node to be checked.
|
|
416
318
|
* @returns true if node is an AutoLinkNode, false otherwise.
|
|
417
319
|
*/
|
|
418
|
-
function $isAutoLinkNode(node) {
|
|
320
|
+
export function $isAutoLinkNode(node) {
|
|
419
321
|
return node instanceof AutoLinkNode;
|
|
420
322
|
}
|
|
421
|
-
|
|
323
|
+
export const TOGGLE_LINK_COMMAND = createCommand("TOGGLE_LINK_COMMAND");
|
|
422
324
|
|
|
423
325
|
//# sourceMappingURL=LinkNode.js.map
|