@vestra-player/sdk 1.6.22 → 1.7.1

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 (57) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/bin/vestra-plugin.mjs +34 -12
  3. package/dist/api-requests.d.ts +22 -0
  4. package/dist/api-requests.js +38 -0
  5. package/dist/capability-check.d.ts +48 -0
  6. package/dist/capability-check.js +219 -51
  7. package/dist/capability-rules.d.ts +21 -0
  8. package/dist/capability-rules.js +32 -1
  9. package/dist/commands.d.ts +8 -0
  10. package/dist/commands.js +11 -11
  11. package/dist/docs-tree.json.gz +0 -0
  12. package/dist/plugin/commands.js +43 -13
  13. package/dist/plugin/connection.d.ts +37 -0
  14. package/dist/plugin/connection.js +34 -0
  15. package/dist/plugin/index.js +12 -2
  16. package/dist/plugin/media.js +3 -1
  17. package/dist/plugin/packages.js +3 -1
  18. package/dist/plugin/passes.d.ts +38 -1
  19. package/dist/plugin/passes.js +89 -5
  20. package/dist/plugin/player/events.d.ts +9 -0
  21. package/dist/plugin/player/events.js +43 -0
  22. package/dist/plugin/player/rules.d.ts +7 -0
  23. package/dist/plugin/player/rules.js +11 -0
  24. package/dist/plugin/player.d.ts +37 -4
  25. package/dist/plugin/player.js +85 -12
  26. package/dist/plugin/resolvers.js +2 -3
  27. package/dist/plugin/runtime.d.ts +2 -3
  28. package/dist/plugin/runtime.js +8 -2
  29. package/dist/plugin/scope.d.ts +9 -0
  30. package/dist/plugin/scope.js +24 -0
  31. package/dist/plugin/services.js +4 -5
  32. package/dist/plugin/state.d.ts +3 -0
  33. package/dist/plugin/state.js +81 -0
  34. package/dist/plugin/stream.d.ts +27 -3
  35. package/dist/plugin/testing/core-actions.js +1 -1
  36. package/dist/plugin/testing/services.js +1 -1
  37. package/dist/plugin/types/base.d.ts +78 -2
  38. package/dist/plugin/types/commands.d.ts +17 -1
  39. package/dist/plugin/types/playback.d.ts +156 -1
  40. package/dist/plugin/types/plugin-wire.d.ts +589 -0
  41. package/dist/plugin/types/plugin-wire.js +1 -0
  42. package/dist/plugin/types/ui-content.d.ts +23 -4
  43. package/dist/plugin/types/ui-shell.d.ts +1 -0
  44. package/dist/plugin/types.d.ts +4 -2
  45. package/dist/plugin/view/base.d.ts +10 -3
  46. package/dist/plugin/view/base.js +30 -6
  47. package/dist/plugin/view/binder.js +8 -1
  48. package/dist/plugin/view/writer.d.ts +49 -4
  49. package/dist/plugin/view/writer.js +383 -17
  50. package/dist/plugin/wire-facade.d.ts +4 -0
  51. package/dist/plugin/wire-facade.js +190 -0
  52. package/dist/ts-plugin.d.ts +3 -0
  53. package/dist/ts-plugin.js +18 -6
  54. package/dist/wire.d.ts +233 -20
  55. package/llms.txt +3 -3
  56. package/package.json +1 -1
  57. package/slint/vestra/focus.slint +33 -0
@@ -0,0 +1,589 @@
1
+ import type { Scope } from "./base.ts";
2
+ import type { CommandOptions, Commands } from "./commands.ts";
3
+ import type { Player } from "./playback.ts";
4
+ import type { Panel, Window } from "./ui-layout.ts";
5
+ import type { SettingsPage } from "./ui-shell.ts";
6
+ import type { Json, PropertyWrite, RowOp } from "../../wire.ts";
7
+ import type { Disposable } from "./base.ts";
8
+ import type { HostEvent } from "./playback.ts";
9
+ import type { View } from "./ui-content.ts";
10
+ /**
11
+ * Direct messages to the player (`plugin.wire`): requests by method name,
12
+ * raw events, property writes below the SDK's comparison and bare command
13
+ * registrations. Experimental: the wire protocol is not semver; this member
14
+ * changes with versions.
15
+ *
16
+ * @remarks
17
+ * The plugin API wraps the player's protocol (JSON requests and events over
18
+ * the plugin's standard input and output) in typed members that keep state,
19
+ * compare values and recover from lost replies. `plugin.wire` is the layer
20
+ * below them, for trying a player method the SDK does not wrap yet, or for
21
+ * a plugin that wants to send exactly what it chooses. Prefer the typed
22
+ * members: they are semver, `plugin.wire` is not. A method or event can
23
+ * change or disappear with a player version, and members of `plugin.wire`
24
+ * may change in any SDK release without a deprecation period.
25
+ *
26
+ * What the SDK still does at this level: `on` marks its subscription as a
27
+ * listener with where it was added (so the player keeps the plugin running
28
+ * and names the listener in its log), `view(v)` sends one write per property
29
+ * at a time and splits large ones, and `commands.register` waits during
30
+ * activation like `commands.add`. What it leaves to the plugin: the
31
+ * parameters' shape, the value limits, revisions of `request`, retries. The
32
+ * player still checks every capability, so a method needs the capability
33
+ * the player's table gives it (`vestra-plugin check` reads a literal method
34
+ * name and says which one; a method name it cannot read is reported as
35
+ * unchecked).
36
+ *
37
+ * [Three ways to write a plugin](../../../docs/explanation/three-ways.md)
38
+ * compares `bind()` (the default), {@link Player.on} with
39
+ * {@link View.set}, and `plugin.wire` on four scenarios; the method and
40
+ * event names are in [Messages](../../../docs/reference/messages.md) and
41
+ * [Events](../../../docs/reference/events.md).
42
+ *
43
+ * @example Show the speed with direct messages
44
+ * A bottom panel shows the playback speed, written by the plugin itself
45
+ * from the raw `source.state` event. The listener types the payload, which
46
+ * is `unknown` here, and `view(bar).write` sends the text as a property
47
+ * write; the SDK keeps no copy of the state and compares nothing.
48
+ * ```ts
49
+ * const bar = plugin.panels.mount("bottom", "ui/bar.slint");
50
+ * const view = plugin.wire.view(bar);
51
+ * plugin.wire.on("source.state", (data) => {
52
+ * const s = data as { rate: number }; // the plugin types the payload
53
+ * void view.write("rate", { value: `${s.rate.toFixed(2)}×` });
54
+ * });
55
+ * ```
56
+ *
57
+ * @capability That of each method and event: the player's capability
58
+ * table, as `vestra-plugin check` reports it.
59
+ * @experimental
60
+ * @since 1.7.0
61
+ * @category Plugin
62
+ */
63
+ export interface Wire {
64
+ /**
65
+ * Send one request to the player by its method name and get its answer.
66
+ *
67
+ * @remarks
68
+ * Experimental: the wire protocol is not semver; this member changes
69
+ * with versions. `method` and `params` go to the player as given; the
70
+ * answer is the player's result, typed by the caller (`T`). The player
71
+ * checks the capability the method needs and refuses with `capability`
72
+ * when the manifest does not declare it; its other refusals arrive with
73
+ * their own codes (`invalid`, `missing`, `stale`…). A method an older
74
+ * player does not know is refused with `unsupported` or `invalid`: compare
75
+ * `plugin.app.version` with the player that added it.
76
+ *
77
+ * Nothing of the SDK's sits between: no value limits, no `seq` or
78
+ * revision, no retry after a lost reply, no wait during activation. A
79
+ * request that changes something the SDK keeps (a window the SDK opened,
80
+ * a command added with {@link Commands.add}) leaves the SDK's copy out of
81
+ * date. The subscriptions are guarded. For the events the SDK knows
82
+ * ({@link HostEvent}) `events.subscribe` and `events.unsubscribe` are
83
+ * refused: the player keeps one subscription per event name, with one
84
+ * mark, and the SDK owns those (its copies of the state,
85
+ * {@link Player.on}); listen with {@link Wire.on} and stop by disposing
86
+ * what it returned. For any other event (a newer player's)
87
+ * `events.subscribe` must say why the plugin listens, `why` (a list of
88
+ * reasons for the player's log) or `mirror: true` (only a copy of the
89
+ * state), so the player's decision to keep the plugin running is never
90
+ * fooled; the SDK does not count such a subscription, the plugin
91
+ * unsubscribes it itself.
92
+ *
93
+ * @param method - The player's method name (`"ui.setMount"`).
94
+ * @param params - Its parameters, a JSON object (omitted: none).
95
+ * @returns The player's result, once the player answered.
96
+ *
97
+ * @throws `invalid` (throws) `method` is not a non-empty string, it is
98
+ * `events.subscribe` or `events.unsubscribe` of a {@link HostEvent},
99
+ * or `events.subscribe` of another event without `why` (a non-empty
100
+ * list of strings) or `mirror: true`.
101
+ * @throws `capability` (rejects) The manifest does not declare the
102
+ * capability the method needs.
103
+ * @throws `unsupported` (rejects) The player does not know the method.
104
+ * @throws `disabled` (rejects) The plugin is stopping.
105
+ *
106
+ * @capability That of the method, from the player's capability table:
107
+ * `vestra-plugin check` names it for a literal method name.
108
+ *
109
+ * @example Write a panel property without the SDK
110
+ * The plugin's bottom panel shows "1.00×" in its `rate` property, written
111
+ * with the player's own request. The parameters are the protocol's
112
+ * (`property`, `value`); the player checks `ui.mount` and the value.
113
+ * ```ts
114
+ * const bar = plugin.panels.mount("bottom", "ui/bar.slint");
115
+ * await bar.ready;
116
+ * await plugin.wire.request("ui.setMount", { property: "rate", value: "1.00×" });
117
+ * ```
118
+ *
119
+ * @experimental
120
+ * @since 1.7.0
121
+ */
122
+ request<T = unknown>(method: string, params?: Json): Promise<T>;
123
+ /**
124
+ * Listen to one event of the player by its name, with its data as the
125
+ * player sent it, untyped.
126
+ *
127
+ * @remarks
128
+ * Experimental: the wire protocol is not semver; this member changes
129
+ * with versions. For one of the {@link HostEvent} names the SDK subscribes
130
+ * (`events.subscribe`) as for {@link Player.on}: once per name however
131
+ * many listeners, always marked as a listener with where it was added
132
+ * (`why`), never as a copy of the state (`mirror`), so the player keeps
133
+ * the plugin running while it listens. The event's capability is the
134
+ * same as for `Player.on` (`events` for most). Any other name is listened
135
+ * to without a subscription: events the player sends unasked
136
+ * (`commands.execute`, `ui.callback`, `ui.closed`), or an event of a newer
137
+ * player that the plugin subscribed to itself with {@link Wire.request}.
138
+ *
139
+ * The listener gets a copy of the data, typed `unknown`: the plugin
140
+ * checks its shape ({@link Player.on} types it for the known events). As
141
+ * for `Player.on`, no update pass follows the listener, and its errors
142
+ * go to {@link Scope.onError}.
143
+ *
144
+ * @param event - The event's name.
145
+ * @param listener - Receives each event's data.
146
+ * @returns A handle that stops listening; it is disposed with the scope.
147
+ *
148
+ * @throws `invalid` (throws) `event` is not a non-empty string, or
149
+ * `listener` is not a function.
150
+ *
151
+ * @capability That of the event: `events`, or `bindings.manage`,
152
+ * `commands`, `video.upscaling` as for {@link Player.on}; none for an
153
+ * event listened to without a subscription.
154
+ *
155
+ * @example Log each command the player runs for this plugin
156
+ * The listener hears the player's `commands.execute` event, which the
157
+ * player sends unasked when the user picks one of this plugin's commands.
158
+ * Its data names the command by its local id; the SDK still runs the
159
+ * command's own `run` too.
160
+ * ```ts
161
+ * plugin.wire.on("commands.execute", (data) => {
162
+ * const { id } = data as { id: string };
163
+ * console.log(`the player ran ${id}`);
164
+ * });
165
+ * ```
166
+ *
167
+ * @experimental
168
+ * @since 1.7.0
169
+ */
170
+ on(event: HostEvent | (string & {}), listener: (data: unknown) => void): Disposable;
171
+ /**
172
+ * Write a view's properties directly, below the SDK's comparison and
173
+ * row patches.
174
+ *
175
+ * @remarks
176
+ * Experimental: the wire protocol is not semver; this member changes
177
+ * with versions. `view` is a {@link Window}, {@link Panel} or
178
+ * {@link SettingsPage} of this plugin; the writes go to it as
179
+ * `ui.set`, `ui.setMount` or `settings.set`. See {@link WireView}.
180
+ *
181
+ * @param view - A window, panel or settings page this plugin made.
182
+ * @returns The view's direct writes.
183
+ *
184
+ * @throws `invalid` (throws) `view` is not a window, panel or settings
185
+ * page of this plugin.
186
+ *
187
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
188
+ *
189
+ * @example Write a list in rows
190
+ * The sidebar shows a list the plugin keeps itself. The first write sends
191
+ * the whole list; later changes are row operations on what the player
192
+ * shows, sent as they are.
193
+ * ```ts
194
+ * const side = plugin.panels.mount("sidebar", "ui/list.slint");
195
+ * await side.ready;
196
+ * const rows = plugin.wire.view(side);
197
+ * await rows.write("items", { value: [{ id: "a", label: "First" }] });
198
+ * await rows.writeRows("items", [{ op: "insert", at: 1, rows: [{ id: "b", label: "Second" }] }]);
199
+ * ```
200
+ *
201
+ * @experimental
202
+ * @since 1.7.0
203
+ */
204
+ view(view: View): WireView;
205
+ /** Bare command registrations, without state functions or update passes. */
206
+ readonly commands: WireCommands;
207
+ }
208
+ /**
209
+ * A view's properties written directly (`plugin.wire.view(v)`): whole
210
+ * values or row operations as the player takes them, sent as given.
211
+ * Experimental: the wire protocol is not semver; this member changes with
212
+ * versions.
213
+ *
214
+ * @remarks
215
+ * A property written here belongs to this track alone: `set()` or a
216
+ * `bind()` that produces it throws `invalid` ("property `rows` is written
217
+ * directly; bind it or write it, not both"; a binding's is reported to
218
+ * {@link Scope.onError} once), and a property already set or bound cannot
219
+ * be written here. That keeps the SDK's record of what the player shows
220
+ * correct for the properties it compares.
221
+ *
222
+ * What the SDK does for these writes: one write in flight per property, in
223
+ * order (a whole value drops the writes still waiting before it, which
224
+ * resolve `false`); with a player that takes row patches (behaviour from
225
+ * player 0.6.0) a whole value without `seq` gets one, a list larger than
226
+ * one request
227
+ * (512 KB of rows) goes in parts, and row operations are numbered and split
228
+ * the same way. What it leaves to the plugin: the value limits (the player
229
+ * refuses a value over them with `limit`), Markdown documents and images in
230
+ * wire form, and a `stale` refusal of row operations (the player shows
231
+ * something else than they apply on: write the whole value). Property
232
+ * names are written in camelCase or as in Slint, as for {@link View.set}.
233
+ *
234
+ * While the view does not show (a window before `show()`, a panel or
235
+ * settings page before `ready`, a closed one) a write is refused with
236
+ * `unavailable`, and so is one the player answers after the view closed
237
+ * or showed its initial properties again. When a window shows its initial
238
+ * properties again (shown after a close), a property written here shows
239
+ * its Slint default: write its whole value again before any
240
+ * {@link WireView.writeRows}. Disposing the view resolves the writes still
241
+ * waiting with `false`.
242
+ *
243
+ * @example Push a status line from a timer
244
+ * A window shows a status line that the plugin's own timer refreshes once
245
+ * a second. Each write replaces the one still waiting, so a slow player
246
+ * never queues stale text; the window's bound values are not involved.
247
+ * ```ts
248
+ * const status = plugin.windows.create("ui/status.slint");
249
+ * await status.show();
250
+ * const direct = plugin.wire.view(status); // writes below bind() and set()
251
+ * const timer = setInterval(() => {
252
+ * void direct.write("line", { value: new Date().toLocaleTimeString() });
253
+ * }, 1000);
254
+ * plugin.onDispose(() => clearInterval(timer));
255
+ * ```
256
+ *
257
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
258
+ * @experimental
259
+ * @since 1.7.0
260
+ * @category Plugin
261
+ */
262
+ export interface WireView {
263
+ /**
264
+ * Write one property: a whole value, or a row patch of the plugin's own.
265
+ *
266
+ * @remarks
267
+ * Experimental: the wire protocol is not semver; this member changes
268
+ * with versions. `{ value }` replaces the property; a player that takes
269
+ * row patches (behaviour from player 0.6.0) gets it with a `seq` (the
270
+ * SDK numbers it unless given) and a list over one request's size in
271
+ * parts with `more`.
272
+ * `{ patch: { base, seq, ops } }` is sent as given: `base` is the `seq`
273
+ * of the write it applies on. {@link WireView.writeRows} numbers patches
274
+ * for you.
275
+ *
276
+ * @param property - The Slint property's name.
277
+ * @param write - The write, as the player takes it.
278
+ * @returns `true` once the player took it; `false` when a newer whole
279
+ * value replaced it before it was sent.
280
+ *
281
+ * @throws `invalid` (throws) `property` is empty or set or bound already
282
+ * on this view, or `write` has neither `value` nor `patch`.
283
+ * @throws `unavailable` (rejects) The view does not show, or it closed
284
+ * or showed its initial properties again before the player answered.
285
+ * @throws `limit` (rejects) The player refused a value over its limits.
286
+ * @throws `stale` (rejects) A patch's `base` is not what the player
287
+ * shows.
288
+ *
289
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
290
+ *
291
+ * @example Show a frame counter
292
+ * A panel shows how many frames the plugin produced, pushed from the
293
+ * plugin's own loop. The write goes out at once; if the player is still
294
+ * busy with the previous one, only the newest count waits.
295
+ * ```ts
296
+ * const bar = plugin.panels.mount("bottom", "ui/bar.slint");
297
+ * await bar.ready;
298
+ * const view = plugin.wire.view(bar);
299
+ * let frames = 0;
300
+ * const tick = setInterval(() => void view.write("frames", { value: ++frames }), 100); // newest waits
301
+ * plugin.onDispose(() => clearInterval(tick));
302
+ * ```
303
+ *
304
+ * @experimental
305
+ * @since 1.7.0
306
+ */
307
+ write(property: string, write: PropertyWrite): Promise<boolean>;
308
+ /**
309
+ * Change a list property by row operations, numbered by the SDK.
310
+ *
311
+ * @remarks
312
+ * Experimental: the wire protocol is not semver; this member changes
313
+ * with versions. The operations apply, in order, on what the player shows
314
+ * for the property after this view's last direct write of it since the
315
+ * view showed its initial properties: `set` one row, `insert` rows,
316
+ * `remove` or `move` a run of rows, by index. Without such a write (the
317
+ * property was never written directly, or the window was shown again
318
+ * since) the player has no rows of the plugin's for it: write the whole
319
+ * value with {@link WireView.write} first. They go as one patch, or
320
+ * several applying on each other when they exceed one request (1024
321
+ * operations or 512 KB of rows). Needs a player that takes row patches
322
+ * (player 0.6.0).
323
+ *
324
+ * @param property - The Slint property's name.
325
+ * @param ops - The operations, applied in order.
326
+ * @returns `true` once the player applied them; `false` when a whole
327
+ * value written later replaced them before they were sent.
328
+ *
329
+ * @throws `invalid` (throws) `property` is empty or set or bound already
330
+ * on this view, or `ops` is not an array.
331
+ * @throws `unsupported` (rejects) The player takes no row patches.
332
+ * @throws `stale` (rejects) No whole value was written directly since
333
+ * the view showed its initial properties (refused before sending), or
334
+ * the player shows something else than the operations apply on: write
335
+ * the whole value.
336
+ * @throws `unavailable` (rejects) The view does not show.
337
+ *
338
+ * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
339
+ * @player 0.6.0
340
+ *
341
+ * @example Append a row to a long list
342
+ * A list of 20,000 entries gains one at its end. Only the new row crosses
343
+ * to the player, as one `insert`; the plugin wrote the whole list once
344
+ * before with `write`.
345
+ * ```ts
346
+ * declare const list: WireView;
347
+ * declare const count: number;
348
+ * // ---cut---
349
+ * await list.writeRows("entries", [
350
+ * { op: "insert", at: count, rows: [{ id: `e${count}`, label: "New entry" }] },
351
+ * ]);
352
+ * ```
353
+ *
354
+ * @experimental
355
+ * @since 1.7.0
356
+ */
357
+ writeRows(property: string, ops: readonly RowOp[]): Promise<boolean>;
358
+ }
359
+ /**
360
+ * Bare command registrations (`plugin.wire.commands`): the player's
361
+ * declaration as given, a state of values and a handler. Experimental: the
362
+ * wire protocol is not semver; this member changes with versions.
363
+ *
364
+ * @remarks
365
+ * {@link Commands.add} checks the options, builds the declaration and keeps
366
+ * function fields current through the update passes. `register` sends a
367
+ * declaration of the plugin's own making and leaves its state to explicit
368
+ * {@link WireCommand.update} calls. The player checks the declaration and
369
+ * refuses it as for `add`; during activation the registration is awaited
370
+ * and a refusal is handled like `add`'s (logged and skipped by the player's
371
+ * runner, failing `startPlugin` in tests).
372
+ *
373
+ * @example Register a menu item from a declaration
374
+ * Playback ▸ Cycle Speed, bound to C, from a declaration written as the
375
+ * player takes it. Picking it runs `run`, as for a command of `add`.
376
+ * ```ts
377
+ * plugin.wire.commands.register({
378
+ * id: "rate.cycle",
379
+ * declaration: {
380
+ * // the player's fields, as commands.register takes them
381
+ * title: "Cycle Speed",
382
+ * path: ["Playback", "Cycle Speed"],
383
+ * order: 0,
384
+ * group: "domain",
385
+ * radio: false,
386
+ * bindings: ["C"],
387
+ * focus: null,
388
+ * repeat: false,
389
+ * },
390
+ * run: () => plugin.player.setRate(1.5),
391
+ * });
392
+ * ```
393
+ *
394
+ * @capability commands
395
+ * @experimental
396
+ * @since 1.7.0
397
+ * @category Plugin
398
+ */
399
+ export interface WireCommands {
400
+ /**
401
+ * Register a command with a declaration as the player takes it.
402
+ *
403
+ * @remarks
404
+ * Experimental: the wire protocol is not semver; this member changes
405
+ * with versions. `declaration` is `commands.register`'s: `title`, `path`,
406
+ * `order`, `group`, `radio`, `bindings`, `focus`, `repeat`, and the
407
+ * fields newer players added (`button`, `category`, `home`: see
408
+ * {@link CommandOptions} for the player each needs). The SDK adds the id,
409
+ * the revision and the state and checks nothing in it: bindings must
410
+ * already be in the player's canonical form (`Ctrl+H`).
411
+ *
412
+ * @param options - The id, the declaration, the first state and the
413
+ * handler.
414
+ * @returns The command, owned by this scope.
415
+ *
416
+ * @throws `invalid` (throws) `id` is not a non-empty string, or
417
+ * `declaration` is not an object.
418
+ * @throws `conflict` (throws) A command of this plugin already has the id.
419
+ *
420
+ * @capability commands
421
+ *
422
+ * @example Register a command and turn it off later
423
+ * The command starts enabled; once the plugin has nothing to export, it
424
+ * greys it out with an explicit state. No update pass evaluates it.
425
+ * ```ts
426
+ * declare const declaration: { [field: string]: Json };
427
+ * // ---cut---
428
+ * const exporter = plugin.wire.commands.register({ id: "export", declaration });
429
+ * await exporter.update({ enabled: false, reason: "Nothing to export" });
430
+ * ```
431
+ *
432
+ * @experimental
433
+ * @since 1.7.0
434
+ */
435
+ register(options: WireCommandOptions): WireCommand;
436
+ }
437
+ /**
438
+ * What {@link WireCommands.register} takes: the command's local id, the
439
+ * player's declaration, its first state and the handler.
440
+ *
441
+ * @remarks
442
+ * Experimental: the wire protocol is not semver; this member changes with
443
+ * versions.
444
+ *
445
+ * @example Declare a checked item
446
+ * A toggle in the Video menu, shown checked from the start. The state
447
+ * fields are the player's (`enabled`, `checked`, `busy`, `reason`).
448
+ * ```ts
449
+ * const options: WireCommandOptions = {
450
+ * id: "grid",
451
+ * declaration: { title: "Grid", path: ["Video", "Grid"], order: 0, group: "domain",
452
+ * radio: false, bindings: [], focus: null, repeat: false },
453
+ * state: { checked: true }, // the player's state fields
454
+ * };
455
+ * plugin.wire.commands.register(options);
456
+ * ```
457
+ *
458
+ * @experimental
459
+ * @since 1.7.0
460
+ * @category Plugin
461
+ */
462
+ export interface WireCommandOptions {
463
+ /** The command's local id, unique within the plugin (as {@link CommandOptions.id}). */
464
+ readonly id: string;
465
+ /** The declaration, as the player's `commands.register` takes it. */
466
+ readonly declaration: {
467
+ readonly [field: string]: Json;
468
+ };
469
+ /**
470
+ * The first state; omitted fields are enabled, unchecked (`null`), not
471
+ * busy, no reason.
472
+ */
473
+ readonly state?: WireCommandState;
474
+ /** The player's conditions for `enabled` and `checked`, in wire form (player 0.5.21). */
475
+ readonly when?: Json;
476
+ /** Runs when the user picks the command or presses its key. */
477
+ readonly run?: () => unknown;
478
+ }
479
+ /**
480
+ * A command's state as the player takes it: `enabled`, `checked` (`null`:
481
+ * no check mark), `busy` and `reason` (a text, or `null`).
482
+ *
483
+ * @remarks
484
+ * Experimental: the wire protocol is not semver; this member changes with
485
+ * versions.
486
+ *
487
+ * @example Grey out a command with a reason
488
+ * The menu shows the command disabled, with the reason as its tooltip.
489
+ * ```ts
490
+ * declare const command: WireCommand;
491
+ * // ---cut---
492
+ * const state: WireCommandState = { enabled: false, reason: "Open a file first" };
493
+ * await command.update(state);
494
+ * ```
495
+ *
496
+ * @experimental
497
+ * @since 1.7.0
498
+ * @category Plugin
499
+ */
500
+ export interface WireCommandState {
501
+ /** The user can run it (default `true`). */
502
+ readonly enabled?: boolean;
503
+ /** A check mark: `true`, `false`, or `null` for none (default `null`). */
504
+ readonly checked?: boolean | null;
505
+ /** Shown as working (default `false`). */
506
+ readonly busy?: boolean;
507
+ /** Why it is disabled: source text or a text value in wire form, or `null` (default). */
508
+ readonly reason?: Json;
509
+ }
510
+ /**
511
+ * A command registered with {@link WireCommands.register}: its id, its
512
+ * registration and explicit state updates. Experimental: the wire protocol
513
+ * is not semver; this member changes with versions.
514
+ *
515
+ * @remarks
516
+ * Its state changes only through {@link WireCommand.update}; nothing is
517
+ * evaluated in the update passes. Disposing it (or its scope) removes it
518
+ * from the menu and the binding table. The player sends a pick as
519
+ * `commands.execute`; the SDK calls `run`, and {@link Wire.on} hears the
520
+ * event too.
521
+ *
522
+ * @example Show work in progress on a command
523
+ * The command shows busy while its export runs and normal again after. Each
524
+ * update is one request, numbered by the SDK.
525
+ * ```ts
526
+ * declare const declaration: { [field: string]: Json };
527
+ * declare function exportAll(): Promise<void>;
528
+ * // ---cut---
529
+ * const command = plugin.wire.commands.register({
530
+ * id: "export",
531
+ * declaration,
532
+ * run: async () => {
533
+ * await command.update({ busy: true }); // one commands.update each
534
+ * await exportAll().finally(() => command.update({ busy: false }));
535
+ * },
536
+ * });
537
+ * ```
538
+ *
539
+ * @capability commands
540
+ * @experimental
541
+ * @since 1.7.0
542
+ * @category Plugin
543
+ */
544
+ export interface WireCommand extends Disposable {
545
+ /** The local id given in {@link WireCommandOptions.id}. */
546
+ readonly id: string;
547
+ /**
548
+ * Resolves once the player registered it.
549
+ *
550
+ * @throws `invalid` (rejects) The player refused the declaration.
551
+ * @throws `conflict` (rejects) Another command has this menu path.
552
+ * @throws `capability` (rejects) The manifest does not declare `commands`.
553
+ * @throws `limit` (rejects) Too many commands in this plugin or the
554
+ * player.
555
+ */
556
+ readonly ready: Promise<void>;
557
+ /**
558
+ * Send a new state, merged into the last one sent.
559
+ *
560
+ * @remarks
561
+ * Experimental: the wire protocol is not semver; this member changes
562
+ * with versions. One `commands.update` with the next revision, after the
563
+ * registration; several calls are sent in order, the newest last. `when`
564
+ * replaces the conditions (omitted: the last ones sent stay).
565
+ *
566
+ * @param state - The fields to change.
567
+ * @param when - The player's conditions, in wire form.
568
+ * @returns Once the player took the new state.
569
+ *
570
+ * @throws `invalid` (rejects) The player refused the state.
571
+ * @throws `missing` (rejects) The command is not registered (refused, or
572
+ * disposed).
573
+ *
574
+ * @capability commands
575
+ *
576
+ * @example Check a command after its action
577
+ * The plugin turns its grid on and shows the check mark in the menu once
578
+ * the player took the state.
579
+ * ```ts
580
+ * declare const grid: WireCommand;
581
+ * // ---cut---
582
+ * await grid.update({ checked: true });
583
+ * ```
584
+ *
585
+ * @experimental
586
+ * @since 1.7.0
587
+ */
588
+ update(state: WireCommandState, when?: Json): Promise<void>;
589
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ import type { Plugin, Scope } from "./base.ts";
2
2
  import type { System } from "./services.ts";
3
3
  import type { Panel, Window } from "./ui-layout.ts";
4
4
  import type { SettingsPage } from "./ui-shell.ts";
5
+ import type { WireView } from "./plugin-wire.ts";
5
6
  import type { Json } from "../../wire.ts";
6
7
  import type { Disposable } from "./base.ts";
7
8
  import type { Text, TextList } from "./ui-locale.ts";
@@ -614,7 +615,16 @@ export interface View {
614
615
  * Do not `set` a property that a {@link View.bind} function also returns:
615
616
  * the next update pass replaces the set value with the bound one.
616
617
  *
617
- * Never throws. A write that fails is retried with back-off and reported
618
+ * On a view nothing was bound to, `set` alone writes (SDK 1.7.0): each
619
+ * value is sent whole, a large list in parts, one write in flight per
620
+ * view; the SDK neither compares nor turns lists into row patches, and
621
+ * the view takes no part in update passes. From the view's first
622
+ * {@link View.bind} on, `set` values go the bound way: a list that
623
+ * differs from the one sent is sent as a row patch where one applies.
624
+ *
625
+ * A property the plugin writes directly ({@link WireView.write}, SDK
626
+ * 1.7.0) cannot be `set`: one track per property. Otherwise it never
627
+ * throws. A write that fails is retried with back-off and reported
618
628
  * to {@link Scope.onError} (the first failure of a run of failures; the
619
629
  * message names the property). A value over the limits of
620
630
  * {@link PropValue} fails with `limit`. As an initial property (written
@@ -627,6 +637,10 @@ export interface View {
627
637
  *
628
638
  * @param props - Properties by name; see {@link Props}.
629
639
  *
640
+ * @throws `invalid` (throws) A property of `props` is written directly
641
+ * with {@link WireView.write} ("property `rows` is written directly;
642
+ * bind it or write it, not both"); nothing of `props` is kept.
643
+ *
630
644
  * @example Put a drop-down back when the user picks an entry the plugin refuses
631
645
  * Choosing "Custom" snaps the drop-down back to the last real preset.
632
646
  * The plugin cannot read a property back, only hear the callback; `set`
@@ -649,9 +663,11 @@ export interface View {
649
663
  *
650
664
  * @remarks
651
665
  * The SDK calls `props` in every update pass (and right after `bind`) and
652
- * sends the values that differ from the ones it sent last. After a change
653
- * of the player state alone it calls `props` only if it read a field of
654
- * `plugin.player.state` that changed (SDK 1.5.45); a full pass follows
666
+ * sends the values that differ from the ones it sent last; a view takes
667
+ * part in the update passes from its first `bind` on (SDK 1.7.0). After a
668
+ * change of the player state alone it calls `props` only if it read a
669
+ * field of `plugin.player.state` (or of a {@link Scope.state} object) that
670
+ * changed (SDK 1.5.45); a full pass follows
655
671
  * after each handler, on {@link Scope.update} and at least once a second
656
672
  * while the player state keeps changing. Because an
657
673
  * unchanged value is not sent again, text the user typed into an `in-out`
@@ -665,6 +681,9 @@ export interface View {
665
681
  * Never throws. Writes that fail are not repeated until the value
666
682
  * changes, and are reported to {@link Scope.onError} like a failed
667
683
  * {@link View.set} (a value over the limits of {@link PropValue}: `limit`).
684
+ * A property the plugin writes directly ({@link WireView.write}, SDK
685
+ * 1.7.0) is left out of what the function returns, reported once to
686
+ * `onError` with `invalid`: one track per property.
668
687
  *
669
688
  * @capability That of the view: `ui.window`, `ui.mount` or `ui.settings`.
670
689
  *
@@ -381,6 +381,7 @@ export interface Panels {
381
381
  * after 0.4.0): each panel is a tab, labelled `title` (else the plugin's
382
382
  * name), and the player draws a 31px tab strip above the current one
383
383
  * while there are two or more (with one panel, nothing changes).
384
+ * Before player 0.7.3 a ninth tab was refused with `conflict`.
384
385
  * Showing, hiding and detaching apply to the whole sidebar. If the
385
386
  * bridge global declares `in property <bool> tabbed`, the player sets
386
387
  * it to `true` while it draws the strip, so a panel with a tab strip of
@@ -13,11 +13,12 @@
13
13
  * and are re-exported here with `export type *`: this module exports the
14
14
  * same names as before the split.
15
15
  */
16
- import type { Json } from "../wire.ts";
16
+ import type { Json, PackageInfo, PropertyWrite, RowOp, WindowFacts, WireMark, WireRange, WireRenderingReason, WireSource, WireTimeline, WireUpscalingReason, WireUpscalingState } from "../wire.ts";
17
+ import type { CommandKeys } from "../commands.ts";
17
18
  import type { AudioNode, ConvolutionPlane, VideoNode } from "../processing.ts";
18
19
  import type { SubtitleStyle } from "../subtitles.ts";
19
20
  import type { ResolvedMedia } from "../source-resolvers.ts";
20
- export type { Json, AudioNode, ConvolutionPlane, VideoNode, SubtitleStyle, ResolvedMedia, };
21
+ export type { Json, PropertyWrite, RowOp, AudioNode, ConvolutionPlane, VideoNode, SubtitleStyle, ResolvedMedia, CommandKeys, PackageInfo, WindowFacts, WireMark, WireRange, WireRenderingReason, WireSource, WireTimeline, WireUpscalingReason, WireUpscalingState, };
21
22
  export type * from "./types/base.ts";
22
23
  export type * from "./types/commands.ts";
23
24
  export type * from "./types/ui-content.ts";
@@ -31,3 +32,4 @@ export type * from "./types/snapshots.ts";
31
32
  export type * from "./types/sources.ts";
32
33
  export type * from "./types/packages.ts";
33
34
  export type * from "./types/services.ts";
35
+ export type * from "./types/plugin-wire.ts";