@etrepum/lexical-builder 0.0.3-nightly.20240530.0 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -208,7 +208,8 @@ interface ReactConfig {
208
208
  placeholder: ((isEditable: boolean) => null | JSX.Element) | null | JSX.Element;
209
209
  ErrorBoundary: ErrorBoundaryType;
210
210
  EditorChildrenComponent: EditorChildrenComponentType;
211
- setComponent: (component: undefined | EditorComponentType, context: LexicalComposerContextWithEditor) => void;
211
+ Component: EditorComponentType;
212
+ getContext: () => LexicalComposerContextWithEditor;
212
213
  decorators: readonly DecoratorComponentType[];
213
214
  }
214
215
  interface LexicalPlanComposerProps {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts","../src/types.ts","../src/definePlan.ts","../src/safeCast.ts","../src/AutoFocusPlan.ts","../src/DragonPlan.ts","../src/HistoryPlan.ts","../src/shared/invariant.ts","../src/deepThemeMergeInPlace.ts","../src/initializeEditor.ts","../src/shallowMergeConfig.ts","../src/PlanRep.ts","../src/LexicalBuilder.ts","../src/PlainTextPlan.ts","../src/registerSubscription.ts","../src/registerShowPlaceholder.ts","../src/shared/useLayoutEffect.ts","../src/useReactDecorators.tsx","../src/useRegisterSubscription.ts","../src/ReactPlan.tsx","../src/ReactPluginHostPlan.tsx","../src/RichTextPlan.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AAEH,OAAO,k0BAAuC,CAAwB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts","../src/types.ts","../src/definePlan.ts","../src/safeCast.ts","../src/AutoFocusPlan.ts","../src/DragonPlan.ts","../src/HistoryPlan.ts","../src/shared/invariant.ts","../src/deepThemeMergeInPlace.ts","../src/initializeEditor.ts","../src/shallowMergeConfig.ts","../src/PlanRep.ts","../src/LexicalBuilder.ts","../src/PlainTextPlan.ts","../src/registerSubscription.ts","../src/registerShowPlaceholder.ts","../src/shared/useLayoutEffect.ts","../src/useReactDecorators.tsx","../src/useRegisterSubscription.ts","../src/ReactPlan.tsx","../src/ReactPluginHostPlan.tsx","../src/RichTextPlan.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AAEH,OAAO,k0BAAuC,CAAwB"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { registerDragonSupport } from '@lexical/dragon';
2
- import { createEmptyHistoryState, registerHistory } from '@lexical/history';
2
+ import { registerHistory, createEmptyHistoryState } from '@lexical/history';
3
3
  import { $getRoot, $createParagraphNode, createEditor, createCommand, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR } from 'lexical';
4
4
  import { registerPlainText } from '@lexical/plain-text';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -31454,21 +31454,23 @@ function useRegisterSubscription(subscription) {
31454
31454
  return useLexicalSubscription(sub);
31455
31455
  }
31456
31456
 
31457
- function notImplemented() { }
31458
31457
  const scheduleMicrotask = "queueMicrotask" in globalThis
31459
31458
  ? queueMicrotask
31460
31459
  : (fn) => Promise.resolve().then(fn);
31461
31460
  function LexicalPlanComposer({ plan, children, }) {
31462
31461
  const componentRef = useRef(undefined);
31463
31462
  const handle = useMemo(() => {
31464
- return LexicalBuilder.fromPlans([
31465
- ReactPlan,
31466
- safeCast({
31467
- setComponent: (component) => {
31468
- componentRef.current = component;
31469
- },
31470
- }),
31471
- ], plan).buildEditor();
31463
+ return LexicalBuilder.fromPlans({
31464
+ name: "@lexical/builder/LexicalPlanComposer",
31465
+ config: {},
31466
+ dependencies: [ReactPlan],
31467
+ register(_editor, _config, state) {
31468
+ componentRef.current = state.getDependencyConfig(ReactPlan).Component;
31469
+ return () => {
31470
+ componentRef.current = undefined;
31471
+ };
31472
+ },
31473
+ }, plan).buildEditor();
31472
31474
  }, [plan]);
31473
31475
  useEffect(() => {
31474
31476
  // This is an awful trick to detect StrictMode
@@ -31488,7 +31490,8 @@ function LexicalPlanComposer({ plan, children, }) {
31488
31490
  function DefaultEditorChildrenComponent({ contentEditable, placeholder, children, }) {
31489
31491
  return (jsxs(Fragment, { children: [contentEditable, placeholder && jsx(Placeholder, { content: placeholder }), children] }));
31490
31492
  }
31491
- function buildEditorComponent(context, config) {
31493
+ function buildEditorComponent(config) {
31494
+ const context = config.getContext();
31492
31495
  const [editor] = context;
31493
31496
  const rawConfigDecorators = config.decorators.map((El) => typeof El === "function" ? jsx(El, { context: context }) : El);
31494
31497
  return function EditorComponent(props) {
@@ -31513,15 +31516,23 @@ function Placeholder({ content, }) {
31513
31516
  return content;
31514
31517
  }
31515
31518
  }
31519
+ const initialConfig = {
31520
+ EditorChildrenComponent: DefaultEditorChildrenComponent,
31521
+ ErrorBoundary: LexicalErrorBoundary,
31522
+ contentEditable: jsx(ContentEditable, {}),
31523
+ decorators: [],
31524
+ placeholder: null,
31525
+ // Initialized on registration
31526
+ Component() {
31527
+ invariant(false, "ReactPlan used before register");
31528
+ },
31529
+ // Initialized on registration
31530
+ getContext() {
31531
+ invariant(false, "ReactPlan used before register");
31532
+ },
31533
+ };
31516
31534
  const ReactPlan = definePlan({
31517
- config: safeCast({
31518
- EditorChildrenComponent: DefaultEditorChildrenComponent,
31519
- ErrorBoundary: LexicalErrorBoundary,
31520
- contentEditable: jsx(ContentEditable, {}),
31521
- decorators: [],
31522
- placeholder: null,
31523
- setComponent: notImplemented,
31524
- }),
31535
+ config: initialConfig,
31525
31536
  mergeConfig(a, b) {
31526
31537
  const config = shallowMergeConfig(a, b);
31527
31538
  if (b && b.decorators && b.decorators.length > 0) {
@@ -31535,9 +31546,11 @@ const ReactPlan = definePlan({
31535
31546
  editor,
31536
31547
  { getTheme: () => editor._config.theme },
31537
31548
  ];
31538
- config.setComponent(buildEditorComponent(context, config), context);
31549
+ config.getContext = () => context;
31550
+ config.Component = buildEditorComponent(config);
31539
31551
  return () => {
31540
- config.setComponent(undefined, context);
31552
+ config.getContext = initialConfig.getContext;
31553
+ config.Component = initialConfig.Component;
31541
31554
  };
31542
31555
  },
31543
31556
  });
@@ -31575,7 +31588,6 @@ function mountReactPluginHost(editor, container) {
31575
31588
  root: createRoot(container),
31576
31589
  });
31577
31590
  }
31578
- const componentMap = new WeakMap();
31579
31591
  const REACT_PLUGIN_HOST_MOUNT_COMMAND = createCommand("REACT_PLUGIN_HOST_MOUNT_COMMAND");
31580
31592
  const REACT_MOUNT_PLUGIN_COMMAND = createCommand("REACT_MOUNT_PLUGIN_COMMAND");
31581
31593
  const ReactPluginHostPlan = definePlan({
@@ -31583,22 +31595,13 @@ const ReactPluginHostPlan = definePlan({
31583
31595
  dependencies: [
31584
31596
  configPlan(ReactPlan, {
31585
31597
  contentEditable: null,
31586
- setComponent(Component, context) {
31587
- const [editor] = context;
31588
- if (Component) {
31589
- componentMap.set(editor, [Component, context]);
31590
- }
31591
- else {
31592
- componentMap.delete(editor);
31593
- }
31594
- },
31595
31598
  }),
31596
31599
  ],
31597
31600
  name: "@etrepum/lexical-builder/ReactPluginHostPlan",
31598
31601
  register(editor, _config, state) {
31599
31602
  let root;
31600
31603
  const mountedPlugins = new Map();
31601
- const { ErrorBoundary } = state.getDependencyConfig(ReactPlan);
31604
+ const { ErrorBoundary, Component } = state.getDependencyConfig(ReactPlan);
31602
31605
  function renderMountedPlugins() {
31603
31606
  const children = [];
31604
31607
  for (const { key, element, domNode } of mountedPlugins.values()) {
@@ -31629,9 +31632,6 @@ const ReactPluginHostPlan = definePlan({
31629
31632
  return false;
31630
31633
  }, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(REACT_PLUGIN_HOST_MOUNT_COMMAND, (arg) => {
31631
31634
  root = arg.root;
31632
- const pair = componentMap.get(editor);
31633
- invariant(pair !== undefined, "ReactPluginHostPlan: Expecting ReactPlan to have called setComponent");
31634
- const [Component] = pair;
31635
31635
  root.render(jsx(Component, { children: jsx(PluginHost, {}) }));
31636
31636
  return true;
31637
31637
  }, COMMAND_PRIORITY_EDITOR));
package/package.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "lexical",
7
7
  "editor",
8
8
  "builder",
9
+ "lexical-builder",
9
10
  "configuration",
10
11
  "plugin",
11
12
  "plug-in"
@@ -16,7 +17,7 @@
16
17
  "test": "vitest run",
17
18
  "test:watch": "vitest"
18
19
  },
19
- "version": "0.0.3-nightly.20240530.0",
20
+ "version": "0.0.4",
20
21
  "license": "MIT",
21
22
  "repository": {
22
23
  "type": "git",