pinia-react 1.2.1 → 1.3.0

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/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2025 karl
4
+ Copyright (c) 2019-present Eduardo San Martin Morote
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.d.ts CHANGED
@@ -1,68 +1,562 @@
1
+ import { ComputedRef, DebuggerEvent, EffectScope, Ref, UnwrapRef, WatchOptions, WritableComputedRef } from "@maoism/runtime-core";
2
+
1
3
  //#region src/types.d.ts
2
4
 
3
- type StateTree = Record<string | number | symbol, unknown>;
4
- type _StoreWithGetters<G> = { readonly [k in keyof G]: G[k] extends ((...args: any[]) => infer R) ? R : G[k] };
5
- type _ActionsTree = Record<string | number | symbol, (...args: any[]) => any>;
6
- type PiniaCustomStateProperties<S extends StateTree = StateTree> = {};
7
- type _GettersTree<S extends StateTree> = Record<string, (state: S & PiniaCustomStateProperties<S>) => any>;
8
5
  /**
9
- * Interface to be extended by the user when they add properties through plugins.
6
+ * Generic state of a Store
7
+ */
8
+ type StateTree = Record<PropertyKey, any>;
9
+ /**
10
+ * Recursive `Partial<T>`. Used by {@link Store['$patch']}.
11
+ *
12
+ * For internal use **only**
10
13
  */
11
- type PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> = {};
12
14
  type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> };
13
- interface _StoreWithState<Id extends string, S extends StateTree, G, A> {
15
+ /**
16
+ * Possible types for SubscriptionCallback
17
+ */
18
+ declare enum MutationType {
19
+ /**
20
+ * Direct mutation of the state:
21
+ *
22
+ * - `store.name = 'new name'`
23
+ * - `store.$state.name = 'new name'`
24
+ * - `store.list.push('new item')`
25
+ */
26
+ direct = "direct",
27
+ /**
28
+ * Mutated the state with `$patch` and an object
29
+ *
30
+ * - `store.$patch({ name: 'newName' })`
31
+ */
32
+ patchObject = "patch object",
33
+ /**
34
+ * Mutated the state with `$patch` and a function
35
+ *
36
+ * - `store.$patch(state => state.name = 'newName')`
37
+ */
38
+ patchFunction = "patch function",
39
+ }
40
+ /**
41
+ * Base type for the context passed to a subscription callback. Internal type.
42
+ */
43
+ interface _SubscriptionCallbackMutationBase {
44
+ /**
45
+ * Type of the mutation.
46
+ */
47
+ type: MutationType;
48
+ /**
49
+ * `id` of the store doing the mutation.
50
+ */
51
+ storeId: string;
52
+ /**
53
+ * 🔴 DEV ONLY, DO NOT use for production code. Different mutation calls. Comes from
54
+ * https://vuejs.org/guide/extras/reactivity-in-depth.html#reactivity-debugging and allows to track mutations in
55
+ * devtools and plugins **during development only**.
56
+ */
57
+ events?: DebuggerEvent[] | DebuggerEvent;
58
+ }
59
+ /**
60
+ * Context passed to a subscription callback when directly mutating the state of
61
+ * a store with `store.someState = newValue` or `store.$state.someState =
62
+ * newValue`.
63
+ */
64
+ interface SubscriptionCallbackMutationDirect extends _SubscriptionCallbackMutationBase {
65
+ type: MutationType.direct;
66
+ events: DebuggerEvent;
67
+ }
68
+ /**
69
+ * Context passed to a subscription callback when `store.$patch()` is called
70
+ * with an object.
71
+ */
72
+ interface SubscriptionCallbackMutationPatchObject<S> extends _SubscriptionCallbackMutationBase {
73
+ type: MutationType.patchObject;
74
+ events: DebuggerEvent[];
75
+ /**
76
+ * Object passed to `store.$patch()`.
77
+ */
78
+ payload: _DeepPartial<UnwrapRef<S>>;
79
+ }
80
+ /**
81
+ * Context passed to a subscription callback when `store.$patch()` is called
82
+ * with a function.
83
+ */
84
+ interface SubscriptionCallbackMutationPatchFunction extends _SubscriptionCallbackMutationBase {
85
+ type: MutationType.patchFunction;
86
+ events: DebuggerEvent[];
87
+ }
88
+ /**
89
+ * Context object passed to a subscription callback.
90
+ */
91
+ type SubscriptionCallbackMutation<S> = SubscriptionCallbackMutationDirect | SubscriptionCallbackMutationPatchObject<S> | SubscriptionCallbackMutationPatchFunction;
92
+ /**
93
+ * Callback of a subscription
94
+ */
95
+ type SubscriptionCallback<S> = (
96
+ /**
97
+ * Object with information relative to the store mutation that triggered the
98
+ * subscription.
99
+ */
100
+ mutation: SubscriptionCallbackMutation<S>,
101
+ /**
102
+ * State of the store when the subscription is triggered. Same as
103
+ * `store.$state`.
104
+ */
105
+ state: UnwrapRef<S>) => void;
106
+ /**
107
+ * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring
108
+ * purposes. For internal use only.
109
+ * For internal use **only**
110
+ */
111
+ interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
112
+ /**
113
+ * Name of the action
114
+ */
115
+ name: ActionName;
116
+ /**
117
+ * Store that is invoking the action
118
+ */
119
+ store: Store;
120
+ /**
121
+ * Parameters passed to the action
122
+ */
123
+ args: A extends Record<ActionName, _Method> ? Parameters<A[ActionName]> : unknown[];
124
+ /**
125
+ * Sets up a hook once the action is finished. It receives the return value
126
+ * of the action, if it's a Promise, it will be unwrapped.
127
+ */
128
+ after: (callback: A extends Record<ActionName, _Method> ? (resolvedReturn: Awaited<ReturnType<A[ActionName]>>) => void : () => void) => void;
129
+ /**
130
+ * Sets up a hook if the action fails. Return `false` to catch the error and
131
+ * stop it from propagating.
132
+ */
133
+ onError: (callback: (error: unknown) => void) => void;
134
+ }
135
+ /**
136
+ * Context object passed to callbacks of `store.$onAction(context => {})`
137
+ * TODO: should have only the Id, the Store and Actions to generate the proper object
138
+ */
139
+ type StoreOnActionListenerContext<Id extends string, S extends StateTree, G, A> = _ActionsTree extends A ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree> : { [Name in keyof A]: Name extends string ? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A> : never }[keyof A];
140
+ /**
141
+ * Argument of `store.$onAction()`
142
+ */
143
+ type StoreOnActionListener<Id extends string, S extends StateTree, G, A> = (context: StoreOnActionListenerContext<Id, S, G, {} extends A ? _ActionsTree : A>) => void;
144
+ /**
145
+ * Properties of a store.
146
+ */
147
+ interface StoreProperties<Id extends string> {
148
+ /**
149
+ * Unique identifier of the store
150
+ */
14
151
  $id: Id;
15
- $state: S & PiniaCustomStateProperties<S>;
16
- $patch(partialState: _DeepPartial<S>): void;
17
- $patch<F extends (state: S) => any>(stateMutator: ReturnType<F> extends Promise<any> ? never : F): void;
152
+ /**
153
+ * Private property defining the pinia the store is attached to.
154
+ *
155
+ * @internal
156
+ */
157
+ _p: Pinia;
158
+ /**
159
+ * Used by devtools plugin to retrieve getters. Removed in production.
160
+ *
161
+ * @internal
162
+ */
163
+ _getters?: string[];
164
+ /**
165
+ * Used (and added) by devtools plugin to detect Setup vs Options API usage.
166
+ *
167
+ * @internal
168
+ */
169
+ _isOptionsAPI?: boolean;
170
+ /**
171
+ * Used by devtools plugin to retrieve properties added with plugins. Removed
172
+ * in production. Can be used by the user to add property keys of the store
173
+ * that should be displayed in devtools.
174
+ */
175
+ _customProperties: Set<string>;
176
+ /**
177
+ * Handles a HMR replacement of this store. Dev Only.
178
+ *
179
+ * @internal
180
+ */
181
+ _hotUpdate(useStore: StoreGeneric): void;
182
+ /**
183
+ * Allows pausing some of the watching mechanisms while the store is being
184
+ * patched with a newer version.
185
+ *
186
+ * @internal
187
+ */
188
+ _hotUpdating: boolean;
189
+ /**
190
+ * Payload of the hmr update. Dev only.
191
+ *
192
+ * @internal
193
+ */
194
+ _hmrPayload: {
195
+ state: string[];
196
+ hotState: Ref<StateTree>;
197
+ actions: _ActionsTree;
198
+ getters: _ActionsTree;
199
+ };
200
+ }
201
+ /**
202
+ * Base store with state and functions. Should not be used directly.
203
+ */
204
+ interface _StoreWithState<Id extends string, S extends StateTree, G, A> extends StoreProperties<Id> {
205
+ /**
206
+ * State of the Store. Setting it will internally call `$patch()` to update the state.
207
+ */
208
+ $state: UnwrapRef<S> & PiniaCustomStateProperties<S>;
209
+ /**
210
+ * Applies a state patch to current state. Allows passing nested values
211
+ *
212
+ * @param partialState - patch to apply to the state
213
+ */
214
+ $patch(partialState: _DeepPartial<UnwrapRef<S>>): void;
215
+ /**
216
+ * Group multiple changes into one function. Useful when mutating objects like
217
+ * Sets or arrays and applying an object patch isn't practical, e.g. appending
218
+ * to an array. The function passed to `$patch()` **must be synchronous**.
219
+ *
220
+ * @param stateMutator - function that mutates `state`, cannot be asynchronous
221
+ */
222
+ $patch<F extends (state: UnwrapRef<S>) => any>(stateMutator: ReturnType<F> extends Promise<any> ? never : F): void;
223
+ /**
224
+ * Resets the store to its initial state by building a new state object.
225
+ */
18
226
  $reset(): void;
19
- $subscribe(callback: (newValue: S) => any, options?: {
20
- detached: boolean;
21
- }): any;
227
+ /**
228
+ * Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note
229
+ * that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the
230
+ * component gets unmounted unless `detached` is set to true.
231
+ *
232
+ * @param callback - callback passed to the watcher
233
+ * @param options - `watch` options + `detached` to detach the subscription from the context (usually a component)
234
+ * this is called from. Note that the `flush` option does not affect calls to `store.$patch()`.
235
+ * @returns function that removes the watcher
236
+ */
237
+ $subscribe(callback: SubscriptionCallback<S>, options?: {
238
+ detached?: boolean;
239
+ } & WatchOptions): () => void;
240
+ /**
241
+ * Setups a callback to be called every time an action is about to get
242
+ * invoked. The callback receives an object with all the relevant information
243
+ * of the invoked action:
244
+ * - `store`: the store it is invoked on
245
+ * - `name`: The name of the action
246
+ * - `args`: The parameters passed to the action
247
+ *
248
+ * On top of these, it receives two functions that allow setting up a callback
249
+ * once the action finishes or when it fails.
250
+ *
251
+ * It also returns a function to remove the callback. Note than when calling
252
+ * `store.$onAction()` inside of a component, it will be automatically cleaned
253
+ * up when the component gets unmounted unless `detached` is set to true.
254
+ *
255
+ * @example
256
+ *
257
+ *```js
258
+ *store.$onAction(({ after, onError }) => {
259
+ * // Here you could share variables between all of the hooks as well as
260
+ * // setting up watchers and clean them up
261
+ * after((resolvedValue) => {
262
+ * // can be used to cleanup side effects
263
+ * . // `resolvedValue` is the value returned by the action, if it's a
264
+ * . // Promise, it will be the resolved value instead of the Promise
265
+ * })
266
+ * onError((error) => {
267
+ * // can be used to pass up errors
268
+ * })
269
+ *})
270
+ *```
271
+ *
272
+ * @param callback - callback called before every action
273
+ * @param detached - detach the subscription from the context this is called from
274
+ * @returns function that removes the watcher
275
+ */
276
+ $onAction(callback: StoreOnActionListener<Id, S, G, A>, detached?: boolean): () => void;
277
+ /**
278
+ * Stops the associated effect scope of the store and remove it from the store
279
+ * registry. Plugins can override this method to cleanup any added effects.
280
+ * e.g. devtools plugin stops displaying disposed stores from devtools.
281
+ * Note this doesn't delete the state of the store, you have to do it manually with
282
+ * `delete pinia.state.value[store.$id]` if you want to. If you don't and the
283
+ * store is used again, it will reuse the previous state.
284
+ */
285
+ $dispose(): void;
22
286
  }
23
- type Store<Id extends string, S extends StateTree, G, A> = _StoreWithState<Id, S, G, A> & S & _StoreWithGetters<G> & (_ActionsTree extends A ? {} : A) & PiniaCustomProperties<Id, S, G, A> & PiniaCustomStateProperties<S>;
287
+ /**
288
+ * Generic type for a function that can infer arguments and return type
289
+ *
290
+ * For internal use **only**
291
+ */
292
+ type _Method = (...args: any[]) => any;
293
+ /**
294
+ * Store augmented for actions. For internal usage only.
295
+ * For internal use **only**
296
+ */
297
+ type _StoreWithActions<A> = { [k in keyof A]: A[k] extends ((...args: infer P) => infer R) ? (...args: P) => R : never };
298
+ /**
299
+ * Store augmented with getters. For internal usage only.
300
+ * For internal use **only**
301
+ */
302
+ type _StoreWithGetters<G> = _StoreWithGetters_Readonly<G> & _StoreWithGetters_Writable<G>;
303
+ /**
304
+ * Store augmented with readonly getters. For internal usage **only**.
305
+ */
306
+ type _StoreWithGetters_Readonly<G> = { readonly [K in keyof G as G[K] extends ((...args: any[]) => any) ? K : ComputedRef extends G[K] ? K : never]: G[K] extends ((...args: any[]) => infer R) ? R : UnwrapRef<G[K]> };
307
+ /**
308
+ * Store augmented with writable getters. For internal usage **only**.
309
+ */
310
+ type _StoreWithGetters_Writable<G> = { [K in keyof G as G[K] extends WritableComputedRef<any> ? K : never]: G[K] extends Readonly<WritableComputedRef<infer R>> ? R : never };
311
+ /**
312
+ * Store type to build a store.
313
+ */
314
+ type Store<Id extends string = string, S extends StateTree = {}, G = {}, A = {}> = _StoreWithState<Id, S, G, A> & UnwrapRef<S> & _StoreWithGetters<G> & (_ActionsTree extends A ? {} : A) & PiniaCustomProperties<Id, S, G, A> & PiniaCustomStateProperties<S>;
315
+ /**
316
+ * Generic and type-unsafe version of Store. Doesn't fail on access with
317
+ * strings, making it much easier to write generic functions that do not care
318
+ * about the kind of store that is passed.
319
+ */
24
320
  type StoreGeneric = Store<string, StateTree, _GettersTree<StateTree>, _ActionsTree>;
25
- type DefineStoreOptionsBase<S extends StateTree, Store> = {};
26
- interface DefineStoreOptions<Id extends string, S extends StateTree, G, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
27
- state?: () => S;
28
- getters?: G & ThisType<S & _StoreWithGetters<G> & PiniaCustomProperties>;
29
- actions?: A & ThisType<A & S & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>;
30
- }
31
321
  /**
32
322
  * Return type of `defineStore()`. Function that allows instantiating a store.
33
323
  */
34
324
  interface StoreDefinition<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {
35
325
  /**
36
326
  * Returns a store, creates it if necessary.
327
+ *
328
+ * @param pinia - Pinia instance to retrieve the store
329
+ * @param hot - dev only hot module replacement
37
330
  */
38
- (): Store<Id, S, G, A>;
331
+ (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>;
39
332
  /**
40
333
  * Id of the store. Used by map helpers.
41
334
  */
42
335
  $id: Id;
336
+ $getStore: () => Store<Id, S, G, A>;
43
337
  /**
44
- * Return to store for use within non-functional components
338
+ * Dev only pinia for HMR.
339
+ *
340
+ * @internal
45
341
  */
46
- $getStore: () => Store<Id, S, G, A>;
342
+ _pinia?: Pinia;
343
+ }
344
+ /**
345
+ * Interface to be extended by the user when they add properties through plugins.
346
+ */
347
+ interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {}
348
+ /**
349
+ * Properties that are added to every `store.$state` by `pinia.use()`.
350
+ */
351
+ interface PiniaCustomStateProperties<S extends StateTree = StateTree> {}
352
+ /**
353
+ * Type of an object of Getters that infers the argument. For internal usage only.
354
+ * For internal use **only**
355
+ */
356
+ type _GettersTree<S extends StateTree> = Record<string, ((state: UnwrapRef<S> & UnwrapRef<PiniaCustomStateProperties<S>>) => any) | (() => any)>;
357
+ /**
358
+ * Type of an object of Actions. For internal usage only.
359
+ * For internal use **only**
360
+ */
361
+ type _ActionsTree = Record<string, _Method>;
362
+ /**
363
+ * Type that enables refactoring through IDE.
364
+ * For internal use **only**
365
+ */
366
+ type _ExtractStateFromSetupStore_Keys<SS> = keyof { [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any };
367
+ /**
368
+ * Type that enables refactoring through IDE.
369
+ * For internal use **only**
370
+ */
371
+ type _ExtractActionsFromSetupStore_Keys<SS> = keyof { [K in keyof SS as SS[K] extends _Method ? K : never]: any };
372
+ /**
373
+ * Type that enables refactoring through IDE.
374
+ * For internal use **only**
375
+ */
376
+ type _ExtractGettersFromSetupStore_Keys<SS> = keyof { [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any };
377
+ /**
378
+ * Type that enables refactoring through IDE.
379
+ * For internal use **only**
380
+ */
381
+ type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> };
382
+ /**
383
+ * For internal use **only**
384
+ */
385
+ type _ExtractStateFromSetupStore<SS> = SS extends undefined | void ? {} : Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>;
386
+ /**
387
+ * For internal use **only**
388
+ */
389
+ type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void ? {} : Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>;
390
+ /**
391
+ * For internal use **only**
392
+ */
393
+ type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void ? {} : Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>;
394
+ /**
395
+ * Options passed to `defineStore()` that are common between option and setup
396
+ * stores. Extend this interface if you want to add custom options to both kinds
397
+ * of stores.
398
+ */
399
+ type DefineStoreOptionsBase<S extends StateTree, Store> = {};
400
+ /**
401
+ * Options parameter of `defineStore()` for option stores. Can be extended to
402
+ * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
403
+ */
404
+ interface DefineStoreOptions<Id extends string, S extends StateTree, G, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
405
+ /**
406
+ * Unique string key to identify the store across the application.
407
+ */
408
+ id: Id;
409
+ /**
410
+ * Function to create a fresh state. **Must be an arrow function** to ensure
411
+ * correct typings!
412
+ */
413
+ state?: () => S;
414
+ /**
415
+ * Optional object of getters.
416
+ */
417
+ getters?: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> & _GettersTree<S>;
418
+ /**
419
+ * Optional object of actions.
420
+ */
421
+ actions?: A & ThisType<A & UnwrapRef<S> & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>;
422
+ /**
423
+ * Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store
424
+ * definition and copying the value from `pinia.state` isn't enough.
425
+ *
426
+ * @example
427
+ * If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on
428
+ * Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local
429
+ * storage:
430
+ *
431
+ * ```ts
432
+ * const useStore = defineStore('main', {
433
+ * state: () => ({
434
+ * n: useLocalStorage('key', 0)
435
+ * }),
436
+ * hydrate(storeState, initialState) {
437
+ * // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
438
+ * storeState.n = useLocalStorage('key', 0)
439
+ * }
440
+ * })
441
+ * ```
442
+ *
443
+ * @param storeState - the current state in the store
444
+ * @param initialState - initialState
445
+ */
446
+ hydrate?(storeState: UnwrapRef<S>, initialState: UnwrapRef<S>): void;
47
447
  }
448
+ /**
449
+ * Options parameter of `defineStore()` for setup stores. Can be extended to
450
+ * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
451
+ */
452
+ interface DefineSetupStoreOptions<Id extends string, S extends StateTree, G, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
453
+ /**
454
+ * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when
455
+ * creating the store. Can be used in plugins to get the list of actions in a
456
+ * store defined with a setup function. Note this is always defined
457
+ */
458
+ actions?: A;
459
+ }
460
+ /**
461
+ * Available `options` when creating a pinia plugin.
462
+ */
463
+ interface DefineStoreOptionsInPlugin<Id extends string, S extends StateTree, G, A> extends Omit<DefineStoreOptions<Id, S, G, A>, 'id' | 'actions'> {
464
+ /**
465
+ * Extracted object of actions. Added by useStore() when the store is built
466
+ * using the setup API, otherwise uses the one passed to `defineStore()`.
467
+ * Defaults to an empty object if no actions are defined.
468
+ */
469
+ actions: A;
470
+ }
471
+ /**
472
+ * Utility type. For internal use **only**
473
+ */
474
+ //#endregion
475
+ //#region src/rootStore.d.ts
476
+ /**
477
+ * Get the currently active pinia if there is any.
478
+ */
479
+ declare const getActivePinia: () => Pinia | undefined;
480
+ /**
481
+ * Every application must own its own pinia to be able to create stores
482
+ */
483
+ interface Pinia {
484
+ /**
485
+ * root state
486
+ */
487
+ state: Ref<Record<string, StateTree>>;
488
+ /**
489
+ * Adds a store plugin to extend every store
490
+ *
491
+ * @param plugin - store plugin to add
492
+ */
493
+ use(plugin: PiniaPlugin): Pinia;
494
+ /**
495
+ * Installed store plugins
496
+ *
497
+ * @internal
498
+ */
499
+ _p: PiniaPlugin[];
500
+ /**
501
+ * Effect scope the pinia is attached to
502
+ *
503
+ * @internal
504
+ */
505
+ _e: EffectScope;
506
+ /**
507
+ * Registry of stores used by this pinia.
508
+ *
509
+ * @internal
510
+ */
511
+ _s: Map<string, StoreGeneric>;
512
+ /**
513
+ * Added by `createTestingPinia()` to bypass `useStore(pinia)`.
514
+ *
515
+ * @internal
516
+ */
517
+ _testing?: boolean;
518
+ }
519
+ declare function setActivePinia(_pinia: Pinia): void;
48
520
  type PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> = {
49
- options: DefineStoreOptions<Id, S, G, A>;
521
+ /**
522
+ * pinia instance.
523
+ */
524
+ pinia: Pinia;
525
+ /**
526
+ * Current store being extended.
527
+ */
50
528
  store: Store<Id, S, G, A>;
529
+ /**
530
+ * Initial options defining the store when calling `defineStore()`.
531
+ */
532
+ options: DefineStoreOptionsInPlugin<Id, S, G, A>;
51
533
  };
52
- type PiniaPlugin = (context: PiniaPluginContext) => Partial<PiniaCustomProperties & PiniaCustomStateProperties> | undefined;
53
- //#endregion
54
- //#region src/defineStore.d.ts
55
- declare function defineStore<Id extends string, S extends StateTree, G extends _GettersTree<S> = {}, A extends _ActionsTree = {}>(id: Id, options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>;
56
- //#endregion
57
- //#region src/pinia.d.ts
58
- interface Pinia {
59
- _store: Map<string, StoreGeneric>;
60
- _state: Map<string, StateTree>;
61
- _plugins: Set<PiniaPlugin>;
62
- use(plugin: PiniaPlugin): this;
534
+ /**
535
+ * Plugin to extend every store.
536
+ */
537
+ interface PiniaPlugin {
538
+ /**
539
+ * Plugin to extend every store. Returns an object to extend the store or
540
+ * nothing.
541
+ *
542
+ * @param context - Context
543
+ */
544
+ (context: PiniaPluginContext): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void;
63
545
  }
64
- declare let pinia: Pinia;
546
+ //#endregion
547
+ //#region src/createPinia.d.ts
548
+ /**
549
+ * Creates a Pinia instance to be used by the application
550
+ */
65
551
  declare function createPinia(): Pinia;
66
- declare function setActivePinia(_pinia: Pinia): void;
67
552
  //#endregion
68
- export { type DefineStoreOptionsBase, type PiniaCustomProperties, type PiniaCustomStateProperties, type PiniaPlugin, type PiniaPluginContext, type StateTree, type Store, createPinia, defineStore, pinia, setActivePinia };
553
+ //#region src/store.d.ts
554
+ /**
555
+ * Creates a `useStore` function that retrieves the store instance
556
+ *
557
+ * @param id - id of the store (must be unique)
558
+ * @param options - options to define the store
559
+ */
560
+ declare function defineStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(id: Id, options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>): StoreDefinition<Id, S, G, A>;
561
+ //#endregion
562
+ export { type DefineSetupStoreOptions, type DefineStoreOptions, type DefineStoreOptionsBase, type DefineStoreOptionsInPlugin, MutationType, type Pinia, type PiniaCustomProperties, type PiniaCustomStateProperties, type PiniaPlugin, type PiniaPluginContext, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type StoreOnActionListener, type StoreOnActionListenerContext, type StoreProperties, type SubscriptionCallback, type SubscriptionCallbackMutation, type SubscriptionCallbackMutationDirect, type SubscriptionCallbackMutationPatchFunction, type SubscriptionCallbackMutationPatchObject, type _ActionsTree, type _DeepPartial, type _ExtractActionsFromSetupStore, type _ExtractActionsFromSetupStore_Keys, type _ExtractGettersFromSetupStore, type _ExtractGettersFromSetupStore_Keys, type _ExtractStateFromSetupStore, type _ExtractStateFromSetupStore_Keys, type _GettersTree, type _Method, type _StoreOnActionListenerContext, type _StoreWithActions, type _StoreWithGetters, type _StoreWithState, type _SubscriptionCallbackMutationBase, type _UnwrapAll, createPinia, defineStore, getActivePinia, setActivePinia };
package/dist/index.js CHANGED
@@ -1,162 +1,6 @@
1
- import { ReactiveEffect, activeEffect, computed, isReactive, isRef, markRaw, reactive, toRefs, watch } from "@maoism/runtime-core";
2
- import { useCallback, useId, useRef, useSyncExternalStore } from "react";
3
- import { isFunction } from "savage-types";
4
- import "savage-utils";
5
-
6
- //#region src/pinia.ts
7
- let pinia;
8
- function createPinia() {
9
- return {
10
- _store: /* @__PURE__ */ new Map(),
11
- _state: /* @__PURE__ */ new Map(),
12
- _plugins: /* @__PURE__ */ new Set(),
13
- use(p) {
14
- this._plugins.add(p);
15
- return this;
16
- }
17
- };
18
- }
19
- function setActivePinia(_pinia) {
20
- pinia = _pinia;
21
- }
22
- setActivePinia(createPinia());
23
-
24
- //#endregion
25
- //#region src/utils.ts
26
- function noop() {
27
- return {};
28
- }
29
- function isPlainObject(o) {
30
- return o && typeof o === "object" && Object.prototype.toString.call(o) === "[object Object]" && typeof o.toJSON !== "function";
31
- }
32
- function mergeReactiveObjects(target, patchToApply) {
33
- if (target instanceof Map && patchToApply instanceof Map) patchToApply.forEach((value, key) => target.set(key, value));
34
- if (target instanceof Set && patchToApply instanceof Set) patchToApply.forEach(target.add, target);
35
- for (const key in patchToApply) {
36
- if (!Object.hasOwn(patchToApply, key)) continue;
37
- const subPatch = patchToApply[key];
38
- const targetValue = target[key];
39
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && target.hasOwnProperty(key) && !isRef(subPatch) && !isReactive(subPatch)) target[key] = mergeReactiveObjects(targetValue, subPatch);
40
- else target[key] = subPatch;
41
- }
42
- return target;
43
- }
44
-
45
- //#endregion
46
- //#region src/subscription.ts
47
- const subscriptions = /* @__PURE__ */ new Set();
48
- function addSubscriptions(callback, onCleanup = noop) {
49
- subscriptions.add(callback);
50
- const remove = () => {
51
- subscriptions.delete(callback);
52
- onCleanup();
53
- };
54
- return remove;
55
- }
56
- function triggerSubscription(state) {
57
- subscriptions.forEach((callback) => callback(state));
58
- }
59
-
60
- //#endregion
61
- //#region src/defineStore.ts
62
- let isLoadingPlugin = false;
63
- function defineStore(id, options) {
64
- let isSyncListening = false;
65
- function createStore() {
66
- const { state, actions, getters } = options;
67
- const $state = reactive(state ? state() : {});
68
- const initState = state ? state() : {};
69
- const baseStore = {
70
- $id: id,
71
- $state,
72
- $patch(val) {
73
- isSyncListening = false;
74
- if (isFunction(val)) val($state);
75
- else mergeReactiveObjects($state, val);
76
- isSyncListening = true;
77
- triggerSubscription($state);
78
- },
79
- $reset() {
80
- this.$patch((v) => {
81
- Object.assign(v, initState);
82
- });
83
- },
84
- $subscribe(cb) {
85
- const remove = addSubscriptions(cb, () => unwatch());
86
- const unwatch = watch($state, (state$1) => {
87
- if (isSyncListening) cb(state$1);
88
- }, {
89
- deep: true,
90
- flush: "sync"
91
- });
92
- return remove;
93
- }
94
- };
95
- pinia._state.set(id, $state);
96
- const store = reactive(Object.assign(baseStore, toRefs($state), Object.keys(actions ?? []).reduce((x, y) => Object.assign(x, { [y]: (...args) => actions[y].call(store, ...args) }), {}), Object.keys(getters || {}).reduce((computedGetters, name) => {
97
- computedGetters[name] = markRaw(computed(() => {
98
- return getters?.[name].call(store, store);
99
- }));
100
- return computedGetters;
101
- }, {})));
102
- const lastLoadingPlugin = isLoadingPlugin;
103
- isLoadingPlugin = true;
104
- pinia._plugins.forEach((p) => {
105
- Object.assign(store, p({
106
- store,
107
- options
108
- }) || {});
109
- });
110
- isLoadingPlugin = lastLoadingPlugin;
111
- pinia._store.set(id, store);
112
- }
113
- const effectMap = /* @__PURE__ */ new WeakMap();
114
- const subscribeMap = /* @__PURE__ */ new WeakMap();
115
- function useStore() {
116
- if (!pinia._store.has(id)) createStore();
117
- const store = pinia._store.get(id);
118
- isSyncListening = true;
119
- const _id = useRef([useId()]);
120
- const storeSnapshotRef = useRef({ ...store });
121
- const isCollectDep = useRef(false);
122
- const subscribe = useCallback((onStoreChange) => {
123
- subscribeMap.set(_id.current, onStoreChange);
124
- return () => {
125
- const effect$1 = effectMap.get(_id.current);
126
- if (effect$1) effect$1.stop();
127
- subscribeMap.delete(_id.current);
128
- effectMap.delete(_id.current);
129
- };
130
- }, []);
131
- useSyncExternalStore(subscribe, () => storeSnapshotRef.current, () => storeSnapshotRef.current);
132
- let effect = effectMap.get(_id.current);
133
- if (!effect) {
134
- const fn = () => {
135
- const onStoreChange = subscribeMap.get(_id.current);
136
- if (!isCollectDep.current) {
137
- storeSnapshotRef.current = { ...store };
138
- onStoreChange?.();
139
- }
140
- };
141
- effect = new ReactiveEffect(fn, noop, () => {
142
- if (effect?.dirty) effect.run();
143
- });
144
- activeEffect.value = effect;
145
- isCollectDep.current = true;
146
- effect.run();
147
- effectMap.set(_id.current, effect);
148
- isCollectDep.current = false;
149
- }
150
- return store;
151
- }
152
- useStore.$id = id;
153
- useStore.$getStore = () => {
154
- if (!pinia._store.has(id)) createStore();
155
- const store = pinia._store.get(id);
156
- return store;
157
- };
158
- return useStore;
159
- }
160
-
161
- //#endregion
162
- export { createPinia, defineStore, pinia, setActivePinia };
1
+ import{useCallback as e,useId as t,useRef as n,useSyncExternalStore as r}from"react";function i(e,t){let n=new Set(e.split(`,`));return t?e=>n.has(e.toLowerCase()):e=>n.has(e)}var a=Object.freeze({});Object.freeze([]);var o=()=>{},s=()=>!1,c=Object.assign,l=(e,t)=>{let n=e.indexOf(t);n>-1&&e.splice(n,1)},u=Object.prototype.hasOwnProperty,d=(e,t)=>u.call(e,t),f=Array.isArray,p=e=>b(e)===`[object Map]`,m=e=>b(e)===`[object Set]`,h=e=>typeof e==`function`,g=e=>typeof e==`string`,_=e=>typeof e==`symbol`,v=e=>typeof e==`object`&&!!e,y=e=>(v(e)||h(e))&&h(e.then)&&h(e.catch),ee=Object.prototype.toString,b=e=>ee.call(e),x=e=>b(e).slice(8,-1),S=e=>b(e)===`[object Object]`,C=e=>g(e)&&e!==`NaN`&&e[0]!==`-`&&``+parseInt(e,10)===e,w=e=>{let t=Object.create(null);return n=>{let r=t[n];return r||(t[n]=e(n))}},te=/-(\w)/g;w(e=>e.replace(te,(e,t)=>t?t.toUpperCase():``));var ne=/\B([A-Z])/g;w(e=>e.replace(ne,`-$1`).toLowerCase());var re=w(e=>e.charAt(0).toUpperCase()+e.slice(1)),ie=w(e=>{let t=e?`on${re(e)}`:``;return t}),T=(e,t)=>!Object.is(e,t),ae=(e,t,n)=>{Object.defineProperty(e,t,{configurable:!0,enumerable:!1,value:n})},oe,se=()=>oe||=typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{},ce=`itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;ce+``;function le(e,...t){console.warn(`[Vue warn] ${e}`,...t)}var E,ue=class{constructor(e=!1){this.detached=e,this._active=!0,this.effects=[],this.cleanups=[],this.parent=E,!e&&E&&(this.index=(E.scopes||=[]).push(this)-1)}get active(){return this._active}run(e){if(this._active){let t=E;try{return E=this,e()}finally{E=t}}else le(`cannot run an inactive effect scope.`)}on(){E=this}off(){E=this.parent}stop(e){if(this._active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t].stop();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(t=0,n=this.scopes.length;t<n;t++)this.scopes[t].stop(!0);if(!this.detached&&this.parent&&!e){let e=this.parent.scopes.pop();e&&e!==this&&(this.parent.scopes[this.index]=e,e.index=this.index)}this.parent=void 0,this._active=!1}}};function de(e){return new ue(e)}function fe(e,t=E){t&&t.active&&t.effects.push(e)}function pe(){return E}var D={value:void 0},me=class{constructor(e,t,n,r){this.fn=e,this.trigger=t,this.scheduler=n,this.active=!0,this.deps=[],this._dirtyLevel=2,this._trackId=0,this._runnings=0,this._shouldSchedule=!1,this._depsLength=0,fe(this,r)}get dirty(){if(this._dirtyLevel===1){xe();for(let e=0;e<this._depsLength;e++){let t=this.deps[e];if(t.computed&&(he(t.computed),this._dirtyLevel>=2))break}this._dirtyLevel<2&&(this._dirtyLevel=0),Se()}return this._dirtyLevel>=2}set dirty(e){this._dirtyLevel=e?2:0}run(){if(this._dirtyLevel=0,!this.active)return this.fn();let e=O,t=D.value;try{return O=!0,D.value=this,this._runnings++,ge(this),this.fn()}finally{_e(this),this._runnings--,D.value=t,O=e}}stop(){this.active&&(ge(this),_e(this),this.onStop?.(),this.active=!1)}};function he(e){return e.value}function ge(e){e._trackId++,e._depsLength=0}function _e(e){if(e.deps&&e.deps.length>e._depsLength){for(let t=e._depsLength;t<e.deps.length;t++)ve(e.deps[t],e);e.deps.length=e._depsLength}}function ve(e,t){let n=e.get(t);n!==void 0&&t._trackId!==n&&(e.delete(t),e.size===0&&e.cleanup())}var O=!0,ye=0,be=[];function xe(){be.push(O),O=!1}function Se(){let e=be.pop();O=e===void 0?!0:e}function Ce(){ye++}function we(){for(ye--;!ye&&Ee.length;)Ee.shift()()}function Te(e,t,n){if(t.get(e)!==e._trackId){t.set(e,e._trackId);let r=e.deps[e._depsLength];r===t?e._depsLength++:(r&&ve(r,e),e.deps[e._depsLength++]=t),e.onTrack?.(c({effect:e},n))}}var Ee=[];function De(e,t,n){Ce();for(let r of e.keys()){if(e.get(r)!==r._trackId)continue;if(r._dirtyLevel<t){let e=r._dirtyLevel;r._dirtyLevel=t,e===0&&(r._shouldSchedule=!0,r.onTrigger?.(c({effect:r},n)),r.trigger())}r.scheduler&&r._shouldSchedule&&(!r._runnings||r.allowRecurse)&&(r._shouldSchedule=!1,Ee.push(r.scheduler))}we()}var Oe=(e,t)=>{let n=new Map;return n.cleanup=e,n.computed=t,n},ke=new WeakMap,k=Symbol(`iterate`),Ae=Symbol(`Map key iterate`);function A(e,t,n){if(O&&D.value){let r=ke.get(e);r||ke.set(e,r=new Map);let i=r.get(n);i||r.set(n,i=Oe(()=>r.delete(n))),Te(D.value,i,{target:e,type:t,key:n})}}function j(e,t,n,r,i,a){let o=ke.get(e);if(!o)return;let s=[];if(t===`clear`)s=[...o.values()];else if(n===`length`&&f(e)){let e=Number(r);o.forEach((t,n)=>{(n===`length`||!_(n)&&n>=e)&&s.push(t)})}else switch(n!==void 0&&s.push(o.get(n)),t){case`add`:f(e)?C(n)&&s.push(o.get(`length`)):(s.push(o.get(k)),p(e)&&s.push(o.get(Ae)));break;case`delete`:f(e)||(s.push(o.get(k)),p(e)&&s.push(o.get(Ae)));break;case`set`:p(e)&&s.push(o.get(k));break}Ce();for(let o of s)o&&De(o,2,{target:e,type:t,key:n,newValue:r,oldValue:i,oldTarget:a});we()}function je(e,t){return ke.get(e)?.get(t)}var Me=i(`__proto__,__v_isRef,__isVue`),Ne=new Set(Object.getOwnPropertyNames(Symbol).filter(e=>e!==`arguments`&&e!==`caller`).map(e=>Symbol[e]).filter(_)),Pe=Fe();function Fe(){let e={};return[`includes`,`indexOf`,`lastIndexOf`].forEach(t=>{e[t]=function(...e){let n=F(this);for(let e=0,t=this.length;e<t;e++)A(n,`get`,e+``);let r=n[t](...e);return r===-1||r===!1?n[t](...e.map(F)):r}}),[`push`,`pop`,`shift`,`unshift`,`splice`].forEach(t=>{e[t]=function(...e){xe(),Ce();let n=F(this)[t].apply(this,e);return we(),Se(),n}}),e}function Ie(e){let t=F(this);return A(t,`has`,e),t.hasOwnProperty(e)}var Le=class{constructor(e=!1,t=!1){this._isReadonly=e,this._shallow=t}get(e,t,n){let r=this._isReadonly,i=this._shallow;if(t===`__v_isReactive`)return!r;if(t===`__v_isReadonly`)return r;if(t===`__v_isShallow`)return i;if(t===`__v_raw`)return n===(r?i?pt:ft:i?dt:ut).get(e)||Object.getPrototypeOf(e)===Object.getPrototypeOf(n)?e:void 0;let a=f(e);if(!r){if(a&&d(Pe,t))return Reflect.get(Pe,t,n);if(t===`hasOwnProperty`)return Ie}let o=Reflect.get(e,t,n);return(_(t)?Ne.has(t):Me(t))||(r||A(e,`get`,t),i)?o:L(o)?a&&C(t)?o:o.value:v(o)?r?_t(o):gt(o):o}},Re=class extends Le{constructor(e=!1){super(!1,e)}set(e,t,n,r){let i=e[t];if(!this._shallow){let t=P(i);if(!bt(n)&&!P(n)&&(i=F(i),n=F(n)),!f(e)&&L(i)&&!L(n))return t?!1:(i.value=n,!0)}let a=f(e)&&C(t)?Number(t)<e.length:d(e,t),o=Reflect.set(e,t,n,r);return e===F(r)&&(a?T(n,i)&&j(e,`set`,t,n,i):j(e,`add`,t,n)),o}deleteProperty(e,t){let n=d(e,t),r=e[t],i=Reflect.deleteProperty(e,t);return i&&n&&j(e,`delete`,t,void 0,r),i}has(e,t){let n=Reflect.has(e,t);return(!_(t)||!Ne.has(t))&&A(e,`has`,t),n}ownKeys(e){return A(e,`iterate`,f(e)?`length`:k),Reflect.ownKeys(e)}},ze=class extends Le{constructor(e=!1){super(!0,e)}set(e,t){return le(`Set operation on key "${String(t)}" failed: target is readonly.`,e),!0}deleteProperty(e,t){return le(`Delete operation on key "${String(t)}" failed: target is readonly.`,e),!0}},Be=new Re,Ve=new ze,He=new ze(!0),Ue=e=>e,We=e=>Reflect.getPrototypeOf(e);function Ge(e,t,n=!1,r=!1){e=e.__v_raw;let i=F(e),a=F(t);n||(T(t,a)&&A(i,`get`,t),A(i,`get`,a));let{has:o}=We(i),s=r?Ue:n?Ct:I;if(o.call(i,t))return s(e.get(t));if(o.call(i,a))return s(e.get(a));e!==i&&e.get(t)}function Ke(e,t=!1){let n=this.__v_raw,r=F(n),i=F(e);return t||(T(e,i)&&A(r,`has`,e),A(r,`has`,i)),e===i?n.has(e):n.has(e)||n.has(i)}function qe(e,t=!1){return e=e.__v_raw,!t&&A(F(e),`iterate`,k),Reflect.get(e,`size`,e)}function Je(e){e=F(e);let t=F(this),n=We(t),r=n.has.call(t,e);return r||(t.add(e),j(t,`add`,e,e)),this}function Ye(e,t){t=F(t);let n=F(this),{has:r,get:i}=We(n),a=r.call(n,e);a?lt(n,r,e):(e=F(e),a=r.call(n,e));let o=i.call(n,e);return n.set(e,t),a?T(t,o)&&j(n,`set`,e,t,o):j(n,`add`,e,t),this}function Xe(e){let t=F(this),{has:n,get:r}=We(t),i=n.call(t,e);i?lt(t,n,e):(e=F(e),i=n.call(t,e));let a=r?r.call(t,e):void 0,o=t.delete(e);return i&&j(t,`delete`,e,void 0,a),o}function Ze(){let e=F(this),t=e.size!==0,n=p(e)?new Map(e):new Set(e),r=e.clear();return t&&j(e,`clear`,void 0,void 0,n),r}function Qe(e,t){return function(n,r){let i=this,a=i.__v_raw,o=F(a),s=t?Ue:e?Ct:I;return!e&&A(o,`iterate`,k),a.forEach((e,t)=>n.call(r,s(e),s(t),i))}}function $e(e,t,n){return function(...r){let i=this.__v_raw,a=F(i),o=p(a),s=e===`entries`||e===Symbol.iterator&&o,c=e===`keys`&&o,l=i[e](...r),u=n?Ue:t?Ct:I;return!t&&A(a,`iterate`,c?Ae:k),{next(){let{value:e,done:t}=l.next();return t?{value:e,done:t}:{value:s?[u(e[0]),u(e[1])]:u(e),done:t}},[Symbol.iterator](){return this}}}}function M(e){return function(...t){{let n=t[0]?`on key "${t[0]}" `:``;console.warn(`${re(e)} operation ${n}failed: target is readonly.`,F(this))}return e===`delete`?!1:e===`clear`?void 0:this}}function et(){let e={get(e){return Ge(this,e)},get size(){return qe(this)},has:Ke,add:Je,set:Ye,delete:Xe,clear:Ze,forEach:Qe(!1,!1)},t={get(e){return Ge(this,e,!1,!0)},get size(){return qe(this)},has:Ke,add:Je,set:Ye,delete:Xe,clear:Ze,forEach:Qe(!1,!0)},n={get(e){return Ge(this,e,!0)},get size(){return qe(this,!0)},has(e){return Ke.call(this,e,!0)},add:M(`add`),set:M(`set`),delete:M(`delete`),clear:M(`clear`),forEach:Qe(!0,!1)},r={get(e){return Ge(this,e,!0,!0)},get size(){return qe(this,!0)},has(e){return Ke.call(this,e,!0)},add:M(`add`),set:M(`set`),delete:M(`delete`),clear:M(`clear`),forEach:Qe(!0,!0)},i=[`keys`,`values`,`entries`,Symbol.iterator];return i.forEach(i=>{e[i]=$e(i,!1,!1),n[i]=$e(i,!0,!1),t[i]=$e(i,!1,!0),r[i]=$e(i,!0,!0)}),[e,n,t,r]}var[tt,nt,rt,it]=et();function at(e,t){let n=t?e?it:rt:e?nt:tt;return(t,r,i)=>r===`__v_isReactive`?!e:r===`__v_isReadonly`?e:r===`__v_raw`?t:Reflect.get(d(n,r)&&r in t?n:t,r,i)}var ot={get:at(!1,!1)},st={get:at(!0,!1)},ct={get:at(!0,!0)};function lt(e,t,n){let r=F(n);if(r!==n&&t.call(e,r)){let t=x(e);console.warn(`Reactive ${t} contains both the raw and reactive versions of the same object${t===`Map`?` as keys`:``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`)}}var ut=new WeakMap,dt=new WeakMap,ft=new WeakMap,pt=new WeakMap;function mt(e){switch(e){case`Object`:case`Array`:return 1;case`Map`:case`Set`:case`WeakMap`:case`WeakSet`:return 2;default:return 0}}function ht(e){return e.__v_skip||!Object.isExtensible(e)?0:mt(x(e))}function gt(e){return P(e)?e:yt(e,!1,Be,ot,ut)}function _t(e){return yt(e,!0,Ve,st,ft)}function vt(e){return yt(e,!0,He,ct,pt)}function yt(e,t,n,r,i){if(!v(e))return console.warn(`value cannot be made reactive: ${String(e)}`),e;if(e.__v_raw&&!(t&&e.__v_isReactive))return e;let a=i.get(e);if(a)return a;let o=ht(e);if(o===0)return e;let s=new Proxy(e,o===2?r:n);return i.set(e,s),s}function N(e){return P(e)?N(e.__v_raw):!!(e&&e.__v_isReactive)}function P(e){return!!(e&&e.__v_isReadonly)}function bt(e){return!!(e&&e.__v_isShallow)}function xt(e){return N(e)||P(e)}function F(e){let t=e&&e.__v_raw;return t?F(t):e}function St(e){return ae(e,`__v_skip`,!0),e}var I=e=>v(e)?gt(e):e,Ct=e=>v(e)?_t(e):e,wt,Tt=class{constructor(e,t,n,r){this._setter=t,this.dep=void 0,this.__v_isRef=!0,this[wt]=!1,this.effect=new me(()=>e(this._value),()=>Ot(this,1)),this.effect.computed=this,this.effect.active=this._cacheable=!r,this.__v_isReadonly=n}static{wt=`__v_isReadonly`}get value(){let e=F(this);return(!e._cacheable||e.effect.dirty)&&T(e._value,e._value=e.effect.run())&&Ot(e,2),Dt(e),e._value}set value(e){this._setter(e)}get _dirty(){return this.effect.dirty}set _dirty(e){this.effect.dirty=e}};function Et(e,t,n=!1){let r,i,a=h(e);a?(r=e,i=()=>{console.warn(`Write operation failed: computed value is readonly`)}):(r=e.get,i=e.set);let o=new Tt(r,i,a||!i,n);return t&&!n&&(o.effect.onTrack=t.onTrack,o.effect.onTrigger=t.onTrigger),o}function Dt(e){O&&D.value&&(e=F(e),Te(D.value,e.dep||=Oe(()=>e.dep=void 0,e instanceof Tt?e:void 0),{target:e,type:`get`,key:`value`}))}function Ot(e,t=2,n){e=F(e);let r=e.dep;r&&De(r,t,{target:e,type:`set`,key:`value`,newValue:n})}function L(e){return!!(e&&e.__v_isRef===!0)}function kt(e){return At(e,!1)}function At(e,t){return L(e)?e:new jt(e,t)}var jt=class{constructor(e,t){this.__v_isShallow=t,this.dep=void 0,this.__v_isRef=!0,this._rawValue=t?e:F(e),this._value=t?e:I(e)}get value(){return Dt(this),this._value}set value(e){let t=this.__v_isShallow||bt(e)||P(e);e=t?e:F(e),T(e,this._rawValue)&&(this._rawValue=e,this._value=t?e:I(e),Ot(this,2,e))}};function Mt(e){return L(e)?e.value:e}var Nt={get:(e,t,n)=>Mt(Reflect.get(e,t,n)),set:(e,t,n,r)=>{let i=e[t];return L(i)&&!L(n)?(i.value=n,!0):Reflect.set(e,t,n,r)}};function Pt(e){return N(e)?e:new Proxy(e,Nt)}function Ft(e){xt(e)||console.warn(`toRefs() expects a reactive object but received a plain one.`);let t=f(e)?Array(e.length):{};for(let n in e)t[n]=Lt(e,n);return t}var It=class{constructor(e,t,n){this._object=e,this._key=t,this._defaultValue=n,this.__v_isRef=!0}get value(){let e=this._object[this._key];return e===void 0?this._defaultValue:e}set value(e){this._object[this._key]=e}get dep(){return je(F(this._object),this._key)}};function Lt(e,t,n){let r=e[t];return L(r)?r:new It(e,t,n)}var R=[];function Rt(e){R.push(e)}function zt(){R.pop()}function z(e,...t){xe();let n=R.length?R[R.length-1].component:null,r=n&&n.appContext.config.warnHandler,i=Bt();if(r)B(r,n,11,[e+t.join(``),n&&n.proxy,i.map(({vnode:e})=>`at <${or(n,e.type)}>`).join(`
2
+ `),i]);else{let n=[`[Vue warn]: ${e}`,...t];i.length&&n.push(`
3
+ `,...Vt(i)),console.warn(...n)}Se()}function Bt(){let e=R[R.length-1];if(!e)return[];let t=[];for(;e;){let n=t[0];n&&n.vnode===e?n.recurseCount++:t.push({vnode:e,recurseCount:0});let r=e.component&&e.component.parent;e=r&&r.vnode}return t}function Vt(e){let t=[];return e.forEach((e,n)=>{t.push(...n===0?[]:[`
4
+ `],...Ht(e))}),t}function Ht({vnode:e,recurseCount:t}){let n=t>0?`... (${t} recursive calls)`:``,r=e.component?e.component.parent==null:!1,i=` at <${or(e.component,e.type,r)}`,a=`>`+n;return e.props?[i,...Ut(e.props),a]:[i+a]}function Ut(e){let t=[],n=Object.keys(e);return n.slice(0,3).forEach(n=>{t.push(...Wt(n,e[n]))}),n.length>3&&t.push(` ...`),t}function Wt(e,t,n){return g(t)?(t=JSON.stringify(t),n?t:[`${e}=${t}`]):typeof t==`number`||typeof t==`boolean`||t==null?n?t:[`${e}=${t}`]:L(t)?(t=Wt(e,F(t.value),!0),n?t:[`${e}=Ref<`,t,`>`]):h(t)?[`${e}=fn${t.name?`<${t.name}>`:``}`]:(t=F(t),n?t:[`${e}=`,t])}var Gt={sp:`serverPrefetch hook`,bc:`beforeCreate hook`,c:`created hook`,bm:`beforeMount hook`,m:`mounted hook`,bu:`beforeUpdate hook`,u:`updated`,bum:`beforeUnmount hook`,um:`unmounted hook`,a:`activated hook`,da:`deactivated hook`,ec:`errorCaptured hook`,rtc:`renderTracked hook`,rtg:`renderTriggered hook`,0:`setup function`,1:`render function`,2:`watcher getter`,3:`watcher callback`,4:`watcher cleanup function`,5:`native event handler`,6:`component event handler`,7:`vnode hook`,8:`directive hook`,9:`transition hook`,10:`app errorHandler`,11:`app warnHandler`,12:`ref function`,13:`async component loader`,14:`scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core .`};function B(e,t,n,r){let i;try{i=r?e(...r):e()}catch(e){Kt(e,t,n)}return i}function V(e,t,n,r){if(h(e)){let i=B(e,t,n,r);return i&&y(i)&&i.catch(e=>{Kt(e,t,n)}),i}let i=[];for(let a=0;a<e.length;a++)i.push(V(e[a],t,n,r));return i}function Kt(e,t,n,r=!0){let i=t?t.vnode:null;if(t){let r=t.parent,i=t.proxy,a=Gt[n];for(;r;){let t=r.ec;if(t){for(let n=0;n<t.length;n++)if(t[n](e,i,a)===!1)return}r=r.parent}let o=t.appContext.config.errorHandler;if(o){B(o,null,10,[e,i,a]);return}}qt(e,n,i,r)}function qt(e,t,n,r=!0){{let i=Gt[t];if(n&&Rt(n),z(`Unhandled error${i?` during execution of ${i}`:``}`),n&&zt(),r)throw e;console.error(e)}}var Jt=!1,Yt=!1,H=[],U=0,W=[],G=null,K=0,Xt=Promise.resolve(),Zt=null,Qt=100;function $t(e){let t=Zt||Xt;return e?t.then(this?e.bind(this):e):t}function en(e){let t=U+1,n=H.length;for(;t<n;){let r=t+n>>>1,i=H[r],a=on(i);a<e||a===e&&i.pre?t=r+1:n=r}return t}function tn(e){(!H.length||!H.includes(e,Jt&&e.allowRecurse?U+1:U))&&(e.id==null?H.push(e):H.splice(en(e.id),0,e),nn())}function nn(){!Jt&&!Yt&&(Yt=!0,Zt=Xt.then(cn))}function rn(e){f(e)?W.push(...e):(!G||!G.includes(e,e.allowRecurse?K+1:K))&&W.push(e),nn()}function an(e){if(W.length){let t=[...new Set(W)].sort((e,t)=>on(e)-on(t));if(W.length=0,G){G.push(...t);return}for(G=t,e||=new Map,K=0;K<G.length;K++)ln(e,G[K])||G[K]();G=null,K=0}}var on=e=>e.id==null?1/0:e.id,sn=(e,t)=>{let n=on(e)-on(t);if(n===0){if(e.pre&&!t.pre)return-1;if(t.pre&&!e.pre)return 1}return n};function cn(e){Yt=!1,Jt=!0,e||=new Map,H.sort(sn);let t=t=>ln(e,t);try{for(U=0;U<H.length;U++){let e=H[U];if(e&&e.active!==!1){if(t(e))continue;B(e,null,14)}}}finally{U=0,H.length=0,an(e),Jt=!1,Zt=null,(H.length||W.length)&&cn(e)}}function ln(e,t){if(!e.has(t))e.set(t,1);else{let n=e.get(t);if(n>Qt){let e=t.ownerInstance,n=e&&ar(e.type);return Kt(`Maximum recursive updates exceeded${n?` in component <${n}>`:``}. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.`,null,10),!0}else e.set(t,n+1)}}var un=!1,dn=new Set;se().__VUE_HMR_RUNTIME__={createRecord:vn(pn),rerender:vn(hn),reload:vn(gn)};var fn=new Map;function pn(e,t){return fn.has(e)?!1:(fn.set(e,{initialDef:mn(t),instances:new Set}),!0)}function mn(e){return sr(e)?e.__vccOpts:e}function hn(e,t){let n=fn.get(e);n&&(n.initialDef.render=t,[...n.instances].forEach(e=>{t&&(e.render=t,mn(e.type).render=t),e.renderCache=[],un=!0,e.effect.dirty=!0,e.update(),un=!1}))}function gn(e,t){let n=fn.get(e);if(!n)return;t=mn(t),_n(n.initialDef,t);let r=[...n.instances];for(let e of r){let r=mn(e.type);dn.has(r)||(r!==n.initialDef&&_n(r,t),dn.add(r)),e.appContext.propsCache.delete(e.type),e.appContext.emitsCache.delete(e.type),e.appContext.optionsCache.delete(e.type),e.ceReload?(dn.add(r),e.ceReload(t.styles),dn.delete(r)):e.parent?(e.parent.effect.dirty=!0,tn(e.parent.update)):e.appContext.reload?e.appContext.reload():typeof window<`u`?window.location.reload():console.warn(`[HMR] Root or manually mounted instance modified. Full reload required.`)}rn(()=>{for(let e of r)dn.delete(mn(e.type))})}function _n(e,t){for(let n in c(e,t),e)n!==`__file`&&!(n in t)&&delete e[n]}function vn(e){return(t,n)=>{try{return e(t,n)}catch(e){console.error(e),console.warn(`[HMR] Something went wrong during Vue component hot-reload. Full reload required.`)}}}var yn=null,bn=!1;function xn(){bn=!0}var Sn=Symbol.for(`v-scx`),Cn=()=>{{let e=Jn(Sn);return e||z(`Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.`),e}},wn={};function Tn(e,t,n){return h(t)||z("`watch(fn, options?)` signature has been moved to a separate API. Use `watchEffect(fn, options?)` instead. `watch` now only supports `watch(source, cb, options?) signature."),En(e,t,n)}function En(e,t,{immediate:n,deep:r,flush:i,once:s,onTrack:c,onTrigger:u}=a){if(t&&s){let e=t;t=(...t)=>{e(...t),ne()}}r!==void 0&&typeof r==`number`&&z(`watch() "deep" option with number value will be used as watch depth in future versions. Please use a boolean instead to avoid potential breakage.`),t||(n!==void 0&&z(`watch() "immediate" option is only respected when using the watch(source, callback, options?) signature.`),r!==void 0&&z(`watch() "deep" option is only respected when using the watch(source, callback, options?) signature.`),s!==void 0&&z(`watch() "once" option is only respected when using the watch(source, callback, options?) signature.`));let d=e=>{z(`Invalid watch source: `,e,`A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`)},p=X,m=e=>r===!0?e:q(e,r===!1?1:void 0),g,_=!1,v=!1;if(L(e)?(g=()=>e.value,_=bt(e)):N(e)?(g=()=>m(e),_=!0):f(e)?(v=!0,_=e.some(e=>N(e)||bt(e)),g=()=>e.map(e=>{if(L(e))return e.value;if(N(e))return m(e);if(h(e))return B(e,p,2);d(e)})):h(e)?g=t?()=>B(e,p,2):()=>(y&&y(),V(e,p,3,[ee])):(g=o,d(e)),t&&r){let e=g;g=()=>q(e())}let y,ee=e=>{y=w.onStop=()=>{B(e,p,4),y=w.onStop=void 0}},b;if(tr)if(ee=o,t?n&&V(t,p,3,[g(),v?[]:void 0,ee]):g(),i===`sync`){let e=Cn();b=e.__watcherHandles||=[]}else return o;let x=v?Array(e.length).fill(wn):wn,S=()=>{if(!(!w.active||!w.dirty))if(t){let e=w.run();(r||_||(v?e.some((e,t)=>T(e,x[t])):T(e,x)))&&(y&&y(),V(t,p,3,[e,x===wn?void 0:v&&x[0]===wn?[]:x,ee]),x=e)}else w.run()};S.allowRecurse=!!t;let C;i===`sync`?C=S:i===`post`?C=()=>Yn(S,p&&p.suspense):(S.pre=!0,p&&(S.id=p.uid),C=()=>tn(S));let w=new me(g,o,C),te=pe(),ne=()=>{w.stop(),te&&l(te.effects,w)};return w.onTrack=c,w.onTrigger=u,t?n?S():x=w.run():i===`post`?Yn(w.run.bind(w),p&&p.suspense):w.run(),b&&b.push(ne),ne}function Dn(e,t,n){let r=this.proxy,i=g(e)?e.includes(`.`)?On(r,e):()=>r[e]:e.bind(r,r),a;h(t)?a=t:(a=t.handler,n=t);let o=$n(this),s=En(i,a.bind(r),n);return o(),s}function On(e,t){let n=t.split(`.`);return()=>{let t=e;for(let e=0;e<n.length&&t;e++)t=t[n[e]];return t}}function q(e,t,n=0,r){if(!v(e)||e.__v_skip)return e;if(t&&t>0){if(n>=t)return e;n++}if(r||=new Set,r.has(e))return e;if(r.add(e),L(e))q(e.value,t,n,r);else if(f(e))for(let i=0;i<e.length;i++)q(e[i],t,n,r);else if(m(e)||p(e))e.forEach(e=>{q(e,t,n,r)});else if(S(e))for(let i in e)q(e[i],t,n,r);return e}Symbol(`_leaveCb`),Symbol(`_enterCb`);function kn(e,t,n=X,r=!1){if(n){let i=n[e]||(n[e]=[]),a=t.__weh||=(...r)=>{if(n.isUnmounted)return;xe();let i=$n(n),a=V(t,n,e,r);return i(),Se(),a};return r?i.unshift(a):i.push(a),a}else{let t=ie(Gt[e].replace(/ hook$/,``));z(`${t} is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.`)}}var J=e=>(t,n=X)=>(!tr||e===`sp`)&&kn(e,(...e)=>t(...e),n);J(`bm`),J(`m`),J(`bu`),J(`u`),J(`bum`),J(`um`),J(`sp`),J(`rtg`),J(`rtc`),Symbol.for(`v-ndc`);var An=e=>e?er(e)?nr(e)||e.proxy:An(e.parent):null,jn=c(Object.create(null),{$:e=>e,$el:e=>e.vnode.el,$data:e=>e.data,$props:e=>vt(e.props),$attrs:e=>vt(e.attrs),$slots:e=>vt(e.slots),$refs:e=>vt(e.refs),$parent:e=>An(e.parent),$root:e=>An(e.root),$emit:e=>e.emit,$options:e=>Ln(e),$forceUpdate:e=>e.f||=()=>{e.effect.dirty=!0,tn(e.update)},$nextTick:e=>e.n||=$t.bind(e.proxy),$watch:e=>Dn.bind(e)}),Mn=e=>e===`_`||e===`$`,Nn=(e,t)=>e!==a&&!e.__isScriptSetup&&d(e,t),Pn={get({_:e},t){let{ctx:n,setupState:r,data:i,props:o,accessCache:s,type:c,appContext:l}=e;if(t===`__isVue`)return!0;let u;if(t[0]!==`$`){let c=s[t];if(c!==void 0)switch(c){case 1:return r[t];case 2:return i[t];case 4:return n[t];case 3:return o[t]}else if(Nn(r,t))return s[t]=1,r[t];else if(i!==a&&d(i,t))return s[t]=2,i[t];else if((u=e.propsOptions[0])&&d(u,t))return s[t]=3,o[t];else if(n!==a&&d(n,t))return s[t]=4,n[t];else In&&(s[t]=0)}let f=jn[t],p,m;if(f)return t===`$attrs`?(A(e,`get`,t),xn()):t===`$slots`&&A(e,`get`,t),f(e);if((p=c.__cssModules)&&(p=p[t]))return p;if(n!==a&&d(n,t))return s[t]=4,n[t];if(m=l.config.globalProperties,d(m,t))return m[t];yn&&(!g(t)||t.indexOf(`__v`)!==0)&&(i!==a&&Mn(t[0])&&d(i,t)?z(`Property ${JSON.stringify(t)} must be accessed via $data because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`):e===yn&&z(`Property ${JSON.stringify(t)} was accessed during render but is not defined on instance.`))},set({_:e},t,n){let{data:r,setupState:i,ctx:o}=e;return Nn(i,t)?(i[t]=n,!0):i.__isScriptSetup&&d(i,t)?(z(`Cannot mutate <script setup> binding "${t}" from Options API.`),!1):r!==a&&d(r,t)?(r[t]=n,!0):d(e.props,t)?(z(`Attempting to mutate prop "${t}". Props are readonly.`),!1):t[0]===`$`&&t.slice(1)in e?(z(`Attempting to mutate public property "${t}". Properties starting with $ are reserved and readonly.`),!1):(t in e.appContext.config.globalProperties?Object.defineProperty(o,t,{enumerable:!0,configurable:!0,value:n}):o[t]=n,!0)},has({_:{data:e,setupState:t,accessCache:n,ctx:r,appContext:i,propsOptions:o}},s){let c;return!!n[s]||e!==a&&d(e,s)||Nn(t,s)||(c=o[0])&&d(c,s)||d(r,s)||d(jn,s)||d(i.config.globalProperties,s)},defineProperty(e,t,n){return n.get==null?d(n,`value`)&&this.set(e,t,n.value,null):e._.accessCache[t]=0,Reflect.defineProperty(e,t,n)}};Pn.ownKeys=e=>(z(`Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead.`),Reflect.ownKeys(e));function Fn(e){return f(e)?e.reduce((e,t)=>(e[t]=null,e),{}):e}var In=!0;function Ln(e){let t=e.type,{mixins:n,extends:r}=t,{mixins:i,optionsCache:a,config:{optionMergeStrategies:o}}=e.appContext,s=a.get(t),c;return s?c=s:!i.length&&!n&&!r?c=t:(c={},i.length&&i.forEach(e=>Rn(c,e,o,!0)),Rn(c,t,o)),v(t)&&a.set(t,c),c}function Rn(e,t,n,r=!1){let{mixins:i,extends:a}=t;for(let o in a&&Rn(e,a,n,!0),i&&i.forEach(t=>Rn(e,t,n,!0)),t)if(r&&o===`expose`)z(`"expose" option is ignored when declared in mixins or extends. It should only be declared in the base component itself.`);else{let r=zn[o]||n&&n[o];e[o]=r?r(e[o],t[o]):t[o]}return e}var zn={data:Bn,props:Wn,emits:Wn,methods:Un,computed:Un,beforeCreate:Y,created:Y,beforeMount:Y,mounted:Y,beforeUpdate:Y,updated:Y,beforeDestroy:Y,beforeUnmount:Y,destroyed:Y,unmounted:Y,activated:Y,deactivated:Y,errorCaptured:Y,serverPrefetch:Y,components:Un,directives:Un,watch:Gn,provide:Bn,inject:Vn};function Bn(e,t){return t?e?function(){return c(h(e)?e.call(this,this):e,h(t)?t.call(this,this):t)}:t:e}function Vn(e,t){return Un(Hn(e),Hn(t))}function Hn(e){if(f(e)){let t={};for(let n=0;n<e.length;n++)t[e[n]]=e[n];return t}return e}function Y(e,t){return e?[...new Set([].concat(e,t))]:t}function Un(e,t){return e?c(Object.create(null),e,t):t}function Wn(e,t){return e?f(e)&&f(t)?[...new Set([...e,...t])]:c(Object.create(null),Fn(e),Fn(t??{})):t}function Gn(e,t){if(!e)return t;if(!t)return e;let n=c(Object.create(null),e);for(let r in t)n[r]=Y(e[r],t[r]);return n}function Kn(){return{app:null,config:{isNativeTag:s,performance:!1,globalProperties:{},optionMergeStrategies:{},errorHandler:void 0,warnHandler:void 0,compilerOptions:{}},mixins:[],components:{},directives:{},provides:Object.create(null),optionsCache:new WeakMap,propsCache:new WeakMap,emitsCache:new WeakMap}}var qn=null;function Jn(e,t,n=!1){let r=X||yn;if(r||qn){let i=r?r.parent==null?r.vnode.appContext&&r.vnode.appContext.provides:r.parent.provides:qn._context.provides;if(i&&e in i)return i[e];if(arguments.length>1)return n&&h(t)?t.call(r&&r.proxy):t;z(`injection "${String(e)}" not found.`)}else z(`inject() can only be used inside setup() or functional components.`)}var Yn=Xn;function Xn(e,t){t&&t.pendingBranch?f(e)?t.effects.push(...e):t.effects.push(e):rn(e)}Symbol.for(`v-fgt`),Symbol.for(`v-txt`),Symbol.for(`v-cmt`),Symbol.for(`v-stc`),Kn();var X=null,Zn,Qn;{let e=se(),t=(t,n)=>{let r;return(r=e[t])||(r=e[t]=[]),r.push(n),e=>{r.length>1?r.forEach(t=>t(e)):r[0](e)}};Zn=t(`__VUE_INSTANCE_SETTERS__`,e=>X=e),Qn=t(`__VUE_SSR_SETTERS__`,e=>tr=e)}var $n=e=>{let t=X;return Zn(e),e.scope.on(),()=>{e.scope.off(),Zn(t)}};function er(e){return e.vnode.shapeFlag&4}var tr=!1;function nr(e){if(e.exposed)return e.exposeProxy||=new Proxy(Pt(St(e.exposed)),{get(t,n){if(n in t)return t[n];if(n in jn)return jn[n](e)},has(e,t){return t in e||t in jn}})}var rr=/(?:^|[-_])(\w)/g,ir=e=>e.replace(rr,e=>e.toUpperCase()).replace(/[-_]/g,``);function ar(e,t=!0){return h(e)?e.displayName||e.name:e.name||t&&e.__name}function or(e,t,n=!1){let r=ar(t);if(!r&&t.__file){let e=t.__file.match(/([^/\\]+)\.\w+$/);e&&(r=e[1])}if(!r&&e&&e.parent){let n=e=>{for(let n in e)if(e[n]===t)return n};r=n(e.components||e.parent.type.components)||n(e.appContext.components)}return r?ir(r):n?`App`:`Anonymous`}function sr(e){return h(e)&&`__vccOpts`in e}var cr=(e,t)=>Et(e,t,tr);
5
+ /*! #__NO_SIDE_EFFECTS__ */
6
+ const lr=()=>ur;let ur;function Z(e){ur=e}function dr(){let e=de(!0),t=e.run(()=>kt({})),n=[],r=St({use(e){return n.push(e),this},_p:n,_e:e,_s:new Map,state:t});return Z(r),r}const fr=()=>{};function pr(e,t,n,r=fr){e.add(t);let i=()=>{e.delete(t),r()};return i}function Q(e,...t){e.forEach(e=>{e(...t)})}let mr=function(e){return e.direct=`direct`,e.patchObject=`patch object`,e.patchFunction=`patch function`,e}({});function hr(e){return Object.prototype.toString.call(e).slice(8,-1)===`Array`}function gr(e){return Object.prototype.toString.call(e).slice(8,-1)===`Object`}function _r(e){return Object.prototype.toString.call(e).slice(8,-1)===`Null`}var vr=class{constructor(e={}){return this.subscribeList={},this.pubAndNoSub={},Object.assign(this,e)}subscribe(e,t){var n;this.pubAndNoSub[e]&&(t(this.pubAndNoSub[e]),Reflect.deleteProperty(this.pubAndNoSub,e)),(n=this.subscribeList[e])!=null&&n.push(t)||(this.subscribeList[e]=[t])}publish(e,t){let n=this.subscribeList[e];!n||n.length===0?this.pubAndNoSub[e]=t:n.forEach(e=>e(t))}remove(e,t){let n=this.subscribeList[e];!n||n.length===0||(t?n.forEach((n,r)=>{n===t&&this.subscribeList[e].splice(r,1)}):this.subscribeList[e]=[])}};new vr;var yr=class{constructor(){this.copyShallow=e=>this.copy(e,`shallow`),this.copyDeep=e=>this.copy(e,`deep`)}copy(e,t){if(typeof e==`object`&&e){let n=Reflect.construct(e.constructor,[]);return Object.keys(e).forEach(r=>{n[r]=t===`shallow`?e[r]:this.copy(e[r],`deep`)}),n}return e}},{copyShallow:br,copyDeep:xr}=new yr,Sr=class{constructor(){this.compareShallow=(e,t)=>this.compare(e,t,`shallow`),this.compareDeep=(e,t)=>this.compare(e,t,`deep`)}compare(e,t,n){if(e===t)return!0;if(!gr(e)||_r(e)||!gr(t)||_r(t))return!1;let r=Object.keys(e).length,i=Object.keys(t).length;if(r!==i)return!1;for(let r of Object.keys(e)){let i=r;if(n===`shallow`&&e[i]!==t[i])return!1;if(n===`deep`){let n=this.compare(e[i],t[i],`deep`);if(!n)return n}}return!0}},{compareShallow:Cr,compareDeep:wr}=new Sr,Tr=class{constructor(){this.mergeShallow=(e,...t)=>this.merge(e,`shallow`,...t),this.mergeDeep=(e,...t)=>this.merge(e,`deep`,...t)}merge(e,t,...n){if(hr(n)){for(;n.length>0;){let r=n.pop();if(!gr(r))return e;Reflect.ownKeys(r).forEach(n=>{if(t===`shallow`)e[n]=r[n];else{if(!Reflect.has(e,n)||!gr(r[n]))return e[n]=xr(r[n]);this.merge(e[n],`deep`,r[n])}})}return e}return e}},{mergeShallow:Er,mergeDeep:Dr}=new Tr;function Or(){return{}}function kr(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}function Ar(e,t){for(let n in e instanceof Map&&t instanceof Map&&t.forEach((t,n)=>e.set(n,t)),e instanceof Set&&t instanceof Set&&t.forEach(e.add,e),t){if(!Object.hasOwn(t,n))continue;let r=t[n],i=e[n];kr(i)&&kr(r)&&e.hasOwnProperty(n)&&!L(r)&&!N(r)?e[n]=Ar(i,r):e[n]=r}return e}const jr=Symbol(),Mr=Symbol(),{assign:$}=Object;function Nr(e,t,n){let{state:r,actions:i,getters:a}=t,o=n.state.value[e],s;function c(){o||(n.state.value[e]=r?r():{});let t=Ft(n.state.value[e]);return $(t,i,Object.keys(a||{}).reduce((t,r)=>(t[r]=St(cr(()=>{Z(n);let t=n._s.get(e);return a[r].call(t,t)})),t),{}))}return s=Pr(e,c,t,n),s}function Pr(e,t,n={},r){let i,a=$({actions:{}},n),o={deep:!0},s,c,l=new Set,u=new Set,d=[],f;function p(t){let n;s=c=!1,typeof t==`function`?(t(r.state.value[e]),n={type:mr.patchFunction,storeId:e,events:d}):(Ar(r.state.value[e],t),n={type:mr.patchObject,payload:t,storeId:e,events:d}),f=Symbol();let i=f;$t().then(()=>{f===i&&(s=!0)}),c=!0,Q(l,n,r.state.value[e])}let m=function(){let{state:e}=n,t=e?e():{};this.$patch(e=>{$(e,t)})},h=(t,n=``)=>{if(jr in t)return t[Mr]=n,t;let i=function(){Z(r);let n=Array.from(arguments),a=new Set,o=new Set;function s(e){a.add(e)}function c(e){o.add(e)}Q(u,{args:n,name:i[Mr],store:_,after:s,onError:c});let l;try{l=t.apply(this&&this.$id===e?this:_,n)}catch(e){throw Q(o,e),e}return l instanceof Promise?l.then(e=>(Q(a,e),e)).catch(e=>(Q(o,e),Promise.reject(e))):(Q(a,l),l)};return i[jr]=!0,i[Mr]=n,i},g={_p:r,$id:e,$onAction:pr.bind(null,u),$patch:p,$reset:m,$subscribe(t,n={}){let a=pr(l,t,n.detached,()=>u()),u=i.run(()=>Tn(()=>r.state.value[e],r=>{(n.flush===`sync`?c:s)&&t({storeId:e,type:mr.direct,events:d},r)},$({},o,n)));return a}},_=gt(g);r._s.set(e,_),i=de();let v=i.run(()=>t({action:h}));for(let e in v){let t=v[e];if(typeof t==`function`){let n=h(t,e);v[e]=n,a.actions[e]=t}}return $(_,v),$(F(_),v),Object.defineProperty(_,`$state`,{get:()=>r.state.value[e],set:e=>{p(t=>{$(t,e)})}}),r._p.forEach(e=>{$(_,i.run(()=>e({store:_,pinia:r,options:a})))}),s=!0,c=!0,_}function Fr(i,a){let o=new WeakMap,s=new WeakMap;function c(c){c&&Z(c),c=ur;let l=D.value;D.value=void 0,c._s.has(i)||Nr(i,a,c),D.value=l;let u=c._s.get(i),d=n([t()]),f=n({...u}),p=n(!1),m=e(e=>(s.set(d.current,e),()=>{let e=o.get(d.current);e&&e.stop(),s.delete(d.current),o.delete(d.current)}),[]);r(m,()=>f.current,()=>f.current);let h=o.get(d.current);if(!h){let e=()=>{let e=s.get(d.current);p.current||(f.current={...u},e?.())};h=new me(e,Or,()=>{h?.dirty&&h.run()}),D.value=h,p.current=!0,h.run(),o.set(d.current,h),p.current=!1}return u}return c.$id=i,c.$getStore=e=>{e&&Z(e),e=ur,e._s.has(i)||Nr(i,a,e);let t=e._s.get(i);return t},c}export{mr as MutationType,dr as createPinia,Fr as defineStore,lr as getActivePinia,Z as setActivePinia};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-react",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "homepage": "https://github.com/savageKarl/pinia-react#readme",
6
6
  "bugs": {
@@ -28,7 +28,7 @@
28
28
  "prepare": "npx simple-git-hooks",
29
29
  "build": "tsdown",
30
30
  "dev": "tsdown --watch",
31
- "playground-react": "vite --config playground/react/vite.config.ts",
31
+ "playground-react": "vite playground/react",
32
32
  "playground-nextjs": "pnpm next dev ./playground/nextjs",
33
33
  "test": "vitest",
34
34
  "semantic-release": "semantic-release",
@@ -67,7 +67,7 @@
67
67
  "simple-git-hooks": "^2.13.1",
68
68
  "tsdown": "^0.13.3",
69
69
  "typescript": "^5.8.3",
70
- "vite": "npm:rolldown-vite@latest",
70
+ "vite": "^7.1.2",
71
71
  "vitest": "^3.2.4"
72
72
  },
73
73
  "dependencies": {