driver-weex
Advanced tools
Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
@@ -16,2 +16,3 @@ (function (global, factory) { | ||
var ARIA_PREFIX_REGEXP = /^aria-/; | ||
var EMPTY = ''; | ||
var nodeMaps = {}; | ||
@@ -21,148 +22,159 @@ /* global __weex_document__ */ | ||
var document = typeof __weex_document__ === 'object' ? __weex_document__ : typeof document === 'object' ? document : null; | ||
var Driver = { | ||
getElementById: function getElementById(id) { | ||
return nodeMaps[id]; | ||
}, | ||
createBody: function createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
function getElementById(id) { | ||
return nodeMaps[id]; | ||
} | ||
function createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
} | ||
var documentElement = document.documentElement; | ||
var body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
return body; | ||
} | ||
function createComment(content) { | ||
return document.createComment(content); | ||
} | ||
function createEmpty() { | ||
return this.createComment(EMPTY); | ||
} | ||
function createText(text) { | ||
return createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text | ||
} | ||
}); | ||
} | ||
function updateText(node, content) { | ||
setAttribute(node, 'value', content); | ||
} | ||
function createElement(type, props) { | ||
var node = document.createElement(type, { | ||
style: props[STYLE] | ||
}); | ||
var documentElement = document.documentElement; | ||
var body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
return body; | ||
}, | ||
createComment: function createComment(content) { | ||
return document.createComment(content); | ||
}, | ||
createEmpty: function createEmpty() { | ||
return this.createComment(''); | ||
}, | ||
createText: function createText(text) { | ||
return Driver.createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text | ||
} | ||
}); | ||
}, | ||
updateText: function updateText(node, content) { | ||
this.setAttribute(node, 'value', content); | ||
}, | ||
createElement: function createElement(type, props) { | ||
var node = document.createElement(type, { | ||
style: props[STYLE] | ||
}); | ||
this.setNativeProps(node, props, true); | ||
return node; | ||
}, | ||
appendChild: function appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
}, | ||
removeChild: function removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
var id = node.attr && node.attr[ID]; | ||
for (var prop in props) { | ||
var value = props[prop]; | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
return parent.removeChild(node); | ||
}, | ||
replaceChild: function replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
var previousSibling = oldChild.previousSibling; | ||
var nextSibling = oldChild.nextSibling; | ||
this.removeChild(oldChild, parent); | ||
if (previousSibling) { | ||
this.insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
this.insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
this.appendChild(newChild, parent); | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
continue; | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
var eventName = prop.slice(2).toLowerCase(); | ||
addEventListener(node, eventName, value, props); | ||
} else { | ||
setAttribute(node, prop, value); | ||
} | ||
} | ||
}, | ||
insertAfter: function insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
}, | ||
insertBefore: function insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
}, | ||
addEventListener: function addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
var params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
}, | ||
removeEventListener: function removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
}, | ||
removeAttribute: function removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} // Weex native will crash when pass null value | ||
} | ||
return node; | ||
} | ||
function appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
} | ||
function removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
var id = node.attr && node.attr[ID]; | ||
return node.setAttr(propKey, undefined, false); | ||
}, | ||
setAttribute: function setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} // Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
} | ||
return parent.removeChild(node); | ||
} | ||
function replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
var previousSibling = oldChild.previousSibling; | ||
var nextSibling = oldChild.nextSibling; | ||
removeChild(oldChild, parent); | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function (m, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
} | ||
if (previousSibling) { | ||
insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
appendChild(newChild, parent); | ||
} | ||
} | ||
function insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
} | ||
function insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
} | ||
function addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
var params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
} | ||
function removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
} | ||
function removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} // Weex native will crash when pass null value | ||
return node.setAttr(propKey, propValue, false); | ||
}, | ||
setStyle: function setStyle(node, style) { | ||
node.setStyles(style); | ||
}, | ||
beforeRender: function beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
}, | ||
afterRender: function afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} // Turn on batched updates | ||
return node.setAttr(propKey, undefined, false); | ||
} | ||
function setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} // Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
document.close(); | ||
}, | ||
setNativeProps: function setNativeProps(node, props, skipSetStyles) { | ||
for (var prop in props) { | ||
var value = props[prop]; | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function (m, p) { | ||
return p.toUpperCase(); | ||
}); | ||
} | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
if (skipSetStyles) { | ||
continue; | ||
} | ||
return node.setAttr(propKey, propValue, false); | ||
} | ||
function setStyle(node, style) { | ||
node.setStyles(style); | ||
} | ||
function beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
} | ||
function afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} // Turn on batched updates | ||
this.setStyles(node, value); | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
var eventName = prop.slice(2).toLowerCase(); | ||
this.addEventListener(node, eventName, value, props); | ||
} else { | ||
this.setAttribute(node, prop, value); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
exports.default = Driver; | ||
document.close(); | ||
} | ||
exports.getElementById = getElementById; | ||
exports.createBody = createBody; | ||
exports.createComment = createComment; | ||
exports.createEmpty = createEmpty; | ||
exports.createText = createText; | ||
exports.updateText = updateText; | ||
exports.createElement = createElement; | ||
exports.appendChild = appendChild; | ||
exports.removeChild = removeChild; | ||
exports.replaceChild = replaceChild; | ||
exports.insertAfter = insertAfter; | ||
exports.insertBefore = insertBefore; | ||
exports.addEventListener = addEventListener; | ||
exports.removeEventListener = removeEventListener; | ||
exports.removeAttribute = removeAttribute; | ||
exports.setAttribute = setAttribute; | ||
exports.setStyle = setStyle; | ||
exports.beforeRender = beforeRender; | ||
exports.afterRender = afterRender; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
@@ -169,0 +181,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).DriverWeex={})}(this,function(e){"use strict";var u="style",r="id",s=/^on[A-Z]/,i=/^aria-/,o={},a="object"==typeof __weex_document__?__weex_document__:"object"==typeof a?a:null,t={getElementById:function(e){return o[e]},createBody:function(e,t){if(a.body)return a.body;var n=a.documentElement,r=a.createBody(e,t);return n.appendChild(r),r},createComment:function(e){return a.createComment(e)},createEmpty:function(){return this.createComment("")},createText:function(e){return t.createElement({type:"text",props:{value:e}})},updateText:function(e,t){this.setAttribute(e,"value",t)},createElement:function(e,t){var n=a.createElement(e,{style:t[u]});return this.setNativeProps(n,t,!0),n},appendChild:function(e,t){return t.appendChild(e)},removeChild:function(e,t){t=t||e.parentNode;var n=e.attr&&e.attr.id;return null!=n&&(o[n]=null),t.removeChild(e)},replaceChild:function(e,t,n){var r=t.previousSibling,i=t.nextSibling;this.removeChild(t,n=n||t.parentNode),r?this.insertAfter(e,r,n):i?this.insertBefore(e,i,n):this.appendChild(e,n)},insertAfter:function(e,t,n){return(n=n||t.parentNode).insertAfter(e,t)},insertBefore:function(e,t,n){return(n=n||t.parentNode).insertBefore(e,t)},addEventListener:function(e,t,n,r){return e.addEvent(t,n,r[t+"EventParams"])},removeEventListener:function(e,t,n){return e.removeEvent(t,n)},removeAttribute:function(e,t,n){return t==r&&(o[n]=null),e.setAttr(t,void 0,!1)},setAttribute:function(e,t,n){return t==r&&(o[n]=e),i.test(t)&&(t=t.replace(/\-(\w)/,function(e,t){return t.toUpperCase()})),e.setAttr(t,n,!1)},setStyle:function(e,t){e.setStyles(t)},beforeRender:function(){a.open()},afterRender:function(){a.listener&&a.listener.createFinish&&a.listener.createFinish(),a.close()},setNativeProps:function(e,t,n){for(var r in t){var i=t[r];if("children"!==r&&null!=i)if(r===u){if(n)continue;this.setStyles(e,i)}else if(s.test(r)){var o=r.slice(2).toLowerCase();this.addEventListener(e,o,i,t)}else this.setAttribute(e,r,i)}}};e.default=t,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).DriverWeex={})}(this,function(e){"use strict";var i="style",r="id",u="children",c=/^on[A-Z]/,o=/^aria-/,f={},a="object"==typeof __weex_document__?__weex_document__:"object"==typeof a?a:null;function t(e,t){var n=a.createElement(e,{style:t[i]});for(var r in t){var o=t[r];if(r!==u&&null!=o){if(r===i)continue;c.test(r)?v(n,r.slice(2).toLowerCase(),o,t):m(n,r,o)}}return n}function d(e,t){return t.appendChild(e)}function l(e,t){t=t||e.parentNode;var n=e.attr&&e.attr[r];return null!=n&&(f[n]=null),t.removeChild(e)}function s(e,t,n){return(n=n||t.parentNode).insertAfter(e,t)}function p(e,t,n){return(n=n||t.parentNode).insertBefore(e,t)}function v(e,t,n,r){return e.addEvent(t,n,r[t+"EventParams"])}function m(e,t,n){return t==r&&(f[n]=e),o.test(t)&&(t=t.replace(/\-(\w)/,function(e,t){return t.toUpperCase()})),e.setAttr(t,n,!1)}e.getElementById=function(e){return f[e]},e.createBody=function(e,t){if(a.body)return a.body;var n=a.documentElement,r=a.createBody(e,t);return n.appendChild(r),r},e.createComment=function(e){return a.createComment(e)},e.createEmpty=function(){return this.createComment("")},e.createText=function(e){return t({type:"text",props:{value:e}})},e.updateText=function(e,t){m(e,"value",t)},e.createElement=t,e.appendChild=d,e.removeChild=l,e.replaceChild=function(e,t,n){var r=t.previousSibling,o=t.nextSibling;l(t,n=n||t.parentNode),r?s(e,r,n):o?p(e,o,n):d(e,n)},e.insertAfter=s,e.insertBefore=p,e.addEventListener=v,e.removeEventListener=function(e,t,n){return e.removeEvent(t,n)},e.removeAttribute=function(e,t,n){return t==r&&(f[n]=null),e.setAttr(t,void 0,!1)},e.setAttribute=m,e.setStyle=function(e,t){e.setStyles(t)},e.beforeRender=function(){a.open()},e.afterRender=function(){a.listener&&a.listener.createFinish&&a.listener.createFinish(),a.close()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=driver-weex.min.js.map |
287
lib/index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
exports.getElementById = getElementById; | ||
exports.createBody = createBody; | ||
exports.createComment = createComment; | ||
exports.createEmpty = createEmpty; | ||
exports.createText = createText; | ||
exports.updateText = updateText; | ||
exports.createElement = createElement; | ||
exports.appendChild = appendChild; | ||
exports.removeChild = removeChild; | ||
exports.replaceChild = replaceChild; | ||
exports.insertAfter = insertAfter; | ||
exports.insertBefore = insertBefore; | ||
exports.addEventListener = addEventListener; | ||
exports.removeEventListener = removeEventListener; | ||
exports.removeAttribute = removeAttribute; | ||
exports.setAttribute = setAttribute; | ||
exports.setStyle = setStyle; | ||
exports.beforeRender = beforeRender; | ||
exports.afterRender = afterRender; | ||
@@ -15,2 +33,3 @@ /** | ||
var ARIA_PREFIX_REGEXP = /^aria-/; | ||
var EMPTY = ''; | ||
var nodeMaps = {}; | ||
@@ -20,146 +39,156 @@ /* global __weex_document__ */ | ||
var document = typeof __weex_document__ === 'object' ? __weex_document__ : typeof document === 'object' ? document : null; | ||
var Driver = { | ||
getElementById: function getElementById(id) { | ||
return nodeMaps[id]; | ||
}, | ||
createBody: function createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
} | ||
var documentElement = document.documentElement; | ||
var body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
return body; | ||
}, | ||
createComment: function createComment(content) { | ||
return document.createComment(content); | ||
}, | ||
createEmpty: function createEmpty() { | ||
return this.createComment(''); | ||
}, | ||
createText: function createText(text) { | ||
return Driver.createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text | ||
} | ||
}); | ||
}, | ||
updateText: function updateText(node, content) { | ||
this.setAttribute(node, 'value', content); | ||
}, | ||
createElement: function createElement(type, props) { | ||
var node = document.createElement(type, { | ||
style: props[STYLE] | ||
}); | ||
this.setNativeProps(node, props, true); | ||
return node; | ||
}, | ||
appendChild: function appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
}, | ||
removeChild: function removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
var id = node.attr && node.attr[ID]; | ||
function getElementById(id) { | ||
return nodeMaps[id]; | ||
} | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
} | ||
function createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
} | ||
return parent.removeChild(node); | ||
}, | ||
replaceChild: function replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
var previousSibling = oldChild.previousSibling; | ||
var nextSibling = oldChild.nextSibling; | ||
this.removeChild(oldChild, parent); | ||
var documentElement = document.documentElement; | ||
var body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
return body; | ||
} | ||
if (previousSibling) { | ||
this.insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
this.insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
this.appendChild(newChild, parent); | ||
function createComment(content) { | ||
return document.createComment(content); | ||
} | ||
function createEmpty() { | ||
return this.createComment(EMPTY); | ||
} | ||
function createText(text) { | ||
return createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text | ||
} | ||
}, | ||
insertAfter: function insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
}, | ||
insertBefore: function insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
}, | ||
addEventListener: function addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
var params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
}, | ||
removeEventListener: function removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
}, | ||
removeAttribute: function removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} // Weex native will crash when pass null value | ||
}); | ||
} | ||
function updateText(node, content) { | ||
setAttribute(node, 'value', content); | ||
} | ||
return node.setAttr(propKey, undefined, false); | ||
}, | ||
setAttribute: function setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} // Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
function createElement(type, props) { | ||
var node = document.createElement(type, { | ||
style: props[STYLE] | ||
}); | ||
for (var prop in props) { | ||
var value = props[prop]; | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function (m, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
return node.setAttr(propKey, propValue, false); | ||
}, | ||
setStyle: function setStyle(node, style) { | ||
node.setStyles(style); | ||
}, | ||
beforeRender: function beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
}, | ||
afterRender: function afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} // Turn on batched updates | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
continue; | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
var eventName = prop.slice(2).toLowerCase(); | ||
addEventListener(node, eventName, value, props); | ||
} else { | ||
setAttribute(node, prop, value); | ||
} | ||
} | ||
} | ||
return node; | ||
} | ||
document.close(); | ||
}, | ||
setNativeProps: function setNativeProps(node, props, skipSetStyles) { | ||
for (var prop in props) { | ||
var value = props[prop]; | ||
function appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
} | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
function removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
var id = node.attr && node.attr[ID]; | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
if (skipSetStyles) { | ||
continue; | ||
} | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
} | ||
this.setStyles(node, value); | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
var eventName = prop.slice(2).toLowerCase(); | ||
this.addEventListener(node, eventName, value, props); | ||
} else { | ||
this.setAttribute(node, prop, value); | ||
} | ||
} | ||
} | ||
return parent.removeChild(node); | ||
} | ||
function replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
var previousSibling = oldChild.previousSibling; | ||
var nextSibling = oldChild.nextSibling; | ||
removeChild(oldChild, parent); | ||
if (previousSibling) { | ||
insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
appendChild(newChild, parent); | ||
} | ||
}; | ||
var _default = Driver; | ||
exports.default = _default; | ||
} | ||
function insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
} | ||
function insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
} | ||
function addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
var params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
} | ||
function removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
} | ||
function removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} // Weex native will crash when pass null value | ||
return node.setAttr(propKey, undefined, false); | ||
} | ||
function setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} // Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function (m, p) { | ||
return p.toUpperCase(); | ||
}); | ||
} | ||
return node.setAttr(propKey, propValue, false); | ||
} | ||
function setStyle(node, style) { | ||
node.setStyles(style); | ||
} | ||
function beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
} | ||
function afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} // Turn on batched updates | ||
document.close(); | ||
} |
{ | ||
"name": "driver-weex", | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"description": "Weex driver for Rax", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -15,4 +15,3 @@ # driver-weex | ||
import {createElement, Component, render} from 'rax'; | ||
import WeexDriver from 'driver-weex'; | ||
import {isWeex} from 'universal-env'; | ||
import * as WeexDriver from 'driver-weex'; | ||
@@ -30,35 +29,4 @@ class Example extends Component { | ||
render(<Example />, null, { | ||
driver: isWeex ? WeexDriver : null | ||
driver: WeexDriver | ||
}); | ||
``` | ||
## Support elements | ||
### Block: p, div, section, header, footer, nav, aside, main | ||
### img | ||
- src | ||
- width: recommend use style.width | ||
- height: recommend use style.height | ||
- placeholder: weex only | ||
- resize: weex only | ||
### a | ||
- href | ||
### video | ||
- src | ||
- controls | ||
- autoplay: not sure | ||
- play-status: weex only | ||
### textarea | ||
- placeholder | ||
- disabled | ||
- autofocus | ||
- rows | ||
- children: as value |
255
src/index.js
@@ -10,2 +10,3 @@ /** | ||
const ARIA_PREFIX_REGEXP = /^aria-/; | ||
const EMPTY = ''; | ||
@@ -18,163 +19,153 @@ const nodeMaps = {}; | ||
const Driver = { | ||
getElementById(id) { | ||
return nodeMaps[id]; | ||
}, | ||
export function getElementById(id) { | ||
return nodeMaps[id]; | ||
} | ||
createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
} | ||
export function createBody(type, props) { | ||
if (document.body) { | ||
return document.body; | ||
} | ||
let documentElement = document.documentElement; | ||
let body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
let documentElement = document.documentElement; | ||
let body = document.createBody(type, props); | ||
documentElement.appendChild(body); | ||
return body; | ||
}, | ||
return body; | ||
} | ||
createComment(content) { | ||
return document.createComment(content); | ||
}, | ||
export function createComment(content) { | ||
return document.createComment(content); | ||
} | ||
createEmpty() { | ||
return this.createComment(''); | ||
}, | ||
createText(text) { | ||
return Driver.createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text, | ||
} | ||
}); | ||
}, | ||
export function createEmpty() { | ||
return this.createComment(EMPTY); | ||
} | ||
updateText(node, content) { | ||
this.setAttribute(node, 'value', content); | ||
}, | ||
export function createText(text) { | ||
return createElement({ | ||
type: TEXT, | ||
props: { | ||
value: text, | ||
} | ||
}); | ||
} | ||
createElement(type, props) { | ||
let node = document.createElement(type, { | ||
style: props[STYLE], | ||
}); | ||
export function updateText(node, content) { | ||
setAttribute(node, 'value', content); | ||
} | ||
this.setNativeProps(node, props, true); | ||
export function createElement(type, props) { | ||
let node = document.createElement(type, { | ||
style: props[STYLE], | ||
}); | ||
return node; | ||
}, | ||
for (let prop in props) { | ||
let value = props[prop]; | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
}, | ||
removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
let id = node.attr && node.attr[ID]; | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
continue; | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
let eventName = prop.slice(2).toLowerCase(); | ||
addEventListener(node, eventName, value, props); | ||
} else { | ||
setAttribute(node, prop, value); | ||
} | ||
} | ||
return parent.removeChild(node); | ||
}, | ||
} | ||
replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
let previousSibling = oldChild.previousSibling; | ||
let nextSibling = oldChild.nextSibling; | ||
this.removeChild(oldChild, parent); | ||
return node; | ||
} | ||
if (previousSibling) { | ||
this.insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
this.insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
this.appendChild(newChild, parent); | ||
} | ||
}, | ||
export function appendChild(node, parent) { | ||
return parent.appendChild(node); | ||
} | ||
insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
}, | ||
export function removeChild(node, parent) { | ||
parent = parent || node.parentNode; | ||
let id = node.attr && node.attr[ID]; | ||
if (id != null) { | ||
nodeMaps[id] = null; | ||
} | ||
return parent.removeChild(node); | ||
} | ||
insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
}, | ||
export function replaceChild(newChild, oldChild, parent) { | ||
parent = parent || oldChild.parentNode; | ||
let previousSibling = oldChild.previousSibling; | ||
let nextSibling = oldChild.nextSibling; | ||
removeChild(oldChild, parent); | ||
addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
let params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
}, | ||
if (previousSibling) { | ||
insertAfter(newChild, previousSibling, parent); | ||
} else if (nextSibling) { | ||
insertBefore(newChild, nextSibling, parent); | ||
} else { | ||
appendChild(newChild, parent); | ||
} | ||
} | ||
removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
}, | ||
export function insertAfter(node, after, parent) { | ||
parent = parent || after.parentNode; | ||
return parent.insertAfter(node, after); | ||
} | ||
removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} | ||
// Weex native will crash when pass null value | ||
return node.setAttr(propKey, undefined, false); | ||
}, | ||
export function insertBefore(node, before, parent) { | ||
parent = parent || before.parentNode; | ||
return parent.insertBefore(node, before); | ||
} | ||
setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} | ||
export function addEventListener(node, eventName, eventHandler, props) { | ||
// https://github.com/apache/incubator-weex/blob/master/runtime/vdom/Element.js#L421 | ||
let params = props[eventName + 'EventParams']; | ||
return node.addEvent(eventName, eventHandler, params); | ||
} | ||
// Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function(m, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
} | ||
export function removeEventListener(node, eventName, eventHandler) { | ||
return node.removeEvent(eventName, eventHandler); | ||
} | ||
return node.setAttr(propKey, propValue, false); | ||
}, | ||
export function removeAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = null; | ||
} | ||
// Weex native will crash when pass null value | ||
return node.setAttr(propKey, undefined, false); | ||
} | ||
setStyle(node, style) { | ||
node.setStyles(style); | ||
}, | ||
export function setAttribute(node, propKey, propValue) { | ||
if (propKey == ID) { | ||
nodeMaps[propValue] = node; | ||
} | ||
beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
}, | ||
// Weex only support `ariaLabel` format, convert `aria-label` format to camelcase | ||
if (ARIA_PREFIX_REGEXP.test(propKey)) { | ||
propKey = propKey.replace(/\-(\w)/, function(m, p) { | ||
return p.toUpperCase(); | ||
}); | ||
} | ||
afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} | ||
return node.setAttr(propKey, propValue, false); | ||
} | ||
// Turn on batched updates | ||
document.close(); | ||
}, | ||
export function setStyle(node, style) { | ||
node.setStyles(style); | ||
} | ||
setNativeProps(node, props, skipSetStyles) { | ||
for (let prop in props) { | ||
let value = props[prop]; | ||
if (prop === CHILDREN) { | ||
continue; | ||
} | ||
export function beforeRender() { | ||
// Turn off batched updates | ||
document.open(); | ||
} | ||
if (value != null) { | ||
if (prop === STYLE) { | ||
if (skipSetStyles) { | ||
continue; | ||
} | ||
this.setStyles(node, value); | ||
} else if (EVENT_PREFIX_REGEXP.test(prop)) { | ||
let eventName = prop.slice(2).toLowerCase(); | ||
this.addEventListener(node, eventName, value, props); | ||
} else { | ||
this.setAttribute(node, prop, value); | ||
} | ||
} | ||
} | ||
export function afterRender() { | ||
if (document.listener && document.listener.createFinish) { | ||
document.listener.createFinish(); | ||
} | ||
}; | ||
export default Driver; | ||
// Turn on batched updates | ||
document.close(); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
600
0
46208
31