@lexical/html 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.
- package/dist/LexicalHtml.dev.js +308 -211
- package/dist/LexicalHtml.dev.mjs +309 -213
- package/dist/LexicalHtml.mjs +1 -0
- package/dist/LexicalHtml.node.mjs +1 -0
- package/dist/LexicalHtml.prod.js +1 -1
- package/dist/LexicalHtml.prod.mjs +1 -1
- package/dist/import/HorizontalRuleImportExtension.d.ts +6 -5
- package/dist/import/coreImportRules.d.ts +1 -1
- package/dist/import/index.d.ts +1 -1
- package/dist/import/schemas.d.ts +15 -0
- package/dist/index.d.ts +1 -1
- package/package.json +6 -6
- package/src/import/HorizontalRuleImportExtension.ts +6 -7
- package/src/import/coreImportRules.ts +61 -1
- package/src/import/index.ts +1 -0
- package/src/import/schemas.ts +44 -0
- package/src/index.ts +6 -0
package/dist/LexicalHtml.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/selection"),t=require("lexical"),n=require("@lexical/utils"),o=require("@lexical/extension");function r(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let s;function i(e,t){const{key:n}=t;return e&&n in e?e[n]:t.defaultValue}function c(e){return s&&s.editor===e?s:void 0}function l(e,t){const n=c(t);return n&&n[e]}function u(e,t){if("cfg"in t){const{cfg:n,updater:o}=t;return[n,o(i(e,n))]}return t}function a(e,t){let n=t;for(const o of e){const[e,r]=u(n,o),s=e.key;if(n===t&&i(n,e)===r)continue;const c=n===t||void 0===n?f(t):n;c[s]=r,n=c}return n}function f(e){return Object.create(e||null)}function d(e,t){return[e,t]}function p(e,n,o,r=t.$getEditor()){const i=s,l=c(r);try{return s={...l,editor:r,[e]:n},o()}finally{s=i}}function h(e,n=()=>{}){return(o,r=t.$getEditor())=>t=>{const s=c(r),i=s&&s[e],l=a(o,i||n(r));return l&&l!==i?p(e,l,t,r):t()}}function m(e,n,o,r){return Object.assign(t.createState(Symbol(n),{isEqual:r,parse:o}),{[e]:!0})}const g=(e,t,n)=>{x(e),n()};function x(e){if(!t.isDOMDocumentNode(e))return;const o=e;if(null===o.querySelector("style"))return;const r=new Map;function s(e){let t=r.get(e);if(void 0===t){t=new Set;for(let n=0;n<e.style.length;n++)t.add(e.style[n]);r.set(e,t)}return t}try{for(const e of Array.from(o.styleSheets)){let r;try{r=e.cssRules}catch(e){continue}for(const e of Array.from(r)){if(!n.objectKlassEquals(e,CSSStyleRule))continue;let r;try{r=o.querySelectorAll(e.selectorText)}catch(e){continue}for(const n of Array.from(r)){if(!t.isHTMLElement(n))continue;const o=s(n);for(let t=0;t<e.style.length;t++){const r=e.style[t];o.has(r)||n.style.setProperty(r,e.style.getPropertyValue(r),e.style.getPropertyPriority(r))}}}}}catch(e){}}const y="@lexical/html/DOM",$=Symbol.for("@lexical/html/DOMExportContext"),S="@lexical/html/DOMImport",E=Symbol.for("@lexical/html/DOMImportContext"),D=()=>!0;function C(e,t,n){return m($,e,t,n)}const I=C("root",Boolean),N=C("isExport",Boolean);function O(e){const t=o.getPeerDependencyFromEditor(e,y);return t?t.output.defaults:void 0}function v(e){const t=o.getPeerDependencyFromEditor(e,y);return t?t.output.runtime:void 0}function M(e=t.$getEditor()){const n=v(e);return n?n.getSessionConfig():t.$getEditorDOMRenderConfig(e)}const R=h($,O);function T(e){return t=>t instanceof e}function b(e,{nodes:t}){if("*"===t)return D;let n={};const o=[];for(const s of t)if("getType"in s){const t=s.getType();if(n){const o=e[t];void 0===o&&r(339,s.name,t),n=Object.assign(n,o.types)}o.push(T(s))}else n=void 0,o.push(s);return n||(1===o.length?o[0]:e=>{for(const t of o)if(t(e))return!0;return!1})}function k(e){return(t,n,o)=>e(t,o)}function w(e){return(t,n,o,r)=>e(t,n,r)}function L(e){return(t,n,o,r,s)=>e(t,n,o,s)}function A(e){return(t,n,o,r,s,i)=>e(t,n,o,r,i)}function _(e,t){return(n,o)=>{const r=()=>e(n,o),s=t(n);return s?s(n,r,o):r()}}function F(e,t){return(n,o,r)=>{const s=()=>e(n,o,r),i=t(n);return i?i(n,o,s,r):s()}}const P=F,H=w;function W(e,t){return(n,o,r,s)=>{const i=()=>e(n,o,r,s),c=t(n);return c?c(n,o,r,i,s):i()}}function B(e,t){return(n,o,r,s,i)=>{const c=()=>e(n,o,r,s,i),l=t(n);return l?l(n,o,r,s,c,i):c()}}function U(e,t){return(n,o,r,s)=>{e(n,o,r,s);const i=t(n);i&&i(n,o,r,s)}}function j(e,t,n,o,r){let s=n[t];for(const n of e[t])if("function"==typeof n[0]){const[e,t]=n;s=o(s,n=>e(n)&&t||void 0)}else{const e=n[1],t={};for(const n in e){const r=e[n];r&&(t[n]=r.reduce((e,t)=>o(e,()=>t),s))}s=o(s,e=>{const n=t[e.getType()];return n&&r(n)})}n[t]=s}function z(e,t,n,o){if(!o)return;const r=e[t];if("function"==typeof n)r.push([n,o]);else{const e=r[r.length-1];let t;e&&"types"===e[0]?t=e[1]:(t={},r.push(["types",t]));for(const e in n){const n=t[e]||[];t[e]=n,n.push(o)}}}function V(e){return"*"===e.nodes}function G(e,n){const r=function(e){const n={},{nodes:r}=o.getKnownTypesAndNodes(e);for(const e of r)n[e.getType()]={klass:e,types:{}};for(const e of Object.values(n))if(e){const o=e.klass.getType();for(let{klass:r}=e;t.$isLexicalNode(r.prototype);r=Object.getPrototypeOf(r)){const{ownNodeType:e}=t.getStaticNodeConfig(r),s=e&&n[e];s&&(s.types[o]=!0)}}return n}(e),s={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const e of function(e){const n=[],o=[],r=[];for(const s of e)if(V(s))n.push(s);else if(Array.isArray(s.nodes))for(const e of s.nodes)t.$isLexicalNode(e.prototype)?r.push(1===s.nodes.length?s:{...s,nodes:[e]}):o.push(1===s.nodes.length?s:{...s,nodes:[e]});const s=new Map,i=e=>{let n=s.get(e);if(void 0===n){n=0;for(let o=e;t.$isLexicalNode(o.prototype);o=Object.getPrototypeOf(o))n++;s.set(e,n)}return n};return r.sort((e,t)=>i(e.nodes[0])-i(t.nodes[0])),[...r,...o,...n]}(n)){const t=b(r,e);for(const n in s){z(s,n,t,e[n])}}return s}function q(e){return e}function K(e,{overrides:n}){const o=G(e,n),r={...t.DEFAULT_EDITOR_DOM_CONFIG,...e.dom};return j(o,"$createDOM",r,_,k),j(o,"$exportDOM",r,_,k),j(o,"$extractWithChild",r,B,A),j(o,"$getDOMSlot",r,P,H),j(o,"$shouldExclude",r,F,w),j(o,"$shouldInclude",r,F,w),j(o,"$updateDOM",r,W,L),j(o,"$decorateDOM",r,U,q),r}function J(e){return{get:t=>i(e,t)}}function Q(e){const t=Object.create(null);return a(e,t)||t}function Y(e,t){const n=J(t);return e.filter(e=>!(e.disabledForEditor&&e.disabledForEditor(n)))}function Z(e){if("*"===e.nodes)return()=>!0;const n=e.nodes.map(e=>{const n=e;return t.$isLexicalNode(n.prototype)?e=>e instanceof n:e});return e=>n.some(t=>t(e))}class X{editor;initialEditorConfig;overrides;editorContext;hasSessionGates;installed;sessionCache=new Map;constructor(e,t,n,o){this.editor=e,this.initialEditorConfig=t,this.overrides=n,this.editorContext=o,this.installed=Y(n,o),this.hasSessionGates=n.some(e=>e.disabledForSession)}setContextValue(e,n){const o=this.installed;this.editorContext[e.key]=n;const r=Y(this.overrides,this.editorContext);if(function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,r))return;const s=function(e,t){const n=new Set(e),o=new Set(t),r=[];for(const t of e)o.has(t)||r.push(t);for(const e of t)n.has(e)||r.push(e);return r}(o,r);this.installed=r,this.sessionCache.clear();const i=K(this.initialEditorConfig,{overrides:r});this.editor._config.dom=i;const c=function(e){const t=[];for(const n of e)(n.$createDOM||n.$getDOMSlot||n.$decorateDOM)&&t.push(Z(n));return 0===t.length?null:e=>t.some(t=>t(e))}(s);if(!c)return;const l=i.$updateDOM;i.$updateDOM=(e,t,n,o)=>!!c(e)||l(e,t,n,o),this.editor.update(t.$fullReconcile,{discrete:!0}),i.$updateDOM=l}getSessionConfig(){const e=this.editor._config.dom||t.DEFAULT_EDITOR_DOM_CONFIG;if(!this.hasSessionGates)return e;const n=J(l($,this.editor)||this.editorContext),o=[],r=[];if(this.installed.forEach((e,t)=>{e.disabledForSession&&e.disabledForSession(n)?o.push(String(t)):r.push(e)}),0===o.length)return e;const s=o.join(",");let i=this.sessionCache.get(s);return i||(i=K(this.initialEditorConfig,{overrides:r}),this.sessionCache.set(s,i)),i}}const ee=t.defineExtension({build(e,t,n){const{initialEditorConfig:o}=n.getInitResult(),r=Q(t.contextDefaults);return{defaults:r,runtime:new X(e,o,t.overrides,r)}},config:{contextDefaults:[],overrides:[]},html:{export:new Map([[t.RootNode,()=>{const e=document.createElement("div");return e.role="textbox",{element:e}}]])},init(e,t){const n={dom:e.dom,nodes:e.nodes},o=Q(t.contextDefaults),r=Y(t.overrides,o);return e.dom=K(e,{overrides:r}),{initialEditorConfig:n}},mergeConfig(e,n){const o=t.shallowMergeConfig(e,n);for(const t of["overrides","contextDefaults"])n[t]&&(o[t]=[...e[t],...n[t]]);return o},name:y}),te=Symbol.for("@lexical/html/SelectorImpl");function ne(e,n){const o={kind:"element",predicate:(s=n,0===s.length?t.isHTMLElement:1===s.length?s[0]:(e,t)=>{for(const n of s)if(!n(e,t))return!1;return!0}),tags:e};var s;const i=t=>ne(e,[...n,t]);return{[te]:o,attr:(e,t,n)=>i(se(e,t,n)),classAll:(...e)=>i(re(e)),classAny:(...e)=>i(function(e){const n=oe(e);if(0===n.length)return()=>!1;return e=>{if(!t.isHTMLElement(e))return!1;const o=e.classList;for(const e of n)if(o.contains(e))return!0;return!1}}(e)),styleAny:(e,n,o)=>i(function(e,n,o){if("string"==typeof n)return o=>t.isHTMLElement(o)&&o.style.getPropertyValue(e)===n;if(n instanceof RegExp){const r=o&&o.capture,s=n;return(n,o)=>{if(!t.isHTMLElement(n))return!1;const i=n.style.getPropertyValue(e);if(!i)return!1;const c=i.match(s);return null!==c&&(void 0!==r&&(o[r]=c),!0)}}r(362,JSON.stringify(e))}(e,n,o))}}function oe(e){const t=[];for(const n of e)n&&t.push(n);return t}function re(e){const n=oe(e);return 0===n.length?()=>!0:e=>{if(!t.isHTMLElement(e))return!1;const o=e.classList;for(const e of n)if(!o.contains(e))return!1;return!0}}function se(e,n,o){if(!0===n)return n=>t.isHTMLElement(n)&&n.hasAttribute(e);if("string"==typeof n)return o=>t.isHTMLElement(o)&&o.getAttribute(e)===n;if(n instanceof RegExp){const r=o&&o.capture,s=n;return(n,o)=>{if(!t.isHTMLElement(n))return!1;const i=n.getAttribute(e);if(null==i)return!1;const c=i.match(s);return null!==c&&(void 0!==r&&(o[r]=c),!0)}}r(361,JSON.stringify(e))}const ie={kind:"text",predicate:t.isDOMTextNode,tags:new Set},ce={[te]:ie},le={kind:"comment",predicate:e=>8===e.nodeType,tags:new Set},ue={[te]:le},ae={any:()=>ne(new Set,[]),comment:()=>ue,tag(...e){e.length>0||r(363);const t=new Set;for(const n of e)t.add(n.toUpperCase());return ne(t,[])},text:()=>ce};const fe=/[A-Za-z0-9_-]/;class de{constructor(e,t){this.source=e,this.pos=t}peek(e=0){return this.source[this.pos+e]||""}consume(){return this.source[this.pos++]||""}eof(){return this.pos>=this.source.length}skipWhitespace(){for(;!this.eof()&&/\s/.test(this.peek());)this.pos++}readIdent(){const e=this.pos;for(;!this.eof()&&fe.test(this.peek());)this.pos++;return this.source.slice(e,this.pos)}readQuoted(){const e=this.consume();this.assert('"'===e||"'"===e,"expected quote");const t=this.pos;for(;!this.eof()&&this.peek()!==e;)"\\"===this.peek()?this.pos+=2:this.pos++;this.assert(!this.eof(),"unterminated string");const n=this.source.slice(t,this.pos);return this.pos++,n.replace(/\\(.)/g,"$1")}assert(e,t){e||r(364,String(this.pos+1),t,this.source)}}function pe(e){const t=new Set,n=[],o=[];if(e.skipWhitespace(),"*"===e.peek())e.consume();else if(fe.test(e.peek())){const n=e.readIdent();n&&t.add(n.toUpperCase())}for(;!e.eof();){const t=e.peek();if("."===t){e.consume();const t=e.readIdent();e.assert(""!==t,'expected class name after "."'),o.push(t)}else if("#"===t){e.consume();const t=e.readIdent();e.assert(""!==t,'expected id after "#"'),n.push(se("id",t))}else{if("["!==t)break;{e.consume(),e.skipWhitespace();const t=e.readIdent();e.assert(""!==t,'expected attribute name after "["'),e.skipWhitespace();let o=!0;if("="===e.peek()){e.consume(),e.skipWhitespace();const t=e.peek();'"'===t||"'"===t?o=e.readQuoted():(o=e.readIdent(),e.assert(""!==o,"expected attribute value")),e.skipWhitespace()}e.assert("]"===e.peek(),'expected "]"'),e.consume(),n.push(se(t,o))}}}return o.length>0&&n.push(re(o)),{predicates:n,tags:t}}function he(e){const t=new de(e,0),n=[];for(;;){const e=pe(t);if(n.push(e),t.skipWhitespace(),t.eof())break;t.assert(","===t.peek(),'expected "," (selector lists are the only supported combinator)'),t.consume(),t.skipWhitespace()}if(1===n.length)return ne(n[0].tags,n[0].predicates);const o=new Set;for(const e of n)for(const t of e.tags)o.add(t);return ne(o,[(e,t)=>{for(const o of n){const n=e.nodeName;if(o.tags.size>0&&!o.tags.has(n))continue;let r=!0;for(const n of o.predicates)if(!n(e,t)){r=!1;break}if(r)return!0}return!1}])}function me(e){return e}function ge(e,t,n){return m(E,e,t,n)}const xe=ge("importSource",()=>"unknown"),ye=ge("importSourceDataTransfer",()=>null),$e=ge("textFormat",()=>0),Se=ge("textStyle",()=>({}));function Ee(e){if(!t.isHTMLElement(e))return!1;if("PRE"===e.nodeName)return!0;const n=e.style.whiteSpace;return"string"==typeof n&&n.startsWith("pre")}function De(e){if(t.isDOMTextNode(e))return!0;if(!t.isHTMLElement(e))return!1;const n=e.style.display;return n?n.startsWith("inline"):!t.isBlockDomNode(e)&&t.isInlineDomNode(e)}const Ce=ge("whitespaceConfig",()=>({isInline:De,preservesWhitespace:Ee})),Ie=ge("importOverlays",()=>[]);class Ne{constructor(e){this.record=e}get(e){return i(this.record,e)}set(e,t){this.record[e.key]=t}update(e,t){this.record[e.key]=t(i(this.record,e))}has(e){return Object.prototype.hasOwnProperty.call(this.record,e.key)}}function Oe(e){const t=o.getPeerDependencyFromEditor(e,S);return t?t.output.defaults:void 0}function ve(e,n=t.$getEditor()){return i(function(e){return l(E,e)||Oe(e)}(n),e)}const Me=h(E,Oe),Re=ae,Te=new Set(["center","end","justify","left","right","start"]);function be(e){return Te.has(e)}const ke={B:{fontWeight:"bold"},EM:{fontStyle:"italic"},I:{fontStyle:"italic"},S:{textDecoration:"line-through"},STRONG:{fontWeight:"bold"},SUB:{verticalAlign:"sub"},SUP:{verticalAlign:"super"},U:{textDecoration:"underline"}},we={CODE:t.IS_CODE,MARK:t.IS_HIGHLIGHT};const Le=new Set(["font-weight","font-style","text-decoration","vertical-align"]);const Ae={$import:(e,n)=>{const o=e.get($e),r=ke[n.nodeName],s=function(e){return{fontStyle:e.style.fontStyle,fontWeight:e.style.fontWeight,textDecoration:e.style.textDecoration,verticalAlign:e.style.verticalAlign}}(n),i=r?(c=r,{fontStyle:(l=s).fontStyle||c.fontStyle,fontWeight:l.fontWeight||c.fontWeight,textDecoration:l.textDecoration||c.textDecoration,verticalAlign:l.verticalAlign||c.verticalAlign}):s;var c,l;let u=(a=o,f=function(e){let n=0,o=0;const{fontWeight:r,fontStyle:s,textDecoration:i,verticalAlign:c}=e;if("700"===r||"bold"===r?n|=t.IS_BOLD:"normal"!==r&&"400"!==r||(o|=t.IS_BOLD),"italic"===s?n|=t.IS_ITALIC:"normal"===s&&(o|=t.IS_ITALIC),i){const e=i.split(" ");e.includes("underline")&&(n|=t.IS_UNDERLINE),e.includes("line-through")&&(n|=t.IS_STRIKETHROUGH),e.includes("none")&&(o|=t.IS_UNDERLINE|t.IS_STRIKETHROUGH)}return"sub"===c?(n|=t.IS_SUBSCRIPT,o|=t.IS_SUPERSCRIPT):"super"===c?(n|=t.IS_SUPERSCRIPT,o|=t.IS_SUBSCRIPT):"baseline"===c&&(o|=t.IS_SUBSCRIPT|t.IS_SUPERSCRIPT),{clear:o,set:n}}(i),a&~f.clear|f.set);var a,f;const p=we[n.nodeName];return p&&(u|=p),u===o?e.$importChildren(n):e.$importChildren(n,{context:[d($e,u)]})},match:Re.tag("b","strong","em","i","code","mark","s","sub","sup","u","span"),name:"@lexical/html/inline-format"};function _e(e,n,o){let r=e;for(;;){let e=null;for(;null===(e=n?r.nextSibling:r.previousSibling);){const e=r.parentNode;if(null===e)return null;r=e}if(r=e,!o.isInline(r))return null;let s=r;for(;null!==(s=n?r.firstChild:r.lastChild);)r=s;if(t.isDOMTextNode(r))return r;if("BR"===r.nodeName)return null}}function Fe(e,n){return 0!==n&&t.$isTextNode(e)?e.setFormat(n):e}function Pe(e,n){if(t.$isTextNode(e)){const t=function(e){let t="";for(const n in e)Le.has(n)||(t+=`${n}: ${e[n]}; `);return t.trimEnd()}(n);""!==t&&e.setStyle(t)}return e}const He={$import:(e,n)=>{const o=e.get($e),r=e.get(Se),s=e.get(Ce);if(function(e,t){let n=e.parentNode;for(;null!==n;){if(t.preservesWhitespace(n))return!0;n=n.parentNode}return!1}(n,s)){const e=t.$generateNodesFromRawText(n.textContent||"");for(const t of e)Fe(t,o),Pe(t,r);return e}const i=function(e,t){let n=(e.textContent||"").replace(/\r/g,"").replace(/[ \t\n]+/g," ");if(0===n.length)return"";if(" "===n[0]){let o=e,r=!0;for(;null!==o&&null!==(o=_e(o,!1,t));){const e=o.textContent||"";if(e.length>0){/[ \t\n]$/.test(e)&&(n=n.slice(1)),r=!1;break}}r&&(n=n.slice(1))}if(n.length>0&&" "===n[n.length-1]){let o=e,r=!0;for(;null!==o&&null!==(o=_e(o,!0,t));)if((o.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){r=!1;break}r&&(n=n.slice(0,-1))}return n}(n,s);if(""===i)return[];const c=t.$createTextNode(i);return Fe(c,o),Pe(c,r),[c]},match:Re.text(),name:"@lexical/html/#text"},We={$import:()=>[],match:Re.tag("script","style"),name:"@lexical/html/script-style-ignore"},Be={$import:()=>[t.$createLineBreakNode()],match:Re.tag("br"),name:"@lexical/html/br"},Ue=[We,{$import:(e,n)=>{const o=t.$createParagraphNode();if(t.$setFormatFromDOM(o,n),t.setNodeIndentFromDOM(n,o),""===o.getFormatType()){const e=n.getAttribute("align");e&&be(e)&&o.setFormat(e)}return t.$setDirectionFromDOM(o,n),[o.splice(0,0,e.$importChildren(n))]},match:Re.tag("p"),name:"@lexical/html/p"},He,Be,Ae];function je(e,t){const n=[];let o=0,r=0;for(;o<e.length&&r<t.length;)e[o]<=t[r]?n.push(e[o++]):n.push(t[r++]);for(;o<e.length;)n.push(e[o++]);for(;r<t.length;)n.push(t[r++]);return n}function ze(e){const t=[],n=new Map,o=[],s=[],i=[],c=new Set;e.forEach((e,l)=>{const u=function(e){const t=e[te];return void 0===t&&r(360),t}(e.match),a=e.name||function(e,t){if("text"===e.kind)return`#text@${t}`;if("comment"===e.kind)return`#comment@${t}`;if(0===e.tags.size)return`*@${t}`;const n=Array.from(e.tags).join(",").toLowerCase();return`${n}@${t}`}(u,l);if(e.name&&c.add(e.name),t.push({$import:e.$import,name:a,predicate:u.predicate}),"text"===u.kind)s.push(l);else if("comment"===u.kind)i.push(l);else if(0===u.tags.size)o.push(l);else for(const e of u.tags){let t=n.get(e);t||(t=[],n.set(e,t)),t.push(l)}});const l=new Map;if(0===o.length)for(const[e,t]of n)l.set(e,t);else for(const[e,t]of n)l.set(e,je(t,o));return{byTag:l,commentIndices:i,rules:t,textIndices:s,wildcardIndices:o}}function Ve(e,n){return t.isDOMTextNode(n)?e.textIndices:8===n.nodeType?e.commentIndices:t.isHTMLElement(n)?e.byTag.get(n.nodeName)||e.wildcardIndices:Ge}const Ge=Object.freeze([]);function qe(e){const t=[];for(const n of e)if(Ke(n))for(const e of n.rules)t.push(e);else t.push(n);return t}function Ke(e){return"object"==typeof e&&null!==e&&"__type"in e&&"CompiledOverlayRules"===e.__type}function Je(e){return t.$isBlockElementNode(e)||t.$isDecoratorNode(e)&&!e.isInline()}function Qe(e,n,o){const r=t.$createParagraphNode();if(t.isHTMLElement(o)){const e=o.style.textAlign;be(e)&&r.setFormat(e)}return[r.splice(0,0,e)]}const Ye={$accepts:Je,$packageRun:Qe,name:"BlockSchema"},Ze={$accepts:e=>!Je(e),name:"InlineSchema"},Xe={$accepts:Je,$packageRun:e=>e,name:"NestedBlockSchema"},et={$accepts:Je,$packageRun:Qe,name:"RootSchema"},tt=Object.freeze({});function nt(e,t){const n={$importChildren:(t,n)=>function(e,t,n){const o=n&&n.rules?n.rules.dispatch:void 0;o&&e.overlays.push(o);try{const o=()=>ot(e,t,n);return n&&n.context?Me(n.context,e.editor)(o):o()}finally{o&&e.overlays.pop()}}(e,t,n),$importOne:(t,n)=>rt(e,t,n),captures:t,get:t=>ve(t,e.editor),session:e.session};return n}function ot(e,t,n){const o=n&&n.$onChild,r=[];for(const n of Array.from(t.childNodes)){const t=rt(e,n,void 0);for(const e of t){const t=o?o(e):e;null!=t&&r.push(t)}}const s=n&&n.$after?n.$after(r):r,i=n&&n.schema;return i?function(e,t,n,o){const r=[];let s=null;const i=()=>{if(null===s)return;const t=s;if(s=null,e.$packageRun){const s=e.$packageRun(t,n,o);if(s.length>0){for(const e of s)r.push(e);return}}if("hoist"===e.onReject)for(const e of t)r.push(e)};for(const o of t)e.$accepts(o,n)?(i(),r.push(o)):(null===s&&(s=[]),s.push(o));return i(),e.$finalize?e.$finalize(r,n):r}(i,s,null,t):s}function rt(e,t,n){const o=()=>function(e,t){const n=function(e,t){const n=[];for(let o=e.overlays.length-1;o>=0;o--){const r=e.overlays[o],s=Ve(r,t);s.length>0&&n.push({dispatch:r,indices:s})}const o=Ve(e.dispatch,t);o.length>0&&n.push({dispatch:e.dispatch,indices:o});return n}(e,t);if(0===n.length)return st(e,t);let o=0,r=0;const s=()=>{for(;o<n.length;){const{dispatch:i,indices:c}=n[o];for(;r<c.length;){const n=c[r++],o=i.rules[n],l={};if(o.predicate(t,l)){const n=nt(e,0===Object.keys(l).length?tt:l);try{return o.$import(n,t,s)}catch(e){throw e}}}o++,r=0}return st(e,t)};return s()}(e,t);return n&&n.context?Me(n.context,e.editor)(o):o()}function st(e,t){if(0===t.childNodes.length)return[];const n=[];for(const o of Array.from(t.childNodes)){const t=rt(e,o,void 0);for(const e of t)n.push(e)}return n}const it={$import:(e,t)=>e.$importChildren(t),match:ae.any(),name:"@lexical/html/default-hoist"},ct=t.defineExtension({build(e,n){const o=ze(qe(n.rules)),r=a(n.contextDefaults,void 0),s=n.preprocess;return{$generateNodesFromDOM:(n,i)=>{const c=i&&i.context?a(i.context,r):r,l=void 0!==c&&c!==r?c:Object.create(r||null),u=new Ne(l),f={session:u};return function(e,t,n){let o=e.length-1;const r=()=>{for(;o>=0;)return void(0,e[o--])(t,n,r)};r()}(i&&i.preprocess?[...s,...i.preprocess]:s,n,f),p(E,l,()=>function(e,n,o,r){return ot({dispatch:e,editor:n,overlays:r.get(Ie).map(e=>e.dispatch),session:r},t.isDOMDocumentNode(o)?o.body:o,{schema:et})}(o,e,n,u),e)},defaults:r}},config:{contextDefaults:[],preprocess:[g],rules:[it]},mergeConfig:(e,n)=>t.shallowMergeConfig(e,{...n,...n.contextDefaults&&{contextDefaults:[...e.contextDefaults,...n.contextDefaults]},...n.preprocess&&{preprocess:[...e.preprocess,...n.preprocess]},...n.rules&&{rules:[...n.rules,...e.rules]}}),name:S});const lt=t.defineExtension({dependencies:[t.configExtension(ct,{rules:Ue})],name:"@lexical/html/CoreImport"}),ut=[{$import:()=>[o.$createHorizontalRuleNode()],match:ae.tag("hr"),name:"@lexical/html/hr"}],at=t.defineExtension({dependencies:[lt,o.HorizontalRuleExtension,t.configExtension(ct,{rules:ut})],name:"@lexical/html/HorizontalRuleImport"}),ft={any:ae.any,comment:ae.comment,css:he,tag:ae.tag,text:ae.text},dt=new Set(["STYLE","SCRIPT"]);function pt(e,n=null,o=t.$getEditor()){return R([d(N,!0)],o)(()=>{const r=t.$getRoot(),s=M(o),i=e.append.bind(e);for(const e of r.getChildren())ht(o,e,i,n,s);return e})}function ht(n,o,r,s=null,i=t.$getEditorDOMRenderConfig(n)){let c=i.$shouldInclude(o,s,n);const l=i.$shouldExclude(o,s,n);let u=o;null!==s&&t.$isTextNode(o)&&(u=e.$sliceSelectedTextNodeContent(s,o,"clone"));const a=i.$exportDOM(u,n),{element:f,after:d,append:p,$getChildNodes:h}=a;if(!f)return!1;const m=document.createDocumentFragment(),g=h?h():t.$isElementNode(u)?u.getChildren():[],x=m.append.bind(m);for(const e of g){const t=ht(n,e,x,s,i);!c&&t&&i.$extractWithChild(o,e,s,"html",n)&&(c=!0)}if(c&&!l){if((t.isHTMLElement(f)||t.isDocumentFragment(f))&&(p?p(m):f.append(m)),r(f),d){const e=d.call(u,f);e&&(t.isDocumentFragment(f)?f.replaceChildren(e):f.replaceWith(e))}}else r(m);return c}function mt(e,n,o,r,s=new Map,i){const c=[];if(dt.has(e.nodeName))return c;let l=null;const u=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let r=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===r||(r.priority||0)<=(n.priority||0))&&(r=n)}return null!==r?r.conversion:null}(e,n),a=u?u(e):null;let f=null;if(null!==a){f=a.after;const t=a.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of s)if(l=e(l,i),!l)break;l&&c.push(...Array.isArray(t)?t:[l])}null!=a.forChild&&s.set(e.nodeName,a.forChild)}const d=e.childNodes;let p=[];const h=(null==l||!t.$isRootOrShadowRoot(l))&&(null!=l&&t.$isBlockElementNode(l)||r);for(let e=0;e<d.length;e++)p.push(...mt(d[e],n,o,h,new Map(s),l));if(null!=f&&(p=f(p)),t.isBlockDomNode(e)&&(p=gt(e,p,h?()=>{const e=new t.ArtificialNode__DO_NOT_USE;return o.push(e),e}:t.$createParagraphNode)),null==l)if(p.length>0)for(const e of p)c.push(e);else t.isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return!1;return t.isInlineDomNode(e.nextSibling)&&t.isInlineDomNode(e.previousSibling)}(e)&&c.push(t.$createLineBreakNode());else t.$isElementNode(l)&&l.append(...p);return c}function gt(e,n,o){const r=e.style.textAlign,s=[];let i=[];for(let e=0;e<n.length;e++){const c=n[e];if(t.$isBlockElementNode(c))r&&!c.getFormat()&&c.setFormat(r),s.push(c);else if(i.push(c),e===n.length-1||e<n.length-1&&t.$isBlockElementNode(n[e+1])){const e=o();e.setFormat(r),e.append(...i),s.push(e),i=[]}}return s}exports.$distributeInlineWrapper=function e(n,o){const r=[];let s=[];const i=()=>{0!==s.length&&(r.push(o().splice(0,0,s)),s=[])};for(const c of n)if(Je(c)){if(i(),t.$isElementNode(c)){const t=e(c.getChildren(),o);c.splice(0,c.getChildrenSize(),t)}r.push(c)}else s.push(c);return i(),r},exports.$generateDOMFromNodes=pt,exports.$generateDOMFromRoot=function(e,n=t.$getRoot()){const o=t.$getEditor();return R([d(N,!0),d(I,!0)],o)(()=>{const t=M(o),r=e.append.bind(e);return ht(o,n,r,null,t),e})},exports.$generateHtmlFromNodes=function(e,t=null){return("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)&&r(338),pt(document.createElement("div"),t,e).innerHTML},exports.$generateNodesFromDOM=function(e,n){x(n);const o=t.isDOMDocumentNode(n)?n.body.childNodes:n.childNodes,r=[],s=[];for(const t of o)if(!dt.has(t.nodeName)){const n=mt(t,e,s,!1);if(null!==n)for(const e of n)r.push(e)}return function(e){for(const n of e)n.getParent()&&n.getNextSibling()instanceof t.ArtificialNode__DO_NOT_USE&&n.insertAfter(t.$createLineBreakNode());for(const t of e){const e=t.getParent();e&&e.splice(t.getIndexWithinParent(),1,t.getChildren())}}(s),r},exports.$generateNodesFromDOMViaExtension=function(e,t){return o.$getExtensionOutput(ct).$generateNodesFromDOM(e,t)},exports.$getImportContextValue=ve,exports.$getRenderContextValue=function(e,n=t.$getEditor()){return i(function(e){return l($,e)||O(e)}(n),e)},exports.$getSessionDOMRenderConfig=M,exports.$inlineStylesFromStyleSheets=g,exports.$isBlockLevel=Je,exports.$setRenderContextValue=function(e,n,o=t.$getEditor()){const r=v(o);r&&r.setContextValue(e,n)},exports.$updateRenderContextValue=function(e,n,o=t.$getEditor()){const r=v(o);r&&r.setContextValue(e,n(i(r.editorContext,e)))},exports.$withImportContext=Me,exports.$withRenderContext=R,exports.BlockSchema=Ye,exports.CoreImportExtension=lt,exports.CoreImportRules=Ue,exports.DOMImportExtension=ct,exports.DOMRenderExtension=ee,exports.HorizontalRuleImportExtension=at,exports.HorizontalRuleImportRules=ut,exports.ImportOverlays=Ie,exports.ImportSource=xe,exports.ImportSourceDataTransfer=ye,exports.ImportTextFormat=$e,exports.ImportTextStyle=Se,exports.ImportWhitespaceConfig=Ce,exports.InlineSchema=Ze,exports.NestedBlockSchema=Xe,exports.RenderContextExport=N,exports.RenderContextRoot=I,exports.RootSchema=et,exports.contextUpdater=function(e,t){return{cfg:e,updater:t}},exports.contextValue=d,exports.createImportState=ge,exports.createRenderState=C,exports.defaultIsInline=De,exports.defaultPreservesWhitespace=Ee,exports.defineImportRule=me,exports.defineOverlayRules=function(e){const t=qe(e);return{__type:"CompiledOverlayRules",dispatch:ze(t),rules:t}},exports.domOverride=function(e,t,n){return{...t,...n,nodes:e}},exports.isElementOfTag=function(e,n){return t.isHTMLElement(e)&&e.nodeName===n.toUpperCase()},exports.parseSelector=he,exports.sel=ft;
|
|
9
|
+
"use strict";var e=require("@lexical/selection"),t=require("lexical"),n=require("@lexical/utils"),o=require("@lexical/extension");function r(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let s;function i(e,t){const{key:n}=t;return e&&n in e?e[n]:t.defaultValue}function c(e){return s&&s.editor===e?s:void 0}function l(e,t){const n=c(t);return n&&n[e]}function u(e,t){if("cfg"in t){const{cfg:n,updater:o}=t;return[n,o(i(e,n))]}return t}function a(e,t){let n=t;for(const o of e){const[e,r]=u(n,o),s=e.key;if(n===t&&i(n,e)===r)continue;const c=n===t||void 0===n?f(t):n;c[s]=r,n=c}return n}function f(e){return Object.create(e||null)}function d(e,t){return[e,t]}function p(e,n,o,r=t.$getEditor()){const i=s,l=c(r);try{return s={...l,editor:r,[e]:n},o()}finally{s=i}}function h(e,n=()=>{}){return(o,r=t.$getEditor())=>t=>{const s=c(r),i=s&&s[e],l=a(o,i||n(r));return l&&l!==i?p(e,l,t,r):t()}}function m(e,n,o,r){return Object.assign(t.createState(Symbol(n),{isEqual:r,parse:o}),{[e]:!0})}const g=(e,t,n)=>{x(e),n()};function x(e){if(!t.isDOMDocumentNode(e))return;const o=e;if(null===o.querySelector("style"))return;const r=new Map;function s(e){let t=r.get(e);if(void 0===t){t=new Set;for(let n=0;n<e.style.length;n++)t.add(e.style[n]);r.set(e,t)}return t}try{for(const e of Array.from(o.styleSheets)){let r;try{r=e.cssRules}catch(e){continue}for(const e of Array.from(r)){if(!n.objectKlassEquals(e,CSSStyleRule))continue;let r;try{r=o.querySelectorAll(e.selectorText)}catch(e){continue}for(const n of Array.from(r)){if(!t.isHTMLElement(n))continue;const o=s(n);for(let t=0;t<e.style.length;t++){const r=e.style[t];o.has(r)||n.style.setProperty(r,e.style.getPropertyValue(r),e.style.getPropertyPriority(r))}}}}}catch(e){}}const y="@lexical/html/DOM",$=Symbol.for("@lexical/html/DOMExportContext"),S="@lexical/html/DOMImport",E=Symbol.for("@lexical/html/DOMImportContext"),C=()=>!0;function D(e,t,n){return m($,e,t,n)}const N=D("root",Boolean),I=D("isExport",Boolean);function O(e){const t=o.getPeerDependencyFromEditor(e,y);return t?t.output.defaults:void 0}function v(e){const t=o.getPeerDependencyFromEditor(e,y);return t?t.output.runtime:void 0}function M(e=t.$getEditor()){const n=v(e);return n?n.getSessionConfig():t.$getEditorDOMRenderConfig(e)}const k=h($,O);function T(e){return t=>t instanceof e}function R(e,{nodes:t}){if("*"===t)return C;let n={};const o=[];for(const s of t)if("getType"in s){const t=s.getType();if(n){const o=e[t];void 0===o&&r(339,s.name,t),n=Object.assign(n,o.types)}o.push(T(s))}else n=void 0,o.push(s);return n||(1===o.length?o[0]:e=>{for(const t of o)if(t(e))return!0;return!1})}function b(e){return(t,n,o)=>e(t,o)}function w(e){return(t,n,o,r)=>e(t,n,r)}function L(e){return(t,n,o,r,s)=>e(t,n,o,s)}function A(e){return(t,n,o,r,s,i)=>e(t,n,o,r,i)}function _(e,t){return(n,o)=>{const r=()=>e(n,o),s=t(n);return s?s(n,r,o):r()}}function F(e,t){return(n,o,r)=>{const s=()=>e(n,o,r),i=t(n);return i?i(n,o,s,r):s()}}const P=F,B=w;function H(e,t){return(n,o,r,s)=>{const i=()=>e(n,o,r,s),c=t(n);return c?c(n,o,r,i,s):i()}}function W(e,t){return(n,o,r,s,i)=>{const c=()=>e(n,o,r,s,i),l=t(n);return l?l(n,o,r,s,c,i):c()}}function U(e,t){return(n,o,r,s)=>{e(n,o,r,s);const i=t(n);i&&i(n,o,r,s)}}function j(e,t,n,o,r){let s=n[t];for(const n of e[t])if("function"==typeof n[0]){const[e,t]=n;s=o(s,n=>e(n)&&t||void 0)}else{const e=n[1],t={};for(const n in e){const r=e[n];r&&(t[n]=r.reduce((e,t)=>o(e,()=>t),s))}s=o(s,e=>{const n=t[e.getType()];return n&&r(n)})}n[t]=s}function z(e,t,n,o){if(!o)return;const r=e[t];if("function"==typeof n)r.push([n,o]);else{const e=r[r.length-1];let t;e&&"types"===e[0]?t=e[1]:(t={},r.push(["types",t]));for(const e in n){const n=t[e]||[];t[e]=n,n.push(o)}}}function V(e){return"*"===e.nodes}function G(e,n){const r=function(e){const n={},{nodes:r}=o.getKnownTypesAndNodes(e);for(const e of r)n[e.getType()]={klass:e,types:{}};for(const e of Object.values(n))if(e){const o=e.klass.getType();for(let{klass:r}=e;t.$isLexicalNode(r.prototype);r=Object.getPrototypeOf(r)){const{ownNodeType:e}=t.getStaticNodeConfig(r),s=e&&n[e];s&&(s.types[o]=!0)}}return n}(e),s={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const e of function(e){const n=[],o=[],r=[];for(const s of e)if(V(s))n.push(s);else if(Array.isArray(s.nodes))for(const e of s.nodes)t.$isLexicalNode(e.prototype)?r.push(1===s.nodes.length?s:{...s,nodes:[e]}):o.push(1===s.nodes.length?s:{...s,nodes:[e]});const s=new Map,i=e=>{let n=s.get(e);if(void 0===n){n=0;for(let o=e;t.$isLexicalNode(o.prototype);o=Object.getPrototypeOf(o))n++;s.set(e,n)}return n};return r.sort((e,t)=>i(e.nodes[0])-i(t.nodes[0])),[...r,...o,...n]}(n)){const t=R(r,e);for(const n in s){z(s,n,t,e[n])}}return s}function q(e){return e}function K(e,{overrides:n}){const o=G(e,n),r={...t.DEFAULT_EDITOR_DOM_CONFIG,...e.dom};return j(o,"$createDOM",r,_,b),j(o,"$exportDOM",r,_,b),j(o,"$extractWithChild",r,W,A),j(o,"$getDOMSlot",r,P,B),j(o,"$shouldExclude",r,F,w),j(o,"$shouldInclude",r,F,w),j(o,"$updateDOM",r,H,L),j(o,"$decorateDOM",r,U,q),r}function J(e){return{get:t=>i(e,t)}}function Q(e){const t=Object.create(null);return a(e,t)||t}function Y(e,t){const n=J(t);return e.filter(e=>!(e.disabledForEditor&&e.disabledForEditor(n)))}function Z(e){if("*"===e.nodes)return()=>!0;const n=e.nodes.map(e=>{const n=e;return t.$isLexicalNode(n.prototype)?e=>e instanceof n:e});return e=>n.some(t=>t(e))}class X{editor;initialEditorConfig;overrides;editorContext;hasSessionGates;installed;sessionCache=new Map;constructor(e,t,n,o){this.editor=e,this.initialEditorConfig=t,this.overrides=n,this.editorContext=o,this.installed=Y(n,o),this.hasSessionGates=n.some(e=>e.disabledForSession)}setContextValue(e,n){const o=this.installed;this.editorContext[e.key]=n;const r=Y(this.overrides,this.editorContext);if(function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,r))return;const s=function(e,t){const n=new Set(e),o=new Set(t),r=[];for(const t of e)o.has(t)||r.push(t);for(const e of t)n.has(e)||r.push(e);return r}(o,r);this.installed=r,this.sessionCache.clear();const i=K(this.initialEditorConfig,{overrides:r});this.editor._config.dom=i;const c=function(e){const t=[];for(const n of e)(n.$createDOM||n.$getDOMSlot||n.$decorateDOM)&&t.push(Z(n));return 0===t.length?null:e=>t.some(t=>t(e))}(s);if(!c)return;const l=i.$updateDOM;i.$updateDOM=(e,t,n,o)=>!!c(e)||l(e,t,n,o),this.editor.update(t.$fullReconcile,{discrete:!0}),i.$updateDOM=l}getSessionConfig(){const e=this.editor._config.dom||t.DEFAULT_EDITOR_DOM_CONFIG;if(!this.hasSessionGates)return e;const n=J(l($,this.editor)||this.editorContext),o=[],r=[];if(this.installed.forEach((e,t)=>{e.disabledForSession&&e.disabledForSession(n)?o.push(String(t)):r.push(e)}),0===o.length)return e;const s=o.join(",");let i=this.sessionCache.get(s);return i||(i=K(this.initialEditorConfig,{overrides:r}),this.sessionCache.set(s,i)),i}}const ee=t.defineExtension({build(e,t,n){const{initialEditorConfig:o}=n.getInitResult(),r=Q(t.contextDefaults);return{defaults:r,runtime:new X(e,o,t.overrides,r)}},config:{contextDefaults:[],overrides:[]},html:{export:new Map([[t.RootNode,()=>{const e=document.createElement("div");return e.role="textbox",{element:e}}]])},init(e,t){const n={dom:e.dom,nodes:e.nodes},o=Q(t.contextDefaults),r=Y(t.overrides,o);return e.dom=K(e,{overrides:r}),{initialEditorConfig:n}},mergeConfig(e,n){const o=t.shallowMergeConfig(e,n);for(const t of["overrides","contextDefaults"])n[t]&&(o[t]=[...e[t],...n[t]]);return o},name:y}),te=Symbol.for("@lexical/html/SelectorImpl");function ne(e,n){const o={kind:"element",predicate:(s=n,0===s.length?t.isHTMLElement:1===s.length?s[0]:(e,t)=>{for(const n of s)if(!n(e,t))return!1;return!0}),tags:e};var s;const i=t=>ne(e,[...n,t]);return{[te]:o,attr:(e,t,n)=>i(se(e,t,n)),classAll:(...e)=>i(re(e)),classAny:(...e)=>i(function(e){const n=oe(e);if(0===n.length)return()=>!1;return e=>{if(!t.isHTMLElement(e))return!1;const o=e.classList;for(const e of n)if(o.contains(e))return!0;return!1}}(e)),styleAny:(e,n,o)=>i(function(e,n,o){if("string"==typeof n)return o=>t.isHTMLElement(o)&&o.style.getPropertyValue(e)===n;if(n instanceof RegExp){const r=o&&o.capture,s=n;return(n,o)=>{if(!t.isHTMLElement(n))return!1;const i=n.style.getPropertyValue(e);if(!i)return!1;const c=i.match(s);return null!==c&&(void 0!==r&&(o[r]=c),!0)}}r(362,JSON.stringify(e))}(e,n,o))}}function oe(e){const t=[];for(const n of e)n&&t.push(n);return t}function re(e){const n=oe(e);return 0===n.length?()=>!0:e=>{if(!t.isHTMLElement(e))return!1;const o=e.classList;for(const e of n)if(!o.contains(e))return!1;return!0}}function se(e,n,o){if(!0===n)return n=>t.isHTMLElement(n)&&n.hasAttribute(e);if("string"==typeof n)return o=>t.isHTMLElement(o)&&o.getAttribute(e)===n;if(n instanceof RegExp){const r=o&&o.capture,s=n;return(n,o)=>{if(!t.isHTMLElement(n))return!1;const i=n.getAttribute(e);if(null==i)return!1;const c=i.match(s);return null!==c&&(void 0!==r&&(o[r]=c),!0)}}r(361,JSON.stringify(e))}const ie={kind:"text",predicate:t.isDOMTextNode,tags:new Set},ce={[te]:ie},le={kind:"comment",predicate:e=>8===e.nodeType,tags:new Set},ue={[te]:le},ae={any:()=>ne(new Set,[]),comment:()=>ue,tag(...e){e.length>0||r(363);const t=new Set;for(const n of e)t.add(n.toUpperCase());return ne(t,[])},text:()=>ce};const fe=/[A-Za-z0-9_-]/;class de{constructor(e,t){this.source=e,this.pos=t}peek(e=0){return this.source[this.pos+e]||""}consume(){return this.source[this.pos++]||""}eof(){return this.pos>=this.source.length}skipWhitespace(){for(;!this.eof()&&/\s/.test(this.peek());)this.pos++}readIdent(){const e=this.pos;for(;!this.eof()&&fe.test(this.peek());)this.pos++;return this.source.slice(e,this.pos)}readQuoted(){const e=this.consume();this.assert('"'===e||"'"===e,"expected quote");const t=this.pos;for(;!this.eof()&&this.peek()!==e;)"\\"===this.peek()?this.pos+=2:this.pos++;this.assert(!this.eof(),"unterminated string");const n=this.source.slice(t,this.pos);return this.pos++,n.replace(/\\(.)/g,"$1")}assert(e,t){e||r(364,String(this.pos+1),t,this.source)}}function pe(e){const t=new Set,n=[],o=[];if(e.skipWhitespace(),"*"===e.peek())e.consume();else if(fe.test(e.peek())){const n=e.readIdent();n&&t.add(n.toUpperCase())}for(;!e.eof();){const t=e.peek();if("."===t){e.consume();const t=e.readIdent();e.assert(""!==t,'expected class name after "."'),o.push(t)}else if("#"===t){e.consume();const t=e.readIdent();e.assert(""!==t,'expected id after "#"'),n.push(se("id",t))}else{if("["!==t)break;{e.consume(),e.skipWhitespace();const t=e.readIdent();e.assert(""!==t,'expected attribute name after "["'),e.skipWhitespace();let o=!0;if("="===e.peek()){e.consume(),e.skipWhitespace();const t=e.peek();'"'===t||"'"===t?o=e.readQuoted():(o=e.readIdent(),e.assert(""!==o,"expected attribute value")),e.skipWhitespace()}e.assert("]"===e.peek(),'expected "]"'),e.consume(),n.push(se(t,o))}}}return o.length>0&&n.push(re(o)),{predicates:n,tags:t}}function he(e){const t=new de(e,0),n=[];for(;;){const e=pe(t);if(n.push(e),t.skipWhitespace(),t.eof())break;t.assert(","===t.peek(),'expected "," (selector lists are the only supported combinator)'),t.consume(),t.skipWhitespace()}if(1===n.length)return ne(n[0].tags,n[0].predicates);const o=new Set;for(const e of n)for(const t of e.tags)o.add(t);return ne(o,[(e,t)=>{for(const o of n){const n=e.nodeName;if(o.tags.size>0&&!o.tags.has(n))continue;let r=!0;for(const n of o.predicates)if(!n(e,t)){r=!1;break}if(r)return!0}return!1}])}function me(e){return e}function ge(e,t,n){return m(E,e,t,n)}const xe=ge("importSource",()=>"unknown"),ye=ge("importSourceDataTransfer",()=>null),$e=ge("textFormat",()=>0),Se=ge("textStyle",()=>({}));function Ee(e){if(!t.isHTMLElement(e))return!1;if("PRE"===e.nodeName)return!0;const n=e.style.whiteSpace;return"string"==typeof n&&n.startsWith("pre")}function Ce(e){if(t.isDOMTextNode(e))return!0;if(!t.isHTMLElement(e))return!1;const n=e.style.display;return n?n.startsWith("inline"):!t.isBlockDomNode(e)&&t.isInlineDomNode(e)}const De=ge("whitespaceConfig",()=>({isInline:Ce,preservesWhitespace:Ee})),Ne=ge("importOverlays",()=>[]);class Ie{constructor(e){this.record=e}get(e){return i(this.record,e)}set(e,t){this.record[e.key]=t}update(e,t){this.record[e.key]=t(i(this.record,e))}has(e){return Object.prototype.hasOwnProperty.call(this.record,e.key)}}function Oe(e){const t=o.getPeerDependencyFromEditor(e,S);return t?t.output.defaults:void 0}function ve(e,n=t.$getEditor()){return i(function(e){return l(E,e)||Oe(e)}(n),e)}const Me=h(E,Oe);function ke(e){return t.$isBlockElementNode(e)||t.$isDecoratorNode(e)&&!e.isInline()}function Te(e,n){if(!t.isHTMLElement(n))return e;const o=n.style.textAlign;if(!Pe(o))return e;for(const n of e)t.$isBlockElementNode(n)&&""===n.getFormatType()&&n.setFormat(o);return e}function Re(e,n,o){1===e.length&&t.$isLineBreakNode(e[0])&&(e=[]);const r=t.$createParagraphNode();if(t.isHTMLElement(o)){const e=o.style.textAlign;Pe(e)&&r.setFormat(e)}return[r.splice(0,0,e)]}const be={$accepts:ke,$packageRun:Re,name:"BlockSchema"},we={$accepts:e=>!ke(e),name:"InlineSchema"},Le={$accepts:ke,$packageRun:e=>e,name:"NestedBlockSchema"},Ae={$accepts:ke,$packageRun:Re,name:"RootSchema"},_e=ae,Fe=new Set(["center","end","justify","left","right","start"]);function Pe(e){return Fe.has(e)}const Be={B:{fontWeight:"bold"},EM:{fontStyle:"italic"},I:{fontStyle:"italic"},S:{textDecoration:"line-through"},STRONG:{fontWeight:"bold"},SUB:{verticalAlign:"sub"},SUP:{verticalAlign:"super"},U:{textDecoration:"underline"}},He={CODE:t.IS_CODE,MARK:t.IS_HIGHLIGHT};const We=new Set(["font-weight","font-style","text-decoration","vertical-align"]);const Ue={$import:(e,n)=>{const o=e.get($e),r=Be[n.nodeName],s=function(e){return{fontStyle:e.style.fontStyle,fontWeight:e.style.fontWeight,textDecoration:e.style.textDecoration,verticalAlign:e.style.verticalAlign}}(n),i=r?(c=r,{fontStyle:(l=s).fontStyle||c.fontStyle,fontWeight:l.fontWeight||c.fontWeight,textDecoration:l.textDecoration||c.textDecoration,verticalAlign:l.verticalAlign||c.verticalAlign}):s;var c,l;let u=(a=o,f=function(e){let n=0,o=0;const{fontWeight:r,fontStyle:s,textDecoration:i,verticalAlign:c}=e;if("700"===r||"bold"===r?n|=t.IS_BOLD:"normal"!==r&&"400"!==r||(o|=t.IS_BOLD),"italic"===s?n|=t.IS_ITALIC:"normal"===s&&(o|=t.IS_ITALIC),i){const e=i.split(" ");e.includes("underline")&&(n|=t.IS_UNDERLINE),e.includes("line-through")&&(n|=t.IS_STRIKETHROUGH),e.includes("none")&&(o|=t.IS_UNDERLINE|t.IS_STRIKETHROUGH)}return"sub"===c?(n|=t.IS_SUBSCRIPT,o|=t.IS_SUPERSCRIPT):"super"===c?(n|=t.IS_SUPERSCRIPT,o|=t.IS_SUBSCRIPT):"baseline"===c&&(o|=t.IS_SUBSCRIPT|t.IS_SUPERSCRIPT),{clear:o,set:n}}(i),a&~f.clear|f.set);var a,f;const p=He[n.nodeName];return p&&(u|=p),u===o?e.$importChildren(n):e.$importChildren(n,{context:[d($e,u)]})},match:_e.tag("b","strong","em","i","code","mark","s","sub","sup","u","span"),name:"@lexical/html/inline-format"};function je(e,n,o){let r=e;for(;;){let e=null;for(;null===(e=n?r.nextSibling:r.previousSibling);){const e=r.parentNode;if(null===e)return null;r=e}if(r=e,!o.isInline(r))return null;let s=r;for(;null!==(s=n?r.firstChild:r.lastChild);)r=s;if(t.isDOMTextNode(r))return r;if("BR"===r.nodeName)return null}}function ze(e,n){return 0!==n&&t.$isTextNode(e)?e.setFormat(n):e}function Ve(e,n){if(t.$isTextNode(e)){const t=function(e){let t="";for(const n in e)We.has(n)||(t+=`${n}: ${e[n]}; `);return t.trimEnd()}(n);""!==t&&e.setStyle(t)}return e}const Ge={$import:(e,n)=>{const o=e.get($e),r=e.get(Se),s=e.get(De);if(function(e,t){let n=e.parentNode;for(;null!==n;){if(t.preservesWhitespace(n))return!0;n=n.parentNode}return!1}(n,s)){const e=t.$generateNodesFromRawText(n.textContent||"");for(const t of e)ze(t,o),Ve(t,r);return e}const i=function(e,t){let n=(e.textContent||"").replace(/\r/g,"").replace(/[ \t\n]+/g," ");if(0===n.length)return"";if(" "===n[0]){let o=e,r=!0;for(;null!==o&&null!==(o=je(o,!1,t));){const e=o.textContent||"";if(e.length>0){/[ \t\n]$/.test(e)&&(n=n.slice(1)),r=!1;break}}r&&(n=n.slice(1))}if(n.length>0&&" "===n[n.length-1]){let o=e,r=!0;for(;null!==o&&null!==(o=je(o,!0,t));)if((o.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){r=!1;break}r&&(n=n.slice(0,-1))}return n}(n,s);if(""===i)return[];const c=t.$createTextNode(i);return ze(c,o),Ve(c,r),[c]},match:_e.text(),name:"@lexical/html/#text"},qe={$import:()=>[],match:_e.tag("script","style"),name:"@lexical/html/script-style-ignore"},Ke={$import:(e,n)=>t.isOnlyChildInBlockNode(n)||t.isLastChildInBlockNode(n)?[]:[t.$createLineBreakNode()],match:_e.tag("br"),name:"@lexical/html/br"},Je=[qe,{$import:(e,n)=>{const o=t.$createParagraphNode();if(t.$setFormatFromDOM(o,n),t.setNodeIndentFromDOM(n,o),""===o.getFormatType()){const e=n.getAttribute("align");e&&Pe(e)&&o.setFormat(e)}return t.$setDirectionFromDOM(o,n),[o.splice(0,0,e.$importChildren(n))]},match:_e.tag("p"),name:"@lexical/html/p"},{$import:(e,n,o)=>t.isBlockDomNode(n)?Te(e.$importChildren(n,{schema:be}),n):o(),match:_e.any(),name:"@lexical/html/transparent-block"},Ge,Ke,Ue];function Qe(e,t){const n=[];let o=0,r=0;for(;o<e.length&&r<t.length;)e[o]<=t[r]?n.push(e[o++]):n.push(t[r++]);for(;o<e.length;)n.push(e[o++]);for(;r<t.length;)n.push(t[r++]);return n}function Ye(e){const t=[],n=new Map,o=[],s=[],i=[],c=new Set;e.forEach((e,l)=>{const u=function(e){const t=e[te];return void 0===t&&r(360),t}(e.match),a=e.name||function(e,t){if("text"===e.kind)return`#text@${t}`;if("comment"===e.kind)return`#comment@${t}`;if(0===e.tags.size)return`*@${t}`;const n=Array.from(e.tags).join(",").toLowerCase();return`${n}@${t}`}(u,l);if(e.name&&c.add(e.name),t.push({$import:e.$import,name:a,predicate:u.predicate}),"text"===u.kind)s.push(l);else if("comment"===u.kind)i.push(l);else if(0===u.tags.size)o.push(l);else for(const e of u.tags){let t=n.get(e);t||(t=[],n.set(e,t)),t.push(l)}});const l=new Map;if(0===o.length)for(const[e,t]of n)l.set(e,t);else for(const[e,t]of n)l.set(e,Qe(t,o));return{byTag:l,commentIndices:i,rules:t,textIndices:s,wildcardIndices:o}}function Ze(e,n){return t.isDOMTextNode(n)?e.textIndices:8===n.nodeType?e.commentIndices:t.isHTMLElement(n)?e.byTag.get(n.nodeName)||e.wildcardIndices:Xe}const Xe=Object.freeze([]);function et(e){const t=[];for(const n of e)if(tt(n))for(const e of n.rules)t.push(e);else t.push(n);return t}function tt(e){return"object"==typeof e&&null!==e&&"__type"in e&&"CompiledOverlayRules"===e.__type}const nt=Object.freeze({});function ot(e,t){const n={$importChildren:(t,n)=>function(e,t,n){const o=n&&n.rules?n.rules.dispatch:void 0;o&&e.overlays.push(o);try{const o=()=>rt(e,t,n);return n&&n.context?Me(n.context,e.editor)(o):o()}finally{o&&e.overlays.pop()}}(e,t,n),$importOne:(t,n)=>st(e,t,n),captures:t,get:t=>ve(t,e.editor),session:e.session};return n}function rt(e,t,n){const o=n&&n.$onChild,r=[];for(const n of Array.from(t.childNodes)){const t=st(e,n,void 0);for(const e of t){const t=o?o(e):e;null!=t&&r.push(t)}}const s=n&&n.$after?n.$after(r):r,i=n&&n.schema;return i?function(e,t,n,o){const r=[];let s=null;const i=()=>{if(null===s)return;const t=s;if(s=null,e.$packageRun){const s=e.$packageRun(t,n,o);if(s.length>0){for(const e of s)r.push(e);return}}if("hoist"===e.onReject)for(const e of t)r.push(e)};for(const o of t)e.$accepts(o,n)?(i(),r.push(o)):(null===s&&(s=[]),s.push(o));return i(),e.$finalize?e.$finalize(r,n):r}(i,s,null,t):s}function st(e,t,n){const o=()=>function(e,t){const n=function(e,t){const n=[];for(let o=e.overlays.length-1;o>=0;o--){const r=e.overlays[o],s=Ze(r,t);s.length>0&&n.push({dispatch:r,indices:s})}const o=Ze(e.dispatch,t);o.length>0&&n.push({dispatch:e.dispatch,indices:o});return n}(e,t);if(0===n.length)return it(e,t);let o=0,r=0;const s=()=>{for(;o<n.length;){const{dispatch:i,indices:c}=n[o];for(;r<c.length;){const n=c[r++],o=i.rules[n],l={};if(o.predicate(t,l)){const n=ot(e,0===Object.keys(l).length?nt:l);try{return o.$import(n,t,s)}catch(e){throw e}}}o++,r=0}return it(e,t)};return s()}(e,t);return n&&n.context?Me(n.context,e.editor)(o):o()}function it(e,t){if(0===t.childNodes.length)return[];const n=[];for(const o of Array.from(t.childNodes)){const t=st(e,o,void 0);for(const e of t)n.push(e)}return n}const ct={$import:(e,t)=>e.$importChildren(t),match:ae.any(),name:"@lexical/html/default-hoist"},lt=t.defineExtension({build(e,n){const o=Ye(et(n.rules)),r=a(n.contextDefaults,void 0),s=n.preprocess;return{$generateNodesFromDOM:(n,i)=>{const c=i&&i.context?a(i.context,r):r,l=void 0!==c&&c!==r?c:Object.create(r||null),u=new Ie(l),f={session:u};return function(e,t,n){let o=e.length-1;const r=()=>{for(;o>=0;)return void(0,e[o--])(t,n,r)};r()}(i&&i.preprocess?[...s,...i.preprocess]:s,n,f),p(E,l,()=>function(e,n,o,r){return rt({dispatch:e,editor:n,overlays:r.get(Ne).map(e=>e.dispatch),session:r},t.isDOMDocumentNode(o)?o.body:o,{schema:Ae})}(o,e,n,u),e)},defaults:r}},config:{contextDefaults:[],preprocess:[g],rules:[ct]},mergeConfig:(e,n)=>t.shallowMergeConfig(e,{...n,...n.contextDefaults&&{contextDefaults:[...e.contextDefaults,...n.contextDefaults]},...n.preprocess&&{preprocess:[...e.preprocess,...n.preprocess]},...n.rules&&{rules:[...n.rules,...e.rules]}}),name:S});const ut=t.defineExtension({dependencies:[t.configExtension(lt,{rules:Je})],name:"@lexical/html/CoreImport"}),at=[{$import:()=>[o.$createHorizontalRuleNode()],match:ae.tag("hr"),name:"@lexical/html/hr"}],ft=t.defineExtension({dependencies:[o.HorizontalRuleExtension,t.configExtension(lt,{rules:at})],name:"@lexical/html/HorizontalRuleImport"}),dt={any:ae.any,comment:ae.comment,css:he,tag:ae.tag,text:ae.text},pt=new Set(["STYLE","SCRIPT"]);function ht(e,n=null,o=t.$getEditor()){return k([d(I,!0)],o)(()=>{const r=t.$getRoot(),s=M(o),i=e.append.bind(e);for(const e of r.getChildren())mt(o,e,i,n,s);return e})}function mt(n,o,r,s=null,i=t.$getEditorDOMRenderConfig(n)){let c=i.$shouldInclude(o,s,n);const l=i.$shouldExclude(o,s,n);let u=o;null!==s&&t.$isTextNode(o)&&(u=e.$sliceSelectedTextNodeContent(s,o,"clone"));const a=i.$exportDOM(u,n),{element:f,after:d,append:p,$getChildNodes:h}=a;if(!f)return!1;const m=document.createDocumentFragment(),g=h?h():t.$isElementNode(u)?u.getChildren():[],x=m.append.bind(m);for(const e of g){const t=mt(n,e,x,s,i);!c&&t&&i.$extractWithChild(o,e,s,"html",n)&&(c=!0)}if(c&&!l){if((t.isHTMLElement(f)||t.isDocumentFragment(f))&&(p?p(m):f.append(m)),r(f),d){const e=d.call(u,f);e&&(t.isDocumentFragment(f)?f.replaceChildren(e):f.replaceWith(e))}}else r(m);return c}function gt(e,n,o,r,s=new Map,i){const c=[];if(pt.has(e.nodeName))return c;let l=null;const u=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let r=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===r||(r.priority||0)<=(n.priority||0))&&(r=n)}return null!==r?r.conversion:null}(e,n),a=u?u(e):null;let f=null;if(null!==a){f=a.after;const t=a.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of s)if(l=e(l,i),!l)break;l&&c.push(...Array.isArray(t)?t:[l])}null!=a.forChild&&s.set(e.nodeName,a.forChild)}const d=e.childNodes;let p=[];const h=(null==l||!t.$isRootOrShadowRoot(l))&&(null!=l&&t.$isBlockElementNode(l)||r);for(let e=0;e<d.length;e++)p.push(...gt(d[e],n,o,h,new Map(s),l));if(null!=f&&(p=f(p)),t.isBlockDomNode(e)&&(p=xt(e,p,h?()=>{const e=new t.ArtificialNode__DO_NOT_USE;return o.push(e),e}:t.$createParagraphNode)),null==l)if(p.length>0)for(const e of p)c.push(e);else t.isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return!1;return t.isInlineDomNode(e.nextSibling)&&t.isInlineDomNode(e.previousSibling)}(e)&&c.push(t.$createLineBreakNode());else t.$isElementNode(l)&&l.append(...p);return c}function xt(e,n,o){const r=e.style.textAlign,s=[];let i=[];for(let e=0;e<n.length;e++){const c=n[e];if(t.$isBlockElementNode(c))r&&!c.getFormat()&&c.setFormat(r),s.push(c);else if(i.push(c),e===n.length-1||e<n.length-1&&t.$isBlockElementNode(n[e+1])){const e=o();e.setFormat(r),e.append(...i),s.push(e),i=[]}}return s}exports.$distributeInlineWrapper=function e(n,o){const r=[];let s=[];const i=()=>{0!==s.length&&(r.push(o().splice(0,0,s)),s=[])};for(const c of n)if(ke(c)){if(i(),t.$isElementNode(c)){const t=e(c.getChildren(),o);c.splice(0,c.getChildrenSize(),t)}r.push(c)}else s.push(c);return i(),r},exports.$generateDOMFromNodes=ht,exports.$generateDOMFromRoot=function(e,n=t.$getRoot()){const o=t.$getEditor();return k([d(I,!0),d(N,!0)],o)(()=>{const t=M(o),r=e.append.bind(e);return mt(o,n,r,null,t),e})},exports.$generateHtmlFromNodes=function(e,n=null){return("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)&&r(338),t.$assumeActiveEditor(e),ht(document.createElement("div"),n,e).innerHTML},exports.$generateNodesFromDOM=function(e,n){x(n);const o=t.isDOMDocumentNode(n)?n.body.childNodes:n.childNodes,r=[],s=[];for(const t of o)if(!pt.has(t.nodeName)){const n=gt(t,e,s,!1);if(null!==n)for(const e of n)r.push(e)}return function(e){for(const n of e)n.getParent()&&n.getNextSibling()instanceof t.ArtificialNode__DO_NOT_USE&&n.insertAfter(t.$createLineBreakNode());for(const t of e){const e=t.getParent();e&&e.splice(t.getIndexWithinParent(),1,t.getChildren())}}(s),r},exports.$generateNodesFromDOMViaExtension=function(e,t){return o.$getExtensionOutput(lt).$generateNodesFromDOM(e,t)},exports.$getImportContextValue=ve,exports.$getRenderContextValue=function(e,n=t.$getEditor()){return i(function(e){return l($,e)||O(e)}(n),e)},exports.$getSessionDOMRenderConfig=M,exports.$inlineStylesFromStyleSheets=g,exports.$isBlockLevel=ke,exports.$propagateTextAlignToBlockChildren=Te,exports.$setRenderContextValue=function(e,n,o=t.$getEditor()){const r=v(o);r&&r.setContextValue(e,n)},exports.$updateRenderContextValue=function(e,n,o=t.$getEditor()){const r=v(o);r&&r.setContextValue(e,n(i(r.editorContext,e)))},exports.$withImportContext=Me,exports.$withRenderContext=k,exports.BlockSchema=be,exports.CoreImportExtension=ut,exports.CoreImportRules=Je,exports.DOMImportExtension=lt,exports.DOMRenderExtension=ee,exports.HorizontalRuleImportExtension=ft,exports.HorizontalRuleImportRules=at,exports.ImportOverlays=Ne,exports.ImportSource=xe,exports.ImportSourceDataTransfer=ye,exports.ImportTextFormat=$e,exports.ImportTextStyle=Se,exports.ImportWhitespaceConfig=De,exports.InlineSchema=we,exports.NestedBlockSchema=Le,exports.RenderContextExport=I,exports.RenderContextRoot=N,exports.RootSchema=Ae,exports.contextUpdater=function(e,t){return{cfg:e,updater:t}},exports.contextValue=d,exports.createImportState=ge,exports.createRenderState=D,exports.defaultIsInline=Ce,exports.defaultPreservesWhitespace=Ee,exports.defineImportRule=me,exports.defineOverlayRules=function(e){const t=et(e);return{__type:"CompiledOverlayRules",dispatch:Ye(t),rules:t}},exports.domOverride=function(e,t,n){return{...t,...n,nodes:e}},exports.isElementOfTag=function(e,n){return t.isHTMLElement(e)&&e.nodeName===n.toUpperCase()},exports.parseSelector=he,exports.sel=dt;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$sliceSelectedTextNodeContent as t}from"@lexical/selection";import{$getEditor as e,createState as n,isDOMDocumentNode as o,isHTMLElement as r,$getEditorDOMRenderConfig as s,DEFAULT_EDITOR_DOM_CONFIG as i,$isLexicalNode as c,getStaticNodeConfig as l,$fullReconcile as u,defineExtension as f,shallowMergeConfig as a,RootNode as p,isDOMTextNode as d,isBlockDomNode as h,isInlineDomNode as g,IS_HIGHLIGHT as m,IS_CODE as y,$generateNodesFromRawText as x,$createTextNode as S,$createLineBreakNode as $,$createParagraphNode as v,$setFormatFromDOM as b,setNodeIndentFromDOM as C,$setDirectionFromDOM as k,$isTextNode as O,IS_BOLD as w,IS_ITALIC as D,IS_UNDERLINE as M,IS_STRIKETHROUGH as A,IS_SUBSCRIPT as N,IS_SUPERSCRIPT as I,$isElementNode as E,$isBlockElementNode as W,$isDecoratorNode as R,configExtension as j,$getRoot as T,isDocumentFragment as F,$isRootOrShadowRoot as P,ArtificialNode__DO_NOT_USE as z}from"lexical";import{objectKlassEquals as _}from"@lexical/utils";import{getPeerDependencyFromEditor as L,getKnownTypesAndNodes as U,$getExtensionOutput as B,HorizontalRuleExtension as V,$createHorizontalRuleNode as q}from"@lexical/extension";function G(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let H;function J(t,e){const{key:n}=e;return t&&n in t?t[n]:e.defaultValue}function Q(t){return H&&H.editor===t?H:void 0}function K(t,e){const n=Q(e);return n&&n[t]}function Y(t,e){if("cfg"in e){const{cfg:n,updater:o}=e;return[n,o(J(t,n))]}return e}function Z(t,e){let n=e;for(const o of t){const[t,r]=Y(n,o),s=t.key;if(n===e&&J(n,t)===r)continue;const i=n===e||void 0===n?X(e):n;i[s]=r,n=i}return n}function X(t){return Object.create(t||null)}function tt(t,e){return[t,e]}function et(t,e){return{cfg:t,updater:e}}function nt(t,n,o,r=e()){const s=H,i=Q(r);try{return H={...i,editor:r,[t]:n},o()}finally{H=s}}function ot(t,n=()=>{}){return(o,r=e())=>e=>{const s=Q(r),i=s&&s[t],c=Z(o,i||n(r));return c&&c!==i?nt(t,c,e,r):e()}}function rt(t,e,o,r){return Object.assign(n(Symbol(e),{isEqual:r,parse:o}),{[t]:!0})}const st=(t,e,n)=>{it(t),n()};function it(t){if(!o(t))return;const e=t;if(null===e.querySelector("style"))return;const n=new Map;function s(t){let e=n.get(t);if(void 0===e){e=new Set;for(let n=0;n<t.style.length;n++)e.add(t.style[n]);n.set(t,e)}return e}try{for(const t of Array.from(e.styleSheets)){let n;try{n=t.cssRules}catch(t){continue}for(const t of Array.from(n)){if(!_(t,CSSStyleRule))continue;let n;try{n=e.querySelectorAll(t.selectorText)}catch(t){continue}for(const e of Array.from(n)){if(!r(e))continue;const n=s(e);for(let o=0;o<t.style.length;o++){const r=t.style[o];n.has(r)||e.style.setProperty(r,t.style.getPropertyValue(r),t.style.getPropertyPriority(r))}}}}}catch(t){}}const ct="@lexical/html/DOM",lt=Symbol.for("@lexical/html/DOMExportContext"),ut="@lexical/html/DOMImport",ft=Symbol.for("@lexical/html/DOMImportContext"),at=()=>!0;function pt(t,e,n){return rt(lt,t,e,n)}const dt=pt("root",Boolean),ht=pt("isExport",Boolean);function gt(t){const e=L(t,ct);return e?e.output.defaults:void 0}function mt(t,n=e()){return J(function(t){return K(lt,t)||gt(t)}(n),t)}function yt(t){const e=L(t,ct);return e?e.output.runtime:void 0}function xt(t,n,o=e()){const r=yt(o);r&&r.setContextValue(t,n)}function St(t,n,o=e()){const r=yt(o);r&&r.setContextValue(t,n(J(r.editorContext,t)))}function $t(t=e()){const n=yt(t);return n?n.getSessionConfig():s(t)}const vt=ot(lt,gt);function bt(t,e,n){return{...e,...n,nodes:t}}function Ct(t){return e=>e instanceof t}function kt(t,{nodes:e}){if("*"===e)return at;let n={};const o=[];for(const r of e)if("getType"in r){const e=r.getType();if(n){const o=t[e];void 0===o&&G(339,r.name,e),n=Object.assign(n,o.types)}o.push(Ct(r))}else n=void 0,o.push(r);return n||(1===o.length?o[0]:t=>{for(const e of o)if(e(t))return!0;return!1})}function Ot(t){return(e,n,o)=>t(e,o)}function wt(t){return(e,n,o,r)=>t(e,n,r)}function Dt(t){return(e,n,o,r,s)=>t(e,n,o,s)}function Mt(t){return(e,n,o,r,s,i)=>t(e,n,o,r,i)}function At(t,e){return(n,o)=>{const r=()=>t(n,o),s=e(n);return s?s(n,r,o):r()}}function Nt(t,e){return(n,o,r)=>{const s=()=>t(n,o,r),i=e(n);return i?i(n,o,s,r):s()}}const It=Nt,Et=wt;function Wt(t,e){return(n,o,r,s)=>{const i=()=>t(n,o,r,s),c=e(n);return c?c(n,o,r,i,s):i()}}function Rt(t,e){return(n,o,r,s,i)=>{const c=()=>t(n,o,r,s,i),l=e(n);return l?l(n,o,r,s,c,i):c()}}function jt(t,e){return(n,o,r,s)=>{t(n,o,r,s);const i=e(n);i&&i(n,o,r,s)}}function Tt(t,e,n,o,r){let s=n[e];for(const n of t[e])if("function"==typeof n[0]){const[t,e]=n;s=o(s,n=>t(n)&&e||void 0)}else{const t=n[1],e={};for(const n in t){const r=t[n];r&&(e[n]=r.reduce((t,e)=>o(t,()=>e),s))}s=o(s,t=>{const n=e[t.getType()];return n&&r(n)})}n[e]=s}function Ft(t,e,n,o){if(!o)return;const r=t[e];if("function"==typeof n)r.push([n,o]);else{const t=r[r.length-1];let e;t&&"types"===t[0]?e=t[1]:(e={},r.push(["types",e]));for(const t in n){const n=e[t]||[];e[t]=n,n.push(o)}}}function Pt(t){return"*"===t.nodes}function zt(t,e){const n=function(t){const e={},{nodes:n}=U(t);for(const t of n)e[t.getType()]={klass:t,types:{}};for(const t of Object.values(e))if(t){const n=t.klass.getType();for(let{klass:o}=t;c(o.prototype);o=Object.getPrototypeOf(o)){const{ownNodeType:t}=l(o),r=t&&e[t];r&&(r.types[n]=!0)}}return e}(t),o={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const t of function(t){const e=[],n=[],o=[];for(const r of t)if(Pt(r))e.push(r);else if(Array.isArray(r.nodes))for(const t of r.nodes)c(t.prototype)?o.push(1===r.nodes.length?r:{...r,nodes:[t]}):n.push(1===r.nodes.length?r:{...r,nodes:[t]});const r=new Map,s=t=>{let e=r.get(t);if(void 0===e){e=0;for(let n=t;c(n.prototype);n=Object.getPrototypeOf(n))e++;r.set(t,e)}return e};return o.sort((t,e)=>s(t.nodes[0])-s(e.nodes[0])),[...o,...n,...e]}(e)){const e=kt(n,t);for(const n in o){Ft(o,n,e,t[n])}}return o}function _t(t){return t}function Lt(t,{overrides:e}){const n=zt(t,e),o={...i,...t.dom};return Tt(n,"$createDOM",o,At,Ot),Tt(n,"$exportDOM",o,At,Ot),Tt(n,"$extractWithChild",o,Rt,Mt),Tt(n,"$getDOMSlot",o,It,Et),Tt(n,"$shouldExclude",o,Nt,wt),Tt(n,"$shouldInclude",o,Nt,wt),Tt(n,"$updateDOM",o,Wt,Dt),Tt(n,"$decorateDOM",o,jt,_t),o}function Ut(t){return{get:e=>J(t,e)}}function Bt(t){const e=Object.create(null);return Z(t,e)||e}function Vt(t,e){const n=Ut(e);return t.filter(t=>!(t.disabledForEditor&&t.disabledForEditor(n)))}function qt(t){if("*"===t.nodes)return()=>!0;const e=t.nodes.map(t=>{const e=t;return c(e.prototype)?t=>t instanceof e:t});return t=>e.some(e=>e(t))}class Gt{editor;initialEditorConfig;overrides;editorContext;hasSessionGates;installed;sessionCache=new Map;constructor(t,e,n,o){this.editor=t,this.initialEditorConfig=e,this.overrides=n,this.editorContext=o,this.installed=Vt(n,o),this.hasSessionGates=n.some(t=>t.disabledForSession)}setContextValue(t,e){const n=this.installed;this.editorContext[t.key]=e;const o=Vt(this.overrides,this.editorContext);if(function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(n,o))return;const r=function(t,e){const n=new Set(t),o=new Set(e),r=[];for(const e of t)o.has(e)||r.push(e);for(const t of e)n.has(t)||r.push(t);return r}(n,o);this.installed=o,this.sessionCache.clear();const s=Lt(this.initialEditorConfig,{overrides:o});this.editor._config.dom=s;const i=function(t){const e=[];for(const n of t)(n.$createDOM||n.$getDOMSlot||n.$decorateDOM)&&e.push(qt(n));return 0===e.length?null:t=>e.some(e=>e(t))}(r);if(!i)return;const c=s.$updateDOM;s.$updateDOM=(t,e,n,o)=>!!i(t)||c(t,e,n,o),this.editor.update(u,{discrete:!0}),s.$updateDOM=c}getSessionConfig(){const t=this.editor._config.dom||i;if(!this.hasSessionGates)return t;const e=Ut(K(lt,this.editor)||this.editorContext),n=[],o=[];if(this.installed.forEach((t,r)=>{t.disabledForSession&&t.disabledForSession(e)?n.push(String(r)):o.push(t)}),0===n.length)return t;const r=n.join(",");let s=this.sessionCache.get(r);return s||(s=Lt(this.initialEditorConfig,{overrides:o}),this.sessionCache.set(r,s)),s}}const Ht=f({build(t,e,n){const{initialEditorConfig:o}=n.getInitResult(),r=Bt(e.contextDefaults);return{defaults:r,runtime:new Gt(t,o,e.overrides,r)}},config:{contextDefaults:[],overrides:[]},html:{export:new Map([[p,()=>{const t=document.createElement("div");return t.role="textbox",{element:t}}]])},init(t,e){const n={dom:t.dom,nodes:t.nodes},o=Bt(e.contextDefaults),r=Vt(e.overrides,o);return t.dom=Lt(t,{overrides:r}),{initialEditorConfig:n}},mergeConfig(t,e){const n=a(t,e);for(const o of["overrides","contextDefaults"])e[o]&&(n[o]=[...t[o],...e[o]]);return n},name:ct}),Jt=Symbol.for("@lexical/html/SelectorImpl");function Qt(t,e){const n={kind:"element",predicate:(o=e,0===o.length?r:1===o.length?o[0]:(t,e)=>{for(const n of o)if(!n(t,e))return!1;return!0}),tags:t};var o;const s=n=>Qt(t,[...e,n]);return{[Jt]:n,attr:(t,e,n)=>s(Zt(t,e,n)),classAll:(...t)=>s(Yt(t)),classAny:(...t)=>s(function(t){const e=Kt(t);if(0===e.length)return()=>!1;return t=>{if(!r(t))return!1;const n=t.classList;for(const t of e)if(n.contains(t))return!0;return!1}}(t)),styleAny:(t,e,n)=>s(function(t,e,n){if("string"==typeof e)return n=>r(n)&&n.style.getPropertyValue(t)===e;if(e instanceof RegExp){const o=n&&n.capture,s=e;return(e,n)=>{if(!r(e))return!1;const i=e.style.getPropertyValue(t);if(!i)return!1;const c=i.match(s);return null!==c&&(void 0!==o&&(n[o]=c),!0)}}G(362,JSON.stringify(t))}(t,e,n))}}function Kt(t){const e=[];for(const n of t)n&&e.push(n);return e}function Yt(t){const e=Kt(t);return 0===e.length?()=>!0:t=>{if(!r(t))return!1;const n=t.classList;for(const t of e)if(!n.contains(t))return!1;return!0}}function Zt(t,e,n){if(!0===e)return e=>r(e)&&e.hasAttribute(t);if("string"==typeof e)return n=>r(n)&&n.getAttribute(t)===e;if(e instanceof RegExp){const o=n&&n.capture,s=e;return(e,n)=>{if(!r(e))return!1;const i=e.getAttribute(t);if(null==i)return!1;const c=i.match(s);return null!==c&&(void 0!==o&&(n[o]=c),!0)}}G(361,JSON.stringify(t))}const Xt={kind:"text",predicate:d,tags:new Set},te={[Jt]:Xt},ee={kind:"comment",predicate:t=>8===t.nodeType,tags:new Set},ne={[Jt]:ee},oe={any:()=>Qt(new Set,[]),comment:()=>ne,tag(...t){t.length>0||G(363);const e=new Set;for(const n of t)e.add(n.toUpperCase());return Qt(e,[])},text:()=>te};function re(t,e){return r(t)&&t.nodeName===e.toUpperCase()}const se=/[A-Za-z0-9_-]/;class ie{constructor(t,e){this.source=t,this.pos=e}peek(t=0){return this.source[this.pos+t]||""}consume(){return this.source[this.pos++]||""}eof(){return this.pos>=this.source.length}skipWhitespace(){for(;!this.eof()&&/\s/.test(this.peek());)this.pos++}readIdent(){const t=this.pos;for(;!this.eof()&&se.test(this.peek());)this.pos++;return this.source.slice(t,this.pos)}readQuoted(){const t=this.consume();this.assert('"'===t||"'"===t,"expected quote");const e=this.pos;for(;!this.eof()&&this.peek()!==t;)"\\"===this.peek()?this.pos+=2:this.pos++;this.assert(!this.eof(),"unterminated string");const n=this.source.slice(e,this.pos);return this.pos++,n.replace(/\\(.)/g,"$1")}assert(t,e){t||G(364,String(this.pos+1),e,this.source)}}function ce(t){const e=new Set,n=[],o=[];if(t.skipWhitespace(),"*"===t.peek())t.consume();else if(se.test(t.peek())){const n=t.readIdent();n&&e.add(n.toUpperCase())}for(;!t.eof();){const e=t.peek();if("."===e){t.consume();const e=t.readIdent();t.assert(""!==e,'expected class name after "."'),o.push(e)}else if("#"===e){t.consume();const e=t.readIdent();t.assert(""!==e,'expected id after "#"'),n.push(Zt("id",e))}else{if("["!==e)break;{t.consume(),t.skipWhitespace();const e=t.readIdent();t.assert(""!==e,'expected attribute name after "["'),t.skipWhitespace();let o=!0;if("="===t.peek()){t.consume(),t.skipWhitespace();const e=t.peek();'"'===e||"'"===e?o=t.readQuoted():(o=t.readIdent(),t.assert(""!==o,"expected attribute value")),t.skipWhitespace()}t.assert("]"===t.peek(),'expected "]"'),t.consume(),n.push(Zt(e,o))}}}return o.length>0&&n.push(Yt(o)),{predicates:n,tags:e}}function le(t){const e=new ie(t,0),n=[];for(;;){const t=ce(e);if(n.push(t),e.skipWhitespace(),e.eof())break;e.assert(","===e.peek(),'expected "," (selector lists are the only supported combinator)'),e.consume(),e.skipWhitespace()}if(1===n.length)return Qt(n[0].tags,n[0].predicates);const o=new Set;for(const t of n)for(const e of t.tags)o.add(e);return Qt(o,[(t,e)=>{for(const o of n){const n=t.nodeName;if(o.tags.size>0&&!o.tags.has(n))continue;let r=!0;for(const n of o.predicates)if(!n(t,e)){r=!1;break}if(r)return!0}return!1}])}function ue(t){return t}function fe(t,e,n){return rt(ft,t,e,n)}const ae=fe("importSource",()=>"unknown"),pe=fe("importSourceDataTransfer",()=>null),de=fe("textFormat",()=>0),he=fe("textStyle",()=>({}));function ge(t){if(!r(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function me(t){if(d(t))return!0;if(!r(t))return!1;const e=t.style.display;return e?e.startsWith("inline"):!h(t)&&g(t)}const ye=fe("whitespaceConfig",()=>({isInline:me,preservesWhitespace:ge})),xe=fe("importOverlays",()=>[]);class Se{constructor(t){this.record=t}get(t){return J(this.record,t)}set(t,e){this.record[t.key]=e}update(t,e){this.record[t.key]=e(J(this.record,t))}has(t){return Object.prototype.hasOwnProperty.call(this.record,t.key)}}function $e(t){const e=L(t,ut);return e?e.output.defaults:void 0}function ve(t,n=e()){return J(function(t){return K(ft,t)||$e(t)}(n),t)}const be=ot(ft,$e),Ce=oe,ke=new Set(["center","end","justify","left","right","start"]);function Oe(t){return ke.has(t)}const we={B:{fontWeight:"bold"},EM:{fontStyle:"italic"},I:{fontStyle:"italic"},S:{textDecoration:"line-through"},STRONG:{fontWeight:"bold"},SUB:{verticalAlign:"sub"},SUP:{verticalAlign:"super"},U:{textDecoration:"underline"}},De={CODE:y,MARK:m};const Me=new Set(["font-weight","font-style","text-decoration","vertical-align"]);const Ae={$import:(t,e)=>{const n=t.get(de),o=we[e.nodeName],r=function(t){return{fontStyle:t.style.fontStyle,fontWeight:t.style.fontWeight,textDecoration:t.style.textDecoration,verticalAlign:t.style.verticalAlign}}(e),s=o?(i=o,{fontStyle:(c=r).fontStyle||i.fontStyle,fontWeight:c.fontWeight||i.fontWeight,textDecoration:c.textDecoration||i.textDecoration,verticalAlign:c.verticalAlign||i.verticalAlign}):r;var i,c;let l=(u=n,f=function(t){let e=0,n=0;const{fontWeight:o,fontStyle:r,textDecoration:s,verticalAlign:i}=t;if("700"===o||"bold"===o?e|=w:"normal"!==o&&"400"!==o||(n|=w),"italic"===r?e|=D:"normal"===r&&(n|=D),s){const t=s.split(" ");t.includes("underline")&&(e|=M),t.includes("line-through")&&(e|=A),t.includes("none")&&(n|=M|A)}return"sub"===i?(e|=N,n|=I):"super"===i?(e|=I,n|=N):"baseline"===i&&(n|=N|I),{clear:n,set:e}}(s),u&~f.clear|f.set);var u,f;const a=De[e.nodeName];return a&&(l|=a),l===n?t.$importChildren(e):t.$importChildren(e,{context:[tt(de,l)]})},match:Ce.tag("b","strong","em","i","code","mark","s","sub","sup","u","span"),name:"@lexical/html/inline-format"};function Ne(t,e,n){let o=t;for(;;){let t=null;for(;null===(t=e?o.nextSibling:o.previousSibling);){const t=o.parentNode;if(null===t)return null;o=t}if(o=t,!n.isInline(o))return null;let r=o;for(;null!==(r=e?o.firstChild:o.lastChild);)o=r;if(d(o))return o;if("BR"===o.nodeName)return null}}function Ie(t,e){return 0!==e&&O(t)?t.setFormat(e):t}function Ee(t,e){if(O(t)){const n=function(t){let e="";for(const n in t)Me.has(n)||(e+=`${n}: ${t[n]}; `);return e.trimEnd()}(e);""!==n&&t.setStyle(n)}return t}const We={$import:(t,e)=>{const n=t.get(de),o=t.get(he),r=t.get(ye);if(function(t,e){let n=t.parentNode;for(;null!==n;){if(e.preservesWhitespace(n))return!0;n=n.parentNode}return!1}(e,r)){const t=x(e.textContent||"");for(const e of t)Ie(e,n),Ee(e,o);return t}const s=function(t,e){let n=(t.textContent||"").replace(/\r/g,"").replace(/[ \t\n]+/g," ");if(0===n.length)return"";if(" "===n[0]){let o=t,r=!0;for(;null!==o&&null!==(o=Ne(o,!1,e));){const t=o.textContent||"";if(t.length>0){/[ \t\n]$/.test(t)&&(n=n.slice(1)),r=!1;break}}r&&(n=n.slice(1))}if(n.length>0&&" "===n[n.length-1]){let o=t,r=!0;for(;null!==o&&null!==(o=Ne(o,!0,e));)if((o.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){r=!1;break}r&&(n=n.slice(0,-1))}return n}(e,r);if(""===s)return[];const i=S(s);return Ie(i,n),Ee(i,o),[i]},match:Ce.text(),name:"@lexical/html/#text"},Re={$import:()=>[],match:Ce.tag("script","style"),name:"@lexical/html/script-style-ignore"},je={$import:()=>[$()],match:Ce.tag("br"),name:"@lexical/html/br"},Te=[Re,{$import:(t,e)=>{const n=v();if(b(n,e),C(e,n),""===n.getFormatType()){const t=e.getAttribute("align");t&&Oe(t)&&n.setFormat(t)}return k(n,e),[n.splice(0,0,t.$importChildren(e))]},match:Ce.tag("p"),name:"@lexical/html/p"},We,je,Ae];function Fe(t,e){const n=[];let o=0,r=0;for(;o<t.length&&r<e.length;)t[o]<=e[r]?n.push(t[o++]):n.push(e[r++]);for(;o<t.length;)n.push(t[o++]);for(;r<e.length;)n.push(e[r++]);return n}function Pe(t){const e=[],n=new Map,o=[],r=[],s=[],i=new Set;t.forEach((t,c)=>{const l=function(t){const e=t[Jt];return void 0===e&&G(360),e}(t.match),u=t.name||function(t,e){if("text"===t.kind)return`#text@${e}`;if("comment"===t.kind)return`#comment@${e}`;if(0===t.tags.size)return`*@${e}`;const n=Array.from(t.tags).join(",").toLowerCase();return`${n}@${e}`}(l,c);if(t.name&&i.add(t.name),e.push({$import:t.$import,name:u,predicate:l.predicate}),"text"===l.kind)r.push(c);else if("comment"===l.kind)s.push(c);else if(0===l.tags.size)o.push(c);else for(const t of l.tags){let e=n.get(t);e||(e=[],n.set(t,e)),e.push(c)}});const c=new Map;if(0===o.length)for(const[t,e]of n)c.set(t,e);else for(const[t,e]of n)c.set(t,Fe(e,o));return{byTag:c,commentIndices:s,rules:e,textIndices:r,wildcardIndices:o}}function ze(t,e){return d(e)?t.textIndices:8===e.nodeType?t.commentIndices:r(e)?t.byTag.get(e.nodeName)||t.wildcardIndices:_e}const _e=Object.freeze([]);function Le(t){const e=[];for(const n of t)if(Ue(n))for(const t of n.rules)e.push(t);else e.push(n);return e}function Ue(t){return"object"==typeof t&&null!==t&&"__type"in t&&"CompiledOverlayRules"===t.__type}function Be(t){const e=Le(t);return{__type:"CompiledOverlayRules",dispatch:Pe(e),rules:e}}function Ve(t){return W(t)||R(t)&&!t.isInline()}function qe(t,e){const n=[];let o=[];const r=()=>{0!==o.length&&(n.push(e().splice(0,0,o)),o=[])};for(const s of t)if(Ve(s)){if(r(),E(s)){const t=qe(s.getChildren(),e);s.splice(0,s.getChildrenSize(),t)}n.push(s)}else o.push(s);return r(),n}function Ge(t,e,n){const o=v();if(r(n)){const t=n.style.textAlign;Oe(t)&&o.setFormat(t)}return[o.splice(0,0,t)]}const He={$accepts:Ve,$packageRun:Ge,name:"BlockSchema"},Je={$accepts:t=>!Ve(t),name:"InlineSchema"},Qe={$accepts:Ve,$packageRun:t=>t,name:"NestedBlockSchema"},Ke={$accepts:Ve,$packageRun:Ge,name:"RootSchema"},Ye=Object.freeze({});function Ze(t,e){const n={$importChildren:(e,n)=>function(t,e,n){const o=n&&n.rules?n.rules.dispatch:void 0;o&&t.overlays.push(o);try{const o=()=>Xe(t,e,n);return n&&n.context?be(n.context,t.editor)(o):o()}finally{o&&t.overlays.pop()}}(t,e,n),$importOne:(e,n)=>tn(t,e,n),captures:e,get:e=>ve(e,t.editor),session:t.session};return n}function Xe(t,e,n){const o=n&&n.$onChild,r=[];for(const n of Array.from(e.childNodes)){const e=tn(t,n,void 0);for(const t of e){const e=o?o(t):t;null!=e&&r.push(e)}}const s=n&&n.$after?n.$after(r):r,i=n&&n.schema;return i?function(t,e,n,o){const r=[];let s=null;const i=()=>{if(null===s)return;const e=s;if(s=null,t.$packageRun){const s=t.$packageRun(e,n,o);if(s.length>0){for(const t of s)r.push(t);return}}if("hoist"===t.onReject)for(const t of e)r.push(t)};for(const o of e)t.$accepts(o,n)?(i(),r.push(o)):(null===s&&(s=[]),s.push(o));return i(),t.$finalize?t.$finalize(r,n):r}(i,s,null,e):s}function tn(t,e,n){const o=()=>function(t,e){const n=function(t,e){const n=[];for(let o=t.overlays.length-1;o>=0;o--){const r=t.overlays[o],s=ze(r,e);s.length>0&&n.push({dispatch:r,indices:s})}const o=ze(t.dispatch,e);o.length>0&&n.push({dispatch:t.dispatch,indices:o});return n}(t,e);if(0===n.length)return en(t,e);let o=0,r=0;const s=()=>{for(;o<n.length;){const{dispatch:i,indices:c}=n[o];for(;r<c.length;){const n=c[r++],o=i.rules[n],l={};if(o.predicate(e,l)){const n=Ze(t,0===Object.keys(l).length?Ye:l);try{return o.$import(n,e,s)}catch(t){throw t}}}o++,r=0}return en(t,e)};return s()}(t,e);return n&&n.context?be(n.context,t.editor)(o):o()}function en(t,e){if(0===e.childNodes.length)return[];const n=[];for(const o of Array.from(e.childNodes)){const e=tn(t,o,void 0);for(const t of e)n.push(t)}return n}const nn={$import:(t,e)=>t.$importChildren(e),match:oe.any(),name:"@lexical/html/default-hoist"},on=f({build(t,e){const n=Pe(Le(e.rules)),r=Z(e.contextDefaults,void 0),s=e.preprocess;return{$generateNodesFromDOM:(e,i)=>{const c=i&&i.context?Z(i.context,r):r,l=void 0!==c&&c!==r?c:Object.create(r||null),u=new Se(l),f={session:u};return function(t,e,n){let o=t.length-1;const r=()=>{for(;o>=0;)return void(0,t[o--])(e,n,r)};r()}(i&&i.preprocess?[...s,...i.preprocess]:s,e,f),nt(ft,l,()=>function(t,e,n,r){return Xe({dispatch:t,editor:e,overlays:r.get(xe).map(t=>t.dispatch),session:r},o(n)?n.body:n,{schema:Ke})}(n,t,e,u),t)},defaults:r}},config:{contextDefaults:[],preprocess:[st],rules:[nn]},mergeConfig:(t,e)=>a(t,{...e,...e.contextDefaults&&{contextDefaults:[...t.contextDefaults,...e.contextDefaults]},...e.preprocess&&{preprocess:[...t.preprocess,...e.preprocess]},...e.rules&&{rules:[...e.rules,...t.rules]}}),name:ut});function rn(t,e){return B(on).$generateNodesFromDOM(t,e)}const sn=f({dependencies:[j(on,{rules:Te})],name:"@lexical/html/CoreImport"}),cn=[{$import:()=>[q()],match:oe.tag("hr"),name:"@lexical/html/hr"}],ln=f({dependencies:[sn,V,j(on,{rules:cn})],name:"@lexical/html/HorizontalRuleImport"}),un={any:oe.any,comment:oe.comment,css:le,tag:oe.tag,text:oe.text},fn=new Set(["STYLE","SCRIPT"]);function an(t,e){it(e);const n=o(e)?e.body.childNodes:e.childNodes,r=[],s=[];for(const e of n)if(!fn.has(e.nodeName)){const n=mn(e,t,s,!1);if(null!==n)for(const t of n)r.push(t)}return function(t){for(const e of t)e.getParent()&&e.getNextSibling()instanceof z&&e.insertAfter($());for(const e of t){const t=e.getParent();t&&t.splice(e.getIndexWithinParent(),1,e.getChildren())}}(s),r}function pn(t,n=null,o=e()){return vt([tt(ht,!0)],o)(()=>{const e=T(),r=$t(o),s=t.append.bind(t);for(const t of e.getChildren())gn(o,t,s,n,r);return t})}function dn(t,n=T()){const o=e();return vt([tt(ht,!0),tt(dt,!0)],o)(()=>{const e=$t(o),r=t.append.bind(t);return gn(o,n,r,null,e),t})}function hn(t,e=null){return("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)&&G(338),pn(document.createElement("div"),e,t).innerHTML}function gn(e,n,o,i=null,c=s(e)){let l=c.$shouldInclude(n,i,e);const u=c.$shouldExclude(n,i,e);let f=n;null!==i&&O(n)&&(f=t(i,n,"clone"));const a=c.$exportDOM(f,e),{element:p,after:d,append:h,$getChildNodes:g}=a;if(!p)return!1;const m=document.createDocumentFragment(),y=g?g():E(f)?f.getChildren():[],x=m.append.bind(m);for(const t of y){const o=gn(e,t,x,i,c);!l&&o&&c.$extractWithChild(n,t,i,"html",e)&&(l=!0)}if(l&&!u){if((r(p)||F(p))&&(h?h(m):p.append(m)),o(p),d){const t=d.call(f,p);t&&(F(p)?p.replaceChildren(t):p.replaceWith(t))}}else o(m);return l}function mn(t,e,n,o,r=new Map,s){const i=[];if(fn.has(t.nodeName))return i;let c=null;const l=function(t,e){const{nodeName:n}=t,o=e._htmlConversions.get(n.toLowerCase());let r=null;if(void 0!==o)for(const e of o){const n=e(t);null!==n&&(null===r||(r.priority||0)<=(n.priority||0))&&(r=n)}return null!==r?r.conversion:null}(t,e),u=l?l(t):null;let f=null;if(null!==u){f=u.after;const e=u.node;if(c=Array.isArray(e)?e[e.length-1]:e,null!==c){for(const[,t]of r)if(c=t(c,s),!c)break;c&&i.push(...Array.isArray(e)?e:[c])}null!=u.forChild&&r.set(t.nodeName,u.forChild)}const a=t.childNodes;let p=[];const d=(null==c||!P(c))&&(null!=c&&W(c)||o);for(let t=0;t<a.length;t++)p.push(...mn(a[t],e,n,d,new Map(r),c));if(null!=f&&(p=f(p)),h(t)&&(p=yn(t,p,d?()=>{const t=new z;return n.push(t),t}:v)),null==c)if(p.length>0)for(const t of p)i.push(t);else h(t)&&function(t){if(null==t.nextSibling||null==t.previousSibling)return!1;return g(t.nextSibling)&&g(t.previousSibling)}(t)&&i.push($());else E(c)&&c.append(...p);return i}function yn(t,e,n){const o=t.style.textAlign,r=[];let s=[];for(let t=0;t<e.length;t++){const i=e[t];if(W(i))o&&!i.getFormat()&&i.setFormat(o),r.push(i);else if(s.push(i),t===e.length-1||t<e.length-1&&W(e[t+1])){const t=n();t.setFormat(o),t.append(...s),r.push(t),s=[]}}return r}export{qe as $distributeInlineWrapper,pn as $generateDOMFromNodes,dn as $generateDOMFromRoot,hn as $generateHtmlFromNodes,an as $generateNodesFromDOM,rn as $generateNodesFromDOMViaExtension,ve as $getImportContextValue,mt as $getRenderContextValue,$t as $getSessionDOMRenderConfig,st as $inlineStylesFromStyleSheets,Ve as $isBlockLevel,xt as $setRenderContextValue,St as $updateRenderContextValue,be as $withImportContext,vt as $withRenderContext,He as BlockSchema,sn as CoreImportExtension,Te as CoreImportRules,on as DOMImportExtension,Ht as DOMRenderExtension,ln as HorizontalRuleImportExtension,cn as HorizontalRuleImportRules,xe as ImportOverlays,ae as ImportSource,pe as ImportSourceDataTransfer,de as ImportTextFormat,he as ImportTextStyle,ye as ImportWhitespaceConfig,Je as InlineSchema,Qe as NestedBlockSchema,ht as RenderContextExport,dt as RenderContextRoot,Ke as RootSchema,et as contextUpdater,tt as contextValue,fe as createImportState,pt as createRenderState,me as defaultIsInline,ge as defaultPreservesWhitespace,ue as defineImportRule,Be as defineOverlayRules,bt as domOverride,re as isElementOfTag,le as parseSelector,un as sel};
|
|
9
|
+
import{$sliceSelectedTextNodeContent as t}from"@lexical/selection";import{$getEditor as e,createState as n,isDOMDocumentNode as o,isHTMLElement as r,$getEditorDOMRenderConfig as s,DEFAULT_EDITOR_DOM_CONFIG as i,$isLexicalNode as c,getStaticNodeConfig as l,$fullReconcile as u,defineExtension as f,shallowMergeConfig as a,RootNode as p,isDOMTextNode as d,isBlockDomNode as h,isInlineDomNode as g,$isElementNode as m,$isBlockElementNode as y,$isDecoratorNode as x,$isLineBreakNode as S,$createParagraphNode as $,IS_HIGHLIGHT as v,IS_CODE as b,$generateNodesFromRawText as C,$createTextNode as k,isOnlyChildInBlockNode as O,isLastChildInBlockNode as w,$createLineBreakNode as D,$setFormatFromDOM as M,setNodeIndentFromDOM as A,$setDirectionFromDOM as N,$isTextNode as I,IS_BOLD as E,IS_ITALIC as W,IS_UNDERLINE as R,IS_STRIKETHROUGH as F,IS_SUBSCRIPT as T,IS_SUPERSCRIPT as j,configExtension as P,$getRoot as z,$assumeActiveEditor as _,isDocumentFragment as L,$isRootOrShadowRoot as U,ArtificialNode__DO_NOT_USE as B}from"lexical";import{objectKlassEquals as V}from"@lexical/utils";import{getPeerDependencyFromEditor as q,getKnownTypesAndNodes as G,$getExtensionOutput as H,HorizontalRuleExtension as J,$createHorizontalRuleNode as Q}from"@lexical/extension";function K(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let Y;function Z(t,e){const{key:n}=e;return t&&n in t?t[n]:e.defaultValue}function X(t){return Y&&Y.editor===t?Y:void 0}function tt(t,e){const n=X(e);return n&&n[t]}function et(t,e){if("cfg"in e){const{cfg:n,updater:o}=e;return[n,o(Z(t,n))]}return e}function nt(t,e){let n=e;for(const o of t){const[t,r]=et(n,o),s=t.key;if(n===e&&Z(n,t)===r)continue;const i=n===e||void 0===n?ot(e):n;i[s]=r,n=i}return n}function ot(t){return Object.create(t||null)}function rt(t,e){return[t,e]}function st(t,e){return{cfg:t,updater:e}}function it(t,n,o,r=e()){const s=Y,i=X(r);try{return Y={...i,editor:r,[t]:n},o()}finally{Y=s}}function ct(t,n=()=>{}){return(o,r=e())=>e=>{const s=X(r),i=s&&s[t],c=nt(o,i||n(r));return c&&c!==i?it(t,c,e,r):e()}}function lt(t,e,o,r){return Object.assign(n(Symbol(e),{isEqual:r,parse:o}),{[t]:!0})}const ut=(t,e,n)=>{ft(t),n()};function ft(t){if(!o(t))return;const e=t;if(null===e.querySelector("style"))return;const n=new Map;function s(t){let e=n.get(t);if(void 0===e){e=new Set;for(let n=0;n<t.style.length;n++)e.add(t.style[n]);n.set(t,e)}return e}try{for(const t of Array.from(e.styleSheets)){let n;try{n=t.cssRules}catch(t){continue}for(const t of Array.from(n)){if(!V(t,CSSStyleRule))continue;let n;try{n=e.querySelectorAll(t.selectorText)}catch(t){continue}for(const e of Array.from(n)){if(!r(e))continue;const n=s(e);for(let o=0;o<t.style.length;o++){const r=t.style[o];n.has(r)||e.style.setProperty(r,t.style.getPropertyValue(r),t.style.getPropertyPriority(r))}}}}}catch(t){}}const at="@lexical/html/DOM",pt=Symbol.for("@lexical/html/DOMExportContext"),dt="@lexical/html/DOMImport",ht=Symbol.for("@lexical/html/DOMImportContext"),gt=()=>!0;function mt(t,e,n){return lt(pt,t,e,n)}const yt=mt("root",Boolean),xt=mt("isExport",Boolean);function St(t){const e=q(t,at);return e?e.output.defaults:void 0}function $t(t,n=e()){return Z(function(t){return tt(pt,t)||St(t)}(n),t)}function vt(t){const e=q(t,at);return e?e.output.runtime:void 0}function bt(t,n,o=e()){const r=vt(o);r&&r.setContextValue(t,n)}function Ct(t,n,o=e()){const r=vt(o);r&&r.setContextValue(t,n(Z(r.editorContext,t)))}function kt(t=e()){const n=vt(t);return n?n.getSessionConfig():s(t)}const Ot=ct(pt,St);function wt(t,e,n){return{...e,...n,nodes:t}}function Dt(t){return e=>e instanceof t}function Mt(t,{nodes:e}){if("*"===e)return gt;let n={};const o=[];for(const r of e)if("getType"in r){const e=r.getType();if(n){const o=t[e];void 0===o&&K(339,r.name,e),n=Object.assign(n,o.types)}o.push(Dt(r))}else n=void 0,o.push(r);return n||(1===o.length?o[0]:t=>{for(const e of o)if(e(t))return!0;return!1})}function At(t){return(e,n,o)=>t(e,o)}function Nt(t){return(e,n,o,r)=>t(e,n,r)}function It(t){return(e,n,o,r,s)=>t(e,n,o,s)}function Et(t){return(e,n,o,r,s,i)=>t(e,n,o,r,i)}function Wt(t,e){return(n,o)=>{const r=()=>t(n,o),s=e(n);return s?s(n,r,o):r()}}function Rt(t,e){return(n,o,r)=>{const s=()=>t(n,o,r),i=e(n);return i?i(n,o,s,r):s()}}const Ft=Rt,Tt=Nt;function jt(t,e){return(n,o,r,s)=>{const i=()=>t(n,o,r,s),c=e(n);return c?c(n,o,r,i,s):i()}}function Pt(t,e){return(n,o,r,s,i)=>{const c=()=>t(n,o,r,s,i),l=e(n);return l?l(n,o,r,s,c,i):c()}}function zt(t,e){return(n,o,r,s)=>{t(n,o,r,s);const i=e(n);i&&i(n,o,r,s)}}function _t(t,e,n,o,r){let s=n[e];for(const n of t[e])if("function"==typeof n[0]){const[t,e]=n;s=o(s,n=>t(n)&&e||void 0)}else{const t=n[1],e={};for(const n in t){const r=t[n];r&&(e[n]=r.reduce((t,e)=>o(t,()=>e),s))}s=o(s,t=>{const n=e[t.getType()];return n&&r(n)})}n[e]=s}function Lt(t,e,n,o){if(!o)return;const r=t[e];if("function"==typeof n)r.push([n,o]);else{const t=r[r.length-1];let e;t&&"types"===t[0]?e=t[1]:(e={},r.push(["types",e]));for(const t in n){const n=e[t]||[];e[t]=n,n.push(o)}}}function Ut(t){return"*"===t.nodes}function Bt(t,e){const n=function(t){const e={},{nodes:n}=G(t);for(const t of n)e[t.getType()]={klass:t,types:{}};for(const t of Object.values(e))if(t){const n=t.klass.getType();for(let{klass:o}=t;c(o.prototype);o=Object.getPrototypeOf(o)){const{ownNodeType:t}=l(o),r=t&&e[t];r&&(r.types[n]=!0)}}return e}(t),o={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const t of function(t){const e=[],n=[],o=[];for(const r of t)if(Ut(r))e.push(r);else if(Array.isArray(r.nodes))for(const t of r.nodes)c(t.prototype)?o.push(1===r.nodes.length?r:{...r,nodes:[t]}):n.push(1===r.nodes.length?r:{...r,nodes:[t]});const r=new Map,s=t=>{let e=r.get(t);if(void 0===e){e=0;for(let n=t;c(n.prototype);n=Object.getPrototypeOf(n))e++;r.set(t,e)}return e};return o.sort((t,e)=>s(t.nodes[0])-s(e.nodes[0])),[...o,...n,...e]}(e)){const e=Mt(n,t);for(const n in o){Lt(o,n,e,t[n])}}return o}function Vt(t){return t}function qt(t,{overrides:e}){const n=Bt(t,e),o={...i,...t.dom};return _t(n,"$createDOM",o,Wt,At),_t(n,"$exportDOM",o,Wt,At),_t(n,"$extractWithChild",o,Pt,Et),_t(n,"$getDOMSlot",o,Ft,Tt),_t(n,"$shouldExclude",o,Rt,Nt),_t(n,"$shouldInclude",o,Rt,Nt),_t(n,"$updateDOM",o,jt,It),_t(n,"$decorateDOM",o,zt,Vt),o}function Gt(t){return{get:e=>Z(t,e)}}function Ht(t){const e=Object.create(null);return nt(t,e)||e}function Jt(t,e){const n=Gt(e);return t.filter(t=>!(t.disabledForEditor&&t.disabledForEditor(n)))}function Qt(t){if("*"===t.nodes)return()=>!0;const e=t.nodes.map(t=>{const e=t;return c(e.prototype)?t=>t instanceof e:t});return t=>e.some(e=>e(t))}class Kt{editor;initialEditorConfig;overrides;editorContext;hasSessionGates;installed;sessionCache=new Map;constructor(t,e,n,o){this.editor=t,this.initialEditorConfig=e,this.overrides=n,this.editorContext=o,this.installed=Jt(n,o),this.hasSessionGates=n.some(t=>t.disabledForSession)}setContextValue(t,e){const n=this.installed;this.editorContext[t.key]=e;const o=Jt(this.overrides,this.editorContext);if(function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(n,o))return;const r=function(t,e){const n=new Set(t),o=new Set(e),r=[];for(const e of t)o.has(e)||r.push(e);for(const t of e)n.has(t)||r.push(t);return r}(n,o);this.installed=o,this.sessionCache.clear();const s=qt(this.initialEditorConfig,{overrides:o});this.editor._config.dom=s;const i=function(t){const e=[];for(const n of t)(n.$createDOM||n.$getDOMSlot||n.$decorateDOM)&&e.push(Qt(n));return 0===e.length?null:t=>e.some(e=>e(t))}(r);if(!i)return;const c=s.$updateDOM;s.$updateDOM=(t,e,n,o)=>!!i(t)||c(t,e,n,o),this.editor.update(u,{discrete:!0}),s.$updateDOM=c}getSessionConfig(){const t=this.editor._config.dom||i;if(!this.hasSessionGates)return t;const e=Gt(tt(pt,this.editor)||this.editorContext),n=[],o=[];if(this.installed.forEach((t,r)=>{t.disabledForSession&&t.disabledForSession(e)?n.push(String(r)):o.push(t)}),0===n.length)return t;const r=n.join(",");let s=this.sessionCache.get(r);return s||(s=qt(this.initialEditorConfig,{overrides:o}),this.sessionCache.set(r,s)),s}}const Yt=f({build(t,e,n){const{initialEditorConfig:o}=n.getInitResult(),r=Ht(e.contextDefaults);return{defaults:r,runtime:new Kt(t,o,e.overrides,r)}},config:{contextDefaults:[],overrides:[]},html:{export:new Map([[p,()=>{const t=document.createElement("div");return t.role="textbox",{element:t}}]])},init(t,e){const n={dom:t.dom,nodes:t.nodes},o=Ht(e.contextDefaults),r=Jt(e.overrides,o);return t.dom=qt(t,{overrides:r}),{initialEditorConfig:n}},mergeConfig(t,e){const n=a(t,e);for(const o of["overrides","contextDefaults"])e[o]&&(n[o]=[...t[o],...e[o]]);return n},name:at}),Zt=Symbol.for("@lexical/html/SelectorImpl");function Xt(t,e){const n={kind:"element",predicate:(o=e,0===o.length?r:1===o.length?o[0]:(t,e)=>{for(const n of o)if(!n(t,e))return!1;return!0}),tags:t};var o;const s=n=>Xt(t,[...e,n]);return{[Zt]:n,attr:(t,e,n)=>s(ne(t,e,n)),classAll:(...t)=>s(ee(t)),classAny:(...t)=>s(function(t){const e=te(t);if(0===e.length)return()=>!1;return t=>{if(!r(t))return!1;const n=t.classList;for(const t of e)if(n.contains(t))return!0;return!1}}(t)),styleAny:(t,e,n)=>s(function(t,e,n){if("string"==typeof e)return n=>r(n)&&n.style.getPropertyValue(t)===e;if(e instanceof RegExp){const o=n&&n.capture,s=e;return(e,n)=>{if(!r(e))return!1;const i=e.style.getPropertyValue(t);if(!i)return!1;const c=i.match(s);return null!==c&&(void 0!==o&&(n[o]=c),!0)}}K(362,JSON.stringify(t))}(t,e,n))}}function te(t){const e=[];for(const n of t)n&&e.push(n);return e}function ee(t){const e=te(t);return 0===e.length?()=>!0:t=>{if(!r(t))return!1;const n=t.classList;for(const t of e)if(!n.contains(t))return!1;return!0}}function ne(t,e,n){if(!0===e)return e=>r(e)&&e.hasAttribute(t);if("string"==typeof e)return n=>r(n)&&n.getAttribute(t)===e;if(e instanceof RegExp){const o=n&&n.capture,s=e;return(e,n)=>{if(!r(e))return!1;const i=e.getAttribute(t);if(null==i)return!1;const c=i.match(s);return null!==c&&(void 0!==o&&(n[o]=c),!0)}}K(361,JSON.stringify(t))}const oe={kind:"text",predicate:d,tags:new Set},re={[Zt]:oe},se={kind:"comment",predicate:t=>8===t.nodeType,tags:new Set},ie={[Zt]:se},ce={any:()=>Xt(new Set,[]),comment:()=>ie,tag(...t){t.length>0||K(363);const e=new Set;for(const n of t)e.add(n.toUpperCase());return Xt(e,[])},text:()=>re};function le(t,e){return r(t)&&t.nodeName===e.toUpperCase()}const ue=/[A-Za-z0-9_-]/;class fe{constructor(t,e){this.source=t,this.pos=e}peek(t=0){return this.source[this.pos+t]||""}consume(){return this.source[this.pos++]||""}eof(){return this.pos>=this.source.length}skipWhitespace(){for(;!this.eof()&&/\s/.test(this.peek());)this.pos++}readIdent(){const t=this.pos;for(;!this.eof()&&ue.test(this.peek());)this.pos++;return this.source.slice(t,this.pos)}readQuoted(){const t=this.consume();this.assert('"'===t||"'"===t,"expected quote");const e=this.pos;for(;!this.eof()&&this.peek()!==t;)"\\"===this.peek()?this.pos+=2:this.pos++;this.assert(!this.eof(),"unterminated string");const n=this.source.slice(e,this.pos);return this.pos++,n.replace(/\\(.)/g,"$1")}assert(t,e){t||K(364,String(this.pos+1),e,this.source)}}function ae(t){const e=new Set,n=[],o=[];if(t.skipWhitespace(),"*"===t.peek())t.consume();else if(ue.test(t.peek())){const n=t.readIdent();n&&e.add(n.toUpperCase())}for(;!t.eof();){const e=t.peek();if("."===e){t.consume();const e=t.readIdent();t.assert(""!==e,'expected class name after "."'),o.push(e)}else if("#"===e){t.consume();const e=t.readIdent();t.assert(""!==e,'expected id after "#"'),n.push(ne("id",e))}else{if("["!==e)break;{t.consume(),t.skipWhitespace();const e=t.readIdent();t.assert(""!==e,'expected attribute name after "["'),t.skipWhitespace();let o=!0;if("="===t.peek()){t.consume(),t.skipWhitespace();const e=t.peek();'"'===e||"'"===e?o=t.readQuoted():(o=t.readIdent(),t.assert(""!==o,"expected attribute value")),t.skipWhitespace()}t.assert("]"===t.peek(),'expected "]"'),t.consume(),n.push(ne(e,o))}}}return o.length>0&&n.push(ee(o)),{predicates:n,tags:e}}function pe(t){const e=new fe(t,0),n=[];for(;;){const t=ae(e);if(n.push(t),e.skipWhitespace(),e.eof())break;e.assert(","===e.peek(),'expected "," (selector lists are the only supported combinator)'),e.consume(),e.skipWhitespace()}if(1===n.length)return Xt(n[0].tags,n[0].predicates);const o=new Set;for(const t of n)for(const e of t.tags)o.add(e);return Xt(o,[(t,e)=>{for(const o of n){const n=t.nodeName;if(o.tags.size>0&&!o.tags.has(n))continue;let r=!0;for(const n of o.predicates)if(!n(t,e)){r=!1;break}if(r)return!0}return!1}])}function de(t){return t}function he(t,e,n){return lt(ht,t,e,n)}const ge=he("importSource",()=>"unknown"),me=he("importSourceDataTransfer",()=>null),ye=he("textFormat",()=>0),xe=he("textStyle",()=>({}));function Se(t){if(!r(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function $e(t){if(d(t))return!0;if(!r(t))return!1;const e=t.style.display;return e?e.startsWith("inline"):!h(t)&&g(t)}const ve=he("whitespaceConfig",()=>({isInline:$e,preservesWhitespace:Se})),be=he("importOverlays",()=>[]);class Ce{constructor(t){this.record=t}get(t){return Z(this.record,t)}set(t,e){this.record[t.key]=e}update(t,e){this.record[t.key]=e(Z(this.record,t))}has(t){return Object.prototype.hasOwnProperty.call(this.record,t.key)}}function ke(t){const e=q(t,dt);return e?e.output.defaults:void 0}function Oe(t,n=e()){return Z(function(t){return tt(ht,t)||ke(t)}(n),t)}const we=ct(ht,ke);function De(t){return y(t)||x(t)&&!t.isInline()}function Me(t,e){const n=[];let o=[];const r=()=>{0!==o.length&&(n.push(e().splice(0,0,o)),o=[])};for(const s of t)if(De(s)){if(r(),m(s)){const t=Me(s.getChildren(),e);s.splice(0,s.getChildrenSize(),t)}n.push(s)}else o.push(s);return r(),n}function Ae(t,e){if(!r(e))return t;const n=e.style.textAlign;if(!je(n))return t;for(const e of t)y(e)&&""===e.getFormatType()&&e.setFormat(n);return t}function Ne(t,e,n){1===t.length&&S(t[0])&&(t=[]);const o=$();if(r(n)){const t=n.style.textAlign;je(t)&&o.setFormat(t)}return[o.splice(0,0,t)]}const Ie={$accepts:De,$packageRun:Ne,name:"BlockSchema"},Ee={$accepts:t=>!De(t),name:"InlineSchema"},We={$accepts:De,$packageRun:t=>t,name:"NestedBlockSchema"},Re={$accepts:De,$packageRun:Ne,name:"RootSchema"},Fe=ce,Te=new Set(["center","end","justify","left","right","start"]);function je(t){return Te.has(t)}const Pe={B:{fontWeight:"bold"},EM:{fontStyle:"italic"},I:{fontStyle:"italic"},S:{textDecoration:"line-through"},STRONG:{fontWeight:"bold"},SUB:{verticalAlign:"sub"},SUP:{verticalAlign:"super"},U:{textDecoration:"underline"}},ze={CODE:b,MARK:v};const _e=new Set(["font-weight","font-style","text-decoration","vertical-align"]);const Le={$import:(t,e)=>{const n=t.get(ye),o=Pe[e.nodeName],r=function(t){return{fontStyle:t.style.fontStyle,fontWeight:t.style.fontWeight,textDecoration:t.style.textDecoration,verticalAlign:t.style.verticalAlign}}(e),s=o?(i=o,{fontStyle:(c=r).fontStyle||i.fontStyle,fontWeight:c.fontWeight||i.fontWeight,textDecoration:c.textDecoration||i.textDecoration,verticalAlign:c.verticalAlign||i.verticalAlign}):r;var i,c;let l=(u=n,f=function(t){let e=0,n=0;const{fontWeight:o,fontStyle:r,textDecoration:s,verticalAlign:i}=t;if("700"===o||"bold"===o?e|=E:"normal"!==o&&"400"!==o||(n|=E),"italic"===r?e|=W:"normal"===r&&(n|=W),s){const t=s.split(" ");t.includes("underline")&&(e|=R),t.includes("line-through")&&(e|=F),t.includes("none")&&(n|=R|F)}return"sub"===i?(e|=T,n|=j):"super"===i?(e|=j,n|=T):"baseline"===i&&(n|=T|j),{clear:n,set:e}}(s),u&~f.clear|f.set);var u,f;const a=ze[e.nodeName];return a&&(l|=a),l===n?t.$importChildren(e):t.$importChildren(e,{context:[rt(ye,l)]})},match:Fe.tag("b","strong","em","i","code","mark","s","sub","sup","u","span"),name:"@lexical/html/inline-format"};function Ue(t,e,n){let o=t;for(;;){let t=null;for(;null===(t=e?o.nextSibling:o.previousSibling);){const t=o.parentNode;if(null===t)return null;o=t}if(o=t,!n.isInline(o))return null;let r=o;for(;null!==(r=e?o.firstChild:o.lastChild);)o=r;if(d(o))return o;if("BR"===o.nodeName)return null}}function Be(t,e){return 0!==e&&I(t)?t.setFormat(e):t}function Ve(t,e){if(I(t)){const n=function(t){let e="";for(const n in t)_e.has(n)||(e+=`${n}: ${t[n]}; `);return e.trimEnd()}(e);""!==n&&t.setStyle(n)}return t}const qe={$import:(t,e)=>{const n=t.get(ye),o=t.get(xe),r=t.get(ve);if(function(t,e){let n=t.parentNode;for(;null!==n;){if(e.preservesWhitespace(n))return!0;n=n.parentNode}return!1}(e,r)){const t=C(e.textContent||"");for(const e of t)Be(e,n),Ve(e,o);return t}const s=function(t,e){let n=(t.textContent||"").replace(/\r/g,"").replace(/[ \t\n]+/g," ");if(0===n.length)return"";if(" "===n[0]){let o=t,r=!0;for(;null!==o&&null!==(o=Ue(o,!1,e));){const t=o.textContent||"";if(t.length>0){/[ \t\n]$/.test(t)&&(n=n.slice(1)),r=!1;break}}r&&(n=n.slice(1))}if(n.length>0&&" "===n[n.length-1]){let o=t,r=!0;for(;null!==o&&null!==(o=Ue(o,!0,e));)if((o.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){r=!1;break}r&&(n=n.slice(0,-1))}return n}(e,r);if(""===s)return[];const i=k(s);return Be(i,n),Ve(i,o),[i]},match:Fe.text(),name:"@lexical/html/#text"},Ge={$import:()=>[],match:Fe.tag("script","style"),name:"@lexical/html/script-style-ignore"},He={$import:(t,e)=>O(e)||w(e)?[]:[D()],match:Fe.tag("br"),name:"@lexical/html/br"},Je=[Ge,{$import:(t,e)=>{const n=$();if(M(n,e),A(e,n),""===n.getFormatType()){const t=e.getAttribute("align");t&&je(t)&&n.setFormat(t)}return N(n,e),[n.splice(0,0,t.$importChildren(e))]},match:Fe.tag("p"),name:"@lexical/html/p"},{$import:(t,e,n)=>h(e)?Ae(t.$importChildren(e,{schema:Ie}),e):n(),match:Fe.any(),name:"@lexical/html/transparent-block"},qe,He,Le];function Qe(t,e){const n=[];let o=0,r=0;for(;o<t.length&&r<e.length;)t[o]<=e[r]?n.push(t[o++]):n.push(e[r++]);for(;o<t.length;)n.push(t[o++]);for(;r<e.length;)n.push(e[r++]);return n}function Ke(t){const e=[],n=new Map,o=[],r=[],s=[],i=new Set;t.forEach((t,c)=>{const l=function(t){const e=t[Zt];return void 0===e&&K(360),e}(t.match),u=t.name||function(t,e){if("text"===t.kind)return`#text@${e}`;if("comment"===t.kind)return`#comment@${e}`;if(0===t.tags.size)return`*@${e}`;const n=Array.from(t.tags).join(",").toLowerCase();return`${n}@${e}`}(l,c);if(t.name&&i.add(t.name),e.push({$import:t.$import,name:u,predicate:l.predicate}),"text"===l.kind)r.push(c);else if("comment"===l.kind)s.push(c);else if(0===l.tags.size)o.push(c);else for(const t of l.tags){let e=n.get(t);e||(e=[],n.set(t,e)),e.push(c)}});const c=new Map;if(0===o.length)for(const[t,e]of n)c.set(t,e);else for(const[t,e]of n)c.set(t,Qe(e,o));return{byTag:c,commentIndices:s,rules:e,textIndices:r,wildcardIndices:o}}function Ye(t,e){return d(e)?t.textIndices:8===e.nodeType?t.commentIndices:r(e)?t.byTag.get(e.nodeName)||t.wildcardIndices:Ze}const Ze=Object.freeze([]);function Xe(t){const e=[];for(const n of t)if(tn(n))for(const t of n.rules)e.push(t);else e.push(n);return e}function tn(t){return"object"==typeof t&&null!==t&&"__type"in t&&"CompiledOverlayRules"===t.__type}function en(t){const e=Xe(t);return{__type:"CompiledOverlayRules",dispatch:Ke(e),rules:e}}const nn=Object.freeze({});function on(t,e){const n={$importChildren:(e,n)=>function(t,e,n){const o=n&&n.rules?n.rules.dispatch:void 0;o&&t.overlays.push(o);try{const o=()=>rn(t,e,n);return n&&n.context?we(n.context,t.editor)(o):o()}finally{o&&t.overlays.pop()}}(t,e,n),$importOne:(e,n)=>sn(t,e,n),captures:e,get:e=>Oe(e,t.editor),session:t.session};return n}function rn(t,e,n){const o=n&&n.$onChild,r=[];for(const n of Array.from(e.childNodes)){const e=sn(t,n,void 0);for(const t of e){const e=o?o(t):t;null!=e&&r.push(e)}}const s=n&&n.$after?n.$after(r):r,i=n&&n.schema;return i?function(t,e,n,o){const r=[];let s=null;const i=()=>{if(null===s)return;const e=s;if(s=null,t.$packageRun){const s=t.$packageRun(e,n,o);if(s.length>0){for(const t of s)r.push(t);return}}if("hoist"===t.onReject)for(const t of e)r.push(t)};for(const o of e)t.$accepts(o,n)?(i(),r.push(o)):(null===s&&(s=[]),s.push(o));return i(),t.$finalize?t.$finalize(r,n):r}(i,s,null,e):s}function sn(t,e,n){const o=()=>function(t,e){const n=function(t,e){const n=[];for(let o=t.overlays.length-1;o>=0;o--){const r=t.overlays[o],s=Ye(r,e);s.length>0&&n.push({dispatch:r,indices:s})}const o=Ye(t.dispatch,e);o.length>0&&n.push({dispatch:t.dispatch,indices:o});return n}(t,e);if(0===n.length)return cn(t,e);let o=0,r=0;const s=()=>{for(;o<n.length;){const{dispatch:i,indices:c}=n[o];for(;r<c.length;){const n=c[r++],o=i.rules[n],l={};if(o.predicate(e,l)){const n=on(t,0===Object.keys(l).length?nn:l);try{return o.$import(n,e,s)}catch(t){throw t}}}o++,r=0}return cn(t,e)};return s()}(t,e);return n&&n.context?we(n.context,t.editor)(o):o()}function cn(t,e){if(0===e.childNodes.length)return[];const n=[];for(const o of Array.from(e.childNodes)){const e=sn(t,o,void 0);for(const t of e)n.push(t)}return n}const ln={$import:(t,e)=>t.$importChildren(e),match:ce.any(),name:"@lexical/html/default-hoist"},un=f({build(t,e){const n=Ke(Xe(e.rules)),r=nt(e.contextDefaults,void 0),s=e.preprocess;return{$generateNodesFromDOM:(e,i)=>{const c=i&&i.context?nt(i.context,r):r,l=void 0!==c&&c!==r?c:Object.create(r||null),u=new Ce(l),f={session:u};return function(t,e,n){let o=t.length-1;const r=()=>{for(;o>=0;)return void(0,t[o--])(e,n,r)};r()}(i&&i.preprocess?[...s,...i.preprocess]:s,e,f),it(ht,l,()=>function(t,e,n,r){return rn({dispatch:t,editor:e,overlays:r.get(be).map(t=>t.dispatch),session:r},o(n)?n.body:n,{schema:Re})}(n,t,e,u),t)},defaults:r}},config:{contextDefaults:[],preprocess:[ut],rules:[ln]},mergeConfig:(t,e)=>a(t,{...e,...e.contextDefaults&&{contextDefaults:[...t.contextDefaults,...e.contextDefaults]},...e.preprocess&&{preprocess:[...t.preprocess,...e.preprocess]},...e.rules&&{rules:[...e.rules,...t.rules]}}),name:dt});function fn(t,e){return H(un).$generateNodesFromDOM(t,e)}const an=f({dependencies:[P(un,{rules:Je})],name:"@lexical/html/CoreImport"}),pn=[{$import:()=>[Q()],match:ce.tag("hr"),name:"@lexical/html/hr"}],dn=f({dependencies:[J,P(un,{rules:pn})],name:"@lexical/html/HorizontalRuleImport"}),hn={any:ce.any,comment:ce.comment,css:pe,tag:ce.tag,text:ce.text},gn=new Set(["STYLE","SCRIPT"]);function mn(t,e){ft(e);const n=o(e)?e.body.childNodes:e.childNodes,r=[],s=[];for(const e of n)if(!gn.has(e.nodeName)){const n=vn(e,t,s,!1);if(null!==n)for(const t of n)r.push(t)}return function(t){for(const e of t)e.getParent()&&e.getNextSibling()instanceof B&&e.insertAfter(D());for(const e of t){const t=e.getParent();t&&t.splice(e.getIndexWithinParent(),1,e.getChildren())}}(s),r}function yn(t,n=null,o=e()){return Ot([rt(xt,!0)],o)(()=>{const e=z(),r=kt(o),s=t.append.bind(t);for(const t of e.getChildren())$n(o,t,s,n,r);return t})}function xn(t,n=z()){const o=e();return Ot([rt(xt,!0),rt(yt,!0)],o)(()=>{const e=kt(o),r=t.append.bind(t);return $n(o,n,r,null,e),t})}function Sn(t,e=null){return("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)&&K(338),_(t),yn(document.createElement("div"),e,t).innerHTML}function $n(e,n,o,i=null,c=s(e)){let l=c.$shouldInclude(n,i,e);const u=c.$shouldExclude(n,i,e);let f=n;null!==i&&I(n)&&(f=t(i,n,"clone"));const a=c.$exportDOM(f,e),{element:p,after:d,append:h,$getChildNodes:g}=a;if(!p)return!1;const y=document.createDocumentFragment(),x=g?g():m(f)?f.getChildren():[],S=y.append.bind(y);for(const t of x){const o=$n(e,t,S,i,c);!l&&o&&c.$extractWithChild(n,t,i,"html",e)&&(l=!0)}if(l&&!u){if((r(p)||L(p))&&(h?h(y):p.append(y)),o(p),d){const t=d.call(f,p);t&&(L(p)?p.replaceChildren(t):p.replaceWith(t))}}else o(y);return l}function vn(t,e,n,o,r=new Map,s){const i=[];if(gn.has(t.nodeName))return i;let c=null;const l=function(t,e){const{nodeName:n}=t,o=e._htmlConversions.get(n.toLowerCase());let r=null;if(void 0!==o)for(const e of o){const n=e(t);null!==n&&(null===r||(r.priority||0)<=(n.priority||0))&&(r=n)}return null!==r?r.conversion:null}(t,e),u=l?l(t):null;let f=null;if(null!==u){f=u.after;const e=u.node;if(c=Array.isArray(e)?e[e.length-1]:e,null!==c){for(const[,t]of r)if(c=t(c,s),!c)break;c&&i.push(...Array.isArray(e)?e:[c])}null!=u.forChild&&r.set(t.nodeName,u.forChild)}const a=t.childNodes;let p=[];const d=(null==c||!U(c))&&(null!=c&&y(c)||o);for(let t=0;t<a.length;t++)p.push(...vn(a[t],e,n,d,new Map(r),c));if(null!=f&&(p=f(p)),h(t)&&(p=bn(t,p,d?()=>{const t=new B;return n.push(t),t}:$)),null==c)if(p.length>0)for(const t of p)i.push(t);else h(t)&&function(t){if(null==t.nextSibling||null==t.previousSibling)return!1;return g(t.nextSibling)&&g(t.previousSibling)}(t)&&i.push(D());else m(c)&&c.append(...p);return i}function bn(t,e,n){const o=t.style.textAlign,r=[];let s=[];for(let t=0;t<e.length;t++){const i=e[t];if(y(i))o&&!i.getFormat()&&i.setFormat(o),r.push(i);else if(s.push(i),t===e.length-1||t<e.length-1&&y(e[t+1])){const t=n();t.setFormat(o),t.append(...s),r.push(t),s=[]}}return r}export{Me as $distributeInlineWrapper,yn as $generateDOMFromNodes,xn as $generateDOMFromRoot,Sn as $generateHtmlFromNodes,mn as $generateNodesFromDOM,fn as $generateNodesFromDOMViaExtension,Oe as $getImportContextValue,$t as $getRenderContextValue,kt as $getSessionDOMRenderConfig,ut as $inlineStylesFromStyleSheets,De as $isBlockLevel,Ae as $propagateTextAlignToBlockChildren,bt as $setRenderContextValue,Ct as $updateRenderContextValue,we as $withImportContext,Ot as $withRenderContext,Ie as BlockSchema,an as CoreImportExtension,Je as CoreImportRules,un as DOMImportExtension,Yt as DOMRenderExtension,dn as HorizontalRuleImportExtension,pn as HorizontalRuleImportRules,be as ImportOverlays,ge as ImportSource,me as ImportSourceDataTransfer,ye as ImportTextFormat,xe as ImportTextStyle,ve as ImportWhitespaceConfig,Ee as InlineSchema,We as NestedBlockSchema,xt as RenderContextExport,yt as RenderContextRoot,Re as RootSchema,st as contextUpdater,rt as contextValue,he as createImportState,mt as createRenderState,$e as defaultIsInline,Se as defaultPreservesWhitespace,de as defineImportRule,en as defineOverlayRules,wt as domOverride,le as isElementOfTag,pe as parseSelector,hn as sel};
|
|
@@ -12,15 +12,16 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const HorizontalRuleImportRules: import("./types").DOMImportRule<import("./types").ElementSelectorBuilder<HTMLHRElement, Record<string, never>>>[];
|
|
14
14
|
/**
|
|
15
|
-
* Bundles {@link HorizontalRuleImportRules}
|
|
16
|
-
* {@link
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* Bundles {@link HorizontalRuleImportRules} together with the runtime
|
|
16
|
+
* {@link HorizontalRuleExtension}. The application is expected to
|
|
17
|
+
* already have `CoreImportExtension` (or some equivalent) in its
|
|
18
|
+
* dependency graph — the core/text/paragraph/inline-format rules are a
|
|
19
|
+
* shared baseline, not something this leaf importer should re-declare.
|
|
19
20
|
*
|
|
20
21
|
* Lives in `@lexical/html` (not `@lexical/extension`) because
|
|
21
22
|
* {@link DOMImportExtension} itself is in `@lexical/html`, and
|
|
22
23
|
* `@lexical/extension` is upstream of `@lexical/html` in the dependency
|
|
23
|
-
* graph
|
|
24
|
+
* graph.
|
|
24
25
|
*
|
|
25
26
|
* @experimental
|
|
26
27
|
*/
|
|
@@ -22,4 +22,4 @@ export declare function isAlignmentValue(value: string): value is ElementFormatT
|
|
|
22
22
|
*
|
|
23
23
|
* @experimental
|
|
24
24
|
*/
|
|
25
|
-
export declare const CoreImportRules: (import("./types").DOMImportRule<import("./types").ElementSelectorBuilder<HTMLElement
|
|
25
|
+
export declare const CoreImportRules: (import("./types").DOMImportRule<import("./types").ElementSelectorBuilder<HTMLElement, Record<string, never>>> | import("./types").DOMImportRule<import("./types").CompiledSelector<Text, Record<string, RegExpMatchArray>>>)[];
|
package/dist/import/index.d.ts
CHANGED
|
@@ -33,6 +33,6 @@ export { HorizontalRuleImportExtension, HorizontalRuleImportRules, } from './Hor
|
|
|
33
33
|
export { $getImportContextValue, $withImportContext, createImportState, defaultIsInline, defaultPreservesWhitespace, ImportOverlays, ImportSource, ImportSourceDataTransfer, type ImportSourceKind, ImportTextFormat, ImportTextStyle, ImportWhitespaceConfig, type IsInlineForWhitespace, type IsPreserveWhitespaceDom, type WhitespaceImportConfig, } from './ImportContext';
|
|
34
34
|
export { $inlineStylesFromStyleSheets } from './inlineStylesFromStyleSheets';
|
|
35
35
|
export { parseSelector } from './parseCss';
|
|
36
|
-
export { $distributeInlineWrapper, $isBlockLevel, BlockSchema, InlineSchema, NestedBlockSchema, RootSchema, } from './schemas';
|
|
36
|
+
export { $distributeInlineWrapper, $isBlockLevel, $propagateTextAlignToBlockChildren, BlockSchema, InlineSchema, NestedBlockSchema, RootSchema, } from './schemas';
|
|
37
37
|
export { isElementOfTag } from './sel';
|
|
38
38
|
export type { AnyDOMImportRule, AttrMatchOptions, CapturesOfSelector, ChildSchema, CompiledSelector, DOMImportContext, DOMImportExtensionOutput, DOMImportFn, DOMImportRule, DOMPreprocessContext, DOMPreprocessFn, ElementSelectorBuilder, GenerateNodesFromDOMOptions, ImportChildrenOpts, ImportContextPairOrUpdater, ImportNodeOpts, ImportSession, ImportStateConfig, NodeOfSelector, StyleMatchOptions, } from './types';
|
package/dist/import/schemas.d.ts
CHANGED
|
@@ -53,6 +53,21 @@ export declare function $distributeInlineWrapper(children: readonly LexicalNode[
|
|
|
53
53
|
* @internal
|
|
54
54
|
*/
|
|
55
55
|
export declare function $applySchema(schema: ChildSchema, children: LexicalNode[], parent: LexicalNode | null, domParent: Node | null): LexicalNode[];
|
|
56
|
+
/**
|
|
57
|
+
* Apply a parent DOM element's `text-align` (when set to one of the
|
|
58
|
+
* supported {@link ElementFormatType} values) to each block-level child
|
|
59
|
+
* Lexical node that does not yet have its own format.
|
|
60
|
+
*
|
|
61
|
+
* Mirrors the part of the legacy `wrapContinuousInlines` that wrote
|
|
62
|
+
* `node.setFormat(textAlign)` onto pre-existing block children when the
|
|
63
|
+
* DOM parent carried `style.textAlign`. Pair with
|
|
64
|
+
* {@link $paragraphPackageRun} (which carries the same propagation onto
|
|
65
|
+
* paragraphs synthesized around inline runs) to fully replicate the
|
|
66
|
+
* legacy behavior on a run of mixed children.
|
|
67
|
+
*
|
|
68
|
+
* @experimental
|
|
69
|
+
*/
|
|
70
|
+
export declare function $propagateTextAlignToBlockChildren(children: LexicalNode[], domParent: Node | null): LexicalNode[];
|
|
56
71
|
/**
|
|
57
72
|
* Default schema for block-level positions (root of the document, the body
|
|
58
73
|
* of a block element node). Accepts block lexical nodes; packages runs of
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { contextUpdater, contextValue } from './ContextRecord';
|
|
|
10
10
|
export { domOverride } from './domOverride';
|
|
11
11
|
export { DOMRenderExtension } from './DOMRenderExtension';
|
|
12
12
|
export type { AnyDOMImportRule, AttrMatchOptions, CapturesOfSelector, ChildSchema, CompiledOverlayRules, CompiledSelector, DOMImportContext, DOMImportExtensionOutput, DOMImportFn, DOMImportRule, DOMImportRuleEntry, DOMPreprocessContext, DOMPreprocessFn, ElementSelectorBuilder, GenerateNodesFromDOMOptions, ImportChildrenOpts, ImportContextPairOrUpdater, ImportNodeOpts, ImportSession, ImportStateConfig, NodeOfSelector, StyleMatchOptions, } from './import';
|
|
13
|
-
export { $distributeInlineWrapper, $generateNodesFromDOMViaExtension, $getImportContextValue, $inlineStylesFromStyleSheets, $isBlockLevel, $withImportContext, BlockSchema, CoreImportExtension, CoreImportRules, createImportState, defaultIsInline, defaultPreservesWhitespace, defineImportRule, defineOverlayRules, type DOMImportConfig, DOMImportExtension, HorizontalRuleImportExtension, HorizontalRuleImportRules, ImportOverlays, ImportSource, ImportSourceDataTransfer, type ImportSourceKind, ImportTextFormat, ImportTextStyle, ImportWhitespaceConfig, InlineSchema, isElementOfTag, type IsInlineForWhitespace, type IsPreserveWhitespaceDom, NestedBlockSchema, parseSelector, RootSchema, sel, type WhitespaceImportConfig, } from './import';
|
|
13
|
+
export { $distributeInlineWrapper, $generateNodesFromDOMViaExtension, $getImportContextValue, $inlineStylesFromStyleSheets, $isBlockLevel, $propagateTextAlignToBlockChildren, $withImportContext, BlockSchema, CoreImportExtension, CoreImportRules, createImportState, defaultIsInline, defaultPreservesWhitespace, defineImportRule, defineOverlayRules, type DOMImportConfig, DOMImportExtension, HorizontalRuleImportExtension, HorizontalRuleImportRules, ImportOverlays, ImportSource, ImportSourceDataTransfer, type ImportSourceKind, ImportTextFormat, ImportTextStyle, ImportWhitespaceConfig, InlineSchema, isElementOfTag, type IsInlineForWhitespace, type IsPreserveWhitespaceDom, NestedBlockSchema, parseSelector, RootSchema, sel, type WhitespaceImportConfig, } from './import';
|
|
14
14
|
export { $getRenderContextValue, $getSessionDOMRenderConfig, $setRenderContextValue, $updateRenderContextValue, $withRenderContext, createRenderState, RenderContextExport, RenderContextRoot, } from './RenderContext';
|
|
15
15
|
export type { AnyDOMRenderMatch, AnyRenderStateConfig, AnyRenderStateConfigPairOrUpdater, ContextPairOrUpdater, DOMOverrideOptions, DOMRenderConfig, DOMRenderExtensionOutput, DOMRenderMatch, DOMRenderMatchConfig, NodeMatch, RenderContextReader, } from './types';
|
|
16
16
|
/**
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"html"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.45.0",
|
|
11
|
+
"version": "0.45.1-dev.0",
|
|
12
12
|
"main": "./dist/LexicalHtml.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"repository": {
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"directory": "packages/lexical-html"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@lexical/extension": "0.45.0",
|
|
21
|
-
"@lexical/internal": "0.45.0",
|
|
22
|
-
"@lexical/selection": "0.45.0",
|
|
23
|
-
"
|
|
24
|
-
"lexical": "0.45.0"
|
|
20
|
+
"@lexical/extension": "0.45.1-dev.0",
|
|
21
|
+
"@lexical/internal": "0.45.1-dev.0",
|
|
22
|
+
"@lexical/selection": "0.45.1-dev.0",
|
|
23
|
+
"lexical": "0.45.1-dev.0",
|
|
24
|
+
"@lexical/utils": "0.45.1-dev.0"
|
|
25
25
|
},
|
|
26
26
|
"module": "./dist/LexicalHtml.mjs",
|
|
27
27
|
"sideEffects": false,
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
} from '@lexical/extension';
|
|
13
13
|
import {configExtension, defineExtension} from 'lexical';
|
|
14
14
|
|
|
15
|
-
import {CoreImportExtension} from './CoreImportExtension';
|
|
16
15
|
import {defineImportRule} from './defineImportRule';
|
|
17
16
|
import {DOMImportExtension} from './DOMImportExtension';
|
|
18
17
|
import {selBase} from './sel';
|
|
@@ -31,21 +30,21 @@ const HorizontalRuleRule = defineImportRule({
|
|
|
31
30
|
export const HorizontalRuleImportRules = [HorizontalRuleRule];
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
|
-
* Bundles {@link HorizontalRuleImportRules}
|
|
35
|
-
* {@link
|
|
36
|
-
*
|
|
37
|
-
*
|
|
33
|
+
* Bundles {@link HorizontalRuleImportRules} together with the runtime
|
|
34
|
+
* {@link HorizontalRuleExtension}. The application is expected to
|
|
35
|
+
* already have `CoreImportExtension` (or some equivalent) in its
|
|
36
|
+
* dependency graph — the core/text/paragraph/inline-format rules are a
|
|
37
|
+
* shared baseline, not something this leaf importer should re-declare.
|
|
38
38
|
*
|
|
39
39
|
* Lives in `@lexical/html` (not `@lexical/extension`) because
|
|
40
40
|
* {@link DOMImportExtension} itself is in `@lexical/html`, and
|
|
41
41
|
* `@lexical/extension` is upstream of `@lexical/html` in the dependency
|
|
42
|
-
* graph
|
|
42
|
+
* graph.
|
|
43
43
|
*
|
|
44
44
|
* @experimental
|
|
45
45
|
*/
|
|
46
46
|
export const HorizontalRuleImportExtension = defineExtension({
|
|
47
47
|
dependencies: [
|
|
48
|
-
CoreImportExtension,
|
|
49
48
|
HorizontalRuleExtension,
|
|
50
49
|
configExtension(DOMImportExtension, {rules: HorizontalRuleImportRules}),
|
|
51
50
|
],
|
|
@@ -22,7 +22,10 @@ import {
|
|
|
22
22
|
IS_SUBSCRIPT,
|
|
23
23
|
IS_SUPERSCRIPT,
|
|
24
24
|
IS_UNDERLINE,
|
|
25
|
+
isBlockDomNode,
|
|
25
26
|
isDOMTextNode,
|
|
27
|
+
isLastChildInBlockNode,
|
|
28
|
+
isOnlyChildInBlockNode,
|
|
26
29
|
type LexicalNode,
|
|
27
30
|
setNodeIndentFromDOM,
|
|
28
31
|
} from 'lexical';
|
|
@@ -35,6 +38,7 @@ import {
|
|
|
35
38
|
ImportWhitespaceConfig,
|
|
36
39
|
type WhitespaceImportConfig,
|
|
37
40
|
} from './ImportContext';
|
|
41
|
+
import {$propagateTextAlignToBlockChildren, BlockSchema} from './schemas';
|
|
38
42
|
import {selBase} from './sel';
|
|
39
43
|
|
|
40
44
|
const sel = selBase;
|
|
@@ -437,7 +441,16 @@ const IgnoreScriptStyleRule = defineImportRule({
|
|
|
437
441
|
});
|
|
438
442
|
|
|
439
443
|
const LineBreakRule = defineImportRule({
|
|
440
|
-
|
|
444
|
+
// Mirror the legacy LineBreakNode.importDOM filter: stray `<br>` that
|
|
445
|
+
// are the sole or trailing child of a block parent (e.g. Apple's
|
|
446
|
+
// `<br class="Apple-interchange-newline">` clipboard sentinel, or the
|
|
447
|
+
// trailing `<br>` browsers insert after the last text in a `<div>`)
|
|
448
|
+
// would otherwise survive as a LineBreakNode and tack an extra blank
|
|
449
|
+
// line onto the imported content.
|
|
450
|
+
$import: (_ctx, el) =>
|
|
451
|
+
isOnlyChildInBlockNode(el) || isLastChildInBlockNode(el)
|
|
452
|
+
? []
|
|
453
|
+
: [$createLineBreakNode()],
|
|
441
454
|
match: sel.tag('br'),
|
|
442
455
|
name: '@lexical/html/br',
|
|
443
456
|
});
|
|
@@ -467,6 +480,52 @@ const ParagraphRule = defineImportRule({
|
|
|
467
480
|
name: '@lexical/html/p',
|
|
468
481
|
});
|
|
469
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Transparent block-container rule for any unconverted block-level DOM
|
|
485
|
+
* element — `<div>`, but also `<section>`, `<article>`, `<header>`,
|
|
486
|
+
* `<figure>`, … (everything {@link isBlockDomNode} recognizes via the
|
|
487
|
+
* legacy `BLOCK_TAG_RE`). Without it these would fall through to the
|
|
488
|
+
* dispatcher's `$hoistChildrenOf` / `DefaultHoistRule` fallback, which
|
|
489
|
+
* transparently lifts children up to the enclosing context. That works
|
|
490
|
+
* structurally, but (a) two sibling `<section>`s collapse into a single
|
|
491
|
+
* paragraph instead of two, and (b) any `text-align` set on the element
|
|
492
|
+
* is lost because the synthesized paragraph (built by the enclosing
|
|
493
|
+
* schema) sees the *grandparent* as `domParent`.
|
|
494
|
+
*
|
|
495
|
+
* The rule is registered as a `sel.any()` wildcard and defers (via
|
|
496
|
+
* `$next()`) for non-block elements so inline tags still reach the inline
|
|
497
|
+
* rules. Higher-priority tag rules (`<p>`, `<li>`, `<td>`, headings, …)
|
|
498
|
+
* are dispatched first and never reach here.
|
|
499
|
+
*
|
|
500
|
+
* The element's children run through {@link BlockSchema} so each inline
|
|
501
|
+
* run becomes its own `ParagraphNode` (with the element's `text-align`
|
|
502
|
+
* picked up via {@link $paragraphPackageRun}'s `domParent`), and any
|
|
503
|
+
* pre-existing block children get the same alignment applied via
|
|
504
|
+
* {@link $propagateTextAlignToBlockChildren}. The resulting block-level
|
|
505
|
+
* nodes are what the enclosing context sees — at the root a sibling
|
|
506
|
+
* paragraph is the natural shape; inside a block lexical container the
|
|
507
|
+
* container rule (e.g. {@link ListItemRule}) collapses paragraph
|
|
508
|
+
* children back into inline-with-line-break form. That way both `<p>`
|
|
509
|
+
* and transparent blocks (`<div>`, `<section>`, …) project to the same
|
|
510
|
+
* `ParagraphNode` intermediate, and there is no need for a marker node
|
|
511
|
+
* to distinguish them.
|
|
512
|
+
*/
|
|
513
|
+
const TransparentBlockRule = defineImportRule({
|
|
514
|
+
$import: (ctx, el, $next) => {
|
|
515
|
+
if (!isBlockDomNode(el)) {
|
|
516
|
+
// Inline element with no dedicated rule — let the inline rules (or
|
|
517
|
+
// the default hoist) handle it.
|
|
518
|
+
return $next();
|
|
519
|
+
}
|
|
520
|
+
return $propagateTextAlignToBlockChildren(
|
|
521
|
+
ctx.$importChildren(el, {schema: BlockSchema}),
|
|
522
|
+
el,
|
|
523
|
+
);
|
|
524
|
+
},
|
|
525
|
+
match: sel.any(),
|
|
526
|
+
name: '@lexical/html/transparent-block',
|
|
527
|
+
});
|
|
528
|
+
|
|
470
529
|
/**
|
|
471
530
|
* Rules covering the {@link ParagraphNode}, {@link TextNode},
|
|
472
531
|
* {@link LineBreakNode}, and {@link TabNode} cases that the legacy
|
|
@@ -479,6 +538,7 @@ const ParagraphRule = defineImportRule({
|
|
|
479
538
|
export const CoreImportRules = [
|
|
480
539
|
IgnoreScriptStyleRule,
|
|
481
540
|
ParagraphRule,
|
|
541
|
+
TransparentBlockRule,
|
|
482
542
|
TextRule,
|
|
483
543
|
LineBreakRule,
|
|
484
544
|
InlineFormatRule,
|
package/src/import/index.ts
CHANGED
package/src/import/schemas.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
$isBlockElementNode,
|
|
13
13
|
$isDecoratorNode,
|
|
14
14
|
$isElementNode,
|
|
15
|
+
$isLineBreakNode,
|
|
15
16
|
type ElementNode,
|
|
16
17
|
isHTMLElement,
|
|
17
18
|
type LexicalNode,
|
|
@@ -153,6 +154,39 @@ export function $applySchema(
|
|
|
153
154
|
return schema.$finalize ? schema.$finalize(out, parent) : out;
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Apply a parent DOM element's `text-align` (when set to one of the
|
|
159
|
+
* supported {@link ElementFormatType} values) to each block-level child
|
|
160
|
+
* Lexical node that does not yet have its own format.
|
|
161
|
+
*
|
|
162
|
+
* Mirrors the part of the legacy `wrapContinuousInlines` that wrote
|
|
163
|
+
* `node.setFormat(textAlign)` onto pre-existing block children when the
|
|
164
|
+
* DOM parent carried `style.textAlign`. Pair with
|
|
165
|
+
* {@link $paragraphPackageRun} (which carries the same propagation onto
|
|
166
|
+
* paragraphs synthesized around inline runs) to fully replicate the
|
|
167
|
+
* legacy behavior on a run of mixed children.
|
|
168
|
+
*
|
|
169
|
+
* @experimental
|
|
170
|
+
*/
|
|
171
|
+
export function $propagateTextAlignToBlockChildren(
|
|
172
|
+
children: LexicalNode[],
|
|
173
|
+
domParent: Node | null,
|
|
174
|
+
): LexicalNode[] {
|
|
175
|
+
if (!isHTMLElement(domParent)) {
|
|
176
|
+
return children;
|
|
177
|
+
}
|
|
178
|
+
const textAlign = domParent.style.textAlign;
|
|
179
|
+
if (!isAlignmentValue(textAlign)) {
|
|
180
|
+
return children;
|
|
181
|
+
}
|
|
182
|
+
for (const child of children) {
|
|
183
|
+
if ($isBlockElementNode(child) && child.getFormatType() === '') {
|
|
184
|
+
child.setFormat(textAlign);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return children;
|
|
188
|
+
}
|
|
189
|
+
|
|
156
190
|
/**
|
|
157
191
|
* Wrap a run of inline lexical nodes in a fresh paragraph, propagating the
|
|
158
192
|
* `text-align` of `domParent` as the paragraph's format type (matching the
|
|
@@ -163,6 +197,16 @@ function $paragraphPackageRun(
|
|
|
163
197
|
_parent: LexicalNode | null,
|
|
164
198
|
domParent: Node | null,
|
|
165
199
|
): LexicalNode[] {
|
|
200
|
+
// Mirror the legacy `$wrapInlineNodes` (driven by
|
|
201
|
+
// `selection.insertNodes`) shortcut where a lone `<br>` at this
|
|
202
|
+
// level (a `LineBreakNode` is the only thing in the rejected run)
|
|
203
|
+
// becomes an *empty* paragraph rather than a paragraph wrapping a
|
|
204
|
+
// visible line break — that's the form clipboard pastes ending in a
|
|
205
|
+
// trailing `<br>` (Google Docs, Gmail, …) rely on for the editor's
|
|
206
|
+
// "extra trailing empty line" expectation.
|
|
207
|
+
if (run.length === 1 && $isLineBreakNode(run[0])) {
|
|
208
|
+
run = [];
|
|
209
|
+
}
|
|
166
210
|
const paragraph = $createParagraphNode();
|
|
167
211
|
if (isHTMLElement(domParent)) {
|
|
168
212
|
const textAlign = domParent.style.textAlign;
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
import invariant from '@lexical/internal/invariant';
|
|
21
21
|
import {$sliceSelectedTextNodeContent} from '@lexical/selection';
|
|
22
22
|
import {
|
|
23
|
+
$assumeActiveEditor,
|
|
23
24
|
$createLineBreakNode,
|
|
24
25
|
$createParagraphNode,
|
|
25
26
|
$getEditor,
|
|
@@ -80,6 +81,7 @@ export {
|
|
|
80
81
|
$getImportContextValue,
|
|
81
82
|
$inlineStylesFromStyleSheets,
|
|
82
83
|
$isBlockLevel,
|
|
84
|
+
$propagateTextAlignToBlockChildren,
|
|
83
85
|
$withImportContext,
|
|
84
86
|
BlockSchema,
|
|
85
87
|
CoreImportExtension,
|
|
@@ -251,6 +253,10 @@ export function $generateHtmlFromNodes(
|
|
|
251
253
|
'To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom or use withDOM from @lexical/headless/dom before calling this function.',
|
|
252
254
|
);
|
|
253
255
|
}
|
|
256
|
+
// BC: $setTextContent now requires an active-editor scope (added in #8519).
|
|
257
|
+
// If the caller is in a legacy `editorState.read(cb)` scope (no active editor),
|
|
258
|
+
// establish one via internal API.
|
|
259
|
+
$assumeActiveEditor(editor);
|
|
254
260
|
return $generateDOMFromNodes(document.createElement('div'), selection, editor)
|
|
255
261
|
.innerHTML;
|
|
256
262
|
}
|