@lexical/selection 0.51.0 → 0.51.1-nightly.20260921.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.
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import{getRootOwnerDocument as e,$isTextNode as t,$getEditor as n,$isRootNode as o,$getSelection as l,$isRangeSelection as r,$caretRangeFromSelection as i,$isTokenOrSegmented as s,$isElementNode as c,$getCharacterOffsets as f,$cloneWithPropertiesEphemeral as u,$getNodeByKey as g,$getPreviousSelection as a,$createTextNode as d,getStyleObjectFromCSS as p,$caretFromPoint as h,$isExtendableTextPointCaret as y,$findMatchingParent as m,INTERNAL_$isBlock as S,flipDirection as x,$getSlotHost as C,$isTextPointCaret as N,$isTabNode as T,$extendCaretToRange as v,$isChildCaret as w,$isDecoratorNode as P,$getSlotFrame as K,$isRootOrShadowRoot as E,$hasAncestor as I,$isLeafNode as B,$setSelection as k}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function F(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.`)}
|
|
10
|
-
/*@__INLINE__*/function b(e){return()=>{}}function z(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function A(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function R(n,o,l,r,i){const s=o.getKey(),c=r.getKey(),f=e(n.getRootElement()).createRange();let u=n.getElementByKey(s),g=n.getElementByKey(c),a=l,d=i;if(t(o)&&(u=z(u)),t(r)&&(g=z(g)),void 0===o||void 0===r||null===u||null===g)return null;"BR"===u.nodeName&&([u,a]=A(u)),"BR"===g.nodeName&&([g,d]=A(g));const p=u.firstChild;u===g&&null!=p&&"BR"===p.nodeName&&0===a&&0===d&&(d=1);try{f.setStart(u,a),f.setEnd(g,d)}catch(e){return null}return!f.collapsed||a===d&&s===c||(f.setStart(g,d),f.setEnd(u,a)),f}function O(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),i=Array.from(t.getClientRects());let s,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=s&&s.top<=t.top&&s.top+s.height>t.top&&s.left+s.width>t.left,l=t.width+r===o.width;n||l?(i.splice(e--,1),c--):s=t}return i}function _(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function L(e){const t=n().getElementByKey(e.getKey());if(null===t)return null;const o=t.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(t)}function M(e){const t=o(e)?e:e.getParent();return t&&L(t)}function $(e){const t=M(e);return null!==t&&"rtl"===t.direction}function D(e,t,n="self"){const o=e.getStartEndPoints();if(t.isSelected(e)&&!s(t)&&null!==o){const[l,r]=o,i=e.isBackward(),s=l.getNode(),c=r.getNode(),g=t.is(s),a=t.is(c);if(g||a){const[o,l]=f(e),r=s.is(c),g=t.is(i?c:s),a=t.is(i?s:c);let d,p=0;
|
|
10
|
+
/*@__INLINE__*/function b(e){return()=>{}}function z(e){let t=e;for(;null!=t;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function A(e){const t=e.parentNode;if(null==t)throw new Error("Should never happen");return[t,Array.from(t.childNodes).indexOf(e)]}function R(n,o,l,r,i){const s=o.getKey(),c=r.getKey(),f=e(n.getRootElement()).createRange();let u=n.getElementByKey(s),g=n.getElementByKey(c),a=l,d=i;if(t(o)&&(u=z(u)),t(r)&&(g=z(g)),void 0===o||void 0===r||null===u||null===g)return null;"BR"===u.nodeName&&([u,a]=A(u)),"BR"===g.nodeName&&([g,d]=A(g));const p=u.firstChild;u===g&&null!=p&&"BR"===p.nodeName&&0===a&&0===d&&(d=1);try{f.setStart(u,a),f.setEnd(g,d)}catch(e){return null}return!f.collapsed||a===d&&s===c||(f.setStart(g,d),f.setEnd(u,a)),f}function O(e,t){const n=e.getRootElement();if(null===n)return[];const o=n.getBoundingClientRect(),l=getComputedStyle(n),r=parseFloat(l.paddingLeft)+parseFloat(l.paddingRight),i=Array.from(t.getClientRects());let s,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=s&&s.top<=t.top&&s.top+s.height>t.top&&s.left+s.width>t.left,l=t.width+r===o.width;n||l?(i.splice(e--,1),c--):s=t}return i}function _(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}function L(e){const t=n().getElementByKey(e.getKey());if(null===t)return null;const o=t.ownerDocument.defaultView;return null===o?null:o.getComputedStyle(t)}function M(e){const t=o(e)?e:e.getParent();return t&&L(t)}function $(e){const t=M(e);return null!==t&&"rtl"===t.direction}function D(e,t,n="self"){const o=e.getStartEndPoints();if(t.isSelected(e)&&!s(t)&&null!==o){const[l,r]=o,i=e.isBackward(),s=l.getNode(),c=r.getNode(),g=t.is(s),a=t.is(c);if(g||a){const[o,l]=f(e),r=s.is(c),g=t.is(i?c:s),a=t.is(i?s:c);let d,p=0;r?(p=o>l?l:o,d=o>l?o:l):g?(p=i?l:o,d=void 0):a&&(p=0,d=i?o:l);const h=t.__text.slice(p,d);h!==t.__text&&("clone"===n&&(t=u(t)),t.__text=h)}}return t}function U(e){if("text"===e.type)return e.offset===e.getNode().getTextContentSize();const t=e.getNode();return c(t)||F(177),e.offset===t.getChildrenSize()}function j(e,n,l){let i=n.getNode(),s=l;if(c(i)){const e=i.getDescendantByIndex(n.offset);null!==e&&(i=e)}for(;s>0&&null!==i;){if(c(i)){const e=i.getLastDescendant();null!==e&&(i=e)}let l=i.getPreviousSibling(),f=0;if(null===l){let e=i.getParentOrThrow(),t=e.getPreviousSibling();for(;null===t;){if(e=e.getParent(),null===e){l=null;break}t=e.getPreviousSibling()}null!==e&&(f=e.isInline()?0:2,l=t)}let u=i.getTextContent();""===u&&c(i)&&!i.isInline()&&(u="\n\n");const p=u.length;if(!t(i)||s>=p){const e=i.getParent();i.remove(),null==e||0!==e.getChildrenSize()||o(e)||e.remove(),s-=p+f,i=l}else{const o=i.getKey(),l=e.read("latest",()=>{const e=g(o);return t(e)&&e.isSimpleText()?e.getTextContent():null}),c=p-s,f=u.slice(0,c);if(null!==l&&l!==u){const e=a();let t=i;if(i.isSimpleText())i.setTextContent(l);else{const e=d(l);i.replace(e),t=e}if(r(e)&&e.isCollapsed()){const n=e.anchor.offset;t.select(n,n)}}else if(i.isSimpleText()){const e=n.key===o;let t=n.offset;t<s&&(t=p);const l=e?t-s:0,r=e?t:c;if(e&&0===l){const[e]=i.splitText(l,r);e.remove()}else{const[,e]=i.splitText(l,r);e.remove()}}else{const e=d(f);i.replace(e)}s=0}}}const H=/* @__PURE__ */b();function V(e,n){(r(e)?e.isCollapsed():t(e)||c(e))||F(280);const o=p(r(e)?e.style:t(e)?e.getStyle():e.getTextStyle()),l=_(Object.entries(n).reduce((t,[n,l])=>("function"==typeof l?t[n]=l(o[n],e):null===l?delete t[n]:t[n]=l,t),{...o}));r(e)||t(e)?e.setStyle(l):e.setTextStyle(l)}function W(e,t){const n=new Set;if(r(e)&&e.isCollapsed()){V(e,t);const o=e.anchor.getNode();c(o)&&o.isEmpty()&&(n.add(o.getKey()),V(o,t))}X(e=>{V(e,t)});const o=e.getNodes();if(o.length>0)for(const e of o){if(!c(e)||!e.canBeEmpty()||0!==e.getChildrenSize())continue;const o=e.getKey();n.has(o)||(n.add(o),V(e,t))}}function X(e){const n=l();if(!n)return;const o=new Map,c=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(r(n))for(const e of i(n).getTextSlices())e&&o.set(e.caret.origin.getKey(),e.getSliceIndices());const f=n.getNodes();for(const n of f){if(!t(n)||!n.canHaveFormat())continue;const[o,l]=c(n);l!==o&&(s(n)||0===o&&l===n.getTextContentSize()?e(n):e(n.splitText(o,l)[0===o?0:1]))}r(n)&&"text"===n.anchor.type&&"text"===n.focus.type&&n.anchor.key===n.focus.key&&q(n)}function q(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 G(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function J(e,t,n){let o=h(e,n);if(y(o))return!1;for(;o;o=o.getParentCaret()){const e=o.getParentAtCaret();if(!e||o.getNodeAtCaret())return!1;if(t.is(e))return!0}return!1}function Q(e,t,n=G){if(!e)return;const o=e.getStartEndPoints();let l=!1,r=null;const i=new Map;if(o){const[t,n]=o,s=m(t.getNode(),S);r=m(n.getNode(),S);const f=e.isBackward()?"previous":"next";l=c(r)&&!r.is(s)&&function(e,t,n){const o=e.getNode();return(!c(o)||!o.isEmpty())&&J(e,t,n)}(n,r,x(f)),c(s)&&i.set(s.getKey(),s),c(r)&&!l&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(c(t)&&S(t)){if(l&&t.is(r))continue;i.set(t.getKey(),t)}else if(!o){const e=m(t,S);c(e)&&i.set(e.getKey(),e)}for(const e of i.values()){if(null!==C(e))continue;const o=t();n(e,o),e.replace(o,!0)}}function Y(e){return e.getNode().isAttached()}function Z(e){let t=e;for(;null!==t&&!E(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function ee(e,t,n=null){const o=e.getStartEndPoints(),l=o?o[0]:null,r=e.getNodes(),i=r.length;if(null!==l){const e=K(l.getNode());if(null!==e&&!E(e))return}if(null!==l&&(0===i||1===i&&"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 s=null,c=[];for(let o=0;o<i;o++){const l=r[o];E(l)?(te(e,c,c.length,t,n),c=[],s=l):null===s||null!==s&&I(l,s)?c.push(l):(te(e,c,c.length,t,n),c=[l])}te(e,c,c.length,t,n)}function te(e,t,n,o,l=null){if(0===t.length)return;const i=t[0],s=new Map,f=[],u=c(i)?i:i.getParentOrThrow();let g=u.isInline()?u.getParentOrThrow():u,d=!1;for(;null!==g;){const e=g.getPreviousSibling();if(null!==e){g=e,d=!0;break}if(g=g.getParentOrThrow(),E(g))break}const p=new Set;for(let e=0;e<n;e++){const n=t[e];c(n)&&0===n.getChildrenSize()&&p.add(n.getKey())}const h=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&&B(n)&&!h.has(n.getKey())){const e=l.getKey();if(void 0===s.get(e)){const t=o();t.setFormat(l.getFormatType()),t.setIndent(l.getIndent()),f.push(t),s.set(e,t);const n=l.getChildren();t.splice(t.getChildrenSize(),0,n);for(const e of n)if(h.add(e.getKey()),c(e))for(const t of e.getChildrenKeys())h.add(t);Z(l)}}else if(p.has(n.getKey())){c(n)||F(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),f.push(e),n.remove(!0)}}if(null!==l)for(let e=0;e<f.length;e++){const t=f[e];l.append(t)}let y=null;if(E(g))if(d)if(null!==l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t)}else{const e=g,t=e.getFirstChild();if(c(t)&&(g=t),null===t)if(l)e.append(l);else for(let t=0;t<f.length;t++){const n=f[t];e.append(n),y=n}else if(null!==l)t.insertBefore(l);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),y=n}}else if(l)g.insertAfter(l);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t),y=t}const m=a();r(m)&&Y(m.anchor)&&Y(m.focus)?k(m.clone()):null!==y?y.selectEnd():e.dirty=!0}function ne(e){const t=oe(e);return null!==t&&"vertical-rl"===t.writingMode}function oe(e){const t=e.anchor.getNode();return c(t)?L(t):M(t)}function le(e,n){let o=ne(e)?!n:n;ie(e)&&(o=!o);const l=h(e.focus,o?"previous":"next");if(y(l))return!1;if(N(l)&&!T(l.origin)&&l.origin.isUnmergeable()){const e=l.getNodeAtCaret();if(t(e)&&!T(e))return!0}for(const e of v(l)){if(w(e))return!e.origin.isInline();if(!c(e.origin)){if(P(e.origin))return!0;break}}return!1}function re(e,t,n,o){e.modify(t?"extend":"move",n,o)}function ie(e){const t=oe(e);return null!==t&&"rtl"===t.direction}function se(e,t,n){const o=ie(e);let l;l=ne(e)||o?!n:n,re(e,t,l,"character")}function ce(e,t,n){const o=e.getStyle(),l=p(o);return null!==l&&l[t]||n}function fe(e,n,o=""){let l=null;const i=e.getNodes();let s,c;if(r(e)){if(e.isCollapsed()&&""!==e.style){const t=p(e.style);if(null!==t&&n in t)return t[n]}const{anchor:o,focus:l}=e,r=e.isBackward(),i=r?l.getNode():o.getNode(),f=r?o.getNode():l.getNode(),u=r?l.offset:o.offset,g=r?o.offset:l.offset;t(i)&&u===i.getTextContentSize()&&(s=i),0===g&&(c=f)}for(let e=0;e<i.length;e++){const r=i[e];if(t(r)&&!r.is(0===e?s:c)){const e=ce(r,n,o);if(null===l)l=e;else if(l!==e){l="";break}}}return null===l?o:l}const ue=p,ge=j;export{H as $addNodeStyle,G as $copyBlockFormatIndent,q as $ensureForwardRangeSelection,X as $forEachSelectedTextNode,L as $getComputedStyleForElement,M as $getComputedStyleForParent,fe as $getSelectionStyleValueForProperty,J as $isAtEdgeOfElement,U as $isAtNodeEnd,ie as $isParentElementRTL,$ as $isParentRTL,re as $moveCaretSelection,se as $moveCharacter,W as $patchStyleText,Q as $setBlocksType,le as $shouldOverrideDefaultCharacterSelection,D as $sliceSelectedTextNodeContent,j as $trimTextContentFromAnchor,ee as $wrapNodes,R as createDOMRange,O as createRectsFromDOMRange,_ as getCSSFromStyleObject,ue as getStyleObjectFromCSS,ge as trimTextContentFromAnchor};
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"selection"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.51.0",
|
|
12
|
+
"version": "0.51.1-nightly.20260921.0",
|
|
13
13
|
"main": "./dist/LexicalSelection.js",
|
|
14
14
|
"types": "./dist/typescript-too-old.d.ts",
|
|
15
15
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lexical/internal": "0.51.0",
|
|
34
|
-
"lexical": "0.51.0"
|
|
33
|
+
"@lexical/internal": "0.51.1-nightly.20260921.0",
|
|
34
|
+
"lexical": "0.51.1-nightly.20260921.0"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist",
|