unplugin-vue-router
Advanced tools
Comparing version 0.8.3 to 0.8.4
@@ -1,5 +0,1 @@ | ||
import 'vue-router' | ||
import 'unplugin-vue-router/runtime' | ||
export {} | ||
declare module 'vue-router/auto-routes' { | ||
@@ -98,6 +94,10 @@ import type { RouteRecordRaw } from 'vue-router' | ||
DataLoaderPlugin, | ||
defineBasicLoader, | ||
defineColadaLoader, | ||
NavigationResult, | ||
} from 'unplugin-vue-router/runtime' | ||
// must be added to the virtual vue-router/auto | ||
// FIXME: is there a way to achieve this without losing the types? | ||
// export { defineBasicLoader } from 'unplugin-vue-router/data-loaders/basic' | ||
// export { defineColadaLoader } from 'unplugin-vue-router/data-loaders/pinia-colada' | ||
} | ||
export {} |
import * as esbuild from 'esbuild'; | ||
import { O as Options } from './options-Cejcs5IG.js'; | ||
import { O as Options } from './options-yBvUhD_i.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkPWIYU44Wjs = require('./chunk-PWIYU44W.js'); | ||
var _chunkRQCPCTLSjs = require('./chunk-RQCPCTLS.js'); | ||
require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
require('./chunk-6F4PWJZI.js'); | ||
// src/esbuild.ts | ||
var esbuild_default = _chunkPWIYU44Wjs.src_default.esbuild; | ||
var esbuild_default = _chunkRQCPCTLSjs.src_default.esbuild; | ||
@@ -11,0 +10,0 @@ |
import * as unplugin from 'unplugin'; | ||
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-Cejcs5IG.js'; | ||
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, T as TreeNode, a as TreeNodeValueParam, b as TreeNodeValueStatic, c as createTreeNodeValue } from './options-Cejcs5IG.js'; | ||
export { y as NavigationGuard, N as NavigationGuardReturn, A as NavigationGuardTyped, z as NavigationGuardWithThis, B as NavigationGuardWithThisTyped, C as NavigationHookAfterTyped, s as RouteLocation, d as RouteLocationAsPathTyped, e as RouteLocationAsPathTypedList, t as RouteLocationAsRelativePath, b as RouteLocationAsRelativeTyped, c as RouteLocationAsRelativeTypedList, f as RouteLocationAsString, p as RouteLocationNormalized, r as RouteLocationNormalizedLoaded, n as RouteLocationNormalizedLoadedTyped, o as RouteLocationNormalizedLoadedTypedList, l as RouteLocationNormalizedTyped, m as RouteLocationNormalizedTypedList, u as RouteLocationRaw, v as RouteLocationResolved, j as RouteLocationResolvedTyped, k as RouteLocationResolvedTypedList, h as RouteLocationTyped, i as RouteLocationTypedList, G as RouteNamedMap, w as RouteParams, x as RouteParamsRaw, R as RouteRecordInfo, q as RouteRecordName, E as Router, T as TypesConfig, _ as _RouteMapGeneric, F as _RouterOptions, D as _RouterTyped, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './router-BioWx5xN.js'; | ||
export { ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouterLinkPropsTyped, RouterLinkTyped, UseLinkFnTyped, _UseLinkReturnTyped } from './types.js'; | ||
import { R as ResolvedOptions, S as ServerContext, T as TreeNode, O as Options } from './options-yBvUhD_i.js'; | ||
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, a as TreeNodeValueParam, b as TreeNodeValueStatic, c as createTreeNodeValue } from './options-yBvUhD_i.js'; | ||
export { NavigationGuard, NavigationGuardReturn, NavigationGuardTyped, NavigationGuardWithThis, NavigationGuardWithThisTyped, NavigationHookAfterTyped, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocation, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativePath, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteNamedMap, RouteParams, RouteParamsRaw, RouteRecordInfo, RouteRecordName, Router, RouterLinkPropsTyped, RouterLinkTyped, TypesConfig, UseLinkFnTyped, _RouteMapGeneric, _RouterOptions, _RouterTyped, _UseLinkReturnTyped } from './types.js'; | ||
import 'vue-router'; | ||
@@ -19,2 +18,18 @@ import 'vue'; | ||
/** | ||
* Creates a name based of the node path segments. | ||
* | ||
* @param node - the node to get the path from | ||
* @param parent - the parent node | ||
* @returns a route name | ||
*/ | ||
declare function getPascalCaseRouteName(node: TreeNode): string; | ||
/** | ||
* Joins the path segments of a node into a name that corresponds to the filepath represented by the node. | ||
* | ||
* @param node - the node to get the path from | ||
* @returns a route name | ||
*/ | ||
declare function getFileBasedRouteName(node: TreeNode): string; | ||
declare const _default: unplugin.UnpluginInstance<Options | undefined, boolean>; | ||
@@ -35,2 +50,2 @@ | ||
export { Options, VueRouterAutoImports, createRoutesContext, _default as default }; | ||
export { Options, TreeNode, VueRouterAutoImports, createRoutesContext, _default as default, getFileBasedRouteName, getPascalCaseRouteName }; |
@@ -7,3 +7,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkPWIYU44Wjs = require('./chunk-PWIYU44W.js'); | ||
var _chunkRQCPCTLSjs = require('./chunk-RQCPCTLS.js'); | ||
@@ -14,3 +14,2 @@ | ||
var _chunkXHAGIRMEjs = require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
require('./chunk-6F4PWJZI.js'); | ||
@@ -26,2 +25,2 @@ | ||
exports.DEFAULT_OPTIONS = _chunkXHAGIRMEjs.DEFAULT_OPTIONS; exports.EditableTreeNode = _chunkPWIYU44Wjs.EditableTreeNode; exports.VueRouterAutoImports = _chunkPWIYU44Wjs.VueRouterAutoImports; exports.createRoutesContext = _chunkPWIYU44Wjs.createRoutesContext; exports.createTreeNodeValue = _chunkPWIYU44Wjs.createTreeNodeValue; exports.default = _chunkPWIYU44Wjs.src_default; exports.getFileBasedRouteName = _chunkXHAGIRMEjs.getFileBasedRouteName; exports.getPascalCaseRouteName = _chunkXHAGIRMEjs.getPascalCaseRouteName; | ||
exports.DEFAULT_OPTIONS = _chunkXHAGIRMEjs.DEFAULT_OPTIONS; exports.EditableTreeNode = _chunkRQCPCTLSjs.EditableTreeNode; exports.VueRouterAutoImports = _chunkRQCPCTLSjs.VueRouterAutoImports; exports.createRoutesContext = _chunkRQCPCTLSjs.createRoutesContext; exports.createTreeNodeValue = _chunkRQCPCTLSjs.createTreeNodeValue; exports.default = _chunkRQCPCTLSjs.src_default; exports.getFileBasedRouteName = _chunkXHAGIRMEjs.getFileBasedRouteName; exports.getPascalCaseRouteName = _chunkXHAGIRMEjs.getPascalCaseRouteName; |
@@ -1,2 +0,2 @@ | ||
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, h as RoutesFolder, d as RoutesFolderOption, e as RoutesFolderOptionResolved, S as ServerContext, f as _OverridableOption, g as _RoutesFolder, r as resolveOptions } from './options-Cejcs5IG.js'; | ||
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, h as RoutesFolder, d as RoutesFolderOption, e as RoutesFolderOptionResolved, S as ServerContext, f as _OverridableOption, g as _RoutesFolder, r as resolveOptions } from './options-yBvUhD_i.js'; | ||
import 'vue-router'; |
@@ -5,3 +5,2 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkXHAGIRMEjs = require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
@@ -8,0 +7,0 @@ |
import * as rollup from 'rollup'; | ||
import { O as Options } from './options-Cejcs5IG.js'; | ||
import { O as Options } from './options-yBvUhD_i.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkPWIYU44Wjs = require('./chunk-PWIYU44W.js'); | ||
var _chunkRQCPCTLSjs = require('./chunk-RQCPCTLS.js'); | ||
require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
require('./chunk-6F4PWJZI.js'); | ||
// src/rollup.ts | ||
var rollup_default = _chunkPWIYU44Wjs.src_default.rollup; | ||
var rollup_default = _chunkRQCPCTLSjs.src_default.rollup; | ||
@@ -11,0 +10,0 @@ |
@@ -1,6 +0,5 @@ | ||
import { NavigationGuard, LocationQuery, RouteRecordRaw } from 'vue-router'; | ||
import { NavigationGuard, Router as Router$1, LocationQuery, RouteRecordRaw } from 'vue-router'; | ||
import { App, EffectScope, ShallowRef } from 'vue'; | ||
import { E as _Router, r as _RouteLocationNormalizedLoaded, q as _RouteRecordName } from './router-BioWx5xN.js'; | ||
import { _ as _Awaitable } from './options-Cejcs5IG.js'; | ||
import { UseQueryOptions, UseQueryKey, UseQueryReturn } from '@pinia/colada'; | ||
import * as unplugin_vue_router_types from 'unplugin-vue-router/types'; | ||
import { Router, RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded$1 } from 'unplugin-vue-router/types'; | ||
@@ -48,4 +47,15 @@ /** | ||
declare const NAVIGATION_RESULTS_KEY: unique symbol; | ||
/** | ||
* Symbol used to save the initial data on the router. | ||
* @internal | ||
*/ | ||
declare const IS_SSR_KEY: unique symbol; | ||
/** | ||
* Maybe a promise maybe not | ||
* @internal | ||
*/ | ||
type _Awaitable<T> = T | PromiseLike<T>; | ||
/** | ||
* Options to initialize the data loader guard. | ||
@@ -117,3 +127,4 @@ */ | ||
*/ | ||
router: _Router; | ||
router: Router | Router$1; | ||
isSSR?: boolean; | ||
/** | ||
@@ -146,2 +157,3 @@ * Called if any data loader returns a `NavigationResult` with an array of them. Should decide what is the outcome of | ||
[APP_KEY]: App<unknown>; | ||
[IS_SSR_KEY]: boolean; | ||
} | ||
@@ -175,2 +187,17 @@ interface RouteMeta { | ||
/** | ||
* @internal: data loaders authoring only. Use `getCurrentContext` instead. | ||
*/ | ||
declare let currentContext: readonly [ | ||
entry: DataLoaderEntryBase, | ||
router: Router, | ||
route: RouteLocationNormalizedLoaded$1 | ||
] | undefined | null; | ||
declare function getCurrentContext(): readonly [entry: DataLoaderEntryBase<boolean, unknown>, router: unplugin_vue_router_types._RouterTyped<RouteNamedMap>, route: RouteNamedMap] | readonly []; | ||
declare function setCurrentContext(context: typeof currentContext | readonly []): void; | ||
/** | ||
* Restore the current context after a promise is resolved. | ||
* @param promise - promise to wrap | ||
*/ | ||
declare function withLoaderContext<P extends Promise<unknown>>(promise: P): P; | ||
/** | ||
* Object and promise of the object itself. Used when we can await some of the properties of an object to be loaded. | ||
@@ -180,2 +207,24 @@ * @internal | ||
type _PromiseMerged<PromiseType, RawType = PromiseType> = RawType & Promise<PromiseType>; | ||
declare const assign: { | ||
<T extends {}, U>(target: T, source: U): T & U; | ||
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V; | ||
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W; | ||
(target: object, ...sources: any[]): any; | ||
}; | ||
/** | ||
* Track the reads of a route and its properties | ||
* @internal | ||
* @param route - route to track | ||
*/ | ||
declare function trackRoute(route: RouteLocationNormalizedLoaded$1): readonly [any, any, any, { | ||
v: string | null; | ||
}]; | ||
/** | ||
* Returns `true` if `inner` is a subset of `outer`. Used to check if a tr | ||
* | ||
* @internal | ||
* @param outer - the bigger params | ||
* @param inner - the smaller params | ||
*/ | ||
declare function isSubsetOf(inner: Partial<LocationQuery>, outer: LocationQuery): boolean; | ||
@@ -210,3 +259,3 @@ /** | ||
*/ | ||
pendingTo: _RouteLocationNormalizedLoaded | null; | ||
pendingTo: RouteLocationNormalizedLoaded$1 | null; | ||
/** | ||
@@ -231,3 +280,3 @@ * Data that was staged by a loader. This is used to avoid showing the old data while the new data is loading. Calling | ||
*/ | ||
commit(to: _RouteLocationNormalizedLoaded): void; | ||
commit(to: RouteLocationNormalizedLoaded$1): void; | ||
} | ||
@@ -314,3 +363,3 @@ interface DefineDataLoaderOptionsBase<isLazy extends boolean> { | ||
*/ | ||
load: (route: _RouteLocationNormalizedLoaded, router: _Router, parent?: DataLoaderEntryBase) => Promise<void>; | ||
load: (route: RouteLocationNormalizedLoaded$1, router: Router, parent?: DataLoaderEntryBase) => Promise<void>; | ||
/** | ||
@@ -326,3 +375,3 @@ * Resolved options for the loader. | ||
*/ | ||
getEntry(router: _Router): DataLoaderEntryBase<isLazy, Data>; | ||
getEntry(router: Router): DataLoaderEntryBase<isLazy, Data>; | ||
} | ||
@@ -361,3 +410,3 @@ /** | ||
*/ | ||
reload(route: _RouteLocationNormalizedLoaded): Promise<void>; | ||
reload(route: RouteLocationNormalizedLoaded$1): Promise<void>; | ||
} | ||
@@ -367,3 +416,3 @@ /** | ||
*/ | ||
interface DefineLoaderFn<Data, Context extends DataLoaderContextBase = DataLoaderContextBase, Route = _RouteLocationNormalizedLoaded> { | ||
interface DefineLoaderFn<Data, Context extends DataLoaderContextBase = DataLoaderContextBase, Route = RouteLocationNormalizedLoaded$1> { | ||
(route: Route, context: Context): Promise<Data>; | ||
@@ -373,124 +422,2 @@ } | ||
/** | ||
* Creates a data loader composable that can be exported by pages to attach the data loading to a route. This returns a | ||
* composable that can be used in any component. | ||
* | ||
* @experimental | ||
* Still under development and subject to change. See https://github.com/vuejs/rfcs/discussions/460 | ||
* | ||
* @param name - name of the route to have typed routes | ||
* @param loader - function that returns a promise with the data | ||
* @param options - options to configure the data loader | ||
*/ | ||
declare function defineBasicLoader<Name extends _RouteRecordName, Data, isLazy extends boolean>(name: Name, loader: DefineLoaderFn<Data, DataLoaderContext, _RouteLocationNormalizedLoaded<Name>>, options?: DefineDataLoaderOptions<isLazy>): UseDataLoader<isLazy, Data>; | ||
declare function defineBasicLoader<Data, isLazy extends boolean>(loader: DefineLoaderFn<Data, DataLoaderContext, _RouteLocationNormalizedLoaded>, options?: DefineDataLoaderOptions<isLazy>): UseDataLoader<isLazy, Data>; | ||
interface DefineDataLoaderOptions<isLazy extends boolean> extends DefineDataLoaderOptionsBase<isLazy> { | ||
/** | ||
* Key to use for SSR state. This will be used to read the initial data from `initialData`'s object. | ||
*/ | ||
key?: string; | ||
} | ||
interface DataLoaderContext extends DataLoaderContextBase { | ||
} | ||
/** | ||
* Symbol used to store the data in the router so it can be retrieved after the initial navigation. | ||
* @internal | ||
*/ | ||
declare const SERVER_INITIAL_DATA_KEY: unique symbol; | ||
/** | ||
* Initial data generated on server and consumed on client. | ||
* @internal | ||
*/ | ||
declare const INITIAL_DATA_KEY: unique symbol; | ||
declare module 'vue-router' { | ||
interface Router { | ||
/** | ||
* Gives access to the initial state during rendering. Should be set to `false` once it's consumed. | ||
* @internal | ||
*/ | ||
[SERVER_INITIAL_DATA_KEY]?: Record<string, unknown> | false; | ||
[INITIAL_DATA_KEY]?: Record<string, unknown> | false; | ||
} | ||
} | ||
/** | ||
* Creates a data loader composable that can be exported by pages to attach the data loading to a route. This returns a | ||
* composable that can be used in any component. | ||
* | ||
* @experimental | ||
* Still under development and subject to change. See https://github.com/vuejs/rfcs/discussions/460 | ||
* | ||
* @param name - name of the route to have typed routes | ||
* @param loader - function that returns a promise with the data | ||
* @param options - options to configure the data loader | ||
*/ | ||
declare function defineColadaLoader<Name extends _RouteRecordName, Data, isLazy extends boolean>(name: Name, options: DefineDataColadaLoaderOptions<isLazy, Name, Data>): UseDataLoaderColada<isLazy, Data>; | ||
declare function defineColadaLoader<Data, isLazy extends boolean>(options: DefineDataColadaLoaderOptions<isLazy, _RouteRecordName, Data>): UseDataLoaderColada<isLazy, Data>; | ||
interface DefineDataColadaLoaderOptions<isLazy extends boolean, Name extends _RouteRecordName, Data> extends DefineDataLoaderOptionsBase<isLazy>, Omit<UseQueryOptions<unknown>, 'query' | 'key'> { | ||
/** | ||
* Key associated with the data and passed to pinia colada | ||
* @param to - Route to load the data | ||
*/ | ||
key: (to: _RouteLocationNormalizedLoaded<Name>) => UseQueryKey; | ||
/** | ||
* Function that returns a promise with the data. | ||
*/ | ||
query: DefineLoaderFn<Data, DataColadaLoaderContext, _RouteLocationNormalizedLoaded<Name>>; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
interface DataColadaLoaderContext extends DataLoaderContextBase { | ||
} | ||
interface UseDataLoaderColadaResult<isLazy extends boolean, Data> extends UseDataLoaderResult<isLazy, Data>, Pick<UseQueryReturn<Data, any>, 'isPending' | 'refetch' | 'refresh' | 'status'> { | ||
} | ||
/** | ||
* Data Loader composable returned by `defineColadaLoader()`. | ||
*/ | ||
interface UseDataLoaderColada<isLazy extends boolean, Data> extends UseDataLoader<isLazy, Data> { | ||
/** | ||
* Data Loader composable returned by `defineColadaLoader()`. | ||
* | ||
* @example | ||
* Returns the Data loader data, isLoading, error etc. Meant to be used in `setup()` or `<script setup>` **without `await`**: | ||
* ```vue | ||
* <script setup> | ||
* const { data, isLoading, error } = useUserData() | ||
* </script> | ||
* ``` | ||
* | ||
* @example | ||
* It also returns a promise of the data when used in nested loaders. Note this `data` is **not a ref**. This is not meant to be used in `setup()` or `<script setup>`. | ||
* ```ts | ||
* export const useUserConnections = defineLoader(async () => { | ||
* const user = await useUserData() | ||
* return fetchUserConnections(user.id) | ||
* }) | ||
* ``` | ||
*/ | ||
(): _PromiseMerged<Exclude<Data, NavigationResult>, UseDataLoaderColadaResult<isLazy, Exclude<Data, NavigationResult>>>; | ||
} | ||
interface DataLoaderColadaEntry<isLazy extends boolean, Data> extends DataLoaderEntryBase<isLazy, Data> { | ||
/** | ||
* Reactive route passed to pinia colada so it automatically refetch | ||
*/ | ||
route: ShallowRef<_RouteLocationNormalizedLoaded>; | ||
/** | ||
* Tracked routes to know when the data should be refreshed. Key is the key of the query. | ||
*/ | ||
tracked: Map<string, TrackedRoute>; | ||
/** | ||
* Extended options for pinia colada | ||
*/ | ||
ext: UseQueryReturn<Data> | null; | ||
} | ||
interface TrackedRoute { | ||
ready: boolean; | ||
params: Partial<LocationQuery>; | ||
query: Partial<LocationQuery>; | ||
hash: { | ||
v: string | null; | ||
}; | ||
} | ||
/** | ||
* Defines properties of the route for the current page component. | ||
@@ -524,2 +451,2 @@ * | ||
export { type DataColadaLoaderContext, type DataLoaderColadaEntry, type DataLoaderContext, type DataLoaderContextBase, type DataLoaderEntryBase, DataLoaderPlugin, type DataLoaderPluginOptions, type DefineDataColadaLoaderOptions, type DefineDataLoaderOptions, type DefineDataLoaderOptionsBase, type DefineLoaderFn, type DefinePage, NavigationResult, type SetupLoaderGuardOptions, type UseDataLoader, type UseDataLoaderColada, type UseDataLoaderColadaResult, type UseDataLoaderInternals, type UseDataLoaderResult, type _DataLoaderRedirectResult, type _DataMaybeLazy, _definePage, _mergeRouteRecord, defineBasicLoader, defineColadaLoader, definePage }; | ||
export { ABORT_CONTROLLER_KEY, APP_KEY, type DataLoaderContextBase, type DataLoaderEntryBase, DataLoaderPlugin, type DataLoaderPluginOptions, type DefineDataLoaderOptionsBase, type DefineLoaderFn, type DefinePage, IS_SSR_KEY, IS_USE_DATA_LOADER_KEY, LOADER_ENTRIES_KEY, LOADER_SET_KEY, NAVIGATION_RESULTS_KEY, NavigationResult, PENDING_LOCATION_KEY, STAGED_NO_VALUE, type SetupLoaderGuardOptions, type UseDataLoader, type UseDataLoaderInternals, type UseDataLoaderResult, type _DataLoaderRedirectResult, type _DataMaybeLazy, type _DefineLoaderEntryMap, type _PromiseMerged, _definePage, _mergeRouteRecord, assign, currentContext, definePage, getCurrentContext, isSubsetOf, setCurrentContext, trackRoute, withLoaderContext }; |
1656
dist/runtime.js
@@ -1,10 +0,6 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } | ||
var _chunkM6BUQN66js = require('./chunk-M6BUQN66.js'); | ||
// src/data-fetching/defineLoader.ts | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/data-loaders/navigation-guard.ts | ||
var _vuerouter = require('vue-router'); | ||
var _vue = require('vue'); | ||
// src/data-fetching/symbols.ts | ||
// src/data-loaders/symbols.ts | ||
var LOADER_SET_KEY = Symbol("loaders"); | ||
@@ -18,4 +14,5 @@ var LOADER_ENTRIES_KEY = Symbol("loaderEntries"); | ||
var NAVIGATION_RESULTS_KEY = Symbol(); | ||
var IS_SSR_KEY = Symbol(); | ||
// src/data-fetching/utils.ts | ||
// src/data-loaders/utils.ts | ||
function isDataLoader(loader) { | ||
@@ -29,5 +26,8 @@ return loader && loader[IS_USE_DATA_LOADER_KEY]; | ||
function setCurrentContext(context) { | ||
currentContext = context ? context.length ? context : null : null; | ||
currentContext = exports.currentContext = context ? context.length ? context : null : null; | ||
} | ||
var IS_CLIENT = typeof window !== "undefined"; | ||
function withLoaderContext(promise) { | ||
const context = currentContext; | ||
return promise.finally(() => currentContext = exports.currentContext = context); | ||
} | ||
var assign = Object.assign; | ||
@@ -84,8 +84,3 @@ function trackRoute(route) { | ||
// src/data-fetching/defineLoader.ts | ||
var _vue = require('vue'); var Vue = _interopRequireWildcard(_vue); var vue_star = _interopRequireWildcard(_vue); | ||
// src/data-fetching/navigation-guard.ts | ||
// src/data-loaders/navigation-guard.ts | ||
function setupLoaderGuard({ | ||
@@ -95,2 +90,3 @@ router, | ||
effect, | ||
isSSR, | ||
selectNavigationResult = (results) => results[0].value | ||
@@ -114,2 +110,3 @@ }) { | ||
router[APP_KEY] = app; | ||
router[IS_SSR_KEY] = !!isSSR; | ||
const removeLoaderGuard = router.beforeEach((to) => { | ||
@@ -153,74 +150,69 @@ if (router[PENDING_LOCATION_KEY]) { | ||
}); | ||
const removeDataLoaderGuard = router.beforeResolve((to) => { | ||
const loaders = Array.from(to.meta[LOADER_SET_KEY]); | ||
setCurrentContext([]); | ||
return Promise.all( | ||
loaders.map((loader) => { | ||
const { commit, server, lazy } = loader._.options; | ||
if (!server && !IS_CLIENT) { | ||
return; | ||
const removeDataLoaderGuard = router.beforeResolve( | ||
(to) => { | ||
const loaders = Array.from(to.meta[LOADER_SET_KEY]); | ||
setCurrentContext([]); | ||
return Promise.all( | ||
loaders.map((loader) => { | ||
const { server, lazy } = loader._.options; | ||
if (!server && isSSR) { | ||
return; | ||
} | ||
const ret = effect.run( | ||
() => app.runWithContext( | ||
() => loader._.load(to, router) | ||
) | ||
); | ||
return !isSSR && lazy ? void 0 : ( | ||
// return the non-lazy loader to commit changes after all loaders are done | ||
ret | ||
); | ||
}) | ||
).then(() => { | ||
if (to.meta[NAVIGATION_RESULTS_KEY].length) { | ||
return selectNavigationResult(to.meta[NAVIGATION_RESULTS_KEY]); | ||
} | ||
const ret = effect.run( | ||
() => app.runWithContext( | ||
() => loader._.load( | ||
to, | ||
router | ||
) | ||
}).catch( | ||
(error) => error instanceof NavigationResult ? error.value : ( | ||
// let the error propagate to router.onError() | ||
// we use never because the rejection means we never resolve a value and using anything else | ||
// will not be valid from the navigation guard's perspective | ||
Promise.reject(error) | ||
) | ||
); | ||
} | ||
); | ||
const removeAfterEach = router.afterEach( | ||
(to, _from, failure) => { | ||
if (failure) { | ||
_optionalChain([to, 'access', _7 => _7.meta, 'access', _8 => _8[ABORT_CONTROLLER_KEY], 'optionalAccess', _9 => _9.abort, 'call', _10 => _10(failure)]); | ||
if ( | ||
// NOTE: using a smaller version to cutoff some bytes | ||
_vuerouter.isNavigationFailure.call(void 0, | ||
failure, | ||
16 | ||
/* NavigationFailureType.duplicated */ | ||
) | ||
).then(() => { | ||
if (commit === "after-load") { | ||
return loader; | ||
) { | ||
for (const loader of to.meta[LOADER_SET_KEY]) { | ||
const entry = loader._.getEntry(router); | ||
entry.resetPending(); | ||
} | ||
}); | ||
return IS_CLIENT && lazy ? void 0 : ( | ||
// return the non-lazy loader to commit changes after all loaders are done | ||
ret | ||
); | ||
}) | ||
).then((loaders2) => { | ||
if (to.meta[NAVIGATION_RESULTS_KEY].length) { | ||
return selectNavigationResult(to.meta[NAVIGATION_RESULTS_KEY]); | ||
} | ||
}).catch( | ||
(error) => error instanceof NavigationResult ? error.value : ( | ||
// let the error propagate to router.onError() | ||
// we use never because the rejection means we never resolve a value and using anything else | ||
// will not be valid from the navigation guard's perspective | ||
Promise.reject(error) | ||
) | ||
); | ||
}); | ||
const removeAfterEach = router.afterEach((to, _from, failure) => { | ||
if (failure) { | ||
_optionalChain([to, 'access', _7 => _7.meta, 'access', _8 => _8[ABORT_CONTROLLER_KEY], 'optionalAccess', _9 => _9.abort, 'call', _10 => _10(failure)]); | ||
if ( | ||
// NOTE: using a smaller version to cutoff some bytes | ||
_vuerouter.isNavigationFailure.call(void 0, | ||
failure, | ||
16 | ||
/* NavigationFailureType.duplicated */ | ||
) | ||
) { | ||
} | ||
} else { | ||
for (const loader of to.meta[LOADER_SET_KEY]) { | ||
const entry = loader._.getEntry(router); | ||
entry.resetPending(); | ||
} | ||
} | ||
} else { | ||
for (const loader of to.meta[LOADER_SET_KEY]) { | ||
const { commit, lazy } = loader._.options; | ||
if (commit === "after-load") { | ||
const entry = loader._.getEntry(router); | ||
if (!lazy || !entry.isLoading.value) { | ||
loader._.getEntry(router).commit( | ||
to | ||
); | ||
const { commit, lazy } = loader._.options; | ||
if (commit === "after-load") { | ||
const entry = loader._.getEntry(router); | ||
if (entry && (!lazy || !entry.isLoading.value)) { | ||
entry.commit(to); | ||
} | ||
} | ||
} | ||
} | ||
if (router[PENDING_LOCATION_KEY] === to) { | ||
router[PENDING_LOCATION_KEY] = null; | ||
} | ||
} | ||
if (router[PENDING_LOCATION_KEY] === to) { | ||
router[PENDING_LOCATION_KEY] = null; | ||
} | ||
}); | ||
); | ||
const removeOnError = router.onError((error, to) => { | ||
@@ -234,2 +226,3 @@ _optionalChain([to, 'access', _11 => _11.meta, 'access', _12 => _12[ABORT_CONTROLLER_KEY], 'optionalAccess', _13 => _13.abort, 'call', _14 => _14(error)]); | ||
delete router[LOADER_ENTRIES_KEY]; | ||
delete router[APP_KEY]; | ||
removeLoaderGuard(); | ||
@@ -261,1482 +254,2 @@ removeDataLoaderGuard(); | ||
// src/data-fetching/defineLoader.ts | ||
function defineBasicLoader(nameOrLoader, _loaderOrOptions, opts) { | ||
const loader = typeof nameOrLoader === "function" ? nameOrLoader : _loaderOrOptions; | ||
opts = typeof _loaderOrOptions === "object" ? _loaderOrOptions : opts; | ||
const options = { | ||
...DEFAULT_DEFINE_LOADER_OPTIONS, | ||
...opts, | ||
// avoid opts overriding with `undefined` | ||
commit: _optionalChain([opts, 'optionalAccess', _15 => _15.commit]) || DEFAULT_DEFINE_LOADER_OPTIONS.commit | ||
}; | ||
function load(to, router, parent) { | ||
const entries = router[LOADER_ENTRIES_KEY]; | ||
if (!entries.has(loader)) { | ||
entries.set(loader, { | ||
// force the type to match | ||
data: _vue.shallowRef.call(void 0, ), | ||
isLoading: _vue.shallowRef.call(void 0, false), | ||
error: _vue.shallowRef.call(void 0, ), | ||
options, | ||
children: /* @__PURE__ */ new Set(), | ||
resetPending() { | ||
this.pendingLoad = null; | ||
this.pendingTo = null; | ||
}, | ||
pendingLoad: null, | ||
pendingTo: null, | ||
staged: STAGED_NO_VALUE, | ||
stagedError: null, | ||
commit | ||
}); | ||
} | ||
const entry = entries.get(loader); | ||
if (entry.pendingTo === to && entry.pendingLoad) { | ||
return entry.pendingLoad; | ||
} | ||
const { error, isLoading, data } = entry; | ||
const initialRootData = router[INITIAL_DATA_KEY]; | ||
const key = options.key || ""; | ||
let initialData = STAGED_NO_VALUE; | ||
if (initialRootData && key in initialRootData) { | ||
initialData = initialRootData[key]; | ||
delete initialRootData[key]; | ||
} | ||
if (initialData !== STAGED_NO_VALUE) { | ||
data.value = initialData; | ||
return entry.pendingLoad = Promise.resolve(); | ||
} | ||
entry.pendingTo = to; | ||
isLoading.value = true; | ||
const currentContext2 = getCurrentContext(); | ||
if (process.env.NODE_ENV === "development") { | ||
if (parent !== currentContext2[0]) { | ||
console.warn( | ||
`\u274C\u{1F476} "${options.key}" has a different parent than the current context. This shouldn't be happening. Please report a bug with a reproduction to https://github.com/posva/unplugin-vue-router/` | ||
); | ||
} | ||
} | ||
setCurrentContext([entry, router, to]); | ||
entry.staged = STAGED_NO_VALUE; | ||
entry.stagedError = error.value; | ||
const currentLoad = Promise.resolve( | ||
loader(to, { signal: to.meta[ABORT_CONTROLLER_KEY].signal }) | ||
).then((d) => { | ||
if (entry.pendingLoad === currentLoad) { | ||
if (d instanceof NavigationResult) { | ||
to.meta[NAVIGATION_RESULTS_KEY].push(d); | ||
} else { | ||
entry.staged = d; | ||
entry.stagedError = null; | ||
} | ||
} | ||
}).catch((e) => { | ||
if (entry.pendingLoad === currentLoad) { | ||
entry.stagedError = e; | ||
if (!options.lazy || !IS_CLIENT) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
}).finally(() => { | ||
setCurrentContext(currentContext2); | ||
if (entry.pendingLoad === currentLoad) { | ||
isLoading.value = false; | ||
if (options.commit === "immediate" || // outside of navigation | ||
!router[PENDING_LOCATION_KEY]) { | ||
entry.commit(to); | ||
} | ||
} else { | ||
} | ||
}); | ||
setCurrentContext(currentContext2); | ||
entry.pendingLoad = currentLoad; | ||
return currentLoad; | ||
} | ||
function commit(to) { | ||
if (this.pendingTo === to) { | ||
if (process.env.NODE_ENV === "development") { | ||
if (this.staged === STAGED_NO_VALUE) { | ||
console.warn( | ||
`Loader "${options.key}"'s "commit()" was called but there is no staged data.` | ||
); | ||
} | ||
} | ||
if (this.staged !== STAGED_NO_VALUE) { | ||
this.data.value = this.staged; | ||
} | ||
this.error.value = this.stagedError; | ||
this.staged = STAGED_NO_VALUE; | ||
this.stagedError = this.error.value; | ||
this.pendingTo = null; | ||
for (const childEntry of this.children) { | ||
childEntry.commit(to); | ||
} | ||
} | ||
} | ||
const useDataLoader = () => { | ||
const [parentEntry, _router, _route] = getCurrentContext(); | ||
const router = _router || _vuerouter.useRouter.call(void 0, ); | ||
const route = _route || _vuerouter.useRoute.call(void 0, ); | ||
const entries = router[LOADER_ENTRIES_KEY]; | ||
let entry = entries.get(loader); | ||
if (process.env.NODE_ENV === "development") { | ||
if (!parentEntry && !entry) { | ||
console.error( | ||
`Some "useDataLoader()" was called outside of a component's setup or a data loader.` | ||
); | ||
} | ||
} | ||
if ( | ||
// if the entry doesn't exist, create it with load and ensure it's loading | ||
!entry || // the existing pending location isn't good, we need to load again | ||
parentEntry && entry.pendingTo !== route | ||
) { | ||
router[APP_KEY].runWithContext(() => load(route, router, parentEntry)); | ||
} | ||
entry = entries.get(loader); | ||
if (parentEntry) { | ||
if (parentEntry === entry) { | ||
console.warn( | ||
`\u{1F476}\u274C "${options.key}" has itself as parent. This shouldn't be happening. Please report a bug with a reproduction to https://github.com/posva/unplugin-vue-router/` | ||
); | ||
} | ||
parentEntry.children.add(entry); | ||
} | ||
const { data, error, isLoading } = entry; | ||
const useDataLoaderResult = { | ||
data, | ||
error, | ||
isLoading, | ||
reload: (to = router.currentRoute.value) => router[APP_KEY].runWithContext(() => load(to, router)).then( | ||
() => entry.commit(to) | ||
) | ||
}; | ||
const promise = entry.pendingLoad.then(() => { | ||
return entry.staged === STAGED_NO_VALUE ? data.value : entry.staged; | ||
}).catch((e) => parentEntry ? Promise.reject(e) : null); | ||
return Object.assign(promise, useDataLoaderResult); | ||
}; | ||
useDataLoader[IS_USE_DATA_LOADER_KEY] = true; | ||
useDataLoader._ = { | ||
load, | ||
options, | ||
// @ts-expect-error: return type has the generics | ||
getEntry(router) { | ||
return router[LOADER_ENTRIES_KEY].get(loader); | ||
} | ||
}; | ||
return useDataLoader; | ||
} | ||
var DEFAULT_DEFINE_LOADER_OPTIONS = { | ||
lazy: false, | ||
server: true, | ||
commit: "immediate" | ||
}; | ||
var SERVER_INITIAL_DATA_KEY = Symbol(); | ||
var INITIAL_DATA_KEY = Symbol(); | ||
// src/data-fetching/defineColadaLoader.ts | ||
// node_modules/.pnpm/@pinia+colada@0.5.3/node_modules/@pinia/colada/dist/index.js | ||
// node_modules/.pnpm/vue-demi@0.14.7_vue@3.4.19/node_modules/vue-demi/lib/index.mjs | ||
var lib_exports = {}; | ||
_chunkM6BUQN66js.__export.call(void 0, lib_exports, { | ||
Vue: () => Vue, | ||
Vue2: () => Vue2, | ||
del: () => del, | ||
install: () => install, | ||
isVue2: () => isVue2, | ||
isVue3: () => isVue3, | ||
set: () => set | ||
}); | ||
_chunkM6BUQN66js.__reExport.call(void 0, lib_exports, vue_star); | ||
var isVue2 = false; | ||
var isVue3 = true; | ||
var Vue2 = void 0; | ||
function install() { | ||
} | ||
function set(target, key, val) { | ||
if (Array.isArray(target)) { | ||
target.length = Math.max(target.length, key); | ||
target.splice(key, 1, val); | ||
return val; | ||
} | ||
target[key] = val; | ||
return val; | ||
} | ||
function del(target, key) { | ||
if (Array.isArray(target)) { | ||
target.splice(key, 1); | ||
return; | ||
} | ||
delete target[key]; | ||
} | ||
// node_modules/.pnpm/pinia@2.1.7_typescript@5.3.3_vue@3.4.19/node_modules/pinia/dist/pinia.mjs | ||
var activePinia; | ||
var setActivePinia = (pinia) => activePinia = pinia; | ||
var piniaSymbol = process.env.NODE_ENV !== "production" ? Symbol("pinia") : ( | ||
/* istanbul ignore next */ | ||
Symbol() | ||
); | ||
function isPlainObject(o) { | ||
return o && typeof o === "object" && Object.prototype.toString.call(o) === "[object Object]" && typeof o.toJSON !== "function"; | ||
} | ||
var MutationType; | ||
(function(MutationType2) { | ||
MutationType2["direct"] = "direct"; | ||
MutationType2["patchObject"] = "patch object"; | ||
MutationType2["patchFunction"] = "patch function"; | ||
})(MutationType || (MutationType = {})); | ||
var IS_CLIENT2 = typeof window !== "undefined"; | ||
var USE_DEVTOOLS = (process.env.NODE_ENV !== "production" || typeof __VUE_PROD_DEVTOOLS__ !== "undefined" && __VUE_PROD_DEVTOOLS__) && !(process.env.NODE_ENV === "test") && IS_CLIENT2; | ||
var _global = /* @__PURE__ */ (() => 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 })(); | ||
function bom(blob, { autoBom = false } = {}) { | ||
if (autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { | ||
return new Blob([String.fromCharCode(65279), blob], { type: blob.type }); | ||
} | ||
return blob; | ||
} | ||
function download(url, name, opts) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open("GET", url); | ||
xhr.responseType = "blob"; | ||
xhr.onload = function() { | ||
saveAs(xhr.response, name, opts); | ||
}; | ||
xhr.onerror = function() { | ||
console.error("could not download file"); | ||
}; | ||
xhr.send(); | ||
} | ||
function corsEnabled(url) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open("HEAD", url, false); | ||
try { | ||
xhr.send(); | ||
} catch (e) { | ||
} | ||
return xhr.status >= 200 && xhr.status <= 299; | ||
} | ||
function click(node) { | ||
try { | ||
node.dispatchEvent(new MouseEvent("click")); | ||
} catch (e) { | ||
const evt = document.createEvent("MouseEvents"); | ||
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null); | ||
node.dispatchEvent(evt); | ||
} | ||
} | ||
var _navigator = typeof navigator === "object" ? navigator : { userAgent: "" }; | ||
var isMacOSWebView = /* @__PURE__ */ (() => /Macintosh/.test(_navigator.userAgent) && /AppleWebKit/.test(_navigator.userAgent) && !/Safari/.test(_navigator.userAgent))(); | ||
var saveAs = !IS_CLIENT2 ? () => { | ||
} : ( | ||
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView or mini program | ||
typeof HTMLAnchorElement !== "undefined" && "download" in HTMLAnchorElement.prototype && !isMacOSWebView ? downloadSaveAs : ( | ||
// Use msSaveOrOpenBlob as a second approach | ||
"msSaveOrOpenBlob" in _navigator ? msSaveAs : ( | ||
// Fallback to using FileReader and a popup | ||
fileSaverSaveAs | ||
) | ||
) | ||
); | ||
function downloadSaveAs(blob, name = "download", opts) { | ||
const a = document.createElement("a"); | ||
a.download = name; | ||
a.rel = "noopener"; | ||
if (typeof blob === "string") { | ||
a.href = blob; | ||
if (a.origin !== location.origin) { | ||
if (corsEnabled(a.href)) { | ||
download(blob, name, opts); | ||
} else { | ||
a.target = "_blank"; | ||
click(a); | ||
} | ||
} else { | ||
click(a); | ||
} | ||
} else { | ||
a.href = URL.createObjectURL(blob); | ||
setTimeout(function() { | ||
URL.revokeObjectURL(a.href); | ||
}, 4e4); | ||
setTimeout(function() { | ||
click(a); | ||
}, 0); | ||
} | ||
} | ||
function msSaveAs(blob, name = "download", opts) { | ||
if (typeof blob === "string") { | ||
if (corsEnabled(blob)) { | ||
download(blob, name, opts); | ||
} else { | ||
const a = document.createElement("a"); | ||
a.href = blob; | ||
a.target = "_blank"; | ||
setTimeout(function() { | ||
click(a); | ||
}); | ||
} | ||
} else { | ||
navigator.msSaveOrOpenBlob(bom(blob, opts), name); | ||
} | ||
} | ||
function fileSaverSaveAs(blob, name, opts, popup) { | ||
popup = popup || open("", "_blank"); | ||
if (popup) { | ||
popup.document.title = popup.document.body.innerText = "downloading..."; | ||
} | ||
if (typeof blob === "string") | ||
return download(blob, name, opts); | ||
const force = blob.type === "application/octet-stream"; | ||
const isSafari = /constructor/i.test(String(_global.HTMLElement)) || "safari" in _global; | ||
const isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent); | ||
if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== "undefined") { | ||
const reader = new FileReader(); | ||
reader.onloadend = function() { | ||
let url = reader.result; | ||
if (typeof url !== "string") { | ||
popup = null; | ||
throw new Error("Wrong reader.result type"); | ||
} | ||
url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, "data:attachment/file;"); | ||
if (popup) { | ||
popup.location.href = url; | ||
} else { | ||
location.assign(url); | ||
} | ||
popup = null; | ||
}; | ||
reader.readAsDataURL(blob); | ||
} else { | ||
const url = URL.createObjectURL(blob); | ||
if (popup) | ||
popup.location.assign(url); | ||
else | ||
location.href = url; | ||
popup = null; | ||
setTimeout(function() { | ||
URL.revokeObjectURL(url); | ||
}, 4e4); | ||
} | ||
} | ||
var { assign: assign$1 } = Object; | ||
function patchObject(newState, oldState) { | ||
for (const key in oldState) { | ||
const subPatch = oldState[key]; | ||
if (!(key in newState)) { | ||
continue; | ||
} | ||
const targetValue = newState[key]; | ||
if (isPlainObject(targetValue) && isPlainObject(subPatch) && !(0, lib_exports.isRef)(subPatch) && !(0, lib_exports.isReactive)(subPatch)) { | ||
newState[key] = patchObject(targetValue, subPatch); | ||
} else { | ||
if (isVue2) { | ||
set(newState, key, subPatch); | ||
} else { | ||
newState[key] = subPatch; | ||
} | ||
} | ||
} | ||
return newState; | ||
} | ||
var noop = () => { | ||
}; | ||
function addSubscription(subscriptions, callback, detached, onCleanup = noop) { | ||
subscriptions.push(callback); | ||
const removeSubscription = () => { | ||
const idx = subscriptions.indexOf(callback); | ||
if (idx > -1) { | ||
subscriptions.splice(idx, 1); | ||
onCleanup(); | ||
} | ||
}; | ||
if (!detached && (0, lib_exports.getCurrentScope)()) { | ||
(0, lib_exports.onScopeDispose)(removeSubscription); | ||
} | ||
return removeSubscription; | ||
} | ||
function triggerSubscriptions(subscriptions, ...args) { | ||
subscriptions.slice().forEach((callback) => { | ||
callback(...args); | ||
}); | ||
} | ||
var fallbackRunWithContext = (fn) => fn(); | ||
function mergeReactiveObjects(target, patchToApply) { | ||
if (target instanceof Map && patchToApply instanceof Map) { | ||
patchToApply.forEach((value, key) => target.set(key, value)); | ||
} | ||
if (target instanceof Set && patchToApply instanceof Set) { | ||
patchToApply.forEach(target.add, target); | ||
} | ||
for (const key in patchToApply) { | ||
if (!patchToApply.hasOwnProperty(key)) | ||
continue; | ||
const subPatch = patchToApply[key]; | ||
const targetValue = target[key]; | ||
if (isPlainObject(targetValue) && isPlainObject(subPatch) && target.hasOwnProperty(key) && !(0, lib_exports.isRef)(subPatch) && !(0, lib_exports.isReactive)(subPatch)) { | ||
target[key] = mergeReactiveObjects(targetValue, subPatch); | ||
} else { | ||
target[key] = subPatch; | ||
} | ||
} | ||
return target; | ||
} | ||
var skipHydrateSymbol = process.env.NODE_ENV !== "production" ? Symbol("pinia:skipHydration") : ( | ||
/* istanbul ignore next */ | ||
Symbol() | ||
); | ||
var skipHydrateMap = /* @__PURE__ */ new WeakMap(); | ||
function shouldHydrate(obj) { | ||
return isVue2 ? ( | ||
/* istanbul ignore next */ | ||
!skipHydrateMap.has(obj) | ||
) : !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol); | ||
} | ||
var { assign: assign2 } = Object; | ||
function isComputed(o) { | ||
return !!((0, lib_exports.isRef)(o) && o.effect); | ||
} | ||
function createOptionsStore(id, options, pinia, hot) { | ||
const { state, actions, getters } = options; | ||
const initialState = pinia.state.value[id]; | ||
let store; | ||
function setup() { | ||
if (!initialState && (!(process.env.NODE_ENV !== "production") || !hot)) { | ||
if (isVue2) { | ||
set(pinia.state.value, id, state ? state() : {}); | ||
} else { | ||
pinia.state.value[id] = state ? state() : {}; | ||
} | ||
} | ||
const localState = process.env.NODE_ENV !== "production" && hot ? ( | ||
// use ref() to unwrap refs inside state TODO: check if this is still necessary | ||
(0, lib_exports.toRefs)((0, lib_exports.ref)(state ? state() : {}).value) | ||
) : (0, lib_exports.toRefs)(pinia.state.value[id]); | ||
return assign2(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name) => { | ||
if (process.env.NODE_ENV !== "production" && name in localState) { | ||
console.warn(`[\u{1F34D}]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`); | ||
} | ||
computedGetters[name] = (0, lib_exports.markRaw)((0, lib_exports.computed)(() => { | ||
setActivePinia(pinia); | ||
const store2 = pinia._s.get(id); | ||
if (isVue2 && !store2._r) | ||
return; | ||
return getters[name].call(store2, store2); | ||
})); | ||
return computedGetters; | ||
}, {})); | ||
} | ||
store = createSetupStore(id, setup, options, pinia, hot, true); | ||
return store; | ||
} | ||
function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) { | ||
let scope; | ||
const optionsForPlugin = assign2({ actions: {} }, options); | ||
if (process.env.NODE_ENV !== "production" && !pinia._e.active) { | ||
throw new Error("Pinia destroyed"); | ||
} | ||
const $subscribeOptions = { | ||
deep: true | ||
// flush: 'post', | ||
}; | ||
if (process.env.NODE_ENV !== "production" && !isVue2) { | ||
$subscribeOptions.onTrigger = (event) => { | ||
if (isListening) { | ||
debuggerEvents = event; | ||
} else if (isListening == false && !store._hotUpdating) { | ||
if (Array.isArray(debuggerEvents)) { | ||
debuggerEvents.push(event); | ||
} else { | ||
console.error("\u{1F34D} debuggerEvents should be an array. This is most likely an internal Pinia bug."); | ||
} | ||
} | ||
}; | ||
} | ||
let isListening; | ||
let isSyncListening; | ||
let subscriptions = []; | ||
let actionSubscriptions = []; | ||
let debuggerEvents; | ||
const initialState = pinia.state.value[$id]; | ||
if (!isOptionsStore && !initialState && (!(process.env.NODE_ENV !== "production") || !hot)) { | ||
if (isVue2) { | ||
set(pinia.state.value, $id, {}); | ||
} else { | ||
pinia.state.value[$id] = {}; | ||
} | ||
} | ||
const hotState = (0, lib_exports.ref)({}); | ||
let activeListener; | ||
function $patch(partialStateOrMutator) { | ||
let subscriptionMutation; | ||
isListening = isSyncListening = false; | ||
if (process.env.NODE_ENV !== "production") { | ||
debuggerEvents = []; | ||
} | ||
if (typeof partialStateOrMutator === "function") { | ||
partialStateOrMutator(pinia.state.value[$id]); | ||
subscriptionMutation = { | ||
type: MutationType.patchFunction, | ||
storeId: $id, | ||
events: debuggerEvents | ||
}; | ||
} else { | ||
mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator); | ||
subscriptionMutation = { | ||
type: MutationType.patchObject, | ||
payload: partialStateOrMutator, | ||
storeId: $id, | ||
events: debuggerEvents | ||
}; | ||
} | ||
const myListenerId = activeListener = Symbol(); | ||
(0, lib_exports.nextTick)().then(() => { | ||
if (activeListener === myListenerId) { | ||
isListening = true; | ||
} | ||
}); | ||
isSyncListening = true; | ||
triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]); | ||
} | ||
const $reset = isOptionsStore ? function $reset2() { | ||
const { state } = options; | ||
const newState = state ? state() : {}; | ||
this.$patch(($state) => { | ||
assign2($state, newState); | ||
}); | ||
} : ( | ||
/* istanbul ignore next */ | ||
process.env.NODE_ENV !== "production" ? () => { | ||
throw new Error(`\u{1F34D}: Store "${$id}" is built using the setup syntax and does not implement $reset().`); | ||
} : noop | ||
); | ||
function $dispose() { | ||
scope.stop(); | ||
subscriptions = []; | ||
actionSubscriptions = []; | ||
pinia._s.delete($id); | ||
} | ||
function wrapAction(name, action) { | ||
return function() { | ||
setActivePinia(pinia); | ||
const args = Array.from(arguments); | ||
const afterCallbackList = []; | ||
const onErrorCallbackList = []; | ||
function after(callback) { | ||
afterCallbackList.push(callback); | ||
} | ||
function onError(callback) { | ||
onErrorCallbackList.push(callback); | ||
} | ||
triggerSubscriptions(actionSubscriptions, { | ||
args, | ||
name, | ||
store, | ||
after, | ||
onError | ||
}); | ||
let ret; | ||
try { | ||
ret = action.apply(this && this.$id === $id ? this : store, args); | ||
} catch (error) { | ||
triggerSubscriptions(onErrorCallbackList, error); | ||
throw error; | ||
} | ||
if (ret instanceof Promise) { | ||
return ret.then((value) => { | ||
triggerSubscriptions(afterCallbackList, value); | ||
return value; | ||
}).catch((error) => { | ||
triggerSubscriptions(onErrorCallbackList, error); | ||
return Promise.reject(error); | ||
}); | ||
} | ||
triggerSubscriptions(afterCallbackList, ret); | ||
return ret; | ||
}; | ||
} | ||
const _hmrPayload = /* @__PURE__ */ (0, lib_exports.markRaw)({ | ||
actions: {}, | ||
getters: {}, | ||
state: [], | ||
hotState | ||
}); | ||
const partialStore = { | ||
_p: pinia, | ||
// _s: scope, | ||
$id, | ||
$onAction: addSubscription.bind(null, actionSubscriptions), | ||
$patch, | ||
$reset, | ||
$subscribe(callback, options2 = {}) { | ||
const removeSubscription = addSubscription(subscriptions, callback, options2.detached, () => stopWatcher()); | ||
const stopWatcher = scope.run(() => (0, lib_exports.watch)(() => pinia.state.value[$id], (state) => { | ||
if (options2.flush === "sync" ? isSyncListening : isListening) { | ||
callback({ | ||
storeId: $id, | ||
type: MutationType.direct, | ||
events: debuggerEvents | ||
}, state); | ||
} | ||
}, assign2({}, $subscribeOptions, options2))); | ||
return removeSubscription; | ||
}, | ||
$dispose | ||
}; | ||
if (isVue2) { | ||
partialStore._r = false; | ||
} | ||
const store = (0, lib_exports.reactive)(process.env.NODE_ENV !== "production" || USE_DEVTOOLS ? assign2( | ||
{ | ||
_hmrPayload, | ||
_customProperties: (0, lib_exports.markRaw)(/* @__PURE__ */ new Set()) | ||
// devtools custom properties | ||
}, | ||
partialStore | ||
// must be added later | ||
// setupStore | ||
) : partialStore); | ||
pinia._s.set($id, store); | ||
const runWithContext = pinia._a && pinia._a.runWithContext || fallbackRunWithContext; | ||
const setupStore = runWithContext(() => pinia._e.run(() => (scope = (0, lib_exports.effectScope)()).run(setup))); | ||
for (const key in setupStore) { | ||
const prop = setupStore[key]; | ||
if ((0, lib_exports.isRef)(prop) && !isComputed(prop) || (0, lib_exports.isReactive)(prop)) { | ||
if (process.env.NODE_ENV !== "production" && hot) { | ||
set(hotState.value, key, (0, lib_exports.toRef)(setupStore, key)); | ||
} else if (!isOptionsStore) { | ||
if (initialState && shouldHydrate(prop)) { | ||
if ((0, lib_exports.isRef)(prop)) { | ||
prop.value = initialState[key]; | ||
} else { | ||
mergeReactiveObjects(prop, initialState[key]); | ||
} | ||
} | ||
if (isVue2) { | ||
set(pinia.state.value[$id], key, prop); | ||
} else { | ||
pinia.state.value[$id][key] = prop; | ||
} | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
_hmrPayload.state.push(key); | ||
} | ||
} else if (typeof prop === "function") { | ||
const actionValue = process.env.NODE_ENV !== "production" && hot ? prop : wrapAction(key, prop); | ||
if (isVue2) { | ||
set(setupStore, key, actionValue); | ||
} else { | ||
setupStore[key] = actionValue; | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
_hmrPayload.actions[key] = prop; | ||
} | ||
optionsForPlugin.actions[key] = prop; | ||
} else if (process.env.NODE_ENV !== "production") { | ||
if (isComputed(prop)) { | ||
_hmrPayload.getters[key] = isOptionsStore ? ( | ||
// @ts-expect-error | ||
options.getters[key] | ||
) : prop; | ||
if (IS_CLIENT2) { | ||
const getters = setupStore._getters || // @ts-expect-error: same | ||
(setupStore._getters = (0, lib_exports.markRaw)([])); | ||
getters.push(key); | ||
} | ||
} | ||
} | ||
} | ||
if (isVue2) { | ||
Object.keys(setupStore).forEach((key) => { | ||
set(store, key, setupStore[key]); | ||
}); | ||
} else { | ||
assign2(store, setupStore); | ||
assign2((0, lib_exports.toRaw)(store), setupStore); | ||
} | ||
Object.defineProperty(store, "$state", { | ||
get: () => process.env.NODE_ENV !== "production" && hot ? hotState.value : pinia.state.value[$id], | ||
set: (state) => { | ||
if (process.env.NODE_ENV !== "production" && hot) { | ||
throw new Error("cannot set hotState"); | ||
} | ||
$patch(($state) => { | ||
assign2($state, state); | ||
}); | ||
} | ||
}); | ||
if (process.env.NODE_ENV !== "production") { | ||
store._hotUpdate = (0, lib_exports.markRaw)((newStore) => { | ||
store._hotUpdating = true; | ||
newStore._hmrPayload.state.forEach((stateKey) => { | ||
if (stateKey in store.$state) { | ||
const newStateTarget = newStore.$state[stateKey]; | ||
const oldStateSource = store.$state[stateKey]; | ||
if (typeof newStateTarget === "object" && isPlainObject(newStateTarget) && isPlainObject(oldStateSource)) { | ||
patchObject(newStateTarget, oldStateSource); | ||
} else { | ||
newStore.$state[stateKey] = oldStateSource; | ||
} | ||
} | ||
set(store, stateKey, (0, lib_exports.toRef)(newStore.$state, stateKey)); | ||
}); | ||
Object.keys(store.$state).forEach((stateKey) => { | ||
if (!(stateKey in newStore.$state)) { | ||
del(store, stateKey); | ||
} | ||
}); | ||
isListening = false; | ||
isSyncListening = false; | ||
pinia.state.value[$id] = (0, lib_exports.toRef)(newStore._hmrPayload, "hotState"); | ||
isSyncListening = true; | ||
(0, lib_exports.nextTick)().then(() => { | ||
isListening = true; | ||
}); | ||
for (const actionName in newStore._hmrPayload.actions) { | ||
const action = newStore[actionName]; | ||
set(store, actionName, wrapAction(actionName, action)); | ||
} | ||
for (const getterName in newStore._hmrPayload.getters) { | ||
const getter = newStore._hmrPayload.getters[getterName]; | ||
const getterValue = isOptionsStore ? ( | ||
// special handling of options api | ||
(0, lib_exports.computed)(() => { | ||
setActivePinia(pinia); | ||
return getter.call(store, store); | ||
}) | ||
) : getter; | ||
set(store, getterName, getterValue); | ||
} | ||
Object.keys(store._hmrPayload.getters).forEach((key) => { | ||
if (!(key in newStore._hmrPayload.getters)) { | ||
del(store, key); | ||
} | ||
}); | ||
Object.keys(store._hmrPayload.actions).forEach((key) => { | ||
if (!(key in newStore._hmrPayload.actions)) { | ||
del(store, key); | ||
} | ||
}); | ||
store._hmrPayload = newStore._hmrPayload; | ||
store._getters = newStore._getters; | ||
store._hotUpdating = false; | ||
}); | ||
} | ||
if (USE_DEVTOOLS) { | ||
const nonEnumerable = { | ||
writable: true, | ||
configurable: true, | ||
// avoid warning on devtools trying to display this property | ||
enumerable: false | ||
}; | ||
["_p", "_hmrPayload", "_getters", "_customProperties"].forEach((p) => { | ||
Object.defineProperty(store, p, assign2({ value: store[p] }, nonEnumerable)); | ||
}); | ||
} | ||
if (isVue2) { | ||
store._r = true; | ||
} | ||
pinia._p.forEach((extender) => { | ||
if (USE_DEVTOOLS) { | ||
const extensions = scope.run(() => extender({ | ||
store, | ||
app: pinia._a, | ||
pinia, | ||
options: optionsForPlugin | ||
})); | ||
Object.keys(extensions || {}).forEach((key) => store._customProperties.add(key)); | ||
assign2(store, extensions); | ||
} else { | ||
assign2(store, scope.run(() => extender({ | ||
store, | ||
app: pinia._a, | ||
pinia, | ||
options: optionsForPlugin | ||
}))); | ||
} | ||
}); | ||
if (process.env.NODE_ENV !== "production" && store.$state && typeof store.$state === "object" && typeof store.$state.constructor === "function" && !store.$state.constructor.toString().includes("[native code]")) { | ||
console.warn(`[\u{1F34D}]: The "state" must be a plain object. It cannot be | ||
state: () => new MyClass() | ||
Found in store "${store.$id}".`); | ||
} | ||
if (initialState && isOptionsStore && options.hydrate) { | ||
options.hydrate(store.$state, initialState); | ||
} | ||
isListening = true; | ||
isSyncListening = true; | ||
return store; | ||
} | ||
function defineStore(idOrOptions, setup, setupOptions) { | ||
let id; | ||
let options; | ||
const isSetupStore = typeof setup === "function"; | ||
if (typeof idOrOptions === "string") { | ||
id = idOrOptions; | ||
options = isSetupStore ? setupOptions : setup; | ||
} else { | ||
options = idOrOptions; | ||
id = idOrOptions.id; | ||
if (process.env.NODE_ENV !== "production" && typeof id !== "string") { | ||
throw new Error(`[\u{1F34D}]: "defineStore()" must be passed a store id as its first argument.`); | ||
} | ||
} | ||
function useStore(pinia, hot) { | ||
const hasContext = (0, lib_exports.hasInjectionContext)(); | ||
pinia = // in test mode, ignore the argument provided as we can always retrieve a | ||
// pinia instance with getActivePinia() | ||
(process.env.NODE_ENV === "test" && activePinia && activePinia._testing ? null : pinia) || (hasContext ? (0, lib_exports.inject)(piniaSymbol, null) : null); | ||
if (pinia) | ||
setActivePinia(pinia); | ||
if (process.env.NODE_ENV !== "production" && !activePinia) { | ||
throw new Error(`[\u{1F34D}]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"? | ||
See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help. | ||
This will fail in production.`); | ||
} | ||
pinia = activePinia; | ||
if (!pinia._s.has(id)) { | ||
if (isSetupStore) { | ||
createSetupStore(id, setup, options, pinia); | ||
} else { | ||
createOptionsStore(id, options, pinia); | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
useStore._pinia = pinia; | ||
} | ||
} | ||
const store = pinia._s.get(id); | ||
if (process.env.NODE_ENV !== "production" && hot) { | ||
const hotId = "__hot:" + id; | ||
const newStore = isSetupStore ? createSetupStore(hotId, setup, options, pinia, true) : createOptionsStore(hotId, assign2({}, options), pinia, true); | ||
hot._hotUpdate(newStore); | ||
delete pinia.state.value[hotId]; | ||
pinia._s.delete(hotId); | ||
} | ||
if (process.env.NODE_ENV !== "production" && IS_CLIENT2) { | ||
const currentInstance = (0, lib_exports.getCurrentInstance)(); | ||
if (currentInstance && currentInstance.proxy && // avoid adding stores that are just built for hot module replacement | ||
!hot) { | ||
const vm = currentInstance.proxy; | ||
const cache = "_pStores" in vm ? vm._pStores : vm._pStores = {}; | ||
cache[id] = store; | ||
} | ||
} | ||
return store; | ||
} | ||
useStore.$id = id; | ||
return useStore; | ||
} | ||
// node_modules/.pnpm/@pinia+colada@0.5.3/node_modules/@pinia/colada/dist/index.js | ||
function useEventListener(target, event, listener, options) { | ||
target.addEventListener(event, listener, options); | ||
if (_vue.getCurrentScope.call(void 0, )) { | ||
_vue.onScopeDispose.call(void 0, () => { | ||
target.removeEventListener(event, listener); | ||
}); | ||
} | ||
} | ||
var IS_CLIENT3 = typeof window !== "undefined"; | ||
function stringifyFlatObject(obj) { | ||
return obj && typeof obj === "object" ? JSON.stringify(obj, Object.keys(obj).sort()) : String(obj); | ||
} | ||
var computedRef = (other) => _vue.computed.call(void 0, { | ||
get: () => other().value, | ||
set: (value) => other().value = value | ||
}); | ||
var TreeMapNode = class _TreeMapNode { | ||
constructor(...args) { | ||
if (args.length) { | ||
this.set(...args); | ||
} | ||
} | ||
/** | ||
* Sets the value while building the tree | ||
* | ||
* @param keys - key as an array | ||
* @param value - value to set | ||
*/ | ||
set(keys, value) { | ||
if (keys.length === 0) { | ||
this.value = value; | ||
} else { | ||
const [top, ...otherKeys] = keys; | ||
const node = _optionalChain([this, 'access', _16 => _16.children, 'optionalAccess', _17 => _17.get, 'call', _18 => _18(top)]); | ||
if (node) { | ||
node.set(otherKeys, value); | ||
} else { | ||
this.children ??= /* @__PURE__ */ new Map(); | ||
this.children.set(top, new _TreeMapNode(otherKeys, value)); | ||
} | ||
} | ||
} | ||
/** | ||
* Finds the node at the given path of keys. | ||
* | ||
* @param keys - path of keys | ||
*/ | ||
find(keys) { | ||
if (keys.length === 0) { | ||
return this; | ||
} else { | ||
const [top, ...otherKeys] = keys; | ||
return _optionalChain([this, 'access', _19 => _19.children, 'optionalAccess', _20 => _20.get, 'call', _21 => _21(top), 'optionalAccess', _22 => _22.find, 'call', _23 => _23(otherKeys)]); | ||
} | ||
} | ||
/** | ||
* Gets the value at the given path of keys. | ||
* | ||
* @param keys - path of keys | ||
*/ | ||
get(keys) { | ||
return _optionalChain([this, 'access', _24 => _24.find, 'call', _25 => _25(keys), 'optionalAccess', _26 => _26.value]); | ||
} | ||
/** | ||
* Delete the node at the given path of keys and all its children. | ||
* | ||
* @param keys - path of keys | ||
*/ | ||
delete(keys) { | ||
if (keys.length === 1) { | ||
_optionalChain([this, 'access', _27 => _27.children, 'optionalAccess', _28 => _28.delete, 'call', _29 => _29(keys[0])]); | ||
} else { | ||
const [top, ...otherKeys] = keys; | ||
_optionalChain([this, 'access', _30 => _30.children, 'optionalAccess', _31 => _31.get, 'call', _32 => _32(top), 'optionalAccess', _33 => _33.delete, 'call', _34 => _34(otherKeys)]); | ||
} | ||
} | ||
/** | ||
* Iterates over the node values if not null or undefined and all its children. Goes in depth first order. Allows a `for (const of node)` loop. | ||
*/ | ||
*[Symbol.iterator]() { | ||
if (this.value != null) { | ||
yield this.value; | ||
} | ||
if (this.children) { | ||
for (const child of this.children.values()) { | ||
yield* child; | ||
} | ||
} | ||
} | ||
}; | ||
function createQueryEntry(initialData, error = null, when = 0) { | ||
const data = _vue.shallowRef.call(void 0, initialData); | ||
const status = _vue.shallowRef.call(void 0, | ||
error ? "error" : initialData !== void 0 ? "success" : "pending" | ||
); | ||
return { | ||
data, | ||
error: _vue.shallowRef.call(void 0, error), | ||
when, | ||
status, | ||
isPending: _vue.computed.call(void 0, () => data.value === void 0), | ||
isFetching: _vue.computed.call(void 0, () => status.value === "loading"), | ||
pending: null | ||
}; | ||
} | ||
var QUERY_STORE_ID = "_pc_query"; | ||
var useQueryCache = defineStore(QUERY_STORE_ID, () => { | ||
const cachesRaw = new TreeMapNode(); | ||
const caches = _vue.shallowReactive.call(void 0, cachesRaw); | ||
const scope = _vue.getCurrentScope.call(void 0, ); | ||
function ensureEntry(keyRaw, options) { | ||
if (process.env.NODE_ENV !== "production" && keyRaw.length === 0) { | ||
throw new Error( | ||
`useQuery() was called with an empty array as the key. It must have at least one element.` | ||
); | ||
} | ||
const key = keyRaw.map(stringifyFlatObject); | ||
let entry = cachesRaw.get(key); | ||
if (!entry) { | ||
cachesRaw.set( | ||
key, | ||
entry = scope.run(() => createQueryEntry(_optionalChain([options, 'access', _35 => _35.initialData, 'optionalCall', _36 => _36()]))) | ||
); | ||
} | ||
if (!entry.options) { | ||
entry.options = options; | ||
} | ||
return entry; | ||
} | ||
function invalidateEntry(key, { | ||
refetch: shouldRefetch = true, | ||
exact = false | ||
} = {}) { | ||
const entryNode = cachesRaw.find(key.map(stringifyFlatObject)); | ||
if (!entryNode) { | ||
return; | ||
} | ||
const list = exact ? entryNode.value != null ? [entryNode.value] : [] : [...entryNode]; | ||
for (const entry of list) { | ||
entry.when = 0; | ||
if (shouldRefetch) { | ||
entry.pending = null; | ||
refetch(entry); | ||
} | ||
} | ||
} | ||
async function refresh(entry) { | ||
if (process.env.NODE_ENV !== "production" && !entry.options) { | ||
throw new Error( | ||
`"entry.refresh()" was called but the entry has no options. This is probably a bug, report it to pinia-colada with a boiled down example to reproduce it. Thank you!` | ||
); | ||
} | ||
const { key: _key, staleTime } = entry.options; | ||
const key = _vue.toValue.call(void 0, _key).map(stringifyFlatObject); | ||
if (entry.error.value || isExpired(entry.when, staleTime)) { | ||
await (_nullishCoalesce(_optionalChain([entry, 'access', _37 => _37.pending, 'optionalAccess', _38 => _38.refreshCall]), () => ( refetch(entry)))); | ||
} | ||
return entry.data.value; | ||
} | ||
async function refetch(entry) { | ||
if (process.env.NODE_ENV !== "production" && !entry.options) { | ||
throw new Error( | ||
`"entry.refetch()" was called but the entry has no options. This is probably a bug, report it to pinia-colada with a boiled down example to reproduce it. Thank you!` | ||
); | ||
} | ||
const key = _vue.toValue.call(void 0, entry.options.key).map(stringifyFlatObject); | ||
entry.status.value = "loading"; | ||
const signalController = new AbortController(); | ||
const { signal } = signalController; | ||
const pendingCall = entry.pending = { | ||
refreshCall: entry.options.query({ signal }).then((data) => { | ||
if (pendingCall === entry.pending && !signal.aborted) { | ||
entry.error.value = null; | ||
entry.data.value = data; | ||
entry.status.value = "success"; | ||
} | ||
}).catch((error) => { | ||
if (pendingCall === entry.pending) { | ||
entry.error.value = error; | ||
entry.status.value = "error"; | ||
} | ||
}).finally(() => { | ||
if (pendingCall === entry.pending) { | ||
entry.pending = null; | ||
entry.when = Date.now(); | ||
} | ||
}), | ||
when: Date.now() | ||
}; | ||
await pendingCall.refreshCall; | ||
return entry.data.value; | ||
} | ||
function setQueryData(key, data) { | ||
const entry = caches.get(key.map(stringifyFlatObject)); | ||
if (!entry) { | ||
return; | ||
} | ||
if (typeof data === "function") { | ||
; | ||
data(entry.data); | ||
_vue.triggerRef.call(void 0, entry.data); | ||
} else { | ||
entry.data.value = data; | ||
} | ||
entry.error.value = null; | ||
} | ||
function getQueryData(key) { | ||
const entry = caches.get(key.map(stringifyFlatObject)); | ||
return _optionalChain([entry, 'optionalAccess', _39 => _39.data, 'access', _40 => _40.value]); | ||
} | ||
function prefetch(key) { | ||
const entry = cachesRaw.get(key.map(stringifyFlatObject)); | ||
if (!entry) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.warn( | ||
`\u26A0\uFE0F trying to prefetch "${String(key)}" but it's not in the registry` | ||
); | ||
} | ||
return; | ||
} | ||
return refetch(entry); | ||
} | ||
return { | ||
caches, | ||
ensureEntry, | ||
invalidateEntry, | ||
setQueryData, | ||
getQueryData, | ||
refetch, | ||
refresh | ||
}; | ||
}); | ||
function isExpired(lastRefresh, staleTime) { | ||
return Date.now() > lastRefresh + staleTime; | ||
} | ||
var DATA_TYPE_SYMBOL = Symbol(); | ||
var USE_QUERY_DEFAULTS = { | ||
staleTime: 1e3 * 5, | ||
// 5 seconds | ||
gcTime: 1e3 * 60 * 5, | ||
// 5 minutes | ||
// avoid type narrowing to `true` | ||
refetchOnWindowFocus: true, | ||
refetchOnReconnect: true, | ||
refetchOnMount: true | ||
}; | ||
var USE_QUERY_OPTIONS_KEY = process.env.NODE_ENV !== "production" ? Symbol("useQueryOptions") : Symbol(); | ||
var useQueryOptions = () => _vue.inject.call(void 0, USE_QUERY_OPTIONS_KEY); | ||
function useQuery(_options) { | ||
const store = useQueryCache(); | ||
const USE_QUERY_DEFAULTS2 = useQueryOptions(); | ||
const options = { | ||
...USE_QUERY_DEFAULTS2, | ||
..._options | ||
}; | ||
const entry = _vue.computed.call(void 0, | ||
() => store.ensureEntry(_vue.toValue.call(void 0, options.key), options) | ||
); | ||
const refresh = () => store.refresh(entry.value); | ||
const refetch = () => store.refetch(entry.value); | ||
const queryReturn = { | ||
data: computedRef(() => entry.value.data), | ||
error: computedRef(() => entry.value.error), | ||
isFetching: _vue.computed.call(void 0, () => entry.value.isFetching.value), | ||
isPending: _vue.computed.call(void 0, () => entry.value.isPending.value), | ||
status: computedRef(() => entry.value.status), | ||
refresh, | ||
refetch | ||
}; | ||
const hasCurrentInstance = _vue.getCurrentInstance.call(void 0, ); | ||
if (hasCurrentInstance) { | ||
_vue.onServerPrefetch.call(void 0, async () => { | ||
await refresh(); | ||
queryReturn.data.value, queryReturn.error.value, queryReturn.isFetching.value, queryReturn.isPending.value; | ||
}); | ||
} | ||
let isActive = false; | ||
if (hasCurrentInstance) { | ||
_vue.onMounted.call(void 0, () => { | ||
isActive = true; | ||
}); | ||
} else { | ||
isActive = true; | ||
} | ||
_vue.watch.call(void 0, entry, (entry2, _, onCleanup) => { | ||
if (!isActive) | ||
return; | ||
refresh(); | ||
onCleanup(() => { | ||
}); | ||
}); | ||
if (options.refetchOnMount && hasCurrentInstance) { | ||
_vue.onMounted.call(void 0, () => { | ||
if (options.refetchOnMount) { | ||
if (options.refetchOnMount === "always") { | ||
refetch(); | ||
} else { | ||
refresh(); | ||
} | ||
} | ||
}); | ||
} | ||
if (_vue.getCurrentScope.call(void 0, )) { | ||
_vue.onScopeDispose.call(void 0, () => { | ||
}); | ||
} | ||
if (IS_CLIENT3) { | ||
if (options.refetchOnWindowFocus) { | ||
useEventListener(document, "visibilitychange", () => { | ||
if (document.visibilityState === "visible") { | ||
if (options.refetchOnWindowFocus === "always") { | ||
refetch(); | ||
} else { | ||
refresh(); | ||
} | ||
} | ||
}); | ||
} | ||
if (options.refetchOnReconnect) { | ||
useEventListener(window, "online", () => { | ||
if (options.refetchOnReconnect === "always") { | ||
refetch(); | ||
} else { | ||
refresh(); | ||
} | ||
}); | ||
} | ||
} | ||
_optionalChain([options, 'access', _41 => _41.setup, 'optionalCall', _42 => _42({ | ||
...queryReturn, | ||
options | ||
})]); | ||
return queryReturn; | ||
} | ||
// src/data-fetching/defineColadaLoader.ts | ||
function defineColadaLoader(nameOrOptions, _options) { | ||
_options = _options || nameOrOptions; | ||
const loader = _options.query; | ||
const options = { | ||
...DEFAULT_DEFINE_LOADER_OPTIONS2, | ||
..._options, | ||
commit: _optionalChain([_options, 'optionalAccess', _43 => _43.commit]) || "after-load" | ||
}; | ||
let isInitial = true; | ||
function load(to, router, parent, reload) { | ||
const entries = router[LOADER_ENTRIES_KEY]; | ||
const key = keyText(options.key(to)); | ||
if (!entries.has(loader)) { | ||
const route = _vue.shallowRef.call(void 0, to); | ||
entries.set(loader, { | ||
// force the type to match | ||
data: _vue.shallowRef.call(void 0, ), | ||
isLoading: _vue.shallowRef.call(void 0, false), | ||
error: _vue.shallowRef.call(void 0, ), | ||
options, | ||
children: /* @__PURE__ */ new Set(), | ||
resetPending() { | ||
this.pendingTo = null; | ||
this.pendingLoad = null; | ||
this.isLoading.value = false; | ||
}, | ||
staged: STAGED_NO_VALUE, | ||
stagedError: null, | ||
commit, | ||
tracked: /* @__PURE__ */ new Map(), | ||
ext: null, | ||
route, | ||
pendingTo: null, | ||
pendingLoad: null | ||
}); | ||
} | ||
const entry = entries.get(loader); | ||
if (entry.pendingTo === to && entry.pendingLoad) { | ||
return entry.pendingLoad; | ||
} | ||
if (!entry.ext) { | ||
entry.ext = useQuery({ | ||
...options, | ||
// FIXME: type Promise<Data> instead of Promise<unknown> | ||
query: () => { | ||
const route = entry.route.value; | ||
const [trackedRoute, params, query, hash] = trackRoute(route); | ||
entry.tracked.set(options.key(trackedRoute).join("|"), { | ||
ready: false, | ||
params, | ||
query, | ||
hash | ||
}); | ||
return loader(trackedRoute, { | ||
signal: route.meta[ABORT_CONTROLLER_KEY].signal | ||
}); | ||
}, | ||
key: () => options.key(entry.route.value) | ||
}); | ||
} | ||
const { isLoading, data, error, ext } = entry; | ||
if (isInitial) { | ||
isInitial = false; | ||
if (ext.data.value !== void 0) { | ||
data.value = ext.data.value; | ||
return entry.pendingLoad = Promise.resolve(); | ||
} | ||
} | ||
if (entry.route.value !== to) { | ||
const tracked = entry.tracked.get(key.join("|")); | ||
reload = !tracked || hasRouteChanged(to, tracked); | ||
} | ||
entry.route.value = entry.pendingTo = to; | ||
isLoading.value = true; | ||
const currentContext2 = getCurrentContext(); | ||
if (process.env.NODE_ENV === "development") { | ||
if (parent !== currentContext2[0]) { | ||
console.warn( | ||
`\u274C\u{1F476} "${key}" has a different parent than the current context. This shouldn't be happening. Please report a bug with a reproduction to https://github.com/posva/unplugin-vue-router/` | ||
); | ||
} | ||
} | ||
setCurrentContext([entry, router, to]); | ||
entry.staged = STAGED_NO_VALUE; | ||
entry.stagedError = error.value; | ||
const currentLoad = ext[reload ? "refetch" : "refresh"]().then((d) => { | ||
if (entry.pendingLoad === currentLoad) { | ||
const newError = ext.error.value; | ||
if (newError) { | ||
entry.stagedError = newError; | ||
if (!options.lazy || !IS_CLIENT) { | ||
return Promise.reject(newError); | ||
} | ||
} else { | ||
const newData = ext.data.value; | ||
if (newData instanceof NavigationResult) { | ||
to.meta[NAVIGATION_RESULTS_KEY].push(newData); | ||
} else { | ||
entry.staged = newData; | ||
entry.stagedError = null; | ||
} | ||
} | ||
} | ||
}).finally(() => { | ||
setCurrentContext(currentContext2); | ||
if (entry.pendingLoad === currentLoad) { | ||
isLoading.value = false; | ||
if (options.commit === "immediate" || // outside of a navigation | ||
!router[PENDING_LOCATION_KEY]) { | ||
entry.commit(to); | ||
} | ||
} else { | ||
} | ||
}); | ||
setCurrentContext(currentContext2); | ||
entry.pendingLoad = currentLoad; | ||
return currentLoad; | ||
} | ||
function commit(to) { | ||
const key = keyText(options.key(to)); | ||
if (this.pendingTo === to) { | ||
if (process.env.NODE_ENV === "development") { | ||
if (this.staged === STAGED_NO_VALUE) { | ||
console.warn( | ||
`Loader "${key}"'s "commit()" was called but there is no staged data.` | ||
); | ||
} | ||
} | ||
if (this.staged !== STAGED_NO_VALUE) { | ||
this.data.value = this.staged; | ||
this.tracked.get(key.join("|")).ready = true; | ||
} | ||
this.error.value = this.stagedError; | ||
this.staged = STAGED_NO_VALUE; | ||
this.stagedError = this.error.value; | ||
this.pendingTo = null; | ||
for (const childEntry of this.children) { | ||
childEntry.commit(to); | ||
} | ||
} else { | ||
} | ||
} | ||
const useDataLoader = () => { | ||
const [parentEntry, _router, _route] = getCurrentContext(); | ||
const router = _router || _vuerouter.useRouter.call(void 0, ); | ||
const route = _route || _vuerouter.useRoute.call(void 0, ); | ||
const entries = router[LOADER_ENTRIES_KEY]; | ||
let entry = entries.get(loader); | ||
if (process.env.NODE_ENV === "development") { | ||
if (!parentEntry && !entry) { | ||
console.error( | ||
`Some "useDataLoader()" was called outside of a component's setup or a data loader.` | ||
); | ||
} | ||
} | ||
if ( | ||
// if the entry doesn't exist, create it with load and ensure it's loading | ||
!entry || // we are nested and the parent is loading a different route than us | ||
parentEntry && entry.pendingTo !== route | ||
) { | ||
router[APP_KEY].runWithContext( | ||
() => load(route, router, parentEntry, true) | ||
); | ||
} | ||
entry = entries.get(loader); | ||
if (parentEntry) { | ||
if (parentEntry === entry) { | ||
console.warn( | ||
`\u{1F476}\u274C "${options.key}" has itself as parent. This shouldn't be happening. Please report a bug with a reproduction to https://github.com/posva/unplugin-vue-router/` | ||
); | ||
} | ||
parentEntry.children.add(entry); | ||
} | ||
const { data, error, isLoading, ext } = entry; | ||
_vue.watch.call(void 0, ext.data, (newData) => { | ||
if (!router[PENDING_LOCATION_KEY]) { | ||
data.value = newData; | ||
} | ||
}); | ||
_vue.watch.call(void 0, ext.isFetching, (isFetching) => { | ||
if (!router[PENDING_LOCATION_KEY]) { | ||
isLoading.value = isFetching; | ||
} | ||
}); | ||
_vue.watch.call(void 0, ext.error, (newError) => { | ||
if (!router[PENDING_LOCATION_KEY]) { | ||
error.value = newError; | ||
} | ||
}); | ||
const useDataLoaderResult = { | ||
data, | ||
error, | ||
isLoading, | ||
reload: (to = router.currentRoute.value) => router[APP_KEY].runWithContext( | ||
() => load(to, router, void 0, true) | ||
).then(() => entry.commit(to)), | ||
// pinia colada | ||
refetch: (to = router.currentRoute.value) => router[APP_KEY].runWithContext( | ||
() => load(to, router, void 0, true) | ||
).then(() => entry.commit(to)), | ||
refresh: (to = router.currentRoute.value) => router[APP_KEY].runWithContext(() => load(to, router)).then( | ||
() => entry.commit(to) | ||
), | ||
isPending: ext.isPending, | ||
status: ext.status | ||
}; | ||
const promise = entry.pendingLoad.then(() => { | ||
return entry.staged === STAGED_NO_VALUE ? ext.data.value : entry.staged; | ||
}).catch((e) => parentEntry ? Promise.reject(e) : null); | ||
return assign(promise, useDataLoaderResult); | ||
}; | ||
useDataLoader[IS_USE_DATA_LOADER_KEY] = true; | ||
useDataLoader._ = { | ||
load, | ||
options, | ||
// @ts-expect-error: return type has the generics | ||
getEntry(router) { | ||
return router[LOADER_ENTRIES_KEY].get(loader); | ||
} | ||
}; | ||
return useDataLoader; | ||
} | ||
function hasRouteChanged(to, tracked) { | ||
return !tracked.ready || !isSubsetOf(tracked.params, to.params) || !isSubsetOf(tracked.query, to.query) || tracked.hash.v != null && tracked.hash.v !== to.hash; | ||
} | ||
var DEFAULT_DEFINE_LOADER_OPTIONS2 = { | ||
lazy: false, | ||
server: true, | ||
commit: "after-load" | ||
}; | ||
var keyText = (key) => { | ||
const keys = Array.isArray(key) ? key : [key]; | ||
return keys.map(stringifyFlatObject2); | ||
}; | ||
function stringifyFlatObject2(obj) { | ||
return obj && typeof obj === "object" ? JSON.stringify(obj, Object.keys(obj).sort()) : String(obj); | ||
} | ||
// src/runtime.ts | ||
@@ -1766,11 +279,16 @@ var _definePage = (route) => route; | ||
exports.DataLoaderPlugin = DataLoaderPlugin; exports.NavigationResult = NavigationResult; exports._definePage = _definePage; exports._mergeRouteRecord = _mergeRouteRecord; exports.defineBasicLoader = defineBasicLoader; exports.defineColadaLoader = defineColadaLoader; exports.definePage = definePage; | ||
/*! Bundled license information: | ||
pinia/dist/pinia.mjs: | ||
(*! | ||
* pinia v2.1.7 | ||
* (c) 2023 Eduardo San Martin Morote | ||
* @license MIT | ||
*) | ||
*/ | ||
exports.ABORT_CONTROLLER_KEY = ABORT_CONTROLLER_KEY; exports.APP_KEY = APP_KEY; exports.DataLoaderPlugin = DataLoaderPlugin; exports.IS_SSR_KEY = IS_SSR_KEY; exports.IS_USE_DATA_LOADER_KEY = IS_USE_DATA_LOADER_KEY; exports.LOADER_ENTRIES_KEY = LOADER_ENTRIES_KEY; exports.LOADER_SET_KEY = LOADER_SET_KEY; exports.NAVIGATION_RESULTS_KEY = NAVIGATION_RESULTS_KEY; exports.NavigationResult = NavigationResult; exports.PENDING_LOCATION_KEY = PENDING_LOCATION_KEY; exports.STAGED_NO_VALUE = STAGED_NO_VALUE; exports._definePage = _definePage; exports._mergeRouteRecord = _mergeRouteRecord; exports.assign = assign; exports.currentContext = currentContext; exports.definePage = definePage; exports.getCurrentContext = getCurrentContext; exports.isSubsetOf = isSubsetOf; exports.setCurrentContext = setCurrentContext; exports.trackRoute = trackRoute; exports.withLoaderContext = withLoaderContext; |
@@ -1,8 +0,263 @@ | ||
export { O as Options, T as TreeNode, a as TreeNodeValueParam, b as TreeNodeValueStatic } from './options-Cejcs5IG.js'; | ||
import { _ as _RouteMapGeneric, f as RouteLocationAsString, c as RouteLocationAsRelativeTypedList, e as RouteLocationAsPathTypedList, k as RouteLocationResolvedTypedList, b as RouteLocationAsRelativeTyped, d as RouteLocationAsPathTyped } from './router-BioWx5xN.js'; | ||
export { y as NavigationGuard, N as NavigationGuardReturn, A as NavigationGuardTyped, z as NavigationGuardWithThis, B as NavigationGuardWithThisTyped, C as NavigationHookAfterTyped, s as RouteLocation, t as RouteLocationAsRelativePath, p as RouteLocationNormalized, r as RouteLocationNormalizedLoaded, n as RouteLocationNormalizedLoadedTyped, o as RouteLocationNormalizedLoadedTypedList, l as RouteLocationNormalizedTyped, m as RouteLocationNormalizedTypedList, u as RouteLocationRaw, v as RouteLocationResolved, j as RouteLocationResolvedTyped, h as RouteLocationTyped, i as RouteLocationTypedList, G as RouteNamedMap, w as RouteParams, x as RouteParamsRaw, R as RouteRecordInfo, q as RouteRecordName, E as Router, T as TypesConfig, F as _RouterOptions, D as _RouterTyped } from './router-BioWx5xN.js'; | ||
import { AllowedComponentProps, ComponentCustomProps, VNodeProps, UnwrapRef, VNode, ComputedRef, Ref } from 'vue'; | ||
import { RouterLinkProps, NavigationFailure, RouteLocationRaw } from 'vue-router'; | ||
import { RouteParamsRaw, RouteParams, RouteMeta, RouteLocationNormalized, RouteRecordName, RouteLocationNormalizedLoaded, RouteQueryAndHash, RouteLocationOptions, RouteLocation, NavigationGuardNext, NavigationFailure, Router, RouterOptions, RouteRecordRaw, RouterLinkProps, RouteLocationRaw } from 'vue-router'; | ||
import { L as LiteralStringUnion, _ as _Awaitable } from './options-yBvUhD_i.js'; | ||
export { E as EditableTreeNode, O as Options, T as TreeNode, a as TreeNodeValueParam, b as TreeNodeValueStatic } from './options-yBvUhD_i.js'; | ||
import { ShallowRef, AllowedComponentProps, ComponentCustomProps, VNodeProps, UnwrapRef, VNode, ComputedRef, Ref } from 'vue'; | ||
/** | ||
* Helper type to define a Typed `RouteRecord` | ||
* @see {@link RouteRecord} | ||
*/ | ||
interface RouteRecordInfo<Name extends string = string, Path extends string = string, ParamsRaw extends RouteParamsRaw = RouteParamsRaw, Params extends RouteParams = RouteParams, Meta extends RouteMeta = RouteMeta> { | ||
name: Name; | ||
path: Path; | ||
paramsRaw: ParamsRaw; | ||
params: Params; | ||
meta: Meta; | ||
} | ||
/** | ||
* Generic version of RouteNamedMap. | ||
* @internal | ||
*/ | ||
type _RouteMapGeneric = Record<string, RouteRecordInfo>; | ||
/** | ||
* Allows using types that are generated at build-time. **ONLY FOR INTERNAL USAGE**. | ||
* | ||
* @internal | ||
*/ | ||
interface TypesConfig { | ||
} | ||
/** | ||
* Convenience type to get the typed RouteMap or a generic one if not provided. | ||
*/ | ||
type RouteNamedMap = TypesConfig extends Record<'RouteNamedMap', infer RouteNamedMap> ? RouteNamedMap : Record<string, RouteRecordInfo>; | ||
type _RouteRecordName = keyof RouteNamedMap; | ||
interface RouteLocationNormalizedTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalized { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationNormalizedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationNormalizedLoadedTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalizedLoaded { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationNormalizedLoadedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationAsRelativeTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions { | ||
name?: Name; | ||
params?: RouteMap[Name]['paramsRaw']; | ||
} | ||
type RouteLocationAsRelativeTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationAsPathTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions { | ||
path: LiteralStringUnion<RouteMap[Name]['path']>; | ||
} | ||
type RouteLocationAsPathTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N>; | ||
}; | ||
type RouteLocationAsString<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = LiteralStringUnion<RouteMap[keyof RouteMap]['path'], string>; | ||
interface RouteLocationTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocation { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationResolvedTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocationTyped<RouteMap, Name> { | ||
href: string; | ||
} | ||
type RouteLocationResolvedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = { | ||
[N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N>; | ||
}; | ||
/** | ||
* Type safe versions of types that are exposed by vue-router | ||
*/ | ||
/** | ||
* Type safe version of `RouteLocationNormalized`. Accepts the name of the route as a type parameter. | ||
* @see {@link RouteLocationNormalized} | ||
*/ | ||
type _RouteLocationNormalized<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationNormalizedTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Type safe version of `RouteLocationNormalizedLoaded`. Accepts the name of the route as a type parameter. | ||
* @see {@link RouteLocationNormalizedLoaded} | ||
*/ | ||
type _RouteLocationNormalizedLoaded<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Type safe version of `RouteLocationAsRelative`. Accepts the name of the route as a type parameter. | ||
* @see {@link RouteLocationAsRelative} | ||
*/ | ||
type _RouteLocationAsRelativePath<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationAsRelativeTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`). | ||
* Allows passing the name of the route to be passed as a generic. | ||
* @see {@link Router['resolve']} | ||
*/ | ||
type _RouteLocationResolved<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationResolvedTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic. | ||
* @see {@link RouteLocation} | ||
*/ | ||
type _RouteLocation<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic. | ||
* @see {@link RouteLocationRaw} | ||
*/ | ||
type _RouteLocationRaw<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationAsString<RouteNamedMap> | RouteLocationAsRelativeTypedList<RouteNamedMap>[Name] | RouteLocationAsPathTypedList<RouteNamedMap>[Name]; | ||
/** | ||
* Generate a type safe params for a route location. Requires the name of the route to be passed as a generic. | ||
* @see {@link RouteParams} | ||
*/ | ||
type _RouteParams<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['params']; | ||
/** | ||
* Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic. | ||
* @see {@link RouteParamsRaw} | ||
*/ | ||
type _RouteParamsRaw<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['paramsRaw']; | ||
/** | ||
* Return types for a Navigation Guard. Accepts a type param for the RouteMap. | ||
*/ | ||
type NavigationGuardReturnTyped<RouteMap extends _RouteMapGeneric> = void | Error | boolean | RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]; | ||
/** | ||
* Return types for a Navigation Guard. Based on `TypesConfig` | ||
* | ||
* @see {@link TypesConfig} | ||
* @see {@link NavigationGuardReturnTyped} | ||
*/ | ||
type NavigationGuardReturn = NavigationGuardReturnTyped<RouteNamedMap>; | ||
/** | ||
* Typed Navigation Guard with a type parameter for `this` and another for the route map. | ||
*/ | ||
interface NavigationGuardWithThisTyped<T, RouteMap extends _RouteMapGeneric> { | ||
(this: T, to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): _Awaitable<NavigationGuardReturnTyped<RouteMap>>; | ||
} | ||
/** | ||
* Typed Navigation Guard with a type parameter for `this`. Based on `TypesConfig` | ||
* @see {@link TypesConfig} | ||
* @see {@link NavigationGuardWithThisTyped} | ||
*/ | ||
interface NavigationGuardWithThis<T> extends NavigationGuardWithThisTyped<T, RouteNamedMap> { | ||
} | ||
/** | ||
* Typed Navigation Guard. Accepts a type param for the RouteMap. | ||
*/ | ||
interface NavigationGuardTyped<RouteMap extends _RouteMapGeneric> { | ||
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): _Awaitable<NavigationGuardReturnTyped<RouteMap>>; | ||
} | ||
/** | ||
* Typed Navigation Guard. Based on `TypesConfig`. | ||
* @see {@link TypesConfig} | ||
* @see {@link NavigationGuardWithThisTyped} | ||
*/ | ||
interface NavigationGuard extends NavigationGuardTyped<RouteNamedMap> { | ||
} | ||
/** | ||
* Typed Navigation Hook After. Accepts a type param for the RouteMap. | ||
*/ | ||
interface NavigationHookAfterTyped<RouteMap extends _RouteMapGeneric> { | ||
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], failure?: NavigationFailure | void): unknown; | ||
} | ||
/** | ||
* NOTE: Ideally, these should be moved to vue-router in the future to enable typed routes in the core. What's left to | ||
* confirm is if the strategy relying on a `TypesConfig` is the future proof. Moving this to vue-router would also | ||
* remove the double documentation. | ||
*/ | ||
interface _RouterTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> extends Omit<Router, 'resolve' | 'push' | 'replace' | 'beforeEach' | 'beforeResolve' | 'afterEach' | 'currentRoute'> { | ||
/** | ||
* Current {@link RouteLocationNormalized}. Prefer using `useRoute()` instead. | ||
*/ | ||
currentRoute: ShallowRef<RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap]>; | ||
/** | ||
* Programmatically navigate to a new URL by pushing an entry in the history | ||
* stack. | ||
* | ||
* @param to - Route location to navigate to | ||
*/ | ||
push(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]): ReturnType<Router['push']>; | ||
/** | ||
* Programmatically navigate to a new URL by replacing the current entry in | ||
* the history stack. Equivalent to `router.push({ replace: true })`. | ||
* | ||
* @param to - Route location to navigate to | ||
*/ | ||
replace(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]): ReturnType<Router['replace']>; | ||
/** | ||
* Returns the {@link RouteLocation | normalized version} of a | ||
* {@link RouteLocationRaw | route location}. Also includes an `href` property | ||
* that includes any existing `base`. By default, the `currentLocation` used is | ||
* `router.currentRoute` and should only be overridden in advanced use cases. | ||
* | ||
* @param to - Raw route location to resolve | ||
* @param currentLocation - Optional current location to resolve against | ||
*/ | ||
resolve<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name>, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolvedTypedList<RouteMap>[Name]; | ||
/** | ||
* Add a navigation guard that executes before any navigation. Returns a | ||
* function that removes the registered guard. | ||
* | ||
* @param guard - navigation guard to add | ||
*/ | ||
beforeEach(guard: NavigationGuardWithThisTyped<undefined, RouteMap>): ReturnType<Router['beforeEach']>; | ||
/** | ||
* Add a navigation guard that executes before navigation is about to be | ||
* resolved. At this state all component have been fetched and other | ||
* navigation guards have been successful. Returns a function that removes the | ||
* registered guard. | ||
* | ||
* @param guard - navigation guard to add | ||
* @returns a function that removes the registered guard | ||
* | ||
* @example | ||
* ```js | ||
* router.beforeResolve(to => { | ||
* if (to.meta.requiresAuth && !isAuthenticated) return false | ||
* }) | ||
* ``` | ||
* | ||
*/ | ||
beforeResolve(guard: NavigationGuardWithThisTyped<undefined, RouteMap>): ReturnType<Router['beforeResolve']>; | ||
/** | ||
* Add a navigation hook that is executed after every navigation. Returns a | ||
* function that removes the registered hook. | ||
* | ||
* @param guard - navigation hook to add | ||
* @returns a function that removes the registered hook | ||
* | ||
* @example | ||
* ```js | ||
* router.afterEach((to, from, failure) => { | ||
* if (isNavigationFailure(failure)) { | ||
* console.log('failed navigation', failure) | ||
* } | ||
* }) | ||
* ``` | ||
*/ | ||
afterEach(guard: NavigationHookAfterTyped<RouteMap>): ReturnType<Router['beforeEach']>; | ||
} | ||
/** | ||
* Type safe version of `Router`. Used internally by loaders and other methods to provide a typed API without having to pass the RouteNamedMap. | ||
* @see {@link Router} | ||
*/ | ||
type _Router = TypesConfig extends Record<'RouteNamedMap', any> ? _RouterTyped<RouteNamedMap> : Router; | ||
/** | ||
* unplugin-vue-router version of `RouterOptions`. | ||
* @see {@link RouterOptions} | ||
*/ | ||
interface _RouterOptions extends Omit<RouterOptions, 'routes'> { | ||
/** | ||
* Modify the routes before they are passed to the router. You can modify the existing array or return a | ||
* new one. | ||
* | ||
* @param routes - The routes generated by this plugin and exposed by `vue-router/auto-routes` | ||
*/ | ||
extendRoutes?: (routes: RouteRecordRaw[]) => RouteRecordRaw[] | void; | ||
} | ||
/** | ||
* Typed version of `RouterLinkProps`. | ||
@@ -69,2 +324,2 @@ */ | ||
export { type ParamValue, type ParamValueOneOrMore, type ParamValueZeroOrMore, type ParamValueZeroOrOne, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationResolvedTypedList, type RouterLinkPropsTyped, type RouterLinkTyped, type UseLinkFnTyped, _RouteMapGeneric, type _UseLinkReturnTyped }; | ||
export type { NavigationGuard, NavigationGuardReturn, NavigationGuardTyped, NavigationGuardWithThis, NavigationGuardWithThisTyped, NavigationHookAfterTyped, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, _RouteLocation as RouteLocation, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, _RouteLocationAsRelativePath as RouteLocationAsRelativePath, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, _RouteLocationNormalized as RouteLocationNormalized, _RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, _RouteLocationRaw as RouteLocationRaw, _RouteLocationResolved as RouteLocationResolved, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteNamedMap, _RouteParams as RouteParams, _RouteParamsRaw as RouteParamsRaw, RouteRecordInfo, _RouteRecordName as RouteRecordName, _Router as Router, RouterLinkPropsTyped, RouterLinkTyped, TypesConfig, UseLinkFnTyped, _RouteMapGeneric, _RouterOptions, _RouterTyped, _UseLinkReturnTyped }; |
import * as vite from 'vite'; | ||
import { O as Options } from './options-Cejcs5IG.js'; | ||
import { O as Options } from './options-yBvUhD_i.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkPWIYU44Wjs = require('./chunk-PWIYU44W.js'); | ||
var _chunkRQCPCTLSjs = require('./chunk-RQCPCTLS.js'); | ||
require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
require('./chunk-6F4PWJZI.js'); | ||
// src/vite.ts | ||
var vite_default = _chunkPWIYU44Wjs.src_default.vite; | ||
var vite_default = _chunkRQCPCTLSjs.src_default.vite; | ||
@@ -11,0 +10,0 @@ |
import * as webpack from 'webpack'; | ||
import { O as Options } from './options-Cejcs5IG.js'; | ||
import { O as Options } from './options-yBvUhD_i.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkPWIYU44Wjs = require('./chunk-PWIYU44W.js'); | ||
var _chunkRQCPCTLSjs = require('./chunk-RQCPCTLS.js'); | ||
require('./chunk-XHAGIRME.js'); | ||
require('./chunk-M6BUQN66.js'); | ||
require('./chunk-6F4PWJZI.js'); | ||
// src/webpack.ts | ||
var webpack_default = _chunkPWIYU44Wjs.src_default.webpack; | ||
var webpack_default = _chunkRQCPCTLSjs.src_default.webpack; | ||
@@ -11,0 +10,0 @@ |
{ | ||
"name": "unplugin-vue-router", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"packageManager": "pnpm@8.15.3", | ||
@@ -95,2 +95,18 @@ "description": "File based typed routing for Vue Router", | ||
}, | ||
"./data-loaders/basic": { | ||
"types": { | ||
"require": "./dist/data-loaders/basic.d.ts", | ||
"import": "./dist/data-loaders/basic.d.mts" | ||
}, | ||
"require": "./dist/data-loaders/basic.js", | ||
"import": "./dist/data-loaders/basic.mjs" | ||
}, | ||
"./data-loaders/pinia-colada": { | ||
"types": { | ||
"require": "./dist/data-loaders/pinia-colada.d.ts", | ||
"import": "./dist/data-loaders/pinia-colada.d.mts" | ||
}, | ||
"require": "./dist/data-loaders/pinia-colada.js", | ||
"import": "./dist/data-loaders/pinia-colada.mjs" | ||
}, | ||
"./client": { | ||
@@ -190,7 +206,9 @@ "types": "./client.d.ts" | ||
"yorkie": "^2.0.0", | ||
"unplugin-vue-router": "0.8.3" | ||
"unplugin-vue-router": "0.8.4" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch src", | ||
"build": "pnpm run build:core && pnpm run build:runtime", | ||
"build:core": "tsup", | ||
"build:runtime": "tsup --config tsup-runtime.config.ts", | ||
"dev": "pnpm run test", | ||
"docs": "vitepress dev docs", | ||
@@ -197,0 +215,0 @@ "docs:build": "vitepress build docs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
53
19
309712
6695
1