@lexical/selection 0.51.1-nightly.20260925.0 → 0.52.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.
|
@@ -159,11 +159,13 @@ function createRectsFromDOMRange(editor, range) {
|
|
|
159
159
|
let prevRect;
|
|
160
160
|
for (let i = 0; i < selectionRectsLength; i++) {
|
|
161
161
|
const selectionRect = selectionRects[i];
|
|
162
|
-
//
|
|
163
|
-
|
|
162
|
+
// Only discard a rect whose entire area is already covered. Mixed font
|
|
163
|
+
// metrics can put a later run before an earlier one in the sorted list,
|
|
164
|
+
// and partially overlapping rects can each cover unique selected text.
|
|
165
|
+
const isContainedRect = prevRect && prevRect.top <= selectionRect.top && prevRect.bottom >= selectionRect.bottom && prevRect.left <= selectionRect.left && prevRect.right >= selectionRect.right;
|
|
164
166
|
// Exclude selections that span the entire element
|
|
165
167
|
const selectionSpansElement = selectionRect.width + rootPadding === rootRect.width;
|
|
166
|
-
if (
|
|
168
|
+
if (isContainedRect || selectionSpansElement) {
|
|
167
169
|
selectionRects.splice(i--, 1);
|
|
168
170
|
selectionRectsLength--;
|
|
169
171
|
continue;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{getRootOwnerDocument as e,$isTextNode as t,$getEditor as n,$isRootNode as o,$getSelection as
|
|
10
|
-
/*@__INLINE__*/function
|
|
9
|
+
import{getRootOwnerDocument as e,$isTextNode as t,$getEditor as n,$isRootNode as o,$getSelection as r,$isRangeSelection as l,$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 B}from"lexical";export{$cloneWithProperties,$selectAll}from"lexical";function k(e,...t){throw function(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);return n.search=o.toString(),new 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.`)}(e,...t)}
|
|
10
|
+
/*@__INLINE__*/function F(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,r,l,i){const s=o.getKey(),c=l.getKey(),f=e(n.getRootElement()).createRange();let u=n.getElementByKey(s),g=n.getElementByKey(c),a=r,d=i;if(t(o)&&(u=z(u)),t(l)&&(g=z(g)),void 0===o||void 0===l||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(),r=getComputedStyle(n),l=parseFloat(r.paddingLeft)+parseFloat(r.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.bottom>=t.bottom&&s.left<=t.left&&s.right>=t.right,r=t.width+l===o.width;n||r?(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[r,l]=o,i=e.isBackward(),s=r.getNode(),c=l.getNode(),g=t.is(s),a=t.is(c);if(g||a){const[o,r]=f(e),l=s.is(c),g=t.is(i?c:s),a=t.is(i?s:c);let d,p=0;l?(p=o>r?r:o,d=o>r?o:r):g?(p=i?r:o,d=void 0):a&&(p=0,d=i?o:r);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)||k(177),e.offset===t.getChildrenSize()}function j(e,n,r){let i=n.getNode(),s=r;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 r=i.getPreviousSibling(),f=0;if(null===r){let e=i.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 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=r}else{const o=i.getKey(),r=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!==r&&r!==u){const e=a();let t=i;if(i.isSimpleText())i.setTextContent(r);else{const e=d(r);i.replace(e),t=e}if(l(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 r=e?t-s:0,l=e?t:c;if(e&&0===r){const[e]=i.splitText(r,l);e.remove()}else{const[,e]=i.splitText(r,l);e.remove()}}else{const e=d(f);i.replace(e)}s=0}}}const H=/* @__PURE__ */F();function V(e,n){(l(e)?e.isCollapsed():t(e)||c(e))||k(280);const o=p(l(e)?e.style:t(e)?e.getStyle():e.getTextStyle()),r=_(Object.entries(n).reduce((t,[n,r])=>("function"==typeof r?t[n]=r(o[n],e):null===r?delete t[n]:t[n]=r,t),{...o}));l(e)||t(e)?e.setStyle(r):e.setTextStyle(r)}function W(e,t){const n=new Set;if(l(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=r();if(!n)return;const o=new Map,c=e=>o.get(e.getKey())||[0,e.getTextContentSize()];if(l(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,r]=c(n);r!==o&&(s(n)||0===o&&r===n.getTextContentSize()?e(n):e(n.splitText(o,r)[0===o?0:1]))}l(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:r,type:l}=t;t.set(n.key,n.offset,n.type),n.set(o,r,l)}}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 r=!1,l=null;const i=new Map;if(o){const[t,n]=o,s=m(t.getNode(),S);l=m(n.getNode(),S);const f=e.isBackward()?"previous":"next";r=c(l)&&!l.is(s)&&function(e,t,n){const o=e.getNode();return(!c(o)||!o.isEmpty())&&J(e,t,n)}(n,l,x(f)),c(s)&&i.set(s.getKey(),s),c(l)&&!r&&i.set(l.getKey(),l)}for(const t of e.getNodes())if(c(t)&&S(t)){if(r&&t.is(l))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(),r=o?o[0]:null,l=e.getNodes(),i=l.length;if(null!==r){const e=K(r.getNode());if(null!==e&&!E(e))return}if(null!==r&&(0===i||1===i&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),o=e.getChildren();let l=t();return l.setFormat(e.getFormatType()),l.setIndent(e.getIndent()),o.forEach(e=>l.append(e)),n&&(l=n.append(l)),void e.replace(l)}let s=null,c=[];for(let o=0;o<i;o++){const r=l[o];E(r)?(te(e,c,c.length,t,n),c=[],s=r):null===s||null!==s&&I(r,s)?c.push(r):(te(e,c,c.length,t,n),c=[r])}te(e,c,c.length,t,n)}function te(e,t,n,o,r=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 r=n.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&b(n)&&!h.has(n.getKey())){const e=r.getKey();if(void 0===s.get(e)){const t=o();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),f.push(t),s.set(e,t);const n=r.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(r)}}else if(p.has(n.getKey())){c(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 y=null;if(E(g))if(d)if(null!==r)g.insertAfter(r);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(r)e.append(r);else for(let t=0;t<f.length;t++){const n=f[t];e.append(n),y=n}else if(null!==r)t.insertBefore(r);else for(let e=0;e<f.length;e++){const n=f[e];t.insertBefore(n),y=n}}else if(r)g.insertAfter(r);else for(let e=f.length-1;e>=0;e--){const t=f[e];g.insertAfter(t),y=t}const m=a();l(m)&&Y(m.anchor)&&Y(m.focus)?B(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 re(e,n){let o=ne(e)?!n:n;ie(e)&&(o=!o);const r=h(e.focus,o?"previous":"next");if(y(r))return!1;if(N(r)&&!T(r.origin)&&r.origin.isUnmergeable()){const e=r.getNodeAtCaret();if(t(e)&&!T(e))return!0}for(const e of v(r)){if(w(e))return!e.origin.isInline();if(!c(e.origin)){if(P(e.origin))return!0;break}}return!1}function le(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 r;r=ne(e)||o?!n:n,le(e,t,r,"character")}function ce(e,t,n){const o=e.getStyle(),r=p(o);return null!==r&&r[t]||n}function fe(e,n,o=""){let r=null;const i=e.getNodes();let s,c;if(l(e)){if(e.isCollapsed()&&""!==e.style){const t=p(e.style);if(null!==t&&n in t)return t[n]}const{anchor:o,focus:r}=e,l=e.isBackward(),i=l?r.getNode():o.getNode(),f=l?o.getNode():r.getNode(),u=l?r.offset:o.offset,g=l?o.offset:r.offset;t(i)&&u===i.getTextContentSize()&&(s=i),0===g&&(c=f)}for(let e=0;e<i.length;e++){const l=i[e];if(t(l)&&!l.is(0===e?s:c)){const e=ce(l,n,o);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?o:r}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,le as $moveCaretSelection,se as $moveCharacter,W as $patchStyleText,Q as $setBlocksType,re 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.
|
|
12
|
+
"version": "0.52.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.
|
|
34
|
-
"lexical": "0.
|
|
33
|
+
"@lexical/internal": "0.52.0",
|
|
34
|
+
"lexical": "0.52.0"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist",
|
package/src/utils.ts
CHANGED
|
@@ -158,16 +158,19 @@ export function createRectsFromDOMRange(
|
|
|
158
158
|
let prevRect;
|
|
159
159
|
for (let i = 0; i < selectionRectsLength; i++) {
|
|
160
160
|
const selectionRect = selectionRects[i];
|
|
161
|
-
//
|
|
162
|
-
|
|
161
|
+
// Only discard a rect whose entire area is already covered. Mixed font
|
|
162
|
+
// metrics can put a later run before an earlier one in the sorted list,
|
|
163
|
+
// and partially overlapping rects can each cover unique selected text.
|
|
164
|
+
const isContainedRect =
|
|
163
165
|
prevRect &&
|
|
164
166
|
prevRect.top <= selectionRect.top &&
|
|
165
|
-
prevRect.
|
|
166
|
-
prevRect.left
|
|
167
|
+
prevRect.bottom >= selectionRect.bottom &&
|
|
168
|
+
prevRect.left <= selectionRect.left &&
|
|
169
|
+
prevRect.right >= selectionRect.right;
|
|
167
170
|
// Exclude selections that span the entire element
|
|
168
171
|
const selectionSpansElement =
|
|
169
172
|
selectionRect.width + rootPadding === rootRect.width;
|
|
170
|
-
if (
|
|
173
|
+
if (isContainedRect || selectionSpansElement) {
|
|
171
174
|
selectionRects.splice(i--, 1);
|
|
172
175
|
selectionRectsLength--;
|
|
173
176
|
continue;
|