@adonisjs/inertia 1.0.0-8 → 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.
Files changed (46) hide show
  1. package/README.md +3 -3
  2. package/build/app.css.stub +1 -1
  3. package/build/{chunk-CXICUKHN.js → chunk-QKSM72AR.js} +59 -23
  4. package/build/config.stub +10 -2
  5. package/build/index.d.ts +7 -3
  6. package/build/index.js +140 -38
  7. package/build/providers/inertia_provider.d.ts +15 -1
  8. package/build/providers/inertia_provider.js +13 -2
  9. package/build/react/app.tsx.stub +19 -6
  10. package/build/react/errors/not_found.tsx.stub +14 -0
  11. package/build/react/errors/server_error.tsx.stub +14 -0
  12. package/build/react/home.tsx.stub +2 -2
  13. package/build/react/root.edge.stub +2 -2
  14. package/build/react/ssr.tsx.stub +17 -0
  15. package/build/react/tsconfig.json.stub +5 -15
  16. package/build/solid/app.tsx.stub +19 -5
  17. package/build/solid/errors/not_found.tsx.stub +14 -0
  18. package/build/solid/errors/server_error.tsx.stub +14 -0
  19. package/build/solid/home.tsx.stub +2 -5
  20. package/build/solid/root.edge.stub +2 -2
  21. package/build/solid/ssr.tsx.stub +19 -0
  22. package/build/solid/tsconfig.json.stub +6 -16
  23. package/build/src/helpers.d.ts +12 -0
  24. package/build/src/helpers.js +14 -0
  25. package/build/src/inertia_middleware.d.ts +5 -51
  26. package/build/src/inertia_middleware.js +1 -1
  27. package/build/src/plugins/japa/api_client.d.ts +3 -1
  28. package/build/src/plugins/vite.d.ts +1 -1
  29. package/build/src/plugins/vite.js +5 -2
  30. package/build/src/types.d.ts +5 -96
  31. package/build/svelte/app.ts.stub +33 -0
  32. package/build/svelte/errors/not_found.svelte.stub +10 -0
  33. package/build/svelte/errors/server_error.svelte.stub +14 -0
  34. package/build/svelte/home.svelte.stub +19 -0
  35. package/build/svelte/root.edge.stub +21 -0
  36. package/build/svelte/ssr.ts.stub +15 -0
  37. package/build/svelte/tsconfig.json.stub +14 -0
  38. package/build/types-fb05P61I.d.ts +203 -0
  39. package/build/vue/app.ts.stub +18 -4
  40. package/build/vue/errors/not_found.vue.stub +10 -0
  41. package/build/vue/errors/server_error.vue.stub +14 -0
  42. package/build/vue/home.vue.stub +4 -4
  43. package/build/vue/root.edge.stub +2 -2
  44. package/build/vue/ssr.ts.stub +22 -0
  45. package/build/vue/tsconfig.json.stub +5 -15
  46. package/package.json +51 -41
@@ -0,0 +1,17 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/app/ssr.tsx') })
3
+ }}}
4
+ import ReactDOMServer from 'react-dom/server'
5
+ import { createInertiaApp } from '@inertiajs/react'
6
+
7
+ export default function render(page: any) {
8
+ return createInertiaApp({
9
+ page,
10
+ render: ReactDOMServer.renderToString,
11
+ resolve: (name) => {
12
+ const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
13
+ {{ 'return pages[`../pages/${name}.tsx`]' }}
14
+ },
15
+ setup: ({ App, props }) => <App {...props} />,
16
+ })
17
+ }
@@ -1,25 +1,15 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/tsconfig.json') })
2
+ exports({ to: app.makePath('inertia/tsconfig.json') })
3
3
  }}}
4
4
  {
5
+ "extends": "@adonisjs/tsconfig/tsconfig.client.json",
5
6
  "compilerOptions": {
6
- "target": "ESNext",
7
- "jsx": "react-jsx",
8
- "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
9
- "useDefineForClassFields": true,
10
7
  "baseUrl": ".",
11
8
  "module": "ESNext",
12
- "moduleResolution": "Bundler",
9
+ "jsx": "react-jsx",
13
10
  "paths": {
14
- "@/*": ["./*"],
15
- "~/*": ["../*"],
11
+ "~/*": ["./*"],
16
12
  },
17
- "resolveJsonModule": true,
18
- "types": ["vite/client"],
19
- "allowSyntheticDefaultImports": true,
20
- "esModuleInterop": true,
21
- "verbatimModuleSyntax": true,
22
- "skipLibCheck": true,
23
13
  },
24
- "include": ["./**/*.ts", "./**/*.tsx", "app.tsx.stub"],
14
+ "include": ["./**/*.ts", "./**/*.tsx"],
25
15
  }
@@ -1,10 +1,18 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/app.tsx') })
2
+ exports({ to: app.makePath('inertia/app/app.tsx') })
3
3
  }}}
4
- import './css/app.css'
4
+ /// <reference path="../../adonisrc.ts" />
5
+ /// <reference path="../../config/inertia.ts" />
5
6
 
7
+ import '../css/app.css'
8
+
9
+ {{#if ssr}}
10
+ import { hydrate } from 'solid-js/web';
11
+ {{#else}}
6
12
  import { render } from 'solid-js/web'
13
+ {{/if}}
7
14
  import { createInertiaApp } from 'inertia-adapter-solid'
15
+ import { resolvePageComponent } from '@adonisjs/inertia/helpers'
8
16
 
9
17
  const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
10
18
 
@@ -13,12 +21,18 @@ createInertiaApp({
13
21
 
14
22
  title: (title) => {{ '`${title} - ${appName}`' }},
15
23
 
16
- resolve(name) {
17
- const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
18
- {{ 'return pages[`./pages/${name}.tsx`]' }}
24
+ resolve: (name) => {
25
+ return resolvePageComponent(
26
+ {{ '`../pages/${name}.tsx`' }},
27
+ import.meta.glob('../pages/**/*.tsx'),
28
+ )
19
29
  },
20
30
 
21
31
  setup({ el, App, props }) {
32
+ {{#if ssr}}
33
+ hydrate(() => <App {...props} />, el)
34
+ {{#else}}
22
35
  render(() => <App {...props} />, el)
36
+ {{/if}}
23
37
  },
24
38
  })
@@ -0,0 +1,14 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/not_found.tsx') })
3
+ }}}
4
+ export default function NotFound() {
5
+ return (
6
+ <>
7
+ <div class="container">
8
+ <div class="title">Page not found</div>
9
+
10
+ <span>This page does not exist.</span>
11
+ </div>
12
+ </>
13
+ )
14
+ }
@@ -0,0 +1,14 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/server_error.tsx') })
3
+ }}}
4
+ export default function ServerError(props: { error: any }) {
5
+ return (
6
+ <>
7
+ <div class="container">
8
+ <div class="title">Server Error</div>
9
+
10
+ <span>{props.error.message}</span>
11
+ </div>
12
+ </>
13
+ )
14
+ }
@@ -1,19 +1,16 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/pages/home.tsx') })
2
+ exports({ to: app.makePath('inertia/pages/home.tsx') })
3
3
  }}}
4
- import { Title } from '@solidjs/meta'
5
4
 
6
5
  export default function Home(props: { version: number }) {
7
6
  return (
8
7
  <>
9
- <Title>Homepage</Title>
10
-
11
8
  <div class="container">
12
9
  <div class="title">AdonisJS {props.version} x Inertia x Solid.js</div>
13
10
 
14
11
  <span>
15
12
  Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
- <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
13
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
17
14
  </span>
18
15
  </div>
19
16
  </>
@@ -1,5 +1,5 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/views/root.edge') })
2
+ exports({ to: app.makePath('resources/views/inertia_layout.edge') })
3
3
  }}}
4
4
  <!DOCTYPE html>
5
5
  <html>
@@ -10,8 +10,8 @@
10
10
 
11
11
  <title inertia>AdonisJS x Inertia x SolidJS</title>
12
12
 
13
- @vite(['resources/app.tsx'])
14
13
  @inertiaHead()
14
+ {{ "@vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`])" }}
15
15
  </head>
16
16
 
17
17
  <body>
@@ -0,0 +1,19 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/app/ssr.tsx') })
3
+ }}}
4
+
5
+ import { hydrate } from 'solid-js/web'
6
+ import { createInertiaApp } from 'inertia-adapter-solid'
7
+
8
+ export default function render(page: any) {
9
+ return createInertiaApp({
10
+ page,
11
+ resolve: (name) => {
12
+ const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
13
+ {{ 'return pages[`../pages/${name}.tsx`]' }}
14
+ },
15
+ setup({ el, App, props }) {
16
+ hydrate(() => <App {...props} />, el)
17
+ },
18
+ })
19
+ }
@@ -1,26 +1,16 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/tsconfig.json') })
2
+ exports({ to: app.makePath('inertia/tsconfig.json') })
3
3
  }}}
4
4
  {
5
+ "extends": "@adonisjs/tsconfig/tsconfig.client.json",
5
6
  "compilerOptions": {
6
- "target": "ESNext",
7
- "jsx": "preserve",
8
- "jsxImportSource": "solid-js",
9
- "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
- "useDefineForClassFields": true,
11
7
  "baseUrl": ".",
8
+ "jsx": "preserve",
12
9
  "module": "ESNext",
13
- "moduleResolution": "Bundler",
10
+ "jsxImportSource": "solid-js",
14
11
  "paths": {
15
- "@/*": ["./*"],
16
- "~/*": ["../*"],
12
+ "~/*": ["./*"],
17
13
  },
18
- "resolveJsonModule": true,
19
- "types": ["vite/client"],
20
- "allowSyntheticDefaultImports": true,
21
- "esModuleInterop": true,
22
- "verbatimModuleSyntax": true,
23
- "skipLibCheck": true,
24
14
  },
25
- "include": ["./**/*.ts", "./**/*.tsx", "app.tsx.stub"],
15
+ "include": ["./**/*.ts", "./**/*.tsx"],
26
16
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Utility function to resolve a page component
3
+ *
4
+ * @example
5
+ * return resolvePageComponent(
6
+ * `./pages/${name}.vue`,
7
+ * import.meta.glob<DefineComponent>("./pages/**\/*.vue")
8
+ * )
9
+ */
10
+ declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
11
+
12
+ export { resolvePageComponent };
@@ -0,0 +1,14 @@
1
+ // src/helpers.ts
2
+ async function resolvePageComponent(path, pages) {
3
+ for (const p of Array.isArray(path) ? path : [path]) {
4
+ const page = pages[p];
5
+ if (typeof page === "undefined") {
6
+ continue;
7
+ }
8
+ return typeof page === "function" ? page() : page;
9
+ }
10
+ throw new Error(`Page not found: ${path}`);
11
+ }
12
+ export {
13
+ resolvePageComponent
14
+ };
@@ -1,55 +1,9 @@
1
1
  import { Vite } from '@adonisjs/vite';
2
2
  import { HttpContext } from '@adonisjs/core/http';
3
3
  import { NextFn } from '@adonisjs/core/types/http';
4
- import { ViteRuntime } from 'vite/runtime';
5
- import { ResolvedConfig, Data, PageProps, MaybePromise } from './types.js';
6
-
7
- /**
8
- * Symbol used to identify lazy props
9
- */
10
- declare const kLazySymbol: unique symbol;
11
- /**
12
- * Main class used to interact with Inertia
13
- */
14
- declare class Inertia {
15
- #private;
16
- protected ctx: HttpContext;
17
- protected config: ResolvedConfig;
18
- protected viteRuntime?: ViteRuntime | undefined;
19
- constructor(ctx: HttpContext, config: ResolvedConfig, viteRuntime?: ViteRuntime | undefined);
20
- /**
21
- * Share data for the current request.
22
- * This data will override any shared data defined in the config.
23
- */
24
- share(data: Record<string, Data>): void;
25
- /**
26
- * Render a page using Inertia
27
- */
28
- render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | {
29
- component: string;
30
- version: string | number;
31
- props: any;
32
- url: string;
33
- }>;
34
- /**
35
- * Create a lazy prop
36
- *
37
- * Lazy props are never resolved on first visit, but only when the client
38
- * request a partial reload explicitely with this value.
39
- *
40
- * See https://inertiajs.com/partial-reloads#lazy-data-evaluation
41
- */
42
- lazy(callback: () => MaybePromise<any>): {
43
- [kLazySymbol]: () => MaybePromise<any>;
44
- };
45
- /**
46
- * This method can be used to redirect the user to an external website
47
- * or even a non-inertia route of your application.
48
- *
49
- * See https://inertiajs.com/redirects#external-redirects
50
- */
51
- location(url: string): Promise<void>;
52
- }
4
+ import { a as Inertia, R as ResolvedConfig } from '../types-fb05P61I.js';
5
+ import '@adonisjs/core/types';
6
+ import '@tuyau/utils/types';
53
7
 
54
8
  /**
55
9
  * HttpContext augmentations
@@ -64,9 +18,9 @@ declare module '@adonisjs/core/http' {
64
18
  * set appropriate headers/status
65
19
  */
66
20
  declare class InertiaMiddleware {
67
- #private;
68
21
  protected config: ResolvedConfig;
69
- constructor(config: ResolvedConfig, vite?: Vite);
22
+ protected vite?: Vite | undefined;
23
+ constructor(config: ResolvedConfig, vite?: Vite | undefined);
70
24
  handle(ctx: HttpContext, next: NextFn): Promise<void>;
71
25
  }
72
26
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-CXICUKHN.js";
3
+ } from "../chunk-QKSM72AR.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -1,7 +1,9 @@
1
1
  import { PluginFn } from '@japa/runner/types';
2
2
  import { ApplicationService } from '@adonisjs/core/types';
3
- import { PageProps } from '../../types.js';
3
+ import { P as PageProps } from '../../../types-fb05P61I.js';
4
4
  import '@adonisjs/core/http';
5
+ import '@tuyau/utils/types';
6
+ import '@adonisjs/vite';
5
7
 
6
8
  declare module '@japa/api-client' {
7
9
  interface ApiRequest {
@@ -21,6 +21,6 @@ type InertiaPluginOptions = {
21
21
  /**
22
22
  * Inertia plugin for Vite that is tailored for AdonisJS
23
23
  */
24
- declare function inertia(options: InertiaPluginOptions): PluginOption;
24
+ declare function inertia(options?: InertiaPluginOptions): PluginOption;
25
25
 
26
26
  export { type InertiaPluginOptions, inertia as default };
@@ -2,9 +2,12 @@
2
2
  function inertia(options) {
3
3
  return {
4
4
  name: "vite-plugin-inertia",
5
- config: () => {
6
- if (!options.ssr?.enabled)
5
+ config: (_, { command }) => {
6
+ if (!options?.ssr?.enabled)
7
7
  return {};
8
+ if (command === "build") {
9
+ process.env.NODE_ENV = "production";
10
+ }
8
11
  return {
9
12
  buildSteps: [
10
13
  {
@@ -1,96 +1,5 @@
1
- import { HttpContext } from '@adonisjs/core/http';
2
-
3
- /**
4
- * VersionCache is used to cache the version of the assets.
5
- *
6
- * If the user has provided a version, it will be used.
7
- * Otherwise, we will compute a hash from the manifest file
8
- * and cache it.
9
- */
10
- declare class VersionCache {
11
- #private;
12
- protected appRoot: URL;
13
- protected assetsVersion?: AssetsVersion;
14
- constructor(appRoot: URL, assetsVersion?: AssetsVersion);
15
- /**
16
- * Pre-compute the version
17
- */
18
- computeVersion(): Promise<this>;
19
- /**
20
- * Returns the current assets version
21
- */
22
- getVersion(): string | number;
23
- /**
24
- * Set the assets version
25
- */
26
- setVersion(version: AssetsVersion): Promise<void>;
27
- }
28
-
29
- type MaybePromise<T> = T | Promise<T>;
30
- /**
31
- * Props that will be passed to inertia render method
32
- */
33
- type PageProps = Record<string, unknown>;
34
- /**
35
- * Shared data types
36
- */
37
- type Data = string | number | object | boolean;
38
- type SharedDatumFactory = (ctx: HttpContext) => MaybePromise<Data>;
39
- type SharedData = Record<string, Data | SharedDatumFactory>;
40
- /**
41
- * Allowed values for the assets version
42
- */
43
- type AssetsVersion = string | number | undefined;
44
- interface InertiaConfig {
45
- /**
46
- * Path to the Edge view that will be used as the root view for Inertia responses.
47
- * @default root (resources/views/root.edge)
48
- */
49
- rootView?: string;
50
- /**
51
- * The version of your assets. Every client request will be checked against this version.
52
- * If the version is not the same, the client will do a full reload.
53
- */
54
- assetsVersion?: AssetsVersion;
55
- /**
56
- * Data that should be shared with all rendered pages
57
- */
58
- sharedData?: SharedData;
59
- /**
60
- * Options to configure SSR
61
- */
62
- ssr?: {
63
- /**
64
- * Enable or disable SSR
65
- */
66
- enabled: boolean;
67
- /**
68
- * List of components that should be rendered on the server
69
- */
70
- pages?: string[];
71
- /**
72
- * Path to the SSR entrypoint file
73
- */
74
- entrypoint?: string;
75
- /**
76
- * Path to the SSR bundled file that will be used in production
77
- */
78
- bundle?: string;
79
- };
80
- }
81
- /**
82
- * Resolved inertia configuration
83
- */
84
- interface ResolvedConfig {
85
- rootView: string;
86
- versionCache: VersionCache;
87
- sharedData: SharedData;
88
- ssr: {
89
- enabled: boolean;
90
- entrypoint: string;
91
- pages?: string[];
92
- bundle: string;
93
- };
94
- }
95
-
96
- export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
1
+ import '@adonisjs/core/types';
2
+ import '@adonisjs/core/http';
3
+ import '@tuyau/utils/types';
4
+ export { A as AssetsVersion, D as Data, I as InertiaConfig, f as InferPageProps, d as InferSharedProps, M as MaybePromise, c as PageObject, P as PageProps, g as RenderInertiaSsrApp, R as ResolvedConfig, S as SharedData, b as SharedDatumFactory, e as SharedProps } from '../types-fb05P61I.js';
5
+ import '@adonisjs/vite';
@@ -0,0 +1,33 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/app/app.ts') })
3
+ }}}
4
+ /// <reference path="../../adonisrc.ts" />
5
+ /// <reference path="../../config/inertia.ts" />
6
+
7
+ import '../css/app.css';
8
+
9
+ import { createInertiaApp } from '@inertiajs/svelte'
10
+ import { resolvePageComponent } from '@adonisjs/inertia/helpers'
11
+
12
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
13
+
14
+ createInertiaApp({
15
+ progress: { color: '#5468FF' },
16
+
17
+ title: (title) => {{ '`${title} - ${appName}`' }},
18
+
19
+ resolve: (name) => {
20
+ return resolvePageComponent(
21
+ {{ '`../pages/${name}.svelte`' }},
22
+ import.meta.glob('../pages/**/*.svelte'),
23
+ )
24
+ },
25
+
26
+ setup({ el, App, props }) {
27
+ {{#if ssr}}
28
+ new App({ target: el, props, hydrate: true })
29
+ {{#else}}
30
+ new App({ target: el, props })
31
+ {{/if}}
32
+ },
33
+ })
@@ -0,0 +1,10 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/not_found.svelte') })
3
+ }}}
4
+ <div>
5
+ <div class="container">
6
+ <div class="title">Page not found</div>
7
+
8
+ <span>This page does not exist.</span>
9
+ </div>
10
+ </div>
@@ -0,0 +1,14 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/server_error.svelte') })
3
+ }}}
4
+ <script>
5
+ export let error
6
+ </script>
7
+
8
+ <div>
9
+ <div class="container">
10
+ <div class="title">Server Error</div>
11
+
12
+ <span>{error.message}</span>
13
+ </div>
14
+ </div>
@@ -0,0 +1,19 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/home.svelte') })
3
+ }}}
4
+ <script>
5
+ export let version
6
+ </script>
7
+
8
+ <svelte:head>
9
+ <title>Homepage</title>
10
+ </svelte:head>
11
+
12
+ <div class="container">
13
+ <div class="title">AdonisJS \{ version \} x Inertia x Svelte</div>
14
+
15
+ <span>
16
+ Learn more about AdonisJS and Inertia.js by visiting the
17
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
18
+ </span>
19
+ </div>
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/inertia_layout.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x Svelte</title>
12
+
13
+ {{ "@vite(['inertia/app/app.ts', `inertia/pages/${page.component}.svelte`])" }}
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,15 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/app/ssr.ts') })
3
+ }}}
4
+
5
+ import { createInertiaApp } from '@inertiajs/svelte'
6
+
7
+ export default function render(page: any) {
8
+ return createInertiaApp({
9
+ page,
10
+ resolve: (name) => {
11
+ const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
12
+ {{ 'return pages[`../pages/${name}.svelte`]' }}
13
+ }
14
+ })
15
+ }
@@ -0,0 +1,14 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "extends": "@adonisjs/tsconfig/tsconfig.client.json",
6
+ "compilerOptions": {
7
+ "baseUrl": ".",
8
+ "module": "ESNext",
9
+ "paths": {
10
+ "~/*": ["./*"],
11
+ },
12
+ },
13
+ "include": ["./**/*.ts", "./**/*.svelte"],
14
+ }