@opensumi/ide-notebook 3.7.1-next-1739774311.0 → 3.7.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.
- package/lib/browser/libro/libro-opensumi-content-contribution.d.ts.map +1 -1
- package/lib/browser/libro.contribution.d.ts.map +1 -1
- package/lib/browser/libro.contribution.js +4 -38
- package/lib/browser/libro.contribution.js.map +1 -1
- package/lib/browser/libro.protocol.d.ts +1 -3
- package/lib/browser/libro.protocol.d.ts.map +1 -1
- package/lib/browser/libro.protocol.js +1 -3
- package/lib/browser/libro.protocol.js.map +1 -1
- package/package.json +14 -20
- package/src/browser/libro/libro-opensumi-content-contribution.ts +1 -1
- package/src/browser/libro.contribution.tsx +4 -43
- package/src/browser/libro.protocol.ts +1 -3
- package/lib/browser/libro/diff-view/components/hooks.d.ts +0 -10
- package/lib/browser/libro/diff-view/components/hooks.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/components/hooks.js +0 -96
- package/lib/browser/libro/diff-view/components/hooks.js.map +0 -1
- package/lib/browser/libro/diff-view/components/index.less +0 -315
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.d.ts +0 -3
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.js +0 -11
- package/lib/browser/libro/diff-view/components/libro-diff-all-cells-same-components.js.map +0 -1
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.d.ts +0 -5
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.js +0 -59
- package/lib/browser/libro/diff-view/components/libro-diff-changed-cell-components.js.map +0 -1
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.d.ts +0 -5
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.js +0 -58
- package/lib/browser/libro/diff-view/components/libro-diff-side-cell-components.js.map +0 -1
- package/lib/browser/libro/diff-view/index.d.ts +0 -5
- package/lib/browser/libro/diff-view/index.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/index.js +0 -5
- package/lib/browser/libro/diff-view/index.js.map +0 -1
- package/lib/browser/libro/diff-view/index.less +0 -47
- package/lib/browser/libro/diff-view/libro-diff-color-registry.d.ts +0 -6
- package/lib/browser/libro/diff-view/libro-diff-color-registry.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-color-registry.js +0 -110
- package/lib/browser/libro/diff-view/libro-diff-color-registry.js.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-component.d.ts +0 -6
- package/lib/browser/libro/diff-view/libro-diff-component.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-component.js +0 -21
- package/lib/browser/libro/diff-view/libro-diff-component.js.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-protocol.d.ts +0 -58
- package/lib/browser/libro/diff-view/libro-diff-protocol.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-protocol.js +0 -38
- package/lib/browser/libro/diff-view/libro-diff-protocol.js.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-view.d.ts +0 -48
- package/lib/browser/libro/diff-view/libro-diff-view.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-diff-view.js +0 -297
- package/lib/browser/libro/diff-view/libro-diff-view.js.map +0 -1
- package/lib/browser/libro/diff-view/libro-version-manager.d.ts +0 -16
- package/lib/browser/libro/diff-view/libro-version-manager.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-version-manager.js +0 -126
- package/lib/browser/libro/diff-view/libro-version-manager.js.map +0 -1
- package/lib/browser/libro/diff-view/libro-version-view.d.ts +0 -13
- package/lib/browser/libro/diff-view/libro-version-view.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/libro-version-view.js +0 -40
- package/lib/browser/libro/diff-view/libro-version-view.js.map +0 -1
- package/lib/browser/libro/diff-view/module.d.ts +0 -3
- package/lib/browser/libro/diff-view/module.d.ts.map +0 -1
- package/lib/browser/libro/diff-view/module.js +0 -10
- package/lib/browser/libro/diff-view/module.js.map +0 -1
- package/lib/browser/libro-preview.view.d.ts +0 -3
- package/lib/browser/libro-preview.view.d.ts.map +0 -1
- package/lib/browser/libro-preview.view.js +0 -27
- package/lib/browser/libro-preview.view.js.map +0 -1
- package/src/browser/libro/diff-view/components/hooks.tsx +0 -123
- package/src/browser/libro/diff-view/components/index.less +0 -315
- package/src/browser/libro/diff-view/components/libro-diff-all-cells-same-components.tsx +0 -43
- package/src/browser/libro/diff-view/components/libro-diff-changed-cell-components.tsx +0 -88
- package/src/browser/libro/diff-view/components/libro-diff-side-cell-components.tsx +0 -84
- package/src/browser/libro/diff-view/index.less +0 -47
- package/src/browser/libro/diff-view/index.ts +0 -4
- package/src/browser/libro/diff-view/libro-diff-color-registry.ts +0 -132
- package/src/browser/libro/diff-view/libro-diff-component.tsx +0 -25
- package/src/browser/libro/diff-view/libro-diff-protocol.ts +0 -94
- package/src/browser/libro/diff-view/libro-diff-view.tsx +0 -351
- package/src/browser/libro/diff-view/libro-version-manager.ts +0 -135
- package/src/browser/libro/diff-view/libro-version-view.tsx +0 -41
- package/src/browser/libro/diff-view/module.ts +0 -11
- package/src/browser/libro-preview.view.tsx +0 -33
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { ColumnHeightOutlined } from '@ant-design/icons';
|
|
2
|
-
import { LibroContentService } from '@difizen/libro-core';
|
|
3
|
-
import {
|
|
4
|
-
BaseView,
|
|
5
|
-
ViewInstance,
|
|
6
|
-
ViewOption,
|
|
7
|
-
getOrigin,
|
|
8
|
-
inject,
|
|
9
|
-
prop,
|
|
10
|
-
transient,
|
|
11
|
-
useInject,
|
|
12
|
-
view,
|
|
13
|
-
} from '@difizen/mana-app';
|
|
14
|
-
import { Spin } from 'antd';
|
|
15
|
-
import { diffArrays } from 'diff';
|
|
16
|
-
import React, { forwardRef, useEffect } from 'react';
|
|
17
|
-
|
|
18
|
-
import './index.less';
|
|
19
|
-
import { ContentLoaderType } from '../../mana';
|
|
20
|
-
|
|
21
|
-
import { ContentSameIcon } from './components/libro-diff-all-cells-same-components';
|
|
22
|
-
import { LibroDiffChangedCellComponent } from './components/libro-diff-changed-cell-components';
|
|
23
|
-
import { LibroDiffSideCellComponent } from './components/libro-diff-side-cell-components';
|
|
24
|
-
import { DiffCellItem, DiffCellUnchangedItems, DiffOption, libroDiffViewFactoryId } from './libro-diff-protocol';
|
|
25
|
-
|
|
26
|
-
import type { DiffArrayItem, DiffCellItemResult, DiffView, IDiffNotebookContent } from './libro-diff-protocol';
|
|
27
|
-
import type { ICell, MultilineString } from '@difizen/libro-common';
|
|
28
|
-
import type { ViewComponent } from '@difizen/mana-app';
|
|
29
|
-
|
|
30
|
-
function comparator(compareLeft: ICell, compareRight: ICell) {
|
|
31
|
-
return compareLeft.id === compareRight.id;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function multilineStringEqual(a: MultilineString, b: MultilineString) {
|
|
35
|
-
if (a.length !== b.length) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
for (let i = 0; i < a.length; i++) {
|
|
39
|
-
if (a[i] !== b[i]) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
export const LibroDiffRender = forwardRef(() => {
|
|
46
|
-
const libroDiffView = useInject<LibroDiffView>(ViewInstance);
|
|
47
|
-
useEffect(() => {}, [
|
|
48
|
-
libroDiffView.diffUnchangedCellsRenderStatus,
|
|
49
|
-
libroDiffView.diffCellsResult,
|
|
50
|
-
libroDiffView.isDiffSame,
|
|
51
|
-
]);
|
|
52
|
-
if (!libroDiffView.diffCellsResult) {
|
|
53
|
-
return (
|
|
54
|
-
<div className='libro-diff-content-loading-container'>
|
|
55
|
-
<Spin size='large' />
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (libroDiffView.isDiffSame) {
|
|
61
|
-
return (
|
|
62
|
-
<div className='libro-diff-content-same-container'>
|
|
63
|
-
<ContentSameIcon />
|
|
64
|
-
<span className='libro-diff-content-same-text'>内容一致</span>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<div className='libro-diff-content-container'>
|
|
71
|
-
{libroDiffView.diffCellsResult &&
|
|
72
|
-
libroDiffView.diffCellsResult.map((item) => {
|
|
73
|
-
if (DiffCellItem.is(item) && item.diffType === 'added') {
|
|
74
|
-
return (
|
|
75
|
-
<LibroDiffSideCellComponent
|
|
76
|
-
diffCellResultItem={item}
|
|
77
|
-
key={libroDiffView.id + item.origin.id?.toString()}
|
|
78
|
-
/>
|
|
79
|
-
);
|
|
80
|
-
} else if (DiffCellItem.is(item) && item.diffType === 'removed') {
|
|
81
|
-
return (
|
|
82
|
-
<LibroDiffSideCellComponent
|
|
83
|
-
diffCellResultItem={item}
|
|
84
|
-
key={libroDiffView.id + item.origin.id?.toString()}
|
|
85
|
-
/>
|
|
86
|
-
);
|
|
87
|
-
} else if (DiffCellItem.is(item) && item.diffType === 'changed') {
|
|
88
|
-
return (
|
|
89
|
-
<LibroDiffChangedCellComponent
|
|
90
|
-
diffCellResultItem={item}
|
|
91
|
-
key={libroDiffView.id + item.origin.id?.toString()}
|
|
92
|
-
/>
|
|
93
|
-
);
|
|
94
|
-
} else {
|
|
95
|
-
if (!DiffCellUnchangedItems.is(item) || item.unchangedResultItems.length === 0) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
if (item.isShown) {
|
|
99
|
-
return item.unchangedResultItems.map((unchangedItem) => (
|
|
100
|
-
<LibroDiffChangedCellComponent
|
|
101
|
-
diffCellResultItem={unchangedItem}
|
|
102
|
-
key={libroDiffView.id + unchangedItem.origin.id?.toString()}
|
|
103
|
-
/>
|
|
104
|
-
));
|
|
105
|
-
} else {
|
|
106
|
-
return (
|
|
107
|
-
<div
|
|
108
|
-
className='libro-diff-fold-container'
|
|
109
|
-
key={libroDiffView.id + item.unchangedResultItems[0].origin.id}
|
|
110
|
-
>
|
|
111
|
-
<div
|
|
112
|
-
className='libro-diff-fold'
|
|
113
|
-
onClick={() => {
|
|
114
|
-
item.isShown = true;
|
|
115
|
-
libroDiffView.diffUnchangedCellsRenderStatus = libroDiffView.getUnchangedDiffCellsRenderStatus();
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
<ColumnHeightOutlined />
|
|
119
|
-
<span className='libro-diff-fold-text'>展开{item.unchangedResultItems.length}个未更改的 Cell</span>
|
|
120
|
-
</div>
|
|
121
|
-
</div>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
})}
|
|
126
|
-
</div>
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
@transient()
|
|
131
|
-
@view(libroDiffViewFactoryId)
|
|
132
|
-
export class LibroDiffView extends BaseView implements DiffView {
|
|
133
|
-
view: ViewComponent = LibroDiffRender;
|
|
134
|
-
libroContentService: LibroContentService;
|
|
135
|
-
@prop()
|
|
136
|
-
diffUnchangedCellsRenderStatus: 'all' | 'part' | 'none' = 'none';
|
|
137
|
-
@prop()
|
|
138
|
-
diffCellsResult: DiffCellItemResult[];
|
|
139
|
-
@prop()
|
|
140
|
-
isDiffSame: boolean = true;
|
|
141
|
-
@prop()
|
|
142
|
-
hasUnchangedCells: boolean = false;
|
|
143
|
-
options: Record<string, any>;
|
|
144
|
-
originContent: IDiffNotebookContent;
|
|
145
|
-
targetContent: IDiffNotebookContent;
|
|
146
|
-
targetFilePath: string;
|
|
147
|
-
originFilePath: string;
|
|
148
|
-
constructor(
|
|
149
|
-
@inject(ViewOption) options: DiffOption,
|
|
150
|
-
@inject(LibroContentService) libroContentService: LibroContentService,
|
|
151
|
-
) {
|
|
152
|
-
super();
|
|
153
|
-
this.libroContentService = libroContentService;
|
|
154
|
-
this.options = options;
|
|
155
|
-
this.targetFilePath = options.target.path.toString();
|
|
156
|
-
this.originFilePath = options.origin.path.toString();
|
|
157
|
-
this.loadDiffContent(options).then(() => {
|
|
158
|
-
this.diffCellsResult = this.getDiffCellsResult(
|
|
159
|
-
this.originContent.content.cells,
|
|
160
|
-
this.targetContent.content.cells,
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
loadDiffContent = async (options: DiffOption) => {
|
|
166
|
-
const originContent = await this.libroContentService.loadLibroContent(
|
|
167
|
-
{ loadType: ContentLoaderType, resource: options.origin },
|
|
168
|
-
this,
|
|
169
|
-
);
|
|
170
|
-
this.originContent = {
|
|
171
|
-
// FIXME: 干啥的?
|
|
172
|
-
diffTag: options.origin.toString(),
|
|
173
|
-
content: originContent,
|
|
174
|
-
};
|
|
175
|
-
const targetContent = await this.libroContentService.loadLibroContent(
|
|
176
|
-
{ loadType: ContentLoaderType, resource: options.target },
|
|
177
|
-
this,
|
|
178
|
-
);
|
|
179
|
-
this.targetContent = {
|
|
180
|
-
diffTag: options.target.toString(),
|
|
181
|
-
content: targetContent,
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
foldAllUnchangedDiffCells = () => {
|
|
186
|
-
this.diffCellsResult.map((item) => {
|
|
187
|
-
if (DiffCellUnchangedItems.is(item)) {
|
|
188
|
-
item.isShown = false;
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
expandAllUnchangedDiffCells = () => {
|
|
194
|
-
this.diffCellsResult.map((item) => {
|
|
195
|
-
if (DiffCellUnchangedItems.is(item)) {
|
|
196
|
-
item.isShown = true;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
getUnchangedDiffCellsRenderStatus = () => {
|
|
202
|
-
let unchanedDiffCellsGroups = 0;
|
|
203
|
-
let unchanedDiffCellsfolded = 0;
|
|
204
|
-
let unchanedDiffCellsExpanded = 0;
|
|
205
|
-
for (const item of this.diffCellsResult) {
|
|
206
|
-
if (DiffCellUnchangedItems.is(item)) {
|
|
207
|
-
unchanedDiffCellsGroups = unchanedDiffCellsGroups + 1;
|
|
208
|
-
if (item.isShown) {
|
|
209
|
-
unchanedDiffCellsExpanded = unchanedDiffCellsExpanded + 1;
|
|
210
|
-
} else {
|
|
211
|
-
unchanedDiffCellsfolded = unchanedDiffCellsfolded + 1;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (unchanedDiffCellsfolded > 0) {
|
|
216
|
-
return unchanedDiffCellsExpanded > 0 ? 'part' : 'none';
|
|
217
|
-
} else {
|
|
218
|
-
return 'all';
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
getAddedCellResult = (valueItem: ICell) => {
|
|
223
|
-
const originDiffCellItem = JSON.parse(JSON.stringify(valueItem)) as ICell;
|
|
224
|
-
originDiffCellItem.source = '';
|
|
225
|
-
const addedCellResult: DiffCellItem = {
|
|
226
|
-
diffType: 'added',
|
|
227
|
-
origin: originDiffCellItem,
|
|
228
|
-
target: valueItem,
|
|
229
|
-
};
|
|
230
|
-
return Object.assign(addedCellResult, {
|
|
231
|
-
originFilePath: this.originFilePath,
|
|
232
|
-
targetFilePath: this.targetFilePath,
|
|
233
|
-
});
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
getRemovedCellResult = (valueItem: ICell) => {
|
|
237
|
-
const targetDiffCellItem = JSON.parse(JSON.stringify(valueItem)) as ICell;
|
|
238
|
-
targetDiffCellItem.source = '';
|
|
239
|
-
const removedCellResult: DiffCellItem = {
|
|
240
|
-
diffType: 'removed',
|
|
241
|
-
origin: valueItem,
|
|
242
|
-
target: targetDiffCellItem,
|
|
243
|
-
};
|
|
244
|
-
return Object.assign(removedCellResult, {
|
|
245
|
-
originFilePath: this.originFilePath,
|
|
246
|
-
targetFilePath: this.targetFilePath,
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
getUnchangedCellResult = (originItem: ICell, targetItem: ICell) => {
|
|
251
|
-
const unchangedCellResult: DiffCellItem = {
|
|
252
|
-
diffType: 'unchanged',
|
|
253
|
-
origin: originItem,
|
|
254
|
-
target: targetItem,
|
|
255
|
-
};
|
|
256
|
-
return Object.assign(unchangedCellResult, {
|
|
257
|
-
originFilePath: this.originFilePath,
|
|
258
|
-
targetFilePath: this.targetFilePath,
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
getChangedCellResult = (originItem: ICell, targetItem: ICell) => {
|
|
263
|
-
const changedCellResult: DiffCellItem = {
|
|
264
|
-
diffType: 'changed',
|
|
265
|
-
origin: originItem,
|
|
266
|
-
target: targetItem,
|
|
267
|
-
};
|
|
268
|
-
return Object.assign(changedCellResult, {
|
|
269
|
-
originFilePath: this.originFilePath,
|
|
270
|
-
targetFilePath: this.targetFilePath,
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
getDiffCellsResult = (origin: ICell[], target: ICell[]) => {
|
|
275
|
-
const diffCellsResult: (DiffCellItemResult & { originFilePath?: string; targetFilePath?: string })[] = [];
|
|
276
|
-
let diffCellUnchangedItems: (DiffCellItem & { originFilePath: string; targetFilePath: string })[] = [];
|
|
277
|
-
let lastDiffItemTypeIsUnchanged: boolean = false;
|
|
278
|
-
|
|
279
|
-
const diffArray = diffArrays(getOrigin(origin), getOrigin(target), {
|
|
280
|
-
comparator,
|
|
281
|
-
}) as DiffArrayItem[];
|
|
282
|
-
diffArray.map((item, index) => {
|
|
283
|
-
if (item.added) {
|
|
284
|
-
if (this.isDiffSame) {
|
|
285
|
-
this.isDiffSame = false;
|
|
286
|
-
}
|
|
287
|
-
if (lastDiffItemTypeIsUnchanged === true) {
|
|
288
|
-
lastDiffItemTypeIsUnchanged = false;
|
|
289
|
-
diffCellsResult.push({
|
|
290
|
-
isShown: false,
|
|
291
|
-
unchangedResultItems: diffCellUnchangedItems,
|
|
292
|
-
});
|
|
293
|
-
diffCellUnchangedItems = [];
|
|
294
|
-
}
|
|
295
|
-
item.value.map((valueItem) => {
|
|
296
|
-
diffCellsResult.push(this.getAddedCellResult(valueItem));
|
|
297
|
-
});
|
|
298
|
-
} else if (item.removed) {
|
|
299
|
-
if (this.isDiffSame) {
|
|
300
|
-
this.isDiffSame = false;
|
|
301
|
-
}
|
|
302
|
-
if (lastDiffItemTypeIsUnchanged === true) {
|
|
303
|
-
lastDiffItemTypeIsUnchanged = false;
|
|
304
|
-
diffCellsResult.push({
|
|
305
|
-
isShown: false,
|
|
306
|
-
unchangedResultItems: diffCellUnchangedItems,
|
|
307
|
-
});
|
|
308
|
-
diffCellUnchangedItems = [];
|
|
309
|
-
}
|
|
310
|
-
item.value.map((valueItem) => {
|
|
311
|
-
diffCellsResult.push(this.getRemovedCellResult(valueItem));
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
item.value.map((valueItem) => {
|
|
315
|
-
const originCell = this.originContent.content.cells.find((cell) => cell.id === valueItem.id);
|
|
316
|
-
const targetCell = this.targetContent.content.cells.find((cell) => cell.id === valueItem.id);
|
|
317
|
-
if (!originCell || !targetCell) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (multilineStringEqual(originCell.source, targetCell.source)) {
|
|
321
|
-
if (this.hasUnchangedCells === false) {
|
|
322
|
-
this.hasUnchangedCells = true;
|
|
323
|
-
}
|
|
324
|
-
lastDiffItemTypeIsUnchanged = true;
|
|
325
|
-
diffCellUnchangedItems.push(this.getUnchangedCellResult(originCell, targetCell));
|
|
326
|
-
} else {
|
|
327
|
-
if (this.isDiffSame) {
|
|
328
|
-
this.isDiffSame = false;
|
|
329
|
-
}
|
|
330
|
-
if (lastDiffItemTypeIsUnchanged === true) {
|
|
331
|
-
lastDiffItemTypeIsUnchanged = false;
|
|
332
|
-
diffCellsResult.push({
|
|
333
|
-
isShown: false,
|
|
334
|
-
unchangedResultItems: diffCellUnchangedItems,
|
|
335
|
-
});
|
|
336
|
-
diffCellUnchangedItems = [];
|
|
337
|
-
}
|
|
338
|
-
diffCellsResult.push(this.getChangedCellResult(originCell, targetCell));
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
if (index === diffArray.length - 1) {
|
|
342
|
-
diffCellsResult.push({
|
|
343
|
-
isShown: false,
|
|
344
|
-
unchangedResultItems: diffCellUnchangedItems,
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
return diffCellsResult;
|
|
350
|
-
};
|
|
351
|
-
}
|