mhx 2026.1.0 → 2026.1.1
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/README.md +82 -0
- package/README.npm.md +82 -0
- package/npm/index.js +8 -1
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# mhx
|
|
2
|
+
|
|
3
|
+
MoonBit Hypermedia X (mhx) is a type-safe Hypermedia-Driven Architecture (HDA)
|
|
4
|
+
library for the browser, inspired by htmx. It uses `mx-*` attributes to declare
|
|
5
|
+
hypermedia behavior and runs as a compact JS runtime compiled from MoonBit.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install mhx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Import the runtime and initialize it once on startup. The npm entry already
|
|
16
|
+
initializes the FFI glue.
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import mhx, { init_mhx } from "mhx";
|
|
20
|
+
|
|
21
|
+
init_mhx();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### HTML Attributes
|
|
25
|
+
|
|
26
|
+
mhx uses `mx-*` attributes (not `hx-*`) to define hypermedia behaviors:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<!-- Simple GET request -->
|
|
30
|
+
<button mx-get="/api/data" mx-target="#result">
|
|
31
|
+
Load Data
|
|
32
|
+
</button>
|
|
33
|
+
|
|
34
|
+
<!-- POST with trigger modifiers -->
|
|
35
|
+
<form mx-post="/api/submit" mx-trigger="submit" mx-swap="outerHTML">
|
|
36
|
+
<input name="email" type="email" />
|
|
37
|
+
<button type="submit">Submit</button>
|
|
38
|
+
</form>
|
|
39
|
+
|
|
40
|
+
<!-- Click with delay and filter -->
|
|
41
|
+
<button mx-get="/api/action" mx-trigger="click[ctrlKey] delay:500ms">
|
|
42
|
+
Ctrl+Click (with 500ms delay)
|
|
43
|
+
</button>
|
|
44
|
+
|
|
45
|
+
<!-- Debounced input -->
|
|
46
|
+
<input
|
|
47
|
+
mx-get="/api/search"
|
|
48
|
+
mx-trigger="input changed debounce:300ms"
|
|
49
|
+
mx-target="#search-results"
|
|
50
|
+
name="q"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
The npm entry exports the following helpers:
|
|
57
|
+
|
|
58
|
+
- `init_mhx()` - initialize mhx (call once after DOM is ready)
|
|
59
|
+
- `process(element)` - process newly added elements
|
|
60
|
+
- `handle_event(event)` - manually dispatch an event
|
|
61
|
+
- `get_instance()` - access the internal singleton instance
|
|
62
|
+
- `version` - runtime version string
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { process } from "mhx";
|
|
66
|
+
|
|
67
|
+
const node = document.querySelector("#new-content");
|
|
68
|
+
process(node);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Build from Source
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pnpm build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This builds `dist/index.js` and `dist/mhx_ffi.js`, which are used by the npm
|
|
78
|
+
wrapper at `npm/index.js`.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
Apache-2.0
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# mhx
|
|
2
|
+
|
|
3
|
+
MoonBit Hypermedia X (mhx) is a type-safe Hypermedia-Driven Architecture (HDA)
|
|
4
|
+
library for the browser, inspired by htmx. It uses `mx-*` attributes to declare
|
|
5
|
+
hypermedia behavior and runs as a compact JS runtime compiled from MoonBit.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install mhx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Import the runtime and initialize it once on startup. The npm entry already
|
|
16
|
+
initializes the FFI glue.
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import mhx, { init_mhx } from "mhx";
|
|
20
|
+
|
|
21
|
+
init_mhx();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### HTML Attributes
|
|
25
|
+
|
|
26
|
+
mhx uses `mx-*` attributes (not `hx-*`) to define hypermedia behaviors:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<!-- Simple GET request -->
|
|
30
|
+
<button mx-get="/api/data" mx-target="#result">
|
|
31
|
+
Load Data
|
|
32
|
+
</button>
|
|
33
|
+
|
|
34
|
+
<!-- POST with trigger modifiers -->
|
|
35
|
+
<form mx-post="/api/submit" mx-trigger="submit" mx-swap="outerHTML">
|
|
36
|
+
<input name="email" type="email" />
|
|
37
|
+
<button type="submit">Submit</button>
|
|
38
|
+
</form>
|
|
39
|
+
|
|
40
|
+
<!-- Click with delay and filter -->
|
|
41
|
+
<button mx-get="/api/action" mx-trigger="click[ctrlKey] delay:500ms">
|
|
42
|
+
Ctrl+Click (with 500ms delay)
|
|
43
|
+
</button>
|
|
44
|
+
|
|
45
|
+
<!-- Debounced input -->
|
|
46
|
+
<input
|
|
47
|
+
mx-get="/api/search"
|
|
48
|
+
mx-trigger="input changed debounce:300ms"
|
|
49
|
+
mx-target="#search-results"
|
|
50
|
+
name="q"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
The npm entry exports the following helpers:
|
|
57
|
+
|
|
58
|
+
- `init_mhx()` - initialize mhx (call once after DOM is ready)
|
|
59
|
+
- `process(element)` - process newly added elements
|
|
60
|
+
- `handle_event(event)` - manually dispatch an event
|
|
61
|
+
- `get_instance()` - access the internal singleton instance
|
|
62
|
+
- `version` - runtime version string
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { process } from "mhx";
|
|
66
|
+
|
|
67
|
+
const node = document.querySelector("#new-content");
|
|
68
|
+
process(node);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Build from Source
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pnpm build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This builds `dist/index.js` and `dist/mhx_ffi.js`, which are used by the npm
|
|
78
|
+
wrapper at `npm/index.js`.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
Apache-2.0
|
package/npm/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import * as mhx from "../dist/index.js";
|
|
2
2
|
import { initMhxFfi } from "../dist/mhx_ffi.js";
|
|
3
3
|
|
|
4
|
-
initMhxFfi(
|
|
4
|
+
initMhxFfi({
|
|
5
|
+
on_fetch_success: mhx.on_fetch_success,
|
|
6
|
+
on_fetch_error: mhx.on_fetch_error,
|
|
7
|
+
on_mutation_observed: mhx.on_mutation_observed,
|
|
8
|
+
});
|
|
5
9
|
|
|
6
10
|
export const init_mhx = mhx.init_mhx;
|
|
7
11
|
export const process = mhx.process;
|
|
8
12
|
export const handle_event = mhx.handle_event;
|
|
9
13
|
export const get_instance = mhx.get_instance;
|
|
10
14
|
export const version = mhx.version;
|
|
15
|
+
export const on_fetch_success = mhx.on_fetch_success;
|
|
16
|
+
export const on_fetch_error = mhx.on_fetch_error;
|
|
17
|
+
export const on_mutation_observed = mhx.on_mutation_observed;
|
|
11
18
|
|
|
12
19
|
export default mhx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mhx",
|
|
3
|
-
"version": "2026.1.
|
|
3
|
+
"version": "2026.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./npm/index.js",
|
|
6
6
|
"files": [
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"LICENSE",
|
|
10
10
|
"README.mbt.md"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build:moon": "moon fmt && moon check && moon test && moon build --target js",
|
|
14
|
+
"build": "pnpm build:moon && mkdir -p dist && cp _build/js/release/build/main/main.js dist/index.js && cp src/ffi/mhx_ffi.js dist/mhx_ffi.js"
|
|
15
|
+
},
|
|
12
16
|
"license": "Apache-2.0",
|
|
13
17
|
"repository": {
|
|
14
18
|
"type": "git",
|
|
15
19
|
"url": "https://github.com/f4ah6o/mhx.mbt"
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build:moon": "moon fmt && moon check && moon test && moon build --target js",
|
|
19
|
-
"build": "pnpm build:moon && mkdir -p dist && cp _build/js/release/build/main/main.js dist/index.js && cp src/ffi/mhx_ffi.js dist/mhx_ffi.js"
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
}
|