UNPKG

para-bridge-demo

Version:

a bridge api for js-ios/andriod rest

1,339 lines (1,322 loc) 96.7 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.Inferno = global.Inferno || {}))); }(this, (function (exports) { 'use strict'; var ERROR_MSG = 'a runtime error occured! Use Inferno in development environment to find the error.'; var isArray = Array.isArray; function isStringOrNumber(o) { var type = typeof o; return type === 'string' || type === 'number'; } function isNullOrUndef(o) { return isUndefined(o) || isNull(o); } function isInvalid(o) { return isNull(o) || o === false || isTrue(o) || isUndefined(o); } function isFunction(o) { return typeof o === 'function'; } function isString(o) { return typeof o === 'string'; } function isNumber(o) { return typeof o === 'number'; } function isNull(o) { return o === null; } function isTrue(o) { return o === true; } function isUndefined(o) { return o === void 0; } function throwError(message) { if (!message) { message = ERROR_MSG; } throw new Error(("Inferno Error: " + message)); } function warning(message) { // tslint:disable-next-line:no-console console.error(message); } function combineFrom(first, second) { var out = {}; if (first) { for (var key in first) { out[key] = first[key]; } } if (second) { for (var key$1 in second) { out[key$1] = second[key$1]; } } return out; } // We need EMPTY_OBJ defined in one place. // Its used for comparison so we cant inline it into shared var EMPTY_OBJ = {}; var Fragment = '$F'; { Object.freeze(EMPTY_OBJ); } function appendChild(parentDOM, dom) { parentDOM.appendChild(dom); } function insertOrAppend(parentDOM, newNode, nextNode) { if (isNull(nextNode)) { appendChild(parentDOM, newNode); } else { parentDOM.insertBefore(newNode, nextNode); } } function documentCreateElement(tag, isSVG) { if (isSVG) { return document.createElementNS('http://www.w3.org/2000/svg', tag); } return document.createElement(tag); } function replaceChild(parentDOM, newDom, lastDom) { parentDOM.replaceChild(newDom, lastDom); } function removeChild(parentDOM, childNode) { parentDOM.removeChild(childNode); } function callAll(arrayFn) { var listener; while ((listener = arrayFn.shift()) !== undefined) { listener(); } } function findDOMfromVNode(vNode, start) { var flags; var children; while (vNode) { flags = vNode.flags; if (flags & 2033 /* DOMRef */) { return vNode.dom; } children = vNode.children; if (flags & 8192 /* Fragment */) { vNode = vNode.childFlags === 2 /* HasVNodeChildren */ ? children : children[start ? 0 : children.length - 1]; } else if (flags & 4 /* ComponentClass */) { vNode = children.$LI; } else { vNode = children; } } return null; } function removeVNodeDOM(vNode, parentDOM) { var flags = vNode.flags; if (flags & 2033 /* DOMRef */) { removeChild(parentDOM, vNode.dom); } else { var children = vNode.children; if (flags & 4 /* ComponentClass */) { removeVNodeDOM(children.$LI, parentDOM); } else if (flags & 8 /* ComponentFunction */) { removeVNodeDOM(children, parentDOM); } else if (flags & 8192 /* Fragment */) { if (vNode.childFlags === 2 /* HasVNodeChildren */) { removeVNodeDOM(children, parentDOM); } else { for (var i = 0, len = children.length; i < len; ++i) { removeVNodeDOM(children[i], parentDOM); } } } } } function moveVNodeDOM(vNode, parentDOM, nextNode) { var flags = vNode.flags; if (flags & 2033 /* DOMRef */) { insertOrAppend(parentDOM, vNode.dom, nextNode); } else { var children = vNode.children; if (flags & 4 /* ComponentClass */) { moveVNodeDOM(children.$LI, parentDOM, nextNode); } else if (flags & 8 /* ComponentFunction */) { moveVNodeDOM(children, parentDOM, nextNode); } else if (flags & 8192 /* Fragment */) { if (vNode.childFlags === 2 /* HasVNodeChildren */) { moveVNodeDOM(children, parentDOM, nextNode); } else { for (var i = 0, len = children.length; i < len; ++i) { moveVNodeDOM(children[i], parentDOM, nextNode); } } } } } function getComponentName(instance) { // Fallback for IE return instance.name || instance.displayName || instance.constructor.name || (instance.toString().match(/^function\s*([^\s(]+)/) || [])[1]; } function createDerivedState(instance, nextProps, state) { if (instance.constructor.getDerivedStateFromProps) { return combineFrom(state, instance.constructor.getDerivedStateFromProps(nextProps, state)); } return state; } var renderCheck = { v: false }; var options = { componentComparator: null, createVNode: null, renderComplete: null }; function getTagName(input) { var tagName; if (isArray(input)) { var arrayText = input.length > 3 ? input.slice(0, 3).toString() + ',...' : input.toString(); tagName = 'Array(' + arrayText + ')'; } else if (isStringOrNumber(input)) { tagName = 'Text(' + input + ')'; } else if (isInvalid(input)) { tagName = 'InvalidVNode(' + input + ')'; } else { var flags = input.flags; if (flags & 481 /* Element */) { tagName = "<" + (input.type) + (input.className ? ' class="' + input.className + '"' : '') + ">"; } else if (flags & 16 /* Text */) { tagName = "Text(" + (input.children) + ")"; } else if (flags & 1024 /* Portal */) { tagName = "Portal*"; } else { tagName = "<" + (getComponentName(input.type)) + " />"; } } return '>> ' + tagName + '\n'; } function DEV_ValidateKeys(vNodeTree, forceKeyed) { var foundKeys = {}; for (var i = 0, len = vNodeTree.length; i < len; ++i) { var childNode = vNodeTree[i]; if (isArray(childNode)) { return 'Encountered ARRAY in mount, array must be flattened, or normalize used. Location: \n' + getTagName(childNode); } if (isInvalid(childNode)) { if (forceKeyed) { return 'Encountered invalid node when preparing to keyed algorithm. Location: \n' + getTagName(childNode); } else if (Object.keys(foundKeys).length !== 0) { return 'Encountered invalid node with mixed keys. Location: \n' + getTagName(childNode); } continue; } if (typeof childNode === 'object') { if (childNode.isValidated) { continue; } childNode.isValidated = true; } // Key can be undefined, null too. But typescript complains for no real reason var key = childNode.key; if (!isNullOrUndef(key) && !isStringOrNumber(key)) { return 'Encountered child vNode where key property is not string or number. Location: \n' + getTagName(childNode); } var children = childNode.children; var childFlags = childNode.childFlags; if (!isInvalid(children)) { var val = (void 0); if (childFlags & 12 /* MultipleChildren */) { val = DEV_ValidateKeys(children, (childFlags & 8 /* HasKeyedChildren */) !== 0); } else if (childFlags === 2 /* HasVNodeChildren */) { val = DEV_ValidateKeys([children], false); } if (val) { val += getTagName(childNode); return val; } } if (forceKeyed && isNullOrUndef(key)) { return ('Encountered child without key during keyed algorithm. If this error points to Array make sure children is flat list. Location: \n' + getTagName(childNode)); } else if (!forceKeyed && isNullOrUndef(key)) { if (Object.keys(foundKeys).length !== 0) { return 'Encountered children with key missing. Location: \n' + getTagName(childNode); } continue; } if (foundKeys[key]) { return 'Encountered two children with same key: {' + key + '}. Location: \n' + getTagName(childNode); } foundKeys[key] = true; } } function validateVNodeElementChildren(vNode) { { if (vNode.childFlags === 1 /* HasInvalidChildren */) { return; } if (vNode.flags & 64 /* InputElement */) { throwError("input elements can't have children."); } if (vNode.flags & 128 /* TextareaElement */) { throwError("textarea elements can't have children."); } if (vNode.flags & 481 /* Element */) { var voidTypes = { area: true, base: true, br: true, col: true, command: true, embed: true, hr: true, img: true, input: true, keygen: true, link: true, meta: true, param: true, source: true, track: true, wbr: true }; var tag = vNode.type.toLowerCase(); if (tag === 'media') { throwError("media elements can't have children."); } if (voidTypes[tag]) { throwError((tag + " elements can't have children.")); } } } } function validateKeys(vNode) { { // Checks if there is any key missing or duplicate keys if (vNode.isValidated === false && vNode.children && vNode.flags & 481 /* Element */) { var error = DEV_ValidateKeys(Array.isArray(vNode.children) ? vNode.children : [vNode.children], (vNode.childFlags & 8 /* HasKeyedChildren */) > 0); if (error) { throwError(error + getTagName(vNode)); } } vNode.isValidated = true; } } function throwIfObjectIsNotVNode(input) { if (!isNumber(input.flags)) { throwError(("normalization received an object that's not a valid VNode, you should stringify it first or fix createVNode flags. Object: \"" + (JSON.stringify(input)) + "\".")); } } var keyPrefix = '$'; function V(childFlags, children, className, flags, key, props, ref, type) { { this.isValidated = false; } this.childFlags = childFlags; this.children = children; this.className = className; this.dom = null; this.flags = flags; this.key = key === void 0 ? null : key; this.props = props === void 0 ? null : props; this.ref = ref === void 0 ? null : ref; this.type = type; } function createVNode(flags, type, className, children, childFlags, props, key, ref) { { if (flags & 14 /* Component */) { throwError('Creating Component vNodes using createVNode is not allowed. Use Inferno.createComponentVNode method.'); } } var childFlag = childFlags === void 0 ? 1 /* HasInvalidChildren */ : childFlags; var vNode = new V(childFlag, children, className, flags, key, props, ref, type); var optsVNode = options.createVNode; if (isFunction(optsVNode)) { optsVNode(vNode); } if (childFlag === 0 /* UnknownChildren */) { normalizeChildren(vNode, vNode.children); } { validateVNodeElementChildren(vNode); } return vNode; } function createComponentVNode(flags, type, props, key, ref) { { if (flags & 1 /* HtmlElement */) { throwError('Creating element vNodes using createComponentVNode is not allowed. Use Inferno.createVNode method.'); } } if ((flags & 2 /* ComponentUnknown */) !== 0) { if (type.prototype && type.prototype.render) { flags = 4 /* ComponentClass */; } else if (type.render) { flags = 32776 /* ForwardRefComponent */; type = type.render; } else { flags = 8 /* ComponentFunction */; } } // set default props var defaultProps = type.defaultProps; if (!isNullOrUndef(defaultProps)) { if (!props) { props = {}; // Props can be referenced and modified at application level so always create new object } for (var prop in defaultProps) { if (isUndefined(props[prop])) { props[prop] = defaultProps[prop]; } } } if ((flags & 8 /* ComponentFunction */) > 0 && (flags & 32768 /* ForwardRef */) === 0) { var defaultHooks = type.defaultHooks; if (!isNullOrUndef(defaultHooks)) { if (!ref) { // As ref cannot be referenced from application level, we can use the same refs object ref = defaultHooks; } else { for (var prop$1 in defaultHooks) { if (isUndefined(ref[prop$1])) { ref[prop$1] = defaultHooks[prop$1]; } } } } } var vNode = new V(1 /* HasInvalidChildren */, null, null, flags, key, props, ref, type); var optsVNode = options.createVNode; if (isFunction(optsVNode)) { optsVNode(vNode); } return vNode; } function createTextVNode(text, key) { return new V(1 /* HasInvalidChildren */, isNullOrUndef(text) ? '' : text, null, 16 /* Text */, key, null, null, null); } function createFragment(children, childFlags, key) { var fragment = createVNode(8192 /* Fragment */, 8192 /* Fragment */, null, children, childFlags, null, key, null); switch (fragment.childFlags) { case 1 /* HasInvalidChildren */: fragment.children = createVoidVNode(); fragment.childFlags = 2 /* HasVNodeChildren */; break; case 16 /* HasTextChildren */: fragment.children = [createTextVNode(children)]; fragment.childFlags = 4 /* HasNonKeyedChildren */; break; default: break; } return fragment; } function normalizeProps(vNode) { var props = vNode.props; if (props) { var flags = vNode.flags; if (flags & 481 /* Element */) { if (props.children !== void 0 && isNullOrUndef(vNode.children)) { normalizeChildren(vNode, props.children); } if (props.className !== void 0) { vNode.className = props.className || null; props.className = undefined; } } if (props.key !== void 0) { vNode.key = props.key; props.key = undefined; } if (props.ref !== void 0) { if (flags & 8 /* ComponentFunction */) { vNode.ref = combineFrom(vNode.ref, props.ref); } else { vNode.ref = props.ref; } props.ref = undefined; } } return vNode; } /* * Fragment is different than normal vNode, * because when it needs to be cloned we need to clone its children too * But not normalize, because otherwise those possibly get KEY and re-mount */ function cloneFragment(vNodeToClone) { var clonedChildren; var oldChildren = vNodeToClone.children; var childFlags = vNodeToClone.childFlags; if (childFlags === 2 /* HasVNodeChildren */) { clonedChildren = directClone(oldChildren); } else if (childFlags & 12 /* MultipleChildren */) { clonedChildren = []; for (var i = 0, len = oldChildren.length; i < len; ++i) { clonedChildren.push(directClone(oldChildren[i])); } } return createFragment(clonedChildren, childFlags, vNodeToClone.key); } function directClone(vNodeToClone) { var flags = vNodeToClone.flags & -81921 /* ClearInUseNormalized */; var props = vNodeToClone.props; if (flags & 14 /* Component */) { if (!isNull(props)) { var propsToClone = props; props = {}; for (var key in propsToClone) { props[key] = propsToClone[key]; } } } if ((flags & 8192 /* Fragment */) === 0) { return new V(vNodeToClone.childFlags, vNodeToClone.children, vNodeToClone.className, flags, vNodeToClone.key, props, vNodeToClone.ref, vNodeToClone.type); } return cloneFragment(vNodeToClone); } function createVoidVNode() { return createTextVNode('', null); } function createPortal(children, container) { return createVNode(1024 /* Portal */, 1024 /* Portal */, null, children, 0 /* UnknownChildren */, null, isInvalid(children) ? null : children.key, container); } function _normalizeVNodes(nodes, result, index, currentKey) { for (var len = nodes.length; index < len; index++) { var n = nodes[index]; if (!isInvalid(n)) { var newKey = currentKey + keyPrefix + index; if (isArray(n)) { _normalizeVNodes(n, result, 0, newKey); } else { if (isStringOrNumber(n)) { n = createTextVNode(n, newKey); } else { { throwIfObjectIsNotVNode(n); } var oldKey = n.key; var isPrefixedKey = isString(oldKey) && oldKey[0] === keyPrefix; if (n.flags & 81920 /* InUseOrNormalized */ || isPrefixedKey) { n = directClone(n); } n.flags |= 65536 /* Normalized */; if (isNull(oldKey) || isPrefixedKey) { n.key = newKey; } else { n.key = currentKey + oldKey; } } result.push(n); } } } } function getFlagsForElementVnode(type) { switch (type) { case 'svg': return 32 /* SvgElement */; case 'input': return 64 /* InputElement */; case 'select': return 256 /* SelectElement */; case 'textarea': return 128 /* TextareaElement */; case Fragment: return 8192 /* Fragment */; default: return 1 /* HtmlElement */; } } function normalizeChildren(vNode, children) { var newChildren; var newChildFlags = 1 /* HasInvalidChildren */; // Don't change children to match strict equal (===) true in patching if (isInvalid(children)) { newChildren = children; } else if (isStringOrNumber(children)) { newChildFlags = 16 /* HasTextChildren */; newChildren = children; } else if (isArray(children)) { var len = children.length; for (var i = 0; i < len; ++i) { var n = children[i]; if (isInvalid(n) || isArray(n)) { newChildren = newChildren || children.slice(0, i); _normalizeVNodes(children, newChildren, i, ''); break; } else if (isStringOrNumber(n)) { newChildren = newChildren || children.slice(0, i); newChildren.push(createTextVNode(n, keyPrefix + i)); } else { { throwIfObjectIsNotVNode(n); } var key = n.key; var needsCloning = (n.flags & 81920 /* InUseOrNormalized */) > 0; var isNullKey = isNull(key); var isPrefixed = !isNullKey && isString(key) && key[0] === keyPrefix; if (needsCloning || isNullKey || isPrefixed) { newChildren = newChildren || children.slice(0, i); if (needsCloning || isPrefixed) { n = directClone(n); } if (isNullKey || isPrefixed) { n.key = keyPrefix + i; } newChildren.push(n); } else if (newChildren) { newChildren.push(n); } n.flags |= 65536 /* Normalized */; } } newChildren = newChildren || children; if (newChildren.length === 0) { newChildFlags = 1 /* HasInvalidChildren */; } else { newChildFlags = 8 /* HasKeyedChildren */; } } else { newChildren = children; newChildren.flags |= 65536 /* Normalized */; if (children.flags & 81920 /* InUseOrNormalized */) { newChildren = directClone(children); } newChildFlags = 2 /* HasVNodeChildren */; } vNode.children = newChildren; vNode.childFlags = newChildFlags; return vNode; } /** * Links given data to event as first parameter * @param {*} data data to be linked, it will be available in function as first parameter * @param {Function} event Function to be called when event occurs * @returns {{data: *, event: Function}} */ function linkEvent(data, event) { if (isFunction(event)) { return { data: data, event: event }; } return null; // Return null when event is invalid, to avoid creating unnecessary event handlers } var xlinkNS = 'http://www.w3.org/1999/xlink'; var xmlNS = 'http://www.w3.org/XML/1998/namespace'; var namespaces = { 'xlink:actuate': xlinkNS, 'xlink:arcrole': xlinkNS, 'xlink:href': xlinkNS, 'xlink:role': xlinkNS, 'xlink:show': xlinkNS, 'xlink:title': xlinkNS, 'xlink:type': xlinkNS, 'xml:base': xmlNS, 'xml:lang': xmlNS, 'xml:space': xmlNS }; function getDelegatedEventObject(v) { return { onClick: v, onDblClick: v, onFocusIn: v, onFocusOut: v, onKeyDown: v, onKeyPress: v, onKeyUp: v, onMouseDown: v, onMouseMove: v, onMouseUp: v, onSubmit: v, onTouchEnd: v, onTouchMove: v, onTouchStart: v }; } var attachedEventCounts = getDelegatedEventObject(0); var attachedEvents = getDelegatedEventObject(null); var delegatedEvents = getDelegatedEventObject(true); function handleEvent(name, nextEvent, dom) { var eventsObject = dom.$EV; if (nextEvent) { if (attachedEventCounts[name] === 0) { attachedEvents[name] = attachEventToDocument(name); } if (!eventsObject) { eventsObject = dom.$EV = getDelegatedEventObject(null); } if (!eventsObject[name]) { ++attachedEventCounts[name]; } eventsObject[name] = nextEvent; } else if (eventsObject && eventsObject[name]) { if (--attachedEventCounts[name] === 0) { document.removeEventListener(normalizeEventName(name), attachedEvents[name]); attachedEvents[name] = null; } eventsObject[name] = null; } } function dispatchEvents(event, target, isClick, name, eventData) { var dom = target; while (!isNull(dom)) { // Html Nodes can be nested fe: span inside button in that scenario browser does not handle disabled attribute on parent, // because the event listener is on document.body // Don't process clicks on disabled elements if (isClick && dom.disabled) { return; } var eventsObject = dom.$EV; if (eventsObject) { var currentEvent = eventsObject[name]; if (currentEvent) { // linkEvent object eventData.dom = dom; if (currentEvent.event) { currentEvent.event(currentEvent.data, event); } else { currentEvent(event); } if (event.cancelBubble) { return; } } } dom = dom.parentNode; } } function normalizeEventName(name) { return name.substr(2).toLowerCase(); } function stopPropagation() { this.cancelBubble = true; if (!this.immediatePropagationStopped) { this.stopImmediatePropagation(); } } function attachEventToDocument(name) { var docEvent = function (event) { var isClick = name === 'onClick' || name === 'onDblClick'; if (isClick && event.button !== 0) { // Firefox incorrectly triggers click event for mid/right mouse buttons. // This bug has been active for 12 years. // https://bugzilla.mozilla.org/show_bug.cgi?id=184051 event.stopPropagation(); return; } event.stopPropagation = stopPropagation; // Event data needs to be object to save reference to currentTarget getter var eventData = { dom: document }; Object.defineProperty(event, 'currentTarget', { configurable: true, get: function get() { return eventData.dom; } }); dispatchEvents(event, event.target, isClick, name, eventData); }; document.addEventListener(normalizeEventName(name), docEvent); return docEvent; } function isSameInnerHTML(dom, innerHTML) { var tempdom = document.createElement('i'); tempdom.innerHTML = innerHTML; return tempdom.innerHTML === dom.innerHTML; } function triggerEventListener(props, methodName, e) { if (props[methodName]) { var listener = props[methodName]; if (listener.event) { listener.event(listener.data, e); } else { listener(e); } } else { var nativeListenerName = methodName.toLowerCase(); if (props[nativeListenerName]) { props[nativeListenerName](e); } } } function createWrappedFunction(methodName, applyValue) { var fnMethod = function (e) { var vNode = this.$V; // If vNode is gone by the time event fires, no-op if (!vNode) { return; } var props = vNode.props || EMPTY_OBJ; var dom = vNode.dom; if (isString(methodName)) { triggerEventListener(props, methodName, e); } else { for (var i = 0; i < methodName.length; ++i) { triggerEventListener(props, methodName[i], e); } } if (isFunction(applyValue)) { var newVNode = this.$V; var newProps = newVNode.props || EMPTY_OBJ; applyValue(newProps, dom, false, newVNode); } }; Object.defineProperty(fnMethod, 'wrapped', { configurable: false, enumerable: false, value: true, writable: false }); return fnMethod; } function isCheckedType(type) { return type === 'checkbox' || type === 'radio'; } var onTextInputChange = createWrappedFunction('onInput', applyValueInput); var wrappedOnChange = createWrappedFunction(['onClick', 'onChange'], applyValueInput); /* tslint:disable-next-line:no-empty */ function emptywrapper(event) { event.stopPropagation(); } emptywrapper.wrapped = true; function inputEvents(dom, nextPropsOrEmpty) { if (isCheckedType(nextPropsOrEmpty.type)) { dom.onchange = wrappedOnChange; dom.onclick = emptywrapper; } else { dom.oninput = onTextInputChange; } } function applyValueInput(nextPropsOrEmpty, dom) { var type = nextPropsOrEmpty.type; var value = nextPropsOrEmpty.value; var checked = nextPropsOrEmpty.checked; var multiple = nextPropsOrEmpty.multiple; var defaultValue = nextPropsOrEmpty.defaultValue; var hasValue = !isNullOrUndef(value); if (type && type !== dom.type) { dom.setAttribute('type', type); } if (!isNullOrUndef(multiple) && multiple !== dom.multiple) { dom.multiple = multiple; } if (!isNullOrUndef(defaultValue) && !hasValue) { dom.defaultValue = defaultValue + ''; } if (isCheckedType(type)) { if (hasValue) { dom.value = value; } if (!isNullOrUndef(checked)) { dom.checked = checked; } } else { if (hasValue && dom.value !== value) { dom.defaultValue = value; dom.value = value; } else if (!isNullOrUndef(checked)) { dom.checked = checked; } } } function updateChildOptions(vNode, value) { if (vNode.type === 'option') { updateChildOption(vNode, value); } else { var children = vNode.children; var flags = vNode.flags; if (flags & 4 /* ComponentClass */) { updateChildOptions(children.$LI, value); } else if (flags & 8 /* ComponentFunction */) { updateChildOptions(children, value); } else if (vNode.childFlags === 2 /* HasVNodeChildren */) { updateChildOptions(children, value); } else if (vNode.childFlags & 12 /* MultipleChildren */) { for (var i = 0, len = children.length; i < len; ++i) { updateChildOptions(children[i], value); } } } } function updateChildOption(vNode, value) { var props = vNode.props || EMPTY_OBJ; var dom = vNode.dom; // we do this as multiple may have changed dom.value = props.value; if (props.value === value || (isArray(value) && value.indexOf(props.value) !== -1)) { dom.selected = true; } else if (!isNullOrUndef(value) || !isNullOrUndef(props.selected)) { dom.selected = props.selected || false; } } var onSelectChange = createWrappedFunction('onChange', applyValueSelect); function selectEvents(dom) { dom.onchange = onSelectChange; } function applyValueSelect(nextPropsOrEmpty, dom, mounting, vNode) { var multiplePropInBoolean = Boolean(nextPropsOrEmpty.multiple); if (!isNullOrUndef(nextPropsOrEmpty.multiple) && multiplePropInBoolean !== dom.multiple) { dom.multiple = multiplePropInBoolean; } var childFlags = vNode.childFlags; if (childFlags !== 1 /* HasInvalidChildren */) { var value = nextPropsOrEmpty.value; if (mounting && isNullOrUndef(value)) { value = nextPropsOrEmpty.defaultValue; } updateChildOptions(vNode, value); } } var onTextareaInputChange = createWrappedFunction('onInput', applyValueTextArea); var wrappedOnChange$1 = createWrappedFunction('onChange'); function textAreaEvents(dom, nextPropsOrEmpty) { dom.oninput = onTextareaInputChange; if (nextPropsOrEmpty.onChange) { dom.onchange = wrappedOnChange$1; } } function applyValueTextArea(nextPropsOrEmpty, dom, mounting) { var value = nextPropsOrEmpty.value; var domValue = dom.value; if (isNullOrUndef(value)) { if (mounting) { var defaultValue = nextPropsOrEmpty.defaultValue; if (!isNullOrUndef(defaultValue) && defaultValue !== domValue) { dom.defaultValue = defaultValue; dom.value = defaultValue; } } } else if (domValue !== value) { /* There is value so keep it controlled */ dom.defaultValue = value; dom.value = value; } } /** * There is currently no support for switching same input between controlled and nonControlled * If that ever becomes a real issue, then re design controlled elements * Currently user must choose either controlled or non-controlled and stick with that */ function processElement(flags, vNode, dom, nextPropsOrEmpty, mounting, isControlled) { if (flags & 64 /* InputElement */) { applyValueInput(nextPropsOrEmpty, dom); } else if (flags & 256 /* SelectElement */) { applyValueSelect(nextPropsOrEmpty, dom, mounting, vNode); } else if (flags & 128 /* TextareaElement */) { applyValueTextArea(nextPropsOrEmpty, dom, mounting); } if (isControlled) { dom.$V = vNode; } } function addFormElementEventHandlers(flags, dom, nextPropsOrEmpty) { if (flags & 64 /* InputElement */) { inputEvents(dom, nextPropsOrEmpty); } else if (flags & 256 /* SelectElement */) { selectEvents(dom); } else if (flags & 128 /* TextareaElement */) { textAreaEvents(dom, nextPropsOrEmpty); } } function isControlledFormElement(nextPropsOrEmpty) { return nextPropsOrEmpty.type && isCheckedType(nextPropsOrEmpty.type) ? !isNullOrUndef(nextPropsOrEmpty.checked) : !isNullOrUndef(nextPropsOrEmpty.value); } function createRef() { return { current: null }; } function forwardRef(render) { if (!isFunction(render)) { warning(("forwardRef requires a render function but was given " + (render === null ? 'null' : typeof render) + ".")); return; } var fwRef = { render: render }; Object.seal(fwRef); return fwRef; } function pushRef(dom, value, lifecycle) { lifecycle.push(function () { value(dom); }); } function unmountRef(ref) { if (ref) { if (isFunction(ref)) { ref(null); } else if (ref.current) { ref.current = null; } } } function mountRef(ref, value, lifecycle) { if (ref) { if (isFunction(ref)) { pushRef(value, ref, lifecycle); } else if (ref.current !== void 0) { ref.current = value; } } } function remove(vNode, parentDOM) { unmount(vNode); if (parentDOM) { removeVNodeDOM(vNode, parentDOM); } } function unmount(vNode) { var flags = vNode.flags; var children = vNode.children; var ref; if (flags & 481 /* Element */) { ref = vNode.ref; var props = vNode.props; unmountRef(ref); var childFlags = vNode.childFlags; if (!isNull(props)) { var keys = Object.keys(props); for (var i = 0, len = keys.length; i < len; i++) { var key = keys[i]; if (delegatedEvents[key]) { handleEvent(key, null, vNode.dom); } } } if (childFlags & 12 /* MultipleChildren */) { unmountAllChildren(children); } else if (childFlags === 2 /* HasVNodeChildren */) { unmount(children); } } else if (children) { if (flags & 4 /* ComponentClass */) { if (isFunction(children.componentWillUnmount)) { children.componentWillUnmount(); } unmountRef(vNode.ref); children.$UN = true; unmount(children.$LI); } else if (flags & 8 /* ComponentFunction */) { ref = vNode.ref; if (!isNullOrUndef(ref) && isFunction(ref.onComponentWillUnmount)) { ref.onComponentWillUnmount(findDOMfromVNode(vNode, true), vNode.props || EMPTY_OBJ); } unmount(children); } else if (flags & 1024 /* Portal */) { remove(children, vNode.ref); } else if (flags & 8192 /* Fragment */) { if (vNode.childFlags & 12 /* MultipleChildren */) { unmountAllChildren(children); } } } } function unmountAllChildren(children) { for (var i = 0, len = children.length; i < len; ++i) { unmount(children[i]); } } function clearDOM(dom) { // Optimization for clearing dom dom.textContent = ''; } function removeAllChildren(dom, vNode, children) { unmountAllChildren(children); if (vNode.flags & 8192 /* Fragment */) { removeVNodeDOM(vNode, dom); } else { clearDOM(dom); } } function createLinkEvent(linkEvent, nextValue) { return function (e) { linkEvent(nextValue.data, e); }; } function patchEvent(name, nextValue, dom) { var nameLowerCase = name.toLowerCase(); if (!isFunction(nextValue) && !isNullOrUndef(nextValue)) { var linkEvent = nextValue.event; if (isFunction(linkEvent)) { dom[nameLowerCase] = createLinkEvent(linkEvent, nextValue); } else { // Development warning { throwError(("an event on a VNode \"" + name + "\". was not a function or a valid linkEvent.")); } } } else { var domEvent = dom[nameLowerCase]; // if the function is wrapped, that means it's been controlled by a wrapper if (!domEvent || !domEvent.wrapped) { dom[nameLowerCase] = nextValue; } } } // We are assuming here that we come from patchProp routine // -nextAttrValue cannot be null or undefined function patchStyle(lastAttrValue, nextAttrValue, dom) { if (isNullOrUndef(nextAttrValue)) { dom.removeAttribute('style'); return; } var domStyle = dom.style; var style; var value; if (isString(nextAttrValue)) { domStyle.cssText = nextAttrValue; return; } if (!isNullOrUndef(lastAttrValue) && !isString(lastAttrValue)) { for (style in nextAttrValue) { // do not add a hasOwnProperty check here, it affects performance value = nextAttrValue[style]; if (value !== lastAttrValue[style]) { domStyle.setProperty(style, value); } } for (style in lastAttrValue) { if (isNullOrUndef(nextAttrValue[style])) { domStyle.removeProperty(style); } } } else { for (style in nextAttrValue) { value = nextAttrValue[style]; domStyle.setProperty(style, value); } } } function patchProp(prop, lastValue, nextValue, dom, isSVG, hasControlledValue, lastVNode) { switch (prop) { case 'children': case 'childrenType': case 'className': case 'defaultValue': case 'key': case 'multiple': case 'ref': break; case 'autoFocus': dom.autofocus = !!nextValue; break; case 'allowfullscreen': case 'autoplay': case 'capture': case 'checked': case 'controls': case 'default': case 'disabled': case 'hidden': case 'indeterminate': case 'loop': case 'muted': case 'novalidate': case 'open': case 'readOnly': case 'required': case 'reversed': case 'scoped': case 'seamless': case 'selected': dom[prop] = !!nextValue; break; case 'defaultChecked': case 'value': case 'volume': if (hasControlledValue && prop === 'value') { break; } var value = isNullOrUndef(nextValue) ? '' : nextValue; if (dom[prop] !== value) { dom[prop] = value; } break; case 'style': patchStyle(lastValue, nextValue, dom); break; case 'dangerouslySetInnerHTML': var lastHtml = (lastValue && lastValue.__html) || ''; var nextHtml = (nextValue && nextValue.__html) || ''; if (lastHtml !== nextHtml) { if (!isNullOrUndef(nextHtml) && !isSameInnerHTML(dom, nextHtml)) { if (!isNull(lastVNode)) { if (lastVNode.childFlags & 12 /* MultipleChildren */) { unmountAllChildren(lastVNode.children); } else if (lastVNode.childFlags === 2 /* HasVNodeChildren */) { unmount(lastVNode.children); } lastVNode.children = null; lastVNode.childFlags = 1 /* HasInvalidChildren */; } dom.innerHTML = nextHtml; } } break; default: if (delegatedEvents[prop]) { if (!(lastValue && nextValue && !isFunction(lastValue) && !isFunction(nextValue) && lastValue.event === nextValue.event && lastValue.data === nextValue.data)) { handleEvent(prop, nextValue, dom); } } else if (prop.charCodeAt(0) === 111 && prop.charCodeAt(1) === 110) { patchEvent(prop, nextValue, dom); } else if (isNullOrUndef(nextValue)) { dom.removeAttribute(prop); } else if (isSVG && namespaces[prop]) { // We optimize for isSVG being false // If we end up in this path we can read property again dom.setAttributeNS(namespaces[prop], prop, nextValue); } else { dom.setAttribute(prop, nextValue); } break; } } function mountProps(vNode, flags, props, dom, isSVG) { var hasControlledValue = false; var isFormElement = (flags & 448 /* FormElement */) > 0; if (isFormElement) { hasControlledValue = isControlledFormElement(props); if (hasControlledValue) { addFormElementEventHandlers(flags, dom, props); } } for (var prop in props) { // do not add a hasOwnProperty check here, it affects performance patchProp(prop, null, props[prop], dom, isSVG, hasControlledValue, null); } if (isFormElement) { processElement(flags, vNode, dom, props, true, hasControlledValue); } } function warnAboutOldLifecycles(component) { var oldLifecycles = []; if (component.componentWillMount) { oldLifecycles.push('componentWillMount'); } if (component.componentWillReceiveProps) { oldLifecycles.push('componentWillReceiveProps'); } if (component.componentWillUpdate) { oldLifecycles.push('componentWillUpdate'); } if (oldLifecycles.length > 0) { warning(("\n Warning: Unsafe legacy lifecycles will not be called for components using new component APIs.\n " + (getComponentName(component)) + " contains the following legacy lifecycles:\n " + (oldLifecycles.join('\n')) + "\n The above lifecycles should be removed.\n ")); } } function renderNewInput(instance, props, context) { var nextInput = handleComponentInput(instance.render(props, instance.state, context)); var childContext = context; if (isFunction(instance.getChildContext)) { childContext = combineFrom(context, instance.getChildContext()); } instance.$CX = childContext; return nextInput; } function createClassComponentInstance(vNode, Component, props, context, isSVG, lifecycle) { var instance = new Component(props, context); var usesNewAPI = (instance.$N = Boolean(Component.getDerivedStateFromProps || instance.getSnapshotBeforeUpdate)); instance.$SVG = isSVG; instance.$L = lifecycle; { if (instance.getDerivedStateFromProps) { warning(((getComponentName(instance)) + " getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.")); } if (usesNewAPI) { warnAboutOldLifecycles(instance); } } vNode.children = instance; instance.$BS = false; instance.context = context; if (instance.props === EMPTY_OBJ) { instance.props = props; } if (!usesNewAPI) { if (isFunction(instance.componentWillMount)) { instance.$BR = true; instance.componentWillMount(); var pending = instance.$PS; if (!isNull(pending)) { var state = instance.state; if (isNull(state)) { instance.state = pending; } else { for (var key in pending) { state[ke