intact-vue
Advanced tools
Comparing version 0.5.11 to 1.0.0
1512
dist/index.js
@@ -1,1062 +0,804 @@ | ||
'use strict'; | ||
import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
import _createClass from '@babel/runtime/helpers/createClass'; | ||
import _get from '@babel/runtime/helpers/get'; | ||
import _inherits from '@babel/runtime/helpers/inherits'; | ||
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn'; | ||
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf'; | ||
import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
import Intact from 'intact/dist'; | ||
import { createApp, h as h$1, KeepAlive, getCurrentInstance, Fragment, cloneVNode, Text, Comment, camelize, isVNode, vShow, isRef, createVNode } from 'vue'; | ||
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; | ||
import _typeof from '@babel/runtime/helpers/typeof'; | ||
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function isIntactComponent(vNode) { | ||
// don't convert Intact functional component to Intact vNode, | ||
// because it's propTypes are missing | ||
return !!vNode.type.Component; // || vNode.type.cid === cid; | ||
} | ||
var cid = 'IntactVueNext'; | ||
var warn = console.warn; | ||
var noop = function noop() {}; | ||
function silentWarn() { | ||
console.warn = noop; | ||
} | ||
function resetWarn() { | ||
console.warn = warn; | ||
} | ||
var Vue = _interopDefault(require('vue')); | ||
var Intact = _interopDefault(require('intact/dist')); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var isFunction = Intact.utils.isFunction; // we must use this hack method to get patch function | ||
var internals; | ||
createApp({ | ||
render: function render() { | ||
return h$1(KeepAlive, null, h$1(function () { | ||
var instance = getCurrentInstance(); | ||
internals = instance.parent.ctx.renderer; | ||
})); | ||
} | ||
}).mount(document.createElement('div')); | ||
var _internals = internals, | ||
patch = _internals.p, | ||
unmount = _internals.um; | ||
var ignorePropRegExp = /_ev[A-Z]/; | ||
var Wrapper = /*#__PURE__*/function () { | ||
function Wrapper() { | ||
_classCallCheck(this, Wrapper); | ||
} | ||
_createClass(Wrapper, [{ | ||
key: "init", | ||
value: function init(lastVNode, nextVNode) { | ||
// let the component destroy by itself | ||
this.destroyed = true; | ||
this._addProps(nextVNode); | ||
var vueVNode = nextVNode.props.vueVNode; | ||
var parentDom = this.parentDom || document.createDocumentFragment(); | ||
patch(null, vueVNode, parentDom, null, getParentComponent(nextVNode)); // if the parentDom exists, Intact will append el to parentDom, but it has been appended by Vue | ||
// | ||
// if we wrap a functional component that returns mutliple vNodes, | ||
// the vueVNode.el will be the start anchor node of Fragment, | ||
// and the anchor will be appended by Intact. | ||
// This will change the order of nodes, | ||
// so we return the end anchor for Intact to append. | ||
if (isFunction(vueVNode.type)) { | ||
var subTree = vueVNode.component.subTree; | ||
if (subTree.type === Fragment) { | ||
return subTree.anchor; | ||
} | ||
} | ||
return vueVNode.el; | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(lastVNode, nextVNode) { | ||
this._addProps(nextVNode); | ||
var vueVNode = nextVNode.props.vueVNode; // render(vueVNode, this.container); | ||
patch(lastVNode.props.vueVNode, vueVNode, this.parentDom, null, getParentComponent(nextVNode)); | ||
return vueVNode.el; | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy(vNode) { | ||
// if we wrap a Intact functional component which return a Inact component, | ||
// the dom will be a comment node that will be replaced by InactVue, | ||
// or the dom will be a text node which specify the start anchor of Fragment, | ||
// in this case we set _unmount to let Inact never remove it, | ||
// and set doRemove to true to let Vue remove it instead. | ||
var vueVNode = vNode.props.vueVNode; | ||
var doRemove = false; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
if (vueVNode.type.cid === cid) { | ||
vNode.dom._unmount = noop; | ||
doRemove = true; | ||
} | ||
unmount(vNode.props.vueVNode, null, null, doRemove); | ||
} // maybe the props has been changed, so we change the vueVNode's data | ||
}, { | ||
key: "_addProps", | ||
value: function _addProps(vNode) { | ||
// for Intact reusing the dom | ||
this.vdt = { | ||
vNode: vNode | ||
}; | ||
var props = vNode.props; | ||
var vueVNode = props.vueVNode; // if we reuse the vNode, clone it | ||
if (vueVNode.el) { | ||
vueVNode = cloneVNode(vueVNode); | ||
} | ||
var shouldAssign = true; | ||
for (var key in props) { | ||
if (key === 'vueVNode') continue; | ||
if (ignorePropRegExp.test(key)) continue; | ||
var vueProps = vueVNode.props; | ||
if (shouldAssign) { | ||
// props may be a EMPTY_OBJ, but we can not get its reference, | ||
// so we use a flag to handle it | ||
vueProps = vueVNode.props = _objectSpread({}, vueVNode.props); | ||
shouldAssign = false; // should change patchFlag to let Vue full diff props | ||
vueVNode.patchFlag |= 16; | ||
} | ||
var prop = props[key]; // is event | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
if (key === 'className') { | ||
vueProps["class"] = prop; | ||
} else if (key === 'style') { | ||
vueProps.style = _objectSpread(_objectSpread({}, vueProps.style), prop); | ||
} else if (key.substr(0, 3) === 'ev-') { | ||
var name = key.substr(3); | ||
vueProps["on" + name[0].toUpperCase() + name.substr(1)] = prop; | ||
} else { | ||
vueProps[key] = prop; | ||
} | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
vNode.props = _objectSpread(_objectSpread({}, props), {}, { | ||
vueVNode: vueVNode | ||
}); | ||
} | ||
} | ||
}]); | ||
return target; | ||
}; | ||
return Wrapper; | ||
}(); | ||
function getParentComponent(vNode) { | ||
var parentVNode = vNode.parentVNode; | ||
while (parentVNode) { | ||
var children = parentVNode.children; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
if (children && children.vueInstance) { | ||
return children.vueInstance.$parent.$; | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
parentVNode = parentVNode.parentVNode; | ||
} | ||
} | ||
var h = Intact.Vdt.miss.h; | ||
var _Intact$utils = Intact.utils, | ||
hasOwn = _Intact$utils.hasOwn, | ||
isArray = _Intact$utils.isArray, | ||
get = _Intact$utils.get, | ||
set = _Intact$utils.set, | ||
each = _Intact$utils.each, | ||
isString = _Intact$utils.isString, | ||
isFunction$1 = _Intact$utils.isFunction; | ||
function normalize(vNode) { | ||
if (vNode == null) return vNode; | ||
var type = _typeof(vNode); | ||
if (type === 'string' || type === 'number') return vNode; // is a intact vnode | ||
if (typeof vNode.type === 'number') return vNode; | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
if (vNode.type === Text) { | ||
return vNode.children; | ||
} | ||
return target; | ||
}; | ||
if (isIntactComponent(vNode)) { | ||
vNode = h(vNode.type.Component, normalizeProps(vNode), null, null, vNode.key, null); | ||
} else { | ||
// ignore comment vNode | ||
if (vNode.type === Comment) return null; // spread fragment | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
if (vNode.type === Fragment) { | ||
return normalizeChildren(vNode.children); | ||
} // Vue will add key 0 to v-if, but Intact will ignore it, so we cast it string | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var _Intact$Vdt$miss = Intact.Vdt.miss; | ||
var h = _Intact$Vdt$miss.h; | ||
var hooks = _Intact$Vdt$miss.hooks; | ||
var config = _Intact$Vdt$miss.config; | ||
var _Intact$utils = Intact.utils; | ||
var _get = _Intact$utils.get; | ||
var _set = _Intact$utils.set; | ||
var extend$1 = _Intact$utils.extend; | ||
var isArray = _Intact$utils.isArray; | ||
var create = _Intact$utils.create; | ||
var hasOwn = _Intact$utils.hasOwn; | ||
var each = _Intact$utils.each; | ||
var key = vNode.key === 0 ? '0' : vNode.key; | ||
vNode = h(Wrapper, { | ||
vueVNode: vNode | ||
}, null, vNode.props && vNode.props["class"], key); | ||
} // tell Vue that this is a read only object, and don't reactive it | ||
var _textVNode = Vue.prototype._v(''); | ||
var VueVNode = _textVNode.constructor; | ||
var _testData = {}; | ||
var _vm = new Vue({ data: _testData }); | ||
var __ob__ = _testData.__ob__; | ||
// for scoped style | ||
if (hooks) { | ||
hooks.beforeInsert = function (vNode) { | ||
var dom = vNode.dom; | ||
var parent = vNode.parentVNode; | ||
var i = void 0; | ||
var j = void 0; | ||
while (parent) { | ||
if ((i = parent.tag) && i.cid === 'IntactVue' && (i = parent.children.$options)) { | ||
if ((i = j = i.parent) && (i = i.$options) && (i = i._scopeId)) { | ||
dom.setAttribute(i, ''); | ||
} | ||
if (j) { | ||
// find vue component parent while we has found the intact component | ||
parent = j.$parent; | ||
while (parent) { | ||
if ((i = parent.$options) && (i = i._scopeId)) { | ||
dom.setAttribute(i, ''); | ||
} | ||
parent = parent.$parent; | ||
} | ||
} | ||
break; | ||
} else { | ||
parent = parent.parentVNode; | ||
} | ||
} | ||
}; | ||
vNode.__v_isReadonly = true; | ||
return vNode; | ||
} | ||
// disable delegate events | ||
if (config) { | ||
config.disableDelegate = true; | ||
} | ||
// for get $parent | ||
Vue.mixin({ | ||
beforeCreate: function beforeCreate() { | ||
if (!this.$parent && this.$vnode) { | ||
this.$parent = this.$vnode.context; | ||
} | ||
} | ||
}); | ||
function normalizeChildren(vNodes) { | ||
var loop = function loop(vNodes) { | ||
if (isArray(vNodes)) { | ||
var _ret = []; | ||
vNodes.forEach(function (vNode) { | ||
if (isArray(vNode)) { | ||
_ret.push.apply(_ret, loop(vNode)); | ||
} else { | ||
_ret.push(normalize(vNode)); | ||
} | ||
}); | ||
return _ret; | ||
var loop = function loop(vNodes) { | ||
if (Array.isArray(vNodes)) { | ||
var _ret = []; | ||
vNodes.forEach(function (vNode) { | ||
if (Array.isArray(vNode)) { | ||
_ret.push.apply(_ret, _toConsumableArray(loop(vNode))); | ||
} else { | ||
_ret.push(normalize(vNode)); | ||
} | ||
return normalize(vNodes); | ||
}; | ||
var ret = loop(vNodes); | ||
if (Array.isArray(ret)) { | ||
var l = ret.length; | ||
return l === 0 ? undefined : l === 1 ? ret[0] : ret; | ||
}); | ||
return _ret; | ||
} | ||
return ret; | ||
} | ||
function normalize(vNode) { | ||
if (vNode == null) return vNode; | ||
var type = typeof vNode === 'undefined' ? 'undefined' : _typeof(vNode); | ||
if (type === 'string' || type === 'number') return vNode; | ||
// is a intact vnode | ||
if (vNode.type) return vNode; | ||
if (vNode.text !== undefined) { | ||
return vNode.text; | ||
} | ||
return normalize(vNodes); | ||
}; | ||
if (isIntactComponent(vNode)) { | ||
var options = vNode.componentOptions; | ||
vNode = h(options.Ctor, normalizeProps(vNode), null, null, vNode.key, vNode.ref); | ||
} else { | ||
vNode = h(Wrapper, { vueVNode: vNode }, null, handleClassName(vNode), vNode.key); | ||
} | ||
var ret = loop(vNodes); | ||
// let vue don't observe it when it is used as property, ksc-fe/kpc#500 | ||
// we can not use `vNode._isVue = true`, because it will affect vue-devtools. ksc-fe/kpc#512 | ||
vNode.__ob__ = __ob__; | ||
return vNode; | ||
if (Array.isArray(ret)) { | ||
var l = ret.length; | ||
return l === 0 ? undefined : l === 1 ? ret[0] : ret; | ||
} | ||
return ret; | ||
} | ||
function normalizeProps(vNode) { | ||
var componentOptions = vNode.componentOptions; | ||
var data = vNode.data; | ||
var attrs = data.attrs; | ||
var propTypes = componentOptions.Ctor.propTypes; | ||
var props = {}; | ||
var attrs = vNode.props; | ||
var slots = vNode.children; | ||
var Component = vNode.type.Component; | ||
var props = {}; | ||
var propTypes = Component.propTypes; | ||
if (attrs) { | ||
for (var key in attrs) { | ||
if (~['staticClass', 'class', 'style', 'staticStyle'].indexOf(key)) continue; | ||
var value = attrs[key]; | ||
if (propTypes) { | ||
var camelizedKey = camelize(key); | ||
if (hasOwn.call(propTypes, camelizedKey)) { | ||
key = camelizedKey; | ||
var tmp = void 0; | ||
if (( | ||
// value is Boolean | ||
(tmp = propTypes[key]) === Boolean || tmp && ( | ||
// value contains Boolean | ||
isArray(tmp) && tmp.indexOf(Boolean) > -1 || | ||
// value.type is Boolean | ||
tmp.type === Boolean || | ||
// value.type contains Boolean | ||
isArray(tmp.type) && tmp.type.indexOf(Boolean) > -1)) && (value === '' || value === key)) { | ||
value = true; | ||
} | ||
} | ||
} | ||
props[key] = value; | ||
} | ||
} | ||
for (var key in attrs) { | ||
var value = attrs[key]; | ||
// add className | ||
var className = handleClassName(vNode); | ||
if (className !== undefined) { | ||
props.className = className; | ||
} | ||
// add style | ||
var style = handleStyle(vNode); | ||
if (style !== undefined) { | ||
props.style = style; | ||
} | ||
switch (key) { | ||
case 'ref': | ||
break; | ||
// add key | ||
if (vNode.key) { | ||
props.key = vNode.key; | ||
} else if (data.key) { | ||
props.key = data.key; | ||
} | ||
case 'class': | ||
props.className = value; | ||
break; | ||
// if exists scoped slots | ||
var scopedSlots = data.scopedSlots; | ||
if (scopedSlots) { | ||
var blocks = props._blocks ? props._blocks : props._blocks = {}; | ||
case 'modelValue': | ||
props.value = value; | ||
break; | ||
var _loop = function _loop(_key) { | ||
blocks[_key] = function (parent) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
default: | ||
if (isOn(key)) { | ||
normalizeEvents(props, key, value); | ||
break; | ||
} | ||
return normalizeChildren(scopedSlots[_key].apply(this, args)); | ||
}; | ||
}; | ||
for (var _key in scopedSlots) { | ||
_loop(_key); | ||
if (propTypes) { | ||
var camelizedKey = camelize(key); | ||
value = normalizeBoolean(propTypes, key, camelizedKey, value); | ||
key = camelizedKey; | ||
} | ||
} | ||
// if exists v-model | ||
var model = data.model; | ||
if (model) { | ||
props.value = model.value; | ||
props['v-model'] = model.expression; | ||
props[key] = value; | ||
break; | ||
} | ||
if (data.directives) { | ||
var directives = data.directives; | ||
for (var i = 0; i < directives.length; i++) { | ||
var _model = directives[i]; | ||
if (_model.name === 'model') { | ||
// for vue@2.1.8 | ||
props.value = _model.value; | ||
props['v-model'] = _model.expression; | ||
break; | ||
} else if (_model.name === 'show' && !_model.value) { | ||
if (props.style) { | ||
props.style.display = 'none'; | ||
} else { | ||
props.style = { display: 'none' }; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// convert ref string to function | ||
handleRef(vNode, props); | ||
normalizeSlots(slots, props); | ||
normalizeDirs(vNode.dirs, props); | ||
normalizeRef(vNode.ref, props); | ||
return props; | ||
} | ||
var listeners = componentOptions.listeners; | ||
if (listeners) { | ||
var _loop2 = function _loop2(_key4) { | ||
var _cb = listeners[_key4]; | ||
var cb = _cb; | ||
var _isArray = isArray(_cb); | ||
var callCb = function callCb(c, v) { | ||
if (_isArray) { | ||
each(_cb, function (cb) { | ||
return cb(v); | ||
}); | ||
} else { | ||
_cb(v); | ||
} | ||
}; | ||
function normalizeBoolean(propTypes, key, camelizedKey, value) { | ||
if (hasOwn.call(propTypes, camelizedKey)) { | ||
var tmp; | ||
if (_key4 === 'input') { | ||
// is a v-model directive of vue | ||
_key4 = '$change:value'; | ||
cb = callCb; | ||
} else if (_key4.substr(0, 7) === 'update:') { | ||
// delegate update:prop(sync modifier) to $change:prop | ||
// propName has been camelized by Vue, don't do this again | ||
// key = `$change:${camelize(key.substr(7))}`; | ||
var _name = _key4.substr(7); | ||
if (_name.indexOf('-') > -1) return 'continue'; | ||
_key4 = '$change:' + _name; | ||
cb = callCb; | ||
} | ||
// if there is a $change:prop originally, set it as array | ||
var name = 'ev-' + camelize(_key4); | ||
if (props[name]) { | ||
props[name] = [].concat(props[name], cb); | ||
} else { | ||
props[name] = cb; | ||
} | ||
_key3 = _key4; | ||
}; | ||
for (var _key3 in listeners) { | ||
var _ret3 = _loop2(_key3); | ||
if (_ret3 === 'continue') continue; | ||
} | ||
if (( // value is Boolean | ||
(tmp = propTypes[camelizedKey]) === Boolean || tmp && ( // value contains Boolean | ||
isArray(tmp) && tmp.indexOf(Boolean) > -1 || // value.type is Boolean | ||
tmp.type === Boolean || // value.type contains Boolean | ||
isArray(tmp.type) && tmp.type.indexOf(Boolean) > -1)) && (value === '' || value === key)) { | ||
value = true; | ||
} | ||
} | ||
// handle children and blocks | ||
var slots = vNode.slots || resolveSlots(componentOptions.children); | ||
return value; | ||
} | ||
var _getChildrenAndBlocks = getChildrenAndBlocks(slots), | ||
children = _getChildrenAndBlocks.children, | ||
_blocks = _getChildrenAndBlocks._blocks; | ||
// for Intact Functional component, the blocks has been handled | ||
// In this case, we should merge them | ||
// maybe children has been set as property | ||
function normalizeSlots(slots, props) { | ||
if (!slots) return; // is array children | ||
if (isArray(slots)) { | ||
return props.children = normalizeChildren(slots); | ||
} // is string | ||
if (!hasOwn.call(props, 'children')) { | ||
props.children = children; | ||
} | ||
if (props._blocks) { | ||
extend$1(props._blocks, _blocks); | ||
} else { | ||
props._blocks = _blocks; | ||
} | ||
normalizeContext(vNode, props); | ||
if (isString(slots)) { | ||
return props.children = slots; | ||
} // the default slot maybe a scope slot, but we can not detect | ||
// whether it is or not, so we try to normalize it as children and | ||
// then treat it as a default scope slot too. | ||
return props; | ||
} | ||
function normalizeContext(vNode, props) { | ||
var context = vNode.context; | ||
props._context = { | ||
data: { | ||
get: function get$$1(name) { | ||
if (name != null) { | ||
// for get both props and data | ||
return _get(context, name); | ||
} else { | ||
return context.$data; | ||
} | ||
}, | ||
set: function set$$1(name, value) { | ||
_set(context, name, value); | ||
}, | ||
if (slots["default"]) { | ||
var slot = slots["default"]; | ||
$router: _get(context, '_routerRoot._router') | ||
} | ||
}; | ||
} | ||
try { | ||
// Vue will detect whether the slot is invoked outside or not, | ||
// but it does not affetch anything in here, | ||
// so we keep the warning silent | ||
// | ||
// Vue will warn if we get property of undefined, we keep it silent | ||
silentWarn(); | ||
props.children = normalizeChildren(ensureValidVNode(slot())); | ||
resetWarn(); | ||
} catch (e) {} | ||
} | ||
function getChildrenAndBlocks(slots) { | ||
var d = slots.default, | ||
rest = objectWithoutProperties(slots, ['default']); | ||
var blocks; | ||
var blocks = void 0; | ||
if (rest) { | ||
blocks = {}; | ||
var _loop = function _loop(key) { | ||
if (key === '_') return "continue"; | ||
var slot = slots[key]; | ||
if (!blocks) blocks = {}; | ||
var _loop3 = function _loop3(key) { | ||
blocks[key] = function () { | ||
return normalizeChildren(rest[key]); | ||
}; | ||
}; | ||
blocks[key] = function (parent) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
for (var key in rest) { | ||
_loop3(key); | ||
} | ||
} | ||
return { | ||
children: normalizeChildren(d), | ||
_blocks: blocks | ||
// if the content is invalid, use parent instead | ||
// this is the default behavior of Vue | ||
var validSlotContent = ensureValidVNode(slot.apply(void 0, args)); | ||
return validSlotContent ? normalizeChildren(validSlotContent) : parent(); | ||
}; | ||
} | ||
}; | ||
function toVueVNode(h, vNode, props) { | ||
var attrs = {}; | ||
var __props = { attrs: attrs }; | ||
var vNodeProps = vNode.props; | ||
for (var key in vNodeProps) { | ||
if (~['children', '_context', 'className', 'style', 'ref', 'key'].indexOf(key)) continue; | ||
attrs[key] = vNodeProps[key]; | ||
} | ||
if (vNode.ref) { | ||
__props.ref = props.data.ref; | ||
} | ||
if (vNodeProps.className) { | ||
__props.staticClass = vNodeProps.className; | ||
} | ||
if (vNode.props.style) { | ||
__props.staticStyle = vNodeProps.style; | ||
} | ||
if (vNode.key != null) { | ||
__props.key = vNodeProps.key; | ||
} | ||
var children = vNodeProps.children; | ||
if (children && !Array.isArray(children)) { | ||
children = [children]; | ||
} | ||
for (var key in slots) { | ||
var _ret2 = _loop(key); | ||
return h(vNode.tag, __props, children); | ||
if (_ret2 === "continue") continue; | ||
} | ||
if (blocks) { | ||
props._blocks = blocks; | ||
} | ||
} | ||
function functionalWrapper(Component) { | ||
function Ctor(props) { | ||
return Component(props); | ||
} | ||
var EMPTY_OBJ = {}; | ||
Ctor.options = { | ||
functional: true, | ||
render: function render(h, props) { | ||
var _props = normalizeProps({ | ||
// fake | ||
componentOptions: { | ||
Ctor: Component, | ||
listeners: props.listeners | ||
}, | ||
data: props.data, | ||
slots: props.slots(), | ||
context: props.parent | ||
}); | ||
var vNode = Component(_props, true /* is in vue */); | ||
if (isArray(vNode)) { | ||
return vNode.map(function (vNode) { | ||
return toVueVNode(h, vNode, props); | ||
}); | ||
} | ||
return toVueVNode(h, vNode, props); | ||
} | ||
}; | ||
function normalizeEvents(props, key, value) { | ||
var name; | ||
var cb = value; | ||
Ctor.cid = 'IntactFunctionalComponent'; | ||
var _isArray = isArray(value); | ||
return Ctor; | ||
} | ||
var changeCallback = function changeCallback(propName) { | ||
return function (c, v) { | ||
var modifiersKey = "".concat(propName === 'value' ? 'model' : propName, "Modifiers"); | ||
var ignorePropRegExp = /_ev[A-Z]/; | ||
var patch = Vue.prototype.__patch__; | ||
// const update = Vue.prototype._update; | ||
var _ref = props[modifiersKey] || EMPTY_OBJ, | ||
number = _ref.number, | ||
trim = _ref.trim; | ||
var Wrapper = function () { | ||
function Wrapper() { | ||
classCallCheck(this, Wrapper); | ||
} | ||
if (trim) { | ||
v = String(v).trim(); | ||
} else if (number) { | ||
v = Number(v); | ||
} | ||
Wrapper.prototype.init = function init(lastVNode, nextVNode) { | ||
// let the component destroy by itself | ||
this.destroyed = true; | ||
this._addProps(nextVNode); | ||
return patch(null, nextVNode.props.vueVNode, false, false, this.parentDom); | ||
if (_isArray) { | ||
each(value, function (value) { | ||
return value(v); | ||
}); | ||
} else { | ||
value(v); | ||
} | ||
}; | ||
}; | ||
Wrapper.prototype.update = function update(lastVNode, nextVNode) { | ||
this._addProps(nextVNode); | ||
return patch(lastVNode.props.vueVNode, nextVNode.props.vueVNode, false, false, this.parentDom); | ||
}; | ||
if (key.startsWith('onUpdate:')) { | ||
var propName = camelize(key.substr(9)); | ||
if (propName === 'modelValue') propName = 'value'; | ||
name = "$change:".concat(propName); | ||
cb = changeCallback(propName); | ||
} else { | ||
key = key.substring(2); | ||
name = key[0].toLowerCase() + key.substring(1); | ||
} // if there is a $change:prop originally, set it as array | ||
Wrapper.prototype.destroy = function destroy(vNode) { | ||
patch(vNode.props.vueVNode, null); | ||
}; | ||
// maybe the props has been changed, so we change the vueVNode's data | ||
name = "ev-".concat(name); | ||
if (props[name]) { | ||
props[name] = [].concat(props[name], cb); | ||
} else { | ||
props[name] = cb; | ||
} | ||
} | ||
Wrapper.prototype._addProps = function _addProps(vNode) { | ||
// for Intact reusing the dom | ||
this.vdt = { vNode: vNode }; | ||
var props = vNode.props; | ||
var vueVNode = props.vueVNode; | ||
// if we reuse the vNode, clone it | ||
if (vueVNode.elm) { | ||
vueVNode = cloneVNode(vueVNode); | ||
} | ||
for (var key in props) { | ||
if (key === 'vueVNode') continue; | ||
if (ignorePropRegExp.test(key)) continue; | ||
if (!vueVNode.data) vueVNode.data = {}; | ||
var data = vueVNode.data; | ||
var prop = props[key]; | ||
// is event | ||
if (key === 'className') { | ||
data.staticClass = prop; | ||
delete data.class; | ||
} else if (key === 'style') { | ||
if (data.staticStyle) { | ||
data.staticStyle = _extends({}, data.staticStyle, prop); | ||
} else { | ||
data.staticStyle = prop; | ||
} | ||
} else if (key.substr(0, 3) === 'ev-') { | ||
if (!data.on) data.on = {}; | ||
data.on[key.substr(3)] = prop; | ||
} else { | ||
if (!data.attrs) data.attrs = {}; | ||
data.attrs[key] = prop; | ||
} | ||
} | ||
function normalizeDirs(dirs, props) { | ||
if (!dirs) return; | ||
dirs.find(function (_ref2) { | ||
var dir = _ref2.dir, | ||
value = _ref2.value; | ||
vNode.props = _extends({}, props, { vueVNode: vueVNode }); | ||
}; | ||
// only handle v-show | ||
if (dir === vShow) { | ||
if (!value) { | ||
(props.style || (props.style = {})).display = 'none'; | ||
} | ||
return Wrapper; | ||
}(); | ||
function handleRef(vNode, props) { | ||
var key = vNode.data.ref; | ||
if (key) { | ||
var refs = vNode.context.$refs; | ||
props.ref = function (i, isRemove) { | ||
// if we pass the ref to intact component, ignore it directlty | ||
if (!refs) return; | ||
if (!isRemove) { | ||
if (vNode.data.refInFor) { | ||
if (!isArray(refs[key])) { | ||
refs[key] = [i]; | ||
} else if (refs[key].indexOf(i) < 0) { | ||
refs[key].push(i); | ||
} | ||
} else { | ||
refs[key] = i; | ||
} | ||
} else { | ||
if (isArray(refs[key])) { | ||
var index = refs[key].indexOf(i); | ||
if (~index) { | ||
refs[key].splice(index, 1); | ||
} | ||
} else { | ||
refs[key] = undefined; | ||
} | ||
} | ||
}; | ||
props.ref.key = key; | ||
return true; | ||
} | ||
}); | ||
} | ||
function handleClassName(vNode) { | ||
var className = void 0; | ||
var data = vNode.data; | ||
if (data) { | ||
if (data.staticClass) { | ||
className = data.staticClass; | ||
} | ||
if (data.class) { | ||
if (!className) { | ||
className = stringifyClass(data.class); | ||
} else { | ||
className += ' ' + stringifyClass(data.class); | ||
} | ||
} | ||
} | ||
return className; | ||
function normalizeRef(rawRef, props) { | ||
if (isFunction$1(rawRef)) props.ref = rawRef;else if (rawRef) { | ||
props.ref = function (i) { | ||
setRef(rawRef, i); | ||
}; | ||
} | ||
} | ||
function stringifyClass(className) { | ||
if (className == null) return ''; | ||
if (isArray(className)) { | ||
return stringifyArray(className); | ||
} | ||
if ((typeof className === 'undefined' ? 'undefined' : _typeof(className)) === 'object') { | ||
return stringifyObject(className); | ||
} | ||
if (typeof className === 'string') { | ||
return className; | ||
} | ||
var onRE = /^on[^a-z]/; | ||
return ''; | ||
} | ||
var isOn = function isOn(key) { | ||
return onRE.test(key); | ||
}; | ||
function stringifyArray(value) { | ||
var res = ''; | ||
var stringified = void 0; | ||
for (var i = 0; i < value.length; i++) { | ||
if ((stringified = stringifyClass(value[i])) != null && stringified !== '') { | ||
if (res) res += ' '; | ||
res += stringified; | ||
} | ||
function ensureValidVNode(vNodes) { | ||
if (!Array.isArray(vNodes)) vNodes = [vNodes]; | ||
return vNodes.some(function (child) { | ||
if (!isVNode(child)) { | ||
return true; | ||
} | ||
return res; | ||
} | ||
function stringifyObject(value) { | ||
var res = ''; | ||
for (var key in value) { | ||
if (value[key]) { | ||
if (res) res += ' '; | ||
res += key; | ||
} | ||
if (child.type === Comment) { | ||
return false; | ||
} | ||
return res; | ||
} | ||
function handleStyle(vNode) { | ||
var style = void 0; | ||
var data = vNode.data; | ||
if (data) { | ||
style = getStyleBinding(data.style); | ||
if (data.staticStyle) { | ||
return extend$1(data.staticStyle, style); | ||
} | ||
if (child.type === Fragment && !ensureValidVNode(child.children)) { | ||
return false; | ||
} | ||
return style; | ||
return true; | ||
}) ? vNodes : null; | ||
} | ||
function getStyleBinding(style) { | ||
if (!style) return style; | ||
function setRef(rawRef, value) { | ||
if (isArray(rawRef)) { | ||
rawRef.forEach(function (r, i) { | ||
return setRef(r, value); | ||
}); | ||
return; | ||
} | ||
if (isArray(style)) { | ||
return toObject(style); | ||
} | ||
if (typeof style === 'string') { | ||
return parseStyleText(style); | ||
} | ||
var owner = rawRef.i, | ||
ref = rawRef.r; | ||
var refs = !Object.keys(owner.refs).length ? owner.refs = {} : owner.refs; | ||
return style; | ||
if (isString(ref)) { | ||
refs[ref] = value; | ||
} else if (isRef(ref)) { | ||
ref.value = value; | ||
} else if (isFunction$1(ref)) { | ||
ref(value, refs); | ||
} else { | ||
console.warn('Invalid template ref type:', value, "(".concat(_typeof(value), ")")); | ||
} | ||
} | ||
function toObject(arr) { | ||
var res = {}; | ||
for (var i = 0; i < arr.length; i++) { | ||
if (arr[i]) { | ||
extend$1(res, arr[i]); | ||
} | ||
} | ||
var isStringOrNumber = Intact.utils.isStringOrNumber; | ||
function functionalWrapper(Component) { | ||
function Ctor(props, context) { | ||
if (context) { | ||
// invoked by Vue | ||
var forwardRef = props.forwardRef, | ||
rest = _objectWithoutProperties(props, ["forwardRef"]); | ||
return res; | ||
} | ||
var _props = normalizeProps({ | ||
props: rest, | ||
children: context.slots, | ||
type: { | ||
Component: Component | ||
}, | ||
ref: forwardRef | ||
}); | ||
var cache = create(null); | ||
function parseStyleText(cssText) { | ||
var hit = cache[cssText]; | ||
if (hit) return hit; | ||
var vNode = Component(_props, true | ||
/* is in vue */ | ||
); | ||
var res = {}; | ||
var listDelimiter = /;(?![^(]*\))/g; | ||
var propertyDelimiter = /:(.+)/; | ||
cssText.split(listDelimiter).forEach(function (item) { | ||
if (item) { | ||
var tmp = item.split(propertyDelimiter); | ||
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); | ||
} | ||
}); | ||
cache[cssText] = res; | ||
if (Array.isArray(vNode)) { | ||
return vNode.map(function (vNode) { | ||
return toVueVNode(vNode); | ||
}); | ||
} | ||
return res; | ||
} | ||
function isIntactComponent(vNode) { | ||
var i = vNode.data; | ||
return i && (i = i.hook) && (i = i.init) && vNode.componentOptions.Ctor.cid === 'IntactVue'; | ||
} | ||
// copy from vue/src/core/instance/render-helpers/resolve-slots.js | ||
function resolveSlots(children) { | ||
var slots = {}; | ||
if (!children) { | ||
return slots; | ||
return toVueVNode(vNode); | ||
} else { | ||
// invoked by Intact | ||
return Component(props); | ||
} | ||
for (var i = 0, l = children.length; i < l; i++) { | ||
var child = children[i]; | ||
var data = child.data; | ||
// remove slot attribute if the node is resolved as a Vue slot node | ||
if (data && data.attrs && data.attrs.slot) { | ||
delete data.attrs.slot; | ||
} | ||
if (data && data.slot != null) { | ||
var _name2 = data.slot; | ||
var slot = slots[_name2] || (slots[_name2] = []); | ||
if (child.tag === 'template') { | ||
slot.push.apply(slot, child.children || []); | ||
} else { | ||
slot.push(child); | ||
} | ||
} else { | ||
(slots.default || (slots.default = [])).push(child); | ||
} | ||
} | ||
// ignore slots that contains only whitespace | ||
for (var _name3 in slots) { | ||
if (slots[_name3].every(isWhitespace)) { | ||
delete slots[_name3]; | ||
} | ||
} | ||
return slots; | ||
} | ||
} | ||
function isWhitespace(node) { | ||
return node.isComment && !node.asyncFactory || node.text === ' '; | ||
Ctor.cid = cid; | ||
Ctor.displayName = Component.displayName || Component.name; | ||
return Ctor; | ||
} | ||
// copy from vue/src/core/vdom/vnode.js | ||
function cloneVNode(vnode) { | ||
var cloned = new VueVNode(vnode.tag, | ||
// clone data | ||
vnode.data ? _extends({}, vnode.data) : vnode.data, | ||
// #7975 | ||
// clone children array to avoid mutating original in case of cloning | ||
// a child. | ||
vnode.children && vnode.children.slice(), vnode.text, vnode.elm, vnode.context, vnode.componentOptions, vnode.asyncFactory); | ||
cloned.ns = vnode.ns; | ||
cloned.isStatic = vnode.isStatic; | ||
cloned.key = vnode.key; | ||
cloned.isComment = vnode.isComment; | ||
cloned.fnContext = vnode.fnContext; | ||
cloned.fnOptions = vnode.fnOptions; | ||
cloned.fnScopeId = vnode.fnScopeId; | ||
cloned.asyncMeta = vnode.asyncMeta; | ||
cloned.isCloned = true; | ||
return cloned; | ||
} | ||
function toVueVNode(vNode) { | ||
if (isStringOrNumber(vNode)) return vNode; | ||
function cached(fn) { | ||
var cache = Object.create(null); | ||
return function (str) { | ||
var hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}; | ||
if (vNode) { | ||
return h$1(vNode.tag, vNode.props); | ||
} | ||
} | ||
/** | ||
* Camelize a hyphen-delimited string. | ||
*/ | ||
var camelizeRE = /-(\w)/g; | ||
var camelize = cached(function (str) { | ||
return str.replace(camelizeRE, function (_, c) { | ||
return c ? c.toUpperCase() : ''; | ||
}); | ||
}); | ||
var hooks = Intact.Vdt.miss.hooks; | ||
// for webpack alias Intact to IntactVue | ||
var _Vue$prototype = Vue.prototype; | ||
var init = _Vue$prototype.init; | ||
var $nextTick = _Vue$prototype.$nextTick; | ||
var _updateFromParent = _Vue$prototype._updateFromParent; | ||
if (hooks) { | ||
hooks.beforeInsert = function (vNode) { | ||
var dom = vNode.dom; | ||
var parent = vNode.parentVNode; | ||
var i; | ||
var extend = Intact.utils.extend; | ||
while (parent) { | ||
// find Intact Component which renders by Vue | ||
if ((i = parent.tag) && i.cid === cid && (i = parent.children.vueInstance)) { | ||
var vnode = i.$.vnode; | ||
var parentComponent = i.$parent.$; | ||
setScopeId(dom, vnode.scopeId, vnode, parentComponent); | ||
break; | ||
} else { | ||
parent = parent.parentVNode; | ||
} | ||
} | ||
}; | ||
} | ||
var activeInstance = void 0; | ||
var mountedQueue = void 0; | ||
function setScopeId(el, scopeId, vnode, parentComponent) { | ||
if (scopeId) { | ||
hostSetScopeId(el, scopeId); | ||
} | ||
var IntactVue = function (_Intact) { | ||
inherits(IntactVue, _Intact); | ||
if (parentComponent) { | ||
var treeOwnerId = parentComponent.type.__scopeId; // vnode's own scopeId and the current patched component's scopeId is | ||
// different - this is a slot content node. | ||
function IntactVue(options) { | ||
classCallCheck(this, IntactVue); | ||
if (treeOwnerId && treeOwnerId !== scopeId) { | ||
hostSetScopeId(el, treeOwnerId + '-s'); | ||
} | ||
var parentVNode = options && options._parentVnode; | ||
if (parentVNode) { | ||
var vNode = normalize(parentVNode); | ||
var subTree = parentComponent.subTree; | ||
// inject hook | ||
// if exist mountedQueue, it indicate that the component is nested into vue element | ||
// we call __patch__ to render it, and it will lead to call mounted hooks | ||
// but this component has not been appended | ||
// so we do it nextTick | ||
// options.mounted = [ | ||
// activeInstance ? | ||
// () => { | ||
// this.$nextTick(this.mount); | ||
// } : | ||
// this.mount | ||
// ]; | ||
if (vnode === subTree) { | ||
setScopeId(el, parentComponent.vnode.scopeId, parentComponent.vnode, parentComponent.parent); | ||
} | ||
} | ||
} | ||
// force vue update intact component | ||
var _this = possibleConstructorReturn(this, _Intact.call(this, vNode.props)); | ||
function hostSetScopeId(el, scopeId) { | ||
el.setAttribute(scopeId, ''); | ||
} | ||
options._renderChildren = true; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
_this.$options = options; | ||
_this.$vnode = parentVNode; | ||
_this._isVue = true; | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
var activeInstance; | ||
var mountedQueue; | ||
var pendingCount = 0; | ||
// for compitibility of vue@2.6 | ||
_this.$scopedSlots = { $stable: true }; | ||
var IntactVue = /*#__PURE__*/function (_Intact) { | ||
_inherits(IntactVue, _Intact); | ||
_this.vNode = vNode; | ||
vNode.children = _this; | ||
var _super = _createSuper(IntactVue); | ||
// for devtools | ||
var parent = options.parent; | ||
if (parent) { | ||
_this.$parent = parent; | ||
_this.$root = parent.$root; | ||
parent.$children.push(_this); | ||
} | ||
_this.$children = []; | ||
_this._data = _this.props; | ||
_this.$refs = {}; | ||
_this._uid = _this.uniqueId; | ||
options.name = _this.displayName || _this.constructor.name; | ||
} else { | ||
var _this = possibleConstructorReturn(this, _Intact.call(this, options)); | ||
} | ||
return possibleConstructorReturn(_this); | ||
} | ||
function IntactVue() { | ||
_classCallCheck(this, IntactVue); | ||
IntactVue.prototype.init = function init(lastVNode, nextVNode) { | ||
var _this2 = this; | ||
return _super.apply(this, arguments); | ||
} | ||
var init = function init() { | ||
_this2.__pushActiveInstance(); | ||
var element = _Intact.prototype.init.call(_this2, lastVNode, nextVNode); | ||
_this2.__popActiveInstance(); | ||
_createClass(IntactVue, [{ | ||
key: "init", | ||
value: function init(lastVNode, nextVNode) { | ||
pushActiveInstance(this); | ||
return element; | ||
}; | ||
var element = _get(_getPrototypeOf(IntactVue.prototype), "init", this).call(this, lastVNode, nextVNode); | ||
if (!this._isVue) return init(); | ||
popActiveInstance(); | ||
return element; | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(lastVNode, nextVNode, fromPending) { | ||
var _this = this; | ||
mountedQueue = this.mountedQueue; | ||
var update = function update() { | ||
pushActiveInstance(_this); | ||
var element = init(); | ||
var element = _get(_getPrototypeOf(IntactVue.prototype), "update", _this).call(_this, lastVNode, nextVNode, fromPending); | ||
popActiveInstance(); | ||
return element; | ||
}; | ||
}; | ||
IntactVue.prototype.update = function update(lastVNode, nextVNode, fromPending) { | ||
var _this3 = this; | ||
if (!this._isVue) return update(); | ||
var element = update(); // should update vnode.el, becasue Intact may change dom after it updated | ||
var update = function update() { | ||
_this3.__pushActiveInstance(); | ||
var element = _Intact.prototype.update.call(_this3, lastVNode, nextVNode, fromPending); | ||
_this3.__popActiveInstance(); | ||
if (this._hasCalledMountd) { | ||
this._updateVNodeEl(); | ||
} | ||
return element; | ||
}; | ||
return element; | ||
} // we should promise that all intact components have been mounted | ||
if (!this._isVue) return update(); | ||
}, { | ||
key: "__initMountedQueue", | ||
value: function __initMountedQueue() { | ||
if (!this.__updating) { | ||
++pendingCount; | ||
} | ||
// maybe update in updating | ||
var oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
if (!mountedQueue || mountedQueue.done) { | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
var element = update(); | ||
mountedQueue = this.mountedQueue; | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
} | ||
} | ||
}, { | ||
key: "__triggerMountedQueue", | ||
value: function __triggerMountedQueue() { | ||
if (! --pendingCount) { | ||
this._triggerMountedQueue(); | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
mountedQueue = null; | ||
} | ||
} | ||
}, { | ||
key: "_updateVNodeEl", | ||
value: function _updateVNodeEl() { | ||
var element = this.element; | ||
var vueInstance = this.vueInstance.$; | ||
var vnode; | ||
// should update elm of vnode of Vue to let Vue hanlde dom correctly | ||
this.$vnode.elm = element; | ||
do { | ||
vnode = vueInstance.vnode; | ||
vueInstance.subTree.el = vnode.el = element; | ||
vueInstance = vueInstance.parent; | ||
} while (vueInstance && vueInstance.subTree === vnode); | ||
} | ||
}], [{ | ||
key: "__vccOpts", | ||
get: function get() { | ||
var Component = this; | ||
return element; | ||
}; | ||
if (Component.hasOwnProperty('__cache')) { | ||
return Component.__cache; | ||
} | ||
IntactVue.prototype.$mount = function $mount(el, hydrating) { | ||
var _this4 = this; | ||
var oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
this.parentVNode = this.vNode.parentVNode = activeInstance && activeInstance.vNode; | ||
// disable intact async component | ||
this.inited = true; | ||
this.$el = this.init(null, this.vNode); | ||
this.vNode.dom = this.$el; | ||
this._vnode = {}; | ||
var options = this.$options; | ||
var refElm = options._refElm; | ||
var parentElm = options._parentElm; | ||
// vue@2.5.18 and above does not need append the dom | ||
// vue will do this by itself | ||
if (parentElm) { | ||
if (refElm) { | ||
parentElm.insertBefore(this.$el, refElm); | ||
} else { | ||
parentElm.appendChild(this.$el); | ||
return Component.__cache = { | ||
// for debug | ||
name: Component.displayName || Component.name, | ||
Component: Component, | ||
setup: function setup(props, ctx) { | ||
var setupState = { | ||
instance: null | ||
}; | ||
var proxy = new Proxy(setupState, { | ||
get: function get(_ref, key) { | ||
var instance = _ref.instance; | ||
if (key === '__v_isReactive') return true; | ||
if (!instance) return null; | ||
if (key === 'instance') return instance; | ||
return instance[key]; | ||
}, | ||
set: function set(setupState, key, value) { | ||
if (key === 'instance') return Reflect.set(setupState, key, value); | ||
return Reflect.set(setupState.instance, key, value); | ||
}, | ||
getOwnPropertyDescriptor: function getOwnPropertyDescriptor() { | ||
return { | ||
value: undefined, | ||
writable: true, | ||
enumerable: true, | ||
configurable: true | ||
}; | ||
}, | ||
ownKeys: function ownKeys() { | ||
return []; | ||
} | ||
} | ||
}); | ||
return proxy; | ||
}, | ||
render: function render(proxyToUse, renderCache, props, setupState, data, ctx) { | ||
var vueInstance = proxyToUse.$; | ||
var vNode = normalize(vueInstance.vnode); | ||
var instance = setupState.instance; | ||
var isInit = false; | ||
this.$el.__vue__ = this; | ||
if (!instance) { | ||
isInit = true; | ||
instance = setupState.instance = new Component(vNode.props); | ||
instance._isVue = true; | ||
} | ||
this.mountedQueue.push(function () { | ||
_this4.mount(); | ||
}); | ||
vNode.children = instance; | ||
instance.vueInstance = proxyToUse; | ||
instance.parentVNode = vNode.parentVNode = activeInstance && activeInstance.vNode; | ||
var lastVNode = instance.vNode; | ||
instance.vNode = vNode; | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
}; | ||
instance.__initMountedQueue(); | ||
IntactVue.prototype.$forceUpdate = function $forceUpdate() { | ||
var oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
if (isInit) { | ||
// disable intact async component | ||
instance.inited = true; | ||
vNode.dom = instance.init(null, vNode); | ||
instance.mountedQueue.push(function () { | ||
instance.mount(); | ||
}); | ||
} else { | ||
instance.__updating = true; | ||
vNode.dom = instance.update(lastVNode, vNode); | ||
} | ||
var vNode = normalize(this.$vnode); | ||
var lastVNode = this.vNode; | ||
vNode.children = this; | ||
return createVNode(Comment, null, 'intact-vue-placeholer'); | ||
}, | ||
mounted: function mounted() { | ||
var el = this.$el; | ||
var dom = this.element; | ||
el.parentNode.replaceChild(dom, el); // update vnode.el | ||
this.vNode = vNode; | ||
this.parentVNode = this.vNode.parentVNode = activeInstance && activeInstance.vNode; | ||
// Intact can change element when update, so we should re-assign it to elm, #4 | ||
this.$vnode.elm = this.update(lastVNode, vNode); | ||
this._updateVNodeEl(); // If we trigger a update in a update lifecyle, | ||
// the order of hooks is beforeMount -> beforeUpdate -> mountd -> updated, | ||
// in this case, we should not updateVNodeEl in beforeUpdated, | ||
// so we add a flag to skip it | ||
// force vue update intact component | ||
// reset it, because vue may set it to undefined | ||
this.$options._renderChildren = true; | ||
// let the vNode patchable for vue to register ref | ||
// this._vnode = this.vdt.vNode; | ||
// don't let vue to register ref, it will change className and so on | ||
// handle it there | ||
var lastRef = lastVNode.ref; | ||
var nextRef = vNode.ref; | ||
if (lastRef !== nextRef && | ||
// if the string of the key is the same, do nothing | ||
!(lastRef && nextRef && lastRef.key === nextRef.key)) { | ||
if (lastRef) { | ||
lastRef(this, true); | ||
} | ||
if (nextRef) { | ||
nextRef(this); | ||
} | ||
} | ||
this._hasCalledMountd = true; | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
}; | ||
this.__triggerMountedQueue(); | ||
}, | ||
updated: function updated() { | ||
this.__updating = false; | ||
IntactVue.prototype.$destroy = function $destroy() { | ||
delete this.$el.__vue__; | ||
var parent = this.$parent; | ||
if (parent) { | ||
var children = parent.$children; | ||
if (children.length) { | ||
var index = children.indexOf(this); | ||
if (~index) { | ||
children.splice(index, 1); | ||
} | ||
} | ||
this.__triggerMountedQueue(); | ||
}, | ||
beforeUnmount: function beforeUnmount() { | ||
this.destroy(); | ||
} | ||
this.destroy(); | ||
}; | ||
}; | ||
} | ||
}]); | ||
// we should promise that all intact components have been mounted | ||
return IntactVue; | ||
}(Intact); | ||
_defineProperty(IntactVue, "functionalWrapper", functionalWrapper); | ||
IntactVue.prototype.__initMountedQueue = function __initMountedQueue() { | ||
this._shouldTrigger = false; | ||
if (!mountedQueue || mountedQueue.done) { | ||
this._shouldTrigger = true; | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
mountedQueue = this.mountedQueue; | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
} | ||
}; | ||
_defineProperty(IntactVue, "normalize", normalizeChildren); | ||
IntactVue.prototype.__triggerMountedQueue = function __triggerMountedQueue() { | ||
if (this._shouldTrigger) { | ||
if (this.mounted) { | ||
this._triggerMountedQueue(); | ||
} else { | ||
// vue will call mouted hook after append the element | ||
// so we push to the queue to make it to be called immediately | ||
this.$options.mounted = [this._triggerMountedQueue]; | ||
// this.$nextTick(() => { | ||
// if (this.destroyed) return; | ||
// this._triggerMountedQueue(); | ||
// }); | ||
} | ||
mountedQueue = null; | ||
this._shouldTrigger = false; | ||
} | ||
}; | ||
_defineProperty(IntactVue, "cid", cid); | ||
var stack = []; | ||
var index = -1; | ||
IntactVue.prototype.__pushActiveInstance = function __pushActiveInstance() { | ||
this._prevActiveInstance = activeInstance; | ||
activeInstance = this; | ||
}; | ||
function pushActiveInstance(instance) { | ||
stack.push(instance); | ||
index++; | ||
activeInstance = instance; | ||
} | ||
IntactVue.prototype.__popActiveInstance = function __popActiveInstance() { | ||
activeInstance = this._prevActiveInstance; | ||
this._prevActiveInstance = null; | ||
}; | ||
// mock api | ||
IntactVue.prototype.$on = function $on() {}; | ||
IntactVue.prototype.$off = function $off() {}; | ||
// for vue-devtools | ||
IntactVue.prototype.$set = function $set(obj, key, value) { | ||
this.set(key, value); | ||
}; | ||
return IntactVue; | ||
}(Intact); | ||
IntactVue.cid = 'IntactVue'; | ||
IntactVue.options = extend({}, Vue.options); | ||
IntactVue.functionalWrapper = functionalWrapper; | ||
IntactVue.normalize = normalizeChildren; | ||
IntactVue.prototype.$nextTick = $nextTick; | ||
// for vue@2.1.8 | ||
IntactVue.prototype._updateFromParent = _updateFromParent; | ||
// for compatibilty of IE <= 10 | ||
if (!Object.setPrototypeOf) { | ||
extend(IntactVue, Intact); | ||
// for Intact <= 2.4.4 | ||
if (!IntactVue.template) { | ||
IntactVue.template = Intact.template; | ||
} | ||
function popActiveInstance() { | ||
stack.pop(); | ||
index--; | ||
activeInstance = stack[index]; | ||
} | ||
module.exports = IntactVue; | ||
export default IntactVue; |
{ | ||
"name": "intact-vue", | ||
"version": "0.5.11", | ||
"version": "1.0.0", | ||
"description": "A compatibility layer for running intact component in vue", | ||
@@ -8,3 +8,3 @@ "main": "dist/index.js", | ||
"test": "karma start karma.config.js", | ||
"build": "rollup -c rollup.config.node.js && rollup -c rollup.config.js && uglifyjs dist/intact.vue.js -o dist/intact.vue.min.js -m", | ||
"build": "rollup -c rollup.config.js", | ||
"release": "npm run release-patch", | ||
@@ -32,36 +32,41 @@ "prelease": "npm version prerelease && git push --tags --force && git push && npm publish", | ||
"peerDependencies": { | ||
"vue": "^2.5.9", | ||
"vue": "^3.0.0", | ||
"intact": "^2.5.4" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"@babel/core": "^7.12.10", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-proposal-decorators": "^7.12.12", | ||
"@babel/plugin-transform-runtime": "^7.12.10", | ||
"@babel/polyfill": "^7.12.1", | ||
"@babel/preset-env": "^7.12.11", | ||
"@rollup/plugin-babel": "^5.2.2", | ||
"@vue/compiler-sfc": "^3.0.5", | ||
"babel-loader": "^8.2.2", | ||
"chai": "^4.1.2", | ||
"css-loader": "^0.28.7", | ||
"html-webpack-plugin": "^3.2.0", | ||
"intact": "^2.5.4", | ||
"karma": "^4.0.1", | ||
"intact": "^2.5.15", | ||
"karma": "^5.2.3", | ||
"karma-mocha": "^1.3.0", | ||
"karma-sinon-chai": "^1.3.3", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^3.0.5", | ||
"karma-webpack": "^4.0.2", | ||
"mocha": "^4.0.1", | ||
"rollup": "^0.52.1", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
"rollup": "^2.36.1", | ||
"sinon": "^4.1.3", | ||
"sinon-chai": "^2.14.0", | ||
"style-loader": "^2.0.0", | ||
"vdt": "^1.3.1", | ||
"vdt-loader": "^1.3.1", | ||
"vue": "^2.6.6", | ||
"vue-loader": "^14.2.4", | ||
"vue": "^3.0.5", | ||
"vue-loader": "^16.1.2", | ||
"vue-router": "^4.0.3", | ||
"vue-style-loader": "^3.0.3", | ||
"vue-template-compiler": "^2.6.6", | ||
"webpack": "^4.29.6", | ||
"webpack": "^4.44.2", | ||
"webpack-dev-server": "^3.2.1" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.5" | ||
} | ||
} |
271
src/index.js
@@ -1,270 +0,3 @@ | ||
import Vue from 'vue'; | ||
// for webpack alias Intact to IntactVue | ||
import Intact from 'intact/dist'; | ||
import { | ||
normalizeChildren, | ||
normalize, | ||
getChildrenAndBlocks, | ||
functionalWrapper | ||
} from './utils'; | ||
import IntactVue from './IntactVue'; | ||
const {init, $nextTick, _updateFromParent} = Vue.prototype; | ||
const extend = Intact.utils.extend; | ||
let activeInstance; | ||
let mountedQueue; | ||
export default class IntactVue extends Intact { | ||
static cid = 'IntactVue'; | ||
static options = extend({}, Vue.options); | ||
static functionalWrapper = functionalWrapper; | ||
static normalize = normalizeChildren; | ||
constructor(options) { | ||
const parentVNode = options && options._parentVnode; | ||
if (parentVNode) { | ||
const vNode = normalize(parentVNode); | ||
super(vNode.props); | ||
// inject hook | ||
// if exist mountedQueue, it indicate that the component is nested into vue element | ||
// we call __patch__ to render it, and it will lead to call mounted hooks | ||
// but this component has not been appended | ||
// so we do it nextTick | ||
// options.mounted = [ | ||
// activeInstance ? | ||
// () => { | ||
// this.$nextTick(this.mount); | ||
// } : | ||
// this.mount | ||
// ]; | ||
// force vue update intact component | ||
options._renderChildren = true; | ||
this.$options = options; | ||
this.$vnode = parentVNode; | ||
this._isVue = true; | ||
// for compitibility of vue@2.6 | ||
this.$scopedSlots = {$stable: true}; | ||
this.vNode = vNode; | ||
vNode.children = this; | ||
// for devtools | ||
const parent = options.parent; | ||
if (parent) { | ||
this.$parent = parent; | ||
this.$root = parent.$root; | ||
parent.$children.push(this); | ||
} | ||
this.$children = []; | ||
this._data = this.props; | ||
this.$refs = {}; | ||
this._uid = this.uniqueId; | ||
options.name = this.displayName || this.constructor.name; | ||
} else { | ||
super(options); | ||
} | ||
} | ||
init(lastVNode, nextVNode) { | ||
const init = () => { | ||
this.__pushActiveInstance(); | ||
var element = super.init(lastVNode, nextVNode); | ||
this.__popActiveInstance(); | ||
return element; | ||
}; | ||
if (!this._isVue) return init(); | ||
mountedQueue = this.mountedQueue; | ||
const element = init(); | ||
return element; | ||
} | ||
update(lastVNode, nextVNode, fromPending) { | ||
const update = () => { | ||
this.__pushActiveInstance(); | ||
const element = super.update(lastVNode, nextVNode, fromPending); | ||
this.__popActiveInstance(); | ||
return element; | ||
}; | ||
if (!this._isVue) return update(); | ||
// maybe update in updating | ||
const oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
const element = update(); | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
// should update elm of vnode of Vue to let Vue hanlde dom correctly | ||
this.$vnode.elm = element; | ||
return element; | ||
} | ||
$mount(el, hydrating) { | ||
const oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
this.parentVNode = this.vNode.parentVNode = activeInstance && activeInstance.vNode; | ||
// disable intact async component | ||
this.inited = true; | ||
this.$el = this.init(null, this.vNode); | ||
this.vNode.dom = this.$el; | ||
this._vnode = {}; | ||
const options = this.$options; | ||
const refElm = options._refElm; | ||
const parentElm = options._parentElm; | ||
// vue@2.5.18 and above does not need append the dom | ||
// vue will do this by itself | ||
if (parentElm) { | ||
if (refElm) { | ||
parentElm.insertBefore(this.$el, refElm); | ||
} else { | ||
parentElm.appendChild(this.$el); | ||
} | ||
} | ||
this.$el.__vue__ = this; | ||
this.mountedQueue.push(() => { | ||
this.mount(); | ||
}); | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
} | ||
$forceUpdate() { | ||
const oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
const vNode = normalize(this.$vnode); | ||
const lastVNode = this.vNode; | ||
vNode.children = this; | ||
this.vNode = vNode; | ||
this.parentVNode = this.vNode.parentVNode = activeInstance && activeInstance.vNode; | ||
// Intact can change element when update, so we should re-assign it to elm, #4 | ||
this.$vnode.elm = this.update(lastVNode, vNode); | ||
// force vue update intact component | ||
// reset it, because vue may set it to undefined | ||
this.$options._renderChildren = true; | ||
// let the vNode patchable for vue to register ref | ||
// this._vnode = this.vdt.vNode; | ||
// don't let vue to register ref, it will change className and so on | ||
// handle it there | ||
const lastRef = lastVNode.ref; | ||
const nextRef = vNode.ref; | ||
if (lastRef !== nextRef && | ||
// if the string of the key is the same, do nothing | ||
!(lastRef && nextRef && lastRef.key === nextRef.key) | ||
) { | ||
if (lastRef) { | ||
lastRef(this, true); | ||
} | ||
if (nextRef) { | ||
nextRef(this); | ||
} | ||
} | ||
this.__triggerMountedQueue(); | ||
this._shouldTrigger = oldTriggerFlag; | ||
} | ||
$destroy() { | ||
delete this.$el.__vue__; | ||
const parent = this.$parent; | ||
if (parent) { | ||
const children = parent.$children; | ||
if (children.length) { | ||
const index = children.indexOf(this); | ||
if (~index) { | ||
children.splice(index, 1); | ||
} | ||
} | ||
} | ||
this.destroy(); | ||
} | ||
// we should promise that all intact components have been mounted | ||
__initMountedQueue() { | ||
this._shouldTrigger = false; | ||
if (!mountedQueue || mountedQueue.done) { | ||
this._shouldTrigger = true; | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
mountedQueue = this.mountedQueue; | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
} | ||
} | ||
__triggerMountedQueue() { | ||
if (this._shouldTrigger) { | ||
if (this.mounted) { | ||
this._triggerMountedQueue(); | ||
} else { | ||
// vue will call mouted hook after append the element | ||
// so we push to the queue to make it to be called immediately | ||
this.$options.mounted = [ | ||
this._triggerMountedQueue | ||
]; | ||
// this.$nextTick(() => { | ||
// if (this.destroyed) return; | ||
// this._triggerMountedQueue(); | ||
// }); | ||
} | ||
mountedQueue = null; | ||
this._shouldTrigger = false; | ||
} | ||
} | ||
__pushActiveInstance() { | ||
this._prevActiveInstance = activeInstance; | ||
activeInstance = this; | ||
} | ||
__popActiveInstance() { | ||
activeInstance = this._prevActiveInstance; | ||
this._prevActiveInstance = null; | ||
} | ||
// mock api | ||
$on() {} | ||
$off() {} | ||
// for vue-devtools | ||
$set(obj, key, value) { | ||
this.set(key, value); | ||
} | ||
} | ||
IntactVue.prototype.$nextTick = $nextTick; | ||
// for vue@2.1.8 | ||
IntactVue.prototype._updateFromParent = _updateFromParent; | ||
// for compatibilty of IE <= 10 | ||
if (!Object.setPrototypeOf) { | ||
extend(IntactVue, Intact); | ||
// for Intact <= 2.4.4 | ||
if (!IntactVue.template) { | ||
IntactVue.template = Intact.template; | ||
} | ||
} | ||
export default IntactVue; |
672
src/utils.js
@@ -1,666 +0,16 @@ | ||
import Intact from 'intact/dist'; | ||
import Vue from 'vue'; | ||
const {h, hooks, config} = Intact.Vdt.miss; | ||
const {get, set, extend, isArray, create, hasOwn, each} = Intact.utils; | ||
const _textVNode = Vue.prototype._v(''); | ||
const VueVNode = _textVNode.constructor; | ||
const _testData = {}; | ||
const _vm = new Vue({data: _testData}); | ||
const __ob__ = _testData.__ob__; | ||
// for scoped style | ||
if (hooks) { | ||
hooks.beforeInsert = function(vNode) { | ||
const dom = vNode.dom; | ||
let parent = vNode.parentVNode; | ||
let i; | ||
let j; | ||
while (parent) { | ||
if ( | ||
(i = parent.tag) && | ||
(i.cid === 'IntactVue') && | ||
(i = parent.children.$options) | ||
) { | ||
if ( | ||
(i = j = i.parent) && | ||
(i = i.$options) && | ||
(i = i._scopeId) | ||
) { | ||
dom.setAttribute(i, ''); | ||
} | ||
if (j) { | ||
// find vue component parent while we has found the intact component | ||
parent = j.$parent; | ||
while (parent) { | ||
if ((i = parent.$options) && (i = i._scopeId)) { | ||
dom.setAttribute(i, ''); | ||
} | ||
parent = parent.$parent; | ||
} | ||
} | ||
break; | ||
} else { | ||
parent = parent.parentVNode; | ||
} | ||
} | ||
}; | ||
export function isIntactComponent(vNode) { | ||
// don't convert Intact functional component to Intact vNode, | ||
// because it's propTypes are missing | ||
return !!vNode.type.Component; // || vNode.type.cid === cid; | ||
} | ||
// disable delegate events | ||
if (config) { | ||
config.disableDelegate = true; | ||
} | ||
export const cid = 'IntactVueNext'; | ||
// for get $parent | ||
Vue.mixin({ | ||
beforeCreate() { | ||
if (!this.$parent && this.$vnode) { | ||
this.$parent = this.$vnode.context; | ||
} | ||
} | ||
}); | ||
export function normalizeChildren(vNodes) { | ||
const loop = (vNodes) => { | ||
if (isArray(vNodes)) { | ||
const ret = []; | ||
vNodes.forEach(vNode => { | ||
if (isArray(vNode)) { | ||
ret.push(...loop(vNode)); | ||
} else { | ||
ret.push(normalize(vNode)); | ||
} | ||
}); | ||
return ret; | ||
} | ||
return normalize(vNodes); | ||
} | ||
const ret = loop(vNodes); | ||
if (Array.isArray(ret)) { | ||
const l = ret.length; | ||
return l === 0 ? undefined : l === 1 ? ret[0] : ret; | ||
} | ||
return ret; | ||
const warn = console.warn; | ||
export const noop = () => {}; | ||
export function silentWarn() { | ||
console.warn = noop; | ||
} | ||
export function normalize(vNode) { | ||
if (vNode == null) return vNode; | ||
const type = typeof vNode; | ||
if (type === 'string' || type === 'number') return vNode; | ||
// is a intact vnode | ||
if (vNode.type) return vNode; | ||
if (vNode.text !== undefined) { | ||
return vNode.text; | ||
} | ||
if (isIntactComponent(vNode)) { | ||
const options = vNode.componentOptions; | ||
vNode = h( | ||
options.Ctor, | ||
normalizeProps(vNode), | ||
null, | ||
null, | ||
vNode.key, | ||
vNode.ref | ||
); | ||
} else { | ||
vNode = h(Wrapper, {vueVNode: vNode}, null, handleClassName(vNode), vNode.key); | ||
} | ||
// let vue don't observe it when it is used as property, ksc-fe/kpc#500 | ||
// we can not use `vNode._isVue = true`, because it will affect vue-devtools. ksc-fe/kpc#512 | ||
vNode.__ob__ = __ob__; | ||
return vNode; | ||
export function resetWarn() { | ||
console.warn = warn; | ||
} | ||
export function normalizeProps(vNode) { | ||
const componentOptions = vNode.componentOptions; | ||
const data = vNode.data; | ||
const attrs = data.attrs; | ||
const propTypes = componentOptions.Ctor.propTypes; | ||
const props = {}; | ||
if (attrs) { | ||
for (let key in attrs) { | ||
if (~['staticClass', 'class', 'style', 'staticStyle'].indexOf(key)) continue; | ||
let value = attrs[key]; | ||
if (propTypes) { | ||
let camelizedKey = camelize(key); | ||
if (hasOwn.call(propTypes, camelizedKey)) { | ||
key = camelizedKey; | ||
let tmp; | ||
if ( | ||
( | ||
// value is Boolean | ||
(tmp = propTypes[key]) === Boolean || | ||
tmp && ( | ||
// value contains Boolean | ||
isArray(tmp) && tmp.indexOf(Boolean) > -1 || | ||
// value.type is Boolean | ||
tmp.type === Boolean || | ||
// value.type contains Boolean | ||
isArray(tmp.type) && tmp.type.indexOf(Boolean) > -1 | ||
) | ||
) && | ||
(value === '' || value === key) | ||
) { | ||
value = true; | ||
} | ||
} | ||
} | ||
props[key] = value; | ||
} | ||
} | ||
// add className | ||
const className = handleClassName(vNode); | ||
if (className !== undefined) { | ||
props.className = className; | ||
} | ||
// add style | ||
const style = handleStyle(vNode); | ||
if (style !== undefined) { | ||
props.style = style; | ||
} | ||
// add key | ||
if (vNode.key) { | ||
props.key = vNode.key; | ||
} else if (data.key) { | ||
props.key = data.key; | ||
} | ||
// if exists scoped slots | ||
const scopedSlots = data.scopedSlots; | ||
if (scopedSlots) { | ||
const blocks = props._blocks ? props._blocks : (props._blocks = {}); | ||
for (const key in scopedSlots) { | ||
blocks[key] = function(parent, ...args) { | ||
return normalizeChildren(scopedSlots[key].apply(this, args)); | ||
}; | ||
} | ||
} | ||
// if exists v-model | ||
const model = data.model; | ||
if (model) { | ||
props.value = model.value; | ||
props['v-model'] = model.expression; | ||
} | ||
if (data.directives) { | ||
const directives = data.directives; | ||
for (let i = 0; i < directives.length; i++) { | ||
const model = directives[i]; | ||
if (model.name === 'model') { | ||
// for vue@2.1.8 | ||
props.value = model.value; | ||
props['v-model'] = model.expression; | ||
break; | ||
} else if (model.name === 'show' && !model.value) { | ||
if (props.style) { | ||
props.style.display = 'none'; | ||
} else { | ||
props.style = {display: 'none'} | ||
} | ||
} | ||
} | ||
} | ||
// convert ref string to function | ||
handleRef(vNode, props); | ||
const listeners = componentOptions.listeners; | ||
if (listeners) { | ||
for (let key in listeners) { | ||
let _cb = listeners[key]; | ||
let cb = _cb; | ||
const _isArray = isArray(_cb); | ||
const callCb = (c, v) => { | ||
if (_isArray) { | ||
each(_cb, cb => cb(v)); | ||
} else { | ||
_cb(v); | ||
} | ||
}; | ||
if (key === 'input') { | ||
// is a v-model directive of vue | ||
key = `$change:value`; | ||
cb = callCb; | ||
} else if (key.substr(0, 7) === 'update:') { | ||
// delegate update:prop(sync modifier) to $change:prop | ||
// propName has been camelized by Vue, don't do this again | ||
// key = `$change:${camelize(key.substr(7))}`; | ||
const name = key.substr(7); | ||
if (name.indexOf('-') > -1) continue; | ||
key = `$change:${name}`; | ||
cb = callCb; | ||
} | ||
// if there is a $change:prop originally, set it as array | ||
const name = `ev-${camelize(key)}`; | ||
if (props[name]) { | ||
props[name] = [].concat(props[name], cb); | ||
} else { | ||
props[name] = cb; | ||
} | ||
} | ||
} | ||
// handle children and blocks | ||
const slots = vNode.slots || resolveSlots(componentOptions.children); | ||
const {children, _blocks} = getChildrenAndBlocks(slots); | ||
// for Intact Functional component, the blocks has been handled | ||
// In this case, we should merge them | ||
// maybe children has been set as property | ||
if (!hasOwn.call(props, 'children')) { | ||
props.children = children; | ||
} | ||
if (props._blocks) { | ||
extend(props._blocks, _blocks); | ||
} else { | ||
props._blocks = _blocks; | ||
} | ||
normalizeContext(vNode, props); | ||
return props; | ||
} | ||
function normalizeContext(vNode, props) { | ||
const context = vNode.context; | ||
props._context = { | ||
data: { | ||
get(name) { | ||
if (name != null) { | ||
// for get both props and data | ||
return get(context, name); | ||
} else { | ||
return context.$data; | ||
} | ||
}, | ||
set(name, value) { | ||
set(context, name, value); | ||
}, | ||
$router: get(context, '_routerRoot._router'), | ||
} | ||
}; | ||
} | ||
export function getChildrenAndBlocks(slots) { | ||
const {default: d, ...rest} = slots; | ||
let blocks; | ||
if (rest) { | ||
blocks = {}; | ||
for (const key in rest) { | ||
blocks[key] = function() { | ||
return normalizeChildren(rest[key]); | ||
} | ||
} | ||
} | ||
return { | ||
children: normalizeChildren(d), | ||
_blocks: blocks, | ||
}; | ||
} | ||
function toVueVNode(h, vNode, props) { | ||
const attrs = {}; | ||
const __props = {attrs}; | ||
const vNodeProps = vNode.props; | ||
for (const key in vNodeProps) { | ||
if (~['children', '_context', 'className', 'style', 'ref', 'key'].indexOf(key)) continue; | ||
attrs[key] = vNodeProps[key]; | ||
} | ||
if (vNode.ref) { | ||
__props.ref = props.data.ref; | ||
} | ||
if (vNodeProps.className) { | ||
__props.staticClass = vNodeProps.className; | ||
} | ||
if (vNode.props.style) { | ||
__props.staticStyle = vNodeProps.style; | ||
} | ||
if (vNode.key != null) { | ||
__props.key = vNodeProps.key; | ||
} | ||
let children = vNodeProps.children; | ||
if (children && !Array.isArray(children)) { | ||
children = [children]; | ||
} | ||
return h( | ||
vNode.tag, | ||
__props, | ||
children | ||
); | ||
} | ||
export function functionalWrapper(Component) { | ||
function Ctor(props) { | ||
return Component(props); | ||
} | ||
Ctor.options = { | ||
functional: true, | ||
render(h, props) { | ||
const _props = normalizeProps({ | ||
// fake | ||
componentOptions: { | ||
Ctor: Component, | ||
listeners: props.listeners, | ||
}, | ||
data: props.data, | ||
slots: props.slots(), | ||
context: props.parent, | ||
}); | ||
const vNode = Component(_props, true /* is in vue */); | ||
if (isArray(vNode)) { | ||
return vNode.map(vNode => toVueVNode(h, vNode, props)); | ||
} | ||
return toVueVNode(h, vNode, props); | ||
} | ||
} | ||
Ctor.cid = 'IntactFunctionalComponent'; | ||
return Ctor; | ||
} | ||
const ignorePropRegExp = /_ev[A-Z]/; | ||
const patch = Vue.prototype.__patch__; | ||
// const update = Vue.prototype._update; | ||
class Wrapper { | ||
init(lastVNode, nextVNode) { | ||
// let the component destroy by itself | ||
this.destroyed = true; | ||
this._addProps(nextVNode); | ||
return patch(null, nextVNode.props.vueVNode, false, false, this.parentDom); | ||
} | ||
update(lastVNode, nextVNode) { | ||
this._addProps(nextVNode); | ||
return patch(lastVNode.props.vueVNode, nextVNode.props.vueVNode, false, false, this.parentDom); | ||
} | ||
destroy(vNode) { | ||
patch(vNode.props.vueVNode, null); | ||
} | ||
// maybe the props has been changed, so we change the vueVNode's data | ||
_addProps(vNode) { | ||
// for Intact reusing the dom | ||
this.vdt = {vNode}; | ||
const props = vNode.props; | ||
let vueVNode = props.vueVNode; | ||
// if we reuse the vNode, clone it | ||
if (vueVNode.elm) { | ||
vueVNode = cloneVNode(vueVNode); | ||
} | ||
for (let key in props) { | ||
if (key === 'vueVNode') continue; | ||
if (ignorePropRegExp.test(key)) continue; | ||
if (!vueVNode.data) vueVNode.data = {}; | ||
const data = vueVNode.data; | ||
const prop = props[key]; | ||
// is event | ||
if (key === 'className') { | ||
data.staticClass = prop; | ||
delete data.class; | ||
} else if (key === 'style') { | ||
if (data.staticStyle) { | ||
data.staticStyle = {...data.staticStyle, ...prop}; | ||
} else { | ||
data.staticStyle = prop; | ||
} | ||
} else if (key.substr(0, 3) === 'ev-') { | ||
if (!data.on) data.on = {}; | ||
data.on[key.substr(3)] = prop; | ||
} else { | ||
if (!data.attrs) data.attrs = {}; | ||
data.attrs[key] = prop; | ||
} | ||
} | ||
vNode.props = {...props, vueVNode}; | ||
} | ||
} | ||
function handleRef(vNode, props) { | ||
const key = vNode.data.ref; | ||
if (key) { | ||
const refs = vNode.context.$refs; | ||
props.ref = function(i, isRemove) { | ||
// if we pass the ref to intact component, ignore it directlty | ||
if (!refs) return; | ||
if (!isRemove) { | ||
if (vNode.data.refInFor) { | ||
if (!isArray(refs[key])) { | ||
refs[key] = [i]; | ||
} else if (refs[key].indexOf(i) < 0) { | ||
refs[key].push(i); | ||
} | ||
} else { | ||
refs[key] = i; | ||
} | ||
} else { | ||
if (isArray(refs[key])) { | ||
var index = refs[key].indexOf(i); | ||
if (~index) { | ||
refs[key].splice(index, 1); | ||
} | ||
} else { | ||
refs[key] = undefined; | ||
} | ||
} | ||
}; | ||
props.ref.key = key; | ||
} | ||
} | ||
function handleClassName(vNode) { | ||
let className; | ||
let data = vNode.data; | ||
if (data) { | ||
if (data.staticClass) { | ||
className = data.staticClass; | ||
} | ||
if (data.class) { | ||
if (!className) { | ||
className = stringifyClass(data.class); | ||
} else { | ||
className += ' ' + stringifyClass(data.class); | ||
} | ||
} | ||
} | ||
return className; | ||
} | ||
function stringifyClass(className) { | ||
if (className == null) return ''; | ||
if (isArray(className)) { | ||
return stringifyArray(className); | ||
} | ||
if (typeof className === 'object') { | ||
return stringifyObject(className); | ||
} | ||
if (typeof className === 'string') { | ||
return className; | ||
} | ||
return ''; | ||
} | ||
function stringifyArray(value) { | ||
let res = ''; | ||
let stringified; | ||
for (let i = 0; i < value.length; i++) { | ||
if ((stringified = stringifyClass(value[i])) != null && stringified !== '') { | ||
if (res) res += ' '; | ||
res += stringified; | ||
} | ||
} | ||
return res; | ||
} | ||
function stringifyObject(value) { | ||
let res = ''; | ||
for (let key in value) { | ||
if (value[key]) { | ||
if (res) res += ' '; | ||
res += key; | ||
} | ||
} | ||
return res; | ||
} | ||
function handleStyle(vNode) { | ||
let style; | ||
let data = vNode.data; | ||
if (data) { | ||
style = getStyleBinding(data.style); | ||
if (data.staticStyle) { | ||
return extend(data.staticStyle, style); | ||
} | ||
} | ||
return style; | ||
} | ||
function getStyleBinding(style) { | ||
if (!style) return style; | ||
if (isArray(style)) { | ||
return toObject(style); | ||
} | ||
if (typeof style === 'string') { | ||
return parseStyleText(style); | ||
} | ||
return style; | ||
} | ||
function toObject(arr) { | ||
const res = {}; | ||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i]) { | ||
extend(res, arr[i]); | ||
} | ||
} | ||
return res; | ||
} | ||
const cache = create(null); | ||
function parseStyleText(cssText) { | ||
const hit = cache[cssText]; | ||
if (hit) return hit; | ||
const res = {}; | ||
const listDelimiter = /;(?![^(]*\))/g; | ||
const propertyDelimiter = /:(.+)/; | ||
cssText.split(listDelimiter).forEach(function (item) { | ||
if (item) { | ||
var tmp = item.split(propertyDelimiter); | ||
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); | ||
} | ||
}); | ||
cache[cssText] = res; | ||
return res; | ||
} | ||
function isIntactComponent(vNode) { | ||
let i = vNode.data; | ||
return i && (i = i.hook) && (i = i.init) && | ||
vNode.componentOptions.Ctor.cid === 'IntactVue'; | ||
} | ||
// copy from vue/src/core/instance/render-helpers/resolve-slots.js | ||
function resolveSlots(children) { | ||
const slots = {} | ||
if (!children) { | ||
return slots; | ||
} | ||
const defaultSlot = []; | ||
for (let i = 0, l = children.length; i < l; i++) { | ||
const child = children[i]; | ||
const data = child.data; | ||
// remove slot attribute if the node is resolved as a Vue slot node | ||
if (data && data.attrs && data.attrs.slot) { | ||
delete data.attrs.slot; | ||
} | ||
if (data && data.slot != null) { | ||
const name = data.slot; | ||
const slot = (slots[name] || (slots[name] = [])); | ||
if (child.tag === 'template') { | ||
slot.push.apply(slot, child.children || []); | ||
} else { | ||
slot.push(child); | ||
} | ||
} else { | ||
(slots.default || (slots.default = [])).push(child); | ||
} | ||
} | ||
// ignore slots that contains only whitespace | ||
for (const name in slots) { | ||
if (slots[name].every(isWhitespace)) { | ||
delete slots[name]; | ||
} | ||
} | ||
return slots; | ||
} | ||
function isWhitespace(node) { | ||
return (node.isComment && !node.asyncFactory) || node.text === ' '; | ||
} | ||
// copy from vue/src/core/vdom/vnode.js | ||
function cloneVNode (vnode) { | ||
var cloned = new VueVNode( | ||
vnode.tag, | ||
// clone data | ||
vnode.data ? {...vnode.data} : vnode.data, | ||
// #7975 | ||
// clone children array to avoid mutating original in case of cloning | ||
// a child. | ||
vnode.children && vnode.children.slice(), | ||
vnode.text, | ||
vnode.elm, | ||
vnode.context, | ||
vnode.componentOptions, | ||
vnode.asyncFactory | ||
); | ||
cloned.ns = vnode.ns; | ||
cloned.isStatic = vnode.isStatic; | ||
cloned.key = vnode.key; | ||
cloned.isComment = vnode.isComment; | ||
cloned.fnContext = vnode.fnContext; | ||
cloned.fnOptions = vnode.fnOptions; | ||
cloned.fnScopeId = vnode.fnScopeId; | ||
cloned.asyncMeta = vnode.asyncMeta; | ||
cloned.isCloned = true; | ||
return cloned | ||
} | ||
function cached(fn) { | ||
const cache = Object.create(null); | ||
return function(str) { | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}; | ||
} | ||
/** | ||
* Camelize a hyphen-delimited string. | ||
*/ | ||
const camelizeRE = /-(\w)/g | ||
const camelize = cached((str) => { | ||
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : ''); | ||
}); |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13
0
50105
3
31
1297
1
+ Added@babel/runtime@^7.12.5
+ Added@babel/runtime@7.26.9(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@vue/compiler-core@3.5.13(transitive)
+ Added@vue/compiler-dom@3.5.13(transitive)
+ Added@vue/compiler-sfc@3.5.13(transitive)
+ Added@vue/compiler-ssr@3.5.13(transitive)
+ Added@vue/reactivity@3.5.13(transitive)
+ Added@vue/runtime-core@3.5.13(transitive)
+ Added@vue/runtime-dom@3.5.13(transitive)
+ Added@vue/server-renderer@3.5.13(transitive)
+ Added@vue/shared@3.5.13(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedmagic-string@0.30.17(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedvue@3.5.13(transitive)
- Removed@vue/compiler-sfc@2.7.16(transitive)
- Removedprettier@2.8.8(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedvue@2.7.16(transitive)