@mpxjs/webpack-plugin 2.10.7 → 2.10.8

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 (43) hide show
  1. package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
  2. package/lib/dependencies/RequireExternalDependency.js +61 -0
  3. package/lib/file-loader.js +3 -2
  4. package/lib/index.js +55 -9
  5. package/lib/json-compiler/index.js +1 -0
  6. package/lib/parser.js +1 -1
  7. package/lib/platform/json/wx/index.js +43 -25
  8. package/lib/platform/style/wx/index.js +7 -0
  9. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  10. package/lib/platform/template/wx/component-config/index.js +5 -1
  11. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  12. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  13. package/lib/react/LoadAsyncChunkModule.js +74 -0
  14. package/lib/react/index.js +3 -1
  15. package/lib/react/processJSON.js +74 -13
  16. package/lib/react/processScript.js +6 -6
  17. package/lib/react/script-helper.js +100 -41
  18. package/lib/runtime/components/react/context.ts +12 -3
  19. package/lib/runtime/components/react/dist/context.js +4 -1
  20. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
  21. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
  22. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -6
  23. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -15
  24. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +117 -0
  25. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  26. package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
  27. package/lib/runtime/components/react/mpx-button.tsx +3 -2
  28. package/lib/runtime/components/react/mpx-movable-view.tsx +8 -4
  29. package/lib/runtime/components/react/mpx-scroll-view.tsx +84 -59
  30. package/lib/runtime/components/react/mpx-sticky-header.tsx +181 -0
  31. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  32. package/lib/runtime/components/web/mpx-scroll-view.vue +18 -4
  33. package/lib/runtime/components/web/mpx-sticky-header.vue +99 -0
  34. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  35. package/lib/runtime/optionProcessorReact.d.ts +18 -0
  36. package/lib/runtime/optionProcessorReact.js +30 -0
  37. package/lib/script-setup-compiler/index.js +27 -5
  38. package/lib/template-compiler/bind-this.js +2 -1
  39. package/lib/template-compiler/compiler.js +4 -3
  40. package/lib/utils/dom-tag-config.js +17 -3
  41. package/lib/utils/trans-async-sub-rules.js +19 -0
  42. package/lib/web/script-helper.js +1 -1
  43. package/package.json +4 -4
@@ -0,0 +1,99 @@
1
+ <script>
2
+ import { warn } from '@mpxjs/utils'
3
+ import { getCustomEvent } from './getInnerListeners'
4
+
5
+ export default {
6
+ name: 'mpx-sticky-header',
7
+ inject: ['scrollOffset', 'refreshVersion'],
8
+ props: {
9
+ offsetTop: {
10
+ type: Number,
11
+ default: 0
12
+ },
13
+ padding: Array
14
+ },
15
+ data() {
16
+ return {
17
+ headerTop: 0,
18
+ isStickOnTop: false
19
+ }
20
+ },
21
+ watch: {
22
+ scrollOffset: {
23
+ handler(newScrollOffset) {
24
+ const newIsStickOnTop = newScrollOffset > this.headerTop
25
+ if (newIsStickOnTop !== this.isStickOnTop) {
26
+ this.isStickOnTop = newIsStickOnTop
27
+ this.$emit('stickontopchange', getCustomEvent('stickontopchange', {
28
+ isStickOnTop: newIsStickOnTop
29
+ }, this))
30
+ }
31
+
32
+ this.setTransformStyle()
33
+ },
34
+ immediate: true
35
+ },
36
+ refreshVersion: {
37
+ handler() {
38
+ this.setHeaderTop()
39
+ this.setTransformStyle()
40
+ },
41
+ }
42
+ },
43
+ mounted() {
44
+ this.setPaddingStyle()
45
+ this.setHeaderTop()
46
+ },
47
+ methods: {
48
+ setHeaderTop () {
49
+ const parentElement = this.$el.parentElement
50
+ if (!parentElement) return
51
+
52
+ const parentClass = parentElement.className || ''
53
+ const isStickySection = /mpx-sticky-section/.test(parentClass)
54
+ const isScrollViewWrapper = /mpx-inner-wrapper/.test(parentClass)
55
+
56
+ if (!isStickySection && !isScrollViewWrapper) {
57
+ warn('sticky-header only supports being a direct child of a scroll-view or sticky-section component.')
58
+ return
59
+ }
60
+ this.headerTop = isStickySection
61
+ ? this.$el.offsetTop + parentElement.offsetTop
62
+ : this.$el.offsetTop
63
+ },
64
+ setPaddingStyle() {
65
+ const stickyHeader = this.$refs.stickyHeader
66
+ if (!stickyHeader) return
67
+
68
+ if (this.padding && Array.isArray(this.padding)) {
69
+ const [top = 0, right = 0, bottom = 0, left = 0] = this.padding
70
+ stickyHeader.style.padding = `${top}px ${right}px ${bottom}px ${left}px`
71
+ }
72
+ },
73
+ setTransformStyle () {
74
+ const stickyHeader = this.$refs.stickyHeader
75
+ if (!stickyHeader) return
76
+
77
+ // 设置 transform
78
+ if (this.scrollOffset > this.headerTop) {
79
+ stickyHeader.style.transform = `translateY(${this.scrollOffset - this.headerTop + this.offsetTop}px)`
80
+ } else {
81
+ stickyHeader.style.transform = 'none'
82
+ }
83
+ }
84
+ },
85
+ render(h) {
86
+ const style = {
87
+ width: '100%',
88
+ boxSizing: 'border-box',
89
+ position: 'relative',
90
+ zIndex: 10
91
+ }
92
+
93
+ return h('div', {
94
+ style,
95
+ ref: 'stickyHeader'
96
+ }, this.$slots.default)
97
+ }
98
+ }
99
+ </script>
@@ -0,0 +1,15 @@
1
+ <script>
2
+ export default {
3
+ name: 'mpx-sticky-section',
4
+ render(h) {
5
+ const style = {
6
+ position: 'relative'
7
+ }
8
+
9
+ return h('div', {
10
+ style,
11
+ class: 'mpx-sticky-section'
12
+ }, this.$slots.default)
13
+ }
14
+ }
15
+ </script>
@@ -1,3 +1,4 @@
1
+ import { ReactNode, ComponentType } from 'react'
1
2
  declare global {
2
3
  namespace NodeJS {
3
4
  interface Global {
@@ -7,3 +8,20 @@ declare global {
7
8
  }
8
9
 
9
10
  export function getComponent (...args: any): object
11
+
12
+ interface AsyncModule {
13
+ __esModule: boolean
14
+ default: ReactNode
15
+ }
16
+
17
+ interface AsyncSuspenseProps {
18
+ type: 'component' | 'page'
19
+ chunkName: string
20
+ moduleId: string
21
+ innerProps: any
22
+ loading: ComponentType<unknown>
23
+ fallback: ComponentType<unknown>
24
+ getChildren: () => Promise<AsyncModule>
25
+ }
26
+
27
+ export function getAsyncSuspense(props: AsyncSuspenseProps): ReactNode
@@ -1,6 +1,36 @@
1
+ import AsyncSuspense from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-async-suspense'
2
+ import { memo, forwardRef, createElement } from 'react'
3
+ import { extend } from './utils'
4
+
1
5
  export function getComponent (component, extendOptions) {
2
6
  component = component.__esModule ? component.default : component
3
7
  // eslint-disable-next-line
4
8
  if (extendOptions) Object.assign(component, extendOptions)
5
9
  return component
6
10
  }
11
+
12
+ export function getAsyncSuspense (commonProps) {
13
+ if (commonProps.type === 'component') {
14
+ return memo(forwardRef(function (props, ref) {
15
+ return createElement(AsyncSuspense,
16
+ extend(commonProps, {
17
+ innerProps: Object.assign({}, props, { ref })
18
+ })
19
+ )
20
+ }))
21
+ } else {
22
+ return function (props) {
23
+ return createElement(AsyncSuspense,
24
+ extend(commonProps, {
25
+ innerProps: props
26
+ })
27
+ )
28
+ }
29
+ }
30
+ }
31
+
32
+ export function getLazyPage (getComponent) {
33
+ return function (props) {
34
+ return createElement(getComponent(), props)
35
+ }
36
+ }
@@ -1,5 +1,6 @@
1
1
  const babylon = require('@babel/parser')
2
2
  const MagicString = require('magic-string')
3
+ const { SourceMapConsumer, SourceMapGenerator } = require('source-map')
3
4
  const traverse = require('@babel/traverse').default
4
5
  const t = require('@babel/types')
5
6
  const formatCodeFrame = require('@babel/code-frame')
@@ -625,7 +626,12 @@ function compileScriptSetup (
625
626
  _s.appendRight(endOffset, '})')
626
627
 
627
628
  return {
628
- content: _s.toString()
629
+ content: _s.toString(),
630
+ map: _s.generateMap({
631
+ source: filePath,
632
+ hires: true,
633
+ includeContent: true
634
+ })
629
635
  }
630
636
  }
631
637
 
@@ -1165,14 +1171,30 @@ function getCtor (ctorType) {
1165
1171
  return ctor
1166
1172
  }
1167
1173
 
1168
- module.exports = function (content) {
1174
+ module.exports = async function (content, sourceMap) {
1169
1175
  const { queryObj } = parseRequest(this.resource)
1170
1176
  const { ctorType, lang } = queryObj
1171
1177
  const filePath = this.resourcePath
1172
- const { content: callbackContent } = compileScriptSetup({
1178
+ const callback = this.async()
1179
+ let finalSourceMap = null
1180
+ const {
1181
+ content: callbackContent,
1182
+ map
1183
+ } = compileScriptSetup({
1173
1184
  content,
1174
1185
  lang
1175
1186
  }, ctorType, filePath)
1176
-
1177
- this.callback(null, callbackContent)
1187
+ finalSourceMap = map
1188
+ if (sourceMap) {
1189
+ const compiledMapConsumer = await new SourceMapConsumer(map)
1190
+ const compiledMapGenerator = SourceMapGenerator.fromSourceMap(compiledMapConsumer)
1191
+
1192
+ const originalConsumer = await new SourceMapConsumer(sourceMap)
1193
+ compiledMapGenerator.applySourceMap(
1194
+ originalConsumer,
1195
+ filePath // 需要确保与原始映射的source路径一致
1196
+ )
1197
+ finalSourceMap = compiledMapGenerator.toJSON()
1198
+ }
1199
+ callback(null, callbackContent, finalSourceMap)
1178
1200
  }
@@ -2,6 +2,7 @@ const babylon = require('@babel/parser')
2
2
  const traverse = require('@babel/traverse').default
3
3
  const t = require('@babel/types')
4
4
  const generate = require('@babel/generator').default
5
+ const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
5
6
 
6
7
  const names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
7
8
  'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
@@ -41,7 +42,7 @@ function getCollectPath (path) {
41
42
  if (current.node.computed) {
42
43
  if (t.isLiteral(current.node.property)) {
43
44
  if (t.isStringLiteral(current.node.property)) {
44
- if (dangerousKeyMap[current.node.property.value]) {
45
+ if (dangerousKeyMap[current.node.property.value] || !isValidIdentifierStr(current.node.property.value)) {
45
46
  break
46
47
  }
47
48
  keyPath += `.${current.node.property.value}`
@@ -581,7 +581,8 @@ function parseComponent (content, options) {
581
581
  let text = content.slice(currentBlock.start, currentBlock.end)
582
582
  // pad content so that linters and pre-processors can output correct
583
583
  // line numbers in errors and warnings
584
- if (options.pad) {
584
+ // stylus编译遇到大量空行时会出现栈溢出,故针对stylus不走pad
585
+ if (options.pad && !(currentBlock.tag === 'style' && currentBlock.lang === 'stylus')) {
585
586
  text = padContent(currentBlock, options.pad) + text
586
587
  }
587
588
  currentBlock.content = text
@@ -1849,7 +1850,7 @@ function processRefReact (el, meta) {
1849
1850
  }])
1850
1851
  }
1851
1852
 
1852
- if (el.tag === 'mpx-scroll-view' && el.attrsMap['scroll-into-view']) {
1853
+ if (el.tag === 'mpx-scroll-view') {
1853
1854
  addAttrs(el, [
1854
1855
  {
1855
1856
  name: '__selectRef',
@@ -2002,7 +2003,7 @@ function postProcessFor (el) {
2002
2003
  function postProcessForReact (el) {
2003
2004
  if (el.for) {
2004
2005
  if (el.for.key) {
2005
- addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key)}, ${el.for.index || 'index'})`, false, 'key')
2006
+ addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key === '_' ? 'index' : el.for.key)}, ${el.for.index || 'index'})`, false, 'key')
2006
2007
  addAttrs(el, [{
2007
2008
  name: 'key',
2008
2009
  value: el.for.key
@@ -72,7 +72,7 @@ const isNativeMiniTag = makeMap(
72
72
  * 是否为mpx内置组件
73
73
  * collected from packages/webpack-plugin/lib/runtime/components/web/
74
74
  */
75
- const isBuildInTag = makeMap(
75
+ const isBuildInWebTag = makeMap(
76
76
  'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
77
  'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
78
78
  'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
@@ -81,6 +81,19 @@ const isBuildInTag = makeMap(
81
81
  'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
82
82
  )
83
83
 
84
+ /**
85
+ * 是否为mpx2rn内置组件
86
+ */
87
+ const isBuildInReactTag = makeMap(
88
+ 'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
89
+ 'mpx-swiper,mpx-swiper-item,mpx-simple-view,mpx-simple-text,mpx-scroll-view,' +
90
+ 'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
91
+ 'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
92
+ 'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
+ 'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
+ 'mpx-icon,mpx-canvas'
95
+ )
96
+
84
97
  const isSpace = makeMap('ensp,emsp,nbsp')
85
98
 
86
99
  const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
@@ -105,11 +118,12 @@ module.exports = {
105
118
  isVoidTag,
106
119
  isNonPhrasingTag,
107
120
  isRichTextTag,
108
- isBuildInTag,
121
+ isBuildInWebTag,
109
122
  isUnaryTag,
110
123
  isSpace,
111
124
  isContWidth,
112
125
  isContHeight,
113
126
  isNativeMiniTag,
114
- isContConRow
127
+ isContConRow,
128
+ isBuildInReactTag
115
129
  }
@@ -0,0 +1,19 @@
1
+ function transSubpackage (asyncSubpackageNameRules, tarRoot) {
2
+ // 如果没有tarRoot,则无需进行tarRoot的修改,因此
3
+ if (tarRoot && Array.isArray(asyncSubpackageNameRules) && asyncSubpackageNameRules.length >= 1) {
4
+ for (const item of asyncSubpackageNameRules) {
5
+ if (item?.from) {
6
+ const fromPaths = Array.isArray(item.from) ? item.from : [item.from]
7
+ if (fromPaths.includes(tarRoot)) {
8
+ tarRoot = item.to
9
+ break
10
+ }
11
+ }
12
+ }
13
+ }
14
+ return tarRoot
15
+ }
16
+
17
+ module.exports = {
18
+ transSubpackage
19
+ }
@@ -13,7 +13,7 @@ function stringifyRequest (loaderContext, request) {
13
13
 
14
14
  function getAsyncChunkName (chunkName) {
15
15
  if (chunkName && typeof chunkName !== 'boolean') {
16
- return `/* webpackChunkName: "${chunkName}" */`
16
+ return `/* webpackChunkName: "${chunkName}/index" */`
17
17
  }
18
18
  return ''
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.7",
3
+ "version": "2.10.8",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,7 +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.10.6",
31
+ "@mpxjs/utils": "^2.10.8",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@d11/react-native-fast-image": "^8.6.12",
86
- "@mpxjs/api-proxy": "^2.10.7",
86
+ "@mpxjs/api-proxy": "^2.10.8",
87
87
  "@types/babel-traverse": "^6.25.4",
88
88
  "@types/babel-types": "^7.0.4",
89
89
  "@types/react": "^18.2.79",
@@ -100,5 +100,5 @@
100
100
  "engines": {
101
101
  "node": ">=14.14.0"
102
102
  },
103
- "gitHead": "3c56726c27464abac9cea343167d1b40933fff0d"
103
+ "gitHead": "23f6e6d5fa30e4abdc35e137007edbd38337b36e"
104
104
  }