@dcl/react-ecs 7.3.27-6724658310.commit-6b8ca94 → 7.3.27-6735610978.commit-0ffa614

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.
@@ -13,6 +13,9 @@ import { UiInputProps } from './types';
13
13
  onChange={(value) => {
14
14
  email = value
15
15
  }}
16
+ onSubmit={(value) => {
17
+ email = value
18
+ }}
16
19
  uiBackground={{ color: Color4.Red() }}
17
20
  uiTransform={{ width: 200, height: 36 }}
18
21
  value={textValue}
@@ -23,6 +23,9 @@ function parseUiInput(props) {
23
23
  onChange={(value) => {
24
24
  email = value
25
25
  }}
26
+ onSubmit={(value) => {
27
+ email = value
28
+ }}
26
29
  uiBackground={{ color: Color4.Red() }}
27
30
  uiTransform={{ width: 200, height: 36 }}
28
31
  value={textValue}
@@ -6,6 +6,8 @@ import { TextAlignType, UiFontType } from '../Label/types';
6
6
  export interface UiInputProps extends Omit<PBUiInput, 'font' | 'textAlign'> {
7
7
  /** function to be called on value change */
8
8
  onChange?(value: string): void;
9
+ /** function to be called on text field submit */
10
+ onSubmit?(value: string): void;
9
11
  font?: UiFontType;
10
12
  textAlign?: TextAlignType;
11
13
  }
@@ -75,10 +75,22 @@ export function createReconciler(engine, pointerEvents) {
75
75
  }
76
76
  function upsertComponent(instance, props = {}, componentName) {
77
77
  const componentId = getComponentId[componentName];
78
- if ('onChange' in props) {
79
- const onChange = props['onChange'];
80
- updateOnChange(instance.entity, componentId, { fn: onChange });
81
- delete props['onChange'];
78
+ const onChangeExists = 'onChange' in props;
79
+ const onSubmitExists = 'onSubmit' in props;
80
+ const entityState = changeEvents.get(instance.entity)?.get(componentId);
81
+ const onChange = onChangeExists
82
+ ? props['onChange']
83
+ : entityState?.onChangeCallback;
84
+ const onSubmit = onSubmitExists
85
+ ? props['onSubmit']
86
+ : entityState?.onSubmitCallback;
87
+ if (onChangeExists || onSubmitExists) {
88
+ updateOnChange(instance.entity, componentId, {
89
+ onChangeCallback: onChange,
90
+ onSubmitCallback: onSubmit
91
+ });
92
+ delete props.onChange;
93
+ delete props.onSubmit;
82
94
  }
83
95
  // We check if there is any key pending to be changed to avoid updating the existing component
84
96
  if (!Object.keys(props).length) {
@@ -141,9 +153,11 @@ export function createReconciler(engine, pointerEvents) {
141
153
  function updateOnChange(entity, componentId, state) {
142
154
  const event = changeEvents.get(entity) || changeEvents.set(entity, new Map()).get(entity);
143
155
  const oldState = event.get(componentId);
144
- const fn = state?.fn;
156
+ const onChangeCallback = state?.onChangeCallback;
157
+ const onSubmitCallback = state?.onSubmitCallback;
145
158
  const value = state?.value ?? oldState?.value;
146
- event.set(componentId, { fn, value });
159
+ const isSubmit = state?.isSubmit ?? oldState?.isSubmit;
160
+ event.set(componentId, { onChangeCallback, onSubmitCallback, value, isSubmit });
147
161
  }
148
162
  const hostConfig = {
149
163
  ...noopConfig,
@@ -223,14 +237,19 @@ export function createReconciler(engine, pointerEvents) {
223
237
  function handleOnChange(componentId, resultComponent) {
224
238
  for (const [entity, Result] of engine.getEntitiesWith(resultComponent)) {
225
239
  const entityState = changeEvents.get(entity)?.get(componentId);
226
- if (entityState?.fn && Result.value !== entityState.value) {
227
- // Call onChange callback and update internal timestamp
228
- entityState.fn(Result.value);
229
- updateOnChange(entity, componentId, {
230
- fn: entityState.fn,
231
- value: Result.value
232
- });
240
+ const isSubmit = !!Result.isSubmit;
241
+ if (entityState?.onChangeCallback && Result.value !== entityState.value) {
242
+ entityState.onChangeCallback(Result.value);
243
+ }
244
+ if (entityState?.onSubmitCallback && isSubmit && !entityState.isSubmit) {
245
+ entityState.onSubmitCallback(Result.value);
233
246
  }
247
+ updateOnChange(entity, componentId, {
248
+ onChangeCallback: entityState?.onChangeCallback,
249
+ onSubmitCallback: entityState?.onSubmitCallback,
250
+ value: Result.value,
251
+ isSubmit
252
+ });
234
253
  }
235
254
  }
236
255
  return {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dcl/react-ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.3.27-6724658310.commit-6b8ca94",
4
+ "version": "7.3.27-6735610978.commit-0ffa614",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
7
7
  "dependencies": {
8
- "@dcl/ecs": "7.3.27-6724658310.commit-6b8ca94",
8
+ "@dcl/ecs": "7.3.27-6735610978.commit-0ffa614",
9
9
  "react": "^18.2.0",
10
10
  "react-reconciler": "^0.29.0"
11
11
  },
@@ -39,5 +39,5 @@
39
39
  "tsconfig": "./tsconfig.json"
40
40
  },
41
41
  "types": "./dist/index.d.ts",
42
- "commit": "6b8ca941a866869acd434e7d06f4e62da681b353"
42
+ "commit": "0ffa614e32c07bbd46dd506273ca4d80d05aa944"
43
43
  }