@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
@@ -201,6 +201,11 @@ module.exports = function getSpec ({ warn, error }) {
201
201
  const props = AbbreviationMap[prop]
202
202
  const values = Array.isArray(value) ? value : parseValues(value)
203
203
  const cssMap = []
204
+ // 复合属性不支持单个css var(css var可以接收单个值可以是复合值,复合值运行时不处理,这里前置提示一下)
205
+ if (values.length === 1 && cssVariableExp.test(value)) {
206
+ error(`Property ${prop} in ${selector} is abbreviated property and does not support a single CSS var`)
207
+ return cssMap
208
+ }
204
209
  let idx = 0
205
210
  let propsIdx = 0
206
211
  const diff = values.length - props.length
@@ -296,16 +301,12 @@ module.exports = function getSpec ({ warn, error }) {
296
301
  all: 'background'
297
302
  }
298
303
  const urlExp = /url\(["']?(.*?)["']?\)/
299
- const linerExp = /linear-gradient\(.*\)\s*$/
304
+ const linearExp = /linear-gradient\(.*\)/
300
305
  switch (prop) {
301
306
  case bgPropMap.image: {
302
- // background-image 仅支持背景图
303
- const imgUrl = value.match(urlExp)?.[0]
304
- const linerVal = value.match(linerExp)?.[0]
305
- if (imgUrl) {
306
- return { prop, value: imgUrl }
307
- } else if (linerVal) {
308
- return { prop, value: linerVal }
307
+ // background-image 支持背景图/渐变/css var
308
+ if (cssVariableExp.test(value) || urlExp.test(value) || linearExp.test(value)) {
309
+ return { prop, value }
309
310
  } else {
310
311
  error(`Value of ${prop} in ${selector} selector only support value <url()> or <linear-gradient()>, received ${value}, please check again!`)
311
312
  return false
@@ -344,11 +345,15 @@ module.exports = function getSpec ({ warn, error }) {
344
345
  }
345
346
  case bgPropMap.all: {
346
347
  // background: 仅支持 background-image & background-color & background-repeat
348
+ if (cssVariableExp.test(value)) {
349
+ error(`Property [${bgPropMap.all}] in ${selector} is abbreviated property and does not support CSS var`)
350
+ return false
351
+ }
347
352
  const bgMap = []
348
353
  const values = parseValues(value)
349
354
  values.forEach(item => {
350
355
  const url = item.match(urlExp)?.[0]
351
- const linerVal = item.match(linerExp)?.[0]
356
+ const linerVal = item.match(linearExp)?.[0]
352
357
  if (url) {
353
358
  bgMap.push({ prop: bgPropMap.image, value: url })
354
359
  } else if (linerVal) {
@@ -368,7 +373,8 @@ module.exports = function getSpec ({ warn, error }) {
368
373
 
369
374
  // transform 转换
370
375
  const formatTransform = ({ prop, value, selector }, { mode }) => {
371
- if (Array.isArray(value)) return { prop, value }
376
+ // css var & 数组直接返回
377
+ if (Array.isArray(value) || calcExp.test(value)) return { prop, value }
372
378
  const values = parseValues(value)
373
379
  const transform = []
374
380
  values.forEach(item => {
@@ -393,7 +399,7 @@ module.exports = function getSpec ({ warn, error }) {
393
399
  break
394
400
  case 'matrix':
395
401
  case 'matrix3d':
396
- transform.push({ [key]: val.split(',').map(val => +val) })
402
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) })
397
403
  break
398
404
  case 'translate':
399
405
  case 'scale':
@@ -404,7 +410,7 @@ module.exports = function getSpec ({ warn, error }) {
404
410
  {
405
411
  // 2 个以上的值处理
406
412
  key = key.replace('3d', '')
407
- const vals = val.split(',').splice(0, key === 'rotate' ? 4 : 3)
413
+ const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3)
408
414
  // scale(.5) === scaleX(.5) scaleY(.5)
409
415
  if (vals.length === 1 && key === 'scale') {
410
416
  vals.push(vals[0])
@@ -450,14 +456,17 @@ module.exports = function getSpec ({ warn, error }) {
450
456
 
451
457
  const formatFlex = ({ prop, value, selector }) => {
452
458
  let values = parseValues(value)
459
+ // 值大于3 去前三
453
460
  if (values.length > 3) {
454
- error(`Value of [flex] in ${selector} supports up to three values, received [${value}], please check again!`)
461
+ warn(`Value of [flex] in ${selector} supports up to three values, received [${value}], please check again!`)
455
462
  values = values.splice(0, 3)
456
463
  }
457
464
  const cssMap = []
458
- const lastOne = values[values.length - 1]
459
- const isAuto = lastOne === 'auto'
460
- // 枚举值 none initial
465
+ // 单个css var 直接设置 flex 属性
466
+ if (values.length === 1 && cssVariableExp.test(value)) {
467
+ return { prop, value }
468
+ }
469
+ // 包含枚举值 none initial
461
470
  if (values.includes('initial') || values.includes('none')) {
462
471
  // css flex: initial ===> flex: 0 1 ===> rn flex 0 1
463
472
  // css flex: none ===> css flex: 0 0 ===> rn flex 0 0
@@ -470,38 +479,31 @@ module.exports = function getSpec ({ warn, error }) {
470
479
  }
471
480
  return cssMap
472
481
  }
473
- // 最后一个值是flexBasis 的有效值(auto或者有单位百分比、px等)
474
- // flex 0 1 auto flex auto flex 1 auto flex 1 30px flex 1 10% flex 1 1 auto
475
- if (!isNumber(lastOne) || !cssVariableExp.test(value)) {
476
- // 添加 grow shrink
477
- // 在设置 flex basis 有效值的场景下,如果没有设置 grow shrink,则默认为1
478
- // 单值 flex: 1 1 <flex-basis>
479
- // 双值 flex: <flex-grow> 1 <flex-basis>
480
- // 三值 flex: <flex-grow> <flex-shrink> <flex-basis>
481
- for (let i = 0; i < 2; i++) {
482
- const item = getIntegersFlex({ prop: AbbreviationMap[prop][i], value: isNumber(values[i]) || cssVariableExp.test(value) ? values[i] : 1 })
482
+ // 只有1-2个值且最后的值是flexBasis 的有效值(auto或者有单位百分比、px等)
483
+ // 在设置 flex basis 有效值的场景下,如果没有设置 grow shrink,则默认为1
484
+ // 单值 flex: 1 1 <flex-basis>
485
+ // 双值 flex: <flex-grow> 1 <flex-basis>
486
+ // 三值 flex: <flex-grow> <flex-shrink> <flex-basis>
487
+ for (let i = 0; i < 3; i++) {
488
+ if (i < 2) {
489
+ // 添加 grow shrink
490
+ const isValid = isNumber(values[0]) || cssVariableExp.test(values[0])
491
+ // 兜底 1
492
+ const val = isValid ? values[0] : 1
493
+ const item = getIntegersFlex({ prop: AbbreviationMap[prop][i], value: val, selector })
483
494
  item && cssMap.push(item)
495
+ isValid && values.shift()
496
+ } else {
497
+ // 添加 flexBasis
498
+ // 有单位(百分比、px等) 的 value 赋值 flexBasis,auto 不处理,兜底 0
499
+ const val = values[0] || 0
500
+ if (val !== 'auto') {
501
+ cssMap.push({
502
+ prop: 'flexBasis',
503
+ value: val
504
+ })
505
+ }
484
506
  }
485
- if (!isAuto) {
486
- // 有单位(百分比、px等) 的 value 赋值 flexBasis,auto 不处理
487
- cssMap.push({
488
- prop: 'flexBasis',
489
- value: lastOne
490
- })
491
- }
492
- return cssMap
493
- }
494
- // 纯数值:value 按flex-grow flex-shrink flex-basis 顺序赋值
495
- // 兜底 shrink & basis
496
- if (values.length === 1) {
497
- values.push(...[1, 0])
498
- } else if (values.length === 2) {
499
- values.push(0)
500
- }
501
- // 循环赋值
502
- for (let i = 0; i < values.length; i++) {
503
- const item = getIntegersFlex({ prop: AbbreviationMap[prop][i], value: values[i] })
504
- item && cssMap.push(item)
505
507
  }
506
508
  return cssMap
507
509
  }
@@ -509,7 +511,7 @@ module.exports = function getSpec ({ warn, error }) {
509
511
  const formatFontFamily = ({ prop, value, selector }) => {
510
512
  // 去掉引号 取逗号分隔后的第一个
511
513
  const newVal = value.replace(/"|'/g, '').trim()
512
- const values = newVal.split(',').filter(i => i)
514
+ const values = parseValues(newVal, ',')
513
515
  if (!newVal || !values.length) {
514
516
  error(`Value of [${prop}] is invalid in ${selector}, received [${value}], please check again!`)
515
517
  return false
@@ -8,6 +8,14 @@ module.exports = function ({ print }) {
8
8
  const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
9
9
  return {
10
10
  test: TAG_NAME,
11
+ android (tag, { el }) {
12
+ el.isBuiltIn = true
13
+ return 'mpx-canvas'
14
+ },
15
+ ios (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'mpx-canvas'
18
+ },
11
19
  props: [
12
20
  {
13
21
  test: /^canvas-id$/,
@@ -1,21 +1,24 @@
1
1
  const { isOriginTag, isBuildInTag } = require('../../../../utils/dom-tag-config')
2
2
 
3
3
  module.exports = function () {
4
+ const handleComponentTag = (el, data) => {
5
+ const newTag = `mpx-com-${el.tag}`
6
+ const usingComponents = data.usingComponents || []
7
+ // 当前组件名与原生tag或内建tag同名,对组件名进行转义
8
+ // json转义见:platform/json/wx/index.js fixComponentName
9
+ if (usingComponents.includes(newTag)) {
10
+ el.tag = newTag
11
+ }
12
+ return el
13
+ }
14
+
4
15
  return {
5
16
  waterfall: true,
6
17
  skipNormalize: true,
7
- supportedModes: ['web'],
18
+ supportedModes: ['web', 'ios', 'android'],
8
19
  test: (input) => isOriginTag(input) || isBuildInTag(input),
9
- // 输出web时对组件名进行转义避免与原生tag和内建tag冲突
10
- web (el, data) {
11
- const newTag = `mpx-com-${el.tag}`
12
- const usingComponents = data.usingComponents || []
13
- // 当前组件名与原生tag或内建tag同名,对组件名进行转义
14
- // json转义见:platform/json/wx/index.js fixComponentName
15
- if (usingComponents.includes(newTag)) {
16
- el.tag = newTag
17
- }
18
- return el
19
- }
20
+ web: handleComponentTag,
21
+ ios: handleComponentTag,
22
+ android: handleComponentTag
20
23
  }
21
24
  }
@@ -82,8 +82,8 @@ module.exports = function getComponentConfigs ({ warn, error }) {
82
82
 
83
83
  // 转换规则只需以微信为基准配置微信和支付宝的差异部分,比如微信和支付宝都支持但是写法不一致,或者微信支持而支付宝不支持的部分(抛出错误或警告)
84
84
  return [
85
- ...unsupported({ print }),
86
85
  fixComponentName({ print }),
86
+ ...unsupported({ print }),
87
87
  ad({ print }),
88
88
  view({ print }),
89
89
  scrollView({ print }),
@@ -92,7 +92,7 @@ module.exports = function ({ print }) {
92
92
  qa: qaPropLog
93
93
  },
94
94
  {
95
- test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|safe-password-.+)$/,
95
+ test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|safe-password-.+)$/,
96
96
  ios: iosPropLog,
97
97
  android: androidPropLog
98
98
  }
@@ -12,6 +12,14 @@ module.exports = function ({ print }) {
12
12
  el.isBuiltIn = true
13
13
  return 'mpx-rich-text'
14
14
  },
15
+ ios (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'mpx-rich-text'
18
+ },
19
+ android (tag, { el }) {
20
+ el.isBuiltIn = true
21
+ return 'mpx-rich-text'
22
+ },
15
23
  props: [
16
24
  {
17
25
  test: /^(space)$/,
@@ -31,7 +31,7 @@ module.exports = function ({ print }) {
31
31
  },
32
32
  props: [
33
33
  {
34
- test: /^(display-multiple-items|skip-hidden-item-layout|easing-function)$/,
34
+ test: /^(display-multiple-items|skip-hidden-item-layout)$/,
35
35
  ali: aliPropLog
36
36
  },
37
37
  {
@@ -78,7 +78,7 @@ module.exports = function ({ print }) {
78
78
  }
79
79
  },
80
80
  {
81
- test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
81
+ test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
82
82
  ios: iosPropLog,
83
83
  android: androidPropLog
84
84
  }
@@ -11,7 +11,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
11
11
  // 快应用不支持的标签集合
12
12
  const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
13
13
  // RN不支持的标签集合
14
- const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'progress', 'rich-text', 'slider', 'audio', 'camera', 'video', 'canvas', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
14
+ const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'progress', 'slider', 'audio', 'camera', 'video', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
15
15
 
16
16
  /**
17
17
  * @param {function(object): function} print
@@ -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
@@ -50,7 +51,7 @@ module.exports = function ({
50
51
  srcMode,
51
52
  moduleId,
52
53
  ctorType,
53
- usingComponents,
54
+ usingComponentsInfo,
54
55
  componentGenerics
55
56
  }, callback)
56
57
  },
@@ -63,7 +64,7 @@ module.exports = function ({
63
64
  }, callback)
64
65
  },
65
66
  (callback) => {
66
- processJSON(parts.json, {
67
+ processJSON(jsonContent, {
67
68
  loaderContext,
68
69
  ctorType,
69
70
  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,
@@ -81,12 +80,11 @@ module.exports = function (json, {
81
80
  }
82
81
 
83
82
  const isApp = ctorType === 'app'
84
- if (!json) {
83
+ if (!jsonContent) {
85
84
  return callback()
86
85
  }
87
- // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
88
86
  try {
89
- jsonObj = JSON5.parse(json.content)
87
+ jsonObj = JSON5.parse(jsonContent)
90
88
  // 处理runner
91
89
  const rulesRunnerOptions = {
92
90
  mode,
@@ -96,8 +94,8 @@ module.exports = function (json, {
96
94
  warn: emitWarning,
97
95
  error: emitError,
98
96
  data: {
99
- // polyfill global usingComponents & record globalComponents
100
- globalComponents: mpx.usingComponents
97
+ // polyfill global usingComponents
98
+ globalComponents: mpx.globalComponents
101
99
  }
102
100
  }
103
101
 
@@ -110,12 +108,6 @@ module.exports = function (json, {
110
108
  if (rulesRunner) {
111
109
  rulesRunner(jsonObj)
112
110
  }
113
- if (isApp) {
114
- // 收集全局组件
115
- Object.assign(mpx.usingComponents, jsonObj.usingComponents)
116
- // 在 rulesRunner 运行后保存全局注册组件
117
- loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
118
- }
119
111
  } catch (e) {
120
112
  return callback(e)
121
113
  }
@@ -8,7 +8,7 @@ const {
8
8
  module.exports = function ({
9
9
  loaderContext
10
10
  }, callback) {
11
- const { i18n, projectName } = loaderContext.getMpx()
11
+ const { i18n, rnConfig } = loaderContext.getMpx()
12
12
 
13
13
  let output = 'import { AppRegistry } from \'react-native\'\n'
14
14
 
@@ -16,8 +16,12 @@ module.exports = function ({
16
16
  output += buildI18n({ loaderContext })
17
17
  }
18
18
  // 此处可添加前置于App执行的语句
19
- output += `var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
20
- output += `AppRegistry.registerComponent(${JSON.stringify(projectName)}, () => App)\n`
19
+ output += `var app = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
20
+ if (rnConfig.projectName) {
21
+ output += `AppRegistry.registerComponent(${JSON.stringify(rnConfig.projectName)}, () => app)\n`
22
+ } else {
23
+ output += 'export default app\n'
24
+ }
21
25
 
22
26
  callback(null, {
23
27
  output
@@ -24,16 +24,15 @@ module.exports = function (script, {
24
24
  if (ctorType === 'app') {
25
25
  output += `
26
26
  import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
27
- import { NavigationContainer, createNavigationContainerRef, StackActions } from '@react-navigation/native'
28
- import { createNativeStackNavigator } from '@react-navigation/native-stack'
27
+ import { NavigationContainer, StackActions } from '@react-navigation/native'
28
+ import { createStackNavigator } from '@react-navigation/stack'
29
29
  import { Provider } from '@ant-design/react-native'
30
30
  import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
31
31
  import { GestureHandlerRootView } from 'react-native-gesture-handler'
32
32
 
33
33
  global.__navigationHelper = {
34
34
  NavigationContainer: NavigationContainer,
35
- createNavigationContainerRef: createNavigationContainerRef,
36
- createNativeStackNavigator: createNativeStackNavigator,
35
+ createStackNavigator: createStackNavigator,
37
36
  StackActions: StackActions,
38
37
  GestureHandlerRootView: GestureHandlerRootView,
39
38
  Provider: Provider,
@@ -56,13 +56,23 @@ module.exports = function (styles, {
56
56
  error
57
57
  })
58
58
  if (ctorType === 'app') {
59
- output += `global.__getAppClassMap = function() {
60
- return ${shallowStringify(classMap)};
59
+ output += `
60
+ let __appClassMap
61
+ global.__getAppClassMap = function() {
62
+ if(!__appClassMap) {
63
+ __appClassMap = ${shallowStringify(classMap)};
64
+ }
65
+ return __appClassMap;
61
66
  };\n`
62
67
  } else {
63
- output += `global.currentInject.injectMethods = {
68
+ output += `
69
+ let __classMap
70
+ global.currentInject.injectMethods = {
64
71
  __getClassMap: function() {
65
- return ${shallowStringify(classMap)};
72
+ if(!__classMap) {
73
+ __classMap = ${shallowStringify(classMap)};
74
+ }
75
+ return __classMap;
66
76
  }
67
77
  };\n`
68
78
  }
@@ -14,7 +14,7 @@ module.exports = function (template, {
14
14
  srcMode,
15
15
  moduleId,
16
16
  ctorType,
17
- usingComponents,
17
+ usingComponentsInfo,
18
18
  componentGenerics
19
19
  }, callback) {
20
20
  const mpx = loaderContext.getMpx()
@@ -64,7 +64,7 @@ module.exports = function (template, {
64
64
  const { root, meta } = templateCompiler.parse(template.content, {
65
65
  warn,
66
66
  error,
67
- usingComponents,
67
+ usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
68
68
  hasComment,
69
69
  isNative,
70
70
  ctorType,
@@ -119,6 +119,9 @@ module.exports = function (template, {
119
119
  }, meta.wxsModuleMap)
120
120
  const bindResult = bindThis.transform(rawCode, {
121
121
  ignoreMap
122
+ // customBindThis (path, t) {
123
+ // path.replaceWith(t.callExpression(t.identifier('getValue'), [t.stringLiteral(path.node.name)]))
124
+ // }
122
125
  })
123
126
  output += `global.currentInject.render = function (createElement, getComponent) {
124
127
  return ${bindResult.code}
@@ -6,16 +6,17 @@ const addInfix = require('../utils/add-infix')
6
6
  const { JSON_JS_EXT } = require('../utils/const')
7
7
 
8
8
  module.exports = class AddModePlugin {
9
- constructor (source, mode, fileConditionRules, target) {
9
+ constructor (source, mode, options, target) {
10
10
  this.source = source
11
11
  this.target = target
12
12
  this.mode = mode
13
- this.fileConditionRules = fileConditionRules
13
+ this.options = options
14
14
  }
15
15
 
16
16
  apply (resolver) {
17
17
  const target = resolver.ensureHook(this.target)
18
- const mode = this.mode
18
+ const { options = {}, mode } = this
19
+ const { defaultMode, fileConditionRules, implicitMode } = options
19
20
  resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
20
21
  if (request.mode || request.env) {
21
22
  return callback()
@@ -31,14 +32,26 @@ module.exports = class AddModePlugin {
31
32
  extname = path.extname(resourcePath)
32
33
  }
33
34
  // 当前资源没有后缀名或者路径不符合fileConditionRules规则时,直接返回
34
- if (!extname || !matchCondition(resourcePath, this.fileConditionRules)) return callback()
35
+ if (!extname || !matchCondition(resourcePath, fileConditionRules)) return callback()
35
36
  const queryObj = parseQuery(request.query || '?')
36
- queryObj.mode = mode
37
- queryObj.infix = `${queryObj.infix || ''}.${mode}`
37
+ const queryInfix = queryObj.infix
38
+ if (!implicitMode) queryObj.mode = mode
39
+ queryObj.infix = `${queryInfix || ''}.${mode}`
38
40
  obj.query = stringifyQuery(queryObj)
39
41
  obj.path = addInfix(resourcePath, mode, extname)
40
42
  obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
41
- resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, callback)
43
+ resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, (err, result) => {
44
+ if (defaultMode && !result) {
45
+ queryObj.infix = `${queryInfix || ''}.${defaultMode}`
46
+ obj.query = stringifyQuery(queryObj)
47
+ obj.path = addInfix(resourcePath, defaultMode, extname)
48
+ resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + defaultMode, resolveContext, (err, result) => {
49
+ callback(err, result)
50
+ })
51
+ return
52
+ }
53
+ callback(err, result)
54
+ })
42
55
  })
43
56
  }
44
57
  }
@@ -5,6 +5,8 @@ export type LabelContextValue = MutableRefObject<{
5
5
  triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
6
6
  }>
7
7
 
8
+ export type KeyboardAvoidContextValue = (enabled: boolean) => void
9
+
8
10
  export interface GroupValue {
9
11
  [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
10
12
  }
@@ -46,3 +48,7 @@ export const PickerContext = createContext(null)
46
48
  export const VarContext = createContext({})
47
49
 
48
50
  export const IntersectionObserverContext = createContext<IntersectionObserver | null>(null)
51
+
52
+ export const RouteContext = createContext<number | null>(null)
53
+
54
+ export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
@@ -7,3 +7,5 @@ export const LabelContext = createContext(null);
7
7
  export const PickerContext = createContext(null);
8
8
  export const VarContext = createContext({});
9
9
  export const IntersectionObserverContext = createContext(null);
10
+ export const RouteContext = createContext(null);
11
+ export const KeyboardAvoidContext = createContext(null);
@@ -1,27 +1,27 @@
1
1
  const eventConfigMap = {
2
- bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
3
- bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
4
- bindtouchstart: ['onTouchStart'],
5
- bindtouchmove: ['onTouchMove'],
6
- bindtouchend: ['onTouchEnd'],
7
- bindtouchcancel: ['onTouchCancel'],
8
- catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
9
- catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
10
- catchtouchstart: ['onTouchStart'],
11
- catchtouchmove: ['onTouchMove'],
12
- catchtouchend: ['onTouchEnd'],
13
- catchtouchcancel: ['onTouchCancel'],
14
- 'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
15
- 'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
16
- 'capture-bindtouchstart': ['onTouchStartCapture'],
17
- 'capture-bindtouchmove': ['onTouchMoveCapture'],
18
- 'capture-bindtouchend': ['onTouchEndCapture'],
19
- 'capture-bindtouchcancel': ['onTouchCancelCapture'],
20
- 'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
21
- 'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
22
- 'capture-catchtouchstart': ['onTouchStartCapture'],
23
- 'capture-catchtouchmove': ['onTouchMoveCapture'],
24
- 'capture-catchtouchend': ['onTouchEndCapture'],
25
- 'capture-catchtouchcancel': ['onTouchCancelCapture']
2
+ bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
3
+ bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
4
+ bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
5
+ bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
6
+ bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
7
+ bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
8
+ catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
9
+ catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
10
+ catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
11
+ catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
12
+ catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
13
+ catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
14
+ 'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
15
+ 'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
16
+ 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
17
+ 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
18
+ 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
19
+ 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
20
+ 'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
21
+ 'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
22
+ 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
23
+ 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
24
+ 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
25
+ 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
26
26
  };
27
27
  export default eventConfigMap;