htmx-router 0.1.3 → 0.2.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/bin/components.d.ts +5 -3
- package/bin/components.js +5 -25
- package/bin/render-args.js +4 -24
- package/package.json +3 -3
- package/readme.md +24 -22
package/bin/components.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
|
+
import html from '@kitajs/html';
|
|
3
|
+
export declare function Link(props: html.PropsWithChildren<{
|
|
2
4
|
to: string;
|
|
3
5
|
class?: string;
|
|
6
|
+
style?: string | CSS.Properties<0 | (string & {}), string & {}>;
|
|
4
7
|
target?: string;
|
|
5
|
-
|
|
6
|
-
}, contents: string[]): string;
|
|
8
|
+
}>): string;
|
package/bin/components.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.Link = void 0;
|
|
27
|
-
const
|
|
28
|
-
function Link(props
|
|
29
|
-
return
|
|
7
|
+
const html_1 = __importDefault(require("@kitajs/html"));
|
|
8
|
+
function Link(props) {
|
|
9
|
+
return html_1.default.createElement("a", { target: props.target || "", class: props.class || "", style: props.style || "", href: props.to, "hx-get": props.to, "hx-headers": '{"Cache-Control": "no-cache"}' }, props.children);
|
|
30
10
|
}
|
|
31
11
|
exports.Link = Link;
|
package/bin/render-args.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.RenderArgs = exports.MaskType = void 0;
|
|
27
|
-
const
|
|
7
|
+
const html_1 = __importDefault(require("@kitajs/html"));
|
|
28
8
|
const titleScript = `<script>` +
|
|
29
9
|
`document.addEventListener("DOMContentLoaded",function(){` +
|
|
30
10
|
`document.body.addEventListener("setTitle",function(evt){document.title=decodeURIComponent(evt.detail.value);})` +
|
|
@@ -91,7 +71,7 @@ class RenderArgs {
|
|
|
91
71
|
return route.render(this, mask, routeName);
|
|
92
72
|
};
|
|
93
73
|
this.renderHeadHTML = () => {
|
|
94
|
-
let out =
|
|
74
|
+
let out = html_1.default.createElement("title", null, this.title);
|
|
95
75
|
for (const elm of this.links) {
|
|
96
76
|
out += "<link";
|
|
97
77
|
for (const attr in elm) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "htmx-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A remix.js style file path router for htmX websites",
|
|
5
5
|
"main": "./bin/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"typescript": "^5.1.6"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"@kitajs/html": "^1.4.2",
|
|
29
|
+
"csstype": "^3.1.2"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/readme.md
CHANGED
|
@@ -4,31 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
This library attempts to be as unopinionated as possible allowing for multiple escape hatches in-case there are certain times you want a different style of behaviour.
|
|
6
6
|
|
|
7
|
-
This library does not rely on any heavy weight dependencies such as react, instead opting to be built on the lighter weight [
|
|
7
|
+
This library does not rely on any heavy weight dependencies such as react, instead opting to be built on the lighter weight [kitajs/html](https://kitajs.github.io/html/) library for it's JSX rendering, and using [csstype](https://www.npmjs.com/package/csstype), just as a type interface to improve developer ergonomics.
|
|
8
8
|
|
|
9
9
|
You can also see an example site running this library [here](https://github.com/AjaniBilby/predictable) with source code as an extra helpful example. Please be mindful the slow loading of this site is actually due to Discord APIs, and the rendering is taking less than 2ms on a raspberry pi on my floor.
|
|
10
10
|
|
|
11
11
|
- [htmX Router](#htmx-router)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
- [Routes](#routes)
|
|
13
|
+
- [Module Layout](#module-layout)
|
|
14
|
+
- [Auth Function](#auth-function)
|
|
15
|
+
- [Render Function](#render-function)
|
|
16
|
+
- [CatchError Function](#catcherror-function)
|
|
17
|
+
- [Router](#router)
|
|
18
|
+
- [Types](#types)
|
|
19
|
+
- [RenderArgs](#renderargs)
|
|
20
|
+
- [Outlet](#outlet)
|
|
21
|
+
- [setTitle](#settitle)
|
|
22
|
+
- [addMeta](#addmeta)
|
|
23
|
+
- [addLinks](#addlinks)
|
|
24
|
+
- [renderHeadHTML](#renderheadhtml)
|
|
25
|
+
- [shared](#shared)
|
|
26
|
+
- [ErrorResponse](#errorresponse)
|
|
27
|
+
- [Override](#override)
|
|
28
|
+
- [Redirect](#redirect)
|
|
29
|
+
- [Components](#components)
|
|
30
|
+
- [Link](#link)
|
|
31
|
+
- [StyleCSS](#stylecss)
|
|
32
32
|
|
|
33
33
|
## Routes
|
|
34
34
|
|
|
@@ -266,7 +266,9 @@ This element will encode as a standard `<a>` with some extra html attributes, me
|
|
|
266
266
|
|
|
267
267
|
## StyleCSS
|
|
268
268
|
|
|
269
|
-
|
|
269
|
+
> **DEPRECATED**: If you utilize `@kitajs/html` instead of `typed-html` this function is no longer needed
|
|
270
|
+
|
|
271
|
+
This is a helper function allowing you to give it a [CSS.Properties](https://www.npmjs.com/package/csstype) type, and render it into a string for [kitajs/html](https://kitajs.github.io/html/) to use.
|
|
270
272
|
```tsx
|
|
271
273
|
<div style={StyleCSS({
|
|
272
274
|
height: "100%",
|