@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.
Files changed (327) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +1 -831
  3. package/LICENSE +1 -21
  4. package/README.md +1 -141
  5. package/as/arrayAsRecord.d.mts +5 -0
  6. package/as/arrayAsRecord.d.ts +5 -0
  7. package/as/arrayAsRecord.js +28 -0
  8. package/as/arrayAsRecord.mjs +26 -0
  9. package/as/arrayAsSet.d.mts +5 -0
  10. package/as/arrayAsSet.d.ts +5 -0
  11. package/as/arrayAsSet.js +13 -0
  12. package/as/arrayAsSet.mjs +11 -0
  13. package/as/arrayAsString.d.mts +5 -0
  14. package/as/arrayAsString.d.ts +5 -0
  15. package/as/arrayAsString.js +13 -0
  16. package/as/arrayAsString.mjs +11 -0
  17. package/as/numberAsString.d.mts +5 -0
  18. package/as/numberAsString.d.ts +5 -0
  19. package/as/numberAsString.js +13 -0
  20. package/as/numberAsString.mjs +11 -0
  21. package/as/recordAsArray.d.mts +5 -0
  22. package/as/recordAsArray.d.ts +5 -0
  23. package/as/recordAsArray.js +25 -0
  24. package/as/recordAsArray.mjs +23 -0
  25. package/as/recordAsString.d.mts +5 -0
  26. package/as/recordAsString.d.ts +5 -0
  27. package/as/recordAsString.js +13 -0
  28. package/as/recordAsString.mjs +11 -0
  29. package/as/setAsArray.d.mts +5 -0
  30. package/as/setAsArray.d.ts +5 -0
  31. package/as/setAsArray.js +13 -0
  32. package/as/setAsArray.mjs +11 -0
  33. package/as/setAsString.d.mts +5 -0
  34. package/as/setAsString.d.ts +5 -0
  35. package/as/setAsString.js +13 -0
  36. package/as/setAsString.mjs +11 -0
  37. package/as/stringAsArray.d.mts +5 -0
  38. package/as/stringAsArray.d.ts +5 -0
  39. package/as/stringAsArray.js +13 -0
  40. package/as/stringAsArray.mjs +11 -0
  41. package/as/stringAsNumber.d.mts +5 -0
  42. package/as/stringAsNumber.d.ts +5 -0
  43. package/as/stringAsNumber.js +16 -0
  44. package/as/stringAsNumber.mjs +14 -0
  45. package/as/stringAsRecord.d.mts +5 -0
  46. package/as/stringAsRecord.d.ts +5 -0
  47. package/as/stringAsRecord.js +15 -0
  48. package/as/stringAsRecord.mjs +13 -0
  49. package/as/stringAsSet.d.mts +5 -0
  50. package/as/stringAsSet.d.ts +5 -0
  51. package/as/stringAsSet.js +13 -0
  52. package/as/stringAsSet.mjs +11 -0
  53. package/babel.d.mts +21 -0
  54. package/babel.d.ts +21 -2
  55. package/babel.js +57 -53
  56. package/babel.mjs +65 -0
  57. package/config/enable$GetSet.js +13 -14
  58. package/config/enable$GetSet.mjs +13 -14
  59. package/config/enableReactComponents.d.mts +9 -0
  60. package/config/enableReactComponents.d.ts +4 -2
  61. package/config/enableReactComponents.js +13 -10
  62. package/config/enableReactComponents.mjs +13 -10
  63. package/config/enableReactNativeComponents.d.mts +22 -0
  64. package/config/enableReactNativeComponents.d.ts +6 -4
  65. package/config/enableReactNativeComponents.js +43 -47
  66. package/config/enableReactNativeComponents.mjs +43 -47
  67. package/config/enableReactTracking.d.mts +7 -0
  68. package/config/enableReactTracking.d.ts +3 -2
  69. package/config/enableReactTracking.js +33 -38
  70. package/config/enableReactTracking.mjs +33 -38
  71. package/config/enableReactUse.d.mts +10 -0
  72. package/config/enableReactUse.d.ts +4 -1
  73. package/config/enableReactUse.js +15 -14
  74. package/config/enableReactUse.mjs +15 -14
  75. package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
  76. package/config/enable_GetSet.d.ts +10 -0
  77. package/config/enable_PeekAssign.d.mts +10 -0
  78. package/config/enable_PeekAssign.d.ts +4 -2
  79. package/config/enable_PeekAssign.js +13 -14
  80. package/config/enable_PeekAssign.mjs +13 -14
  81. package/helpers/pageHash.d.mts +9 -0
  82. package/helpers/pageHash.d.ts +2 -0
  83. package/helpers/pageHash.js +25 -30
  84. package/helpers/pageHash.mjs +25 -30
  85. package/helpers/pageHashParams.d.mts +9 -0
  86. package/helpers/pageHashParams.d.ts +2 -0
  87. package/helpers/pageHashParams.js +34 -37
  88. package/helpers/pageHashParams.mjs +34 -37
  89. package/helpers/time.d.mts +6 -0
  90. package/helpers/time.d.ts +6 -3
  91. package/helpers/time.js +17 -17
  92. package/helpers/time.mjs +17 -17
  93. package/helpers/trackHistory.d.mts +6 -0
  94. package/helpers/trackHistory.d.ts +4 -2
  95. package/helpers/trackHistory.js +13 -16
  96. package/helpers/trackHistory.mjs +13 -16
  97. package/helpers/undoRedo.d.mts +37 -0
  98. package/helpers/undoRedo.d.ts +5 -3
  99. package/helpers/undoRedo.js +59 -94
  100. package/helpers/undoRedo.mjs +59 -94
  101. package/index.d.mts +404 -0
  102. package/index.d.ts +371 -28
  103. package/index.js +2015 -2166
  104. package/index.mjs +2015 -2166
  105. package/package.json +254 -195
  106. package/persist-plugins/async-storage.d.mts +18 -0
  107. package/persist-plugins/async-storage.d.ts +6 -3
  108. package/persist-plugins/async-storage.js +79 -86
  109. package/persist-plugins/async-storage.mjs +79 -86
  110. package/persist-plugins/indexeddb.d.mts +29 -0
  111. package/persist-plugins/indexeddb.d.ts +6 -3
  112. package/persist-plugins/indexeddb.js +331 -352
  113. package/persist-plugins/indexeddb.mjs +331 -352
  114. package/persist-plugins/local-storage.d.mts +23 -0
  115. package/persist-plugins/local-storage.d.ts +8 -5
  116. package/persist-plugins/local-storage.js +74 -76
  117. package/persist-plugins/local-storage.mjs +74 -76
  118. package/persist-plugins/mmkv.d.mts +18 -0
  119. package/persist-plugins/mmkv.d.ts +6 -3
  120. package/persist-plugins/mmkv.js +82 -86
  121. package/persist-plugins/mmkv.mjs +82 -86
  122. package/react-hooks/createObservableHook.d.mts +5 -0
  123. package/react-hooks/createObservableHook.d.ts +4 -1
  124. package/react-hooks/createObservableHook.js +29 -30
  125. package/react-hooks/createObservableHook.mjs +25 -30
  126. package/react-hooks/useHover.d.mts +5 -0
  127. package/react-hooks/useHover.d.ts +5 -3
  128. package/react-hooks/useHover.js +29 -29
  129. package/react-hooks/useHover.mjs +29 -29
  130. package/react-hooks/useMeasure.d.mts +9 -0
  131. package/react-hooks/useMeasure.d.ts +5 -2
  132. package/react-hooks/useMeasure.js +30 -32
  133. package/react-hooks/useMeasure.mjs +30 -32
  134. package/react-hooks/useObservableNextRouter.d.mts +35 -0
  135. package/react-hooks/useObservableNextRouter.d.ts +9 -7
  136. package/react-hooks/useObservableNextRouter.js +64 -77
  137. package/react-hooks/useObservableNextRouter.mjs +60 -77
  138. package/react.d.mts +157 -0
  139. package/react.d.ts +157 -21
  140. package/react.js +458 -749
  141. package/react.mjs +457 -752
  142. package/sync-plugins/crud.d.mts +54 -0
  143. package/sync-plugins/crud.d.ts +12 -10
  144. package/sync-plugins/crud.js +253 -270
  145. package/sync-plugins/crud.mjs +253 -270
  146. package/sync-plugins/fetch.d.mts +21 -0
  147. package/sync-plugins/fetch.d.ts +7 -4
  148. package/sync-plugins/fetch.js +50 -37
  149. package/sync-plugins/fetch.mjs +50 -37
  150. package/sync-plugins/keel.d.mts +108 -0
  151. package/sync-plugins/keel.d.ts +17 -15
  152. package/sync-plugins/keel.js +229 -462
  153. package/sync-plugins/keel.mjs +227 -464
  154. package/sync-plugins/supabase.d.mts +39 -0
  155. package/sync-plugins/supabase.d.ts +16 -14
  156. package/sync-plugins/supabase.js +128 -128
  157. package/sync-plugins/supabase.mjs +128 -128
  158. package/sync-plugins/tanstack-query.d.mts +14 -0
  159. package/sync-plugins/tanstack-query.d.ts +7 -4
  160. package/sync-plugins/tanstack-query.js +51 -57
  161. package/sync-plugins/tanstack-query.mjs +51 -57
  162. package/sync-plugins/tanstack-react-query.d.mts +8 -0
  163. package/sync-plugins/tanstack-react-query.d.ts +6 -1
  164. package/sync-plugins/tanstack-react-query.js +2 -2
  165. package/sync-plugins/tanstack-react-query.mjs +2 -2
  166. package/sync.d.mts +351 -0
  167. package/sync.d.ts +349 -9
  168. package/sync.js +910 -964
  169. package/sync.mjs +920 -974
  170. package/trace.d.mts +9 -0
  171. package/trace.d.ts +9 -4
  172. package/trace.js +72 -62
  173. package/trace.mjs +72 -62
  174. package/types/babel.d.ts +1 -12
  175. package/babel.js.map +0 -1
  176. package/config/enable$GetSet.js.map +0 -1
  177. package/config/enable$GetSet.mjs.map +0 -1
  178. package/config/enableReactComponents.js.map +0 -1
  179. package/config/enableReactComponents.mjs.map +0 -1
  180. package/config/enableReactNativeComponents.js.map +0 -1
  181. package/config/enableReactNativeComponents.mjs.map +0 -1
  182. package/config/enableReactTracking.js.map +0 -1
  183. package/config/enableReactTracking.mjs.map +0 -1
  184. package/config/enableReactUse.js.map +0 -1
  185. package/config/enableReactUse.mjs.map +0 -1
  186. package/config/enable_PeekAssign.js.map +0 -1
  187. package/config/enable_PeekAssign.mjs.map +0 -1
  188. package/helpers/pageHash.js.map +0 -1
  189. package/helpers/pageHash.mjs.map +0 -1
  190. package/helpers/pageHashParams.js.map +0 -1
  191. package/helpers/pageHashParams.mjs.map +0 -1
  192. package/helpers/time.js.map +0 -1
  193. package/helpers/time.mjs.map +0 -1
  194. package/helpers/trackHistory.js.map +0 -1
  195. package/helpers/trackHistory.mjs.map +0 -1
  196. package/helpers/undoRedo.js.map +0 -1
  197. package/helpers/undoRedo.mjs.map +0 -1
  198. package/history.d.ts +0 -1
  199. package/history.js +0 -24
  200. package/history.js.map +0 -1
  201. package/history.mjs +0 -22
  202. package/history.mjs.map +0 -1
  203. package/index.js.map +0 -1
  204. package/index.mjs.map +0 -1
  205. package/persist-plugins/async-storage.js.map +0 -1
  206. package/persist-plugins/async-storage.mjs.map +0 -1
  207. package/persist-plugins/indexeddb.js.map +0 -1
  208. package/persist-plugins/indexeddb.mjs.map +0 -1
  209. package/persist-plugins/local-storage.js.map +0 -1
  210. package/persist-plugins/local-storage.mjs.map +0 -1
  211. package/persist-plugins/mmkv.js.map +0 -1
  212. package/persist-plugins/mmkv.mjs.map +0 -1
  213. package/react-hooks/createObservableHook.js.map +0 -1
  214. package/react-hooks/createObservableHook.mjs.map +0 -1
  215. package/react-hooks/useHover.js.map +0 -1
  216. package/react-hooks/useHover.mjs.map +0 -1
  217. package/react-hooks/useMeasure.js.map +0 -1
  218. package/react-hooks/useMeasure.mjs.map +0 -1
  219. package/react-hooks/useObservableNextRouter.js.map +0 -1
  220. package/react-hooks/useObservableNextRouter.mjs.map +0 -1
  221. package/react.js.map +0 -1
  222. package/react.mjs.map +0 -1
  223. package/src/ObservableObject.ts +0 -1350
  224. package/src/ObservablePrimitive.ts +0 -62
  225. package/src/babel/index.ts +0 -83
  226. package/src/batching.ts +0 -357
  227. package/src/computed.ts +0 -18
  228. package/src/config/enable$GetSet.ts +0 -30
  229. package/src/config/enableReactComponents.ts +0 -26
  230. package/src/config/enableReactNativeComponents.ts +0 -102
  231. package/src/config/enableReactTracking.ts +0 -62
  232. package/src/config/enableReactUse.ts +0 -32
  233. package/src/config/enable_PeekAssign.ts +0 -31
  234. package/src/config.ts +0 -47
  235. package/src/createObservable.ts +0 -47
  236. package/src/event.ts +0 -26
  237. package/src/globals.ts +0 -235
  238. package/src/helpers/pageHash.ts +0 -41
  239. package/src/helpers/pageHashParams.ts +0 -55
  240. package/src/helpers/time.ts +0 -30
  241. package/src/helpers/trackHistory.ts +0 -29
  242. package/src/helpers/undoRedo.ts +0 -111
  243. package/src/helpers.ts +0 -231
  244. package/src/is.ts +0 -63
  245. package/src/linked.ts +0 -17
  246. package/src/observable.ts +0 -32
  247. package/src/observableInterfaces.ts +0 -151
  248. package/src/observableTypes.ts +0 -232
  249. package/src/observe.ts +0 -89
  250. package/src/old-plugins/firebase.ts +0 -1053
  251. package/src/onChange.ts +0 -146
  252. package/src/persist/configureObservablePersistence.ts +0 -7
  253. package/src/persist/fieldTransformer.ts +0 -149
  254. package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
  255. package/src/persist/persistObservable.ts +0 -1034
  256. package/src/persist-plugins/async-storage.ts +0 -99
  257. package/src/persist-plugins/indexeddb.ts +0 -439
  258. package/src/persist-plugins/local-storage.ts +0 -86
  259. package/src/persist-plugins/mmkv.ts +0 -91
  260. package/src/proxy.ts +0 -28
  261. package/src/react/Computed.tsx +0 -8
  262. package/src/react/For.tsx +0 -116
  263. package/src/react/Memo.tsx +0 -4
  264. package/src/react/Reactive.tsx +0 -53
  265. package/src/react/Show.tsx +0 -33
  266. package/src/react/Switch.tsx +0 -43
  267. package/src/react/react-globals.ts +0 -3
  268. package/src/react/reactInterfaces.ts +0 -32
  269. package/src/react/reactive-observer.tsx +0 -210
  270. package/src/react/useComputed.ts +0 -36
  271. package/src/react/useEffectOnce.ts +0 -41
  272. package/src/react/useIsMounted.ts +0 -16
  273. package/src/react/useMount.ts +0 -15
  274. package/src/react/useObservable.ts +0 -24
  275. package/src/react/useObservableReducer.ts +0 -52
  276. package/src/react/useObservableState.ts +0 -30
  277. package/src/react/useObserve.ts +0 -54
  278. package/src/react/useObserveEffect.ts +0 -40
  279. package/src/react/usePauseProvider.tsx +0 -16
  280. package/src/react/useSelector.ts +0 -167
  281. package/src/react/useUnmount.ts +0 -8
  282. package/src/react/useWhen.ts +0 -9
  283. package/src/react-hooks/createObservableHook.ts +0 -53
  284. package/src/react-hooks/useHover.ts +0 -40
  285. package/src/react-hooks/useMeasure.ts +0 -48
  286. package/src/react-hooks/useObservableNextRouter.ts +0 -137
  287. package/src/retry.ts +0 -71
  288. package/src/setupTracking.ts +0 -26
  289. package/src/sync/activateSyncedNode.ts +0 -128
  290. package/src/sync/configureObservableSync.ts +0 -7
  291. package/src/sync/persistTypes.ts +0 -216
  292. package/src/sync/syncHelpers.ts +0 -180
  293. package/src/sync/syncObservable.ts +0 -1056
  294. package/src/sync/syncObservableAdapter.ts +0 -31
  295. package/src/sync/syncTypes.ts +0 -189
  296. package/src/sync/synced.ts +0 -21
  297. package/src/sync-plugins/crud.ts +0 -412
  298. package/src/sync-plugins/fetch.ts +0 -80
  299. package/src/sync-plugins/keel.ts +0 -495
  300. package/src/sync-plugins/supabase.ts +0 -249
  301. package/src/sync-plugins/tanstack-query.ts +0 -113
  302. package/src/sync-plugins/tanstack-react-query.ts +0 -12
  303. package/src/trace/traceHelpers.ts +0 -11
  304. package/src/trace/useTraceListeners.ts +0 -34
  305. package/src/trace/useTraceUpdates.ts +0 -24
  306. package/src/trace/useVerifyNotTracking.ts +0 -33
  307. package/src/trace/useVerifyOneRender.ts +0 -10
  308. package/src/trackSelector.ts +0 -52
  309. package/src/tracking.ts +0 -43
  310. package/src/types/babel.d.ts +0 -12
  311. package/src/when.ts +0 -75
  312. package/sync-plugins/crud.js.map +0 -1
  313. package/sync-plugins/crud.mjs.map +0 -1
  314. package/sync-plugins/fetch.js.map +0 -1
  315. package/sync-plugins/fetch.mjs.map +0 -1
  316. package/sync-plugins/keel.js.map +0 -1
  317. package/sync-plugins/keel.mjs.map +0 -1
  318. package/sync-plugins/supabase.js.map +0 -1
  319. package/sync-plugins/supabase.mjs.map +0 -1
  320. package/sync-plugins/tanstack-query.js.map +0 -1
  321. package/sync-plugins/tanstack-query.mjs.map +0 -1
  322. package/sync-plugins/tanstack-react-query.js.map +0 -1
  323. package/sync-plugins/tanstack-react-query.mjs.map +0 -1
  324. package/sync.js.map +0 -1
  325. package/sync.mjs.map +0 -1
  326. package/trace.js.map +0 -1
  327. package/trace.mjs.map +0 -1
@@ -1,38 +1,33 @@
1
1
  import { observable } from '@legendapp/state';
2
2
 
3
- let _options = { setter: 'hash' };
3
+ // src/helpers/pageHash.ts
4
+ var _options = { setter: "hash" };
4
5
  function configurePageHash(options) {
5
- _options = options;
6
+ _options = options;
6
7
  }
7
- const hasWindow = typeof window !== 'undefined';
8
- const pageHash = observable(hasWindow ? window.location.hash.slice(1) : '');
8
+ var hasWindow = typeof window !== "undefined";
9
+ var pageHash = observable(hasWindow ? window.location.hash.slice(1) : "");
9
10
  if (hasWindow) {
10
- let isSetting = false;
11
- // Set the page hash when the observable changes
12
- pageHash.onChange(({ value }) => {
13
- if (!isSetting) {
14
- const hash = '#' + value;
15
- const setter = (_options === null || _options === void 0 ? void 0 : _options.setter) || 'hash';
16
- if (setter === 'pushState') {
17
- history.pushState(null, null, hash);
18
- }
19
- else if (setter === 'replaceState') {
20
- history.replaceState(null, null, hash);
21
- }
22
- else {
23
- location.hash = hash;
24
- }
25
- }
26
- });
27
- // Update the observable whenever the hash changes
28
- const cb = () => {
29
- isSetting = true;
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
- let _options = { setter: 'hash' };
5
+ // src/helpers/pageHashParams.ts
6
+ var _options = { setter: "hash" };
6
7
  function configurePageHashParams(options) {
7
- _options = options;
8
+ _options = options;
8
9
  }
9
10
  function toParams(str) {
10
- const ret = {};
11
- const searchParams = new URLSearchParams(str);
12
- for (const [key, value] of searchParams) {
13
- ret[key] = value;
14
- }
15
- return ret;
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
- return new URLSearchParams(params).toString().replace(/=$/, '');
19
+ return new URLSearchParams(params).toString().replace(/=$/, "");
19
20
  }
20
- const hasWindow = typeof window !== 'undefined';
21
- const pageHashParams = state.observable(hasWindow ? toParams(window.location.hash.slice(1)) : {});
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
- let isSetting = false;
24
- // Set the page hash when the observable changes
25
- pageHashParams.onChange(({ value }) => {
26
- if (!isSetting) {
27
- const hash = '#' + toString(value);
28
- const setter = (_options === null || _options === void 0 ? void 0 : _options.setter) || 'hash';
29
- if (setter === 'pushState') {
30
- history.pushState(null, null, hash);
31
- }
32
- else if (setter === 'replaceState') {
33
- history.replaceState(null, null, hash);
34
- }
35
- else {
36
- location.hash = hash;
37
- }
38
- }
39
- });
40
- // Update the observable whenever the hash changes
41
- const cb = () => {
42
- isSetting = true;
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
- let _options = { setter: 'hash' };
3
+ // src/helpers/pageHashParams.ts
4
+ var _options = { setter: "hash" };
4
5
  function configurePageHashParams(options) {
5
- _options = options;
6
+ _options = options;
6
7
  }
7
8
  function toParams(str) {
8
- const ret = {};
9
- const searchParams = new URLSearchParams(str);
10
- for (const [key, value] of searchParams) {
11
- ret[key] = value;
12
- }
13
- return ret;
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
- return new URLSearchParams(params).toString().replace(/=$/, '');
17
+ return new URLSearchParams(params).toString().replace(/=$/, "");
17
18
  }
18
- const hasWindow = typeof window !== 'undefined';
19
- const pageHashParams = observable(hasWindow ? toParams(window.location.hash.slice(1)) : {});
19
+ var hasWindow = typeof window !== "undefined";
20
+ var pageHashParams = observable(
21
+ hasWindow ? toParams(window.location.hash.slice(1)) : {}
22
+ );
20
23
  if (hasWindow) {
21
- let isSetting = false;
22
- // Set the page hash when the observable changes
23
- pageHashParams.onChange(({ value }) => {
24
- if (!isSetting) {
25
- const hash = '#' + toString(value);
26
- const setter = (_options === null || _options === void 0 ? void 0 : _options.setter) || 'hash';
27
- if (setter === 'pushState') {
28
- history.pushState(null, null, hash);
29
- }
30
- else if (setter === 'replaceState') {
31
- history.replaceState(null, null, hash);
32
- }
33
- else {
34
- location.hash = hash;
35
- }
36
- }
37
- });
38
- // Update the observable whenever the hash changes
39
- const cb = () => {
40
- isSetting = true;
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
@@ -0,0 +1,6 @@
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.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const currentTime: import("@legendapp/state").ObservablePrimitive<Date>;
2
- declare const currentDay: import("@legendapp/state").ObservablePrimitive<Date>;
3
- export { currentTime, currentDay };
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
- const MSPerMinute = 60000;
5
+ // src/helpers/time.ts
6
+ var MSPerMinute = 6e4;
6
7
  function clearTime(date) {
7
- date = new Date(date);
8
- date.setHours(0, 0, 0, 0);
9
- return date;
8
+ date = new Date(date);
9
+ date.setHours(0, 0, 0, 0);
10
+ return date;
10
11
  }
11
- let time = new Date();
12
- const currentTime = state.observable(time);
13
- const currentDay = state.observable(clearTime(time));
14
- const timeToSecond = (60 - time.getSeconds() + 1) * 1000;
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
- const now = new Date();
17
- currentTime.set(now);
18
- if (now.getDate() !== time.getDate()) {
19
- currentDay.set(clearTime(now));
20
- }
21
- time = now;
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
- update();
25
- setInterval(update, MSPerMinute);
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
- const MSPerMinute = 60000;
3
+ // src/helpers/time.ts
4
+ var MSPerMinute = 6e4;
4
5
  function clearTime(date) {
5
- date = new Date(date);
6
- date.setHours(0, 0, 0, 0);
7
- return date;
6
+ date = new Date(date);
7
+ date.setHours(0, 0, 0, 0);
8
+ return date;
8
9
  }
9
- let time = new Date();
10
- const currentTime = observable(time);
11
- const currentDay = observable(clearTime(time));
12
- const timeToSecond = (60 - time.getSeconds() + 1) * 1000;
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
- const now = new Date();
15
- currentTime.set(now);
16
- if (now.getDate() !== time.getDate()) {
17
- currentDay.set(clearTime(now));
18
- }
19
- time = now;
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
- update();
23
- setInterval(update, MSPerMinute);
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
- export declare function trackHistory<T>(value$: ObservableParam<T>, targetObservable?: ObservableParam<Record<TimestampAsString, Partial<T>>>): ObservableParam<Record<TimestampAsString, any>>;
4
- export {};
4
+ declare function trackHistory<T>(value$: ObservableParam<T>, targetObservable?: ObservableParam<Record<TimestampAsString, Partial<T>>>): ObservableParam<Record<TimestampAsString, any>>;
5
+
6
+ export { trackHistory };
@@ -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
- const history = targetObservable !== null && targetObservable !== void 0 ? targetObservable : state.observable();
7
- value$.onChange(({ loading, remote, changes }) => {
8
- // Don't save history if this is a remote change.
9
- // History will be saved remotely by the client making the local change.
10
- if (!loading && !remote) {
11
- const time = Date.now().toString();
12
- // Save to history observable by date, with the previous value
13
- for (let i = 0; i < changes.length; i++) {
14
- const { path, prevAtPath, pathTypes } = changes[i];
15
- const obj = state.constructObjectWithPath(path, pathTypes, prevAtPath);
16
- state.mergeIntoObservable(history[time], obj);
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
@@ -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
- const history = targetObservable !== null && targetObservable !== void 0 ? targetObservable : observable();
5
- value$.onChange(({ loading, remote, changes }) => {
6
- // Don't save history if this is a remote change.
7
- // History will be saved remotely by the client making the local change.
8
- if (!loading && !remote) {
9
- const time = Date.now().toString();
10
- // Save to history observable by date, with the previous value
11
- for (let i = 0; i < changes.length; i++) {
12
- const { path, prevAtPath, pathTypes } = changes[i];
13
- const obj = constructObjectWithPath(path, pathTypes, prevAtPath);
14
- mergeIntoObservable(history[time], obj);
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 };
@@ -1,4 +1,5 @@
1
- import { type ObservablePrimitive } from '@legendapp/state';
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
- export declare function undoRedo<T>(obs$: ObservablePrimitive<T>, options?: UndoRedoOptions): {
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
- export {};
36
+
37
+ export { undoRedo };