@vizejs/musea-nuxt 0.463.0 → 0.471.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-imports.d.mts +3 -0
- package/dist/auto-imports.mjs +3 -0
- package/dist/error-k5KbRk2C.mjs +507 -0
- package/dist/index.d.mts +2 -295
- package/dist/index.mjs +10 -519
- package/dist/runtime-DQQ-6lr_.d.mts +297 -0
- package/package.json +5 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as preloadComponents, B as useRequestFetch, C as useSeoMeta, D as definePageMeta, E as defineNuxtRouteMiddleware, F as useAsyncData, H as useRouter, I as useFetch, L as useLazyAsyncData, M as setPageLayout, N as clearNuxtData, O as navigateTo, P as refreshNuxtData, R as useLazyFetch, S as useHeadSafe, T as abortNavigation, V as useRoute, _ as clearError, a as onNuxtReady, b as useError, c as useAppConfig, d as useNuxtApp, f as useRequestEvent, g as useState, h as useRuntimeConfig, i as defineNuxtPlugin, j as preloadRouteComponents, k as prefetchComponents, l as useCookie, m as useRequestURL, n as clearNuxtState, o as reloadNuxtApp, p as useRequestHeaders, r as defineNuxtComponent, s as updateAppConfig, t as callOnce, u as useId, v as createError, w as useServerSeoMeta, x as useHead, y as showError, z as useNuxtData } from "./runtime-DQQ-6lr_.mjs";
|
|
2
|
+
import { computed, customRef, defineAsyncComponent, defineComponent, effectScope, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, markRaw, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onScopeDispose, onUnmounted, onUpdated, provide, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, toValue, triggerRef, unref, useAttrs, useSlots, watch, watchEffect } from "vue";
|
|
3
|
+
export { abortNavigation, callOnce, clearError, clearNuxtData, clearNuxtState, computed, createError, customRef, defineAsyncComponent, defineComponent, defineNuxtComponent, defineNuxtPlugin, defineNuxtRouteMiddleware, definePageMeta, effectScope, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, markRaw, navigateTo, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onNuxtReady, onScopeDispose, onUnmounted, onUpdated, prefetchComponents, preloadComponents, preloadRouteComponents, provide, reactive, readonly, ref, refreshNuxtData, reloadNuxtApp, setPageLayout, shallowReactive, shallowReadonly, shallowRef, showError, toRaw, toRef, toRefs, toValue, triggerRef, unref, updateAppConfig, useAppConfig, useAsyncData, useAttrs, useCookie, useError, useFetch, useHead, useHeadSafe, useId, useLazyAsyncData, useLazyFetch, useNuxtApp, useNuxtData, useRequestEvent, useRequestFetch, useRequestHeaders, useRequestURL, useRoute, useRouter, useRuntimeConfig, useSeoMeta, useServerSeoMeta, useSlots, useState, watch, watchEffect };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as useRequestURL, B as preloadComponents, C as updateAppConfig, D as useNuxtApp, E as useId, F as abortNavigation, H as setPageLayout, I as defineNuxtRouteMiddleware, L as definePageMeta, M as useState, N as useRoute, O as useRequestEvent, P as useRouter, R as navigateTo, S as reloadNuxtApp, T as useCookie, V as preloadRouteComponents, _ as callOnce, a as useHead, b as defineNuxtPlugin, c as useServerSeoMeta, d as useAsyncData, f as useFetch, g as useRequestFetch, h as useNuxtData, i as useError, j as useRuntimeConfig, k as useRequestHeaders, l as clearNuxtData, m as useLazyFetch, n as createError, o as useHeadSafe, p as useLazyAsyncData, r as showError, s as useSeoMeta, t as clearError, u as refreshNuxtData, v as clearNuxtState, w as useAppConfig, x as onNuxtReady, y as defineNuxtComponent, z as prefetchComponents } from "./error-k5KbRk2C.mjs";
|
|
2
|
+
import { computed, customRef, defineAsyncComponent, defineComponent, effectScope, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, markRaw, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onScopeDispose, onUnmounted, onUpdated, provide, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, toValue, triggerRef, unref, useAttrs, useSlots, watch, watchEffect } from "vue";
|
|
3
|
+
export { abortNavigation, callOnce, clearError, clearNuxtData, clearNuxtState, computed, createError, customRef, defineAsyncComponent, defineComponent, defineNuxtComponent, defineNuxtPlugin, defineNuxtRouteMiddleware, definePageMeta, effectScope, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, markRaw, navigateTo, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onNuxtReady, onScopeDispose, onUnmounted, onUpdated, prefetchComponents, preloadComponents, preloadRouteComponents, provide, reactive, readonly, ref, refreshNuxtData, reloadNuxtApp, setPageLayout, shallowReactive, shallowReadonly, shallowRef, showError, toRaw, toRef, toRefs, toValue, triggerRef, unref, updateAppConfig, useAppConfig, useAsyncData, useAttrs, useCookie, useError, useFetch, useHead, useHeadSafe, useId, useLazyAsyncData, useLazyFetch, useNuxtApp, useNuxtData, useRequestEvent, useRequestFetch, useRequestHeaders, useRequestURL, useRoute, useRouter, useRuntimeConfig, useSeoMeta, useServerSeoMeta, useSlots, useState, watch, watchEffect };
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { computed, reactive, ref, toValue } from "vue";
|
|
2
|
+
//#region src/context.ts
|
|
3
|
+
const DEFAULT_REQUEST_URL = "http://localhost:3000/";
|
|
4
|
+
const routeState = reactive(createRoute({}));
|
|
5
|
+
const runtimeConfigState = reactive({ public: {} });
|
|
6
|
+
const appConfigState = reactive({});
|
|
7
|
+
const requestState = reactive({
|
|
8
|
+
url: DEFAULT_REQUEST_URL,
|
|
9
|
+
headers: {}
|
|
10
|
+
});
|
|
11
|
+
const stateRefs = /* @__PURE__ */ new Map();
|
|
12
|
+
const cookieRefs = /* @__PURE__ */ new Map();
|
|
13
|
+
const callOnceKeys = /* @__PURE__ */ new Set();
|
|
14
|
+
const fetchMocksState = {};
|
|
15
|
+
const errorRef = ref(null);
|
|
16
|
+
let idCounter = 0;
|
|
17
|
+
function configureNuxtMuseaMocks(options = {}) {
|
|
18
|
+
setRouteConfig(options.route ?? {});
|
|
19
|
+
setRuntimeConfig(options.runtimeConfig ?? {});
|
|
20
|
+
setAppConfig(options.appConfig ?? {});
|
|
21
|
+
setFetchMocks(options.fetchMocks ?? {});
|
|
22
|
+
setStateMocks(options.stateMocks ?? {});
|
|
23
|
+
setCookieMocks(options.cookieMocks ?? {});
|
|
24
|
+
setRequestConfig(options.request ?? {});
|
|
25
|
+
}
|
|
26
|
+
function resetNuxtMuseaMocks() {
|
|
27
|
+
setRouteConfig({});
|
|
28
|
+
setRuntimeConfig({});
|
|
29
|
+
setAppConfig({});
|
|
30
|
+
setFetchMocks({});
|
|
31
|
+
setRequestConfig({});
|
|
32
|
+
stateRefs.clear();
|
|
33
|
+
cookieRefs.clear();
|
|
34
|
+
callOnceKeys.clear();
|
|
35
|
+
errorRef.value = null;
|
|
36
|
+
idCounter = 0;
|
|
37
|
+
}
|
|
38
|
+
function getRouteState() {
|
|
39
|
+
return routeState;
|
|
40
|
+
}
|
|
41
|
+
function setRouteConfig(config) {
|
|
42
|
+
Object.assign(routeState, createRoute(config));
|
|
43
|
+
}
|
|
44
|
+
function resolveNavigationTarget(target) {
|
|
45
|
+
if (typeof target === "string") return createRoute({ path: target });
|
|
46
|
+
return createRoute({
|
|
47
|
+
path: target.path,
|
|
48
|
+
name: target.name ?? null,
|
|
49
|
+
params: target.params,
|
|
50
|
+
query: target.query,
|
|
51
|
+
hash: target.hash,
|
|
52
|
+
meta: typeof target.meta === "object" && target.meta != null ? target.meta : void 0
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function getRuntimeConfigState() {
|
|
56
|
+
return runtimeConfigState;
|
|
57
|
+
}
|
|
58
|
+
function setRuntimeConfig(config) {
|
|
59
|
+
replaceRecord(runtimeConfigState, {
|
|
60
|
+
public: {},
|
|
61
|
+
...config
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function getAppConfigState() {
|
|
65
|
+
return appConfigState;
|
|
66
|
+
}
|
|
67
|
+
function setAppConfig(config) {
|
|
68
|
+
replaceRecord(appConfigState, config);
|
|
69
|
+
}
|
|
70
|
+
function updateAppConfigState(config) {
|
|
71
|
+
Object.assign(appConfigState, config);
|
|
72
|
+
}
|
|
73
|
+
function getFetchMocks() {
|
|
74
|
+
return fetchMocksState;
|
|
75
|
+
}
|
|
76
|
+
function setFetchMocks(mocks) {
|
|
77
|
+
replaceRecord(fetchMocksState, mocks);
|
|
78
|
+
}
|
|
79
|
+
function getStateRef(key, init) {
|
|
80
|
+
const existing = stateRefs.get(key);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
const state = ref(init ? init() : void 0);
|
|
83
|
+
stateRefs.set(key, state);
|
|
84
|
+
return state;
|
|
85
|
+
}
|
|
86
|
+
function setStateMocks(mocks) {
|
|
87
|
+
stateRefs.clear();
|
|
88
|
+
for (const [key, value] of Object.entries(mocks)) stateRefs.set(key, ref(value));
|
|
89
|
+
}
|
|
90
|
+
function clearStateRefs(keys) {
|
|
91
|
+
if (keys == null) {
|
|
92
|
+
stateRefs.clear();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
for (const key of Array.isArray(keys) ? keys : [keys]) stateRefs.delete(key);
|
|
96
|
+
}
|
|
97
|
+
function getCookieRef(name, init) {
|
|
98
|
+
const existing = cookieRefs.get(name);
|
|
99
|
+
if (existing) return existing;
|
|
100
|
+
const cookie = ref(init ? init() : void 0);
|
|
101
|
+
cookieRefs.set(name, cookie);
|
|
102
|
+
return cookie;
|
|
103
|
+
}
|
|
104
|
+
function setCookieMocks(mocks) {
|
|
105
|
+
cookieRefs.clear();
|
|
106
|
+
for (const [key, value] of Object.entries(mocks)) cookieRefs.set(key, ref(value));
|
|
107
|
+
}
|
|
108
|
+
function getRequestState() {
|
|
109
|
+
return requestState;
|
|
110
|
+
}
|
|
111
|
+
function setRequestConfig(request) {
|
|
112
|
+
requestState.url = request.url ?? DEFAULT_REQUEST_URL;
|
|
113
|
+
requestState.headers = { ...request.headers };
|
|
114
|
+
}
|
|
115
|
+
function getErrorRef() {
|
|
116
|
+
return errorRef;
|
|
117
|
+
}
|
|
118
|
+
function setError(error) {
|
|
119
|
+
errorRef.value = error;
|
|
120
|
+
}
|
|
121
|
+
function nextNuxtId() {
|
|
122
|
+
idCounter += 1;
|
|
123
|
+
return `musea-nuxt-${idCounter}`;
|
|
124
|
+
}
|
|
125
|
+
async function runCallOnce(key, fn) {
|
|
126
|
+
if (callOnceKeys.has(key)) return;
|
|
127
|
+
callOnceKeys.add(key);
|
|
128
|
+
return await fn();
|
|
129
|
+
}
|
|
130
|
+
function createRoute(config) {
|
|
131
|
+
const path = config.path ?? "/";
|
|
132
|
+
const query = { ...config.query };
|
|
133
|
+
const hash = normalizeHash(config.hash ?? "");
|
|
134
|
+
return {
|
|
135
|
+
path,
|
|
136
|
+
name: config.name ?? inferRouteName(path),
|
|
137
|
+
params: { ...config.params },
|
|
138
|
+
query,
|
|
139
|
+
hash,
|
|
140
|
+
fullPath: config.fullPath ?? buildFullPath(path, query, hash),
|
|
141
|
+
meta: { ...config.meta },
|
|
142
|
+
matched: [...config.matched ?? []],
|
|
143
|
+
redirectedFrom: config.redirectedFrom
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function inferRouteName(path) {
|
|
147
|
+
const normalized = path.replace(/^\/+|\/+$/g, "");
|
|
148
|
+
return normalized.length === 0 ? "index" : normalized.replace(/[^A-Za-z0-9_]+/g, "-");
|
|
149
|
+
}
|
|
150
|
+
function buildFullPath(path, query, hash) {
|
|
151
|
+
const searchParams = new URLSearchParams();
|
|
152
|
+
for (const [key, value] of Object.entries(query)) {
|
|
153
|
+
if (value == null) continue;
|
|
154
|
+
if (Array.isArray(value)) {
|
|
155
|
+
for (const item of value) searchParams.append(key, item);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
searchParams.set(key, value);
|
|
159
|
+
}
|
|
160
|
+
const search = searchParams.toString();
|
|
161
|
+
return `${path}${search ? `?${search}` : ""}${hash}`;
|
|
162
|
+
}
|
|
163
|
+
function normalizeHash(hash) {
|
|
164
|
+
if (!hash) return "";
|
|
165
|
+
return hash.startsWith("#") ? hash : `#${hash}`;
|
|
166
|
+
}
|
|
167
|
+
function replaceRecord(target, value) {
|
|
168
|
+
for (const key of Object.keys(target)) delete target[key];
|
|
169
|
+
Object.assign(target, value);
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/mocks/navigation.ts
|
|
173
|
+
/**
|
|
174
|
+
* Mock Nuxt navigation utilities.
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Mock navigateTo - updates the shared route state in gallery context.
|
|
178
|
+
*/
|
|
179
|
+
function navigateTo(to, _opts) {
|
|
180
|
+
setRouteConfig(resolveNavigationTarget(to));
|
|
181
|
+
return Promise.resolve();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Mock abortNavigation - no-op in gallery context.
|
|
185
|
+
*/
|
|
186
|
+
function abortNavigation(_err) {}
|
|
187
|
+
/**
|
|
188
|
+
* Mock defineNuxtRouteMiddleware - returns the middleware function as-is.
|
|
189
|
+
*/
|
|
190
|
+
function defineNuxtRouteMiddleware(middleware) {
|
|
191
|
+
return middleware;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Mock definePageMeta - page metadata is handled by Nuxt at build time.
|
|
195
|
+
*/
|
|
196
|
+
function definePageMeta(_meta) {}
|
|
197
|
+
/**
|
|
198
|
+
* Mock setPageLayout - no layout switching in isolated previews.
|
|
199
|
+
*/
|
|
200
|
+
function setPageLayout(_layout) {}
|
|
201
|
+
function prefetchComponents(_to) {
|
|
202
|
+
return Promise.resolve();
|
|
203
|
+
}
|
|
204
|
+
function preloadComponents(_to) {
|
|
205
|
+
return Promise.resolve();
|
|
206
|
+
}
|
|
207
|
+
function preloadRouteComponents(_to) {
|
|
208
|
+
return Promise.resolve();
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/mocks/composables.ts
|
|
212
|
+
/**
|
|
213
|
+
* Mock Nuxt routing composables.
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* Mock useRoute - returns a reactive route object.
|
|
217
|
+
*/
|
|
218
|
+
function useRoute() {
|
|
219
|
+
return getRouteState();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Mock useRouter - returns a router-like object with no-op navigation.
|
|
223
|
+
*/
|
|
224
|
+
function useRouter() {
|
|
225
|
+
const navigate = async (to) => {
|
|
226
|
+
setRouteConfig(resolveNavigationTarget(to));
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
push: navigate,
|
|
230
|
+
replace: navigate,
|
|
231
|
+
back: () => {},
|
|
232
|
+
forward: () => {},
|
|
233
|
+
go: (_delta) => {},
|
|
234
|
+
resolve: (to) => ({
|
|
235
|
+
href: resolveNavigationTarget(to).fullPath,
|
|
236
|
+
route: resolveNavigationTarget(to)
|
|
237
|
+
}),
|
|
238
|
+
currentRoute: computed(() => useRoute()),
|
|
239
|
+
addRoute: () => () => {},
|
|
240
|
+
removeRoute: () => {},
|
|
241
|
+
hasRoute: () => false,
|
|
242
|
+
getRoutes: () => [],
|
|
243
|
+
beforeEach: () => () => {},
|
|
244
|
+
afterEach: () => () => {},
|
|
245
|
+
onError: () => () => {},
|
|
246
|
+
isReady: () => Promise.resolve(),
|
|
247
|
+
options: {}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/mocks/runtime.ts
|
|
252
|
+
/**
|
|
253
|
+
* Mock Nuxt runtime composables.
|
|
254
|
+
*/
|
|
255
|
+
/**
|
|
256
|
+
* Mock useNuxtApp - returns a minimal Nuxt app-like object.
|
|
257
|
+
*/
|
|
258
|
+
function useNuxtApp() {
|
|
259
|
+
return {
|
|
260
|
+
$config: useRuntimeConfig(),
|
|
261
|
+
$router: useRouter(),
|
|
262
|
+
$route: useRoute(),
|
|
263
|
+
provide: (_name, _value) => {},
|
|
264
|
+
hook: (_name, _fn) => {},
|
|
265
|
+
callHook: async (_name, ..._args) => {},
|
|
266
|
+
vueApp: null,
|
|
267
|
+
payload: reactive({
|
|
268
|
+
data: {},
|
|
269
|
+
state: {}
|
|
270
|
+
}),
|
|
271
|
+
isHydrating: false,
|
|
272
|
+
runWithContext: (fn) => fn()
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Mock useRuntimeConfig - returns the configured runtime config.
|
|
277
|
+
*/
|
|
278
|
+
function useRuntimeConfig() {
|
|
279
|
+
return getRuntimeConfigState();
|
|
280
|
+
}
|
|
281
|
+
function useAppConfig() {
|
|
282
|
+
return getAppConfigState();
|
|
283
|
+
}
|
|
284
|
+
function updateAppConfig(config) {
|
|
285
|
+
updateAppConfigState(config);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Mock useState - returns a ref initialized from mock config or init function.
|
|
289
|
+
*/
|
|
290
|
+
function useState(key, init) {
|
|
291
|
+
return getStateRef(key, init);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Mock useRequestHeaders - returns empty headers in gallery context.
|
|
295
|
+
*/
|
|
296
|
+
function useRequestHeaders(_include) {
|
|
297
|
+
return { ...getRequestState().headers };
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Mock useRequestEvent - returns undefined in gallery context.
|
|
301
|
+
*/
|
|
302
|
+
function useRequestEvent() {}
|
|
303
|
+
/**
|
|
304
|
+
* Mock useRequestURL - returns current window location.
|
|
305
|
+
*/
|
|
306
|
+
function useRequestURL() {
|
|
307
|
+
if (typeof window !== "undefined") return new URL(window.location.href);
|
|
308
|
+
return new URL(getRequestState().url);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Mock useCookie - returns a ref-like cookie mock.
|
|
312
|
+
*/
|
|
313
|
+
function useCookie(name, opts) {
|
|
314
|
+
return getCookieRef(name, opts?.default);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Mock clearNuxtState - no-op.
|
|
318
|
+
*/
|
|
319
|
+
function clearNuxtState(keys) {
|
|
320
|
+
clearStateRefs(keys);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Mock defineNuxtPlugin - returns the plugin function as-is.
|
|
324
|
+
*/
|
|
325
|
+
function defineNuxtPlugin(plugin) {
|
|
326
|
+
return plugin;
|
|
327
|
+
}
|
|
328
|
+
function defineNuxtComponent(component) {
|
|
329
|
+
return component;
|
|
330
|
+
}
|
|
331
|
+
function onNuxtReady(callback) {
|
|
332
|
+
if (typeof queueMicrotask === "function") {
|
|
333
|
+
queueMicrotask(callback);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
Promise.resolve().then(callback);
|
|
337
|
+
}
|
|
338
|
+
function callOnce(keyOrFn, fn) {
|
|
339
|
+
if (typeof keyOrFn === "function") return runCallOnce("__default__", keyOrFn);
|
|
340
|
+
return runCallOnce(keyOrFn, fn ?? (() => void 0));
|
|
341
|
+
}
|
|
342
|
+
function useId() {
|
|
343
|
+
return nextNuxtId();
|
|
344
|
+
}
|
|
345
|
+
function reloadNuxtApp(_options) {
|
|
346
|
+
return Promise.resolve();
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/mocks/data.ts
|
|
350
|
+
/**
|
|
351
|
+
* Mock Nuxt data-fetching composables.
|
|
352
|
+
*/
|
|
353
|
+
function findMockData(key) {
|
|
354
|
+
const fetchMocks = getFetchMocks();
|
|
355
|
+
if (key in fetchMocks) return fetchMocks[key];
|
|
356
|
+
for (const [pattern, data] of Object.entries(fetchMocks)) if (key.includes(pattern)) return data;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Mock useFetch - returns reactive data based on mock config.
|
|
360
|
+
*/
|
|
361
|
+
function useFetch(url, opts) {
|
|
362
|
+
return createAsyncDataResult(stringifyDataKey(toValue(url)), void 0, opts);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Mock useAsyncData - similar to useFetch but with key-based lookup.
|
|
366
|
+
*/
|
|
367
|
+
function useAsyncData(key, handler, opts) {
|
|
368
|
+
return createAsyncDataResult(key, handler, opts);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Mock useLazyFetch - lazy variant of useFetch.
|
|
372
|
+
*/
|
|
373
|
+
function useLazyFetch(url, opts) {
|
|
374
|
+
return useFetch(url, {
|
|
375
|
+
...opts,
|
|
376
|
+
lazy: true
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Mock useLazyAsyncData - lazy variant of useAsyncData.
|
|
381
|
+
*/
|
|
382
|
+
function useLazyAsyncData(key, handler, opts) {
|
|
383
|
+
return useAsyncData(key, handler, {
|
|
384
|
+
...opts,
|
|
385
|
+
lazy: true
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
function refreshNuxtData(_keys) {
|
|
389
|
+
return Promise.resolve();
|
|
390
|
+
}
|
|
391
|
+
function clearNuxtData(_keys) {}
|
|
392
|
+
function useNuxtData(key) {
|
|
393
|
+
return { data: ref(findMockData(key) ?? null) };
|
|
394
|
+
}
|
|
395
|
+
function useRequestFetch() {
|
|
396
|
+
return async (url) => {
|
|
397
|
+
return findMockData(stringifyDataKey(url));
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function createAsyncDataResult(key, handler, opts = {}) {
|
|
401
|
+
const initial = resolveInitialData(key, opts);
|
|
402
|
+
const data = ref(initial);
|
|
403
|
+
const pending = ref(false);
|
|
404
|
+
const error = ref(null);
|
|
405
|
+
const status = ref(initial == null ? "idle" : "success");
|
|
406
|
+
const execute = async () => {
|
|
407
|
+
pending.value = true;
|
|
408
|
+
status.value = "pending";
|
|
409
|
+
error.value = null;
|
|
410
|
+
try {
|
|
411
|
+
const mockData = findMockData(key);
|
|
412
|
+
data.value = applyDataOptions(mockData !== void 0 ? mockData : handler ? await handler() : data.value, opts);
|
|
413
|
+
status.value = "success";
|
|
414
|
+
} catch (caught) {
|
|
415
|
+
error.value = caught instanceof Error ? caught : new Error(String(caught));
|
|
416
|
+
status.value = "error";
|
|
417
|
+
} finally {
|
|
418
|
+
pending.value = false;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
if (opts.immediate !== false && opts.lazy !== true && initial == null && handler) execute();
|
|
422
|
+
return {
|
|
423
|
+
data,
|
|
424
|
+
pending,
|
|
425
|
+
error,
|
|
426
|
+
refresh: execute,
|
|
427
|
+
execute,
|
|
428
|
+
clear: () => {
|
|
429
|
+
data.value = null;
|
|
430
|
+
error.value = null;
|
|
431
|
+
pending.value = false;
|
|
432
|
+
status.value = "idle";
|
|
433
|
+
},
|
|
434
|
+
status
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function resolveInitialData(key, opts) {
|
|
438
|
+
const mockData = findMockData(key);
|
|
439
|
+
if (mockData !== void 0) return applyDataOptions(mockData, opts);
|
|
440
|
+
return opts.default ? opts.default() : null;
|
|
441
|
+
}
|
|
442
|
+
function applyDataOptions(value, opts) {
|
|
443
|
+
const transformed = opts.transform ? opts.transform(value) : value;
|
|
444
|
+
if (!opts.pick || typeof transformed !== "object" || transformed == null) return transformed;
|
|
445
|
+
const picked = {};
|
|
446
|
+
for (const key of opts.pick) picked[key] = transformed[key];
|
|
447
|
+
return picked;
|
|
448
|
+
}
|
|
449
|
+
function stringifyDataKey(value) {
|
|
450
|
+
return typeof value === "string" ? value : value.toString();
|
|
451
|
+
}
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/mocks/head.ts
|
|
454
|
+
function createHeadEntry() {
|
|
455
|
+
return {
|
|
456
|
+
dispose: () => {},
|
|
457
|
+
patch: (_input) => {},
|
|
458
|
+
pause: () => {},
|
|
459
|
+
resume: () => {}
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Mock useHead - no-op.
|
|
464
|
+
*/
|
|
465
|
+
function useHead(_input) {
|
|
466
|
+
return createHeadEntry();
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Mock useSeoMeta - no-op.
|
|
470
|
+
*/
|
|
471
|
+
function useSeoMeta(_input) {
|
|
472
|
+
return createHeadEntry();
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Mock useHeadSafe - no-op.
|
|
476
|
+
*/
|
|
477
|
+
function useHeadSafe(_input) {
|
|
478
|
+
return createHeadEntry();
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Mock useServerSeoMeta - no-op.
|
|
482
|
+
*/
|
|
483
|
+
function useServerSeoMeta(_input) {
|
|
484
|
+
return createHeadEntry();
|
|
485
|
+
}
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/mocks/error.ts
|
|
488
|
+
function createError(input) {
|
|
489
|
+
const message = typeof input === "string" ? input : input.message ?? input.statusMessage ?? "Error";
|
|
490
|
+
const error = new Error(message);
|
|
491
|
+
if (typeof input === "object") Object.assign(error, input);
|
|
492
|
+
return error;
|
|
493
|
+
}
|
|
494
|
+
function showError(input) {
|
|
495
|
+
const error = createError(input);
|
|
496
|
+
setError(error);
|
|
497
|
+
return error;
|
|
498
|
+
}
|
|
499
|
+
function clearError(_options) {
|
|
500
|
+
setError(null);
|
|
501
|
+
return Promise.resolve();
|
|
502
|
+
}
|
|
503
|
+
function useError() {
|
|
504
|
+
return getErrorRef();
|
|
505
|
+
}
|
|
506
|
+
//#endregion
|
|
507
|
+
export { useRequestURL as A, preloadComponents as B, updateAppConfig as C, useNuxtApp as D, useId as E, abortNavigation as F, getRouteState as G, setPageLayout as H, defineNuxtRouteMiddleware as I, resolveNavigationTarget as J, getRuntimeConfigState as K, definePageMeta as L, useState as M, useRoute as N, useRequestEvent as O, useRouter as P, navigateTo as R, reloadNuxtApp as S, useCookie as T, configureNuxtMuseaMocks as U, preloadRouteComponents as V, getAppConfigState as W, callOnce as _, useHead as a, defineNuxtPlugin as b, useServerSeoMeta as c, useAsyncData as d, useFetch as f, useRequestFetch as g, useNuxtData as h, useError as i, useRuntimeConfig as j, useRequestHeaders as k, clearNuxtData as l, useLazyFetch as m, createError as n, useHeadSafe as o, useLazyAsyncData as p, resetNuxtMuseaMocks as q, showError as r, useSeoMeta as s, clearError as t, refreshNuxtData as u, clearNuxtState as v, useAppConfig as w, onNuxtReady as x, defineNuxtComponent as y, prefetchComponents as z };
|