@lexical/selection 0.2.1 → 0.2.4

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.
@@ -459,7 +459,7 @@ function $removeParentEmptyElements(startingNode) {
459
459
  const parentNode = node.getParent();
460
460
 
461
461
  if (latest.__children.length === 0) {
462
- node.remove();
462
+ node.remove(true);
463
463
  }
464
464
 
465
465
  node = parentNode;
@@ -10,7 +10,7 @@ e.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
10
10
  function x(a){if(l.$isRangeSelection(a)){var c=a.anchor,b=a.focus,g=c.getCharacterOffset();const n=b.getCharacterOffset();var h=c.getNode(),e=b.getNode(),d=h.getParentOrThrow();if(h===e&&l.$isTextNode(h)&&(d.canBeEmpty()||1<d.getChildrenSize()))return a=u(h),h=n>g,a.__text=a.__text.slice(h?g:n,h?n:g),g=a.getKey(),{nodeMap:[[g,a]],range:[g]};a=a.getNodes();if(0===a.length)return{nodeMap:[],range:[]};h=a.length;e=a[0];d=e.getParent();if(null!==d&&(!d.canBeEmpty()||l.$isRootNode(d))){var f=d.__children;
11
11
  if(f.length===h){var k=!0;for(var m=0;m<f.length;m++)if(f[m]!==a[m].__key){k=!1;break}k&&(h++,a.push(d))}}d=a[h-1];c=c.isBefore(b);b=new Map;f=[];w(e,c?g:n,!0,f,b);for(e=0;e<h;e++)if(k=a[e],m=k.getKey(),!(b.has(m)||l.$isElementNode(k)&&k.excludeFromCopy())){const r=u(k);l.$isRootNode(k.getParent())&&f.push(k.getKey());b.set(m,r)}w(d,c?n:g,!1,f,b);return{nodeMap:Array.from(b.entries()),range:f}}if(l.$isGridSelection(a))return{nodeMap:a.getNodes().map(n=>{const r=n.getKey();n=u(n);return[r,n]}),range:[a.gridKey]};
12
12
  throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");}function y(a){return t.get(a)||null}function z(a,c){var b=y(a.getStyle());c=b?{...b,...c}:c;b="";for(g in c)g&&(b+=`${g}: ${c[g]};`);var g=b;a.setStyle(g);t.set(g,c)}function A(a,c,b,g){a.modify(c?"extend":"move",b,g)}function B(a){a=a.anchor.getNode();return"rtl"===(l.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
13
- function C(a){for(;null!==a&&!l.$isRootNode(a);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove();a=b}}exports.$cloneContents=function(a){return x(a)};
13
+ function C(a){for(;null!==a&&!l.$isRootNode(a);){const c=a.getLatest(),b=a.getParent();0===c.__children.length&&a.remove(!0);a=b}}exports.$cloneContents=function(a){return x(a)};
14
14
  exports.$getSelectionStyleValueForProperty=function(a,c,b=""){let g=null;const h=a.getNodes();var e=a.anchor,d=a.focus,f=a.isBackward();a=f?d.offset:e.offset;e=f?d.getNode():e.getNode();for(d=0;d<h.length;d++){var k=h[d];if((0===d||0!==a||!k.is(e))&&l.$isTextNode(k)){f=c;var m=b;k=k.getStyle();k=y(k);f=null!==k?k[f]||m:m;if(null===g)g=f;else if(g!==f){g="";break}}}return null===g?b:g};exports.$isAtNodeEnd=function(a){return"text"===a.type?a.offset===a.getNode().getTextContentSize():a.offset===a.getNode().getChildrenSize()};
15
15
  exports.$isParentElementRTL=B;exports.$moveCaretSelection=A;exports.$moveCharacter=function(a,c,b){const g=B(a);A(a,c,b?!g:g,"character")};
16
16
  exports.$patchStyleText=function(a,c){var b=a.getNodes();const g=b.length-1;let h=b[0],e=b[g];if(!a.isCollapsed()){var d=a.anchor,f=a.focus;a=h.getTextContent().length;var k=f.offset,m=d.offset;d=(f=d.isBefore(f))?m:k;f=f?k:m;if(d===h.getTextContentSize()){const n=h.getNextSibling();l.$isTextNode(n)&&(d=m=0,h=n)}if(h.is(e))l.$isTextNode(h)&&(d=m>k?k:m,f=m>k?m:k,d!==f&&(0===d&&f===a?(z(h,c),h.select(d,f)):(b=h.splitText(d,f),b=0===d?b[0]:b[1],z(b,c),b.select(0,f-d))));else for(l.$isTextNode(h)&&(0!==
package/README.md CHANGED
@@ -1,3 +1,127 @@
1
1
  # `@lexical/selection`
2
2
 
3
- This package contains utilities and helpers for handling Lexical selection.
3
+ This package contains selection helpers for Lexical.
4
+
5
+ ### Methods
6
+
7
+ #### `$cloneContents`
8
+
9
+ Clones the Lexical nodes in the selection, returning a map of Key -> LexicalNode and a list containing the keys
10
+ of all direct children of the RootNode. Useful for insertion/transfer operations, such as copy and paste.
11
+
12
+ ```ts
13
+ export function $cloneContents(
14
+ selection: RangeSelection | NodeSelection | GridSelection,
15
+ ): {
16
+ nodeMap: Array<[NodeKey, LexicalNode]>;
17
+ range: Array<NodeKey>;
18
+ };
19
+ ```
20
+
21
+ #### `getStyleObjectFromCSS`
22
+
23
+ Given a CSS string, returns an object from the style cache.
24
+
25
+ ```ts
26
+ export function getStyleObjectFromCSS(css: string): {
27
+ [key: string]: string;
28
+ } | null;
29
+ ```
30
+
31
+ #### `$patchStyleText`
32
+
33
+ Applies the provided styles to the TextNodes in the provided Selection. Key names in the patch argument should be
34
+ the valid CSS properties (i.e., kebab-case).
35
+
36
+ ```ts
37
+ export function $patchStyleText(
38
+ selection: RangeSelection | GridSelection,
39
+ patch: {
40
+ [key: string]: string;
41
+ },
42
+ ): void;
43
+ ```
44
+
45
+ #### `$getSelectionStyleValueForProperty`
46
+
47
+ Given a selection and a valid CSS property name, returns the current value of that property for TextNodes in the Selection, if set. If not set, it returns the defaultValue. If all TextNodes do not have the same value, it returns an empty string.
48
+
49
+ ```ts
50
+ export function $getSelectionStyleValueForProperty(
51
+ selection: RangeSelection,
52
+ styleProperty: string,
53
+ defaultValue: string,
54
+ ): string;
55
+ ```
56
+
57
+ #### `$moveCaretSelection`
58
+
59
+ Moves the selection according to the arguments.
60
+
61
+ ```ts
62
+ export function $moveCaretSelection(
63
+ selection: RangeSelection,
64
+ isHoldingShift: boolean,
65
+ isBackward: boolean,
66
+ granularity: 'character' | 'word' | 'lineboundary',
67
+ ): void;
68
+ ```
69
+
70
+ #### `$isParentElementRTL`
71
+
72
+ Returns true if the parent of the Selection anchor node is in Right-To-Left mode, false if not.
73
+
74
+ ```ts
75
+ export function $isParentElementRTL(selection: RangeSelection): boolean;
76
+ ```
77
+
78
+ #### `$moveCharacter`
79
+
80
+ Wraps $moveCaretSelection, using character granularity and accounting for RTL mode.
81
+
82
+ ```ts
83
+ export function $moveCharacter(
84
+ selection: RangeSelection,
85
+ isHoldingShift: boolean,
86
+ isBackward: boolean,
87
+ ): void;
88
+ ```
89
+
90
+ #### `$selectAll`
91
+
92
+ Expands the current Selection to cover all of the content in the editor.
93
+
94
+ ```ts
95
+ export function $selectAll(selection: RangeSelection): void;
96
+ ```
97
+
98
+ #### `$wrapLeafNodesInElements`
99
+
100
+ Attempts to wrap all leaf nodes in the Selection in ElementNodes returned from createElement. If wrappingElement is provided, all of the wrapped leaves are appended to the wrappingElement. It attempts to append the resulting sub-tree to the nearest safe insertion target.
101
+
102
+ ```ts
103
+ export function $wrapLeafNodesInElements(
104
+ selection: RangeSelection,
105
+ createElement: () => ElementNode,
106
+ wrappingElement?: ElementNode,
107
+ ): void;
108
+ ```
109
+
110
+ #### `$isAtNodeEnd`
111
+
112
+ Returns true if the provided point offset is in the last possible position.
113
+
114
+ ```ts
115
+ export function $isAtNodeEnd(point: Point): boolean;
116
+ ```
117
+
118
+ #### `$shouldOverrideDefaultCharacterSelection`
119
+
120
+ Returns true if default character selection should be overridden, false if not. Used with DecoratorNodes
121
+
122
+ ```ts
123
+ export function $shouldOverrideDefaultCharacterSelection(
124
+ selection: RangeSelection,
125
+ isBackward: boolean,
126
+ ): boolean;
127
+ ```
package/package.json CHANGED
@@ -9,10 +9,10 @@
9
9
  "selection"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.2.1",
12
+ "version": "0.2.4",
13
13
  "main": "LexicalSelection.js",
14
14
  "peerDependencies": {
15
- "lexical": "0.2.1"
15
+ "lexical": "0.2.4"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",