@dudousxd/nestjs-inertia-client 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.
- package/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/README.md +274 -0
- package/dist/index.cjs +294 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +175 -0
- package/dist/index.d.ts +175 -0
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +68 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +26 -0
- package/dist/react/index.d.ts +26 -0
- package/dist/react/index.js +41 -0
- package/dist/react/index.js.map +1 -0
- package/dist/ssr/hydrate.cjs +50 -0
- package/dist/ssr/hydrate.cjs.map +1 -0
- package/dist/ssr/hydrate.d.cts +21 -0
- package/dist/ssr/hydrate.d.ts +21 -0
- package/dist/ssr/hydrate.js +26 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/svelte/Link.svelte +25 -0
- package/dist/svelte/index.cjs +101 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.cts +21 -0
- package/dist/svelte/index.d.ts +21 -0
- package/dist/svelte/index.js +64 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/index.cjs +101 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.cts +73 -0
- package/dist/vue/index.d.ts +73 -0
- package/dist/vue/index.js +73 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +118 -0
- package/src/svelte/Link.svelte +25 -0
|
@@ -0,0 +1,101 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/vue/index.ts
|
|
22
|
+
var vue_exports = {};
|
|
23
|
+
__export(vue_exports, {
|
|
24
|
+
INERTIA_ROUTES_KEY: () => INERTIA_ROUTES_KEY,
|
|
25
|
+
Link: () => Link,
|
|
26
|
+
provideInertiaRoutes: () => provideInertiaRoutes,
|
|
27
|
+
useInertiaRoutes: () => useInertiaRoutes
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(vue_exports);
|
|
30
|
+
|
|
31
|
+
// src/vue/link.ts
|
|
32
|
+
var import_vue3 = require("@inertiajs/vue3");
|
|
33
|
+
var import_vue2 = require("vue");
|
|
34
|
+
|
|
35
|
+
// src/vue/provider.ts
|
|
36
|
+
var import_vue = require("vue");
|
|
37
|
+
var INERTIA_ROUTES_KEY = /* @__PURE__ */ Symbol("inertia-routes");
|
|
38
|
+
function provideInertiaRoutes(resolver) {
|
|
39
|
+
(0, import_vue.provide)(INERTIA_ROUTES_KEY, resolver);
|
|
40
|
+
}
|
|
41
|
+
__name(provideInertiaRoutes, "provideInertiaRoutes");
|
|
42
|
+
function useInertiaRoutes() {
|
|
43
|
+
const resolver = (0, import_vue.inject)(INERTIA_ROUTES_KEY);
|
|
44
|
+
if (!resolver) {
|
|
45
|
+
throw new Error("@dudousxd/nestjs-inertia-client: provideInertiaRoutes() not called.\n\nCall provideInertiaRoutes(route) in your app setup:\n\n import { provideInertiaRoutes } from '@dudousxd/nestjs-inertia-client/vue';\n import { route } from './.nestjs-inertia/routes.js';\n\n setup({ el, App, props, plugin }) {\n const app = createApp(...);\n provideInertiaRoutes(route); // before mount\n app.mount(el);\n }");
|
|
46
|
+
}
|
|
47
|
+
return resolver;
|
|
48
|
+
}
|
|
49
|
+
__name(useInertiaRoutes, "useInertiaRoutes");
|
|
50
|
+
|
|
51
|
+
// src/vue/link.ts
|
|
52
|
+
var Link = (0, import_vue2.defineComponent)({
|
|
53
|
+
name: "InertiaTypedLink",
|
|
54
|
+
props: {
|
|
55
|
+
route: {
|
|
56
|
+
type: String,
|
|
57
|
+
required: true
|
|
58
|
+
},
|
|
59
|
+
routeParams: {
|
|
60
|
+
type: Object,
|
|
61
|
+
default: void 0
|
|
62
|
+
},
|
|
63
|
+
query: {
|
|
64
|
+
type: Object,
|
|
65
|
+
default: void 0
|
|
66
|
+
},
|
|
67
|
+
class: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: void 0
|
|
70
|
+
},
|
|
71
|
+
method: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: void 0
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
setup(props, { slots, attrs }) {
|
|
77
|
+
const resolveRoute = useInertiaRoutes();
|
|
78
|
+
return () => {
|
|
79
|
+
const href = resolveRoute(props.route, props.routeParams, props.query);
|
|
80
|
+
const linkProps = {
|
|
81
|
+
href,
|
|
82
|
+
...attrs
|
|
83
|
+
};
|
|
84
|
+
if (props.class) {
|
|
85
|
+
linkProps.class = props.class;
|
|
86
|
+
}
|
|
87
|
+
if (props.method) {
|
|
88
|
+
linkProps.method = props.method;
|
|
89
|
+
}
|
|
90
|
+
return (0, import_vue2.h)(import_vue3.Link, linkProps, slots);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
INERTIA_ROUTES_KEY,
|
|
97
|
+
Link,
|
|
98
|
+
provideInertiaRoutes,
|
|
99
|
+
useInertiaRoutes
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/vue/index.ts","../../src/vue/link.ts","../../src/vue/provider.ts"],"sourcesContent":["export { Link } from './link.js';\nexport type { LinkProps } from './link.js';\nexport { provideInertiaRoutes, useInertiaRoutes, INERTIA_ROUTES_KEY } from './provider.js';\n","import type { RegistryRoutes } from '@dudousxd/nestjs-inertia';\nimport { Link as InertiaLink } from '@inertiajs/vue3';\nimport { defineComponent, h } from 'vue';\nimport type { PropType } from 'vue';\nimport { useInertiaRoutes } from './provider.js';\n\ntype AnyRoutes = RegistryRoutes;\n\n// Conditional type helpers mirroring the React Link:\n// routeParams is required when the route has path params, optional otherwise.\ntype RoutePropsFor<K extends keyof AnyRoutes> = AnyRoutes[K] extends\n | Record<string, never>\n | undefined\n ? { routeParams?: never }\n : { routeParams: AnyRoutes[K] };\n\nexport type LinkProps<K extends keyof AnyRoutes> = {\n route: K;\n query?: Record<string, unknown>;\n class?: string;\n method?: string;\n} & RoutePropsFor<K>;\n\nexport const Link = defineComponent({\n name: 'InertiaTypedLink',\n props: {\n route: {\n type: String as PropType<keyof AnyRoutes & string>,\n required: true,\n },\n routeParams: {\n type: Object as PropType<Record<string, unknown>>,\n default: undefined,\n },\n query: {\n type: Object as PropType<Record<string, unknown>>,\n default: undefined,\n },\n class: {\n type: String,\n default: undefined,\n },\n method: {\n type: String,\n default: undefined,\n },\n },\n setup(props, { slots, attrs }) {\n const resolveRoute = useInertiaRoutes();\n return () => {\n const href = resolveRoute(\n props.route,\n props.routeParams as Record<string, unknown> | undefined,\n props.query,\n );\n\n const linkProps: Record<string, unknown> = {\n href,\n ...attrs,\n };\n\n if (props.class) {\n linkProps.class = props.class;\n }\n\n if (props.method) {\n linkProps.method = props.method;\n }\n\n return h(InertiaLink, linkProps, slots);\n };\n },\n});\n","import { type InjectionKey, inject, provide } from 'vue';\n\ntype RouteResolver = (\n name: string,\n params?: Record<string, unknown>,\n query?: Record<string, unknown>,\n) => string;\n\nexport const INERTIA_ROUTES_KEY: InjectionKey<RouteResolver> = Symbol('inertia-routes');\n\nexport function provideInertiaRoutes(resolver: RouteResolver): void {\n provide(INERTIA_ROUTES_KEY, resolver);\n}\n\nexport function useInertiaRoutes(): RouteResolver {\n const resolver = inject(INERTIA_ROUTES_KEY);\n if (!resolver) {\n throw new Error(\n '@dudousxd/nestjs-inertia-client: provideInertiaRoutes() not called.\\n\\n' +\n 'Call provideInertiaRoutes(route) in your app setup:\\n\\n' +\n \" import { provideInertiaRoutes } from '@dudousxd/nestjs-inertia-client/vue';\\n\" +\n \" import { route } from './.nestjs-inertia/routes.js';\\n\\n\" +\n ' setup({ el, App, props, plugin }) {\\n' +\n ' const app = createApp(...);\\n' +\n ' provideInertiaRoutes(route); // before mount\\n' +\n ' app.mount(el);\\n' +\n ' }',\n );\n }\n return resolver;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACCA,kBAAoC;AACpC,IAAAA,cAAmC;;;ACFnC,iBAAmD;AAQ5C,IAAMC,qBAAkDC,uBAAO,gBAAA;AAE/D,SAASC,qBAAqBC,UAAuB;AAC1DC,0BAAQJ,oBAAoBG,QAAAA;AAC9B;AAFgBD;AAIT,SAASG,mBAAAA;AACd,QAAMF,eAAWG,mBAAON,kBAAAA;AACxB,MAAI,CAACG,UAAU;AACb,UAAM,IAAII,MACR,0ZAQE;EAEN;AACA,SAAOJ;AACT;AAhBgBE;;;ADST,IAAMG,WAAOC,6BAAgB;EAClCC,MAAM;EACNC,OAAO;IACLC,OAAO;MACLC,MAAMC;MACNC,UAAU;IACZ;IACAC,aAAa;MACXH,MAAMI;MACNC,SAASC;IACX;IACAC,OAAO;MACLP,MAAMI;MACNC,SAASC;IACX;IACAE,OAAO;MACLR,MAAMC;MACNI,SAASC;IACX;IACAG,QAAQ;MACNT,MAAMC;MACNI,SAASC;IACX;EACF;EACAI,MAAMZ,OAAO,EAAEa,OAAOC,MAAK,GAAE;AAC3B,UAAMC,eAAeC,iBAAAA;AACrB,WAAO,MAAA;AACL,YAAMC,OAAOF,aACXf,MAAMC,OACND,MAAMK,aACNL,MAAMS,KAAK;AAGb,YAAMS,YAAqC;QACzCD;QACA,GAAGH;MACL;AAEA,UAAId,MAAMU,OAAO;AACfQ,kBAAUR,QAAQV,MAAMU;MAC1B;AAEA,UAAIV,MAAMW,QAAQ;AAChBO,kBAAUP,SAASX,MAAMW;MAC3B;AAEA,iBAAOQ,eAAEC,YAAAA,MAAaF,WAAWL,KAAAA;IACnC;EACF;AACF,CAAA;","names":["import_vue","INERTIA_ROUTES_KEY","Symbol","provideInertiaRoutes","resolver","provide","useInertiaRoutes","inject","Error","Link","defineComponent","name","props","route","type","String","required","routeParams","Object","default","undefined","query","class","method","setup","slots","attrs","resolveRoute","useInertiaRoutes","href","linkProps","h","InertiaLink"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType, InjectionKey } from 'vue';
|
|
3
|
+
import { RegistryRoutes } from '@dudousxd/nestjs-inertia';
|
|
4
|
+
|
|
5
|
+
type AnyRoutes = RegistryRoutes;
|
|
6
|
+
type RoutePropsFor<K extends keyof AnyRoutes> = AnyRoutes[K] extends Record<string, never> | undefined ? {
|
|
7
|
+
routeParams?: never;
|
|
8
|
+
} : {
|
|
9
|
+
routeParams: AnyRoutes[K];
|
|
10
|
+
};
|
|
11
|
+
type LinkProps<K extends keyof AnyRoutes> = {
|
|
12
|
+
route: K;
|
|
13
|
+
query?: Record<string, unknown>;
|
|
14
|
+
class?: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
} & RoutePropsFor<K>;
|
|
17
|
+
declare const Link: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
18
|
+
route: {
|
|
19
|
+
type: PropType<keyof AnyRoutes & string>;
|
|
20
|
+
required: true;
|
|
21
|
+
};
|
|
22
|
+
routeParams: {
|
|
23
|
+
type: PropType<Record<string, unknown>>;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
query: {
|
|
27
|
+
type: PropType<Record<string, unknown>>;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
class: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
default: undefined;
|
|
33
|
+
};
|
|
34
|
+
method: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
41
|
+
route: {
|
|
42
|
+
type: PropType<keyof AnyRoutes & string>;
|
|
43
|
+
required: true;
|
|
44
|
+
};
|
|
45
|
+
routeParams: {
|
|
46
|
+
type: PropType<Record<string, unknown>>;
|
|
47
|
+
default: undefined;
|
|
48
|
+
};
|
|
49
|
+
query: {
|
|
50
|
+
type: PropType<Record<string, unknown>>;
|
|
51
|
+
default: undefined;
|
|
52
|
+
};
|
|
53
|
+
class: {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
default: undefined;
|
|
56
|
+
};
|
|
57
|
+
method: {
|
|
58
|
+
type: StringConstructor;
|
|
59
|
+
default: undefined;
|
|
60
|
+
};
|
|
61
|
+
}>> & Readonly<{}>, {
|
|
62
|
+
routeParams: Record<string, unknown>;
|
|
63
|
+
query: Record<string, unknown>;
|
|
64
|
+
class: string;
|
|
65
|
+
method: string;
|
|
66
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
67
|
+
|
|
68
|
+
type RouteResolver = (name: string, params?: Record<string, unknown>, query?: Record<string, unknown>) => string;
|
|
69
|
+
declare const INERTIA_ROUTES_KEY: InjectionKey<RouteResolver>;
|
|
70
|
+
declare function provideInertiaRoutes(resolver: RouteResolver): void;
|
|
71
|
+
declare function useInertiaRoutes(): RouteResolver;
|
|
72
|
+
|
|
73
|
+
export { INERTIA_ROUTES_KEY, Link, type LinkProps, provideInertiaRoutes, useInertiaRoutes };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType, InjectionKey } from 'vue';
|
|
3
|
+
import { RegistryRoutes } from '@dudousxd/nestjs-inertia';
|
|
4
|
+
|
|
5
|
+
type AnyRoutes = RegistryRoutes;
|
|
6
|
+
type RoutePropsFor<K extends keyof AnyRoutes> = AnyRoutes[K] extends Record<string, never> | undefined ? {
|
|
7
|
+
routeParams?: never;
|
|
8
|
+
} : {
|
|
9
|
+
routeParams: AnyRoutes[K];
|
|
10
|
+
};
|
|
11
|
+
type LinkProps<K extends keyof AnyRoutes> = {
|
|
12
|
+
route: K;
|
|
13
|
+
query?: Record<string, unknown>;
|
|
14
|
+
class?: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
} & RoutePropsFor<K>;
|
|
17
|
+
declare const Link: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
18
|
+
route: {
|
|
19
|
+
type: PropType<keyof AnyRoutes & string>;
|
|
20
|
+
required: true;
|
|
21
|
+
};
|
|
22
|
+
routeParams: {
|
|
23
|
+
type: PropType<Record<string, unknown>>;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
query: {
|
|
27
|
+
type: PropType<Record<string, unknown>>;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
class: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
default: undefined;
|
|
33
|
+
};
|
|
34
|
+
method: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
41
|
+
route: {
|
|
42
|
+
type: PropType<keyof AnyRoutes & string>;
|
|
43
|
+
required: true;
|
|
44
|
+
};
|
|
45
|
+
routeParams: {
|
|
46
|
+
type: PropType<Record<string, unknown>>;
|
|
47
|
+
default: undefined;
|
|
48
|
+
};
|
|
49
|
+
query: {
|
|
50
|
+
type: PropType<Record<string, unknown>>;
|
|
51
|
+
default: undefined;
|
|
52
|
+
};
|
|
53
|
+
class: {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
default: undefined;
|
|
56
|
+
};
|
|
57
|
+
method: {
|
|
58
|
+
type: StringConstructor;
|
|
59
|
+
default: undefined;
|
|
60
|
+
};
|
|
61
|
+
}>> & Readonly<{}>, {
|
|
62
|
+
routeParams: Record<string, unknown>;
|
|
63
|
+
query: Record<string, unknown>;
|
|
64
|
+
class: string;
|
|
65
|
+
method: string;
|
|
66
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
67
|
+
|
|
68
|
+
type RouteResolver = (name: string, params?: Record<string, unknown>, query?: Record<string, unknown>) => string;
|
|
69
|
+
declare const INERTIA_ROUTES_KEY: InjectionKey<RouteResolver>;
|
|
70
|
+
declare function provideInertiaRoutes(resolver: RouteResolver): void;
|
|
71
|
+
declare function useInertiaRoutes(): RouteResolver;
|
|
72
|
+
|
|
73
|
+
export { INERTIA_ROUTES_KEY, Link, type LinkProps, provideInertiaRoutes, useInertiaRoutes };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/vue/link.ts
|
|
5
|
+
import { Link as InertiaLink } from "@inertiajs/vue3";
|
|
6
|
+
import { defineComponent, h } from "vue";
|
|
7
|
+
|
|
8
|
+
// src/vue/provider.ts
|
|
9
|
+
import { inject, provide } from "vue";
|
|
10
|
+
var INERTIA_ROUTES_KEY = /* @__PURE__ */ Symbol("inertia-routes");
|
|
11
|
+
function provideInertiaRoutes(resolver) {
|
|
12
|
+
provide(INERTIA_ROUTES_KEY, resolver);
|
|
13
|
+
}
|
|
14
|
+
__name(provideInertiaRoutes, "provideInertiaRoutes");
|
|
15
|
+
function useInertiaRoutes() {
|
|
16
|
+
const resolver = inject(INERTIA_ROUTES_KEY);
|
|
17
|
+
if (!resolver) {
|
|
18
|
+
throw new Error("@dudousxd/nestjs-inertia-client: provideInertiaRoutes() not called.\n\nCall provideInertiaRoutes(route) in your app setup:\n\n import { provideInertiaRoutes } from '@dudousxd/nestjs-inertia-client/vue';\n import { route } from './.nestjs-inertia/routes.js';\n\n setup({ el, App, props, plugin }) {\n const app = createApp(...);\n provideInertiaRoutes(route); // before mount\n app.mount(el);\n }");
|
|
19
|
+
}
|
|
20
|
+
return resolver;
|
|
21
|
+
}
|
|
22
|
+
__name(useInertiaRoutes, "useInertiaRoutes");
|
|
23
|
+
|
|
24
|
+
// src/vue/link.ts
|
|
25
|
+
var Link = defineComponent({
|
|
26
|
+
name: "InertiaTypedLink",
|
|
27
|
+
props: {
|
|
28
|
+
route: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
routeParams: {
|
|
33
|
+
type: Object,
|
|
34
|
+
default: void 0
|
|
35
|
+
},
|
|
36
|
+
query: {
|
|
37
|
+
type: Object,
|
|
38
|
+
default: void 0
|
|
39
|
+
},
|
|
40
|
+
class: {
|
|
41
|
+
type: String,
|
|
42
|
+
default: void 0
|
|
43
|
+
},
|
|
44
|
+
method: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: void 0
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
setup(props, { slots, attrs }) {
|
|
50
|
+
const resolveRoute = useInertiaRoutes();
|
|
51
|
+
return () => {
|
|
52
|
+
const href = resolveRoute(props.route, props.routeParams, props.query);
|
|
53
|
+
const linkProps = {
|
|
54
|
+
href,
|
|
55
|
+
...attrs
|
|
56
|
+
};
|
|
57
|
+
if (props.class) {
|
|
58
|
+
linkProps.class = props.class;
|
|
59
|
+
}
|
|
60
|
+
if (props.method) {
|
|
61
|
+
linkProps.method = props.method;
|
|
62
|
+
}
|
|
63
|
+
return h(InertiaLink, linkProps, slots);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
export {
|
|
68
|
+
INERTIA_ROUTES_KEY,
|
|
69
|
+
Link,
|
|
70
|
+
provideInertiaRoutes,
|
|
71
|
+
useInertiaRoutes
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/vue/link.ts","../../src/vue/provider.ts"],"sourcesContent":["import type { RegistryRoutes } from '@dudousxd/nestjs-inertia';\nimport { Link as InertiaLink } from '@inertiajs/vue3';\nimport { defineComponent, h } from 'vue';\nimport type { PropType } from 'vue';\nimport { useInertiaRoutes } from './provider.js';\n\ntype AnyRoutes = RegistryRoutes;\n\n// Conditional type helpers mirroring the React Link:\n// routeParams is required when the route has path params, optional otherwise.\ntype RoutePropsFor<K extends keyof AnyRoutes> = AnyRoutes[K] extends\n | Record<string, never>\n | undefined\n ? { routeParams?: never }\n : { routeParams: AnyRoutes[K] };\n\nexport type LinkProps<K extends keyof AnyRoutes> = {\n route: K;\n query?: Record<string, unknown>;\n class?: string;\n method?: string;\n} & RoutePropsFor<K>;\n\nexport const Link = defineComponent({\n name: 'InertiaTypedLink',\n props: {\n route: {\n type: String as PropType<keyof AnyRoutes & string>,\n required: true,\n },\n routeParams: {\n type: Object as PropType<Record<string, unknown>>,\n default: undefined,\n },\n query: {\n type: Object as PropType<Record<string, unknown>>,\n default: undefined,\n },\n class: {\n type: String,\n default: undefined,\n },\n method: {\n type: String,\n default: undefined,\n },\n },\n setup(props, { slots, attrs }) {\n const resolveRoute = useInertiaRoutes();\n return () => {\n const href = resolveRoute(\n props.route,\n props.routeParams as Record<string, unknown> | undefined,\n props.query,\n );\n\n const linkProps: Record<string, unknown> = {\n href,\n ...attrs,\n };\n\n if (props.class) {\n linkProps.class = props.class;\n }\n\n if (props.method) {\n linkProps.method = props.method;\n }\n\n return h(InertiaLink, linkProps, slots);\n };\n },\n});\n","import { type InjectionKey, inject, provide } from 'vue';\n\ntype RouteResolver = (\n name: string,\n params?: Record<string, unknown>,\n query?: Record<string, unknown>,\n) => string;\n\nexport const INERTIA_ROUTES_KEY: InjectionKey<RouteResolver> = Symbol('inertia-routes');\n\nexport function provideInertiaRoutes(resolver: RouteResolver): void {\n provide(INERTIA_ROUTES_KEY, resolver);\n}\n\nexport function useInertiaRoutes(): RouteResolver {\n const resolver = inject(INERTIA_ROUTES_KEY);\n if (!resolver) {\n throw new Error(\n '@dudousxd/nestjs-inertia-client: provideInertiaRoutes() not called.\\n\\n' +\n 'Call provideInertiaRoutes(route) in your app setup:\\n\\n' +\n \" import { provideInertiaRoutes } from '@dudousxd/nestjs-inertia-client/vue';\\n\" +\n \" import { route } from './.nestjs-inertia/routes.js';\\n\\n\" +\n ' setup({ el, App, props, plugin }) {\\n' +\n ' const app = createApp(...);\\n' +\n ' provideInertiaRoutes(route); // before mount\\n' +\n ' app.mount(el);\\n' +\n ' }',\n );\n }\n return resolver;\n}\n"],"mappings":";;;;AACA,SAASA,QAAQC,mBAAmB;AACpC,SAASC,iBAAiBC,SAAS;;;ACFnC,SAA4BC,QAAQC,eAAe;AAQ5C,IAAMC,qBAAkDC,uBAAO,gBAAA;AAE/D,SAASC,qBAAqBC,UAAuB;AAC1DC,UAAQJ,oBAAoBG,QAAAA;AAC9B;AAFgBD;AAIT,SAASG,mBAAAA;AACd,QAAMF,WAAWG,OAAON,kBAAAA;AACxB,MAAI,CAACG,UAAU;AACb,UAAM,IAAII,MACR,0ZAQE;EAEN;AACA,SAAOJ;AACT;AAhBgBE;;;ADST,IAAMG,OAAOC,gBAAgB;EAClCC,MAAM;EACNC,OAAO;IACLC,OAAO;MACLC,MAAMC;MACNC,UAAU;IACZ;IACAC,aAAa;MACXH,MAAMI;MACNC,SAASC;IACX;IACAC,OAAO;MACLP,MAAMI;MACNC,SAASC;IACX;IACAE,OAAO;MACLR,MAAMC;MACNI,SAASC;IACX;IACAG,QAAQ;MACNT,MAAMC;MACNI,SAASC;IACX;EACF;EACAI,MAAMZ,OAAO,EAAEa,OAAOC,MAAK,GAAE;AAC3B,UAAMC,eAAeC,iBAAAA;AACrB,WAAO,MAAA;AACL,YAAMC,OAAOF,aACXf,MAAMC,OACND,MAAMK,aACNL,MAAMS,KAAK;AAGb,YAAMS,YAAqC;QACzCD;QACA,GAAGH;MACL;AAEA,UAAId,MAAMU,OAAO;AACfQ,kBAAUR,QAAQV,MAAMU;MAC1B;AAEA,UAAIV,MAAMW,QAAQ;AAChBO,kBAAUP,SAASX,MAAMW;MAC3B;AAEA,aAAOQ,EAAEC,aAAaF,WAAWL,KAAAA;IACnC;EACF;AACF,CAAA;","names":["Link","InertiaLink","defineComponent","h","inject","provide","INERTIA_ROUTES_KEY","Symbol","provideInertiaRoutes","resolver","provide","useInertiaRoutes","inject","Error","Link","defineComponent","name","props","route","type","String","required","routeParams","Object","default","undefined","query","class","method","setup","slots","attrs","resolveRoute","useInertiaRoutes","href","linkProps","h","InertiaLink"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dudousxd/nestjs-inertia-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Tuyau-style typed HTTP client for @dudousxd/nestjs-inertia, built on TanStack Query v5 core.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/DavideCarvalho/nestjs-inertia.git",
|
|
9
|
+
"directory": "packages/client"
|
|
10
|
+
},
|
|
11
|
+
"author": "Davi Carvalho <davi@goflip.ai>",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./ssr": {
|
|
23
|
+
"types": "./dist/ssr/hydrate.d.ts",
|
|
24
|
+
"import": "./dist/ssr/hydrate.js",
|
|
25
|
+
"require": "./dist/ssr/hydrate.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./react": {
|
|
28
|
+
"types": "./dist/react/index.d.ts",
|
|
29
|
+
"import": "./dist/react/index.js",
|
|
30
|
+
"require": "./dist/react/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./vue": {
|
|
33
|
+
"types": "./dist/vue/index.d.ts",
|
|
34
|
+
"import": "./dist/vue/index.js",
|
|
35
|
+
"require": "./dist/vue/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./svelte": {
|
|
38
|
+
"types": "./dist/svelte/index.d.ts",
|
|
39
|
+
"svelte": "./dist/svelte/index.js",
|
|
40
|
+
"import": "./dist/svelte/index.js",
|
|
41
|
+
"require": "./dist/svelte/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"src/svelte/Link.svelte",
|
|
47
|
+
"README.md",
|
|
48
|
+
"CHANGELOG.md"
|
|
49
|
+
],
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@inertiajs/react": "^2.0.0 || ^3.0.0",
|
|
52
|
+
"@inertiajs/vue3": "^2.0.0 || ^3.0.0",
|
|
53
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
54
|
+
"@tanstack/query-core": "^5.0.0",
|
|
55
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
56
|
+
"vue": "^3.4.0",
|
|
57
|
+
"@inertiajs/svelte": "^3.0.0",
|
|
58
|
+
"svelte": "^5.0.0",
|
|
59
|
+
"zod": "^3.22.0",
|
|
60
|
+
"@dudousxd/nestjs-inertia": "1.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@inertiajs/react": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"react": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@inertiajs/vue3": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"vue": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@inertiajs/svelte": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"svelte": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@inertiajs/react": "^3.0.0",
|
|
84
|
+
"@nestjs/common": "^11.0.0",
|
|
85
|
+
"@tanstack/query-core": "^5.51.0",
|
|
86
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
87
|
+
"@testing-library/react": "^16.3.2",
|
|
88
|
+
"@types/node": "^20.0.0",
|
|
89
|
+
"@types/react": "^19.0.0",
|
|
90
|
+
"@types/react-dom": "^19.0.0",
|
|
91
|
+
"@vitejs/plugin-react": "^4.3.0",
|
|
92
|
+
"jsdom": "^29.1.1",
|
|
93
|
+
"react": "^19.0.0",
|
|
94
|
+
"react-dom": "^19.0.0",
|
|
95
|
+
"reflect-metadata": "^0.2.0",
|
|
96
|
+
"typescript": "^5.4.0",
|
|
97
|
+
"@inertiajs/vue3": "^3.0.0",
|
|
98
|
+
"@vue/test-utils": "^2.4.0",
|
|
99
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
100
|
+
"vue": "^3.5.0",
|
|
101
|
+
"@inertiajs/svelte": "^3.2.0",
|
|
102
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
103
|
+
"@testing-library/svelte": "^5.3.1",
|
|
104
|
+
"svelte": "^5.55.9",
|
|
105
|
+
"vitest": "^3.0.0",
|
|
106
|
+
"zod": "^3.23.0",
|
|
107
|
+
"@dudousxd/nestjs-inertia": "1.0.0"
|
|
108
|
+
},
|
|
109
|
+
"engines": {
|
|
110
|
+
"node": ">=20"
|
|
111
|
+
},
|
|
112
|
+
"scripts": {
|
|
113
|
+
"build": "tsup && cp src/svelte/Link.svelte dist/svelte/Link.svelte",
|
|
114
|
+
"test": "vitest run",
|
|
115
|
+
"test:watch": "vitest",
|
|
116
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script lang="ts" generics="K extends keyof import('@dudousxd/nestjs-inertia').InertiaRegistry['routes'] & string">
|
|
2
|
+
import { Link as InertiaLink } from '@inertiajs/svelte';
|
|
3
|
+
import type { RegistryRoutes } from '@dudousxd/nestjs-inertia';
|
|
4
|
+
import { useInertiaRoutes } from './provider.js';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
|
|
7
|
+
type Routes = RegistryRoutes;
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
route: K;
|
|
11
|
+
routeParams?: Routes[K];
|
|
12
|
+
query?: Record<string, unknown>;
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { route, routeParams = undefined, query = undefined, children, ...rest }: Props = $props();
|
|
18
|
+
|
|
19
|
+
const resolveRoute = useInertiaRoutes();
|
|
20
|
+
const href = $derived(resolveRoute(route, routeParams as never, query));
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<InertiaLink {href} {...rest}>
|
|
24
|
+
{@render children?.()}
|
|
25
|
+
</InertiaLink>
|