@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.
- package/README.md +3 -15
- package/package.json +4 -4
- package/src/module.js +21 -19
package/README.md
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# HTMX
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This handler module serves HTMX components with the .htmx extension.
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
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.
|
|
19
|
-
"runtime-compat": "^0.
|
|
18
|
+
"htmx.org": "^1.9.4",
|
|
19
|
+
"runtime-compat": "^0.24.1"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"primate": "0.
|
|
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 {
|
|
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 =
|
|
17
|
-
async
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
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":
|
|
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
|
|
38
|
+
export default _ => ({
|
|
32
39
|
name: "@primate/htmx",
|
|
33
40
|
register(app, next) {
|
|
34
|
-
app.register("htmx", handler
|
|
41
|
+
app.register("htmx", handler);
|
|
35
42
|
return next(app);
|
|
36
43
|
},
|
|
37
44
|
async publish(app, next) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
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
|
});
|