提交 3843f98e 编写于 作者: D doly mood 提交者: GitHub

Fix create api (#172)

* fix input append prepend style

* fix issue #167

* create-api params check

* add istanbul ignore
上级 f26633b8
......@@ -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) => {
......
......@@ -65,6 +65,7 @@ let vendor = (() => {
})()
export function prefixStyle(style) {
/* istanbul ignore if */
if (vendor === false) {
return false
}
......
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)) {
......
......@@ -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)
}
......
......@@ -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
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册