@primate/htmx 0.14.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 (3) hide show
  1. package/README.md +3 -15
  2. package/package.json +4 -4
  3. package/src/module.js +21 -19
package/README.md CHANGED
@@ -1,17 +1,5 @@
1
- # Primate HTMX module
1
+ # HTMX
2
2
 
3
- ## Install
3
+ This handler module serves HTMX components with the .htmx extension.
4
4
 
5
- `npm i @primate/htmx`
6
-
7
- ## Configure
8
-
9
- Add to `primate.config.js`
10
-
11
- ```js
12
- import htmx from "@primate/htmx";
13
-
14
- export default {
15
- modules: [htmx()],
16
- };
17
- ```
5
+ ## [Documentation](https://primatejs.com/modules/htmx)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.14.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.17.0"
18
+ "htmx.org": "^1.9.4",
19
+ "runtime-compat": "^0.24.1"
20
20
  },
21
21
  "peerDependencies": {
22
- "primate": "0.19"
22
+ "primate": "0.21"
23
23
  },
24
24
  "type": "module",
25
25
  "exports": "./src/exports.js"
package/src/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {Path} from "runtime-compat/fs";
1
+ import {Response, Status, MediaType} from "runtime-compat/http";
2
2
 
3
3
  const loadComponent = async (file) => {
4
4
  try {
@@ -13,36 +13,38 @@ const getBody = async (app, partial, file) => {
13
13
  return partial ? body : app.render({body});
14
14
  };
15
15
 
16
- const handler = path => (name, {status = 200, partial = false} = {}) =>
17
- async (app, headers) => {
18
- const styleSrc = "style-src 'self' 'unsafe-inline';";
19
- const csp = `${headers["Content-Security-Policy"]}${styleSrc}`;
20
- const options = {
16
+ const handler = (name, {status = Status.OK, partial = false} = {}) =>
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
+
22
+ const headers = app.headers();
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, {
21
29
  status,
22
30
  headers: {
23
31
  ...headers,
24
- "Content-Type": "text/html",
32
+ "Content-Type": MediaType.TEXT_HTML,
25
33
  "Content-Security-Policy": csp,
26
34
  },
27
- };
28
- return [await getBody(app, partial, path.join(name).file), options];
35
+ });
29
36
  };
30
37
 
31
- export default directory => ({
38
+ export default _ => ({
32
39
  name: "@primate/htmx",
33
40
  register(app, next) {
34
- app.register("htmx", handler(directory ?? app.paths.components));
41
+ app.register("htmx", handler);
35
42
  return next(app);
36
43
  },
37
44
  async publish(app, next) {
38
- const src = "htmx.js";
39
- const scriptPath = ["node_modules", "htmx.org", "dist", src];
40
- const path = import.meta.resolve === undefined
41
- ? await Path.resolve().join(...scriptPath)
42
- : new Path(await import.meta.resolve("htmx.org"));
43
- const code = await path.file.read();
44
- await app.publish({src, code, type: "module"});
45
- app.bootstrap({type: "script", code: `import * as htmx from "./${src}";`});
45
+ const name = "htmx.org";
46
+ await app.import(name);
47
+ app.bootstrap({type: "script", code: `export * as htmx from "${name}";`});
46
48
  return next(app);
47
49
  },
48
50
  });