@legendapp/state 3.0.0-alpha.1 → 3.0.0-alpha.3
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/.DS_Store +0 -0
- package/CHANGELOG.md +1 -831
- package/LICENSE +1 -21
- package/README.md +1 -141
- package/as/arrayAsRecord.d.mts +5 -0
- package/as/arrayAsRecord.d.ts +5 -0
- package/as/arrayAsRecord.js +28 -0
- package/as/arrayAsRecord.mjs +26 -0
- package/as/arrayAsSet.d.mts +5 -0
- package/as/arrayAsSet.d.ts +5 -0
- package/as/arrayAsSet.js +13 -0
- package/as/arrayAsSet.mjs +11 -0
- package/as/arrayAsString.d.mts +5 -0
- package/as/arrayAsString.d.ts +5 -0
- package/as/arrayAsString.js +13 -0
- package/as/arrayAsString.mjs +11 -0
- package/as/numberAsString.d.mts +5 -0
- package/as/numberAsString.d.ts +5 -0
- package/as/numberAsString.js +13 -0
- package/as/numberAsString.mjs +11 -0
- package/as/recordAsArray.d.mts +5 -0
- package/as/recordAsArray.d.ts +5 -0
- package/as/recordAsArray.js +25 -0
- package/as/recordAsArray.mjs +23 -0
- package/as/recordAsString.d.mts +5 -0
- package/as/recordAsString.d.ts +5 -0
- package/as/recordAsString.js +13 -0
- package/as/recordAsString.mjs +11 -0
- package/as/setAsArray.d.mts +5 -0
- package/as/setAsArray.d.ts +5 -0
- package/as/setAsArray.js +13 -0
- package/as/setAsArray.mjs +11 -0
- package/as/setAsString.d.mts +5 -0
- package/as/setAsString.d.ts +5 -0
- package/as/setAsString.js +13 -0
- package/as/setAsString.mjs +11 -0
- package/as/stringAsArray.d.mts +5 -0
- package/as/stringAsArray.d.ts +5 -0
- package/as/stringAsArray.js +13 -0
- package/as/stringAsArray.mjs +11 -0
- package/as/stringAsNumber.d.mts +5 -0
- package/as/stringAsNumber.d.ts +5 -0
- package/as/stringAsNumber.js +16 -0
- package/as/stringAsNumber.mjs +14 -0
- package/as/stringAsRecord.d.mts +5 -0
- package/as/stringAsRecord.d.ts +5 -0
- package/as/stringAsRecord.js +15 -0
- package/as/stringAsRecord.mjs +13 -0
- package/as/stringAsSet.d.mts +5 -0
- package/as/stringAsSet.d.ts +5 -0
- package/as/stringAsSet.js +13 -0
- package/as/stringAsSet.mjs +11 -0
- package/babel.d.mts +21 -0
- package/babel.d.ts +21 -2
- package/babel.js +57 -53
- package/babel.mjs +65 -0
- package/config/enable$GetSet.js +13 -14
- package/config/enable$GetSet.mjs +13 -14
- package/config/enableReactComponents.d.mts +9 -0
- package/config/enableReactComponents.d.ts +4 -2
- package/config/enableReactComponents.js +13 -10
- package/config/enableReactComponents.mjs +13 -10
- package/config/enableReactNativeComponents.d.mts +22 -0
- package/config/enableReactNativeComponents.d.ts +6 -4
- package/config/enableReactNativeComponents.js +43 -47
- package/config/enableReactNativeComponents.mjs +43 -47
- package/config/enableReactTracking.d.mts +7 -0
- package/config/enableReactTracking.d.ts +3 -2
- package/config/enableReactTracking.js +33 -38
- package/config/enableReactTracking.mjs +33 -38
- package/config/enableReactUse.d.mts +10 -0
- package/config/enableReactUse.d.ts +4 -1
- package/config/enableReactUse.js +15 -14
- package/config/enableReactUse.mjs +15 -14
- package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
- package/config/enable_GetSet.d.ts +10 -0
- package/config/enable_PeekAssign.d.mts +10 -0
- package/config/enable_PeekAssign.d.ts +4 -2
- package/config/enable_PeekAssign.js +13 -14
- package/config/enable_PeekAssign.mjs +13 -14
- package/helpers/pageHash.d.mts +9 -0
- package/helpers/pageHash.d.ts +2 -0
- package/helpers/pageHash.js +25 -30
- package/helpers/pageHash.mjs +25 -30
- package/helpers/pageHashParams.d.mts +9 -0
- package/helpers/pageHashParams.d.ts +2 -0
- package/helpers/pageHashParams.js +34 -37
- package/helpers/pageHashParams.mjs +34 -37
- package/helpers/time.d.mts +6 -0
- package/helpers/time.d.ts +6 -3
- package/helpers/time.js +17 -17
- package/helpers/time.mjs +17 -17
- package/helpers/trackHistory.d.mts +6 -0
- package/helpers/trackHistory.d.ts +4 -2
- package/helpers/trackHistory.js +13 -16
- package/helpers/trackHistory.mjs +13 -16
- package/helpers/undoRedo.d.mts +37 -0
- package/helpers/undoRedo.d.ts +5 -3
- package/helpers/undoRedo.js +59 -94
- package/helpers/undoRedo.mjs +59 -94
- package/index.d.mts +404 -0
- package/index.d.ts +371 -28
- package/index.js +2015 -2166
- package/index.mjs +2015 -2166
- package/package.json +254 -195
- package/persist-plugins/async-storage.d.mts +18 -0
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +79 -86
- package/persist-plugins/async-storage.mjs +79 -86
- package/persist-plugins/indexeddb.d.mts +29 -0
- package/persist-plugins/indexeddb.d.ts +6 -3
- package/persist-plugins/indexeddb.js +331 -352
- package/persist-plugins/indexeddb.mjs +331 -352
- package/persist-plugins/local-storage.d.mts +23 -0
- package/persist-plugins/local-storage.d.ts +8 -5
- package/persist-plugins/local-storage.js +74 -76
- package/persist-plugins/local-storage.mjs +74 -76
- package/persist-plugins/mmkv.d.mts +18 -0
- package/persist-plugins/mmkv.d.ts +6 -3
- package/persist-plugins/mmkv.js +82 -86
- package/persist-plugins/mmkv.mjs +82 -86
- package/react-hooks/createObservableHook.d.mts +5 -0
- package/react-hooks/createObservableHook.d.ts +4 -1
- package/react-hooks/createObservableHook.js +29 -30
- package/react-hooks/createObservableHook.mjs +25 -30
- package/react-hooks/useHover.d.mts +5 -0
- package/react-hooks/useHover.d.ts +5 -3
- package/react-hooks/useHover.js +29 -29
- package/react-hooks/useHover.mjs +29 -29
- package/react-hooks/useMeasure.d.mts +9 -0
- package/react-hooks/useMeasure.d.ts +5 -2
- package/react-hooks/useMeasure.js +30 -32
- package/react-hooks/useMeasure.mjs +30 -32
- package/react-hooks/useObservableNextRouter.d.mts +35 -0
- package/react-hooks/useObservableNextRouter.d.ts +9 -7
- package/react-hooks/useObservableNextRouter.js +64 -77
- package/react-hooks/useObservableNextRouter.mjs +60 -77
- package/react.d.mts +157 -0
- package/react.d.ts +157 -21
- package/react.js +458 -749
- package/react.mjs +457 -752
- package/sync-plugins/crud.d.mts +54 -0
- package/sync-plugins/crud.d.ts +12 -10
- package/sync-plugins/crud.js +253 -270
- package/sync-plugins/crud.mjs +253 -270
- package/sync-plugins/fetch.d.mts +21 -0
- package/sync-plugins/fetch.d.ts +7 -4
- package/sync-plugins/fetch.js +50 -37
- package/sync-plugins/fetch.mjs +50 -37
- package/sync-plugins/keel.d.mts +108 -0
- package/sync-plugins/keel.d.ts +17 -15
- package/sync-plugins/keel.js +229 -462
- package/sync-plugins/keel.mjs +227 -464
- package/sync-plugins/supabase.d.mts +39 -0
- package/sync-plugins/supabase.d.ts +16 -14
- package/sync-plugins/supabase.js +128 -128
- package/sync-plugins/supabase.mjs +128 -128
- package/sync-plugins/tanstack-query.d.mts +14 -0
- package/sync-plugins/tanstack-query.d.ts +7 -4
- package/sync-plugins/tanstack-query.js +51 -57
- package/sync-plugins/tanstack-query.mjs +51 -57
- package/sync-plugins/tanstack-react-query.d.mts +8 -0
- package/sync-plugins/tanstack-react-query.d.ts +6 -1
- package/sync-plugins/tanstack-react-query.js +2 -2
- package/sync-plugins/tanstack-react-query.mjs +2 -2
- package/sync.d.mts +351 -0
- package/sync.d.ts +349 -9
- package/sync.js +910 -964
- package/sync.mjs +920 -974
- package/trace.d.mts +9 -0
- package/trace.d.ts +9 -4
- package/trace.js +72 -62
- package/trace.mjs +72 -62
- package/types/babel.d.ts +1 -12
- package/babel.js.map +0 -1
- package/config/enable$GetSet.js.map +0 -1
- package/config/enable$GetSet.mjs.map +0 -1
- package/config/enableReactComponents.js.map +0 -1
- package/config/enableReactComponents.mjs.map +0 -1
- package/config/enableReactNativeComponents.js.map +0 -1
- package/config/enableReactNativeComponents.mjs.map +0 -1
- package/config/enableReactTracking.js.map +0 -1
- package/config/enableReactTracking.mjs.map +0 -1
- package/config/enableReactUse.js.map +0 -1
- package/config/enableReactUse.mjs.map +0 -1
- package/config/enable_PeekAssign.js.map +0 -1
- package/config/enable_PeekAssign.mjs.map +0 -1
- package/helpers/pageHash.js.map +0 -1
- package/helpers/pageHash.mjs.map +0 -1
- package/helpers/pageHashParams.js.map +0 -1
- package/helpers/pageHashParams.mjs.map +0 -1
- package/helpers/time.js.map +0 -1
- package/helpers/time.mjs.map +0 -1
- package/helpers/trackHistory.js.map +0 -1
- package/helpers/trackHistory.mjs.map +0 -1
- package/helpers/undoRedo.js.map +0 -1
- package/helpers/undoRedo.mjs.map +0 -1
- package/history.d.ts +0 -1
- package/history.js +0 -24
- package/history.js.map +0 -1
- package/history.mjs +0 -22
- package/history.mjs.map +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/persist-plugins/async-storage.js.map +0 -1
- package/persist-plugins/async-storage.mjs.map +0 -1
- package/persist-plugins/indexeddb.js.map +0 -1
- package/persist-plugins/indexeddb.mjs.map +0 -1
- package/persist-plugins/local-storage.js.map +0 -1
- package/persist-plugins/local-storage.mjs.map +0 -1
- package/persist-plugins/mmkv.js.map +0 -1
- package/persist-plugins/mmkv.mjs.map +0 -1
- package/react-hooks/createObservableHook.js.map +0 -1
- package/react-hooks/createObservableHook.mjs.map +0 -1
- package/react-hooks/useHover.js.map +0 -1
- package/react-hooks/useHover.mjs.map +0 -1
- package/react-hooks/useMeasure.js.map +0 -1
- package/react-hooks/useMeasure.mjs.map +0 -1
- package/react-hooks/useObservableNextRouter.js.map +0 -1
- package/react-hooks/useObservableNextRouter.mjs.map +0 -1
- package/react.js.map +0 -1
- package/react.mjs.map +0 -1
- package/src/ObservableObject.ts +0 -1350
- package/src/ObservablePrimitive.ts +0 -62
- package/src/babel/index.ts +0 -83
- package/src/batching.ts +0 -357
- package/src/computed.ts +0 -18
- package/src/config/enable$GetSet.ts +0 -30
- package/src/config/enableReactComponents.ts +0 -26
- package/src/config/enableReactNativeComponents.ts +0 -102
- package/src/config/enableReactTracking.ts +0 -62
- package/src/config/enableReactUse.ts +0 -32
- package/src/config/enable_PeekAssign.ts +0 -31
- package/src/config.ts +0 -47
- package/src/createObservable.ts +0 -47
- package/src/event.ts +0 -26
- package/src/globals.ts +0 -235
- package/src/helpers/pageHash.ts +0 -41
- package/src/helpers/pageHashParams.ts +0 -55
- package/src/helpers/time.ts +0 -30
- package/src/helpers/trackHistory.ts +0 -29
- package/src/helpers/undoRedo.ts +0 -111
- package/src/helpers.ts +0 -231
- package/src/is.ts +0 -63
- package/src/linked.ts +0 -17
- package/src/observable.ts +0 -32
- package/src/observableInterfaces.ts +0 -151
- package/src/observableTypes.ts +0 -232
- package/src/observe.ts +0 -89
- package/src/old-plugins/firebase.ts +0 -1053
- package/src/onChange.ts +0 -146
- package/src/persist/configureObservablePersistence.ts +0 -7
- package/src/persist/fieldTransformer.ts +0 -149
- package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
- package/src/persist/persistObservable.ts +0 -1034
- package/src/persist-plugins/async-storage.ts +0 -99
- package/src/persist-plugins/indexeddb.ts +0 -439
- package/src/persist-plugins/local-storage.ts +0 -86
- package/src/persist-plugins/mmkv.ts +0 -91
- package/src/proxy.ts +0 -28
- package/src/react/Computed.tsx +0 -8
- package/src/react/For.tsx +0 -116
- package/src/react/Memo.tsx +0 -4
- package/src/react/Reactive.tsx +0 -53
- package/src/react/Show.tsx +0 -33
- package/src/react/Switch.tsx +0 -43
- package/src/react/react-globals.ts +0 -3
- package/src/react/reactInterfaces.ts +0 -32
- package/src/react/reactive-observer.tsx +0 -210
- package/src/react/useComputed.ts +0 -36
- package/src/react/useEffectOnce.ts +0 -41
- package/src/react/useIsMounted.ts +0 -16
- package/src/react/useMount.ts +0 -15
- package/src/react/useObservable.ts +0 -24
- package/src/react/useObservableReducer.ts +0 -52
- package/src/react/useObservableState.ts +0 -30
- package/src/react/useObserve.ts +0 -54
- package/src/react/useObserveEffect.ts +0 -40
- package/src/react/usePauseProvider.tsx +0 -16
- package/src/react/useSelector.ts +0 -167
- package/src/react/useUnmount.ts +0 -8
- package/src/react/useWhen.ts +0 -9
- package/src/react-hooks/createObservableHook.ts +0 -53
- package/src/react-hooks/useHover.ts +0 -40
- package/src/react-hooks/useMeasure.ts +0 -48
- package/src/react-hooks/useObservableNextRouter.ts +0 -137
- package/src/retry.ts +0 -71
- package/src/setupTracking.ts +0 -26
- package/src/sync/activateSyncedNode.ts +0 -128
- package/src/sync/configureObservableSync.ts +0 -7
- package/src/sync/persistTypes.ts +0 -216
- package/src/sync/syncHelpers.ts +0 -180
- package/src/sync/syncObservable.ts +0 -1056
- package/src/sync/syncObservableAdapter.ts +0 -31
- package/src/sync/syncTypes.ts +0 -189
- package/src/sync/synced.ts +0 -21
- package/src/sync-plugins/crud.ts +0 -412
- package/src/sync-plugins/fetch.ts +0 -80
- package/src/sync-plugins/keel.ts +0 -495
- package/src/sync-plugins/supabase.ts +0 -249
- package/src/sync-plugins/tanstack-query.ts +0 -113
- package/src/sync-plugins/tanstack-react-query.ts +0 -12
- package/src/trace/traceHelpers.ts +0 -11
- package/src/trace/useTraceListeners.ts +0 -34
- package/src/trace/useTraceUpdates.ts +0 -24
- package/src/trace/useVerifyNotTracking.ts +0 -33
- package/src/trace/useVerifyOneRender.ts +0 -10
- package/src/trackSelector.ts +0 -52
- package/src/tracking.ts +0 -43
- package/src/types/babel.d.ts +0 -12
- package/src/when.ts +0 -75
- package/sync-plugins/crud.js.map +0 -1
- package/sync-plugins/crud.mjs.map +0 -1
- package/sync-plugins/fetch.js.map +0 -1
- package/sync-plugins/fetch.mjs.map +0 -1
- package/sync-plugins/keel.js.map +0 -1
- package/sync-plugins/keel.mjs.map +0 -1
- package/sync-plugins/supabase.js.map +0 -1
- package/sync-plugins/supabase.mjs.map +0 -1
- package/sync-plugins/tanstack-query.js.map +0 -1
- package/sync-plugins/tanstack-query.mjs.map +0 -1
- package/sync-plugins/tanstack-react-query.js.map +0 -1
- package/sync-plugins/tanstack-react-query.mjs.map +0 -1
- package/sync.js.map +0 -1
- package/sync.mjs.map +0 -1
- package/trace.js.map +0 -1
- package/trace.mjs.map +0 -1
package/helpers/pageHash.mjs
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
import { observable } from '@legendapp/state';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/helpers/pageHash.ts
|
|
4
|
+
var _options = { setter: "hash" };
|
|
4
5
|
function configurePageHash(options) {
|
|
5
|
-
|
|
6
|
+
_options = options;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
var hasWindow = typeof window !== "undefined";
|
|
9
|
+
var pageHash = observable(hasWindow ? window.location.hash.slice(1) : "");
|
|
9
10
|
if (hasWindow) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
pageHash.set(window.location.hash.slice(1));
|
|
31
|
-
isSetting = false;
|
|
32
|
-
};
|
|
33
|
-
// Subscribe to window hashChange event
|
|
34
|
-
window.addEventListener('hashchange', cb);
|
|
11
|
+
let isSetting = false;
|
|
12
|
+
pageHash.onChange(({ value }) => {
|
|
13
|
+
if (!isSetting) {
|
|
14
|
+
const hash = "#" + value;
|
|
15
|
+
const setter = (_options == null ? void 0 : _options.setter) || "hash";
|
|
16
|
+
if (setter === "pushState") {
|
|
17
|
+
history.pushState(null, null, hash);
|
|
18
|
+
} else if (setter === "replaceState") {
|
|
19
|
+
history.replaceState(null, null, hash);
|
|
20
|
+
} else {
|
|
21
|
+
location.hash = hash;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const cb = () => {
|
|
26
|
+
isSetting = true;
|
|
27
|
+
pageHash.set(window.location.hash.slice(1));
|
|
28
|
+
isSetting = false;
|
|
29
|
+
};
|
|
30
|
+
window.addEventListener("hashchange", cb);
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
export { configurePageHash, pageHash };
|
|
38
|
-
//# sourceMappingURL=pageHash.mjs.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Observable } from '@legendapp/state';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
setter: 'pushState' | 'replaceState' | 'hash';
|
|
5
|
+
}
|
|
6
|
+
declare function configurePageHashParams(options: Options): void;
|
|
7
|
+
declare const pageHashParams: Observable<Record<string, string>>;
|
|
8
|
+
|
|
9
|
+
export { configurePageHashParams, pageHashParams };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Observable } from '@legendapp/state';
|
|
2
|
+
|
|
2
3
|
interface Options {
|
|
3
4
|
setter: 'pushState' | 'replaceState' | 'hash';
|
|
4
5
|
}
|
|
5
6
|
declare function configurePageHashParams(options: Options): void;
|
|
6
7
|
declare const pageHashParams: Observable<Record<string, string>>;
|
|
8
|
+
|
|
7
9
|
export { configurePageHashParams, pageHashParams };
|
|
@@ -2,51 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
var state = require('@legendapp/state');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/helpers/pageHashParams.ts
|
|
6
|
+
var _options = { setter: "hash" };
|
|
6
7
|
function configurePageHashParams(options) {
|
|
7
|
-
|
|
8
|
+
_options = options;
|
|
8
9
|
}
|
|
9
10
|
function toParams(str) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const ret = {};
|
|
12
|
+
const searchParams = new URLSearchParams(str);
|
|
13
|
+
for (const [key, value] of searchParams) {
|
|
14
|
+
ret[key] = value;
|
|
15
|
+
}
|
|
16
|
+
return ret;
|
|
16
17
|
}
|
|
17
18
|
function toString(params) {
|
|
18
|
-
|
|
19
|
+
return new URLSearchParams(params).toString().replace(/=$/, "");
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
var hasWindow = typeof window !== "undefined";
|
|
22
|
+
var pageHashParams = state.observable(
|
|
23
|
+
hasWindow ? toParams(window.location.hash.slice(1)) : {}
|
|
24
|
+
);
|
|
22
25
|
if (hasWindow) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
pageHashParams.set(toParams(window.location.hash.slice(1)));
|
|
44
|
-
isSetting = false;
|
|
45
|
-
};
|
|
46
|
-
// Subscribe to window hashChange event
|
|
47
|
-
window.addEventListener('hashchange', cb);
|
|
26
|
+
let isSetting = false;
|
|
27
|
+
pageHashParams.onChange(({ value }) => {
|
|
28
|
+
if (!isSetting) {
|
|
29
|
+
const hash = "#" + toString(value);
|
|
30
|
+
const setter = (_options == null ? void 0 : _options.setter) || "hash";
|
|
31
|
+
if (setter === "pushState") {
|
|
32
|
+
history.pushState(null, null, hash);
|
|
33
|
+
} else if (setter === "replaceState") {
|
|
34
|
+
history.replaceState(null, null, hash);
|
|
35
|
+
} else {
|
|
36
|
+
location.hash = hash;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const cb = () => {
|
|
41
|
+
isSetting = true;
|
|
42
|
+
pageHashParams.set(toParams(window.location.hash.slice(1)));
|
|
43
|
+
isSetting = false;
|
|
44
|
+
};
|
|
45
|
+
window.addEventListener("hashchange", cb);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
exports.configurePageHashParams = configurePageHashParams;
|
|
51
49
|
exports.pageHashParams = pageHashParams;
|
|
52
|
-
//# sourceMappingURL=pageHashParams.js.map
|
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
import { observable } from '@legendapp/state';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/helpers/pageHashParams.ts
|
|
4
|
+
var _options = { setter: "hash" };
|
|
4
5
|
function configurePageHashParams(options) {
|
|
5
|
-
|
|
6
|
+
_options = options;
|
|
6
7
|
}
|
|
7
8
|
function toParams(str) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const ret = {};
|
|
10
|
+
const searchParams = new URLSearchParams(str);
|
|
11
|
+
for (const [key, value] of searchParams) {
|
|
12
|
+
ret[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return ret;
|
|
14
15
|
}
|
|
15
16
|
function toString(params) {
|
|
16
|
-
|
|
17
|
+
return new URLSearchParams(params).toString().replace(/=$/, "");
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
var hasWindow = typeof window !== "undefined";
|
|
20
|
+
var pageHashParams = observable(
|
|
21
|
+
hasWindow ? toParams(window.location.hash.slice(1)) : {}
|
|
22
|
+
);
|
|
20
23
|
if (hasWindow) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
pageHashParams.set(toParams(window.location.hash.slice(1)));
|
|
42
|
-
isSetting = false;
|
|
43
|
-
};
|
|
44
|
-
// Subscribe to window hashChange event
|
|
45
|
-
window.addEventListener('hashchange', cb);
|
|
24
|
+
let isSetting = false;
|
|
25
|
+
pageHashParams.onChange(({ value }) => {
|
|
26
|
+
if (!isSetting) {
|
|
27
|
+
const hash = "#" + toString(value);
|
|
28
|
+
const setter = (_options == null ? void 0 : _options.setter) || "hash";
|
|
29
|
+
if (setter === "pushState") {
|
|
30
|
+
history.pushState(null, null, hash);
|
|
31
|
+
} else if (setter === "replaceState") {
|
|
32
|
+
history.replaceState(null, null, hash);
|
|
33
|
+
} else {
|
|
34
|
+
location.hash = hash;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const cb = () => {
|
|
39
|
+
isSetting = true;
|
|
40
|
+
pageHashParams.set(toParams(window.location.hash.slice(1)));
|
|
41
|
+
isSetting = false;
|
|
42
|
+
};
|
|
43
|
+
window.addEventListener("hashchange", cb);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
export { configurePageHashParams, pageHashParams };
|
|
49
|
-
//# sourceMappingURL=pageHashParams.mjs.map
|
package/helpers/time.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as _legendapp_state from '@legendapp/state';
|
|
2
|
+
|
|
3
|
+
declare const currentTime: _legendapp_state.ObservablePrimitive<Date>;
|
|
4
|
+
declare const currentDay: _legendapp_state.ObservablePrimitive<Date>;
|
|
5
|
+
|
|
6
|
+
export { currentDay, currentTime };
|
package/helpers/time.js
CHANGED
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
var state = require('@legendapp/state');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/helpers/time.ts
|
|
6
|
+
var MSPerMinute = 6e4;
|
|
6
7
|
function clearTime(date) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
date = new Date(date);
|
|
9
|
+
date.setHours(0, 0, 0, 0);
|
|
10
|
+
return date;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var time = /* @__PURE__ */ new Date();
|
|
13
|
+
var currentTime = state.observable(time);
|
|
14
|
+
var currentDay = state.observable(clearTime(time));
|
|
15
|
+
var timeToSecond = (60 - time.getSeconds() + 1) * 1e3;
|
|
15
16
|
function update() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const now = /* @__PURE__ */ new Date();
|
|
18
|
+
currentTime.set(now);
|
|
19
|
+
if (now.getDate() !== time.getDate()) {
|
|
20
|
+
currentDay.set(clearTime(now));
|
|
21
|
+
}
|
|
22
|
+
time = now;
|
|
22
23
|
}
|
|
23
24
|
setTimeout(() => {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
update();
|
|
26
|
+
setInterval(update, MSPerMinute);
|
|
26
27
|
}, timeToSecond);
|
|
27
28
|
|
|
28
29
|
exports.currentDay = currentDay;
|
|
29
30
|
exports.currentTime = currentTime;
|
|
30
|
-
//# sourceMappingURL=time.js.map
|
package/helpers/time.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { observable } from '@legendapp/state';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/helpers/time.ts
|
|
4
|
+
var MSPerMinute = 6e4;
|
|
4
5
|
function clearTime(date) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
date = new Date(date);
|
|
7
|
+
date.setHours(0, 0, 0, 0);
|
|
8
|
+
return date;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
var time = /* @__PURE__ */ new Date();
|
|
11
|
+
var currentTime = observable(time);
|
|
12
|
+
var currentDay = observable(clearTime(time));
|
|
13
|
+
var timeToSecond = (60 - time.getSeconds() + 1) * 1e3;
|
|
13
14
|
function update() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const now = /* @__PURE__ */ new Date();
|
|
16
|
+
currentTime.set(now);
|
|
17
|
+
if (now.getDate() !== time.getDate()) {
|
|
18
|
+
currentDay.set(clearTime(now));
|
|
19
|
+
}
|
|
20
|
+
time = now;
|
|
20
21
|
}
|
|
21
22
|
setTimeout(() => {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
update();
|
|
24
|
+
setInterval(update, MSPerMinute);
|
|
24
25
|
}, timeToSecond);
|
|
25
26
|
|
|
26
27
|
export { currentDay, currentTime };
|
|
27
|
-
//# sourceMappingURL=time.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ObservableParam } from '@legendapp/state';
|
|
2
|
+
|
|
3
|
+
type TimestampAsString = string;
|
|
4
|
+
declare function trackHistory<T>(value$: ObservableParam<T>, targetObservable?: ObservableParam<Record<TimestampAsString, Partial<T>>>): ObservableParam<Record<TimestampAsString, any>>;
|
|
5
|
+
|
|
6
|
+
export { trackHistory };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ObservableParam } from '@legendapp/state';
|
|
2
|
+
|
|
2
3
|
type TimestampAsString = string;
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
declare function trackHistory<T>(value$: ObservableParam<T>, targetObservable?: ObservableParam<Record<TimestampAsString, Partial<T>>>): ObservableParam<Record<TimestampAsString, any>>;
|
|
5
|
+
|
|
6
|
+
export { trackHistory };
|
package/helpers/trackHistory.js
CHANGED
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var state = require('@legendapp/state');
|
|
4
4
|
|
|
5
|
+
// src/helpers/trackHistory.ts
|
|
5
6
|
function trackHistory(value$, targetObservable) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return history;
|
|
7
|
+
const history = targetObservable != null ? targetObservable : state.observable();
|
|
8
|
+
value$.onChange(({ loading, remote, changes }) => {
|
|
9
|
+
if (!loading && !remote) {
|
|
10
|
+
const time = Date.now().toString();
|
|
11
|
+
for (let i = 0; i < changes.length; i++) {
|
|
12
|
+
const { path, prevAtPath, pathTypes } = changes[i];
|
|
13
|
+
const obj = state.constructObjectWithPath(path, pathTypes, prevAtPath);
|
|
14
|
+
state.mergeIntoObservable(history[time], obj);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return history;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
exports.trackHistory = trackHistory;
|
|
24
|
-
//# sourceMappingURL=trackHistory.js.map
|
package/helpers/trackHistory.mjs
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { observable, constructObjectWithPath, mergeIntoObservable } from '@legendapp/state';
|
|
2
2
|
|
|
3
|
+
// src/helpers/trackHistory.ts
|
|
3
4
|
function trackHistory(value$, targetObservable) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return history;
|
|
5
|
+
const history = targetObservable != null ? targetObservable : observable();
|
|
6
|
+
value$.onChange(({ loading, remote, changes }) => {
|
|
7
|
+
if (!loading && !remote) {
|
|
8
|
+
const time = Date.now().toString();
|
|
9
|
+
for (let i = 0; i < changes.length; i++) {
|
|
10
|
+
const { path, prevAtPath, pathTypes } = changes[i];
|
|
11
|
+
const obj = constructObjectWithPath(path, pathTypes, prevAtPath);
|
|
12
|
+
mergeIntoObservable(history[time], obj);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return history;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export { trackHistory };
|
|
22
|
-
//# sourceMappingURL=trackHistory.mjs.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ObservablePrimitive } from '@legendapp/state';
|
|
2
|
+
|
|
3
|
+
type UndoRedoOptions = {
|
|
4
|
+
limit?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Usage:
|
|
8
|
+
*
|
|
9
|
+
* Use this function to add undo/redo functionality to an observable.
|
|
10
|
+
*
|
|
11
|
+
* You can monitor how many undos or redos are available to enable/disable undo/redo
|
|
12
|
+
* UI elements with undo$ and redo$.
|
|
13
|
+
*
|
|
14
|
+
* If you undo and then make a change, it'll delete any redos and add the change, as expected.
|
|
15
|
+
*
|
|
16
|
+
* If you don't pass in a limit, it will keep all history. This means it can grow indefinitely.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const obs$ = observable({ test: 'hi', test2: 'a' });
|
|
20
|
+
* const { undo, redo, undos$, redos$, getHistory } = undoRedo(obs$, { limit: 40 });
|
|
21
|
+
* obs$.test.set('hello');
|
|
22
|
+
* undo();
|
|
23
|
+
* redo();
|
|
24
|
+
* // observables for # of undos/redos available
|
|
25
|
+
* undos$.get();
|
|
26
|
+
* redos$.get();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function undoRedo<T>(obs$: ObservablePrimitive<T>, options?: UndoRedoOptions): {
|
|
30
|
+
undo(): void;
|
|
31
|
+
redo(): void;
|
|
32
|
+
undos$: ObservablePrimitive<number>;
|
|
33
|
+
redos$: ObservablePrimitive<number>;
|
|
34
|
+
getHistory: () => T[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { undoRedo };
|
package/helpers/undoRedo.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObservablePrimitive } from '@legendapp/state';
|
|
2
|
+
|
|
2
3
|
type UndoRedoOptions = {
|
|
3
4
|
limit?: number;
|
|
4
5
|
};
|
|
@@ -25,11 +26,12 @@ type UndoRedoOptions = {
|
|
|
25
26
|
* redos$.get();
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
declare function undoRedo<T>(obs$: ObservablePrimitive<T>, options?: UndoRedoOptions): {
|
|
29
30
|
undo(): void;
|
|
30
31
|
redo(): void;
|
|
31
32
|
undos$: ObservablePrimitive<number>;
|
|
32
33
|
redos$: ObservablePrimitive<number>;
|
|
33
34
|
getHistory: () => T[];
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
export { undoRedo };
|