@lobehub/editor 1.20.2 → 1.21.0
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.
|
@@ -164,6 +164,13 @@ function convertMdastToLexical(node, index, ctx) {
|
|
|
164
164
|
ret.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
165
165
|
return ret;
|
|
166
166
|
}, []).filter(Boolean).flat();
|
|
167
|
+
while (htmlStack.length > 0) {
|
|
168
|
+
var _children3;
|
|
169
|
+
var tag = htmlStack.shift();
|
|
170
|
+
ctx.pop();
|
|
171
|
+
// @ts-expect-error not error
|
|
172
|
+
(_children3 = _children).push.apply(_children3, [INodeHelper.createTextNode(tag === null || tag === void 0 ? void 0 : tag.node.value)].concat(_toConsumableArray(tag.children)));
|
|
173
|
+
}
|
|
167
174
|
}
|
|
168
175
|
if (markdownReaders[node.type]) {
|
|
169
176
|
var reader = markdownReaders[node.type];
|
|
@@ -258,28 +258,36 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
258
258
|
// No markdown detected - plain text is already inserted
|
|
259
259
|
_this2.logger.debug('no markdown patterns detected, keeping as plain text');
|
|
260
260
|
}
|
|
261
|
-
if (clipboardData.types.includes('text/html') && clipboardData.types.includes('text/rtf')) {
|
|
262
|
-
// Code detected - insert as code block
|
|
263
|
-
_this2.logger.debug("code like, inserting as code block");
|
|
264
|
-
event.preventDefault();
|
|
265
|
-
event.stopPropagation();
|
|
266
|
-
editor.update(function () {
|
|
267
|
-
var selection = $getSelection();
|
|
268
|
-
if (!$isRangeSelection(selection)) return;
|
|
269
|
-
|
|
270
|
-
// Create code block node with detected language
|
|
271
|
-
var codeNode = $createCodeNode('plaintext');
|
|
272
|
-
selection.insertNodes([codeNode]);
|
|
273
261
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
262
|
+
// word 一类富文本编辑器会同时包含 text/html 和 text/rtf 类型的内容
|
|
263
|
+
// if (
|
|
264
|
+
// clipboardData.types.includes('text/html') &&
|
|
265
|
+
// clipboardData.types.includes('text/rtf')
|
|
266
|
+
// ) {
|
|
267
|
+
// // Code detected - insert as code block
|
|
268
|
+
// this.logger.debug(`code like, inserting as code block`);
|
|
269
|
+
//
|
|
270
|
+
// event.preventDefault();
|
|
271
|
+
// event.stopPropagation();
|
|
272
|
+
//
|
|
273
|
+
// editor.update(() => {
|
|
274
|
+
// const selection = $getSelection();
|
|
275
|
+
// if (!$isRangeSelection(selection)) return;
|
|
276
|
+
//
|
|
277
|
+
// // Create code block node with detected language
|
|
278
|
+
// const codeNode = $createCodeNode('plaintext');
|
|
279
|
+
// selection.insertNodes([codeNode]);
|
|
280
|
+
//
|
|
281
|
+
// // Insert the code text into the code block
|
|
282
|
+
// codeNode.select();
|
|
283
|
+
// const codeSelection = $getSelection();
|
|
284
|
+
// if ($isRangeSelection(codeSelection)) {
|
|
285
|
+
// codeSelection.insertText(text);
|
|
286
|
+
// }
|
|
287
|
+
// });
|
|
288
|
+
//
|
|
289
|
+
// return true; // Command handled
|
|
290
|
+
// }
|
|
283
291
|
|
|
284
292
|
// Force plain text paste for external content
|
|
285
293
|
event.preventDefault();
|
|
@@ -10,6 +10,7 @@ import { $createQuoteNode, $isHeadingNode, $isQuoteNode } from '@lexical/rich-te
|
|
|
10
10
|
import { $setBlocksType } from '@lexical/selection';
|
|
11
11
|
import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
|
|
12
12
|
import { $createNodeSelection, $getSelection, $isParagraphNode, $isRangeSelection, $setSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
|
|
13
|
+
import { debounce } from 'lodash-es';
|
|
13
14
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
14
15
|
import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
|
|
15
16
|
import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
|
|
@@ -369,14 +370,22 @@ export function useEditorState(editor) {
|
|
|
369
370
|
if (!editor) return;
|
|
370
371
|
var lexicalEditor = editor.getLexicalEditor();
|
|
371
372
|
var cleanup = function cleanup() {};
|
|
373
|
+
var debounceUpdate = debounce(function () {
|
|
374
|
+
lexicalEditor === null || lexicalEditor === void 0 || lexicalEditor.read(function () {
|
|
375
|
+
$updateToolbar();
|
|
376
|
+
});
|
|
377
|
+
}, 500);
|
|
372
378
|
var handleLexicalEditor = function handleLexicalEditor(lexicalEditor) {
|
|
373
|
-
cleanup = mergeRegister(lexicalEditor.registerUpdateListener(function (_ref) {
|
|
379
|
+
cleanup = mergeRegister(lexicalEditor.registerUpdateListener(debounce(function (_ref) {
|
|
374
380
|
var editorState = _ref.editorState;
|
|
375
381
|
editorState.read(function () {
|
|
376
382
|
$updateToolbar();
|
|
377
383
|
});
|
|
378
|
-
}), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
|
|
379
|
-
|
|
384
|
+
}, 500)), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
|
|
385
|
+
if (lexicalEditor.isComposing()) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
debounceUpdate();
|
|
380
389
|
return false;
|
|
381
390
|
}, COMMAND_PRIORITY_LOW), lexicalEditor.registerCommand(CAN_UNDO_COMMAND, function (payload) {
|
|
382
391
|
setCanUndo(payload);
|
package/package.json
CHANGED