@mpxjs/webpack-plugin 2.10.18-beta.1 → 2.10.19

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 (29) hide show
  1. package/LICENSE +433 -0
  2. package/lib/index.js +0 -12
  3. package/lib/runtime/components/react/dist/mpx-camera.d.ts +4 -4
  4. package/lib/runtime/components/react/dist/mpx-camera.jsx +75 -41
  5. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +92 -15
  6. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -1
  7. package/lib/runtime/components/react/dist/mpx-swiper.jsx +24 -43
  8. package/lib/runtime/components/react/mpx-camera.tsx +78 -47
  9. package/lib/runtime/components/react/mpx-scroll-view.tsx +106 -16
  10. package/lib/runtime/components/react/mpx-swiper.tsx +23 -43
  11. package/lib/runtime/components/web/mpx-scroll-view.vue +2 -5
  12. package/lib/template-compiler/compiler.js +3 -7
  13. package/lib/utils/const.js +0 -29
  14. package/package.json +4 -3
  15. package/lib/resolver/ExtendComponentsPlugin.js +0 -60
  16. package/lib/runtime/components/ali/mpx-section-list.mpx +0 -566
  17. package/lib/runtime/components/ali/mpx-sticky-header.mpx +0 -212
  18. package/lib/runtime/components/ali/mpx-sticky-section.mpx +0 -17
  19. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +0 -48
  20. package/lib/runtime/components/react/dist/mpx-section-list.jsx +0 -292
  21. package/lib/runtime/components/react/mpx-section-list.tsx +0 -439
  22. package/lib/runtime/components/web/mpx-section-list.vue +0 -551
  23. package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +0 -26
  24. package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +0 -26
  25. package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +0 -26
  26. package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +0 -26
  27. package/lib/runtime/components/wx/mpx-section-list.mpx +0 -209
  28. package/lib/runtime/components/wx/mpx-sticky-header.mpx +0 -40
  29. package/lib/runtime/components/wx/mpx-sticky-section.mpx +0 -31
@@ -1,551 +0,0 @@
1
- <template>
2
- <div class="mpx-section-list">
3
- <ScrollView
4
- ref="scrollView"
5
- :enableSticky="enableSticky"
6
- :scroll-y="true"
7
- :enhanced="enhanced"
8
- :scrollWithAnimation="scrollWithAnimation"
9
- :refresherEnabled="refresherEnabled"
10
- :refresherTriggered="refresherTriggered"
11
- :scrollOptions="scrollOptions"
12
- @scroll="onScroll"
13
- @scrolltolower="onScrolltolower"
14
- @refresherrefresh="onRefresherrefresh"
15
- :style="scrollViewStyle"
16
- >
17
- <div class="content-wrapper">
18
- <template v-if="useListHeader">
19
- <list-header :listHeaderData="listHeaderData"></list-header>
20
- </template>
21
- <div class="infinite-list-placeholder" ref="infinitePlaceholder"></div>
22
- <div class="infinite-list" ref="infiniteList">
23
- <template v-for="item in visibleData">
24
- <section-header
25
- v-if="item.itemData && item.itemData.isSectionHeader"
26
- :key="'header' + (item.itemData.item_key || item._index)"
27
- :itemData="item.itemData"
28
- />
29
- <recycle-item
30
- v-if="item.itemData && !item.itemData.isSectionHeader"
31
- :key="'item' + (item.itemData.item_key || item._index)"
32
- :itemData="item.itemData"
33
- />
34
- </template>
35
- </div>
36
- <template v-if="useListFooter">
37
- <list-footer :listFooterData="listFooterData"></list-footer>
38
- </template>
39
- </div>
40
- <template
41
- v-if="
42
- _stickyHeaders &&
43
- _stickyHeaders.length &&
44
- enableSticky &&
45
- genericsectionHeader
46
- "
47
- >
48
- <StickyHeader
49
- v-for="stickyItem in _stickyHeaders"
50
- :key="stickyItem._index"
51
- class="sticky-section"
52
- :style="{
53
- top:
54
- ((positions[stickyItem._index] &&
55
- positions[stickyItem._index].top) ||
56
- 0) + 'px',
57
- }"
58
- >
59
- <section-header
60
- :key="'header' + stickyItem._index"
61
- :itemData="stickyItem.itemData"
62
- />
63
- </StickyHeader>
64
- </template>
65
- </ScrollView>
66
- </div>
67
- </template>
68
-
69
- <script>
70
- import ScrollView from "./mpx-scroll-view.vue";
71
- import StickyHeader from "./mpx-sticky-header.vue";
72
-
73
- export default {
74
- props: {
75
- width: String | Number,
76
- height: String | Number,
77
- listData: {
78
- type: Array,
79
- default: () => {
80
- return []
81
- }
82
- },
83
- scrollOptions: {
84
- type: Object,
85
- default: () => {
86
- return {}
87
- }
88
- },
89
- minRenderCount: {
90
- type: Number,
91
- default: 10,
92
- },
93
- bufferScale: {
94
- type: Number,
95
- default: 1,
96
- },
97
- itemHeight: {
98
- type: Object,
99
- default: () => {
100
- return {}
101
- }
102
- },
103
- listHeaderHeight: {
104
- type: Object,
105
- default: () => {
106
- return {}
107
- }
108
- },
109
- sectionHeaderHeight: {
110
- type: Object,
111
- default: () => {
112
- return {}
113
- }
114
- },
115
- listHeaderData: {
116
- type: Object,
117
- default: () => {
118
- return {}
119
- }
120
- },
121
- enhanced: {
122
- type: Boolean,
123
- default: false
124
- },
125
- refresherEnabled: {
126
- type: Boolean,
127
- default: false
128
- },
129
- refresherTriggered: {
130
- type: Boolean,
131
- default: false
132
- },
133
- enableSticky: {
134
- type: Boolean,
135
- default: false
136
- },
137
- scrollWithAnimation: {
138
- type: Boolean,
139
- default: false
140
- },
141
- useListHeader: {
142
- type: Boolean,
143
- default: true
144
- },
145
- listFooterData: {
146
- type: Object,
147
- default: () => {
148
- return {}
149
- }
150
- },
151
- useListFooter: {
152
- type: Boolean,
153
- default: false
154
- },
155
- generichash: String,
156
- genericlistHeader: String,
157
- genericlistFooter: String,
158
- genericrecycleItem: String,
159
- genericsectionHeader: String
160
- },
161
- data() {
162
- return {
163
- start: 0,
164
- end: 0,
165
- containerHeight: 0,
166
- positions: [],
167
- visibleCounts: [],
168
- };
169
- },
170
- computed: {
171
- _listData() {
172
- return (this.listData && this.listData.map((item, index) => {
173
- return {
174
- itemData: item,
175
- _index: `_${index}`,
176
- };
177
- })) || [];
178
- },
179
- _stickyHeaders() {
180
- const data = [];
181
- this.listData && this.listData.forEach((item, index) => {
182
- if (item.isSectionHeader) {
183
- data.push({
184
- itemData: item,
185
- _index: index,
186
- });
187
- }
188
- });
189
- return data;
190
- },
191
- scrollViewStyle() {
192
- return `height: ${this.formatDimension(
193
- this.height
194
- )};width: ${this.formatDimension(this.width)}`;
195
- },
196
- visibleCount() {
197
- if (!this.visibleCounts.length) return this.minRenderCount;
198
- return Math.max(this.visibleCounts[this.start], this.minRenderCount);
199
- },
200
- aboveCount() {
201
- if (!this._listData.length || !this.visibleCounts.length) return 0;
202
- let count = 0;
203
- const startIndex = Math.max(0, this.start);
204
- const endIndex = Math.max(0, startIndex - this.bufferScale);
205
-
206
- for (let i = startIndex; i > endIndex; i--) {
207
- count += this.visibleCounts[i] || 0;
208
- }
209
-
210
- return count;
211
- },
212
- belowCount() {
213
- if (!this._listData.length || !this.visibleCounts.length) return 0;
214
- let count = 0;
215
- const startIndex = Math.min(this.start, this._listData.length - 1);
216
- const endIndex = Math.min(
217
- startIndex + this.bufferScale,
218
- this._listData.length - 1
219
- );
220
-
221
- for (let i = startIndex; i < endIndex; i++) {
222
- count += this.visibleCounts[i] || 0;
223
- }
224
-
225
- return count;
226
- },
227
- visibleData() {
228
- if (!this._listData.length) return [];
229
-
230
- const start = Math.min(
231
- Math.max(0, this.start - this.aboveCount),
232
- this._listData.length - 1
233
- );
234
-
235
- let end = Math.min(
236
- this._listData.length,
237
- this.start + this.visibleCount + this.belowCount
238
- );
239
-
240
- // 如果接近列表末尾,确保显示所有剩余项目
241
- if (end > this._listData.length - 3) {
242
- end = this._listData.length;
243
- }
244
-
245
- return this._listData.slice(start, end).map((item, idx) => {
246
- const realIndex = start + idx;
247
- return {
248
- ...item,
249
- _index: `_${realIndex}`,
250
- };
251
- });
252
- },
253
- _listHeaderHeight() {
254
- let listHeaderHeight = 0;
255
- if (this.useListHeader) {
256
- listHeaderHeight =
257
- this.getItemHeight(this.listHeaderData, 0, "listHeaderHeight") || 0;
258
- }
259
- return listHeaderHeight;
260
- },
261
- placeholderHeight() {
262
- if (!this.positions.length) return 0;
263
- return (
264
- this.positions[this.positions.length - 1].bottom -
265
- this._listHeaderHeight || 0
266
- );
267
- },
268
- },
269
- watch: {
270
- listData: {
271
- handler() {
272
- this.initPositions();
273
- this.setPlaceholderStyle();
274
- // 更新真实偏移量
275
- this.setStartOffset();
276
- },
277
- },
278
- itemHeight: {
279
- handler() {
280
- this.handleHeightChange()
281
- },
282
- deep: true
283
- },
284
- sectionHeaderHeight: {
285
- handler() {
286
- this.handleHeightChange()
287
- },
288
- deep: true
289
- },
290
- listHeaderHeight: {
291
- handler() {
292
- this.handleHeightChange()
293
- },
294
- deep: true
295
- },
296
- containerHeight() {
297
- this.calculateVisibleCounts();
298
- },
299
- },
300
- created() {
301
- this.registerGenericComponents();
302
- },
303
- mounted() {
304
- this.initPositions();
305
- this.containerHeight = this.$refs.scrollView?.$el?.clientHeight || 0;
306
- this.setPlaceholderStyle();
307
- if (!this.positions || !this.positions.length) {
308
- return;
309
- }
310
- this.start = this.getStartIndex();
311
- this.end = this.start + this.visibleCount;
312
- this.setStartOffset();
313
- },
314
- methods: {
315
- handleHeightChange () {
316
- this.initPositions();
317
- this.setPlaceholderStyle();
318
- this.setStartOffset();
319
- // 外部传值虽然变了,但是未触发 DOM 实际宽高变更,所以也不会自动触发 scrollView 内部 refresh 机制
320
- // 需要手动触发,让 sticky-header 重新计算位置
321
- this.$refs.scrollView?.forceUpdateRefreshVersion?.()
322
- },
323
- registerGenericComponents() {
324
- if (!this.generichash || !global.__mpxGenericsMap[this.generichash]) {
325
- return;
326
- }
327
-
328
- let components = null;
329
- const genericList = {
330
- "recycle-item": this.genericrecycleItem ,
331
- "list-header": this.genericlistHeader,
332
- "section-header": this.genericsectionHeader,
333
- "list-footer": this.genericlistFooter
334
- }
335
-
336
- for (const key in genericList) {
337
- const value = genericList[key]
338
- if (value) {
339
- components = components || {};
340
- components[key] = global.__mpxGenericsMap[this.generichash][value]
341
- }
342
- }
343
-
344
- if (components) {
345
- this.$options.components = Object.assign(
346
- {},
347
- this.$options.components,
348
- components
349
- );
350
- }
351
- },
352
- formatDimension(value) {
353
- return typeof value === "number" ? `${value}px` : value || "100%";
354
- },
355
- setPlaceholderStyle() {
356
- const infinitePlaceholder = this.$refs.infinitePlaceholder;
357
- if (infinitePlaceholder) {
358
- infinitePlaceholder.style.height = `${this.placeholderHeight}px`;
359
- }
360
- },
361
- initPositions() {
362
- let bottom = this._listHeaderHeight || 0;
363
- this.positions = this._listData.map((item, index) => {
364
- const height = this.getItemHeight(
365
- item.itemData,
366
- index,
367
- item.itemData.isSectionHeader ? "sectionHeaderHeight" : "itemHeight"
368
- );
369
- const position = {
370
- index,
371
- height: height,
372
- top: bottom,
373
- bottom: bottom + height,
374
- };
375
- bottom = position.bottom;
376
- return position;
377
- });
378
-
379
- if (this.containerHeight) {
380
- this.calculateVisibleCounts();
381
- }
382
- },
383
- calculateVisibleCounts() {
384
- this.visibleCounts = this.positions.map((_, startIndex) => {
385
- let count = 0;
386
- let totalHeight = 0;
387
-
388
- for (let i = startIndex; i < this.positions.length; i++) {
389
- totalHeight += this.positions[i].height;
390
- if (totalHeight > this.containerHeight) {
391
- break;
392
- }
393
- count++;
394
- }
395
-
396
- // 如果是最后几个项目,确保全部显示
397
- if (startIndex + count > this.positions.length - 3) {
398
- count = this.positions.length - startIndex;
399
- }
400
-
401
- return count;
402
- });
403
- },
404
-
405
- getStartIndex(scrollTop = 0) {
406
- // 确保不会返回超出范围的索引
407
- if (!this.positions.length) {
408
- return 0;
409
- }
410
-
411
- // 如果滚动位置为0,直接返回0
412
- if (scrollTop <= 0) {
413
- return 0;
414
- }
415
- const index = this.binarySearch(this.positions, scrollTop);
416
- return Math.max(0, Math.min(index, this._listData.length - 1));
417
- },
418
- binarySearch(list, value) {
419
- if (!list.length) return 0;
420
-
421
- // 如果 scrollTop 超过了最后一个元素的底部
422
- if (value >= list[list.length - 1].bottom) {
423
- return list.length - 1;
424
- }
425
-
426
- let start = 0;
427
- let end = list.length - 1;
428
-
429
- while (start <= end) {
430
- const midIndex = Math.floor((start + end) / 2);
431
- const midValue = list[midIndex];
432
-
433
- if (value >= midValue.top && value < midValue.bottom) {
434
- return midIndex;
435
- }
436
-
437
- if (value < midValue.top) {
438
- end = midIndex - 1;
439
- } else {
440
- start = midIndex + 1;
441
- }
442
- }
443
-
444
- return Math.min(Math.max(0, start - 1), list.length - 1);
445
- },
446
- setStartOffset() {
447
- const infiniteList = this.$refs.infiniteList;
448
- if (!this.positions.length || !infiniteList) return;
449
- if (this.start >= 1) {
450
- // 确保 startIndex 不会超出范围
451
- const startIndex = Math.min(
452
- Math.max(0, this.start - this.aboveCount),
453
- this.positions.length - 1
454
- );
455
-
456
- const offset = this.positions[startIndex].top;
457
- infiniteList.style.transform = `translateY(${offset}px)`;
458
- } else {
459
- infiniteList.style.transform = `translateY(${this.positions[0].top}px)`;
460
- }
461
- },
462
- getItemHeight(item, index, key) {
463
- const { value, getter } = this[key];
464
- if (typeof getter === "function") {
465
- return getter(item, index) || 0;
466
- } else {
467
- return value || 0;
468
- }
469
- },
470
- onScroll(e) {
471
- const { scrollTop } = e.detail;
472
- const newStart = this.getStartIndex(scrollTop);
473
-
474
- // 只有当start发生足够变化时才更新,避免滚动触发重渲染
475
- if (Math.abs(newStart - this.end) >= Math.floor(this.belowCount / 2)) {
476
- this.start = newStart;
477
- this.end = this.start + this.visibleCount;
478
- this.setStartOffset();
479
- }
480
-
481
- this.$emit("scroll", e);
482
- },
483
- onScrolltolower(e) {
484
- this.$emit("scrolltolower", e);
485
- },
486
- onRefresherrefresh(e) {
487
- this.$emit("refresherrefresh", e);
488
- },
489
- scrollToIndex({ index, animated, viewPosition = 0, viewOffset = 0 }) {
490
- const isStickyHeader = this._listData[index].itemData?.isSectionHeader;
491
- let prevHeaderHeight = 0;
492
- // 如果不是sticky header 查找最近一个吸顶的 sticky header
493
- if (!isStickyHeader && this.enableSticky) {
494
- for (let i = index - 1; i >= 0; i--) {
495
- if (this._listData[i].itemData?.isSectionHeader) {
496
- prevHeaderHeight = this.positions[i].height;
497
- break;
498
- }
499
- }
500
- }
501
-
502
- const itemTop = (this.positions[index]?.top || 0) - prevHeaderHeight;
503
- const itemHeight = this.positions[index]?.height || 0;
504
- const containerHeight = this.containerHeight;
505
-
506
- let targetTop = itemTop;
507
- if (viewPosition === 1) {
508
- // 滚动到可视区底部
509
- targetTop = itemTop - (containerHeight - itemHeight);
510
- } else if (viewPosition === 0.5) {
511
- // 滚动到可视区中央
512
- targetTop = itemTop - (containerHeight - itemHeight) / 2;
513
- }
514
-
515
- targetTop -= viewOffset;
516
-
517
- this.$refs.scrollView?.bs.scrollTo(0, -targetTop, animated ? 200 : 0);
518
- },
519
- },
520
- components: {
521
- ScrollView,
522
- StickyHeader,
523
- },
524
- };
525
- </script>
526
-
527
- <style scoped>
528
- .mpx-section-list {
529
- position: relative;
530
- overflow: hidden;
531
- height: 100%;
532
- }
533
-
534
- .content-wrapper {
535
- position: relative;
536
- width: 100%;
537
- }
538
-
539
- .infinite-list {
540
- left: 0;
541
- right: 0;
542
- top: 0;
543
- position: absolute;
544
- will-change: transform;
545
- -webkit-backface-visibility: hidden;
546
- backface-visibility: hidden;
547
- }
548
- .sticky-section {
549
- position: absolute !important;
550
- }
551
- </style>
@@ -1,26 +0,0 @@
1
- <template>
2
- <view class="mpx-list-footer-default">
3
- <view class="mpx-default-content">list-footer-default</view>
4
- </view>
5
- </template>
6
-
7
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
- createComponent({})
10
- </script>
11
-
12
- <style lang="stylus" scoped>
13
- .mpx-list-footer-default
14
- margin 4px 16px
15
- padding 16px
16
- background #fff
17
- border-radius 8px
18
- box-shadow 0 2px 4px rgba(0,0,0,0.1)
19
-
20
- .mpx-default-content
21
- display flex
22
- flex-direction column
23
- font-size 14px
24
- color #666
25
-
26
- </style>
@@ -1,26 +0,0 @@
1
- <template>
2
- <view class="mpx-list-header-default">
3
- <view class="mpx-default-content">list-header-default</view>
4
- </view>
5
- </template>
6
-
7
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
- createComponent({})
10
- </script>
11
-
12
- <style lang="stylus" scoped>
13
- .mpx-list-header-default
14
- margin 4px 16px
15
- padding 16px
16
- background #fff
17
- border-radius 8px
18
- box-shadow 0 2px 4px rgba(0,0,0,0.1)
19
-
20
- .mpx-default-content
21
- display flex
22
- flex-direction column
23
- font-size 14px
24
- color #666
25
-
26
- </style>
@@ -1,26 +0,0 @@
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
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
- createComponent({})
10
- </script>
11
-
12
- <style lang="stylus" scoped>
13
- .mpx-recycle-item-default
14
- margin 4px 16px
15
- padding 16px
16
- background #fff
17
- border-radius 8px
18
- box-shadow 0 2px 4px rgba(0,0,0,0.1)
19
-
20
- .mpx-default-content
21
- display flex
22
- flex-direction column
23
- font-size 14px
24
- color #666
25
-
26
- </style>
@@ -1,26 +0,0 @@
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
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
- createComponent({})
10
- </script>
11
-
12
- <style lang="stylus" scoped>
13
- .mpx-section-header-default
14
- margin 4px 16px
15
- padding 16px
16
- background #fff
17
- border-radius 8px
18
- box-shadow 0 2px 4px rgba(0,0,0,0.1)
19
-
20
- .mpx-default-content
21
- display flex
22
- flex-direction column
23
- font-size 14px
24
- color #666
25
-
26
- </style>