@mpxjs/webpack-plugin 2.9.69 → 2.9.70
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/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
|
-
import { isObject, isFunction, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
|
|
4
4
|
import { VarContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
@@ -8,14 +8,17 @@ import FastImage from '@d11/react-native-fast-image';
|
|
|
8
8
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
9
9
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
10
10
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
|
|
11
|
+
export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i;
|
|
11
12
|
export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/;
|
|
12
|
-
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/;
|
|
13
|
+
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/;
|
|
13
14
|
export const DEFAULT_FONT_SIZE = 16;
|
|
14
15
|
export const HIDDEN_STYLE = {
|
|
15
16
|
opacity: 0
|
|
16
17
|
};
|
|
17
|
-
const varDecRegExp =
|
|
18
|
+
const varDecRegExp = /^--/;
|
|
18
19
|
const varUseRegExp = /var\(/;
|
|
20
|
+
const unoVarDecRegExp = /^--un-/;
|
|
21
|
+
const unoVarUseRegExp = /var\(--un-/;
|
|
19
22
|
const calcUseRegExp = /calc\(/;
|
|
20
23
|
const envUseRegExp = /env\(/;
|
|
21
24
|
const safeAreaInsetMap = {
|
|
@@ -26,14 +29,11 @@ const safeAreaInsetMap = {
|
|
|
26
29
|
};
|
|
27
30
|
function getSafeAreaInset(name) {
|
|
28
31
|
const navigation = getFocusedNavigation();
|
|
29
|
-
const insets = {
|
|
30
|
-
...initialWindowMetrics?.insets,
|
|
31
|
-
...navigation?.insets
|
|
32
|
-
};
|
|
32
|
+
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
|
|
33
33
|
return insets[safeAreaInsetMap[name]];
|
|
34
34
|
}
|
|
35
35
|
export function omit(obj, fields) {
|
|
36
|
-
const shallowCopy =
|
|
36
|
+
const shallowCopy = extendObject({}, obj);
|
|
37
37
|
for (let i = 0; i < fields.length; i += 1) {
|
|
38
38
|
const key = fields[i];
|
|
39
39
|
delete shallowCopy[key];
|
|
@@ -71,7 +71,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
|
|
|
71
71
|
if (rest.length || !v || !k)
|
|
72
72
|
return styleObj;
|
|
73
73
|
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
|
|
74
|
-
return
|
|
74
|
+
return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) });
|
|
75
75
|
}, {});
|
|
76
76
|
};
|
|
77
77
|
export const parseUrl = (cssUrl = '') => {
|
|
@@ -81,23 +81,13 @@ export const parseUrl = (cssUrl = '') => {
|
|
|
81
81
|
return match?.[1];
|
|
82
82
|
};
|
|
83
83
|
export const getRestProps = (transferProps = {}, originProps = {}, deletePropsKey = []) => {
|
|
84
|
-
return {
|
|
85
|
-
...transferProps,
|
|
86
|
-
...omit(originProps, deletePropsKey)
|
|
87
|
-
};
|
|
84
|
+
return extendObject({}, transferProps, omit(originProps, deletePropsKey));
|
|
88
85
|
};
|
|
89
86
|
export function isText(ele) {
|
|
90
87
|
if (isValidElement(ele)) {
|
|
91
88
|
const displayName = ele.type?.displayName;
|
|
92
89
|
const isCustomText = ele.type?.isCustomText;
|
|
93
|
-
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
export function isEmbedded(ele) {
|
|
98
|
-
if (isValidElement(ele)) {
|
|
99
|
-
const displayName = ele.type?.displayName || '';
|
|
100
|
-
return ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName);
|
|
90
|
+
return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText;
|
|
101
91
|
}
|
|
102
92
|
return false;
|
|
103
93
|
}
|
|
@@ -240,13 +230,25 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
|
|
|
240
230
|
});
|
|
241
231
|
});
|
|
242
232
|
}
|
|
233
|
+
const stringifyProps = ['fontWeight'];
|
|
234
|
+
function transformStringify(styleObj) {
|
|
235
|
+
stringifyProps.forEach((prop) => {
|
|
236
|
+
if (isNumber(styleObj[prop])) {
|
|
237
|
+
styleObj[prop] = '' + styleObj[prop];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
243
241
|
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
244
242
|
const varStyle = {};
|
|
243
|
+
const unoVarStyle = {};
|
|
245
244
|
const normalStyle = {};
|
|
245
|
+
const normalStyleRef = useRef({});
|
|
246
|
+
const normalStyleChangedRef = useRef(false);
|
|
246
247
|
let hasVarDec = false;
|
|
247
248
|
let hasVarUse = false;
|
|
248
249
|
let hasSelfPercent = false;
|
|
249
250
|
const varKeyPaths = [];
|
|
251
|
+
const unoVarKeyPaths = [];
|
|
250
252
|
const percentKeyPaths = [];
|
|
251
253
|
const calcKeyPaths = [];
|
|
252
254
|
const envKeyPaths = [];
|
|
@@ -254,7 +256,10 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
254
256
|
const [height, setHeight] = useState(0);
|
|
255
257
|
function varVisitor({ key, value, keyPath }) {
|
|
256
258
|
if (keyPath.length === 1) {
|
|
257
|
-
if (
|
|
259
|
+
if (unoVarDecRegExp.test(key)) {
|
|
260
|
+
unoVarStyle[key] = value;
|
|
261
|
+
}
|
|
262
|
+
else if (varDecRegExp.test(key)) {
|
|
258
263
|
hasVarDec = true;
|
|
259
264
|
varStyle[key] = value;
|
|
260
265
|
}
|
|
@@ -264,12 +269,18 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
264
269
|
}
|
|
265
270
|
}
|
|
266
271
|
// 对于var定义中使用的var无需替换值,可以通过resolveVar递归解析出值
|
|
267
|
-
if (!varDecRegExp.test(key)
|
|
268
|
-
|
|
269
|
-
|
|
272
|
+
if (!varDecRegExp.test(key)) {
|
|
273
|
+
// 一般情况下一个样式属性中不会混用unocss var和普通css var,可分开进行互斥处理
|
|
274
|
+
if (unoVarUseRegExp.test(value)) {
|
|
275
|
+
unoVarKeyPaths.push(keyPath.slice());
|
|
276
|
+
}
|
|
277
|
+
else if (varUseRegExp.test(value)) {
|
|
278
|
+
hasVarUse = true;
|
|
279
|
+
varKeyPaths.push(keyPath.slice());
|
|
280
|
+
}
|
|
270
281
|
}
|
|
271
282
|
}
|
|
272
|
-
// traverse var
|
|
283
|
+
// traverse var & generate normalStyle
|
|
273
284
|
traverseStyle(styleObj, [varVisitor]);
|
|
274
285
|
hasVarDec = hasVarDec || !!externalVarContext;
|
|
275
286
|
enableVar = enableVar || hasVarDec || hasVarUse;
|
|
@@ -277,76 +288,92 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
277
288
|
if (enableVarRef.current !== enableVar) {
|
|
278
289
|
error('css variable use/declare should be stable in the component lifecycle, or you can set [enable-var] with true.');
|
|
279
290
|
}
|
|
280
|
-
// apply var
|
|
291
|
+
// apply css var
|
|
281
292
|
const varContextRef = useRef({});
|
|
282
293
|
if (enableVarRef.current) {
|
|
294
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
283
295
|
const varContext = useContext(VarContext);
|
|
284
|
-
const newVarContext =
|
|
296
|
+
const newVarContext = extendObject({}, varContext, externalVarContext, varStyle);
|
|
285
297
|
// 缓存比较newVarContext是否发生变化
|
|
286
298
|
if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
|
|
287
299
|
varContextRef.current = newVarContext;
|
|
288
300
|
}
|
|
289
301
|
transformVar(normalStyle, varKeyPaths, varContextRef.current);
|
|
290
302
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
303
|
+
// apply unocss var
|
|
304
|
+
if (unoVarKeyPaths.length) {
|
|
305
|
+
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
|
|
295
306
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
307
|
+
const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
|
|
308
|
+
if (diff) {
|
|
309
|
+
normalStyleRef.current = clone;
|
|
310
|
+
normalStyleChangedRef.current = !normalStyleChangedRef.current;
|
|
300
311
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
312
|
+
const memoResult = useMemo(() => {
|
|
313
|
+
// transform can be memoized
|
|
314
|
+
function envVisitor({ value, keyPath }) {
|
|
315
|
+
if (envUseRegExp.test(value)) {
|
|
316
|
+
envKeyPaths.push(keyPath.slice());
|
|
317
|
+
}
|
|
305
318
|
}
|
|
306
|
-
|
|
307
|
-
|
|
319
|
+
function calcVisitor({ value, keyPath }) {
|
|
320
|
+
if (calcUseRegExp.test(value)) {
|
|
321
|
+
calcKeyPaths.push(keyPath.slice());
|
|
322
|
+
}
|
|
308
323
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
parentHeight,
|
|
318
|
-
parentFontSize
|
|
319
|
-
};
|
|
320
|
-
// apply env
|
|
321
|
-
transformEnv(normalStyle, envKeyPaths);
|
|
322
|
-
// apply percent
|
|
323
|
-
transformPercent(normalStyle, percentKeyPaths, percentConfig);
|
|
324
|
-
// apply calc
|
|
325
|
-
transformCalc(normalStyle, calcKeyPaths, (value, key) => {
|
|
326
|
-
if (PERCENT_REGEX.test(value)) {
|
|
327
|
-
const resolved = resolvePercent(value, key, percentConfig);
|
|
328
|
-
return typeof resolved === 'number' ? resolved : 0;
|
|
324
|
+
function percentVisitor({ key, value, keyPath }) {
|
|
325
|
+
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
326
|
+
hasSelfPercent = true;
|
|
327
|
+
percentKeyPaths.push(keyPath.slice());
|
|
328
|
+
}
|
|
329
|
+
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
330
|
+
percentKeyPaths.push(keyPath.slice());
|
|
331
|
+
}
|
|
329
332
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
333
|
+
// traverse env & calc & percent
|
|
334
|
+
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
|
|
335
|
+
const percentConfig = {
|
|
336
|
+
width,
|
|
337
|
+
height,
|
|
338
|
+
fontSize: normalStyle.fontSize,
|
|
339
|
+
parentWidth,
|
|
340
|
+
parentHeight,
|
|
341
|
+
parentFontSize
|
|
342
|
+
};
|
|
343
|
+
// apply env
|
|
344
|
+
transformEnv(normalStyle, envKeyPaths);
|
|
345
|
+
// apply percent
|
|
346
|
+
transformPercent(normalStyle, percentKeyPaths, percentConfig);
|
|
347
|
+
// apply calc
|
|
348
|
+
transformCalc(normalStyle, calcKeyPaths, (value, key) => {
|
|
349
|
+
if (PERCENT_REGEX.test(value)) {
|
|
350
|
+
const resolved = resolvePercent(value, key, percentConfig);
|
|
351
|
+
return typeof resolved === 'number' ? resolved : 0;
|
|
334
352
|
}
|
|
335
353
|
else {
|
|
336
|
-
|
|
337
|
-
|
|
354
|
+
const formatted = global.__formatValue(value);
|
|
355
|
+
if (typeof formatted === 'number') {
|
|
356
|
+
return formatted;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
warn('calc() only support number, px, rpx, % temporarily.');
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
338
362
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
363
|
+
});
|
|
364
|
+
// transform number enum stringify
|
|
365
|
+
transformStringify(normalStyle);
|
|
366
|
+
return {
|
|
367
|
+
normalStyle,
|
|
368
|
+
hasSelfPercent
|
|
369
|
+
};
|
|
370
|
+
}, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize]);
|
|
371
|
+
return extendObject({
|
|
344
372
|
hasVarDec,
|
|
345
|
-
enableVarRef,
|
|
346
373
|
varContextRef,
|
|
347
374
|
setWidth,
|
|
348
375
|
setHeight
|
|
349
|
-
};
|
|
376
|
+
}, memoResult);
|
|
350
377
|
}
|
|
351
378
|
export function traverseStyle(styleObj, visitors) {
|
|
352
379
|
const keyPath = [];
|
|
@@ -404,7 +431,7 @@ export function splitProps(props) {
|
|
|
404
431
|
export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }) => {
|
|
405
432
|
const layoutRef = useRef({});
|
|
406
433
|
const hasLayoutRef = useRef(false);
|
|
407
|
-
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {};
|
|
434
|
+
const layoutStyle = useMemo(() => { return !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}; }, [hasLayoutRef.current]);
|
|
408
435
|
const layoutProps = {};
|
|
409
436
|
const enableOffset = props['enable-offset'];
|
|
410
437
|
if (hasSelfPercent || onLayout || enableOffset) {
|
|
@@ -435,8 +462,8 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
|
|
|
435
462
|
if (textStyle || textProps) {
|
|
436
463
|
children = Children.map(children, (child) => {
|
|
437
464
|
if (isText(child)) {
|
|
438
|
-
const style = {
|
|
439
|
-
return cloneElement(child, {
|
|
465
|
+
const style = extendObject({}, textStyle, child.props.style);
|
|
466
|
+
return cloneElement(child, extendObject({}, textProps, { style }));
|
|
440
467
|
}
|
|
441
468
|
return child;
|
|
442
469
|
});
|
|
@@ -469,7 +496,7 @@ export const useStableCallback = (callback) => {
|
|
|
469
496
|
return useCallback((...args) => ref.current?.(...args), []);
|
|
470
497
|
};
|
|
471
498
|
export const usePrevious = (value) => {
|
|
472
|
-
const ref = useRef(
|
|
499
|
+
const ref = useRef();
|
|
473
500
|
const prev = ref.current;
|
|
474
501
|
ref.current = value;
|
|
475
502
|
return prev;
|
|
@@ -483,9 +510,7 @@ export function flatGesture(gestures = []) {
|
|
|
483
510
|
return gesture?.current ? [gesture] : [];
|
|
484
511
|
})) || [];
|
|
485
512
|
}
|
|
486
|
-
export
|
|
487
|
-
return Object.assign({}, ...args);
|
|
488
|
-
}
|
|
513
|
+
export const extendObject = Object.assign;
|
|
489
514
|
export function getCurrentPage(pageId) {
|
|
490
515
|
if (!global.getCurrentPages)
|
|
491
516
|
return;
|
|
@@ -2,31 +2,30 @@ interface EventConfig {
|
|
|
2
2
|
[key: string]: string[];
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
const eventConfigMap:
|
|
6
|
-
bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
7
|
-
bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
8
|
-
bindtouchstart: ['onTouchStart'],
|
|
9
|
-
bindtouchmove: ['onTouchMove'],
|
|
10
|
-
bindtouchend: ['onTouchEnd'],
|
|
11
|
-
bindtouchcancel: ['onTouchCancel'],
|
|
12
|
-
catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
13
|
-
catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
14
|
-
catchtouchstart: ['onTouchStart'],
|
|
15
|
-
catchtouchmove: ['onTouchMove'],
|
|
16
|
-
catchtouchend: ['onTouchEnd'],
|
|
17
|
-
catchtouchcancel: ['onTouchCancel'],
|
|
18
|
-
'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
19
|
-
'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
20
|
-
'capture-bindtouchstart': ['onTouchStartCapture'],
|
|
21
|
-
'capture-bindtouchmove': ['onTouchMoveCapture'],
|
|
22
|
-
'capture-bindtouchend': ['onTouchEndCapture'],
|
|
23
|
-
'capture-bindtouchcancel': ['onTouchCancelCapture'],
|
|
24
|
-
'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
25
|
-
'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
26
|
-
'capture-catchtouchstart': ['onTouchStartCapture'],
|
|
27
|
-
'capture-catchtouchmove': ['onTouchMoveCapture'],
|
|
28
|
-
'capture-catchtouchend': ['onTouchEndCapture'],
|
|
29
|
-
'capture-catchtouchcancel': ['onTouchCancelCapture']
|
|
5
|
+
const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = {
|
|
6
|
+
bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
|
|
7
|
+
bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
|
|
8
|
+
bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
|
|
9
|
+
bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
|
|
10
|
+
bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
|
|
11
|
+
bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
|
|
12
|
+
catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
|
|
13
|
+
catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
|
|
14
|
+
catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
|
|
15
|
+
catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
|
|
16
|
+
catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
|
|
17
|
+
catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
|
|
18
|
+
'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
|
|
19
|
+
'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
|
|
20
|
+
'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
|
|
21
|
+
'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
|
|
22
|
+
'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
|
|
23
|
+
'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
|
|
24
|
+
'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
|
|
25
|
+
'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
|
|
26
|
+
'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
|
|
27
|
+
'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
|
|
28
|
+
'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
|
|
29
|
+
'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
export default eventConfigMap
|