@primate/htmx 0.15.0 → 0.16.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 (2) hide show
  1. package/package.json +4 -4
  2. package/src/module.js +18 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Primate HTMX module",
5
5
  "homepage": "https://primatejs.com/modules/htmx",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
@@ -15,11 +15,11 @@
15
15
  "directory": "packages/htmx"
16
16
  },
17
17
  "dependencies": {
18
- "htmx.org": "^1.9.2",
19
- "runtime-compat": "^0.20.2"
18
+ "htmx.org": "^1.9.4",
19
+ "runtime-compat": "^0.24.1"
20
20
  },
21
21
  "peerDependencies": {
22
- "primate": "0.20"
22
+ "primate": "0.21"
23
23
  },
24
24
  "type": "module",
25
25
  "exports": "./src/exports.js"
package/src/module.js CHANGED
@@ -1,3 +1,5 @@
1
+ import {Response, Status, MediaType} from "runtime-compat/http";
2
+
1
3
  const loadComponent = async (file) => {
2
4
  try {
3
5
  return await file.read();
@@ -11,32 +13,38 @@ const getBody = async (app, partial, file) => {
11
13
  return partial ? body : app.render({body});
12
14
  };
13
15
 
14
- const handler = path => (name, {status = 200, partial = false} = {}) =>
16
+ const handler = (name, {status = Status.OK, partial = false} = {}) =>
15
17
  async app => {
18
+ const {build: {paths: {components}}} = app;
19
+ const code = "import {htmx} from \"app\";";
20
+ await app.publish({code, type: "module", inline: true});
21
+
16
22
  const headers = app.headers();
17
- const styleSrc = "style-src 'self' 'unsafe-inline';";
18
- const csp = `${headers["Content-Security-Policy"]}${styleSrc}`;
19
- const options = {
23
+ const csp = headers["Content-Security-Policy"].replace(
24
+ "style-src 'self'", "style-src 'self' 'unsafe-inline'"
25
+ );
26
+ const body = await getBody(app, partial, components.join(name).file);
27
+
28
+ return new Response(body, {
20
29
  status,
21
30
  headers: {
22
31
  ...headers,
23
- "Content-Type": "text/html",
32
+ "Content-Type": MediaType.TEXT_HTML,
24
33
  "Content-Security-Policy": csp,
25
34
  },
26
- };
27
- return [await getBody(app, partial, path.join(name).file), options];
35
+ });
28
36
  };
29
37
 
30
- export default directory => ({
38
+ export default _ => ({
31
39
  name: "@primate/htmx",
32
40
  register(app, next) {
33
- app.register("htmx", handler(directory ?? app.paths.components));
41
+ app.register("htmx", handler);
34
42
  return next(app);
35
43
  },
36
44
  async publish(app, next) {
37
45
  const name = "htmx.org";
38
46
  await app.import(name);
39
- app.bootstrap({type: "script", code: `import * as htmx from "${name}";`});
47
+ app.bootstrap({type: "script", code: `export * as htmx from "${name}";`});
40
48
  return next(app);
41
49
  },
42
50
  });