@mpxjs/webpack-plugin 2.9.59 → 2.9.64

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 (115) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +344 -270
  3. package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
  4. package/lib/platform/template/wx/component-config/checkbox.js +8 -0
  5. package/lib/platform/template/wx/component-config/cover-image.js +15 -0
  6. package/lib/platform/template/wx/component-config/cover-view.js +9 -0
  7. package/lib/platform/template/wx/component-config/form.js +13 -1
  8. package/lib/platform/template/wx/component-config/icon.js +8 -0
  9. package/lib/platform/template/wx/component-config/index.js +5 -1
  10. package/lib/platform/template/wx/component-config/label.js +15 -0
  11. package/lib/platform/template/wx/component-config/movable-area.js +18 -1
  12. package/lib/platform/template/wx/component-config/movable-view.js +18 -1
  13. package/lib/platform/template/wx/component-config/navigator.js +8 -0
  14. package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
  15. package/lib/platform/template/wx/component-config/picker-view.js +18 -2
  16. package/lib/platform/template/wx/component-config/picker.js +14 -1
  17. package/lib/platform/template/wx/component-config/radio-group.js +8 -0
  18. package/lib/platform/template/wx/component-config/radio.js +8 -0
  19. package/lib/platform/template/wx/component-config/root-portal.js +15 -0
  20. package/lib/platform/template/wx/component-config/switch.js +8 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -3
  22. package/lib/react/processScript.js +2 -0
  23. package/lib/react/processStyles.js +1 -0
  24. package/lib/react/processTemplate.js +2 -3
  25. package/lib/react/style-helper.js +12 -7
  26. package/lib/runtime/components/react/context.ts +40 -0
  27. package/lib/runtime/components/react/dist/context.js +8 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
  30. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
  32. package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
  33. package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
  34. package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
  35. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
  45. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
  48. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
  53. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
  54. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
  55. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
  56. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
  57. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  58. package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
  59. package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
  60. package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/types/common.js +1 -0
  65. package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
  66. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  67. package/lib/runtime/components/react/getInnerListeners.ts +43 -21
  68. package/lib/runtime/components/react/mpx-button.tsx +129 -119
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
  71. package/lib/runtime/components/react/mpx-form.tsx +117 -0
  72. package/lib/runtime/components/react/mpx-icon.tsx +106 -0
  73. package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
  74. package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
  75. package/lib/runtime/components/react/mpx-input.tsx +90 -42
  76. package/lib/runtime/components/react/mpx-label.tsx +110 -0
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
  79. package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
  80. package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
  81. package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
  82. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
  83. package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
  84. package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
  85. package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
  86. package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
  87. package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
  88. package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
  89. package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
  90. package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
  91. package/lib/runtime/components/react/mpx-radio.tsx +230 -0
  92. package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
  93. package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
  94. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
  95. package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
  96. package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
  98. package/lib/runtime/components/react/mpx-switch.tsx +148 -0
  99. package/lib/runtime/components/react/mpx-text.tsx +53 -77
  100. package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
  101. package/lib/runtime/components/react/mpx-view.tsx +576 -195
  102. package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
  103. package/lib/runtime/components/react/parser.ts +245 -0
  104. package/lib/runtime/components/react/types/common.ts +12 -0
  105. package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
  106. package/lib/runtime/components/react/types/global.d.ts +17 -1
  107. package/lib/runtime/components/react/useNodesRef.ts +4 -10
  108. package/lib/runtime/components/react/utils.tsx +505 -0
  109. package/lib/runtime/optionProcessor.js +19 -17
  110. package/lib/template-compiler/compiler.js +84 -61
  111. package/lib/template-compiler/gen-node-react.js +7 -9
  112. package/lib/web/processStyles.js +2 -5
  113. package/package.json +8 -3
  114. package/lib/runtime/components/react/dist/utils.js +0 -80
  115. package/lib/runtime/components/react/utils.ts +0 -92
@@ -990,7 +990,7 @@ function processComponentIs (el, options) {
990
990
  const eventIdentifier = '__mpx_event__'
991
991
 
992
992
  function parseFuncStr (str, extraStr = '') {
993
- const funcRE = /^([^()]+)(\((.*)\))?/
993
+ const funcRE = /^(.*{{.+}}[^()]*|[^()]+)(\((.*)\))?/
994
994
  const match = funcRE.exec(str)
995
995
  if (match) {
996
996
  const funcName = parseMustacheWithContext(match[1]).result
@@ -1068,7 +1068,10 @@ function processStyleReact (el, options) {
1068
1068
  let staticStyle = getAndRemoveAttr(el, 'style').val || ''
1069
1069
  staticStyle = staticStyle.replace(/\s+/g, ' ')
1070
1070
 
1071
- const show = getAndRemoveAttr(el, config[mode].directive.show).val
1071
+ const { val: show, has } = getAndRemoveAttr(el, config[mode].directive.show)
1072
+ if (has && show === undefined) {
1073
+ error$1(`Attrs ${config[mode].directive.show} should have a value `)
1074
+ }
1072
1075
 
1073
1076
  if (dynamicClass || staticClass || dynamicStyle || staticStyle || show) {
1074
1077
  const staticClassExp = parseMustacheWithContext(staticClass).result
@@ -1080,14 +1083,14 @@ function processStyleReact (el, options) {
1080
1083
  addAttrs(el, [{
1081
1084
  name: 'style',
1082
1085
  // runtime helper
1083
- value: `{{this.__getStyle(${staticClassExp}, ${dynamicClassExp}, ${staticStyleExp}, ${dynamicStyleExp}, ${showExp})}}`
1086
+ value: `{{this.__getStyle(${staticClassExp}, ${dynamicClassExp}, ${staticStyleExp}, ${dynamicStyleExp}${show === undefined ? '' : `, !(${showExp})`})}}`
1084
1087
  }])
1085
1088
  }
1086
1089
 
1087
1090
  if (staticHoverClass && staticHoverClass !== 'none') {
1088
1091
  const staticClassExp = parseMustacheWithContext(staticHoverClass).result
1089
1092
  addAttrs(el, [{
1090
- name: 'hoverStyle',
1093
+ name: 'hover-style',
1091
1094
  value: `{{this.__getStyle(${staticClassExp})}}`
1092
1095
  }])
1093
1096
  }
@@ -1355,11 +1358,13 @@ function processEvent (el, options) {
1355
1358
  }
1356
1359
  }
1357
1360
 
1358
- function processSlotReact (el) {
1361
+ function processSlotReact (el, meta) {
1359
1362
  if (el.tag === 'slot') {
1360
1363
  el.slot = {
1361
1364
  name: getAndRemoveAttr(el, 'name').val
1362
1365
  }
1366
+ meta.options = meta.options || {}
1367
+ meta.options.disableMemo = true
1363
1368
  }
1364
1369
  }
1365
1370
 
@@ -1720,34 +1725,33 @@ function processRefReact (el, meta) {
1720
1725
  type
1721
1726
  }
1722
1727
 
1728
+ const selectors = []
1729
+
1730
+ /**
1731
+ * selectorsConf: [type, [[prefix, selector], [prefix, selector]]]
1732
+ */
1723
1733
  if (!val) {
1724
- refConf.key = `ref_rn_${++refId}`
1725
- refConf.sKeys = []
1726
1734
  const rawId = el.attrsMap.id
1727
1735
  const rawClass = el.attrsMap.class
1728
1736
  const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
1729
1737
 
1730
- meta.computed = meta.computed || []
1731
1738
  if (rawId) {
1732
1739
  const staticId = parseMustacheWithContext(rawId).result
1733
- const computedIdKey = `_ri${refId}`
1734
- refConf.sKeys.push({ key: computedIdKey, prefix: '#' })
1735
- meta.computed.push(`${computedIdKey}() {\n return ${staticId}}`)
1740
+ selectors.push({ prefix: '#', selector: `${staticId}` })
1736
1741
  }
1737
1742
  if (rawClass || rawDynamicClass) {
1738
1743
  const staticClass = parseMustacheWithContext(rawClass).result
1739
1744
  const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
1740
- const computedClassKey = `_rc${refId}`
1741
- refConf.sKeys.push({ key: computedClassKey, prefix: '.' })
1742
- meta.computed.push(`${computedClassKey}() {\n return this.__getClass(${staticClass}, ${dynamicClass})}`)
1745
+ selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
1743
1746
  }
1747
+ } else {
1748
+ meta.refs.push(refConf)
1749
+ selectors.push({ prefix: '', selector: `"${refConf.key}"` })
1744
1750
  }
1745
-
1746
- meta.refs.push(refConf)
1747
-
1751
+ const selectorsConf = selectors.map(item => `["${item.prefix}", ${item.selector}]`)
1748
1752
  addAttrs(el, [{
1749
1753
  name: 'ref',
1750
- value: `{{ this.__getRefVal('${refConf.key}') }}`
1754
+ value: `{{ this.__getRefVal('${type}', [${selectorsConf}]) }}`
1751
1755
  }])
1752
1756
  }
1753
1757
  }
@@ -2329,7 +2333,7 @@ function getVirtualHostRoot (options, meta) {
2329
2333
  if (ctorType === 'component') {
2330
2334
  if (mode === 'wx' && hasVirtualHost) {
2331
2335
  // wx组件注入virtualHost配置
2332
- !meta.options && (meta.options = {})
2336
+ meta.options = meta.options || {}
2333
2337
  meta.options.virtualHost = true
2334
2338
  }
2335
2339
  if (mode === 'web' && !hasVirtualHost) {
@@ -2353,8 +2357,12 @@ function getVirtualHostRoot (options, meta) {
2353
2357
  name: 'class',
2354
2358
  value: `${MPX_ROOT_VIEW} host-${moduleId}`
2355
2359
  }
2360
+ // todo 运行时通过root标识确定是否合并rootProps
2361
+ // {
2362
+ // name: 'is-root',
2363
+ // value: '{{true}}'
2364
+ // }
2356
2365
  ])
2357
- rootView.isRoot = true
2358
2366
  processElement(rootView, rootView, options, meta)
2359
2367
  return rootView
2360
2368
  }
@@ -2441,12 +2449,26 @@ function isValidModeP (i) {
2441
2449
 
2442
2450
  const wrapRE = /^\((.*)\)$/
2443
2451
 
2444
- function processAtMode (el) {
2445
- // 父节点的atMode匹配状态不应该影响子节点,atMode的影响范围应该限制在当前节点本身
2446
- // if (el.parent && el.parent._atModeStatus) {
2447
- // el._atModeStatus = el.parent._atModeStatus
2448
- // }
2452
+ // MATCH: mode 与 env 都匹配,节点/属性保留,但不做跨平台转换
2453
+ // IMPLICITMATCH: mode 与 env 匹配,节点/属性保留,属于隐式匹配,做跨平台转换
2454
+ // MISMATCH: mode env不匹配,节点/属性直接删除
2455
+ const statusEnum = {
2456
+ MISMATCH: 1,
2457
+ IMPLICITMATCH: 2,
2458
+ MATCH: 3
2459
+ }
2449
2460
 
2461
+ // 父节点的atMode匹配状态不应该影响子节点,atMode的影响范围应该限制在当前节点本身
2462
+ function setModeStatus (target, status) {
2463
+ // 高优status才可以覆盖低优status,status枚举值代表优先级
2464
+ if (!target._matchStatus) {
2465
+ target._matchStatus = status
2466
+ } else if (status > target._matchStatus) {
2467
+ target._matchStatus = status
2468
+ }
2469
+ }
2470
+
2471
+ function processAtMode (el) {
2450
2472
  const attrsListClone = cloneAttrsList(el.attrsList)
2451
2473
  attrsListClone.forEach(item => {
2452
2474
  const attrName = item.name || ''
@@ -2483,40 +2505,41 @@ function processAtMode (el) {
2483
2505
  const attrValue = getAndRemoveAttr(el, attrName).val
2484
2506
  const replacedAttrName = attrArr.join('@')
2485
2507
  const processedAttr = { name: replacedAttrName, value: attrValue }
2486
-
2508
+ const target = replacedAttrName ? processedAttr : el
2509
+ // 循环 conditionMap
2510
+ // 判断 env 是否匹配
2511
+ // 判断 mode 是否匹配
2512
+ // 额外处理attr value 场景
2487
2513
  for (let [defineMode, defineEnvArr] of conditionMap.entries()) {
2488
2514
  const isImplicitMode = defineMode[0] === '_'
2489
2515
  if (isImplicitMode) defineMode = defineMode.slice(1)
2490
- if (defineMode === 'noMode' || defineMode === mode) {
2491
- // 命中 env 规则(没有定义env 或者定义的envArr包含当前env)
2492
- if (!defineEnvArr.length || defineEnvArr.includes(env)) {
2493
- if (!replacedAttrName) {
2494
- if (defineMode === 'noMode' || isImplicitMode) {
2495
- // 若defineMode 为 noMode 或 implicitMode,则 element 都需要进行规则转换
2496
- } else {
2497
- el._atModeStatus = 'match'
2498
- }
2499
- } else {
2500
- if (defineMode === 'noMode' || isImplicitMode) {
2501
- // 若defineMode 为 noMode 或 implicitMode,则直接将 attr 挂载回 el,进行规则转换
2502
- addAttrs(el, [processedAttr])
2503
- } else {
2504
- // 如果命中了指定的mode,且当前 mode 不为 noMode 或 implicitMode,则把不需要转换的 attrs 暂存在 noTransAttrs 上,等规则转换后再挂载回去
2505
- el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
2506
- }
2507
- }
2508
- // 命中mode,命中env,完成匹配,直接退出
2516
+
2517
+ const isNoMode = defineMode === 'noMode'
2518
+ const isMatchMode = isNoMode || defineMode === mode
2519
+ const isMatchEnv = !defineEnvArr.length || defineEnvArr.includes(env)
2520
+ let matchStatus = statusEnum.MISMATCH
2521
+ // 是否为针对于节点的条件判断,否为节点属性
2522
+ if (isMatchMode && isMatchEnv) {
2523
+ // mpxTagName 特殊标签,需要做转换保留处理
2524
+ matchStatus = (isNoMode || isImplicitMode || replacedAttrName === 'mpxTagName') ? statusEnum.IMPLICITMATCH : statusEnum.MATCH
2525
+ }
2526
+ setModeStatus(target, matchStatus)
2527
+ }
2528
+ // 解析处理attr._matchStatus
2529
+ if (replacedAttrName) {
2530
+ switch (processedAttr._matchStatus) {
2531
+ // IMPLICITMATCH保留属性并进行平台转换
2532
+ case statusEnum.IMPLICITMATCH:
2533
+ addAttrs(el, [processedAttr])
2509
2534
  break
2510
- } else if (!replacedAttrName) {
2511
- // 命中mode规则,没有命中当前env规则,设置为 'mismatch'
2512
- el._atModeStatus = 'mismatch'
2513
- }
2514
- } else if (!replacedAttrName) {
2515
- // 没有命中当前mode规则,设置为 'mismatch'
2516
- el._atModeStatus = 'mismatch'
2517
- } else {
2518
- // 如果没命中指定的mode,则该属性删除
2535
+ // MATCH保留属性并跳过平台转换
2536
+ case statusEnum.MATCH:
2537
+ el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
2538
+ break
2539
+ default:
2540
+ // MISMATCH丢弃属性
2519
2541
  }
2542
+ delete processedAttr._matchStatus
2520
2543
  }
2521
2544
  }
2522
2545
  })
@@ -2564,15 +2587,17 @@ function processMpxTagName (el) {
2564
2587
  function processElement (el, root, options, meta) {
2565
2588
  processAtMode(el)
2566
2589
  // 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
2567
- if (el._atModeStatus === 'mismatch') {
2590
+ if (el._matchStatus === statusEnum.MISMATCH) {
2568
2591
  return
2569
2592
  }
2570
2593
 
2594
+ processMpxTagName(el)
2595
+
2571
2596
  if (runtimeCompile && options.dynamicTemplateRuleRunner) {
2572
2597
  options.dynamicTemplateRuleRunner(el, options, config[mode])
2573
2598
  }
2574
2599
 
2575
- if (rulesRunner && el._atModeStatus !== 'match') {
2600
+ if (rulesRunner && el._matchStatus !== statusEnum.MATCH) {
2576
2601
  currentEl = el
2577
2602
  rulesRunner(el)
2578
2603
  }
@@ -2581,8 +2606,6 @@ function processElement (el, root, options, meta) {
2581
2606
 
2582
2607
  processDuplicateAttrsList(el)
2583
2608
 
2584
- processMpxTagName(el)
2585
-
2586
2609
  processInjectWxs(el, meta, options)
2587
2610
 
2588
2611
  const transAli = mode === 'ali' && srcMode === 'wx'
@@ -2607,7 +2630,7 @@ function processElement (el, root, options, meta) {
2607
2630
  processStyleReact(el, options)
2608
2631
  processEventReact(el)
2609
2632
  processComponentIs(el, options)
2610
- processSlotReact(el)
2633
+ processSlotReact(el, meta)
2611
2634
  processAttrs(el, options)
2612
2635
  return
2613
2636
  }
@@ -2684,8 +2707,8 @@ function collectDynamicInfo (el, options, meta) {
2684
2707
  }
2685
2708
 
2686
2709
  function postProcessAtMode (el) {
2687
- if (el._atModeStatus === 'mismatch') {
2688
- removeNode(el, true)
2710
+ if (el._matchStatus === statusEnum.MISMATCH) {
2711
+ removeNode(el)
2689
2712
  }
2690
2713
  }
2691
2714
 
@@ -60,9 +60,7 @@ function genNode (node) {
60
60
  exp += `__getSlot(${name ? s(name) : ''})`
61
61
  } else {
62
62
  exp += `createElement(${`getComponent(${node.is || s(node.tag)})`}`
63
- if (node.isRoot) {
64
- exp += `, Object.assign({}, rootProps, {style: [${attrExpMap.style}, rootProps.style]})`
65
- } else if (node.attrsList.length) {
63
+ if (node.attrsList.length) {
66
64
  const attrs = []
67
65
  node.attrsList && node.attrsList.forEach(({ name, value }) => {
68
66
  const attrExp = attrExpMap[name] ? attrExpMap[name] : s(value)
@@ -75,17 +73,17 @@ function genNode (node) {
75
73
 
76
74
  if (!node.unary && node.children.length) {
77
75
  exp += ','
78
- node.children.forEach(function (child, index) {
79
- exp += `${index === 0 ? '' : ','}${genNode(child)}`
80
- })
76
+ exp += node.children.map((child) => {
77
+ return genNode(child)
78
+ }).filter(fragment => fragment).join(',')
81
79
  }
82
80
  exp += ')'
83
81
  }
84
82
  }
85
83
  } else {
86
- node.children.forEach(function (child, index) {
87
- exp += `${index === 0 ? '' : ','}${genNode(child)}`
88
- })
84
+ exp += node.children.map((child) => {
85
+ return genNode(child)
86
+ }).filter(fragment => fragment).join(',')
89
87
  }
90
88
  }
91
89
  }
@@ -8,11 +8,8 @@ module.exports = function (styles, options, callback) {
8
8
  attrs (style) {
9
9
  const attrs = Object.assign({}, style.attrs)
10
10
  if (options.autoScope) attrs.scoped = true
11
- attrs.mpxStyleOptions = JSON.stringify({
12
- // scoped: !!options.autoScope,
13
- // query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
14
- mid: options.moduleId
15
- })
11
+ // query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
12
+ attrs.mid = options.moduleId
16
13
  return attrs
17
14
  }
18
15
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.59",
3
+ "version": "2.9.64",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,6 +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.64",
31
32
  "acorn": "^8.11.3",
32
33
  "acorn-walk": "^7.2.0",
33
34
  "async": "^2.6.0",
@@ -41,7 +42,7 @@
41
42
  "html-minifier": "^3.5.8",
42
43
  "icss-utils": "^2.1.0",
43
44
  "json5": "^2.1.3",
44
- "loader-utils": "^2.0.2",
45
+ "loader-utils": "^2.0.0",
45
46
  "lodash": "^4.17.15",
46
47
  "lodash.camelcase": "^4.3.0",
47
48
  "lru-cache": "^4.1.2",
@@ -81,14 +82,18 @@
81
82
  },
82
83
  "devDependencies": {
83
84
  "@ant-design/react-native": "^5.2.2",
85
+ "@mpxjs/api-proxy": "^2.9.64",
84
86
  "@types/babel-traverse": "^6.25.4",
85
87
  "@types/babel-types": "^7.0.4",
86
88
  "@types/react": "^18.2.79",
87
89
  "react-native": "^0.74.5",
90
+ "react-native-gesture-handler": "^2.18.1",
91
+ "react-native-linear-gradient": "^2.8.3",
92
+ "react-native-webview": "^13.12.2",
88
93
  "rimraf": "^6.0.1"
89
94
  },
90
95
  "engines": {
91
96
  "node": ">=14.14.0"
92
97
  },
93
- "gitHead": "aa001c11cc7b21772fc6f9f5bcdd13118fc6d67c"
98
+ "gitHead": "803334dc0e600f219d514c27461aa7663b7a6653"
94
99
  }
@@ -1,80 +0,0 @@
1
- import { useEffect, useRef, Children, isValidElement } from 'react';
2
- import { StyleSheet } from 'react-native';
3
- export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
4
- export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
5
- const URL_REGEX = /url\(["']?(.*?)["']?\)/;
6
- export function omit(obj, fields) {
7
- const shallowCopy = Object.assign({}, obj);
8
- for (let i = 0; i < fields.length; i += 1) {
9
- const key = fields[i];
10
- delete shallowCopy[key];
11
- }
12
- return shallowCopy;
13
- }
14
- /**
15
- * 从 style 中提取 TextStyle
16
- * @param style
17
- * @returns
18
- */
19
- export const extractTextStyle = (style) => {
20
- return Object.entries(StyleSheet.flatten(style)).reduce((textStyle, [key, value]) => {
21
- TEXT_STYLE_REGEX.test(key) && Object.assign(textStyle, { [key]: value });
22
- return textStyle;
23
- }, {});
24
- };
25
- /**
26
- * 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
27
- */
28
- export const useUpdateEffect = (effect, deps) => {
29
- const isMounted = useRef(false);
30
- // for react-refresh
31
- useEffect(() => {
32
- return () => {
33
- isMounted.current = false;
34
- };
35
- }, []);
36
- useEffect(() => {
37
- if (!isMounted.current) {
38
- isMounted.current = true;
39
- }
40
- else {
41
- return effect();
42
- }
43
- }, deps);
44
- };
45
- /**
46
- * 解析行内样式
47
- * @param inlineStyle
48
- * @returns
49
- */
50
- export const parseInlineStyle = (inlineStyle = '') => {
51
- return inlineStyle.split(';').reduce((styleObj, style) => {
52
- const [k, v, ...rest] = style.split(':');
53
- if (rest.length || !v || !k)
54
- return styleObj;
55
- const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
56
- return Object.assign(styleObj, { [key]: v.trim() });
57
- }, {});
58
- };
59
- export const parseUrl = (cssUrl = '') => {
60
- if (!cssUrl)
61
- return;
62
- const match = cssUrl.match(URL_REGEX);
63
- return match?.[1];
64
- };
65
- export const getRestProps = (transferProps = {}, originProps = {}, deletePropsKey = []) => {
66
- return {
67
- ...transferProps,
68
- ...omit(originProps, deletePropsKey)
69
- };
70
- };
71
- export const isText = (ele) => {
72
- if (isValidElement(ele)) {
73
- const displayName = ele.type?.displayName;
74
- return displayName === 'mpx-text' || displayName === 'Text';
75
- }
76
- return false;
77
- };
78
- export function every(children, callback) {
79
- return Children.toArray(children).every((child) => callback(child));
80
- }
@@ -1,92 +0,0 @@
1
- import { useEffect, useRef, Children, ReactNode, FunctionComponent, isValidElement } from 'react'
2
- import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'
3
-
4
- export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
5
-
6
- export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
7
-
8
- const URL_REGEX = /url\(["']?(.*?)["']?\)/
9
-
10
- export function omit<T, K extends string>(obj: T, fields: K[]): Omit<T, K> {
11
- const shallowCopy: any = Object.assign({}, obj)
12
- for (let i = 0; i < fields.length; i += 1) {
13
- const key = fields[i]
14
- delete shallowCopy[key]
15
- }
16
- return shallowCopy
17
- }
18
-
19
- /**
20
- * 从 style 中提取 TextStyle
21
- * @param style
22
- * @returns
23
- */
24
- export const extractTextStyle = (style: StyleProp<ViewStyle & TextStyle>): TextStyle => {
25
- return Object.entries(StyleSheet.flatten(style)).reduce((textStyle, [key, value]) => {
26
- TEXT_STYLE_REGEX.test(key) && Object.assign(textStyle, { [key]: value })
27
- return textStyle
28
- }, {})
29
- }
30
-
31
- /**
32
- * 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
33
- */
34
- export const useUpdateEffect = (effect: any, deps: any) => {
35
- const isMounted = useRef(false)
36
-
37
- // for react-refresh
38
- useEffect(() => {
39
- return () => {
40
- isMounted.current = false
41
- }
42
- }, [])
43
-
44
- useEffect(() => {
45
- if (!isMounted.current) {
46
- isMounted.current = true
47
- } else {
48
- return effect()
49
- }
50
- }, deps)
51
- }
52
-
53
- /**
54
- * 解析行内样式
55
- * @param inlineStyle
56
- * @returns
57
- */
58
- export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
59
- return inlineStyle.split(';').reduce((styleObj, style) => {
60
- const [k, v, ...rest] = style.split(':')
61
- if (rest.length || !v || !k) return styleObj
62
- const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
63
- return Object.assign(styleObj, { [key]: v.trim() })
64
- }, {})
65
- }
66
-
67
- export const parseUrl = (cssUrl: string = '') => {
68
- if (!cssUrl) return
69
-
70
- const match = cssUrl.match(URL_REGEX)
71
-
72
- return match?.[1]
73
- }
74
-
75
- export const getRestProps = (transferProps: any = {}, originProps: any = {}, deletePropsKey: any = []) => {
76
- return {
77
- ...transferProps,
78
- ...omit(originProps, deletePropsKey)
79
- }
80
- }
81
-
82
- export const isText = (ele: ReactNode) => {
83
- if (isValidElement(ele)) {
84
- const displayName = (ele.type as FunctionComponent)?.displayName
85
- return displayName === 'mpx-text' || displayName === 'Text'
86
- }
87
- return false
88
- }
89
-
90
- export function every(children: ReactNode, callback: (children: ReactNode) => boolean ) {
91
- return Children.toArray(children).every((child) => callback(child as ReactNode))
92
- }