@dcl-regenesislabs/react-ecs 7.33.1-45463223330.commit-bb0e4a4 → 7.33.1-45493173181.commit-4abbc35
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 +5 -2
- package/dist/components/Input/index.js +5 -2
- package/dist/components/Label/index.js +5 -2
- package/dist/components/Label/types.d.ts +1 -1
- package/dist/components/listeners/types.d.ts +10 -2
- package/dist/components/listeners/types.js +4 -1
- package/dist/components/uiBackground/types.d.ts +12 -1
- package/dist/components/uiBackground/utils.js +8 -0
- package/dist/components/uiTransform/index.js +5 -3
- package/dist/components/uiTransform/types.d.ts +12 -0
- package/dist/components/uiTransform/utils.js +21 -0
- package/dist/react-ecs.d.ts +3 -0
- package/dist/reconciler/index.d.ts +1 -1
- package/dist/reconciler/index.js +31 -6
- package/dist/reconciler/utils.js +3 -0
- package/dist/system.d.ts +15 -0
- package/dist/system.js +30 -0
- package/package.json +2 -2
|
@@ -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, ...otherProps } = props;
|
|
33
33
|
const buttonProps = getButtonProps(props);
|
|
34
34
|
const uiBackgroundProps = parseUiBackground({
|
|
35
35
|
...buttonProps.uiBackground,
|
|
@@ -58,5 +58,5 @@ export function Button(props) {
|
|
|
58
58
|
uiBackgroundProps.color = { ...uiBackgroundProps.color, a: uiBackgroundProps.color.a / 2 };
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
return (ReactEcs.createElement("entity", { onMouseDown: !!props.disabled ? undefined : onMouseDown, onMouseUp: !!props.disabled ? undefined : onMouseUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, uiTransform: uiTransformProps, uiText: textProps, uiBackground: uiBackgroundProps }));
|
|
61
|
+
return (ReactEcs.createElement("entity", { onMouseDown: !!props.disabled ? undefined : onMouseDown, onMouseUp: !!props.disabled ? undefined : onMouseUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onMouseDrag: onMouseDrag, onMouseDragLocked: onMouseDragLocked, onMouseDragEnd: onMouseDragEnd, uiTransform: uiTransformProps, uiText: textProps, uiBackground: uiBackgroundProps }));
|
|
62
62
|
}
|
|
@@ -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, ...otherProps } = props;
|
|
38
38
|
const dropdownProps = parseUiDropdown(otherProps);
|
|
39
39
|
const commonProps = parseProps({
|
|
40
40
|
uiTransform,
|
|
@@ -42,7 +42,10 @@ export function Dropdown(props) {
|
|
|
42
42
|
onMouseDown,
|
|
43
43
|
onMouseUp,
|
|
44
44
|
onMouseEnter,
|
|
45
|
-
onMouseLeave
|
|
45
|
+
onMouseLeave,
|
|
46
|
+
onMouseDrag,
|
|
47
|
+
onMouseDragLocked,
|
|
48
|
+
onMouseDragEnd
|
|
46
49
|
});
|
|
47
50
|
return ReactEcs.createElement("entity", { ...commonProps, uiDropdown: dropdownProps });
|
|
48
51
|
}
|
|
@@ -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, ...otherProps } = props;
|
|
39
39
|
const inputProps = parseUiInput(otherProps);
|
|
40
40
|
const commonProps = parseProps({
|
|
41
41
|
uiTransform,
|
|
@@ -43,7 +43,10 @@ export function Input(props) {
|
|
|
43
43
|
onMouseDown,
|
|
44
44
|
onMouseUp,
|
|
45
45
|
onMouseEnter,
|
|
46
|
-
onMouseLeave
|
|
46
|
+
onMouseLeave,
|
|
47
|
+
onMouseDrag,
|
|
48
|
+
onMouseDragLocked,
|
|
49
|
+
onMouseDragEnd
|
|
47
50
|
});
|
|
48
51
|
return ReactEcs.createElement("entity", { ...commonProps, uiInput: inputProps });
|
|
49
52
|
}
|
|
@@ -16,14 +16,17 @@ 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, ...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
|
|
27
30
|
});
|
|
28
31
|
const { font, textAlign, fontSize, textWrap, ...textProps } = uiTextProps;
|
|
29
32
|
const uiText = {
|
|
@@ -15,7 +15,7 @@ export interface UiLabelProps {
|
|
|
15
15
|
textAlign?: TextAlignType | undefined;
|
|
16
16
|
/** Label font type. @defaultValue 'sans-serif' */
|
|
17
17
|
font?: UiFontType | undefined;
|
|
18
|
-
/**
|
|
18
|
+
/** A `.ttf` file in the scene content, or a Google Fonts family name. `font` is used when it can't be loaded. */
|
|
19
19
|
fontSrc?: string | undefined;
|
|
20
20
|
/** Behaviour when text reached. @defaultValue 'wrap' */
|
|
21
21
|
textWrap?: UiTextWrapType | undefined;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { PBPointerEventsResult } from '@dcl/ecs';
|
|
1
2
|
/**
|
|
2
|
-
* Callback function to be triggered on a specified event
|
|
3
|
+
* Callback function to be triggered on a specified event. Receives the pointer event that
|
|
4
|
+
* fired it (button, hit, and for drags the pointer delta), which handlers may ignore.
|
|
3
5
|
* @public
|
|
4
6
|
*/
|
|
5
|
-
export type Callback = () => void;
|
|
7
|
+
export type Callback = (event: PBPointerEventsResult) => void;
|
|
6
8
|
/**
|
|
7
9
|
* User key event Listeners
|
|
8
10
|
* @public
|
|
@@ -16,4 +18,10 @@ export type Listeners = {
|
|
|
16
18
|
onMouseEnter?: Callback;
|
|
17
19
|
/** triggered on mouse leave event */
|
|
18
20
|
onMouseLeave?: Callback;
|
|
21
|
+
/** triggered while the pointer is dragged after pressing on the element. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
22
|
+
onMouseDrag?: Callback;
|
|
23
|
+
/** triggered while the pointer is dragged with the cursor locked in place. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
24
|
+
onMouseDragLocked?: Callback;
|
|
25
|
+
/** triggered when a drag that started on the element ends. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
26
|
+
onMouseDragEnd?: Callback;
|
|
19
27
|
};
|
|
@@ -2,7 +2,10 @@ 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
|
|
6
9
|
};
|
|
7
10
|
const listenersKey = Object.keys(listeners);
|
|
8
11
|
/**
|
|
@@ -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: the frames of a VideoPlayer on another entity. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
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
|
+
* Video Texture. Supported only by the Bevy Explorer; other clients ignore it.
|
|
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, getScrollPosition, getScrollVisible, parseBorderColor, parseBorderRadius, parseBorderWidth, 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 { height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, borderRadius, borderWidth, borderColor, scrollPosition, scrollVisible, ...otherProps } = props;
|
|
64
64
|
return {
|
|
65
65
|
...defaultUiTransform,
|
|
66
66
|
...otherProps,
|
|
@@ -86,6 +86,8 @@ 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))
|
|
90
92
|
};
|
|
91
93
|
}
|
|
@@ -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'
|
|
@@ -131,4 +132,15 @@ export interface UiTransformProps {
|
|
|
131
132
|
opacity?: number;
|
|
132
133
|
/** default 0 */
|
|
133
134
|
zIndex?: number;
|
|
135
|
+
/** A reference id for the element, e.g. as a scrollPosition target or for SetUiFocus. default empty. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
136
|
+
elementId?: string;
|
|
137
|
+
/** Scroll offset when overflow is 'scroll': a position, or the elementId of a child to scroll to. default (0, 0). Supported only by the Bevy Explorer; other clients ignore it. */
|
|
138
|
+
scrollPosition?: Vector2 | string;
|
|
139
|
+
/** Which scrollbars to show when overflow is 'scroll'. default 'both'. Supported only by the Bevy Explorer; other clients ignore it. */
|
|
140
|
+
scrollVisible?: ScrollVisibleType;
|
|
134
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Which scrollbars are shown when the overflow is scrollable. Supported only by the Bevy Explorer; other clients ignore it.
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export type ScrollVisibleType = 'horizontal' | 'vertical' | 'both' | 'hidden';
|
|
@@ -244,3 +244,24 @@ const parsePointerFilter = {
|
|
|
244
244
|
none: 0 /* PointerFilterMode.PFM_NONE */,
|
|
245
245
|
block: 1 /* PointerFilterMode.PFM_BLOCK */
|
|
246
246
|
};
|
|
247
|
+
/**
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
export function getScrollPosition(scrollPosition) {
|
|
251
|
+
if (typeof scrollPosition === 'string') {
|
|
252
|
+
return { scrollPosition: { value: { $case: 'reference', reference: scrollPosition } } };
|
|
253
|
+
}
|
|
254
|
+
return { scrollPosition: { value: { $case: 'position', position: scrollPosition } } };
|
|
255
|
+
}
|
|
256
|
+
const parseScrollVisible = {
|
|
257
|
+
both: 0 /* ShowScrollBar.SSB_BOTH */,
|
|
258
|
+
hidden: 3 /* ShowScrollBar.SSB_HIDDEN */,
|
|
259
|
+
horizontal: 2 /* ShowScrollBar.SSB_ONLY_HORIZONTAL */,
|
|
260
|
+
vertical: 1 /* ShowScrollBar.SSB_ONLY_VERTICAL */
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* @internal
|
|
264
|
+
*/
|
|
265
|
+
export function getScrollVisible(scrollVisible) {
|
|
266
|
+
return { scrollVisible: parseScrollVisible[scrollVisible] };
|
|
267
|
+
}
|
package/dist/react-ecs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entity, IEngine, PointerEventsSystem } from '@dcl/ecs';
|
|
2
2
|
import { ReactEcs } from '../react-ecs';
|
|
3
|
-
export declare function createReconciler(engine: Pick<IEngine, 'getComponent' | 'addEntity' | 'removeEntity' | 'defineComponentFromSchema' | 'getEntitiesWith'>, pointerEvents: PointerEventsSystem): {
|
|
3
|
+
export declare function createReconciler(engine: Pick<IEngine, 'getComponent' | 'addEntity' | 'removeEntity' | 'defineComponentFromSchema' | 'getEntitiesWith'>, pointerEvents: PointerEventsSystem, rootEntity?: Entity): {
|
|
4
4
|
update: (component: ReactEcs.JSX.ReactNode) => number;
|
|
5
5
|
getEntities: () => Entity[];
|
|
6
6
|
};
|
package/dist/reconciler/index.js
CHANGED
|
@@ -8,11 +8,17 @@ function getPointerEnum(pointerKey) {
|
|
|
8
8
|
onMouseDown: 1 /* PointerEventType.PET_DOWN */,
|
|
9
9
|
onMouseUp: 0 /* PointerEventType.PET_UP */,
|
|
10
10
|
onMouseEnter: 2 /* PointerEventType.PET_HOVER_ENTER */,
|
|
11
|
-
onMouseLeave: 3 /* PointerEventType.PET_HOVER_LEAVE
|
|
11
|
+
onMouseLeave: 3 /* PointerEventType.PET_HOVER_LEAVE */,
|
|
12
|
+
onMouseDrag: 7 /* PointerEventType.PET_DRAG */,
|
|
13
|
+
onMouseDragLocked: 6 /* PointerEventType.PET_DRAG_LOCKED */,
|
|
14
|
+
onMouseDragEnd: 8 /* PointerEventType.PET_DRAG_END */
|
|
12
15
|
};
|
|
13
16
|
return pointers[pointerKey];
|
|
14
17
|
}
|
|
15
|
-
export function createReconciler(engine, pointerEvents
|
|
18
|
+
export function createReconciler(engine, pointerEvents,
|
|
19
|
+
// When set, every entity this reconciler creates is parented to it -- a UiCanvas on the root
|
|
20
|
+
// entity then renders the tree to a texture instead of the screen.
|
|
21
|
+
rootEntity) {
|
|
16
22
|
// Store all the entities so when we destroy the UI we can also destroy them
|
|
17
23
|
const entities = new Set();
|
|
18
24
|
// Store the onChange callbacks to be runned every time a Result has changed
|
|
@@ -29,6 +35,7 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
29
35
|
const UiInputResult = components.UiInputResult(engine);
|
|
30
36
|
const UiDropdown = components.UiDropdown(engine);
|
|
31
37
|
const UiDropdownResult = components.UiDropdownResult(engine);
|
|
38
|
+
const Transform = components.Transform(engine);
|
|
32
39
|
const UiInputBinding = components.UiInputBinding(engine);
|
|
33
40
|
// Component ID Helper
|
|
34
41
|
const getComponentId = {
|
|
@@ -39,10 +46,10 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
39
46
|
uiDropdown: UiDropdown.componentId,
|
|
40
47
|
uiInputBinding: UiInputBinding.componentId
|
|
41
48
|
};
|
|
42
|
-
function pointerEventCallback(entity, pointerEvent) {
|
|
49
|
+
function pointerEventCallback(entity, pointerEvent, event) {
|
|
43
50
|
const callback = clickEvents.get(entity)?.get(pointerEvent);
|
|
44
51
|
if (callback)
|
|
45
|
-
callback();
|
|
52
|
+
callback(event);
|
|
46
53
|
return;
|
|
47
54
|
}
|
|
48
55
|
function updateTree(instance, props) {
|
|
@@ -66,6 +73,15 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
66
73
|
else if (update.component === 'onMouseLeave') {
|
|
67
74
|
pointerEvents.removeOnPointerHoverLeave(instance.entity);
|
|
68
75
|
}
|
|
76
|
+
else if (update.component === 'onMouseDrag') {
|
|
77
|
+
pointerEvents.removeOnPointerDrag(instance.entity);
|
|
78
|
+
}
|
|
79
|
+
else if (update.component === 'onMouseDragLocked') {
|
|
80
|
+
pointerEvents.removeOnPointerDragLocked(instance.entity);
|
|
81
|
+
}
|
|
82
|
+
else if (update.component === 'onMouseDragEnd') {
|
|
83
|
+
pointerEvents.removeOnPointerDragEnd(instance.entity);
|
|
84
|
+
}
|
|
69
85
|
return;
|
|
70
86
|
}
|
|
71
87
|
if (update.props) {
|
|
@@ -81,7 +97,13 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
81
97
|
? pointerEvents.onPointerUp
|
|
82
98
|
: update.component === 'onMouseEnter'
|
|
83
99
|
? pointerEvents.onPointerHoverEnter
|
|
84
|
-
: update.component === 'onMouseLeave'
|
|
100
|
+
: update.component === 'onMouseLeave'
|
|
101
|
+
? pointerEvents.onPointerHoverLeave
|
|
102
|
+
: update.component === 'onMouseDrag'
|
|
103
|
+
? pointerEvents.onPointerDrag
|
|
104
|
+
: update.component === 'onMouseDragLocked'
|
|
105
|
+
? pointerEvents.onPointerDragLocked
|
|
106
|
+
: update.component === 'onMouseDragEnd' && pointerEvents.onPointerDragEnd;
|
|
85
107
|
if (pointerEventSystem) {
|
|
86
108
|
pointerEventSystem({
|
|
87
109
|
entity: instance.entity,
|
|
@@ -91,7 +113,7 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
91
113
|
// This is needed for the renderer to know which entities are clickeables
|
|
92
114
|
showFeedback: true
|
|
93
115
|
}
|
|
94
|
-
}, () => pointerEventCallback(instance.entity, pointerEvent));
|
|
116
|
+
}, (event) => pointerEventCallback(instance.entity, pointerEvent, event));
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
119
|
}
|
|
@@ -248,6 +270,9 @@ export function createReconciler(engine, pointerEvents) {
|
|
|
248
270
|
...noopConfig,
|
|
249
271
|
createInstance(type, props) {
|
|
250
272
|
const entity = engine.addEntity();
|
|
273
|
+
if (rootEntity !== undefined) {
|
|
274
|
+
Transform.createOrReplace(entity, { parent: rootEntity });
|
|
275
|
+
}
|
|
251
276
|
entities.add(entity);
|
|
252
277
|
const instance = {
|
|
253
278
|
entity,
|
package/dist/reconciler/utils.js
CHANGED
|
@@ -49,6 +49,9 @@ const entityComponent = {
|
|
|
49
49
|
onMouseUp: undefined,
|
|
50
50
|
onMouseEnter: undefined,
|
|
51
51
|
onMouseLeave: undefined,
|
|
52
|
+
onMouseDrag: undefined,
|
|
53
|
+
onMouseDragLocked: undefined,
|
|
54
|
+
onMouseDragEnd: undefined,
|
|
52
55
|
uiInput: undefined,
|
|
53
56
|
uiDropdown: undefined,
|
|
54
57
|
uiInputBinding: undefined
|
package/dist/system.d.ts
CHANGED
|
@@ -85,6 +85,21 @@ export interface ReactBasedUiSystem {
|
|
|
85
85
|
* @param entity - The entity whose UI renderer should be removed
|
|
86
86
|
*/
|
|
87
87
|
removeUiRenderer(entity: Entity): void;
|
|
88
|
+
/**
|
|
89
|
+
* Render a UI tree to a texture. The tree is rooted at `entity`, which must carry a UiCanvas
|
|
90
|
+
* describing the texture; the result can be sampled through `TextureUnion.uiTexture`. Replaces
|
|
91
|
+
* any texture renderer already set on the entity, and is torn down when the entity is removed.
|
|
92
|
+
* Supported only by the Bevy Explorer; other clients ignore it.
|
|
93
|
+
*
|
|
94
|
+
* @param entity - The UiCanvas entity the UI tree hangs from
|
|
95
|
+
* @param ui - The UI component to render
|
|
96
|
+
*/
|
|
97
|
+
setTextureRenderer(entity: Entity, ui: UiComponent): void;
|
|
98
|
+
/**
|
|
99
|
+
* Remove a texture renderer previously set with setTextureRenderer(), destroying its entities.
|
|
100
|
+
* @param entity - The UiCanvas entity the renderer was set on
|
|
101
|
+
*/
|
|
102
|
+
removeTextureRenderer(entity: Entity): void;
|
|
88
103
|
}
|
|
89
104
|
/**
|
|
90
105
|
* @public
|
package/dist/system.js
CHANGED
|
@@ -55,6 +55,18 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
|
55
55
|
// order, so it is already sorted by `order` and only the main UI has to be slotted in.
|
|
56
56
|
let nextOrder = 0;
|
|
57
57
|
let mainOrder = undefined;
|
|
58
|
+
// UI trees rendered to a texture, keyed by their UiCanvas entity. Each needs its own reconciler
|
|
59
|
+
// because the root parent is a per-reconciler property.
|
|
60
|
+
const textureRenderers = new Map();
|
|
61
|
+
function destroyTextureRenderer(entity) {
|
|
62
|
+
const entry = textureRenderers.get(entity);
|
|
63
|
+
if (!entry)
|
|
64
|
+
return;
|
|
65
|
+
textureRenderers.delete(entity);
|
|
66
|
+
for (const uiEntity of entry.renderer.getEntities()) {
|
|
67
|
+
engine.removeEntity(uiEntity);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
58
70
|
const UiCanvasInformation = ecsComponents.UiCanvasInformation(engine);
|
|
59
71
|
// Unique owner to prevent other UI systems resetting this scale factor.
|
|
60
72
|
const uiScaleFactorOwner = Symbol('react-ecs-ui-scale');
|
|
@@ -191,6 +203,14 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
|
191
203
|
else {
|
|
192
204
|
renderer.update(null);
|
|
193
205
|
}
|
|
206
|
+
for (const [entity, entry] of textureRenderers) {
|
|
207
|
+
if (engine.getEntityState(entity) === EntityState.Removed) {
|
|
208
|
+
destroyTextureRenderer(entity);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
entry.renderer.update(React.createElement(entry.ui));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
194
214
|
}
|
|
195
215
|
function UiScaleSystem() {
|
|
196
216
|
const canvasInfo = UiCanvasInformation.getOrNull(engine.RootEntity);
|
|
@@ -248,6 +268,9 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
|
248
268
|
for (const entity of renderer.getEntities()) {
|
|
249
269
|
engine.removeEntity(entity);
|
|
250
270
|
}
|
|
271
|
+
for (const entity of textureRenderers.keys()) {
|
|
272
|
+
destroyTextureRenderer(entity);
|
|
273
|
+
}
|
|
251
274
|
},
|
|
252
275
|
setUiRenderer(ui, options) {
|
|
253
276
|
uiComponent = ui;
|
|
@@ -259,6 +282,13 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
|
|
|
259
282
|
},
|
|
260
283
|
removeUiRenderer(entity) {
|
|
261
284
|
additionalRenderers.delete(entity);
|
|
285
|
+
},
|
|
286
|
+
setTextureRenderer(entity, ui) {
|
|
287
|
+
destroyTextureRenderer(entity);
|
|
288
|
+
textureRenderers.set(entity, { renderer: createReconciler(engine, pointerSystem, entity), ui });
|
|
289
|
+
},
|
|
290
|
+
removeTextureRenderer(entity) {
|
|
291
|
+
destroyTextureRenderer(entity);
|
|
262
292
|
}
|
|
263
293
|
};
|
|
264
294
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl-regenesislabs/react-ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.33.1-
|
|
4
|
+
"version": "7.33.1-45493173181.commit-4abbc35",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/dcl-one/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@dcl/ecs": "npm:@dcl-regenesislabs/ecs@7.33.1-
|
|
8
|
+
"@dcl/ecs": "npm:@dcl-regenesislabs/ecs@7.33.1-45493173181.commit-4abbc35",
|
|
9
9
|
"react": "^18.2.0",
|
|
10
10
|
"react-reconciler": "^0.29.0"
|
|
11
11
|
},
|