@primate/htmx 0.16.0 → 0.19.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) Terrablue <terrablue@proton.me> and contributors.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.16.0",
4
- "description": "Primate HTMX module",
3
+ "version": "0.19.0",
4
+ "description": "Primate HTMX frontend",
5
5
  "homepage": "https://primatejs.com/modules/htmx",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
7
7
  "license": "MIT",
@@ -15,12 +15,38 @@
15
15
  "directory": "packages/htmx"
16
16
  },
17
17
  "dependencies": {
18
- "htmx.org": "^1.9.4",
19
- "runtime-compat": "^0.24.1"
18
+ "@rcompat/object": "^0.5.0",
19
+ "@rcompat/string": "^0.3.0",
20
+ "@primate/frontend": "^0.16.0",
21
+ "@primate/html": "^0.10.0"
20
22
  },
21
23
  "peerDependencies": {
22
- "primate": "0.21"
24
+ "htmx-esm": "0.2",
25
+ "primate": "^0.32.0"
23
26
  },
24
27
  "type": "module",
25
- "exports": "./src/exports.js"
26
- }
28
+ "imports": {
29
+ "#*": {
30
+ "@primate/lt": "./src/private/*.js",
31
+ "default": "./src/private/*.js"
32
+ },
33
+ "#build": {
34
+ "@primate/lt": "./src/private/build/index.js",
35
+ "default": "./src/private/build/index.js"
36
+ },
37
+ "#serve": {
38
+ "@primate/lt": "./src/private/serve/index.js",
39
+ "default": "./src/private/serve/index.js"
40
+ },
41
+ "#error/*": {
42
+ "@primate/lt": "./src/private/error/*.js",
43
+ "default": "./src/private/error/*.js"
44
+ }
45
+ },
46
+ "exports": {
47
+ ".": {
48
+ "runtime": "./src/public/runtime.js",
49
+ "default": "./src/public/default.js"
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,51 @@
1
+ import no_client_extension from "#error/no-client-extension";
2
+ import name from "#name";
3
+ import compile from "@primate/frontend/core/compile";
4
+ import empty from "@rcompat/object/empty";
5
+ import server from "./server.js";
6
+
7
+ const templates = "client-side-templates";
8
+ const htmx_esm = "htmx-esm";
9
+ const base_import_template = (subpath, app) =>
10
+ app.build.export(`export * from "${htmx_esm}/${templates}/${subpath}";`);
11
+
12
+ const import_template = {
13
+ handlebars: app => base_import_template("handlebars", app),
14
+ mustache: app => base_import_template("mustache", app),
15
+ nunjucks: app => base_import_template("nunjucks", app),
16
+ // noop
17
+ xslt: _ => _,
18
+ };
19
+
20
+ export default ({
21
+ extension,
22
+ extensions,
23
+ client_side_templates,
24
+ }) => async (app, next) => {
25
+ app.build.export(`export { default as htmx } from "${htmx_esm}";`);
26
+
27
+ extensions.forEach(extension_name =>
28
+ app.build.export(`export * from "${htmx_esm}/${extension_name}";`));
29
+
30
+ if (!empty(client_side_templates)) {
31
+ const has_templates = extensions.includes(templates);
32
+ // app.assert(has_templates, nce(templates, client_side_templates.join(",")));
33
+ has_templates ||
34
+ no_client_extension(templates, client_side_templates.join(", "));
35
+ client_side_templates.forEach(client_side_template =>
36
+ import_template[client_side_template](app));
37
+ }
38
+
39
+ app.register(extension, {
40
+ ...await compile({
41
+ app,
42
+ extension,
43
+ name,
44
+ compile: { server },
45
+ }),
46
+ // no support for hydration
47
+ client: _ => _,
48
+ });
49
+
50
+ return next(app);
51
+ };
@@ -0,0 +1,8 @@
1
+ export default text => `import HTML from "@rcompat/string/html";
2
+ export default (props = {}, options) => {
3
+ const encoded = JSON.parse(HTML.escape(JSON.stringify(props)));
4
+ const keys = Object.keys(encoded);
5
+ const values = Object.values(encoded);
6
+ const text = ${JSON.stringify(text)};
7
+ return new Function(...keys, \`return \\\`\${text}\\\`;\`)(...values);
8
+ }`;
@@ -0,0 +1,11 @@
1
+ import pkgname from "#pkgname";
2
+ import log from "@primate/core/log";
3
+ import file from "@rcompat/fs/file";
4
+
5
+ export default (...params) => log.error({
6
+ params,
7
+ name: file(import.meta.url).base,
8
+ module: pkgname,
9
+ message: "the extension {0} is required for {1} client side support",
10
+ fix: "add \"{0}\" to the `extensions` array for the HTMX module",
11
+ });
@@ -0,0 +1 @@
1
+ export default ".htmx";
@@ -0,0 +1 @@
1
+ export default "htmx";
@@ -0,0 +1 @@
1
+ export default "@primate/htmx";
@@ -0,0 +1,13 @@
1
+ import handler from "@primate/html/handler";
2
+
3
+ export default (name, props, options = {}) => async (app, _, request) => {
4
+ const code = "import { htmx } from \"app\";";
5
+ const { head , integrity } = await app.inline(code, "module");
6
+ const script_src = [integrity];
7
+
8
+ return handler(name, props, { head: [head],
9
+ csp: { script_src },
10
+ partial: Boolean(request.headers.get("hx-request")),
11
+ ...options,
12
+ })(app, _, request);
13
+ };
@@ -0,0 +1,7 @@
1
+ import handler from "./handler.js";
2
+
3
+ export default extension => (app, next) => {
4
+ app.register(extension, handler);
5
+
6
+ return next(app);
7
+ };
@@ -0,0 +1,14 @@
1
+ import build from "#build";
2
+ import default_extension from "#extension";
3
+ import pkgname from "#pkgname";
4
+ import serve from "#serve";
5
+
6
+ export default ({
7
+ extension = default_extension,
8
+ extensions = [],
9
+ client_side_templates = [],
10
+ } = {}) => ({
11
+ name: pkgname,
12
+ build: build({ extension, extensions, client_side_templates }),
13
+ serve: serve(extension),
14
+ });
@@ -0,0 +1,8 @@
1
+ import default_extension from "#extension";
2
+ import pkgname from "#pkgname";
3
+ import serve from "#serve";
4
+
5
+ export default ({ extension = default_extension } = {}) => ({
6
+ name: pkgname,
7
+ serve: serve(extension),
8
+ });
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # HTMX
2
-
3
- This handler module serves HTMX components with the .htmx extension.
4
-
5
- ## [Documentation](https://primatejs.com/modules/htmx)
package/src/exports.js DELETED
@@ -1 +0,0 @@
1
- export {default} from "./module.js";
package/src/module.js DELETED
@@ -1,50 +0,0 @@
1
- import {Response, Status, MediaType} from "runtime-compat/http";
2
-
3
- const loadComponent = async (file) => {
4
- try {
5
- return await file.read();
6
- } catch (error) {
7
- throw new Error(`cannot load component at ${file.name}`);
8
- }
9
- };
10
-
11
- const getBody = async (app, partial, file) => {
12
- const body = await loadComponent(file);
13
- return partial ? body : app.render({body});
14
- };
15
-
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, {
29
- status,
30
- headers: {
31
- ...headers,
32
- "Content-Type": MediaType.TEXT_HTML,
33
- "Content-Security-Policy": csp,
34
- },
35
- });
36
- };
37
-
38
- export default _ => ({
39
- name: "@primate/htmx",
40
- register(app, next) {
41
- app.register("htmx", handler);
42
- return next(app);
43
- },
44
- async publish(app, next) {
45
- const name = "htmx.org";
46
- await app.import(name);
47
- app.bootstrap({type: "script", code: `export * as htmx from "${name}";`});
48
- return next(app);
49
- },
50
- });