f_000002 46 KB

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