@difizen/libro-output 0.0.2-alpha.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/display-data-output/display-data-output-contribution.d.ts +11 -0
  4. package/es/display-data-output/display-data-output-contribution.d.ts.map +1 -0
  5. package/es/display-data-output/display-data-output-contribution.js +40 -0
  6. package/es/display-data-output/display-data-output-model.d.ts +22 -0
  7. package/es/display-data-output/display-data-output-model.d.ts.map +1 -0
  8. package/es/display-data-output/display-data-output-model.js +77 -0
  9. package/es/display-data-output/display-data-output-module.d.ts +3 -0
  10. package/es/display-data-output/display-data-output-module.d.ts.map +1 -0
  11. package/es/display-data-output/display-data-output-module.js +6 -0
  12. package/es/display-data-output/index.d.ts +4 -0
  13. package/es/display-data-output/index.d.ts.map +1 -0
  14. package/es/display-data-output/index.js +3 -0
  15. package/es/error-output/error-output-contribution.d.ts +11 -0
  16. package/es/error-output/error-output-contribution.d.ts.map +1 -0
  17. package/es/error-output/error-output-contribution.js +40 -0
  18. package/es/error-output/error-output-model.d.ts +16 -0
  19. package/es/error-output/error-output-model.d.ts.map +1 -0
  20. package/es/error-output/error-output-model.js +117 -0
  21. package/es/error-output/error-output-module.d.ts +3 -0
  22. package/es/error-output/error-output-module.d.ts.map +1 -0
  23. package/es/error-output/error-output-module.js +6 -0
  24. package/es/error-output/index.d.ts +4 -0
  25. package/es/error-output/index.d.ts.map +1 -0
  26. package/es/error-output/index.js +3 -0
  27. package/es/index.d.ts +4 -0
  28. package/es/index.d.ts.map +1 -0
  29. package/es/index.js +3 -0
  30. package/es/index.less +836 -0
  31. package/es/output-utils.d.ts +21 -0
  32. package/es/output-utils.d.ts.map +1 -0
  33. package/es/output-utils.js +68 -0
  34. package/es/stream-output/index.d.ts +4 -0
  35. package/es/stream-output/index.d.ts.map +1 -0
  36. package/es/stream-output/index.js +3 -0
  37. package/es/stream-output/stream-output-contribution.d.ts +11 -0
  38. package/es/stream-output/stream-output-contribution.d.ts.map +1 -0
  39. package/es/stream-output/stream-output-contribution.js +40 -0
  40. package/es/stream-output/stream-output-model.d.ts +18 -0
  41. package/es/stream-output/stream-output-model.d.ts.map +1 -0
  42. package/es/stream-output/stream-output-model.js +70 -0
  43. package/es/stream-output/stream-output-module.d.ts +3 -0
  44. package/es/stream-output/stream-output-module.d.ts.map +1 -0
  45. package/es/stream-output/stream-output-module.js +6 -0
  46. package/package.json +62 -0
  47. package/src/display-data-output/display-data-output-contribution.ts +24 -0
  48. package/src/display-data-output/display-data-output-model.tsx +67 -0
  49. package/src/display-data-output/display-data-output-module.ts +10 -0
  50. package/src/display-data-output/index.ts +3 -0
  51. package/src/error-output/error-output-contribution.ts +21 -0
  52. package/src/error-output/error-output-model.tsx +94 -0
  53. package/src/error-output/error-output-module.ts +10 -0
  54. package/src/error-output/index.ts +3 -0
  55. package/src/index.less +835 -0
  56. package/src/index.ts +3 -0
  57. package/src/output-utils.ts +84 -0
  58. package/src/stream-output/index.ts +3 -0
  59. package/src/stream-output/stream-output-contribution.ts +21 -0
  60. package/src/stream-output/stream-output-model.tsx +60 -0
  61. package/src/stream-output/stream-output-module.ts +10 -0
@@ -0,0 +1,21 @@
1
+ import type { IOutput, PartialJSONObject, PartialJSONValue, ReadonlyPartialJSONObject } from '@difizen/libro-common';
2
+ /**
3
+ * Get the data from a notebook output.
4
+ */
5
+ export declare function getData(output: IOutput): PartialJSONObject;
6
+ /**
7
+ * Get the metadata from an output message.
8
+ */
9
+ export declare function getMetadata(output: IOutput): PartialJSONObject;
10
+ /**
11
+ * Get the bundle options given output model options.
12
+ */
13
+ export declare function getBundleOptions(options: IOutput): {
14
+ data: IOutput;
15
+ metadata: PartialJSONObject;
16
+ };
17
+ /**
18
+ * Extract a value from a JSONObject.
19
+ */
20
+ export declare function extract(value: ReadonlyPartialJSONObject, key: string): PartialJSONValue | undefined;
21
+ //# sourceMappingURL=output-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-utils.d.ts","sourceRoot":"","sources":["../src/output-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAU/B;;GAEG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAiB1D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAQ9D;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO;;;EAIhD;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,MAAM,GACV,gBAAgB,GAAG,SAAS,CAM9B"}
@@ -0,0 +1,68 @@
1
+ import { isDisplayData, isDisplayUpdate, isError, isExecuteResult, isPrimitive, isStream } from '@difizen/libro-common';
2
+
3
+ /**
4
+ * Get the data from a notebook output.
5
+ */
6
+ export function getData(output) {
7
+ var bundle = {};
8
+ if (isExecuteResult(output) || isDisplayData(output) || isDisplayUpdate(output)) {
9
+ bundle = output.data;
10
+ } else if (isStream(output)) {
11
+ if (output.name === 'stderr') {
12
+ bundle['application/vnd.jupyter.stderr'] = output.text;
13
+ } else {
14
+ bundle['application/vnd.jupyter.stdout'] = output.text;
15
+ }
16
+ } else if (isError(output)) {
17
+ bundle['application/vnd.jupyter.error'] = output;
18
+ var traceback = output.traceback.join('\n');
19
+ bundle['application/vnd.jupyter.stderr'] = traceback || "".concat(output.ename, ": ").concat(output.evalue);
20
+ }
21
+ return convertBundle(bundle);
22
+ }
23
+
24
+ /**
25
+ * Get the metadata from an output message.
26
+ */
27
+ export function getMetadata(output) {
28
+ var value = Object.create(null);
29
+ if (isExecuteResult(output) || isDisplayData(output)) {
30
+ for (var key in output.metadata) {
31
+ value[key] = extract(output.metadata, key);
32
+ }
33
+ }
34
+ return value;
35
+ }
36
+ /**
37
+ * Get the bundle options given output model options.
38
+ */
39
+ export function getBundleOptions(options) {
40
+ var data = getData(options);
41
+ var metadata = getMetadata(options);
42
+ return {
43
+ data: data,
44
+ metadata: metadata
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Extract a value from a JSONObject.
50
+ */
51
+ export function extract(value, key) {
52
+ var item = value[key];
53
+ if (item === undefined || isPrimitive(item)) {
54
+ return item;
55
+ }
56
+ return JSON.parse(JSON.stringify(item));
57
+ }
58
+
59
+ /**
60
+ * Convert a mime bundle to mime data.
61
+ */
62
+ function convertBundle(bundle) {
63
+ var map = Object.create(null);
64
+ for (var mimeType in bundle) {
65
+ map[mimeType] = extract(bundle, mimeType);
66
+ }
67
+ return map;
68
+ }
@@ -0,0 +1,4 @@
1
+ export * from './stream-output-contribution.js';
2
+ export * from './stream-output-model.js';
3
+ export * from './stream-output-module.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream-output/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./stream-output-contribution.js";
2
+ export * from "./stream-output-model.js";
3
+ export * from "./stream-output-module.js";
@@ -0,0 +1,11 @@
1
+ import type { IOutput } from '@difizen/libro-common';
2
+ import type { IOutputOptions } from '@difizen/libro-core';
3
+ import { OutputContribution } from '@difizen/libro-core';
4
+ import { ViewManager } from '@difizen/mana-app';
5
+ import { StreamOutputModel } from './stream-output-model.js';
6
+ export declare class StreamOutputContribution implements OutputContribution {
7
+ viewManager: ViewManager;
8
+ canHandle: (output: IOutput) => 100 | 1;
9
+ factory(output: IOutputOptions): Promise<StreamOutputModel>;
10
+ }
11
+ //# sourceMappingURL=stream-output-contribution.d.ts.map
@@ -0,0 +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;CAG/B"}
@@ -0,0 +1,40 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _dec2, _class, _class2, _descriptor;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
10
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
11
+ import { OutputContribution } from '@difizen/libro-core';
12
+ import { inject, singleton } from '@difizen/mana-app';
13
+ import { ViewManager } from '@difizen/mana-app';
14
+ import { StreamOutputModel } from "./stream-output-model.js";
15
+ export var StreamOutputContribution = (_dec = singleton({
16
+ contrib: OutputContribution
17
+ }), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
18
+ function StreamOutputContribution() {
19
+ _classCallCheck(this, StreamOutputContribution);
20
+ _initializerDefineProperty(this, "viewManager", _descriptor, this);
21
+ this.canHandle = function (output) {
22
+ if (output.output_type === 'stream') {
23
+ return 100;
24
+ }
25
+ return 1;
26
+ };
27
+ }
28
+ _createClass(StreamOutputContribution, [{
29
+ key: "factory",
30
+ value: function factory(output) {
31
+ return this.viewManager.getOrCreateView(StreamOutputModel, output);
32
+ }
33
+ }]);
34
+ return StreamOutputContribution;
35
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
36
+ configurable: true,
37
+ enumerable: true,
38
+ writable: true,
39
+ initializer: null
40
+ })), _class2)) || _class);
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import { LibroOutputView } from '@difizen/libro-core';
3
+ import type { BaseOutputView, IOutputOptions } from '@difizen/libro-core';
4
+ import '../index.less';
5
+ export declare class StreamOutputModel extends LibroOutputView implements BaseOutputView {
6
+ constructor(options: IOutputOptions);
7
+ view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
8
+ toJSON(): {
9
+ output_type: string;
10
+ name: string | number | boolean | Partial<{
11
+ [key: string]: import("@difizen/libro-common").PartialJSONValue;
12
+ }> | import("@difizen/libro-common").PartialJSONValue[] | null | undefined;
13
+ text: string | number | boolean | Partial<{
14
+ [key: string]: import("@difizen/libro-common").PartialJSONValue;
15
+ }> | import("@difizen/libro-common").PartialJSONValue[] | string[] | null | undefined;
16
+ };
17
+ }
18
+ //# sourceMappingURL=stream-output-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-output-model.d.ts","sourceRoot":"","sources":["../../src/stream-output/stream-output-model.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAa1E,OAAO,eAAe,CAAC;AA0BvB,qBAEa,iBAAkB,SAAQ,eAAgB,YAAW,cAAc;gBAC9C,OAAO,EAAE,cAAc;IAO9C,IAAI,2FAA2B;IAC/B,MAAM;;;;;;;;;CAOhB"}
@@ -0,0 +1,70 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _dec2, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
9
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ import { LibroOutputView } from '@difizen/libro-core';
16
+ import { RenderMimeRegistry } from '@difizen/libro-rendermime';
17
+ import { inject, transient } from '@difizen/mana-app';
18
+ import { getOrigin, useInject, view, ViewInstance, ViewOption } from '@difizen/mana-app';
19
+ import { forwardRef } from 'react';
20
+ import "../index.less";
21
+ import { getBundleOptions } from "../output-utils.js";
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ var StreamOutputModelRender = /*#__PURE__*/forwardRef(function StreamOutputModelRender(_props, ref) {
24
+ var output = useInject(ViewInstance);
25
+ var model = getOrigin(output);
26
+ var defaultRenderMime = useInject(RenderMimeRegistry);
27
+ var defaultRenderMimeType = defaultRenderMime.preferredMimeType(model);
28
+ if (defaultRenderMimeType) {
29
+ var OutputRender = defaultRenderMime.createRenderer(defaultRenderMimeType, model);
30
+ var children = /*#__PURE__*/_jsx(OutputRender, {
31
+ model: model
32
+ });
33
+ return /*#__PURE__*/_jsx("div", {
34
+ ref: ref,
35
+ className: 'libro-stream-container',
36
+ children: children
37
+ });
38
+ } else {
39
+ return null;
40
+ }
41
+ });
42
+ export var StreamOutputModel = (_dec = transient(), _dec2 = view('libro-stream-output-model'), _dec(_class = _dec2(_class = /*#__PURE__*/function (_LibroOutputView) {
43
+ _inherits(StreamOutputModel, _LibroOutputView);
44
+ var _super = _createSuper(StreamOutputModel);
45
+ function StreamOutputModel(options) {
46
+ var _this;
47
+ _classCallCheck(this, StreamOutputModel);
48
+ _this = _super.call(this, options);
49
+ _this.view = StreamOutputModelRender;
50
+ var _getBundleOptions = getBundleOptions(options.output),
51
+ data = _getBundleOptions.data,
52
+ metadata = _getBundleOptions.metadata;
53
+ _this.type = options.output.output_type;
54
+ _this.data = data;
55
+ _this.metadata = metadata;
56
+ return _this;
57
+ }
58
+ StreamOutputModel = inject(ViewOption)(StreamOutputModel, undefined, 0) || StreamOutputModel;
59
+ _createClass(StreamOutputModel, [{
60
+ key: "toJSON",
61
+ value: function toJSON() {
62
+ return {
63
+ output_type: this.raw.output_type,
64
+ name: this.raw.name,
65
+ text: this.raw.text
66
+ };
67
+ }
68
+ }]);
69
+ return StreamOutputModel;
70
+ }(LibroOutputView)) || _class) || _class);
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const StreamOutputModule: ManaModule;
3
+ //# sourceMappingURL=stream-output-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-output-module.d.ts","sourceRoot":"","sources":["../../src/stream-output/stream-output-module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,eAAO,MAAM,kBAAkB,YAEiB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { OutputModule } from '@difizen/libro-core';
2
+ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
3
+ import { ManaModule } from '@difizen/mana-app';
4
+ import { StreamOutputContribution } from "./stream-output-contribution.js";
5
+ import { StreamOutputModel } from "./stream-output-model.js";
6
+ export var StreamOutputModule = ManaModule.create().register(StreamOutputModel, StreamOutputContribution).dependOn(OutputModule, LibroRenderMimeModule);
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@difizen/libro-output",
3
+ "version": "0.0.2-alpha.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro",
7
+ "notebook"
8
+ ],
9
+ "repository": "git@github.com:difizen/libro.git",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "typings": "./es/index.d.ts",
15
+ "default": "./es/index.js"
16
+ },
17
+ "./mock": {
18
+ "typings": "./es/mock/index.d.ts",
19
+ "default": "./es/mock/index.js"
20
+ },
21
+ "./es/mock": {
22
+ "typings": "./es/mock/index.d.ts",
23
+ "default": "./es/mock/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "es/index.js",
28
+ "module": "es/index.js",
29
+ "typings": "es/index.d.ts",
30
+ "files": [
31
+ "es",
32
+ "src"
33
+ ],
34
+ "dependencies": {
35
+ "@difizen/libro-common": "^0.0.2-alpha.0",
36
+ "@difizen/libro-core": "^0.0.2-alpha.0",
37
+ "@difizen/libro-rendermime": "^0.0.2-alpha.0",
38
+ "@difizen/mana-app": "alpha",
39
+ "markdown-it": "^13.0.1"
40
+ },
41
+ "peerDependencies": {
42
+ "antd": "^5.8.6",
43
+ "react": "^18.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/react": "^18.2.25",
47
+ "@types/sanitize-html": "^2.6.2"
48
+ },
49
+ "scripts": {
50
+ "setup": "father build",
51
+ "build": "father build",
52
+ "test": ": Note: lint task is delegated to test:* scripts",
53
+ "test:vitest": "vitest run",
54
+ "test:jest": "jest",
55
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
56
+ "coverage:vitest": "vitest run --coverage",
57
+ "coverage:jest": "jest --coverage",
58
+ "lint": ": Note: lint task is delegated to lint:* scripts",
59
+ "lint:eslint": "eslint src",
60
+ "lint:tsc": "tsc --noEmit"
61
+ }
62
+ }
@@ -0,0 +1,24 @@
1
+ import type { IOutput } from '@difizen/libro-common';
2
+ import type { IOutputOptions } from '@difizen/libro-core';
3
+ import { OutputContribution } from '@difizen/libro-core';
4
+ import { inject, singleton } from '@difizen/mana-app';
5
+ import { ViewManager } from '@difizen/mana-app';
6
+
7
+ import { DisplayDataOutputModel } from './display-data-output-model.js';
8
+
9
+ @singleton({ contrib: OutputContribution })
10
+ export class DisplayDataOutputContribution implements OutputContribution {
11
+ @inject(ViewManager) viewManager: ViewManager;
12
+ canHandle = (output: IOutput) => {
13
+ if (
14
+ output.output_type === 'display_data' ||
15
+ output.output_type === 'execute_result'
16
+ ) {
17
+ return 100;
18
+ }
19
+ return 1;
20
+ };
21
+ factory(output: IOutputOptions) {
22
+ return this.viewManager.getOrCreateView(DisplayDataOutputModel, output);
23
+ }
24
+ }
@@ -0,0 +1,67 @@
1
+ import type { JSONObject } from '@difizen/libro-common';
2
+ import { LibroOutputView } from '@difizen/libro-core';
3
+ import type { BaseOutputView, IOutputOptions } from '@difizen/libro-core';
4
+ import { RenderMimeRegistry } from '@difizen/libro-rendermime';
5
+ import type { IRenderMimeRegistry } from '@difizen/libro-rendermime';
6
+ import {
7
+ getOrigin,
8
+ useInject,
9
+ view,
10
+ ViewInstance,
11
+ ViewOption,
12
+ } from '@difizen/mana-app';
13
+ import { inject, transient } from '@difizen/mana-app';
14
+ import { forwardRef } from 'react';
15
+
16
+ import { getBundleOptions } from '../output-utils.js';
17
+ import '../index.less';
18
+
19
+ const DisplayDataOutputModelRender = forwardRef<HTMLDivElement>(
20
+ function DisplayDataOutputModelRender(_props, ref) {
21
+ const output = useInject<DisplayDataOutputModel>(ViewInstance);
22
+ const defaultRenderMime = useInject<IRenderMimeRegistry>(RenderMimeRegistry);
23
+
24
+ const model = getOrigin(output);
25
+ const defaultRenderMimeType = defaultRenderMime.preferredMimeType(model);
26
+ let children = null;
27
+ if (defaultRenderMimeType) {
28
+ const OutputRender = defaultRenderMime.createRenderer(
29
+ defaultRenderMimeType,
30
+ model,
31
+ );
32
+ children = <OutputRender model={model} />;
33
+ }
34
+ return (
35
+ <div ref={ref} className={'libro-display-data-container'}>
36
+ {children}
37
+ </div>
38
+ );
39
+ },
40
+ );
41
+ @transient()
42
+ @view('libro-display-data-output-model')
43
+ export class DisplayDataOutputModel extends LibroOutputView implements BaseOutputView {
44
+ constructor(@inject(ViewOption) options: IOutputOptions) {
45
+ super(options);
46
+ const { data, metadata } = getBundleOptions(options.output);
47
+ this.type = options.output.output_type;
48
+ this.data = data as JSONObject;
49
+ this.metadata = metadata;
50
+ }
51
+ override view = DisplayDataOutputModelRender;
52
+ override toJSON() {
53
+ if (this.raw.execution_count !== undefined) {
54
+ return {
55
+ output_type: this.raw.output_type,
56
+ data: this.raw.data,
57
+ metadata: this.raw.metadata,
58
+ execution_count: this.raw.execution_count,
59
+ };
60
+ }
61
+ return {
62
+ output_type: this.raw.output_type,
63
+ data: this.raw.data,
64
+ metadata: this.raw.metadata,
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,10 @@
1
+ import { OutputModule } from '@difizen/libro-core';
2
+ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
3
+ import { ManaModule } from '@difizen/mana-app';
4
+
5
+ import { DisplayDataOutputContribution } from './display-data-output-contribution.js';
6
+ import { DisplayDataOutputModel } from './display-data-output-model.js';
7
+
8
+ export const DisplayDataOutputModule = ManaModule.create()
9
+ .register(DisplayDataOutputModel, DisplayDataOutputContribution)
10
+ .dependOn(OutputModule, LibroRenderMimeModule);
@@ -0,0 +1,3 @@
1
+ export * from './display-data-output-contribution.js';
2
+ export * from './display-data-output-model.js';
3
+ export * from './display-data-output-module.js';
@@ -0,0 +1,21 @@
1
+ import type { IOutput } from '@difizen/libro-common';
2
+ import type { IOutputOptions } from '@difizen/libro-core';
3
+ import { OutputContribution } from '@difizen/libro-core';
4
+ import { inject, singleton } from '@difizen/mana-app';
5
+ import { ViewManager } from '@difizen/mana-app';
6
+
7
+ import { ErrorOutputModel } from './error-output-model.js';
8
+
9
+ @singleton({ contrib: OutputContribution })
10
+ export class ErrorOutputContribution implements OutputContribution {
11
+ @inject(ViewManager) viewManager: ViewManager;
12
+ canHandle = (output: IOutput) => {
13
+ if (output.output_type === 'error') {
14
+ return 100;
15
+ }
16
+ return 1;
17
+ };
18
+ factory(output: IOutputOptions) {
19
+ return this.viewManager.getOrCreateView(ErrorOutputModel, output);
20
+ }
21
+ }
@@ -0,0 +1,94 @@
1
+ import { defaultSanitizer } from '@difizen/libro-common';
2
+ import type { IError, JSONObject } from '@difizen/libro-common';
3
+ import { LibroOutputView } from '@difizen/libro-core';
4
+ import type { BaseOutputView, IOutputOptions } from '@difizen/libro-core';
5
+ import { RenderMimeRegistry, renderText } from '@difizen/libro-rendermime';
6
+ import type { IRenderMimeRegistry } from '@difizen/libro-rendermime';
7
+ import { inject, transient } from '@difizen/mana-app';
8
+ import {
9
+ getOrigin,
10
+ prop,
11
+ useInject,
12
+ view,
13
+ ViewInstance,
14
+ ViewOption,
15
+ } from '@difizen/mana-app';
16
+ import { Button } from 'antd';
17
+ import { forwardRef, createRef, useEffect } from 'react';
18
+ import '../index.less';
19
+
20
+ import { getBundleOptions } from '../output-utils.js';
21
+
22
+ const ErrorOutputModelRender = forwardRef<HTMLDivElement>(
23
+ function ErrorOutputModelRender(_props, ref) {
24
+ const output = useInject<ErrorOutputModel>(ViewInstance);
25
+ const model = getOrigin(output);
26
+ const source = getOrigin(output).raw as IError;
27
+ const defaultRenderMime = useInject<IRenderMimeRegistry>(RenderMimeRegistry);
28
+ const traceback = source.traceback.join('\n');
29
+ const defaultRenderMimeType = defaultRenderMime.preferredMimeType(model);
30
+ const streamRef = createRef<HTMLDivElement>();
31
+
32
+ useEffect(() => {
33
+ renderText({
34
+ host: streamRef.current as HTMLDivElement,
35
+ sanitizer: defaultSanitizer,
36
+ source: traceback,
37
+ mimeType: defaultRenderMimeType || '',
38
+ });
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, []);
41
+ const handleShowErrorDetail = () => {
42
+ output.showErrorDetail = !output.showErrorDetail;
43
+ };
44
+
45
+ return (
46
+ <div ref={ref} className="libro-error-container">
47
+ <div className="libro-text-render-container">
48
+ <div className="libro-error-label libro-text-render">
49
+ <pre>
50
+ <span className="ansi-red-fg">{source.ename}</span>
51
+ {': ' + source.evalue}
52
+ </pre>
53
+ <Button
54
+ className="libro-show-error-detail-button"
55
+ danger
56
+ onClick={handleShowErrorDetail}
57
+ >
58
+ {output.showErrorDetail ? 'Hide' : 'Show'} error details
59
+ </Button>
60
+ </div>
61
+ </div>
62
+ <div className="libro-text-render-container">
63
+ <div
64
+ className="libro-text-render"
65
+ ref={streamRef}
66
+ style={{ display: `${output.showErrorDetail ? 'block' : 'none'} ` }}
67
+ />
68
+ </div>
69
+ </div>
70
+ );
71
+ },
72
+ );
73
+ @transient()
74
+ @view('libro-error-output-model')
75
+ export class ErrorOutputModel extends LibroOutputView implements BaseOutputView {
76
+ constructor(@inject(ViewOption) options: IOutputOptions) {
77
+ super(options);
78
+ const { data, metadata } = getBundleOptions(options.output);
79
+ this.type = options.output.output_type;
80
+ this.data = data as JSONObject;
81
+ this.metadata = metadata;
82
+ }
83
+ override view = ErrorOutputModelRender;
84
+ override toJSON() {
85
+ return {
86
+ output_type: this.raw.output_type,
87
+ ename: this.raw.ename,
88
+ evalue: this.raw.evalue,
89
+ traceback: this.raw.traceback,
90
+ };
91
+ }
92
+ @prop()
93
+ showErrorDetail = false;
94
+ }
@@ -0,0 +1,10 @@
1
+ import { OutputModule } from '@difizen/libro-core';
2
+ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
3
+ import { ManaModule } from '@difizen/mana-app';
4
+
5
+ import { ErrorOutputContribution } from './error-output-contribution.js';
6
+ import { ErrorOutputModel } from './error-output-model.js';
7
+
8
+ export const ErrorOutputModule = ManaModule.create()
9
+ .register(ErrorOutputModel, ErrorOutputContribution)
10
+ .dependOn(OutputModule, LibroRenderMimeModule);
@@ -0,0 +1,3 @@
1
+ export * from './error-output-contribution.js';
2
+ export * from './error-output-model.js';
3
+ export * from './error-output-module.js';