@lobehub/editor 4.7.0 → 4.8.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/renderer.d.ts +6 -1
- package/es/renderer.js +63 -18
- package/package.json +1 -1
package/es/renderer.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Klass, LexicalNode, SerializedEditorState, SerializedLexicalNode } from
|
|
|
2
2
|
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
3
|
import { CSSProperties, JSX, ReactElement, ReactNode } from "react";
|
|
4
4
|
|
|
5
|
+
//#region src/renderer/diff/style.d.ts
|
|
6
|
+
type DiffAppearance = 'borderless' | 'default';
|
|
7
|
+
//#endregion
|
|
5
8
|
//#region src/renderer/diff/types.d.ts
|
|
6
9
|
type LexicalDiffRowKind = 'delete' | 'equal' | 'insert' | 'modify';
|
|
7
10
|
interface LexicalDiffCell {
|
|
@@ -60,6 +63,7 @@ interface LexicalRendererProps {
|
|
|
60
63
|
//#endregion
|
|
61
64
|
//#region src/renderer/LexicalDiff.d.ts
|
|
62
65
|
interface LexicalDiffProps {
|
|
66
|
+
appearance?: DiffAppearance;
|
|
63
67
|
blockRenderers?: Record<string, LexicalDiffBlockRenderer>;
|
|
64
68
|
className?: string;
|
|
65
69
|
extraNodes?: LexicalRendererProps['extraNodes'];
|
|
@@ -79,6 +83,7 @@ declare function LexicalDiff({
|
|
|
79
83
|
oldValue,
|
|
80
84
|
newValue,
|
|
81
85
|
variant,
|
|
86
|
+
appearance,
|
|
82
87
|
extraNodes,
|
|
83
88
|
overrides,
|
|
84
89
|
renderContext,
|
|
@@ -107,4 +112,4 @@ declare const rendererNodes: Array<Klass<LexicalNode>>;
|
|
|
107
112
|
//#region src/renderer/renderers/index.d.ts
|
|
108
113
|
declare function createDefaultRenderers(): RendererRegistry;
|
|
109
114
|
//#endregion
|
|
110
|
-
export { type HeadlessRenderContext, type HeadlessRenderableNode, LexicalDiff, type LexicalDiffBlockRenderContext, type LexicalDiffBlockRenderer, type LexicalDiffCell, type LexicalDiffProps, type LexicalDiffRow, type LexicalDiffRowKind, LexicalRenderer, type LexicalRendererContext, type LexicalRendererProps, type NodeRenderer, type RendererRegistry, createDefaultRenderers, loadLanguage, rendererNodes };
|
|
115
|
+
export { type DiffAppearance, type HeadlessRenderContext, type HeadlessRenderableNode, LexicalDiff, type LexicalDiffBlockRenderContext, type LexicalDiffBlockRenderer, type LexicalDiffCell, type LexicalDiffProps, type LexicalDiffRow, type LexicalDiffRowKind, LexicalRenderer, type LexicalRendererContext, type LexicalRendererProps, type NodeRenderer, type RendererRegistry, createDefaultRenderers, loadLanguage, rendererNodes };
|
package/es/renderer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as CodeNode, L as CursorNode, M as CodeMirrorNode, O as styles
|
|
2
|
-
import { S as PlaceholderNode, a as styles$
|
|
1
|
+
import { E as CodeNode, L as CursorNode, M as CodeMirrorNode, O as styles, _ as AutoLinkNode, b as LinkNode, c as MathBlockNode, f as LinkHighlightNode, i as MentionNode, l as MathInlineNode, t as styles$1 } from "./style-Ub1LiKko.js";
|
|
2
|
+
import { S as PlaceholderNode, a as styles$5, b as DiffNode, c as ImageNode, d as BlockImageNode, h as styles$6, m as HorizontalRuleNode, n as styles$4, r as styles$2, t as styles$3, v as FileNode, x as PlaceholderBlockNode } from "./style-CFkese2R.js";
|
|
3
3
|
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
|
|
4
4
|
import { $getRoot, $isElementNode, $isTextNode } from "lexical";
|
|
5
5
|
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
|
|
@@ -44,28 +44,28 @@ const tableHeaderFix = createStaticStyles(({ css, cssVar }) => css`
|
|
|
44
44
|
}
|
|
45
45
|
`);
|
|
46
46
|
function getRendererClassName(className) {
|
|
47
|
-
return cx(styles
|
|
47
|
+
return cx(styles.root, styles.variant, className);
|
|
48
48
|
}
|
|
49
49
|
function getListClassName(listType) {
|
|
50
|
-
return cx(listType === "number" ? "editor_listOrdered" : "editor_listUnordered", styles$
|
|
50
|
+
return cx(listType === "number" ? "editor_listOrdered" : "editor_listUnordered", styles$2);
|
|
51
51
|
}
|
|
52
52
|
function getTableWrapperClassName() {
|
|
53
|
-
return cx("editor_table_scrollable_wrapper", styles$
|
|
53
|
+
return cx("editor_table_scrollable_wrapper", styles$3, tableHeaderFix);
|
|
54
54
|
}
|
|
55
55
|
function getMathInlineClassName() {
|
|
56
|
-
return styles$
|
|
56
|
+
return styles$4.mathInline;
|
|
57
57
|
}
|
|
58
58
|
function getMathBlockClassName() {
|
|
59
|
-
return styles$
|
|
59
|
+
return styles$4.mathBlock;
|
|
60
60
|
}
|
|
61
61
|
function getImageClassName() {
|
|
62
|
-
return styles$
|
|
62
|
+
return styles$5.image;
|
|
63
63
|
}
|
|
64
64
|
function getBlockImageClassName() {
|
|
65
|
-
return styles$
|
|
65
|
+
return styles$5.blockImage;
|
|
66
66
|
}
|
|
67
67
|
function getMentionClassName() {
|
|
68
|
-
return cx("editor_mention", styles$
|
|
68
|
+
return cx("editor_mention", styles$1.mention);
|
|
69
69
|
}
|
|
70
70
|
function getCSSVariables(variant) {
|
|
71
71
|
const isChat = variant === "chat";
|
|
@@ -343,7 +343,7 @@ function renderCodeBlock(node, key) {
|
|
|
343
343
|
//#region src/renderer/renderers/file.tsx
|
|
344
344
|
function renderFile(node, key) {
|
|
345
345
|
const { name, fileUrl, status, message } = node;
|
|
346
|
-
const cls = styles$
|
|
346
|
+
const cls = styles$6.file;
|
|
347
347
|
if (status === "error") return /* @__PURE__ */ jsxs("span", {
|
|
348
348
|
className: cls,
|
|
349
349
|
"data-file-status": "error",
|
|
@@ -901,7 +901,7 @@ function computeLexicalDiffRows(oldState, newState) {
|
|
|
901
901
|
}
|
|
902
902
|
//#endregion
|
|
903
903
|
//#region src/renderer/diff/style.ts
|
|
904
|
-
const
|
|
904
|
+
const base = createStaticStyles(({ css, cssVar }) => ({
|
|
905
905
|
body: css`
|
|
906
906
|
display: flex;
|
|
907
907
|
flex-direction: column;
|
|
@@ -917,13 +917,22 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
917
917
|
min-width: 0;
|
|
918
918
|
}
|
|
919
919
|
`,
|
|
920
|
-
cellOld: css``,
|
|
921
920
|
deleteCell: css`
|
|
922
921
|
background: color-mix(in srgb, ${cssVar.colorError} 10%, transparent);
|
|
923
922
|
`,
|
|
924
923
|
emptyCell: css`
|
|
925
924
|
background: ${cssVar.colorFillQuaternary};
|
|
926
925
|
`,
|
|
926
|
+
insertCell: css`
|
|
927
|
+
background: color-mix(in srgb, ${cssVar.colorSuccess} 10%, transparent);
|
|
928
|
+
`,
|
|
929
|
+
row: css`
|
|
930
|
+
display: grid;
|
|
931
|
+
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
|
932
|
+
`
|
|
933
|
+
}));
|
|
934
|
+
const defaultOverrides = createStaticStyles(({ css, cssVar }) => ({
|
|
935
|
+
cellOld: css``,
|
|
927
936
|
header: css`
|
|
928
937
|
display: grid;
|
|
929
938
|
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
|
@@ -942,9 +951,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
942
951
|
`,
|
|
943
952
|
headerOld: css`
|
|
944
953
|
border-inline-end: 1px solid ${cssVar.colorBorderSecondary};
|
|
945
|
-
`,
|
|
946
|
-
insertCell: css`
|
|
947
|
-
background: color-mix(in srgb, ${cssVar.colorSuccess} 10%, transparent);
|
|
948
954
|
`,
|
|
949
955
|
root: css`
|
|
950
956
|
overflow: hidden;
|
|
@@ -955,12 +961,50 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
955
961
|
font-size: 14px;
|
|
956
962
|
|
|
957
963
|
background: ${cssVar.colorBgContainer};
|
|
964
|
+
`
|
|
965
|
+
}));
|
|
966
|
+
const borderlessOverrides = createStaticStyles(({ css, cssVar }) => ({
|
|
967
|
+
body: css`
|
|
968
|
+
& > *:nth-child(odd) {
|
|
969
|
+
background: ${cssVar.colorFillQuaternary};
|
|
970
|
+
}
|
|
958
971
|
`,
|
|
959
|
-
|
|
972
|
+
cellOld: css``,
|
|
973
|
+
header: css`
|
|
960
974
|
display: grid;
|
|
961
975
|
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
|
976
|
+
column-gap: 12px;
|
|
977
|
+
`,
|
|
978
|
+
headerCell: css`
|
|
979
|
+
padding-block: 8px;
|
|
980
|
+
padding-inline: 16px;
|
|
981
|
+
|
|
982
|
+
font-size: 12px;
|
|
983
|
+
font-weight: 600;
|
|
984
|
+
color: ${cssVar.colorTextSecondary};
|
|
985
|
+
text-transform: uppercase;
|
|
986
|
+
letter-spacing: 0.05em;
|
|
987
|
+
`,
|
|
988
|
+
headerOld: css``,
|
|
989
|
+
root: css`
|
|
990
|
+
overflow: hidden;
|
|
991
|
+
font-size: 14px;
|
|
992
|
+
background: ${cssVar.colorBgContainer};
|
|
993
|
+
`,
|
|
994
|
+
row: css`
|
|
995
|
+
column-gap: 12px;
|
|
962
996
|
`
|
|
963
997
|
}));
|
|
998
|
+
function merge(baseSet, overrides) {
|
|
999
|
+
const result = {};
|
|
1000
|
+
const allKeys = new Set([...Object.keys(baseSet), ...Object.keys(overrides)]);
|
|
1001
|
+
for (const key of allKeys) result[key] = cx(baseSet[key], overrides[key]);
|
|
1002
|
+
return result;
|
|
1003
|
+
}
|
|
1004
|
+
const diffStyles = {
|
|
1005
|
+
borderless: merge(base, borderlessOverrides),
|
|
1006
|
+
default: merge(base, defaultOverrides)
|
|
1007
|
+
};
|
|
964
1008
|
//#endregion
|
|
965
1009
|
//#region src/renderer/LexicalDiff.tsx
|
|
966
1010
|
function wrapBlock(block) {
|
|
@@ -979,7 +1023,8 @@ function RowCell({ className, content }) {
|
|
|
979
1023
|
children: content
|
|
980
1024
|
});
|
|
981
1025
|
}
|
|
982
|
-
function LexicalDiff({ oldValue, newValue, variant = "default", extraNodes, overrides, renderContext, labels, blockRenderers, renderBlockDiff, className, style }) {
|
|
1026
|
+
function LexicalDiff({ oldValue, newValue, variant = "default", appearance = "default", extraNodes, overrides, renderContext, labels, blockRenderers, renderBlockDiff, className, style }) {
|
|
1027
|
+
const styles = diffStyles[appearance];
|
|
983
1028
|
const rows = useMemo(() => computeLexicalDiffRows(oldValue, newValue), [oldValue, newValue]);
|
|
984
1029
|
const renderDefaultCell = (block) => {
|
|
985
1030
|
if (!block) return null;
|
package/package.json
CHANGED