dom-primitive-bindings 1.0.0 → 1.4.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/LICENSE +22 -22
- package/README.md +163 -126
- package/package.json +27 -36
- package/src/index.js +3 -3
- package/src/{v1 → v2}/dispatch/executeBinding.js +21 -21
- package/src/{v1 → v2}/dispatch/getClientData.js +8 -8
- package/src/{v1 → v2}/dispatch/getStartInput.js +10 -10
- package/src/{v1 → v2}/dispatch/index.js +15 -15
- package/src/{v1 → v2}/guards/bindings/index.js +11 -11
- package/src/{v1 → v2}/guards/bindings/validateArray.js +10 -10
- package/src/{v1 → v2}/guards/container/index.js +13 -13
- package/src/{v1 → v2}/guards/container/resolveElement.js +14 -14
- package/src/{v1 → v2}/guards/index.js +15 -15
- package/src/{v1 → v2}/index.js +22 -22
- package/src/{v1 → v2}/listeners/attachListener.js +10 -10
- package/src/{v1 → v2}/listeners/index.js +12 -12
- package/src/{v1 → v2}/prepare/groupBindings.js +14 -14
- package/src/{v1 → v2}/prepare/index.js +8 -8
- package/src/{v1 → v2}/register/index.js +18 -17
- package/src/{v1 → v2}/register/meta.js +6 -7
- package/src/v3/dispatch/executeBinding.js +21 -0
- package/src/v3/dispatch/getClientData.js +8 -0
- package/src/v3/dispatch/getStartInput.js +10 -0
- package/src/v3/dispatch/index.js +15 -0
- package/src/v3/guards/bindings/index.js +11 -0
- package/src/v3/guards/bindings/validateArray.js +10 -0
- package/src/v3/guards/container/index.js +13 -0
- package/src/v3/guards/container/resolveElement.js +14 -0
- package/src/v3/guards/index.js +15 -0
- package/src/v3/index.js +22 -0
- package/src/v3/listeners/attachListener.js +10 -0
- package/src/v3/listeners/index.js +12 -0
- package/src/v3/prepare/groupBindings.js +14 -0
- package/src/v3/prepare/index.js +8 -0
- package/src/v3/register/index.js +18 -0
- package/src/v3/register/meta.js +6 -0
- package/src/v4/dispatch/executeBinding.js +21 -0
- package/src/v4/dispatch/getClientData.js +8 -0
- package/src/v4/dispatch/getStartInput.js +10 -0
- package/src/v4/dispatch/index.js +15 -0
- package/src/v4/guards/bindings/index.js +11 -0
- package/src/v4/guards/bindings/validateArray.js +10 -0
- package/src/v4/guards/container/index.js +13 -0
- package/src/v4/guards/container/resolveElement.js +14 -0
- package/src/v4/guards/index.js +15 -0
- package/src/v4/index.js +22 -0
- package/src/v4/listeners/attachListener.js +10 -0
- package/src/v4/listeners/index.js +12 -0
- package/src/v4/prepare/groupBindings.js +14 -0
- package/src/v4/prepare/index.js +8 -0
- package/src/v4/register/index.js +18 -0
- package/src/v4/register/meta.js +6 -0
- package/docs/dist/min.js +0 -63
- package/docs/dist/v1/min.js +0 -63
- package/docs/index.html +0 -185
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,126 +1,163 @@
|
|
|
1
|
-
# DOM Primitive Bindings
|
|
2
|
-
|
|
3
|
-
> Modern, lightweight, delegated event engine for browser DOMs.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/dom-primitive-bindings)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[]()
|
|
8
|
+
[](./docs/index.html)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 📖 The 4-Part Event Delegation Story
|
|
13
|
+
|
|
14
|
+
Explore the interactive interactive story chapters in [`docs/stories/`](./docs/index.html):
|
|
15
|
+
|
|
16
|
+
1. **[Chapter 1: The Everyday Habit & The Listener Trap](./docs/stories/01-the-listener-trap.html)**
|
|
17
|
+
Why attaching listeners to individual elements causes memory leaks, double-trigger cascades, and dead-zones on dynamic elements.
|
|
18
|
+
2. **[Chapter 2: The Delegation Epiphany](./docs/stories/02-the-delegation-epiphany.html)**
|
|
19
|
+
Harnessing browser event bubbling: 1 container listener catching bubbling events forever.
|
|
20
|
+
3. **[Chapter 3: The Staged Pipeline Architecture](./docs/stories/03-the-staged-pipeline.html)**
|
|
21
|
+
Inside the decoupled 4-stage pipeline: `guards` $\to$ `prepare` $\to$ `listeners` $\to$ `dispatch`.
|
|
22
|
+
4. **[Chapter 4: The Joy of Declarative JSON](./docs/stories/04-declarative-json-bindings.html)**
|
|
23
|
+
Moving from imperative JavaScript arrays to clean, serializable `bindings.json` specifications with a live interactive demo.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🎯 The Philosophy: The Wiring Layer
|
|
28
|
+
|
|
29
|
+
A common mistake in UI architecture is conflating **event wiring** with **DOM manipulation** or **data extraction**:
|
|
30
|
+
|
|
31
|
+
- **`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 table schemas into objects.
|
|
33
|
+
- **`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")`, column mapping) to produce clean JSON.
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
[ User Action in Browser ]
|
|
38
|
+
│
|
|
39
|
+
▼
|
|
40
|
+
┌───────────────────────────────┐
|
|
41
|
+
│ dom-primitive-bindings │ ◄── Wiring Layer: Catches event & matches target
|
|
42
|
+
│ (guards → prepare → dispatch)│
|
|
43
|
+
└──────────────┬────────────────┘
|
|
44
|
+
│ delivers { event, targetElement }
|
|
45
|
+
▼
|
|
46
|
+
┌───────────────────────────────┐
|
|
47
|
+
│ Consumer / App Logic │ ◄── Extraction (dom-primitive-engine) or App Handler
|
|
48
|
+
└───────────────────────────────┘
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🏗️ Staged Architecture (`src/v3/`)
|
|
54
|
+
|
|
55
|
+
The engine enforces a staged pipeline where every directory contains an `index.js` and all files export a single function as `default`:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
src/v3/
|
|
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
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Key Design Disciplines
|
|
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.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 🚀 Interactive Browser Samples (`samples/v3/`)
|
|
89
|
+
|
|
90
|
+
Start the Vite development server to view and interact with real browser DOM events:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install
|
|
94
|
+
npm run dev
|
|
95
|
+
```
|
|
96
|
+
|
|
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
|
+
---
|
|
103
|
+
|
|
104
|
+
## 📦 Usage
|
|
105
|
+
|
|
106
|
+
### 1. Declare `bindings.json`
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
[
|
|
110
|
+
{
|
|
111
|
+
"event": "click",
|
|
112
|
+
"selector": ".btn-action"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"event": "keydown",
|
|
116
|
+
"selector": "input[type='search']"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 2. Run with `bindEvents`
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
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
|
+
|
|
132
|
+
```html
|
|
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>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📚 Technical Specifications
|
|
143
|
+
|
|
144
|
+
- **[Architecture & Design Story](./docs/architecture.md)**: Deep dive into the 4 internal stages and data flow.
|
|
145
|
+
- **[Binding Specification Schema](./docs/binding-spec.md)**: Complete property reference for `bindings.json`.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 🧪 Testing & Build
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Run unit tests
|
|
153
|
+
npm test
|
|
154
|
+
|
|
155
|
+
# Build production bundle to docs/dist/v3/min.js
|
|
156
|
+
npm run build
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 📄 License
|
|
162
|
+
|
|
163
|
+
MIT © KeshavSoft
|
package/package.json
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dom-primitive-bindings",
|
|
3
|
-
"version": "1.
|
|
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
|
-
|
|
28
|
-
"dev": "vite",
|
|
29
|
-
"build": "vite build",
|
|
30
|
-
"preview": "vite preview",
|
|
31
|
-
"test": "node --test"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"vite": "^6.4.1"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dom-primitive-bindings",
|
|
3
|
+
"version": "1.4.1",
|
|
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": {}
|
|
27
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./v4/index.js";
|
|
2
|
+
|
|
3
|
+
export { default } from "./v4/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
|
+
|