@primate/htmx 0.23.0 → 0.24.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 +10 -0
- package/lib/private/default.js +35 -0
- package/lib/private/init.d.ts +11 -0
- package/lib/private/init.js +44 -0
- package/lib/private/runtime.d.ts +10 -0
- package/lib/private/runtime.js +4 -0
- package/lib/public/default.d.ts +1 -4
- package/lib/public/default.js +1 -2
- package/lib/public/runtime.d.ts +1 -4
- package/lib/public/runtime.js +1 -2
- package/package.json +16 -9
- package/lib/private/Default.d.ts +0 -12
- package/lib/private/Default.js +0 -38
- package/lib/private/Options.d.ts +0 -8
- package/lib/private/Options.js +0 -2
- package/lib/private/Runtime.d.ts +0 -10
- package/lib/private/Runtime.js +0 -23
- package/lib/private/Template.d.ts +0 -3
- package/lib/private/Template.js +0 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: (input?: import("@rcompat/type").Unpack<({
|
|
2
|
+
extensions?: string[] | undefined;
|
|
3
|
+
spa?: boolean | undefined;
|
|
4
|
+
ssr?: boolean | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
htmxExtensions?: string[] | undefined;
|
|
7
|
+
templates?: ("handlebars" | "mustache" | "nunjucks" | "xslt")[] | undefined;
|
|
8
|
+
}) | undefined>) => import("@primate/core/frontend").Module;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import init from "#init";
|
|
2
|
+
import frontend from "@primate/core/frontend";
|
|
3
|
+
import is from "@rcompat/is";
|
|
4
|
+
import string from "@rcompat/string";
|
|
5
|
+
const htmx_esm = "htmx-esm";
|
|
6
|
+
function server(text) {
|
|
7
|
+
return string.dedent `
|
|
8
|
+
import render from "@primate/htmx/render";
|
|
9
|
+
|
|
10
|
+
export default props => render(${JSON.stringify(text)}, props);`;
|
|
11
|
+
}
|
|
12
|
+
export default frontend({
|
|
13
|
+
...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}";`);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
compile: {
|
|
32
|
+
server,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Init } from "@primate/core/frontend";
|
|
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")[]>;
|
|
5
|
+
}>, {
|
|
6
|
+
htmxExtensions: string[];
|
|
7
|
+
templates: ("handlebars" | "mustache" | "nunjucks" | "xslt")[];
|
|
8
|
+
}>;
|
|
9
|
+
declare const init: Init<any, typeof schema>;
|
|
10
|
+
export default init;
|
|
11
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import transform_html from "@primate/html/transform";
|
|
2
|
+
import error from "@rcompat/error";
|
|
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"];
|
|
11
|
+
const schema = p({
|
|
12
|
+
htmxExtensions: p.array(p.string).default([]),
|
|
13
|
+
templates: p.array(p.enum(TEMPLATES)).unique().default([]),
|
|
14
|
+
});
|
|
15
|
+
const init = {
|
|
16
|
+
name: "htmx",
|
|
17
|
+
extensions: [".htmx"],
|
|
18
|
+
layouts: false,
|
|
19
|
+
client: false,
|
|
20
|
+
conditions: [],
|
|
21
|
+
schema,
|
|
22
|
+
async transform({ body, head = "", headers = {}, app, options, request }) {
|
|
23
|
+
const base = await transform_html({
|
|
24
|
+
body,
|
|
25
|
+
head,
|
|
26
|
+
headers,
|
|
27
|
+
app,
|
|
28
|
+
options,
|
|
29
|
+
request,
|
|
30
|
+
});
|
|
31
|
+
const app_js = app.assets.find(({ src }) => src !== undefined && src.includes("app") && src.endsWith(".js"));
|
|
32
|
+
if (app_js === undefined)
|
|
33
|
+
throw errors.could_not_find_app_js_in_assets();
|
|
34
|
+
const script = `<script type="module" src="${app_js.src}"></script>`;
|
|
35
|
+
return {
|
|
36
|
+
body: base.body,
|
|
37
|
+
head: (base.head ?? "").concat(script),
|
|
38
|
+
headers: base.headers,
|
|
39
|
+
partial: Boolean(request.headers.try("hx-request")),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export default init;
|
|
44
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: (input?: import("@rcompat/type").Unpack<({
|
|
2
|
+
extensions?: string[] | undefined;
|
|
3
|
+
spa?: boolean | undefined;
|
|
4
|
+
ssr?: boolean | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
htmxExtensions?: string[] | undefined;
|
|
7
|
+
templates?: ("handlebars" | "mustache" | "nunjucks" | "xslt")[] | undefined;
|
|
8
|
+
}) | undefined>) => import("@primate/core/frontend").Module;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=runtime.d.ts.map
|
package/lib/public/default.d.ts
CHANGED
package/lib/public/default.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/htmx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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,35 +17,42 @@
|
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@rcompat/
|
|
21
|
-
"@rcompat/
|
|
20
|
+
"@rcompat/error": "^0.3.1",
|
|
21
|
+
"@rcompat/is": "^0.6.1",
|
|
22
|
+
"@rcompat/string": "^0.16.1",
|
|
22
23
|
"htmx-esm": "^0.2.1910",
|
|
23
|
-
"@primate/core": "^0.
|
|
24
|
-
"
|
|
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"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
27
|
-
"primate": "^0.
|
|
32
|
+
"primate": "^0.37.0"
|
|
28
33
|
},
|
|
29
34
|
"imports": {
|
|
30
35
|
"#*": {
|
|
31
|
-
"
|
|
36
|
+
"@primate/source": "./src/private/*.ts",
|
|
32
37
|
"default": "./lib/private/*.js"
|
|
33
38
|
}
|
|
34
39
|
},
|
|
35
40
|
"exports": {
|
|
36
41
|
".": {
|
|
42
|
+
"@primate/source": "./src/public/default.ts",
|
|
37
43
|
"browser": "./lib/public/browser.js",
|
|
38
44
|
"runtime": "./lib/public/runtime.js",
|
|
39
45
|
"default": "./lib/public/default.js"
|
|
40
46
|
},
|
|
41
47
|
"./*": {
|
|
42
|
-
"
|
|
48
|
+
"@primate/source": "./src/public/*.ts",
|
|
43
49
|
"default": "./lib/public/*.js"
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
"scripts": {
|
|
47
53
|
"build": "npm run clean && tsc",
|
|
48
54
|
"clean": "rm -rf ./lib",
|
|
49
|
-
"lint": "eslint ."
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"test": "npx proby"
|
|
50
57
|
}
|
|
51
58
|
}
|
package/lib/private/Default.d.ts
DELETED
|
@@ -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
|
package/lib/private/Default.js
DELETED
|
@@ -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
|
package/lib/private/Options.d.ts
DELETED
package/lib/private/Options.js
DELETED
package/lib/private/Runtime.d.ts
DELETED
|
@@ -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
|
package/lib/private/Runtime.js
DELETED
|
@@ -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
|
package/lib/private/Template.js
DELETED