@vizejs/musea-nuxt 0.58.0 → 0.59.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/index.d.mts +392 -0
- package/dist/index.mjs +440 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import * as _$vue from "vue";
|
|
2
|
+
import { Ref, ref } from "vue";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* NuxtMusea plugin options.
|
|
8
|
+
*/
|
|
9
|
+
interface NuxtMuseaOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Mock route data.
|
|
12
|
+
*/
|
|
13
|
+
route?: {
|
|
14
|
+
path?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
params?: Record<string, string>;
|
|
17
|
+
query?: Record<string, string>;
|
|
18
|
+
hash?: string;
|
|
19
|
+
fullPath?: string;
|
|
20
|
+
meta?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Mock runtime config.
|
|
24
|
+
*/
|
|
25
|
+
runtimeConfig?: {
|
|
26
|
+
public?: Record<string, unknown>;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Mock useFetch / useAsyncData default responses.
|
|
31
|
+
* Key is the URL/key pattern, value is the mock response data.
|
|
32
|
+
*/
|
|
33
|
+
fetchMocks?: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Mock useState initial values.
|
|
36
|
+
* Key is the state key, value is the initial state.
|
|
37
|
+
*/
|
|
38
|
+
stateMocks?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/mocks/composables.d.ts
|
|
42
|
+
/**
|
|
43
|
+
* Mock useRoute - returns a reactive route object.
|
|
44
|
+
*/
|
|
45
|
+
declare function useRoute(): {
|
|
46
|
+
path: string;
|
|
47
|
+
name: string;
|
|
48
|
+
params: Record<string, string>;
|
|
49
|
+
query: Record<string, string>;
|
|
50
|
+
hash: string;
|
|
51
|
+
fullPath: string;
|
|
52
|
+
meta: Record<string, unknown>;
|
|
53
|
+
matched: never[];
|
|
54
|
+
redirectedFrom: undefined;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Mock useRouter - returns a router-like object with no-op navigation.
|
|
58
|
+
*/
|
|
59
|
+
declare function useRouter(): {
|
|
60
|
+
push: (_to: unknown) => Promise<void>;
|
|
61
|
+
replace: (_to: unknown) => Promise<void>;
|
|
62
|
+
back: () => void;
|
|
63
|
+
forward: () => void;
|
|
64
|
+
go: (_delta: number) => void;
|
|
65
|
+
resolve: (to: unknown) => {
|
|
66
|
+
href: string;
|
|
67
|
+
route: {
|
|
68
|
+
path: string;
|
|
69
|
+
name: string;
|
|
70
|
+
params: Record<string, string>;
|
|
71
|
+
query: Record<string, string>;
|
|
72
|
+
hash: string;
|
|
73
|
+
fullPath: string;
|
|
74
|
+
meta: Record<string, unknown>;
|
|
75
|
+
matched: never[];
|
|
76
|
+
redirectedFrom: undefined;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
currentRoute: _$vue.ComputedRef<{
|
|
80
|
+
path: string;
|
|
81
|
+
name: string;
|
|
82
|
+
params: Record<string, string>;
|
|
83
|
+
query: Record<string, string>;
|
|
84
|
+
hash: string;
|
|
85
|
+
fullPath: string;
|
|
86
|
+
meta: Record<string, unknown>;
|
|
87
|
+
matched: never[];
|
|
88
|
+
redirectedFrom: undefined;
|
|
89
|
+
}>;
|
|
90
|
+
addRoute: () => () => void;
|
|
91
|
+
removeRoute: () => void;
|
|
92
|
+
hasRoute: () => boolean;
|
|
93
|
+
getRoutes: () => never[];
|
|
94
|
+
beforeEach: () => () => void;
|
|
95
|
+
afterEach: () => () => void;
|
|
96
|
+
onError: () => () => void;
|
|
97
|
+
isReady: () => Promise<void>;
|
|
98
|
+
options: {};
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/mocks/data.d.ts
|
|
102
|
+
interface AsyncDataResult<T> {
|
|
103
|
+
data: ReturnType<typeof ref<T | null>>;
|
|
104
|
+
pending: ReturnType<typeof ref<boolean>>;
|
|
105
|
+
error: ReturnType<typeof ref<Error | null>>;
|
|
106
|
+
refresh: () => Promise<void>;
|
|
107
|
+
execute: () => Promise<void>;
|
|
108
|
+
status: ReturnType<typeof ref<string>>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Mock useFetch - returns reactive data based on mock config.
|
|
112
|
+
*/
|
|
113
|
+
declare function useFetch<T = unknown>(url: string | (() => string), _opts?: Record<string, unknown>): AsyncDataResult<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Mock useAsyncData - similar to useFetch but with key-based lookup.
|
|
116
|
+
*/
|
|
117
|
+
declare function useAsyncData<T = unknown>(key: string, _handler?: () => Promise<T>, _opts?: Record<string, unknown>): AsyncDataResult<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Mock useLazyFetch - lazy variant of useFetch.
|
|
120
|
+
*/
|
|
121
|
+
declare function useLazyFetch<T = unknown>(url: string | (() => string), opts?: Record<string, unknown>): AsyncDataResult<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Mock useLazyAsyncData - lazy variant of useAsyncData.
|
|
124
|
+
*/
|
|
125
|
+
declare function useLazyAsyncData<T = unknown>(key: string, handler?: () => Promise<T>, opts?: Record<string, unknown>): AsyncDataResult<T>;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/mocks/navigation.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Mock Nuxt navigation utilities.
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* Mock navigateTo - no-op in gallery context.
|
|
133
|
+
*/
|
|
134
|
+
declare function navigateTo(_to: string | Record<string, unknown>, _opts?: {
|
|
135
|
+
replace?: boolean;
|
|
136
|
+
redirectCode?: number;
|
|
137
|
+
external?: boolean;
|
|
138
|
+
}): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Mock abortNavigation - no-op in gallery context.
|
|
141
|
+
*/
|
|
142
|
+
declare function abortNavigation(_err?: string | Error): void;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/mocks/head.d.ts
|
|
145
|
+
/**
|
|
146
|
+
* Mock Nuxt head management composables.
|
|
147
|
+
* All are no-ops in the gallery context.
|
|
148
|
+
*/
|
|
149
|
+
/**
|
|
150
|
+
* Mock useHead - no-op.
|
|
151
|
+
*/
|
|
152
|
+
declare function useHead(_input: Record<string, unknown>): void;
|
|
153
|
+
/**
|
|
154
|
+
* Mock useSeoMeta - no-op.
|
|
155
|
+
*/
|
|
156
|
+
declare function useSeoMeta(_input: Record<string, unknown>): void;
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/mocks/runtime.d.ts
|
|
159
|
+
/**
|
|
160
|
+
* Mock useNuxtApp - returns a minimal Nuxt app-like object.
|
|
161
|
+
*/
|
|
162
|
+
declare function useNuxtApp(): {
|
|
163
|
+
$config: {
|
|
164
|
+
public: Record<string, unknown>;
|
|
165
|
+
};
|
|
166
|
+
provide: (_name: string, _value: unknown) => void;
|
|
167
|
+
hook: (_name: string, _fn: (...args: unknown[]) => void) => void;
|
|
168
|
+
callHook: (_name: string, ..._args: unknown[]) => Promise<void>;
|
|
169
|
+
vueApp: null;
|
|
170
|
+
payload: {
|
|
171
|
+
data: {};
|
|
172
|
+
state: {};
|
|
173
|
+
};
|
|
174
|
+
isHydrating: boolean;
|
|
175
|
+
runWithContext: <T>(fn: () => T) => T;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Mock useRuntimeConfig - returns the configured runtime config.
|
|
179
|
+
*/
|
|
180
|
+
declare function useRuntimeConfig(): {
|
|
181
|
+
public: Record<string, unknown>;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Mock useState - returns a ref initialized from mock config or init function.
|
|
185
|
+
*/
|
|
186
|
+
declare function useState<T = unknown>(key: string, init?: () => T): Ref<T | undefined>;
|
|
187
|
+
/**
|
|
188
|
+
* Mock useCookie - returns a ref-like cookie mock.
|
|
189
|
+
*/
|
|
190
|
+
declare function useCookie<T = unknown>(_name: string, _opts?: Record<string, unknown>): Ref<T | undefined>;
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/mocks/components.d.ts
|
|
193
|
+
/**
|
|
194
|
+
* Mock Nuxt built-in components.
|
|
195
|
+
*/
|
|
196
|
+
/**
|
|
197
|
+
* Mock NuxtLink - renders as <RouterLink> or <a>.
|
|
198
|
+
*/
|
|
199
|
+
declare const NuxtLink: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
200
|
+
to: {
|
|
201
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
202
|
+
default: string;
|
|
203
|
+
};
|
|
204
|
+
href: {
|
|
205
|
+
type: StringConstructor;
|
|
206
|
+
default: undefined;
|
|
207
|
+
};
|
|
208
|
+
target: {
|
|
209
|
+
type: StringConstructor;
|
|
210
|
+
default: undefined;
|
|
211
|
+
};
|
|
212
|
+
rel: {
|
|
213
|
+
type: StringConstructor;
|
|
214
|
+
default: undefined;
|
|
215
|
+
};
|
|
216
|
+
external: {
|
|
217
|
+
type: BooleanConstructor;
|
|
218
|
+
default: boolean;
|
|
219
|
+
};
|
|
220
|
+
replace: {
|
|
221
|
+
type: BooleanConstructor;
|
|
222
|
+
default: boolean;
|
|
223
|
+
};
|
|
224
|
+
prefetch: {
|
|
225
|
+
type: BooleanConstructor;
|
|
226
|
+
default: boolean;
|
|
227
|
+
};
|
|
228
|
+
noPrefetch: {
|
|
229
|
+
type: BooleanConstructor;
|
|
230
|
+
default: boolean;
|
|
231
|
+
};
|
|
232
|
+
activeClass: {
|
|
233
|
+
type: StringConstructor;
|
|
234
|
+
default: string;
|
|
235
|
+
};
|
|
236
|
+
exactActiveClass: {
|
|
237
|
+
type: StringConstructor;
|
|
238
|
+
default: string;
|
|
239
|
+
};
|
|
240
|
+
}>, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
241
|
+
[key: string]: any;
|
|
242
|
+
}>, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
243
|
+
to: {
|
|
244
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
245
|
+
default: string;
|
|
246
|
+
};
|
|
247
|
+
href: {
|
|
248
|
+
type: StringConstructor;
|
|
249
|
+
default: undefined;
|
|
250
|
+
};
|
|
251
|
+
target: {
|
|
252
|
+
type: StringConstructor;
|
|
253
|
+
default: undefined;
|
|
254
|
+
};
|
|
255
|
+
rel: {
|
|
256
|
+
type: StringConstructor;
|
|
257
|
+
default: undefined;
|
|
258
|
+
};
|
|
259
|
+
external: {
|
|
260
|
+
type: BooleanConstructor;
|
|
261
|
+
default: boolean;
|
|
262
|
+
};
|
|
263
|
+
replace: {
|
|
264
|
+
type: BooleanConstructor;
|
|
265
|
+
default: boolean;
|
|
266
|
+
};
|
|
267
|
+
prefetch: {
|
|
268
|
+
type: BooleanConstructor;
|
|
269
|
+
default: boolean;
|
|
270
|
+
};
|
|
271
|
+
noPrefetch: {
|
|
272
|
+
type: BooleanConstructor;
|
|
273
|
+
default: boolean;
|
|
274
|
+
};
|
|
275
|
+
activeClass: {
|
|
276
|
+
type: StringConstructor;
|
|
277
|
+
default: string;
|
|
278
|
+
};
|
|
279
|
+
exactActiveClass: {
|
|
280
|
+
type: StringConstructor;
|
|
281
|
+
default: string;
|
|
282
|
+
};
|
|
283
|
+
}>> & Readonly<{}>, {
|
|
284
|
+
to: string | Record<string, any>;
|
|
285
|
+
href: string;
|
|
286
|
+
target: string;
|
|
287
|
+
rel: string;
|
|
288
|
+
external: boolean;
|
|
289
|
+
replace: boolean;
|
|
290
|
+
prefetch: boolean;
|
|
291
|
+
noPrefetch: boolean;
|
|
292
|
+
activeClass: string;
|
|
293
|
+
exactActiveClass: string;
|
|
294
|
+
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
295
|
+
/**
|
|
296
|
+
* Mock NuxtPage - renders <RouterView> or slot content.
|
|
297
|
+
*/
|
|
298
|
+
declare const NuxtPage: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
299
|
+
name: {
|
|
300
|
+
type: StringConstructor;
|
|
301
|
+
default: string;
|
|
302
|
+
};
|
|
303
|
+
transition: {
|
|
304
|
+
type: (ObjectConstructor | BooleanConstructor)[];
|
|
305
|
+
default: undefined;
|
|
306
|
+
};
|
|
307
|
+
keepalive: {
|
|
308
|
+
type: (ObjectConstructor | BooleanConstructor)[];
|
|
309
|
+
default: undefined;
|
|
310
|
+
};
|
|
311
|
+
pageKey: {
|
|
312
|
+
type: (StringConstructor | FunctionConstructor)[];
|
|
313
|
+
default: undefined;
|
|
314
|
+
};
|
|
315
|
+
}>, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
316
|
+
[key: string]: any;
|
|
317
|
+
}> | _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
318
|
+
[key: string]: any;
|
|
319
|
+
}>[], {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
320
|
+
name: {
|
|
321
|
+
type: StringConstructor;
|
|
322
|
+
default: string;
|
|
323
|
+
};
|
|
324
|
+
transition: {
|
|
325
|
+
type: (ObjectConstructor | BooleanConstructor)[];
|
|
326
|
+
default: undefined;
|
|
327
|
+
};
|
|
328
|
+
keepalive: {
|
|
329
|
+
type: (ObjectConstructor | BooleanConstructor)[];
|
|
330
|
+
default: undefined;
|
|
331
|
+
};
|
|
332
|
+
pageKey: {
|
|
333
|
+
type: (StringConstructor | FunctionConstructor)[];
|
|
334
|
+
default: undefined;
|
|
335
|
+
};
|
|
336
|
+
}>> & Readonly<{}>, {
|
|
337
|
+
name: string;
|
|
338
|
+
transition: boolean | Record<string, any>;
|
|
339
|
+
keepalive: boolean | Record<string, any>;
|
|
340
|
+
pageKey: string | Function;
|
|
341
|
+
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
342
|
+
/**
|
|
343
|
+
* Mock ClientOnly - renders default slot on client side (always in browser context).
|
|
344
|
+
*/
|
|
345
|
+
declare const ClientOnly: _$vue.DefineComponent<{}, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
346
|
+
[key: string]: any;
|
|
347
|
+
}>[] | null, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
348
|
+
/**
|
|
349
|
+
* Mock NuxtLayout - renders slot content with optional layout wrapper.
|
|
350
|
+
*/
|
|
351
|
+
declare const NuxtLayout: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
352
|
+
name: {
|
|
353
|
+
type: StringConstructor;
|
|
354
|
+
default: string;
|
|
355
|
+
};
|
|
356
|
+
fallback: {
|
|
357
|
+
type: StringConstructor;
|
|
358
|
+
default: undefined;
|
|
359
|
+
};
|
|
360
|
+
}>, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
361
|
+
[key: string]: any;
|
|
362
|
+
}>[] | null, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
363
|
+
name: {
|
|
364
|
+
type: StringConstructor;
|
|
365
|
+
default: string;
|
|
366
|
+
};
|
|
367
|
+
fallback: {
|
|
368
|
+
type: StringConstructor;
|
|
369
|
+
default: undefined;
|
|
370
|
+
};
|
|
371
|
+
}>> & Readonly<{}>, {
|
|
372
|
+
name: string;
|
|
373
|
+
fallback: string;
|
|
374
|
+
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
375
|
+
/**
|
|
376
|
+
* Mock NuxtLoadingIndicator - renders nothing.
|
|
377
|
+
*/
|
|
378
|
+
declare const NuxtLoadingIndicator: _$vue.DefineComponent<{}, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
379
|
+
/**
|
|
380
|
+
* Mock NuxtErrorBoundary - renders default slot.
|
|
381
|
+
*/
|
|
382
|
+
declare const NuxtErrorBoundary: _$vue.DefineComponent<{}, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
383
|
+
[key: string]: any;
|
|
384
|
+
}>[] | null, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/index.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Create Nuxt mock Vite plugin for Musea.
|
|
389
|
+
*/
|
|
390
|
+
declare function nuxtMusea(options?: NuxtMuseaOptions): Plugin;
|
|
391
|
+
//#endregion
|
|
392
|
+
export { ClientOnly, NuxtErrorBoundary, NuxtLayout, NuxtLink, NuxtLoadingIndicator, type NuxtMuseaOptions, NuxtPage, abortNavigation, navigateTo, nuxtMusea, useAsyncData, useCookie, useFetch, useHead, useLazyAsyncData, useLazyFetch, useNuxtApp, useRoute, useRouter, useRuntimeConfig, useSeoMeta, useState };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { computed, defineComponent, h, reactive, ref } from "vue";
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/plugin.ts
|
|
9
|
+
const VIRTUAL_IMPORTS_ID = "\0musea-nuxt:imports";
|
|
10
|
+
const VIRTUAL_IMPORTS_MODULE = "#imports";
|
|
11
|
+
const VIRTUAL_NUXT_COMPONENTS_ID = "\0musea-nuxt:components";
|
|
12
|
+
function createNuxtMuseaPlugin(options = {}) {
|
|
13
|
+
const srcDir = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
return {
|
|
15
|
+
name: "vite-plugin-musea-nuxt",
|
|
16
|
+
enforce: "pre",
|
|
17
|
+
config() {
|
|
18
|
+
return { resolve: { alias: {
|
|
19
|
+
"#imports": VIRTUAL_IMPORTS_MODULE,
|
|
20
|
+
"#app": VIRTUAL_IMPORTS_MODULE,
|
|
21
|
+
"#build": VIRTUAL_IMPORTS_MODULE
|
|
22
|
+
} } };
|
|
23
|
+
},
|
|
24
|
+
resolveId(id) {
|
|
25
|
+
if (id === VIRTUAL_IMPORTS_MODULE || id === "#imports" || id === "#app" || id === "#build") return VIRTUAL_IMPORTS_ID;
|
|
26
|
+
if (id === "#components" || id === "nuxt/dist/app/components") return VIRTUAL_NUXT_COMPONENTS_ID;
|
|
27
|
+
return null;
|
|
28
|
+
},
|
|
29
|
+
load(id) {
|
|
30
|
+
if (id === VIRTUAL_IMPORTS_ID) return generateImportsModule(srcDir, options);
|
|
31
|
+
if (id === VIRTUAL_NUXT_COMPONENTS_ID) return generateComponentsModule(srcDir);
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
transform(code, id) {
|
|
35
|
+
if (id.endsWith(".vue") || id.endsWith(".art.vue")) {
|
|
36
|
+
if (code.includes("<NuxtLink") || code.includes("<nuxt-link")) {
|
|
37
|
+
if (!code.includes("NuxtLink")) {
|
|
38
|
+
const importLine = `import { NuxtLink } from '${VIRTUAL_IMPORTS_MODULE}';\n`;
|
|
39
|
+
const lastImportIdx = code.lastIndexOf("import ");
|
|
40
|
+
if (lastImportIdx !== -1) {
|
|
41
|
+
const lineEnd = code.indexOf("\n", lastImportIdx);
|
|
42
|
+
code = code.slice(0, lineEnd + 1) + importLine + code.slice(lineEnd + 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return code;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function generateImportsModule(srcDir, options) {
|
|
52
|
+
const autoImportsPath = path.join(srcDir, "auto-imports.js").replace(/\\/g, "/");
|
|
53
|
+
const configJson = JSON.stringify(options);
|
|
54
|
+
return `
|
|
55
|
+
// Auto-generated by @vizejs/musea-nuxt
|
|
56
|
+
export * from '${autoImportsPath}';
|
|
57
|
+
|
|
58
|
+
// Configure mocks with provided options
|
|
59
|
+
import { _setRouteConfig } from '${path.join(srcDir, "mocks", "composables.js").replace(/\\/g, "/")}';
|
|
60
|
+
import { _setFetchMocks } from '${path.join(srcDir, "mocks", "data.js").replace(/\\/g, "/")}';
|
|
61
|
+
import { _setRuntimeConfig, _setStateMocks } from '${path.join(srcDir, "mocks", "runtime.js").replace(/\\/g, "/")}';
|
|
62
|
+
|
|
63
|
+
const _config = ${configJson};
|
|
64
|
+
_setRouteConfig(_config.route);
|
|
65
|
+
_setFetchMocks(_config.fetchMocks ?? {});
|
|
66
|
+
_setRuntimeConfig(_config.runtimeConfig);
|
|
67
|
+
_setStateMocks(_config.stateMocks ?? {});
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
function generateComponentsModule(srcDir) {
|
|
71
|
+
return `
|
|
72
|
+
// Auto-generated by @vizejs/musea-nuxt
|
|
73
|
+
export {
|
|
74
|
+
NuxtLink,
|
|
75
|
+
NuxtPage,
|
|
76
|
+
ClientOnly,
|
|
77
|
+
NuxtLayout,
|
|
78
|
+
NuxtLoadingIndicator,
|
|
79
|
+
NuxtErrorBoundary,
|
|
80
|
+
} from '${path.join(srcDir, "mocks", "components.js").replace(/\\/g, "/")}';
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/mocks/composables.ts
|
|
85
|
+
/**
|
|
86
|
+
* Mock Nuxt routing composables.
|
|
87
|
+
*/
|
|
88
|
+
let _routeConfig = {};
|
|
89
|
+
/**
|
|
90
|
+
* Mock useRoute - returns a reactive route object.
|
|
91
|
+
*/
|
|
92
|
+
function useRoute() {
|
|
93
|
+
return reactive({
|
|
94
|
+
path: _routeConfig?.path ?? "/",
|
|
95
|
+
name: _routeConfig?.name ?? "index",
|
|
96
|
+
params: _routeConfig?.params ?? {},
|
|
97
|
+
query: _routeConfig?.query ?? {},
|
|
98
|
+
hash: _routeConfig?.hash ?? "",
|
|
99
|
+
fullPath: _routeConfig?.fullPath ?? _routeConfig?.path ?? "/",
|
|
100
|
+
meta: _routeConfig?.meta ?? {},
|
|
101
|
+
matched: [],
|
|
102
|
+
redirectedFrom: void 0
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Mock useRouter - returns a router-like object with no-op navigation.
|
|
107
|
+
*/
|
|
108
|
+
function useRouter() {
|
|
109
|
+
return {
|
|
110
|
+
push: async (_to) => {},
|
|
111
|
+
replace: async (_to) => {},
|
|
112
|
+
back: () => {},
|
|
113
|
+
forward: () => {},
|
|
114
|
+
go: (_delta) => {},
|
|
115
|
+
resolve: (to) => ({
|
|
116
|
+
href: typeof to === "string" ? to : "/",
|
|
117
|
+
route: useRoute()
|
|
118
|
+
}),
|
|
119
|
+
currentRoute: computed(() => useRoute()),
|
|
120
|
+
addRoute: () => () => {},
|
|
121
|
+
removeRoute: () => {},
|
|
122
|
+
hasRoute: () => false,
|
|
123
|
+
getRoutes: () => [],
|
|
124
|
+
beforeEach: () => () => {},
|
|
125
|
+
afterEach: () => () => {},
|
|
126
|
+
onError: () => () => {},
|
|
127
|
+
isReady: () => Promise.resolve(),
|
|
128
|
+
options: {}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/mocks/data.ts
|
|
133
|
+
/**
|
|
134
|
+
* Mock Nuxt data-fetching composables.
|
|
135
|
+
*/
|
|
136
|
+
let _fetchMocks = {};
|
|
137
|
+
function findMockData(key) {
|
|
138
|
+
if (key in _fetchMocks) return _fetchMocks[key];
|
|
139
|
+
for (const [pattern, data] of Object.entries(_fetchMocks)) if (key.includes(pattern)) return data;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Mock useFetch - returns reactive data based on mock config.
|
|
143
|
+
*/
|
|
144
|
+
function useFetch(url, _opts) {
|
|
145
|
+
const data = ref(findMockData(typeof url === "function" ? url() : url) ?? null);
|
|
146
|
+
const pending = ref(false);
|
|
147
|
+
const error = ref(null);
|
|
148
|
+
const status = ref("success");
|
|
149
|
+
const refresh = async () => {};
|
|
150
|
+
const execute = async () => {};
|
|
151
|
+
return {
|
|
152
|
+
data,
|
|
153
|
+
pending,
|
|
154
|
+
error,
|
|
155
|
+
refresh,
|
|
156
|
+
execute,
|
|
157
|
+
status
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Mock useAsyncData - similar to useFetch but with key-based lookup.
|
|
162
|
+
*/
|
|
163
|
+
function useAsyncData(key, _handler, _opts) {
|
|
164
|
+
const data = ref(findMockData(key) ?? null);
|
|
165
|
+
const pending = ref(false);
|
|
166
|
+
const error = ref(null);
|
|
167
|
+
const status = ref("success");
|
|
168
|
+
const refresh = async () => {};
|
|
169
|
+
const execute = async () => {};
|
|
170
|
+
return {
|
|
171
|
+
data,
|
|
172
|
+
pending,
|
|
173
|
+
error,
|
|
174
|
+
refresh,
|
|
175
|
+
execute,
|
|
176
|
+
status
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Mock useLazyFetch - lazy variant of useFetch.
|
|
181
|
+
*/
|
|
182
|
+
function useLazyFetch(url, opts) {
|
|
183
|
+
return useFetch(url, {
|
|
184
|
+
...opts,
|
|
185
|
+
lazy: true
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Mock useLazyAsyncData - lazy variant of useAsyncData.
|
|
190
|
+
*/
|
|
191
|
+
function useLazyAsyncData(key, handler, opts) {
|
|
192
|
+
return useAsyncData(key, handler, {
|
|
193
|
+
...opts,
|
|
194
|
+
lazy: true
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/mocks/navigation.ts
|
|
199
|
+
/**
|
|
200
|
+
* Mock Nuxt navigation utilities.
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Mock navigateTo - no-op in gallery context.
|
|
204
|
+
*/
|
|
205
|
+
function navigateTo(_to, _opts) {
|
|
206
|
+
return Promise.resolve();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Mock abortNavigation - no-op in gallery context.
|
|
210
|
+
*/
|
|
211
|
+
function abortNavigation(_err) {}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/mocks/head.ts
|
|
214
|
+
/**
|
|
215
|
+
* Mock Nuxt head management composables.
|
|
216
|
+
* All are no-ops in the gallery context.
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* Mock useHead - no-op.
|
|
220
|
+
*/
|
|
221
|
+
function useHead(_input) {}
|
|
222
|
+
/**
|
|
223
|
+
* Mock useSeoMeta - no-op.
|
|
224
|
+
*/
|
|
225
|
+
function useSeoMeta(_input) {}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/mocks/runtime.ts
|
|
228
|
+
/**
|
|
229
|
+
* Mock Nuxt runtime composables.
|
|
230
|
+
*/
|
|
231
|
+
let _runtimeConfig = {};
|
|
232
|
+
let _stateMocks = {};
|
|
233
|
+
/**
|
|
234
|
+
* Mock useNuxtApp - returns a minimal Nuxt app-like object.
|
|
235
|
+
*/
|
|
236
|
+
function useNuxtApp() {
|
|
237
|
+
return {
|
|
238
|
+
$config: reactive({
|
|
239
|
+
public: _runtimeConfig?.public ?? {},
|
|
240
|
+
..._runtimeConfig
|
|
241
|
+
}),
|
|
242
|
+
provide: (_name, _value) => {},
|
|
243
|
+
hook: (_name, _fn) => {},
|
|
244
|
+
callHook: async (_name, ..._args) => {},
|
|
245
|
+
vueApp: null,
|
|
246
|
+
payload: reactive({
|
|
247
|
+
data: {},
|
|
248
|
+
state: {}
|
|
249
|
+
}),
|
|
250
|
+
isHydrating: false,
|
|
251
|
+
runWithContext: (fn) => fn()
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Mock useRuntimeConfig - returns the configured runtime config.
|
|
256
|
+
*/
|
|
257
|
+
function useRuntimeConfig() {
|
|
258
|
+
return reactive({
|
|
259
|
+
public: _runtimeConfig?.public ?? {},
|
|
260
|
+
..._runtimeConfig
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Mock useState - returns a ref initialized from mock config or init function.
|
|
265
|
+
*/
|
|
266
|
+
function useState(key, init) {
|
|
267
|
+
if (key in _stateMocks) return ref(_stateMocks[key]);
|
|
268
|
+
return ref(init ? init() : void 0);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Mock useCookie - returns a ref-like cookie mock.
|
|
272
|
+
*/
|
|
273
|
+
function useCookie(_name, _opts) {
|
|
274
|
+
return ref(void 0);
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/mocks/components.ts
|
|
278
|
+
/**
|
|
279
|
+
* Mock Nuxt built-in components.
|
|
280
|
+
*/
|
|
281
|
+
/**
|
|
282
|
+
* Mock NuxtLink - renders as <RouterLink> or <a>.
|
|
283
|
+
*/
|
|
284
|
+
const NuxtLink = defineComponent({
|
|
285
|
+
name: "NuxtLink",
|
|
286
|
+
props: {
|
|
287
|
+
to: {
|
|
288
|
+
type: [String, Object],
|
|
289
|
+
default: "/"
|
|
290
|
+
},
|
|
291
|
+
href: {
|
|
292
|
+
type: String,
|
|
293
|
+
default: void 0
|
|
294
|
+
},
|
|
295
|
+
target: {
|
|
296
|
+
type: String,
|
|
297
|
+
default: void 0
|
|
298
|
+
},
|
|
299
|
+
rel: {
|
|
300
|
+
type: String,
|
|
301
|
+
default: void 0
|
|
302
|
+
},
|
|
303
|
+
external: {
|
|
304
|
+
type: Boolean,
|
|
305
|
+
default: false
|
|
306
|
+
},
|
|
307
|
+
replace: {
|
|
308
|
+
type: Boolean,
|
|
309
|
+
default: false
|
|
310
|
+
},
|
|
311
|
+
prefetch: {
|
|
312
|
+
type: Boolean,
|
|
313
|
+
default: true
|
|
314
|
+
},
|
|
315
|
+
noPrefetch: {
|
|
316
|
+
type: Boolean,
|
|
317
|
+
default: false
|
|
318
|
+
},
|
|
319
|
+
activeClass: {
|
|
320
|
+
type: String,
|
|
321
|
+
default: "router-link-active"
|
|
322
|
+
},
|
|
323
|
+
exactActiveClass: {
|
|
324
|
+
type: String,
|
|
325
|
+
default: "router-link-exact-active"
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
setup(props, { slots }) {
|
|
329
|
+
return () => {
|
|
330
|
+
const to = props.href || props.to;
|
|
331
|
+
if (props.external || typeof to === "string" && to.startsWith("http")) return h("a", {
|
|
332
|
+
href: typeof to === "string" ? to : "/",
|
|
333
|
+
target: props.target,
|
|
334
|
+
rel: props.rel ?? (props.target === "_blank" ? "noopener noreferrer" : void 0)
|
|
335
|
+
}, slots.default?.());
|
|
336
|
+
try {
|
|
337
|
+
const { RouterLink } = __require("vue-router");
|
|
338
|
+
return h(RouterLink, {
|
|
339
|
+
to,
|
|
340
|
+
replace: props.replace,
|
|
341
|
+
activeClass: props.activeClass,
|
|
342
|
+
exactActiveClass: props.exactActiveClass
|
|
343
|
+
}, slots);
|
|
344
|
+
} catch {
|
|
345
|
+
return h("a", { href: typeof to === "string" ? to : "/" }, slots.default?.());
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
/**
|
|
351
|
+
* Mock NuxtPage - renders <RouterView> or slot content.
|
|
352
|
+
*/
|
|
353
|
+
const NuxtPage = defineComponent({
|
|
354
|
+
name: "NuxtPage",
|
|
355
|
+
props: {
|
|
356
|
+
name: {
|
|
357
|
+
type: String,
|
|
358
|
+
default: "default"
|
|
359
|
+
},
|
|
360
|
+
transition: {
|
|
361
|
+
type: [Boolean, Object],
|
|
362
|
+
default: void 0
|
|
363
|
+
},
|
|
364
|
+
keepalive: {
|
|
365
|
+
type: [Boolean, Object],
|
|
366
|
+
default: void 0
|
|
367
|
+
},
|
|
368
|
+
pageKey: {
|
|
369
|
+
type: [String, Function],
|
|
370
|
+
default: void 0
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
setup(props, { slots }) {
|
|
374
|
+
return () => {
|
|
375
|
+
if (slots.default) return slots.default();
|
|
376
|
+
try {
|
|
377
|
+
const { RouterView } = __require("vue-router");
|
|
378
|
+
return h(RouterView, { name: props.name });
|
|
379
|
+
} catch {
|
|
380
|
+
return h("div", { "data-nuxt-page": "" }, "NuxtPage placeholder");
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
/**
|
|
386
|
+
* Mock ClientOnly - renders default slot on client side (always in browser context).
|
|
387
|
+
*/
|
|
388
|
+
const ClientOnly = defineComponent({
|
|
389
|
+
name: "ClientOnly",
|
|
390
|
+
setup(_props, { slots }) {
|
|
391
|
+
return () => slots.default?.() ?? null;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
/**
|
|
395
|
+
* Mock NuxtLayout - renders slot content with optional layout wrapper.
|
|
396
|
+
*/
|
|
397
|
+
const NuxtLayout = defineComponent({
|
|
398
|
+
name: "NuxtLayout",
|
|
399
|
+
props: {
|
|
400
|
+
name: {
|
|
401
|
+
type: String,
|
|
402
|
+
default: "default"
|
|
403
|
+
},
|
|
404
|
+
fallback: {
|
|
405
|
+
type: String,
|
|
406
|
+
default: void 0
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
setup(_props, { slots }) {
|
|
410
|
+
return () => slots.default?.() ?? null;
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
/**
|
|
414
|
+
* Mock NuxtLoadingIndicator - renders nothing.
|
|
415
|
+
*/
|
|
416
|
+
const NuxtLoadingIndicator = defineComponent({
|
|
417
|
+
name: "NuxtLoadingIndicator",
|
|
418
|
+
render() {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
/**
|
|
423
|
+
* Mock NuxtErrorBoundary - renders default slot.
|
|
424
|
+
*/
|
|
425
|
+
const NuxtErrorBoundary = defineComponent({
|
|
426
|
+
name: "NuxtErrorBoundary",
|
|
427
|
+
setup(_props, { slots }) {
|
|
428
|
+
return () => slots.default?.() ?? null;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/index.ts
|
|
433
|
+
/**
|
|
434
|
+
* Create Nuxt mock Vite plugin for Musea.
|
|
435
|
+
*/
|
|
436
|
+
function nuxtMusea(options = {}) {
|
|
437
|
+
return createNuxtMuseaPlugin(options);
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
export { ClientOnly, NuxtErrorBoundary, NuxtLayout, NuxtLink, NuxtLoadingIndicator, NuxtPage, abortNavigation, navigateTo, nuxtMusea, useAsyncData, useCookie, useFetch, useHead, useLazyAsyncData, useLazyFetch, useNuxtApp, useRoute, useRouter, useRuntimeConfig, useSeoMeta, useState };
|