From ec18a3f1c6eae68cf3119f4db173bbf34285975f Mon Sep 17 00:00:00 2001 From: Aaron Elligsen Date: Thu, 9 Jul 2020 11:17:06 -0700 Subject: [PATCH 1/2] handle event handles correctly for snabbdom 0.7.4 --- src/render.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/src/render.js b/src/render.js index 42aec52..1b75ffb 100644 --- a/src/render.js +++ b/src/render.js @@ -10,11 +10,99 @@ const h = require('snabbdom/h').default const omit = (o, fields) => Object.keys(o).reduce((a, b) => !fields.includes(b) ? Object.assign(a, {[b]: o[b]}) : a, {}) const shadowRoot = (child) => h('span', {}, child.map(deflate)) // Should be replaced with reference to parent instead? const deflate = (child) => child ? (Array.isArray(child) ? shadowRoot(child) : child.tagName ? vtree(child) : child) : '' +const ScriptAttributes = new Set([ + 'onafterprint', + 'onbeforeprint', + 'onbeforeunload', + 'onerror', + 'onhashchange', + 'onload', + 'onoffline', + 'ononline', + 'onpagehide', + 'onpageshow', + 'onpopstate', + 'onresize', + 'onstorage', + 'onunload', + 'onblur', + 'onchange', + 'oncontextmenu', + 'onfocus', + 'oninput', + 'oninvalid', + 'onreset', + 'onsearch', + 'onselect', + 'onsubmit', + 'onkeydown', + 'onkeypress', + 'onkeyup', + 'onclick', + 'ondblclick', + 'onmousedown', + 'onmousemove', + 'onmouseout', + 'onmouseover', + 'onmouseup', + 'onmousewheel', + 'onwheel', + 'ondrag', + 'ondragend', + 'ondragenter', + 'ondragleave', + 'ondragover', + 'ondragstart', + 'ondrop', + 'onscroll', + 'oncopy', + 'oncut', + 'onpaste', + 'ondetail', + 'onabort', + 'oncanplay', + 'oncanplaythrough', + 'oncuechange', + 'ondurationchange', + 'onemptied', + 'onended', + 'onerror', + 'onloadeddata', + 'onloadedmetadata', + 'onloadstart', + 'onpause', + 'onplay', + 'onplaying', + 'onprogress', + 'onratechange', + 'onseeked', + 'onseeking', + 'onstalled', + 'onsuspend', + 'ontimeupdate', + 'onvolumechange', + 'onwaiting', +]); + +function collectOns(obj) { + let on = {}; + for(let key in obj) { + let name = key.toLocaleLowerCase(); + if(ScriptAttributes.has(name)) { + on[name.slice(2)] = obj[key]; + delete obj[key]; + } + } + return on; +} + function vtree (tree) { const props = omit(tree, ['element', 'children', 'style', 'tagName']) + const on = collectOns(props); const children = tree.children && tree.children.map(deflate) - return h(tree.tagName, {props, style: tree.style, attrs: props.attrs || (props.properties || {}).attributes}, children) + return h(tree.tagName, {props, style: tree.style, attrs: props.attrs || (props.properties || {}).attributes, on}, children) } + function render (tree, node, oldTree) { const newTree = vtree(tree) if (oldTree) { patch(oldTree, newTree) } else { patch(node, newTree) } From be4733025db75f0feb57119d86ba06d929006bc9 Mon Sep 17 00:00:00 2001 From: Aaron Elligsen Date: Thu, 9 Jul 2020 11:17:33 -0700 Subject: [PATCH 2/2] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bc5d56d..ec81b1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pureact", - "version": "1.3.0", + "version": "1.3.1", "author": "Christian Landgren", "license": "MIT", "repository": { @@ -10,7 +10,7 @@ "main": "lib/index.js", "module": "src/index.js", "dependencies": { - "snabbdom": "^0.6.9" + "snabbdom": "^0.7.4" }, "scripts": { "build": "npx microbundle src/*",