From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- .../src/platforms/weex/runtime/components/index.js | 9 + .../platforms/weex/runtime/components/richtext.js | 82 +++++++ .../weex/runtime/components/transition-group.js | 148 +++++++++++ .../weex/runtime/components/transition.js | 9 + .../src/platforms/weex/runtime/directives/index.js | 2 + .../vue/src/platforms/weex/runtime/index.js | 42 ++++ .../src/platforms/weex/runtime/modules/attrs.js | 44 ++++ .../src/platforms/weex/runtime/modules/class.js | 75 ++++++ .../src/platforms/weex/runtime/modules/events.js | 57 +++++ .../src/platforms/weex/runtime/modules/index.js | 13 + .../src/platforms/weex/runtime/modules/style.js | 84 +++++++ .../platforms/weex/runtime/modules/transition.js | 270 +++++++++++++++++++++ .../vue/src/platforms/weex/runtime/node-ops.js | 91 +++++++ .../vue/src/platforms/weex/runtime/patch.js | 16 ++ .../recycle-list/render-component-template.js | 34 +++ .../weex/runtime/recycle-list/virtual-component.js | 136 +++++++++++ .../vue/src/platforms/weex/runtime/text-node.js | 9 + 17 files changed, 1121 insertions(+) create mode 100644 node_modules/vue/src/platforms/weex/runtime/components/index.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/components/richtext.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/components/transition-group.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/components/transition.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/directives/index.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/index.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/modules/attrs.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/modules/class.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/modules/events.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/modules/index.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/modules/style.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/modules/transition.js create mode 100755 node_modules/vue/src/platforms/weex/runtime/node-ops.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/patch.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/recycle-list/render-component-template.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/recycle-list/virtual-component.js create mode 100644 node_modules/vue/src/platforms/weex/runtime/text-node.js (limited to 'node_modules/vue/src/platforms/weex/runtime') diff --git a/node_modules/vue/src/platforms/weex/runtime/components/index.js b/node_modules/vue/src/platforms/weex/runtime/components/index.js new file mode 100644 index 00000000..449db1ad --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/components/index.js @@ -0,0 +1,9 @@ +import Richtext from './richtext' +import Transition from './transition' +import TransitionGroup from './transition-group' + +export default { + Richtext, + Transition, + TransitionGroup +} diff --git a/node_modules/vue/src/platforms/weex/runtime/components/richtext.js b/node_modules/vue/src/platforms/weex/runtime/components/richtext.js new file mode 100644 index 00000000..a9164c7a --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/components/richtext.js @@ -0,0 +1,82 @@ +/* @flow */ + +function getVNodeType (vnode: VNode): string { + if (!vnode.tag) { + return '' + } + return vnode.tag.replace(/vue\-component\-(\d+\-)?/, '') +} + +function isSimpleSpan (vnode: VNode): boolean { + return vnode.children && + vnode.children.length === 1 && + !vnode.children[0].tag +} + +function parseStyle (vnode: VNode): Object | void { + if (!vnode || !vnode.data) { + return + } + const { staticStyle, staticClass } = vnode.data + if (vnode.data.style || vnode.data.class || staticStyle || staticClass) { + const styles = Object.assign({}, staticStyle, vnode.data.style) + const cssMap = vnode.context.$options.style || {} + const classList = [].concat(staticClass, vnode.data.class) + classList.forEach(name => { + if (name && cssMap[name]) { + Object.assign(styles, cssMap[name]) + } + }) + return styles + } +} + +function convertVNodeChildren (children: Array): Array | void { + if (!children.length) { + return + } + + return children.map(vnode => { + const type: string = getVNodeType(vnode) + const props: Object = { type } + + // convert raw text node + if (!type) { + props.type = 'span' + props.attr = { + value: (vnode.text || '').trim() + } + } else { + props.style = parseStyle(vnode) + if (vnode.data) { + props.attr = vnode.data.attrs + if (vnode.data.on) { + props.events = vnode.data.on + } + } + if (type === 'span' && isSimpleSpan(vnode)) { + props.attr = props.attr || {} + props.attr.value = vnode.children[0].text.trim() + return props + } + } + + if (vnode.children && vnode.children.length) { + props.children = convertVNodeChildren(vnode.children) + } + + return props + }) +} + +export default { + name: 'richtext', + render (h: Function) { + return h('weex:richtext', { + on: this._events, + attrs: { + value: convertVNodeChildren(this.$options._renderChildren || []) + } + }) + } +} diff --git a/node_modules/vue/src/platforms/weex/runtime/components/transition-group.js b/node_modules/vue/src/platforms/weex/runtime/components/transition-group.js new file mode 100644 index 00000000..4a65965f --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/components/transition-group.js @@ -0,0 +1,148 @@ +import { warn, extend } from 'core/util/index' +import { transitionProps, extractTransitionData } from './transition' + +const props = extend({ + tag: String, + moveClass: String +}, transitionProps) + +delete props.mode + +export default { + props, + + created () { + const dom = this.$requireWeexModule('dom') + this.getPosition = el => new Promise((resolve, reject) => { + dom.getComponentRect(el.ref, res => { + if (!res.result) { + reject(new Error(`failed to get rect for element: ${el.tag}`)) + } else { + resolve(res.size) + } + }) + }) + + const animation = this.$requireWeexModule('animation') + this.animate = (el, options) => new Promise(resolve => { + animation.transition(el.ref, options, resolve) + }) + }, + + render (h) { + const tag = this.tag || this.$vnode.data.tag || 'span' + const map = Object.create(null) + const prevChildren = this.prevChildren = this.children + const rawChildren = this.$slots.default || [] + const children = this.children = [] + const transitionData = extractTransitionData(this) + + for (let i = 0; i < rawChildren.length; i++) { + const c = rawChildren[i] + if (c.tag) { + if (c.key != null && String(c.key).indexOf('__vlist') !== 0) { + children.push(c) + map[c.key] = c + ;(c.data || (c.data = {})).transition = transitionData + } else if (process.env.NODE_ENV !== 'production') { + const opts = c.componentOptions + const name = opts + ? (opts.Ctor.options.name || opts.tag) + : c.tag + warn(` children must be keyed: <${name}>`) + } + } + } + + if (prevChildren) { + const kept = [] + const removed = [] + prevChildren.forEach(c => { + c.data.transition = transitionData + + // TODO: record before patch positions + + if (map[c.key]) { + kept.push(c) + } else { + removed.push(c) + } + }) + this.kept = h(tag, null, kept) + this.removed = removed + } + + return h(tag, null, children) + }, + + beforeUpdate () { + // force removing pass + this.__patch__( + this._vnode, + this.kept, + false, // hydrating + true // removeOnly (!important, avoids unnecessary moves) + ) + this._vnode = this.kept + }, + + updated () { + const children = this.prevChildren + const moveClass = this.moveClass || ((this.name || 'v') + '-move') + const moveData = children.length && this.getMoveData(children[0].context, moveClass) + if (!moveData) { + return + } + + // TODO: finish implementing move animations once + // we have access to sync getComponentRect() + + // children.forEach(callPendingCbs) + + // Promise.all(children.map(c => { + // const oldPos = c.data.pos + // const newPos = c.data.newPos + // const dx = oldPos.left - newPos.left + // const dy = oldPos.top - newPos.top + // if (dx || dy) { + // c.data.moved = true + // return this.animate(c.elm, { + // styles: { + // transform: `translate(${dx}px,${dy}px)` + // } + // }) + // } + // })).then(() => { + // children.forEach(c => { + // if (c.data.moved) { + // this.animate(c.elm, { + // styles: { + // transform: '' + // }, + // duration: moveData.duration || 0, + // delay: moveData.delay || 0, + // timingFunction: moveData.timingFunction || 'linear' + // }) + // } + // }) + // }) + }, + + methods: { + getMoveData (context, moveClass) { + const stylesheet = context.$options.style || {} + return stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][moveClass] + } + } +} + +// function callPendingCbs (c) { +// /* istanbul ignore if */ +// if (c.elm._moveCb) { +// c.elm._moveCb() +// } +// /* istanbul ignore if */ +// if (c.elm._enterCb) { +// c.elm._enterCb() +// } +// } diff --git a/node_modules/vue/src/platforms/weex/runtime/components/transition.js b/node_modules/vue/src/platforms/weex/runtime/components/transition.js new file mode 100644 index 00000000..20ba632d --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/components/transition.js @@ -0,0 +1,9 @@ +// reuse same transition component logic from web +export { + transitionProps, + extractTransitionData +} from 'web/runtime/components/transition' + +import Transition from 'web/runtime/components/transition' + +export default Transition diff --git a/node_modules/vue/src/platforms/weex/runtime/directives/index.js b/node_modules/vue/src/platforms/weex/runtime/directives/index.js new file mode 100755 index 00000000..efba7fa6 --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/directives/index.js @@ -0,0 +1,2 @@ +export default { +} diff --git a/node_modules/vue/src/platforms/weex/runtime/index.js b/node_modules/vue/src/platforms/weex/runtime/index.js new file mode 100755 index 00000000..b8e09305 --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/index.js @@ -0,0 +1,42 @@ +/* @flow */ + +import Vue from 'core/index' +import { patch } from 'weex/runtime/patch' +import { mountComponent } from 'core/instance/lifecycle' +import platformDirectives from 'weex/runtime/directives/index' +import platformComponents from 'weex/runtime/components/index' + +import { + query, + mustUseProp, + isReservedTag, + isRuntimeComponent, + isUnknownElement +} from 'weex/util/element' + +// install platform specific utils +Vue.config.mustUseProp = mustUseProp +Vue.config.isReservedTag = isReservedTag +Vue.config.isRuntimeComponent = isRuntimeComponent +Vue.config.isUnknownElement = isUnknownElement + +// install platform runtime directives and components +Vue.options.directives = platformDirectives +Vue.options.components = platformComponents + +// install platform patch function +Vue.prototype.__patch__ = patch + +// wrap mount +Vue.prototype.$mount = function ( + el?: any, + hydrating?: boolean +): Component { + return mountComponent( + this, + el && query(el, this.$document), + hydrating + ) +} + +export default Vue diff --git a/node_modules/vue/src/platforms/weex/runtime/modules/attrs.js b/node_modules/vue/src/platforms/weex/runtime/modules/attrs.js new file mode 100755 index 00000000..1b6185ca --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/modules/attrs.js @@ -0,0 +1,44 @@ +/* @flow */ + +import { extend } from 'shared/util' + +function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { + if (!oldVnode.data.attrs && !vnode.data.attrs) { + return + } + let key, cur, old + const elm = vnode.elm + const oldAttrs = oldVnode.data.attrs || {} + let attrs = vnode.data.attrs || {} + // clone observed objects, as the user probably wants to mutate it + if (attrs.__ob__) { + attrs = vnode.data.attrs = extend({}, attrs) + } + + const supportBatchUpdate = typeof elm.setAttrs === 'function' + const batchedAttrs = {} + for (key in attrs) { + cur = attrs[key] + old = oldAttrs[key] + if (old !== cur) { + supportBatchUpdate + ? (batchedAttrs[key] = cur) + : elm.setAttr(key, cur) + } + } + for (key in oldAttrs) { + if (attrs[key] == null) { + supportBatchUpdate + ? (batchedAttrs[key] = undefined) + : elm.setAttr(key) + } + } + if (supportBatchUpdate) { + elm.setAttrs(batchedAttrs) + } +} + +export default { + create: updateAttrs, + update: updateAttrs +} diff --git a/node_modules/vue/src/platforms/weex/runtime/modules/class.js b/node_modules/vue/src/platforms/weex/runtime/modules/class.js new file mode 100755 index 00000000..029b9e9e --- /dev/null +++ b/node_modules/vue/src/platforms/weex/runtime/modules/class.js @@ -0,0 +1,75 @@ +/* @flow */ + +import { extend } from 'shared/util' + +function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { + const el = vnode.elm + const ctx = vnode.context + + const data: VNodeData = vnode.data + const oldData: VNodeData = oldVnode.data + if (!data.staticClass && + !data.class && + (!oldData || (!oldData.staticClass && !oldData.class)) + ) { + return + } + + const oldClassList = [] + // unlike web, weex vnode staticClass is an Array + const oldStaticClass: any = oldData.staticClass + if (oldStaticClass) { + oldClassList.push.apply(oldClassList, oldStaticClass) + } + if (oldData.class) { + oldClassList.push.apply(oldClassList, oldData.class) + } + + const classList = [] + // unlike web, weex vnode staticClass is an Array + const staticClass: any = data.staticClass + if (staticClass) { + classList.push.apply(classList, staticClass) + } + if (data.class) { + classList.push.apply(classList, data.class) + } + + if (typeof el.setClassList === 'function') { + el.setClassList(classList) + } else { + const style = getStyle(oldClassList, classList, ctx) + if (typeof el.setStyles === 'function') { + el.setStyles(style) + } else { + for (const key in style) { + el.setStyle(key, style[key]) + } + } + } +} + +function getStyle (oldClassList: Array, classList: Array, ctx: Component): Object { + // style is a weex-only injected object + // compiled from