@difizen/libro-output 0.3.43 → 0.3.45
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/display-data-output/display-data-output-contribution.d.ts.map +1 -1
- package/es/display-data-output/display-data-output-contribution.js +20 -1
- package/es/stream-output/stream-output-contribution.d.ts.map +1 -1
- package/es/stream-output/stream-output-contribution.js +17 -1
- package/package.json +6 -5
- package/src/display-data-output/display-data-output-contribution.ts +25 -1
- package/src/stream-output/stream-output-contribution.ts +23 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-data-output-contribution.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAGL,WAAW,EACX,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"display-data-output-contribution.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAGL,WAAW,EACX,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAOxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAa/D,qBACa,6BAA8B,YAAW,kBAAkB;IACjD,WAAW,EAAE,WAAW,CAAC;IAChB,oBAAoB,EAAE,oBAAoB,CAAC;IAC7C,kBAAkB,EAAE,kBAAkB,CAAC;IAEnE,SAAS,WAAY,OAAO,aAQ1B;IAEI,OAAO,CAAC,MAAM,EAAE,cAAc;YA2BtB,mBAAmB;YA2DnB,wBAAwB;CA8CvC"}
|
|
@@ -23,10 +23,12 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
23
23
|
import { getBundleOptions } from '@difizen/libro-common';
|
|
24
24
|
import { OutputContribution } from '@difizen/libro-core';
|
|
25
25
|
import { inject, singleton, ViewManager, ConfigurationService } from '@difizen/mana-app';
|
|
26
|
+
import { v4 } from 'uuid';
|
|
26
27
|
import { DisplayDataOutputModel } from "./display-data-output-model.js";
|
|
27
28
|
import { ImageProcessingEnabled, ImageProcessingRemoveOriginal, ImageProcessingSizeThreshold, ImageProcessingSupportedMimeTypes } from "./display-data-output-setting.js";
|
|
28
29
|
import { ImageUploadService } from "./image-upload-service.js";
|
|
29
30
|
var IMAGE_URL_MIME_TYPE = 'image/vnd.libro.image-url';
|
|
31
|
+
var outputIdMap = new WeakMap();
|
|
30
32
|
export var DisplayDataOutputContribution = (_dec = singleton({
|
|
31
33
|
contrib: OutputContribution
|
|
32
34
|
}), _dec2 = inject(ViewManager), _dec3 = inject(ConfigurationService), _dec4 = inject(ImageUploadService), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
@@ -54,7 +56,24 @@ export var DisplayDataOutputContribution = (_dec = singleton({
|
|
|
54
56
|
return this.preprocessImageData(output);
|
|
55
57
|
case 2:
|
|
56
58
|
processedOutput = _context.sent;
|
|
57
|
-
return _context.abrupt("return", this.viewManager.getOrCreateView(DisplayDataOutputModel, processedOutput
|
|
59
|
+
return _context.abrupt("return", this.viewManager.getOrCreateView(DisplayDataOutputModel, Object.assign(processedOutput, {
|
|
60
|
+
toJSON: function toJSON() {
|
|
61
|
+
var _processedOutput$outp;
|
|
62
|
+
// 在 Jupyter 协议中,transient.display_id 用于标识可更新的显示数据
|
|
63
|
+
// 但是大多数输出(如静态图表、文本)没有 transient 字段。
|
|
64
|
+
var displayId = (_processedOutput$outp = processedOutput.output['transient']) === null || _processedOutput$outp === void 0 ? void 0 : _processedOutput$outp.display_id;
|
|
65
|
+
var uniqueId = outputIdMap.get(output.output);
|
|
66
|
+
if (!displayId && !uniqueId) {
|
|
67
|
+
uniqueId = v4();
|
|
68
|
+
outputIdMap.set(output.output, uniqueId);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
_id: displayId || uniqueId,
|
|
72
|
+
cellId: processedOutput.cell.id,
|
|
73
|
+
type: processedOutput.output.output_type
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
})));
|
|
58
77
|
case 4:
|
|
59
78
|
case "end":
|
|
60
79
|
return _context.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-output-contribution.d.ts","sourceRoot":"","sources":["../../src/stream-output/stream-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-output-contribution.d.ts","sourceRoot":"","sources":["../../src/stream-output/stream-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAI7D,qBACa,wBAAyB,YAAW,kBAAkB;IAC5C,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,WAAY,OAAO,aAK1B;IACF,OAAO,CAAC,MAAM,EAAE,cAAc;CAsB/B"}
|
|
@@ -11,7 +11,9 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
11
11
|
import { OutputContribution } from '@difizen/libro-core';
|
|
12
12
|
import { inject, singleton } from '@difizen/mana-app';
|
|
13
13
|
import { ViewManager } from '@difizen/mana-app';
|
|
14
|
+
import { v4 } from 'uuid';
|
|
14
15
|
import { StreamOutputModel } from "./stream-output-model.js";
|
|
16
|
+
var outputIdMap = new WeakMap();
|
|
15
17
|
export var StreamOutputContribution = (_dec = singleton({
|
|
16
18
|
contrib: OutputContribution
|
|
17
19
|
}), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
@@ -28,7 +30,21 @@ export var StreamOutputContribution = (_dec = singleton({
|
|
|
28
30
|
_createClass(StreamOutputContribution, [{
|
|
29
31
|
key: "factory",
|
|
30
32
|
value: function factory(output) {
|
|
31
|
-
return this.viewManager.getOrCreateView(StreamOutputModel, output
|
|
33
|
+
return this.viewManager.getOrCreateView(StreamOutputModel, Object.assign(output, {
|
|
34
|
+
toJSON: function toJSON() {
|
|
35
|
+
var uniqueId = outputIdMap.get(output.output);
|
|
36
|
+
if (!uniqueId) {
|
|
37
|
+
uniqueId = v4();
|
|
38
|
+
outputIdMap.set(output.output, uniqueId);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
_id: uniqueId,
|
|
42
|
+
cellId: output.cell.id,
|
|
43
|
+
type: output.output.output_type,
|
|
44
|
+
name: output.output.name
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
32
48
|
}
|
|
33
49
|
}]);
|
|
34
50
|
return StreamOutputContribution;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-output",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,12 +32,13 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-common": "^0.3.
|
|
36
|
-
"@difizen/libro-core": "^0.3.
|
|
37
|
-
"@difizen/libro-rendermime": "^0.3.
|
|
35
|
+
"@difizen/libro-common": "^0.3.45",
|
|
36
|
+
"@difizen/libro-core": "^0.3.45",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.3.45",
|
|
38
38
|
"@difizen/mana-app": "latest",
|
|
39
39
|
"@difizen/mana-l10n": "^0.1.32",
|
|
40
|
-
"markdown-it": "^13.0.1"
|
|
40
|
+
"markdown-it": "^13.0.1",
|
|
41
|
+
"uuid": "^9.0.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"antd": "^5.8.6",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ViewManager,
|
|
9
9
|
ConfigurationService,
|
|
10
10
|
} from '@difizen/mana-app';
|
|
11
|
+
import { v4 } from 'uuid';
|
|
11
12
|
|
|
12
13
|
import { DisplayDataOutputModel } from './display-data-output-model.js';
|
|
13
14
|
import {
|
|
@@ -27,6 +28,8 @@ interface ImageProcessingConfig {
|
|
|
27
28
|
|
|
28
29
|
const IMAGE_URL_MIME_TYPE = 'image/vnd.libro.image-url';
|
|
29
30
|
|
|
31
|
+
const outputIdMap = new WeakMap<IOutput, string>();
|
|
32
|
+
|
|
30
33
|
@singleton({ contrib: OutputContribution })
|
|
31
34
|
export class DisplayDataOutputContribution implements OutputContribution {
|
|
32
35
|
@inject(ViewManager) viewManager: ViewManager;
|
|
@@ -46,7 +49,28 @@ export class DisplayDataOutputContribution implements OutputContribution {
|
|
|
46
49
|
async factory(output: IOutputOptions) {
|
|
47
50
|
// 在构造模型之前预处理图片数据
|
|
48
51
|
const processedOutput = await this.preprocessImageData(output);
|
|
49
|
-
return this.viewManager.getOrCreateView(
|
|
52
|
+
return this.viewManager.getOrCreateView(
|
|
53
|
+
DisplayDataOutputModel,
|
|
54
|
+
Object.assign(processedOutput, {
|
|
55
|
+
toJSON: () => {
|
|
56
|
+
// 在 Jupyter 协议中,transient.display_id 用于标识可更新的显示数据
|
|
57
|
+
// 但是大多数输出(如静态图表、文本)没有 transient 字段。
|
|
58
|
+
const displayId = (processedOutput.output['transient'] as any)?.display_id;
|
|
59
|
+
let uniqueId = outputIdMap.get(output.output);
|
|
60
|
+
|
|
61
|
+
if (!displayId && !uniqueId) {
|
|
62
|
+
uniqueId = v4();
|
|
63
|
+
outputIdMap.set(output.output, uniqueId as string);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
_id: displayId || uniqueId,
|
|
68
|
+
cellId: processedOutput.cell.id,
|
|
69
|
+
type: processedOutput.output.output_type,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
private async preprocessImageData(options: IOutputOptions): Promise<IOutputOptions> {
|
|
@@ -3,9 +3,12 @@ import type { IOutputOptions } from '@difizen/libro-core';
|
|
|
3
3
|
import { OutputContribution } from '@difizen/libro-core';
|
|
4
4
|
import { inject, singleton } from '@difizen/mana-app';
|
|
5
5
|
import { ViewManager } from '@difizen/mana-app';
|
|
6
|
+
import { v4 } from 'uuid';
|
|
6
7
|
|
|
7
8
|
import { StreamOutputModel } from './stream-output-model.js';
|
|
8
9
|
|
|
10
|
+
const outputIdMap = new WeakMap<IOutput, string>();
|
|
11
|
+
|
|
9
12
|
@singleton({ contrib: OutputContribution })
|
|
10
13
|
export class StreamOutputContribution implements OutputContribution {
|
|
11
14
|
@inject(ViewManager) viewManager: ViewManager;
|
|
@@ -16,6 +19,25 @@ export class StreamOutputContribution implements OutputContribution {
|
|
|
16
19
|
return 1;
|
|
17
20
|
};
|
|
18
21
|
factory(output: IOutputOptions) {
|
|
19
|
-
return this.viewManager.getOrCreateView(
|
|
22
|
+
return this.viewManager.getOrCreateView(
|
|
23
|
+
StreamOutputModel,
|
|
24
|
+
Object.assign(output, {
|
|
25
|
+
toJSON: () => {
|
|
26
|
+
let uniqueId = outputIdMap.get(output.output);
|
|
27
|
+
|
|
28
|
+
if (!uniqueId) {
|
|
29
|
+
uniqueId = v4();
|
|
30
|
+
outputIdMap.set(output.output, uniqueId as string);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
_id: uniqueId,
|
|
35
|
+
cellId: output.cell.id,
|
|
36
|
+
type: output.output.output_type,
|
|
37
|
+
name: (output.output as any).name,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
20
42
|
}
|
|
21
43
|
}
|