pinia.js 41 KB

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