@dcl/react-ecs 7.13.1-19324737285.commit-cb42004 → 7.13.1-19516109426.commit-e1e79aa
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/Button/index.js +2 -2
- package/dist/components/Dropdown/index.js +10 -2
- package/dist/components/Input/index.js +10 -2
- package/dist/components/Label/index.js +13 -3
- package/dist/components/Label/types.d.ts +4 -0
- package/dist/components/listeners/types.d.ts +37 -6
- package/dist/components/listeners/types.js +9 -1
- package/dist/components/uiBackground/types.d.ts +12 -1
- package/dist/components/uiBackground/utils.js +8 -0
- package/dist/components/uiTransform/index.d.ts +1 -1
- package/dist/components/uiTransform/index.js +6 -3
- package/dist/components/uiTransform/types.d.ts +12 -0
- package/dist/components/uiTransform/utils.js +37 -0
- package/dist/react-ecs.d.ts +14 -6
- package/dist/reconciler/index.d.ts +4 -3
- package/dist/reconciler/index.js +59 -44
- package/dist/reconciler/utils.js +8 -0
- package/dist/system.d.ts +2 -1
- package/dist/system.js +16 -1
- package/package.json +3 -3
|
@@ -29,7 +29,7 @@ function getButtonProps(props) {
|
|
|
29
29
|
*/
|
|
30
30
|
/* @__PURE__ */
|
|
31
31
|
export function Button(props) {
|
|
32
|
-
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
32
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseDrag, onMouseDragLocked, onMouseDragEnd, onInputDown, onInputUp, onInputDrag, onInputDragLocked, onInputDragEnd, ...otherProps } = props;
|
|
33
33
|
const buttonProps = getButtonProps(props);
|
|
34
34
|
const uiBackgroundProps = parseUiBackground({
|
|
35
35
|
...buttonProps.uiBackground,
|
|
@@ -54,5 +54,5 @@ export function Button(props) {
|
|
|
54
54
|
if (uiBackgroundProps && uiBackgroundProps.color)
|
|
55
55
|
uiBackgroundProps.color.a /= 2;
|
|
56
56
|
}
|
|
57
|
-
return (ReactEcs.createElement("entity", { onMouseDown: !!props.disabled ? undefined : onMouseDown, onMouseUp: !!props.disabled ? undefined : onMouseUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, uiTransform: uiTransformProps, uiText: textProps, uiBackground: uiBackgroundProps }));
|
|
57
|
+
return (ReactEcs.createElement("entity", { onMouseDown: !!props.disabled ? undefined : onMouseDown, onMouseUp: !!props.disabled ? undefined : onMouseUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onMouseDrag: onMouseDrag, onMouseDragLocked: onMouseDragLocked, onMouseDragEnd: onMouseDragEnd, onInputDown: !!props.disabled ? undefined : onInputDown, onInputUp: !!props.disabled ? undefined : onInputUp, onInputDrag: onInputDrag, onInputDragLocked: onInputDragLocked, onInputDragEnd: onInputDragEnd, uiTransform: uiTransformProps, uiText: textProps, uiBackground: uiBackgroundProps }));
|
|
58
58
|
}
|
|
@@ -34,7 +34,7 @@ function parseUiDropdown(props) {
|
|
|
34
34
|
*/
|
|
35
35
|
/* @__PURE__ */
|
|
36
36
|
export function Dropdown(props) {
|
|
37
|
-
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
37
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseDrag, onMouseDragLocked, onMouseDragEnd, onInputDown, onInputUp, onInputDrag, onInputDragLocked, onInputDragEnd, ...otherProps } = props;
|
|
38
38
|
const dropdownProps = parseUiDropdown(otherProps);
|
|
39
39
|
const commonProps = parseProps({
|
|
40
40
|
uiTransform,
|
|
@@ -42,7 +42,15 @@ export function Dropdown(props) {
|
|
|
42
42
|
onMouseDown,
|
|
43
43
|
onMouseUp,
|
|
44
44
|
onMouseEnter,
|
|
45
|
-
onMouseLeave
|
|
45
|
+
onMouseLeave,
|
|
46
|
+
onMouseDrag,
|
|
47
|
+
onMouseDragLocked,
|
|
48
|
+
onMouseDragEnd,
|
|
49
|
+
onInputDown,
|
|
50
|
+
onInputUp,
|
|
51
|
+
onInputDrag,
|
|
52
|
+
onInputDragLocked,
|
|
53
|
+
onInputDragEnd
|
|
46
54
|
});
|
|
47
55
|
return ReactEcs.createElement("entity", { ...commonProps, uiDropdown: dropdownProps });
|
|
48
56
|
}
|
|
@@ -35,7 +35,7 @@ function parseUiInput(props) {
|
|
|
35
35
|
* @category Component
|
|
36
36
|
*/ /* @__PURE__ */
|
|
37
37
|
export function Input(props) {
|
|
38
|
-
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
38
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseDrag, onMouseDragLocked, onMouseDragEnd, onInputDown, onInputUp, onInputDrag, onInputDragLocked, onInputDragEnd, ...otherProps } = props;
|
|
39
39
|
const inputProps = parseUiInput(otherProps);
|
|
40
40
|
const commonProps = parseProps({
|
|
41
41
|
uiTransform,
|
|
@@ -43,7 +43,15 @@ export function Input(props) {
|
|
|
43
43
|
onMouseDown,
|
|
44
44
|
onMouseUp,
|
|
45
45
|
onMouseEnter,
|
|
46
|
-
onMouseLeave
|
|
46
|
+
onMouseLeave,
|
|
47
|
+
onMouseDrag,
|
|
48
|
+
onMouseDragLocked,
|
|
49
|
+
onMouseDragEnd,
|
|
50
|
+
onInputDown,
|
|
51
|
+
onInputUp,
|
|
52
|
+
onInputDrag,
|
|
53
|
+
onInputDragLocked,
|
|
54
|
+
onInputDragEnd
|
|
47
55
|
});
|
|
48
56
|
return ReactEcs.createElement("entity", { ...commonProps, uiInput: inputProps });
|
|
49
57
|
}
|
|
@@ -16,14 +16,22 @@ export { scaleFontSize } from './utils';
|
|
|
16
16
|
*/
|
|
17
17
|
/* @__PURE__ */
|
|
18
18
|
export function Label(props) {
|
|
19
|
-
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...uiTextProps } = props;
|
|
19
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseDrag, onMouseDragLocked, onMouseDragEnd, onInputDown, onInputUp, onInputDrag, onInputDragLocked, onInputDragEnd, ...uiTextProps } = props;
|
|
20
20
|
const commonProps = parseProps({
|
|
21
21
|
uiTransform,
|
|
22
22
|
uiBackground,
|
|
23
23
|
onMouseDown,
|
|
24
24
|
onMouseUp,
|
|
25
25
|
onMouseEnter,
|
|
26
|
-
onMouseLeave
|
|
26
|
+
onMouseLeave,
|
|
27
|
+
onMouseDrag,
|
|
28
|
+
onMouseDragLocked,
|
|
29
|
+
onMouseDragEnd,
|
|
30
|
+
onInputDown,
|
|
31
|
+
onInputUp,
|
|
32
|
+
onInputDrag,
|
|
33
|
+
onInputDragLocked,
|
|
34
|
+
onInputDragEnd
|
|
27
35
|
});
|
|
28
36
|
const { font, textAlign, fontSize, textWrap, ...textProps } = uiTextProps;
|
|
29
37
|
const uiText = {
|
|
@@ -31,7 +39,9 @@ export function Label(props) {
|
|
|
31
39
|
...getFont(font),
|
|
32
40
|
...getTextAlign(textAlign),
|
|
33
41
|
...getFontSize(fontSize),
|
|
34
|
-
...getTextWrap(textWrap)
|
|
42
|
+
...getTextWrap(textWrap),
|
|
43
|
+
outlineWidth: props.outlineWidth,
|
|
44
|
+
outlineColor: props.outlineColor
|
|
35
45
|
};
|
|
36
46
|
return ReactEcs.createElement("entity", { ...commonProps, uiText: uiText });
|
|
37
47
|
}
|
|
@@ -15,6 +15,10 @@ export interface UiLabelProps {
|
|
|
15
15
|
textAlign?: TextAlignType | undefined;
|
|
16
16
|
/** Label font type. @defaultValue 'sans-serif' */
|
|
17
17
|
font?: UiFontType | undefined;
|
|
18
|
+
/** Outline width of the text. @defaultValue 0 */
|
|
19
|
+
outlineWidth?: number | undefined;
|
|
20
|
+
/** Outline color of the text. @defaultValue `{ r: 0, g: 0, b: 0, a: 1 }` */
|
|
21
|
+
outlineColor?: Color4 | undefined;
|
|
18
22
|
/** Behaviour when text reached. @defaultValue 'wrap' */
|
|
19
23
|
textWrap?: UiTextWrapType | undefined;
|
|
20
24
|
}
|
|
@@ -1,19 +1,50 @@
|
|
|
1
|
+
import { EventSystemCallback, InputAction } from '@dcl/ecs';
|
|
1
2
|
/**
|
|
2
|
-
* Callback function
|
|
3
|
-
*
|
|
3
|
+
* legacy Callback function
|
|
4
|
+
*
|
|
5
|
+
* @public @deprecated This type is no longer used in the sdk api, EventSystemCallback is
|
|
6
|
+
* used for listeners instead
|
|
4
7
|
*/
|
|
5
8
|
export type Callback = () => void;
|
|
9
|
+
/**
|
|
10
|
+
* a record object mapping `InputAction`s to functions.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* onInputDown={{
|
|
14
|
+
* [InputAction.IA_PRIMARY]: (eventData) => { console.log("primary") },
|
|
15
|
+
* [InputAction.IA_SECONDARY]: () => { console.log("secondary") },
|
|
16
|
+
* }}
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type MultiCallback = Partial<Record<InputAction, EventSystemCallback>>;
|
|
6
21
|
/**
|
|
7
22
|
* User key event Listeners
|
|
8
23
|
* @public
|
|
9
24
|
*/
|
|
10
25
|
export type Listeners = {
|
|
11
26
|
/** triggered on mouse down event */
|
|
12
|
-
onMouseDown?:
|
|
27
|
+
onMouseDown?: EventSystemCallback;
|
|
13
28
|
/** triggered on mouse up event */
|
|
14
|
-
onMouseUp?:
|
|
29
|
+
onMouseUp?: EventSystemCallback;
|
|
15
30
|
/** triggered on mouse hover event */
|
|
16
|
-
onMouseEnter?:
|
|
31
|
+
onMouseEnter?: EventSystemCallback;
|
|
17
32
|
/** triggered on mouse leave event */
|
|
18
|
-
onMouseLeave?:
|
|
33
|
+
onMouseLeave?: EventSystemCallback;
|
|
34
|
+
/** triggered on mouse drag event */
|
|
35
|
+
onMouseDrag?: EventSystemCallback;
|
|
36
|
+
/** triggered on mouse drag event */
|
|
37
|
+
onMouseDragLocked?: EventSystemCallback;
|
|
38
|
+
/** triggered on mouse drag event */
|
|
39
|
+
onMouseDragEnd?: EventSystemCallback;
|
|
40
|
+
/** triggered on input down event */
|
|
41
|
+
onInputDown?: MultiCallback;
|
|
42
|
+
/** triggered on input up event */
|
|
43
|
+
onInputUp?: MultiCallback;
|
|
44
|
+
/** triggered on input drag event */
|
|
45
|
+
onInputDrag?: MultiCallback;
|
|
46
|
+
/** triggered on input drag event */
|
|
47
|
+
onInputDragLocked?: MultiCallback;
|
|
48
|
+
/** triggered on input drag event */
|
|
49
|
+
onInputDragEnd?: MultiCallback;
|
|
19
50
|
};
|
|
@@ -2,7 +2,15 @@ const listeners = {
|
|
|
2
2
|
onMouseDown: undefined,
|
|
3
3
|
onMouseUp: undefined,
|
|
4
4
|
onMouseEnter: undefined,
|
|
5
|
-
onMouseLeave: undefined
|
|
5
|
+
onMouseLeave: undefined,
|
|
6
|
+
onMouseDrag: undefined,
|
|
7
|
+
onMouseDragLocked: undefined,
|
|
8
|
+
onMouseDragEnd: undefined,
|
|
9
|
+
onInputDown: undefined,
|
|
10
|
+
onInputUp: undefined,
|
|
11
|
+
onInputDrag: undefined,
|
|
12
|
+
onInputDragLocked: undefined,
|
|
13
|
+
onInputDragEnd: undefined
|
|
6
14
|
};
|
|
7
15
|
const listenersKey = Object.keys(listeners);
|
|
8
16
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BorderRect } from '@dcl/ecs';
|
|
1
|
+
import { BorderRect, Entity } from '@dcl/ecs';
|
|
2
2
|
import { Color4 } from '@dcl/ecs/dist/components/generated/pb/decentraland/common/colors.gen';
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
@@ -15,6 +15,8 @@ export interface UiBackgroundProps {
|
|
|
15
15
|
uvs?: number[];
|
|
16
16
|
/** AvatarTexture for the background */
|
|
17
17
|
avatarTexture?: UiAvatarTexture;
|
|
18
|
+
/** VideoTexture for the background */
|
|
19
|
+
videoTexture?: UiVideoTexture;
|
|
18
20
|
/** Texture for the background */
|
|
19
21
|
texture?: UiTexture;
|
|
20
22
|
}
|
|
@@ -27,6 +29,15 @@ export interface UiAvatarTexture {
|
|
|
27
29
|
wrapMode?: TextureWrapType;
|
|
28
30
|
filterMode?: TextureFilterType;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Texture
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export interface UiVideoTexture {
|
|
37
|
+
videoPlayerEntity: Entity;
|
|
38
|
+
wrapMode?: TextureWrapType;
|
|
39
|
+
filterMode?: TextureFilterType;
|
|
40
|
+
}
|
|
30
41
|
/**
|
|
31
42
|
* Texture
|
|
32
43
|
* @public
|
|
@@ -30,6 +30,14 @@ export function getTexture(props) {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
if (props.videoTexture) {
|
|
34
|
+
return {
|
|
35
|
+
tex: {
|
|
36
|
+
$case: 'videoTexture',
|
|
37
|
+
videoTexture: parseTexture(props.videoTexture)
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
33
41
|
return undefined;
|
|
34
42
|
}
|
|
35
43
|
function parseTexture(texture) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAlign, getDisplay, getFlexDirection, getFlexWrap, getJustify, getOverflow, getPointerFilter, getPositionType, parseBorderColor, parseBorderRadius, parseBorderWidth, parsePosition, parseSize } from './utils';
|
|
1
|
+
import { getAlign, getDisplay, getFlexDirection, getFlexWrap, getJustify, getOverflow, getPointerFilter, getPositionType, parseBorderColor, parseBorderRadius, parseBorderWidth, getScrollPosition, getScrollVisible, parsePosition, parseSize } from './utils';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
@@ -60,7 +60,7 @@ const defaultUiTransform = {
|
|
|
60
60
|
*/
|
|
61
61
|
/* @__PURE__ */
|
|
62
62
|
export function parseUiTransform(props = {}) {
|
|
63
|
-
const { height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, borderRadius, borderWidth, borderColor, ...otherProps } = props;
|
|
63
|
+
const { scrollPosition, scrollVisible, height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, borderRadius, borderWidth, borderColor, zIndex, ...otherProps } = props;
|
|
64
64
|
return {
|
|
65
65
|
...defaultUiTransform,
|
|
66
66
|
...otherProps,
|
|
@@ -86,6 +86,9 @@ export function parseUiTransform(props = {}) {
|
|
|
86
86
|
...(flexWrap && getFlexWrap(flexWrap)),
|
|
87
87
|
...(borderRadius && parseBorderRadius(borderRadius)),
|
|
88
88
|
...(borderWidth && parseBorderWidth(borderWidth)),
|
|
89
|
-
...(borderColor && parseBorderColor(borderColor))
|
|
89
|
+
...(borderColor && parseBorderColor(borderColor)),
|
|
90
|
+
...(scrollPosition && getScrollPosition(scrollPosition)),
|
|
91
|
+
...(scrollVisible && getScrollVisible(scrollVisible)),
|
|
92
|
+
...(zIndex && { zIndex })
|
|
90
93
|
};
|
|
91
94
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Color4 } from '@dcl/ecs/dist/components/generated/pb/decentraland/common/colors.gen';
|
|
2
|
+
import { Vector2 } from '@dcl/ecs/dist/components/generated/pb/decentraland/common/vectors.gen';
|
|
2
3
|
import { ScaleUnit } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* unit value specified. i.e. 1 || '100%' || '1px' || '10vw'
|
|
@@ -73,6 +74,11 @@ export type PositionType = 'absolute' | 'relative';
|
|
|
73
74
|
* The pointer filter property determines if the ui element blocks the pointer or not (elements with pointer events always block the pointer regardless of this property)
|
|
74
75
|
*/
|
|
75
76
|
export type PointerFilterType = 'none' | 'block';
|
|
77
|
+
/**
|
|
78
|
+
* @public
|
|
79
|
+
* The scroll-visible determines if the scrollbars are shown when the scroll overflow is enabled
|
|
80
|
+
*/
|
|
81
|
+
export type ScrollVisibleType = 'horizontal' | 'vertical' | 'both' | 'hidden';
|
|
76
82
|
/**
|
|
77
83
|
* Layout props to position things in the canvas
|
|
78
84
|
* @public
|
|
@@ -129,6 +135,12 @@ export interface UiTransformProps {
|
|
|
129
135
|
borderWidth?: Partial<Position> | PositionUnit;
|
|
130
136
|
/** The opacity property sets the opacity level for an element, it's accumulated across children @defaultValue 1 */
|
|
131
137
|
opacity?: number;
|
|
138
|
+
/** A reference value to identify the element, default empty */
|
|
139
|
+
elementId?: string;
|
|
140
|
+
/** default position=(0,0) if it aplies, a vector or a reference-id */
|
|
141
|
+
scrollPosition?: Vector2 | string;
|
|
142
|
+
/** default ShowScrollBar.SSB_BOTH */
|
|
143
|
+
scrollVisible?: ScrollVisibleType;
|
|
132
144
|
/** default 0 */
|
|
133
145
|
zIndex?: number;
|
|
134
146
|
}
|
|
@@ -241,3 +241,40 @@ const parsePointerFilter = {
|
|
|
241
241
|
none: 0 /* PointerFilterMode.PFM_NONE */,
|
|
242
242
|
block: 1 /* PointerFilterMode.PFM_BLOCK */
|
|
243
243
|
};
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
export function getScrollPosition(scrollPosition) {
|
|
248
|
+
if (typeof scrollPosition === 'string') {
|
|
249
|
+
return {
|
|
250
|
+
scrollPosition: {
|
|
251
|
+
value: {
|
|
252
|
+
$case: 'reference',
|
|
253
|
+
reference: scrollPosition
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return {
|
|
260
|
+
scrollPosition: {
|
|
261
|
+
value: {
|
|
262
|
+
$case: 'position',
|
|
263
|
+
position: scrollPosition
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const parseScrollVisible = {
|
|
270
|
+
both: 0 /* ShowScrollBar.SSB_BOTH */,
|
|
271
|
+
hidden: 3 /* ShowScrollBar.SSB_HIDDEN */,
|
|
272
|
+
horizontal: 2 /* ShowScrollBar.SSB_ONLY_HORIZONTAL */,
|
|
273
|
+
vertical: 1 /* ShowScrollBar.SSB_ONLY_VERTICAL */
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
export function getScrollVisible(scrollVisible) {
|
|
279
|
+
return { scrollVisible: parseScrollVisible[scrollVisible] };
|
|
280
|
+
}
|
package/dist/react-ecs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PBUiBackground, PBUiText, PBUiTransform, PBUiInput, PBUiDropdown } from '@dcl/ecs';
|
|
2
|
-
import {
|
|
1
|
+
import { PBUiBackground, PBUiText, PBUiTransform, PBUiInput, PBUiDropdown, EventSystemCallback } from '@dcl/ecs';
|
|
2
|
+
import { Key, MultiCallback } from './components';
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
@@ -18,10 +18,18 @@ export type EntityComponents = {
|
|
|
18
18
|
uiBackground: PBUiBackground;
|
|
19
19
|
uiInput: PBUiInput;
|
|
20
20
|
uiDropdown: PBUiDropdown;
|
|
21
|
-
onMouseDown:
|
|
22
|
-
onMouseUp:
|
|
23
|
-
onMouseEnter:
|
|
24
|
-
onMouseLeave:
|
|
21
|
+
onMouseDown: EventSystemCallback;
|
|
22
|
+
onMouseUp: EventSystemCallback;
|
|
23
|
+
onMouseEnter: EventSystemCallback;
|
|
24
|
+
onMouseLeave: EventSystemCallback;
|
|
25
|
+
onMouseDrag: EventSystemCallback;
|
|
26
|
+
onMouseDragLocked: EventSystemCallback;
|
|
27
|
+
onMouseDragEnd: EventSystemCallback;
|
|
28
|
+
onInputDown: MultiCallback;
|
|
29
|
+
onInputUp: MultiCallback;
|
|
30
|
+
onInputDrag: MultiCallback;
|
|
31
|
+
onInputDragLocked: MultiCallback;
|
|
32
|
+
onInputDragEnd: MultiCallback;
|
|
25
33
|
};
|
|
26
34
|
/**
|
|
27
35
|
* @hidden
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Entity, IEngine, PointerEventsSystem } from '@dcl/ecs';
|
|
2
2
|
import { ReactEcs } from '../react-ecs';
|
|
3
|
-
export
|
|
4
|
-
update: (component: ReactEcs.JSX.ReactNode) =>
|
|
3
|
+
export interface DclReconciler {
|
|
4
|
+
update: (component: ReactEcs.JSX.ReactNode) => void;
|
|
5
5
|
getEntities: () => Entity[];
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare function createReconciler(engine: Pick<IEngine, 'getComponent' | 'addEntity' | 'removeEntity' | 'defineComponentFromSchema' | 'getEntitiesWith'>, pointerEvents: PointerEventsSystem, rootEntity: Entity | undefined): DclReconciler;
|
package/dist/reconciler/index.js
CHANGED
|
@@ -3,21 +3,11 @@ import Reconciler from 'react-reconciler';
|
|
|
3
3
|
import { isListener } from '../components';
|
|
4
4
|
import { CANVAS_ROOT_ENTITY } from '../components/uiTransform';
|
|
5
5
|
import { componentKeys, isNotUndefined, noopConfig, propsChanged } from './utils';
|
|
6
|
-
function
|
|
7
|
-
const pointers = {
|
|
8
|
-
onMouseDown: 1 /* PointerEventType.PET_DOWN */,
|
|
9
|
-
onMouseUp: 0 /* PointerEventType.PET_UP */,
|
|
10
|
-
onMouseEnter: 2 /* PointerEventType.PET_HOVER_ENTER */,
|
|
11
|
-
onMouseLeave: 3 /* PointerEventType.PET_HOVER_LEAVE */
|
|
12
|
-
};
|
|
13
|
-
return pointers[pointerKey];
|
|
14
|
-
}
|
|
15
|
-
export function createReconciler(engine, pointerEvents) {
|
|
6
|
+
export function createReconciler(engine, pointerEvents, rootEntity) {
|
|
16
7
|
// Store all the entities so when we destroy the UI we can also destroy them
|
|
17
8
|
const entities = new Set();
|
|
18
9
|
// Store the onChange callbacks to be runned every time a Result has changed
|
|
19
10
|
const changeEvents = new Map();
|
|
20
|
-
const clickEvents = new Map();
|
|
21
11
|
// Initialize components
|
|
22
12
|
const UiTransform = components.UiTransform(engine);
|
|
23
13
|
const UiText = components.UiText(engine);
|
|
@@ -26,6 +16,8 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
26
16
|
const UiInputResult = components.UiInputResult(engine);
|
|
27
17
|
const UiDropdown = components.UiDropdown(engine);
|
|
28
18
|
const UiDropdownResult = components.UiDropdownResult(engine);
|
|
19
|
+
const UiScrollResult = components.UiScrollResult(engine);
|
|
20
|
+
const Transform = components.Transform(engine);
|
|
29
21
|
// Component ID Helper
|
|
30
22
|
const getComponentId = {
|
|
31
23
|
uiTransform: UiTransform.componentId,
|
|
@@ -34,22 +26,15 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
34
26
|
uiInput: UiInput.componentId,
|
|
35
27
|
uiDropdown: UiDropdown.componentId
|
|
36
28
|
};
|
|
37
|
-
function pointerEventCallback(entity, pointerEvent) {
|
|
38
|
-
const callback = clickEvents.get(entity)?.get(pointerEvent);
|
|
39
|
-
if (callback)
|
|
40
|
-
callback();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
29
|
function updateTree(instance, props) {
|
|
44
30
|
upsertComponent(instance, props, 'uiTransform');
|
|
45
31
|
}
|
|
46
32
|
function upsertListener(instance, update) {
|
|
47
33
|
if (update.type === 'delete' || !update.props) {
|
|
48
|
-
|
|
49
|
-
if (update.component === 'onMouseDown') {
|
|
34
|
+
if (update.component === 'onMouseDown' || update.component === 'onInputDown') {
|
|
50
35
|
pointerEvents.removeOnPointerDown(instance.entity);
|
|
51
36
|
}
|
|
52
|
-
else if (update.component === 'onMouseUp') {
|
|
37
|
+
else if (update.component === 'onMouseUp' || update.component === 'onInputUp') {
|
|
53
38
|
pointerEvents.removeOnPointerUp(instance.entity);
|
|
54
39
|
}
|
|
55
40
|
else if (update.component === 'onMouseEnter') {
|
|
@@ -58,32 +43,57 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
58
43
|
else if (update.component === 'onMouseLeave') {
|
|
59
44
|
pointerEvents.removeOnPointerHoverLeave(instance.entity);
|
|
60
45
|
}
|
|
46
|
+
else if (update.component === 'onMouseDrag' || update.component === 'onInputDrag') {
|
|
47
|
+
pointerEvents.removeOnPointerDrag(instance.entity);
|
|
48
|
+
}
|
|
49
|
+
else if (update.component === 'onMouseDragLocked' || update.component === 'onInputDragLocked') {
|
|
50
|
+
pointerEvents.removeOnPointerDragLocked(instance.entity);
|
|
51
|
+
}
|
|
52
|
+
else if (update.component === 'onMouseDragEnd' || update.component === 'onInputDragEnd') {
|
|
53
|
+
pointerEvents.removeOnPointerDragEnd(instance.entity);
|
|
54
|
+
}
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
63
57
|
if (update.props) {
|
|
64
|
-
const
|
|
65
|
-
const entityEvent = clickEvents.get(instance.entity) || clickEvents.set(instance.entity, new Map()).get(instance.entity);
|
|
66
|
-
const alreadyHasPointerEvent = entityEvent.get(pointerEvent);
|
|
67
|
-
entityEvent.set(pointerEvent, update.props);
|
|
68
|
-
if (alreadyHasPointerEvent)
|
|
69
|
-
return;
|
|
70
|
-
const pointerEventSystem = update.component === 'onMouseDown'
|
|
58
|
+
const pointerEventSystem = update.component === 'onMouseDown' || update.component === 'onInputDown'
|
|
71
59
|
? pointerEvents.onPointerDown
|
|
72
|
-
: update.component === 'onMouseUp'
|
|
60
|
+
: update.component === 'onMouseUp' || update.component === 'onInputUp'
|
|
73
61
|
? pointerEvents.onPointerUp
|
|
74
62
|
: update.component === 'onMouseEnter'
|
|
75
63
|
? pointerEvents.onPointerHoverEnter
|
|
76
|
-
: update.component === 'onMouseLeave'
|
|
64
|
+
: update.component === 'onMouseLeave'
|
|
65
|
+
? pointerEvents.onPointerHoverLeave
|
|
66
|
+
: update.component === 'onMouseDrag' || update.component === 'onInputDrag'
|
|
67
|
+
? pointerEvents.onPointerDrag
|
|
68
|
+
: update.component === 'onMouseDragLocked' || update.component === 'onInputDragLocked'
|
|
69
|
+
? pointerEvents.onPointerDragLocked
|
|
70
|
+
: (update.component === 'onMouseDragEnd' || update.component === 'onInputDragEnd') &&
|
|
71
|
+
pointerEvents.onPointerDragEnd;
|
|
77
72
|
if (pointerEventSystem) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
if (typeof update.props === 'function') {
|
|
74
|
+
pointerEventSystem({
|
|
75
|
+
entity: instance.entity,
|
|
76
|
+
opts: {
|
|
77
|
+
button: 0 /* InputAction.IA_POINTER */,
|
|
78
|
+
// We add this showFeedBack so the pointerEventSystem creates a PointerEvent component with our entity
|
|
79
|
+
// This is needed for the renderer to know which entities are clickeables
|
|
80
|
+
showFeedback: true
|
|
81
|
+
}
|
|
82
|
+
}, update.props);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// force the right overload (the single arg version doesn't exist for onPointerHoverEnter or onPointerHoverLeave,
|
|
86
|
+
// but we don't have onInputXXX components for those)
|
|
87
|
+
;
|
|
88
|
+
pointerEventSystem({
|
|
89
|
+
entity: instance.entity,
|
|
90
|
+
optsList: Object.entries(update.props).map(([button, cb]) => ({
|
|
91
|
+
button: Number(button),
|
|
92
|
+
showFeedback: true,
|
|
93
|
+
cb
|
|
94
|
+
}))
|
|
95
|
+
});
|
|
96
|
+
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
99
|
}
|
|
@@ -124,7 +134,6 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
124
134
|
}
|
|
125
135
|
function removeChildEntity(instance) {
|
|
126
136
|
changeEvents.delete(instance.entity);
|
|
127
|
-
clickEvents.delete(instance.entity);
|
|
128
137
|
engine.removeEntity(instance.entity);
|
|
129
138
|
for (const child of instance._child) {
|
|
130
139
|
removeChildEntity(child);
|
|
@@ -193,6 +202,10 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
193
202
|
...noopConfig,
|
|
194
203
|
createInstance(type, props) {
|
|
195
204
|
const entity = engine.addEntity();
|
|
205
|
+
// set root
|
|
206
|
+
if (rootEntity !== undefined) {
|
|
207
|
+
Transform.createOrReplace(entity, { parent: rootEntity });
|
|
208
|
+
}
|
|
196
209
|
entities.add(entity);
|
|
197
210
|
const instance = {
|
|
198
211
|
entity,
|
|
@@ -206,11 +219,13 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
206
219
|
continue;
|
|
207
220
|
}
|
|
208
221
|
if (isListener(keyTyped)) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
222
|
+
if (props[keyTyped] !== undefined) {
|
|
223
|
+
upsertListener(instance, {
|
|
224
|
+
type: 'add',
|
|
225
|
+
props: props[keyTyped],
|
|
226
|
+
component: keyTyped
|
|
227
|
+
});
|
|
228
|
+
}
|
|
214
229
|
}
|
|
215
230
|
else {
|
|
216
231
|
upsertComponent(instance, props[keyTyped], keyTyped);
|
package/dist/reconciler/utils.js
CHANGED
|
@@ -35,6 +35,14 @@ const entityComponent = {
|
|
|
35
35
|
onMouseUp: undefined,
|
|
36
36
|
onMouseEnter: undefined,
|
|
37
37
|
onMouseLeave: undefined,
|
|
38
|
+
onMouseDrag: undefined,
|
|
39
|
+
onMouseDragLocked: undefined,
|
|
40
|
+
onMouseDragEnd: undefined,
|
|
41
|
+
onInputDown: undefined,
|
|
42
|
+
onInputUp: undefined,
|
|
43
|
+
onInputDrag: undefined,
|
|
44
|
+
onInputDragLocked: undefined,
|
|
45
|
+
onInputDragEnd: undefined,
|
|
38
46
|
uiInput: undefined,
|
|
39
47
|
uiDropdown: undefined
|
|
40
48
|
};
|
package/dist/system.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IEngine, PointerEventsSystem } from '@dcl/ecs';
|
|
1
|
+
import type { Entity, IEngine, PointerEventsSystem } from '@dcl/ecs';
|
|
2
2
|
import type { ReactEcs } from './react-ecs';
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
@@ -10,6 +10,7 @@ export type UiComponent = () => ReactEcs.JSX.ReactNode;
|
|
|
10
10
|
export interface ReactBasedUiSystem {
|
|
11
11
|
destroy(): void;
|
|
12
12
|
setUiRenderer(ui: UiComponent): void;
|
|
13
|
+
setTextureRenderer(entity: Entity, ui: UiComponent): void;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* @public
|
package/dist/system.js
CHANGED
|
@@ -4,11 +4,15 @@ import { createReconciler } from './reconciler';
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
7
|
-
const renderer = createReconciler(engine, pointerSystem);
|
|
7
|
+
const renderer = createReconciler(engine, pointerSystem, undefined);
|
|
8
8
|
let uiComponent = undefined;
|
|
9
|
+
const textureRenderersAndUis = [];
|
|
9
10
|
function ReactBasedUiSystem() {
|
|
10
11
|
if (uiComponent)
|
|
11
12
|
renderer.update(React.createElement(uiComponent));
|
|
13
|
+
for (const [textureRenderer, ui] of textureRenderersAndUis) {
|
|
14
|
+
textureRenderer.update(React.createElement(ui));
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
engine.addSystem(ReactBasedUiSystem, 100e3, '@dcl/react-ecs');
|
|
14
18
|
return {
|
|
@@ -17,9 +21,20 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
|
17
21
|
for (const entity of renderer.getEntities()) {
|
|
18
22
|
engine.removeEntity(entity);
|
|
19
23
|
}
|
|
24
|
+
for (const [textureRenderer, _] of textureRenderersAndUis) {
|
|
25
|
+
for (const entity of textureRenderer.getEntities()) {
|
|
26
|
+
engine.removeEntity(entity);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const entity of renderer.getEntities()) {
|
|
30
|
+
engine.removeEntity(entity);
|
|
31
|
+
}
|
|
20
32
|
},
|
|
21
33
|
setUiRenderer(ui) {
|
|
22
34
|
uiComponent = ui;
|
|
35
|
+
},
|
|
36
|
+
setTextureRenderer(entity, ui) {
|
|
37
|
+
textureRenderersAndUis.push([createReconciler(engine, pointerSystem, entity), ui]);
|
|
23
38
|
}
|
|
24
39
|
};
|
|
25
40
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/react-ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.13.1-
|
|
4
|
+
"version": "7.13.1-19516109426.commit-e1e79aa",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@dcl/ecs": "7.13.1-
|
|
8
|
+
"@dcl/ecs": "7.13.1-19516109426.commit-e1e79aa",
|
|
9
9
|
"react": "^18.2.0",
|
|
10
10
|
"react-reconciler": "^0.29.0"
|
|
11
11
|
},
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"tsconfig": "./tsconfig.json"
|
|
41
41
|
},
|
|
42
42
|
"types": "./dist/index.d.ts",
|
|
43
|
-
"commit": "
|
|
43
|
+
"commit": "e1e79aa4c353b3698cf182659d0110ef3eb2e68f"
|
|
44
44
|
}
|