@lobehub/editor 4.23.1 โ†’ 4.23.2

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.
Files changed (51) hide show
  1. package/es/editor-kernel/index.js +1 -0
  2. package/es/editor-kernel/kernel.js +47 -40
  3. package/es/editor-kernel/react/useLexicalNodeSelection.js +4 -2
  4. package/es/headless.js +201 -175
  5. package/es/index.js +5 -2
  6. package/es/plugins/auto-complete/plugin/index.js +4 -2
  7. package/es/plugins/block/react/ReactBlockPlugin.js +5 -4
  8. package/es/plugins/codeblock/command/index.js +8 -6
  9. package/es/plugins/codeblock/plugin/index.js +4 -2
  10. package/es/plugins/codeblock/react/ReactCodeblockPlugin.js +2 -1
  11. package/es/plugins/codemirror-block/command/index.js +8 -6
  12. package/es/plugins/common/data-source/json-data-source.js +5 -4
  13. package/es/plugins/common/plugin/index.js +1 -3
  14. package/es/plugins/common/plugin/paste-handler.js +2 -1
  15. package/es/plugins/hr/command/index.js +2 -1
  16. package/es/plugins/image/react/components/BrokenImage.js +2 -1
  17. package/es/plugins/image/react/components/Image.js +18 -15
  18. package/es/plugins/image/react/components/ImageEditPopover.js +42 -41
  19. package/es/plugins/image/react/components/ResizeHandle.js +1 -3
  20. package/es/plugins/link/node/LinkNode.js +4 -2
  21. package/es/plugins/link/plugin/registry.js +17 -12
  22. package/es/plugins/link/react/components/LinkEdit.js +9 -8
  23. package/es/plugins/list/plugin/index.js +1 -4
  24. package/es/plugins/list/utils/index.js +4 -2
  25. package/es/plugins/litexml/command/index.js +69 -62
  26. package/es/plugins/litexml/node/DiffNode.js +14 -10
  27. package/es/plugins/litexml/plugin/index.js +6 -12
  28. package/es/plugins/markdown/data-source/markdown-data-source.js +5 -4
  29. package/es/plugins/markdown/plugin/index.js +2 -1
  30. package/es/plugins/markdown/service/transformers.js +4 -2
  31. package/es/plugins/markdown/utils/index.js +10 -8
  32. package/es/plugins/math/command/index.js +4 -2
  33. package/es/plugins/math/react/components/MathInline.js +14 -13
  34. package/es/plugins/slash/plugin/index.js +13 -4
  35. package/es/plugins/slash/react/components/DefaultSlashMenu.js +2 -1
  36. package/es/plugins/slash/react/components/menuLoading.js +4 -0
  37. package/es/plugins/slash/service/i-slash-service.d.ts +6 -1
  38. package/es/plugins/slash/service/i-slash-service.js +16 -2
  39. package/es/plugins/slash/utils/utils.js +1 -1
  40. package/es/plugins/table/react/TableActionMenu/ActionMenu.js +69 -67
  41. package/es/plugins/table/react/TableColController.js +29 -26
  42. package/es/plugins/table/react/TableHoverActions/index.js +0 -2
  43. package/es/plugins/table/react/TableRowController.js +29 -26
  44. package/es/plugins/table/utils/index.js +4 -2
  45. package/es/react/Editor/Editor.js +24 -23
  46. package/es/react/hooks/useEditorState/index.js +28 -21
  47. package/es/react/hooks/useEditorState/utils.js +2 -1
  48. package/es/renderer/engine/render-builtin-node.js +26 -18
  49. package/es/renderer/engine/render-tree.js +4 -1
  50. package/es/renderer/renderers/mermaid.js +2 -1
  51. package/package.json +1 -1
@@ -7,6 +7,7 @@ import { resetRandomKey as resetRandomKey$1 } from "lexical";
7
7
  init_kernel();
8
8
  init_utils();
9
9
  init_event();
10
+ init_utils();
10
11
  /**
11
12
  * Editor object to create an instance of the editor
12
13
  */
@@ -384,17 +384,19 @@ var init_kernel = __esmMin((() => {
384
384
  return datasource.write(this.editor, { selection: true });
385
385
  }
386
386
  registerDecorator(name, decorator) {
387
- if (this.decorators[name]) if (this.hotReloadMode) {
388
- this.logger.warn(`๐Ÿ”„ Hot reload: decorator "${name}"`);
389
- this.decorators[name] = decorator;
390
- return this;
391
- } else {
392
- if (this.decorators[name] === decorator) {
393
- this.logger.warn(`[Editor] Decorator "${name}" is already registered with the same function`);
387
+ if (this.decorators[name]) {
388
+ if (this.hotReloadMode) {
389
+ this.logger.warn(`๐Ÿ”„ Hot reload: decorator "${name}"`);
390
+ this.decorators[name] = decorator;
394
391
  return this;
392
+ } else {
393
+ if (this.decorators[name] === decorator) {
394
+ this.logger.warn(`[Editor] Decorator "${name}" is already registered with the same function`);
395
+ return this;
396
+ }
397
+ this.logger.error(`[Editor] Attempting to register duplicate decorator "${name}". Enable hot reload mode if this is intended.`);
398
+ throw new Error(`Decorator with name "${name}" is already registered.`);
395
399
  }
396
- this.logger.error(`[Editor] Attempting to register duplicate decorator "${name}". Enable hot reload mode if this is intended.`);
397
- throw new Error(`Decorator with name "${name}" is already registered.`);
398
400
  }
399
401
  this.decorators[name] = decorator;
400
402
  this.logger.debug(`๐ŸŽญ Decorator: ${name}`);
@@ -435,31 +437,34 @@ var init_kernel = __esmMin((() => {
435
437
  }
436
438
  registerPlugin(plugin, config) {
437
439
  const findPlugin = this.plugins.find((p) => p.pluginName === plugin.pluginName);
438
- if (findPlugin) if (findPlugin !== plugin) if (this.hotReloadMode) {
439
- this.logger.warn(`๐Ÿ”„ Hot reload: plugin "${plugin.pluginName}"`);
440
- const index = this.plugins.findIndex((p) => p.pluginName === plugin.pluginName);
441
- if (index !== -1) {
442
- this.plugins.splice(index, 1);
443
- const instanceIndex = this.pluginsInstances.findIndex((instance) => {
444
- return instance.constructor.pluginName === plugin.pluginName;
445
- });
446
- if (instanceIndex !== -1) {
447
- const oldInstance = this.pluginsInstances[instanceIndex];
448
- if (oldInstance instanceof KernelPlugin) {
449
- const decoratorNames = oldInstance.getRegisteredDecorators();
450
- for (const decoratorName of decoratorNames) {
451
- this.unregisterDecorator(decoratorName);
452
- this.logger.debug(`๐Ÿงจ Cleanup: decorator "${decoratorName}"`);
440
+ if (findPlugin) {
441
+ if (findPlugin !== plugin) {
442
+ if (this.hotReloadMode) {
443
+ this.logger.warn(`๐Ÿ”„ Hot reload: plugin "${plugin.pluginName}"`);
444
+ const index = this.plugins.findIndex((p) => p.pluginName === plugin.pluginName);
445
+ if (index !== -1) {
446
+ this.plugins.splice(index, 1);
447
+ const instanceIndex = this.pluginsInstances.findIndex((instance) => {
448
+ return instance.constructor.pluginName === plugin.pluginName;
449
+ });
450
+ if (instanceIndex !== -1) {
451
+ const oldInstance = this.pluginsInstances[instanceIndex];
452
+ if (oldInstance instanceof KernelPlugin) {
453
+ const decoratorNames = oldInstance.getRegisteredDecorators();
454
+ for (const decoratorName of decoratorNames) {
455
+ this.unregisterDecorator(decoratorName);
456
+ this.logger.debug(`๐Ÿงจ Cleanup: decorator "${decoratorName}"`);
457
+ }
458
+ }
459
+ if (oldInstance.destroy) oldInstance.destroy();
460
+ this.pluginsInstances.splice(instanceIndex, 1);
453
461
  }
454
462
  }
455
- if (oldInstance.destroy) oldInstance.destroy();
456
- this.pluginsInstances.splice(instanceIndex, 1);
457
- }
463
+ } else throw new Error(`Plugin with name "${plugin.pluginName}" is already registered with a different implementation.`);
464
+ } else {
465
+ if (config !== void 0) this.pluginsConfig.set(plugin, config);
466
+ return this;
458
467
  }
459
- } else throw new Error(`Plugin with name "${plugin.pluginName}" is already registered with a different implementation.`);
460
- else {
461
- if (config !== void 0) this.pluginsConfig.set(plugin, config);
462
- return this;
463
468
  }
464
469
  this.pluginsConfig.set(plugin, config || {});
465
470
  this.plugins.push(plugin);
@@ -526,17 +531,19 @@ var init_kernel = __esmMin((() => {
526
531
  }
527
532
  registerService(serviceId, service) {
528
533
  const serviceIdString = serviceId.__serviceId;
529
- if (this.serviceMap.has(serviceIdString)) if (this.hotReloadMode) {
530
- this.logger.warn(`๐Ÿ”„ Hot reload: service "${serviceIdString}"`);
531
- this.serviceMap.set(serviceIdString, service);
532
- return;
533
- } else {
534
- if (this.serviceMap.get(serviceIdString) === service) {
535
- this.logger.warn(`[Editor] Service "${serviceIdString}" is already registered with the same instance`);
534
+ if (this.serviceMap.has(serviceIdString)) {
535
+ if (this.hotReloadMode) {
536
+ this.logger.warn(`๐Ÿ”„ Hot reload: service "${serviceIdString}"`);
537
+ this.serviceMap.set(serviceIdString, service);
536
538
  return;
539
+ } else {
540
+ if (this.serviceMap.get(serviceIdString) === service) {
541
+ this.logger.warn(`[Editor] Service "${serviceIdString}" is already registered with the same instance`);
542
+ return;
543
+ }
544
+ this.logger.error(`[Editor] Attempting to register duplicate service "${serviceIdString}". Enable hot reload mode if this is intended.`);
545
+ throw new Error(`Service with ID "${serviceIdString}" is already registered.`);
537
546
  }
538
- this.logger.error(`[Editor] Attempting to register duplicate service "${serviceIdString}". Enable hot reload mode if this is intended.`);
539
- throw new Error(`Service with ID "${serviceIdString}" is already registered.`);
540
547
  }
541
548
  this.serviceMap.set(serviceIdString, service);
542
549
  this.logger.debug(`๐Ÿ”ง Service: ${serviceIdString}`);
@@ -68,8 +68,10 @@ function useLexicalNodeSelection(key) {
68
68
  selection = $createNodeSelection();
69
69
  $setSelection(selection);
70
70
  }
71
- if ($isNodeSelection(selection)) if (selected) selection.add(key);
72
- else selection.delete(key);
71
+ if ($isNodeSelection(selection)) {
72
+ if (selected) selection.add(key);
73
+ else selection.delete(key);
74
+ }
73
75
  });
74
76
  }, [lexicalEditor, key]),
75
77
  useCallback(() => {