@vestra-player/sdk 1.6.20 → 1.6.21
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/CHANGELOG.md +11 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/i18n-tools.js +7 -2
- package/dist/plugin/types/base.d.ts +1097 -0
- package/dist/plugin/types/base.js +1 -0
- package/dist/plugin/types/commands.d.ts +1189 -0
- package/dist/plugin/types/commands.js +1 -0
- package/dist/plugin/types/packages.d.ts +661 -0
- package/dist/plugin/types/packages.js +1 -0
- package/dist/plugin/types/playback.d.ts +1654 -0
- package/dist/plugin/types/playback.js +1 -0
- package/dist/plugin/types/processing.d.ts +974 -0
- package/dist/plugin/types/processing.js +1 -0
- package/dist/plugin/types/services.d.ts +1132 -0
- package/dist/plugin/types/services.js +1 -0
- package/dist/plugin/types/snapshots.d.ts +491 -0
- package/dist/plugin/types/snapshots.js +1 -0
- package/dist/plugin/types/sources.d.ts +302 -0
- package/dist/plugin/types/sources.js +1 -0
- package/dist/plugin/types/subtitles.d.ts +327 -0
- package/dist/plugin/types/subtitles.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +692 -0
- package/dist/plugin/types/ui-content.js +1 -0
- package/dist/plugin/types/ui-layout.d.ts +1079 -0
- package/dist/plugin/types/ui-layout.js +1 -0
- package/dist/plugin/types/ui-locale.d.ts +490 -0
- package/dist/plugin/types/ui-locale.js +1 -0
- package/dist/plugin/types/ui-shell.d.ts +1072 -0
- package/dist/plugin/types/ui-shell.js +1 -0
- package/dist/plugin/types.d.ts +18 -11072
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1079 @@
|
|
|
1
|
+
import type { MainWindow, Scope } from "./base.ts";
|
|
2
|
+
import type { PluginInfo } from "./packages.ts";
|
|
3
|
+
import type { Ui } from "./ui-content.ts";
|
|
4
|
+
import type { Dialogs, Panels, Settings } from "./ui-shell.ts";
|
|
5
|
+
import type { Disposable } from "./base.ts";
|
|
6
|
+
import type { Command } from "./commands.ts";
|
|
7
|
+
import type { View } from "./ui-content.ts";
|
|
8
|
+
/**
|
|
9
|
+
* A tool window: a separate operating-system window drawn from one of the
|
|
10
|
+
* plugin's `.slint` files, made by {@link Windows.create}.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* **What it is.** A top-level window with its own title bar: the user can
|
|
14
|
+
* move it, resize it (if the Slint file allows) and close it. It is not
|
|
15
|
+
* modal and not attached to the main window: playback and the main window
|
|
16
|
+
* keep working while it is open. Its title, size and content come from the
|
|
17
|
+
* Slint `Window` component (`title`, `width` or `preferred-width`…); the
|
|
18
|
+
* player applies its palette and the system font before the window appears.
|
|
19
|
+
* The system chooses its position; the player does not remember it.
|
|
20
|
+
* {@link MainWindow.setAlwaysOnTop} also floats tool windows.
|
|
21
|
+
*
|
|
22
|
+
* **Life cycle.**
|
|
23
|
+
* 1. `create()` makes the handle; nothing is on screen.
|
|
24
|
+
* 2. Bind callbacks with {@link View.on} and properties with
|
|
25
|
+
* {@link View.bind} or {@link View.set}.
|
|
26
|
+
* 3. {@link Window.show} opens the window with those properties.
|
|
27
|
+
* {@link Window.hide} hides it and keeps its state.
|
|
28
|
+
* 4. {@link Window.close}, or the user (title-bar button or the
|
|
29
|
+
* [standard close keys](../../../docs/reference/commands.md#keys-the-system-takes-first)), destroys the window instance; only the
|
|
30
|
+
* user's close calls {@link Window.onClose}. The handle stays usable: the
|
|
31
|
+
* next `show()` opens a fresh instance with the current properties.
|
|
32
|
+
* 5. `dispose()`, disposing the owning scope or the plugin stopping closes
|
|
33
|
+
* it for good (without `onClose`); the id can then be used again.
|
|
34
|
+
*
|
|
35
|
+
* Command key bindings do not fire while a tool window has focus; handle
|
|
36
|
+
* keys in Slint (a `FocusScope`). The standard close keys never reach the
|
|
37
|
+
* window's Slint code.
|
|
38
|
+
*
|
|
39
|
+
* Testing: `host.window(id)` of `@vestra-player/sdk/testing` has the
|
|
40
|
+
* window's `props`, `visible`, `emit(callback, ...args)` and `userClose()`.
|
|
41
|
+
*
|
|
42
|
+
* @capability ui.window
|
|
43
|
+
*
|
|
44
|
+
* @example Open a window from a menu command (examples/bookmark)
|
|
45
|
+
* Playback ▸ Bookmark… opens the Bookmark window. `create` only makes a
|
|
46
|
+
* handle; the command's `run` calls `show`, which compiles the Slint file
|
|
47
|
+
* and opens the window with the bound properties the first time, and
|
|
48
|
+
* brings back the same window afterwards.
|
|
49
|
+
*
|
|
50
|
+
* {@includeCode ../../../examples/bookmark/main.ts#window,command}
|
|
51
|
+
*
|
|
52
|
+
* @example Stop work when the user closes the window
|
|
53
|
+
* A clock window ticks every second while it is open and stops costing
|
|
54
|
+
* anything once the user closes it. `plugin.update()` makes the SDK
|
|
55
|
+
* evaluate the bound time again from a timer; `onClose` runs only for the
|
|
56
|
+
* user's close, so the plugin stops the timer there.
|
|
57
|
+
* ```ts
|
|
58
|
+
* const clock = plugin.windows.create("ui/clock.slint");
|
|
59
|
+
* let timer: NodeJS.Timeout | undefined;
|
|
60
|
+
* clock.bind(() => ({ time: new Date().toLocaleTimeString() }));
|
|
61
|
+
* clock.onClose(() => {
|
|
62
|
+
* clearInterval(timer);
|
|
63
|
+
* timer = undefined;
|
|
64
|
+
* });
|
|
65
|
+
* plugin.commands.add({
|
|
66
|
+
* id: "clock",
|
|
67
|
+
* path: ["@screen", "Clock…"],
|
|
68
|
+
* run: async () => {
|
|
69
|
+
* await clock.show();
|
|
70
|
+
* // Re-evaluate `bind` once a second: bound values change only then.
|
|
71
|
+
* timer ??= setInterval(() => plugin.update(), 1000);
|
|
72
|
+
* },
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @see {@link Windows.create}, {@link View}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md), [Remember a window's state between runs](../../../docs/how-to/window-state.md)
|
|
77
|
+
* @since 1.0.0
|
|
78
|
+
* @category UI
|
|
79
|
+
*/
|
|
80
|
+
export interface Window extends View, Disposable {
|
|
81
|
+
/**
|
|
82
|
+
* Open the window, or show it again if it is hidden.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* When no window instance exists (the first call, or after a close), the
|
|
86
|
+
* player compiles the Slint file and opens a new window. Its initial
|
|
87
|
+
* properties are the bound values and the values last passed to
|
|
88
|
+
* {@link View.set}, so no default values flash, and the callbacks bound
|
|
89
|
+
* so far are registered. When the window is hidden, it is shown again with
|
|
90
|
+
* its state.
|
|
91
|
+
*
|
|
92
|
+
* `show`, `hide` and `close` of one window run one after another in call
|
|
93
|
+
* order. After `dispose()`, `show` does nothing.
|
|
94
|
+
*
|
|
95
|
+
* @capability ui.window
|
|
96
|
+
*
|
|
97
|
+
* @returns Resolves once the player has shown the window.
|
|
98
|
+
*
|
|
99
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.window`.
|
|
100
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
101
|
+
* @throws `host` (rejects) The Slint file is missing, outside the package
|
|
102
|
+
* directory or does not compile; it exports more than one component; or
|
|
103
|
+
* a bound property or callback is not declared in it. `message` has the
|
|
104
|
+
* reason, including the compiler's diagnostics.
|
|
105
|
+
* @throws `missing` (rejects) An image in the initial properties does not
|
|
106
|
+
* exist (see {@link Ui.image}).
|
|
107
|
+
* @throws `invalid` (rejects) An image in the initial properties fails
|
|
108
|
+
* another check: outside the allowed directories, too large, not PNG or
|
|
109
|
+
* JPEG.
|
|
110
|
+
*
|
|
111
|
+
* @example Tell the user why a window did not open
|
|
112
|
+
* When the inspector cannot open, the user sees why on the OSD instead
|
|
113
|
+
* of nothing happening. `show` compiles the Slint file and opens the
|
|
114
|
+
* window; it rejects with a code, such as `host` for a Slint file that
|
|
115
|
+
* does not compile or `unavailable` without a user interface.
|
|
116
|
+
* ```ts
|
|
117
|
+
* const inspectorWindow = plugin.windows.create("ui/inspector.slint");
|
|
118
|
+
* try {
|
|
119
|
+
* await inspectorWindow.show();
|
|
120
|
+
* } catch (error) {
|
|
121
|
+
* // The code is data; `message` has the details for the log.
|
|
122
|
+
* await plugin.osd.show("Cannot open the inspector ({})", [(error as PluginError).code]);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*/
|
|
128
|
+
show(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Hide the window without closing it.
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* The instance and everything in it stay; {@link Window.opened} stays
|
|
134
|
+
* `true` and {@link Window.show} brings the window back as it was. Does
|
|
135
|
+
* nothing when the window is not open.
|
|
136
|
+
*
|
|
137
|
+
* @capability ui.window
|
|
138
|
+
*
|
|
139
|
+
* @returns Resolves once the window is hidden.
|
|
140
|
+
*
|
|
141
|
+
* @throws `missing` (rejects) The user closed the window just before (the
|
|
142
|
+
* close had not reached the plugin yet).
|
|
143
|
+
*
|
|
144
|
+
* @example Show and hide a window from a checkable menu item
|
|
145
|
+
* Audio ▸ Levels shows the window with a check mark and hides it again.
|
|
146
|
+
* `hide` keeps the window's instance and state, so showing it again is
|
|
147
|
+
* instant; the check mark follows `visible`, and `onClose` resets it when
|
|
148
|
+
* the user closes the window with its title-bar button.
|
|
149
|
+
* ```ts
|
|
150
|
+
* const levels = plugin.windows.create("ui/levels.slint");
|
|
151
|
+
* let visible = false; // what the check mark shows
|
|
152
|
+
* plugin.commands.add({
|
|
153
|
+
* id: "levels",
|
|
154
|
+
* path: ["@audio", "Levels"],
|
|
155
|
+
* checked: () => visible,
|
|
156
|
+
* run: async () => {
|
|
157
|
+
* visible = !visible;
|
|
158
|
+
* await (visible ? levels.show() : levels.hide());
|
|
159
|
+
* },
|
|
160
|
+
* });
|
|
161
|
+
* levels.onClose(() => (visible = false));
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @since 1.0.0
|
|
165
|
+
*/
|
|
166
|
+
hide(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Close the window and destroy its instance; the handle stays usable.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* The next {@link Window.show} opens a fresh instance with the current
|
|
172
|
+
* properties; state that only the Slint side had (text the plugin did not
|
|
173
|
+
* record) is gone. {@link Window.onClose} is not called. Does nothing when
|
|
174
|
+
* the window is not open. Unlike `dispose()`, the handle, its handlers and
|
|
175
|
+
* its bindings stay.
|
|
176
|
+
*
|
|
177
|
+
* @capability ui.window
|
|
178
|
+
*
|
|
179
|
+
* @returns Resolves once the window is closed.
|
|
180
|
+
*
|
|
181
|
+
* @throws `missing` (rejects) The user closed the window just before.
|
|
182
|
+
*
|
|
183
|
+
* @example Close the window from its own button
|
|
184
|
+
* The editor's Done button closes the editor window. `close` destroys
|
|
185
|
+
* the window instance but keeps the handle, its handlers and bindings,
|
|
186
|
+
* so the next `show` opens a fresh window; `onClose` is not called for
|
|
187
|
+
* the plugin's own close.
|
|
188
|
+
* ```ts
|
|
189
|
+
* const editor = plugin.windows.create("ui/editor.slint");
|
|
190
|
+
* editor.on("done", () => editor.close());
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @since 1.0.0
|
|
194
|
+
*/
|
|
195
|
+
close(): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Whether a window instance exists, shown or hidden: `false` before the
|
|
198
|
+
* first {@link Window.show}, after {@link Window.close}, after the user
|
|
199
|
+
* closed the window and after `dispose()`.
|
|
200
|
+
*/
|
|
201
|
+
readonly opened: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Run code when the user closes the window.
|
|
204
|
+
*
|
|
205
|
+
* @remarks
|
|
206
|
+
* Called for the title-bar close button and the
|
|
207
|
+
* [standard close keys](../../../docs/reference/commands.md#keys-the-system-takes-first). When it runs, the window
|
|
208
|
+
* instance is gone and {@link Window.opened} is already `false`; a later
|
|
209
|
+
* `show()` opens a fresh one. It is not called for the plugin's own
|
|
210
|
+
* {@link Window.close} or `dispose()`, nor when the plugin stops. Errors
|
|
211
|
+
* it throws go to {@link Scope.onError}, and an update pass follows.
|
|
212
|
+
*
|
|
213
|
+
* Stop what the window needed here: timers, polling, a live preview.
|
|
214
|
+
*
|
|
215
|
+
* @capability ui.window
|
|
216
|
+
*
|
|
217
|
+
* @param listener - Called with no arguments; may be async.
|
|
218
|
+
* @returns A handle that removes the listener.
|
|
219
|
+
*
|
|
220
|
+
* @example Remember that the user closed the window
|
|
221
|
+
* The plugin records that the notes window was closed, so it does not
|
|
222
|
+
* reopen it at the next start. `onClose` runs for the title-bar button,
|
|
223
|
+
* the player's close keys (Cmd+W, Ctrl+W, Ctrl+F4) and the system's own
|
|
224
|
+
* close request such as Alt+F4 (not for the plugin's own `close`); the
|
|
225
|
+
* store writes the change to `window.json` shortly after.
|
|
226
|
+
* ```ts
|
|
227
|
+
* const store = plugin.storage.json("window", { defaults: { open: false } });
|
|
228
|
+
* const notesWindow = plugin.windows.create("ui/notes.slint");
|
|
229
|
+
* notesWindow.onClose(() => store.save({ open: false }));
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @see [Remember a window's state between runs](../../../docs/how-to/window-state.md)
|
|
233
|
+
* @since 1.0.0
|
|
234
|
+
*/
|
|
235
|
+
onClose(listener: () => unknown): Disposable;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Create tool windows: separate windows drawn from the plugin's `.slint`
|
|
239
|
+
* files. `plugin.windows`.
|
|
240
|
+
*
|
|
241
|
+
* @remarks
|
|
242
|
+
* Use a tool window for something the user opens, works with and closes: a
|
|
243
|
+
* picture adjustment panel, an inspector, an editor. For content that should
|
|
244
|
+
* stay inside the player's main window, mount a {@link Panels | panel}; for
|
|
245
|
+
* preferences, add a {@link Settings.page | settings page}; for a yes/no
|
|
246
|
+
* question, use {@link Dialogs.confirm}. A plugin can have any number of
|
|
247
|
+
* windows.
|
|
248
|
+
*
|
|
249
|
+
* @capability ui.window
|
|
250
|
+
*
|
|
251
|
+
* @example Create a window and open it from a menu (examples/bookmark)
|
|
252
|
+
* A Bookmark window opens from Playback ▸ Bookmark…. `create` returns a
|
|
253
|
+
* handle without opening anything; its bindings and callbacks are set up
|
|
254
|
+
* first, and `show` opens the window when the command runs.
|
|
255
|
+
*
|
|
256
|
+
* {@includeCode ../../../examples/bookmark/main.ts#window,command}
|
|
257
|
+
*
|
|
258
|
+
* @see {@link Window}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md)
|
|
259
|
+
* @since 1.0.0
|
|
260
|
+
* @category UI
|
|
261
|
+
*/
|
|
262
|
+
export interface Windows {
|
|
263
|
+
/**
|
|
264
|
+
* Create a window handle for a `.slint` file; nothing opens until
|
|
265
|
+
* {@link Window.show}.
|
|
266
|
+
*
|
|
267
|
+
* @remarks
|
|
268
|
+
* The file must export exactly one component, usually
|
|
269
|
+
* `export component Name inherits Window`; helper components without
|
|
270
|
+
* `export` are allowed. The window's properties and callbacks are declared
|
|
271
|
+
* on that component. The file is not read here: a missing or broken file
|
|
272
|
+
* makes {@link Window.show} reject.
|
|
273
|
+
*
|
|
274
|
+
* Bind every callback with {@link View.on} before the first `show()`.
|
|
275
|
+
*
|
|
276
|
+
* @capability ui.window (checked by {@link Window.show}).
|
|
277
|
+
*
|
|
278
|
+
* @param file - Path relative to the package directory, with `/` on every
|
|
279
|
+
* system, for example `"ui/picture.slint"`. It must stay inside the
|
|
280
|
+
* package.
|
|
281
|
+
* @param options - `id`: the window's name, unique among this plugin's
|
|
282
|
+
* windows until the window is disposed. Default: the file name without
|
|
283
|
+
* its extension (`ui/picture.slint` → `picture`). Give distinct ids to
|
|
284
|
+
* open the same file more than once.
|
|
285
|
+
* @returns A {@link Window} owned by this scope.
|
|
286
|
+
*
|
|
287
|
+
* @throws `conflict` (throws) This plugin already has a window with this id
|
|
288
|
+
* (SDK 1.3.0; before, a plain `Error` without `code`).
|
|
289
|
+
*
|
|
290
|
+
* @example Open two windows from one Slint file
|
|
291
|
+
* Two compare windows open side by side, one labelled A and one B. A
|
|
292
|
+
* window's id defaults to its file name, so the second window of the
|
|
293
|
+
* same file needs its own `id`; each handle has its own properties.
|
|
294
|
+
* ```ts
|
|
295
|
+
* const left = plugin.windows.create("ui/compare.slint", { id: "compare-left" });
|
|
296
|
+
* const right = plugin.windows.create("ui/compare.slint", { id: "compare-right" });
|
|
297
|
+
* left.set({ side: "A" });
|
|
298
|
+
* right.set({ side: "B" });
|
|
299
|
+
* await Promise.all([left.show(), right.show()]);
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @since 1.0.0
|
|
303
|
+
*/
|
|
304
|
+
create(file: string, options?: {
|
|
305
|
+
id?: string;
|
|
306
|
+
}): Window;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The state of the bottom bar or sidebar position, whoever mounted the
|
|
310
|
+
* panel there.
|
|
311
|
+
*
|
|
312
|
+
* @since 1.0.0
|
|
313
|
+
* @category UI
|
|
314
|
+
*/
|
|
315
|
+
export interface SlotState {
|
|
316
|
+
/** The user's choice: the check mark of the menu item that shows the panel. */
|
|
317
|
+
preferred: boolean;
|
|
318
|
+
/** Whether the panel is on screen right now (docked, popped out or floating). */
|
|
319
|
+
effective: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Why it is not on screen, `null` while it is:
|
|
322
|
+
*
|
|
323
|
+
* - `userHidden`: the user (or a plugin) turned it off;
|
|
324
|
+
* - `space`: the window is too narrow for the sidebar (the preference stays);
|
|
325
|
+
* - `fullscreen`: the sidebar's fullscreen overlay is collapsed and pops
|
|
326
|
+
* out when the pointer reaches the right edge; treat it as "on" for a
|
|
327
|
+
* toggle button;
|
|
328
|
+
* - `idle`: the bottom bar in fullscreen while the pointer is outside the
|
|
329
|
+
* bar's own band at the bottom of the screen (player 0.5.1: keys and
|
|
330
|
+
* pointer motion elsewhere do not bring it back; before 0.5.1 it hid after
|
|
331
|
+
* 3 seconds without activity).
|
|
332
|
+
*/
|
|
333
|
+
reason: "userHidden" | "space" | "fullscreen" | "idle" | null;
|
|
334
|
+
/** The sidebar floats in its own window; always `false` for the bottom bar. */
|
|
335
|
+
detached: boolean;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* One panel of a position ({@link PanelSlot.panels}): a tab of the sidebar.
|
|
339
|
+
*
|
|
340
|
+
* @since 1.5.2
|
|
341
|
+
* @category UI
|
|
342
|
+
*/
|
|
343
|
+
export interface SlotPanel {
|
|
344
|
+
/** The manifest id of the plugin that mounted it (pass it to {@link PanelSlot.activate}). */
|
|
345
|
+
plugin: string;
|
|
346
|
+
/** Its tab label: the `title` of {@link Panels.mount}, else the plugin's name. */
|
|
347
|
+
title: string;
|
|
348
|
+
/** Its tab is the current one (the panel the position shows). */
|
|
349
|
+
active: boolean;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The state of one panel ({@link Panel.state}): its position's state, seen
|
|
353
|
+
* from this panel, which may be one of several sidebar tabs.
|
|
354
|
+
*
|
|
355
|
+
* @since 1.5.2
|
|
356
|
+
* @category UI
|
|
357
|
+
*/
|
|
358
|
+
export interface PanelState {
|
|
359
|
+
/**
|
|
360
|
+
* Its tab is the current one. Always `true` for the bottom bar, the
|
|
361
|
+
* backdrop and a sidebar panel without other tabs.
|
|
362
|
+
*/
|
|
363
|
+
active: boolean;
|
|
364
|
+
/** The position's preference (the user's choice to show it). */
|
|
365
|
+
preferred: boolean;
|
|
366
|
+
/** This panel is on screen now: the position is, and this is its current tab. */
|
|
367
|
+
effective: boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Why this panel is not on screen, `null` while it is: `otherTab` while
|
|
370
|
+
* another plugin's tab is the current one (whatever the position's state),
|
|
371
|
+
* else the position's reason ({@link SlotState.reason}).
|
|
372
|
+
*/
|
|
373
|
+
reason: SlotState["reason"] | "otherTab";
|
|
374
|
+
/** The sidebar floats in its own window (with all its tabs); always `false` in the adjust column. */
|
|
375
|
+
detached: boolean;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* The bottom bar, the sidebar or the adjust column position
|
|
379
|
+
* (`plugin.panels.bottom`, `plugin.panels.sidebar`, `plugin.panels.adjust`),
|
|
380
|
+
* independent of who mounted the panel there.
|
|
381
|
+
*
|
|
382
|
+
* @remarks
|
|
383
|
+
* The position does not belong to the plugin that mounted the panel: any
|
|
384
|
+
* plugin with `ui.mount` may read and toggle it, so a "Show playlist" command
|
|
385
|
+
* can live in a different plugin than the playlist. The player remembers
|
|
386
|
+
* the sidebar's visibility, width, detached state and floating window
|
|
387
|
+
* position across launches.
|
|
388
|
+
*
|
|
389
|
+
* `state` is read when first used. With `events` it then follows every
|
|
390
|
+
* change (the user, other plugins, the window size); without `events` it
|
|
391
|
+
* refreshes only after this plugin's own changes.
|
|
392
|
+
*
|
|
393
|
+
* @capability ui.mount; `events` to follow changes made elsewhere.
|
|
394
|
+
*
|
|
395
|
+
* @example Add a "Show sidebar" item that works with any sidebar panel
|
|
396
|
+
* Tools ▸ Show sidebar shows or hides the sidebar, whichever plugin's
|
|
397
|
+
* panel is in it, with a check mark while it is shown. The position does
|
|
398
|
+
* not belong to the plugin that mounted the panel: `state` is `null`
|
|
399
|
+
* while nobody has a panel there (the item is disabled then), and
|
|
400
|
+
* `toggle` flips the user's remembered preference.
|
|
401
|
+
* ```ts
|
|
402
|
+
* const sidebar = plugin.panels.sidebar;
|
|
403
|
+
* plugin.commands.add({
|
|
404
|
+
* id: "sidebar",
|
|
405
|
+
* path: ["Tools", "Show sidebar"],
|
|
406
|
+
* // `state` is null while no plugin has a panel in the sidebar.
|
|
407
|
+
* checked: () => sidebar.state?.preferred ?? false,
|
|
408
|
+
* enabled: () => sidebar.state !== null,
|
|
409
|
+
* run: () => sidebar.toggle(),
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*
|
|
413
|
+
* @see {@link Panels}, {@link SlotState}
|
|
414
|
+
* @since 1.0.0
|
|
415
|
+
* @category UI
|
|
416
|
+
*/
|
|
417
|
+
export interface PanelSlot {
|
|
418
|
+
/**
|
|
419
|
+
* The current state; `null` while no plugin has a panel there (or without
|
|
420
|
+
* `ui.mount`). With sidebar tabs it is the whole position's: shown,
|
|
421
|
+
* hidden and floating apply to all tabs, which {@link PanelSlot.panels}
|
|
422
|
+
* lists.
|
|
423
|
+
*/
|
|
424
|
+
readonly state: SlotState | null;
|
|
425
|
+
/**
|
|
426
|
+
* The position's panels in tab order: the sidebar's tabs, the bottom
|
|
427
|
+
* bar's one panel; `null` while there is none (as `state`), and from
|
|
428
|
+
* players without sidebar tabs (0.4.0 and older). Refreshed with `state`.
|
|
429
|
+
*
|
|
430
|
+
* @throws Never.
|
|
431
|
+
*
|
|
432
|
+
* @since 1.5.2
|
|
433
|
+
*/
|
|
434
|
+
readonly panels: readonly SlotPanel[] | null;
|
|
435
|
+
/**
|
|
436
|
+
* Run code when the position's state changes.
|
|
437
|
+
*
|
|
438
|
+
* @remarks
|
|
439
|
+
* Needs `events`: without it the listener runs only after this plugin's own
|
|
440
|
+
* changes. Called with `null` when the panel there is unmounted, and also
|
|
441
|
+
* when only the tabs changed ({@link PanelSlot.panels}: a panel added or
|
|
442
|
+
* removed, another tab current). Errors go to {@link Scope.onError}.
|
|
443
|
+
*
|
|
444
|
+
* @capability ui.mount and events
|
|
445
|
+
*
|
|
446
|
+
* @param listener - Receives the new state.
|
|
447
|
+
* @returns A handle that removes the listener.
|
|
448
|
+
*
|
|
449
|
+
* @example Tell the user when the window is too narrow for the sidebar
|
|
450
|
+
* When the sidebar should show but the window has no room for it, the
|
|
451
|
+
* OSD says so. With `events`, the listener runs on every change of the
|
|
452
|
+
* position, whoever caused it. The player reports `reason: "space"` when
|
|
453
|
+
* the preference is to show the sidebar but the window is too small.
|
|
454
|
+
* ```ts
|
|
455
|
+
* plugin.panels.sidebar.onChange((state) => {
|
|
456
|
+
* // `null`: no panel is mounted in the sidebar any more.
|
|
457
|
+
* if (state?.reason === "space") void plugin.osd.show("Widen the window to see the playlist");
|
|
458
|
+
* });
|
|
459
|
+
* ```
|
|
460
|
+
*
|
|
461
|
+
* @since 1.0.0
|
|
462
|
+
*/
|
|
463
|
+
onChange(listener: (state: SlotState | null) => void): Disposable;
|
|
464
|
+
/**
|
|
465
|
+
* Show or hide the panel at this position: set the user's preference.
|
|
466
|
+
*
|
|
467
|
+
* @remarks
|
|
468
|
+
* The same as the user's menu item: the preference is remembered. Showing
|
|
469
|
+
* may still leave the panel off screen (`reason: "space"`); in fullscreen,
|
|
470
|
+
* `true` pops the sidebar overlay out at once.
|
|
471
|
+
*
|
|
472
|
+
* @capability ui.mount
|
|
473
|
+
*
|
|
474
|
+
* @param visible - The new preference.
|
|
475
|
+
* @returns Resolves once the layout has the new preference, with `state`
|
|
476
|
+
* refreshed.
|
|
477
|
+
*
|
|
478
|
+
* @throws `missing` (rejects) No panel is mounted at this position.
|
|
479
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
480
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.mount`.
|
|
481
|
+
*
|
|
482
|
+
* @example Hide the bottom bar for a clean picture
|
|
483
|
+
* The control bar disappears, as if the user had hidden it from the menu,
|
|
484
|
+
* and stays hidden at the next start because the preference is
|
|
485
|
+
* remembered. `setVisible` rejects with `missing` when no panel is in the
|
|
486
|
+
* bottom bar, which this plugin treats as nothing to hide.
|
|
487
|
+
* ```ts
|
|
488
|
+
* await plugin.panels.bottom.setVisible(false).catch((error: PluginError) => {
|
|
489
|
+
* if (error.code !== "missing") throw error; // no bar mounted: nothing to do
|
|
490
|
+
* });
|
|
491
|
+
* ```
|
|
492
|
+
*
|
|
493
|
+
* @since 1.0.0
|
|
494
|
+
*/
|
|
495
|
+
setVisible(visible: boolean): Promise<void>;
|
|
496
|
+
/**
|
|
497
|
+
* Flip the user's preference, using the player's current value.
|
|
498
|
+
*
|
|
499
|
+
* @remarks
|
|
500
|
+
* Reads the state from the player first, so it is right even without
|
|
501
|
+
* `events`. It is a switch, the same in every mode: in fullscreen a column
|
|
502
|
+
* switched on is revealed by the pointer at the right edge, and is not
|
|
503
|
+
* popped out by the toggle (SDK 1.6.13, player 0.7.6; `setVisible(true)`
|
|
504
|
+
* pops it out). Switching it off while it is out slides it in at once.
|
|
505
|
+
*
|
|
506
|
+
* @capability ui.mount
|
|
507
|
+
*
|
|
508
|
+
* @returns Resolves once the layout has the new preference.
|
|
509
|
+
*
|
|
510
|
+
* @throws `missing` (rejects) No panel is mounted at this position.
|
|
511
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
512
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.mount`.
|
|
513
|
+
*
|
|
514
|
+
* @example Toggle the control bar from a checkable menu item
|
|
515
|
+
* Screen ▸ Control bar shows or hides the bottom bar and carries a check
|
|
516
|
+
* mark while it is shown. `toggle` reads the player's current preference
|
|
517
|
+
* first, so it is right even without `events`; `checked` is evaluated
|
|
518
|
+
* again after the command runs and follows `state`.
|
|
519
|
+
* ```ts
|
|
520
|
+
* plugin.commands.add({
|
|
521
|
+
* id: "toggle-bar",
|
|
522
|
+
* path: ["@screen", "Control bar"],
|
|
523
|
+
* // The user's preference, remembered across launches.
|
|
524
|
+
* checked: () => plugin.panels.bottom.state?.preferred ?? false,
|
|
525
|
+
* run: () => plugin.panels.bottom.toggle(),
|
|
526
|
+
* });
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* @since 1.0.0
|
|
530
|
+
*/
|
|
531
|
+
toggle(): Promise<void>;
|
|
532
|
+
/**
|
|
533
|
+
* Make a panel's tab the current one, without showing or hiding the
|
|
534
|
+
* position.
|
|
535
|
+
*
|
|
536
|
+
* @remarks
|
|
537
|
+
* The sidebar holds the panels of several plugins as tabs (see
|
|
538
|
+
* {@link Panels.mount}); this switches which one it shows, like a click on
|
|
539
|
+
* its tab. To show this plugin's own panel, use {@link Panel.show}. The
|
|
540
|
+
* bottom bar has one panel: activating it changes nothing. Players
|
|
541
|
+
* without sidebar tabs (0.4.0 and older) ignore it.
|
|
542
|
+
*
|
|
543
|
+
* @capability ui.mount
|
|
544
|
+
*
|
|
545
|
+
* @param plugin - The manifest id of the plugin whose panel to show, one
|
|
546
|
+
* of {@link PanelSlot.panels}.
|
|
547
|
+
* @returns Resolves once the layout has the new current tab, with `state`
|
|
548
|
+
* refreshed.
|
|
549
|
+
*
|
|
550
|
+
* @throws `missing` (rejects) No panel is mounted at this position, or
|
|
551
|
+
* none of `plugin`.
|
|
552
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
553
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.mount`.
|
|
554
|
+
*
|
|
555
|
+
* @example Switch the sidebar to the playlist's tab
|
|
556
|
+
* A command makes the playlist the sidebar's current tab without showing
|
|
557
|
+
* or hiding the sidebar, like a click on its tab. `activate` takes the
|
|
558
|
+
* manifest id of the plugin whose tab to show and rejects with
|
|
559
|
+
* `missing` when that plugin has no panel there.
|
|
560
|
+
* ```ts
|
|
561
|
+
* plugin.commands.add({
|
|
562
|
+
* id: "to-playlist",
|
|
563
|
+
* title: "Show the playlist tab",
|
|
564
|
+
* run: () => plugin.panels.sidebar.activate("vestra.playlist"),
|
|
565
|
+
* });
|
|
566
|
+
* ```
|
|
567
|
+
*
|
|
568
|
+
* @since 1.5.2
|
|
569
|
+
*/
|
|
570
|
+
activate(plugin: string): Promise<void>;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* The sidebar position: a {@link PanelSlot} that can also float in a window
|
|
574
|
+
* of its own.
|
|
575
|
+
*
|
|
576
|
+
* @remarks
|
|
577
|
+
* Detached, the sidebar panel is shown in a separate window (300×408 by
|
|
578
|
+
* default, at least 300×250) with the panel's `title`. The plugin's
|
|
579
|
+
* properties and callbacks stay the same, but the window holds a new
|
|
580
|
+
* instance of the component. Closing the floating window (its close button
|
|
581
|
+
* or the [standard close keys](../../../docs/reference/commands.md#keys-the-system-takes-first)) is the same as `setVisible(false)`.
|
|
582
|
+
*
|
|
583
|
+
* @capability ui.mount
|
|
584
|
+
*
|
|
585
|
+
* @example Add a "Detach sidebar" item
|
|
586
|
+
* Tools ▸ Detach sidebar floats the sidebar in its own window and docks
|
|
587
|
+
* it again, with a check mark while it floats. `setDetached` moves all
|
|
588
|
+
* the sidebar's tabs; the floating window holds new instances of the
|
|
589
|
+
* panels, which keep the plugins' properties and callbacks.
|
|
590
|
+
* ```ts
|
|
591
|
+
* const sidebar = plugin.panels.sidebar;
|
|
592
|
+
* plugin.commands.add({
|
|
593
|
+
* id: "detach",
|
|
594
|
+
* path: ["Tools", "Detach sidebar"],
|
|
595
|
+
* // Detaching moves every tab of the sidebar into the floating window.
|
|
596
|
+
* checked: () => sidebar.state?.detached ?? false,
|
|
597
|
+
* enabled: () => sidebar.state !== null,
|
|
598
|
+
* run: () => sidebar.setDetached(!sidebar.state?.detached),
|
|
599
|
+
* });
|
|
600
|
+
* ```
|
|
601
|
+
*
|
|
602
|
+
* @since 1.0.0
|
|
603
|
+
* @category UI
|
|
604
|
+
*/
|
|
605
|
+
export interface SidebarSlot extends PanelSlot {
|
|
606
|
+
/**
|
|
607
|
+
* Float the sidebar panel in its own window, or attach it back.
|
|
608
|
+
*
|
|
609
|
+
* @capability ui.mount
|
|
610
|
+
*
|
|
611
|
+
* @param detached - `true` to float, `false` to dock.
|
|
612
|
+
* @returns Resolves once the layout has changed, with `state` refreshed.
|
|
613
|
+
*
|
|
614
|
+
* @throws `missing` (rejects) No panel is mounted in the sidebar.
|
|
615
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
616
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.mount`.
|
|
617
|
+
*
|
|
618
|
+
* @example Float the sidebar or dock it back
|
|
619
|
+
* The sidebar moves into its own window, or back into the main window
|
|
620
|
+
* when it already floats. `state` says whether it is detached now;
|
|
621
|
+
* `setDetached` resolves once the layout changed, with `state` refreshed.
|
|
622
|
+
* ```ts
|
|
623
|
+
* const sidebar = plugin.panels.sidebar;
|
|
624
|
+
* await sidebar.setDetached(!sidebar.state?.detached);
|
|
625
|
+
* ```
|
|
626
|
+
*
|
|
627
|
+
* @since 1.0.0
|
|
628
|
+
*/
|
|
629
|
+
setDetached(detached: boolean): Promise<void>;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* A panel in the player's main window, made by {@link Panels.mount}.
|
|
633
|
+
*
|
|
634
|
+
* @remarks
|
|
635
|
+
* Properties and callbacks live on the file's bridge global (see
|
|
636
|
+
* {@link Panels}). Unlike a tool window, a panel forwards every callback of
|
|
637
|
+
* the global, so {@link View.on} has no "bind before show" rule.
|
|
638
|
+
*
|
|
639
|
+
* **Life cycle.** `mount()` returns at once; in the next microtask the SDK
|
|
640
|
+
* sends the mount with every property bound or set so far. The player queues
|
|
641
|
+
* mounts and rebuilds its main window with the panel; {@link Panel.ready}
|
|
642
|
+
* then resolves. Rebuilding happens whenever any plugin mounts or unmounts a
|
|
643
|
+
* panel, and detaching the sidebar puts a new instance in a floating window.
|
|
644
|
+
* The player restores the bridge properties to the values last written, but
|
|
645
|
+
* state kept only inside the component (a scroll position, a property the
|
|
646
|
+
* plugin never writes) starts over: keep what matters in bridge properties.
|
|
647
|
+
* `dispose()`, disposing the scope or stopping the plugin unmounts it.
|
|
648
|
+
*
|
|
649
|
+
* Testing: `host.mounted()` of `@vestra-player/sdk/testing` has the panel's
|
|
650
|
+
* `slot`, `props` and `emit(callback, ...args)`.
|
|
651
|
+
*
|
|
652
|
+
* @capability ui.mount
|
|
653
|
+
*
|
|
654
|
+
* @example Mount a sidebar list with a right-click menu (examples/panel-menu)
|
|
655
|
+
* The sidebar gets an "Example list" tab whose rows can be selected and
|
|
656
|
+
* have a context menu. `mount` returns at once and the player adds the
|
|
657
|
+
* panel when it rebuilds its main window; `bind` keeps the rows and the
|
|
658
|
+
* selection on the panel's bridge global, and the `context-menu` callback
|
|
659
|
+
* opens a menu of the plugin's commands where the user clicked.
|
|
660
|
+
*
|
|
661
|
+
* {@includeCode ../../../examples/panel-menu/main.ts#mount,menu}
|
|
662
|
+
*
|
|
663
|
+
* `ui/panel.slint`:
|
|
664
|
+
*
|
|
665
|
+
* {@includeCode ../../../examples/panel-menu/ui/panel.slint}
|
|
666
|
+
*
|
|
667
|
+
* @see {@link Panels.mount}, {@link PanelSlot}, [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md)
|
|
668
|
+
* @since 1.0.0
|
|
669
|
+
* @category UI
|
|
670
|
+
*/
|
|
671
|
+
export interface Panel extends View, Disposable {
|
|
672
|
+
/**
|
|
673
|
+
* Resolves once the player has mounted the panel and the main window shows
|
|
674
|
+
* it; rejects when the mount failed.
|
|
675
|
+
*
|
|
676
|
+
* @remarks
|
|
677
|
+
* Mounts made while `activate` runs must succeed before the plugin is
|
|
678
|
+
* ready: a rejection fails activation, except `conflict` for a taken
|
|
679
|
+
* position (below), which the player (0.4.x after 0.4.0) and `TestHost`
|
|
680
|
+
* do not count: the plugin runs without its panel, its commands and keys
|
|
681
|
+
* work, and the player shows the refusal (an OSD message,
|
|
682
|
+
* {@link PluginInfo.warnings} and the text in {@link PluginInfo.error}).
|
|
683
|
+
* Later failures also go to {@link Scope.onError}.
|
|
684
|
+
*
|
|
685
|
+
* A second sidebar panel is not refused: it resolves as another tab
|
|
686
|
+
* (see {@link Panel.state}). Built-in plugins mount first at start-up,
|
|
687
|
+
* so the playlist's tab is first and a built-in panel keeps its position.
|
|
688
|
+
* Behaviour from player 0.7.3: the sidebar takes any number of tabs; the
|
|
689
|
+
* strip shows the tabs that fit and a `»` menu lists all of them.
|
|
690
|
+
* Players 0.4.x to 0.7.2 refused a ninth tab with `conflict`. A plugin
|
|
691
|
+
* whose sidebar tab is in the background, and that holds nothing else
|
|
692
|
+
* that keeps it running, goes to standby when idle; showing the tab
|
|
693
|
+
* starts it again (see {@link Panel.state}).
|
|
694
|
+
*
|
|
695
|
+
* @throws `ui-prepare` (rejects) The Slint file does not compile, or a
|
|
696
|
+
* bound property is not declared on the bridge global; `message` has the
|
|
697
|
+
* diagnostics. (Players 0.4.0 and older also answer a taken bottom bar
|
|
698
|
+
* or sidebar with it.)
|
|
699
|
+
* @throws `conflict` (rejects) Another plugin's panel holds the bottom bar
|
|
700
|
+
* or the backdrop (shown, or being mounted); `message` names the
|
|
701
|
+
* position and the holder (「底栏已被 vestra.playback 使用」). Not an
|
|
702
|
+
* activation failure. Never for the sidebar (behaviour from player
|
|
703
|
+
* 0.7.3); players 0.4.x to 0.7.2 also refused a ninth sidebar tab.
|
|
704
|
+
* @throws `busy` (rejects) The player is still preparing this plugin's
|
|
705
|
+
* previous mount, or its queue of mounts is full.
|
|
706
|
+
* @throws `invalid` (rejects) `title` is longer than 128 bytes or has
|
|
707
|
+
* control characters.
|
|
708
|
+
* @throws `host` (rejects) The file is missing or outside the package
|
|
709
|
+
* directory.
|
|
710
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
711
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.mount`.
|
|
712
|
+
*/
|
|
713
|
+
readonly ready: Promise<void>;
|
|
714
|
+
/**
|
|
715
|
+
* This panel's state: its position's, and whether its tab is the current
|
|
716
|
+
* one; `null` until {@link Panel.ready} resolved (and after `dispose`).
|
|
717
|
+
*
|
|
718
|
+
* @remarks
|
|
719
|
+
* Read when first used; with `events` it then follows every change (the
|
|
720
|
+
* user switching tabs, other plugins, the window size), without `events`
|
|
721
|
+
* only this plugin's own changes. A sidebar panel in a background tab
|
|
722
|
+
* has `active: false`, `effective: false` and `reason: "otherTab"`.
|
|
723
|
+
*
|
|
724
|
+
* Behaviour from player 0.7.3: a background tab does not keep the plugin
|
|
725
|
+
* running.
|
|
726
|
+
* If the panel is all that keeps it running, the plugin goes to standby
|
|
727
|
+
* after the idle time (stop reason `idle`): the player keeps its tab, with
|
|
728
|
+
* its title, in the strip and the `»` menu. When the user shows the tab,
|
|
729
|
+
* the player starts the plugin again; `activate` runs and mounts the same
|
|
730
|
+
* panel (same file and component), which takes the tab over, and
|
|
731
|
+
* {@link Panel.ready} resolves again. Anything the plugin kept only in
|
|
732
|
+
* memory is gone: restore the view from storage (session storage
|
|
733
|
+
* survives standby). While it is in the background, the player may also
|
|
734
|
+
* drop the panel's component and build it again from the bridge
|
|
735
|
+
* properties last written, as it does on any rebuild.
|
|
736
|
+
*
|
|
737
|
+
* @throws Never; `null` stands for "not mounted".
|
|
738
|
+
*
|
|
739
|
+
* @since 1.5.2
|
|
740
|
+
*/
|
|
741
|
+
readonly state: PanelState | null;
|
|
742
|
+
/**
|
|
743
|
+
* Run code when this panel's state changes.
|
|
744
|
+
*
|
|
745
|
+
* @remarks
|
|
746
|
+
* Needs `events`: without it the listener runs only after this plugin's
|
|
747
|
+
* own changes. Called with `null` when the panel is unmounted. Errors go
|
|
748
|
+
* to {@link Scope.onError}.
|
|
749
|
+
*
|
|
750
|
+
* @capability ui.mount and events
|
|
751
|
+
*
|
|
752
|
+
* @param listener - Receives the new state.
|
|
753
|
+
* @returns A handle that removes the listener.
|
|
754
|
+
*
|
|
755
|
+
* @example Notice when the list moves to a background tab
|
|
756
|
+
* The plugin logs when the user switches the sidebar to another plugin's
|
|
757
|
+
* tab, for example to pause work the list does. With `events` the
|
|
758
|
+
* listener runs on every change. `reason: "otherTab"` exists only in a
|
|
759
|
+
* panel's own state: the SDK sets it when the sidebar's current tab is
|
|
760
|
+
* another plugin's (the position's state never has it).
|
|
761
|
+
* ```ts
|
|
762
|
+
* const panel = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
|
|
763
|
+
* panel.onChange((state) => {
|
|
764
|
+
* if (state?.reason === "otherTab") console.error("list in a background tab");
|
|
765
|
+
* });
|
|
766
|
+
* ```
|
|
767
|
+
*
|
|
768
|
+
* @since 1.5.2
|
|
769
|
+
*/
|
|
770
|
+
onChange(listener: (state: PanelState | null) => void): Disposable;
|
|
771
|
+
/**
|
|
772
|
+
* Show this panel: make its tab the current one and show its position.
|
|
773
|
+
*
|
|
774
|
+
* @remarks
|
|
775
|
+
* Sets the position's preference like {@link PanelSlot.setVisible}`(true)`
|
|
776
|
+
* (remembered; in fullscreen the sidebar overlay pops out). On players
|
|
777
|
+
* without sidebar tabs (0.4.0 and older) it is just that. Waits for
|
|
778
|
+
* {@link Panel.ready} first.
|
|
779
|
+
*
|
|
780
|
+
* @capability ui.mount
|
|
781
|
+
*
|
|
782
|
+
* @returns Resolves once the layout shows the panel's tab, with `state`
|
|
783
|
+
* refreshed.
|
|
784
|
+
*
|
|
785
|
+
* @throws `invalid` (rejects) The panel is the backdrop, which the player
|
|
786
|
+
* shows by itself.
|
|
787
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
788
|
+
* @throws The errors of {@link Panel.ready} (rejects) The mount failed.
|
|
789
|
+
*
|
|
790
|
+
* @example Bring the plugin's sidebar panel to the front
|
|
791
|
+
* A command shows the List tab: it becomes the current tab and the
|
|
792
|
+
* sidebar is shown, and the preference is remembered. `show` waits for
|
|
793
|
+
* the mount first, so it can run right after `mount`.
|
|
794
|
+
* ```ts
|
|
795
|
+
* const list = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
|
|
796
|
+
* plugin.commands.add({ id: "show", title: "Show the list", run: () => list.show() });
|
|
797
|
+
* ```
|
|
798
|
+
*
|
|
799
|
+
* @since 1.5.2
|
|
800
|
+
*/
|
|
801
|
+
show(): Promise<void>;
|
|
802
|
+
/**
|
|
803
|
+
* Show this panel, or hide its position when it is shown.
|
|
804
|
+
*
|
|
805
|
+
* @remarks
|
|
806
|
+
* Reads the state from the player first. When the position is shown
|
|
807
|
+
* (`preferred`) and this panel's tab is the current one, it hides the
|
|
808
|
+
* position; otherwise it switches the position on at this panel's tab: a
|
|
809
|
+
* panel in a background tab comes to the front instead of the sidebar
|
|
810
|
+
* closing. It is a switch, the same in every mode, like the player's own
|
|
811
|
+
* Alt+1…4 and Adjust button: in fullscreen a column switched on is revealed
|
|
812
|
+
* by the pointer at the right edge, not popped out (SDK 1.6.13, player
|
|
813
|
+
* 0.7.6; {@link Panel.show} pops it out), and one switched off while out
|
|
814
|
+
* slides in at once. A "Show list"
|
|
815
|
+
* command checked by `state.preferred && state.active` matches it. Waits
|
|
816
|
+
* for {@link Panel.ready} first.
|
|
817
|
+
*
|
|
818
|
+
* @capability ui.mount
|
|
819
|
+
*
|
|
820
|
+
* @returns Resolves once the layout has changed, with `state` refreshed.
|
|
821
|
+
*
|
|
822
|
+
* @throws `invalid` (rejects) The panel is the backdrop.
|
|
823
|
+
* @throws `unavailable` (rejects) The player runs without a user interface.
|
|
824
|
+
* @throws The errors of {@link Panel.ready} (rejects) The mount failed.
|
|
825
|
+
*
|
|
826
|
+
* @example Toggle a sidebar panel with F6, like the playlist
|
|
827
|
+
* F6 and Screen ▸ List show the List tab, or hide the sidebar when the
|
|
828
|
+
* list is already in front. `toggle` reads the player's state first:
|
|
829
|
+
* it hides the position only when it is shown and this panel's tab is
|
|
830
|
+
* the current one, otherwise it shows the panel.
|
|
831
|
+
* ```ts
|
|
832
|
+
* const list = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
|
|
833
|
+
* plugin.commands.add({
|
|
834
|
+
* id: "list",
|
|
835
|
+
* path: ["@screen", "List"],
|
|
836
|
+
* bindings: ["F6"],
|
|
837
|
+
* // Checked while the sidebar is shown with this list in front.
|
|
838
|
+
* checked: () => (list.state?.preferred ?? false) && (list.state?.active ?? false),
|
|
839
|
+
* run: () => list.toggle(),
|
|
840
|
+
* });
|
|
841
|
+
* ```
|
|
842
|
+
*
|
|
843
|
+
* @since 1.5.2
|
|
844
|
+
*/
|
|
845
|
+
toggle(): Promise<void>;
|
|
846
|
+
/**
|
|
847
|
+
* Keep the panel on screen while the user works in it.
|
|
848
|
+
*
|
|
849
|
+
* @remarks
|
|
850
|
+
* In fullscreen the bottom bar shows only while the pointer is in the bar's
|
|
851
|
+
* own band at the bottom of the screen: at once when the pointer enters it,
|
|
852
|
+
* hidden 500 ms after it leaves (player 0.5.1; keys and pointer motion
|
|
853
|
+
* elsewhere do not reveal it), and the fullscreen sidebar overlay collapses
|
|
854
|
+
* when the pointer leaves it. A lock keeps the bar shown. Set a
|
|
855
|
+
* lock while a text field has focus, a drag is in progress or a popup is
|
|
856
|
+
* open, and clear it afterwards. Locks are merged with the earlier ones;
|
|
857
|
+
* the last value of each wins. The player already locks a panel while the
|
|
858
|
+
* pointer is over it. No effect on the backdrop.
|
|
859
|
+
*
|
|
860
|
+
* Never throws: a failed write is reported to {@link Scope.onError}.
|
|
861
|
+
*
|
|
862
|
+
* @capability ui.mount
|
|
863
|
+
*
|
|
864
|
+
* @param locks - The locks to change; omitted ones keep their value.
|
|
865
|
+
*
|
|
866
|
+
* @example Keep the bar on screen while a search field has focus
|
|
867
|
+
* In fullscreen the bottom bar stays visible while the user types in
|
|
868
|
+
* its search field, instead of hiding when the pointer leaves it. The
|
|
869
|
+
* Slint side reports the field's focus through a callback, and
|
|
870
|
+
* `setInteraction` sets or clears the `focused` lock; other locks keep
|
|
871
|
+
* their values.
|
|
872
|
+
* ```ts
|
|
873
|
+
* const panel = plugin.panels.mount("bottom", "ui/bar.slint");
|
|
874
|
+
* panel.on("searchFocused", (focused: boolean) => panel.setInteraction({ focused }));
|
|
875
|
+
* ```
|
|
876
|
+
*
|
|
877
|
+
* @since 1.0.0
|
|
878
|
+
*/
|
|
879
|
+
setInteraction(locks: Partial<{
|
|
880
|
+
/** A text field (or another control taking keys) has focus. */
|
|
881
|
+
focused: boolean;
|
|
882
|
+
/** The user is dragging something in the panel. */
|
|
883
|
+
dragging: boolean;
|
|
884
|
+
/** A popup or menu of the panel is open. */
|
|
885
|
+
popupOpen: boolean;
|
|
886
|
+
}>): void;
|
|
887
|
+
/**
|
|
888
|
+
* Pop up a menu of this plugin's commands at a point in the panel.
|
|
889
|
+
*
|
|
890
|
+
* @remarks
|
|
891
|
+
* A one-level menu, styled like the main menu (check marks, shortcut text),
|
|
892
|
+
* in the window that shows the panel. Picking an item runs that command;
|
|
893
|
+
* `null` is a separator. Commands without a menu `path` work too, which
|
|
894
|
+
* makes context-only commands possible. Call it when the right button is
|
|
895
|
+
* released, as the main menu does. Waits for {@link Panel.ready} first.
|
|
896
|
+
*
|
|
897
|
+
* @capability ui.mount
|
|
898
|
+
*
|
|
899
|
+
* @param items - At most 32 commands of this plugin, or `null` for a
|
|
900
|
+
* separator.
|
|
901
|
+
* @param at - Where to open it, in the window's logical pixels: in Slint,
|
|
902
|
+
* `(self.absolute-position.x + self.mouse-x) / 1px` (and the same for
|
|
903
|
+
* `y`).
|
|
904
|
+
* @returns Resolves once the menu is open (not when the user picks).
|
|
905
|
+
*
|
|
906
|
+
* @throws `missing` (rejects) An item is not a command of this plugin.
|
|
907
|
+
* @throws `unavailable` (rejects) The panel is not on screen (also: its
|
|
908
|
+
* sidebar tab is not the current one), or it is the backdrop.
|
|
909
|
+
* @throws `invalid` (rejects) No items, more than 32, or `at` is not
|
|
910
|
+
* finite.
|
|
911
|
+
* @throws The errors of {@link Panel.ready} (rejects) The mount failed.
|
|
912
|
+
*
|
|
913
|
+
* @example Open a context menu where the user right-clicked (examples/panel-menu)
|
|
914
|
+
* Right-clicking the list opens a menu with "Select the first item" and
|
|
915
|
+
* "Remove the selected item". The Slint file passes the pointer position
|
|
916
|
+
* in window pixels with its `context-menu` callback; `showMenu` opens the
|
|
917
|
+
* plugin's commands there, and picking one runs that command.
|
|
918
|
+
*
|
|
919
|
+
* {@includeCode ../../../examples/panel-menu/main.ts#menu}
|
|
920
|
+
*
|
|
921
|
+
* @since 1.0.0
|
|
922
|
+
*/
|
|
923
|
+
showMenu(items: (Command | null)[], at: {
|
|
924
|
+
/** Logical pixels from the window's left edge. */
|
|
925
|
+
x: number;
|
|
926
|
+
/** Logical pixels from the window's top edge. */
|
|
927
|
+
y: number;
|
|
928
|
+
}): Promise<void>;
|
|
929
|
+
/**
|
|
930
|
+
* Receive the files dropped on this panel.
|
|
931
|
+
*
|
|
932
|
+
* @remarks
|
|
933
|
+
* Covers the docked panel and the floating sidebar window. While a listener
|
|
934
|
+
* exists, drops on the panel come here as one group (not split by
|
|
935
|
+
* extension) instead of going to the {@link Drops} providers. Drops on
|
|
936
|
+
* tool windows and the Options window are ignored; in fullscreen, the
|
|
937
|
+
* bottom bar floats over the video and drops there count as drops on the
|
|
938
|
+
* video area.
|
|
939
|
+
*
|
|
940
|
+
* @capability ui.drop
|
|
941
|
+
*
|
|
942
|
+
* @param listener - Receives the paths in the order the file manager gave
|
|
943
|
+
* them, the point in panel coordinates (logical pixels from the panel's
|
|
944
|
+
* top-left corner) and the keys held.
|
|
945
|
+
* @returns A handle that removes the listener.
|
|
946
|
+
*
|
|
947
|
+
* @example Add dropped files to a list
|
|
948
|
+
* Files dropped on the Files panel are added to its list. While the
|
|
949
|
+
* listener exists, drops on the panel come here as one group instead of
|
|
950
|
+
* going to the drop providers; after the listener returns, the SDK runs
|
|
951
|
+
* an update pass and `bind` sends the longer list.
|
|
952
|
+
* ```ts
|
|
953
|
+
* const files: string[] = [];
|
|
954
|
+
* const panel = plugin.panels.mount("sidebar", "ui/list.slint", { title: "Files" });
|
|
955
|
+
* panel.bind(() => ({ rows: files }));
|
|
956
|
+
* panel.onDrop(({ paths }) => {
|
|
957
|
+
* files.push(...paths); // in the order the file manager gave them
|
|
958
|
+
* });
|
|
959
|
+
* ```
|
|
960
|
+
*
|
|
961
|
+
* @since 1.0.0
|
|
962
|
+
*/
|
|
963
|
+
onDrop(listener: (event: {
|
|
964
|
+
/** Absolute paths of the dropped files and folders. */
|
|
965
|
+
paths: string[];
|
|
966
|
+
/** Panel coordinates, logical pixels. */
|
|
967
|
+
at: {
|
|
968
|
+
x: number;
|
|
969
|
+
y: number;
|
|
970
|
+
};
|
|
971
|
+
/** The keys held while dropping. */
|
|
972
|
+
modifiers: DropModifiers;
|
|
973
|
+
}) => unknown): Disposable;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Keys held when the files were dropped.
|
|
977
|
+
*
|
|
978
|
+
* @since 1.0.0
|
|
979
|
+
* @category UI
|
|
980
|
+
*/
|
|
981
|
+
export interface DropModifiers {
|
|
982
|
+
/** Option (macOS) / Alt (Windows). */
|
|
983
|
+
readonly alt: boolean;
|
|
984
|
+
/** Shift. */
|
|
985
|
+
readonly shift: boolean;
|
|
986
|
+
/** ⌘ on macOS, Ctrl on Windows. */
|
|
987
|
+
readonly cmd: boolean;
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* A provider for files dropped on the video area ({@link Drops.provide}).
|
|
991
|
+
*
|
|
992
|
+
* @see {@link Drops.provide}
|
|
993
|
+
* @since 1.0.0
|
|
994
|
+
* @category UI
|
|
995
|
+
*/
|
|
996
|
+
export interface DropHandler {
|
|
997
|
+
/**
|
|
998
|
+
* Lower case, without the dot; `"folder"` matches directories.
|
|
999
|
+
* 1–64 entries of 1–16 lower-case letters or digits.
|
|
1000
|
+
*/
|
|
1001
|
+
extensions: string[];
|
|
1002
|
+
/** The dropped paths with these extensions, in the order dropped. */
|
|
1003
|
+
drop(event: {
|
|
1004
|
+
paths: string[];
|
|
1005
|
+
modifiers: DropModifiers;
|
|
1006
|
+
}): unknown;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* `plugin.drops`: files dropped on the video area. Needs `ui.drop`.
|
|
1010
|
+
*
|
|
1011
|
+
* @remarks
|
|
1012
|
+
* Files dropped on the video area go to providers by extension: each
|
|
1013
|
+
* extension belongs to the provider registered for it first, and each
|
|
1014
|
+
* provider gets one call with all of its paths. Files nobody takes are
|
|
1015
|
+
* ignored. A panel with {@link Panel.onDrop} takes drops on itself first.
|
|
1016
|
+
*
|
|
1017
|
+
* @capability ui.drop
|
|
1018
|
+
*
|
|
1019
|
+
* @example Collect dropped CHIP-8 programs
|
|
1020
|
+
* `.ch8` files dropped on the player are added to the plugin's list. The
|
|
1021
|
+
* provider claims the extension; the player calls `drop` with the dropped
|
|
1022
|
+
* paths of that type, in the order the file manager gave them. Extensions
|
|
1023
|
+
* go to the first provider: the built-in playlist claims every audio and
|
|
1024
|
+
* video extension when it starts, and a built-in plugin cannot be disabled,
|
|
1025
|
+
* so another plugin's provider for those never gets them (except a
|
|
1026
|
+
* development load that replaces the playlist under its id).
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* const queue: string[] = [];
|
|
1029
|
+
* plugin.drops.provide({
|
|
1030
|
+
* extensions: ["ch8"],
|
|
1031
|
+
* drop: ({ paths }) => {
|
|
1032
|
+
* queue.push(...paths); // only .ch8 files reach here
|
|
1033
|
+
* },
|
|
1034
|
+
* });
|
|
1035
|
+
* ```
|
|
1036
|
+
*
|
|
1037
|
+
* @see {@link Panel.onDrop}
|
|
1038
|
+
* @since 1.0.0
|
|
1039
|
+
* @category UI
|
|
1040
|
+
*/
|
|
1041
|
+
export interface Drops {
|
|
1042
|
+
/**
|
|
1043
|
+
* Take files dropped on the video area. The first provider registered for
|
|
1044
|
+
* an extension gets it; files nobody takes are ignored.
|
|
1045
|
+
*
|
|
1046
|
+
* Paths are grouped by provider (an extension, case-insensitive, belongs
|
|
1047
|
+
* to the provider that registered it first) in the order the file
|
|
1048
|
+
* manager gave them, one call per provider. Folders are not expanded.
|
|
1049
|
+
*
|
|
1050
|
+
* @throws `invalid` synchronously for malformed extensions.
|
|
1051
|
+
*
|
|
1052
|
+
* @example Load dropped subtitle files
|
|
1053
|
+
* Dropping .srt or .ass files on the video loads each one as a subtitle
|
|
1054
|
+
* track. Each extension belongs to the provider that registered it first;
|
|
1055
|
+
* the player groups the dropped paths by provider and calls each provider
|
|
1056
|
+
* once with all of its paths, so .srt and .ass files dropped together
|
|
1057
|
+
* arrive in one call. (A panel under the pointer that listens with
|
|
1058
|
+
* `onDrop` takes the whole drop first.) The plugin reads each file itself
|
|
1059
|
+
* and uploads its bytes with `subtitles.load`.
|
|
1060
|
+
* ```ts
|
|
1061
|
+
* import { readFile } from "node:fs/promises";
|
|
1062
|
+
* // ---cut---
|
|
1063
|
+
* plugin.drops.provide({
|
|
1064
|
+
* extensions: ["srt", "ass"],
|
|
1065
|
+
* drop: async ({ paths }) => {
|
|
1066
|
+
* // Only .srt and .ass files reach this provider.
|
|
1067
|
+
* for (const path of paths)
|
|
1068
|
+
* await plugin.subtitles.load(await readFile(path), {
|
|
1069
|
+
* format: path.endsWith(".ass") ? "ass" : "srt",
|
|
1070
|
+
* });
|
|
1071
|
+
* },
|
|
1072
|
+
* });
|
|
1073
|
+
* ```
|
|
1074
|
+
*
|
|
1075
|
+
* @capability ui.drop
|
|
1076
|
+
* @since 1.0.0
|
|
1077
|
+
*/
|
|
1078
|
+
provide(handler: DropHandler): Disposable;
|
|
1079
|
+
}
|