@lexical/selection 0.38.3-nightly.20251209.0 → 0.39.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
CHANGED
|
@@ -486,6 +486,21 @@ function $patchStyleText(selection, patch) {
|
|
|
486
486
|
$forEachSelectedTextNode(textNode => {
|
|
487
487
|
$patchStyle(textNode, patch);
|
|
488
488
|
});
|
|
489
|
+
const nodes = selection.getNodes();
|
|
490
|
+
if (nodes.length > 0) {
|
|
491
|
+
const patchedElementKeys = new Set();
|
|
492
|
+
for (const node of nodes) {
|
|
493
|
+
if (!lexical.$isElementNode(node) || !node.canBeEmpty() || node.getChildrenSize() !== 0) {
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const key = node.getKey();
|
|
497
|
+
if (patchedElementKeys.has(key)) {
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
patchedElementKeys.add(key);
|
|
501
|
+
$patchStyle(node, patch);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
489
504
|
}
|
|
490
505
|
function $forEachSelectedTextNode(fn) {
|
|
491
506
|
const selection = lexical.$getSelection();
|
package/LexicalSelection.dev.mjs
CHANGED
|
@@ -485,6 +485,21 @@ function $patchStyleText(selection, patch) {
|
|
|
485
485
|
$forEachSelectedTextNode(textNode => {
|
|
486
486
|
$patchStyle(textNode, patch);
|
|
487
487
|
});
|
|
488
|
+
const nodes = selection.getNodes();
|
|
489
|
+
if (nodes.length > 0) {
|
|
490
|
+
const patchedElementKeys = new Set();
|
|
491
|
+
for (const node of nodes) {
|
|
492
|
+
if (!$isElementNode(node) || !node.canBeEmpty() || node.getChildrenSize() !== 0) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const key = node.getKey();
|
|
496
|
+
if (patchedElementKeys.has(key)) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
patchedElementKeys.add(key);
|
|
500
|
+
$patchStyle(node, patch);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
488
503
|
}
|
|
489
504
|
function $forEachSelectedTextNode(fn) {
|
|
490
505
|
const selection = $getSelection();
|
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 l(e){let t=n.get(e);return void 0===t&&(t=r(e),n.set(e,t)),t}function i(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 a(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,a=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(a);s.replace(t)}r=0}}}function d(o,s){(e.$isRangeSelection(o)?o.isCollapsed():e.$isTextNode(o)||e.$isElementNode(o))||t(280);const r=l(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=i(c);e.$isRangeSelection(o)||e.$isTextNode(o)?o.setStyle(f):o.setTextStyle(f),n.set(f,c)}function u(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&&g(n)}function g(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,l=null){if(0===o.length)return;const i=o[0],c=new Map,f=[];let a=e.$isElementNode(i)?i:i.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let d=!1;for(;null!==a;){const t=a.getPreviousSibling();if(null!==t){a=t,d=!0;break}if(a=a.getParentOrThrow(),e.$isRootOrShadowRoot(a))break}const u=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&u.add(n.getKey())}const g=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)&&!g.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),g.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach(e=>g.add(e))}),h(l)}}else if(u.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 p=null;if(e.$isRootOrShadowRoot(a))if(d)if(null!==l)a.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.insertAfter(t)}else{const t=a.getFirstChild();if(e.$isElementNode(t)&&(a=t),null===t)if(l)a.append(l);else for(let e=0;e<f.length;e++){const t=f[e];a.append(t),p=t}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),p=n}}else if(l)a.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];a.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 m(e){const t=S(e);return null!==t&&"vertical-rl"===t.writingMode}function S(t){const n=t.anchor.getNode();return e.$isElementNode(n)?c(n):f(n)}function x(e,t,n,o){e.modify(t?"extend":"move",n,o)}function N(e){const t=S(e);return null!==t&&"rtl"===t.direction}function T(e,t,n){const o=l(e.getStyle());return null!==o&&o[t]||n}const E=a;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=g,exports.$forEachSelectedTextNode=u,exports.$getComputedStyleForElement=c,exports.$getComputedStyleForParent=f,exports.$getSelectionStyleValueForProperty=function(t,n,o=""){let s=null;const r=t.getNodes(),i=t.anchor,c=t.focus,f=t.isBackward(),a=f?c.offset:i.offset,d=f?c.getNode():i.getNode();if(e.$isRangeSelection(t)&&t.isCollapsed()&&""!==t.style){const e=l(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const l=r[t];if((0===t||0!==a||!l.is(d))&&e.$isTextNode(l)){const e=T(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=N,exports.$isParentRTL=function(e){const t=f(e);return null!==t&&"rtl"===t.direction},exports.$moveCaretSelection=x,exports.$moveCharacter=function(e,t,n){const o=N(e);let s;s=m(e)||o?!n:n,x(e,t,s,"character")},exports.$patchStyleText=function(t,n){if(e.$isRangeSelection(t)&&t.isCollapsed()){d(t,n);const o=t.anchor.getNode();e.$isElementNode(o)&&o.isEmpty()&&d(o,n)}u(e=>{d(e,n)})},exports.$setBlocksType=function(t,n,o=p){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=m(t)?!n:n;N(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(),a=n.is(c),d=n.is(f);if(a||d){const[s,r]=e.$getCharacterOffsets(t),l=c.is(f),a=n.is(i?f:c),d=n.is(i?c:f);let u,g=0;if(l)g=s>r?r:s,u=s>r?s:r;else if(a){g=i?r:s,u=void 0}else if(d){g=0,u=i?s:r}const p=n.__text.slice(g,u);p!==n.__text&&("clone"===o&&(n=e.$cloneWithPropertiesEphemeral(n)),n.__text=p)}}return n},exports.$trimTextContentFromAnchor=a,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)?(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,l,i){const c=n.getKey(),f=l.getKey(),a=document.createRange();let d=t.getElementByKey(c),u=t.getElementByKey(f),g=r,p=i;if(e.$isTextNode(n)&&(d=o(d)),e.$isTextNode(l)&&(u=o(u)),void 0===n||void 0===l||null===d||null===u)return null;"BR"===d.nodeName&&([d,g]=s(d)),"BR"===u.nodeName&&([u,p]=s(u));const $=d.firstChild;d===u&&null!=$&&"BR"===$.nodeName&&0===g&&0===p&&(p=1);try{a.setStart(d,g),a.setEnd(u,p)}catch(e){return null}return!a.collapsed||g===p&&c===f||(a.setStart(u,p),a.setEnd(d,g)),a},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=i,exports.getStyleObjectFromCSS=l,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.`)}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 u(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&&g(n)}function g(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 u=new Set;for(let t=0;t<s;t++){const n=o[t];e.$isElementNode(n)&&0===n.getChildrenSize()&&u.add(n.getKey())}const g=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)&&!g.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),g.add(t.getKey()),e.$isElementNode(t)&&t.getChildrenKeys().forEach(e=>g.add(e))}),h(i)}}else if(u.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 m(e){const t=S(e);return null!==t&&"vertical-rl"===t.writingMode}function S(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=S(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=g,exports.$forEachSelectedTextNode=u,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.offset:l.offset,a=f?c.getNode():l.getNode();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||0!==d||!i.is(a))&&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=m(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)}u(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=m(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 u,g=0;if(i)g=s>r?r:s,u=s>r?s:r;else if(d){g=l?r:s,u=void 0}else if(a){g=0,u=l?s:r}const p=n.__text.slice(g,u);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),u=t.getElementByKey(f),g=r,p=l;if(e.$isTextNode(n)&&(a=o(a)),e.$isTextNode(i)&&(u=o(u)),void 0===n||void 0===i||null===a||null===u)return null;"BR"===a.nodeName&&([a,g]=s(a)),"BR"===u.nodeName&&([u,p]=s(u));const $=a.firstChild;a===u&&null!=$&&"BR"===$.nodeName&&0===g&&0===p&&(p=1);try{d.setStart(a,g),d.setEnd(u,p)}catch(e){return null}return!d.collapsed||g===p&&c===f||(d.setStart(u,p),d.setEnd(a,g)),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;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isTextNode as e,$getEditor as t,$isRootNode as n,$isElementNode as o,$getNodeByKey as l,$getPreviousSelection as r,$createTextNode as s,$isRangeSelection as i,$getSelection as c,$caretRangeFromSelection as f,$isTokenOrSegmented as u,$getCharacterOffsets as g,$cloneWithPropertiesEphemeral 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 w,$isRootOrShadowRoot as v,$hasAncestor as N,$isLeafNode as C}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 P=new Map;function E(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=E(f)),e(l)&&(u=E(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=P.get(e);return void 0===t&&(t=F(e),P.set(e,t)),t}function R(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function O(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 O(n(e)?e:e.getParentOrThrow())}function A(e){const t=z(e);return null!==t&&"rtl"===t.direction}function M(e,t,n="self"){const o=e.getStartEndPoints();if(t.isSelected(e)&&!u(t)&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),c=r.getNode(),f=t.is(i),u=t.is(c);if(f||u){const[o,l]=g(e),r=i.is(c),f=t.is(s?c:i),u=t.is(s?i:c);let d,p=0;if(r)p=o>l?l:o,d=o>l?o:l;else if(f){p=s?l:o,d=void 0}else if(u){p=0,d=s?o:l}const h=t.__text.slice(p,d);h!==t.__text&&("clone"===n&&(t=a(t)),t.__text=h)}}return t}function _(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return o(t)||K(177),e.offset===t.getChildrenSize()}function L(t,c,f){let u=c.getNode(),g=f;if(o(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;g>0&&null!==u;){if(o(u)){const e=u.getLastDescendant();null!==e&&(u=e)}let f=u.getPreviousSibling(),a=0;if(null===f){let e=u.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){f=null;break}t=e.getPreviousSibling()}null!==e&&(a=e.isInline()?0:2,f=t)}let d=u.getTextContent();""===d&&o(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!e(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),g-=p+a,u=f}else{const n=u.getKey(),o=t.getEditorState().read(()=>{const t=l(n);return e(t)&&t.isSimpleText()?t.getTextContent():null}),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(o);else{const e=s(o);u.replace(e),t=e}if(i(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const o=e?t-g:0,l=e?t:f;if(e&&0===o){const[e]=u.splitText(o,l);e.remove()}else{const[,e]=u.splitText(o,l);e.remove()}}else{const e=s(a);u.replace(e)}g=0}}}function $(e){const t=e.getStyle(),n=F(t);P.set(t,n)}function D(t,n){(i(t)?t.isCollapsed():e(t)||o(t))||K(280);const l=b(i(t)?t.style:e(t)?t.getStyle():t.getTextStyle()),r=Object.entries(n).reduce((e,[n,o])=>("function"==typeof o?e[n]=o(l[n],t):null===o?delete e[n]:e[n]=o,e),{...l}),s=R(r);i(t)||e(t)?t.setStyle(s):t.setTextStyle(s),P.set(s,r)}function U(e,t){if(i(e)&&e.isCollapsed()){D(e,t);const n=e.anchor.getNode();o(n)&&n.isEmpty()&&D(n,t)}j(e=>{D(e,t)})}function j(t){const n=c();if(!n)return;const o=new Map,l=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(i(n))for(const e of f(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const r=n.getNodes();for(const n of r){if(!e(n)||!n.canHaveFormat())continue;const[o,r]=l(n);if(r!==o)if(u(n)||0===o&&r===n.getTextContentSize())t(n);else{t(n.splitText(o,r)[0===o?0:1])}}i(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),i=p(t.getNode(),h);o(n)&&r.set(n.getKey(),n),o(i)&&r.set(i.getKey(),i)}for(const t of e.getNodes())if(o(t)&&h(t))r.set(t.getKey(),t);else if(null===l){const e=p(t,h);o(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(c())&&y(s)}function X(e){return e.getNode().isAttached()}function q(e){let t=e;for(;null!==t&&!v(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];v(l)?(J(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&N(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,l,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let g=o(c)?c:c.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());let a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),v(g))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];o(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const p=new Set;for(let e=0;e<n;e++){const n=t[e];let r=n.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&C(n)&&!p.has(n.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=l();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),u.push(t),f.set(e,t),r.getChildren().forEach(e=>{t.append(e),p.add(e.getKey()),o(e)&&e.getChildrenKeys().forEach(e=>p.add(e))}),q(r)}}else if(d.has(n.getKey())){o(n)||K(179);const e=l();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),u.push(e),n.remove(!0)}}if(null!==s)for(let e=0;e<u.length;e++){const t=u[e];s.append(t)}let h=null;if(v(g))if(a)if(null!==s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t)}else{const e=g.getFirstChild();if(o(e)&&(g=e),null===e)if(s)g.append(s);else for(let e=0;e<u.length;e++){const t=u[e];g.append(t),h=t}else if(null!==s)e.insertBefore(s);else for(let t=0;t<u.length;t++){const n=u[t];e.insertBefore(n),h=n}}else if(s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t),h=t}const m=r();i(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 o(t)?O(t):z(t)}function Z(e,t){let n=Q(e)?!t:t;te(e)&&(n=!n);const l=m(e.focus,n?"previous":"next");if(S(l))return!1;for(const e of x(l)){if(T(e))return!e.origin.isInline();if(!o(e.origin)){if(w(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 l=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,g=f?c.getNode():s.getNode();if(i(t)&&t.isCollapsed()&&""!==t.style){const e=b(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const s=r[t];if((0===t||0!==u||!s.is(g))&&e(s)){const e=oe(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}const re=L;export{$ as $addNodeStyle,V as $copyBlockFormatIndent,H as $ensureForwardRangeSelection,j as $forEachSelectedTextNode,O as $getComputedStyleForElement,z 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,R as getCSSFromStyleObject,b as getStyleObjectFromCSS,re as trimTextContentFromAnchor};
|
|
9
|
+
import{$isTextNode as e,$getEditor as t,$isRootNode as n,$isElementNode as o,$getNodeByKey as l,$getPreviousSelection as r,$createTextNode as s,$isRangeSelection as i,$getSelection as c,$caretRangeFromSelection as f,$isTokenOrSegmented as u,$getCharacterOffsets as g,$cloneWithPropertiesEphemeral 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 w,$isRootOrShadowRoot as N,$hasAncestor as v,$isLeafNode as C}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 R(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function z(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 z(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)&&!u(t)&&null!==o){const[l,r]=o,s=e.isBackward(),i=l.getNode(),c=r.getNode(),f=t.is(i),u=t.is(c);if(f||u){const[o,l]=g(e),r=i.is(c),f=t.is(s?c:i),u=t.is(s?i:c);let d,p=0;if(r)p=o>l?l:o,d=o>l?o:l;else if(f){p=s?l:o,d=void 0}else if(u){p=0,d=s?o:l}const h=t.__text.slice(p,d);h!==t.__text&&("clone"===n&&(t=a(t)),t.__text=h)}}return t}function _(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return o(t)||K(177),e.offset===t.getChildrenSize()}function L(t,c,f){let u=c.getNode(),g=f;if(o(u)){const e=u.getDescendantByIndex(c.offset);null!==e&&(u=e)}for(;g>0&&null!==u;){if(o(u)){const e=u.getLastDescendant();null!==e&&(u=e)}let f=u.getPreviousSibling(),a=0;if(null===f){let e=u.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){f=null;break}t=e.getPreviousSibling()}null!==e&&(a=e.isInline()?0:2,f=t)}let d=u.getTextContent();""===d&&o(u)&&!u.isInline()&&(d="\n\n");const p=d.length;if(!e(u)||g>=p){const e=u.getParent();u.remove(),null==e||0!==e.getChildrenSize()||n(e)||e.remove(),g-=p+a,u=f}else{const n=u.getKey(),o=t.getEditorState().read(()=>{const t=l(n);return e(t)&&t.isSimpleText()?t.getTextContent():null}),f=p-g,a=d.slice(0,f);if(null!==o&&o!==d){const e=r();let t=u;if(u.isSimpleText())u.setTextContent(o);else{const e=s(o);u.replace(e),t=e}if(i(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(u.isSimpleText()){const e=c.key===n;let t=c.offset;t<g&&(t=p);const o=e?t-g:0,l=e?t:f;if(e&&0===o){const[e]=u.splitText(o,l);e.remove()}else{const[,e]=u.splitText(o,l);e.remove()}}else{const e=s(a);u.replace(e)}g=0}}}function $(e){const t=e.getStyle(),n=F(t);E.set(t,n)}function D(t,n){(i(t)?t.isCollapsed():e(t)||o(t))||K(280);const l=b(i(t)?t.style:e(t)?t.getStyle():t.getTextStyle()),r=Object.entries(n).reduce((e,[n,o])=>("function"==typeof o?e[n]=o(l[n],t):null===o?delete e[n]:e[n]=o,e),{...l}),s=R(r);i(t)||e(t)?t.setStyle(s):t.setTextStyle(s),E.set(s,r)}function U(e,t){if(i(e)&&e.isCollapsed()){D(e,t);const n=e.anchor.getNode();o(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 l of n){if(!o(l)||!l.canBeEmpty()||0!==l.getChildrenSize())continue;const n=l.getKey();e.has(n)||(e.add(n),D(l,t))}}}function j(t){const n=c();if(!n)return;const o=new Map,l=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(i(n))for(const e of f(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const r=n.getNodes();for(const n of r){if(!e(n)||!n.canHaveFormat())continue;const[o,r]=l(n);if(r!==o)if(u(n)||0===o&&r===n.getTextContentSize())t(n);else{t(n.splitText(o,r)[0===o?0:1])}}i(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),i=p(t.getNode(),h);o(n)&&r.set(n.getKey(),n),o(i)&&r.set(i.getKey(),i)}for(const t of e.getNodes())if(o(t)&&h(t))r.set(t.getKey(),t);else if(null===l){const e=p(t,h);o(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(c())&&y(s)}function X(e){return e.getNode().isAttached()}function q(e){let t=e;for(;null!==t&&!N(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];N(l)?(J(e,c,c.length,t,n),c=[],i=l):null===i||null!==i&&v(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,l,s=null){if(0===t.length)return;const c=t[0],f=new Map,u=[];let g=o(c)?c:c.getParentOrThrow();g.isInline()&&(g=g.getParentOrThrow());let a=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,a=!0;break}if(g=g.getParentOrThrow(),N(g))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];o(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const p=new Set;for(let e=0;e<n;e++){const n=t[e];let r=n.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&C(n)&&!p.has(n.getKey())){const e=r.getKey();if(void 0===f.get(e)){const t=l();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),u.push(t),f.set(e,t),r.getChildren().forEach(e=>{t.append(e),p.add(e.getKey()),o(e)&&e.getChildrenKeys().forEach(e=>p.add(e))}),q(r)}}else if(d.has(n.getKey())){o(n)||K(179);const e=l();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),u.push(e),n.remove(!0)}}if(null!==s)for(let e=0;e<u.length;e++){const t=u[e];s.append(t)}let h=null;if(N(g))if(a)if(null!==s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t)}else{const e=g.getFirstChild();if(o(e)&&(g=e),null===e)if(s)g.append(s);else for(let e=0;e<u.length;e++){const t=u[e];g.append(t),h=t}else if(null!==s)e.insertBefore(s);else for(let t=0;t<u.length;t++){const n=u[t];e.insertBefore(n),h=n}}else if(s)g.insertAfter(s);else for(let e=u.length-1;e>=0;e--){const t=u[e];g.insertAfter(t),h=t}const m=r();i(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 o(t)?z(t):O(t)}function Z(e,t){let n=Q(e)?!t:t;te(e)&&(n=!n);const l=m(e.focus,n?"previous":"next");if(S(l))return!1;for(const e of x(l)){if(T(e))return!e.origin.isInline();if(!o(e.origin)){if(w(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 l=null;const r=t.getNodes(),s=t.anchor,c=t.focus,f=t.isBackward(),u=f?c.offset:s.offset,g=f?c.getNode():s.getNode();if(i(t)&&t.isCollapsed()&&""!==t.style){const e=b(t.style);if(null!==e&&n in e)return e[n]}for(let t=0;t<r.length;t++){const s=r[t];if((0===t||0!==u||!s.is(g))&&e(s)){const e=oe(s,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}const re=L;export{$ as $addNodeStyle,V as $copyBlockFormatIndent,H as $ensureForwardRangeSelection,j as $forEachSelectedTextNode,z 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,R as getCSSFromStyleObject,b as getStyleObjectFromCSS,re as trimTextContentFromAnchor};
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.39.0",
|
|
13
13
|
"main": "LexicalSelection.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/facebook/lexical",
|
|
17
|
+
"url": "git+https://github.com/facebook/lexical.git",
|
|
18
18
|
"directory": "packages/lexical-selection"
|
|
19
19
|
},
|
|
20
20
|
"module": "LexicalSelection.mjs",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"lexical": "0.
|
|
40
|
+
"lexical": "0.39.0"
|
|
41
41
|
}
|
|
42
42
|
}
|