@lexical/selection 0.43.1-nightly.20260417.0 → 0.44.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/LexicalSelection.dev.js +21 -53
- package/LexicalSelection.dev.mjs +22 -54
- package/LexicalSelection.js.flow +2 -1
- package/LexicalSelection.prod.js +1 -1
- package/LexicalSelection.prod.mjs +1 -1
- package/index.d.ts +4 -1
- package/lexical-node.d.ts +2 -3
- package/package.json +2 -2
- package/utils.d.ts +1 -7
- package/constants.d.ts +0 -8
package/LexicalSelection.dev.js
CHANGED
|
@@ -31,7 +31,19 @@ function formatDevErrorMessage(message) {
|
|
|
31
31
|
* LICENSE file in the root directory of this source tree.
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
/*@__INLINE__*/
|
|
36
|
+
function warnOnlyOnce(message) {
|
|
37
|
+
{
|
|
38
|
+
let run = false;
|
|
39
|
+
return () => {
|
|
40
|
+
if (!run) {
|
|
41
|
+
console.warn(message);
|
|
42
|
+
}
|
|
43
|
+
run = true;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
|
|
36
48
|
/**
|
|
37
49
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -153,50 +165,10 @@ function createRectsFromDOMRange(editor, range) {
|
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param css - The CSS string of styles and their values.
|
|
158
|
-
* @returns The styleObject containing all the styles and their values.
|
|
159
|
-
*/
|
|
160
|
-
function getStyleObjectFromRawCSS(css) {
|
|
161
|
-
const styleObject = {};
|
|
162
|
-
if (!css) {
|
|
163
|
-
return styleObject;
|
|
164
|
-
}
|
|
165
|
-
const styles = css.split(';');
|
|
166
|
-
for (const style of styles) {
|
|
167
|
-
if (style !== '') {
|
|
168
|
-
const [key, value] = style.split(/:([^]+)/); // split on first colon
|
|
169
|
-
if (key && value) {
|
|
170
|
-
styleObject[key.trim()] = value.trim();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return styleObject;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Given a CSS string, returns an object from the style cache.
|
|
168
|
+
* Given a CSS string, returns the parsed style object.
|
|
179
169
|
* @param css - The CSS property as a string.
|
|
180
170
|
* @returns The value of the given CSS property.
|
|
181
171
|
*/
|
|
182
|
-
function getStyleObjectFromCSS(css) {
|
|
183
|
-
let value = CSS_TO_STYLES.get(css);
|
|
184
|
-
if (value === undefined) {
|
|
185
|
-
value = getStyleObjectFromRawCSS(css);
|
|
186
|
-
CSS_TO_STYLES.set(css, value);
|
|
187
|
-
}
|
|
188
|
-
{
|
|
189
|
-
// Freeze the value in DEV to prevent accidental mutations
|
|
190
|
-
Object.freeze(value);
|
|
191
|
-
}
|
|
192
|
-
return value;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Gets the CSS styles from the style object.
|
|
197
|
-
* @param styles - The style object containing the styles to get.
|
|
198
|
-
* @returns A string containing the CSS styles and their values.
|
|
199
|
-
*/
|
|
200
172
|
function getCSSFromStyleObject(styles) {
|
|
201
173
|
let css = '';
|
|
202
174
|
for (const style in styles) {
|
|
@@ -426,14 +398,9 @@ function $trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
|
426
398
|
}
|
|
427
399
|
|
|
428
400
|
/**
|
|
429
|
-
*
|
|
430
|
-
* @param node - The TextNode to add styles to.
|
|
401
|
+
* @deprecated node styles are parsed on demand and not cached eternally
|
|
431
402
|
*/
|
|
432
|
-
|
|
433
|
-
const CSSText = node.getStyle();
|
|
434
|
-
const styles = getStyleObjectFromRawCSS(CSSText);
|
|
435
|
-
CSS_TO_STYLES.set(CSSText, styles);
|
|
436
|
-
}
|
|
403
|
+
const $addNodeStyle = warnOnlyOnce('$addNodeStyle is a deprecated no-op and calls should be removed');
|
|
437
404
|
|
|
438
405
|
/**
|
|
439
406
|
* Applies the provided styles to the given TextNode, ElementNode, or
|
|
@@ -446,7 +413,7 @@ function $patchStyle(target, patch) {
|
|
|
446
413
|
if (!(lexical.$isRangeSelection(target) ? target.isCollapsed() : lexical.$isTextNode(target) || lexical.$isElementNode(target))) {
|
|
447
414
|
formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
|
|
448
415
|
}
|
|
449
|
-
const prevStyles = getStyleObjectFromCSS(lexical.$isRangeSelection(target) ? target.style : lexical.$isTextNode(target) ? target.getStyle() : target.getTextStyle());
|
|
416
|
+
const prevStyles = lexical.getStyleObjectFromCSS(lexical.$isRangeSelection(target) ? target.style : lexical.$isTextNode(target) ? target.getStyle() : target.getTextStyle());
|
|
450
417
|
const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
|
|
451
418
|
if (typeof value === 'function') {
|
|
452
419
|
styles[key] = value(prevStyles[key], target);
|
|
@@ -465,7 +432,6 @@ function $patchStyle(target, patch) {
|
|
|
465
432
|
} else {
|
|
466
433
|
target.setTextStyle(newCSSText);
|
|
467
434
|
}
|
|
468
|
-
CSS_TO_STYLES.set(newCSSText, newStyles);
|
|
469
435
|
}
|
|
470
436
|
|
|
471
437
|
/**
|
|
@@ -973,7 +939,7 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
973
939
|
*/
|
|
974
940
|
function $getNodeStyleValueForProperty(node, styleProperty, defaultValue) {
|
|
975
941
|
const css = node.getStyle();
|
|
976
|
-
const styleObject = getStyleObjectFromCSS(css);
|
|
942
|
+
const styleObject = lexical.getStyleObjectFromCSS(css);
|
|
977
943
|
if (styleObject !== null) {
|
|
978
944
|
return styleObject[styleProperty] || defaultValue;
|
|
979
945
|
}
|
|
@@ -1000,7 +966,7 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
1000
966
|
const endOffset = isBackward ? anchor.offset : focus.offset;
|
|
1001
967
|
if (lexical.$isRangeSelection(selection) && selection.isCollapsed() && selection.style !== '') {
|
|
1002
968
|
const css = selection.style;
|
|
1003
|
-
const styleObject = getStyleObjectFromCSS(css);
|
|
969
|
+
const styleObject = lexical.getStyleObjectFromCSS(css);
|
|
1004
970
|
if (styleObject !== null && styleProperty in styleObject) {
|
|
1005
971
|
return styleObject[styleProperty];
|
|
1006
972
|
}
|
|
@@ -1036,6 +1002,8 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
1036
1002
|
*
|
|
1037
1003
|
*/
|
|
1038
1004
|
|
|
1005
|
+
/** @deprecated moved to the `lexical` package */
|
|
1006
|
+
const getStyleObjectFromCSS = lexical.getStyleObjectFromCSS;
|
|
1039
1007
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
1040
1008
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
1041
1009
|
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { $isTextNode, $getEditor, $isRootNode, $getSelection, $isRangeSelection, $caretRangeFromSelection, $isTokenOrSegmented, $isElementNode, $getCharacterOffsets, $cloneWithPropertiesEphemeral, $getNodeByKey, $getPreviousSelection, $createTextNode, $createRangeSelection, $findMatchingParent, INTERNAL_$isBlock, $setSelection, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode, $isRootOrShadowRoot, $hasAncestor, $isLeafNode } from 'lexical';
|
|
9
|
+
import { $isTextNode, $getEditor, $isRootNode, $getSelection, $isRangeSelection, $caretRangeFromSelection, $isTokenOrSegmented, $isElementNode, $getCharacterOffsets, $cloneWithPropertiesEphemeral, $getNodeByKey, $getPreviousSelection, $createTextNode, getStyleObjectFromCSS as getStyleObjectFromCSS$1, $createRangeSelection, $findMatchingParent, INTERNAL_$isBlock, $setSelection, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode, $isRootOrShadowRoot, $hasAncestor, $isLeafNode } from 'lexical';
|
|
10
10
|
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -30,7 +30,19 @@ function formatDevErrorMessage(message) {
|
|
|
30
30
|
* LICENSE file in the root directory of this source tree.
|
|
31
31
|
*
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
/*@__INLINE__*/
|
|
35
|
+
function warnOnlyOnce(message) {
|
|
36
|
+
{
|
|
37
|
+
let run = false;
|
|
38
|
+
return () => {
|
|
39
|
+
if (!run) {
|
|
40
|
+
console.warn(message);
|
|
41
|
+
}
|
|
42
|
+
run = true;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
48
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -152,50 +164,10 @@ function createRectsFromDOMRange(editor, range) {
|
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param css - The CSS string of styles and their values.
|
|
157
|
-
* @returns The styleObject containing all the styles and their values.
|
|
158
|
-
*/
|
|
159
|
-
function getStyleObjectFromRawCSS(css) {
|
|
160
|
-
const styleObject = {};
|
|
161
|
-
if (!css) {
|
|
162
|
-
return styleObject;
|
|
163
|
-
}
|
|
164
|
-
const styles = css.split(';');
|
|
165
|
-
for (const style of styles) {
|
|
166
|
-
if (style !== '') {
|
|
167
|
-
const [key, value] = style.split(/:([^]+)/); // split on first colon
|
|
168
|
-
if (key && value) {
|
|
169
|
-
styleObject[key.trim()] = value.trim();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return styleObject;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Given a CSS string, returns an object from the style cache.
|
|
167
|
+
* Given a CSS string, returns the parsed style object.
|
|
178
168
|
* @param css - The CSS property as a string.
|
|
179
169
|
* @returns The value of the given CSS property.
|
|
180
170
|
*/
|
|
181
|
-
function getStyleObjectFromCSS(css) {
|
|
182
|
-
let value = CSS_TO_STYLES.get(css);
|
|
183
|
-
if (value === undefined) {
|
|
184
|
-
value = getStyleObjectFromRawCSS(css);
|
|
185
|
-
CSS_TO_STYLES.set(css, value);
|
|
186
|
-
}
|
|
187
|
-
{
|
|
188
|
-
// Freeze the value in DEV to prevent accidental mutations
|
|
189
|
-
Object.freeze(value);
|
|
190
|
-
}
|
|
191
|
-
return value;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Gets the CSS styles from the style object.
|
|
196
|
-
* @param styles - The style object containing the styles to get.
|
|
197
|
-
* @returns A string containing the CSS styles and their values.
|
|
198
|
-
*/
|
|
199
171
|
function getCSSFromStyleObject(styles) {
|
|
200
172
|
let css = '';
|
|
201
173
|
for (const style in styles) {
|
|
@@ -425,14 +397,9 @@ function $trimTextContentFromAnchor(editor, anchor, delCount) {
|
|
|
425
397
|
}
|
|
426
398
|
|
|
427
399
|
/**
|
|
428
|
-
*
|
|
429
|
-
* @param node - The TextNode to add styles to.
|
|
400
|
+
* @deprecated node styles are parsed on demand and not cached eternally
|
|
430
401
|
*/
|
|
431
|
-
|
|
432
|
-
const CSSText = node.getStyle();
|
|
433
|
-
const styles = getStyleObjectFromRawCSS(CSSText);
|
|
434
|
-
CSS_TO_STYLES.set(CSSText, styles);
|
|
435
|
-
}
|
|
402
|
+
const $addNodeStyle = warnOnlyOnce('$addNodeStyle is a deprecated no-op and calls should be removed');
|
|
436
403
|
|
|
437
404
|
/**
|
|
438
405
|
* Applies the provided styles to the given TextNode, ElementNode, or
|
|
@@ -445,7 +412,7 @@ function $patchStyle(target, patch) {
|
|
|
445
412
|
if (!($isRangeSelection(target) ? target.isCollapsed() : $isTextNode(target) || $isElementNode(target))) {
|
|
446
413
|
formatDevErrorMessage(`$patchStyle must only be called with a TextNode, ElementNode, or collapsed RangeSelection`);
|
|
447
414
|
}
|
|
448
|
-
const prevStyles = getStyleObjectFromCSS($isRangeSelection(target) ? target.style : $isTextNode(target) ? target.getStyle() : target.getTextStyle());
|
|
415
|
+
const prevStyles = getStyleObjectFromCSS$1($isRangeSelection(target) ? target.style : $isTextNode(target) ? target.getStyle() : target.getTextStyle());
|
|
449
416
|
const newStyles = Object.entries(patch).reduce((styles, [key, value]) => {
|
|
450
417
|
if (typeof value === 'function') {
|
|
451
418
|
styles[key] = value(prevStyles[key], target);
|
|
@@ -464,7 +431,6 @@ function $patchStyle(target, patch) {
|
|
|
464
431
|
} else {
|
|
465
432
|
target.setTextStyle(newCSSText);
|
|
466
433
|
}
|
|
467
|
-
CSS_TO_STYLES.set(newCSSText, newStyles);
|
|
468
434
|
}
|
|
469
435
|
|
|
470
436
|
/**
|
|
@@ -972,7 +938,7 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
972
938
|
*/
|
|
973
939
|
function $getNodeStyleValueForProperty(node, styleProperty, defaultValue) {
|
|
974
940
|
const css = node.getStyle();
|
|
975
|
-
const styleObject = getStyleObjectFromCSS(css);
|
|
941
|
+
const styleObject = getStyleObjectFromCSS$1(css);
|
|
976
942
|
if (styleObject !== null) {
|
|
977
943
|
return styleObject[styleProperty] || defaultValue;
|
|
978
944
|
}
|
|
@@ -999,7 +965,7 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
999
965
|
const endOffset = isBackward ? anchor.offset : focus.offset;
|
|
1000
966
|
if ($isRangeSelection(selection) && selection.isCollapsed() && selection.style !== '') {
|
|
1001
967
|
const css = selection.style;
|
|
1002
|
-
const styleObject = getStyleObjectFromCSS(css);
|
|
968
|
+
const styleObject = getStyleObjectFromCSS$1(css);
|
|
1003
969
|
if (styleObject !== null && styleProperty in styleObject) {
|
|
1004
970
|
return styleObject[styleProperty];
|
|
1005
971
|
}
|
|
@@ -1035,6 +1001,8 @@ function $getSelectionStyleValueForProperty(selection, styleProperty, defaultVal
|
|
|
1035
1001
|
*
|
|
1036
1002
|
*/
|
|
1037
1003
|
|
|
1004
|
+
/** @deprecated moved to the `lexical` package */
|
|
1005
|
+
const getStyleObjectFromCSS = getStyleObjectFromCSS$1;
|
|
1038
1006
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
1039
1007
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
1040
1008
|
|
package/LexicalSelection.js.flow
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
TextNode,
|
|
19
19
|
} from 'lexical';
|
|
20
20
|
declare export function $cloneWithProperties<T extends LexicalNode>(node: T): T;
|
|
21
|
+
/** @deprecated moved to the lexical package */
|
|
21
22
|
declare export function getStyleObjectFromCSS(css: string): {
|
|
22
23
|
[string]: string,
|
|
23
24
|
};
|
|
@@ -98,4 +99,4 @@ declare export function $sliceSelectedTextNodeContent<T extends TextNode>(
|
|
|
98
99
|
declare export function $copyBlockFormatIndent(
|
|
99
100
|
srcNode: ElementNode,
|
|
100
101
|
destNode: ElementNode,
|
|
101
|
-
): void;
|
|
102
|
+
): void;
|
package/LexicalSelection.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical");function t(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const n=new Map;function o(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function s(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function r(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim())}return t}function i(e){let t=n.get(e);return void 0===t&&(t=r(e),n.set(e,t)),t}function l(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function c(t){const n=e.$getEditor().getElementByKey(t.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function f(t){return c(e.$isRootNode(t)?t:t.getParentOrThrow())}function d(t,n,o){let s=n.getNode(),r=o;if(e.$isElementNode(s)){const e=s.getDescendantByIndex(n.offset);null!==e&&(s=e)}for(;r>0&&null!==s;){if(e.$isElementNode(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let o=s.getPreviousSibling(),i=0;if(null===o){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){o=null;break}t=e.getPreviousSibling()}null!==e&&(i=e.isInline()?0:2,o=t)}let l=s.getTextContent();""===l&&e.$isElementNode(s)&&!s.isInline()&&(l="\n\n");const c=l.length;if(!e.$isTextNode(s)||r>=c){const t=s.getParent();s.remove(),null==t||0!==t.getChildrenSize()||e.$isRootNode(t)||t.remove(),r-=c+i,s=o}else{const o=s.getKey(),i=t.getEditorState().read(()=>{const t=e.$getNodeByKey(o);return e.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null}),f=c-r,d=l.slice(0,f);if(null!==i&&i!==l){const t=e.$getPreviousSelection();let n=s;if(s.isSimpleText())s.setTextContent(i);else{const t=e.$createTextNode(i);s.replace(t),n=t}if(e.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor.offset;n.select(e,e)}}else if(s.isSimpleText()){const e=n.key===o;let t=n.offset;t<r&&(t=c);const i=e?t-r:0,l=e?t:f;if(e&&0===i){const[e]=s.splitText(i,l);e.remove()}else{const[,e]=s.splitText(i,l);e.remove()}}else{const t=e.$createTextNode(d);s.replace(t)}r=0}}}function a(o,s){(e.$isRangeSelection(o)?o.isCollapsed():e.$isTextNode(o)||e.$isElementNode(o))||t(280);const r=i(e.$isRangeSelection(o)?o.style:e.$isTextNode(o)?o.getStyle():o.getTextStyle()),c=Object.entries(s).reduce((e,[t,n])=>("function"==typeof n?e[t]=n(r[t],o):null===n?delete e[t]:e[t]=n,e),{...r}),f=l(c);e.$isRangeSelection(o)||e.$isTextNode(o)?o.setStyle(f):o.setTextStyle(f),n.set(f,c)}function g(t){const n=e.$getSelection();if(!n)return;const o=new Map,s=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(e.$isRangeSelection(n))for(const t of e.$caretRangeFromSelection(n).getTextSlices())t&&o.set(t.caret.origin.getKey(),t.getSliceIndices());const r=n.getNodes();for(const n of r){if(!e.$isTextNode(n)||!n.canHaveFormat())continue;const[o,r]=s(n);if(r!==o)if(e.$isTokenOrSegmented(n)||0===o&&r===n.getTextContentSize())t(n);else{t(n.splitText(o,r)[0===o?0:1])}}e.$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&u(n)}function u(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:s,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,s,r)}}function p(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function $(e){return e.getNode().isAttached()}function h(t){let n=t;for(;null!==n&&!e.$isRootOrShadowRoot(n);){const e=n.getLatest(),t=n.getParent();0===e.getChildrenSize()&&n.remove(!0),n=t}}function y(n,o,s,r,i=null){if(0===o.length)return;const l=o[0],c=new Map,f=[];let d=e.$isElementNode(l)?l:l.getParentOrThrow();d.isInline()&&(d=d.getParentOrThrow());let a=!1;for(;null!==d;){const t=d.getPreviousSibling();if(null!==t){d=t,a=!0;break}if(d=d.getParentOrThrow(),e.$isRootOrShadowRoot(d))break}const g=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}const u=new Set;for(let n=0;n<s;n++){const s=o[n];let i=s.getParent();if(null!==i&&i.isInline()&&(i=i.getParent()),null!==i&&e.$isLeafNode(s)&&!u.has(s.getKey())){const t=i.getKey();if(void 0===c.get(t)){const n=r();n.setFormat(i.getFormatType()),n.setIndent(i.getIndent()),f.push(n),c.set(t,n),i.getChildren().forEach(t=>{n.append(t),u.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach(e=>u.add(e))}),h(i)}}else if(g.has(s.getKey())){e.$isElementNode(s)||t(179);const n=r();n.setFormat(s.getFormatType()),n.setIndent(s.getIndent()),f.push(n),s.remove(!0)}}if(null!==i)for(let e=0;e<f.length;e++){const t=f[e];i.append(t)}let p=null;if(e.$isRootOrShadowRoot(d))if(a)if(null!==i)d.insertAfter(i);else for(let e=f.length-1;e>=0;e--){const t=f[e];d.insertAfter(t)}else{const t=d.getFirstChild();if(e.$isElementNode(t)&&(d=t),null===t)if(i)d.append(i);else for(let e=0;e<f.length;e++){const t=f[e];d.append(t),p=t}else if(null!==i)t.insertBefore(i);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),p=n}}else if(i)d.insertAfter(i);else for(let e=f.length-1;e>=0;e--){const t=f[e];d.insertAfter(t),p=t}const y=e.$getPreviousSelection();e.$isRangeSelection(y)&&$(y.anchor)&&$(y.focus)?e.$setSelection(y.clone()):null!==p?p.selectEnd():n.dirty=!0}function S(e){const t=m(e);return null!==t&&"vertical-rl"===t.writingMode}function m(t){const n=t.anchor.getNode();return e.$isElementNode(n)?c(n):f(n)}function N(e,t,n,o){e.modify(t?"extend":"move",n,o)}function x(e){const t=m(e);return null!==t&&"rtl"===t.direction}function T(e,t,n){const o=i(e.getStyle());return null!==o&&o[t]||n}const E=d;exports.$cloneWithProperties=e.$cloneWithProperties,exports.$selectAll=e.$selectAll,exports.$addNodeStyle=function(e){const t=e.getStyle(),o=r(t);n.set(t,o)},exports.$copyBlockFormatIndent=p,exports.$ensureForwardRangeSelection=u,exports.$forEachSelectedTextNode=g,exports.$getComputedStyleForElement=c,exports.$getComputedStyleForParent=f,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let s=null;const r=t.getNodes(),l=t.anchor,c=t.focus,f=t.isBackward(),d=f?c.getNode():l.getNode(),a=f?l.getNode():c.getNode(),g=f?c.offset:l.offset,u=f?l.offset:c.offset;if(e.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=i(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const i=r[t];if((0!==t||!i.is(d)||!e.$isTextNode(i)||g!==i.getTextContentSize())&&((0===t||!i.is(a)||0!==u)&&e.$isTextNode(i))){const e=T(i,n,o);if(null===s)s=e;else if(s!==e){s="";break}}}return null===s?o:s},exports.$isAtNodeEnd=function(n){if("text"===n.type)return n.offset===n.getNode().getTextContentSize();const o=n.getNode();return e.$isElementNode(o)||t(177),n.offset===o.getChildrenSize()},exports.$isParentElementRTL=x,exports.$isParentRTL=function(e){const t=f(e);return null!==t&&"rtl"===t.direction},exports.$moveCaretSelection=N,exports.$moveCharacter=function(e,t,n){const o=x(e);let s;s=S(e)||o?!n:n,N(e,t,s,"character")},exports.$patchStyleText=function(t,n){if(e.$isRangeSelection(t)&&t.isCollapsed()){a(t,n);const o=t.anchor.getNode();e.$isElementNode(o)&&o.isEmpty()&&a(o,n)}g(e=>{a(e,n)});const o=t.getNodes();if(o.length>0){const t=new Set;for(const s of o){if(!e.$isElementNode(s)||!s.canBeEmpty()||0!==s.getChildrenSize())continue;const o=s.getKey();t.has(o)||(t.add(o),a(s,n))}}},exports.$setBlocksType=function(t,n,o=p){if(null===t)return;const s=t.getStartEndPoints(),r=new Map;let i=null;if(s){const[t,n]=s;i=e.$createRangeSelection(),i.anchor.set(t.key,t.offset,t.type),i.focus.set(n.key,n.offset,n.type);const o=e.$findMatchingParent(t.getNode(),e.INTERNAL_$isBlock),l=e.$findMatchingParent(n.getNode(),e.INTERNAL_$isBlock);e.$isElementNode(o)&&r.set(o.getKey(),o),e.$isElementNode(l)&&r.set(l.getKey(),l)}for(const n of t.getNodes())if(e.$isElementNode(n)&&e.INTERNAL_$isBlock(n))r.set(n.getKey(),n);else if(null===s){const t=e.$findMatchingParent(n,e.INTERNAL_$isBlock);e.$isElementNode(t)&&r.set(t.getKey(),t)}for(const[e,t]of r){const s=n();o(t,s),t.replace(s,!0),i&&(e===i.anchor.key&&i.anchor.set(s.getKey(),i.anchor.offset,i.anchor.type),e===i.focus.key&&i.focus.set(s.getKey(),i.focus.offset,i.focus.type))}i&&t.is(e.$getSelection())&&e.$setSelection(i)},exports.$shouldOverrideDefaultCharacterSelection=function(t,n){let o=S(t)?!n:n;x(t)&&(o=!o);const s=e.$caretFromPoint(t.focus,o?"previous":"next");if(e.$isExtendableTextPointCaret(s))return!1;for(const t of e.$extendCaretToRange(s)){if(e.$isChildCaret(t))return!t.origin.isInline();if(!e.$isElementNode(t.origin)){if(e.$isDecoratorNode(t.origin))return!0;break}}return!1},exports.$sliceSelectedTextNodeContent=function(t,n,o="self"){const s=t.getStartEndPoints();if(n.isSelected(t)&&!e.$isTokenOrSegmented(n)&&null!==s){const[r,i]=s,l=t.isBackward(),c=r.getNode(),f=i.getNode(),d=n.is(c),a=n.is(f);if(d||a){const[s,r]=e.$getCharacterOffsets(t),i=c.is(f),d=n.is(l?f:c),a=n.is(l?c:f);let g,u=0;if(i)u=s>r?r:s,g=s>r?s:r;else if(d){u=l?r:s,g=void 0}else if(a){u=0,g=l?s:r}const p=n.__text.slice(u,g);p!==n.__text&&("clone"===o&&(n=e.$cloneWithPropertiesEphemeral(n)),n.__text=p)}}return n},exports.$trimTextContentFromAnchor=d,exports.$wrapNodes=function(t,n,o=null){const s=t.getStartEndPoints(),r=s?s[0]:null,i=t.getNodes(),l=i.length;if(null!==r&&(0===l||1===l&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),t=e.getChildren();let s=n();return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),t.forEach(e=>s.append(e)),o&&(s=o.append(s)),void e.replace(s)}let c=null,f=[];for(let s=0;s<l;s++){const r=i[s];e.$isRootOrShadowRoot(r)?(y(t,f,f.length,n,o),f=[],c=r):null===c||null!==c&&e.$hasAncestor(r,c)?f.push(r):(y(t,f,f.length,n,o),f=[r])}y(t,f,f.length,n,o)},exports.createDOMRange=function(t,n,r,i,l){const c=n.getKey(),f=i.getKey(),d=document.createRange();let a=t.getElementByKey(c),g=t.getElementByKey(f),u=r,p=l;if(e.$isTextNode(n)&&(a=o(a)),e.$isTextNode(i)&&(g=o(g)),void 0===n||void 0===i||null===a||null===g)return null;"BR"===a.nodeName&&([a,u]=s(a)),"BR"===g.nodeName&&([g,p]=s(g));const $=a.firstChild;a===g&&null!=$&&"BR"===$.nodeName&&0===u&&0===p&&(p=1);try{d.setStart(a,u),d.setEnd(g,p)}catch(e){return null}return!d.collapsed||u===p&&c===f||(d.setStart(g,p),d.setEnd(a,u)),d},exports.createRectsFromDOMRange=function(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),s=getComputedStyle(n),r=parseFloat(s.paddingLeft)+parseFloat(s.paddingRight),i=Array.from(t.getClientRects());let l,c=i.length;i.sort((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n});for(let e=0;e<c;e++){const t=i[e],n=l&&l.top<=t.top&&l.top+l.height>t.top&&l.left+l.width>t.left,s=t.width+r===o.width;n||s?(i.splice(e--,1),c--):l=t}return i},exports.getCSSFromStyleObject=l,exports.getStyleObjectFromCSS=i,exports.trimTextContentFromAnchor=E;
|
|
9
|
+
"use strict";var e=require("lexical");function t(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function n(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function o(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function s(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function r(t){const n=e.$getEditor().getElementByKey(t.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function l(t){return r(e.$isRootNode(t)?t:t.getParentOrThrow())}function i(t,n,o){let s=n.getNode(),r=o;if(e.$isElementNode(s)){const e=s.getDescendantByIndex(n.offset);null!==e&&(s=e)}for(;r>0&&null!==s;){if(e.$isElementNode(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let o=s.getPreviousSibling(),l=0;if(null===o){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){o=null;break}t=e.getPreviousSibling()}null!==e&&(l=e.isInline()?0:2,o=t)}let i=s.getTextContent();""===i&&e.$isElementNode(s)&&!s.isInline()&&(i="\n\n");const c=i.length;if(!e.$isTextNode(s)||r>=c){const t=s.getParent();s.remove(),null==t||0!==t.getChildrenSize()||e.$isRootNode(t)||t.remove(),r-=c+l,s=o}else{const o=s.getKey(),l=t.getEditorState().read(()=>{const t=e.$getNodeByKey(o);return e.$isTextNode(t)&&t.isSimpleText()?t.getTextContent():null}),f=c-r,d=i.slice(0,f);if(null!==l&&l!==i){const t=e.$getPreviousSelection();let n=s;if(s.isSimpleText())s.setTextContent(l);else{const t=e.$createTextNode(l);s.replace(t),n=t}if(e.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor.offset;n.select(e,e)}}else if(s.isSimpleText()){const e=n.key===o;let t=n.offset;t<r&&(t=c);const l=e?t-r:0,i=e?t:f;if(e&&0===l){const[e]=s.splitText(l,i);e.remove()}else{const[,e]=s.splitText(l,i);e.remove()}}else{const t=e.$createTextNode(d);s.replace(t)}r=0}}}const c=()=>{};function f(n,o){(e.$isRangeSelection(n)?n.isCollapsed():e.$isTextNode(n)||e.$isElementNode(n))||t(280);const r=e.getStyleObjectFromCSS(e.$isRangeSelection(n)?n.style:e.$isTextNode(n)?n.getStyle():n.getTextStyle()),l=s(Object.entries(o).reduce((e,[t,o])=>("function"==typeof o?e[t]=o(r[t],n):null===o?delete e[t]:e[t]=o,e),{...r}));e.$isRangeSelection(n)||e.$isTextNode(n)?n.setStyle(l):n.setTextStyle(l)}function d(t){const n=e.$getSelection();if(!n)return;const o=new Map,s=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(e.$isRangeSelection(n))for(const t of e.$caretRangeFromSelection(n).getTextSlices())t&&o.set(t.caret.origin.getKey(),t.getSliceIndices());const r=n.getNodes();for(const n of r){if(!e.$isTextNode(n)||!n.canHaveFormat())continue;const[o,r]=s(n);if(r!==o)if(e.$isTokenOrSegmented(n)||0===o&&r===n.getTextContentSize())t(n);else{t(n.splitText(o,r)[0===o?0:1])}}e.$isRangeSelection(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&a(n)}function a(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:s,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,s,r)}}function g(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function u(e){return e.getNode().isAttached()}function p(t){let n=t;for(;null!==n&&!e.$isRootOrShadowRoot(n);){const e=n.getLatest(),t=n.getParent();0===e.getChildrenSize()&&n.remove(!0),n=t}}function $(n,o,s,r,l=null){if(0===o.length)return;const i=o[0],c=new Map,f=[];let d=e.$isElementNode(i)?i:i.getParentOrThrow();d.isInline()&&(d=d.getParentOrThrow());let a=!1;for(;null!==d;){const t=d.getPreviousSibling();if(null!==t){d=t,a=!0;break}if(d=d.getParentOrThrow(),e.$isRootOrShadowRoot(d))break}const g=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&g.add(n.getKey())}const $=new Set;for(let n=0;n<s;n++){const s=o[n];let l=s.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&e.$isLeafNode(s)&&!$.has(s.getKey())){const t=l.getKey();if(void 0===c.get(t)){const n=r();n.setFormat(l.getFormatType()),n.setIndent(l.getIndent()),f.push(n),c.set(t,n),l.getChildren().forEach(t=>{n.append(t),$.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach(e=>$.add(e))}),p(l)}}else if(g.has(s.getKey())){e.$isElementNode(s)||t(179);const n=r();n.setFormat(s.getFormatType()),n.setIndent(s.getIndent()),f.push(n),s.remove(!0)}}if(null!==l)for(let e=0;e<f.length;e++){const t=f[e];l.append(t)}let h=null;if(e.$isRootOrShadowRoot(d))if(a)if(null!==l)d.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];d.insertAfter(t)}else{const t=d.getFirstChild();if(e.$isElementNode(t)&&(d=t),null===t)if(l)d.append(l);else for(let e=0;e<f.length;e++){const t=f[e];d.append(t),h=t}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),h=n}}else if(l)d.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];d.insertAfter(t),h=t}const S=e.$getPreviousSelection();e.$isRangeSelection(S)&&u(S.anchor)&&u(S.focus)?e.$setSelection(S.clone()):null!==h?h.selectEnd():n.dirty=!0}function h(e){const t=S(e);return null!==t&&"vertical-rl"===t.writingMode}function S(t){const n=t.anchor.getNode();return e.$isElementNode(n)?r(n):l(n)}function y(e,t,n,o){e.modify(t?"extend":"move",n,o)}function m(e){const t=S(e);return null!==t&&"rtl"===t.direction}function N(t,n,o){const s=t.getStyle(),r=e.getStyleObjectFromCSS(s);return null!==r&&r[n]||o}const x=e.getStyleObjectFromCSS,T=i;exports.$cloneWithProperties=e.$cloneWithProperties,exports.$selectAll=e.$selectAll,exports.$addNodeStyle=c,exports.$copyBlockFormatIndent=g,exports.$ensureForwardRangeSelection=a,exports.$forEachSelectedTextNode=d,exports.$getComputedStyleForElement=r,exports.$getComputedStyleForParent=l,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let s=null;const r=t.getNodes(),l=t.anchor,i=t.focus,c=t.isBackward(),f=c?i.getNode():l.getNode(),d=c?l.getNode():i.getNode(),a=c?i.offset:l.offset,g=c?l.offset:i.offset;if(e.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const o=t.style,s=e.getStyleObjectFromCSS(o);if(null!==s&&n in s)return s[n]}for(let t=0;t<r.length;t++){const l=r[t];if((0!==t||!l.is(f)||!e.$isTextNode(l)||a!==l.getTextContentSize())&&((0===t||!l.is(d)||0!==g)&&e.$isTextNode(l))){const e=N(l,n,o);if(null===s)s=e;else if(s!==e){s="";break}}}return null===s?o:s},exports.$isAtNodeEnd=function(n){if("text"===n.type)return n.offset===n.getNode().getTextContentSize();const o=n.getNode();return e.$isElementNode(o)||t(177),n.offset===o.getChildrenSize()},exports.$isParentElementRTL=m,exports.$isParentRTL=function(e){const t=l(e);return null!==t&&"rtl"===t.direction},exports.$moveCaretSelection=y,exports.$moveCharacter=function(e,t,n){const o=m(e);let s;s=h(e)||o?!n:n,y(e,t,s,"character")},exports.$patchStyleText=function(t,n){if(e.$isRangeSelection(t)&&t.isCollapsed()){f(t,n);const o=t.anchor.getNode();e.$isElementNode(o)&&o.isEmpty()&&f(o,n)}d(e=>{f(e,n)});const o=t.getNodes();if(o.length>0){const t=new Set;for(const s of o){if(!e.$isElementNode(s)||!s.canBeEmpty()||0!==s.getChildrenSize())continue;const o=s.getKey();t.has(o)||(t.add(o),f(s,n))}}},exports.$setBlocksType=function(t,n,o=g){if(null===t)return;const s=t.getStartEndPoints(),r=new Map;let l=null;if(s){const[t,n]=s;l=e.$createRangeSelection(),l.anchor.set(t.key,t.offset,t.type),l.focus.set(n.key,n.offset,n.type);const o=e.$findMatchingParent(t.getNode(),e.INTERNAL_$isBlock),i=e.$findMatchingParent(n.getNode(),e.INTERNAL_$isBlock);e.$isElementNode(o)&&r.set(o.getKey(),o),e.$isElementNode(i)&&r.set(i.getKey(),i)}for(const n of t.getNodes())if(e.$isElementNode(n)&&e.INTERNAL_$isBlock(n))r.set(n.getKey(),n);else if(null===s){const t=e.$findMatchingParent(n,e.INTERNAL_$isBlock);e.$isElementNode(t)&&r.set(t.getKey(),t)}for(const[e,t]of r){const s=n();o(t,s),t.replace(s,!0),l&&(e===l.anchor.key&&l.anchor.set(s.getKey(),l.anchor.offset,l.anchor.type),e===l.focus.key&&l.focus.set(s.getKey(),l.focus.offset,l.focus.type))}l&&t.is(e.$getSelection())&&e.$setSelection(l)},exports.$shouldOverrideDefaultCharacterSelection=function(t,n){let o=h(t)?!n:n;m(t)&&(o=!o);const s=e.$caretFromPoint(t.focus,o?"previous":"next");if(e.$isExtendableTextPointCaret(s))return!1;for(const t of e.$extendCaretToRange(s)){if(e.$isChildCaret(t))return!t.origin.isInline();if(!e.$isElementNode(t.origin)){if(e.$isDecoratorNode(t.origin))return!0;break}}return!1},exports.$sliceSelectedTextNodeContent=function(t,n,o="self"){const s=t.getStartEndPoints();if(n.isSelected(t)&&!e.$isTokenOrSegmented(n)&&null!==s){const[r,l]=s,i=t.isBackward(),c=r.getNode(),f=l.getNode(),d=n.is(c),a=n.is(f);if(d||a){const[s,r]=e.$getCharacterOffsets(t),l=c.is(f),d=n.is(i?f:c),a=n.is(i?c:f);let g,u=0;if(l)u=s>r?r:s,g=s>r?s:r;else if(d){u=i?r:s,g=void 0}else if(a){u=0,g=i?s:r}const p=n.__text.slice(u,g);p!==n.__text&&("clone"===o&&(n=e.$cloneWithPropertiesEphemeral(n)),n.__text=p)}}return n},exports.$trimTextContentFromAnchor=i,exports.$wrapNodes=function(t,n,o=null){const s=t.getStartEndPoints(),r=s?s[0]:null,l=t.getNodes(),i=l.length;if(null!==r&&(0===i||1===i&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),t=e.getChildren();let s=n();return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),t.forEach(e=>s.append(e)),o&&(s=o.append(s)),void e.replace(s)}let c=null,f=[];for(let s=0;s<i;s++){const r=l[s];e.$isRootOrShadowRoot(r)?($(t,f,f.length,n,o),f=[],c=r):null===c||null!==c&&e.$hasAncestor(r,c)?f.push(r):($(t,f,f.length,n,o),f=[r])}$(t,f,f.length,n,o)},exports.createDOMRange=function(t,s,r,l,i){const c=s.getKey(),f=l.getKey(),d=document.createRange();let a=t.getElementByKey(c),g=t.getElementByKey(f),u=r,p=i;if(e.$isTextNode(s)&&(a=n(a)),e.$isTextNode(l)&&(g=n(g)),void 0===s||void 0===l||null===a||null===g)return null;"BR"===a.nodeName&&([a,u]=o(a)),"BR"===g.nodeName&&([g,p]=o(g));const $=a.firstChild;a===g&&null!=$&&"BR"===$.nodeName&&0===u&&0===p&&(p=1);try{d.setStart(a,u),d.setEnd(g,p)}catch(e){return null}return!d.collapsed||u===p&&c===f||(d.setStart(g,p),d.setEnd(a,u)),d},exports.createRectsFromDOMRange=function(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),s=getComputedStyle(n),r=parseFloat(s.paddingLeft)+parseFloat(s.paddingRight),l=Array.from(t.getClientRects());let i,c=l.length;l.sort((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n});for(let e=0;e<c;e++){const t=l[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,s=t.width+r===o.width;n||s?(l.splice(e--,1),c--):i=t}return l},exports.getCSSFromStyleObject=s,exports.getStyleObjectFromCSS=x,exports.trimTextContentFromAnchor=T;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isTextNode as e,$getEditor as t,$isRootNode as n,$getSelection as o,$isRangeSelection as l,$caretRangeFromSelection as r,$isTokenOrSegmented as s,$isElementNode as i,$getCharacterOffsets as c,$cloneWithPropertiesEphemeral as f,$getNodeByKey as u,$getPreviousSelection as g,$createTextNode as a,$createRangeSelection as d,$findMatchingParent as p,INTERNAL_$isBlock as h,$setSelection as y,$caretFromPoint as m,$isExtendableTextPointCaret as S,$extendCaretToRange as x,$isChildCaret as T,$isDecoratorNode as N,$isRootOrShadowRoot as w,$hasAncestor as C,$isLeafNode as v}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function K(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const E=new Map;function P(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function k(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function I(t,n,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=o,a=r;if(e(n)&&(f=P(f)),e(l)&&(u=P(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=k(f)),"BR"===u.nodeName&&([u,a]=k(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a)}catch(e){return null}return!c.collapsed||g===a&&s===i||(c.setStart(u,a),c.setEnd(f,g)),c}function B(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),s=Array.from(t.getClientRects());let i,c=s.length;s.sort((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n});for(let e=0;e<c;e++){const t=s[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,l=t.width+r===o.width;n||l?(s.splice(e--,1),c--):i=t}return s}function F(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim())}return t}function b(e){let t=E.get(e);return void 0===t&&(t=F(e),E.set(e,t)),t}function z(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function R(e){const n=t().getElementByKey(e.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function O(e){return R(n(e)?e:e.getParentOrThrow())}function A(e){const t=O(e);return null!==t&&"rtl"===t.direction}function M(e,t,n="self"){const o=e.getStartEndPoints();if(t.isSelected(e)&&!s(t)&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),u=r.getNode(),g=t.is(i),a=t.is(u);if(g||a){const[o,l]=c(e),r=i.is(u),g=t.is(s?u:i),a=t.is(s?i:u);let d,p=0;if(r)p=o>l?l:o,d=o>l?o:l;else if(g){p=s?l:o,d=void 0}else if(a){p=0,d=s?o:l}const h=t.__text.slice(p,d);h!==t.__text&&("clone"===n&&(t=f(t)),t.__text=h)}}return t}function _(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return i(t)||K(177),e.offset===t.getChildrenSize()}function L(t,o,r){let s=o.getNode(),c=r;if(i(s)){const e=s.getDescendantByIndex(o.offset);null!==e&&(s=e)}for(;c>0&&null!==s;){if(i(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let r=s.getPreviousSibling(),f=0;if(null===r){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){r=null;break}t=e.getPreviousSibling()}null!==e&&(f=e.isInline()?0:2,r=t)}let d=s.getTextContent();""===d&&i(s)&&!s.isInline()&&(d="\n\n");const p=d.length;if(!e(s)||c>=p){const e=s.getParent();s.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),c-=p+f,s=r}else{const n=s.getKey(),r=t.getEditorState().read(()=>{const t=u(n);return e(t)&&t.isSimpleText()?t.getTextContent():null}),i=p-c,f=d.slice(0,i);if(null!==r&&r!==d){const e=g();let t=s;if(s.isSimpleText())s.setTextContent(r);else{const e=a(r);s.replace(e),t=e}if(l(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(s.isSimpleText()){const e=o.key===n;let t=o.offset;t<c&&(t=p);const l=e?t-c:0,r=e?t:i;if(e&&0===l){const[e]=s.splitText(l,r);e.remove()}else{const[,e]=s.splitText(l,r);e.remove()}}else{const e=a(f);s.replace(e)}c=0}}}function $(e){const t=e.getStyle(),n=F(t);E.set(t,n)}function D(t,n){(l(t)?t.isCollapsed():e(t)||i(t))||K(280);const o=b(l(t)?t.style:e(t)?t.getStyle():t.getTextStyle()),r=Object.entries(n).reduce((e,[n,l])=>("function"==typeof l?e[n]=l(o[n],t):null===l?delete e[n]:e[n]=l,e),{...o}),s=z(r);l(t)||e(t)?t.setStyle(s):t.setTextStyle(s),E.set(s,r)}function U(e,t){if(l(e)&&e.isCollapsed()){D(e,t);const n=e.anchor.getNode();i(n)&&n.isEmpty()&&D(n,t)}j(e=>{D(e,t)});const n=e.getNodes();if(n.length>0){const e=new Set;for(const o of n){if(!i(o)||!o.canBeEmpty()||0!==o.getChildrenSize())continue;const n=o.getKey();e.has(n)||(e.add(n),D(o,t))}}}function j(t){const n=o();if(!n)return;const i=new Map,c=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(l(n))for(const e of r(n).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const f=n.getNodes();for(const n of f){if(!e(n)||!n.canHaveFormat())continue;const[o,l]=c(n);if(l!==o)if(s(n)||0===o&&l===n.getTextContentSize())t(n);else{t(n.splitText(o,l)[0===o?0:1])}}l(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&H(n)}function H(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:l,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,l,r)}}function V(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function W(e,t,n=V){if(null===e)return;const l=e.getStartEndPoints(),r=new Map;let s=null;if(l){const[e,t]=l;s=d(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const n=p(e.getNode(),h),o=p(t.getNode(),h);i(n)&&r.set(n.getKey(),n),i(o)&&r.set(o.getKey(),o)}for(const t of e.getNodes())if(i(t)&&h(t))r.set(t.getKey(),t);else if(null===l){const e=p(t,h);i(e)&&r.set(e.getKey(),e)}for(const[e,o]of r){const l=t();n(o,l),o.replace(l,!0),s&&(e===s.anchor.key&&s.anchor.set(l.getKey(),s.anchor.offset,s.anchor.type),e===s.focus.key&&s.focus.set(l.getKey(),s.focus.offset,s.focus.type))}s&&e.is(o())&&y(s)}function X(e){return e.getNode().isAttached()}function q(e){let t=e;for(;null!==t&&!w(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function G(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),s=r.length;if(null!==l&&(0===s||1===s&&"element"===l.type&&0===l.getNode().getChildrenSize())){const e="text"===l.type?l.getNode().getParentOrThrow():l.getNode(),o=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),o.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let i=null,c=[];for(let o=0;o<s;o++){const l=r[o];w(l)?(J(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&C(l,i)?c.push(l):(J(e,c,c.length,t,n),c=[l])}J(e,c,c.length,t,n)}function J(e,t,n,o,r=null){if(0===t.length)return;const s=t[0],c=new Map,f=[];let u=i(s)?s:s.getParentOrThrow();u.isInline()&&(u=u.getParentOrThrow());let a=!1;for(;null!==u;){const e=u.getPreviousSibling();if(null!==e){u=e,a=!0;break}if(u=u.getParentOrThrow(),w(u))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];i(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const p=new Set;for(let e=0;e<n;e++){const n=t[e];let l=n.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&v(n)&&!p.has(n.getKey())){const e=l.getKey();if(void 0===c.get(e)){const t=o();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),f.push(t),c.set(e,t),l.getChildren().forEach(e=>{t.append(e),p.add(e.getKey()),i(e)&&e.getChildrenKeys().forEach(e=>p.add(e))}),q(l)}}else if(d.has(n.getKey())){i(n)||K(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),f.push(e),n.remove(!0)}}if(null!==r)for(let e=0;e<f.length;e++){const t=f[e];r.append(t)}let h=null;if(w(u))if(a)if(null!==r)u.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];u.insertAfter(t)}else{const e=u.getFirstChild();if(i(e)&&(u=e),null===e)if(r)u.append(r);else for(let e=0;e<f.length;e++){const t=f[e];u.append(t),h=t}else if(null!==r)e.insertBefore(r);else for(let t=0;t<f.length;t++){const n=f[t];e.insertBefore(n),h=n}}else if(r)u.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];u.insertAfter(t),h=t}const m=g();l(m)&&X(m.anchor)&&X(m.focus)?y(m.clone()):null!==h?h.selectEnd():e.dirty=!0}function Q(e){const t=Y(e);return null!==t&&"vertical-rl"===t.writingMode}function Y(e){const t=e.anchor.getNode();return i(t)?R(t):O(t)}function Z(e,t){let n=Q(e)?!t:t;te(e)&&(n=!n);const o=m(e.focus,n?"previous":"next");if(S(o))return!1;for(const e of x(o)){if(T(e))return!e.origin.isInline();if(!i(e.origin)){if(N(e.origin))return!0;break}}return!1}function ee(e,t,n,o){e.modify(t?"extend":"move",n,o)}function te(e){const t=Y(e);return null!==t&&"rtl"===t.direction}function ne(e,t,n){const o=te(e);let l;l=Q(e)||o?!n:n,ee(e,t,l,"character")}function oe(e,t,n){const o=b(e.getStyle());return null!==o&&o[t]||n}function le(t,n,o=""){let r=null;const s=t.getNodes(),i=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.getNode():i.getNode(),g=f?i.getNode():c.getNode(),a=f?c.offset:i.offset,d=f?i.offset:c.offset;if(l(t)&&t.isCollapsed()&&""!==t.style){const e=b(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<s.length;t++){const l=s[t];if((0!==t||!l.is(u)||!e(l)||a!==l.getTextContentSize())&&((0===t||!l.is(g)||0!==d)&&e(l))){const e=oe(l,n,o);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?o:r}const re=L;export{$ as $addNodeStyle,V as $copyBlockFormatIndent,H as $ensureForwardRangeSelection,j as $forEachSelectedTextNode,R as $getComputedStyleForElement,O as $getComputedStyleForParent,le as $getSelectionStyleValueForProperty,_ as $isAtNodeEnd,te as $isParentElementRTL,A as $isParentRTL,ee as $moveCaretSelection,ne as $moveCharacter,U as $patchStyleText,W as $setBlocksType,Z as $shouldOverrideDefaultCharacterSelection,M as $sliceSelectedTextNodeContent,L as $trimTextContentFromAnchor,G as $wrapNodes,I as createDOMRange,B as createRectsFromDOMRange,z as getCSSFromStyleObject,b as getStyleObjectFromCSS,re as trimTextContentFromAnchor};
|
|
9
|
+
import{$isTextNode as e,$getEditor as t,$isRootNode as n,$getSelection as o,$isRangeSelection as l,$caretRangeFromSelection as r,$isTokenOrSegmented as s,$isElementNode as i,$getCharacterOffsets as c,$cloneWithPropertiesEphemeral as f,$getNodeByKey as u,$getPreviousSelection as g,$createTextNode as a,getStyleObjectFromCSS as d,$createRangeSelection as p,$findMatchingParent as h,INTERNAL_$isBlock as y,$setSelection as m,$caretFromPoint as S,$isExtendableTextPointCaret as x,$extendCaretToRange as T,$isChildCaret as N,$isDecoratorNode as C,$isRootOrShadowRoot as w,$hasAncestor as v,$isLeafNode as K}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function E(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function P(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function k(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function I(t,n,o,l,r){const s=n.getKey(),i=l.getKey(),c=document.createRange();let f=t.getElementByKey(s),u=t.getElementByKey(i),g=o,a=r;if(e(n)&&(f=P(f)),e(l)&&(u=P(u)),void 0===n||void 0===l||null===f||null===u)return null;"BR"===f.nodeName&&([f,g]=k(f)),"BR"===u.nodeName&&([u,a]=k(u));const d=f.firstChild;f===u&&null!=d&&"BR"===d.nodeName&&0===g&&0===a&&(a=1);try{c.setStart(f,g),c.setEnd(u,a)}catch(e){return null}return!c.collapsed||g===a&&s===i||(c.setStart(u,a),c.setEnd(f,g)),c}function B(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),s=Array.from(t.getClientRects());let i,c=s.length;s.sort((e,t)=>{const n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n});for(let e=0;e<c;e++){const t=s[e],n=i&&i.top<=t.top&&i.top+i.height>t.top&&i.left+i.width>t.left,l=t.width+r===o.width;n||l?(s.splice(e--,1),c--):i=t}return s}function F(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function b(e){const n=t().getElementByKey(e.getKey());if(null===n)return null;const o=n.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(n)}function z(e){return b(n(e)?e:e.getParentOrThrow())}function O(e){const t=z(e);return null!==t&&"rtl"===t.direction}function R(e,t,n="self"){const o=e.getStartEndPoints();if(t.isSelected(e)&&!s(t)&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),u=r.getNode(),g=t.is(i),a=t.is(u);if(g||a){const[o,l]=c(e),r=i.is(u),g=t.is(s?u:i),a=t.is(s?i:u);let d,p=0;if(r)p=o>l?l:o,d=o>l?o:l;else if(g){p=s?l:o,d=void 0}else if(a){p=0,d=s?o:l}const h=t.__text.slice(p,d);h!==t.__text&&("clone"===n&&(t=f(t)),t.__text=h)}}return t}function A(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return i(t)||E(177),e.offset===t.getChildrenSize()}function _(t,o,r){let s=o.getNode(),c=r;if(i(s)){const e=s.getDescendantByIndex(o.offset);null!==e&&(s=e)}for(;c>0&&null!==s;){if(i(s)){const e=s.getLastDescendant();null!==e&&(s=e)}let r=s.getPreviousSibling(),f=0;if(null===r){let e=s.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){r=null;break}t=e.getPreviousSibling()}null!==e&&(f=e.isInline()?0:2,r=t)}let d=s.getTextContent();""===d&&i(s)&&!s.isInline()&&(d="\n\n");const p=d.length;if(!e(s)||c>=p){const e=s.getParent();s.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),c-=p+f,s=r}else{const n=s.getKey(),r=t.getEditorState().read(()=>{const t=u(n);return e(t)&&t.isSimpleText()?t.getTextContent():null}),i=p-c,f=d.slice(0,i);if(null!==r&&r!==d){const e=g();let t=s;if(s.isSimpleText())s.setTextContent(r);else{const e=a(r);s.replace(e),t=e}if(l(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(s.isSimpleText()){const e=o.key===n;let t=o.offset;t<c&&(t=p);const l=e?t-c:0,r=e?t:i;if(e&&0===l){const[e]=s.splitText(l,r);e.remove()}else{const[,e]=s.splitText(l,r);e.remove()}}else{const e=a(f);s.replace(e)}c=0}}}const L=()=>{};function M(t,n){(l(t)?t.isCollapsed():e(t)||i(t))||E(280);const o=d(l(t)?t.style:e(t)?t.getStyle():t.getTextStyle()),r=F(Object.entries(n).reduce((e,[n,l])=>("function"==typeof l?e[n]=l(o[n],t):null===l?delete e[n]:e[n]=l,e),{...o}));l(t)||e(t)?t.setStyle(r):t.setTextStyle(r)}function $(e,t){if(l(e)&&e.isCollapsed()){M(e,t);const n=e.anchor.getNode();i(n)&&n.isEmpty()&&M(n,t)}D(e=>{M(e,t)});const n=e.getNodes();if(n.length>0){const e=new Set;for(const o of n){if(!i(o)||!o.canBeEmpty()||0!==o.getChildrenSize())continue;const n=o.getKey();e.has(n)||(e.add(n),M(o,t))}}}function D(t){const n=o();if(!n)return;const i=new Map,c=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(l(n))for(const e of r(n).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const f=n.getNodes();for(const n of f){if(!e(n)||!n.canHaveFormat())continue;const[o,l]=c(n);if(l!==o)if(s(n)||0===o&&l===n.getTextContentSize())t(n);else{t(n.splitText(o,l)[0===o?0:1])}}l(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&j(n)}function j(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:o,offset:l,type:r}=t;t.set(n.key,n.offset,n.type),n.set(o,l,r)}}function U(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function H(e,t,n=U){if(null===e)return;const l=e.getStartEndPoints(),r=new Map;let s=null;if(l){const[e,t]=l;s=p(),s.anchor.set(e.key,e.offset,e.type),s.focus.set(t.key,t.offset,t.type);const n=h(e.getNode(),y),o=h(t.getNode(),y);i(n)&&r.set(n.getKey(),n),i(o)&&r.set(o.getKey(),o)}for(const t of e.getNodes())if(i(t)&&y(t))r.set(t.getKey(),t);else if(null===l){const e=h(t,y);i(e)&&r.set(e.getKey(),e)}for(const[e,o]of r){const l=t();n(o,l),o.replace(l,!0),s&&(e===s.anchor.key&&s.anchor.set(l.getKey(),s.anchor.offset,s.anchor.type),e===s.focus.key&&s.focus.set(l.getKey(),s.focus.offset,s.focus.type))}s&&e.is(o())&&m(s)}function V(e){return e.getNode().isAttached()}function W(e){let t=e;for(;null!==t&&!w(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function X(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),s=r.length;if(null!==l&&(0===s||1===s&&"element"===l.type&&0===l.getNode().getChildrenSize())){const e="text"===l.type?l.getNode().getParentOrThrow():l.getNode(),o=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),o.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let i=null,c=[];for(let o=0;o<s;o++){const l=r[o];w(l)?(q(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&v(l,i)?c.push(l):(q(e,c,c.length,t,n),c=[l])}q(e,c,c.length,t,n)}function q(e,t,n,o,r=null){if(0===t.length)return;const s=t[0],c=new Map,f=[];let u=i(s)?s:s.getParentOrThrow();u.isInline()&&(u=u.getParentOrThrow());let a=!1;for(;null!==u;){const e=u.getPreviousSibling();if(null!==e){u=e,a=!0;break}if(u=u.getParentOrThrow(),w(u))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];i(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const p=new Set;for(let e=0;e<n;e++){const n=t[e];let l=n.getParent();if(null!==l&&l.isInline()&&(l=l.getParent()),null!==l&&K(n)&&!p.has(n.getKey())){const e=l.getKey();if(void 0===c.get(e)){const t=o();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),f.push(t),c.set(e,t),l.getChildren().forEach(e=>{t.append(e),p.add(e.getKey()),i(e)&&e.getChildrenKeys().forEach(e=>p.add(e))}),W(l)}}else if(d.has(n.getKey())){i(n)||E(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),f.push(e),n.remove(!0)}}if(null!==r)for(let e=0;e<f.length;e++){const t=f[e];r.append(t)}let h=null;if(w(u))if(a)if(null!==r)u.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];u.insertAfter(t)}else{const e=u.getFirstChild();if(i(e)&&(u=e),null===e)if(r)u.append(r);else for(let e=0;e<f.length;e++){const t=f[e];u.append(t),h=t}else if(null!==r)e.insertBefore(r);else for(let t=0;t<f.length;t++){const n=f[t];e.insertBefore(n),h=n}}else if(r)u.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];u.insertAfter(t),h=t}const y=g();l(y)&&V(y.anchor)&&V(y.focus)?m(y.clone()):null!==h?h.selectEnd():e.dirty=!0}function G(e){const t=J(e);return null!==t&&"vertical-rl"===t.writingMode}function J(e){const t=e.anchor.getNode();return i(t)?b(t):z(t)}function Q(e,t){let n=G(e)?!t:t;Z(e)&&(n=!n);const o=S(e.focus,n?"previous":"next");if(x(o))return!1;for(const e of T(o)){if(N(e))return!e.origin.isInline();if(!i(e.origin)){if(C(e.origin))return!0;break}}return!1}function Y(e,t,n,o){e.modify(t?"extend":"move",n,o)}function Z(e){const t=J(e);return null!==t&&"rtl"===t.direction}function ee(e,t,n){const o=Z(e);let l;l=G(e)||o?!n:n,Y(e,t,l,"character")}function te(e,t,n){const o=e.getStyle(),l=d(o);return null!==l&&l[t]||n}function ne(t,n,o=""){let r=null;const s=t.getNodes(),i=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.getNode():i.getNode(),g=f?i.getNode():c.getNode(),a=f?c.offset:i.offset,p=f?i.offset:c.offset;if(l(t)&&t.isCollapsed()&&""!==t.style){const e=t.style,o=d(e);if(null!==o&&n in o)return o[n]}for(let t=0;t<s.length;t++){const l=s[t];if((0!==t||!l.is(u)||!e(l)||a!==l.getTextContentSize())&&((0===t||!l.is(g)||0!==p)&&e(l))){const e=te(l,n,o);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?o:r}const oe=d,le=_;export{L as $addNodeStyle,U as $copyBlockFormatIndent,j as $ensureForwardRangeSelection,D as $forEachSelectedTextNode,b as $getComputedStyleForElement,z as $getComputedStyleForParent,ne as $getSelectionStyleValueForProperty,A as $isAtNodeEnd,Z as $isParentElementRTL,O as $isParentRTL,Y as $moveCaretSelection,ee as $moveCharacter,$ as $patchStyleText,H as $setBlocksType,Q as $shouldOverrideDefaultCharacterSelection,R as $sliceSelectedTextNodeContent,_ as $trimTextContentFromAnchor,X as $wrapNodes,I as createDOMRange,B as createRectsFromDOMRange,F as getCSSFromStyleObject,oe as getStyleObjectFromCSS,le as trimTextContentFromAnchor};
|
package/index.d.ts
CHANGED
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
import { getStyleObjectFromCSS as getStyleObjectFromCSS_ } from 'lexical';
|
|
8
9
|
import { $trimTextContentFromAnchor } from './lexical-node';
|
|
9
10
|
export { $addNodeStyle, $ensureForwardRangeSelection, $forEachSelectedTextNode, $isAtNodeEnd, $patchStyleText, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, } from './lexical-node';
|
|
10
11
|
export { $copyBlockFormatIndent, $getSelectionStyleValueForProperty, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $wrapNodes, } from './range-selection';
|
|
11
|
-
export { $getComputedStyleForElement, $getComputedStyleForParent, $isParentRTL, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject,
|
|
12
|
+
export { $getComputedStyleForElement, $getComputedStyleForParent, $isParentRTL, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, } from './utils';
|
|
13
|
+
/** @deprecated moved to the `lexical` package */
|
|
14
|
+
export declare const getStyleObjectFromCSS: typeof getStyleObjectFromCSS_;
|
|
12
15
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
13
16
|
export declare const trimTextContentFromAnchor: typeof $trimTextContentFromAnchor;
|
|
14
17
|
export {
|
package/lexical-node.d.ts
CHANGED
|
@@ -31,10 +31,9 @@ export declare function $isAtNodeEnd(point: Point): boolean;
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function $trimTextContentFromAnchor(editor: LexicalEditor, anchor: Point, delCount: number): void;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param node - The TextNode to add styles to.
|
|
34
|
+
* @deprecated node styles are parsed on demand and not cached eternally
|
|
36
35
|
*/
|
|
37
|
-
export declare
|
|
36
|
+
export declare const $addNodeStyle: (_node: TextNode) => void;
|
|
38
37
|
/**
|
|
39
38
|
* Applies the provided styles to the given TextNode, ElementNode, or
|
|
40
39
|
* collapsed RangeSelection.
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.44.0",
|
|
13
13
|
"main": "LexicalSelection.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"repository": {
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"lexical": "0.
|
|
40
|
+
"lexical": "0.44.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/utils.d.ts
CHANGED
|
@@ -30,16 +30,10 @@ export declare function createRectsFromDOMRange(editor: LexicalEditor, range: Ra
|
|
|
30
30
|
*/
|
|
31
31
|
export declare function getStyleObjectFromRawCSS(css: string): Record<string, string>;
|
|
32
32
|
/**
|
|
33
|
-
* Given a CSS string, returns
|
|
33
|
+
* Given a CSS string, returns the parsed style object.
|
|
34
34
|
* @param css - The CSS property as a string.
|
|
35
35
|
* @returns The value of the given CSS property.
|
|
36
36
|
*/
|
|
37
|
-
export declare function getStyleObjectFromCSS(css: string): Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* Gets the CSS styles from the style object.
|
|
40
|
-
* @param styles - The style object containing the styles to get.
|
|
41
|
-
* @returns A string containing the CSS styles and their values.
|
|
42
|
-
*/
|
|
43
37
|
export declare function getCSSFromStyleObject(styles: Record<string, string>): string;
|
|
44
38
|
/**
|
|
45
39
|
* Gets the computed DOM styles of the element.
|
package/constants.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export declare const CSS_TO_STYLES: Map<string, Record<string, string>>;
|