@wise/dynamic-flow-client 5.19.0 → 5.20.0-experimental-2dcb025
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 +364 -77
- package/build/main.mjs +364 -77
- package/build/tsconfig.types.tsbuildinfo +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/applyCollectionResponse.d.ts +3 -0
- package/build/types/domain/components/collectionComponent/applyCollectionResponse.d.ts.map +1 -0
- package/build/types/domain/components/collectionComponent/types.d.ts +73 -0
- package/build/types/domain/components/collectionComponent/types.d.ts.map +1 -0
- package/build/types/domain/features/collection/getPerformCollectionQueryFunction.d.ts +12 -0
- package/build/types/domain/features/collection/getPerformCollectionQueryFunction.d.ts.map +1 -0
- 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/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/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/test-utils/getMergedTestRenderers.d.ts +1 -1
- package/build/types/test-utils/getMergedTestRenderers.d.ts.map +1 -1
- package/package.json +4 -4
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":
|
|
@@ -1500,6 +1501,339 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
|
|
|
1500
1501
|
)
|
|
1501
1502
|
});
|
|
1502
1503
|
|
|
1504
|
+
// src/domain/mappers/utils/utils.ts
|
|
1505
|
+
var mapInlineAlert = (alert) => {
|
|
1506
|
+
return alert ? {
|
|
1507
|
+
content: alert.content,
|
|
1508
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1509
|
+
} : void 0;
|
|
1510
|
+
};
|
|
1511
|
+
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1512
|
+
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1513
|
+
if (info) {
|
|
1514
|
+
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1515
|
+
const isLink = behavior.type === "link";
|
|
1516
|
+
return {
|
|
1517
|
+
text: info.text,
|
|
1518
|
+
href: isLink ? behavior.url : void 0,
|
|
1519
|
+
hrefWithTracking: getHrefWithTracking({
|
|
1520
|
+
behavior,
|
|
1521
|
+
onBehavior,
|
|
1522
|
+
trackEvent
|
|
1523
|
+
}),
|
|
1524
|
+
accessibilityDescription: info.accessibilityDescription,
|
|
1525
|
+
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1526
|
+
void onBehavior(behavior);
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
return void 0;
|
|
1531
|
+
};
|
|
1532
|
+
var mapSchemaAlert = (alert) => {
|
|
1533
|
+
return alert ? {
|
|
1534
|
+
content: alert.markdown,
|
|
1535
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1536
|
+
} : void 0;
|
|
1537
|
+
};
|
|
1538
|
+
|
|
1539
|
+
// src/domain/components/utils/debounce.ts
|
|
1540
|
+
var debounce = (callback, waitMs) => {
|
|
1541
|
+
let timeoutId = null;
|
|
1542
|
+
let lastArgs = null;
|
|
1543
|
+
const clearTimer = () => {
|
|
1544
|
+
if (timeoutId !== null) {
|
|
1545
|
+
clearTimeout(timeoutId);
|
|
1546
|
+
timeoutId = null;
|
|
1547
|
+
}
|
|
1548
|
+
lastArgs = null;
|
|
1549
|
+
};
|
|
1550
|
+
const debouncedFn = (...args) => {
|
|
1551
|
+
lastArgs = args;
|
|
1552
|
+
if (timeoutId !== null) {
|
|
1553
|
+
clearTimeout(timeoutId);
|
|
1554
|
+
}
|
|
1555
|
+
timeoutId = setTimeout(() => {
|
|
1556
|
+
callback(...lastArgs);
|
|
1557
|
+
timeoutId = null;
|
|
1558
|
+
lastArgs = null;
|
|
1559
|
+
}, waitMs);
|
|
1560
|
+
};
|
|
1561
|
+
debouncedFn.cancel = () => {
|
|
1562
|
+
if (timeoutId !== null) {
|
|
1563
|
+
clearTimer();
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
debouncedFn.flush = () => {
|
|
1567
|
+
if (timeoutId !== null) {
|
|
1568
|
+
callback(...lastArgs);
|
|
1569
|
+
clearTimer();
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
return debouncedFn;
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1575
|
+
// src/domain/components/collectionComponent/applyCollectionResponse.ts
|
|
1576
|
+
var applyCollectionResponse = (currentState, response, isPaginated) => {
|
|
1577
|
+
var _a, _b, _c, _d;
|
|
1578
|
+
const sections = isPaginated ? mergeSections(currentState.sections, response.sections) : response.sections;
|
|
1579
|
+
return {
|
|
1580
|
+
sections,
|
|
1581
|
+
nextCursor: response.nextCursor,
|
|
1582
|
+
filters: (_a = response.filters) != null ? _a : currentState.filters,
|
|
1583
|
+
search: (_b = response.search) != null ? _b : currentState.search,
|
|
1584
|
+
beforeSections: (_c = response.beforeSections) != null ? _c : currentState.beforeSections,
|
|
1585
|
+
afterSections: (_d = response.afterSections) != null ? _d : currentState.afterSections
|
|
1586
|
+
};
|
|
1587
|
+
};
|
|
1588
|
+
var mergeSections = (existing, incoming) => {
|
|
1589
|
+
const knownIds = new Set(existing.map((section) => section.id));
|
|
1590
|
+
const newSections = incoming.filter((section) => !knownIds.has(section.id));
|
|
1591
|
+
const merged = existing.map((section) => {
|
|
1592
|
+
const match = incoming.find((s) => s.id === section.id);
|
|
1593
|
+
if (!match) return section;
|
|
1594
|
+
return __spreadProps(__spreadValues({}, section), { items: [...section.items, ...match.items] });
|
|
1595
|
+
});
|
|
1596
|
+
return [...merged, ...newSections];
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/domain/components/collectionComponent/CollectionComponent.ts
|
|
1600
|
+
var DEBOUNCE_TIME = 800;
|
|
1601
|
+
var createCollectionComponent = (props, onComponentUpdate, searchFunction) => {
|
|
1602
|
+
const { uid, analyticsId, control, margin, tags, url, method, state } = props;
|
|
1603
|
+
const update = getInputUpdateFunction(onComponentUpdate);
|
|
1604
|
+
let abortController = new AbortController();
|
|
1605
|
+
const query = (component2, cursor) => {
|
|
1606
|
+
var _a, _b;
|
|
1607
|
+
abortController.abort();
|
|
1608
|
+
abortController = new AbortController();
|
|
1609
|
+
const { signal } = abortController;
|
|
1610
|
+
searchFunction({
|
|
1611
|
+
searchParam: (_a = component2.state.search) == null ? void 0 : _a.param,
|
|
1612
|
+
query: (_b = component2.state.search) == null ? void 0 : _b.query,
|
|
1613
|
+
cursor,
|
|
1614
|
+
signal,
|
|
1615
|
+
filters: component2.state.filters
|
|
1616
|
+
}).then((response) => {
|
|
1617
|
+
if (!response) {
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
update(component2, (draft) => {
|
|
1621
|
+
const newState = applyCollectionResponse(draft.state, response, !!cursor);
|
|
1622
|
+
draft.state = __spreadProps(__spreadValues({}, newState), {
|
|
1623
|
+
filters: mapFilters(newState.filters),
|
|
1624
|
+
search: mapSearch(newState.search)
|
|
1625
|
+
});
|
|
1626
|
+
draft.status = {
|
|
1627
|
+
type: "idle",
|
|
1628
|
+
loadMore: newState.nextCursor ? () => query(component2, newState.nextCursor) : void 0
|
|
1629
|
+
};
|
|
1630
|
+
});
|
|
1631
|
+
}).catch(() => {
|
|
1632
|
+
if (!signal.aborted) {
|
|
1633
|
+
update(component2, (draft) => {
|
|
1634
|
+
draft.status = {
|
|
1635
|
+
type: "error",
|
|
1636
|
+
reason: cursor ? "pagination" : "search",
|
|
1637
|
+
retry: () => query(component2, cursor)
|
|
1638
|
+
};
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
};
|
|
1643
|
+
const debouncedQuery = debounce(
|
|
1644
|
+
(component2) => query(component2),
|
|
1645
|
+
DEBOUNCE_TIME
|
|
1646
|
+
);
|
|
1647
|
+
const selectFilter = (filterIndex, optionIndex) => {
|
|
1648
|
+
var _a;
|
|
1649
|
+
const filter = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
|
|
1650
|
+
if (!filter) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
const currentValue = filter.options[optionIndex].selected;
|
|
1654
|
+
update(component, (draft) => {
|
|
1655
|
+
if (!draft.state.filters) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
if (filter.multiSelect) {
|
|
1659
|
+
draft.state.filters[filterIndex].options[optionIndex].selected = !currentValue;
|
|
1660
|
+
} else {
|
|
1661
|
+
draft.state.filters[filterIndex].options = draft.state.filters[filterIndex].options.map(
|
|
1662
|
+
(option, index) => __spreadProps(__spreadValues({}, option), {
|
|
1663
|
+
selected: index === optionIndex ? !currentValue : false
|
|
1664
|
+
})
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1668
|
+
});
|
|
1669
|
+
query(component);
|
|
1670
|
+
};
|
|
1671
|
+
const mapFilters = (filters) => filters == null ? void 0 : filters.map((filter, i) => {
|
|
1672
|
+
var _a;
|
|
1673
|
+
return __spreadProps(__spreadValues({}, filter), {
|
|
1674
|
+
options: (_a = filter.options) == null ? void 0 : _a.map((option, j) => {
|
|
1675
|
+
var _a2;
|
|
1676
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1677
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1678
|
+
onSelect: () => selectFilter(i, j)
|
|
1679
|
+
});
|
|
1680
|
+
})
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
const mapSearch = (search) => search ? __spreadProps(__spreadValues({}, search), {
|
|
1684
|
+
onChange(value) {
|
|
1685
|
+
update(component, (draft) => {
|
|
1686
|
+
if (draft.state.search) {
|
|
1687
|
+
draft.state.search.query = value;
|
|
1688
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
debouncedQuery(component);
|
|
1692
|
+
}
|
|
1693
|
+
}) : void 0;
|
|
1694
|
+
const component = {
|
|
1695
|
+
type: "collection",
|
|
1696
|
+
kind: "layout",
|
|
1697
|
+
uid,
|
|
1698
|
+
analyticsId,
|
|
1699
|
+
control,
|
|
1700
|
+
margin,
|
|
1701
|
+
method,
|
|
1702
|
+
url,
|
|
1703
|
+
tags,
|
|
1704
|
+
status: {
|
|
1705
|
+
type: "idle",
|
|
1706
|
+
loadMore: state.nextCursor ? () => query(component, state.nextCursor) : void 0
|
|
1707
|
+
},
|
|
1708
|
+
state: __spreadProps(__spreadValues({}, state), {
|
|
1709
|
+
filters: mapFilters(state.filters),
|
|
1710
|
+
search: mapSearch(props.search)
|
|
1711
|
+
})
|
|
1712
|
+
};
|
|
1713
|
+
return component;
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
// src/domain/features/collection/getPerformCollectionQueryFunction.ts
|
|
1717
|
+
var getPerformCollectionQueryFunction = (httpClient, url, method, mapState) => {
|
|
1718
|
+
return async ({ searchParam, query, cursor, signal, filters = [] }) => {
|
|
1719
|
+
const headers = { "Content-Type": "application/json" };
|
|
1720
|
+
const filterValues = filters.map(
|
|
1721
|
+
(f) => {
|
|
1722
|
+
var _a;
|
|
1723
|
+
return [f.param, (_a = f.options.find((option) => option.selected)) == null ? void 0 : _a.value];
|
|
1724
|
+
}
|
|
1725
|
+
);
|
|
1726
|
+
const response = await (method === "GET" ? httpClient(
|
|
1727
|
+
addQueryParameters(url, [
|
|
1728
|
+
[searchParam, query != null ? query : void 0],
|
|
1729
|
+
["cursor", cursor],
|
|
1730
|
+
...filterValues
|
|
1731
|
+
]),
|
|
1732
|
+
{
|
|
1733
|
+
method,
|
|
1734
|
+
headers,
|
|
1735
|
+
signal
|
|
1736
|
+
}
|
|
1737
|
+
) : httpClient(url, {
|
|
1738
|
+
method,
|
|
1739
|
+
headers,
|
|
1740
|
+
signal,
|
|
1741
|
+
body: JSON.stringify(__spreadValues(__spreadProps(__spreadValues({}, searchParam && query ? { [searchParam]: query } : {}), {
|
|
1742
|
+
cursor
|
|
1743
|
+
}), filterValues.reduce((acc, [k, v]) => __spreadProps(__spreadValues({}, acc), { [k]: v }), {})))
|
|
1744
|
+
}));
|
|
1745
|
+
const results = await parseResponse(response);
|
|
1746
|
+
return mapState(results);
|
|
1747
|
+
};
|
|
1748
|
+
};
|
|
1749
|
+
var parseResponse = async (response) => {
|
|
1750
|
+
if (response.ok) {
|
|
1751
|
+
const body = await response.json().catch(() => null);
|
|
1752
|
+
return body;
|
|
1753
|
+
}
|
|
1754
|
+
throw Error("error response");
|
|
1755
|
+
};
|
|
1756
|
+
var addQueryParameters = (url, params) => {
|
|
1757
|
+
return params.reduce(
|
|
1758
|
+
(u, [key, param]) => key && param ? addQueryParameter(u, key, param) : u,
|
|
1759
|
+
url
|
|
1760
|
+
);
|
|
1761
|
+
};
|
|
1762
|
+
var addQueryParameter = (url, key, value) => {
|
|
1763
|
+
const [urlBase, urlQuery] = url.split("?");
|
|
1764
|
+
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
1765
|
+
urlQueryParams.set(key, value);
|
|
1766
|
+
return `${urlBase}?${urlQueryParams.toString()}`;
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
// src/domain/mappers/layout/collectionLayoutToComponent.ts
|
|
1770
|
+
var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, method, search, tags, url }, mapperProps) => {
|
|
1771
|
+
const { httpClient, onComponentUpdate } = mapperProps;
|
|
1772
|
+
const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
|
|
1773
|
+
const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
|
|
1774
|
+
const searchFunction = getPerformCollectionQueryFunction(httpClient, url, method, mapState);
|
|
1775
|
+
const component = createCollectionComponent(
|
|
1776
|
+
{
|
|
1777
|
+
uid,
|
|
1778
|
+
analyticsId,
|
|
1779
|
+
control,
|
|
1780
|
+
margin: margin != null ? margin : "md",
|
|
1781
|
+
tags,
|
|
1782
|
+
url,
|
|
1783
|
+
method,
|
|
1784
|
+
state: mapState(initialState),
|
|
1785
|
+
search: search ? {
|
|
1786
|
+
param: search == null ? void 0 : search.param,
|
|
1787
|
+
query: "",
|
|
1788
|
+
hint: search == null ? void 0 : search.hint
|
|
1789
|
+
} : void 0
|
|
1790
|
+
},
|
|
1791
|
+
onComponentUpdate,
|
|
1792
|
+
searchFunction
|
|
1793
|
+
);
|
|
1794
|
+
return component;
|
|
1795
|
+
};
|
|
1796
|
+
var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
|
|
1797
|
+
var _a, _b, _c;
|
|
1798
|
+
return {
|
|
1799
|
+
sections: specState.sections.map((section) => {
|
|
1800
|
+
return {
|
|
1801
|
+
id: section.id,
|
|
1802
|
+
title: section.title,
|
|
1803
|
+
callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
|
|
1804
|
+
items: section.items.map((item) => {
|
|
1805
|
+
const behavior = getDomainLayerBehavior(
|
|
1806
|
+
{ behavior: item.primaryBehavior },
|
|
1807
|
+
[],
|
|
1808
|
+
mapperProps.registerSubmissionBehavior
|
|
1809
|
+
);
|
|
1810
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
1811
|
+
onClick: item.primaryBehavior ? () => {
|
|
1812
|
+
void mapperProps.onBehavior(behavior);
|
|
1813
|
+
} : void 0,
|
|
1814
|
+
callToAction: getDomainLayerCallToAction(item.callToAction, mapperProps),
|
|
1815
|
+
inlineAlert: mapInlineAlert(item.inlineAlert)
|
|
1816
|
+
});
|
|
1817
|
+
})
|
|
1818
|
+
};
|
|
1819
|
+
}),
|
|
1820
|
+
filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
|
|
1821
|
+
options: filter.options.map((option) => {
|
|
1822
|
+
var _a2;
|
|
1823
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1824
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1825
|
+
onSelect: () => {
|
|
1826
|
+
}
|
|
1827
|
+
// todo: what goes here?
|
|
1828
|
+
});
|
|
1829
|
+
})
|
|
1830
|
+
})),
|
|
1831
|
+
beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
|
|
1832
|
+
afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
|
|
1833
|
+
nextCursor: specState.nextCursor
|
|
1834
|
+
};
|
|
1835
|
+
};
|
|
1836
|
+
|
|
1503
1837
|
// src/domain/components/ButtonComponent.ts
|
|
1504
1838
|
var createButtonComponent = (props) => __spreadValues({
|
|
1505
1839
|
type: "button",
|
|
@@ -1668,41 +2002,6 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1668
2002
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1669
2003
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1670
2004
|
|
|
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
2005
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1707
2006
|
var decisionLayoutToComponent = (uid, {
|
|
1708
2007
|
analyticsId,
|
|
@@ -2178,44 +2477,8 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2178
2477
|
});
|
|
2179
2478
|
};
|
|
2180
2479
|
|
|
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
2480
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2218
|
-
var
|
|
2481
|
+
var DEBOUNCE_TIME2 = 400;
|
|
2219
2482
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2220
2483
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2221
2484
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2245,7 +2508,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2245
2508
|
}
|
|
2246
2509
|
});
|
|
2247
2510
|
};
|
|
2248
|
-
const debouncedSearch = debounce(search,
|
|
2511
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME2);
|
|
2249
2512
|
const component = {
|
|
2250
2513
|
type: "search",
|
|
2251
2514
|
kind: "layout",
|
|
@@ -2307,7 +2570,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2307
2570
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2308
2571
|
const { method, param, url } = config;
|
|
2309
2572
|
const headers = { "Content-Type": "application/json" };
|
|
2310
|
-
const response = await (method === "GET" ? httpClient(
|
|
2573
|
+
const response = await (method === "GET" ? httpClient(addQueryParameter2(url, param, query), {
|
|
2311
2574
|
method,
|
|
2312
2575
|
headers,
|
|
2313
2576
|
signal
|
|
@@ -2317,7 +2580,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2317
2580
|
signal,
|
|
2318
2581
|
body: JSON.stringify({ [param]: query })
|
|
2319
2582
|
}));
|
|
2320
|
-
const results = await
|
|
2583
|
+
const results = await parseResponse2(response);
|
|
2321
2584
|
latestSuccessfulRequestHash = requestHash;
|
|
2322
2585
|
if (results.type === "layout") {
|
|
2323
2586
|
const mappedLayoutResult = {
|
|
@@ -2333,7 +2596,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2333
2596
|
return latestSuccessfulResults;
|
|
2334
2597
|
};
|
|
2335
2598
|
};
|
|
2336
|
-
var
|
|
2599
|
+
var parseResponse2 = async (response) => {
|
|
2337
2600
|
if (response.ok) {
|
|
2338
2601
|
const body = await response.json().catch(() => null);
|
|
2339
2602
|
if (isValidResponseBody(body)) {
|
|
@@ -2350,7 +2613,7 @@ var parseResponse = async (response) => {
|
|
|
2350
2613
|
}
|
|
2351
2614
|
throw Error("error response");
|
|
2352
2615
|
};
|
|
2353
|
-
var
|
|
2616
|
+
var addQueryParameter2 = (url, key, value) => {
|
|
2354
2617
|
const [urlBase, urlQuery] = url.split("?");
|
|
2355
2618
|
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
2356
2619
|
urlQueryParams.set(key, value);
|
|
@@ -2556,6 +2819,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2556
2819
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2557
2820
|
case "button":
|
|
2558
2821
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2822
|
+
case "collection":
|
|
2823
|
+
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2559
2824
|
case "columns":
|
|
2560
2825
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2561
2826
|
case "decision":
|
|
@@ -7929,6 +8194,26 @@ var mapBoxControl = ({
|
|
|
7929
8194
|
return control;
|
|
7930
8195
|
};
|
|
7931
8196
|
|
|
8197
|
+
// src/renderers/mappers/collectionComponentToProps.ts
|
|
8198
|
+
var collectionComponentToProps = (component, rendererMapperProps) => {
|
|
8199
|
+
var _a, _b, _c;
|
|
8200
|
+
return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags", "url", "method")), rendererMapperProps), {
|
|
8201
|
+
status: component.status,
|
|
8202
|
+
state: __spreadProps(__spreadValues({}, component.state), {
|
|
8203
|
+
filters: (_a = component.state.filters) != null ? _a : [],
|
|
8204
|
+
sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
|
|
8205
|
+
callToAction: mapCallToActionOptional(section.callToAction),
|
|
8206
|
+
items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
8207
|
+
callToAction: mapCallToActionOptional(item.callToAction),
|
|
8208
|
+
additionalInfo: mapAdditionalInfo2(item.additionalInfo)
|
|
8209
|
+
}))
|
|
8210
|
+
})),
|
|
8211
|
+
beforeSections: (_b = component.state.beforeSections) == null ? void 0 : _b.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render),
|
|
8212
|
+
afterSections: (_c = component.state.afterSections) == null ? void 0 : _c.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render)
|
|
8213
|
+
})
|
|
8214
|
+
});
|
|
8215
|
+
};
|
|
8216
|
+
|
|
7932
8217
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
7933
8218
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
7934
8219
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8558,6 +8843,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8558
8843
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8559
8844
|
case "button":
|
|
8560
8845
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8846
|
+
case "collection":
|
|
8847
|
+
return collectionComponentToProps(component, rendererMapperProps);
|
|
8561
8848
|
case "columns":
|
|
8562
8849
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8563
8850
|
case "container":
|