@lexical/mark 0.4.0 → 0.5.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/LexicalMark.dev.js +32 -11
- package/LexicalMark.prod.js +2 -2
- package/package.json +3 -3
package/LexicalMark.dev.js
CHANGED
|
@@ -214,15 +214,16 @@ function $wrapSelectionInMarkNode(selection, isBackward, id) {
|
|
|
214
214
|
const startOffset = isBackward ? focusOffset : anchorOffset;
|
|
215
215
|
const endOffset = isBackward ? anchorOffset : focusOffset;
|
|
216
216
|
let currentNodeParent;
|
|
217
|
-
let
|
|
217
|
+
let lastCreatedMarkNode; // We only want wrap adjacent text nodes, line break nodes
|
|
218
218
|
// and inline element nodes. For decorator nodes and block
|
|
219
|
-
// element nodes, we
|
|
220
|
-
// after, if there are more nodes.
|
|
219
|
+
// element nodes, we step out of their boundary and start
|
|
220
|
+
// again after, if there are more nodes.
|
|
221
221
|
|
|
222
222
|
for (let i = 0; i < nodesLength; i++) {
|
|
223
223
|
const node = nodes[i];
|
|
224
224
|
|
|
225
|
-
if (lexical.$isElementNode(
|
|
225
|
+
if (lexical.$isElementNode(lastCreatedMarkNode) && lastCreatedMarkNode.isParentOf(node)) {
|
|
226
|
+
// If the current node is a child of the last created mark node, there is nothing to do here
|
|
226
227
|
continue;
|
|
227
228
|
}
|
|
228
229
|
|
|
@@ -231,6 +232,7 @@ function $wrapSelectionInMarkNode(selection, isBackward, id) {
|
|
|
231
232
|
let targetNode = null;
|
|
232
233
|
|
|
233
234
|
if (lexical.$isTextNode(node)) {
|
|
235
|
+
// Case 1: The node is a text node and we can split it
|
|
234
236
|
const textContentSize = node.getTextContentSize();
|
|
235
237
|
const startTextOffset = isFirstNode ? startOffset : 0;
|
|
236
238
|
const endTextOffset = isLastNode ? endOffset : textContentSize;
|
|
@@ -241,32 +243,51 @@ function $wrapSelectionInMarkNode(selection, isBackward, id) {
|
|
|
241
243
|
|
|
242
244
|
const splitNodes = node.splitText(startTextOffset, endTextOffset);
|
|
243
245
|
targetNode = splitNodes.length > 1 && (splitNodes.length === 3 || isFirstNode && !isLastNode || endTextOffset === textContentSize) ? splitNodes[1] : splitNodes[0];
|
|
246
|
+
} else if ($isMarkNode(node)) {
|
|
247
|
+
// Case 2: the node is a mark node and we can ignore it as a target,
|
|
248
|
+
// moving on to its children. Note that when we make a mark inside
|
|
249
|
+
// another mark, it may utlimately be unnested by a call to
|
|
250
|
+
// `registerNestedElementResolver<MarkNode>` somewhere else in the
|
|
251
|
+
// codebase.
|
|
252
|
+
continue;
|
|
244
253
|
} else if (lexical.$isElementNode(node) && node.isInline()) {
|
|
254
|
+
// Case 3: inline element nodes can be added in their entirety to the new
|
|
255
|
+
// mark
|
|
245
256
|
targetNode = node;
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
if (targetNode !== null) {
|
|
260
|
+
// Now that we have a target node for wrapping with a mark, we can run
|
|
261
|
+
// through special cases.
|
|
249
262
|
if (targetNode && targetNode.is(currentNodeParent)) {
|
|
263
|
+
// The current node is a child of the target node to be wrapped, there
|
|
264
|
+
// is nothing to do here.
|
|
250
265
|
continue;
|
|
251
266
|
}
|
|
252
267
|
|
|
253
268
|
const parentNode = targetNode.getParent();
|
|
254
269
|
|
|
255
270
|
if (parentNode == null || !parentNode.is(currentNodeParent)) {
|
|
256
|
-
|
|
271
|
+
// If the parent node is not the current node's parent node, we can
|
|
272
|
+
// clear the last created mark node.
|
|
273
|
+
lastCreatedMarkNode = undefined;
|
|
257
274
|
}
|
|
258
275
|
|
|
259
276
|
currentNodeParent = parentNode;
|
|
260
277
|
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
278
|
+
if (lastCreatedMarkNode === undefined) {
|
|
279
|
+
// If we don't have a created mark node, we can make one
|
|
280
|
+
lastCreatedMarkNode = $createMarkNode([id]);
|
|
281
|
+
targetNode.insertBefore(lastCreatedMarkNode);
|
|
282
|
+
} // Add the target node to be wrapped in the latest created mark node
|
|
283
|
+
|
|
265
284
|
|
|
266
|
-
|
|
285
|
+
lastCreatedMarkNode.append(targetNode);
|
|
267
286
|
} else {
|
|
287
|
+
// If we don't have a target node to wrap we can clear our state and
|
|
288
|
+
// continue on with the next node
|
|
268
289
|
currentNodeParent = undefined;
|
|
269
|
-
|
|
290
|
+
lastCreatedMarkNode = undefined;
|
|
270
291
|
}
|
|
271
292
|
}
|
|
272
293
|
}
|
package/LexicalMark.prod.js
CHANGED
|
@@ -10,5 +10,5 @@ m.addClassNamesToElement(b,a.theme.markOverlap);return b}updateDOM(a,b,c){a=a.__
|
|
|
10
10
|
this.getWritable();if(q(b)){let c=b.__ids;b.__ids=c;for(b=0;b<c.length;b++)if(a===c[b]){c.splice(b,1);break}}}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(l.$isElementNode(a)){let b=p(this.__ids);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b,c){if(!l.$isRangeSelection(b)||"html"===c)return!1;let e=b.anchor,d=b.focus;a=e.getNode();c=d.getNode();b=b.isBackward()?e.offset-
|
|
11
11
|
d.offset:d.offset-e.offset;return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b}excludeFromCopy(a){return"clone"!==a}}function p(a){return new n(a)}function q(a){return a instanceof n}exports.$createMarkNode=p;exports.$getMarkIDs=function(a,b){for(;null!==a;){if(q(a))return a.getIDs();if(l.$isTextNode(a)&&b===a.getTextContentSize()){let c=a.getNextSibling();if(q(c))return c.getIDs()}a=a.getParent()}return null};exports.$isMarkNode=q;
|
|
12
12
|
exports.$unwrapMarkNode=function(a){let b=a.getChildren(),c=null;for(let e=0;e<b.length;e++){let d=b[e];null===c?a.insertBefore(d):c.insertAfter(d);c=d}a.remove()};
|
|
13
|
-
exports.$wrapSelectionInMarkNode=function(a,b,c){let e=a.getNodes();var d=a.anchor.offset,h=a.focus.offset;a=e.length;let w=b?h:d;b=b?d:h;let r,k;for(d=0;d<a;d++){var f=e[d];if(l.$isElementNode(k)&&k.isParentOf(f))continue;h=0===d;let u=d===a-1;var g=null;if(l.$isTextNode(f)){g=f.getTextContentSize();let v=h?w:0,t=u?b:g;if(0===v&&0===t)continue;f=f.splitText(v,t);g=1<f.length&&(3===f.length||h&&!u||t===g)?f[1]:f[0]}else l.$isElementNode(f)&&f.isInline()&&(g=f);null!==g?g&&g.is(r)||
|
|
14
|
-
null!=h&&h.is(r)||(k=void 0),r=h,void 0===k&&(k=p([c]),g.insertBefore(k)),k.append(g)):k=r=void 0}};exports.MarkNode=n
|
|
13
|
+
exports.$wrapSelectionInMarkNode=function(a,b,c){let e=a.getNodes();var d=a.anchor.offset,h=a.focus.offset;a=e.length;let w=b?h:d;b=b?d:h;let r,k;for(d=0;d<a;d++){var f=e[d];if(l.$isElementNode(k)&&k.isParentOf(f))continue;h=0===d;let u=d===a-1;var g=null;if(l.$isTextNode(f)){g=f.getTextContentSize();let v=h?w:0,t=u?b:g;if(0===v&&0===t)continue;f=f.splitText(v,t);g=1<f.length&&(3===f.length||h&&!u||t===g)?f[1]:f[0]}else if(q(f))continue;else l.$isElementNode(f)&&f.isInline()&&(g=f);null!==g?g&&g.is(r)||
|
|
14
|
+
(h=g.getParent(),null!=h&&h.is(r)||(k=void 0),r=h,void 0===k&&(k=p([c]),g.insertBefore(k)),k.append(g)):k=r=void 0}};exports.MarkNode=n
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"mark"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.5.0",
|
|
12
12
|
"main": "LexicalMark.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.5.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.5.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|