@wise/dynamic-flow-client 5.20.0 → 5.22.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.css +9 -0
- package/build/main.js +473 -103
- package/build/main.mjs +473 -103
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/build/types/domain/components/AlertComponent.d.ts +6 -2
- package/build/types/domain/components/AlertComponent.d.ts.map +1 -1
- package/build/types/domain/components/SectionComponent.d.ts +2 -1
- package/build/types/domain/components/SectionComponent.d.ts.map +1 -1
- package/build/types/domain/components/collectionComponent/CollectionComponent.d.ts +7 -0
- package/build/types/domain/components/collectionComponent/CollectionComponent.d.ts.map +1 -0
- package/build/types/domain/components/collectionComponent/types.d.ts +71 -0
- package/build/types/domain/components/collectionComponent/types.d.ts.map +1 -0
- package/build/types/domain/features/collection/getPerformCollectionQuery.d.ts +14 -0
- package/build/types/domain/features/collection/getPerformCollectionQuery.d.ts.map +1 -0
- package/build/types/domain/handlers/dismissHandler.d.ts +5 -0
- package/build/types/domain/handlers/dismissHandler.d.ts.map +1 -0
- package/build/types/domain/mappers/layout/alertLayoutToComponent.d.ts +1 -1
- package/build/types/domain/mappers/layout/alertLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/mappers/layout/collectionLayoutToComponent.d.ts +7 -0
- package/build/types/domain/mappers/layout/collectionLayoutToComponent.d.ts.map +1 -0
- package/build/types/domain/mappers/layout/sectionLayoutToComponent.d.ts +1 -1
- package/build/types/domain/mappers/layout/sectionLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/mappers/layout/upsellLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/mappers/mapLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/types.d.ts +2 -1
- package/build/types/domain/types.d.ts.map +1 -1
- package/build/types/renderers/mappers/alertComponentToProps.d.ts.map +1 -1
- package/build/types/renderers/mappers/collectionComponentToProps.d.ts +5 -0
- package/build/types/renderers/mappers/collectionComponentToProps.d.ts.map +1 -0
- package/build/types/renderers/mappers/componentToRendererProps.d.ts.map +1 -1
- package/build/types/renderers/mappers/sectionComponentToProps.d.ts.map +1 -1
- package/build/types/test-utils/getMergedTestRenderers.d.ts +1 -1
- package/build/types/test-utils/getMergedTestRenderers.d.ts.map +1 -1
- package/build/types/useDynamicFlow.d.ts +2 -1
- package/build/types/useDynamicFlow.d.ts.map +1 -1
- package/build/types/useDynamicFlowModal.d.ts +1 -1
- package/package.json +5 -5
package/build/main.js
CHANGED
|
@@ -883,6 +883,7 @@ var getChildren = (node) => {
|
|
|
883
883
|
return node.tabs.flatMap((c) => c.childrenProps);
|
|
884
884
|
case "alert":
|
|
885
885
|
case "button":
|
|
886
|
+
case "collection":
|
|
886
887
|
case "input-checkbox":
|
|
887
888
|
case "input-date":
|
|
888
889
|
case "decision":
|
|
@@ -1301,6 +1302,17 @@ var createAlertComponent = (props) => __spreadValues({
|
|
|
1301
1302
|
kind: "layout"
|
|
1302
1303
|
}, props);
|
|
1303
1304
|
|
|
1305
|
+
// src/domain/handlers/dismissHandler.ts
|
|
1306
|
+
var makeDismissHandler = (onDismiss, mapperProps) => () => {
|
|
1307
|
+
const { url, method, body, headers } = onDismiss;
|
|
1308
|
+
void mapperProps.httpClient(url, {
|
|
1309
|
+
method,
|
|
1310
|
+
body: method === "GET" ? void 0 : JSON.stringify(body),
|
|
1311
|
+
headers
|
|
1312
|
+
}).catch(() => {
|
|
1313
|
+
});
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1304
1316
|
// src/domain/mappers/utils/behavior-utils.ts
|
|
1305
1317
|
var getDomainLayerBehavior = ({ action, behavior: specBehavior }, stepActions, registerSubmissionBehavior) => {
|
|
1306
1318
|
if (specBehavior) {
|
|
@@ -1454,20 +1466,25 @@ var alertLayoutToComponent = (uid, {
|
|
|
1454
1466
|
context,
|
|
1455
1467
|
callToAction,
|
|
1456
1468
|
analyticsId,
|
|
1457
|
-
tags
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1469
|
+
tags,
|
|
1470
|
+
title,
|
|
1471
|
+
media,
|
|
1472
|
+
onDismiss,
|
|
1473
|
+
secondaryCallToAction
|
|
1474
|
+
}, mapperProps) => createAlertComponent({
|
|
1475
|
+
uid,
|
|
1476
|
+
analyticsId,
|
|
1477
|
+
control,
|
|
1478
|
+
markdown,
|
|
1479
|
+
margin: margin != null ? margin : "md",
|
|
1480
|
+
callToAction: getDomainLayerCallToAction(callToAction, mapperProps),
|
|
1481
|
+
context: mapLegacyContext(context != null ? context : "neutral"),
|
|
1482
|
+
tags,
|
|
1483
|
+
title,
|
|
1484
|
+
media,
|
|
1485
|
+
dismiss: onDismiss ? makeDismissHandler(onDismiss, mapperProps) : void 0,
|
|
1486
|
+
secondaryCallToAction: getDomainLayerCallToAction(secondaryCallToAction, mapperProps)
|
|
1487
|
+
});
|
|
1471
1488
|
|
|
1472
1489
|
// src/domain/components/BoxComponent.ts
|
|
1473
1490
|
var createBoxComponent = (props) => __spreadProps(__spreadValues({}, props), {
|
|
@@ -1500,6 +1517,367 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
|
|
|
1500
1517
|
)
|
|
1501
1518
|
});
|
|
1502
1519
|
|
|
1520
|
+
// src/domain/mappers/utils/utils.ts
|
|
1521
|
+
var mapInlineAlert = (alert) => {
|
|
1522
|
+
return alert ? {
|
|
1523
|
+
content: alert.content,
|
|
1524
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1525
|
+
} : void 0;
|
|
1526
|
+
};
|
|
1527
|
+
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1528
|
+
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1529
|
+
if (info) {
|
|
1530
|
+
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1531
|
+
const isLink = behavior.type === "link";
|
|
1532
|
+
return {
|
|
1533
|
+
text: info.text,
|
|
1534
|
+
href: isLink ? behavior.url : void 0,
|
|
1535
|
+
hrefWithTracking: getHrefWithTracking({
|
|
1536
|
+
behavior,
|
|
1537
|
+
onBehavior,
|
|
1538
|
+
trackEvent
|
|
1539
|
+
}),
|
|
1540
|
+
accessibilityDescription: info.accessibilityDescription,
|
|
1541
|
+
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1542
|
+
void onBehavior(behavior);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
return void 0;
|
|
1547
|
+
};
|
|
1548
|
+
var mapSchemaAlert = (alert) => {
|
|
1549
|
+
return alert ? {
|
|
1550
|
+
content: alert.markdown,
|
|
1551
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1552
|
+
} : void 0;
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
// src/domain/components/utils/debounce.ts
|
|
1556
|
+
var debounce = (callback, waitMs) => {
|
|
1557
|
+
let timeoutId = null;
|
|
1558
|
+
let lastArgs = null;
|
|
1559
|
+
const clearTimer = () => {
|
|
1560
|
+
if (timeoutId !== null) {
|
|
1561
|
+
clearTimeout(timeoutId);
|
|
1562
|
+
timeoutId = null;
|
|
1563
|
+
}
|
|
1564
|
+
lastArgs = null;
|
|
1565
|
+
};
|
|
1566
|
+
const debouncedFn = (...args) => {
|
|
1567
|
+
lastArgs = args;
|
|
1568
|
+
if (timeoutId !== null) {
|
|
1569
|
+
clearTimeout(timeoutId);
|
|
1570
|
+
}
|
|
1571
|
+
timeoutId = setTimeout(() => {
|
|
1572
|
+
callback(...lastArgs);
|
|
1573
|
+
timeoutId = null;
|
|
1574
|
+
lastArgs = null;
|
|
1575
|
+
}, waitMs);
|
|
1576
|
+
};
|
|
1577
|
+
debouncedFn.cancel = () => {
|
|
1578
|
+
if (timeoutId !== null) {
|
|
1579
|
+
clearTimer();
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
debouncedFn.flush = () => {
|
|
1583
|
+
if (timeoutId !== null) {
|
|
1584
|
+
callback(...lastArgs);
|
|
1585
|
+
clearTimer();
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
return debouncedFn;
|
|
1589
|
+
};
|
|
1590
|
+
|
|
1591
|
+
// src/domain/components/collectionComponent/CollectionComponent.ts
|
|
1592
|
+
var DEBOUNCE_TIME = 800;
|
|
1593
|
+
var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
|
|
1594
|
+
const { uid, analyticsId, control, margin, tags, state } = props;
|
|
1595
|
+
const update = getInputUpdateFunction(onComponentUpdate);
|
|
1596
|
+
let abortController = new AbortController();
|
|
1597
|
+
const query = (mode) => {
|
|
1598
|
+
var _a, _b;
|
|
1599
|
+
abortController.abort();
|
|
1600
|
+
abortController = new AbortController();
|
|
1601
|
+
const { signal } = abortController;
|
|
1602
|
+
queryFunction({
|
|
1603
|
+
searchParam: (_a = component.state.search) == null ? void 0 : _a.param,
|
|
1604
|
+
query: (_b = component.state.search) == null ? void 0 : _b.query,
|
|
1605
|
+
cursor: mode === "pagination" ? component.state.nextCursor : void 0,
|
|
1606
|
+
signal,
|
|
1607
|
+
filters: component.state.filters
|
|
1608
|
+
}).then((response) => {
|
|
1609
|
+
if (!response) {
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
update(component, (draft) => {
|
|
1613
|
+
var _a2, _b2;
|
|
1614
|
+
draft.state = {
|
|
1615
|
+
sections: mode === "pagination" ? mergeSections(component.state.sections, response.sections) : response.sections,
|
|
1616
|
+
nextCursor: response.nextCursor,
|
|
1617
|
+
filters: response.filters ? mapFilters(response.filters) : component.state.filters,
|
|
1618
|
+
search: response.search ? mapSearch(response.search) : component.state.search,
|
|
1619
|
+
beforeSections: (_a2 = response.beforeSections) != null ? _a2 : component.state.beforeSections,
|
|
1620
|
+
afterSections: (_b2 = response.afterSections) != null ? _b2 : component.state.afterSections
|
|
1621
|
+
};
|
|
1622
|
+
draft.status = {
|
|
1623
|
+
type: "idle",
|
|
1624
|
+
loadMore: response.nextCursor ? paginate : void 0
|
|
1625
|
+
};
|
|
1626
|
+
});
|
|
1627
|
+
}).catch(() => {
|
|
1628
|
+
if (!signal.aborted) {
|
|
1629
|
+
update(component, (draft) => {
|
|
1630
|
+
draft.state = {
|
|
1631
|
+
filters: component.state.filters,
|
|
1632
|
+
search: component.state.search,
|
|
1633
|
+
sections: []
|
|
1634
|
+
};
|
|
1635
|
+
draft.status = { type: "error", reason: mode, retry: () => query(mode) };
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
};
|
|
1640
|
+
const debouncedQuery = debounce(query, DEBOUNCE_TIME);
|
|
1641
|
+
const search = () => {
|
|
1642
|
+
abortController.abort();
|
|
1643
|
+
debouncedQuery("search");
|
|
1644
|
+
};
|
|
1645
|
+
const filter = () => {
|
|
1646
|
+
debouncedQuery("search");
|
|
1647
|
+
debouncedQuery.flush();
|
|
1648
|
+
};
|
|
1649
|
+
const paginate = () => query("pagination");
|
|
1650
|
+
const selectFilter = (filterIndex, optionIndex) => {
|
|
1651
|
+
var _a;
|
|
1652
|
+
const selected = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
|
|
1653
|
+
if (!selected) {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
const currentValue = selected.options[optionIndex].selected;
|
|
1657
|
+
update(component, (draft) => {
|
|
1658
|
+
if (!draft.state.filters) {
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
const draftFilter = draft.state.filters[filterIndex];
|
|
1662
|
+
if (selected.multiSelect) {
|
|
1663
|
+
draftFilter.options[optionIndex].selected = !currentValue;
|
|
1664
|
+
} else {
|
|
1665
|
+
draftFilter.options.forEach((draftOption, index) => {
|
|
1666
|
+
draftOption.selected = index === optionIndex ? !currentValue : false;
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1670
|
+
});
|
|
1671
|
+
filter();
|
|
1672
|
+
};
|
|
1673
|
+
const mapFilters = (filters) => filters == null ? void 0 : filters.map((f, filterIndex) => {
|
|
1674
|
+
var _a;
|
|
1675
|
+
return __spreadProps(__spreadValues({}, f), {
|
|
1676
|
+
options: (_a = f.options) == null ? void 0 : _a.map((option, optionIndex) => {
|
|
1677
|
+
var _a2;
|
|
1678
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1679
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1680
|
+
onSelect: () => selectFilter(filterIndex, optionIndex)
|
|
1681
|
+
});
|
|
1682
|
+
})
|
|
1683
|
+
});
|
|
1684
|
+
});
|
|
1685
|
+
const mapSearch = (searchConfig) => searchConfig ? __spreadProps(__spreadValues({
|
|
1686
|
+
query: ""
|
|
1687
|
+
}, searchConfig), {
|
|
1688
|
+
onChange(value) {
|
|
1689
|
+
update(component, (draft) => {
|
|
1690
|
+
if (draft.state.search) {
|
|
1691
|
+
draft.state.search.query = value;
|
|
1692
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
search();
|
|
1696
|
+
}
|
|
1697
|
+
}) : void 0;
|
|
1698
|
+
const component = {
|
|
1699
|
+
type: "collection",
|
|
1700
|
+
kind: "layout",
|
|
1701
|
+
uid,
|
|
1702
|
+
analyticsId,
|
|
1703
|
+
control,
|
|
1704
|
+
margin,
|
|
1705
|
+
tags,
|
|
1706
|
+
status: {
|
|
1707
|
+
type: "idle",
|
|
1708
|
+
loadMore: state.nextCursor ? () => query("pagination") : void 0
|
|
1709
|
+
},
|
|
1710
|
+
state: __spreadProps(__spreadValues({}, state), {
|
|
1711
|
+
filters: mapFilters(state.filters),
|
|
1712
|
+
search: mapSearch(props.search)
|
|
1713
|
+
})
|
|
1714
|
+
};
|
|
1715
|
+
return component;
|
|
1716
|
+
};
|
|
1717
|
+
var mergeSections = (existing, incoming) => {
|
|
1718
|
+
const knownIds = new Set(existing.map((section) => section.id));
|
|
1719
|
+
const newSections = incoming.filter((section) => !knownIds.has(section.id));
|
|
1720
|
+
const merged = existing.map((section) => {
|
|
1721
|
+
const match = incoming.find((s) => s.id === section.id);
|
|
1722
|
+
if (!match) return section;
|
|
1723
|
+
return __spreadProps(__spreadValues({}, match), { items: [...section.items, ...match.items] });
|
|
1724
|
+
});
|
|
1725
|
+
return [...merged, ...newSections];
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
// src/domain/features/collection/getPerformCollectionQuery.ts
|
|
1729
|
+
var getPerformCollectionQuery = (httpClient, baseRequest, mapState) => {
|
|
1730
|
+
let latestSuccessfulRequestHash = null;
|
|
1731
|
+
let latestSuccessfulResults = null;
|
|
1732
|
+
return async (props) => {
|
|
1733
|
+
const requestHash = hashRequest(props);
|
|
1734
|
+
if (requestHash !== latestSuccessfulRequestHash) {
|
|
1735
|
+
const response = await performRequest(baseRequest, props, httpClient);
|
|
1736
|
+
const results = await parseResponse(response);
|
|
1737
|
+
latestSuccessfulRequestHash = requestHash;
|
|
1738
|
+
const mappedState = mapState(results);
|
|
1739
|
+
latestSuccessfulResults = mappedState;
|
|
1740
|
+
return mappedState;
|
|
1741
|
+
}
|
|
1742
|
+
return latestSuccessfulResults;
|
|
1743
|
+
};
|
|
1744
|
+
};
|
|
1745
|
+
var performRequest = (request, queryProps, httpClient) => {
|
|
1746
|
+
const { url, method, body, headers } = request;
|
|
1747
|
+
if (method === "GET") {
|
|
1748
|
+
return httpClient(buildQueryURL(url, queryProps), {
|
|
1749
|
+
method,
|
|
1750
|
+
headers: __spreadProps(__spreadValues({}, headers), {
|
|
1751
|
+
"Content-Type": "application/json"
|
|
1752
|
+
}),
|
|
1753
|
+
signal: queryProps.signal
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
return httpClient(url, {
|
|
1757
|
+
method,
|
|
1758
|
+
headers: __spreadProps(__spreadValues({}, headers), {
|
|
1759
|
+
"Content-Type": "application/json"
|
|
1760
|
+
}),
|
|
1761
|
+
signal: queryProps.signal,
|
|
1762
|
+
body: JSON.stringify(__spreadValues(__spreadValues({}, body && typeof body === "object" && !isArray(body) ? body : {}), buildRequestBody(queryProps)))
|
|
1763
|
+
});
|
|
1764
|
+
};
|
|
1765
|
+
var buildQueryURL = (url, { searchParam, query, cursor, filters = [] }) => {
|
|
1766
|
+
const [baseUrl, queryParams] = splitUrlAndParams(url);
|
|
1767
|
+
const params = new URLSearchParams(queryParams);
|
|
1768
|
+
if (searchParam && query) {
|
|
1769
|
+
params.append(searchParam, query);
|
|
1770
|
+
}
|
|
1771
|
+
if (cursor) {
|
|
1772
|
+
params.append("cursor", cursor);
|
|
1773
|
+
}
|
|
1774
|
+
getFilterValues(filters).forEach(([key, value]) => {
|
|
1775
|
+
if (typeof value === "string") {
|
|
1776
|
+
params.append(key, value);
|
|
1777
|
+
} else {
|
|
1778
|
+
value.forEach((v) => params.append(key, v));
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
return `${baseUrl}?${params.toString()}`;
|
|
1782
|
+
};
|
|
1783
|
+
var splitUrlAndParams = (url) => {
|
|
1784
|
+
const [baseUrl, ...rest] = url.split("?");
|
|
1785
|
+
return [baseUrl, rest.join("")];
|
|
1786
|
+
};
|
|
1787
|
+
var buildRequestBody = ({
|
|
1788
|
+
searchParam,
|
|
1789
|
+
query,
|
|
1790
|
+
cursor,
|
|
1791
|
+
filters = []
|
|
1792
|
+
}) => __spreadProps(__spreadValues(__spreadValues({}, searchParam && query ? { [searchParam]: query } : {}), Object.fromEntries(getFilterValues(filters))), {
|
|
1793
|
+
cursor
|
|
1794
|
+
});
|
|
1795
|
+
var getFilterValues = (filters) => {
|
|
1796
|
+
return filters.map((filter) => {
|
|
1797
|
+
const { multiSelect, param } = filter;
|
|
1798
|
+
const values = filter.options.filter((option) => option.selected).map((option) => option.value);
|
|
1799
|
+
if (values.length === 0) {
|
|
1800
|
+
return void 0;
|
|
1801
|
+
}
|
|
1802
|
+
return [param, multiSelect ? values : values[0]];
|
|
1803
|
+
}).filter((value) => value !== void 0);
|
|
1804
|
+
};
|
|
1805
|
+
var parseResponse = async (response) => {
|
|
1806
|
+
if (response.ok) {
|
|
1807
|
+
const body = await response.json().catch(() => null);
|
|
1808
|
+
return body;
|
|
1809
|
+
}
|
|
1810
|
+
throw Error("error response");
|
|
1811
|
+
};
|
|
1812
|
+
var hashRequest = ({
|
|
1813
|
+
query,
|
|
1814
|
+
cursor,
|
|
1815
|
+
filters
|
|
1816
|
+
}) => JSON.stringify({ query, cursor, filters: getFilterValues(filters != null ? filters : []) });
|
|
1817
|
+
|
|
1818
|
+
// src/domain/mappers/layout/collectionLayoutToComponent.ts
|
|
1819
|
+
var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, search, tags, baseRequest }, mapperProps) => {
|
|
1820
|
+
const { httpClient, onComponentUpdate } = mapperProps;
|
|
1821
|
+
const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
|
|
1822
|
+
const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
|
|
1823
|
+
const queryFunction = getPerformCollectionQuery(httpClient, baseRequest, mapState);
|
|
1824
|
+
const component = createCollectionComponent(
|
|
1825
|
+
{
|
|
1826
|
+
uid,
|
|
1827
|
+
analyticsId,
|
|
1828
|
+
control,
|
|
1829
|
+
margin: margin != null ? margin : "md",
|
|
1830
|
+
tags,
|
|
1831
|
+
state: mapState(initialState),
|
|
1832
|
+
search
|
|
1833
|
+
},
|
|
1834
|
+
onComponentUpdate,
|
|
1835
|
+
queryFunction
|
|
1836
|
+
);
|
|
1837
|
+
return component;
|
|
1838
|
+
};
|
|
1839
|
+
var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
|
|
1840
|
+
var _a, _b, _c;
|
|
1841
|
+
return {
|
|
1842
|
+
sections: specState.sections.map((section) => {
|
|
1843
|
+
return {
|
|
1844
|
+
id: section.id,
|
|
1845
|
+
title: section.title,
|
|
1846
|
+
callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
|
|
1847
|
+
items: section.items.map((item) => {
|
|
1848
|
+
const behavior = getDomainLayerBehavior(
|
|
1849
|
+
{ behavior: item.primaryBehavior },
|
|
1850
|
+
[],
|
|
1851
|
+
mapperProps.registerSubmissionBehavior
|
|
1852
|
+
);
|
|
1853
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
1854
|
+
id: item.entityId,
|
|
1855
|
+
onClick: item.primaryBehavior ? () => {
|
|
1856
|
+
void mapperProps.onBehavior(behavior);
|
|
1857
|
+
} : void 0,
|
|
1858
|
+
callToAction: getDomainLayerCallToAction(item.callToAction, mapperProps),
|
|
1859
|
+
inlineAlert: mapInlineAlert(item.inlineAlert)
|
|
1860
|
+
});
|
|
1861
|
+
})
|
|
1862
|
+
};
|
|
1863
|
+
}),
|
|
1864
|
+
filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
|
|
1865
|
+
options: filter.options.map((option) => {
|
|
1866
|
+
var _a2;
|
|
1867
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1868
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1869
|
+
onSelect: () => {
|
|
1870
|
+
}
|
|
1871
|
+
// noop - this gets added during mapping
|
|
1872
|
+
});
|
|
1873
|
+
})
|
|
1874
|
+
})),
|
|
1875
|
+
beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
|
|
1876
|
+
afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
|
|
1877
|
+
nextCursor: specState.nextCursor
|
|
1878
|
+
};
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1503
1881
|
// src/domain/components/ButtonComponent.ts
|
|
1504
1882
|
var createButtonComponent = (props) => __spreadValues({
|
|
1505
1883
|
type: "button",
|
|
@@ -1668,41 +2046,6 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1668
2046
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1669
2047
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1670
2048
|
|
|
1671
|
-
// src/domain/mappers/utils/utils.ts
|
|
1672
|
-
var mapInlineAlert = (alert) => {
|
|
1673
|
-
return alert ? {
|
|
1674
|
-
content: alert.content,
|
|
1675
|
-
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1676
|
-
} : void 0;
|
|
1677
|
-
};
|
|
1678
|
-
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1679
|
-
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1680
|
-
if (info) {
|
|
1681
|
-
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1682
|
-
const isLink = behavior.type === "link";
|
|
1683
|
-
return {
|
|
1684
|
-
text: info.text,
|
|
1685
|
-
href: isLink ? behavior.url : void 0,
|
|
1686
|
-
hrefWithTracking: getHrefWithTracking({
|
|
1687
|
-
behavior,
|
|
1688
|
-
onBehavior,
|
|
1689
|
-
trackEvent
|
|
1690
|
-
}),
|
|
1691
|
-
accessibilityDescription: info.accessibilityDescription,
|
|
1692
|
-
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1693
|
-
void onBehavior(behavior);
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
}
|
|
1697
|
-
return void 0;
|
|
1698
|
-
};
|
|
1699
|
-
var mapSchemaAlert = (alert) => {
|
|
1700
|
-
return alert ? {
|
|
1701
|
-
content: alert.markdown,
|
|
1702
|
-
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1703
|
-
} : void 0;
|
|
1704
|
-
};
|
|
1705
|
-
|
|
1706
2049
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1707
2050
|
var decisionLayoutToComponent = (uid, {
|
|
1708
2051
|
analyticsId,
|
|
@@ -2178,44 +2521,8 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2178
2521
|
});
|
|
2179
2522
|
};
|
|
2180
2523
|
|
|
2181
|
-
// src/domain/components/utils/debounce.ts
|
|
2182
|
-
var debounce = (callback, waitMs) => {
|
|
2183
|
-
let timeoutId = null;
|
|
2184
|
-
let lastArgs = null;
|
|
2185
|
-
const clearTimer = () => {
|
|
2186
|
-
if (timeoutId !== null) {
|
|
2187
|
-
clearTimeout(timeoutId);
|
|
2188
|
-
timeoutId = null;
|
|
2189
|
-
}
|
|
2190
|
-
lastArgs = null;
|
|
2191
|
-
};
|
|
2192
|
-
const debouncedFn = (...args) => {
|
|
2193
|
-
lastArgs = args;
|
|
2194
|
-
if (timeoutId !== null) {
|
|
2195
|
-
clearTimeout(timeoutId);
|
|
2196
|
-
}
|
|
2197
|
-
timeoutId = setTimeout(() => {
|
|
2198
|
-
callback(...lastArgs);
|
|
2199
|
-
timeoutId = null;
|
|
2200
|
-
lastArgs = null;
|
|
2201
|
-
}, waitMs);
|
|
2202
|
-
};
|
|
2203
|
-
debouncedFn.cancel = () => {
|
|
2204
|
-
if (timeoutId !== null) {
|
|
2205
|
-
clearTimer();
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2208
|
-
debouncedFn.flush = () => {
|
|
2209
|
-
if (timeoutId !== null) {
|
|
2210
|
-
callback(...lastArgs);
|
|
2211
|
-
clearTimer();
|
|
2212
|
-
}
|
|
2213
|
-
};
|
|
2214
|
-
return debouncedFn;
|
|
2215
|
-
};
|
|
2216
|
-
|
|
2217
2524
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2218
|
-
var
|
|
2525
|
+
var DEBOUNCE_TIME2 = 400;
|
|
2219
2526
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2220
2527
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2221
2528
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2245,7 +2552,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2245
2552
|
}
|
|
2246
2553
|
});
|
|
2247
2554
|
};
|
|
2248
|
-
const debouncedSearch = debounce(search,
|
|
2555
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME2);
|
|
2249
2556
|
const component = {
|
|
2250
2557
|
type: "search",
|
|
2251
2558
|
kind: "layout",
|
|
@@ -2300,10 +2607,10 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2300
2607
|
|
|
2301
2608
|
// src/domain/features/search/getPerformSearchFunction.ts
|
|
2302
2609
|
var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultConfig) => {
|
|
2303
|
-
let latestSuccessfulRequestHash =
|
|
2610
|
+
let latestSuccessfulRequestHash = hashRequest2("", defaultConfig);
|
|
2304
2611
|
let latestSuccessfulResults = null;
|
|
2305
2612
|
return async ({ config = defaultConfig, query, signal }) => {
|
|
2306
|
-
const requestHash =
|
|
2613
|
+
const requestHash = hashRequest2(query, config);
|
|
2307
2614
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2308
2615
|
const { method, param, url } = config;
|
|
2309
2616
|
const headers = { "Content-Type": "application/json" };
|
|
@@ -2317,7 +2624,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2317
2624
|
signal,
|
|
2318
2625
|
body: JSON.stringify({ [param]: query })
|
|
2319
2626
|
}));
|
|
2320
|
-
const results = await
|
|
2627
|
+
const results = await parseResponse2(response);
|
|
2321
2628
|
latestSuccessfulRequestHash = requestHash;
|
|
2322
2629
|
if (results.type === "layout") {
|
|
2323
2630
|
const mappedLayoutResult = {
|
|
@@ -2333,7 +2640,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2333
2640
|
return latestSuccessfulResults;
|
|
2334
2641
|
};
|
|
2335
2642
|
};
|
|
2336
|
-
var
|
|
2643
|
+
var parseResponse2 = async (response) => {
|
|
2337
2644
|
if (response.ok) {
|
|
2338
2645
|
const body = await response.json().catch(() => null);
|
|
2339
2646
|
if (isValidResponseBody(body)) {
|
|
@@ -2370,7 +2677,7 @@ var isValidResponseBody = (body) => {
|
|
|
2370
2677
|
}
|
|
2371
2678
|
return false;
|
|
2372
2679
|
};
|
|
2373
|
-
var
|
|
2680
|
+
var hashRequest2 = (query, config) => JSON.stringify({ query, config });
|
|
2374
2681
|
|
|
2375
2682
|
// src/domain/mappers/layout/searchLayoutToComponent.ts
|
|
2376
2683
|
var searchLayoutToComponent = (uid, {
|
|
@@ -2447,12 +2754,22 @@ var createSectionComponent = (props) => __spreadProps(__spreadValues({}, props),
|
|
|
2447
2754
|
});
|
|
2448
2755
|
|
|
2449
2756
|
// src/domain/mappers/layout/sectionLayoutToComponent.ts
|
|
2450
|
-
var sectionLayoutToComponent = (uid, {
|
|
2757
|
+
var sectionLayoutToComponent = (uid, {
|
|
2758
|
+
analyticsId,
|
|
2759
|
+
control,
|
|
2760
|
+
shortTitle,
|
|
2761
|
+
title,
|
|
2762
|
+
components,
|
|
2763
|
+
callToAction,
|
|
2764
|
+
margin,
|
|
2765
|
+
tags
|
|
2766
|
+
}, mapperProps, schemaComponents) => {
|
|
2451
2767
|
return createSectionComponent({
|
|
2452
2768
|
uid,
|
|
2453
2769
|
analyticsId,
|
|
2454
2770
|
control,
|
|
2455
2771
|
title,
|
|
2772
|
+
shortTitle,
|
|
2456
2773
|
components: components.map(
|
|
2457
2774
|
(component, index) => mapLayoutToComponent(`${uid}.section-${index}`, component, mapperProps, schemaComponents)
|
|
2458
2775
|
),
|
|
@@ -2536,12 +2853,7 @@ var upsellLayoutToComponent = (uid, { analyticsId, callToAction, control, margin
|
|
|
2536
2853
|
media: getDomainLayerMedia({ media }),
|
|
2537
2854
|
tags,
|
|
2538
2855
|
text,
|
|
2539
|
-
dismiss: onDismiss ? ()
|
|
2540
|
-
const { url, method } = onDismiss;
|
|
2541
|
-
const body = method === "GET" ? void 0 : JSON.stringify(onDismiss.body);
|
|
2542
|
-
void mapperProps.httpClient(url, { method, body }).catch(() => {
|
|
2543
|
-
});
|
|
2544
|
-
} : void 0
|
|
2856
|
+
dismiss: onDismiss ? makeDismissHandler(onDismiss, mapperProps) : void 0
|
|
2545
2857
|
},
|
|
2546
2858
|
onComponentUpdate
|
|
2547
2859
|
);
|
|
@@ -2556,6 +2868,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2556
2868
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2557
2869
|
case "button":
|
|
2558
2870
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2871
|
+
case "collection":
|
|
2872
|
+
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2559
2873
|
case "columns":
|
|
2560
2874
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2561
2875
|
case "decision":
|
|
@@ -7809,8 +8123,22 @@ function pick(obj, ...keys) {
|
|
|
7809
8123
|
}
|
|
7810
8124
|
|
|
7811
8125
|
// src/renderers/mappers/alertComponentToProps.ts
|
|
7812
|
-
var alertComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
7813
|
-
|
|
8126
|
+
var alertComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8127
|
+
component,
|
|
8128
|
+
"uid",
|
|
8129
|
+
"analyticsId",
|
|
8130
|
+
"type",
|
|
8131
|
+
"context",
|
|
8132
|
+
"control",
|
|
8133
|
+
"margin",
|
|
8134
|
+
"markdown",
|
|
8135
|
+
"media",
|
|
8136
|
+
"tags",
|
|
8137
|
+
"title"
|
|
8138
|
+
)), {
|
|
8139
|
+
callToAction: mapCallToActionOptional(component.callToAction),
|
|
8140
|
+
onDismiss: component.dismiss,
|
|
8141
|
+
secondaryCallToAction: mapCallToActionOptional(component.secondaryCallToAction)
|
|
7814
8142
|
}), rendererMapperProps);
|
|
7815
8143
|
|
|
7816
8144
|
// src/renderers/mappers/allOfComponentToProps.ts
|
|
@@ -7929,6 +8257,35 @@ var mapBoxControl = ({
|
|
|
7929
8257
|
return control;
|
|
7930
8258
|
};
|
|
7931
8259
|
|
|
8260
|
+
// src/renderers/mappers/collectionComponentToProps.ts
|
|
8261
|
+
var collectionComponentToProps = (component, rendererMapperProps) => {
|
|
8262
|
+
var _a, _b, _c;
|
|
8263
|
+
const beforeSectionsProps = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
|
|
8264
|
+
(child) => componentToRendererProps(child, rendererMapperProps)
|
|
8265
|
+
);
|
|
8266
|
+
const afterSectionsProps = (_b = component.state.afterSections) == null ? void 0 : _b.map(
|
|
8267
|
+
(child) => componentToRendererProps(child, rendererMapperProps)
|
|
8268
|
+
);
|
|
8269
|
+
return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags")), rendererMapperProps), {
|
|
8270
|
+
status: component.status,
|
|
8271
|
+
state: __spreadProps(__spreadValues({}, component.state), {
|
|
8272
|
+
filters: (_c = component.state.filters) != null ? _c : [],
|
|
8273
|
+
sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
|
|
8274
|
+
callToAction: mapCallToActionOptional(section.callToAction),
|
|
8275
|
+
items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
8276
|
+
callToAction: mapCallToActionOptional(item.callToAction),
|
|
8277
|
+
additionalInfo: mapAdditionalInfo2(item.additionalInfo),
|
|
8278
|
+
disabled: rendererMapperProps.stepLoadingState !== "idle" || item.disabled
|
|
8279
|
+
}))
|
|
8280
|
+
})),
|
|
8281
|
+
beforeSectionsProps,
|
|
8282
|
+
beforeSections: beforeSectionsProps == null ? void 0 : beforeSectionsProps.map(rendererMapperProps.render),
|
|
8283
|
+
afterSectionsProps,
|
|
8284
|
+
afterSections: afterSectionsProps == null ? void 0 : afterSectionsProps.map(rendererMapperProps.render)
|
|
8285
|
+
})
|
|
8286
|
+
});
|
|
8287
|
+
};
|
|
8288
|
+
|
|
7932
8289
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
7933
8290
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
7934
8291
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8416,7 +8773,17 @@ var sectionComponentToProps = (component, rendererMapperProps) => {
|
|
|
8416
8773
|
const childrenProps = component.components.map(
|
|
8417
8774
|
(c) => componentToRendererProps(c, rendererMapperProps)
|
|
8418
8775
|
);
|
|
8419
|
-
return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8776
|
+
return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8777
|
+
component,
|
|
8778
|
+
"uid",
|
|
8779
|
+
"analyticsId",
|
|
8780
|
+
"type",
|
|
8781
|
+
"shortTitle",
|
|
8782
|
+
"title",
|
|
8783
|
+
"margin",
|
|
8784
|
+
"control",
|
|
8785
|
+
"tags"
|
|
8786
|
+
)), {
|
|
8420
8787
|
callToAction: mapCallToActionOptional(component.callToAction)
|
|
8421
8788
|
}), rendererMapperProps), {
|
|
8422
8789
|
children: childrenProps.map(rendererMapperProps.render),
|
|
@@ -8558,6 +8925,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8558
8925
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8559
8926
|
case "button":
|
|
8560
8927
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8928
|
+
case "collection":
|
|
8929
|
+
return collectionComponentToProps(component, rendererMapperProps);
|
|
8561
8930
|
case "columns":
|
|
8562
8931
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8563
8932
|
case "container":
|
|
@@ -8900,8 +9269,9 @@ function useDynamicFlow(props) {
|
|
|
8900
9269
|
);
|
|
8901
9270
|
return {
|
|
8902
9271
|
controller: {
|
|
8903
|
-
|
|
9272
|
+
getValue: () => rootComponent.getSubmittableValueSync(),
|
|
8904
9273
|
validate: () => rootComponent.validate(),
|
|
9274
|
+
/** @experimental This method may be changed or removed in the future without notice. */
|
|
8905
9275
|
getCurrentStep: () => {
|
|
8906
9276
|
var _a2, _b2;
|
|
8907
9277
|
return (_b2 = (_a2 = rootComponent.getStep()) == null ? void 0 : _a2.step) != null ? _b2 : null;
|