@primate/htmx 0.7.1 → 0.8.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 +3 -3
  2. package/src/module.js +9 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Primate HTMX module",
5
5
  "homepage": "https://primatejs.com/modules/htmx",
6
6
  "bugs": "https://github.com/primatejs/htmx/issues",
@@ -8,13 +8,13 @@
8
8
  "repository": "https://github.com/primatejs/htmx",
9
9
  "dependencies": {
10
10
  "htmx.org": "^1.8.6",
11
- "runtime-compat": "^0.14.1"
11
+ "runtime-compat": "^0.15.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "maximin": "^0.1.2"
15
15
  },
16
16
  "peerDependencies": {
17
- "primate": "0.14.0"
17
+ "primate": "0.15"
18
18
  },
19
19
  "type": "module",
20
20
  "exports": "./exports.js",
package/src/module.js CHANGED
@@ -1,23 +1,19 @@
1
1
  import {Path} from "runtime-compat/fs";
2
2
 
3
- const loadComponent = async (env, name) => {
3
+ const loadComponent = async (file) => {
4
4
  try {
5
- return await env.paths.components.join(`${name}.html`).file.read();
5
+ return await file.read();
6
6
  } catch (error) {
7
- throw new Error(`cannot load component at ${name}.html`);
7
+ throw new Error(`cannot load component at ${file.name}`);
8
8
  }
9
9
  };
10
10
 
11
- const getContent = (env, {adhoc, content}) => {
12
- return adhoc ? content : loadComponent(env, content);
13
- };
14
-
15
- const getBody = async (env, {adhoc, partial, content}) => {
16
- const body = await getContent(env, {adhoc, content});
11
+ const getBody = async (env, partial, file) => {
12
+ const body = await loadComponent(file);
17
13
  return partial ? body : env.render({body});
18
14
  };
19
15
 
20
- const htmx = (content, {status = 200, partial = false, adhoc = false} = {}) =>
16
+ const handler = path => (name, {status = 200, partial = false} = {}) =>
21
17
  async (env, headers) => {
22
18
  const styleSrc = "style-src 'unsafe-inline';";
23
19
  const csp = `${headers["Content-Security-Policy"]}${styleSrc}`;
@@ -29,13 +25,12 @@ const htmx = (content, {status = 200, partial = false, adhoc = false} = {}) =>
29
25
  "Content-Security-Policy": csp,
30
26
  },
31
27
  };
32
-
33
- return [await getBody(env, {adhoc, partial, content}), options];
28
+ return [await getBody(env, partial, path.join(name).file), options];
34
29
  };
35
30
 
36
- export default () => ({
31
+ export default directory => ({
37
32
  register(env, next) {
38
- env.register("htmx", htmx);
33
+ env.register("htmx", handler(directory ?? env.paths.components));
39
34
  return next(env);
40
35
  },
41
36
  async publish(env, next) {