@lexical/extension 0.50.1-nightly.20260917.0 → 0.51.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.
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Type-only smoke test for the hand-maintained `@lexical/extension` Flow
|
|
12
|
+
* declarations, in the spirit of `packages/lexical/flow/Lexical.flowtest.js.flow`:
|
|
13
|
+
* `pnpm lint-flow` checks that the names match the generated `.d.ts` and
|
|
14
|
+
* `pnpm flow` checks that the declarations are internally consistent, but
|
|
15
|
+
* neither one ever composes the API the way an application does.
|
|
16
|
+
*
|
|
17
|
+
* Everything below is what building a nested editor from extensions looks like
|
|
18
|
+
* downstream. None of it type-checked before: `dependencies` could not hold a
|
|
19
|
+
* single extension, `configExtension` could not be called, and
|
|
20
|
+
* `ReactProviderExtension` was declared nowhere at all.
|
|
21
|
+
*
|
|
22
|
+
* See that file's header for why the `.js.flow` extension is load-bearing.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type {LexicalEditor, LexicalEditorWithDispose} from 'lexical';
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
buildEditorFromExtensions,
|
|
29
|
+
configExtension,
|
|
30
|
+
defineExtension,
|
|
31
|
+
NestedEditorExtension,
|
|
32
|
+
} from '@lexical/extension';
|
|
33
|
+
import {ReactExtension} from '@lexical/react/ReactExtension';
|
|
34
|
+
import {ReactProviderExtension} from '@lexical/react/ReactProviderExtension';
|
|
35
|
+
|
|
36
|
+
// A dependency list holding a bare extension. `LexicalExtension` was invariant
|
|
37
|
+
// in `Name`, so no concrete extension was a subtype of the
|
|
38
|
+
// `LexicalExtension<any, string, any, any>` the list is declared over, and a
|
|
39
|
+
// single-element `dependencies` was an error.
|
|
40
|
+
const dependsOnAnExtension = defineExtension({
|
|
41
|
+
dependencies: [ReactProviderExtension],
|
|
42
|
+
name: '@lexical/flow-smoke-test/DependsOnAnExtension',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// A dependency carrying a config override. `configExtension` returns the
|
|
46
|
+
// `[extension, ...Partial<Config>[]]` tuple type, whose trailing array spread
|
|
47
|
+
// Flow rejects outright ("Cannot spread non-tuple into tuple type"), so the
|
|
48
|
+
// call could not be written at all.
|
|
49
|
+
const configuresItsDependency = defineExtension({
|
|
50
|
+
dependencies: [configExtension(ReactExtension, {contentEditable: null})],
|
|
51
|
+
name: '@lexical/flow-smoke-test/ConfiguresItsDependency',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// The same override written inline, which is the tuple the normalized argument
|
|
55
|
+
// type exists to describe.
|
|
56
|
+
const configuresInline = defineExtension({
|
|
57
|
+
dependencies: [[ReactExtension, {contentEditable: null}]],
|
|
58
|
+
name: '@lexical/flow-smoke-test/ConfiguresInline',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// `NestedEditorExtension`'s own config, and the editor a nested surface
|
|
62
|
+
// actually builds: the extension's parent hook plus React hosting.
|
|
63
|
+
export function flowBuildsNestedEditor(
|
|
64
|
+
parentEditor: LexicalEditor,
|
|
65
|
+
): LexicalEditorWithDispose {
|
|
66
|
+
return buildEditorFromExtensions(
|
|
67
|
+
defineExtension({
|
|
68
|
+
dependencies: [
|
|
69
|
+
ReactProviderExtension,
|
|
70
|
+
configExtension(ReactExtension, {contentEditable: null}),
|
|
71
|
+
configExtension(NestedEditorExtension, {
|
|
72
|
+
$getParentEditor: () => parentEditor,
|
|
73
|
+
inheritEditableFromParent: true,
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
name: '@lexical/flow-smoke-test/NestedEditor',
|
|
77
|
+
namespace: 'flow-smoke-test-nested',
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// `buildEditorFromExtensions` is variadic over the same argument type, so a
|
|
83
|
+
// config override passed straight to it has to work too.
|
|
84
|
+
export function flowBuildsFromArguments(): LexicalEditorWithDispose {
|
|
85
|
+
return buildEditorFromExtensions(
|
|
86
|
+
ReactProviderExtension,
|
|
87
|
+
configExtension(ReactExtension, {contentEditable: null}),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function flowExtensionNames(): string {
|
|
92
|
+
return [
|
|
93
|
+
dependsOnAnExtension.name,
|
|
94
|
+
configuresItsDependency.name,
|
|
95
|
+
configuresInline.name,
|
|
96
|
+
].join(',');
|
|
97
|
+
}
|
|
@@ -33,9 +33,9 @@ function formatDevErrorMessage(message) {
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* `"0.
|
|
36
|
+
* `"0.51.0+dev.esm"` is statically replaced with the build-specific
|
|
37
37
|
* version string in a Rollup build, and a consumer's bundler `define` can
|
|
38
|
-
* inject it the same way — so the exact `"0.
|
|
38
|
+
* inject it the same way — so the exact `"0.51.0+dev.esm"` member
|
|
39
39
|
* expression must be preserved for that substitution to match. Reading it
|
|
40
40
|
* inside a try/catch lets the source be consumed directly (via the `source`
|
|
41
41
|
* export condition) in a browser bundle, where `process` is undefined and
|
|
@@ -53,7 +53,7 @@ function formatDevErrorMessage(message) {
|
|
|
53
53
|
function readLexicalVersion() {
|
|
54
54
|
let envLexicalVersion;
|
|
55
55
|
try {
|
|
56
|
-
envLexicalVersion = "0.
|
|
56
|
+
envLexicalVersion = "0.51.0+dev.esm";
|
|
57
57
|
} catch (_unused) {
|
|
58
58
|
// `process` is not defined in some browser bundles; use the fallback.
|
|
59
59
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{shallowMergeConfig as t,createEditor as e,mergeRegister as n}from"lexical";import{getNodeConfig as i}from"@lexical/extension/config";import{InitialStateExtension as s}from"@lexical/extension/InitialStateExtension";function o(t,...e){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",t);for(const t of e)i.append("v",t);throw n.search=i.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function r(){let t;try{t="0.
|
|
9
|
+
import{shallowMergeConfig as t,createEditor as e,mergeRegister as n}from"lexical";import{getNodeConfig as i}from"@lexical/extension/config";import{InitialStateExtension as s}from"@lexical/extension/InitialStateExtension";function o(t,...e){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",t);for(const t of e)i.append("v",t);throw n.search=i.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function r(){let t;try{t="0.51.0+prod.esm"}catch(t){}return t??'"<unknown>+source"'}const a=/* @__PURE__ */r(),c=new Set(["__proto__","constructor","prototype"]);function d(t,e){if(t&&e&&!Array.isArray(e)&&"object"==typeof t&&"object"==typeof e){const n=t,i=e;for(const t in i)!c.has(t)&&Object.prototype.hasOwnProperty.call(i,t)&&(n[t]=d(n[t],i[t]));return t}return e}const g=0,h=1,f=2,u=3,p=4,l=5,m=6,x=7;function E(t){return t.id===g}function S(t){return t.id===f}function b(t){return function(t){return t.id===h}(t)||o(305,String(t.id),String(h)),Object.assign(t,{id:f})}const y=new Set;class R{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(t,e){this.builder=t,this.extension=e,this.configs=new Set,this.state={id:g}}mergeConfigs(){let e=this.extension.config||{};const n=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):t;for(const t of this.configs)e=n(e,t);return e}init(t){const e=this.state;S(e)||o(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)},s=function(t,e,n){return Object.assign(t,{config:e,id:u,registerState:n})}(e,this.mergeConfigs(),n);let r;this.state=s,this.extension.init&&(r=this.extension.init(t,s.config,n)),this.state=function(t,e,n){return Object.assign(t,{id:p,initResult:e,registerState:n})}(s,r,i)}build(t){const e=this.state;let n;e.id!==p&&o(307,String(e.id),String(l)),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:l,output:e,registerState:n})}(e,n,i)}register(t,e){this._signal=e;const n=this.state;n.id!==l&&o(308,String(n.id),String(l));const i=this.extension.register&&this.extension.register(t,n.config,n.registerState);return this.state=function(t){return Object.assign(t,{id:m})}(n),()=>{const t=this.state;t.id!==x&&o(309,String(n.id),String(x)),this.state=function(t){return Object.assign(t,{id:l})}(t),i&&i()}}afterRegistration(t){const e=this.state;let n;return e.id!==m&&o(310,String(e.id),String(m)),this.extension.afterRegistration&&(n=this.extension.afterRegistration(t,e.config,e.registerState)),this.state=function(t){return Object.assign(t,{id:x})}(e),n}getSignal(){return void 0===this._signal&&o(311),this._signal}getInitResult(){void 0===this.extension.init&&o(312,this.extension.name);const t=this.state;return function(t){return t.id>=p}(t)||o(313,String(t.id),String(p)),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>=u}(t)||o(314,String(t.id),String(u)),{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&&o(315,this.extension.name,t.name),e.getExtensionInitDependency()}getDependency(t){const e=this.builder.getExtensionRep(t);return void 0===e&&o(315,this.extension.name,t.name),e.getExtensionDependency()}getState(){const t=this.state;return function(t){return t.id>=x}(t)||o(316,String(t.id),String(x)),t}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||y}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>=l})(t)||o(317,this.extension.name),this._dependency={config:t.config,init:t.initResult,output:t.output}}return this._dependency}}const v=Symbol.for("@lexical/extension/LexicalBuilder");function N(...t){return O.fromExtensions(t).buildEditor()}function _(){}function w(t){throw t}function M(t){return Array.isArray(t)?t:[t]}const D=a;class O{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=D,this.roots=t;for(const e of t)this.addExtension(e)}static fromExtensions(t){const e=[M(s)];for(const n of t)e.push(M(n));return new O(e)}static maybeFromEditor(t){const e=t[v];return e&&(e.PACKAGE_VERSION!==D&&o(292,e.PACKAGE_VERSION,D),e instanceof O||o(293)),e}static fromEditor(t){const e=O.maybeFromEditor(t);return void 0===e&&o(294),e}constructEditor(){const{$initialEditorState:t,onError:n,onWarn:i,...s}=this.buildCreateEditorArgs(),o=Object.assign(e({...s,...n?{onError:t=>{n(t,o)}}:{},...i?{onWarn:t=>{i(t,o)}}:{}}),{[v]:this});for(const t of this.sortedExtensionReps())t.build(o);return o}buildEditor(){let t=_;function e(){try{t()}finally{t=_}}const i=Object.assign(this.constructEditor(),{dispose:e,[Symbol.dispose]:e});return t=n(this.registerEditor(i),()=>i.setRootElement(null)),i}hasExtensionByName(t){return this.extensionNameMap.has(t)}getExtensionRep(t){const e=this.extensionNameMap.get(t.name);if(e)return e.extension!==t&&o(295,t.name),e}addEdge(t,e,n){const i=this.outgoingConfigEdges.get(t);if(i){const t=i.get(e);t?t.push(...n):i.set(e,n)}else this.outgoingConfigEdges.set(t,new Map([[e,n]]));const s=this.incomingEdges.get(e);s?s.add(t):this.incomingEdges.set(e,new Set([t]))}addExtension(t){void 0!==this._sortedExtensionReps&&o(296);const e=M(t),[n]=e;"string"!=typeof n.name&&o(297,typeof n.name);let i=this.extensionNameMap.get(n.name);if(void 0!==i&&i.extension!==n&&o(298,n.name),!i){i=new R(this,n),this.extensionNameMap.set(n.name,i);const t=this.conflicts.get(n.name);"string"==typeof t&&o(299,n.name,t);for(const t of n.conflictsWith||[])this.extensionNameMap.has(t)&&o(299,n.name,t),this.conflicts.set(t,n.name);for(const t of n.dependencies||[]){const e=M(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 s=n.state;if(S(s))return;const r=n.extension.name;var a;E(s)||o(300,r,i||"[unknown]"),E(a=s)||o(304,String(a.id),String(g)),s=Object.assign(a,{id:h}),n.state=s;const c=this.outgoingConfigEdges.get(r);if(c)for(const t of c.keys()){const n=this.extensionNameMap.get(t);n&&e(n,r)}s=b(s),n.state=s,t.push(n)};for(const t of this.extensionNameMap.values())E(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&&o(301,t.name);for(const t of e)n.configs.add(t)}return this._sortedExtensionReps=t,this._sortedExtensionReps}registerEditor(t){const e=this.sortedExtensionReps(),i=new AbortController,s=[()=>i.abort()],o=i.signal;for(const n of e){const e=n.register(t,o);e&&s.push(e)}for(const n of e){const e=n.afterRegistration(t);e&&s.push(e)}return n(...s)}buildCreateEditorArgs(){const t={},e=new Set,n=new Map,s=new Map,r={},a={},c=this.sortedExtensionReps();for(const g of c){const{extension:c}=g;if(void 0!==c.onError&&(t.onError=c.onError),void 0!==c.onWarn&&(t.onWarn=c.onWarn),void 0!==c.disableEvents&&(t.disableEvents=c.disableEvents),void 0!==c.parentEditor&&(t.parentEditor=c.parentEditor),void 0!==c.editable&&(t.editable=c.editable),void 0!==c.namespace&&(t.namespace=c.namespace),void 0!==c.$initialEditorState&&(t.$initialEditorState=c.$initialEditorState),c.nodes)for(const t of i(c)){if("function"!=typeof t){const e=n.get(t.replace);e&&o(302,c.name,t.replace.name,e.extension.name),n.set(t.replace,g)}e.add(t)}if(c.html){if(c.html.export)for(const[t,e]of c.html.export.entries())s.set(t,e);c.html.import&&Object.assign(r,c.html.import)}c.theme&&d(a,c.theme)}Object.keys(a).length>0&&(t.theme=a),e.size&&(t.nodes=Array.from(e));const g=Object.keys(r).length>0,h=s.size>0;(g||h)&&(t.html={},g&&(t.html.import=r),h&&(t.html.export=s));for(const e of c)e.init(t);return t.onError||(t.onError=w),t}}export{O as LexicalBuilder,N as buildEditorFromExtensions,v as builderSymbol};
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"extension",
|
|
7
7
|
"plugin"
|
|
8
8
|
],
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.51.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"description": "This package provides the extension functionality for Lexical.",
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@lexical/internal": "0.
|
|
25
|
-
"@lexical/utils": "0.
|
|
24
|
+
"@lexical/internal": "0.51.0",
|
|
25
|
+
"@lexical/utils": "0.51.0",
|
|
26
26
|
"@preact/signals-core": "^1.14.1",
|
|
27
|
-
"lexical": "0.
|
|
27
|
+
"lexical": "0.51.0"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
"./AutoFocusExtension": {
|