@primate/htmx 0.15.0 → 0.17.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 +1 -1
  2. package/package.json +4 -4
  3. package/src/module.js +25 -13
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # HTMX
2
2
 
3
- This handler module serves HTMX components with the .htmx extension.
3
+ This handler serves HTMX components with the `htmx` file extension.
4
4
 
5
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.15.0",
3
+ "version": "0.17.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.25.7"
20
20
  },
21
21
  "peerDependencies": {
22
- "primate": "0.20"
22
+ "primate": "0.22"
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,42 @@ 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} = {}) =>
15
- async app => {
16
+ const handler = directory =>
17
+ (name, {status = Status.OK, partial = false} = {}) => async app => {
18
+ const components = app.runpath(directory);
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 => ({
31
- name: "@primate/htmx",
38
+ const name = "htmx.org";
39
+ export default ({
40
+ extension = "htmx",
41
+ directory,
42
+ } = {}) => ({
43
+ name: "primate:htmx",
32
44
  register(app, next) {
33
- app.register("htmx", handler(directory ?? app.paths.components));
45
+ app.register(extension, handler(directory
46
+ ?? app.config.location.components));
34
47
  return next(app);
35
48
  },
36
49
  async publish(app, next) {
37
- const name = "htmx.org";
38
50
  await app.import(name);
39
- app.bootstrap({type: "script", code: `import * as htmx from "${name}";`});
51
+ app.export({type: "script", code: `export * as htmx from "${name}";`});
40
52
  return next(app);
41
53
  },
42
54
  });