@wise/dynamic-flow-client 4.9.0-exp-modal-renderer-d460e05 → 4.9.0-exp-modal-renderer-b16f932

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
@@ -3081,8 +3081,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
3081
3081
  }
3082
3082
  };
3083
3083
 
3084
- // src/revamp/domain/mappers/layout/modalToContent.ts
3085
- var modalToContent = (uid, { content, title }, mapperProps, schemaComponents) => createModalContentComponent(
3084
+ // src/revamp/domain/mappers/layout/modalToComponent.ts
3085
+ var modalToComponent = (uid, { content, title }, mapperProps, schemaComponents) => createModalContentComponent(
3086
3086
  {
3087
3087
  uid: `${uid}-modal-${getRandomId()}`,
3088
3088
  title,
@@ -6689,7 +6689,7 @@ function useDynamicFlowCore(props) {
6689
6689
  case "modal":
6690
6690
  if (stepRef.current) {
6691
6691
  rootComponentRef.current.showModal(
6692
- modalToContent(
6692
+ modalToComponent(
6693
6693
  rootComponentRef.current.uid,
6694
6694
  behavior,
6695
6695
  __spreadValues({
@@ -6952,663 +6952,359 @@ var DynamicFormCore = (0, import_react5.forwardRef)(function DynamicFormCore2(pr
6952
6952
  );
6953
6953
  });
6954
6954
 
6955
- // src/legacy/step/layoutStep/utils/layout-utils.ts
6956
- function convertStepToLayout(step, { displayStepTitle = true } = {}) {
6957
- if (step.layout) {
6958
- return addMissingTitleAndDescriptionToStep(step, displayStepTitle);
6959
- }
6960
- switch (step.type) {
6961
- case "final":
6962
- return convertFinalStepToDynamicLayout(step);
6963
- case "decision":
6964
- return convertDecisionStepToDynamicLayout(step);
6965
- case "external":
6966
- return convertExternalStepToDynamicLayout(step);
6967
- default:
6968
- return convertFormStepToDynamicLayout(step);
6969
- }
6955
+ // src/legacy/dynamicFlow/DynamicFlow.tsx
6956
+ var import_react49 = require("react");
6957
+ var import_react_intl39 = require("react-intl");
6958
+
6959
+ // src/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.tsx
6960
+ var import_react7 = require("react");
6961
+
6962
+ // src/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.ts
6963
+ var import_react6 = require("react");
6964
+ function usePendingPromiseCounter() {
6965
+ const [count, setCount] = (0, import_react6.useState)(0);
6966
+ const addPendingPromise = (0, import_react6.useCallback)(
6967
+ (promise) => {
6968
+ setCount((c) => c + 1);
6969
+ promise.catch(noop2).finally(() => delayUntilNextCycle(() => setCount((c) => Math.max(0, c - 1))));
6970
+ },
6971
+ [setCount]
6972
+ );
6973
+ return { addPendingPromise, pendingPromises: count };
6970
6974
  }
6971
- function convertCommonComponents(step) {
6972
- const layout = [];
6973
- if (step.title) {
6974
- layout.push(convertStepTitleToDynamicHeading(step.title));
6975
- }
6976
- if (step.image) {
6977
- const image = convertStepImageToDynamicImage(step.image);
6978
- layout.push(image);
6975
+ var delayUntilNextCycle = (fn) => setTimeout(() => fn(), 0);
6976
+ var noop2 = () => {
6977
+ };
6978
+
6979
+ // src/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.tsx
6980
+ var import_jsx_runtime8 = require("react/jsx-runtime");
6981
+ var defaultContextValue = {
6982
+ loading: false,
6983
+ registerPersistAsyncPromise: (promise) => {
6979
6984
  }
6980
- if (step.description) {
6981
- layout.push(convertStepDescriptionToDynamicParagraph(step.description));
6985
+ };
6986
+ var DFContext = (0, import_react7.createContext)(defaultContextValue);
6987
+ var DynamicFlowProvider = ({ loading, children }) => {
6988
+ const { pendingPromises, addPendingPromise } = usePendingPromiseCounter();
6989
+ const providerValue = (0, import_react7.useMemo)(() => {
6990
+ return {
6991
+ loading: loading || pendingPromises > 0,
6992
+ registerPersistAsyncPromise: addPendingPromise
6993
+ };
6994
+ }, [loading, pendingPromises, addPendingPromise]);
6995
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DFContext.Provider, { value: providerValue, children });
6996
+ };
6997
+ var useDynamicFlow = () => {
6998
+ const context = (0, import_react7.useContext)(DFContext);
6999
+ return context || defaultContextValue;
7000
+ };
7001
+
7002
+ // src/legacy/common/contexts/eventsContext/EventsContext.tsx
7003
+ var import_react8 = require("react");
7004
+ var import_jsx_runtime9 = require("react/jsx-runtime");
7005
+ var EventsContext = (0, import_react8.createContext)({
7006
+ triggerEvent: () => {
6982
7007
  }
6983
- return layout;
6984
- }
6985
- function convertExternalStepToDynamicLayout(step) {
6986
- return [...convertCommonComponents(step), convertStepToExternalComponent(step)];
7008
+ });
7009
+ function EventsContextProvider({ metadata, children, onEvent }) {
7010
+ const value = (0, import_react8.useMemo)(
7011
+ () => ({ triggerEvent: getEventDispatcher(onEvent, metadata) }),
7012
+ [onEvent, metadata]
7013
+ );
7014
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EventsContext.Provider, { value, children });
6987
7015
  }
6988
- function convertStepToExternalComponent(step) {
6989
- return {
6990
- type: "external",
6991
- requestUrl: step.requestUrl,
6992
- polling: step.polling,
6993
- responseHandlers: step.responseHandlers,
6994
- retryTitle: step.retryTitle
6995
- };
7016
+ function useEventDispatcher() {
7017
+ const { triggerEvent } = (0, import_react8.useContext)(EventsContext);
7018
+ return triggerEvent;
6996
7019
  }
6997
- function convertFormStepToDynamicLayout(step) {
6998
- const layout = convertCommonComponents(step);
6999
- if (step.reviewFields) {
7000
- layout.push(convertStepReviewToDynamicReview(step.reviewFields));
7001
- }
7002
- if (step.schemas) {
7003
- layout.push(...getSchemaLayout(step));
7020
+ var getEventDispatcher = (onEvent, metadata) => (eventName, properties = {}) => {
7021
+ try {
7022
+ onEvent(eventName, __spreadValues(__spreadValues({}, metadata), properties));
7023
+ } catch (e) {
7004
7024
  }
7005
- if (step.actions) {
7006
- const actions = step.actions.map(convertStepActionToDynamicAction);
7007
- layout.push(dynamicBox(actions, "md"));
7025
+ };
7026
+
7027
+ // src/legacy/common/contexts/logContext/LogContext.tsx
7028
+ var import_react9 = require("react");
7029
+ var import_jsx_runtime10 = require("react/jsx-runtime");
7030
+ var getLogger = (level, onLog, flowId = "UNKNOWN-FLOW-ID", stepId = "UNKNOWN-FLOW-ID") => (title, description, extra) => {
7031
+ try {
7032
+ onLog(level, `Dynamic Flow ${level} - ${title} - ${description}`, __spreadValues({
7033
+ flowId,
7034
+ stepId
7035
+ }, extra));
7036
+ } catch (e) {
7008
7037
  }
7009
- return layout;
7038
+ };
7039
+ var LogContext = (0, import_react9.createContext)(null);
7040
+ function LogProvider({ flowId, stepId, children, onLog }) {
7041
+ const value = (0, import_react9.useMemo)(
7042
+ () => ({
7043
+ debug: getLogger("debug", onLog, flowId, stepId),
7044
+ info: getLogger("info", onLog, flowId, stepId),
7045
+ warning: getLogger("warning", onLog, flowId, stepId),
7046
+ error: getLogger("error", onLog, flowId, stepId),
7047
+ critical: getLogger("critical", onLog, flowId, stepId)
7048
+ }),
7049
+ [onLog, flowId, stepId]
7050
+ );
7051
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LogContext.Provider, { value, children });
7010
7052
  }
7011
- function convertFinalStepToDynamicLayout(step) {
7012
- const layout = [];
7013
- if (step.details) {
7014
- if (step.details.image) {
7015
- const image = convertFinalStepImageToDynamicImage(step.details.image);
7016
- layout.push(image);
7017
- }
7018
- if (step.details.title) {
7019
- layout.push(convertStepTitleToDynamicHeading(step.details.title));
7020
- }
7021
- if (step.details.description) {
7022
- layout.push(convertStepDescriptionToDynamicParagraph(step.details.description));
7023
- }
7024
- }
7025
- if (step.actions) {
7026
- const actions = step.actions.map(
7027
- (action) => convertStepActionToDynamicAction(__spreadProps(__spreadValues({}, action), { type: action.type || "primary" }))
7053
+ var useLogger = () => {
7054
+ const logging = (0, import_react9.useContext)(LogContext);
7055
+ if (logging == null) {
7056
+ throw new Error(
7057
+ "Logging context not found. Did you forget to wrap your component in a <LogProvider />?"
7028
7058
  );
7029
- layout.push(dynamicBox(actions, "md"));
7030
7059
  }
7031
- return layout;
7032
- }
7033
- function convertDecisionStepToDynamicLayout(step) {
7034
- const layout = convertCommonComponents(step);
7035
- if (step.options) {
7036
- layout.push(convertStepDecisionToDynamicDecision(step.options));
7060
+ return logging;
7061
+ };
7062
+
7063
+ // src/common/cameraCapture/utils/mobile-utils.ts
7064
+ var isMobile = () => isMobileScreenSize() && (isTouchScreen() || isMobileUA());
7065
+ var isMobileUA = (userAgent = window.navigator.userAgent) => (
7066
+ // eslint-disable-next-line regexp/no-unused-capturing-group
7067
+ /mobi|\b(iphone|android|blackberry|webos|windows phone)\b/i.test(userAgent)
7068
+ );
7069
+ var isMobileScreenSize = (width = window.screen.width, height = window.screen.height) => width < 768 || height < 768;
7070
+ var isTouchScreen = (navigator2 = window.navigator, matchMedia = window.matchMedia) => {
7071
+ if ("maxTouchPoints" in navigator2) {
7072
+ return navigator2.maxTouchPoints > 0;
7037
7073
  }
7038
- return layout;
7039
- }
7040
- function dynamicBox(components, size) {
7041
- return {
7042
- type: "box",
7043
- width: size || "md",
7044
- components
7045
- };
7046
- }
7047
- function convertStepTitleToDynamicHeading(title) {
7048
- return {
7049
- type: "heading",
7050
- text: title,
7051
- size: "lg",
7052
- margin: "lg",
7053
- align: "center"
7074
+ const mQ = matchMedia == null ? void 0 : matchMedia("(pointer:coarse)");
7075
+ if ((mQ == null ? void 0 : mQ.media) === "(pointer:coarse)") {
7076
+ return Boolean(mQ.matches);
7077
+ }
7078
+ return false;
7079
+ };
7080
+
7081
+ // src/common/utils/debounce.ts
7082
+ var debounce2 = (callback, waitMs) => {
7083
+ let timeoutId = null;
7084
+ let lastArgs = null;
7085
+ const clearTimer = () => {
7086
+ if (timeoutId) {
7087
+ clearTimeout(timeoutId);
7088
+ timeoutId = null;
7089
+ }
7090
+ lastArgs = null;
7054
7091
  };
7055
- }
7056
- function convertStepDescriptionToDynamicParagraph(description) {
7057
- return {
7058
- type: "paragraph",
7059
- text: description,
7060
- align: "center"
7092
+ const debouncedFn = (...args) => {
7093
+ lastArgs = args;
7094
+ if (timeoutId !== null) {
7095
+ clearTimeout(timeoutId);
7096
+ }
7097
+ timeoutId = setTimeout(() => {
7098
+ callback(...lastArgs);
7099
+ timeoutId = null;
7100
+ lastArgs = null;
7101
+ }, waitMs);
7061
7102
  };
7062
- }
7063
- function convertStepSchemaToDynamicForm(schema) {
7064
- return { type: "form", schema };
7065
- }
7066
- function convertStepDecisionToDynamicDecision(options) {
7067
- return {
7068
- type: "decision",
7069
- options: options.map(convertStepDecisionOption)
7103
+ debouncedFn.cancel = () => {
7104
+ if (timeoutId !== null) {
7105
+ clearTimer();
7106
+ }
7070
7107
  };
7071
- }
7072
- function convertStepDecisionOption(option) {
7073
- return {
7074
- title: option.title,
7075
- description: option.description,
7076
- action: {
7077
- title: option.title,
7078
- method: "GET",
7079
- url: option.url,
7080
- disabled: option.disabled
7108
+ debouncedFn.flush = () => {
7109
+ if (timeoutId !== null) {
7110
+ callback(...lastArgs);
7111
+ clearTimer();
7081
7112
  }
7082
7113
  };
7114
+ debouncedFn.isPending = () => timeoutId !== null;
7115
+ return debouncedFn;
7116
+ };
7117
+
7118
+ // src/legacy/common/utils/api-utils.ts
7119
+ function isStatus2xx(status) {
7120
+ return status >= 200 && status < 300;
7083
7121
  }
7084
- function convertStepImageToDynamicImage(image) {
7085
- return {
7086
- type: "image",
7087
- url: image.url,
7088
- text: image.text,
7089
- margin: image.margin || "lg",
7090
- size: image.size || "md"
7091
- };
7092
- }
7093
- function convertFinalStepImageToDynamicImage(image) {
7094
- return typeof image === "string" ? {
7095
- type: "image",
7096
- url: image,
7097
- text: void 0,
7098
- margin: "lg",
7099
- size: "md"
7100
- } : convertStepImageToDynamicImage(image);
7101
- }
7102
- function convertStepActionToDynamicAction(action) {
7103
- const newAction = __spreadProps(__spreadValues({}, action), { title: action.title });
7104
- return {
7105
- type: "button",
7106
- action: newAction
7107
- };
7108
- }
7109
- function convertStepReviewToDynamicReview(reviewFields) {
7110
- return {
7111
- type: "review",
7112
- title: reviewFields.title,
7113
- fields: reviewFields.fields.map(convertReviewFieldToDefinition)
7114
- };
7122
+
7123
+ // src/legacy/common/validators/types/type-validators.ts
7124
+ var isString2 = (value) => typeof value === "string";
7125
+ var isNumber2 = (value) => typeof value === "number" && !Number.isNaN(value);
7126
+ var isInteger2 = (value) => {
7127
+ return isNumber2(value) && Math.floor(value) === value;
7128
+ };
7129
+ var isBoolean2 = (value) => typeof value === "boolean";
7130
+ var isObject2 = (value) => !isNull2(value) && !isUndefined2(value) && (value == null ? void 0 : value.constructor) === Object;
7131
+ var isArray2 = (value) => Array.isArray(value);
7132
+ var isNull2 = (value) => value === null;
7133
+ var isUndefined2 = (value) => typeof value === "undefined";
7134
+
7135
+ // src/legacy/common/validators/values/value-validators.ts
7136
+ var isEmpty = (value) => isString2(value) && value.length === 0 || (isObject2(value) || isArray2(value)) && Object.keys(value).length === 0;
7137
+
7138
+ // src/legacy/common/validators/models/model-utils.ts
7139
+ function cleanBasicModelWithOneOfSchema(model, schema) {
7140
+ return schema.oneOf.some(
7141
+ (nestedSchema) => getValidBasicModelOrNull(model, nestedSchema) === model
7142
+ ) ? model : null;
7115
7143
  }
7116
- function convertReviewFieldToDefinition(reviewField) {
7117
- return {
7118
- label: reviewField.title,
7119
- value: reviewField.value
7120
- };
7144
+ function cleanArrayModelWithOneOfSchema(model, schema) {
7145
+ var _a;
7146
+ const validModels = schema.oneOf.map((nestedSchema) => getValidArrayModelOrNull(model, nestedSchema)).filter((item) => item !== null);
7147
+ if (validModels.length === 0) {
7148
+ return null;
7149
+ }
7150
+ return (_a = validModels.find((model2) => model2.some((item) => item !== null))) != null ? _a : validModels[0];
7121
7151
  }
7122
- function getSchemaLayout(step) {
7123
- const layout = [];
7124
- if (step.schemas && step.schemas[0]) {
7125
- const schema = step.schemas[0];
7126
- const dynamicForm = convertStepSchemaToDynamicForm(schema);
7127
- if (isWideForm()) {
7128
- layout.push(dynamicForm);
7129
- } else {
7130
- layout.push(dynamicBox([dynamicForm], "md"));
7131
- }
7152
+ function getValidArrayModelOrNull(model, schema) {
7153
+ if (!isArraySchema2(schema)) {
7154
+ return null;
7132
7155
  }
7133
- return layout;
7156
+ if (!isListArraySchema(schema)) {
7157
+ return null;
7158
+ }
7159
+ return cleanModelWithArraySchema(model, schema);
7134
7160
  }
7135
- function isWideForm() {
7136
- return false;
7161
+ function cleanModelWithStringSchema(model) {
7162
+ return isString2(model) && !isEmpty(model) ? model : null;
7137
7163
  }
7138
- function addMissingTitleAndDescriptionToStep(step, displayStepTitle) {
7139
- return [
7140
- ...displayStepTitle && step.title ? [convertStepTitleToDynamicHeading(step.title)] : [],
7141
- ...step.description ? [convertStepDescriptionToDynamicParagraph(step.description)] : [],
7142
- ...step.layout || []
7143
- ];
7164
+ function cleanModelWithNumberSchema(model) {
7165
+ return isNumber2(model) ? model : null;
7144
7166
  }
7145
-
7146
- // src/legacy/step/layoutStep/utils/inline-reference-utils.ts
7147
- function inlineReferences({
7148
- layout,
7149
- schemas,
7150
- actions,
7151
- model
7152
- }) {
7153
- if (!layout) {
7154
- return [];
7167
+ function cleanModelWithBooleanSchema(model) {
7168
+ return isBoolean2(model) ? model : null;
7169
+ }
7170
+ function cleanModelWithArraySchema(model, schema) {
7171
+ if (!isArray2(model)) {
7172
+ return null;
7155
7173
  }
7156
- if (!schemas) {
7157
- return layout;
7174
+ if (!isListArraySchema(schema)) {
7175
+ return null;
7158
7176
  }
7159
- return layout.map((component) => {
7160
- if (component.type === "form") {
7161
- return inlineFormSchema({ formComponent: component, schemas });
7177
+ if (model.length > 0) {
7178
+ const expectedType = typeof model[0];
7179
+ if (!model.every((item) => typeof item === expectedType)) {
7180
+ return new Array(model.length).fill(null);
7162
7181
  }
7163
- if (component.type === "decision") {
7164
- return inlineDecisionActions({ decisionComponent: component, actions });
7182
+ }
7183
+ return model.map((childModel) => getValidModelParts(childModel, schema.items));
7184
+ }
7185
+ function cleanObjectModelWithObjectSchema(model, schema) {
7186
+ return Object.keys(schema.properties).reduce((cleanedModel, property) => {
7187
+ if (model && !isUndefined2(model[property])) {
7188
+ const subModel = model[property];
7189
+ const subSchema = schema.properties[property];
7190
+ const newValue = getValidModelParts(subModel, subSchema);
7191
+ if (!isNull2(newValue)) {
7192
+ return __spreadProps(__spreadValues({}, cleanedModel), { [property]: newValue });
7193
+ }
7165
7194
  }
7166
- if (component.type === "button") {
7167
- return inlineAction2({ actionComponent: component, actions });
7195
+ return cleanedModel;
7196
+ }, {});
7197
+ }
7198
+ function cleanObjectModelWithAllOfSchema(model, schema) {
7199
+ return schema.allOf.reduce((cleanObjectModel, nestedSchema) => {
7200
+ const validSubsetOfModel = getValidObjectModelParts(model, nestedSchema);
7201
+ if (isObjectModel2(validSubsetOfModel)) {
7202
+ return __spreadValues(__spreadValues({}, cleanObjectModel), validSubsetOfModel);
7168
7203
  }
7169
- if (component.type === "box") {
7170
- return __spreadProps(__spreadValues({}, component), {
7171
- components: inlineReferences({ layout: component.components, schemas, actions, model })
7172
- });
7204
+ return cleanObjectModel;
7205
+ }, {});
7206
+ }
7207
+ function cleanObjectModelWithOneOfSchema(model, schema) {
7208
+ return schema.oneOf.map((nestedSchema) => getValidObjectModelParts(model, nestedSchema)).reduce((combined, current) => {
7209
+ if (isNull2(combined)) {
7210
+ return current;
7173
7211
  }
7174
- if (component.type === "modal") {
7175
- return __spreadProps(__spreadValues({}, component), {
7176
- components: inlineReferences({
7177
- layout: component.content.components,
7178
- schemas,
7179
- actions,
7180
- model
7181
- })
7182
- });
7212
+ if (isObjectModel2(combined) && isObjectModel2(current)) {
7213
+ return deepMergeObject(combined, current);
7183
7214
  }
7184
- if (component.type === "columns") {
7185
- return __spreadProps(__spreadValues({}, component), {
7186
- left: inlineReferences({ layout: component.left, schemas, actions, model }),
7187
- right: inlineReferences({ layout: component.right, schemas, actions, model })
7188
- });
7215
+ if (isNull2(current)) {
7216
+ return combined;
7189
7217
  }
7190
- return component;
7191
- });
7192
- }
7193
- function inlineFormSchema({
7194
- formComponent,
7195
- schemas
7196
- }) {
7197
- if (formComponent.schemaId) {
7198
- return {
7199
- type: "form",
7200
- margin: formComponent.margin,
7201
- schema: getSchemaById(schemas, formComponent.schemaId)
7202
- };
7203
- }
7204
- if (formComponent.schema && isReference(formComponent.schema) && formComponent.schema.$ref) {
7205
- return {
7206
- type: "form",
7207
- margin: formComponent.margin,
7208
- schema: getSchemaById(schemas, formComponent.schema.$ref)
7209
- };
7210
- }
7211
- if (formComponent.schema && !isReference(formComponent.schema)) {
7212
- return __spreadValues({}, formComponent);
7213
- }
7214
- throw new Error('Invalid form layout component. Missing "schema" or "schemaId" properties.');
7218
+ return current;
7219
+ }, null);
7215
7220
  }
7216
- function inlineDecisionActions({
7217
- decisionComponent,
7218
- actions
7219
- }) {
7220
- var _a;
7221
- const newOptions = (_a = decisionComponent == null ? void 0 : decisionComponent.options) == null ? void 0 : _a.map(
7222
- (option) => option.action && isReference(option.action) ? __spreadProps(__spreadValues({}, option), {
7223
- action: getActionById(actions, option.action.$ref)
7224
- }) : option
7221
+ function deepMergeObject(object1, object2) {
7222
+ return Object.keys(object2).reduce(
7223
+ (acc, property) => {
7224
+ const object1Property = object1[property];
7225
+ const object2Property = object2[property];
7226
+ if (isObjectModel2(object1Property) && isObjectModel2(object2Property)) {
7227
+ return __spreadProps(__spreadValues({}, acc), {
7228
+ [property]: deepMergeObject(object1Property, object2Property)
7229
+ });
7230
+ }
7231
+ return __spreadProps(__spreadValues({}, acc), {
7232
+ [property]: object2[property]
7233
+ });
7234
+ },
7235
+ __spreadValues({}, object1)
7225
7236
  );
7226
- return __spreadProps(__spreadValues({}, decisionComponent), {
7227
- options: newOptions
7228
- });
7229
7237
  }
7230
- function inlineAction2({
7231
- actionComponent,
7232
- actions
7233
- }) {
7234
- var _a;
7235
- if (actionComponent.action && isReference(actionComponent.action) && ((_a = actionComponent.action) == null ? void 0 : _a.$ref)) {
7236
- const newAction = getActionById(actions, actionComponent.action.$ref);
7237
- return convertStepActionToDynamicAction(newAction);
7238
+
7239
+ // src/legacy/common/validators/models/model-validators.ts
7240
+ var getValidModelParts = (model, schema) => {
7241
+ if (isObjectModel2(model)) {
7242
+ return getValidObjectModelParts(model, schema);
7238
7243
  }
7239
- return actionComponent;
7240
- }
7241
- function getSchemaById(schemas, id) {
7242
- const schema = schemas.find((schema2) => schema2.$id === id);
7243
- if (!schema) {
7244
- throw new Error(`Fatal Error. Schema not found. $id ${id}`);
7244
+ if (isArrayModel2(model)) {
7245
+ return getValidArrayModelParts(model, schema);
7245
7246
  }
7246
- return schema;
7247
- }
7248
- function getActionById(actions, id) {
7249
- const action = actions.find((action2) => action2.$id === id);
7250
- if (!action) {
7251
- throw new Error(`Fatal Error. Action not found. $id ${id}`);
7252
- }
7253
- return action;
7254
- }
7255
- function isReference(block) {
7256
- return Object.hasOwnProperty.call(block, "$ref");
7257
- }
7258
-
7259
- // src/legacy/dynamicFlow/DynamicFlow.tsx
7260
- var import_react49 = require("react");
7261
- var import_react_intl39 = require("react-intl");
7262
-
7263
- // src/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.tsx
7264
- var import_react7 = require("react");
7265
-
7266
- // src/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.ts
7267
- var import_react6 = require("react");
7268
- function usePendingPromiseCounter() {
7269
- const [count, setCount] = (0, import_react6.useState)(0);
7270
- const addPendingPromise = (0, import_react6.useCallback)(
7271
- (promise) => {
7272
- setCount((c) => c + 1);
7273
- promise.catch(noop2).finally(() => delayUntilNextCycle(() => setCount((c) => Math.max(0, c - 1))));
7274
- },
7275
- [setCount]
7276
- );
7277
- return { addPendingPromise, pendingPromises: count };
7278
- }
7279
- var delayUntilNextCycle = (fn) => setTimeout(() => fn(), 0);
7280
- var noop2 = () => {
7247
+ return getValidBasicModelOrNull(model, schema);
7281
7248
  };
7282
-
7283
- // src/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.tsx
7284
- var import_jsx_runtime8 = require("react/jsx-runtime");
7285
- var defaultContextValue = {
7286
- loading: false,
7287
- registerPersistAsyncPromise: (promise) => {
7249
+ function getValidBasicModelOrNull(model, schema) {
7250
+ if (isNull2(model)) {
7251
+ return null;
7288
7252
  }
7289
- };
7290
- var DFContext = (0, import_react7.createContext)(defaultContextValue);
7291
- var DynamicFlowProvider = ({ loading, children }) => {
7292
- const { pendingPromises, addPendingPromise } = usePendingPromiseCounter();
7293
- const providerValue = (0, import_react7.useMemo)(() => {
7294
- return {
7295
- loading: loading || pendingPromises > 0,
7296
- registerPersistAsyncPromise: addPendingPromise
7297
- };
7298
- }, [loading, pendingPromises, addPendingPromise]);
7299
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DFContext.Provider, { value: providerValue, children });
7300
- };
7301
- var useDynamicFlow = () => {
7302
- const context = (0, import_react7.useContext)(DFContext);
7303
- return context || defaultContextValue;
7304
- };
7305
-
7306
- // src/legacy/common/contexts/eventsContext/EventsContext.tsx
7307
- var import_react8 = require("react");
7308
- var import_jsx_runtime9 = require("react/jsx-runtime");
7309
- var EventsContext = (0, import_react8.createContext)({
7310
- triggerEvent: () => {
7253
+ if (schema.oneOf) {
7254
+ return cleanBasicModelWithOneOfSchema(model, schema);
7311
7255
  }
7312
- });
7313
- function EventsContextProvider({ metadata, children, onEvent }) {
7314
- const value = (0, import_react8.useMemo)(
7315
- () => ({ triggerEvent: getEventDispatcher(onEvent, metadata) }),
7316
- [onEvent, metadata]
7317
- );
7318
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EventsContext.Provider, { value, children });
7319
- }
7320
- function useEventDispatcher() {
7321
- const { triggerEvent } = (0, import_react8.useContext)(EventsContext);
7322
- return triggerEvent;
7323
- }
7324
- var getEventDispatcher = (onEvent, metadata) => (eventName, properties = {}) => {
7325
- try {
7326
- onEvent(eventName, __spreadValues(__spreadValues({}, metadata), properties));
7327
- } catch (e) {
7256
+ if (!isUndefined2(schema.const) && model === schema.const) {
7257
+ return model;
7328
7258
  }
7329
- };
7330
-
7331
- // src/legacy/common/contexts/logContext/LogContext.tsx
7332
- var import_react9 = require("react");
7333
- var import_jsx_runtime10 = require("react/jsx-runtime");
7334
- var getLogger = (level, onLog, flowId = "UNKNOWN-FLOW-ID", stepId = "UNKNOWN-FLOW-ID") => (title, description, extra) => {
7335
- try {
7336
- onLog(level, `Dynamic Flow ${level} - ${title} - ${description}`, __spreadValues({
7337
- flowId,
7338
- stepId
7339
- }, extra));
7340
- } catch (e) {
7259
+ if (schema.type) {
7260
+ switch (schema.type) {
7261
+ case "string":
7262
+ return cleanModelWithStringSchema(model);
7263
+ case "number":
7264
+ case "integer":
7265
+ return cleanModelWithNumberSchema(model);
7266
+ case "boolean":
7267
+ return cleanModelWithBooleanSchema(model);
7268
+ default:
7269
+ return null;
7270
+ }
7341
7271
  }
7342
- };
7343
- var LogContext = (0, import_react9.createContext)(null);
7344
- function LogProvider({ flowId, stepId, children, onLog }) {
7345
- const value = (0, import_react9.useMemo)(
7346
- () => ({
7347
- debug: getLogger("debug", onLog, flowId, stepId),
7348
- info: getLogger("info", onLog, flowId, stepId),
7349
- warning: getLogger("warning", onLog, flowId, stepId),
7350
- error: getLogger("error", onLog, flowId, stepId),
7351
- critical: getLogger("critical", onLog, flowId, stepId)
7352
- }),
7353
- [onLog, flowId, stepId]
7354
- );
7355
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LogContext.Provider, { value, children });
7272
+ return null;
7356
7273
  }
7357
- var useLogger = () => {
7358
- const logging = (0, import_react9.useContext)(LogContext);
7359
- if (logging == null) {
7360
- throw new Error(
7361
- "Logging context not found. Did you forget to wrap your component in a <LogProvider />?"
7362
- );
7274
+ function getValidObjectModelParts(model, schema) {
7275
+ if (isBasicSchema(schema) || isArraySchema2(schema) || isNull2(model)) {
7276
+ return null;
7363
7277
  }
7364
- return logging;
7365
- };
7366
-
7367
- // src/common/cameraCapture/utils/mobile-utils.ts
7368
- var isMobile = () => isMobileScreenSize() && (isTouchScreen() || isMobileUA());
7369
- var isMobileUA = (userAgent = window.navigator.userAgent) => (
7370
- // eslint-disable-next-line regexp/no-unused-capturing-group
7371
- /mobi|\b(iphone|android|blackberry|webos|windows phone)\b/i.test(userAgent)
7372
- );
7373
- var isMobileScreenSize = (width = window.screen.width, height = window.screen.height) => width < 768 || height < 768;
7374
- var isTouchScreen = (navigator2 = window.navigator, matchMedia = window.matchMedia) => {
7375
- if ("maxTouchPoints" in navigator2) {
7376
- return navigator2.maxTouchPoints > 0;
7278
+ if (schema.allOf) {
7279
+ return cleanObjectModelWithAllOfSchema(model, schema);
7377
7280
  }
7378
- const mQ = matchMedia == null ? void 0 : matchMedia("(pointer:coarse)");
7379
- if ((mQ == null ? void 0 : mQ.media) === "(pointer:coarse)") {
7380
- return Boolean(mQ.matches);
7281
+ if (schema.oneOf) {
7282
+ return cleanObjectModelWithOneOfSchema(model, schema);
7381
7283
  }
7382
- return false;
7383
- };
7384
-
7385
- // src/common/utils/debounce.ts
7386
- var debounce2 = (callback, waitMs) => {
7387
- let timeoutId = null;
7388
- let lastArgs = null;
7389
- const clearTimer = () => {
7390
- if (timeoutId) {
7391
- clearTimeout(timeoutId);
7392
- timeoutId = null;
7393
- }
7394
- lastArgs = null;
7395
- };
7396
- const debouncedFn = (...args) => {
7397
- lastArgs = args;
7398
- if (timeoutId !== null) {
7399
- clearTimeout(timeoutId);
7400
- }
7401
- timeoutId = setTimeout(() => {
7402
- callback(...lastArgs);
7403
- timeoutId = null;
7404
- lastArgs = null;
7405
- }, waitMs);
7406
- };
7407
- debouncedFn.cancel = () => {
7408
- if (timeoutId !== null) {
7409
- clearTimer();
7410
- }
7411
- };
7412
- debouncedFn.flush = () => {
7413
- if (timeoutId !== null) {
7414
- callback(...lastArgs);
7415
- clearTimer();
7416
- }
7417
- };
7418
- debouncedFn.isPending = () => timeoutId !== null;
7419
- return debouncedFn;
7420
- };
7421
-
7422
- // src/legacy/common/utils/api-utils.ts
7423
- function isStatus2xx(status) {
7424
- return status >= 200 && status < 300;
7425
- }
7426
-
7427
- // src/legacy/common/validators/types/type-validators.ts
7428
- var isString2 = (value) => typeof value === "string";
7429
- var isNumber2 = (value) => typeof value === "number" && !Number.isNaN(value);
7430
- var isInteger2 = (value) => {
7431
- return isNumber2(value) && Math.floor(value) === value;
7432
- };
7433
- var isBoolean2 = (value) => typeof value === "boolean";
7434
- var isObject2 = (value) => !isNull2(value) && !isUndefined2(value) && (value == null ? void 0 : value.constructor) === Object;
7435
- var isArray2 = (value) => Array.isArray(value);
7436
- var isNull2 = (value) => value === null;
7437
- var isUndefined2 = (value) => typeof value === "undefined";
7438
-
7439
- // src/legacy/common/validators/values/value-validators.ts
7440
- var isEmpty = (value) => isString2(value) && value.length === 0 || (isObject2(value) || isArray2(value)) && Object.keys(value).length === 0;
7441
-
7442
- // src/legacy/common/validators/models/model-utils.ts
7443
- function cleanBasicModelWithOneOfSchema(model, schema) {
7444
- return schema.oneOf.some(
7445
- (nestedSchema) => getValidBasicModelOrNull(model, nestedSchema) === model
7446
- ) ? model : null;
7447
- }
7448
- function cleanArrayModelWithOneOfSchema(model, schema) {
7449
- var _a;
7450
- const validModels = schema.oneOf.map((nestedSchema) => getValidArrayModelOrNull(model, nestedSchema)).filter((item) => item !== null);
7451
- if (validModels.length === 0) {
7452
- return null;
7284
+ if (!isUndefined2(schema.const) && isEqual(model, schema.const)) {
7285
+ return model;
7453
7286
  }
7454
- return (_a = validModels.find((model2) => model2.some((item) => item !== null))) != null ? _a : validModels[0];
7287
+ return isObjectSchema2(schema) ? cleanObjectModelWithObjectSchema(model, schema) : null;
7455
7288
  }
7456
- function getValidArrayModelOrNull(model, schema) {
7457
- if (!isArraySchema2(schema)) {
7458
- return null;
7289
+ function getValidArrayModelParts(model, schema) {
7290
+ if (isOneOfSchema2(schema)) {
7291
+ return cleanArrayModelWithOneOfSchema(model, schema);
7459
7292
  }
7460
- if (!isListArraySchema(schema)) {
7293
+ if (!isArraySchema2(schema)) {
7461
7294
  return null;
7462
7295
  }
7463
7296
  return cleanModelWithArraySchema(model, schema);
7464
7297
  }
7465
- function cleanModelWithStringSchema(model) {
7466
- return isString2(model) && !isEmpty(model) ? model : null;
7298
+
7299
+ // src/legacy/common/validators/validationFailures/validation-failures.utils.ts
7300
+ function isValidRequired(value, isRequired = false) {
7301
+ return !isRequired || !isUndefined2(value);
7467
7302
  }
7468
- function cleanModelWithNumberSchema(model) {
7469
- return isNumber2(model) ? model : null;
7303
+ function isValidRequiredArray(value, isRequired = false) {
7304
+ return !isRequired || isArray2(value);
7470
7305
  }
7471
- function cleanModelWithBooleanSchema(model) {
7472
- return isBoolean2(model) ? model : null;
7473
- }
7474
- function cleanModelWithArraySchema(model, schema) {
7475
- if (!isArray2(model)) {
7476
- return null;
7477
- }
7478
- if (!isListArraySchema(schema)) {
7479
- return null;
7480
- }
7481
- if (model.length > 0) {
7482
- const expectedType = typeof model[0];
7483
- if (!model.every((item) => typeof item === expectedType)) {
7484
- return new Array(model.length).fill(null);
7485
- }
7486
- }
7487
- return model.map((childModel) => getValidModelParts(childModel, schema.items));
7488
- }
7489
- function cleanObjectModelWithObjectSchema(model, schema) {
7490
- return Object.keys(schema.properties).reduce((cleanedModel, property) => {
7491
- if (model && !isUndefined2(model[property])) {
7492
- const subModel = model[property];
7493
- const subSchema = schema.properties[property];
7494
- const newValue = getValidModelParts(subModel, subSchema);
7495
- if (!isNull2(newValue)) {
7496
- return __spreadProps(__spreadValues({}, cleanedModel), { [property]: newValue });
7497
- }
7498
- }
7499
- return cleanedModel;
7500
- }, {});
7501
- }
7502
- function cleanObjectModelWithAllOfSchema(model, schema) {
7503
- return schema.allOf.reduce((cleanObjectModel, nestedSchema) => {
7504
- const validSubsetOfModel = getValidObjectModelParts(model, nestedSchema);
7505
- if (isObjectModel2(validSubsetOfModel)) {
7506
- return __spreadValues(__spreadValues({}, cleanObjectModel), validSubsetOfModel);
7507
- }
7508
- return cleanObjectModel;
7509
- }, {});
7510
- }
7511
- function cleanObjectModelWithOneOfSchema(model, schema) {
7512
- return schema.oneOf.map((nestedSchema) => getValidObjectModelParts(model, nestedSchema)).reduce((combined, current) => {
7513
- if (isNull2(combined)) {
7514
- return current;
7515
- }
7516
- if (isObjectModel2(combined) && isObjectModel2(current)) {
7517
- return deepMergeObject(combined, current);
7518
- }
7519
- if (isNull2(current)) {
7520
- return combined;
7521
- }
7522
- return current;
7523
- }, null);
7524
- }
7525
- function deepMergeObject(object1, object2) {
7526
- return Object.keys(object2).reduce(
7527
- (acc, property) => {
7528
- const object1Property = object1[property];
7529
- const object2Property = object2[property];
7530
- if (isObjectModel2(object1Property) && isObjectModel2(object2Property)) {
7531
- return __spreadProps(__spreadValues({}, acc), {
7532
- [property]: deepMergeObject(object1Property, object2Property)
7533
- });
7534
- }
7535
- return __spreadProps(__spreadValues({}, acc), {
7536
- [property]: object2[property]
7537
- });
7538
- },
7539
- __spreadValues({}, object1)
7540
- );
7541
- }
7542
-
7543
- // src/legacy/common/validators/models/model-validators.ts
7544
- var getValidModelParts = (model, schema) => {
7545
- if (isObjectModel2(model)) {
7546
- return getValidObjectModelParts(model, schema);
7547
- }
7548
- if (isArrayModel2(model)) {
7549
- return getValidArrayModelParts(model, schema);
7550
- }
7551
- return getValidBasicModelOrNull(model, schema);
7552
- };
7553
- function getValidBasicModelOrNull(model, schema) {
7554
- if (isNull2(model)) {
7555
- return null;
7556
- }
7557
- if (schema.oneOf) {
7558
- return cleanBasicModelWithOneOfSchema(model, schema);
7559
- }
7560
- if (!isUndefined2(schema.const) && model === schema.const) {
7561
- return model;
7562
- }
7563
- if (schema.type) {
7564
- switch (schema.type) {
7565
- case "string":
7566
- return cleanModelWithStringSchema(model);
7567
- case "number":
7568
- case "integer":
7569
- return cleanModelWithNumberSchema(model);
7570
- case "boolean":
7571
- return cleanModelWithBooleanSchema(model);
7572
- default:
7573
- return null;
7574
- }
7575
- }
7576
- return null;
7577
- }
7578
- function getValidObjectModelParts(model, schema) {
7579
- if (isBasicSchema(schema) || isArraySchema2(schema) || isNull2(model)) {
7580
- return null;
7581
- }
7582
- if (schema.allOf) {
7583
- return cleanObjectModelWithAllOfSchema(model, schema);
7584
- }
7585
- if (schema.oneOf) {
7586
- return cleanObjectModelWithOneOfSchema(model, schema);
7587
- }
7588
- if (!isUndefined2(schema.const) && isEqual(model, schema.const)) {
7589
- return model;
7590
- }
7591
- return isObjectSchema2(schema) ? cleanObjectModelWithObjectSchema(model, schema) : null;
7592
- }
7593
- function getValidArrayModelParts(model, schema) {
7594
- if (isOneOfSchema2(schema)) {
7595
- return cleanArrayModelWithOneOfSchema(model, schema);
7596
- }
7597
- if (!isArraySchema2(schema)) {
7598
- return null;
7599
- }
7600
- return cleanModelWithArraySchema(model, schema);
7601
- }
7602
-
7603
- // src/legacy/common/validators/validationFailures/validation-failures.utils.ts
7604
- function isValidRequired(value, isRequired = false) {
7605
- return !isRequired || !isUndefined2(value);
7606
- }
7607
- function isValidRequiredArray(value, isRequired = false) {
7608
- return !isRequired || isArray2(value);
7609
- }
7610
- function isValidMinLength(value, minLength) {
7611
- return !isNumber2(minLength) || isString2(value) && value.length >= minLength;
7306
+ function isValidMinLength(value, minLength) {
7307
+ return !isNumber2(minLength) || isString2(value) && value.length >= minLength;
7612
7308
  }
7613
7309
  function isValidMaxLength(value, maxLength) {
7614
7310
  return !isNumber2(maxLength) || isString2(value) && value.length <= maxLength;
@@ -12578,6 +12274,310 @@ function useStepPolling(polling, onAction) {
12578
12274
  });
12579
12275
  }
12580
12276
 
12277
+ // src/legacy/step/layoutStep/utils/layout-utils.ts
12278
+ function convertStepToLayout(step, { displayStepTitle = true } = {}) {
12279
+ if (step.layout) {
12280
+ return addMissingTitleAndDescriptionToStep(step, displayStepTitle);
12281
+ }
12282
+ switch (step.type) {
12283
+ case "final":
12284
+ return convertFinalStepToDynamicLayout(step);
12285
+ case "decision":
12286
+ return convertDecisionStepToDynamicLayout(step);
12287
+ case "external":
12288
+ return convertExternalStepToDynamicLayout(step);
12289
+ default:
12290
+ return convertFormStepToDynamicLayout(step);
12291
+ }
12292
+ }
12293
+ function convertCommonComponents(step) {
12294
+ const layout = [];
12295
+ if (step.title) {
12296
+ layout.push(convertStepTitleToDynamicHeading(step.title));
12297
+ }
12298
+ if (step.image) {
12299
+ const image = convertStepImageToDynamicImage(step.image);
12300
+ layout.push(image);
12301
+ }
12302
+ if (step.description) {
12303
+ layout.push(convertStepDescriptionToDynamicParagraph(step.description));
12304
+ }
12305
+ return layout;
12306
+ }
12307
+ function convertExternalStepToDynamicLayout(step) {
12308
+ return [...convertCommonComponents(step), convertStepToExternalComponent(step)];
12309
+ }
12310
+ function convertStepToExternalComponent(step) {
12311
+ return {
12312
+ type: "external",
12313
+ requestUrl: step.requestUrl,
12314
+ polling: step.polling,
12315
+ responseHandlers: step.responseHandlers,
12316
+ retryTitle: step.retryTitle
12317
+ };
12318
+ }
12319
+ function convertFormStepToDynamicLayout(step) {
12320
+ const layout = convertCommonComponents(step);
12321
+ if (step.reviewFields) {
12322
+ layout.push(convertStepReviewToDynamicReview(step.reviewFields));
12323
+ }
12324
+ if (step.schemas) {
12325
+ layout.push(...getSchemaLayout(step));
12326
+ }
12327
+ if (step.actions) {
12328
+ const actions = step.actions.map(convertStepActionToDynamicAction);
12329
+ layout.push(dynamicBox(actions, "md"));
12330
+ }
12331
+ return layout;
12332
+ }
12333
+ function convertFinalStepToDynamicLayout(step) {
12334
+ const layout = [];
12335
+ if (step.details) {
12336
+ if (step.details.image) {
12337
+ const image = convertFinalStepImageToDynamicImage(step.details.image);
12338
+ layout.push(image);
12339
+ }
12340
+ if (step.details.title) {
12341
+ layout.push(convertStepTitleToDynamicHeading(step.details.title));
12342
+ }
12343
+ if (step.details.description) {
12344
+ layout.push(convertStepDescriptionToDynamicParagraph(step.details.description));
12345
+ }
12346
+ }
12347
+ if (step.actions) {
12348
+ const actions = step.actions.map(
12349
+ (action) => convertStepActionToDynamicAction(__spreadProps(__spreadValues({}, action), { type: action.type || "primary" }))
12350
+ );
12351
+ layout.push(dynamicBox(actions, "md"));
12352
+ }
12353
+ return layout;
12354
+ }
12355
+ function convertDecisionStepToDynamicLayout(step) {
12356
+ const layout = convertCommonComponents(step);
12357
+ if (step.options) {
12358
+ layout.push(convertStepDecisionToDynamicDecision(step.options));
12359
+ }
12360
+ return layout;
12361
+ }
12362
+ function dynamicBox(components, size) {
12363
+ return {
12364
+ type: "box",
12365
+ width: size || "md",
12366
+ components
12367
+ };
12368
+ }
12369
+ function convertStepTitleToDynamicHeading(title) {
12370
+ return {
12371
+ type: "heading",
12372
+ text: title,
12373
+ size: "lg",
12374
+ margin: "lg",
12375
+ align: "center"
12376
+ };
12377
+ }
12378
+ function convertStepDescriptionToDynamicParagraph(description) {
12379
+ return {
12380
+ type: "paragraph",
12381
+ text: description,
12382
+ align: "center"
12383
+ };
12384
+ }
12385
+ function convertStepSchemaToDynamicForm(schema) {
12386
+ return { type: "form", schema };
12387
+ }
12388
+ function convertStepDecisionToDynamicDecision(options) {
12389
+ return {
12390
+ type: "decision",
12391
+ options: options.map(convertStepDecisionOption)
12392
+ };
12393
+ }
12394
+ function convertStepDecisionOption(option) {
12395
+ return {
12396
+ title: option.title,
12397
+ description: option.description,
12398
+ action: {
12399
+ title: option.title,
12400
+ method: "GET",
12401
+ url: option.url,
12402
+ disabled: option.disabled
12403
+ }
12404
+ };
12405
+ }
12406
+ function convertStepImageToDynamicImage(image) {
12407
+ return {
12408
+ type: "image",
12409
+ url: image.url,
12410
+ text: image.text,
12411
+ margin: image.margin || "lg",
12412
+ size: image.size || "md"
12413
+ };
12414
+ }
12415
+ function convertFinalStepImageToDynamicImage(image) {
12416
+ return typeof image === "string" ? {
12417
+ type: "image",
12418
+ url: image,
12419
+ text: void 0,
12420
+ margin: "lg",
12421
+ size: "md"
12422
+ } : convertStepImageToDynamicImage(image);
12423
+ }
12424
+ function convertStepActionToDynamicAction(action) {
12425
+ const newAction = __spreadProps(__spreadValues({}, action), { title: action.title });
12426
+ return {
12427
+ type: "button",
12428
+ action: newAction
12429
+ };
12430
+ }
12431
+ function convertStepReviewToDynamicReview(reviewFields) {
12432
+ return {
12433
+ type: "review",
12434
+ title: reviewFields.title,
12435
+ fields: reviewFields.fields.map(convertReviewFieldToDefinition)
12436
+ };
12437
+ }
12438
+ function convertReviewFieldToDefinition(reviewField) {
12439
+ return {
12440
+ label: reviewField.title,
12441
+ value: reviewField.value
12442
+ };
12443
+ }
12444
+ function getSchemaLayout(step) {
12445
+ const layout = [];
12446
+ if (step.schemas && step.schemas[0]) {
12447
+ const schema = step.schemas[0];
12448
+ const dynamicForm = convertStepSchemaToDynamicForm(schema);
12449
+ if (isWideForm()) {
12450
+ layout.push(dynamicForm);
12451
+ } else {
12452
+ layout.push(dynamicBox([dynamicForm], "md"));
12453
+ }
12454
+ }
12455
+ return layout;
12456
+ }
12457
+ function isWideForm() {
12458
+ return false;
12459
+ }
12460
+ function addMissingTitleAndDescriptionToStep(step, displayStepTitle) {
12461
+ return [
12462
+ ...displayStepTitle && step.title ? [convertStepTitleToDynamicHeading(step.title)] : [],
12463
+ ...step.description ? [convertStepDescriptionToDynamicParagraph(step.description)] : [],
12464
+ ...step.layout || []
12465
+ ];
12466
+ }
12467
+
12468
+ // src/legacy/step/layoutStep/utils/inline-reference-utils.ts
12469
+ function inlineReferences({
12470
+ layout,
12471
+ schemas,
12472
+ actions,
12473
+ model
12474
+ }) {
12475
+ if (!layout) {
12476
+ return [];
12477
+ }
12478
+ if (!schemas) {
12479
+ return layout;
12480
+ }
12481
+ return layout.map((component) => {
12482
+ if (component.type === "form") {
12483
+ return inlineFormSchema({ formComponent: component, schemas });
12484
+ }
12485
+ if (component.type === "decision") {
12486
+ return inlineDecisionActions({ decisionComponent: component, actions });
12487
+ }
12488
+ if (component.type === "button") {
12489
+ return inlineAction2({ actionComponent: component, actions });
12490
+ }
12491
+ if (component.type === "box") {
12492
+ return __spreadProps(__spreadValues({}, component), {
12493
+ components: inlineReferences({ layout: component.components, schemas, actions, model })
12494
+ });
12495
+ }
12496
+ if (component.type === "modal") {
12497
+ return __spreadProps(__spreadValues({}, component), {
12498
+ components: inlineReferences({
12499
+ layout: component.content.components,
12500
+ schemas,
12501
+ actions,
12502
+ model
12503
+ })
12504
+ });
12505
+ }
12506
+ if (component.type === "columns") {
12507
+ return __spreadProps(__spreadValues({}, component), {
12508
+ left: inlineReferences({ layout: component.left, schemas, actions, model }),
12509
+ right: inlineReferences({ layout: component.right, schemas, actions, model })
12510
+ });
12511
+ }
12512
+ return component;
12513
+ });
12514
+ }
12515
+ function inlineFormSchema({
12516
+ formComponent,
12517
+ schemas
12518
+ }) {
12519
+ if (formComponent.schemaId) {
12520
+ return {
12521
+ type: "form",
12522
+ margin: formComponent.margin,
12523
+ schema: getSchemaById(schemas, formComponent.schemaId)
12524
+ };
12525
+ }
12526
+ if (formComponent.schema && isReference(formComponent.schema) && formComponent.schema.$ref) {
12527
+ return {
12528
+ type: "form",
12529
+ margin: formComponent.margin,
12530
+ schema: getSchemaById(schemas, formComponent.schema.$ref)
12531
+ };
12532
+ }
12533
+ if (formComponent.schema && !isReference(formComponent.schema)) {
12534
+ return __spreadValues({}, formComponent);
12535
+ }
12536
+ throw new Error('Invalid form layout component. Missing "schema" or "schemaId" properties.');
12537
+ }
12538
+ function inlineDecisionActions({
12539
+ decisionComponent,
12540
+ actions
12541
+ }) {
12542
+ var _a;
12543
+ const newOptions = (_a = decisionComponent == null ? void 0 : decisionComponent.options) == null ? void 0 : _a.map(
12544
+ (option) => option.action && isReference(option.action) ? __spreadProps(__spreadValues({}, option), {
12545
+ action: getActionById(actions, option.action.$ref)
12546
+ }) : option
12547
+ );
12548
+ return __spreadProps(__spreadValues({}, decisionComponent), {
12549
+ options: newOptions
12550
+ });
12551
+ }
12552
+ function inlineAction2({
12553
+ actionComponent,
12554
+ actions
12555
+ }) {
12556
+ var _a;
12557
+ if (actionComponent.action && isReference(actionComponent.action) && ((_a = actionComponent.action) == null ? void 0 : _a.$ref)) {
12558
+ const newAction = getActionById(actions, actionComponent.action.$ref);
12559
+ return convertStepActionToDynamicAction(newAction);
12560
+ }
12561
+ return actionComponent;
12562
+ }
12563
+ function getSchemaById(schemas, id) {
12564
+ const schema = schemas.find((schema2) => schema2.$id === id);
12565
+ if (!schema) {
12566
+ throw new Error(`Fatal Error. Schema not found. $id ${id}`);
12567
+ }
12568
+ return schema;
12569
+ }
12570
+ function getActionById(actions, id) {
12571
+ const action = actions.find((action2) => action2.$id === id);
12572
+ if (!action) {
12573
+ throw new Error(`Fatal Error. Action not found. $id ${id}`);
12574
+ }
12575
+ return action;
12576
+ }
12577
+ function isReference(block) {
12578
+ return Object.hasOwnProperty.call(block, "$ref");
12579
+ }
12580
+
12581
12581
  // src/legacy/step/layoutStep/LayoutStep.tsx
12582
12582
  var import_jsx_runtime64 = require("react/jsx-runtime");
12583
12583
  var getComponents = (step, options) => {