@sweidos/eidos 1.0.4 → 1.0.7
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 +26 -3
- package/dist/eidos.cjs.js +91 -438
- package/dist/eidos.cjs.js.map +1 -1
- package/dist/eidos.es.js +90 -437
- package/dist/eidos.es.js.map +1 -1
- package/dist/index.d.ts +32 -4
- package/package.json +2 -4
package/dist/eidos.es.js
CHANGED
|
@@ -1,398 +1,61 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useSyncExternalStore, useEffect } from "react";
|
|
2
2
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const getState = () => state;
|
|
16
|
-
const getInitialState = () => initialState;
|
|
17
|
-
const subscribe = (listener) => {
|
|
18
|
-
listeners.add(listener);
|
|
19
|
-
return () => listeners.delete(listener);
|
|
20
|
-
};
|
|
21
|
-
const destroy = () => {
|
|
22
|
-
if ((__vite_import_meta_env__$1 ? "production" : void 0) !== "production") {
|
|
23
|
-
console.warn(
|
|
24
|
-
"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
listeners.clear();
|
|
28
|
-
};
|
|
29
|
-
const api = { setState, getState, getInitialState, subscribe, destroy };
|
|
30
|
-
const initialState = state = createState(setState, getState, api);
|
|
31
|
-
return api;
|
|
32
|
-
};
|
|
33
|
-
const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
34
|
-
function getDefaultExportFromCjs(x) {
|
|
35
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
36
|
-
}
|
|
37
|
-
var withSelector = { exports: {} };
|
|
38
|
-
var withSelector_production = {};
|
|
39
|
-
var shim = { exports: {} };
|
|
40
|
-
var useSyncExternalStoreShim_production = {};
|
|
41
|
-
/**
|
|
42
|
-
* @license React
|
|
43
|
-
* use-sync-external-store-shim.production.js
|
|
44
|
-
*
|
|
45
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
46
|
-
*
|
|
47
|
-
* This source code is licensed under the MIT license found in the
|
|
48
|
-
* LICENSE file in the root directory of this source tree.
|
|
49
|
-
*/
|
|
50
|
-
var hasRequiredUseSyncExternalStoreShim_production;
|
|
51
|
-
function requireUseSyncExternalStoreShim_production() {
|
|
52
|
-
if (hasRequiredUseSyncExternalStoreShim_production) return useSyncExternalStoreShim_production;
|
|
53
|
-
hasRequiredUseSyncExternalStoreShim_production = 1;
|
|
54
|
-
var React = require$$0;
|
|
55
|
-
function is(x, y) {
|
|
56
|
-
return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
|
|
57
|
-
}
|
|
58
|
-
var objectIs = "function" === typeof Object.is ? Object.is : is, useState = React.useState, useEffect2 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
|
|
59
|
-
function useSyncExternalStore$2(subscribe, getSnapshot) {
|
|
60
|
-
var value = getSnapshot(), _useState = useState({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
61
|
-
useLayoutEffect(
|
|
62
|
-
function() {
|
|
63
|
-
inst.value = value;
|
|
64
|
-
inst.getSnapshot = getSnapshot;
|
|
65
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
66
|
-
},
|
|
67
|
-
[subscribe, value, getSnapshot]
|
|
68
|
-
);
|
|
69
|
-
useEffect2(
|
|
70
|
-
function() {
|
|
71
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
72
|
-
return subscribe(function() {
|
|
73
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
[subscribe]
|
|
77
|
-
);
|
|
78
|
-
useDebugValue2(value);
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
function checkIfSnapshotChanged(inst) {
|
|
82
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
83
|
-
inst = inst.value;
|
|
84
|
-
try {
|
|
85
|
-
var nextValue = latestGetSnapshot();
|
|
86
|
-
return !objectIs(inst, nextValue);
|
|
87
|
-
} catch (error) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
92
|
-
return getSnapshot();
|
|
93
|
-
}
|
|
94
|
-
var shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
|
95
|
-
useSyncExternalStoreShim_production.useSyncExternalStore = void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim2;
|
|
96
|
-
return useSyncExternalStoreShim_production;
|
|
97
|
-
}
|
|
98
|
-
var useSyncExternalStoreShim_development = {};
|
|
99
|
-
/**
|
|
100
|
-
* @license React
|
|
101
|
-
* use-sync-external-store-shim.development.js
|
|
102
|
-
*
|
|
103
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
104
|
-
*
|
|
105
|
-
* This source code is licensed under the MIT license found in the
|
|
106
|
-
* LICENSE file in the root directory of this source tree.
|
|
107
|
-
*/
|
|
108
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
109
|
-
function requireUseSyncExternalStoreShim_development() {
|
|
110
|
-
if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
|
|
111
|
-
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
112
|
-
"production" !== process.env.NODE_ENV && function() {
|
|
113
|
-
function is(x, y) {
|
|
114
|
-
return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
|
|
115
|
-
}
|
|
116
|
-
function useSyncExternalStore$2(subscribe, getSnapshot) {
|
|
117
|
-
didWarnOld18Alpha || void 0 === React.startTransition || (didWarnOld18Alpha = true, console.error(
|
|
118
|
-
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
119
|
-
));
|
|
120
|
-
var value = getSnapshot();
|
|
121
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
122
|
-
var cachedValue = getSnapshot();
|
|
123
|
-
objectIs(value, cachedValue) || (console.error(
|
|
124
|
-
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
125
|
-
), didWarnUncachedGetSnapshot = true);
|
|
126
|
-
}
|
|
127
|
-
cachedValue = useState({
|
|
128
|
-
inst: { value, getSnapshot }
|
|
129
|
-
});
|
|
130
|
-
var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
|
|
131
|
-
useLayoutEffect(
|
|
132
|
-
function() {
|
|
133
|
-
inst.value = value;
|
|
134
|
-
inst.getSnapshot = getSnapshot;
|
|
135
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
136
|
-
},
|
|
137
|
-
[subscribe, value, getSnapshot]
|
|
138
|
-
);
|
|
139
|
-
useEffect2(
|
|
140
|
-
function() {
|
|
141
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
142
|
-
return subscribe(function() {
|
|
143
|
-
checkIfSnapshotChanged(inst) && forceUpdate({ inst });
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
[subscribe]
|
|
147
|
-
);
|
|
148
|
-
useDebugValue2(value);
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
function checkIfSnapshotChanged(inst) {
|
|
152
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
153
|
-
inst = inst.value;
|
|
154
|
-
try {
|
|
155
|
-
var nextValue = latestGetSnapshot();
|
|
156
|
-
return !objectIs(inst, nextValue);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
162
|
-
return getSnapshot();
|
|
163
|
-
}
|
|
164
|
-
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
165
|
-
var React = require$$0, objectIs = "function" === typeof Object.is ? Object.is : is, useState = React.useState, useEffect2 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
|
166
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim2;
|
|
167
|
-
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
168
|
-
}();
|
|
169
|
-
return useSyncExternalStoreShim_development;
|
|
170
|
-
}
|
|
171
|
-
var hasRequiredShim;
|
|
172
|
-
function requireShim() {
|
|
173
|
-
if (hasRequiredShim) return shim.exports;
|
|
174
|
-
hasRequiredShim = 1;
|
|
175
|
-
if (process.env.NODE_ENV === "production") {
|
|
176
|
-
shim.exports = requireUseSyncExternalStoreShim_production();
|
|
177
|
-
} else {
|
|
178
|
-
shim.exports = requireUseSyncExternalStoreShim_development();
|
|
179
|
-
}
|
|
180
|
-
return shim.exports;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* @license React
|
|
184
|
-
* use-sync-external-store-shim/with-selector.production.js
|
|
185
|
-
*
|
|
186
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
187
|
-
*
|
|
188
|
-
* This source code is licensed under the MIT license found in the
|
|
189
|
-
* LICENSE file in the root directory of this source tree.
|
|
190
|
-
*/
|
|
191
|
-
var hasRequiredWithSelector_production;
|
|
192
|
-
function requireWithSelector_production() {
|
|
193
|
-
if (hasRequiredWithSelector_production) return withSelector_production;
|
|
194
|
-
hasRequiredWithSelector_production = 1;
|
|
195
|
-
var React = require$$0, shim2 = requireShim();
|
|
196
|
-
function is(x, y) {
|
|
197
|
-
return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
|
|
198
|
-
}
|
|
199
|
-
var objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo = React.useMemo, useDebugValue2 = React.useDebugValue;
|
|
200
|
-
withSelector_production.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
201
|
-
var instRef = useRef2(null);
|
|
202
|
-
if (null === instRef.current) {
|
|
203
|
-
var inst = { hasValue: false, value: null };
|
|
204
|
-
instRef.current = inst;
|
|
205
|
-
} else inst = instRef.current;
|
|
206
|
-
instRef = useMemo(
|
|
207
|
-
function() {
|
|
208
|
-
function memoizedSelector(nextSnapshot) {
|
|
209
|
-
if (!hasMemo) {
|
|
210
|
-
hasMemo = true;
|
|
211
|
-
memoizedSnapshot = nextSnapshot;
|
|
212
|
-
nextSnapshot = selector(nextSnapshot);
|
|
213
|
-
if (void 0 !== isEqual && inst.hasValue) {
|
|
214
|
-
var currentSelection = inst.value;
|
|
215
|
-
if (isEqual(currentSelection, nextSnapshot))
|
|
216
|
-
return memoizedSelection = currentSelection;
|
|
217
|
-
}
|
|
218
|
-
return memoizedSelection = nextSnapshot;
|
|
219
|
-
}
|
|
220
|
-
currentSelection = memoizedSelection;
|
|
221
|
-
if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
|
|
222
|
-
var nextSelection = selector(nextSnapshot);
|
|
223
|
-
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
224
|
-
return memoizedSnapshot = nextSnapshot, currentSelection;
|
|
225
|
-
memoizedSnapshot = nextSnapshot;
|
|
226
|
-
return memoizedSelection = nextSelection;
|
|
227
|
-
}
|
|
228
|
-
var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
|
|
229
|
-
return [
|
|
230
|
-
function() {
|
|
231
|
-
return memoizedSelector(getSnapshot());
|
|
232
|
-
},
|
|
233
|
-
null === maybeGetServerSnapshot ? void 0 : function() {
|
|
234
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
235
|
-
}
|
|
236
|
-
];
|
|
237
|
-
},
|
|
238
|
-
[getSnapshot, getServerSnapshot, selector, isEqual]
|
|
239
|
-
);
|
|
240
|
-
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
|
|
241
|
-
useEffect2(
|
|
242
|
-
function() {
|
|
243
|
-
inst.hasValue = true;
|
|
244
|
-
inst.value = value;
|
|
245
|
-
},
|
|
246
|
-
[value]
|
|
247
|
-
);
|
|
248
|
-
useDebugValue2(value);
|
|
249
|
-
return value;
|
|
250
|
-
};
|
|
251
|
-
return withSelector_production;
|
|
252
|
-
}
|
|
253
|
-
var withSelector_development = {};
|
|
254
|
-
/**
|
|
255
|
-
* @license React
|
|
256
|
-
* use-sync-external-store-shim/with-selector.development.js
|
|
257
|
-
*
|
|
258
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
259
|
-
*
|
|
260
|
-
* This source code is licensed under the MIT license found in the
|
|
261
|
-
* LICENSE file in the root directory of this source tree.
|
|
262
|
-
*/
|
|
263
|
-
var hasRequiredWithSelector_development;
|
|
264
|
-
function requireWithSelector_development() {
|
|
265
|
-
if (hasRequiredWithSelector_development) return withSelector_development;
|
|
266
|
-
hasRequiredWithSelector_development = 1;
|
|
267
|
-
"production" !== process.env.NODE_ENV && function() {
|
|
268
|
-
function is(x, y) {
|
|
269
|
-
return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
|
|
270
|
-
}
|
|
271
|
-
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
272
|
-
var React = require$$0, shim2 = requireShim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo = React.useMemo, useDebugValue2 = React.useDebugValue;
|
|
273
|
-
withSelector_development.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
274
|
-
var instRef = useRef2(null);
|
|
275
|
-
if (null === instRef.current) {
|
|
276
|
-
var inst = { hasValue: false, value: null };
|
|
277
|
-
instRef.current = inst;
|
|
278
|
-
} else inst = instRef.current;
|
|
279
|
-
instRef = useMemo(
|
|
280
|
-
function() {
|
|
281
|
-
function memoizedSelector(nextSnapshot) {
|
|
282
|
-
if (!hasMemo) {
|
|
283
|
-
hasMemo = true;
|
|
284
|
-
memoizedSnapshot = nextSnapshot;
|
|
285
|
-
nextSnapshot = selector(nextSnapshot);
|
|
286
|
-
if (void 0 !== isEqual && inst.hasValue) {
|
|
287
|
-
var currentSelection = inst.value;
|
|
288
|
-
if (isEqual(currentSelection, nextSnapshot))
|
|
289
|
-
return memoizedSelection = currentSelection;
|
|
290
|
-
}
|
|
291
|
-
return memoizedSelection = nextSnapshot;
|
|
292
|
-
}
|
|
293
|
-
currentSelection = memoizedSelection;
|
|
294
|
-
if (objectIs(memoizedSnapshot, nextSnapshot))
|
|
295
|
-
return currentSelection;
|
|
296
|
-
var nextSelection = selector(nextSnapshot);
|
|
297
|
-
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
298
|
-
return memoizedSnapshot = nextSnapshot, currentSelection;
|
|
299
|
-
memoizedSnapshot = nextSnapshot;
|
|
300
|
-
return memoizedSelection = nextSelection;
|
|
301
|
-
}
|
|
302
|
-
var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
|
|
303
|
-
return [
|
|
304
|
-
function() {
|
|
305
|
-
return memoizedSelector(getSnapshot());
|
|
306
|
-
},
|
|
307
|
-
null === maybeGetServerSnapshot ? void 0 : function() {
|
|
308
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
309
|
-
}
|
|
310
|
-
];
|
|
311
|
-
},
|
|
312
|
-
[getSnapshot, getServerSnapshot, selector, isEqual]
|
|
313
|
-
);
|
|
314
|
-
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
|
|
315
|
-
useEffect2(
|
|
316
|
-
function() {
|
|
317
|
-
inst.hasValue = true;
|
|
318
|
-
inst.value = value;
|
|
319
|
-
},
|
|
320
|
-
[value]
|
|
321
|
-
);
|
|
322
|
-
useDebugValue2(value);
|
|
323
|
-
return value;
|
|
324
|
-
};
|
|
325
|
-
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
326
|
-
}();
|
|
327
|
-
return withSelector_development;
|
|
328
|
-
}
|
|
329
|
-
if (process.env.NODE_ENV === "production") {
|
|
330
|
-
withSelector.exports = requireWithSelector_production();
|
|
331
|
-
} else {
|
|
332
|
-
withSelector.exports = requireWithSelector_development();
|
|
333
|
-
}
|
|
334
|
-
var withSelectorExports = withSelector.exports;
|
|
335
|
-
const useSyncExternalStoreExports = /* @__PURE__ */ getDefaultExportFromCjs(withSelectorExports);
|
|
336
|
-
const __vite_import_meta_env__ = {};
|
|
337
|
-
const { useDebugValue } = require$$0;
|
|
338
|
-
const { useSyncExternalStoreWithSelector } = useSyncExternalStoreExports;
|
|
339
|
-
let didWarnAboutEqualityFn = false;
|
|
340
|
-
const identity = (arg) => arg;
|
|
341
|
-
function useStore(api, selector = identity, equalityFn) {
|
|
342
|
-
if ((__vite_import_meta_env__ ? "production" : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
|
|
343
|
-
console.warn(
|
|
344
|
-
"[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
|
|
345
|
-
);
|
|
346
|
-
didWarnAboutEqualityFn = true;
|
|
347
|
-
}
|
|
348
|
-
const slice = useSyncExternalStoreWithSelector(
|
|
349
|
-
api.subscribe,
|
|
350
|
-
api.getState,
|
|
351
|
-
api.getServerState || api.getInitialState,
|
|
352
|
-
selector,
|
|
353
|
-
equalityFn
|
|
354
|
-
);
|
|
355
|
-
useDebugValue(slice);
|
|
356
|
-
return slice;
|
|
357
|
-
}
|
|
358
|
-
const createImpl = (createState) => {
|
|
359
|
-
if ((__vite_import_meta_env__ ? "production" : void 0) !== "production" && typeof createState !== "function") {
|
|
360
|
-
console.warn(
|
|
361
|
-
"[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
const api = typeof createState === "function" ? createStore(createState) : createState;
|
|
365
|
-
const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
|
|
366
|
-
Object.assign(useBoundStore, api);
|
|
367
|
-
return useBoundStore;
|
|
368
|
-
};
|
|
369
|
-
const create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
370
|
-
const useEidosStore = create((set) => ({
|
|
3
|
+
let _state;
|
|
4
|
+
const _listeners = /* @__PURE__ */ new Set();
|
|
5
|
+
function _notify() {
|
|
6
|
+
_listeners.forEach((fn) => fn());
|
|
7
|
+
}
|
|
8
|
+
function _set(updater) {
|
|
9
|
+
_state = { ..._state, ...updater(_state) };
|
|
10
|
+
_notify();
|
|
11
|
+
}
|
|
12
|
+
_state = {
|
|
371
13
|
isOnline: typeof navigator !== "undefined" ? navigator.onLine : true,
|
|
372
14
|
swStatus: "idle",
|
|
373
15
|
swError: void 0,
|
|
374
16
|
resources: {},
|
|
375
17
|
queue: [],
|
|
376
|
-
setOnline: (isOnline) =>
|
|
377
|
-
setSwStatus: (swStatus, swError) =>
|
|
378
|
-
registerResource: (url, entry) =>
|
|
379
|
-
updateResource: (url, update) =>
|
|
18
|
+
setOnline: (isOnline) => _set(() => ({ isOnline })),
|
|
19
|
+
setSwStatus: (swStatus, swError) => _set(() => ({ swStatus, swError })),
|
|
20
|
+
registerResource: (url, entry) => _set((s) => ({ resources: { ...s.resources, [url]: entry } })),
|
|
21
|
+
updateResource: (url, update) => _set((s) => ({
|
|
380
22
|
resources: {
|
|
381
23
|
...s.resources,
|
|
382
24
|
[url]: s.resources[url] ? { ...s.resources[url], ...update } : s.resources[url]
|
|
383
25
|
}
|
|
384
26
|
})),
|
|
385
|
-
unregisterResource: (url) =>
|
|
27
|
+
unregisterResource: (url) => _set((s) => {
|
|
386
28
|
const { [url]: _removed, ...rest } = s.resources;
|
|
387
29
|
return { resources: rest };
|
|
388
30
|
}),
|
|
389
|
-
addQueueItem: (item) =>
|
|
390
|
-
updateQueueItem: (id, update) =>
|
|
31
|
+
addQueueItem: (item) => _set((s) => ({ queue: [...s.queue, item] })),
|
|
32
|
+
updateQueueItem: (id, update) => _set((s) => ({
|
|
391
33
|
queue: s.queue.map((item) => item.id === id ? { ...item, ...update } : item)
|
|
392
34
|
})),
|
|
393
|
-
removeQueueItem: (id) =>
|
|
394
|
-
hydrateQueue: (items) =>
|
|
395
|
-
}
|
|
35
|
+
removeQueueItem: (id) => _set((s) => ({ queue: s.queue.filter((item) => item.id !== id) })),
|
|
36
|
+
hydrateQueue: (items) => _set(() => ({ queue: items }))
|
|
37
|
+
};
|
|
38
|
+
function _getState() {
|
|
39
|
+
return _state;
|
|
40
|
+
}
|
|
41
|
+
function _subscribe(listener) {
|
|
42
|
+
_listeners.add(listener);
|
|
43
|
+
return () => {
|
|
44
|
+
_listeners.delete(listener);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function _useStore(selector) {
|
|
48
|
+
const fn = selector ?? ((s) => s);
|
|
49
|
+
return useSyncExternalStore(_subscribe, () => fn(_getState()));
|
|
50
|
+
}
|
|
51
|
+
_useStore.getState = _getState;
|
|
52
|
+
_useStore.subscribe = _subscribe;
|
|
53
|
+
_useStore.setState = (partial) => {
|
|
54
|
+
const update = typeof partial === "function" ? partial(_state) : partial;
|
|
55
|
+
_state = { ..._state, ...update };
|
|
56
|
+
_notify();
|
|
57
|
+
};
|
|
58
|
+
const useEidosStore = _useStore;
|
|
396
59
|
let _registration = null;
|
|
397
60
|
let _pendingMessages = [];
|
|
398
61
|
async function registerServiceWorker(swPath) {
|
|
@@ -736,12 +399,46 @@ async function idbRemoveFromQueue(id) {
|
|
|
736
399
|
tx.onerror = () => reject(tx.error);
|
|
737
400
|
});
|
|
738
401
|
}
|
|
402
|
+
async function idbGetPendingItems() {
|
|
403
|
+
const db = await openDB();
|
|
404
|
+
return new Promise((resolve, reject) => {
|
|
405
|
+
const tx = db.transaction(QUEUE_STORE, "readonly");
|
|
406
|
+
const index = tx.objectStore(QUEUE_STORE).index("status");
|
|
407
|
+
const results = [];
|
|
408
|
+
let done = 0;
|
|
409
|
+
function finish(err) {
|
|
410
|
+
if (err) {
|
|
411
|
+
reject(err);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (++done === 2) resolve(results);
|
|
415
|
+
}
|
|
416
|
+
const pendingReq = index.openCursor(IDBKeyRange.only("pending"));
|
|
417
|
+
pendingReq.onsuccess = (e) => {
|
|
418
|
+
const cursor = e.target.result;
|
|
419
|
+
if (cursor) {
|
|
420
|
+
results.push(cursor.value);
|
|
421
|
+
cursor.continue();
|
|
422
|
+
} else finish();
|
|
423
|
+
};
|
|
424
|
+
pendingReq.onerror = () => finish(pendingReq.error);
|
|
425
|
+
const failedReq = index.openCursor(IDBKeyRange.only("failed"));
|
|
426
|
+
failedReq.onsuccess = (e) => {
|
|
427
|
+
const cursor = e.target.result;
|
|
428
|
+
if (cursor) {
|
|
429
|
+
results.push(cursor.value);
|
|
430
|
+
cursor.continue();
|
|
431
|
+
} else finish();
|
|
432
|
+
};
|
|
433
|
+
failedReq.onerror = () => finish(failedReq.error);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
739
436
|
const _actionRegistry = /* @__PURE__ */ new Map();
|
|
740
437
|
function uid() {
|
|
741
438
|
return crypto.randomUUID();
|
|
742
439
|
}
|
|
743
440
|
function action(fn, config) {
|
|
744
|
-
const actionId = config.name
|
|
441
|
+
const actionId = config.name || fn.name || uid();
|
|
745
442
|
_actionRegistry.set(actionId, fn);
|
|
746
443
|
const wrapped = async (...args) => {
|
|
747
444
|
const { isOnline } = useEidosStore.getState();
|
|
@@ -797,10 +494,10 @@ async function replayQueue() {
|
|
|
797
494
|
}
|
|
798
495
|
}
|
|
799
496
|
async function _doReplayQueue(store) {
|
|
800
|
-
const
|
|
497
|
+
const candidates = await idbGetPendingItems();
|
|
801
498
|
const now = Date.now();
|
|
802
|
-
const pending =
|
|
803
|
-
(item) =>
|
|
499
|
+
const pending = candidates.filter(
|
|
500
|
+
(item) => !item.nextRetryAt || item.nextRetryAt <= now
|
|
804
501
|
);
|
|
805
502
|
await Promise.allSettled(
|
|
806
503
|
pending.map(async (item) => {
|
|
@@ -858,9 +555,10 @@ async function initEidos(config = {}) {
|
|
|
858
555
|
}
|
|
859
556
|
if (autoReplay) {
|
|
860
557
|
let prevIsOnline = useEidosStore.getState().isOnline;
|
|
861
|
-
useEidosStore.subscribe((
|
|
862
|
-
const
|
|
863
|
-
|
|
558
|
+
useEidosStore.subscribe(() => {
|
|
559
|
+
const { isOnline } = useEidosStore.getState();
|
|
560
|
+
const justCameOnline = isOnline && !prevIsOnline;
|
|
561
|
+
prevIsOnline = isOnline;
|
|
864
562
|
if (justCameOnline) {
|
|
865
563
|
setTimeout(replayQueue, 600);
|
|
866
564
|
}
|
|
@@ -878,50 +576,6 @@ function EidosProvider({ children, swPath, autoReplay }) {
|
|
|
878
576
|
}, []);
|
|
879
577
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
880
578
|
}
|
|
881
|
-
function shallow(objA, objB) {
|
|
882
|
-
if (Object.is(objA, objB)) {
|
|
883
|
-
return true;
|
|
884
|
-
}
|
|
885
|
-
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
|
886
|
-
return false;
|
|
887
|
-
}
|
|
888
|
-
if (objA instanceof Map && objB instanceof Map) {
|
|
889
|
-
if (objA.size !== objB.size) return false;
|
|
890
|
-
for (const [key, value] of objA) {
|
|
891
|
-
if (!Object.is(value, objB.get(key))) {
|
|
892
|
-
return false;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
return true;
|
|
896
|
-
}
|
|
897
|
-
if (objA instanceof Set && objB instanceof Set) {
|
|
898
|
-
if (objA.size !== objB.size) return false;
|
|
899
|
-
for (const value of objA) {
|
|
900
|
-
if (!objB.has(value)) {
|
|
901
|
-
return false;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
return true;
|
|
905
|
-
}
|
|
906
|
-
const keysA = Object.keys(objA);
|
|
907
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
908
|
-
return false;
|
|
909
|
-
}
|
|
910
|
-
for (const keyA of keysA) {
|
|
911
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
|
|
912
|
-
return false;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return true;
|
|
916
|
-
}
|
|
917
|
-
const { useRef } = require$$0;
|
|
918
|
-
function useShallow(selector) {
|
|
919
|
-
const prev = useRef();
|
|
920
|
-
return (state) => {
|
|
921
|
-
const next = selector(state);
|
|
922
|
-
return shallow(prev.current, next) ? prev.current : prev.current = next;
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
579
|
function useEidos() {
|
|
926
580
|
return useEidosStore();
|
|
927
581
|
}
|
|
@@ -932,16 +586,15 @@ function useEidosQueue() {
|
|
|
932
586
|
return useEidosStore((s) => s.queue);
|
|
933
587
|
}
|
|
934
588
|
function useEidosStatus() {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
swError: s.swError
|
|
940
|
-
}))
|
|
941
|
-
);
|
|
589
|
+
const isOnline = useEidosStore((s) => s.isOnline);
|
|
590
|
+
const swStatus = useEidosStore((s) => s.swStatus);
|
|
591
|
+
const swError = useEidosStore((s) => s.swError);
|
|
592
|
+
return { isOnline, swStatus, swError };
|
|
942
593
|
}
|
|
594
|
+
const VERSION = "1.0.7";
|
|
943
595
|
export {
|
|
944
596
|
EidosProvider,
|
|
597
|
+
VERSION,
|
|
945
598
|
action,
|
|
946
599
|
initEidos,
|
|
947
600
|
replayQueue,
|