epos 1.8.3 → 1.8.4
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 +34 -50
- package/dist/vite.js +2 -2
- package/package.json +3 -3
- package/src/epos.ts +29 -46
- package/src/vite.ts +2 -2
package/dist/epos.d.ts
CHANGED
|
@@ -11,11 +11,8 @@ type Obj = Record<string, unknown>;
|
|
|
11
11
|
type Versioner = Record<number, (this: any, state: any) => void>;
|
|
12
12
|
type ClassName = string | null | boolean | undefined | ClassName[];
|
|
13
13
|
type ModelClass = new (...args: any[]) => any;
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
models?: Record<string, ModelClass>;
|
|
17
|
-
versioner?: Versioner;
|
|
18
|
-
};
|
|
14
|
+
type Model = InstanceType<ModelClass>;
|
|
15
|
+
type Initial<T extends Obj | Model> = T | (() => T);
|
|
19
16
|
type Storage = {
|
|
20
17
|
/** Get value from the storage. */
|
|
21
18
|
get<T = unknown>(key: string): Promise<T>;
|
|
@@ -52,8 +49,8 @@ interface Epos {
|
|
|
52
49
|
state: {
|
|
53
50
|
/** Connect state. */
|
|
54
51
|
connect: {
|
|
55
|
-
<T extends Obj>(
|
|
56
|
-
<T extends Obj>(
|
|
52
|
+
<T extends Obj | Model>(initial?: Initial<T>, versioner?: Versioner): Promise<T>;
|
|
53
|
+
<T extends Obj | Model>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>;
|
|
57
54
|
};
|
|
58
55
|
/** Disconnect state. */
|
|
59
56
|
disconnect(name?: string): void;
|
|
@@ -64,20 +61,18 @@ interface Epos {
|
|
|
64
61
|
/** Get the list of all state names. */
|
|
65
62
|
list(filter?: {
|
|
66
63
|
connected?: boolean;
|
|
67
|
-
}): Promise<
|
|
64
|
+
}): Promise<{
|
|
68
65
|
name: string | null;
|
|
69
|
-
}
|
|
66
|
+
}[]>;
|
|
70
67
|
/** Remove state and all its data. */
|
|
71
68
|
destroy(name?: string): Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
|
|
69
|
+
/** Register models for all states. */
|
|
70
|
+
registerModels(models: Record<string, ModelClass>): void;
|
|
74
71
|
symbols: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
readonly parent: unique symbol;
|
|
80
|
-
};
|
|
72
|
+
readonly parent: unique symbol;
|
|
73
|
+
readonly modelInit: unique symbol;
|
|
74
|
+
readonly modelCleanup: unique symbol;
|
|
75
|
+
readonly modelVersioner: unique symbol;
|
|
81
76
|
};
|
|
82
77
|
};
|
|
83
78
|
storage: {
|
|
@@ -91,15 +86,26 @@ interface Epos {
|
|
|
91
86
|
keys(storageName?: string): Promise<string[]>;
|
|
92
87
|
/** Clear storage. Removes all keys and storage itself. */
|
|
93
88
|
clear(storageName?: string): Promise<void>;
|
|
94
|
-
/**
|
|
95
|
-
use(
|
|
96
|
-
/** Get list of all
|
|
97
|
-
list(): Promise<
|
|
89
|
+
/** Get storage API for a specific storage. */
|
|
90
|
+
use(storageName: string): Promise<Storage>;
|
|
91
|
+
/** Get this list of all storages. */
|
|
92
|
+
list(): Promise<{
|
|
98
93
|
name: string | null;
|
|
99
|
-
}
|
|
94
|
+
}[]>;
|
|
95
|
+
};
|
|
96
|
+
frame: {
|
|
97
|
+
/** Open frame in the background. */
|
|
98
|
+
open(name: string, url: string, attributes?: Record<string, unknown>): Promise<void>;
|
|
99
|
+
/** Remove background frame by its name. */
|
|
100
|
+
close(name: string): Promise<void>;
|
|
101
|
+
/** Get list of all open background frames. */
|
|
102
|
+
list(): Promise<{
|
|
103
|
+
name: string;
|
|
104
|
+
url: string;
|
|
105
|
+
}[]>;
|
|
100
106
|
};
|
|
101
107
|
assets: {
|
|
102
|
-
/** Get asset URL.
|
|
108
|
+
/** Get asset URL. The asset must be loaded first. */
|
|
103
109
|
url(path: string): string;
|
|
104
110
|
/** Load asset by path. */
|
|
105
111
|
load(path: string): Promise<Blob>;
|
|
@@ -109,42 +115,20 @@ interface Epos {
|
|
|
109
115
|
unload(path: string): void;
|
|
110
116
|
/** Unload all assets from memory. */
|
|
111
117
|
unloadAll(): void;
|
|
112
|
-
/** Get list of all available
|
|
118
|
+
/** Get list of all available assets. */
|
|
113
119
|
list(filter?: {
|
|
114
120
|
loaded?: boolean;
|
|
115
|
-
}):
|
|
121
|
+
}): {
|
|
116
122
|
path: string;
|
|
117
123
|
loaded: boolean;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
frames: {
|
|
121
|
-
/** Create a new frame. */
|
|
122
|
-
create(name: string, url: string, attributes?: Record<string, unknown>): Promise<void>;
|
|
123
|
-
/** Remove frame by name. */
|
|
124
|
-
remove(name: string): Promise<void>;
|
|
125
|
-
/** Get list of all created frames. */
|
|
126
|
-
list(): Promise<Array<{
|
|
127
|
-
name: string;
|
|
128
|
-
url: string;
|
|
129
|
-
}>>;
|
|
124
|
+
}[];
|
|
130
125
|
};
|
|
131
126
|
env: {
|
|
132
|
-
/** Current tab ID. */
|
|
133
127
|
tabId: number;
|
|
134
|
-
|
|
135
|
-
isTab: boolean;
|
|
136
|
-
/** True if running in an iframe. */
|
|
137
|
-
isFrame: boolean;
|
|
138
|
-
/** True if running in a popup or side panel (`<popup>` or `<sidePanel>`). */
|
|
139
|
-
isShell: boolean;
|
|
140
|
-
/** True if running in a popup (`<popup>`). */
|
|
128
|
+
isWeb: boolean;
|
|
141
129
|
isPopup: boolean;
|
|
142
|
-
/** True if running in a side panel (`<sidePanel>`). */
|
|
143
130
|
isSidePanel: boolean;
|
|
144
|
-
/** True if running in the background (`<background>`). */
|
|
145
131
|
isBackground: boolean;
|
|
146
|
-
/** True if running in the foreground (not `<background>` and not inside iframe). */
|
|
147
|
-
isForeground: boolean;
|
|
148
132
|
};
|
|
149
133
|
libs: {
|
|
150
134
|
mobx: typeof mobx;
|
|
@@ -167,4 +151,4 @@ declare global {
|
|
|
167
151
|
declare const _epos: Epos;
|
|
168
152
|
var epos$1 = epos;
|
|
169
153
|
|
|
170
|
-
export { type ClassName, type
|
|
154
|
+
export { type ClassName, type Epos, type Fn, type Initial, type Model, type ModelClass, type Obj, type Storage, type Versioner, epos$1 as default, _epos as epos };
|
package/dist/vite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/vite.ts
|
|
2
2
|
import { resolve } from "path";
|
|
3
|
-
var
|
|
3
|
+
var libs = {
|
|
4
4
|
"react": resolve(import.meta.dirname, "./libs/libs-react.js"),
|
|
5
5
|
"react/jsx-runtime": resolve(import.meta.dirname, "./libs/libs-react-jsx-runtime.js"),
|
|
6
6
|
"react-dom": resolve(import.meta.dirname, "./libs/libs-react-dom.js"),
|
|
@@ -12,7 +12,7 @@ function epos() {
|
|
|
12
12
|
return {
|
|
13
13
|
name: "epos",
|
|
14
14
|
enforce: "pre",
|
|
15
|
-
resolveId: (source) =>
|
|
15
|
+
resolveId: (source) => libs[source] ?? null
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
var vite_default = epos;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epos",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
7
7
|
"description": "",
|
|
8
8
|
"keywords": [],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsup src --format esm --dts --clean",
|
|
10
|
+
"build": "tsup src --format esm --dts --clean --no-splitting",
|
|
11
11
|
"lint": "tsc --noEmit",
|
|
12
12
|
"release": "sh -c 'npm version ${1:-patch} && npm run build && npm publish' --"
|
|
13
13
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/react": "^19.1.14",
|
|
36
36
|
"@types/react-dom": "^19.1.9",
|
|
37
37
|
"mobx": "^6.15.0",
|
|
38
|
-
"mobx-react-lite": "^4.1.
|
|
38
|
+
"mobx-react-lite": "^4.1.1",
|
|
39
39
|
"react": "^19.1.1",
|
|
40
40
|
"yjs": "^13.6.27"
|
|
41
41
|
},
|
package/src/epos.ts
CHANGED
|
@@ -11,12 +11,8 @@ export type Obj = Record<string, unknown>
|
|
|
11
11
|
export type Versioner = Record<number, (this: any, state: any) => void>
|
|
12
12
|
export type ClassName = string | null | boolean | undefined | ClassName[]
|
|
13
13
|
export type ModelClass = new (...args: any[]) => any
|
|
14
|
-
|
|
15
|
-
export type
|
|
16
|
-
getInitialState?: () => T
|
|
17
|
-
models?: Record<string, ModelClass>
|
|
18
|
-
versioner?: Versioner
|
|
19
|
-
}
|
|
14
|
+
export type Model = InstanceType<ModelClass>
|
|
15
|
+
export type Initial<T extends Obj | Model> = T | (() => T)
|
|
20
16
|
|
|
21
17
|
export type Storage = {
|
|
22
18
|
/** Get value from the storage. */
|
|
@@ -60,8 +56,8 @@ export interface Epos {
|
|
|
60
56
|
state: {
|
|
61
57
|
/** Connect state. */
|
|
62
58
|
connect: {
|
|
63
|
-
<T extends Obj>(
|
|
64
|
-
<T extends Obj>(
|
|
59
|
+
<T extends Obj | Model>(initial?: Initial<T>, versioner?: Versioner): Promise<T>
|
|
60
|
+
<T extends Obj | Model>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>
|
|
65
61
|
}
|
|
66
62
|
/** Disconnect state. */
|
|
67
63
|
disconnect(name?: string): void
|
|
@@ -70,18 +66,16 @@ export interface Epos {
|
|
|
70
66
|
/** Create local state (no sync). */
|
|
71
67
|
local<T extends Obj = {}>(state?: T): T
|
|
72
68
|
/** Get the list of all state names. */
|
|
73
|
-
list(filter?: { connected?: boolean }): Promise<
|
|
69
|
+
list(filter?: { connected?: boolean }): Promise<{ name: string | null }[]>
|
|
74
70
|
/** Remove state and all its data. */
|
|
75
71
|
destroy(name?: string): Promise<void>
|
|
76
|
-
/**
|
|
77
|
-
|
|
72
|
+
/** Register models for all states. */
|
|
73
|
+
registerModels(models: Record<string, ModelClass>): void
|
|
78
74
|
symbols: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
readonly parent: unique symbol
|
|
84
|
-
}
|
|
75
|
+
readonly parent: unique symbol
|
|
76
|
+
readonly modelInit: unique symbol
|
|
77
|
+
readonly modelCleanup: unique symbol
|
|
78
|
+
readonly modelVersioner: unique symbol
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
|
|
@@ -97,15 +91,25 @@ export interface Epos {
|
|
|
97
91
|
keys(storageName?: string): Promise<string[]>
|
|
98
92
|
/** Clear storage. Removes all keys and storage itself. */
|
|
99
93
|
clear(storageName?: string): Promise<void>
|
|
100
|
-
/**
|
|
101
|
-
use(
|
|
102
|
-
/** Get list of all
|
|
103
|
-
list(): Promise<
|
|
94
|
+
/** Get storage API for a specific storage. */
|
|
95
|
+
use(storageName: string): Promise<Storage>
|
|
96
|
+
/** Get this list of all storages. */
|
|
97
|
+
list(): Promise<{ name: string | null }[]>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Frame
|
|
101
|
+
frame: {
|
|
102
|
+
/** Open frame in the background. */
|
|
103
|
+
open(name: string, url: string, attributes?: Record<string, unknown>): Promise<void>
|
|
104
|
+
/** Remove background frame by its name. */
|
|
105
|
+
close(name: string): Promise<void>
|
|
106
|
+
/** Get list of all open background frames. */
|
|
107
|
+
list(): Promise<{ name: string; url: string }[]>
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
// Assets
|
|
107
111
|
assets: {
|
|
108
|
-
/** Get asset URL.
|
|
112
|
+
/** Get asset URL. The asset must be loaded first. */
|
|
109
113
|
url(path: string): string
|
|
110
114
|
/** Load asset by path. */
|
|
111
115
|
load(path: string): Promise<Blob>
|
|
@@ -115,38 +119,17 @@ export interface Epos {
|
|
|
115
119
|
unload(path: string): void
|
|
116
120
|
/** Unload all assets from memory. */
|
|
117
121
|
unloadAll(): void
|
|
118
|
-
/** Get list of all available
|
|
119
|
-
list(filter?: { loaded?: boolean }):
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Frames
|
|
123
|
-
frames: {
|
|
124
|
-
/** Create a new frame. */
|
|
125
|
-
create(name: string, url: string, attributes?: Record<string, unknown>): Promise<void>
|
|
126
|
-
/** Remove frame by name. */
|
|
127
|
-
remove(name: string): Promise<void>
|
|
128
|
-
/** Get list of all created frames. */
|
|
129
|
-
list(): Promise<Array<{ name: string; url: string }>>
|
|
122
|
+
/** Get list of all available assets. */
|
|
123
|
+
list(filter?: { loaded?: boolean }): { path: string; loaded: boolean }[]
|
|
130
124
|
}
|
|
131
125
|
|
|
132
126
|
// Env
|
|
133
127
|
env: {
|
|
134
|
-
/** Current tab ID. */
|
|
135
128
|
tabId: number
|
|
136
|
-
|
|
137
|
-
isTab: boolean
|
|
138
|
-
/** True if running in an iframe. */
|
|
139
|
-
isFrame: boolean
|
|
140
|
-
/** True if running in a popup or side panel (`<popup>` or `<sidePanel>`). */
|
|
141
|
-
isShell: boolean
|
|
142
|
-
/** True if running in a popup (`<popup>`). */
|
|
129
|
+
isWeb: boolean
|
|
143
130
|
isPopup: boolean
|
|
144
|
-
/** True if running in a side panel (`<sidePanel>`). */
|
|
145
131
|
isSidePanel: boolean
|
|
146
|
-
/** True if running in the background (`<background>`). */
|
|
147
132
|
isBackground: boolean
|
|
148
|
-
/** True if running in the foreground (not `<background>` and not inside iframe). */
|
|
149
|
-
isForeground: boolean
|
|
150
133
|
}
|
|
151
134
|
|
|
152
135
|
// Libs
|
package/src/vite.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import type { Plugin } from 'vite'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const libs: Record<string, string> = {
|
|
5
5
|
'react': resolve(import.meta.dirname, './libs/libs-react.js'),
|
|
6
6
|
'react/jsx-runtime': resolve(import.meta.dirname, './libs/libs-react-jsx-runtime.js'),
|
|
7
7
|
'react-dom': resolve(import.meta.dirname, './libs/libs-react-dom.js'),
|
|
@@ -14,7 +14,7 @@ export function epos(): Plugin {
|
|
|
14
14
|
return {
|
|
15
15
|
name: 'epos',
|
|
16
16
|
enforce: 'pre',
|
|
17
|
-
resolveId: source =>
|
|
17
|
+
resolveId: source => libs[source] ?? null,
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|