dom-primitive-bindings 1.7.3 → 1.9.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 +171 -153
- package/package.json +4 -2
- package/src/index.js +2 -2
- package/src/v6/guards/actions/index.js +21 -21
- package/src/v6/guards/bindings/index.js +5 -5
- package/src/v6/guards/bindings/validateArray.js +23 -23
- package/src/v6/guards/bindings/validateBinding.js +22 -22
- package/src/v6/guards/index.js +19 -19
- package/src/v6/index.js +21 -21
- package/src/v6/prepare/index.js +23 -23
- package/src/v6/register/meta.js +6 -6
- package/src/v7/guards/actions/index.js +21 -21
- package/src/v7/guards/bindings/index.js +5 -5
- package/src/v7/guards/bindings/validateArray.js +23 -23
- package/src/v7/guards/bindings/validateBinding.js +22 -22
- package/src/v7/guards/index.js +19 -19
- package/src/v7/index.js +43 -43
- package/src/v7/prepare/index.js +23 -23
- package/src/v7/register/index.js +18 -18
- package/src/v7/register/meta.js +6 -6
- package/src/v7/sample/index.js +22 -22
- package/src/v8/dispatch/executeBinding.js +21 -0
- package/src/v8/dispatch/getClientData.js +8 -0
- package/src/v8/dispatch/getStartInput.js +10 -0
- package/src/v8/dispatch/index.js +15 -0
- package/src/v8/guards/actions/index.js +21 -0
- package/src/v8/guards/bindings/index.js +5 -0
- package/src/v8/guards/bindings/validateArray.js +23 -0
- package/src/v8/guards/bindings/validateBinding.js +22 -0
- package/src/v8/guards/container/index.js +13 -0
- package/src/v8/guards/container/resolveElement.js +14 -0
- package/src/v8/guards/index.js +19 -0
- package/src/v8/index.js +37 -0
- package/src/v8/listeners/attachListener.js +10 -0
- package/src/v8/listeners/index.js +12 -0
- package/src/v8/prepare/groupBindings.js +14 -0
- package/src/v8/prepare/index.js +23 -0
- package/src/v8/register/index.js +15 -0
- package/src/v8/register/meta.js +6 -0
- package/src/v8/sample/index.js +22 -0
- package/src/v9/dispatch/index.js +7 -0
- package/src/v9/guards/actions/index.js +27 -0
- package/src/v9/guards/bindings/index.js +5 -0
- package/src/v9/guards/bindings/validateArray.js +23 -0
- package/src/v9/guards/bindings/validateBinding.js +22 -0
- package/src/v9/guards/container/index.js +13 -0
- package/src/v9/guards/container/resolveElement.js +14 -0
- package/src/v9/guards/index.js +19 -0
- package/src/v9/index.js +21 -0
- package/src/v9/listeners/attachListener.js +9 -0
- package/src/v9/listeners/index.js +12 -0
- package/src/v9/prepare/groupBindings.js +14 -0
- package/src/v9/prepare/index.js +12 -0
- package/src/v9/register/index.js +15 -0
- package/src/v9/register/meta.js +2 -0
- package/src/v9/sample/index.js +12 -0
package/README.md
CHANGED
|
@@ -1,153 +1,171 @@
|
|
|
1
|
-
# DOM Primitive Bindings
|
|
2
|
-
|
|
3
|
-
> Browser-native, single-listener container event delegation driven by declarative JSON instructions.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://keshavsoft.github.io/dom-primitive-bindings/)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## 🌐 Live Documentation & Interactive Story
|
|
12
|
-
|
|
13
|
-
Explore the complete interactive story and live samples on **[GitHub Pages](https://keshavsoft.github.io/dom-primitive-bindings/)**:
|
|
14
|
-
|
|
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. **[
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
┌───────────────────────────────┐
|
|
46
|
-
│
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```html
|
|
63
|
-
<script type="module" src="https://keshavsoft.github.io/dom-primitive-bindings/dist/min.js"></script>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
###
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
# DOM Primitive Bindings
|
|
2
|
+
|
|
3
|
+
> Browser-native, single-listener container event delegation driven by declarative JSON instructions.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://keshavsoft.github.io/dom-primitive-bindings/)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🌐 Live Documentation & Interactive Story
|
|
12
|
+
|
|
13
|
+
Explore the complete interactive story and live samples on **[GitHub Pages](https://keshavsoft.github.io/dom-primitive-bindings/)**:
|
|
14
|
+
|
|
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. **[Chapter 4: The Declarative Transformation](https://keshavsoft.github.io/dom-primitive-bindings/stories/04-declarative-json-bindings.html)** ([local](./docs/stories/04-declarative-json-bindings.html))
|
|
22
|
+
Moving from imperative JavaScript arrays to serializable `bindings.json` specifications.
|
|
23
|
+
5. **[Chapter 5: The Pure 3-File Architecture (v7)](https://keshavsoft.github.io/dom-primitive-bindings/stories/05-the-three-file-architecture.html)** ([local](./docs/stories/05-the-three-file-architecture.html))
|
|
24
|
+
The ultimate standard: cleanly decoupling `bindings.json` (Blueprint), `actions.js` (Behavior), and `index.js` (Wiring) at every folder level.
|
|
25
|
+
6. **[Usage & Available Builds](https://keshavsoft.github.io/dom-primitive-bindings/usage/)** ([local](./docs/usage/index.html))
|
|
26
|
+
Available builds hosted on GitHub Pages CDN with one-click copyable script tags and ES Module imports.
|
|
27
|
+
7. **[Interactive v7 Showcase](https://keshavsoft.github.io/dom-primitive-bindings/samples/v7/)** ([local](./samples/v7/index.html))
|
|
28
|
+
Live in-browser demonstrations: Card Grid delegation, Table with live search filtering, and Form controls.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 🎯 The Philosophy: The Wiring Layer
|
|
33
|
+
|
|
34
|
+
A common mistake in UI architecture is conflating **event wiring** with **DOM manipulation** or **data extraction**:
|
|
35
|
+
|
|
36
|
+
- **`dom-primitive-bindings` (This Repository):**
|
|
37
|
+
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.
|
|
38
|
+
- **`dom-primitive-engine` (Sibling Repository):**
|
|
39
|
+
Pure **Extraction Layer**. Receives the matched target element and executes declarative instruction pipelines (e.g. `closest("tr")`, `querySelectorAll("td")`) to produce clean JSON.
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
[ User Action in Browser ]
|
|
43
|
+
│
|
|
44
|
+
▼
|
|
45
|
+
┌───────────────────────────────┐
|
|
46
|
+
│ dom-primitive-bindings │ ◄── Wiring Layer: Catches bubbling event & matches target
|
|
47
|
+
│ (guards → prepare → dispatch)│
|
|
48
|
+
└──────────────┬────────────────┘
|
|
49
|
+
│ delivers { event, targetElement }
|
|
50
|
+
▼
|
|
51
|
+
┌───────────────────────────────┐
|
|
52
|
+
│ Consumer / App Logic │ ◄── Extraction (dom-primitive-engine) or Action Handler
|
|
53
|
+
└───────────────────────────────┘
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## ⚡ Quick Start & Distribution
|
|
59
|
+
|
|
60
|
+
### 1. Direct Script Tag (Zero Install via GitHub Pages CDN)
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<script type="module" src="https://keshavsoft.github.io/dom-primitive-bindings/dist/v7/min.js"></script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or always use the latest build:
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<script type="module" src="https://keshavsoft.github.io/dom-primitive-bindings/dist/min.js"></script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. ES Module Import in JavaScript
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
import { bindEvents } from "https://keshavsoft.github.io/dom-primitive-bindings/dist/v7/min.js";
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. NPM Package
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install dom-primitive-bindings
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📦 The 3-File Standard Usage Example (v7)
|
|
87
|
+
|
|
88
|
+
### 1. Declare `bindings.json` (The Blueprint)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
[
|
|
92
|
+
{
|
|
93
|
+
"event": "click",
|
|
94
|
+
"selector": "#rakaBtn",
|
|
95
|
+
"action": "loadRaka"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"event": "click",
|
|
99
|
+
"selector": "#buildBtn",
|
|
100
|
+
"action": "buildOutput"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2. Declare `actions.js` (The Behaviors)
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
export const actions = {
|
|
109
|
+
loadRaka: (event, matchElement) => {
|
|
110
|
+
console.log("Loading Raka columns into editor...");
|
|
111
|
+
},
|
|
112
|
+
buildOutput: (event, matchElement) => {
|
|
113
|
+
console.log("Transforming and rendering output...");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export default actions;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 3. Delegate with `index.js` (The Orchestrator)
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
import bindings from "./bindings.json" with { type: "json" };
|
|
124
|
+
import actions from "./actions.js";
|
|
125
|
+
import { bindEvents } from "dom-primitive-bindings";
|
|
126
|
+
|
|
127
|
+
// Single container listener intercepts bubbling events and dispatches to actions
|
|
128
|
+
bindEvents("app-container", bindings, actions);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 🏗️ Staged Pipeline Architecture
|
|
134
|
+
|
|
135
|
+
The engine enforces a decoupled pipeline where every directory contains an `index.js` public gateway:
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
src/v7/
|
|
139
|
+
├── guards/ # Validates container, bindings array, and actions object
|
|
140
|
+
├── prepare/ # Groups bindings by event type into Map & wires action mappings
|
|
141
|
+
├── listeners/ # Attaches single container listener per event type
|
|
142
|
+
├── dispatch/ # Handles event bubbling, target matching (closest) & execution
|
|
143
|
+
├── register/ # Exposes module onto globalThis.ks.domPrimitiveBindings
|
|
144
|
+
└── index.js # Orchestrator
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 🧪 Testing & Build
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Run unit tests
|
|
153
|
+
npm test
|
|
154
|
+
|
|
155
|
+
# Build production bundle using build-cli
|
|
156
|
+
npx @keshavsoft/build-cli build
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 🔗 Useful Links
|
|
162
|
+
|
|
163
|
+
- **Live Documentation**: [https://keshavsoft.github.io/dom-primitive-bindings/](https://keshavsoft.github.io/dom-primitive-bindings/)
|
|
164
|
+
- **Copyable Script Links**: [https://keshavsoft.github.io/dom-primitive-bindings/usage/](https://keshavsoft.github.io/dom-primitive-bindings/usage/)
|
|
165
|
+
- **NPM Package**: [https://www.npmjs.com/package/dom-primitive-bindings](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 📄 License
|
|
170
|
+
|
|
171
|
+
MIT © KeshavSoft
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dom-primitive-bindings",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "Declarative, instruction-driven DOM delegated event bindings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"README.md",
|
|
23
23
|
"LICENSE"
|
|
24
24
|
],
|
|
25
|
-
"scripts": {
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "npx @keshavsoft/build-cli"
|
|
27
|
+
},
|
|
26
28
|
"devDependencies": {}
|
|
27
29
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v9/index.js";
|
|
2
2
|
|
|
3
|
-
export { default } from "./
|
|
3
|
+
export { default } from "./v9/index.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const isPlainObject = (value) => {
|
|
2
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3
|
-
const prototype = Object.getPrototypeOf(value);
|
|
4
|
-
return prototype === Object.prototype || prototype === null;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const checkActions = (actions = {}) => {
|
|
8
|
-
if (!isPlainObject(actions)) {
|
|
9
|
-
throw new TypeError("actions must be a plain, flat object.");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
for (const [name, action] of Object.entries(actions)) {
|
|
13
|
-
if (typeof action !== "function") {
|
|
14
|
-
throw new TypeError(`actions.${name} must be a function.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return actions;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default checkActions;
|
|
1
|
+
const isPlainObject = (value) => {
|
|
2
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3
|
+
const prototype = Object.getPrototypeOf(value);
|
|
4
|
+
return prototype === Object.prototype || prototype === null;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const checkActions = (actions = {}) => {
|
|
8
|
+
if (!isPlainObject(actions)) {
|
|
9
|
+
throw new TypeError("actions must be a plain, flat object.");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
for (const [name, action] of Object.entries(actions)) {
|
|
13
|
+
if (typeof action !== "function") {
|
|
14
|
+
throw new TypeError(`actions.${name} must be a function.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return actions;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default checkActions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import validateArray from "./validateArray.js";
|
|
2
|
-
|
|
3
|
-
const checkBindings = (bindings) => validateArray(bindings);
|
|
4
|
-
|
|
5
|
-
export default checkBindings;
|
|
1
|
+
import validateArray from "./validateArray.js";
|
|
2
|
+
|
|
3
|
+
const checkBindings = (bindings) => validateArray(bindings);
|
|
4
|
+
|
|
5
|
+
export default checkBindings;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import validateBinding from "./validateBinding.js";
|
|
2
|
-
|
|
3
|
-
const validateArray = (bindings) => {
|
|
4
|
-
if (!Array.isArray(bindings)) {
|
|
5
|
-
throw new TypeError("bindings must be an array.");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (bindings.length === 0) {
|
|
9
|
-
throw new TypeError("bindings must contain at least one binding.");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
bindings.forEach((binding, index) => {
|
|
13
|
-
if (!validateBinding(binding)) {
|
|
14
|
-
throw new TypeError(
|
|
15
|
-
`bindings[${index}] must be an object with exactly three non-empty string properties: event, selector, and action.`
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return bindings;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default validateArray;
|
|
1
|
+
import validateBinding from "./validateBinding.js";
|
|
2
|
+
|
|
3
|
+
const validateArray = (bindings) => {
|
|
4
|
+
if (!Array.isArray(bindings)) {
|
|
5
|
+
throw new TypeError("bindings must be an array.");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (bindings.length === 0) {
|
|
9
|
+
throw new TypeError("bindings must contain at least one binding.");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
bindings.forEach((binding, index) => {
|
|
13
|
+
if (!validateBinding(binding)) {
|
|
14
|
+
throw new TypeError(
|
|
15
|
+
`bindings[${index}] must be an object with exactly three non-empty string properties: event, selector, and action.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return bindings;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default validateArray;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const bindingKeys = ["event", "selector", "action"];
|
|
2
|
-
|
|
3
|
-
const isPlainObject = (value) => {
|
|
4
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
5
|
-
const prototype = Object.getPrototypeOf(value);
|
|
6
|
-
return prototype === Object.prototype || prototype === null;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const validateBinding = (binding) => {
|
|
10
|
-
if (!isPlainObject(binding)) return false;
|
|
11
|
-
|
|
12
|
-
const keys = Object.keys(binding);
|
|
13
|
-
if (keys.length !== bindingKeys.length) return false;
|
|
14
|
-
if (!bindingKeys.every((key) => Object.hasOwn(binding, key))) return false;
|
|
15
|
-
|
|
16
|
-
return bindingKeys.every((key) => (
|
|
17
|
-
typeof binding[key] === "string" && binding[key].trim().length > 0
|
|
18
|
-
));
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { bindingKeys, isPlainObject };
|
|
22
|
-
export default validateBinding;
|
|
1
|
+
const bindingKeys = ["event", "selector", "action"];
|
|
2
|
+
|
|
3
|
+
const isPlainObject = (value) => {
|
|
4
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
5
|
+
const prototype = Object.getPrototypeOf(value);
|
|
6
|
+
return prototype === Object.prototype || prototype === null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const validateBinding = (binding) => {
|
|
10
|
+
if (!isPlainObject(binding)) return false;
|
|
11
|
+
|
|
12
|
+
const keys = Object.keys(binding);
|
|
13
|
+
if (keys.length !== bindingKeys.length) return false;
|
|
14
|
+
if (!bindingKeys.every((key) => Object.hasOwn(binding, key))) return false;
|
|
15
|
+
|
|
16
|
+
return bindingKeys.every((key) => (
|
|
17
|
+
typeof binding[key] === "string" && binding[key].trim().length > 0
|
|
18
|
+
));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { bindingKeys, isPlainObject };
|
|
22
|
+
export default validateBinding;
|
package/src/v6/guards/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import checkContainer from "./container/index.js";
|
|
2
|
-
import checkBindings from "./bindings/index.js";
|
|
3
|
-
import checkActions from "./actions/index.js";
|
|
4
|
-
|
|
5
|
-
const runGuards = (containerOrId, bindings, actions = {}) => {
|
|
6
|
-
const container = checkContainer(containerOrId);
|
|
7
|
-
if (!container) return null;
|
|
8
|
-
|
|
9
|
-
const validBindings = checkBindings(bindings);
|
|
10
|
-
const validActions = checkActions(actions);
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
container,
|
|
14
|
-
bindings: validBindings,
|
|
15
|
-
actions: validActions
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default runGuards;
|
|
1
|
+
import checkContainer from "./container/index.js";
|
|
2
|
+
import checkBindings from "./bindings/index.js";
|
|
3
|
+
import checkActions from "./actions/index.js";
|
|
4
|
+
|
|
5
|
+
const runGuards = (containerOrId, bindings, actions = {}) => {
|
|
6
|
+
const container = checkContainer(containerOrId);
|
|
7
|
+
if (!container) return null;
|
|
8
|
+
|
|
9
|
+
const validBindings = checkBindings(bindings);
|
|
10
|
+
const validActions = checkActions(actions);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
container,
|
|
14
|
+
bindings: validBindings,
|
|
15
|
+
actions: validActions
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default runGuards;
|
package/src/v6/index.js
CHANGED
|
@@ -1,21 +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 = [], actions = {}) => {
|
|
7
|
-
const guarded = runGuards(containerOrId, bindings, actions);
|
|
8
|
-
if (!guarded) return null;
|
|
9
|
-
|
|
10
|
-
const { container, bindings: validBindings } = guarded;
|
|
11
|
-
const eventGroups = prepareBindings(validBindings, guarded.actions);
|
|
12
|
-
|
|
13
|
-
attachListeners(container, eventGroups);
|
|
14
|
-
|
|
15
|
-
return container;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { bindEvents };
|
|
19
|
-
export default bindEvents;
|
|
20
|
-
|
|
21
|
-
registerGlobal(bindEvents);
|
|
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, actions);
|
|
8
|
+
if (!guarded) return null;
|
|
9
|
+
|
|
10
|
+
const { container, bindings: validBindings } = guarded;
|
|
11
|
+
const eventGroups = prepareBindings(validBindings, guarded.actions);
|
|
12
|
+
|
|
13
|
+
attachListeners(container, eventGroups);
|
|
14
|
+
|
|
15
|
+
return container;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { bindEvents };
|
|
19
|
+
export default bindEvents;
|
|
20
|
+
|
|
21
|
+
registerGlobal(bindEvents);
|
package/src/v6/prepare/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import groupBindings from "./groupBindings.js";
|
|
2
|
-
|
|
3
|
-
const prepareBindings = (bindings, actions = {}) => {
|
|
4
|
-
const hasActions = actions && typeof actions === "object" && Object.keys(actions).length > 0;
|
|
5
|
-
|
|
6
|
-
const configuredBindings = hasActions
|
|
7
|
-
? bindings.map((binding) => {
|
|
8
|
-
if (binding.action && typeof actions[binding.action] === "function" && typeof binding.onExtract !== "function") {
|
|
9
|
-
return {
|
|
10
|
-
...binding,
|
|
11
|
-
onExtract: (result, event, matchElement) => {
|
|
12
|
-
actions[binding.action](event, matchElement, result);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
return binding;
|
|
17
|
-
})
|
|
18
|
-
: bindings;
|
|
19
|
-
|
|
20
|
-
return groupBindings(configuredBindings);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default prepareBindings;
|
|
1
|
+
import groupBindings from "./groupBindings.js";
|
|
2
|
+
|
|
3
|
+
const prepareBindings = (bindings, actions = {}) => {
|
|
4
|
+
const hasActions = actions && typeof actions === "object" && Object.keys(actions).length > 0;
|
|
5
|
+
|
|
6
|
+
const configuredBindings = hasActions
|
|
7
|
+
? bindings.map((binding) => {
|
|
8
|
+
if (binding.action && typeof actions[binding.action] === "function" && typeof binding.onExtract !== "function") {
|
|
9
|
+
return {
|
|
10
|
+
...binding,
|
|
11
|
+
onExtract: (result, event, matchElement) => {
|
|
12
|
+
actions[binding.action](event, matchElement, result);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return binding;
|
|
17
|
+
})
|
|
18
|
+
: bindings;
|
|
19
|
+
|
|
20
|
+
return groupBindings(configuredBindings);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default prepareBindings;
|
package/src/v6/register/meta.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const meta = {
|
|
2
|
-
name: "dom-primitive-bindings",
|
|
3
|
-
version: "5.0.0"
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export default meta;
|
|
1
|
+
export const meta = {
|
|
2
|
+
name: "dom-primitive-bindings",
|
|
3
|
+
version: "5.0.0"
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export default meta;
|