提交 f20a6cad 编写于 作者: M mehaotian

Merge branch 'v3' of https://github.com/dcloudio/uni-app into v3

......@@ -12,5 +12,5 @@
"message": "chore(release): publish %s"
}
},
"version": "3.0.0-alpha-24020191018012"
"version": "3.0.0-alpha-24020191018019"
}
......@@ -28,7 +28,7 @@
"release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=v3"
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
},
"dependencies": {
"base64-arraybuffer": "^0.2.0",
......
{
"name": "@dcloudio/uni-app-plus-nvue",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app app-plus-nvue",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
......@@ -3173,7 +3173,7 @@ var serviceContext = (function () {
return invokeVmMethodWithoutArgs(ctx, 'pause')
},
seek (ctx, args) {
return invokeVmMethod(ctx, 'seek', args)
return invokeVmMethod(ctx, 'seek', args.position)
},
stop (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'stop')
......@@ -3182,7 +3182,7 @@ var serviceContext = (function () {
return invokeVmMethod(ctx, 'sendDanmu', args)
},
playbackRate (ctx, args) {
return invokeVmMethod(ctx, 'playbackRate', args)
return invokeVmMethod(ctx, 'playbackRate', args.rate)
},
requestFullScreen (ctx, args) {
return invokeVmMethod(ctx, 'requestFullScreen', args)
......@@ -7999,7 +7999,7 @@ var serviceContext = (function () {
createMapContext: createMapContext$1
});
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5];
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0];
function operateVideoPlayer$3 (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data);
......@@ -8021,8 +8021,8 @@ var serviceContext = (function () {
operateVideoPlayer$3(this.id, this.pageVm, 'stop');
}
seek (position) {
operateVideoPlayer$3(this.id, this.pageVm, 'seek', {
position
operateVideoPlayer$3(this.id, this.pageVm, 'seek', {
position
});
}
sendDanmu (args) {
......@@ -8032,12 +8032,12 @@ var serviceContext = (function () {
if (!~RATES.indexOf(rate)) {
rate = 1.0;
}
operateVideoPlayer$3(this.id, this.pageVm, 'playbackRate', {
rate
operateVideoPlayer$3(this.id, this.pageVm, 'playbackRate', {
rate
});
}
requestFullScreen () {
operateVideoPlayer$3(this.id, this.pageVm, 'requestFullScreen');
requestFullScreen (args = {}) {
operateVideoPlayer$3(this.id, this.pageVm, 'requestFullScreen', args);
}
exitFullScreen () {
operateVideoPlayer$3(this.id, this.pageVm, 'exitFullScreen');
......
......@@ -695,7 +695,13 @@ var uid = 0;
* directives subscribing to it.
*/
var Dep = function Dep () {
this.id = uid++;
// fixed by xxxxxx (nvue vuex)
/* eslint-disable no-undef */
if(typeof SharedObject !== 'undefined'){
this.id = SharedObject.uid++;
} else {
this.id = uid++;
}
this.subs = [];
};
......@@ -708,8 +714,8 @@ Dep.prototype.removeSub = function removeSub (sub) {
};
Dep.prototype.depend = function depend () {
if (Dep.target) {
Dep.target.addDep(this);
if (Dep.SharedObject.target) { // fixed by xxxxxx
Dep.SharedObject.target.addDep(this);
}
};
......@@ -730,17 +736,20 @@ Dep.prototype.notify = function notify () {
// The current target watcher being evaluated.
// This is globally unique because only one watcher
// can be evaluated at a time.
Dep.target = null;
var targetStack = [];
// fixed by xxxxxx (nvue shared vuex)
/* eslint-disable no-undef */
Dep.SharedObject = typeof SharedObject !== 'undefined' ? SharedObject : {};
Dep.SharedObject.target = null;
Dep.SharedObject.targetStack = [];
function pushTarget (target) {
targetStack.push(target);
Dep.target = target;
Dep.SharedObject.targetStack.push(target);
Dep.SharedObject.target = target;
}
function popTarget () {
targetStack.pop();
Dep.target = targetStack[targetStack.length - 1];
Dep.SharedObject.targetStack.pop();
Dep.SharedObject.target = Dep.SharedObject.targetStack[Dep.SharedObject.targetStack.length - 1];
}
/* */
......@@ -1019,7 +1028,7 @@ function defineReactive$$1 (
configurable: true,
get: function reactiveGetter () {
var value = getter ? getter.call(obj) : val;
if (Dep.target) {
if (Dep.SharedObject.target) { // fixed by xxxxxx
dep.depend();
if (childOb) {
childOb.dep.depend();
......@@ -4843,7 +4852,7 @@ function createComputedGetter (key) {
if (watcher.dirty) {
watcher.evaluate();
}
if (Dep.target) {
if (Dep.SharedObject.target) { // fixed by xxxxxx
watcher.depend();
}
return watcher.value
......@@ -6792,10 +6801,6 @@ var plugin = {
Vue.prototype._$queue = queue;
Vue.prototype._m = function renderStatic() {
return this._e()
};
Vue.prototype.__call_hook = callHook$2;
// 运行时需要格式化 class,style
Vue.prototype._$stringifyClass = stringifyClass;
......
此差异已折叠。
{
"name": "@dcloudio/uni-app-plus",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app app-plus",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-cli-shared",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-cli-shared",
"main": "lib/index.js",
"repository": {
......@@ -21,5 +21,5 @@
"hash-sum": "^1.0.2",
"strip-json-comments": "^2.0.1"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-h5-ui",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app h5 ui",
"main": "dist/index.umd.min.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-h5",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"repository": {
......@@ -18,5 +18,5 @@
"intersection-observer": "^0.7.0",
"safe-area-insets": "^1.4.1"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-mp-alipay",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-mp-baidu",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-mp-qq",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-qq",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-mp-weixin",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/uni-stat",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "",
"main": "dist/index.js",
"repository": {
......@@ -34,5 +34,5 @@
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
......@@ -70,6 +70,17 @@ describe('codegen', () => {
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
)
})
it('generate keep-alive', () => {
assertCodegen(
`<keep-alive exclude="componentWithStatus1"><component is="componentWithStatus"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
)
assertCodegen(
`<keep-alive :exclude="componentWithStatus1"><component :is="'componentWithStatus'+index"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":_$s(0,'a-exclude',componentWithStatus1),"_i":0}},[_c(_$s(1,'is','componentWithStatus'+index),{tag:"component",attrs:{"_i":1}})],1)}`
)
})
})
/* eslint-enable quotes */
......@@ -15,7 +15,7 @@ describe('codegen', () => {
it('generate directive', () => {
assertCodegen(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
it('generate v-for directive', () => {
......@@ -45,6 +45,16 @@ describe('codegen', () => {
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$g(0,'t0')))]}}])})}`
)
})
it('generate keep-alive', () => {
assertCodegen(
`<keep-alive exclude="componentWithStatus1"><component is="componentWithStatus"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
)
assertCodegen(
`<keep-alive :exclude="componentWithStatus1"><component :is="'componentWithStatus'+index"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":_$g(0,'a-exclude'),"_i":0}},[_c(_$g(1,'is'),{tag:"component",attrs:{"_i":1}})],1)}`
)
})
})
/* eslint-enable quotes */
......@@ -576,7 +576,7 @@ describe('codegen', () => {
)
assertCodegen(
'<div :is="component1"></div>',
`with(this){return _c(component1,{tag:"div"})}`
`with(this){return _c(_$s(0,'is',component1),{tag:"div"})}`
)
// maybe a component and normalize type should be 1
assertCodegen(
......@@ -589,7 +589,7 @@ describe('codegen', () => {
// have "inline-template'"
assertCodegen(
'<my-component inline-template><p><span>hello world</span></p></my-component>',
`with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span')])}}]}})}`
`with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('p',[_c('span')])}},staticRenderFns:[]}})}`
)
// "have inline-template attrs, but not having exactly one child element
assertCodegen(
......@@ -616,7 +616,7 @@ describe('codegen', () => {
it('generate static trees inside v-for', () => {
assertCodegen(
`<div><div v-for="i in 10"><p><span></span></p></div></div>`,
`with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_m(0,true)])}),0)}`
`with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_c('p',[_c('span')])])}),0)}`
// [`with(this){return _c('p',[_c('span')])}`]
)
})
......@@ -660,7 +660,7 @@ describe('codegen', () => {
it('does not squash templates inside v-pre', () => {
assertCodegen(
'<div v-pre><template><p>{{msg}}</p></template></div>',
`with(this){return _m(0)}`
`with(this){return _c('div',[[_c('p')]],2)}`
)
// const template = '<div v-pre><template><p>{{msg}}</p></template></div>'
// const generatedCode = `with(this){return _m(0)}`
......
......@@ -15,12 +15,12 @@ describe('codegen', () => {
it('generate directive', () => {
assertCodegen(
'<p v-custom1:arg1.modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
// extra
assertCodegen(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
......@@ -576,7 +576,7 @@ describe('codegen', () => {
)
assertCodegen(
'<div :is="component1"></div>',
`with(this){return _c(component1,{tag:"v-uni-view",attrs:{"_i":0}})}`
`with(this){return _c(_$g(0,'is'),{tag:"v-uni-view",attrs:{"_i":0}})}`
)
// maybe a component and normalize type should be 1
assertCodegen(
......
const compiler = require('../lib')
const res = compiler.compile(
`
<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>
<p v-text="test"></p>
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
......@@ -13,7 +13,7 @@ const res = compiler.compile(
mp: {
platform: 'app-plus'
},
service: true,
// service: true,
view: true
})
console.log(require('util').inspect(res, {
......
......@@ -14,7 +14,11 @@ function no (a, b, c) {
}
function isBuiltInTag (tag) {
if (tag === 'slot' || tag === 'component') {
if (
tag === 'slot' ||
tag === 'component' ||
tag === 'keep-alive'
) {
return true
}
}
......@@ -48,11 +52,11 @@ function markStatic (node) {
}
delete node.attrs
}
if (node.type === 1) {
if (node.type === 1) {
delete node.staticClass
delete node.staticStyle
if (node.attrs && !isComponent(node.tag)) { // 移除静态属性
if (node.attrs && !isComponent(node.tag) && node.tag !== 'keep-alive') { // 移除静态属性
node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value))
}
......
const {
ID,
C_IS,
V_IF,
V_FOR,
V_ELSE_IF,
......@@ -8,6 +9,15 @@ const {
const parseTextExpr = require('./text-parser')
function parseIs (el, genVar) {
if (!el.component) {
return
}
if (isVar(el.component)) {
el.component = genVar(C_IS, el.component)
}
}
function parseIf (el, createGenVar) {
if (!el.if) {
return
......@@ -60,6 +70,7 @@ function parseText (el, parent, state) {
}
module.exports = {
parseIs,
parseIf,
parseFor,
parseText,
......
const {
ID,
hasOwn
ID
} = require('../util')
const tags = require('../../../../uni-cli-shared/lib/tags')
const {
isComponent
} = require('../../util')
// 仅限 view 层
module.exports = function parseComponent (el) {
// 需要把自定义组件的 attrs, props 全干掉
if (el.tag && !hasOwn(tags, el.tag.replace('v-uni-', ''))) {
if (el.tag && isComponent(el.tag)) {
// 仅保留 ID
el.attrs && (el.attrs = el.attrs.filter(attr => attr.name === ID))
}
......
......@@ -14,6 +14,7 @@ const {
} = require('../util')
const {
parseIs,
parseIf,
parseFor,
parseText,
......@@ -82,6 +83,7 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID])
parseIs(el, genVar)
parseFor(el, createGenVar)
parseKey(el)
......
......@@ -9,6 +9,8 @@ const ITERATOR2 = '$2'
const ITERATOR3 = '$3'
const SET_DATA = '_$s'
const GET_DATA = '_$g'
const C_IS = 'is'
const V_FOR = 'f'
const V_IF = 'i'
......@@ -190,7 +192,8 @@ function addHandler (el, name, value, important) {
el.plain = false
}
module.exports = {
module.exports = {
C_IS,
V_FOR,
V_IF,
V_ELSE_IF,
......
......@@ -9,10 +9,10 @@ const {
} = require('./util')
const {
parseIs,
parseIf,
parseFor,
parseText,
parseDirs,
parseAttrs,
parseProps,
parseBinding
......@@ -53,6 +53,41 @@ function parseKey (el) {
}
}
function parseDirs (el, genVar, ignoreDirs, includeDirs = []) {
if (!el.directives) {
return
}
el.directives = el.directives.filter(dir => {
if (includeDirs.indexOf(dir.name) !== -1) {
if (ignoreDirs.indexOf(dir.name) === -1) {
dir.value && (dir.value = genVar('v-' + dir.name, dir.value))
dir.isDynamicArg && (dir.arg = genVar('v-' + dir.name + '-arg', dir.arg))
}
return true
}
})
}
const includeDirs = [
'text',
'html',
'bind',
'model',
'show',
'if',
'else',
'else-if',
'for',
'on',
'bind',
'slot',
'pre',
'cloak',
'once'
]
const ignoreDirs = ['model']
function transformNode (el, parent, state) {
if (el.type === 3) {
return
......@@ -74,6 +109,8 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID])
parseIs(el, genVar)
if (parseFor(el, createGenVar)) {
if (el.alias[0] === '{') { // <div><li v-for=" { a, b } in items"></li></div>
el.alias = '$item'
......@@ -83,7 +120,7 @@ function transformNode (el, parent, state) {
parseIf(el, createGenVar)
parseBinding(el, genVar)
parseDirs(el, genVar, ['model'])
parseDirs(el, genVar, ignoreDirs, includeDirs)
parseAttrs(el, genVar)
parseProps(el, genVar)
}
......
......@@ -30,7 +30,7 @@ module.exports = {
compile (source, options = {}) {
if (options.service) {
(options.modules || (options.modules = [])).push(require('./app/service'))
options.optimize = true // 启用 staticRenderFns
options.optimize = false // 启用 staticRenderFns
// domProps => attrs
options.mustUseProp = () => false
options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置
......@@ -38,12 +38,11 @@ module.exports = {
// clear staticRenderFns
const compiled = compile(source, options)
compiled.staticRenderFns.length = 0
return compiled
} else if (options.view) {
(options.modules || (options.modules = [])).push(require('./app/view'))
options.optimize = false // 暂不启用 staticRenderFns
options.optimize = false // 暂不启用 staticRenderFns
options.isReservedTag = (tagName) => false // 均为组件
return compile(source, options)
}
......
......@@ -183,9 +183,13 @@ const {
} = require('./h5')
function isComponent (tagName) {
if (tagName === 'block' || tagName === 'template') {
if (
tagName === 'block' ||
tagName === 'template' ||
tagName === 'keep-alive'
) {
return false
}
}
return !hasOwn(tags, getTagName(tagName.replace('v-uni-', '')))
}
......
{
"name": "@dcloudio/uni-template-compiler",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-template-compiler",
"main": "lib/index.js",
"repository": {
......@@ -22,5 +22,5 @@
"@babel/types": "^7.3.3",
"vue-template-compiler": "^2.6.10"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/vue-cli-plugin-hbuilderx",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "HBuilderX plugin for vue-cli 3",
"main": "index.js",
"repository": {
......@@ -18,5 +18,5 @@
"css": "~2.2.1",
"escodegen": "^1.8.1"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/vue-cli-plugin-uni-optimize",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js",
"repository": {
......@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/vue-cli-plugin-uni",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app plugin for vue-cli 3",
"main": "index.js",
"repository": {
......@@ -17,7 +17,7 @@
"author": "fxy060608",
"license": "Apache-2.0",
"dependencies": {
"@dcloudio/uni-stat": "^3.0.0-alpha-24020191018012",
"@dcloudio/uni-stat": "^3.0.0-alpha-24020191018019",
"copy-webpack-plugin": "^4.6.0",
"cross-env": "^5.2.0",
"envinfo": "^6.0.1",
......@@ -34,5 +34,5 @@
"wrap-loader": "^0.2.0",
"xregexp": "4.0.0"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
......@@ -17,7 +17,9 @@ const {
parseComponents
} = require('./util')
function getDefineComponents(components) {
function getDefineComponents({
components
}) {
return components.map(({
name,
source
......@@ -93,7 +95,7 @@ module.exports = function(source, map) {
return `
import 'uni-pages'
function initView(){
${getStylesCode(this)}
${getStylesCode(this)}
injectStyles()
${getDefineComponents(parseComponents(source, traverse)).join('\n')}
UniViewJSBridge.publishHandler('webviewReady')
......
......@@ -10,7 +10,7 @@ const {
parseComponents
} = require('./util')
function genComponentCode (components) {
function genComponentCode(components) {
const importCode = []
const componentsCode = []
components.forEach(({
......@@ -24,12 +24,20 @@ function genComponentCode (components) {
return [importCode.join('\n'), componentsCode.join(',\n')]
}
function genCode (components, css = []) {
function genCode({
components,
options
}, css = []) {
const optionsCode = []
Object.keys(options).forEach(name => {
options[name] !== null && optionsCode.push(`${name}:${options[name]}`)
})
const [importComponentCode, componentsCode] = genComponentCode(components)
// TODO js 内引用 css
return `
${importComponentCode}
export default {
${optionsCode.length?(optionsCode.join(',')+','):''}
data(){
return {}
},
......@@ -40,7 +48,7 @@ export default {
`
}
module.exports = function (content, map) {
module.exports = function(content, map) {
this.cacheable && this.cacheable()
content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
......
const parser = require('@babel/parser')
function parseComponents (content, traverse) {
function parseComponents(content, traverse) {
const {
state: {
options,
components
}
} = traverse(parser.parse(content, {
......@@ -15,9 +16,16 @@ function parseComponents (content, traverse) {
'classProperties'
]
}), {
components: []
components: [],
options: {
name: null,
inheritAttrs: null
}
})
return components
return {
components,
options
}
}
module.exports = {
......
......@@ -6,10 +6,27 @@ const {
} = require('./util')
function handleObjectExpression (declaration, path, state) {
if (state.options) { // name,inheritAttrs
Object.keys(state.options).forEach(name => {
const optionProperty = declaration.properties.filter(prop => {
return t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) &&
prop.key.name === name
})[0]
if (optionProperty) {
if (t.isStringLiteral(optionProperty.value)) {
state.options[name] = JSON.stringify(optionProperty.value.value)
} else {
state.options[name] = optionProperty.value.value
}
}
})
}
const componentsProperty = declaration.properties.filter(prop => {
return t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) &&
prop.key.name === 'components'
t.isIdentifier(prop.key) &&
prop.key.name === 'components'
})[0]
if (componentsProperty && t.isObjectExpression(componentsProperty.value)) {
......@@ -27,7 +44,8 @@ function handleObjectExpression (declaration, path, state) {
module.exports = function (ast, state = {
type: 'Component',
components: []
components: [],
options: {}
}) {
babelTraverse(ast, {
ExportDefaultDeclaration (path) {
......@@ -35,15 +53,15 @@ module.exports = function (ast, state = {
if (t.isObjectExpression(declaration)) { // export default {components:{}}
handleObjectExpression(declaration, path, state)
} else if (t.isCallExpression(declaration) &&
t.isMemberExpression(declaration.callee) &&
declaration.arguments.length === 1) { // export default Vue.extend({components:{}})
t.isMemberExpression(declaration.callee) &&
declaration.arguments.length === 1) { // export default Vue.extend({components:{}})
if (declaration.callee.object.name === 'Vue' && declaration.callee.property.name ===
'extend') {
'extend') {
handleObjectExpression(declaration.arguments[0], path, state)
}
} else if (t.isClassDeclaration(declaration) &&
declaration.decorators &&
declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
declaration.decorators &&
declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
const componentDecorator = declaration.decorators[0]
if (t.isCallExpression(componentDecorator.expression)) {
const args = componentDecorator.expression.arguments
......
{
"name": "@dcloudio/webpack-uni-mp-loader",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "webpack-uni-mp-loader",
"main": "index.js",
"repository": {
......@@ -16,5 +16,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
{
"name": "@dcloudio/webpack-uni-pages-loader",
"version": "3.0.0-alpha-24020191018012",
"version": "3.0.0-alpha-24020191018019",
"description": "uni-app pages.json loader",
"main": "lib/index.js",
"repository": {
......@@ -23,5 +23,5 @@
"uni-app": {
"compilerVersion": "2.3.4"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
"gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
}
......@@ -15,3 +15,4 @@ export const WEBVIEW_READY = 'webviewReady'
export const WEBVIEW_UI_EVENT = 'webviewUIEvent'
export const VD_SYNC_CALLBACK = 'vdSyncCallback'
export const INVOKE_API = 'invokeApi'
export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
......@@ -4,7 +4,8 @@ import {
VD_SYNC,
VD_SYNC_CALLBACK,
INVOKE_API,
WEBVIEW_READY
WEBVIEW_READY,
WEB_INVOKE_APPSERVICE
} from '../../../constants'
import {
......@@ -16,7 +17,8 @@ import onWebviewReady from './on-webview-ready'
import onVdSync from './on-vd-sync'
import onVdSyncCallback from './on-vd-sync-callback'
import onInvokeApi from './on-invoke-api'
import onInvokeApi from './on-invoke-api'
import onWebInvokeApi from './on-web-invoke-api'
export function initSubscribeHandlers () {
const {
......@@ -34,6 +36,8 @@ export function initSubscribeHandlers () {
subscribeHandler(data.type, data.data, data.pageId)
})
registerPlusMessage(WEB_INVOKE_APPSERVICE, onWebInvokeApi)
subscribe(WEBVIEW_READY, onWebviewReady)
const entryPagePath = '/' + __uniConfig.entryPagePath
......
export default function onInvokeApi (data) {
// TODO
console.log('onInvokeApi', data)
}
......@@ -12,9 +12,9 @@
</template>
<script>
import {
subscriber,
listeners
subscriber
} from 'uni-mixins'
import native from '../../mixins/native'
const methods = [
'play',
......@@ -60,7 +60,7 @@ const attrs = [
export default {
name: 'Video',
mixins: [subscriber, listeners],
mixins: [subscriber, native],
props: {
id: {
type: String,
......@@ -145,18 +145,6 @@ export default {
default: true
}
},
data () {
return {
style: {
top: '0px',
left: '0px',
width: '0px',
height: '0px',
position: 'static'
},
hidden: false
}
},
computed: {
attrs () {
const obj = {}
......@@ -173,11 +161,7 @@ export default {
this.video && this.video[val ? 'hide' : 'show']()
}
},
listeners: {
'@view-update': '_requestUpdate'
},
mounted () {
this._updateStyle()
const video = this.video = plus.video.createVideoPlayer('video' + Date.now(), Object.assign({}, this.attrs, this.style))
plus.webview.currentWebview().append(video)
if (this.hidden) {
......@@ -217,29 +201,6 @@ export default {
}
this.video && this.video[type](data)
}
},
_updateStyle () {
const rect = this.$refs.container.getBoundingClientRect()
this.hidden = false;
['top', 'left', 'width', 'height'].forEach(key => {
let val = rect[key]
val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val
if (!val && (key === 'width' || key === 'height')) {
this.hidden = true
}
this.style[key] = val + 'px'
})
},
_requestUpdate () {
if (this._animationFrame) {
cancelAnimationFrame(this._animationFrame)
}
if (this.video) {
this._animationFrame = requestAnimationFrame(() => {
delete this._animationFrame
this._updateStyle()
})
}
}
}
}
......
import {
listeners
} from 'uni-mixins'
export default {
name: 'Native',
mixins: [listeners],
data () {
return {
style: {
top: '0px',
left: '0px',
width: '0px',
height: '0px',
position: 'static'
},
hidden: false,
tags: []
}
},
mounted () {
this._updateStyle()
this.$nextTick(() => {
if (this.tags.length) {
const view = this.view = plus.nativeObj.View('view' + Date.now(), this.style, this.tags)
plus.webview.currentWebview().append(view)
if (this.hidden) {
view.hide()
}
}
})
},
beforeDestroy () {
this.view && this.view.close()
delete this.view
},
listeners: {
'@view-update': '_requestUpdate'
},
methods: {
insertTextView () {
},
updateTextView () {
},
removeTextView () {
},
insertImageView () {
},
updateImageView () {
},
removeImageView () {
},
_updateStyle () {
const rect = this.$refs.container.getBoundingClientRect()
this.hidden = false;
['top', 'left', 'width', 'height'].forEach(key => {
let val = rect[key]
val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val
if (!val && (key === 'width' || key === 'height')) {
this.hidden = true
}
this.style[key] = val + 'px'
})
},
_requestUpdate () {
if (this._animationFrame) {
cancelAnimationFrame(this._animationFrame)
}
if (this._isMounted) {
this._animationFrame = requestAnimationFrame(() => {
delete this._animationFrame
this._updateStyle()
})
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册