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