@wise/dynamic-flow-client 5.5.1 → 5.6.0

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
@@ -1337,9 +1337,10 @@ var createBoxComponent = (boxProps) => __spreadProps(__spreadValues({}, boxProps
1337
1337
  });
1338
1338
 
1339
1339
  // src/domain/mappers/utils/layout-utils.ts
1340
- var removeMarginFromLayout = (component) => {
1341
- return __spreadProps(__spreadValues({}, component), {
1342
- margin: "xs"
1340
+ var normaliseMarginInLastComponent = (container) => {
1341
+ return container.map((component, index) => {
1342
+ const shouldRemoveMargin = index === container.length - 1 && component.margin === void 0;
1343
+ return shouldRemoveMargin ? __spreadProps(__spreadValues({}, component), { margin: "xs" }) : component;
1343
1344
  });
1344
1345
  };
1345
1346
 
@@ -1352,16 +1353,9 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
1352
1353
  margin: margin != null ? margin : "md",
1353
1354
  width: width != null ? width : "xl",
1354
1355
  tags,
1355
- components: components.map((component, index) => {
1356
- const shouldRemoveMargin = index === components.length - 1 && component.margin === void 0;
1357
- const componentWithAdjustedMargin = shouldRemoveMargin ? removeMarginFromLayout(component) : component;
1358
- return mapLayoutToComponent(
1359
- `${uid}.box-${index}`,
1360
- componentWithAdjustedMargin,
1361
- mapperProps,
1362
- schemaComponents
1363
- );
1364
- })
1356
+ components: normaliseMarginInLastComponent(components).map(
1357
+ (component, index) => mapLayoutToComponent(`${uid}.box-${index}`, component, mapperProps, schemaComponents)
1358
+ )
1365
1359
  });
1366
1360
 
1367
1361
  // src/domain/components/ButtonComponent.ts
@@ -6091,7 +6085,6 @@ var mapStepToComponent = (_a) => {
6091
6085
  errors,
6092
6086
  external,
6093
6087
  key,
6094
- layout = [],
6095
6088
  navigation,
6096
6089
  polling,
6097
6090
  refreshAfter,
@@ -6132,21 +6125,12 @@ var mapStepToComponent = (_a) => {
6132
6125
  mapperProps,
6133
6126
  referencedSchemaIds
6134
6127
  );
6135
- const shouldPinButtons = features.isEnabled("pinnedButtons");
6136
- const { pinned, nonPinned } = shouldPinButtons ? groupLayoutByPinned(layout) : { pinned: [], nonPinned: layout };
6137
- const layoutComponents = nonPinned.map(
6128
+ const { layout, footer } = getLayoutAndFooter(step, features);
6129
+ const layoutComponents = layout.map(
6138
6130
  (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps, schemaComponents)
6139
6131
  );
6140
- const footerComponents = pinned.map((footerComponent, index) => {
6141
- const shouldRemoveMargin = index === pinned.length - 1 && footerComponent.margin === void 0;
6142
- return shouldRemoveMargin ? removeMarginFromLayout(footerComponent) : footerComponent;
6143
- }).map(
6144
- (footerComponent, index) => mapLayoutToComponent(
6145
- `${uid}.footer-${index}`,
6146
- footerComponent,
6147
- mapperProps,
6148
- schemaComponents
6149
- )
6132
+ const footerComponents = normaliseMarginInLastComponent(footer).map(
6133
+ (footerComponent, index) => mapLayoutToComponent(`${uid}.footer-${index}`, footerComponent, mapperProps, schemaComponents)
6150
6134
  );
6151
6135
  const toolbar = mapToolbarToComponent(uid, step.toolbar, mapperProps);
6152
6136
  const stepComponent = createStepComponent({
@@ -6218,6 +6202,19 @@ var executePrefetch = (props) => {
6218
6202
  }
6219
6203
  });
6220
6204
  };
6205
+ var getLayoutAndFooter = (step, features) => {
6206
+ var _a;
6207
+ if (step.footer) {
6208
+ const { layout: layout2 = [], footer = [] } = step;
6209
+ return { layout: layout2, footer };
6210
+ }
6211
+ if (features.isEnabled("pinnedButtons")) {
6212
+ const { pinned: footer, nonPinned: layout2 } = groupLayoutByPinned((_a = step.layout) != null ? _a : []);
6213
+ return { layout: layout2, footer };
6214
+ }
6215
+ const { layout = [] } = step;
6216
+ return { layout, footer: [] };
6217
+ };
6221
6218
 
6222
6219
  // src/getSubflowCallbacks.ts
6223
6220
  var getSubflowCallbacks = ({
@@ -6810,17 +6807,25 @@ var createFlowController = (props) => {
6810
6807
  return false;
6811
6808
  }
6812
6809
  };
6813
- trackEvent("Initiated");
6810
+ let isInitialised = false;
6814
6811
  if (initialStep) {
6812
+ isInitialised = true;
6813
+ trackEvent("Initiated");
6815
6814
  createStep(initialStep, null);
6816
6815
  trackEvent("Step Shown", { isFirstStep: true });
6817
- } else if (initialAction) {
6818
- rootComponent.setLoadingState("submitting");
6819
- void onAction(__spreadValues({ method: "GET" }, initialAction), null);
6820
6816
  }
6821
- rootComponent.start();
6817
+ const start = () => {
6818
+ if (!isInitialised && initialAction) {
6819
+ isInitialised = true;
6820
+ trackEvent("Initiated");
6821
+ rootComponent.setLoadingState("submitting");
6822
+ void onAction(__spreadValues({ method: "GET" }, initialAction), null);
6823
+ }
6824
+ rootComponent.start();
6825
+ };
6822
6826
  return {
6823
6827
  rootComponent,
6828
+ start,
6824
6829
  cancel: closeWithCancellation
6825
6830
  };
6826
6831
  };
@@ -8218,7 +8223,10 @@ var useRerender = () => {
8218
8223
  };
8219
8224
  var useFlowController = (props) => {
8220
8225
  const df = (0, import_react3.useMemo)(() => createFlowController(props), []);
8221
- (0, import_react3.useEffect)(() => () => df.rootComponent.stop(), []);
8226
+ (0, import_react3.useEffect)(() => {
8227
+ df.start();
8228
+ return () => df.rootComponent.stop();
8229
+ }, []);
8222
8230
  return df;
8223
8231
  };
8224
8232
 
package/build/main.mjs CHANGED
@@ -1307,9 +1307,10 @@ var createBoxComponent = (boxProps) => __spreadProps(__spreadValues({}, boxProps
1307
1307
  });
1308
1308
 
1309
1309
  // src/domain/mappers/utils/layout-utils.ts
1310
- var removeMarginFromLayout = (component) => {
1311
- return __spreadProps(__spreadValues({}, component), {
1312
- margin: "xs"
1310
+ var normaliseMarginInLastComponent = (container) => {
1311
+ return container.map((component, index) => {
1312
+ const shouldRemoveMargin = index === container.length - 1 && component.margin === void 0;
1313
+ return shouldRemoveMargin ? __spreadProps(__spreadValues({}, component), { margin: "xs" }) : component;
1313
1314
  });
1314
1315
  };
1315
1316
 
@@ -1322,16 +1323,9 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
1322
1323
  margin: margin != null ? margin : "md",
1323
1324
  width: width != null ? width : "xl",
1324
1325
  tags,
1325
- components: components.map((component, index) => {
1326
- const shouldRemoveMargin = index === components.length - 1 && component.margin === void 0;
1327
- const componentWithAdjustedMargin = shouldRemoveMargin ? removeMarginFromLayout(component) : component;
1328
- return mapLayoutToComponent(
1329
- `${uid}.box-${index}`,
1330
- componentWithAdjustedMargin,
1331
- mapperProps,
1332
- schemaComponents
1333
- );
1334
- })
1326
+ components: normaliseMarginInLastComponent(components).map(
1327
+ (component, index) => mapLayoutToComponent(`${uid}.box-${index}`, component, mapperProps, schemaComponents)
1328
+ )
1335
1329
  });
1336
1330
 
1337
1331
  // src/domain/components/ButtonComponent.ts
@@ -6061,7 +6055,6 @@ var mapStepToComponent = (_a) => {
6061
6055
  errors,
6062
6056
  external,
6063
6057
  key,
6064
- layout = [],
6065
6058
  navigation,
6066
6059
  polling,
6067
6060
  refreshAfter,
@@ -6102,21 +6095,12 @@ var mapStepToComponent = (_a) => {
6102
6095
  mapperProps,
6103
6096
  referencedSchemaIds
6104
6097
  );
6105
- const shouldPinButtons = features.isEnabled("pinnedButtons");
6106
- const { pinned, nonPinned } = shouldPinButtons ? groupLayoutByPinned(layout) : { pinned: [], nonPinned: layout };
6107
- const layoutComponents = nonPinned.map(
6098
+ const { layout, footer } = getLayoutAndFooter(step, features);
6099
+ const layoutComponents = layout.map(
6108
6100
  (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps, schemaComponents)
6109
6101
  );
6110
- const footerComponents = pinned.map((footerComponent, index) => {
6111
- const shouldRemoveMargin = index === pinned.length - 1 && footerComponent.margin === void 0;
6112
- return shouldRemoveMargin ? removeMarginFromLayout(footerComponent) : footerComponent;
6113
- }).map(
6114
- (footerComponent, index) => mapLayoutToComponent(
6115
- `${uid}.footer-${index}`,
6116
- footerComponent,
6117
- mapperProps,
6118
- schemaComponents
6119
- )
6102
+ const footerComponents = normaliseMarginInLastComponent(footer).map(
6103
+ (footerComponent, index) => mapLayoutToComponent(`${uid}.footer-${index}`, footerComponent, mapperProps, schemaComponents)
6120
6104
  );
6121
6105
  const toolbar = mapToolbarToComponent(uid, step.toolbar, mapperProps);
6122
6106
  const stepComponent = createStepComponent({
@@ -6188,6 +6172,19 @@ var executePrefetch = (props) => {
6188
6172
  }
6189
6173
  });
6190
6174
  };
6175
+ var getLayoutAndFooter = (step, features) => {
6176
+ var _a;
6177
+ if (step.footer) {
6178
+ const { layout: layout2 = [], footer = [] } = step;
6179
+ return { layout: layout2, footer };
6180
+ }
6181
+ if (features.isEnabled("pinnedButtons")) {
6182
+ const { pinned: footer, nonPinned: layout2 } = groupLayoutByPinned((_a = step.layout) != null ? _a : []);
6183
+ return { layout: layout2, footer };
6184
+ }
6185
+ const { layout = [] } = step;
6186
+ return { layout, footer: [] };
6187
+ };
6191
6188
 
6192
6189
  // src/getSubflowCallbacks.ts
6193
6190
  var getSubflowCallbacks = ({
@@ -6780,17 +6777,25 @@ var createFlowController = (props) => {
6780
6777
  return false;
6781
6778
  }
6782
6779
  };
6783
- trackEvent("Initiated");
6780
+ let isInitialised = false;
6784
6781
  if (initialStep) {
6782
+ isInitialised = true;
6783
+ trackEvent("Initiated");
6785
6784
  createStep(initialStep, null);
6786
6785
  trackEvent("Step Shown", { isFirstStep: true });
6787
- } else if (initialAction) {
6788
- rootComponent.setLoadingState("submitting");
6789
- void onAction(__spreadValues({ method: "GET" }, initialAction), null);
6790
6786
  }
6791
- rootComponent.start();
6787
+ const start = () => {
6788
+ if (!isInitialised && initialAction) {
6789
+ isInitialised = true;
6790
+ trackEvent("Initiated");
6791
+ rootComponent.setLoadingState("submitting");
6792
+ void onAction(__spreadValues({ method: "GET" }, initialAction), null);
6793
+ }
6794
+ rootComponent.start();
6795
+ };
6792
6796
  return {
6793
6797
  rootComponent,
6798
+ start,
6794
6799
  cancel: closeWithCancellation
6795
6800
  };
6796
6801
  };
@@ -8188,7 +8193,10 @@ var useRerender = () => {
8188
8193
  };
8189
8194
  var useFlowController = (props) => {
8190
8195
  const df = useMemo(() => createFlowController(props), []);
8191
- useEffect2(() => () => df.rootComponent.stop(), []);
8196
+ useEffect2(() => {
8197
+ df.start();
8198
+ return () => df.rootComponent.stop();
8199
+ }, []);
8192
8200
  return df;
8193
8201
  };
8194
8202
 
@@ -14,5 +14,6 @@ export type FlowControllerProps = Omit<DynamicFlowCoreProps, 'renderers' | 'feat
14
14
  };
15
15
  export declare const createFlowController: (props: FlowControllerProps) => {
16
16
  rootComponent: import("../domain/components/RootDomainComponent").RootDomainComponent;
17
+ start: () => void;
17
18
  cancel: () => void;
18
19
  };
@@ -1,2 +1,7 @@
1
1
  import type { Layout } from '@wise/dynamic-flow-types/spec';
2
- export declare const removeMarginFromLayout: (component: Layout) => Layout;
2
+ /**
3
+ * Normalizes the margin of the last layout component in the container by removing its margin if it is not explicitly set.
4
+ * @param container The array of layout components.
5
+ * @returns The array of layout components with the last component's margin normalized if needed.
6
+ */
7
+ export declare const normaliseMarginInLastComponent: (container: Layout[]) => Layout[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "description": "Dynamic Flow web client",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.js",
@@ -72,8 +72,8 @@
72
72
  "typescript": "5.9.3",
73
73
  "vitest": "4.0.18",
74
74
  "vitest-fetch-mock": "0.4.5",
75
- "@wise/dynamic-flow-fixtures": "0.0.1",
76
- "@wise/dynamic-flow-renderers": "0.0.0"
75
+ "@wise/dynamic-flow-renderers": "0.0.0",
76
+ "@wise/dynamic-flow-fixtures": "0.0.1"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@transferwise/components": "^46.104.0",
@@ -86,7 +86,7 @@
86
86
  "react-intl": "^6 || ^7"
87
87
  },
88
88
  "dependencies": {
89
- "@wise/dynamic-flow-types": "4.6.0"
89
+ "@wise/dynamic-flow-types": "4.7.0"
90
90
  },
91
91
  "scripts": {
92
92
  "dev": "EXCLUDE_VISUAL_TESTS=true pnpm storybook dev -p 3003",