@lobehub/editor 1.15.0 → 1.16.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.
|
@@ -166,7 +166,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
168
|
return /*#__PURE__*/_jsxs("div", {
|
|
169
|
-
className: cx(styles.root, markdownOption === true && styles.variant, markdownOption === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.header === true && styles.header, _typeof(markdownOption) === 'object' && markdownOption.header === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.code === true && styles.code, _typeof(markdownOption) === 'object' && markdownOption.quote === true && styles.blockquote, className),
|
|
169
|
+
className: cx(styles.root, markdownOption === true && styles.variant, markdownOption === false && styles.noStyle, markdownOption === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.header === true && styles.header, _typeof(markdownOption) === 'object' && markdownOption.header === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.code === true && styles.code, _typeof(markdownOption) === 'object' && markdownOption.quote === true && styles.blockquote, className),
|
|
170
170
|
style: style,
|
|
171
171
|
children: [/*#__PURE__*/_jsx("div", {
|
|
172
172
|
contentEditable: true,
|
|
@@ -26,6 +26,7 @@ export declare const useStyles: (props?: {
|
|
|
26
26
|
code: import("antd-style").SerializedStyles;
|
|
27
27
|
header: import("antd-style").SerializedStyles;
|
|
28
28
|
noHeader: import("antd-style").SerializedStyles;
|
|
29
|
+
noStyle: import("antd-style").SerializedStyles;
|
|
29
30
|
p: import("antd-style").SerializedStyles;
|
|
30
31
|
root: import("antd-style").SerializedStyles;
|
|
31
32
|
variant: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16;
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
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); }
|
|
4
4
|
import { createStyles } from 'antd-style';
|
|
@@ -30,7 +30,7 @@ export var useStyles = createStyles(function (_ref2, _ref3) {
|
|
|
30
30
|
lineHeight = _ref3$lineHeight === void 0 ? 1.8 : _ref3$lineHeight;
|
|
31
31
|
var __root = css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n width: 100%;\n max-width: 100%;\n height: 100%;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n @keyframes cursor-blink {\n to {\n visibility: hidden;\n }\n }\n\n [data-lexical-cursor='true'] {\n pointer-events: none;\n position: absolute;\n display: block;\n\n &::after {\n content: '';\n\n position: absolute;\n inset-block-start: -2px;\n\n display: block;\n\n width: 20px;\n border-block-start: 1px solid ", ";\n\n animation: cursor-blink 1.1s steps(2, start) infinite;\n }\n }\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadiusLG, token.colorFillQuaternary, token.colorText);
|
|
32
32
|
var header = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: max(\n calc(var(--lobe-markdown-header-multiple) * var(--lobe-markdown-margin-multiple) * 0.4em),\n var(--lobe-markdown-font-size)\n );\n font-weight: bold;\n line-height: 1.25;\n }\n\n h1 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 1.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h2 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + var(--lobe-markdown-header-multiple))\n );\n }\n\n h3 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h4 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.25 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h5,\n h6 {\n font-size: calc(var(--lobe-markdown-font-size) * 1);\n }\n "])));
|
|
33
|
-
var p = css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n p {\n margin-block:
|
|
33
|
+
var p = css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n p {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n line-height: var(--lobe-markdown-line-height);\n letter-spacing: 0.02em;\n\n &:not(:first-child) {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n\n &:not(:last-child) {\n margin-block-end: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n }\n "])));
|
|
34
34
|
var blockquote = css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n .editor_quote {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n border-inline-start: solid 4px ", ";\n\n color: ", ";\n }\n "])), token.colorBorder, token.colorTextSecondary);
|
|
35
35
|
var code = css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n .editor_code {\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n }\n "])), token.fontFamilyCode, token.colorFillSecondary);
|
|
36
36
|
return {
|
|
@@ -38,6 +38,7 @@ export var useStyles = createStyles(function (_ref2, _ref3) {
|
|
|
38
38
|
code: code,
|
|
39
39
|
header: header,
|
|
40
40
|
noHeader: css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: 4px;\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n letter-spacing: 0.02em;\n\n &:not(:first-child) {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n\n &:not(:last-child) {\n margin-block-end: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n }\n "]))),
|
|
41
|
+
noStyle: css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n --lobe-markdown-header-multiple: 0;\n --lobe-markdown-margin-multiple: 0;\n --lobe-markdown-line-height: 1.5;\n\n p {\n margin-block: 0;\n }\n "]))),
|
|
41
42
|
p: p,
|
|
42
43
|
root: __root,
|
|
43
44
|
variant: cx(header, p, blockquote, code)
|
|
@@ -63,104 +63,104 @@ function convertMdastToLexical(node, index, ctx) {
|
|
|
63
63
|
}
|
|
64
64
|
default:
|
|
65
65
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return ret;
|
|
87
|
-
}
|
|
66
|
+
var _children = [];
|
|
67
|
+
if ('children' in node && Array.isArray(node.children)) {
|
|
68
|
+
var htmlStack = []; // 当前循环是否包含 HTML 标签
|
|
69
|
+
_children = node.children.reduce(function (ret, child, index) {
|
|
70
|
+
if (child.type === 'html') {
|
|
71
|
+
var tag = child.value.replaceAll(/^<\/?|>$/g, '');
|
|
72
|
+
var isEndTag = child.value.startsWith('</');
|
|
73
|
+
if (selfClosingHtmlTags.has(tag)) {
|
|
74
|
+
// Self-closing tag
|
|
75
|
+
var reader = markdownReaders['html'];
|
|
76
|
+
if (Array.isArray(reader)) {
|
|
77
|
+
var _iterator = _createForOfIteratorHelper(reader),
|
|
78
|
+
_step;
|
|
79
|
+
try {
|
|
80
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
81
|
+
var element = _step.value;
|
|
82
|
+
var inode = element(child, [], index);
|
|
83
|
+
if (inode) {
|
|
84
|
+
ret.push(inode);
|
|
85
|
+
return ret;
|
|
88
86
|
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_iterator.e(err);
|
|
91
|
-
} finally {
|
|
92
|
-
_iterator.f();
|
|
93
|
-
}
|
|
94
|
-
} else if (typeof _reader === 'function') {
|
|
95
|
-
var _inode = _reader(child, [], index);
|
|
96
|
-
if (_inode) {
|
|
97
|
-
ret.push(_inode);
|
|
98
|
-
return ret;
|
|
99
87
|
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
_iterator.e(err);
|
|
90
|
+
} finally {
|
|
91
|
+
_iterator.f();
|
|
100
92
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
htmlStack.pop();
|
|
106
|
-
if ((top === null || top === void 0 ? void 0 : top.tag) !== tag) {
|
|
107
|
-
logger.warn('HTML tag mismatch:', tag);
|
|
108
|
-
ret.push.apply(ret, _toConsumableArray((top === null || top === void 0 ? void 0 : top.children) || []));
|
|
93
|
+
} else if (typeof reader === 'function') {
|
|
94
|
+
var _inode = reader(child, [], index);
|
|
95
|
+
if (_inode) {
|
|
96
|
+
ret.push(_inode);
|
|
109
97
|
return ret;
|
|
110
98
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
99
|
+
}
|
|
100
|
+
return ret;
|
|
101
|
+
}
|
|
102
|
+
if (isEndTag) {
|
|
103
|
+
var top = ctx.pop();
|
|
104
|
+
htmlStack.pop();
|
|
105
|
+
if ((top === null || top === void 0 ? void 0 : top.tag) !== tag) {
|
|
106
|
+
logger.warn('HTML tag mismatch:', tag);
|
|
107
|
+
ret.push.apply(ret, _toConsumableArray((top === null || top === void 0 ? void 0 : top.children) || []));
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
var _reader = markdownReaders['html'];
|
|
111
|
+
var _children2 = top.children.flat().filter(Boolean) || [];
|
|
112
|
+
if (Array.isArray(_reader)) {
|
|
113
|
+
var _iterator2 = _createForOfIteratorHelper(_reader),
|
|
114
|
+
_step2;
|
|
115
|
+
try {
|
|
116
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
117
|
+
var _element = _step2.value;
|
|
118
|
+
var _inode2 = _element(top.node, _children2, index);
|
|
119
|
+
if (_inode2) {
|
|
120
|
+
ret.push(_inode2);
|
|
121
|
+
return ret;
|
|
124
122
|
}
|
|
125
|
-
} catch (err) {
|
|
126
|
-
_iterator2.e(err);
|
|
127
|
-
} finally {
|
|
128
|
-
_iterator2.f();
|
|
129
|
-
}
|
|
130
|
-
} else if (typeof _reader2 === 'function') {
|
|
131
|
-
var _inode3 = _reader2(top.node, _children2, index);
|
|
132
|
-
if (_inode3) {
|
|
133
|
-
ret.push(_inode3);
|
|
134
|
-
return ret;
|
|
135
123
|
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
_iterator2.e(err);
|
|
126
|
+
} finally {
|
|
127
|
+
_iterator2.f();
|
|
136
128
|
}
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
} else if (typeof _reader === 'function') {
|
|
130
|
+
var _inode3 = _reader(top.node, _children2, index);
|
|
131
|
+
if (_inode3) {
|
|
132
|
+
ret.push(_inode3);
|
|
133
|
+
return ret;
|
|
139
134
|
}
|
|
140
|
-
return ret;
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
children
|
|
144
|
-
index: index,
|
|
145
|
-
isEndTag: isEndTag,
|
|
146
|
-
node: child,
|
|
147
|
-
tag: tag
|
|
148
|
-
};
|
|
149
|
-
htmlStack.push(htmlStackItem);
|
|
150
|
-
ctx.push(htmlStackItem);
|
|
151
|
-
return ret;
|
|
152
|
-
}
|
|
153
|
-
if (htmlStack.length > 0) {
|
|
154
|
-
var _top = ctx.last;
|
|
155
|
-
if (_top) {
|
|
156
|
-
_top.children.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
136
|
+
if (top) {
|
|
137
|
+
ret.push.apply(ret, _toConsumableArray(top.children));
|
|
157
138
|
}
|
|
158
139
|
return ret;
|
|
159
140
|
}
|
|
160
|
-
|
|
141
|
+
var htmlStackItem = {
|
|
142
|
+
children: [],
|
|
143
|
+
index: index,
|
|
144
|
+
isEndTag: isEndTag,
|
|
145
|
+
node: child,
|
|
146
|
+
tag: tag
|
|
147
|
+
};
|
|
148
|
+
htmlStack.push(htmlStackItem);
|
|
149
|
+
ctx.push(htmlStackItem);
|
|
161
150
|
return ret;
|
|
162
|
-
}
|
|
163
|
-
|
|
151
|
+
}
|
|
152
|
+
if (htmlStack.length > 0) {
|
|
153
|
+
var _top = ctx.last;
|
|
154
|
+
if (_top) {
|
|
155
|
+
_top.children.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
156
|
+
}
|
|
157
|
+
return ret;
|
|
158
|
+
}
|
|
159
|
+
ret.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
160
|
+
return ret;
|
|
161
|
+
}, []).filter(Boolean).flat();
|
|
162
|
+
}
|
|
163
|
+
if (markdownReaders[node.type]) {
|
|
164
164
|
var reader = markdownReaders[node.type];
|
|
165
165
|
if (Array.isArray(reader)) {
|
|
166
166
|
var _iterator3 = _createForOfIteratorHelper(reader),
|
|
@@ -187,7 +187,7 @@ function convertMdastToLexical(node, index, ctx) {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// Fallback for unsupported nodes
|
|
190
|
-
return null;
|
|
190
|
+
return _children || null;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
}
|
package/package.json
CHANGED