提交 4045d035 编写于 作者: fxy060608's avatar fxy060608

wip(mp): mp-lark

上级 6ac07c8a
label,scroll-view,swiper-item,view{display:flex;flex-direction:column;flex-shrink:0;flex-grow:0;flex-basis:auto;align-items:stretch;align-content:flex-start}image,input,scroll-view,swiper,swiper-item,text,textarea,video,view{position:relative;border:0 solid #000;box-sizing:border-box}swiper-item{position:absolute}button{margin:0}
\ No newline at end of file
label,
scroll-view,
swiper-item,
view {
display: flex;
flex-direction: column;
flex-shrink: 0;
flex-grow: 0;
flex-basis: auto;
align-items: stretch;
align-content: flex-start;
}
image,
input,
scroll-view,
swiper,
swiper-item,
text,
textarea,
video,
view {
position: relative;
border: 0 solid #000;
box-sizing: border-box;
}
swiper-item {
position: absolute;
}
button {
margin: 0;
}
......@@ -4,6 +4,8 @@ export const EXTNAME_VUE = ['.vue', '.nvue']
export const EXTNAME_VUE_RE = /\.(vue|nvue)$/
export const EXTNAME_JS_RE = /\.[jt]sx?$/
export const ASSETS_INLINE_LIMIT = 40 * 1024
export const BINDING_COMPONENTS = '__BINDING_COMPONENTS__'
// APP 平台解析页面后缀的优先级
export const PAGE_EXTNAME_APP = ['.nvue', '.vue', '.tsx', '.jsx', '.js']
......
......@@ -42,7 +42,7 @@ export const removeInfoFormatter: Formatter = {
return ''
},
}
const REMOVED_WARN_MSGS = ['warnings when minifying css:']
const REMOVED_WARN_MSGS: string[] = []
export const removeWarnFormatter: Formatter = {
test(msg) {
return !!REMOVED_WARN_MSGS.find((m) => msg.includes(m))
......
......@@ -11,6 +11,7 @@ const DEFAULT_KEYS = [
'MP_ALIPAY',
'MP_BAIDU',
'MP_QQ',
'MP_LARK',
'MP_TOUTIAO',
'MP_WEIXIN',
'MP_KUAISHOU',
......
......@@ -438,8 +438,16 @@ function handleEvent(event) {
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......
......@@ -67,7 +67,10 @@ function initHook(
this: CustomAppInstanceProperty | CustomComponentInstanceProperty,
args: unknown
) {
if (__PLATFORM__ === 'mp-toutiao' && hook === 'onError') {
if (
(__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') &&
hook === 'onError'
) {
return getApp().$vm.$callHook(hook, args)
}
return this.$vm && this.$vm.$callHook(hook, args)
......
import { ComponentPropsOptions } from 'vue'
import { onBeforeMount, ComponentPropsOptions } from 'vue'
import { isArray, isPlainObject, isFunction } from '@vue/shared'
import { MPComponentOptions, MPComponentInstance } from './component'
......@@ -8,8 +8,22 @@ const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function createObserver(name: string) {
return function observer(this: MPComponentInstance, newVal: unknown) {
if (this.$vm) {
this.$vm.$.props[name] = newVal // 为了触发其他非 render watcher
const { $vm } = this
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
if (__PLATFORM__ === 'mp-lark') {
if (instance.isMounted) {
instance.props[name] = newVal
} else {
onBeforeMount(() => (instance.props[name] = newVal), instance)
}
} else {
instance.props[name] = newVal
}
}
}
}
......
......@@ -23,7 +23,10 @@ function initHook(
options: Record<string, any>,
isComponent?: boolean
) {
if (__PLATFORM__ === 'mp-toutiao' && isComponent) {
if (
(__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') &&
isComponent
) {
// fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
options = options.lifetimes
}
......
'use strict';
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniCliShared = require('@dcloudio/uni-cli-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -190,7 +190,7 @@ const uniMiniProgramKuaishouPlugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
},
};
},
......
......@@ -438,8 +438,16 @@ function handleEvent(event) {
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......
import { Plugin } from 'vite'
import { ASSETS_INLINE_LIMIT } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin from '@dcloudio/uni-mp-vite'
import { options } from './options'
......@@ -12,7 +12,7 @@ const uniMiniProgramKuaishouPlugin: Plugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: ASSETS_INLINE_LIMIT,
},
}
},
......
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
[
{
"input": {
"src/compiler/index.ts": "dist/uni.compiler.js"
},
"output": {
"format": "cjs"
},
"external": [
"@vue/compiler-core",
"@dcloudio/uni-shared",
"@dcloudio/uni-cli-shared",
"@dcloudio/uni-mp-vite",
"@dcloudio/uni-mp-compiler"
]
},
{
"input": {
"src/runtime/index.ts": "dist/uni.mp.esm.js",
"src/api/index.ts": "dist/uni.api.esm.js"
},
"alias": {
"entries": [
{
"find": "@dcloudio/uni-platform",
"replacement": "packages/uni-mp-lark/src/platform/index.ts"
},
{
"find": "@dcloudio/uni-mp-platform",
"replacement": "packages/uni-mp-core/src/platform/index.ts"
}
]
},
"replacements": {
"__GLOBAL__": "tt",
"__PLATFORM__": "\"mp-lark\"",
"__PLATFORM_TITLE__": "飞书小程序"
},
"external": ["@dcloudio/uni-i18n", "@vue/shared", "vue"]
}
]
此差异已折叠。
'use strict';
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var uniCliShared = require('@dcloudio/uni-cli-shared');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
var compilerCore = require('@vue/compiler-core');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefaultLegacy(initMiniProgramPlugin);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var setting = {
urlCheck: false,
es6: true,
postcss: false,
minified: false,
newFeature: true
};
var appid = "testAppId";
var projectname = "";
var condition = {
miniprogram: {
current: -1
}
};
var source = {
setting: setting,
appid: appid,
projectname: projectname,
condition: condition
};
function transformSwiper(node) {
if (node.type !== 1 /* ELEMENT */ || node.tag !== 'swiper') {
return;
}
const disableTouchProp = compilerCore.findProp(node, 'disable-touch', false, true);
if (!disableTouchProp) {
return;
}
const { props } = node;
if (disableTouchProp.type === 6 /* ATTRIBUTE */) {
// <swiper disable-touch/> => <swiper :touchable="false"/>
props.splice(props.indexOf(disableTouchProp), 1, uniCliShared.createBindDirectiveNode('touchable', 'false'));
}
else {
if (disableTouchProp.exp) {
// <swiper :disable-touch="true"/> => <swiper :touchable="!(true)"/>
let touchable = '';
if (disableTouchProp.exp.type === 4 /* SIMPLE_EXPRESSION */) {
if (disableTouchProp.exp.content === 'true') {
touchable = 'false';
}
else if (disableTouchProp.exp.content === 'false') {
touchable = 'true';
}
}
props.splice(props.indexOf(disableTouchProp), 1, uniCliShared.createBindDirectiveNode('touchable', touchable || `!(${uniMpCompiler.genExpr(disableTouchProp.exp)})`));
}
}
}
const projectConfigFilename = 'project.config.json';
const nodeTransforms = [
uniCliShared.transformRef,
transformSwiper,
uniCliShared.transformMatchMedia,
uniCliShared.transformComponentLink,
];
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
};
const miniProgram = {
class: {
array: false,
},
slot: {
fallbackContent: true,
dynamicSlotNames: true,
},
directive: 'tt:',
};
const options = {
vite: {
inject: {
uni: [path__default["default"].resolve(__dirname, 'uni.api.esm.js'), 'default'],
},
alias: {
'uni-mp-runtime': path__default["default"].resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: ['ttcomponents'],
},
},
global: 'tt',
app: {
darkmode: false,
subpackages: true,
},
project: {
filename: projectConfigFilename,
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
if (filename) {
return `<sjs src="${filename}.sjs" module="${filter.name}"/>`;
}
return `<sjs module="${filter.name}">
${filter.code}
</sjs>`;
},
}, extname: '.ttml', compilerOptions }),
style: {
extname: '.ttss',
},
};
const uniMiniProgramToutiaoPlugin = {
name: 'vite:uni-mp-lark',
config() {
return {
define: {
__VUE_CREATED_DEFERRED__: true,
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
},
};
},
};
options.template.slot.fallbackContent = false;
var index = [uniMiniProgramToutiaoPlugin, ...initMiniProgramPlugin__default["default"](options)];
module.exports = index;
此差异已折叠。
{
"name": "@dcloudio/uni-mp-lark",
"version": "3.0.0-alpha-3021220211102002",
"description": "uni-app mp-lark",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-mp-lark"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "Apache-2.0",
"uni-app": {
"name": "mp-lark",
"title": "飞书小程序",
"apply": "mp-lark",
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
}
import uni from '@dcloudio/uni-mp-toutiao/src/api'
export default uni
import { Plugin } from 'vite'
import initMiniProgramPlugin from '@dcloudio/uni-mp-vite'
import { ASSETS_INLINE_LIMIT } from '@dcloudio/uni-cli-shared'
import { options } from '@dcloudio/uni-mp-toutiao/src/compiler/options'
const uniMiniProgramToutiaoPlugin: Plugin = {
name: 'vite:uni-mp-lark',
config() {
return {
define: {
__VUE_CREATED_DEFERRED__: true,
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: ASSETS_INLINE_LIMIT,
},
}
},
}
options.template.slot.fallbackContent = false
export default [uniMiniProgramToutiaoPlugin, ...initMiniProgramPlugin(options)]
{
"setting": {
"urlCheck": false,
"es6": true,
"postcss": false,
"minified": false,
"newFeature": true
},
"appid": "testAppId",
"projectname": "",
"condition": {
"miniprogram": {
"current": -1
}
}
}
export function getBaseSystemInfo() {
return tt.getSystemInfoSync()
}
import { EventChannel } from '@dcloudio/uni-shared'
import {
initCreateApp,
initCreatePage,
initCreateComponent,
} from '@dcloudio/uni-mp-core'
import '@dcloudio/uni-mp-polyfill'
import * as parsePageOptions from '@dcloudio/uni-mp-toutiao/src/runtime/parsePageOptions'
import * as parseComponentOptions from '@dcloudio/uni-mp-toutiao/src/runtime/parseComponentOptions'
export const createApp = initCreateApp()
export const createPage = initCreatePage(parsePageOptions)
export const createComponent = initCreateComponent(parseComponentOptions)
;(tt as any).EventChannel = EventChannel
;(tt as any).createApp = (global as any).createApp = createApp
;(tt as any).createPage = createPage
;(tt as any).createComponent = createComponent
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": ["packages/uni-mp-lark/src/platform/index.ts"],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
'use strict';
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var fs = require('fs-extra');
var uniShared = require('@dcloudio/uni-shared');
var uniCliShared = require('@dcloudio/uni-cli-shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -158,7 +158,7 @@ const uniMiniProgramQQPlugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
},
};
},
......
......@@ -408,8 +408,16 @@ function findVmByVueId(instance, vuePid) {
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......
import { Plugin } from 'vite'
import { ASSETS_INLINE_LIMIT } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin from '@dcloudio/uni-mp-vite'
import { fix2648 } from './fix2648'
......@@ -14,7 +14,7 @@ const uniMiniProgramQQPlugin: Plugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: ASSETS_INLINE_LIMIT,
},
}
},
......
......@@ -411,8 +411,16 @@ function findVmByVueId(instance, vuePid) {
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......@@ -786,51 +794,47 @@ function initInjections(instance) {
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
const components = [];
function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
function created() {
components.push(this);
}
function attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
// 初始化 vue 实例
const mpInstance = this;
const mpType = isPage(mpInstance) ? 'page' : 'component';
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
}, {
mpType,
mpInstance,
slots: properties.vS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
initMocks(instance, mpInstance, mocks);
initComponentInstance(instance, options);
},
});
// 处理父子关系
initRelation(this, relationOptions);
}
function detached() {
this.$vm && $destroyComponent(this.$vm);
}
return {
created() {
components.push(this);
},
created,
attached() {
this.__lifetimes_attached = function () {
const properties = this.properties;
initVueIds(properties.vI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
// 初始化 vue 实例
const mpInstance = this;
const mpType = isPage(mpInstance) ? 'page' : 'component';
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
this.$vm = $createComponent({
type: vueOptions,
props: properties,
}, {
mpType,
mpInstance,
slots: properties.vS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
initMocks(instance, mpInstance, mocks);
initComponentInstance(instance, options);
},
});
// 处理父子关系
initRelation(this, relationOptions);
attached.call(this);
};
let component = this;
while (component &&
......@@ -843,10 +847,22 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
component = components[0];
}
},
detached() {
this.$vm && $destroyComponent(this.$vm);
},
detached,
};
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const mocks = [
......
......@@ -16,6 +16,8 @@ import {
initComponentInstance,
} from '@dcloudio/uni-mp-core'
const fixAttached = __PLATFORM__ === 'mp-toutiao'
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
const components: MPComponentInstance[] = []
......@@ -25,60 +27,60 @@ export function initLifetimes({
initRelation,
vueOptions,
}: CreateLifetimesOptions) {
return {
created(this: MPComponentInstance) {
components.push(this)
},
attached(this: MPComponentInstance) {
this.__lifetimes_attached = function () {
const properties = this.properties
initVueIds(properties.vI, this)
const relationOptions: RelationOptions = {
vuePid: this._$vuePid,
}
// 初始化 vue 实例
const mpInstance = this
const mpType = isPage(mpInstance) ? 'page' : 'component'
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__
}
function created(this: MPComponentInstance) {
components.push(this)
}
function attached(this: MPComponentInstance) {
const properties = this.properties
initVueIds(properties.vI, this)
const relationOptions: RelationOptions = {
vuePid: this._$vuePid,
}
// 初始化 vue 实例
const mpInstance = this
const mpType = isPage(mpInstance) ? 'page' : 'component'
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__
}
fixProperties(properties)
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined
}
})
this.$vm = $createComponent(
{
type: vueOptions,
props: properties,
},
{
mpType,
mpInstance,
slots: properties.vS, // vueSlots
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(
instance: ComponentInternalInstance,
options: CreateComponentOptions
) {
initRefs(instance, mpInstance)
initMocks(instance, mpInstance, mocks)
initComponentInstance(instance, options)
},
}
) as ComponentPublicInstance
this.$vm = $createComponent(
{
type: vueOptions,
props: properties,
},
{
mpType,
mpInstance,
slots: properties.vS, // vueSlots
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(
instance: ComponentInternalInstance,
options: CreateComponentOptions
) {
initRefs(instance, mpInstance)
initMocks(instance, mpInstance, mocks)
initComponentInstance(instance, options)
},
}
) as ComponentPublicInstance
// 处理父子关系
initRelation(this, relationOptions)
}
// 处理父子关系
initRelation(this, relationOptions)
function detached(this: MPComponentInstance) {
this.$vm && $destroyComponent(this.$vm)
}
if (!fixAttached) {
return { attached, detached }
}
return {
created,
attached(this: MPComponentInstance) {
this.__lifetimes_attached = function () {
attached.call(this)
}
let component = this
while (
......@@ -93,8 +95,21 @@ export function initLifetimes({
component = components[0]
}
},
detached(this: MPComponentInstance) {
this.$vm && $destroyComponent(this.$vm)
},
detached,
}
}
function fixProperties(properties: Record<string, any>) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined
}
})
}
import { hasOwn } from '@vue/shared'
import { ComponentPublicInstance } from 'vue'
import { MPComponentInstance, MPComponentOptions } from '@dcloudio/uni-mp-core'
import { findVmByVueId } from '@dcloudio/uni-mp-core'
......@@ -29,7 +29,8 @@ interface RelationOptions {
webviewId: string
}
export const instances = Object.create(null)
export const instances: Record<string, ComponentPublicInstance> =
Object.create(null)
export function initRelation(mpInstance: MPComponentInstance, detail: Object) {
// 头条 triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
......@@ -37,7 +38,7 @@ export function initRelation(mpInstance: MPComponentInstance, detail: Object) {
? mpInstance.__nodeId__
: mpInstance.__nodeid__
const webviewId = mpInstance.__webviewId__ + ''
instances[webviewId + '_' + nodeId] = mpInstance.$vm
instances[webviewId + '_' + nodeId] = mpInstance.$vm!
mpInstance.triggerEvent('__l', {
vuePid: (detail as any).vuePid,
nodeId,
......@@ -70,7 +71,7 @@ export function handleLink(
if (__VUE_OPTIONS_API__) {
;(parentVm as any).$children.push(vm)
const parent = parentVm.$ as any
vm.$.provides = parent
;(vm.$ as any).provides = parent
? parent.provides
: Object.create(parent.appContext.provides)
initInjections(vm)
......
......@@ -34,8 +34,6 @@ export function buildOptions(): UserConfig['build'] {
// sourcemap: 'inline', // TODO
// target: ['chrome53'], // 由小程序自己启用 es6 编译
emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
// 由各个小程序控制,目前已知百度支持本地路径,其他不支持
// assetsInlineLimit: 0, // 40kb
lib: {
entry: resolveMainPathOnce(inputDir),
formats: ['cjs'],
......
'use strict';
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniCliShared = require('@dcloudio/uni-cli-shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -143,7 +143,7 @@ const uniMiniProgramWeixinPlugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
},
};
},
......
......@@ -353,8 +353,16 @@ function findVmByVueId(instance, vuePid) {
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......
import { Plugin } from 'vite'
import { ASSETS_INLINE_LIMIT } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin from '@dcloudio/uni-mp-vite'
import { options } from './options'
......@@ -12,7 +12,7 @@ const uniMiniProgramWeixinPlugin: Plugin = {
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: 40 * 1024, // 40kb
assetsInlineLimit: ASSETS_INLINE_LIMIT,
},
}
},
......
......@@ -389,8 +389,16 @@ function initRefs(instance, mpInstance) {
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
if (this.$vm) {
this.$vm.$.props[name] = newVal; // 为了触发其他非 render watcher
const { $vm } = this;
if ($vm) {
// 为了触发其他非 render watcher
const instance = $vm.$;
// 飞书小程序初始化太慢,导致 observer 触发时,vue 组件的 created 可能还没触发,此时开发者可能已经定义了 watch
// 但因为 created 还没触发,导致部分组件出错,如 uni-collapse,在 created 中初始化了 this.children
// 自定义 watch 中使用了 this.children
{
instance.props[name] = newVal;
}
}
};
}
......@@ -757,70 +765,57 @@ function initInjections(instance) {
}
}
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
const components = [];
function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
return {
created() {
components.push(this);
},
attached() {
this.__lifetimes_attached = function () {
const properties = this.properties;
initVueIds(properties.vI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
// 初始化 vue 实例
const mpInstance = this;
const mpType = isPage(mpInstance) ? 'page' : 'component';
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
this.$vm = $createComponent({
type: vueOptions,
props: properties,
}, {
mpType,
mpInstance,
slots: properties.vS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
initMocks(instance, mpInstance, mocks);
initComponentInstance(instance, options);
},
});
// 处理父子关系
initRelation(this, relationOptions);
};
let component = this;
while (component &&
component.__lifetimes_attached &&
components[0] &&
component === components[0]) {
components.shift();
component.__lifetimes_attached();
delete component.__lifetimes_attached;
component = components[0];
}
},
detached() {
this.$vm && $destroyComponent(this.$vm);
},
};
function attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
// 初始化 vue 实例
const mpInstance = this;
const mpType = isPage(mpInstance) ? 'page' : 'component';
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
}, {
mpType,
mpInstance,
slots: properties.vS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
initMocks(instance, mpInstance, mocks);
initComponentInstance(instance, options);
},
});
// 处理父子关系
initRelation(this, relationOptions);
}
function detached() {
this.$vm && $destroyComponent(this.$vm);
}
{
return { attached, detached };
}
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const instances = Object.create(null);
......
......@@ -14,6 +14,7 @@ export const PLATFORMS = [
'mp-alipay',
'mp-baidu',
'mp-qq',
'mp-lark',
'mp-toutiao',
'mp-weixin',
'quickapp-webview-huawei',
......
......@@ -25,6 +25,7 @@ export function createCss(
postcss: resolvePostcssConfig(options.inputDir),
preprocessorOptions: {
scss: {
charset: false,
additionalData: resolveAdditionalData(options.inputDir),
},
},
......
......@@ -12,6 +12,7 @@ const priority = {
'uni-mp-baidu': 70,
'uni-mp-kuaishou': 70,
'uni-mp-qq': 70,
'uni-mp-lark': 70,
'uni-mp-toutiao': 70,
'uni-mp-weixin': 70,
'uni-quickapp-webview': 70,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册