@mpxjs/webpack-plugin 2.10.19 → 2.10.21

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 (137) hide show
  1. package/lib/dependencies/ResolveDependency.js +2 -2
  2. package/lib/index.js +38 -7
  3. package/lib/json-compiler/helper.js +11 -10
  4. package/lib/json-compiler/index.js +7 -4
  5. package/lib/json-compiler/plugin.js +4 -4
  6. package/lib/loader.js +4 -4
  7. package/lib/native-loader.js +4 -4
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/create-diagnostic.js +168 -0
  10. package/lib/platform/index.js +16 -3
  11. package/lib/platform/json/wx/index.js +66 -17
  12. package/lib/platform/run-rules.js +9 -5
  13. package/lib/platform/style/wx/index.js +82 -33
  14. package/lib/platform/template/normalize-component-rules.js +7 -9
  15. package/lib/platform/template/wx/component-config/block.js +2 -1
  16. package/lib/platform/template/wx/component-config/custom-built-in-component.js +34 -0
  17. package/lib/platform/template/wx/component-config/index.js +18 -3
  18. package/lib/platform/template/wx/component-config/input.js +1 -7
  19. package/lib/platform/template/wx/component-config/movable-view.js +1 -7
  20. package/lib/platform/template/wx/component-config/text.js +1 -1
  21. package/lib/platform/template/wx/component-config/textarea.js +1 -25
  22. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  23. package/lib/platform/template/wx/index.js +48 -34
  24. package/lib/react/processJSON.js +7 -4
  25. package/lib/react/processStyles.js +22 -8
  26. package/lib/react/processTemplate.js +98 -41
  27. package/lib/react/style-helper.js +121 -86
  28. package/lib/react/template-loader.js +161 -0
  29. package/lib/runtime/components/react/context.ts +8 -1
  30. package/lib/runtime/components/react/dist/context.d.ts +6 -1
  31. package/lib/runtime/components/react/dist/context.js +1 -0
  32. package/lib/runtime/components/react/dist/getInnerListeners.js +1 -0
  33. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +1 -1
  34. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -1
  35. package/lib/runtime/components/react/dist/mpx-button.jsx +6 -5
  36. package/lib/runtime/components/react/dist/mpx-camera.jsx +1 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -1
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +6 -4
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +3 -3
  41. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +5 -1
  42. package/lib/runtime/components/react/dist/mpx-image.d.ts +3 -3
  43. package/lib/runtime/components/react/dist/mpx-image.jsx +45 -12
  44. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +10 -6
  45. package/lib/runtime/components/react/dist/mpx-input.jsx +17 -4
  46. package/lib/runtime/components/react/dist/mpx-label.jsx +6 -4
  47. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +19 -4
  48. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +1 -1
  50. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +7 -4
  51. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  52. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +4 -1
  53. package/lib/runtime/components/react/dist/mpx-radio.jsx +5 -4
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -1
  55. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -4
  56. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +52 -6
  57. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +36 -6
  58. package/lib/runtime/components/react/dist/mpx-slider.jsx +2 -1
  59. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +8 -4
  60. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -4
  61. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +7 -4
  62. package/lib/runtime/components/react/dist/mpx-swiper.jsx +15 -4
  63. package/lib/runtime/components/react/dist/mpx-switch.jsx +4 -1
  64. package/lib/runtime/components/react/dist/mpx-text.jsx +57 -12
  65. package/lib/runtime/components/react/dist/mpx-video.d.ts +2 -1
  66. package/lib/runtime/components/react/dist/mpx-video.jsx +10 -4
  67. package/lib/runtime/components/react/dist/mpx-view.jsx +42 -7
  68. package/lib/runtime/components/react/dist/utils.d.ts +21 -11
  69. package/lib/runtime/components/react/dist/utils.jsx +105 -35
  70. package/lib/runtime/components/react/getInnerListeners.ts +1 -0
  71. package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
  72. package/lib/runtime/components/react/mpx-button.tsx +6 -5
  73. package/lib/runtime/components/react/mpx-camera.tsx +1 -0
  74. package/lib/runtime/components/react/mpx-canvas/index.tsx +4 -1
  75. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -1
  76. package/lib/runtime/components/react/mpx-checkbox.tsx +6 -4
  77. package/lib/runtime/components/react/mpx-form.tsx +3 -3
  78. package/lib/runtime/components/react/mpx-icon/index.tsx +5 -1
  79. package/lib/runtime/components/react/mpx-image.tsx +57 -20
  80. package/lib/runtime/components/react/mpx-inline-text.tsx +12 -7
  81. package/lib/runtime/components/react/mpx-input.tsx +17 -4
  82. package/lib/runtime/components/react/mpx-label.tsx +6 -4
  83. package/lib/runtime/components/react/mpx-movable-view.tsx +20 -4
  84. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -2
  85. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  86. package/lib/runtime/components/react/mpx-picker-view/index.tsx +8 -4
  87. package/lib/runtime/components/react/mpx-portal/index.tsx +5 -1
  88. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -1
  89. package/lib/runtime/components/react/mpx-radio.tsx +5 -4
  90. package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -1
  91. package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -4
  92. package/lib/runtime/components/react/mpx-simple-text.tsx +55 -8
  93. package/lib/runtime/components/react/mpx-simple-view.tsx +30 -6
  94. package/lib/runtime/components/react/mpx-slider.tsx +2 -1
  95. package/lib/runtime/components/react/mpx-sticky-header.tsx +8 -4
  96. package/lib/runtime/components/react/mpx-sticky-section.tsx +6 -4
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +7 -4
  98. package/lib/runtime/components/react/mpx-swiper.tsx +16 -4
  99. package/lib/runtime/components/react/mpx-switch.tsx +4 -1
  100. package/lib/runtime/components/react/mpx-text.tsx +55 -15
  101. package/lib/runtime/components/react/mpx-video.tsx +11 -5
  102. package/lib/runtime/components/react/mpx-view.tsx +35 -7
  103. package/lib/runtime/components/react/types/global.d.ts +4 -0
  104. package/lib/runtime/components/react/utils.tsx +126 -45
  105. package/lib/runtime/components/wx/default-component.mpx +9 -0
  106. package/lib/runtime/components/wx/default-page.mpx +3 -11
  107. package/lib/runtime/optionProcessor.d.ts +2 -0
  108. package/lib/runtime/optionProcessor.js +77 -1
  109. package/lib/runtime/optionProcessorReact.js +5 -0
  110. package/lib/script-setup-compiler/index.js +1 -1
  111. package/lib/style-compiler/index.js +2 -0
  112. package/lib/style-compiler/plugins/remove-strip-conditional-comments.js +14 -0
  113. package/lib/style-compiler/plugins/trans-special.js +1 -1
  114. package/lib/style-compiler/strip-conditional.js +40 -26
  115. package/lib/template-compiler/compiler.js +306 -125
  116. package/lib/template-compiler/gen-node-react.js +35 -7
  117. package/lib/template-compiler/index.js +9 -7
  118. package/lib/utils/const.js +4 -1
  119. package/lib/utils/gen-component-tag.js +1 -5
  120. package/lib/utils/normalize-perf-options.js +47 -0
  121. package/lib/utils/partial-compile-rules.js +27 -0
  122. package/lib/utils/pre-process-json.js +3 -0
  123. package/lib/utils/source-location.js +96 -0
  124. package/lib/web/compile-wx-template-fragment.js +68 -0
  125. package/lib/web/index.js +3 -0
  126. package/lib/web/processJSON.js +7 -4
  127. package/lib/web/processMainScript.js +3 -7
  128. package/lib/web/processScript.js +43 -8
  129. package/lib/web/processStyles.js +12 -3
  130. package/lib/web/processTemplate.js +61 -19
  131. package/lib/web/template-loader.js +123 -0
  132. package/lib/web/template-shared.js +48 -0
  133. package/lib/wxml/loader.js +4 -3
  134. package/lib/wxss/loader.js +1 -1
  135. package/lib/wxss/utils.js +6 -4
  136. package/package.json +12 -4
  137. package/lib/platform/template/wx/component-config/component.js +0 -41
@@ -2,20 +2,24 @@ const postcss = require('postcss')
2
2
  const selectorParser = require('postcss-selector-parser')
3
3
  const { MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
4
4
  const getRulesRunner = require('../platform/index')
5
+ const createDiagnostic = require('../platform/create-diagnostic')
5
6
  const dash2hump = require('../utils/hump-dash').dash2hump
6
7
  const parseValues = require('../utils/string').parseValues
7
8
  const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh|px)?\s*$/
8
9
  const hairlineRegExp = /^\s*hairlineWidth\s*$/
9
10
  const varRegExp = /^--/
10
11
  const cssPrefixExp = /^-(webkit|moz|ms|o)-/
11
- function getClassMap ({ content, filename, mode, srcMode, ctorType, formatValueName, warn, error }) {
12
+ function getClassMap ({ content, styles, filename, inputFileSystem, mode, srcMode, ctorType, formatValueName, warn, error }) {
12
13
  const classMap = ctorType === 'page'
13
14
  ? { [MPX_TAG_PAGE_SELECTOR]: { flex: 1, height: "'100%'" } }
14
15
  : {}
15
16
 
16
- const root = postcss.parse(content, {
17
- from: filename
18
- })
17
+ styles = styles && styles.length
18
+ ? styles
19
+ : [{
20
+ content,
21
+ filename
22
+ }]
19
23
 
20
24
  function formatValue (value) {
21
25
  let needStringify = true
@@ -30,7 +34,7 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, formatValueN
30
34
  }
31
35
  }
32
36
  if (hairlineRegExp.test(value)) {
33
- value = `${formatValueName}(${JSON.stringify(value)}, 'hairlineWidth')`
37
+ value = `${formatValueName}('hairlineWidth')`
34
38
  needStringify = false
35
39
  }
36
40
  return needStringify ? JSON.stringify(value) : value
@@ -67,99 +71,130 @@ function getClassMap ({ content, filename, mode, srcMode, ctorType, formatValueN
67
71
  }, {})
68
72
  }
69
73
 
70
- const rulesRunner = getRulesRunner({
71
- mode,
72
- srcMode,
73
- type: 'style',
74
- testKey: 'prop',
75
- warn,
76
- error
77
- })
78
-
79
- // 目前所有 AtRule 只支持 @media,其他全部给出错误提示
80
- root.walkAtRules(rule => {
81
- if (rule.name !== 'media') {
82
- warn(`Only @media rule is supported in react native mode temporarily, but got @${rule.name}`)
83
- // 删除不支持的 AtRule,防止其影响后续解析
84
- rule.remove()
74
+ styles.forEach((style) => {
75
+ const styleContent = style.content || ''
76
+ if (!styleContent.trim()) return
77
+ const styleFilename = style.filename || filename
78
+ const sourceMap = style.map
79
+ const diagnostic = {
80
+ file: styleFilename,
81
+ source: styleContent,
82
+ sourceMap,
83
+ inputFileSystem
85
84
  }
86
- })
85
+ const reporter = createDiagnostic({
86
+ type: 'style',
87
+ mode,
88
+ srcMode,
89
+ warn,
90
+ error,
91
+ diagnostic
92
+ })
93
+ const root = postcss.parse(styleContent, {
94
+ from: styleFilename
95
+ })
96
+ const rulesRunner = getRulesRunner({
97
+ mode,
98
+ srcMode,
99
+ type: 'style',
100
+ testKey: 'prop',
101
+ warn,
102
+ error,
103
+ diagnostic
104
+ })
87
105
 
88
- root.walkRules(rule => {
89
- const classMapValue = {}
90
- rule.walkDecls(({ prop, value }) => {
91
- if (value === 'undefined' || cssPrefixExp.test(prop) || cssPrefixExp.test(value)) return
92
- let newData = rulesRunner({ prop, value, selector: rule.selector })
93
- if (!newData) return
94
- if (!Array.isArray(newData)) {
95
- newData = [newData]
96
- }
97
- newData.forEach(item => {
98
- prop = varRegExp.test(item.prop) ? item.prop : dash2hump(item.prop)
99
- value = item.value
100
- if (Array.isArray(value)) {
101
- value = value.map(val => {
102
- if (typeof val === 'object') {
103
- for (const key in val) {
104
- val[key] = formatValue(val[key])
105
- }
106
- return val
107
- } else {
108
- return formatValue(val)
109
- }
110
- })
111
- } else if (typeof value === 'object') {
112
- for (const key in value) {
113
- value[key] = formatValue(value[key])
106
+ // 目前所有 AtRule 只支持 @media,其他全部给出错误提示
107
+ root.walkAtRules(rule => {
108
+ if (rule.name !== 'media') {
109
+ reporter.warn(`Only @media rule is supported in react native mode temporarily, but got @${rule.name}`, {
110
+ node: rule,
111
+ sourceMap,
112
+ target: {
113
+ kind: 'css-atrule',
114
+ name: rule.name,
115
+ params: rule.params
114
116
  }
115
- } else {
116
- value = formatValue(value)
117
- }
118
- classMapValue[prop] = value
119
- })
117
+ })
118
+ // 删除不支持的 AtRule,防止其影响后续解析
119
+ rule.remove()
120
+ }
120
121
  })
121
122
 
122
- const classMapKeys = []
123
- const options = getMediaOptions(rule.parent.params || '')
124
- const isMedia = options.maxWidth || options.minWidth
125
- selectorParser(selectors => {
126
- selectors.each(selector => {
127
- if (selector.nodes.length === 1 && selector.nodes[0].type === 'class') {
128
- classMapKeys.push(selector.nodes[0].value)
129
- } else {
130
- error('Only single class selector is supported in react native mode temporarily.')
123
+ root.walkRules(rule => {
124
+ const classMapValue = {}
125
+ rule.walkDecls((decl) => {
126
+ let { prop, value } = decl
127
+ if (value === 'undefined' || cssPrefixExp.test(prop) || cssPrefixExp.test(value)) return
128
+ let newData = rulesRunner && rulesRunner({ prop, value, selector: rule.selector, decl, rule, sourceMap })
129
+ if (!newData) return
130
+ if (!Array.isArray(newData)) {
131
+ newData = [newData]
131
132
  }
132
- })
133
- }).processSync(rule.selector)
134
-
135
- if (classMapKeys.length) {
136
- classMapKeys.forEach((key) => {
137
- if (Object.keys(classMapValue).length) {
138
- let _default = classMap[key]?._default
139
- let _media = classMap[key]?._media
140
- if (isMedia) {
141
- // 当前是媒体查询
142
- _default = _default || {}
143
- _media = _media || []
144
- _media.push({
145
- options,
146
- value: classMapValue
133
+ newData.forEach(item => {
134
+ prop = varRegExp.test(item.prop) ? item.prop : dash2hump(item.prop)
135
+ value = item.value
136
+ if (Array.isArray(value)) {
137
+ value = value.map(val => {
138
+ if (typeof val === 'object') {
139
+ for (const key in val) {
140
+ val[key] = formatValue(val[key])
141
+ }
142
+ return val
143
+ } else {
144
+ return formatValue(val)
145
+ }
147
146
  })
148
- classMap[key] = {
149
- _media,
150
- _default
147
+ } else if (typeof value === 'object') {
148
+ for (const key in value) {
149
+ value[key] = formatValue(value[key])
151
150
  }
152
- } else if (_default) {
153
- // 已有媒体查询数据,此次非媒体查询
154
- Object.assign(_default, classMapValue)
155
151
  } else {
156
- // 无媒体查询
152
+ value = formatValue(value)
153
+ }
154
+ classMapValue[prop] = value
155
+ })
156
+ })
157
+
158
+ const classMapKeys = []
159
+ const options = getMediaOptions(rule.parent.params || '')
160
+ const isMedia = options.maxWidth || options.minWidth
161
+ selectorParser(selectors => {
162
+ selectors.each(selector => {
163
+ if (selector.nodes.length === 1 && selector.nodes[0].type === 'class') {
164
+ classMapKeys.push(selector.nodes[0].value)
165
+ } else {
166
+ reporter.error('Only single class selector is supported in react native mode temporarily.', {
167
+ node: rule,
168
+ sourceMap,
169
+ target: {
170
+ kind: 'selector',
171
+ value: rule.selector
172
+ }
173
+ })
174
+ }
175
+ })
176
+ }).processSync(rule.selector)
177
+
178
+ if (classMapKeys.length) {
179
+ classMapKeys.forEach((key) => {
180
+ if (Object.keys(classMapValue).length) {
181
+ // set css defalut value
157
182
  const val = classMap[key] || {}
158
183
  classMap[key] = Object.assign(val, classMapValue)
184
+
185
+ // set css media
186
+ if (isMedia) {
187
+ const _media = classMap[key]?._media || []
188
+ _media.push({
189
+ options,
190
+ value: classMapValue
191
+ })
192
+ classMap[key]._media = _media
193
+ }
159
194
  }
160
- }
161
- })
162
- }
195
+ })
196
+ }
197
+ })
163
198
  })
164
199
  return classMap
165
200
  }
@@ -0,0 +1,161 @@
1
+ const loaderUtils = require('loader-utils')
2
+ const addQuery = require('../utils/add-query')
3
+ const normalize = require('../utils/normalize')
4
+ const parseRequest = require('../utils/parse-request')
5
+ const { matchCondition } = require('../utils/match-condition')
6
+ const templateCompiler = require('../template-compiler/compiler')
7
+ const { genTemplate } = require('../template-compiler/gen-node-react')
8
+ const bindThis = require('../template-compiler/bind-this')
9
+ const isUrlRequestBase = require('../utils/is-url-request')
10
+
11
+ module.exports = function (content) {
12
+ const loaderContext = this
13
+ const mpx = loaderContext.getMpx()
14
+
15
+ const {
16
+ projectRoot,
17
+ externals,
18
+ mode,
19
+ srcMode,
20
+ env,
21
+ defs,
22
+ wxsContentMap,
23
+ decodeHTMLText,
24
+ externalClasses,
25
+ forceProxyEventRules,
26
+ getModuleId,
27
+ rnConfig
28
+ } = mpx
29
+
30
+ const { resourcePath, rawResourcePath, queryObj } = parseRequest(loaderContext.resource)
31
+ const moduleId = getModuleId(resourcePath)
32
+
33
+ const warn = (msg, loc) => {
34
+ loaderContext.emitWarning(
35
+ new Error('[Mpx template warning][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
36
+ )
37
+ }
38
+ const error = (msg, loc) => {
39
+ loaderContext.emitError(
40
+ new Error('[Mpx template error][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
41
+ )
42
+ }
43
+ const parseOptions = {
44
+ warn,
45
+ error,
46
+ mode,
47
+ srcMode: queryObj.srcMode || srcMode,
48
+ env,
49
+ defs,
50
+ decodeHTMLText,
51
+ externalClasses,
52
+ moduleId,
53
+ filePath: rawResourcePath,
54
+ forceProxyEvent: matchCondition(resourcePath, forceProxyEventRules),
55
+ customBuiltInComponents: rnConfig && rnConfig.customBuiltInComponents,
56
+ isUrlRequest: (url) => isUrlRequestBase(url, projectRoot, externals)
57
+ }
58
+
59
+ // Parse the template
60
+ const { meta } = templateCompiler.parse(content, parseOptions)
61
+ const templateAssetsIgnoreMap = {}
62
+ let templateAssetsCode = ''
63
+ if (meta.templateAssets) {
64
+ Object.keys(meta.templateAssets).forEach((name) => {
65
+ templateAssetsIgnoreMap[name] = true
66
+ const request = loaderUtils.urlToRequest(meta.templateAssets[name], projectRoot)
67
+ templateAssetsCode += `var ${name} = require(${loaderUtils.stringifyRequest(loaderContext, request)});\n`
68
+ })
69
+ }
70
+ if (meta.wxsContentMap && wxsContentMap) {
71
+ for (const module in meta.wxsContentMap) {
72
+ wxsContentMap[`${rawResourcePath}~${module}`] = meta.wxsContentMap[module]
73
+ }
74
+ }
75
+
76
+ // Generate imports
77
+ const imports = []
78
+ if (meta.imports) {
79
+ const reactTemplateLoaderPath = normalize.lib('react/template-loader')
80
+ meta.imports.forEach((importSrc) => {
81
+ const request = loaderUtils.urlToRequest(importSrc, projectRoot)
82
+ imports.push(`require(${loaderUtils.stringifyRequest(loaderContext, `!!${reactTemplateLoaderPath}!${request}`)})`)
83
+ })
84
+ }
85
+
86
+ const builtInPaths = meta.builtInComponentsMap || {}
87
+ const builtInComponents = []
88
+ Object.keys(builtInPaths).forEach((componentName) => {
89
+ const componentRequest = loaderUtils.stringifyRequest(loaderContext, addQuery(builtInPaths[componentName], { isComponent: true }))
90
+ builtInComponents.push(`"${componentName}": function () { return getBuiltInBaseComponent(require(${componentRequest}), { __mpxBuiltIn: true }) }`)
91
+ })
92
+
93
+ // Generate local templates
94
+ let localTemplatesCode = 'var localTemplates = {\n'
95
+ if (meta.templates) {
96
+ Object.keys(meta.templates).forEach((name) => {
97
+ const template = meta.templates[name]
98
+ const templateCode = genTemplate(template)
99
+ if (templateCode) {
100
+ localTemplatesCode += `${JSON.stringify(name)}: ${templateCode},\n`
101
+ }
102
+ })
103
+ }
104
+ localTemplatesCode += '};'
105
+
106
+ try {
107
+ const ignoreMap = Object.assign({
108
+ createElement: true,
109
+ getComponent: true,
110
+ getTemplate: true
111
+ }, meta.wxsModuleMap, templateAssetsIgnoreMap)
112
+ const bindResult = bindThis.transform(localTemplatesCode, {
113
+ ignoreMap
114
+ })
115
+ localTemplatesCode = bindResult.code
116
+ } catch (e) {
117
+ loaderContext.emitError(
118
+ new Error(`[Mpx template error]: Invalid render function generated by the template, please check!\\n Error code:\\n ${localTemplatesCode}\\n Error Detail:\\n ${e.stack}`)
119
+ )
120
+ }
121
+
122
+ let wxsImports = ''
123
+ for (const module in meta.wxsModuleMap) {
124
+ const request = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
125
+ wxsImports += `var ${module} = require(${loaderUtils.stringifyRequest(loaderContext, request)});\n`
126
+ }
127
+ const hasTemplateSource = imports.length || (meta.templates && Object.keys(meta.templates).length)
128
+ const templateHelpersCode = hasTemplateSource
129
+ ? `var templates = Object.assign({}, ${imports.join(', ') || '{}'});
130
+ Object.assign(templates, localTemplates);
131
+ function getTemplate(name) {
132
+ return templates[name] || function(){};
133
+ }`
134
+ : ''
135
+
136
+ const output = `
137
+ ${wxsImports}
138
+ ${templateAssetsCode}
139
+ var getBuiltInBaseComponent = require(${loaderUtils.stringifyRequest(loaderContext, normalize.lib('runtime/optionProcessorReact'))}).getComponent;
140
+ var builtInComponentsMap = {${builtInComponents.join(',')}};
141
+ ${localTemplatesCode}
142
+ ${templateHelpersCode}
143
+ function getBuiltInComponent(name) {
144
+ var getter = builtInComponentsMap[name];
145
+ return getter && getter();
146
+ }
147
+ function getTemplateComponent(name, getComponent) {
148
+ return getComponent(name) || getBuiltInComponent(name);
149
+ }
150
+ Object.keys(localTemplates).forEach(function (name) {
151
+ var template = localTemplates[name];
152
+ localTemplates[name] = function (createElement, getComponent) {
153
+ return template.call(this, createElement, function (componentName) {
154
+ return getTemplateComponent(componentName, getComponent);
155
+ });
156
+ };
157
+ });
158
+ module.exports = localTemplates;
159
+ `
160
+ return output
161
+ }
@@ -1,5 +1,5 @@
1
1
  import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react'
2
- import type { NativeSyntheticEvent, Animated, ScaledSize } from 'react-native'
2
+ import type { NativeSyntheticEvent, Animated, ScaledSize, TextStyle } from 'react-native'
3
3
  import { noop } from '@mpxjs/utils'
4
4
 
5
5
  export type LabelContextValue = MutableRefObject<{
@@ -70,6 +70,11 @@ export interface StickyContextValue {
70
70
  unregisterStickyHeader: Function
71
71
  }
72
72
 
73
+ export interface TextPassThroughContextValue {
74
+ textStyle?: TextStyle
75
+ pendingTextProps?: Record<string, any>
76
+ }
77
+
73
78
  export const MovableAreaContext = createContext({ width: 0, height: 0 })
74
79
 
75
80
  export const FormContext = createContext<FormContextValue | null>(null)
@@ -84,6 +89,8 @@ export const PickerContext = createContext(null)
84
89
 
85
90
  export const VarContext = createContext({})
86
91
 
92
+ export const TextPassThroughContext = createContext<TextPassThroughContextValue | null>(null)
93
+
87
94
  export const IntersectionObserverContext = createContext<IntersectionObserver | null>(null)
88
95
 
89
96
  export const RouteContext = createContext<RouteContextValue | null>(null)
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, MutableRefObject, SetStateAction } from 'react';
2
- import type { NativeSyntheticEvent, Animated, ScaledSize } from 'react-native';
2
+ import type { NativeSyntheticEvent, Animated, ScaledSize, TextStyle } from 'react-native';
3
3
  export type LabelContextValue = MutableRefObject<{
4
4
  triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void;
5
5
  }>;
@@ -62,6 +62,10 @@ export interface StickyContextValue {
62
62
  registerStickyHeader: Function;
63
63
  unregisterStickyHeader: Function;
64
64
  }
65
+ export interface TextPassThroughContextValue {
66
+ textStyle?: TextStyle;
67
+ pendingTextProps?: Record<string, any>;
68
+ }
65
69
  export declare const MovableAreaContext: import("react").Context<{
66
70
  width: number;
67
71
  height: number;
@@ -72,6 +76,7 @@ export declare const RadioGroupContext: import("react").Context<GroupContextValu
72
76
  export declare const LabelContext: import("react").Context<LabelContextValue | null>;
73
77
  export declare const PickerContext: import("react").Context<null>;
74
78
  export declare const VarContext: import("react").Context<{}>;
79
+ export declare const TextPassThroughContext: import("react").Context<TextPassThroughContextValue | null>;
75
80
  export declare const IntersectionObserverContext: import("react").Context<IntersectionObserver | null>;
76
81
  export declare const RouteContext: import("react").Context<RouteContextValue | null>;
77
82
  export declare const SwiperContext: import("react").Context<{}>;
@@ -7,6 +7,7 @@ export const RadioGroupContext = createContext(null);
7
7
  export const LabelContext = createContext(null);
8
8
  export const PickerContext = createContext(null);
9
9
  export const VarContext = createContext({});
10
+ export const TextPassThroughContext = createContext(null);
10
11
  export const IntersectionObserverContext = createContext(null);
11
12
  export const RouteContext = createContext(null);
12
13
  export const SwiperContext = createContext({});
@@ -257,6 +257,7 @@ const useInnerProps = (props = {}, userRemoveProps = [], rawConfig) => {
257
257
  'parent-font-size',
258
258
  'parent-width',
259
259
  'parent-height',
260
+ 'enable-text-pass-through',
260
261
  ...userRemoveProps,
261
262
  ...rawEventKeys
262
263
  ];
@@ -124,7 +124,7 @@ const AsyncSuspense = ({ type, chunkName, moduleId, innerProps, getLoading, getF
124
124
  else if (status === 'error') {
125
125
  if (type === 'page') {
126
126
  const fallback = getFallback ? getFallback() : DefaultFallback;
127
- return createElement(fallback, { onReload: reloadPage });
127
+ return createElement(fallback, { onReload: reloadPage, bindreload: reloadPage });
128
128
  }
129
129
  else {
130
130
  return getFallback ? createElement(getFallback(), innerProps) : null;
@@ -19,7 +19,7 @@
19
19
  * ✘ app-parameter
20
20
  * ✘ show-message-card
21
21
  * ✘ phone-number-no-quota-toast
22
- * bindgetuserinfo
22
+ * bindgetuserinfo
23
23
  * ✘ bindcontact
24
24
  * ✘ createliveactivity
25
25
  * ✘ bindgetphonenumber
@@ -19,7 +19,7 @@
19
19
  * ✘ app-parameter
20
20
  * ✘ show-message-card
21
21
  * ✘ phone-number-no-quota-toast
22
- * bindgetuserinfo
22
+ * bindgetuserinfo
23
23
  * ✘ bindcontact
24
24
  * ✘ createliveactivity
25
25
  * ✘ bindgetphonenumber
@@ -38,7 +38,7 @@ import { createElement, useEffect, useRef, forwardRef, useContext } from 'react'
38
38
  import { View, StyleSheet, Animated, Easing, useAnimatedValue } from 'react-native';
39
39
  import { warn } from '@mpxjs/utils';
40
40
  import { GestureDetector } from 'react-native-gesture-handler';
41
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils';
41
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover, useTextPassThroughValue } from './utils';
42
42
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
43
43
  import useNodesRef from './useNodesRef';
44
44
  import { RouteContext, FormContext } from './context';
@@ -173,6 +173,7 @@ const Button = forwardRef((buttonProps, ref) => {
173
173
  useNodesRef(props, ref, nodeRef, { style: normalStyle });
174
174
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
175
175
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
176
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps);
176
177
  if (backgroundStyle) {
177
178
  warn('Button does not support background image-related styles!');
178
179
  }
@@ -252,7 +253,8 @@ const Button = forwardRef((buttonProps, ref) => {
252
253
  'hover-start-time',
253
254
  'hover-stay-time',
254
255
  'open-type',
255
- 'form-type'
256
+ 'form-type',
257
+ 'bindgetuserinfo'
256
258
  ], {
257
259
  layoutRef,
258
260
  disableTap: disabled
@@ -260,8 +262,7 @@ const Button = forwardRef((buttonProps, ref) => {
260
262
  const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props, {
261
263
  hasVarDec,
262
264
  varContext: varContextRef.current,
263
- textStyle,
264
- textProps
265
+ textPassThrough
265
266
  }));
266
267
  const finalComponent = enableHover
267
268
  ? createElement(GestureDetector, { gesture: gesture }, baseButton)
@@ -246,6 +246,7 @@ const _camera = forwardRef((props, ref) => {
246
246
  'mode',
247
247
  'resolution',
248
248
  'frame-size',
249
+ 'device-position',
249
250
  'bindinitdone',
250
251
  'bindstop',
251
252
  'flash',
@@ -60,7 +60,10 @@ const _Canvas = forwardRef((props = {}, ref) => {
60
60
  const innerProps = useInnerProps(extendObject({}, props, layoutProps, {
61
61
  ref: nodeRef,
62
62
  style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 })
63
- }), [], {
63
+ }), [
64
+ 'originWhitelist',
65
+ 'binderror'
66
+ ], {
64
67
  layoutRef
65
68
  });
66
69
  const context2D = new CanvasRenderingContext2D(canvasRef.current);
@@ -62,7 +62,8 @@ const CheckboxGroup = forwardRef((props, ref) => {
62
62
  ref: nodeRef,
63
63
  style: extendObject({}, normalStyle, layoutStyle)
64
64
  }), [
65
- 'name'
65
+ 'name',
66
+ 'bindchange'
66
67
  ], {
67
68
  layoutRef
68
69
  });
@@ -10,7 +10,7 @@ import { warn } from '@mpxjs/utils';
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
11
  import useNodesRef from './useNodesRef';
12
12
  import Icon from './mpx-icon';
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThroughValue } from './utils';
14
14
  import { CheckboxGroupContext, LabelContext } from './context';
15
15
  import Portal from './mpx-portal';
16
16
  const styles = StyleSheet.create({
@@ -72,6 +72,7 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
72
72
  });
73
73
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
74
74
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
75
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps);
75
76
  if (backgroundStyle) {
76
77
  warn('Checkbox does not support background image-related styles!');
77
78
  }
@@ -90,7 +91,9 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
90
91
  }), [
91
92
  'value',
92
93
  'disabled',
93
- 'checked'
94
+ 'checked',
95
+ 'color',
96
+ '_onChange'
94
97
  ], {
95
98
  layoutRef
96
99
  });
@@ -123,8 +126,7 @@ const Checkbox = forwardRef((checkboxProps, ref) => {
123
126
  })), wrapChildren(props, {
124
127
  hasVarDec,
125
128
  varContext: varContextRef.current,
126
- textStyle,
127
- textProps
129
+ textPassThrough
128
130
  }));
129
131
  if (hasPositionFixed) {
130
132
  return createElement(Portal, null, finalComponent);
@@ -9,12 +9,13 @@ import { useRef, forwardRef, useMemo, createElement } from 'react';
9
9
  import useNodesRef from './useNodesRef';
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
11
  import { FormContext } from './context';
12
- import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils';
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThroughValue } from './utils';
13
13
  const _Form = forwardRef((fromProps, ref) => {
14
14
  const { textProps, innerProps: props = {} } = splitProps(fromProps);
15
15
  const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
16
16
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
17
17
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
18
+ const textPassThrough = useTextPassThroughValue(textStyle, textProps);
18
19
  const formRef = useRef(null);
19
20
  useNodesRef(props, ref, formRef, {
20
21
  style: normalStyle
@@ -60,8 +61,7 @@ const _Form = forwardRef((fromProps, ref) => {
60
61
  return createElement(View, innerProps, createElement(FormContext.Provider, { value: contextValue }, wrapChildren(props, {
61
62
  hasVarDec,
62
63
  varContext: varContextRef.current,
63
- textStyle,
64
- textProps
64
+ textPassThrough
65
65
  })));
66
66
  });
67
67
  _Form.displayName = 'MpxForm';
@@ -42,7 +42,11 @@ const Icon = forwardRef((props, ref) => {
42
42
  ref: nodeRef,
43
43
  source,
44
44
  style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
45
- }), [], {
45
+ }), [
46
+ 'type',
47
+ 'size',
48
+ 'color'
49
+ ], {
46
50
  layoutRef
47
51
  });
48
52
  const finalComponent = createElement(Image, innerProps);