-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
345 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
var DataSet = require("data-set") | ||
'use strict'; | ||
|
||
module.exports = DataSetHook; | ||
var EvStore = require('ev-store'); | ||
|
||
function DataSetHook(value) { | ||
if (!(this instanceof DataSetHook)) { | ||
return new DataSetHook(value); | ||
module.exports = EvHook; | ||
|
||
function EvHook(value) { | ||
if (!(this instanceof EvHook)) { | ||
return new EvHook(value); | ||
} | ||
|
||
this.value = value; | ||
} | ||
|
||
DataSetHook.prototype.hook = function (node, propertyName) { | ||
var ds = DataSet(node) | ||
var propName = propertyName.substr(3) | ||
EvHook.prototype.hook = function (node, propertyName) { | ||
var es = EvStore(node); | ||
var propName = propertyName.substr(3); | ||
|
||
ds[propName] = this.value; | ||
es[propName] = this.value; | ||
}; | ||
|
||
DataSetHook.prototype.unhook = function(node, propertyName) { | ||
var ds = DataSet(node); | ||
EvHook.prototype.unhook = function(node, propertyName) { | ||
var es = EvStore(node); | ||
var propName = propertyName.substr(3); | ||
|
||
ds[propName] = undefined; | ||
} | ||
es[propName] = undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
var document = require("global/document") | ||
var nextTick = require("next-tick") | ||
'use strict'; | ||
|
||
module.exports = MutableFocusHook | ||
var document = require("global/document"); | ||
var nextTick = require("next-tick"); | ||
|
||
module.exports = MutableFocusHook; | ||
|
||
function MutableFocusHook() { | ||
if (!(this instanceof MutableFocusHook)) { | ||
return new MutableFocusHook() | ||
return new MutableFocusHook(); | ||
} | ||
} | ||
|
||
MutableFocusHook.prototype.hook = function (node, property) { | ||
MutableFocusHook.prototype.hook = function (node) { | ||
nextTick(function () { | ||
if (document.activeElement !== node) { | ||
node.focus(); | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = SoftSetHook; | ||
|
||
function SoftSetHook(value) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,125 @@ | ||
var TypedError = require("error/typed") | ||
|
||
var VNode = require("../vnode/vnode.js") | ||
var VText = require("../vnode/vtext.js") | ||
var isVNode = require("../vnode/is-vnode") | ||
var isVText = require("../vnode/is-vtext") | ||
var isWidget = require("../vnode/is-widget") | ||
var isHook = require("../vnode/is-vhook") | ||
var isVThunk = require("../vnode/is-thunk") | ||
|
||
var parseTag = require("./parse-tag.js") | ||
var softSetHook = require("./hooks/soft-set-hook.js") | ||
var dataSetHook = require("./hooks/data-set-hook.js") | ||
var evHook = require("./hooks/ev-hook.js") | ||
|
||
var UnexpectedVirtualElement = TypedError({ | ||
type: "virtual-hyperscript.unexpected.virtual-element", | ||
message: "Unexpected virtual child passed to h().\n" + | ||
"Expected a VNode / Vthunk / VWidget / string but:\n" + | ||
"got a {foreignObjectStr}.\n" + | ||
"The parent vnode is {parentVnodeStr}.\n" + | ||
"Suggested fix: change your `h(..., [ ... ])` callsite.", | ||
foreignObjectStr: null, | ||
parentVnodeStr: null, | ||
foreignObject: null, | ||
parentVnode: null | ||
}) | ||
|
||
module.exports = h | ||
'use strict'; | ||
|
||
var isArray = require('x-is-array'); | ||
|
||
var VNode = require('../vnode/vnode.js'); | ||
var VText = require('../vnode/vtext.js'); | ||
var isVNode = require('../vnode/is-vnode'); | ||
var isVText = require('../vnode/is-vtext'); | ||
var isWidget = require('../vnode/is-widget'); | ||
var isHook = require('../vnode/is-vhook'); | ||
var isVThunk = require('../vnode/is-thunk'); | ||
|
||
var parseTag = require('./parse-tag.js'); | ||
var softSetHook = require('./hooks/soft-set-hook.js'); | ||
var evHook = require('./hooks/ev-hook.js'); | ||
|
||
module.exports = h; | ||
|
||
function h(tagName, properties, children) { | ||
var childNodes = [] | ||
var tag, props, key, namespace | ||
var childNodes = []; | ||
var tag, props, key, namespace; | ||
|
||
if (!children && isChildren(properties)) { | ||
children = properties | ||
props = {} | ||
children = properties; | ||
props = {}; | ||
} | ||
|
||
props = props || properties || {} | ||
tag = parseTag(tagName, props) | ||
props = props || properties || {}; | ||
tag = parseTag(tagName, props); | ||
|
||
// support keys | ||
if (props.hasOwnProperty("key")) { | ||
key = props.key | ||
props.key = undefined | ||
if (props.hasOwnProperty('key')) { | ||
key = props.key; | ||
props.key = undefined; | ||
} | ||
|
||
// support namespace | ||
if (props.hasOwnProperty("namespace")) { | ||
namespace = props.namespace | ||
props.namespace = undefined | ||
if (props.hasOwnProperty('namespace')) { | ||
namespace = props.namespace; | ||
props.namespace = undefined; | ||
} | ||
|
||
// fix cursor bug | ||
if (tag === "INPUT" && | ||
if (tag === 'INPUT' && | ||
!props.namespace && | ||
props.hasOwnProperty("value") && | ||
props.hasOwnProperty('value') && | ||
props.value !== undefined && | ||
!isHook(props.value) | ||
) { | ||
props.value = softSetHook(props.value) | ||
props.value = softSetHook(props.value); | ||
} | ||
|
||
transformProperties(props) | ||
transformProperties(props); | ||
|
||
if (children !== undefined && children !== null) { | ||
addChild(children, childNodes, tag, props) | ||
addChild(children, childNodes, tag, props); | ||
} | ||
|
||
|
||
var node = new VNode(tag, props, childNodes, key, namespace) | ||
var node = new VNode(tag, props, childNodes, key, namespace); | ||
|
||
return node | ||
return node; | ||
} | ||
|
||
function addChild(c, childNodes, tag, props) { | ||
if (typeof c === "string") { | ||
childNodes.push(new VText(c)) | ||
if (typeof c === 'string') { | ||
childNodes.push(new VText(c)); | ||
} else if (isChild(c)) { | ||
childNodes.push(c) | ||
} else if (Array.isArray(c)) { | ||
childNodes.push(c); | ||
} else if (isArray(c)) { | ||
for (var i = 0; i < c.length; i++) { | ||
addChild(c[i], childNodes, tag, props) | ||
addChild(c[i], childNodes, tag, props); | ||
} | ||
} else if (c === null || c === undefined) { | ||
return | ||
return; | ||
} else { | ||
throw UnexpectedVirtualElement({ | ||
foreignObjectStr: JSON.stringify(c), | ||
foreignObject: c, | ||
parentVnodeStr: JSON.stringify({ | ||
tagName: tag, | ||
properties: props | ||
}), | ||
parentVnode: { | ||
tagName: tag, | ||
properties: props | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
function transformProperties(props) { | ||
for (var propName in props) { | ||
if (props.hasOwnProperty(propName)) { | ||
var value = props[propName] | ||
var value = props[propName]; | ||
|
||
if (isHook(value)) { | ||
continue | ||
continue; | ||
} | ||
|
||
if (propName.substr(0, 5) === "data-") { | ||
// add data-foo support | ||
props[propName] = dataSetHook(value) | ||
} else if (propName.substr(0, 3) === "ev-") { | ||
if (propName.substr(0, 3) === 'ev-') { | ||
// add ev-foo support | ||
props[propName] = evHook(value) | ||
props[propName] = evHook(value); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function isChild(x) { | ||
return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x) | ||
return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x); | ||
} | ||
|
||
function isChildren(x) { | ||
return typeof x === "string" || Array.isArray(x) || isChild(x) | ||
return typeof x === 'string' || isArray(x) || isChild(x); | ||
} | ||
|
||
function UnexpectedVirtualElement(data) { | ||
var err = new Error(); | ||
|
||
err.type = 'virtual-hyperscript.unexpected.virtual-element'; | ||
err.message = 'Unexpected virtual child passed to h().\n' + | ||
'Expected a VNode / Vthunk / VWidget / string but:\n' + | ||
'got a {foreignObjectStr}.\n' + | ||
'The parent vnode is {parentVnodeStr}.\n' + | ||
'Suggested fix: change your `h(..., [ ... ])` callsite.'; | ||
err.foreignObject = data.foreignObject; | ||
err.parentVnode = data.parentVnode; | ||
|
||
return err; | ||
} |
Oops, something went wrong.