@mpxjs/webpack-plugin 2.9.66 → 2.9.69-beta.0

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.
Files changed (158) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +24 -18
  8. package/lib/platform/style/wx/index.js +49 -47
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  11. package/lib/platform/template/wx/component-config/index.js +1 -1
  12. package/lib/platform/template/wx/component-config/input.js +1 -1
  13. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  16. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  17. package/lib/react/index.js +4 -3
  18. package/lib/react/processJSON.js +5 -13
  19. package/lib/react/processMainScript.js +7 -3
  20. package/lib/react/processScript.js +3 -4
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +5 -2
  23. package/lib/resolver/AddModePlugin.js +20 -7
  24. package/lib/runtime/components/react/context.ts +6 -0
  25. package/lib/runtime/components/react/dist/context.js +2 -0
  26. package/lib/runtime/components/react/dist/event.config.js +24 -24
  27. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  28. package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
  29. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
  41. package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
  42. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
  44. package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
  45. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
  46. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
  47. package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
  48. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  50. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  51. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  56. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  57. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
  58. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
  63. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  64. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
  65. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
  67. package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
  68. package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
  69. package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
  70. package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
  71. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  72. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  73. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  74. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  75. package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
  76. package/lib/runtime/components/react/dist/utils.jsx +80 -24
  77. package/lib/runtime/components/react/event.config.ts +25 -26
  78. package/lib/runtime/components/react/getInnerListeners.ts +237 -198
  79. package/lib/runtime/components/react/mpx-button.tsx +105 -58
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
  91. package/lib/runtime/components/react/mpx-form.tsx +62 -57
  92. package/lib/runtime/components/react/mpx-icon.tsx +13 -18
  93. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +139 -117
  95. package/lib/runtime/components/react/mpx-label.tsx +36 -34
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
  98. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  99. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  100. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  101. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  104. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  105. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  106. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  107. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  108. package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
  109. package/lib/runtime/components/react/mpx-radio.tsx +46 -55
  110. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  111. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  112. package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
  114. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  115. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
  116. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  117. package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
  118. package/lib/runtime/components/react/mpx-switch.tsx +39 -25
  119. package/lib/runtime/components/react/mpx-text.tsx +15 -19
  120. package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
  121. package/lib/runtime/components/react/mpx-view.tsx +93 -77
  122. package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
  123. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  124. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  125. package/lib/runtime/components/react/types/common.ts +2 -0
  126. package/lib/runtime/components/react/types/global.d.ts +5 -17
  127. package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
  128. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  129. package/lib/runtime/components/react/utils.tsx +113 -27
  130. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  131. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  132. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  133. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  134. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  135. package/lib/runtime/optionProcessor.js +7 -38
  136. package/lib/runtime/optionProcessorReact.js +0 -15
  137. package/lib/runtime/swanHelper.wxs +1 -1
  138. package/lib/runtime/utils.js +2 -0
  139. package/lib/style-compiler/index.js +1 -1
  140. package/lib/style-compiler/plugins/scope-id.js +31 -2
  141. package/lib/template-compiler/bind-this.js +7 -2
  142. package/lib/template-compiler/compiler.js +118 -56
  143. package/lib/template-compiler/gen-node-react.js +3 -3
  144. package/lib/template-compiler/index.js +4 -4
  145. package/lib/utils/pre-process-json.js +117 -0
  146. package/lib/web/index.js +5 -4
  147. package/lib/web/processJSON.js +5 -13
  148. package/lib/web/processTemplate.js +2 -2
  149. package/package.json +6 -4
  150. package/LICENSE +0 -433
  151. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  152. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  153. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  154. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  155. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  156. package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
  157. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  158. package/lib/runtime/components/web/event.js +0 -105
@@ -116,6 +116,8 @@ let i18nInjectableComputed = []
116
116
  let hasOptionalChaining = false
117
117
  let processingTemplate = false
118
118
  const rulesResultMap = new Map()
119
+ let usingComponents = []
120
+ let usingComponentsInfo = {}
119
121
 
120
122
  function updateForScopesMap () {
121
123
  forScopesMap = {}
@@ -633,6 +635,10 @@ function parse (template, options) {
633
635
  processingTemplate = false
634
636
  rulesResultMap.clear()
635
637
 
638
+ if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
639
+ usingComponents = Object.keys(options.usingComponentsInfo)
640
+ usingComponentsInfo = options.usingComponentsInfo
641
+
636
642
  const _warn = content => {
637
643
  const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, {
638
644
  warnArray: [],
@@ -654,7 +660,7 @@ function parse (template, options) {
654
660
  type: 'template',
655
661
  testKey: 'tag',
656
662
  data: {
657
- usingComponents: options.usingComponents
663
+ usingComponents
658
664
  },
659
665
  warn: _warn,
660
666
  error: _error
@@ -721,7 +727,7 @@ function parse (template, options) {
721
727
  stack.push(element)
722
728
  } else {
723
729
  element.unary = true
724
- closeElement(element, meta, options)
730
+ closeElement(element, options, meta)
725
731
  }
726
732
  },
727
733
 
@@ -736,7 +742,7 @@ function parse (template, options) {
736
742
  // pop stack
737
743
  stack.pop()
738
744
  currentParent = stack[stack.length - 1]
739
- closeElement(element, meta, options)
745
+ closeElement(element, options, meta)
740
746
  }
741
747
  },
742
748
 
@@ -761,7 +767,7 @@ function parse (template, options) {
761
767
  parent: currentParent
762
768
  }
763
769
  children.push(el)
764
- runtimeCompile ? processTextDynamic(el) : processText(el)
770
+ runtimeCompile ? processTextDynamic(el) : processText(el, options, meta)
765
771
  }
766
772
  },
767
773
  comment: function comment (text) {
@@ -804,7 +810,7 @@ function parse (template, options) {
804
810
 
805
811
  if (!tagNames.has('component') && options.checkUsingComponents) {
806
812
  const arr = []
807
- options.usingComponents.forEach((item) => {
813
+ usingComponents.forEach((item) => {
808
814
  if (!tagNames.has(item) && !options.globalComponents.includes(item) && !options.componentPlaceholder.includes(item)) {
809
815
  arr.push(item)
810
816
  }
@@ -980,7 +986,7 @@ function processComponentIs (el, options) {
980
986
 
981
987
  const range = getAndRemoveAttr(el, 'range').val
982
988
  const isInRange = makeMap(range || '')
983
- el.components = (options.usingComponents || []).filter(i => {
989
+ el.components = (usingComponents).filter(i => {
984
990
  if (!range) return true
985
991
  return isInRange(i)
986
992
  })
@@ -1160,7 +1166,7 @@ function processEventReact (el) {
1160
1166
  configs: []
1161
1167
  }
1162
1168
  }
1163
- eventConfigMap[type].configs.push(Object.assign({ name }, parsedFunc))
1169
+ eventConfigMap[type].configs.push(Object.assign({ name, value }, parsedFunc))
1164
1170
  }
1165
1171
  }
1166
1172
  })
@@ -1201,26 +1207,32 @@ function processEventReact (el) {
1201
1207
 
1202
1208
  // let wrapper
1203
1209
  for (const type in eventConfigMap) {
1204
- let { configs } = eventConfigMap[type]
1205
- configs.forEach(({ name }) => {
1206
- if (name) {
1207
- // 清空原始事件绑定
1208
- let has
1209
- do {
1210
- has = getAndRemoveAttr(el, name).has
1211
- } while (has)
1212
- }
1213
- })
1214
- configs = configs.map((item) => {
1215
- return item.expStr
1216
- })
1217
- const value = `{{(e)=>this.__invoke(e, [${configs}])}}`
1218
- addAttrs(el, [
1219
- {
1220
- name: type,
1221
- value
1222
- }
1223
- ])
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
+
1224
1236
  // 非button的情况下,press/longPress时间需要包裹TouchableWithoutFeedback进行响应,后续可支持配置
1225
1237
  // if ((type === 'press' || type === 'longPress') && el.tag !== 'mpx-button') {
1226
1238
  // if (!wrapper) {
@@ -1370,7 +1382,8 @@ function processEvent (el, options) {
1370
1382
  function processSlotReact (el, meta) {
1371
1383
  if (el.tag === 'slot') {
1372
1384
  el.slot = {
1373
- name: getAndRemoveAttr(el, 'name').val
1385
+ name: getAndRemoveAttr(el, 'name').val,
1386
+ slot: getAndRemoveAttr(el, 'slot').val
1374
1387
  }
1375
1388
  meta.options = meta.options || {}
1376
1389
  meta.options.disableMemo = true
@@ -1763,6 +1776,15 @@ function processRefReact (el, meta) {
1763
1776
  value: `{{ this.__getRefVal('${type}', [${selectorsConf}]) }}`
1764
1777
  }])
1765
1778
  }
1779
+
1780
+ if (el.tag === 'mpx-scroll-view' && el.attrsMap['scroll-into-view']) {
1781
+ addAttrs(el, [
1782
+ {
1783
+ name: '__selectRef',
1784
+ value: '{{ this.__selectRef.bind(this) }}'
1785
+ }
1786
+ ])
1787
+ }
1766
1788
  }
1767
1789
 
1768
1790
  function processRef (el, options, meta) {
@@ -1908,7 +1930,7 @@ function postProcessFor (el) {
1908
1930
  function postProcessForReact (el) {
1909
1931
  if (el.for) {
1910
1932
  if (el.for.key) {
1911
- 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')
1912
1934
  addAttrs(el, [{
1913
1935
  name: 'key',
1914
1936
  value: el.for.key
@@ -2022,7 +2044,7 @@ function postProcessIfReact (el) {
2022
2044
  }
2023
2045
  }
2024
2046
 
2025
- function processText (el) {
2047
+ function processText (el, options, meta) {
2026
2048
  if (el.type !== 3 || el.isComment) {
2027
2049
  return
2028
2050
  }
@@ -2032,17 +2054,38 @@ function processText (el) {
2032
2054
  }
2033
2055
  el.text = parsed.val
2034
2056
  if (isReact(mode)) {
2035
- processWrapTextReact(el)
2057
+ processWrapTextReact(el, options, meta)
2036
2058
  }
2037
2059
  }
2038
2060
 
2039
- // RN中文字需被Text包裹
2040
- function processWrapTextReact (el) {
2041
- const parentTag = el.parent.tag
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
2042
2066
  if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
2043
- const wrapper = createASTElement('Text')
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)
2044
2085
  replaceNode(el, wrapper, true)
2045
2086
  addChild(wrapper, el)
2087
+ processBuiltInComponents(wrapper, meta)
2088
+ processAttrs(wrapper, options)
2046
2089
  }
2047
2090
  }
2048
2091
 
@@ -2137,19 +2180,27 @@ function processStyle (el, meta) {
2137
2180
  }
2138
2181
 
2139
2182
  function isRealNode (el) {
2140
- const virtualNodeTagMap = ['block', 'template', 'import', config[mode].wxs.tag].reduce((map, item) => {
2183
+ const virtualNodeTagMap = ['block', 'template', 'import', 'slot', config[mode].wxs.tag].reduce((map, item) => {
2141
2184
  map[item] = true
2142
2185
  return map
2143
2186
  }, {})
2144
2187
  return !virtualNodeTagMap[el.tag]
2145
2188
  }
2146
2189
 
2147
- function isComponentNode (el, options) {
2148
- return options.usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
2190
+ function isComponentNode (el) {
2191
+ return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
2192
+ }
2193
+
2194
+ function getComponentInfo (el) {
2195
+ return usingComponentsInfo[el.tag] || {}
2196
+ }
2197
+
2198
+ function isReactComponent (el) {
2199
+ return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn
2149
2200
  }
2150
2201
 
2151
2202
  function processExternalClasses (el, options) {
2152
- const isComponent = isComponentNode(el, options)
2203
+ const isComponent = isComponentNode(el)
2153
2204
  const classLikeAttrNames = isComponent ? ['class'].concat(options.externalClasses) : ['class']
2154
2205
 
2155
2206
  classLikeAttrNames.forEach((classLikeAttrName) => {
@@ -2263,8 +2314,9 @@ function postProcessAliComponentRootView (el, options, meta) {
2263
2314
  { condition: /^style$/, action: 'move' },
2264
2315
  { condition: /^slot$/, action: 'move' }
2265
2316
  ]
2317
+ const mid = getComponentInfo(el).mid
2266
2318
  const processAppendAttrsRules = [
2267
- { name: 'class', value: `${MPX_ROOT_VIEW} host-${moduleId}` }
2319
+ { name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` }
2268
2320
  ]
2269
2321
  const newAttrs = []
2270
2322
  const allAttrs = cloneAttrsList(el.attrsList)
@@ -2341,12 +2393,11 @@ function getVirtualHostRoot (options, meta) {
2341
2393
  {
2342
2394
  name: 'class',
2343
2395
  value: `${MPX_ROOT_VIEW} host-${moduleId}`
2396
+ },
2397
+ {
2398
+ name: 'ishost',
2399
+ value: '{{true}}'
2344
2400
  }
2345
- // todo 运行时通过root标识确定是否合并rootProps
2346
- // {
2347
- // name: 'is-root',
2348
- // value: '{{true}}'
2349
- // }
2350
2401
  ])
2351
2402
  processElement(rootView, rootView, options, meta)
2352
2403
  return rootView
@@ -2370,7 +2421,7 @@ function processShow (el, options, root) {
2370
2421
  show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
2371
2422
  }
2372
2423
  if (show === undefined) return
2373
- if (isComponentNode(el, options)) {
2424
+ if (isComponentNode(el) && getComponentInfo(el).hasVirtualHost) {
2374
2425
  if (show === '') {
2375
2426
  show = '{{false}}'
2376
2427
  }
@@ -2594,16 +2645,19 @@ function processElement (el, root, options, meta) {
2594
2645
  }
2595
2646
 
2596
2647
  if (isReact(mode)) {
2648
+ const pass = isReactComponent(el, options)
2597
2649
  // 收集内建组件
2598
2650
  processBuiltInComponents(el, meta)
2599
2651
  // 预处理代码维度条件编译
2600
2652
  processIf(el)
2601
2653
  processFor(el)
2602
2654
  processRefReact(el, meta)
2603
- processStyleReact(el, options)
2604
- processEventReact(el)
2605
- processComponentIs(el, options)
2606
- processSlotReact(el, meta)
2655
+ if (!pass) {
2656
+ processStyleReact(el, options)
2657
+ processEventReact(el)
2658
+ processComponentIs(el, options)
2659
+ processSlotReact(el, meta)
2660
+ }
2607
2661
  processAttrs(el, options)
2608
2662
  return
2609
2663
  }
@@ -2640,7 +2694,7 @@ function processElement (el, root, options, meta) {
2640
2694
  processAttrs(el, options)
2641
2695
  }
2642
2696
 
2643
- function closeElement (el, meta, options) {
2697
+ function closeElement (el, options, meta) {
2644
2698
  postProcessAtMode(el)
2645
2699
  postProcessWxs(el, meta)
2646
2700
 
@@ -2656,11 +2710,19 @@ function closeElement (el, meta, options) {
2656
2710
  }
2657
2711
 
2658
2712
  const isTemplate = postProcessTemplate(el) || processingTemplate
2659
- if (!isNative && !isTemplate) {
2660
- if (isComponentNode(el, options) && !hasVirtualHost && mode === 'ali') {
2713
+ if (!isTemplate) {
2714
+ if (!isNative) {
2715
+ postProcessComponentIs(el, (child) => {
2716
+ if (!hasVirtualHost && mode === 'ali') {
2717
+ postProcessAliComponentRootView(child, options)
2718
+ } else {
2719
+ postProcessIf(child)
2720
+ }
2721
+ })
2722
+ }
2723
+ if (isComponentNode(el) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
2661
2724
  postProcessAliComponentRootView(el, options, meta)
2662
2725
  }
2663
- postProcessComponentIs(el)
2664
2726
  }
2665
2727
 
2666
2728
  if (runtimeCompile) {
@@ -2707,7 +2769,7 @@ function cloneAttrsList (attrsList) {
2707
2769
  })
2708
2770
  }
2709
2771
 
2710
- function postProcessComponentIs (el) {
2772
+ function postProcessComponentIs (el, postProcessChild) {
2711
2773
  if (el.is && el.components) {
2712
2774
  let tempNode
2713
2775
  if (el.for || el.if || el.elseif || el.else) {
@@ -2729,7 +2791,7 @@ function postProcessComponentIs (el) {
2729
2791
  })
2730
2792
  newChild.exps = el.exps
2731
2793
  addChild(tempNode, newChild)
2732
- postProcessIf(newChild)
2794
+ postProcessChild(newChild)
2733
2795
  })
2734
2796
 
2735
2797
  if (!el.parent) {
@@ -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 `_i(${node.for.exp}, function(${item},${index}){return ${genNode(node)}})`
22
+ return `this.__iter(${node.for.exp}, function(${item},${index}){return ${genNode(node)}})`
23
23
  }
24
24
 
25
25
  const s = JSON.stringify
@@ -56,8 +56,8 @@ function genNode (node) {
56
56
  return map
57
57
  }, {})
58
58
  if (node.slot) {
59
- const name = node.slot.name
60
- exp += `__getSlot(${name ? s(name) : ''})`
59
+ const { name, slot } = node.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) {
@@ -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 usingComponents = queryObj.usingComponents || []
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 || '_' + mpx.pathHash(resourcePath)
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.usingComponents),
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,117 @@
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 { matchCondition } = require('./match-condition')
10
+ const async = require('async')
11
+
12
+ module.exports = function ({
13
+ json,
14
+ srcMode,
15
+ emitWarning,
16
+ emitError,
17
+ ctorType,
18
+ resourcePath,
19
+ loaderContext
20
+ }, callback) {
21
+ const mpx = loaderContext.getMpx()
22
+ const context = loaderContext.context
23
+ const { mode, pagesMap, autoVirtualHostRules } = mpx
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, info) => {
82
+ usingComponentsInfo[name] = info
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
+ const hasVirtualHost = matchCondition(rawResourcePath, autoVirtualHostRules)
100
+ setUsingComponentInfo(name, {
101
+ mid: moduleId,
102
+ hasVirtualHost
103
+ })
104
+ callback()
105
+ })
106
+ }, (err) => {
107
+ finalCallback(err)
108
+ })
109
+ } else {
110
+ finalCallback()
111
+ }
112
+ } catch (err) {
113
+ finalCallback(err)
114
+ }
115
+ }
116
+ ], callback)
117
+ }
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
- usingComponents,
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(parts.json, {
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
- usingComponents,
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(parts.json, {
84
+ processJSON(jsonContent, {
84
85
  loaderContext,
85
86
  ctorType,
86
87
  pagesMap,
@@ -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 (json, {
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 (!json) {
84
+ if (!jsonContent) {
86
85
  return callback()
87
86
  }
88
- // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
89
87
  try {
90
- jsonObj = JSON5.parse(json.content)
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 & record globalComponents
101
- globalComponents: mpx.usingComponents
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
  }
@@ -12,7 +12,7 @@ module.exports = function (template, {
12
12
  srcMode,
13
13
  moduleId,
14
14
  ctorType,
15
- usingComponents,
15
+ usingComponentsInfo,
16
16
  componentGenerics
17
17
  }, callback) {
18
18
  const mpx = loaderContext.getMpx()
@@ -73,7 +73,7 @@ module.exports = function (template, {
73
73
  const { root, meta } = templateCompiler.parse(template.content, {
74
74
  warn,
75
75
  error,
76
- usingComponents,
76
+ usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
77
77
  hasComment,
78
78
  isNative,
79
79
  ctorType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.66",
3
+ "version": "2.9.69-beta.0",
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.65",
31
+ "@mpxjs/utils": "^2.9.69",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -82,7 +82,8 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@ant-design/react-native": "^5.2.2",
85
- "@mpxjs/api-proxy": "^2.9.66",
85
+ "@d11/react-native-fast-image": "^8.6.12",
86
+ "@mpxjs/api-proxy": "^2.9.69",
86
87
  "@types/babel-traverse": "^6.25.4",
87
88
  "@types/babel-types": "^7.0.4",
88
89
  "@types/react": "^18.2.79",
@@ -90,6 +91,7 @@
90
91
  "react-native-gesture-handler": "^2.18.1",
91
92
  "react-native-linear-gradient": "^2.8.3",
92
93
  "react-native-reanimated": "^3.15.2",
94
+ "react-native-svg": "^15.8.0",
93
95
  "react-native-safe-area-context": "^4.12.0",
94
96
  "react-native-webview": "^13.12.2",
95
97
  "rimraf": "^6.0.1"
@@ -97,5 +99,5 @@
97
99
  "engines": {
98
100
  "node": ">=14.14.0"
99
101
  },
100
- "gitHead": "ff9eb06a3be28538870823cebf813ed56f39bbd7"
102
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
101
103
  }