@one2x/medeo-plugin-sdk 0.0.0-stage → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/generated.d.ts +591 -0
- package/dist/generated.js +1 -0
- package/dist/index.d.ts +1320 -0
- package/dist/index.js +541 -0
- package/dist/react.d.ts +46 -0
- package/dist/react.js +44 -0
- package/dist/registry.d.ts +1349 -0
- package/dist/registry.js +203 -0
- package/dist/rpc.d.ts +28 -0
- package/dist/rpc.js +172 -0
- package/dist/testing.d.ts +43 -0
- package/dist/testing.js +190 -0
- package/dist/ui/styles.d.ts +4 -0
- package/dist/ui/styles.js +31 -0
- package/dist/ui.d.ts +50 -0
- package/dist/ui.js +115 -0
- package/package.json +66 -4
- package/src/generated.ts +231 -0
- package/src/index.ts +658 -0
- package/src/react.ts +50 -0
- package/src/registry.ts +204 -0
- package/src/rpc.ts +136 -0
- package/src/testing.ts +169 -0
- package/src/ui/styles.ts +31 -0
- package/src/ui.ts +102 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
export { METHODS, LIMITS } from "./registry.js";
|
|
2
|
+
/** The `api_version` this SDK targets; `spec/api-v1.json` carries the same number. */
|
|
3
|
+
export const API_VERSION = 1;
|
|
4
|
+
/** Messages between this plugin's background worker and its own windows
|
|
5
|
+
* (64 KiB each, JSON). A worker message reaches every open window; a window
|
|
6
|
+
* message reaches the worker. Nothing is persisted or sent elsewhere. */
|
|
7
|
+
export const channel = {
|
|
8
|
+
post: (message) => globalThis.medeoPlugin.post(message),
|
|
9
|
+
onMessage: (callback) => globalThis.medeoPlugin.onMessage(m => callback(m)),
|
|
10
|
+
};
|
|
11
|
+
export const events = {
|
|
12
|
+
on: (callback) => globalThis.medeoPlugin.onEvent(callback),
|
|
13
|
+
/** Call `pull` now and again whenever the channel signals new entries. A
|
|
14
|
+
* failed pull (e.g. a permission withdrawn meanwhile) waits for the next signal. */
|
|
15
|
+
onSignal(channel, pull) {
|
|
16
|
+
const run = () => { void Promise.resolve().then(pull).catch(() => { }); };
|
|
17
|
+
const off = globalThis.medeoPlugin.onEvent(event => { if (event.type === 'signal' && event.channel === channel)
|
|
18
|
+
run(); });
|
|
19
|
+
run();
|
|
20
|
+
return off;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/** Resolves on the next event for `id`, or after `fallbackMs` as a safety net. */
|
|
24
|
+
function nextChange(id, fallbackMs) {
|
|
25
|
+
let off = () => { };
|
|
26
|
+
const promise = new Promise(resolve => {
|
|
27
|
+
const timer = setTimeout(resolve, fallbackMs);
|
|
28
|
+
const stop = globalThis.medeoPlugin.onEvent(event => { if (event.type === 'operation' && event.id === id) {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
resolve();
|
|
31
|
+
} });
|
|
32
|
+
off = () => { clearTimeout(timer); stop(); };
|
|
33
|
+
});
|
|
34
|
+
return { promise, off };
|
|
35
|
+
}
|
|
36
|
+
export const storage = {
|
|
37
|
+
get: (key) => globalThis.medeoPlugin.invoke('storage.get', { key }),
|
|
38
|
+
remove: (key) => globalThis.medeoPlugin.invoke('storage.remove', { key }),
|
|
39
|
+
set: (key, value) => globalThis.medeoPlugin.invoke('storage.set', { key, value }),
|
|
40
|
+
};
|
|
41
|
+
export const creation = { open: () => globalThis.medeoPlugin.invoke('creation.open') };
|
|
42
|
+
export const commands = { run: (command, args) => globalThis.medeoPlugin.run(command, args) };
|
|
43
|
+
export function definePlugin(definition) {
|
|
44
|
+
return { deactivate: () => undefined, ...definition };
|
|
45
|
+
}
|
|
46
|
+
/** Settings declared under `contributes.configuration`; the user edits them in the plugin center. */
|
|
47
|
+
export const config = {
|
|
48
|
+
get: (key) => globalThis.medeoPlugin.invoke('config.get', { key }),
|
|
49
|
+
all: () => globalThis.medeoPlugin.invoke('config.get'),
|
|
50
|
+
set: (key, value) => globalThis.medeoPlugin.invoke('config.set', { key, value }),
|
|
51
|
+
/** Calls `listener` with all values after each change, from the user or the plugin. */
|
|
52
|
+
onDidChange(listener) {
|
|
53
|
+
return globalThis.medeoPlugin.onEvent(event => {
|
|
54
|
+
if (event.type === 'signal' && event.channel === 'config')
|
|
55
|
+
void config.all().then(listener).catch(() => { });
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export const providers = {
|
|
60
|
+
list: () => globalThis.medeoPlugin.invoke('providers.list'),
|
|
61
|
+
require: async (id, version = 1) => {
|
|
62
|
+
const provider = (await providers.list()).find(p => p.id === id && p.version === version && p.available);
|
|
63
|
+
if (!provider)
|
|
64
|
+
throw new Error('provider_unavailable');
|
|
65
|
+
return provider;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
export const resources = {
|
|
69
|
+
chooseDirectories: (access = {}) => globalThis.medeoPlugin.invoke('resources.choose_directories', access.full ? { full: true } : {}),
|
|
70
|
+
list: () => globalThis.medeoPlugin.invoke('resources.list'),
|
|
71
|
+
revoke: (id) => globalThis.medeoPlugin.invoke('resources.revoke', { id }),
|
|
72
|
+
requestDirectory: (path, reason, access = {}) => globalThis.medeoPlugin.invoke('resources.request_directory', { path, reason, ...(access.full ? { full: true } : {}) }),
|
|
73
|
+
};
|
|
74
|
+
export const drive = {
|
|
75
|
+
state: () => globalThis.medeoPlugin.invoke('drive.state', {}),
|
|
76
|
+
folders: () => globalThis.medeoPlugin.invoke('drive.folders', {}),
|
|
77
|
+
transfers: () => globalThis.medeoPlugin.invoke('drive.transfers', {}),
|
|
78
|
+
/** Most recently synced files, newest first; `limit` 1–100 (default 20). */
|
|
79
|
+
recent: (limit) => globalThis.medeoPlugin.invoke('drive.recent', limit === undefined ? {} : { limit }),
|
|
80
|
+
failed: () => globalThis.medeoPlugin.invoke('drive.failed', {}),
|
|
81
|
+
/** Sync state of up to 500 paths in a folder: `synced`, `pending`, `uploading`/`downloading` (with
|
|
82
|
+
* `progress` 0–1), `failed` (with `reason`), `cloud` (only in the cloud) or `unknown`. */
|
|
83
|
+
fileStates: (folder, paths) => globalThis.medeoPlugin.invoke('drive.fileStates', { folder, paths }),
|
|
84
|
+
/** Download a cloud-only file to this computer (`drive_manage`); watch it with `fileStates`. */
|
|
85
|
+
download: (folder, path) => globalThis.medeoPlugin.invoke('drive.download', { folder, path }),
|
|
86
|
+
/** Re-queue a folder's failed files (`drive_manage`). */
|
|
87
|
+
retry: (folder) => globalThis.medeoPlugin.invoke('drive.retry', { folder }),
|
|
88
|
+
/** From a plugin window, with `file_access` declared: Medeo asks the user (a named `folder`, or a picker
|
|
89
|
+
* opened at the drive) and grants that folder; read and write it with `files.*` (see `resources.list`). */
|
|
90
|
+
requestFolder: (reason, folder) => globalThis.medeoPlugin.invoke('drive.requestFolder', folder === undefined ? { reason } : { reason, folder }),
|
|
91
|
+
};
|
|
92
|
+
/** Generic registered-provider entry point; the Host remains the authority. */
|
|
93
|
+
export const capabilities = {
|
|
94
|
+
list: () => globalThis.medeoPlugin.invoke('capabilities.list'),
|
|
95
|
+
labels: () => globalThis.medeoPlugin.invoke('capabilities.labels'),
|
|
96
|
+
invoke: (method, args = {}) => globalThis.medeoPlugin.invoke(method, args),
|
|
97
|
+
};
|
|
98
|
+
export const clipboard = { read: () => globalThis.medeoPlugin.invoke('clipboard.read'), write: (text) => globalThis.medeoPlugin.invoke('clipboard.write', { text }) };
|
|
99
|
+
export const system = { info: () => globalThis.medeoPlugin.invoke('system.info'), running: (rules) => capabilities.invoke('system.running', { rules }) };
|
|
100
|
+
/** `runtime: "node"` plugins only (the `node` permission): moves up to 256 absolute
|
|
101
|
+
* paths to the OS Trash, the one thing Node cannot do itself. A failure does not stop the rest. */
|
|
102
|
+
export const trash = (paths) => globalThis.medeoPlugin.invoke('system.trash', { paths });
|
|
103
|
+
export const notifications = { show: (id, title, body) => globalThis.medeoPlugin.invoke('notifications.show', { id, title, body }), close: (id) => globalThis.medeoPlugin.invoke('notifications.close', { id }) };
|
|
104
|
+
export const power = { start: (type) => globalThis.medeoPlugin.invoke('power.start', { type }), stop: (id) => globalThis.medeoPlugin.invoke('power.stop', { id }), state: () => globalThis.medeoPlugin.invoke('power.state') };
|
|
105
|
+
export const shortcuts = { list: () => globalThis.medeoPlugin.invoke('shortcuts.list'), register: (id, accelerator, openUI = false) => globalThis.medeoPlugin.invoke('shortcuts.register', { id, accelerator, open_ui: openUI }), unregister: (id) => globalThis.medeoPlugin.invoke('shortcuts.unregister', { id }), events: () => globalThis.medeoPlugin.invoke('shortcuts.events') };
|
|
106
|
+
/** `panel: true` (macOS): a frameless window floating over every app and Space that does not
|
|
107
|
+
* activate Medeo — the app the user was in keeps focus — opened at the pointer and hidden (not
|
|
108
|
+
* closed) when it loses focus; opening it again moves it to the pointer. `hide` keeps a window
|
|
109
|
+
* and its page alive for the next `open`/`focus`.
|
|
110
|
+
* `overlay: true` (macOS, needs `window_management` too): a transparent, shadowless panel covering
|
|
111
|
+
* the whole display under the pointer (menu bar included), above full-screen apps — for previews
|
|
112
|
+
* and radial menus. It takes keyboard focus without activating Medeo, hides when it loses focus,
|
|
113
|
+
* and each `open` moves it to the pointer's display; `width`/`height` are ignored. The page's
|
|
114
|
+
* `window.screenX/screenY` is the display's top-left in the same global points as
|
|
115
|
+
* `windowManagement`. `panel` and `overlay` are exclusive. */
|
|
116
|
+
export const appWindows = { open: (options) => globalThis.medeoPlugin.invoke('windows.open', options), close: (id) => globalThis.medeoPlugin.invoke('windows.close', { id }), focus: (id) => globalThis.medeoPlugin.invoke('windows.focus', { id }), hide: (id) => globalThis.medeoPlugin.invoke('windows.hide', { id }), list: () => globalThis.medeoPlugin.invoke('windows.list') };
|
|
117
|
+
export const tray = { set: (title, items, options = {}) => globalThis.medeoPlugin.invoke('tray.set', { title, items, ...options }), remove: () => globalThis.medeoPlugin.invoke('tray.remove'), events: () => globalThis.medeoPlugin.invoke('tray.events') };
|
|
118
|
+
export const external = { open: (url) => globalThis.medeoPlugin.invoke('external.open', { url }) };
|
|
119
|
+
export const permissions = { request: (permission, reason) => globalThis.medeoPlugin.invoke('permissions.request', { permission, reason }) };
|
|
120
|
+
export const approvals = {
|
|
121
|
+
request: (request) => globalThis.medeoPlugin.invoke('approvals.request', { ...request }),
|
|
122
|
+
rules: () => globalThis.medeoPlugin.invoke('approvals.rules'),
|
|
123
|
+
forget: (action, pattern) => globalThis.medeoPlugin.invoke('approvals.forget', { action, pattern }),
|
|
124
|
+
};
|
|
125
|
+
export const agent = {
|
|
126
|
+
models: () => capabilities.invoke('agent.models', {}),
|
|
127
|
+
start: (messages, model) => capabilities.invoke('agent.start', { messages, ...(model ? { model } : {}) }),
|
|
128
|
+
state: (id) => operations.state(id),
|
|
129
|
+
cancel: (id) => operations.cancel(id),
|
|
130
|
+
release: (id) => operations.release(id),
|
|
131
|
+
/** Calls `onText` as the reply streams in; resolves with the final job. */
|
|
132
|
+
async follow(id, onText) {
|
|
133
|
+
for (;;) {
|
|
134
|
+
const change = nextChange(id, 2000);
|
|
135
|
+
const job = await agent.state(id);
|
|
136
|
+
onText(job);
|
|
137
|
+
if (job.status !== 'running') {
|
|
138
|
+
change.off();
|
|
139
|
+
return job;
|
|
140
|
+
}
|
|
141
|
+
await change.promise;
|
|
142
|
+
change.off();
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
export const applications = {
|
|
147
|
+
/** The whole inventory; plugins rank and filter it themselves. */
|
|
148
|
+
list: (refresh = false) => capabilities.invoke('applications.list', { refresh }),
|
|
149
|
+
launch: (id) => capabilities.invoke('applications.launch', { id }),
|
|
150
|
+
state: () => capabilities.invoke('applications.state', {}),
|
|
151
|
+
/** 64 px PNG `data:` URLs (≤ 24 ids per call; `null` when the app has none). Ids not drawn yet are
|
|
152
|
+
* left out and counted in `pending`; ask again shortly. Medeo 0.1.33+. */
|
|
153
|
+
icons: (ids) => capabilities.invoke('applications.icons', { ids }),
|
|
154
|
+
};
|
|
155
|
+
const bridge = () => { const api = globalThis.medeoPlugin; if (!api.onLauncher || !api.launcher)
|
|
156
|
+
throw new Error('launcher_unavailable'); return api; };
|
|
157
|
+
export const launcher = {
|
|
158
|
+
/** Answer launcher searches and actions. Call it in `activate`; needs `contributes.launcher.provider`. */
|
|
159
|
+
provide(provider) {
|
|
160
|
+
// An older Medeo has no launchers to answer: the plugin runs on without being searchable.
|
|
161
|
+
if (!globalThis.medeoPlugin.onLauncher)
|
|
162
|
+
return { dispose() { } };
|
|
163
|
+
const off = bridge().onLauncher(async ({ op, payload }) => {
|
|
164
|
+
if (op === 'search')
|
|
165
|
+
return provider.search(String(payload?.query ?? ''), { scoped: payload?.scoped === true, limit: Number(payload?.limit) || 20 });
|
|
166
|
+
if (op === 'action') {
|
|
167
|
+
if (!provider.action)
|
|
168
|
+
throw new Error('action_unsupported');
|
|
169
|
+
return (await provider.action(String(payload?.item), String(payload?.action), { query: String(payload?.query ?? '') })) ?? null;
|
|
170
|
+
}
|
|
171
|
+
throw new Error('unknown_launcher_op');
|
|
172
|
+
});
|
|
173
|
+
return { dispose: off };
|
|
174
|
+
},
|
|
175
|
+
/** The session of a command a launcher started, from the command's `args`; null otherwise. */
|
|
176
|
+
session(args) {
|
|
177
|
+
const id = args?.launcher?.session;
|
|
178
|
+
if (typeof id !== 'string')
|
|
179
|
+
return null;
|
|
180
|
+
const send = (op, view) => bridge().launcher(op, id, view);
|
|
181
|
+
return {
|
|
182
|
+
id,
|
|
183
|
+
show: async (view) => { await send('update', view); },
|
|
184
|
+
progress: async (title, options = {}) => { await send('update', { type: 'progress', title, ...options }); },
|
|
185
|
+
confirm: async (view) => await send('prompt', { type: 'confirm', ...view }),
|
|
186
|
+
result: async (view) => { await send('update', { type: 'result', ...view }); },
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
/** Data sent to this command from another plugin's result, if any. */
|
|
190
|
+
input(args) {
|
|
191
|
+
const input = args?.input;
|
|
192
|
+
return input && typeof input.value === 'string' && typeof input.type === 'string' ? input : null;
|
|
193
|
+
},
|
|
194
|
+
// Launchers (`plugin_commands`):
|
|
195
|
+
/** Every provider's results for `query`, or one plugin's with `scope`. */
|
|
196
|
+
search: (query, options = {}) => capabilities.invoke('launcher.search', { query, ...options }),
|
|
197
|
+
act: (pluginId, item, action, query = '') => capabilities.invoke('launcher.act', { plugin_id: pluginId, item, action, query }),
|
|
198
|
+
/** Runs a command with a session: its views arrive as `launcher.events()` tagged with `session`. */
|
|
199
|
+
run: (pluginId, command, args, session) => capabilities.invoke('plugins.run', { plugin_id: pluginId, command, session, ...(args === undefined ? {} : { args }) }),
|
|
200
|
+
answer: (prompt, value) => capabilities.invoke('launcher.answer', { prompt, value }),
|
|
201
|
+
/** Drain on the `launcher` signal: `events.onSignal('launcher', …)`. */
|
|
202
|
+
events: () => capabilities.invoke('launcher.events', {}),
|
|
203
|
+
};
|
|
204
|
+
/** For launchers: other plugins' commands, run as if the user picked them in the plugin center.
|
|
205
|
+
* Needs the sensitive `plugin_commands` permission and Medeo 0.1.33+. A command started this way
|
|
206
|
+
* cannot call `plugins.run` itself (`recursive_command`). */
|
|
207
|
+
export const plugins = {
|
|
208
|
+
commands: () => capabilities.invoke('plugins.commands', {}),
|
|
209
|
+
run: (pluginId, command, args) => capabilities.invoke('plugins.run', { plugin_id: pluginId, command, ...(args === undefined ? {} : { args }) }),
|
|
210
|
+
open: (pluginId) => capabilities.invoke('plugins.open', { plugin_id: pluginId }),
|
|
211
|
+
/** Shows the plugin center on its Discover page, where the user installs more plugins. */
|
|
212
|
+
center: () => capabilities.invoke('plugins.center', {}),
|
|
213
|
+
/** Ask the user to install an official plugin this one works with (from a click). Medeo shows its own
|
|
214
|
+
* install confirmation; `installed` when it is there now (already, or just installed / updated). */
|
|
215
|
+
suggestInstall: (pluginId) => capabilities.invoke('plugins.suggestInstall', { plugin_id: pluginId }),
|
|
216
|
+
};
|
|
217
|
+
export const capture = {
|
|
218
|
+
status: (refresh = true) => capabilities.invoke('capture.status', { refresh }),
|
|
219
|
+
sources: (refresh = false, requestPermission = false) => capabilities.invoke('capture.sources', { refresh, request_permission: requestPermission }),
|
|
220
|
+
start: (source, options = {}) => capabilities.invoke('capture.start', { source, microphone: options.microphone ?? false, system_audio: options.systemAudio ?? false }),
|
|
221
|
+
state: () => capabilities.invoke('capture.state', {}),
|
|
222
|
+
stop: (id) => capabilities.invoke('capture.stop', { id }),
|
|
223
|
+
cancel: (id) => capabilities.invoke('capture.cancel', { id }),
|
|
224
|
+
recover: (id) => capabilities.invoke('capture.recover', { id }),
|
|
225
|
+
open: (id, mode = 'play') => capabilities.invoke('capture.open', { id, mode }),
|
|
226
|
+
previewURL: (id) => location.origin + '/_capture/' + encodeURIComponent(id) + '.mp4',
|
|
227
|
+
};
|
|
228
|
+
export const inputMethod = {
|
|
229
|
+
system: (refresh = false) => capabilities.invoke('input_method.system', { refresh }),
|
|
230
|
+
setup: () => capabilities.invoke('input_method.setup'),
|
|
231
|
+
remove: () => capabilities.invoke('input_method.remove'),
|
|
232
|
+
settings: () => capabilities.invoke('input_method.settings'),
|
|
233
|
+
status: () => capabilities.invoke('input_method.status'),
|
|
234
|
+
configure: (name) => capabilities.invoke('input_method.configure', { name }),
|
|
235
|
+
enable: () => capabilities.invoke('input_method.enable'),
|
|
236
|
+
disable: () => capabilities.invoke('input_method.disable'),
|
|
237
|
+
events: () => capabilities.invoke('input_method.events'),
|
|
238
|
+
respond: (id, candidates) => capabilities.invoke('input_method.respond', { id, candidates }),
|
|
239
|
+
};
|
|
240
|
+
export const network = {
|
|
241
|
+
origins: () => capabilities.invoke('network.origins'),
|
|
242
|
+
requestOrigin: (origin, reason) => capabilities.invoke('network.request_origin', { origin, reason }),
|
|
243
|
+
revokeOrigin: (origin) => capabilities.invoke('network.revoke_origin', { origin }),
|
|
244
|
+
request: (request) => capabilities.invoke('network.request', { ...request }),
|
|
245
|
+
state: (id) => operations.state(id),
|
|
246
|
+
read: (id, offset = 0, length = 32768) => capabilities.invoke('network.read', { id, offset, length }),
|
|
247
|
+
cancel: (id) => operations.cancel(id),
|
|
248
|
+
release: (id) => operations.release(id),
|
|
249
|
+
/** Resolves once the response has fully arrived; the job stays readable until released. */
|
|
250
|
+
async settled(id) { for (;;) {
|
|
251
|
+
const change = nextChange(id, 2000);
|
|
252
|
+
const state = await network.state(id);
|
|
253
|
+
if (state.status !== 'running') {
|
|
254
|
+
change.off();
|
|
255
|
+
return state;
|
|
256
|
+
}
|
|
257
|
+
await change.promise;
|
|
258
|
+
change.off();
|
|
259
|
+
} },
|
|
260
|
+
/** Single consumer for a stream:true job. Break/throw/abort cancels and releases it. */
|
|
261
|
+
async *bytes(id, signal) {
|
|
262
|
+
let offset = 0;
|
|
263
|
+
let abortCleanup;
|
|
264
|
+
const abort = () => { abortCleanup = network.dispose(id); void abortCleanup.catch(() => { }); };
|
|
265
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
266
|
+
try {
|
|
267
|
+
for (;;) {
|
|
268
|
+
let wake;
|
|
269
|
+
const changed = new Promise(resolve => { wake = resolve; });
|
|
270
|
+
const off = events.on(event => { if (event.type === 'operation' && event.id === id)
|
|
271
|
+
wake(); });
|
|
272
|
+
signal?.addEventListener('abort', wake, { once: true });
|
|
273
|
+
try {
|
|
274
|
+
if (signal?.aborted)
|
|
275
|
+
throw new Error('network_cancelled');
|
|
276
|
+
const state = await network.state(id);
|
|
277
|
+
if (state.status === 'failed' || state.status === 'cancelled')
|
|
278
|
+
throw new Error(state.error ?? state.status);
|
|
279
|
+
const part = await network.read(id, offset);
|
|
280
|
+
offset = part.next_offset;
|
|
281
|
+
if (signal?.aborted)
|
|
282
|
+
throw new Error('network_cancelled');
|
|
283
|
+
if (part.data_base64)
|
|
284
|
+
yield Uint8Array.from(atob(part.data_base64), c => c.charCodeAt(0));
|
|
285
|
+
if (part.eof)
|
|
286
|
+
return;
|
|
287
|
+
if (!part.data_base64)
|
|
288
|
+
await changed;
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
off();
|
|
292
|
+
signal?.removeEventListener('abort', wake);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
signal?.removeEventListener('abort', abort);
|
|
298
|
+
await (abortCleanup ?? network.dispose(id));
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
/** Incremental UTF-8 decoder, including code points split across HTTP chunks. */
|
|
302
|
+
async *textStream(id, signal) {
|
|
303
|
+
const decoder = new TextDecoder();
|
|
304
|
+
for await (const bytes of network.bytes(id, signal)) {
|
|
305
|
+
const text = decoder.decode(bytes, { stream: true });
|
|
306
|
+
if (text)
|
|
307
|
+
yield text;
|
|
308
|
+
}
|
|
309
|
+
const tail = decoder.decode();
|
|
310
|
+
if (tail)
|
|
311
|
+
yield tail;
|
|
312
|
+
},
|
|
313
|
+
/** SSE framing only: no automatic reconnect/retry or Last-Event-ID requests. */
|
|
314
|
+
async *sse(id, signal) {
|
|
315
|
+
let pending = '', data = [], event = '', lastId = '', retry, size = 0, skipLf = false;
|
|
316
|
+
for await (const text of network.textStream(id, signal)) {
|
|
317
|
+
pending += skipLf && text.startsWith('\n') ? text.slice(1) : text;
|
|
318
|
+
skipLf = false;
|
|
319
|
+
for (;;) {
|
|
320
|
+
const at = pending.search(/[\r\n]/);
|
|
321
|
+
if (at < 0)
|
|
322
|
+
break;
|
|
323
|
+
skipLf = pending[at] === '\r' && at === pending.length - 1;
|
|
324
|
+
const line = pending.slice(0, at);
|
|
325
|
+
pending = pending.slice(at + (pending[at] === '\r' && pending[at + 1] === '\n' ? 2 : 1));
|
|
326
|
+
size += line.length;
|
|
327
|
+
if (size > 262144)
|
|
328
|
+
throw new Error('network_sse_event_too_large');
|
|
329
|
+
if (!line) {
|
|
330
|
+
if (data.length)
|
|
331
|
+
yield { data: data.join('\n'), event: event || 'message', id: lastId, ...(retry === undefined ? {} : { retry }) };
|
|
332
|
+
data = [];
|
|
333
|
+
event = '';
|
|
334
|
+
size = 0;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (line.startsWith(':'))
|
|
338
|
+
continue;
|
|
339
|
+
const colon = line.indexOf(':');
|
|
340
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
341
|
+
let value = colon < 0 ? '' : line.slice(colon + 1);
|
|
342
|
+
if (value.startsWith(' '))
|
|
343
|
+
value = value.slice(1);
|
|
344
|
+
if (field === 'data')
|
|
345
|
+
data.push(value);
|
|
346
|
+
else if (field === 'event')
|
|
347
|
+
event = value;
|
|
348
|
+
else if (field === 'id' && !value.includes('\0'))
|
|
349
|
+
lastId = value;
|
|
350
|
+
else if (field === 'retry' && /^\d+$/.test(value) && Number.isSafeInteger(Number(value)))
|
|
351
|
+
retry = Number(value);
|
|
352
|
+
}
|
|
353
|
+
if (size + pending.length > 262144)
|
|
354
|
+
throw new Error('network_sse_event_too_large');
|
|
355
|
+
}
|
|
356
|
+
// SSE requires a blank line to dispatch; incomplete final events are discarded.
|
|
357
|
+
},
|
|
358
|
+
/** Explicitly dispose a stream that was never iterated (or has another owner). */
|
|
359
|
+
async dispose(id) {
|
|
360
|
+
const ignoreMissing = (error) => { if (!/^(operation_missing|network_job_missing|permission_denied)$/.test(error instanceof Error ? error.message : String(error)))
|
|
361
|
+
throw error; };
|
|
362
|
+
try {
|
|
363
|
+
await network.cancel(id);
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
ignoreMissing(error);
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
await network.release(id);
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
ignoreMissing(error);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
async text(id) {
|
|
376
|
+
const decoder = new TextDecoder();
|
|
377
|
+
let offset = 0, text = '';
|
|
378
|
+
for (;;) {
|
|
379
|
+
const part = await network.read(id, offset);
|
|
380
|
+
const bytes = Uint8Array.from(atob(part.data_base64), c => c.charCodeAt(0));
|
|
381
|
+
text += decoder.decode(bytes, { stream: !part.eof });
|
|
382
|
+
if (part.eof)
|
|
383
|
+
return text;
|
|
384
|
+
offset = part.next_offset;
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
export const files = {
|
|
389
|
+
backupPreview: (root, record) => capabilities.invoke('files.backup_preview', { root, record }),
|
|
390
|
+
archiveBackup: (preview) => capabilities.invoke('files.archive_backup', { preview }),
|
|
391
|
+
forgetPreview: (root, record) => capabilities.invoke('files.forget_preview', { root, record }),
|
|
392
|
+
forgetRecord: (preview) => capabilities.invoke('files.forget_record', { preview }),
|
|
393
|
+
historyPage: (root, cursor, limit = 50) => capabilities.invoke('files.history_page', { root, ...(cursor ? { cursor } : {}), limit }),
|
|
394
|
+
trashPreview: (root, path) => capabilities.invoke('files.trash_preview', { root, path }),
|
|
395
|
+
discardPreview: (preview) => capabilities.invoke('files.discard_preview', { preview }),
|
|
396
|
+
trash: (preview) => capabilities.invoke('files.trash', { preview }),
|
|
397
|
+
/** Breadth-first listings of a whole tree in one call. Hidden and `skip`
|
|
398
|
+
* directories are listed by their parent but not entered. */
|
|
399
|
+
listTree: (root, path = '', options = {}) => capabilities.invoke('files.list_tree', { root, path, ...options }),
|
|
400
|
+
/** Full-access roots only: move entries to the Trash without a Host confirmation.
|
|
401
|
+
* `stamp` is what `files.measure` returned; a changed entry is refused, not moved. */
|
|
402
|
+
trashDirect: (items) => capabilities.invoke('files.trash_direct', { items }),
|
|
403
|
+
watch: (root, path = '', recursive = false) => capabilities.invoke('files.watch', { root, path, recursive }),
|
|
404
|
+
watches: () => capabilities.invoke('files.watches'),
|
|
405
|
+
events: (id, after = 0) => capabilities.invoke('files.events', { id, after }),
|
|
406
|
+
unwatch: (id) => capabilities.invoke('files.unwatch', { id }),
|
|
407
|
+
roots: () => capabilities.invoke('files.roots'),
|
|
408
|
+
list: (root, path = '') => capabilities.invoke('files.list', { root, path }),
|
|
409
|
+
stat: (root, path = '') => capabilities.invoke('files.stat', { root, path }),
|
|
410
|
+
readText: (root, path, revision) => capabilities.invoke('files.read_text', { root, path, ...(revision ? { revision } : {}) }),
|
|
411
|
+
writeText: (root, path, text, revision) => capabilities.invoke('files.write_text', { root, path, text, revision }),
|
|
412
|
+
mkdir: (root, path) => capabilities.invoke('files.mkdir', { root, path }),
|
|
413
|
+
move: (root, path, destination, revision) => capabilities.invoke('files.move', { root, path, destination, revision }),
|
|
414
|
+
history: (root) => capabilities.invoke('files.history', { root }),
|
|
415
|
+
restore: (root, record) => capabilities.invoke('files.restore', { root, record }),
|
|
416
|
+
// Medeo 0.1.43+: files in and out of a grant. Bytes and real paths never pass through the plugin.
|
|
417
|
+
/** From a plugin window: the system picker; the chosen files become one-use sources. */
|
|
418
|
+
chooseFiles: () => capabilities.invoke('files.chooseFiles'),
|
|
419
|
+
/** Files dropped on this window (`event.dataTransfer.files` in a `drop` handler) as one-use sources. */
|
|
420
|
+
fromDrop: (files) => globalThis.medeoPlugin.dropped ? globalThis.medeoPlugin.dropped(Array.from(files)) : Promise.reject(new Error('capability_unavailable')), // a FileList does not cross the context bridge; an array of Files does
|
|
421
|
+
/** Copy a source to `path` in `root`; a taken name is `file_exists`, or `name (2).ext` with `keepBoth`. */
|
|
422
|
+
import: (root, path, source, options = {}) => capabilities.invoke('files.import', { root, path, source, ...(options.keepBoth ? { keep_both: true } : {}) }),
|
|
423
|
+
/** From a plugin window: copies to where the user picks (save panel for one file, a folder for several). */
|
|
424
|
+
export: (root, paths) => capabilities.invoke('files.export', { root, paths }),
|
|
425
|
+
/** From a plugin window: open with the default app / show in Finder. */
|
|
426
|
+
open: (root, path) => capabilities.invoke('files.open', { root, path }),
|
|
427
|
+
reveal: (root, path) => capabilities.invoke('files.reveal', { root, path }),
|
|
428
|
+
/** Call in a `dragstart` handler (after `event.preventDefault()`): the system drags these files out. */
|
|
429
|
+
startDrag: (root, paths) => capabilities.invoke('files.startDrag', { root, paths }),
|
|
430
|
+
state: (id) => operations.state(id),
|
|
431
|
+
cancel: (id) => operations.cancel(id),
|
|
432
|
+
release: (id) => operations.release(id),
|
|
433
|
+
result: (job) => operations.wait(job),
|
|
434
|
+
};
|
|
435
|
+
async function secretOperation(method, args) {
|
|
436
|
+
const job = await capabilities.invoke('secrets.' + method, args);
|
|
437
|
+
const deadline = Date.now() + 30000;
|
|
438
|
+
for (;;) {
|
|
439
|
+
const change = nextChange(job.id, 1000);
|
|
440
|
+
const result = await capabilities.invoke('secrets.result', { id: job.id });
|
|
441
|
+
if (result.status !== 'running')
|
|
442
|
+
change.off();
|
|
443
|
+
if (result.status === 'completed')
|
|
444
|
+
return result.value ?? null;
|
|
445
|
+
if (result.status === 'failed')
|
|
446
|
+
throw Error(result.error ?? 'secrets_storage_failed');
|
|
447
|
+
if (Date.now() >= deadline) {
|
|
448
|
+
change.off();
|
|
449
|
+
throw Error('secrets_outcome_unknown');
|
|
450
|
+
}
|
|
451
|
+
await change.promise;
|
|
452
|
+
change.off();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
export const secrets = {
|
|
456
|
+
get: (key) => secretOperation('get', { key }),
|
|
457
|
+
set: async (key, value) => { await secretOperation('set', { key, value }); },
|
|
458
|
+
remove: async (key) => { await secretOperation('remove', { key }); },
|
|
459
|
+
};
|
|
460
|
+
/** A loopback server is instance-owned and never survives Host restart. Keep the
|
|
461
|
+
* start token in private memory and serve requests in a worker for background use. */
|
|
462
|
+
export const server = {
|
|
463
|
+
start: (options) => capabilities.invoke('server.start', { ...options }),
|
|
464
|
+
state: (id) => capabilities.invoke('server.state', { id }),
|
|
465
|
+
list: () => capabilities.invoke('server.state'),
|
|
466
|
+
events: (id, limit = 8) => capabilities.invoke('server.events', { id, limit }),
|
|
467
|
+
respond: (id, request, response) => capabilities.invoke('server.respond', { id, request, ...response }),
|
|
468
|
+
stop: (id) => capabilities.invoke('server.stop', { id }),
|
|
469
|
+
};
|
|
470
|
+
/** Text is formatted in Rust from the signed package. Render with textContent,
|
|
471
|
+
* never innerHTML. Register listeners before initial state fetch to avoid races. */
|
|
472
|
+
export const i18n = {
|
|
473
|
+
state: () => capabilities.invoke('i18n.state'),
|
|
474
|
+
setLocale: (preference) => capabilities.invoke('i18n.setLocale', { preference }),
|
|
475
|
+
t: (key, params = {}) => capabilities.invoke('i18n.t', { key, params }),
|
|
476
|
+
/** Every message of the effective locale (default-locale fallback merged in). */
|
|
477
|
+
catalog: () => capabilities.invoke('i18n.catalog'),
|
|
478
|
+
onDidChangeLocale: (callback) => globalThis.medeoPlugin.onLocaleChanged(callback),
|
|
479
|
+
};
|
|
480
|
+
export const operations = {
|
|
481
|
+
state: (id) => capabilities.invoke('operations.state', { id }),
|
|
482
|
+
list: () => capabilities.invoke('operations.list'),
|
|
483
|
+
cancel: (id) => capabilities.invoke('operations.cancel', { id }),
|
|
484
|
+
release: (id) => capabilities.invoke('operations.release', { id }),
|
|
485
|
+
async wait(operation, signal) {
|
|
486
|
+
let value = operation;
|
|
487
|
+
while (value.status === 'running') {
|
|
488
|
+
if (signal?.aborted) {
|
|
489
|
+
await operations.cancel(value.id);
|
|
490
|
+
throw Error('cancelled');
|
|
491
|
+
}
|
|
492
|
+
const change = nextChange(value.id, 2000);
|
|
493
|
+
value = await operations.state(value.id);
|
|
494
|
+
if (value.status === 'running')
|
|
495
|
+
await change.promise;
|
|
496
|
+
change.off();
|
|
497
|
+
}
|
|
498
|
+
// Quick reads may come back settled and already released by the Host.
|
|
499
|
+
if (!value.released)
|
|
500
|
+
await operations.release(value.id);
|
|
501
|
+
if (value.status !== 'completed')
|
|
502
|
+
throw Error(value.error ?? value.status);
|
|
503
|
+
return value.result;
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
const nativeCall = (method, args = {}) => capabilities.invoke(method, args);
|
|
507
|
+
function mediaProvider(kind) {
|
|
508
|
+
return {
|
|
509
|
+
status: () => nativeCall(kind + '.status'),
|
|
510
|
+
start: (maxSeconds = 300) => nativeCall(kind + '.start', { max_seconds: maxSeconds }),
|
|
511
|
+
stop: (id) => nativeCall(kind + '.stop', { id }),
|
|
512
|
+
state: (id) => nativeCall(kind + '.state', id ? { id } : {}),
|
|
513
|
+
read: (id, offset = 0, length = 32768) => nativeCall(kind + '.read', { id, offset, length }),
|
|
514
|
+
/** Same-origin URL for an `<audio>` / `<video>` element; plays once the record is "completed". */
|
|
515
|
+
previewURL: (record) => location.origin + '/_media/' + encodeURIComponent(record.id) + (record.extension === 'm4a' ? '.m4a' : '.mp4'),
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export const camera = mediaProvider('camera'), microphone = mediaProvider('microphone'), systemAudio = mediaProvider('system_audio');
|
|
519
|
+
export const accessibility = { status: () => nativeCall('accessibility.status'), request: () => nativeCall('accessibility.request'), windows: () => nativeCall('accessibility.windows'), focus: (id) => nativeCall('accessibility.focus', { id }), selectedText: (id) => nativeCall('accessibility.selected_text', { id }), insertText: (focus, text) => nativeCall('accessibility.insert_text', { id: focus, text }) };
|
|
520
|
+
/** Window management (macOS, permission `window_management`, OS Accessibility). All calls are
|
|
521
|
+
* operations: `operations.wait(await windowManagement.focused())`. `request` opens the system
|
|
522
|
+
* prompt and is window-only; the others work in the worker too. `focused` never returns a Medeo window:
|
|
523
|
+
* when Medeo is in front (a plugin's own page) it is the window of the app right behind it, and `null`
|
|
524
|
+
* when there is none or the frontmost app has no window; `set_frame` reports the frame the app
|
|
525
|
+
* actually accepted (apps may clamp sizes) and fails with `resource_missing` once the window is gone. */
|
|
526
|
+
export const windowManagement = {
|
|
527
|
+
status: () => nativeCall('window_management.status'),
|
|
528
|
+
request: () => nativeCall('window_management.request'),
|
|
529
|
+
focused: () => nativeCall('window_management.focused'),
|
|
530
|
+
setFrame: (id, frame) => nativeCall('window_management.set_frame', { id, x: frame.x, y: frame.y, width: frame.width, height: frame.height }),
|
|
531
|
+
screens: () => nativeCall('window_management.screens'),
|
|
532
|
+
pointer: () => nativeCall('window_management.pointer'),
|
|
533
|
+
};
|
|
534
|
+
export const browserView = { open: (id, url, width = 1000, height = 720) => capabilities.invoke('browser.open', { id, url, width, height }), state: (id) => capabilities.invoke('browser.state', { id }), close: (id) => capabilities.invoke('browser.close', { id }) };
|
|
535
|
+
export const printing = { print: (text) => capabilities.invoke('printing.print', { text }) };
|
|
536
|
+
export const processes = { start: (executable, args = [], timeoutMs = 60000) => nativeCall('process.start', { executable, arguments: args, timeout_ms: timeoutMs }), state: (id) => nativeCall('process.state', { id }), write: (id, text) => nativeCall('process.write', { id, text }), stop: (id) => nativeCall('process.stop', { id }) };
|
|
537
|
+
export const background = { schedule: (id, delayMs, payload = null, intervalMs = 0) => capabilities.invoke('background.schedule', { id, delay_ms: delayMs, interval_ms: intervalMs, payload }), list: () => capabilities.invoke('background.list'), cancel: (id) => capabilities.invoke('background.cancel', { id }), events: () => capabilities.invoke('background.events') };
|
|
538
|
+
export const contacts = { status: () => nativeCall('contacts.status'), request: () => nativeCall('contacts.request'), list: (query = '', limit = 50) => nativeCall('contacts.list', { query, limit }), save: (contact) => nativeCall('contacts.save', contact) };
|
|
539
|
+
export const calendar = { status: () => nativeCall('calendar.status'), request: () => nativeCall('calendar.request'), list: (startMs, endMs, limit = 50) => nativeCall('calendar.list', { start_ms: startMs, end_ms: endMs, limit }), save: (event) => nativeCall('calendar.save', event) };
|
|
540
|
+
export const deviceLocation = { status: () => nativeCall('location.status'), request: () => nativeCall('location.request'), current: () => nativeCall('location.current') };
|
|
541
|
+
export const devices = { choose: (transport) => nativeCall('devices.choose', { transport }), open: (id, baudRate = 115200) => nativeCall('devices.open', { id, baud_rate: baudRate }), list: () => nativeCall('devices.list'), read: (id, length = 4096) => nativeCall('devices.read', { id, length }), write: (id, dataBase64) => nativeCall('devices.write', { id, data_base64: dataBase64 }), close: (id) => nativeCall('devices.close', { id }) };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** React is only imported by the optional @one2x/medeo-plugin-sdk/ui/react entry. */
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type CardOptions, type PillOptions, type ToggleOptions, type SegmentedOptions, type ListOptions } from './ui.js';
|
|
4
|
+
export { uiStyles, installStyles } from './ui/styles.js';
|
|
5
|
+
export type { CardOptions, PillOptions, ToggleOptions, SegmentedOptions, ListOptions, Segment } from './ui.js';
|
|
6
|
+
/** Call once near your root. SSR-safe; style installation is idempotent. */
|
|
7
|
+
export declare function useUIStyles(): void;
|
|
8
|
+
export declare function Card({ title, description, testid, children }: CardOptions & {
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}): import("react").DetailedReactHTMLElement<{
|
|
11
|
+
className: string;
|
|
12
|
+
'data-testid': string;
|
|
13
|
+
'aria-label': string;
|
|
14
|
+
}, HTMLElement>;
|
|
15
|
+
export declare function Pill({ label, tone, testid }: PillOptions): import("react").DetailedReactHTMLElement<{
|
|
16
|
+
className: string;
|
|
17
|
+
'data-testid': string;
|
|
18
|
+
'data-tone': "error" | "info" | "neutral";
|
|
19
|
+
}, HTMLElement>;
|
|
20
|
+
/** Controlled: update checked in onChange. Native input supplies name and Space handling. */
|
|
21
|
+
export declare function Toggle({ label, checked, disabled, onChange, testid }: ToggleOptions): import("react").DetailedReactHTMLElement<{
|
|
22
|
+
className: string;
|
|
23
|
+
'data-testid': string;
|
|
24
|
+
}, HTMLElement>;
|
|
25
|
+
/** Controlled radio group with a single tab stop and arrow/Home/End navigation. */
|
|
26
|
+
export declare function Segmented<T extends string>({ label, value, options, disabled, onChange, testid }: SegmentedOptions<T>): import("react").DetailedReactHTMLElement<{
|
|
27
|
+
className: string;
|
|
28
|
+
role: "radiogroup";
|
|
29
|
+
'aria-label': string;
|
|
30
|
+
'data-testid': string;
|
|
31
|
+
}, HTMLElement>;
|
|
32
|
+
export declare function List({ label, testid, items }: ListOptions & {
|
|
33
|
+
items: readonly {
|
|
34
|
+
key: string;
|
|
35
|
+
content: ReactNode;
|
|
36
|
+
}[];
|
|
37
|
+
}): import("react").DetailedReactHTMLElement<{
|
|
38
|
+
className: string;
|
|
39
|
+
'data-testid': string;
|
|
40
|
+
'aria-label': string;
|
|
41
|
+
}, HTMLElement>;
|
|
42
|
+
export declare function EmptyState({ title, description, testid }: CardOptions): import("react").DetailedReactHTMLElement<{
|
|
43
|
+
className: string;
|
|
44
|
+
'data-testid': string;
|
|
45
|
+
'aria-label': string;
|
|
46
|
+
}, HTMLElement>;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** React is only imported by the optional @one2x/medeo-plugin-sdk/ui/react entry. */
|
|
2
|
+
import { createElement as h, useEffect } from 'react';
|
|
3
|
+
import { segmentTarget, segmentTabIndex } from './ui.js';
|
|
4
|
+
import { installStyles } from './ui/styles.js';
|
|
5
|
+
export { uiStyles, installStyles } from './ui/styles.js';
|
|
6
|
+
/** Call once near your root. SSR-safe; style installation is idempotent. */
|
|
7
|
+
export function useUIStyles() { useEffect(() => { installStyles(); }, []); }
|
|
8
|
+
export function Card({ title, description, testid, children }) {
|
|
9
|
+
return h('section', { className: 'medeo-ui medeo-card', 'data-testid': testid, 'aria-label': title }, h('h2', { 'data-testid': `${testid}.title` }, title), description !== undefined && h('p', { className: 'medeo-description' }, description), children);
|
|
10
|
+
}
|
|
11
|
+
export function Pill({ label, tone = 'info', testid }) {
|
|
12
|
+
return h('span', { className: 'medeo-ui medeo-pill', 'data-testid': testid, 'data-tone': tone }, label);
|
|
13
|
+
}
|
|
14
|
+
/** Controlled: update checked in onChange. Native input supplies name and Space handling. */
|
|
15
|
+
export function Toggle({ label, checked, disabled, onChange, testid }) {
|
|
16
|
+
return h('label', { className: 'medeo-ui medeo-toggle', 'data-testid': `${testid}.root` }, h('input', { type: 'checkbox', role: 'switch', checked, disabled, 'data-testid': testid, onChange: (event) => onChange(event.currentTarget.checked) }), h('span', null, label));
|
|
17
|
+
}
|
|
18
|
+
/** Controlled radio group with a single tab stop and arrow/Home/End navigation. */
|
|
19
|
+
export function Segmented({ label, value, options, disabled, onChange, testid }) {
|
|
20
|
+
return h('div', { className: 'medeo-ui medeo-segmented', role: 'radiogroup', 'aria-label': label, 'data-testid': testid }, options.map((option, index) => h('button', {
|
|
21
|
+
key: option.value, type: 'button', role: 'radio', 'aria-checked': option.value === value,
|
|
22
|
+
'data-testid': `${testid}.${index}`, disabled: disabled || option.disabled,
|
|
23
|
+
tabIndex: disabled ? -1 : segmentTabIndex(options, value, index),
|
|
24
|
+
onClick: () => { if (!disabled && !option.disabled)
|
|
25
|
+
onChange(option.value); },
|
|
26
|
+
onKeyDown: (event) => {
|
|
27
|
+
if (disabled)
|
|
28
|
+
return;
|
|
29
|
+
const group = event.currentTarget.parentElement;
|
|
30
|
+
const target = segmentTarget(options, index, event.key, getComputedStyle(group).direction === 'rtl');
|
|
31
|
+
if (target === undefined)
|
|
32
|
+
return;
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
group.children[target].focus();
|
|
35
|
+
onChange(options[target].value);
|
|
36
|
+
},
|
|
37
|
+
}, option.label)));
|
|
38
|
+
}
|
|
39
|
+
export function List({ label, testid, items }) {
|
|
40
|
+
return h('ul', { className: 'medeo-ui medeo-list', 'data-testid': testid, 'aria-label': label }, items.map(item => h('li', { key: item.key, 'data-testid': `${testid}.${item.key}` }, item.content)));
|
|
41
|
+
}
|
|
42
|
+
export function EmptyState({ title, description, testid }) {
|
|
43
|
+
return h('section', { className: 'medeo-ui medeo-empty', 'data-testid': testid, 'aria-label': title }, h('h2', null, title), description !== undefined && h('p', { className: 'medeo-description' }, description));
|
|
44
|
+
}
|