@primate/htmx 0.19.5 → 0.21.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/lib/private/Default.d.ts +12 -0
- package/lib/private/Default.js +34 -0
- package/lib/private/Options.d.ts +8 -0
- package/lib/private/Options.js +2 -0
- package/lib/private/Runtime.d.ts +10 -0
- package/lib/private/Runtime.js +23 -0
- package/lib/private/Template.d.ts +3 -0
- package/lib/private/Template.js +2 -0
- package/lib/public/default.d.ts +5 -0
- package/lib/public/default.js +3 -0
- package/lib/public/render.d.ts +2 -0
- package/lib/public/render.js +2 -0
- package/lib/public/runtime.d.ts +5 -0
- package/lib/public/runtime.js +3 -0
- package/package.json +29 -29
- package/src/private/build/index.js +0 -51
- package/src/private/build/server.js +0 -8
- package/src/private/error/no-client-extension.js +0 -11
- package/src/private/extension.js +0 -1
- package/src/private/name.js +0 -1
- package/src/private/pkgname.js +0 -1
- package/src/private/serve/handler.js +0 -13
- package/src/private/serve/index.js +0 -7
- package/src/public/default.js +0 -14
- package/src/public/escape.js +0 -1
- package/src/public/runtime.js +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type Options from "#Options";
|
|
2
|
+
import Runtime from "#Runtime";
|
|
3
|
+
import type BuildApp from "@primate/core/BuildApp";
|
|
4
|
+
export default class Default extends Runtime {
|
|
5
|
+
#private;
|
|
6
|
+
compile: {
|
|
7
|
+
server: (text: string) => string;
|
|
8
|
+
};
|
|
9
|
+
constructor(options?: Options);
|
|
10
|
+
publish(app: BuildApp): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Default.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Runtime from "#Runtime";
|
|
2
|
+
import empty from "@rcompat/record/empty";
|
|
3
|
+
import dedent from "@rcompat/string/dedent";
|
|
4
|
+
const htmx_esm = "htmx-esm";
|
|
5
|
+
const _export = `export * from "${htmx_esm}`;
|
|
6
|
+
export default class Default extends Runtime {
|
|
7
|
+
#extensions;
|
|
8
|
+
#templates;
|
|
9
|
+
compile = {
|
|
10
|
+
server: (text) => dedent `
|
|
11
|
+
import render from "@primate/htmx/render";
|
|
12
|
+
|
|
13
|
+
export default props => render(${JSON.stringify(text)}, props);`,
|
|
14
|
+
};
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
super({ fileExtensions: options.fileExtensions });
|
|
17
|
+
this.#extensions = options.extensions ?? [];
|
|
18
|
+
this.#templates = options.templates ?? [];
|
|
19
|
+
}
|
|
20
|
+
get #has_templates() {
|
|
21
|
+
return this.#extensions.includes("client-side-templates") &&
|
|
22
|
+
!empty(this.#templates);
|
|
23
|
+
}
|
|
24
|
+
publish(app) {
|
|
25
|
+
app.export(`export { default as htmx } from "${htmx_esm}";`);
|
|
26
|
+
this.#extensions.map(extension => app.export(`${_export}/${extension}";`));
|
|
27
|
+
if (this.#has_templates) {
|
|
28
|
+
this.#templates
|
|
29
|
+
.filter(template => template !== "xslt")
|
|
30
|
+
.map(template => app.export(`${_export}/templates/${template}";`));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=Default.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
+
import type ViewResponse from "@primate/core/frontend/ViewResponse";
|
|
3
|
+
export default class Runtime extends FrontendModule {
|
|
4
|
+
name: string;
|
|
5
|
+
defaultExtensions: string[];
|
|
6
|
+
layouts: boolean;
|
|
7
|
+
client: boolean;
|
|
8
|
+
respond: ViewResponse;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Runtime.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
+
import inline from "@primate/core/inline";
|
|
3
|
+
import response from "@primate/html/response";
|
|
4
|
+
export default class Runtime extends FrontendModule {
|
|
5
|
+
name = "htmx";
|
|
6
|
+
defaultExtensions = [".htmx"];
|
|
7
|
+
layouts = false;
|
|
8
|
+
client = false;
|
|
9
|
+
respond = (name, props, options = {}) => {
|
|
10
|
+
return async (app, _, request) => {
|
|
11
|
+
const code = "import { htmx } from \"app\";";
|
|
12
|
+
const { head, integrity } = await inline(code, "module");
|
|
13
|
+
const script_src = [integrity];
|
|
14
|
+
return response(this)(name, props, {
|
|
15
|
+
csp: { script_src },
|
|
16
|
+
head,
|
|
17
|
+
partial: Boolean(request.headers.try("hx-request")),
|
|
18
|
+
...options,
|
|
19
|
+
})(app, _, request);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Runtime.js.map
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/htmx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Primate HTMX frontend",
|
|
5
|
-
"homepage": "https://
|
|
6
|
-
"bugs": "https://github.com/
|
|
5
|
+
"homepage": "https://primate.run/docs/frontend/htmx",
|
|
6
|
+
"bugs": "https://github.com/primate-run/primate/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"/lib/**/*.js",
|
|
10
|
+
"/lib/**/*.d.ts",
|
|
11
|
+
"!/**/*.spec.*"
|
|
11
12
|
],
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/primate-run/primate",
|
|
15
16
|
"directory": "packages/htmx"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@rcompat/
|
|
19
|
-
"@rcompat/
|
|
20
|
-
"
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
19
|
+
"@rcompat/assert": "^0.3.1",
|
|
20
|
+
"@rcompat/fs": "^0.21.1",
|
|
21
|
+
"@rcompat/html": "^0.6.0",
|
|
22
|
+
"@rcompat/record": "^0.9.1",
|
|
23
|
+
"@rcompat/string": "^0.10.0",
|
|
24
|
+
"htmx-esm": "^0.2.1910",
|
|
25
|
+
"@primate/core": "^0.3.0",
|
|
26
|
+
"@primate/html": "^0.12.0"
|
|
23
27
|
},
|
|
24
28
|
"peerDependencies": {
|
|
25
|
-
"primate": "^0.
|
|
29
|
+
"primate": "^0.34.0"
|
|
26
30
|
},
|
|
27
31
|
"type": "module",
|
|
28
32
|
"imports": {
|
|
29
33
|
"#*": {
|
|
30
|
-
"
|
|
31
|
-
"default": "./
|
|
32
|
-
},
|
|
33
|
-
"#build": {
|
|
34
|
-
"livetypes": "./src/private/build/index.js",
|
|
35
|
-
"default": "./src/private/build/index.js"
|
|
36
|
-
},
|
|
37
|
-
"#serve": {
|
|
38
|
-
"livetypes": "./src/private/serve/index.js",
|
|
39
|
-
"default": "./src/private/serve/index.js"
|
|
40
|
-
},
|
|
41
|
-
"#error/*": {
|
|
42
|
-
"livetypes": "./src/private/error/*.js",
|
|
43
|
-
"default": "./src/private/error/*.js"
|
|
34
|
+
"apekit": "./src/private/*.ts",
|
|
35
|
+
"default": "./lib/private/*.js"
|
|
44
36
|
}
|
|
45
37
|
},
|
|
46
38
|
"exports": {
|
|
47
39
|
".": {
|
|
48
|
-
"runtime": "./
|
|
49
|
-
"default": "./
|
|
40
|
+
"runtime": "./lib/public/runtime.js",
|
|
41
|
+
"default": "./lib/public/default.js"
|
|
50
42
|
},
|
|
51
|
-
"./*":
|
|
43
|
+
"./*": {
|
|
44
|
+
"apekit": "./src/public/*.ts",
|
|
45
|
+
"default": "./lib/public/*.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "npm run clean && tsc",
|
|
50
|
+
"clean": "rm -rf ./lib",
|
|
51
|
+
"lint": "eslint ."
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default text => `import escape from "@primate/htmx/escape";
|
|
2
|
-
export default (props = {}, options) => {
|
|
3
|
-
const encoded = JSON.parse(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
|
-
}`;
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
});
|
package/src/private/extension.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default ".htmx";
|
package/src/private/name.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default "htmx";
|
package/src/private/pkgname.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default "@primate/htmx";
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
};
|
package/src/public/default.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
});
|
package/src/public/escape.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "@rcompat/html/escape";
|