@lexical/selection 0.12.4 → 0.12.5
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/LexicalSelection.dev.js
CHANGED
|
@@ -146,7 +146,9 @@ function getStyleObjectFromRawCSS(css) {
|
|
|
146
146
|
for (const style of styles) {
|
|
147
147
|
if (style !== '') {
|
|
148
148
|
const [key, value] = style.split(/:([^]+)/); // split on first colon
|
|
149
|
-
|
|
149
|
+
if (key && value) {
|
|
150
|
+
styleObject[key.trim()] = value.trim();
|
|
151
|
+
}
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
return styleObject;
|
|
@@ -238,7 +240,7 @@ function $cloneWithProperties(node) {
|
|
|
238
240
|
* @returns The updated TextNode.
|
|
239
241
|
*/
|
|
240
242
|
function $sliceSelectedTextNodeContent(selection, textNode) {
|
|
241
|
-
if (textNode.isSelected() && !textNode.isSegmented() && !textNode.isToken() &&
|
|
243
|
+
if (textNode.isSelected() && !textNode.isSegmented() && !textNode.isToken() && lexical.$INTERNAL_isPointSelection(selection)) {
|
|
242
244
|
const anchorNode = selection.anchor.getNode();
|
|
243
245
|
const focusNode = selection.focus.getNode();
|
|
244
246
|
const isAnchor = textNode.is(anchorNode);
|
|
@@ -448,7 +450,7 @@ function $patchStyleText(selection, patch) {
|
|
|
448
450
|
const lastIndex = selectedNodesLength - 1;
|
|
449
451
|
let firstNode = selectedNodes[0];
|
|
450
452
|
let lastNode = selectedNodes[lastIndex];
|
|
451
|
-
if (selection.isCollapsed()) {
|
|
453
|
+
if (selection.isCollapsed() && lexical.$isRangeSelection(selection)) {
|
|
452
454
|
$patchStyle(selection, patch);
|
|
453
455
|
return;
|
|
454
456
|
}
|
package/LexicalSelection.js.flow
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type {
|
|
10
10
|
ElementNode,
|
|
11
|
-
GridSelection,
|
|
12
11
|
LexicalEditor,
|
|
13
12
|
LexicalNode,
|
|
14
13
|
NodeKey,
|
|
15
14
|
NodeSelection,
|
|
16
15
|
Point,
|
|
16
|
+
INTERNAL_PointSelection,
|
|
17
17
|
RangeSelection,
|
|
18
18
|
} from 'lexical';
|
|
19
19
|
declare export function $cloneWithProperties<T: LexicalNode>(node: T): T;
|
|
@@ -21,7 +21,7 @@ declare export function getStyleObjectFromCSS(css: string): {
|
|
|
21
21
|
[string]: string,
|
|
22
22
|
};
|
|
23
23
|
declare export function $patchStyleText(
|
|
24
|
-
selection:
|
|
24
|
+
selection: INTERNAL_PointSelection,
|
|
25
25
|
patch: {
|
|
26
26
|
[string]: string | null,
|
|
27
27
|
},
|
|
@@ -45,7 +45,7 @@ declare export function $moveCharacter(
|
|
|
45
45
|
): void;
|
|
46
46
|
declare export function $selectAll(selection: RangeSelection): void;
|
|
47
47
|
declare export function $wrapNodes(
|
|
48
|
-
selection:
|
|
48
|
+
selection: INTERNAL_PointSelection,
|
|
49
49
|
createElement: () => ElementNode,
|
|
50
50
|
wrappingElement?: ElementNode,
|
|
51
51
|
): void;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var k=require("lexical");let u=new Map;function v(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function w(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function y(a){let b={};a=a.split(";");for(let d of a)if(""!==d){let [f,c]=d.split(/:([^]+)/);b[f.trim()]=c.trim()}return b}function z(a){let b=u.get(a);void 0===b&&(b=y(a),u.set(a,b));return b}
|
|
7
|
+
'use strict';var k=require("lexical");let u=new Map;function v(a){for(;null!=a;){if(a.nodeType===Node.TEXT_NODE)return a;a=a.firstChild}return null}function w(a){let b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}function y(a){let b={};a=a.split(";");for(let d of a)if(""!==d){let [f,c]=d.split(/:([^]+)/);f&&c&&(b[f.trim()]=c.trim())}return b}function z(a){let b=u.get(a);void 0===b&&(b=y(a),u.set(a,b));return b}
|
|
8
8
|
function A(a){let b="";for(let d in a)d&&(b+=`${d}: ${a[d]};`);return b}function B(a,b){var d=z("getStyle"in a?a.getStyle():a.style);b=Object.entries(b).reduce((f,[c,g])=>{null===g?delete f[c]:f[c]=g;return f},{...d});d=A(b);a.setStyle(d);u.set(d,b)}
|
|
9
|
-
function C(a,b){var d=a.getNodes(),f=d.length;if(k.DEPRECATED_$isGridSelection(a)){var c=k.$createRangeSelection(),g=c.anchor,h=c.focus;for(var e=0;e<f;e++){var l=d[e];k.DEPRECATED_$isGridCellNode(l)&&(g.set(l.getKey(),0,"element"),h.set(l.getKey(),l.getChildrenSize(),"element"),C(k.$normalizeSelection__EXPERIMENTAL(c),b))}k.$setSelection(a)}else if(--f,c=d[0],g=d[f],a.isCollapsed())B(a,b);else{e=a.anchor;var m=a.focus;l=c.getTextContent().length;var p=m.offset,n=e.offset,
|
|
10
|
-
a=r?p:n;var q=r?e.type:m.type,t=r?m.type:e.type;m=r?m.key:e.key;k.$isTextNode(c)&&h===l&&(r=c.getNextSibling(),k.$isTextNode(r)&&(h=n=0,c=r));if(1===d.length)k.$isTextNode(c)&&(h="element"===q?0:n>p?p:n,a="element"===t?l:n>p?n:p,h!==a&&(0===h&&a===l?(B(c,b),c.select(h,a)):(d=c.splitText(h,a),d=0===h?d[0]:d[1],B(d,b),d.select(0,a-h))));else for(k.$isTextNode(c)&&h<c.getTextContentSize()&&(0!==h&&(c=c.splitText(h)[1],h=0,e.set(c.getKey(),h,"text")),B(c,b)),k.$isTextNode(g)&&
|
|
11
|
-
g.__key!==m&&0!==a&&(a=h),a!==h&&([g]=g.splitText(a)),0!==a&&B(g,b)),a=1;a<f;a++)h=d[a],e=h.getKey(),k.$isTextNode(h)&&e!==c.getKey()&&e!==g.getKey()&&!h.isToken()&&B(h,b)}}function D(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),d=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=d}}
|
|
9
|
+
function C(a,b){var d=a.getNodes(),f=d.length;if(k.DEPRECATED_$isGridSelection(a)){var c=k.$createRangeSelection(),g=c.anchor,h=c.focus;for(var e=0;e<f;e++){var l=d[e];k.DEPRECATED_$isGridCellNode(l)&&(g.set(l.getKey(),0,"element"),h.set(l.getKey(),l.getChildrenSize(),"element"),C(k.$normalizeSelection__EXPERIMENTAL(c),b))}k.$setSelection(a)}else if(--f,c=d[0],g=d[f],a.isCollapsed()&&k.$isRangeSelection(a))B(a,b);else{e=a.anchor;var m=a.focus;l=c.getTextContent().length;var p=m.offset,n=e.offset,
|
|
10
|
+
r=e.isBefore(m);h=r?n:p;a=r?p:n;var q=r?e.type:m.type,t=r?m.type:e.type;m=r?m.key:e.key;k.$isTextNode(c)&&h===l&&(r=c.getNextSibling(),k.$isTextNode(r)&&(h=n=0,c=r));if(1===d.length)k.$isTextNode(c)&&(h="element"===q?0:n>p?p:n,a="element"===t?l:n>p?n:p,h!==a&&(0===h&&a===l?(B(c,b),c.select(h,a)):(d=c.splitText(h,a),d=0===h?d[0]:d[1],B(d,b),d.select(0,a-h))));else for(k.$isTextNode(c)&&h<c.getTextContentSize()&&(0!==h&&(c=c.splitText(h)[1],h=0,e.set(c.getKey(),h,"text")),B(c,b)),k.$isTextNode(g)&&
|
|
11
|
+
(h=g.getTextContent().length,g.__key!==m&&0!==a&&(a=h),a!==h&&([g]=g.splitText(a)),0!==a&&B(g,b)),a=1;a<f;a++)h=d[a],e=h.getKey(),k.$isTextNode(h)&&e!==c.getKey()&&e!==g.getKey()&&!h.isToken()&&B(h,b)}}function D(a){for(;null!==a&&!k.$isRootOrShadowRoot(a);){let b=a.getLatest(),d=a.getParent();0===b.getChildrenSize()&&a.remove(!0);a=d}}
|
|
12
12
|
function E(a,b,d,f,c=null){if(0!==b.length){var g=b[0],h=new Map,e=[];g=k.$isElementNode(g)?g:g.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());for(var l=!1;null!==g;){var m=g.getPreviousSibling();if(null!==m){g=m;l=!0;break}g=g.getParentOrThrow();if(k.$isRootOrShadowRoot(g))break}m=new Set;for(var p=0;p<d;p++){var n=b[p];k.$isElementNode(n)&&0===n.getChildrenSize()&&m.add(n.getKey())}var r=new Set;for(p=0;p<d;p++){n=b[p];var q=n.getParent();null!==q&&q.isInline()&&(q=q.getParent());if(null!==
|
|
13
13
|
q&&k.$isLeafNode(n)&&!r.has(n.getKey())){if(n=q.getKey(),void 0===h.get(n)){let t=f();t.setFormat(q.getFormatType());t.setIndent(q.getIndent());e.push(t);h.set(n,t);q.getChildren().forEach(x=>{t.append(x);r.add(x.getKey());k.$isElementNode(x)&&x.getChildrenKeys().forEach(I=>r.add(I))});D(q)}}else m.has(n.getKey())&&(q=f(),q.setFormat(n.getFormatType()),q.setIndent(n.getIndent()),e.push(q),n.remove(!0))}if(null!==c)for(b=0;b<e.length;b++)c.append(e[b]);b=null;if(k.$isRootOrShadowRoot(g))if(l)if(null!==
|
|
14
14
|
c)g.insertAfter(c);else for(c=e.length-1;0<=c;c--)g.insertAfter(e[c]);else if(l=g.getFirstChild(),k.$isElementNode(l)&&(g=l),null===l)if(c)g.append(c);else for(c=0;c<e.length;c++)l=e[c],g.append(l),b=l;else if(null!==c)l.insertBefore(c);else for(g=0;g<e.length;g++)c=e[g],l.insertBefore(c),b=c;else if(c)g.insertAfter(c);else for(c=e.length-1;0<=c;c--)l=e[c],g.insertAfter(l),b=l;e=k.$getPreviousSelection();k.$isRangeSelection(e)&&e.anchor.getNode().isAttached()&&e.focus.getNode().isAttached()?k.$setSelection(e.clone()):
|
|
@@ -19,7 +19,7 @@ exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().ge
|
|
|
19
19
|
exports.$selectAll=function(a){let b=a.anchor;a=a.focus;var d=b.getNode().getTopLevelElementOrThrow().getParentOrThrow();let f=d.getFirstDescendant();d=d.getLastDescendant();let c="element",g="element",h=0;k.$isTextNode(f)?c="text":k.$isElementNode(f)||null===f||(f=f.getParentOrThrow());k.$isTextNode(d)?(g="text",h=d.getTextContentSize()):k.$isElementNode(d)||null===d||(d=d.getParentOrThrow());f&&d&&(b.set(f.getKey(),0,c),a.set(d.getKey(),h,g))};
|
|
20
20
|
exports.$setBlocksType=function(a,b){if("root"===a.anchor.key){b=b();var d=k.$getRoot();(a=d.getFirstChild())?a.replace(b,!0):d.append(b)}else{d=a.getNodes();for(a=a.anchor.getNode();null!==a&&null!==a.getParent()&&!H(a);)a=a.getParentOrThrow();(a=H(a)?a:null)&&-1===d.indexOf(a)&&d.push(a);for(a=0;a<d.length;a++){let f=d[a];if(!H(f))continue;let c=b();c.setFormat(f.getFormatType());c.setIndent(f.getIndent());f.replace(c,!0)}}};
|
|
21
21
|
exports.$shouldOverrideDefaultCharacterSelection=function(a,b){a=k.$getAdjacentNode(a.focus,b);return k.$isDecoratorNode(a)&&!a.isIsolated()||k.$isElementNode(a)&&!a.isInline()&&!a.canBeEmpty()};
|
|
22
|
-
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected()&&!b.isSegmented()&&!b.isToken()&&
|
|
22
|
+
exports.$sliceSelectedTextNodeContent=function(a,b){if(b.isSelected()&&!b.isSegmented()&&!b.isToken()&&k.$INTERNAL_isPointSelection(a)){var d=a.anchor.getNode(),f=a.focus.getNode(),c=b.is(d),g=b.is(f);if(c||g){c=a.isBackward();let [h,e]=a.getCharacterOffsets();a=d.is(f);g=b.is(c?f:d);f=b.is(c?d:f);d=0;let l=void 0;a?(d=h>e?e:h,l=h>e?h:e):g?(d=c?e:h,l=void 0):f&&(c=c?h:e,d=0,l=c);b.__text=b.__text.slice(d,l)}}return b};
|
|
23
23
|
exports.$wrapNodes=function(a,b,d=null){var f=a.getNodes();let c=f.length;var g=a.anchor;if(0===c||1===c&&"element"===g.type&&0===g.getNode().getChildrenSize()){a="text"===g.type?g.getNode().getParentOrThrow():g.getNode();f=a.getChildren();let e=b();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());f.forEach(l=>e.append(l));d&&(e=d.append(e));a.replace(e)}else{g=null;var h=[];for(let e=0;e<c;e++){let l=f[e];k.$isRootOrShadowRoot(l)?(E(a,h,h.length,b,d),h=[],g=l):null===g||null!==g&&k.$hasAncestor(l,
|
|
24
24
|
g)?h.push(l):(E(a,h,h.length,b,d),h=[l])}E(a,h,h.length,b,d)}};
|
|
25
25
|
exports.createDOMRange=function(a,b,d,f,c){let g=b.getKey(),h=f.getKey(),e=document.createRange(),l=a.getElementByKey(g);a=a.getElementByKey(h);k.$isTextNode(b)&&(l=v(l));k.$isTextNode(f)&&(a=v(a));if(void 0===b||void 0===f||null===l||null===a)return null;"BR"===l.nodeName&&([l,d]=w(l));"BR"===a.nodeName&&([a,c]=w(a));b=l.firstChild;l===a&&null!=b&&"BR"===b.nodeName&&0===d&&0===c&&(c=1);try{e.setStart(l,d),e.setEnd(a,c)}catch(m){return null}!e.collapsed||d===c&&g===h||(e.setStart(a,c),e.setEnd(l,
|
package/lexical-node.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { BaseSelection, INTERNAL_PointSelection, LexicalEditor, LexicalNode, Point, TextNode } from 'lexical';
|
|
9
9
|
/**
|
|
10
10
|
* Returns a copy of a node, but generates a new key for the copy.
|
|
11
11
|
* @param node - The node to be cloned.
|
|
@@ -19,7 +19,7 @@ export declare function $cloneWithProperties<T extends LexicalNode>(node: T): T;
|
|
|
19
19
|
* @param textNode - The TextNode to be edited.
|
|
20
20
|
* @returns The updated TextNode.
|
|
21
21
|
*/
|
|
22
|
-
export declare function $sliceSelectedTextNodeContent(selection:
|
|
22
|
+
export declare function $sliceSelectedTextNodeContent(selection: BaseSelection, textNode: TextNode): LexicalNode;
|
|
23
23
|
/**
|
|
24
24
|
* Determines if the current selection is at the end of the node.
|
|
25
25
|
* @param point - The point of the selection to test.
|
|
@@ -47,4 +47,4 @@ export declare function $addNodeStyle(node: TextNode): void;
|
|
|
47
47
|
* @param selection - The selected node(s) to update.
|
|
48
48
|
* @param patch - The patch to apply, which can include multiple styles. { CSSProperty: value }
|
|
49
49
|
*/
|
|
50
|
-
export declare function $patchStyleText(selection:
|
|
50
|
+
export declare function $patchStyleText(selection: INTERNAL_PointSelection, patch: Record<string, string | null>): void;
|
package/package.json
CHANGED
package/range-selection.d.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type { DecoratorNode, ElementNode,
|
|
8
|
+
import type { DecoratorNode, ElementNode, INTERNAL_PointSelection, LexicalNode, RangeSelection } from 'lexical';
|
|
9
9
|
/**
|
|
10
10
|
* Converts all nodes in the selection that are of one block type to another.
|
|
11
11
|
* @param selection - The selected blocks to be converted.
|
|
12
12
|
* @param createElement - The function that creates the node. eg. $createParagraphNode.
|
|
13
13
|
*/
|
|
14
|
-
export declare function $setBlocksType(selection:
|
|
14
|
+
export declare function $setBlocksType(selection: INTERNAL_PointSelection, createElement: () => ElementNode): void;
|
|
15
15
|
/**
|
|
16
16
|
* @deprecated
|
|
17
17
|
* Wraps all nodes in the selection into another node of the type returned by createElement.
|
|
@@ -19,7 +19,7 @@ export declare function $setBlocksType(selection: RangeSelection | GridSelection
|
|
|
19
19
|
* @param createElement - A function that creates the wrapping ElementNode. eg. $createParagraphNode.
|
|
20
20
|
* @param wrappingElement - An element to append the wrapped selection and its children to.
|
|
21
21
|
*/
|
|
22
|
-
export declare function $wrapNodes(selection:
|
|
22
|
+
export declare function $wrapNodes(selection: INTERNAL_PointSelection, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
|
|
23
23
|
/**
|
|
24
24
|
* Wraps each node into a new ElementNode.
|
|
25
25
|
* @param selection - The selection of nodes to wrap.
|
|
@@ -29,7 +29,7 @@ export declare function $wrapNodes(selection: RangeSelection | GridSelection, cr
|
|
|
29
29
|
* @param wrappingElement - An element to wrap all the nodes into.
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
export declare function $wrapNodesImpl(selection:
|
|
32
|
+
export declare function $wrapNodesImpl(selection: INTERNAL_PointSelection, nodes: LexicalNode[], nodesLength: number, createElement: () => ElementNode, wrappingElement?: null | ElementNode): void;
|
|
33
33
|
/**
|
|
34
34
|
* Determines if the default character selection should be overridden. Used with DecoratorNodes
|
|
35
35
|
* @param selection - The selection whose default character selection may need to be overridden.
|