@opensumi/ide-notebook 3.7.1-next-1737703128.0 → 3.7.1-next-1738824147.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,351 @@
|
|
|
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 { Diff } 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 = Diff.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
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { LibroService } from '@difizen/libro-core';
|
|
2
|
+
import { ViewManager, getOrigin, inject, singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { Injector } from '@opensumi/di';
|
|
5
|
+
import { Event, MonacoService } from '@opensumi/ide-core-browser';
|
|
6
|
+
import { uuid } from '@opensumi/ide-utils';
|
|
7
|
+
import { IModelService } from '@opensumi/monaco-editor-core/esm/vs/editor/common/services/model';
|
|
8
|
+
import { StandaloneServices } from '@opensumi/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
|
|
9
|
+
|
|
10
|
+
import { OpensumiInjector } from '../../mana';
|
|
11
|
+
|
|
12
|
+
import { DiffType } from './libro-diff-protocol';
|
|
13
|
+
import { LibroDiffView } from './libro-diff-view';
|
|
14
|
+
import { AIStudioLibroVersionView } from './libro-version-view';
|
|
15
|
+
|
|
16
|
+
import type { NotebookOption } from '@difizen/libro-core';
|
|
17
|
+
|
|
18
|
+
@singleton()
|
|
19
|
+
export class LibroVersionManager {
|
|
20
|
+
protected readonly libroService: LibroService;
|
|
21
|
+
protected readonly viewManager: ViewManager;
|
|
22
|
+
protected readonly opensumiInjector: Injector;
|
|
23
|
+
constructor(
|
|
24
|
+
@inject(LibroService) libroService: LibroService,
|
|
25
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
26
|
+
@inject(OpensumiInjector) opensumiInjector: Injector,
|
|
27
|
+
) {
|
|
28
|
+
this.libroService = libroService;
|
|
29
|
+
this.viewManager = viewManager;
|
|
30
|
+
this.opensumiInjector = opensumiInjector;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getOrCreateView(options: NotebookOption): Promise<AIStudioLibroVersionView> {
|
|
34
|
+
const aistudioLibroVersionView = await this.viewManager.getOrCreateView<AIStudioLibroVersionView>(
|
|
35
|
+
AIStudioLibroVersionView,
|
|
36
|
+
{
|
|
37
|
+
...(options || {}),
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
// 如果存在原始和目标uri,则创建diff视图,默认为预览视图(git uri)
|
|
41
|
+
if (options.originalUri && options.targetUri) {
|
|
42
|
+
this.viewManager
|
|
43
|
+
.getOrCreateView(LibroDiffView, {
|
|
44
|
+
id: uuid(),
|
|
45
|
+
origin: options.originalUri,
|
|
46
|
+
target: options.targetUri,
|
|
47
|
+
})
|
|
48
|
+
.then((diffView) => {
|
|
49
|
+
aistudioLibroVersionView.libroDiffView = diffView;
|
|
50
|
+
aistudioLibroVersionView.isDiff = true;
|
|
51
|
+
});
|
|
52
|
+
return aistudioLibroVersionView;
|
|
53
|
+
}
|
|
54
|
+
const libroView = await this.libroService.getOrCreateView({
|
|
55
|
+
...(options || {}),
|
|
56
|
+
});
|
|
57
|
+
// 版本预览视图只读
|
|
58
|
+
libroView.model.inputEditable = false;
|
|
59
|
+
libroView.model.cellsEditable = false;
|
|
60
|
+
libroView.headerRender = () => null;
|
|
61
|
+
aistudioLibroVersionView.libro = libroView;
|
|
62
|
+
return aistudioLibroVersionView;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
createPreviewEditor(content: string, language: string, dom: HTMLElement, diffType: DiffType) {
|
|
66
|
+
const monacoService: MonacoService = this.opensumiInjector.get(MonacoService);
|
|
67
|
+
const editor = getOrigin(monacoService).createCodeEditor(dom, {
|
|
68
|
+
language,
|
|
69
|
+
minimap: {
|
|
70
|
+
enabled: false,
|
|
71
|
+
},
|
|
72
|
+
value: content,
|
|
73
|
+
automaticLayout: false,
|
|
74
|
+
folding: true,
|
|
75
|
+
wordWrap: 'off',
|
|
76
|
+
lineDecorationsWidth: 0,
|
|
77
|
+
lineNumbersMinChars: 3,
|
|
78
|
+
scrollbar: {
|
|
79
|
+
vertical: 'hidden',
|
|
80
|
+
alwaysConsumeMouseWheel: false,
|
|
81
|
+
verticalScrollbarSize: 0,
|
|
82
|
+
horizontal: 'visible',
|
|
83
|
+
horizontalScrollbarSize: 0,
|
|
84
|
+
},
|
|
85
|
+
glyphMargin: true,
|
|
86
|
+
scrollBeyondLastLine: false,
|
|
87
|
+
renderFinalNewline: 'off',
|
|
88
|
+
renderLineHighlight: 'none',
|
|
89
|
+
readOnly: true,
|
|
90
|
+
// scrollBeyondLastColumn: 2,
|
|
91
|
+
extraEditorClassName: `libro-diff-editor-${diffType}`,
|
|
92
|
+
});
|
|
93
|
+
return editor;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
createDiffEditor(original: string, modified: string, language: string, dom: HTMLElement) {
|
|
97
|
+
const monacoService: MonacoService = this.opensumiInjector.get(MonacoService);
|
|
98
|
+
const editor = getOrigin(monacoService).createDiffEditor(dom, {
|
|
99
|
+
minimap: {
|
|
100
|
+
enabled: false,
|
|
101
|
+
},
|
|
102
|
+
automaticLayout: false,
|
|
103
|
+
renderSideBySide: true,
|
|
104
|
+
fontSize: 13,
|
|
105
|
+
folding: true,
|
|
106
|
+
wordWrap: 'off',
|
|
107
|
+
renderIndicators: false,
|
|
108
|
+
lineNumbersMinChars: 3,
|
|
109
|
+
scrollbar: {
|
|
110
|
+
vertical: 'hidden',
|
|
111
|
+
alwaysConsumeMouseWheel: false,
|
|
112
|
+
verticalScrollbarSize: 0,
|
|
113
|
+
horizontal: 'visible',
|
|
114
|
+
horizontalScrollbarSize: 0,
|
|
115
|
+
},
|
|
116
|
+
glyphMargin: true,
|
|
117
|
+
scrollBeyondLastLine: false,
|
|
118
|
+
scrollBeyondLastColumn: 1,
|
|
119
|
+
renderFinalNewline: 'off',
|
|
120
|
+
renderOverviewRuler: false,
|
|
121
|
+
renderLineHighlight: 'none',
|
|
122
|
+
enableSplitViewResizing: false,
|
|
123
|
+
lineDecorationsWidth: '16px',
|
|
124
|
+
diffWordWrap: 'off',
|
|
125
|
+
readOnly: true,
|
|
126
|
+
extraEditorClassName: 'libro-diff-editor-changed',
|
|
127
|
+
});
|
|
128
|
+
const modelService = StandaloneServices.get(IModelService);
|
|
129
|
+
editor.setModel({
|
|
130
|
+
original: modelService.createModel(original, { languageId: language, onDidChange: Event.None }),
|
|
131
|
+
modified: modelService.createModel(modified, { languageId: language, onDidChange: Event.None }),
|
|
132
|
+
});
|
|
133
|
+
return editor;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { LibroView } from '@difizen/libro-core';
|
|
2
|
+
import {
|
|
3
|
+
BaseView,
|
|
4
|
+
ViewInstance,
|
|
5
|
+
ViewOption,
|
|
6
|
+
ViewRender,
|
|
7
|
+
inject,
|
|
8
|
+
prop,
|
|
9
|
+
transient,
|
|
10
|
+
useInject,
|
|
11
|
+
view,
|
|
12
|
+
} from '@difizen/mana-app';
|
|
13
|
+
import React, { forwardRef } from 'react';
|
|
14
|
+
|
|
15
|
+
import type { LibroDiffView } from './';
|
|
16
|
+
const LibroVersionRender = forwardRef<HTMLDivElement>((_props, ref) => {
|
|
17
|
+
const aistudioLibroVersionView = useInject<AIStudioLibroVersionView>(ViewInstance);
|
|
18
|
+
return (
|
|
19
|
+
<div className='libro-version-content' ref={ref}>
|
|
20
|
+
{aistudioLibroVersionView.isDiff
|
|
21
|
+
? aistudioLibroVersionView.libroDiffView && <ViewRender view={aistudioLibroVersionView.libroDiffView} />
|
|
22
|
+
: aistudioLibroVersionView.libro && <ViewRender view={aistudioLibroVersionView.libro} />}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
@transient()
|
|
28
|
+
@view('libro-version-view')
|
|
29
|
+
export class AIStudioLibroVersionView extends BaseView {
|
|
30
|
+
view = LibroVersionRender;
|
|
31
|
+
@inject(ViewOption) options: any;
|
|
32
|
+
@prop()
|
|
33
|
+
isDiff: boolean = false;
|
|
34
|
+
// for git preview
|
|
35
|
+
@prop()
|
|
36
|
+
libro: LibroView;
|
|
37
|
+
// for git diff
|
|
38
|
+
@prop()
|
|
39
|
+
libroDiffView: LibroDiffView;
|
|
40
|
+
onViewMount() {}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LibroJupyterNoEditorModule } from '@difizen/libro-jupyter/noeditor';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { LibroDiffColorRegistry } from './libro-diff-color-registry';
|
|
5
|
+
import { LibroDiffView } from './libro-diff-view';
|
|
6
|
+
import { LibroVersionManager } from './libro-version-manager';
|
|
7
|
+
import { AIStudioLibroVersionView } from './libro-version-view';
|
|
8
|
+
|
|
9
|
+
export const LibroDiffModule = ManaModule.create()
|
|
10
|
+
.register(AIStudioLibroVersionView, LibroVersionManager, LibroDiffView, LibroDiffColorRegistry)
|
|
11
|
+
.dependOn(LibroJupyterNoEditorModule);
|
|
@@ -14,7 +14,7 @@ export class LibroOpensumiContentContribution implements ContentContribution {
|
|
|
14
14
|
@inject(OpensumiInjector) injector: Injector;
|
|
15
15
|
|
|
16
16
|
canHandle = (options) => (options.loadType === ContentLoaderType ? 100 : 1);
|
|
17
|
-
async loadContent(options: NotebookOption, model: LibroJupyterModel) {
|
|
17
|
+
async loadContent(options: NotebookOption, model: LibroJupyterModel): Promise<INotebookContent> {
|
|
18
18
|
const fileServiceClient: IFileServiceClient = this.injector.get(IFileServiceClient);
|
|
19
19
|
const messageService = this.injector.get(IMessageService);
|
|
20
20
|
let notebookContent: INotebookContent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Container, URI, ViewRender } from '@difizen/mana-app';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useInjectable } from '@opensumi/ide-core-browser';
|
|
5
|
+
import { ReactEditorComponent } from '@opensumi/ide-editor/lib/browser/types';
|
|
6
|
+
|
|
7
|
+
import { LibroVersionManager } from './libro/diff-view/libro-version-manager';
|
|
8
|
+
import { AIStudioLibroVersionView } from './libro/diff-view/libro-version-view';
|
|
9
|
+
import { ContentLoaderType, ManaContainer } from './mana';
|
|
10
|
+
|
|
11
|
+
export const LibroVersionPreview: ReactEditorComponent = ({ resource }) => {
|
|
12
|
+
const uri = resource.uri;
|
|
13
|
+
const originalUri = uri.scheme === 'diff' ? new URI(decodeURIComponent(uri.getParsedQuery().original)) : undefined;
|
|
14
|
+
const targetUri = uri.scheme === 'diff' ? new URI(decodeURIComponent(uri.getParsedQuery().modified)) : undefined;
|
|
15
|
+
const manaContainer = useInjectable<Container>(ManaContainer);
|
|
16
|
+
const libroVersionManager = manaContainer.get(LibroVersionManager);
|
|
17
|
+
const [versionView, setVersionView] = useState<AIStudioLibroVersionView>();
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
libroVersionManager
|
|
21
|
+
.getOrCreateView({
|
|
22
|
+
resource: uri.toString(),
|
|
23
|
+
loadType: ContentLoaderType,
|
|
24
|
+
originalUri,
|
|
25
|
+
targetUri,
|
|
26
|
+
})
|
|
27
|
+
.then((view) => {
|
|
28
|
+
setVersionView(view);
|
|
29
|
+
});
|
|
30
|
+
}, [uri]);
|
|
31
|
+
|
|
32
|
+
return <div className='libro-version'>{versionView && <ViewRender view={versionView}></ViewRender>}</div>;
|
|
33
|
+
};
|
|
@@ -41,9 +41,11 @@ import { IThemeService, IconType } from '@opensumi/ide-theme/lib/common';
|
|
|
41
41
|
|
|
42
42
|
import { KERNEL_PANEL_ID, KernelPanel, initKernelPanelColorToken } from './kernel-panel';
|
|
43
43
|
import { LibroOpensumiModule } from './libro';
|
|
44
|
+
import { LibroDiffModule } from './libro/diff-view';
|
|
44
45
|
import { LibroOpener } from './libro-opener';
|
|
46
|
+
import { LibroVersionPreview } from './libro-preview.view';
|
|
45
47
|
import { initLibroColorToken } from './libro.color.tokens';
|
|
46
|
-
import {
|
|
48
|
+
import { LIBRO_COMPONENTS_SCHEME_ID, LIBRO_COMPONENT_ID, LIBRO_PREVIEW_COMPONENT_ID } from './libro.protocol';
|
|
47
49
|
import { OpensumiLibroView } from './libro.view';
|
|
48
50
|
import { ManaContainer, initLibroOpensumi, manaContainer } from './mana/index';
|
|
49
51
|
import { NotebookDocumentContentProvider } from './notebook-document-content-provider';
|
|
@@ -62,7 +64,14 @@ const LayoutWrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
62
64
|
return (
|
|
63
65
|
<ManaComponents.Application
|
|
64
66
|
context={{ container: manaContainer }}
|
|
65
|
-
modules={[
|
|
67
|
+
modules={[
|
|
68
|
+
ManaAppPreset,
|
|
69
|
+
LibroJupyterNoEditorModule,
|
|
70
|
+
LibroDiffModule,
|
|
71
|
+
LibroTOCModule,
|
|
72
|
+
LibroOpensumiModule,
|
|
73
|
+
LibroVariableModule,
|
|
74
|
+
]}
|
|
66
75
|
renderChildren
|
|
67
76
|
onReady={() => setIsReady(true)}
|
|
68
77
|
>
|
|
@@ -182,11 +191,17 @@ export class LibroContribution
|
|
|
182
191
|
|
|
183
192
|
registerEditorComponent(registry: EditorComponentRegistry) {
|
|
184
193
|
registry.registerEditorComponent({
|
|
185
|
-
uid:
|
|
194
|
+
uid: LIBRO_COMPONENT_ID,
|
|
186
195
|
scheme: LIBRO_COMPONENTS_SCHEME_ID,
|
|
187
196
|
component: OpensumiLibroView,
|
|
188
197
|
});
|
|
189
198
|
|
|
199
|
+
registry.registerEditorComponent({
|
|
200
|
+
uid: LIBRO_PREVIEW_COMPONENT_ID,
|
|
201
|
+
scheme: LIBRO_COMPONENTS_SCHEME_ID,
|
|
202
|
+
component: LibroVersionPreview,
|
|
203
|
+
});
|
|
204
|
+
|
|
190
205
|
registry.registerEditorComponentResolver(Schemes.file, (resource, results) => {
|
|
191
206
|
if (resource.uri.path.ext === `.${LIBRO_COMPONENTS_SCHEME_ID}`) {
|
|
192
207
|
// 首次打开 notebook 文件时初始化 jupyter 服务连接
|
|
@@ -197,7 +212,31 @@ export class LibroContribution
|
|
|
197
212
|
}
|
|
198
213
|
results.push({
|
|
199
214
|
type: 'component',
|
|
200
|
-
componentId:
|
|
215
|
+
componentId: LIBRO_COMPONENT_ID,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// git schema 的 notebook 资源,在 ide 中打开
|
|
221
|
+
registry.registerEditorComponentResolver('git', (resource, results) => {
|
|
222
|
+
if (resource.uri.path.ext === '.ipynb') {
|
|
223
|
+
results.push({
|
|
224
|
+
type: 'component',
|
|
225
|
+
componentId: LIBRO_PREVIEW_COMPONENT_ID,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
registry.registerEditorComponentResolver('diff', (resource, results) => {
|
|
231
|
+
const { original, modified } = resource.uri.getParsedQuery();
|
|
232
|
+
if (
|
|
233
|
+
new URI(decodeURIComponent(modified)).path.ext === '.ipynb' ||
|
|
234
|
+
new URI(decodeURIComponent(original)).path.ext === '.ipynb'
|
|
235
|
+
) {
|
|
236
|
+
// TODO: 需要等 git 插件 ready,否则 git uri 无法解析
|
|
237
|
+
results.push({
|
|
238
|
+
type: 'component',
|
|
239
|
+
componentId: LIBRO_PREVIEW_COMPONENT_ID,
|
|
201
240
|
});
|
|
202
241
|
}
|
|
203
242
|
});
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const LIBRO_COMPONENT_ID = 'opensumi:libro';
|
|
2
|
+
export const LIBRO_PREVIEW_COMPONENT_ID = 'opensumi:libro-preview';
|
|
3
|
+
export const LIBRO_DIFF_COMPONENT_ID = 'opensumi:libro-diff';
|
|
2
4
|
export const LIBRO_COMPONENTS_SCHEME_ID = 'ipynb';
|