@lobehub/editor 4.17.2 → 4.18.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.
- package/es/headless/index.js +12 -2
- package/es/headless.js +3119 -1224
- package/es/index.d.ts +1 -1
- package/es/index.js +13 -13
- package/es/plugins/codeblock/command/index.d.ts +2 -8
- package/es/plugins/codeblock/command/index.js +3 -3
- package/es/plugins/codeblock/command/symbols.d.ts +8 -0
- package/es/plugins/codeblock/command/symbols.js +5 -0
- package/es/plugins/codeblock/index.d.ts +1 -1
- package/es/plugins/codeblock/index.js +1 -1
- package/es/plugins/codeblock/plugin/FacadeShiki.js +1 -1
- package/es/plugins/codeblock/plugin/index.js +1 -1
- package/es/plugins/codemirror-block/command/index.js +1 -1
- package/es/plugins/codemirror-block/node/CodeMirrorNode.js +10 -1
- package/es/plugins/codemirror-block/plugin/index.d.ts +1 -1
- package/es/plugins/file/plugin/index.d.ts +2 -2
- package/es/plugins/file/plugin/index.js +26 -23
- package/es/plugins/image/node/block-image-node.d.ts +1 -0
- package/es/plugins/image/node/block-image-node.js +6 -0
- package/es/plugins/image/node/image-node.d.ts +1 -0
- package/es/plugins/image/node/image-node.js +6 -0
- package/es/plugins/image/plugin/index.d.ts +3 -3
- package/es/plugins/image/plugin/index.js +5 -23
- package/es/plugins/image/react/ReactImagePlugin.js +18 -0
- package/es/plugins/image/react/components/Image.js +1 -1
- package/es/plugins/math/plugin/index.d.ts +1 -1
- package/es/plugins/math/react/components/MathEditor.js +1 -1
- package/es/plugins/math/react/components/MathInline.js +1 -1
- package/es/plugins/mention/plugin/index.d.ts +1 -1
- package/es/plugins/mention/plugin/index.js +1 -1
- package/es/react/hooks/useEditorState/index.js +2 -2
- package/es/renderer/engine/shiki.js +1 -1
- package/es/renderer/nodes/index.js +4 -4
- package/es/renderer/renderers/codeblock.js +1 -0
- package/package.json +1 -1
- package/es/headless/plugins/codeblock.js +0 -82
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { INodeHelper, init_helper } from "../../editor-kernel/inode/helper.js";
|
|
2
|
-
import { KernelPlugin, init_plugin } from "../../editor-kernel/plugin.js";
|
|
3
|
-
import { ILitexmlService } from "../../plugins/litexml/service/litexml-service.js";
|
|
4
|
-
import { IMarkdownShortCutService } from "../../plugins/markdown/service/shortcut.js";
|
|
5
|
-
import { getCodeLanguageByInput } from "../../plugins/codeblock/utils/language.js";
|
|
6
|
-
import { TabNode } from "lexical";
|
|
7
|
-
import { $isCodeHighlightNode, $isCodeNode, CodeHighlightNode, CodeNode } from "@lexical/code-core";
|
|
8
|
-
//#region src/headless/plugins/codeblock.ts
|
|
9
|
-
init_helper();
|
|
10
|
-
init_plugin();
|
|
11
|
-
const createCodeChildren = (code) => code.split("\n").flatMap((text, index, array) => {
|
|
12
|
-
const textNode = INodeHelper.createTextNode(text);
|
|
13
|
-
textNode.type = "code-highlight";
|
|
14
|
-
if (index === array.length - 1) return textNode;
|
|
15
|
-
return [textNode, {
|
|
16
|
-
type: "linebreak",
|
|
17
|
-
version: 1
|
|
18
|
-
}];
|
|
19
|
-
}).flat();
|
|
20
|
-
const HeadlessCodeblockPlugin = class extends KernelPlugin {
|
|
21
|
-
static {
|
|
22
|
-
this.pluginName = "HeadlessCodeblockPlugin";
|
|
23
|
-
}
|
|
24
|
-
constructor(kernel) {
|
|
25
|
-
super();
|
|
26
|
-
this.kernel = kernel;
|
|
27
|
-
kernel.registerNodes([CodeNode, CodeHighlightNode]);
|
|
28
|
-
kernel.registerThemes({ code: "editor-code" });
|
|
29
|
-
}
|
|
30
|
-
onInit() {
|
|
31
|
-
this.registerMarkdown();
|
|
32
|
-
this.registerLiteXml();
|
|
33
|
-
}
|
|
34
|
-
registerLiteXml() {
|
|
35
|
-
const litexmlService = this.kernel.requireService(ILitexmlService);
|
|
36
|
-
if (!litexmlService) return;
|
|
37
|
-
litexmlService.registerXMLWriter(CodeNode.getType(), (node, ctx) => {
|
|
38
|
-
const codeNode = node;
|
|
39
|
-
return ctx.createXmlNode("code", { lang: codeNode.getLanguage() || "plaintext" }, codeNode.getTextContent());
|
|
40
|
-
});
|
|
41
|
-
litexmlService.registerXMLReader("code", (xmlElement, children) => {
|
|
42
|
-
const text = children.map((value) => value.text || "").join("");
|
|
43
|
-
return INodeHelper.createElementNode(CodeNode.getType(), {
|
|
44
|
-
children: createCodeChildren(text),
|
|
45
|
-
direction: "ltr",
|
|
46
|
-
format: "",
|
|
47
|
-
indent: 0,
|
|
48
|
-
language: xmlElement.getAttribute("lang"),
|
|
49
|
-
version: 1
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
registerMarkdown() {
|
|
54
|
-
const markdownService = this.kernel.requireService(IMarkdownShortCutService);
|
|
55
|
-
if (!markdownService) return;
|
|
56
|
-
markdownService.registerMarkdownWriter(CodeNode.getType(), (ctx, node) => {
|
|
57
|
-
if ($isCodeNode(node)) ctx.wrap("```" + (node.getLanguage() || "") + "\n", "\n```\n");
|
|
58
|
-
});
|
|
59
|
-
markdownService.registerMarkdownWriter(TabNode.getType(), (ctx) => {
|
|
60
|
-
ctx.appendLine(" ");
|
|
61
|
-
});
|
|
62
|
-
markdownService.registerMarkdownWriter(CodeHighlightNode.getType(), (ctx, node) => {
|
|
63
|
-
if ($isCodeHighlightNode(node)) ctx.appendLine(node.getTextContent());
|
|
64
|
-
});
|
|
65
|
-
markdownService.registerMarkdownWriter("linebreak", (ctx, node) => {
|
|
66
|
-
if ($isCodeNode(node.getParent())) ctx.appendLine("\n");
|
|
67
|
-
});
|
|
68
|
-
markdownService.registerMarkdownReader("code", (node) => {
|
|
69
|
-
const language = node.lang ? getCodeLanguageByInput(node.lang) : "plaintext";
|
|
70
|
-
return INodeHelper.createElementNode("code", {
|
|
71
|
-
children: createCodeChildren(node.value),
|
|
72
|
-
direction: "ltr",
|
|
73
|
-
format: "",
|
|
74
|
-
indent: 0,
|
|
75
|
-
language,
|
|
76
|
-
version: 1
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
//#endregion
|
|
82
|
-
export { HeadlessCodeblockPlugin };
|