@wise/dynamic-flow-client 3.1.0 → 3.1.1

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/build/main.js CHANGED
@@ -10887,19 +10887,22 @@ var createButtonComponent = (buttonProps) => __spreadProps(__spreadValues({
10887
10887
  });
10888
10888
 
10889
10889
  // src/revamp/domain/mappers/layout/buttonLayoutToComponent.ts
10890
- var buttonLayoutToComponent = (uid, { action, context, control, disabled, margin = "md", pinOrder, size, title }, { onAction }) => createButtonComponent({
10891
- uid,
10892
- context: getButtonContext({ context, action }),
10893
- control: getButtonControl({ control, action }),
10894
- disabled: getButtonDisabled({ disabled, action }),
10895
- margin,
10896
- pinOrder,
10897
- size,
10898
- title: getButtonTitle({ title, action }),
10899
- onClick: () => {
10900
- void onAction(action);
10901
- }
10902
- });
10890
+ var buttonLayoutToComponent = (uid, { action, context, control, disabled, margin = "md", pinOrder, size, title }, { onAction, step }) => {
10891
+ const mergedAction = (action == null ? void 0 : action.$ref) ? __spreadValues(__spreadValues({}, getActionByReference(action.$ref, step == null ? void 0 : step.actions)), action) : action;
10892
+ return createButtonComponent({
10893
+ uid,
10894
+ context: getButtonContext({ context, action: mergedAction }),
10895
+ control: getButtonControl({ control, action: mergedAction }),
10896
+ disabled: getButtonDisabled({ disabled, action: mergedAction }),
10897
+ margin,
10898
+ pinOrder,
10899
+ size,
10900
+ title: getButtonTitle({ title, action: mergedAction }),
10901
+ onClick: () => {
10902
+ void onAction(mergedAction);
10903
+ }
10904
+ });
10905
+ };
10903
10906
  var getButtonTitle = ({ title, action }) => {
10904
10907
  var _a;
10905
10908
  return (_a = title != null ? title : action == null ? void 0 : action.title) != null ? _a : "";
@@ -10923,6 +10926,13 @@ var getButtonContext = ({ context, action }) => {
10923
10926
  }
10924
10927
  return (action == null ? void 0 : action.type) ? mapLegacyActionTypeToContext(action.type) : "neutral";
10925
10928
  };
10929
+ var getActionByReference = ($ref, actions = []) => {
10930
+ const action = actions.find((a) => a.$id === $ref);
10931
+ if (!action) {
10932
+ throw new Error("Action reference not found in actions array.");
10933
+ }
10934
+ return action;
10935
+ };
10926
10936
 
10927
10937
  // src/revamp/domain/components/ColumnsComponent.ts
10928
10938
  var createColumnsComponent = (columnsProps) => __spreadProps(__spreadValues({}, columnsProps), {
@@ -11060,6 +11070,7 @@ var getComponentPersistAsync = (update, performPersistAsync) => (
11060
11070
  }
11061
11071
  update((draft) => {
11062
11072
  draft.errors = [error.message];
11073
+ draft.persistedState.lastSubmitted = null;
11063
11074
  });
11064
11075
  throw error;
11065
11076
  }
@@ -11222,6 +11233,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
11222
11233
  if (performPersistAsync) {
11223
11234
  const persist = getComponentPersistAsync(update, performPersistAsync);
11224
11235
  return __spreadProps(__spreadValues({}, numberComponent), {
11236
+ isPersisted: true,
11225
11237
  onBlur() {
11226
11238
  if (this.validate()) {
11227
11239
  persist(this.persistedState, this.getLocalValue()).catch(() => {
@@ -11932,6 +11944,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
11932
11944
  if (performPersistAsync) {
11933
11945
  const persist = getComponentPersistAsync(update, performPersistAsync);
11934
11946
  return __spreadProps(__spreadValues({}, integerComponent), {
11947
+ isPersisted: true,
11935
11948
  onBlur() {
11936
11949
  if (this.validate()) {
11937
11950
  persist(this.persistedState, this.getLocalValue()).catch(() => {
@@ -11995,21 +12008,35 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
11995
12008
  };
11996
12009
 
11997
12010
  // src/revamp/domain/components/utils/isPartialLocalValueMatch.ts
11998
- var isPartialLocalValueMatch = (partialValue, value) => {
11999
- if (isArray2(partialValue) && isArray2(value)) {
12000
- return partialValue.every(
12001
- (_, index) => isPartialLocalValueMatch(partialValue[index], value[index])
12002
- );
12011
+ var isPartialLocalValueMatch = (partialValue, component) => {
12012
+ if (isArray2(partialValue) && component.type === "repeatable") {
12013
+ const children = component.getChildren();
12014
+ return partialValue.every((value, index) => {
12015
+ const childComponent = children[index];
12016
+ return childComponent ? isPartialLocalValueMatch(value, childComponent) : false;
12017
+ });
12003
12018
  }
12004
- if (isObjectLocalValue(partialValue) && isObjectLocalValue(value)) {
12005
- const allKeys = Array.from(/* @__PURE__ */ new Set([...Object.keys(partialValue), ...Object.keys(value)]));
12019
+ if (isObjectLocalValue(partialValue) && component.type === "object") {
12020
+ const allKeys = Array.from(
12021
+ /* @__PURE__ */ new Set([...Object.keys(partialValue), ...Object.keys(component.componentMap)])
12022
+ );
12006
12023
  const matchingKeys = allKeys.filter(
12007
- (key) => !isNullish3(partialValue[key]) && !isNullish3(value[key])
12024
+ (key) => !isNullish3(partialValue[key]) && !isNullish3(component.componentMap[key])
12025
+ );
12026
+ return matchingKeys.every(
12027
+ (key) => isPartialLocalValueMatch(partialValue[key], component.componentMap[key])
12008
12028
  );
12009
- return matchingKeys.every((key) => isPartialLocalValueMatch(partialValue[key], value[key]));
12010
12029
  }
12011
- return partialValue === value;
12030
+ const componentValue = component.getLocalValue();
12031
+ if (partialValue instanceof File && componentValue instanceof File) {
12032
+ return areEquivalentFiles(partialValue, componentValue);
12033
+ }
12034
+ if ("isPersisted" in component && component.isPersisted) {
12035
+ return true;
12036
+ }
12037
+ return partialValue === componentValue;
12012
12038
  };
12039
+ var areEquivalentFiles = (fileA, fileB) => fileA.name === fileB.name && fileA.type === fileB.type && fileA.size === fileB.size;
12013
12040
 
12014
12041
  // src/revamp/domain/components/SelectInputComponent.ts
12015
12042
  var createSelectInputComponent = (selectProps, updateComponent) => {
@@ -12031,9 +12058,10 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
12031
12058
  "summariser"
12032
12059
  ]);
12033
12060
  const children = options.map((option) => option.component);
12034
- const selectedIndex = options.findIndex(
12035
- (option) => isPartialLocalValueMatch(selectProps.initialValue, option.component.getLocalValue())
12061
+ const matchingOptions = options.map(
12062
+ (option) => isPartialLocalValueMatch(selectProps.initialValue, option.component)
12036
12063
  );
12064
+ const selectedIndex = matchingOptions.filter(isTrue).length === 1 ? matchingOptions.indexOf(true) : null;
12037
12065
  const update = getInputUpdateFunction(uid, updateComponent);
12038
12066
  const getValidationErrors = getLocalValueValidator(checks);
12039
12067
  const getAndSetValidationErrors = (currentValue) => {
@@ -12100,6 +12128,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
12100
12128
  }
12101
12129
  const persist = getComponentPersistAsync(update, performPersistAsync);
12102
12130
  return __spreadProps(__spreadValues({}, selectComponent), {
12131
+ isPersisted: true,
12103
12132
  onSelect(updatedIndex) {
12104
12133
  selectComponent.onSelect.call(this, updatedIndex);
12105
12134
  const isValid = getValidationErrors(this.getLocalValue()).length === 0;
@@ -12113,6 +12142,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
12113
12142
  }
12114
12143
  });
12115
12144
  };
12145
+ var isTrue = (value) => value;
12116
12146
 
12117
12147
  // src/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.ts
12118
12148
  var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
@@ -12245,6 +12275,7 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
12245
12275
  if (performPersistAsync) {
12246
12276
  const persist = getComponentPersistAsync(update, performPersistAsync);
12247
12277
  return __spreadProps(__spreadValues({}, dateInputComponent), {
12278
+ isPersisted: true,
12248
12279
  onChange(updatedValue) {
12249
12280
  dateInputComponent.onChange.call(this, updatedValue);
12250
12281
  const isValid = getValidationErrors(updatedValue).length === 0;
@@ -12394,6 +12425,7 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
12394
12425
  const persist = getComponentPersistAsync(update, performPersistAsync);
12395
12426
  return __spreadProps(__spreadValues({}, uploadComponent), {
12396
12427
  format,
12428
+ isPersisted: true,
12397
12429
  async onUpload(file) {
12398
12430
  update((draft) => {
12399
12431
  draft.errors = [];
@@ -12511,6 +12543,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
12511
12543
  if (performPersistAsync) {
12512
12544
  const persist = getComponentPersistAsync(update, performPersistAsync);
12513
12545
  return __spreadProps(__spreadValues({}, inputComponent), {
12546
+ isPersisted: true,
12514
12547
  onBlur() {
12515
12548
  if (this.validate()) {
12516
12549
  persist(this.persistedState, this.getLocalValue()).catch(() => {
@@ -12860,6 +12893,7 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
12860
12893
  const persist = getComponentMultiPersistAsync(update, performPersistAsync);
12861
12894
  return __spreadProps(__spreadValues({}, uploadComponent), {
12862
12895
  format,
12896
+ isPersisted: true,
12863
12897
  async onUpload(file, fileId) {
12864
12898
  await uploadComponent.onUpload.call(this, file, fileId);
12865
12899
  const submission = format === "blob" ? file : await toBase642(file);
@@ -13010,6 +13044,7 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
13010
13044
  if (performPersistAsync) {
13011
13045
  const persist = getComponentPersistAsync(update, performPersistAsync);
13012
13046
  return __spreadProps(__spreadValues({}, booleanComponent), {
13047
+ isPersisted: true,
13013
13048
  onChange(updatedValue) {
13014
13049
  booleanComponent.onChange.call(this, updatedValue);
13015
13050
  persist(this.persistedState, this.getLocalValue()).catch(() => {
@@ -13182,12 +13217,13 @@ var createFormComponent = (formProps) => __spreadProps(__spreadValues({}, formPr
13182
13217
  });
13183
13218
 
13184
13219
  // src/revamp/domain/mappers/layout/formLayoutToComponent.ts
13185
- var formLayoutToComponent = (uid, { schemaId, control, margin = "md" }, mapperProps) => {
13220
+ var formLayoutToComponent = (uid, { schemaId, schema: schemaRef, control, margin = "md" }, mapperProps) => {
13186
13221
  const { step, stepLocalValue } = mapperProps;
13187
13222
  const { model, errors, schemas } = step;
13188
- const schema = schemas.find((s) => s.$id === schemaId);
13223
+ const id = schemaId != null ? schemaId : schemaRef == null ? void 0 : schemaRef.$ref;
13224
+ const schema = schemas.find((s) => s.$id === id);
13189
13225
  if (!schema) {
13190
- throw new Error("Bad layout schemaId");
13226
+ throw new Error("Schema not found in schemas array.");
13191
13227
  }
13192
13228
  return createFormComponent({
13193
13229
  uid,
@@ -14579,7 +14615,7 @@ function DynamicFlowCore(props) {
14579
14615
  () => getRenderFunction([CoreContainerRenderer, ...renderers2, StepRenderer]),
14580
14616
  [renderers2]
14581
14617
  );
14582
- return /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(ErrorBoundary_default, { onError, children: step ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
14618
+ return /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(ErrorBoundary_default, { onError: closeWithError, children: step ? /* @__PURE__ */ (0, import_jsx_runtime121.jsx)(
14583
14619
  Step_default,
14584
14620
  {
14585
14621
  displayStepTitle,