@kemu-io/hs-react 0.2.36 → 0.2.38
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/cjs/WidgetWrapper.d.ts +17 -2
- package/cjs/components/ResizableContainer.d.ts +71 -0
- package/cjs/components/WidgetContainer.d.ts +20 -0
- package/cjs/components/index.d.ts +85 -0
- package/cjs/constants.d.ts +14 -0
- package/cjs/hooks/index.d.ts +712 -0
- package/cjs/hooks/useOnBroadcastEvent.d.ts +569 -0
- package/cjs/hooks/useOnParentEvent.d.ts +562 -0
- package/cjs/hooks/useOnSetOutputsEvent.d.ts +571 -0
- package/cjs/hooks/useReactiveWidgetState.d.ts +46 -0
- package/cjs/hooks/useReactiveWidgetState.js +1 -1
- package/cjs/hooks/useResizableWidgetDimensions.d.ts +39 -0
- package/cjs/hooks/useWidgetState.d.ts +46 -0
- package/cjs/lib/InstanceContext.d.ts +540 -0
- package/cjs/lib/cache.d.ts +14 -0
- package/cjs/lib/globalContext.d.ts +446 -0
- package/cjs/types/context_t.d.ts +444 -0
- package/cjs/types/hooks_t.d.ts +44 -0
- package/cjs/types/widgetUI_t.d.ts +536 -0
- package/mjs/WidgetWrapper.d.ts +17 -2
- package/mjs/components/ResizableContainer.d.ts +71 -0
- package/mjs/components/WidgetContainer.d.ts +20 -0
- package/mjs/components/index.d.ts +85 -0
- package/mjs/constants.d.ts +14 -0
- package/mjs/hooks/index.d.ts +712 -0
- package/mjs/hooks/useOnBroadcastEvent.d.ts +569 -0
- package/mjs/hooks/useOnParentEvent.d.ts +562 -0
- package/mjs/hooks/useOnSetOutputsEvent.d.ts +571 -0
- package/mjs/hooks/useReactiveWidgetState.d.ts +46 -0
- package/mjs/hooks/useReactiveWidgetState.js +1 -1
- package/mjs/hooks/useResizableWidgetDimensions.d.ts +39 -0
- package/mjs/hooks/useWidgetState.d.ts +46 -0
- package/mjs/lib/InstanceContext.d.ts +540 -0
- package/mjs/lib/cache.d.ts +14 -0
- package/mjs/lib/globalContext.d.ts +446 -0
- package/mjs/types/context_t.d.ts +444 -0
- package/mjs/types/hooks_t.d.ts +44 -0
- package/mjs/types/widgetUI_t.d.ts +536 -0
- package/package.json +1 -1
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
export type Rect = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
top: number;
|
|
5
|
+
left: number;
|
|
6
|
+
};
|
|
7
|
+
export type Point = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
export type BinaryFile<D extends ArrayBuffer | Uint8Array | Uint8ClampedArray | Buffer = ArrayBuffer> = {
|
|
12
|
+
format: string;
|
|
13
|
+
fileName?: string;
|
|
14
|
+
data: D;
|
|
15
|
+
};
|
|
16
|
+
declare enum DataType {
|
|
17
|
+
Number = 0,
|
|
18
|
+
String = 1,
|
|
19
|
+
ArrayBuffer = 2,
|
|
20
|
+
Array = 3,
|
|
21
|
+
Boolean = 4,
|
|
22
|
+
/** a javascript object */
|
|
23
|
+
JsonObj = 5,
|
|
24
|
+
/**
|
|
25
|
+
* Does not care; mostly used by actions to indicate they accept anything since they probably won't use the
|
|
26
|
+
* value.
|
|
27
|
+
**/
|
|
28
|
+
Anything = 6,
|
|
29
|
+
/** Raw image data, produced in browser environments */
|
|
30
|
+
ImageData = 7,
|
|
31
|
+
/** Raw audio data fraction */
|
|
32
|
+
AudioBuffer = 8,
|
|
33
|
+
Rect = 9,
|
|
34
|
+
Point = 10,
|
|
35
|
+
ImageBitmap = 11,
|
|
36
|
+
/**
|
|
37
|
+
* Custom binary data. Use the `format` property to specify the type of data, i.e. 'image/png', 'audio/mp3', etc.
|
|
38
|
+
**/
|
|
39
|
+
BinaryFile = 12
|
|
40
|
+
}
|
|
41
|
+
export type JsonType = {
|
|
42
|
+
[key: string]: SupportedTypes;
|
|
43
|
+
};
|
|
44
|
+
export type KemuType = number | string | ArrayBuffer | JsonType | boolean | ImageData | AudioBuffer | Rect | Point | ImageBitmap | BinaryFile;
|
|
45
|
+
export type SupportedTypes = KemuType | KemuType[];
|
|
46
|
+
/** Type passed around between gates and blocks */
|
|
47
|
+
export type Data = {
|
|
48
|
+
/** the type of data represented */
|
|
49
|
+
type: DataType;
|
|
50
|
+
value: SupportedTypes;
|
|
51
|
+
/** original time when the event was first picked up by an input gate. */
|
|
52
|
+
timestamp: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Describe the shape of objects. For example:
|
|
56
|
+
*
|
|
57
|
+
* Given the following object:
|
|
58
|
+
* ```
|
|
59
|
+
* const obj = {
|
|
60
|
+
* property1: 12,
|
|
61
|
+
* property2: 'Hello'
|
|
62
|
+
* };
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* The shape definition would be:
|
|
66
|
+
* ```
|
|
67
|
+
* {
|
|
68
|
+
* 'property1': DataType.Number,
|
|
69
|
+
* 'property2': DataType.String,
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Use a JsonPrimitiveFormat (`$$primitive_{x}`) to specify the type of an array of primitive objects,
|
|
74
|
+
* where 'x' is the index in the array the value of the property belongs to. For example:
|
|
75
|
+
*
|
|
76
|
+
* An event with `[1, 'hi', {other: 'yes}]` would produce the following jsonShape:
|
|
77
|
+
*
|
|
78
|
+
* ```
|
|
79
|
+
* {
|
|
80
|
+
* '$$primitive_0': DataType.Number,
|
|
81
|
+
* '$$primitive_1': DataType.String,
|
|
82
|
+
* '$$primitive_2': DataType.JsonObj,
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* If no primitive index is specified, the system assumes all the items in the array
|
|
87
|
+
* will have the given primitive type. For example:
|
|
88
|
+
*
|
|
89
|
+
* An array of `[1, 2, 3, 4]` should be described as:
|
|
90
|
+
* ```
|
|
91
|
+
* {
|
|
92
|
+
* '$$primitive': DataType.Number
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export type JsonTypeShape = {
|
|
97
|
+
[key: string]: DataType;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Used by Widget (formerly known as Gates) modules when defining their
|
|
101
|
+
* input/output port list
|
|
102
|
+
*/
|
|
103
|
+
export type WidgetPort = {
|
|
104
|
+
/** a unique identifier (in the context of the widget) for this port. */
|
|
105
|
+
name: string;
|
|
106
|
+
/** alternative label used to replace the name for presentation purposes only */
|
|
107
|
+
label?: string;
|
|
108
|
+
/** Type of data the port accepts or produces, an array indicates the gate can receive multiple types */
|
|
109
|
+
type: DataType | DataType[];
|
|
110
|
+
/**
|
|
111
|
+
* If true, processors won't be invoked until at least an event is received in this port.
|
|
112
|
+
*/
|
|
113
|
+
required?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Describes the shape of a JSON object when dataType == JsonObj. Or the shape of items
|
|
116
|
+
* when dataType == Array
|
|
117
|
+
*/
|
|
118
|
+
jsonShape?: JsonTypeShape;
|
|
119
|
+
/** help description markdown */
|
|
120
|
+
description?: string;
|
|
121
|
+
/**
|
|
122
|
+
* If true, the port will be highlighted in the UI
|
|
123
|
+
* to indicate events on this port will start the
|
|
124
|
+
* processor execution.
|
|
125
|
+
*/
|
|
126
|
+
triggerPort?: boolean;
|
|
127
|
+
};
|
|
128
|
+
export type WidgetState<T extends Record<string, any> = Record<string, unknown>> = T;
|
|
129
|
+
export type TargetOutput = {
|
|
130
|
+
/**
|
|
131
|
+
* the name of the port the `data` will be sent from.
|
|
132
|
+
* This name MUST match one of the ports
|
|
133
|
+
* returned by the `getOutputs` function or defined in the widget
|
|
134
|
+
* manifest. If the name does not match, the data will not be sent.
|
|
135
|
+
**/
|
|
136
|
+
name: string;
|
|
137
|
+
/**
|
|
138
|
+
* The data to send to the output port.
|
|
139
|
+
* If the value is `undefined` or `null`, no data will be sent.
|
|
140
|
+
* Also, the data type MUST match the type defined in the widget manifest.
|
|
141
|
+
*/
|
|
142
|
+
value: SupportedTypes | undefined | null;
|
|
143
|
+
/**
|
|
144
|
+
* the data type of the value being sent.
|
|
145
|
+
* This value is automatically inferred from the widget manifest.
|
|
146
|
+
**/
|
|
147
|
+
type: DataType;
|
|
148
|
+
/** id of the variant that defined the output */
|
|
149
|
+
variantId?: string;
|
|
150
|
+
};
|
|
151
|
+
export type WidgetPortStr = Omit<WidgetPort, "type"> & {
|
|
152
|
+
type: string;
|
|
153
|
+
};
|
|
154
|
+
declare enum ProcessorType {
|
|
155
|
+
Javascript = "js",
|
|
156
|
+
Python = "py",
|
|
157
|
+
Executable = "exe"
|
|
158
|
+
}
|
|
159
|
+
export type ServiceSecret = {
|
|
160
|
+
/** a markdown description of the secret */
|
|
161
|
+
description: string;
|
|
162
|
+
/** if true, the secret is optional and the service will still start if the secret is not provided */
|
|
163
|
+
optional?: boolean;
|
|
164
|
+
};
|
|
165
|
+
export type ServiceWidgetVariant<P extends WidgetPort | WidgetPortStr> = {
|
|
166
|
+
/** unique identifier for the variant */
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
description: string;
|
|
170
|
+
/**
|
|
171
|
+
* custom color for the variant. If not provided, the main
|
|
172
|
+
* color defined in the manifest will be used.
|
|
173
|
+
**/
|
|
174
|
+
color?: string;
|
|
175
|
+
/** SVG icon data */
|
|
176
|
+
svgIcon?: string;
|
|
177
|
+
inputs?: P[];
|
|
178
|
+
outputs?: P[];
|
|
179
|
+
};
|
|
180
|
+
export type ValidPlatformArch = "win-x64" | "win-x86" | "win-arm" | "win-arm64" | "osx-x64" | "osx-arm64";
|
|
181
|
+
export type ServiceManifest<P extends WidgetPort | WidgetPortStr> = {
|
|
182
|
+
/** the unique name defined by the service */
|
|
183
|
+
name: string;
|
|
184
|
+
/** a unique identifier given during startup */
|
|
185
|
+
version: string;
|
|
186
|
+
/** a service title for UI purposes */
|
|
187
|
+
title?: string;
|
|
188
|
+
/** a shorten title to be used in the canvas */
|
|
189
|
+
shortTitle?: string;
|
|
190
|
+
description: string;
|
|
191
|
+
processor: ProcessorType;
|
|
192
|
+
/** Id of the user that published the service */
|
|
193
|
+
author: string;
|
|
194
|
+
/** id of the item in the marketplace */
|
|
195
|
+
publicationId?: string;
|
|
196
|
+
/**
|
|
197
|
+
* if true, it indicates other services can subscribe
|
|
198
|
+
* to events emitted by this service. Only services
|
|
199
|
+
* with `eventEmitter` set to true can use `broadcast`
|
|
200
|
+
* to emit events.
|
|
201
|
+
*/
|
|
202
|
+
eventEmitter?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Specifies the default timeout in seconds when a parentEvent is received.
|
|
205
|
+
* This is used to discard events that take too long to process.
|
|
206
|
+
* Set to 0 to disable the timeout. Warning this may
|
|
207
|
+
* cause some parent widgets to hang indefinitely if the child
|
|
208
|
+
* widget does not respond to the event.
|
|
209
|
+
**/
|
|
210
|
+
processingTimeoutSec?: number;
|
|
211
|
+
/**
|
|
212
|
+
* if true, parent events sent to this widget will
|
|
213
|
+
* be resolved immediately, meaning the parent widget
|
|
214
|
+
* will not have to wait for this service to respond
|
|
215
|
+
* before continuing execution.
|
|
216
|
+
*/
|
|
217
|
+
asyncParentEvents?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* if true, it indicates the service is only meant to be used in a
|
|
220
|
+
* web environment. The widget won't work when exported.
|
|
221
|
+
*/
|
|
222
|
+
webOnly?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* if set the service will only receive env vars that start with this prefix.
|
|
225
|
+
* Use it to isolate the information services have access to.
|
|
226
|
+
* Eg:
|
|
227
|
+
* - `KEMU_{CUSTOM_PREFIX}_DB_URL`: Your service will receive this env var as `DB_URL`
|
|
228
|
+
*
|
|
229
|
+
* Remember that only variables that start with `KEMU_` are forwarded to services.
|
|
230
|
+
*/
|
|
231
|
+
envVarPrefix?: string;
|
|
232
|
+
color?: string;
|
|
233
|
+
svgIcon?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Flags this service as internal. Internal services are not
|
|
236
|
+
* meant to be used by the end-user. Attempts to use an internal service
|
|
237
|
+
* will likely result in an error.
|
|
238
|
+
*/
|
|
239
|
+
internal?: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* if true, the service is expected to have a `widgetUI.js` file in the root directory
|
|
242
|
+
* that will be used to mount a new UI onto the canvas.
|
|
243
|
+
**/
|
|
244
|
+
widgetUI?: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* If true, the processor won't be forwarded any parent events.
|
|
247
|
+
* Use it when you have a widget with custom UI that performs all processing
|
|
248
|
+
* inside of its own component. Keep in mind that when exported, any processing
|
|
249
|
+
* logic that does not exist in the processor will not be available in the exported
|
|
250
|
+
* recipe.
|
|
251
|
+
*/
|
|
252
|
+
ignoreParentEvents?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* A list of relative paths to `txt` files where custom widget clipboard data are stored. Eg:
|
|
255
|
+
* ```json
|
|
256
|
+
* {
|
|
257
|
+
* "customWidgets": [
|
|
258
|
+
* "customWidgets/widget1.txt",
|
|
259
|
+
* "customWidgets/widget2.txt",
|
|
260
|
+
* ]
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
* This will cause the service to be rendered as a folder with the custom widgets as sub-widgets.
|
|
264
|
+
*/
|
|
265
|
+
customWidgets?: string[];
|
|
266
|
+
/**
|
|
267
|
+
* A list of widget variants that can be selected by the user.
|
|
268
|
+
* All variants will invoke the same processor, but they can have different input/output ports
|
|
269
|
+
* and be visually distinct.
|
|
270
|
+
*/
|
|
271
|
+
variants?: ServiceWidgetVariant<P>[];
|
|
272
|
+
/**
|
|
273
|
+
* A list of relative paths to folders containing extra services that are part of this service. Eg:
|
|
274
|
+
* ```json
|
|
275
|
+
* {
|
|
276
|
+
* "subServices": [
|
|
277
|
+
* "subServices/subService1",
|
|
278
|
+
* "subServices/subService2",
|
|
279
|
+
* ]
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* Each folder should contain all the required files that represent a service (manifest, processor, etc).
|
|
284
|
+
*/
|
|
285
|
+
subServices?: string[];
|
|
286
|
+
/** the list of input ports. If not provided,
|
|
287
|
+
* `dynamicInputs` MUST be set to true, or loading the
|
|
288
|
+
* widget will fail.
|
|
289
|
+
*/
|
|
290
|
+
inputs: P[];
|
|
291
|
+
/**
|
|
292
|
+
* the list of output ports. If not provided,
|
|
293
|
+
* `dynamicOutputs` MUST be set to true, or loading the
|
|
294
|
+
* widget will fail.
|
|
295
|
+
*/
|
|
296
|
+
outputs: P[];
|
|
297
|
+
/**
|
|
298
|
+
* A map of secret names to their descriptions
|
|
299
|
+
*/
|
|
300
|
+
requiredSecrets?: {
|
|
301
|
+
[name: string]: ServiceSecret;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* A list of platforms that this service supports.
|
|
305
|
+
* If not provided, it will default to 'win-x86', 'win-x64', 'osx-x64' and 'osx-arm64'.
|
|
306
|
+
*/
|
|
307
|
+
supportedPlatforms?: ValidPlatformArch[];
|
|
308
|
+
};
|
|
309
|
+
export type ServiceWidgetInfo = {
|
|
310
|
+
name: string;
|
|
311
|
+
icon?: string;
|
|
312
|
+
color?: string;
|
|
313
|
+
description: string;
|
|
314
|
+
contents: string;
|
|
315
|
+
/**
|
|
316
|
+
* The id of the first root group in the widget.
|
|
317
|
+
* Keep in mind this id will be re-generated when the widget is added to the canvas.
|
|
318
|
+
*/
|
|
319
|
+
rootGroupId: string;
|
|
320
|
+
protocolVersion: string;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* This is the output of the service library after processing its own manifest file.
|
|
324
|
+
*/
|
|
325
|
+
export type PartiallyProcessedManifest<B extends Buffer | ArrayBuffer = Buffer, SM extends WidgetPort | WidgetPortStr = WidgetPortStr> = ServiceManifest<SM> & {
|
|
326
|
+
widgetUIContents?: B;
|
|
327
|
+
uiContentChecksum?: string;
|
|
328
|
+
/** path to the root directory where the service resides */
|
|
329
|
+
path: string;
|
|
330
|
+
/** added by the service automatically when the service is running in dev mode */
|
|
331
|
+
readonly devMode?: boolean;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* This is the output of the Hub after combining a PartiallyProcessedManifest and processing variants, sub-services and custom widgets.
|
|
335
|
+
*/
|
|
336
|
+
export type ProcessedManifest<B extends Buffer | ArrayBuffer = Buffer> = Omit<PartiallyProcessedManifest<B, WidgetPort>, "customWidgets"> & {
|
|
337
|
+
customWidgets?: ServiceWidgetInfo[];
|
|
338
|
+
/** if present, it indicates this service is a sub-service of another service */
|
|
339
|
+
parentService?: {
|
|
340
|
+
name: string;
|
|
341
|
+
version: string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
345
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
|
346
|
+
}[Keys];
|
|
347
|
+
export type DefineDynamicPortsArgs = RequireAtLeastOne<{
|
|
348
|
+
/**
|
|
349
|
+
* Set to null to remove any previously defined ports or
|
|
350
|
+
* set to an empty array to remove ports from the widget.
|
|
351
|
+
*/
|
|
352
|
+
outputs?: WidgetPort[] | null;
|
|
353
|
+
/**
|
|
354
|
+
* Set to null to remove any previously defined ports or
|
|
355
|
+
* set to an empty array to remove ports from the widget.
|
|
356
|
+
*/
|
|
357
|
+
inputs?: WidgetPort[] | null;
|
|
358
|
+
}, "outputs" | "inputs"> & {
|
|
359
|
+
/** the id of the variant this definition applies to */
|
|
360
|
+
variantId?: string;
|
|
361
|
+
};
|
|
362
|
+
export type UseWidgetStateResponse<T extends WidgetState = WidgetState> = {
|
|
363
|
+
/**
|
|
364
|
+
* the current state of the widget at the time the hook was created.
|
|
365
|
+
* This state is not reactive and will not trigger a re-render when the state changes.
|
|
366
|
+
**/
|
|
367
|
+
state: Readonly<T>;
|
|
368
|
+
/**
|
|
369
|
+
* @returns the current state of the widget. This function is memoized and will always return the latest state.
|
|
370
|
+
*/
|
|
371
|
+
getState: () => Readonly<T>;
|
|
372
|
+
/**
|
|
373
|
+
* Updates the state of the widget.
|
|
374
|
+
* @param newState the new state to set.
|
|
375
|
+
* @param triggerEvents if true, the widget will notify listeners that its state has changed. Default is true.
|
|
376
|
+
*/
|
|
377
|
+
setState: (newState: T, triggerEvents?: boolean) => void;
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* @returns the current state and a memoized function to get the current state.
|
|
381
|
+
*/
|
|
382
|
+
export type UseWidgetStateHook<T extends WidgetState = WidgetState> = () => UseWidgetStateResponse<T>;
|
|
383
|
+
export type DeepReadOnly<T> = T extends (infer R)[] ? ReadonlyArray<DeepReadOnly<R>> : T extends object ? {
|
|
384
|
+
readonly [K in keyof T]: DeepReadOnly<T[K]>;
|
|
385
|
+
} : T;
|
|
386
|
+
export type DeepReadOnlyArray<T> = ReadonlyArray<DeepReadOnly<T>>;
|
|
387
|
+
export type ServiceParentEvent = {
|
|
388
|
+
/** information about the widget producing */
|
|
389
|
+
sourceWidget: {
|
|
390
|
+
id: string;
|
|
391
|
+
port: string;
|
|
392
|
+
};
|
|
393
|
+
targetPort: string;
|
|
394
|
+
data: Data;
|
|
395
|
+
};
|
|
396
|
+
export type BroadcastEvent = {
|
|
397
|
+
outputs: TargetOutput[];
|
|
398
|
+
source: {
|
|
399
|
+
serviceName: string;
|
|
400
|
+
serviceVersion: string;
|
|
401
|
+
sessionId: number;
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
export type ServiceParentEventHandler = (event: ServiceParentEvent) => void | Promise<void>;
|
|
405
|
+
export type ServiceBroadcastEventHandler = (event: DeepReadOnly<BroadcastEvent>) => void | Promise<void>;
|
|
406
|
+
export type ServiceSetOutputsEventHandler = (outputs: DeepReadOnlyArray<TargetOutput>) => void | Promise<void>;
|
|
407
|
+
export type WidgetRenderArgs = {
|
|
408
|
+
/** indicates if the Hub service is currently online */
|
|
409
|
+
serviceOnline: boolean;
|
|
410
|
+
/** indicates if this Widget is currently disabled */
|
|
411
|
+
disabled: boolean;
|
|
412
|
+
};
|
|
413
|
+
export type WidgetUIInstance = {
|
|
414
|
+
/** unmounts the component */
|
|
415
|
+
destroy: () => void;
|
|
416
|
+
/**
|
|
417
|
+
* re-renders the component by triggering
|
|
418
|
+
* an internal state change.
|
|
419
|
+
**/
|
|
420
|
+
render: (a?: WidgetRenderArgs) => void;
|
|
421
|
+
handleParentEvent: ServiceParentEventHandler | null;
|
|
422
|
+
handleBroadcastEvent: ServiceBroadcastEventHandler | null;
|
|
423
|
+
handleSetOutputsEvent: ServiceSetOutputsEventHandler | null;
|
|
424
|
+
};
|
|
425
|
+
export type LimitedManifest = Omit<ProcessedManifest, "widgetUIContents" | "settingsUIContents" | "path">;
|
|
426
|
+
export type ReactWidgetUtils = {
|
|
427
|
+
/**
|
|
428
|
+
* Shows a native dialog to choose a file.
|
|
429
|
+
* @returns a promise that resolves to the paths of the chosen files.
|
|
430
|
+
**/
|
|
431
|
+
showChooseFileDialog: (args: {
|
|
432
|
+
title?: string;
|
|
433
|
+
fileTypes?: string[];
|
|
434
|
+
allowMultiple?: boolean;
|
|
435
|
+
}) => Promise<string[]>;
|
|
436
|
+
/**
|
|
437
|
+
* Shows a native dialog to choose a directory.
|
|
438
|
+
* @returns a promise that resolves to the path of the chosen directory.
|
|
439
|
+
*/
|
|
440
|
+
showChooseDirectoryDialog: (args: {
|
|
441
|
+
title?: string;
|
|
442
|
+
}) => Promise<string>;
|
|
443
|
+
browser: {
|
|
444
|
+
/**
|
|
445
|
+
* @returns the Cache Storage path for the given file
|
|
446
|
+
**/
|
|
447
|
+
getCacheFilePath: (fileName: string) => string;
|
|
448
|
+
/**
|
|
449
|
+
* Adds the given data to the service cache
|
|
450
|
+
* @param filePath the full path of the file, including the file name and extension
|
|
451
|
+
* @param data the raw data to store
|
|
452
|
+
* @param headers optional response headers
|
|
453
|
+
* @returns
|
|
454
|
+
*/
|
|
455
|
+
cacheFile: (filePath: string, data: string | ArrayBuffer | Uint8Array | Uint8ClampedArray | Blob, headers?: Headers) => Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Attempts to load the file from the cache storage
|
|
458
|
+
* @param filePath full path of the file, including the file name and extension
|
|
459
|
+
* @returns the cached file or undefined if the file is not found
|
|
460
|
+
*/
|
|
461
|
+
getCachedFile: (filePath: string) => Promise<Response | undefined>;
|
|
462
|
+
/**
|
|
463
|
+
* Removes the file from the cache storage. If path does not exist, nothing happens.
|
|
464
|
+
* @param filePath full path of the file, including the file name and extension
|
|
465
|
+
*/
|
|
466
|
+
removeCachedFile: (filePath: string) => Promise<void>;
|
|
467
|
+
/**
|
|
468
|
+
* Removes all entries linked to this service
|
|
469
|
+
*/
|
|
470
|
+
clearServiceCache: () => Promise<void>;
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
export type CustomWidgetProps = {
|
|
474
|
+
/** the id of this widget in the recipe */
|
|
475
|
+
readonly widgetId: string;
|
|
476
|
+
/** the id of the recipe */
|
|
477
|
+
readonly recipeId: string;
|
|
478
|
+
/** the widget variant that was added to the workspace */
|
|
479
|
+
readonly variantId?: string;
|
|
480
|
+
/** the manifest file of the running service */
|
|
481
|
+
manifest: DeepReadOnly<LimitedManifest>;
|
|
482
|
+
serviceOnline: boolean;
|
|
483
|
+
disabled: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Redraws the ports and their connections.
|
|
486
|
+
* Useful when the size of your widget changes dynamically.
|
|
487
|
+
**/
|
|
488
|
+
repaintPorts: () => void;
|
|
489
|
+
/**
|
|
490
|
+
* Sets the value of the outputs of the widget.
|
|
491
|
+
* IMPORTANT: Keep in mind that port changes triggered from UI components won't work
|
|
492
|
+
* when the recipe is exported as a standalone service.
|
|
493
|
+
**/
|
|
494
|
+
setOutputs: GlobalContext["setOutputs"];
|
|
495
|
+
/**
|
|
496
|
+
* Invokes an `onUIEvent` in the processor file.
|
|
497
|
+
* @param name the name of the handler to be called.
|
|
498
|
+
* @returns a promise that resolves to the return value of the processor handler.
|
|
499
|
+
**/
|
|
500
|
+
callProcessorHandler: <R = any>(name: string, data?: any) => Promise<R>;
|
|
501
|
+
/**
|
|
502
|
+
* Allows the UI instance to change the default
|
|
503
|
+
* ports definition of a widget service based on custom logic. The interface
|
|
504
|
+
* will repaint the ports for the given widget accordingly.
|
|
505
|
+
*
|
|
506
|
+
* Keep in mind that calling this method while attached to other widgets will
|
|
507
|
+
* automatically remove the links with any parent or child widget.
|
|
508
|
+
**/
|
|
509
|
+
defineDynamicPorts: (config: DefineDynamicPortsArgs) => Promise<void>;
|
|
510
|
+
/**
|
|
511
|
+
* Utility functions
|
|
512
|
+
*/
|
|
513
|
+
utils: ReactWidgetUtils;
|
|
514
|
+
};
|
|
515
|
+
export type WidgetCanvasDimensions = {
|
|
516
|
+
width: number;
|
|
517
|
+
height: number;
|
|
518
|
+
};
|
|
519
|
+
export type Output = Omit<TargetOutput, "value"> & {
|
|
520
|
+
value: SupportedTypes;
|
|
521
|
+
};
|
|
522
|
+
export type GlobalContext<T extends WidgetState = WidgetState> = {
|
|
523
|
+
useWidgetState: UseWidgetStateHook<T>;
|
|
524
|
+
setOutputs: (outputs: Output[]) => Promise<void>;
|
|
525
|
+
defineDynamicPorts: (config: DefineDynamicPortsArgs) => Promise<void>;
|
|
526
|
+
callProcessorHandler: <R = any>(name: string, data?: any) => Promise<R>;
|
|
527
|
+
setWidgetDimensions: (width: number, height: number) => void;
|
|
528
|
+
getWidgetDimensions: () => WidgetCanvasDimensions;
|
|
529
|
+
utils: ReactWidgetUtils;
|
|
530
|
+
widgetId: string;
|
|
531
|
+
recipeId: string;
|
|
532
|
+
variantId?: string;
|
|
533
|
+
manifest: LimitedManifest;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
export {};
|
package/mjs/WidgetWrapper.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
1
|
import React$1 from 'react';
|
|
4
2
|
|
|
5
3
|
export type Rect = {
|
|
@@ -14,6 +12,7 @@ export type Point = {
|
|
|
14
12
|
};
|
|
15
13
|
export type BinaryFile<D extends ArrayBuffer | Uint8Array | Uint8ClampedArray | Buffer = ArrayBuffer> = {
|
|
16
14
|
format: string;
|
|
15
|
+
fileName?: string;
|
|
17
16
|
data: D;
|
|
18
17
|
};
|
|
19
18
|
declare enum DataType {
|
|
@@ -121,6 +120,12 @@ export type WidgetPort = {
|
|
|
121
120
|
jsonShape?: JsonTypeShape;
|
|
122
121
|
/** help description markdown */
|
|
123
122
|
description?: string;
|
|
123
|
+
/**
|
|
124
|
+
* If true, the port will be highlighted in the UI
|
|
125
|
+
* to indicate events on this port will start the
|
|
126
|
+
* processor execution.
|
|
127
|
+
*/
|
|
128
|
+
triggerPort?: boolean;
|
|
124
129
|
};
|
|
125
130
|
export type WidgetState<T extends Record<string, any> = Record<string, unknown>> = T;
|
|
126
131
|
export type TargetOutput = {
|
|
@@ -174,6 +179,7 @@ export type ServiceWidgetVariant<P extends WidgetPort | WidgetPortStr> = {
|
|
|
174
179
|
inputs?: P[];
|
|
175
180
|
outputs?: P[];
|
|
176
181
|
};
|
|
182
|
+
export type ValidPlatformArch = "win-x64" | "win-x86" | "win-arm" | "win-arm64" | "osx-x64" | "osx-arm64";
|
|
177
183
|
export type ServiceManifest<P extends WidgetPort | WidgetPortStr> = {
|
|
178
184
|
/** the unique name defined by the service */
|
|
179
185
|
name: string;
|
|
@@ -185,6 +191,10 @@ export type ServiceManifest<P extends WidgetPort | WidgetPortStr> = {
|
|
|
185
191
|
shortTitle?: string;
|
|
186
192
|
description: string;
|
|
187
193
|
processor: ProcessorType;
|
|
194
|
+
/** Id of the user that published the service */
|
|
195
|
+
author: string;
|
|
196
|
+
/** id of the item in the marketplace */
|
|
197
|
+
publicationId?: string;
|
|
188
198
|
/**
|
|
189
199
|
* if true, it indicates other services can subscribe
|
|
190
200
|
* to events emitted by this service. Only services
|
|
@@ -292,6 +302,11 @@ export type ServiceManifest<P extends WidgetPort | WidgetPortStr> = {
|
|
|
292
302
|
requiredSecrets?: {
|
|
293
303
|
[name: string]: ServiceSecret;
|
|
294
304
|
};
|
|
305
|
+
/**
|
|
306
|
+
* A list of platforms that this service supports.
|
|
307
|
+
* If not provided, it will default to 'win-x86', 'win-x64', 'osx-x64' and 'osx-arm64'.
|
|
308
|
+
*/
|
|
309
|
+
supportedPlatforms?: ValidPlatformArch[];
|
|
295
310
|
};
|
|
296
311
|
export type ServiceWidgetInfo = {
|
|
297
312
|
name: string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CSSObject } from '@emotion/styled';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
import { CSSProperties } from 'react';
|
|
4
|
+
|
|
5
|
+
export type ResizableContainerProps = {
|
|
6
|
+
css?: CSSObject;
|
|
7
|
+
minWidth?: number;
|
|
8
|
+
minHeight?: number;
|
|
9
|
+
maxWidth?: number;
|
|
10
|
+
maxHeight?: number;
|
|
11
|
+
defaultWidth?: number;
|
|
12
|
+
defaultHeight?: number;
|
|
13
|
+
children: React$1.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The lockAspectRatio property is used to lock aspect ratio. Set to true to lock
|
|
16
|
+
* the aspect ratio based on the initial size. Set to a numeric value to lock a
|
|
17
|
+
* specific aspect ratio (such as 16/9). If set to numeric, make sure to set initial
|
|
18
|
+
* height/width to values with correct aspect ratio. If omitted, set false.
|
|
19
|
+
*/
|
|
20
|
+
lockAspectRatio?: boolean | number;
|
|
21
|
+
/**
|
|
22
|
+
* Callback when the component is being resized.
|
|
23
|
+
*/
|
|
24
|
+
onResize?: (width: number, height: number, originalEvent: MouseEvent | TouchEvent) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Callback when the component has been resized.
|
|
27
|
+
*/
|
|
28
|
+
onStopResize?: (width: number, height: number, originalEvent: MouseEvent | TouchEvent) => void;
|
|
29
|
+
};
|
|
30
|
+
export type WrapperProps = {
|
|
31
|
+
cWidth?: number | string;
|
|
32
|
+
cHeight?: number | string;
|
|
33
|
+
noPadding?: boolean;
|
|
34
|
+
noBorderRadius?: boolean;
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: React$1.CSSProperties;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A resizable container for the widget's canvas. It implements styles to handle
|
|
40
|
+
* the widget's appearance when selected or offline.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import packageJson from '../package.json';
|
|
45
|
+
* import { CustomWidgetProps, components, createWidgetUI } from '@kemu-io/hs-react';
|
|
46
|
+
*
|
|
47
|
+
* const { ResizableContainer } = components;
|
|
48
|
+
*
|
|
49
|
+
* const MyWidgetUI = (props: CustomWidgetProps) => {
|
|
50
|
+
*
|
|
51
|
+
* const handleResize = useCallback((width: number, height: number) => {
|
|
52
|
+
* console.log('Widget resized: ', width, height);
|
|
53
|
+
* }, []);
|
|
54
|
+
*
|
|
55
|
+
* return (
|
|
56
|
+
* <ResizableContainer>
|
|
57
|
+
* <button>Click Me</button>
|
|
58
|
+
* </ResizableContainer>
|
|
59
|
+
* );
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
* export default createWidgetUI(MyWidgetUI, packageJson.name, packageJson.version);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare const ResizableContainer: (props: ResizableContainerProps & WrapperProps) => import("react/jsx-runtime.js").JSX.Element;
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
ResizableContainer as default,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type WrapperProps = {
|
|
2
|
+
cWidth?: number | string;
|
|
3
|
+
cHeight?: number | string;
|
|
4
|
+
noPadding?: boolean;
|
|
5
|
+
noBorderRadius?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type WidthLessProps = Omit<WrapperProps, "cWidth" | "cHeight"> & {
|
|
8
|
+
width?: number | string;
|
|
9
|
+
height?: number | string;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: React.CSSProperties;
|
|
13
|
+
};
|
|
14
|
+
declare const Wrap: (p: WidthLessProps) => import("react/jsx-runtime.js").JSX.Element;
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
Wrap as default,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {};
|