@difizen/libro-output 0.3.44 → 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.
@@ -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;AAE3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAOxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAW/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;YAetB,mBAAmB;YA2DnB,wBAAwB;CA8CvC"}
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 () {
@@ -56,10 +58,19 @@ export var DisplayDataOutputContribution = (_dec = singleton({
56
58
  processedOutput = _context.sent;
57
59
  return _context.abrupt("return", this.viewManager.getOrCreateView(DisplayDataOutputModel, Object.assign(processedOutput, {
58
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
+ }
59
70
  return {
71
+ _id: displayId || uniqueId,
60
72
  cellId: processedOutput.cell.id,
61
- type: processedOutput.output.output_type,
62
- keys: Object.keys(processedOutput.output.data || {})
73
+ type: processedOutput.output.output_type
63
74
  };
64
75
  }
65
76
  })));
@@ -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;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,qBACa,wBAAyB,YAAW,kBAAkB;IAC5C,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,WAAY,OAAO,aAK1B;IACF,OAAO,CAAC,MAAM,EAAE,cAAc;CAgB/B"}
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 () {
@@ -30,11 +32,16 @@ export var StreamOutputContribution = (_dec = singleton({
30
32
  value: function factory(output) {
31
33
  return this.viewManager.getOrCreateView(StreamOutputModel, Object.assign(output, {
32
34
  toJSON: function toJSON() {
35
+ var uniqueId = outputIdMap.get(output.output);
36
+ if (!uniqueId) {
37
+ uniqueId = v4();
38
+ outputIdMap.set(output.output, uniqueId);
39
+ }
33
40
  return {
41
+ _id: uniqueId,
34
42
  cellId: output.cell.id,
35
43
  type: output.output.output_type,
36
- name: output.output.name,
37
- length: typeof output.output.text === 'string' ? output.output.text.length : 0
44
+ name: output.output.name
38
45
  };
39
46
  }
40
47
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-output",
3
- "version": "0.3.44",
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.44",
36
- "@difizen/libro-core": "^0.3.44",
37
- "@difizen/libro-rendermime": "^0.3.44",
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;
@@ -49,11 +52,23 @@ export class DisplayDataOutputContribution implements OutputContribution {
49
52
  return this.viewManager.getOrCreateView(
50
53
  DisplayDataOutputModel,
51
54
  Object.assign(processedOutput, {
52
- toJSON: () => ({
53
- cellId: processedOutput.cell.id,
54
- type: processedOutput.output.output_type,
55
- keys: Object.keys((processedOutput.output as any).data || {}),
56
- }),
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
+ },
57
72
  }),
58
73
  );
59
74
  }
@@ -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;
@@ -19,15 +22,21 @@ export class StreamOutputContribution implements OutputContribution {
19
22
  return this.viewManager.getOrCreateView(
20
23
  StreamOutputModel,
21
24
  Object.assign(output, {
22
- toJSON: () => ({
23
- cellId: output.cell.id,
24
- type: output.output.output_type,
25
- name: (output.output as any).name,
26
- length:
27
- typeof (output.output as any).text === 'string'
28
- ? (output.output as any).text.length
29
- : 0,
30
- }),
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
+ },
31
40
  }),
32
41
  );
33
42
  }