@mpxjs/webpack-plugin 2.10.20 → 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 (92) hide show
  1. package/lib/index.js +13 -1
  2. package/lib/parser.js +1 -1
  3. package/lib/platform/style/wx/index.js +78 -30
  4. package/lib/platform/template/wx/component-config/block.js +2 -1
  5. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  6. package/lib/react/processTemplate.js +23 -10
  7. package/lib/react/style-helper.js +1 -1
  8. package/lib/react/template-loader.js +15 -2
  9. package/lib/runtime/components/react/context.ts +8 -1
  10. package/lib/runtime/components/react/dist/context.d.ts +6 -1
  11. package/lib/runtime/components/react/dist/context.js +1 -0
  12. package/lib/runtime/components/react/dist/getInnerListeners.js +1 -0
  13. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -1
  14. package/lib/runtime/components/react/dist/mpx-button.jsx +6 -5
  15. package/lib/runtime/components/react/dist/mpx-camera.jsx +1 -0
  16. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -1
  17. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
  18. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +6 -4
  19. package/lib/runtime/components/react/dist/mpx-form.jsx +3 -3
  20. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +5 -1
  21. package/lib/runtime/components/react/dist/mpx-image.d.ts +3 -2
  22. package/lib/runtime/components/react/dist/mpx-image.jsx +46 -12
  23. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +10 -6
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +17 -4
  25. package/lib/runtime/components/react/dist/mpx-label.jsx +6 -4
  26. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +19 -4
  27. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -2
  28. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +7 -4
  29. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  30. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +4 -1
  31. package/lib/runtime/components/react/dist/mpx-radio.jsx +5 -4
  32. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +3 -1
  33. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -4
  34. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +52 -6
  35. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +36 -6
  36. package/lib/runtime/components/react/dist/mpx-slider.jsx +2 -1
  37. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +8 -4
  38. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -4
  39. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +7 -4
  40. package/lib/runtime/components/react/dist/mpx-swiper.jsx +15 -4
  41. package/lib/runtime/components/react/dist/mpx-switch.jsx +4 -1
  42. package/lib/runtime/components/react/dist/mpx-text.jsx +57 -12
  43. package/lib/runtime/components/react/dist/mpx-video.d.ts +2 -1
  44. package/lib/runtime/components/react/dist/mpx-video.jsx +10 -4
  45. package/lib/runtime/components/react/dist/mpx-view.jsx +42 -7
  46. package/lib/runtime/components/react/dist/utils.d.ts +21 -11
  47. package/lib/runtime/components/react/dist/utils.jsx +102 -33
  48. package/lib/runtime/components/react/getInnerListeners.ts +1 -0
  49. package/lib/runtime/components/react/mpx-button.tsx +6 -5
  50. package/lib/runtime/components/react/mpx-camera.tsx +1 -0
  51. package/lib/runtime/components/react/mpx-canvas/index.tsx +4 -1
  52. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -1
  53. package/lib/runtime/components/react/mpx-checkbox.tsx +6 -4
  54. package/lib/runtime/components/react/mpx-form.tsx +3 -3
  55. package/lib/runtime/components/react/mpx-icon/index.tsx +5 -1
  56. package/lib/runtime/components/react/mpx-image.tsx +58 -19
  57. package/lib/runtime/components/react/mpx-inline-text.tsx +12 -7
  58. package/lib/runtime/components/react/mpx-input.tsx +17 -4
  59. package/lib/runtime/components/react/mpx-label.tsx +6 -4
  60. package/lib/runtime/components/react/mpx-movable-view.tsx +20 -4
  61. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -2
  62. package/lib/runtime/components/react/mpx-picker-view/index.tsx +8 -4
  63. package/lib/runtime/components/react/mpx-portal/index.tsx +5 -1
  64. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -1
  65. package/lib/runtime/components/react/mpx-radio.tsx +5 -4
  66. package/lib/runtime/components/react/mpx-rich-text/index.tsx +3 -1
  67. package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -4
  68. package/lib/runtime/components/react/mpx-simple-text.tsx +55 -8
  69. package/lib/runtime/components/react/mpx-simple-view.tsx +30 -6
  70. package/lib/runtime/components/react/mpx-slider.tsx +2 -1
  71. package/lib/runtime/components/react/mpx-sticky-header.tsx +8 -4
  72. package/lib/runtime/components/react/mpx-sticky-section.tsx +6 -4
  73. package/lib/runtime/components/react/mpx-swiper-item.tsx +7 -4
  74. package/lib/runtime/components/react/mpx-swiper.tsx +16 -4
  75. package/lib/runtime/components/react/mpx-switch.tsx +4 -1
  76. package/lib/runtime/components/react/mpx-text.tsx +55 -15
  77. package/lib/runtime/components/react/mpx-video.tsx +11 -5
  78. package/lib/runtime/components/react/mpx-view.tsx +35 -7
  79. package/lib/runtime/components/react/types/global.d.ts +4 -0
  80. package/lib/runtime/components/react/utils.tsx +123 -43
  81. package/lib/runtime/optionProcessorReact.js +5 -0
  82. package/lib/script-setup-compiler/index.js +1 -1
  83. package/lib/style-compiler/plugins/trans-special.js +1 -1
  84. package/lib/template-compiler/compiler.js +37 -14
  85. package/lib/utils/gen-component-tag.js +1 -5
  86. package/lib/utils/normalize-perf-options.js +47 -0
  87. package/lib/web/index.js +1 -0
  88. package/lib/web/processMainScript.js +3 -7
  89. package/lib/web/processScript.js +3 -6
  90. package/lib/web/processStyles.js +12 -3
  91. package/lib/wxml/loader.js +1 -1
  92. package/package.json +5 -4
package/lib/index.js CHANGED
@@ -53,6 +53,7 @@ const { transSubpackage } = require('./utils/trans-async-sub-rules')
53
53
  const { matchCondition } = require('./utils/match-condition')
54
54
  const { getPartialCompileRules } = require('./utils/partial-compile-rules')
55
55
  const processDefs = require('./utils/process-defs')
56
+ const { PERF_GROUPS, normalizePerfOptions } = require('./utils/normalize-perf-options')
56
57
  const config = require('./config')
57
58
  const hash = require('hash-sum')
58
59
  const nativeLoaderPath = normalize.lib('native-loader')
@@ -164,13 +165,24 @@ class MpxWebpackPlugin {
164
165
  options.transMpxRules = options.transMpxRules || {
165
166
  include: () => true
166
167
  }
168
+ // 归一化 perf 配置:{ enable, probes: [...] } → { enable, framework, user, ... }
169
+ // 分组未知 / typo 在此直接抛错,避免静默失效。
170
+ const perf = normalizePerfOptions(options.perf)
171
+ options.perf = perf
167
172
  // 通过默认defs配置实现mode及srcMode的注入,简化内部处理逻辑
168
173
  options.defs = Object.assign({}, options.defs, {
169
174
  __mpx_mode__: options.mode,
170
175
  __mpx_src_mode__: options.srcMode,
171
176
  __mpx_env__: options.env,
172
- __mpx_dynamic_runtime__: options.dynamicRuntime
177
+ __mpx_dynamic_runtime__: options.dynamicRuntime,
178
+ // 总开关:@mpxjs/perf 包内部使用,决定 impl 是否进入 bundle。
179
+ __mpx_perf__: perf.enable
173
180
  })
181
+ // 分组开关:调用方点缀代码使用。开关粒度独立、产物 DCE 独立。
182
+ for (let i = 0; i < PERF_GROUPS.length; i++) {
183
+ const k = PERF_GROUPS[i]
184
+ options.defs[`__mpx_perf_${k}__`] = perf[k]
185
+ }
174
186
  // 批量指定源码mode
175
187
  options.modeRules = options.modeRules || {}
176
188
  options.generateBuildMap = options.generateBuildMap || false
package/lib/parser.js CHANGED
@@ -14,7 +14,7 @@ module.exports = (content, { filePath, needMap, mode, env }) => {
14
14
  output = compiler.parseComponent(content, {
15
15
  mode,
16
16
  filePath,
17
- pad: 'line',
17
+ pad: mode !== 'web' && 'line',
18
18
  env
19
19
  })
20
20
  if (needMap) {
@@ -17,6 +17,7 @@ module.exports = function getSpec({ warn, error }) {
17
17
  // calc(xx)
18
18
  const calcExp = /calc\(/
19
19
  const envExp = /env\(/
20
+ const silentVerify = 'silent'
20
21
  // 不支持的属性提示
21
22
  const unsupportedPropError = ({ prop, value, selector }, { mode }, isError = true) => {
22
23
  const tips = isError ? error : warn
@@ -118,7 +119,7 @@ module.exports = function getSpec({ warn, error }) {
118
119
  const verifyValues = ({ prop, value, selector }, isError = true) => {
119
120
  prop = prop.trim()
120
121
  const rawValue = value.trim()
121
- const tips = isError ? error : warn
122
+ const tips = isError === silentVerify ? () => {} : isError ? error : warn
122
123
 
123
124
  // CSS 自定义属性(--xxx)是变量定义,不属于 RN 样式属性:
124
125
  // 不能按 `-height/-color` 等后缀推断类型去校验,否则会把变量定义错误过滤,导致运行时 var() 取值失败
@@ -340,6 +341,36 @@ module.exports = function getSpec({ warn, error }) {
340
341
  }
341
342
  const urlExp = /url\(["']?(.*?)["']?\)/
342
343
  const linearExp = /linear-gradient\(.*\)/
344
+ const formatBackgroundSize = (value) => {
345
+ // 不支持逗号分隔的多个值:设置多重背景!!!
346
+ // 支持一个值:这个值指定图片的宽度,图片的高度隐式的为 auto
347
+ // 支持两个值:第一个值指定图片的宽度,第二个值指定图片的高度
348
+ if (parseValues(value, ',').length > 1) { // commas are not allowed in values
349
+ error(`Value of [${bgPropMap.size}] in ${selector} does not support commas, received [${value}], please check again!`)
350
+ return false
351
+ }
352
+ const values = []
353
+ parseValues(value).forEach(item => {
354
+ if (verifyValues({ prop: bgPropMap.size, value: item, selector })) {
355
+ // 支持 number 值 / container cover auto 枚举
356
+ values.push(item)
357
+ }
358
+ })
359
+ // value 无有效值时返回false
360
+ return values.length === 0 ? false : { prop: bgPropMap.size, value: values }
361
+ }
362
+ const formatBackgroundPosition = (value) => {
363
+ const values = []
364
+ parseValues(value).forEach(item => {
365
+ if (verifyValues({ prop: bgPropMap.position, value: item, selector })) {
366
+ // 支持 number 值 / 枚举, center与50%等价
367
+ values.push(item === 'center' ? '50%' : item)
368
+ } else {
369
+ error(`Value of [${bgPropMap.size}] in ${selector} does not support commas, received [${value}], please check again!`)
370
+ }
371
+ })
372
+ return { prop: bgPropMap.position, value: values }
373
+ }
343
374
  switch (prop) {
344
375
  case bgPropMap.image: {
345
376
  // background-image 支持背景图/渐变/css var
@@ -352,37 +383,13 @@ module.exports = function getSpec({ warn, error }) {
352
383
  }
353
384
  case bgPropMap.size: {
354
385
  // background-size
355
- // 不支持逗号分隔的多个值:设置多重背景!!!
356
- // 支持一个值:这个值指定图片的宽度,图片的高度隐式的为 auto
357
- // 支持两个值:第一个值指定图片的宽度,第二个值指定图片的高度
358
- if (parseValues(value, ',').length > 1) { // commas are not allowed in values
359
- error(`Value of [${bgPropMap.size}] in ${selector} does not support commas, received [${value}], please check again!`)
360
- return false
361
- }
362
- const values = []
363
- parseValues(value).forEach(item => {
364
- if (verifyValues({ prop, value: item, selector })) {
365
- // 支持 number 值 / container cover auto 枚举
366
- values.push(item)
367
- }
368
- })
369
- // value 无有效值时返回false
370
- return values.length === 0 ? false : { prop, value: values }
386
+ return formatBackgroundSize(value)
371
387
  }
372
388
  case bgPropMap.position: {
373
- const values = []
374
- parseValues(value).forEach(item => {
375
- if (verifyValues({ prop, value: item, selector })) {
376
- // 支持 number 值 / 枚举, center与50%等价
377
- values.push(item === 'center' ? '50%' : item)
378
- } else {
379
- error(`Value of [${bgPropMap.size}] in ${selector} does not support commas, received [${value}], please check again!`)
380
- }
381
- })
382
- return { prop, value: values }
389
+ return formatBackgroundPosition(value)
383
390
  }
384
391
  case bgPropMap.all: {
385
- // background: 仅支持 background-image & background-color & background-repeat
392
+ // background: 支持 image/color/repeat position/size
386
393
  if (cssVariableExp.test(value)) {
387
394
  error(`Property [${bgPropMap.all}] in ${selector} is abbreviated property and does not support CSS var`)
388
395
  return false
@@ -395,6 +402,37 @@ module.exports = function getSpec({ warn, error }) {
395
402
  ]
396
403
  }
397
404
  const bgMap = []
405
+ const positionValues = []
406
+ const sizeValues = []
407
+ let isSize = false
408
+ const pushPositionOrSize = (item) => {
409
+ if (isSize) {
410
+ if (verifyValues({ prop: bgPropMap.size, value: item, selector }, silentVerify)) {
411
+ sizeValues.push(item)
412
+ }
413
+ } else if (verifyValues({ prop: bgPropMap.position, value: item, selector }, silentVerify)) {
414
+ positionValues.push(item)
415
+ }
416
+ }
417
+ const handlePositionSize = (item) => {
418
+ if (item === '/') {
419
+ isSize = true
420
+ return true
421
+ }
422
+ const parts = parseValues(item, '/')
423
+ if (parts.length > 1) {
424
+ parts.forEach((part, index) => {
425
+ if (index > 0) isSize = true
426
+ part && pushPositionOrSize(part)
427
+ })
428
+ return true
429
+ }
430
+ if (isSize || verifyValues({ prop: bgPropMap.position, value: item, selector }, silentVerify)) {
431
+ pushPositionOrSize(item)
432
+ return true
433
+ }
434
+ return false
435
+ }
398
436
  const values = parseValues(value)
399
437
  values.forEach(item => {
400
438
  const url = item.match(urlExp)?.[0]
@@ -403,12 +441,22 @@ module.exports = function getSpec({ warn, error }) {
403
441
  bgMap.push({ prop: bgPropMap.image, value: url })
404
442
  } else if (linerVal) {
405
443
  bgMap.push({ prop: bgPropMap.image, value: linerVal })
406
- } else if (verifyValues({ prop: bgPropMap.color, value: item }, false)) {
444
+ } else if (verifyValues({ prop: bgPropMap.color, value: item, selector }, silentVerify)) {
407
445
  bgMap.push({ prop: bgPropMap.color, value: item })
408
- } else if (verifyValues({ prop: bgPropMap.repeat, value: item, selector }, false)) {
446
+ } else if (verifyValues({ prop: bgPropMap.repeat, value: item, selector }, silentVerify)) {
409
447
  bgMap.push({ prop: bgPropMap.repeat, value: item })
448
+ } else {
449
+ handlePositionSize(item)
410
450
  }
411
451
  })
452
+ if (positionValues.length) {
453
+ const position = formatBackgroundPosition(positionValues.join(' '))
454
+ position && bgMap.push(position)
455
+ }
456
+ if (sizeValues.length) {
457
+ const size = formatBackgroundSize(sizeValues.join(' '))
458
+ size && bgMap.push(size)
459
+ }
412
460
  return bgMap.length ? bgMap : false
413
461
  }
414
462
  }
@@ -3,7 +3,8 @@ const TAG_NAME = 'block'
3
3
  module.exports = function () {
4
4
  return {
5
5
  test: TAG_NAME,
6
- web () {
6
+ web (tag, data) {
7
+ data.el.isBlock = true
7
8
  return 'template'
8
9
  }
9
10
  }
@@ -13,7 +13,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
13
13
  // 快应用不支持的标签集合
14
14
  const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
15
15
  // RN不支持的标签集合
16
- const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'audio', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
16
+ const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'audio', 'match-media', 'page-container', 'keyboard-accessory', 'map']
17
17
 
18
18
  /**
19
19
  * @param {function(object): function} print
@@ -8,15 +8,10 @@ const bindThis = require('../template-compiler/bind-this')
8
8
  const isEmptyObject = require('../utils/is-empty-object')
9
9
  const dash2hump = require('../utils/hump-dash').dash2hump
10
10
  const addQuery = require('../utils/add-query')
11
+ const isUrlRequestBase = require('../utils/is-url-request')
11
12
 
12
- function transformCode (code, wxsModuleMap, error) {
13
+ function transformCode (code, ignoreMap, error) {
13
14
  try {
14
- const ignoreMap = Object.assign({
15
- createElement: true,
16
- getComponent: true,
17
- getTemplate: true
18
- }, wxsModuleMap)
19
-
20
15
  const bindResult = bindThis.transform(code, {
21
16
  ignoreMap
22
17
  })
@@ -42,6 +37,7 @@ module.exports = function (template, {
42
37
  const mpx = loaderContext.getMpx()
43
38
  const {
44
39
  projectRoot,
40
+ externals,
45
41
  mode,
46
42
  env,
47
43
  defs,
@@ -113,9 +109,25 @@ module.exports = function (template, {
113
109
  forceProxyEvent: matchCondition(resourcePath, forceProxyEventRules),
114
110
  checkUsingComponents: matchCondition(resourcePath, checkUsingComponentsRules),
115
111
  isCustomText: matchCondition(resourcePath, customTextRules),
116
- customBuiltInComponents: rnConfig && rnConfig.customBuiltInComponents
112
+ customBuiltInComponents: rnConfig && rnConfig.customBuiltInComponents,
113
+ isUrlRequest: (url) => isUrlRequestBase(url, projectRoot, externals)
117
114
  }
118
115
  const { root, meta } = templateCompiler.parse(template.content, parseOptions)
116
+ const templateAssetsIgnoreMap = {}
117
+ let templateAssetsCode = ''
118
+ if (meta.templateAssets) {
119
+ Object.keys(meta.templateAssets).forEach((name) => {
120
+ templateAssetsIgnoreMap[name] = true
121
+ const request = loaderUtils.urlToRequest(meta.templateAssets[name], projectRoot)
122
+ templateAssetsCode += `var ${name} = require(${loaderUtils.stringifyRequest(loaderContext, request)});\n`
123
+ })
124
+ }
125
+
126
+ const ignoreMap = Object.assign({
127
+ createElement: true,
128
+ getComponent: true,
129
+ getTemplate: true
130
+ }, meta.wxsModuleMap, templateAssetsIgnoreMap)
119
131
 
120
132
  if (meta.wxsContentMap) {
121
133
  for (const module in meta.wxsContentMap) {
@@ -142,7 +154,7 @@ module.exports = function (template, {
142
154
  }
143
155
  })
144
156
  localTemplatesCode += '};'
145
- const transformedCode = transformCode(localTemplatesCode, meta.wxsModuleMap, error)
157
+ const transformedCode = transformCode(localTemplatesCode, ignoreMap, error)
146
158
  if (transformedCode) {
147
159
  output += transformedCode + '\n'
148
160
  templates.push('localTemplates')
@@ -163,6 +175,7 @@ module.exports = function (template, {
163
175
  const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
164
176
  output += `var ${module} = require(${loaderUtils.stringifyRequest(loaderContext, src)});\n`
165
177
  }
178
+ output += templateAssetsCode
166
179
 
167
180
  const templateHelpersCode = templates.length
168
181
  ? `var templates = Object.assign({}, ${templates.join(', ')});
@@ -175,7 +188,7 @@ function getTemplate(name) {
175
188
 
176
189
  const rawCode = genNode(root, true)
177
190
  if (rawCode) {
178
- const transformedCode = transformCode(rawCode, meta.wxsModuleMap, error)
191
+ const transformedCode = transformCode(rawCode, ignoreMap, error)
179
192
  if (transformedCode) {
180
193
  output += `global.currentInject.render = function (createElement, getComponent) {
181
194
  return ${transformedCode}
@@ -34,7 +34,7 @@ function getClassMap ({ content, styles, filename, inputFileSystem, mode, srcMod
34
34
  }
35
35
  }
36
36
  if (hairlineRegExp.test(value)) {
37
- value = `${formatValueName}(${JSON.stringify(value)}, 'hairlineWidth')`
37
+ value = `${formatValueName}('hairlineWidth')`
38
38
  needStringify = false
39
39
  }
40
40
  return needStringify ? JSON.stringify(value) : value
@@ -6,6 +6,7 @@ const { matchCondition } = require('../utils/match-condition')
6
6
  const templateCompiler = require('../template-compiler/compiler')
7
7
  const { genTemplate } = require('../template-compiler/gen-node-react')
8
8
  const bindThis = require('../template-compiler/bind-this')
9
+ const isUrlRequestBase = require('../utils/is-url-request')
9
10
 
10
11
  module.exports = function (content) {
11
12
  const loaderContext = this
@@ -13,6 +14,7 @@ module.exports = function (content) {
13
14
 
14
15
  const {
15
16
  projectRoot,
17
+ externals,
16
18
  mode,
17
19
  srcMode,
18
20
  env,
@@ -50,11 +52,21 @@ module.exports = function (content) {
50
52
  moduleId,
51
53
  filePath: rawResourcePath,
52
54
  forceProxyEvent: matchCondition(resourcePath, forceProxyEventRules),
53
- customBuiltInComponents: rnConfig && rnConfig.customBuiltInComponents
55
+ customBuiltInComponents: rnConfig && rnConfig.customBuiltInComponents,
56
+ isUrlRequest: (url) => isUrlRequestBase(url, projectRoot, externals)
54
57
  }
55
58
 
56
59
  // Parse the template
57
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
+ }
58
70
  if (meta.wxsContentMap && wxsContentMap) {
59
71
  for (const module in meta.wxsContentMap) {
60
72
  wxsContentMap[`${rawResourcePath}~${module}`] = meta.wxsContentMap[module]
@@ -96,7 +108,7 @@ module.exports = function (content) {
96
108
  createElement: true,
97
109
  getComponent: true,
98
110
  getTemplate: true
99
- }, meta.wxsModuleMap)
111
+ }, meta.wxsModuleMap, templateAssetsIgnoreMap)
100
112
  const bindResult = bindThis.transform(localTemplatesCode, {
101
113
  ignoreMap
102
114
  })
@@ -123,6 +135,7 @@ module.exports = function (content) {
123
135
 
124
136
  const output = `
125
137
  ${wxsImports}
138
+ ${templateAssetsCode}
126
139
  var getBuiltInBaseComponent = require(${loaderUtils.stringifyRequest(loaderContext, normalize.lib('runtime/optionProcessorReact'))}).getComponent;
127
140
  var builtInComponentsMap = {${builtInComponents.join(',')}};
128
141
  ${localTemplatesCode}
@@ -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
  ];
@@ -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);
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { Image as RNImage, ImageStyle, NativeSyntheticEvent, ImageErrorEventData, ImageLoadEventData } from 'react-native';
2
+ import { Image as RNImage, ImageStyle, NativeSyntheticEvent, ImageErrorEventData, ImageLoadEventData, ImageSourcePropType } from 'react-native';
3
3
  import { HandlerRef } from './useNodesRef';
4
4
  export type Mode = 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'widthFix' | 'heightFix' | 'top' | 'bottom' | 'center' | 'left' | 'right' | 'top left' | 'top right' | 'bottom left' | 'bottom right';
5
5
  export interface ImageProps {
6
- src?: string;
6
+ src?: string | ImageSourcePropType;
7
7
  mode?: Mode;
8
8
  style?: ImageStyle & Record<string, any>;
9
9
  'enable-offset'?: boolean;
@@ -13,6 +13,7 @@ export interface ImageProps {
13
13
  'parent-width'?: number;
14
14
  'parent-height'?: number;
15
15
  'enable-fast-image'?: boolean;
16
+ 'is-svg'?: boolean;
16
17
  bindload?: (evt: NativeSyntheticEvent<ImageLoadEventData> | unknown) => void;
17
18
  binderror?: (evt: NativeSyntheticEvent<ImageErrorEventData> | unknown) => void;
18
19
  }