diff --git a/src/common/helpers/create-api-component.js b/src/common/helpers/create-api-component.js index fbf303cf292e94b9f1dd908b54d0da5520c9c78e..678a49385696b98796890a8dd13d27b553c741b1 100644 --- a/src/common/helpers/create-api-component.js +++ b/src/common/helpers/create-api-component.js @@ -9,11 +9,17 @@ export default function createAPIComponent(Vue, Component, events = [], single = before(fn) { beforeFns.push(fn) }, - open(data, renderFn, instanceSingle) { - if (typeof renderFn !== 'function') { - instanceSingle = renderFn + open(data, renderFn, options) { + if (typeof renderFn !== 'function' && options === undefined) { + options = renderFn renderFn = null } + let instanceSingle = options + if (typeof options === 'object') { + instanceSingle = !!options.single + delete options.single + } + beforeFns.forEach((before) => { before(data, renderFn, instanceSingle) }) @@ -26,7 +32,7 @@ export default function createAPIComponent(Vue, Component, events = [], single = // singleComponent.show && singleComponent.show() return singleComponent } - const component = instantiateComponent(Vue, Component, data, renderFn) + const component = instantiateComponent(Vue, Component, data, renderFn, options) const instance = component.$parent const originRemove = component.remove @@ -61,13 +67,27 @@ export default function createAPIComponent(Vue, Component, events = [], single = }, create(config, renderFn, single) { const ownerInstance = this + const isInVueInstance = !!ownerInstance.$on const renderData = parseRenderData(config, events) cancelWatchProps() processProps() processEvents() - const component = api.open(renderData, renderFn, single) + if (typeof renderFn !== 'function' && single === undefined) { + single = !!renderFn + renderFn = null + } + // to get Vue options + // store router i18n ... + const options = { + single: single + } + if (isInVueInstance) { + options.parent = ownerInstance + } + + const component = api.open(renderData, renderFn, options) if (component.__cube__parent !== ownerInstance) { component.__cube__parent = ownerInstance const beforeDestroy = function () { @@ -78,7 +98,7 @@ export default function createAPIComponent(Vue, Component, events = [], single = ownerInstance.$off('hook:beforeDestroy', beforeDestroy) component.__cube__parent = null } - ownerInstance.$on && ownerInstance.$on('hook:beforeDestroy', beforeDestroy) + isInVueInstance && ownerInstance.$on('hook:beforeDestroy', beforeDestroy) } return component @@ -100,7 +120,7 @@ export default function createAPIComponent(Vue, Component, events = [], single = renderData.props[key] = propKey } }) - if (ownerInstance.$watch) { + if (isInVueInstance) { ownerInstance.__createAPI_watcher = ownerInstance.$watch(function () { const props = {} watchKeys.forEach((key, i) => { diff --git a/src/common/helpers/dom.js b/src/common/helpers/dom.js index 351669f6d4c6823614cc78671c76a70a6ff24918..f97cb83522738256a7bca6a0af622b29b160da1c 100644 --- a/src/common/helpers/dom.js +++ b/src/common/helpers/dom.js @@ -65,6 +65,7 @@ let vendor = (() => { })() export function prefixStyle(style) { + /* istanbul ignore if */ if (vendor === false) { return false } diff --git a/src/common/helpers/instantiate-component.js b/src/common/helpers/instantiate-component.js index 04db2c2062cf7797d5c06dee0774e2d972a21c13..2297fd2e44dae05894be51d068e370621ff60b3d 100644 --- a/src/common/helpers/instantiate-component.js +++ b/src/common/helpers/instantiate-component.js @@ -1,7 +1,13 @@ -export default function instantiateComponent(Vue, Component, data, renderFn) { +export default function instantiateComponent(Vue, Component, data, renderFn, options) { let renderData let childrenRenderFn + + if (options === undefined) { + options = {} + } + const instance = new Vue({ + ...options, render(createElement) { let children = childrenRenderFn && childrenRenderFn(createElement) if (children && !Array.isArray(children)) { diff --git a/src/common/helpers/raf.js b/src/common/helpers/raf.js index 79970409d8a716848de49000dd023c4744c05d68..2de23478909348f3d0763a8834ca1f0e245f7a21 100644 --- a/src/common/helpers/raf.js +++ b/src/common/helpers/raf.js @@ -11,10 +11,14 @@ export const requestAnimationFrame = (() => { return noop } return window.requestAnimationFrame || + /* istanbul ignore next */ window.webkitRequestAnimationFrame || + /* istanbul ignore next */ window.mozRequestAnimationFrame || + /* istanbul ignore next */ window.oRequestAnimationFrame || // if all else fails, use setTimeout + /* istanbul ignore next */ function (callback) { return window.setTimeout(callback, (callback.interval || DEFAULT_INTERVAL) / 2) // make interval as precise as possible. } @@ -26,9 +30,13 @@ export const cancelAnimationFrame = (() => { return noop } return window.cancelAnimationFrame || + /* istanbul ignore next */ window.webkitCancelAnimationFrame || + /* istanbul ignore next */ window.mozCancelAnimationFrame || + /* istanbul ignore next */ window.oCancelAnimationFrame || + /* istanbul ignore next */ function (id) { window.clearTimeout(id) } diff --git a/src/common/helpers/util.js b/src/common/helpers/util.js index 319e562315179ec3f02a453eadf270cb1fc1f723..f15d3d897e1f31565a747451bd087c9556d1d048 100644 --- a/src/common/helpers/util.js +++ b/src/common/helpers/util.js @@ -2,7 +2,9 @@ function findIndex(ary, fn) { if (ary.findIndex) { return ary.findIndex(fn) } + /* istanbul ignore next */ let index = -1 + /* istanbul ignore next */ ary.some(function (item, i, ary) { const ret = fn.call(this, item, i, ary) if (ret) { @@ -10,6 +12,7 @@ function findIndex(ary, fn) { return ret } }) + /* istanbul ignore next */ return index } diff --git a/src/components/input/input.vue b/src/components/input/input.vue index 1093e7e40f3c20c42864674bd1a5532b51194087..71bba0fd90f8962dce97bb867a00c486ae60a4ac 100644 --- a/src/components/input/input.vue +++ b/src/components/input/input.vue @@ -179,6 +179,7 @@ border-color: $input-focus-border-color .cube-input-prepend, .cube-input-append display: flex + align-items: center .cube-input-prepend + .cube-input-field margin-left: -5px