atom.io 0.14.4 → 0.14.6

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 (91) hide show
  1. package/data/dist/index.cjs +47 -1416
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +16 -317
  4. package/data/dist/index.d.ts +16 -317
  5. package/data/dist/index.js +4 -6
  6. package/data/dist/index.js.map +1 -1
  7. package/dist/chunk-NYTGCPHB.js +261 -0
  8. package/dist/chunk-NYTGCPHB.js.map +1 -0
  9. package/dist/chunk-PZLG2HP3.js +36 -0
  10. package/dist/chunk-PZLG2HP3.js.map +1 -0
  11. package/dist/chunk-XACXFU3B.js +46 -0
  12. package/dist/chunk-XACXFU3B.js.map +1 -0
  13. package/dist/index.cjs +55 -2330
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +21 -269
  16. package/dist/index.d.ts +21 -269
  17. package/dist/index.js +152 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/metafile-cjs.json +1 -1
  20. package/dist/metafile-esm.json +1 -1
  21. package/internal/dist/index.cjs +30 -159
  22. package/internal/dist/index.cjs.map +1 -1
  23. package/internal/dist/index.d.cts +28 -229
  24. package/internal/dist/index.d.ts +28 -229
  25. package/internal/dist/index.js +2027 -1
  26. package/internal/dist/index.js.map +1 -1
  27. package/introspection/dist/index.cjs +45 -1565
  28. package/introspection/dist/index.cjs.map +1 -1
  29. package/introspection/dist/index.d.cts +4 -376
  30. package/introspection/dist/index.d.ts +4 -376
  31. package/introspection/dist/index.js +298 -2
  32. package/introspection/dist/index.js.map +1 -1
  33. package/json/dist/index.cjs +5 -1502
  34. package/json/dist/index.cjs.map +1 -1
  35. package/json/dist/index.d.cts +7 -373
  36. package/json/dist/index.d.ts +7 -373
  37. package/json/dist/index.js +37 -1
  38. package/json/dist/index.js.map +1 -1
  39. package/package.json +1 -1
  40. package/react/dist/index.cjs +14 -1549
  41. package/react/dist/index.cjs.map +1 -1
  42. package/react/dist/index.d.cts +4 -377
  43. package/react/dist/index.d.ts +4 -377
  44. package/react/dist/index.js +62 -2
  45. package/react/dist/index.js.map +1 -1
  46. package/react-devtools/dist/index.cjs +135 -2153
  47. package/react-devtools/dist/index.cjs.map +1 -1
  48. package/react-devtools/dist/index.d.cts +24 -149
  49. package/react-devtools/dist/index.d.ts +24 -149
  50. package/react-devtools/dist/index.js +5 -3
  51. package/react-devtools/dist/index.js.map +1 -1
  52. package/realtime-client/dist/index.cjs +34 -1529
  53. package/realtime-client/dist/index.cjs.map +1 -1
  54. package/realtime-client/dist/index.d.cts +12 -384
  55. package/realtime-client/dist/index.d.ts +12 -384
  56. package/realtime-client/dist/index.js +165 -2
  57. package/realtime-client/dist/index.js.map +1 -1
  58. package/realtime-react/dist/index.cjs +35 -1727
  59. package/realtime-react/dist/index.cjs.map +1 -1
  60. package/realtime-react/dist/index.d.cts +9 -49
  61. package/realtime-react/dist/index.d.ts +9 -49
  62. package/realtime-react/dist/index.js +66 -4
  63. package/realtime-react/dist/index.js.map +1 -1
  64. package/realtime-server/dist/index.cjs +57 -1548
  65. package/realtime-server/dist/index.cjs.map +1 -1
  66. package/realtime-server/dist/index.d.cts +11 -394
  67. package/realtime-server/dist/index.d.ts +11 -394
  68. package/realtime-server/dist/index.js +21 -27
  69. package/realtime-server/dist/index.js.map +1 -1
  70. package/realtime-testing/dist/index.cjs +15 -2376
  71. package/realtime-testing/dist/index.cjs.map +1 -1
  72. package/realtime-testing/dist/index.d.cts +3 -489
  73. package/realtime-testing/dist/index.d.ts +3 -489
  74. package/realtime-testing/dist/index.js +10 -9
  75. package/realtime-testing/dist/index.js.map +1 -1
  76. package/transceivers/set-rtx/dist/index.cjs +9 -31
  77. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  78. package/transceivers/set-rtx/dist/index.d.cts +3 -29
  79. package/transceivers/set-rtx/dist/index.d.ts +3 -29
  80. package/transceivers/set-rtx/dist/index.js +3 -2
  81. package/transceivers/set-rtx/dist/index.js.map +1 -1
  82. package/dist/chunk-GMN5KH6A.js +0 -309
  83. package/dist/chunk-GMN5KH6A.js.map +0 -1
  84. package/dist/chunk-HQWWV67P.js +0 -62
  85. package/dist/chunk-HQWWV67P.js.map +0 -1
  86. package/dist/chunk-MK4OJD24.js +0 -67
  87. package/dist/chunk-MK4OJD24.js.map +0 -1
  88. package/dist/chunk-N7ADBQJG.js +0 -176
  89. package/dist/chunk-N7ADBQJG.js.map +0 -1
  90. package/dist/chunk-PURABO5G.js +0 -2581
  91. package/dist/chunk-PURABO5G.js.map +0 -1
@@ -1,380 +1,7 @@
1
+ import { Store } from 'atom.io/internal';
1
2
  import * as React from 'react';
2
-
3
- type primitive = boolean | number | string | null;
4
-
5
- type Serializable = primitive | Readonly<{
6
- [key: string]: Serializable;
7
- }> | ReadonlyArray<Serializable>;
8
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
9
-
10
- type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
11
- key: string;
12
- type: `atom_family`;
13
- subject: Subject<AtomToken<T>>;
14
- mutable?: boolean;
15
- };
16
-
17
- declare const LoggerIconDictionary: {
18
- readonly "\u231B": "Timeline event fully captured";
19
- readonly "\u23E9": "Timeline redo";
20
- readonly "\u23EA": "Timeline undo";
21
- readonly "\u23ED\uFE0F": "Transaction redo";
22
- readonly "\u23EE\uFE0F": "Transaction undo";
23
- readonly "\u23F3": "Timeline event partially captured";
24
- readonly "\u23F9\uFE0F": "Time-travel complete";
25
- readonly "\uD83D\uDC81": "Notice";
26
- readonly "\uD83D\uDD04": "Realtime transaction synchronized";
27
- readonly "\u2705": "Realtime transaction success";
28
- readonly "\u2728": "Computation complete";
29
- readonly "\u274C": "Conflict prevents attempted action";
30
- readonly "\u2B55": "Operation start";
31
- readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
32
- readonly "\uD83D\uDC40": "Subscription added";
33
- readonly "\uD83D\uDC6A": "Family member added";
34
- readonly "\uD83D\uDCC1": "Stow update";
35
- readonly "\uD83D\uDCC3": "Copy mutable";
36
- readonly "\uD83D\uDCD6": "Read state";
37
- readonly "\uD83D\uDCDD": "Write state";
38
- readonly "\uD83D\uDCE2": "Notify subscribers";
39
- readonly "\uD83D\uDD0C": "Register dependency";
40
- readonly "\uD83D\uDD0D": "Discover root";
41
- readonly "\uD83D\uDD25": "Delete state";
42
- readonly "\uD83D\uDD27": "Create mutable atom";
43
- readonly "\uD83D\uDD28": "Create immutable atom";
44
- readonly "\uD83D\uDD34": "Operation complete";
45
- readonly "\uD83D\uDDD1": "Evict cached value";
46
- readonly "\uD83D\uDCA5": "Caught";
47
- readonly "\uD83D\uDE48": "Subscription canceled";
48
- readonly "\uD83D\uDEC4": "Apply transaction";
49
- readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
50
- readonly "\uD83D\uDEEB": "Begin transaction";
51
- readonly "\uD83D\uDEEC": "Complete transaction";
52
- readonly "\uD83E\uDDEE": "Computing selector";
53
- readonly "\uD83E\uDDF9": "Prepare to evict";
54
- readonly "\uD83E\uDE82": "Abort transaction";
55
- };
56
- type LoggerIcon = keyof typeof LoggerIconDictionary;
57
- declare const LOG_LEVELS: readonly ["info", "warn", "error"];
58
- type LogLevel = (typeof LOG_LEVELS)[number];
59
- type LogFn = (icon: LoggerIcon, tokenType: `atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
60
- type LogFilter = (...params: Parameters<LogFn>) => boolean;
61
- type Logger = Record<LogLevel, LogFn>;
62
- declare class AtomIOLogger implements Logger {
63
- logLevel: `error` | `info` | `warn` | null;
64
- private readonly filter?;
65
- private readonly logger;
66
- constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
67
- error: LogFn;
68
- info: LogFn;
69
- warn: LogFn;
70
- }
71
-
72
- type TransactionToken<_> = {
73
- key: string;
74
- type: `transaction`;
75
- __brand?: _;
76
- };
77
- type TransactionUpdate<ƒ extends ƒn> = {
78
- key: string;
79
- updates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[];
80
- params: Parameters<ƒ>;
81
- output: ReturnType<ƒ>;
82
- };
83
-
84
- type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
85
- key: string;
86
- type: `selector_family`;
87
- subject: Subject<SelectorToken<T>>;
88
- };
89
- type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
90
- key: string;
91
- type: `readonly_selector_family`;
92
- subject: Subject<ReadonlySelectorToken<T>>;
93
- };
94
-
95
- type StateUpdate<T> = {
96
- newValue: T;
97
- oldValue: T;
98
- };
99
- type KeyedStateUpdate<T> = StateUpdate<T> & {
100
- key: string;
101
- family?: FamilyMetadata;
102
- };
103
-
104
- type TimelineToken = {
105
- key: string;
106
- type: `timeline`;
107
- };
108
- type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
109
-
110
- type ƒn = (...parameters: any[]) => any;
111
- type AtomToken<_> = {
112
- key: string;
113
- type: `atom`;
114
- family?: FamilyMetadata;
115
- __brand?: _;
116
- };
117
- interface MutableAtomToken<T extends Transceiver<any>, J extends Serializable> extends AtomToken<T> {
118
- __asJSON?: J;
119
- __update?: T extends Transceiver<infer Update> ? Update : never;
120
- }
121
- type SelectorToken<_> = {
122
- key: string;
123
- type: `selector`;
124
- family?: FamilyMetadata;
125
- __brand?: _;
126
- };
127
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
128
- type ReadonlySelectorToken<_> = {
129
- key: string;
130
- type: `readonly_selector`;
131
- family?: FamilyMetadata;
132
- __brand?: _;
133
- };
134
- type FamilyMetadata = {
135
- key: string;
136
- subKey: string;
137
- };
138
-
139
- declare class Subject<T> {
140
- Subscriber: (value: T) => void;
141
- subscribers: Map<string, this[`Subscriber`]>;
142
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
143
- private unsubscribe;
144
- next(value: T): void;
145
- }
146
- declare class StatefulSubject<T> extends Subject<T> {
147
- state: T;
148
- constructor(initialState: T);
149
- next(value: T): void;
150
- }
151
-
152
- type Selector<T> = {
153
- key: string;
154
- type: `selector`;
155
- family?: FamilyMetadata;
156
- install: (store: Store) => void;
157
- subject: Subject<{
158
- newValue: T;
159
- oldValue: T;
160
- }>;
161
- get: () => T;
162
- set: (newValue: T | ((oldValue: T) => T)) => void;
163
- };
164
- type ReadonlySelector<T> = {
165
- key: string;
166
- type: `readonly_selector`;
167
- family?: FamilyMetadata;
168
- install: (store: Store) => void;
169
- subject: Subject<{
170
- newValue: T;
171
- oldValue: T;
172
- }>;
173
- get: () => T;
174
- };
175
-
176
- type Transaction<ƒ extends ƒn> = {
177
- key: string;
178
- type: `transaction`;
179
- install: (store: Store) => void;
180
- subject: Subject<TransactionUpdate<ƒ>>;
181
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
182
- };
183
-
184
- type TransactionMeta<ƒ extends ƒn> = {
185
- phase: `applying` | `building`;
186
- time: number;
187
- update: TransactionUpdate<ƒ>;
188
- };
189
-
190
- type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
191
- type Cardinality = `1:1` | `1:n` | `n:n`;
192
-
193
- interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
194
- readonly relations: [string, string[]][];
195
- readonly contents: [string, Content][];
196
- }
197
- interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
198
- readonly between: [a: ASide, b: BSide];
199
- readonly cardinality: Cardinality;
200
- }
201
- type BaseExternalStoreConfiguration = {
202
- addRelation: (a: string, b: string) => void;
203
- deleteRelation: (a: string, b: string) => void;
204
- replaceRelationsSafely: (a: string, bs: string[]) => void;
205
- replaceRelationsUnsafely: (a: string, bs: string[]) => void;
206
- getRelatedKeys: (key: string) => Set<string> | undefined;
207
- has: (a: string, b?: string) => boolean;
208
- };
209
- type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
210
- getContent: (contentKey: string) => Content | undefined;
211
- setContent: (contentKey: string, content: Content) => void;
212
- deleteContent: (contentKey: string) => void;
213
- };
214
- type Empty<Obj extends object> = {
215
- [Key in keyof Obj]?: undefined;
216
- };
217
- type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
218
- type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
219
- externalStore?: ExternalStoreConfiguration<Content>;
220
- isContent?: Refinement<unknown, Content>;
221
- makeContentKey?: (a: string, b: string) => string;
222
- };
223
- type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
224
- declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
225
- readonly a: ASide;
226
- readonly b: BSide;
227
- readonly cardinality: Cardinality;
228
- readonly relations: Map<string, Set<string>>;
229
- readonly contents: Map<string, Content>;
230
- isContent: Refinement<unknown, Content> | null;
231
- makeContentKey: (a: string, b: string) => string;
232
- getRelatedKeys(key: string): Set<string> | undefined;
233
- protected addRelation(a: string, b: string): void;
234
- protected deleteRelation(a: string, b: string): void;
235
- protected replaceRelationsUnsafely(a: string, bs: string[]): void;
236
- protected replaceRelationsSafely(a: string, bs: string[]): void;
237
- protected getContentInternal(contentKey: string): Content | undefined;
238
- protected setContent(contentKey: string, content: Content): void;
239
- protected deleteContent(contentKey: string): void;
240
- constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
241
- toJSON(): JunctionJSON<ASide, BSide, Content>;
242
- set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
243
- set(relation: {
244
- [Key in ASide | BSide]: string;
245
- }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
246
- delete(a: string, b?: string): this;
247
- delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
248
- getRelatedKey(key: string): string | undefined;
249
- replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
250
- reckless: boolean;
251
- }): this;
252
- getContent(a: string, b: string): Content | undefined;
253
- getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
254
- has(a: string, b?: string): boolean;
255
- }
256
-
257
- interface Lineage {
258
- parent: typeof this | null;
259
- child: typeof this | null;
260
- }
261
-
262
- interface Transceiver<Signal extends Serializable> {
263
- do: (update: Signal) => void;
264
- undo: (update: Signal) => void;
265
- subscribe: (key: string, fn: (update: Signal) => void) => () => void;
266
- cacheUpdateNumber: number;
267
- getUpdateNumber: (update: Signal) => number;
268
- }
269
-
270
- /**
271
- * @internal Give the tracker a transceiver state and a store, and it will
272
- * subscribe to the transceiver's inner value. When the inner value changes,
273
- * the tracker will update its own state to reflect the change.
274
- */
275
- declare class Tracker<Mutable extends Transceiver<any>> {
276
- private Update;
277
- private initializeState;
278
- private unsubscribeFromInnerValue;
279
- private observeCore;
280
- private updateCore;
281
- mutableState: MutableAtomToken<Mutable, Serializable>;
282
- latestUpdateState: AtomToken<typeof this.Update | null>;
283
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
284
- }
285
-
286
- interface MutableAtom<T> extends Atom<T> {
287
- mutable: true;
288
- }
289
-
290
- type OperationProgress = {
291
- open: false;
292
- } | {
293
- open: true;
294
- done: Set<string>;
295
- prev: Map<string, any>;
296
- time: number;
297
- token: StateToken<any>;
298
- };
299
-
300
- type TimelineAtomUpdate = StateUpdate<unknown> & {
301
- key: string;
302
- type: `atom_update`;
303
- timestamp: number;
304
- family?: FamilyMetadata;
305
- };
306
- type TimelineSelectorUpdate = {
307
- key: string;
308
- type: `selector_update`;
309
- timestamp: number;
310
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
311
- };
312
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
313
- key: string;
314
- type: `transaction_update`;
315
- timestamp: number;
316
- };
317
- type Timeline = {
318
- type: `timeline`;
319
- key: string;
320
- at: number;
321
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
322
- timeTraveling: `into_future` | `into_past` | null;
323
- history: TimelineUpdate[];
324
- selectorTime: number | null;
325
- transactionKey: string | null;
326
- install: (store: Store) => void;
327
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
328
- };
329
-
330
- declare class Store implements Lineage {
331
- parent: Store | null;
332
- child: Store | null;
333
- valueMap: Map<string, any>;
334
- atoms: Map<string, Atom<any> | MutableAtom<any>>;
335
- selectors: Map<string, Selector<any>>;
336
- readonlySelectors: Map<string, ReadonlySelector<any>>;
337
- trackers: Map<string, Tracker<Transceiver<any>>>;
338
- families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
339
- timelines: Map<string, Timeline>;
340
- transactions: Map<string, Transaction<ƒn>>;
341
- atomsThatAreDefault: Set<string>;
342
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
343
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
344
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
345
- source: string;
346
- }>;
347
- subject: {
348
- atomCreation: Subject<AtomToken<unknown>>;
349
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
350
- transactionCreation: Subject<TransactionToken<ƒn>>;
351
- timelineCreation: Subject<TimelineToken>;
352
- transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
353
- operationStatus: Subject<OperationProgress>;
354
- };
355
- operation: OperationProgress;
356
- transactionMeta: TransactionMeta<ƒn> | null;
357
- config: {
358
- name: string;
359
- };
360
- loggers: AtomIOLogger[];
361
- logger: Logger;
362
- constructor(name: string, store?: Store | null);
363
- }
364
-
365
- type Atom<T> = {
366
- key: string;
367
- type: `atom`;
368
- mutable?: boolean;
369
- family?: FamilyMetadata;
370
- install: (store: Store) => void;
371
- subject: Subject<{
372
- newValue: T;
373
- oldValue: T;
374
- }>;
375
- default: T | (() => T);
376
- cleanup?: () => void;
377
- };
3
+ import { StateToken, ReadonlySelectorToken, MutableAtomToken, TimelineToken } from 'atom.io';
4
+ import { Json } from 'atom.io/json';
378
5
 
379
6
  declare const StoreContext: React.Context<Store>;
380
7
  declare const StoreProvider: React.FC<{
@@ -384,7 +11,7 @@ declare const StoreProvider: React.FC<{
384
11
 
385
12
  declare function useI<T>(token: StateToken<T>): <New extends T>(next: New | ((old: T) => New)) => void;
386
13
  declare function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T;
387
- declare function useJSON<Serializable extends Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
14
+ declare function useJSON<Serializable extends Json.Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
388
15
  type TimelineMeta = {
389
16
  at: number;
390
17
  length: number;
@@ -1,4 +1,64 @@
1
- export { StoreContext, StoreProvider, useI, useJSON, useO, useTL } from '../../dist/chunk-HQWWV67P.js';
2
- import '../../dist/chunk-PURABO5G.js';
1
+ import '../../dist/chunk-PZLG2HP3.js';
2
+ import { IMPLICIT, subscribeToState, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
3
+ import * as React2 from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
5
+ import { setState, getState, undo, redo } from 'atom.io';
6
+
7
+ var StoreContext = React2.createContext(IMPLICIT.STORE);
8
+ var StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, { value: store, children });
9
+ function useI(token) {
10
+ const store = React2.useContext(StoreContext);
11
+ const setter = React2.useRef(null);
12
+ if (setter.current === null) {
13
+ setter.current = (next) => setState(token, next, store);
14
+ }
15
+ return setter.current;
16
+ }
17
+ function useO(token) {
18
+ const store = React2.useContext(StoreContext);
19
+ const id = React2.useId();
20
+ return React2.useSyncExternalStore(
21
+ (dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
22
+ () => getState(token, store),
23
+ () => getState(token, store)
24
+ );
25
+ }
26
+ function useJSON(token) {
27
+ const jsonToken = getJsonToken(token);
28
+ return useO(jsonToken);
29
+ }
30
+ function useTL(token) {
31
+ const store = React2.useContext(StoreContext);
32
+ const id = React2.useId();
33
+ const timeline = withdraw(token, store);
34
+ const base = React2.useRef({
35
+ undo: () => undo(token),
36
+ redo: () => redo(token)
37
+ });
38
+ const rebuildMeta = React2.useCallback(() => {
39
+ var _a, _b;
40
+ return Object.assign(
41
+ {
42
+ at: (_a = timeline == null ? void 0 : timeline.at) != null ? _a : NaN,
43
+ length: (_b = timeline == null ? void 0 : timeline.history.length) != null ? _b : NaN
44
+ },
45
+ base.current
46
+ );
47
+ }, []);
48
+ const meta = React2.useRef(rebuildMeta());
49
+ const retrieve = React2.useCallback(() => {
50
+ if (meta.current.at !== (timeline == null ? void 0 : timeline.at) || meta.current.length !== (timeline == null ? void 0 : timeline.history.length)) {
51
+ meta.current = rebuildMeta();
52
+ }
53
+ return meta.current;
54
+ }, []);
55
+ return React2.useSyncExternalStore(
56
+ (dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),
57
+ retrieve,
58
+ retrieve
59
+ );
60
+ }
61
+
62
+ export { StoreContext, StoreProvider, useI, useJSON, useO, useTL };
3
63
  //# sourceMappingURL=out.js.map
4
64
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACVhD,YAAYA,YAAW;AAEvB,SAAS,UAAU,MAAM,UAAU,YAAY;AAQ/C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAIA,SAAS,KACf,OACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,SAAS,OAAO,MAAM,KAAK;AAAA,EACvD;AACA,SAAO,OAAO;AACf;AAEO,SAAS,KAAQ,OAAoD;AAC3E,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,OAAO,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACpE,MAAM,SAAS,OAAO,KAAK;AAAA,IAC3B,MAAM,SAAS,OAAO,KAAK;AAAA,EAC5B;AACD;AAEO,SAAS,QACf,OACe;AACf,QAAM,YAAY,aAAa,KAAK;AACpC,SAAO,KAAK,SAAS;AACtB;AASO,SAAS,MAAM,OAAoC;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,OAAa,cAAO;AAAA,IACzB,MAAM,MAAM,KAAK,KAAK;AAAA,IACtB,MAAM,MAAM,KAAK,KAAK;AAAA,EACvB,CAAC;AACD,QAAM,cAAoB,mBAAY,MAAM;AAhE7C;AAiEE,WAAO,OAAO;AAAA,MACb;AAAA,QACC,KAAI,0CAAU,OAAV,YAAgB;AAAA,QACpB,SAAQ,0CAAU,QAAQ,WAAlB,YAA4B;AAAA,MACrC;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD,GAAG,CAAC,CAAC;AACL,QAAM,OAAa,cAAqB,YAAY,CAAC;AACrD,QAAM,WAAiB,mBAAY,MAAM;AACxC,QACC,KAAK,QAAQ,QAAO,qCAAU,OAC9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,SACzC;AACD,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb,GAAG,CAAC,CAAC;AACL,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as React from \"react\"\n\nimport { getState, redo, setState, undo } from \"atom.io\"\nimport type {\n\tMutableAtomToken,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n} from \"atom.io\"\n\nimport {\n\tgetJsonToken,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\twithdraw,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: StateToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setState(token, next, store)\n\t}\n\treturn setter.current\n}\n\nexport function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),\n\t\t() => getState(token, store),\n\t\t() => getState(token, store),\n\t)\n}\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable {\n\tconst jsonToken = getJsonToken(token)\n\treturn useO(jsonToken)\n}\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst base = React.useRef({\n\t\tundo: () => undo(token),\n\t\tredo: () => redo(token),\n\t})\n\tconst rebuildMeta = React.useCallback(() => {\n\t\treturn Object.assign(\n\t\t\t{\n\t\t\t\tat: timeline?.at ?? NaN,\n\t\t\t\tlength: timeline?.history.length ?? NaN,\n\t\t\t},\n\t\t\tbase.current,\n\t\t)\n\t}, [])\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = React.useCallback(() => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length\n\t\t) {\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}, [])\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}