dom-primitive-bindings 1.3.1 → 1.7.3
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 +22 -22
- package/README.md +67 -77
- package/package.json +26 -35
- package/src/index.js +3 -3
- package/src/{v3 → v5}/dispatch/executeBinding.js +21 -21
- package/src/{v3 → v5}/dispatch/getClientData.js +8 -8
- package/src/{v3 → v5}/dispatch/getStartInput.js +10 -10
- package/src/{v3 → v5}/dispatch/index.js +15 -15
- package/src/{v3 → v5}/guards/bindings/index.js +11 -11
- package/src/{v3 → v5}/guards/bindings/validateArray.js +10 -10
- package/src/{v3 → v5}/guards/container/index.js +13 -13
- package/src/{v3 → v5}/guards/container/resolveElement.js +14 -14
- package/src/{v3 → v5}/guards/index.js +15 -15
- package/src/{v3 → v5}/index.js +21 -22
- package/src/{v3 → v5}/listeners/attachListener.js +10 -10
- package/src/{v3 → v5}/listeners/index.js +12 -12
- package/src/{v3 → v5}/prepare/groupBindings.js +14 -14
- package/src/v5/prepare/index.js +23 -0
- package/src/{v3 → v5}/register/index.js +18 -18
- package/src/v5/register/meta.js +6 -0
- package/src/v6/dispatch/executeBinding.js +21 -0
- package/src/v6/dispatch/getClientData.js +8 -0
- package/src/v6/dispatch/getStartInput.js +10 -0
- package/src/v6/dispatch/index.js +15 -0
- package/src/v6/guards/actions/index.js +21 -0
- package/src/v6/guards/bindings/index.js +5 -0
- package/src/v6/guards/bindings/validateArray.js +23 -0
- package/src/v6/guards/bindings/validateBinding.js +22 -0
- package/src/v6/guards/container/index.js +13 -0
- package/src/v6/guards/container/resolveElement.js +14 -0
- package/src/v6/guards/index.js +19 -0
- package/src/v6/index.js +21 -0
- package/src/v6/listeners/attachListener.js +10 -0
- package/src/v6/listeners/index.js +12 -0
- package/src/v6/prepare/groupBindings.js +14 -0
- package/src/v6/prepare/index.js +23 -0
- package/src/v6/register/index.js +18 -0
- package/src/{v3 → v6}/register/meta.js +1 -1
- package/src/v7/dispatch/executeBinding.js +21 -0
- package/src/v7/dispatch/getClientData.js +8 -0
- package/src/v7/dispatch/getStartInput.js +10 -0
- package/src/v7/dispatch/index.js +15 -0
- package/src/v7/guards/actions/index.js +21 -0
- package/src/v7/guards/bindings/index.js +5 -0
- package/src/v7/guards/bindings/validateArray.js +23 -0
- package/src/v7/guards/bindings/validateBinding.js +22 -0
- package/src/v7/guards/container/index.js +13 -0
- package/src/v7/guards/container/resolveElement.js +14 -0
- package/src/v7/guards/index.js +19 -0
- package/src/v7/index.js +43 -0
- package/src/v7/listeners/attachListener.js +10 -0
- package/src/v7/listeners/index.js +12 -0
- package/src/v7/prepare/groupBindings.js +14 -0
- package/src/v7/prepare/index.js +23 -0
- package/src/v7/register/index.js +18 -0
- package/src/v7/register/meta.js +6 -0
- package/src/v7/sample/index.js +22 -0
- package/docs/architecture.md +0 -111
- package/docs/binding-spec.md +0 -86
- package/docs/dist/min.js +0 -64
- package/docs/dist/v1/min.js +0 -63
- package/docs/dist/v2/min.js +0 -64
- package/docs/dist/v3/min.js +0 -64
- package/docs/index.html +0 -208
- package/docs/stories/01-the-listener-trap.html +0 -189
- package/docs/stories/02-the-delegation-epiphany.html +0 -185
- package/docs/stories/03-the-staged-pipeline.html +0 -162
- package/docs/stories/04-declarative-json-bindings.html +0 -159
- package/src/v3/prepare/index.js +0 -8
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 KeshavSoft
|
|
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.
|
|
22
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KeshavSoft
|
|
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.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
# DOM Primitive Bindings
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Browser-native, single-listener container event delegation driven by declarative JSON instructions.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](./docs/index.html)
|
|
7
|
+
[](https://keshavsoft.github.io/dom-primitive-bindings/)
|
|
9
8
|
|
|
10
9
|
---
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## 🌐 Live Documentation & Interactive Story
|
|
13
12
|
|
|
14
|
-
Explore the
|
|
13
|
+
Explore the complete interactive story and live samples on **[GitHub Pages](https://keshavsoft.github.io/dom-primitive-bindings/)**:
|
|
15
14
|
|
|
16
|
-
1. **[Chapter 1: The
|
|
17
|
-
Why attaching listeners to individual elements causes memory leaks, double-trigger cascades, and
|
|
18
|
-
2. **[Chapter 2:
|
|
19
|
-
|
|
20
|
-
3. **[Chapter 3:
|
|
21
|
-
|
|
22
|
-
4. **[
|
|
23
|
-
|
|
15
|
+
1. **[Chapter 1: The Problem (Why?)](https://keshavsoft.github.io/dom-primitive-bindings/why/)** ([local](./docs/why/index.html))
|
|
16
|
+
Why attaching listeners to individual elements causes memory leaks, double-trigger cascades, and re-render dead zones.
|
|
17
|
+
2. **[Chapter 2: How We Achieved It](https://keshavsoft.github.io/dom-primitive-bindings/how/)** ([local](./docs/how/index.html))
|
|
18
|
+
The delegation epiphany: leveraging browser event bubbling across a decoupled 4-stage pipeline (`guards` $\to$ `prepare` $\to$ `listeners` $\to$ `dispatch`).
|
|
19
|
+
3. **[Chapter 3: Declarative JSON](https://keshavsoft.github.io/dom-primitive-bindings/declarative/)** ([local](./docs/declarative/index.html))
|
|
20
|
+
Separating intent from execution: why JSON instructions make UI code human-readable, statically guardable, and self-documenting.
|
|
21
|
+
4. **[Usage & Available Builds](https://keshavsoft.github.io/dom-primitive-bindings/usage/)** ([local](./docs/usage/index.html))
|
|
22
|
+
Available builds hosted on GitHub Pages CDN with one-click copyable script tags and ES Module imports.
|
|
24
23
|
|
|
25
24
|
---
|
|
26
25
|
|
|
@@ -29,79 +28,56 @@ Explore the interactive interactive story chapters in [`docs/stories/`](./docs/i
|
|
|
29
28
|
A common mistake in UI architecture is conflating **event wiring** with **DOM manipulation** or **data extraction**:
|
|
30
29
|
|
|
31
30
|
- **`dom-primitive-bindings` (This Repository):**
|
|
32
|
-
Pure **Wiring Layer**. Attaches one container listener per event type, matches bubbling targets via `closest(selector)`, and delivers `{ event, targetElement }`. It does **not** manipulate DOM elements and does **not** extract
|
|
31
|
+
Pure **Wiring Layer**. Attaches one container listener per event type, matches bubbling targets via `closest(selector)`, and delivers `{ event, targetElement }`. It does **not** manipulate DOM elements and does **not** extract schemas.
|
|
33
32
|
- **`dom-primitive-engine` (Sibling Repository):**
|
|
34
|
-
Pure **Extraction Layer**. Receives the matched target element and executes declarative instruction pipelines (e.g. `closest("tr")`, `querySelectorAll("td")
|
|
33
|
+
Pure **Extraction Layer**. Receives the matched target element and executes declarative instruction pipelines (e.g. `closest("tr")`, `querySelectorAll("td")`) to produce clean JSON.
|
|
35
34
|
|
|
36
35
|
```text
|
|
37
36
|
[ User Action in Browser ]
|
|
38
37
|
│
|
|
39
38
|
▼
|
|
40
39
|
┌───────────────────────────────┐
|
|
41
|
-
│ dom-primitive-bindings │ ◄── Wiring Layer: Catches event & matches target
|
|
40
|
+
│ dom-primitive-bindings │ ◄── Wiring Layer: Catches bubbling event & matches target
|
|
42
41
|
│ (guards → prepare → dispatch)│
|
|
43
42
|
└──────────────┬────────────────┘
|
|
44
43
|
│ delivers { event, targetElement }
|
|
45
44
|
▼
|
|
46
45
|
┌───────────────────────────────┐
|
|
47
|
-
│ Consumer / App Logic │ ◄── Extraction (dom-primitive-engine) or
|
|
46
|
+
│ Consumer / App Logic │ ◄── Extraction (dom-primitive-engine) or Action Handler
|
|
48
47
|
└───────────────────────────────┘
|
|
49
48
|
```
|
|
50
49
|
|
|
51
50
|
---
|
|
52
51
|
|
|
53
|
-
##
|
|
52
|
+
## ⚡ Quick Start & Distribution
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
### 1. Direct Script Tag (Zero Install via GitHub Pages CDN)
|
|
56
55
|
|
|
57
|
-
```
|
|
58
|
-
src/
|
|
59
|
-
├── guards/ # Validates container & bindings array
|
|
60
|
-
│ ├── container/ # Resolves 1st input (container ID or DOM element)
|
|
61
|
-
│ ├── bindings/ # Filters and validates 2nd input (bindings array)
|
|
62
|
-
│ └── index.js
|
|
63
|
-
├── prepare/ # Groups bindings by event type into Map
|
|
64
|
-
│ ├── groupBindings.js
|
|
65
|
-
│ └── index.js
|
|
66
|
-
├── listeners/ # Attaches single container listener per event type
|
|
67
|
-
│ ├── attachListener.js
|
|
68
|
-
│ └── index.js
|
|
69
|
-
├── dispatch/ # Handles event bubbling, target matching & execution
|
|
70
|
-
│ ├── getStartInput.js
|
|
71
|
-
│ ├── getClientData.js
|
|
72
|
-
│ ├── executeBinding.js
|
|
73
|
-
│ └── index.js
|
|
74
|
-
├── register/ # Exposes module onto window.ks.domPrimitiveBindings
|
|
75
|
-
│ ├── meta.js
|
|
76
|
-
│ └── index.js
|
|
77
|
-
└── index.js # Orchestrator
|
|
56
|
+
```html
|
|
57
|
+
<script type="module" src="https://keshavsoft.github.io/dom-primitive-bindings/dist/v4/min.js"></script>
|
|
78
58
|
```
|
|
79
59
|
|
|
80
|
-
|
|
81
|
-
1. **Zero Comments:** The folder hierarchy and descriptive file names convey the full narrative without inline code comments.
|
|
82
|
-
2. **Folder Discipline:** Every folder contains an `index.js` public gateway.
|
|
83
|
-
3. **Single Function Default Export:** No default export objects; every file exports a single function.
|
|
84
|
-
4. **Declarative JSON:** Bindings are defined in serializable `bindings.json` files.
|
|
60
|
+
Or always use the latest build:
|
|
85
61
|
|
|
86
|
-
|
|
62
|
+
```html
|
|
63
|
+
<script type="module" src="https://keshavsoft.github.io/dom-primitive-bindings/dist/min.js"></script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. ES Module Import in JavaScript
|
|
87
67
|
|
|
88
|
-
|
|
68
|
+
```javascript
|
|
69
|
+
import { bindEvents } from "https://keshavsoft.github.io/dom-primitive-bindings/dist/v4/min.js";
|
|
70
|
+
```
|
|
89
71
|
|
|
90
|
-
|
|
72
|
+
### 3. NPM Package
|
|
91
73
|
|
|
92
74
|
```bash
|
|
93
|
-
npm install
|
|
94
|
-
npm run dev
|
|
75
|
+
npm install dom-primitive-bindings
|
|
95
76
|
```
|
|
96
77
|
|
|
97
|
-
Open in Chrome or Edge:
|
|
98
|
-
- **`samples/v3/tableWithSearch/`** — Declarative table row clicks and live Enter-key search input loaded from `bindings.json`.
|
|
99
|
-
- **`samples/v3/cardGrid/`** — Declarative card button and card body click bindings loaded from `bindings.json`.
|
|
100
|
-
- **`samples/v3/formEvents/`** — Declarative input, change, and button click bindings loaded from `bindings.json`.
|
|
101
|
-
|
|
102
78
|
---
|
|
103
79
|
|
|
104
|
-
## 📦 Usage
|
|
80
|
+
## 📦 Usage Example
|
|
105
81
|
|
|
106
82
|
### 1. Declare `bindings.json`
|
|
107
83
|
|
|
@@ -109,40 +85,46 @@ Open in Chrome or Edge:
|
|
|
109
85
|
[
|
|
110
86
|
{
|
|
111
87
|
"event": "click",
|
|
112
|
-
"selector": "
|
|
88
|
+
"selector": "#rakaBtn",
|
|
89
|
+
"narration": "Load and populate Raka columns JSON into editor"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"event": "click",
|
|
93
|
+
"selector": "#templateBtn",
|
|
94
|
+
"narration": "Load and populate template JSON into editor"
|
|
113
95
|
},
|
|
114
96
|
{
|
|
115
|
-
"event": "
|
|
116
|
-
"selector": "
|
|
97
|
+
"event": "click",
|
|
98
|
+
"selector": "#buildBtn",
|
|
99
|
+
"narration": "Transform columns with template and display output in editor"
|
|
117
100
|
}
|
|
118
101
|
]
|
|
119
102
|
```
|
|
120
103
|
|
|
121
|
-
### 2.
|
|
104
|
+
### 2. Delegate with `bindEvents`
|
|
122
105
|
|
|
123
106
|
```javascript
|
|
107
|
+
import { bindEvents } from "https://keshavsoft.github.io/dom-primitive-bindings/dist/v4/min.js";
|
|
124
108
|
import bindings from "./bindings.json" with { type: "json" };
|
|
125
|
-
import { bindEvents } from "dom-primitive-bindings";
|
|
126
|
-
|
|
127
|
-
bindEvents("container-id", bindings);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Or via global browser script:
|
|
131
109
|
|
|
132
|
-
|
|
133
|
-
<script type="module" src="./docs/dist/v3/min.js"></script>
|
|
134
|
-
<script type="module">
|
|
135
|
-
import bindings from "./bindings.json" with { type: "json" };
|
|
136
|
-
window.ks.domPrimitiveBindings.bindEvents("container-id", bindings);
|
|
137
|
-
</script>
|
|
110
|
+
bindEvents("app-container", bindings);
|
|
138
111
|
```
|
|
139
112
|
|
|
140
113
|
---
|
|
141
114
|
|
|
142
|
-
##
|
|
115
|
+
## 🏗️ Staged Pipeline Architecture
|
|
116
|
+
|
|
117
|
+
The engine enforces a decoupled pipeline where every directory contains an `index.js` public gateway:
|
|
143
118
|
|
|
144
|
-
|
|
145
|
-
|
|
119
|
+
```text
|
|
120
|
+
src/v4/
|
|
121
|
+
├── guards/ # Validates container & bindings array before execution
|
|
122
|
+
├── prepare/ # Groups bindings by event type into Map
|
|
123
|
+
├── listeners/ # Attaches single container listener per event type
|
|
124
|
+
├── dispatch/ # Handles event bubbling, target matching (closest) & execution
|
|
125
|
+
├── register/ # Exposes module onto window.ks.domPrimitiveBindings
|
|
126
|
+
└── index.js # Orchestrator
|
|
127
|
+
```
|
|
146
128
|
|
|
147
129
|
---
|
|
148
130
|
|
|
@@ -152,12 +134,20 @@ Or via global browser script:
|
|
|
152
134
|
# Run unit tests
|
|
153
135
|
npm test
|
|
154
136
|
|
|
155
|
-
# Build production bundle
|
|
156
|
-
|
|
137
|
+
# Build production bundle using build-cli
|
|
138
|
+
npx @keshavsoft/build-cli build
|
|
157
139
|
```
|
|
158
140
|
|
|
159
141
|
---
|
|
160
142
|
|
|
143
|
+
## 🔗 Useful Links
|
|
144
|
+
|
|
145
|
+
- **Live Documentation**: [https://keshavsoft.github.io/dom-primitive-bindings/](https://keshavsoft.github.io/dom-primitive-bindings/)
|
|
146
|
+
- **Copyable Script Links**: [https://keshavsoft.github.io/dom-primitive-bindings/usage/](https://keshavsoft.github.io/dom-primitive-bindings/usage/)
|
|
147
|
+
- **NPM Package**: [https://www.npmjs.com/package/dom-primitive-bindings](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
161
151
|
## 📄 License
|
|
162
152
|
|
|
163
153
|
MIT © KeshavSoft
|
package/package.json
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dom-primitive-bindings",
|
|
3
|
-
"version": "1.3
|
|
4
|
-
"description": "Declarative, instruction-driven DOM delegated event bindings",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "KeshavSoft",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/keshavsoft/dom-primitive-bindings.git"
|
|
11
|
-
},
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/keshavsoft/dom-primitive-bindings/issues"
|
|
14
|
-
},
|
|
15
|
-
"homepage": "https://github.com/keshavsoft/dom-primitive-bindings#readme",
|
|
16
|
-
"main": "./src/index.js",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": "./src/index.js"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"src
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"scripts": {
|
|
28
|
-
"dev": "vite",
|
|
29
|
-
"build": "vite build",
|
|
30
|
-
"preview": "vite preview",
|
|
31
|
-
"test": "node --test"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"vite": "^6.4.1"
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dom-primitive-bindings",
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"description": "Declarative, instruction-driven DOM delegated event bindings",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "KeshavSoft",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/keshavsoft/dom-primitive-bindings.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/keshavsoft/dom-primitive-bindings/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/keshavsoft/dom-primitive-bindings#readme",
|
|
16
|
+
"main": "./src/index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"devDependencies": {}
|
|
36
27
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./v7/index.js";
|
|
2
|
+
|
|
3
|
+
export { default } from "./v7/index.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import getStartInput from "./getStartInput.js";
|
|
2
|
-
import getClientData from "./getClientData.js";
|
|
3
|
-
|
|
4
|
-
const executeBinding = ({ binding, event, matchElement }) => {
|
|
5
|
-
const startInput = getStartInput(binding, event, matchElement);
|
|
6
|
-
const clientData = getClientData(binding, event, matchElement);
|
|
7
|
-
const runner = binding.runner;
|
|
8
|
-
|
|
9
|
-
const result = typeof runner === "function"
|
|
10
|
-
? runner(startInput, binding.instructions, clientData)
|
|
11
|
-
: startInput;
|
|
12
|
-
|
|
13
|
-
if (result !== null && result !== undefined && typeof binding.onExtract === "function") {
|
|
14
|
-
binding.onExtract(result, event, matchElement);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return result;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default executeBinding;
|
|
21
|
-
|
|
1
|
+
import getStartInput from "./getStartInput.js";
|
|
2
|
+
import getClientData from "./getClientData.js";
|
|
3
|
+
|
|
4
|
+
const executeBinding = ({ binding, event, matchElement }) => {
|
|
5
|
+
const startInput = getStartInput(binding, event, matchElement);
|
|
6
|
+
const clientData = getClientData(binding, event, matchElement);
|
|
7
|
+
const runner = binding.runner;
|
|
8
|
+
|
|
9
|
+
const result = typeof runner === "function"
|
|
10
|
+
? runner(startInput, binding.instructions, clientData)
|
|
11
|
+
: startInput;
|
|
12
|
+
|
|
13
|
+
if (result !== null && result !== undefined && typeof binding.onExtract === "function") {
|
|
14
|
+
binding.onExtract(result, event, matchElement);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default executeBinding;
|
|
21
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const getClientData = (binding, event, matchElement) => ({
|
|
2
|
-
...binding.clientData,
|
|
3
|
-
event,
|
|
4
|
-
targetElement: matchElement
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
export default getClientData;
|
|
8
|
-
|
|
1
|
+
const getClientData = (binding, event, matchElement) => ({
|
|
2
|
+
...binding.clientData,
|
|
3
|
+
event,
|
|
4
|
+
targetElement: matchElement
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export default getClientData;
|
|
8
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const getStartInput = (binding, event, matchElement) => {
|
|
2
|
-
if (binding.root === "event" || event?.type?.startsWith("key")) {
|
|
3
|
-
return event;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return matchElement;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default getStartInput;
|
|
10
|
-
|
|
1
|
+
const getStartInput = (binding, event, matchElement) => {
|
|
2
|
+
if (binding.root === "event" || event?.type?.startsWith("key")) {
|
|
3
|
+
return event;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return matchElement;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default getStartInput;
|
|
10
|
+
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import executeBinding from "./executeBinding.js";
|
|
2
|
-
|
|
3
|
-
const dispatchEvent = ({ bindings, event, container }) => {
|
|
4
|
-
for (const binding of bindings) {
|
|
5
|
-
const matchElement = event.target?.closest?.(binding.selector);
|
|
6
|
-
if (!matchElement || !container.contains(matchElement)) {
|
|
7
|
-
continue;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
executeBinding({ binding, event, matchElement });
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default dispatchEvent;
|
|
15
|
-
|
|
1
|
+
import executeBinding from "./executeBinding.js";
|
|
2
|
+
|
|
3
|
+
const dispatchEvent = ({ bindings, event, container }) => {
|
|
4
|
+
for (const binding of bindings) {
|
|
5
|
+
const matchElement = event.target?.closest?.(binding.selector);
|
|
6
|
+
if (!matchElement || !container.contains(matchElement)) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
executeBinding({ binding, event, matchElement });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default dispatchEvent;
|
|
15
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import validateArray from "./validateArray.js";
|
|
2
|
-
|
|
3
|
-
const checkBindings = (bindings) => {
|
|
4
|
-
const valid = validateArray(bindings);
|
|
5
|
-
if (valid.length === 0) return null;
|
|
6
|
-
|
|
7
|
-
return valid;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default checkBindings;
|
|
11
|
-
|
|
1
|
+
import validateArray from "./validateArray.js";
|
|
2
|
+
|
|
3
|
+
const checkBindings = (bindings) => {
|
|
4
|
+
const valid = validateArray(bindings);
|
|
5
|
+
if (valid.length === 0) return null;
|
|
6
|
+
|
|
7
|
+
return valid;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default checkBindings;
|
|
11
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const validateArray = (bindings) => {
|
|
2
|
-
if (!Array.isArray(bindings)) return [];
|
|
3
|
-
|
|
4
|
-
return bindings.filter((binding) => (
|
|
5
|
-
binding && typeof binding === "object" && typeof binding.event === "string" && typeof binding.selector === "string"
|
|
6
|
-
));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default validateArray;
|
|
10
|
-
|
|
1
|
+
const validateArray = (bindings) => {
|
|
2
|
+
if (!Array.isArray(bindings)) return [];
|
|
3
|
+
|
|
4
|
+
return bindings.filter((binding) => (
|
|
5
|
+
binding && typeof binding === "object" && typeof binding.event === "string" && typeof binding.selector === "string"
|
|
6
|
+
));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default validateArray;
|
|
10
|
+
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import resolveElement from "./resolveElement.js";
|
|
2
|
-
|
|
3
|
-
const checkContainer = (containerOrId) => {
|
|
4
|
-
if (!containerOrId) return null;
|
|
5
|
-
|
|
6
|
-
const element = resolveElement(containerOrId);
|
|
7
|
-
if (!element) return null;
|
|
8
|
-
|
|
9
|
-
return element;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export default checkContainer;
|
|
13
|
-
|
|
1
|
+
import resolveElement from "./resolveElement.js";
|
|
2
|
+
|
|
3
|
+
const checkContainer = (containerOrId) => {
|
|
4
|
+
if (!containerOrId) return null;
|
|
5
|
+
|
|
6
|
+
const element = resolveElement(containerOrId);
|
|
7
|
+
if (!element) return null;
|
|
8
|
+
|
|
9
|
+
return element;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default checkContainer;
|
|
13
|
+
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const resolveElement = (containerOrId) => {
|
|
2
|
-
if (typeof containerOrId === "string") {
|
|
3
|
-
return document.getElementById(containerOrId) || document.querySelector(containerOrId);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (containerOrId && typeof containerOrId === "object" && "addEventListener" in containerOrId) {
|
|
7
|
-
return containerOrId;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return null;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default resolveElement;
|
|
14
|
-
|
|
1
|
+
const resolveElement = (containerOrId) => {
|
|
2
|
+
if (typeof containerOrId === "string") {
|
|
3
|
+
return document.getElementById(containerOrId) || document.querySelector(containerOrId);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (containerOrId && typeof containerOrId === "object" && "addEventListener" in containerOrId) {
|
|
7
|
+
return containerOrId;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default resolveElement;
|
|
14
|
+
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import checkContainer from "./container/index.js";
|
|
2
|
-
import checkBindings from "./bindings/index.js";
|
|
3
|
-
|
|
4
|
-
const runGuards = (containerOrId, bindings) => {
|
|
5
|
-
const container = checkContainer(containerOrId);
|
|
6
|
-
if (!container) return null;
|
|
7
|
-
|
|
8
|
-
const validBindings = checkBindings(bindings);
|
|
9
|
-
if (!validBindings) return null;
|
|
10
|
-
|
|
11
|
-
return { container, bindings: validBindings };
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default runGuards;
|
|
15
|
-
|
|
1
|
+
import checkContainer from "./container/index.js";
|
|
2
|
+
import checkBindings from "./bindings/index.js";
|
|
3
|
+
|
|
4
|
+
const runGuards = (containerOrId, bindings) => {
|
|
5
|
+
const container = checkContainer(containerOrId);
|
|
6
|
+
if (!container) return null;
|
|
7
|
+
|
|
8
|
+
const validBindings = checkBindings(bindings);
|
|
9
|
+
if (!validBindings) return null;
|
|
10
|
+
|
|
11
|
+
return { container, bindings: validBindings };
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default runGuards;
|
|
15
|
+
|
package/src/{v3 → v5}/index.js
RENAMED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import registerGlobal from "./register/index.js";
|
|
2
|
-
import runGuards from "./guards/index.js";
|
|
3
|
-
import prepareBindings from "./prepare/index.js";
|
|
4
|
-
import attachListeners from "./listeners/index.js";
|
|
5
|
-
|
|
6
|
-
const bindEvents = (containerOrId, bindings = []) => {
|
|
7
|
-
const guarded = runGuards(containerOrId, bindings);
|
|
8
|
-
if (!guarded) return null;
|
|
9
|
-
|
|
10
|
-
const { container, bindings: validBindings } = guarded;
|
|
11
|
-
const eventGroups = prepareBindings(validBindings);
|
|
12
|
-
|
|
13
|
-
attachListeners(container, eventGroups);
|
|
14
|
-
|
|
15
|
-
return container;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { bindEvents };
|
|
19
|
-
export default bindEvents;
|
|
20
|
-
|
|
21
|
-
registerGlobal(bindEvents);
|
|
22
|
-
|
|
1
|
+
import registerGlobal from "./register/index.js";
|
|
2
|
+
import runGuards from "./guards/index.js";
|
|
3
|
+
import prepareBindings from "./prepare/index.js";
|
|
4
|
+
import attachListeners from "./listeners/index.js";
|
|
5
|
+
|
|
6
|
+
const bindEvents = (containerOrId, bindings = [], actions = {}) => {
|
|
7
|
+
const guarded = runGuards(containerOrId, bindings);
|
|
8
|
+
if (!guarded) return null;
|
|
9
|
+
|
|
10
|
+
const { container, bindings: validBindings } = guarded;
|
|
11
|
+
const eventGroups = prepareBindings(validBindings, actions);
|
|
12
|
+
|
|
13
|
+
attachListeners(container, eventGroups);
|
|
14
|
+
|
|
15
|
+
return container;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { bindEvents };
|
|
19
|
+
export default bindEvents;
|
|
20
|
+
|
|
21
|
+
registerGlobal(bindEvents);
|