@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.mjs
CHANGED
|
@@ -852,6 +852,7 @@ var getChildren = (node) => {
|
|
|
852
852
|
return node.tabs.flatMap((c) => c.childrenProps);
|
|
853
853
|
case "alert":
|
|
854
854
|
case "button":
|
|
855
|
+
case "collection":
|
|
855
856
|
case "input-checkbox":
|
|
856
857
|
case "input-date":
|
|
857
858
|
case "decision":
|
|
@@ -1270,6 +1271,17 @@ var createAlertComponent = (props) => __spreadValues({
|
|
|
1270
1271
|
kind: "layout"
|
|
1271
1272
|
}, props);
|
|
1272
1273
|
|
|
1274
|
+
// src/domain/handlers/dismissHandler.ts
|
|
1275
|
+
var makeDismissHandler = (onDismiss, mapperProps) => () => {
|
|
1276
|
+
const { url, method, body, headers } = onDismiss;
|
|
1277
|
+
void mapperProps.httpClient(url, {
|
|
1278
|
+
method,
|
|
1279
|
+
body: method === "GET" ? void 0 : JSON.stringify(body),
|
|
1280
|
+
headers
|
|
1281
|
+
}).catch(() => {
|
|
1282
|
+
});
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1273
1285
|
// src/domain/mappers/utils/behavior-utils.ts
|
|
1274
1286
|
var getDomainLayerBehavior = ({ action, behavior: specBehavior }, stepActions, registerSubmissionBehavior) => {
|
|
1275
1287
|
if (specBehavior) {
|
|
@@ -1423,20 +1435,25 @@ var alertLayoutToComponent = (uid, {
|
|
|
1423
1435
|
context,
|
|
1424
1436
|
callToAction,
|
|
1425
1437
|
analyticsId,
|
|
1426
|
-
tags
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1438
|
+
tags,
|
|
1439
|
+
title,
|
|
1440
|
+
media,
|
|
1441
|
+
onDismiss,
|
|
1442
|
+
secondaryCallToAction
|
|
1443
|
+
}, mapperProps) => createAlertComponent({
|
|
1444
|
+
uid,
|
|
1445
|
+
analyticsId,
|
|
1446
|
+
control,
|
|
1447
|
+
markdown,
|
|
1448
|
+
margin: margin != null ? margin : "md",
|
|
1449
|
+
callToAction: getDomainLayerCallToAction(callToAction, mapperProps),
|
|
1450
|
+
context: mapLegacyContext(context != null ? context : "neutral"),
|
|
1451
|
+
tags,
|
|
1452
|
+
title,
|
|
1453
|
+
media,
|
|
1454
|
+
dismiss: onDismiss ? makeDismissHandler(onDismiss, mapperProps) : void 0,
|
|
1455
|
+
secondaryCallToAction: getDomainLayerCallToAction(secondaryCallToAction, mapperProps)
|
|
1456
|
+
});
|
|
1440
1457
|
|
|
1441
1458
|
// src/domain/components/BoxComponent.ts
|
|
1442
1459
|
var createBoxComponent = (props) => __spreadProps(__spreadValues({}, props), {
|
|
@@ -1469,6 +1486,367 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
|
|
|
1469
1486
|
)
|
|
1470
1487
|
});
|
|
1471
1488
|
|
|
1489
|
+
// src/domain/mappers/utils/utils.ts
|
|
1490
|
+
var mapInlineAlert = (alert) => {
|
|
1491
|
+
return alert ? {
|
|
1492
|
+
content: alert.content,
|
|
1493
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1494
|
+
} : void 0;
|
|
1495
|
+
};
|
|
1496
|
+
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1497
|
+
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1498
|
+
if (info) {
|
|
1499
|
+
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1500
|
+
const isLink = behavior.type === "link";
|
|
1501
|
+
return {
|
|
1502
|
+
text: info.text,
|
|
1503
|
+
href: isLink ? behavior.url : void 0,
|
|
1504
|
+
hrefWithTracking: getHrefWithTracking({
|
|
1505
|
+
behavior,
|
|
1506
|
+
onBehavior,
|
|
1507
|
+
trackEvent
|
|
1508
|
+
}),
|
|
1509
|
+
accessibilityDescription: info.accessibilityDescription,
|
|
1510
|
+
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1511
|
+
void onBehavior(behavior);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
return void 0;
|
|
1516
|
+
};
|
|
1517
|
+
var mapSchemaAlert = (alert) => {
|
|
1518
|
+
return alert ? {
|
|
1519
|
+
content: alert.markdown,
|
|
1520
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1521
|
+
} : void 0;
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
// src/domain/components/utils/debounce.ts
|
|
1525
|
+
var debounce = (callback, waitMs) => {
|
|
1526
|
+
let timeoutId = null;
|
|
1527
|
+
let lastArgs = null;
|
|
1528
|
+
const clearTimer = () => {
|
|
1529
|
+
if (timeoutId !== null) {
|
|
1530
|
+
clearTimeout(timeoutId);
|
|
1531
|
+
timeoutId = null;
|
|
1532
|
+
}
|
|
1533
|
+
lastArgs = null;
|
|
1534
|
+
};
|
|
1535
|
+
const debouncedFn = (...args) => {
|
|
1536
|
+
lastArgs = args;
|
|
1537
|
+
if (timeoutId !== null) {
|
|
1538
|
+
clearTimeout(timeoutId);
|
|
1539
|
+
}
|
|
1540
|
+
timeoutId = setTimeout(() => {
|
|
1541
|
+
callback(...lastArgs);
|
|
1542
|
+
timeoutId = null;
|
|
1543
|
+
lastArgs = null;
|
|
1544
|
+
}, waitMs);
|
|
1545
|
+
};
|
|
1546
|
+
debouncedFn.cancel = () => {
|
|
1547
|
+
if (timeoutId !== null) {
|
|
1548
|
+
clearTimer();
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
debouncedFn.flush = () => {
|
|
1552
|
+
if (timeoutId !== null) {
|
|
1553
|
+
callback(...lastArgs);
|
|
1554
|
+
clearTimer();
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
return debouncedFn;
|
|
1558
|
+
};
|
|
1559
|
+
|
|
1560
|
+
// src/domain/components/collectionComponent/CollectionComponent.ts
|
|
1561
|
+
var DEBOUNCE_TIME = 800;
|
|
1562
|
+
var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
|
|
1563
|
+
const { uid, analyticsId, control, margin, tags, state } = props;
|
|
1564
|
+
const update = getInputUpdateFunction(onComponentUpdate);
|
|
1565
|
+
let abortController = new AbortController();
|
|
1566
|
+
const query = (mode) => {
|
|
1567
|
+
var _a, _b;
|
|
1568
|
+
abortController.abort();
|
|
1569
|
+
abortController = new AbortController();
|
|
1570
|
+
const { signal } = abortController;
|
|
1571
|
+
queryFunction({
|
|
1572
|
+
searchParam: (_a = component.state.search) == null ? void 0 : _a.param,
|
|
1573
|
+
query: (_b = component.state.search) == null ? void 0 : _b.query,
|
|
1574
|
+
cursor: mode === "pagination" ? component.state.nextCursor : void 0,
|
|
1575
|
+
signal,
|
|
1576
|
+
filters: component.state.filters
|
|
1577
|
+
}).then((response) => {
|
|
1578
|
+
if (!response) {
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
update(component, (draft) => {
|
|
1582
|
+
var _a2, _b2;
|
|
1583
|
+
draft.state = {
|
|
1584
|
+
sections: mode === "pagination" ? mergeSections(component.state.sections, response.sections) : response.sections,
|
|
1585
|
+
nextCursor: response.nextCursor,
|
|
1586
|
+
filters: response.filters ? mapFilters(response.filters) : component.state.filters,
|
|
1587
|
+
search: response.search ? mapSearch(response.search) : component.state.search,
|
|
1588
|
+
beforeSections: (_a2 = response.beforeSections) != null ? _a2 : component.state.beforeSections,
|
|
1589
|
+
afterSections: (_b2 = response.afterSections) != null ? _b2 : component.state.afterSections
|
|
1590
|
+
};
|
|
1591
|
+
draft.status = {
|
|
1592
|
+
type: "idle",
|
|
1593
|
+
loadMore: response.nextCursor ? paginate : void 0
|
|
1594
|
+
};
|
|
1595
|
+
});
|
|
1596
|
+
}).catch(() => {
|
|
1597
|
+
if (!signal.aborted) {
|
|
1598
|
+
update(component, (draft) => {
|
|
1599
|
+
draft.state = {
|
|
1600
|
+
filters: component.state.filters,
|
|
1601
|
+
search: component.state.search,
|
|
1602
|
+
sections: []
|
|
1603
|
+
};
|
|
1604
|
+
draft.status = { type: "error", reason: mode, retry: () => query(mode) };
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
};
|
|
1609
|
+
const debouncedQuery = debounce(query, DEBOUNCE_TIME);
|
|
1610
|
+
const search = () => {
|
|
1611
|
+
abortController.abort();
|
|
1612
|
+
debouncedQuery("search");
|
|
1613
|
+
};
|
|
1614
|
+
const filter = () => {
|
|
1615
|
+
debouncedQuery("search");
|
|
1616
|
+
debouncedQuery.flush();
|
|
1617
|
+
};
|
|
1618
|
+
const paginate = () => query("pagination");
|
|
1619
|
+
const selectFilter = (filterIndex, optionIndex) => {
|
|
1620
|
+
var _a;
|
|
1621
|
+
const selected = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
|
|
1622
|
+
if (!selected) {
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
const currentValue = selected.options[optionIndex].selected;
|
|
1626
|
+
update(component, (draft) => {
|
|
1627
|
+
if (!draft.state.filters) {
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
const draftFilter = draft.state.filters[filterIndex];
|
|
1631
|
+
if (selected.multiSelect) {
|
|
1632
|
+
draftFilter.options[optionIndex].selected = !currentValue;
|
|
1633
|
+
} else {
|
|
1634
|
+
draftFilter.options.forEach((draftOption, index) => {
|
|
1635
|
+
draftOption.selected = index === optionIndex ? !currentValue : false;
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1639
|
+
});
|
|
1640
|
+
filter();
|
|
1641
|
+
};
|
|
1642
|
+
const mapFilters = (filters) => filters == null ? void 0 : filters.map((f, filterIndex) => {
|
|
1643
|
+
var _a;
|
|
1644
|
+
return __spreadProps(__spreadValues({}, f), {
|
|
1645
|
+
options: (_a = f.options) == null ? void 0 : _a.map((option, optionIndex) => {
|
|
1646
|
+
var _a2;
|
|
1647
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1648
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1649
|
+
onSelect: () => selectFilter(filterIndex, optionIndex)
|
|
1650
|
+
});
|
|
1651
|
+
})
|
|
1652
|
+
});
|
|
1653
|
+
});
|
|
1654
|
+
const mapSearch = (searchConfig) => searchConfig ? __spreadProps(__spreadValues({
|
|
1655
|
+
query: ""
|
|
1656
|
+
}, searchConfig), {
|
|
1657
|
+
onChange(value) {
|
|
1658
|
+
update(component, (draft) => {
|
|
1659
|
+
if (draft.state.search) {
|
|
1660
|
+
draft.state.search.query = value;
|
|
1661
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
search();
|
|
1665
|
+
}
|
|
1666
|
+
}) : void 0;
|
|
1667
|
+
const component = {
|
|
1668
|
+
type: "collection",
|
|
1669
|
+
kind: "layout",
|
|
1670
|
+
uid,
|
|
1671
|
+
analyticsId,
|
|
1672
|
+
control,
|
|
1673
|
+
margin,
|
|
1674
|
+
tags,
|
|
1675
|
+
status: {
|
|
1676
|
+
type: "idle",
|
|
1677
|
+
loadMore: state.nextCursor ? () => query("pagination") : void 0
|
|
1678
|
+
},
|
|
1679
|
+
state: __spreadProps(__spreadValues({}, state), {
|
|
1680
|
+
filters: mapFilters(state.filters),
|
|
1681
|
+
search: mapSearch(props.search)
|
|
1682
|
+
})
|
|
1683
|
+
};
|
|
1684
|
+
return component;
|
|
1685
|
+
};
|
|
1686
|
+
var mergeSections = (existing, incoming) => {
|
|
1687
|
+
const knownIds = new Set(existing.map((section) => section.id));
|
|
1688
|
+
const newSections = incoming.filter((section) => !knownIds.has(section.id));
|
|
1689
|
+
const merged = existing.map((section) => {
|
|
1690
|
+
const match = incoming.find((s) => s.id === section.id);
|
|
1691
|
+
if (!match) return section;
|
|
1692
|
+
return __spreadProps(__spreadValues({}, match), { items: [...section.items, ...match.items] });
|
|
1693
|
+
});
|
|
1694
|
+
return [...merged, ...newSections];
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
// src/domain/features/collection/getPerformCollectionQuery.ts
|
|
1698
|
+
var getPerformCollectionQuery = (httpClient, baseRequest, mapState) => {
|
|
1699
|
+
let latestSuccessfulRequestHash = null;
|
|
1700
|
+
let latestSuccessfulResults = null;
|
|
1701
|
+
return async (props) => {
|
|
1702
|
+
const requestHash = hashRequest(props);
|
|
1703
|
+
if (requestHash !== latestSuccessfulRequestHash) {
|
|
1704
|
+
const response = await performRequest(baseRequest, props, httpClient);
|
|
1705
|
+
const results = await parseResponse(response);
|
|
1706
|
+
latestSuccessfulRequestHash = requestHash;
|
|
1707
|
+
const mappedState = mapState(results);
|
|
1708
|
+
latestSuccessfulResults = mappedState;
|
|
1709
|
+
return mappedState;
|
|
1710
|
+
}
|
|
1711
|
+
return latestSuccessfulResults;
|
|
1712
|
+
};
|
|
1713
|
+
};
|
|
1714
|
+
var performRequest = (request, queryProps, httpClient) => {
|
|
1715
|
+
const { url, method, body, headers } = request;
|
|
1716
|
+
if (method === "GET") {
|
|
1717
|
+
return httpClient(buildQueryURL(url, queryProps), {
|
|
1718
|
+
method,
|
|
1719
|
+
headers: __spreadProps(__spreadValues({}, headers), {
|
|
1720
|
+
"Content-Type": "application/json"
|
|
1721
|
+
}),
|
|
1722
|
+
signal: queryProps.signal
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
return httpClient(url, {
|
|
1726
|
+
method,
|
|
1727
|
+
headers: __spreadProps(__spreadValues({}, headers), {
|
|
1728
|
+
"Content-Type": "application/json"
|
|
1729
|
+
}),
|
|
1730
|
+
signal: queryProps.signal,
|
|
1731
|
+
body: JSON.stringify(__spreadValues(__spreadValues({}, body && typeof body === "object" && !isArray(body) ? body : {}), buildRequestBody(queryProps)))
|
|
1732
|
+
});
|
|
1733
|
+
};
|
|
1734
|
+
var buildQueryURL = (url, { searchParam, query, cursor, filters = [] }) => {
|
|
1735
|
+
const [baseUrl, queryParams] = splitUrlAndParams(url);
|
|
1736
|
+
const params = new URLSearchParams(queryParams);
|
|
1737
|
+
if (searchParam && query) {
|
|
1738
|
+
params.append(searchParam, query);
|
|
1739
|
+
}
|
|
1740
|
+
if (cursor) {
|
|
1741
|
+
params.append("cursor", cursor);
|
|
1742
|
+
}
|
|
1743
|
+
getFilterValues(filters).forEach(([key, value]) => {
|
|
1744
|
+
if (typeof value === "string") {
|
|
1745
|
+
params.append(key, value);
|
|
1746
|
+
} else {
|
|
1747
|
+
value.forEach((v) => params.append(key, v));
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
return `${baseUrl}?${params.toString()}`;
|
|
1751
|
+
};
|
|
1752
|
+
var splitUrlAndParams = (url) => {
|
|
1753
|
+
const [baseUrl, ...rest] = url.split("?");
|
|
1754
|
+
return [baseUrl, rest.join("")];
|
|
1755
|
+
};
|
|
1756
|
+
var buildRequestBody = ({
|
|
1757
|
+
searchParam,
|
|
1758
|
+
query,
|
|
1759
|
+
cursor,
|
|
1760
|
+
filters = []
|
|
1761
|
+
}) => __spreadProps(__spreadValues(__spreadValues({}, searchParam && query ? { [searchParam]: query } : {}), Object.fromEntries(getFilterValues(filters))), {
|
|
1762
|
+
cursor
|
|
1763
|
+
});
|
|
1764
|
+
var getFilterValues = (filters) => {
|
|
1765
|
+
return filters.map((filter) => {
|
|
1766
|
+
const { multiSelect, param } = filter;
|
|
1767
|
+
const values = filter.options.filter((option) => option.selected).map((option) => option.value);
|
|
1768
|
+
if (values.length === 0) {
|
|
1769
|
+
return void 0;
|
|
1770
|
+
}
|
|
1771
|
+
return [param, multiSelect ? values : values[0]];
|
|
1772
|
+
}).filter((value) => value !== void 0);
|
|
1773
|
+
};
|
|
1774
|
+
var parseResponse = async (response) => {
|
|
1775
|
+
if (response.ok) {
|
|
1776
|
+
const body = await response.json().catch(() => null);
|
|
1777
|
+
return body;
|
|
1778
|
+
}
|
|
1779
|
+
throw Error("error response");
|
|
1780
|
+
};
|
|
1781
|
+
var hashRequest = ({
|
|
1782
|
+
query,
|
|
1783
|
+
cursor,
|
|
1784
|
+
filters
|
|
1785
|
+
}) => JSON.stringify({ query, cursor, filters: getFilterValues(filters != null ? filters : []) });
|
|
1786
|
+
|
|
1787
|
+
// src/domain/mappers/layout/collectionLayoutToComponent.ts
|
|
1788
|
+
var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, search, tags, baseRequest }, mapperProps) => {
|
|
1789
|
+
const { httpClient, onComponentUpdate } = mapperProps;
|
|
1790
|
+
const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
|
|
1791
|
+
const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
|
|
1792
|
+
const queryFunction = getPerformCollectionQuery(httpClient, baseRequest, mapState);
|
|
1793
|
+
const component = createCollectionComponent(
|
|
1794
|
+
{
|
|
1795
|
+
uid,
|
|
1796
|
+
analyticsId,
|
|
1797
|
+
control,
|
|
1798
|
+
margin: margin != null ? margin : "md",
|
|
1799
|
+
tags,
|
|
1800
|
+
state: mapState(initialState),
|
|
1801
|
+
search
|
|
1802
|
+
},
|
|
1803
|
+
onComponentUpdate,
|
|
1804
|
+
queryFunction
|
|
1805
|
+
);
|
|
1806
|
+
return component;
|
|
1807
|
+
};
|
|
1808
|
+
var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
|
|
1809
|
+
var _a, _b, _c;
|
|
1810
|
+
return {
|
|
1811
|
+
sections: specState.sections.map((section) => {
|
|
1812
|
+
return {
|
|
1813
|
+
id: section.id,
|
|
1814
|
+
title: section.title,
|
|
1815
|
+
callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
|
|
1816
|
+
items: section.items.map((item) => {
|
|
1817
|
+
const behavior = getDomainLayerBehavior(
|
|
1818
|
+
{ behavior: item.primaryBehavior },
|
|
1819
|
+
[],
|
|
1820
|
+
mapperProps.registerSubmissionBehavior
|
|
1821
|
+
);
|
|
1822
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
1823
|
+
id: item.entityId,
|
|
1824
|
+
onClick: item.primaryBehavior ? () => {
|
|
1825
|
+
void mapperProps.onBehavior(behavior);
|
|
1826
|
+
} : void 0,
|
|
1827
|
+
callToAction: getDomainLayerCallToAction(item.callToAction, mapperProps),
|
|
1828
|
+
inlineAlert: mapInlineAlert(item.inlineAlert)
|
|
1829
|
+
});
|
|
1830
|
+
})
|
|
1831
|
+
};
|
|
1832
|
+
}),
|
|
1833
|
+
filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
|
|
1834
|
+
options: filter.options.map((option) => {
|
|
1835
|
+
var _a2;
|
|
1836
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1837
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1838
|
+
onSelect: () => {
|
|
1839
|
+
}
|
|
1840
|
+
// noop - this gets added during mapping
|
|
1841
|
+
});
|
|
1842
|
+
})
|
|
1843
|
+
})),
|
|
1844
|
+
beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
|
|
1845
|
+
afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
|
|
1846
|
+
nextCursor: specState.nextCursor
|
|
1847
|
+
};
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1472
1850
|
// src/domain/components/ButtonComponent.ts
|
|
1473
1851
|
var createButtonComponent = (props) => __spreadValues({
|
|
1474
1852
|
type: "button",
|
|
@@ -1637,41 +2015,6 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1637
2015
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1638
2016
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1639
2017
|
|
|
1640
|
-
// src/domain/mappers/utils/utils.ts
|
|
1641
|
-
var mapInlineAlert = (alert) => {
|
|
1642
|
-
return alert ? {
|
|
1643
|
-
content: alert.content,
|
|
1644
|
-
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1645
|
-
} : void 0;
|
|
1646
|
-
};
|
|
1647
|
-
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1648
|
-
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1649
|
-
if (info) {
|
|
1650
|
-
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1651
|
-
const isLink = behavior.type === "link";
|
|
1652
|
-
return {
|
|
1653
|
-
text: info.text,
|
|
1654
|
-
href: isLink ? behavior.url : void 0,
|
|
1655
|
-
hrefWithTracking: getHrefWithTracking({
|
|
1656
|
-
behavior,
|
|
1657
|
-
onBehavior,
|
|
1658
|
-
trackEvent
|
|
1659
|
-
}),
|
|
1660
|
-
accessibilityDescription: info.accessibilityDescription,
|
|
1661
|
-
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1662
|
-
void onBehavior(behavior);
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
|
-
return void 0;
|
|
1667
|
-
};
|
|
1668
|
-
var mapSchemaAlert = (alert) => {
|
|
1669
|
-
return alert ? {
|
|
1670
|
-
content: alert.markdown,
|
|
1671
|
-
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1672
|
-
} : void 0;
|
|
1673
|
-
};
|
|
1674
|
-
|
|
1675
2018
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1676
2019
|
var decisionLayoutToComponent = (uid, {
|
|
1677
2020
|
analyticsId,
|
|
@@ -2147,44 +2490,8 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2147
2490
|
});
|
|
2148
2491
|
};
|
|
2149
2492
|
|
|
2150
|
-
// src/domain/components/utils/debounce.ts
|
|
2151
|
-
var debounce = (callback, waitMs) => {
|
|
2152
|
-
let timeoutId = null;
|
|
2153
|
-
let lastArgs = null;
|
|
2154
|
-
const clearTimer = () => {
|
|
2155
|
-
if (timeoutId !== null) {
|
|
2156
|
-
clearTimeout(timeoutId);
|
|
2157
|
-
timeoutId = null;
|
|
2158
|
-
}
|
|
2159
|
-
lastArgs = null;
|
|
2160
|
-
};
|
|
2161
|
-
const debouncedFn = (...args) => {
|
|
2162
|
-
lastArgs = args;
|
|
2163
|
-
if (timeoutId !== null) {
|
|
2164
|
-
clearTimeout(timeoutId);
|
|
2165
|
-
}
|
|
2166
|
-
timeoutId = setTimeout(() => {
|
|
2167
|
-
callback(...lastArgs);
|
|
2168
|
-
timeoutId = null;
|
|
2169
|
-
lastArgs = null;
|
|
2170
|
-
}, waitMs);
|
|
2171
|
-
};
|
|
2172
|
-
debouncedFn.cancel = () => {
|
|
2173
|
-
if (timeoutId !== null) {
|
|
2174
|
-
clearTimer();
|
|
2175
|
-
}
|
|
2176
|
-
};
|
|
2177
|
-
debouncedFn.flush = () => {
|
|
2178
|
-
if (timeoutId !== null) {
|
|
2179
|
-
callback(...lastArgs);
|
|
2180
|
-
clearTimer();
|
|
2181
|
-
}
|
|
2182
|
-
};
|
|
2183
|
-
return debouncedFn;
|
|
2184
|
-
};
|
|
2185
|
-
|
|
2186
2493
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2187
|
-
var
|
|
2494
|
+
var DEBOUNCE_TIME2 = 400;
|
|
2188
2495
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2189
2496
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2190
2497
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2214,7 +2521,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2214
2521
|
}
|
|
2215
2522
|
});
|
|
2216
2523
|
};
|
|
2217
|
-
const debouncedSearch = debounce(search,
|
|
2524
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME2);
|
|
2218
2525
|
const component = {
|
|
2219
2526
|
type: "search",
|
|
2220
2527
|
kind: "layout",
|
|
@@ -2269,10 +2576,10 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2269
2576
|
|
|
2270
2577
|
// src/domain/features/search/getPerformSearchFunction.ts
|
|
2271
2578
|
var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultConfig) => {
|
|
2272
|
-
let latestSuccessfulRequestHash =
|
|
2579
|
+
let latestSuccessfulRequestHash = hashRequest2("", defaultConfig);
|
|
2273
2580
|
let latestSuccessfulResults = null;
|
|
2274
2581
|
return async ({ config = defaultConfig, query, signal }) => {
|
|
2275
|
-
const requestHash =
|
|
2582
|
+
const requestHash = hashRequest2(query, config);
|
|
2276
2583
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2277
2584
|
const { method, param, url } = config;
|
|
2278
2585
|
const headers = { "Content-Type": "application/json" };
|
|
@@ -2286,7 +2593,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2286
2593
|
signal,
|
|
2287
2594
|
body: JSON.stringify({ [param]: query })
|
|
2288
2595
|
}));
|
|
2289
|
-
const results = await
|
|
2596
|
+
const results = await parseResponse2(response);
|
|
2290
2597
|
latestSuccessfulRequestHash = requestHash;
|
|
2291
2598
|
if (results.type === "layout") {
|
|
2292
2599
|
const mappedLayoutResult = {
|
|
@@ -2302,7 +2609,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2302
2609
|
return latestSuccessfulResults;
|
|
2303
2610
|
};
|
|
2304
2611
|
};
|
|
2305
|
-
var
|
|
2612
|
+
var parseResponse2 = async (response) => {
|
|
2306
2613
|
if (response.ok) {
|
|
2307
2614
|
const body = await response.json().catch(() => null);
|
|
2308
2615
|
if (isValidResponseBody(body)) {
|
|
@@ -2339,7 +2646,7 @@ var isValidResponseBody = (body) => {
|
|
|
2339
2646
|
}
|
|
2340
2647
|
return false;
|
|
2341
2648
|
};
|
|
2342
|
-
var
|
|
2649
|
+
var hashRequest2 = (query, config) => JSON.stringify({ query, config });
|
|
2343
2650
|
|
|
2344
2651
|
// src/domain/mappers/layout/searchLayoutToComponent.ts
|
|
2345
2652
|
var searchLayoutToComponent = (uid, {
|
|
@@ -2416,12 +2723,22 @@ var createSectionComponent = (props) => __spreadProps(__spreadValues({}, props),
|
|
|
2416
2723
|
});
|
|
2417
2724
|
|
|
2418
2725
|
// src/domain/mappers/layout/sectionLayoutToComponent.ts
|
|
2419
|
-
var sectionLayoutToComponent = (uid, {
|
|
2726
|
+
var sectionLayoutToComponent = (uid, {
|
|
2727
|
+
analyticsId,
|
|
2728
|
+
control,
|
|
2729
|
+
shortTitle,
|
|
2730
|
+
title,
|
|
2731
|
+
components,
|
|
2732
|
+
callToAction,
|
|
2733
|
+
margin,
|
|
2734
|
+
tags
|
|
2735
|
+
}, mapperProps, schemaComponents) => {
|
|
2420
2736
|
return createSectionComponent({
|
|
2421
2737
|
uid,
|
|
2422
2738
|
analyticsId,
|
|
2423
2739
|
control,
|
|
2424
2740
|
title,
|
|
2741
|
+
shortTitle,
|
|
2425
2742
|
components: components.map(
|
|
2426
2743
|
(component, index) => mapLayoutToComponent(`${uid}.section-${index}`, component, mapperProps, schemaComponents)
|
|
2427
2744
|
),
|
|
@@ -2505,12 +2822,7 @@ var upsellLayoutToComponent = (uid, { analyticsId, callToAction, control, margin
|
|
|
2505
2822
|
media: getDomainLayerMedia({ media }),
|
|
2506
2823
|
tags,
|
|
2507
2824
|
text,
|
|
2508
|
-
dismiss: onDismiss ? ()
|
|
2509
|
-
const { url, method } = onDismiss;
|
|
2510
|
-
const body = method === "GET" ? void 0 : JSON.stringify(onDismiss.body);
|
|
2511
|
-
void mapperProps.httpClient(url, { method, body }).catch(() => {
|
|
2512
|
-
});
|
|
2513
|
-
} : void 0
|
|
2825
|
+
dismiss: onDismiss ? makeDismissHandler(onDismiss, mapperProps) : void 0
|
|
2514
2826
|
},
|
|
2515
2827
|
onComponentUpdate
|
|
2516
2828
|
);
|
|
@@ -2525,6 +2837,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2525
2837
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2526
2838
|
case "button":
|
|
2527
2839
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2840
|
+
case "collection":
|
|
2841
|
+
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2528
2842
|
case "columns":
|
|
2529
2843
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2530
2844
|
case "decision":
|
|
@@ -7778,8 +8092,22 @@ function pick(obj, ...keys) {
|
|
|
7778
8092
|
}
|
|
7779
8093
|
|
|
7780
8094
|
// src/renderers/mappers/alertComponentToProps.ts
|
|
7781
|
-
var alertComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
7782
|
-
|
|
8095
|
+
var alertComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8096
|
+
component,
|
|
8097
|
+
"uid",
|
|
8098
|
+
"analyticsId",
|
|
8099
|
+
"type",
|
|
8100
|
+
"context",
|
|
8101
|
+
"control",
|
|
8102
|
+
"margin",
|
|
8103
|
+
"markdown",
|
|
8104
|
+
"media",
|
|
8105
|
+
"tags",
|
|
8106
|
+
"title"
|
|
8107
|
+
)), {
|
|
8108
|
+
callToAction: mapCallToActionOptional(component.callToAction),
|
|
8109
|
+
onDismiss: component.dismiss,
|
|
8110
|
+
secondaryCallToAction: mapCallToActionOptional(component.secondaryCallToAction)
|
|
7783
8111
|
}), rendererMapperProps);
|
|
7784
8112
|
|
|
7785
8113
|
// src/renderers/mappers/allOfComponentToProps.ts
|
|
@@ -7898,6 +8226,35 @@ var mapBoxControl = ({
|
|
|
7898
8226
|
return control;
|
|
7899
8227
|
};
|
|
7900
8228
|
|
|
8229
|
+
// src/renderers/mappers/collectionComponentToProps.ts
|
|
8230
|
+
var collectionComponentToProps = (component, rendererMapperProps) => {
|
|
8231
|
+
var _a, _b, _c;
|
|
8232
|
+
const beforeSectionsProps = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
|
|
8233
|
+
(child) => componentToRendererProps(child, rendererMapperProps)
|
|
8234
|
+
);
|
|
8235
|
+
const afterSectionsProps = (_b = component.state.afterSections) == null ? void 0 : _b.map(
|
|
8236
|
+
(child) => componentToRendererProps(child, rendererMapperProps)
|
|
8237
|
+
);
|
|
8238
|
+
return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags")), rendererMapperProps), {
|
|
8239
|
+
status: component.status,
|
|
8240
|
+
state: __spreadProps(__spreadValues({}, component.state), {
|
|
8241
|
+
filters: (_c = component.state.filters) != null ? _c : [],
|
|
8242
|
+
sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
|
|
8243
|
+
callToAction: mapCallToActionOptional(section.callToAction),
|
|
8244
|
+
items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
8245
|
+
callToAction: mapCallToActionOptional(item.callToAction),
|
|
8246
|
+
additionalInfo: mapAdditionalInfo2(item.additionalInfo),
|
|
8247
|
+
disabled: rendererMapperProps.stepLoadingState !== "idle" || item.disabled
|
|
8248
|
+
}))
|
|
8249
|
+
})),
|
|
8250
|
+
beforeSectionsProps,
|
|
8251
|
+
beforeSections: beforeSectionsProps == null ? void 0 : beforeSectionsProps.map(rendererMapperProps.render),
|
|
8252
|
+
afterSectionsProps,
|
|
8253
|
+
afterSections: afterSectionsProps == null ? void 0 : afterSectionsProps.map(rendererMapperProps.render)
|
|
8254
|
+
})
|
|
8255
|
+
});
|
|
8256
|
+
};
|
|
8257
|
+
|
|
7901
8258
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
7902
8259
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
7903
8260
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8385,7 +8742,17 @@ var sectionComponentToProps = (component, rendererMapperProps) => {
|
|
|
8385
8742
|
const childrenProps = component.components.map(
|
|
8386
8743
|
(c) => componentToRendererProps(c, rendererMapperProps)
|
|
8387
8744
|
);
|
|
8388
|
-
return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8745
|
+
return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, pick(
|
|
8746
|
+
component,
|
|
8747
|
+
"uid",
|
|
8748
|
+
"analyticsId",
|
|
8749
|
+
"type",
|
|
8750
|
+
"shortTitle",
|
|
8751
|
+
"title",
|
|
8752
|
+
"margin",
|
|
8753
|
+
"control",
|
|
8754
|
+
"tags"
|
|
8755
|
+
)), {
|
|
8389
8756
|
callToAction: mapCallToActionOptional(component.callToAction)
|
|
8390
8757
|
}), rendererMapperProps), {
|
|
8391
8758
|
children: childrenProps.map(rendererMapperProps.render),
|
|
@@ -8527,6 +8894,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8527
8894
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8528
8895
|
case "button":
|
|
8529
8896
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8897
|
+
case "collection":
|
|
8898
|
+
return collectionComponentToProps(component, rendererMapperProps);
|
|
8530
8899
|
case "columns":
|
|
8531
8900
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8532
8901
|
case "container":
|
|
@@ -8869,8 +9238,9 @@ function useDynamicFlow(props) {
|
|
|
8869
9238
|
);
|
|
8870
9239
|
return {
|
|
8871
9240
|
controller: {
|
|
8872
|
-
|
|
9241
|
+
getValue: () => rootComponent.getSubmittableValueSync(),
|
|
8873
9242
|
validate: () => rootComponent.validate(),
|
|
9243
|
+
/** @experimental This method may be changed or removed in the future without notice. */
|
|
8874
9244
|
getCurrentStep: () => {
|
|
8875
9245
|
var _a2, _b2;
|
|
8876
9246
|
return (_b2 = (_a2 = rootComponent.getStep()) == null ? void 0 : _a2.step) != null ? _b2 : null;
|