@primate/htmx 0.23.0 → 0.25.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.
@@ -0,0 +1,11 @@
1
+ declare const _default: (input?: import("@rcompat/type").Unpack<({
2
+ extensions?: string[] | undefined;
3
+ csr?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } & {
6
+ clientSideTemplates?: {
7
+ engine: "handlebars" | "mustache" | "nunjucks";
8
+ } | undefined;
9
+ }) | undefined>) => import("@primate/core/frontend").Module;
10
+ export default _default;
11
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1,54 @@
1
+ import E from "#errors";
2
+ import init from "#init";
3
+ import frontend from "@primate/core/frontend";
4
+ import string from "@rcompat/string";
5
+ const CLIENT_SIDE_TEMPLATES = {
6
+ mustache: {
7
+ package: "mustache",
8
+ global: "Mustache",
9
+ },
10
+ handlebars: {
11
+ package: "handlebars",
12
+ global: "Handlebars",
13
+ },
14
+ nunjucks: {
15
+ package: "nunjucks",
16
+ global: "nunjucks",
17
+ },
18
+ };
19
+ function server(text) {
20
+ return string.dedent `
21
+ import render from "@primate/htmx/render";
22
+ export default props => render(${JSON.stringify(text)}, props);`;
23
+ }
24
+ async function has(specifier, from) {
25
+ return from.join("node_modules", specifier).exists();
26
+ }
27
+ async function ensure(specifier, from, error) {
28
+ if (!await has(specifier, from))
29
+ throw error();
30
+ }
31
+ export default frontend({
32
+ ...init,
33
+ async onBuild(app, options) {
34
+ await ensure("htmx.org", app.root, () => E.htmx_package_required());
35
+ const templates = options.clientSideTemplates;
36
+ const lines = [
37
+ `import htmx from "htmx.org";`,
38
+ "globalThis.htmx = htmx;",
39
+ ];
40
+ if (templates !== undefined) {
41
+ await ensure("htmx-ext-client-side-templates", app.root, () => E.client_side_templates_required());
42
+ const engine = CLIENT_SIDE_TEMPLATES[templates.engine];
43
+ await ensure(engine.package, app.root, () => {
44
+ throw E.template_engine_required(templates.engine, engine.package);
45
+ });
46
+ lines.push(`import ${engine.global} from "${engine.package}";`, `globalThis.${engine.global} = ${engine.global};`, `import "htmx-ext-client-side-templates";`);
47
+ }
48
+ app.entrypoint(lines.join("\n"));
49
+ },
50
+ compile: {
51
+ server,
52
+ },
53
+ });
54
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1,21 @@
1
+ declare const peer_deps: {
2
+ handlebars: string;
3
+ "htmx-ext-client-side-templates": string;
4
+ "htmx.org": string;
5
+ mustache: string;
6
+ nunjucks: string;
7
+ primate: string;
8
+ };
9
+ type PeerDep = keyof typeof peer_deps;
10
+ declare function could_not_find_app_js_in_assets(): import("@rcompat/error").TemplateError;
11
+ declare function client_side_templates_required(): import("@rcompat/error").TemplateError;
12
+ declare function htmx_package_required(): import("@rcompat/error").TemplateError;
13
+ declare function template_engine_required(engine: string, pkg: PeerDep): import("@rcompat/error").TemplateError;
14
+ declare const errors: {
15
+ could_not_find_app_js_in_assets: typeof could_not_find_app_js_in_assets;
16
+ template_engine_required: typeof template_engine_required;
17
+ client_side_templates_required: typeof client_side_templates_required;
18
+ htmx_package_required: typeof htmx_package_required;
19
+ };
20
+ export default errors;
21
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,33 @@
1
+ import pkg_json from "#pkg-json" with { type: "json" };
2
+ import assert from "@rcompat/assert";
3
+ import error from "@rcompat/error";
4
+ const peer_deps = assert.dict(pkg_json.peerDependencies);
5
+ const t = error.template;
6
+ function version(pkg) {
7
+ return `${pkg}@${peer_deps[pkg]}`;
8
+ }
9
+ function could_not_find_app_js_in_assets() {
10
+ return t `could not find app.js in assets`;
11
+ }
12
+ function client_side_templates_required() {
13
+ const option = "clientSideTemplates";
14
+ const pkg = "htmx-ext-client-side-templates";
15
+ return t `${option} requires ${version(pkg)} to be installed`;
16
+ }
17
+ ;
18
+ function htmx_package_required() {
19
+ return t `${version("htmx.org")} must be installed`;
20
+ }
21
+ ;
22
+ function template_engine_required(engine, pkg) {
23
+ const option = "clientSideTemplates.engine";
24
+ return t `${option} is set to ${engine}, but ${version(pkg)} is not installed`;
25
+ }
26
+ const errors = error.coded({
27
+ could_not_find_app_js_in_assets,
28
+ template_engine_required,
29
+ client_side_templates_required,
30
+ htmx_package_required,
31
+ });
32
+ export default errors;
33
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,15 @@
1
+ import type { Init } from "@primate/core/frontend";
2
+ declare const schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
3
+ readonly clientSideTemplates: import("pema").OptionalType<import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
4
+ readonly engine: import("pema").EnumType<readonly ["mustache", "handlebars", "nunjucks"]>;
5
+ }>, {
6
+ engine: "handlebars" | "mustache" | "nunjucks";
7
+ }>>;
8
+ }>, {
9
+ clientSideTemplates: {
10
+ engine: "handlebars" | "mustache" | "nunjucks";
11
+ } | undefined;
12
+ }>;
13
+ declare const init: Init<any, typeof schema>;
14
+ export default init;
15
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1,43 @@
1
+ import E from "#errors";
2
+ import transform_html from "@primate/html/transform";
3
+ import p from "pema";
4
+ const CLIENT_SIDE_TEMPLATE_ENGINES = [
5
+ "mustache",
6
+ "handlebars",
7
+ "nunjucks",
8
+ ];
9
+ const schema = p({
10
+ clientSideTemplates: p({
11
+ engine: p.enum(CLIENT_SIDE_TEMPLATE_ENGINES),
12
+ }).optional(),
13
+ });
14
+ const init = {
15
+ name: "htmx",
16
+ extensions: [".htmx"],
17
+ layouts: false,
18
+ client: false,
19
+ conditions: [],
20
+ schema,
21
+ async transform({ body, head = "", headers = {}, app, options, request }) {
22
+ const base = await transform_html({
23
+ body,
24
+ head,
25
+ headers,
26
+ app,
27
+ options,
28
+ request,
29
+ });
30
+ const app_js = app.assets.find(({ src }) => src !== undefined && src.includes("app") && src.endsWith(".js"));
31
+ if (app_js === undefined)
32
+ throw E.could_not_find_app_js_in_assets();
33
+ const script = `<script type="module" src="${app_js.src}"></script>`;
34
+ return {
35
+ body: base.body,
36
+ head: (base.head ?? "").concat(script),
37
+ headers: base.headers,
38
+ partial: Boolean(request.headers.try("hx-request")),
39
+ };
40
+ },
41
+ };
42
+ export default init;
43
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,11 @@
1
+ declare const _default: (input?: import("@rcompat/type").Unpack<({
2
+ extensions?: string[] | undefined;
3
+ csr?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } & {
6
+ clientSideTemplates?: {
7
+ engine: "handlebars" | "mustache" | "nunjucks";
8
+ } | undefined;
9
+ }) | undefined>) => import("@primate/core/frontend").Module;
10
+ export default _default;
11
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,4 @@
1
+ import init from "#init";
2
+ import frontend from "@primate/core/frontend";
3
+ export default frontend(init);
4
+ //# sourceMappingURL=runtime.js.map
@@ -1,5 +1,2 @@
1
- import Default from "#Default";
2
- import type Options from "#Options";
3
- declare const _default: (options?: Options) => Default;
4
- export default _default;
1
+ export { default } from "#default";
5
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,3 +1,2 @@
1
- import Default from "#Default";
2
- export default (options) => new Default(options);
1
+ export { default } from "#default";
3
2
  //# sourceMappingURL=default.js.map
@@ -1,5 +1,2 @@
1
- import type Options from "#Options";
2
- import Runtime from "#Runtime";
3
- declare const _default: (options?: Options) => Runtime;
4
- export default _default;
1
+ export { default } from "#runtime";
5
2
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,3 +1,2 @@
1
- import Runtime from "#Runtime";
2
- export default (options) => new Runtime(options);
1
+ export { default } from "#runtime";
3
2
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "HTMX for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/htmx",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -17,29 +17,54 @@
17
17
  "!/**/*.spec.*"
18
18
  ],
19
19
  "dependencies": {
20
- "@rcompat/is": "^0.4.2",
21
- "@rcompat/string": "^0.13.0",
22
- "htmx-esm": "^0.2.1910",
23
- "@primate/core": "^0.5.0",
24
- "@primate/html": "^0.16.0"
20
+ "@rcompat/assert": "^0.13.0",
21
+ "@rcompat/error": "^0.8.0",
22
+ "@rcompat/fs": "^0.33.2",
23
+ "@rcompat/is": "^0.11.0",
24
+ "@rcompat/runtime": "^0.16.0",
25
+ "@rcompat/string": "^0.21.0",
26
+ "@primate/core": "^0.7.0",
27
+ "@primate/html": "^0.18.0",
28
+ "pema": "^0.7.0"
25
29
  },
26
30
  "peerDependencies": {
27
- "primate": "^0.36.0"
31
+ "handlebars": "4",
32
+ "htmx-ext-client-side-templates": "2",
33
+ "htmx.org": "2",
34
+ "mustache": "4",
35
+ "nunjucks": "3",
36
+ "primate": "^0.38.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "htmx-ext-client-side-templates": {
40
+ "optional": true
41
+ },
42
+ "mustache": {
43
+ "optional": true
44
+ },
45
+ "handlebars": {
46
+ "optional": true
47
+ },
48
+ "nunjucks": {
49
+ "optional": true
50
+ }
28
51
  },
29
52
  "imports": {
30
53
  "#*": {
31
- "apekit": "./src/private/*.ts",
54
+ "@primate/source": "./src/private/*.ts",
32
55
  "default": "./lib/private/*.js"
33
- }
56
+ },
57
+ "#pkg-json": "./package.json"
34
58
  },
35
59
  "exports": {
36
60
  ".": {
61
+ "@primate/source": "./src/public/default.ts",
37
62
  "browser": "./lib/public/browser.js",
38
63
  "runtime": "./lib/public/runtime.js",
39
64
  "default": "./lib/public/default.js"
40
65
  },
41
66
  "./*": {
42
- "apekit": "./src/public/*.ts",
67
+ "@primate/source": "./src/public/*.ts",
43
68
  "default": "./lib/public/*.js"
44
69
  }
45
70
  },
@@ -1,12 +0,0 @@
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
@@ -1,38 +0,0 @@
1
- import Runtime from "#Runtime";
2
- import is from "@rcompat/is";
3
- import string from "@rcompat/string";
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) => string.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
- !is.empty(this.#templates);
23
- }
24
- publish(app) {
25
- app.entrypoint(`export { default as htmx } from "${htmx_esm}";`);
26
- this.#extensions.forEach(extension => {
27
- app.entrypoint(`export * from "${htmx_esm}/${extension}";`);
28
- });
29
- if (this.#has_templates) {
30
- this.#templates
31
- .filter(template => template !== "xslt")
32
- .forEach(template => {
33
- app.entrypoint(`export * from "${htmx_esm}/templates/${template}";`);
34
- });
35
- }
36
- }
37
- }
38
- //# sourceMappingURL=Default.js.map
@@ -1,8 +0,0 @@
1
- import type Template from "#Template";
2
- type Options = {
3
- extensions?: string[];
4
- fileExtensions?: [string];
5
- templates?: Template[];
6
- };
7
- export type { Options as default };
8
- //# sourceMappingURL=Options.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Options.js.map
@@ -1,10 +0,0 @@
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
@@ -1,23 +0,0 @@
1
- import fail from "@primate/core/fail";
2
- import FrontendModule from "@primate/core/frontend/Module";
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 app_js = app.assets.find(asset => asset.src?.includes("app") && asset.src.endsWith(".js"));
12
- if (!app_js)
13
- throw fail("Could not find app.js in assets");
14
- const script = `<script type="module" src="${app_js.src}"></script>`;
15
- return response(this)(name, props, {
16
- head: script,
17
- partial: Boolean(request.headers.try("hx-request")),
18
- ...options,
19
- })(app, _, request);
20
- };
21
- };
22
- }
23
- //# sourceMappingURL=Runtime.js.map
@@ -1,3 +0,0 @@
1
- type Template = "handlebars" | "mustache" | "nunjucks" | "xslt";
2
- export type { Template as default };
3
- //# sourceMappingURL=Template.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Template.js.map