@react-fabric/lexical 1.0.0-beta.57 → 1.0.0-beta.58
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/css/_lexical.css +4 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +33 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +525 -194
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +26 -23
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +3 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +95 -38
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +387 -124
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +22 -18
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +107 -8
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +4 -0
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +23 -20
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +420 -137
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +50 -45
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +61 -65
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +2 -0
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -46
- package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
- package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +34 -2
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +524 -196
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +96 -40
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +387 -127
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +56 -31
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +106 -10
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +3 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +417 -139
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +62 -67
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +2 -1
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
- package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
- package/package.json +12 -12
- package/src/hooks/useFormatWatcher.ts +3 -1
- package/src/plugins/ToolbarPlugin.tsx +5 -10
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement, mergeRegister } from '../utils/LexicalUtils.js';
|
|
4
|
-
import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, ElementNode, $isParagraphNode, $applyNodeReplacement, $createTextNode, createCommand, COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND, $isTextNode, TextNode } from 'lexical';
|
|
3
|
+
import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement, mergeRegister, $findMatchingParent, calculateZoomLevel } from '../utils/LexicalUtils.js';
|
|
4
|
+
import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, ElementNode, buildImportMap, $isParagraphNode, $applyNodeReplacement, $createTextNode, createCommand, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_SPACE_COMMAND, $getNearestNodeFromDOMNode, KEY_ARROW_LEFT_COMMAND, $getNodeByKey, INSERT_PARAGRAPH_COMMAND, $isTextNode, TextNode, getNearestEditorFromDOMNode } from 'lexical';
|
|
5
|
+
import { getStyleObjectFromCSS } from '../selection/LexicalSelection.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -11,6 +12,6 @@ import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraph
|
|
|
11
12
|
*
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
function v(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function k(t){let e=1,r=t.getParent();for(;null!=r;){if($(r)){const t=r.getParent();if(Y(t)){e++,r=t.getParent();continue}v(40);}return e}return e}function b(t){let e=t.getParent();Y(e)||v(40);let r=e;for(;null!==r;)r=r.getParent(),Y(r)&&(e=r);return e}function N(t){let e=[];const r=t.getChildren().filter($);for(let t=0;t<r.length;t++){const n=r[t],s=n.getFirstChild();Y(s)?e=e.concat(N(s)):e.push(n);}return e}function F(t){return $(t)&&Y(t.getFirstChild())}function O(t){return z().append(t)}function P(t,e){return $(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function A(t){const e=$getSelection();if(null!==e){let r=e.getNodes();if($isRangeSelection(e)){const n=e.getStartEndPoints();null===n&&v(143);const[s]=n,i=s.getNode(),o=i.getParent();if($isRootOrShadowRoot(i)){const t=i.getFirstChild();if(t)r=t.selectStart().getNodes();else {const t=$createParagraphNode();i.append(t),r=t.select().getNodes();}}else if(P(i,r)){const e=X(t);if($isRootOrShadowRoot(o)){i.replace(e);const t=z();$isElementNode(i)&&(t.setFormat(i.getFormatType()),t.setIndent(i.getIndent())),e.append(t);}else if($(i)){const t=i.getParentOrThrow();L(e,t.getChildren()),t.replace(e);}return}}const n=new Set;for(let e=0;e<r.length;e++){const s=r[e];if(!$isElementNode(s)||!s.isEmpty()||$(s)||n.has(s.getKey())){if($isLeafNode(s)){let e=s.getParent();for(;null!=e;){const r=e.getKey();if(Y(e)){if(!n.has(r)){const s=X(t);L(s,e.getChildren()),e.replace(s),n.add(r);}break}{const s=e.getParent();if($isRootOrShadowRoot(s)&&!n.has(r)){n.add(r),E(e,t);break}e=s;}}}}else E(s,t);}}}function L(t,e){t.splice(t.getChildrenSize(),0,e);}function E(t,e){if(Y(t))return t;const r=t.getPreviousSibling(),n=t.getNextSibling(),s=z();let i;if(L(s,t.getChildren()),Y(r)&&e===r.getListType())r.append(s),Y(n)&&e===n.getListType()&&(L(r,n.getChildren()),n.remove()),i=r;else if(Y(n)&&e===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else {const r=X(e);r.append(s),t.replace(r),i=r;}return s.setFormat(t.getFormatType()),s.setIndent(t.getIndent()),t.remove(),i}function M(t,e){const r=t.getLastChild(),n=e.getFirstChild();r&&n&&F(r)&&F(n)&&(M(r.getFirstChild(),n.getFirstChild()),n.remove());const s=e.getChildren();s.length>0&&t.append(...s),e.remove();}function w(){const e=$getSelection();if($isRangeSelection(e)){const r=new Set,n=e.getNodes(),s=e.anchor.getNode();if(P(s,n))r.add(b(s));else for(let e=0;e<n.length;e++){const s=n[e];if($isLeafNode(s)){const e=$getNearestNodeOfType(s,W);null!=e&&r.add(b(e));}}for(const t of r){let r=t;const n=N(t);for(const t of n){const n=$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);L(n,t.getChildren()),r.insertAfter(n),r=n,t.__key===e.anchor.key&&$setPointFromCaret(e.anchor,$normalizeCaret($getChildCaret(n,"next"))),t.__key===e.focus.key&&$setPointFromCaret(e.focus,$normalizeCaret($getChildCaret(n,"next"))),t.remove();}t.remove();}}}function I(t){const e=new Set;if(F(t)||e.has(t.getKey()))return;const r=t.getParent(),n=t.getNextSibling(),s=t.getPreviousSibling();if(F(n)&&F(s)){const r=s.getFirstChild();if(Y(r)){r.append(t);const s=n.getFirstChild();if(Y(s)){L(r,s.getChildren()),n.remove(),e.add(n.getKey());}}}else if(F(n)){const e=n.getFirstChild();if(Y(e)){const r=e.getFirstChild();null!==r&&r.insertBefore(t);}}else if(F(s)){const e=s.getFirstChild();Y(e)&&e.append(t);}else if(Y(r)){const e=z().setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle()),i=X(r.getListType()).setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle());e.append(i),i.append(t),s?s.insertAfter(e):n?n.insertBefore(e):r.append(e);}}function D(t){if(F(t))return;const e=t.getParent(),r=e?e.getParent():void 0;if(Y(r?r.getParent():void 0)&&$(r)&&Y(e)){const n=e?e.getFirstChild():void 0,s=e?e.getLastChild():void 0;if(t.is(n))r.insertBefore(t),e.isEmpty()&&r.remove();else if(t.is(s))r.insertAfter(t),e.isEmpty()&&r.remove();else {const n=e.getListType(),s=z(),i=X(n);s.append(i),t.getPreviousSiblings().forEach((t=>i.append(t)));const o=z(),l=X(n);o.append(l),L(l,t.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(t);}}}function J(){const t=$getSelection();if(!$isRangeSelection(t)||!t.isCollapsed())return !1;const e=t.anchor.getNode();if(!$(e)||0!==e.getChildrenSize())return !1;const r=b(e),n=e.getParent();Y(n)||v(40);const s=n.getParent();let a;if($isRootOrShadowRoot(s))a=$createParagraphNode(),r.insertAfter(a);else {if(!$(s))return !1;a=z(),s.insertAfter(a);}a.setTextStyle(t.style).setTextFormat(t.format).select();const h=e.getNextSiblings();if(h.length>0){const t=X(n.getListType());if($(a)){const e=z();e.append(t),a.insertAfter(e);}else a.insertAfter(t);t.append(...h);}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!$(t)&&!Y(t))break;e=t;}e.remove();}(e),!0}function R(...t){const e=[];for(const r of t)if(r&&"string"==typeof r)for(const[t]of r.matchAll(/\S+/g))e.push(t);return e}class W extends ElementNode{static getType(){return "listitem"}static clone(t){return new W(t.__value,t.__checked,t.__key)}constructor(t,e,r){super(r),this.__value=void 0===t?1:t,this.__checked=e;}createDOM(t){const e=document.createElement("li"),r=this.getParent();Y(r)&&"check"===r.getListType()&&K(e,this,null),e.value=this.__value,B(e,t.theme,this);const n=this.__style||this.__textStyle;return n&&(e.style.cssText=n),e}updateDOM(t,e,r){const n=this.getParent();Y(n)&&"check"===n.getListType()&&K(e,this,t),e.value=this.__value,B(e,r.theme,this);const s=t.__style||t.__textStyle,i=this.__style||this.__textStyle;return s!==i&&(e.style.cssText=i,""===i&&e.removeAttribute("style")),!1}static transform(){return t=>{if($(t)||v(144),null==t.__checked)return;const e=t.getParent();Y(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0);}}static importDOM(){return {li:()=>({conversion:V,priority:0})}}static importJSON(t){return z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config);e.style.textAlign=this.getFormatType();const r=this.getDirection();return r&&(e.dir=r),{element:e}}exportJSON(){return {...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if($isElementNode(r)&&this.canMergeWith(r)){const t=r.getChildren();this.append(...t),r.remove();}else super.append(r);}return this}replace(t,e){if($(t))return super.replace(t);this.setIndent(0);const r=this.getParentOrThrow();if(!Y(r))return t;if(r.__first===this.getKey())r.insertBefore(t);else if(r.__last===this.getKey())r.insertAfter(t);else {const e=X(r.getListType());let n=this.getNextSibling();for(;n;){const t=n;n=n.getNextSibling(),e.append(t);}r.insertAfter(t),t.insertAfter(e);}return e&&($isElementNode(t)||v(139),this.getChildren().forEach((e=>{t.append(e);}))),this.remove(),0===r.getChildrenSize()&&r.remove(),t}insertAfter(t,e=!0){const r=this.getParentOrThrow();if(Y(r)||v(39),$(t))return super.insertAfter(t,e);const n=this.getNextSiblings();if(r.insertAfter(t,e),0!==n.length){const s=X(r.getListType());n.forEach((t=>s.append(t))),t.insertAfter(s,e);}return t}remove(t){const e=this.getPreviousSibling(),r=this.getNextSibling();super.remove(t),e&&r&&F(e)&&F(r)&&(M(e.getFirstChild(),r.getFirstChild()),r.remove());}insertNewAfter(t,e=!0){const r=z().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,e),r}collapseAtStart(t){const e=$createParagraphNode();this.getChildren().forEach((t=>e.append(t)));const r=this.getParentOrThrow(),n=r.getParentOrThrow(),s=$(n);if(1===r.getChildrenSize())if(s)r.remove(),n.select();else {r.insertBefore(e),r.remove();const n=t.anchor,s=t.focus,i=e.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element");}else r.insertBefore(e),this.remove();return !0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const r=this.getParent();return Y(r)&&(e=r.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),r=0;for(;$(e);)e=e.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(t){"number"!=typeof t&&v(117),(t=Math.floor(t))>=0||v(199);let e=this.getIndent();for(;e!==t;)e<t?(I(this),e++):(D(this),e--);return this}canInsertAfter(t){return $(t)}canReplaceWith(t){return $(t)}canMergeWith(t){return $(t)||$isParagraphNode(t)}extractWithChild(t,e){if(!$isRangeSelection(e))return !1;const r=e.anchor.getNode(),n=e.focus.getNode();return this.isParentOf(r)&&this.isParentOf(n)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return !0}createParentElementNode(){return X("bullet")}canMergeWhenEmpty(){return !0}}function B(t,n,s){const i=[],o=[],l=n.list,c=l?l.listitem:void 0;let a;if(l&&l.nested&&(a=l.nested.listitem),void 0!==c&&i.push(...R(c)),l){const t=s.getParent(),e=Y(t)&&"check"===t.getListType(),r=s.getChecked();e&&!r||o.push(l.listitemUnchecked),e&&r||o.push(l.listitemChecked),e&&i.push(r?l.listitemChecked:l.listitemUnchecked);}if(void 0!==a){const t=R(a);s.getChildren().some((t=>Y(t)))?i.push(...t):o.push(...t);}o.length>0&&removeClassNamesFromElement(t,...o),i.length>0&&addClassNamesToElement(t,...i);}function K(t,e,r,n){Y(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),r&&e.__checked===r.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"));}function V(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return U(e);const e=t.getAttribute("aria-checked");return {node:z("true"===e||"false"!==e&&void 0)}}function U(t){if(!("checkbox"===t.getAttribute("type")))return {node:null};return {node:z(t.hasAttribute("checked"))}}function z(t){return $applyNodeReplacement(new W(void 0,t))}function $(t){return t instanceof W}class q extends ElementNode{static getType(){return "list"}static clone(t){const e=t.__listType||Q[t.__tag];return new q(e,t.__start,t.__key)}constructor(t="number",e=1,r){super(r);const n=Q[t]||t;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=e;}getTag(){return this.__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.__listType}getStart(){return this.__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,H(n,t.theme,this),n}updateDOM(t,e,r){return t.__tag!==this.__tag||(H(e,r.theme,this),!1)}static transform(){return t=>{Y(t)||v(163),function(t){const e=t.getNextSibling();Y(e)&&t.getListType()===e.getListType()&&M(t,e);}(t),function(t){const e="check"!==t.getListType();let r=t.getStart();for(const n of t.getChildren())$(n)&&(n.getValue()!==r&&n.setValue(r),e&&null!=n.getLatest().__checked&&n.setChecked(void 0),Y(n.getFirstChild())||r++);}(t);}}static importDOM(){return {ol:()=>({conversion:G,priority:0}),ul:()=>({conversion:G,priority:0})}}static importJSON(t){return X().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return isHTMLElement(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return {...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return !1}canIndent(){return !1}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if($(r))super.append(r);else {const t=z();if(Y(r))t.append(r);else if($isElementNode(r))if(r.isInline())t.append(r);else {const e=$createTextNode(r.getTextContent());t.append(e);}else t.append(r);super.append(t);}}return this}extractWithChild(t){return $(t)}}function H(t,n,s){const i=[],o=[],l=n.list;if(void 0!==l){const t=l[`${s.__tag}Depth`]||[],e=k(s)-1,r=e%t.length,n=t[r],c=l[s.__tag];let a;const h=l.nested,g=l.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==c&&i.push(c),void 0!==g&&"check"===s.__listType&&i.push(g),void 0!==n){i.push(...R(n));for(let e=0;e<t.length;e++)e!==r&&o.push(s.__tag+e);}if(void 0!==a){const t=R(a);e>1?i.push(...t):o.push(...t);}}o.length>0&&removeClassNamesFromElement(t,...o),i.length>0&&addClassNamesToElement(t,...i);}function j(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];if($(n)){e.push(n);const t=n.getChildren();t.length>1&&t.forEach((t=>{Y(t)&&e.push(O(t));}));}else e.push(O(n));}return e}function G(t){const e=t.nodeName.toLowerCase();let r=null;if("ol"===e){r=X("number",t.start);}else "ul"===e&&(r=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return !0;for(const e of t.childNodes)if(isHTMLElement(e)&&e.hasAttribute("aria-checked"))return !0;return !1}(t)?X("check"):X("bullet"));return {after:j,node:r}}const Q={ol:"number",ul:"bullet"};function X(t="number",e=1){return $applyNodeReplacement(new q(t,e))}function Y(t){return t instanceof q}const Z=createCommand("INSERT_UNORDERED_LIST_COMMAND"),tt=createCommand("INSERT_ORDERED_LIST_COMMAND"),et=createCommand("INSERT_CHECK_LIST_COMMAND"),rt=createCommand("REMOVE_LIST_COMMAND");function nt(t){return mergeRegister(t.registerCommand(tt,(()=>(A("number"),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(Z,(()=>(A("bullet"),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(rt,(()=>(w(),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>J()),COMMAND_PRIORITY_LOW),t.registerNodeTransform(W,(t=>{const e=t.getFirstChild();if(e){if($isTextNode(e)){const r=e.getStyle(),n=e.getFormat();t.getTextStyle()!==r&&t.setTextStyle(r),t.getTextFormat()!==n&&t.setTextFormat(n);}}else {const e=$getSelection();$isRangeSelection(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format);}})),t.registerNodeTransform(TextNode,(t=>{const e=t.getParent();if($(e)&&t.is(e.getFirstChild())){const r=t.getStyle(),n=t.getFormat();r===e.getTextStyle()&&n===e.getTextFormat()||e.setTextStyle(r).setTextFormat(n);}})))}function st(t,e){t.update((()=>A(e)));}function it(t){t.update((()=>w()));}
|
|
15
|
+
function I(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function M(t){let e=1,n=t.getParent();for(;null!=n;){if(nt(n)){const t=n.getParent();if(at(t)){e++,n=t.getParent();continue}I(40);}return e}return e}function R(t){let e=t.getParent();at(e)||I(40);let n=e;for(;null!==n;)n=n.getParent(),at(n)&&(e=n);return e}function B(t){let e=[];const n=t.getChildren().filter(nt);for(let t=0;t<n.length;t++){const r=n[t],i=r.getFirstChild();at(i)?e=e.concat(B(i)):e.push(r);}return e}function K(t){return nt(t)&&at(t.getFirstChild())}function W(t){return et().append(t)}function J(t,e){return nt(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function $(t){const e=$getSelection();if(null!==e){let n=e.getNodes();if($isRangeSelection(e)){const r=e.getStartEndPoints();null===r&&I(143);const[i]=r,s=i.getNode(),o=s.getParent();if($isRootOrShadowRoot(s)){const t=s.getFirstChild();if(t)n=t.selectStart().getNodes();else {const t=$createParagraphNode();s.append(t),n=t.select().getNodes();}}else if(J(s,n)){const e=ct(t);if($isRootOrShadowRoot(o)){s.replace(e);const t=et();$isElementNode(s)&&(t.setFormat(s.getFormatType()),t.setIndent(s.getIndent())),e.append(t);}else if(nt(s)){const t=s.getParentOrThrow();U(e,t.getChildren()),t.replace(e);}return}}const r=new Set;for(let e=0;e<n.length;e++){const i=n[e];if($isElementNode(i)&&i.isEmpty()&&!nt(i)&&!r.has(i.getKey())){V(i,t);continue}let s=$isLeafNode(i)?i.getParent():nt(i)&&i.isEmpty()?i:null;for(;null!=s;){const e=s.getKey();if(at(s)){if(!r.has(e)){const n=ct(t);U(n,s.getChildren()),s.replace(n),r.add(e);}break}{const n=s.getParent();if($isRootOrShadowRoot(n)&&!r.has(e)){r.add(e),V(s,t);break}s=n;}}}}}function U(t,e){t.splice(t.getChildrenSize(),0,e);}function V(t,e){if(at(t))return t;const n=t.getPreviousSibling(),r=t.getNextSibling(),i=et();let s;if(U(i,t.getChildren()),at(n)&&e===n.getListType())n.append(i),at(r)&&e===r.getListType()&&(U(n,r.getChildren()),r.remove()),s=n;else if(at(r)&&e===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else {const n=ct(e);n.append(i),t.replace(n),s=n;}return i.setFormat(t.getFormatType()),i.setIndent(t.getIndent()),t.remove(),s}function z(t,e){const n=t.getLastChild(),r=e.getFirstChild();n&&r&&K(n)&&K(r)&&(z(n.getFirstChild(),r.getFirstChild()),r.remove());const i=e.getChildren();i.length>0&&t.append(...i),e.remove();}function q(){const e=$getSelection();if($isRangeSelection(e)){const n=new Set,r=e.getNodes(),i=e.anchor.getNode();if(J(i,r))n.add(R(i));else for(let e=0;e<r.length;e++){const i=r[e];if($isLeafNode(i)){const e=$getNearestNodeOfType(i,Y);null!=e&&n.add(R(e));}}for(const t of n){let n=t;const r=B(t);for(const t of r){const r=$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);U(r,t.getChildren()),n.insertAfter(r),n=r,t.__key===e.anchor.key&&$setPointFromCaret(e.anchor,$normalizeCaret($getChildCaret(r,"next"))),t.__key===e.focus.key&&$setPointFromCaret(e.focus,$normalizeCaret($getChildCaret(r,"next"))),t.remove();}t.remove();}}}function H(t){const e="check"!==t.getListType();let n=t.getStart();for(const r of t.getChildren())nt(r)&&(r.getValue()!==n&&r.setValue(n),e&&null!=r.getLatest().__checked&&r.setChecked(void 0),at(r.getFirstChild())||n++);}function X(t){const e=new Set;if(K(t)||e.has(t.getKey()))return;const n=t.getParent(),r=t.getNextSibling(),i=t.getPreviousSibling();if(K(r)&&K(i)){const n=i.getFirstChild();if(at(n)){n.append(t);const i=r.getFirstChild();if(at(i)){U(n,i.getChildren()),r.remove(),e.add(r.getKey());}}}else if(K(r)){const e=r.getFirstChild();if(at(e)){const n=e.getFirstChild();null!==n&&n.insertBefore(t);}}else if(K(i)){const e=i.getFirstChild();at(e)&&e.append(t);}else if(at(n)){const e=et().setTextFormat(t.getTextFormat()).setTextStyle(t.getTextStyle()),s=ct(n.getListType()).setTextFormat(n.getTextFormat()).setTextStyle(n.getTextStyle());e.append(s),s.append(t),i?i.insertAfter(e):r?r.insertBefore(e):n.append(e);}}function j(t){if(K(t))return;const e=t.getParent(),n=e?e.getParent():void 0;if(at(n?n.getParent():void 0)&&nt(n)&&at(e)){const r=e?e.getFirstChild():void 0,i=e?e.getLastChild():void 0;if(t.is(r))n.insertBefore(t),e.isEmpty()&&n.remove();else if(t.is(i))n.insertAfter(t),e.isEmpty()&&n.remove();else {const r=e.getListType(),i=et(),s=ct(r);i.append(s),t.getPreviousSiblings().forEach((t=>s.append(t)));const o=et(),l=ct(r);o.append(l),U(l,t.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(t);}}}function G(){const t=$getSelection();if(!$isRangeSelection(t)||!t.isCollapsed())return !1;const e=t.anchor.getNode();if(!nt(e)||0!==e.getChildrenSize())return !1;const n=R(e),r=e.getParent();at(r)||I(40);const i=r.getParent();let s;if($isRootOrShadowRoot(i))s=$createParagraphNode(),n.insertAfter(s);else {if(!nt(i))return !1;s=et(),i.insertAfter(s);}s.setTextStyle(t.style).setTextFormat(t.format).select();const o=e.getNextSiblings();if(o.length>0){const t=ct(r.getListType());if(nt(s)){const e=et();e.append(t),s.insertAfter(e);}else s.insertAfter(t);t.append(...o);}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!nt(t)&&!at(t))break;e=t;}e.remove();}(e),!0}function Q(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}class Y extends ElementNode{$config(){return this.config("listitem",{$transform:t=>{if(null==t.__checked)return;const e=t.getParent();at(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0);},extends:ElementNode,importDOM:buildImportMap({li:()=>({conversion:Z,priority:0})})})}constructor(t=1,e=void 0,n){super(n),this.__value=void 0===t?1:t,this.__checked=e;}afterCloneFrom(t){super.afterCloneFrom(t),this.__value=t.__value,this.__checked=t.__checked;}createDOM(t){const e=document.createElement("li");return this.updateListItemDOM(null,e,t),e}updateListItemDOM(t,r,i){const s=this.getParent();at(s)&&"check"===s.getListType()&&function(t,e,n,r){at(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),n&&e.__checked===n.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"));}(r,this,t),r.value=this.__value,function(t,r,i){const s=[],o=[],l=r.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&s.push(...Q(c));if(l){const t=i.getParent(),e=at(t)&&"check"===t.getListType(),n=i.getChecked();e&&!n||o.push(l.listitemUnchecked),e&&n||o.push(l.listitemChecked),e&&s.push(n?l.listitemChecked:l.listitemUnchecked);}if(void 0!==a){const t=Q(a);i.getChildren().some((t=>at(t)))?s.push(...t):o.push(...t);}o.length>0&&removeClassNamesFromElement(t,...o);s.length>0&&addClassNamesToElement(t,...s);}(r,i.theme,this);const o=t?t.__style:"",l=this.__style;o!==l&&(""===l?r.removeAttribute("style"):r.style.cssText=l),function(t,e,n){const r=getStyleObjectFromCSS(e.__textStyle);for(const e in r)t.style.setProperty(`--listitem-marker-${e}`,r[e]);if(n)for(const e in getStyleObjectFromCSS(n.__textStyle))e in r||t.style.removeProperty(`--listitem-marker-${e}`);}(r,this,t);}updateDOM(t,e,n){const r=e;return this.updateListItemDOM(t,r,n),!1}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config),n=this.getFormatType();n&&(e.style.textAlign=n);const r=this.getDirection();return r&&(e.dir=r),{element:e}}exportJSON(){return {...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const n=t[e];if($isElementNode(n)&&this.canMergeWith(n)){const t=n.getChildren();this.append(...t),n.remove();}else super.append(n);}return this}replace(t,e){if(nt(t))return super.replace(t);this.setIndent(0);const n=this.getParentOrThrow();if(!at(n))return t;if(n.__first===this.getKey())n.insertBefore(t);else if(n.__last===this.getKey())n.insertAfter(t);else {const e=ct(n.getListType());let r=this.getNextSibling();for(;r;){const t=r;r=r.getNextSibling(),e.append(t);}n.insertAfter(t),t.insertAfter(e);}return e&&($isElementNode(t)||I(139),this.getChildren().forEach((e=>{t.append(e);}))),this.remove(),0===n.getChildrenSize()&&n.remove(),t}insertAfter(t,e=!0){const n=this.getParentOrThrow();if(at(n)||I(39),nt(t))return super.insertAfter(t,e);const r=this.getNextSiblings();if(n.insertAfter(t,e),0!==r.length){const i=ct(n.getListType());r.forEach((t=>i.append(t))),t.insertAfter(i,e);}return t}remove(t){const e=this.getPreviousSibling(),n=this.getNextSibling();super.remove(t),e&&n&&K(e)&&K(n)&&(z(e.getFirstChild(),n.getFirstChild()),n.remove());}insertNewAfter(t,e=!0){const n=et().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(n,e),n}collapseAtStart(t){const e=$createParagraphNode();this.getChildren().forEach((t=>e.append(t)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=nt(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else {n.insertBefore(e),n.remove();const r=t.anchor,i=t.focus,s=e.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element");}else n.insertBefore(e),this.remove();return !0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const n=this.getParent();return at(n)&&(e=n.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),n=0;for(;nt(e);)e=e.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(t){"number"!=typeof t&&I(117),(t=Math.floor(t))>=0||I(199);let e=this.getIndent();for(;e!==t;)e<t?(X(this),e++):(j(this),e--);return this}canInsertAfter(t){return nt(t)}canReplaceWith(t){return nt(t)}canMergeWith(t){return nt(t)||$isParagraphNode(t)}extractWithChild(t,e){if(!$isRangeSelection(e))return !1;const n=e.anchor.getNode(),r=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return !0}createParentElementNode(){return ct("bullet")}canMergeWhenEmpty(){return !0}}function Z(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return tt(e);const e=t.getAttribute("aria-checked");return {node:et("true"===e||"false"!==e&&void 0)}}function tt(t){if(!("checkbox"===t.getAttribute("type")))return {node:null};return {node:et(t.hasAttribute("checked"))}}function et(t){return $applyNodeReplacement(new Y(void 0,t))}function nt(t){return t instanceof Y}class rt extends ElementNode{$config(){return this.config("list",{$transform:t=>{!function(t){const e=t.getNextSibling();at(e)&&t.getListType()===e.getListType()&&z(t,e);}(t),H(t);},extends:ElementNode,importDOM:buildImportMap({ol:()=>({conversion:ot,priority:0}),ul:()=>({conversion:ot,priority:0})})})}constructor(t="number",e=1,n){super(n);const r=lt[t]||t;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=e;}afterCloneFrom(t){super.afterCloneFrom(t),this.__listType=t.__listType,this.__tag=t.__tag,this.__start=t.__start;}getTag(){return this.getLatest().__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,it(r,t.theme,this),r}updateDOM(t,e,n){return t.__tag!==this.__tag||(it(e,n.theme,this),!1)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return isHTMLElement(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return {...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return !1}canIndent(){return !1}splice(t,e,n){let r=n;for(let t=0;t<n.length;t++){const e=n[t];nt(e)||(r===n&&(r=[...n]),r[t]=et().append(!$isElementNode(e)||at(e)||e.isInline()?e:$createTextNode(e.getTextContent())));}return super.splice(t,e,r)}extractWithChild(t){return nt(t)}}function it(t,r,i){const s=[],o=[],l=r.list;if(void 0!==l){const t=l[`${i.__tag}Depth`]||[],e=M(i)-1,n=e%t.length,r=t[n],c=l[i.__tag];let a;const g=l.nested,u=l.checklist;if(void 0!==g&&g.list&&(a=g.list),void 0!==c&&s.push(c),void 0!==u&&"check"===i.__listType&&s.push(u),void 0!==r){s.push(...Q(r));for(let e=0;e<t.length;e++)e!==n&&o.push(i.__tag+e);}if(void 0!==a){const t=Q(a);e>1?s.push(...t):o.push(...t);}}o.length>0&&removeClassNamesFromElement(t,...o),s.length>0&&addClassNamesToElement(t,...s);}function st(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(nt(r)){e.push(r);const t=r.getChildren();t.length>1&&t.forEach((t=>{at(t)&&e.push(W(t));}));}else e.push(W(r));}return e}function ot(t){const e=t.nodeName.toLowerCase();let n=null;if("ol"===e){n=ct("number",t.start);}else "ul"===e&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return !0;for(const e of t.childNodes)if(isHTMLElement(e)&&e.hasAttribute("aria-checked"))return !0;return !1}(t)?ct("check"):ct("bullet"));return {after:st,node:n}}const lt={ol:"number",ul:"bullet"};function ct(t="number",e=1){return $applyNodeReplacement(new rt(t,e))}function at(t){return t instanceof rt}const gt=createCommand("INSERT_CHECK_LIST_COMMAND");function ut(t){return mergeRegister(t.registerCommand(gt,(()=>($("check"),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_DOWN_COMMAND,(e=>mt(e,t,!1)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_UP_COMMAND,(e=>mt(e,t,!0)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ESCAPE_COMMAND,(()=>{if(null!=pt()){const e=t.getRootElement();return null!=e&&e.focus(),!0}return !1}),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_SPACE_COMMAND,(e=>{const n=pt();return !(null==n||!t.isEditable())&&(t.update((()=>{const t=$getNearestNodeFromDOMNode(n);nt(t)&&(e.preventDefault(),t.toggleChecked());})),!0)}),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_LEFT_COMMAND,(e=>t.getEditorState().read((()=>{const n=$getSelection();if($isRangeSelection(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),o=$findMatchingParent(n,(t=>$isElementNode(t)&&!t.isInline()));if(nt(o)){const r=o.getParent();if(at(r)&&"check"===r.getListType()&&(i||o.getFirstDescendant()===n)){const n=t.getElementByKey(o.__key);if(null!=n&&document.activeElement!==n)return n.focus(),e.preventDefault(),!0}}}}return !1}))),COMMAND_PRIORITY_LOW),t.registerRootListener(((t,e)=>{null!==t&&(t.addEventListener("click",ft),t.addEventListener("pointerdown",dt)),null!==e&&(e.removeEventListener("click",ft),e.removeEventListener("pointerdown",dt));})))}function ht(t,e){const n=t.target;if(!isHTMLElement(n))return;const i=n.firstChild;if(isHTMLElement(i)&&("UL"===i.tagName||"OL"===i.tagName))return;const s=n.parentNode;if(!s||"check"!==s.__lexicalListType)return;const l=n.getBoundingClientRect(),c=calculateZoomLevel(n),a=t.clientX/c,g=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},u=parseFloat(g.width),h="touch"===t.pointerType?32:0;("rtl"===n.dir?a<l.right+h&&a>l.right-u-h:a>l.left-h&&a<l.left+u+h)&&e();}function ft(t){ht(t,(()=>{if(isHTMLElement(t.target)){const e=t.target,n=getNearestEditorFromDOMNode(e);null!=n&&n.isEditable()&&n.update((()=>{const t=$getNearestNodeFromDOMNode(e);nt(t)&&(e.focus(),t.toggleChecked());}));}}));}function dt(t){ht(t,(()=>{t.preventDefault();}));}function pt(){const t=document.activeElement;return isHTMLElement(t)&&"LI"===t.tagName&&null!=t.parentNode&&"check"===t.parentNode.__lexicalListType?t:null}function mt(t,e,n){const r=pt();return null!=r&&e.update((()=>{const i=$getNearestNodeFromDOMNode(r);if(!nt(i))return;const s=function(t,e){let n=e?t.getPreviousSibling():t.getNextSibling(),r=t;for(;null==n&&nt(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=e?r.getPreviousSibling():r.getNextSibling());for(;nt(n);){const t=e?n.getLastChild():n.getFirstChild();if(!at(t))return n;n=e?t.getLastChild():t.getFirstChild();}return null}(i,n);if(null!=s){s.selectStart();const n=e.getElementByKey(s.__key);null!=n&&(t.preventDefault(),setTimeout((()=>{n.focus();}),0));}})),!1}const _t=createCommand("UPDATE_LIST_START_COMMAND"),yt=createCommand("INSERT_UNORDERED_LIST_COMMAND"),Ct=createCommand("INSERT_ORDERED_LIST_COMMAND"),Tt=createCommand("REMOVE_LIST_COMMAND");function St(t){return mergeRegister(t.registerCommand(Ct,(()=>($("number"),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(_t,(t=>{const{listNodeKey:e,newStart:n}=t,r=$getNodeByKey(e);return !!at(r)&&("number"===r.getListType()&&(r.setStart(n),H(r)),!0)}),COMMAND_PRIORITY_LOW),t.registerCommand(yt,(()=>($("bullet"),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(Tt,(()=>(q(),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>G()),COMMAND_PRIORITY_LOW),t.registerNodeTransform(Y,(t=>{const e=t.getFirstChild();if(e){if($isTextNode(e)){const n=e.getStyle(),r=e.getFormat();t.getTextStyle()!==n&&t.setTextStyle(n),t.getTextFormat()!==r&&t.setTextFormat(r);}}else {const e=$getSelection();$isRangeSelection(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format);}})),t.registerNodeTransform(TextNode,(t=>{const e=t.getParent();if(nt(e)&&t.is(e.getFirstChild())){const n=t.getStyle(),r=t.getFormat();n===e.getTextStyle()&&r===e.getTextFormat()||e.setTextStyle(n).setTextFormat(r);}})))}function vt(t){const e=t=>{const e=t.getParent();if(at(t.getFirstChild())||!at(e))return;const n=$findMatchingParent(t,(t=>nt(t)&&at(t.getParent())&&nt(t.getPreviousSibling())));if(null===n&&t.getIndent()>0)t.setIndent(0);else if(nt(n)){const r=n.getPreviousSibling();if(nt(r)){const n=function(t){let e=t,n=e.getFirstChild();for(;at(n);){const t=n.getLastChild();if(!nt(t))break;e=t,n=e.getFirstChild();}return e}(r),i=n.getParent();if(at(i)){const n=M(i);n+1<M(e)&&t.setIndent(n);}}}};return t.registerNodeTransform(rt,(t=>{const n=[t];for(;n.length>0;){const t=n.shift();if(at(t))for(const r of t.getChildren())if(nt(r)){e(r);const t=r.getFirstChild();at(t)&&n.push(t);}}}))}function xt(t,e){t.update((()=>$(e)));}function kt(t){t.update((()=>q()));}
|
|
15
16
|
|
|
16
|
-
export {
|
|
17
|
+
export { et as $createListItemNode, ct as $createListNode, M as $getListDepth, G as $handleListInsertParagraph, $ as $insertList, nt as $isListItemNode, at as $isListNode, q as $removeList, gt as INSERT_CHECK_LIST_COMMAND, Ct as INSERT_ORDERED_LIST_COMMAND, yt as INSERT_UNORDERED_LIST_COMMAND, Y as ListItemNode, rt as ListNode, Tt as REMOVE_LIST_COMMAND, _t as UPDATE_LIST_START_COMMAND, xt as insertList, ut as registerCheckList, St as registerList, vt as registerListStrictIndentTransform, kt as removeList };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { $insertDataTransferForRichText, copyToClipboard } from '../clipboard/LexicalClipboard.js';
|
|
4
|
-
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '../selection/LexicalSelection.js';
|
|
4
|
+
import { $isParentRTL, $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '../selection/LexicalSelection.js';
|
|
5
5
|
import { addClassNamesToElement, isHTMLElement, objectKlassEquals, mergeRegister, $findMatchingParent, $getNearestBlockElementAncestorOrThrow } from '../utils/LexicalUtils.js';
|
|
6
|
-
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection,
|
|
6
|
+
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, COMMAND_PRIORITY_EDITOR, DELETE_CHARACTER_COMMAND, $isRangeSelection, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, REMOVE_TEXT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, $isElementNode, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, $insertNodes, $createTabNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $getAdjacentNode, $isDecoratorNode, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, DROP_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection, DRAGSTART_COMMAND, DRAGOVER_COMMAND, SELECT_ALL_COMMAND, $selectAll, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND, isDOMNode, isSelectionCapturedInDecoratorInput, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, PASTE_TAG, $getRoot, $isRootNode } from 'lexical';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -122,7 +122,9 @@ class QuoteNode extends ElementNode {
|
|
|
122
122
|
element.append(document.createElement('br'));
|
|
123
123
|
}
|
|
124
124
|
const formatType = this.getFormatType();
|
|
125
|
-
|
|
125
|
+
if (formatType) {
|
|
126
|
+
element.style.textAlign = formatType;
|
|
127
|
+
}
|
|
126
128
|
const direction = this.getDirection();
|
|
127
129
|
if (direction) {
|
|
128
130
|
element.dir = direction;
|
|
@@ -265,7 +267,9 @@ class HeadingNode extends ElementNode {
|
|
|
265
267
|
element.append(document.createElement('br'));
|
|
266
268
|
}
|
|
267
269
|
const formatType = this.getFormatType();
|
|
268
|
-
|
|
270
|
+
if (formatType) {
|
|
271
|
+
element.style.textAlign = formatType;
|
|
272
|
+
}
|
|
269
273
|
const direction = this.getDirection();
|
|
270
274
|
if (direction) {
|
|
271
275
|
element.dir = direction;
|
|
@@ -360,7 +364,7 @@ function onPasteForRichText(event, editor) {
|
|
|
360
364
|
$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
361
365
|
}
|
|
362
366
|
}, {
|
|
363
|
-
tag:
|
|
367
|
+
tag: PASTE_TAG
|
|
364
368
|
});
|
|
365
369
|
}
|
|
366
370
|
async function onCutForRichText(event, editor) {
|
|
@@ -426,6 +430,23 @@ function $isSelectionAtEndOfRoot(selection) {
|
|
|
426
430
|
const focus = selection.focus;
|
|
427
431
|
return focus.key === 'root' && focus.offset === $getRoot().getChildrenSize();
|
|
428
432
|
}
|
|
433
|
+
function $isSelectionCollapsedAtFrontOfIndentedBlock(selection) {
|
|
434
|
+
if (!selection.isCollapsed()) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
const {
|
|
438
|
+
anchor
|
|
439
|
+
} = selection;
|
|
440
|
+
if (anchor.offset !== 0) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
const anchorNode = anchor.getNode();
|
|
444
|
+
if ($isRootNode(anchorNode)) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
const element = $getNearestBlockElementAncestorOrThrow(anchorNode);
|
|
448
|
+
return element.getIndent() > 0 && (element.is(anchorNode) || anchorNode.is(element.getFirstDescendant()));
|
|
449
|
+
}
|
|
429
450
|
|
|
430
451
|
/**
|
|
431
452
|
* Resets the capitalization of the selection to default.
|
|
@@ -447,13 +468,16 @@ function registerRichText(editor) {
|
|
|
447
468
|
return true;
|
|
448
469
|
}
|
|
449
470
|
return false;
|
|
450
|
-
},
|
|
471
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {
|
|
451
472
|
const selection = $getSelection();
|
|
452
|
-
if (
|
|
453
|
-
|
|
473
|
+
if ($isRangeSelection(selection)) {
|
|
474
|
+
selection.deleteCharacter(isBackward);
|
|
475
|
+
return true;
|
|
476
|
+
} else if ($isNodeSelection(selection)) {
|
|
477
|
+
selection.deleteNodes();
|
|
478
|
+
return true;
|
|
454
479
|
}
|
|
455
|
-
|
|
456
|
-
return true;
|
|
480
|
+
return false;
|
|
457
481
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_WORD_COMMAND, isBackward => {
|
|
458
482
|
const selection = $getSelection();
|
|
459
483
|
if (!$isRangeSelection(selection)) {
|
|
@@ -543,12 +567,12 @@ function registerRichText(editor) {
|
|
|
543
567
|
return $handleIndentAndOutdent(block => {
|
|
544
568
|
const indent = block.getIndent();
|
|
545
569
|
if (indent > 0) {
|
|
546
|
-
block.setIndent(indent - 1);
|
|
570
|
+
block.setIndent(Math.max(0, indent - 1));
|
|
547
571
|
}
|
|
548
572
|
});
|
|
549
573
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_UP_COMMAND, event => {
|
|
550
574
|
const selection = $getSelection();
|
|
551
|
-
if ($isNodeSelection(selection)
|
|
575
|
+
if ($isNodeSelection(selection)) {
|
|
552
576
|
// If selection is on a node, let's try and move selection
|
|
553
577
|
// back to being a range selection.
|
|
554
578
|
const nodes = selection.getNodes();
|
|
@@ -596,7 +620,11 @@ function registerRichText(editor) {
|
|
|
596
620
|
const nodes = selection.getNodes();
|
|
597
621
|
if (nodes.length > 0) {
|
|
598
622
|
event.preventDefault();
|
|
599
|
-
nodes[0]
|
|
623
|
+
if ($isParentRTL(nodes[0])) {
|
|
624
|
+
nodes[0].selectNext(0, 0);
|
|
625
|
+
} else {
|
|
626
|
+
nodes[0].selectPrevious();
|
|
627
|
+
}
|
|
600
628
|
return true;
|
|
601
629
|
}
|
|
602
630
|
}
|
|
@@ -612,13 +640,17 @@ function registerRichText(editor) {
|
|
|
612
640
|
return false;
|
|
613
641
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, event => {
|
|
614
642
|
const selection = $getSelection();
|
|
615
|
-
if ($isNodeSelection(selection)
|
|
643
|
+
if ($isNodeSelection(selection)) {
|
|
616
644
|
// If selection is on a node, let's try and move selection
|
|
617
645
|
// back to being a range selection.
|
|
618
646
|
const nodes = selection.getNodes();
|
|
619
647
|
if (nodes.length > 0) {
|
|
620
648
|
event.preventDefault();
|
|
621
|
-
nodes[0]
|
|
649
|
+
if ($isParentRTL(nodes[0])) {
|
|
650
|
+
nodes[0].selectPrevious();
|
|
651
|
+
} else {
|
|
652
|
+
nodes[0].selectNext(0, 0);
|
|
653
|
+
}
|
|
622
654
|
return true;
|
|
623
655
|
}
|
|
624
656
|
}
|
|
@@ -637,24 +669,17 @@ function registerRichText(editor) {
|
|
|
637
669
|
return false;
|
|
638
670
|
}
|
|
639
671
|
const selection = $getSelection();
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
}
|
|
643
|
-
const {
|
|
644
|
-
anchor
|
|
645
|
-
} = selection;
|
|
646
|
-
const anchorNode = anchor.getNode();
|
|
647
|
-
if (selection.isCollapsed() && anchor.offset === 0 && !$isRootNode(anchorNode)) {
|
|
648
|
-
const element = $getNearestBlockElementAncestorOrThrow(anchorNode);
|
|
649
|
-
if (element.getIndent() > 0) {
|
|
672
|
+
if ($isRangeSelection(selection)) {
|
|
673
|
+
if ($isSelectionCollapsedAtFrontOfIndentedBlock(selection)) {
|
|
650
674
|
event.preventDefault();
|
|
651
675
|
return editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
652
676
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
677
|
+
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
|
|
678
|
+
// more details - https://github.com/facebook/lexical/issues/5841
|
|
679
|
+
if (IS_IOS && navigator.language === 'ko-KR') {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
} else if (!$isNodeSelection(selection)) {
|
|
658
683
|
return false;
|
|
659
684
|
}
|
|
660
685
|
event.preventDefault();
|
|
@@ -664,7 +689,7 @@ function registerRichText(editor) {
|
|
|
664
689
|
return false;
|
|
665
690
|
}
|
|
666
691
|
const selection = $getSelection();
|
|
667
|
-
if (
|
|
692
|
+
if (!($isRangeSelection(selection) || $isNodeSelection(selection))) {
|
|
668
693
|
return false;
|
|
669
694
|
}
|
|
670
695
|
event.preventDefault();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { $insertDataTransferForRichText, copyToClipboard } from '../clipboard/LexicalClipboard.js';
|
|
4
|
-
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '../selection/LexicalSelection.js';
|
|
4
|
+
import { $isParentRTL, $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '../selection/LexicalSelection.js';
|
|
5
5
|
import { addClassNamesToElement, isHTMLElement, objectKlassEquals, mergeRegister, $findMatchingParent, $getNearestBlockElementAncestorOrThrow } from '../utils/LexicalUtils.js';
|
|
6
|
-
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection,
|
|
6
|
+
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, COMMAND_PRIORITY_EDITOR, DELETE_CHARACTER_COMMAND, $isRangeSelection, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, REMOVE_TEXT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, $isElementNode, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, $insertNodes, $createTabNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $getAdjacentNode, $isDecoratorNode, KEY_ARROW_DOWN_COMMAND, $getRoot, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, $isRootNode, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, DROP_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection, DRAGSTART_COMMAND, DRAGOVER_COMMAND, SELECT_ALL_COMMAND, $selectAll, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND, isDOMNode, isSelectionCapturedInDecoratorInput, PASTE_TAG, KEY_SPACE_COMMAND, KEY_TAB_COMMAND } from 'lexical';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -13,6 +13,6 @@ import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement
|
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
function lt(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const dt="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,mt=dt&&"documentMode"in document?document.documentMode:null,ft=!(!dt||!("InputEvent"in window)||mt)&&"getTargetRanges"in new window.InputEvent("input"),gt=dt&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),pt=dt&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,ht=dt&&/^(?=.*Chrome).*/i.test(navigator.userAgent),Ct=dt&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!ht,vt=createCommand("DRAG_DROP_PASTE_FILE");class yt extends ElementNode{static getType(){return "quote"}static clone(t){return new yt(t.__key)}createDOM(t){const e=document.createElement("blockquote");return addClassNamesToElement(e,t.theme.quote),e}updateDOM(t,e){return !1}static importDOM(){return {blockquote:t=>({conversion:Ot,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(isHTMLElement(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n);}return {element:e}}static importJSON(t){return Dt().updateFromJSON(t)}insertNewAfter(t,e){const n=$createParagraphNode(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=$createParagraphNode();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}canMergeWhenEmpty(){return !0}}function Dt(){return $applyNodeReplacement(new yt)}function xt(t){return t instanceof yt}class wt extends ElementNode{static getType(){return "heading"}static clone(t){return new wt(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t;}getTag(){return this.__tag}setTag(t){const e=this.getWritable();return this.__tag=t,e}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];addClassNamesToElement(n,t);}return n}updateDOM(t,e,n){return t.__tag!==this.__tag}static importDOM(){return {h1:t=>({conversion:Et,priority:0}),h2:t=>({conversion:Et,priority:0}),h3:t=>({conversion:Et,priority:0}),h4:t=>({conversion:Et,priority:0}),h5:t=>({conversion:Et,priority:0}),h6:t=>({conversion:Et,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&Nt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>Nt(t)?{conversion:t=>({node:Tt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(isHTMLElement(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n);}return {element:e}}static importJSON(t){return Tt(t.tag).updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTag(t.tag)}exportJSON(){return {...super.exportJSON(),tag:this.getTag()}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=this.getLastDescendant(),o=!r||t&&t.anchor.key===r.getKey()&&n===r.getTextContentSize()||!t?$createParagraphNode():Tt(this.getTag()),i=this.getDirection();if(o.setDirection(i),this.insertAfter(o,e),0===n&&!this.isEmpty()&&t){const t=$createParagraphNode();t.select(),this.replace(t,!0);}return o}collapseAtStart(){const t=this.isEmpty()?$createParagraphNode():Tt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return !0}}function Nt(t){return "span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Et(t){const e=t.nodeName.toLowerCase();let n=null;return "h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=Tt(e),null!==t.style&&(setNodeIndentFromDOM(t,n),n.setFormat(t.style.textAlign))),{node:n}}function Ot(t){const e=Dt();return null!==t.style&&(e.setFormat(t.style.textAlign),setNodeIndentFromDOM(t,e)),{node:e}}function Tt(t="h1"){return $applyNodeReplacement(new wt(t))}function _t(t){return t instanceof wt}function At(t){let e=null;if(objectKlassEquals(t,DragEvent)?e=t.dataTransfer:objectKlassEquals(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return [!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return [r,Array.from(e.files),o]}function St(t){const e=$getSelection();if(!$isRangeSelection(e))return !1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=$findMatchingParent(o,(t=>$isElementNode(t)&&!t.isInline()));if(null===s)continue;const a=s.getKey();s.canIndent()&&!n.has(a)&&(n.add(a),t(s));}return n.size>0}function Ft(t){const e=$getNearestNodeFromDOMNode(t);return $isDecoratorNode(e)}function It(t){for(const e of ["lowercase","uppercase","capitalize"])t.hasFormat(e)&&t.toggleFormat(e);}function Pt(o){return mergeRegister(o.registerCommand(CLICK_COMMAND,(t=>{const e=$getSelection();return !!$isNodeSelection(e)&&(e.clear(),!0)}),0),o.registerCommand(DELETE_CHARACTER_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.deleteCharacter(t),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DELETE_WORD_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.deleteWord(t),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DELETE_LINE_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.deleteLine(t),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND,(e=>{const n=$getSelection();if("string"==typeof e)null!==n&&n.insertText(e);else {if(null===n)return !1;const r=e.dataTransfer;if(null!=r)$insertDataTransferForRichText(r,n,o);else if($isRangeSelection(n)){const t=e.data;return t&&n.insertText(t),!0}}return !0}),COMMAND_PRIORITY_EDITOR),o.registerCommand(REMOVE_TEXT_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(t.removeText(),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(FORMAT_TEXT_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.formatText(t),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(FORMAT_ELEMENT_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e)&&!$isNodeSelection(e))return !1;const n=e.getNodes();for(const e of n){const n=$findMatchingParent(e,(t=>$isElementNode(t)&&!t.isInline()));null!==n&&n.setFormat(t);}return !0}),COMMAND_PRIORITY_EDITOR),o.registerCommand(INSERT_LINE_BREAK_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.insertLineBreak(t),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(t.insertParagraph(),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(INSERT_TAB_COMMAND,(()=>($insertNodes([$createTabNode()]),!0)),COMMAND_PRIORITY_EDITOR),o.registerCommand(INDENT_CONTENT_COMMAND,(()=>St((t=>{const e=t.getIndent();t.setIndent(e+1);}))),COMMAND_PRIORITY_EDITOR),o.registerCommand(OUTDENT_CONTENT_COMMAND,(()=>St((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1);}))),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ARROW_UP_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)&&!Ft(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if($isRangeSelection(e)){const n=$getAdjacentNode(e.focus,!0);if(!t.shiftKey&&$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return !1}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ARROW_DOWN_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if($isRangeSelection(e)){if(function(t){const e=t.focus;return "root"===e.key&&e.offset===$getRoot().getChildrenSize()}(e))return t.preventDefault(),!0;const n=$getAdjacentNode(e.focus,!1);if(!t.shiftKey&&$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return !1}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ARROW_LEFT_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!$isRangeSelection(e))return !1;if($shouldOverrideDefaultCharacterSelection(e,!0)){const n=t.shiftKey;return t.preventDefault(),$moveCharacter(e,n,!0),!0}return !1}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ARROW_RIGHT_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)&&!Ft(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!$isRangeSelection(e))return !1;const o=t.shiftKey;return !!$shouldOverrideDefaultCharacterSelection(e,!1)&&(t.preventDefault(),$moveCharacter(e,o,!1),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_BACKSPACE_COMMAND,(t=>{if(Ft(t.target))return !1;const e=$getSelection();if(!$isRangeSelection(e))return !1;const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!$isRootNode(r)){if($getNearestBlockElementAncestorOrThrow(r).getIndent()>0)return t.preventDefault(),o.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0)}return (!pt||"ko-KR"!==navigator.language)&&(t.preventDefault(),o.dispatchCommand(DELETE_CHARACTER_COMMAND,!0))}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_DELETE_COMMAND,(t=>{if(Ft(t.target))return !1;const e=$getSelection();return !!$isRangeSelection(e)&&(t.preventDefault(),o.dispatchCommand(DELETE_CHARACTER_COMMAND,!1))}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ENTER_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e))return !1;if(It(e),null!==t){if((pt||gt||Ct)&&ft)return !1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(INSERT_LINE_BREAK_COMMAND,!1)}return o.dispatchCommand(INSERT_PARAGRAPH_COMMAND,void 0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_ESCAPE_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(o.blur(),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DROP_COMMAND,(t=>{const[,e]=At(t);if(e.length>0){const n=lt(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,i=$getNearestNodeFromDOMNode(r);if(null!==i){const e=$createRangeSelection();if($isTextNode(i))e.anchor.set(i.getKey(),t,"text"),e.focus.set(i.getKey(),t,"text");else {const t=i.getParentOrThrow().getKey(),n=i.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element");}const n=$normalizeSelection__EXPERIMENTAL(e);$setSelection(n);}o.dispatchCommand(vt,e);}return t.preventDefault(),!0}const n=$getSelection();return !!$isRangeSelection(n)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DRAGSTART_COMMAND,(t=>{const[e]=At(t),n=$getSelection();return !(e&&!$isRangeSelection(n))}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DRAGOVER_COMMAND,(t=>{const[e]=At(t),n=$getSelection();if(e&&!$isRangeSelection(n))return !1;const r=lt(t.clientX,t.clientY);if(null!==r){const e=$getNearestNodeFromDOMNode(r.node);$isDecoratorNode(e)&&t.preventDefault();}return !0}),COMMAND_PRIORITY_EDITOR),o.registerCommand(SELECT_ALL_COMMAND,(()=>($selectAll(),!0)),COMMAND_PRIORITY_EDITOR),o.registerCommand(COPY_COMMAND,(t=>(copyToClipboard(o,objectKlassEquals(t,ClipboardEvent)?t:null),!0)),COMMAND_PRIORITY_EDITOR),o.registerCommand(CUT_COMMAND,(t=>(async function(t,n){await copyToClipboard(n,objectKlassEquals(t,ClipboardEvent)?t:null),n.update((()=>{const t=$getSelection();$isRangeSelection(t)?t.removeText():$isNodeSelection(t)&&t.getNodes().forEach((t=>t.remove()));}));}(t,o),!0)),COMMAND_PRIORITY_EDITOR),o.registerCommand(PASTE_COMMAND,(e=>{const[,n,r]=At(e);if(n.length>0&&!r)return o.dispatchCommand(vt,n),!0;if(isDOMNode(e.target)&&isSelectionCapturedInDecoratorInput(e.target))return !1;return null!==$getSelection()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=$getSelection(),o=objectKlassEquals(e,InputEvent)||objectKlassEquals(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&$insertDataTransferForRichText(o,r,n);}),{tag:"paste"});}(e,o),!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_SPACE_COMMAND,(t=>{const e=$getSelection();return $isRangeSelection(e)&&It(e),!1}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_TAB_COMMAND,(t=>{const e=$getSelection();return $isRangeSelection(e)&&It(e),!1}),COMMAND_PRIORITY_EDITOR))}
|
|
16
|
+
function mt(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const ft="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,gt=ft&&"documentMode"in document?document.documentMode:null,pt=!(!ft||!("InputEvent"in window)||gt)&&"getTargetRanges"in new window.InputEvent("input"),ht=ft&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),Ct=ft&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,vt=ft&&/^(?=.*Chrome).*/i.test(navigator.userAgent),yt=ft&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!vt,Dt=createCommand("DRAG_DROP_PASTE_FILE");class xt extends ElementNode{static getType(){return "quote"}static clone(t){return new xt(t.__key)}createDOM(t){const e=document.createElement("blockquote");return addClassNamesToElement(e,t.theme.quote),e}updateDOM(t,e){return !1}static importDOM(){return {blockquote:t=>({conversion:_t,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(isHTMLElement(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();t&&(e.style.textAlign=t);const n=this.getDirection();n&&(e.dir=n);}return {element:e}}static importJSON(t){return Nt().updateFromJSON(t)}insertNewAfter(t,e){const n=$createParagraphNode(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=$createParagraphNode();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}canMergeWhenEmpty(){return !0}}function Nt(){return $applyNodeReplacement(new xt)}function wt(t){return t instanceof xt}class Et extends ElementNode{static getType(){return "heading"}static clone(t){return new Et(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t;}getTag(){return this.__tag}setTag(t){const e=this.getWritable();return this.__tag=t,e}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];addClassNamesToElement(n,t);}return n}updateDOM(t,e,n){return t.__tag!==this.__tag}static importDOM(){return {h1:t=>({conversion:Tt,priority:0}),h2:t=>({conversion:Tt,priority:0}),h3:t=>({conversion:Tt,priority:0}),h4:t=>({conversion:Tt,priority:0}),h5:t=>({conversion:Tt,priority:0}),h6:t=>({conversion:Tt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&Ot(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>Ot(t)?{conversion:t=>({node:At("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(isHTMLElement(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();t&&(e.style.textAlign=t);const n=this.getDirection();n&&(e.dir=n);}return {element:e}}static importJSON(t){return At(t.tag).updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTag(t.tag)}exportJSON(){return {...super.exportJSON(),tag:this.getTag()}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=this.getLastDescendant(),o=!r||t&&t.anchor.key===r.getKey()&&n===r.getTextContentSize()||!t?$createParagraphNode():At(this.getTag()),i=this.getDirection();if(o.setDirection(i),this.insertAfter(o,e),0===n&&!this.isEmpty()&&t){const t=$createParagraphNode();t.select(),this.replace(t,!0);}return o}collapseAtStart(){const t=this.isEmpty()?$createParagraphNode():At(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return !0}}function Ot(t){return "span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Tt(t){const e=t.nodeName.toLowerCase();let n=null;return "h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=At(e),null!==t.style&&(setNodeIndentFromDOM(t,n),n.setFormat(t.style.textAlign))),{node:n}}function _t(t){const e=Nt();return null!==t.style&&(e.setFormat(t.style.textAlign),setNodeIndentFromDOM(t,e)),{node:e}}function At(t="h1"){return $applyNodeReplacement(new Et(t))}function Ft(t){return t instanceof Et}function Pt(t){let e=null;if(objectKlassEquals(t,DragEvent)?e=t.dataTransfer:objectKlassEquals(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return [!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return [r,Array.from(e.files),o]}function St(t){const e=$getSelection();if(!$isRangeSelection(e))return !1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=$findMatchingParent(o,(t=>$isElementNode(t)&&!t.isInline()));if(null===s)continue;const a=s.getKey();s.canIndent()&&!n.has(a)&&(n.add(a),t(s));}return n.size>0}function It(t){const e=$getNearestNodeFromDOMNode(t);return $isDecoratorNode(e)}function Mt(t){for(const e of ["lowercase","uppercase","capitalize"])t.hasFormat(e)&&t.toggleFormat(e);}function bt(i){return mergeRegister(i.registerCommand(CLICK_COMMAND,(t=>{const e=$getSelection();return !!$isNodeSelection(e)&&(e.clear(),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DELETE_CHARACTER_COMMAND,(t=>{const e=$getSelection();return $isRangeSelection(e)?(e.deleteCharacter(t),!0):!!$isNodeSelection(e)&&(e.deleteNodes(),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DELETE_WORD_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.deleteWord(t),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DELETE_LINE_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.deleteLine(t),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND,(e=>{const n=$getSelection();if("string"==typeof e)null!==n&&n.insertText(e);else {if(null===n)return !1;const r=e.dataTransfer;if(null!=r)$insertDataTransferForRichText(r,n,i);else if($isRangeSelection(n)){const t=e.data;return t&&n.insertText(t),!0}}return !0}),COMMAND_PRIORITY_EDITOR),i.registerCommand(REMOVE_TEXT_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(t.removeText(),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(FORMAT_TEXT_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.formatText(t),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(FORMAT_ELEMENT_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e)&&!$isNodeSelection(e))return !1;const n=e.getNodes();for(const e of n){const n=$findMatchingParent(e,(t=>$isElementNode(t)&&!t.isInline()));null!==n&&n.setFormat(t);}return !0}),COMMAND_PRIORITY_EDITOR),i.registerCommand(INSERT_LINE_BREAK_COMMAND,(t=>{const e=$getSelection();return !!$isRangeSelection(e)&&(e.insertLineBreak(t),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(t.insertParagraph(),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(INSERT_TAB_COMMAND,(()=>($insertNodes([$createTabNode()]),!0)),COMMAND_PRIORITY_EDITOR),i.registerCommand(INDENT_CONTENT_COMMAND,(()=>St((t=>{const e=t.getIndent();t.setIndent(e+1);}))),COMMAND_PRIORITY_EDITOR),i.registerCommand(OUTDENT_CONTENT_COMMAND,(()=>St((t=>{const e=t.getIndent();e>0&&t.setIndent(Math.max(0,e-1));}))),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ARROW_UP_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if($isRangeSelection(e)){const n=$getAdjacentNode(e.focus,!0);if(!t.shiftKey&&$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return !1}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ARROW_DOWN_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if($isRangeSelection(e)){if(function(t){const e=t.focus;return "root"===e.key&&e.offset===$getRoot().getChildrenSize()}(e))return t.preventDefault(),!0;const n=$getAdjacentNode(e.focus,!1);if(!t.shiftKey&&$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return !1}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ARROW_LEFT_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const r=e.getNodes();if(r.length>0)return t.preventDefault(),$isParentRTL(r[0])?r[0].selectNext(0,0):r[0].selectPrevious(),!0}if(!$isRangeSelection(e))return !1;if($shouldOverrideDefaultCharacterSelection(e,!0)){const n=t.shiftKey;return t.preventDefault(),$moveCharacter(e,n,!0),!0}return !1}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ARROW_RIGHT_COMMAND,(t=>{const e=$getSelection();if($isNodeSelection(e)){const r=e.getNodes();if(r.length>0)return t.preventDefault(),$isParentRTL(r[0])?r[0].selectPrevious():r[0].selectNext(0,0),!0}if(!$isRangeSelection(e))return !1;const i=t.shiftKey;return !!$shouldOverrideDefaultCharacterSelection(e,!1)&&(t.preventDefault(),$moveCharacter(e,i,!1),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_BACKSPACE_COMMAND,(t=>{if(It(t.target))return !1;const e=$getSelection();if($isRangeSelection(e)){if(function(t){if(!t.isCollapsed())return !1;const{anchor:e}=t;if(0!==e.offset)return !1;const n=e.getNode();if($isRootNode(n))return !1;const r=$getNearestBlockElementAncestorOrThrow(n);return r.getIndent()>0&&(r.is(n)||n.is(r.getFirstDescendant()))}(e))return t.preventDefault(),i.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0);if(Ct&&"ko-KR"===navigator.language)return !1}else if(!$isNodeSelection(e))return !1;return t.preventDefault(),i.dispatchCommand(DELETE_CHARACTER_COMMAND,!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_DELETE_COMMAND,(t=>{if(It(t.target))return !1;const e=$getSelection();return !(!$isRangeSelection(e)&&!$isNodeSelection(e))&&(t.preventDefault(),i.dispatchCommand(DELETE_CHARACTER_COMMAND,!1))}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ENTER_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e))return !1;if(Mt(e),null!==t){if((Ct||ht||yt)&&pt)return !1;if(t.preventDefault(),t.shiftKey)return i.dispatchCommand(INSERT_LINE_BREAK_COMMAND,!1)}return i.dispatchCommand(INSERT_PARAGRAPH_COMMAND,void 0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_ESCAPE_COMMAND,(()=>{const t=$getSelection();return !!$isRangeSelection(t)&&(i.blur(),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DROP_COMMAND,(t=>{const[,e]=Pt(t);if(e.length>0){const n=mt(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,o=$getNearestNodeFromDOMNode(r);if(null!==o){const e=$createRangeSelection();if($isTextNode(o))e.anchor.set(o.getKey(),t,"text"),e.focus.set(o.getKey(),t,"text");else {const t=o.getParentOrThrow().getKey(),n=o.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element");}const n=$normalizeSelection__EXPERIMENTAL(e);$setSelection(n);}i.dispatchCommand(Dt,e);}return t.preventDefault(),!0}const n=$getSelection();return !!$isRangeSelection(n)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DRAGSTART_COMMAND,(t=>{const[e]=Pt(t),n=$getSelection();return !(e&&!$isRangeSelection(n))}),COMMAND_PRIORITY_EDITOR),i.registerCommand(DRAGOVER_COMMAND,(t=>{const[e]=Pt(t),n=$getSelection();if(e&&!$isRangeSelection(n))return !1;const r=mt(t.clientX,t.clientY);if(null!==r){const e=$getNearestNodeFromDOMNode(r.node);$isDecoratorNode(e)&&t.preventDefault();}return !0}),COMMAND_PRIORITY_EDITOR),i.registerCommand(SELECT_ALL_COMMAND,(()=>($selectAll(),!0)),COMMAND_PRIORITY_EDITOR),i.registerCommand(COPY_COMMAND,(t=>(copyToClipboard(i,objectKlassEquals(t,ClipboardEvent)?t:null),!0)),COMMAND_PRIORITY_EDITOR),i.registerCommand(CUT_COMMAND,(t=>(async function(t,n){await copyToClipboard(n,objectKlassEquals(t,ClipboardEvent)?t:null),n.update((()=>{const t=$getSelection();$isRangeSelection(t)?t.removeText():$isNodeSelection(t)&&t.getNodes().forEach((t=>t.remove()));}));}(t,i),!0)),COMMAND_PRIORITY_EDITOR),i.registerCommand(PASTE_COMMAND,(e=>{const[,n,r]=Pt(e);if(n.length>0&&!r)return i.dispatchCommand(Dt,n),!0;if(isDOMNode(e.target)&&isSelectionCapturedInDecoratorInput(e.target))return !1;return null!==$getSelection()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=$getSelection(),o=objectKlassEquals(e,InputEvent)||objectKlassEquals(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&$insertDataTransferForRichText(o,r,n);}),{tag:PASTE_TAG});}(e,i),!0)}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_SPACE_COMMAND,(t=>{const e=$getSelection();return $isRangeSelection(e)&&Mt(e),!1}),COMMAND_PRIORITY_EDITOR),i.registerCommand(KEY_TAB_COMMAND,(t=>{const e=$getSelection();return $isRangeSelection(e)&&Mt(e),!1}),COMMAND_PRIORITY_EDITOR))}
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { At as $createHeadingNode, Nt as $createQuoteNode, Ft as $isHeadingNode, wt as $isQuoteNode, Dt as DRAG_DROP_PASTE, Et as HeadingNode, xt as QuoteNode, Pt as eventFiles, bt as registerRichText };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { $isTextNode, $
|
|
3
|
+
import { $isTextNode, $getEditor, $isRootNode, $isTokenOrSegmented, $getCharacterOffsets, $isElementNode, $getNodeByKey, $getPreviousSelection, $createTextNode, $isRangeSelection, $getSelection, $caretRangeFromSelection, $createRangeSelection, INTERNAL_$isBlock, $setSelection, $isRootOrShadowRoot, $hasAncestor, $isLeafNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isChildCaret, $isDecoratorNode } from 'lexical';
|
|
4
4
|
export { $cloneWithProperties, $selectAll } from 'lexical';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -209,6 +209,44 @@ function getCSSFromStyleObject(styles) {
|
|
|
209
209
|
return css;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Gets the computed DOM styles of the element.
|
|
214
|
+
* @param node - The node to check the styles for.
|
|
215
|
+
* @returns the computed styles of the element or null if there is no DOM element or no default view for the document.
|
|
216
|
+
*/
|
|
217
|
+
function $getComputedStyleForElement(element) {
|
|
218
|
+
const editor = $getEditor();
|
|
219
|
+
const domElement = editor.getElementByKey(element.getKey());
|
|
220
|
+
if (domElement === null) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const view = domElement.ownerDocument.defaultView;
|
|
224
|
+
if (view === null) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return view.getComputedStyle(domElement);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Gets the computed DOM styles of the parent of the node.
|
|
232
|
+
* @param node - The node to check its parent's styles for.
|
|
233
|
+
* @returns the computed styles of the node or null if there is no DOM element or no default view for the document.
|
|
234
|
+
*/
|
|
235
|
+
function $getComputedStyleForParent(node) {
|
|
236
|
+
const parent = $isRootNode(node) ? node : node.getParentOrThrow();
|
|
237
|
+
return $getComputedStyleForElement(parent);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Determines whether a node's parent is RTL.
|
|
242
|
+
* @param node - The node to check whether it is RTL.
|
|
243
|
+
* @returns whether the node is RTL.
|
|
244
|
+
*/
|
|
245
|
+
function $isParentRTL(node) {
|
|
246
|
+
const styles = $getComputedStyleForParent(node);
|
|
247
|
+
return styles !== null && styles.direction === 'rtl';
|
|
248
|
+
}
|
|
249
|
+
|
|
212
250
|
/**
|
|
213
251
|
* Generally used to append text content to HTML and JSON. Grabs the text content and "slices"
|
|
214
252
|
* it to be generated into the new TextNode.
|
|
@@ -218,7 +256,7 @@ function getCSSFromStyleObject(styles) {
|
|
|
218
256
|
*/
|
|
219
257
|
function $sliceSelectedTextNodeContent(selection, textNode) {
|
|
220
258
|
const anchorAndFocus = selection.getStartEndPoints();
|
|
221
|
-
if (textNode.isSelected(selection) &&
|
|
259
|
+
if (textNode.isSelected(selection) && !$isTokenOrSegmented(textNode) && anchorAndFocus !== null) {
|
|
222
260
|
const [anchor, focus] = anchorAndFocus;
|
|
223
261
|
const isBackward = selection.isBackward();
|
|
224
262
|
const anchorNode = anchor.getNode();
|
|
@@ -244,8 +282,11 @@ function $sliceSelectedTextNodeContent(selection, textNode) {
|
|
|
244
282
|
startOffset = 0;
|
|
245
283
|
endOffset = offset;
|
|
246
284
|
}
|
|
285
|
+
|
|
286
|
+
// NOTE: This mutates __text directly because the primary use case is to
|
|
287
|
+
// modify a $cloneWithProperties node that should never be added
|
|
288
|
+
// to the EditorState so we must not call getWritable via setTextContent
|
|
247
289
|
textNode.__text = textNode.__text.slice(startOffset, endOffset);
|
|
248
|
-
return textNode;
|
|
249
290
|
}
|
|
250
291
|
}
|
|
251
292
|
return textNode;
|
|
@@ -554,6 +595,11 @@ function $setBlocksType(selection, $createElement, $afterCreateElement = $copyBl
|
|
|
554
595
|
for (const node of selection.getNodes()) {
|
|
555
596
|
if ($isElementNode(node) && INTERNAL_$isBlock(node)) {
|
|
556
597
|
blockMap.set(node.getKey(), node);
|
|
598
|
+
} else if (anchorAndFocus === null) {
|
|
599
|
+
const ancestorBlock = $getAncestor(node, INTERNAL_$isBlock);
|
|
600
|
+
if ($isElementNode(ancestorBlock)) {
|
|
601
|
+
blockMap.set(ancestorBlock.getKey(), ancestorBlock);
|
|
602
|
+
}
|
|
557
603
|
}
|
|
558
604
|
}
|
|
559
605
|
for (const [key, prevNode] of blockMap) {
|
|
@@ -589,7 +635,7 @@ function $removeParentEmptyElements(startingNode) {
|
|
|
589
635
|
}
|
|
590
636
|
|
|
591
637
|
/**
|
|
592
|
-
* @deprecated
|
|
638
|
+
* @deprecated In favor of $setBlockTypes
|
|
593
639
|
* Wraps all nodes in the selection into another node of the type returned by createElement.
|
|
594
640
|
* @param selection - The selection of nodes to be wrapped.
|
|
595
641
|
* @param createElement - A function that creates the wrapping ElementNode. eg. $createParagraphNode.
|
|
@@ -791,6 +837,29 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
|
|
|
791
837
|
}
|
|
792
838
|
}
|
|
793
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Tests if the selection's parent element has vertical writing mode.
|
|
842
|
+
* @param selection - The selection whose parent to test.
|
|
843
|
+
* @returns true if the selection's parent has vertical writing mode (writing-mode: vertical-rl), false otherwise.
|
|
844
|
+
*/
|
|
845
|
+
function $isEditorVerticalOrientation(selection) {
|
|
846
|
+
const computedStyle = $getComputedStyle(selection);
|
|
847
|
+
return computedStyle !== null && computedStyle.writingMode === 'vertical-rl';
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Gets the computed DOM styles of the parent of the selection's anchor node.
|
|
852
|
+
* @param selection - The selection to check the styles for.
|
|
853
|
+
* @returns the computed styles of the node or null if there is no DOM element or no default view for the document.
|
|
854
|
+
*/
|
|
855
|
+
function $getComputedStyle(selection) {
|
|
856
|
+
const anchorNode = selection.anchor.getNode();
|
|
857
|
+
if ($isElementNode(anchorNode)) {
|
|
858
|
+
return $getComputedStyleForElement(anchorNode);
|
|
859
|
+
}
|
|
860
|
+
return $getComputedStyleForParent(anchorNode);
|
|
861
|
+
}
|
|
862
|
+
|
|
794
863
|
/**
|
|
795
864
|
* Determines if the default character selection should be overridden. Used with DecoratorNodes
|
|
796
865
|
* @param selection - The selection whose default character selection may need to be overridden.
|
|
@@ -798,7 +867,16 @@ function $wrapNodesImpl(selection, nodes, nodesLength, createElement, wrappingEl
|
|
|
798
867
|
* @returns true if it should be overridden, false if not.
|
|
799
868
|
*/
|
|
800
869
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
801
|
-
const
|
|
870
|
+
const isVertical = $isEditorVerticalOrientation(selection);
|
|
871
|
+
|
|
872
|
+
// In vertical writing mode, we adjust the direction for correct caret movement
|
|
873
|
+
let adjustedIsBackward = isVertical ? !isBackward : isBackward;
|
|
874
|
+
|
|
875
|
+
// In right-to-left writing mode, we invert the direction for correct caret movement
|
|
876
|
+
if ($isParentElementRTL(selection)) {
|
|
877
|
+
adjustedIsBackward = !adjustedIsBackward;
|
|
878
|
+
}
|
|
879
|
+
const focusCaret = $caretFromPoint(selection.focus, adjustedIsBackward ? 'previous' : 'next');
|
|
802
880
|
if ($isExtendableTextPointCaret(focusCaret)) {
|
|
803
881
|
return false;
|
|
804
882
|
}
|
|
@@ -832,9 +910,8 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
|
|
|
832
910
|
* @returns true if the selections' parent element has a direction of 'rtl' (right to left), false otherwise.
|
|
833
911
|
*/
|
|
834
912
|
function $isParentElementRTL(selection) {
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
return parent.getDirection() === 'rtl';
|
|
913
|
+
const computedStyle = $getComputedStyle(selection);
|
|
914
|
+
return computedStyle !== null && computedStyle.direction === 'rtl';
|
|
838
915
|
}
|
|
839
916
|
|
|
840
917
|
/**
|
|
@@ -845,7 +922,26 @@ function $isParentElementRTL(selection) {
|
|
|
845
922
|
*/
|
|
846
923
|
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
847
924
|
const isRTL = $isParentElementRTL(selection);
|
|
848
|
-
$
|
|
925
|
+
const isVertical = $isEditorVerticalOrientation(selection);
|
|
926
|
+
|
|
927
|
+
// In vertical-rl writing mode, arrow key directions need to be flipped
|
|
928
|
+
// to match the visual flow of text (top to bottom, right to left)
|
|
929
|
+
let adjustedIsBackward;
|
|
930
|
+
if (isVertical) {
|
|
931
|
+
// In vertical-rl mode, we need to completely invert the direction
|
|
932
|
+
// Left arrow (backward) should move down (forward)
|
|
933
|
+
// Right arrow (forward) should move up (backward)
|
|
934
|
+
adjustedIsBackward = !isBackward;
|
|
935
|
+
} else if (isRTL) {
|
|
936
|
+
// In horizontal RTL mode, use the standard RTL behavior
|
|
937
|
+
adjustedIsBackward = !isBackward;
|
|
938
|
+
} else {
|
|
939
|
+
// Standard LTR horizontal text
|
|
940
|
+
adjustedIsBackward = isBackward;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// Apply the direction adjustment to move the caret
|
|
944
|
+
$moveCaretSelection(selection, isHoldingShift, adjustedIsBackward, 'character');
|
|
849
945
|
}
|
|
850
946
|
|
|
851
947
|
/**
|
|
@@ -929,4 +1025,4 @@ function $getAncestor(node, predicate) {
|
|
|
929
1025
|
/** @deprecated renamed to {@link $trimTextContentFromAnchor} by @lexical/eslint-plugin rules-of-lexical */
|
|
930
1026
|
const trimTextContentFromAnchor = $trimTextContentFromAnchor;
|
|
931
1027
|
|
|
932
|
-
export { $addNodeStyle, $copyBlockFormatIndent, $ensureForwardRangeSelection, $forEachSelectedTextNode, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
|
1028
|
+
export { $addNodeStyle, $copyBlockFormatIndent, $ensureForwardRangeSelection, $forEachSelectedTextNode, $getComputedStyleForElement, $getComputedStyleForParent, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $isParentRTL, $moveCaretSelection, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, $trimTextContentFromAnchor, $wrapNodes, createDOMRange, createRectsFromDOMRange, getCSSFromStyleObject, getStyleObjectFromCSS, trimTextContentFromAnchor };
|
|
@@ -16,11 +16,13 @@ const $addNodeStyle = mod.$addNodeStyle;
|
|
|
16
16
|
const $getSelectionStyleValueForProperty = mod.$getSelectionStyleValueForProperty;
|
|
17
17
|
const $isAtNodeEnd = mod.$isAtNodeEnd;
|
|
18
18
|
const $isParentElementRTL = mod.$isParentElementRTL;
|
|
19
|
+
const $isParentRTL = mod.$isParentRTL;
|
|
19
20
|
const $moveCharacter = mod.$moveCharacter;
|
|
20
21
|
const $patchStyleText = mod.$patchStyleText;
|
|
21
22
|
const $setBlocksType = mod.$setBlocksType;
|
|
22
23
|
const $shouldOverrideDefaultCharacterSelection = mod.$shouldOverrideDefaultCharacterSelection;
|
|
23
24
|
const $sliceSelectedTextNodeContent = mod.$sliceSelectedTextNodeContent;
|
|
24
25
|
const createRectsFromDOMRange = mod.createRectsFromDOMRange;
|
|
26
|
+
const getStyleObjectFromCSS = mod.getStyleObjectFromCSS;
|
|
25
27
|
|
|
26
|
-
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, createRectsFromDOMRange };
|
|
28
|
+
export { $addNodeStyle, $getSelectionStyleValueForProperty, $isAtNodeEnd, $isParentElementRTL, $isParentRTL, $moveCharacter, $patchStyleText, $setBlocksType, $shouldOverrideDefaultCharacterSelection, $sliceSelectedTextNodeContent, createRectsFromDOMRange, getStyleObjectFromCSS };
|