@lexical/rich-text 0.45.0 → 0.45.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -179,15 +179,16 @@ const GoogleDocsTitleSpanRule = html.defineImportRule({
|
|
|
179
179
|
const RichTextImportRules = [HeadingRule, QuoteRule, GoogleDocsTitleParagraphRule, GoogleDocsTitleSpanRule];
|
|
180
180
|
|
|
181
181
|
/**
|
|
182
|
-
* Bundles {@link RichTextImportRules}
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
182
|
+
* Bundles {@link RichTextImportRules} together with the runtime
|
|
183
|
+
* {@link RichTextExtension}. The application is expected to already
|
|
184
|
+
* have `CoreImportExtension` (or some equivalent) in its dependency
|
|
185
|
+
* graph — the core/text/paragraph/inline-format rules are a shared
|
|
186
|
+
* baseline, not something this leaf importer should re-declare.
|
|
186
187
|
*
|
|
187
188
|
* @experimental
|
|
188
189
|
*/
|
|
189
190
|
const RichTextImportExtension = lexical.defineExtension({
|
|
190
|
-
dependencies: [
|
|
191
|
+
dependencies: [RichTextExtension, lexical.configExtension(html.DOMImportExtension, {
|
|
191
192
|
rules: RichTextImportRules
|
|
192
193
|
})],
|
|
193
194
|
name: '@lexical/rich-text/Import'
|
|
@@ -12,7 +12,7 @@ import { $isParentRTL, $shouldOverrideDefaultCharacterSelection, $moveCharacter
|
|
|
12
12
|
import { addClassNamesToElement, isHTMLElement as isHTMLElement$1, objectKlassEquals, mergeRegister, $findMatchingParent, $handleIndentAndOutdent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
13
13
|
import { defineExtension, safeCast, shallowMergeConfig, configExtension, setNodeIndentFromDOM, $setFormatFromDOM, $setDirectionFromDOM, isHTMLElement, createCommand, $applyNodeReplacement, ElementNode, $createParagraphNode, CLICK_COMMAND, $getSelection, $isNodeSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, DELETE_CHARACTER_COMMAND, 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, $createTabNode, $insertNodes, 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, IS_IOS, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, IS_SAFARI, IS_APPLE_WEBKIT, CAN_USE_BEFORE_INPUT, 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, MOVE_TO_END, MOVE_TO_START, $getRoot, $isRootNode, PASTE_TAG } from 'lexical';
|
|
14
14
|
import { DragonExtension } from '@lexical/dragon';
|
|
15
|
-
import {
|
|
15
|
+
import { DOMImportExtension, defineImportRule, sel } from '@lexical/html';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -177,15 +177,16 @@ const GoogleDocsTitleSpanRule = defineImportRule({
|
|
|
177
177
|
const RichTextImportRules = [HeadingRule, QuoteRule, GoogleDocsTitleParagraphRule, GoogleDocsTitleSpanRule];
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
* Bundles {@link RichTextImportRules}
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
180
|
+
* Bundles {@link RichTextImportRules} together with the runtime
|
|
181
|
+
* {@link RichTextExtension}. The application is expected to already
|
|
182
|
+
* have `CoreImportExtension` (or some equivalent) in its dependency
|
|
183
|
+
* graph — the core/text/paragraph/inline-format rules are a shared
|
|
184
|
+
* baseline, not something this leaf importer should re-declare.
|
|
184
185
|
*
|
|
185
186
|
* @experimental
|
|
186
187
|
*/
|
|
187
188
|
const RichTextImportExtension = defineExtension({
|
|
188
|
-
dependencies: [
|
|
189
|
+
dependencies: [RichTextExtension, configExtension(DOMImportExtension, {
|
|
189
190
|
rules: RichTextImportRules
|
|
190
191
|
})],
|
|
191
192
|
name: '@lexical/rich-text/Import'
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/clipboard"),t=require("@lexical/extension"),n=require("@lexical/selection"),r=require("@lexical/utils"),o=require("lexical"),i=require("@lexical/dragon"),s=require("@lexical/html");function a(e,t){return e&&null!==t?o.shallowMergeConfig(e,t):t}const c=o.defineExtension({build:(e,n)=>t.namedSignals(n),config:o.safeCast({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[i.DragonExtension,t.NormalizeInlineElementsExtension,t.NormalizeTripleClickSelectionExtension],mergeConfig:function(e,t){const n=o.shallowMergeConfig(e,t);return t.escapeFormatTriggers&&(n.escapeFormatTriggers=function(e,t){const n=o.shallowMergeConfig(e,t);for(const r of Object.keys(t))n[r]=a(e[r],t[r]);return n}(e.escapeFormatTriggers,t.escapeFormatTriggers)),n},name:"@lexical/rich-text",nodes:()=>[O,g],register:(e,n,r)=>t.effect(()=>C(e,r.getOutput().escapeFormatTriggers))});const l=[s.defineImportRule({$import:(e,t)=>{const n=R(t.nodeName.toLowerCase());return o.setNodeIndentFromDOM(t,n),o.$setFormatFromDOM(n,t),o.$setDirectionFromDOM(n,t),[n.splice(0,0,e.$importChildren(t))]},match:s.sel.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),s.defineImportRule({$import:(e,t)=>{const n=m();return o.$setFormatFromDOM(n,t),o.setNodeIndentFromDOM(t,n),o.$setDirectionFromDOM(n,t),[n.splice(0,0,e.$importChildren(t))]},match:s.sel.tag("blockquote"),name:"@lexical/rich-text/blockquote"}),s.defineImportRule({$import:(e,t,n)=>{const r=t.firstChild;return r&&(i=r,o.isHTMLElement(i)&&"SPAN"===i.nodeName&&"26pt"===i.style.fontSize)?e.$importChildren(t):n();var i},match:s.sel.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),s.defineImportRule({$import:(e,t,n)=>"26pt"!==t.style.fontSize?n():[R("h1").splice(0,0,e.$importChildren(t))],match:s.sel.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})],u=o.defineExtension({dependencies:[s.CoreImportExtension,c,o.configExtension(s.DOMImportExtension,{rules:l})],name:"@lexical/rich-text/Import"}),d=o.createCommand("DRAG_DROP_PASTE_FILE");class g extends o.ElementNode{static getType(){return"quote"}static clone(e){return new g(e.__key)}createDOM(e){const t=document.createElement("blockquote");return r.addClassNamesToElement(t,e.theme.quote),t}updateDOM(e,t){return!1}static importDOM(){return{blockquote:e=>({conversion:p,priority:0})}}exportDOM(e){const{element:t}=super.exportDOM(e);if(r.isHTMLElement(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return m().updateFromJSON(e)}insertNewAfter(e,t){const n=o.$createParagraphNode(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,t),n}collapseAtStart(){const e=o.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}}function m(){return o.$applyNodeReplacement(new g)}class O extends o.ElementNode{__tag;static getType(){return"heading"}static clone(e){return new O(e.__tag,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,n=document.createElement(t),o=e.theme.heading;if(void 0!==o){const e=o[t];r.addClassNamesToElement(n,e)}return n}updateDOM(e,t,n){return e.__tag!==this.__tag}static importDOM(){return{h1:e=>({conversion:N,priority:0}),h2:e=>({conversion:N,priority:0}),h3:e=>({conversion:N,priority:0}),h4:e=>({conversion:N,priority:0}),h5:e=>({conversion:N,priority:0}),h6:e=>({conversion:N,priority:0}),p:e=>{const t=e.firstChild;return null!==t&&D(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>D(e)?{conversion:e=>({node:R("h1")}),priority:3}:null}}exportDOM(e){const{element:t}=super.exportDOM(e);if(r.isHTMLElement(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return R(e.tag).updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const n=e?e.anchor.offset:0,r=this.getLastDescendant(),i=!r||e&&e.anchor.key===r.getKey()&&n===r.getTextContentSize()||!e?o.$createParagraphNode():R(this.getTag()),s=this.getDirection();if(i.setDirection(s),this.insertAfter(i,t),0===n&&!this.isEmpty()&&e){const e=o.$createParagraphNode();e.select(),this.replace(e,!0)}return i}collapseAtStart(){if(this.isEmpty()){const e=o.$createParagraphNode();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}}function D(e){return"span"===e.nodeName.toLowerCase()&&"26pt"===e.style.fontSize}function N(e){const t=e.nodeName.toLowerCase();let n=null;return"h1"!==t&&"h2"!==t&&"h3"!==t&&"h4"!==t&&"h5"!==t&&"h6"!==t||(n=R(t),o.setNodeIndentFromDOM(e,n),o.$setFormatFromDOM(n,e),o.$setDirectionFromDOM(n,e)),{node:n}}function p(e){const t=m();return o.$setFormatFromDOM(t,e),o.setNodeIndentFromDOM(e,t),o.$setDirectionFromDOM(t,e),{node:t}}function R(e="h1"){return o.$applyNodeReplacement(new O(e))}function f(e){let t=null;if(r.objectKlassEquals(e,DragEvent)?t=e.dataTransfer:r.objectKlassEquals(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,o=n.includes("Files"),i=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(t.files),i]}function M(e){const t=o.$getNearestNodeFromDOMNode(e);return o.$isDecoratorNode(t)}function _(e,t,n,r){let i=!1,s=null;if(e.isCollapsed()&&"text"===e.anchor.type){const t=e.anchor.getNode();if(o.$isTextNode(t)){s=t;const r=e.anchor.offset,o=r===t.getTextContentSize()&&null===t.getNextSibling(),a=0===r&&null===t.getPreviousSibling();i="end"===n&&o||"start"===n&&a||"both"===n&&(o||a)}}let a=!1;for(const[n,c]of Object.entries(r)){if(null==c||!c[t])continue;const r=n;if(c.onlyAtBoundary){if(!(i&&s&&o.$isTextNode(s)&&s.hasFormat(r)))continue;a=!0}e.hasFormat(r)&&e.toggleFormat(r)}a&&e.setStyle("")}const T={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function C(i,s=t.signal(T)){const a=r.mergeRegister(i.registerCommand(o.CLICK_COMMAND,()=>{const e=o.$getSelection();return o.$isNodeSelection(e)?(e.clear(),!0):(o.$isRangeSelection(e)&&_(e,"click","both",s.peek()),!1)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();return o.$isRangeSelection(t)?(t.deleteCharacter(e),!0):!!o.$isNodeSelection(t)&&(t.deleteNodes(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_WORD_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteWord(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_LINE_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteLine(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.CONTROLLED_TEXT_INSERTION_COMMAND,t=>{const n=o.$getSelection();if("string"==typeof t)null!==n&&n.insertText(t);else{if(null===n)return!1;const r=t.dataTransfer;if(null!=r)e.$insertDataTransferForRichText(r,n,i);else if(o.$isRangeSelection(n)){const e=t.data;return e&&n.insertText(e),!0}}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.REMOVE_TEXT_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.removeText(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.FORMAT_TEXT_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.formatText(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.FORMAT_ELEMENT_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t)&&!o.$isNodeSelection(t))return!1;const n=t.getNodes();for(const t of n){const n=r.$findMatchingParent(t,e=>o.$isElementNode(e)&&!e.isInline());null!==n&&n.setFormat(e)}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_LINE_BREAK_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.insertLineBreak(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_PARAGRAPH_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.insertParagraph(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_TAB_COMMAND,()=>{const e=o.$createTabNode(),t=o.$getSelection();return o.$isRangeSelection(t)&&(e.setFormat(t.format),e.setStyle(t.style)),o.$insertNodes([e]),!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INDENT_CONTENT_COMMAND,()=>r.$handleIndentAndOutdent(e=>{const t=e.getIndent();e.setIndent(t+1)}),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.OUTDENT_CONTENT_COMMAND,()=>r.$handleIndentAndOutdent(e=>{const t=e.getIndent();t>0&&e.setIndent(Math.max(0,t-1))}),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_UP_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectPrevious(),!0}else if(o.$isRangeSelection(t)){const n=o.$getAdjacentNode(t.focus,!0);if(!e.shiftKey&&o.$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),e.preventDefault(),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_DOWN_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectNext(0,0),!0}else if(o.$isRangeSelection(t)){if(function(e){const t=e.focus;return"root"===t.key&&t.offset===o.$getRoot().getChildrenSize()}(t))return e.preventDefault(),!0;const n=o.$getAdjacentNode(t.focus,!1);if(!e.shiftKey&&o.$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),e.preventDefault(),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_LEFT_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const r=t.getNodes();if(r.length>0)return e.preventDefault(),n.$isParentRTL(r[0])?r[0].selectNext(0,0):r[0].selectPrevious(),!0}if(!o.$isRangeSelection(t))return!1;if(e.shiftKey||_(t,"arrow","start",s.peek()),n.$shouldOverrideDefaultCharacterSelection(t,!0)){const r=e.shiftKey;return e.preventDefault(),n.$moveCharacter(t,r,!0),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_RIGHT_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const r=t.getNodes();if(r.length>0)return e.preventDefault(),n.$isParentRTL(r[0])?r[0].selectPrevious():r[0].selectNext(0,0),!0}if(!o.$isRangeSelection(t))return!1;if(e.shiftKey||_(t,"arrow","end",s.peek()),n.$shouldOverrideDefaultCharacterSelection(t,!1)){const r=e.shiftKey;return e.preventDefault(),n.$moveCharacter(t,r,!1),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_BACKSPACE_COMMAND,e=>{if(M(e.target))return!1;const t=o.$getSelection();if(o.$isRangeSelection(t)){if(function(e){if(!e.isCollapsed())return!1;const{anchor:t}=e;if(0!==t.offset)return!1;const n=t.getNode();if(o.$isRootNode(n))return!1;const i=r.$getNearestBlockElementAncestorOrThrow(n);return i.getIndent()>0&&(i.is(n)||n.is(i.getFirstDescendant()))}(t))return e.preventDefault(),i.dispatchCommand(o.OUTDENT_CONTENT_COMMAND,void 0);if(o.IS_IOS&&"ko-KR"===navigator.language)return!1}else if(!o.$isNodeSelection(t))return!1;return e.preventDefault(),i.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_DELETE_COMMAND,e=>{if(M(e.target))return!1;const t=o.$getSelection();return!(!o.$isRangeSelection(t)&&!o.$isNodeSelection(t))&&(e.preventDefault(),i.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!1))},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ENTER_COMMAND,e=>{let t=o.$getSelection();if(o.$isNodeSelection(t)){const e=t.getNodes();1===e.length&&o.$isDecoratorNode(e[0])&&!e[0].isInline()&&(t=e[0].selectNext())}if(!o.$isRangeSelection(t))return!1;if(_(t,"enter","both",s.peek()),null!==e){if((o.IS_IOS||o.IS_SAFARI||o.IS_APPLE_WEBKIT)&&o.CAN_USE_BEFORE_INPUT)return!1;if(e.preventDefault(),e.shiftKey)return i.dispatchCommand(o.INSERT_LINE_BREAK_COMMAND,!1)}return i.dispatchCommand(o.INSERT_PARAGRAPH_COMMAND,void 0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ESCAPE_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(i.blur(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DROP_COMMAND,t=>{const[,n]=f(t);if(n.length>0){const r=t.clientX,s=t.clientY,a=e.caretFromPoint(r,s);if(null!==a){const{offset:e,node:t}=a,r=o.$getNearestNodeFromDOMNode(t);if(null!==r){const t=o.$createRangeSelection();if(o.$isTextNode(r))t.anchor.set(r.getKey(),e,"text"),t.focus.set(r.getKey(),e,"text");else{const e=r.getParentOrThrow().getKey(),n=r.getIndexWithinParent()+1;t.anchor.set(e,n,"element"),t.focus.set(e,n,"element")}const n=o.$normalizeSelection__EXPERIMENTAL(t);o.$setSelection(n)}i.dispatchCommand(d,n)}return t.preventDefault(),!0}return e.$handleRichTextDrop(t,i)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DRAGSTART_COMMAND,t=>{const[n]=f(t),r=o.$getSelection();return!(n&&!o.$isRangeSelection(r))&&(o.$isRangeSelection(r)&&!r.isCollapsed()&&null!==t.dataTransfer&&(e.setLexicalClipboardDataTransfer(t.dataTransfer,e.$getClipboardDataFromSelection(r)),e.$writeDragSourceToDataTransfer(t.dataTransfer,i)),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DRAGOVER_COMMAND,t=>{const[n]=f(t),r=o.$getSelection();if(n&&!o.$isRangeSelection(r))return!1;const i=t.clientX,s=t.clientY,a=e.caretFromPoint(i,s);if(null!==a){const e=o.$getNearestNodeFromDOMNode(a.node);o.$isDecoratorNode(e)&&t.preventDefault()}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.SELECT_ALL_COMMAND,()=>(o.$selectAll(),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.COPY_COMMAND,t=>(e.copyToClipboard(i,r.objectKlassEquals(t,ClipboardEvent)?t:null),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.CUT_COMMAND,t=>(async function(t,n){await e.copyToClipboard(n,r.objectKlassEquals(t,ClipboardEvent)?t:null),n.update(()=>{const e=o.$getSelection();o.$isRangeSelection(e)?e.removeText():o.$isNodeSelection(e)&&e.getNodes().forEach(e=>e.remove())})}(t,i),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.PASTE_COMMAND,t=>{const[,n,s]=f(t);if(n.length>0&&!s)return i.dispatchCommand(d,n),!0;if(o.isDOMNode(t.target)&&o.isSelectionCapturedInDecoratorInput(t.target))return!1;return null!==o.$getSelection()&&(function(t,n){t.preventDefault(),n.update(()=>{const i=o.$getSelection(),s=r.objectKlassEquals(t,InputEvent)||r.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData;null!=s&&null!==i&&e.$insertDataTransferForRichText(s,i,n)},{tag:o.PASTE_TAG})}(t,i),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_SPACE_COMMAND,()=>{const e=o.$getSelection();return o.$isRangeSelection(e)&&_(e,"space","both",s.peek()),!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_TAB_COMMAND,()=>{const e=o.$getSelection();return o.$isRangeSelection(e)&&_(e,"tab","both",s.peek()),!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.MOVE_TO_END,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const{anchor:n}=t;if("element"!==n.type||0!==n.offset)return!1;const r=n.getNode();if(!o.$isElementNode(r))return!1;const i=r.getFirstChild();if(!o.$isDecoratorNode(i)||!i.isInline())return!1;const s=r.getLastDescendant();if(null==s||o.$isDecoratorNode(s))return!1;const a=r.getKey(),c=r.selectEnd();return e.shiftKey&&c.anchor.set(a,0,"element"),e.preventDefault(),e.stopPropagation(),!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.MOVE_TO_START,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const{anchor:n,focus:i}=t,s=r.$findMatchingParent(i.getNode(),e=>o.$isElementNode(e)&&!e.isInline());if(null===s)return!1;const a=s.getFirstChild();if(!o.$isDecoratorNode(a)||!a.isInline())return!1;const c=s.getLastDescendant();if(null==c||o.$isDecoratorNode(c))return!1;if(r.$findMatchingParent(n.getNode(),e=>o.$isElementNode(e)&&!e.isInline())!==s)return!1;const l=s.getKey();return("element"!==i.type||i.key!==l||0!==i.offset)&&(t.focus.set(l,0,"element"),e.shiftKey||t.anchor.set(l,0,"element"),e.preventDefault(),e.stopPropagation(),!0)},o.COMMAND_PRIORITY_EDITOR));return a}exports.$createHeadingNode=R,exports.$createQuoteNode=m,exports.$isHeadingNode=function(e){return e instanceof O},exports.$isQuoteNode=function(e){return e instanceof g},exports.DRAG_DROP_PASTE=d,exports.HeadingNode=O,exports.QuoteNode=g,exports.RichTextExtension=c,exports.RichTextImportExtension=u,exports.RichTextImportRules=l,exports.eventFiles=f,exports.registerRichText=C;
|
|
9
|
+
"use strict";var e=require("@lexical/clipboard"),t=require("@lexical/extension"),n=require("@lexical/selection"),r=require("@lexical/utils"),o=require("lexical"),i=require("@lexical/dragon"),s=require("@lexical/html");function a(e,t){return e&&null!==t?o.shallowMergeConfig(e,t):t}const c=o.defineExtension({build:(e,n)=>t.namedSignals(n),config:o.safeCast({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[i.DragonExtension,t.NormalizeInlineElementsExtension,t.NormalizeTripleClickSelectionExtension],mergeConfig:function(e,t){const n=o.shallowMergeConfig(e,t);return t.escapeFormatTriggers&&(n.escapeFormatTriggers=function(e,t){const n=o.shallowMergeConfig(e,t);for(const r of Object.keys(t))n[r]=a(e[r],t[r]);return n}(e.escapeFormatTriggers,t.escapeFormatTriggers)),n},name:"@lexical/rich-text",nodes:()=>[O,g],register:(e,n,r)=>t.effect(()=>C(e,r.getOutput().escapeFormatTriggers))});const l=[s.defineImportRule({$import:(e,t)=>{const n=R(t.nodeName.toLowerCase());return o.setNodeIndentFromDOM(t,n),o.$setFormatFromDOM(n,t),o.$setDirectionFromDOM(n,t),[n.splice(0,0,e.$importChildren(t))]},match:s.sel.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),s.defineImportRule({$import:(e,t)=>{const n=m();return o.$setFormatFromDOM(n,t),o.setNodeIndentFromDOM(t,n),o.$setDirectionFromDOM(n,t),[n.splice(0,0,e.$importChildren(t))]},match:s.sel.tag("blockquote"),name:"@lexical/rich-text/blockquote"}),s.defineImportRule({$import:(e,t,n)=>{const r=t.firstChild;return r&&(i=r,o.isHTMLElement(i)&&"SPAN"===i.nodeName&&"26pt"===i.style.fontSize)?e.$importChildren(t):n();var i},match:s.sel.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),s.defineImportRule({$import:(e,t,n)=>"26pt"!==t.style.fontSize?n():[R("h1").splice(0,0,e.$importChildren(t))],match:s.sel.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})],u=o.defineExtension({dependencies:[c,o.configExtension(s.DOMImportExtension,{rules:l})],name:"@lexical/rich-text/Import"}),d=o.createCommand("DRAG_DROP_PASTE_FILE");class g extends o.ElementNode{static getType(){return"quote"}static clone(e){return new g(e.__key)}createDOM(e){const t=document.createElement("blockquote");return r.addClassNamesToElement(t,e.theme.quote),t}updateDOM(e,t){return!1}static importDOM(){return{blockquote:e=>({conversion:p,priority:0})}}exportDOM(e){const{element:t}=super.exportDOM(e);if(r.isHTMLElement(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return m().updateFromJSON(e)}insertNewAfter(e,t){const n=o.$createParagraphNode(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,t),n}collapseAtStart(){const e=o.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}}function m(){return o.$applyNodeReplacement(new g)}class O extends o.ElementNode{__tag;static getType(){return"heading"}static clone(e){return new O(e.__tag,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,n=document.createElement(t),o=e.theme.heading;if(void 0!==o){const e=o[t];r.addClassNamesToElement(n,e)}return n}updateDOM(e,t,n){return e.__tag!==this.__tag}static importDOM(){return{h1:e=>({conversion:N,priority:0}),h2:e=>({conversion:N,priority:0}),h3:e=>({conversion:N,priority:0}),h4:e=>({conversion:N,priority:0}),h5:e=>({conversion:N,priority:0}),h6:e=>({conversion:N,priority:0}),p:e=>{const t=e.firstChild;return null!==t&&D(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>D(e)?{conversion:e=>({node:R("h1")}),priority:3}:null}}exportDOM(e){const{element:t}=super.exportDOM(e);if(r.isHTMLElement(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return R(e.tag).updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const n=e?e.anchor.offset:0,r=this.getLastDescendant(),i=!r||e&&e.anchor.key===r.getKey()&&n===r.getTextContentSize()||!e?o.$createParagraphNode():R(this.getTag()),s=this.getDirection();if(i.setDirection(s),this.insertAfter(i,t),0===n&&!this.isEmpty()&&e){const e=o.$createParagraphNode();e.select(),this.replace(e,!0)}return i}collapseAtStart(){if(this.isEmpty()){const e=o.$createParagraphNode();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}}function D(e){return"span"===e.nodeName.toLowerCase()&&"26pt"===e.style.fontSize}function N(e){const t=e.nodeName.toLowerCase();let n=null;return"h1"!==t&&"h2"!==t&&"h3"!==t&&"h4"!==t&&"h5"!==t&&"h6"!==t||(n=R(t),o.setNodeIndentFromDOM(e,n),o.$setFormatFromDOM(n,e),o.$setDirectionFromDOM(n,e)),{node:n}}function p(e){const t=m();return o.$setFormatFromDOM(t,e),o.setNodeIndentFromDOM(e,t),o.$setDirectionFromDOM(t,e),{node:t}}function R(e="h1"){return o.$applyNodeReplacement(new O(e))}function f(e){let t=null;if(r.objectKlassEquals(e,DragEvent)?t=e.dataTransfer:r.objectKlassEquals(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,o=n.includes("Files"),i=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(t.files),i]}function M(e){const t=o.$getNearestNodeFromDOMNode(e);return o.$isDecoratorNode(t)}function _(e,t,n,r){let i=!1,s=null;if(e.isCollapsed()&&"text"===e.anchor.type){const t=e.anchor.getNode();if(o.$isTextNode(t)){s=t;const r=e.anchor.offset,o=r===t.getTextContentSize()&&null===t.getNextSibling(),a=0===r&&null===t.getPreviousSibling();i="end"===n&&o||"start"===n&&a||"both"===n&&(o||a)}}let a=!1;for(const[n,c]of Object.entries(r)){if(null==c||!c[t])continue;const r=n;if(c.onlyAtBoundary){if(!(i&&s&&o.$isTextNode(s)&&s.hasFormat(r)))continue;a=!0}e.hasFormat(r)&&e.toggleFormat(r)}a&&e.setStyle("")}const T={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function C(i,s=t.signal(T)){const a=r.mergeRegister(i.registerCommand(o.CLICK_COMMAND,()=>{const e=o.$getSelection();return o.$isNodeSelection(e)?(e.clear(),!0):(o.$isRangeSelection(e)&&_(e,"click","both",s.peek()),!1)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();return o.$isRangeSelection(t)?(t.deleteCharacter(e),!0):!!o.$isNodeSelection(t)&&(t.deleteNodes(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_WORD_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteWord(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DELETE_LINE_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteLine(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.CONTROLLED_TEXT_INSERTION_COMMAND,t=>{const n=o.$getSelection();if("string"==typeof t)null!==n&&n.insertText(t);else{if(null===n)return!1;const r=t.dataTransfer;if(null!=r)e.$insertDataTransferForRichText(r,n,i);else if(o.$isRangeSelection(n)){const e=t.data;return e&&n.insertText(e),!0}}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.REMOVE_TEXT_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.removeText(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.FORMAT_TEXT_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.formatText(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.FORMAT_ELEMENT_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t)&&!o.$isNodeSelection(t))return!1;const n=t.getNodes();for(const t of n){const n=r.$findMatchingParent(t,e=>o.$isElementNode(e)&&!e.isInline());null!==n&&n.setFormat(e)}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_LINE_BREAK_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.insertLineBreak(e),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_PARAGRAPH_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.insertParagraph(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INSERT_TAB_COMMAND,()=>{const e=o.$createTabNode(),t=o.$getSelection();return o.$isRangeSelection(t)&&(e.setFormat(t.format),e.setStyle(t.style)),o.$insertNodes([e]),!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.INDENT_CONTENT_COMMAND,()=>r.$handleIndentAndOutdent(e=>{const t=e.getIndent();e.setIndent(t+1)}),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.OUTDENT_CONTENT_COMMAND,()=>r.$handleIndentAndOutdent(e=>{const t=e.getIndent();t>0&&e.setIndent(Math.max(0,t-1))}),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_UP_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectPrevious(),!0}else if(o.$isRangeSelection(t)){const n=o.$getAdjacentNode(t.focus,!0);if(!e.shiftKey&&o.$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),e.preventDefault(),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_DOWN_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectNext(0,0),!0}else if(o.$isRangeSelection(t)){if(function(e){const t=e.focus;return"root"===t.key&&t.offset===o.$getRoot().getChildrenSize()}(t))return e.preventDefault(),!0;const n=o.$getAdjacentNode(t.focus,!1);if(!e.shiftKey&&o.$isDecoratorNode(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),e.preventDefault(),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_LEFT_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const r=t.getNodes();if(r.length>0)return e.preventDefault(),n.$isParentRTL(r[0])?r[0].selectNext(0,0):r[0].selectPrevious(),!0}if(!o.$isRangeSelection(t))return!1;if(e.shiftKey||_(t,"arrow","start",s.peek()),n.$shouldOverrideDefaultCharacterSelection(t,!0)){const r=e.shiftKey;return e.preventDefault(),n.$moveCharacter(t,r,!0),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ARROW_RIGHT_COMMAND,e=>{const t=o.$getSelection();if(o.$isNodeSelection(t)){const r=t.getNodes();if(r.length>0)return e.preventDefault(),n.$isParentRTL(r[0])?r[0].selectPrevious():r[0].selectNext(0,0),!0}if(!o.$isRangeSelection(t))return!1;if(e.shiftKey||_(t,"arrow","end",s.peek()),n.$shouldOverrideDefaultCharacterSelection(t,!1)){const r=e.shiftKey;return e.preventDefault(),n.$moveCharacter(t,r,!1),!0}return!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_BACKSPACE_COMMAND,e=>{if(M(e.target))return!1;const t=o.$getSelection();if(o.$isRangeSelection(t)){if(function(e){if(!e.isCollapsed())return!1;const{anchor:t}=e;if(0!==t.offset)return!1;const n=t.getNode();if(o.$isRootNode(n))return!1;const i=r.$getNearestBlockElementAncestorOrThrow(n);return i.getIndent()>0&&(i.is(n)||n.is(i.getFirstDescendant()))}(t))return e.preventDefault(),i.dispatchCommand(o.OUTDENT_CONTENT_COMMAND,void 0);if(o.IS_IOS&&"ko-KR"===navigator.language)return!1}else if(!o.$isNodeSelection(t))return!1;return e.preventDefault(),i.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_DELETE_COMMAND,e=>{if(M(e.target))return!1;const t=o.$getSelection();return!(!o.$isRangeSelection(t)&&!o.$isNodeSelection(t))&&(e.preventDefault(),i.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!1))},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ENTER_COMMAND,e=>{let t=o.$getSelection();if(o.$isNodeSelection(t)){const e=t.getNodes();1===e.length&&o.$isDecoratorNode(e[0])&&!e[0].isInline()&&(t=e[0].selectNext())}if(!o.$isRangeSelection(t))return!1;if(_(t,"enter","both",s.peek()),null!==e){if((o.IS_IOS||o.IS_SAFARI||o.IS_APPLE_WEBKIT)&&o.CAN_USE_BEFORE_INPUT)return!1;if(e.preventDefault(),e.shiftKey)return i.dispatchCommand(o.INSERT_LINE_BREAK_COMMAND,!1)}return i.dispatchCommand(o.INSERT_PARAGRAPH_COMMAND,void 0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_ESCAPE_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(i.blur(),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DROP_COMMAND,t=>{const[,n]=f(t);if(n.length>0){const r=t.clientX,s=t.clientY,a=e.caretFromPoint(r,s);if(null!==a){const{offset:e,node:t}=a,r=o.$getNearestNodeFromDOMNode(t);if(null!==r){const t=o.$createRangeSelection();if(o.$isTextNode(r))t.anchor.set(r.getKey(),e,"text"),t.focus.set(r.getKey(),e,"text");else{const e=r.getParentOrThrow().getKey(),n=r.getIndexWithinParent()+1;t.anchor.set(e,n,"element"),t.focus.set(e,n,"element")}const n=o.$normalizeSelection__EXPERIMENTAL(t);o.$setSelection(n)}i.dispatchCommand(d,n)}return t.preventDefault(),!0}return e.$handleRichTextDrop(t,i)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DRAGSTART_COMMAND,t=>{const[n]=f(t),r=o.$getSelection();return!(n&&!o.$isRangeSelection(r))&&(o.$isRangeSelection(r)&&!r.isCollapsed()&&null!==t.dataTransfer&&(e.setLexicalClipboardDataTransfer(t.dataTransfer,e.$getClipboardDataFromSelection(r)),e.$writeDragSourceToDataTransfer(t.dataTransfer,i)),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.DRAGOVER_COMMAND,t=>{const[n]=f(t),r=o.$getSelection();if(n&&!o.$isRangeSelection(r))return!1;const i=t.clientX,s=t.clientY,a=e.caretFromPoint(i,s);if(null!==a){const e=o.$getNearestNodeFromDOMNode(a.node);o.$isDecoratorNode(e)&&t.preventDefault()}return!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.SELECT_ALL_COMMAND,()=>(o.$selectAll(),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.COPY_COMMAND,t=>(e.copyToClipboard(i,r.objectKlassEquals(t,ClipboardEvent)?t:null),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.CUT_COMMAND,t=>(async function(t,n){await e.copyToClipboard(n,r.objectKlassEquals(t,ClipboardEvent)?t:null),n.update(()=>{const e=o.$getSelection();o.$isRangeSelection(e)?e.removeText():o.$isNodeSelection(e)&&e.getNodes().forEach(e=>e.remove())})}(t,i),!0),o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.PASTE_COMMAND,t=>{const[,n,s]=f(t);if(n.length>0&&!s)return i.dispatchCommand(d,n),!0;if(o.isDOMNode(t.target)&&o.isSelectionCapturedInDecoratorInput(t.target))return!1;return null!==o.$getSelection()&&(function(t,n){t.preventDefault(),n.update(()=>{const i=o.$getSelection(),s=r.objectKlassEquals(t,InputEvent)||r.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData;null!=s&&null!==i&&e.$insertDataTransferForRichText(s,i,n)},{tag:o.PASTE_TAG})}(t,i),!0)},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_SPACE_COMMAND,()=>{const e=o.$getSelection();return o.$isRangeSelection(e)&&_(e,"space","both",s.peek()),!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.KEY_TAB_COMMAND,()=>{const e=o.$getSelection();return o.$isRangeSelection(e)&&_(e,"tab","both",s.peek()),!1},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.MOVE_TO_END,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const{anchor:n}=t;if("element"!==n.type||0!==n.offset)return!1;const r=n.getNode();if(!o.$isElementNode(r))return!1;const i=r.getFirstChild();if(!o.$isDecoratorNode(i)||!i.isInline())return!1;const s=r.getLastDescendant();if(null==s||o.$isDecoratorNode(s))return!1;const a=r.getKey(),c=r.selectEnd();return e.shiftKey&&c.anchor.set(a,0,"element"),e.preventDefault(),e.stopPropagation(),!0},o.COMMAND_PRIORITY_EDITOR),i.registerCommand(o.MOVE_TO_START,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const{anchor:n,focus:i}=t,s=r.$findMatchingParent(i.getNode(),e=>o.$isElementNode(e)&&!e.isInline());if(null===s)return!1;const a=s.getFirstChild();if(!o.$isDecoratorNode(a)||!a.isInline())return!1;const c=s.getLastDescendant();if(null==c||o.$isDecoratorNode(c))return!1;if(r.$findMatchingParent(n.getNode(),e=>o.$isElementNode(e)&&!e.isInline())!==s)return!1;const l=s.getKey();return("element"!==i.type||i.key!==l||0!==i.offset)&&(t.focus.set(l,0,"element"),e.shiftKey||t.anchor.set(l,0,"element"),e.preventDefault(),e.stopPropagation(),!0)},o.COMMAND_PRIORITY_EDITOR));return a}exports.$createHeadingNode=R,exports.$createQuoteNode=m,exports.$isHeadingNode=function(e){return e instanceof O},exports.$isQuoteNode=function(e){return e instanceof g},exports.DRAG_DROP_PASTE=d,exports.HeadingNode=O,exports.QuoteNode=g,exports.RichTextExtension=c,exports.RichTextImportExtension=u,exports.RichTextImportRules=l,exports.eventFiles=f,exports.registerRichText=C;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$insertDataTransferForRichText as e,caretFromPoint as t,$handleRichTextDrop as n,setLexicalClipboardDataTransfer as r,$getClipboardDataFromSelection as o,$writeDragSourceToDataTransfer as s,copyToClipboard as i}from"@lexical/clipboard";import{NormalizeInlineElementsExtension as a,NormalizeTripleClickSelectionExtension as c,effect as l,namedSignals as u,signal as m}from"@lexical/extension";import{$isParentRTL as f,$shouldOverrideDefaultCharacterSelection as p,$moveCharacter as d}from"@lexical/selection";import{addClassNamesToElement as g,isHTMLElement as h,objectKlassEquals as C,mergeRegister as y,$findMatchingParent as x,$handleIndentAndOutdent as v,$getNearestBlockElementAncestorOrThrow as D}from"@lexical/utils";import{defineExtension as N,safeCast as b,shallowMergeConfig as T,configExtension as _,setNodeIndentFromDOM as F,$setFormatFromDOM as O,$setDirectionFromDOM as E,isHTMLElement as S,createCommand as k,$applyNodeReplacement as I,ElementNode as K,$createParagraphNode as w,CLICK_COMMAND as A,$getSelection as M,$isNodeSelection as P,$isRangeSelection as L,COMMAND_PRIORITY_EDITOR as z,DELETE_CHARACTER_COMMAND as J,DELETE_WORD_COMMAND as $,DELETE_LINE_COMMAND as q,CONTROLLED_TEXT_INSERTION_COMMAND as W,REMOVE_TEXT_COMMAND as R,FORMAT_TEXT_COMMAND as j,FORMAT_ELEMENT_COMMAND as B,$isElementNode as X,INSERT_LINE_BREAK_COMMAND as Y,INSERT_PARAGRAPH_COMMAND as G,INSERT_TAB_COMMAND as H,$createTabNode as Q,$insertNodes as U,INDENT_CONTENT_COMMAND as V,OUTDENT_CONTENT_COMMAND as Z,KEY_ARROW_UP_COMMAND as ee,$getAdjacentNode as te,$isDecoratorNode as ne,KEY_ARROW_DOWN_COMMAND as re,KEY_ARROW_LEFT_COMMAND as oe,KEY_ARROW_RIGHT_COMMAND as se,KEY_BACKSPACE_COMMAND as ie,IS_IOS as ae,KEY_DELETE_COMMAND as ce,KEY_ENTER_COMMAND as le,IS_SAFARI as ue,IS_APPLE_WEBKIT as me,CAN_USE_BEFORE_INPUT as fe,KEY_ESCAPE_COMMAND as pe,DROP_COMMAND as de,$getNearestNodeFromDOMNode as ge,$createRangeSelection as he,$isTextNode as Ce,$normalizeSelection__EXPERIMENTAL as ye,$setSelection as xe,DRAGSTART_COMMAND as ve,DRAGOVER_COMMAND as De,SELECT_ALL_COMMAND as Ne,$selectAll as be,COPY_COMMAND as Te,CUT_COMMAND as _e,PASTE_COMMAND as Fe,isDOMNode as Oe,isSelectionCapturedInDecoratorInput as Ee,KEY_SPACE_COMMAND as Se,KEY_TAB_COMMAND as ke,MOVE_TO_END as Ie,MOVE_TO_START as Ke,$getRoot as we,$isRootNode as Ae,PASTE_TAG as Me}from"lexical";import{DragonExtension as Pe}from"@lexical/dragon";import{CoreImportExtension as Le,DOMImportExtension as ze,defineImportRule as Je,sel as $e}from"@lexical/html";function qe(e,t){return e&&null!==t?T(e,t):t}const We=N({build:(e,t)=>u(t),config:b({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[Pe,a,c],mergeConfig:function(e,t){const n=T(e,t);return t.escapeFormatTriggers&&(n.escapeFormatTriggers=function(e,t){const n=T(e,t);for(const r of Object.keys(t))n[r]=qe(e[r],t[r]);return n}(e.escapeFormatTriggers,t.escapeFormatTriggers)),n},name:"@lexical/rich-text",nodes:()=>[He,Xe],register:(e,t,n)=>l(()=>st(e,n.getOutput().escapeFormatTriggers))});const Re=[Je({$import:(e,t)=>{const n=Ze(t.nodeName.toLowerCase());return F(t,n),O(n,t),E(n,t),[n.splice(0,0,e.$importChildren(t))]},match:$e.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),Je({$import:(e,t)=>{const n=Ye();return O(n,t),F(t,n),E(n,t),[n.splice(0,0,e.$importChildren(t))]},match:$e.tag("blockquote"),name:"@lexical/rich-text/blockquote"}),Je({$import:(e,t,n)=>{const r=t.firstChild;return r&&(S(o=r)&&"SPAN"===o.nodeName&&"26pt"===o.style.fontSize)?e.$importChildren(t):n();var o},match:$e.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),Je({$import:(e,t,n)=>"26pt"!==t.style.fontSize?n():[Ze("h1").splice(0,0,e.$importChildren(t))],match:$e.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})],je=N({dependencies:[Le,We,_(ze,{rules:Re})],name:"@lexical/rich-text/Import"}),Be=k("DRAG_DROP_PASTE_FILE");class Xe extends K{static getType(){return"quote"}static clone(e){return new Xe(e.__key)}createDOM(e){const t=document.createElement("blockquote");return g(t,e.theme.quote),t}updateDOM(e,t){return!1}static importDOM(){return{blockquote:e=>({conversion:Ve,priority:0})}}exportDOM(e){const{element:t}=super.exportDOM(e);if(h(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return Ye().updateFromJSON(e)}insertNewAfter(e,t){const n=w(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,t),n}collapseAtStart(){const e=w();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}}function Ye(){return I(new Xe)}function Ge(e){return e instanceof Xe}class He extends K{__tag;static getType(){return"heading"}static clone(e){return new He(e.__tag,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,n=document.createElement(t),r=e.theme.heading;if(void 0!==r){const e=r[t];g(n,e)}return n}updateDOM(e,t,n){return e.__tag!==this.__tag}static importDOM(){return{h1:e=>({conversion:Ue,priority:0}),h2:e=>({conversion:Ue,priority:0}),h3:e=>({conversion:Ue,priority:0}),h4:e=>({conversion:Ue,priority:0}),h5:e=>({conversion:Ue,priority:0}),h6:e=>({conversion:Ue,priority:0}),p:e=>{const t=e.firstChild;return null!==t&&Qe(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>Qe(e)?{conversion:e=>({node:Ze("h1")}),priority:3}:null}}exportDOM(e){const{element:t}=super.exportDOM(e);if(h(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return Ze(e.tag).updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const n=e?e.anchor.offset:0,r=this.getLastDescendant(),o=!r||e&&e.anchor.key===r.getKey()&&n===r.getTextContentSize()||!e?w():Ze(this.getTag()),s=this.getDirection();if(o.setDirection(s),this.insertAfter(o,t),0===n&&!this.isEmpty()&&e){const e=w();e.select(),this.replace(e,!0)}return o}collapseAtStart(){if(this.isEmpty()){const e=w();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}}function Qe(e){return"span"===e.nodeName.toLowerCase()&&"26pt"===e.style.fontSize}function Ue(e){const t=e.nodeName.toLowerCase();let n=null;return"h1"!==t&&"h2"!==t&&"h3"!==t&&"h4"!==t&&"h5"!==t&&"h6"!==t||(n=Ze(t),F(e,n),O(n,e),E(n,e)),{node:n}}function Ve(e){const t=Ye();return O(t,e),F(e,t),E(t,e),{node:t}}function Ze(e="h1"){return I(new He(e))}function et(e){return e instanceof He}function tt(e){let t=null;if(C(e,DragEvent)?t=e.dataTransfer:C(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(t.files),o]}function nt(e){const t=ge(e);return ne(t)}function rt(e,t,n,r){let o=!1,s=null;if(e.isCollapsed()&&"text"===e.anchor.type){const t=e.anchor.getNode();if(Ce(t)){s=t;const r=e.anchor.offset,i=r===t.getTextContentSize()&&null===t.getNextSibling(),a=0===r&&null===t.getPreviousSibling();o="end"===n&&i||"start"===n&&a||"both"===n&&(i||a)}}let i=!1;for(const[n,a]of Object.entries(r)){if(null==a||!a[t])continue;const r=n;if(a.onlyAtBoundary){if(!(o&&s&&Ce(s)&&s.hasFormat(r)))continue;i=!0}e.hasFormat(r)&&e.toggleFormat(r)}i&&e.setStyle("")}const ot={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function st(a,c=m(ot)){return y(a.registerCommand(A,()=>{const e=M();return P(e)?(e.clear(),!0):(L(e)&&rt(e,"click","both",c.peek()),!1)},z),a.registerCommand(J,e=>{const t=M();return L(t)?(t.deleteCharacter(e),!0):!!P(t)&&(t.deleteNodes(),!0)},z),a.registerCommand($,e=>{const t=M();return!!L(t)&&(t.deleteWord(e),!0)},z),a.registerCommand(q,e=>{const t=M();return!!L(t)&&(t.deleteLine(e),!0)},z),a.registerCommand(W,t=>{const n=M();if("string"==typeof t)null!==n&&n.insertText(t);else{if(null===n)return!1;const r=t.dataTransfer;if(null!=r)e(r,n,a);else if(L(n)){const e=t.data;return e&&n.insertText(e),!0}}return!0},z),a.registerCommand(R,()=>{const e=M();return!!L(e)&&(e.removeText(),!0)},z),a.registerCommand(j,e=>{const t=M();return!!L(t)&&(t.formatText(e),!0)},z),a.registerCommand(B,e=>{const t=M();if(!L(t)&&!P(t))return!1;const n=t.getNodes();for(const t of n){const n=x(t,e=>X(e)&&!e.isInline());null!==n&&n.setFormat(e)}return!0},z),a.registerCommand(Y,e=>{const t=M();return!!L(t)&&(t.insertLineBreak(e),!0)},z),a.registerCommand(G,()=>{const e=M();return!!L(e)&&(e.insertParagraph(),!0)},z),a.registerCommand(H,()=>{const e=Q(),t=M();return L(t)&&(e.setFormat(t.format),e.setStyle(t.style)),U([e]),!0},z),a.registerCommand(V,()=>v(e=>{const t=e.getIndent();e.setIndent(t+1)}),z),a.registerCommand(Z,()=>v(e=>{const t=e.getIndent();t>0&&e.setIndent(Math.max(0,t-1))}),z),a.registerCommand(ee,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectPrevious(),!0}else if(L(t)){const n=te(t.focus,!0);if(!e.shiftKey&&ne(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),e.preventDefault(),!0}return!1},z),a.registerCommand(re,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectNext(0,0),!0}else if(L(t)){if(function(e){const t=e.focus;return"root"===t.key&&t.offset===we().getChildrenSize()}(t))return e.preventDefault(),!0;const n=te(t.focus,!1);if(!e.shiftKey&&ne(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),e.preventDefault(),!0}return!1},z),a.registerCommand(oe,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),f(n[0])?n[0].selectNext(0,0):n[0].selectPrevious(),!0}if(!L(t))return!1;if(e.shiftKey||rt(t,"arrow","start",c.peek()),p(t,!0)){const n=e.shiftKey;return e.preventDefault(),d(t,n,!0),!0}return!1},z),a.registerCommand(se,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),f(n[0])?n[0].selectPrevious():n[0].selectNext(0,0),!0}if(!L(t))return!1;if(e.shiftKey||rt(t,"arrow","end",c.peek()),p(t,!1)){const n=e.shiftKey;return e.preventDefault(),d(t,n,!1),!0}return!1},z),a.registerCommand(ie,e=>{if(nt(e.target))return!1;const t=M();if(L(t)){if(function(e){if(!e.isCollapsed())return!1;const{anchor:t}=e;if(0!==t.offset)return!1;const n=t.getNode();if(Ae(n))return!1;const r=D(n);return r.getIndent()>0&&(r.is(n)||n.is(r.getFirstDescendant()))}(t))return e.preventDefault(),a.dispatchCommand(Z,void 0);if(ae&&"ko-KR"===navigator.language)return!1}else if(!P(t))return!1;return e.preventDefault(),a.dispatchCommand(J,!0)},z),a.registerCommand(ce,e=>{if(nt(e.target))return!1;const t=M();return!(!L(t)&&!P(t))&&(e.preventDefault(),a.dispatchCommand(J,!1))},z),a.registerCommand(le,e=>{let t=M();if(P(t)){const e=t.getNodes();1===e.length&&ne(e[0])&&!e[0].isInline()&&(t=e[0].selectNext())}if(!L(t))return!1;if(rt(t,"enter","both",c.peek()),null!==e){if((ae||ue||me)&&fe)return!1;if(e.preventDefault(),e.shiftKey)return a.dispatchCommand(Y,!1)}return a.dispatchCommand(G,void 0)},z),a.registerCommand(pe,()=>{const e=M();return!!L(e)&&(a.blur(),!0)},z),a.registerCommand(de,e=>{const[,r]=tt(e);if(r.length>0){const n=e.clientX,o=e.clientY,s=t(n,o);if(null!==s){const{offset:e,node:t}=s,n=ge(t);if(null!==n){const t=he();if(Ce(n))t.anchor.set(n.getKey(),e,"text"),t.focus.set(n.getKey(),e,"text");else{const e=n.getParentOrThrow().getKey(),r=n.getIndexWithinParent()+1;t.anchor.set(e,r,"element"),t.focus.set(e,r,"element")}const r=ye(t);xe(r)}a.dispatchCommand(Be,r)}return e.preventDefault(),!0}return n(e,a)},z),a.registerCommand(ve,e=>{const[t]=tt(e),n=M();return!(t&&!L(n))&&(L(n)&&!n.isCollapsed()&&null!==e.dataTransfer&&(r(e.dataTransfer,o(n)),s(e.dataTransfer,a)),!0)},z),a.registerCommand(De,e=>{const[n]=tt(e),r=M();if(n&&!L(r))return!1;const o=e.clientX,s=e.clientY,i=t(o,s);if(null!==i){const t=ge(i.node);ne(t)&&e.preventDefault()}return!0},z),a.registerCommand(Ne,()=>(be(),!0),z),a.registerCommand(Te,e=>(i(a,C(e,ClipboardEvent)?e:null),!0),z),a.registerCommand(_e,e=>(async function(e,t){await i(t,C(e,ClipboardEvent)?e:null),t.update(()=>{const e=M();L(e)?e.removeText():P(e)&&e.getNodes().forEach(e=>e.remove())})}(e,a),!0),z),a.registerCommand(Fe,t=>{const[,n,r]=tt(t);if(n.length>0&&!r)return a.dispatchCommand(Be,n),!0;if(Oe(t.target)&&Ee(t.target))return!1;return null!==M()&&(function(t,n){t.preventDefault(),n.update(()=>{const r=M(),o=C(t,InputEvent)||C(t,KeyboardEvent)?null:t.clipboardData;null!=o&&null!==r&&e(o,r,n)},{tag:Me})}(t,a),!0)},z),a.registerCommand(Se,()=>{const e=M();return L(e)&&rt(e,"space","both",c.peek()),!1},z),a.registerCommand(ke,()=>{const e=M();return L(e)&&rt(e,"tab","both",c.peek()),!1},z),a.registerCommand(Ie,e=>{const t=M();if(!L(t))return!1;const{anchor:n}=t;if("element"!==n.type||0!==n.offset)return!1;const r=n.getNode();if(!X(r))return!1;const o=r.getFirstChild();if(!ne(o)||!o.isInline())return!1;const s=r.getLastDescendant();if(null==s||ne(s))return!1;const i=r.getKey(),a=r.selectEnd();return e.shiftKey&&a.anchor.set(i,0,"element"),e.preventDefault(),e.stopPropagation(),!0},z),a.registerCommand(Ke,e=>{const t=M();if(!L(t))return!1;const{anchor:n,focus:r}=t,o=x(r.getNode(),e=>X(e)&&!e.isInline());if(null===o)return!1;const s=o.getFirstChild();if(!ne(s)||!s.isInline())return!1;const i=o.getLastDescendant();if(null==i||ne(i))return!1;if(x(n.getNode(),e=>X(e)&&!e.isInline())!==o)return!1;const a=o.getKey();return("element"!==r.type||r.key!==a||0!==r.offset)&&(t.focus.set(a,0,"element"),e.shiftKey||t.anchor.set(a,0,"element"),e.preventDefault(),e.stopPropagation(),!0)},z))}export{Ze as $createHeadingNode,Ye as $createQuoteNode,et as $isHeadingNode,Ge as $isQuoteNode,Be as DRAG_DROP_PASTE,He as HeadingNode,Xe as QuoteNode,We as RichTextExtension,je as RichTextImportExtension,Re as RichTextImportRules,tt as eventFiles,st as registerRichText};
|
|
9
|
+
import{$insertDataTransferForRichText as e,caretFromPoint as t,$handleRichTextDrop as n,setLexicalClipboardDataTransfer as r,$getClipboardDataFromSelection as o,$writeDragSourceToDataTransfer as s,copyToClipboard as i}from"@lexical/clipboard";import{NormalizeInlineElementsExtension as a,NormalizeTripleClickSelectionExtension as c,effect as l,namedSignals as u,signal as m}from"@lexical/extension";import{$isParentRTL as f,$shouldOverrideDefaultCharacterSelection as p,$moveCharacter as d}from"@lexical/selection";import{addClassNamesToElement as g,isHTMLElement as h,objectKlassEquals as C,mergeRegister as y,$findMatchingParent as x,$handleIndentAndOutdent as v,$getNearestBlockElementAncestorOrThrow as D}from"@lexical/utils";import{defineExtension as N,safeCast as b,shallowMergeConfig as T,configExtension as _,setNodeIndentFromDOM as F,$setFormatFromDOM as O,$setDirectionFromDOM as E,isHTMLElement as S,createCommand as k,$applyNodeReplacement as I,ElementNode as K,$createParagraphNode as w,CLICK_COMMAND as A,$getSelection as M,$isNodeSelection as P,$isRangeSelection as L,COMMAND_PRIORITY_EDITOR as z,DELETE_CHARACTER_COMMAND as J,DELETE_WORD_COMMAND as $,DELETE_LINE_COMMAND as q,CONTROLLED_TEXT_INSERTION_COMMAND as W,REMOVE_TEXT_COMMAND as R,FORMAT_TEXT_COMMAND as j,FORMAT_ELEMENT_COMMAND as B,$isElementNode as X,INSERT_LINE_BREAK_COMMAND as Y,INSERT_PARAGRAPH_COMMAND as G,INSERT_TAB_COMMAND as H,$createTabNode as Q,$insertNodes as U,INDENT_CONTENT_COMMAND as V,OUTDENT_CONTENT_COMMAND as Z,KEY_ARROW_UP_COMMAND as ee,$getAdjacentNode as te,$isDecoratorNode as ne,KEY_ARROW_DOWN_COMMAND as re,KEY_ARROW_LEFT_COMMAND as oe,KEY_ARROW_RIGHT_COMMAND as se,KEY_BACKSPACE_COMMAND as ie,IS_IOS as ae,KEY_DELETE_COMMAND as ce,KEY_ENTER_COMMAND as le,IS_SAFARI as ue,IS_APPLE_WEBKIT as me,CAN_USE_BEFORE_INPUT as fe,KEY_ESCAPE_COMMAND as pe,DROP_COMMAND as de,$getNearestNodeFromDOMNode as ge,$createRangeSelection as he,$isTextNode as Ce,$normalizeSelection__EXPERIMENTAL as ye,$setSelection as xe,DRAGSTART_COMMAND as ve,DRAGOVER_COMMAND as De,SELECT_ALL_COMMAND as Ne,$selectAll as be,COPY_COMMAND as Te,CUT_COMMAND as _e,PASTE_COMMAND as Fe,isDOMNode as Oe,isSelectionCapturedInDecoratorInput as Ee,KEY_SPACE_COMMAND as Se,KEY_TAB_COMMAND as ke,MOVE_TO_END as Ie,MOVE_TO_START as Ke,$getRoot as we,$isRootNode as Ae,PASTE_TAG as Me}from"lexical";import{DragonExtension as Pe}from"@lexical/dragon";import{DOMImportExtension as Le,defineImportRule as ze,sel as Je}from"@lexical/html";function $e(e,t){return e&&null!==t?T(e,t):t}const qe=N({build:(e,t)=>u(t),config:b({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[Pe,a,c],mergeConfig:function(e,t){const n=T(e,t);return t.escapeFormatTriggers&&(n.escapeFormatTriggers=function(e,t){const n=T(e,t);for(const r of Object.keys(t))n[r]=$e(e[r],t[r]);return n}(e.escapeFormatTriggers,t.escapeFormatTriggers)),n},name:"@lexical/rich-text",nodes:()=>[Ge,Be],register:(e,t,n)=>l(()=>ot(e,n.getOutput().escapeFormatTriggers))});const We=[ze({$import:(e,t)=>{const n=Ve(t.nodeName.toLowerCase());return F(t,n),O(n,t),E(n,t),[n.splice(0,0,e.$importChildren(t))]},match:Je.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),ze({$import:(e,t)=>{const n=Xe();return O(n,t),F(t,n),E(n,t),[n.splice(0,0,e.$importChildren(t))]},match:Je.tag("blockquote"),name:"@lexical/rich-text/blockquote"}),ze({$import:(e,t,n)=>{const r=t.firstChild;return r&&(S(o=r)&&"SPAN"===o.nodeName&&"26pt"===o.style.fontSize)?e.$importChildren(t):n();var o},match:Je.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),ze({$import:(e,t,n)=>"26pt"!==t.style.fontSize?n():[Ve("h1").splice(0,0,e.$importChildren(t))],match:Je.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})],Re=N({dependencies:[qe,_(Le,{rules:We})],name:"@lexical/rich-text/Import"}),je=k("DRAG_DROP_PASTE_FILE");class Be extends K{static getType(){return"quote"}static clone(e){return new Be(e.__key)}createDOM(e){const t=document.createElement("blockquote");return g(t,e.theme.quote),t}updateDOM(e,t){return!1}static importDOM(){return{blockquote:e=>({conversion:Ue,priority:0})}}exportDOM(e){const{element:t}=super.exportDOM(e);if(h(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return Xe().updateFromJSON(e)}insertNewAfter(e,t){const n=w(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,t),n}collapseAtStart(){const e=w();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}}function Xe(){return I(new Be)}function Ye(e){return e instanceof Be}class Ge extends K{__tag;static getType(){return"heading"}static clone(e){return new Ge(e.__tag,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,n=document.createElement(t),r=e.theme.heading;if(void 0!==r){const e=r[t];g(n,e)}return n}updateDOM(e,t,n){return e.__tag!==this.__tag}static importDOM(){return{h1:e=>({conversion:Qe,priority:0}),h2:e=>({conversion:Qe,priority:0}),h3:e=>({conversion:Qe,priority:0}),h4:e=>({conversion:Qe,priority:0}),h5:e=>({conversion:Qe,priority:0}),h6:e=>({conversion:Qe,priority:0}),p:e=>{const t=e.firstChild;return null!==t&&He(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>He(e)?{conversion:e=>({node:Ve("h1")}),priority:3}:null}}exportDOM(e){const{element:t}=super.exportDOM(e);if(h(t)){this.isEmpty()&&t.append(document.createElement("br"));const e=this.getFormatType();e&&(t.style.textAlign=e);const n=this.getDirection();n&&(t.dir=n)}return{element:t}}static importJSON(e){return Ve(e.tag).updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const n=e?e.anchor.offset:0,r=this.getLastDescendant(),o=!r||e&&e.anchor.key===r.getKey()&&n===r.getTextContentSize()||!e?w():Ve(this.getTag()),s=this.getDirection();if(o.setDirection(s),this.insertAfter(o,t),0===n&&!this.isEmpty()&&e){const e=w();e.select(),this.replace(e,!0)}return o}collapseAtStart(){if(this.isEmpty()){const e=w();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}}function He(e){return"span"===e.nodeName.toLowerCase()&&"26pt"===e.style.fontSize}function Qe(e){const t=e.nodeName.toLowerCase();let n=null;return"h1"!==t&&"h2"!==t&&"h3"!==t&&"h4"!==t&&"h5"!==t&&"h6"!==t||(n=Ve(t),F(e,n),O(n,e),E(n,e)),{node:n}}function Ue(e){const t=Xe();return O(t,e),F(e,t),E(t,e),{node:t}}function Ve(e="h1"){return I(new Ge(e))}function Ze(e){return e instanceof Ge}function et(e){let t=null;if(C(e,DragEvent)?t=e.dataTransfer:C(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(t.files),o]}function tt(e){const t=ge(e);return ne(t)}function nt(e,t,n,r){let o=!1,s=null;if(e.isCollapsed()&&"text"===e.anchor.type){const t=e.anchor.getNode();if(Ce(t)){s=t;const r=e.anchor.offset,i=r===t.getTextContentSize()&&null===t.getNextSibling(),a=0===r&&null===t.getPreviousSibling();o="end"===n&&i||"start"===n&&a||"both"===n&&(i||a)}}let i=!1;for(const[n,a]of Object.entries(r)){if(null==a||!a[t])continue;const r=n;if(a.onlyAtBoundary){if(!(o&&s&&Ce(s)&&s.hasFormat(r)))continue;i=!0}e.hasFormat(r)&&e.toggleFormat(r)}i&&e.setStyle("")}const rt={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function ot(a,c=m(rt)){return y(a.registerCommand(A,()=>{const e=M();return P(e)?(e.clear(),!0):(L(e)&&nt(e,"click","both",c.peek()),!1)},z),a.registerCommand(J,e=>{const t=M();return L(t)?(t.deleteCharacter(e),!0):!!P(t)&&(t.deleteNodes(),!0)},z),a.registerCommand($,e=>{const t=M();return!!L(t)&&(t.deleteWord(e),!0)},z),a.registerCommand(q,e=>{const t=M();return!!L(t)&&(t.deleteLine(e),!0)},z),a.registerCommand(W,t=>{const n=M();if("string"==typeof t)null!==n&&n.insertText(t);else{if(null===n)return!1;const r=t.dataTransfer;if(null!=r)e(r,n,a);else if(L(n)){const e=t.data;return e&&n.insertText(e),!0}}return!0},z),a.registerCommand(R,()=>{const e=M();return!!L(e)&&(e.removeText(),!0)},z),a.registerCommand(j,e=>{const t=M();return!!L(t)&&(t.formatText(e),!0)},z),a.registerCommand(B,e=>{const t=M();if(!L(t)&&!P(t))return!1;const n=t.getNodes();for(const t of n){const n=x(t,e=>X(e)&&!e.isInline());null!==n&&n.setFormat(e)}return!0},z),a.registerCommand(Y,e=>{const t=M();return!!L(t)&&(t.insertLineBreak(e),!0)},z),a.registerCommand(G,()=>{const e=M();return!!L(e)&&(e.insertParagraph(),!0)},z),a.registerCommand(H,()=>{const e=Q(),t=M();return L(t)&&(e.setFormat(t.format),e.setStyle(t.style)),U([e]),!0},z),a.registerCommand(V,()=>v(e=>{const t=e.getIndent();e.setIndent(t+1)}),z),a.registerCommand(Z,()=>v(e=>{const t=e.getIndent();t>0&&e.setIndent(Math.max(0,t-1))}),z),a.registerCommand(ee,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectPrevious(),!0}else if(L(t)){const n=te(t.focus,!0);if(!e.shiftKey&&ne(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),e.preventDefault(),!0}return!1},z),a.registerCommand(re,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),n[0].selectNext(0,0),!0}else if(L(t)){if(function(e){const t=e.focus;return"root"===t.key&&t.offset===we().getChildrenSize()}(t))return e.preventDefault(),!0;const n=te(t.focus,!1);if(!e.shiftKey&&ne(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),e.preventDefault(),!0}return!1},z),a.registerCommand(oe,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),f(n[0])?n[0].selectNext(0,0):n[0].selectPrevious(),!0}if(!L(t))return!1;if(e.shiftKey||nt(t,"arrow","start",c.peek()),p(t,!0)){const n=e.shiftKey;return e.preventDefault(),d(t,n,!0),!0}return!1},z),a.registerCommand(se,e=>{const t=M();if(P(t)){const n=t.getNodes();if(n.length>0)return e.preventDefault(),f(n[0])?n[0].selectPrevious():n[0].selectNext(0,0),!0}if(!L(t))return!1;if(e.shiftKey||nt(t,"arrow","end",c.peek()),p(t,!1)){const n=e.shiftKey;return e.preventDefault(),d(t,n,!1),!0}return!1},z),a.registerCommand(ie,e=>{if(tt(e.target))return!1;const t=M();if(L(t)){if(function(e){if(!e.isCollapsed())return!1;const{anchor:t}=e;if(0!==t.offset)return!1;const n=t.getNode();if(Ae(n))return!1;const r=D(n);return r.getIndent()>0&&(r.is(n)||n.is(r.getFirstDescendant()))}(t))return e.preventDefault(),a.dispatchCommand(Z,void 0);if(ae&&"ko-KR"===navigator.language)return!1}else if(!P(t))return!1;return e.preventDefault(),a.dispatchCommand(J,!0)},z),a.registerCommand(ce,e=>{if(tt(e.target))return!1;const t=M();return!(!L(t)&&!P(t))&&(e.preventDefault(),a.dispatchCommand(J,!1))},z),a.registerCommand(le,e=>{let t=M();if(P(t)){const e=t.getNodes();1===e.length&&ne(e[0])&&!e[0].isInline()&&(t=e[0].selectNext())}if(!L(t))return!1;if(nt(t,"enter","both",c.peek()),null!==e){if((ae||ue||me)&&fe)return!1;if(e.preventDefault(),e.shiftKey)return a.dispatchCommand(Y,!1)}return a.dispatchCommand(G,void 0)},z),a.registerCommand(pe,()=>{const e=M();return!!L(e)&&(a.blur(),!0)},z),a.registerCommand(de,e=>{const[,r]=et(e);if(r.length>0){const n=e.clientX,o=e.clientY,s=t(n,o);if(null!==s){const{offset:e,node:t}=s,n=ge(t);if(null!==n){const t=he();if(Ce(n))t.anchor.set(n.getKey(),e,"text"),t.focus.set(n.getKey(),e,"text");else{const e=n.getParentOrThrow().getKey(),r=n.getIndexWithinParent()+1;t.anchor.set(e,r,"element"),t.focus.set(e,r,"element")}const r=ye(t);xe(r)}a.dispatchCommand(je,r)}return e.preventDefault(),!0}return n(e,a)},z),a.registerCommand(ve,e=>{const[t]=et(e),n=M();return!(t&&!L(n))&&(L(n)&&!n.isCollapsed()&&null!==e.dataTransfer&&(r(e.dataTransfer,o(n)),s(e.dataTransfer,a)),!0)},z),a.registerCommand(De,e=>{const[n]=et(e),r=M();if(n&&!L(r))return!1;const o=e.clientX,s=e.clientY,i=t(o,s);if(null!==i){const t=ge(i.node);ne(t)&&e.preventDefault()}return!0},z),a.registerCommand(Ne,()=>(be(),!0),z),a.registerCommand(Te,e=>(i(a,C(e,ClipboardEvent)?e:null),!0),z),a.registerCommand(_e,e=>(async function(e,t){await i(t,C(e,ClipboardEvent)?e:null),t.update(()=>{const e=M();L(e)?e.removeText():P(e)&&e.getNodes().forEach(e=>e.remove())})}(e,a),!0),z),a.registerCommand(Fe,t=>{const[,n,r]=et(t);if(n.length>0&&!r)return a.dispatchCommand(je,n),!0;if(Oe(t.target)&&Ee(t.target))return!1;return null!==M()&&(function(t,n){t.preventDefault(),n.update(()=>{const r=M(),o=C(t,InputEvent)||C(t,KeyboardEvent)?null:t.clipboardData;null!=o&&null!==r&&e(o,r,n)},{tag:Me})}(t,a),!0)},z),a.registerCommand(Se,()=>{const e=M();return L(e)&&nt(e,"space","both",c.peek()),!1},z),a.registerCommand(ke,()=>{const e=M();return L(e)&&nt(e,"tab","both",c.peek()),!1},z),a.registerCommand(Ie,e=>{const t=M();if(!L(t))return!1;const{anchor:n}=t;if("element"!==n.type||0!==n.offset)return!1;const r=n.getNode();if(!X(r))return!1;const o=r.getFirstChild();if(!ne(o)||!o.isInline())return!1;const s=r.getLastDescendant();if(null==s||ne(s))return!1;const i=r.getKey(),a=r.selectEnd();return e.shiftKey&&a.anchor.set(i,0,"element"),e.preventDefault(),e.stopPropagation(),!0},z),a.registerCommand(Ke,e=>{const t=M();if(!L(t))return!1;const{anchor:n,focus:r}=t,o=x(r.getNode(),e=>X(e)&&!e.isInline());if(null===o)return!1;const s=o.getFirstChild();if(!ne(s)||!s.isInline())return!1;const i=o.getLastDescendant();if(null==i||ne(i))return!1;if(x(n.getNode(),e=>X(e)&&!e.isInline())!==o)return!1;const a=o.getKey();return("element"!==r.type||r.key!==a||0!==r.offset)&&(t.focus.set(a,0,"element"),e.shiftKey||t.anchor.set(a,0,"element"),e.preventDefault(),e.stopPropagation(),!0)},z))}export{Ve as $createHeadingNode,Xe as $createQuoteNode,Ze as $isHeadingNode,Ye as $isQuoteNode,je as DRAG_DROP_PASTE,Ge as HeadingNode,Be as QuoteNode,qe as RichTextExtension,Re as RichTextImportExtension,We as RichTextImportRules,et as eventFiles,ot as registerRichText};
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export declare const RichTextImportRules: import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLSpanElement, Record<string, never>>>[];
|
|
18
18
|
/**
|
|
19
|
-
* Bundles {@link RichTextImportRules}
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* Bundles {@link RichTextImportRules} together with the runtime
|
|
20
|
+
* {@link RichTextExtension}. The application is expected to already
|
|
21
|
+
* have `CoreImportExtension` (or some equivalent) in its dependency
|
|
22
|
+
* graph — the core/text/paragraph/inline-format rules are a shared
|
|
23
|
+
* baseline, not something this leaf importer should re-declare.
|
|
23
24
|
*
|
|
24
25
|
* @experimental
|
|
25
26
|
*/
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.45.0",
|
|
10
|
+
"version": "0.45.1-dev.0",
|
|
11
11
|
"main": "./dist/LexicalRichText.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"repository": {
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@lexical/
|
|
40
|
-
"@lexical/
|
|
41
|
-
"@lexical/
|
|
42
|
-
"@lexical/html": "0.45.0",
|
|
43
|
-
"@lexical/
|
|
44
|
-
"
|
|
45
|
-
"lexical": "0.45.0"
|
|
39
|
+
"@lexical/clipboard": "0.45.1-dev.0",
|
|
40
|
+
"@lexical/dragon": "0.45.1-dev.0",
|
|
41
|
+
"@lexical/extension": "0.45.1-dev.0",
|
|
42
|
+
"@lexical/html": "0.45.1-dev.0",
|
|
43
|
+
"@lexical/selection": "0.45.1-dev.0",
|
|
44
|
+
"lexical": "0.45.1-dev.0",
|
|
45
|
+
"@lexical/utils": "0.45.1-dev.0"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"dist",
|
|
@@ -6,12 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
CoreImportExtension,
|
|
11
|
-
defineImportRule,
|
|
12
|
-
DOMImportExtension,
|
|
13
|
-
sel,
|
|
14
|
-
} from '@lexical/html';
|
|
9
|
+
import {defineImportRule, DOMImportExtension, sel} from '@lexical/html';
|
|
15
10
|
import {
|
|
16
11
|
$setDirectionFromDOM,
|
|
17
12
|
$setFormatFromDOM,
|
|
@@ -112,16 +107,16 @@ export const RichTextImportRules = [
|
|
|
112
107
|
];
|
|
113
108
|
|
|
114
109
|
/**
|
|
115
|
-
* Bundles {@link RichTextImportRules}
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
110
|
+
* Bundles {@link RichTextImportRules} together with the runtime
|
|
111
|
+
* {@link RichTextExtension}. The application is expected to already
|
|
112
|
+
* have `CoreImportExtension` (or some equivalent) in its dependency
|
|
113
|
+
* graph — the core/text/paragraph/inline-format rules are a shared
|
|
114
|
+
* baseline, not something this leaf importer should re-declare.
|
|
119
115
|
*
|
|
120
116
|
* @experimental
|
|
121
117
|
*/
|
|
122
118
|
export const RichTextImportExtension = defineExtension({
|
|
123
119
|
dependencies: [
|
|
124
|
-
CoreImportExtension,
|
|
125
120
|
RichTextExtension,
|
|
126
121
|
configExtension(DOMImportExtension, {rules: RichTextImportRules}),
|
|
127
122
|
],
|