@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.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":
|
|
@@ -1469,6 +1470,348 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
|
|
|
1469
1470
|
)
|
|
1470
1471
|
});
|
|
1471
1472
|
|
|
1473
|
+
// src/domain/mappers/utils/utils.ts
|
|
1474
|
+
var mapInlineAlert = (alert) => {
|
|
1475
|
+
return alert ? {
|
|
1476
|
+
content: alert.content,
|
|
1477
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1478
|
+
} : void 0;
|
|
1479
|
+
};
|
|
1480
|
+
var mapAdditionalInfo = (info, mapperProps) => {
|
|
1481
|
+
const { onBehavior, trackEvent, registerSubmissionBehavior } = mapperProps;
|
|
1482
|
+
if (info) {
|
|
1483
|
+
const behavior = getDomainLayerBehavior(info, [], registerSubmissionBehavior);
|
|
1484
|
+
const isLink = behavior.type === "link";
|
|
1485
|
+
return {
|
|
1486
|
+
text: info.text,
|
|
1487
|
+
href: isLink ? behavior.url : void 0,
|
|
1488
|
+
hrefWithTracking: getHrefWithTracking({
|
|
1489
|
+
behavior,
|
|
1490
|
+
onBehavior,
|
|
1491
|
+
trackEvent
|
|
1492
|
+
}),
|
|
1493
|
+
accessibilityDescription: info.accessibilityDescription,
|
|
1494
|
+
onClick: behavior.type === "none" ? void 0 : () => {
|
|
1495
|
+
void onBehavior(behavior);
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
return void 0;
|
|
1500
|
+
};
|
|
1501
|
+
var mapSchemaAlert = (alert) => {
|
|
1502
|
+
return alert ? {
|
|
1503
|
+
content: alert.markdown,
|
|
1504
|
+
context: alert.context ? mapLegacyContext(alert.context) : "neutral"
|
|
1505
|
+
} : void 0;
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
// src/domain/components/utils/debounce.ts
|
|
1509
|
+
var debounce = (callback, waitMs) => {
|
|
1510
|
+
let timeoutId = null;
|
|
1511
|
+
let lastArgs = null;
|
|
1512
|
+
const clearTimer = () => {
|
|
1513
|
+
if (timeoutId !== null) {
|
|
1514
|
+
clearTimeout(timeoutId);
|
|
1515
|
+
timeoutId = null;
|
|
1516
|
+
}
|
|
1517
|
+
lastArgs = null;
|
|
1518
|
+
};
|
|
1519
|
+
const debouncedFn = (...args) => {
|
|
1520
|
+
lastArgs = args;
|
|
1521
|
+
if (timeoutId !== null) {
|
|
1522
|
+
clearTimeout(timeoutId);
|
|
1523
|
+
}
|
|
1524
|
+
timeoutId = setTimeout(() => {
|
|
1525
|
+
callback(...lastArgs);
|
|
1526
|
+
timeoutId = null;
|
|
1527
|
+
lastArgs = null;
|
|
1528
|
+
}, waitMs);
|
|
1529
|
+
};
|
|
1530
|
+
debouncedFn.cancel = () => {
|
|
1531
|
+
if (timeoutId !== null) {
|
|
1532
|
+
clearTimer();
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
debouncedFn.flush = () => {
|
|
1536
|
+
if (timeoutId !== null) {
|
|
1537
|
+
callback(...lastArgs);
|
|
1538
|
+
clearTimer();
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
return debouncedFn;
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1544
|
+
// src/domain/components/collectionComponent/applyCollectionResponse.ts
|
|
1545
|
+
var applyCollectionResponse = (currentState, response, isPaginated) => {
|
|
1546
|
+
var _a, _b, _c, _d;
|
|
1547
|
+
const sections = isPaginated ? mergeSections(currentState.sections, response.sections) : response.sections;
|
|
1548
|
+
return {
|
|
1549
|
+
sections,
|
|
1550
|
+
nextCursor: response.nextCursor,
|
|
1551
|
+
filters: (_a = response.filters) != null ? _a : currentState.filters,
|
|
1552
|
+
search: (_b = response.search) != null ? _b : currentState.search,
|
|
1553
|
+
beforeSections: (_c = response.beforeSections) != null ? _c : currentState.beforeSections,
|
|
1554
|
+
afterSections: (_d = response.afterSections) != null ? _d : currentState.afterSections
|
|
1555
|
+
};
|
|
1556
|
+
};
|
|
1557
|
+
var mergeSections = (existing, incoming) => {
|
|
1558
|
+
const knownIds = new Set(existing.map((section) => section.id));
|
|
1559
|
+
const newSections = incoming.filter((section) => !knownIds.has(section.id));
|
|
1560
|
+
const merged = existing.map((section) => {
|
|
1561
|
+
const match = incoming.find((s) => s.id === section.id);
|
|
1562
|
+
if (!match) return section;
|
|
1563
|
+
return __spreadProps(__spreadValues({}, section), { items: [...section.items, ...match.items] });
|
|
1564
|
+
});
|
|
1565
|
+
return [...merged, ...newSections];
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
// src/domain/components/collectionComponent/CollectionComponent.ts
|
|
1569
|
+
var DEBOUNCE_TIME = 800;
|
|
1570
|
+
var createCollectionComponent = (props, onComponentUpdate, searchFunction) => {
|
|
1571
|
+
const { uid, analyticsId, control, margin, tags, url, method, state } = props;
|
|
1572
|
+
const update = getInputUpdateFunction(onComponentUpdate);
|
|
1573
|
+
let abortController = new AbortController();
|
|
1574
|
+
const query = (component2, cursor) => {
|
|
1575
|
+
var _a, _b;
|
|
1576
|
+
abortController.abort();
|
|
1577
|
+
abortController = new AbortController();
|
|
1578
|
+
const { signal } = abortController;
|
|
1579
|
+
searchFunction({
|
|
1580
|
+
searchParam: (_a = component2.state.search) == null ? void 0 : _a.param,
|
|
1581
|
+
query: (_b = component2.state.search) == null ? void 0 : _b.query,
|
|
1582
|
+
cursor,
|
|
1583
|
+
signal,
|
|
1584
|
+
filters: component2.state.filters
|
|
1585
|
+
}).then((response) => {
|
|
1586
|
+
if (!response) {
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
update(component2, (draft) => {
|
|
1590
|
+
const newState = applyCollectionResponse(draft.state, response, !!cursor);
|
|
1591
|
+
draft.state = __spreadProps(__spreadValues({}, newState), {
|
|
1592
|
+
filters: mapFilters(newState.filters),
|
|
1593
|
+
search: mapSearch(newState.search)
|
|
1594
|
+
});
|
|
1595
|
+
draft.status = {
|
|
1596
|
+
type: "idle",
|
|
1597
|
+
loadMore: newState.nextCursor ? () => query(component2, newState.nextCursor) : void 0
|
|
1598
|
+
};
|
|
1599
|
+
});
|
|
1600
|
+
}).catch(() => {
|
|
1601
|
+
if (!signal.aborted) {
|
|
1602
|
+
update(component2, (draft) => {
|
|
1603
|
+
draft.status = {
|
|
1604
|
+
type: "error",
|
|
1605
|
+
reason: cursor ? "pagination" : "search",
|
|
1606
|
+
retry: () => query(component2, cursor)
|
|
1607
|
+
};
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
};
|
|
1612
|
+
const debouncedQuery = debounce(
|
|
1613
|
+
(component2) => query(component2),
|
|
1614
|
+
DEBOUNCE_TIME
|
|
1615
|
+
);
|
|
1616
|
+
const selectFilter = (filterIndex, optionIndex) => {
|
|
1617
|
+
var _a;
|
|
1618
|
+
const filter = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
|
|
1619
|
+
if (!filter) {
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
const currentValue = filter.options[optionIndex].selected;
|
|
1623
|
+
update(component, (draft) => {
|
|
1624
|
+
if (!draft.state.filters) {
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
if (filter.multiSelect) {
|
|
1628
|
+
draft.state.filters[filterIndex].options[optionIndex].selected = !currentValue;
|
|
1629
|
+
} else {
|
|
1630
|
+
draft.state.filters[filterIndex].options = draft.state.filters[filterIndex].options.map(
|
|
1631
|
+
(option, index) => __spreadProps(__spreadValues({}, option), {
|
|
1632
|
+
selected: index === optionIndex ? !currentValue : false
|
|
1633
|
+
})
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1637
|
+
});
|
|
1638
|
+
query(component);
|
|
1639
|
+
};
|
|
1640
|
+
const mapFilters = (filters) => filters == null ? void 0 : filters.map((filter, i) => {
|
|
1641
|
+
var _a;
|
|
1642
|
+
return __spreadProps(__spreadValues({}, filter), {
|
|
1643
|
+
options: (_a = filter.options) == null ? void 0 : _a.map((option, j) => {
|
|
1644
|
+
var _a2;
|
|
1645
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1646
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1647
|
+
onSelect: () => selectFilter(i, j)
|
|
1648
|
+
});
|
|
1649
|
+
})
|
|
1650
|
+
});
|
|
1651
|
+
});
|
|
1652
|
+
const mapSearch = (search) => search ? __spreadProps(__spreadValues({}, search), {
|
|
1653
|
+
onChange(value) {
|
|
1654
|
+
update(component, (draft) => {
|
|
1655
|
+
if (draft.state.search) {
|
|
1656
|
+
draft.state.search.query = value;
|
|
1657
|
+
draft.status = { type: "loading", reason: "search" };
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
debouncedQuery(component);
|
|
1661
|
+
}
|
|
1662
|
+
}) : void 0;
|
|
1663
|
+
const component = {
|
|
1664
|
+
type: "collection",
|
|
1665
|
+
kind: "layout",
|
|
1666
|
+
uid,
|
|
1667
|
+
analyticsId,
|
|
1668
|
+
control,
|
|
1669
|
+
margin,
|
|
1670
|
+
method,
|
|
1671
|
+
url,
|
|
1672
|
+
tags,
|
|
1673
|
+
status: {
|
|
1674
|
+
type: "idle",
|
|
1675
|
+
loadMore: state.nextCursor ? () => query(component, state.nextCursor) : void 0
|
|
1676
|
+
},
|
|
1677
|
+
state: __spreadProps(__spreadValues({}, state), {
|
|
1678
|
+
filters: mapFilters(state.filters),
|
|
1679
|
+
search: mapSearch(props.search)
|
|
1680
|
+
})
|
|
1681
|
+
};
|
|
1682
|
+
return component;
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
// src/domain/features/collection/getPerformCollectionQueryFunction.ts
|
|
1686
|
+
var getPerformCollectionQueryFunction = (httpClient, url, method, mapState) => {
|
|
1687
|
+
return async ({ searchParam, query, cursor, signal, filters = [] }) => {
|
|
1688
|
+
const headers = { "Content-Type": "application/json" };
|
|
1689
|
+
const filterValues = filters.map(
|
|
1690
|
+
(f) => {
|
|
1691
|
+
var _a;
|
|
1692
|
+
return [
|
|
1693
|
+
f.param,
|
|
1694
|
+
f.multiSelect ? f.options.filter((option) => option.selected).map((option) => option.value) : (_a = f.options.find((option) => option.selected)) == null ? void 0 : _a.value
|
|
1695
|
+
];
|
|
1696
|
+
}
|
|
1697
|
+
);
|
|
1698
|
+
const response = await (method === "GET" ? httpClient(
|
|
1699
|
+
addQueryParameters(url, [
|
|
1700
|
+
[searchParam, query != null ? query : void 0],
|
|
1701
|
+
["cursor", cursor],
|
|
1702
|
+
...filterValues
|
|
1703
|
+
]),
|
|
1704
|
+
{
|
|
1705
|
+
method,
|
|
1706
|
+
headers,
|
|
1707
|
+
signal
|
|
1708
|
+
}
|
|
1709
|
+
) : httpClient(url, {
|
|
1710
|
+
method,
|
|
1711
|
+
headers,
|
|
1712
|
+
signal,
|
|
1713
|
+
body: JSON.stringify(__spreadValues(__spreadProps(__spreadValues({}, searchParam && query ? { [searchParam]: query } : {}), {
|
|
1714
|
+
cursor
|
|
1715
|
+
}), filterValues.reduce((acc, [k, v]) => __spreadProps(__spreadValues({}, acc), { [k]: v }), {})))
|
|
1716
|
+
}));
|
|
1717
|
+
const results = await parseResponse(response);
|
|
1718
|
+
return mapState(results);
|
|
1719
|
+
};
|
|
1720
|
+
};
|
|
1721
|
+
var parseResponse = async (response) => {
|
|
1722
|
+
if (response.ok) {
|
|
1723
|
+
const body = await response.json().catch(() => null);
|
|
1724
|
+
return body;
|
|
1725
|
+
}
|
|
1726
|
+
throw Error("error response");
|
|
1727
|
+
};
|
|
1728
|
+
var addQueryParameters = (url, params) => {
|
|
1729
|
+
return params.reduce(
|
|
1730
|
+
(u, [key, param]) => key && param ? addQueryParameter(u, key, param) : u,
|
|
1731
|
+
url
|
|
1732
|
+
);
|
|
1733
|
+
};
|
|
1734
|
+
var addQueryParameter = (url, key, value) => {
|
|
1735
|
+
const [urlBase, urlQuery] = url.split("?");
|
|
1736
|
+
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
1737
|
+
if (isArray(value)) {
|
|
1738
|
+
value.forEach((v) => {
|
|
1739
|
+
urlQueryParams.append(key, v);
|
|
1740
|
+
});
|
|
1741
|
+
} else {
|
|
1742
|
+
urlQueryParams.append(key, value);
|
|
1743
|
+
}
|
|
1744
|
+
return `${urlBase}?${urlQueryParams.toString()}`;
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
// src/domain/mappers/layout/collectionLayoutToComponent.ts
|
|
1748
|
+
var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, method, search, tags, url }, mapperProps) => {
|
|
1749
|
+
const { httpClient, onComponentUpdate } = mapperProps;
|
|
1750
|
+
const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
|
|
1751
|
+
const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
|
|
1752
|
+
const searchFunction = getPerformCollectionQueryFunction(httpClient, url, method, mapState);
|
|
1753
|
+
const component = createCollectionComponent(
|
|
1754
|
+
{
|
|
1755
|
+
uid,
|
|
1756
|
+
analyticsId,
|
|
1757
|
+
control,
|
|
1758
|
+
margin: margin != null ? margin : "md",
|
|
1759
|
+
tags,
|
|
1760
|
+
url,
|
|
1761
|
+
method,
|
|
1762
|
+
state: mapState(initialState),
|
|
1763
|
+
search: search ? {
|
|
1764
|
+
param: search == null ? void 0 : search.param,
|
|
1765
|
+
query: "",
|
|
1766
|
+
hint: search == null ? void 0 : search.hint
|
|
1767
|
+
} : void 0
|
|
1768
|
+
},
|
|
1769
|
+
onComponentUpdate,
|
|
1770
|
+
searchFunction
|
|
1771
|
+
);
|
|
1772
|
+
return component;
|
|
1773
|
+
};
|
|
1774
|
+
var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
|
|
1775
|
+
var _a, _b, _c;
|
|
1776
|
+
return {
|
|
1777
|
+
sections: specState.sections.map((section) => {
|
|
1778
|
+
return {
|
|
1779
|
+
id: section.id,
|
|
1780
|
+
title: section.title,
|
|
1781
|
+
callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
|
|
1782
|
+
items: section.items.map((item) => {
|
|
1783
|
+
const behavior = getDomainLayerBehavior(
|
|
1784
|
+
{ behavior: item.primaryBehavior },
|
|
1785
|
+
[],
|
|
1786
|
+
mapperProps.registerSubmissionBehavior
|
|
1787
|
+
);
|
|
1788
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
1789
|
+
onClick: item.primaryBehavior ? () => {
|
|
1790
|
+
void mapperProps.onBehavior(behavior);
|
|
1791
|
+
} : void 0,
|
|
1792
|
+
callToAction: getDomainLayerCallToAction(item.callToAction, mapperProps),
|
|
1793
|
+
inlineAlert: mapInlineAlert(item.inlineAlert)
|
|
1794
|
+
});
|
|
1795
|
+
})
|
|
1796
|
+
};
|
|
1797
|
+
}),
|
|
1798
|
+
filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
|
|
1799
|
+
options: filter.options.map((option) => {
|
|
1800
|
+
var _a2;
|
|
1801
|
+
return __spreadProps(__spreadValues({}, option), {
|
|
1802
|
+
selected: (_a2 = option.selected) != null ? _a2 : false,
|
|
1803
|
+
onSelect: () => {
|
|
1804
|
+
}
|
|
1805
|
+
// todo: what goes here?
|
|
1806
|
+
});
|
|
1807
|
+
})
|
|
1808
|
+
})),
|
|
1809
|
+
beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
|
|
1810
|
+
afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
|
|
1811
|
+
nextCursor: specState.nextCursor
|
|
1812
|
+
};
|
|
1813
|
+
};
|
|
1814
|
+
|
|
1472
1815
|
// src/domain/components/ButtonComponent.ts
|
|
1473
1816
|
var createButtonComponent = (props) => __spreadValues({
|
|
1474
1817
|
type: "button",
|
|
@@ -1637,41 +1980,6 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1637
1980
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1638
1981
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1639
1982
|
|
|
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
1983
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1676
1984
|
var decisionLayoutToComponent = (uid, {
|
|
1677
1985
|
analyticsId,
|
|
@@ -2147,44 +2455,8 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2147
2455
|
});
|
|
2148
2456
|
};
|
|
2149
2457
|
|
|
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
2458
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2187
|
-
var
|
|
2459
|
+
var DEBOUNCE_TIME2 = 400;
|
|
2188
2460
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2189
2461
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2190
2462
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2214,7 +2486,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2214
2486
|
}
|
|
2215
2487
|
});
|
|
2216
2488
|
};
|
|
2217
|
-
const debouncedSearch = debounce(search,
|
|
2489
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME2);
|
|
2218
2490
|
const component = {
|
|
2219
2491
|
type: "search",
|
|
2220
2492
|
kind: "layout",
|
|
@@ -2276,7 +2548,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2276
2548
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2277
2549
|
const { method, param, url } = config;
|
|
2278
2550
|
const headers = { "Content-Type": "application/json" };
|
|
2279
|
-
const response = await (method === "GET" ? httpClient(
|
|
2551
|
+
const response = await (method === "GET" ? httpClient(addQueryParameter2(url, param, query), {
|
|
2280
2552
|
method,
|
|
2281
2553
|
headers,
|
|
2282
2554
|
signal
|
|
@@ -2286,7 +2558,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2286
2558
|
signal,
|
|
2287
2559
|
body: JSON.stringify({ [param]: query })
|
|
2288
2560
|
}));
|
|
2289
|
-
const results = await
|
|
2561
|
+
const results = await parseResponse2(response);
|
|
2290
2562
|
latestSuccessfulRequestHash = requestHash;
|
|
2291
2563
|
if (results.type === "layout") {
|
|
2292
2564
|
const mappedLayoutResult = {
|
|
@@ -2302,7 +2574,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2302
2574
|
return latestSuccessfulResults;
|
|
2303
2575
|
};
|
|
2304
2576
|
};
|
|
2305
|
-
var
|
|
2577
|
+
var parseResponse2 = async (response) => {
|
|
2306
2578
|
if (response.ok) {
|
|
2307
2579
|
const body = await response.json().catch(() => null);
|
|
2308
2580
|
if (isValidResponseBody(body)) {
|
|
@@ -2319,7 +2591,7 @@ var parseResponse = async (response) => {
|
|
|
2319
2591
|
}
|
|
2320
2592
|
throw Error("error response");
|
|
2321
2593
|
};
|
|
2322
|
-
var
|
|
2594
|
+
var addQueryParameter2 = (url, key, value) => {
|
|
2323
2595
|
const [urlBase, urlQuery] = url.split("?");
|
|
2324
2596
|
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
2325
2597
|
urlQueryParams.set(key, value);
|
|
@@ -2525,6 +2797,8 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2525
2797
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2526
2798
|
case "button":
|
|
2527
2799
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2800
|
+
case "collection":
|
|
2801
|
+
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2528
2802
|
case "columns":
|
|
2529
2803
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2530
2804
|
case "decision":
|
|
@@ -7898,6 +8172,26 @@ var mapBoxControl = ({
|
|
|
7898
8172
|
return control;
|
|
7899
8173
|
};
|
|
7900
8174
|
|
|
8175
|
+
// src/renderers/mappers/collectionComponentToProps.ts
|
|
8176
|
+
var collectionComponentToProps = (component, rendererMapperProps) => {
|
|
8177
|
+
var _a, _b, _c;
|
|
8178
|
+
return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags", "url", "method")), rendererMapperProps), {
|
|
8179
|
+
status: component.status,
|
|
8180
|
+
state: __spreadProps(__spreadValues({}, component.state), {
|
|
8181
|
+
filters: (_a = component.state.filters) != null ? _a : [],
|
|
8182
|
+
sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
|
|
8183
|
+
callToAction: mapCallToActionOptional(section.callToAction),
|
|
8184
|
+
items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
8185
|
+
callToAction: mapCallToActionOptional(item.callToAction),
|
|
8186
|
+
additionalInfo: mapAdditionalInfo2(item.additionalInfo)
|
|
8187
|
+
}))
|
|
8188
|
+
})),
|
|
8189
|
+
beforeSections: (_b = component.state.beforeSections) == null ? void 0 : _b.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render),
|
|
8190
|
+
afterSections: (_c = component.state.afterSections) == null ? void 0 : _c.map((child) => componentToRendererProps(child, rendererMapperProps)).map(rendererMapperProps.render)
|
|
8191
|
+
})
|
|
8192
|
+
});
|
|
8193
|
+
};
|
|
8194
|
+
|
|
7901
8195
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
7902
8196
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
7903
8197
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8527,6 +8821,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8527
8821
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8528
8822
|
case "button":
|
|
8529
8823
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8824
|
+
case "collection":
|
|
8825
|
+
return collectionComponentToProps(component, rendererMapperProps);
|
|
8530
8826
|
case "columns":
|
|
8531
8827
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8532
8828
|
case "container":
|