@kudzujs/core 0.6.27 → 0.7.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.
@@ -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 native = JSON.parse(node.dataset[`kNative${capitalize(eventName)}`])
74
- const result = modules.get(native.module)[native.handler](createNativeContext(browserState, native.states, commitDom, native.scope), event)
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 target = event.target.closest(`[data-k-set-true-${eventName}],[data-k-on-${eventName}]`)
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[`kOn${capitalize(eventName)}`]
120
- applyCommands(browserState, JSON.parse(commands), commitDom)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kudzujs/core",
3
- "version": "0.6.27",
3
+ "version": "0.7.0",
4
4
  "description": "HTML-first TSX framework with synchronous state semantics and no virtual DOM",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,6 +26,7 @@
26
26
  "framework/",
27
27
  "GOAL_A.md",
28
28
  "GOAL_B.md",
29
+ "RELEASES.md",
29
30
  "README.md",
30
31
  "LICENSE"
31
32
  ],