@opensumi/ide-notebook 3.7.1-next-1736826301.0 → 3.7.1-next-1737364617.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/lib/browser/libro/diff-view/components/hooks.d.ts +10 -0
- package/lib/browser/libro/diff-view/components/hooks.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/components/hooks.js +96 -0
- package/lib/browser/libro/diff-view/components/hooks.js.map +1 -0
- package/lib/browser/libro/diff-view/components/index.less +315 -0
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.d.ts +3 -0
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.js +11 -0
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.js.map +1 -0
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.d.ts +5 -0
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.js +59 -0
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.js.map +1 -0
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.d.ts +5 -0
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.js +58 -0
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.js.map +1 -0
- package/lib/browser/libro/diff-view/index.d.ts +5 -0
- package/lib/browser/libro/diff-view/index.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/index.js +5 -0
- package/lib/browser/libro/diff-view/index.js.map +1 -0
- package/lib/browser/libro/diff-view/index.less +47 -0
- package/lib/browser/libro/diff-view/libro-diff-color-registry.d.ts +6 -0
- package/lib/browser/libro/diff-view/libro-diff-color-registry.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-color-registry.js +110 -0
- package/lib/browser/libro/diff-view/libro-diff-color-registry.js.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-component.d.ts +6 -0
- package/lib/browser/libro/diff-view/libro-diff-component.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-component.js +21 -0
- package/lib/browser/libro/diff-view/libro-diff-component.js.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-protocol.d.ts +58 -0
- package/lib/browser/libro/diff-view/libro-diff-protocol.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-protocol.js +38 -0
- package/lib/browser/libro/diff-view/libro-diff-protocol.js.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-view.d.ts +48 -0
- package/lib/browser/libro/diff-view/libro-diff-view.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-diff-view.js +297 -0
- package/lib/browser/libro/diff-view/libro-diff-view.js.map +1 -0
- package/lib/browser/libro/diff-view/libro-version-manager.d.ts +16 -0
- package/lib/browser/libro/diff-view/libro-version-manager.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-version-manager.js +126 -0
- package/lib/browser/libro/diff-view/libro-version-manager.js.map +1 -0
- package/lib/browser/libro/diff-view/libro-version-view.d.ts +13 -0
- package/lib/browser/libro/diff-view/libro-version-view.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/libro-version-view.js +40 -0
- package/lib/browser/libro/diff-view/libro-version-view.js.map +1 -0
- package/lib/browser/libro/diff-view/module.d.ts +3 -0
- package/lib/browser/libro/diff-view/module.d.ts.map +1 -0
- package/lib/browser/libro/diff-view/module.js +10 -0
- package/lib/browser/libro/diff-view/module.js.map +1 -0
- package/lib/browser/libro/libro-opensumi-content-contribution.d.ts.map +1 -1
- package/lib/browser/libro-preview.view.d.ts +3 -0
- package/lib/browser/libro-preview.view.d.ts.map +1 -0
- package/lib/browser/libro-preview.view.js +27 -0
- package/lib/browser/libro-preview.view.js.map +1 -0
- package/lib/browser/libro.contribution.d.ts.map +1 -1
- package/lib/browser/libro.contribution.js +38 -4
- package/lib/browser/libro.contribution.js.map +1 -1
- package/lib/browser/libro.protocol.d.ts +3 -1
- package/lib/browser/libro.protocol.d.ts.map +1 -1
- package/lib/browser/libro.protocol.js +3 -1
- package/lib/browser/libro.protocol.js.map +1 -1
- package/package.json +17 -14
- package/src/browser/libro/diff-view/components/hooks.tsx +123 -0
- package/src/browser/libro/diff-view/components/index.less +315 -0
- package/src/browser/libro/diff-view/components/libro-diff-all-cells-same-components.tsx +43 -0
- package/src/browser/libro/diff-view/components/libro-diff-changed-cell-components.tsx +88 -0
- package/src/browser/libro/diff-view/components/libro-diff-side-cell-components.tsx +84 -0
- package/src/browser/libro/diff-view/index.less +47 -0
- package/src/browser/libro/diff-view/index.ts +4 -0
- package/src/browser/libro/diff-view/libro-diff-color-registry.ts +132 -0
- package/src/browser/libro/diff-view/libro-diff-component.tsx +25 -0
- package/src/browser/libro/diff-view/libro-diff-protocol.ts +94 -0
- package/src/browser/libro/diff-view/libro-diff-view.tsx +351 -0
- package/src/browser/libro/diff-view/libro-version-manager.ts +135 -0
- package/src/browser/libro/diff-view/libro-version-view.tsx +41 -0
- package/src/browser/libro/diff-view/module.ts +11 -0
- package/src/browser/libro/libro-opensumi-content-contribution.ts +1 -1
- package/src/browser/libro-preview.view.tsx +33 -0
- package/src/browser/libro.contribution.tsx +43 -4
- package/src/browser/libro.protocol.ts +3 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useInject } from '@difizen/mana-app';
|
|
2
|
+
import React, { memo, useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { IDiffEditor } from '@opensumi/ide-monaco';
|
|
5
|
+
|
|
6
|
+
import { getLibroCellType, getSource } from '../libro-diff-protocol';
|
|
7
|
+
import { LibroVersionManager } from '../libro-version-manager';
|
|
8
|
+
|
|
9
|
+
import { useEditorLayout } from './hooks';
|
|
10
|
+
|
|
11
|
+
import type { DiffEditorProps } from '../libro-diff-protocol';
|
|
12
|
+
|
|
13
|
+
import './index.less';
|
|
14
|
+
|
|
15
|
+
const getEditorLanguage = (libroCellType: string) => {
|
|
16
|
+
if (libroCellType === 'sql') {
|
|
17
|
+
return 'sql-odps';
|
|
18
|
+
} else if (libroCellType === 'markdown' || libroCellType === 'raw') {
|
|
19
|
+
return 'markdown';
|
|
20
|
+
} else {
|
|
21
|
+
return 'python';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const LibroDiffChangedCellComponent: React.FC<DiffEditorProps> = memo(({ diffCellResultItem }) => {
|
|
26
|
+
const editorDiffRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const editorContainerRef = useRef<HTMLDivElement>(null);
|
|
28
|
+
const [diffEditor, setDiffEditor] = useState<IDiffEditor | undefined>();
|
|
29
|
+
const versionManager = useInject(LibroVersionManager);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!editorDiffRef.current) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const language = diffCellResultItem.origin.metadata.libroCellType
|
|
35
|
+
? getEditorLanguage(diffCellResultItem.origin.metadata.libroCellType.toString())
|
|
36
|
+
: getEditorLanguage(diffCellResultItem.origin.cell_type);
|
|
37
|
+
const diffEditor = versionManager.createDiffEditor(
|
|
38
|
+
getSource(diffCellResultItem.origin),
|
|
39
|
+
getSource(diffCellResultItem.target),
|
|
40
|
+
language,
|
|
41
|
+
editorDiffRef.current,
|
|
42
|
+
);
|
|
43
|
+
setDiffEditor(diffEditor);
|
|
44
|
+
return () => {
|
|
45
|
+
diffEditor?.dispose();
|
|
46
|
+
};
|
|
47
|
+
}, [editorDiffRef]);
|
|
48
|
+
|
|
49
|
+
useEditorLayout(diffEditor, editorDiffRef, editorContainerRef);
|
|
50
|
+
|
|
51
|
+
const type = diffCellResultItem.diffType === 'changed' ? 'changed' : 'unchanged';
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className='libro-diff-cell-container' ref={editorContainerRef}>
|
|
55
|
+
<div className={`libro-diff-cell-${type}-container`}>
|
|
56
|
+
<div className={`libro-diff-cell-${type}-origin-header ${diffCellResultItem.diffType}`}>
|
|
57
|
+
<span className='libro-diff-cell-header-text'>{getLibroCellType(diffCellResultItem.origin)}</span>
|
|
58
|
+
<span
|
|
59
|
+
className='libro-diff-cell-header-origin-execute-count'
|
|
60
|
+
style={{
|
|
61
|
+
display: diffCellResultItem.origin.cell_type !== 'markdown' ? 'block' : 'none',
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
{diffCellResultItem.origin.execution_count
|
|
65
|
+
? '[' + diffCellResultItem.origin.execution_count?.toString() + ']'
|
|
66
|
+
: '[ ]'}
|
|
67
|
+
</span>
|
|
68
|
+
</div>
|
|
69
|
+
<div className={`libro-diff-cell-${type}-target-header ${diffCellResultItem.diffType}`}>
|
|
70
|
+
<span className='libro-diff-cell-header-text'>{getLibroCellType(diffCellResultItem.target)}</span>
|
|
71
|
+
<span
|
|
72
|
+
className='libro-diff-cell-header-target-execute-count'
|
|
73
|
+
style={{
|
|
74
|
+
display: diffCellResultItem.target.cell_type !== 'markdown' ? 'block' : 'none',
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{diffCellResultItem.target.execution_count
|
|
78
|
+
? '[' + diffCellResultItem.target.execution_count?.toString() + ']'
|
|
79
|
+
: '[ ]'}
|
|
80
|
+
</span>
|
|
81
|
+
</div>
|
|
82
|
+
<div className={`libro-diff-cell-${type}-content`} ref={editorDiffRef} />
|
|
83
|
+
<div className={`libro-diff-cell-${type}-origin-border`} />
|
|
84
|
+
<div className={`libro-diff-cell-${type}-target-border`} />
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Container } from '@difizen/mana-app';
|
|
2
|
+
import React, { memo, useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useInjectable } from '@opensumi/ide-core-browser';
|
|
5
|
+
import { ICodeEditor } from '@opensumi/ide-monaco';
|
|
6
|
+
|
|
7
|
+
import { ManaContainer } from '../../../mana';
|
|
8
|
+
import { getLibroCellType } from '../libro-diff-protocol';
|
|
9
|
+
import { LibroVersionManager } from '../libro-version-manager';
|
|
10
|
+
|
|
11
|
+
import { useEditorLayout } from './hooks';
|
|
12
|
+
|
|
13
|
+
import type { DiffEditorProps } from '../libro-diff-protocol';
|
|
14
|
+
|
|
15
|
+
import './index.less';
|
|
16
|
+
|
|
17
|
+
const getEditorLanguage = (libroCellType: string) => {
|
|
18
|
+
if (libroCellType === 'sql') {
|
|
19
|
+
return 'sql-odps';
|
|
20
|
+
} else if (libroCellType === 'markdown' || libroCellType === 'raw') {
|
|
21
|
+
return 'markdown';
|
|
22
|
+
} else {
|
|
23
|
+
return 'python';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const LibroDiffSideCellComponent: React.FC<DiffEditorProps> = memo(({ diffCellResultItem }) => {
|
|
28
|
+
const manaContainer = useInjectable<Container>(ManaContainer);
|
|
29
|
+
const libroVersionManager = manaContainer.get(LibroVersionManager);
|
|
30
|
+
const editorTargetRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
const editorContainerRef = useRef<HTMLDivElement>(null);
|
|
32
|
+
const language = diffCellResultItem.origin.metadata.libroCellType
|
|
33
|
+
? getEditorLanguage(diffCellResultItem.origin.metadata.libroCellType.toString())
|
|
34
|
+
: getEditorLanguage(diffCellResultItem.origin.cell_type);
|
|
35
|
+
|
|
36
|
+
const [editor, setEditor] = useState<ICodeEditor | undefined>();
|
|
37
|
+
|
|
38
|
+
const createEditor = () => {
|
|
39
|
+
// 这里其实已经拿到content了,但是 opensumi editor 需要uri,理论上有优化空间
|
|
40
|
+
const content =
|
|
41
|
+
diffCellResultItem.diffType === 'removed' ? diffCellResultItem.origin.source : diffCellResultItem.target.source;
|
|
42
|
+
const previewedEditor = libroVersionManager.createPreviewEditor(
|
|
43
|
+
content.toString(),
|
|
44
|
+
language,
|
|
45
|
+
editorTargetRef.current!,
|
|
46
|
+
diffCellResultItem.diffType,
|
|
47
|
+
);
|
|
48
|
+
setEditor(previewedEditor);
|
|
49
|
+
return previewedEditor;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
useEditorLayout(editor, editorTargetRef, editorContainerRef);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!editorTargetRef.current) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const previewedEditor = createEditor();
|
|
59
|
+
return () => {
|
|
60
|
+
previewedEditor?.dispose();
|
|
61
|
+
};
|
|
62
|
+
}, [editorTargetRef.current]);
|
|
63
|
+
const type = diffCellResultItem.diffType === 'removed' ? 'origin' : 'target';
|
|
64
|
+
return (
|
|
65
|
+
<div className='libro-diff-cell-container' ref={editorContainerRef}>
|
|
66
|
+
<div className={`libro-diff-cell-${type}-container`}>
|
|
67
|
+
<div className={`libro-diff-cell-${type}-header`}>
|
|
68
|
+
<span className='libro-diff-cell-header-text'>{getLibroCellType(diffCellResultItem.origin)}</span>
|
|
69
|
+
<span
|
|
70
|
+
className={`libro-diff-cell-header-${type}-execute-count`}
|
|
71
|
+
style={{
|
|
72
|
+
display: diffCellResultItem.target.cell_type !== 'markdown' ? 'block' : 'none',
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
{diffCellResultItem.target.execution_count
|
|
76
|
+
? '[' + diffCellResultItem.target.execution_count?.toString() + ']'
|
|
77
|
+
: '[ ]'}
|
|
78
|
+
</span>
|
|
79
|
+
</div>
|
|
80
|
+
<div className={`libro-diff-cell-${type}-content`} ref={editorTargetRef} />
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.libro-diff-content-container, .libro-diff-content-loading-container, .libro-diff-content-same-container {
|
|
2
|
+
background-color: var(--mana-libro-diff-container-color);
|
|
3
|
+
}
|
|
4
|
+
.libro-diff-content-container {
|
|
5
|
+
height: 100%;
|
|
6
|
+
padding: 24px 36px;
|
|
7
|
+
}
|
|
8
|
+
.libro-diff-content-loading-container {
|
|
9
|
+
height: 100%;
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
align-items: center;
|
|
13
|
+
}
|
|
14
|
+
.libro-diff-fold-container {
|
|
15
|
+
padding: 8px 0;
|
|
16
|
+
}
|
|
17
|
+
.libro-diff-fold {
|
|
18
|
+
display: flex;
|
|
19
|
+
padding: 6px 0;
|
|
20
|
+
border-radius: 6px;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
height: 32px;
|
|
24
|
+
background: var(--mana-libro-diff-fold-background-color);
|
|
25
|
+
color: var(--mana-libro-diff-fold-text-color);
|
|
26
|
+
&:hover {
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
background: var(--mana-libro-diff-fold-hover-background-color);
|
|
29
|
+
}
|
|
30
|
+
.libro-diff-fold-text {
|
|
31
|
+
padding-left: 6px;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
.libro-diff-content-same-container {
|
|
35
|
+
display: flex;
|
|
36
|
+
height: 100%;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
align-items: center;
|
|
40
|
+
}
|
|
41
|
+
.libro-diff-content-same-text {
|
|
42
|
+
margin-top: 15px;
|
|
43
|
+
font-size: 16px;
|
|
44
|
+
color: var(--mana-libro-diff-content-same-text-color);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Color, ColorContribution, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { ColorRegistry } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
@singleton({ contrib: ColorContribution })
|
|
6
|
+
export class LibroDiffColorRegistry implements ColorContribution {
|
|
7
|
+
registerColors(colors: ColorRegistry): void {
|
|
8
|
+
colors.register(
|
|
9
|
+
// #region antd variable
|
|
10
|
+
{
|
|
11
|
+
id: 'libro.diff.added.cell.header.color',
|
|
12
|
+
defaults: { dark: '#404C34', light: '#E4EADC' },
|
|
13
|
+
description: '',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'libro.diff.removed.cell.header.color',
|
|
17
|
+
defaults: { dark: '#5A3433', light: '#F2E7EA' },
|
|
18
|
+
description: '',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'libro.diff.cell.header.text.color',
|
|
22
|
+
defaults: { dark: '#e3e4e6', light: Color.rgba(0, 10, 26, 0.47) },
|
|
23
|
+
description: '',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'libro.diff.cell.header.execution.color',
|
|
27
|
+
defaults: { dark: '#6A83AA', light: '#6A83AA' },
|
|
28
|
+
description: '',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'libro.diff.unchanged.cell.header.color',
|
|
32
|
+
defaults: { dark: Color.rgba(255, 255, 255, 0.06), light: '#EAECF2' },
|
|
33
|
+
description: '',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'libro.diff.container.color',
|
|
37
|
+
defaults: { dark: '#1f2022', light: '#ffffff' },
|
|
38
|
+
description: '',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'libro.diff.input.background.color',
|
|
42
|
+
defaults: { dark: '#19191B', light: '#F4F6FB' },
|
|
43
|
+
description: '',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'libro.diff.editor.background.color',
|
|
47
|
+
defaults: { dark: '#1F2022', light: '#ffffff' },
|
|
48
|
+
description: '',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'libro.diff.cell.border.color',
|
|
52
|
+
defaults: { dark: '#3B3C42', light: '#D7DBE7' },
|
|
53
|
+
description: '',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'libro.diff.editor.removed.color',
|
|
57
|
+
defaults: { dark: '#4F2726', light: '#FAF0F0' },
|
|
58
|
+
description: '',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'libro.diff.editor.added.color',
|
|
62
|
+
defaults: { dark: '#334126', light: '#ECF4E3' },
|
|
63
|
+
description: '',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'libro.diff.editor.line.insert.color',
|
|
67
|
+
defaults: { dark: Color.rgba(83, 104, 48, 0.45), light: Color.rgba(189, 214, 151, 0.25) },
|
|
68
|
+
description: '',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'libro.diff.editor.line.delete.color',
|
|
72
|
+
defaults: { dark: Color.rgba(126, 50, 45, 0.45), light: Color.rgba(241, 212, 216, 0.35) },
|
|
73
|
+
description: '',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'libro.diff.editor.char.insert.color',
|
|
77
|
+
defaults: { dark: Color.rgba(16, 22, 3, 0.7), light: Color.rgba(67, 151, 36, 0.25) },
|
|
78
|
+
description: '',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'libro.diff.editor.char.delete.color',
|
|
82
|
+
defaults: { dark: Color.rgba(53, 15, 14, 0.7), light: Color.rgba(255, 0, 0, 0.2) },
|
|
83
|
+
description: '',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'libro.diff.fold.background.color',
|
|
87
|
+
defaults: { dark: Color.rgba(255, 255, 255, 0.08), light: Color.rgba(0, 10, 26, 0.02) },
|
|
88
|
+
description: '',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: 'libro.diff.fold.hover.background.color',
|
|
92
|
+
defaults: { dark: Color.rgba(255, 255, 255, 0.1), light: Color.rgba(0, 10, 26, 0.04) },
|
|
93
|
+
description: '',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'libro.diff.fold.text.color',
|
|
97
|
+
defaults: { dark: '#BDC0C4', light: Color.rgba(0, 10, 26, 0.47) },
|
|
98
|
+
description: '',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'libro.diff.content.same.text.color',
|
|
102
|
+
defaults: { dark: '#E3E4E6', light: Color.rgba(0, 10, 26, 0.68) },
|
|
103
|
+
description: '',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'libro.diff.select.background.color',
|
|
107
|
+
defaults: { dark: '#BCCEFF', light: '#e5ebf1' },
|
|
108
|
+
description: '',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'libro.diff.select.highlight.background.color',
|
|
112
|
+
defaults: { dark: '#C8D1E7', light: '#DDE6FF' },
|
|
113
|
+
description: '',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'libro.diff.editor.gutter.number.color',
|
|
117
|
+
defaults: { dark: '#a8aebf', light: '#A4AECB' },
|
|
118
|
+
description: '',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'libro.diff.editor.intent.color',
|
|
122
|
+
defaults: { dark: '#565C6D', light: '#A4AECB' },
|
|
123
|
+
description: '',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: 'libro.editor.cursor.color',
|
|
127
|
+
defaults: { dark: '#ffffff', light: '#000000' },
|
|
128
|
+
description: '',
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ViewManager, ViewRender, useInject } from '@difizen/mana-app';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { libroDiffViewFactoryId } from './libro-diff-protocol';
|
|
5
|
+
|
|
6
|
+
import type { DiffOption } from './libro-diff-protocol';
|
|
7
|
+
import type { LibroDiffView } from './libro-diff-view';
|
|
8
|
+
|
|
9
|
+
export function LibroDiffComponent(props: { options: DiffOption }) {
|
|
10
|
+
const [libroDiffView, setLibroDiffView] = useState<LibroDiffView | undefined>(undefined);
|
|
11
|
+
const viewManager = useInject(ViewManager);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
viewManager
|
|
14
|
+
.getOrCreateView<LibroDiffView>(libroDiffViewFactoryId, {
|
|
15
|
+
...(props.options || {}),
|
|
16
|
+
})
|
|
17
|
+
.then((view) => {
|
|
18
|
+
setLibroDiffView(view);
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
if (!libroDiffView || !libroDiffView.view) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return <ViewRender view={libroDiffView} />;
|
|
25
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
2
|
+
|
|
3
|
+
import type { ICell, INotebookContent } from '@difizen/libro-common';
|
|
4
|
+
import type { URI, View } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
export const libroDiffViewFactoryId = 'libro-diff-view-factory';
|
|
7
|
+
|
|
8
|
+
export const getLibroCellType = (cell: ICell) => {
|
|
9
|
+
const cellType = (cell.metadata?.libroCellType as string) ?? cell.cell_type;
|
|
10
|
+
if (cellType === 'sql') {
|
|
11
|
+
return 'SQL';
|
|
12
|
+
}
|
|
13
|
+
return cellType.charAt(0).toUpperCase() + cellType.slice(1);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getSource = (cell: ICell) => {
|
|
17
|
+
let codeValue = concatMultilineString(cell.source);
|
|
18
|
+
if (getLibroCellType(cell) === 'SQL' && codeValue.includes(',tmp_table:')) {
|
|
19
|
+
codeValue = decodeURIComponent(escape(atob(codeValue.split(',tmp_table:')[0].substring(6))));
|
|
20
|
+
}
|
|
21
|
+
if (getLibroCellType(cell) === 'SQL' && codeValue.includes(',variable:')) {
|
|
22
|
+
codeValue = decodeURIComponent(escape(atob(codeValue.split(',variable:')[0].substring(6))));
|
|
23
|
+
}
|
|
24
|
+
return codeValue;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type DiffCellItemResult = DiffCellItem | DiffCellUnchangedItems;
|
|
28
|
+
export interface DiffView extends View {
|
|
29
|
+
diffCellsResult: DiffCellItemResult[];
|
|
30
|
+
originContent: IDiffNotebookContent;
|
|
31
|
+
targetContent: IDiffNotebookContent;
|
|
32
|
+
diffUnchangedCellsRenderStatus: 'all' | 'part' | 'none';
|
|
33
|
+
options?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
export interface IDiffNotebookContent {
|
|
36
|
+
content: INotebookContent;
|
|
37
|
+
diffTag: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type DiffType = 'added' | 'removed' | 'changed' | 'unchanged';
|
|
41
|
+
export interface DiffCellItem {
|
|
42
|
+
diffType: DiffType;
|
|
43
|
+
origin: ICell;
|
|
44
|
+
target: ICell;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const DiffCellItem = {
|
|
48
|
+
is: (arg: Record<any, any>): arg is DiffCellItem =>
|
|
49
|
+
!!arg &&
|
|
50
|
+
'diffType' in arg &&
|
|
51
|
+
typeof (arg as any).diffType === 'string' &&
|
|
52
|
+
'origin' in arg &&
|
|
53
|
+
typeof (arg as any).origin === 'object' &&
|
|
54
|
+
'target' in arg &&
|
|
55
|
+
typeof (arg as any).target === 'object',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export interface DiffCellUnchangedItems {
|
|
59
|
+
isShown: boolean;
|
|
60
|
+
unchangedResultItems: DiffCellItem[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const DiffCellUnchangedItems = {
|
|
64
|
+
is: (arg: Record<any, any>): arg is DiffCellUnchangedItems =>
|
|
65
|
+
!!arg &&
|
|
66
|
+
'isShown' in arg &&
|
|
67
|
+
typeof (arg as any).isShown === 'boolean' &&
|
|
68
|
+
'unchangedResultItems' in arg &&
|
|
69
|
+
typeof (arg as any).unchangedResultItems === 'object',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export interface DiffArrayItem {
|
|
73
|
+
count: number;
|
|
74
|
+
added?: undefined | string;
|
|
75
|
+
removed?: undefined | string;
|
|
76
|
+
value: ICell[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface DiffEditorProps {
|
|
80
|
+
diffCellResultItem: DiffCellItem & { originFilePath?: string; targetFilePath?: string };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const DiffOption = Symbol('DiffOption');
|
|
84
|
+
/**
|
|
85
|
+
* LibroDiff 创建参数
|
|
86
|
+
* 默认可 json 序列化
|
|
87
|
+
*/
|
|
88
|
+
export interface DiffOption {
|
|
89
|
+
loadType: string;
|
|
90
|
+
id?: string;
|
|
91
|
+
origin: URI;
|
|
92
|
+
target: URI;
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}
|