@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.
Files changed (39) hide show
  1. package/cjs/WidgetWrapper.d.ts +17 -2
  2. package/cjs/components/ResizableContainer.d.ts +71 -0
  3. package/cjs/components/WidgetContainer.d.ts +20 -0
  4. package/cjs/components/index.d.ts +85 -0
  5. package/cjs/constants.d.ts +14 -0
  6. package/cjs/hooks/index.d.ts +712 -0
  7. package/cjs/hooks/useOnBroadcastEvent.d.ts +569 -0
  8. package/cjs/hooks/useOnParentEvent.d.ts +562 -0
  9. package/cjs/hooks/useOnSetOutputsEvent.d.ts +571 -0
  10. package/cjs/hooks/useReactiveWidgetState.d.ts +46 -0
  11. package/cjs/hooks/useReactiveWidgetState.js +1 -1
  12. package/cjs/hooks/useResizableWidgetDimensions.d.ts +39 -0
  13. package/cjs/hooks/useWidgetState.d.ts +46 -0
  14. package/cjs/lib/InstanceContext.d.ts +540 -0
  15. package/cjs/lib/cache.d.ts +14 -0
  16. package/cjs/lib/globalContext.d.ts +446 -0
  17. package/cjs/types/context_t.d.ts +444 -0
  18. package/cjs/types/hooks_t.d.ts +44 -0
  19. package/cjs/types/widgetUI_t.d.ts +536 -0
  20. package/mjs/WidgetWrapper.d.ts +17 -2
  21. package/mjs/components/ResizableContainer.d.ts +71 -0
  22. package/mjs/components/WidgetContainer.d.ts +20 -0
  23. package/mjs/components/index.d.ts +85 -0
  24. package/mjs/constants.d.ts +14 -0
  25. package/mjs/hooks/index.d.ts +712 -0
  26. package/mjs/hooks/useOnBroadcastEvent.d.ts +569 -0
  27. package/mjs/hooks/useOnParentEvent.d.ts +562 -0
  28. package/mjs/hooks/useOnSetOutputsEvent.d.ts +571 -0
  29. package/mjs/hooks/useReactiveWidgetState.d.ts +46 -0
  30. package/mjs/hooks/useReactiveWidgetState.js +1 -1
  31. package/mjs/hooks/useResizableWidgetDimensions.d.ts +39 -0
  32. package/mjs/hooks/useWidgetState.d.ts +46 -0
  33. package/mjs/lib/InstanceContext.d.ts +540 -0
  34. package/mjs/lib/cache.d.ts +14 -0
  35. package/mjs/lib/globalContext.d.ts +446 -0
  36. package/mjs/types/context_t.d.ts +444 -0
  37. package/mjs/types/hooks_t.d.ts +44 -0
  38. package/mjs/types/widgetUI_t.d.ts +536 -0
  39. package/package.json +1 -1
@@ -0,0 +1,446 @@
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
+ /**
47
+ * Describe the shape of objects. For example:
48
+ *
49
+ * Given the following object:
50
+ * ```
51
+ * const obj = {
52
+ * property1: 12,
53
+ * property2: 'Hello'
54
+ * };
55
+ * ```
56
+ *
57
+ * The shape definition would be:
58
+ * ```
59
+ * {
60
+ * 'property1': DataType.Number,
61
+ * 'property2': DataType.String,
62
+ * }
63
+ * ```
64
+ *
65
+ * Use a JsonPrimitiveFormat (`$$primitive_{x}`) to specify the type of an array of primitive objects,
66
+ * where 'x' is the index in the array the value of the property belongs to. For example:
67
+ *
68
+ * An event with `[1, 'hi', {other: 'yes}]` would produce the following jsonShape:
69
+ *
70
+ * ```
71
+ * {
72
+ * '$$primitive_0': DataType.Number,
73
+ * '$$primitive_1': DataType.String,
74
+ * '$$primitive_2': DataType.JsonObj,
75
+ * }
76
+ * ```
77
+ *
78
+ * If no primitive index is specified, the system assumes all the items in the array
79
+ * will have the given primitive type. For example:
80
+ *
81
+ * An array of `[1, 2, 3, 4]` should be described as:
82
+ * ```
83
+ * {
84
+ * '$$primitive': DataType.Number
85
+ * }
86
+ * ```
87
+ */
88
+ export type JsonTypeShape = {
89
+ [key: string]: DataType;
90
+ };
91
+ /**
92
+ * Used by Widget (formerly known as Gates) modules when defining their
93
+ * input/output port list
94
+ */
95
+ export type WidgetPort = {
96
+ /** a unique identifier (in the context of the widget) for this port. */
97
+ name: string;
98
+ /** alternative label used to replace the name for presentation purposes only */
99
+ label?: string;
100
+ /** Type of data the port accepts or produces, an array indicates the gate can receive multiple types */
101
+ type: DataType | DataType[];
102
+ /**
103
+ * If true, processors won't be invoked until at least an event is received in this port.
104
+ */
105
+ required?: boolean;
106
+ /**
107
+ * Describes the shape of a JSON object when dataType == JsonObj. Or the shape of items
108
+ * when dataType == Array
109
+ */
110
+ jsonShape?: JsonTypeShape;
111
+ /** help description markdown */
112
+ description?: string;
113
+ /**
114
+ * If true, the port will be highlighted in the UI
115
+ * to indicate events on this port will start the
116
+ * processor execution.
117
+ */
118
+ triggerPort?: boolean;
119
+ };
120
+ export type WidgetState<T extends Record<string, any> = Record<string, unknown>> = T;
121
+ export type TargetOutput = {
122
+ /**
123
+ * the name of the port the `data` will be sent from.
124
+ * This name MUST match one of the ports
125
+ * returned by the `getOutputs` function or defined in the widget
126
+ * manifest. If the name does not match, the data will not be sent.
127
+ **/
128
+ name: string;
129
+ /**
130
+ * The data to send to the output port.
131
+ * If the value is `undefined` or `null`, no data will be sent.
132
+ * Also, the data type MUST match the type defined in the widget manifest.
133
+ */
134
+ value: SupportedTypes | undefined | null;
135
+ /**
136
+ * the data type of the value being sent.
137
+ * This value is automatically inferred from the widget manifest.
138
+ **/
139
+ type: DataType;
140
+ /** id of the variant that defined the output */
141
+ variantId?: string;
142
+ };
143
+ export type WidgetPortStr = Omit<WidgetPort, "type"> & {
144
+ type: string;
145
+ };
146
+ declare enum ProcessorType {
147
+ Javascript = "js",
148
+ Python = "py",
149
+ Executable = "exe"
150
+ }
151
+ export type ServiceSecret = {
152
+ /** a markdown description of the secret */
153
+ description: string;
154
+ /** if true, the secret is optional and the service will still start if the secret is not provided */
155
+ optional?: boolean;
156
+ };
157
+ export type ServiceWidgetVariant<P extends WidgetPort | WidgetPortStr> = {
158
+ /** unique identifier for the variant */
159
+ id: string;
160
+ name: string;
161
+ description: string;
162
+ /**
163
+ * custom color for the variant. If not provided, the main
164
+ * color defined in the manifest will be used.
165
+ **/
166
+ color?: string;
167
+ /** SVG icon data */
168
+ svgIcon?: string;
169
+ inputs?: P[];
170
+ outputs?: P[];
171
+ };
172
+ export type ValidPlatformArch = "win-x64" | "win-x86" | "win-arm" | "win-arm64" | "osx-x64" | "osx-arm64";
173
+ export type ServiceManifest<P extends WidgetPort | WidgetPortStr> = {
174
+ /** the unique name defined by the service */
175
+ name: string;
176
+ /** a unique identifier given during startup */
177
+ version: string;
178
+ /** a service title for UI purposes */
179
+ title?: string;
180
+ /** a shorten title to be used in the canvas */
181
+ shortTitle?: string;
182
+ description: string;
183
+ processor: ProcessorType;
184
+ /** Id of the user that published the service */
185
+ author: string;
186
+ /** id of the item in the marketplace */
187
+ publicationId?: string;
188
+ /**
189
+ * if true, it indicates other services can subscribe
190
+ * to events emitted by this service. Only services
191
+ * with `eventEmitter` set to true can use `broadcast`
192
+ * to emit events.
193
+ */
194
+ eventEmitter?: boolean;
195
+ /**
196
+ * Specifies the default timeout in seconds when a parentEvent is received.
197
+ * This is used to discard events that take too long to process.
198
+ * Set to 0 to disable the timeout. Warning this may
199
+ * cause some parent widgets to hang indefinitely if the child
200
+ * widget does not respond to the event.
201
+ **/
202
+ processingTimeoutSec?: number;
203
+ /**
204
+ * if true, parent events sent to this widget will
205
+ * be resolved immediately, meaning the parent widget
206
+ * will not have to wait for this service to respond
207
+ * before continuing execution.
208
+ */
209
+ asyncParentEvents?: boolean;
210
+ /**
211
+ * if true, it indicates the service is only meant to be used in a
212
+ * web environment. The widget won't work when exported.
213
+ */
214
+ webOnly?: boolean;
215
+ /**
216
+ * if set the service will only receive env vars that start with this prefix.
217
+ * Use it to isolate the information services have access to.
218
+ * Eg:
219
+ * - `KEMU_{CUSTOM_PREFIX}_DB_URL`: Your service will receive this env var as `DB_URL`
220
+ *
221
+ * Remember that only variables that start with `KEMU_` are forwarded to services.
222
+ */
223
+ envVarPrefix?: string;
224
+ color?: string;
225
+ svgIcon?: string;
226
+ /**
227
+ * Flags this service as internal. Internal services are not
228
+ * meant to be used by the end-user. Attempts to use an internal service
229
+ * will likely result in an error.
230
+ */
231
+ internal?: boolean;
232
+ /**
233
+ * if true, the service is expected to have a `widgetUI.js` file in the root directory
234
+ * that will be used to mount a new UI onto the canvas.
235
+ **/
236
+ widgetUI?: boolean;
237
+ /**
238
+ * If true, the processor won't be forwarded any parent events.
239
+ * Use it when you have a widget with custom UI that performs all processing
240
+ * inside of its own component. Keep in mind that when exported, any processing
241
+ * logic that does not exist in the processor will not be available in the exported
242
+ * recipe.
243
+ */
244
+ ignoreParentEvents?: boolean;
245
+ /**
246
+ * A list of relative paths to `txt` files where custom widget clipboard data are stored. Eg:
247
+ * ```json
248
+ * {
249
+ * "customWidgets": [
250
+ * "customWidgets/widget1.txt",
251
+ * "customWidgets/widget2.txt",
252
+ * ]
253
+ * }
254
+ * ```
255
+ * This will cause the service to be rendered as a folder with the custom widgets as sub-widgets.
256
+ */
257
+ customWidgets?: string[];
258
+ /**
259
+ * A list of widget variants that can be selected by the user.
260
+ * All variants will invoke the same processor, but they can have different input/output ports
261
+ * and be visually distinct.
262
+ */
263
+ variants?: ServiceWidgetVariant<P>[];
264
+ /**
265
+ * A list of relative paths to folders containing extra services that are part of this service. Eg:
266
+ * ```json
267
+ * {
268
+ * "subServices": [
269
+ * "subServices/subService1",
270
+ * "subServices/subService2",
271
+ * ]
272
+ * }
273
+ * ```
274
+ *
275
+ * Each folder should contain all the required files that represent a service (manifest, processor, etc).
276
+ */
277
+ subServices?: string[];
278
+ /** the list of input ports. If not provided,
279
+ * `dynamicInputs` MUST be set to true, or loading the
280
+ * widget will fail.
281
+ */
282
+ inputs: P[];
283
+ /**
284
+ * the list of output ports. If not provided,
285
+ * `dynamicOutputs` MUST be set to true, or loading the
286
+ * widget will fail.
287
+ */
288
+ outputs: P[];
289
+ /**
290
+ * A map of secret names to their descriptions
291
+ */
292
+ requiredSecrets?: {
293
+ [name: string]: ServiceSecret;
294
+ };
295
+ /**
296
+ * A list of platforms that this service supports.
297
+ * If not provided, it will default to 'win-x86', 'win-x64', 'osx-x64' and 'osx-arm64'.
298
+ */
299
+ supportedPlatforms?: ValidPlatformArch[];
300
+ };
301
+ export type ServiceWidgetInfo = {
302
+ name: string;
303
+ icon?: string;
304
+ color?: string;
305
+ description: string;
306
+ contents: string;
307
+ /**
308
+ * The id of the first root group in the widget.
309
+ * Keep in mind this id will be re-generated when the widget is added to the canvas.
310
+ */
311
+ rootGroupId: string;
312
+ protocolVersion: string;
313
+ };
314
+ /**
315
+ * This is the output of the service library after processing its own manifest file.
316
+ */
317
+ export type PartiallyProcessedManifest<B extends Buffer | ArrayBuffer = Buffer, SM extends WidgetPort | WidgetPortStr = WidgetPortStr> = ServiceManifest<SM> & {
318
+ widgetUIContents?: B;
319
+ uiContentChecksum?: string;
320
+ /** path to the root directory where the service resides */
321
+ path: string;
322
+ /** added by the service automatically when the service is running in dev mode */
323
+ readonly devMode?: boolean;
324
+ };
325
+ /**
326
+ * This is the output of the Hub after combining a PartiallyProcessedManifest and processing variants, sub-services and custom widgets.
327
+ */
328
+ export type ProcessedManifest<B extends Buffer | ArrayBuffer = Buffer> = Omit<PartiallyProcessedManifest<B, WidgetPort>, "customWidgets"> & {
329
+ customWidgets?: ServiceWidgetInfo[];
330
+ /** if present, it indicates this service is a sub-service of another service */
331
+ parentService?: {
332
+ name: string;
333
+ version: string;
334
+ };
335
+ };
336
+ export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
337
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
338
+ }[Keys];
339
+ export type DefineDynamicPortsArgs = RequireAtLeastOne<{
340
+ /**
341
+ * Set to null to remove any previously defined ports or
342
+ * set to an empty array to remove ports from the widget.
343
+ */
344
+ outputs?: WidgetPort[] | null;
345
+ /**
346
+ * Set to null to remove any previously defined ports or
347
+ * set to an empty array to remove ports from the widget.
348
+ */
349
+ inputs?: WidgetPort[] | null;
350
+ }, "outputs" | "inputs"> & {
351
+ /** the id of the variant this definition applies to */
352
+ variantId?: string;
353
+ };
354
+ export type UseWidgetStateResponse<T extends WidgetState = WidgetState> = {
355
+ /**
356
+ * the current state of the widget at the time the hook was created.
357
+ * This state is not reactive and will not trigger a re-render when the state changes.
358
+ **/
359
+ state: Readonly<T>;
360
+ /**
361
+ * @returns the current state of the widget. This function is memoized and will always return the latest state.
362
+ */
363
+ getState: () => Readonly<T>;
364
+ /**
365
+ * Updates the state of the widget.
366
+ * @param newState the new state to set.
367
+ * @param triggerEvents if true, the widget will notify listeners that its state has changed. Default is true.
368
+ */
369
+ setState: (newState: T, triggerEvents?: boolean) => void;
370
+ };
371
+ /**
372
+ * @returns the current state and a memoized function to get the current state.
373
+ */
374
+ export type UseWidgetStateHook<T extends WidgetState = WidgetState> = () => UseWidgetStateResponse<T>;
375
+ export type LimitedManifest = Omit<ProcessedManifest, "widgetUIContents" | "settingsUIContents" | "path">;
376
+ export type ReactWidgetUtils = {
377
+ /**
378
+ * Shows a native dialog to choose a file.
379
+ * @returns a promise that resolves to the paths of the chosen files.
380
+ **/
381
+ showChooseFileDialog: (args: {
382
+ title?: string;
383
+ fileTypes?: string[];
384
+ allowMultiple?: boolean;
385
+ }) => Promise<string[]>;
386
+ /**
387
+ * Shows a native dialog to choose a directory.
388
+ * @returns a promise that resolves to the path of the chosen directory.
389
+ */
390
+ showChooseDirectoryDialog: (args: {
391
+ title?: string;
392
+ }) => Promise<string>;
393
+ browser: {
394
+ /**
395
+ * @returns the Cache Storage path for the given file
396
+ **/
397
+ getCacheFilePath: (fileName: string) => string;
398
+ /**
399
+ * Adds the given data to the service cache
400
+ * @param filePath the full path of the file, including the file name and extension
401
+ * @param data the raw data to store
402
+ * @param headers optional response headers
403
+ * @returns
404
+ */
405
+ cacheFile: (filePath: string, data: string | ArrayBuffer | Uint8Array | Uint8ClampedArray | Blob, headers?: Headers) => Promise<void>;
406
+ /**
407
+ * Attempts to load the file from the cache storage
408
+ * @param filePath full path of the file, including the file name and extension
409
+ * @returns the cached file or undefined if the file is not found
410
+ */
411
+ getCachedFile: (filePath: string) => Promise<Response | undefined>;
412
+ /**
413
+ * Removes the file from the cache storage. If path does not exist, nothing happens.
414
+ * @param filePath full path of the file, including the file name and extension
415
+ */
416
+ removeCachedFile: (filePath: string) => Promise<void>;
417
+ /**
418
+ * Removes all entries linked to this service
419
+ */
420
+ clearServiceCache: () => Promise<void>;
421
+ };
422
+ };
423
+ export type WidgetCanvasDimensions = {
424
+ width: number;
425
+ height: number;
426
+ };
427
+ export type Output = Omit<TargetOutput, "value"> & {
428
+ value: SupportedTypes;
429
+ };
430
+ export type GlobalContext<T extends WidgetState = WidgetState> = {
431
+ useWidgetState: UseWidgetStateHook<T>;
432
+ setOutputs: (outputs: Output[]) => Promise<void>;
433
+ defineDynamicPorts: (config: DefineDynamicPortsArgs) => Promise<void>;
434
+ callProcessorHandler: <R = any>(name: string, data?: any) => Promise<R>;
435
+ setWidgetDimensions: (width: number, height: number) => void;
436
+ getWidgetDimensions: () => WidgetCanvasDimensions;
437
+ utils: ReactWidgetUtils;
438
+ widgetId: string;
439
+ recipeId: string;
440
+ variantId?: string;
441
+ manifest: LimitedManifest;
442
+ };
443
+ export declare const setContext: (newContext: GlobalContext) => void;
444
+ export declare const getContext: <T extends WidgetState>() => GlobalContext<T>;
445
+
446
+ export {};