@mpxjs/core 2.8.39 → 2.8.40-test
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +54 -26
- package/@types/node.d.ts +10 -8
- package/package.json +4 -4
- package/src/core/injectMixins.js +1 -1
- package/src/core/proxy.js +25 -7
- package/src/index.js +7 -1
- package/src/observer/effect.js +3 -1
- package/src/platform/builtInMixins/pageRouteMixin.js +13 -0
- package/src/platform/builtInMixins/proxyEventMixin.js +5 -10
- package/src/platform/builtInMixins/proxyEventMixin.web.js +0 -5
- package/src/platform/builtInMixins/refsMixin.web.js +4 -4
- package/src/platform/builtInMixins/renderHelperMixin.js +12 -1
- package/src/platform/export/index.web.js +59 -22
- package/src/platform/patch/ali/getDefaultOptions.js +9 -11
- package/src/platform/patch/wx/getDefaultOptions.js +9 -11
- package/src/vuePlugin.js +33 -6
package/@types/index.d.ts
CHANGED
|
@@ -31,18 +31,22 @@ type ArrayType<T extends any[]> = T extends Array<infer R> ? R : never;
|
|
|
31
31
|
// Mpx types
|
|
32
32
|
type Data = object | (() => object)
|
|
33
33
|
|
|
34
|
-
type
|
|
34
|
+
type PropConstructor<T = any> = {
|
|
35
|
+
new (...args: any[]): T & {};
|
|
36
|
+
} | {
|
|
37
|
+
(): T;
|
|
38
|
+
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
type: PropType
|
|
38
|
-
optionalTypes?: Array<PropType>
|
|
39
|
-
value?: any
|
|
40
|
+
export type PropType<T> = PropConstructor<T>
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
type FullPropType<T> = {
|
|
43
|
+
type: PropType<T>;
|
|
44
|
+
value?: T;
|
|
45
|
+
optionalTypes?: PropType<T>[];
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
interface Properties {
|
|
45
|
-
[key: string]:
|
|
49
|
+
[key: string]: WechatMiniprogram.Component.AllProperty
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
interface Methods {
|
|
@@ -79,7 +83,11 @@ type PropValueType<Def> = Def extends {
|
|
|
79
83
|
? T
|
|
80
84
|
: Def extends (...args: any[]) => infer T
|
|
81
85
|
? T
|
|
82
|
-
:
|
|
86
|
+
: Def extends FullPropType<infer T>
|
|
87
|
+
? T
|
|
88
|
+
: Def extends PropType<infer T>
|
|
89
|
+
? T
|
|
90
|
+
: any;
|
|
83
91
|
|
|
84
92
|
type GetPropsType<T> = {
|
|
85
93
|
readonly [K in keyof T]: PropValueType<T[K]>
|
|
@@ -96,6 +104,7 @@ interface Mixin<D, P, C, M> {
|
|
|
96
104
|
properties?: P
|
|
97
105
|
computed?: C
|
|
98
106
|
methods?: M
|
|
107
|
+
|
|
99
108
|
[index: string]: any
|
|
100
109
|
}
|
|
101
110
|
|
|
@@ -108,14 +117,16 @@ interface Context {
|
|
|
108
117
|
triggerEvent: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['triggerEvent']
|
|
109
118
|
refs: ObjectOf<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>
|
|
110
119
|
asyncRefs: ObjectOf<Promise<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>>
|
|
120
|
+
|
|
111
121
|
forceUpdate (params?: object, callback?: () => void): void
|
|
122
|
+
|
|
112
123
|
selectComponent: ReplaceWxComponentIns['selectComponent']
|
|
113
124
|
selectAllComponents: ReplaceWxComponentIns['selectAllComponents']
|
|
114
125
|
createSelectorQuery: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createSelectorQuery']
|
|
115
126
|
createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver']
|
|
116
127
|
}
|
|
117
128
|
|
|
118
|
-
interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption>{
|
|
129
|
+
interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption> {
|
|
119
130
|
data?: D
|
|
120
131
|
properties?: P
|
|
121
132
|
computed?: C
|
|
@@ -137,11 +148,11 @@ type PageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> =
|
|
|
137
148
|
ComponentOpt<D, P, C, M, Mi, S>
|
|
138
149
|
& Partial<WechatMiniprogram.Page.ILifetime>
|
|
139
150
|
|
|
140
|
-
type ThisTypedPageOpt<D extends
|
|
151
|
+
type ThisTypedPageOpt<D extends Data, P extends Properties, C, M extends Methods, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
141
152
|
PageOpt<D, P, C, M, Mi, S>
|
|
142
153
|
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
143
154
|
|
|
144
|
-
type ThisTypedComponentOpt<D extends
|
|
155
|
+
type ThisTypedComponentOpt<D extends Data, P extends Properties, C, M extends Methods, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
145
156
|
ComponentOpt<D, P, C, M, Mi, S>
|
|
146
157
|
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
147
158
|
|
|
@@ -169,13 +180,17 @@ type MpxComProps<O> = { $rawOptions: O }
|
|
|
169
180
|
|
|
170
181
|
export interface MpxComponentIns {
|
|
171
182
|
$refs: ObjectOf<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>
|
|
172
|
-
$asyncRefs
|
|
183
|
+
$asyncRefs: ObjectOf<Promise<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>>
|
|
173
184
|
$set: typeof set
|
|
174
185
|
$remove: typeof del
|
|
175
186
|
$delete: typeof del
|
|
187
|
+
|
|
176
188
|
$watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
|
|
189
|
+
|
|
177
190
|
$forceUpdate (params?: object, callback?: () => void): void
|
|
191
|
+
|
|
178
192
|
$nextTick (fn: () => void): void
|
|
193
|
+
|
|
179
194
|
$i18n: {
|
|
180
195
|
locale: string
|
|
181
196
|
fallbackLocale: string
|
|
@@ -184,6 +199,7 @@ export interface MpxComponentIns {
|
|
|
184
199
|
$tc: typeof tc
|
|
185
200
|
$te: typeof te
|
|
186
201
|
$tm: typeof tm
|
|
202
|
+
|
|
187
203
|
[k: string]: any
|
|
188
204
|
}
|
|
189
205
|
|
|
@@ -193,17 +209,16 @@ interface ReplaceWxComponentIns {
|
|
|
193
209
|
selectAllComponents (selector: string): Array<ComponentIns<{}, {}, {}, {}, []>>
|
|
194
210
|
}
|
|
195
211
|
|
|
196
|
-
type WxComponentIns<D extends
|
|
197
|
-
|
|
198
|
-
&
|
|
199
|
-
& WechatMiniprogram.Component.InstanceMethods<D>
|
|
212
|
+
type WxComponentIns<D extends Data = {}, P extends Properties = {}, M extends Methods = {}> =
|
|
213
|
+
Omit<WechatMiniprogram.Component.Instance<D, P, M>, 'selectComponent' | 'selectAllComponents'>
|
|
214
|
+
& ReplaceWxComponentIns
|
|
200
215
|
|
|
201
|
-
type ComponentIns<D extends
|
|
216
|
+
type ComponentIns<D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], S extends Record<any, any> = {}, O = {}> =
|
|
202
217
|
GetDataType<D> & UnboxMixinsField<Mi, 'data'> &
|
|
203
218
|
M & UnboxMixinsField<Mi, 'methods'> & { [K in keyof S]: S[K] extends Ref<infer V> ? V : S[K] } &
|
|
204
219
|
GetPropsType<P & UnboxMixinsField<Mi, 'properties'>> &
|
|
205
220
|
GetComputedType<C & UnboxMixinsField<Mi, 'computed'>> &
|
|
206
|
-
WxComponentIns<D> & MpxComponentIns & MpxComProps<O>
|
|
221
|
+
WxComponentIns<D, P, M> & MpxComponentIns & MpxComProps<O>
|
|
207
222
|
|
|
208
223
|
interface CreateConfig {
|
|
209
224
|
customCtor: any
|
|
@@ -225,7 +240,10 @@ export function createApp<T extends WechatMiniprogram.IAnyObject> (opt: WechatMi
|
|
|
225
240
|
|
|
226
241
|
type MixinType = 'app' | 'page' | 'component'
|
|
227
242
|
|
|
228
|
-
export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | {
|
|
243
|
+
export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | {
|
|
244
|
+
types?: MixinType | MixinType[],
|
|
245
|
+
stage?: number
|
|
246
|
+
}): Mpx
|
|
229
247
|
|
|
230
248
|
// export function watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
|
|
231
249
|
|
|
@@ -235,6 +253,11 @@ interface AnyConstructor {
|
|
|
235
253
|
prototype: any
|
|
236
254
|
}
|
|
237
255
|
|
|
256
|
+
interface WebviewConfig {
|
|
257
|
+
hostWhitelists?: Array<string>
|
|
258
|
+
apiImplementations?: object
|
|
259
|
+
}
|
|
260
|
+
|
|
238
261
|
interface MpxConfig {
|
|
239
262
|
useStrictDiff: boolean
|
|
240
263
|
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
|
|
@@ -244,7 +267,8 @@ interface MpxConfig {
|
|
|
244
267
|
proxyEventHandler: (e: Event) => any | null
|
|
245
268
|
setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => any | null
|
|
246
269
|
forceFlushSync: boolean,
|
|
247
|
-
webRouteConfig: object
|
|
270
|
+
webRouteConfig: object,
|
|
271
|
+
webviewConfig?: WebviewConfig
|
|
248
272
|
}
|
|
249
273
|
|
|
250
274
|
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
|
|
@@ -318,7 +342,7 @@ export interface Ref<T = any> {
|
|
|
318
342
|
* We need this to be in public d.ts but don't want it to show up in IDE
|
|
319
343
|
* autocomplete, so we use a private Symbol instead.
|
|
320
344
|
*/
|
|
321
|
-
|
|
345
|
+
[RefSymbol]: true
|
|
322
346
|
}
|
|
323
347
|
|
|
324
348
|
type CollectionTypes = IterableCollections | WeakCollections
|
|
@@ -427,7 +451,11 @@ export interface WatchOptions extends WatchEffectOptions {
|
|
|
427
451
|
|
|
428
452
|
interface EffectScope {
|
|
429
453
|
run<T> (fn: () => T): T | undefined // 如果作用域不活跃就为 undefined
|
|
430
|
-
stop (): void
|
|
454
|
+
stop (fromParent?: boolean): void
|
|
455
|
+
|
|
456
|
+
pause (): void
|
|
457
|
+
|
|
458
|
+
resume (ignoreDirty?: boolean): void
|
|
431
459
|
}
|
|
432
460
|
|
|
433
461
|
|
|
@@ -486,7 +514,7 @@ export function reactive<T extends object> (target: T): Reactive<T>
|
|
|
486
514
|
|
|
487
515
|
export function isReactive (value: unknown): boolean
|
|
488
516
|
|
|
489
|
-
export function markRaw<T extends object>(value: T): T
|
|
517
|
+
export function markRaw<T extends object> (value: T): T
|
|
490
518
|
|
|
491
519
|
export function shallowReactive<T extends object> (target: T): ShallowReactive<T>
|
|
492
520
|
|
|
@@ -566,6 +594,7 @@ export function onBeforeUnmount (callback: () => void): void
|
|
|
566
594
|
export function onUnmounted (callback: () => void): void
|
|
567
595
|
|
|
568
596
|
export function onLoad<T extends Record<string, string | undefined>> (callback: (query: T) => void): void
|
|
597
|
+
|
|
569
598
|
// wechat dose not have generics
|
|
570
599
|
// export function onLoad (callback: WechatMiniprogram.Page.ILifetime['onLoad']): void
|
|
571
600
|
|
|
@@ -592,7 +621,7 @@ export function onTabItemTap (callback: WechatMiniprogram.Page.ILifetime['onTabI
|
|
|
592
621
|
export function onSaveExitState (callback: () => void): void
|
|
593
622
|
|
|
594
623
|
// get instance
|
|
595
|
-
export function getCurrentInstance<T extends
|
|
624
|
+
export function getCurrentInstance<T extends ComponentIns<{}, {}, {}>> (): { proxy: T, [x: string]: any }
|
|
596
625
|
|
|
597
626
|
// I18n
|
|
598
627
|
export function useI18n<Options extends {
|
|
@@ -612,8 +641,7 @@ type InferDefaults<T> = {
|
|
|
612
641
|
[K in keyof T]?: InferDefault<T, NotUndefined<T[K]>>
|
|
613
642
|
}
|
|
614
643
|
|
|
615
|
-
type InferDefault<P, T> = T extends
|
|
616
|
-
| null
|
|
644
|
+
type InferDefault<P, T> = T extends | null
|
|
617
645
|
| number
|
|
618
646
|
| string
|
|
619
647
|
| boolean
|
package/@types/node.d.ts
CHANGED
|
@@ -12,19 +12,21 @@ declare let process: {
|
|
|
12
12
|
env: EnvType
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
declare namespace __WebpackModuleApi {
|
|
17
16
|
interface RequireContext {
|
|
18
|
-
keys(): string[];
|
|
17
|
+
keys (): string[];
|
|
18
|
+
|
|
19
19
|
(id: string): any;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
|
|
21
|
+
<T> (id: string): T;
|
|
22
|
+
|
|
23
|
+
resolve (id: string): string;
|
|
24
|
+
|
|
22
25
|
/** The module id of the context module. This may be useful for module.hot.accept. */
|
|
23
26
|
id: string;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export function async<T>(path: string): Promise<T>
|
|
30
|
+
interface Require {
|
|
31
|
+
context (path: string, deep?: boolean, filter?: RegExp, mode?: 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once'): __WebpackModuleApi.RequireContext
|
|
30
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.40-test",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.8.
|
|
22
|
+
"@mpxjs/utils": "^2.8.40-test",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
|
-
"miniprogram-api-typings": "^3.0
|
|
24
|
+
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@mpxjs/api-proxy": "^2.7.44",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
48
|
},
|
|
49
49
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "8524f9b69ebcfb0667ebff2608cf6f675f14f141"
|
|
51
51
|
}
|
package/src/core/injectMixins.js
CHANGED
package/src/core/proxy.js
CHANGED
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
getFirstKey,
|
|
27
27
|
callWithErrorHandling,
|
|
28
28
|
warn,
|
|
29
|
-
error
|
|
29
|
+
error,
|
|
30
|
+
getEnvObj
|
|
30
31
|
} from '@mpxjs/utils'
|
|
31
32
|
import {
|
|
32
33
|
BEFORECREATE,
|
|
@@ -45,6 +46,8 @@ import {
|
|
|
45
46
|
|
|
46
47
|
let uid = 0
|
|
47
48
|
|
|
49
|
+
const envObj = getEnvObj()
|
|
50
|
+
|
|
48
51
|
class RenderTask {
|
|
49
52
|
resolved = false
|
|
50
53
|
|
|
@@ -235,14 +238,14 @@ export default class MpxProxy {
|
|
|
235
238
|
const setupResult = callWithErrorHandling(setup, this, 'setup function', [
|
|
236
239
|
this.props,
|
|
237
240
|
{
|
|
238
|
-
triggerEvent: this.target.triggerEvent.bind(this.target),
|
|
241
|
+
triggerEvent: this.target.triggerEvent ? this.target.triggerEvent.bind(this.target) : noop,
|
|
239
242
|
refs: this.target.$refs,
|
|
240
243
|
asyncRefs: this.target.$asyncRefs,
|
|
241
244
|
forceUpdate: this.forceUpdate.bind(this),
|
|
242
245
|
selectComponent: this.target.selectComponent.bind(this.target),
|
|
243
246
|
selectAllComponents: this.target.selectAllComponents.bind(this.target),
|
|
244
|
-
createSelectorQuery: this.target.createSelectorQuery.bind(this.target),
|
|
245
|
-
createIntersectionObserver: this.target.createIntersectionObserver.bind(this.target)
|
|
247
|
+
createSelectorQuery: this.target.createSelectorQuery ? this.target.createSelectorQuery.bind(this.target) : envObj.createSelectorQuery.bind(envObj),
|
|
248
|
+
createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj)
|
|
246
249
|
}
|
|
247
250
|
])
|
|
248
251
|
if (!isObject(setupResult)) {
|
|
@@ -308,7 +311,16 @@ export default class MpxProxy {
|
|
|
308
311
|
watch (source, cb, options) {
|
|
309
312
|
const target = this.target
|
|
310
313
|
const getter = isString(source)
|
|
311
|
-
? () =>
|
|
314
|
+
? () => {
|
|
315
|
+
// for watch multi path string like 'a.b,c,d'
|
|
316
|
+
if (source.indexOf(',') > -1) {
|
|
317
|
+
return source.split(',').map(path => {
|
|
318
|
+
return getByPath(target, path.trim())
|
|
319
|
+
})
|
|
320
|
+
} else {
|
|
321
|
+
return getByPath(target, source)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
312
324
|
: source.bind(target)
|
|
313
325
|
|
|
314
326
|
if (isObject(cb)) {
|
|
@@ -526,6 +538,10 @@ export default class MpxProxy {
|
|
|
526
538
|
initRender () {
|
|
527
539
|
if (this.options.__nativeRender__) return this.doRender()
|
|
528
540
|
|
|
541
|
+
const _i = this.target._i.bind(this.target)
|
|
542
|
+
const _c = this.target._c.bind(this.target)
|
|
543
|
+
const _r = this.target._r.bind(this.target)
|
|
544
|
+
const _sc = this.target._sc.bind(this.target)
|
|
529
545
|
const effect = this.effect = new ReactiveEffect(() => {
|
|
530
546
|
// pre render for props update
|
|
531
547
|
if (this.propsUpdatedFlag) {
|
|
@@ -534,7 +550,7 @@ export default class MpxProxy {
|
|
|
534
550
|
|
|
535
551
|
if (this.target.__injectedRender) {
|
|
536
552
|
try {
|
|
537
|
-
return this.target.__injectedRender()
|
|
553
|
+
return this.target.__injectedRender(_i, _c, _r, _sc)
|
|
538
554
|
} catch (e) {
|
|
539
555
|
warn('Failed to execute render function, degrade to full-set-data mode.', this.options.mpxFileResource, e)
|
|
540
556
|
this.render()
|
|
@@ -604,7 +620,9 @@ export default class MpxProxy {
|
|
|
604
620
|
|
|
605
621
|
export let currentInstance = null
|
|
606
622
|
|
|
607
|
-
export const getCurrentInstance = () =>
|
|
623
|
+
export const getCurrentInstance = () => {
|
|
624
|
+
return currentInstance && { proxy: currentInstance?.target }
|
|
625
|
+
}
|
|
608
626
|
|
|
609
627
|
export const setCurrentInstance = (instance) => {
|
|
610
628
|
currentInstance = instance
|
package/src/index.js
CHANGED
|
@@ -135,7 +135,13 @@ Mpx.config = {
|
|
|
135
135
|
proxyEventHandler: null,
|
|
136
136
|
setDataHandler: null,
|
|
137
137
|
forceFlushSync: false,
|
|
138
|
-
webRouteConfig: {}
|
|
138
|
+
webRouteConfig: {},
|
|
139
|
+
/*
|
|
140
|
+
支持两个属性
|
|
141
|
+
hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
142
|
+
apiImplementations webview JSSDK接口 例如getlocation
|
|
143
|
+
*/
|
|
144
|
+
webviewConfig: {}
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
global.__mpx = Mpx
|
package/src/observer/effect.js
CHANGED
|
@@ -4,6 +4,19 @@ export default function pageRouteMixin (mixinType) {
|
|
|
4
4
|
return {
|
|
5
5
|
beforeCreate () {
|
|
6
6
|
this.route = this.$options.__mpxPageRoute || ''
|
|
7
|
+
},
|
|
8
|
+
methods: {
|
|
9
|
+
getOpenerEventChannel () {
|
|
10
|
+
const router = global.__mpxRouter
|
|
11
|
+
const eventChannel = router && router.eventChannelMap[this.route]
|
|
12
|
+
return eventChannel || {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
methods: {
|
|
19
|
+
getOpenerEventChannel () {
|
|
7
20
|
}
|
|
8
21
|
}
|
|
9
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setByPath, error, hasOwn } from '@mpxjs/utils'
|
|
1
|
+
import { setByPath, error, hasOwn, dash2hump } from '@mpxjs/utils'
|
|
2
2
|
import Mpx from '../../index'
|
|
3
3
|
|
|
4
4
|
const datasetReg = /^data-(.+)$/
|
|
@@ -36,6 +36,8 @@ export default function proxyEventMixin () {
|
|
|
36
36
|
if (type === 'begin' || type === 'end') {
|
|
37
37
|
// 地图的 regionchange 事件会派发 e.type 为 begin 和 end 的事件
|
|
38
38
|
fallbackType = 'regionchange'
|
|
39
|
+
} else if (/-([a-z])/.test(type)) {
|
|
40
|
+
fallbackType = dash2hump(type)
|
|
39
41
|
} else if (__mpx_mode__ === 'ali') {
|
|
40
42
|
fallbackType = type.replace(/^./, i => i.toLowerCase())
|
|
41
43
|
}
|
|
@@ -99,15 +101,8 @@ export default function proxyEventMixin () {
|
|
|
99
101
|
const eventObj = {
|
|
100
102
|
type: eventName,
|
|
101
103
|
timeStamp,
|
|
102
|
-
target: {
|
|
103
|
-
|
|
104
|
-
dataset,
|
|
105
|
-
targetDataset: dataset
|
|
106
|
-
},
|
|
107
|
-
currentTarget: {
|
|
108
|
-
id,
|
|
109
|
-
dataset
|
|
110
|
-
},
|
|
104
|
+
target: { id, dataset, targetDataset: dataset },
|
|
105
|
+
currentTarget: { id, dataset },
|
|
111
106
|
detail: eventDetail
|
|
112
107
|
}
|
|
113
108
|
handler.call(this, eventObj)
|
|
@@ -18,11 +18,6 @@ export default function proxyEventMixin () {
|
|
|
18
18
|
const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
|
|
19
19
|
const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
|
|
20
20
|
setByPath(this, expr, value)
|
|
21
|
-
},
|
|
22
|
-
getOpenerEventChannel () {
|
|
23
|
-
const router = global.__mpxRouter
|
|
24
|
-
const eventChannel = router && router.__mpxAction && router.__mpxAction.eventChannel
|
|
25
|
-
return eventChannel
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BEFOREMOUNT, UPDATED } from '../../core/innerLifecycle'
|
|
2
|
-
import
|
|
2
|
+
import { createSelectorQuery } from '@mpxjs/api-proxy'
|
|
3
3
|
|
|
4
4
|
function getEl (ref) {
|
|
5
5
|
if (ref && ref.nodeType === 1) return ref
|
|
@@ -8,19 +8,19 @@ function getEl (ref) {
|
|
|
8
8
|
|
|
9
9
|
function processRefs (refs) {
|
|
10
10
|
Object.keys(refs).forEach((key) => {
|
|
11
|
-
const matched = /^__mpx_ref_(
|
|
11
|
+
const matched = /^__mpx_ref_(.+)__$/.exec(key)
|
|
12
12
|
const rKey = matched && matched[1]
|
|
13
13
|
if (rKey) {
|
|
14
14
|
const ref = refs[key]
|
|
15
15
|
if (Array.isArray(ref)) {
|
|
16
16
|
if (getEl(ref[0])) {
|
|
17
|
-
refs[rKey] =
|
|
17
|
+
refs[rKey] = createSelectorQuery().in(this).selectAll(ref.map(getEl))
|
|
18
18
|
} else {
|
|
19
19
|
refs[rKey] = ref
|
|
20
20
|
}
|
|
21
21
|
} else {
|
|
22
22
|
if (getEl(ref)) {
|
|
23
|
-
refs[rKey] =
|
|
23
|
+
refs[rKey] = createSelectorQuery().in(this).select(getEl(ref))
|
|
24
24
|
} else {
|
|
25
25
|
refs[rKey] = ref
|
|
26
26
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject } from '@mpxjs/utils'
|
|
1
|
+
import { getByPath, hasOwn, isObject } from '@mpxjs/utils'
|
|
2
2
|
|
|
3
3
|
export default function renderHelperMixin () {
|
|
4
4
|
return {
|
|
@@ -21,10 +21,21 @@ export default function renderHelperMixin () {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
+
// collect
|
|
24
25
|
_c (key, value) {
|
|
26
|
+
if (hasOwn(this.__mpxProxy.renderData, key)) {
|
|
27
|
+
return this.__mpxProxy.renderData[key]
|
|
28
|
+
}
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
value = getByPath(this, key)
|
|
31
|
+
}
|
|
25
32
|
this.__mpxProxy.renderData[key] = value
|
|
26
33
|
return value
|
|
27
34
|
},
|
|
35
|
+
// simple collect
|
|
36
|
+
_sc (key) {
|
|
37
|
+
return (this.__mpxProxy.renderData[key] = this[key])
|
|
38
|
+
},
|
|
28
39
|
_r () {
|
|
29
40
|
this.__mpxProxy.renderWithData()
|
|
30
41
|
}
|
|
@@ -1,8 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { EffectScope } from 'vue'
|
|
2
|
+
import { hasOwn } from '@mpxjs/utils'
|
|
3
|
+
import { PausedState } from '../../helper/const'
|
|
4
|
+
|
|
5
|
+
const hackEffectScope = () => {
|
|
6
|
+
EffectScope.prototype.pause = function () {
|
|
7
|
+
if (this.active) {
|
|
8
|
+
let i, l
|
|
9
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
10
|
+
const effect = this.effects[i]
|
|
11
|
+
// vue2.7中存在对于watcher实例方法的重写(doWatch),因此无法通过修改Watcher.prototype统一实现pause和resume,只能逐个实例修改实现
|
|
12
|
+
if (!hasOwn(effect, 'pausedState')) {
|
|
13
|
+
effect.pausedState = PausedState.resumed
|
|
14
|
+
const rawUpdate = effect.update
|
|
15
|
+
effect.update = function () {
|
|
16
|
+
if (effect.pausedState !== PausedState.resumed) {
|
|
17
|
+
effect.pausedState = PausedState.dirty
|
|
18
|
+
} else {
|
|
19
|
+
rawUpdate.call(effect)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (effect.pausedState !== PausedState.dirty) {
|
|
24
|
+
effect.pausedState = PausedState.paused
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (this.scopes) {
|
|
28
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
29
|
+
this.scopes[i].pause()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
EffectScope.prototype.resume = function (ignoreDirty = false) {
|
|
36
|
+
if (this.active) {
|
|
37
|
+
let i, l
|
|
38
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
39
|
+
const effect = this.effects[i]
|
|
40
|
+
if (hasOwn(effect, 'pausedState')) {
|
|
41
|
+
const lastPausedState = effect.pausedState
|
|
42
|
+
effect.pausedState = PausedState.resumed
|
|
43
|
+
if (!ignoreDirty && lastPausedState === PausedState.dirty) {
|
|
44
|
+
effect.update()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (this.scopes) {
|
|
49
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
50
|
+
this.scopes[i].resume(ignoreDirty)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
hackEffectScope()
|
|
6
58
|
|
|
7
59
|
export {
|
|
8
60
|
// watch
|
|
@@ -29,27 +81,12 @@ export {
|
|
|
29
81
|
// computed
|
|
30
82
|
computed,
|
|
31
83
|
// instance
|
|
32
|
-
getCurrentInstance
|
|
33
|
-
} from 'vue'
|
|
34
|
-
|
|
35
|
-
const noop = () => {
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const fixEffectScope = (scope) => {
|
|
39
|
-
scope.pause = noop
|
|
40
|
-
scope.resume = noop
|
|
41
|
-
return scope
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
|
|
45
|
-
const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
|
|
46
|
-
|
|
47
|
-
export {
|
|
84
|
+
getCurrentInstance,
|
|
48
85
|
// effectScope
|
|
49
86
|
effectScope,
|
|
50
87
|
getCurrentScope,
|
|
51
88
|
onScopeDispose
|
|
52
|
-
}
|
|
89
|
+
} from 'vue'
|
|
53
90
|
|
|
54
91
|
export {
|
|
55
92
|
// i18n
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import MpxProxy from '../../../core/proxy'
|
|
2
2
|
import builtInKeysMap from '../builtInKeysMap'
|
|
3
3
|
import mergeOptions from '../../../core/mergeOptions'
|
|
4
|
-
import { isFunction, error, diffAndCloneA, hasOwn } from '@mpxjs/utils'
|
|
4
|
+
import { isFunction, error, diffAndCloneA, hasOwn, noop } from '@mpxjs/utils'
|
|
5
5
|
|
|
6
6
|
function transformApiForProxy (context, currentInject) {
|
|
7
7
|
const rawSetData = context.setData.bind(context)
|
|
@@ -45,16 +45,14 @@ function transformApiForProxy (context, currentInject) {
|
|
|
45
45
|
}
|
|
46
46
|
})
|
|
47
47
|
if (currentInject) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
}
|
|
48
|
+
Object.defineProperties(context, {
|
|
49
|
+
__injectedRender: {
|
|
50
|
+
get () {
|
|
51
|
+
return currentInject.render || noop
|
|
52
|
+
},
|
|
53
|
+
configurable: false
|
|
54
|
+
}
|
|
55
|
+
})
|
|
58
56
|
if (currentInject.getRefsData) {
|
|
59
57
|
Object.defineProperties(context, {
|
|
60
58
|
__getRefsData: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasOwn } from '@mpxjs/utils'
|
|
1
|
+
import { hasOwn, noop } from '@mpxjs/utils'
|
|
2
2
|
import MpxProxy from '../../../core/proxy'
|
|
3
3
|
import builtInKeysMap from '../builtInKeysMap'
|
|
4
4
|
import mergeOptions from '../../../core/mergeOptions'
|
|
@@ -83,16 +83,14 @@ function transformApiForProxy (context, currentInject) {
|
|
|
83
83
|
|
|
84
84
|
// 绑定注入的render
|
|
85
85
|
if (currentInject) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
95
|
-
}
|
|
86
|
+
Object.defineProperties(context, {
|
|
87
|
+
__injectedRender: {
|
|
88
|
+
get () {
|
|
89
|
+
return currentInject.render || noop
|
|
90
|
+
},
|
|
91
|
+
configurable: false
|
|
92
|
+
}
|
|
93
|
+
})
|
|
96
94
|
if (currentInject.getRefsData) {
|
|
97
95
|
Object.defineProperties(context, {
|
|
98
96
|
__getRefsData: {
|
package/src/vuePlugin.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
|
-
import { walkChildren, parseSelector, error } from '@mpxjs/utils'
|
|
2
|
-
import
|
|
1
|
+
import { walkChildren, parseSelector, error, hasOwn } from '@mpxjs/utils'
|
|
2
|
+
import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
|
|
3
|
+
const datasetReg = /^data-(.+)$/
|
|
4
|
+
|
|
5
|
+
function collectDataset (attrs) {
|
|
6
|
+
const dataset = {}
|
|
7
|
+
for (const key in attrs) {
|
|
8
|
+
if (hasOwn(attrs, key)) {
|
|
9
|
+
const matched = datasetReg.exec(key)
|
|
10
|
+
if (matched) {
|
|
11
|
+
dataset[matched[1]] = attrs[key]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return dataset
|
|
16
|
+
}
|
|
3
17
|
|
|
4
18
|
export default function install (Vue) {
|
|
5
19
|
Vue.prototype.triggerEvent = function (eventName, eventDetail) {
|
|
6
|
-
|
|
20
|
+
// 输出Web时自定义组件绑定click事件会和web原生事件冲突,组件内部triggerEvent时会导致事件执行两次,将click事件改为_click来规避此问题
|
|
21
|
+
const escapeEvents = ['click']
|
|
22
|
+
if (escapeEvents.includes(eventName)) {
|
|
23
|
+
eventName = '_' + eventName
|
|
24
|
+
}
|
|
25
|
+
let eventObj = {}
|
|
26
|
+
const dataset = collectDataset(this.$attrs)
|
|
27
|
+
const id = this.$attrs.id || ''
|
|
28
|
+
const timeStamp = +new Date()
|
|
29
|
+
eventObj = {
|
|
7
30
|
type: eventName,
|
|
31
|
+
timeStamp,
|
|
32
|
+
target: { id, dataset, targetDataset: dataset },
|
|
33
|
+
currentTarget: { id, dataset },
|
|
8
34
|
detail: eventDetail
|
|
9
|
-
}
|
|
35
|
+
}
|
|
36
|
+
return this.$emit(eventName, eventObj)
|
|
10
37
|
}
|
|
11
38
|
Vue.prototype.selectComponent = function (selector, all) {
|
|
12
39
|
const result = []
|
|
@@ -23,9 +50,9 @@ export default function install (Vue) {
|
|
|
23
50
|
return this.selectComponent(selector, true)
|
|
24
51
|
}
|
|
25
52
|
Vue.prototype.createSelectorQuery = function () {
|
|
26
|
-
return
|
|
53
|
+
return createSelectorQuery().in(this)
|
|
27
54
|
}
|
|
28
55
|
Vue.prototype.createIntersectionObserver = function (component, options) {
|
|
29
|
-
return
|
|
56
|
+
return createIntersectionObserver(this, options)
|
|
30
57
|
}
|
|
31
58
|
}
|