@lobehub/editor 4.8.4 → 4.8.5
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/renderer.js +60 -0
- package/package.json +1 -1
package/es/renderer.js
CHANGED
|
@@ -121,6 +121,65 @@ function formatLinkHighlightUrl(url) {
|
|
|
121
121
|
function textToSlug(text) {
|
|
122
122
|
return text.toLowerCase().trim().replaceAll(/[^\s\w\u3000-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF-]/g, "").replaceAll(/[\s_]+/g, "-").replaceAll(/^-+|-+$/g, "");
|
|
123
123
|
}
|
|
124
|
+
const DIFF_ROOT_STYLE = { position: "relative" };
|
|
125
|
+
const DIFF_LIST_ITEM_ROOT_STYLE = {
|
|
126
|
+
display: "inline-block",
|
|
127
|
+
minWidth: "100%",
|
|
128
|
+
position: "relative"
|
|
129
|
+
};
|
|
130
|
+
const DIFF_DELETED_STYLE = {
|
|
131
|
+
color: "var(--ant-color-text-quaternary, rgba(0, 0, 0, 0.45))",
|
|
132
|
+
textDecoration: "line-through"
|
|
133
|
+
};
|
|
134
|
+
function renderDiffNode(node, key, children) {
|
|
135
|
+
const diffType = typeof node.diffType === "string" ? node.diffType : "unchanged";
|
|
136
|
+
const renderedChildren = children ?? [];
|
|
137
|
+
const sharedContentStyle = {
|
|
138
|
+
marginBlockStart: "calc(var(--lobe-markdown-margin-multiple, 1) * 0.5em)",
|
|
139
|
+
paddingInlineEnd: 4
|
|
140
|
+
};
|
|
141
|
+
const borderColor = diffType === "add" || diffType === "listItemAdd" ? "var(--ant-color-success, #52c41a)" : diffType === "remove" || diffType === "listItemRemove" ? "var(--ant-color-error, #ff4d4f)" : "var(--ant-color-warning, #faad14)";
|
|
142
|
+
const contentStyle = diffType === "unchanged" ? sharedContentStyle : {
|
|
143
|
+
...sharedContentStyle,
|
|
144
|
+
borderInlineEnd: `3px solid ${borderColor}`
|
|
145
|
+
};
|
|
146
|
+
const rootStyle = diffType === "listItemAdd" || diffType === "listItemModify" || diffType === "listItemRemove" ? DIFF_LIST_ITEM_ROOT_STYLE : DIFF_ROOT_STYLE;
|
|
147
|
+
const wrapChild = (child, childKey, style) => {
|
|
148
|
+
if (child === void 0 || child === null) return null;
|
|
149
|
+
return /* @__PURE__ */ jsx("div", {
|
|
150
|
+
style,
|
|
151
|
+
children: child
|
|
152
|
+
}, childKey);
|
|
153
|
+
};
|
|
154
|
+
let content;
|
|
155
|
+
switch (diffType) {
|
|
156
|
+
case "add":
|
|
157
|
+
case "listItemAdd":
|
|
158
|
+
content = wrapChild(renderedChildren[0], `${key}-add`);
|
|
159
|
+
break;
|
|
160
|
+
case "remove":
|
|
161
|
+
case "listItemRemove":
|
|
162
|
+
content = wrapChild(renderedChildren[0], `${key}-remove`, DIFF_DELETED_STYLE);
|
|
163
|
+
break;
|
|
164
|
+
case "modify":
|
|
165
|
+
case "listItemModify":
|
|
166
|
+
content = [wrapChild(renderedChildren[0], `${key}-old`, DIFF_DELETED_STYLE), wrapChild(renderedChildren[1], `${key}-new`)];
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
content = renderedChildren;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
return /* @__PURE__ */ jsx("div", {
|
|
173
|
+
className: "ne-diff",
|
|
174
|
+
"data-diff-type": diffType,
|
|
175
|
+
style: rootStyle,
|
|
176
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
177
|
+
className: "content",
|
|
178
|
+
style: contentStyle,
|
|
179
|
+
children: content
|
|
180
|
+
})
|
|
181
|
+
}, key);
|
|
182
|
+
}
|
|
124
183
|
function renderBuiltinNode(node, key, children, headingSlugs, textContent) {
|
|
125
184
|
switch (node.type) {
|
|
126
185
|
case "root": return children;
|
|
@@ -216,6 +275,7 @@ function renderBuiltinNode(node, key, children, headingSlugs, textContent) {
|
|
|
216
275
|
children: node.text
|
|
217
276
|
}, key);
|
|
218
277
|
return /* @__PURE__ */ jsx("span", { children: node.text }, key);
|
|
278
|
+
case "diff": return renderDiffNode(node, key, children);
|
|
219
279
|
case "cursor": return null;
|
|
220
280
|
default:
|
|
221
281
|
console.warn(`[LexicalRenderer] Unknown node type: "${node.type}"`);
|
package/package.json
CHANGED