@wc-bindable/marko 0.6.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/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wc-bindable-protocol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @wc-bindable/marko
|
|
2
|
+
|
|
3
|
+
Marko adapter for the **wc-bindable** protocol.
|
|
4
|
+
|
|
5
|
+
The adapter is a single framework-agnostic helper that wires `bind()` from
|
|
6
|
+
`@wc-bindable/core` into Marko's own mount/destroy lifecycle. It is
|
|
7
|
+
version-agnostic — the same import works in **Marko 5** (class components) and
|
|
8
|
+
**Marko 6** (Tags API).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @wc-bindable/marko marko
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API
|
|
17
|
+
|
|
18
|
+
### `wcBindable(el, onUpdate): unbind`
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Description |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `el` | `HTMLElement` | The Web Component DOM node |
|
|
23
|
+
| `onUpdate` | `(name: string, value: unknown) => void` | Called for each declared property on the initial sync and on every subsequent change event |
|
|
24
|
+
|
|
25
|
+
Returns an `unbind` function. If `el` does not implement the wc-bindable
|
|
26
|
+
protocol, the helper is a no-op and the returned function is safe to call.
|
|
27
|
+
|
|
28
|
+
## Marko 6 (Tags API)
|
|
29
|
+
|
|
30
|
+
Capture the element with a tag variable, then call the helper from `<lifecycle>`:
|
|
31
|
+
|
|
32
|
+
```marko
|
|
33
|
+
import { wcBindable } from "@wc-bindable/marko";
|
|
34
|
+
|
|
35
|
+
<let/state = { value: "" } />
|
|
36
|
+
<my-input/inputEl />
|
|
37
|
+
<lifecycle
|
|
38
|
+
onMount() { this.unbind = wcBindable(inputEl, (n, v) => state = { ...state, [n]: v }); }
|
|
39
|
+
onDestroy() { this.unbind?.(); }
|
|
40
|
+
/>
|
|
41
|
+
<output>${state.value}</output>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Marko 5 (class components)
|
|
45
|
+
|
|
46
|
+
Use a `key=` ref + `getEl()` from `onMount`, release in `onDestroy`:
|
|
47
|
+
|
|
48
|
+
```marko
|
|
49
|
+
import { wcBindable } from "@wc-bindable/marko";
|
|
50
|
+
|
|
51
|
+
class {
|
|
52
|
+
onCreate() { this.state = { value: "" }; }
|
|
53
|
+
onMount() {
|
|
54
|
+
this.unbind = wcBindable(this.getEl("input"), (name, value) => {
|
|
55
|
+
this.state[name] = value;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
onDestroy() { if (this.unbind) this.unbind(); }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
<my-input key="input" />
|
|
62
|
+
<output>${state.value}</output>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If your Web Component's tag name contains a hyphen, Marko 5 may try to resolve
|
|
66
|
+
it as a custom Marko component. Use the dynamic-tag syntax to render it as a
|
|
67
|
+
plain HTML element:
|
|
68
|
+
|
|
69
|
+
```marko
|
|
70
|
+
$ const TAG = "my-input";
|
|
71
|
+
<${TAG} key="input"/>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC;AAElC,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAE9D,wBAAgB,UAAU,CAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAGxE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMvD,MAAM,UAAU,UAAU,CAAC,EAAe,EAAE,QAAkB;IAC5D,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC5B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wc-bindable/marko",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Marko adapter for wc-bindable protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"test": "vitest run tests",
|
|
23
|
+
"test:watch": "vitest tests",
|
|
24
|
+
"test:integration": "vitest run --config vitest.integration.config.ts integration"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@wc-bindable/core": "^0.6.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"marko": ">=5"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/wc-bindable-protocol/wc-bindable-protocol.git",
|
|
35
|
+
"directory": "packages/marko"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT"
|
|
38
|
+
}
|