@difizen/libro-widget 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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/base/comm.d.ts +65 -0
  4. package/es/base/comm.d.ts.map +1 -0
  5. package/es/base/comm.js +151 -0
  6. package/es/base/index.d.ts +7 -0
  7. package/es/base/index.d.ts.map +1 -0
  8. package/es/base/index.js +6 -0
  9. package/es/base/libro-widgets.d.ts +79 -0
  10. package/es/base/libro-widgets.d.ts.map +1 -0
  11. package/es/base/libro-widgets.js +285 -0
  12. package/es/base/protocal.d.ts +171 -0
  13. package/es/base/protocal.d.ts.map +1 -0
  14. package/es/base/protocal.js +21 -0
  15. package/es/base/utils.d.ts +27 -0
  16. package/es/base/utils.d.ts.map +1 -0
  17. package/es/base/utils.js +59 -0
  18. package/es/base/version.d.ts +3 -0
  19. package/es/base/version.d.ts.map +1 -0
  20. package/es/base/version.js +2 -0
  21. package/es/base/widget-manager.d.ts +18 -0
  22. package/es/base/widget-manager.d.ts.map +1 -0
  23. package/es/base/widget-manager.js +68 -0
  24. package/es/base/widget-view-contribution.d.ts +10 -0
  25. package/es/base/widget-view-contribution.d.ts.map +1 -0
  26. package/es/base/widget-view-contribution.js +36 -0
  27. package/es/base/widget-view.d.ts +52 -0
  28. package/es/base/widget-view.d.ts.map +1 -0
  29. package/es/base/widget-view.js +137 -0
  30. package/es/components/index.d.ts +3 -0
  31. package/es/components/index.d.ts.map +1 -0
  32. package/es/components/index.js +2 -0
  33. package/es/components/progressBar.d.ts +15 -0
  34. package/es/components/progressBar.d.ts.map +1 -0
  35. package/es/components/progressBar.js +20 -0
  36. package/es/components/progressCircle.d.ts +11 -0
  37. package/es/components/progressCircle.d.ts.map +1 -0
  38. package/es/components/progressCircle.js +16 -0
  39. package/es/index.d.ts +5 -0
  40. package/es/index.d.ts.map +1 -0
  41. package/es/index.js +4 -0
  42. package/es/widget-module.d.ts +3 -0
  43. package/es/widget-module.d.ts.map +1 -0
  44. package/es/widget-module.js +39 -0
  45. package/es/widgets/hbox-widget-view-contribution.d.ts +10 -0
  46. package/es/widgets/hbox-widget-view-contribution.d.ts.map +1 -0
  47. package/es/widgets/hbox-widget-view-contribution.js +39 -0
  48. package/es/widgets/hbox-widget-view.d.ts +17 -0
  49. package/es/widgets/hbox-widget-view.d.ts.map +1 -0
  50. package/es/widgets/hbox-widget-view.js +69 -0
  51. package/es/widgets/index.d.ts +9 -0
  52. package/es/widgets/index.d.ts.map +1 -0
  53. package/es/widgets/index.js +8 -0
  54. package/es/widgets/index.less +3 -0
  55. package/es/widgets/instances-progress-widget-view-contribution.d.ts +10 -0
  56. package/es/widgets/instances-progress-widget-view-contribution.d.ts.map +1 -0
  57. package/es/widgets/instances-progress-widget-view-contribution.js +39 -0
  58. package/es/widgets/instances-progress-widget-view.d.ts +31 -0
  59. package/es/widgets/instances-progress-widget-view.d.ts.map +1 -0
  60. package/es/widgets/instances-progress-widget-view.js +181 -0
  61. package/es/widgets/progress-widget-view-contribution.d.ts +10 -0
  62. package/es/widgets/progress-widget-view-contribution.d.ts.map +1 -0
  63. package/es/widgets/progress-widget-view-contribution.js +39 -0
  64. package/es/widgets/progress-widget-view.d.ts +25 -0
  65. package/es/widgets/progress-widget-view.d.ts.map +1 -0
  66. package/es/widgets/progress-widget-view.js +103 -0
  67. package/es/widgets/text-widget-view-contribution.d.ts +10 -0
  68. package/es/widgets/text-widget-view-contribution.d.ts.map +1 -0
  69. package/es/widgets/text-widget-view-contribution.js +39 -0
  70. package/es/widgets/text-widget-view.d.ts +19 -0
  71. package/es/widgets/text-widget-view.d.ts.map +1 -0
  72. package/es/widgets/text-widget-view.js +91 -0
  73. package/package.json +60 -0
  74. package/src/base/comm.ts +152 -0
  75. package/src/base/index.ts +6 -0
  76. package/src/base/libro-widgets.ts +207 -0
  77. package/src/base/protocal.ts +218 -0
  78. package/src/base/utils.ts +67 -0
  79. package/src/base/version.ts +2 -0
  80. package/src/base/widget-manager.ts +41 -0
  81. package/src/base/widget-view-contribution.ts +14 -0
  82. package/src/base/widget-view.tsx +146 -0
  83. package/src/components/index.ts +3 -0
  84. package/src/components/progressBar.tsx +29 -0
  85. package/src/components/progressCircle.tsx +18 -0
  86. package/src/index.ts +4 -0
  87. package/src/widget-module.ts +68 -0
  88. package/src/widgets/hbox-widget-view-contribution.ts +20 -0
  89. package/src/widgets/hbox-widget-view.tsx +64 -0
  90. package/src/widgets/index.less +3 -0
  91. package/src/widgets/index.ts +8 -0
  92. package/src/widgets/instances-progress-widget-view-contribution.ts +20 -0
  93. package/src/widgets/instances-progress-widget-view.tsx +160 -0
  94. package/src/widgets/progress-widget-view-contribution.ts +24 -0
  95. package/src/widgets/progress-widget-view.tsx +85 -0
  96. package/src/widgets/text-widget-view-contribution.ts +20 -0
  97. package/src/widgets/text-widget-view.tsx +83 -0
@@ -0,0 +1,171 @@
1
+ import type { JSONObject, JSONValue } from '@difizen/libro-common';
2
+ import type { IComm, IKernelConnection, KernelMessage } from '@difizen/libro-kernel';
3
+ import { Syringe } from '@difizen/mana-app';
4
+ import type { WidgetView } from './widget-view.js';
5
+ export interface IWidgetViewOptions {
6
+ model_id: string;
7
+ comm: IClassicComm;
8
+ }
9
+ export interface IWidgetViewProps {
10
+ attributes: any;
11
+ options: IWidgetViewOptions;
12
+ }
13
+ /**
14
+ * A simple dictionary type.
15
+ */
16
+ export type Dict<T> = Record<string, T>;
17
+ export type BufferJSON = {
18
+ [property: string]: BufferJSON;
19
+ } | BufferJSON[] | string | number | boolean | null | ArrayBuffer | DataView;
20
+ export interface ISerializedState {
21
+ state: JSONObject;
22
+ buffers: ArrayBuffer[];
23
+ buffer_paths: (string | number)[][];
24
+ }
25
+ /**
26
+ * The widget manager interface exposed on the Widget instances
27
+ */
28
+ export interface IWidgets {
29
+ getModel: (model_id: string) => WidgetView;
30
+ /**
31
+ * Returns true if the given model is registered, otherwise false.
32
+ *
33
+ * #### Notes
34
+ * This is a synchronous way to check if a model is registered.
35
+ */
36
+ hasModel: (model_id: string) => boolean;
37
+ /**
38
+ * Register a model instance promise with the manager.
39
+ *
40
+ * By registering the model, it can later be retrieved with `getModel`.
41
+ */
42
+ registerWidgetView: (model_id: string, model: Promise<WidgetView>) => void;
43
+ newWidgetView: (attributes: any, options: IWidgetViewOptions) => Promise<WidgetView>;
44
+ }
45
+ export declare const LibroWidgetsFactory: unique symbol;
46
+ export type LibroWidgetsFactory = (options: WidgetsOption) => IWidgets;
47
+ export declare const WidgetsOption: unique symbol;
48
+ export interface WidgetsOption {
49
+ kc: IKernelConnection;
50
+ id: string;
51
+ }
52
+ export interface IWidgetView {
53
+ initialize: (props: IWidgetViewProps) => void;
54
+ toJSON: () => string;
55
+ set_state: (state: Dict<unknown>) => void;
56
+ handleCommMsg: (msg: KernelMessage.ICommMsgMsg) => Promise<void>;
57
+ model_id: string;
58
+ name: string;
59
+ module: string;
60
+ model_module: string;
61
+ model_name: string;
62
+ model_module_version: string;
63
+ view_module: string;
64
+ view_name: string | null;
65
+ view_module_version: string;
66
+ view_count: number | null;
67
+ }
68
+ export declare const IWidgetView: unique symbol;
69
+ export declare const WidgetViewContribution: Syringe.DefinedToken;
70
+ export interface WidgetViewContribution {
71
+ canHandle: (attributes: any) => number;
72
+ factory: (props: IWidgetViewProps) => Promise<WidgetView>;
73
+ }
74
+ export interface InstanceRecord {
75
+ startDate: number;
76
+ endDate: number;
77
+ }
78
+ interface Stage {
79
+ name: string;
80
+ backup_workers: number;
81
+ terminated_workers: number;
82
+ running_workers: number;
83
+ total_workers: number;
84
+ input_records: number;
85
+ output_records: number;
86
+ finished_percentage: number;
87
+ }
88
+ export interface Task {
89
+ name: string;
90
+ status: 'WAITING' | 'RUNNING' | 'SUCCESS' | 'FAILED' | 'SUSPENDED' | 'CANCELLED';
91
+ stages: Stage[];
92
+ }
93
+ export interface ProgressInstance {
94
+ id: string;
95
+ status: 'Running' | 'Suspended' | 'Terminated';
96
+ logview: string;
97
+ tasks: Task[];
98
+ }
99
+ export interface ProgressItem {
100
+ name: string;
101
+ key: string;
102
+ gen_time: string;
103
+ logView: string;
104
+ instances?: ProgressInstance[];
105
+ }
106
+ export type InstancesRecords = Record<string, InstanceRecord>;
107
+ /**
108
+ * Callbacks for services shim comms.
109
+ */
110
+ export interface ICallbacks {
111
+ shell?: Record<string, (msg: KernelMessage.IShellMessage) => void>;
112
+ iopub?: Record<string, (msg: KernelMessage.IIOPubMessage) => void>;
113
+ input?: (msg: KernelMessage.IStdinMessage) => void;
114
+ }
115
+ export declare const LibroWidgetCommFactory: unique symbol;
116
+ export type LibroWidgetCommFactory = (options: WidgetCommOption) => IClassicComm;
117
+ export declare const WidgetCommOption: unique symbol;
118
+ export interface WidgetCommOption {
119
+ comm: IComm;
120
+ }
121
+ export interface IClassicComm {
122
+ /**
123
+ * Comm id
124
+ * @return {string}
125
+ */
126
+ comm_id: string;
127
+ /**
128
+ * Target name
129
+ * @return {string}
130
+ */
131
+ target_name: string;
132
+ /**
133
+ * Opens a sibling comm in the backend
134
+ * @param data
135
+ * @param callbacks
136
+ * @param metadata
137
+ * @param buffers
138
+ * @return msg id
139
+ */
140
+ open(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
141
+ /**
142
+ * Sends a message to the sibling comm in the backend
143
+ * @param data
144
+ * @param callbacks
145
+ * @param metadata
146
+ * @param buffers
147
+ * @return message id
148
+ */
149
+ send(data: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
150
+ /**
151
+ * Closes the sibling comm in the backend
152
+ * @param data
153
+ * @param callbacks
154
+ * @param metadata
155
+ * @param buffers
156
+ * @return msg id
157
+ */
158
+ close(data?: JSONValue, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
159
+ /**
160
+ * Register a message handler
161
+ * @param callback, which is given a message
162
+ */
163
+ on_msg(callback: (x: any) => void): void;
164
+ /**
165
+ * Register a handler for when the comm is closed by the backend
166
+ * @param callback, which is given a message
167
+ */
168
+ on_close(callback: (x: any) => void): void;
169
+ }
170
+ export {};
171
+ //# sourceMappingURL=protocal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocal.d.ts","sourceRoot":"","sources":["../../src/base/protocal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,EAAE,kBAAkB,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAExC,MAAM,MAAM,UAAU,GAClB;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,GAClC,UAAU,EAAE,GACZ,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,YAAY,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,CAAC,QAAQ,EAAE,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IAEV;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;IAEzC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5C"}
@@ -0,0 +1,21 @@
1
+ import { Syringe } from '@difizen/mana-app';
2
+
3
+ /**
4
+ * A simple dictionary type.
5
+ */
6
+
7
+ /**
8
+ * The widget manager interface exposed on the Widget instances
9
+ */
10
+
11
+ export var LibroWidgetsFactory = Symbol('LibroWidgetsFactory');
12
+ export var WidgetsOption = Symbol('WidgetsOption');
13
+ export var IWidgetView = Symbol('IWidgetView');
14
+ export var WidgetViewContribution = Syringe.defineToken('WidgetViewContribution');
15
+
16
+ /**
17
+ * Callbacks for services shim comms.
18
+ */
19
+
20
+ export var LibroWidgetCommFactory = Symbol('LibroWidgetCommFactory');
21
+ export var WidgetCommOption = Symbol('WidgetCommOption');
@@ -0,0 +1,27 @@
1
+ import type { BufferJSON, Dict } from './protocal.js';
2
+ /**
3
+ * Takes an object 'state' and fills in buffer[i] at 'path' buffer_paths[i]
4
+ * where buffer_paths[i] is a list indicating where in the object buffer[i] should
5
+ * be placed
6
+ * Example: state = {a: 1, b: {}, c: [0, null]}
7
+ * buffers = [array1, array2]
8
+ * buffer_paths = [['b', 'data'], ['c', 1]]
9
+ * Will lead to {a: 1, b: {data: array1}, c: [0, array2]}
10
+ */
11
+ export declare function put_buffers(state: Dict<BufferJSON>, buffer_paths: (string | number)[][], buffers: (DataView | ArrayBuffer | ArrayBufferView | {
12
+ buffer: ArrayBuffer;
13
+ })[]): void;
14
+ /**
15
+ * Creates a wrappable Promise rejection function.
16
+ *
17
+ * Creates a function that logs an error message before rethrowing
18
+ * the original error that caused the promise to reject.
19
+ */
20
+ export declare function reject(message: string, log: boolean): (error: Error) => never;
21
+ /**
22
+ * A polyfill for Object.assign
23
+ *
24
+ * This is from code that Typescript 2.4 generates for a polyfill.
25
+ */
26
+ export declare const assign: any;
27
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EACvB,YAAY,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,EACnC,OAAO,EAAE,CAAC,QAAQ,GAAG,WAAW,GAAG,eAAe,GAAG;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,EAAE,GAC9E,IAAI,CAiBN;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,WACV,KAAK,KAAG,KAAK,CAMtD;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,KAYhB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Takes an object 'state' and fills in buffer[i] at 'path' buffer_paths[i]
3
+ * where buffer_paths[i] is a list indicating where in the object buffer[i] should
4
+ * be placed
5
+ * Example: state = {a: 1, b: {}, c: [0, null]}
6
+ * buffers = [array1, array2]
7
+ * buffer_paths = [['b', 'data'], ['c', 1]]
8
+ * Will lead to {a: 1, b: {data: array1}, c: [0, array2]}
9
+ */
10
+ export function put_buffers(state, buffer_paths, buffers) {
11
+ for (var i = 0; i < buffer_paths.length; i++) {
12
+ var buffer_path = buffer_paths[i];
13
+ // make sure the buffers are DataViews
14
+ var buffer = buffers[i];
15
+ if (!(buffer instanceof DataView)) {
16
+ buffer = new DataView(buffer instanceof ArrayBuffer ? buffer : buffer.buffer);
17
+ }
18
+ // say we want to set state[x][y][z] = buffer
19
+ var obj = state;
20
+ // we first get obj = state[x][y]
21
+ for (var j = 0; j < buffer_path.length - 1; j++) {
22
+ obj = obj[buffer_path[j]];
23
+ }
24
+ // and then set: obj[z] = buffer
25
+ obj[buffer_path[buffer_path.length - 1]] = buffer;
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Creates a wrappable Promise rejection function.
31
+ *
32
+ * Creates a function that logs an error message before rethrowing
33
+ * the original error that caused the promise to reject.
34
+ */
35
+ export function reject(message, log) {
36
+ return function promiseRejection(error) {
37
+ if (log) {
38
+ console.error(new Error(message));
39
+ }
40
+ throw error;
41
+ };
42
+ }
43
+
44
+ /**
45
+ * A polyfill for Object.assign
46
+ *
47
+ * This is from code that Typescript 2.4 generates for a polyfill.
48
+ */
49
+ export var assign = Object.assign || function (t) {
50
+ for (var i = 1; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
51
+ var s = i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1];
52
+ for (var p in s) {
53
+ if (Object.prototype.hasOwnProperty.call(s, p)) {
54
+ t[p] = s[p];
55
+ }
56
+ }
57
+ }
58
+ return t;
59
+ };
@@ -0,0 +1,3 @@
1
+ export declare const LIBRO_WIDGETS_VERSION = "2.0.0";
2
+ export declare const PROTOCOL_VERSION = "2.1.0";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/base/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAC7C,eAAO,MAAM,gBAAgB,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export var LIBRO_WIDGETS_VERSION = '2.0.0';
2
+ export var PROTOCOL_VERSION = '2.1.0';
@@ -0,0 +1,18 @@
1
+ import { LibroService } from '@difizen/libro-core';
2
+ import type { IKernelConnection } from '@difizen/libro-kernel';
3
+ import { LibroKernelManager } from '@difizen/libro-kernel';
4
+ import { ApplicationContribution } from '@difizen/mana-app';
5
+ import type { LibroWidgets } from './libro-widgets.js';
6
+ import type { WidgetsOption } from './protocal.js';
7
+ export declare class LibroWidgetManager implements ApplicationContribution {
8
+ widgetsFactory: (options: WidgetsOption) => LibroWidgets;
9
+ kernelManager: LibroKernelManager;
10
+ libroService: LibroService;
11
+ initialize: () => void;
12
+ getOrCreateWidgets: (kc: IKernelConnection) => LibroWidgets;
13
+ /**
14
+ * Dictionary of model ids and model instance promises
15
+ */
16
+ private widgets;
17
+ }
18
+ //# sourceMappingURL=widget-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-manager.d.ts","sourceRoot":"","sources":["../../src/base/widget-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAoB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAA2B,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAErF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,qBACa,kBAAmB,YAAW,uBAAuB;IACnC,cAAc,EAAG,CAC5C,OAAO,EAAE,aAAa,KACnB,YAAY,CAAC;IACU,aAAa,EAAE,kBAAkB,CAAC;IACxC,YAAY,EAAE,YAAY,CAAC;IAEjD,UAAU,aAMR;IAEF,kBAAkB,OAAQ,iBAAiB,kBAQzC;IAEF;;OAEG;IAEH,OAAO,CAAC,OAAO,CAAwC;CACxD"}
@@ -0,0 +1,68 @@
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, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
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 _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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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 { LibroService } from '@difizen/libro-core';
12
+ import { KernelConnection, LibroKernelManager } from '@difizen/libro-kernel';
13
+ import { inject, prop, singleton, ApplicationContribution } from '@difizen/mana-app';
14
+ import { LibroWidgetsFactory } from "./protocal.js";
15
+ export var LibroWidgetManager = (_dec = singleton({
16
+ contrib: ApplicationContribution
17
+ }), _dec2 = inject(LibroWidgetsFactory), _dec3 = inject(LibroKernelManager), _dec4 = inject(LibroService), _dec5 = prop(), _dec(_class = (_class2 = /*#__PURE__*/_createClass(function LibroWidgetManager() {
18
+ var _this = this;
19
+ _classCallCheck(this, LibroWidgetManager);
20
+ _initializerDefineProperty(this, "widgetsFactory", _descriptor, this);
21
+ _initializerDefineProperty(this, "kernelManager", _descriptor2, this);
22
+ _initializerDefineProperty(this, "libroService", _descriptor3, this);
23
+ this.initialize = function () {
24
+ _this.kernelManager.onConnectToKernel(function (kc) {
25
+ if (kc instanceof KernelConnection) {
26
+ _this.getOrCreateWidgets(kc);
27
+ }
28
+ });
29
+ };
30
+ this.getOrCreateWidgets = function (kc) {
31
+ var widgets = _this.widgets.get(kc.id);
32
+ if (widgets) {
33
+ return widgets;
34
+ }
35
+ var newWidgets = _this.widgetsFactory({
36
+ kc: kc,
37
+ id: kc.id
38
+ });
39
+ _this.widgets.set(kc.id, newWidgets);
40
+ return newWidgets;
41
+ };
42
+ /**
43
+ * Dictionary of model ids and model instance promises
44
+ */
45
+ _initializerDefineProperty(this, "widgets", _descriptor4, this);
46
+ }), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "widgetsFactory", [_dec2], {
47
+ configurable: true,
48
+ enumerable: true,
49
+ writable: true,
50
+ initializer: null
51
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "kernelManager", [_dec3], {
52
+ configurable: true,
53
+ enumerable: true,
54
+ writable: true,
55
+ initializer: null
56
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "libroService", [_dec4], {
57
+ configurable: true,
58
+ enumerable: true,
59
+ writable: true,
60
+ initializer: null
61
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "widgets", [_dec5], {
62
+ configurable: true,
63
+ enumerable: true,
64
+ writable: true,
65
+ initializer: function initializer() {
66
+ return new Map();
67
+ }
68
+ })), _class2)) || _class);
@@ -0,0 +1,10 @@
1
+ import { ViewManager } from '@difizen/mana-app';
2
+ import type { IWidgetViewProps } from './protocal.js';
3
+ import { WidgetViewContribution } from './protocal.js';
4
+ import { WidgetView } from './widget-view.js';
5
+ export declare class DefaultWidgetViewContribution implements WidgetViewContribution {
6
+ viewManager: ViewManager;
7
+ canHandle: () => number;
8
+ factory(props: IWidgetViewProps): Promise<WidgetView>;
9
+ }
10
+ //# sourceMappingURL=widget-view-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-view-contribution.d.ts","sourceRoot":"","sources":["../../src/base/widget-view-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBACa,6BAA8B,YAAW,sBAAsB;IACrD,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,eAAW;IACpB,OAAO,CAAC,KAAK,EAAE,gBAAgB;CAGhC"}
@@ -0,0 +1,36 @@
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 { ViewManager, inject, singleton } from '@difizen/mana-app';
12
+ import { WidgetViewContribution } from "./protocal.js";
13
+ import { WidgetView } from "./widget-view.js";
14
+ export var DefaultWidgetViewContribution = (_dec = singleton({
15
+ contrib: WidgetViewContribution
16
+ }), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
17
+ function DefaultWidgetViewContribution() {
18
+ _classCallCheck(this, DefaultWidgetViewContribution);
19
+ _initializerDefineProperty(this, "viewManager", _descriptor, this);
20
+ this.canHandle = function () {
21
+ return 1;
22
+ };
23
+ }
24
+ _createClass(DefaultWidgetViewContribution, [{
25
+ key: "factory",
26
+ value: function factory(props) {
27
+ return this.viewManager.getOrCreateView(WidgetView, props);
28
+ }
29
+ }]);
30
+ return DefaultWidgetViewContribution;
31
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
32
+ configurable: true,
33
+ enumerable: true,
34
+ writable: true,
35
+ initializer: null
36
+ })), _class2)) || _class);
@@ -0,0 +1,52 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type { JSONValue } from '@difizen/libro-common';
3
+ import { LirboContextKey } from '@difizen/libro-core';
4
+ import type { KernelMessage } from '@difizen/libro-kernel';
5
+ import { BaseView } from '@difizen/mana-app';
6
+ import type { ViewComponent } from '@difizen/mana-app';
7
+ import type { IWidgetViewProps } from './protocal.js';
8
+ import type { Dict, IWidgets, IWidgetView, IClassicComm, ICallbacks } from './protocal.js';
9
+ export declare const LibroWidgetComponent: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
10
+ export declare class WidgetView extends BaseView implements IWidgetView {
11
+ view: ViewComponent;
12
+ lirboContextKey: LirboContextKey;
13
+ disableCommandMode: boolean;
14
+ constructor(props: IWidgetViewProps, lirboContextKey: LirboContextKey);
15
+ onViewMount(): void;
16
+ initialize(props: IWidgetViewProps): void;
17
+ /**
18
+ * Handle incoming comm msg.
19
+ */
20
+ handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void>;
21
+ handleCommClosed: () => void;
22
+ /**
23
+ * Handle when a widget is updated from the backend.
24
+ *
25
+ * This function is meant for internal use only. Values set here will not be propagated on a sync.
26
+ */
27
+ set_state(state: Dict<unknown>): void;
28
+ /**
29
+ * Serialize the model. See the deserialization function at the top of this file
30
+ * and the kernel-side serializer/deserializer.
31
+ */
32
+ toJSON(): string;
33
+ /**
34
+ * Send a custom msg over the comm.
35
+ */
36
+ send: (data: JSONValue, callbacks?: ICallbacks, buffers?: ArrayBuffer[] | ArrayBufferView[]) => void;
37
+ comm: IClassicComm;
38
+ libroWidgets: IWidgets;
39
+ model_id: string;
40
+ state_change: Promise<any>;
41
+ name: string;
42
+ module: string;
43
+ isCommClosed: boolean;
44
+ model_module: string;
45
+ model_name: string;
46
+ model_module_version: string;
47
+ view_module: string;
48
+ view_name: string | null;
49
+ view_module_version: string;
50
+ view_count: number | null;
51
+ }
52
+ //# sourceMappingURL=widget-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-view.d.ts","sourceRoot":"","sources":["../../src/base/widget-view.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAuC,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAEV,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACX,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,oBAAoB,0FAIhC,CAAC;AAEF,qBAEa,UAAW,SAAQ,QAAS,YAAW,WAAW;IACpD,IAAI,EAAE,aAAa,CAAwB;IACpD,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,UAAQ;gBAEJ,KAAK,EAAE,gBAAgB,EAClB,eAAe,EAAE,eAAe;IAOlD,WAAW;IAepB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IA2BzC;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5D,gBAAgB,aAEd;IACF;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI;IAIrC;;;OAGG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,IAAI,SACI,SAAS,cACH,UAAU,YACZ,WAAW,EAAE,GAAG,eAAe,EAAE,UAK3C;IAEF,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,EAAE,QAAQ,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,UAAS;IAErB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
@@ -0,0 +1,137 @@
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 { LirboContextKey } from '@difizen/libro-core';
16
+ import { inject, transient, ViewOption, view, BaseView } from '@difizen/mana-app';
17
+ import { forwardRef } from 'react';
18
+ import { assign } from "./utils.js";
19
+ import { Fragment as _Fragment } from "react/jsx-runtime";
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ export var LibroWidgetComponent = /*#__PURE__*/forwardRef(function LibroWidgetComponent() {
22
+ return /*#__PURE__*/_jsx(_Fragment, {});
23
+ });
24
+ export var WidgetView = (_dec = transient(), _dec2 = view('libro-widget-view'), _dec(_class = _dec2(_class = /*#__PURE__*/function (_BaseView) {
25
+ _inherits(WidgetView, _BaseView);
26
+ var _super = _createSuper(WidgetView);
27
+ function WidgetView(props, lirboContextKey) {
28
+ var _this;
29
+ _classCallCheck(this, WidgetView);
30
+ _this = _super.call(this);
31
+ _this.view = LibroWidgetComponent;
32
+ _this.disableCommandMode = true;
33
+ _this.handleCommClosed = function () {
34
+ _this.isCommClosed = true;
35
+ };
36
+ /**
37
+ * Send a custom msg over the comm.
38
+ */
39
+ _this.send = function (data, callbacks, buffers) {
40
+ if (_this.comm !== undefined) {
41
+ _this.comm.send(data, callbacks, {}, buffers);
42
+ }
43
+ };
44
+ _this.isCommClosed = false;
45
+ _this.initialize(props);
46
+ _this.lirboContextKey = lirboContextKey;
47
+ return _this;
48
+ }
49
+ WidgetView = inject(LirboContextKey)(WidgetView, undefined, 1) || WidgetView;
50
+ WidgetView = inject(ViewOption)(WidgetView, undefined, 0) || WidgetView;
51
+ _createClass(WidgetView, [{
52
+ key: "onViewMount",
53
+ value: function onViewMount() {
54
+ var _this2 = this;
55
+ if (this.container && this.container.current && this.disableCommandMode) {
56
+ this.container.current.addEventListener('focusin', function () {
57
+ _this2.lirboContextKey.disableCommandMode();
58
+ });
59
+ this.container.current.addEventListener('blur', function (e) {
60
+ var _this2$container, _this2$container$curr;
61
+ if ((_this2$container = _this2.container) !== null && _this2$container !== void 0 && (_this2$container$curr = _this2$container.current) !== null && _this2$container$curr !== void 0 && _this2$container$curr.contains(e.relatedTarget)) {
62
+ _this2.lirboContextKey.disableCommandMode();
63
+ } else {
64
+ _this2.lirboContextKey.enableCommandMode();
65
+ }
66
+ });
67
+ }
68
+ }
69
+ }, {
70
+ key: "initialize",
71
+ value: function initialize(props) {
72
+ this.model_module = props.attributes._model_module;
73
+ this.model_name = props.attributes._model_name;
74
+ this.model_module_version = props.attributes._model_module_version;
75
+ this.view_module = props.attributes._view_module;
76
+ this.view_name = props.attributes._view_name;
77
+ this.view_module_version = props.attributes._view_module_version;
78
+ this.view_count = props.attributes._view_count;
79
+
80
+ // Attributes should be initialized here, since user initialization may depend on it
81
+ // this.libroWidgets = props.options.libroWidgets;
82
+ var comm = props.options.comm;
83
+ if (comm) {
84
+ // Remember comm associated with the model.
85
+ this.comm = comm;
86
+
87
+ // Hook comm messages up to model.
88
+ comm.on_close(this.handleCommClosed.bind(this));
89
+ comm.on_msg(this.handleCommMsg.bind(this));
90
+ } else {
91
+ this.isCommClosed = false;
92
+ }
93
+ this.model_id = props.options.model_id;
94
+ this.state_change = Promise.resolve();
95
+ }
96
+
97
+ /**
98
+ * Handle incoming comm msg.
99
+ */
100
+ }, {
101
+ key: "handleCommMsg",
102
+ value: function handleCommMsg(msg) {
103
+ var data = msg.content.data;
104
+ var method = data.method;
105
+ switch (method) {
106
+ case 'update':
107
+ case 'echo_update':
108
+ // eslint-disable-next-line no-case-declarations
109
+ var state = data.state;
110
+ this.set_state(state);
111
+ }
112
+ return Promise.resolve();
113
+ }
114
+ }, {
115
+ key: "set_state",
116
+ value:
117
+ /**
118
+ * Handle when a widget is updated from the backend.
119
+ *
120
+ * This function is meant for internal use only. Values set here will not be propagated on a sync.
121
+ */
122
+ function set_state(state) {
123
+ assign(this, state);
124
+ }
125
+
126
+ /**
127
+ * Serialize the model. See the deserialization function at the top of this file
128
+ * and the kernel-side serializer/deserializer.
129
+ */
130
+ }, {
131
+ key: "toJSON",
132
+ value: function toJSON() {
133
+ return "IPY_MODEL_".concat(this.model_id);
134
+ }
135
+ }]);
136
+ return WidgetView;
137
+ }(BaseView)) || _class) || _class);