@ekz/lexical-extension 0.40.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/AutoFocusExtension.d.ts +24 -0
- package/ClearEditorExtension.d.ts +16 -0
- package/EditorStateExtension.d.ts +4 -0
- package/EkzLexicalExtension.dev.js +1447 -0
- package/EkzLexicalExtension.dev.mjs +1416 -0
- package/EkzLexicalExtension.js +11 -0
- package/EkzLexicalExtension.mjs +42 -0
- package/EkzLexicalExtension.node.mjs +40 -0
- package/EkzLexicalExtension.prod.js +9 -0
- package/EkzLexicalExtension.prod.mjs +9 -0
- package/ExtensionRep.d.ts +91 -0
- package/HorizontalRuleExtension.d.ts +29 -0
- package/InitialStateExtension.d.ts +25 -0
- package/LICENSE +21 -0
- package/LexicalBuilder.d.ts +77 -0
- package/LexicalExtension.js.flow +202 -0
- package/NodeSelectionExtension.d.ts +20 -0
- package/README.md +5 -0
- package/TabIndentationExtension.d.ts +20 -0
- package/config.d.ts +26 -0
- package/deepThemeMergeInPlace.d.ts +24 -0
- package/getExtensionDependencyFromEditor.d.ts +23 -0
- package/getPeerDependencyFromEditor.d.ts +71 -0
- package/index.d.ts +22 -0
- package/namedSignals.d.ts +28 -0
- package/package.json +47 -0
- package/signals.d.ts +8 -0
- package/watchedSignal.d.ts +18 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const EkzLexicalExtension = process.env.NODE_ENV !== 'production' ? require('./EkzLexicalExtension.dev.js') : require('./EkzLexicalExtension.prod.js');
|
|
11
|
+
module.exports = EkzLexicalExtension;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as modDev from './EkzLexicalExtension.dev.mjs';
|
|
10
|
+
import * as modProd from './EkzLexicalExtension.prod.mjs';
|
|
11
|
+
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
+
export const $createHorizontalRuleNode = mod.$createHorizontalRuleNode;
|
|
13
|
+
export const $isHorizontalRuleNode = mod.$isHorizontalRuleNode;
|
|
14
|
+
export const AutoFocusExtension = mod.AutoFocusExtension;
|
|
15
|
+
export const ClearEditorExtension = mod.ClearEditorExtension;
|
|
16
|
+
export const EditorStateExtension = mod.EditorStateExtension;
|
|
17
|
+
export const HorizontalRuleExtension = mod.HorizontalRuleExtension;
|
|
18
|
+
export const HorizontalRuleNode = mod.HorizontalRuleNode;
|
|
19
|
+
export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
|
|
20
|
+
export const InitialStateExtension = mod.InitialStateExtension;
|
|
21
|
+
export const LexicalBuilder = mod.LexicalBuilder;
|
|
22
|
+
export const NodeSelectionExtension = mod.NodeSelectionExtension;
|
|
23
|
+
export const TabIndentationExtension = mod.TabIndentationExtension;
|
|
24
|
+
export const batch = mod.batch;
|
|
25
|
+
export const buildEditorFromExtensions = mod.buildEditorFromExtensions;
|
|
26
|
+
export const computed = mod.computed;
|
|
27
|
+
export const configExtension = mod.configExtension;
|
|
28
|
+
export const declarePeerDependency = mod.declarePeerDependency;
|
|
29
|
+
export const defineExtension = mod.defineExtension;
|
|
30
|
+
export const effect = mod.effect;
|
|
31
|
+
export const getExtensionDependencyFromEditor = mod.getExtensionDependencyFromEditor;
|
|
32
|
+
export const getKnownTypesAndNodes = mod.getKnownTypesAndNodes;
|
|
33
|
+
export const getPeerDependencyFromEditor = mod.getPeerDependencyFromEditor;
|
|
34
|
+
export const getPeerDependencyFromEditorOrThrow = mod.getPeerDependencyFromEditorOrThrow;
|
|
35
|
+
export const namedSignals = mod.namedSignals;
|
|
36
|
+
export const registerClearEditor = mod.registerClearEditor;
|
|
37
|
+
export const registerTabIndentation = mod.registerTabIndentation;
|
|
38
|
+
export const safeCast = mod.safeCast;
|
|
39
|
+
export const shallowMergeConfig = mod.shallowMergeConfig;
|
|
40
|
+
export const signal = mod.signal;
|
|
41
|
+
export const untracked = mod.untracked;
|
|
42
|
+
export const watchedSignal = mod.watchedSignal;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./EkzLexicalExtension.dev.mjs') : import('./EkzLexicalExtension.prod.mjs'));
|
|
10
|
+
export const $createHorizontalRuleNode = mod.$createHorizontalRuleNode;
|
|
11
|
+
export const $isHorizontalRuleNode = mod.$isHorizontalRuleNode;
|
|
12
|
+
export const AutoFocusExtension = mod.AutoFocusExtension;
|
|
13
|
+
export const ClearEditorExtension = mod.ClearEditorExtension;
|
|
14
|
+
export const EditorStateExtension = mod.EditorStateExtension;
|
|
15
|
+
export const HorizontalRuleExtension = mod.HorizontalRuleExtension;
|
|
16
|
+
export const HorizontalRuleNode = mod.HorizontalRuleNode;
|
|
17
|
+
export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
|
|
18
|
+
export const InitialStateExtension = mod.InitialStateExtension;
|
|
19
|
+
export const LexicalBuilder = mod.LexicalBuilder;
|
|
20
|
+
export const NodeSelectionExtension = mod.NodeSelectionExtension;
|
|
21
|
+
export const TabIndentationExtension = mod.TabIndentationExtension;
|
|
22
|
+
export const batch = mod.batch;
|
|
23
|
+
export const buildEditorFromExtensions = mod.buildEditorFromExtensions;
|
|
24
|
+
export const computed = mod.computed;
|
|
25
|
+
export const configExtension = mod.configExtension;
|
|
26
|
+
export const declarePeerDependency = mod.declarePeerDependency;
|
|
27
|
+
export const defineExtension = mod.defineExtension;
|
|
28
|
+
export const effect = mod.effect;
|
|
29
|
+
export const getExtensionDependencyFromEditor = mod.getExtensionDependencyFromEditor;
|
|
30
|
+
export const getKnownTypesAndNodes = mod.getKnownTypesAndNodes;
|
|
31
|
+
export const getPeerDependencyFromEditor = mod.getPeerDependencyFromEditor;
|
|
32
|
+
export const getPeerDependencyFromEditorOrThrow = mod.getPeerDependencyFromEditorOrThrow;
|
|
33
|
+
export const namedSignals = mod.namedSignals;
|
|
34
|
+
export const registerClearEditor = mod.registerClearEditor;
|
|
35
|
+
export const registerTabIndentation = mod.registerTabIndentation;
|
|
36
|
+
export const safeCast = mod.safeCast;
|
|
37
|
+
export const shallowMergeConfig = mod.shallowMergeConfig;
|
|
38
|
+
export const signal = mod.signal;
|
|
39
|
+
export const untracked = mod.untracked;
|
|
40
|
+
export const watchedSignal = mod.watchedSignal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var t=require("@ekz/lexical"),e=require("@ekz/lexical-utils");const n=Symbol.for("preact-signals");function i(){if(d>1)return void d--;let t,e=!1;for(;void 0!==r;){let n=r;for(r=void 0,a++;void 0!==n;){const i=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&g(n))try{n.c()}catch(n){e||(t=n,e=!0)}n=i}}if(a=0,d--,e)throw t}function o(t){if(d>0)return t();d++;try{return t()}finally{i()}}let s,r;function c(t){const e=s;s=void 0;try{return t()}finally{s=e}}let d=0,a=0,f=0;function u(t){if(void 0===s)return;let e=t.n;return void 0===e||e.t!==s?(e={i:0,S:t,p:s.s,n:void 0,t:s,e:void 0,x:void 0,r:e},void 0!==s.s&&(s.s.n=e),s.s=e,t.n=e,32&s.f&&t.S(e),e):-1===e.i?(e.i=0,void 0!==e.n&&(e.n.p=e.p,void 0!==e.p&&(e.p.n=e.n),e.p=s.s,e.n=void 0,s.s.n=e,s.s=e),e):void 0}function l(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.W=null==e?void 0:e.watched,this.Z=null==e?void 0:e.unwatched,this.name=null==e?void 0:e.name}function h(t,e){return new l(t,e)}function g(t){for(let e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function p(t){for(let e=t.s;void 0!==e;e=e.n){const n=e.S.n;if(void 0!==n&&(e.r=n),e.S.n=e,e.i=-1,void 0===e.n){t.s=e;break}}}function m(t){let e,n=t.s;for(;void 0!==n;){const t=n.p;-1===n.i?(n.S.U(n),void 0!==t&&(t.n=n.n),void 0!==n.n&&(n.n.p=t)):e=n,n.S.n=n.r,void 0!==n.r&&(n.r=void 0),n=t}t.s=e}function x(t,e){l.call(this,void 0),this.x=t,this.s=void 0,this.g=f-1,this.f=4,this.W=null==e?void 0:e.watched,this.Z=null==e?void 0:e.unwatched,this.name=null==e?void 0:e.name}function E(t,e){return new x(t,e)}function v(t){const e=t.u;if(t.u=void 0,"function"==typeof e){d++;const n=s;s=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,S(t),e}finally{s=n,i()}}}function S(t){for(let e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,v(t)}function y(t){if(s!==this)throw new Error("Out-of-order effect");m(this),s=t,this.f&=-2,8&this.f&&S(this),i()}function N(t,e){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=null==e?void 0:e.name}function b(t,e){const n=new N(t,e);try{n.c()}catch(t){throw n.d(),t}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function R(t,e={}){const n={};for(const i in t){const o=e[i],s=h(void 0===o?t[i]:o);n[i]=s}return n}l.prototype.brand=n,l.prototype.h=function(){return!0},l.prototype.S=function(t){const e=this.t;e!==t&&void 0===t.e&&(t.x=e,this.t=t,void 0!==e?e.e=t:c(()=>{var t;null==(t=this.W)||t.call(this)}))},l.prototype.U=function(t){if(void 0!==this.t){const e=t.e,n=t.x;void 0!==e&&(e.x=n,t.e=void 0),void 0!==n&&(n.e=e,t.x=void 0),t===this.t&&(this.t=n,void 0===n&&c(()=>{var t;null==(t=this.Z)||t.call(this)}))}},l.prototype.subscribe=function(t){return b(()=>{const e=this.value,n=s;s=void 0;try{t(e)}finally{s=n}},{name:"sub"})},l.prototype.valueOf=function(){return this.value},l.prototype.toString=function(){return this.value+""},l.prototype.toJSON=function(){return this.value},l.prototype.peek=function(){const t=s;s=void 0;try{return this.value}finally{s=t}},Object.defineProperty(l.prototype,"value",{get(){const t=u(this);return void 0!==t&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(a>100)throw new Error("Cycle detected");this.v=t,this.i++,f++,d++;try{for(let t=this.t;void 0!==t;t=t.x)t.t.N()}finally{i()}}}}),x.prototype=new l,x.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===f)return!0;if(this.g=f,this.f|=1,this.i>0&&!g(this))return this.f&=-2,!0;const t=s;try{p(this),s=this;const t=this.x();(16&this.f||this.v!==t||0===this.i)&&(this.v=t,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return s=t,m(this),this.f&=-2,!0},x.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(let t=this.s;void 0!==t;t=t.n)t.S.S(t)}l.prototype.S.call(this,t)},x.prototype.U=function(t){if(void 0!==this.t&&(l.prototype.U.call(this,t),void 0===this.t)){this.f&=-33;for(let t=this.s;void 0!==t;t=t.n)t.S.U(t)}},x.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let t=this.t;void 0!==t;t=t.x)t.t.N()}},Object.defineProperty(x.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=u(this);if(this.h(),void 0!==t&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),N.prototype.c=function(){const t=this.S();try{if(8&this.f)return;if(void 0===this.x)return;const t=this.x();"function"==typeof t&&(this.u=t)}finally{t()}},N.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,v(this),p(this),d++;const t=s;return s=this,y.bind(this,t)},N.prototype.N=function(){2&this.f||(this.f|=2,this.o=r,r=this)},N.prototype.d=function(){this.f|=8,1&this.f||S(this)},N.prototype.dispose=function(){this.d()};const O=t.defineExtension({build:(t,e,n)=>R(e),config:t.safeCast({defaultSelection:"rootEnd",disabled:!1}),name:"@ekz/lexical-extension/AutoFocus",register(t,e,n){const i=n.getOutput();return b(()=>i.disabled.value?void 0:t.registerRootListener(e=>{t.focus(()=>{const t=document.activeElement;null===e||null!==t&&e.contains(t)||e.focus({preventScroll:!0})},{defaultSelection:i.defaultSelection.peek()})}))}});function w(){const e=t.$getRoot(),n=t.$getSelection(),i=t.$createParagraphNode();e.clear(),e.append(i),null!==n&&i.select(),t.$isRangeSelection(n)&&(n.format=0)}function C(e,n=w){return e.registerCommand(t.CLEAR_EDITOR_COMMAND,t=>(e.update(n),!0),t.COMMAND_PRIORITY_EDITOR)}const M=t.defineExtension({build:(t,e,n)=>R(e),config:t.safeCast({$onClear:w}),name:"@ekz/lexical-extension/ClearEditor",register(t,e,n){const{$onClear:i}=n.getOutput();return b(()=>C(t,i.value))}});function D(t){return("function"==typeof t.nodes?t.nodes():t.nodes)||[]}function _(t,e){let n;return h(t(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=t(),n=e(this)}})}const I=t.defineExtension({build:t=>_(()=>t.getEditorState(),e=>t.registerUpdateListener(t=>{e.value=t.editorState})),name:"@ekz/lexical-extension/EditorState"});function T(t,...e){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",t);for(const t of e)i.append("v",t);throw n.search=i.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function A(t,e){if(t&&e&&!Array.isArray(e)&&"object"==typeof t&&"object"==typeof e){const n=t,i=e;for(const t in i)n[t]=A(n[t],i[t]);return t}return e}const $=0,P=1,k=2,z=3,j=4,K=5,L=6,B=7;function U(t){return t.id===$}function F(t){return t.id===k}function H(t){return function(t){return t.id===P}(t)||T(305,String(t.id),String(P)),Object.assign(t,{id:k})}const G=new Set;class Y{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(t,e){this.builder=t,this.extension=e,this.configs=new Set,this.state={id:$}}mergeConfigs(){let e=this.extension.config||{};const n=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):t.shallowMergeConfig;for(const t of this.configs)e=n(e,t);return e}init(t){const e=this.state;F(e)||T(306,String(e.id));const n={getDependency:this.getInitDependency.bind(this),getDirectDependentNames:this.getDirectDependentNames.bind(this),getPeer:this.getInitPeer.bind(this),getPeerNameSet:this.getPeerNameSet.bind(this)},i={...n,getDependency:this.getDependency.bind(this),getInitResult:this.getInitResult.bind(this),getPeer:this.getPeer.bind(this)},o=function(t,e,n){return Object.assign(t,{config:e,id:z,registerState:n})}(e,this.mergeConfigs(),n);let s;this.state=o,this.extension.init&&(s=this.extension.init(t,o.config,n)),this.state=function(t,e,n){return Object.assign(t,{id:j,initResult:e,registerState:n})}(o,s,i)}build(t){const e=this.state;let n;e.id!==j&&T(307,String(e.id),String(K)),this.extension.build&&(n=this.extension.build(t,e.config,e.registerState));const i={...e.registerState,getOutput:()=>n,getSignal:this.getSignal.bind(this)};this.state=function(t,e,n){return Object.assign(t,{id:K,output:e,registerState:n})}(e,n,i)}register(t,e){this._signal=e;const n=this.state;n.id!==K&&T(308,String(n.id),String(K));const i=this.extension.register&&this.extension.register(t,n.config,n.registerState);return this.state=function(t){return Object.assign(t,{id:L})}(n),()=>{const t=this.state;t.id!==B&&T(309,String(n.id),String(B)),this.state=function(t){return Object.assign(t,{id:K})}(t),i&&i()}}afterRegistration(t){const e=this.state;let n;return e.id!==L&&T(310,String(e.id),String(L)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(t,e.config,e.registerState)),this.state=function(t){return Object.assign(t,{id:B})}(e),n}getSignal(){return void 0===this._signal&&T(311),this._signal}getInitResult(){void 0===this.extension.init&&T(312,this.extension.name);const t=this.state;return function(t){return t.id>=j}(t)||T(313,String(t.id),String(j)),t.initResult}getInitPeer(t){const e=this.builder.extensionNameMap.get(t);return e?e.getExtensionInitDependency():void 0}getExtensionInitDependency(){const t=this.state;return function(t){return t.id>=z}(t)||T(314,String(t.id),String(z)),{config:t.config}}getPeer(t){const e=this.builder.extensionNameMap.get(t);return e?e.getExtensionDependency():void 0}getInitDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&T(315,this.extension.name,t.name),e.getExtensionInitDependency()}getDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&T(315,this.extension.name,t.name),e.getExtensionDependency()}getState(){const t=this.state;return function(t){return t.id>=B}(t)||T(316,String(t.id),String(B)),t}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||G}getPeerNameSet(){let t=this._peerNameSet;return t||(t=new Set((this.extension.peerDependencies||[]).map(([t])=>t)),this._peerNameSet=t),t}getExtensionDependency(){if(!this._dependency){const t=this.state;(function(t){return t.id>=K})(t)||T(317,this.extension.name),this._dependency={config:t.config,init:t.initResult,output:t.output}}return this._dependency}}const W={tag:t.HISTORY_MERGE_TAG};function Z(){const e=t.$getRoot();e.isEmpty()&&e.append(t.$createParagraphNode())}const V=t.defineExtension({config:t.safeCast({setOptions:W,updateOptions:W}),init:({$initialEditorState:t=Z})=>({$initialEditorState:t,initialized:!1}),afterRegistration(e,{updateOptions:n,setOptions:i},o){const s=o.getInitResult();if(!s.initialized){s.initialized=!0;const{$initialEditorState:o}=s;if(t.$isEditorState(o))e.setEditorState(o,i);else if("function"==typeof o)e.update(()=>{o(e)},n);else if(o&&("string"==typeof o||"object"==typeof o)){const t=e.parseEditorState(o);e.setEditorState(t,i)}}return()=>{}},name:"@ekz/lexical-extension/InitialState",nodes:[t.RootNode,t.TextNode,t.LineBreakNode,t.TabNode,t.ParagraphNode]}),J=Symbol.for("@ekz/lexical-extension/LexicalBuilder");function q(){}function X(t){throw t}function Q(t){return Array.isArray(t)?t:[t]}const tt="0.40.0+prod.cjs";class et{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(t){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=tt,this.roots=t;for(const e of t)this.addExtension(e)}static fromExtensions(t){const e=[Q(V)];for(const n of t)e.push(Q(n));return new et(e)}static maybeFromEditor(t){const e=t[J];return e&&(e.PACKAGE_VERSION!==tt&&T(292,e.PACKAGE_VERSION,tt),e instanceof et||T(293)),e}static fromEditor(t){const e=et.maybeFromEditor(t);return void 0===e&&T(294),e}constructEditor(){const{$initialEditorState:e,onError:n,...i}=this.buildCreateEditorArgs(),o=Object.assign(t.createEditor({...i,...n?{onError:t=>{n(t,o)}}:{}}),{[J]:this});for(const t of this.sortedExtensionReps())t.build(o);return o}buildEditor(){let t=q;function n(){try{t()}finally{t=q}}const i=Object.assign(this.constructEditor(),{dispose:n,[Symbol.dispose]:n});return t=e.mergeRegister(this.registerEditor(i),()=>i.setRootElement(null)),i}hasExtensionByName(t){return this.extensionNameMap.has(t)}getExtensionRep(t){const e=this.extensionNameMap.get(t.name);if(e)return e.extension!==t&&T(295,t.name),e}addEdge(t,e,n){const i=this.outgoingConfigEdges.get(t);i?i.set(e,n):this.outgoingConfigEdges.set(t,new Map([[e,n]]));const o=this.incomingEdges.get(e);o?o.add(t):this.incomingEdges.set(e,new Set([t]))}addExtension(t){void 0!==this._sortedExtensionReps&&T(296);const e=Q(t),[n]=e;"string"!=typeof n.name&&T(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&T(298,n.name),!i){i=new Y(this,n),this.extensionNameMap.set(n.name,i);const t=this.conflicts.get(n.name);"string"==typeof t&&T(299,n.name,t);for(const t of n.conflictsWith||[])this.extensionNameMap.has(t)&&T(299,n.name,t),this.conflicts.set(t,n.name);for(const t of n.dependencies||[]){const e=Q(t);this.addEdge(n.name,e[0].name,e.slice(1)),this.addExtension(e)}for(const[t,e]of n.peerDependencies||[])this.addEdge(n.name,t,e?[e]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const t=[],e=(n,i)=>{let o=n.state;if(F(o))return;const s=n.extension.name;var r;U(o)||T(300,s,i||"[unknown]"),U(r=o)||T(304,String(r.id),String($)),o=Object.assign(r,{id:P}),n.state=o;const c=this.outgoingConfigEdges.get(s);if(c)for(const t of c.keys()){const n=this.extensionNameMap.get(t);n&&e(n,s)}o=H(o),n.state=o,t.push(n)};for(const t of this.extensionNameMap.values())U(t.state)&&e(t);for(const e of t)for(const[t,n]of this.outgoingConfigEdges.get(e.extension.name)||[])if(n.length>0){const e=this.extensionNameMap.get(t);if(e)for(const t of n)e.configs.add(t)}for(const[t,...e]of this.roots)if(e.length>0){const n=this.extensionNameMap.get(t.name);void 0===n&&T(301,t.name);for(const t of e)n.configs.add(t)}return this._sortedExtensionReps=t,this._sortedExtensionReps}registerEditor(t){const n=this.sortedExtensionReps(),i=new AbortController,o=[()=>i.abort()],s=i.signal;for(const e of n){const n=e.register(t,s);n&&o.push(n)}for(const e of n){const n=e.afterRegistration(t);n&&o.push(n)}return e.mergeRegister(...o)}buildCreateEditorArgs(){const t={},e=new Set,n=new Map,i=new Map,o={},s={},r=this.sortedExtensionReps();for(const c of r){const{extension:r}=c;if(void 0!==r.onError&&(t.onError=r.onError),void 0!==r.disableEvents&&(t.disableEvents=r.disableEvents),void 0!==r.parentEditor&&(t.parentEditor=r.parentEditor),void 0!==r.editable&&(t.editable=r.editable),void 0!==r.namespace&&(t.namespace=r.namespace),void 0!==r.$initialEditorState&&(t.$initialEditorState=r.$initialEditorState),r.nodes)for(const t of D(r)){if("function"!=typeof t){const e=n.get(t.replace);e&&T(302,r.name,t.replace.name,e.extension.name),n.set(t.replace,c)}e.add(t)}if(r.html){if(r.html.export)for(const[t,e]of r.html.export.entries())i.set(t,e);r.html.import&&Object.assign(o,r.html.import)}r.theme&&A(s,r.theme)}Object.keys(s).length>0&&(t.theme=s),e.size&&(t.nodes=[...e]);const c=Object.keys(o).length>0,d=i.size>0;(c||d)&&(t.html={},c&&(t.html.import=o),d&&(t.html.export=i));for(const e of r)e.init(t);return t.onError||(t.onError=X),t}}function nt(t,e){const n=et.fromEditor(t).extensionNameMap.get(e);return n?n.getExtensionDependency():void 0}const it=new Set,ot=t.defineExtension({build(e,n,i){const o=i.getDependency(I).output,s=h({watchedNodeKeys:new Map}),r=_(()=>{},()=>b(()=>{const e=r.peek(),{watchedNodeKeys:n}=s.value;let i,c=!1;o.value.read(()=>{if(t.$getSelection())for(const[o,s]of n.entries()){if(0===s.size){n.delete(o);continue}const r=t.$getNodeByKey(o),d=r&&r.isSelected()||!1;c=c||d!==(!!e&&e.has(o)),d&&(i=i||new Set,i.add(o))}}),!c&&i&&e&&i.size===e.size||(r.value=i)}));return{watchNodeKey:function(t){const e=E(()=>(r.value||it).has(t)),{watchedNodeKeys:n}=s.peek();let i=n.get(t);const o=void 0!==i;return i=i||new Set,i.add(e),o||(n.set(t,i),s.value={watchedNodeKeys:n}),e}}},dependencies:[I],name:"@ekz/lexical-extension/NodeSelection"}),st=t.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");class rt extends t.DecoratorNode{static getType(){return"horizontalrule"}static clone(t){return new rt(t.__key)}static importJSON(t){return dt().updateFromJSON(t)}static importDOM(){return{hr:()=>({conversion:ct,priority:0})}}exportDOM(){return{element:document.createElement("hr")}}createDOM(t){const n=document.createElement("hr");return e.addClassNamesToElement(n,t.theme.hr),n}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}}function ct(){return{node:dt()}}function dt(){return t.$create(rt)}function at(t){return t instanceof rt}const ft=t.defineExtension({dependencies:[I,ot],name:"@ekz/lexical-extension/HorizontalRule",nodes:()=>[rt],register(n,i,s){const{watchNodeKey:r}=s.getDependency(ot).output,c=h({nodeSelections:new Map}),d=n._config.theme.hrSelected??"selected";return e.mergeRegister(n.registerCommand(t.CLICK_COMMAND,e=>{if(t.isDOMNode(e.target)){const n=t.$getNodeFromDOMNode(e.target);if(at(n))return function(e,n=!1){const i=t.$getSelection(),o=e.isSelected(),s=e.getKey();let r;n&&t.$isNodeSelection(i)?r=i:(r=t.$createNodeSelection(),t.$setSelection(r)),o?r.delete(s):r.add(s)}(n,e.shiftKey),!0}return!1},t.COMMAND_PRIORITY_LOW),n.registerMutationListener(rt,(t,e)=>{o(()=>{let e=!1;const{nodeSelections:i}=c.peek();for(const[o,s]of t.entries())if("destroyed"===s)i.delete(o),e=!0;else{const t=i.get(o),s=n.getElementByKey(o);t?t.domNode.value=s:(e=!0,i.set(o,{domNode:h(s),selectedSignal:r(o)}))}e&&(c.value={nodeSelections:i})})}),b(()=>{const t=[];for(const{domNode:n,selectedSignal:i}of c.value.nodeSelections.values())t.push(b(()=>{const t=n.value;if(t){i.value?e.addClassNamesToElement(t,d):e.removeClassNamesFromElement(t,d)}}));return e.mergeRegister(...t)}))}});function ut(n,i){return e.mergeRegister(n.registerCommand(t.KEY_TAB_COMMAND,i=>{const o=t.$getSelection();if(!t.$isRangeSelection(o))return!1;i.preventDefault();const s=function(n){const i=n.getNodes();if(e.$filter(i,e=>t.$isBlockElementNode(e)&&e.canIndent()?e:null).length>0)return!0;const o=n.anchor,s=n.focus,r=s.isBefore(o)?s:o,c=r.getNode(),d=e.$getNearestBlockElementAncestorOrThrow(c);if(d.canIndent()){const e=d.getKey();let n=t.$createRangeSelection();if(n.anchor.set(e,0,"element"),n.focus.set(e,0,"element"),n=t.$normalizeSelection__EXPERIMENTAL(n),n.anchor.is(r))return!0}return!1}(o)?i.shiftKey?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND;return n.dispatchCommand(s,void 0)},t.COMMAND_PRIORITY_EDITOR),n.registerCommand(t.INDENT_CONTENT_COMMAND,()=>{const n="number"==typeof i?i:i?i.peek():null;if(null==n)return!1;const o=t.$getSelection();if(!t.$isRangeSelection(o))return!1;const s=o.getNodes().map(t=>e.$getNearestBlockElementAncestorOrThrow(t).getIndent());return Math.max(...s)+1>=n},t.COMMAND_PRIORITY_CRITICAL))}const lt=t.defineExtension({build:(t,e,n)=>R(e),config:t.safeCast({disabled:!1,maxIndent:null}),name:"@ekz/lexical-extension/TabIndentation",register(t,e,n){const{disabled:i,maxIndent:o}=n.getOutput();return b(()=>{if(!i.value)return ut(t,o)})}});exports.configExtension=t.configExtension,exports.declarePeerDependency=t.declarePeerDependency,exports.defineExtension=t.defineExtension,exports.safeCast=t.safeCast,exports.shallowMergeConfig=t.shallowMergeConfig,exports.$createHorizontalRuleNode=dt,exports.$isHorizontalRuleNode=at,exports.AutoFocusExtension=O,exports.ClearEditorExtension=M,exports.EditorStateExtension=I,exports.HorizontalRuleExtension=ft,exports.HorizontalRuleNode=rt,exports.INSERT_HORIZONTAL_RULE_COMMAND=st,exports.InitialStateExtension=V,exports.LexicalBuilder=et,exports.NodeSelectionExtension=ot,exports.TabIndentationExtension=lt,exports.batch=o,exports.buildEditorFromExtensions=function(...t){return et.fromExtensions(t).buildEditor()},exports.computed=E,exports.effect=b,exports.getExtensionDependencyFromEditor=function(t,e){const n=et.fromEditor(t).getExtensionRep(e);return void 0===n&&T(303,e.name),n.getExtensionDependency()},exports.getKnownTypesAndNodes=function(t){const e=new Set,n=new Set;for(const i of D(t)){const t="function"==typeof i?i:i.replace;e.add(t.getType()),n.add(t)}return{nodes:n,types:e}},exports.getPeerDependencyFromEditor=nt,exports.getPeerDependencyFromEditorOrThrow=function(t,e){const n=nt(t,e);return void 0===n&&T(291,e),n},exports.namedSignals=R,exports.registerClearEditor=C,exports.registerTabIndentation=ut,exports.signal=h,exports.untracked=c,exports.watchedSignal=_;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{defineExtension as t,safeCast as e,CLEAR_EDITOR_COMMAND as n,COMMAND_PRIORITY_EDITOR as i,$getRoot as o,$getSelection as s,$createParagraphNode as r,$isRangeSelection as c,shallowMergeConfig as d,RootNode as a,TextNode as u,LineBreakNode as f,TabNode as h,ParagraphNode as l,$isEditorState as g,HISTORY_MERGE_TAG as p,createEditor as m,$getNodeByKey as v,createCommand as x,$create as y,CLICK_COMMAND as S,isDOMNode as E,$getNodeFromDOMNode as b,COMMAND_PRIORITY_LOW as w,DecoratorNode as N,$isNodeSelection as O,$createNodeSelection as R,$setSelection as M,KEY_TAB_COMMAND as C,OUTDENT_CONTENT_COMMAND as D,INDENT_CONTENT_COMMAND as _,INSERT_TAB_COMMAND as I,COMMAND_PRIORITY_CRITICAL as k,$isBlockElementNode as z,$createRangeSelection as j,$normalizeSelection__EXPERIMENTAL as A}from"@ekz/lexical";export{configExtension,declarePeerDependency,defineExtension,safeCast,shallowMergeConfig}from"@ekz/lexical";import{mergeRegister as P,addClassNamesToElement as K,removeClassNamesFromElement as $,$getNearestBlockElementAncestorOrThrow as U,$filter as L}from"@ekz/lexical-utils";const T=Symbol.for("preact-signals");function B(){if(Z>1)return void Z--;let t,e=!1;for(;void 0!==V;){let n=V;for(V=void 0,J++;void 0!==n;){const i=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Y(n))try{n.c()}catch(n){e||(t=n,e=!0)}n=i}}if(J=0,Z--,e)throw t}function F(t){if(Z>0)return t();Z++;try{return t()}finally{B()}}let G,V;function W(t){const e=G;G=void 0;try{return t()}finally{G=e}}let Z=0,J=0,H=0;function q(t){if(void 0===G)return;let e=t.n;return void 0===e||e.t!==G?(e={i:0,S:t,p:G.s,n:void 0,t:G,e:void 0,x:void 0,r:e},void 0!==G.s&&(G.s.n=e),G.s=e,t.n=e,32&G.f&&t.S(e),e):-1===e.i?(e.i=0,void 0!==e.n&&(e.n.p=e.p,void 0!==e.p&&(e.p.n=e.n),e.p=G.s,e.n=void 0,G.s.n=e,G.s=e),e):void 0}function Q(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.W=null==e?void 0:e.watched,this.Z=null==e?void 0:e.unwatched,this.name=null==e?void 0:e.name}function X(t,e){return new Q(t,e)}function Y(t){for(let e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function tt(t){for(let e=t.s;void 0!==e;e=e.n){const n=e.S.n;if(void 0!==n&&(e.r=n),e.S.n=e,e.i=-1,void 0===e.n){t.s=e;break}}}function et(t){let e,n=t.s;for(;void 0!==n;){const t=n.p;-1===n.i?(n.S.U(n),void 0!==t&&(t.n=n.n),void 0!==n.n&&(n.n.p=t)):e=n,n.S.n=n.r,void 0!==n.r&&(n.r=void 0),n=t}t.s=e}function nt(t,e){Q.call(this,void 0),this.x=t,this.s=void 0,this.g=H-1,this.f=4,this.W=null==e?void 0:e.watched,this.Z=null==e?void 0:e.unwatched,this.name=null==e?void 0:e.name}function it(t,e){return new nt(t,e)}function ot(t){const e=t.u;if(t.u=void 0,"function"==typeof e){Z++;const n=G;G=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,st(t),e}finally{G=n,B()}}}function st(t){for(let e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,ot(t)}function rt(t){if(G!==this)throw new Error("Out-of-order effect");et(this),G=t,this.f&=-2,8&this.f&&st(this),B()}function ct(t,e){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=null==e?void 0:e.name}function dt(t,e){const n=new ct(t,e);try{n.c()}catch(t){throw n.d(),t}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function at(t,e={}){const n={};for(const i in t){const o=e[i],s=X(void 0===o?t[i]:o);n[i]=s}return n}Q.prototype.brand=T,Q.prototype.h=function(){return!0},Q.prototype.S=function(t){const e=this.t;e!==t&&void 0===t.e&&(t.x=e,this.t=t,void 0!==e?e.e=t:W(()=>{var t;null==(t=this.W)||t.call(this)}))},Q.prototype.U=function(t){if(void 0!==this.t){const e=t.e,n=t.x;void 0!==e&&(e.x=n,t.e=void 0),void 0!==n&&(n.e=e,t.x=void 0),t===this.t&&(this.t=n,void 0===n&&W(()=>{var t;null==(t=this.Z)||t.call(this)}))}},Q.prototype.subscribe=function(t){return dt(()=>{const e=this.value,n=G;G=void 0;try{t(e)}finally{G=n}},{name:"sub"})},Q.prototype.valueOf=function(){return this.value},Q.prototype.toString=function(){return this.value+""},Q.prototype.toJSON=function(){return this.value},Q.prototype.peek=function(){const t=G;G=void 0;try{return this.value}finally{G=t}},Object.defineProperty(Q.prototype,"value",{get(){const t=q(this);return void 0!==t&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(J>100)throw new Error("Cycle detected");this.v=t,this.i++,H++,Z++;try{for(let t=this.t;void 0!==t;t=t.x)t.t.N()}finally{B()}}}}),nt.prototype=new Q,nt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===H)return!0;if(this.g=H,this.f|=1,this.i>0&&!Y(this))return this.f&=-2,!0;const t=G;try{tt(this),G=this;const t=this.x();(16&this.f||this.v!==t||0===this.i)&&(this.v=t,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return G=t,et(this),this.f&=-2,!0},nt.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(let t=this.s;void 0!==t;t=t.n)t.S.S(t)}Q.prototype.S.call(this,t)},nt.prototype.U=function(t){if(void 0!==this.t&&(Q.prototype.U.call(this,t),void 0===this.t)){this.f&=-33;for(let t=this.s;void 0!==t;t=t.n)t.S.U(t)}},nt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let t=this.t;void 0!==t;t=t.x)t.t.N()}},Object.defineProperty(nt.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=q(this);if(this.h(),void 0!==t&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),ct.prototype.c=function(){const t=this.S();try{if(8&this.f)return;if(void 0===this.x)return;const t=this.x();"function"==typeof t&&(this.u=t)}finally{t()}},ct.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,ot(this),tt(this),Z++;const t=G;return G=this,rt.bind(this,t)},ct.prototype.N=function(){2&this.f||(this.f|=2,this.o=V,V=this)},ct.prototype.d=function(){this.f|=8,1&this.f||st(this)},ct.prototype.dispose=function(){this.d()};const ut=t({build:(t,e,n)=>at(e),config:e({defaultSelection:"rootEnd",disabled:!1}),name:"@ekz/lexical-extension/AutoFocus",register(t,e,n){const i=n.getOutput();return dt(()=>i.disabled.value?void 0:t.registerRootListener(e=>{t.focus(()=>{const t=document.activeElement;null===e||null!==t&&e.contains(t)||e.focus({preventScroll:!0})},{defaultSelection:i.defaultSelection.peek()})}))}});function ft(){const t=o(),e=s(),n=r();t.clear(),t.append(n),null!==e&&n.select(),c(e)&&(e.format=0)}function ht(t,e=ft){return t.registerCommand(n,n=>(t.update(e),!0),i)}const lt=t({build:(t,e,n)=>at(e),config:e({$onClear:ft}),name:"@ekz/lexical-extension/ClearEditor",register(t,e,n){const{$onClear:i}=n.getOutput();return dt(()=>ht(t,i.value))}});function gt(t){const e=new Set,n=new Set;for(const i of pt(t)){const t="function"==typeof i?i:i.replace;e.add(t.getType()),n.add(t)}return{nodes:n,types:e}}function pt(t){return("function"==typeof t.nodes?t.nodes():t.nodes)||[]}function mt(t,e){let n;return X(t(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=t(),n=e(this)}})}const vt=t({build:t=>mt(()=>t.getEditorState(),e=>t.registerUpdateListener(t=>{e.value=t.editorState})),name:"@ekz/lexical-extension/EditorState"});function xt(t,...e){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",t);for(const t of e)i.append("v",t);throw n.search=i.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function yt(t,e){if(t&&e&&!Array.isArray(e)&&"object"==typeof t&&"object"==typeof e){const n=t,i=e;for(const t in i)n[t]=yt(n[t],i[t]);return t}return e}const St=0,Et=1,bt=2,wt=3,Nt=4,Ot=5,Rt=6,Mt=7;function Ct(t){return t.id===St}function Dt(t){return t.id===bt}function _t(t){return function(t){return t.id===Et}(t)||xt(305,String(t.id),String(Et)),Object.assign(t,{id:bt})}const It=new Set;class kt{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(t,e){this.builder=t,this.extension=e,this.configs=new Set,this.state={id:St}}mergeConfigs(){let t=this.extension.config||{};const e=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):d;for(const n of this.configs)t=e(t,n);return t}init(t){const e=this.state;Dt(e)||xt(306,String(e.id));const n={getDependency:this.getInitDependency.bind(this),getDirectDependentNames:this.getDirectDependentNames.bind(this),getPeer:this.getInitPeer.bind(this),getPeerNameSet:this.getPeerNameSet.bind(this)},i={...n,getDependency:this.getDependency.bind(this),getInitResult:this.getInitResult.bind(this),getPeer:this.getPeer.bind(this)},o=function(t,e,n){return Object.assign(t,{config:e,id:wt,registerState:n})}(e,this.mergeConfigs(),n);let s;this.state=o,this.extension.init&&(s=this.extension.init(t,o.config,n)),this.state=function(t,e,n){return Object.assign(t,{id:Nt,initResult:e,registerState:n})}(o,s,i)}build(t){const e=this.state;let n;e.id!==Nt&&xt(307,String(e.id),String(Ot)),this.extension.build&&(n=this.extension.build(t,e.config,e.registerState));const i={...e.registerState,getOutput:()=>n,getSignal:this.getSignal.bind(this)};this.state=function(t,e,n){return Object.assign(t,{id:Ot,output:e,registerState:n})}(e,n,i)}register(t,e){this._signal=e;const n=this.state;n.id!==Ot&&xt(308,String(n.id),String(Ot));const i=this.extension.register&&this.extension.register(t,n.config,n.registerState);return this.state=function(t){return Object.assign(t,{id:Rt})}(n),()=>{const t=this.state;t.id!==Mt&&xt(309,String(n.id),String(Mt)),this.state=function(t){return Object.assign(t,{id:Ot})}(t),i&&i()}}afterRegistration(t){const e=this.state;let n;return e.id!==Rt&&xt(310,String(e.id),String(Rt)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(t,e.config,e.registerState)),this.state=function(t){return Object.assign(t,{id:Mt})}(e),n}getSignal(){return void 0===this._signal&&xt(311),this._signal}getInitResult(){void 0===this.extension.init&&xt(312,this.extension.name);const t=this.state;return function(t){return t.id>=Nt}(t)||xt(313,String(t.id),String(Nt)),t.initResult}getInitPeer(t){const e=this.builder.extensionNameMap.get(t);return e?e.getExtensionInitDependency():void 0}getExtensionInitDependency(){const t=this.state;return function(t){return t.id>=wt}(t)||xt(314,String(t.id),String(wt)),{config:t.config}}getPeer(t){const e=this.builder.extensionNameMap.get(t);return e?e.getExtensionDependency():void 0}getInitDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&xt(315,this.extension.name,t.name),e.getExtensionInitDependency()}getDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&xt(315,this.extension.name,t.name),e.getExtensionDependency()}getState(){const t=this.state;return function(t){return t.id>=Mt}(t)||xt(316,String(t.id),String(Mt)),t}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||It}getPeerNameSet(){let t=this._peerNameSet;return t||(t=new Set((this.extension.peerDependencies||[]).map(([t])=>t)),this._peerNameSet=t),t}getExtensionDependency(){if(!this._dependency){const t=this.state;(function(t){return t.id>=Ot})(t)||xt(317,this.extension.name),this._dependency={config:t.config,init:t.initResult,output:t.output}}return this._dependency}}const zt={tag:p};function jt(){const t=o();t.isEmpty()&&t.append(r())}const At=t({config:e({setOptions:zt,updateOptions:zt}),init:({$initialEditorState:t=jt})=>({$initialEditorState:t,initialized:!1}),afterRegistration(t,{updateOptions:e,setOptions:n},i){const o=i.getInitResult();if(!o.initialized){o.initialized=!0;const{$initialEditorState:i}=o;if(g(i))t.setEditorState(i,n);else if("function"==typeof i)t.update(()=>{i(t)},e);else if(i&&("string"==typeof i||"object"==typeof i)){const e=t.parseEditorState(i);t.setEditorState(e,n)}}return()=>{}},name:"@ekz/lexical-extension/InitialState",nodes:[a,u,f,h,l]}),Pt=Symbol.for("@ekz/lexical-extension/LexicalBuilder");function Kt(...t){return Bt.fromExtensions(t).buildEditor()}function $t(){}function Ut(t){throw t}function Lt(t){return Array.isArray(t)?t:[t]}const Tt="0.40.0+prod.esm";class Bt{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(t){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=Tt,this.roots=t;for(const e of t)this.addExtension(e)}static fromExtensions(t){const e=[Lt(At)];for(const n of t)e.push(Lt(n));return new Bt(e)}static maybeFromEditor(t){const e=t[Pt];return e&&(e.PACKAGE_VERSION!==Tt&&xt(292,e.PACKAGE_VERSION,Tt),e instanceof Bt||xt(293)),e}static fromEditor(t){const e=Bt.maybeFromEditor(t);return void 0===e&&xt(294),e}constructEditor(){const{$initialEditorState:t,onError:e,...n}=this.buildCreateEditorArgs(),i=Object.assign(m({...n,...e?{onError:t=>{e(t,i)}}:{}}),{[Pt]:this});for(const t of this.sortedExtensionReps())t.build(i);return i}buildEditor(){let t=$t;function e(){try{t()}finally{t=$t}}const n=Object.assign(this.constructEditor(),{dispose:e,[Symbol.dispose]:e});return t=P(this.registerEditor(n),()=>n.setRootElement(null)),n}hasExtensionByName(t){return this.extensionNameMap.has(t)}getExtensionRep(t){const e=this.extensionNameMap.get(t.name);if(e)return e.extension!==t&&xt(295,t.name),e}addEdge(t,e,n){const i=this.outgoingConfigEdges.get(t);i?i.set(e,n):this.outgoingConfigEdges.set(t,new Map([[e,n]]));const o=this.incomingEdges.get(e);o?o.add(t):this.incomingEdges.set(e,new Set([t]))}addExtension(t){void 0!==this._sortedExtensionReps&&xt(296);const e=Lt(t),[n]=e;"string"!=typeof n.name&&xt(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&xt(298,n.name),!i){i=new kt(this,n),this.extensionNameMap.set(n.name,i);const t=this.conflicts.get(n.name);"string"==typeof t&&xt(299,n.name,t);for(const t of n.conflictsWith||[])this.extensionNameMap.has(t)&&xt(299,n.name,t),this.conflicts.set(t,n.name);for(const t of n.dependencies||[]){const e=Lt(t);this.addEdge(n.name,e[0].name,e.slice(1)),this.addExtension(e)}for(const[t,e]of n.peerDependencies||[])this.addEdge(n.name,t,e?[e]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const t=[],e=(n,i)=>{let o=n.state;if(Dt(o))return;const s=n.extension.name;var r;Ct(o)||xt(300,s,i||"[unknown]"),Ct(r=o)||xt(304,String(r.id),String(St)),o=Object.assign(r,{id:Et}),n.state=o;const c=this.outgoingConfigEdges.get(s);if(c)for(const t of c.keys()){const n=this.extensionNameMap.get(t);n&&e(n,s)}o=_t(o),n.state=o,t.push(n)};for(const t of this.extensionNameMap.values())Ct(t.state)&&e(t);for(const e of t)for(const[t,n]of this.outgoingConfigEdges.get(e.extension.name)||[])if(n.length>0){const e=this.extensionNameMap.get(t);if(e)for(const t of n)e.configs.add(t)}for(const[t,...e]of this.roots)if(e.length>0){const n=this.extensionNameMap.get(t.name);void 0===n&&xt(301,t.name);for(const t of e)n.configs.add(t)}return this._sortedExtensionReps=t,this._sortedExtensionReps}registerEditor(t){const e=this.sortedExtensionReps(),n=new AbortController,i=[()=>n.abort()],o=n.signal;for(const n of e){const e=n.register(t,o);e&&i.push(e)}for(const n of e){const e=n.afterRegistration(t);e&&i.push(e)}return P(...i)}buildCreateEditorArgs(){const t={},e=new Set,n=new Map,i=new Map,o={},s={},r=this.sortedExtensionReps();for(const c of r){const{extension:r}=c;if(void 0!==r.onError&&(t.onError=r.onError),void 0!==r.disableEvents&&(t.disableEvents=r.disableEvents),void 0!==r.parentEditor&&(t.parentEditor=r.parentEditor),void 0!==r.editable&&(t.editable=r.editable),void 0!==r.namespace&&(t.namespace=r.namespace),void 0!==r.$initialEditorState&&(t.$initialEditorState=r.$initialEditorState),r.nodes)for(const t of pt(r)){if("function"!=typeof t){const e=n.get(t.replace);e&&xt(302,r.name,t.replace.name,e.extension.name),n.set(t.replace,c)}e.add(t)}if(r.html){if(r.html.export)for(const[t,e]of r.html.export.entries())i.set(t,e);r.html.import&&Object.assign(o,r.html.import)}r.theme&&yt(s,r.theme)}Object.keys(s).length>0&&(t.theme=s),e.size&&(t.nodes=[...e]);const c=Object.keys(o).length>0,d=i.size>0;(c||d)&&(t.html={},c&&(t.html.import=o),d&&(t.html.export=i));for(const e of r)e.init(t);return t.onError||(t.onError=Ut),t}}function Ft(t,e){const n=Bt.fromEditor(t).getExtensionRep(e);return void 0===n&&xt(303,e.name),n.getExtensionDependency()}function Gt(t,e){const n=Bt.fromEditor(t).extensionNameMap.get(e);return n?n.getExtensionDependency():void 0}function Vt(t,e){const n=Gt(t,e);return void 0===n&&xt(291,e),n}const Wt=new Set,Zt=t({build(t,e,n){const i=n.getDependency(vt).output,o=X({watchedNodeKeys:new Map}),r=mt(()=>{},()=>dt(()=>{const t=r.peek(),{watchedNodeKeys:e}=o.value;let n,c=!1;i.value.read(()=>{if(s())for(const[i,o]of e.entries()){if(0===o.size){e.delete(i);continue}const s=v(i),r=s&&s.isSelected()||!1;c=c||r!==(!!t&&t.has(i)),r&&(n=n||new Set,n.add(i))}}),!c&&n&&t&&n.size===t.size||(r.value=n)}));return{watchNodeKey:function(t){const e=it(()=>(r.value||Wt).has(t)),{watchedNodeKeys:n}=o.peek();let i=n.get(t);const s=void 0!==i;return i=i||new Set,i.add(e),s||(n.set(t,i),o.value={watchedNodeKeys:n}),e}}},dependencies:[vt],name:"@ekz/lexical-extension/NodeSelection"}),Jt=x("INSERT_HORIZONTAL_RULE_COMMAND");class Ht extends N{static getType(){return"horizontalrule"}static clone(t){return new Ht(t.__key)}static importJSON(t){return Qt().updateFromJSON(t)}static importDOM(){return{hr:()=>({conversion:qt,priority:0})}}exportDOM(){return{element:document.createElement("hr")}}createDOM(t){const e=document.createElement("hr");return K(e,t.theme.hr),e}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}}function qt(){return{node:Qt()}}function Qt(){return y(Ht)}function Xt(t){return t instanceof Ht}const Yt=t({dependencies:[vt,Zt],name:"@ekz/lexical-extension/HorizontalRule",nodes:()=>[Ht],register(t,e,n){const{watchNodeKey:i}=n.getDependency(Zt).output,o=X({nodeSelections:new Map}),r=t._config.theme.hrSelected??"selected";return P(t.registerCommand(S,t=>{if(E(t.target)){const e=b(t.target);if(Xt(e))return function(t,e=!1){const n=s(),i=t.isSelected(),o=t.getKey();let r;e&&O(n)?r=n:(r=R(),M(r)),i?r.delete(o):r.add(o)}(e,t.shiftKey),!0}return!1},w),t.registerMutationListener(Ht,(e,n)=>{F(()=>{let n=!1;const{nodeSelections:s}=o.peek();for(const[o,r]of e.entries())if("destroyed"===r)s.delete(o),n=!0;else{const e=s.get(o),r=t.getElementByKey(o);e?e.domNode.value=r:(n=!0,s.set(o,{domNode:X(r),selectedSignal:i(o)}))}n&&(o.value={nodeSelections:s})})}),dt(()=>{const t=[];for(const{domNode:e,selectedSignal:n}of o.value.nodeSelections.values())t.push(dt(()=>{const t=e.value;if(t){n.value?K(t,r):$(t,r)}}));return P(...t)}))}});function te(t,e){return P(t.registerCommand(C,e=>{const n=s();if(!c(n))return!1;e.preventDefault();const i=function(t){const e=t.getNodes();if(L(e,t=>z(t)&&t.canIndent()?t:null).length>0)return!0;const n=t.anchor,i=t.focus,o=i.isBefore(n)?i:n,s=o.getNode(),r=U(s);if(r.canIndent()){const t=r.getKey();let e=j();if(e.anchor.set(t,0,"element"),e.focus.set(t,0,"element"),e=A(e),e.anchor.is(o))return!0}return!1}(n)?e.shiftKey?D:_:I;return t.dispatchCommand(i,void 0)},i),t.registerCommand(_,()=>{const t="number"==typeof e?e:e?e.peek():null;if(null==t)return!1;const n=s();if(!c(n))return!1;const i=n.getNodes().map(t=>U(t).getIndent());return Math.max(...i)+1>=t},k))}const ee=t({build:(t,e,n)=>at(e),config:e({disabled:!1,maxIndent:null}),name:"@ekz/lexical-extension/TabIndentation",register(t,e,n){const{disabled:i,maxIndent:o}=n.getOutput();return dt(()=>{if(!i.value)return te(t,o)})}});export{Qt as $createHorizontalRuleNode,Xt as $isHorizontalRuleNode,ut as AutoFocusExtension,lt as ClearEditorExtension,vt as EditorStateExtension,Yt as HorizontalRuleExtension,Ht as HorizontalRuleNode,Jt as INSERT_HORIZONTAL_RULE_COMMAND,At as InitialStateExtension,Bt as LexicalBuilder,Zt as NodeSelectionExtension,ee as TabIndentationExtension,F as batch,Kt as buildEditorFromExtensions,it as computed,dt as effect,Ft as getExtensionDependencyFromEditor,gt as getKnownTypesAndNodes,Gt as getPeerDependencyFromEditor,Vt as getPeerDependencyFromEditorOrThrow,at as namedSignals,ht as registerClearEditor,te as registerTabIndentation,X as signal,W as untracked,mt as watchedSignal};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { LexicalBuilder } from './LexicalBuilder';
|
|
9
|
+
import type { AnyLexicalExtension, ExtensionBuildState, ExtensionInitState, ExtensionRegisterState, InitialEditorConfig, LexicalEditor, LexicalExtensionConfig, LexicalExtensionDependency, LexicalExtensionInit, LexicalExtensionOutput } from '@ekz/lexical';
|
|
10
|
+
export declare const ExtensionRepStateIds: {
|
|
11
|
+
readonly unmarked: 0;
|
|
12
|
+
readonly temporary: 1;
|
|
13
|
+
readonly permanent: 2;
|
|
14
|
+
readonly configured: 3;
|
|
15
|
+
readonly initialized: 4;
|
|
16
|
+
readonly built: 5;
|
|
17
|
+
readonly registered: 6;
|
|
18
|
+
readonly afterRegistration: 7;
|
|
19
|
+
};
|
|
20
|
+
interface UnmarkedState {
|
|
21
|
+
id: (typeof ExtensionRepStateIds)['unmarked'];
|
|
22
|
+
}
|
|
23
|
+
interface TemporaryState {
|
|
24
|
+
id: (typeof ExtensionRepStateIds)['temporary'];
|
|
25
|
+
}
|
|
26
|
+
interface PermanentState {
|
|
27
|
+
id: (typeof ExtensionRepStateIds)['permanent'];
|
|
28
|
+
}
|
|
29
|
+
interface ConfiguredState<Extension extends AnyLexicalExtension> {
|
|
30
|
+
id: (typeof ExtensionRepStateIds)['configured'];
|
|
31
|
+
config: LexicalExtensionConfig<Extension>;
|
|
32
|
+
registerState: ExtensionInitState;
|
|
33
|
+
}
|
|
34
|
+
interface InitializedState<Extension extends AnyLexicalExtension> extends Omit<ConfiguredState<Extension>, 'id' | 'registerState'> {
|
|
35
|
+
id: (typeof ExtensionRepStateIds)['initialized'];
|
|
36
|
+
initResult: LexicalExtensionInit<Extension>;
|
|
37
|
+
registerState: ExtensionBuildState<LexicalExtensionInit<Extension>>;
|
|
38
|
+
}
|
|
39
|
+
interface BuiltState<Extension extends AnyLexicalExtension> extends Omit<ConfiguredState<Extension>, 'id' | 'registerState'> {
|
|
40
|
+
id: (typeof ExtensionRepStateIds)['built'];
|
|
41
|
+
initResult: LexicalExtensionInit<Extension>;
|
|
42
|
+
output: LexicalExtensionOutput<Extension>;
|
|
43
|
+
registerState: ExtensionRegisterState<LexicalExtensionInit<Extension>, LexicalExtensionOutput<Extension>>;
|
|
44
|
+
}
|
|
45
|
+
interface RegisteredState<Extension extends AnyLexicalExtension> extends Omit<BuiltState<Extension>, 'id'> {
|
|
46
|
+
id: (typeof ExtensionRepStateIds)['registered'];
|
|
47
|
+
}
|
|
48
|
+
interface AfterRegistrationState<Extension extends AnyLexicalExtension> extends Omit<RegisteredState<Extension>, 'id'> {
|
|
49
|
+
id: (typeof ExtensionRepStateIds)['afterRegistration'];
|
|
50
|
+
}
|
|
51
|
+
export type ExtensionRepState<Extension extends AnyLexicalExtension> = UnmarkedState | TemporaryState | PermanentState | ConfiguredState<Extension> | InitializedState<Extension> | BuiltState<Extension> | RegisteredState<Extension> | AfterRegistrationState<Extension>;
|
|
52
|
+
export declare function isExactlyUnmarkedExtensionRepState<Extension extends AnyLexicalExtension>(state: ExtensionRepState<Extension>): state is UnmarkedState;
|
|
53
|
+
export declare function isExactlyPermanentExtensionRepState<Extension extends AnyLexicalExtension>(state: ExtensionRepState<Extension>): state is PermanentState;
|
|
54
|
+
export declare function applyTemporaryMark<Extension extends AnyLexicalExtension>(state: ExtensionRepState<Extension>): TemporaryState;
|
|
55
|
+
export declare function applyPermanentMark<Extension extends AnyLexicalExtension>(state: ExtensionRepState<Extension>): PermanentState;
|
|
56
|
+
export declare function applyConfiguredState<Extension extends AnyLexicalExtension>(state: PermanentState, config: LexicalExtensionConfig<Extension>, registerState: ExtensionInitState): ConfiguredState<Extension>;
|
|
57
|
+
export declare function applyInitializedState<Extension extends AnyLexicalExtension>(state: ConfiguredState<Extension>, initResult: LexicalExtensionInit<Extension>, registerState: ExtensionBuildState<LexicalExtensionInit<Extension>>): InitializedState<Extension>;
|
|
58
|
+
export declare function applyBuiltState<Extension extends AnyLexicalExtension>(state: InitializedState<Extension>, output: LexicalExtensionOutput<Extension>, registerState: ExtensionRegisterState<LexicalExtensionInit<Extension>, LexicalExtensionOutput<Extension>>): BuiltState<Extension>;
|
|
59
|
+
export declare function applyRegisteredState<Extension extends AnyLexicalExtension>(state: BuiltState<Extension>): never;
|
|
60
|
+
export declare function applyAfterRegistrationState<Extension extends AnyLexicalExtension>(state: RegisteredState<Extension>): AfterRegistrationState<Extension>;
|
|
61
|
+
export declare function rollbackToBuiltState<Extension extends AnyLexicalExtension>(state: AfterRegistrationState<Extension>): BuiltState<Extension>;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare class ExtensionRep<Extension extends AnyLexicalExtension> {
|
|
66
|
+
builder: LexicalBuilder;
|
|
67
|
+
configs: Set<Partial<LexicalExtensionConfig<Extension>>>;
|
|
68
|
+
_dependency?: LexicalExtensionDependency<Extension>;
|
|
69
|
+
_peerNameSet?: Set<string>;
|
|
70
|
+
extension: Extension;
|
|
71
|
+
state: ExtensionRepState<Extension>;
|
|
72
|
+
_signal?: AbortSignal;
|
|
73
|
+
constructor(builder: LexicalBuilder, extension: Extension);
|
|
74
|
+
mergeConfigs(): LexicalExtensionConfig<Extension>;
|
|
75
|
+
init(editorConfig: InitialEditorConfig): void;
|
|
76
|
+
build(editor: LexicalEditor): void;
|
|
77
|
+
register(editor: LexicalEditor, signal: AbortSignal): undefined | (() => void);
|
|
78
|
+
afterRegistration(editor: LexicalEditor): undefined | (() => void);
|
|
79
|
+
getSignal(): AbortSignal;
|
|
80
|
+
getInitResult(): LexicalExtensionInit<Extension>;
|
|
81
|
+
getInitPeer<PeerExtension extends AnyLexicalExtension = never>(name: PeerExtension['name']): undefined | Omit<LexicalExtensionDependency<PeerExtension>, 'output' | 'init'>;
|
|
82
|
+
getExtensionInitDependency(): Omit<LexicalExtensionDependency<Extension>, 'output' | 'init'>;
|
|
83
|
+
getPeer<PeerExtension extends AnyLexicalExtension = never>(name: PeerExtension['name']): undefined | LexicalExtensionDependency<PeerExtension>;
|
|
84
|
+
getInitDependency<Dependency extends AnyLexicalExtension>(dep: Dependency): Omit<LexicalExtensionDependency<Dependency>, 'output' | 'init'>;
|
|
85
|
+
getDependency<Dependency extends AnyLexicalExtension>(dep: Dependency): LexicalExtensionDependency<Dependency>;
|
|
86
|
+
getState(): AfterRegistrationState<Extension>;
|
|
87
|
+
getDirectDependentNames(): ReadonlySet<string>;
|
|
88
|
+
getPeerNameSet(): ReadonlySet<string>;
|
|
89
|
+
getExtensionDependency(): LexicalExtensionDependency<Extension>;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalCommand, LexicalNode, SerializedLexicalNode } from '@ekz/lexical';
|
|
9
|
+
import { DecoratorNode } from '@ekz/lexical';
|
|
10
|
+
export type SerializedHorizontalRuleNode = SerializedLexicalNode;
|
|
11
|
+
export declare const INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
|
|
12
|
+
export declare class HorizontalRuleNode extends DecoratorNode<unknown> {
|
|
13
|
+
static getType(): string;
|
|
14
|
+
static clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
15
|
+
static importJSON(serializedNode: SerializedHorizontalRuleNode): HorizontalRuleNode;
|
|
16
|
+
static importDOM(): DOMConversionMap | null;
|
|
17
|
+
exportDOM(): DOMExportOutput;
|
|
18
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
19
|
+
getTextContent(): string;
|
|
20
|
+
isInline(): false;
|
|
21
|
+
updateDOM(): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function $createHorizontalRuleNode(): HorizontalRuleNode;
|
|
24
|
+
export declare function $isHorizontalRuleNode(node: LexicalNode | null | undefined): node is HorizontalRuleNode;
|
|
25
|
+
/**
|
|
26
|
+
* An extension for HorizontalRuleNode that provides an implementation that
|
|
27
|
+
* works without any React dependency.
|
|
28
|
+
*/
|
|
29
|
+
export declare const HorizontalRuleExtension: import("@ekz/lexical").LexicalExtension<import("@ekz/lexical").ExtensionConfigBase, "@ekz/lexical-extension/HorizontalRule", unknown, unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { type EditorSetOptions, type EditorUpdateOptions } from '@ekz/lexical';
|
|
9
|
+
export interface InitialStateConfig {
|
|
10
|
+
updateOptions: EditorUpdateOptions;
|
|
11
|
+
setOptions: EditorSetOptions;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An extension to set the initial state of the editor from
|
|
15
|
+
* a function or serialized JSON EditorState. This is
|
|
16
|
+
* implicitly included with all editors built with
|
|
17
|
+
* Lexical Extension. This happens in the `afterRegistration`
|
|
18
|
+
* phase so your initial state may depend on registered commands,
|
|
19
|
+
* but you should not call `editor.setRootElement` earlier than
|
|
20
|
+
* this phase to avoid rendering an empty editor first.
|
|
21
|
+
*/
|
|
22
|
+
export declare const InitialStateExtension: import("@ekz/lexical").LexicalExtension<InitialStateConfig, "@ekz/lexical-extension/InitialState", unknown, {
|
|
23
|
+
$initialEditorState: import("@ekz/lexical").InitialEditorStateType;
|
|
24
|
+
initialized: boolean;
|
|
25
|
+
}>;
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { type AnyLexicalExtension, type AnyLexicalExtensionArgument, type AnyNormalizedLexicalExtensionArgument, type CreateEditorArgs, type InitialEditorConfig, type LexicalEditor, type LexicalEditorWithDispose, type LexicalExtensionConfig } from '@ekz/lexical';
|
|
9
|
+
import { ExtensionRep } from './ExtensionRep';
|
|
10
|
+
/** @internal Use a well-known symbol for dev tools purposes */
|
|
11
|
+
export declare const builderSymbol: unique symbol;
|
|
12
|
+
type BuildCreateEditorArgs = Omit<CreateEditorArgs, 'onError'> & Pick<InitialEditorConfig, 'onError' | '$initialEditorState'>;
|
|
13
|
+
/**
|
|
14
|
+
* Build a LexicalEditor by combining together one or more extensions, optionally
|
|
15
|
+
* overriding some of their configuration.
|
|
16
|
+
*
|
|
17
|
+
* @param extensions - Extension arguments (extensions or extensions with config overrides)
|
|
18
|
+
* @returns An editor handle
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* A single root extension with multiple dependencies
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const editor = buildEditorFromExtensions(
|
|
25
|
+
* defineExtension({
|
|
26
|
+
* name: "[root]",
|
|
27
|
+
* dependencies: [
|
|
28
|
+
* RichTextExtension,
|
|
29
|
+
* configExtension(EmojiExtension, { emojiBaseUrl: "/assets/emoji" }),
|
|
30
|
+
* ],
|
|
31
|
+
* register: (editor: LexicalEditor) => {
|
|
32
|
+
* console.log("Editor Created");
|
|
33
|
+
* return () => console.log("Editor Disposed");
|
|
34
|
+
* },
|
|
35
|
+
* }),
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* A very similar minimal configuration without the register hook
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const editor = buildEditorFromExtensions(
|
|
44
|
+
* RichTextExtension,
|
|
45
|
+
* configExtension(EmojiExtension, { emojiBaseUrl: "/assets/emoji" }),
|
|
46
|
+
* );
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildEditorFromExtensions(...extensions: AnyLexicalExtensionArgument[]): LexicalEditorWithDispose;
|
|
50
|
+
interface WithBuilder {
|
|
51
|
+
[builderSymbol]?: LexicalBuilder | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
export declare class LexicalBuilder {
|
|
55
|
+
roots: readonly AnyNormalizedLexicalExtensionArgument[];
|
|
56
|
+
extensionNameMap: Map<string, ExtensionRep<AnyLexicalExtension>>;
|
|
57
|
+
outgoingConfigEdges: Map<string, Map<string, LexicalExtensionConfig<AnyLexicalExtension>[]>>;
|
|
58
|
+
incomingEdges: Map<string, Set<string>>;
|
|
59
|
+
conflicts: Map<string, string>;
|
|
60
|
+
_sortedExtensionReps?: readonly ExtensionRep<AnyLexicalExtension>[];
|
|
61
|
+
PACKAGE_VERSION: string;
|
|
62
|
+
constructor(roots: AnyNormalizedLexicalExtensionArgument[]);
|
|
63
|
+
static fromExtensions(extensions: AnyLexicalExtensionArgument[]): LexicalBuilder;
|
|
64
|
+
static maybeFromEditor(editor: LexicalEditor): undefined | LexicalBuilder;
|
|
65
|
+
/** Look up the editor that was created by this LexicalBuilder or throw */
|
|
66
|
+
static fromEditor(editor: LexicalEditor): LexicalBuilder;
|
|
67
|
+
constructEditor(): LexicalEditor & WithBuilder;
|
|
68
|
+
buildEditor(): LexicalEditorWithDispose;
|
|
69
|
+
hasExtensionByName(name: string): boolean;
|
|
70
|
+
getExtensionRep<Extension extends AnyLexicalExtension>(extension: Extension): ExtensionRep<Extension> | undefined;
|
|
71
|
+
addEdge(fromExtensionName: string, toExtensionName: string, configs: LexicalExtensionConfig<AnyLexicalExtension>[]): void;
|
|
72
|
+
addExtension(arg: AnyLexicalExtensionArgument): void;
|
|
73
|
+
sortedExtensionReps(): readonly ExtensionRep<AnyLexicalExtension>[];
|
|
74
|
+
registerEditor(editor: LexicalEditor): () => void;
|
|
75
|
+
buildCreateEditorArgs(): BuildCreateEditorArgs;
|
|
76
|
+
}
|
|
77
|
+
export {};
|