diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index f493a59e1a535b35bce5f6d32d08e6375b2d12b9..8ba4b7ed2e2d82f963bf08a4559c5f75fc72f04e 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -946,7 +946,7 @@ var serviceContext = (function (vue) { res.errMsg = normalizeErrMsg$1(res.errMsg, name); isFunction(beforeAll) && beforeAll(res); if (res.errMsg === name + ':ok') { - isFunction(beforeSuccess) && beforeSuccess(res); + isFunction(beforeSuccess) && beforeSuccess(res, args); hasSuccess && success(res); } else { @@ -1767,6 +1767,25 @@ var serviceContext = (function (vue) { useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false); } }); + const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => { + const name = 'uni.setClipboardData.'; + const keys = ['success']; + { + useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Content copied']), false); + } + { + useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Contenido copiado']), false); + } + { + useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Contenu copié']), false); + } + { + useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['内容已复制']), false); + } + { + useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['內容已復制']), false); + } + }); const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => { const name = 'uni.scanCode.'; const keys = ['title', 'album', 'fail', 'flash.on', 'flash.off']; @@ -4477,7 +4496,37 @@ var serviceContext = (function (vue) { const API_ADD_PHONE_CONTACT = 'addPhoneContact'; const API_GET_CLIPBOARD_DATA = 'getClipboardData'; - const API_SET_CLIPBOARD_DATA = 'setClipboardData'; + const API_SET_CLIPBOARD_DATA = 'setClipboardData'; + const SetClipboardDataOptions = { + formatArgs: { + showToast: true, + }, + beforeInvoke() { + initI18nSetClipboardDataMsgsOnce(); + }, + beforeSuccess(res, params) { + if (!params.showToast) + return; + const { t } = useI18n(); + const title = t('uni.setClipboardData.success'); + if (title) { + uni.showToast({ + title: title, + icon: 'success', + mask: false, + }); + } + }, + }; + const SetClipboardDataProtocol = { + data: { + type: String, + required: true, + }, + showToast: { + type: Boolean, + }, + }; const API_ON_ACCELEROMETER = 'onAccelerometer'; const API_OFF_ACCELEROMETER = 'offAccelerometer'; @@ -6802,7 +6851,7 @@ var serviceContext = (function (vue) { const clipboard = requireNativePlugin('clipboard'); clipboard.setString(options.data); resolve(); - }); + }, SetClipboardDataProtocol, SetClipboardDataOptions); const API_ON_NETWORK_STATUS_CHANGE = 'onNetworkStatusChange'; function networkListener() { diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index eeeb58d7e95a2fcde10919510ca55e54fac5ac77..2a2c5d003e71b516d6aafbe8b91916e69b0aa79c 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1128,7 +1128,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = res.errMsg = normalizeErrMsg$1(res.errMsg, name); shared.isFunction(beforeAll) && beforeAll(res); if (res.errMsg === name + ":ok") { - shared.isFunction(beforeSuccess) && beforeSuccess(res); + shared.isFunction(beforeSuccess) && beforeSuccess(res, args); hasSuccess && success(res); } else { hasFail && fail(res); diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 5c71848122c6b593085acbe297c81801759c07ef..16b08e31979c0e5a9dbacff9c1a37c47b4e417c8 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -2407,7 +2407,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = res.errMsg = normalizeErrMsg$1(res.errMsg, name); isFunction(beforeAll) && beforeAll(res); if (res.errMsg === name + ":ok") { - isFunction(beforeSuccess) && beforeSuccess(res); + isFunction(beforeSuccess) && beforeSuccess(res, args); hasSuccess && success(res); } else { hasFail && fail(res); diff --git a/packages/uni-mp-compiler/__tests__/codegen.spec.ts b/packages/uni-mp-compiler/__tests__/codegen.spec.ts index 3f681d15487527a2fd611b6123fcf0d376550441..b8c221595538ae6aceea6dcce55b9b240d8a3b5e 100644 --- a/packages/uni-mp-compiler/__tests__/codegen.spec.ts +++ b/packages/uni-mp-compiler/__tests__/codegen.spec.ts @@ -8,7 +8,7 @@ describe('compiler: codegen', () => { `import { vOn as _vOn, vFor as _vFor } from "vue" export function render(_ctx, _cache) { - return { a: _vFor(_ctx.items, item => { return {}; }), b: _vOn(_ctx.onClick) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) } }`, { inline: false, mode: 'module', prefixIdentifiers: false } ) @@ -21,7 +21,7 @@ export function render(_ctx, _cache) { `import { vOn as _vOn, vFor as _vFor } from "vue" export function render(_ctx, _cache) { - return { a: _vFor(_ctx.items, item => { return {}; }), b: _vOn(_ctx.onClick) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) } }`, { inline: false, mode: 'module' } ) @@ -37,7 +37,7 @@ return function render(_ctx, _cache) { with (_ctx) { const { vOn: _vOn, vFor: _vFor } = _Vue - return { a: _vFor(items, item => { return {}; }), b: _vOn(onClick) } + return { a: _vFor(items, (item, k0, i0) => { return {}; }), b: _vOn(onClick) } } }`, { inline: false, mode: 'function', prefixIdentifiers: false } @@ -50,7 +50,7 @@ return function render(_ctx, _cache) { `const { vOn: _vOn, vFor: _vFor } = Vue return function render(_ctx, _cache) { - return { a: _vFor(_ctx.items, item => { return {}; }), b: _vOn(_ctx.onClick) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) } }`, { inline: false, mode: 'function' } ) diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts index 54190261d63e017d60ec49d238b1e9f531b8a698..8884f419f1aa27cea79178258e23ea86c702a116 100644 --- a/packages/uni-mp-compiler/__tests__/component.spec.ts +++ b/packages/uni-mp-compiler/__tests__/component.spec.ts @@ -2,12 +2,94 @@ import { addComponentBindLink } from '@dcloudio/uni-cli-shared' import { assert } from './testUtils' describe('compiler: transform component', () => { - test('basic', () => { + // test('basic', () => { + // assert( + // ``, + // ``, + // `(_ctx, _cache) => { + // return {} + // }`, + // { + // nodeTransforms: [addComponentBindLink as any], + // } + // ) + // }) + test('component + component', () => { assert( - ``, - ``, + ``, + ``, `(_ctx, _cache) => { return {} +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + }) + test('component + component + component', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return {} +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + }) + test('component with v-for', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) } +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _vFor(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) } +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + }) + test('component + component with v-for', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) } +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + }) + test('component with v-for + component', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) } +}`, + { + nodeTransforms: [addComponentBindLink as any], + } + ) + }) + test('component with v-for + component with v-for', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _vFor(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) } }`, { nodeTransforms: [addComponentBindLink as any], diff --git a/packages/uni-mp-compiler/__tests__/ref.spec.ts b/packages/uni-mp-compiler/__tests__/ref.spec.ts index 55d1432d9f0556aa7a89d9ab134099d590bab868..2022c5be2ebcb87c50de525b5ca9410af4250c13 100644 --- a/packages/uni-mp-compiler/__tests__/ref.spec.ts +++ b/packages/uni-mp-compiler/__tests__/ref.spec.ts @@ -4,14 +4,14 @@ describe('compiler: transform ref', () => { test('vue-ref', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { return {} }` ) assert( - ``, - ``, + ``, + ``, `(_ctx, _cache) => { return {} }` @@ -20,16 +20,16 @@ describe('compiler: transform ref', () => { test('vue-ref-in-for', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) } }` ) }) test('static ref', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { return {} }` @@ -38,7 +38,7 @@ describe('compiler: transform ref', () => { test('dynamic ref', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { return { a: _ctx.custom } }` diff --git a/packages/uni-mp-compiler/__tests__/scope.spec.ts b/packages/uni-mp-compiler/__tests__/scope.spec.ts index fb225d0a4f9aaa2ebcbb2ffcea684d731c70d457..5232b715d0b1a090766850722eb9827e83b8591c 100644 --- a/packages/uni-mp-compiler/__tests__/scope.spec.ts +++ b/packages/uni-mp-compiler/__tests__/scope.spec.ts @@ -6,7 +6,7 @@ describe('compiler: scope', () => { `{{item.title}}`, `{{item.a}}`, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) } }` ) }) @@ -15,21 +15,21 @@ describe('compiler: scope', () => { `{{item.title}}{{handle(foo)}}{{item.id}}{{item1.title}}`, `{{item.a}}{{b}}{{item.c}}{{item1.a}}`, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return { a: _toDisplayString(item.title), b: _vFor(item.list, item1 => { return { a: _toDisplayString(item1.title), b: item1.id, c: _vOn($event => _ctx.longpress(item1)) }; }), c: _toDisplayString(item.id), d: _vOn($event => _ctx.onClick(item)), e: item.id }; }), b: _toDisplayString(_ctx.handle(_ctx.foo)) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: _vFor(item.list, (item1, k1, i1) => { return { a: _toDisplayString(item1.title), b: item1.id, c: _vOn($event => _ctx.longpress(item1)) }; }), c: _toDisplayString(item.id), d: _vOn($event => _ctx.onClick(item)), e: item.id }; }), b: _toDisplayString(_ctx.handle(_ctx.foo)) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return { a: item.id }; }), b: _vFor(_ctx.item1, item1 => { return { a: item1.title }; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id }; }), b: _vFor(_ctx.item1, (item1, k1, i1) => { return { a: item1.title }; }) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.weeks, (item, weekIndex) => { return { a: _vFor(item, (weeks, weeksIndex) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) } + return { a: _vFor(_ctx.weeks, (item, weekIndex, i0) => { return { a: _vFor(item, (weeks, weeksIndex, i1) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) } }` ) }) @@ -38,7 +38,7 @@ describe('compiler: scope', () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return { ...(true ? { a: _ctx.id } : {}) }; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { ...(true ? { a: _ctx.id } : {}) }; }) } }` ) }) @@ -56,7 +56,7 @@ describe('compiler: scope', () => { ``, ``, `(_ctx, _cache) => { - return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.items, item => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _vOn(_ctx.onClick) } : _ctx.ok1 ? { f: _vFor(_ctx.items, item => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _vOn(_ctx.onClick) } : { i: _vFor(_ctx.items, item => { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _vOn(_ctx.onClick) }), e: _ctx.ok1 } + return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _vOn(_ctx.onClick) } : _ctx.ok1 ? { f: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _vOn(_ctx.onClick) } : { i: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _vOn(_ctx.onClick) }), e: _ctx.ok1 } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts index 57fa2747d9854538020b4dc218cce986d2362f37..9e226c073503608fd1b723f353cedcc1e21d4f56 100644 --- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts +++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts @@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(5, index => { return {}; }) } + return { a: _vFor(5, (index, k0, i0) => { return {}; }) } }` ) }) @@ -38,7 +38,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -47,7 +47,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, ({ id, value }) => { return {}; }) } + return { a: _vFor(_ctx.items, ({ id, value }, k0, i0) => { return {}; }) } }` ) }) @@ -56,7 +56,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, ([id, value]) => { return {}; }) } + return { a: _vFor(_ctx.items, ([id, value], k0, i0) => { return {}; }) } }` ) }) @@ -65,7 +65,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (item, key) => { return {}; }) } + return { a: _vFor(_ctx.items, (item, key, i0) => { return {}; }) } }` ) }) @@ -83,7 +83,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (value, __, index) => { return {}; }) } + return { a: _vFor(_ctx.items, (value, k0, index) => { return {}; }) } }` ) }) @@ -92,7 +92,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (_, __, index) => { return {}; }) } + return { a: _vFor(_ctx.items, (v0, k0, index) => { return {}; }) } }` ) }) @@ -101,7 +101,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -110,7 +110,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (item, key) => { return {}; }) } + return { a: _vFor(_ctx.items, (item, key, i0) => { return {}; }) } }` ) }) @@ -128,7 +128,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (value, __, index) => { return {}; }) } + return { a: _vFor(_ctx.items, (value, k0, index) => { return {}; }) } }` ) }) @@ -137,7 +137,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, (_, __, index) => { return {}; }) } + return { a: _vFor(_ctx.items, (v0, k0, index) => { return {}; }) } }` ) }) @@ -146,7 +146,7 @@ describe(`compiler: v-for`, () => { ``, `hello`, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -155,7 +155,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -165,7 +165,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return { a: item.id, b: item.id }; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.id }; }) } }` ) }) @@ -174,7 +174,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -183,7 +183,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -192,7 +192,7 @@ describe(`compiler: v-for`, () => { ``, `hello`, `(_ctx, _cache) => { - return { a: _vFor(_ctx.items, item => { return {}; }) } + return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) } }` ) }) @@ -201,7 +201,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_ctx, _cache) => { - return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list, i => { return {}; }) } : {}) } + return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list, (i, k0, i0) => { return {}; }) } : {}) } }` ) }) @@ -211,7 +211,7 @@ describe(`compiler: v-for`, () => { `