@brust/runtime-dom 2.0.0-alpha.11 → 2.0.0-alpha.13
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/package.json +1 -1
- package/src/directives/bind.ts +2 -0
- package/src/directives/on.ts +12 -0
package/package.json
CHANGED
package/src/directives/bind.ts
CHANGED
|
@@ -24,6 +24,8 @@ BINDERS.push({
|
|
|
24
24
|
return
|
|
25
25
|
}
|
|
26
26
|
if (v == null || v === false) { el.removeAttribute(name); return }
|
|
27
|
+
// React writes no `src=""` / `href=""` (it would load the page again); an anchor keeps its empty href.
|
|
28
|
+
if (v === '' && (name === 'src' || name === 'href') && el.tagName !== 'A') { el.removeAttribute(name); return }
|
|
27
29
|
if (URL_ATTRS.has(name) && !safeUrl(String(v))) { warnOnce(`b:${inst.name}:${name}`, `${attr} in ${inst.name}: unsafe URL refused`); return }
|
|
28
30
|
el.setAttribute(name, String(v))
|
|
29
31
|
})
|
package/src/directives/on.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { BINDERS, parsed, member } from '../core-api'
|
|
2
|
+
|
|
3
|
+
// React's SyntheticEvent has five members a DOM event lacks; code written for React calls them on the event it is handed
|
|
4
|
+
// (Radix: `event.isPropagationStopped()`), and on a DOM event that is a TypeError (F195). Added to the event the handler
|
|
5
|
+
// receives, never to Event.prototype, so nothing else on the page changes.
|
|
6
|
+
const SYNTHETIC: PropertyDescriptorMap = {
|
|
7
|
+
isPropagationStopped: { value(this: Event) { return this.cancelBubble } },
|
|
8
|
+
isDefaultPrevented: { value(this: Event) { return this.defaultPrevented } },
|
|
9
|
+
persist: { value() {} },
|
|
10
|
+
isPersistent: { value: () => true },
|
|
11
|
+
nativeEvent: { get(this: Event) { return this } },
|
|
12
|
+
}
|
|
2
13
|
BINDERS.push({
|
|
3
14
|
match: (a) => a.startsWith('x-on-'),
|
|
4
15
|
bind: ({ inst, el, attr, raw, scope }) => {
|
|
5
16
|
const event = attr.slice('x-on-'.length)
|
|
6
17
|
const p = parsed(inst, attr, raw); if (!p) return
|
|
7
18
|
const handler = (e: Event) => {
|
|
19
|
+
if (!('isPropagationStopped' in e)) Object.defineProperties(e, SYNTHETIC)
|
|
8
20
|
const fn = member(inst, p, attr)
|
|
9
21
|
if (typeof fn !== 'function') return
|
|
10
22
|
const args = p.bindings.map((b) => scope[b])
|