@anfo/nuxt-dialogs-plugin 1.0.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.
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/module.ts
21
+ var module_exports = {};
22
+ __export(module_exports, {
23
+ default: () => module_default
24
+ });
25
+ module.exports = __toCommonJS(module_exports);
26
+ var import_kit = require("@nuxt/kit");
27
+ var import_node_path2 = require("path");
28
+
29
+ // src/vite-plugin.ts
30
+ var import_node_fs = require("fs");
31
+ var import_node_path = require("path");
32
+ var VIRTUAL_ID = "virtual:dialogs";
33
+ var RESOLVED_VIRTUAL_ID = "\0virtual:dialogs";
34
+ function scanDialogFiles(dir, pattern) {
35
+ try {
36
+ return (0, import_node_fs.readdirSync)(dir).filter((f) => pattern.test(f)).sort().map((f) => (0, import_node_path.resolve)(dir, f));
37
+ } catch {
38
+ return [];
39
+ }
40
+ }
41
+ function componentName(filePath) {
42
+ return (0, import_node_path.basename)(filePath, ".vue");
43
+ }
44
+ function generateModuleCode(files, options) {
45
+ const { dir, importAlias, runtimePkg, inheritNuxtApp } = options;
46
+ const runtimeImports = inheritNuxtApp ? "applyDialogAppPlugins, dialogControllerKey, getDialogsNuxtVueApp" : "applyDialogAppPlugins, dialogControllerKey";
47
+ const lines = [
48
+ `import { createApp } from "vue";`,
49
+ `import { ${runtimeImports} } from ${JSON.stringify(runtimePkg)};`
50
+ ];
51
+ for (let i = 0; i < files.length; i++) {
52
+ lines.push(
53
+ `import _D${i} from ${JSON.stringify(`${importAlias}/${(0, import_node_path.basename)(files[i])}`)};`
54
+ );
55
+ }
56
+ const ssrGuard = ` if (typeof document === "undefined") {
57
+ console.warn("[nuxt-dialogs] dialogs can only be opened in the browser; ignoring a dialog opened during SSR.");
58
+ return Object.assign(Promise.resolve({ type: "reject", reason: new Error("Dialogs are client-only (opened during SSR).") }), {
59
+ resolve() { return this; },
60
+ reject() { return this; },
61
+ });
62
+ }
63
+ `;
64
+ const contextInherit = inheritNuxtApp ? ` const nuxtVueApp = getDialogsNuxtVueApp();
65
+ if (nuxtVueApp) {
66
+ const base = app._context;
67
+ const main = nuxtVueApp._context;
68
+ app._context = {
69
+ ...base,
70
+ config: { ...base.config, ...main.config },
71
+ components: { ...base.components, ...main.components },
72
+ directives: { ...base.directives, ...main.directives },
73
+ provides: { ...base.provides, ...main.provides },
74
+ };
75
+ }
76
+ ` : "";
77
+ lines.push(`
78
+ function mountDialog(component, props) {
79
+ ${ssrGuard} const result = new Promise((resolve) => {
80
+ const host = document.createElement("div");
81
+ document.body.appendChild(host);
82
+ let settled = false;
83
+ function cleanup() { app.unmount(); host.remove(); }
84
+ function finish(cb) {
85
+ if (settled) return;
86
+ settled = true;
87
+ cb();
88
+ cleanup();
89
+ }
90
+ function handleResolve(...args) {
91
+ finish(() => {
92
+ if (args.length === 0) { resolve({ type: "resolve" }); return; }
93
+ resolve({ type: "resolve", value: args[0] });
94
+ });
95
+ }
96
+ const controller = {
97
+ resolve: handleResolve,
98
+ reject: (reason) => { finish(() => resolve({ type: "reject", reason })); },
99
+ };
100
+ const app = createApp(component, props);
101
+ ${contextInherit} app.provide(dialogControllerKey, controller);
102
+ applyDialogAppPlugins(app);
103
+ app.mount(host);
104
+ });
105
+ return Object.assign(result, {
106
+ resolve(callback) {
107
+ result.then((value) => {
108
+ if (value.type === "resolve") callback?.(value.value);
109
+ });
110
+ return this;
111
+ },
112
+ reject(callback) {
113
+ result.then((value) => {
114
+ if (value.type === "reject") callback(value.reason);
115
+ });
116
+ return this;
117
+ },
118
+ });
119
+ }`);
120
+ lines.push("");
121
+ lines.push("export const dialogs = {");
122
+ for (let i = 0; i < files.length; i++) {
123
+ lines.push(
124
+ ` ${componentName(files[i])}: (props) => mountDialog(_D${i}, props),`
125
+ );
126
+ }
127
+ lines.push("};");
128
+ return lines.join("\n");
129
+ }
130
+ function generateDialogsDts(options) {
131
+ const { files, dtsDir, dialogsDir, runtimePkg } = options;
132
+ const lines = [
133
+ "// Auto-generated by @anfo/nuxt-dialogs-plugin \u2014 do not edit manually.",
134
+ "",
135
+ `declare module "${VIRTUAL_ID}" {`,
136
+ ` type _C = import("vue").Component;`,
137
+ ` type _CE<T extends _C> = import("vue-component-type-helpers").ComponentExposed<T>;`,
138
+ ` type _CP<T extends _C> = import("vue-component-type-helpers").ComponentProps<T>;`,
139
+ ` type _DE<T> = import(${JSON.stringify(runtimePkg)}).DialogExposed<T>;`,
140
+ ` type _DS<T> = import(${JSON.stringify(runtimePkg)}).DialogSettledResult<T>;`,
141
+ ` type _DR = import(${JSON.stringify(runtimePkg)}).DialogRejectedResult;`,
142
+ ` type _IK = "key" | "ref" | "ref_for" | "ref_key" | "class" | "style" | \`on\${string}\`;`,
143
+ ` type _P<T extends _C> = Omit<_CP<T>, _IK>;`,
144
+ ` type _RK<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];`,
145
+ ` type _A<T extends _C> = [_RK<_P<T>>] extends [never] ? [props?: _P<T>] : [props: _P<T>];`,
146
+ ` type _V<T extends _C> = _CE<T> extends _DE<infer R> ? R : void;`,
147
+ ` type _R<T extends _C> = _DS<_V<T>>;`,
148
+ ` type _RN = _DR["reason"];`,
149
+ ` type _H<T extends _C> = Promise<_R<T>> & {`,
150
+ ` resolve(callback?: (value: _V<T> | undefined) => void): _H<T>;`,
151
+ ` reject(callback: (reason: _RN) => void): _H<T>;`,
152
+ ` };`,
153
+ ` export const dialogs: {`
154
+ ];
155
+ for (const filePath of files) {
156
+ const name = componentName(filePath);
157
+ let rel = (0, import_node_path.relative)(dtsDir, filePath).replace(/\\/g, "/");
158
+ if (!rel.startsWith(".")) rel = `./${rel}`;
159
+ const comp = `typeof import(${JSON.stringify(rel)})["default"]`;
160
+ lines.push(` ${name}: (...args: _A<${comp}>) => _H<${comp}>;`);
161
+ }
162
+ lines.push(" };", "}", "");
163
+ return lines.join("\n");
164
+ }
165
+ function createDialogsVitePlugin(options) {
166
+ const { dir, pattern, dtsPath } = options;
167
+ function writeDts() {
168
+ const dtsDir = (0, import_node_path.dirname)(dtsPath);
169
+ (0, import_node_fs.mkdirSync)(dtsDir, { recursive: true });
170
+ (0, import_node_fs.writeFileSync)(
171
+ dtsPath,
172
+ generateDialogsDts({
173
+ files: scanDialogFiles(dir, pattern),
174
+ dtsDir,
175
+ dialogsDir: dir,
176
+ runtimePkg: options.runtimePkg
177
+ }),
178
+ "utf-8"
179
+ );
180
+ }
181
+ function invalidate(server) {
182
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
183
+ if (mod) server.moduleGraph.invalidateModule(mod);
184
+ writeDts();
185
+ server.hot.send({ type: "full-reload" });
186
+ }
187
+ return {
188
+ name: "nuxt-dialogs-plugin",
189
+ buildStart() {
190
+ writeDts();
191
+ },
192
+ resolveId(id) {
193
+ if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
194
+ },
195
+ load(id) {
196
+ if (id !== RESOLVED_VIRTUAL_ID) return;
197
+ const files = scanDialogFiles(dir, pattern);
198
+ return {
199
+ code: generateModuleCode(files, options),
200
+ moduleType: "js"
201
+ };
202
+ },
203
+ configureServer(server) {
204
+ server.watcher.add(dir);
205
+ server.watcher.on("add", (file) => {
206
+ if (pattern.test(file) && file.startsWith(dir)) {
207
+ invalidate(server);
208
+ }
209
+ });
210
+ server.watcher.on("unlink", (file) => {
211
+ if (pattern.test(file) && file.startsWith(dir)) {
212
+ invalidate(server);
213
+ }
214
+ });
215
+ }
216
+ };
217
+ }
218
+
219
+ // src/module.ts
220
+ var RUNTIME_PKG = "@anfo/nuxt-dialogs-plugin/runtime";
221
+ var IMPORT_ALIAS = "#dialogs-components";
222
+ var TYPE_TEMPLATE = "types/dialogs.d.ts";
223
+ var module_default = (0, import_kit.defineNuxtModule)({
224
+ meta: {
225
+ name: "@anfo/nuxt-dialogs-plugin",
226
+ configKey: "dialogs",
227
+ version: "1.0.0",
228
+ compatibility: { nuxt: ">=3.5.0" }
229
+ },
230
+ defaults: {
231
+ dir: "dialogs",
232
+ pattern: /(Dialog|Drawer)\.vue$/,
233
+ inheritNuxtApp: true
234
+ },
235
+ setup(options, nuxt) {
236
+ const dialogsDir = (0, import_node_path2.resolve)(nuxt.options.srcDir, options.dir ?? "dialogs");
237
+ const pattern = options.pattern ?? /(Dialog|Drawer)\.vue$/;
238
+ const dtsPath = (0, import_node_path2.resolve)(nuxt.options.buildDir, TYPE_TEMPLATE);
239
+ if (String(nuxt.options.builder ?? "").includes("webpack")) {
240
+ console.warn(
241
+ "[@anfo/nuxt-dialogs-plugin] only the Vite builder is supported; `virtual:dialogs` will not resolve in webpack builds."
242
+ );
243
+ }
244
+ nuxt.options.alias[IMPORT_ALIAS] = dialogsDir;
245
+ const vitePlugin = createDialogsVitePlugin({
246
+ dir: dialogsDir,
247
+ pattern,
248
+ importAlias: IMPORT_ALIAS,
249
+ runtimePkg: RUNTIME_PKG,
250
+ dtsPath,
251
+ inheritNuxtApp: options.inheritNuxtApp ?? true
252
+ });
253
+ nuxt.hook("vite:extendConfig", (config) => {
254
+ config.plugins ?? (config.plugins = []);
255
+ config.plugins.push(vitePlugin);
256
+ });
257
+ if (options.inheritNuxtApp) {
258
+ (0, import_kit.addPluginTemplate)({
259
+ filename: "dialogs-context-plugin.mjs",
260
+ getContents: () => `import { provideDialogsNuxtApp } from ${JSON.stringify(RUNTIME_PKG)};
261
+ export default (nuxtApp) => { provideDialogsNuxtApp(nuxtApp.vueApp); };
262
+ `
263
+ });
264
+ }
265
+ (0, import_kit.addImports)([
266
+ { name: "dialogs", from: "virtual:dialogs" },
267
+ { name: "useDialogContext", from: RUNTIME_PKG },
268
+ { name: "createDialogExpose", from: RUNTIME_PKG },
269
+ { name: "configureDialogs", from: RUNTIME_PKG }
270
+ ]);
271
+ const files = scanDialogFiles(dialogsDir, pattern);
272
+ (0, import_kit.addTypeTemplate)({
273
+ filename: TYPE_TEMPLATE,
274
+ getContents: () => generateDialogsDts({
275
+ files,
276
+ dtsDir: (0, import_node_path2.dirname)(dtsPath),
277
+ dialogsDir,
278
+ runtimePkg: RUNTIME_PKG
279
+ })
280
+ });
281
+ }
282
+ });
283
+ //# sourceMappingURL=module.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/module.ts","../src/vite-plugin.ts"],"sourcesContent":["import {\n addImports,\n addPluginTemplate,\n addTypeTemplate,\n defineNuxtModule,\n} from \"@nuxt/kit\";\nimport type { Nuxt } from \"@nuxt/schema\";\nimport { dirname, resolve } from \"node:path\";\nimport {\n createDialogsVitePlugin,\n generateDialogsDts,\n scanDialogFiles,\n} from \"./vite-plugin\";\n\nexport interface ModuleOptions {\n /**\n * Directory that contains dialog components.\n * Relative paths are resolved against `srcDir`. Defaults to `dialogs`.\n */\n dir?: string;\n /**\n * RegExp used to identify dialog component files.\n * Defaults to files whose name ends with `Dialog.vue` or `Drawer.vue`.\n */\n pattern?: RegExp;\n /**\n * When true (default), every dialog app inherits the Nuxt app's context:\n * global components, directives and provides — Pinia, i18n, UI libraries,\n * the `nuxtApp` itself — are all available inside dialogs with no wiring.\n */\n inheritNuxtApp?: boolean;\n}\n\nconst RUNTIME_PKG = \"@anfo/nuxt-dialogs-plugin/runtime\";\nconst IMPORT_ALIAS = \"#dialogs-components\";\nconst TYPE_TEMPLATE = \"types/dialogs.d.ts\";\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: \"@anfo/nuxt-dialogs-plugin\",\n configKey: \"dialogs\",\n version: \"1.0.0\",\n compatibility: { nuxt: \">=3.5.0\" },\n },\n defaults: {\n dir: \"dialogs\",\n pattern: /(Dialog|Drawer)\\.vue$/,\n inheritNuxtApp: true,\n },\n setup(options, nuxt: Nuxt) {\n const dialogsDir = resolve(nuxt.options.srcDir, options.dir ?? \"dialogs\");\n const pattern = options.pattern ?? /(Dialog|Drawer)\\.vue$/;\n const dtsPath = resolve(nuxt.options.buildDir, TYPE_TEMPLATE);\n\n if (String(nuxt.options.builder ?? \"\").includes(\"webpack\")) {\n console.warn(\n \"[@anfo/nuxt-dialogs-plugin] only the Vite builder is supported; `virtual:dialogs` will not resolve in webpack builds.\",\n );\n }\n\n // Let the generated virtual module import components through a stable\n // alias, so the dialogs directory can live anywhere.\n nuxt.options.alias[IMPORT_ALIAS] = dialogsDir;\n\n // Register the dialogs virtual module in every Vite build (client and\n // server bundles both need to resolve `virtual:dialogs` imports).\n const vitePlugin = createDialogsVitePlugin({\n dir: dialogsDir,\n pattern,\n importAlias: IMPORT_ALIAS,\n runtimePkg: RUNTIME_PKG,\n dtsPath,\n inheritNuxtApp: options.inheritNuxtApp ?? true,\n });\n nuxt.hook(\"vite:extendConfig\", (config) => {\n (config as { plugins: unknown[] }).plugins ??= [];\n (config.plugins as unknown[]).push(vitePlugin);\n });\n\n // Capture the Nuxt app so generated dialog mounts can inherit its\n // context (global components, directives, provides).\n if (options.inheritNuxtApp) {\n addPluginTemplate({\n filename: \"dialogs-context-plugin.mjs\",\n getContents: () =>\n `import { provideDialogsNuxtApp } from ${JSON.stringify(RUNTIME_PKG)};\\n` +\n `export default (nuxtApp) => { provideDialogsNuxtApp(nuxtApp.vueApp); };\\n`,\n });\n }\n\n // Auto-imports — explicit imports from the runtime keep working too.\n addImports([\n { name: \"dialogs\", from: \"virtual:dialogs\" },\n { name: \"useDialogContext\", from: RUNTIME_PKG },\n { name: \"createDialogExpose\", from: RUNTIME_PKG },\n { name: \"configureDialogs\", from: RUNTIME_PKG },\n ]);\n\n // Type declarations for `virtual:dialogs`, included in the generated\n // tsconfig automatically — no user tsconfig changes required. The Vite\n // plugin rewrites this same file when dialog files are added/removed.\n const files = scanDialogFiles(dialogsDir, pattern);\n addTypeTemplate({\n filename: TYPE_TEMPLATE,\n getContents: () =>\n generateDialogsDts({\n files,\n dtsDir: dirname(dtsPath),\n dialogsDir,\n runtimePkg: RUNTIME_PKG,\n }),\n });\n },\n});\n","import type { Plugin, ViteDevServer } from \"vite\";\nimport { mkdirSync, readdirSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, relative, resolve } from \"node:path\";\n\nexport interface DialogsVitePluginOptions {\n /** Absolute path to the directory that contains dialog components. */\n dir: string;\n /** RegExp used to identify dialog component files. */\n pattern: RegExp;\n /**\n * Alias registered on the Nuxt app (e.g. `#dialogs-components`) that maps\n * to `dir`. The virtual module imports components through it so the\n * generated code never depends on where the directory lives.\n */\n importAlias: string;\n /** Runtime package specifier, e.g. `@anfo/nuxt-dialogs-plugin/runtime`. */\n runtimePkg: string;\n /** Absolute path of the generated declaration file. */\n dtsPath: string;\n /**\n * When true, generated dialog apps inherit the Nuxt app's context\n * (global components, directives, provides — Pinia, i18n, UI libs…).\n */\n inheritNuxtApp: boolean;\n}\n\nconst VIRTUAL_ID = \"virtual:dialogs\";\nconst RESOLVED_VIRTUAL_ID = \"\\0virtual:dialogs\";\n\n// ── Scanning ──────────────────────────────────────────────────────────────────\n\nexport function scanDialogFiles(dir: string, pattern: RegExp): string[] {\n try {\n return readdirSync(dir)\n .filter((f: string) => pattern.test(f))\n .sort()\n .map((f: string) => resolve(dir, f));\n } catch {\n return [];\n }\n}\n\nfunction componentName(filePath: string): string {\n return basename(filePath, \".vue\");\n}\n\n// ── Virtual module code generation ────────────────────────────────────────────\n\nfunction generateModuleCode(\n files: string[],\n options: DialogsVitePluginOptions,\n): string {\n const { dir, importAlias, runtimePkg, inheritNuxtApp } = options;\n\n const runtimeImports = inheritNuxtApp\n ? \"applyDialogAppPlugins, dialogControllerKey, getDialogsNuxtVueApp\"\n : \"applyDialogAppPlugins, dialogControllerKey\";\n\n const lines: string[] = [\n `import { createApp } from \"vue\";`,\n `import { ${runtimeImports} } from ${JSON.stringify(runtimePkg)};`,\n ];\n for (let i = 0; i < files.length; i++) {\n lines.push(\n `import _D${i} from ${JSON.stringify(`${importAlias}/${basename(files[i])}`)};`,\n );\n }\n\n // Dialogs are DOM-only; calling one during SSR resolves as a rejection\n // instead of crashing the server render.\n const ssrGuard = ` if (typeof document === \"undefined\") {\n console.warn(\"[nuxt-dialogs] dialogs can only be opened in the browser; ignoring a dialog opened during SSR.\");\n return Object.assign(Promise.resolve({ type: \"reject\", reason: new Error(\"Dialogs are client-only (opened during SSR).\") }), {\n resolve() { return this; },\n reject() { return this; },\n });\n }\n`;\n\n // Shallow-clone the Nuxt app's context onto the dialog app. Every bucket\n // must be copied (not shared by reference) so the `provide()` below — and\n // any plugin install — cannot leak into the main Nuxt app.\n const contextInherit = inheritNuxtApp\n ? ` const nuxtVueApp = getDialogsNuxtVueApp();\n if (nuxtVueApp) {\n const base = app._context;\n const main = nuxtVueApp._context;\n app._context = {\n ...base,\n config: { ...base.config, ...main.config },\n components: { ...base.components, ...main.components },\n directives: { ...base.directives, ...main.directives },\n provides: { ...base.provides, ...main.provides },\n };\n }\n`\n : \"\";\n\n lines.push(`\nfunction mountDialog(component, props) {\n${ssrGuard} const result = new Promise((resolve) => {\n const host = document.createElement(\"div\");\n document.body.appendChild(host);\n let settled = false;\n function cleanup() { app.unmount(); host.remove(); }\n function finish(cb) {\n if (settled) return;\n settled = true;\n cb();\n cleanup();\n }\n function handleResolve(...args) {\n finish(() => {\n if (args.length === 0) { resolve({ type: \"resolve\" }); return; }\n resolve({ type: \"resolve\", value: args[0] });\n });\n }\n const controller = {\n resolve: handleResolve,\n reject: (reason) => { finish(() => resolve({ type: \"reject\", reason })); },\n };\n const app = createApp(component, props);\n${contextInherit} app.provide(dialogControllerKey, controller);\n applyDialogAppPlugins(app);\n app.mount(host);\n });\n return Object.assign(result, {\n resolve(callback) {\n result.then((value) => {\n if (value.type === \"resolve\") callback?.(value.value);\n });\n return this;\n },\n reject(callback) {\n result.then((value) => {\n if (value.type === \"reject\") callback(value.reason);\n });\n return this;\n },\n });\n}`);\n\n lines.push(\"\");\n lines.push(\"export const dialogs = {\");\n for (let i = 0; i < files.length; i++) {\n lines.push(\n `\\t${componentName(files[i])}: (props) => mountDialog(_D${i}, props),`,\n );\n }\n lines.push(\"};\");\n return lines.join(\"\\n\");\n}\n\n// ── Declaration file generation ───────────────────────────────────────────────\n\nexport function generateDialogsDts(options: {\n files: string[];\n /** Absolute path of the directory the .d.ts is written to. */\n dtsDir: string;\n /** Directory containing the dialog components (absolute). */\n dialogsDir: string;\n /** Runtime package specifier for type imports. */\n runtimePkg: string;\n}): string {\n const { files, dtsDir, dialogsDir, runtimePkg } = options;\n\n const lines: string[] = [\n \"// Auto-generated by @anfo/nuxt-dialogs-plugin — do not edit manually.\",\n \"\",\n `declare module \"${VIRTUAL_ID}\" {`,\n `\\ttype _C = import(\"vue\").Component;`,\n `\\ttype _CE<T extends _C> = import(\"vue-component-type-helpers\").ComponentExposed<T>;`,\n `\\ttype _CP<T extends _C> = import(\"vue-component-type-helpers\").ComponentProps<T>;`,\n `\\ttype _DE<T> = import(${JSON.stringify(runtimePkg)}).DialogExposed<T>;`,\n `\\ttype _DS<T> = import(${JSON.stringify(runtimePkg)}).DialogSettledResult<T>;`,\n `\\ttype _DR = import(${JSON.stringify(runtimePkg)}).DialogRejectedResult;`,\n `\\ttype _IK = \"key\" | \"ref\" | \"ref_for\" | \"ref_key\" | \"class\" | \"style\" | \\`on\\${string}\\`;`,\n `\\ttype _P<T extends _C> = Omit<_CP<T>, _IK>;`,\n `\\ttype _RK<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];`,\n `\\ttype _A<T extends _C> = [_RK<_P<T>>] extends [never] ? [props?: _P<T>] : [props: _P<T>];`,\n `\\ttype _V<T extends _C> = _CE<T> extends _DE<infer R> ? R : void;`,\n `\\ttype _R<T extends _C> = _DS<_V<T>>;`,\n `\\ttype _RN = _DR[\"reason\"];`,\n `\\ttype _H<T extends _C> = Promise<_R<T>> & {`,\n `\\t\\tresolve(callback?: (value: _V<T> | undefined) => void): _H<T>;`,\n `\\t\\treject(callback: (reason: _RN) => void): _H<T>;`,\n `\\t};`,\n `\\texport const dialogs: {`,\n ];\n\n for (const filePath of files) {\n const name = componentName(filePath);\n let rel = relative(dtsDir, filePath).replace(/\\\\/g, \"/\");\n if (!rel.startsWith(\".\")) rel = `./${rel}`;\n const comp = `typeof import(${JSON.stringify(rel)})[\"default\"]`;\n lines.push(`\\t\\t${name}: (...args: _A<${comp}>) => _H<${comp}>;`);\n }\n\n lines.push(\"\\t};\", \"}\", \"\");\n return lines.join(\"\\n\");\n}\n\n// ── Plugin ────────────────────────────────────────────────────────────────────\n\nexport function createDialogsVitePlugin(\n options: DialogsVitePluginOptions,\n): Plugin {\n const { dir, pattern, dtsPath } = options;\n\n function writeDts(): void {\n const dtsDir = dirname(dtsPath);\n mkdirSync(dtsDir, { recursive: true });\n writeFileSync(\n dtsPath,\n generateDialogsDts({\n files: scanDialogFiles(dir, pattern),\n dtsDir,\n dialogsDir: dir,\n runtimePkg: options.runtimePkg,\n }),\n \"utf-8\",\n );\n }\n\n function invalidate(server: ViteDevServer): void {\n const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);\n if (mod) server.moduleGraph.invalidateModule(mod);\n writeDts();\n server.hot.send({ type: \"full-reload\" });\n }\n\n return {\n name: \"nuxt-dialogs-plugin\",\n\n buildStart() {\n writeDts();\n },\n\n resolveId(id) {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;\n },\n\n load(id) {\n if (id !== RESOLVED_VIRTUAL_ID) return;\n const files = scanDialogFiles(dir, pattern);\n return {\n code: generateModuleCode(files, options),\n moduleType: \"js\",\n };\n },\n\n configureServer(server) {\n server.watcher.add(dir);\n\n server.watcher.on(\"add\", (file) => {\n if (pattern.test(file) && file.startsWith(dir)) {\n invalidate(server);\n }\n });\n\n server.watcher.on(\"unlink\", (file) => {\n if (pattern.test(file) && file.startsWith(dir)) {\n invalidate(server);\n }\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAKO;AAEP,IAAAA,oBAAiC;;;ACNjC,qBAAsD;AACtD,uBAAqD;AAwBrD,IAAM,aAAa;AACnB,IAAM,sBAAsB;AAIrB,SAAS,gBAAgB,KAAa,SAA2B;AACpE,MAAI;AACA,eAAO,4BAAY,GAAG,EACjB,OAAO,CAAC,MAAc,QAAQ,KAAK,CAAC,CAAC,EACrC,KAAK,EACL,IAAI,CAAC,UAAc,0BAAQ,KAAK,CAAC,CAAC;AAAA,EAC3C,QAAQ;AACJ,WAAO,CAAC;AAAA,EACZ;AACJ;AAEA,SAAS,cAAc,UAA0B;AAC7C,aAAO,2BAAS,UAAU,MAAM;AACpC;AAIA,SAAS,mBACL,OACA,SACM;AACN,QAAM,EAAE,KAAK,aAAa,YAAY,eAAe,IAAI;AAEzD,QAAM,iBAAiB,iBACjB,qEACA;AAEN,QAAM,QAAkB;AAAA,IACpB;AAAA,IACA,YAAY,cAAc,WAAW,KAAK,UAAU,UAAU,CAAC;AAAA,EACnE;AACA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,UAAM;AAAA,MACF,YAAY,CAAC,SAAS,KAAK,UAAU,GAAG,WAAW,QAAI,2BAAS,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AAAA,IAChF;AAAA,EACJ;AAIA,QAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AgB;AACxB,wCAAkB;AAAA,QACd,UAAU;AAAA,QACV,aAAa,MACT,yCAAyC,KAAK,UAAU,WAAW,CAAC;AAAA;AAAA;AAAA,MAE5E,CAAC;AAAA,IACL;AAGA,+BAAW;AAAA,MACP,EAAE,MAAM,WAAW,MAAM,kBAAkB;AAAA,MAC3C,EAAE,MAAM,oBAAoB,MAAM,YAAY;AAAA,MAC9C,EAAE,MAAM,sBAAsB,MAAM,YAAY;AAAA,MAChD,EAAE,MAAM,oBAAoB,MAAM,YAAY;AAAA,IAClD,CAAC;AAKD,UAAM,QAAQ,gBAAgB,YAAY,OAAO;AACjD,oCAAgB;AAAA,MACZ,UAAU;AAAA,MACV,aAAa,MACT,mBAAmB;AAAA,QACf;AAAA,QACA,YAAQ,2BAAQ,OAAO;AAAA,QACvB;AAAA,QACA,YAAY;AAAA,MAChB,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AACJ,CAAC;","names":["import_node_path"]}
@@ -0,0 +1,23 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface ModuleOptions {
4
+ /**
5
+ * Directory that contains dialog components.
6
+ * Relative paths are resolved against `srcDir`. Defaults to `dialogs`.
7
+ */
8
+ dir?: string;
9
+ /**
10
+ * RegExp used to identify dialog component files.
11
+ * Defaults to files whose name ends with `Dialog.vue` or `Drawer.vue`.
12
+ */
13
+ pattern?: RegExp;
14
+ /**
15
+ * When true (default), every dialog app inherits the Nuxt app's context:
16
+ * global components, directives and provides — Pinia, i18n, UI libraries,
17
+ * the `nuxtApp` itself — are all available inside dialogs with no wiring.
18
+ */
19
+ inheritNuxtApp?: boolean;
20
+ }
21
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
22
+
23
+ export { type ModuleOptions, _default as default };
@@ -0,0 +1,23 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface ModuleOptions {
4
+ /**
5
+ * Directory that contains dialog components.
6
+ * Relative paths are resolved against `srcDir`. Defaults to `dialogs`.
7
+ */
8
+ dir?: string;
9
+ /**
10
+ * RegExp used to identify dialog component files.
11
+ * Defaults to files whose name ends with `Dialog.vue` or `Drawer.vue`.
12
+ */
13
+ pattern?: RegExp;
14
+ /**
15
+ * When true (default), every dialog app inherits the Nuxt app's context:
16
+ * global components, directives and provides — Pinia, i18n, UI libraries,
17
+ * the `nuxtApp` itself — are all available inside dialogs with no wiring.
18
+ */
19
+ inheritNuxtApp?: boolean;
20
+ }
21
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
22
+
23
+ export { type ModuleOptions, _default as default };
package/dist/module.js ADDED
@@ -0,0 +1,267 @@
1
+ // src/module.ts
2
+ import {
3
+ addImports,
4
+ addPluginTemplate,
5
+ addTypeTemplate,
6
+ defineNuxtModule
7
+ } from "@nuxt/kit";
8
+ import { dirname as dirname2, resolve as resolve2 } from "path";
9
+
10
+ // src/vite-plugin.ts
11
+ import { mkdirSync, readdirSync, writeFileSync } from "fs";
12
+ import { basename, dirname, relative, resolve } from "path";
13
+ var VIRTUAL_ID = "virtual:dialogs";
14
+ var RESOLVED_VIRTUAL_ID = "\0virtual:dialogs";
15
+ function scanDialogFiles(dir, pattern) {
16
+ try {
17
+ return readdirSync(dir).filter((f) => pattern.test(f)).sort().map((f) => resolve(dir, f));
18
+ } catch {
19
+ return [];
20
+ }
21
+ }
22
+ function componentName(filePath) {
23
+ return basename(filePath, ".vue");
24
+ }
25
+ function generateModuleCode(files, options) {
26
+ const { dir, importAlias, runtimePkg, inheritNuxtApp } = options;
27
+ const runtimeImports = inheritNuxtApp ? "applyDialogAppPlugins, dialogControllerKey, getDialogsNuxtVueApp" : "applyDialogAppPlugins, dialogControllerKey";
28
+ const lines = [
29
+ `import { createApp } from "vue";`,
30
+ `import { ${runtimeImports} } from ${JSON.stringify(runtimePkg)};`
31
+ ];
32
+ for (let i = 0; i < files.length; i++) {
33
+ lines.push(
34
+ `import _D${i} from ${JSON.stringify(`${importAlias}/${basename(files[i])}`)};`
35
+ );
36
+ }
37
+ const ssrGuard = ` if (typeof document === "undefined") {
38
+ console.warn("[nuxt-dialogs] dialogs can only be opened in the browser; ignoring a dialog opened during SSR.");
39
+ return Object.assign(Promise.resolve({ type: "reject", reason: new Error("Dialogs are client-only (opened during SSR).") }), {
40
+ resolve() { return this; },
41
+ reject() { return this; },
42
+ });
43
+ }
44
+ `;
45
+ const contextInherit = inheritNuxtApp ? ` const nuxtVueApp = getDialogsNuxtVueApp();
46
+ if (nuxtVueApp) {
47
+ const base = app._context;
48
+ const main = nuxtVueApp._context;
49
+ app._context = {
50
+ ...base,
51
+ config: { ...base.config, ...main.config },
52
+ components: { ...base.components, ...main.components },
53
+ directives: { ...base.directives, ...main.directives },
54
+ provides: { ...base.provides, ...main.provides },
55
+ };
56
+ }
57
+ ` : "";
58
+ lines.push(`
59
+ function mountDialog(component, props) {
60
+ ${ssrGuard} const result = new Promise((resolve) => {
61
+ const host = document.createElement("div");
62
+ document.body.appendChild(host);
63
+ let settled = false;
64
+ function cleanup() { app.unmount(); host.remove(); }
65
+ function finish(cb) {
66
+ if (settled) return;
67
+ settled = true;
68
+ cb();
69
+ cleanup();
70
+ }
71
+ function handleResolve(...args) {
72
+ finish(() => {
73
+ if (args.length === 0) { resolve({ type: "resolve" }); return; }
74
+ resolve({ type: "resolve", value: args[0] });
75
+ });
76
+ }
77
+ const controller = {
78
+ resolve: handleResolve,
79
+ reject: (reason) => { finish(() => resolve({ type: "reject", reason })); },
80
+ };
81
+ const app = createApp(component, props);
82
+ ${contextInherit} app.provide(dialogControllerKey, controller);
83
+ applyDialogAppPlugins(app);
84
+ app.mount(host);
85
+ });
86
+ return Object.assign(result, {
87
+ resolve(callback) {
88
+ result.then((value) => {
89
+ if (value.type === "resolve") callback?.(value.value);
90
+ });
91
+ return this;
92
+ },
93
+ reject(callback) {
94
+ result.then((value) => {
95
+ if (value.type === "reject") callback(value.reason);
96
+ });
97
+ return this;
98
+ },
99
+ });
100
+ }`);
101
+ lines.push("");
102
+ lines.push("export const dialogs = {");
103
+ for (let i = 0; i < files.length; i++) {
104
+ lines.push(
105
+ ` ${componentName(files[i])}: (props) => mountDialog(_D${i}, props),`
106
+ );
107
+ }
108
+ lines.push("};");
109
+ return lines.join("\n");
110
+ }
111
+ function generateDialogsDts(options) {
112
+ const { files, dtsDir, dialogsDir, runtimePkg } = options;
113
+ const lines = [
114
+ "// Auto-generated by @anfo/nuxt-dialogs-plugin \u2014 do not edit manually.",
115
+ "",
116
+ `declare module "${VIRTUAL_ID}" {`,
117
+ ` type _C = import("vue").Component;`,
118
+ ` type _CE<T extends _C> = import("vue-component-type-helpers").ComponentExposed<T>;`,
119
+ ` type _CP<T extends _C> = import("vue-component-type-helpers").ComponentProps<T>;`,
120
+ ` type _DE<T> = import(${JSON.stringify(runtimePkg)}).DialogExposed<T>;`,
121
+ ` type _DS<T> = import(${JSON.stringify(runtimePkg)}).DialogSettledResult<T>;`,
122
+ ` type _DR = import(${JSON.stringify(runtimePkg)}).DialogRejectedResult;`,
123
+ ` type _IK = "key" | "ref" | "ref_for" | "ref_key" | "class" | "style" | \`on\${string}\`;`,
124
+ ` type _P<T extends _C> = Omit<_CP<T>, _IK>;`,
125
+ ` type _RK<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];`,
126
+ ` type _A<T extends _C> = [_RK<_P<T>>] extends [never] ? [props?: _P<T>] : [props: _P<T>];`,
127
+ ` type _V<T extends _C> = _CE<T> extends _DE<infer R> ? R : void;`,
128
+ ` type _R<T extends _C> = _DS<_V<T>>;`,
129
+ ` type _RN = _DR["reason"];`,
130
+ ` type _H<T extends _C> = Promise<_R<T>> & {`,
131
+ ` resolve(callback?: (value: _V<T> | undefined) => void): _H<T>;`,
132
+ ` reject(callback: (reason: _RN) => void): _H<T>;`,
133
+ ` };`,
134
+ ` export const dialogs: {`
135
+ ];
136
+ for (const filePath of files) {
137
+ const name = componentName(filePath);
138
+ let rel = relative(dtsDir, filePath).replace(/\\/g, "/");
139
+ if (!rel.startsWith(".")) rel = `./${rel}`;
140
+ const comp = `typeof import(${JSON.stringify(rel)})["default"]`;
141
+ lines.push(` ${name}: (...args: _A<${comp}>) => _H<${comp}>;`);
142
+ }
143
+ lines.push(" };", "}", "");
144
+ return lines.join("\n");
145
+ }
146
+ function createDialogsVitePlugin(options) {
147
+ const { dir, pattern, dtsPath } = options;
148
+ function writeDts() {
149
+ const dtsDir = dirname(dtsPath);
150
+ mkdirSync(dtsDir, { recursive: true });
151
+ writeFileSync(
152
+ dtsPath,
153
+ generateDialogsDts({
154
+ files: scanDialogFiles(dir, pattern),
155
+ dtsDir,
156
+ dialogsDir: dir,
157
+ runtimePkg: options.runtimePkg
158
+ }),
159
+ "utf-8"
160
+ );
161
+ }
162
+ function invalidate(server) {
163
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
164
+ if (mod) server.moduleGraph.invalidateModule(mod);
165
+ writeDts();
166
+ server.hot.send({ type: "full-reload" });
167
+ }
168
+ return {
169
+ name: "nuxt-dialogs-plugin",
170
+ buildStart() {
171
+ writeDts();
172
+ },
173
+ resolveId(id) {
174
+ if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
175
+ },
176
+ load(id) {
177
+ if (id !== RESOLVED_VIRTUAL_ID) return;
178
+ const files = scanDialogFiles(dir, pattern);
179
+ return {
180
+ code: generateModuleCode(files, options),
181
+ moduleType: "js"
182
+ };
183
+ },
184
+ configureServer(server) {
185
+ server.watcher.add(dir);
186
+ server.watcher.on("add", (file) => {
187
+ if (pattern.test(file) && file.startsWith(dir)) {
188
+ invalidate(server);
189
+ }
190
+ });
191
+ server.watcher.on("unlink", (file) => {
192
+ if (pattern.test(file) && file.startsWith(dir)) {
193
+ invalidate(server);
194
+ }
195
+ });
196
+ }
197
+ };
198
+ }
199
+
200
+ // src/module.ts
201
+ var RUNTIME_PKG = "@anfo/nuxt-dialogs-plugin/runtime";
202
+ var IMPORT_ALIAS = "#dialogs-components";
203
+ var TYPE_TEMPLATE = "types/dialogs.d.ts";
204
+ var module_default = defineNuxtModule({
205
+ meta: {
206
+ name: "@anfo/nuxt-dialogs-plugin",
207
+ configKey: "dialogs",
208
+ version: "1.0.0",
209
+ compatibility: { nuxt: ">=3.5.0" }
210
+ },
211
+ defaults: {
212
+ dir: "dialogs",
213
+ pattern: /(Dialog|Drawer)\.vue$/,
214
+ inheritNuxtApp: true
215
+ },
216
+ setup(options, nuxt) {
217
+ const dialogsDir = resolve2(nuxt.options.srcDir, options.dir ?? "dialogs");
218
+ const pattern = options.pattern ?? /(Dialog|Drawer)\.vue$/;
219
+ const dtsPath = resolve2(nuxt.options.buildDir, TYPE_TEMPLATE);
220
+ if (String(nuxt.options.builder ?? "").includes("webpack")) {
221
+ console.warn(
222
+ "[@anfo/nuxt-dialogs-plugin] only the Vite builder is supported; `virtual:dialogs` will not resolve in webpack builds."
223
+ );
224
+ }
225
+ nuxt.options.alias[IMPORT_ALIAS] = dialogsDir;
226
+ const vitePlugin = createDialogsVitePlugin({
227
+ dir: dialogsDir,
228
+ pattern,
229
+ importAlias: IMPORT_ALIAS,
230
+ runtimePkg: RUNTIME_PKG,
231
+ dtsPath,
232
+ inheritNuxtApp: options.inheritNuxtApp ?? true
233
+ });
234
+ nuxt.hook("vite:extendConfig", (config) => {
235
+ config.plugins ?? (config.plugins = []);
236
+ config.plugins.push(vitePlugin);
237
+ });
238
+ if (options.inheritNuxtApp) {
239
+ addPluginTemplate({
240
+ filename: "dialogs-context-plugin.mjs",
241
+ getContents: () => `import { provideDialogsNuxtApp } from ${JSON.stringify(RUNTIME_PKG)};
242
+ export default (nuxtApp) => { provideDialogsNuxtApp(nuxtApp.vueApp); };
243
+ `
244
+ });
245
+ }
246
+ addImports([
247
+ { name: "dialogs", from: "virtual:dialogs" },
248
+ { name: "useDialogContext", from: RUNTIME_PKG },
249
+ { name: "createDialogExpose", from: RUNTIME_PKG },
250
+ { name: "configureDialogs", from: RUNTIME_PKG }
251
+ ]);
252
+ const files = scanDialogFiles(dialogsDir, pattern);
253
+ addTypeTemplate({
254
+ filename: TYPE_TEMPLATE,
255
+ getContents: () => generateDialogsDts({
256
+ files,
257
+ dtsDir: dirname2(dtsPath),
258
+ dialogsDir,
259
+ runtimePkg: RUNTIME_PKG
260
+ })
261
+ });
262
+ }
263
+ });
264
+ export {
265
+ module_default as default
266
+ };
267
+ //# sourceMappingURL=module.js.map