@lobehub/editor 1.5.2 → 1.5.4
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.
- package/README.md +74 -23
- package/es/editor-kernel/kernel.d.ts +1 -0
- package/es/editor-kernel/kernel.js +57 -16
- package/es/editor-kernel/react/useDecorators.js +14 -4
- package/es/index.d.ts +1 -0
- package/es/index.js +11 -4
- package/es/plugins/common/node/cursor.js +5 -3
- package/es/plugins/file/command/index.js +3 -1
- package/es/plugins/file/plugin/index.js +3 -1
- package/es/plugins/image/command/index.js +3 -1
- package/es/plugins/image/plugin/index.js +1 -1
- package/es/plugins/markdown/service/shortcut.d.ts +1 -0
- package/es/plugins/markdown/service/shortcut.js +3 -1
- package/es/plugins/math/plugin/index.js +3 -1
- package/es/plugins/math/react/component/MathInline.js +3 -1
- package/es/plugins/math/react/index.js +1 -1
- package/es/plugins/mention/react/ReactMentionPlugin.js +1 -1
- package/es/plugins/slash/plugin/index.js +1 -1
- package/es/plugins/slash/service/i-slash-service.d.ts +1 -0
- package/es/plugins/slash/service/i-slash-service.js +4 -1
- package/es/plugins/upload/plugin/index.js +5 -3
- package/es/react/Editor/Editor.js +2 -1
- package/es/utils/debug.d.ts +429 -0
- package/es/utils/debug.js +348 -0
- package/package.json +2 -1
|
@@ -0,0 +1,348 @@
|
|
|
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
// @ts-ignore - debug package types
|
|
9
|
+
import createDebug from 'debug';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Base namespace for all LobeHub Editor debug messages
|
|
13
|
+
*/
|
|
14
|
+
var BASE_NAMESPACE = 'lobe-editor';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Development mode check
|
|
18
|
+
*/
|
|
19
|
+
var isDev = process.env.NODE_ENV === 'development';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Debug utility factory for LobeHub Editor
|
|
23
|
+
* Creates namespaced debug functions following the pattern: lobe-editor:category
|
|
24
|
+
*/
|
|
25
|
+
export var DebugLogger = /*#__PURE__*/function () {
|
|
26
|
+
function DebugLogger() {
|
|
27
|
+
_classCallCheck(this, DebugLogger);
|
|
28
|
+
_defineProperty(this, "debuggers", new Map());
|
|
29
|
+
}
|
|
30
|
+
_createClass(DebugLogger, [{
|
|
31
|
+
key: "getDebugger",
|
|
32
|
+
value:
|
|
33
|
+
/**
|
|
34
|
+
* Get or create a debug function for a specific namespace
|
|
35
|
+
* @param category - The debug category (e.g., 'kernel', 'plugin', 'upload')
|
|
36
|
+
* @param subcategory - Optional subcategory for more specific debugging
|
|
37
|
+
* @returns Debug function
|
|
38
|
+
*/
|
|
39
|
+
function getDebugger(category, subcategory) {
|
|
40
|
+
var namespace = subcategory ? "".concat(BASE_NAMESPACE, ":").concat(category, ":").concat(subcategory) : "".concat(BASE_NAMESPACE, ":").concat(category);
|
|
41
|
+
if (!this.debuggers.has(namespace)) {
|
|
42
|
+
this.debuggers.set(namespace, createDebug(namespace));
|
|
43
|
+
}
|
|
44
|
+
return this.debuggers.get(namespace);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a scoped debug logger for a specific component/service
|
|
49
|
+
* @param category - Main category
|
|
50
|
+
* @param subcategory - Optional subcategory
|
|
51
|
+
* @returns Object with debug methods
|
|
52
|
+
*/
|
|
53
|
+
}, {
|
|
54
|
+
key: "createLogger",
|
|
55
|
+
value: function createLogger(category, subcategory) {
|
|
56
|
+
var debug = this.getDebugger(category, subcategory);
|
|
57
|
+
var warnDebugger = this.getDebugger(category, subcategory ? "".concat(subcategory, ":warn") : 'warn');
|
|
58
|
+
var errorDebugger = this.getDebugger(category, subcategory ? "".concat(subcategory, ":error") : 'error');
|
|
59
|
+
var info = this.getDebugger(category, subcategory ? "".concat(subcategory, ":info") : 'info');
|
|
60
|
+
|
|
61
|
+
// Create wrapper functions that use native console methods for proper browser dev tool support
|
|
62
|
+
var warn = function warn() {
|
|
63
|
+
if (warnDebugger.enabled) {
|
|
64
|
+
var _console;
|
|
65
|
+
var prefix = warnDebugger.namespace;
|
|
66
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
|
+
args[_key] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
(_console = console).warn.apply(_console, ["".concat(prefix)].concat(args));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var error = function error() {
|
|
73
|
+
if (errorDebugger.enabled) {
|
|
74
|
+
var _console2;
|
|
75
|
+
var prefix = errorDebugger.namespace;
|
|
76
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
77
|
+
args[_key2] = arguments[_key2];
|
|
78
|
+
}
|
|
79
|
+
(_console2 = console).error.apply(_console2, ["".concat(prefix)].concat(args));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
/**
|
|
84
|
+
* General debug logging
|
|
85
|
+
*/
|
|
86
|
+
debug: debug,
|
|
87
|
+
/**
|
|
88
|
+
* Error level logging - uses console.error for proper browser dev tool support
|
|
89
|
+
*/
|
|
90
|
+
error: error,
|
|
91
|
+
/**
|
|
92
|
+
* Info level logging
|
|
93
|
+
*/
|
|
94
|
+
info: info,
|
|
95
|
+
/**
|
|
96
|
+
* Log function - alias for debug for compatibility
|
|
97
|
+
*/
|
|
98
|
+
log: debug,
|
|
99
|
+
/**
|
|
100
|
+
* Warning level logging - uses console.warn for proper browser dev tool support
|
|
101
|
+
*/
|
|
102
|
+
warn: warn
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Enable debug for specific namespaces
|
|
108
|
+
* @param namespaces - Comma-separated list of namespaces to enable
|
|
109
|
+
*/
|
|
110
|
+
}, {
|
|
111
|
+
key: "enable",
|
|
112
|
+
value: function enable(namespaces) {
|
|
113
|
+
createDebug.enable(namespaces);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Disable all debug output
|
|
118
|
+
*/
|
|
119
|
+
}, {
|
|
120
|
+
key: "disable",
|
|
121
|
+
value: function disable() {
|
|
122
|
+
createDebug.disable();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check if a namespace is enabled
|
|
127
|
+
* @param namespace - The namespace to check
|
|
128
|
+
* @returns Whether the namespace is enabled
|
|
129
|
+
*/
|
|
130
|
+
}, {
|
|
131
|
+
key: "enabled",
|
|
132
|
+
value: function enabled(namespace) {
|
|
133
|
+
return createDebug.enabled(namespace);
|
|
134
|
+
}
|
|
135
|
+
}]);
|
|
136
|
+
return DebugLogger;
|
|
137
|
+
}();
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Global debug logger instance
|
|
141
|
+
*/
|
|
142
|
+
export var debugLogger = new DebugLogger();
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Browser environment debug initialization - Zero configuration approach
|
|
146
|
+
* Automatically enables debug based on environment variables or development mode
|
|
147
|
+
*/
|
|
148
|
+
if (typeof window !== 'undefined') {
|
|
149
|
+
// Check for server-side DEBUG environment variable (passed through build process)
|
|
150
|
+
var envDebug = process.env.DEBUG;
|
|
151
|
+
|
|
152
|
+
// Simple logic: Environment variable takes precedence, then development mode
|
|
153
|
+
var debugConfig = null;
|
|
154
|
+
if (envDebug) {
|
|
155
|
+
// Environment variable exists - use it directly
|
|
156
|
+
debugConfig = envDebug;
|
|
157
|
+
localStorage.debug = envDebug;
|
|
158
|
+
} else if (isDev) {
|
|
159
|
+
// Development mode - auto-enable all lobe-editor debug
|
|
160
|
+
debugConfig = 'lobe-editor:*';
|
|
161
|
+
localStorage.debug = debugConfig;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Apply debug configuration
|
|
165
|
+
if (debugConfig) {
|
|
166
|
+
createDebug.enable(debugConfig);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Convenience function to create a debug logger for a specific category
|
|
172
|
+
* @param category - Main category (e.g., 'kernel', 'plugin', 'upload')
|
|
173
|
+
* @param subcategory - Optional subcategory
|
|
174
|
+
* @returns Logger object with debug methods
|
|
175
|
+
*/
|
|
176
|
+
export function createDebugLogger(category, subcategory) {
|
|
177
|
+
return debugLogger.createLogger(category, subcategory);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Pre-configured debug loggers for common categories
|
|
182
|
+
*/
|
|
183
|
+
export var debugLoggers = {
|
|
184
|
+
demo: createDebugLogger('demo'),
|
|
185
|
+
file: createDebugLogger('file'),
|
|
186
|
+
image: createDebugLogger('image'),
|
|
187
|
+
kernel: createDebugLogger('kernel'),
|
|
188
|
+
markdown: createDebugLogger('markdown'),
|
|
189
|
+
math: createDebugLogger('math'),
|
|
190
|
+
mention: createDebugLogger('mention'),
|
|
191
|
+
plugin: createDebugLogger('plugin'),
|
|
192
|
+
react: createDebugLogger('react'),
|
|
193
|
+
service: createDebugLogger('service'),
|
|
194
|
+
slash: createDebugLogger('slash'),
|
|
195
|
+
upload: createDebugLogger('upload')
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Development mode utilities
|
|
200
|
+
*/
|
|
201
|
+
export { isDev };
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Conditional console logging - only logs in development mode
|
|
205
|
+
* Use this for demo files and development-only logging
|
|
206
|
+
*/
|
|
207
|
+
export var devConsole = {
|
|
208
|
+
error: function error() {
|
|
209
|
+
if (isDev) {
|
|
210
|
+
var _console3;
|
|
211
|
+
(_console3 = console).error.apply(_console3, arguments);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
info: function info() {
|
|
215
|
+
if (isDev) {
|
|
216
|
+
var _console4;
|
|
217
|
+
(_console4 = console).info.apply(_console4, arguments);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
log: function log() {
|
|
221
|
+
if (isDev) {
|
|
222
|
+
var _console5;
|
|
223
|
+
(_console5 = console).log.apply(_console5, arguments);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
warn: function warn() {
|
|
227
|
+
if (isDev) {
|
|
228
|
+
var _console6;
|
|
229
|
+
(_console6 = console).warn.apply(_console6, arguments);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Production-safe error logging
|
|
236
|
+
* Always logs errors and warnings regardless of environment using native console methods
|
|
237
|
+
* for proper browser dev tool support. Debug/info uses debug package.
|
|
238
|
+
*/
|
|
239
|
+
export var prodSafeLogger = {
|
|
240
|
+
/**
|
|
241
|
+
* Debug info - only shown when debug is enabled
|
|
242
|
+
*/
|
|
243
|
+
debug: debugLoggers.kernel.debug,
|
|
244
|
+
/**
|
|
245
|
+
* Log critical errors that should always be visible (uses console.error)
|
|
246
|
+
*/
|
|
247
|
+
error: function error() {
|
|
248
|
+
var _console7;
|
|
249
|
+
(_console7 = console).error.apply(_console7, arguments);
|
|
250
|
+
},
|
|
251
|
+
/**
|
|
252
|
+
* Info logging - only shown when debug is enabled
|
|
253
|
+
*/
|
|
254
|
+
info: debugLoggers.kernel.info,
|
|
255
|
+
/**
|
|
256
|
+
* Log warnings that should always be visible (uses console.warn)
|
|
257
|
+
*/
|
|
258
|
+
warn: function warn() {
|
|
259
|
+
var _console8;
|
|
260
|
+
(_console8 = console).warn.apply(_console8, arguments);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Browser debug utilities for Next.js and other client-side frameworks
|
|
266
|
+
*/
|
|
267
|
+
export var browserDebug = {
|
|
268
|
+
/**
|
|
269
|
+
* Disable debug logging in browser environment
|
|
270
|
+
*/
|
|
271
|
+
disable: function disable() {
|
|
272
|
+
if (typeof window !== 'undefined') {
|
|
273
|
+
localStorage.removeItem('debug');
|
|
274
|
+
createDebug.disable();
|
|
275
|
+
console.info('Debug disabled.');
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
/**
|
|
279
|
+
* Enable debug logging in browser environment
|
|
280
|
+
* @param namespaces - Debug namespaces to enable (e.g., 'lobe-editor:*')
|
|
281
|
+
*/
|
|
282
|
+
enable: function enable() {
|
|
283
|
+
var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'lobe-editor:*';
|
|
284
|
+
if (typeof window !== 'undefined') {
|
|
285
|
+
localStorage.debug = namespaces;
|
|
286
|
+
createDebug.enable(namespaces);
|
|
287
|
+
console.info("Debug enabled: ".concat(namespaces));
|
|
288
|
+
console.info('Refresh the page to see debug logs from initialization.');
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* Get current debug configuration
|
|
293
|
+
*/
|
|
294
|
+
getConfig: function getConfig() {
|
|
295
|
+
if (typeof window !== 'undefined') {
|
|
296
|
+
var _envDebug = process.env.DEBUG;
|
|
297
|
+
var currentDebug = localStorage.getItem('debug');
|
|
298
|
+
if (_envDebug) {
|
|
299
|
+
return {
|
|
300
|
+
enabled: _envDebug,
|
|
301
|
+
source: 'environment variable (auto-applied)'
|
|
302
|
+
};
|
|
303
|
+
} else if (isDev && currentDebug) {
|
|
304
|
+
return {
|
|
305
|
+
enabled: currentDebug,
|
|
306
|
+
source: 'development mode (auto-applied)'
|
|
307
|
+
};
|
|
308
|
+
} else {
|
|
309
|
+
return {
|
|
310
|
+
enabled: false,
|
|
311
|
+
source: 'disabled'
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
enabled: process.env.DEBUG || false,
|
|
317
|
+
source: 'server-side'
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
/**
|
|
321
|
+
* Show available debug categories
|
|
322
|
+
*/
|
|
323
|
+
showCategories: function showCategories() {
|
|
324
|
+
console.group('Available debug categories:');
|
|
325
|
+
console.log('� lobe-editor:kernel - Core editor functionality');
|
|
326
|
+
console.log('🔌 lobe-editor:plugin:* - All plugins');
|
|
327
|
+
console.log('🔍 lobe-editor:service:* - All services');
|
|
328
|
+
console.log('💬 lobe-editor:*:info - Info level messages');
|
|
329
|
+
console.log('⚠️ lobe-editor:*:warn - Warning messages');
|
|
330
|
+
console.log('❌ lobe-editor:*:error - Error messages');
|
|
331
|
+
console.groupEnd();
|
|
332
|
+
console.info('Usage: browserDebug.enable("lobe-editor:kernel,lobe-editor:plugin:*")');
|
|
333
|
+
},
|
|
334
|
+
/**
|
|
335
|
+
* Show current debug status and configuration
|
|
336
|
+
*/
|
|
337
|
+
showStatus: function showStatus() {
|
|
338
|
+
var config = browserDebug.getConfig();
|
|
339
|
+
console.group('� LobeHub Editor Debug Status');
|
|
340
|
+
console.log("Status: ".concat(config.enabled ? '✅ Enabled' : '❌ Disabled'));
|
|
341
|
+
console.log("Configuration: ".concat(config.enabled || 'none'));
|
|
342
|
+
console.log("Source: ".concat(config.source));
|
|
343
|
+
console.groupEnd();
|
|
344
|
+
if (!config.enabled) {
|
|
345
|
+
console.info('💡 Zero-config setup: Set DEBUG=lobe-editor:* in your environment');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
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",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@shikijs/engine-javascript": "^3.9.2",
|
|
44
44
|
"ahooks": "^3.9.3",
|
|
45
45
|
"antd-style": "^3.7.1",
|
|
46
|
+
"debug": "^4.4.1",
|
|
46
47
|
"eventemitter3": "^5.0.1",
|
|
47
48
|
"framer-motion": "^12.23.12",
|
|
48
49
|
"fuse.js": "^7.1.0",
|