@foxglove/extension 2.23.0 → 2.25.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.
package/src/index.ts CHANGED
@@ -1,891 +1,3 @@
1
- import type { Immutable } from "./immutable";
2
-
1
+ export * from "./stable";
3
2
  export type { Immutable } from "./immutable";
4
-
5
- // Valid types for parameter data (such as rosparams)
6
- export type ParameterValue =
7
- | undefined
8
- | boolean
9
- | number
10
- | string
11
- | Date
12
- | Uint8Array
13
- | ParameterValue[]
14
- | { [key: string]: ParameterValue };
15
-
16
- // Valid types for global variables
17
- export type VariableValue =
18
- | undefined
19
- | boolean
20
- | number
21
- | string
22
- | VariableValue[]
23
- | { [key: string]: VariableValue };
24
-
25
- export type VariableStruct = { [key: string]: VariableValue };
26
-
27
- // Valid types for application settings
28
- export type AppSettingValue = string | number | boolean | undefined;
29
-
30
- export interface Time {
31
- sec: number;
32
- nsec: number;
33
- }
34
-
35
- /**
36
- * A topic is a namespace for specific types of messages
37
- */
38
- export type Topic = {
39
- /**
40
- * topic name i.e. "/some/topic"
41
- */
42
- name: string;
43
- /**
44
- * @deprecated Renamed to `schemaName`. `datatype` will be removed in a future release.
45
- */
46
- datatype: string;
47
- /**
48
- * The schema name is an identifier for the types of messages on this topic. Typically this is the
49
- * fully-qualified name of the message schema. The fully-qualified name depends on the data source
50
- * and data loaded by the data source.
51
- *
52
- * i.e. `package.Message` in protobuf-like serialization or `pkg/Msg` in ROS systems.
53
- */
54
- schemaName: string;
55
-
56
- /**
57
- * Lists any additional schema names available for subscribers on the topic. When subscribing to
58
- * a topic, the panel can request messages be automatically converted from schemaName into one
59
- * of the convertibleTo schemas using the convertTo option.
60
- */
61
- convertibleTo?: readonly string[];
62
- };
63
-
64
- export type Subscription = {
65
- topic: string;
66
-
67
- /**
68
- * If a topic has additional schema names, specifying a schema name will convert messages on that
69
- * topic to the convertTo schema using a registered message converter. MessageEvents for the
70
- * subscription will contain the converted message and an originalMessageEvent field with the
71
- * original message event.
72
- */
73
- convertTo?: string;
74
-
75
- /**
76
- * Setting preload to _true_ hints to the data source that it should attempt to load all available
77
- * messages for the topic. The default behavior is to only load messages for the current frame.
78
- *
79
- * **Only** topics with `preload: true` are available in the `allFrames` render state.
80
- */
81
- preload?: boolean;
82
- };
83
-
84
- /**
85
- * A message event frames message data with the topic and receive time
86
- */
87
- export type MessageEvent<T = unknown> = {
88
- /** The topic name this message was received on, i.e. "/some/topic" */
89
- topic: string;
90
- /**
91
- * The schema name is an identifier for the schema of the message within the message event.
92
- */
93
- schemaName: string;
94
- /**
95
- * The time in nanoseconds this message was received. This may be set by the
96
- * local system clock or the data source, depending on the data source used
97
- * and whether time is simulated via a /clock topic or similar mechanism.
98
- * The timestamp is often nanoseconds since the UNIX epoch, but may be
99
- * relative to another event such as system boot time or simulation start
100
- * time depending on the context.
101
- */
102
- receiveTime: Time;
103
- /**
104
- * The time in nanoseconds this message was originally published. This is
105
- * only available for some data sources. The timestamp is often nanoseconds
106
- * since the UNIX epoch, but may be relative to another event such as system
107
- * boot time or simulation start time depending on the context.
108
- */
109
- publishTime?: Time;
110
- /** The deserialized message as a JavaScript object. */
111
- message: T;
112
- /**
113
- * The approximate size of this message event in its deserialized form. This can be
114
- * useful for statistics tracking and cache eviction.
115
- */
116
- sizeInBytes: number;
117
-
118
- /**
119
- * When subscribing to a topic using the `convertTo` option, the message event `message`
120
- * contains the converted message and the originalMessageEvent field contains the original
121
- * un-converted message event.
122
- */
123
- originalMessageEvent?: MessageEvent;
124
- };
125
-
126
- export interface LayoutActions {
127
- /** Open a new panel or update an existing panel in the layout. */
128
- addPanel(params: {
129
- /**
130
- * Where to position the panel. Currently, only "sibling" is supported which indicates the
131
- * new panel will be adjacent to the calling panel.
132
- */
133
- position: "sibling";
134
-
135
- /**
136
- * The type of panel to open. For extension panels, this `"extensionName.panelName"` where
137
- * extensionName is the `name` field from the extension's package.json, and panelName is the
138
- * name provided to `registerPanel()`.
139
- */
140
- type: string;
141
-
142
- /**
143
- * Whether to update an existing sibling panel of the same type, if it already exists. If false
144
- * or omitted, a new panel will always be added.
145
- *
146
- * @deprecated This parameter is only supported for built-in panels at this time.
147
- */
148
- updateIfExists?: boolean;
149
-
150
- /**
151
- * A function that returns the state for the new panel. If updating an existing panel, the
152
- * existing state will be passed in.
153
- * @see `updateIfExists`
154
- */
155
- getState(existingState?: unknown): unknown;
156
- }): void;
157
- }
158
-
159
- export type RenderState = {
160
- /**
161
- * The latest messages for the current render frame. These are new messages since the last render frame.
162
- */
163
- currentFrame?: MessageEvent[];
164
-
165
- /**
166
- * True if the data source performed a seek. This indicates that some data may have been skipped
167
- * (never appeared in the `currentFrame`), so panels should clear out any stale state to avoid
168
- * displaying incorrect data.
169
- */
170
- didSeek?: boolean;
171
-
172
- /**
173
- * All available messages. Best-effort list of all available messages.
174
- */
175
- allFrames?: MessageEvent[];
176
-
177
- /**
178
- * Map of current parameter values. Parameters are key/value pairs associated with the data
179
- * source, and may not be available for all data sources. For example, ROS 1 live connections
180
- * support parameters through the Parameter Server <http://wiki.ros.org/Parameter%20Server>.
181
- */
182
- parameters?: Map<string, ParameterValue>;
183
-
184
- /**
185
- * Transient panel state shared between panels of the same type. This can be any data a
186
- * panel author wishes to share between panels.
187
- */
188
- sharedPanelState?: Record<string, unknown>;
189
-
190
- /**
191
- * Map of current Studio variables. Variables are key/value pairs that are globally accessible
192
- * to panels and scripts in the current layout. See
193
- * <https://docs.foxglove.dev/docs/visualization/variables> for more information.
194
- */
195
- variables?: Map<string, VariableValue>;
196
-
197
- /**
198
- * List of available topics. This list includes subscribed and unsubscribed topics.
199
- */
200
- topics?: Topic[];
201
-
202
- /**
203
- * A timestamp value indicating the current playback time.
204
- */
205
- currentTime?: Time;
206
-
207
- /**
208
- * The start timestamp of the playback range for the current data source. For offline files it
209
- * is expected to be present. For live connections, the start time may or may not be present
210
- * depending on the data source.
211
- */
212
- startTime?: Time;
213
-
214
- /**
215
- * The end timestamp of the playback range for the current data source. For offline files it
216
- * is expected to be present. For live connections, the end time may or may not be present
217
- * depending on the data source.
218
- */
219
- endTime?: Time;
220
-
221
- /**
222
- * A seconds value indicating a preview time. The preview time is set when a user hovers
223
- * over the seek bar or when a panel sets the preview time explicitly. The preview time
224
- * is a seconds value within the playback range.
225
- *
226
- * i.e. A plot panel may set the preview time when a user is hovering over the plot to signal
227
- * to other panels where the user is currently hovering and allow them to render accordingly.
228
- */
229
- previewTime?: number | undefined;
230
-
231
- /** The color scheme currently in use throughout the app. */
232
- colorScheme?: "dark" | "light";
233
-
234
- /** Application settings. This will only contain subscribed application setting key/values */
235
- appSettings?: Map<string, AppSettingValue>;
236
- };
237
-
238
- type SubscribeMessageRangeArgs = {
239
- /**
240
- * Topic to be subscribed to.
241
- */
242
- topic: string;
243
- /**
244
- * Convert messages to this schema before delivering to the subscriber.
245
- *
246
- * MessageEvents for the subscription will contain the converted message and an
247
- * `originalMessageEvent` field with the original message event. If no `convertTo` schema is
248
- * specified, then no message converters will be used. If no message converter exists for
249
- * converting the original schema to the `convertTo` schema, then no messages are delivered for
250
- * this subscription.
251
- */
252
- convertTo?: string;
253
- /**
254
- * `onReset` is a function that receives an async iterable when there is message data available on
255
- * the subscription.
256
- *
257
- * To read messages, your function should iterate through the provided async iterable. Each item
258
- * of the iterable is a batch of message events for the subscription's topic. These batches and
259
- * messages are in _log time_ order. When there are no more messages to read the iterator will
260
- * finish.
261
- *
262
- * ```typescript
263
- * async function onReset(batchIterator) {
264
- * for await (const batch of batchIterator) {
265
- * //...
266
- * }
267
- * }
268
- * ```
269
- *
270
- * `onReset` is called again when the upstream topic data changes. I.E subscribing to a
271
- * user-script output topic and the user script changes, or subscribing to an aliased topic and
272
- * the alias changes. When topic data changes, the previous iterator will end, and its data is no
273
- * longer valid. When `onReset` is called, you should discard previously received data.
274
- *
275
- * If your `onReset` function throws an error, the iterator will end and you will not receive any
276
- * more messages until `onReset` is called again. Your error will appear in the problems sidebar
277
- * for user visibility.
278
- */
279
- onReset: (batchIterator: AsyncIterable<Immutable<MessageEvent[]>>) => Promise<void>;
280
- };
281
-
282
- export type PanelExtensionContext = {
283
- /**
284
- * The root element for the panel. Add your panel elements as children under this element.
285
- */
286
- readonly panelElement: HTMLDivElement;
287
-
288
- /**
289
- * Initial panel state
290
- */
291
- readonly initialState: unknown;
292
-
293
- /** Actions the panel may perform related to the user's current layout. */
294
- readonly layout: LayoutActions;
295
-
296
- /**
297
- * Identifies the semantics of the data being played back, such as which topics or parameters
298
- * are semantically meaningful or normalization conventions to use. This typically maps to a
299
- * shorthand identifier for a robotics framework such as "ros1", "ros2", or "ulog". See the MCAP
300
- * profiles concept at <https://github.com/foxglove/mcap/blob/main/docs/specification/appendix.md#well-known-profiles>.
301
- */
302
- readonly dataSourceProfile?: string;
303
-
304
- /**
305
- * Subscribe to updates on this field within the render state. Render will only be invoked when
306
- * this field changes.
307
- */
308
- watch: (field: keyof RenderState) => void;
309
-
310
- /**
311
- * Save arbitrary object as persisted panel state. This state is persisted for the panel
312
- * within a layout.
313
- *
314
- * The state value should be JSON serializable.
315
- */
316
- saveState: (state: Partial<unknown>) => void;
317
-
318
- /**
319
- * Set the value of parameter name to value.
320
- *
321
- * @param name The name of the parameter to set.
322
- * @param value The new value of the parameter.
323
- */
324
- setParameter: (name: string, value: ParameterValue) => void;
325
-
326
- /**
327
- * Set the transient state shared by panels of the same type as the caller of this function.
328
- * This will not be persisted in the layout.
329
- */
330
- setSharedPanelState: (state: undefined | Record<string, unknown>) => void;
331
-
332
- /**
333
- * Set the value of variable name to value.
334
- *
335
- * @param name The name of the variable to set.
336
- * @param value The new value of the variable.
337
- */
338
- setVariable: (name: string, value: VariableValue) => void;
339
-
340
- /**
341
- * Set the active preview time. Setting the preview time to undefined clears the preview time.
342
- */
343
- setPreviewTime: (time: number | undefined) => void;
344
-
345
- /**
346
- * Seek playback to the given time. Behaves as if the user had clicked the playback bar
347
- * to seek.
348
- *
349
- * Clients can pass a number or alternatively a Time object for greater precision.
350
- */
351
- seekPlayback?: (time: number | Time) => void;
352
-
353
- /**
354
- * Subscribe to an array of topic names.
355
- *
356
- * Subscribe will update the current subscriptions to the list of topic names. Passing an empty
357
- * array will unsubscribe from all topics.
358
- *
359
- * Calling subscribe with an empty array of topics is analagous to unsubscribeAll.
360
- *
361
- * @deprecated Use `subscribe` with an array of Subscription objects instead.
362
- */
363
- subscribe(topics: string[]): void;
364
-
365
- /**
366
- * Subscribe to an array of topics with additional options for each subscription.
367
- *
368
- * Subscribe will update the current subscriptions to the new list of Subscriptions and
369
- * unsubscribe from any previously subscribed topics no longer in the Subscription list. Passing
370
- * an empty array will unsubscribe from all topics.
371
- *
372
- * Calling subscribe with an empty array is analagous to unsubscribeAll.
373
- */
374
- subscribe(subscriptions: Subscription[]): void;
375
-
376
- /**
377
- * Unsubscribe from all topics.
378
- *
379
- * Note: This is analagous to calling subscribe([]) with an empty array of topics.
380
- */
381
- unsubscribeAll(): void;
382
-
383
- /**
384
- * Subscribe to any changes in application settings for an array of setting names.
385
- */
386
- subscribeAppSettings(settings: string[]): void;
387
-
388
- /**
389
- * Indicate intent to publish messages on a specific topic.
390
- *
391
- * @param topic The topic on which the extension will publish messages.
392
- * @param schemaName The name of the schema that the published messages will conform to.
393
- * @param options Options passed to the current data source for additional configuration.
394
- */
395
- advertise?(topic: string, schemaName: string, options?: Record<string, unknown>): void;
396
-
397
- /**
398
- * Indicate that you no longer want to advertise on this topic.
399
- */
400
- unadvertise?(topic: string): void;
401
-
402
- /**
403
- * Publish a message on a given topic. You must first advertise on the topic before publishing.
404
- *
405
- * @param topic The name of the topic to publish the message on
406
- * @param message The message to publish
407
- */
408
- publish?(topic: string, message: unknown): void;
409
-
410
- /**
411
- * Call a service.
412
- *
413
- * @param service The name of the service to call
414
- * @param request The request payload for the service call
415
- * @returns A promise that resolves when the result is available or rejected with an error
416
- */
417
- callService?(service: string, request: unknown): Promise<unknown>;
418
-
419
- /**
420
- * Process render events for the panel. Each render event receives a render state and a done callback.
421
- * Render events occur frequently (60hz, 30hz, etc).
422
- *
423
- * The done callback should be called once the panel has rendered the render state.
424
- */
425
- onRender?: (renderState: Immutable<RenderState>, done: () => void) => void;
426
-
427
- /**
428
- * Updates the panel's settings editor. Call this every time you want to update
429
- * the representation of the panel settings in the editor.
430
- */
431
- updatePanelSettingsEditor(settings: Immutable<SettingsTree>): void;
432
-
433
- /**
434
- * Updates the panel's default title. Users can always override the default title by editing it
435
- * manually. A value of `undefined` will display the panel's name in the title bar.
436
- */
437
- setDefaultPanelTitle(defaultTitle: string | undefined): void;
438
- /**
439
- * NOTE: UNSTABLE API SUBJECT TO CHANGE
440
- *
441
- * Subscribe to receive the entire time range of messages for a given topic for the current data source.
442
- *
443
- * See `SubscribeMessageRangeArgs` for more information on behavior.
444
- *
445
- * Note: This will not read messages for live sources, like foxglove bridge, rosbridge, or ROS1
446
- * native. For those messages you will still need to use `context.subscribe()` and
447
- * watch("currentFrame").
448
- *
449
- * @returns A function that will unsubscribe from the topic, cancel the active async iterator,
450
- * and prevent `onReset` from being called again.
451
- */
452
- UNSTABLE_subscribeMessageRange?: (args: SubscribeMessageRangeArgs) => () => void;
453
- };
454
-
455
- export type ExtensionPanelRegistration = {
456
- // Unique name of the panel within your extension
457
- //
458
- // NOTE: Panel names within your extension must be unique. The panel name identifies this panel
459
- // within a layout. Changing the panel name will cause layouts using the old name unable to load
460
- // your panel.
461
- name: string;
462
-
463
- /**
464
- * This function is invoked when your panel is initialized
465
- * @return: (optional) A function which is called when the panel is removed or replaced. Typically intended for cleanup logic to gracefully teardown your panel.
466
- */
467
- initPanel: (context: PanelExtensionContext) => void | (() => void);
468
- };
469
-
470
- export type RegisterMessageConverterArgs<Src> = {
471
- fromSchemaName: string;
472
- toSchemaName: string;
473
- converter: (msg: Src, event: Immutable<MessageEvent<Src>>) => unknown;
474
- };
475
-
476
- type BaseTopic = { name: string; schemaName?: string };
477
- type TopicAlias = { name: string; sourceTopicName: string };
478
-
479
- /**
480
- * An AliasFunction takes a list of data source topics and variables and outputs
481
- * a list of aliased topics.
482
- */
483
- export type TopicAliasFunction = (
484
- args: Immutable<{
485
- topics: BaseTopic[];
486
- globalVariables: Readonly<Record<string, VariableValue>>;
487
- }>,
488
- ) => TopicAlias[];
489
-
490
- export interface ExtensionContext {
491
- /** The current _mode_ of the application. */
492
- readonly mode: "production" | "development" | "test";
493
-
494
- registerPanel(params: ExtensionPanelRegistration): void;
495
-
496
- /**
497
- * Register a function to convert messages from one schema to another.
498
- *
499
- * A converter function is invoked when a panel subscribes to a topic with the `convertTo` option.
500
- * The return value of the converter function is the converted message and is provided to the
501
- * panel.
502
- *
503
- * If the converter function invocation returns _undefined_, the output of the converter for that
504
- * message is ignored and no message is provided to the panel. This is useful in instances where
505
- * you might want to selectively output a converted schema depending on the input message.
506
- */
507
- registerMessageConverter<Src>(args: RegisterMessageConverterArgs<Src>): void;
508
-
509
- /**
510
- * Registers a new alias function with the extension context. The function will be
511
- * called every time there is a new set of topics and variables and returns an array of
512
- * topic aliases.
513
- */
514
- registerTopicAliases(aliasFunction: TopicAliasFunction): void;
515
- }
516
-
517
- export type ExtensionActivate = (extensionContext: ExtensionContext) => void;
518
-
519
- // ExtensionModule describes the interface your extension entry level module must export
520
- // as its default export
521
- export interface ExtensionModule {
522
- activate: ExtensionActivate;
523
- }
524
-
525
- export type SettingsIcon =
526
- | "Add"
527
- | "Addchart"
528
- | "AutoAwesome"
529
- | "Background"
530
- | "Camera"
531
- | "Cells"
532
- | "Check"
533
- | "Circle"
534
- | "Clear"
535
- | "Clock"
536
- | "Collapse"
537
- | "Cube"
538
- | "Delete"
539
- | "Expand"
540
- | "Flag"
541
- | "Folder"
542
- | "FolderOpen"
543
- | "Grid"
544
- | "Hive"
545
- | "ImageProjection"
546
- | "Map"
547
- | "Move"
548
- | "MoveDown"
549
- | "MoveUp"
550
- | "NorthWest"
551
- | "Note"
552
- | "NoteFilled"
553
- | "Points"
554
- | "PrecisionManufacturing"
555
- | "Radar"
556
- | "Settings"
557
- | "Shapes"
558
- | "Share"
559
- | "Star"
560
- | "SouthEast"
561
- | "Timeline"
562
- | "Topic"
563
- | "Walk"
564
- | "World";
565
-
566
- /**
567
- * A settings tree field specifies the input type and the value of a field
568
- * in the settings editor.
569
- */
570
- export type SettingsTreeFieldValue =
571
- | {
572
- input: "autocomplete";
573
- value?: string;
574
- items: string[];
575
-
576
- /**
577
- * Optional placeholder text displayed in the field input when value is undefined
578
- */
579
- placeholder?: string;
580
- }
581
- | { input: "boolean"; value?: boolean }
582
- | {
583
- input: "rgb";
584
- value?: string;
585
-
586
- /**
587
- * Optional placeholder text displayed in the field input when value is undefined
588
- */
589
- placeholder?: string;
590
-
591
- /**
592
- * Optional field that's true if the clear button should be hidden.
593
- */
594
- hideClearButton?: boolean;
595
- }
596
- | {
597
- input: "rgba";
598
- value?: string;
599
-
600
- /**
601
- * Optional placeholder text displayed in the field input when value is undefined
602
- */
603
- placeholder?: string;
604
-
605
- /**
606
- * Optional field that's true if the clear button should be hidden.
607
- */
608
- hideClearButton?: boolean;
609
- }
610
- | { input: "gradient"; value?: [string, string] }
611
- | {
612
- input: "messagepath";
613
- value?: string;
614
- validTypes?: string[];
615
- /** True if the input should allow math modifiers like @abs. */
616
- supportsMathModifiers?: boolean;
617
- }
618
- | {
619
- input: "number";
620
- value?: number;
621
- step?: number;
622
- max?: number;
623
- min?: number;
624
- precision?: number;
625
-
626
- /**
627
- * Optional placeholder text displayed in the field input when value is undefined
628
- */
629
- placeholder?: string;
630
- }
631
- | {
632
- input: "select";
633
- value?: number | number[];
634
- options: Array<{ label: string; value: undefined | number; disabled?: boolean }>;
635
- }
636
- | {
637
- input: "select";
638
- value?: string | string[];
639
- options: Array<{ label: string; value: undefined | string; disabled?: boolean }>;
640
- }
641
- | {
642
- input: "string";
643
- value?: string;
644
-
645
- /**
646
- * Optional placeholder text displayed in the field input when value is undefined
647
- */
648
- placeholder?: string;
649
- }
650
- | {
651
- input: "toggle";
652
- value?: string;
653
- options: string[] | Array<{ label: string; value: undefined | string }>;
654
- }
655
- | {
656
- input: "toggle";
657
- value?: number;
658
- options: number[] | Array<{ label: string; value: undefined | number }>;
659
- }
660
- | {
661
- input: "vec3";
662
- value?: [undefined | number, undefined | number, undefined | number];
663
- placeholder?: [undefined | string, undefined | string, undefined | string];
664
- step?: number;
665
- precision?: number;
666
- labels?: [string, string, string];
667
- max?: number;
668
- min?: number;
669
- }
670
- | {
671
- input: "vec2";
672
- value?: [undefined | number, undefined | number];
673
- placeholder?: [undefined | string, undefined | string];
674
- step?: number;
675
- precision?: number;
676
- labels?: [string, string];
677
- max?: number;
678
- min?: number;
679
- };
680
-
681
- export type SettingsTreeField = SettingsTreeFieldValue & {
682
- /**
683
- * True if the field is disabled.
684
- */
685
- disabled?: boolean;
686
-
687
- /**
688
- * Optional help text to explain the purpose of the field.
689
- */
690
- help?: string;
691
-
692
- /**
693
- * The label displayed alongside the field.
694
- */
695
- label: string;
696
-
697
- /**
698
- * True if the field is readonly.
699
- */
700
- readonly?: boolean;
701
-
702
- /**
703
- * Optional message indicating any error state for the field.
704
- */
705
- error?: string;
706
- };
707
-
708
- export type SettingsTreeFields = Record<string, undefined | SettingsTreeField>;
709
-
710
- export type SettingsTreeChildren = Record<string, undefined | SettingsTreeNode>;
711
-
712
- export type SettingsTreeNodeActionItem = {
713
- type: "action";
714
-
715
- /**
716
- * A unique idenfier for the action.
717
- */
718
- id: string;
719
-
720
- /**
721
- * A descriptive label for the action.
722
- */
723
- label: string;
724
-
725
- /**
726
- * Optional icon to display with the action.
727
- */
728
- icon?: SettingsIcon;
729
-
730
- /**
731
- * Specifies whether the item is rendered as an inline action or as an item in the
732
- * context menu. Defaults to "menu" if not specified. Inline items will be rendered
733
- * as an icon only if their icon is specified.
734
- */
735
- display?: "menu" | "inline";
736
- };
737
-
738
- export type SettingsTreeNodeActionDivider = { type: "divider" };
739
-
740
- /**
741
- * An action included in the action menu for a settings node.
742
- */
743
- export type SettingsTreeNodeAction = SettingsTreeNodeActionItem | SettingsTreeNodeActionDivider;
744
-
745
- export type SettingsTreeNode = {
746
- /**
747
- * An array of actions that can be performed on this node.
748
- */
749
- actions?: SettingsTreeNodeAction[];
750
-
751
- /**
752
- * Other settings tree nodes nested under this node.
753
- */
754
- children?: SettingsTreeChildren;
755
-
756
- /**
757
- * Set to collapsed if the node should be initially collapsed.
758
- */
759
- defaultExpansionState?: "collapsed" | "expanded";
760
-
761
- /**
762
- * Optional message indicating any error state for the node.
763
- */
764
- error?: string;
765
-
766
- /**
767
- * Field inputs attached directly to this node.
768
- */
769
- fields?: SettingsTreeFields;
770
-
771
- /**
772
- * Optional icon to display next to the node label.
773
- */
774
- icon?: SettingsIcon;
775
-
776
- /**
777
- * An optional label shown at the top of this node.
778
- */
779
- label?: string;
780
-
781
- /**
782
- * True if the node label can be edited by the user.
783
- */
784
- renamable?: boolean;
785
-
786
- /**
787
- * Optional sort order to override natural object ordering. All nodes
788
- * with a sort order will be rendered before nodes all with no sort order.
789
- *
790
- * Nodes without an explicit order will be ordered according to ECMA
791
- * object ordering rules.
792
- *
793
- * https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
794
- */
795
- order?: number | string;
796
-
797
- /**
798
- * An optional visibility status. If this is not undefined, the node
799
- * editor will display a visiblity toggle button and send update actions
800
- * to the action handler.
801
- **/
802
- visible?: boolean;
803
-
804
- /**
805
- * Filter Children by visibility status
806
- */
807
- enableVisibilityFilter?: boolean;
808
- };
809
-
810
- /**
811
- * Distributes Pick<T, K> across all members of a union, used for extracting structured
812
- * subtypes.
813
- */
814
- type DistributivePick<T, K extends keyof T> = T extends unknown ? Pick<T, K> : never;
815
-
816
- /**
817
- * Represents actions that can be dispatched to source of the SettingsTree to implement
818
- * edits and updates.
819
- */
820
- export type SettingsTreeAction =
821
- | {
822
- action: "update";
823
- payload: { path: readonly string[] } & DistributivePick<
824
- SettingsTreeFieldValue,
825
- "input" | "value"
826
- >;
827
- }
828
- | {
829
- action: "perform-node-action";
830
- payload: { id: string; path: readonly string[] };
831
- };
832
-
833
- export type SettingsTreeNodes = Record<string, undefined | SettingsTreeNode>;
834
-
835
- /**
836
- * A settings tree is a tree of panel settings that can be displayed and edited in
837
- * the panel settings sidebar.
838
- *
839
- * Nodes and fields in the tree can be referred to by a string path, which collects
840
- * the keys of each node on the path from the root to the child node or field.
841
- *
842
- * For example, for the following tree:
843
- *
844
- * root: {
845
- * children: {
846
- * a: {
847
- * children: {
848
- * b: {
849
- * fields: {
850
- * toggleMe: {
851
- * label: "Toggle me",
852
- * input: "boolean",
853
- * value: false,
854
- * },
855
- * },
856
- * },
857
- * },
858
- * },
859
- * },
860
- * },
861
- *
862
- * the path to the node at b would be ["a", "b"] and the path to the toggleMe
863
- * field would be ["a", "b", "toggleMe"]. These paths are used in the
864
- * actionHandler, which responds to updates to values in the tree, and also in
865
- * the focusedPath, which is used to focus the editor UI at a particular node
866
- * in the tree.
867
- */
868
- export type SettingsTree = {
869
- /**
870
- * Handler to process all actions on the settings tree initiated by the UI.
871
- */
872
- actionHandler: (action: SettingsTreeAction) => void;
873
-
874
- /**
875
- * True if the settings editor should show the filter control.
876
- */
877
- enableFilter?: boolean;
878
-
879
- /**
880
- * Setting this will have a one-time effect of scrolling the editor to the
881
- * node at the path and highlighting it. This is a transient effect so it is
882
- * not necessary to subsequently unset this.
883
- */
884
- focusedPath?: readonly string[];
885
-
886
- /**
887
- * The settings tree root nodes. Updates to these will automatically be
888
- * reflected in the editor UI.
889
- */
890
- nodes: SettingsTreeNodes;
891
- };
3
+ export type { Experimental } from "./experimental";