@lexical/extension 0.45.1-dev.0 → 0.45.1-nightly.20260531.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/IMEExtension.d.ts +38 -0
- package/dist/LexicalExtension.dev.js +130 -4
- package/dist/LexicalExtension.dev.mjs +132 -7
- package/dist/LexicalExtension.js.flow +6 -0
- package/dist/LexicalExtension.mjs +1 -0
- package/dist/LexicalExtension.node.mjs +1 -0
- package/dist/LexicalExtension.prod.js +1 -1
- package/dist/LexicalExtension.prod.mjs +1 -1
- package/dist/deepThemeMergeInPlace.d.ts +0 -16
- package/dist/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/IMEExtension.ts +142 -0
- package/src/deepThemeMergeInPlace.ts +13 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
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 NodeKey, type TextNode } from 'lexical';
|
|
9
|
+
import { type Signal } from './signals';
|
|
10
|
+
/**
|
|
11
|
+
* Centralizes IME composition state so extensions that react to
|
|
12
|
+
* composition lifecycle don't each re-implement the
|
|
13
|
+
* COMPOSITION_START_COMMAND + compositionend listener dance.
|
|
14
|
+
*
|
|
15
|
+
* Exposes two signals (both always-active for the editor's lifetime —
|
|
16
|
+
* listeners are wired up by `register`, not lazily on subscription, so
|
|
17
|
+
* consumers can read `.value` from anywhere without holding a
|
|
18
|
+
* subscription themselves):
|
|
19
|
+
*
|
|
20
|
+
* - `compositionKey` is the raw mirror — the value Lexical's own
|
|
21
|
+
* `$handleCompositionStart` writes to its internal `_compositionKey`,
|
|
22
|
+
* i.e. the `selection.anchor.key` at the moment composition starts.
|
|
23
|
+
* This can be a non-TextNode key when composition begins on an
|
|
24
|
+
* element-anchor selection (e.g. empty paragraph). Cleared on
|
|
25
|
+
* `compositionend`.
|
|
26
|
+
*
|
|
27
|
+
* - `composingTextNode` is the resolved view — the actual TextNode
|
|
28
|
+
* being composed on, or `null` while there is no TextNode-level
|
|
29
|
+
* composition. For an element-anchor start it stays `null` until
|
|
30
|
+
* the `COMPOSITION_START_TAG`-tagged update fires with the
|
|
31
|
+
* post-ZWSP-heuristic selection, at which point it updates to the
|
|
32
|
+
* new TextNode.
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export declare const IMEExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/extension/IME", {
|
|
36
|
+
compositionKey: Signal<null | NodeKey>;
|
|
37
|
+
composingTextNode: Signal<null | TextNode>;
|
|
38
|
+
}, unknown>;
|
|
@@ -569,9 +569,9 @@ function formatDevErrorMessage(message) {
|
|
|
569
569
|
*
|
|
570
570
|
*/
|
|
571
571
|
|
|
572
|
-
// `"0.45.1-
|
|
572
|
+
// `"0.45.1-nightly.20260531.0+dev.cjs"` is statically replaced with the build-specific
|
|
573
573
|
// version string in a Rollup build, and a consumer's bundler `define` can
|
|
574
|
-
// inject it the same way — so the exact `"0.45.1-
|
|
574
|
+
// inject it the same way — so the exact `"0.45.1-nightly.20260531.0+dev.cjs"` member
|
|
575
575
|
// expression must be preserved for that substitution to match. Reading it
|
|
576
576
|
// inside a try/catch lets the source be consumed directly (via the `source`
|
|
577
577
|
// export condition) in a browser bundle, where `process` is undefined and
|
|
@@ -580,11 +580,11 @@ function formatDevErrorMessage(message) {
|
|
|
580
580
|
// `pnpm run update-version`.
|
|
581
581
|
let envLexicalVersion;
|
|
582
582
|
try {
|
|
583
|
-
envLexicalVersion = "0.45.1-
|
|
583
|
+
envLexicalVersion = "0.45.1-nightly.20260531.0+dev.cjs";
|
|
584
584
|
} catch (_unused) {
|
|
585
585
|
// `process` is not defined in some browser bundles; use the fallback.
|
|
586
586
|
}
|
|
587
|
-
const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-
|
|
587
|
+
const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-nightly.20260531.0+source';
|
|
588
588
|
|
|
589
589
|
/**
|
|
590
590
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -610,11 +610,20 @@ const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-dev.0+source';
|
|
|
610
610
|
* expect(a).toEqual({ a: "a", b: "b", nested: { a: 1, b: 2 } });
|
|
611
611
|
* ```
|
|
612
612
|
*/
|
|
613
|
+
// Keys that must never be merged: assigning or recursing through them can
|
|
614
|
+
// mutate the prototype chain (prototype pollution). A malicious `__proto__`
|
|
615
|
+
// entry — e.g. from `JSON.parse('{"__proto__": {...}}')` — would otherwise
|
|
616
|
+
// leak into `Object.prototype` and affect every object in the realm.
|
|
617
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
613
618
|
function deepThemeMergeInPlace(a, b) {
|
|
614
619
|
if (a && b && !Array.isArray(b) && typeof a === 'object' && typeof b === 'object') {
|
|
615
620
|
const aObj = a;
|
|
616
621
|
const bObj = b;
|
|
617
622
|
for (const k in bObj) {
|
|
623
|
+
// Only merge own, prototype-safe keys.
|
|
624
|
+
if (UNSAFE_KEYS.has(k) || !Object.prototype.hasOwnProperty.call(bObj, k)) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
618
627
|
aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);
|
|
619
628
|
}
|
|
620
629
|
return a;
|
|
@@ -1783,6 +1792,122 @@ const HorizontalRuleExtension = lexical.defineExtension({
|
|
|
1783
1792
|
}
|
|
1784
1793
|
});
|
|
1785
1794
|
|
|
1795
|
+
/**
|
|
1796
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1797
|
+
*
|
|
1798
|
+
* This source code is licensed under the MIT license found in the
|
|
1799
|
+
* LICENSE file in the root directory of this source tree.
|
|
1800
|
+
*
|
|
1801
|
+
*/
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* Centralizes IME composition state so extensions that react to
|
|
1806
|
+
* composition lifecycle don't each re-implement the
|
|
1807
|
+
* COMPOSITION_START_COMMAND + compositionend listener dance.
|
|
1808
|
+
*
|
|
1809
|
+
* Exposes two signals (both always-active for the editor's lifetime —
|
|
1810
|
+
* listeners are wired up by `register`, not lazily on subscription, so
|
|
1811
|
+
* consumers can read `.value` from anywhere without holding a
|
|
1812
|
+
* subscription themselves):
|
|
1813
|
+
*
|
|
1814
|
+
* - `compositionKey` is the raw mirror — the value Lexical's own
|
|
1815
|
+
* `$handleCompositionStart` writes to its internal `_compositionKey`,
|
|
1816
|
+
* i.e. the `selection.anchor.key` at the moment composition starts.
|
|
1817
|
+
* This can be a non-TextNode key when composition begins on an
|
|
1818
|
+
* element-anchor selection (e.g. empty paragraph). Cleared on
|
|
1819
|
+
* `compositionend`.
|
|
1820
|
+
*
|
|
1821
|
+
* - `composingTextNode` is the resolved view — the actual TextNode
|
|
1822
|
+
* being composed on, or `null` while there is no TextNode-level
|
|
1823
|
+
* composition. For an element-anchor start it stays `null` until
|
|
1824
|
+
* the `COMPOSITION_START_TAG`-tagged update fires with the
|
|
1825
|
+
* post-ZWSP-heuristic selection, at which point it updates to the
|
|
1826
|
+
* new TextNode.
|
|
1827
|
+
*
|
|
1828
|
+
*/
|
|
1829
|
+
const IMEExtension = lexical.defineExtension({
|
|
1830
|
+
build(_editor) {
|
|
1831
|
+
return {
|
|
1832
|
+
composingTextNode: a(null),
|
|
1833
|
+
compositionKey: a(null)
|
|
1834
|
+
};
|
|
1835
|
+
},
|
|
1836
|
+
name: '@lexical/extension/IME',
|
|
1837
|
+
register(editor, _config, state) {
|
|
1838
|
+
const {
|
|
1839
|
+
compositionKey,
|
|
1840
|
+
composingTextNode
|
|
1841
|
+
} = state.getOutput();
|
|
1842
|
+
const removeStartCommand = editor.registerCommand(lexical.COMPOSITION_START_COMMAND, () => {
|
|
1843
|
+
// `BEFORE_EDITOR` lands at the head of the EDITOR-priority
|
|
1844
|
+
// bucket, sequenced immediately before Lexical's own
|
|
1845
|
+
// EDITOR-priority `$handleCompositionStart` that calls
|
|
1846
|
+
// `$setCompositionKey(anchor.key)`. Both write the same
|
|
1847
|
+
// `selection.anchor.key`. The lower nominal priority keeps
|
|
1848
|
+
// room for downstream extensions to override.
|
|
1849
|
+
const selection = lexical.$getSelection();
|
|
1850
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
1851
|
+
compositionKey.value = selection.anchor.key;
|
|
1852
|
+
}
|
|
1853
|
+
return false;
|
|
1854
|
+
}, lexical.COMMAND_PRIORITY_BEFORE_EDITOR);
|
|
1855
|
+
|
|
1856
|
+
// Stage 1: react to compositionKey transitions. Resolve the key
|
|
1857
|
+
// to a TextNode when possible. Element-anchor starts resolve to
|
|
1858
|
+
// null here and stay null until stage 2.
|
|
1859
|
+
const stopKeyEffect = j(() => {
|
|
1860
|
+
const key = compositionKey.value;
|
|
1861
|
+
if (key === null) {
|
|
1862
|
+
composingTextNode.value = null;
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
composingTextNode.value = editor.getEditorState().read(() => {
|
|
1866
|
+
const node = lexical.$getNodeByKey(key);
|
|
1867
|
+
return lexical.$isTextNode(node) ? node : null;
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
// Stage 2: after Lexical's ZWSP heuristic inserts the actual
|
|
1872
|
+
// composing TextNode for an element-anchor start, the
|
|
1873
|
+
// corresponding update fires with COMPOSITION_START_TAG. The
|
|
1874
|
+
// selection now points at the new TextNode — re-read it and
|
|
1875
|
+
// upgrade the signal to the resolved node.
|
|
1876
|
+
const removeUpdateListener = editor.registerUpdateListener(({
|
|
1877
|
+
tags,
|
|
1878
|
+
editorState
|
|
1879
|
+
}) => {
|
|
1880
|
+
if (!tags.has(lexical.COMPOSITION_START_TAG)) {
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
editorState.read(() => {
|
|
1884
|
+
const selection = lexical.$getSelection();
|
|
1885
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
const node = selection.anchor.getNode();
|
|
1889
|
+
if (lexical.$isTextNode(node)) {
|
|
1890
|
+
composingTextNode.value = node;
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
});
|
|
1894
|
+
const removeRootListener = editor.registerRootListener(rootElem => {
|
|
1895
|
+
if (rootElem === null) {
|
|
1896
|
+
compositionKey.value = null;
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1899
|
+
const onCompositionEnd = () => {
|
|
1900
|
+
compositionKey.value = null;
|
|
1901
|
+
};
|
|
1902
|
+
rootElem.addEventListener('compositionend', onCompositionEnd);
|
|
1903
|
+
return () => {
|
|
1904
|
+
rootElem.removeEventListener('compositionend', onCompositionEnd);
|
|
1905
|
+
};
|
|
1906
|
+
});
|
|
1907
|
+
return utils.mergeRegister(removeStartCommand, stopKeyEffect, removeUpdateListener, removeRootListener);
|
|
1908
|
+
}
|
|
1909
|
+
});
|
|
1910
|
+
|
|
1786
1911
|
/**
|
|
1787
1912
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1788
1913
|
*
|
|
@@ -2144,6 +2269,7 @@ exports.DecoratorTextNode = DecoratorTextNode;
|
|
|
2144
2269
|
exports.EditorStateExtension = EditorStateExtension;
|
|
2145
2270
|
exports.HorizontalRuleExtension = HorizontalRuleExtension;
|
|
2146
2271
|
exports.HorizontalRuleNode = HorizontalRuleNode;
|
|
2272
|
+
exports.IMEExtension = IMEExtension;
|
|
2147
2273
|
exports.INSERT_HORIZONTAL_RULE_COMMAND = INSERT_HORIZONTAL_RULE_COMMAND;
|
|
2148
2274
|
exports.InitialStateExtension = InitialStateExtension;
|
|
2149
2275
|
exports.LexicalBuilder = LexicalBuilder;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { defineExtension, safeCast, CLEAR_EDITOR_COMMAND, COMMAND_PRIORITY_EDITOR, $getRoot, $getSelection, $createParagraphNode, $isRangeSelection, $isDecoratorNode, $isElementNode, stopLexicalPropagation, getStaticNodeConfig, FORMAT_TEXT_COMMAND, $isNodeSelection, COMMAND_PRIORITY_LOW, DecoratorNode, $getState, toggleTextFormatType, $setState, TEXT_TYPE_TO_FORMAT, createState, shallowMergeConfig, RootNode, TextNode, LineBreakNode, TabNode, ParagraphNode, $isEditorState, HISTORY_MERGE_TAG, createEditor, mergeRegister, $getEditor, $getNodeByKey, $create, CLICK_COMMAND, isDOMNode, $getNodeFromDOMNode, addClassNamesToElement, createCommand, $createNodeSelection, $setSelection, removeClassNamesFromElement, ElementNode, $getCaretRangeInDirection, $caretRangeFromSelection, $isTextPointCaret, $rewindSiblingCaret, $isSiblingCaret, $isLineBreakNode, $isChildCaret, $getSiblingCaret, $normalizeCaret, $getChildCaret, $setSelectionFromCaretRange, $getCaretRange, getDOMSelection, $updateDOMSelection, $getPreviousSelection, SKIP_SELECTION_FOCUS_TAG, SKIP_SCROLL_INTO_VIEW_TAG, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_BEFORE_CRITICAL, KEY_TAB_COMMAND, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, $isBlockElementNode, $createRangeSelection, $normalizeSelection__EXPERIMENTAL } from 'lexical';
|
|
9
|
+
import { defineExtension, safeCast, CLEAR_EDITOR_COMMAND, COMMAND_PRIORITY_EDITOR, $getRoot, $getSelection, $createParagraphNode, $isRangeSelection, $isDecoratorNode, $isElementNode, stopLexicalPropagation, getStaticNodeConfig, FORMAT_TEXT_COMMAND, $isNodeSelection, COMMAND_PRIORITY_LOW, DecoratorNode, $getState, toggleTextFormatType, $setState, TEXT_TYPE_TO_FORMAT, createState, shallowMergeConfig, RootNode, TextNode, LineBreakNode, TabNode, ParagraphNode, $isEditorState, HISTORY_MERGE_TAG, createEditor, mergeRegister, $getEditor, $getNodeByKey, $create, CLICK_COMMAND, isDOMNode, $getNodeFromDOMNode, addClassNamesToElement, createCommand, $createNodeSelection, $setSelection, removeClassNamesFromElement, COMPOSITION_START_COMMAND, COMMAND_PRIORITY_BEFORE_EDITOR, COMPOSITION_START_TAG, $isTextNode, ElementNode, $getCaretRangeInDirection, $caretRangeFromSelection, $isTextPointCaret, $rewindSiblingCaret, $isSiblingCaret, $isLineBreakNode, $isChildCaret, $getSiblingCaret, $normalizeCaret, $getChildCaret, $setSelectionFromCaretRange, $getCaretRange, getDOMSelection, $updateDOMSelection, $getPreviousSelection, SKIP_SELECTION_FOCUS_TAG, SKIP_SCROLL_INTO_VIEW_TAG, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_BEFORE_CRITICAL, KEY_TAB_COMMAND, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, $isBlockElementNode, $createRangeSelection, $normalizeSelection__EXPERIMENTAL } from 'lexical';
|
|
10
10
|
export { configExtension, declarePeerDependency, defineExtension, safeCast, shallowMergeConfig } from 'lexical';
|
|
11
|
-
import { $insertNodeToNearestRoot, selectionAlwaysOnDisplay, $handleIndentAndOutdent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
11
|
+
import { $insertNodeToNearestRoot, mergeRegister as mergeRegister$1, selectionAlwaysOnDisplay, $handleIndentAndOutdent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
12
12
|
|
|
13
13
|
const i=Symbol.for("preact-signals");function t(){if(e>1){e--;return}let i,t=false;!function(){let i=r;r=void 0;while(void 0!==i){if(i.S.v===i.v)i.S.i=i.i;i=i.o;}}();while(void 0!==s){let n=s;s=void 0;u++;while(void 0!==n){const o=n.u;n.u=void 0;n.f&=-3;if(!(8&n.f)&&w(n))try{n.c();}catch(n){if(!t){i=n;t=true;}}n=o;}}u=0;e--;if(t)throw i}function n(i){if(e>0)return i();d=++c;e++;try{return i()}finally{t();}}let o,s;function h(i){const t=o;o=void 0;try{return i()}finally{o=t;}}let r,e=0,u=0,c=0,d=0,v=0;function l(i){if(void 0===o)return;let t=i.n;if(void 0===t||t.t!==o){t={i:0,S:i,p:o.s,n:void 0,t:o,e:void 0,x:void 0,r:t};if(void 0!==o.s)o.s.n=t;o.s=t;i.n=t;if(32&o.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=o.s;t.n=void 0;o.s.n=t;o.s=t;}return t}}function y(i,t){this.v=i;this.i=0;this.n=void 0;this.t=void 0;this.l=0;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name;}y.prototype.brand=i;y.prototype.h=function(){return true};y.prototype.S=function(i){const t=this.t;if(t!==i&&void 0===i.e){i.x=t;this.t=i;if(void 0!==t)t.e=i;else h(()=>{var i;null==(i=this.W)||i.call(this);});}};y.prototype.U=function(i){if(void 0!==this.t){const t=i.e,n=i.x;if(void 0!==t){t.x=n;i.e=void 0;}if(void 0!==n){n.e=t;i.x=void 0;}if(i===this.t){this.t=n;if(void 0===n)h(()=>{var i;null==(i=this.Z)||i.call(this);});}}};y.prototype.subscribe=function(i){return j(()=>{const t=this.value,n=o;o=void 0;try{i(t);}finally{o=n;}},{name:"sub"})};y.prototype.valueOf=function(){return this.value};y.prototype.toString=function(){return this.value+""};y.prototype.toJSON=function(){return this.value};y.prototype.peek=function(){const i=o;o=void 0;try{return this.value}finally{o=i;}};Object.defineProperty(y.prototype,"value",{get(){const i=l(this);if(void 0!==i)i.i=this.i;return this.v},set(i){if(i!==this.v){if(u>100)throw new Error("Cycle detected");!function(i){if(0!==e&&0===u)if(i.l!==d){i.l=d;r={S:i,v:i.v,i:i.i,o:r};}}(this);this.v=i;this.i++;v++;e++;try{for(let i=this.t;void 0!==i;i=i.x)i.t.N();}finally{t();}}}});function a(i,t){return new y(i,t)}function w(i){for(let t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return true;return false}function _(i){for(let t=i.s;void 0!==t;t=t.n){const n=t.S.n;if(void 0!==n)t.r=n;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function b(i){let t,n=i.s;while(void 0!==n){const i=n.p;if(-1===n.i){n.S.U(n);if(void 0!==i)i.n=n.n;if(void 0!==n.n)n.n.p=i;}else t=n;n.S.n=n.r;if(void 0!==n.r)n.r=void 0;n=i;}i.s=t;}function p(i,t){y.call(this,void 0);this.x=i;this.s=void 0;this.g=v-1;this.f=4;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name;}p.prototype=new y;p.prototype.h=function(){this.f&=-3;if(1&this.f)return false;if(32==(36&this.f))return true;this.f&=-5;if(this.g===v)return true;this.g=v;this.f|=1;if(this.i>0&&!w(this)){this.f&=-2;return true}const i=o;try{_(this);o=this;const i=this.x();if(16&this.f||this.v!==i||0===this.i){this.v=i;this.f&=-17;this.i++;}}catch(i){this.v=i;this.f|=16;this.i++;}o=i;b(this);this.f&=-2;return true};p.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(let i=this.s;void 0!==i;i=i.n)i.S.S(i);}y.prototype.S.call(this,i);};p.prototype.U=function(i){if(void 0!==this.t){y.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(let i=this.s;void 0!==i;i=i.n)i.S.U(i);}}};p.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let i=this.t;void 0!==i;i=i.x)i.t.N();}};Object.defineProperty(p.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const i=l(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function g(i,t){return new p(i,t)}function S(i){const n=i.m;i.m=void 0;if("function"==typeof n){e++;const s=o;o=void 0;try{n();}catch(t){i.f&=-2;i.f|=8;m(i);throw t}finally{o=s;t();}}}function m(i){for(let t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;S(i);}function x(i){if(o!==this)throw new Error("Out-of-order effect");b(this);o=i;this.f&=-2;if(8&this.f)m(this);t();}function E(i,t){this.x=i;this.m=void 0;this.s=void 0;this.u=void 0;this.f=32;this.name=null==t?void 0:t.name;}E.prototype.c=function(){const i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;const t=this.x();if("function"==typeof t)this.m=t;}finally{i();}};E.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;S(this);_(this);e++;const i=o;o=this;return x.bind(this,i)};E.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.u=s;s=this;}};E.prototype.d=function(){this.f|=8;if(!(1&this.f))m(this);};E.prototype.dispose=function(){this.d();};function j(i,t){const n=new E(i,t);try{n.c();}catch(i){n.d();throw i}const o=n.d.bind(n);o[Symbol.dispose]=o;return o}
|
|
14
14
|
|
|
@@ -568,9 +568,9 @@ function formatDevErrorMessage(message) {
|
|
|
568
568
|
*
|
|
569
569
|
*/
|
|
570
570
|
|
|
571
|
-
// `"0.45.1-
|
|
571
|
+
// `"0.45.1-nightly.20260531.0+dev.esm"` is statically replaced with the build-specific
|
|
572
572
|
// version string in a Rollup build, and a consumer's bundler `define` can
|
|
573
|
-
// inject it the same way — so the exact `"0.45.1-
|
|
573
|
+
// inject it the same way — so the exact `"0.45.1-nightly.20260531.0+dev.esm"` member
|
|
574
574
|
// expression must be preserved for that substitution to match. Reading it
|
|
575
575
|
// inside a try/catch lets the source be consumed directly (via the `source`
|
|
576
576
|
// export condition) in a browser bundle, where `process` is undefined and
|
|
@@ -579,11 +579,11 @@ function formatDevErrorMessage(message) {
|
|
|
579
579
|
// `pnpm run update-version`.
|
|
580
580
|
let envLexicalVersion;
|
|
581
581
|
try {
|
|
582
|
-
envLexicalVersion = "0.45.1-
|
|
582
|
+
envLexicalVersion = "0.45.1-nightly.20260531.0+dev.esm";
|
|
583
583
|
} catch (_unused) {
|
|
584
584
|
// `process` is not defined in some browser bundles; use the fallback.
|
|
585
585
|
}
|
|
586
|
-
const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-
|
|
586
|
+
const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-nightly.20260531.0+source';
|
|
587
587
|
|
|
588
588
|
/**
|
|
589
589
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -609,11 +609,20 @@ const LEXICAL_VERSION = envLexicalVersion ?? '0.45.1-dev.0+source';
|
|
|
609
609
|
* expect(a).toEqual({ a: "a", b: "b", nested: { a: 1, b: 2 } });
|
|
610
610
|
* ```
|
|
611
611
|
*/
|
|
612
|
+
// Keys that must never be merged: assigning or recursing through them can
|
|
613
|
+
// mutate the prototype chain (prototype pollution). A malicious `__proto__`
|
|
614
|
+
// entry — e.g. from `JSON.parse('{"__proto__": {...}}')` — would otherwise
|
|
615
|
+
// leak into `Object.prototype` and affect every object in the realm.
|
|
616
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
612
617
|
function deepThemeMergeInPlace(a, b) {
|
|
613
618
|
if (a && b && !Array.isArray(b) && typeof a === 'object' && typeof b === 'object') {
|
|
614
619
|
const aObj = a;
|
|
615
620
|
const bObj = b;
|
|
616
621
|
for (const k in bObj) {
|
|
622
|
+
// Only merge own, prototype-safe keys.
|
|
623
|
+
if (UNSAFE_KEYS.has(k) || !Object.prototype.hasOwnProperty.call(bObj, k)) {
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
617
626
|
aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);
|
|
618
627
|
}
|
|
619
628
|
return a;
|
|
@@ -1782,6 +1791,122 @@ const HorizontalRuleExtension = defineExtension({
|
|
|
1782
1791
|
}
|
|
1783
1792
|
});
|
|
1784
1793
|
|
|
1794
|
+
/**
|
|
1795
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1796
|
+
*
|
|
1797
|
+
* This source code is licensed under the MIT license found in the
|
|
1798
|
+
* LICENSE file in the root directory of this source tree.
|
|
1799
|
+
*
|
|
1800
|
+
*/
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
/**
|
|
1804
|
+
* Centralizes IME composition state so extensions that react to
|
|
1805
|
+
* composition lifecycle don't each re-implement the
|
|
1806
|
+
* COMPOSITION_START_COMMAND + compositionend listener dance.
|
|
1807
|
+
*
|
|
1808
|
+
* Exposes two signals (both always-active for the editor's lifetime —
|
|
1809
|
+
* listeners are wired up by `register`, not lazily on subscription, so
|
|
1810
|
+
* consumers can read `.value` from anywhere without holding a
|
|
1811
|
+
* subscription themselves):
|
|
1812
|
+
*
|
|
1813
|
+
* - `compositionKey` is the raw mirror — the value Lexical's own
|
|
1814
|
+
* `$handleCompositionStart` writes to its internal `_compositionKey`,
|
|
1815
|
+
* i.e. the `selection.anchor.key` at the moment composition starts.
|
|
1816
|
+
* This can be a non-TextNode key when composition begins on an
|
|
1817
|
+
* element-anchor selection (e.g. empty paragraph). Cleared on
|
|
1818
|
+
* `compositionend`.
|
|
1819
|
+
*
|
|
1820
|
+
* - `composingTextNode` is the resolved view — the actual TextNode
|
|
1821
|
+
* being composed on, or `null` while there is no TextNode-level
|
|
1822
|
+
* composition. For an element-anchor start it stays `null` until
|
|
1823
|
+
* the `COMPOSITION_START_TAG`-tagged update fires with the
|
|
1824
|
+
* post-ZWSP-heuristic selection, at which point it updates to the
|
|
1825
|
+
* new TextNode.
|
|
1826
|
+
*
|
|
1827
|
+
*/
|
|
1828
|
+
const IMEExtension = defineExtension({
|
|
1829
|
+
build(_editor) {
|
|
1830
|
+
return {
|
|
1831
|
+
composingTextNode: a(null),
|
|
1832
|
+
compositionKey: a(null)
|
|
1833
|
+
};
|
|
1834
|
+
},
|
|
1835
|
+
name: '@lexical/extension/IME',
|
|
1836
|
+
register(editor, _config, state) {
|
|
1837
|
+
const {
|
|
1838
|
+
compositionKey,
|
|
1839
|
+
composingTextNode
|
|
1840
|
+
} = state.getOutput();
|
|
1841
|
+
const removeStartCommand = editor.registerCommand(COMPOSITION_START_COMMAND, () => {
|
|
1842
|
+
// `BEFORE_EDITOR` lands at the head of the EDITOR-priority
|
|
1843
|
+
// bucket, sequenced immediately before Lexical's own
|
|
1844
|
+
// EDITOR-priority `$handleCompositionStart` that calls
|
|
1845
|
+
// `$setCompositionKey(anchor.key)`. Both write the same
|
|
1846
|
+
// `selection.anchor.key`. The lower nominal priority keeps
|
|
1847
|
+
// room for downstream extensions to override.
|
|
1848
|
+
const selection = $getSelection();
|
|
1849
|
+
if ($isRangeSelection(selection)) {
|
|
1850
|
+
compositionKey.value = selection.anchor.key;
|
|
1851
|
+
}
|
|
1852
|
+
return false;
|
|
1853
|
+
}, COMMAND_PRIORITY_BEFORE_EDITOR);
|
|
1854
|
+
|
|
1855
|
+
// Stage 1: react to compositionKey transitions. Resolve the key
|
|
1856
|
+
// to a TextNode when possible. Element-anchor starts resolve to
|
|
1857
|
+
// null here and stay null until stage 2.
|
|
1858
|
+
const stopKeyEffect = j(() => {
|
|
1859
|
+
const key = compositionKey.value;
|
|
1860
|
+
if (key === null) {
|
|
1861
|
+
composingTextNode.value = null;
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
composingTextNode.value = editor.getEditorState().read(() => {
|
|
1865
|
+
const node = $getNodeByKey(key);
|
|
1866
|
+
return $isTextNode(node) ? node : null;
|
|
1867
|
+
});
|
|
1868
|
+
});
|
|
1869
|
+
|
|
1870
|
+
// Stage 2: after Lexical's ZWSP heuristic inserts the actual
|
|
1871
|
+
// composing TextNode for an element-anchor start, the
|
|
1872
|
+
// corresponding update fires with COMPOSITION_START_TAG. The
|
|
1873
|
+
// selection now points at the new TextNode — re-read it and
|
|
1874
|
+
// upgrade the signal to the resolved node.
|
|
1875
|
+
const removeUpdateListener = editor.registerUpdateListener(({
|
|
1876
|
+
tags,
|
|
1877
|
+
editorState
|
|
1878
|
+
}) => {
|
|
1879
|
+
if (!tags.has(COMPOSITION_START_TAG)) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
editorState.read(() => {
|
|
1883
|
+
const selection = $getSelection();
|
|
1884
|
+
if (!$isRangeSelection(selection)) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const node = selection.anchor.getNode();
|
|
1888
|
+
if ($isTextNode(node)) {
|
|
1889
|
+
composingTextNode.value = node;
|
|
1890
|
+
}
|
|
1891
|
+
});
|
|
1892
|
+
});
|
|
1893
|
+
const removeRootListener = editor.registerRootListener(rootElem => {
|
|
1894
|
+
if (rootElem === null) {
|
|
1895
|
+
compositionKey.value = null;
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
const onCompositionEnd = () => {
|
|
1899
|
+
compositionKey.value = null;
|
|
1900
|
+
};
|
|
1901
|
+
rootElem.addEventListener('compositionend', onCompositionEnd);
|
|
1902
|
+
return () => {
|
|
1903
|
+
rootElem.removeEventListener('compositionend', onCompositionEnd);
|
|
1904
|
+
};
|
|
1905
|
+
});
|
|
1906
|
+
return mergeRegister$1(removeStartCommand, stopKeyEffect, removeUpdateListener, removeRootListener);
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1785
1910
|
/**
|
|
1786
1911
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1787
1912
|
*
|
|
@@ -2123,4 +2248,4 @@ const WatchEditableExtension = defineExtension({
|
|
|
2123
2248
|
name: '@lexical/extension/WatchEditable'
|
|
2124
2249
|
});
|
|
2125
2250
|
|
|
2126
|
-
export { $createHorizontalRuleNode, $defaultShouldInsertAfter, $getExtensionDependency, $getExtensionOutput, $getPeerDependency, $isDecoratorTextNode, $isHorizontalRuleNode, AutoFocusExtension, ClearEditorExtension, ClickAfterLastBlockExtension, DecoratorTextExtension, DecoratorTextNode, EditorStateExtension, HorizontalRuleExtension, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND, InitialStateExtension, LexicalBuilder, NestedEditorExtension, NodeSelectionExtension, NormalizeInlineElementsExtension, NormalizeTripleClickSelectionExtension, SelectionAlwaysOnDisplayExtension, TabIndentationExtension, WatchEditableExtension, applyFormatFromStyle, applyFormatToDom, n as batch, buildEditorFromExtensions, g as computed, j as effect, getExtensionDependencyFromEditor, getKnownTypesAndNodes, getPeerDependencyFromEditor, getPeerDependencyFromEditorOrThrow, namedSignals, registerClearEditor, registerTabIndentation, a as signal, h as untracked, watchedSignal };
|
|
2251
|
+
export { $createHorizontalRuleNode, $defaultShouldInsertAfter, $getExtensionDependency, $getExtensionOutput, $getPeerDependency, $isDecoratorTextNode, $isHorizontalRuleNode, AutoFocusExtension, ClearEditorExtension, ClickAfterLastBlockExtension, DecoratorTextExtension, DecoratorTextNode, EditorStateExtension, HorizontalRuleExtension, HorizontalRuleNode, IMEExtension, INSERT_HORIZONTAL_RULE_COMMAND, InitialStateExtension, LexicalBuilder, NestedEditorExtension, NodeSelectionExtension, NormalizeInlineElementsExtension, NormalizeTripleClickSelectionExtension, SelectionAlwaysOnDisplayExtension, TabIndentationExtension, WatchEditableExtension, applyFormatFromStyle, applyFormatToDom, n as batch, buildEditorFromExtensions, g as computed, j as effect, getExtensionDependencyFromEditor, getKnownTypesAndNodes, getPeerDependencyFromEditor, getPeerDependencyFromEditorOrThrow, namedSignals, registerClearEditor, registerTabIndentation, a as signal, h as untracked, watchedSignal };
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type {
|
|
14
14
|
LexicalNode,
|
|
15
15
|
NodeKey,
|
|
16
|
+
TextNode,
|
|
16
17
|
ExtensionConfigBase,
|
|
17
18
|
EditorState,
|
|
18
19
|
AnyLexicalExtension,
|
|
@@ -153,6 +154,11 @@ declare export function $isHorizontalRuleNode(
|
|
|
153
154
|
declare export var INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
|
|
154
155
|
declare export var HorizontalRuleExtension: LexicalExtension<ExtensionConfigBase, "@lexical/extension/HorizontalRule", void, void>;
|
|
155
156
|
|
|
157
|
+
declare export var IMEExtension: LexicalExtension<ExtensionConfigBase, "@lexical/extension/IME", {
|
|
158
|
+
compositionKey: Signal<null | NodeKey>;
|
|
159
|
+
composingTextNode: Signal<null | TextNode>;
|
|
160
|
+
}, void>;
|
|
161
|
+
|
|
156
162
|
export type InitialStateConfig = {
|
|
157
163
|
updateOptions: EditorUpdateOptions;
|
|
158
164
|
setOptions: EditorSetOptions;
|
|
@@ -24,6 +24,7 @@ export const DecoratorTextNode = mod.DecoratorTextNode;
|
|
|
24
24
|
export const EditorStateExtension = mod.EditorStateExtension;
|
|
25
25
|
export const HorizontalRuleExtension = mod.HorizontalRuleExtension;
|
|
26
26
|
export const HorizontalRuleNode = mod.HorizontalRuleNode;
|
|
27
|
+
export const IMEExtension = mod.IMEExtension;
|
|
27
28
|
export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
|
|
28
29
|
export const InitialStateExtension = mod.InitialStateExtension;
|
|
29
30
|
export const LexicalBuilder = mod.LexicalBuilder;
|
|
@@ -22,6 +22,7 @@ export const DecoratorTextNode = mod.DecoratorTextNode;
|
|
|
22
22
|
export const EditorStateExtension = mod.EditorStateExtension;
|
|
23
23
|
export const HorizontalRuleExtension = mod.HorizontalRuleExtension;
|
|
24
24
|
export const HorizontalRuleNode = mod.HorizontalRuleNode;
|
|
25
|
+
export const IMEExtension = mod.IMEExtension;
|
|
25
26
|
export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
|
|
26
27
|
export const InitialStateExtension = mod.InitialStateExtension;
|
|
27
28
|
export const LexicalBuilder = mod.LexicalBuilder;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/utils");const n=Symbol.for("preact-signals");function i(){if(d>1)return void d--;let e,t=!1;for(!function(){let e=c;for(c=void 0;void 0!==e;)e.S.v===e.v&&(e.S.i=e.i),e=e.o}();void 0!==r;){let n=r;for(r=void 0,l++;void 0!==n;){const i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&E(n))try{n.c()}catch(n){t||(e=n,t=!0)}n=i}}if(l=0,d--,t)throw e}function o(e){if(d>0)return e();f=++u,d++;try{return e()}finally{i()}}let s,r;function a(e){const t=s;s=void 0;try{return e()}finally{s=t}}let c,d=0,l=0,u=0,f=0,g=0;function h(e){if(void 0===s)return;let t=e.n;return void 0===t||t.t!==s?(t={i:0,S:e,p:s.s,n:void 0,t:s,e:void 0,x:void 0,r:t},void 0!==s.s&&(s.s.n=t),s.s=t,e.n=t,32&s.f&&e.S(t),t):-1===t.i?(t.i=0,void 0!==t.n&&(t.n.p=t.p,void 0!==t.p&&(t.p.n=t.n),t.p=s.s,t.n=void 0,s.s.n=t,s.s=t),t):void 0}function p(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function m(e,t){return new p(e,t)}function E(e){for(let t=e.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function x(e){for(let t=e.s;void 0!==t;t=t.n){const n=t.S.n;if(void 0!==n&&(t.r=n),t.S.n=t,t.i=-1,void 0===t.n){e.s=t;break}}}function v(e){let t,n=e.s;for(;void 0!==n;){const e=n.p;-1===n.i?(n.S.U(n),void 0!==e&&(e.n=n.n),void 0!==n.n&&(n.n.p=e)):t=n,n.S.n=n.r,void 0!==n.r&&(n.r=void 0),n=e}e.s=t}function S(e,t){p.call(this,void 0),this.x=e,this.s=void 0,this.g=g-1,this.f=4,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function y(e,t){return new S(e,t)}function N(e){const t=e.m;if(e.m=void 0,"function"==typeof t){d++;const n=s;s=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,b(e),t}finally{s=n,i()}}}function b(e){for(let t=e.s;void 0!==t;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,N(e)}function C(e){if(s!==this)throw new Error("Out-of-order effect");v(this),s=e,this.f&=-2,8&this.f&&b(this),i()}function O(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=null==t?void 0:t.name}function R(e,t){const n=new O(e,t);try{n.c()}catch(e){throw n.d(),e}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function $(e,t={}){const n={};for(const i in e){const o=t[i],s=m(void 0===o?e[i]:o);n[i]=s}return n}p.prototype.brand=n,p.prototype.h=function(){return!0},p.prototype.S=function(e){const t=this.t;t!==e&&void 0===e.e&&(e.x=t,this.t=e,void 0!==t?t.e=e:a(()=>{var e;null==(e=this.W)||e.call(this)}))},p.prototype.U=function(e){if(void 0!==this.t){const t=e.e,n=e.x;void 0!==t&&(t.x=n,e.e=void 0),void 0!==n&&(n.e=t,e.x=void 0),e===this.t&&(this.t=n,void 0===n&&a(()=>{var e;null==(e=this.Z)||e.call(this)}))}},p.prototype.subscribe=function(e){return R(()=>{const t=this.value,n=s;s=void 0;try{e(t)}finally{s=n}},{name:"sub"})},p.prototype.valueOf=function(){return this.value},p.prototype.toString=function(){return this.value+""},p.prototype.toJSON=function(){return this.value},p.prototype.peek=function(){const e=s;s=void 0;try{return this.value}finally{s=e}},Object.defineProperty(p.prototype,"value",{get(){const e=h(this);return void 0!==e&&(e.i=this.i),this.v},set(e){if(e!==this.v){if(l>100)throw new Error("Cycle detected");!function(e){0!==d&&0===l&&e.l!==f&&(e.l=f,c={S:e,v:e.v,i:e.i,o:c})}(this),this.v=e,this.i++,g++,d++;try{for(let e=this.t;void 0!==e;e=e.x)e.t.N()}finally{i()}}}}),S.prototype=new p,S.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===g)return!0;if(this.g=g,this.f|=1,this.i>0&&!E(this))return this.f&=-2,!0;const e=s;try{x(this),s=this;const e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return s=e,v(this),this.f&=-2,!0},S.prototype.S=function(e){if(void 0===this.t){this.f|=36;for(let e=this.s;void 0!==e;e=e.n)e.S.S(e)}p.prototype.S.call(this,e)},S.prototype.U=function(e){if(void 0!==this.t&&(p.prototype.U.call(this,e),void 0===this.t)){this.f&=-33;for(let e=this.s;void 0!==e;e=e.n)e.S.U(e)}},S.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let e=this.t;void 0!==e;e=e.x)e.t.N()}},Object.defineProperty(S.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const e=h(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),O.prototype.c=function(){const e=this.S();try{if(8&this.f)return;if(void 0===this.x)return;const e=this.x();"function"==typeof e&&(this.m=e)}finally{e()}},O.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,N(this),x(this),d++;const e=s;return s=this,C.bind(this,e)},O.prototype.N=function(){2&this.f||(this.f|=2,this.u=r,r=this)},O.prototype.d=function(){this.f|=8,1&this.f||b(this)},O.prototype.dispose=function(){this.d()};const D=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({defaultSelection:"rootEnd",disabled:!1}),name:"@lexical/extension/AutoFocus",register(e,t,n){const i=n.getOutput();return R(()=>i.disabled.value?void 0:e.registerRootListener(t=>{e.focus(()=>{const e=document.activeElement;null===t||null!==e&&t.contains(e)||t.focus({preventScroll:!0})},{defaultSelection:i.defaultSelection.peek()})}))}});function w(){const t=e.$getRoot(),n=e.$getSelection(),i=e.$createParagraphNode();t.clear(),t.append(i),null!==n&&i.select(),e.$isRangeSelection(n)&&(n.format=0)}function I(t,n=w){return t.registerCommand(e.CLEAR_EDITOR_COMMAND,e=>(t.update(n),!0),e.COMMAND_PRIORITY_EDITOR)}const M=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$onClear:w}),name:"@lexical/extension/ClearEditor",register(e,t,n){const{$onClear:i}=n.getOutput();return R(()=>I(e,i.value))}});function _(t){return!!e.$isDecoratorNode(t)||!(!e.$isElementNode(t)||!t.isShadowRoot())}function T(t,n,i,o){return!!t.isEditable()&&(i.target===n&&t.getEditorState().read(()=>{const n=e.$getRoot().getLastChild();if(null===n)return!1;const s=t.getElementByKey(n.getKey());return null!==s&&(!(i.clientY<=s.getBoundingClientRect().bottom)&&o(n))},{editor:t}))}const A=e.defineExtension({build:(e,t)=>$(t),config:e.safeCast({$shouldInsertAfter:_,disabled:!1}),name:"@lexical/ClickAfterLastBlock",register:(t,n,i)=>R(()=>{const n=i.getOutput();if(!n.disabled.value)return t.registerRootListener(i=>{if(null===i)return;const o=e=>{T(t,i,e,n.$shouldInsertAfter.peek())&&e.preventDefault()},s=o=>{T(t,i,o,n.$shouldInsertAfter.peek())&&(o.preventDefault(),e.stopLexicalPropagation(o),t.update(()=>{const t=e.$getRoot().getLastChild();if(null===t)return;if(!n.$shouldInsertAfter.peek()(t))return;const i=e.$createParagraphNode();t.insertAfter(i),i.select()}))};return i.addEventListener("mousedown",o,!0),i.addEventListener("click",s,!0),()=>{i.removeEventListener("mousedown",o,!0),i.removeEventListener("click",s,!0)}})})});function F(e){return("function"==typeof e.nodes?e.nodes():e.nodes)||[]}const P=e.createState("format",{parse:e=>"number"==typeof e?e:0});class L extends e.DecoratorNode{$config(){return this.config("decorator-text",{extends:e.DecoratorNode,stateConfigs:[{flat:!0,stateConfig:P}]})}getFormat(){return e.$getState(this,P)}getFormatFlags(t,n){return e.toggleTextFormatType(this.getFormat(),t,n)}hasFormat(t){const n=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(this.getFormat()&n)}setFormat(t){return e.$setState(this,P,t)}toggleFormat(t){const n=this.getFormat(),i=e.toggleTextFormatType(n,t,null);return this.setFormat(i)}isInline(){return!0}createDOM(){return document.createElement("span")}updateDOM(){return!1}}function k(e){return e instanceof L}function K(e,t){const n=document.createElement(t);return n.appendChild(e),n}const z={b:"bold",code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"},j=e.defineExtension({name:"@lexical/extension/DecoratorText",nodes:()=>[L],register:(t,n,i)=>t.registerCommand(e.FORMAT_TEXT_COMMAND,t=>{const n=e.$getSelection();if(e.$isNodeSelection(n)||e.$isRangeSelection(n))for(const e of n.getNodes())k(e)&&e.toggleFormat(t);return!1},e.COMMAND_PRIORITY_LOW)});function B(e,t){let n;return m(e(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=e(),n=t(this)}})}const U=e.defineExtension({build:e=>B(()=>e.getEditorState(),t=>e.registerUpdateListener(e=>{t.value=e.editorState})),name:"@lexical/extension/EditorState"});function Y(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.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 W;try{W="0.45.1-dev.0+prod.cjs"}catch(e){}const G=W??"0.45.1-dev.0+source";function H(e,t){if(e&&t&&!Array.isArray(t)&&"object"==typeof e&&"object"==typeof t){const n=e,i=t;for(const e in i)n[e]=H(n[e],i[e]);return e}return t}const V=0,Z=1,J=2,X=3,q=4,Q=5,ee=6,te=7;function ne(e){return e.id===V}function ie(e){return e.id===J}function oe(e){return function(e){return e.id===Z}(e)||Y(305,String(e.id),String(Z)),Object.assign(e,{id:J})}const se=new Set;class re{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(e,t){this.builder=e,this.extension=t,this.configs=new Set,this.state={id:V}}mergeConfigs(){let t=this.extension.config||{};const n=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):e.shallowMergeConfig;for(const e of this.configs)t=n(t,e);return t}init(e){const t=this.state;ie(t)||Y(306,String(t.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(e,t,n){return Object.assign(e,{config:t,id:X,registerState:n})}(t,this.mergeConfigs(),n);let s;this.state=o,this.extension.init&&(s=this.extension.init(e,o.config,n)),this.state=function(e,t,n){return Object.assign(e,{id:q,initResult:t,registerState:n})}(o,s,i)}build(e){const t=this.state;let n;t.id!==q&&Y(307,String(t.id),String(Q)),this.extension.build&&(n=this.extension.build(e,t.config,t.registerState));const i={...t.registerState,getOutput:()=>n,getSignal:this.getSignal.bind(this)};this.state=function(e,t,n){return Object.assign(e,{id:Q,output:t,registerState:n})}(t,n,i)}register(e,t){this._signal=t;const n=this.state;n.id!==Q&&Y(308,String(n.id),String(Q));const i=this.extension.register&&this.extension.register(e,n.config,n.registerState);return this.state=function(e){return Object.assign(e,{id:ee})}(n),()=>{const e=this.state;e.id!==te&&Y(309,String(n.id),String(te)),this.state=function(e){return Object.assign(e,{id:Q})}(e),i&&i()}}afterRegistration(e){const t=this.state;let n;return t.id!==ee&&Y(310,String(t.id),String(ee)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(e,t.config,t.registerState)),this.state=function(e){return Object.assign(e,{id:te})}(t),n}getSignal(){return void 0===this._signal&&Y(311),this._signal}getInitResult(){void 0===this.extension.init&&Y(312,this.extension.name);const e=this.state;return function(e){return e.id>=q}(e)||Y(313,String(e.id),String(q)),e.initResult}getInitPeer(e){const t=this.builder.extensionNameMap.get(e);return t?t.getExtensionInitDependency():void 0}getExtensionInitDependency(){const e=this.state;return function(e){return e.id>=X}(e)||Y(314,String(e.id),String(X)),{config:e.config}}getPeer(e){const t=this.builder.extensionNameMap.get(e);return t?t.getExtensionDependency():void 0}getInitDependency(e){const t=this.builder.getExtensionRep(e);return void 0===t&&Y(315,this.extension.name,e.name),t.getExtensionInitDependency()}getDependency(e){const t=this.builder.getExtensionRep(e);return void 0===t&&Y(315,this.extension.name,e.name),t.getExtensionDependency()}getState(){const e=this.state;return function(e){return e.id>=te}(e)||Y(316,String(e.id),String(te)),e}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||se}getPeerNameSet(){let e=this._peerNameSet;return e||(e=new Set((this.extension.peerDependencies||[]).map(([e])=>e)),this._peerNameSet=e),e}getExtensionDependency(){if(!this._dependency){const e=this.state;(function(e){return e.id>=Q})(e)||Y(317,this.extension.name),this._dependency={config:e.config,init:e.initResult,output:e.output}}return this._dependency}}const ae={tag:e.HISTORY_MERGE_TAG};function ce(){const t=e.$getRoot();t.isEmpty()&&t.append(e.$createParagraphNode())}const de=e.defineExtension({config:e.safeCast({setOptions:ae,updateOptions:ae}),init:({$initialEditorState:e=ce})=>({$initialEditorState:e,initialized:!1}),afterRegistration(t,{updateOptions:n,setOptions:i},o){const s=o.getInitResult();if(!s.initialized){s.initialized=!0;const{$initialEditorState:o}=s;if(e.$isEditorState(o))t.setEditorState(o,i);else if("function"==typeof o)t.update(()=>{o(t)},n);else if(o&&("string"==typeof o||"object"==typeof o)){const e=t.parseEditorState(o);t.setEditorState(e,i)}}return()=>{}},name:"@lexical/extension/InitialState",nodes:[e.RootNode,e.TextNode,e.LineBreakNode,e.TabNode,e.ParagraphNode]}),le=Symbol.for("@lexical/extension/LexicalBuilder");function ue(){}function fe(e){throw e}function ge(e){return Array.isArray(e)?e:[e]}const he=G;class pe{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(e){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=he,this.roots=e;for(const t of e)this.addExtension(t)}static fromExtensions(e){const t=[ge(de)];for(const n of e)t.push(ge(n));return new pe(t)}static maybeFromEditor(e){const t=e[le];return t&&(t.PACKAGE_VERSION!==he&&Y(292,t.PACKAGE_VERSION,he),t instanceof pe||Y(293)),t}static fromEditor(e){const t=pe.maybeFromEditor(e);return void 0===t&&Y(294),t}constructEditor(){const{$initialEditorState:t,onError:n,...i}=this.buildCreateEditorArgs(),o=Object.assign(e.createEditor({...i,...n?{onError:e=>{n(e,o)}}:{}}),{[le]:this});for(const e of this.sortedExtensionReps())e.build(o);return o}buildEditor(){let t=ue;function n(){try{t()}finally{t=ue}}const i=Object.assign(this.constructEditor(),{dispose:n,[Symbol.dispose]:n});return t=e.mergeRegister(this.registerEditor(i),()=>i.setRootElement(null)),i}hasExtensionByName(e){return this.extensionNameMap.has(e)}getExtensionRep(e){const t=this.extensionNameMap.get(e.name);if(t)return t.extension!==e&&Y(295,e.name),t}addEdge(e,t,n){const i=this.outgoingConfigEdges.get(e);i?i.set(t,n):this.outgoingConfigEdges.set(e,new Map([[t,n]]));const o=this.incomingEdges.get(t);o?o.add(e):this.incomingEdges.set(t,new Set([e]))}addExtension(e){void 0!==this._sortedExtensionReps&&Y(296);const t=ge(e),[n]=t;"string"!=typeof n.name&&Y(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&Y(298,n.name),!i){i=new re(this,n),this.extensionNameMap.set(n.name,i);const e=this.conflicts.get(n.name);"string"==typeof e&&Y(299,n.name,e);for(const e of n.conflictsWith||[])this.extensionNameMap.has(e)&&Y(299,n.name,e),this.conflicts.set(e,n.name);for(const e of n.dependencies||[]){const t=ge(e);this.addEdge(n.name,t[0].name,t.slice(1)),this.addExtension(t)}for(const[e,t]of n.peerDependencies||[])this.addEdge(n.name,e,t?[t]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const e=[],t=(n,i)=>{let o=n.state;if(ie(o))return;const s=n.extension.name;var r;ne(o)||Y(300,s,i||"[unknown]"),ne(r=o)||Y(304,String(r.id),String(V)),o=Object.assign(r,{id:Z}),n.state=o;const a=this.outgoingConfigEdges.get(s);if(a)for(const e of a.keys()){const n=this.extensionNameMap.get(e);n&&t(n,s)}o=oe(o),n.state=o,e.push(n)};for(const e of this.extensionNameMap.values())ne(e.state)&&t(e);for(const t of e)for(const[e,n]of this.outgoingConfigEdges.get(t.extension.name)||[])if(n.length>0){const t=this.extensionNameMap.get(e);if(t)for(const e of n)t.configs.add(e)}for(const[e,...t]of this.roots)if(t.length>0){const n=this.extensionNameMap.get(e.name);void 0===n&&Y(301,e.name);for(const e of t)n.configs.add(e)}return this._sortedExtensionReps=e,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 e={},t=new Set,n=new Map,i=new Map,o={},s={},r=this.sortedExtensionReps();for(const a of r){const{extension:r}=a;if(void 0!==r.onError&&(e.onError=r.onError),void 0!==r.disableEvents&&(e.disableEvents=r.disableEvents),void 0!==r.parentEditor&&(e.parentEditor=r.parentEditor),void 0!==r.editable&&(e.editable=r.editable),void 0!==r.namespace&&(e.namespace=r.namespace),void 0!==r.$initialEditorState&&(e.$initialEditorState=r.$initialEditorState),r.nodes)for(const e of F(r)){if("function"!=typeof e){const t=n.get(e.replace);t&&Y(302,r.name,e.replace.name,t.extension.name),n.set(e.replace,a)}t.add(e)}if(r.html){if(r.html.export)for(const[e,t]of r.html.export.entries())i.set(e,t);r.html.import&&Object.assign(o,r.html.import)}r.theme&&H(s,r.theme)}Object.keys(s).length>0&&(e.theme=s),t.size&&(e.nodes=[...t]);const a=Object.keys(o).length>0,c=i.size>0;(a||c)&&(e.html={},a&&(e.html.import=o),c&&(e.html.export=i));for(const t of r)t.init(e);return e.onError||(e.onError=fe),e}}function me(e,t){const n=pe.fromEditor(e).getExtensionRep(t);return void 0===n&&Y(303,t.name),n.getExtensionDependency()}function Ee(e,t){const n=pe.maybeFromEditor(e);if(!n)return;const i=n.extensionNameMap.get(t);return i?i.getExtensionDependency():void 0}function xe(t){return me(e.$getEditor(),t)}const ve=new Set,Se=e.defineExtension({build(t,n,i){const o=i.getDependency(U).output,s=m({watchedNodeKeys:new Map}),r=B(()=>{},()=>R(()=>{const t=r.peek(),{watchedNodeKeys:n}=s.value;let i,a=!1;o.value.read(()=>{if(e.$getSelection())for(const[o,s]of n.entries()){if(0===s.size){n.delete(o);continue}const r=e.$getNodeByKey(o),c=r&&r.isSelected()||!1;a=a||c!==(!!t&&t.has(o)),c&&(i=i||new Set,i.add(o))}}),!a&&i&&t&&i.size===t.size||(r.value=i)}));return{watchNodeKey:function(e){const t=y(()=>(r.value||ve).has(e)),{watchedNodeKeys:n}=s.peek();let i=n.get(e);const o=void 0!==i;return i=i||new Set,i.add(t),o||(n.set(e,i),s.value={watchedNodeKeys:n}),t}}},dependencies:[U],name:"@lexical/extension/NodeSelection"}),ye=e.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");class Ne extends e.DecoratorNode{static getType(){return"horizontalrule"}static clone(e){return new Ne(e.__key)}static importJSON(e){return Ce().updateFromJSON(e)}static importDOM(){return{hr:()=>({conversion:be,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 be(){return{node:Ce()}}function Ce(){return e.$create(Ne)}function Oe(e){return e instanceof Ne}const Re=e.defineExtension({dependencies:[U,Se],name:"@lexical/extension/HorizontalRule",nodes:()=>[Ne],register(n,i,s){const{watchNodeKey:r}=s.getDependency(Se).output,a=m({nodeSelections:new Map}),c=n._config.theme.hrSelected??"selected";return e.mergeRegister(n.registerCommand(ye,n=>{const i=e.$getSelection();if(!e.$isRangeSelection(i))return!1;if(null!==i.focus.getNode()){const e=Ce();t.$insertNodeToNearestRoot(e)}return!0},e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.CLICK_COMMAND,t=>{if(e.isDOMNode(t.target)){const n=e.$getNodeFromDOMNode(t.target);if(Oe(n))return function(t,n=!1){const i=e.$getSelection(),o=t.isSelected(),s=t.getKey();let r;n&&e.$isNodeSelection(i)?r=i:(r=e.$createNodeSelection(),e.$setSelection(r)),o?r.delete(s):r.add(s)}(n,t.shiftKey),!0}return!1},e.COMMAND_PRIORITY_LOW),n.registerMutationListener(Ne,(e,t)=>{o(()=>{let t=!1;const{nodeSelections:i}=a.peek();for(const[o,s]of e.entries())if("destroyed"===s)i.delete(o),t=!0;else{const e=i.get(o),s=n.getElementByKey(o);e?e.domNode.value=s:(t=!0,i.set(o,{domNode:m(s),selectedSignal:r(o)}))}t&&(a.value={nodeSelections:i})})}),R(()=>{const t=[];for(const{domNode:n,selectedSignal:i}of a.value.nodeSelections.values())t.push(R(()=>{const t=n.value;if(t){i.value?e.addClassNamesToElement(t,c):e.removeClassNamesFromElement(t,c)}}));return e.mergeRegister(...t)}))}});const $e=e.defineExtension({build:(e,t)=>$({inheritEditableFromParent:t.inheritEditableFromParent}),config:e.safeCast({$getParentEditor:function(){const t=e.$getEditor();return pe.fromEditor(t),t},inheritEditableFromParent:!1}),init:(e,t,n)=>{const i=t.$getParentEditor();e.parentEditor=i,e.theme=e.theme||i._config.theme},name:"@lexical/extension/NestedEditor",register:(e,t,n)=>R(()=>{const t=e._parentEditor;if(t&&n.getOutput().inheritEditableFromParent.value)return e.setEditable(t.isEditable()),t.registerEditableListener(e.setEditable.bind(e))})});function De(t){e.$isElementNode(t)&&t.isInline()&&t.isEmpty()&&t.remove()}const we=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({disabled:!1}),name:"@lexical/NormalizeInlineElements",register:(t,n,i)=>{const o=i.getOutput();return R(()=>{if(!o.disabled.value){const n=[];for(const{klass:i,transforms:o}of t._nodes.values())i.prototype instanceof e.ElementNode&&i.prototype.isInline!==e.ElementNode.prototype.isInline&&(o.add(De),n.push(()=>o.delete(De)));return()=>n.forEach(e=>e())}})}}),Ie=new Set([e.SKIP_SELECTION_FOCUS_TAG,e.SKIP_SCROLL_INTO_VIEW_TAG]);const Me=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$fixFocusOverselection:function(){const t=e.$getSelection();if(e.$isRangeSelection(t)&&!t.isCollapsed()){const n=e.$getCaretRangeInDirection(e.$caretRangeFromSelection(t),"next");let i=n.focus;for(e.$isTextPointCaret(i)&&n.anchor.origin!==i.origin&&0===i.offset&&(i=e.$rewindSiblingCaret(i.getSiblingCaret())),e.$isSiblingCaret(i)&&n.anchor.origin!==i.origin&&e.$isLineBreakNode(i.origin)&&(i=e.$rewindSiblingCaret(i));e.$isChildCaret(i)&&n.anchor.origin!==i.origin;)i=e.$rewindSiblingCaret(e.$getSiblingCaret(i.origin,"next"));if(e.$isSiblingCaret(i)&&e.$isElementNode(i.origin)&&(i=e.$normalizeCaret(e.$getChildCaret(i.origin,"previous")).getFlipped()),i=e.$normalizeCaret(i),!i.isSamePointCaret(n.focus)){const t=e.$setSelectionFromCaretRange(e.$getCaretRange(n.anchor,i)),o=e.$getEditor().getRootElement(),s=o&&e.getDOMSelection(o.ownerDocument.defaultView);s&&e.$updateDOMSelection(e.$getPreviousSelection(),t,e.$getEditor(),s,Ie,o)}}},dateNow:Date.now,disabled:!1,thresholdMsec:100}),name:"@lexical/NormalizeTripleClickSelection",register:(t,n,i)=>R(()=>{const n=i.getOutput();if(!n.disabled.value)return t.registerRootListener(i=>{if(!i)return;let o=0;const s=e=>{if(e?3===e.detail:o>0){const t=n.dateNow.peek()();o=e&&"mousedown"===e.type||t-o<=n.thresholdMsec.peek()?t:0}return o};return e.mergeRegister(t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>(s(null)&&(o=0,n.$fixFocusOverselection.peek()()),!1),e.COMMAND_PRIORITY_BEFORE_CRITICAL),(()=>{const e=["mouseup","mousedown"];return e.forEach(e=>i.addEventListener(e,s,!0)),()=>e.forEach(e=>i.removeEventListener(e,s,!0))})())})})}),_e=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({disabled:!1,onReposition:void 0}),name:"@lexical/utils/SelectionAlwaysOnDisplay",register:(e,n,i)=>{const o=i.getOutput();return R(()=>{if(!o.disabled.value)return t.selectionAlwaysOnDisplay(e,o.onReposition.value)})}});function Te(e){return e.canIndent()}function Ae(n,i,o=Te){return e.mergeRegister(n.registerCommand(e.KEY_TAB_COMMAND,i=>{const o=e.$getSelection();if(!e.$isRangeSelection(o))return!1;i.preventDefault();const s=function(n){if(n.getNodes().filter(t=>e.$isBlockElementNode(t)&&t.canIndent()).length>0)return!0;const i=n.anchor,o=n.focus,s=o.isBefore(i)?o:i,r=s.getNode(),a=t.$getNearestBlockElementAncestorOrThrow(r);if(a.canIndent()){const t=a.getKey();let n=e.$createRangeSelection();if(n.anchor.set(t,0,"element"),n.focus.set(t,0,"element"),n=e.$normalizeSelection__EXPERIMENTAL(n),n.anchor.is(s))return!0}return!1}(o)?i.shiftKey?e.OUTDENT_CONTENT_COMMAND:e.INDENT_CONTENT_COMMAND:e.INSERT_TAB_COMMAND;return n.dispatchCommand(s,void 0)},e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.INDENT_CONTENT_COMMAND,()=>{const n="number"==typeof i?i:i?i.peek():null,s=e.$getSelection();if(!e.$isRangeSelection(s))return!1;const r="function"==typeof o?o:o.peek();return t.$handleIndentAndOutdent(e=>{if(r(e)){const t=e.getIndent()+1;(!n||t<n)&&e.setIndent(t)}})},e.COMMAND_PRIORITY_CRITICAL))}const Fe=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$canIndent:Te,disabled:!1,maxIndent:null}),name:"@lexical/extension/TabIndentation",register(e,t,n){const{disabled:i,maxIndent:o,$canIndent:s}=n.getOutput();return R(()=>{if(!i.value)return Ae(e,o,s)})}}),Pe=e.defineExtension({build:e=>B(()=>e.isEditable(),t=>e.registerEditableListener(e=>{t.value=e})),name:"@lexical/extension/WatchEditable"});exports.configExtension=e.configExtension,exports.declarePeerDependency=e.declarePeerDependency,exports.defineExtension=e.defineExtension,exports.safeCast=e.safeCast,exports.shallowMergeConfig=e.shallowMergeConfig,exports.$createHorizontalRuleNode=Ce,exports.$defaultShouldInsertAfter=_,exports.$getExtensionDependency=xe,exports.$getExtensionOutput=function(e){return xe(e).output},exports.$getPeerDependency=function(t){return Ee(e.$getEditor(),t)},exports.$isDecoratorTextNode=k,exports.$isHorizontalRuleNode=Oe,exports.AutoFocusExtension=D,exports.ClearEditorExtension=M,exports.ClickAfterLastBlockExtension=A,exports.DecoratorTextExtension=j,exports.DecoratorTextNode=L,exports.EditorStateExtension=U,exports.HorizontalRuleExtension=Re,exports.HorizontalRuleNode=Ne,exports.INSERT_HORIZONTAL_RULE_COMMAND=ye,exports.InitialStateExtension=de,exports.LexicalBuilder=pe,exports.NestedEditorExtension=$e,exports.NodeSelectionExtension=Se,exports.NormalizeInlineElementsExtension=we,exports.NormalizeTripleClickSelectionExtension=Me,exports.SelectionAlwaysOnDisplayExtension=_e,exports.TabIndentationExtension=Fe,exports.WatchEditableExtension=Pe,exports.applyFormatFromStyle=function(e,t,n){const i=t.fontWeight,o=t.textDecoration.split(" "),s="700"===i||"bold"===i,r=o.includes("line-through"),a="italic"===t.fontStyle,c=o.includes("underline"),d=t.verticalAlign;return s&&!e.hasFormat("bold")&&e.toggleFormat("bold"),r&&!e.hasFormat("strikethrough")&&e.toggleFormat("strikethrough"),a&&!e.hasFormat("italic")&&e.toggleFormat("italic"),c&&!e.hasFormat("underline")&&e.toggleFormat("underline"),"sub"!==d||e.hasFormat("subscript")||e.toggleFormat("subscript"),"super"!==d||e.hasFormat("superscript")||e.toggleFormat("superscript"),n&&!e.hasFormat(n)&&e.toggleFormat(n),e},exports.applyFormatToDom=function(e,t,n=z){for(const[i,o]of Object.entries(n))e.hasFormat(o)&&(t=K(t,i));return t},exports.batch=o,exports.buildEditorFromExtensions=function(...e){return pe.fromExtensions(e).buildEditor()},exports.computed=y,exports.effect=R,exports.getExtensionDependencyFromEditor=me,exports.getKnownTypesAndNodes=function(t){const n=new Set,i=new Set;for(const o of F(t)){const t="function"==typeof o?o:o.replace;e.getStaticNodeConfig(t),n.add(t.getType()),i.add(t)}return{nodes:i,types:n}},exports.getPeerDependencyFromEditor=Ee,exports.getPeerDependencyFromEditorOrThrow=function(e,t){const n=Ee(e,t);return void 0===n&&Y(291,t),n},exports.namedSignals=$,exports.registerClearEditor=I,exports.registerTabIndentation=Ae,exports.signal=m,exports.untracked=a,exports.watchedSignal=B;
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/utils");const n=Symbol.for("preact-signals");function i(){if(d>1)return void d--;let e,t=!1;for(!function(){let e=c;for(c=void 0;void 0!==e;)e.S.v===e.v&&(e.S.i=e.i),e=e.o}();void 0!==r;){let n=r;for(r=void 0,l++;void 0!==n;){const i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&E(n))try{n.c()}catch(n){t||(e=n,t=!0)}n=i}}if(l=0,d--,t)throw e}function o(e){if(d>0)return e();f=++u,d++;try{return e()}finally{i()}}let s,r;function a(e){const t=s;s=void 0;try{return e()}finally{s=t}}let c,d=0,l=0,u=0,f=0,g=0;function h(e){if(void 0===s)return;let t=e.n;return void 0===t||t.t!==s?(t={i:0,S:e,p:s.s,n:void 0,t:s,e:void 0,x:void 0,r:t},void 0!==s.s&&(s.s.n=t),s.s=t,e.n=t,32&s.f&&e.S(t),t):-1===t.i?(t.i=0,void 0!==t.n&&(t.n.p=t.p,void 0!==t.p&&(t.p.n=t.n),t.p=s.s,t.n=void 0,s.s.n=t,s.s=t),t):void 0}function p(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function m(e,t){return new p(e,t)}function E(e){for(let t=e.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function x(e){for(let t=e.s;void 0!==t;t=t.n){const n=t.S.n;if(void 0!==n&&(t.r=n),t.S.n=t,t.i=-1,void 0===t.n){e.s=t;break}}}function S(e){let t,n=e.s;for(;void 0!==n;){const e=n.p;-1===n.i?(n.S.U(n),void 0!==e&&(e.n=n.n),void 0!==n.n&&(n.n.p=e)):t=n,n.S.n=n.r,void 0!==n.r&&(n.r=void 0),n=e}e.s=t}function v(e,t){p.call(this,void 0),this.x=e,this.s=void 0,this.g=g-1,this.f=4,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function y(e,t){return new v(e,t)}function N(e){const t=e.m;if(e.m=void 0,"function"==typeof t){d++;const n=s;s=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,b(e),t}finally{s=n,i()}}}function b(e){for(let t=e.s;void 0!==t;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,N(e)}function C(e){if(s!==this)throw new Error("Out-of-order effect");S(this),s=e,this.f&=-2,8&this.f&&b(this),i()}function O(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=null==t?void 0:t.name}function R(e,t){const n=new O(e,t);try{n.c()}catch(e){throw n.d(),e}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function $(e,t={}){const n={};for(const i in e){const o=t[i],s=m(void 0===o?e[i]:o);n[i]=s}return n}p.prototype.brand=n,p.prototype.h=function(){return!0},p.prototype.S=function(e){const t=this.t;t!==e&&void 0===e.e&&(e.x=t,this.t=e,void 0!==t?t.e=e:a(()=>{var e;null==(e=this.W)||e.call(this)}))},p.prototype.U=function(e){if(void 0!==this.t){const t=e.e,n=e.x;void 0!==t&&(t.x=n,e.e=void 0),void 0!==n&&(n.e=t,e.x=void 0),e===this.t&&(this.t=n,void 0===n&&a(()=>{var e;null==(e=this.Z)||e.call(this)}))}},p.prototype.subscribe=function(e){return R(()=>{const t=this.value,n=s;s=void 0;try{e(t)}finally{s=n}},{name:"sub"})},p.prototype.valueOf=function(){return this.value},p.prototype.toString=function(){return this.value+""},p.prototype.toJSON=function(){return this.value},p.prototype.peek=function(){const e=s;s=void 0;try{return this.value}finally{s=e}},Object.defineProperty(p.prototype,"value",{get(){const e=h(this);return void 0!==e&&(e.i=this.i),this.v},set(e){if(e!==this.v){if(l>100)throw new Error("Cycle detected");!function(e){0!==d&&0===l&&e.l!==f&&(e.l=f,c={S:e,v:e.v,i:e.i,o:c})}(this),this.v=e,this.i++,g++,d++;try{for(let e=this.t;void 0!==e;e=e.x)e.t.N()}finally{i()}}}}),v.prototype=new p,v.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===g)return!0;if(this.g=g,this.f|=1,this.i>0&&!E(this))return this.f&=-2,!0;const e=s;try{x(this),s=this;const e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return s=e,S(this),this.f&=-2,!0},v.prototype.S=function(e){if(void 0===this.t){this.f|=36;for(let e=this.s;void 0!==e;e=e.n)e.S.S(e)}p.prototype.S.call(this,e)},v.prototype.U=function(e){if(void 0!==this.t&&(p.prototype.U.call(this,e),void 0===this.t)){this.f&=-33;for(let e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let e=this.t;void 0!==e;e=e.x)e.t.N()}},Object.defineProperty(v.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const e=h(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),O.prototype.c=function(){const e=this.S();try{if(8&this.f)return;if(void 0===this.x)return;const e=this.x();"function"==typeof e&&(this.m=e)}finally{e()}},O.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,N(this),x(this),d++;const e=s;return s=this,C.bind(this,e)},O.prototype.N=function(){2&this.f||(this.f|=2,this.u=r,r=this)},O.prototype.d=function(){this.f|=8,1&this.f||b(this)},O.prototype.dispose=function(){this.d()};const I=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({defaultSelection:"rootEnd",disabled:!1}),name:"@lexical/extension/AutoFocus",register(e,t,n){const i=n.getOutput();return R(()=>i.disabled.value?void 0:e.registerRootListener(t=>{e.focus(()=>{const e=document.activeElement;null===t||null!==e&&t.contains(e)||t.focus({preventScroll:!0})},{defaultSelection:i.defaultSelection.peek()})}))}});function _(){const t=e.$getRoot(),n=e.$getSelection(),i=e.$createParagraphNode();t.clear(),t.append(i),null!==n&&i.select(),e.$isRangeSelection(n)&&(n.format=0)}function D(t,n=_){return t.registerCommand(e.CLEAR_EDITOR_COMMAND,e=>(t.update(n),!0),e.COMMAND_PRIORITY_EDITOR)}const M=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$onClear:_}),name:"@lexical/extension/ClearEditor",register(e,t,n){const{$onClear:i}=n.getOutput();return R(()=>D(e,i.value))}});function T(t){return!!e.$isDecoratorNode(t)||!(!e.$isElementNode(t)||!t.isShadowRoot())}function w(t,n,i,o){return!!t.isEditable()&&(i.target===n&&t.getEditorState().read(()=>{const n=e.$getRoot().getLastChild();if(null===n)return!1;const s=t.getElementByKey(n.getKey());return null!==s&&(!(i.clientY<=s.getBoundingClientRect().bottom)&&o(n))},{editor:t}))}const A=e.defineExtension({build:(e,t)=>$(t),config:e.safeCast({$shouldInsertAfter:T,disabled:!1}),name:"@lexical/ClickAfterLastBlock",register:(t,n,i)=>R(()=>{const n=i.getOutput();if(!n.disabled.value)return t.registerRootListener(i=>{if(null===i)return;const o=e=>{w(t,i,e,n.$shouldInsertAfter.peek())&&e.preventDefault()},s=o=>{w(t,i,o,n.$shouldInsertAfter.peek())&&(o.preventDefault(),e.stopLexicalPropagation(o),t.update(()=>{const t=e.$getRoot().getLastChild();if(null===t)return;if(!n.$shouldInsertAfter.peek()(t))return;const i=e.$createParagraphNode();t.insertAfter(i),i.select()}))};return i.addEventListener("mousedown",o,!0),i.addEventListener("click",s,!0),()=>{i.removeEventListener("mousedown",o,!0),i.removeEventListener("click",s,!0)}})})});function F(e){return("function"==typeof e.nodes?e.nodes():e.nodes)||[]}const P=e.createState("format",{parse:e=>"number"==typeof e?e:0});class L extends e.DecoratorNode{$config(){return this.config("decorator-text",{extends:e.DecoratorNode,stateConfigs:[{flat:!0,stateConfig:P}]})}getFormat(){return e.$getState(this,P)}getFormatFlags(t,n){return e.toggleTextFormatType(this.getFormat(),t,n)}hasFormat(t){const n=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(this.getFormat()&n)}setFormat(t){return e.$setState(this,P,t)}toggleFormat(t){const n=this.getFormat(),i=e.toggleTextFormatType(n,t,null);return this.setFormat(i)}isInline(){return!0}createDOM(){return document.createElement("span")}updateDOM(){return!1}}function k(e){return e instanceof L}function K(e,t){const n=document.createElement(t);return n.appendChild(e),n}const j={b:"bold",code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"},z=e.defineExtension({name:"@lexical/extension/DecoratorText",nodes:()=>[L],register:(t,n,i)=>t.registerCommand(e.FORMAT_TEXT_COMMAND,t=>{const n=e.$getSelection();if(e.$isNodeSelection(n)||e.$isRangeSelection(n))for(const e of n.getNodes())k(e)&&e.toggleFormat(t);return!1},e.COMMAND_PRIORITY_LOW)});function B(e,t){let n;return m(e(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=e(),n=t(this)}})}const U=e.defineExtension({build:e=>B(()=>e.getEditorState(),t=>e.registerUpdateListener(e=>{t.value=e.editorState})),name:"@lexical/extension/EditorState"});function Y(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.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 G;try{G="0.45.1-nightly.20260531.0+prod.cjs"}catch(e){}const W=G??"0.45.1-nightly.20260531.0+source",H=new Set(["__proto__","constructor","prototype"]);function V(e,t){if(e&&t&&!Array.isArray(t)&&"object"==typeof e&&"object"==typeof t){const n=e,i=t;for(const e in i)!H.has(e)&&Object.prototype.hasOwnProperty.call(i,e)&&(n[e]=V(n[e],i[e]));return e}return t}const Z=0,J=1,X=2,q=3,Q=4,ee=5,te=6,ne=7;function ie(e){return e.id===Z}function oe(e){return e.id===X}function se(e){return function(e){return e.id===J}(e)||Y(305,String(e.id),String(J)),Object.assign(e,{id:X})}const re=new Set;class ae{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(e,t){this.builder=e,this.extension=t,this.configs=new Set,this.state={id:Z}}mergeConfigs(){let t=this.extension.config||{};const n=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):e.shallowMergeConfig;for(const e of this.configs)t=n(t,e);return t}init(e){const t=this.state;oe(t)||Y(306,String(t.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(e,t,n){return Object.assign(e,{config:t,id:q,registerState:n})}(t,this.mergeConfigs(),n);let s;this.state=o,this.extension.init&&(s=this.extension.init(e,o.config,n)),this.state=function(e,t,n){return Object.assign(e,{id:Q,initResult:t,registerState:n})}(o,s,i)}build(e){const t=this.state;let n;t.id!==Q&&Y(307,String(t.id),String(ee)),this.extension.build&&(n=this.extension.build(e,t.config,t.registerState));const i={...t.registerState,getOutput:()=>n,getSignal:this.getSignal.bind(this)};this.state=function(e,t,n){return Object.assign(e,{id:ee,output:t,registerState:n})}(t,n,i)}register(e,t){this._signal=t;const n=this.state;n.id!==ee&&Y(308,String(n.id),String(ee));const i=this.extension.register&&this.extension.register(e,n.config,n.registerState);return this.state=function(e){return Object.assign(e,{id:te})}(n),()=>{const e=this.state;e.id!==ne&&Y(309,String(n.id),String(ne)),this.state=function(e){return Object.assign(e,{id:ee})}(e),i&&i()}}afterRegistration(e){const t=this.state;let n;return t.id!==te&&Y(310,String(t.id),String(te)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(e,t.config,t.registerState)),this.state=function(e){return Object.assign(e,{id:ne})}(t),n}getSignal(){return void 0===this._signal&&Y(311),this._signal}getInitResult(){void 0===this.extension.init&&Y(312,this.extension.name);const e=this.state;return function(e){return e.id>=Q}(e)||Y(313,String(e.id),String(Q)),e.initResult}getInitPeer(e){const t=this.builder.extensionNameMap.get(e);return t?t.getExtensionInitDependency():void 0}getExtensionInitDependency(){const e=this.state;return function(e){return e.id>=q}(e)||Y(314,String(e.id),String(q)),{config:e.config}}getPeer(e){const t=this.builder.extensionNameMap.get(e);return t?t.getExtensionDependency():void 0}getInitDependency(e){const t=this.builder.getExtensionRep(e);return void 0===t&&Y(315,this.extension.name,e.name),t.getExtensionInitDependency()}getDependency(e){const t=this.builder.getExtensionRep(e);return void 0===t&&Y(315,this.extension.name,e.name),t.getExtensionDependency()}getState(){const e=this.state;return function(e){return e.id>=ne}(e)||Y(316,String(e.id),String(ne)),e}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||re}getPeerNameSet(){let e=this._peerNameSet;return e||(e=new Set((this.extension.peerDependencies||[]).map(([e])=>e)),this._peerNameSet=e),e}getExtensionDependency(){if(!this._dependency){const e=this.state;(function(e){return e.id>=ee})(e)||Y(317,this.extension.name),this._dependency={config:e.config,init:e.initResult,output:e.output}}return this._dependency}}const ce={tag:e.HISTORY_MERGE_TAG};function de(){const t=e.$getRoot();t.isEmpty()&&t.append(e.$createParagraphNode())}const le=e.defineExtension({config:e.safeCast({setOptions:ce,updateOptions:ce}),init:({$initialEditorState:e=de})=>({$initialEditorState:e,initialized:!1}),afterRegistration(t,{updateOptions:n,setOptions:i},o){const s=o.getInitResult();if(!s.initialized){s.initialized=!0;const{$initialEditorState:o}=s;if(e.$isEditorState(o))t.setEditorState(o,i);else if("function"==typeof o)t.update(()=>{o(t)},n);else if(o&&("string"==typeof o||"object"==typeof o)){const e=t.parseEditorState(o);t.setEditorState(e,i)}}return()=>{}},name:"@lexical/extension/InitialState",nodes:[e.RootNode,e.TextNode,e.LineBreakNode,e.TabNode,e.ParagraphNode]}),ue=Symbol.for("@lexical/extension/LexicalBuilder");function fe(){}function ge(e){throw e}function he(e){return Array.isArray(e)?e:[e]}const pe=W;class me{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(e){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=pe,this.roots=e;for(const t of e)this.addExtension(t)}static fromExtensions(e){const t=[he(le)];for(const n of e)t.push(he(n));return new me(t)}static maybeFromEditor(e){const t=e[ue];return t&&(t.PACKAGE_VERSION!==pe&&Y(292,t.PACKAGE_VERSION,pe),t instanceof me||Y(293)),t}static fromEditor(e){const t=me.maybeFromEditor(e);return void 0===t&&Y(294),t}constructEditor(){const{$initialEditorState:t,onError:n,...i}=this.buildCreateEditorArgs(),o=Object.assign(e.createEditor({...i,...n?{onError:e=>{n(e,o)}}:{}}),{[ue]:this});for(const e of this.sortedExtensionReps())e.build(o);return o}buildEditor(){let t=fe;function n(){try{t()}finally{t=fe}}const i=Object.assign(this.constructEditor(),{dispose:n,[Symbol.dispose]:n});return t=e.mergeRegister(this.registerEditor(i),()=>i.setRootElement(null)),i}hasExtensionByName(e){return this.extensionNameMap.has(e)}getExtensionRep(e){const t=this.extensionNameMap.get(e.name);if(t)return t.extension!==e&&Y(295,e.name),t}addEdge(e,t,n){const i=this.outgoingConfigEdges.get(e);i?i.set(t,n):this.outgoingConfigEdges.set(e,new Map([[t,n]]));const o=this.incomingEdges.get(t);o?o.add(e):this.incomingEdges.set(t,new Set([e]))}addExtension(e){void 0!==this._sortedExtensionReps&&Y(296);const t=he(e),[n]=t;"string"!=typeof n.name&&Y(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&Y(298,n.name),!i){i=new ae(this,n),this.extensionNameMap.set(n.name,i);const e=this.conflicts.get(n.name);"string"==typeof e&&Y(299,n.name,e);for(const e of n.conflictsWith||[])this.extensionNameMap.has(e)&&Y(299,n.name,e),this.conflicts.set(e,n.name);for(const e of n.dependencies||[]){const t=he(e);this.addEdge(n.name,t[0].name,t.slice(1)),this.addExtension(t)}for(const[e,t]of n.peerDependencies||[])this.addEdge(n.name,e,t?[t]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const e=[],t=(n,i)=>{let o=n.state;if(oe(o))return;const s=n.extension.name;var r;ie(o)||Y(300,s,i||"[unknown]"),ie(r=o)||Y(304,String(r.id),String(Z)),o=Object.assign(r,{id:J}),n.state=o;const a=this.outgoingConfigEdges.get(s);if(a)for(const e of a.keys()){const n=this.extensionNameMap.get(e);n&&t(n,s)}o=se(o),n.state=o,e.push(n)};for(const e of this.extensionNameMap.values())ie(e.state)&&t(e);for(const t of e)for(const[e,n]of this.outgoingConfigEdges.get(t.extension.name)||[])if(n.length>0){const t=this.extensionNameMap.get(e);if(t)for(const e of n)t.configs.add(e)}for(const[e,...t]of this.roots)if(t.length>0){const n=this.extensionNameMap.get(e.name);void 0===n&&Y(301,e.name);for(const e of t)n.configs.add(e)}return this._sortedExtensionReps=e,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 e={},t=new Set,n=new Map,i=new Map,o={},s={},r=this.sortedExtensionReps();for(const a of r){const{extension:r}=a;if(void 0!==r.onError&&(e.onError=r.onError),void 0!==r.disableEvents&&(e.disableEvents=r.disableEvents),void 0!==r.parentEditor&&(e.parentEditor=r.parentEditor),void 0!==r.editable&&(e.editable=r.editable),void 0!==r.namespace&&(e.namespace=r.namespace),void 0!==r.$initialEditorState&&(e.$initialEditorState=r.$initialEditorState),r.nodes)for(const e of F(r)){if("function"!=typeof e){const t=n.get(e.replace);t&&Y(302,r.name,e.replace.name,t.extension.name),n.set(e.replace,a)}t.add(e)}if(r.html){if(r.html.export)for(const[e,t]of r.html.export.entries())i.set(e,t);r.html.import&&Object.assign(o,r.html.import)}r.theme&&V(s,r.theme)}Object.keys(s).length>0&&(e.theme=s),t.size&&(e.nodes=[...t]);const a=Object.keys(o).length>0,c=i.size>0;(a||c)&&(e.html={},a&&(e.html.import=o),c&&(e.html.export=i));for(const t of r)t.init(e);return e.onError||(e.onError=ge),e}}function Ee(e,t){const n=me.fromEditor(e).getExtensionRep(t);return void 0===n&&Y(303,t.name),n.getExtensionDependency()}function xe(e,t){const n=me.maybeFromEditor(e);if(!n)return;const i=n.extensionNameMap.get(t);return i?i.getExtensionDependency():void 0}function Se(t){return Ee(e.$getEditor(),t)}const ve=new Set,ye=e.defineExtension({build(t,n,i){const o=i.getDependency(U).output,s=m({watchedNodeKeys:new Map}),r=B(()=>{},()=>R(()=>{const t=r.peek(),{watchedNodeKeys:n}=s.value;let i,a=!1;o.value.read(()=>{if(e.$getSelection())for(const[o,s]of n.entries()){if(0===s.size){n.delete(o);continue}const r=e.$getNodeByKey(o),c=r&&r.isSelected()||!1;a=a||c!==(!!t&&t.has(o)),c&&(i=i||new Set,i.add(o))}}),!a&&i&&t&&i.size===t.size||(r.value=i)}));return{watchNodeKey:function(e){const t=y(()=>(r.value||ve).has(e)),{watchedNodeKeys:n}=s.peek();let i=n.get(e);const o=void 0!==i;return i=i||new Set,i.add(t),o||(n.set(e,i),s.value={watchedNodeKeys:n}),t}}},dependencies:[U],name:"@lexical/extension/NodeSelection"}),Ne=e.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");class be extends e.DecoratorNode{static getType(){return"horizontalrule"}static clone(e){return new be(e.__key)}static importJSON(e){return Oe().updateFromJSON(e)}static importDOM(){return{hr:()=>({conversion:Ce,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 Ce(){return{node:Oe()}}function Oe(){return e.$create(be)}function Re(e){return e instanceof be}const $e=e.defineExtension({dependencies:[U,ye],name:"@lexical/extension/HorizontalRule",nodes:()=>[be],register(n,i,s){const{watchNodeKey:r}=s.getDependency(ye).output,a=m({nodeSelections:new Map}),c=n._config.theme.hrSelected??"selected";return e.mergeRegister(n.registerCommand(Ne,n=>{const i=e.$getSelection();if(!e.$isRangeSelection(i))return!1;if(null!==i.focus.getNode()){const e=Oe();t.$insertNodeToNearestRoot(e)}return!0},e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.CLICK_COMMAND,t=>{if(e.isDOMNode(t.target)){const n=e.$getNodeFromDOMNode(t.target);if(Re(n))return function(t,n=!1){const i=e.$getSelection(),o=t.isSelected(),s=t.getKey();let r;n&&e.$isNodeSelection(i)?r=i:(r=e.$createNodeSelection(),e.$setSelection(r)),o?r.delete(s):r.add(s)}(n,t.shiftKey),!0}return!1},e.COMMAND_PRIORITY_LOW),n.registerMutationListener(be,(e,t)=>{o(()=>{let t=!1;const{nodeSelections:i}=a.peek();for(const[o,s]of e.entries())if("destroyed"===s)i.delete(o),t=!0;else{const e=i.get(o),s=n.getElementByKey(o);e?e.domNode.value=s:(t=!0,i.set(o,{domNode:m(s),selectedSignal:r(o)}))}t&&(a.value={nodeSelections:i})})}),R(()=>{const t=[];for(const{domNode:n,selectedSignal:i}of a.value.nodeSelections.values())t.push(R(()=>{const t=n.value;if(t){i.value?e.addClassNamesToElement(t,c):e.removeClassNamesFromElement(t,c)}}));return e.mergeRegister(...t)}))}}),Ie=e.defineExtension({build:e=>({composingTextNode:m(null),compositionKey:m(null)}),name:"@lexical/extension/IME",register(n,i,o){const{compositionKey:s,composingTextNode:r}=o.getOutput(),a=n.registerCommand(e.COMPOSITION_START_COMMAND,()=>{const t=e.$getSelection();return e.$isRangeSelection(t)&&(s.value=t.anchor.key),!1},e.COMMAND_PRIORITY_BEFORE_EDITOR),c=R(()=>{const t=s.value;r.value=null!==t?n.getEditorState().read(()=>{const n=e.$getNodeByKey(t);return e.$isTextNode(n)?n:null}):null}),d=n.registerUpdateListener(({tags:t,editorState:n})=>{t.has(e.COMPOSITION_START_TAG)&&n.read(()=>{const t=e.$getSelection();if(!e.$isRangeSelection(t))return;const n=t.anchor.getNode();e.$isTextNode(n)&&(r.value=n)})}),l=n.registerRootListener(e=>{if(null===e)return void(s.value=null);const t=()=>{s.value=null};return e.addEventListener("compositionend",t),()=>{e.removeEventListener("compositionend",t)}});return t.mergeRegister(a,c,d,l)}});const _e=e.defineExtension({build:(e,t)=>$({inheritEditableFromParent:t.inheritEditableFromParent}),config:e.safeCast({$getParentEditor:function(){const t=e.$getEditor();return me.fromEditor(t),t},inheritEditableFromParent:!1}),init:(e,t,n)=>{const i=t.$getParentEditor();e.parentEditor=i,e.theme=e.theme||i._config.theme},name:"@lexical/extension/NestedEditor",register:(e,t,n)=>R(()=>{const t=e._parentEditor;if(t&&n.getOutput().inheritEditableFromParent.value)return e.setEditable(t.isEditable()),t.registerEditableListener(e.setEditable.bind(e))})});function De(t){e.$isElementNode(t)&&t.isInline()&&t.isEmpty()&&t.remove()}const Me=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({disabled:!1}),name:"@lexical/NormalizeInlineElements",register:(t,n,i)=>{const o=i.getOutput();return R(()=>{if(!o.disabled.value){const n=[];for(const{klass:i,transforms:o}of t._nodes.values())i.prototype instanceof e.ElementNode&&i.prototype.isInline!==e.ElementNode.prototype.isInline&&(o.add(De),n.push(()=>o.delete(De)));return()=>n.forEach(e=>e())}})}}),Te=new Set([e.SKIP_SELECTION_FOCUS_TAG,e.SKIP_SCROLL_INTO_VIEW_TAG]);const we=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$fixFocusOverselection:function(){const t=e.$getSelection();if(e.$isRangeSelection(t)&&!t.isCollapsed()){const n=e.$getCaretRangeInDirection(e.$caretRangeFromSelection(t),"next");let i=n.focus;for(e.$isTextPointCaret(i)&&n.anchor.origin!==i.origin&&0===i.offset&&(i=e.$rewindSiblingCaret(i.getSiblingCaret())),e.$isSiblingCaret(i)&&n.anchor.origin!==i.origin&&e.$isLineBreakNode(i.origin)&&(i=e.$rewindSiblingCaret(i));e.$isChildCaret(i)&&n.anchor.origin!==i.origin;)i=e.$rewindSiblingCaret(e.$getSiblingCaret(i.origin,"next"));if(e.$isSiblingCaret(i)&&e.$isElementNode(i.origin)&&(i=e.$normalizeCaret(e.$getChildCaret(i.origin,"previous")).getFlipped()),i=e.$normalizeCaret(i),!i.isSamePointCaret(n.focus)){const t=e.$setSelectionFromCaretRange(e.$getCaretRange(n.anchor,i)),o=e.$getEditor().getRootElement(),s=o&&e.getDOMSelection(o.ownerDocument.defaultView);s&&e.$updateDOMSelection(e.$getPreviousSelection(),t,e.$getEditor(),s,Te,o)}}},dateNow:Date.now,disabled:!1,thresholdMsec:100}),name:"@lexical/NormalizeTripleClickSelection",register:(t,n,i)=>R(()=>{const n=i.getOutput();if(!n.disabled.value)return t.registerRootListener(i=>{if(!i)return;let o=0;const s=e=>{if(e?3===e.detail:o>0){const t=n.dateNow.peek()();o=e&&"mousedown"===e.type||t-o<=n.thresholdMsec.peek()?t:0}return o};return e.mergeRegister(t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>(s(null)&&(o=0,n.$fixFocusOverselection.peek()()),!1),e.COMMAND_PRIORITY_BEFORE_CRITICAL),(()=>{const e=["mouseup","mousedown"];return e.forEach(e=>i.addEventListener(e,s,!0)),()=>e.forEach(e=>i.removeEventListener(e,s,!0))})())})})}),Ae=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({disabled:!1,onReposition:void 0}),name:"@lexical/utils/SelectionAlwaysOnDisplay",register:(e,n,i)=>{const o=i.getOutput();return R(()=>{if(!o.disabled.value)return t.selectionAlwaysOnDisplay(e,o.onReposition.value)})}});function Fe(e){return e.canIndent()}function Pe(n,i,o=Fe){return e.mergeRegister(n.registerCommand(e.KEY_TAB_COMMAND,i=>{const o=e.$getSelection();if(!e.$isRangeSelection(o))return!1;i.preventDefault();const s=function(n){if(n.getNodes().filter(t=>e.$isBlockElementNode(t)&&t.canIndent()).length>0)return!0;const i=n.anchor,o=n.focus,s=o.isBefore(i)?o:i,r=s.getNode(),a=t.$getNearestBlockElementAncestorOrThrow(r);if(a.canIndent()){const t=a.getKey();let n=e.$createRangeSelection();if(n.anchor.set(t,0,"element"),n.focus.set(t,0,"element"),n=e.$normalizeSelection__EXPERIMENTAL(n),n.anchor.is(s))return!0}return!1}(o)?i.shiftKey?e.OUTDENT_CONTENT_COMMAND:e.INDENT_CONTENT_COMMAND:e.INSERT_TAB_COMMAND;return n.dispatchCommand(s,void 0)},e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.INDENT_CONTENT_COMMAND,()=>{const n="number"==typeof i?i:i?i.peek():null,s=e.$getSelection();if(!e.$isRangeSelection(s))return!1;const r="function"==typeof o?o:o.peek();return t.$handleIndentAndOutdent(e=>{if(r(e)){const t=e.getIndent()+1;(!n||t<n)&&e.setIndent(t)}})},e.COMMAND_PRIORITY_CRITICAL))}const Le=e.defineExtension({build:(e,t,n)=>$(t),config:e.safeCast({$canIndent:Fe,disabled:!1,maxIndent:null}),name:"@lexical/extension/TabIndentation",register(e,t,n){const{disabled:i,maxIndent:o,$canIndent:s}=n.getOutput();return R(()=>{if(!i.value)return Pe(e,o,s)})}}),ke=e.defineExtension({build:e=>B(()=>e.isEditable(),t=>e.registerEditableListener(e=>{t.value=e})),name:"@lexical/extension/WatchEditable"});exports.configExtension=e.configExtension,exports.declarePeerDependency=e.declarePeerDependency,exports.defineExtension=e.defineExtension,exports.safeCast=e.safeCast,exports.shallowMergeConfig=e.shallowMergeConfig,exports.$createHorizontalRuleNode=Oe,exports.$defaultShouldInsertAfter=T,exports.$getExtensionDependency=Se,exports.$getExtensionOutput=function(e){return Se(e).output},exports.$getPeerDependency=function(t){return xe(e.$getEditor(),t)},exports.$isDecoratorTextNode=k,exports.$isHorizontalRuleNode=Re,exports.AutoFocusExtension=I,exports.ClearEditorExtension=M,exports.ClickAfterLastBlockExtension=A,exports.DecoratorTextExtension=z,exports.DecoratorTextNode=L,exports.EditorStateExtension=U,exports.HorizontalRuleExtension=$e,exports.HorizontalRuleNode=be,exports.IMEExtension=Ie,exports.INSERT_HORIZONTAL_RULE_COMMAND=Ne,exports.InitialStateExtension=le,exports.LexicalBuilder=me,exports.NestedEditorExtension=_e,exports.NodeSelectionExtension=ye,exports.NormalizeInlineElementsExtension=Me,exports.NormalizeTripleClickSelectionExtension=we,exports.SelectionAlwaysOnDisplayExtension=Ae,exports.TabIndentationExtension=Le,exports.WatchEditableExtension=ke,exports.applyFormatFromStyle=function(e,t,n){const i=t.fontWeight,o=t.textDecoration.split(" "),s="700"===i||"bold"===i,r=o.includes("line-through"),a="italic"===t.fontStyle,c=o.includes("underline"),d=t.verticalAlign;return s&&!e.hasFormat("bold")&&e.toggleFormat("bold"),r&&!e.hasFormat("strikethrough")&&e.toggleFormat("strikethrough"),a&&!e.hasFormat("italic")&&e.toggleFormat("italic"),c&&!e.hasFormat("underline")&&e.toggleFormat("underline"),"sub"!==d||e.hasFormat("subscript")||e.toggleFormat("subscript"),"super"!==d||e.hasFormat("superscript")||e.toggleFormat("superscript"),n&&!e.hasFormat(n)&&e.toggleFormat(n),e},exports.applyFormatToDom=function(e,t,n=j){for(const[i,o]of Object.entries(n))e.hasFormat(o)&&(t=K(t,i));return t},exports.batch=o,exports.buildEditorFromExtensions=function(...e){return me.fromExtensions(e).buildEditor()},exports.computed=y,exports.effect=R,exports.getExtensionDependencyFromEditor=Ee,exports.getKnownTypesAndNodes=function(t){const n=new Set,i=new Set;for(const o of F(t)){const t="function"==typeof o?o:o.replace;e.getStaticNodeConfig(t),n.add(t.getType()),i.add(t)}return{nodes:i,types:n}},exports.getPeerDependencyFromEditor=xe,exports.getPeerDependencyFromEditorOrThrow=function(e,t){const n=xe(e,t);return void 0===n&&Y(291,t),n},exports.namedSignals=$,exports.registerClearEditor=D,exports.registerTabIndentation=Pe,exports.signal=m,exports.untracked=a,exports.watchedSignal=B;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
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,$isDecoratorNode as a,$isElementNode as d,stopLexicalPropagation as u,getStaticNodeConfig as l,FORMAT_TEXT_COMMAND as f,$isNodeSelection as h,COMMAND_PRIORITY_LOW as g,DecoratorNode as p,$getState as m,toggleTextFormatType as v,$setState as E,TEXT_TYPE_TO_FORMAT as x,createState as y,shallowMergeConfig as S,RootNode as b,TextNode as w,LineBreakNode as N,TabNode as O,ParagraphNode as C,$isEditorState as R,HISTORY_MERGE_TAG as D,createEditor as F,mergeRegister as I,$getEditor as M,$getNodeByKey as k,$create as _,CLICK_COMMAND as A,isDOMNode as P,$getNodeFromDOMNode as L,addClassNamesToElement as $,createCommand as j,$createNodeSelection as K,$setSelection as z,removeClassNamesFromElement as U,ElementNode as T,$getCaretRangeInDirection as B,$caretRangeFromSelection as W,$isTextPointCaret as V,$rewindSiblingCaret as G,$isSiblingCaret as Z,$isLineBreakNode as J,$isChildCaret as H,$getSiblingCaret as Y,$normalizeCaret as q,$getChildCaret as Q,$setSelectionFromCaretRange as X,$getCaretRange as tt,getDOMSelection as et,$updateDOMSelection as nt,$getPreviousSelection as it,SKIP_SELECTION_FOCUS_TAG as ot,SKIP_SCROLL_INTO_VIEW_TAG as st,SELECTION_CHANGE_COMMAND as rt,COMMAND_PRIORITY_BEFORE_CRITICAL as ct,KEY_TAB_COMMAND as at,OUTDENT_CONTENT_COMMAND as dt,INDENT_CONTENT_COMMAND as ut,INSERT_TAB_COMMAND as lt,COMMAND_PRIORITY_CRITICAL as ft,$isBlockElementNode as ht,$createRangeSelection as gt,$normalizeSelection__EXPERIMENTAL as pt}from"lexical";export{configExtension,declarePeerDependency,defineExtension,safeCast,shallowMergeConfig}from"lexical";import{$insertNodeToNearestRoot as mt,selectionAlwaysOnDisplay as vt,$handleIndentAndOutdent as Et,$getNearestBlockElementAncestorOrThrow as xt}from"@lexical/utils";const yt=Symbol.for("preact-signals");function St(){if(Rt>1)return void Rt--;let t,e=!1;for(!function(){let t=Ct;for(Ct=void 0;void 0!==t;)t.S.v===t.v&&(t.S.i=t.i),t=t.o}();void 0!==Nt;){let n=Nt;for(Nt=void 0,Dt++;void 0!==n;){const i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Pt(n))try{n.c()}catch(n){e||(t=n,e=!0)}n=i}}if(Dt=0,Rt--,e)throw t}function bt(t){if(Rt>0)return t();It=++Ft,Rt++;try{return t()}finally{St()}}let wt,Nt;function Ot(t){const e=wt;wt=void 0;try{return t()}finally{wt=e}}let Ct,Rt=0,Dt=0,Ft=0,It=0,Mt=0;function kt(t){if(void 0===wt)return;let e=t.n;return void 0===e||e.t!==wt?(e={i:0,S:t,p:wt.s,n:void 0,t:wt,e:void 0,x:void 0,r:e},void 0!==wt.s&&(wt.s.n=e),wt.s=e,t.n=e,32&wt.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=wt.s,e.n=void 0,wt.s.n=e,wt.s=e),e):void 0}function _t(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=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 At(t,e){return new _t(t,e)}function Pt(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 Lt(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 $t(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 jt(t,e){_t.call(this,void 0),this.x=t,this.s=void 0,this.g=Mt-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 Kt(t,e){return new jt(t,e)}function zt(t){const e=t.m;if(t.m=void 0,"function"==typeof e){Rt++;const n=wt;wt=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,Ut(t),e}finally{wt=n,St()}}}function Ut(t){for(let e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,zt(t)}function Tt(t){if(wt!==this)throw new Error("Out-of-order effect");$t(this),wt=t,this.f&=-2,8&this.f&&Ut(this),St()}function Bt(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=null==e?void 0:e.name}function Wt(t,e){const n=new Bt(t,e);try{n.c()}catch(t){throw n.d(),t}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function Vt(t,e={}){const n={};for(const i in t){const o=e[i],s=At(void 0===o?t[i]:o);n[i]=s}return n}_t.prototype.brand=yt,_t.prototype.h=function(){return!0},_t.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:Ot(()=>{var t;null==(t=this.W)||t.call(this)}))},_t.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&&Ot(()=>{var t;null==(t=this.Z)||t.call(this)}))}},_t.prototype.subscribe=function(t){return Wt(()=>{const e=this.value,n=wt;wt=void 0;try{t(e)}finally{wt=n}},{name:"sub"})},_t.prototype.valueOf=function(){return this.value},_t.prototype.toString=function(){return this.value+""},_t.prototype.toJSON=function(){return this.value},_t.prototype.peek=function(){const t=wt;wt=void 0;try{return this.value}finally{wt=t}},Object.defineProperty(_t.prototype,"value",{get(){const t=kt(this);return void 0!==t&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(Dt>100)throw new Error("Cycle detected");!function(t){0!==Rt&&0===Dt&&t.l!==It&&(t.l=It,Ct={S:t,v:t.v,i:t.i,o:Ct})}(this),this.v=t,this.i++,Mt++,Rt++;try{for(let t=this.t;void 0!==t;t=t.x)t.t.N()}finally{St()}}}}),jt.prototype=new _t,jt.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===Mt)return!0;if(this.g=Mt,this.f|=1,this.i>0&&!Pt(this))return this.f&=-2,!0;const t=wt;try{Lt(this),wt=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 wt=t,$t(this),this.f&=-2,!0},jt.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)}_t.prototype.S.call(this,t)},jt.prototype.U=function(t){if(void 0!==this.t&&(_t.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)}},jt.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(jt.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=kt(this);if(this.h(),void 0!==t&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),Bt.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.m=t)}finally{t()}},Bt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,zt(this),Lt(this),Rt++;const t=wt;return wt=this,Tt.bind(this,t)},Bt.prototype.N=function(){2&this.f||(this.f|=2,this.u=Nt,Nt=this)},Bt.prototype.d=function(){this.f|=8,1&this.f||Ut(this)},Bt.prototype.dispose=function(){this.d()};const Gt=t({build:(t,e,n)=>Vt(e),config:e({defaultSelection:"rootEnd",disabled:!1}),name:"@lexical/extension/AutoFocus",register(t,e,n){const i=n.getOutput();return Wt(()=>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 Zt(){const t=o(),e=s(),n=r();t.clear(),t.append(n),null!==e&&n.select(),c(e)&&(e.format=0)}function Jt(t,e=Zt){return t.registerCommand(n,n=>(t.update(e),!0),i)}const Ht=t({build:(t,e,n)=>Vt(e),config:e({$onClear:Zt}),name:"@lexical/extension/ClearEditor",register(t,e,n){const{$onClear:i}=n.getOutput();return Wt(()=>Jt(t,i.value))}});function Yt(t){return!!a(t)||!(!d(t)||!t.isShadowRoot())}function qt(t,e,n,i){return!!t.isEditable()&&(n.target===e&&t.getEditorState().read(()=>{const e=o().getLastChild();if(null===e)return!1;const s=t.getElementByKey(e.getKey());return null!==s&&(!(n.clientY<=s.getBoundingClientRect().bottom)&&i(e))},{editor:t}))}const Qt=t({build:(t,e)=>Vt(e),config:e({$shouldInsertAfter:Yt,disabled:!1}),name:"@lexical/ClickAfterLastBlock",register:(t,e,n)=>Wt(()=>{const e=n.getOutput();if(!e.disabled.value)return t.registerRootListener(n=>{if(null===n)return;const i=i=>{qt(t,n,i,e.$shouldInsertAfter.peek())&&i.preventDefault()},s=i=>{qt(t,n,i,e.$shouldInsertAfter.peek())&&(i.preventDefault(),u(i),t.update(()=>{const t=o().getLastChild();if(null===t)return;if(!e.$shouldInsertAfter.peek()(t))return;const n=r();t.insertAfter(n),n.select()}))};return n.addEventListener("mousedown",i,!0),n.addEventListener("click",s,!0),()=>{n.removeEventListener("mousedown",i,!0),n.removeEventListener("click",s,!0)}})})});function Xt(t){const e=new Set,n=new Set;for(const i of te(t)){const t="function"==typeof i?i:i.replace;l(t),e.add(t.getType()),n.add(t)}return{nodes:n,types:e}}function te(t){return("function"==typeof t.nodes?t.nodes():t.nodes)||[]}const ee=y("format",{parse:t=>"number"==typeof t?t:0});class ne extends p{$config(){return this.config("decorator-text",{extends:p,stateConfigs:[{flat:!0,stateConfig:ee}]})}getFormat(){return m(this,ee)}getFormatFlags(t,e){return v(this.getFormat(),t,e)}hasFormat(t){const e=x[t];return 0!==(this.getFormat()&e)}setFormat(t){return E(this,ee,t)}toggleFormat(t){const e=this.getFormat(),n=v(e,t,null);return this.setFormat(n)}isInline(){return!0}createDOM(){return document.createElement("span")}updateDOM(){return!1}}function ie(t){return t instanceof ne}function oe(t,e,n){const i=e.fontWeight,o=e.textDecoration.split(" "),s="700"===i||"bold"===i,r=o.includes("line-through"),c="italic"===e.fontStyle,a=o.includes("underline"),d=e.verticalAlign;return s&&!t.hasFormat("bold")&&t.toggleFormat("bold"),r&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),c&&!t.hasFormat("italic")&&t.toggleFormat("italic"),a&&!t.hasFormat("underline")&&t.toggleFormat("underline"),"sub"!==d||t.hasFormat("subscript")||t.toggleFormat("subscript"),"super"!==d||t.hasFormat("superscript")||t.toggleFormat("superscript"),n&&!t.hasFormat(n)&&t.toggleFormat(n),t}function se(t,e,n=ce){for(const[i,o]of Object.entries(n))t.hasFormat(o)&&(e=re(e,i));return e}function re(t,e){const n=document.createElement(e);return n.appendChild(t),n}const ce={b:"bold",code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"},ae=t({name:"@lexical/extension/DecoratorText",nodes:()=>[ne],register:(t,e,n)=>t.registerCommand(f,t=>{const e=s();if(h(e)||c(e))for(const n of e.getNodes())ie(n)&&n.toggleFormat(t);return!1},g)});function de(t,e){let n;return At(t(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=t(),n=e(this)}})}const ue=t({build:t=>de(()=>t.getEditorState(),e=>t.registerUpdateListener(t=>{e.value=t.editorState})),name:"@lexical/extension/EditorState"});function le(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.`)}let fe;try{fe="0.45.1-dev.0+prod.esm"}catch(t){}const he=fe??"0.45.1-dev.0+source";function ge(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]=ge(n[t],i[t]);return t}return e}const pe=0,me=1,ve=2,Ee=3,xe=4,ye=5,Se=6,be=7;function we(t){return t.id===pe}function Ne(t){return t.id===ve}function Oe(t){return function(t){return t.id===me}(t)||le(305,String(t.id),String(me)),Object.assign(t,{id:ve})}const Ce=new Set;class Re{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(t,e){this.builder=t,this.extension=e,this.configs=new Set,this.state={id:pe}}mergeConfigs(){let t=this.extension.config||{};const e=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):S;for(const n of this.configs)t=e(t,n);return t}init(t){const e=this.state;Ne(e)||le(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:Ee,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:xe,initResult:e,registerState:n})}(o,s,i)}build(t){const e=this.state;let n;e.id!==xe&&le(307,String(e.id),String(ye)),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:ye,output:e,registerState:n})}(e,n,i)}register(t,e){this._signal=e;const n=this.state;n.id!==ye&&le(308,String(n.id),String(ye));const i=this.extension.register&&this.extension.register(t,n.config,n.registerState);return this.state=function(t){return Object.assign(t,{id:Se})}(n),()=>{const t=this.state;t.id!==be&&le(309,String(n.id),String(be)),this.state=function(t){return Object.assign(t,{id:ye})}(t),i&&i()}}afterRegistration(t){const e=this.state;let n;return e.id!==Se&&le(310,String(e.id),String(Se)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(t,e.config,e.registerState)),this.state=function(t){return Object.assign(t,{id:be})}(e),n}getSignal(){return void 0===this._signal&&le(311),this._signal}getInitResult(){void 0===this.extension.init&&le(312,this.extension.name);const t=this.state;return function(t){return t.id>=xe}(t)||le(313,String(t.id),String(xe)),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>=Ee}(t)||le(314,String(t.id),String(Ee)),{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&&le(315,this.extension.name,t.name),e.getExtensionInitDependency()}getDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&le(315,this.extension.name,t.name),e.getExtensionDependency()}getState(){const t=this.state;return function(t){return t.id>=be}(t)||le(316,String(t.id),String(be)),t}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||Ce}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>=ye})(t)||le(317,this.extension.name),this._dependency={config:t.config,init:t.initResult,output:t.output}}return this._dependency}}const De={tag:D};function Fe(){const t=o();t.isEmpty()&&t.append(r())}const Ie=t({config:e({setOptions:De,updateOptions:De}),init:({$initialEditorState:t=Fe})=>({$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(R(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:"@lexical/extension/InitialState",nodes:[b,w,N,O,C]}),Me=Symbol.for("@lexical/extension/LexicalBuilder");function ke(...t){return $e.fromExtensions(t).buildEditor()}function _e(){}function Ae(t){throw t}function Pe(t){return Array.isArray(t)?t:[t]}const Le=he;class $e{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=Le,this.roots=t;for(const e of t)this.addExtension(e)}static fromExtensions(t){const e=[Pe(Ie)];for(const n of t)e.push(Pe(n));return new $e(e)}static maybeFromEditor(t){const e=t[Me];return e&&(e.PACKAGE_VERSION!==Le&&le(292,e.PACKAGE_VERSION,Le),e instanceof $e||le(293)),e}static fromEditor(t){const e=$e.maybeFromEditor(t);return void 0===e&&le(294),e}constructEditor(){const{$initialEditorState:t,onError:e,...n}=this.buildCreateEditorArgs(),i=Object.assign(F({...n,...e?{onError:t=>{e(t,i)}}:{}}),{[Me]:this});for(const t of this.sortedExtensionReps())t.build(i);return i}buildEditor(){let t=_e;function e(){try{t()}finally{t=_e}}const n=Object.assign(this.constructEditor(),{dispose:e,[Symbol.dispose]:e});return t=I(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&&le(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&&le(296);const e=Pe(t),[n]=e;"string"!=typeof n.name&&le(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&le(298,n.name),!i){i=new Re(this,n),this.extensionNameMap.set(n.name,i);const t=this.conflicts.get(n.name);"string"==typeof t&&le(299,n.name,t);for(const t of n.conflictsWith||[])this.extensionNameMap.has(t)&&le(299,n.name,t),this.conflicts.set(t,n.name);for(const t of n.dependencies||[]){const e=Pe(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(Ne(o))return;const s=n.extension.name;var r;we(o)||le(300,s,i||"[unknown]"),we(r=o)||le(304,String(r.id),String(pe)),o=Object.assign(r,{id:me}),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=Oe(o),n.state=o,t.push(n)};for(const t of this.extensionNameMap.values())we(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&&le(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 I(...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 te(r)){if("function"!=typeof t){const e=n.get(t.replace);e&&le(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&&ge(s,r.theme)}Object.keys(s).length>0&&(t.theme=s),e.size&&(t.nodes=[...e]);const c=Object.keys(o).length>0,a=i.size>0;(c||a)&&(t.html={},c&&(t.html.import=o),a&&(t.html.export=i));for(const e of r)e.init(t);return t.onError||(t.onError=Ae),t}}function je(t,e){const n=$e.fromEditor(t).getExtensionRep(e);return void 0===n&&le(303,e.name),n.getExtensionDependency()}function Ke(t,e){const n=$e.maybeFromEditor(t);if(!n)return;const i=n.extensionNameMap.get(e);return i?i.getExtensionDependency():void 0}function ze(t,e){const n=Ke(t,e);return void 0===n&&le(291,e),n}function Ue(t){return je(M(),t)}function Te(t){return Ue(t).output}function Be(t){return Ke(M(),t)}const We=new Set,Ve=t({build(t,e,n){const i=n.getDependency(ue).output,o=At({watchedNodeKeys:new Map}),r=de(()=>{},()=>Wt(()=>{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=k(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=Kt(()=>(r.value||We).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:[ue],name:"@lexical/extension/NodeSelection"}),Ge=j("INSERT_HORIZONTAL_RULE_COMMAND");class Ze extends p{static getType(){return"horizontalrule"}static clone(t){return new Ze(t.__key)}static importJSON(t){return He().updateFromJSON(t)}static importDOM(){return{hr:()=>({conversion:Je,priority:0})}}exportDOM(){return{element:document.createElement("hr")}}createDOM(t){const e=document.createElement("hr");return $(e,t.theme.hr),e}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}}function Je(){return{node:He()}}function He(){return _(Ze)}function Ye(t){return t instanceof Ze}const qe=t({dependencies:[ue,Ve],name:"@lexical/extension/HorizontalRule",nodes:()=>[Ze],register(t,e,n){const{watchNodeKey:o}=n.getDependency(Ve).output,r=At({nodeSelections:new Map}),a=t._config.theme.hrSelected??"selected";return I(t.registerCommand(Ge,t=>{const e=s();if(!c(e))return!1;if(null!==e.focus.getNode()){const t=He();mt(t)}return!0},i),t.registerCommand(A,t=>{if(P(t.target)){const e=L(t.target);if(Ye(e))return function(t,e=!1){const n=s(),i=t.isSelected(),o=t.getKey();let r;e&&h(n)?r=n:(r=K(),z(r)),i?r.delete(o):r.add(o)}(e,t.shiftKey),!0}return!1},g),t.registerMutationListener(Ze,(e,n)=>{bt(()=>{let n=!1;const{nodeSelections:i}=r.peek();for(const[s,r]of e.entries())if("destroyed"===r)i.delete(s),n=!0;else{const e=i.get(s),r=t.getElementByKey(s);e?e.domNode.value=r:(n=!0,i.set(s,{domNode:At(r),selectedSignal:o(s)}))}n&&(r.value={nodeSelections:i})})}),Wt(()=>{const t=[];for(const{domNode:e,selectedSignal:n}of r.value.nodeSelections.values())t.push(Wt(()=>{const t=e.value;if(t){n.value?$(t,a):U(t,a)}}));return I(...t)}))}});const Qe=t({build:(t,e)=>Vt({inheritEditableFromParent:e.inheritEditableFromParent}),config:e({$getParentEditor:function(){const t=M();return $e.fromEditor(t),t},inheritEditableFromParent:!1}),init:(t,e,n)=>{const i=e.$getParentEditor();t.parentEditor=i,t.theme=t.theme||i._config.theme},name:"@lexical/extension/NestedEditor",register:(t,e,n)=>Wt(()=>{const e=t._parentEditor;if(e&&n.getOutput().inheritEditableFromParent.value)return t.setEditable(e.isEditable()),e.registerEditableListener(t.setEditable.bind(t))})});function Xe(t){d(t)&&t.isInline()&&t.isEmpty()&&t.remove()}const tn=t({build:(t,e,n)=>Vt(e),config:e({disabled:!1}),name:"@lexical/NormalizeInlineElements",register:(t,e,n)=>{const i=n.getOutput();return Wt(()=>{if(!i.disabled.value){const e=[];for(const{klass:n,transforms:i}of t._nodes.values())n.prototype instanceof T&&n.prototype.isInline!==T.prototype.isInline&&(i.add(Xe),e.push(()=>i.delete(Xe)));return()=>e.forEach(t=>t())}})}}),en=new Set([ot,st]);const nn=t({build:(t,e,n)=>Vt(e),config:e({$fixFocusOverselection:function(){const t=s();if(c(t)&&!t.isCollapsed()){const e=B(W(t),"next");let n=e.focus;for(V(n)&&e.anchor.origin!==n.origin&&0===n.offset&&(n=G(n.getSiblingCaret())),Z(n)&&e.anchor.origin!==n.origin&&J(n.origin)&&(n=G(n));H(n)&&e.anchor.origin!==n.origin;)n=G(Y(n.origin,"next"));if(Z(n)&&d(n.origin)&&(n=q(Q(n.origin,"previous")).getFlipped()),n=q(n),!n.isSamePointCaret(e.focus)){const t=X(tt(e.anchor,n)),i=M().getRootElement(),o=i&&et(i.ownerDocument.defaultView);o&&nt(it(),t,M(),o,en,i)}}},dateNow:Date.now,disabled:!1,thresholdMsec:100}),name:"@lexical/NormalizeTripleClickSelection",register:(t,e,n)=>Wt(()=>{const e=n.getOutput();if(!e.disabled.value)return t.registerRootListener(n=>{if(!n)return;let i=0;const o=t=>{if(t?3===t.detail:i>0){const n=e.dateNow.peek()();i=t&&"mousedown"===t.type||n-i<=e.thresholdMsec.peek()?n:0}return i};return I(t.registerCommand(rt,()=>(o(null)&&(i=0,e.$fixFocusOverselection.peek()()),!1),ct),(()=>{const t=["mouseup","mousedown"];return t.forEach(t=>n.addEventListener(t,o,!0)),()=>t.forEach(t=>n.removeEventListener(t,o,!0))})())})})}),on=t({build:(t,e,n)=>Vt(e),config:e({disabled:!1,onReposition:void 0}),name:"@lexical/utils/SelectionAlwaysOnDisplay",register:(t,e,n)=>{const i=n.getOutput();return Wt(()=>{if(!i.disabled.value)return vt(t,i.onReposition.value)})}});function sn(t){return t.canIndent()}function rn(t,e,n=sn){return I(t.registerCommand(at,e=>{const n=s();if(!c(n))return!1;e.preventDefault();const i=function(t){if(t.getNodes().filter(t=>ht(t)&&t.canIndent()).length>0)return!0;const e=t.anchor,n=t.focus,i=n.isBefore(e)?n:e,o=i.getNode(),s=xt(o);if(s.canIndent()){const t=s.getKey();let e=gt();if(e.anchor.set(t,0,"element"),e.focus.set(t,0,"element"),e=pt(e),e.anchor.is(i))return!0}return!1}(n)?e.shiftKey?dt:ut:lt;return t.dispatchCommand(i,void 0)},i),t.registerCommand(ut,()=>{const t="number"==typeof e?e:e?e.peek():null,i=s();if(!c(i))return!1;const o="function"==typeof n?n:n.peek();return Et(e=>{if(o(e)){const n=e.getIndent()+1;(!t||n<t)&&e.setIndent(n)}})},ft))}const cn=t({build:(t,e,n)=>Vt(e),config:e({$canIndent:sn,disabled:!1,maxIndent:null}),name:"@lexical/extension/TabIndentation",register(t,e,n){const{disabled:i,maxIndent:o,$canIndent:s}=n.getOutput();return Wt(()=>{if(!i.value)return rn(t,o,s)})}}),an=t({build:t=>de(()=>t.isEditable(),e=>t.registerEditableListener(t=>{e.value=t})),name:"@lexical/extension/WatchEditable"});export{He as $createHorizontalRuleNode,Yt as $defaultShouldInsertAfter,Ue as $getExtensionDependency,Te as $getExtensionOutput,Be as $getPeerDependency,ie as $isDecoratorTextNode,Ye as $isHorizontalRuleNode,Gt as AutoFocusExtension,Ht as ClearEditorExtension,Qt as ClickAfterLastBlockExtension,ae as DecoratorTextExtension,ne as DecoratorTextNode,ue as EditorStateExtension,qe as HorizontalRuleExtension,Ze as HorizontalRuleNode,Ge as INSERT_HORIZONTAL_RULE_COMMAND,Ie as InitialStateExtension,$e as LexicalBuilder,Qe as NestedEditorExtension,Ve as NodeSelectionExtension,tn as NormalizeInlineElementsExtension,nn as NormalizeTripleClickSelectionExtension,on as SelectionAlwaysOnDisplayExtension,cn as TabIndentationExtension,an as WatchEditableExtension,oe as applyFormatFromStyle,se as applyFormatToDom,bt as batch,ke as buildEditorFromExtensions,Kt as computed,Wt as effect,je as getExtensionDependencyFromEditor,Xt as getKnownTypesAndNodes,Ke as getPeerDependencyFromEditor,ze as getPeerDependencyFromEditorOrThrow,Vt as namedSignals,Jt as registerClearEditor,rn as registerTabIndentation,At as signal,Ot as untracked,de as watchedSignal};
|
|
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,$isDecoratorNode as a,$isElementNode as d,stopLexicalPropagation as u,getStaticNodeConfig as l,FORMAT_TEXT_COMMAND as f,$isNodeSelection as h,COMMAND_PRIORITY_LOW as g,DecoratorNode as p,$getState as m,toggleTextFormatType as v,$setState as E,TEXT_TYPE_TO_FORMAT as x,createState as y,shallowMergeConfig as S,RootNode as b,TextNode as w,LineBreakNode as N,TabNode as O,ParagraphNode as C,$isEditorState as R,HISTORY_MERGE_TAG as D,createEditor as I,mergeRegister as F,$getEditor as M,$getNodeByKey as _,$create as k,CLICK_COMMAND as A,isDOMNode as L,$getNodeFromDOMNode as P,addClassNamesToElement as $,createCommand as j,$createNodeSelection as K,$setSelection as z,removeClassNamesFromElement as U,COMPOSITION_START_COMMAND as T,COMMAND_PRIORITY_BEFORE_EDITOR as B,COMPOSITION_START_TAG as W,$isTextNode as V,ElementNode as G,$getCaretRangeInDirection as Z,$caretRangeFromSelection as J,$isTextPointCaret as H,$rewindSiblingCaret as Y,$isSiblingCaret as q,$isLineBreakNode as Q,$isChildCaret as X,$getSiblingCaret as tt,$normalizeCaret as et,$getChildCaret as nt,$setSelectionFromCaretRange as it,$getCaretRange as ot,getDOMSelection as st,$updateDOMSelection as rt,$getPreviousSelection as ct,SKIP_SELECTION_FOCUS_TAG as at,SKIP_SCROLL_INTO_VIEW_TAG as dt,SELECTION_CHANGE_COMMAND as ut,COMMAND_PRIORITY_BEFORE_CRITICAL as lt,KEY_TAB_COMMAND as ft,OUTDENT_CONTENT_COMMAND as ht,INDENT_CONTENT_COMMAND as gt,INSERT_TAB_COMMAND as pt,COMMAND_PRIORITY_CRITICAL as mt,$isBlockElementNode as vt,$createRangeSelection as Et,$normalizeSelection__EXPERIMENTAL as xt}from"lexical";export{configExtension,declarePeerDependency,defineExtension,safeCast,shallowMergeConfig}from"lexical";import{$insertNodeToNearestRoot as yt,mergeRegister as St,selectionAlwaysOnDisplay as bt,$handleIndentAndOutdent as wt,$getNearestBlockElementAncestorOrThrow as Nt}from"@lexical/utils";const Ot=Symbol.for("preact-signals");function Ct(){if(_t>1)return void _t--;let t,e=!1;for(!function(){let t=Mt;for(Mt=void 0;void 0!==t;)t.S.v===t.v&&(t.S.i=t.i),t=t.o}();void 0!==It;){let n=It;for(It=void 0,kt++;void 0!==n;){const i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&zt(n))try{n.c()}catch(n){e||(t=n,e=!0)}n=i}}if(kt=0,_t--,e)throw t}function Rt(t){if(_t>0)return t();Lt=++At,_t++;try{return t()}finally{Ct()}}let Dt,It;function Ft(t){const e=Dt;Dt=void 0;try{return t()}finally{Dt=e}}let Mt,_t=0,kt=0,At=0,Lt=0,Pt=0;function $t(t){if(void 0===Dt)return;let e=t.n;return void 0===e||e.t!==Dt?(e={i:0,S:t,p:Dt.s,n:void 0,t:Dt,e:void 0,x:void 0,r:e},void 0!==Dt.s&&(Dt.s.n=e),Dt.s=e,t.n=e,32&Dt.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=Dt.s,e.n=void 0,Dt.s.n=e,Dt.s=e),e):void 0}function jt(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=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 Kt(t,e){return new jt(t,e)}function zt(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 Ut(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 Tt(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 Bt(t,e){jt.call(this,void 0),this.x=t,this.s=void 0,this.g=Pt-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 Wt(t,e){return new Bt(t,e)}function Vt(t){const e=t.m;if(t.m=void 0,"function"==typeof e){_t++;const n=Dt;Dt=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,Gt(t),e}finally{Dt=n,Ct()}}}function Gt(t){for(let e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,Vt(t)}function Zt(t){if(Dt!==this)throw new Error("Out-of-order effect");Tt(this),Dt=t,this.f&=-2,8&this.f&&Gt(this),Ct()}function Jt(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=null==e?void 0:e.name}function Ht(t,e){const n=new Jt(t,e);try{n.c()}catch(t){throw n.d(),t}const i=n.d.bind(n);return i[Symbol.dispose]=i,i}function Yt(t,e={}){const n={};for(const i in t){const o=e[i],s=Kt(void 0===o?t[i]:o);n[i]=s}return n}jt.prototype.brand=Ot,jt.prototype.h=function(){return!0},jt.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:Ft(()=>{var t;null==(t=this.W)||t.call(this)}))},jt.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&&Ft(()=>{var t;null==(t=this.Z)||t.call(this)}))}},jt.prototype.subscribe=function(t){return Ht(()=>{const e=this.value,n=Dt;Dt=void 0;try{t(e)}finally{Dt=n}},{name:"sub"})},jt.prototype.valueOf=function(){return this.value},jt.prototype.toString=function(){return this.value+""},jt.prototype.toJSON=function(){return this.value},jt.prototype.peek=function(){const t=Dt;Dt=void 0;try{return this.value}finally{Dt=t}},Object.defineProperty(jt.prototype,"value",{get(){const t=$t(this);return void 0!==t&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(kt>100)throw new Error("Cycle detected");!function(t){0!==_t&&0===kt&&t.l!==Lt&&(t.l=Lt,Mt={S:t,v:t.v,i:t.i,o:Mt})}(this),this.v=t,this.i++,Pt++,_t++;try{for(let t=this.t;void 0!==t;t=t.x)t.t.N()}finally{Ct()}}}}),Bt.prototype=new jt,Bt.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===Pt)return!0;if(this.g=Pt,this.f|=1,this.i>0&&!zt(this))return this.f&=-2,!0;const t=Dt;try{Ut(this),Dt=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 Dt=t,Tt(this),this.f&=-2,!0},Bt.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)}jt.prototype.S.call(this,t)},Bt.prototype.U=function(t){if(void 0!==this.t&&(jt.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)}},Bt.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(Bt.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=$t(this);if(this.h(),void 0!==t&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),Jt.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.m=t)}finally{t()}},Jt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Vt(this),Ut(this),_t++;const t=Dt;return Dt=this,Zt.bind(this,t)},Jt.prototype.N=function(){2&this.f||(this.f|=2,this.u=It,It=this)},Jt.prototype.d=function(){this.f|=8,1&this.f||Gt(this)},Jt.prototype.dispose=function(){this.d()};const qt=t({build:(t,e,n)=>Yt(e),config:e({defaultSelection:"rootEnd",disabled:!1}),name:"@lexical/extension/AutoFocus",register(t,e,n){const i=n.getOutput();return Ht(()=>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 Qt(){const t=o(),e=s(),n=r();t.clear(),t.append(n),null!==e&&n.select(),c(e)&&(e.format=0)}function Xt(t,e=Qt){return t.registerCommand(n,n=>(t.update(e),!0),i)}const te=t({build:(t,e,n)=>Yt(e),config:e({$onClear:Qt}),name:"@lexical/extension/ClearEditor",register(t,e,n){const{$onClear:i}=n.getOutput();return Ht(()=>Xt(t,i.value))}});function ee(t){return!!a(t)||!(!d(t)||!t.isShadowRoot())}function ne(t,e,n,i){return!!t.isEditable()&&(n.target===e&&t.getEditorState().read(()=>{const e=o().getLastChild();if(null===e)return!1;const s=t.getElementByKey(e.getKey());return null!==s&&(!(n.clientY<=s.getBoundingClientRect().bottom)&&i(e))},{editor:t}))}const ie=t({build:(t,e)=>Yt(e),config:e({$shouldInsertAfter:ee,disabled:!1}),name:"@lexical/ClickAfterLastBlock",register:(t,e,n)=>Ht(()=>{const e=n.getOutput();if(!e.disabled.value)return t.registerRootListener(n=>{if(null===n)return;const i=i=>{ne(t,n,i,e.$shouldInsertAfter.peek())&&i.preventDefault()},s=i=>{ne(t,n,i,e.$shouldInsertAfter.peek())&&(i.preventDefault(),u(i),t.update(()=>{const t=o().getLastChild();if(null===t)return;if(!e.$shouldInsertAfter.peek()(t))return;const n=r();t.insertAfter(n),n.select()}))};return n.addEventListener("mousedown",i,!0),n.addEventListener("click",s,!0),()=>{n.removeEventListener("mousedown",i,!0),n.removeEventListener("click",s,!0)}})})});function oe(t){const e=new Set,n=new Set;for(const i of se(t)){const t="function"==typeof i?i:i.replace;l(t),e.add(t.getType()),n.add(t)}return{nodes:n,types:e}}function se(t){return("function"==typeof t.nodes?t.nodes():t.nodes)||[]}const re=y("format",{parse:t=>"number"==typeof t?t:0});class ce extends p{$config(){return this.config("decorator-text",{extends:p,stateConfigs:[{flat:!0,stateConfig:re}]})}getFormat(){return m(this,re)}getFormatFlags(t,e){return v(this.getFormat(),t,e)}hasFormat(t){const e=x[t];return 0!==(this.getFormat()&e)}setFormat(t){return E(this,re,t)}toggleFormat(t){const e=this.getFormat(),n=v(e,t,null);return this.setFormat(n)}isInline(){return!0}createDOM(){return document.createElement("span")}updateDOM(){return!1}}function ae(t){return t instanceof ce}function de(t,e,n){const i=e.fontWeight,o=e.textDecoration.split(" "),s="700"===i||"bold"===i,r=o.includes("line-through"),c="italic"===e.fontStyle,a=o.includes("underline"),d=e.verticalAlign;return s&&!t.hasFormat("bold")&&t.toggleFormat("bold"),r&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),c&&!t.hasFormat("italic")&&t.toggleFormat("italic"),a&&!t.hasFormat("underline")&&t.toggleFormat("underline"),"sub"!==d||t.hasFormat("subscript")||t.toggleFormat("subscript"),"super"!==d||t.hasFormat("superscript")||t.toggleFormat("superscript"),n&&!t.hasFormat(n)&&t.toggleFormat(n),t}function ue(t,e,n=fe){for(const[i,o]of Object.entries(n))t.hasFormat(o)&&(e=le(e,i));return e}function le(t,e){const n=document.createElement(e);return n.appendChild(t),n}const fe={b:"bold",code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"},he=t({name:"@lexical/extension/DecoratorText",nodes:()=>[ce],register:(t,e,n)=>t.registerCommand(f,t=>{const e=s();if(h(e)||c(e))for(const n of e.getNodes())ae(n)&&n.toggleFormat(t);return!1},g)});function ge(t,e){let n;return Kt(t(),{unwatched(){n&&(n(),n=void 0)},watched(){this.value=t(),n=e(this)}})}const pe=t({build:t=>ge(()=>t.getEditorState(),e=>t.registerUpdateListener(t=>{e.value=t.editorState})),name:"@lexical/extension/EditorState"});function me(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.`)}let ve;try{ve="0.45.1-nightly.20260531.0+prod.esm"}catch(t){}const Ee=ve??"0.45.1-nightly.20260531.0+source",xe=new Set(["__proto__","constructor","prototype"]);function ye(t,e){if(t&&e&&!Array.isArray(e)&&"object"==typeof t&&"object"==typeof e){const n=t,i=e;for(const t in i)!xe.has(t)&&Object.prototype.hasOwnProperty.call(i,t)&&(n[t]=ye(n[t],i[t]));return t}return e}const Se=0,be=1,we=2,Ne=3,Oe=4,Ce=5,Re=6,De=7;function Ie(t){return t.id===Se}function Fe(t){return t.id===we}function Me(t){return function(t){return t.id===be}(t)||me(305,String(t.id),String(be)),Object.assign(t,{id:we})}const _e=new Set;class ke{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(t,e){this.builder=t,this.extension=e,this.configs=new Set,this.state={id:Se}}mergeConfigs(){let t=this.extension.config||{};const e=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):S;for(const n of this.configs)t=e(t,n);return t}init(t){const e=this.state;Fe(e)||me(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:Ne,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:Oe,initResult:e,registerState:n})}(o,s,i)}build(t){const e=this.state;let n;e.id!==Oe&&me(307,String(e.id),String(Ce)),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:Ce,output:e,registerState:n})}(e,n,i)}register(t,e){this._signal=e;const n=this.state;n.id!==Ce&&me(308,String(n.id),String(Ce));const i=this.extension.register&&this.extension.register(t,n.config,n.registerState);return this.state=function(t){return Object.assign(t,{id:Re})}(n),()=>{const t=this.state;t.id!==De&&me(309,String(n.id),String(De)),this.state=function(t){return Object.assign(t,{id:Ce})}(t),i&&i()}}afterRegistration(t){const e=this.state;let n;return e.id!==Re&&me(310,String(e.id),String(Re)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(t,e.config,e.registerState)),this.state=function(t){return Object.assign(t,{id:De})}(e),n}getSignal(){return void 0===this._signal&&me(311),this._signal}getInitResult(){void 0===this.extension.init&&me(312,this.extension.name);const t=this.state;return function(t){return t.id>=Oe}(t)||me(313,String(t.id),String(Oe)),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>=Ne}(t)||me(314,String(t.id),String(Ne)),{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&&me(315,this.extension.name,t.name),e.getExtensionInitDependency()}getDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&me(315,this.extension.name,t.name),e.getExtensionDependency()}getState(){const t=this.state;return function(t){return t.id>=De}(t)||me(316,String(t.id),String(De)),t}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||_e}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>=Ce})(t)||me(317,this.extension.name),this._dependency={config:t.config,init:t.initResult,output:t.output}}return this._dependency}}const Ae={tag:D};function Le(){const t=o();t.isEmpty()&&t.append(r())}const Pe=t({config:e({setOptions:Ae,updateOptions:Ae}),init:({$initialEditorState:t=Le})=>({$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(R(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:"@lexical/extension/InitialState",nodes:[b,w,N,O,C]}),$e=Symbol.for("@lexical/extension/LexicalBuilder");function je(...t){return Be.fromExtensions(t).buildEditor()}function Ke(){}function ze(t){throw t}function Ue(t){return Array.isArray(t)?t:[t]}const Te=Ee;class Be{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=Te,this.roots=t;for(const e of t)this.addExtension(e)}static fromExtensions(t){const e=[Ue(Pe)];for(const n of t)e.push(Ue(n));return new Be(e)}static maybeFromEditor(t){const e=t[$e];return e&&(e.PACKAGE_VERSION!==Te&&me(292,e.PACKAGE_VERSION,Te),e instanceof Be||me(293)),e}static fromEditor(t){const e=Be.maybeFromEditor(t);return void 0===e&&me(294),e}constructEditor(){const{$initialEditorState:t,onError:e,...n}=this.buildCreateEditorArgs(),i=Object.assign(I({...n,...e?{onError:t=>{e(t,i)}}:{}}),{[$e]:this});for(const t of this.sortedExtensionReps())t.build(i);return i}buildEditor(){let t=Ke;function e(){try{t()}finally{t=Ke}}const n=Object.assign(this.constructEditor(),{dispose:e,[Symbol.dispose]:e});return t=F(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&&me(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&&me(296);const e=Ue(t),[n]=e;"string"!=typeof n.name&&me(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&me(298,n.name),!i){i=new ke(this,n),this.extensionNameMap.set(n.name,i);const t=this.conflicts.get(n.name);"string"==typeof t&&me(299,n.name,t);for(const t of n.conflictsWith||[])this.extensionNameMap.has(t)&&me(299,n.name,t),this.conflicts.set(t,n.name);for(const t of n.dependencies||[]){const e=Ue(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(Fe(o))return;const s=n.extension.name;var r;Ie(o)||me(300,s,i||"[unknown]"),Ie(r=o)||me(304,String(r.id),String(Se)),o=Object.assign(r,{id:be}),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=Me(o),n.state=o,t.push(n)};for(const t of this.extensionNameMap.values())Ie(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&&me(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 F(...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 se(r)){if("function"!=typeof t){const e=n.get(t.replace);e&&me(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&&ye(s,r.theme)}Object.keys(s).length>0&&(t.theme=s),e.size&&(t.nodes=[...e]);const c=Object.keys(o).length>0,a=i.size>0;(c||a)&&(t.html={},c&&(t.html.import=o),a&&(t.html.export=i));for(const e of r)e.init(t);return t.onError||(t.onError=ze),t}}function We(t,e){const n=Be.fromEditor(t).getExtensionRep(e);return void 0===n&&me(303,e.name),n.getExtensionDependency()}function Ve(t,e){const n=Be.maybeFromEditor(t);if(!n)return;const i=n.extensionNameMap.get(e);return i?i.getExtensionDependency():void 0}function Ge(t,e){const n=Ve(t,e);return void 0===n&&me(291,e),n}function Ze(t){return We(M(),t)}function Je(t){return Ze(t).output}function He(t){return Ve(M(),t)}const Ye=new Set,qe=t({build(t,e,n){const i=n.getDependency(pe).output,o=Kt({watchedNodeKeys:new Map}),r=ge(()=>{},()=>Ht(()=>{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=_(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=Wt(()=>(r.value||Ye).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:[pe],name:"@lexical/extension/NodeSelection"}),Qe=j("INSERT_HORIZONTAL_RULE_COMMAND");class Xe extends p{static getType(){return"horizontalrule"}static clone(t){return new Xe(t.__key)}static importJSON(t){return en().updateFromJSON(t)}static importDOM(){return{hr:()=>({conversion:tn,priority:0})}}exportDOM(){return{element:document.createElement("hr")}}createDOM(t){const e=document.createElement("hr");return $(e,t.theme.hr),e}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}}function tn(){return{node:en()}}function en(){return k(Xe)}function nn(t){return t instanceof Xe}const on=t({dependencies:[pe,qe],name:"@lexical/extension/HorizontalRule",nodes:()=>[Xe],register(t,e,n){const{watchNodeKey:o}=n.getDependency(qe).output,r=Kt({nodeSelections:new Map}),a=t._config.theme.hrSelected??"selected";return F(t.registerCommand(Qe,t=>{const e=s();if(!c(e))return!1;if(null!==e.focus.getNode()){const t=en();yt(t)}return!0},i),t.registerCommand(A,t=>{if(L(t.target)){const e=P(t.target);if(nn(e))return function(t,e=!1){const n=s(),i=t.isSelected(),o=t.getKey();let r;e&&h(n)?r=n:(r=K(),z(r)),i?r.delete(o):r.add(o)}(e,t.shiftKey),!0}return!1},g),t.registerMutationListener(Xe,(e,n)=>{Rt(()=>{let n=!1;const{nodeSelections:i}=r.peek();for(const[s,r]of e.entries())if("destroyed"===r)i.delete(s),n=!0;else{const e=i.get(s),r=t.getElementByKey(s);e?e.domNode.value=r:(n=!0,i.set(s,{domNode:Kt(r),selectedSignal:o(s)}))}n&&(r.value={nodeSelections:i})})}),Ht(()=>{const t=[];for(const{domNode:e,selectedSignal:n}of r.value.nodeSelections.values())t.push(Ht(()=>{const t=e.value;if(t){n.value?$(t,a):U(t,a)}}));return F(...t)}))}}),sn=t({build:t=>({composingTextNode:Kt(null),compositionKey:Kt(null)}),name:"@lexical/extension/IME",register(t,e,n){const{compositionKey:i,composingTextNode:o}=n.getOutput(),r=t.registerCommand(T,()=>{const t=s();return c(t)&&(i.value=t.anchor.key),!1},B),a=Ht(()=>{const e=i.value;o.value=null!==e?t.getEditorState().read(()=>{const t=_(e);return V(t)?t:null}):null}),d=t.registerUpdateListener(({tags:t,editorState:e})=>{t.has(W)&&e.read(()=>{const t=s();if(!c(t))return;const e=t.anchor.getNode();V(e)&&(o.value=e)})}),u=t.registerRootListener(t=>{if(null===t)return void(i.value=null);const e=()=>{i.value=null};return t.addEventListener("compositionend",e),()=>{t.removeEventListener("compositionend",e)}});return St(r,a,d,u)}});const rn=t({build:(t,e)=>Yt({inheritEditableFromParent:e.inheritEditableFromParent}),config:e({$getParentEditor:function(){const t=M();return Be.fromEditor(t),t},inheritEditableFromParent:!1}),init:(t,e,n)=>{const i=e.$getParentEditor();t.parentEditor=i,t.theme=t.theme||i._config.theme},name:"@lexical/extension/NestedEditor",register:(t,e,n)=>Ht(()=>{const e=t._parentEditor;if(e&&n.getOutput().inheritEditableFromParent.value)return t.setEditable(e.isEditable()),e.registerEditableListener(t.setEditable.bind(t))})});function cn(t){d(t)&&t.isInline()&&t.isEmpty()&&t.remove()}const an=t({build:(t,e,n)=>Yt(e),config:e({disabled:!1}),name:"@lexical/NormalizeInlineElements",register:(t,e,n)=>{const i=n.getOutput();return Ht(()=>{if(!i.disabled.value){const e=[];for(const{klass:n,transforms:i}of t._nodes.values())n.prototype instanceof G&&n.prototype.isInline!==G.prototype.isInline&&(i.add(cn),e.push(()=>i.delete(cn)));return()=>e.forEach(t=>t())}})}}),dn=new Set([at,dt]);const un=t({build:(t,e,n)=>Yt(e),config:e({$fixFocusOverselection:function(){const t=s();if(c(t)&&!t.isCollapsed()){const e=Z(J(t),"next");let n=e.focus;for(H(n)&&e.anchor.origin!==n.origin&&0===n.offset&&(n=Y(n.getSiblingCaret())),q(n)&&e.anchor.origin!==n.origin&&Q(n.origin)&&(n=Y(n));X(n)&&e.anchor.origin!==n.origin;)n=Y(tt(n.origin,"next"));if(q(n)&&d(n.origin)&&(n=et(nt(n.origin,"previous")).getFlipped()),n=et(n),!n.isSamePointCaret(e.focus)){const t=it(ot(e.anchor,n)),i=M().getRootElement(),o=i&&st(i.ownerDocument.defaultView);o&&rt(ct(),t,M(),o,dn,i)}}},dateNow:Date.now,disabled:!1,thresholdMsec:100}),name:"@lexical/NormalizeTripleClickSelection",register:(t,e,n)=>Ht(()=>{const e=n.getOutput();if(!e.disabled.value)return t.registerRootListener(n=>{if(!n)return;let i=0;const o=t=>{if(t?3===t.detail:i>0){const n=e.dateNow.peek()();i=t&&"mousedown"===t.type||n-i<=e.thresholdMsec.peek()?n:0}return i};return F(t.registerCommand(ut,()=>(o(null)&&(i=0,e.$fixFocusOverselection.peek()()),!1),lt),(()=>{const t=["mouseup","mousedown"];return t.forEach(t=>n.addEventListener(t,o,!0)),()=>t.forEach(t=>n.removeEventListener(t,o,!0))})())})})}),ln=t({build:(t,e,n)=>Yt(e),config:e({disabled:!1,onReposition:void 0}),name:"@lexical/utils/SelectionAlwaysOnDisplay",register:(t,e,n)=>{const i=n.getOutput();return Ht(()=>{if(!i.disabled.value)return bt(t,i.onReposition.value)})}});function fn(t){return t.canIndent()}function hn(t,e,n=fn){return F(t.registerCommand(ft,e=>{const n=s();if(!c(n))return!1;e.preventDefault();const i=function(t){if(t.getNodes().filter(t=>vt(t)&&t.canIndent()).length>0)return!0;const e=t.anchor,n=t.focus,i=n.isBefore(e)?n:e,o=i.getNode(),s=Nt(o);if(s.canIndent()){const t=s.getKey();let e=Et();if(e.anchor.set(t,0,"element"),e.focus.set(t,0,"element"),e=xt(e),e.anchor.is(i))return!0}return!1}(n)?e.shiftKey?ht:gt:pt;return t.dispatchCommand(i,void 0)},i),t.registerCommand(gt,()=>{const t="number"==typeof e?e:e?e.peek():null,i=s();if(!c(i))return!1;const o="function"==typeof n?n:n.peek();return wt(e=>{if(o(e)){const n=e.getIndent()+1;(!t||n<t)&&e.setIndent(n)}})},mt))}const gn=t({build:(t,e,n)=>Yt(e),config:e({$canIndent:fn,disabled:!1,maxIndent:null}),name:"@lexical/extension/TabIndentation",register(t,e,n){const{disabled:i,maxIndent:o,$canIndent:s}=n.getOutput();return Ht(()=>{if(!i.value)return hn(t,o,s)})}}),pn=t({build:t=>ge(()=>t.isEditable(),e=>t.registerEditableListener(t=>{e.value=t})),name:"@lexical/extension/WatchEditable"});export{en as $createHorizontalRuleNode,ee as $defaultShouldInsertAfter,Ze as $getExtensionDependency,Je as $getExtensionOutput,He as $getPeerDependency,ae as $isDecoratorTextNode,nn as $isHorizontalRuleNode,qt as AutoFocusExtension,te as ClearEditorExtension,ie as ClickAfterLastBlockExtension,he as DecoratorTextExtension,ce as DecoratorTextNode,pe as EditorStateExtension,on as HorizontalRuleExtension,Xe as HorizontalRuleNode,sn as IMEExtension,Qe as INSERT_HORIZONTAL_RULE_COMMAND,Pe as InitialStateExtension,Be as LexicalBuilder,rn as NestedEditorExtension,qe as NodeSelectionExtension,an as NormalizeInlineElementsExtension,un as NormalizeTripleClickSelectionExtension,ln as SelectionAlwaysOnDisplayExtension,gn as TabIndentationExtension,pn as WatchEditableExtension,de as applyFormatFromStyle,ue as applyFormatToDom,Rt as batch,je as buildEditorFromExtensions,Wt as computed,Ht as effect,We as getExtensionDependencyFromEditor,oe as getKnownTypesAndNodes,Ve as getPeerDependencyFromEditor,Ge as getPeerDependencyFromEditorOrThrow,Yt as namedSignals,Xt as registerClearEditor,hn as registerTabIndentation,Kt as signal,Ft as untracked,ge as watchedSignal};
|
|
@@ -5,20 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
/**
|
|
9
|
-
* Recursively merge the given theme configuration in-place.
|
|
10
|
-
*
|
|
11
|
-
* @returns If `a` and `b` are both objects (and `b` is not an Array) then
|
|
12
|
-
* all keys in `b` are merged into `a` then `a` is returned.
|
|
13
|
-
* Otherwise `b` is returned.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const a = { a: "a", nested: { a: 1 } };
|
|
18
|
-
* const b = { b: "b", nested: { b: 2 } };
|
|
19
|
-
* const rval = deepThemeMergeInPlace(a, b);
|
|
20
|
-
* expect(a).toBe(rval);
|
|
21
|
-
* expect(a).toEqual({ a: "a", b: "b", nested: { a: 1, b: 2 } });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
8
|
export declare function deepThemeMergeInPlace(a: unknown, b: unknown): unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { $getExtensionDependency, $getExtensionOutput, $getPeerDependency, } fro
|
|
|
15
15
|
export { getExtensionDependencyFromEditor } from './getExtensionDependencyFromEditor';
|
|
16
16
|
export { getPeerDependencyFromEditor, getPeerDependencyFromEditorOrThrow, } from './getPeerDependencyFromEditor';
|
|
17
17
|
export { $createHorizontalRuleNode, $isHorizontalRuleNode, HorizontalRuleExtension, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND, type SerializedHorizontalRuleNode, } from './HorizontalRuleExtension';
|
|
18
|
+
export { IMEExtension } from './IMEExtension';
|
|
18
19
|
export { type InitialStateConfig, InitialStateExtension, } from './InitialStateExtension';
|
|
19
20
|
export { buildEditorFromExtensions, LexicalBuilder } from './LexicalBuilder';
|
|
20
21
|
export { namedSignals, type NamedSignalsOptions, type NamedSignalsOutput, } from './namedSignals';
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"extension",
|
|
7
7
|
"plugin"
|
|
8
8
|
],
|
|
9
|
-
"version": "0.45.1-
|
|
9
|
+
"version": "0.45.1-nightly.20260531.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"module": "./dist/LexicalExtension.mjs",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@preact/signals-core": "^1.14.1",
|
|
27
|
-
"@lexical/internal": "0.45.1-
|
|
28
|
-
"@lexical/utils": "0.45.1-
|
|
29
|
-
"lexical": "0.45.1-
|
|
27
|
+
"@lexical/internal": "0.45.1-nightly.20260531.0",
|
|
28
|
+
"@lexical/utils": "0.45.1-nightly.20260531.0",
|
|
29
|
+
"lexical": "0.45.1-nightly.20260531.0"
|
|
30
30
|
},
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
|
@@ -0,0 +1,142 @@
|
|
|
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 {mergeRegister} from '@lexical/utils';
|
|
10
|
+
import {
|
|
11
|
+
$getNodeByKey,
|
|
12
|
+
$getSelection,
|
|
13
|
+
$isRangeSelection,
|
|
14
|
+
$isTextNode,
|
|
15
|
+
COMMAND_PRIORITY_BEFORE_EDITOR,
|
|
16
|
+
COMPOSITION_START_COMMAND,
|
|
17
|
+
COMPOSITION_START_TAG,
|
|
18
|
+
defineExtension,
|
|
19
|
+
type LexicalEditor,
|
|
20
|
+
type NodeKey,
|
|
21
|
+
type TextNode,
|
|
22
|
+
} from 'lexical';
|
|
23
|
+
|
|
24
|
+
import {effect, type Signal, signal} from './signals';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Centralizes IME composition state so extensions that react to
|
|
28
|
+
* composition lifecycle don't each re-implement the
|
|
29
|
+
* COMPOSITION_START_COMMAND + compositionend listener dance.
|
|
30
|
+
*
|
|
31
|
+
* Exposes two signals (both always-active for the editor's lifetime —
|
|
32
|
+
* listeners are wired up by `register`, not lazily on subscription, so
|
|
33
|
+
* consumers can read `.value` from anywhere without holding a
|
|
34
|
+
* subscription themselves):
|
|
35
|
+
*
|
|
36
|
+
* - `compositionKey` is the raw mirror — the value Lexical's own
|
|
37
|
+
* `$handleCompositionStart` writes to its internal `_compositionKey`,
|
|
38
|
+
* i.e. the `selection.anchor.key` at the moment composition starts.
|
|
39
|
+
* This can be a non-TextNode key when composition begins on an
|
|
40
|
+
* element-anchor selection (e.g. empty paragraph). Cleared on
|
|
41
|
+
* `compositionend`.
|
|
42
|
+
*
|
|
43
|
+
* - `composingTextNode` is the resolved view — the actual TextNode
|
|
44
|
+
* being composed on, or `null` while there is no TextNode-level
|
|
45
|
+
* composition. For an element-anchor start it stays `null` until
|
|
46
|
+
* the `COMPOSITION_START_TAG`-tagged update fires with the
|
|
47
|
+
* post-ZWSP-heuristic selection, at which point it updates to the
|
|
48
|
+
* new TextNode.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
export const IMEExtension = defineExtension({
|
|
52
|
+
build(_editor: LexicalEditor): {
|
|
53
|
+
compositionKey: Signal<null | NodeKey>;
|
|
54
|
+
composingTextNode: Signal<null | TextNode>;
|
|
55
|
+
} {
|
|
56
|
+
return {
|
|
57
|
+
composingTextNode: signal<null | TextNode>(null),
|
|
58
|
+
compositionKey: signal<null | NodeKey>(null),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
name: '@lexical/extension/IME',
|
|
62
|
+
register(editor, _config, state) {
|
|
63
|
+
const {compositionKey, composingTextNode} = state.getOutput();
|
|
64
|
+
|
|
65
|
+
const removeStartCommand = editor.registerCommand(
|
|
66
|
+
COMPOSITION_START_COMMAND,
|
|
67
|
+
() => {
|
|
68
|
+
// `BEFORE_EDITOR` lands at the head of the EDITOR-priority
|
|
69
|
+
// bucket, sequenced immediately before Lexical's own
|
|
70
|
+
// EDITOR-priority `$handleCompositionStart` that calls
|
|
71
|
+
// `$setCompositionKey(anchor.key)`. Both write the same
|
|
72
|
+
// `selection.anchor.key`. The lower nominal priority keeps
|
|
73
|
+
// room for downstream extensions to override.
|
|
74
|
+
const selection = $getSelection();
|
|
75
|
+
if ($isRangeSelection(selection)) {
|
|
76
|
+
compositionKey.value = selection.anchor.key;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
},
|
|
80
|
+
COMMAND_PRIORITY_BEFORE_EDITOR,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Stage 1: react to compositionKey transitions. Resolve the key
|
|
84
|
+
// to a TextNode when possible. Element-anchor starts resolve to
|
|
85
|
+
// null here and stay null until stage 2.
|
|
86
|
+
const stopKeyEffect = effect(() => {
|
|
87
|
+
const key = compositionKey.value;
|
|
88
|
+
if (key === null) {
|
|
89
|
+
composingTextNode.value = null;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
composingTextNode.value = editor.getEditorState().read(() => {
|
|
93
|
+
const node = $getNodeByKey(key);
|
|
94
|
+
return $isTextNode(node) ? node : null;
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Stage 2: after Lexical's ZWSP heuristic inserts the actual
|
|
99
|
+
// composing TextNode for an element-anchor start, the
|
|
100
|
+
// corresponding update fires with COMPOSITION_START_TAG. The
|
|
101
|
+
// selection now points at the new TextNode — re-read it and
|
|
102
|
+
// upgrade the signal to the resolved node.
|
|
103
|
+
const removeUpdateListener = editor.registerUpdateListener(
|
|
104
|
+
({tags, editorState}) => {
|
|
105
|
+
if (!tags.has(COMPOSITION_START_TAG)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
editorState.read(() => {
|
|
109
|
+
const selection = $getSelection();
|
|
110
|
+
if (!$isRangeSelection(selection)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const node = selection.anchor.getNode();
|
|
114
|
+
if ($isTextNode(node)) {
|
|
115
|
+
composingTextNode.value = node;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const removeRootListener = editor.registerRootListener(rootElem => {
|
|
122
|
+
if (rootElem === null) {
|
|
123
|
+
compositionKey.value = null;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const onCompositionEnd = () => {
|
|
127
|
+
compositionKey.value = null;
|
|
128
|
+
};
|
|
129
|
+
rootElem.addEventListener('compositionend', onCompositionEnd);
|
|
130
|
+
return () => {
|
|
131
|
+
rootElem.removeEventListener('compositionend', onCompositionEnd);
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return mergeRegister(
|
|
136
|
+
removeStartCommand,
|
|
137
|
+
stopKeyEffect,
|
|
138
|
+
removeUpdateListener,
|
|
139
|
+
removeRootListener,
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
@@ -22,6 +22,12 @@
|
|
|
22
22
|
* expect(a).toEqual({ a: "a", b: "b", nested: { a: 1, b: 2 } });
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
+
// Keys that must never be merged: assigning or recursing through them can
|
|
26
|
+
// mutate the prototype chain (prototype pollution). A malicious `__proto__`
|
|
27
|
+
// entry — e.g. from `JSON.parse('{"__proto__": {...}}')` — would otherwise
|
|
28
|
+
// leak into `Object.prototype` and affect every object in the realm.
|
|
29
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
30
|
+
|
|
25
31
|
export function deepThemeMergeInPlace(a: unknown, b: unknown) {
|
|
26
32
|
if (
|
|
27
33
|
a &&
|
|
@@ -33,6 +39,13 @@ export function deepThemeMergeInPlace(a: unknown, b: unknown) {
|
|
|
33
39
|
const aObj = a as Record<string, unknown>;
|
|
34
40
|
const bObj = b as Record<string, unknown>;
|
|
35
41
|
for (const k in bObj) {
|
|
42
|
+
// Only merge own, prototype-safe keys.
|
|
43
|
+
if (
|
|
44
|
+
UNSAFE_KEYS.has(k) ||
|
|
45
|
+
!Object.prototype.hasOwnProperty.call(bObj, k)
|
|
46
|
+
) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
36
49
|
aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);
|
|
37
50
|
}
|
|
38
51
|
return a;
|
package/src/index.ts
CHANGED