@wise/dynamic-flow-client 5.19.0 → 5.20.0-experimental-9265cac
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 +33 -0
- package/build/main.js +373 -77
- package/build/main.mjs +373 -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 +18 -18
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,348 @@ 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 [
|
|
1724
|
+
f.param,
|
|
1725
|
+
f.multiSelect ? f.options.filter((option) => option.selected).map((option) => option.value) : (_a = f.options.find((option) => option.selected)) == null ? void 0 : _a.value
|
|
1726
|
+
];
|
|
1727
|
+
}
|
|
1728
|
+
);
|
|
1729
|
+
const response = await (method === "GET" ? httpClient(
|
|
1730
|
+
addQueryParameters(url, [
|
|
1731
|
+
[searchParam, query != null ? query : void 0],
|
|
1732
|
+
["cursor", cursor],
|
|
1733
|
+
...filterValues
|
|
1734
|
+
]),
|
|
1735
|
+
{
|
|
1736
|
+
method,
|
|
1737
|
+
headers,
|
|
1738
|
+
signal
|
|
1739
|
+
}
|
|
1740
|
+
) : httpClient(url, {
|
|
1741
|
+
method,
|
|
1742
|
+
headers,
|
|
1743
|
+
signal,
|
|
1744
|
+
body: JSON.stringify(__spreadValues(__spreadProps(__spreadValues({}, searchParam && query ? { [searchParam]: query } : {}), {
|
|
1745
|
+
cursor
|
|
1746
|
+
}), filterValues.reduce((acc, [k, v]) => __spreadProps(__spreadValues({}, acc), { [k]: v }), {})))
|
|
1747
|
+
}));
|
|
1748
|
+
const results = await parseResponse(response);
|
|
1749
|
+
return mapState(results);
|
|
1750
|
+
};
|
|
1751
|
+
};
|
|
1752
|
+
var parseResponse = async (response) => {
|
|
1753
|
+
if (response.ok) {
|
|
1754
|
+
const body = await response.json().catch(() => null);
|
|
1755
|
+
return body;
|
|
1756
|
+
}
|
|
1757
|
+
throw Error("error response");
|
|
1758
|
+
};
|
|
1759
|
+
var addQueryParameters = (url, params) => {
|
|
1760
|
+
return params.reduce(
|
|
1761
|
+
(u, [key, param]) => key && param ? addQueryParameter(u, key, param) : u,
|
|
1762
|
+
url
|
|
1763
|
+
);
|
|
1764
|
+
};
|
|
1765
|
+
var addQueryParameter = (url, key, value) => {
|
|
1766
|
+
const [urlBase, urlQuery] = url.split("?");
|
|
1767
|
+
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
1768
|
+
if (isArray(value)) {
|
|
1769
|
+
value.forEach((v) => {
|
|
1770
|
+
urlQueryParams.append(key, v);
|
|
1771
|
+
});
|
|
1772
|
+
} else {
|
|
1773
|
+
urlQueryParams.append(key, value);
|
|
1774
|
+
}
|
|
1775
|
+
return `${urlBase}?${urlQueryParams.toString()}`;
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
// src/domain/mappers/layout/collectionLayoutToComponent.ts
|
|
1779
|
+
var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, method, search, tags, url }, mapperProps) => {
|
|
1780
|
+
const { httpClient, onComponentUpdate } = mapperProps;
|
|
1781
|
+
const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
|
|
1782
|
+
const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
|
|
1783
|
+
const searchFunction = getPerformCollectionQueryFunction(httpClient, url, method, mapState);
|
|
1784
|
+
const component = createCollectionComponent(
|
|
1785
|
+
{
|
|
1786
|
+
uid,
|
|
1787
|
+
analyticsId,
|
|
1788
|
+
control,
|
|
1789
|
+
margin: margin != null ? margin : "md",
|
|
1790
|
+
tags,
|
|
1791
|
+
url,
|
|
1792
|
+
method,
|
|
1793
|
+
state: mapState(initialState),
|
|
1794
|
+
search: search ? {
|
|
1795
|
+
param: search == null ? void 0 : search.param,
|
|
1796
|
+
query: "",
|
|
1797
|
+
hint: search == null ? void 0 : search.hint
|
|
1798
|
+
} : void 0
|
|
1799
|
+
},
|
|
1800
|
+
onComponentUpdate,
|
|
1801
|
+
searchFunction
|
|
1802
|
+
);
|
|
1803
|
+
return component;
|
|
1804
|
+
};
|
|
1805
|
+
var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
|
|
1806
|
+
var _a, _b, _c;
|
|
1807
|
+
return {
|
|
1808
|
+
sections: specState.sections.map((section) => {
|
|
1809
|
+
return {
|
|
1810
|
+
id: section.id,
|
|
1811
|
+
title: section.title,
|
|
1812
|
+
callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
|
|
1813
|
+
items: section.items.map((item) => {
|
|
1814
|
+
const behavior = getDomainLayerBehavior(
|
|
1815
|
+
{ behavior: item.primaryBehavior },
|
|
1816
|
+
[],
|
|
1817
|
+
mapperProps.registerSubmissionBehavior
|
|
1818
|
+
);
|
|
1819
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
1820
|
+
onClick: item.primaryBehavior ? () => {
|
|
1821
|
+
void mapperProps.onBehavior(behavior);
|
|
1822
|
+
} : void 0,
|
|
1823
|
+
callToAction: getDomainLayerCallToAction(item.callToAction, mapperProps),
|
|
1824
|
+
inlineAlert: mapInlineAlert(item.inlineAlert)
|
|
1825
|
+
});
|
|
1826
|
+
})
|
|
1827
|
+
};
|
|
1828
|
+
}),
|
|
1829
|
+
filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
|
|
1830
|
+
options: filter.options.map((option) => {
|
|
1831
|
+
var _a2;
|
|
1832
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1833
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1834
|
+
onSelect: () => {
|
|
1835
|
+
}
|
|
1836
|
+
// todo: what goes here?
|
|
1837
|
+
});
|
|
1838
|
+
})
|
|
1839
|
+
})),
|
|
1840
|
+
beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
|
|
1841
|
+
afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
|
|
1842
|
+
nextCursor: specState.nextCursor
|
|
1843
|
+
};
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1503
1846
|
// src/domain/components/ButtonComponent.ts
|
|
1504
1847
|
var createButtonComponent = (props) => __spreadValues({
|
|
1505
1848
|
type: "button",
|
|
@@ -1668,41 +2011,6 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1668
2011
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1669
2012
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1670
2013
|
|
|
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
2014
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1707
2015
|
var decisionLayoutToComponent = (uid, {
|
|
1708
2016
|
analyticsId,
|
|
@@ -2178,44 +2486,8 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2178
2486
|
});
|
|
2179
2487
|
};
|
|
2180
2488
|
|
|
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
2489
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2218
|
-
var
|
|
2490
|
+
var DEBOUNCE_TIME2 = 400;
|
|
2219
2491
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2220
2492
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2221
2493
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2245,7 +2517,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2245
2517
|
}
|
|
2246
2518
|
});
|
|
2247
2519
|
};
|
|
2248
|
-
const debouncedSearch = debounce(search,
|
|
2520
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME2);
|
|
2249
2521
|
const component = {
|
|
2250
2522
|
type: "search",
|
|
2251
2523
|
kind: "layout",
|
|
@@ -2307,7 +2579,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2307
2579
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2308
2580
|
const { method, param, url } = config;
|
|
2309
2581
|
const headers = { "Content-Type": "application/json" };
|
|
2310
|
-
const response = await (method === "GET" ? httpClient(
|
|
2582
|
+
const response = await (method === "GET" ? httpClient(addQueryParameter2(url, param, query), {
|
|
2311
2583
|
method,
|
|
2312
2584
|
headers,
|
|
2313
2585
|
signal
|
|
@@ -2317,7 +2589,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2317
2589
|
signal,
|
|
2318
2590
|
body: JSON.stringify({ [param]: query })
|
|
2319
2591
|
}));
|
|
2320
|
-
const results = await
|
|
2592
|
+
const results = await parseResponse2(response);
|
|
2321
2593
|
latestSuccessfulRequestHash = requestHash;
|
|
2322
2594
|
if (results.type === "layout") {
|
|
2323
2595
|
const mappedLayoutResult = {
|
|
@@ -2333,7 +2605,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2333
2605
|
return latestSuccessfulResults;
|
|
2334
2606
|
};
|
|
2335
2607
|
};
|
|
2336
|
-
var
|
|
2608
|
+
var parseResponse2 = async (response) => {
|
|
2337
2609
|
if (response.ok) {
|
|
2338
2610
|
const body = await response.json().catch(() => null);
|
|
2339
2611
|
if (isValidResponseBody(body)) {
|
|
@@ -2350,7 +2622,7 @@ var parseResponse = async (response) => {
|
|
|
2350
2622
|
}
|
|
2351
2623
|
throw Error("error response");
|
|
2352
2624
|
};
|
|
2353
|
-
var
|
|
2625
|
+
var addQueryParameter2 = (url, key, value) => {
|
|
2354
2626
|
const [urlBase, urlQuery] = url.split("?");
|
|
2355
2627
|
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
2356
2628
|
urlQueryParams.set(key, value);
|
|
@@ -2556,6 +2828,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2556
2828
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2557
2829
|
case "button":
|
|
2558
2830
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2831
|
+
case "collection":
|
|
2832
|
+
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2559
2833
|
case "columns":
|
|
2560
2834
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2561
2835
|
case "decision":
|
|
@@ -7929,6 +8203,26 @@ var mapBoxControl = ({
|
|
|
7929
8203
|
return control;
|
|
7930
8204
|
};
|
|
7931
8205
|
|
|
8206
|
+
// src/renderers/mappers/collectionComponentToProps.ts
|
|
8207
|
+
var collectionComponentToProps = (component, rendererMapperProps) => {
|
|
8208
|
+
var _a, _b, _c;
|
|
8209
|
+
return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags", "url", "method")), rendererMapperProps), {
|
|
8210
|
+
status: component.status,
|
|
8211
|
+
state: __spreadProps(__spreadValues({}, component.state), {
|
|
8212
|
+
filters: (_a = component.state.filters) != null ? _a : [],
|
|
8213
|
+
sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
|
|
8214
|
+
callToAction: mapCallToActionOptional(section.callToAction),
|
|
8215
|
+
items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
8216
|
+
callToAction: mapCallToActionOptional(item.callToAction),
|
|
8217
|
+
additionalInfo: mapAdditionalInfo2(item.additionalInfo)
|
|
8218
|
+
}))
|
|
8219
|
+
})),
|
|
8220
|
+
beforeSections: (_b = component.state.beforeSections) == null ? void 0 : _b.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render),
|
|
8221
|
+
afterSections: (_c = component.state.afterSections) == null ? void 0 : _c.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render)
|
|
8222
|
+
})
|
|
8223
|
+
});
|
|
8224
|
+
};
|
|
8225
|
+
|
|
7932
8226
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
7933
8227
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
7934
8228
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8558,6 +8852,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8558
8852
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8559
8853
|
case "button":
|
|
8560
8854
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8855
|
+
case "collection":
|
|
8856
|
+
return collectionComponentToProps(component, rendererMapperProps);
|
|
8561
8857
|
case "columns":
|
|
8562
8858
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8563
8859
|
case "container":
|