@mpxjs/webpack-plugin 2.10.17-unocss.1 → 2.10.18-beta.1

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 (40) hide show
  1. package/lib/index.js +49 -36
  2. package/lib/platform/style/wx/index.js +0 -2
  3. package/lib/platform/template/wx/component-config/camera.js +12 -0
  4. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  5. package/lib/react/processStyles.js +8 -39
  6. package/lib/react/style-helper.js +5 -16
  7. package/lib/resolver/ExtendComponentsPlugin.js +60 -0
  8. package/lib/runtime/components/ali/mpx-section-list.mpx +566 -0
  9. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  10. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  11. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +0 -1
  12. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +2 -1
  13. package/lib/runtime/components/react/dist/mpx-input.jsx +10 -3
  14. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +13 -2
  15. package/lib/runtime/components/react/dist/mpx-swiper.jsx +60 -40
  16. package/lib/runtime/components/react/dist/utils.jsx +8 -4
  17. package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
  18. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  19. package/lib/runtime/components/react/mpx-input.tsx +11 -2
  20. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +13 -2
  21. package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
  22. package/lib/runtime/components/react/mpx-swiper.tsx +113 -66
  23. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  24. package/lib/runtime/components/react/tsconfig.json +1 -1
  25. package/lib/runtime/components/react/utils.tsx +8 -4
  26. package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
  27. package/lib/runtime/components/web/mpx-section-list.vue +551 -0
  28. package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
  29. package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
  30. package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
  31. package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
  32. package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
  33. package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
  34. package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -0
  35. package/lib/template-compiler/compiler.js +7 -3
  36. package/lib/utils/const.js +29 -0
  37. package/lib/utils/dom-tag-config.js +1 -1
  38. package/lib/wxss/loader.js +4 -1
  39. package/lib/wxss/utils.js +7 -2
  40. package/package.json +3 -3
@@ -0,0 +1,209 @@
1
+ <template>
2
+ <scroll-view wx:ref="recycleViewRef" class="mpx-section-list" 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" scroll-into-view-offset="{{ scrollIntoViewOffset }}"
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
+ <block wx:if="{{ useListFooter }}">
31
+ <list-footer listFooterData="{{ listFooterData }}"></list-footer>
32
+ </block>
33
+ </scroll-view>
34
+ </template>
35
+
36
+ <script>
37
+ import { createComponent } from '@mpxjs/core'
38
+
39
+ createComponent({
40
+ properties: {
41
+ height: {
42
+ type: Number,
43
+ value: null
44
+ },
45
+ width: {
46
+ type: Number,
47
+ value: null
48
+ },
49
+ listData: {
50
+ type: Array,
51
+ value: []
52
+ },
53
+ enableSticky: {
54
+ type: Boolean,
55
+ value: false
56
+ },
57
+ showScrollbar: {
58
+ type: Boolean,
59
+ value: false
60
+ },
61
+ enhanced: {
62
+ type: Boolean,
63
+ value: false
64
+ },
65
+ bounces: {
66
+ type: Boolean,
67
+ value: false
68
+ },
69
+ refresherEnabled: {
70
+ type: Boolean,
71
+ value: false
72
+ },
73
+ refresherTriggered: {
74
+ type: Boolean,
75
+ value: false
76
+ },
77
+ listHeaderData: {
78
+ type: Object,
79
+ value: null
80
+ },
81
+ scrollWithAnimation: {
82
+ type: Boolean,
83
+ value: false
84
+ },
85
+ useListHeader: {
86
+ type: Boolean,
87
+ value: false
88
+ },
89
+ listFooterData: {
90
+ type: Object,
91
+ value: null
92
+ },
93
+ useListFooter: {
94
+ type: Boolean,
95
+ value: false
96
+ }
97
+ },
98
+ data: {
99
+ convertedListData: [],
100
+ scrollIntoViewId: '',
101
+ scrollIntoViewOffset: 0,
102
+ viewPosition: 'start'
103
+ },
104
+ computed: {
105
+ scrollViewStyle() {
106
+ return `height: ${this.formatDimension(this.height)};width: ${this.formatDimension(this.width)}`
107
+ }
108
+ },
109
+ watch: {
110
+ listData: {
111
+ handler(newVal) {
112
+ this.convertedListData = this.convertToSectionListData(newVal)
113
+ },
114
+ immediate: true
115
+ }
116
+ },
117
+ methods: {
118
+ formatDimension(value) {
119
+ return typeof value === 'number' ? `${value}px` : value || '100%'
120
+ },
121
+ onScroll(e) {
122
+ this.triggerEvent('scroll', e)
123
+ },
124
+ onRefresh(e) {
125
+ this.triggerEvent('refresh', e)
126
+ },
127
+ scrollToIndex({ index, viewPosition = 0, viewOffset = 0 }) {
128
+ if (index >= 0) {
129
+ this.scrollIntoViewId = `mpx-recycle-item-${index}`
130
+ switch (viewPosition) {
131
+ case 0:
132
+ this.viewPosition = 'start'
133
+ break
134
+ case 0.5:
135
+ this.viewPosition = 'center'
136
+ break
137
+ case 1:
138
+ this.viewPosition = 'end'
139
+ break
140
+ default:
141
+ this.viewPosition = 'start'
142
+ }
143
+ this.scrollIntoViewOffset = -viewOffset || 0
144
+ }
145
+ },
146
+ convertToSectionListData(data) {
147
+ const sections = []
148
+ let currentSection = null
149
+
150
+ data && data.forEach((item, index) => {
151
+ if (item.isSectionHeader) {
152
+ // 如果已经存在一个 section,先把它添加到 sections 中
153
+ if (currentSection) {
154
+ sections.push(currentSection)
155
+ }
156
+ // 创建新的 section
157
+ currentSection = {
158
+ headerData: item,
159
+ data: [],
160
+ hasSectionHeader: true,
161
+ _domId: `mpx-recycle-item-${index}`
162
+ }
163
+ } else {
164
+ // 如果没有当前 section,创建一个默认的
165
+ if (!currentSection) {
166
+ // 创建默认section (无header的section)
167
+ currentSection = {
168
+ headerData: null,
169
+ data: [],
170
+ hasSectionHeader: false
171
+ }
172
+ }
173
+ currentSection.data.push({
174
+ itemData: item,
175
+ _domId: `mpx-recycle-item-${index}`
176
+ })
177
+ }
178
+ })
179
+
180
+ // 添加最后一个 section
181
+ if (currentSection) {
182
+ sections.push(currentSection)
183
+ }
184
+
185
+ return sections
186
+ }
187
+ }
188
+ })
189
+ </script>
190
+
191
+ <script type="application/json">
192
+ {
193
+ "component": true,
194
+ "componentGenerics": {
195
+ "recycle-item": {
196
+ "default": "./mpx-section-list-default/list-item.mpx"
197
+ },
198
+ "section-header": {
199
+ "default": "./mpx-section-list-default/section-header.mpx"
200
+ },
201
+ "list-header": {
202
+ "default": "./mpx-section-list-default/list-header.mpx"
203
+ },
204
+ "list-footer": {
205
+ "default": "./mpx-section-list-default/list-footer.mpx"
206
+ }
207
+ }
208
+ }
209
+ </script>
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <sticky-header offset-top="{{offsetTop}}" padding="{{padding}}" allow-overlapping="{{allowOverlapping}}" bindstickontopchange="handleStickyChange">
3
+ <slot></slot>
4
+ </sticky-header>
5
+ </template>
6
+
7
+ <script>
8
+ import { createComponent } from '@mpxjs/core'
9
+
10
+ createComponent({
11
+ options: {
12
+ virtualHost: true
13
+ },
14
+ properties: {
15
+ offsetTop: {
16
+ type: Number,
17
+ value: 0
18
+ },
19
+ padding: {
20
+ type: Array,
21
+ value: [0, 0, 0, 0]
22
+ },
23
+ allowOverlapping: {
24
+ type: Boolean,
25
+ value: false
26
+ }
27
+ },
28
+ methods: {
29
+ handleStickyChange(e) {
30
+ this.triggerEvent('stickontopchange', e.detail)
31
+ }
32
+ }
33
+ })
34
+ </script>
35
+
36
+ <script type="application/json">
37
+ {
38
+ "component": true
39
+ }
40
+ </script>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <sticky-section padding="{{ padding }}" push-pinned-header="{{ pushPinnedHeader }}">
3
+ <slot></slot>
4
+ </sticky-section>
5
+ </template>
6
+
7
+ <script>
8
+ import { createComponent } from '@mpxjs/core'
9
+
10
+ createComponent({
11
+ options: {
12
+ virtualHost: true
13
+ },
14
+ properties: {
15
+ padding: {
16
+ type: Array,
17
+ value: [0, 0, 0, 0]
18
+ },
19
+ pushPinnedHeader: {
20
+ type: Boolean,
21
+ value: true
22
+ }
23
+ }
24
+ })
25
+ </script>
26
+
27
+ <script type="application/json">
28
+ {
29
+ "component": true
30
+ }
31
+ </script>
@@ -1,7 +1,7 @@
1
1
  const JSON5 = require('json5')
2
2
  const he = require('he')
3
3
  const config = require('../config')
4
- const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID, MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
4
+ const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID, MPX_TAG_PAGE_SELECTOR, EXTEND_COMPONENT_CONFIG } = require('../utils/const')
5
5
  const normalize = require('../utils/normalize')
6
6
  const { normalizeCondition } = require('../utils/match-condition')
7
7
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
@@ -2432,7 +2432,11 @@ function isRealNode (el) {
2432
2432
  }
2433
2433
 
2434
2434
  function isComponentNode (el) {
2435
- return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component' || componentGenerics[el.tag]
2435
+ return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component' || componentGenerics[el.tag] || isExtendComponentNode(el)
2436
+ }
2437
+
2438
+ function isExtendComponentNode (el) {
2439
+ return EXTEND_COMPONENT_CONFIG[el.tag]?.[mode]
2436
2440
  }
2437
2441
 
2438
2442
  function getComponentInfo (el) {
@@ -2440,7 +2444,7 @@ function getComponentInfo (el) {
2440
2444
  }
2441
2445
 
2442
2446
  function isReactComponent (el) {
2443
- return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn
2447
+ return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn && !isExtendComponentNode(el)
2444
2448
  }
2445
2449
 
2446
2450
  function processExternalClasses (el, options) {
@@ -1,3 +1,5 @@
1
+ const componentPrefixPath = '@mpxjs/webpack-plugin/lib/runtime/components'
2
+
1
3
  module.exports = {
2
4
  MPX_PROCESSED_FLAG: 'mpx_processed',
3
5
  MPX_DISABLE_EXTRACTOR_CACHE: 'mpx_disable_extractor_cache',
@@ -7,5 +9,32 @@ module.exports = {
7
9
  MPX_ROOT_VIEW: 'mpx-root-view', // 根节点类名
8
10
  MPX_APP_MODULE_ID: 'mpx-app-scope', // app文件moduleId
9
11
  PARENT_MODULE_ID: '__pid',
12
+ // 扩展组件的平台配置:声明哪些组件在哪些平台有专用实现,哪些使用公共组件
13
+ EXTEND_COMPONENT_CONFIG: {
14
+ 'section-list': {
15
+ wx: `${componentPrefixPath}/wx/mpx-section-list.mpx`,
16
+ ali: `${componentPrefixPath}/ali/mpx-section-list.mpx`,
17
+ web: `${componentPrefixPath}/web/mpx-section-list.vue`,
18
+ ios: `${componentPrefixPath}/react/dist/mpx-section-list.jsx`,
19
+ android: `${componentPrefixPath}/react/dist/mpx-section-list.jsx`,
20
+ harmony: `${componentPrefixPath}/react/dist/mpx-section-list.jsx`
21
+ },
22
+ 'sticky-header': {
23
+ wx: `${componentPrefixPath}/wx/mpx-sticky-header.mpx`,
24
+ ali: `${componentPrefixPath}/ali/mpx-sticky-header.mpx`,
25
+ web: `${componentPrefixPath}/web/mpx-sticky-header.vue`,
26
+ ios: `${componentPrefixPath}/react/dist/mpx-sticky-header.jsx`,
27
+ android: `${componentPrefixPath}/react/dist/mpx-sticky-header.jsx`,
28
+ harmony: `${componentPrefixPath}/react/dist/mpx-sticky-header.jsx`
29
+ },
30
+ 'sticky-section': {
31
+ wx: `${componentPrefixPath}/wx/mpx-sticky-section.mpx`,
32
+ ali: `${componentPrefixPath}/ali/mpx-sticky-section.mpx`,
33
+ web: `${componentPrefixPath}/web/mpx-sticky-section.vue`,
34
+ ios: `${componentPrefixPath}/react/dist/mpx-sticky-section.jsx`,
35
+ android: `${componentPrefixPath}/react/dist/mpx-sticky-section.jsx`,
36
+ harmony: `${componentPrefixPath}/react/dist/mpx-sticky-section.jsx`
37
+ }
38
+ },
10
39
  MPX_TAG_PAGE_SELECTOR: 'mpx-page'
11
40
  }
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
91
91
  'mpx-movable-area,mpx-label,mpx-input,' +
92
92
  'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
93
  'mpx-rich-text,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
- 'mpx-icon,mpx-canvas'
94
+ 'mpx-icon,mpx-canvas,mpx-camera'
95
95
  )
96
96
 
97
97
  const isSpace = makeMap('ensp,emsp,nbsp')
@@ -92,6 +92,9 @@ module.exports = async function loader (content, map, meta) {
92
92
  filter: options.import.filter,
93
93
  urlHandler: (url) => {
94
94
  url = combineRequests(getPreRequester(this)(options.importLoaders), url)
95
+ if (isRN) {
96
+ return stringifyRequest(this, url)
97
+ }
95
98
  return getRequestString('styles', { src: url }, {
96
99
  isStatic: true,
97
100
  issuerResource: this.resource,
@@ -249,7 +252,7 @@ module.exports = async function loader (content, map, meta) {
249
252
  let moduleCode
250
253
 
251
254
  try {
252
- moduleCode = getModuleCode(result, api, replacements, options, this)
255
+ moduleCode = getModuleCode(result, api, replacements, options, isRN, this)
253
256
  } catch (error) {
254
257
  callback(error)
255
258
 
package/lib/wxss/utils.js CHANGED
@@ -1016,6 +1016,7 @@ function getModuleCode (
1016
1016
  api,
1017
1017
  replacements,
1018
1018
  options,
1019
+ isRN,
1019
1020
  loaderContext
1020
1021
  ) {
1021
1022
  if (options.modules.exportOnlyLocals === true) {
@@ -1054,8 +1055,12 @@ function getModuleCode (
1054
1055
  } else {
1055
1056
  // 符合css后缀名的文件经过mpx处理后会带上相应的后缀防止使用 webpack 的默认解析规则,此时 require/import 相应路径时,导出的不是一段 css 代码了,事实上是一个文件路径。
1056
1057
  const printedParam = printParams(media, dedupe, supports, layer)
1057
- const otherParams = printedParam.length > 0 ? printedParam : ''
1058
- beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";', ${JSON.stringify(otherParams)} ]);\n`
1058
+ const hasParams = printedParam.length > 0
1059
+ if (isRN) {
1060
+ beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${hasParams ? `, ${printedParam}` : ''});\n`
1061
+ } else {
1062
+ beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";'${hasParams ? `, ${printedParam}` : ''}]);\n`
1063
+ }
1059
1064
  }
1060
1065
  }
1061
1066
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.17-unocss.1",
3
+ "version": "2.10.18-beta.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,7 +29,7 @@
29
29
  "@better-scroll/wheel": "^2.5.1",
30
30
  "@better-scroll/zoom": "^2.5.1",
31
31
  "@mpxjs/template-engine": "^2.8.7",
32
- "@mpxjs/utils": "^2.10.17",
32
+ "@mpxjs/utils": "^2.10.18",
33
33
  "acorn": "^8.11.3",
34
34
  "acorn-walk": "^7.2.0",
35
35
  "async": "^2.6.0",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "devDependencies": {
86
86
  "@d11/react-native-fast-image": "^8.6.12",
87
- "@mpxjs/api-proxy": "^2.10.17",
87
+ "@mpxjs/api-proxy": "^2.10.18",
88
88
  "@types/babel-traverse": "^6.25.4",
89
89
  "@types/babel-types": "^7.0.4",
90
90
  "@types/glob": "^8.1.0",