@kudzujs/core 0.6.26 → 0.6.28
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/GOAL_A.md +1 -1
- package/README.md +53 -37
- package/framework/README.md +7 -3
- package/framework/binding-runtime.js +4 -2
- package/framework/build.mjs +397 -155
- package/framework/collection-selector.js +63 -0
- package/framework/core.d.ts +2 -1
- package/framework/core.mjs +80 -41
- package/framework/list-runtime.js +342 -96
- package/framework/native-runtime.js +13 -2
- package/framework/shared-runtime.js +18 -5
- package/package.json +1 -1
|
@@ -68,10 +68,21 @@ function mountNative(root, eventNames, modules) {
|
|
|
68
68
|
for (const node of matching(root, `[data-k-native-${eventName}]`)) {
|
|
69
69
|
const listeners = registrations.get(node) ?? new Map()
|
|
70
70
|
if (listeners.has(eventName)) continue
|
|
71
|
+
let encoded = node.dataset[`kNative${capitalize(eventName)}`]
|
|
72
|
+
let native = JSON.parse(encoded)
|
|
73
|
+
let handler
|
|
74
|
+
let context = createNativeContext(browserState, native.states, commitDom, native.scope)
|
|
71
75
|
const listener = event => {
|
|
72
76
|
try {
|
|
73
|
-
const
|
|
74
|
-
|
|
77
|
+
const current = node.dataset[`kNative${capitalize(eventName)}`]
|
|
78
|
+
if (current !== encoded) {
|
|
79
|
+
native = JSON.parse(current)
|
|
80
|
+
encoded = current
|
|
81
|
+
context = createNativeContext(browserState, native.states, commitDom, native.scope)
|
|
82
|
+
handler = undefined
|
|
83
|
+
}
|
|
84
|
+
handler ??= modules.get(native.module)[native.handler]
|
|
85
|
+
const result = handler(context, event)
|
|
75
86
|
if (result && typeof result.then === "function") result.catch(error => console.error(error))
|
|
76
87
|
} catch (error) {
|
|
77
88
|
console.error(error)
|
|
@@ -107,17 +107,30 @@ if (typeof document !== "undefined") {
|
|
|
107
107
|
|
|
108
108
|
const eventNames = ["click", "input", "change"]
|
|
109
109
|
for (const eventName of eventNames) {
|
|
110
|
+
const directName = `kSetTrue${capitalize(eventName)}`
|
|
111
|
+
const commandsName = `kOn${capitalize(eventName)}`
|
|
112
|
+
const selector = `[data-k-set-true-${eventName}],[data-k-on-${eventName}]`
|
|
110
113
|
document.addEventListener(eventName, event => {
|
|
111
|
-
const
|
|
112
|
-
if (!target) return
|
|
113
|
-
const direct = target.dataset[`kSetTrue${capitalize(eventName)}`]
|
|
114
|
+
const direct = event.target.dataset?.[directName]
|
|
114
115
|
if (direct) {
|
|
115
116
|
browserState.set(direct, true)
|
|
116
117
|
commitDom(direct, true)
|
|
117
118
|
return
|
|
118
119
|
}
|
|
119
|
-
const commands = target.dataset[
|
|
120
|
-
|
|
120
|
+
const commands = event.target.dataset?.[commandsName]
|
|
121
|
+
if (commands) {
|
|
122
|
+
applyCommands(browserState, JSON.parse(commands), commitDom)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
const target = event.target.closest?.(selector)
|
|
126
|
+
if (!target) return
|
|
127
|
+
const inheritedDirect = target.dataset[directName]
|
|
128
|
+
if (inheritedDirect) {
|
|
129
|
+
browserState.set(inheritedDirect, true)
|
|
130
|
+
commitDom(inheritedDirect, true)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
applyCommands(browserState, JSON.parse(target.dataset[commandsName]), commitDom)
|
|
121
134
|
})
|
|
122
135
|
}
|
|
123
136
|
}
|