@wise/dynamic-flow-client 3.19.6 → 3.20.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
@@ -7014,25 +7014,89 @@ var getActionByReference = ($ref, actions = []) => {
7014
7014
  };
7015
7015
 
7016
7016
  // src/revamp/domain/mappers/layout/buttonLayoutToComponent.ts
7017
- var buttonLayoutToComponent = (uid, button, { onAction, step }) => {
7017
+ var buttonLayoutToComponent = (uid, button, mapperProps) => {
7018
+ if (button.behavior) {
7019
+ return buttonLayoutToComponentWithBehavior(
7020
+ uid,
7021
+ __spreadProps(__spreadValues({}, button), { behavior: button.behavior }),
7022
+ mapperProps
7023
+ );
7024
+ }
7025
+ if (button.action) {
7026
+ return buttonLayoutToComponentWithAction(
7027
+ uid,
7028
+ __spreadProps(__spreadValues({}, button), { action: button.action }),
7029
+ mapperProps
7030
+ );
7031
+ }
7032
+ return buttonLayoutToComponentWithNoop(uid, button);
7033
+ };
7034
+ var buttonLayoutToComponentWithBehavior = (uid, button, mapperProps) => {
7035
+ const { onAction, onLink, step } = mapperProps;
7036
+ const { context, control, disabled, margin = "md", pinOrder, size, title, behavior } = button;
7037
+ const { action, link } = behavior;
7038
+ const inlinedAction = action ? inlineAction(action, step == null ? void 0 : step.actions) : null;
7039
+ const onClick = (() => {
7040
+ if (inlinedAction) {
7041
+ return () => {
7042
+ void onAction(inlinedAction);
7043
+ };
7044
+ }
7045
+ if (link) {
7046
+ return () => {
7047
+ onLink(link.url);
7048
+ };
7049
+ }
7050
+ return () => {
7051
+ };
7052
+ })();
7053
+ return createButtonComponent({
7054
+ uid,
7055
+ context: mapLegacyContext(context != null ? context : "neutral"),
7056
+ control,
7057
+ disabled: disabled != null ? disabled : false,
7058
+ margin,
7059
+ pinOrder,
7060
+ size,
7061
+ title: title != null ? title : "",
7062
+ onClick
7063
+ });
7064
+ };
7065
+ var buttonLayoutToComponentWithAction = (uid, button, mapperProps) => {
7066
+ const { onAction, step } = mapperProps;
7018
7067
  const { context, control, disabled, margin = "md", pinOrder, size, title } = button;
7019
- const action = button.action ? inlineAction(button.action, step == null ? void 0 : step.actions) : {};
7020
- const onClick = button.action ? () => {
7021
- void onAction(action);
7022
- } : () => {
7068
+ const { action } = button;
7069
+ const inlinedAction = action ? inlineAction(action, step == null ? void 0 : step.actions) : {};
7070
+ const onClick = () => {
7071
+ void onAction(inlinedAction);
7023
7072
  };
7024
7073
  return createButtonComponent({
7025
7074
  uid,
7026
- context: getButtonContext({ context, action }),
7027
- control: getButtonControl({ control, action }),
7028
- disabled: getButtonDisabled({ disabled, action }),
7075
+ context: getButtonContext({ context, action: inlinedAction }),
7076
+ control: getButtonControl({ control, action: inlinedAction }),
7077
+ disabled: getButtonDisabled({ disabled, action: inlinedAction }),
7029
7078
  margin,
7030
7079
  pinOrder,
7031
7080
  size,
7032
- title: getButtonTitle({ title, action }),
7081
+ title: getButtonTitle({ title, action: inlinedAction }),
7033
7082
  onClick
7034
7083
  });
7035
7084
  };
7085
+ var buttonLayoutToComponentWithNoop = (uid, button) => {
7086
+ const { context, control, disabled, margin = "md", pinOrder, size, title } = button;
7087
+ return createButtonComponent({
7088
+ uid,
7089
+ context: mapLegacyContext(context != null ? context : "neutral"),
7090
+ control,
7091
+ disabled: disabled != null ? disabled : false,
7092
+ margin,
7093
+ pinOrder,
7094
+ size,
7095
+ title: title != null ? title : "",
7096
+ onClick: () => {
7097
+ }
7098
+ });
7099
+ };
7036
7100
  var getButtonTitle = ({ title, action }) => {
7037
7101
  var _a;
7038
7102
  return (_a = title != null ? title : action == null ? void 0 : action.title) != null ? _a : "";
@@ -10731,6 +10795,7 @@ function useDynamicFlowCore(props) {
10731
10795
  const httpClient = useStableCallback(rest.httpClient);
10732
10796
  const onCompletion = useStableCallback(rest.onCompletion);
10733
10797
  const onValueChange = useStableCallback(props.onValueChange);
10798
+ const onLink = useStableCallback(props.onLink);
10734
10799
  const onError = useStableCallback(rest.onError);
10735
10800
  const onEvent = useStableCallback(rest.onEvent);
10736
10801
  const onLog = useStableCallback(rest.onLog);
@@ -10794,6 +10859,7 @@ function useDynamicFlowCore(props) {
10794
10859
  onAction,
10795
10860
  onRefresh,
10796
10861
  onPoll,
10862
+ onLink,
10797
10863
  onValueChange
10798
10864
  });
10799
10865
  setStepComponent(() => {
@@ -10972,14 +11038,7 @@ function DynamicFlowCore(props) {
10972
11038
  onEvent == null ? void 0 : onEvent("Dynamic Flow - Failed", { error });
10973
11039
  onError == null ? void 0 : onError(error);
10974
11040
  },
10975
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
10976
- "div",
10977
- {
10978
- id: (_b = (_a = stepComponentRef.current) == null ? void 0 : _a.step) == null ? void 0 : _b.id,
10979
- className: "dynamic-flow",
10980
- children: stepComponentRef.current ? render(stepComponentRef.current) : null
10981
- }
10982
- )
11041
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { id: (_b = (_a = stepComponentRef.current) == null ? void 0 : _a.step) == null ? void 0 : _b.id, className: "dynamic-flow", children: stepComponentRef.current ? render(stepComponentRef.current) : null })
10983
11042
  }
10984
11043
  );
10985
11044
  }
@@ -13039,13 +13098,24 @@ var getWiseRenderers = () => [
13039
13098
  StepRenderer
13040
13099
  ];
13041
13100
 
13101
+ // src/revamp/utils/openLinkInNewTab.tsx
13102
+ var openLinkInNewTab = (url) => {
13103
+ var _a;
13104
+ try {
13105
+ const w = (_a = window == null ? void 0 : window.open) == null ? void 0 : _a.call(window, url, "_blank");
13106
+ return Boolean(w);
13107
+ } catch (e) {
13108
+ return false;
13109
+ }
13110
+ };
13111
+
13042
13112
  // src/revamp/DynamicFlowWise.tsx
13043
13113
  var import_jsx_runtime59 = require("react/jsx-runtime");
13044
13114
  var wiseRenderers = getWiseRenderers();
13045
13115
  function DynamicFlowWise(props) {
13046
- const { httpClient, renderers } = props;
13116
+ const { httpClient, renderers, onLink = openLinkInNewTab } = props;
13047
13117
  const mergedRenderers = (0, import_react20.useMemo)(() => [...renderers != null ? renderers : [], ...wiseRenderers], [renderers]);
13048
- return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(RendererHttpClientProvider, { httpClient, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(DynamicFlowCore, __spreadProps(__spreadValues({}, props), { renderers: mergedRenderers })) });
13118
+ return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(RendererHttpClientProvider, { httpClient, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(DynamicFlowCore, __spreadProps(__spreadValues({}, props), { renderers: mergedRenderers, onLink })) });
13049
13119
  }
13050
13120
  var DynamicFlowWise_default = DynamicFlowWise;
13051
13121
 
@@ -13076,10 +13146,17 @@ var useHasHttpClientProvider = () => {
13076
13146
  var import_jsx_runtime61 = require("react/jsx-runtime");
13077
13147
  var wiseRenderers2 = getWiseRenderers();
13078
13148
  var DynamicFragmentWise = (0, import_react22.forwardRef)(function DynamicFragmentWise2(props, ref) {
13079
- const { httpClient, onCompletion = () => {
13080
- }, onEvent, onError, renderers } = props;
13149
+ const {
13150
+ httpClient,
13151
+ onCompletion = () => {
13152
+ },
13153
+ onEvent,
13154
+ onError,
13155
+ renderers,
13156
+ onLink = openLinkInNewTab
13157
+ } = props;
13081
13158
  const mergedRenderers = (0, import_react22.useMemo)(() => [...renderers != null ? renderers : [], ...wiseRenderers2], [renderers]);
13082
- const { stepComponentRef } = useDynamicFlowCore(__spreadValues({ onCompletion }, props));
13159
+ const { stepComponentRef } = useDynamicFlowCore(__spreadProps(__spreadValues({ onCompletion }, props), { onLink }));
13083
13160
  (0, import_react22.useImperativeHandle)(
13084
13161
  ref,
13085
13162
  () => ({
@@ -13117,8 +13194,8 @@ var import_react23 = require("react");
13117
13194
  var import_jsx_runtime62 = require("react/jsx-runtime");
13118
13195
  var DynamicFragmentCore = (0, import_react23.forwardRef)(function DynamicFragmentCore2(props, ref) {
13119
13196
  const { onCompletion = () => {
13120
- }, onEvent, onError, renderers } = props;
13121
- const { stepComponentRef } = useDynamicFlowCore(__spreadValues({ onCompletion }, props));
13197
+ }, onEvent, onError, onLink = openLinkInNewTab, renderers } = props;
13198
+ const { stepComponentRef } = useDynamicFlowCore(__spreadProps(__spreadValues({ onCompletion }, props), { onLink }));
13122
13199
  (0, import_react23.useImperativeHandle)(
13123
13200
  ref,
13124
13201
  () => ({