@mpxjs/webpack-plugin 2.9.66 → 2.9.67
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/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +23 -7
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +15 -10
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +17 -4
- package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +12 -3
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +1 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +18 -3
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +46 -16
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +4 -4
|
@@ -16,9 +16,6 @@ import {
|
|
|
16
16
|
import { ExtendedViewStyle } from './types/common'
|
|
17
17
|
import type { _ViewProps } from './mpx-view'
|
|
18
18
|
|
|
19
|
-
// type TransformKey = 'translateX' | 'translateY' | 'rotate' | 'rotateX' | 'rotateY' | 'rotateZ' | 'scaleX' | 'scaleY' | 'skewX' | 'skewY'
|
|
20
|
-
// type NormalKey = 'opacity' | 'backgroundColor' | 'width' | 'height' | 'top' | 'right' | 'bottom' | 'left' | 'transformOrigin'
|
|
21
|
-
// type RuleKey = TransformKey | NormalKey
|
|
22
19
|
type AnimatedOption = {
|
|
23
20
|
duration: number
|
|
24
21
|
delay: number
|
|
@@ -84,20 +81,79 @@ const InitialValue: ExtendedViewStyle = Object.assign({
|
|
|
84
81
|
transformOrigin: ['50%', '50%', 0]
|
|
85
82
|
}, TransformInitial)
|
|
86
83
|
const TransformOrigin = 'transformOrigin'
|
|
87
|
-
// deg 角度
|
|
88
|
-
// const isDeg = (key: RuleKey) => ['rotateX', 'rotateY', 'rotateZ', 'rotate', 'skewX', 'skewY'].includes(key)
|
|
89
|
-
// 背景色
|
|
90
|
-
// const isBg = (key: RuleKey) => key === 'backgroundColor'
|
|
91
84
|
// transform
|
|
92
85
|
const isTransform = (key: string) => Object.keys(TransformInitial).includes(key)
|
|
86
|
+
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
87
|
+
const parseTransform = (transformStr: string) => {
|
|
88
|
+
const values = transformStr.trim().split(/\s+/)
|
|
89
|
+
const transform: {[propName: string]: string|number|number[]}[] = []
|
|
90
|
+
values.forEach(item => {
|
|
91
|
+
const match = item.match(/([/\w]+)\(([^)]+)\)/)
|
|
92
|
+
if (match && match.length >= 3) {
|
|
93
|
+
let key = match[1]
|
|
94
|
+
const val = match[2]
|
|
95
|
+
switch (key) {
|
|
96
|
+
case 'translateX':
|
|
97
|
+
case 'translateY':
|
|
98
|
+
case 'scaleX':
|
|
99
|
+
case 'scaleY':
|
|
100
|
+
case 'rotateX':
|
|
101
|
+
case 'rotateY':
|
|
102
|
+
case 'rotateZ':
|
|
103
|
+
case 'rotate':
|
|
104
|
+
case 'skewX':
|
|
105
|
+
case 'skewY':
|
|
106
|
+
case 'perspective':
|
|
107
|
+
// 单个值处理
|
|
108
|
+
transform.push({ [key]: global.__formatValue(val) })
|
|
109
|
+
break
|
|
110
|
+
case 'matrix':
|
|
111
|
+
case 'matrix3d':
|
|
112
|
+
transform.push({ [key]: val.split(',').map(val => +val) })
|
|
113
|
+
break
|
|
114
|
+
case 'translate':
|
|
115
|
+
case 'scale':
|
|
116
|
+
case 'skew':
|
|
117
|
+
case 'rotate3d': // x y z angle
|
|
118
|
+
case 'translate3d': // x y 支持 z不支持
|
|
119
|
+
case 'scale3d': // x y 支持 z不支持
|
|
120
|
+
{
|
|
121
|
+
// 2 个以上的值处理
|
|
122
|
+
key = key.replace('3d', '')
|
|
123
|
+
const vals = val.split(',', key === 'rotate' ? 4 : 3)
|
|
124
|
+
// scale(.5) === scaleX(.5) scaleY(.5) 这里处理一下
|
|
125
|
+
if (vals.length === 1 && key === 'scale') {
|
|
126
|
+
vals.push(vals[0])
|
|
127
|
+
}
|
|
128
|
+
const xyz = ['X', 'Y', 'Z']
|
|
129
|
+
transform.push(...vals.map((v, index) => {
|
|
130
|
+
return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) }
|
|
131
|
+
}))
|
|
132
|
+
break
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
return transform
|
|
138
|
+
}
|
|
139
|
+
// format style
|
|
140
|
+
const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
|
|
141
|
+
if (!style.transform || Array.isArray(style.transform)) return style
|
|
142
|
+
return Object.assign({}, style, {
|
|
143
|
+
transform: parseTransform(style.transform)
|
|
144
|
+
})
|
|
145
|
+
}
|
|
93
146
|
|
|
94
147
|
export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
95
|
-
const { style
|
|
148
|
+
const { style = {}, animation } = props
|
|
149
|
+
const originalStyle = formatStyle(style)
|
|
96
150
|
// id 标识
|
|
97
151
|
const id = animation?.id || -1
|
|
98
152
|
// 有动画样式的 style key
|
|
99
153
|
const animatedStyleKeys = useSharedValue([] as (string|string[])[])
|
|
100
|
-
|
|
154
|
+
// 记录动画key的style样式值 没有的话设置为false
|
|
155
|
+
const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean})
|
|
156
|
+
// const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean|number|string})
|
|
101
157
|
// ** 全量 style prop sharedValue
|
|
102
158
|
// 不能做增量的原因:
|
|
103
159
|
// 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
|
|
@@ -119,6 +175,16 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
119
175
|
// 驱动动画
|
|
120
176
|
createAnimation(keys)
|
|
121
177
|
}, [id])
|
|
178
|
+
// 同步style更新
|
|
179
|
+
// useEffect(() => {
|
|
180
|
+
// Object.keys(animatedKeys.current).forEach(key => {
|
|
181
|
+
// const originVal = getOriginalStyleVal(key, isTransform(key))
|
|
182
|
+
// if (originVal && animatedKeys.current[key] !== originVal) {
|
|
183
|
+
// animatedKeys.current[key] = originVal
|
|
184
|
+
// shareValMap[key].value = originVal
|
|
185
|
+
// }
|
|
186
|
+
// })
|
|
187
|
+
// }, [style])
|
|
122
188
|
// ** 清空动画
|
|
123
189
|
useEffect(() => {
|
|
124
190
|
return () => {
|
|
@@ -152,9 +218,9 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
152
218
|
}
|
|
153
219
|
// 添加每个key的多次step动画
|
|
154
220
|
animatedKeys.forEach(key => {
|
|
155
|
-
let toVal = (rules.get(key) || transform.get(key))
|
|
221
|
+
let toVal = (rules.get(key) || transform.get(key))
|
|
156
222
|
// key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
|
|
157
|
-
if (
|
|
223
|
+
if (toVal === undefined) {
|
|
158
224
|
toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value
|
|
159
225
|
}
|
|
160
226
|
const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined)
|
|
@@ -181,9 +247,8 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
181
247
|
: withTiming(value, { duration, easing })
|
|
182
248
|
return delay ? withDelay(delay, animation) : animation
|
|
183
249
|
}
|
|
184
|
-
// 获取初始值(prop style or 默认值)
|
|
185
250
|
function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
186
|
-
if (isTransform && originalStyle.transform
|
|
251
|
+
if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
187
252
|
let initialVal = InitialValue[key]
|
|
188
253
|
// 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
189
254
|
originalStyle.transform.forEach(item => {
|
|
@@ -193,12 +258,31 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
193
258
|
}
|
|
194
259
|
return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key]
|
|
195
260
|
}
|
|
261
|
+
// 从 prop style 中获取样式初始值 没有为undefined
|
|
262
|
+
// function getOriginalStyleVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
263
|
+
// if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
264
|
+
// let initialVal = undefined // InitialValue[key]
|
|
265
|
+
// // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
266
|
+
// originalStyle.transform.forEach(item => {
|
|
267
|
+
// if (item[key] !== undefined) initialVal = item[key]
|
|
268
|
+
// })
|
|
269
|
+
// return initialVal
|
|
270
|
+
// }
|
|
271
|
+
// return originalStyle[key] // === undefined ? InitialValue[key] : originalStyle[key]
|
|
272
|
+
// }
|
|
273
|
+
// 获取动画shareVal初始值(prop style or 默认值)
|
|
274
|
+
// function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
275
|
+
// const originalVal = getOriginalStyleVal(key, isTransform)
|
|
276
|
+
// return originalVal === undefined ? InitialValue[key] : originalStyle[key]
|
|
277
|
+
// }
|
|
196
278
|
// 循环 animation actions 获取所有有动画的 style prop name
|
|
197
279
|
function getAnimatedStyleKeys () {
|
|
198
280
|
return (animation?.actions || []).reduce((keyMap, action) => {
|
|
199
281
|
const { rules, transform } = action
|
|
200
282
|
const ruleArr = [...rules.keys(), ...transform.keys()]
|
|
201
283
|
ruleArr.forEach(key => {
|
|
284
|
+
// const originalVal = getOriginalStyleVal(key, isTransform(key))
|
|
285
|
+
// if (!keyMap[key]) keyMap[key] = originalVal === undefined ? false : originalVal
|
|
202
286
|
if (!keyMap[key]) keyMap[key] = true
|
|
203
287
|
})
|
|
204
288
|
return keyMap
|
|
@@ -12,7 +12,7 @@ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/
|
|
|
12
12
|
export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/
|
|
13
13
|
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/
|
|
14
14
|
export const DEFAULT_FONT_SIZE = 16
|
|
15
|
-
export const
|
|
15
|
+
export const HIDDEN_STYLE = {
|
|
16
16
|
opacity: 0
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -99,7 +99,7 @@ export function isText (ele: ReactNode): ele is ReactElement {
|
|
|
99
99
|
if (isValidElement(ele)) {
|
|
100
100
|
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName
|
|
101
101
|
const isCustomText = (ele.type as ExtendedFunctionComponent)?.isCustomText
|
|
102
|
-
return displayName === '
|
|
102
|
+
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText
|
|
103
103
|
}
|
|
104
104
|
return false
|
|
105
105
|
}
|
|
@@ -474,7 +474,7 @@ interface LayoutConfig {
|
|
|
474
474
|
export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }: LayoutConfig) => {
|
|
475
475
|
const layoutRef = useRef({})
|
|
476
476
|
const hasLayoutRef = useRef(false)
|
|
477
|
-
const layoutStyle: Record<string, any> = !hasLayoutRef.current && hasSelfPercent ?
|
|
477
|
+
const layoutStyle: Record<string, any> = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}
|
|
478
478
|
const layoutProps: Record<string, any> = {}
|
|
479
479
|
const enableOffset = props['enable-offset']
|
|
480
480
|
if (hasSelfPercent || onLayout || enableOffset) {
|
|
@@ -524,3 +524,18 @@ export function wrapChildren (props: Record<string, any> = {}, { hasVarDec, varC
|
|
|
524
524
|
}
|
|
525
525
|
return children
|
|
526
526
|
}
|
|
527
|
+
|
|
528
|
+
export interface GestureHandler {
|
|
529
|
+
nodeRefs?: Array<{ getNodeInstance: () => { nodeRef: unknown } }>;
|
|
530
|
+
current?: unknown;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export function flatGesture (gestures: Array<GestureHandler> = []) {
|
|
534
|
+
return (gestures && gestures.flatMap((gesture: GestureHandler) => {
|
|
535
|
+
if (gesture && gesture.nodeRefs) {
|
|
536
|
+
return gesture.nodeRefs
|
|
537
|
+
.map((item: { getNodeInstance: () => any }) => item.getNodeInstance()?.instance?.gestureRef || {})
|
|
538
|
+
}
|
|
539
|
+
return gesture?.current ? [gesture] : []
|
|
540
|
+
})) || []
|
|
541
|
+
}
|
|
@@ -4,18 +4,3 @@ export function getComponent (component, extendOptions) {
|
|
|
4
4
|
if (extendOptions) Object.assign(component, extendOptions)
|
|
5
5
|
return component
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
export function createApp ({
|
|
9
|
-
App,
|
|
10
|
-
pagesMap,
|
|
11
|
-
firstPage,
|
|
12
|
-
createElement,
|
|
13
|
-
NavigationContainer,
|
|
14
|
-
createNativeStackNavigator
|
|
15
|
-
}) {
|
|
16
|
-
const Stack = createNativeStackNavigator()
|
|
17
|
-
const pages = []
|
|
18
|
-
return () => {
|
|
19
|
-
return createElement(NavigationContainer, null, createElement(Stack.Navigator, null, ...pages))
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -19,7 +19,7 @@ module.exports = function (css, map) {
|
|
|
19
19
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
20
20
|
const mpx = this.getMpx()
|
|
21
21
|
const mpxStyleOptions = (queryObj.mpxStyleOptions && JSON.parse(queryObj.mpxStyleOptions)) || {}
|
|
22
|
-
const id = queryObj.moduleId || mpxStyleOptions.mid ||
|
|
22
|
+
const id = queryObj.moduleId || mpxStyleOptions.mid || mpx.getModuleId(resourcePath)
|
|
23
23
|
const appInfo = mpx.appInfo
|
|
24
24
|
const defs = mpx.defs
|
|
25
25
|
const mode = mpx.mode
|
|
@@ -116,6 +116,7 @@ let i18nInjectableComputed = []
|
|
|
116
116
|
let hasOptionalChaining = false
|
|
117
117
|
let processingTemplate = false
|
|
118
118
|
const rulesResultMap = new Map()
|
|
119
|
+
let usingComponents = []
|
|
119
120
|
|
|
120
121
|
function updateForScopesMap () {
|
|
121
122
|
forScopesMap = {}
|
|
@@ -633,6 +634,9 @@ function parse (template, options) {
|
|
|
633
634
|
processingTemplate = false
|
|
634
635
|
rulesResultMap.clear()
|
|
635
636
|
|
|
637
|
+
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
638
|
+
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
639
|
+
|
|
636
640
|
const _warn = content => {
|
|
637
641
|
const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, {
|
|
638
642
|
warnArray: [],
|
|
@@ -654,7 +658,7 @@ function parse (template, options) {
|
|
|
654
658
|
type: 'template',
|
|
655
659
|
testKey: 'tag',
|
|
656
660
|
data: {
|
|
657
|
-
usingComponents
|
|
661
|
+
usingComponents
|
|
658
662
|
},
|
|
659
663
|
warn: _warn,
|
|
660
664
|
error: _error
|
|
@@ -804,7 +808,7 @@ function parse (template, options) {
|
|
|
804
808
|
|
|
805
809
|
if (!tagNames.has('component') && options.checkUsingComponents) {
|
|
806
810
|
const arr = []
|
|
807
|
-
|
|
811
|
+
usingComponents.forEach((item) => {
|
|
808
812
|
if (!tagNames.has(item) && !options.globalComponents.includes(item) && !options.componentPlaceholder.includes(item)) {
|
|
809
813
|
arr.push(item)
|
|
810
814
|
}
|
|
@@ -980,7 +984,7 @@ function processComponentIs (el, options) {
|
|
|
980
984
|
|
|
981
985
|
const range = getAndRemoveAttr(el, 'range').val
|
|
982
986
|
const isInRange = makeMap(range || '')
|
|
983
|
-
el.components = (
|
|
987
|
+
el.components = (usingComponents).filter(i => {
|
|
984
988
|
if (!range) return true
|
|
985
989
|
return isInRange(i)
|
|
986
990
|
})
|
|
@@ -1763,6 +1767,15 @@ function processRefReact (el, meta) {
|
|
|
1763
1767
|
value: `{{ this.__getRefVal('${type}', [${selectorsConf}]) }}`
|
|
1764
1768
|
}])
|
|
1765
1769
|
}
|
|
1770
|
+
|
|
1771
|
+
if (el.tag === 'mpx-scroll-view' && el.attrsMap['scroll-into-view']) {
|
|
1772
|
+
addAttrs(el, [
|
|
1773
|
+
{
|
|
1774
|
+
name: '__selectRef',
|
|
1775
|
+
value: '{{ this.__selectRef.bind(this) }}'
|
|
1776
|
+
}
|
|
1777
|
+
])
|
|
1778
|
+
}
|
|
1766
1779
|
}
|
|
1767
1780
|
|
|
1768
1781
|
function processRef (el, options, meta) {
|
|
@@ -2137,7 +2150,7 @@ function processStyle (el, meta) {
|
|
|
2137
2150
|
}
|
|
2138
2151
|
|
|
2139
2152
|
function isRealNode (el) {
|
|
2140
|
-
const virtualNodeTagMap = ['block', 'template', 'import', config[mode].wxs.tag].reduce((map, item) => {
|
|
2153
|
+
const virtualNodeTagMap = ['block', 'template', 'import', 'slot', config[mode].wxs.tag].reduce((map, item) => {
|
|
2141
2154
|
map[item] = true
|
|
2142
2155
|
return map
|
|
2143
2156
|
}, {})
|
|
@@ -2145,7 +2158,11 @@ function isRealNode (el) {
|
|
|
2145
2158
|
}
|
|
2146
2159
|
|
|
2147
2160
|
function isComponentNode (el, options) {
|
|
2148
|
-
return
|
|
2161
|
+
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
function isReactComponent (el, options) {
|
|
2165
|
+
return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn
|
|
2149
2166
|
}
|
|
2150
2167
|
|
|
2151
2168
|
function processExternalClasses (el, options) {
|
|
@@ -2263,8 +2280,10 @@ function postProcessAliComponentRootView (el, options, meta) {
|
|
|
2263
2280
|
{ condition: /^style$/, action: 'move' },
|
|
2264
2281
|
{ condition: /^slot$/, action: 'move' }
|
|
2265
2282
|
]
|
|
2283
|
+
const tagName = el.tag
|
|
2284
|
+
const mid = options.usingComponentsInfo[tagName]?.mid || moduleId
|
|
2266
2285
|
const processAppendAttrsRules = [
|
|
2267
|
-
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${
|
|
2286
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` }
|
|
2268
2287
|
]
|
|
2269
2288
|
const newAttrs = []
|
|
2270
2289
|
const allAttrs = cloneAttrsList(el.attrsList)
|
|
@@ -2594,16 +2613,19 @@ function processElement (el, root, options, meta) {
|
|
|
2594
2613
|
}
|
|
2595
2614
|
|
|
2596
2615
|
if (isReact(mode)) {
|
|
2616
|
+
const pass = isReactComponent(el, options)
|
|
2597
2617
|
// 收集内建组件
|
|
2598
2618
|
processBuiltInComponents(el, meta)
|
|
2599
2619
|
// 预处理代码维度条件编译
|
|
2600
2620
|
processIf(el)
|
|
2601
2621
|
processFor(el)
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2622
|
+
if (!pass) {
|
|
2623
|
+
processRefReact(el, meta)
|
|
2624
|
+
processStyleReact(el, options)
|
|
2625
|
+
processEventReact(el)
|
|
2626
|
+
processComponentIs(el, options)
|
|
2627
|
+
processSlotReact(el, meta)
|
|
2628
|
+
}
|
|
2607
2629
|
processAttrs(el, options)
|
|
2608
2630
|
return
|
|
2609
2631
|
}
|
|
@@ -2656,11 +2678,19 @@ function closeElement (el, meta, options) {
|
|
|
2656
2678
|
}
|
|
2657
2679
|
|
|
2658
2680
|
const isTemplate = postProcessTemplate(el) || processingTemplate
|
|
2659
|
-
if (!
|
|
2660
|
-
if (
|
|
2681
|
+
if (!isTemplate) {
|
|
2682
|
+
if (!isNative) {
|
|
2683
|
+
postProcessComponentIs(el, (child) => {
|
|
2684
|
+
if (!hasVirtualHost && mode === 'ali') {
|
|
2685
|
+
postProcessAliComponentRootView(child, options)
|
|
2686
|
+
} else {
|
|
2687
|
+
postProcessIf(child)
|
|
2688
|
+
}
|
|
2689
|
+
})
|
|
2690
|
+
}
|
|
2691
|
+
if (isComponentNode(el, options) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
|
|
2661
2692
|
postProcessAliComponentRootView(el, options, meta)
|
|
2662
2693
|
}
|
|
2663
|
-
postProcessComponentIs(el)
|
|
2664
2694
|
}
|
|
2665
2695
|
|
|
2666
2696
|
if (runtimeCompile) {
|
|
@@ -2707,7 +2737,7 @@ function cloneAttrsList (attrsList) {
|
|
|
2707
2737
|
})
|
|
2708
2738
|
}
|
|
2709
2739
|
|
|
2710
|
-
function postProcessComponentIs (el) {
|
|
2740
|
+
function postProcessComponentIs (el, postProcessChild) {
|
|
2711
2741
|
if (el.is && el.components) {
|
|
2712
2742
|
let tempNode
|
|
2713
2743
|
if (el.for || el.if || el.elseif || el.else) {
|
|
@@ -2729,7 +2759,7 @@ function postProcessComponentIs (el) {
|
|
|
2729
2759
|
})
|
|
2730
2760
|
newChild.exps = el.exps
|
|
2731
2761
|
addChild(tempNode, newChild)
|
|
2732
|
-
|
|
2762
|
+
postProcessChild(newChild)
|
|
2733
2763
|
})
|
|
2734
2764
|
|
|
2735
2765
|
if (!el.parent) {
|
|
@@ -24,14 +24,14 @@ module.exports = function (raw) {
|
|
|
24
24
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
25
25
|
const wxsContentMap = mpx.wxsContentMap
|
|
26
26
|
const optimizeRenderRules = mpx.optimizeRenderRules
|
|
27
|
-
const
|
|
27
|
+
const usingComponentsInfo = queryObj.usingComponentsInfo || {}
|
|
28
28
|
const componentPlaceholder = queryObj.componentPlaceholder || []
|
|
29
29
|
const hasComment = queryObj.hasComment
|
|
30
30
|
const isNative = queryObj.isNative
|
|
31
31
|
const ctorType = queryObj.ctorType
|
|
32
32
|
const hasScoped = queryObj.hasScoped
|
|
33
33
|
const runtimeCompile = queryObj.isDynamic
|
|
34
|
-
const moduleId = queryObj.moduleId ||
|
|
34
|
+
const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath)
|
|
35
35
|
|
|
36
36
|
let optimizeRenderLevel = 0
|
|
37
37
|
for (const rule of optimizeRenderRules) {
|
|
@@ -57,7 +57,6 @@ module.exports = function (raw) {
|
|
|
57
57
|
warn,
|
|
58
58
|
error,
|
|
59
59
|
runtimeCompile,
|
|
60
|
-
usingComponents,
|
|
61
60
|
componentPlaceholder,
|
|
62
61
|
hasComment,
|
|
63
62
|
isNative,
|
|
@@ -70,11 +69,12 @@ module.exports = function (raw) {
|
|
|
70
69
|
externalClasses,
|
|
71
70
|
hasScoped,
|
|
72
71
|
moduleId,
|
|
72
|
+
usingComponentsInfo,
|
|
73
73
|
// 这里需传递resourcePath和wxsContentMap保持一致
|
|
74
74
|
filePath: resourcePath,
|
|
75
75
|
i18n,
|
|
76
76
|
checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
|
|
77
|
-
globalComponents: Object.keys(mpx.
|
|
77
|
+
globalComponents: Object.keys(mpx.globalComponents),
|
|
78
78
|
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules) || runtimeCompile,
|
|
79
79
|
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
|
|
80
80
|
dynamicTemplateRuleRunner: mpx.dynamicTemplateRuleRunner
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
2
|
+
const JSON5 = require('json5')
|
|
3
|
+
const isUrlRequest = require('./is-url-request')
|
|
4
|
+
const parseRequest = require('./parse-request')
|
|
5
|
+
const addQuery = require('./add-query')
|
|
6
|
+
const resolve = require('./resolve')
|
|
7
|
+
const getJSONContent = require('./get-json-content')
|
|
8
|
+
const getRulesRunner = require('../platform')
|
|
9
|
+
const async = require('async')
|
|
10
|
+
|
|
11
|
+
module.exports = function ({
|
|
12
|
+
json,
|
|
13
|
+
srcMode,
|
|
14
|
+
emitWarning,
|
|
15
|
+
emitError,
|
|
16
|
+
ctorType,
|
|
17
|
+
resourcePath,
|
|
18
|
+
loaderContext
|
|
19
|
+
}, callback) {
|
|
20
|
+
const mpx = loaderContext.getMpx()
|
|
21
|
+
const context = loaderContext.context
|
|
22
|
+
const mode = mpx.mode
|
|
23
|
+
const pagesMap = mpx.pagesMap
|
|
24
|
+
async.waterfall([
|
|
25
|
+
(callback) => {
|
|
26
|
+
getJSONContent(json, null, loaderContext, callback)
|
|
27
|
+
},
|
|
28
|
+
(jsonContent, callback) => {
|
|
29
|
+
if (!jsonContent) return callback(null, {})
|
|
30
|
+
let componentPlaceholder = []
|
|
31
|
+
let componentGenerics = {}
|
|
32
|
+
const usingComponentsInfo = {}
|
|
33
|
+
const usingComponents = {}
|
|
34
|
+
const finalCallback = (err) => {
|
|
35
|
+
if (err) return callback(err)
|
|
36
|
+
if (ctorType === 'app') {
|
|
37
|
+
// 在 rulesRunner 运行后保存全局注册组件
|
|
38
|
+
// todo 其余地方在使用mpx.globalComponents时存在缓存问题,要规避该问题需要在所有使用mpx.globalComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
|
|
39
|
+
// todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
|
|
40
|
+
loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(usingComponents, usingComponentsInfo, context))
|
|
41
|
+
}
|
|
42
|
+
callback(null, {
|
|
43
|
+
componentPlaceholder,
|
|
44
|
+
componentGenerics,
|
|
45
|
+
usingComponentsInfo: Object.assign({}, usingComponentsInfo, mpx.globalComponentsInfo),
|
|
46
|
+
jsonContent
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const ret = JSON5.parse(jsonContent)
|
|
51
|
+
const rulesMeta = {}
|
|
52
|
+
const rulesRunnerOptions = {
|
|
53
|
+
mode,
|
|
54
|
+
srcMode,
|
|
55
|
+
type: 'json',
|
|
56
|
+
waterfall: true,
|
|
57
|
+
warn: emitWarning,
|
|
58
|
+
error: emitError,
|
|
59
|
+
meta: rulesMeta
|
|
60
|
+
}
|
|
61
|
+
if (ctorType !== 'app') {
|
|
62
|
+
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
63
|
+
}
|
|
64
|
+
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
65
|
+
try {
|
|
66
|
+
if (rulesRunner) rulesRunner(ret)
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return finalCallback(e)
|
|
69
|
+
}
|
|
70
|
+
// 不支持全局组件的平台,runRules 时会删除 app.json 中的 usingComponents, 同时 fillGlobalComponents 方法会对 rulesMeta 赋值 usingComponents,通过 rulesMeta 来重新获取 globalComponents
|
|
71
|
+
// page | component 时 直接获取 ret.usingComponents 内容
|
|
72
|
+
Object.assign(usingComponents, ret.usingComponents || rulesMeta.usingComponents)
|
|
73
|
+
|
|
74
|
+
if (ret.componentPlaceholder) {
|
|
75
|
+
componentPlaceholder = componentPlaceholder.concat(Object.values(ret.componentPlaceholder))
|
|
76
|
+
}
|
|
77
|
+
if (ret.componentGenerics) {
|
|
78
|
+
componentGenerics = Object.assign({}, ret.componentGenerics)
|
|
79
|
+
}
|
|
80
|
+
if (usingComponents) {
|
|
81
|
+
const setUsingComponentInfo = (name, moduleId) => {
|
|
82
|
+
usingComponentsInfo[name] = { mid: moduleId }
|
|
83
|
+
}
|
|
84
|
+
async.eachOf(usingComponents, (component, name, callback) => {
|
|
85
|
+
if (ctorType === 'app') {
|
|
86
|
+
usingComponents[name] = addQuery(component, {
|
|
87
|
+
context
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
if (!isUrlRequest(component)) {
|
|
91
|
+
const moduleId = mpx.getModuleId(component, ctorType === 'app')
|
|
92
|
+
setUsingComponentInfo(name, moduleId)
|
|
93
|
+
return callback()
|
|
94
|
+
}
|
|
95
|
+
resolve(context, component, loaderContext, (err, resource) => {
|
|
96
|
+
if (err) return callback(err)
|
|
97
|
+
const { rawResourcePath } = parseRequest(resource)
|
|
98
|
+
const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app')
|
|
99
|
+
setUsingComponentInfo(name, moduleId)
|
|
100
|
+
callback()
|
|
101
|
+
})
|
|
102
|
+
}, (err) => {
|
|
103
|
+
finalCallback(err)
|
|
104
|
+
})
|
|
105
|
+
} else {
|
|
106
|
+
finalCallback()
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
finalCallback(err)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
], callback)
|
|
113
|
+
}
|
package/lib/web/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const RecordLoaderContentDependency = require('../dependencies/RecordLoaderConte
|
|
|
8
8
|
|
|
9
9
|
module.exports = function ({
|
|
10
10
|
parts,
|
|
11
|
+
jsonContent,
|
|
11
12
|
loaderContext,
|
|
12
13
|
pagesMap,
|
|
13
14
|
componentsMap,
|
|
@@ -19,7 +20,7 @@ module.exports = function ({
|
|
|
19
20
|
hasScoped,
|
|
20
21
|
hasComment,
|
|
21
22
|
isNative,
|
|
22
|
-
|
|
23
|
+
usingComponentsInfo,
|
|
23
24
|
componentGenerics,
|
|
24
25
|
autoScope,
|
|
25
26
|
callback
|
|
@@ -27,7 +28,7 @@ module.exports = function ({
|
|
|
27
28
|
if (ctorType === 'app' && !queryObj.isApp) {
|
|
28
29
|
return async.waterfall([
|
|
29
30
|
(callback) => {
|
|
30
|
-
processJSON(
|
|
31
|
+
processJSON(jsonContent, {
|
|
31
32
|
loaderContext,
|
|
32
33
|
ctorType,
|
|
33
34
|
pagesMap,
|
|
@@ -68,7 +69,7 @@ module.exports = function ({
|
|
|
68
69
|
srcMode,
|
|
69
70
|
moduleId,
|
|
70
71
|
ctorType,
|
|
71
|
-
|
|
72
|
+
usingComponentsInfo,
|
|
72
73
|
componentGenerics
|
|
73
74
|
}, callback)
|
|
74
75
|
},
|
|
@@ -80,7 +81,7 @@ module.exports = function ({
|
|
|
80
81
|
}, callback)
|
|
81
82
|
},
|
|
82
83
|
(callback) => {
|
|
83
|
-
processJSON(
|
|
84
|
+
processJSON(jsonContent, {
|
|
84
85
|
loaderContext,
|
|
85
86
|
ctorType,
|
|
86
87
|
pagesMap,
|
package/lib/web/processJSON.js
CHANGED
|
@@ -12,9 +12,8 @@ const createJSONHelper = require('../json-compiler/helper')
|
|
|
12
12
|
const getRulesRunner = require('../platform/index')
|
|
13
13
|
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
14
14
|
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
15
|
-
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
16
15
|
|
|
17
|
-
module.exports = function (
|
|
16
|
+
module.exports = function (jsonContent, {
|
|
18
17
|
loaderContext,
|
|
19
18
|
ctorType,
|
|
20
19
|
pagesMap,
|
|
@@ -82,12 +81,11 @@ module.exports = function (json, {
|
|
|
82
81
|
|
|
83
82
|
const isApp = ctorType === 'app'
|
|
84
83
|
|
|
85
|
-
if (!
|
|
84
|
+
if (!jsonContent) {
|
|
86
85
|
return callback()
|
|
87
86
|
}
|
|
88
|
-
// 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
|
|
89
87
|
try {
|
|
90
|
-
jsonObj = JSON5.parse(
|
|
88
|
+
jsonObj = JSON5.parse(jsonContent)
|
|
91
89
|
// 处理runner
|
|
92
90
|
const rulesRunnerOptions = {
|
|
93
91
|
mode,
|
|
@@ -97,8 +95,8 @@ module.exports = function (json, {
|
|
|
97
95
|
warn: emitWarning,
|
|
98
96
|
error: emitError,
|
|
99
97
|
data: {
|
|
100
|
-
// polyfill global usingComponents
|
|
101
|
-
globalComponents: mpx.
|
|
98
|
+
// polyfill global usingComponents
|
|
99
|
+
globalComponents: mpx.globalComponents
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -111,12 +109,6 @@ module.exports = function (json, {
|
|
|
111
109
|
if (rulesRunner) {
|
|
112
110
|
rulesRunner(jsonObj)
|
|
113
111
|
}
|
|
114
|
-
if (isApp) {
|
|
115
|
-
// 收集全局组件
|
|
116
|
-
Object.assign(mpx.usingComponents, jsonObj.usingComponents)
|
|
117
|
-
// 在 rulesRunner 运行后保存全局注册组件
|
|
118
|
-
loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
|
|
119
|
-
}
|
|
120
112
|
} catch (e) {
|
|
121
113
|
return callback(e)
|
|
122
114
|
}
|