@lobehub/editor 1.0.0 → 1.0.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.
@@ -1,8 +1,10 @@
1
1
  import EventEmitter from 'eventemitter3';
2
2
  import { CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
3
+ import { IEditor, IEditorKernel, IEditorPluginConstructor, IPlugin, IServiceID } from "../types/kernel";
4
+ import { ILocaleKeys } from "../types/locale";
3
5
  import DataSource from './data-source';
4
- import { IEditor, IEditorKernel, IEditorPluginConstructor, ILocaleKeys, IPlugin, IServiceID } from './types';
5
6
  export declare class Kernel extends EventEmitter implements IEditorKernel {
7
+ private static globalHotReloadMode;
6
8
  private dataTypeMap;
7
9
  private plugins;
8
10
  private pluginsInstances;
@@ -11,8 +13,19 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
11
13
  private decorators;
12
14
  private serviceMap;
13
15
  private localeMap;
16
+ private hotReloadMode;
14
17
  private editor?;
15
18
  constructor();
19
+ private detectDevelopmentMode;
20
+ /**
21
+ * Globally enable or disable hot reload mode for all kernel instances
22
+ * @param enabled Whether to enable hot reload mode globally
23
+ */
24
+ static setGlobalHotReloadMode(enabled: boolean): void;
25
+ /**
26
+ * Reset global hot reload mode to automatic detection
27
+ */
28
+ static resetGlobalHotReloadMode(): void;
16
29
  getLexicalEditor(): LexicalEditor | null;
17
30
  destroy(): void;
18
31
  getRootElement(): HTMLElement | null;
@@ -33,6 +46,21 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
33
46
  registerPlugins(plugins: Array<IPlugin>): IEditor;
34
47
  registerNodes(nodes: Array<LexicalNodeConfig>): void;
35
48
  registerService<T>(serviceId: IServiceID<T>, service: T): void;
49
+ /**
50
+ * Register service with hot reload support - allows overriding existing services
51
+ * @param serviceId Service identifier
52
+ * @param service Service instance
53
+ */
54
+ registerServiceHotReload<T>(serviceId: IServiceID<T>, service: T): void;
55
+ /**
56
+ * Enable or disable hot reload mode
57
+ * @param enabled Whether to enable hot reload mode
58
+ */
59
+ setHotReloadMode(enabled: boolean): void;
60
+ /**
61
+ * Check if hot reload mode is enabled
62
+ */
63
+ isHotReloadMode(): boolean;
36
64
  /**
37
65
  * Get service
38
66
  * @param serviceId Service ID
@@ -42,11 +42,61 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
42
42
  _defineProperty(_assertThisInitialized(_this), "decorators", {});
43
43
  _defineProperty(_assertThisInitialized(_this), "serviceMap", new Map());
44
44
  _defineProperty(_assertThisInitialized(_this), "localeMap", defaultLocale);
45
+ _defineProperty(_assertThisInitialized(_this), "hotReloadMode", false);
45
46
  _defineProperty(_assertThisInitialized(_this), "editor", void 0);
46
47
  _this.dataTypeMap = new Map();
48
+ // Enable hot reload mode in development
49
+ _this.hotReloadMode = _this.detectDevelopmentMode();
47
50
  return _this;
48
51
  }
49
52
  _createClass(Kernel, [{
53
+ key: "detectDevelopmentMode",
54
+ value: function detectDevelopmentMode() {
55
+ var _process$env;
56
+ // Check global override first
57
+ if (Kernel.globalHotReloadMode !== undefined) {
58
+ return Kernel.globalHotReloadMode;
59
+ }
60
+
61
+ // Multiple ways to detect development mode
62
+ if (typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development') {
63
+ return true;
64
+ }
65
+
66
+ // Check for common development indicators
67
+ if (typeof window !== 'undefined') {
68
+ var _NEXT_DATA__;
69
+ // Webpack HMR
70
+ if (window.webpackHotUpdate) {
71
+ return true;
72
+ }
73
+ // Vite HMR
74
+ if (window.__vite_plugin_react_preamble_installed__) {
75
+ return true;
76
+ }
77
+ // Next.js development
78
+ if (((_NEXT_DATA__ = window.__NEXT_DATA__) === null || _NEXT_DATA__ === void 0 ? void 0 : _NEXT_DATA__.buildId) === 'development') {
79
+ return true;
80
+ }
81
+ }
82
+
83
+ // Check for localhost or development URLs
84
+ if (typeof window !== 'undefined' && window.location) {
85
+ var hostname = window.location.hostname;
86
+ if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.endsWith('.local')) {
87
+ return true;
88
+ }
89
+ }
90
+
91
+ // Default to development mode for better DX
92
+ return true;
93
+ }
94
+
95
+ /**
96
+ * Globally enable or disable hot reload mode for all kernel instances
97
+ * @param enabled Whether to enable hot reload mode globally
98
+ */
99
+ }, {
50
100
  key: "getLexicalEditor",
51
101
  value: function getLexicalEditor() {
52
102
  return this.editor || null;
@@ -63,6 +113,8 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
63
113
  }
64
114
  });
65
115
  this.pluginsInstances = [];
116
+ // Clear services to support hot reload
117
+ this.serviceMap.clear();
66
118
  }
67
119
  }, {
68
120
  key: "getRootElement",
@@ -74,18 +126,28 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
74
126
  key: "setRootElement",
75
127
  value: function setRootElement(dom) {
76
128
  var _this2 = this;
77
- var _iterator = _createForOfIteratorHelper(this.plugins),
78
- _step;
79
- try {
80
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
81
- var plugin = _step.value;
82
- var instance = new plugin(this, plugin.__config);
83
- this.pluginsInstances.push(instance);
129
+ // Check if editor is already initialized to prevent re-initialization
130
+ if (this.editor) {
131
+ console.warn('[Editor] Editor is already initialized, updating root element only');
132
+ this.editor.setRootElement(dom);
133
+ return this.editor;
134
+ }
135
+
136
+ // Initialize plugins if not already done
137
+ if (this.pluginsInstances.length === 0) {
138
+ var _iterator = _createForOfIteratorHelper(this.plugins),
139
+ _step;
140
+ try {
141
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
142
+ var plugin = _step.value;
143
+ var instance = new plugin(this, plugin.__config);
144
+ this.pluginsInstances.push(instance);
145
+ }
146
+ } catch (err) {
147
+ _iterator.e(err);
148
+ } finally {
149
+ _iterator.f();
84
150
  }
85
- } catch (err) {
86
- _iterator.e(err);
87
- } finally {
88
- _iterator.f();
89
151
  }
90
152
  var editor = this.editor = createEditor({
91
153
  // @ts-expect-error Inject into lexical editor instance
@@ -176,9 +238,37 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
176
238
  if (findPlugin) {
177
239
  // Error if same name but different plugin
178
240
  if (findPlugin !== plugin) {
179
- throw new Error("Plugin with name \"".concat(plugin.pluginName, "\" is already registered with a different implementation."));
241
+ if (this.hotReloadMode) {
242
+ console.warn("[Hot Reload] Replacing plugin \"".concat(plugin.pluginName, "\" with new implementation"));
243
+ // Remove old plugin
244
+ var index = this.plugins.findIndex(function (p) {
245
+ return p.pluginName === plugin.pluginName;
246
+ });
247
+ if (index !== -1) {
248
+ this.plugins.splice(index, 1);
249
+ // Also remove corresponding plugin instance if it exists
250
+ var instanceIndex = this.pluginsInstances.findIndex(function (instance) {
251
+ return instance.constructor.pluginName === plugin.pluginName;
252
+ });
253
+ if (instanceIndex !== -1) {
254
+ var oldInstance = this.pluginsInstances[instanceIndex];
255
+ if (oldInstance.destroy) {
256
+ oldInstance.destroy();
257
+ }
258
+ this.pluginsInstances.splice(instanceIndex, 1);
259
+ }
260
+ }
261
+ } else {
262
+ throw new Error("Plugin with name \"".concat(plugin.pluginName, "\" is already registered with a different implementation."));
263
+ }
264
+ } else {
265
+ // Same plugin, just update config if provided
266
+ if (config !== undefined) {
267
+ // @ts-expect-error not error
268
+ plugin.__config = config;
269
+ }
270
+ return this; // If plugin already exists, don't register again
180
271
  }
181
- return this; // If plugin already exists, don't register again
182
272
  }
183
273
  // @ts-expect-error not error
184
274
  plugin.__config = config || {};
@@ -216,12 +306,61 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
216
306
  }, {
217
307
  key: "registerService",
218
308
  value: function registerService(serviceId, service) {
219
- if (this.serviceMap.has(serviceId.__serviceId)) {
220
- throw new Error("Service with ID \"".concat(serviceId.__serviceId, "\" is already registered."));
309
+ var serviceIdString = serviceId.__serviceId;
310
+ if (this.serviceMap.has(serviceIdString)) {
311
+ if (this.hotReloadMode) {
312
+ // In hot reload mode, allow service override with warning
313
+ console.warn("[Hot Reload] Overriding service with ID \"".concat(serviceIdString, "\""));
314
+ this.serviceMap.set(serviceIdString, service);
315
+ return;
316
+ } else {
317
+ // Check if it's the same service instance
318
+ var existingService = this.serviceMap.get(serviceIdString);
319
+ if (existingService === service) {
320
+ // Same service instance, no need to re-register
321
+ console.warn("[Editor] Service \"".concat(serviceIdString, "\" is already registered with the same instance"));
322
+ return;
323
+ }
324
+
325
+ // Different service instance in production mode
326
+ console.error("[Editor] Attempting to register duplicate service \"".concat(serviceIdString, "\". Enable hot reload mode if this is intended."));
327
+ throw new Error("Service with ID \"".concat(serviceIdString, "\" is already registered."));
328
+ }
221
329
  }
330
+ this.serviceMap.set(serviceIdString, service);
331
+ console.debug("[Editor] Registered service: ".concat(serviceIdString));
332
+ }
333
+
334
+ /**
335
+ * Register service with hot reload support - allows overriding existing services
336
+ * @param serviceId Service identifier
337
+ * @param service Service instance
338
+ */
339
+ }, {
340
+ key: "registerServiceHotReload",
341
+ value: function registerServiceHotReload(serviceId, service) {
222
342
  this.serviceMap.set(serviceId.__serviceId, service);
223
343
  }
224
344
 
345
+ /**
346
+ * Enable or disable hot reload mode
347
+ * @param enabled Whether to enable hot reload mode
348
+ */
349
+ }, {
350
+ key: "setHotReloadMode",
351
+ value: function setHotReloadMode(enabled) {
352
+ this.hotReloadMode = enabled;
353
+ }
354
+
355
+ /**
356
+ * Check if hot reload mode is enabled
357
+ */
358
+ }, {
359
+ key: "isHotReloadMode",
360
+ value: function isHotReloadMode() {
361
+ return this.hotReloadMode;
362
+ }
363
+
225
364
  /**
226
365
  * Get service
227
366
  * @param serviceId Service ID
@@ -268,6 +407,22 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
268
407
  }
269
408
  return translation;
270
409
  }
410
+ }], [{
411
+ key: "setGlobalHotReloadMode",
412
+ value: function setGlobalHotReloadMode(enabled) {
413
+ Kernel.globalHotReloadMode = enabled;
414
+ }
415
+
416
+ /**
417
+ * Reset global hot reload mode to automatic detection
418
+ */
419
+ }, {
420
+ key: "resetGlobalHotReloadMode",
421
+ value: function resetGlobalHotReloadMode() {
422
+ Kernel.globalHotReloadMode = undefined;
423
+ }
271
424
  }]);
272
425
  return Kernel;
273
- }(EventEmitter);
426
+ }(EventEmitter);
427
+ // Global hot reload flag
428
+ _defineProperty(Kernel, "globalHotReloadMode", undefined);
@@ -1,5 +1,5 @@
1
1
  import { type RefObject } from 'react';
2
- import { IEditor } from '../types';
2
+ import { IEditor } from "../../types";
3
3
  /**
4
4
  * Provide toolbar state and toolbar methods
5
5
  * @returns
@@ -1,4 +1,4 @@
1
- import { EditorState, LexicalEditor, LexicalNode, NodeKey } from 'lexical';
1
+ import { LexicalEditor, LexicalNode, NodeKey } from 'lexical';
2
2
  import type { IEditorKernel, IServiceID } from "../types";
3
3
  export declare const DOM_ELEMENT_TYPE = 1;
4
4
  export declare const DOM_TEXT_TYPE = 3;
@@ -6,10 +6,10 @@ export declare const DOM_DOCUMENT_TYPE = 9;
6
6
  export declare const DOM_DOCUMENT_FRAGMENT_TYPE = 11;
7
7
  export declare function genServiceId<T>(name: string): IServiceID<T>;
8
8
  export declare const noop: () => void;
9
- export declare function createEmptyEditorState(): EditorState;
9
+ export declare function createEmptyEditorState(): import("lexical").EditorState;
10
10
  export declare function assert(cond?: boolean, message?: string): asserts cond;
11
11
  export declare function getNodeKeyFromDOMNode(dom: Node, editor: LexicalEditor): NodeKey | undefined;
12
- export declare function $getNodeFromDOMNode(dom: Node, editor: LexicalEditor, editorState?: EditorState): LexicalNode | null;
12
+ export declare function $getNodeFromDOMNode(dom: Node, editor: LexicalEditor, editorState?: ReturnType<LexicalEditor['getEditorState']>): LexicalNode | null;
13
13
  /**
14
14
  * @param x - The element being tested
15
15
  * @returns Returns true if x is a DOM Node, false otherwise.
@@ -21,5 +21,5 @@ export declare function isDOMNode(x: unknown): x is Node;
21
21
  */
22
22
  export declare function isDocumentFragment(x: unknown): x is DocumentFragment;
23
23
  export declare function getParentElement(node: Node): HTMLElement | null;
24
- export declare function $getNearestNodeFromDOMNode(startingDOM: Node, editor: LexicalEditor, editorState?: EditorState): LexicalNode | null;
24
+ export declare function $getNearestNodeFromDOMNode(startingDOM: Node, editor: LexicalEditor, editorState?: ReturnType<LexicalEditor['getEditorState']>): LexicalNode | null;
25
25
  export declare function getKernelFromEditor(editor: LexicalEditor): IEditorKernel;
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- import { $getNodeByKey, EditorState } from 'lexical';
2
+ import { $getNodeByKey, createEditor } from 'lexical';
3
3
  // DOM
4
4
  export var DOM_ELEMENT_TYPE = 1;
5
5
  export var DOM_TEXT_TYPE = 3;
@@ -12,7 +12,9 @@ export function genServiceId(name) {
12
12
  }
13
13
  export var noop = function noop() {};
14
14
  export function createEmptyEditorState() {
15
- return new EditorState(new Map(), null);
15
+ // Create a temporary editor to get an empty state
16
+ var tempEditor = createEditor();
17
+ return tempEditor.getEditorState();
16
18
  }
17
19
  export function assert(cond, message) {
18
20
  if (cond) {
package/es/index.d.ts CHANGED
@@ -12,3 +12,13 @@ export * from './plugins/slash';
12
12
  export * from './plugins/table';
13
13
  export * from './plugins/upload';
14
14
  export type { IEditor } from './types';
15
+ export { Kernel } from './editor-kernel/kernel';
16
+ /**
17
+ * Enable hot reload mode globally for all editor instances
18
+ * Call this in your app's entry point during development
19
+ */
20
+ export declare function enableHotReload(): void;
21
+ /**
22
+ * Disable hot reload mode globally
23
+ */
24
+ export declare function disableHotReload(): void;
package/es/index.js CHANGED
@@ -11,4 +11,30 @@ export * from "./plugins/mention";
11
11
  export * from "./plugins/slash";
12
12
  export * from "./plugins/table";
13
13
  export * from "./plugins/upload";
14
- export {};
14
+ // Hot reload utilities
15
+ export { Kernel } from "./editor-kernel/kernel";
16
+
17
+ /**
18
+ * Enable hot reload mode globally for all editor instances
19
+ * Call this in your app's entry point during development
20
+ */
21
+ export function enableHotReload() {
22
+ if (typeof window !== 'undefined') {
23
+ var _require = require("./editor-kernel/kernel"),
24
+ Kernel = _require.Kernel;
25
+ Kernel.setGlobalHotReloadMode(true);
26
+ console.log('[LobeHub Editor] Hot reload mode enabled globally');
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Disable hot reload mode globally
32
+ */
33
+ export function disableHotReload() {
34
+ if (typeof window !== 'undefined') {
35
+ var _require2 = require("./editor-kernel/kernel"),
36
+ Kernel = _require2.Kernel;
37
+ Kernel.setGlobalHotReloadMode(false);
38
+ console.log('[LobeHub Editor] Hot reload mode disabled globally');
39
+ }
40
+ }
@@ -1,6 +1,5 @@
1
- import { EditorState, LexicalEditor } from 'lexical';
1
+ import { LexicalEditor } from 'lexical';
2
2
  import { DataSource } from "../../../editor-kernel";
3
- export declare function createEmptyEditorState(): EditorState;
4
3
  export default class JSONDataSource extends DataSource {
5
4
  read(editor: LexicalEditor, data: any): void;
6
5
  write(editor: LexicalEditor): any;
@@ -11,11 +11,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
11
11
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
13
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
- import { EditorState, RootNode } from 'lexical';
15
14
  import { DataSource } from "../../../editor-kernel";
16
- export function createEmptyEditorState() {
17
- return new EditorState(new Map([['root', new RootNode()]]));
18
- }
19
15
  var JSONDataSource = /*#__PURE__*/function (_DataSource) {
20
16
  _inherits(JSONDataSource, _DataSource);
21
17
  var _super = _createSuper(JSONDataSource);
@@ -14,6 +14,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
14
14
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
15
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
16
  import { ElementDOMSlot } from 'lexical';
17
+ // @ts-ignore
17
18
  export var MElementDOMSlot = /*#__PURE__*/function (_ElementDOMSlot) {
18
19
  _inherits(MElementDOMSlot, _ElementDOMSlot);
19
20
  var _super = _createSuper(MElementDOMSlot);
@@ -68,7 +68,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
68
68
  editor.registerPlugin(CommonPlugin, {
69
69
  theme: restTheme ? _objectSpread(_objectSpread({}, themeStyles), restTheme) : themeStyles
70
70
  });
71
- }, []);
71
+ }, [editor, restTheme, themeStyles]);
72
72
  useEffect(function () {
73
73
  var _editor$getLexicalEdi;
74
74
  var container = editorContainerRef.current;
@@ -80,7 +80,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
80
80
  return (_editor$getLexicalEdi = editor.getLexicalEditor()) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.registerUpdateListener(function () {
81
81
  onChange === null || onChange === void 0 || onChange(editor);
82
82
  });
83
- }, []);
83
+ }, [editor, type, content, onChange]);
84
84
  return /*#__PURE__*/_jsxs("div", {
85
85
  className: cx(styles.root, styles.variant, className),
86
86
  style: style,
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n width: 100%;\n height: 4px;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 1.5em);\n border-color: ", ";\n border-style: dashed;\n border-width: 1px;\n border-block-start: none;\n border-inline-start: none;\n border-inline-end: none;\n\n &.selected {\n border-color: ", ";\n }\n "])), token.colorBorder, token.yellow);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n width: 100%;\n height: 4px;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n border-color: ", ";\n border-style: dashed;\n border-width: 1px;\n border-block-start: none;\n border-inline-start: none;\n border-inline-end: none;\n\n &.selected {\n border-color: ", ";\n }\n "])), token.colorBorder, token.yellow);
8
8
  });
@@ -29,8 +29,9 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
29
29
  var _this;
30
30
  _classCallCheck(this, MarkdownPlugin);
31
31
  _this = _super.call(this);
32
- _defineProperty(_assertThisInitialized(_this), "service", new MarkdownShortCutService());
32
+ _defineProperty(_assertThisInitialized(_this), "service", void 0);
33
33
  _this.kernel = kernel;
34
+ _this.service = new MarkdownShortCutService(kernel);
34
35
  kernel.registerService(IMarkdownShortCutService, _this.service);
35
36
  // @todo To be implemented
36
37
  kernel.registerDataSource(new MarkdownDataSource('markdown', _this.service));
@@ -1,5 +1,5 @@
1
1
  import { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical';
2
- import { IServiceID } from "../../../editor-kernel/types";
2
+ import { IServiceID } from "../../../types/kernel";
3
3
  export type TextFormatTransformer = Readonly<{
4
4
  format: ReadonlyArray<TextFormatType>;
5
5
  intraword?: boolean;
@@ -86,10 +86,12 @@ export interface IMarkdownShortCutService {
86
86
  }
87
87
  export declare const IMarkdownShortCutService: IServiceID<IMarkdownShortCutService>;
88
88
  export declare class MarkdownShortCutService implements IMarkdownShortCutService {
89
+ private kernel?;
89
90
  private elementTransformers;
90
91
  private textFormatTransformers;
91
92
  private textMatchTransformers;
92
93
  private _markdownWriters;
94
+ constructor(kernel?: import("../../../types/kernel").IEditorKernel | undefined);
93
95
  get markdownWriters(): Record<string, (ctx: IMarkdownWriterContext, node: LexicalNode) => void>;
94
96
  private _textFormatTransformersByTrigger;
95
97
  private _textMatchTransformersByTrigger;
@@ -288,7 +288,7 @@ function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransfor
288
288
  return false;
289
289
  }
290
290
  export var MarkdownShortCutService = /*#__PURE__*/function () {
291
- function MarkdownShortCutService() {
291
+ function MarkdownShortCutService(kernel) {
292
292
  _classCallCheck(this, MarkdownShortCutService);
293
293
  _defineProperty(this, "elementTransformers", []);
294
294
  _defineProperty(this, "textFormatTransformers", []);
@@ -296,6 +296,7 @@ export var MarkdownShortCutService = /*#__PURE__*/function () {
296
296
  _defineProperty(this, "_markdownWriters", {});
297
297
  _defineProperty(this, "_textFormatTransformersByTrigger", null);
298
298
  _defineProperty(this, "_textMatchTransformersByTrigger", null);
299
+ this.kernel = kernel;
299
300
  }
300
301
  _createClass(MarkdownShortCutService, [{
301
302
  key: "markdownWriters",
@@ -390,10 +391,16 @@ export var MarkdownShortCutService = /*#__PURE__*/function () {
390
391
  }, {
391
392
  key: "registerMarkdownWriter",
392
393
  value: function registerMarkdownWriter(type, writer) {
394
+ var _this$kernel;
393
395
  if (!this._markdownWriters[type]) {
394
396
  this._markdownWriters[type] = writer;
395
397
  return;
396
398
  }
399
+ if ((_this$kernel = this.kernel) !== null && _this$kernel !== void 0 && _this$kernel.isHotReloadMode()) {
400
+ console.warn("[Hot Reload] Overriding markdown writer for type \"".concat(type, "\""));
401
+ this._markdownWriters[type] = writer;
402
+ return;
403
+ }
397
404
  throw new Error("Markdown writer for type \"".concat(type, "\" is already registered."));
398
405
  }
399
406
  }]);
@@ -25,7 +25,11 @@ export var SlashService = /*#__PURE__*/function () {
25
25
  key: "registerSlash",
26
26
  value: function registerSlash(options) {
27
27
  if (this.triggerMap.has(options.trigger)) {
28
- throw new Error("Slash trigger \"".concat(options.trigger, "\" is already registered."));
28
+ if (this.kernel.isHotReloadMode()) {
29
+ console.warn("[Hot Reload] Overriding slash trigger \"".concat(options.trigger, "\""));
30
+ } else {
31
+ throw new Error("Slash trigger \"".concat(options.trigger, "\" is already registered."));
32
+ }
29
33
  }
30
34
  this.triggerMap.set(options.trigger, options);
31
35
  this.triggerFnMap.set(options.trigger, getBasicTypeaheadTriggerMatch(options.trigger, {
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow-x: auto;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n\n .editor_table {\n table-layout: fixed;\n border-spacing: 0;\n border-collapse: collapse;\n\n width: fit-content;\n\n text-align: start;\n text-indent: initial;\n text-wrap: pretty;\n word-break: auto-phrase;\n overflow-wrap: break-word;\n\n background: ", ";\n\n > tr:first-of-type {\n background: ", ";\n\n .editor_table_cell_header {\n font-weight: bold;\n }\n }\n }\n\n code {\n word-break: break-word;\n }\n\n .editor_table_cell_header {\n font-weight: normal;\n }\n\n .editor_table_cell {\n position: relative;\n\n overflow: auto;\n\n width: 75px;\n padding-block: 6px;\n padding-inline: 8px;\n border: 1px solid ", ";\n\n text-align: start;\n vertical-align: top;\n\n outline: none;\n }\n\n .editor_table_cell_selected {\n color: #000;\n background-color: ", ";\n caret-color: transparent;\n }\n "])), token.colorFillQuaternary, token.colorFillQuaternary, token.colorFillSecondary, token.yellow);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow-x: auto;\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em)\n calc(var(--lobe-markdown-margin-multiple) * 0.5em + 16px);\n\n .editor_table {\n table-layout: fixed;\n border-spacing: 0;\n border-collapse: collapse;\n\n width: fit-content;\n\n text-align: start;\n text-indent: initial;\n text-wrap: pretty;\n word-break: auto-phrase;\n overflow-wrap: break-word;\n\n background: ", ";\n\n > tr:first-of-type {\n background: ", ";\n\n .editor_table_cell_header {\n font-weight: bold;\n }\n }\n }\n\n code {\n word-break: break-word;\n }\n\n .editor_table_cell_header {\n font-weight: normal;\n }\n\n .editor_table_cell {\n position: relative;\n\n overflow: auto;\n\n width: 75px;\n padding-block: 6px;\n padding-inline: 8px;\n border: 1px solid ", ";\n\n text-align: start;\n vertical-align: top;\n\n outline: none;\n }\n\n .editor_table_cell_selected {\n color: #000;\n background-color: ", ";\n caret-color: transparent;\n }\n "])), token.colorFillQuaternary, token.colorFillQuaternary, token.colorFillSecondary, token.yellow);
8
8
  });
@@ -127,6 +127,10 @@ export interface IEditorKernel extends IEditor {
127
127
  * @param name
128
128
  */
129
129
  getDecorator(name: string): ((_node: DecoratorNode<any>, _editor: LexicalEditor) => any) | undefined;
130
+ /**
131
+ * Check if hot reload mode is enabled
132
+ */
133
+ isHotReloadMode(): boolean;
130
134
  /**
131
135
  * Register data source for multi-format data conversion
132
136
  * @param dataSource
@@ -149,11 +153,22 @@ export interface IEditorKernel extends IEditor {
149
153
  * @param service
150
154
  */
151
155
  registerService<T>(serviceId: IServiceID<T>, service: T): void;
156
+ /**
157
+ * Register service with hot reload support - allows overriding existing services
158
+ * @param serviceId Service identifier
159
+ * @param service Service instance
160
+ */
161
+ registerServiceHotReload<T>(serviceId: IServiceID<T>, service: T): void;
152
162
  /**
153
163
  * Register theme
154
164
  * @param themes
155
165
  */
156
166
  registerThemes(themes: Record<string, any>): void;
167
+ /**
168
+ * Enable or disable hot reload mode
169
+ * @param enabled Whether to enable hot reload mode
170
+ */
171
+ setHotReloadMode(enabled: boolean): void;
157
172
  }
158
173
  /**
159
174
  * Plugin interface
@@ -177,4 +192,8 @@ export interface IEditorPluginConstructor<IConfig> {
177
192
  readonly pluginName: string;
178
193
  new (kernel: IEditorKernel, config?: IConfig): IEditorPlugin<IConfig>;
179
194
  }
195
+ export interface IKernelStatic {
196
+ resetGlobalHotReloadMode(): void;
197
+ setGlobalHotReloadMode(enabled: boolean): void;
198
+ }
180
199
  export type IPlugin<T = any> = IEditorPluginConstructor<T> | [IEditorPluginConstructor<T>, T?];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -24,9 +24,7 @@
24
24
  "files": [
25
25
  "es",
26
26
  "react.d.ts",
27
- "react.js",
28
- "patches",
29
- "scripts/patch-lexical-package-json.js"
27
+ "react.js"
30
28
  ],
31
29
  "dependencies": {
32
30
  "@floating-ui/dom": "^1.7.3",
@@ -1,189 +0,0 @@
1
- import type { CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
2
- import type DataSource from './data-source';
3
- /**
4
- * Internationalization key type declaration, plugins can extend through declaration merging
5
- */
6
- export type LocaleType = typeof import("../locale").default;
7
- type FlattenKeys<T, Prefix extends string = ''> = {
8
- [K in keyof T & string]: T[K] extends string ? Prefix extends '' ? K : `${Prefix}.${K}` : T[K] extends Record<string, any> ? FlattenKeys<T[K], Prefix extends '' ? K : `${Prefix}.${K}`> : never;
9
- }[keyof T & string];
10
- export type TFunction = <TKey extends FlattenKeys<LocaleType>>(key: TKey, options?: Record<string, string | number>) => string;
11
- export type ILocaleKeys = Record<FlattenKeys<LocaleType>, string>;
12
- /**
13
- * Service ID type
14
- */
15
- export type IServiceID<Service> = {
16
- readonly __serviceId: string;
17
- __serviceType?: Service;
18
- };
19
- export interface IKernelEventMap {
20
- /**
21
- * Editor error event
22
- */
23
- error: (error: Error) => void;
24
- /**
25
- * Initialization event
26
- * @param editor Lexical editor instance
27
- * @returns
28
- */
29
- initialized: (editor: LexicalEditor) => void;
30
- }
31
- /**
32
- * External API
33
- */
34
- export interface IEditor {
35
- /**
36
- * Lose focus
37
- */
38
- blur(): void;
39
- /**
40
- * Destroy editor instance
41
- */
42
- destroy(): void;
43
- /**
44
- * Execute editor commands to manipulate editor content
45
- * @param type
46
- * @param payload
47
- */
48
- dispatchCommand<TCommand extends LexicalCommand<unknown>>(type: TCommand, payload: CommandPayloadType<TCommand>): boolean;
49
- /**
50
- * Focus editor
51
- */
52
- focus(): void;
53
- /**
54
- * Get editor content of specified type
55
- */
56
- getDocument(type: string): DataSource | undefined;
57
- /**
58
- * Get Lexical editor instance
59
- */
60
- getLexicalEditor(): LexicalEditor | null;
61
- /**
62
- * Get document editor root node
63
- */
64
- getRootElement(): HTMLElement | null;
65
- /**
66
- * Get editor theme
67
- */
68
- getTheme(): Record<string, string | Record<string, string>>;
69
- /**
70
- * Remove editor event listener
71
- * @param event
72
- * @param listener
73
- */
74
- off<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
75
- /**
76
- * Add editor event listener
77
- * @param event
78
- * @param listener
79
- */
80
- on<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
81
- /**
82
- * Listen to event once, automatically remove listener after trigger
83
- * @param event
84
- * @param listener
85
- */
86
- once<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
87
- /**
88
- * Register internationalization text
89
- * @param locale Internationalization text object
90
- */
91
- registerLocale(locale: Partial<Record<keyof ILocaleKeys, string>>): void;
92
- /**
93
- * Register editor plugin
94
- */
95
- registerPlugin<T>(plugin: IEditorPluginConstructor<T>, config?: T): IEditor;
96
- /**
97
- * Register multiple editor plugins
98
- */
99
- registerPlugins(plugins: Array<IPlugin>): IEditor;
100
- /**
101
- * Get editor Service, usually provided by plugins to extend certain functionalities
102
- * @param serviceId
103
- */
104
- requireService<T>(serviceId: IServiceID<T>): T | null;
105
- /**
106
- * Set editor content, type is content type, content is content data
107
- * @param type
108
- * @param content
109
- */
110
- setDocument(type: string, content: any): void;
111
- /**
112
- * Set document editor root node
113
- * @param dom
114
- */
115
- setRootElement(dom: HTMLElement): LexicalEditor;
116
- /**
117
- * Get translation text
118
- * @param key Translation key
119
- * @param params Parameter replacement
120
- */
121
- t<K extends keyof ILocaleKeys>(key: K, params?: Record<string, any>): string;
122
- /**
123
- * Update editor theme
124
- * @param key
125
- * @param value
126
- */
127
- updateTheme(key: string, value: string | Record<string, string>): void;
128
- }
129
- /**
130
- * API provided to plugins
131
- */
132
- export interface IEditorKernel extends IEditor {
133
- /**
134
- * Get editor Node decorator for specific Node rendering
135
- * @param name
136
- */
137
- getDecorator(name: string): ((_node: DecoratorNode<any>, _editor: LexicalEditor) => any) | undefined;
138
- /**
139
- * Register data source for multi-format data conversion
140
- * @param dataSource
141
- */
142
- registerDataSource(dataSource: DataSource): void;
143
- /**
144
- * Register editor node decorator
145
- * @param name
146
- * @param decorator
147
- */
148
- registerDecorator(name: string, decorator: (_node: DecoratorNode<any>, _editor: LexicalEditor) => any): void;
149
- /**
150
- * Register Lexical Node
151
- * @param nodes
152
- */
153
- registerNodes(nodes: Array<LexicalNodeConfig>): void;
154
- /**
155
- * Register service
156
- * @param serviceId
157
- * @param service
158
- */
159
- registerService<T>(serviceId: IServiceID<T>, service: T): void;
160
- /**
161
- * Register theme
162
- * @param themes
163
- */
164
- registerThemes(themes: Record<string, any>): void;
165
- }
166
- /**
167
- * Plugin interface
168
- */
169
- export interface IEditorPlugin<IConfig> {
170
- config?: IConfig;
171
- /**
172
- * Editor destruction
173
- */
174
- destroy(): void;
175
- /**
176
- * After Lexical editor instantiation
177
- * @param editor Lexical editor instance
178
- */
179
- onInit?(editor: LexicalEditor): void;
180
- }
181
- /**
182
- * Plugin class interface
183
- */
184
- export interface IEditorPluginConstructor<IConfig> {
185
- readonly pluginName: string;
186
- new (kernel: IEditorKernel, config?: IConfig): IEditorPlugin<IConfig>;
187
- }
188
- export type IPlugin<T = any> = IEditorPluginConstructor<T> | [IEditorPluginConstructor<T>, T?];
189
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,88 +0,0 @@
1
- diff --git a/node_modules/lexical/Lexical.dev.js b/node_modules/lexical/Lexical.dev.js
2
- index f129fe0..4a6af35 100644
3
- --- a/node_modules/lexical/Lexical.dev.js
4
- +++ b/node_modules/lexical/Lexical.dev.js
5
- @@ -13865,3 +13865,5 @@ exports.removeFromParent = removeFromParent;
6
- exports.resetRandomKey = resetRandomKey;
7
- exports.setDOMUnmanaged = setDOMUnmanaged;
8
- exports.setNodeIndentFromDOM = setNodeIndentFromDOM;
9
- +exports.EditorState = EditorState;
10
- +exports.ElementDOMSlot = ElementDOMSlot;
11
- diff --git a/node_modules/lexical/Lexical.dev.mjs b/node_modules/lexical/Lexical.dev.mjs
12
- index ab18d70..28cb4ab 100644
13
- --- a/node_modules/lexical/Lexical.dev.mjs
14
- +++ b/node_modules/lexical/Lexical.dev.mjs
15
- @@ -6,6 +6,8 @@
16
- *
17
- */
18
-
19
- +import { EditorStateReadOptions } from "./Lexical.dev";
20
- +
21
- /**
22
- * Copyright (c) Meta Platforms, Inc. and affiliates.
23
- *
24
- @@ -13665,4 +13667,4 @@ function $splitAtPointCaretNext(pointCaret, {
25
- return parentCaret;
26
- }
27
-
28
- -export { $addUpdateTag, $applyNodeReplacement, $caretFromPoint, $caretRangeFromSelection, $cloneWithProperties, $comparePointCaretNext, $copyNode, $create, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createPoint, $createRangeSelection, $createRangeSelectionFromDom, $createTabNode, $createTextNode, $extendCaretToRange, $getAdjacentChildCaret, $getAdjacentNode, $getAdjacentSiblingOrParentSiblingCaret, $getCaretInDirection, $getCaretRange, $getCaretRangeInDirection, $getCharacterOffsets, $getChildCaret, $getChildCaretAtIndex, $getChildCaretOrSelf, $getCollapsedCaretRange, $getCommonAncestor, $getCommonAncestorResultBranchOrder, $getEditor, $getNearestNodeFromDOMNode, $getNearestRootOrShadowRoot, $getNodeByKey, $getNodeByKeyOrThrow, $getPreviousSelection, $getRoot, $getSelection, $getSiblingCaret, $getState, $getStateChange, $getTextContent, $getTextNodeOffset, $getTextPointCaret, $getTextPointCaretSlice, $getWritableNodeState, $hasAncestor, $hasUpdateTag, $insertNodes, $isBlockElementNode, $isChildCaret, $isDecoratorNode, $isElementNode, $isExtendableTextPointCaret, $isInlineElementOrDecoratorNode, $isLeafNode, $isLineBreakNode, $isNodeCaret, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isRootOrShadowRoot, $isSiblingCaret, $isTabNode, $isTextNode, $isTextPointCaret, $isTextPointCaretSlice, $isTokenOrSegmented, $isTokenOrTab, $nodesOfType, $normalizeCaret, $normalizeSelection as $normalizeSelection__EXPERIMENTAL, $onUpdate, $parseSerializedNode, $removeTextFromCaretRange, $rewindSiblingCaret, $selectAll, $setCompositionKey, $setPointFromCaret, $setSelection, $setSelectionFromCaretRange, $setState, $splitAtPointCaretNext, $splitNode, $updateRangeSelectionFromCaretRange, ArtificialNode__DO_NOT_USE, BLUR_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CLICK_COMMAND, COLLABORATION_TAG, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, CONTROLLED_TEXT_INSERTION_COMMAND, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DELETE_LINE_COMMAND, DELETE_WORD_COMMAND, DRAGEND_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, DecoratorNode, ElementNode, FOCUS_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, HISTORIC_TAG, HISTORY_MERGE_TAG, HISTORY_PUSH_TAG, INDENT_CONTENT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, INTERNAL_$isBlock, IS_ALL_FORMATTING, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, LineBreakNode, MOVE_TO_END, MOVE_TO_START, NODE_STATE_KEY, OUTDENT_CONTENT_COMMAND, PASTE_COMMAND, PASTE_TAG, ParagraphNode, REDO_COMMAND, REMOVE_TEXT_COMMAND, RootNode, SELECTION_CHANGE_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, SKIP_COLLAB_TAG, SKIP_DOM_SELECTION_TAG, SKIP_SCROLL_INTO_VIEW_TAG, TEXT_TYPE_TO_FORMAT, TabNode, TextNode, UNDO_COMMAND, buildImportMap, createCommand, createEditor, createSharedNodeState, createState, flipDirection, getDOMOwnerDocument, getDOMSelection, getDOMSelectionFromTarget, getDOMTextNode, getEditorPropertyFromDOMNode, getNearestEditorFromDOMNode, getRegisteredNode, getRegisteredNodeOrThrow, isBlockDomNode, isCurrentlyReadOnlyMode, isDOMDocumentNode, isDOMNode, isDOMTextNode, isDOMUnmanaged, isDocumentFragment, isExactShortcutMatch, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, isLexicalEditor, isModifierMatch, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor, makeStepwiseIterator, removeFromParent, resetRandomKey, setDOMUnmanaged, setNodeIndentFromDOM };
29
- +export { $addUpdateTag, $applyNodeReplacement, $caretFromPoint, $caretRangeFromSelection, $cloneWithProperties, $comparePointCaretNext, $copyNode, $create, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createPoint, $createRangeSelection, $createRangeSelectionFromDom, $createTabNode, $createTextNode, $extendCaretToRange, $getAdjacentChildCaret, $getAdjacentNode, $getAdjacentSiblingOrParentSiblingCaret, $getCaretInDirection, $getCaretRange, $getCaretRangeInDirection, $getCharacterOffsets, $getChildCaret, $getChildCaretAtIndex, $getChildCaretOrSelf, $getCollapsedCaretRange, $getCommonAncestor, $getCommonAncestorResultBranchOrder, $getEditor, $getNearestNodeFromDOMNode, $getNearestRootOrShadowRoot, $getNodeByKey, $getNodeByKeyOrThrow, $getPreviousSelection, $getRoot, $getSelection, $getSiblingCaret, $getState, $getStateChange, $getTextContent, $getTextNodeOffset, $getTextPointCaret, $getTextPointCaretSlice, $getWritableNodeState, $hasAncestor, $hasUpdateTag, $insertNodes, $isBlockElementNode, $isChildCaret, $isDecoratorNode, $isElementNode, $isExtendableTextPointCaret, $isInlineElementOrDecoratorNode, $isLeafNode, $isLineBreakNode, $isNodeCaret, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isRootOrShadowRoot, $isSiblingCaret, $isTabNode, $isTextNode, $isTextPointCaret, $isTextPointCaretSlice, $isTokenOrSegmented, $isTokenOrTab, $nodesOfType, $normalizeCaret, $normalizeSelection as $normalizeSelection__EXPERIMENTAL, $onUpdate, $parseSerializedNode, $removeTextFromCaretRange, $rewindSiblingCaret, $selectAll, $setCompositionKey, $setPointFromCaret, $setSelection, $setSelectionFromCaretRange, $setState, $splitAtPointCaretNext, $splitNode, $updateRangeSelectionFromCaretRange, ArtificialNode__DO_NOT_USE, BLUR_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CLICK_COMMAND, COLLABORATION_TAG, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, CONTROLLED_TEXT_INSERTION_COMMAND, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DELETE_LINE_COMMAND, DELETE_WORD_COMMAND, DRAGEND_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, DecoratorNode, ElementNode, FOCUS_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, HISTORIC_TAG, HISTORY_MERGE_TAG, HISTORY_PUSH_TAG, INDENT_CONTENT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, INTERNAL_$isBlock, IS_ALL_FORMATTING, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, LineBreakNode, MOVE_TO_END, MOVE_TO_START, NODE_STATE_KEY, OUTDENT_CONTENT_COMMAND, PASTE_COMMAND, PASTE_TAG, ParagraphNode, REDO_COMMAND, REMOVE_TEXT_COMMAND, RootNode, SELECTION_CHANGE_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, SKIP_COLLAB_TAG, SKIP_DOM_SELECTION_TAG, SKIP_SCROLL_INTO_VIEW_TAG, TEXT_TYPE_TO_FORMAT, TabNode, TextNode, UNDO_COMMAND, buildImportMap, createCommand, createEditor, createSharedNodeState, createState, flipDirection, getDOMOwnerDocument, getDOMSelection, getDOMSelectionFromTarget, getDOMTextNode, getEditorPropertyFromDOMNode, getNearestEditorFromDOMNode, getRegisteredNode, getRegisteredNodeOrThrow, isBlockDomNode, isCurrentlyReadOnlyMode, isDOMDocumentNode, isDOMNode, isDOMTextNode, isDOMUnmanaged, isDocumentFragment, isExactShortcutMatch, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, isLexicalEditor, isModifierMatch, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor, makeStepwiseIterator, removeFromParent, resetRandomKey, setDOMUnmanaged, setNodeIndentFromDOM, EditorState, ElementDOMSlot };
30
- diff --git a/node_modules/lexical/Lexical.js b/node_modules/lexical/Lexical.js
31
- index d2e1194..d4d1894 100644
32
- --- a/node_modules/lexical/Lexical.js
33
- +++ b/node_modules/lexical/Lexical.js
34
- @@ -7,5 +7,5 @@
35
- */
36
-
37
- 'use strict'
38
- -const Lexical = process.env.NODE_ENV !== 'production' ? require('./Lexical.dev.js') : require('./Lexical.prod.js');
39
- +const Lexical = require('./Lexical.dev.js');
40
- module.exports = Lexical;
41
-
42
- diff --git a/node_modules/lexical/Lexical.mjs b/node_modules/lexical/Lexical.mjs
43
- index a6b0b72..4ef410d 100644
44
- --- a/node_modules/lexical/Lexical.mjs
45
- +++ b/node_modules/lexical/Lexical.mjs
46
- @@ -7,8 +7,7 @@
47
- */
48
-
49
- import * as modDev from './Lexical.dev.mjs';
50
- -import * as modProd from './Lexical.prod.mjs';
51
- -const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
52
- +const mod = modDev;
53
- export const $addUpdateTag = mod.$addUpdateTag;
54
- export const $applyNodeReplacement = mod.$applyNodeReplacement;
55
- export const $caretFromPoint = mod.$caretFromPoint;
56
- diff --git a/node_modules/lexical/Lexical.node.mjs b/node_modules/lexical/Lexical.node.mjs
57
- index 15045bc..e1e9480 100644
58
- --- a/node_modules/lexical/Lexical.node.mjs
59
- +++ b/node_modules/lexical/Lexical.node.mjs
60
- @@ -205,3 +205,5 @@ export const removeFromParent = mod.removeFromParent;
61
- export const resetRandomKey = mod.resetRandomKey;
62
- export const setDOMUnmanaged = mod.setDOMUnmanaged;
63
- export const setNodeIndentFromDOM = mod.setNodeIndentFromDOM;
64
- +export const EditorState = mod.EditorState;
65
- +export const ElementDOMSlot = mod.ElementDOMSlot;
66
- diff --git a/node_modules/lexical/index.d.ts b/node_modules/lexical/index.d.ts
67
- index 4d1c06d..d480555 100644
68
- --- a/node_modules/lexical/index.d.ts
69
- +++ b/node_modules/lexical/index.d.ts
70
- @@ -12,7 +12,7 @@ export { BLUR_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND,
71
- export { IS_ALL_FORMATTING, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE, NODE_STATE_KEY, TEXT_TYPE_TO_FORMAT, } from './LexicalConstants';
72
- export type { CommandListener, CommandListenerPriority, CommandPayloadType, CreateEditorArgs, EditableListener, EditorConfig, EditorSetOptions, EditorThemeClasses, EditorThemeClassName, EditorUpdateOptions, HTMLConfig, Klass, KlassConstructor, LexicalCommand, LexicalEditor, LexicalNodeConfig, LexicalNodeReplacement, MutationListener, NodeMutation, RootListener, SerializedEditor, Spread, Transform, UpdateListener, UpdateListenerPayload, } from './LexicalEditor';
73
- export { COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, createEditor, } from './LexicalEditor';
74
- -export type { EditorState, EditorStateReadOptions, SerializedEditorState, } from './LexicalEditorState';
75
- +export { EditorState, EditorStateReadOptions, SerializedEditorState, } from './LexicalEditorState';
76
- export type { EventHandler } from './LexicalEvents';
77
- export type { BaseStaticNodeConfig, DOMChildConversion, DOMConversion, DOMConversionFn, DOMConversionMap, DOMConversionOutput, DOMExportOutput, DOMExportOutputMap, LexicalExportJSON, LexicalNode, LexicalUpdateJSON, NodeKey, NodeMap, SerializedLexicalNode, StaticNodeConfig, StaticNodeConfigRecord, StaticNodeConfigValue, } from './LexicalNode';
78
- export { buildImportMap } from './LexicalNode';
79
- @@ -24,7 +24,8 @@ export { $parseSerializedNode, isCurrentlyReadOnlyMode } from './LexicalUpdates'
80
- export { $addUpdateTag, $applyNodeReplacement, $cloneWithProperties, $copyNode, $create, $getAdjacentNode, $getEditor, $getNearestNodeFromDOMNode, $getNearestRootOrShadowRoot, $getNodeByKey, $getNodeByKeyOrThrow, $getRoot, $hasAncestor, $hasUpdateTag, $isInlineElementOrDecoratorNode, $isLeafNode, $isRootOrShadowRoot, $isTokenOrSegmented, $isTokenOrTab, $nodesOfType, $onUpdate, $selectAll, $setCompositionKey, $setSelection, $splitNode, getDOMOwnerDocument, getDOMSelection, getDOMSelectionFromTarget, getDOMTextNode, getEditorPropertyFromDOMNode, getNearestEditorFromDOMNode, getRegisteredNode, getRegisteredNodeOrThrow, INTERNAL_$isBlock, isBlockDomNode, isDocumentFragment, isDOMDocumentNode, isDOMNode, isDOMTextNode, isDOMUnmanaged, isExactShortcutMatch, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, isLexicalEditor, isModifierMatch, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor, removeFromParent, resetRandomKey, setDOMUnmanaged, setNodeIndentFromDOM, } from './LexicalUtils';
81
- export { ArtificialNode__DO_NOT_USE } from './nodes/ArtificialNode';
82
- export { $isDecoratorNode, DecoratorNode } from './nodes/LexicalDecoratorNode';
83
- -export type { ElementDOMSlot, ElementFormatType, SerializedElementNode, } from './nodes/LexicalElementNode';
84
- +export type { ElementFormatType, SerializedElementNode, } from './nodes/LexicalElementNode';
85
- +export { ElementDOMSlot } from './nodes/LexicalElementNode';
86
- export { $isElementNode, ElementNode } from './nodes/LexicalElementNode';
87
- export type { SerializedLineBreakNode } from './nodes/LexicalLineBreakNode';
88
- export { $createLineBreakNode, $isLineBreakNode, LineBreakNode, } from './nodes/LexicalLineBreakNode';
@@ -1,20 +0,0 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
3
-
4
- // 定位 lexical 的 package.json 文件
5
- const packageJsonPath = path.resolve(__dirname, '../node_modules/lexical/package.json');
6
-
7
- // 读取 package.json
8
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
9
-
10
- // 修改 package.json 的内容
11
- const expt = packageJson.exports['.'];
12
- Object.keys(expt).forEach((key) => {
13
- const obj = expt[key];
14
- obj.production = obj.development; // 将 development 指向 production
15
- });
16
-
17
- // 写回修改后的 package.json
18
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
19
-
20
- console.log('lexical package.json has been patched!');