@etrepum/lexical-builder 0.0.10-nightly.20240604.0 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,15 @@ declare module "@etrepum/lexical-builder" {
11
11
  }
12
12
  }
13
13
  export interface AutoFocusConfig {
14
+ /**
15
+ * Where to move the selection when the editor is focused and there is no
16
+ * existing selection. Can be "rootStart" or "rootEnd" (the default).
17
+ */
14
18
  defaultSelection?: "rootStart" | "rootEnd";
15
19
  }
16
- export declare const AutoFocusPlan: import('./types').LexicalPlan<AutoFocusConfig, "@etrepum/lexical-builder/AutoFocusPlan">;
20
+ /**
21
+ * A Plan to focus the LexicalEditor when the root element is set
22
+ * (typically only when the editor is first created).
23
+ */
24
+ export declare const AutoFocusPlan: import('@etrepum/lexical-builder').LexicalPlan<AutoFocusConfig, "@etrepum/lexical-builder/AutoFocusPlan">;
17
25
  //# sourceMappingURL=AutoFocusPlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AutoFocusPlan.d.ts","sourceRoot":"","sources":["../src/AutoFocusPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,mBAAmB;QAC3B,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,aAAa,CAAC;KAC5C;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC5C;AAED,eAAO,MAAM,aAAa,0FAwBxB,CAAC"}
1
+ {"version":3,"file":"AutoFocusPlan.d.ts","sourceRoot":"","sources":["../src/AutoFocusPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,mBAAmB;QAC3B,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,aAAa,CAAC;KAC5C;CACF;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC5C;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,2GAwBxB,CAAC"}
@@ -5,5 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- export declare const DragonPlan: import('./types').LexicalPlan<{}, "@lexical/dragon">;
8
+ /**
9
+ * Add Dragon speech to text input support to the editor, via the
10
+ * @lexical/dragon module.
11
+ */
12
+ export declare const DragonPlan: import('@etrepum/lexical-builder').LexicalPlan<{}, "@lexical/dragon">;
9
13
  //# sourceMappingURL=DragonPlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DragonPlan.d.ts","sourceRoot":"","sources":["../src/DragonPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,eAAO,MAAM,UAAU,sDAIrB,CAAC"}
1
+ {"version":3,"file":"DragonPlan.d.ts","sourceRoot":"","sources":["../src/DragonPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;GAGG;AACH,eAAO,MAAM,UAAU,uEAIrB,CAAC"}
@@ -6,8 +6,19 @@ declare module "@etrepum/lexical-builder" {
6
6
  }
7
7
  }
8
8
  export interface HistoryConfig {
9
+ /**
10
+ * The time (in milliseconds) the editor should delay generating a new history stack,
11
+ * instead of merging the current changes with the current stack. The default is 300ms.
12
+ */
9
13
  delay: number;
14
+ /**
15
+ * The initial history state, the default is {@link createEmptyHistoryState}.
16
+ */
10
17
  createInitialHistoryState: () => HistoryState;
11
18
  }
12
- export declare const HistoryPlan: import('./types').LexicalPlan<HistoryConfig, "@etrepum/lexical-builder/HistoryPlan">;
19
+ /**
20
+ * Registers necessary listeners to manage undo/redo history stack and related
21
+ * editor commands, via the @lexical/history module.
22
+ */
23
+ export declare const HistoryPlan: import('@etrepum/lexical-builder').LexicalPlan<HistoryConfig, "@etrepum/lexical-builder/HistoryPlan">;
13
24
  //# sourceMappingURL=HistoryPlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HistoryPlan.d.ts","sourceRoot":"","sources":["../src/HistoryPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,mBAAmB;QAC3B,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,WAAW,CAAC;KACxC;CACF;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB,EAAE,MAAM,YAAY,CAAC;CAC/C;AAED,eAAO,MAAM,WAAW,sFAStB,CAAC"}
1
+ {"version":3,"file":"HistoryPlan.d.ts","sourceRoot":"","sources":["../src/HistoryPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,mBAAmB;QAC3B,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,WAAW,CAAC;KACxC;CACF;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,yBAAyB,EAAE,MAAM,YAAY,CAAC;CAC/C;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,uGAStB,CAAC"}
@@ -2,6 +2,37 @@ import { AnyLexicalPlan, AnyLexicalPlanArgument, EditorHandle } from './types';
2
2
  import { LexicalEditor, CreateEditorArgs } from 'lexical';
3
3
  import { PlanRep } from './PlanRep';
4
4
 
5
+ /**
6
+ * Build a LexicalEditor by combining together one or more plans, optionally
7
+ * overriding some of their configuration.
8
+ *
9
+ * @param plan A plan argument (a plan, or a plan with config overrides)
10
+ * @param plans Optional additional plan arguments
11
+ * @returns An editor handle
12
+ *
13
+ * @example A single root plan with multiple dependencies
14
+ * ```ts
15
+ * const editorHandle = buildEditorFromPlans(
16
+ * defineRootPlan({
17
+ * dependencies: [
18
+ * RichTextPlan,
19
+ * configPlan(EmojiPlan, { emojiBaseUrl: "/assets/emoji" }),
20
+ * ],
21
+ * register: (editor: LexicalEditor) => {
22
+ * console.log("Editor Created");
23
+ * return () => console.log("Editor Disposed");
24
+ * },
25
+ * }),
26
+ * );
27
+ * ```
28
+ * @example A very similar minimal configuration without the register hook
29
+ * ```ts
30
+ * const editorHandle = buildEditorFromPlans(
31
+ * RichTextPlan,
32
+ * configPlan(EmojiPlan, { emojiBaseUrl: "/assets/emoji" }),
33
+ * );
34
+ * ```
35
+ */
5
36
  export declare function buildEditorFromPlans(plan: AnyLexicalPlanArgument, ...plans: AnyLexicalPlanArgument[]): EditorHandle;
6
37
  /** @internal */
7
38
  export declare class LexicalBuilder {
@@ -10,6 +41,7 @@ export declare class LexicalBuilder {
10
41
  planNameMap: Map<string, PlanRep<AnyLexicalPlan>>;
11
42
  conflicts: Map<string, string>;
12
43
  constructor();
44
+ /** Look up the editor that was created by this LexicalBuilder or throw */
13
45
  static fromEditor(editor: LexicalEditor): LexicalBuilder;
14
46
  buildEditor(): EditorHandle;
15
47
  addPlan(arg: AnyLexicalPlanArgument): number;
@@ -1 +1 @@
1
- {"version":3,"file":"LexicalBuilder.d.ts","sourceRoot":"","sources":["../src/LexicalBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,aAAa,EAEb,KAAK,gBAAgB,EAKtB,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,sBAAsB,EAC5B,GAAG,KAAK,EAAE,sBAAsB,EAAE,GACjC,YAAY,CAOd;AA2BD,gBAAgB;AAChB,qBAAa,cAAc;IACzB,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC,C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CAAC,CAAC;IAClD,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;;IAU/B,0EAA0E;IAC1E,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc;IASxD,WAAW,IAAI,YAAY;IAmB3B,OAAO,CAAC,GAAG,EAAE,sBAAsB,GAAG,MAAM;IA4E3C,cAAc;IAMf,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,IAAI;IA6BjD,qBAAqB;CAqFtB"}
@@ -1,2 +1,5 @@
1
- export declare const PlainTextPlan: import('./types').LexicalPlan<{}, "@lexical/plain-text">;
1
+ /**
2
+ * A plan to register @lexical/plain-text behavior
3
+ */
4
+ export declare const PlainTextPlan: import('@etrepum/lexical-builder').LexicalPlan<{}, "@lexical/plain-text">;
2
5
  //# sourceMappingURL=PlainTextPlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlainTextPlan.d.ts","sourceRoot":"","sources":["../src/PlainTextPlan.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa,0DAKxB,CAAC"}
1
+ {"version":3,"file":"PlainTextPlan.d.ts","sourceRoot":"","sources":["../src/PlainTextPlan.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,eAAO,MAAM,aAAa,2EAKxB,CAAC"}
package/dist/PlanRep.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import { LexicalBuilder } from './LexicalBuilder';
2
- import { AnyLexicalPlan, LexicalPlanConfig, LexicalPlanRegistry } from './types';
2
+ import { AnyLexicalPlan, LexicalPlanConfig } from './types';
3
+ import { LexicalPlanRegistry } from '@etrepum/lexical-builder';
3
4
 
5
+ /**
6
+ * @internal
7
+ */
4
8
  export declare class PlanRep<Plan extends AnyLexicalPlan> {
5
9
  builder: LexicalBuilder;
6
- configs: Set<LexicalPlanConfig<Plan>>;
10
+ configs: Set<Partial<LexicalPlanConfig<Plan>>>;
7
11
  _config?: LexicalPlanConfig<Plan>;
8
12
  plan: Plan;
9
13
  constructor(builder: LexicalBuilder, plan: Plan);
@@ -1 +1 @@
1
- {"version":3,"file":"PlanRep.d.ts","sourceRoot":"","sources":["../src/PlanRep.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAMnD,qBAAa,OAAO,CAAC,IAAI,SAAS,cAAc;IAC9C,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,OAAO,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC;gBACC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI;IAK/C,aAAa,CAAC,IAAI,SAAS,MAAM,mBAAmB,EAClD,IAAI,EAAE,MAAM,GACX,SAAS,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAI3D,mBAAmB,CAAC,UAAU,SAAS,cAAc,EACnD,GAAG,EAAE,UAAU,GACd,iBAAiB,CAAC,UAAU,CAAC;IAUhC,SAAS,IAAI,iBAAiB,CAAC,IAAI,CAAC;CAcrC"}
1
+ {"version":3,"file":"PlanRep.d.ts","sourceRoot":"","sources":["../src/PlanRep.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAMpE;;GAEG;AACH,qBAAa,OAAO,CAAC,IAAI,SAAS,cAAc;IAC9C,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC;gBACC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI;IAK/C,aAAa,CAAC,IAAI,SAAS,MAAM,mBAAmB,EAClD,IAAI,EAAE,MAAM,GACX,SAAS,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAI3D,mBAAmB,CAAC,UAAU,SAAS,cAAc,EACnD,GAAG,EAAE,UAAU,GACd,iBAAiB,CAAC,UAAU,CAAC;IAUhC,SAAS,IAAI,iBAAiB,CAAC,IAAI,CAAC;CAcrC"}
@@ -5,5 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- export declare const RichTextPlan: import('./types').LexicalPlan<{}, "@lexical/rich-text">;
8
+ /**
9
+ * A plan to register @lexical/rich-text behavior and nodes
10
+ * ({@link HeadingNode}, {@link QuoteNode})
11
+ */
12
+ export declare const RichTextPlan: import('@etrepum/lexical-builder').LexicalPlan<{}, "@lexical/rich-text">;
9
13
  //# sourceMappingURL=RichTextPlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextPlan.d.ts","sourceRoot":"","sources":["../src/RichTextPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,eAAO,MAAM,YAAY,yDAMvB,CAAC"}
1
+ {"version":3,"file":"RichTextPlan.d.ts","sourceRoot":"","sources":["../src/RichTextPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;GAGG;AACH,eAAO,MAAM,YAAY,0EAMvB,CAAC"}
@@ -5,5 +5,21 @@
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
+ */
8
24
  export declare function deepThemeMergeInPlace(a: unknown, b: unknown): unknown;
9
25
  //# sourceMappingURL=deepThemeMergeInPlace.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deepThemeMergeInPlace.d.ts","sourceRoot":"","sources":["../src/deepThemeMergeInPlace.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAgB3D"}
1
+ {"version":3,"file":"deepThemeMergeInPlace.d.ts","sourceRoot":"","sources":["../src/deepThemeMergeInPlace.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAgB3D"}
@@ -1,6 +1,79 @@
1
- import { AnyLexicalPlan, LexicalPlan, LexicalPlanConfig, PlanConfigBase } from './types';
1
+ import { LexicalPlan, NormalizedLexicalPlanArgument, PlanConfigBase } from './types';
2
2
 
3
+ /**
4
+ * Define a LexicalPlan from the given object literal. TypeScript will
5
+ * infer Config and Name in most cases, but you may want to use
6
+ * {@link safeCast} for config if there are default fields or varying types.
7
+ *
8
+ * @param plan The LexicalPlan
9
+ * @returns The unmodified plan argument (this is only an inference helper)
10
+ *
11
+ * @example Basic example
12
+ * ```ts
13
+ * export const MyPlan = definePlan({
14
+ * // Plan names must be unique in an editor
15
+ * name: "my",
16
+ * // Config must be an object, but an empty object is fine
17
+ * config: {},
18
+ * nodes: [MyNode],
19
+ * });
20
+ * ```
21
+ *
22
+ * @example Plan with optional configuration
23
+ * ```ts
24
+ * export interface ConfigurableConfig {
25
+ * optional?: string;
26
+ * required: number;
27
+ * }
28
+ * export const ConfigurablePlan = definePlan({
29
+ * name: "configurable",
30
+ * // The Plan's config must satisfy the full config type,
31
+ * // but using the Plan as a dependency never requires
32
+ * // configuration and any partial of the config can be specified
33
+ * config: safeCast<ConfigurableConfig>({ required: 1 }),
34
+ * });
35
+ * ```
36
+ */
3
37
  export declare function definePlan<Config extends PlanConfigBase, Name extends string>(plan: LexicalPlan<Config, Name>): LexicalPlan<Config, Name>;
4
- export declare function defineRootPlan(plan: Omit<LexicalPlan<PlanConfigBase, string>, "config" | "name">): LexicalPlan<PlanConfigBase, "[root]">;
5
- export declare function configPlan<Plan extends AnyLexicalPlan>(plan: Plan, config: Partial<LexicalPlanConfig<Plan>>): [Plan, Partial<LexicalPlanConfig<Plan>>];
38
+ /**
39
+ * Define a LexicalPlan from the given object literal, assigning an
40
+ * empty config and the name "[root]". This plan must only be used
41
+ * at most once per editor, usually as the first argument to
42
+ * {@link buildEditorFromPlans}
43
+ *
44
+ * @param rootPlan A plan without the config or name properties
45
+ * @returns The given plan argument, after in-place assignment of config and name
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const editorHandle = buildEditorFromPlans(
50
+ * defineRootPlan({
51
+ * dependencies: [DragonPlan, RichTextPlan, HistoryPlan],
52
+ * }),
53
+ * );
54
+ * ```
55
+ */
56
+ export declare function defineRootPlan(rootPlan: Omit<LexicalPlan<PlanConfigBase, "[root]">, "config" | "name">): LexicalPlan<PlanConfigBase, "[root]">;
57
+ /**
58
+ * Define a NormalizedLexicalPlanArgument from the given arguments,
59
+ * this is a plan and one or more config partials for that plan.
60
+ * Generally used in the dependencies array of another plan, or as
61
+ * an argument to {@link buildEditorFromPlans}
62
+ *
63
+ * @param args A plan followed by one or more config partials for that plan
64
+ * @returns [plan, config, ...configs]
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * export const ReactDecoratorPlan = definePlan({
69
+ * name: "react-decorator",
70
+ * dependencies: [
71
+ * configPlan(ReactPlan, {
72
+ * decorators: [<ReactDecorator />]
73
+ * }),
74
+ * ],
75
+ * });
76
+ * ```
77
+ */
78
+ export declare function configPlan<Config extends PlanConfigBase, Name extends string>(...args: NormalizedLexicalPlanArgument<Config, Name>): NormalizedLexicalPlanArgument<Config, Name>;
6
79
  //# sourceMappingURL=definePlan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"definePlan.d.ts","sourceRoot":"","sources":["../src/definePlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,wBAAgB,UAAU,CAAC,MAAM,SAAS,cAAc,EAAE,IAAI,SAAS,MAAM,EAC3E,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,GAC9B,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAE3B;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,GACjE,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAEvC;AAED,wBAAgB,UAAU,CAAC,IAAI,SAAS,cAAc,EACpD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GACvC,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAE1C"}
1
+ {"version":3,"file":"definePlan.d.ts","sourceRoot":"","sources":["../src/definePlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,6BAA6B,EAC7B,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAS,cAAc,EAAE,IAAI,SAAS,MAAM,EAC3E,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,GAC9B,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAE3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,GACvE,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAGvC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAS,cAAc,EAAE,IAAI,SAAS,MAAM,EAC3E,GAAG,IAAI,EAAE,6BAA6B,CAAC,MAAM,EAAE,IAAI,CAAC,GACnD,6BAA6B,CAAC,MAAM,EAAE,IAAI,CAAC,CAE7C"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- export declare const PACKAGE_VERSION: any;
8
+ export declare const PACKAGE_VERSION: string;
9
9
  export { configPlan, definePlan, defineRootPlan } from './definePlan';
10
10
  export { LexicalBuilder, buildEditorFromPlans } from './LexicalBuilder';
11
11
  export { type AnyLexicalPlan, type AnyLexicalPlanArgument, type EditorHandle, type InitialEditorStateType, type LexicalPeerConfig, type LexicalPlan, type LexicalPlanArgument, type LexicalPlanConfig, type LexicalPlanName, type NormalizedLexicalPlanArgument, type PlanConfigBase, type RegisterState, } from './types';
@@ -16,4 +16,24 @@ export { DragonPlan } from './DragonPlan';
16
16
  export { type HistoryConfig, HistoryPlan } from './HistoryPlan';
17
17
  export { PlainTextPlan } from './PlainTextPlan';
18
18
  export { RichTextPlan } from './RichTextPlan';
19
+ /**
20
+ * An open interface for Name -> Config mappings. If you are defining a
21
+ * plan with non-empty config and it may be used as a peerDependency then
22
+ * you should extend this as follows:
23
+ *
24
+ * @example Extending LexicalPlanRegistry
25
+ * ```ts
26
+ * export const SomePlan = definePlan({
27
+ * name: "@some/plan",
28
+ * config: { className: "default" }
29
+ * });
30
+ * declare module '@etrepum/lexical-builder' {
31
+ * interface LexicalPlanRegistry {
32
+ * [SomePlan.name]: typeof SomePlan;
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+ export interface LexicalPlanRegistry {
38
+ }
19
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,eAAe,KAAkC,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAClC,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAwC,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAClC,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,mBAAmB;CAAG"}
package/dist/index.js CHANGED
@@ -13,11 +13,11 @@ import { HeadingNode, QuoteNode, registerRichText } from "@lexical/rich-text";
13
13
  function definePlan(plan) {
14
14
  return plan;
15
15
  }
16
- function defineRootPlan(plan) {
17
- return { ...plan, name: "[root]", config: {} };
16
+ function defineRootPlan(rootPlan) {
17
+ return Object.assign(rootPlan, { name: "[root]", config: {} });
18
18
  }
19
- function configPlan(plan, config) {
20
- return [plan, config];
19
+ function configPlan(...args) {
20
+ return args;
21
21
  }
22
22
  function invariant(cond, message, ...args) {
23
23
  if (cond) {
@@ -64,16 +64,16 @@ function initializeEditor(editor, $initialEditorState = $defaultInitializer) {
64
64
  }
65
65
  }
66
66
  }
67
- function shallowMergeConfig(a, b) {
68
- if (!b || a === b) {
69
- return a;
67
+ function shallowMergeConfig(config, overrides) {
68
+ if (!overrides || config === overrides) {
69
+ return config;
70
70
  }
71
- for (const k in b) {
72
- if (b[k] !== a[k]) {
73
- return { ...a, ...b };
71
+ for (const k in overrides) {
72
+ if (config[k] !== overrides[k]) {
73
+ return { ...config, ...overrides };
74
74
  }
75
75
  }
76
- return a;
76
+ return config;
77
77
  }
78
78
  class PlanRep {
79
79
  constructor(builder, plan) {
@@ -156,6 +156,7 @@ class LexicalBuilder {
156
156
  this.planNameMap = /* @__PURE__ */ new Map();
157
157
  this.conflicts = /* @__PURE__ */ new Map();
158
158
  }
159
+ /** Look up the editor that was created by this LexicalBuilder or throw */
159
160
  static fromEditor(editor) {
160
161
  const builder = buildersForEditors.get(editor);
161
162
  invariant(
@@ -218,7 +219,12 @@ class LexicalBuilder {
218
219
  )) {
219
220
  const dep = this.planNameMap.get(depName);
220
221
  if (dep) {
221
- phase = Math.max(phase, 1 + this.addPlan([dep.plan, cfg]));
222
+ phase = Math.max(
223
+ phase,
224
+ 1 + this.addPlan(
225
+ configPlan(dep.plan, cfg)
226
+ )
227
+ );
222
228
  }
223
229
  }
224
230
  invariant(
@@ -409,7 +415,7 @@ const RichTextPlan = definePlan({
409
415
  nodes: [HeadingNode, QuoteNode],
410
416
  register: registerRichText
411
417
  });
412
- const PACKAGE_VERSION = "0.0.10-nightly.20240604.0";
418
+ const PACKAGE_VERSION = "0.0.11";
413
419
  export {
414
420
  AutoFocusPlan,
415
421
  DragonPlan,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/definePlan.ts","../src/shared/invariant.ts","../src/deepThemeMergeInPlace.ts","../src/initializeEditor.ts","../src/shallowMergeConfig.ts","../src/PlanRep.ts","../src/LexicalBuilder.ts","../src/safeCast.ts","../src/AutoFocusPlan.ts","../src/DragonPlan.ts","../src/HistoryPlan.ts","../src/PlainTextPlan.ts","../src/RichTextPlan.ts","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type {\n AnyLexicalPlan,\n LexicalPlan,\n LexicalPlanConfig,\n PlanConfigBase,\n} from \"./types\";\n\nexport function definePlan<Config extends PlanConfigBase, Name extends string>(\n plan: LexicalPlan<Config, Name>,\n): LexicalPlan<Config, Name> {\n return plan;\n}\n\nexport function defineRootPlan(\n plan: Omit<LexicalPlan<PlanConfigBase, string>, \"config\" | \"name\">,\n): LexicalPlan<PlanConfigBase, \"[root]\"> {\n return { ...plan, name: \"[root]\", config: {} };\n}\n\nexport function configPlan<Plan extends AnyLexicalPlan>(\n plan: Plan,\n config: Partial<LexicalPlanConfig<Plan>>,\n): [Plan, Partial<LexicalPlanConfig<Plan>>] {\n return [plan, config];\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n// invariant(condition, message) will refine types based on \"condition\", and\n// if \"condition\" is false will throw an error. This function is special-cased\n// in flow itself, so we can't name it anything else.\nexport default function invariant(\n cond?: boolean,\n message?: string,\n ...args: string[]\n): asserts cond {\n if (cond) {\n return;\n }\n\n throw new Error(\n args.reduce((msg, arg) => msg.replace(\"%s\", String(arg)), message || \"\"),\n );\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nexport function deepThemeMergeInPlace(a: unknown, b: unknown) {\n if (\n a &&\n b &&\n !Array.isArray(b) &&\n typeof a === \"object\" &&\n typeof b === \"object\"\n ) {\n const aObj = a as Record<string, unknown>;\n const bObj = b as Record<string, unknown>;\n for (const k in bObj) {\n aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);\n }\n return a;\n }\n return b;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { InitialEditorStateType } from \"./types\";\n\nimport { $createParagraphNode, $getRoot, type LexicalEditor } from \"lexical\";\n\nconst HISTORY_MERGE_OPTIONS = { tag: \"history-merge\" };\n\nfunction $defaultInitializer() {\n const root = $getRoot();\n if (root.isEmpty()) {\n root.append($createParagraphNode());\n }\n}\n\nexport function initializeEditor(\n editor: LexicalEditor,\n $initialEditorState: InitialEditorStateType = $defaultInitializer,\n): void {\n switch (typeof $initialEditorState) {\n case \"function\": {\n editor.update(() => $initialEditorState(editor), HISTORY_MERGE_OPTIONS);\n break;\n }\n case \"string\": {\n const parsedEditorState = editor.parseEditorState($initialEditorState);\n editor.setEditorState(parsedEditorState, HISTORY_MERGE_OPTIONS);\n break;\n }\n case \"object\": {\n if ($initialEditorState) {\n editor.setEditorState($initialEditorState, HISTORY_MERGE_OPTIONS);\n }\n break;\n }\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport type { PlanConfigBase } from \"./types\";\n\nexport function shallowMergeConfig<T extends PlanConfigBase>(\n a: T,\n b?: Partial<T>,\n): T {\n if (!b || a === b) {\n return a;\n }\n for (const k in b) {\n if (b[k] !== a[k]) {\n return { ...a, ...b };\n }\n }\n return a;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { LexicalBuilder } from \"./LexicalBuilder\";\nimport type { AnyLexicalPlan, LexicalPlanConfig } from \"./types\";\nimport type { LexicalPlanRegistry } from \"./types\";\n\nimport invariant from \"./shared/invariant\";\n\nimport { shallowMergeConfig } from \"./shallowMergeConfig\";\n\nexport class PlanRep<Plan extends AnyLexicalPlan> {\n builder: LexicalBuilder;\n configs: Set<LexicalPlanConfig<Plan>>;\n _config?: LexicalPlanConfig<Plan>;\n plan: Plan;\n constructor(builder: LexicalBuilder, plan: Plan) {\n this.builder = builder;\n this.plan = plan;\n this.configs = new Set();\n }\n getPeerConfig<Name extends keyof LexicalPlanRegistry>(\n name: string,\n ): undefined | LexicalPlanConfig<LexicalPlanRegistry[Name]> {\n const rep = this.builder.planNameMap.get(name);\n return rep && rep.getConfig();\n }\n getDependencyConfig<Dependency extends AnyLexicalPlan>(\n dep: Dependency,\n ): LexicalPlanConfig<Dependency> {\n const pair = this.builder.planMap.get(dep);\n invariant(\n pair !== undefined,\n \"LexicalPlanBuilder: Plan %s missing dependency plan %s to be in registry\",\n this.plan.name,\n dep.name,\n );\n return pair[1].getConfig();\n }\n getConfig(): LexicalPlanConfig<Plan> {\n if (this._config) {\n return this._config;\n }\n let config = this.plan.config;\n const mergeConfig = this.plan.mergeConfig\n ? this.plan.mergeConfig.bind(this.plan)\n : shallowMergeConfig;\n for (const cfg of this.configs) {\n config = mergeConfig(config, cfg);\n }\n this._config = config;\n return config;\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport type {\n AnyLexicalPlan,\n AnyLexicalPlanArgument,\n EditorHandle,\n} from \"./types\";\n\nimport {\n LexicalEditor,\n createEditor,\n type CreateEditorArgs,\n type EditorThemeClasses,\n type HTMLConfig,\n type KlassConstructor,\n type LexicalNode,\n} from \"lexical\";\nimport invariant from \"./shared/invariant\";\n\nimport { deepThemeMergeInPlace } from \"./deepThemeMergeInPlace\";\nimport { initializeEditor } from \"./initializeEditor\";\nimport { PlanRep } from \"./PlanRep\";\nimport { mergeRegister } from \"@lexical/utils\";\n\nconst buildersForEditors = new WeakMap<LexicalEditor, LexicalBuilder>();\n\nexport function buildEditorFromPlans(\n plan: AnyLexicalPlanArgument,\n ...plans: AnyLexicalPlanArgument[]\n): EditorHandle {\n const builder = new LexicalBuilder();\n builder.addPlan(plan);\n for (const otherPlan of plans) {\n builder.addPlan(otherPlan);\n }\n return builder.buildEditor();\n}\n\nfunction noop() {}\nclass DisposableEditorHandle implements EditorHandle {\n editor: LexicalEditor;\n dispose: () => void;\n constructor(editor: LexicalEditor, dispose: () => void) {\n this.editor = editor;\n this.dispose = () => {\n try {\n dispose();\n } finally {\n this.dispose = noop;\n }\n };\n }\n // This should be safe even if the runtime doesn't have Symbol.dispose\n // because it will just be `handle[undefined] = dispose;`\n [Symbol.dispose]() {\n this.dispose();\n }\n}\n\nfunction defaultOnError(err: Error) {\n throw err;\n}\n\n/** @internal */\nexport class LexicalBuilder {\n phases: Map<AnyLexicalPlan, PlanRep<AnyLexicalPlan>>[];\n planMap: Map<AnyLexicalPlan, [number, PlanRep<AnyLexicalPlan>]>;\n planNameMap: Map<string, PlanRep<AnyLexicalPlan>>;\n conflicts: Map<string, string>;\n\n constructor() {\n // closure compiler can't handle class initializers\n this.phases = [new Map()];\n this.planMap = new Map();\n this.planNameMap = new Map();\n this.conflicts = new Map();\n }\n\n static fromEditor(editor: LexicalEditor): LexicalBuilder {\n const builder = buildersForEditors.get(editor);\n invariant(\n builder !== undefined,\n \"LexicalBuilder.fromEditor: editor was not created with this version of LexicalBuilder\",\n );\n return builder;\n }\n\n buildEditor(): EditorHandle {\n const { $initialEditorState, onError, ...editorConfig } =\n this.buildCreateEditorArgs();\n const editor = createEditor({\n ...editorConfig,\n ...(onError ? { onError: (err) => onError(err, editor) } : {}),\n });\n initializeEditor(editor, $initialEditorState);\n buildersForEditors.set(editor, this);\n return new DisposableEditorHandle(\n editor,\n mergeRegister(\n () => buildersForEditors.delete(editor),\n () => editor.setRootElement(null),\n this.registerEditor(editor),\n ),\n );\n }\n\n addPlan(arg: AnyLexicalPlanArgument): number {\n let plan: AnyLexicalPlan;\n let configs: unknown[];\n if (Array.isArray(arg)) {\n [plan, ...configs] = arg;\n } else {\n plan = arg;\n configs = [];\n }\n let [phase, planRep] = this.planMap.get(plan) || [0, undefined];\n if (!planRep) {\n const hasConflict = this.conflicts.get(plan.name);\n if (typeof hasConflict === \"string\") {\n invariant(\n false,\n \"LexicalBuilder: plan %s conflicts with %s\",\n plan.name,\n hasConflict,\n );\n }\n for (const name of plan.conflictsWith || []) {\n invariant(\n !this.planNameMap.has(name),\n \"LexicalBuilder: plan %s conflicts with %s\",\n plan.name,\n name,\n );\n this.conflicts.set(name, plan.name);\n }\n // TODO detect circular dependencies\n for (const dep of plan.dependencies || []) {\n phase = Math.max(phase, 1 + this.addPlan(dep));\n }\n for (const [depName, cfg] of Object.entries(\n plan.peerDependencies || {},\n )) {\n const dep = this.planNameMap.get(depName);\n if (dep) {\n phase = Math.max(phase, 1 + this.addPlan([dep.plan, cfg]));\n }\n }\n invariant(\n this.phases.length >= phase,\n \"LexicalBuilder: Expected phase to be no greater than phases.length\",\n );\n if (this.phases.length === phase) {\n this.phases.push(new Map());\n }\n planRep = new PlanRep(this, plan);\n invariant(\n !this.planNameMap.has(plan.name),\n \"LexicalBuilder: Multiple plans registered with name %s, names must be unique\",\n plan.name,\n );\n this.planMap.set(plan, [phase, planRep]);\n this.planNameMap.set(plan.name, planRep);\n const currentPhaseMap = this.phases[phase];\n invariant(\n currentPhaseMap !== undefined,\n \"LexicalBuilder: Expecting phase map for phase %s\",\n String(phase),\n );\n currentPhaseMap.set(plan, planRep);\n }\n for (const config of configs) {\n planRep.configs.add(config);\n }\n return phase;\n }\n\n *sortedPlanReps() {\n for (const phase of this.phases) {\n yield* phase.values();\n }\n }\n\n registerEditor(editor: LexicalEditor): () => void {\n const cleanups: (() => void)[] = [];\n const controller = new AbortController();\n for (const planRep of this.sortedPlanReps()) {\n if (planRep.plan.register) {\n cleanups.push(\n planRep.plan.register(editor, planRep.getConfig(), {\n getDependencyConfig: planRep.getDependencyConfig.bind(planRep),\n getPeerConfig: planRep.getPeerConfig.bind(planRep),\n signal: controller.signal,\n }),\n );\n }\n }\n return () => {\n for (let i = cleanups.length - 1; i >= 0; i--) {\n const cleanupFun = cleanups[i];\n invariant(\n cleanupFun !== undefined,\n \"LexicalBuilder: Expecting cleanups[%s] to be defined\",\n String(i),\n );\n cleanupFun();\n }\n cleanups.length = 0;\n controller.abort();\n };\n }\n\n buildCreateEditorArgs() {\n const config: Pick<\n CreateEditorArgs,\n \"nodes\" | \"html\" | \"theme\" | \"disableEvents\" | \"editable\" | \"namespace\"\n > &\n Pick<AnyLexicalPlan, \"$initialEditorState\" | \"onError\"> = {\n // Prefer throwing errors rather than console.error by default\n onError: defaultOnError\n };\n const nodes = new Set<NonNullable<CreateEditorArgs[\"nodes\"]>[number]>();\n const replacedNodes = new Map<\n KlassConstructor<typeof LexicalNode>,\n PlanRep<AnyLexicalPlan>\n >();\n const htmlExport: NonNullable<HTMLConfig[\"export\"]> = new Map();\n const htmlImport: NonNullable<HTMLConfig[\"import\"]> = {};\n const theme: EditorThemeClasses = {};\n for (const planRep of this.sortedPlanReps()) {\n const { plan } = planRep;\n if (plan.onError !== undefined) {\n config.onError = plan.onError;\n }\n if (plan.disableEvents !== undefined) {\n config.disableEvents = plan.disableEvents;\n }\n if (plan.editable !== undefined) {\n config.editable = plan.editable;\n }\n if (plan.namespace !== undefined) {\n config.namespace = plan.namespace;\n }\n if (plan.$initialEditorState !== undefined) {\n config.$initialEditorState = plan.$initialEditorState;\n }\n if (plan.nodes) {\n for (const node of plan.nodes) {\n if (typeof node !== \"function\") {\n const conflictPlan = replacedNodes.get(node.replace);\n if (conflictPlan) {\n invariant(\n false,\n \"LexicalBuilder: Plan %s can not register replacement for node %s because %s already did\",\n plan.name,\n node.replace.name,\n conflictPlan.plan.name,\n );\n }\n replacedNodes.set(node.replace, planRep);\n }\n nodes.add(node);\n }\n }\n if (plan.html) {\n if (plan.html.export) {\n for (const [k, v] of plan.html.export.entries()) {\n htmlExport.set(k, v);\n }\n }\n if (plan.html.import) {\n Object.assign(htmlImport, plan.html.import);\n }\n }\n if (plan.theme) {\n deepThemeMergeInPlace(theme, plan.theme);\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n if (Object.keys(theme).length > 0) {\n config.theme = theme;\n }\n if (nodes.size) {\n config.nodes = [...nodes];\n }\n const hasImport = Object.keys(htmlImport).length > 0;\n const hasExport = htmlExport.size > 0;\n if (hasImport || hasExport) {\n config.html = {};\n if (hasImport) {\n config.html.import = htmlImport;\n }\n if (hasExport) {\n config.html.export = htmlExport;\n }\n }\n return config;\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n/**\n * Explicitly and safely cast a value to a specific type when inference or\n * satisfies isn't going to work as expected (often useful for the config\n * property with definePlan)\n */\nexport function safeCast<T>(value: T): T {\n return value;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { definePlan } from \"./definePlan\";\nimport { safeCast } from \"./safeCast\";\n\nimport type {} from \"@etrepum/lexical-builder\";\ndeclare module \"@etrepum/lexical-builder\" {\n interface LexicalPlanRegistry {\n [AutoFocusPlan.name]: typeof AutoFocusPlan;\n }\n}\n\nexport interface AutoFocusConfig {\n defaultSelection?: \"rootStart\" | \"rootEnd\";\n}\n\nexport const AutoFocusPlan = definePlan({\n config: safeCast<AutoFocusConfig>({}),\n name: \"@etrepum/lexical-builder/AutoFocusPlan\",\n register(editor, { defaultSelection }) {\n return editor.registerRootListener((rootElement) => {\n editor.focus(\n () => {\n // If we try and move selection to the same point with setBaseAndExtent, it won't\n // trigger a re-focus on the element. So in the case this occurs, we'll need to correct it.\n // Normally this is fine, Selection API !== Focus API, but fore the intents of the naming\n // of this plugin, which should preserve focus too.\n const activeElement = document.activeElement;\n if (\n rootElement !== null &&\n (activeElement === null || !rootElement.contains(activeElement))\n ) {\n // Note: preventScroll won't work in Webkit.\n rootElement.focus({ preventScroll: true });\n }\n },\n { defaultSelection }\n );\n });\n },\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { registerDragonSupport } from \"@lexical/dragon\";\n\nimport { definePlan } from \"./definePlan\";\n\nexport const DragonPlan = definePlan({\n config: {},\n name: \"@lexical/dragon\",\n register: registerDragonSupport,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport {\n createEmptyHistoryState,\n type HistoryState,\n registerHistory,\n} from \"@lexical/history\";\n\nimport { definePlan } from \"./definePlan\";\nimport { safeCast } from \"./safeCast\";\n\nimport type {} from \"@etrepum/lexical-builder\";\ndeclare module \"@etrepum/lexical-builder\" {\n interface LexicalPlanRegistry {\n [HistoryPlan.name]: typeof HistoryPlan;\n }\n}\n\nexport interface HistoryConfig {\n delay: number;\n createInitialHistoryState: () => HistoryState;\n}\n\nexport const HistoryPlan = definePlan({\n config: safeCast<HistoryConfig>({\n createInitialHistoryState: createEmptyHistoryState,\n delay: 300,\n }),\n name: \"@etrepum/lexical-builder/HistoryPlan\",\n register(editor, { delay, createInitialHistoryState }) {\n return registerHistory(editor, createInitialHistoryState(), delay);\n },\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { registerPlainText } from \"@lexical/plain-text\";\n\nimport { definePlan } from \"./definePlan\";\n\nexport const PlainTextPlan = definePlan({\n config: {},\n conflictsWith: [\"@lexical/rich-text\"],\n name: \"@lexical/plain-text\",\n register: registerPlainText,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { HeadingNode, QuoteNode, registerRichText } from \"@lexical/rich-text\";\n\nimport { definePlan } from \"./definePlan\";\n\nexport const RichTextPlan = definePlan({\n config: {},\n conflictsWith: [\"@lexical/plain-text\"],\n name: \"@lexical/rich-text\",\n nodes: [HeadingNode, QuoteNode],\n register: registerRichText,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nexport const PACKAGE_VERSION = import.meta.env.PACKAGE_VERSION;\n\nexport { configPlan, definePlan, defineRootPlan } from \"./definePlan\";\nexport { LexicalBuilder, buildEditorFromPlans } from \"./LexicalBuilder\";\nexport {\n type AnyLexicalPlan,\n type AnyLexicalPlanArgument,\n type EditorHandle,\n type InitialEditorStateType,\n type LexicalPeerConfig,\n type LexicalPlan,\n type LexicalPlanArgument,\n type LexicalPlanConfig,\n type LexicalPlanName,\n type NormalizedLexicalPlanArgument,\n type PlanConfigBase,\n type RegisterState,\n} from \"./types\";\nexport { safeCast } from \"./safeCast\";\nexport { shallowMergeConfig } from \"./shallowMergeConfig\";\n// These plan definitions should all be colocated with their implementations, only here for convenience\nexport { type AutoFocusConfig, AutoFocusPlan } from \"./AutoFocusPlan\";\nexport { DragonPlan } from \"./DragonPlan\";\nexport { type HistoryConfig, HistoryPlan } from \"./HistoryPlan\";\nexport { PlainTextPlan } from \"./PlainTextPlan\";\nexport { RichTextPlan } from \"./RichTextPlan\";\n"],"names":[],"mappings":";;;;;;;;;;;;AAeO,SAAS,WACd,MAC2B;AACpB,SAAA;AACT;AAEO,SAAS,eACd,MACuC;AACvC,SA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,"file":"index.js","sources":["../src/definePlan.ts","../src/shared/invariant.ts","../src/deepThemeMergeInPlace.ts","../src/initializeEditor.ts","../src/shallowMergeConfig.ts","../src/PlanRep.ts","../src/LexicalBuilder.ts","../src/safeCast.ts","../src/AutoFocusPlan.ts","../src/DragonPlan.ts","../src/HistoryPlan.ts","../src/PlainTextPlan.ts","../src/RichTextPlan.ts","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type {\n LexicalPlan,\n NormalizedLexicalPlanArgument,\n PlanConfigBase,\n} from \"./types\";\n\n/**\n * Define a LexicalPlan from the given object literal. TypeScript will\n * infer Config and Name in most cases, but you may want to use\n * {@link safeCast} for config if there are default fields or varying types.\n *\n * @param plan The LexicalPlan\n * @returns The unmodified plan argument (this is only an inference helper)\n *\n * @example Basic example\n * ```ts\n * export const MyPlan = definePlan({\n * // Plan names must be unique in an editor\n * name: \"my\",\n * // Config must be an object, but an empty object is fine\n * config: {},\n * nodes: [MyNode],\n * });\n * ```\n *\n * @example Plan with optional configuration\n * ```ts\n * export interface ConfigurableConfig {\n * optional?: string;\n * required: number;\n * }\n * export const ConfigurablePlan = definePlan({\n * name: \"configurable\",\n * // The Plan's config must satisfy the full config type,\n * // but using the Plan as a dependency never requires\n * // configuration and any partial of the config can be specified\n * config: safeCast<ConfigurableConfig>({ required: 1 }),\n * });\n * ```\n */\nexport function definePlan<Config extends PlanConfigBase, Name extends string>(\n plan: LexicalPlan<Config, Name>,\n): LexicalPlan<Config, Name> {\n return plan;\n}\n\n/**\n * Define a LexicalPlan from the given object literal, assigning an\n * empty config and the name \"[root]\". This plan must only be used\n * at most once per editor, usually as the first argument to\n * {@link buildEditorFromPlans}\n *\n * @param rootPlan A plan without the config or name properties\n * @returns The given plan argument, after in-place assignment of config and name\n *\n * @example\n * ```ts\n * const editorHandle = buildEditorFromPlans(\n * defineRootPlan({\n * dependencies: [DragonPlan, RichTextPlan, HistoryPlan],\n * }),\n * );\n * ```\n */\nexport function defineRootPlan(\n rootPlan: Omit<LexicalPlan<PlanConfigBase, \"[root]\">, \"config\" | \"name\">,\n): LexicalPlan<PlanConfigBase, \"[root]\"> {\n // @ts-ignore\n return Object.assign(rootPlan, { name: \"[root]\", config: {} }) as any;\n}\n\n/**\n * Define a NormalizedLexicalPlanArgument from the given arguments,\n * this is a plan and one or more config partials for that plan.\n * Generally used in the dependencies array of another plan, or as\n * an argument to {@link buildEditorFromPlans}\n *\n * @param args A plan followed by one or more config partials for that plan\n * @returns [plan, config, ...configs]\n *\n * @example\n * ```ts\n * export const ReactDecoratorPlan = definePlan({\n * name: \"react-decorator\",\n * dependencies: [\n * configPlan(ReactPlan, {\n * decorators: [<ReactDecorator />]\n * }),\n * ],\n * });\n * ```\n */\nexport function configPlan<Config extends PlanConfigBase, Name extends string>(\n ...args: NormalizedLexicalPlanArgument<Config, Name>\n): NormalizedLexicalPlanArgument<Config, Name> {\n return args;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n// invariant(condition, message) will refine types based on \"condition\", and\n// if \"condition\" is false will throw an error. This function is special-cased\n// in flow itself, so we can't name it anything else.\nexport default function invariant(\n cond?: boolean,\n message?: string,\n ...args: string[]\n): asserts cond {\n if (cond) {\n return;\n }\n\n throw new Error(\n args.reduce((msg, arg) => msg.replace(\"%s\", String(arg)), message || \"\"),\n );\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n/**\n * Recursively merge the given theme configuration in-place.\n *\n * @returns If `a` and `b` are both objects (and `b` is not an Array) then\n * all keys in `b` are merged into `a` then `a` is returned.\n * Otherwise `b` is returned.\n *\n * @example\n * ```ts\n * const a = { a: \"a\", nested: { a: 1 } };\n * const b = { b: \"b\", nested: { b: 2 } };\n * const rval = deepThemeMergeInPlace(a, b);\n * expect(a).toBe(rval);\n * expect(a).toEqual({ a: \"a\", b: \"b\", nested: { a: 1, b: 2 } });\n * ```\n */\nexport function deepThemeMergeInPlace(a: unknown, b: unknown) {\n if (\n a &&\n b &&\n !Array.isArray(b) &&\n typeof a === \"object\" &&\n typeof b === \"object\"\n ) {\n const aObj = a as Record<string, unknown>;\n const bObj = b as Record<string, unknown>;\n for (const k in bObj) {\n aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);\n }\n return a;\n }\n return b;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { InitialEditorStateType } from \"./types\";\n\nimport { $createParagraphNode, $getRoot, type LexicalEditor } from \"lexical\";\n\nconst HISTORY_MERGE_OPTIONS = { tag: \"history-merge\" };\n\nfunction $defaultInitializer() {\n const root = $getRoot();\n if (root.isEmpty()) {\n root.append($createParagraphNode());\n }\n}\n\nexport function initializeEditor(\n editor: LexicalEditor,\n $initialEditorState: InitialEditorStateType = $defaultInitializer,\n): void {\n switch (typeof $initialEditorState) {\n case \"function\": {\n editor.update(() => $initialEditorState(editor), HISTORY_MERGE_OPTIONS);\n break;\n }\n case \"string\": {\n const parsedEditorState = editor.parseEditorState($initialEditorState);\n editor.setEditorState(parsedEditorState, HISTORY_MERGE_OPTIONS);\n break;\n }\n case \"object\": {\n if ($initialEditorState) {\n editor.setEditorState($initialEditorState, HISTORY_MERGE_OPTIONS);\n }\n break;\n }\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport type { PlanConfigBase } from \"./types\";\n\n/**\n * The default merge strategy for plan configuration is a shallow merge.\n *\n * @param config A full config\n * @param overrides A partial config of overrides\n * @returns config if there are no overrides, otherwise `{...config, ...overrides}`\n */\nexport function shallowMergeConfig<T extends PlanConfigBase>(\n config: T,\n overrides?: Partial<T>,\n): T {\n if (!overrides || config === overrides) {\n return config;\n }\n for (const k in overrides) {\n if (config[k] !== overrides[k]) {\n return { ...config, ...overrides };\n }\n }\n return config;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { LexicalBuilder } from \"./LexicalBuilder\";\nimport type { AnyLexicalPlan, LexicalPlanConfig } from \"./types\";\nimport type { LexicalPlanRegistry } from \"@etrepum/lexical-builder\";\n\nimport invariant from \"./shared/invariant\";\n\nimport { shallowMergeConfig } from \"./shallowMergeConfig\";\n\n/**\n * @internal\n */\nexport class PlanRep<Plan extends AnyLexicalPlan> {\n builder: LexicalBuilder;\n configs: Set<Partial<LexicalPlanConfig<Plan>>>;\n _config?: LexicalPlanConfig<Plan>;\n plan: Plan;\n constructor(builder: LexicalBuilder, plan: Plan) {\n this.builder = builder;\n this.plan = plan;\n this.configs = new Set();\n }\n getPeerConfig<Name extends keyof LexicalPlanRegistry>(\n name: string,\n ): undefined | LexicalPlanConfig<LexicalPlanRegistry[Name]> {\n const rep = this.builder.planNameMap.get(name);\n return rep && rep.getConfig();\n }\n getDependencyConfig<Dependency extends AnyLexicalPlan>(\n dep: Dependency,\n ): LexicalPlanConfig<Dependency> {\n const pair = this.builder.planMap.get(dep);\n invariant(\n pair !== undefined,\n \"LexicalPlanBuilder: Plan %s missing dependency plan %s to be in registry\",\n this.plan.name,\n dep.name,\n );\n return pair[1].getConfig();\n }\n getConfig(): LexicalPlanConfig<Plan> {\n if (this._config) {\n return this._config;\n }\n let config = this.plan.config;\n const mergeConfig = this.plan.mergeConfig\n ? this.plan.mergeConfig.bind(this.plan)\n : shallowMergeConfig;\n for (const cfg of this.configs) {\n config = mergeConfig(config, cfg);\n }\n this._config = config;\n return config;\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport type {\n AnyLexicalPlan,\n AnyLexicalPlanArgument,\n EditorHandle,\n LexicalPlanConfig,\n} from \"./types\";\n\nimport {\n LexicalEditor,\n createEditor,\n type CreateEditorArgs,\n type EditorThemeClasses,\n type HTMLConfig,\n type KlassConstructor,\n type LexicalNode,\n} from \"lexical\";\nimport invariant from \"./shared/invariant\";\n\nimport { deepThemeMergeInPlace } from \"./deepThemeMergeInPlace\";\nimport { initializeEditor } from \"./initializeEditor\";\nimport { PlanRep } from \"./PlanRep\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { configPlan } from \"./definePlan\";\n\nconst buildersForEditors = new WeakMap<LexicalEditor, LexicalBuilder>();\n\n/**\n * Build a LexicalEditor by combining together one or more plans, optionally\n * overriding some of their configuration.\n *\n * @param plan A plan argument (a plan, or a plan with config overrides)\n * @param plans Optional additional plan arguments\n * @returns An editor handle\n *\n * @example A single root plan with multiple dependencies\n * ```ts\n * const editorHandle = buildEditorFromPlans(\n * defineRootPlan({\n * dependencies: [\n * RichTextPlan,\n * configPlan(EmojiPlan, { emojiBaseUrl: \"/assets/emoji\" }),\n * ],\n * register: (editor: LexicalEditor) => {\n * console.log(\"Editor Created\");\n * return () => console.log(\"Editor Disposed\");\n * },\n * }),\n * );\n * ```\n * @example A very similar minimal configuration without the register hook\n * ```ts\n * const editorHandle = buildEditorFromPlans(\n * RichTextPlan,\n * configPlan(EmojiPlan, { emojiBaseUrl: \"/assets/emoji\" }),\n * );\n * ```\n */\nexport function buildEditorFromPlans(\n plan: AnyLexicalPlanArgument,\n ...plans: AnyLexicalPlanArgument[]\n): EditorHandle {\n const builder = new LexicalBuilder();\n builder.addPlan(plan);\n for (const otherPlan of plans) {\n builder.addPlan(otherPlan);\n }\n return builder.buildEditor();\n}\n\n/** @internal */\nfunction noop() {}\n\n/** @internal */\nclass DisposableEditorHandle implements EditorHandle {\n editor: LexicalEditor;\n dispose: () => void;\n constructor(editor: LexicalEditor, dispose: () => void) {\n this.editor = editor;\n this.dispose = () => {\n try {\n dispose();\n } finally {\n this.dispose = noop;\n }\n };\n }\n // This should be safe even if the runtime doesn't have Symbol.dispose\n // because it will just be `handle[undefined] = dispose;`\n [Symbol.dispose]() {\n this.dispose();\n }\n}\n\n/** Throw the given Error */\nfunction defaultOnError(err: Error) {\n throw err;\n}\n\n/** @internal */\nexport class LexicalBuilder {\n phases: Map<AnyLexicalPlan, PlanRep<AnyLexicalPlan>>[];\n planMap: Map<AnyLexicalPlan, [number, PlanRep<AnyLexicalPlan>]>;\n planNameMap: Map<string, PlanRep<AnyLexicalPlan>>;\n conflicts: Map<string, string>;\n\n constructor() {\n // closure compiler can't handle class initializers\n this.phases = [new Map()];\n this.planMap = new Map();\n this.planNameMap = new Map();\n this.conflicts = new Map();\n }\n\n /** Look up the editor that was created by this LexicalBuilder or throw */\n static fromEditor(editor: LexicalEditor): LexicalBuilder {\n const builder = buildersForEditors.get(editor);\n invariant(\n builder !== undefined,\n \"LexicalBuilder.fromEditor: editor was not created with this version of LexicalBuilder\",\n );\n return builder;\n }\n\n buildEditor(): EditorHandle {\n const { $initialEditorState, onError, ...editorConfig } =\n this.buildCreateEditorArgs();\n const editor = createEditor({\n ...editorConfig,\n ...(onError ? { onError: (err) => onError(err, editor) } : {}),\n });\n initializeEditor(editor, $initialEditorState);\n buildersForEditors.set(editor, this);\n return new DisposableEditorHandle(\n editor,\n mergeRegister(\n () => buildersForEditors.delete(editor),\n () => editor.setRootElement(null),\n this.registerEditor(editor),\n ),\n );\n }\n\n addPlan(arg: AnyLexicalPlanArgument): number {\n let plan: AnyLexicalPlan;\n let configs: unknown[];\n if (Array.isArray(arg)) {\n [plan, ...configs] = arg;\n } else {\n plan = arg;\n configs = [];\n }\n let [phase, planRep] = this.planMap.get(plan) || [0, undefined];\n if (!planRep) {\n const hasConflict = this.conflicts.get(plan.name);\n if (typeof hasConflict === \"string\") {\n invariant(\n false,\n \"LexicalBuilder: plan %s conflicts with %s\",\n plan.name,\n hasConflict,\n );\n }\n for (const name of plan.conflictsWith || []) {\n invariant(\n !this.planNameMap.has(name),\n \"LexicalBuilder: plan %s conflicts with %s\",\n plan.name,\n name,\n );\n this.conflicts.set(name, plan.name);\n }\n // TODO detect circular dependencies\n for (const dep of plan.dependencies || []) {\n phase = Math.max(phase, 1 + this.addPlan(dep));\n }\n for (const [depName, cfg] of Object.entries(\n plan.peerDependencies || {},\n )) {\n const dep = this.planNameMap.get(depName);\n if (dep) {\n phase = Math.max(\n phase,\n 1 +\n this.addPlan(\n configPlan(dep.plan, cfg as LexicalPlanConfig<typeof dep.plan>),\n ),\n );\n }\n }\n invariant(\n this.phases.length >= phase,\n \"LexicalBuilder: Expected phase to be no greater than phases.length\",\n );\n if (this.phases.length === phase) {\n this.phases.push(new Map());\n }\n planRep = new PlanRep(this, plan);\n invariant(\n !this.planNameMap.has(plan.name),\n \"LexicalBuilder: Multiple plans registered with name %s, names must be unique\",\n plan.name,\n );\n this.planMap.set(plan, [phase, planRep]);\n this.planNameMap.set(plan.name, planRep);\n const currentPhaseMap = this.phases[phase];\n invariant(\n currentPhaseMap !== undefined,\n \"LexicalBuilder: Expecting phase map for phase %s\",\n String(phase),\n );\n currentPhaseMap.set(plan, planRep);\n }\n for (const config of configs) {\n planRep.configs.add(config as Partial<LexicalPlanConfig<AnyLexicalPlan>>);\n }\n return phase;\n }\n\n *sortedPlanReps() {\n for (const phase of this.phases) {\n yield* phase.values();\n }\n }\n\n registerEditor(editor: LexicalEditor): () => void {\n const cleanups: (() => void)[] = [];\n const controller = new AbortController();\n for (const planRep of this.sortedPlanReps()) {\n if (planRep.plan.register) {\n cleanups.push(\n planRep.plan.register(editor, planRep.getConfig(), {\n getDependencyConfig: planRep.getDependencyConfig.bind(planRep),\n getPeerConfig: planRep.getPeerConfig.bind(planRep),\n signal: controller.signal,\n }),\n );\n }\n }\n return () => {\n for (let i = cleanups.length - 1; i >= 0; i--) {\n const cleanupFun = cleanups[i];\n invariant(\n cleanupFun !== undefined,\n \"LexicalBuilder: Expecting cleanups[%s] to be defined\",\n String(i),\n );\n cleanupFun();\n }\n cleanups.length = 0;\n controller.abort();\n };\n }\n\n buildCreateEditorArgs() {\n const config: Pick<\n CreateEditorArgs,\n \"nodes\" | \"html\" | \"theme\" | \"disableEvents\" | \"editable\" | \"namespace\"\n > &\n Pick<AnyLexicalPlan, \"$initialEditorState\" | \"onError\"> = {\n // Prefer throwing errors rather than console.error by default\n onError: defaultOnError,\n };\n const nodes = new Set<NonNullable<CreateEditorArgs[\"nodes\"]>[number]>();\n const replacedNodes = new Map<\n KlassConstructor<typeof LexicalNode>,\n PlanRep<AnyLexicalPlan>\n >();\n const htmlExport: NonNullable<HTMLConfig[\"export\"]> = new Map();\n const htmlImport: NonNullable<HTMLConfig[\"import\"]> = {};\n const theme: EditorThemeClasses = {};\n for (const planRep of this.sortedPlanReps()) {\n const { plan } = planRep;\n if (plan.onError !== undefined) {\n config.onError = plan.onError;\n }\n if (plan.disableEvents !== undefined) {\n config.disableEvents = plan.disableEvents;\n }\n if (plan.editable !== undefined) {\n config.editable = plan.editable;\n }\n if (plan.namespace !== undefined) {\n config.namespace = plan.namespace;\n }\n if (plan.$initialEditorState !== undefined) {\n config.$initialEditorState = plan.$initialEditorState;\n }\n if (plan.nodes) {\n for (const node of plan.nodes) {\n if (typeof node !== \"function\") {\n const conflictPlan = replacedNodes.get(node.replace);\n if (conflictPlan) {\n invariant(\n false,\n \"LexicalBuilder: Plan %s can not register replacement for node %s because %s already did\",\n plan.name,\n node.replace.name,\n conflictPlan.plan.name,\n );\n }\n replacedNodes.set(node.replace, planRep);\n }\n nodes.add(node);\n }\n }\n if (plan.html) {\n if (plan.html.export) {\n for (const [k, v] of plan.html.export.entries()) {\n htmlExport.set(k, v);\n }\n }\n if (plan.html.import) {\n Object.assign(htmlImport, plan.html.import);\n }\n }\n if (plan.theme) {\n deepThemeMergeInPlace(theme, plan.theme);\n }\n }\n if (Object.keys(theme).length > 0) {\n config.theme = theme;\n }\n if (nodes.size) {\n config.nodes = [...nodes];\n }\n const hasImport = Object.keys(htmlImport).length > 0;\n const hasExport = htmlExport.size > 0;\n if (hasImport || hasExport) {\n config.html = {};\n if (hasImport) {\n config.html.import = htmlImport;\n }\n if (hasExport) {\n config.html.export = htmlExport;\n }\n }\n return config;\n }\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n/**\n * Explicitly and safely cast a value to a specific type when inference or\n * satisfies isn't going to work as expected (often useful for the config\n * property with definePlan)\n */\nexport function safeCast<T>(value: T): T {\n return value;\n}\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { definePlan } from \"./definePlan\";\nimport { safeCast } from \"./safeCast\";\n\nimport type {} from \"@etrepum/lexical-builder\";\ndeclare module \"@etrepum/lexical-builder\" {\n interface LexicalPlanRegistry {\n [AutoFocusPlan.name]: typeof AutoFocusPlan;\n }\n}\n\nexport interface AutoFocusConfig {\n /**\n * Where to move the selection when the editor is focused and there is no\n * existing selection. Can be \"rootStart\" or \"rootEnd\" (the default).\n */\n defaultSelection?: \"rootStart\" | \"rootEnd\";\n}\n\n/**\n * A Plan to focus the LexicalEditor when the root element is set\n * (typically only when the editor is first created).\n */\nexport const AutoFocusPlan = definePlan({\n config: safeCast<AutoFocusConfig>({}),\n name: \"@etrepum/lexical-builder/AutoFocusPlan\",\n register(editor, { defaultSelection }) {\n return editor.registerRootListener((rootElement) => {\n editor.focus(\n () => {\n // If we try and move selection to the same point with setBaseAndExtent, it won't\n // trigger a re-focus on the element. So in the case this occurs, we'll need to correct it.\n // Normally this is fine, Selection API !== Focus API, but fore the intents of the naming\n // of this plugin, which should preserve focus too.\n const activeElement = document.activeElement;\n if (\n rootElement !== null &&\n (activeElement === null || !rootElement.contains(activeElement))\n ) {\n // Note: preventScroll won't work in Webkit.\n rootElement.focus({ preventScroll: true });\n }\n },\n { defaultSelection },\n );\n });\n },\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { registerDragonSupport } from \"@lexical/dragon\";\n\nimport { definePlan } from \"./definePlan\";\n\n/**\n * Add Dragon speech to text input support to the editor, via the\n * @lexical/dragon module.\n */\nexport const DragonPlan = definePlan({\n config: {},\n name: \"@lexical/dragon\",\n register: registerDragonSupport,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport {\n createEmptyHistoryState,\n type HistoryState,\n registerHistory,\n} from \"@lexical/history\";\n\nimport { definePlan } from \"./definePlan\";\nimport { safeCast } from \"./safeCast\";\n\nimport type {} from \"@etrepum/lexical-builder\";\ndeclare module \"@etrepum/lexical-builder\" {\n interface LexicalPlanRegistry {\n [HistoryPlan.name]: typeof HistoryPlan;\n }\n}\n\nexport interface HistoryConfig {\n /**\n * The time (in milliseconds) the editor should delay generating a new history stack,\n * instead of merging the current changes with the current stack. The default is 300ms.\n */\n delay: number;\n /**\n * The initial history state, the default is {@link createEmptyHistoryState}.\n */\n createInitialHistoryState: () => HistoryState;\n}\n\n/**\n * Registers necessary listeners to manage undo/redo history stack and related\n * editor commands, via the @lexical/history module.\n */\nexport const HistoryPlan = definePlan({\n config: safeCast<HistoryConfig>({\n createInitialHistoryState: createEmptyHistoryState,\n delay: 300,\n }),\n name: \"@etrepum/lexical-builder/HistoryPlan\",\n register(editor, { delay, createInitialHistoryState }) {\n return registerHistory(editor, createInitialHistoryState(), delay);\n },\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { registerPlainText } from \"@lexical/plain-text\";\n\nimport { definePlan } from \"./definePlan\";\n\n/**\n * A plan to register @lexical/plain-text behavior\n */\nexport const PlainTextPlan = definePlan({\n config: {},\n conflictsWith: [\"@lexical/rich-text\"],\n name: \"@lexical/plain-text\",\n register: registerPlainText,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { HeadingNode, QuoteNode, registerRichText } from \"@lexical/rich-text\";\n\nimport { definePlan } from \"./definePlan\";\n\n/**\n * A plan to register @lexical/rich-text behavior and nodes\n * ({@link HeadingNode}, {@link QuoteNode})\n */\nexport const RichTextPlan = definePlan({\n config: {},\n conflictsWith: [\"@lexical/plain-text\"],\n name: \"@lexical/rich-text\",\n nodes: [HeadingNode, QuoteNode],\n register: registerRichText,\n});\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nexport const PACKAGE_VERSION: string = import.meta.env.PACKAGE_VERSION;\n\nexport { configPlan, definePlan, defineRootPlan } from \"./definePlan\";\nexport { LexicalBuilder, buildEditorFromPlans } from \"./LexicalBuilder\";\nexport {\n type AnyLexicalPlan,\n type AnyLexicalPlanArgument,\n type EditorHandle,\n type InitialEditorStateType,\n type LexicalPeerConfig,\n type LexicalPlan,\n type LexicalPlanArgument,\n type LexicalPlanConfig,\n type LexicalPlanName,\n type NormalizedLexicalPlanArgument,\n type PlanConfigBase,\n type RegisterState,\n} from \"./types\";\nexport { safeCast } from \"./safeCast\";\nexport { shallowMergeConfig } from \"./shallowMergeConfig\";\n// These plan definitions should all be colocated with their implementations, only here for convenience\nexport { type AutoFocusConfig, AutoFocusPlan } from \"./AutoFocusPlan\";\nexport { DragonPlan } from \"./DragonPlan\";\nexport { type HistoryConfig, HistoryPlan } from \"./HistoryPlan\";\nexport { PlainTextPlan } from \"./PlainTextPlan\";\nexport { RichTextPlan } from \"./RichTextPlan\";\n\n/**\n * An open interface for Name -> Config mappings. If you are defining a\n * plan with non-empty config and it may be used as a peerDependency then\n * you should extend this as follows:\n *\n * @example Extending LexicalPlanRegistry\n * ```ts\n * export const SomePlan = definePlan({\n * name: \"@some/plan\",\n * config: { className: \"default\" }\n * });\n * declare module '@etrepum/lexical-builder' {\n * interface LexicalPlanRegistry {\n * [SomePlan.name]: typeof SomePlan;\n * }\n * }\n * ```\n */\nexport interface LexicalPlanRegistry {}\n"],"names":[],"mappings":";;;;;;;;;;;;AAgDO,SAAS,WACd,MAC2B;AACpB,SAAA;AACT;AAoBO,SAAS,eACd,UACuC;AAEhC,SAAA,OAAO,OAAO,UAAU,EAAE,MAAM,UAAU,QAAQ,CAAC,EAAA,CAAG;AAC/D;AAuBO,SAAS,cACX,MAC0C;AACtC,SAAA;AACT;AC7FwB,SAAA,UACtB,MACA,YACG,MACW;AACd,MAAI,MAAM;AACR;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR,KAAK,OAAO,CAAC,KAAK,QAAQ,IAAI,QAAQ,MAAM,OAAO,GAAG,CAAC,GAAG,WAAW,EAAE;AAAA,EAAA;AAE3E;ACCgB,SAAA,sBAAsB,GAAY,GAAY;AAC5D,MACE,KACA,KACA,CAAC,MAAM,QAAQ,CAAC,KAChB,OAAO,MAAM,YACb,OAAO,MAAM,UACb;AACA,UAAM,OAAO;AACb,UAAM,OAAO;AACb,eAAW,KAAK,MAAM;AACf,WAAA,CAAC,IAAI,sBAAsB,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAAA,IAClD;AACO,WAAA;AAAA,EACT;AACO,SAAA;AACT;AC5BA,MAAM,wBAAwB,EAAE,KAAK;AAErC,SAAS,sBAAsB;AAC7B,QAAM,OAAO;AACT,MAAA,KAAK,WAAW;AACb,SAAA,OAAO,sBAAsB;AAAA,EACpC;AACF;AAEgB,SAAA,iBACd,QACA,sBAA8C,qBACxC;AACN,UAAQ,O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CACR;AAAA,EACD,MAAM;AAAA,EACN,SAAS,QAAQ,EAAE,OAAO,6BAA6B;AACrD,WAAO,gBAAgB,QAAQ,0BAA0B,GAAG,KAAK;AAAA,EACnE;AACF,CAAC;AClCM,MAAM,gBAAgB,WAAW;AAAA,EACtC,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC,oBAAoB;AAAA,EACpC,MAAM;AAAA,EACN,UAAU;AACZ,CAAC;ACHM,MAAM,eAAe,WAAW;AAAA,EACrC,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC,qBAAqB;AAAA,EACrC,MAAM;AAAA,EACN,OAAO,CAAC,aAAa,SAAS;AAAA,EAC9B,UAAU;AACZ,CAAC;ACdY,MAAA,kBAA0B;"}
@@ -1,4 +1,11 @@
1
1
  import { PlanConfigBase } from './types';
2
2
 
3
- export declare function shallowMergeConfig<T extends PlanConfigBase>(a: T, b?: Partial<T>): T;
3
+ /**
4
+ * The default merge strategy for plan configuration is a shallow merge.
5
+ *
6
+ * @param config A full config
7
+ * @param overrides A partial config of overrides
8
+ * @returns config if there are no overrides, otherwise `{...config, ...overrides}`
9
+ */
10
+ export declare function shallowMergeConfig<T extends PlanConfigBase>(config: T, overrides?: Partial<T>): T;
4
11
  //# sourceMappingURL=shallowMergeConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shallowMergeConfig.d.ts","sourceRoot":"","sources":["../src/shallowMergeConfig.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,cAAc,EACzD,CAAC,EAAE,CAAC,EACJ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GACb,CAAC,CAUH"}
1
+ {"version":3,"file":"shallowMergeConfig.d.ts","sourceRoot":"","sources":["../src/shallowMergeConfig.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,cAAc,EACzD,MAAM,EAAE,CAAC,EACT,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GACrB,CAAC,CAUH"}
package/dist/types.d.ts CHANGED
@@ -1,15 +1,52 @@
1
1
  import { CreateEditorArgs, EditorState, LexicalEditor } from 'lexical';
2
+ import { LexicalPlanRegistry } from '@etrepum/lexical-builder';
2
3
 
4
+ /**
5
+ * Any concrete {@link LexicalPlan}
6
+ */
3
7
  export type AnyLexicalPlan = LexicalPlan<any, string>;
8
+ /**
9
+ * Any {@link LexicalPlan} or {@link NormalizedLexicalPlanArgument}
10
+ */
4
11
  export type AnyLexicalPlanArgument = LexicalPlanArgument<any, string>;
12
+ /**
13
+ * The default plan configuration of an empty object
14
+ */
5
15
  export type PlanConfigBase = Record<never, never>;
6
- export type NormalizedLexicalPlanArgument<Config extends PlanConfigBase, Name extends string> = [LexicalPlan<Config, Name>, Config, ...Config[]];
16
+ /**
17
+ * A tuple of [plan, configOverride, ...configOverrides]
18
+ */
19
+ export type NormalizedLexicalPlanArgument<Config extends PlanConfigBase, Name extends string> = [LexicalPlan<Config, Name>, Partial<Config>, ...Partial<Config>[]];
20
+ /**
21
+ * An object that the register method can use to detect unmount and access the
22
+ * configuration for plan dependencies
23
+ */
7
24
  export interface RegisterState {
25
+ /** An AbortSignal that is aborted when the EditorHandle is disposed */
8
26
  signal: AbortSignal;
27
+ /**
28
+ * Get the configuration of a peerDependency by name, if it exists
29
+ * (must be a peerDependency of this plan)
30
+ */
9
31
  getPeerConfig<Name extends keyof LexicalPlanRegistry>(name: string): undefined | LexicalPlanConfig<LexicalPlanRegistry[Name]>;
32
+ /**
33
+ * Get the configuration of a dependency by plan
34
+ * (must be a direct dependency of this plan)
35
+ */
10
36
  getDependencyConfig<Dependency extends AnyLexicalPlan>(dep: Dependency): LexicalPlanConfig<Dependency>;
11
37
  }
38
+ /**
39
+ * A {@link LexicalPlan} or {@link NormalizedLexicalPlanArgument} (plan with config overrides)
40
+ */
12
41
  export type LexicalPlanArgument<Config extends PlanConfigBase, Name extends string> = LexicalPlan<Config, Name> | NormalizedLexicalPlanArgument<Config, Name>;
42
+ /**
43
+ * A Plan is a composable unit of LexicalEditor configuration
44
+ * (nodes, theme, etc) used to create an editor, plus runtime behavior
45
+ * that is registered after the editor is created.
46
+ *
47
+ * A Plan may depend on other Plans, and provide functionality to other
48
+ * plans through its config.
49
+ */
13
50
  export interface LexicalPlan<Config extends PlanConfigBase = PlanConfigBase, Name extends string = string> {
14
51
  /** The name of the Plan, must be unique */
15
52
  name: Name;
@@ -22,7 +59,7 @@ export interface LexicalPlan<Config extends PlanConfigBase = PlanConfigBase, Nam
22
59
  * configure, if they are directly depended on by another Plan
23
60
  */
24
61
  peerDependencies?: {
25
- [k in keyof LexicalPlanRegistry]?: LexicalPeerConfig<k>;
62
+ [k in keyof LexicalPlanRegistry]?: Partial<LexicalPeerConfig<k>>;
26
63
  };
27
64
  /**
28
65
  * @internal Disable root element events (for internal Meta use)
@@ -59,7 +96,7 @@ export interface LexicalPlan<Config extends PlanConfigBase = PlanConfigBase, Nam
59
96
  /**
60
97
  * The editor will catch errors that happen during updates and
61
98
  * reconciliation and call this. It defaults to
62
- * `(error) => console.error(error)`.
99
+ * `(error) => { throw error }`.
63
100
  *
64
101
  * @param error The Error object
65
102
  * @param editor The editor that this error came from
@@ -67,23 +104,27 @@ export interface LexicalPlan<Config extends PlanConfigBase = PlanConfigBase, Nam
67
104
  onError?: (error: Error, editor: LexicalEditor) => void;
68
105
  /**
69
106
  * The initial EditorState as a JSON string, an EditorState, or a function
70
- * to update the editor once.
107
+ * to update the editor (once).
71
108
  */
72
109
  $initialEditorState?: InitialEditorStateType;
73
110
  /**
74
- * The default configuration specific to this Plan
111
+ * The default configuration specific to this Plan. This Config may be
112
+ * seen by this Plan, or any Plan that uses it as a dependency.
113
+ *
114
+ * The config may be mutated on register, this is particularly useful
115
+ * for vending functionality to other Plans that depend on this Plan.
75
116
  */
76
117
  config: Config;
77
118
  /**
78
- * By default, Config is shallow merged `{...a, ...b}`, if your Plan
79
- * requires other strategies (such as concatenating an Array) you can
80
- * implement it here.
119
+ * By default, Config is shallow merged `{...a, ...b}` with
120
+ * {@link shallowMergeConfig}, if your Plan requires other strategies
121
+ * (such as concatenating an Array) you can implement it here.
81
122
  *
82
- * @param a The current configuration
83
- * @param b The partial configuration to merge
123
+ * @param config The current configuration
124
+ * @param overrides The partial configuration to merge
84
125
  * @returns The merged configuration
85
126
  */
86
- mergeConfig?: (a: Config, b?: Partial<Config>) => Config;
127
+ mergeConfig?: (config: Config, overrides?: Partial<Config>) => Config;
87
128
  /**
88
129
  * Add behavior to the editor (register transforms, listeners, etc.) after
89
130
  * the Editor is created.
@@ -97,31 +138,39 @@ export interface LexicalPlan<Config extends PlanConfigBase = PlanConfigBase, Nam
97
138
  */
98
139
  register?: (editor: LexicalEditor, config: Config, state: RegisterState) => () => void;
99
140
  }
141
+ /**
142
+ * Get the Config type of a peer Plan from {@link LexicalPlanRegistry} by
143
+ * name, or the empty {@link PlanConfigBase} if it is not globally registered.
144
+ */
100
145
  export type LexicalPeerConfig<Name extends keyof LexicalPlanRegistry | string> = [
101
146
  Name
102
147
  ] extends [keyof LexicalPlanRegistry] ? LexicalPlanRegistry[Name] : PlanConfigBase;
148
+ /**
149
+ * Extract the Config type from a Plan
150
+ */
103
151
  export type LexicalPlanConfig<Plan extends AnyLexicalPlan> = Plan["config"];
152
+ /**
153
+ * Extract the Name type from a Plan
154
+ */
104
155
  export type LexicalPlanName<Plan extends AnyLexicalPlan> = Plan["name"];
156
+ /**
157
+ * A handle to the editor and its dispose function
158
+ */
105
159
  export interface EditorHandle extends Disposable {
160
+ /** The created editor */
106
161
  editor: LexicalEditor;
162
+ /**
163
+ * Dispose the editor and perform all clean-up
164
+ * (also available as Symbol.dispose via Disposable)
165
+ */
107
166
  dispose: () => void;
108
167
  }
109
- export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
110
168
  /**
111
- * An open interface for Name -> Config mappings. If you are defining a
112
- * plan with non-empty config and it may be used as a peerDependency then
113
- * you should extend this as follows:
114
- *
115
- * @example Extending LexicalPlanRegistry
116
- * ```ts
117
- * export const SomePlan = definePlan({ name: "@some/plan", config: { className: "default" } });
118
- * declare module '@etrepum/lexical-builder' {
119
- * interface LexicalPlanRegistry {
120
- * [SomePlan.name]: typeof SomePlan;
121
- * }
122
- * }
123
- * ```
169
+ * All of the possible ways to initialize $initialEditorState:
170
+ * - `null` an empty state, the default
171
+ * - `string` an EditorState serialized to JSON
172
+ * - `EditorState` an EditorState that has been deserialized already (not just parsed JSON)
173
+ * - `((editor: LexicalEditor) => void)` A function that is called with the editor for you to mutate it
124
174
  */
125
- export interface LexicalPlanRegistry {
126
- }
175
+ export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
127
176
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG5E,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAEtD,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACtE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAElD,MAAM,MAAM,6BAA6B,CACvC,MAAM,SAAS,cAAc,EAC7B,IAAI,SAAS,MAAM,IACjB,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,M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K,MAAM,CAAC;IACtE;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,CACT,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,aAAa,KACjB,MAAM,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,MAAM,mBAAmB,GAAG,MAAM,IAC3E;IAAC,IAAI;CAAC,SAAS,CAAC,MAAM,mBAAmB,CAAC,GACtC,mBAAmB,CAAC,IAAI,CAAC,GACzB,cAAc,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,yBAAyB;IACzB,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAC9B,IAAI,GACJ,MAAM,GACN,WAAW,GACX,CAAC,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC,CAAC"}
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "test": "vitest run",
18
18
  "test:watch": "vitest"
19
19
  },
20
- "version": "0.0.10-nightly.20240604.0",
20
+ "version": "0.0.11",
21
21
  "license": "MIT",
22
22
  "repository": {
23
23
  "type": "git",
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "homepage": "https://github.com/etrepum/lexical-builder",
31
31
  "peerDependencies": {
32
- "@lexical/dragon": ">=0.15.0",
33
- "@lexical/history": ">=0.15.0",
34
- "@lexical/plain-text": ">=0.15.0",
35
- "@lexical/rich-text": ">=0.15.0",
36
- "@lexical/text": ">=0.15.0",
37
- "@lexical/utils": ">=0.15.0",
38
- "lexical": ">=0.15.0"
32
+ "@lexical/dragon": ">=0.16.0",
33
+ "@lexical/history": ">=0.16.0",
34
+ "@lexical/plain-text": ">=0.16.0",
35
+ "@lexical/rich-text": ">=0.16.0",
36
+ "@lexical/text": ">=0.16.0",
37
+ "@lexical/utils": ">=0.16.0",
38
+ "lexical": ">=0.16.0"
39
39
  },
40
40
  "sideEffects": false,
41
41
  "devDependencies": {