@mpxjs/webpack-plugin 2.9.69 → 2.9.70
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/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -117,6 +117,7 @@ let hasOptionalChaining = false
|
|
|
117
117
|
let processingTemplate = false
|
|
118
118
|
const rulesResultMap = new Map()
|
|
119
119
|
let usingComponents = []
|
|
120
|
+
let usingComponentsInfo = {}
|
|
120
121
|
|
|
121
122
|
function updateForScopesMap () {
|
|
122
123
|
forScopesMap = {}
|
|
@@ -636,6 +637,7 @@ function parse (template, options) {
|
|
|
636
637
|
|
|
637
638
|
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
638
639
|
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
640
|
+
usingComponentsInfo = options.usingComponentsInfo
|
|
639
641
|
|
|
640
642
|
const _warn = content => {
|
|
641
643
|
const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, {
|
|
@@ -725,7 +727,7 @@ function parse (template, options) {
|
|
|
725
727
|
stack.push(element)
|
|
726
728
|
} else {
|
|
727
729
|
element.unary = true
|
|
728
|
-
closeElement(element,
|
|
730
|
+
closeElement(element, options, meta)
|
|
729
731
|
}
|
|
730
732
|
},
|
|
731
733
|
|
|
@@ -740,7 +742,7 @@ function parse (template, options) {
|
|
|
740
742
|
// pop stack
|
|
741
743
|
stack.pop()
|
|
742
744
|
currentParent = stack[stack.length - 1]
|
|
743
|
-
closeElement(element,
|
|
745
|
+
closeElement(element, options, meta)
|
|
744
746
|
}
|
|
745
747
|
},
|
|
746
748
|
|
|
@@ -765,7 +767,7 @@ function parse (template, options) {
|
|
|
765
767
|
parent: currentParent
|
|
766
768
|
}
|
|
767
769
|
children.push(el)
|
|
768
|
-
runtimeCompile ? processTextDynamic(el) : processText(el)
|
|
770
|
+
runtimeCompile ? processTextDynamic(el) : processText(el, options, meta)
|
|
769
771
|
}
|
|
770
772
|
},
|
|
771
773
|
comment: function comment (text) {
|
|
@@ -1164,7 +1166,7 @@ function processEventReact (el) {
|
|
|
1164
1166
|
configs: []
|
|
1165
1167
|
}
|
|
1166
1168
|
}
|
|
1167
|
-
eventConfigMap[type].configs.push(Object.assign({ name }, parsedFunc))
|
|
1169
|
+
eventConfigMap[type].configs.push(Object.assign({ name, value }, parsedFunc))
|
|
1168
1170
|
}
|
|
1169
1171
|
}
|
|
1170
1172
|
})
|
|
@@ -1205,26 +1207,32 @@ function processEventReact (el) {
|
|
|
1205
1207
|
|
|
1206
1208
|
// let wrapper
|
|
1207
1209
|
for (const type in eventConfigMap) {
|
|
1208
|
-
|
|
1209
|
-
configs.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1210
|
+
const { configs } = eventConfigMap[type]
|
|
1211
|
+
if (!configs.length) continue
|
|
1212
|
+
const needBind = configs.length > 1 || configs[0].hasArgs
|
|
1213
|
+
if (needBind) {
|
|
1214
|
+
configs.forEach(({ name }) => {
|
|
1215
|
+
if (name) {
|
|
1216
|
+
// 清空原始事件绑定
|
|
1217
|
+
let has
|
|
1218
|
+
do {
|
|
1219
|
+
has = getAndRemoveAttr(el, name).has
|
|
1220
|
+
} while (has)
|
|
1221
|
+
}
|
|
1222
|
+
})
|
|
1223
|
+
const value = `{{(e)=>this.__invoke(e, [${configs.map(item => item.expStr)}])}}`
|
|
1224
|
+
addAttrs(el, [
|
|
1225
|
+
{
|
|
1226
|
+
name: type,
|
|
1227
|
+
value
|
|
1228
|
+
}
|
|
1229
|
+
])
|
|
1230
|
+
} else {
|
|
1231
|
+
const { name, value } = configs[0]
|
|
1232
|
+
const { result } = parseMustacheWithContext(value)
|
|
1233
|
+
modifyAttr(el, name, `{{this[${result}]}}`)
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1228
1236
|
// 非button的情况下,press/longPress时间需要包裹TouchableWithoutFeedback进行响应,后续可支持配置
|
|
1229
1237
|
// if ((type === 'press' || type === 'longPress') && el.tag !== 'mpx-button') {
|
|
1230
1238
|
// if (!wrapper) {
|
|
@@ -1922,7 +1930,7 @@ function postProcessFor (el) {
|
|
|
1922
1930
|
function postProcessForReact (el) {
|
|
1923
1931
|
if (el.for) {
|
|
1924
1932
|
if (el.for.key) {
|
|
1925
|
-
addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key)})`, false, 'key')
|
|
1933
|
+
addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key)}, ${el.for.index || 'index'})`, false, 'key')
|
|
1926
1934
|
addAttrs(el, [{
|
|
1927
1935
|
name: 'key',
|
|
1928
1936
|
value: el.for.key
|
|
@@ -2036,7 +2044,7 @@ function postProcessIfReact (el) {
|
|
|
2036
2044
|
}
|
|
2037
2045
|
}
|
|
2038
2046
|
|
|
2039
|
-
function processText (el) {
|
|
2047
|
+
function processText (el, options, meta) {
|
|
2040
2048
|
if (el.type !== 3 || el.isComment) {
|
|
2041
2049
|
return
|
|
2042
2050
|
}
|
|
@@ -2046,17 +2054,38 @@ function processText (el) {
|
|
|
2046
2054
|
}
|
|
2047
2055
|
el.text = parsed.val
|
|
2048
2056
|
if (isReact(mode)) {
|
|
2049
|
-
processWrapTextReact(el)
|
|
2057
|
+
processWrapTextReact(el, options, meta)
|
|
2050
2058
|
}
|
|
2051
2059
|
}
|
|
2052
2060
|
|
|
2053
|
-
// RN
|
|
2054
|
-
|
|
2055
|
-
|
|
2061
|
+
// RN中裸文字需被Text包裹
|
|
2062
|
+
// 为了批量修改Text默认属性,如allowFontScaling,使用mpx-simple-text进行包裹
|
|
2063
|
+
function processWrapTextReact (el, options, meta) {
|
|
2064
|
+
const parent = el.parent
|
|
2065
|
+
const parentTag = parent.tag
|
|
2056
2066
|
if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
|
|
2057
|
-
const wrapper = createASTElement('
|
|
2067
|
+
const wrapper = createASTElement('mpx-simple-text')
|
|
2068
|
+
wrapper.isBuiltIn = true
|
|
2069
|
+
const inheritAttrs = []
|
|
2070
|
+
parent.attrsList.forEach(({ name, value }) => {
|
|
2071
|
+
if (/^data-/.test(name)) {
|
|
2072
|
+
inheritAttrs.push({
|
|
2073
|
+
name,
|
|
2074
|
+
value
|
|
2075
|
+
})
|
|
2076
|
+
}
|
|
2077
|
+
if (/^id$/.test(name)) {
|
|
2078
|
+
inheritAttrs.push({
|
|
2079
|
+
name: 'parentId',
|
|
2080
|
+
value
|
|
2081
|
+
})
|
|
2082
|
+
}
|
|
2083
|
+
})
|
|
2084
|
+
addAttrs(wrapper, inheritAttrs)
|
|
2058
2085
|
replaceNode(el, wrapper, true)
|
|
2059
2086
|
addChild(wrapper, el)
|
|
2087
|
+
processBuiltInComponents(wrapper, meta)
|
|
2088
|
+
processAttrs(wrapper, options)
|
|
2060
2089
|
}
|
|
2061
2090
|
}
|
|
2062
2091
|
|
|
@@ -2158,16 +2187,20 @@ function isRealNode (el) {
|
|
|
2158
2187
|
return !virtualNodeTagMap[el.tag]
|
|
2159
2188
|
}
|
|
2160
2189
|
|
|
2161
|
-
function isComponentNode (el
|
|
2190
|
+
function isComponentNode (el) {
|
|
2162
2191
|
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
2163
2192
|
}
|
|
2164
2193
|
|
|
2165
|
-
function
|
|
2166
|
-
return
|
|
2194
|
+
function getComponentInfo (el) {
|
|
2195
|
+
return usingComponentsInfo[el.tag] || {}
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
function isReactComponent (el) {
|
|
2199
|
+
return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn
|
|
2167
2200
|
}
|
|
2168
2201
|
|
|
2169
2202
|
function processExternalClasses (el, options) {
|
|
2170
|
-
const isComponent = isComponentNode(el
|
|
2203
|
+
const isComponent = isComponentNode(el)
|
|
2171
2204
|
const classLikeAttrNames = isComponent ? ['class'].concat(options.externalClasses) : ['class']
|
|
2172
2205
|
|
|
2173
2206
|
classLikeAttrNames.forEach((classLikeAttrName) => {
|
|
@@ -2281,8 +2314,7 @@ function postProcessAliComponentRootView (el, options, meta) {
|
|
|
2281
2314
|
{ condition: /^style$/, action: 'move' },
|
|
2282
2315
|
{ condition: /^slot$/, action: 'move' }
|
|
2283
2316
|
]
|
|
2284
|
-
const
|
|
2285
|
-
const mid = options.usingComponentsInfo[tagName]?.mid || moduleId
|
|
2317
|
+
const mid = getComponentInfo(el).mid
|
|
2286
2318
|
const processAppendAttrsRules = [
|
|
2287
2319
|
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` }
|
|
2288
2320
|
]
|
|
@@ -2361,12 +2393,11 @@ function getVirtualHostRoot (options, meta) {
|
|
|
2361
2393
|
{
|
|
2362
2394
|
name: 'class',
|
|
2363
2395
|
value: `${MPX_ROOT_VIEW} host-${moduleId}`
|
|
2396
|
+
},
|
|
2397
|
+
{
|
|
2398
|
+
name: 'ishost',
|
|
2399
|
+
value: '{{true}}'
|
|
2364
2400
|
}
|
|
2365
|
-
// todo 运行时通过root标识确定是否合并rootProps
|
|
2366
|
-
// {
|
|
2367
|
-
// name: 'is-root',
|
|
2368
|
-
// value: '{{true}}'
|
|
2369
|
-
// }
|
|
2370
2401
|
])
|
|
2371
2402
|
processElement(rootView, rootView, options, meta)
|
|
2372
2403
|
return rootView
|
|
@@ -2390,7 +2421,7 @@ function processShow (el, options, root) {
|
|
|
2390
2421
|
show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
|
|
2391
2422
|
}
|
|
2392
2423
|
if (show === undefined) return
|
|
2393
|
-
if (isComponentNode(el
|
|
2424
|
+
if (isComponentNode(el) && getComponentInfo(el).hasVirtualHost) {
|
|
2394
2425
|
if (show === '') {
|
|
2395
2426
|
show = '{{false}}'
|
|
2396
2427
|
}
|
|
@@ -2663,7 +2694,7 @@ function processElement (el, root, options, meta) {
|
|
|
2663
2694
|
processAttrs(el, options)
|
|
2664
2695
|
}
|
|
2665
2696
|
|
|
2666
|
-
function closeElement (el,
|
|
2697
|
+
function closeElement (el, options, meta) {
|
|
2667
2698
|
postProcessAtMode(el)
|
|
2668
2699
|
postProcessWxs(el, meta)
|
|
2669
2700
|
|
|
@@ -2682,14 +2713,14 @@ function closeElement (el, meta, options) {
|
|
|
2682
2713
|
if (!isTemplate) {
|
|
2683
2714
|
if (!isNative) {
|
|
2684
2715
|
postProcessComponentIs(el, (child) => {
|
|
2685
|
-
if (!hasVirtualHost && mode === 'ali') {
|
|
2716
|
+
if (!getComponentInfo(el).hasVirtualHost && mode === 'ali') {
|
|
2686
2717
|
postProcessAliComponentRootView(child, options)
|
|
2687
2718
|
} else {
|
|
2688
2719
|
postProcessIf(child)
|
|
2689
2720
|
}
|
|
2690
2721
|
})
|
|
2691
2722
|
}
|
|
2692
|
-
if (isComponentNode(el
|
|
2723
|
+
if (isComponentNode(el) && !getComponentInfo(el).hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
|
|
2693
2724
|
postProcessAliComponentRootView(el, options, meta)
|
|
2694
2725
|
}
|
|
2695
2726
|
}
|
|
@@ -19,7 +19,7 @@ function genFor (node) {
|
|
|
19
19
|
node.forProcessed = true
|
|
20
20
|
const index = node.for.index || 'index'
|
|
21
21
|
const item = node.for.item || 'item'
|
|
22
|
-
return `
|
|
22
|
+
return `this.__iter(${node.for.exp}, function(${item},${index}){return ${genNode(node)}})`
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const s = JSON.stringify
|
|
@@ -57,7 +57,7 @@ function genNode (node) {
|
|
|
57
57
|
}, {})
|
|
58
58
|
if (node.slot) {
|
|
59
59
|
const { name, slot } = node.slot
|
|
60
|
-
exp += `__getSlot(${name ? s(name) : ''}${slot ? `, ${s(slot)}` : ''})`
|
|
60
|
+
exp += `this.__getSlot(${name ? s(name) : ''}${slot ? `, ${s(slot)}` : ''})`
|
|
61
61
|
} else {
|
|
62
62
|
exp += `createElement(${`getComponent(${node.is || s(node.tag)})`}`
|
|
63
63
|
if (node.attrsList.length) {
|
|
@@ -6,6 +6,7 @@ const addQuery = require('./add-query')
|
|
|
6
6
|
const resolve = require('./resolve')
|
|
7
7
|
const getJSONContent = require('./get-json-content')
|
|
8
8
|
const getRulesRunner = require('../platform')
|
|
9
|
+
const { matchCondition } = require('./match-condition')
|
|
9
10
|
const async = require('async')
|
|
10
11
|
|
|
11
12
|
module.exports = function ({
|
|
@@ -19,8 +20,7 @@ module.exports = function ({
|
|
|
19
20
|
}, callback) {
|
|
20
21
|
const mpx = loaderContext.getMpx()
|
|
21
22
|
const context = loaderContext.context
|
|
22
|
-
const mode = mpx
|
|
23
|
-
const pagesMap = mpx.pagesMap
|
|
23
|
+
const { mode, pagesMap, autoVirtualHostRules } = mpx
|
|
24
24
|
async.waterfall([
|
|
25
25
|
(callback) => {
|
|
26
26
|
getJSONContent(json, null, loaderContext, callback)
|
|
@@ -78,8 +78,8 @@ module.exports = function ({
|
|
|
78
78
|
componentGenerics = Object.assign({}, ret.componentGenerics)
|
|
79
79
|
}
|
|
80
80
|
if (usingComponents) {
|
|
81
|
-
const setUsingComponentInfo = (name,
|
|
82
|
-
usingComponentsInfo[name] =
|
|
81
|
+
const setUsingComponentInfo = (name, info) => {
|
|
82
|
+
usingComponentsInfo[name] = info
|
|
83
83
|
}
|
|
84
84
|
async.eachOf(usingComponents, (component, name, callback) => {
|
|
85
85
|
if (ctorType === 'app') {
|
|
@@ -96,7 +96,11 @@ module.exports = function ({
|
|
|
96
96
|
if (err) return callback(err)
|
|
97
97
|
const { rawResourcePath } = parseRequest(resource)
|
|
98
98
|
const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app')
|
|
99
|
-
|
|
99
|
+
const hasVirtualHost = matchCondition(rawResourcePath, autoVirtualHostRules)
|
|
100
|
+
setUsingComponentInfo(name, {
|
|
101
|
+
mid: moduleId,
|
|
102
|
+
hasVirtualHost
|
|
103
|
+
})
|
|
100
104
|
callback()
|
|
101
105
|
})
|
|
102
106
|
}, (err) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.70",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@better-scroll/wheel": "^2.5.1",
|
|
29
29
|
"@better-scroll/zoom": "^2.5.1",
|
|
30
30
|
"@mpxjs/template-engine": "^2.8.7",
|
|
31
|
-
"@mpxjs/utils": "^2.9.
|
|
31
|
+
"@mpxjs/utils": "^2.9.70",
|
|
32
32
|
"acorn": "^8.11.3",
|
|
33
33
|
"acorn-walk": "^7.2.0",
|
|
34
34
|
"async": "^2.6.0",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@ant-design/react-native": "^5.2.2",
|
|
85
85
|
"@d11/react-native-fast-image": "^8.6.12",
|
|
86
|
-
"@mpxjs/api-proxy": "^2.9.
|
|
86
|
+
"@mpxjs/api-proxy": "^2.9.70",
|
|
87
87
|
"@types/babel-traverse": "^6.25.4",
|
|
88
88
|
"@types/babel-types": "^7.0.4",
|
|
89
89
|
"@types/react": "^18.2.79",
|
|
@@ -92,11 +92,12 @@
|
|
|
92
92
|
"react-native-linear-gradient": "^2.8.3",
|
|
93
93
|
"react-native-reanimated": "^3.15.2",
|
|
94
94
|
"react-native-safe-area-context": "^4.12.0",
|
|
95
|
+
"react-native-svg": "^15.8.0",
|
|
95
96
|
"react-native-webview": "^13.12.2",
|
|
96
97
|
"rimraf": "^6.0.1"
|
|
97
98
|
},
|
|
98
99
|
"engines": {
|
|
99
100
|
"node": ">=14.14.0"
|
|
100
101
|
},
|
|
101
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "ad8f04de95865ffc2b50b8c0a7f87b5952fb8647"
|
|
102
103
|
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ✔ src
|
|
3
|
-
* - mode: Partially, Only SVG format do not support
|
|
4
|
-
* ✘ show-menu-by-longpress
|
|
5
|
-
* ✔ binderror
|
|
6
|
-
* ✔ bindload
|
|
7
|
-
* ✘ fade-in
|
|
8
|
-
* ✔ webp
|
|
9
|
-
* ✘ lazy-load
|
|
10
|
-
* ✔ bindtap
|
|
11
|
-
* ✔ DEFAULT_SIZE
|
|
12
|
-
*/
|
|
13
|
-
import { useEffect, useMemo, useState, useRef, forwardRef } from 'react';
|
|
14
|
-
import { Image as RNImage, View, StyleSheet } from 'react-native';
|
|
15
|
-
import useInnerProps, { getCustomEvent } from '../getInnerListeners';
|
|
16
|
-
import useNodesRef from '../useNodesRef';
|
|
17
|
-
import { useLayout, useTransformStyle } from '../utils';
|
|
18
|
-
const DEFAULT_IMAGE_WIDTH = 320;
|
|
19
|
-
const DEFAULT_IMAGE_HEIGHT = 240;
|
|
20
|
-
// const REMOTE_SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i
|
|
21
|
-
// const styls = StyleSheet.create({
|
|
22
|
-
// suspense: {
|
|
23
|
-
// display: 'flex',
|
|
24
|
-
// justifyContent: 'center',
|
|
25
|
-
// alignItems: 'center',
|
|
26
|
-
// width: '100%',
|
|
27
|
-
// height: '100%',
|
|
28
|
-
// },
|
|
29
|
-
// })
|
|
30
|
-
const cropMode = [
|
|
31
|
-
'top',
|
|
32
|
-
'bottom',
|
|
33
|
-
'center',
|
|
34
|
-
'right',
|
|
35
|
-
'left',
|
|
36
|
-
'top left',
|
|
37
|
-
'top right',
|
|
38
|
-
'bottom left',
|
|
39
|
-
'bottom right'
|
|
40
|
-
];
|
|
41
|
-
const ModeMap = new Map([
|
|
42
|
-
['scaleToFill', 'stretch'],
|
|
43
|
-
['aspectFit', 'contain'],
|
|
44
|
-
['aspectFill', 'cover'],
|
|
45
|
-
['widthFix', 'stretch'],
|
|
46
|
-
['heightFix', 'stretch'],
|
|
47
|
-
...cropMode.map(mode => [mode, 'stretch'])
|
|
48
|
-
]);
|
|
49
|
-
const isNumber = (value) => typeof value === 'number';
|
|
50
|
-
const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2;
|
|
51
|
-
// const Svg = lazy(() => import('./svg'))
|
|
52
|
-
// const Fallback = (
|
|
53
|
-
// <View style={styls.suspense}>
|
|
54
|
-
// <Text>loading ...</Text>
|
|
55
|
-
// </View>
|
|
56
|
-
// )
|
|
57
|
-
const Image = forwardRef((props, ref) => {
|
|
58
|
-
const { src = '', mode = 'scaleToFill',
|
|
59
|
-
// svg = false,
|
|
60
|
-
style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindload, binderror } = props;
|
|
61
|
-
const defaultStyle = {
|
|
62
|
-
width: DEFAULT_IMAGE_WIDTH,
|
|
63
|
-
height: DEFAULT_IMAGE_HEIGHT
|
|
64
|
-
};
|
|
65
|
-
const styleObj = {
|
|
66
|
-
...defaultStyle,
|
|
67
|
-
...style,
|
|
68
|
-
overflow: 'hidden'
|
|
69
|
-
};
|
|
70
|
-
const nodeRef = useRef(null);
|
|
71
|
-
useNodesRef(props, ref, nodeRef, {
|
|
72
|
-
defaultStyle
|
|
73
|
-
});
|
|
74
|
-
const onLayout = ({ nativeEvent: { layout: { width, height } } }) => {
|
|
75
|
-
setViewWidth(width);
|
|
76
|
-
setViewHeight(height);
|
|
77
|
-
};
|
|
78
|
-
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
79
|
-
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout });
|
|
80
|
-
const { width, height } = normalStyle;
|
|
81
|
-
const preSrc = useRef();
|
|
82
|
-
const resizeMode = ModeMap.get(mode) || 'stretch';
|
|
83
|
-
const isWidthFixMode = mode === 'widthFix';
|
|
84
|
-
const isHeightFixMode = mode === 'heightFix';
|
|
85
|
-
const isCropMode = cropMode.includes(mode);
|
|
86
|
-
const source = typeof src === 'string' ? { uri: src } : src;
|
|
87
|
-
const [viewWidth, setViewWidth] = useState(isNumber(width) ? width : 0);
|
|
88
|
-
const [viewHeight, setViewHeight] = useState(isNumber(height) ? height : 0);
|
|
89
|
-
const [imageWidth, setImageWidth] = useState(0);
|
|
90
|
-
const [imageHeight, setImageHeight] = useState(0);
|
|
91
|
-
const [ratio, setRatio] = useState(0);
|
|
92
|
-
const [loaded, setLoaded] = useState(false);
|
|
93
|
-
const fixedHeight = useMemo(() => {
|
|
94
|
-
const fixed = viewWidth * ratio;
|
|
95
|
-
return !fixed ? viewHeight : fixed;
|
|
96
|
-
}, [ratio, viewWidth, viewHeight]);
|
|
97
|
-
const fixedWidth = useMemo(() => {
|
|
98
|
-
if (!ratio)
|
|
99
|
-
return viewWidth;
|
|
100
|
-
const fixed = viewHeight / ratio;
|
|
101
|
-
return !fixed ? viewWidth : fixed;
|
|
102
|
-
}, [ratio, viewWidth, viewHeight]);
|
|
103
|
-
const cropModeStyle = useMemo(() => {
|
|
104
|
-
switch (mode) {
|
|
105
|
-
case 'top':
|
|
106
|
-
return { top: 0, left: relativeCenteredSize(viewWidth, imageWidth) };
|
|
107
|
-
case 'bottom':
|
|
108
|
-
return { top: 'auto', bottom: 0, left: relativeCenteredSize(viewWidth, imageWidth) };
|
|
109
|
-
case 'center':
|
|
110
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: relativeCenteredSize(viewWidth, imageWidth) };
|
|
111
|
-
case 'left':
|
|
112
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: 0 };
|
|
113
|
-
case 'right':
|
|
114
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: 'auto', right: 0 };
|
|
115
|
-
case 'top left':
|
|
116
|
-
return { top: 0, left: 0 };
|
|
117
|
-
case 'top right':
|
|
118
|
-
return { top: 0, left: 'auto', right: 0 };
|
|
119
|
-
case 'bottom left':
|
|
120
|
-
return { top: 'auto', bottom: 0, left: 0 };
|
|
121
|
-
case 'bottom right':
|
|
122
|
-
return { top: 'auto', bottom: 0, left: 'auto', right: 0 };
|
|
123
|
-
default:
|
|
124
|
-
return {};
|
|
125
|
-
}
|
|
126
|
-
}, [mode, viewWidth, viewHeight, imageWidth, imageHeight]);
|
|
127
|
-
const onImageLoad = (evt) => {
|
|
128
|
-
if (!bindload)
|
|
129
|
-
return;
|
|
130
|
-
if (typeof src === 'string') {
|
|
131
|
-
evt.persist();
|
|
132
|
-
RNImage.getSize(src, (width, height) => {
|
|
133
|
-
bindload(getCustomEvent('load', evt, {
|
|
134
|
-
detail: { width, height },
|
|
135
|
-
layoutRef
|
|
136
|
-
}, props));
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
const { width = 0, height = 0 } = RNImage.resolveAssetSource(src) || {};
|
|
141
|
-
bindload(getCustomEvent('load', evt, {
|
|
142
|
-
detail: { width, height },
|
|
143
|
-
layoutRef
|
|
144
|
-
}, props));
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
const onImageError = (evt) => {
|
|
148
|
-
binderror &&
|
|
149
|
-
binderror(getCustomEvent('error', evt, {
|
|
150
|
-
detail: { errMsg: evt.nativeEvent.error },
|
|
151
|
-
layoutRef
|
|
152
|
-
}, props));
|
|
153
|
-
};
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
if (!isWidthFixMode && !isHeightFixMode && !isCropMode) {
|
|
156
|
-
setLoaded(true);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const changed = preSrc.current !== src;
|
|
160
|
-
preSrc.current = src;
|
|
161
|
-
changed && setLoaded(false);
|
|
162
|
-
if (typeof src === 'string') {
|
|
163
|
-
RNImage.getSize(src, (width, height) => {
|
|
164
|
-
if (isWidthFixMode || isHeightFixMode) {
|
|
165
|
-
setRatio(width === 0 ? 0 : height / width);
|
|
166
|
-
}
|
|
167
|
-
if (isCropMode) {
|
|
168
|
-
setImageWidth(width);
|
|
169
|
-
setImageHeight(height);
|
|
170
|
-
}
|
|
171
|
-
changed && setLoaded(true);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
const { width = 0, height = 0 } = RNImage.resolveAssetSource(src) || {};
|
|
176
|
-
if (isWidthFixMode || isHeightFixMode) {
|
|
177
|
-
setRatio(width === 0 ? 0 : height / width);
|
|
178
|
-
}
|
|
179
|
-
if (isCropMode) {
|
|
180
|
-
setImageWidth(width);
|
|
181
|
-
setImageHeight(height);
|
|
182
|
-
}
|
|
183
|
-
changed && setLoaded(true);
|
|
184
|
-
}
|
|
185
|
-
}, [isWidthFixMode, isHeightFixMode, isCropMode, src]);
|
|
186
|
-
const innerProps = useInnerProps(props, {
|
|
187
|
-
ref: nodeRef,
|
|
188
|
-
style: {
|
|
189
|
-
...normalStyle,
|
|
190
|
-
...layoutStyle,
|
|
191
|
-
...(isHeightFixMode && { width: fixedWidth }),
|
|
192
|
-
...(isWidthFixMode && { height: fixedHeight })
|
|
193
|
-
},
|
|
194
|
-
...layoutProps
|
|
195
|
-
}, [], {
|
|
196
|
-
layoutRef
|
|
197
|
-
});
|
|
198
|
-
// if (typeof src === 'string' && REMOTE_SVG_REGEXP.test(src)) {
|
|
199
|
-
// return (
|
|
200
|
-
// <Suspense fallback={Fallback} {...innerProps}>
|
|
201
|
-
// <View {...innerProps}>
|
|
202
|
-
// <Svg src={src} style={style} width={width as SvgNumberProp} height={height as SvgNumberProp} />
|
|
203
|
-
// </View>
|
|
204
|
-
// </Suspense>
|
|
205
|
-
// )
|
|
206
|
-
// }
|
|
207
|
-
// if (svg) {
|
|
208
|
-
// return (
|
|
209
|
-
// <Suspense fallback={Fallback}>
|
|
210
|
-
// <View {...innerProps}>
|
|
211
|
-
// <Svg local src={src} style={style} width={width as SvgNumberProp} height={height as SvgNumberProp} />
|
|
212
|
-
// </View>
|
|
213
|
-
// </Suspense>
|
|
214
|
-
// )
|
|
215
|
-
// }
|
|
216
|
-
return (<View {...innerProps}>
|
|
217
|
-
{loaded && <RNImage source={source} resizeMode={resizeMode} onLoad={onImageLoad} onError={onImageError} style={{
|
|
218
|
-
...StyleSheet.absoluteFillObject,
|
|
219
|
-
width: isCropMode ? imageWidth : '100%',
|
|
220
|
-
height: isCropMode ? imageHeight : '100%',
|
|
221
|
-
...(isCropMode && cropModeStyle)
|
|
222
|
-
}}/>}
|
|
223
|
-
</View>);
|
|
224
|
-
});
|
|
225
|
-
Image.displayName = 'MpxImage';
|
|
226
|
-
export default Image;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { SvgCssUri, WithLocalSvg } from 'react-native-svg/css';
|
|
2
|
-
const Svg = ({ local = false, src, style, width, height }) => {
|
|
3
|
-
return local
|
|
4
|
-
? (<WithLocalSvg style={style} asset={src} width={width} height={height}/>)
|
|
5
|
-
: (<SvgCssUri style={style} uri={src} width={width} height={height}/>);
|
|
6
|
-
};
|
|
7
|
-
export default Svg;
|