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