@react-fabric/lexical 1.0.0-beta.47 → 1.0.0-beta.49
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/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
- package/dist/cjs/node_modules/prismjs/prism.js +1 -1
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/node_modules/prismjs/prism.js +1 -1
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/package.json +7 -8
- package/src/components/StickyComponent.tsx +1 -1
- package/src/editor/LexicalEditor.tsx +25 -21
- package/src/plugins/ToolbarPlugin.tsx +20 -4
|
@@ -11,7 +11,7 @@ import * as LexicalList_prod from './LexicalList.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalList_dev : LexicalList_prod;
|
|
15
15
|
const $isListNode = mod.$isListNode;
|
|
16
16
|
const INSERT_CHECK_LIST_COMMAND = mod.INSERT_CHECK_LIST_COMMAND;
|
|
17
17
|
const INSERT_ORDERED_LIST_COMMAND = mod.INSERT_ORDERED_LIST_COMMAND;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { $
|
|
4
|
-
import { $
|
|
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';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -11,6 +11,6 @@ import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElem
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=p((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function m(e){let t=1,n=e.getParent();for(;null!=n;){if(B(n)){const e=n.getParent();if($(e)){t++,n=e.getParent();continue}_(40);}return t}return t}function v(e){let t=e.getParent();$(t)||_(40);let n=t;for(;null!==n;)n=n.getParent(),$(n)&&(t=n);return t}function y(e){let t=[];const n=e.getChildren().filter(B);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();$(i)?t=t.concat(y(i)):t.push(r);}return t}function C(e){return B(e)&&$(e.getFirstChild())}function k(e){return R().append(e)}function T(e,t){return B(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function b(s,o){s.update((()=>{const s=$getSelection();if(null!==s){const e=s.getNodes();if($isRangeSelection(s)){const t=s.getStartEndPoints();null===t&&_(143);const[i]=t,c=i.getNode(),l=c.getParent();if(T(c,e)){const e=U(o);if($isRootOrShadowRoot(l)){c.replace(e);const t=R();$isElementNode(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t);}else if(B(c)){const t=c.getParentOrThrow();S(e,t.getChildren()),t.replace(e);}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!$isElementNode(s)||!s.isEmpty()||B(s)||c.has(s.getKey())){if($isLeafNode(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if($(e)){if(!c.has(t)){const n=U(o);S(n,e.getChildren()),e.replace(n),c.add(t);}break}{const r=e.getParent();if($isRootOrShadowRoot(r)&&!c.has(t)){c.add(t),P(e,o);break}e=r;}}}}else P(s,o);}}}));}function S(e,t){e.splice(e.getChildrenSize(),0,t);}function P(e,t){if($(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=R();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),S(i,e.getChildren()),$(n)&&t===n.getListType())return n.append(i),e.remove(),$(r)&&t===r.getListType()&&(S(n,r.getChildren()),r.remove()),n;if($(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=U(t);return n.append(i),e.replace(n),n}}function A(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&C(n)&&C(r)&&(A(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove();}function N(n){n.update((()=>{const n=$getSelection();if($isRangeSelection(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(T(r,t))e.add(v(r));else for(let n=0;n<t.length;n++){const r=t[n];if($isLeafNode(r)){const t=$getNearestNodeOfType(r,M);null!=t&&e.add(v(t));}}for(const t of e){let e=t;const r=y(t);for(const t of r){const r=$createParagraphNode();S(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove();}t.remove();}}}));}function x(e){const t=new Set;if(C(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(C(r)&&C(i)){const n=i.getFirstChild();if($(n)){n.append(e);const i=r.getFirstChild();if($(i)){S(n,i.getChildren()),r.remove(),t.add(r.getKey());}}}else if(C(r)){const t=r.getFirstChild();if($(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e);}}else if(C(i)){const t=i.getFirstChild();$(t)&&t.append(e);}else if($(n)){const t=R(),s=U(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t);}}function L(e){if(C(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if($(n?n.getParent():void 0)&&B(n)&&$(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else {const r=t.getListType(),i=R(),s=U(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=R(),c=U(r);o.append(c),S(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e);}}}function O(){const r=$getSelection();if(!$isRangeSelection(r)||!r.isCollapsed())return !1;const i=r.anchor.getNode();if(!B(i)||0!==i.getChildrenSize())return !1;const c=v(i),l=i.getParent();$(l)||_(40);const a=l.getParent();let h;if($isRootOrShadowRoot(a))h=$createParagraphNode(),c.insertAfter(h);else {if(!B(a))return !1;h=R(),a.insertAfter(h);}h.select();const u=i.getNextSiblings();if(u.length>0){const e=U(l.getListType());if($isParagraphNode(h))h.insertAfter(e);else {const t=R();t.append(e),h.insertAfter(t);}u.forEach((t=>{t.remove(),e.append(t);}));}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!B(t)&&!$(t))break;t=e;}t.remove();}(i),!0}function E(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class M extends ElementNode{static getType(){return "listitem"}static clone(e){return new M(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t;}createDOM(e){const t=document.createElement("li"),n=this.getParent();return $(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,F(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return $(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,F(t,n.theme,this),!1}static transform(){return e=>{if(B(e)||_(144),null==e.__checked)return;const t=e.getParent();$(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);}}static importDOM(){return {li:()=>({conversion:D,priority:0})}}static importJSON(e){const t=R();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return {...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if($isElementNode(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove();}else super.append(n);}return this}replace(e,t){if(B(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!$(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else {const t=U(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e);}n.insertAfter(e),e.insertAfter(t);}return t&&($isElementNode(e)||_(139),this.getChildren().forEach((t=>{e.append(t);}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if($(n)||_(39),B(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=U(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t);}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&C(t)&&C(n)&&(A(t.getFirstChild(),n.getFirstChild()),n.remove());}insertNewAfter(e,t=!0){const n=R(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=$createParagraphNode();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=B(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else {n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.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(t),this.remove();return !0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e;}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return $(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){this.getWritable().__checked=e;}toggleChecked(){this.setChecked(!this.__checked);}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;B(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&_(117),(e=Math.floor(e))>=0||_(199);let t=this.getIndent();for(;t!==e;)t<e?(x(this),t++):(L(this),t--);return this}canInsertAfter(e){return B(e)}canReplaceWith(e){return B(e)}canMergeWith(e){return $isParagraphNode(e)||B(e)}extractWithChild(e,n){if(!$isRangeSelection(n))return !1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return !0}createParentElementNode(){return U("bullet")}canMergeWhenEmpty(){return !0}}function F(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...E(o)),s){const e=n.getParent(),t=$(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked);}if(void 0!==c){const e=E(c);n.getChildren().some((e=>$(e)))?r.push(...e):i.push(...e);}i.length>0&&removeClassNamesFromElement(e,...i),r.length>0&&addClassNamesToElement(e,...r);}function w(e,t,n,r){$(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"));}function D(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return I(t);const t=e.getAttribute("aria-checked");return {node:R("true"===t||"false"!==t&&void 0)}}function I(e){if(!("checkbox"===e.getAttribute("type")))return {node:null};return {node:R(e.hasAttribute("checked"))}}function R(e){return $applyNodeReplacement(new M(void 0,e))}function B(e){return e instanceof M}class K extends ElementNode{static getType(){return "list"}static clone(e){const t=e.__listType||z[e.__tag];return new K(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=z[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t;}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul";}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,W(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(W(t,n.theme,this),!1)}static transform(){return e=>{$(e)||_(163),function(e){const t=e.getNextSibling();$(t)&&e.getListType()===t.getListType()&&A(e,t);}(e),function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())B(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),$(r.getFirstChild())||n++);}(e);}}static importDOM(){return {ol:()=>({conversion:J,priority:0}),ul:()=>({conversion:J,priority:0})}}static importJSON(e){const t=U(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&isHTMLElement(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return {...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return !1}canIndent(){return !1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(B(n))super.append(n);else {const e=R();if($(n))e.append(n);else if($isElementNode(n)){const t=$createTextNode(n.getTextContent());e.append(t);}else e.append(n);super.append(e);}}return this}extractWithChild(e){return B(e)}}function W(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=m(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let a;const h=s.nested,u=s.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...E(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t);}if(void 0!==a){const e=E(a);t>1?r.push(...e):i.push(...e);}}i.length>0&&removeClassNamesFromElement(e,...i),r.length>0&&addClassNamesToElement(e,...r);}function V(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(B(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{$(e)&&t.push(k(e));}));}else t.push(k(r));}return t}function J(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=U("number",e.start);}else "ul"===t&&(n=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list"))return !0;for(const t of e.childNodes)if(isHTMLElement(t)&&t.hasAttribute("aria-checked"))return !0;return !1}(e)?U("check"):U("bullet"));return {after:V,node:n}}const z={ol:"number",ul:"bullet"};function U(e,t=1){return $applyNodeReplacement(new K(e,t))}function $(e){return e instanceof K}const j=createCommand("INSERT_UNORDERED_LIST_COMMAND"),q=createCommand("INSERT_ORDERED_LIST_COMMAND"),H=createCommand("INSERT_CHECK_LIST_COMMAND"),G=createCommand("REMOVE_LIST_COMMAND");
|
|
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
15
|
|
|
16
|
-
export {
|
|
16
|
+
export { z as $createListItemNode, X as $createListNode, k as $getListDepth, J as $handleListInsertParagraph, A as $insertList, $ as $isListItemNode, Y as $isListNode, w as $removeList, et as INSERT_CHECK_LIST_COMMAND, tt as INSERT_ORDERED_LIST_COMMAND, Z as INSERT_UNORDERED_LIST_COMMAND, W as ListItemNode, q as ListNode, rt as REMOVE_LIST_COMMAND, st as insertList, nt as registerList, it as removeList };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { $insertDataTransferForRichText, copyToClipboard } from '../clipboard/LexicalClipboard.js';
|
|
4
4
|
import { $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, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection, COMMAND_PRIORITY_EDITOR, 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, $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, isSelectionCapturedInDecoratorInput, $getRoot } from 'lexical';
|
|
6
|
+
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection, COMMAND_PRIORITY_EDITOR, 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, $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, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, $getRoot } from 'lexical';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -94,9 +94,6 @@ class QuoteNode extends ElementNode {
|
|
|
94
94
|
static clone(node) {
|
|
95
95
|
return new QuoteNode(node.__key);
|
|
96
96
|
}
|
|
97
|
-
constructor(key) {
|
|
98
|
-
super(key);
|
|
99
|
-
}
|
|
100
97
|
|
|
101
98
|
// View
|
|
102
99
|
|
|
@@ -120,7 +117,7 @@ class QuoteNode extends ElementNode {
|
|
|
120
117
|
const {
|
|
121
118
|
element
|
|
122
119
|
} = super.exportDOM(editor);
|
|
123
|
-
if (
|
|
120
|
+
if (isHTMLElement(element)) {
|
|
124
121
|
if (this.isEmpty()) {
|
|
125
122
|
element.append(document.createElement('br'));
|
|
126
123
|
}
|
|
@@ -136,17 +133,7 @@ class QuoteNode extends ElementNode {
|
|
|
136
133
|
};
|
|
137
134
|
}
|
|
138
135
|
static importJSON(serializedNode) {
|
|
139
|
-
|
|
140
|
-
node.setFormat(serializedNode.format);
|
|
141
|
-
node.setIndent(serializedNode.indent);
|
|
142
|
-
node.setDirection(serializedNode.direction);
|
|
143
|
-
return node;
|
|
144
|
-
}
|
|
145
|
-
exportJSON() {
|
|
146
|
-
return {
|
|
147
|
-
...super.exportJSON(),
|
|
148
|
-
type: 'quote'
|
|
149
|
-
};
|
|
136
|
+
return $createQuoteNode().updateFromJSON(serializedNode);
|
|
150
137
|
}
|
|
151
138
|
|
|
152
139
|
// Mutation
|
|
@@ -192,6 +179,11 @@ class HeadingNode extends ElementNode {
|
|
|
192
179
|
getTag() {
|
|
193
180
|
return this.__tag;
|
|
194
181
|
}
|
|
182
|
+
setTag(tag) {
|
|
183
|
+
const self = this.getWritable();
|
|
184
|
+
this.__tag = tag;
|
|
185
|
+
return self;
|
|
186
|
+
}
|
|
195
187
|
|
|
196
188
|
// View
|
|
197
189
|
|
|
@@ -206,8 +198,8 @@ class HeadingNode extends ElementNode {
|
|
|
206
198
|
}
|
|
207
199
|
return element;
|
|
208
200
|
}
|
|
209
|
-
updateDOM(prevNode, dom) {
|
|
210
|
-
return
|
|
201
|
+
updateDOM(prevNode, dom, config) {
|
|
202
|
+
return prevNode.__tag !== this.__tag;
|
|
211
203
|
}
|
|
212
204
|
static importDOM() {
|
|
213
205
|
return {
|
|
@@ -268,7 +260,7 @@ class HeadingNode extends ElementNode {
|
|
|
268
260
|
const {
|
|
269
261
|
element
|
|
270
262
|
} = super.exportDOM(editor);
|
|
271
|
-
if (
|
|
263
|
+
if (isHTMLElement(element)) {
|
|
272
264
|
if (this.isEmpty()) {
|
|
273
265
|
element.append(document.createElement('br'));
|
|
274
266
|
}
|
|
@@ -284,18 +276,15 @@ class HeadingNode extends ElementNode {
|
|
|
284
276
|
};
|
|
285
277
|
}
|
|
286
278
|
static importJSON(serializedNode) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return node;
|
|
279
|
+
return $createHeadingNode(serializedNode.tag).updateFromJSON(serializedNode);
|
|
280
|
+
}
|
|
281
|
+
updateFromJSON(serializedNode) {
|
|
282
|
+
return super.updateFromJSON(serializedNode).setTag(serializedNode.tag);
|
|
292
283
|
}
|
|
293
284
|
exportJSON() {
|
|
294
285
|
return {
|
|
295
286
|
...super.exportJSON(),
|
|
296
|
-
tag: this.getTag()
|
|
297
|
-
type: 'heading',
|
|
298
|
-
version: 1
|
|
287
|
+
tag: this.getTag()
|
|
299
288
|
};
|
|
300
289
|
}
|
|
301
290
|
|
|
@@ -338,6 +327,7 @@ function $convertHeadingElement(element) {
|
|
|
338
327
|
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
|
|
339
328
|
node = $createHeadingNode(nodeName);
|
|
340
329
|
if (element.style !== null) {
|
|
330
|
+
setNodeIndentFromDOM(element, node);
|
|
341
331
|
node.setFormat(element.style.textAlign);
|
|
342
332
|
}
|
|
343
333
|
}
|
|
@@ -349,12 +339,13 @@ function $convertBlockquoteElement(element) {
|
|
|
349
339
|
const node = $createQuoteNode();
|
|
350
340
|
if (element.style !== null) {
|
|
351
341
|
node.setFormat(element.style.textAlign);
|
|
342
|
+
setNodeIndentFromDOM(element, node);
|
|
352
343
|
}
|
|
353
344
|
return {
|
|
354
345
|
node
|
|
355
346
|
};
|
|
356
347
|
}
|
|
357
|
-
function $createHeadingNode(headingTag) {
|
|
348
|
+
function $createHeadingNode(headingTag = 'h1') {
|
|
358
349
|
return $applyNodeReplacement(new HeadingNode(headingTag));
|
|
359
350
|
}
|
|
360
351
|
function $isHeadingNode(node) {
|
|
@@ -435,6 +426,19 @@ function $isSelectionAtEndOfRoot(selection) {
|
|
|
435
426
|
const focus = selection.focus;
|
|
436
427
|
return focus.key === 'root' && focus.offset === $getRoot().getChildrenSize();
|
|
437
428
|
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Resets the capitalization of the selection to default.
|
|
432
|
+
* Called when the user presses space, tab, or enter key.
|
|
433
|
+
* @param selection The selection to reset the capitalization of.
|
|
434
|
+
*/
|
|
435
|
+
function $resetCapitalization(selection) {
|
|
436
|
+
for (const format of ['lowercase', 'uppercase', 'capitalize']) {
|
|
437
|
+
if (selection.hasFormat(format)) {
|
|
438
|
+
selection.toggleFormat(format);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
438
442
|
function registerRichText(editor) {
|
|
439
443
|
const removeListener = mergeRegister(editor.registerCommand(CLICK_COMMAND, payload => {
|
|
440
444
|
const selection = $getSelection();
|
|
@@ -636,7 +640,6 @@ function registerRichText(editor) {
|
|
|
636
640
|
if (!$isRangeSelection(selection)) {
|
|
637
641
|
return false;
|
|
638
642
|
}
|
|
639
|
-
event.preventDefault();
|
|
640
643
|
const {
|
|
641
644
|
anchor
|
|
642
645
|
} = selection;
|
|
@@ -644,9 +647,17 @@ function registerRichText(editor) {
|
|
|
644
647
|
if (selection.isCollapsed() && anchor.offset === 0 && !$isRootNode(anchorNode)) {
|
|
645
648
|
const element = $getNearestBlockElementAncestorOrThrow(anchorNode);
|
|
646
649
|
if (element.getIndent() > 0) {
|
|
650
|
+
event.preventDefault();
|
|
647
651
|
return editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
648
652
|
}
|
|
649
653
|
}
|
|
654
|
+
|
|
655
|
+
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
|
|
656
|
+
// more details - https://github.com/facebook/lexical/issues/5841
|
|
657
|
+
if (IS_IOS && navigator.language === 'ko-KR') {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
event.preventDefault();
|
|
650
661
|
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, true);
|
|
651
662
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DELETE_COMMAND, event => {
|
|
652
663
|
if ($isTargetWithinDecorator(event.target)) {
|
|
@@ -663,6 +674,7 @@ function registerRichText(editor) {
|
|
|
663
674
|
if (!$isRangeSelection(selection)) {
|
|
664
675
|
return false;
|
|
665
676
|
}
|
|
677
|
+
$resetCapitalization(selection);
|
|
666
678
|
if (event !== null) {
|
|
667
679
|
// If we have beforeinput, then we can avoid blocking
|
|
668
680
|
// the default behavior. This ensures that the iOS can
|
|
@@ -765,7 +777,7 @@ function registerRichText(editor) {
|
|
|
765
777
|
}
|
|
766
778
|
|
|
767
779
|
// if inputs then paste within the input ignore creating a new node on paste event
|
|
768
|
-
if (isSelectionCapturedInDecoratorInput(event.target)) {
|
|
780
|
+
if (isDOMNode(event.target) && isSelectionCapturedInDecoratorInput(event.target)) {
|
|
769
781
|
return false;
|
|
770
782
|
}
|
|
771
783
|
const selection = $getSelection();
|
|
@@ -774,6 +786,18 @@ function registerRichText(editor) {
|
|
|
774
786
|
return true;
|
|
775
787
|
}
|
|
776
788
|
return false;
|
|
789
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_SPACE_COMMAND, _ => {
|
|
790
|
+
const selection = $getSelection();
|
|
791
|
+
if ($isRangeSelection(selection)) {
|
|
792
|
+
$resetCapitalization(selection);
|
|
793
|
+
}
|
|
794
|
+
return false;
|
|
795
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_TAB_COMMAND, _ => {
|
|
796
|
+
const selection = $getSelection();
|
|
797
|
+
if ($isRangeSelection(selection)) {
|
|
798
|
+
$resetCapitalization(selection);
|
|
799
|
+
}
|
|
800
|
+
return false;
|
|
777
801
|
}, COMMAND_PRIORITY_EDITOR));
|
|
778
802
|
return removeListener;
|
|
779
803
|
}
|
|
@@ -11,7 +11,7 @@ import * as LexicalRichText_prod from './LexicalRichText.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalRichText_dev : LexicalRichText_prod;
|
|
15
15
|
const $createHeadingNode = mod.$createHeadingNode;
|
|
16
16
|
const $createQuoteNode = mod.$createQuoteNode;
|
|
17
17
|
const $isHeadingNode = mod.$isHeadingNode;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { $insertDataTransferForRichText, copyToClipboard } from '../clipboard/LexicalClipboard.js';
|
|
4
4
|
import { $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, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection, COMMAND_PRIORITY_EDITOR, 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, isSelectionCapturedInDecoratorInput } from 'lexical';
|
|
6
|
+
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, setNodeIndentFromDOM, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection, COMMAND_PRIORITY_EDITOR, 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, 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 st(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 ct="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,at=ct&&"documentMode"in document?document.documentMode:null,ut=!(!ct||!("InputEvent"in window)||at)&&"getTargetRanges"in new window.InputEvent("input"),lt=ct&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),dt=ct&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,mt=ct&&/^(?=.*Chrome).*/i.test(navigator.userAgent),ft=ct&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!mt,gt=createCommand("DRAG_DROP_PASTE_FILE");class pt extends ElementNode{static getType(){return "quote"}static clone(t){return new pt(t.__key)}constructor(t){super(t);}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:xt,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&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){const e=ht();return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return {...super.exportJSON(),type:"quote"}}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 ht(){return $applyNodeReplacement(new pt)}function Ct(t){return t instanceof pt}class yt extends ElementNode{static getType(){return "heading"}static clone(t){return new yt(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t;}getTag(){return this.__tag}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){return !1}static importDOM(){return {h1:t=>({conversion:Dt,priority:0}),h2:t=>({conversion:Dt,priority:0}),h3:t=>({conversion:Dt,priority:0}),h4:t=>({conversion:Dt,priority:0}),h5:t=>({conversion:Dt,priority:0}),h6:t=>({conversion:Dt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&vt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>vt(t)?{conversion:t=>({node:wt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&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){const e=wt(t.tag);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return {...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}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():wt(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():wt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return !0}}function vt(t){return "span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Dt(t){const e=t.nodeName.toLowerCase();let n=null;return "h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=wt(e),null!==t.style&&n.setFormat(t.style.textAlign)),{node:n}}function xt(t){const e=ht();return null!==t.style&&e.setFormat(t.style.textAlign),{node:e}}function wt(t){return $applyNodeReplacement(new yt(t))}function Et(t){return t instanceof yt}function Nt(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 It(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 c=s.getKey();s.canIndent()&&!n.has(c)&&(n.add(c),t(s));}return n.size>0}function Ot(t){const e=$getNearestNodeFromDOMNode(t);return $isDecoratorNode(e)}function Tt(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,(()=>It((t=>{const e=t.getIndent();t.setIndent(e+1);}))),COMMAND_PRIORITY_EDITOR),o.registerCommand(OUTDENT_CONTENT_COMMAND,(()=>It((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)&&!Ot(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)&&!Ot(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(Ot(t.target))return !1;const e=$getSelection();if(!$isRangeSelection(e))return !1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!$isRootNode(r)){if($getNearestBlockElementAncestorOrThrow(r).getIndent()>0)return o.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0)}return o.dispatchCommand(DELETE_CHARACTER_COMMAND,!0)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(KEY_DELETE_COMMAND,(t=>{if(Ot(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(null!==t){if((dt||lt||ft)&&ut)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]=Nt(t);if(e.length>0){const n=st(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(gt,e);}return t.preventDefault(),!0}const n=$getSelection();return !!$isRangeSelection(n)}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DRAGSTART_COMMAND,(t=>{const[e]=Nt(t),n=$getSelection();return !(e&&!$isRangeSelection(n))}),COMMAND_PRIORITY_EDITOR),o.registerCommand(DRAGOVER_COMMAND,(t=>{const[e]=Nt(t),n=$getSelection();if(e&&!$isRangeSelection(n))return !1;const r=st(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]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(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))}
|
|
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))}
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { Tt as $createHeadingNode, Dt as $createQuoteNode, _t as $isHeadingNode, xt as $isQuoteNode, vt as DRAG_DROP_PASTE, wt as HeadingNode, yt as QuoteNode, At as eventFiles, Pt as registerRichText };
|