@nara-web/inertia-vue 0.1.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/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @nara/inertia-vue
2
+
3
+ Vue 3 + Inertia.js adapter for the NARA framework.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nara/inertia-vue @inertiajs/vue3 vue
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Server-side
14
+
15
+ Register the Vue adapter in your NARA application:
16
+
17
+ ```typescript
18
+ // app/index.ts or server.ts
19
+ import { vueAdapter } from '@nara/inertia-vue';
20
+
21
+ const app = new Nara({
22
+ adapter: vueAdapter({
23
+ rootView: 'inertia.html',
24
+ }),
25
+ });
26
+ ```
27
+
28
+ ### Client-side
29
+
30
+ Initialize the Inertia app in your client entry point:
31
+
32
+ ```typescript
33
+ // resources/js/app.ts
34
+ import { initInertiaApp } from '@nara/inertia-vue';
35
+
36
+ initInertiaApp({
37
+ resolve: (name) => import(`./pages/${name}.vue`),
38
+ });
39
+ ```
40
+
41
+ ### Vite Configuration
42
+
43
+ Use the provided helper to configure Vite:
44
+
45
+ ```typescript
46
+ // vite.config.ts
47
+ import { defineConfig } from 'vite';
48
+ import { createViteConfig } from '@nara/inertia-vue';
49
+
50
+ export default defineConfig(
51
+ createViteConfig()
52
+ );
53
+ ```
54
+
55
+ ## License
56
+
57
+ MIT
@@ -0,0 +1,22 @@
1
+ // src/client/app.ts
2
+ import { createApp, h } from "vue";
3
+ import { createInertiaApp } from "@inertiajs/vue3";
4
+ function initInertiaApp(options = {}) {
5
+ const {
6
+ el = "#app",
7
+ resolve = (name) => {
8
+ const pages = import.meta.glob("./pages/**/*.vue", { eager: true });
9
+ return pages[`./pages/${name}.vue`];
10
+ }
11
+ } = options;
12
+ createInertiaApp({
13
+ resolve,
14
+ setup({ el: element, App, props, plugin }) {
15
+ createApp({ render: () => h(App, props) }).use(plugin).mount(element);
16
+ }
17
+ });
18
+ }
19
+
20
+ export {
21
+ initInertiaApp
22
+ };
@@ -0,0 +1,47 @@
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/client/app.ts
21
+ var app_exports = {};
22
+ __export(app_exports, {
23
+ initInertiaApp: () => initInertiaApp
24
+ });
25
+ module.exports = __toCommonJS(app_exports);
26
+ var import_vue = require("vue");
27
+ var import_vue3 = require("@inertiajs/vue3");
28
+ var import_meta = {};
29
+ function initInertiaApp(options = {}) {
30
+ const {
31
+ el = "#app",
32
+ resolve = (name) => {
33
+ const pages = import_meta.glob("./pages/**/*.vue", { eager: true });
34
+ return pages[`./pages/${name}.vue`];
35
+ }
36
+ } = options;
37
+ (0, import_vue3.createInertiaApp)({
38
+ resolve,
39
+ setup({ el: element, App, props, plugin }) {
40
+ (0, import_vue.createApp)({ render: () => (0, import_vue.h)(App, props) }).use(plugin).mount(element);
41
+ }
42
+ });
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ initInertiaApp
47
+ });
@@ -0,0 +1,17 @@
1
+ interface InitOptions {
2
+ /**
3
+ * Resolve a page component by name
4
+ */
5
+ resolve?: (name: string) => any;
6
+ /**
7
+ * Element selector to mount the app
8
+ * @default '#app'
9
+ */
10
+ el?: string;
11
+ }
12
+ /**
13
+ * Initializes the Inertia app for Vue 3
14
+ */
15
+ declare function initInertiaApp(options?: InitOptions): void;
16
+
17
+ export { type InitOptions, initInertiaApp };
@@ -0,0 +1,17 @@
1
+ interface InitOptions {
2
+ /**
3
+ * Resolve a page component by name
4
+ */
5
+ resolve?: (name: string) => any;
6
+ /**
7
+ * Element selector to mount the app
8
+ * @default '#app'
9
+ */
10
+ el?: string;
11
+ }
12
+ /**
13
+ * Initializes the Inertia app for Vue 3
14
+ */
15
+ declare function initInertiaApp(options?: InitOptions): void;
16
+
17
+ export { type InitOptions, initInertiaApp };
@@ -0,0 +1,6 @@
1
+ import {
2
+ initInertiaApp
3
+ } from "../chunk-ZSN4VNUJ.js";
4
+ export {
5
+ initInertiaApp
6
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createViteConfig: () => createViteConfig,
34
+ initInertiaApp: () => initInertiaApp,
35
+ vueAdapter: () => vueAdapter
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/middleware.ts
40
+ function inertiaMiddleware(options = {}) {
41
+ const { rootView = "inertia.html", version = "1.0.0" } = options;
42
+ return async (req, res, next) => {
43
+ res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
44
+ const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
45
+ const props = {
46
+ user: req.user || {},
47
+ ...inertiaProps,
48
+ ...viewProps,
49
+ error: req.cookies?.error || null
50
+ };
51
+ if (req.cookies?.error) {
52
+ res.clearCookie("error");
53
+ }
54
+ const inertiaObject = {
55
+ component,
56
+ props,
57
+ url,
58
+ version
59
+ };
60
+ if (!req.header("X-Inertia")) {
61
+ try {
62
+ const viewService = await import("@services/View").catch(() => null);
63
+ if (!viewService || !viewService.view) {
64
+ throw new Error("View service unavailable");
65
+ }
66
+ const html = await viewService.view(rootView, {
67
+ page: JSON.stringify(inertiaObject),
68
+ title: process.env["TITLE"] || "Nara App"
69
+ });
70
+ return res.type("html").send(html);
71
+ } catch (e) {
72
+ return res.status(500).send("Root view not found or View service unavailable");
73
+ }
74
+ }
75
+ res.setHeader("Vary", "Accept");
76
+ res.setHeader("X-Inertia", "true");
77
+ res.setHeader("X-Inertia-Version", version);
78
+ return res.json(inertiaObject);
79
+ };
80
+ next();
81
+ };
82
+ }
83
+
84
+ // src/adapter.ts
85
+ function vueAdapter(options = {}) {
86
+ return {
87
+ name: "vue-inertia",
88
+ /**
89
+ * Factory that returns the adapter's global middleware
90
+ */
91
+ middleware: () => inertiaMiddleware(options),
92
+ /**
93
+ * Method called during app initialization to extend the NaraResponse
94
+ */
95
+ extendResponse: (_res) => {
96
+ }
97
+ };
98
+ }
99
+
100
+ // src/vite.ts
101
+ var import_plugin_vue = __toESM(require("@vitejs/plugin-vue"), 1);
102
+ function createViteConfig(options = {}) {
103
+ return {
104
+ plugins: [
105
+ (0, import_plugin_vue.default)(options.vueOptions)
106
+ ],
107
+ resolve: {
108
+ alias: {
109
+ "@": "/resources/js"
110
+ }
111
+ },
112
+ build: {
113
+ outDir: "public/build",
114
+ manifest: true,
115
+ rollupOptions: {
116
+ input: "resources/js/app.ts"
117
+ }
118
+ }
119
+ };
120
+ }
121
+
122
+ // src/client/app.ts
123
+ var import_vue = require("vue");
124
+ var import_vue3 = require("@inertiajs/vue3");
125
+ var import_meta = {};
126
+ function initInertiaApp(options = {}) {
127
+ const {
128
+ el = "#app",
129
+ resolve = (name) => {
130
+ const pages = import_meta.glob("./pages/**/*.vue", { eager: true });
131
+ return pages[`./pages/${name}.vue`];
132
+ }
133
+ } = options;
134
+ (0, import_vue3.createInertiaApp)({
135
+ resolve,
136
+ setup({ el: element, App, props, plugin }) {
137
+ (0, import_vue.createApp)({ render: () => (0, import_vue.h)(App, props) }).use(plugin).mount(element);
138
+ }
139
+ });
140
+ }
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ createViteConfig,
144
+ initInertiaApp,
145
+ vueAdapter
146
+ });
@@ -0,0 +1,64 @@
1
+ import { UserConfig } from 'vite';
2
+ export { InitOptions, initInertiaApp } from './client/app.cjs';
3
+
4
+ /**
5
+ * Nara Request and Response minimal interfaces for the adapter
6
+ */
7
+ interface NaraRequest {
8
+ protocol: string;
9
+ get(header: string): string | undefined;
10
+ header(header: string): string | undefined;
11
+ originalUrl: string;
12
+ cookies: Record<string, any>;
13
+ [key: string]: any;
14
+ }
15
+ interface NaraResponse {
16
+ type(type: string): this;
17
+ send(body: any): any;
18
+ json(body: any): any;
19
+ setHeader(name: string, value: string): this;
20
+ status(code: number): this;
21
+ cookie(name: string, value: any, options?: any): this;
22
+ clearCookie(name: string): this;
23
+ inertia?: (component: string, props?: Record<string, any>, viewProps?: Record<string, any>) => Promise<any>;
24
+ [key: string]: any;
25
+ }
26
+ type AdapterMiddlewareHandler = (req: NaraRequest, res: NaraResponse, next: () => void) => unknown | Promise<unknown>;
27
+ interface FrontendAdapter {
28
+ name: string;
29
+ middleware: () => AdapterMiddlewareHandler;
30
+ extendResponse: (res: NaraResponse) => void;
31
+ }
32
+
33
+ interface VueAdapterOptions {
34
+ /**
35
+ * The root view template file name
36
+ * @default 'inertia.html'
37
+ */
38
+ rootView?: string;
39
+ /**
40
+ * The version of the assets
41
+ * @default '1.0.0'
42
+ */
43
+ version?: string;
44
+ }
45
+
46
+ /**
47
+ * Vue 3 adapter for Inertia.js
48
+ *
49
+ * Provides Inertia.js support for Vue 3 components.
50
+ */
51
+ declare function vueAdapter(options?: VueAdapterOptions): FrontendAdapter;
52
+
53
+ interface ViteOptions {
54
+ /**
55
+ * Options for the Vue plugin
56
+ */
57
+ vueOptions?: any;
58
+ }
59
+ /**
60
+ * Creates a Vite configuration for NARA + Vue 3
61
+ */
62
+ declare function createViteConfig(options?: ViteOptions): UserConfig;
63
+
64
+ export { type ViteOptions, type VueAdapterOptions, createViteConfig, vueAdapter };
@@ -0,0 +1,64 @@
1
+ import { UserConfig } from 'vite';
2
+ export { InitOptions, initInertiaApp } from './client/app.js';
3
+
4
+ /**
5
+ * Nara Request and Response minimal interfaces for the adapter
6
+ */
7
+ interface NaraRequest {
8
+ protocol: string;
9
+ get(header: string): string | undefined;
10
+ header(header: string): string | undefined;
11
+ originalUrl: string;
12
+ cookies: Record<string, any>;
13
+ [key: string]: any;
14
+ }
15
+ interface NaraResponse {
16
+ type(type: string): this;
17
+ send(body: any): any;
18
+ json(body: any): any;
19
+ setHeader(name: string, value: string): this;
20
+ status(code: number): this;
21
+ cookie(name: string, value: any, options?: any): this;
22
+ clearCookie(name: string): this;
23
+ inertia?: (component: string, props?: Record<string, any>, viewProps?: Record<string, any>) => Promise<any>;
24
+ [key: string]: any;
25
+ }
26
+ type AdapterMiddlewareHandler = (req: NaraRequest, res: NaraResponse, next: () => void) => unknown | Promise<unknown>;
27
+ interface FrontendAdapter {
28
+ name: string;
29
+ middleware: () => AdapterMiddlewareHandler;
30
+ extendResponse: (res: NaraResponse) => void;
31
+ }
32
+
33
+ interface VueAdapterOptions {
34
+ /**
35
+ * The root view template file name
36
+ * @default 'inertia.html'
37
+ */
38
+ rootView?: string;
39
+ /**
40
+ * The version of the assets
41
+ * @default '1.0.0'
42
+ */
43
+ version?: string;
44
+ }
45
+
46
+ /**
47
+ * Vue 3 adapter for Inertia.js
48
+ *
49
+ * Provides Inertia.js support for Vue 3 components.
50
+ */
51
+ declare function vueAdapter(options?: VueAdapterOptions): FrontendAdapter;
52
+
53
+ interface ViteOptions {
54
+ /**
55
+ * Options for the Vue plugin
56
+ */
57
+ vueOptions?: any;
58
+ }
59
+ /**
60
+ * Creates a Vite configuration for NARA + Vue 3
61
+ */
62
+ declare function createViteConfig(options?: ViteOptions): UserConfig;
63
+
64
+ export { type ViteOptions, type VueAdapterOptions, createViteConfig, vueAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ import {
2
+ initInertiaApp
3
+ } from "./chunk-ZSN4VNUJ.js";
4
+
5
+ // src/middleware.ts
6
+ function inertiaMiddleware(options = {}) {
7
+ const { rootView = "inertia.html", version = "1.0.0" } = options;
8
+ return async (req, res, next) => {
9
+ res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
10
+ const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
11
+ const props = {
12
+ user: req.user || {},
13
+ ...inertiaProps,
14
+ ...viewProps,
15
+ error: req.cookies?.error || null
16
+ };
17
+ if (req.cookies?.error) {
18
+ res.clearCookie("error");
19
+ }
20
+ const inertiaObject = {
21
+ component,
22
+ props,
23
+ url,
24
+ version
25
+ };
26
+ if (!req.header("X-Inertia")) {
27
+ try {
28
+ const viewService = await import("@services/View").catch(() => null);
29
+ if (!viewService || !viewService.view) {
30
+ throw new Error("View service unavailable");
31
+ }
32
+ const html = await viewService.view(rootView, {
33
+ page: JSON.stringify(inertiaObject),
34
+ title: process.env["TITLE"] || "Nara App"
35
+ });
36
+ return res.type("html").send(html);
37
+ } catch (e) {
38
+ return res.status(500).send("Root view not found or View service unavailable");
39
+ }
40
+ }
41
+ res.setHeader("Vary", "Accept");
42
+ res.setHeader("X-Inertia", "true");
43
+ res.setHeader("X-Inertia-Version", version);
44
+ return res.json(inertiaObject);
45
+ };
46
+ next();
47
+ };
48
+ }
49
+
50
+ // src/adapter.ts
51
+ function vueAdapter(options = {}) {
52
+ return {
53
+ name: "vue-inertia",
54
+ /**
55
+ * Factory that returns the adapter's global middleware
56
+ */
57
+ middleware: () => inertiaMiddleware(options),
58
+ /**
59
+ * Method called during app initialization to extend the NaraResponse
60
+ */
61
+ extendResponse: (_res) => {
62
+ }
63
+ };
64
+ }
65
+
66
+ // src/vite.ts
67
+ import vue from "@vitejs/plugin-vue";
68
+ function createViteConfig(options = {}) {
69
+ return {
70
+ plugins: [
71
+ vue(options.vueOptions)
72
+ ],
73
+ resolve: {
74
+ alias: {
75
+ "@": "/resources/js"
76
+ }
77
+ },
78
+ build: {
79
+ outDir: "public/build",
80
+ manifest: true,
81
+ rollupOptions: {
82
+ input: "resources/js/app.ts"
83
+ }
84
+ }
85
+ };
86
+ }
87
+ export {
88
+ createViteConfig,
89
+ initInertiaApp,
90
+ vueAdapter
91
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@nara-web/inertia-vue",
3
+ "version": "0.1.0",
4
+ "description": "Vue 3 + Inertia.js adapter for NARA",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "typecheck": "tsc --noEmit"
29
+ },
30
+ "dependencies": {
31
+ "@inertiajs/vue3": "^2.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@nara-web/core": "^0.1.0",
35
+ "vue": "^3.5.0",
36
+ "vite": "^5.0.0 || ^6.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@nara-web/core": "^0.1.0",
40
+ "@vitejs/plugin-vue": "^5.2.1",
41
+ "tsup": "^8.3.5",
42
+ "typescript": "^5.7.3",
43
+ "vue": "^3.5.13"
44
+ },
45
+ "license": "MIT"
46
+ }