@primate/htmx 0.24.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.
@@ -1,10 +1,11 @@
1
1
  declare const _default: (input?: import("@rcompat/type").Unpack<({
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } & {
6
- htmxExtensions?: string[] | undefined;
7
- templates?: ("handlebars" | "mustache" | "nunjucks" | "xslt")[] | undefined;
6
+ clientSideTemplates?: {
7
+ engine: "handlebars" | "mustache" | "nunjucks";
8
+ } | undefined;
8
9
  }) | undefined>) => import("@primate/core/frontend").Module;
9
10
  export default _default;
10
11
  //# sourceMappingURL=default.d.ts.map
@@ -1,32 +1,51 @@
1
+ import E from "#errors";
1
2
  import init from "#init";
2
3
  import frontend from "@primate/core/frontend";
3
- import is from "@rcompat/is";
4
4
  import string from "@rcompat/string";
5
- const htmx_esm = "htmx-esm";
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
+ };
6
19
  function server(text) {
7
20
  return string.dedent `
8
21
  import render from "@primate/htmx/render";
9
-
10
22
  export default props => render(${JSON.stringify(text)}, props);`;
11
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
+ }
12
31
  export default frontend({
13
32
  ...init,
14
- onBuild(app, { htmxExtensions, templates }) {
15
- app.entrypoint(`export { default as htmx } from "${htmx_esm}";`);
16
- htmxExtensions.forEach(extension => {
17
- app.entrypoint(`
18
- export * from "${htmx_esm}/${extension}";
19
- `);
20
- });
21
- const has_templates = htmxExtensions.includes("client-side-templates")
22
- && !is.empty(templates);
23
- if (has_templates) {
24
- templates
25
- .filter(template => template !== "xslt")
26
- .forEach(template => {
27
- app.entrypoint(`export * from "${htmx_esm}/templates/${template}";`);
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);
28
45
  });
46
+ lines.push(`import ${engine.global} from "${engine.package}";`, `globalThis.${engine.global} = ${engine.global};`, `import "htmx-ext-client-side-templates";`);
29
47
  }
48
+ app.entrypoint(lines.join("\n"));
30
49
  },
31
50
  compile: {
32
51
  server,
@@ -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
@@ -1,10 +1,14 @@
1
1
  import type { Init } from "@primate/core/frontend";
2
2
  declare const schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
3
- readonly htmxExtensions: import("pema").DefaultType<import("pema").ArrayType<import("pema").StringType>, string[]>;
4
- readonly templates: import("pema").DefaultType<import("pema").ArrayType<import("pema").EnumType<readonly ["handlebars", "mustache", "nunjucks", "xslt"]>>, ("handlebars" | "mustache" | "nunjucks" | "xslt")[]>;
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
+ }>>;
5
8
  }>, {
6
- htmxExtensions: string[];
7
- templates: ("handlebars" | "mustache" | "nunjucks" | "xslt")[];
9
+ clientSideTemplates: {
10
+ engine: "handlebars" | "mustache" | "nunjucks";
11
+ } | undefined;
8
12
  }>;
9
13
  declare const init: Init<any, typeof schema>;
10
14
  export default init;
@@ -1,16 +1,15 @@
1
+ import E from "#errors";
1
2
  import transform_html from "@primate/html/transform";
2
- import error from "@rcompat/error";
3
3
  import p from "pema";
4
- function could_not_find_app_js_in_assets() {
5
- return error.template `could not find app.js in assets`;
6
- }
7
- const errors = error.coded({
8
- could_not_find_app_js_in_assets,
9
- });
10
- const TEMPLATES = ["handlebars", "mustache", "nunjucks", "xslt"];
4
+ const CLIENT_SIDE_TEMPLATE_ENGINES = [
5
+ "mustache",
6
+ "handlebars",
7
+ "nunjucks",
8
+ ];
11
9
  const schema = p({
12
- htmxExtensions: p.array(p.string).default([]),
13
- templates: p.array(p.enum(TEMPLATES)).unique().default([]),
10
+ clientSideTemplates: p({
11
+ engine: p.enum(CLIENT_SIDE_TEMPLATE_ENGINES),
12
+ }).optional(),
14
13
  });
15
14
  const init = {
16
15
  name: "htmx",
@@ -30,7 +29,7 @@ const init = {
30
29
  });
31
30
  const app_js = app.assets.find(({ src }) => src !== undefined && src.includes("app") && src.endsWith(".js"));
32
31
  if (app_js === undefined)
33
- throw errors.could_not_find_app_js_in_assets();
32
+ throw E.could_not_find_app_js_in_assets();
34
33
  const script = `<script type="module" src="${app_js.src}"></script>`;
35
34
  return {
36
35
  body: base.body,
@@ -1,10 +1,11 @@
1
1
  declare const _default: (input?: import("@rcompat/type").Unpack<({
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } & {
6
- htmxExtensions?: string[] | undefined;
7
- templates?: ("handlebars" | "mustache" | "nunjucks" | "xslt")[] | undefined;
6
+ clientSideTemplates?: {
7
+ engine: "handlebars" | "mustache" | "nunjucks";
8
+ } | undefined;
8
9
  }) | undefined>) => import("@primate/core/frontend").Module;
9
10
  export default _default;
10
11
  //# sourceMappingURL=runtime.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/htmx",
3
- "version": "0.24.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,25 +17,44 @@
17
17
  "!/**/*.spec.*"
18
18
  ],
19
19
  "dependencies": {
20
- "@rcompat/error": "^0.3.1",
21
- "@rcompat/is": "^0.6.1",
22
- "@rcompat/string": "^0.16.1",
23
- "htmx-esm": "^0.2.1910",
24
- "@primate/core": "^0.6.0",
25
- "pema": "^0.6.0",
26
- "@primate/html": "^0.17.0"
27
- },
28
- "devDependencies": {
29
- "@primate/test": "^0.0.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"
30
29
  },
31
30
  "peerDependencies": {
32
- "primate": "^0.37.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
+ }
33
51
  },
34
52
  "imports": {
35
53
  "#*": {
36
54
  "@primate/source": "./src/private/*.ts",
37
55
  "default": "./lib/private/*.js"
38
- }
56
+ },
57
+ "#pkg-json": "./package.json"
39
58
  },
40
59
  "exports": {
41
60
  ".": {
@@ -52,7 +71,6 @@
52
71
  "scripts": {
53
72
  "build": "npm run clean && tsc",
54
73
  "clean": "rm -rf ./lib",
55
- "lint": "eslint .",
56
- "test": "npx proby"
74
+ "lint": "eslint ."
57
75
  }
58
76
  }