@mpxjs/webpack-plugin 2.10.7 → 2.10.8-beta.3
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.
- package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
- package/lib/dependencies/RequireExternalDependency.js +61 -0
- package/lib/file-loader.js +3 -2
- package/lib/index.js +55 -9
- package/lib/json-compiler/index.js +1 -0
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +43 -25
- package/lib/platform/style/wx/index.js +7 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/index.js +9 -1
- package/lib/platform/template/wx/component-config/nav-container.js +27 -0
- package/lib/platform/template/wx/component-config/page-container.js +19 -0
- package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
- package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/LoadAsyncChunkModule.js +74 -0
- package/lib/react/index.js +3 -1
- package/lib/react/processJSON.js +74 -13
- package/lib/react/processScript.js +6 -6
- package/lib/react/script-helper.js +100 -41
- package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
- package/lib/runtime/components/react/context.ts +27 -7
- package/lib/runtime/components/react/dist/context.d.ts +78 -0
- package/lib/runtime/components/react/dist/context.js +5 -1
- package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +49 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +28 -9
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +42 -46
- package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -6
- package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-page-container.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-page-container.jsx +255 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -15
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +117 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
- package/lib/runtime/components/react/dist/nav.d.ts +11 -0
- package/lib/runtime/components/react/dist/nav.jsx +141 -0
- package/lib/runtime/components/react/dist/parser.d.ts +39 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
- package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
- package/lib/runtime/components/react/dist/useNavShared.js +6 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
- package/lib/runtime/components/react/dist/utils.d.ts +121 -0
- package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
- package/lib/runtime/components/react/mpx-button.tsx +3 -2
- package/lib/runtime/components/react/mpx-input.tsx +35 -16
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +46 -45
- package/lib/runtime/components/react/mpx-movable-view.tsx +8 -4
- package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
- package/lib/runtime/components/react/mpx-page-container.tsx +394 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +84 -59
- package/lib/runtime/components/react/mpx-sticky-header.tsx +181 -0
- package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
- package/lib/runtime/components/react/mpx-swiper.tsx +4 -2
- package/lib/runtime/components/react/nav.tsx +172 -0
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/useNavShared.ts +8 -0
- package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
- package/lib/runtime/components/web/mpx-scroll-view.vue +18 -4
- package/lib/runtime/components/web/mpx-sticky-header.vue +99 -0
- package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
- package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
- package/lib/runtime/optionProcessorReact.d.ts +18 -0
- package/lib/runtime/optionProcessorReact.js +30 -0
- package/lib/script-setup-compiler/index.js +27 -5
- package/lib/template-compiler/bind-this.js +2 -1
- package/lib/template-compiler/compiler.js +27 -6
- package/lib/utils/dom-tag-config.js +18 -4
- package/lib/utils/trans-async-sub-rules.js +19 -0
- package/lib/web/script-helper.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -433
package/lib/react/processJSON.js
CHANGED
|
@@ -8,11 +8,15 @@ const addQuery = require('../utils/add-query')
|
|
|
8
8
|
const parseComponent = require('../parser')
|
|
9
9
|
const getJSONContent = require('../utils/get-json-content')
|
|
10
10
|
const resolve = require('../utils/resolve')
|
|
11
|
+
const { transSubpackage } = require('../utils/trans-async-sub-rules')
|
|
11
12
|
const createJSONHelper = require('../json-compiler/helper')
|
|
12
13
|
const getRulesRunner = require('../platform/index')
|
|
13
14
|
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
15
|
+
const normalize = require('../utils/normalize')
|
|
14
16
|
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
15
17
|
const RecordPageConfigsMapDependency = require('../dependencies/RecordPageConfigsMapDependency')
|
|
18
|
+
const mpxViewPath = normalize.lib('runtime/components/react/dist/mpx-view.jsx')
|
|
19
|
+
const mpxTextPath = normalize.lib('runtime/components/react/dist/mpx-text.jsx')
|
|
16
20
|
|
|
17
21
|
module.exports = function (jsonContent, {
|
|
18
22
|
loaderContext,
|
|
@@ -133,6 +137,45 @@ module.exports = function (jsonContent, {
|
|
|
133
137
|
isShow: true
|
|
134
138
|
}
|
|
135
139
|
|
|
140
|
+
const fillInComponentPlaceholder = (name, placeholder, placeholderEntry) => {
|
|
141
|
+
const componentPlaceholder = jsonObj.componentPlaceholder || {}
|
|
142
|
+
if (componentPlaceholder[name]) return
|
|
143
|
+
componentPlaceholder[name] = placeholder
|
|
144
|
+
jsonObj.componentPlaceholder = componentPlaceholder
|
|
145
|
+
if (placeholderEntry && !jsonObj.usingComponents[placeholder]) jsonObj.usingComponents[placeholder] = placeholderEntry
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const fillInComponentsMap = (name, entry, tarRoot) => {
|
|
149
|
+
const { resource, outputPath } = entry
|
|
150
|
+
const { resourcePath } = parseRequest(resource)
|
|
151
|
+
tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
|
|
152
|
+
componentsMap[resourcePath] = outputPath
|
|
153
|
+
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
154
|
+
localComponentsMap[name] = {
|
|
155
|
+
resource: addQuery(resource, {
|
|
156
|
+
isComponent: true,
|
|
157
|
+
outputPath
|
|
158
|
+
}),
|
|
159
|
+
async: tarRoot
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const normalizePlaceholder = (placeholder) => {
|
|
164
|
+
if (typeof placeholder === 'string') {
|
|
165
|
+
const placeholderMap = mode === 'ali'
|
|
166
|
+
? {
|
|
167
|
+
view: { name: 'mpx-view', resource: mpxViewPath },
|
|
168
|
+
text: { name: 'mpx-text', resource: mpxTextPath }
|
|
169
|
+
}
|
|
170
|
+
: {}
|
|
171
|
+
placeholder = placeholderMap[placeholder] || { name: placeholder }
|
|
172
|
+
}
|
|
173
|
+
if (!placeholder.name) {
|
|
174
|
+
emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
|
|
175
|
+
}
|
|
176
|
+
return placeholder
|
|
177
|
+
}
|
|
178
|
+
|
|
136
179
|
const processTabBar = (tabBar, callback) => {
|
|
137
180
|
if (tabBar) {
|
|
138
181
|
tabBar = Object.assign({}, defaultTabbar, tabBar)
|
|
@@ -247,7 +290,7 @@ module.exports = function (jsonContent, {
|
|
|
247
290
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
248
291
|
if (pageKeySet.has(key)) return callback()
|
|
249
292
|
pageKeySet.add(key)
|
|
250
|
-
const { resourcePath
|
|
293
|
+
const { resourcePath } = parseRequest(resource)
|
|
251
294
|
if (localPagesMap[outputPath]) {
|
|
252
295
|
const { resourcePath: oldResourcePath } = parseRequest(localPagesMap[outputPath].resource)
|
|
253
296
|
if (oldResourcePath !== resourcePath) {
|
|
@@ -259,9 +302,11 @@ module.exports = function (jsonContent, {
|
|
|
259
302
|
|
|
260
303
|
pagesMap[resourcePath] = outputPath
|
|
261
304
|
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
|
|
305
|
+
// 通过asyncSubPackagesNameRules对tarRoot进行修改,仅修改tarRoot,不修改outputPath页面路径
|
|
306
|
+
tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
|
|
262
307
|
localPagesMap[outputPath] = {
|
|
263
308
|
resource: addQuery(resource, { isPage: true }),
|
|
264
|
-
async:
|
|
309
|
+
async: tarRoot,
|
|
265
310
|
isFirst
|
|
266
311
|
}
|
|
267
312
|
callback()
|
|
@@ -301,19 +346,35 @@ module.exports = function (jsonContent, {
|
|
|
301
346
|
const processComponents = (components, context, callback) => {
|
|
302
347
|
if (components) {
|
|
303
348
|
async.eachOf(components, (component, name, callback) => {
|
|
304
|
-
processComponent(component, context, {}, (err,
|
|
349
|
+
processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder } = {}) => {
|
|
305
350
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
351
|
+
fillInComponentsMap(name, entry, tarRoot)
|
|
352
|
+
const { relativePath } = entry
|
|
353
|
+
|
|
354
|
+
if (tarRoot) {
|
|
355
|
+
if (placeholder) {
|
|
356
|
+
placeholder = normalizePlaceholder(placeholder)
|
|
357
|
+
if (placeholder.resource) {
|
|
358
|
+
processComponent(placeholder.resource, projectRoot, { relativePath }, (err, entry) => {
|
|
359
|
+
if (err) return callback(err)
|
|
360
|
+
fillInComponentPlaceholder(name, placeholder.name, entry)
|
|
361
|
+
fillInComponentsMap(placeholder.name, entry, '')
|
|
362
|
+
callback()
|
|
363
|
+
})
|
|
364
|
+
} else {
|
|
365
|
+
fillInComponentPlaceholder(name, placeholder.name)
|
|
366
|
+
callback()
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
if (!jsonObj.componentPlaceholder || !jsonObj.componentPlaceholder[name]) {
|
|
370
|
+
const errMsg = `componentPlaceholder of "${name}" doesn't exist! \n\r`
|
|
371
|
+
emitError(errMsg)
|
|
372
|
+
}
|
|
373
|
+
callback()
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
callback()
|
|
315
377
|
}
|
|
316
|
-
callback()
|
|
317
378
|
})
|
|
318
379
|
}, callback)
|
|
319
380
|
} else {
|
|
@@ -13,6 +13,7 @@ module.exports = function (script, {
|
|
|
13
13
|
builtInComponentsMap,
|
|
14
14
|
localComponentsMap,
|
|
15
15
|
localPagesMap,
|
|
16
|
+
rnConfig,
|
|
16
17
|
componentGenerics,
|
|
17
18
|
genericsInfo
|
|
18
19
|
}, callback) {
|
|
@@ -34,12 +35,13 @@ module.exports = function (script, {
|
|
|
34
35
|
let output = '/* script */\n'
|
|
35
36
|
if (ctorType === 'app') {
|
|
36
37
|
output += `
|
|
37
|
-
import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
38
|
+
import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
38
39
|
\n`
|
|
39
40
|
const { pagesMap, firstPage } = buildPagesMap({
|
|
40
41
|
localPagesMap,
|
|
41
42
|
loaderContext,
|
|
42
|
-
jsonConfig
|
|
43
|
+
jsonConfig,
|
|
44
|
+
rnConfig
|
|
43
45
|
})
|
|
44
46
|
const componentsMap = buildComponentsMap({
|
|
45
47
|
localComponentsMap,
|
|
@@ -50,9 +52,7 @@ import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPa
|
|
|
50
52
|
output += getRequireScript({ ctorType, script, loaderContext })
|
|
51
53
|
output += `export default global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
|
|
52
54
|
} else {
|
|
53
|
-
|
|
54
|
-
// output += 'import { lazy } from \'react\'\n'
|
|
55
|
-
output += `import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
|
|
55
|
+
output += `import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
|
|
56
56
|
// 获取组件集合
|
|
57
57
|
const componentsMap = buildComponentsMap({
|
|
58
58
|
localComponentsMap,
|
|
@@ -61,7 +61,7 @@ import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPa
|
|
|
61
61
|
jsonConfig
|
|
62
62
|
})
|
|
63
63
|
|
|
64
|
-
output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, outputPath, genericsInfo, componentGenerics })
|
|
64
|
+
output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, outputPath, genericsInfo, componentGenerics, hasApp })
|
|
65
65
|
output += getRequireScript({ ctorType, script, loaderContext })
|
|
66
66
|
output += `export default global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
|
|
67
67
|
}
|
|
@@ -3,30 +3,71 @@ const createHelpers = require('../helpers')
|
|
|
3
3
|
const parseRequest = require('../utils/parse-request')
|
|
4
4
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
|
+
const addQuery = require('../utils/add-query')
|
|
7
|
+
const { isBuildInReactTag } = require('../utils/dom-tag-config')
|
|
6
8
|
|
|
7
9
|
function stringifyRequest (loaderContext, request) {
|
|
8
10
|
return loaderUtils.stringifyRequest(loaderContext, request)
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function getBuiltInComponentRequest (component) {
|
|
14
|
+
return JSON.stringify(addQuery(`@mpxjs/webpack-plugin/lib/runtime/components/react/dist/${component}`, { isComponent: true }))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getAsyncChunkName (chunkName) {
|
|
18
|
+
if (chunkName && typeof chunkName !== 'boolean') {
|
|
19
|
+
return `/* webpackChunkName: "${chunkName}/index" */`
|
|
20
|
+
}
|
|
21
|
+
return ''
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getAsyncSuspense (type, moduleId, componentRequest, componentName, chunkName, fallback, loading) {
|
|
25
|
+
return `getAsyncSuspense({
|
|
26
|
+
type: ${JSON.stringify(type)},
|
|
27
|
+
moduleId: ${JSON.stringify(moduleId)},
|
|
28
|
+
chunkName: ${JSON.stringify(chunkName)},
|
|
29
|
+
loading: ${loading},
|
|
30
|
+
fallback: ${fallback},
|
|
31
|
+
getChildren () {
|
|
32
|
+
return import(${getAsyncChunkName(chunkName)}${componentRequest}).then(function (res) {
|
|
33
|
+
return getComponent(res, {displayName: ${JSON.stringify(componentName)}})
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
})`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getComponent (componentRequest, componentName) {
|
|
40
|
+
return `getComponent(require(${componentRequest}), {displayName: ${JSON.stringify(componentName)}})`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getBuiltInComponent (componentRequest) {
|
|
44
|
+
return `getComponent(require(${componentRequest}), {__mpxBuiltIn: true})`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// function getLazyPage (componentRequest) {
|
|
48
|
+
// return `getLazyPage(${getComponentGetter(getComponent(componentRequest, 'Page'))})`
|
|
16
49
|
// }
|
|
17
50
|
|
|
18
|
-
function
|
|
51
|
+
function getComponentGetter (component) {
|
|
52
|
+
return `function(){ return ${component} }`
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig }) {
|
|
19
56
|
let firstPage = ''
|
|
20
57
|
const pagesMap = {}
|
|
58
|
+
const mpx = loaderContext.getMpx()
|
|
21
59
|
Object.keys(localPagesMap).forEach((pagePath) => {
|
|
22
60
|
const pageCfg = localPagesMap[pagePath]
|
|
23
61
|
const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
62
|
+
if (pageCfg.async) {
|
|
63
|
+
const moduleId = mpx.getModuleId(pageCfg.resource)
|
|
64
|
+
const fallback = rnConfig.asyncChunk && rnConfig.asyncChunk.fallback && getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.fallback, { isComponent: true })), 'PageFallback')
|
|
65
|
+
const loading = rnConfig.asyncChunk && rnConfig.asyncChunk.loading && getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.loading, { isComponent: true })), 'PageLoading')
|
|
66
|
+
pagesMap[pagePath] = getComponentGetter(getAsyncSuspense('page', moduleId, pageRequest, 'Page', pageCfg.async, fallback, loading))
|
|
67
|
+
} else {
|
|
68
|
+
// 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
|
|
69
|
+
pagesMap[pagePath] = getComponentGetter(getComponent(pageRequest, 'Page'))
|
|
70
|
+
}
|
|
30
71
|
if (pagePath === jsonConfig.entryPagePath) {
|
|
31
72
|
firstPage = pagePath
|
|
32
73
|
}
|
|
@@ -42,30 +83,58 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig }) {
|
|
|
42
83
|
|
|
43
84
|
function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) {
|
|
44
85
|
const componentsMap = {}
|
|
86
|
+
const mpx = loaderContext.getMpx()
|
|
45
87
|
if (localComponentsMap) {
|
|
46
88
|
Object.keys(localComponentsMap).forEach((componentName) => {
|
|
47
89
|
const componentCfg = localComponentsMap[componentName]
|
|
48
90
|
const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
91
|
+
if (componentCfg.async) {
|
|
92
|
+
const moduleId = mpx.getModuleId(componentCfg.resource)
|
|
93
|
+
const placeholder = jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName]
|
|
94
|
+
let fallback
|
|
95
|
+
if (placeholder) {
|
|
96
|
+
if (localComponentsMap[placeholder]) {
|
|
97
|
+
const placeholderCfg = localComponentsMap[placeholder]
|
|
98
|
+
const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
|
|
99
|
+
if (placeholderCfg.async) {
|
|
100
|
+
loaderContext.emitWarning(
|
|
101
|
+
new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
fallback = getComponent(placeholderRequest, placeholder)
|
|
105
|
+
} else {
|
|
106
|
+
const tag = `mpx-${placeholder}`
|
|
107
|
+
if (isBuildInReactTag(tag)) {
|
|
108
|
+
fallback = getBuiltInComponent(getBuiltInComponentRequest(tag))
|
|
109
|
+
} else {
|
|
110
|
+
loaderContext.emitError(
|
|
111
|
+
new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component, please check!`)
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
loaderContext.emitError(
|
|
117
|
+
new Error(`[json processor][${loaderContext.resource}]: ${componentName} has no componentPlaceholder, please check!`)
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
componentsMap[componentName] = getComponentGetter(getAsyncSuspense('component', moduleId, componentRequest, componentName, componentCfg.async, fallback))
|
|
121
|
+
} else {
|
|
122
|
+
componentsMap[componentName] = getComponentGetter(getComponent(componentRequest, componentName))
|
|
123
|
+
}
|
|
55
124
|
})
|
|
56
125
|
}
|
|
57
126
|
if (builtInComponentsMap) {
|
|
58
127
|
Object.keys(builtInComponentsMap).forEach((componentName) => {
|
|
59
128
|
const componentCfg = builtInComponentsMap[componentName]
|
|
60
129
|
const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
|
|
61
|
-
componentsMap[componentName] =
|
|
130
|
+
componentsMap[componentName] = getComponentGetter(getBuiltInComponent(componentRequest))
|
|
62
131
|
})
|
|
63
132
|
}
|
|
64
133
|
return componentsMap
|
|
65
134
|
}
|
|
66
135
|
|
|
67
136
|
function getRequireScript ({ script, ctorType, loaderContext }) {
|
|
68
|
-
let content = '
|
|
137
|
+
let content = '/** script content **/\n'
|
|
69
138
|
const { getRequire } = createHelpers(loaderContext)
|
|
70
139
|
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
71
140
|
const extraOptions = {
|
|
@@ -75,7 +144,7 @@ function getRequireScript ({ script, ctorType, loaderContext }) {
|
|
|
75
144
|
ctorType,
|
|
76
145
|
lang: script.lang || 'js'
|
|
77
146
|
}
|
|
78
|
-
content +=
|
|
147
|
+
content += `${getRequire('script', script, extraOptions)}\n`
|
|
79
148
|
return content
|
|
80
149
|
}
|
|
81
150
|
|
|
@@ -104,17 +173,11 @@ global.__mpxOptionsMap = {}
|
|
|
104
173
|
global.__mpxPagesMap = {}
|
|
105
174
|
global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
|
|
106
175
|
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
107
|
-
global.
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
global.currentInject.getPages = function () {
|
|
111
|
-
return ${shallowStringify(pagesMap)}
|
|
112
|
-
}
|
|
176
|
+
global.__appComponentsMap = ${shallowStringify(componentsMap)}
|
|
177
|
+
global.__preloadRule = ${JSON.stringify(jsonConfig.preloadRule)}
|
|
178
|
+
global.currentInject.pagesMap = ${shallowStringify(pagesMap)}
|
|
113
179
|
global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n`
|
|
114
180
|
} else {
|
|
115
|
-
if (!hasApp) {
|
|
116
|
-
content += ' global.__mpxGenericsMap = global.__mpxGenericsMap || {}\n'
|
|
117
|
-
}
|
|
118
181
|
if (ctorType === 'page') {
|
|
119
182
|
const pageConfig = Object.assign({}, jsonConfig)
|
|
120
183
|
delete pageConfig.usingComponents
|
|
@@ -122,19 +185,15 @@ global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n`
|
|
|
122
185
|
}
|
|
123
186
|
|
|
124
187
|
content += `
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return ${shallowStringify(componentsMap)}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
global.currentInject.getComponents = getComponents\n`
|
|
188
|
+
var componentsMap = ${shallowStringify(componentsMap)}
|
|
189
|
+
global.currentInject.componentsMap = componentsMap\n`
|
|
131
190
|
if (genericsInfo) {
|
|
191
|
+
if (!hasApp) {
|
|
192
|
+
content += 'global.__mpxGenericsMap = global.__mpxGenericsMap || {}\n'
|
|
193
|
+
}
|
|
132
194
|
content += `
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return getComponents()[name]
|
|
136
|
-
}
|
|
137
|
-
\n`
|
|
195
|
+
const genericHash = ${JSON.stringify(genericsInfo.hash)}\n
|
|
196
|
+
global.__mpxGenericsMap[genericHash] = componentsMap\n`
|
|
138
197
|
}
|
|
139
198
|
if (ctorType === 'component') {
|
|
140
199
|
content += `global.currentInject.componentPath = '/' + ${JSON.stringify(outputPath)}\n`
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
2
|
-
import { NativeSyntheticEvent } from 'react-native'
|
|
2
|
+
import { NativeSyntheticEvent, Animated } from 'react-native'
|
|
3
|
+
import { noop } from '@mpxjs/utils'
|
|
3
4
|
|
|
4
5
|
export type LabelContextValue = MutableRefObject<{
|
|
5
6
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
|
|
6
7
|
}>
|
|
7
8
|
|
|
8
|
-
export type KeyboardAvoidContextValue = MutableRefObject<
|
|
9
|
-
|
|
10
|
-
>
|
|
9
|
+
export type KeyboardAvoidContextValue = MutableRefObject<{
|
|
10
|
+
cursorSpacing: number
|
|
11
|
+
ref: MutableRefObject<any>
|
|
12
|
+
adjustPosition: boolean
|
|
13
|
+
keyboardHeight?: number
|
|
14
|
+
onKeyboardShow?: () => void
|
|
15
|
+
} | null>
|
|
11
16
|
|
|
12
17
|
export interface GroupValue {
|
|
13
18
|
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
|
|
@@ -36,13 +41,14 @@ export interface IntersectionObserver {
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
export interface PortalContextValue {
|
|
39
|
-
mount: (children: React.ReactNode, key?: number | null, id?: number| null) => number| undefined
|
|
44
|
+
mount: (children: React.ReactNode, key?: number | null, id?: number | null) => number | undefined
|
|
40
45
|
update: (key: number, children: React.ReactNode) => void
|
|
41
46
|
unmount: (key: number) => void
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
export interface ScrollViewContextValue {
|
|
45
|
-
|
|
50
|
+
gestureRef: React.RefObject<any> | null
|
|
51
|
+
scrollOffset: Animated.Value
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export interface RouteContextValue {
|
|
@@ -50,6 +56,16 @@ export interface RouteContextValue {
|
|
|
50
56
|
navigation: Record<string, any>
|
|
51
57
|
}
|
|
52
58
|
|
|
59
|
+
export interface StickyContextValue {
|
|
60
|
+
registerStickyHeader: Function
|
|
61
|
+
unregisterStickyHeader: Function
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface NavSharedValue {
|
|
65
|
+
customNav?: React.ReactNode
|
|
66
|
+
setCustomNav: (value: React.ReactNode) => void
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
export const MovableAreaContext = createContext({ width: 0, height: 0 })
|
|
54
70
|
|
|
55
71
|
export const FormContext = createContext<FormContextValue | null>(null)
|
|
@@ -72,6 +88,10 @@ export const SwiperContext = createContext({})
|
|
|
72
88
|
|
|
73
89
|
export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
|
|
74
90
|
|
|
75
|
-
export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null })
|
|
91
|
+
export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null, scrollOffset: new Animated.Value(0) })
|
|
76
92
|
|
|
77
93
|
export const PortalContext = createContext<PortalContextValue>(null as any)
|
|
94
|
+
|
|
95
|
+
export const StickyContext = createContext<StickyContextValue>({ registerStickyHeader: noop, unregisterStickyHeader: noop })
|
|
96
|
+
|
|
97
|
+
export const NavSharedContext = createContext<NavSharedValue>(null as any)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|
2
|
+
import { NativeSyntheticEvent, Animated } from 'react-native';
|
|
3
|
+
export type LabelContextValue = MutableRefObject<{
|
|
4
|
+
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void;
|
|
5
|
+
}>;
|
|
6
|
+
export type KeyboardAvoidContextValue = MutableRefObject<{
|
|
7
|
+
cursorSpacing: number;
|
|
8
|
+
ref: MutableRefObject<any>;
|
|
9
|
+
adjustPosition: boolean;
|
|
10
|
+
keyboardHeight?: number;
|
|
11
|
+
onKeyboardShow?: () => void;
|
|
12
|
+
} | null>;
|
|
13
|
+
export interface GroupValue {
|
|
14
|
+
[key: string]: {
|
|
15
|
+
checked: boolean;
|
|
16
|
+
setValue: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface GroupContextValue {
|
|
20
|
+
groupValue: GroupValue;
|
|
21
|
+
notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface FormFieldValue {
|
|
24
|
+
getValue: () => any;
|
|
25
|
+
resetValue: ({ newVal, type }: {
|
|
26
|
+
newVal?: any;
|
|
27
|
+
type?: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface FormContextValue {
|
|
31
|
+
formValuesMap: Map<string, FormFieldValue>;
|
|
32
|
+
submit: () => void;
|
|
33
|
+
reset: () => void;
|
|
34
|
+
}
|
|
35
|
+
export interface IntersectionObserver {
|
|
36
|
+
[key: number]: {
|
|
37
|
+
throttleMeasure: () => void;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface PortalContextValue {
|
|
41
|
+
mount: (children: React.ReactNode, key?: number | null, id?: number | null) => number | undefined;
|
|
42
|
+
update: (key: number, children: React.ReactNode) => void;
|
|
43
|
+
unmount: (key: number) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface ScrollViewContextValue {
|
|
46
|
+
gestureRef: React.RefObject<any> | null;
|
|
47
|
+
scrollOffset: Animated.Value;
|
|
48
|
+
}
|
|
49
|
+
export interface RouteContextValue {
|
|
50
|
+
pageId: number;
|
|
51
|
+
navigation: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
export interface StickyContextValue {
|
|
54
|
+
registerStickyHeader: Function;
|
|
55
|
+
unregisterStickyHeader: Function;
|
|
56
|
+
}
|
|
57
|
+
export interface NavSharedValue {
|
|
58
|
+
customNav?: React.ReactNode;
|
|
59
|
+
setCustomNav: (value: React.ReactNode) => void;
|
|
60
|
+
}
|
|
61
|
+
export declare const MovableAreaContext: import("react").Context<{
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
}>;
|
|
65
|
+
export declare const FormContext: import("react").Context<FormContextValue | null>;
|
|
66
|
+
export declare const CheckboxGroupContext: import("react").Context<GroupContextValue | null>;
|
|
67
|
+
export declare const RadioGroupContext: import("react").Context<GroupContextValue | null>;
|
|
68
|
+
export declare const LabelContext: import("react").Context<LabelContextValue | null>;
|
|
69
|
+
export declare const PickerContext: import("react").Context<null>;
|
|
70
|
+
export declare const VarContext: import("react").Context<{}>;
|
|
71
|
+
export declare const IntersectionObserverContext: import("react").Context<IntersectionObserver | null>;
|
|
72
|
+
export declare const RouteContext: import("react").Context<RouteContextValue | null>;
|
|
73
|
+
export declare const SwiperContext: import("react").Context<{}>;
|
|
74
|
+
export declare const KeyboardAvoidContext: import("react").Context<KeyboardAvoidContextValue | null>;
|
|
75
|
+
export declare const ScrollViewContext: import("react").Context<ScrollViewContextValue>;
|
|
76
|
+
export declare const PortalContext: import("react").Context<PortalContextValue>;
|
|
77
|
+
export declare const StickyContext: import("react").Context<StickyContextValue>;
|
|
78
|
+
export declare const NavSharedContext: import("react").Context<NavSharedValue>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import { noop } from '@mpxjs/utils';
|
|
2
4
|
export const MovableAreaContext = createContext({ width: 0, height: 0 });
|
|
3
5
|
export const FormContext = createContext(null);
|
|
4
6
|
export const CheckboxGroupContext = createContext(null);
|
|
@@ -10,5 +12,7 @@ export const IntersectionObserverContext = createContext(null);
|
|
|
10
12
|
export const RouteContext = createContext(null);
|
|
11
13
|
export const SwiperContext = createContext({});
|
|
12
14
|
export const KeyboardAvoidContext = createContext(null);
|
|
13
|
-
export const ScrollViewContext = createContext({ gestureRef: null });
|
|
15
|
+
export const ScrollViewContext = createContext({ gestureRef: null, scrollOffset: new Animated.Value(0) });
|
|
14
16
|
export const PortalContext = createContext(null);
|
|
17
|
+
export const StickyContext = createContext({ registerStickyHeader: noop, unregisterStickyHeader: noop });
|
|
18
|
+
export const NavSharedContext = createContext(null);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Props, RawConfig, RemoveProps, LayoutRef, ExtendedNativeTouchEvent } from './types/getInnerListeners';
|
|
2
|
+
export declare const getCustomEvent: (type: string | undefined, oe: any, { detail, layoutRef }: {
|
|
3
|
+
detail?: Record<string, unknown> | undefined;
|
|
4
|
+
layoutRef?: LayoutRef | undefined;
|
|
5
|
+
}, props?: Props) => any;
|
|
6
|
+
declare const useInnerProps: (props?: Props, userRemoveProps?: RemoveProps, rawConfig?: RawConfig) => Record<string, (e: ExtendedNativeTouchEvent) => void> & Omit<Props, string>;
|
|
7
|
+
export default useInnerProps;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
interface AsyncSuspenseProps {
|
|
3
|
+
type: 'component' | 'page';
|
|
4
|
+
chunkName: string;
|
|
5
|
+
moduleId: string;
|
|
6
|
+
innerProps: any;
|
|
7
|
+
loading?: ComponentType<unknown>;
|
|
8
|
+
fallback?: ComponentType<unknown>;
|
|
9
|
+
getChildren: () => Promise<ReactNode>;
|
|
10
|
+
}
|
|
11
|
+
declare const AsyncSuspense: React.FC<AsyncSuspenseProps>;
|
|
12
|
+
export default AsyncSuspense;
|