@adonisjs/inertia 1.0.0-2 → 1.0.0-4

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.
@@ -67,6 +67,7 @@ var Inertia = class {
67
67
  if (!isInertiaRequest) {
68
68
  return this.ctx.view.render(this.config.rootView, { ...viewProps, page: pageObject });
69
69
  }
70
+ this.ctx.response.header("x-inertia", "true");
70
71
  return pageObject;
71
72
  }
72
73
  /**
@@ -105,7 +106,6 @@ var InertiaMiddleware = class {
105
106
  if (!isInertiaRequest)
106
107
  return;
107
108
  response.header("Vary", "Accept");
108
- response.header("X-Inertia", "true");
109
109
  const method = request.method();
110
110
  if (response.getStatus() === 302 && ["PUT", "PATCH", "DELETE"].includes(method)) {
111
111
  response.status(303);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-GDULL3NT.js";
3
+ } from "../chunk-PZZVHQTV.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -15,7 +15,7 @@ var InertiaProvider = class {
15
15
  async registerEdgePlugin() {
16
16
  try {
17
17
  const edgeExports = await import("edge.js");
18
- const { edgePluginInertia } = await import("../src/plugins/edge.js");
18
+ const { edgePluginInertia } = await import("../src/plugins/edge/plugin.js");
19
19
  edgeExports.default.use(edgePluginInertia());
20
20
  } catch {
21
21
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-GDULL3NT.js";
3
+ } from "../chunk-PZZVHQTV.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -0,0 +1,85 @@
1
+ // src/plugins/edge/plugin.ts
2
+ import { encode } from "html-entities";
3
+
4
+ // src/debug.ts
5
+ import { debuglog } from "node:util";
6
+ var debug_default = debuglog("adonisjs:inertia");
7
+
8
+ // src/plugins/edge/tags.ts
9
+ import { EdgeError } from "edge-error";
10
+
11
+ // src/plugins/edge/utils.ts
12
+ function isSubsetOf(expression, expressions, errorCallback) {
13
+ if (!expressions.includes(expression.type)) {
14
+ errorCallback();
15
+ }
16
+ }
17
+
18
+ // src/plugins/edge/tags.ts
19
+ var inertiaTag = {
20
+ block: false,
21
+ tagName: "inertia",
22
+ seekable: true,
23
+ compile(parser, buffer, { filename, loc, properties }) {
24
+ if (properties.jsArg.trim() === "") {
25
+ buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
26
+ return;
27
+ }
28
+ properties.jsArg = `(${properties.jsArg})`;
29
+ const parsed = parser.utils.transformAst(
30
+ parser.utils.generateAST(properties.jsArg, loc, filename),
31
+ filename,
32
+ parser
33
+ );
34
+ isSubsetOf(parsed, ["ObjectExpression"], () => {
35
+ const { line, col } = parser.utils.getExpressionLoc(parsed);
36
+ throw new EdgeError(
37
+ `"${properties.jsArg}" is not a valid argument for @inertia`,
38
+ "E_UNALLOWED_EXPRESSION",
39
+ { line, col, filename }
40
+ );
41
+ });
42
+ const attributes = parser.utils.stringify(parsed);
43
+ buffer.writeExpression(
44
+ `out += state.inertia(state.page, ${attributes})`,
45
+ filename,
46
+ loc.start.line
47
+ );
48
+ }
49
+ };
50
+ var inertiaHeadTag = {
51
+ block: false,
52
+ tagName: "inertiaHead",
53
+ seekable: false,
54
+ compile(_, buffer, { filename, loc }) {
55
+ buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
56
+ }
57
+ };
58
+
59
+ // src/plugins/edge/plugin.ts
60
+ var edgePluginInertia = () => {
61
+ return (edge) => {
62
+ debug_default("sharing globals and inertia tags with edge");
63
+ edge.global(
64
+ "inertia",
65
+ (page = {}, attributes = {}) => {
66
+ if (page.ssrBody)
67
+ return page.ssrBody;
68
+ const className = attributes?.class ? ` class="${attributes.class}"` : "";
69
+ const id = attributes?.id ? ` id="${attributes.id}"` : ' id="app"';
70
+ const tag = attributes?.as || "div";
71
+ const dataPage = encode(JSON.stringify(page));
72
+ return `<${tag}${id}${className} data-page="${dataPage}"></${tag}>`;
73
+ }
74
+ );
75
+ edge.global("inertiaHead", (page) => {
76
+ const { ssrHead = [] } = page || {};
77
+ return ssrHead.join("\n");
78
+ });
79
+ edge.registerTag(inertiaHeadTag);
80
+ edge.registerTag(inertiaTag);
81
+ };
82
+ };
83
+ export {
84
+ edgePluginInertia
85
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "1.0.0-2",
4
+ "version": "1.0.0-4",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -16,7 +16,7 @@
16
16
  "./services/main": "./build/services/inertia.js",
17
17
  "./inertia_middleware": "./build/src/inertia_middleware.js",
18
18
  "./inertia_provider": "./build/providers/inertia_provider.js",
19
- "./plugins/edge": "./build/src/plugins/edge.js",
19
+ "./plugins/edge": "./build/src/plugins/edge/plugin.js",
20
20
  "./plugins/api_client": "./build/src/plugins/api_client.js"
21
21
  },
22
22
  "scripts": {
@@ -55,6 +55,7 @@
55
55
  "c8": "^8.0.1",
56
56
  "copyfiles": "^2.4.1",
57
57
  "del-cli": "^5.1.0",
58
+ "edge-parser": "^9.0.0",
58
59
  "edge.js": "^6.0.0",
59
60
  "eslint": "^8.53.0",
60
61
  "get-port": "^7.0.0",
@@ -69,6 +70,7 @@
69
70
  "dependencies": {
70
71
  "@poppinss/utils": "^6.5.1",
71
72
  "crc-32": "^1.2.2",
73
+ "edge-error": "^4.0.0",
72
74
  "html-entities": "^2.4.0",
73
75
  "qs": "^6.11.2"
74
76
  },
@@ -124,7 +126,7 @@
124
126
  "./services/inertia.ts",
125
127
  "./src/inertia_middleware.ts",
126
128
  "./providers/inertia_provider.ts",
127
- "./src/plugins/edge.ts",
129
+ "./src/plugins/edge/plugin.ts",
128
130
  "./src/plugins/api_client.ts"
129
131
  ],
130
132
  "outDir": "./build",
@@ -1,41 +0,0 @@
1
- // src/plugins/edge.ts
2
- import { encode } from "html-entities";
3
-
4
- // src/debug.ts
5
- import { debuglog } from "node:util";
6
- var debug_default = debuglog("adonisjs:inertia");
7
-
8
- // src/plugins/edge.ts
9
- var edgePluginInertia = () => {
10
- return (edge) => {
11
- debug_default("sharing globals and inertia tags with edge");
12
- edge.global("inertia", (page = {}) => {
13
- if (page.ssrBody)
14
- return page.ssrBody;
15
- return `<div id="app" data-page="${encode(JSON.stringify(page))}"></div>`;
16
- });
17
- edge.global("inertiaHead", (page) => {
18
- const { ssrHead = [] } = page || {};
19
- return ssrHead.join("\n");
20
- });
21
- edge.registerTag({
22
- block: false,
23
- tagName: "inertia",
24
- seekable: false,
25
- compile(_, buffer, { filename, loc }) {
26
- buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
27
- }
28
- });
29
- edge.registerTag({
30
- block: false,
31
- tagName: "inertiaHead",
32
- seekable: false,
33
- compile(_, buffer, { filename, loc }) {
34
- buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
35
- }
36
- });
37
- };
38
- };
39
- export {
40
- edgePluginInertia
41
- };