@ditari/bsui 1.1.47 → 1.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/menu/Menu.cjs +6 -1
  4. package/dist/cjs/menu/Menu.cjs.map +1 -1
  5. package/dist/esm/index.mjs.map +1 -1
  6. package/dist/esm/menu/Menu.mjs +6 -1
  7. package/dist/esm/menu/Menu.mjs.map +1 -1
  8. package/package.json +7 -3
  9. package/example/index.html +0 -13
  10. package/example/node_modules/.vite/deps/@ant-design_icons-vue.js +0 -29406
  11. package/example/node_modules/.vite/deps/@ant-design_icons-vue.js.map +0 -7
  12. package/example/node_modules/.vite/deps/@vueuse_core.js +0 -8255
  13. package/example/node_modules/.vite/deps/@vueuse_core.js.map +0 -7
  14. package/example/node_modules/.vite/deps/_metadata.json +0 -80
  15. package/example/node_modules/.vite/deps/ant-design-vue.js +0 -62756
  16. package/example/node_modules/.vite/deps/ant-design-vue.js.map +0 -7
  17. package/example/node_modules/.vite/deps/axios.js +0 -2126
  18. package/example/node_modules/.vite/deps/axios.js.map +0 -7
  19. package/example/node_modules/.vite/deps/chunk-5WWUZCGV.js +0 -36
  20. package/example/node_modules/.vite/deps/chunk-5WWUZCGV.js.map +0 -7
  21. package/example/node_modules/.vite/deps/chunk-D36HXFYL.js +0 -25
  22. package/example/node_modules/.vite/deps/chunk-D36HXFYL.js.map +0 -7
  23. package/example/node_modules/.vite/deps/chunk-EBDM3ESC.js +0 -161
  24. package/example/node_modules/.vite/deps/chunk-EBDM3ESC.js.map +0 -7
  25. package/example/node_modules/.vite/deps/chunk-EKNPBJBG.js +0 -3600
  26. package/example/node_modules/.vite/deps/chunk-EKNPBJBG.js.map +0 -7
  27. package/example/node_modules/.vite/deps/chunk-GK7Q6YQN.js +0 -10796
  28. package/example/node_modules/.vite/deps/chunk-GK7Q6YQN.js.map +0 -7
  29. package/example/node_modules/.vite/deps/chunk-TDI2FIXO.js +0 -19
  30. package/example/node_modules/.vite/deps/chunk-TDI2FIXO.js.map +0 -7
  31. package/example/node_modules/.vite/deps/package.json +0 -3
  32. package/example/node_modules/.vite/deps/pinia-plugin-persistedstate.js +0 -125
  33. package/example/node_modules/.vite/deps/pinia-plugin-persistedstate.js.map +0 -7
  34. package/example/node_modules/.vite/deps/pinia.js +0 -1519
  35. package/example/node_modules/.vite/deps/pinia.js.map +0 -7
  36. package/example/node_modules/.vite/deps/vue-request.js +0 -1191
  37. package/example/node_modules/.vite/deps/vue-request.js.map +0 -7
  38. package/example/node_modules/.vite/deps/vue-router.js +0 -2667
  39. package/example/node_modules/.vite/deps/vue-router.js.map +0 -7
  40. package/example/node_modules/.vite/deps/vue.js +0 -314
  41. package/example/node_modules/.vite/deps/vue.js.map +0 -7
  42. package/example/package.json +0 -17
  43. package/example/src/App.vue +0 -7
  44. package/example/src/api/list.ts +0 -22
  45. package/example/src/api/user.ts +0 -13
  46. package/example/src/components/AppMain.vue +0 -113
  47. package/example/src/hooks.ts +0 -103
  48. package/example/src/main.ts +0 -22
  49. package/example/src/router/form/index.route.ts +0 -23
  50. package/example/src/router/index.ts +0 -61
  51. package/example/src/router/table/index.route.ts +0 -39
  52. package/example/src/views/Demo.vue +0 -49
  53. package/example/src/views/DemoBk.vue +0 -34
  54. package/example/src/views/Login.vue +0 -79
  55. package/example/src/views/form/List.vue +0 -16
  56. package/example/src/views/form/List2.vue +0 -74
  57. package/example/src/views/form/QueryFormDemo.vue +0 -49
  58. package/example/src/views/form/dyn/List.vue +0 -121
  59. package/example/src/views/table/Add.vue +0 -377
  60. package/example/src/views/table/Demo.vue +0 -15
  61. package/example/src/views/table/Demo2.vue +0 -12
  62. package/example/src/views/table/Edit.vue +0 -10
  63. package/example/src/views/table/List.vue +0 -415
  64. package/example/src/views/table/Test.tsx +0 -42
  65. package/example/src/views/table/TestModal.vue +0 -64
  66. package/example/src/views/table/WorkStatusRound.vue +0 -31
  67. package/example/src/views/table/components/AddForm.vue +0 -44
  68. package/example/src/views/table/hooks.ts +0 -106
  69. package/example/src/views/task/Todo.vue +0 -6
  70. package/example/tsconfig.json +0 -16
  71. package/example/utils/http.ts +0 -107
  72. package/example/vite-env.d.ts +0 -8
  73. package/example/vite.config.ts +0 -10
  74. package/src/_utils/html.ts +0 -17
  75. package/src/_utils/install.ts +0 -12
  76. package/src/components.ts +0 -10
  77. package/src/config/Config.vue +0 -8
  78. package/src/date/RangePicker.tsx +0 -93
  79. package/src/date/index.ts +0 -9
  80. package/src/desensitize/Desensitize.tsx +0 -97
  81. package/src/desensitize/index.ts +0 -9
  82. package/src/desensitize/style/index.scss +0 -8
  83. package/src/dic/DicReplace.tsx +0 -63
  84. package/src/dic/index.ts +0 -8
  85. package/src/dic/replace.worker.ts +0 -25
  86. package/src/form/DQueryForm.tsx +0 -258
  87. package/src/form/index.ts +0 -9
  88. package/src/form/style/index.less +0 -0
  89. package/src/grid/Grid.tsx +0 -83
  90. package/src/grid/GridItem.tsx +0 -15
  91. package/src/grid/index.md +0 -4
  92. package/src/grid/index.ts +0 -16
  93. package/src/grid/style/index.scss +0 -70
  94. package/src/index.scss +0 -19
  95. package/src/index.ts +0 -50
  96. package/src/json-scheme-render/JsonSchemeRender.tsx +0 -101
  97. package/src/json-scheme-render/index.ts +0 -9
  98. package/src/layout/Breadcrumb.vue +0 -39
  99. package/src/layout/FuckMain.vue +0 -90
  100. package/src/layout/List.vue +0 -145
  101. package/src/layout/Main.vue +0 -97
  102. package/src/layout/NavTabs.vue +0 -129
  103. package/src/layout/Show.vue +0 -135
  104. package/src/layout/index.ts +0 -24
  105. package/src/layout/style/breadcrumb.scss +0 -61
  106. package/src/layout/style/fuckmain.scss +0 -21
  107. package/src/layout/style/index.scss +0 -35
  108. package/src/layout/style/list.scss +0 -26
  109. package/src/layout/style/main.scss +0 -74
  110. package/src/layout/style/navtab.scss +0 -146
  111. package/src/layout/style/show.scss +0 -50
  112. package/src/menu/Menu.tsx +0 -181
  113. package/src/menu/style/index.scss +0 -26
  114. package/src/modal/Modal.tsx +0 -83
  115. package/src/modal/index.ts +0 -9
  116. package/src/modal/style/index.scss +0 -74
  117. package/src/select/Select.vue +0 -177
  118. package/src/select/dic.worker.ts +0 -32
  119. package/src/select/index.ts +0 -9
  120. package/src/table/Field.vue +0 -44
  121. package/src/table/Table.tsx +0 -515
  122. package/src/table/index.md +0 -1
  123. package/src/table/index.ts +0 -9
  124. package/src/table/interface/table.ts +0 -64
  125. package/src/table/style/index.scss +0 -10
  126. package/src/theme/index.ts +0 -1
  127. package/src/theme/theme.scss +0 -1
  128. package/src/theme/variable.scss +0 -67
@@ -1,1519 +0,0 @@
1
- import {
2
- del,
3
- isVue2,
4
- set
5
- } from "./chunk-D36HXFYL.js";
6
- import {
7
- setupDevtoolsPlugin
8
- } from "./chunk-EBDM3ESC.js";
9
- import {
10
- computed,
11
- effectScope,
12
- getCurrentInstance,
13
- getCurrentScope,
14
- hasInjectionContext,
15
- inject,
16
- isReactive,
17
- isRef,
18
- markRaw,
19
- nextTick,
20
- onScopeDispose,
21
- reactive,
22
- ref,
23
- toRaw,
24
- toRef,
25
- toRefs,
26
- unref,
27
- watch
28
- } from "./chunk-GK7Q6YQN.js";
29
- import "./chunk-5WWUZCGV.js";
30
-
31
- // ../../../node_modules/.pnpm/pinia@2.1.4_@vue+composition-api@1.7.1_typescript@4.9.5_vue@3.3.4/node_modules/pinia/dist/pinia.mjs
32
- var activePinia;
33
- var setActivePinia = (pinia) => activePinia = pinia;
34
- var getActivePinia = () => hasInjectionContext() && inject(piniaSymbol) || activePinia;
35
- var piniaSymbol = true ? Symbol("pinia") : (
36
- /* istanbul ignore next */
37
- Symbol()
38
- );
39
- function isPlainObject(o) {
40
- return o && typeof o === "object" && Object.prototype.toString.call(o) === "[object Object]" && typeof o.toJSON !== "function";
41
- }
42
- var MutationType;
43
- (function(MutationType2) {
44
- MutationType2["direct"] = "direct";
45
- MutationType2["patchObject"] = "patch object";
46
- MutationType2["patchFunction"] = "patch function";
47
- })(MutationType || (MutationType = {}));
48
- var IS_CLIENT = typeof window !== "undefined";
49
- var USE_DEVTOOLS = IS_CLIENT;
50
- var _global = (() => typeof window === "object" && window.window === window ? window : typeof self === "object" && self.self === self ? self : typeof global === "object" && global.global === global ? global : typeof globalThis === "object" ? globalThis : { HTMLElement: null })();
51
- function bom(blob, { autoBom = false } = {}) {
52
- if (autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
53
- return new Blob([String.fromCharCode(65279), blob], { type: blob.type });
54
- }
55
- return blob;
56
- }
57
- function download(url, name, opts) {
58
- const xhr = new XMLHttpRequest();
59
- xhr.open("GET", url);
60
- xhr.responseType = "blob";
61
- xhr.onload = function() {
62
- saveAs(xhr.response, name, opts);
63
- };
64
- xhr.onerror = function() {
65
- console.error("could not download file");
66
- };
67
- xhr.send();
68
- }
69
- function corsEnabled(url) {
70
- const xhr = new XMLHttpRequest();
71
- xhr.open("HEAD", url, false);
72
- try {
73
- xhr.send();
74
- } catch (e) {
75
- }
76
- return xhr.status >= 200 && xhr.status <= 299;
77
- }
78
- function click(node) {
79
- try {
80
- node.dispatchEvent(new MouseEvent("click"));
81
- } catch (e) {
82
- const evt = document.createEvent("MouseEvents");
83
- evt.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
84
- node.dispatchEvent(evt);
85
- }
86
- }
87
- var _navigator = typeof navigator === "object" ? navigator : { userAgent: "" };
88
- var isMacOSWebView = (() => /Macintosh/.test(_navigator.userAgent) && /AppleWebKit/.test(_navigator.userAgent) && !/Safari/.test(_navigator.userAgent))();
89
- var saveAs = !IS_CLIENT ? () => {
90
- } : (
91
- // Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView or mini program
92
- typeof HTMLAnchorElement !== "undefined" && "download" in HTMLAnchorElement.prototype && !isMacOSWebView ? downloadSaveAs : (
93
- // Use msSaveOrOpenBlob as a second approach
94
- "msSaveOrOpenBlob" in _navigator ? msSaveAs : (
95
- // Fallback to using FileReader and a popup
96
- fileSaverSaveAs
97
- )
98
- )
99
- );
100
- function downloadSaveAs(blob, name = "download", opts) {
101
- const a = document.createElement("a");
102
- a.download = name;
103
- a.rel = "noopener";
104
- if (typeof blob === "string") {
105
- a.href = blob;
106
- if (a.origin !== location.origin) {
107
- if (corsEnabled(a.href)) {
108
- download(blob, name, opts);
109
- } else {
110
- a.target = "_blank";
111
- click(a);
112
- }
113
- } else {
114
- click(a);
115
- }
116
- } else {
117
- a.href = URL.createObjectURL(blob);
118
- setTimeout(function() {
119
- URL.revokeObjectURL(a.href);
120
- }, 4e4);
121
- setTimeout(function() {
122
- click(a);
123
- }, 0);
124
- }
125
- }
126
- function msSaveAs(blob, name = "download", opts) {
127
- if (typeof blob === "string") {
128
- if (corsEnabled(blob)) {
129
- download(blob, name, opts);
130
- } else {
131
- const a = document.createElement("a");
132
- a.href = blob;
133
- a.target = "_blank";
134
- setTimeout(function() {
135
- click(a);
136
- });
137
- }
138
- } else {
139
- navigator.msSaveOrOpenBlob(bom(blob, opts), name);
140
- }
141
- }
142
- function fileSaverSaveAs(blob, name, opts, popup) {
143
- popup = popup || open("", "_blank");
144
- if (popup) {
145
- popup.document.title = popup.document.body.innerText = "downloading...";
146
- }
147
- if (typeof blob === "string")
148
- return download(blob, name, opts);
149
- const force = blob.type === "application/octet-stream";
150
- const isSafari = /constructor/i.test(String(_global.HTMLElement)) || "safari" in _global;
151
- const isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
152
- if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== "undefined") {
153
- const reader = new FileReader();
154
- reader.onloadend = function() {
155
- let url = reader.result;
156
- if (typeof url !== "string") {
157
- popup = null;
158
- throw new Error("Wrong reader.result type");
159
- }
160
- url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, "data:attachment/file;");
161
- if (popup) {
162
- popup.location.href = url;
163
- } else {
164
- location.assign(url);
165
- }
166
- popup = null;
167
- };
168
- reader.readAsDataURL(blob);
169
- } else {
170
- const url = URL.createObjectURL(blob);
171
- if (popup)
172
- popup.location.assign(url);
173
- else
174
- location.href = url;
175
- popup = null;
176
- setTimeout(function() {
177
- URL.revokeObjectURL(url);
178
- }, 4e4);
179
- }
180
- }
181
- function toastMessage(message, type) {
182
- const piniaMessage = "🍍 " + message;
183
- if (typeof __VUE_DEVTOOLS_TOAST__ === "function") {
184
- __VUE_DEVTOOLS_TOAST__(piniaMessage, type);
185
- } else if (type === "error") {
186
- console.error(piniaMessage);
187
- } else if (type === "warn") {
188
- console.warn(piniaMessage);
189
- } else {
190
- console.log(piniaMessage);
191
- }
192
- }
193
- function isPinia(o) {
194
- return "_a" in o && "install" in o;
195
- }
196
- function checkClipboardAccess() {
197
- if (!("clipboard" in navigator)) {
198
- toastMessage(`Your browser doesn't support the Clipboard API`, "error");
199
- return true;
200
- }
201
- }
202
- function checkNotFocusedError(error) {
203
- if (error instanceof Error && error.message.toLowerCase().includes("document is not focused")) {
204
- toastMessage('You need to activate the "Emulate a focused page" setting in the "Rendering" panel of devtools.', "warn");
205
- return true;
206
- }
207
- return false;
208
- }
209
- async function actionGlobalCopyState(pinia) {
210
- if (checkClipboardAccess())
211
- return;
212
- try {
213
- await navigator.clipboard.writeText(JSON.stringify(pinia.state.value));
214
- toastMessage("Global state copied to clipboard.");
215
- } catch (error) {
216
- if (checkNotFocusedError(error))
217
- return;
218
- toastMessage(`Failed to serialize the state. Check the console for more details.`, "error");
219
- console.error(error);
220
- }
221
- }
222
- async function actionGlobalPasteState(pinia) {
223
- if (checkClipboardAccess())
224
- return;
225
- try {
226
- pinia.state.value = JSON.parse(await navigator.clipboard.readText());
227
- toastMessage("Global state pasted from clipboard.");
228
- } catch (error) {
229
- if (checkNotFocusedError(error))
230
- return;
231
- toastMessage(`Failed to deserialize the state from clipboard. Check the console for more details.`, "error");
232
- console.error(error);
233
- }
234
- }
235
- async function actionGlobalSaveState(pinia) {
236
- try {
237
- saveAs(new Blob([JSON.stringify(pinia.state.value)], {
238
- type: "text/plain;charset=utf-8"
239
- }), "pinia-state.json");
240
- } catch (error) {
241
- toastMessage(`Failed to export the state as JSON. Check the console for more details.`, "error");
242
- console.error(error);
243
- }
244
- }
245
- var fileInput;
246
- function getFileOpener() {
247
- if (!fileInput) {
248
- fileInput = document.createElement("input");
249
- fileInput.type = "file";
250
- fileInput.accept = ".json";
251
- }
252
- function openFile() {
253
- return new Promise((resolve, reject) => {
254
- fileInput.onchange = async () => {
255
- const files = fileInput.files;
256
- if (!files)
257
- return resolve(null);
258
- const file = files.item(0);
259
- if (!file)
260
- return resolve(null);
261
- return resolve({ text: await file.text(), file });
262
- };
263
- fileInput.oncancel = () => resolve(null);
264
- fileInput.onerror = reject;
265
- fileInput.click();
266
- });
267
- }
268
- return openFile;
269
- }
270
- async function actionGlobalOpenStateFile(pinia) {
271
- try {
272
- const open2 = await getFileOpener();
273
- const result = await open2();
274
- if (!result)
275
- return;
276
- const { text, file } = result;
277
- pinia.state.value = JSON.parse(text);
278
- toastMessage(`Global state imported from "${file.name}".`);
279
- } catch (error) {
280
- toastMessage(`Failed to export the state as JSON. Check the console for more details.`, "error");
281
- console.error(error);
282
- }
283
- }
284
- function formatDisplay(display) {
285
- return {
286
- _custom: {
287
- display
288
- }
289
- };
290
- }
291
- var PINIA_ROOT_LABEL = "🍍 Pinia (root)";
292
- var PINIA_ROOT_ID = "_root";
293
- function formatStoreForInspectorTree(store) {
294
- return isPinia(store) ? {
295
- id: PINIA_ROOT_ID,
296
- label: PINIA_ROOT_LABEL
297
- } : {
298
- id: store.$id,
299
- label: store.$id
300
- };
301
- }
302
- function formatStoreForInspectorState(store) {
303
- if (isPinia(store)) {
304
- const storeNames = Array.from(store._s.keys());
305
- const storeMap = store._s;
306
- const state2 = {
307
- state: storeNames.map((storeId) => ({
308
- editable: true,
309
- key: storeId,
310
- value: store.state.value[storeId]
311
- })),
312
- getters: storeNames.filter((id) => storeMap.get(id)._getters).map((id) => {
313
- const store2 = storeMap.get(id);
314
- return {
315
- editable: false,
316
- key: id,
317
- value: store2._getters.reduce((getters, key) => {
318
- getters[key] = store2[key];
319
- return getters;
320
- }, {})
321
- };
322
- })
323
- };
324
- return state2;
325
- }
326
- const state = {
327
- state: Object.keys(store.$state).map((key) => ({
328
- editable: true,
329
- key,
330
- value: store.$state[key]
331
- }))
332
- };
333
- if (store._getters && store._getters.length) {
334
- state.getters = store._getters.map((getterName) => ({
335
- editable: false,
336
- key: getterName,
337
- value: store[getterName]
338
- }));
339
- }
340
- if (store._customProperties.size) {
341
- state.customProperties = Array.from(store._customProperties).map((key) => ({
342
- editable: true,
343
- key,
344
- value: store[key]
345
- }));
346
- }
347
- return state;
348
- }
349
- function formatEventData(events) {
350
- if (!events)
351
- return {};
352
- if (Array.isArray(events)) {
353
- return events.reduce((data, event) => {
354
- data.keys.push(event.key);
355
- data.operations.push(event.type);
356
- data.oldValue[event.key] = event.oldValue;
357
- data.newValue[event.key] = event.newValue;
358
- return data;
359
- }, {
360
- oldValue: {},
361
- keys: [],
362
- operations: [],
363
- newValue: {}
364
- });
365
- } else {
366
- return {
367
- operation: formatDisplay(events.type),
368
- key: formatDisplay(events.key),
369
- oldValue: events.oldValue,
370
- newValue: events.newValue
371
- };
372
- }
373
- }
374
- function formatMutationType(type) {
375
- switch (type) {
376
- case MutationType.direct:
377
- return "mutation";
378
- case MutationType.patchFunction:
379
- return "$patch";
380
- case MutationType.patchObject:
381
- return "$patch";
382
- default:
383
- return "unknown";
384
- }
385
- }
386
- var isTimelineActive = true;
387
- var componentStateTypes = [];
388
- var MUTATIONS_LAYER_ID = "pinia:mutations";
389
- var INSPECTOR_ID = "pinia";
390
- var { assign: assign$1 } = Object;
391
- var getStoreType = (id) => "🍍 " + id;
392
- function registerPiniaDevtools(app, pinia) {
393
- setupDevtoolsPlugin({
394
- id: "dev.esm.pinia",
395
- label: "Pinia 🍍",
396
- logo: "https://pinia.vuejs.org/logo.svg",
397
- packageName: "pinia",
398
- homepage: "https://pinia.vuejs.org",
399
- componentStateTypes,
400
- app
401
- }, (api) => {
402
- if (typeof api.now !== "function") {
403
- 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.");
404
- }
405
- api.addTimelineLayer({
406
- id: MUTATIONS_LAYER_ID,
407
- label: `Pinia 🍍`,
408
- color: 15064968
409
- });
410
- api.addInspector({
411
- id: INSPECTOR_ID,
412
- label: "Pinia 🍍",
413
- icon: "storage",
414
- treeFilterPlaceholder: "Search stores",
415
- actions: [
416
- {
417
- icon: "content_copy",
418
- action: () => {
419
- actionGlobalCopyState(pinia);
420
- },
421
- tooltip: "Serialize and copy the state"
422
- },
423
- {
424
- icon: "content_paste",
425
- action: async () => {
426
- await actionGlobalPasteState(pinia);
427
- api.sendInspectorTree(INSPECTOR_ID);
428
- api.sendInspectorState(INSPECTOR_ID);
429
- },
430
- tooltip: "Replace the state with the content of your clipboard"
431
- },
432
- {
433
- icon: "save",
434
- action: () => {
435
- actionGlobalSaveState(pinia);
436
- },
437
- tooltip: "Save the state as a JSON file"
438
- },
439
- {
440
- icon: "folder_open",
441
- action: async () => {
442
- await actionGlobalOpenStateFile(pinia);
443
- api.sendInspectorTree(INSPECTOR_ID);
444
- api.sendInspectorState(INSPECTOR_ID);
445
- },
446
- tooltip: "Import the state from a JSON file"
447
- }
448
- ],
449
- nodeActions: [
450
- {
451
- icon: "restore",
452
- tooltip: 'Reset the state (with "$reset")',
453
- action: (nodeId) => {
454
- const store = pinia._s.get(nodeId);
455
- if (!store) {
456
- toastMessage(`Cannot reset "${nodeId}" store because it wasn't found.`, "warn");
457
- } else if (typeof store.$reset !== "function") {
458
- toastMessage(`Cannot reset "${nodeId}" store because it doesn't have a "$reset" method implemented.`, "warn");
459
- } else {
460
- store.$reset();
461
- toastMessage(`Store "${nodeId}" reset.`);
462
- }
463
- }
464
- }
465
- ]
466
- });
467
- api.on.inspectComponent((payload, ctx) => {
468
- const proxy = payload.componentInstance && payload.componentInstance.proxy;
469
- if (proxy && proxy._pStores) {
470
- const piniaStores = payload.componentInstance.proxy._pStores;
471
- Object.values(piniaStores).forEach((store) => {
472
- payload.instanceData.state.push({
473
- type: getStoreType(store.$id),
474
- key: "state",
475
- editable: true,
476
- value: store._isOptionsAPI ? {
477
- _custom: {
478
- value: toRaw(store.$state),
479
- actions: [
480
- {
481
- icon: "restore",
482
- tooltip: "Reset the state of this store",
483
- action: () => store.$reset()
484
- }
485
- ]
486
- }
487
- } : (
488
- // NOTE: workaround to unwrap transferred refs
489
- Object.keys(store.$state).reduce((state, key) => {
490
- state[key] = store.$state[key];
491
- return state;
492
- }, {})
493
- )
494
- });
495
- if (store._getters && store._getters.length) {
496
- payload.instanceData.state.push({
497
- type: getStoreType(store.$id),
498
- key: "getters",
499
- editable: false,
500
- value: store._getters.reduce((getters, key) => {
501
- try {
502
- getters[key] = store[key];
503
- } catch (error) {
504
- getters[key] = error;
505
- }
506
- return getters;
507
- }, {})
508
- });
509
- }
510
- });
511
- }
512
- });
513
- api.on.getInspectorTree((payload) => {
514
- if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
515
- let stores = [pinia];
516
- stores = stores.concat(Array.from(pinia._s.values()));
517
- payload.rootNodes = (payload.filter ? stores.filter((store) => "$id" in store ? store.$id.toLowerCase().includes(payload.filter.toLowerCase()) : PINIA_ROOT_LABEL.toLowerCase().includes(payload.filter.toLowerCase())) : stores).map(formatStoreForInspectorTree);
518
- }
519
- });
520
- api.on.getInspectorState((payload) => {
521
- if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
522
- const inspectedStore = payload.nodeId === PINIA_ROOT_ID ? pinia : pinia._s.get(payload.nodeId);
523
- if (!inspectedStore) {
524
- return;
525
- }
526
- if (inspectedStore) {
527
- payload.state = formatStoreForInspectorState(inspectedStore);
528
- }
529
- }
530
- });
531
- api.on.editInspectorState((payload, ctx) => {
532
- if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
533
- const inspectedStore = payload.nodeId === PINIA_ROOT_ID ? pinia : pinia._s.get(payload.nodeId);
534
- if (!inspectedStore) {
535
- return toastMessage(`store "${payload.nodeId}" not found`, "error");
536
- }
537
- const { path } = payload;
538
- if (!isPinia(inspectedStore)) {
539
- if (path.length !== 1 || !inspectedStore._customProperties.has(path[0]) || path[0] in inspectedStore.$state) {
540
- path.unshift("$state");
541
- }
542
- } else {
543
- path.unshift("state");
544
- }
545
- isTimelineActive = false;
546
- payload.set(inspectedStore, path, payload.state.value);
547
- isTimelineActive = true;
548
- }
549
- });
550
- api.on.editComponentState((payload) => {
551
- if (payload.type.startsWith("🍍")) {
552
- const storeId = payload.type.replace(/^🍍\s*/, "");
553
- const store = pinia._s.get(storeId);
554
- if (!store) {
555
- return toastMessage(`store "${storeId}" not found`, "error");
556
- }
557
- const { path } = payload;
558
- if (path[0] !== "state") {
559
- return toastMessage(`Invalid path for store "${storeId}":
560
- ${path}
561
- Only state can be modified.`);
562
- }
563
- path[0] = "$state";
564
- isTimelineActive = false;
565
- payload.set(store, path, payload.state.value);
566
- isTimelineActive = true;
567
- }
568
- });
569
- });
570
- }
571
- function addStoreToDevtools(app, store) {
572
- if (!componentStateTypes.includes(getStoreType(store.$id))) {
573
- componentStateTypes.push(getStoreType(store.$id));
574
- }
575
- setupDevtoolsPlugin({
576
- id: "dev.esm.pinia",
577
- label: "Pinia 🍍",
578
- logo: "https://pinia.vuejs.org/logo.svg",
579
- packageName: "pinia",
580
- homepage: "https://pinia.vuejs.org",
581
- componentStateTypes,
582
- app,
583
- settings: {
584
- logStoreChanges: {
585
- label: "Notify about new/deleted stores",
586
- type: "boolean",
587
- defaultValue: true
588
- }
589
- // useEmojis: {
590
- // label: 'Use emojis in messages ⚡️',
591
- // type: 'boolean',
592
- // defaultValue: true,
593
- // },
594
- }
595
- }, (api) => {
596
- const now = typeof api.now === "function" ? api.now.bind(api) : Date.now;
597
- store.$onAction(({ after, onError, name, args }) => {
598
- const groupId = runningActionId++;
599
- api.addTimelineEvent({
600
- layerId: MUTATIONS_LAYER_ID,
601
- event: {
602
- time: now(),
603
- title: "🛫 " + name,
604
- subtitle: "start",
605
- data: {
606
- store: formatDisplay(store.$id),
607
- action: formatDisplay(name),
608
- args
609
- },
610
- groupId
611
- }
612
- });
613
- after((result) => {
614
- activeAction = void 0;
615
- api.addTimelineEvent({
616
- layerId: MUTATIONS_LAYER_ID,
617
- event: {
618
- time: now(),
619
- title: "🛬 " + name,
620
- subtitle: "end",
621
- data: {
622
- store: formatDisplay(store.$id),
623
- action: formatDisplay(name),
624
- args,
625
- result
626
- },
627
- groupId
628
- }
629
- });
630
- });
631
- onError((error) => {
632
- activeAction = void 0;
633
- api.addTimelineEvent({
634
- layerId: MUTATIONS_LAYER_ID,
635
- event: {
636
- time: now(),
637
- logType: "error",
638
- title: "💥 " + name,
639
- subtitle: "end",
640
- data: {
641
- store: formatDisplay(store.$id),
642
- action: formatDisplay(name),
643
- args,
644
- error
645
- },
646
- groupId
647
- }
648
- });
649
- });
650
- }, true);
651
- store._customProperties.forEach((name) => {
652
- watch(() => unref(store[name]), (newValue, oldValue) => {
653
- api.notifyComponentUpdate();
654
- api.sendInspectorState(INSPECTOR_ID);
655
- if (isTimelineActive) {
656
- api.addTimelineEvent({
657
- layerId: MUTATIONS_LAYER_ID,
658
- event: {
659
- time: now(),
660
- title: "Change",
661
- subtitle: name,
662
- data: {
663
- newValue,
664
- oldValue
665
- },
666
- groupId: activeAction
667
- }
668
- });
669
- }
670
- }, { deep: true });
671
- });
672
- store.$subscribe(({ events, type }, state) => {
673
- api.notifyComponentUpdate();
674
- api.sendInspectorState(INSPECTOR_ID);
675
- if (!isTimelineActive)
676
- return;
677
- const eventData = {
678
- time: now(),
679
- title: formatMutationType(type),
680
- data: assign$1({ store: formatDisplay(store.$id) }, formatEventData(events)),
681
- groupId: activeAction
682
- };
683
- if (type === MutationType.patchFunction) {
684
- eventData.subtitle = "⤵️";
685
- } else if (type === MutationType.patchObject) {
686
- eventData.subtitle = "🧩";
687
- } else if (events && !Array.isArray(events)) {
688
- eventData.subtitle = events.type;
689
- }
690
- if (events) {
691
- eventData.data["rawEvent(s)"] = {
692
- _custom: {
693
- display: "DebuggerEvent",
694
- type: "object",
695
- tooltip: "raw DebuggerEvent[]",
696
- value: events
697
- }
698
- };
699
- }
700
- api.addTimelineEvent({
701
- layerId: MUTATIONS_LAYER_ID,
702
- event: eventData
703
- });
704
- }, { detached: true, flush: "sync" });
705
- const hotUpdate = store._hotUpdate;
706
- store._hotUpdate = markRaw((newStore) => {
707
- hotUpdate(newStore);
708
- api.addTimelineEvent({
709
- layerId: MUTATIONS_LAYER_ID,
710
- event: {
711
- time: now(),
712
- title: "🔥 " + store.$id,
713
- subtitle: "HMR update",
714
- data: {
715
- store: formatDisplay(store.$id),
716
- info: formatDisplay(`HMR update`)
717
- }
718
- }
719
- });
720
- api.notifyComponentUpdate();
721
- api.sendInspectorTree(INSPECTOR_ID);
722
- api.sendInspectorState(INSPECTOR_ID);
723
- });
724
- const { $dispose } = store;
725
- store.$dispose = () => {
726
- $dispose();
727
- api.notifyComponentUpdate();
728
- api.sendInspectorTree(INSPECTOR_ID);
729
- api.sendInspectorState(INSPECTOR_ID);
730
- api.getSettings().logStoreChanges && toastMessage(`Disposed "${store.$id}" store 🗑`);
731
- };
732
- api.notifyComponentUpdate();
733
- api.sendInspectorTree(INSPECTOR_ID);
734
- api.sendInspectorState(INSPECTOR_ID);
735
- api.getSettings().logStoreChanges && toastMessage(`"${store.$id}" store installed 🆕`);
736
- });
737
- }
738
- var runningActionId = 0;
739
- var activeAction;
740
- function patchActionForGrouping(store, actionNames, wrapWithProxy) {
741
- const actions = actionNames.reduce((storeActions, actionName) => {
742
- storeActions[actionName] = toRaw(store)[actionName];
743
- return storeActions;
744
- }, {});
745
- for (const actionName in actions) {
746
- store[actionName] = function() {
747
- const _actionId = runningActionId;
748
- const trackedStore = wrapWithProxy ? new Proxy(store, {
749
- get(...args) {
750
- activeAction = _actionId;
751
- return Reflect.get(...args);
752
- },
753
- set(...args) {
754
- activeAction = _actionId;
755
- return Reflect.set(...args);
756
- }
757
- }) : store;
758
- activeAction = _actionId;
759
- const retValue = actions[actionName].apply(trackedStore, arguments);
760
- activeAction = void 0;
761
- return retValue;
762
- };
763
- }
764
- }
765
- function devtoolsPlugin({ app, store, options }) {
766
- if (store.$id.startsWith("__hot:")) {
767
- return;
768
- }
769
- store._isOptionsAPI = !!options.state;
770
- patchActionForGrouping(store, Object.keys(options.actions), store._isOptionsAPI);
771
- const originalHotUpdate = store._hotUpdate;
772
- toRaw(store)._hotUpdate = function(newStore) {
773
- originalHotUpdate.apply(this, arguments);
774
- patchActionForGrouping(store, Object.keys(newStore._hmrPayload.actions), !!store._isOptionsAPI);
775
- };
776
- addStoreToDevtools(
777
- app,
778
- // FIXME: is there a way to allow the assignment from Store<Id, S, G, A> to StoreGeneric?
779
- store
780
- );
781
- }
782
- function createPinia() {
783
- const scope = effectScope(true);
784
- const state = scope.run(() => ref({}));
785
- let _p = [];
786
- let toBeInstalled = [];
787
- const pinia = markRaw({
788
- install(app) {
789
- setActivePinia(pinia);
790
- if (!isVue2) {
791
- pinia._a = app;
792
- app.provide(piniaSymbol, pinia);
793
- app.config.globalProperties.$pinia = pinia;
794
- if (USE_DEVTOOLS) {
795
- registerPiniaDevtools(app, pinia);
796
- }
797
- toBeInstalled.forEach((plugin) => _p.push(plugin));
798
- toBeInstalled = [];
799
- }
800
- },
801
- use(plugin) {
802
- if (!this._a && !isVue2) {
803
- toBeInstalled.push(plugin);
804
- } else {
805
- _p.push(plugin);
806
- }
807
- return this;
808
- },
809
- _p,
810
- // it's actually undefined here
811
- // @ts-expect-error
812
- _a: null,
813
- _e: scope,
814
- _s: /* @__PURE__ */ new Map(),
815
- state
816
- });
817
- if (USE_DEVTOOLS && typeof Proxy !== "undefined") {
818
- pinia.use(devtoolsPlugin);
819
- }
820
- return pinia;
821
- }
822
- var isUseStore = (fn) => {
823
- return typeof fn === "function" && typeof fn.$id === "string";
824
- };
825
- function patchObject(newState, oldState) {
826
- for (const key in oldState) {
827
- const subPatch = oldState[key];
828
- if (!(key in newState)) {
829
- continue;
830
- }
831
- const targetValue = newState[key];
832
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && !isRef(subPatch) && !isReactive(subPatch)) {
833
- newState[key] = patchObject(targetValue, subPatch);
834
- } else {
835
- if (isVue2) {
836
- set(newState, key, subPatch);
837
- } else {
838
- newState[key] = subPatch;
839
- }
840
- }
841
- }
842
- return newState;
843
- }
844
- function acceptHMRUpdate(initialUseStore, hot) {
845
- if (false) {
846
- return () => {
847
- };
848
- }
849
- return (newModule) => {
850
- const pinia = hot.data.pinia || initialUseStore._pinia;
851
- if (!pinia) {
852
- return;
853
- }
854
- hot.data.pinia = pinia;
855
- for (const exportName in newModule) {
856
- const useStore = newModule[exportName];
857
- if (isUseStore(useStore) && pinia._s.has(useStore.$id)) {
858
- const id = useStore.$id;
859
- if (id !== initialUseStore.$id) {
860
- console.warn(`The id of the store changed from "${initialUseStore.$id}" to "${id}". Reloading.`);
861
- return hot.invalidate();
862
- }
863
- const existingStore = pinia._s.get(id);
864
- if (!existingStore) {
865
- console.log(`[Pinia]: skipping hmr because store doesn't exist yet`);
866
- return;
867
- }
868
- useStore(pinia, existingStore);
869
- }
870
- }
871
- };
872
- }
873
- var noop = () => {
874
- };
875
- function addSubscription(subscriptions, callback, detached, onCleanup = noop) {
876
- subscriptions.push(callback);
877
- const removeSubscription = () => {
878
- const idx = subscriptions.indexOf(callback);
879
- if (idx > -1) {
880
- subscriptions.splice(idx, 1);
881
- onCleanup();
882
- }
883
- };
884
- if (!detached && getCurrentScope()) {
885
- onScopeDispose(removeSubscription);
886
- }
887
- return removeSubscription;
888
- }
889
- function triggerSubscriptions(subscriptions, ...args) {
890
- subscriptions.slice().forEach((callback) => {
891
- callback(...args);
892
- });
893
- }
894
- var fallbackRunWithContext = (fn) => fn();
895
- function mergeReactiveObjects(target, patchToApply) {
896
- if (target instanceof Map && patchToApply instanceof Map) {
897
- patchToApply.forEach((value, key) => target.set(key, value));
898
- }
899
- if (target instanceof Set && patchToApply instanceof Set) {
900
- patchToApply.forEach(target.add, target);
901
- }
902
- for (const key in patchToApply) {
903
- if (!patchToApply.hasOwnProperty(key))
904
- continue;
905
- const subPatch = patchToApply[key];
906
- const targetValue = target[key];
907
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && target.hasOwnProperty(key) && !isRef(subPatch) && !isReactive(subPatch)) {
908
- target[key] = mergeReactiveObjects(targetValue, subPatch);
909
- } else {
910
- target[key] = subPatch;
911
- }
912
- }
913
- return target;
914
- }
915
- var skipHydrateSymbol = true ? Symbol("pinia:skipHydration") : (
916
- /* istanbul ignore next */
917
- Symbol()
918
- );
919
- var skipHydrateMap = /* @__PURE__ */ new WeakMap();
920
- function skipHydrate(obj) {
921
- return isVue2 ? (
922
- // in @vue/composition-api, the refs are sealed so defineProperty doesn't work...
923
- /* istanbul ignore next */
924
- skipHydrateMap.set(obj, 1) && obj
925
- ) : Object.defineProperty(obj, skipHydrateSymbol, {});
926
- }
927
- function shouldHydrate(obj) {
928
- return isVue2 ? (
929
- /* istanbul ignore next */
930
- !skipHydrateMap.has(obj)
931
- ) : !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol);
932
- }
933
- var { assign } = Object;
934
- function isComputed(o) {
935
- return !!(isRef(o) && o.effect);
936
- }
937
- function createOptionsStore(id, options, pinia, hot) {
938
- const { state, actions, getters } = options;
939
- const initialState = pinia.state.value[id];
940
- let store;
941
- function setup() {
942
- if (!initialState && !hot) {
943
- if (isVue2) {
944
- set(pinia.state.value, id, state ? state() : {});
945
- } else {
946
- pinia.state.value[id] = state ? state() : {};
947
- }
948
- }
949
- const localState = hot ? (
950
- // use ref() to unwrap refs inside state TODO: check if this is still necessary
951
- toRefs(ref(state ? state() : {}).value)
952
- ) : toRefs(pinia.state.value[id]);
953
- return assign(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name) => {
954
- if (name in localState) {
955
- console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`);
956
- }
957
- computedGetters[name] = markRaw(computed(() => {
958
- setActivePinia(pinia);
959
- const store2 = pinia._s.get(id);
960
- if (isVue2 && !store2._r)
961
- return;
962
- return getters[name].call(store2, store2);
963
- }));
964
- return computedGetters;
965
- }, {}));
966
- }
967
- store = createSetupStore(id, setup, options, pinia, hot, true);
968
- return store;
969
- }
970
- function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) {
971
- let scope;
972
- const optionsForPlugin = assign({ actions: {} }, options);
973
- if (!pinia._e.active) {
974
- throw new Error("Pinia destroyed");
975
- }
976
- const $subscribeOptions = {
977
- deep: true
978
- // flush: 'post',
979
- };
980
- if (!isVue2) {
981
- $subscribeOptions.onTrigger = (event) => {
982
- if (isListening) {
983
- debuggerEvents = event;
984
- } else if (isListening == false && !store._hotUpdating) {
985
- if (Array.isArray(debuggerEvents)) {
986
- debuggerEvents.push(event);
987
- } else {
988
- console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug.");
989
- }
990
- }
991
- };
992
- }
993
- let isListening;
994
- let isSyncListening;
995
- let subscriptions = [];
996
- let actionSubscriptions = [];
997
- let debuggerEvents;
998
- const initialState = pinia.state.value[$id];
999
- if (!isOptionsStore && !initialState && !hot) {
1000
- if (isVue2) {
1001
- set(pinia.state.value, $id, {});
1002
- } else {
1003
- pinia.state.value[$id] = {};
1004
- }
1005
- }
1006
- const hotState = ref({});
1007
- let activeListener;
1008
- function $patch(partialStateOrMutator) {
1009
- let subscriptionMutation;
1010
- isListening = isSyncListening = false;
1011
- if (true) {
1012
- debuggerEvents = [];
1013
- }
1014
- if (typeof partialStateOrMutator === "function") {
1015
- partialStateOrMutator(pinia.state.value[$id]);
1016
- subscriptionMutation = {
1017
- type: MutationType.patchFunction,
1018
- storeId: $id,
1019
- events: debuggerEvents
1020
- };
1021
- } else {
1022
- mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator);
1023
- subscriptionMutation = {
1024
- type: MutationType.patchObject,
1025
- payload: partialStateOrMutator,
1026
- storeId: $id,
1027
- events: debuggerEvents
1028
- };
1029
- }
1030
- const myListenerId = activeListener = Symbol();
1031
- nextTick().then(() => {
1032
- if (activeListener === myListenerId) {
1033
- isListening = true;
1034
- }
1035
- });
1036
- isSyncListening = true;
1037
- triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]);
1038
- }
1039
- const $reset = isOptionsStore ? function $reset2() {
1040
- const { state } = options;
1041
- const newState = state ? state() : {};
1042
- this.$patch(($state) => {
1043
- assign($state, newState);
1044
- });
1045
- } : (
1046
- /* istanbul ignore next */
1047
- true ? () => {
1048
- throw new Error(`🍍: Store "${$id}" is built using the setup syntax and does not implement $reset().`);
1049
- } : noop
1050
- );
1051
- function $dispose() {
1052
- scope.stop();
1053
- subscriptions = [];
1054
- actionSubscriptions = [];
1055
- pinia._s.delete($id);
1056
- }
1057
- function wrapAction(name, action) {
1058
- return function() {
1059
- setActivePinia(pinia);
1060
- const args = Array.from(arguments);
1061
- const afterCallbackList = [];
1062
- const onErrorCallbackList = [];
1063
- function after(callback) {
1064
- afterCallbackList.push(callback);
1065
- }
1066
- function onError(callback) {
1067
- onErrorCallbackList.push(callback);
1068
- }
1069
- triggerSubscriptions(actionSubscriptions, {
1070
- args,
1071
- name,
1072
- store,
1073
- after,
1074
- onError
1075
- });
1076
- let ret;
1077
- try {
1078
- ret = action.apply(this && this.$id === $id ? this : store, args);
1079
- } catch (error) {
1080
- triggerSubscriptions(onErrorCallbackList, error);
1081
- throw error;
1082
- }
1083
- if (ret instanceof Promise) {
1084
- return ret.then((value) => {
1085
- triggerSubscriptions(afterCallbackList, value);
1086
- return value;
1087
- }).catch((error) => {
1088
- triggerSubscriptions(onErrorCallbackList, error);
1089
- return Promise.reject(error);
1090
- });
1091
- }
1092
- triggerSubscriptions(afterCallbackList, ret);
1093
- return ret;
1094
- };
1095
- }
1096
- const _hmrPayload = markRaw({
1097
- actions: {},
1098
- getters: {},
1099
- state: [],
1100
- hotState
1101
- });
1102
- const partialStore = {
1103
- _p: pinia,
1104
- // _s: scope,
1105
- $id,
1106
- $onAction: addSubscription.bind(null, actionSubscriptions),
1107
- $patch,
1108
- $reset,
1109
- $subscribe(callback, options2 = {}) {
1110
- const removeSubscription = addSubscription(subscriptions, callback, options2.detached, () => stopWatcher());
1111
- const stopWatcher = scope.run(() => watch(() => pinia.state.value[$id], (state) => {
1112
- if (options2.flush === "sync" ? isSyncListening : isListening) {
1113
- callback({
1114
- storeId: $id,
1115
- type: MutationType.direct,
1116
- events: debuggerEvents
1117
- }, state);
1118
- }
1119
- }, assign({}, $subscribeOptions, options2)));
1120
- return removeSubscription;
1121
- },
1122
- $dispose
1123
- };
1124
- if (isVue2) {
1125
- partialStore._r = false;
1126
- }
1127
- const store = reactive(true ? assign(
1128
- {
1129
- _hmrPayload,
1130
- _customProperties: markRaw(/* @__PURE__ */ new Set())
1131
- // devtools custom properties
1132
- },
1133
- partialStore
1134
- // must be added later
1135
- // setupStore
1136
- ) : partialStore);
1137
- pinia._s.set($id, store);
1138
- const runWithContext = pinia._a && pinia._a.runWithContext || fallbackRunWithContext;
1139
- const setupStore = pinia._e.run(() => {
1140
- scope = effectScope();
1141
- return runWithContext(() => scope.run(setup));
1142
- });
1143
- for (const key in setupStore) {
1144
- const prop = setupStore[key];
1145
- if (isRef(prop) && !isComputed(prop) || isReactive(prop)) {
1146
- if (hot) {
1147
- set(hotState.value, key, toRef(setupStore, key));
1148
- } else if (!isOptionsStore) {
1149
- if (initialState && shouldHydrate(prop)) {
1150
- if (isRef(prop)) {
1151
- prop.value = initialState[key];
1152
- } else {
1153
- mergeReactiveObjects(prop, initialState[key]);
1154
- }
1155
- }
1156
- if (isVue2) {
1157
- set(pinia.state.value[$id], key, prop);
1158
- } else {
1159
- pinia.state.value[$id][key] = prop;
1160
- }
1161
- }
1162
- if (true) {
1163
- _hmrPayload.state.push(key);
1164
- }
1165
- } else if (typeof prop === "function") {
1166
- const actionValue = hot ? prop : wrapAction(key, prop);
1167
- if (isVue2) {
1168
- set(setupStore, key, actionValue);
1169
- } else {
1170
- setupStore[key] = actionValue;
1171
- }
1172
- if (true) {
1173
- _hmrPayload.actions[key] = prop;
1174
- }
1175
- optionsForPlugin.actions[key] = prop;
1176
- } else if (true) {
1177
- if (isComputed(prop)) {
1178
- _hmrPayload.getters[key] = isOptionsStore ? (
1179
- // @ts-expect-error
1180
- options.getters[key]
1181
- ) : prop;
1182
- if (IS_CLIENT) {
1183
- const getters = setupStore._getters || // @ts-expect-error: same
1184
- (setupStore._getters = markRaw([]));
1185
- getters.push(key);
1186
- }
1187
- }
1188
- }
1189
- }
1190
- if (isVue2) {
1191
- Object.keys(setupStore).forEach((key) => {
1192
- set(store, key, setupStore[key]);
1193
- });
1194
- } else {
1195
- assign(store, setupStore);
1196
- assign(toRaw(store), setupStore);
1197
- }
1198
- Object.defineProperty(store, "$state", {
1199
- get: () => hot ? hotState.value : pinia.state.value[$id],
1200
- set: (state) => {
1201
- if (hot) {
1202
- throw new Error("cannot set hotState");
1203
- }
1204
- $patch(($state) => {
1205
- assign($state, state);
1206
- });
1207
- }
1208
- });
1209
- if (true) {
1210
- store._hotUpdate = markRaw((newStore) => {
1211
- store._hotUpdating = true;
1212
- newStore._hmrPayload.state.forEach((stateKey) => {
1213
- if (stateKey in store.$state) {
1214
- const newStateTarget = newStore.$state[stateKey];
1215
- const oldStateSource = store.$state[stateKey];
1216
- if (typeof newStateTarget === "object" && isPlainObject(newStateTarget) && isPlainObject(oldStateSource)) {
1217
- patchObject(newStateTarget, oldStateSource);
1218
- } else {
1219
- newStore.$state[stateKey] = oldStateSource;
1220
- }
1221
- }
1222
- set(store, stateKey, toRef(newStore.$state, stateKey));
1223
- });
1224
- Object.keys(store.$state).forEach((stateKey) => {
1225
- if (!(stateKey in newStore.$state)) {
1226
- del(store, stateKey);
1227
- }
1228
- });
1229
- isListening = false;
1230
- isSyncListening = false;
1231
- pinia.state.value[$id] = toRef(newStore._hmrPayload, "hotState");
1232
- isSyncListening = true;
1233
- nextTick().then(() => {
1234
- isListening = true;
1235
- });
1236
- for (const actionName in newStore._hmrPayload.actions) {
1237
- const action = newStore[actionName];
1238
- set(store, actionName, wrapAction(actionName, action));
1239
- }
1240
- for (const getterName in newStore._hmrPayload.getters) {
1241
- const getter = newStore._hmrPayload.getters[getterName];
1242
- const getterValue = isOptionsStore ? (
1243
- // special handling of options api
1244
- computed(() => {
1245
- setActivePinia(pinia);
1246
- return getter.call(store, store);
1247
- })
1248
- ) : getter;
1249
- set(store, getterName, getterValue);
1250
- }
1251
- Object.keys(store._hmrPayload.getters).forEach((key) => {
1252
- if (!(key in newStore._hmrPayload.getters)) {
1253
- del(store, key);
1254
- }
1255
- });
1256
- Object.keys(store._hmrPayload.actions).forEach((key) => {
1257
- if (!(key in newStore._hmrPayload.actions)) {
1258
- del(store, key);
1259
- }
1260
- });
1261
- store._hmrPayload = newStore._hmrPayload;
1262
- store._getters = newStore._getters;
1263
- store._hotUpdating = false;
1264
- });
1265
- }
1266
- if (USE_DEVTOOLS) {
1267
- const nonEnumerable = {
1268
- writable: true,
1269
- configurable: true,
1270
- // avoid warning on devtools trying to display this property
1271
- enumerable: false
1272
- };
1273
- ["_p", "_hmrPayload", "_getters", "_customProperties"].forEach((p) => {
1274
- Object.defineProperty(store, p, assign({ value: store[p] }, nonEnumerable));
1275
- });
1276
- }
1277
- if (isVue2) {
1278
- store._r = true;
1279
- }
1280
- pinia._p.forEach((extender) => {
1281
- if (USE_DEVTOOLS) {
1282
- const extensions = scope.run(() => extender({
1283
- store,
1284
- app: pinia._a,
1285
- pinia,
1286
- options: optionsForPlugin
1287
- }));
1288
- Object.keys(extensions || {}).forEach((key) => store._customProperties.add(key));
1289
- assign(store, extensions);
1290
- } else {
1291
- assign(store, scope.run(() => extender({
1292
- store,
1293
- app: pinia._a,
1294
- pinia,
1295
- options: optionsForPlugin
1296
- })));
1297
- }
1298
- });
1299
- if (store.$state && typeof store.$state === "object" && typeof store.$state.constructor === "function" && !store.$state.constructor.toString().includes("[native code]")) {
1300
- console.warn(`[🍍]: The "state" must be a plain object. It cannot be
1301
- state: () => new MyClass()
1302
- Found in store "${store.$id}".`);
1303
- }
1304
- if (initialState && isOptionsStore && options.hydrate) {
1305
- options.hydrate(store.$state, initialState);
1306
- }
1307
- isListening = true;
1308
- isSyncListening = true;
1309
- return store;
1310
- }
1311
- function defineStore(idOrOptions, setup, setupOptions) {
1312
- let id;
1313
- let options;
1314
- const isSetupStore = typeof setup === "function";
1315
- if (typeof idOrOptions === "string") {
1316
- id = idOrOptions;
1317
- options = isSetupStore ? setupOptions : setup;
1318
- } else {
1319
- options = idOrOptions;
1320
- id = idOrOptions.id;
1321
- if (typeof id !== "string") {
1322
- throw new Error(`[🍍]: "defineStore()" must be passed a store id as its first argument.`);
1323
- }
1324
- }
1325
- function useStore(pinia, hot) {
1326
- const hasContext = hasInjectionContext();
1327
- pinia = // in test mode, ignore the argument provided as we can always retrieve a
1328
- // pinia instance with getActivePinia()
1329
- (false ? null : pinia) || (hasContext ? inject(piniaSymbol, null) : null);
1330
- if (pinia)
1331
- setActivePinia(pinia);
1332
- if (!activePinia) {
1333
- throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Did you forget to install pinia?
1334
- const pinia = createPinia()
1335
- app.use(pinia)
1336
- This will fail in production.`);
1337
- }
1338
- pinia = activePinia;
1339
- if (!pinia._s.has(id)) {
1340
- if (isSetupStore) {
1341
- createSetupStore(id, setup, options, pinia);
1342
- } else {
1343
- createOptionsStore(id, options, pinia);
1344
- }
1345
- if (true) {
1346
- useStore._pinia = pinia;
1347
- }
1348
- }
1349
- const store = pinia._s.get(id);
1350
- if (hot) {
1351
- const hotId = "__hot:" + id;
1352
- const newStore = isSetupStore ? createSetupStore(hotId, setup, options, pinia, true) : createOptionsStore(hotId, assign({}, options), pinia, true);
1353
- hot._hotUpdate(newStore);
1354
- delete pinia.state.value[hotId];
1355
- pinia._s.delete(hotId);
1356
- }
1357
- if (IS_CLIENT) {
1358
- const currentInstance = getCurrentInstance();
1359
- if (currentInstance && currentInstance.proxy && // avoid adding stores that are just built for hot module replacement
1360
- !hot) {
1361
- const vm = currentInstance.proxy;
1362
- const cache = "_pStores" in vm ? vm._pStores : vm._pStores = {};
1363
- cache[id] = store;
1364
- }
1365
- }
1366
- return store;
1367
- }
1368
- useStore.$id = id;
1369
- return useStore;
1370
- }
1371
- var mapStoreSuffix = "Store";
1372
- function setMapStoreSuffix(suffix) {
1373
- mapStoreSuffix = suffix;
1374
- }
1375
- function mapStores(...stores) {
1376
- if (Array.isArray(stores[0])) {
1377
- console.warn(`[🍍]: Directly pass all stores to "mapStores()" without putting them in an array:
1378
- Replace
1379
- mapStores([useAuthStore, useCartStore])
1380
- with
1381
- mapStores(useAuthStore, useCartStore)
1382
- This will fail in production if not fixed.`);
1383
- stores = stores[0];
1384
- }
1385
- return stores.reduce((reduced, useStore) => {
1386
- reduced[useStore.$id + mapStoreSuffix] = function() {
1387
- return useStore(this.$pinia);
1388
- };
1389
- return reduced;
1390
- }, {});
1391
- }
1392
- function mapState(useStore, keysOrMapper) {
1393
- return Array.isArray(keysOrMapper) ? keysOrMapper.reduce((reduced, key) => {
1394
- reduced[key] = function() {
1395
- return useStore(this.$pinia)[key];
1396
- };
1397
- return reduced;
1398
- }, {}) : Object.keys(keysOrMapper).reduce((reduced, key) => {
1399
- reduced[key] = function() {
1400
- const store = useStore(this.$pinia);
1401
- const storeKey = keysOrMapper[key];
1402
- return typeof storeKey === "function" ? storeKey.call(this, store) : store[storeKey];
1403
- };
1404
- return reduced;
1405
- }, {});
1406
- }
1407
- var mapGetters = mapState;
1408
- function mapActions(useStore, keysOrMapper) {
1409
- return Array.isArray(keysOrMapper) ? keysOrMapper.reduce((reduced, key) => {
1410
- reduced[key] = function(...args) {
1411
- return useStore(this.$pinia)[key](...args);
1412
- };
1413
- return reduced;
1414
- }, {}) : Object.keys(keysOrMapper).reduce((reduced, key) => {
1415
- reduced[key] = function(...args) {
1416
- return useStore(this.$pinia)[keysOrMapper[key]](...args);
1417
- };
1418
- return reduced;
1419
- }, {});
1420
- }
1421
- function mapWritableState(useStore, keysOrMapper) {
1422
- return Array.isArray(keysOrMapper) ? keysOrMapper.reduce((reduced, key) => {
1423
- reduced[key] = {
1424
- get() {
1425
- return useStore(this.$pinia)[key];
1426
- },
1427
- set(value) {
1428
- return useStore(this.$pinia)[key] = value;
1429
- }
1430
- };
1431
- return reduced;
1432
- }, {}) : Object.keys(keysOrMapper).reduce((reduced, key) => {
1433
- reduced[key] = {
1434
- get() {
1435
- return useStore(this.$pinia)[keysOrMapper[key]];
1436
- },
1437
- set(value) {
1438
- return useStore(this.$pinia)[keysOrMapper[key]] = value;
1439
- }
1440
- };
1441
- return reduced;
1442
- }, {});
1443
- }
1444
- function storeToRefs(store) {
1445
- if (isVue2) {
1446
- return toRefs(store);
1447
- } else {
1448
- store = toRaw(store);
1449
- const refs = {};
1450
- for (const key in store) {
1451
- const value = store[key];
1452
- if (isRef(value) || isReactive(value)) {
1453
- refs[key] = // ---
1454
- toRef(store, key);
1455
- }
1456
- }
1457
- return refs;
1458
- }
1459
- }
1460
- var PiniaVuePlugin = function(_Vue) {
1461
- _Vue.mixin({
1462
- beforeCreate() {
1463
- const options = this.$options;
1464
- if (options.pinia) {
1465
- const pinia = options.pinia;
1466
- if (!this._provided) {
1467
- const provideCache = {};
1468
- Object.defineProperty(this, "_provided", {
1469
- get: () => provideCache,
1470
- set: (v) => Object.assign(provideCache, v)
1471
- });
1472
- }
1473
- this._provided[piniaSymbol] = pinia;
1474
- if (!this.$pinia) {
1475
- this.$pinia = pinia;
1476
- }
1477
- pinia._a = this;
1478
- if (IS_CLIENT) {
1479
- setActivePinia(pinia);
1480
- }
1481
- if (USE_DEVTOOLS) {
1482
- registerPiniaDevtools(pinia._a, pinia);
1483
- }
1484
- } else if (!this.$pinia && options.parent && options.parent.$pinia) {
1485
- this.$pinia = options.parent.$pinia;
1486
- }
1487
- },
1488
- destroyed() {
1489
- delete this._pStores;
1490
- }
1491
- });
1492
- };
1493
- export {
1494
- MutationType,
1495
- PiniaVuePlugin,
1496
- acceptHMRUpdate,
1497
- createPinia,
1498
- defineStore,
1499
- getActivePinia,
1500
- mapActions,
1501
- mapGetters,
1502
- mapState,
1503
- mapStores,
1504
- mapWritableState,
1505
- setActivePinia,
1506
- setMapStoreSuffix,
1507
- skipHydrate,
1508
- storeToRefs
1509
- };
1510
- /*! Bundled license information:
1511
-
1512
- pinia/dist/pinia.mjs:
1513
- (*!
1514
- * pinia v2.1.4
1515
- * (c) 2023 Eduardo San Martin Morote
1516
- * @license MIT
1517
- *)
1518
- */
1519
- //# sourceMappingURL=pinia.js.map