@dcl/react-ecs 7.0.6-4153633895.commit-4aad233 → 7.0.6-4177592674.commit-39cdc99
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/dist/components/index.d.ts +4 -1
- package/dist/components/index.js +9 -1
- package/dist/components/uiTransform/index.js +13 -6
- package/dist/components/uiTransform/types.d.ts +18 -6
- package/dist/components/uiTransform/utils.d.ts +2 -2
- package/dist/components/uiTransform/utils.js +35 -16
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactEcs } from '../react-ecs';
|
|
2
|
+
import { UiLabelProps } from './Label/types';
|
|
2
3
|
import { EntityPropTypes } from './types';
|
|
3
4
|
export * from './types';
|
|
4
5
|
export * from './uiTransform/types';
|
|
@@ -16,4 +17,6 @@ export { Button } from './Button';
|
|
|
16
17
|
* @public
|
|
17
18
|
* @category Component
|
|
18
19
|
*/
|
|
19
|
-
export declare function UiEntity(props: EntityPropTypes
|
|
20
|
+
export declare function UiEntity(props: EntityPropTypes & {
|
|
21
|
+
uiText?: UiLabelProps;
|
|
22
|
+
}): ReactEcs.JSX.Element;
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactEcs } from '../react-ecs';
|
|
2
|
+
import { getFont, getTextAlign } from './Label/utils';
|
|
2
3
|
import { parseProps } from './utils';
|
|
3
4
|
export * from './types';
|
|
4
5
|
export * from './uiTransform/types';
|
|
@@ -18,5 +19,12 @@ export { Button } from './Button';
|
|
|
18
19
|
*/
|
|
19
20
|
/*#__PURE__*/
|
|
20
21
|
export function UiEntity(props) {
|
|
21
|
-
|
|
22
|
+
const uiText = props.uiText && {
|
|
23
|
+
uiText: {
|
|
24
|
+
...props.uiText,
|
|
25
|
+
...getFont(props.uiText.font),
|
|
26
|
+
...getTextAlign(props.uiText.textAlign)
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return ReactEcs.createElement("entity", { ...parseProps(props), ...uiText });
|
|
22
30
|
}
|
|
@@ -4,6 +4,12 @@ import { getAlign, getFlexDirection, getDisplay, getFlexWrap, getJustify, getOve
|
|
|
4
4
|
*/
|
|
5
5
|
export const CANVAS_ROOT_ENTITY = 0;
|
|
6
6
|
const defaultUiTransform = {
|
|
7
|
+
overflow: 0 /* YGOverflow.YGO_VISIBLE */,
|
|
8
|
+
display: 0 /* YGDisplay.YGD_FLEX */,
|
|
9
|
+
justifyContent: 0 /* YGJustify.YGJ_FLEX_START */,
|
|
10
|
+
alignSelf: 0 /* YGAlign.YGA_AUTO */,
|
|
11
|
+
flexDirection: 0 /* YGFlexDirection.YGFD_ROW */,
|
|
12
|
+
positionType: 0 /* YGPositionType.YGPT_RELATIVE */,
|
|
7
13
|
parent: CANVAS_ROOT_ENTITY,
|
|
8
14
|
rightOf: 0,
|
|
9
15
|
flexBasis: 0,
|
|
@@ -51,7 +57,7 @@ const defaultUiTransform = {
|
|
|
51
57
|
*/
|
|
52
58
|
/*#__PURE__*/
|
|
53
59
|
export function parseUiTransform(props = {}) {
|
|
54
|
-
const { height, minHeight, maxHeight, width, minWidth, maxWidth, ...otherProps } = props;
|
|
60
|
+
const { height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, ...otherProps } = props;
|
|
55
61
|
return {
|
|
56
62
|
...defaultUiTransform,
|
|
57
63
|
...otherProps,
|
|
@@ -65,13 +71,14 @@ export function parseUiTransform(props = {}) {
|
|
|
65
71
|
...parseSize(props.minWidth, 'minWidth'),
|
|
66
72
|
...parseSize(props.maxWidth, 'maxWidth'),
|
|
67
73
|
...getDisplay(props.display),
|
|
68
|
-
...getAlign('
|
|
69
|
-
...getAlign('alignSelf', props.alignSelf, 1 /* YGAlign.YGA_FLEX_START */),
|
|
70
|
-
...getAlign('alignItems', props.alignItems, 1 /* YGAlign.YGA_FLEX_START */),
|
|
74
|
+
...getAlign('alignSelf', props.alignSelf ?? 'auto'),
|
|
71
75
|
...getJustify(props.justifyContent),
|
|
72
76
|
...getFlexDirection(props.flexDirection),
|
|
73
|
-
...getFlexWrap(props.flexWrap),
|
|
74
77
|
...getOverflow(props.overflow),
|
|
75
|
-
...getPoistionType(props.positionType)
|
|
78
|
+
...getPoistionType(props.positionType),
|
|
79
|
+
// Optional values
|
|
80
|
+
...(alignContent && getAlign('alignContent', alignContent)),
|
|
81
|
+
...(alignItems && getAlign('alignItems', alignItems)),
|
|
82
|
+
...(flexWrap && getFlexWrap(flexWrap))
|
|
76
83
|
};
|
|
77
84
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* i.e. width="100", width="100%", width="100px"
|
|
2
|
+
* unit value specified. i.e. 1 || '100%' || '1px'
|
|
4
3
|
* @public
|
|
5
4
|
*/
|
|
6
|
-
export type PositionUnit = `${number}px` | `${number}%` | number
|
|
5
|
+
export type PositionUnit = `${number}px` | `${number}%` | number | `${number}`;
|
|
6
|
+
/**
|
|
7
|
+
* The values are in clockwise order, beginning at the top: top, right, bottom, then left
|
|
8
|
+
|
|
9
|
+
* When one value is specified, it applies the same margin to all four sides.
|
|
10
|
+
*
|
|
11
|
+
* When two values are specified, the first margin applies to the top and bottom, the second to the left and right.
|
|
12
|
+
*
|
|
13
|
+
* When three values are specified, the first margin applies to the top, the second to the left and right, the third to the bottom.
|
|
14
|
+
*
|
|
15
|
+
When four values are specified, the margins apply to the top, right, bottom, and left in that order (clockwise).
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type PositionShorthand = PositionUnit | `${PositionUnit} ${PositionUnit}` | `${PositionUnit} ${PositionUnit} ${PositionUnit}` | `${PositionUnit} ${PositionUnit} ${PositionUnit} ${PositionUnit}`;
|
|
7
19
|
/**
|
|
8
20
|
* Type used for defining the position of the element. i.e. margin, padding
|
|
9
21
|
* @public
|
|
@@ -66,11 +78,11 @@ export interface UiTransformProps {
|
|
|
66
78
|
/** The flex-direction property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed). */
|
|
67
79
|
flexDirection?: FlexDirectionType;
|
|
68
80
|
/** The position property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final location of positioned elements. */
|
|
69
|
-
position?: Partial<Position
|
|
81
|
+
position?: Partial<Position> | PositionShorthand;
|
|
70
82
|
/** The padding shorthand property sets the padding area on all four sides of an element at once. */
|
|
71
|
-
padding?: Partial<Position
|
|
83
|
+
padding?: Partial<Position> | PositionShorthand;
|
|
72
84
|
/** The margin shorthand property sets the margin area on all four sides of an element. */
|
|
73
|
-
margin?: Partial<Position
|
|
85
|
+
margin?: Partial<Position> | PositionShorthand;
|
|
74
86
|
/** The width property specifies the width of an element. */
|
|
75
87
|
width?: PositionUnit;
|
|
76
88
|
/** The height property specifies the height of an element. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { YGUnit } from '@dcl/ecs';
|
|
2
|
-
import { Position, PositionUnit } from './types';
|
|
2
|
+
import { Position, PositionUnit, PositionShorthand } from './types';
|
|
3
3
|
type PropName = 'position' | 'margin' | 'padding';
|
|
4
4
|
type PropKey = `${PropName}${Capitalize<keyof Position>}`;
|
|
5
5
|
type PropKeyUnit = `${PropName}${Capitalize<keyof Position>}Unit`;
|
|
@@ -8,7 +8,7 @@ type PositionParsed = {
|
|
|
8
8
|
} & {
|
|
9
9
|
[key in PropKeyUnit]?: YGUnit;
|
|
10
10
|
};
|
|
11
|
-
export declare function parsePosition<T extends PropName>(position: Partial<Position> | undefined, prop: T): Partial<PositionParsed>;
|
|
11
|
+
export declare function parsePosition<T extends PropName>(position: PositionShorthand | Partial<Position> | undefined, prop: T): Partial<PositionParsed>;
|
|
12
12
|
type HeightWidth = 'height' | 'width';
|
|
13
13
|
type SizePropName = HeightWidth | `max${Capitalize<HeightWidth>}` | `min${Capitalize<HeightWidth>}`;
|
|
14
14
|
type SizePropKeyUnit = `${SizePropName}Unit`;
|
|
@@ -14,7 +14,7 @@ function parsePositionUnit(val) {
|
|
|
14
14
|
if (val === undefined || val === null) {
|
|
15
15
|
return [undefined, 0 /* YGUnit.YGU_UNDEFINED */];
|
|
16
16
|
}
|
|
17
|
-
if (typeof val === 'number') {
|
|
17
|
+
if (typeof val === 'number' || (typeof val === 'string' && !isNaN(Number(val)))) {
|
|
18
18
|
return [Number(val), 1 /* YGUnit.YGU_POINT */];
|
|
19
19
|
}
|
|
20
20
|
if (isPercent(val)) {
|
|
@@ -25,20 +25,39 @@ function parsePositionUnit(val) {
|
|
|
25
25
|
}
|
|
26
26
|
return [undefined, 0 /* YGUnit.YGU_UNDEFINED */];
|
|
27
27
|
}
|
|
28
|
-
// position: { top: '1px' } => { positionTop: 1, positionTopUnit: YGUnit.YGU_Point }
|
|
29
28
|
export function parsePosition(position = {}, prop) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (typeof position === 'object') {
|
|
30
|
+
const obj = {};
|
|
31
|
+
for (const key in position) {
|
|
32
|
+
const typedKey = key;
|
|
33
|
+
const propKey = `${prop}${capitalize(typedKey)}`;
|
|
34
|
+
const propKeyUnit = `${prop}${capitalize(typedKey)}Unit`;
|
|
35
|
+
const [value, unit] = parsePositionUnit(position[typedKey]);
|
|
36
|
+
if (value === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
obj[propKeyUnit] = unit;
|
|
39
|
+
obj[propKey] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
if (typeof position === 'number') {
|
|
44
|
+
return parsePosition({ top: position, left: position, right: position, bottom: position }, prop);
|
|
45
|
+
}
|
|
46
|
+
const values = position.split(' ').filter((a) => a !== '');
|
|
47
|
+
if (values.length === 1) {
|
|
48
|
+
const [value] = values;
|
|
49
|
+
return parsePosition({ top: value, left: value, right: value, bottom: value }, prop);
|
|
50
|
+
}
|
|
51
|
+
if (values.length === 2) {
|
|
52
|
+
const [topBottom, rigthLeft] = values;
|
|
53
|
+
return parsePosition({ top: topBottom, left: rigthLeft, right: rigthLeft, bottom: topBottom }, prop);
|
|
54
|
+
}
|
|
55
|
+
if (values.length === 3) {
|
|
56
|
+
const [top, rigthLeft, bottom] = values;
|
|
57
|
+
return parsePosition({ top, left: rigthLeft, right: rigthLeft, bottom }, prop);
|
|
58
|
+
}
|
|
59
|
+
const [top, right, bottom, left] = values;
|
|
60
|
+
return parsePosition({ top, right, bottom, left }, prop);
|
|
42
61
|
}
|
|
43
62
|
export function parseSize(val, key) {
|
|
44
63
|
const unitKey = `${key}Unit`;
|
|
@@ -79,8 +98,8 @@ const parseJustify = {
|
|
|
79
98
|
/**
|
|
80
99
|
* @internal
|
|
81
100
|
*/
|
|
82
|
-
export function getAlign(prop, align
|
|
83
|
-
const value =
|
|
101
|
+
export function getAlign(prop, align) {
|
|
102
|
+
const value = parseAligns[align];
|
|
84
103
|
return { [prop]: value };
|
|
85
104
|
}
|
|
86
105
|
const parseAligns = {
|
|
@@ -110,7 +129,7 @@ const parseFlexDirection = {
|
|
|
110
129
|
* @internal
|
|
111
130
|
*/
|
|
112
131
|
export function getFlexWrap(flexWrap) {
|
|
113
|
-
const value =
|
|
132
|
+
const value = parseFlexWrap[flexWrap];
|
|
114
133
|
return { flexWrap: value };
|
|
115
134
|
}
|
|
116
135
|
const parseFlexWrap = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/react-ecs",
|
|
3
|
-
"version": "7.0.6-
|
|
3
|
+
"version": "7.0.6-4177592674.commit-39cdc99",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"displayName": "React ECS",
|
|
43
43
|
"tsconfig": "./tsconfig.json"
|
|
44
44
|
},
|
|
45
|
-
"commit": "
|
|
45
|
+
"commit": "39cdc99ea857c63f707ec9188836116d838fa10e"
|
|
46
46
|
}
|