@lobehub/editor 4.1.0 → 4.1.1
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.
|
@@ -82,6 +82,12 @@ export var CodePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
82
82
|
});
|
|
83
83
|
markdownService.registerMarkdownShortCuts([{
|
|
84
84
|
process: function process(selection) {
|
|
85
|
+
// If selection already contains a code node, do not process the shortcut to avoid nesting code nodes
|
|
86
|
+
if (selection.getNodes().some(function (node) {
|
|
87
|
+
return node.getType() === CodeNode.getType();
|
|
88
|
+
})) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
85
91
|
var text = selection.getTextContent();
|
|
86
92
|
selection.removeText();
|
|
87
93
|
selection.insertNodes([$createCodeNode(text), $createCursorNode()]);
|
|
@@ -75,7 +75,7 @@ export declare class MarkdownShortCutService implements IMarkdownShortCutService
|
|
|
75
75
|
get textFormatTransformersByTrigger(): Readonly<Record<string, readonly Readonly<{
|
|
76
76
|
format?: readonly import("lexical").TextFormatType[] | undefined;
|
|
77
77
|
intraword?: boolean | undefined;
|
|
78
|
-
process?: ((selection: import("lexical").RangeSelection) => void) | undefined;
|
|
78
|
+
process?: ((selection: import("lexical").RangeSelection) => boolean | void) | undefined;
|
|
79
79
|
tag: string;
|
|
80
80
|
type: "text-format";
|
|
81
81
|
}>[]>>;
|
|
@@ -2,7 +2,7 @@ import type { ElementNode, LexicalNode, RangeSelection, TextFormatType, TextNode
|
|
|
2
2
|
export type TextFormatTransformer = Readonly<{
|
|
3
3
|
format?: ReadonlyArray<TextFormatType>;
|
|
4
4
|
intraword?: boolean;
|
|
5
|
-
process?: (selection: RangeSelection) => void;
|
|
5
|
+
process?: (selection: RangeSelection) => boolean | void;
|
|
6
6
|
tag: string;
|
|
7
7
|
type: 'text-format';
|
|
8
8
|
}>;
|
|
@@ -9,7 +9,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
9
9
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
-
import { $createRangeSelection, $getSelection, $isLineBreakNode, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection } from 'lexical';
|
|
12
|
+
import { $createRangeSelection, $getNodeByKey, $getSelection, $isLineBreakNode, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection } from 'lexical';
|
|
13
13
|
import { PUNCTUATION_OR_SPACE, getOpenTagStartIndex, isEqualSubString } from "../utils";
|
|
14
14
|
export function testElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers, fromTrigger) {
|
|
15
15
|
var grandParentNode = parentNode.getParent();
|
|
@@ -230,7 +230,19 @@ export function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatT
|
|
|
230
230
|
nextSelection.anchor.set(openNode.__key, openTagStartIndex, 'text');
|
|
231
231
|
nextSelection.focus.set(closeNode.__key, newOffset, 'text');
|
|
232
232
|
if (matcher.process) {
|
|
233
|
-
matcher.process(nextSelection)
|
|
233
|
+
if (matcher.process(nextSelection) === false) {
|
|
234
|
+
var currentOpenNode = $getNodeByKey(openNode.__key);
|
|
235
|
+
var currentCloseNode = $getNodeByKey(closeNode.__key);
|
|
236
|
+
if ($isTextNode(currentOpenNode)) {
|
|
237
|
+
currentOpenNode.setTextContent(prevOpenNodeText);
|
|
238
|
+
}
|
|
239
|
+
if (currentCloseNode !== currentOpenNode && $isTextNode(currentCloseNode)) {
|
|
240
|
+
currentCloseNode.setTextContent(prevCloseNodeText);
|
|
241
|
+
}
|
|
242
|
+
// If process function returns false, cancel the transform and set selection to original position
|
|
243
|
+
$setSelection(anchorNode.selectEnd());
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
234
246
|
return true;
|
|
235
247
|
} else if (matcher.format) {
|
|
236
248
|
// Apply formatting to selected text
|
package/package.json
CHANGED