pinia.js 46 KB

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