epos 2.0.1 → 2.0.2
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/dist/epos.d.ts +273 -83
- package/dist/epos.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +3 -0
- package/README.md +0 -3
- /package/{LICENSE.md → license.md} +0 -0
package/dist/epos.d.ts
CHANGED
|
@@ -9,195 +9,361 @@ import type * as yjs from 'yjs';
|
|
|
9
9
|
import type { Browser } from './browser.js';
|
|
10
10
|
import type { Spec } from './spec.js';
|
|
11
11
|
export interface Epos {
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Fetch a resource through the extension runtime.
|
|
14
|
+
*
|
|
15
|
+
* Behaves like `fetch`, but bypasses page CORS restrictions and returns a
|
|
16
|
+
* simplified response object without stream support.
|
|
17
|
+
*/
|
|
13
18
|
fetch: EposFetch;
|
|
14
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* WebExtensions API. Like `chrome.*`, but works in any context.
|
|
21
|
+
*/
|
|
15
22
|
browser: Browser;
|
|
16
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Render a React tree into the provided container.
|
|
25
|
+
*
|
|
26
|
+
* When `container` is omitted, Epos uses its pre-created default view.
|
|
27
|
+
*/
|
|
17
28
|
render(node: react.ReactNode, container?: reactDomClient.Container): void;
|
|
18
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a React component so it reacts to Epos-managed observable state.
|
|
31
|
+
*/
|
|
19
32
|
component<T>(Component: react.FC<T>): react.FC<T>;
|
|
20
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Environment variables.
|
|
35
|
+
*/
|
|
21
36
|
env: EposEnv;
|
|
22
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* DOM elements created by Epos.
|
|
39
|
+
*/
|
|
23
40
|
dom: EposDom;
|
|
24
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Event bus for cross-context communication.
|
|
43
|
+
*/
|
|
25
44
|
bus: EposBus;
|
|
26
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* State management.
|
|
47
|
+
*/
|
|
27
48
|
state: EposState;
|
|
28
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Storage management.
|
|
51
|
+
*/
|
|
29
52
|
storage: EposStorage;
|
|
30
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Asset management.
|
|
55
|
+
*/
|
|
31
56
|
assets: EposAssets;
|
|
32
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Background frames management.
|
|
59
|
+
*/
|
|
33
60
|
frames: EposFrames;
|
|
34
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Project management.
|
|
63
|
+
*/
|
|
35
64
|
projects: EposProjects;
|
|
36
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Third party libraries used by Epos.
|
|
67
|
+
*/
|
|
37
68
|
libs: EposLibs;
|
|
38
69
|
}
|
|
39
70
|
export type EposFetch = (url: string | URL, init?: ReqInit) => Promise<Res>;
|
|
40
71
|
export interface EposEnv {
|
|
41
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Tab identifier, -1 for background and iframes.
|
|
74
|
+
*/
|
|
42
75
|
tabId: -1 | number;
|
|
43
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Window identifier, -1 for background and iframes.
|
|
78
|
+
*/
|
|
44
79
|
windowId: -1 | number;
|
|
45
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Indicates if running in `<popup>` context.
|
|
82
|
+
*/
|
|
46
83
|
isPopup: boolean;
|
|
47
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Indicates if running in `<sidePanel>` context.
|
|
86
|
+
*/
|
|
48
87
|
isSidePanel: boolean;
|
|
49
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Indicates if running in `<background>` context.
|
|
90
|
+
*/
|
|
50
91
|
isBackground: boolean;
|
|
51
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Current project data.
|
|
94
|
+
*/
|
|
52
95
|
project: Project;
|
|
53
96
|
}
|
|
54
97
|
export interface EposDom {
|
|
55
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Project's root element.
|
|
100
|
+
*/
|
|
56
101
|
root: HTMLDivElement;
|
|
57
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Pre-created element used as default container for React.
|
|
104
|
+
*/
|
|
58
105
|
view: HTMLDivElement;
|
|
59
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Pre-created shadow DOM.
|
|
108
|
+
*/
|
|
60
109
|
shadowRoot: ShadowRoot;
|
|
61
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Pre-created element inside shadow DOM used as default container for React.
|
|
112
|
+
*/
|
|
62
113
|
shadowView: HTMLDivElement;
|
|
63
114
|
}
|
|
64
115
|
export interface EposBus {
|
|
65
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Register an event listener.
|
|
118
|
+
*
|
|
119
|
+
* Listeners added with the same `name` are invoked in registration order.
|
|
120
|
+
* `thisArg` becomes `this` inside non-arrow callbacks.
|
|
121
|
+
*
|
|
122
|
+
* A listener may return a value, and that value becomes the resolved result
|
|
123
|
+
* of `send()` for the matching event.
|
|
124
|
+
*/
|
|
66
125
|
on<T extends Fn>(name: string, callback: T, thisArg?: unknown): void;
|
|
67
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Remove a previously registered event listener.
|
|
128
|
+
*
|
|
129
|
+
* When `callback` is omitted, every listener registered for `name` is removed.
|
|
130
|
+
*/
|
|
68
131
|
off<T extends Fn>(name: string, callback?: T): void;
|
|
69
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Register a one-time event listener.
|
|
134
|
+
*
|
|
135
|
+
* The listener is removed immediately after the first matching event.
|
|
136
|
+
*/
|
|
70
137
|
once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void;
|
|
71
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Send an event to other extension contexts.
|
|
140
|
+
*
|
|
141
|
+
* Resolves with the first value returned by a remote `on()` listener, if any
|
|
142
|
+
* remote listener responds.
|
|
143
|
+
*/
|
|
72
144
|
send<T>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | undefined>;
|
|
73
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Emit an event to local listeners only. Does not trigger remote listeners in other contexts.
|
|
147
|
+
*
|
|
148
|
+
* Resolves with the first returned value, if any local listener responds.
|
|
149
|
+
*/
|
|
74
150
|
emit<T>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | undefined>;
|
|
75
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Set a signal that can be awaited with `waitSignal()`.
|
|
153
|
+
*/
|
|
76
154
|
setSignal(name: string, value?: unknown): void;
|
|
77
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Wait for a signal to be set with `setSignal()`.
|
|
157
|
+
*/
|
|
78
158
|
waitSignal<T>(name: string, timeout?: number): Promise<T | undefined>;
|
|
79
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Register a service that can be used remotely with `use()`.
|
|
161
|
+
*/
|
|
80
162
|
register(name: string, api: Obj<any>): void;
|
|
81
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Remove a previously registered service.
|
|
165
|
+
*/
|
|
82
166
|
unregister(name: string): void;
|
|
83
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Get an object that represents remote service registered with `register()`.
|
|
169
|
+
*/
|
|
84
170
|
use<T extends Obj<any>>(name: string): BusService<T>;
|
|
85
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Create a namespaced bus API to avoid naming collisions.
|
|
173
|
+
*/
|
|
86
174
|
for(namespace: string): Omit<EposBus, 'for'> & {
|
|
87
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Dispose namespaced bus instance. Removes all its listeners and ignores any further method calls.
|
|
177
|
+
*/
|
|
88
178
|
dispose: () => void;
|
|
89
179
|
};
|
|
90
180
|
}
|
|
91
181
|
export interface EposState {
|
|
92
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Connect to a shared reactive state.
|
|
184
|
+
*/
|
|
93
185
|
connect: {
|
|
94
186
|
<T>(initial?: Initial<T>, versioner?: Versioner<T>): Promise<T>;
|
|
95
187
|
<T>(name?: string, initial?: Initial<T>, versioner?: Versioner<T>): Promise<T>;
|
|
96
188
|
};
|
|
97
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* Disconnect from a shared reactive state.
|
|
191
|
+
*/
|
|
98
192
|
disconnect(name?: string): void;
|
|
99
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Batch multiple state mutations into a single reactive update.
|
|
195
|
+
*/
|
|
100
196
|
transaction: (fn: () => void) => void;
|
|
101
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* MobX `reaction` method placed on `epos.state` for convenience.
|
|
199
|
+
*/
|
|
102
200
|
reaction: typeof mobx.reaction;
|
|
103
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* Create observable local state that is not synchronized across contexts.
|
|
203
|
+
*/
|
|
104
204
|
local<T extends {}>(initial?: Initial<T>): T;
|
|
105
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* List known shared states.
|
|
207
|
+
*/
|
|
106
208
|
list(filter?: {
|
|
107
209
|
connected?: boolean;
|
|
108
210
|
}): Promise<{
|
|
109
211
|
name: string | null;
|
|
110
212
|
connected: boolean;
|
|
111
213
|
}[]>;
|
|
112
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Delete a shared state and its data.
|
|
216
|
+
*/
|
|
113
217
|
remove(name?: string): Promise<void>;
|
|
114
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Register models that can be used in any shared state.
|
|
220
|
+
*
|
|
221
|
+
* Models should be registered before `epos.state.connect` is called.
|
|
222
|
+
*/
|
|
115
223
|
register(models: Record<string, Ctor>): void;
|
|
116
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Parent access for state objects and arrays.
|
|
226
|
+
*/
|
|
117
227
|
PARENT: symbol;
|
|
228
|
+
/**
|
|
229
|
+
* Attach hook for state objects and arrays.
|
|
230
|
+
*/
|
|
118
231
|
ATTACH: symbol;
|
|
232
|
+
/**
|
|
233
|
+
* Detach hook for state objects and arrays.
|
|
234
|
+
*/
|
|
119
235
|
DETACH: symbol;
|
|
120
236
|
}
|
|
121
237
|
export interface EposStorage {
|
|
122
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* Read a value from storage.
|
|
240
|
+
*/
|
|
123
241
|
get: {
|
|
124
242
|
<T>(key: string): Promise<T | null>;
|
|
125
243
|
<T>(name: string, key: string): Promise<T | null>;
|
|
126
244
|
};
|
|
127
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Write a value to storage.
|
|
247
|
+
*/
|
|
128
248
|
set: {
|
|
129
249
|
<T>(key: string, value: T): Promise<void>;
|
|
130
250
|
<T>(name: string, key: string, value: T): Promise<void>;
|
|
131
251
|
};
|
|
132
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Check whether a key exists in storage.
|
|
254
|
+
*/
|
|
133
255
|
has: {
|
|
134
256
|
(key: string): Promise<boolean>;
|
|
135
257
|
(name: string, key: string): Promise<boolean>;
|
|
136
258
|
};
|
|
137
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Delete a key from storage.
|
|
261
|
+
*/
|
|
138
262
|
delete: {
|
|
139
263
|
(key: string): Promise<void>;
|
|
140
264
|
(name: string, key: string): Promise<void>;
|
|
141
265
|
};
|
|
142
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* List storage keys.
|
|
268
|
+
*/
|
|
143
269
|
keys(name?: string): Promise<string[]>;
|
|
144
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* List all existing storages.
|
|
272
|
+
*/
|
|
145
273
|
list(): Promise<{
|
|
146
274
|
name: string | null;
|
|
147
275
|
}[]>;
|
|
148
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* Remove storage and all its data.
|
|
278
|
+
*/
|
|
149
279
|
clear(name?: string): Promise<void>;
|
|
150
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* Create a namespaced storage API.
|
|
282
|
+
*/
|
|
151
283
|
for(name?: string): {
|
|
152
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Read a value from storage.
|
|
286
|
+
*/
|
|
153
287
|
get<T>(key: string): Promise<T | null>;
|
|
154
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* Write a value to storage.
|
|
290
|
+
*/
|
|
155
291
|
set(key: string, value: unknown): Promise<void>;
|
|
156
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* Check whether a key exists in storage.
|
|
294
|
+
*/
|
|
157
295
|
has(key: string): Promise<boolean>;
|
|
158
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Delete a key from storage.
|
|
298
|
+
*/
|
|
159
299
|
delete(key: string): Promise<void>;
|
|
160
|
-
/**
|
|
300
|
+
/**
|
|
301
|
+
* List all keys in storage.
|
|
302
|
+
*/
|
|
161
303
|
keys(): Promise<string[]>;
|
|
162
|
-
/**
|
|
304
|
+
/**
|
|
305
|
+
* Remove storage and all its data.
|
|
306
|
+
*/
|
|
163
307
|
clear(): Promise<void>;
|
|
164
308
|
};
|
|
165
309
|
}
|
|
166
310
|
export interface EposAssets {
|
|
167
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* Get a URL for an asset.
|
|
313
|
+
*/
|
|
168
314
|
url(path: string): string;
|
|
169
|
-
/**
|
|
315
|
+
/**
|
|
316
|
+
* Read an asset as a `Blob`.
|
|
317
|
+
*
|
|
318
|
+
* If the asset is not currently loaded, Epos reads it from IndexedDB directly.
|
|
319
|
+
*
|
|
320
|
+
* Returns `null` when the asset is unknown or not available.
|
|
321
|
+
*/
|
|
170
322
|
get(path: string): Promise<Blob | null>;
|
|
171
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* List declared assets and whether each one is currently loaded in memory.
|
|
325
|
+
*/
|
|
172
326
|
list(filter?: {
|
|
173
327
|
loaded?: boolean;
|
|
174
328
|
}): {
|
|
175
329
|
path: string;
|
|
176
330
|
loaded: boolean;
|
|
177
331
|
}[];
|
|
178
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Load an asset into memory.
|
|
334
|
+
*
|
|
335
|
+
* Call without arguments to load all assets.
|
|
336
|
+
*/
|
|
179
337
|
load: {
|
|
180
|
-
/** Load all assets. */
|
|
181
338
|
(): Promise<void>;
|
|
182
|
-
/** Load specified asset. */
|
|
183
339
|
(path: string): Promise<void>;
|
|
184
340
|
};
|
|
185
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* Unload an asset from memory.
|
|
343
|
+
*
|
|
344
|
+
* Call without arguments to unload all assets.
|
|
345
|
+
*/
|
|
186
346
|
unload: {
|
|
187
|
-
/** Unload all assets. */
|
|
188
347
|
(): void;
|
|
189
|
-
/** Unload specified asset. */
|
|
190
348
|
(path: string): void;
|
|
191
349
|
};
|
|
192
350
|
}
|
|
193
351
|
export interface EposFrames {
|
|
194
|
-
/**
|
|
352
|
+
/**
|
|
353
|
+
* Create a hidden background frame and return its id.
|
|
354
|
+
*/
|
|
195
355
|
create(url: string, attrs?: Attrs): Promise<string>;
|
|
196
|
-
/**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/**
|
|
356
|
+
/**
|
|
357
|
+
* Remove a background frame by id.
|
|
358
|
+
*/
|
|
359
|
+
remove(id: string): Promise<void>;
|
|
360
|
+
/**
|
|
361
|
+
* Check whether a background frame with the given id exists.
|
|
362
|
+
*/
|
|
363
|
+
has(id: string): Promise<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* List all currently open background frames.
|
|
366
|
+
*/
|
|
201
367
|
list(): Promise<{
|
|
202
368
|
id: string;
|
|
203
369
|
name: string;
|
|
@@ -205,26 +371,50 @@ export interface EposFrames {
|
|
|
205
371
|
}[]>;
|
|
206
372
|
}
|
|
207
373
|
export interface EposProjects {
|
|
208
|
-
/**
|
|
374
|
+
/**
|
|
375
|
+
* Check whether a project exists.
|
|
376
|
+
*/
|
|
209
377
|
has(id: string): Promise<boolean>;
|
|
210
|
-
/**
|
|
378
|
+
/**
|
|
379
|
+
* Load a project by id.
|
|
380
|
+
*
|
|
381
|
+
* `query` controls whether heavyweight fields like `sources` and `assets`
|
|
382
|
+
* are included in the returned object.
|
|
383
|
+
*/
|
|
211
384
|
get<T extends ProjectQuery>(id: string, query?: T): Promise<Project<T> | null>;
|
|
212
|
-
/**
|
|
385
|
+
/**
|
|
386
|
+
* List projects.
|
|
387
|
+
*
|
|
388
|
+
* `query` controls whether heavyweight fields like `sources` and `assets`
|
|
389
|
+
* are included in each returned object.
|
|
390
|
+
*/
|
|
213
391
|
list<T extends ProjectQuery>(query?: T): Promise<Project<T>[]>;
|
|
214
|
-
/**
|
|
392
|
+
/**
|
|
393
|
+
* Create a project from a bundle and optional settings.
|
|
394
|
+
*/
|
|
215
395
|
create<T extends string>(params: Bundle & Partial<{
|
|
216
396
|
id: T;
|
|
217
397
|
} & ProjectSettings>): Promise<T>;
|
|
218
|
-
/**
|
|
398
|
+
/**
|
|
399
|
+
* Update an existing project's bundle data or runtime settings.
|
|
400
|
+
*/
|
|
219
401
|
update(id: string, updates: Partial<Bundle & ProjectSettings>): Promise<void>;
|
|
220
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Permanently remove a project.
|
|
404
|
+
*/
|
|
221
405
|
remove(id: string): Promise<void>;
|
|
222
|
-
/**
|
|
406
|
+
/**
|
|
407
|
+
* Export a project as a map of files ready for download or external use.
|
|
408
|
+
*/
|
|
223
409
|
export(id: string): Promise<Record<string, Blob>>;
|
|
224
|
-
/**
|
|
410
|
+
/**
|
|
411
|
+
* Subscribe to project registry changes.
|
|
412
|
+
*/
|
|
225
413
|
watch(listener: () => void): void;
|
|
226
|
-
/**
|
|
227
|
-
|
|
414
|
+
/**
|
|
415
|
+
* Fetch and assemble a project bundle from a remote `epos.json` spec URL.
|
|
416
|
+
*/
|
|
417
|
+
fetch(eposJsonUrl: string): Promise<Bundle>;
|
|
228
418
|
}
|
|
229
419
|
export interface EposLibs {
|
|
230
420
|
mobx: typeof mobx;
|
package/dist/epos.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epos.js","sourceRoot":"","sources":["../src/epos.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"epos.js","sourceRoot":"","sources":["../src/epos.ts"],"names":[],"mappings":"AAweA,MAAM,KAAK,GAAG,IAAI,CAAA;AAClB,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA;AAExB,eAAe,KAAK,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epos",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@eposlabs/utils": "^1.26.0",
|
|
31
|
-
"@types/chrome": "^0.1.
|
|
31
|
+
"@types/chrome": "^0.1.39",
|
|
32
32
|
"@types/react": "^19.2.14",
|
|
33
33
|
"@types/react-dom": "^19.2.3",
|
|
34
34
|
"browser-extension-url-match": "^1.2.0",
|
package/readme.md
ADDED
package/README.md
DELETED
|
File without changes
|