@histoire/vendors 0.8.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.
@@ -0,0 +1,1936 @@
1
+ import { i as isVue2, s as set, d as del } from './index.js';
2
+ import { s as setupDevtoolsPlugin } from './index2.js';
3
+ import { y as getCurrentInstance, z as inject, A as watch, B as unref, C as markRaw, D as toRaw, E as effectScope, u as ref, G as isRef, H as isReactive, I as onUnmounted, J as toRefs, K as computed, a as nextTick, L as reactive, M as toRef } from './vue.runtime.esm-bundler.js';
4
+
5
+ /*!
6
+ * pinia v2.0.14
7
+ * (c) 2022 Eduardo San Martin Morote
8
+ * @license MIT
9
+ */
10
+
11
+ /**
12
+ * setActivePinia must be called to handle SSR at the top of functions like
13
+ * `fetch`, `setup`, `serverPrefetch` and others
14
+ */
15
+ let activePinia;
16
+ /**
17
+ * Sets or unsets the active pinia. Used in SSR and internally when calling
18
+ * actions and getters
19
+ *
20
+ * @param pinia - Pinia instance
21
+ */
22
+ const setActivePinia = (pinia) => (activePinia = pinia);
23
+ /**
24
+ * Get the currently active pinia if there is any.
25
+ */
26
+ const getActivePinia = () => (getCurrentInstance() && inject(piniaSymbol)) || activePinia;
27
+ const piniaSymbol = ((process.env.NODE_ENV !== 'production') ? Symbol('pinia') : /* istanbul ignore next */ Symbol());
28
+
29
+ function isPlainObject(
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ o) {
32
+ return (o &&
33
+ typeof o === 'object' &&
34
+ Object.prototype.toString.call(o) === '[object Object]' &&
35
+ typeof o.toJSON !== 'function');
36
+ }
37
+ // type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
38
+ // TODO: can we change these to numbers?
39
+ /**
40
+ * Possible types for SubscriptionCallback
41
+ */
42
+ var MutationType;
43
+ (function (MutationType) {
44
+ /**
45
+ * Direct mutation of the state:
46
+ *
47
+ * - `store.name = 'new name'`
48
+ * - `store.$state.name = 'new name'`
49
+ * - `store.list.push('new item')`
50
+ */
51
+ MutationType["direct"] = "direct";
52
+ /**
53
+ * Mutated the state with `$patch` and an object
54
+ *
55
+ * - `store.$patch({ name: 'newName' })`
56
+ */
57
+ MutationType["patchObject"] = "patch object";
58
+ /**
59
+ * Mutated the state with `$patch` and a function
60
+ *
61
+ * - `store.$patch(state => state.name = 'newName')`
62
+ */
63
+ MutationType["patchFunction"] = "patch function";
64
+ // maybe reset? for $state = {} and $reset
65
+ })(MutationType || (MutationType = {}));
66
+
67
+ const IS_CLIENT = typeof window !== 'undefined';
68
+
69
+ /*
70
+ * FileSaver.js A saveAs() FileSaver implementation.
71
+ *
72
+ * Originally by Eli Grey, adapted as an ESM module by Eduardo San Martin
73
+ * Morote.
74
+ *
75
+ * License : MIT
76
+ */
77
+ // The one and only way of getting global scope in all environments
78
+ // https://stackoverflow.com/q/3277182/1008999
79
+ const _global = /*#__PURE__*/ (() => typeof window === 'object' && window.window === window
80
+ ? window
81
+ : typeof self === 'object' && self.self === self
82
+ ? self
83
+ : typeof global === 'object' && global.global === global
84
+ ? global
85
+ : typeof globalThis === 'object'
86
+ ? globalThis
87
+ : { HTMLElement: null })();
88
+ function bom(blob, { autoBom = false } = {}) {
89
+ // prepend BOM for UTF-8 XML and text/* types (including HTML)
90
+ // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
91
+ if (autoBom &&
92
+ /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
93
+ return new Blob([String.fromCharCode(0xfeff), blob], { type: blob.type });
94
+ }
95
+ return blob;
96
+ }
97
+ function download(url, name, opts) {
98
+ const xhr = new XMLHttpRequest();
99
+ xhr.open('GET', url);
100
+ xhr.responseType = 'blob';
101
+ xhr.onload = function () {
102
+ saveAs(xhr.response, name, opts);
103
+ };
104
+ xhr.onerror = function () {
105
+ console.error('could not download file');
106
+ };
107
+ xhr.send();
108
+ }
109
+ function corsEnabled(url) {
110
+ const xhr = new XMLHttpRequest();
111
+ // use sync to avoid popup blocker
112
+ xhr.open('HEAD', url, false);
113
+ try {
114
+ xhr.send();
115
+ }
116
+ catch (e) { }
117
+ return xhr.status >= 200 && xhr.status <= 299;
118
+ }
119
+ // `a.click()` doesn't work for all browsers (#465)
120
+ function click(node) {
121
+ try {
122
+ node.dispatchEvent(new MouseEvent('click'));
123
+ }
124
+ catch (e) {
125
+ const evt = document.createEvent('MouseEvents');
126
+ evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
127
+ node.dispatchEvent(evt);
128
+ }
129
+ }
130
+ const _navigator =
131
+ typeof navigator === 'object' ? navigator : { userAgent: '' };
132
+ // Detect WebView inside a native macOS app by ruling out all browsers
133
+ // We just need to check for 'Safari' because all other browsers (besides Firefox) include that too
134
+ // https://www.whatismybrowser.com/guides/the-latest-user-agent/macos
135
+ const isMacOSWebView = /*#__PURE__*/ (() => /Macintosh/.test(_navigator.userAgent) &&
136
+ /AppleWebKit/.test(_navigator.userAgent) &&
137
+ !/Safari/.test(_navigator.userAgent))();
138
+ const saveAs = !IS_CLIENT
139
+ ? () => { } // noop
140
+ : // Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView or mini program
141
+ typeof HTMLAnchorElement !== 'undefined' &&
142
+ 'download' in HTMLAnchorElement.prototype &&
143
+ !isMacOSWebView
144
+ ? downloadSaveAs
145
+ : // Use msSaveOrOpenBlob as a second approach
146
+ 'msSaveOrOpenBlob' in _navigator
147
+ ? msSaveAs
148
+ : // Fallback to using FileReader and a popup
149
+ fileSaverSaveAs;
150
+ function downloadSaveAs(blob, name = 'download', opts) {
151
+ const a = document.createElement('a');
152
+ a.download = name;
153
+ a.rel = 'noopener'; // tabnabbing
154
+ // TODO: detect chrome extensions & packaged apps
155
+ // a.target = '_blank'
156
+ if (typeof blob === 'string') {
157
+ // Support regular links
158
+ a.href = blob;
159
+ if (a.origin !== location.origin) {
160
+ if (corsEnabled(a.href)) {
161
+ download(blob, name, opts);
162
+ }
163
+ else {
164
+ a.target = '_blank';
165
+ click(a);
166
+ }
167
+ }
168
+ else {
169
+ click(a);
170
+ }
171
+ }
172
+ else {
173
+ // Support blobs
174
+ a.href = URL.createObjectURL(blob);
175
+ setTimeout(function () {
176
+ URL.revokeObjectURL(a.href);
177
+ }, 4e4); // 40s
178
+ setTimeout(function () {
179
+ click(a);
180
+ }, 0);
181
+ }
182
+ }
183
+ function msSaveAs(blob, name = 'download', opts) {
184
+ if (typeof blob === 'string') {
185
+ if (corsEnabled(blob)) {
186
+ download(blob, name, opts);
187
+ }
188
+ else {
189
+ const a = document.createElement('a');
190
+ a.href = blob;
191
+ a.target = '_blank';
192
+ setTimeout(function () {
193
+ click(a);
194
+ });
195
+ }
196
+ }
197
+ else {
198
+ // @ts-ignore: works on windows
199
+ navigator.msSaveOrOpenBlob(bom(blob, opts), name);
200
+ }
201
+ }
202
+ function fileSaverSaveAs(blob, name, opts, popup) {
203
+ // Open a popup immediately do go around popup blocker
204
+ // Mostly only available on user interaction and the fileReader is async so...
205
+ popup = popup || open('', '_blank');
206
+ if (popup) {
207
+ popup.document.title = popup.document.body.innerText = 'downloading...';
208
+ }
209
+ if (typeof blob === 'string')
210
+ return download(blob, name, opts);
211
+ const force = blob.type === 'application/octet-stream';
212
+ const isSafari = /constructor/i.test(String(_global.HTMLElement)) || 'safari' in _global;
213
+ const isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
214
+ if ((isChromeIOS || (force && isSafari) || isMacOSWebView) &&
215
+ typeof FileReader !== 'undefined') {
216
+ // Safari doesn't allow downloading of blob URLs
217
+ const reader = new FileReader();
218
+ reader.onloadend = function () {
219
+ let url = reader.result;
220
+ if (typeof url !== 'string') {
221
+ popup = null;
222
+ throw new Error('Wrong reader.result type');
223
+ }
224
+ url = isChromeIOS
225
+ ? url
226
+ : url.replace(/^data:[^;]*;/, 'data:attachment/file;');
227
+ if (popup) {
228
+ popup.location.href = url;
229
+ }
230
+ else {
231
+ location.assign(url);
232
+ }
233
+ popup = null; // reverse-tabnabbing #460
234
+ };
235
+ reader.readAsDataURL(blob);
236
+ }
237
+ else {
238
+ const url = URL.createObjectURL(blob);
239
+ if (popup)
240
+ popup.location.assign(url);
241
+ else
242
+ location.href = url;
243
+ popup = null; // reverse-tabnabbing #460
244
+ setTimeout(function () {
245
+ URL.revokeObjectURL(url);
246
+ }, 4e4); // 40s
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Shows a toast or console.log
252
+ *
253
+ * @param message - message to log
254
+ * @param type - different color of the tooltip
255
+ */
256
+ function toastMessage(message, type) {
257
+ const piniaMessage = '🍍 ' + message;
258
+ if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') {
259
+ __VUE_DEVTOOLS_TOAST__(piniaMessage, type);
260
+ }
261
+ else if (type === 'error') {
262
+ console.error(piniaMessage);
263
+ }
264
+ else if (type === 'warn') {
265
+ console.warn(piniaMessage);
266
+ }
267
+ else {
268
+ console.log(piniaMessage);
269
+ }
270
+ }
271
+ function isPinia(o) {
272
+ return '_a' in o && 'install' in o;
273
+ }
274
+
275
+ function checkClipboardAccess() {
276
+ if (!('clipboard' in navigator)) {
277
+ toastMessage(`Your browser doesn't support the Clipboard API`, 'error');
278
+ return true;
279
+ }
280
+ }
281
+ function checkNotFocusedError(error) {
282
+ if (error instanceof Error &&
283
+ error.message.toLowerCase().includes('document is not focused')) {
284
+ toastMessage('You need to activate the "Emulate a focused page" setting in the "Rendering" panel of devtools.', 'warn');
285
+ return true;
286
+ }
287
+ return false;
288
+ }
289
+ async function actionGlobalCopyState(pinia) {
290
+ if (checkClipboardAccess())
291
+ return;
292
+ try {
293
+ await navigator.clipboard.writeText(JSON.stringify(pinia.state.value));
294
+ toastMessage('Global state copied to clipboard.');
295
+ }
296
+ catch (error) {
297
+ if (checkNotFocusedError(error))
298
+ return;
299
+ toastMessage(`Failed to serialize the state. Check the console for more details.`, 'error');
300
+ console.error(error);
301
+ }
302
+ }
303
+ async function actionGlobalPasteState(pinia) {
304
+ if (checkClipboardAccess())
305
+ return;
306
+ try {
307
+ pinia.state.value = JSON.parse(await navigator.clipboard.readText());
308
+ toastMessage('Global state pasted from clipboard.');
309
+ }
310
+ catch (error) {
311
+ if (checkNotFocusedError(error))
312
+ return;
313
+ toastMessage(`Failed to deserialize the state from clipboard. Check the console for more details.`, 'error');
314
+ console.error(error);
315
+ }
316
+ }
317
+ async function actionGlobalSaveState(pinia) {
318
+ try {
319
+ saveAs(new Blob([JSON.stringify(pinia.state.value)], {
320
+ type: 'text/plain;charset=utf-8',
321
+ }), 'pinia-state.json');
322
+ }
323
+ catch (error) {
324
+ toastMessage(`Failed to export the state as JSON. Check the console for more details.`, 'error');
325
+ console.error(error);
326
+ }
327
+ }
328
+ let fileInput;
329
+ function getFileOpener() {
330
+ if (!fileInput) {
331
+ fileInput = document.createElement('input');
332
+ fileInput.type = 'file';
333
+ fileInput.accept = '.json';
334
+ }
335
+ function openFile() {
336
+ return new Promise((resolve, reject) => {
337
+ fileInput.onchange = async () => {
338
+ const files = fileInput.files;
339
+ if (!files)
340
+ return resolve(null);
341
+ const file = files.item(0);
342
+ if (!file)
343
+ return resolve(null);
344
+ return resolve({ text: await file.text(), file });
345
+ };
346
+ // @ts-ignore: TODO: changed from 4.3 to 4.4
347
+ fileInput.oncancel = () => resolve(null);
348
+ fileInput.onerror = reject;
349
+ fileInput.click();
350
+ });
351
+ }
352
+ return openFile;
353
+ }
354
+ async function actionGlobalOpenStateFile(pinia) {
355
+ try {
356
+ const open = await getFileOpener();
357
+ const result = await open();
358
+ if (!result)
359
+ return;
360
+ const { text, file } = result;
361
+ pinia.state.value = JSON.parse(text);
362
+ toastMessage(`Global state imported from "${file.name}".`);
363
+ }
364
+ catch (error) {
365
+ toastMessage(`Failed to export the state as JSON. Check the console for more details.`, 'error');
366
+ console.error(error);
367
+ }
368
+ }
369
+
370
+ function formatDisplay(display) {
371
+ return {
372
+ _custom: {
373
+ display,
374
+ },
375
+ };
376
+ }
377
+ const PINIA_ROOT_LABEL = '🍍 Pinia (root)';
378
+ const PINIA_ROOT_ID = '_root';
379
+ function formatStoreForInspectorTree(store) {
380
+ return isPinia(store)
381
+ ? {
382
+ id: PINIA_ROOT_ID,
383
+ label: PINIA_ROOT_LABEL,
384
+ }
385
+ : {
386
+ id: store.$id,
387
+ label: store.$id,
388
+ };
389
+ }
390
+ function formatStoreForInspectorState(store) {
391
+ if (isPinia(store)) {
392
+ const storeNames = Array.from(store._s.keys());
393
+ const storeMap = store._s;
394
+ const state = {
395
+ state: storeNames.map((storeId) => ({
396
+ editable: true,
397
+ key: storeId,
398
+ value: store.state.value[storeId],
399
+ })),
400
+ getters: storeNames
401
+ .filter((id) => storeMap.get(id)._getters)
402
+ .map((id) => {
403
+ const store = storeMap.get(id);
404
+ return {
405
+ editable: false,
406
+ key: id,
407
+ value: store._getters.reduce((getters, key) => {
408
+ getters[key] = store[key];
409
+ return getters;
410
+ }, {}),
411
+ };
412
+ }),
413
+ };
414
+ return state;
415
+ }
416
+ const state = {
417
+ state: Object.keys(store.$state).map((key) => ({
418
+ editable: true,
419
+ key,
420
+ value: store.$state[key],
421
+ })),
422
+ };
423
+ // avoid adding empty getters
424
+ if (store._getters && store._getters.length) {
425
+ state.getters = store._getters.map((getterName) => ({
426
+ editable: false,
427
+ key: getterName,
428
+ value: store[getterName],
429
+ }));
430
+ }
431
+ if (store._customProperties.size) {
432
+ state.customProperties = Array.from(store._customProperties).map((key) => ({
433
+ editable: true,
434
+ key,
435
+ value: store[key],
436
+ }));
437
+ }
438
+ return state;
439
+ }
440
+ function formatEventData(events) {
441
+ if (!events)
442
+ return {};
443
+ if (Array.isArray(events)) {
444
+ // TODO: handle add and delete for arrays and objects
445
+ return events.reduce((data, event) => {
446
+ data.keys.push(event.key);
447
+ data.operations.push(event.type);
448
+ data.oldValue[event.key] = event.oldValue;
449
+ data.newValue[event.key] = event.newValue;
450
+ return data;
451
+ }, {
452
+ oldValue: {},
453
+ keys: [],
454
+ operations: [],
455
+ newValue: {},
456
+ });
457
+ }
458
+ else {
459
+ return {
460
+ operation: formatDisplay(events.type),
461
+ key: formatDisplay(events.key),
462
+ oldValue: events.oldValue,
463
+ newValue: events.newValue,
464
+ };
465
+ }
466
+ }
467
+ function formatMutationType(type) {
468
+ switch (type) {
469
+ case MutationType.direct:
470
+ return 'mutation';
471
+ case MutationType.patchFunction:
472
+ return '$patch';
473
+ case MutationType.patchObject:
474
+ return '$patch';
475
+ default:
476
+ return 'unknown';
477
+ }
478
+ }
479
+
480
+ // timeline can be paused when directly changing the state
481
+ let isTimelineActive = true;
482
+ const componentStateTypes = [];
483
+ const MUTATIONS_LAYER_ID = 'pinia:mutations';
484
+ const INSPECTOR_ID = 'pinia';
485
+ /**
486
+ * Gets the displayed name of a store in devtools
487
+ *
488
+ * @param id - id of the store
489
+ * @returns a formatted string
490
+ */
491
+ const getStoreType = (id) => '🍍 ' + id;
492
+ /**
493
+ * Add the pinia plugin without any store. Allows displaying a Pinia plugin tab
494
+ * as soon as it is added to the application.
495
+ *
496
+ * @param app - Vue application
497
+ * @param pinia - pinia instance
498
+ */
499
+ function registerPiniaDevtools(app, pinia) {
500
+ setupDevtoolsPlugin({
501
+ id: 'dev.esm.pinia',
502
+ label: 'Pinia 🍍',
503
+ logo: 'https://pinia.vuejs.org/logo.svg',
504
+ packageName: 'pinia',
505
+ homepage: 'https://pinia.vuejs.org',
506
+ componentStateTypes,
507
+ app,
508
+ }, (api) => {
509
+ if (typeof api.now !== 'function') {
510
+ toastMessage('You seem to be using an outdated version of Vue Devtools. Are you still using the Beta release instead of the stable one? You can find the links at https://devtools.vuejs.org/guide/installation.html.');
511
+ }
512
+ api.addTimelineLayer({
513
+ id: MUTATIONS_LAYER_ID,
514
+ label: `Pinia 🍍`,
515
+ color: 0xe5df88,
516
+ });
517
+ api.addInspector({
518
+ id: INSPECTOR_ID,
519
+ label: 'Pinia 🍍',
520
+ icon: 'storage',
521
+ treeFilterPlaceholder: 'Search stores',
522
+ actions: [
523
+ {
524
+ icon: 'content_copy',
525
+ action: () => {
526
+ actionGlobalCopyState(pinia);
527
+ },
528
+ tooltip: 'Serialize and copy the state',
529
+ },
530
+ {
531
+ icon: 'content_paste',
532
+ action: async () => {
533
+ await actionGlobalPasteState(pinia);
534
+ api.sendInspectorTree(INSPECTOR_ID);
535
+ api.sendInspectorState(INSPECTOR_ID);
536
+ },
537
+ tooltip: 'Replace the state with the content of your clipboard',
538
+ },
539
+ {
540
+ icon: 'save',
541
+ action: () => {
542
+ actionGlobalSaveState(pinia);
543
+ },
544
+ tooltip: 'Save the state as a JSON file',
545
+ },
546
+ {
547
+ icon: 'folder_open',
548
+ action: async () => {
549
+ await actionGlobalOpenStateFile(pinia);
550
+ api.sendInspectorTree(INSPECTOR_ID);
551
+ api.sendInspectorState(INSPECTOR_ID);
552
+ },
553
+ tooltip: 'Import the state from a JSON file',
554
+ },
555
+ ],
556
+ });
557
+ api.on.inspectComponent((payload, ctx) => {
558
+ const proxy = (payload.componentInstance &&
559
+ payload.componentInstance.proxy);
560
+ if (proxy && proxy._pStores) {
561
+ const piniaStores = payload.componentInstance.proxy._pStores;
562
+ Object.values(piniaStores).forEach((store) => {
563
+ payload.instanceData.state.push({
564
+ type: getStoreType(store.$id),
565
+ key: 'state',
566
+ editable: true,
567
+ value: store._isOptionsAPI
568
+ ? {
569
+ _custom: {
570
+ value: store.$state,
571
+ actions: [
572
+ {
573
+ icon: 'restore',
574
+ tooltip: 'Reset the state of this store',
575
+ action: () => store.$reset(),
576
+ },
577
+ ],
578
+ },
579
+ }
580
+ : store.$state,
581
+ });
582
+ if (store._getters && store._getters.length) {
583
+ payload.instanceData.state.push({
584
+ type: getStoreType(store.$id),
585
+ key: 'getters',
586
+ editable: false,
587
+ value: store._getters.reduce((getters, key) => {
588
+ try {
589
+ getters[key] = store[key];
590
+ }
591
+ catch (error) {
592
+ // @ts-expect-error: we just want to show it in devtools
593
+ getters[key] = error;
594
+ }
595
+ return getters;
596
+ }, {}),
597
+ });
598
+ }
599
+ });
600
+ }
601
+ });
602
+ api.on.getInspectorTree((payload) => {
603
+ if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
604
+ let stores = [pinia];
605
+ stores = stores.concat(Array.from(pinia._s.values()));
606
+ payload.rootNodes = (payload.filter
607
+ ? stores.filter((store) => '$id' in store
608
+ ? store.$id
609
+ .toLowerCase()
610
+ .includes(payload.filter.toLowerCase())
611
+ : PINIA_ROOT_LABEL.toLowerCase().includes(payload.filter.toLowerCase()))
612
+ : stores).map(formatStoreForInspectorTree);
613
+ }
614
+ });
615
+ api.on.getInspectorState((payload) => {
616
+ if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
617
+ const inspectedStore = payload.nodeId === PINIA_ROOT_ID
618
+ ? pinia
619
+ : pinia._s.get(payload.nodeId);
620
+ if (!inspectedStore) {
621
+ // this could be the selected store restored for a different project
622
+ // so it's better not to say anything here
623
+ return;
624
+ }
625
+ if (inspectedStore) {
626
+ payload.state = formatStoreForInspectorState(inspectedStore);
627
+ }
628
+ }
629
+ });
630
+ api.on.editInspectorState((payload, ctx) => {
631
+ if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
632
+ const inspectedStore = payload.nodeId === PINIA_ROOT_ID
633
+ ? pinia
634
+ : pinia._s.get(payload.nodeId);
635
+ if (!inspectedStore) {
636
+ return toastMessage(`store "${payload.nodeId}" not found`, 'error');
637
+ }
638
+ const { path } = payload;
639
+ if (!isPinia(inspectedStore)) {
640
+ // access only the state
641
+ if (path.length !== 1 ||
642
+ !inspectedStore._customProperties.has(path[0]) ||
643
+ path[0] in inspectedStore.$state) {
644
+ path.unshift('$state');
645
+ }
646
+ }
647
+ else {
648
+ // Root access, we can omit the `.value` because the devtools API does it for us
649
+ path.unshift('state');
650
+ }
651
+ isTimelineActive = false;
652
+ payload.set(inspectedStore, path, payload.state.value);
653
+ isTimelineActive = true;
654
+ }
655
+ });
656
+ api.on.editComponentState((payload) => {
657
+ if (payload.type.startsWith('🍍')) {
658
+ const storeId = payload.type.replace(/^🍍\s*/, '');
659
+ const store = pinia._s.get(storeId);
660
+ if (!store) {
661
+ return toastMessage(`store "${storeId}" not found`, 'error');
662
+ }
663
+ const { path } = payload;
664
+ if (path[0] !== 'state') {
665
+ return toastMessage(`Invalid path for store "${storeId}":\n${path}\nOnly state can be modified.`);
666
+ }
667
+ // rewrite the first entry to be able to directly set the state as
668
+ // well as any other path
669
+ path[0] = '$state';
670
+ isTimelineActive = false;
671
+ payload.set(store, path, payload.state.value);
672
+ isTimelineActive = true;
673
+ }
674
+ });
675
+ });
676
+ }
677
+ function addStoreToDevtools(app, store) {
678
+ if (!componentStateTypes.includes(getStoreType(store.$id))) {
679
+ componentStateTypes.push(getStoreType(store.$id));
680
+ }
681
+ setupDevtoolsPlugin({
682
+ id: 'dev.esm.pinia',
683
+ label: 'Pinia 🍍',
684
+ logo: 'https://pinia.vuejs.org/logo.svg',
685
+ packageName: 'pinia',
686
+ homepage: 'https://pinia.vuejs.org',
687
+ componentStateTypes,
688
+ app,
689
+ settings: {
690
+ logStoreChanges: {
691
+ label: 'Notify about new/deleted stores',
692
+ type: 'boolean',
693
+ defaultValue: true,
694
+ },
695
+ // useEmojis: {
696
+ // label: 'Use emojis in messages ⚡️',
697
+ // type: 'boolean',
698
+ // defaultValue: true,
699
+ // },
700
+ },
701
+ }, (api) => {
702
+ // gracefully handle errors
703
+ const now = typeof api.now === 'function' ? api.now.bind(api) : Date.now;
704
+ store.$onAction(({ after, onError, name, args }) => {
705
+ const groupId = runningActionId++;
706
+ api.addTimelineEvent({
707
+ layerId: MUTATIONS_LAYER_ID,
708
+ event: {
709
+ time: now(),
710
+ title: '🛫 ' + name,
711
+ subtitle: 'start',
712
+ data: {
713
+ store: formatDisplay(store.$id),
714
+ action: formatDisplay(name),
715
+ args,
716
+ },
717
+ groupId,
718
+ },
719
+ });
720
+ after((result) => {
721
+ activeAction = undefined;
722
+ api.addTimelineEvent({
723
+ layerId: MUTATIONS_LAYER_ID,
724
+ event: {
725
+ time: now(),
726
+ title: '🛬 ' + name,
727
+ subtitle: 'end',
728
+ data: {
729
+ store: formatDisplay(store.$id),
730
+ action: formatDisplay(name),
731
+ args,
732
+ result,
733
+ },
734
+ groupId,
735
+ },
736
+ });
737
+ });
738
+ onError((error) => {
739
+ activeAction = undefined;
740
+ api.addTimelineEvent({
741
+ layerId: MUTATIONS_LAYER_ID,
742
+ event: {
743
+ time: now(),
744
+ logType: 'error',
745
+ title: '💥 ' + name,
746
+ subtitle: 'end',
747
+ data: {
748
+ store: formatDisplay(store.$id),
749
+ action: formatDisplay(name),
750
+ args,
751
+ error,
752
+ },
753
+ groupId,
754
+ },
755
+ });
756
+ });
757
+ }, true);
758
+ store._customProperties.forEach((name) => {
759
+ watch(() => unref(store[name]), (newValue, oldValue) => {
760
+ api.notifyComponentUpdate();
761
+ api.sendInspectorState(INSPECTOR_ID);
762
+ if (isTimelineActive) {
763
+ api.addTimelineEvent({
764
+ layerId: MUTATIONS_LAYER_ID,
765
+ event: {
766
+ time: now(),
767
+ title: 'Change',
768
+ subtitle: name,
769
+ data: {
770
+ newValue,
771
+ oldValue,
772
+ },
773
+ groupId: activeAction,
774
+ },
775
+ });
776
+ }
777
+ }, { deep: true });
778
+ });
779
+ store.$subscribe(({ events, type }, state) => {
780
+ api.notifyComponentUpdate();
781
+ api.sendInspectorState(INSPECTOR_ID);
782
+ if (!isTimelineActive)
783
+ return;
784
+ // rootStore.state[store.id] = state
785
+ const eventData = {
786
+ time: now(),
787
+ title: formatMutationType(type),
788
+ data: {
789
+ store: formatDisplay(store.$id),
790
+ ...formatEventData(events),
791
+ },
792
+ groupId: activeAction,
793
+ };
794
+ // reset for the next mutation
795
+ activeAction = undefined;
796
+ if (type === MutationType.patchFunction) {
797
+ eventData.subtitle = '⤵️';
798
+ }
799
+ else if (type === MutationType.patchObject) {
800
+ eventData.subtitle = '🧩';
801
+ }
802
+ else if (events && !Array.isArray(events)) {
803
+ eventData.subtitle = events.type;
804
+ }
805
+ if (events) {
806
+ eventData.data['rawEvent(s)'] = {
807
+ _custom: {
808
+ display: 'DebuggerEvent',
809
+ type: 'object',
810
+ tooltip: 'raw DebuggerEvent[]',
811
+ value: events,
812
+ },
813
+ };
814
+ }
815
+ api.addTimelineEvent({
816
+ layerId: MUTATIONS_LAYER_ID,
817
+ event: eventData,
818
+ });
819
+ }, { detached: true, flush: 'sync' });
820
+ const hotUpdate = store._hotUpdate;
821
+ store._hotUpdate = markRaw((newStore) => {
822
+ hotUpdate(newStore);
823
+ api.addTimelineEvent({
824
+ layerId: MUTATIONS_LAYER_ID,
825
+ event: {
826
+ time: now(),
827
+ title: '🔥 ' + store.$id,
828
+ subtitle: 'HMR update',
829
+ data: {
830
+ store: formatDisplay(store.$id),
831
+ info: formatDisplay(`HMR update`),
832
+ },
833
+ },
834
+ });
835
+ // update the devtools too
836
+ api.notifyComponentUpdate();
837
+ api.sendInspectorTree(INSPECTOR_ID);
838
+ api.sendInspectorState(INSPECTOR_ID);
839
+ });
840
+ const { $dispose } = store;
841
+ store.$dispose = () => {
842
+ $dispose();
843
+ api.notifyComponentUpdate();
844
+ api.sendInspectorTree(INSPECTOR_ID);
845
+ api.sendInspectorState(INSPECTOR_ID);
846
+ api.getSettings().logStoreChanges &&
847
+ toastMessage(`Disposed "${store.$id}" store 🗑`);
848
+ };
849
+ // trigger an update so it can display new registered stores
850
+ api.notifyComponentUpdate();
851
+ api.sendInspectorTree(INSPECTOR_ID);
852
+ api.sendInspectorState(INSPECTOR_ID);
853
+ api.getSettings().logStoreChanges &&
854
+ toastMessage(`"${store.$id}" store installed 🆕`);
855
+ });
856
+ }
857
+ let runningActionId = 0;
858
+ let activeAction;
859
+ /**
860
+ * Patches a store to enable action grouping in devtools by wrapping the store with a Proxy that is passed as the
861
+ * context of all actions, allowing us to set `runningAction` on each access and effectively associating any state
862
+ * mutation to the action.
863
+ *
864
+ * @param store - store to patch
865
+ * @param actionNames - list of actionst to patch
866
+ */
867
+ function patchActionForGrouping(store, actionNames) {
868
+ // original actions of the store as they are given by pinia. We are going to override them
869
+ const actions = actionNames.reduce((storeActions, actionName) => {
870
+ // use toRaw to avoid tracking #541
871
+ storeActions[actionName] = toRaw(store)[actionName];
872
+ return storeActions;
873
+ }, {});
874
+ for (const actionName in actions) {
875
+ store[actionName] = function () {
876
+ // setActivePinia(store._p)
877
+ // the running action id is incremented in a before action hook
878
+ const _actionId = runningActionId;
879
+ const trackedStore = new Proxy(store, {
880
+ get(...args) {
881
+ activeAction = _actionId;
882
+ return Reflect.get(...args);
883
+ },
884
+ set(...args) {
885
+ activeAction = _actionId;
886
+ return Reflect.set(...args);
887
+ },
888
+ });
889
+ return actions[actionName].apply(trackedStore, arguments);
890
+ };
891
+ }
892
+ }
893
+ /**
894
+ * pinia.use(devtoolsPlugin)
895
+ */
896
+ function devtoolsPlugin({ app, store, options }) {
897
+ // HMR module
898
+ if (store.$id.startsWith('__hot:')) {
899
+ return;
900
+ }
901
+ // detect option api vs setup api
902
+ if (options.state) {
903
+ store._isOptionsAPI = true;
904
+ }
905
+ // only wrap actions in option-defined stores as this technique relies on
906
+ // wrapping the context of the action with a proxy
907
+ if (typeof options.state === 'function') {
908
+ patchActionForGrouping(
909
+ // @ts-expect-error: can cast the store...
910
+ store, Object.keys(options.actions));
911
+ const originalHotUpdate = store._hotUpdate;
912
+ // Upgrade the HMR to also update the new actions
913
+ toRaw(store)._hotUpdate = function (newStore) {
914
+ originalHotUpdate.apply(this, arguments);
915
+ patchActionForGrouping(store, Object.keys(newStore._hmrPayload.actions));
916
+ };
917
+ }
918
+ addStoreToDevtools(app,
919
+ // FIXME: is there a way to allow the assignment from Store<Id, S, G, A> to StoreGeneric?
920
+ store);
921
+ }
922
+
923
+ /**
924
+ * Creates a Pinia instance to be used by the application
925
+ */
926
+ function createPinia() {
927
+ const scope = effectScope(true);
928
+ // NOTE: here we could check the window object for a state and directly set it
929
+ // if there is anything like it with Vue 3 SSR
930
+ const state = scope.run(() => ref({}));
931
+ let _p = [];
932
+ // plugins added before calling app.use(pinia)
933
+ let toBeInstalled = [];
934
+ const pinia = markRaw({
935
+ install(app) {
936
+ // this allows calling useStore() outside of a component setup after
937
+ // installing pinia's plugin
938
+ setActivePinia(pinia);
939
+ if (!isVue2) {
940
+ pinia._a = app;
941
+ app.provide(piniaSymbol, pinia);
942
+ app.config.globalProperties.$pinia = pinia;
943
+ /* istanbul ignore else */
944
+ if ((process.env.NODE_ENV !== 'production') && IS_CLIENT) {
945
+ registerPiniaDevtools(app, pinia);
946
+ }
947
+ toBeInstalled.forEach((plugin) => _p.push(plugin));
948
+ toBeInstalled = [];
949
+ }
950
+ },
951
+ use(plugin) {
952
+ if (!this._a && !isVue2) {
953
+ toBeInstalled.push(plugin);
954
+ }
955
+ else {
956
+ _p.push(plugin);
957
+ }
958
+ return this;
959
+ },
960
+ _p,
961
+ // it's actually undefined here
962
+ // @ts-expect-error
963
+ _a: null,
964
+ _e: scope,
965
+ _s: new Map(),
966
+ state,
967
+ });
968
+ // pinia devtools rely on dev only features so they cannot be forced unless
969
+ // the dev build of Vue is used
970
+ // We also don't need devtools in test mode
971
+ if ((process.env.NODE_ENV !== 'production') && IS_CLIENT && !(process.env.NODE_ENV === 'test')) {
972
+ pinia.use(devtoolsPlugin);
973
+ }
974
+ return pinia;
975
+ }
976
+
977
+ /**
978
+ * Checks if a function is a `StoreDefinition`.
979
+ *
980
+ * @param fn - object to test
981
+ * @returns true if `fn` is a StoreDefinition
982
+ */
983
+ const isUseStore = (fn) => {
984
+ return typeof fn === 'function' && typeof fn.$id === 'string';
985
+ };
986
+ /**
987
+ * Mutates in place `newState` with `oldState` to _hot update_ it. It will
988
+ * remove any key not existing in `newState` and recursively merge plain
989
+ * objects.
990
+ *
991
+ * @param newState - new state object to be patched
992
+ * @param oldState - old state that should be used to patch newState
993
+ * @returns - newState
994
+ */
995
+ function patchObject(newState, oldState) {
996
+ // no need to go through symbols because they cannot be serialized anyway
997
+ for (const key in oldState) {
998
+ const subPatch = oldState[key];
999
+ // skip the whole sub tree
1000
+ if (!(key in newState)) {
1001
+ continue;
1002
+ }
1003
+ const targetValue = newState[key];
1004
+ if (isPlainObject(targetValue) &&
1005
+ isPlainObject(subPatch) &&
1006
+ !isRef(subPatch) &&
1007
+ !isReactive(subPatch)) {
1008
+ newState[key] = patchObject(targetValue, subPatch);
1009
+ }
1010
+ else {
1011
+ // objects are either a bit more complex (e.g. refs) or primitives, so we
1012
+ // just set the whole thing
1013
+ if (isVue2) {
1014
+ set(newState, key, subPatch);
1015
+ }
1016
+ else {
1017
+ newState[key] = subPatch;
1018
+ }
1019
+ }
1020
+ }
1021
+ return newState;
1022
+ }
1023
+ /**
1024
+ * Creates an _accept_ function to pass to `import.meta.hot` in Vite applications.
1025
+ *
1026
+ * @example
1027
+ * ```js
1028
+ * const useUser = defineStore(...)
1029
+ * if (import.meta.hot) {
1030
+ * import.meta.hot.accept(acceptHMRUpdate(useUser, import.meta.hot))
1031
+ * }
1032
+ * ```
1033
+ *
1034
+ * @param initialUseStore - return of the defineStore to hot update
1035
+ * @param hot - `import.meta.hot`
1036
+ */
1037
+ function acceptHMRUpdate(initialUseStore, hot) {
1038
+ return (newModule) => {
1039
+ const pinia = hot.data.pinia || initialUseStore._pinia;
1040
+ if (!pinia) {
1041
+ // this store is still not used
1042
+ return;
1043
+ }
1044
+ // preserve the pinia instance across loads
1045
+ hot.data.pinia = pinia;
1046
+ // console.log('got data', newStore)
1047
+ for (const exportName in newModule) {
1048
+ const useStore = newModule[exportName];
1049
+ // console.log('checking for', exportName)
1050
+ if (isUseStore(useStore) && pinia._s.has(useStore.$id)) {
1051
+ // console.log('Accepting update for', useStore.$id)
1052
+ const id = useStore.$id;
1053
+ if (id !== initialUseStore.$id) {
1054
+ console.warn(`The id of the store changed from "${initialUseStore.$id}" to "${id}". Reloading.`);
1055
+ // return import.meta.hot.invalidate()
1056
+ return hot.invalidate();
1057
+ }
1058
+ const existingStore = pinia._s.get(id);
1059
+ if (!existingStore) {
1060
+ console.log(`[Pinia]: skipping hmr because store doesn't exist yet`);
1061
+ return;
1062
+ }
1063
+ useStore(pinia, existingStore);
1064
+ }
1065
+ }
1066
+ };
1067
+ }
1068
+
1069
+ const noop = () => { };
1070
+ function addSubscription(subscriptions, callback, detached, onCleanup = noop) {
1071
+ subscriptions.push(callback);
1072
+ const removeSubscription = () => {
1073
+ const idx = subscriptions.indexOf(callback);
1074
+ if (idx > -1) {
1075
+ subscriptions.splice(idx, 1);
1076
+ onCleanup();
1077
+ }
1078
+ };
1079
+ if (!detached && getCurrentInstance()) {
1080
+ onUnmounted(removeSubscription);
1081
+ }
1082
+ return removeSubscription;
1083
+ }
1084
+ function triggerSubscriptions(subscriptions, ...args) {
1085
+ subscriptions.slice().forEach((callback) => {
1086
+ callback(...args);
1087
+ });
1088
+ }
1089
+
1090
+ function mergeReactiveObjects(target, patchToApply) {
1091
+ // no need to go through symbols because they cannot be serialized anyway
1092
+ for (const key in patchToApply) {
1093
+ if (!patchToApply.hasOwnProperty(key))
1094
+ continue;
1095
+ const subPatch = patchToApply[key];
1096
+ const targetValue = target[key];
1097
+ if (isPlainObject(targetValue) &&
1098
+ isPlainObject(subPatch) &&
1099
+ target.hasOwnProperty(key) &&
1100
+ !isRef(subPatch) &&
1101
+ !isReactive(subPatch)) {
1102
+ target[key] = mergeReactiveObjects(targetValue, subPatch);
1103
+ }
1104
+ else {
1105
+ // @ts-expect-error: subPatch is a valid value
1106
+ target[key] = subPatch;
1107
+ }
1108
+ }
1109
+ return target;
1110
+ }
1111
+ const skipHydrateSymbol = (process.env.NODE_ENV !== 'production')
1112
+ ? Symbol('pinia:skipHydration')
1113
+ : /* istanbul ignore next */ Symbol();
1114
+ const skipHydrateMap = /*#__PURE__*/ new WeakMap();
1115
+ function skipHydrate(obj) {
1116
+ return isVue2
1117
+ ? // in @vue/composition-api, the refs are sealed so defineProperty doesn't work...
1118
+ /* istanbul ignore next */ skipHydrateMap.set(obj, 1) && obj
1119
+ : Object.defineProperty(obj, skipHydrateSymbol, {});
1120
+ }
1121
+ function shouldHydrate(obj) {
1122
+ return isVue2
1123
+ ? /* istanbul ignore next */ !skipHydrateMap.has(obj)
1124
+ : !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol);
1125
+ }
1126
+ const { assign } = Object;
1127
+ function isComputed(o) {
1128
+ return !!(isRef(o) && o.effect);
1129
+ }
1130
+ function createOptionsStore(id, options, pinia, hot) {
1131
+ const { state, actions, getters } = options;
1132
+ const initialState = pinia.state.value[id];
1133
+ let store;
1134
+ function setup() {
1135
+ if (!initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
1136
+ /* istanbul ignore if */
1137
+ if (isVue2) {
1138
+ set(pinia.state.value, id, state ? state() : {});
1139
+ }
1140
+ else {
1141
+ pinia.state.value[id] = state ? state() : {};
1142
+ }
1143
+ }
1144
+ // avoid creating a state in pinia.state.value
1145
+ const localState = (process.env.NODE_ENV !== 'production') && hot
1146
+ ? // use ref() to unwrap refs inside state TODO: check if this is still necessary
1147
+ toRefs(ref(state ? state() : {}).value)
1148
+ : toRefs(pinia.state.value[id]);
1149
+ return assign(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name) => {
1150
+ computedGetters[name] = markRaw(computed(() => {
1151
+ setActivePinia(pinia);
1152
+ // it was created just before
1153
+ const store = pinia._s.get(id);
1154
+ // allow cross using stores
1155
+ /* istanbul ignore next */
1156
+ if (isVue2 && !store._r)
1157
+ return;
1158
+ // @ts-expect-error
1159
+ // return getters![name].call(context, context)
1160
+ // TODO: avoid reading the getter while assigning with a global variable
1161
+ return getters[name].call(store, store);
1162
+ }));
1163
+ return computedGetters;
1164
+ }, {}));
1165
+ }
1166
+ store = createSetupStore(id, setup, options, pinia, hot, true);
1167
+ store.$reset = function $reset() {
1168
+ const newState = state ? state() : {};
1169
+ // we use a patch to group all changes into one single subscription
1170
+ this.$patch(($state) => {
1171
+ assign($state, newState);
1172
+ });
1173
+ };
1174
+ return store;
1175
+ }
1176
+ function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) {
1177
+ let scope;
1178
+ const optionsForPlugin = assign({ actions: {} }, options);
1179
+ /* istanbul ignore if */
1180
+ // @ts-expect-error: active is an internal property
1181
+ if ((process.env.NODE_ENV !== 'production') && !pinia._e.active) {
1182
+ throw new Error('Pinia destroyed');
1183
+ }
1184
+ // watcher options for $subscribe
1185
+ const $subscribeOptions = {
1186
+ deep: true,
1187
+ // flush: 'post',
1188
+ };
1189
+ /* istanbul ignore else */
1190
+ if ((process.env.NODE_ENV !== 'production') && !isVue2) {
1191
+ $subscribeOptions.onTrigger = (event) => {
1192
+ /* istanbul ignore else */
1193
+ if (isListening) {
1194
+ debuggerEvents = event;
1195
+ // avoid triggering this while the store is being built and the state is being set in pinia
1196
+ }
1197
+ else if (isListening == false && !store._hotUpdating) {
1198
+ // let patch send all the events together later
1199
+ /* istanbul ignore else */
1200
+ if (Array.isArray(debuggerEvents)) {
1201
+ debuggerEvents.push(event);
1202
+ }
1203
+ else {
1204
+ console.error('🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug.');
1205
+ }
1206
+ }
1207
+ };
1208
+ }
1209
+ // internal state
1210
+ let isListening; // set to true at the end
1211
+ let isSyncListening; // set to true at the end
1212
+ let subscriptions = markRaw([]);
1213
+ let actionSubscriptions = markRaw([]);
1214
+ let debuggerEvents;
1215
+ const initialState = pinia.state.value[$id];
1216
+ // avoid setting the state for option stores are it is set
1217
+ // by the setup
1218
+ if (!isOptionsStore && !initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
1219
+ /* istanbul ignore if */
1220
+ if (isVue2) {
1221
+ set(pinia.state.value, $id, {});
1222
+ }
1223
+ else {
1224
+ pinia.state.value[$id] = {};
1225
+ }
1226
+ }
1227
+ const hotState = ref({});
1228
+ // avoid triggering too many listeners
1229
+ // https://github.com/vuejs/pinia/issues/1129
1230
+ let activeListener;
1231
+ function $patch(partialStateOrMutator) {
1232
+ let subscriptionMutation;
1233
+ isListening = isSyncListening = false;
1234
+ // reset the debugger events since patches are sync
1235
+ /* istanbul ignore else */
1236
+ if ((process.env.NODE_ENV !== 'production')) {
1237
+ debuggerEvents = [];
1238
+ }
1239
+ if (typeof partialStateOrMutator === 'function') {
1240
+ partialStateOrMutator(pinia.state.value[$id]);
1241
+ subscriptionMutation = {
1242
+ type: MutationType.patchFunction,
1243
+ storeId: $id,
1244
+ events: debuggerEvents,
1245
+ };
1246
+ }
1247
+ else {
1248
+ mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator);
1249
+ subscriptionMutation = {
1250
+ type: MutationType.patchObject,
1251
+ payload: partialStateOrMutator,
1252
+ storeId: $id,
1253
+ events: debuggerEvents,
1254
+ };
1255
+ }
1256
+ const myListenerId = (activeListener = Symbol());
1257
+ nextTick().then(() => {
1258
+ if (activeListener === myListenerId) {
1259
+ isListening = true;
1260
+ }
1261
+ });
1262
+ isSyncListening = true;
1263
+ // because we paused the watcher, we need to manually call the subscriptions
1264
+ triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]);
1265
+ }
1266
+ /* istanbul ignore next */
1267
+ const $reset = (process.env.NODE_ENV !== 'production')
1268
+ ? () => {
1269
+ throw new Error(`🍍: Store "${$id}" is build using the setup syntax and does not implement $reset().`);
1270
+ }
1271
+ : noop;
1272
+ function $dispose() {
1273
+ scope.stop();
1274
+ subscriptions = [];
1275
+ actionSubscriptions = [];
1276
+ pinia._s.delete($id);
1277
+ }
1278
+ /**
1279
+ * Wraps an action to handle subscriptions.
1280
+ *
1281
+ * @param name - name of the action
1282
+ * @param action - action to wrap
1283
+ * @returns a wrapped action to handle subscriptions
1284
+ */
1285
+ function wrapAction(name, action) {
1286
+ return function () {
1287
+ setActivePinia(pinia);
1288
+ const args = Array.from(arguments);
1289
+ const afterCallbackList = [];
1290
+ const onErrorCallbackList = [];
1291
+ function after(callback) {
1292
+ afterCallbackList.push(callback);
1293
+ }
1294
+ function onError(callback) {
1295
+ onErrorCallbackList.push(callback);
1296
+ }
1297
+ // @ts-expect-error
1298
+ triggerSubscriptions(actionSubscriptions, {
1299
+ args,
1300
+ name,
1301
+ store,
1302
+ after,
1303
+ onError,
1304
+ });
1305
+ let ret;
1306
+ try {
1307
+ ret = action.apply(this && this.$id === $id ? this : store, args);
1308
+ // handle sync errors
1309
+ }
1310
+ catch (error) {
1311
+ triggerSubscriptions(onErrorCallbackList, error);
1312
+ throw error;
1313
+ }
1314
+ if (ret instanceof Promise) {
1315
+ return ret
1316
+ .then((value) => {
1317
+ triggerSubscriptions(afterCallbackList, value);
1318
+ return value;
1319
+ })
1320
+ .catch((error) => {
1321
+ triggerSubscriptions(onErrorCallbackList, error);
1322
+ return Promise.reject(error);
1323
+ });
1324
+ }
1325
+ // allow the afterCallback to override the return value
1326
+ triggerSubscriptions(afterCallbackList, ret);
1327
+ return ret;
1328
+ };
1329
+ }
1330
+ const _hmrPayload = /*#__PURE__*/ markRaw({
1331
+ actions: {},
1332
+ getters: {},
1333
+ state: [],
1334
+ hotState,
1335
+ });
1336
+ const partialStore = {
1337
+ _p: pinia,
1338
+ // _s: scope,
1339
+ $id,
1340
+ $onAction: addSubscription.bind(null, actionSubscriptions),
1341
+ $patch,
1342
+ $reset,
1343
+ $subscribe(callback, options = {}) {
1344
+ const removeSubscription = addSubscription(subscriptions, callback, options.detached, () => stopWatcher());
1345
+ const stopWatcher = scope.run(() => watch(() => pinia.state.value[$id], (state) => {
1346
+ if (options.flush === 'sync' ? isSyncListening : isListening) {
1347
+ callback({
1348
+ storeId: $id,
1349
+ type: MutationType.direct,
1350
+ events: debuggerEvents,
1351
+ }, state);
1352
+ }
1353
+ }, assign({}, $subscribeOptions, options)));
1354
+ return removeSubscription;
1355
+ },
1356
+ $dispose,
1357
+ };
1358
+ /* istanbul ignore if */
1359
+ if (isVue2) {
1360
+ // start as non ready
1361
+ partialStore._r = false;
1362
+ }
1363
+ const store = reactive(assign((process.env.NODE_ENV !== 'production') && IS_CLIENT
1364
+ ? // devtools custom properties
1365
+ {
1366
+ _customProperties: markRaw(new Set()),
1367
+ _hmrPayload,
1368
+ }
1369
+ : {}, partialStore
1370
+ // must be added later
1371
+ // setupStore
1372
+ ));
1373
+ // store the partial store now so the setup of stores can instantiate each other before they are finished without
1374
+ // creating infinite loops.
1375
+ pinia._s.set($id, store);
1376
+ // TODO: idea create skipSerialize that marks properties as non serializable and they are skipped
1377
+ const setupStore = pinia._e.run(() => {
1378
+ scope = effectScope();
1379
+ return scope.run(() => setup());
1380
+ });
1381
+ // overwrite existing actions to support $onAction
1382
+ for (const key in setupStore) {
1383
+ const prop = setupStore[key];
1384
+ if ((isRef(prop) && !isComputed(prop)) || isReactive(prop)) {
1385
+ // mark it as a piece of state to be serialized
1386
+ if ((process.env.NODE_ENV !== 'production') && hot) {
1387
+ set(hotState.value, key, toRef(setupStore, key));
1388
+ // createOptionStore directly sets the state in pinia.state.value so we
1389
+ // can just skip that
1390
+ }
1391
+ else if (!isOptionsStore) {
1392
+ // in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
1393
+ if (initialState && shouldHydrate(prop)) {
1394
+ if (isRef(prop)) {
1395
+ prop.value = initialState[key];
1396
+ }
1397
+ else {
1398
+ // probably a reactive object, lets recursively assign
1399
+ mergeReactiveObjects(prop, initialState[key]);
1400
+ }
1401
+ }
1402
+ // transfer the ref to the pinia state to keep everything in sync
1403
+ /* istanbul ignore if */
1404
+ if (isVue2) {
1405
+ set(pinia.state.value[$id], key, prop);
1406
+ }
1407
+ else {
1408
+ pinia.state.value[$id][key] = prop;
1409
+ }
1410
+ }
1411
+ /* istanbul ignore else */
1412
+ if ((process.env.NODE_ENV !== 'production')) {
1413
+ _hmrPayload.state.push(key);
1414
+ }
1415
+ // action
1416
+ }
1417
+ else if (typeof prop === 'function') {
1418
+ // @ts-expect-error: we are overriding the function we avoid wrapping if
1419
+ const actionValue = (process.env.NODE_ENV !== 'production') && hot ? prop : wrapAction(key, prop);
1420
+ // this a hot module replacement store because the hotUpdate method needs
1421
+ // to do it with the right context
1422
+ /* istanbul ignore if */
1423
+ if (isVue2) {
1424
+ set(setupStore, key, actionValue);
1425
+ }
1426
+ else {
1427
+ // @ts-expect-error
1428
+ setupStore[key] = actionValue;
1429
+ }
1430
+ /* istanbul ignore else */
1431
+ if ((process.env.NODE_ENV !== 'production')) {
1432
+ _hmrPayload.actions[key] = prop;
1433
+ }
1434
+ // list actions so they can be used in plugins
1435
+ // @ts-expect-error
1436
+ optionsForPlugin.actions[key] = prop;
1437
+ }
1438
+ else if ((process.env.NODE_ENV !== 'production')) {
1439
+ // add getters for devtools
1440
+ if (isComputed(prop)) {
1441
+ _hmrPayload.getters[key] = isOptionsStore
1442
+ ? // @ts-expect-error
1443
+ options.getters[key]
1444
+ : prop;
1445
+ if (IS_CLIENT) {
1446
+ const getters =
1447
+ // @ts-expect-error: it should be on the store
1448
+ setupStore._getters || (setupStore._getters = markRaw([]));
1449
+ getters.push(key);
1450
+ }
1451
+ }
1452
+ }
1453
+ }
1454
+ // add the state, getters, and action properties
1455
+ /* istanbul ignore if */
1456
+ if (isVue2) {
1457
+ Object.keys(setupStore).forEach((key) => {
1458
+ set(store, key,
1459
+ // @ts-expect-error: valid key indexing
1460
+ setupStore[key]);
1461
+ });
1462
+ }
1463
+ else {
1464
+ assign(store, setupStore);
1465
+ // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
1466
+ // Make `storeToRefs()` work with `reactive()` #799
1467
+ assign(toRaw(store), setupStore);
1468
+ }
1469
+ // use this instead of a computed with setter to be able to create it anywhere
1470
+ // without linking the computed lifespan to wherever the store is first
1471
+ // created.
1472
+ Object.defineProperty(store, '$state', {
1473
+ get: () => ((process.env.NODE_ENV !== 'production') && hot ? hotState.value : pinia.state.value[$id]),
1474
+ set: (state) => {
1475
+ /* istanbul ignore if */
1476
+ if ((process.env.NODE_ENV !== 'production') && hot) {
1477
+ throw new Error('cannot set hotState');
1478
+ }
1479
+ $patch(($state) => {
1480
+ assign($state, state);
1481
+ });
1482
+ },
1483
+ });
1484
+ // add the hotUpdate before plugins to allow them to override it
1485
+ /* istanbul ignore else */
1486
+ if ((process.env.NODE_ENV !== 'production')) {
1487
+ store._hotUpdate = markRaw((newStore) => {
1488
+ store._hotUpdating = true;
1489
+ newStore._hmrPayload.state.forEach((stateKey) => {
1490
+ if (stateKey in store.$state) {
1491
+ const newStateTarget = newStore.$state[stateKey];
1492
+ const oldStateSource = store.$state[stateKey];
1493
+ if (typeof newStateTarget === 'object' &&
1494
+ isPlainObject(newStateTarget) &&
1495
+ isPlainObject(oldStateSource)) {
1496
+ patchObject(newStateTarget, oldStateSource);
1497
+ }
1498
+ else {
1499
+ // transfer the ref
1500
+ newStore.$state[stateKey] = oldStateSource;
1501
+ }
1502
+ }
1503
+ // patch direct access properties to allow store.stateProperty to work as
1504
+ // store.$state.stateProperty
1505
+ set(store, stateKey, toRef(newStore.$state, stateKey));
1506
+ });
1507
+ // remove deleted state properties
1508
+ Object.keys(store.$state).forEach((stateKey) => {
1509
+ if (!(stateKey in newStore.$state)) {
1510
+ del(store, stateKey);
1511
+ }
1512
+ });
1513
+ // avoid devtools logging this as a mutation
1514
+ isListening = false;
1515
+ isSyncListening = false;
1516
+ pinia.state.value[$id] = toRef(newStore._hmrPayload, 'hotState');
1517
+ isSyncListening = true;
1518
+ nextTick().then(() => {
1519
+ isListening = true;
1520
+ });
1521
+ for (const actionName in newStore._hmrPayload.actions) {
1522
+ const action = newStore[actionName];
1523
+ set(store, actionName, wrapAction(actionName, action));
1524
+ }
1525
+ // TODO: does this work in both setup and option store?
1526
+ for (const getterName in newStore._hmrPayload.getters) {
1527
+ const getter = newStore._hmrPayload.getters[getterName];
1528
+ const getterValue = isOptionsStore
1529
+ ? // special handling of options api
1530
+ computed(() => {
1531
+ setActivePinia(pinia);
1532
+ return getter.call(store, store);
1533
+ })
1534
+ : getter;
1535
+ set(store, getterName, getterValue);
1536
+ }
1537
+ // remove deleted getters
1538
+ Object.keys(store._hmrPayload.getters).forEach((key) => {
1539
+ if (!(key in newStore._hmrPayload.getters)) {
1540
+ del(store, key);
1541
+ }
1542
+ });
1543
+ // remove old actions
1544
+ Object.keys(store._hmrPayload.actions).forEach((key) => {
1545
+ if (!(key in newStore._hmrPayload.actions)) {
1546
+ del(store, key);
1547
+ }
1548
+ });
1549
+ // update the values used in devtools and to allow deleting new properties later on
1550
+ store._hmrPayload = newStore._hmrPayload;
1551
+ store._getters = newStore._getters;
1552
+ store._hotUpdating = false;
1553
+ });
1554
+ const nonEnumerable = {
1555
+ writable: true,
1556
+ configurable: true,
1557
+ // avoid warning on devtools trying to display this property
1558
+ enumerable: false,
1559
+ };
1560
+ if (IS_CLIENT) {
1561
+ ['_p', '_hmrPayload', '_getters', '_customProperties'].forEach((p) => {
1562
+ Object.defineProperty(store, p, {
1563
+ value: store[p],
1564
+ ...nonEnumerable,
1565
+ });
1566
+ });
1567
+ }
1568
+ }
1569
+ /* istanbul ignore if */
1570
+ if (isVue2) {
1571
+ // mark the store as ready before plugins
1572
+ store._r = true;
1573
+ }
1574
+ // apply all plugins
1575
+ pinia._p.forEach((extender) => {
1576
+ /* istanbul ignore else */
1577
+ if ((process.env.NODE_ENV !== 'production') && IS_CLIENT) {
1578
+ const extensions = scope.run(() => extender({
1579
+ store,
1580
+ app: pinia._a,
1581
+ pinia,
1582
+ options: optionsForPlugin,
1583
+ }));
1584
+ Object.keys(extensions || {}).forEach((key) => store._customProperties.add(key));
1585
+ assign(store, extensions);
1586
+ }
1587
+ else {
1588
+ assign(store, scope.run(() => extender({
1589
+ store,
1590
+ app: pinia._a,
1591
+ pinia,
1592
+ options: optionsForPlugin,
1593
+ })));
1594
+ }
1595
+ });
1596
+ if ((process.env.NODE_ENV !== 'production') &&
1597
+ store.$state &&
1598
+ typeof store.$state === 'object' &&
1599
+ typeof store.$state.constructor === 'function' &&
1600
+ !store.$state.constructor.toString().includes('[native code]')) {
1601
+ console.warn(`[🍍]: The "state" must be a plain object. It cannot be\n` +
1602
+ `\tstate: () => new MyClass()\n` +
1603
+ `Found in store "${store.$id}".`);
1604
+ }
1605
+ // only apply hydrate to option stores with an initial state in pinia
1606
+ if (initialState &&
1607
+ isOptionsStore &&
1608
+ options.hydrate) {
1609
+ options.hydrate(store.$state, initialState);
1610
+ }
1611
+ isListening = true;
1612
+ isSyncListening = true;
1613
+ return store;
1614
+ }
1615
+ function defineStore(
1616
+ // TODO: add proper types from above
1617
+ idOrOptions, setup, setupOptions) {
1618
+ let id;
1619
+ let options;
1620
+ const isSetupStore = typeof setup === 'function';
1621
+ if (typeof idOrOptions === 'string') {
1622
+ id = idOrOptions;
1623
+ // the option store setup will contain the actual options in this case
1624
+ options = isSetupStore ? setupOptions : setup;
1625
+ }
1626
+ else {
1627
+ options = idOrOptions;
1628
+ id = idOrOptions.id;
1629
+ }
1630
+ function useStore(pinia, hot) {
1631
+ const currentInstance = getCurrentInstance();
1632
+ pinia =
1633
+ // in test mode, ignore the argument provided as we can always retrieve a
1634
+ // pinia instance with getActivePinia()
1635
+ ((process.env.NODE_ENV === 'test') && activePinia && activePinia._testing ? null : pinia) ||
1636
+ (currentInstance && inject(piniaSymbol));
1637
+ if (pinia)
1638
+ setActivePinia(pinia);
1639
+ if ((process.env.NODE_ENV !== 'production') && !activePinia) {
1640
+ throw new Error(`[🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia?\n` +
1641
+ `\tconst pinia = createPinia()\n` +
1642
+ `\tapp.use(pinia)\n` +
1643
+ `This will fail in production.`);
1644
+ }
1645
+ pinia = activePinia;
1646
+ if (!pinia._s.has(id)) {
1647
+ // creating the store registers it in `pinia._s`
1648
+ if (isSetupStore) {
1649
+ createSetupStore(id, setup, options, pinia);
1650
+ }
1651
+ else {
1652
+ createOptionsStore(id, options, pinia);
1653
+ }
1654
+ /* istanbul ignore else */
1655
+ if ((process.env.NODE_ENV !== 'production')) {
1656
+ // @ts-expect-error: not the right inferred type
1657
+ useStore._pinia = pinia;
1658
+ }
1659
+ }
1660
+ const store = pinia._s.get(id);
1661
+ if ((process.env.NODE_ENV !== 'production') && hot) {
1662
+ const hotId = '__hot:' + id;
1663
+ const newStore = isSetupStore
1664
+ ? createSetupStore(hotId, setup, options, pinia, true)
1665
+ : createOptionsStore(hotId, assign({}, options), pinia, true);
1666
+ hot._hotUpdate(newStore);
1667
+ // cleanup the state properties and the store from the cache
1668
+ delete pinia.state.value[hotId];
1669
+ pinia._s.delete(hotId);
1670
+ }
1671
+ // save stores in instances to access them devtools
1672
+ if ((process.env.NODE_ENV !== 'production') &&
1673
+ IS_CLIENT &&
1674
+ currentInstance &&
1675
+ currentInstance.proxy &&
1676
+ // avoid adding stores that are just built for hot module replacement
1677
+ !hot) {
1678
+ const vm = currentInstance.proxy;
1679
+ const cache = '_pStores' in vm ? vm._pStores : (vm._pStores = {});
1680
+ cache[id] = store;
1681
+ }
1682
+ // StoreGeneric cannot be casted towards Store
1683
+ return store;
1684
+ }
1685
+ useStore.$id = id;
1686
+ return useStore;
1687
+ }
1688
+
1689
+ let mapStoreSuffix = 'Store';
1690
+ /**
1691
+ * Changes the suffix added by `mapStores()`. Can be set to an empty string.
1692
+ * Defaults to `"Store"`. Make sure to extend the MapStoresCustomization
1693
+ * interface if you need are using TypeScript.
1694
+ *
1695
+ * @param suffix - new suffix
1696
+ */
1697
+ function setMapStoreSuffix(suffix // could be 'Store' but that would be annoying for JS
1698
+ ) {
1699
+ mapStoreSuffix = suffix;
1700
+ }
1701
+ /**
1702
+ * Allows using stores without the composition API (`setup()`) by generating an
1703
+ * object to be spread in the `computed` field of a component. It accepts a list
1704
+ * of store definitions.
1705
+ *
1706
+ * @example
1707
+ * ```js
1708
+ * export default {
1709
+ * computed: {
1710
+ * // other computed properties
1711
+ * ...mapStores(useUserStore, useCartStore)
1712
+ * },
1713
+ *
1714
+ * created() {
1715
+ * this.userStore // store with id "user"
1716
+ * this.cartStore // store with id "cart"
1717
+ * }
1718
+ * }
1719
+ * ```
1720
+ *
1721
+ * @param stores - list of stores to map to an object
1722
+ */
1723
+ function mapStores(...stores) {
1724
+ if ((process.env.NODE_ENV !== 'production') && Array.isArray(stores[0])) {
1725
+ console.warn(`[🍍]: Directly pass all stores to "mapStores()" without putting them in an array:\n` +
1726
+ `Replace\n` +
1727
+ `\tmapStores([useAuthStore, useCartStore])\n` +
1728
+ `with\n` +
1729
+ `\tmapStores(useAuthStore, useCartStore)\n` +
1730
+ `This will fail in production if not fixed.`);
1731
+ stores = stores[0];
1732
+ }
1733
+ return stores.reduce((reduced, useStore) => {
1734
+ // @ts-expect-error: $id is added by defineStore
1735
+ reduced[useStore.$id + mapStoreSuffix] = function () {
1736
+ return useStore(this.$pinia);
1737
+ };
1738
+ return reduced;
1739
+ }, {});
1740
+ }
1741
+ /**
1742
+ * Allows using state and getters from one store without using the composition
1743
+ * API (`setup()`) by generating an object to be spread in the `computed` field
1744
+ * of a component.
1745
+ *
1746
+ * @param useStore - store to map from
1747
+ * @param keysOrMapper - array or object
1748
+ */
1749
+ function mapState(useStore, keysOrMapper) {
1750
+ return Array.isArray(keysOrMapper)
1751
+ ? keysOrMapper.reduce((reduced, key) => {
1752
+ reduced[key] = function () {
1753
+ return useStore(this.$pinia)[key];
1754
+ };
1755
+ return reduced;
1756
+ }, {})
1757
+ : Object.keys(keysOrMapper).reduce((reduced, key) => {
1758
+ // @ts-expect-error
1759
+ reduced[key] = function () {
1760
+ const store = useStore(this.$pinia);
1761
+ const storeKey = keysOrMapper[key];
1762
+ // for some reason TS is unable to infer the type of storeKey to be a
1763
+ // function
1764
+ return typeof storeKey === 'function'
1765
+ ? storeKey.call(this, store)
1766
+ : store[storeKey];
1767
+ };
1768
+ return reduced;
1769
+ }, {});
1770
+ }
1771
+ /**
1772
+ * Alias for `mapState()`. You should use `mapState()` instead.
1773
+ * @deprecated use `mapState()` instead.
1774
+ */
1775
+ const mapGetters = mapState;
1776
+ /**
1777
+ * Allows directly using actions from your store without using the composition
1778
+ * API (`setup()`) by generating an object to be spread in the `methods` field
1779
+ * of a component.
1780
+ *
1781
+ * @param useStore - store to map from
1782
+ * @param keysOrMapper - array or object
1783
+ */
1784
+ function mapActions(useStore, keysOrMapper) {
1785
+ return Array.isArray(keysOrMapper)
1786
+ ? keysOrMapper.reduce((reduced, key) => {
1787
+ // @ts-expect-error
1788
+ reduced[key] = function (...args) {
1789
+ return useStore(this.$pinia)[key](...args);
1790
+ };
1791
+ return reduced;
1792
+ }, {})
1793
+ : Object.keys(keysOrMapper).reduce((reduced, key) => {
1794
+ // @ts-expect-error
1795
+ reduced[key] = function (...args) {
1796
+ return useStore(this.$pinia)[keysOrMapper[key]](...args);
1797
+ };
1798
+ return reduced;
1799
+ }, {});
1800
+ }
1801
+ /**
1802
+ * Allows using state and getters from one store without using the composition
1803
+ * API (`setup()`) by generating an object to be spread in the `computed` field
1804
+ * of a component.
1805
+ *
1806
+ * @param useStore - store to map from
1807
+ * @param keysOrMapper - array or object
1808
+ */
1809
+ function mapWritableState(useStore, keysOrMapper) {
1810
+ return Array.isArray(keysOrMapper)
1811
+ ? keysOrMapper.reduce((reduced, key) => {
1812
+ // @ts-ignore
1813
+ reduced[key] = {
1814
+ get() {
1815
+ return useStore(this.$pinia)[key];
1816
+ },
1817
+ set(value) {
1818
+ // it's easier to type it here as any
1819
+ return (useStore(this.$pinia)[key] = value);
1820
+ },
1821
+ };
1822
+ return reduced;
1823
+ }, {})
1824
+ : Object.keys(keysOrMapper).reduce((reduced, key) => {
1825
+ // @ts-ignore
1826
+ reduced[key] = {
1827
+ get() {
1828
+ return useStore(this.$pinia)[keysOrMapper[key]];
1829
+ },
1830
+ set(value) {
1831
+ // it's easier to type it here as any
1832
+ return (useStore(this.$pinia)[keysOrMapper[key]] = value);
1833
+ },
1834
+ };
1835
+ return reduced;
1836
+ }, {});
1837
+ }
1838
+
1839
+ /**
1840
+ * Creates an object of references with all the state, getters, and plugin-added
1841
+ * state properties of the store. Similar to `toRefs()` but specifically
1842
+ * designed for Pinia stores so methods and non reactive properties are
1843
+ * completely ignored.
1844
+ *
1845
+ * @param store - store to extract the refs from
1846
+ */
1847
+ function storeToRefs(store) {
1848
+ // See https://github.com/vuejs/pinia/issues/852
1849
+ // It's easier to just use toRefs() even if it includes more stuff
1850
+ if (isVue2) {
1851
+ // @ts-expect-error: toRefs include methods and others
1852
+ return toRefs(store);
1853
+ }
1854
+ else {
1855
+ store = toRaw(store);
1856
+ const refs = {};
1857
+ for (const key in store) {
1858
+ const value = store[key];
1859
+ if (isRef(value) || isReactive(value)) {
1860
+ // @ts-expect-error: the key is state or getter
1861
+ refs[key] =
1862
+ // ---
1863
+ toRef(store, key);
1864
+ }
1865
+ }
1866
+ return refs;
1867
+ }
1868
+ }
1869
+
1870
+ /**
1871
+ * Vue 2 Plugin that must be installed for pinia to work. Note **you don't need
1872
+ * this plugin if you are using Nuxt.js**. Use the `buildModule` instead:
1873
+ * https://pinia.vuejs.org/ssr/nuxt.html.
1874
+ *
1875
+ * @example
1876
+ * ```js
1877
+ * import Vue from 'vue'
1878
+ * import { PiniaVuePlugin, createPinia } from 'pinia'
1879
+ *
1880
+ * Vue.use(PiniaVuePlugin)
1881
+ * const pinia = createPinia()
1882
+ *
1883
+ * new Vue({
1884
+ * el: '#app',
1885
+ * // ...
1886
+ * pinia,
1887
+ * })
1888
+ * ```
1889
+ *
1890
+ * @param _Vue - `Vue` imported from 'vue'.
1891
+ */
1892
+ const PiniaVuePlugin = function (_Vue) {
1893
+ // Equivalent of
1894
+ // app.config.globalProperties.$pinia = pinia
1895
+ _Vue.mixin({
1896
+ beforeCreate() {
1897
+ const options = this.$options;
1898
+ if (options.pinia) {
1899
+ const pinia = options.pinia;
1900
+ // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30
1901
+ /* istanbul ignore else */
1902
+ if (!this._provided) {
1903
+ const provideCache = {};
1904
+ Object.defineProperty(this, '_provided', {
1905
+ get: () => provideCache,
1906
+ set: (v) => Object.assign(provideCache, v),
1907
+ });
1908
+ }
1909
+ this._provided[piniaSymbol] = pinia;
1910
+ // propagate the pinia instance in an SSR friendly way
1911
+ // avoid adding it to nuxt twice
1912
+ /* istanbul ignore else */
1913
+ if (!this.$pinia) {
1914
+ this.$pinia = pinia;
1915
+ }
1916
+ pinia._a = this;
1917
+ if (IS_CLIENT) {
1918
+ // this allows calling useStore() outside of a component setup after
1919
+ // installing pinia's plugin
1920
+ setActivePinia(pinia);
1921
+ if ((process.env.NODE_ENV !== 'production')) {
1922
+ registerPiniaDevtools(pinia._a, pinia);
1923
+ }
1924
+ }
1925
+ }
1926
+ else if (!this.$pinia && options.parent && options.parent.$pinia) {
1927
+ this.$pinia = options.parent.$pinia;
1928
+ }
1929
+ },
1930
+ destroyed() {
1931
+ delete this._pStores;
1932
+ },
1933
+ });
1934
+ };
1935
+
1936
+ export { MutationType, PiniaVuePlugin, acceptHMRUpdate, createPinia, defineStore, getActivePinia, mapActions, mapGetters, mapState, mapStores, mapWritableState, setActivePinia, setMapStoreSuffix, skipHydrate, storeToRefs };