@mpxjs/webpack-plugin 2.10.16 → 2.10.17-beta.10

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 (226) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  4. package/lib/dependencies/ResolveDependency.js +1 -1
  5. package/lib/file-loader.js +4 -1
  6. package/lib/global.d.ts +245 -0
  7. package/lib/helpers.js +2 -0
  8. package/lib/index.js +80 -19
  9. package/lib/json-compiler/helper.js +72 -2
  10. package/lib/json-compiler/index.js +45 -59
  11. package/lib/json-compiler/plugin.js +2 -2
  12. package/lib/loader.js +14 -4
  13. package/lib/native-loader.js +6 -3
  14. package/lib/platform/json/wx/index.js +30 -29
  15. package/lib/platform/style/wx/index.js +51 -36
  16. package/lib/platform/template/wx/component-config/ad.js +5 -0
  17. package/lib/platform/template/wx/component-config/button.js +22 -6
  18. package/lib/platform/template/wx/component-config/camera.js +25 -3
  19. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  20. package/lib/platform/template/wx/component-config/component.js +31 -33
  21. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  22. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  23. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  24. package/lib/platform/template/wx/component-config/form.js +27 -2
  25. package/lib/platform/template/wx/component-config/image.js +5 -0
  26. package/lib/platform/template/wx/component-config/input.js +11 -1
  27. package/lib/platform/template/wx/component-config/label.js +10 -2
  28. package/lib/platform/template/wx/component-config/map.js +11 -0
  29. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  30. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  31. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  32. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  33. package/lib/platform/template/wx/component-config/picker.js +3 -1
  34. package/lib/platform/template/wx/component-config/progress.js +11 -1
  35. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  36. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  37. package/lib/platform/template/wx/component-config/slider.js +8 -0
  38. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  39. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  40. package/lib/platform/template/wx/component-config/text.js +5 -0
  41. package/lib/platform/template/wx/component-config/textarea.js +20 -3
  42. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  43. package/lib/platform/template/wx/component-config/video.js +10 -0
  44. package/lib/platform/template/wx/index.js +21 -1
  45. package/lib/react/LoadAsyncChunkModule.js +1 -1
  46. package/lib/react/index.js +2 -0
  47. package/lib/react/processJSON.js +59 -72
  48. package/lib/react/processScript.js +1 -0
  49. package/lib/react/processStyles.js +24 -11
  50. package/lib/react/processTemplate.js +8 -6
  51. package/lib/react/script-helper.js +6 -17
  52. package/lib/react/style-helper.js +84 -13
  53. package/lib/resolver/AddModePlugin.js +23 -8
  54. package/lib/runtime/components/ali/mpx-recycle-view.mpx +518 -0
  55. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  56. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  57. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  58. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
  59. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  60. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  61. package/lib/runtime/components/react/context.ts +19 -7
  62. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  63. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  64. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  65. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
  66. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  67. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  68. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  69. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  70. package/lib/runtime/components/react/dist/context.d.ts +79 -0
  71. package/lib/runtime/components/react/dist/context.js +1 -0
  72. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  73. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  74. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  75. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  76. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  77. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  78. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  79. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  80. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  81. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  82. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  83. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  84. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  85. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  86. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  87. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  88. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  89. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  90. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  91. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  92. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  93. package/lib/runtime/components/react/dist/mpx-image.jsx +109 -59
  94. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  95. package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
  96. package/lib/runtime/components/react/dist/mpx-input.jsx +52 -17
  97. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  98. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +62 -49
  99. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  100. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  101. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +65 -0
  102. package/lib/runtime/components/react/dist/mpx-nav.d.ts +8 -0
  103. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  104. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  106. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  107. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  108. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  109. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  110. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  111. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  112. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  113. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +32 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  116. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +23 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  121. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +13 -0
  122. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  123. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  124. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  125. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  126. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  127. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  128. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  132. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts +23 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  135. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  136. package/lib/runtime/components/react/dist/mpx-recycle-view.d.ts +45 -0
  137. package/lib/runtime/components/react/dist/mpx-recycle-view.jsx +307 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  141. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  142. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  143. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  144. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  145. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  146. package/lib/runtime/components/react/dist/mpx-slider.d.ts +30 -0
  147. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  148. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  149. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  150. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +63 -0
  151. package/lib/runtime/components/react/dist/mpx-swiper.jsx +77 -44
  152. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  153. package/lib/runtime/components/react/dist/mpx-text.d.ts +22 -0
  154. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  155. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  156. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  157. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  158. package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
  159. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  160. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
  161. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  162. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  163. package/lib/runtime/components/react/dist/utils.d.ts +124 -0
  164. package/lib/runtime/components/react/dist/utils.jsx +42 -17
  165. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  166. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  167. package/lib/runtime/components/react/mpx-image.tsx +132 -79
  168. package/lib/runtime/components/react/mpx-input.tsx +63 -24
  169. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +70 -48
  170. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  171. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  172. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  173. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  174. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  175. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  176. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  177. package/lib/runtime/components/react/mpx-recycle-view.tsx +437 -0
  178. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  179. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -17
  180. package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -1
  181. package/lib/runtime/components/react/mpx-swiper.tsx +92 -42
  182. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  183. package/lib/runtime/components/react/mpx-view.tsx +28 -13
  184. package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
  185. package/lib/runtime/components/react/tsconfig.json +26 -0
  186. package/lib/runtime/components/react/types/common.d.ts +19 -0
  187. package/lib/runtime/components/react/types/global.d.ts +1 -0
  188. package/lib/runtime/components/react/utils.tsx +43 -21
  189. package/lib/runtime/components/web/mpx-recycle-view.vue +508 -0
  190. package/lib/runtime/components/wx/mpx-list-header-default.mpx +21 -0
  191. package/lib/runtime/components/wx/mpx-recycle-item-default.mpx +21 -0
  192. package/lib/runtime/components/wx/mpx-recycle-view.mpx +193 -0
  193. package/lib/runtime/components/wx/mpx-section-header-default.mpx +21 -0
  194. package/lib/runtime/optionProcessor.js +5 -0
  195. package/lib/runtime/optionProcessorReact.js +7 -0
  196. package/lib/runtime/stringify.wxs +2 -2
  197. package/lib/script-setup-compiler/index.js +2 -2
  198. package/lib/style-compiler/index.js +3 -2
  199. package/lib/style-compiler/load-postcss-config.js +1 -1
  200. package/lib/style-compiler/plugins/trans-special.js +10 -2
  201. package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
  202. package/lib/style-compiler/strip-conditional-loader.js +124 -18
  203. package/lib/template-compiler/compiler.js +272 -72
  204. package/lib/template-compiler/gen-node-react.js +18 -6
  205. package/lib/template-compiler/index.js +6 -4
  206. package/lib/template-compiler/parse-exps.js +1 -1
  207. package/lib/utils/const.js +19 -1
  208. package/lib/utils/dom-tag-config.js +6 -6
  209. package/lib/utils/env.js +6 -1
  210. package/lib/utils/get-build-tag-component.js +35 -0
  211. package/lib/utils/merge-visitors.js +55 -0
  212. package/lib/utils/pre-process-json.js +5 -0
  213. package/lib/utils/process-extend-components.js +43 -0
  214. package/lib/utils/string.js +25 -1
  215. package/lib/web/index.js +2 -0
  216. package/lib/web/processJSON.js +64 -18
  217. package/lib/web/processScript.js +1 -1
  218. package/lib/web/processTemplate.js +6 -4
  219. package/lib/web/script-helper.js +19 -9
  220. package/lib/wxs/pre-loader.js +9 -6
  221. package/lib/wxss/loader.js +1 -9
  222. package/package.json +11 -7
  223. package/LICENSE +0 -433
  224. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  225. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  226. package/lib/utils/chain-assign.js +0 -47
@@ -0,0 +1,21 @@
1
+ <template>
2
+ <view class="mpx-recycle-item-default">
3
+ <view class="mpx-default-content">recycle-item-default</view>
4
+ </view>
5
+ </template>
6
+
7
+ <style lang="stylus" scoped>
8
+ .mpx-recycle-item-default
9
+ margin 4px 16px
10
+ padding 16px
11
+ background #fff
12
+ border-radius 8px
13
+ box-shadow 0 2px 4px rgba(0,0,0,0.1)
14
+
15
+ .mpx-default-content
16
+ display flex
17
+ flex-direction column
18
+ font-size 14px
19
+ color #666
20
+
21
+ </style>
@@ -0,0 +1,193 @@
1
+ <template>
2
+ <scroll-view wx:ref="recycleViewRef" class="mpx-recycle-view" scroll-y wx:style="{{ scrollViewStyle }}" type="custom"
3
+ enhanced="{{ enhanced }}" scroll-with-animation="{{ scrollWithAnimation }}" bounces="{{ bounces }}"
4
+ show-scrollbar="{{ showScrollbar }}" refresher-enabled="{{ refresherEnabled }}"
5
+ refresher-triggered="{{ refresherTriggered }}" bindscroll="onScroll" bindrefresherrefresh="onRefresh"
6
+ scroll-into-view="{{ scrollIntoViewId }}" scroll-into-view-alignment="{{ viewPosition }}">
7
+ <block wx:if="{{ useListHeader }}">
8
+ <list-header listHeaderData="{{ listHeaderData }}"></list-header>
9
+ </block>
10
+ <block wx:for="{{ convertedListData }}" wx:key="index">
11
+ <sticky-section>
12
+ <!-- section header -->
13
+ <block wx:if="{{ item.hasSectionHeader }}">
14
+ <block wx:if="{{ enableSticky }}">
15
+ <sticky-header>
16
+ <section-header itemData="{{ item.headerData }}" id="{{ item._domId }}"></section-header>
17
+ </sticky-header>
18
+ </block>
19
+ <block wx:else>
20
+ <section-header itemData="{{ item.headerData }}" id="{{ item._domId }}"></section-header>
21
+ </block>
22
+
23
+ </block>
24
+ <block wx:for="{{ item.data }}" wx:for-item="subItem" wx:key="subIndex">
25
+ <!-- section items -->
26
+ <recycle-item itemData="{{ subItem.itemData }}" id="{{ subItem._domId }}"></recycle-item>
27
+ </block>
28
+ </sticky-section>
29
+ </block>
30
+ </scroll-view>
31
+ </template>
32
+
33
+ <script>
34
+ import { createComponent } from '@mpxjs/core'
35
+
36
+ createComponent({
37
+ properties: {
38
+ height: {
39
+ type: Number,
40
+ value: null
41
+ },
42
+ width: {
43
+ type: Number,
44
+ value: null
45
+ },
46
+ listData: {
47
+ type: Array,
48
+ value: []
49
+ },
50
+ enableSticky: {
51
+ type: Boolean,
52
+ value: false
53
+ },
54
+ showScrollbar: {
55
+ type: Boolean,
56
+ value: false
57
+ },
58
+ enhanced: {
59
+ type: Boolean,
60
+ value: false
61
+ },
62
+ bounces: {
63
+ type: Boolean,
64
+ value: false
65
+ },
66
+ refresherEnabled: {
67
+ type: Boolean,
68
+ value: false
69
+ },
70
+ refresherTriggered: {
71
+ type: Boolean,
72
+ value: false
73
+ },
74
+ listHeaderData: {
75
+ type: Object,
76
+ value: null
77
+ },
78
+ scrollWithAnimation: {
79
+ type: Boolean,
80
+ value: false
81
+ },
82
+ useListHeader: {
83
+ type: Boolean,
84
+ value: false
85
+ }
86
+ },
87
+ data: {
88
+ convertedListData: [],
89
+ scrollIntoViewId: '',
90
+ viewPosition: 'start'
91
+ },
92
+ computed: {
93
+ scrollViewStyle() {
94
+ return `height: ${this.formatDimension(this.height)};width: ${this.formatDimension(this.width)}`
95
+ }
96
+ },
97
+ watch: {
98
+ listData: {
99
+ handler(newVal) {
100
+ this.convertedListData = this.convertToSectionListData(newVal)
101
+ },
102
+ immediate: true
103
+ }
104
+ },
105
+ methods: {
106
+ formatDimension(value) {
107
+ return typeof value === 'number' ? `${value}px` : value || '100%'
108
+ },
109
+ onScroll(e) {
110
+ this.triggerEvent('scroll', e)
111
+ },
112
+ onRefresh(e) {
113
+ this.triggerEvent('refresh', e)
114
+ },
115
+ scrollToIndex({ index, animated, viewPosition = 0 }) {
116
+ if (index >= 0) {
117
+ this.scrollIntoViewId = `mpx-recycle-item-${index}`
118
+ switch (viewPosition) {
119
+ case 0:
120
+ this.viewPosition = 'start'
121
+ break
122
+ case 0.5:
123
+ this.viewPosition = 'center'
124
+ break
125
+ case 1:
126
+ this.viewPosition = 'end'
127
+ break
128
+ default:
129
+ this.viewPosition = 'start'
130
+ }
131
+ }
132
+ },
133
+ convertToSectionListData(data) {
134
+ const sections = []
135
+ let currentSection = null
136
+
137
+ data.forEach((item, index) => {
138
+ if (item.isSectionHeader) {
139
+ // 如果已经存在一个 section,先把它添加到 sections 中
140
+ if (currentSection) {
141
+ sections.push(currentSection)
142
+ }
143
+ // 创建新的 section
144
+ currentSection = {
145
+ headerData: item,
146
+ data: [],
147
+ hasSectionHeader: true,
148
+ _domId: `mpx-recycle-item-${index}`
149
+ }
150
+ } else {
151
+ // 如果没有当前 section,创建一个默认的
152
+ if (!currentSection) {
153
+ // 创建默认section (无header的section)
154
+ currentSection = {
155
+ headerData: null,
156
+ data: [],
157
+ hasSectionHeader: false
158
+ }
159
+ }
160
+ currentSection.data.push({
161
+ itemData: item,
162
+ _domId: `mpx-recycle-item-${index}`
163
+ })
164
+ }
165
+ })
166
+
167
+ // 添加最后一个 section
168
+ if (currentSection) {
169
+ sections.push(currentSection)
170
+ }
171
+
172
+ return sections
173
+ }
174
+ }
175
+ })
176
+ </script>
177
+
178
+ <script type="application/json">
179
+ {
180
+ "component": true,
181
+ "componentGenerics": {
182
+ "recycle-item": {
183
+ "default": "./mpx-recycle-item-default"
184
+ },
185
+ "section-header": {
186
+ "default": "./mpx-section-header-default"
187
+ },
188
+ "list-header": {
189
+ "default": "./mpx-list-header-default"
190
+ }
191
+ }
192
+ }
193
+ </script>
@@ -0,0 +1,21 @@
1
+ <template>
2
+ <view class="mpx-section-header-default">
3
+ <view class="mpx-default-content">section-header-default</view>
4
+ </view>
5
+ </template>
6
+
7
+ <style lang="stylus" scoped>
8
+ .mpx-section-header-default
9
+ margin 4px 16px
10
+ padding 16px
11
+ background #fff
12
+ border-radius 8px
13
+ box-shadow 0 2px 4px rgba(0,0,0,0.1)
14
+
15
+ .mpx-default-content
16
+ display flex
17
+ flex-direction column
18
+ font-size 14px
19
+ color #666
20
+
21
+ </style>
@@ -2,6 +2,7 @@ import { hasOwn, isEmptyObject, extend } from './utils'
2
2
  import { isBrowser } from './env'
3
3
  import transRpxStyle from './transRpxStyle'
4
4
  import animation from './animation'
5
+ import { error } from '@mpxjs/utils'
5
6
  const dash2hump = require('../utils/hump-dash').dash2hump
6
7
 
7
8
  export function processComponentOption (
@@ -107,6 +108,10 @@ registered in parent context!`)
107
108
 
108
109
  export function getComponent (component, extendOptions) {
109
110
  component = component.__esModule ? component.default : component
111
+ if (!component) {
112
+ error('getComponent() expected component options as the first argument, but got undefined.')
113
+ return null
114
+ }
110
115
  // eslint-disable-next-line
111
116
  if (extendOptions && !component.__mpxExtended) {
112
117
  extend(component, extendOptions, { __mpxExtended: true })
@@ -1,9 +1,16 @@
1
1
  import AsyncSuspense from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-async-suspense'
2
2
  import { memo, forwardRef, createElement } from 'react'
3
+ import { error } from '@mpxjs/utils'
3
4
  import { extend } from './utils'
4
5
 
5
6
  export function getComponent (component, extendOptions) {
6
7
  component = component.__esModule ? component.default : component
8
+ if (!component) {
9
+ error(
10
+ `getComponent expecting function/class component ${extendOptions?.displayName ? `[${extendOptions.displayName}] ` : ''}as the first argument, but got undefined.`
11
+ )
12
+ return null
13
+ }
7
14
  // eslint-disable-next-line
8
15
  if (extendOptions && !component.__mpxExtended) {
9
16
  extend(component, extendOptions, { __mpxExtended: true })
@@ -45,7 +45,7 @@ function objectKeys (obj) {
45
45
  }
46
46
 
47
47
  function genRegExp (str, flags) {
48
- if (!__mpx_wxs__) {
48
+ if (!__mpx_wxs__ || __mpx_mode__ === 'ks') {
49
49
  return new RegExp(str, flags)
50
50
  } else {
51
51
  return getRegExp(str, flags)
@@ -234,4 +234,4 @@ module.exports = {
234
234
  var parsedStaticStyle = typeof staticStyle === 'string' ? parseStyleText(staticStyle) : {}
235
235
  return genStyleText(extend(parsedStaticStyle, normalizedDynamicStyle))
236
236
  }
237
- }
237
+ }
@@ -98,7 +98,7 @@ function compileScriptSetup (
98
98
  ) {
99
99
  if (node) {
100
100
  throw new Error(
101
- `[@mpxjs/webpack-plugin script-setup-compiler] ${msg}\n\n${filePath}\n${formatCodeFrame(
101
+ `[Mpx script error]: ${msg}\n\n${filePath}\n${formatCodeFrame(
102
102
  content,
103
103
  node.start + startOffset,
104
104
  end
@@ -106,7 +106,7 @@ function compileScriptSetup (
106
106
  )
107
107
  } else {
108
108
  throw new Error(
109
- `[@mpxjs/webpack-plugin script-setup-compiler] ${msg}\n\n${filePath}\n`
109
+ `[Mpx script error]: ${msg}\n\n${filePath}\n`
110
110
  )
111
111
  }
112
112
  }
@@ -18,7 +18,8 @@ module.exports = function (css, map) {
18
18
  const { resourcePath, queryObj } = parseRequest(this.resource)
19
19
  const mpx = this.getMpx()
20
20
  const mpxStyleOptions = (queryObj.mpxStyleOptions && JSON.parse(queryObj.mpxStyleOptions)) || {}
21
- const id = queryObj.moduleId || mpxStyleOptions.mid || mpx.getModuleId(resourcePath)
21
+ const id = queryObj.moduleId || mpxStyleOptions.mid || mpx.getModuleId(resourcePath, false, (queryObj.moduleId || mpxStyleOptions.mid) ? null : this)
22
+
22
23
  const appInfo = mpx.appInfo
23
24
  const defs = mpx.defs
24
25
  const mode = mpx.mode
@@ -55,7 +56,7 @@ module.exports = function (css, map) {
55
56
  }
56
57
 
57
58
  if (isReact(mode)) {
58
- plugins.push(transSpecial({ id }))
59
+ plugins.push(transSpecial({ id, transPage: true }))
59
60
  }
60
61
 
61
62
  // plugins.push(pluginCondStrip({
@@ -29,7 +29,7 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
29
29
  if (err.message.indexOf('No PostCSS Config found') >= 0) {
30
30
  return
31
31
  }
32
- loaderContext.emitWarning(`Error loading PostCSS config: ${err.message}`)
32
+ loaderContext.emitWarning(`[Mpx style warning]: Error loading PostCSS config: ${err.message}`)
33
33
  })
34
34
  }
35
35
 
@@ -1,7 +1,8 @@
1
1
  const selectorParser = require('postcss-selector-parser')
2
+ const { MPX_TAG_PAGE_SELECTOR } = require('../../utils/const')
2
3
  // trans-special
3
4
 
4
- module.exports = ({ id }) => {
5
+ module.exports = ({ id, transPage = false }) => {
5
6
  return {
6
7
  postcssPlugin: 'trans-special',
7
8
  Once: (root) => {
@@ -13,7 +14,14 @@ module.exports = ({ id }) => {
13
14
  if (/^:host$/.test(n.value)) {
14
15
  const compoundSelectors = n.nodes
15
16
  n.replaceWith(selectorParser.className({
16
- value: 'host-' + id
17
+ value: `host-${id}`
18
+ }))
19
+ selector.insertAfter(n, compoundSelectors)
20
+ }
21
+ if (transPage && /^page$/.test(n.value)) {
22
+ const compoundSelectors = n.nodes || []
23
+ n.replaceWith(selectorParser.className({
24
+ value: MPX_TAG_PAGE_SELECTOR
17
25
  }))
18
26
  selector.insertAfter(n, compoundSelectors)
19
27
  }
@@ -0,0 +1,225 @@
1
+ const path = require('node:path')
2
+ /**
3
+ * @typedef {(id: string, importer?: string, aliasOnly?: boolean) => Promise<string | undefined>} ResolveIdFn
4
+ */
5
+ /**
6
+ * @typedef {(unquotedUrl: string, rawUrl: string) => Promise<string | false> | string | false} CssUrlReplacer
7
+ */
8
+
9
+ // https://drafts.csswg.org/css-syntax-3/#identifier-code-point
10
+ const cssUrlRE = /(?<!@import\s+)(?<=^|[^\w\-\u0080-\uffff])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/
11
+ const cssDataUriRE = /(?<=^|[^\w\-\u0080-\uffff])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/
12
+ const importCssRE = /@import\s+(?:url\()?('[^']+\.css'|"[^"]+\.css"|[^'"\s)]+\.css)/
13
+ const nonEscapedDoubleQuoteRe = /(?<!\\)"/g
14
+ const externalRE = /^([a-z]+:)?\/\//
15
+ const isExternalUrl = url => externalRE.test(url)
16
+
17
+ const dataUrlRE = /^\s*data:/i
18
+ const isDataUrl = url => dataUrlRE.test(url)
19
+ const functionCallRE = /^[A-Z_][.\w-]*\(/i
20
+
21
+ function skipUrlReplacer(unquotedUrl) {
22
+ return isExternalUrl(unquotedUrl) || isDataUrl(unquotedUrl) || unquotedUrl[0] === '#' || unquotedUrl[0] === '@' || functionCallRE.test(unquotedUrl)
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {string} rawUrl
28
+ * @param {string} matched
29
+ * @param {CssUrlReplacer} replacer
30
+ * @param {string} funcName
31
+ * @returns {Promise<string>}
32
+ */
33
+ async function doUrlReplace(rawUrl, matched, replacer, funcName = 'url') {
34
+ let wrap = ''
35
+ const first = rawUrl[0]
36
+ let unquotedUrl = rawUrl
37
+ if (first === '"' || first === "'") {
38
+ wrap = first
39
+ unquotedUrl = rawUrl.slice(1, -1)
40
+ }
41
+ if (skipUrlReplacer(unquotedUrl)) {
42
+ return matched
43
+ }
44
+ // Remove escape sequences to get the actual file name before resolving.
45
+ unquotedUrl = unquotedUrl.replace(/\\(\W)/g, '$1')
46
+
47
+ let newUrl = await replacer(unquotedUrl, rawUrl)
48
+ if (newUrl === false) {
49
+ return matched
50
+ }
51
+
52
+ // The new url might need wrapping even if the original did not have it, e.g.
53
+ // if a space was added during replacement or the URL contains ")"
54
+ if (wrap === '' && (newUrl !== encodeURI(newUrl) || newUrl.includes(')'))) {
55
+ wrap = '"'
56
+ }
57
+ // If wrapping in single quotes and newUrl also contains single quotes, switch to double quotes.
58
+ // Give preference to double quotes since SVG inlining converts double quotes to single quotes.
59
+ if (wrap === "'" && newUrl.includes("'")) {
60
+ wrap = '"'
61
+ }
62
+ // Escape double quotes if they exist (they also tend to be rarer than single quotes)
63
+ if (wrap === '"' && newUrl.includes('"')) {
64
+ newUrl = newUrl.replace(nonEscapedDoubleQuoteRe, '\\"')
65
+ }
66
+ return `${funcName}(${wrap}${newUrl}${wrap})`
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @param {string} rawUrl
72
+ * @param {string} matched
73
+ * @param {CssUrlReplacer} replacer
74
+ * @returns
75
+ */
76
+ async function doImportCSSReplace(rawUrl, matched, replacer) {
77
+ let wrap = ''
78
+ const first = rawUrl[0]
79
+ let unquotedUrl = rawUrl
80
+ if (first === '"' || first === "'") {
81
+ wrap = first
82
+ unquotedUrl = rawUrl.slice(1, -1)
83
+ }
84
+ if (skipUrlReplacer(unquotedUrl)) {
85
+ return matched
86
+ }
87
+
88
+ const newUrl = await replacer(unquotedUrl, rawUrl)
89
+ if (newUrl === false) {
90
+ return matched
91
+ }
92
+
93
+ const prefix = matched.includes('url(') ? 'url(' : ''
94
+ return `@import ${prefix}${wrap}${newUrl}${wrap}`
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param {string} input
100
+ * @param {RegExp} re
101
+ * @param {(match: RegExpMatchArray) => string | Promise<string>} replacer
102
+ * @returns {Promise<string>}
103
+ */
104
+ async function asyncReplace(input, re, replacer) {
105
+ let match = null
106
+ let remaining = input
107
+ let rewritten = ''
108
+ while ((match = re.exec(remaining))) {
109
+ rewritten += remaining.slice(0, match.index)
110
+ rewritten += await replacer(match)
111
+ remaining = remaining.slice(match.index + match[0].length)
112
+ }
113
+ rewritten += remaining
114
+ return rewritten
115
+ }
116
+ module.exports.asyncReplace = asyncReplace
117
+
118
+ /**
119
+ *
120
+ * @param {string} css
121
+ * @param {CssUrlReplacer} replacer
122
+ * @returns
123
+ */
124
+ function rewriteCssUrls(css, replacer) {
125
+ return asyncReplace(css, cssUrlRE, async match => {
126
+ const [matched, rawUrl] = match
127
+ return await doUrlReplace(rawUrl.trim(), matched, replacer)
128
+ })
129
+ }
130
+
131
+ /**
132
+ *
133
+ * @param {string} css
134
+ * @param {CssUrlReplacer} replacer
135
+ * @returns
136
+ */
137
+ function rewriteCssDataUris(css, replacer) {
138
+ return asyncReplace(css, cssDataUriRE, async match => {
139
+ const [matched, rawUrl] = match
140
+ return await doUrlReplace(rawUrl.trim(), matched, replacer, 'data-uri')
141
+ })
142
+ }
143
+ /**
144
+ *
145
+ * @param {string} css
146
+ * @param {CssUrlReplacer} replacer
147
+ * @returns
148
+ */
149
+ function rewriteImportCss(css, replacer) {
150
+ return asyncReplace(css, importCssRE, async match => {
151
+ const [matched, rawUrl] = match
152
+ return await doImportCSSReplace(rawUrl, matched, replacer)
153
+ })
154
+ }
155
+
156
+ const windowsSlashRE = /\\/g
157
+ function slash(p) {
158
+ return p.replace(windowsSlashRE, '/')
159
+ }
160
+
161
+ const isWindows = typeof process !== 'undefined' && process.platform === 'win32'
162
+ /**
163
+ *
164
+ * @param {string} id
165
+ * @returns {string}
166
+ */
167
+ function normalizePath(id) {
168
+ return path.posix.normalize(isWindows ? slash(id) : id)
169
+ }
170
+
171
+ /**
172
+ *
173
+ * @param {string} file
174
+ * @param {string} rootFile
175
+ * @param {string} content
176
+ * @param {ResolveIdFn} resolver
177
+ * @param {(unquotedUrl: string, rawUrl: string) => boolean} [ignoreUrl]
178
+ * @returns {Promise<{ file: string, contents?: string }>}
179
+ */
180
+ async function rebaseUrls(file, rootFile, content, resolver, ignoreUrl) {
181
+ // file = path.resolve(file) // ensure os-specific flashes
182
+ // in the same dir, no need to rebase
183
+ const fileDir = path.dirname(file)
184
+ const rootDir = path.dirname(rootFile)
185
+
186
+ // no url()
187
+ const hasUrls = cssUrlRE.test(content)
188
+ // data-uri() calls
189
+ const hasDataUris = cssDataUriRE.test(content)
190
+ // no @import xxx.css
191
+ const hasImportCss = importCssRE.test(content)
192
+
193
+ if (!hasUrls && !hasDataUris && !hasImportCss) {
194
+ return { file }
195
+ }
196
+
197
+ let rebased
198
+ const rebaseFn = async (unquotedUrl, rawUrl) => {
199
+ if (ignoreUrl?.(unquotedUrl, rawUrl)) return false
200
+ if (unquotedUrl[0] === '/') return unquotedUrl
201
+ const absolute = (await resolver(unquotedUrl, file)) || path.resolve(fileDir, unquotedUrl)
202
+ const relative = path.relative(rootDir, absolute)
203
+ return normalizePath(relative)
204
+ }
205
+
206
+ // fix css imports in less such as `@import "foo.css"`
207
+ if (hasImportCss) {
208
+ rebased = await rewriteImportCss(content, rebaseFn)
209
+ }
210
+
211
+ if (hasUrls) {
212
+ rebased = await rewriteCssUrls(rebased || content, rebaseFn)
213
+ }
214
+
215
+ if (hasDataUris) {
216
+ rebased = await rewriteCssDataUris(rebased || content, rebaseFn)
217
+ }
218
+
219
+ return {
220
+ file,
221
+ contents: rebased
222
+ }
223
+ }
224
+
225
+ module.exports.rebaseUrls = rebaseUrls