@lobehub/editor 3.2.2 → 3.3.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.
Files changed (41) hide show
  1. package/es/editor-kernel/react/useLexicalNodeSelection.d.ts +1 -1
  2. package/es/editor-kernel/react/useLexicalNodeSelection.js +22 -1
  3. package/es/index.d.ts +1 -0
  4. package/es/index.js +1 -0
  5. package/es/locale/index.d.ts +10 -0
  6. package/es/locale/index.js +10 -0
  7. package/es/plugins/codemirror-block/command/index.d.ts +9 -0
  8. package/es/plugins/codemirror-block/command/index.js +46 -0
  9. package/es/plugins/codemirror-block/index.d.ts +2 -0
  10. package/es/plugins/codemirror-block/index.js +2 -0
  11. package/es/plugins/codemirror-block/lib/index.d.ts +58 -0
  12. package/es/plugins/codemirror-block/lib/index.js +40 -0
  13. package/es/plugins/codemirror-block/lib/mode.d.ts +25 -0
  14. package/es/plugins/codemirror-block/lib/mode.js +416 -0
  15. package/es/plugins/codemirror-block/node/CodeMirrorNode.d.ts +46 -0
  16. package/es/plugins/codemirror-block/node/CodeMirrorNode.js +343 -0
  17. package/es/plugins/codemirror-block/plugin/index.d.ts +8 -0
  18. package/es/plugins/codemirror-block/plugin/index.js +113 -0
  19. package/es/plugins/codemirror-block/react/CodemirrorNode.d.ts +10 -0
  20. package/es/plugins/codemirror-block/react/CodemirrorNode.js +323 -0
  21. package/es/plugins/codemirror-block/react/ReactCodemirrorNode.d.ts +4 -0
  22. package/es/plugins/codemirror-block/react/ReactCodemirrorNode.js +34 -0
  23. package/es/plugins/codemirror-block/react/components/CopyButton.d.ts +5 -0
  24. package/es/plugins/codemirror-block/react/components/CopyButton.js +35 -0
  25. package/es/plugins/codemirror-block/react/components/LanguageSelect.d.ts +8 -0
  26. package/es/plugins/codemirror-block/react/components/LanguageSelect.js +77 -0
  27. package/es/plugins/codemirror-block/react/components/MoreOptions.d.ts +16 -0
  28. package/es/plugins/codemirror-block/react/components/MoreOptions.js +79 -0
  29. package/es/plugins/codemirror-block/react/components/Toolbar.d.ts +16 -0
  30. package/es/plugins/codemirror-block/react/components/Toolbar.js +56 -0
  31. package/es/plugins/codemirror-block/react/components/style.d.ts +3 -0
  32. package/es/plugins/codemirror-block/react/components/style.js +9 -0
  33. package/es/plugins/codemirror-block/react/index.d.ts +1 -0
  34. package/es/plugins/codemirror-block/react/index.js +1 -0
  35. package/es/plugins/codemirror-block/react/style.d.ts +1 -0
  36. package/es/plugins/codemirror-block/react/style.js +8 -0
  37. package/es/plugins/codemirror-block/react/theme.d.ts +133 -0
  38. package/es/plugins/codemirror-block/react/theme.js +158 -0
  39. package/es/plugins/codemirror-block/react/type.d.ts +3 -0
  40. package/es/plugins/codemirror-block/react/type.js +1 -0
  41. package/package.json +4 -2
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import { ActionIcon, Flexbox } from '@lobehub/ui';
4
+ import { ChevronDown, ChevronRight } from 'lucide-react';
5
+ import CopyButton from "./CopyButton";
6
+ import { LanguageSelect } from "./LanguageSelect";
7
+ import { MoreOptions } from "./MoreOptions";
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ export var Toolbar = function Toolbar(_ref) {
11
+ var selectedLang = _ref.selectedLang,
12
+ onLanguageChange = _ref.onLanguageChange,
13
+ onCopy = _ref.onCopy,
14
+ tabSize = _ref.tabSize,
15
+ onTabSizeChange = _ref.onTabSizeChange,
16
+ useTabs = _ref.useTabs,
17
+ onUseTabsChange = _ref.onUseTabsChange,
18
+ showLineNumbers = _ref.showLineNumbers,
19
+ onShowLineNumbersChange = _ref.onShowLineNumbersChange,
20
+ onClick = _ref.onClick,
21
+ expand = _ref.expand,
22
+ toggleExpand = _ref.toggleExpand;
23
+ return /*#__PURE__*/_jsxs(Flexbox, {
24
+ align: 'center',
25
+ className: 'cm-header-toolbar',
26
+ horizontal: true,
27
+ justify: 'space-between',
28
+ onClick: onClick,
29
+ padding: 4,
30
+ children: [/*#__PURE__*/_jsx(LanguageSelect, {
31
+ onLanguageChange: onLanguageChange,
32
+ selectedLang: selectedLang
33
+ }), /*#__PURE__*/_jsxs(Flexbox, {
34
+ gap: 4,
35
+ horizontal: true,
36
+ onClick: function onClick(e) {
37
+ return e.stopPropagation();
38
+ },
39
+ children: [/*#__PURE__*/_jsx(MoreOptions, {
40
+ onShowLineNumbersChange: onShowLineNumbersChange,
41
+ onTabSizeChange: onTabSizeChange,
42
+ onUseTabsChange: onUseTabsChange,
43
+ showLineNumbers: showLineNumbers,
44
+ tabSize: tabSize,
45
+ useTabs: useTabs
46
+ }), /*#__PURE__*/_jsx(CopyButton, {
47
+ onCopy: onCopy
48
+ }), /*#__PURE__*/_jsx(ActionIcon, {
49
+ icon: expand ? ChevronDown : ChevronRight,
50
+ onClick: toggleExpand,
51
+ size: "small"
52
+ })]
53
+ })]
54
+ });
55
+ };
56
+ Toolbar.displayName = 'Toolbar';
@@ -0,0 +1,3 @@
1
+ export declare const styles: {
2
+ container: string;
3
+ };
@@ -0,0 +1,9 @@
1
+ var _templateObject;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStaticStyles } from 'antd-style';
4
+ export var styles = createStaticStyles(function (_ref) {
5
+ var css = _ref.css;
6
+ return {
7
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n min-width: 160px;\n "])))
8
+ };
9
+ });
@@ -0,0 +1 @@
1
+ export { default as ReactCodemirrorPlugin } from './ReactCodemirrorNode';
@@ -0,0 +1 @@
1
+ export { default as ReactCodemirrorPlugin } from "./ReactCodemirrorNode";
@@ -0,0 +1 @@
1
+ export declare const styles: string;
@@ -0,0 +1,8 @@
1
+ var _templateObject;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStaticStyles } from 'antd-style';
4
+ export var styles = createStaticStyles(function (_ref) {
5
+ var css = _ref.css,
6
+ cssVar = _ref.cssVar;
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n position: relative;\n\n overflow: hidden;\n display: flex;\n flex-direction: column;\n align-items: center;\n\n width: 100%;\n\n background: ", ";\n\n .cm-hidden-actions {\n opacity: 0;\n transition: opacity 0.2s ease-in-out;\n }\n\n .cm-language-select {\n opacity: 0.5;\n filter: grayscale(100%);\n transition:\n opacity,\n grayscale 0.2s ease-in-out;\n }\n\n &.selected {\n user-select: none;\n }\n\n &.selected::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n z-index: 10;\n inset: 0;\n\n width: 100%;\n height: 100%;\n\n opacity: 0.2;\n background: ", ";\n\n transition: all 0.3s;\n }\n\n .cm-container {\n position: relative;\n width: 100%;\n border-block-start: 1px solid ", ";\n }\n\n .cm-container-collapsed {\n overflow: hidden;\n height: 0;\n border-block-start: none;\n }\n\n .cm-textarea {\n height: 44px;\n opacity: 0;\n }\n\n &:hover {\n .cm-hidden-actions {\n opacity: 1;\n }\n\n .cm-language-select {\n opacity: 1;\n filter: grayscale(0);\n }\n }\n "])), cssVar.colorFillQuaternary, cssVar.yellow, cssVar.colorFillQuaternary);
8
+ });
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Lobe 主题配置
3
+ * 基于 shiki 主题配置,使用 antd-style 的 cssVar 进行颜色映射
4
+ */
5
+ export declare const lobeTheme: {
6
+ '&': {
7
+ '& .cm-cursor': {
8
+ 'border-left-color': string;
9
+ };
10
+ '& .cm-cursor.cm-cursor-primary': {
11
+ 'border-inline-start': string;
12
+ };
13
+ '& .cm-gutters': {
14
+ 'background-color': string;
15
+ border: string;
16
+ color: string;
17
+ cursor: string;
18
+ };
19
+ '& .cm-line': {
20
+ '& .cm-atom': {
21
+ color: string;
22
+ };
23
+ '& .cm-attribute': {
24
+ color: string;
25
+ };
26
+ '& .cm-builtin': {
27
+ color: string;
28
+ fontStyle: string;
29
+ };
30
+ '& .cm-comment': {
31
+ color: string;
32
+ fontStyle: string;
33
+ };
34
+ '& .cm-foldPlaceholder': {
35
+ background: string;
36
+ border: string;
37
+ color: string;
38
+ display: string;
39
+ height: string;
40
+ padding: number;
41
+ 'vertical-align': string;
42
+ width: string;
43
+ };
44
+ '& .cm-function': {
45
+ color: string;
46
+ };
47
+ '& .cm-header': {
48
+ color: string;
49
+ };
50
+ '& .cm-keyword': {
51
+ color: string;
52
+ };
53
+ '& .cm-meta': {
54
+ color: string;
55
+ };
56
+ '& .cm-modifier': {
57
+ color: string;
58
+ };
59
+ '& .cm-number': {
60
+ color: string;
61
+ };
62
+ '& .cm-operator': {
63
+ color: string;
64
+ };
65
+ '& .cm-property': {
66
+ color: string;
67
+ };
68
+ '& .cm-punctuation': {
69
+ color: string;
70
+ };
71
+ '& .cm-qualifier': {
72
+ color: string;
73
+ };
74
+ '& .cm-string': {
75
+ color: string;
76
+ };
77
+ '& .cm-string-2': {
78
+ color: string;
79
+ };
80
+ '& .cm-tag': {
81
+ color: string;
82
+ };
83
+ '& .cm-tag.cm-bracket': {
84
+ color: string;
85
+ };
86
+ '& .cm-type': {
87
+ color: string;
88
+ };
89
+ '& .cm-variable': {
90
+ color: string;
91
+ };
92
+ '& .cm-variable-2': {
93
+ color: string;
94
+ };
95
+ '& .cm-variable-3': {
96
+ color: string;
97
+ };
98
+ '& .cm-variable.cm-callee': {
99
+ color: string;
100
+ };
101
+ '& .cm-variable.cm-def': {
102
+ color: string;
103
+ };
104
+ color: string;
105
+ 'padding-inline': string;
106
+ };
107
+ };
108
+ '& .cm-selectionBackground': {
109
+ background: string;
110
+ };
111
+ '& .cm-selectionMatch': {
112
+ background: string;
113
+ };
114
+ '&.cm-editor': {
115
+ background: string;
116
+ cursor: string;
117
+ 'padding-block': string;
118
+ width: string;
119
+ };
120
+ '&.cm-editor span': {
121
+ 'font-family': string;
122
+ 'font-size': string;
123
+ };
124
+ '&.cm-editor.cm-focused .cm-selectionBackground': {
125
+ background: string;
126
+ };
127
+ '&.cm-editor.cm-focused .cm-selectionLineGutter': {
128
+ color: string;
129
+ };
130
+ '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground': {
131
+ background: string;
132
+ };
133
+ };
@@ -0,0 +1,158 @@
1
+ import { cssVar } from 'antd-style';
2
+
3
+ /**
4
+ * Lobe 主题配置
5
+ * 基于 shiki 主题配置,使用 antd-style 的 cssVar 进行颜色映射
6
+ */
7
+ export var lobeTheme = {
8
+ '&': {
9
+ '& .cm-cursor': {
10
+ 'border-left-color': cssVar.colorPrimary
11
+ },
12
+ '& .cm-cursor.cm-cursor-primary': {
13
+ 'border-inline-start': "2px solid ".concat(cssVar.colorPrimary, " !important")
14
+ },
15
+ '& .cm-gutters': {
16
+ 'background-color': cssVar.colorBgContainer,
17
+ 'border': 'none',
18
+ 'color': cssVar.colorTextQuaternary,
19
+ 'cursor': 'default'
20
+ },
21
+ '& .cm-line': {
22
+ // 布尔值 - constant.language.boolean
23
+ '& .cm-atom': {
24
+ color: cssVar.purple10
25
+ },
26
+ // 属性名 - entity.other.attribute-name
27
+ '& .cm-attribute': {
28
+ color: cssVar.purple10
29
+ },
30
+ // 内置 - support.module, support.node
31
+ '& .cm-builtin': {
32
+ color: cssVar.volcano10,
33
+ fontStyle: 'italic'
34
+ },
35
+ // 注释 - comment
36
+ '& .cm-comment': {
37
+ color: cssVar.colorTextQuaternary,
38
+ fontStyle: 'italic'
39
+ },
40
+ // 折叠占位符
41
+ '& .cm-foldPlaceholder': {
42
+ 'background': "url(\"data:image/svg+xml,%3Csvg width='16' height='16' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Crect fill='%23E8E8E8' width='16' height='16' rx='2'/%3E%3Cpath d='M2.75 7.984a.875.875 0 1 0 1.75 0 .875.875 0 0 0-1.75 0Zm4.375 0a.875.875 0 1 0 1.75 0 .875.875 0 0 0-1.75 0Zm4.375 0a.875.875 0 1 0 1.75 0 .875.875 0 0 0-1.75 0Z' fill='%232A3238'/%3E%3C/g%3E%3C/svg%3E\") no-repeat",
43
+ 'border': 'none',
44
+ 'color': 'transparent',
45
+ 'display': 'inline-block',
46
+ 'height': '16px',
47
+ 'padding': 0,
48
+ 'vertical-align': 'middle',
49
+ 'width': '16px'
50
+ },
51
+ // 函数名 - entity.name.function, support.function
52
+ '& .cm-function': {
53
+ color: cssVar.geekblue10
54
+ },
55
+ // 标题 - markup.heading
56
+ '& .cm-header': {
57
+ color: cssVar.colorInfo
58
+ },
59
+ // 关键字 - keyword, modifier, storage.type, storage.modifier, storage.control
60
+ '& .cm-keyword': {
61
+ color: cssVar.colorInfo
62
+ },
63
+ // 元数据 - meta
64
+ '& .cm-meta': {
65
+ color: cssVar.colorText
66
+ },
67
+ '& .cm-modifier': {
68
+ color: cssVar.colorInfo
69
+ },
70
+ // 数字 - constant.numeric
71
+ '& .cm-number': {
72
+ color: cssVar.volcano10
73
+ },
74
+ // 操作符 - punctuation, operator
75
+ '& .cm-operator': {
76
+ color: cssVar.colorInfo
77
+ },
78
+ // 属性 - variable.object.property
79
+ '& .cm-property': {
80
+ color: cssVar.volcano10
81
+ },
82
+ '& .cm-punctuation': {
83
+ color: cssVar.colorInfo
84
+ },
85
+ // 限定符 - support.type.property-name
86
+ '& .cm-qualifier': {
87
+ color: cssVar.colorWarning
88
+ },
89
+ // 字符串 - string
90
+ '& .cm-string': {
91
+ color: cssVar.colorSuccess
92
+ },
93
+ '& .cm-string-2': {
94
+ color: cssVar.colorSuccess
95
+ },
96
+ // 标签 - entity.name.tag, meta.tag
97
+ '& .cm-tag': {
98
+ color: cssVar.volcano10
99
+ },
100
+ '& .cm-tag.cm-bracket': {
101
+ color: cssVar.colorInfo
102
+ },
103
+ // 类型 - entity.name.type, support.type, storage.type
104
+ '& .cm-type': {
105
+ color: cssVar.colorWarning
106
+ },
107
+ // 变量 - variable, variable.parameter
108
+ '& .cm-variable': {
109
+ color: cssVar.colorText
110
+ },
111
+ '& .cm-variable-2': {
112
+ color: cssVar.geekblue10
113
+ },
114
+ '& .cm-variable-3': {
115
+ color: cssVar.colorWarning
116
+ },
117
+ '& .cm-variable.cm-callee': {
118
+ color: cssVar.geekblue10
119
+ },
120
+ '& .cm-variable.cm-def': {
121
+ color: cssVar.colorText
122
+ },
123
+ // 默认文本颜色
124
+ 'color': cssVar.colorText,
125
+ 'padding-inline': '12px'
126
+ }
127
+ },
128
+ // 选中背景
129
+ '& .cm-selectionBackground': {
130
+ background: 'transparent'
131
+ },
132
+ // 选中匹配
133
+ '& .cm-selectionMatch': {
134
+ background: "".concat(cssVar.colorFillSecondary, " !important")
135
+ },
136
+ // 编辑器背景
137
+ '&.cm-editor': {
138
+ 'background': 'transparent',
139
+ 'cursor': 'text',
140
+ 'padding-block': '12px',
141
+ 'width': '100%'
142
+ },
143
+ '&.cm-editor span': {
144
+ 'font-family': cssVar.fontFamilyCode,
145
+ 'font-size': 'calc(var(--lobe-markdown-font-size) * 0.8)'
146
+ },
147
+ // 聚焦时的选中背景
148
+ '&.cm-editor.cm-focused .cm-selectionBackground': {
149
+ background: cssVar.colorPrimaryBg
150
+ },
151
+ // 聚焦时的行号颜色
152
+ '&.cm-editor.cm-focused .cm-selectionLineGutter': {
153
+ color: cssVar.colorText
154
+ },
155
+ '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground': {
156
+ background: cssVar.yellow
157
+ }
158
+ };
@@ -0,0 +1,3 @@
1
+ export interface ReactCodemirrorPluginProps {
2
+ className?: string;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
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",
@@ -41,6 +41,7 @@
41
41
  "@lexical/selection": "^0.39.0",
42
42
  "@lexical/table": "^0.39.0",
43
43
  "@lexical/utils": "^0.39.0",
44
+ "@lobehub/codemirror": "^1.0.0",
44
45
  "@shikijs/core": "^3.20.0",
45
46
  "@shikijs/engine-javascript": "^3.20.0",
46
47
  "@xmldom/xmldom": "^0.8.11",
@@ -69,5 +70,6 @@
69
70
  "motion": "^12.0.0",
70
71
  "react": "^19.0.0",
71
72
  "react-dom": "^19.0.0"
72
- }
73
+ },
74
+ "packageManager": "pnpm@10.20.0"
73
75
  }