@wise/dynamic-flow-client 5.20.0-experimental-9265cac → 5.20.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/i18n/ar.json +38 -0
- package/build/i18n/ko.json +38 -0
- package/build/main.js +77 -373
- package/build/main.mjs +77 -373
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/build/types/domain/mappers/mapLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/types.d.ts +2 -3
- package/build/types/domain/types.d.ts.map +1 -1
- 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/types/domain/components/collectionComponent/CollectionComponent.d.ts +0 -7
- package/build/types/domain/components/collectionComponent/CollectionComponent.d.ts.map +0 -1
- package/build/types/domain/components/collectionComponent/applyCollectionResponse.d.ts +0 -3
- package/build/types/domain/components/collectionComponent/applyCollectionResponse.d.ts.map +0 -1
- package/build/types/domain/components/collectionComponent/types.d.ts +0 -73
- package/build/types/domain/components/collectionComponent/types.d.ts.map +0 -1
- package/build/types/domain/features/collection/getPerformCollectionQueryFunction.d.ts +0 -12
- package/build/types/domain/features/collection/getPerformCollectionQueryFunction.d.ts.map +0 -1
- package/build/types/domain/mappers/layout/collectionLayoutToComponent.d.ts +0 -7
- package/build/types/domain/mappers/layout/collectionLayoutToComponent.d.ts.map +0 -1
- package/build/types/renderers/mappers/collectionComponentToProps.d.ts +0 -5
- package/build/types/renderers/mappers/collectionComponentToProps.d.ts.map +0 -1
package/build/main.mjs
CHANGED
|
@@ -852,7 +852,6 @@ var getChildren = (node) => {
|
|
|
852
852
|
return node.tabs.flatMap((c) => c.childrenProps);
|
|
853
853
|
case "alert":
|
|
854
854
|
case "button":
|
|
855
|
-
case "collection":
|
|
856
855
|
case "input-checkbox":
|
|
857
856
|
case "input-date":
|
|
858
857
|
case "decision":
|
|
@@ -1470,348 +1469,6 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
|
|
|
1470
1469
|
)
|
|
1471
1470
|
});
|
|
1472
1471
|
|
|
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
|
-
|
|
1815
1472
|
// src/domain/components/ButtonComponent.ts
|
|
1816
1473
|
var createButtonComponent = (props) => __spreadValues({
|
|
1817
1474
|
type: "button",
|
|
@@ -1980,6 +1637,41 @@ var createDecisionComponent = (props) => __spreadValues({
|
|
|
1980
1637
|
// src/domain/mappers/utils/tags-utils.ts
|
|
1981
1638
|
var mapTags = ({ tag, tags }) => tags != null ? tags : tag != null ? [tag] : void 0;
|
|
1982
1639
|
|
|
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
|
+
|
|
1983
1675
|
// src/domain/mappers/layout/decisionLayoutToComponent.ts
|
|
1984
1676
|
var decisionLayoutToComponent = (uid, {
|
|
1985
1677
|
analyticsId,
|
|
@@ -2455,8 +2147,44 @@ var mapReviewField = (field, mapperProps) => {
|
|
|
2455
2147
|
});
|
|
2456
2148
|
};
|
|
2457
2149
|
|
|
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
|
+
|
|
2458
2186
|
// src/domain/components/searchComponent/SearchComponent.ts
|
|
2459
|
-
var
|
|
2187
|
+
var DEBOUNCE_TIME = 400;
|
|
2460
2188
|
var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate) => {
|
|
2461
2189
|
const { uid, analyticsId, control, emptyMessage, initialState, hint, margin, tags, title } = props;
|
|
2462
2190
|
const update = getInputUpdateFunction(onComponentUpdate);
|
|
@@ -2486,7 +2214,7 @@ var createSearchComponent = (props, performSearch, onBehavior, onComponentUpdate
|
|
|
2486
2214
|
}
|
|
2487
2215
|
});
|
|
2488
2216
|
};
|
|
2489
|
-
const debouncedSearch = debounce(search,
|
|
2217
|
+
const debouncedSearch = debounce(search, DEBOUNCE_TIME);
|
|
2490
2218
|
const component = {
|
|
2491
2219
|
type: "search",
|
|
2492
2220
|
kind: "layout",
|
|
@@ -2548,7 +2276,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2548
2276
|
if (requestHash !== latestSuccessfulRequestHash) {
|
|
2549
2277
|
const { method, param, url } = config;
|
|
2550
2278
|
const headers = { "Content-Type": "application/json" };
|
|
2551
|
-
const response = await (method === "GET" ? httpClient(
|
|
2279
|
+
const response = await (method === "GET" ? httpClient(addQueryParameter(url, param, query), {
|
|
2552
2280
|
method,
|
|
2553
2281
|
headers,
|
|
2554
2282
|
signal
|
|
@@ -2558,7 +2286,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2558
2286
|
signal,
|
|
2559
2287
|
body: JSON.stringify({ [param]: query })
|
|
2560
2288
|
}));
|
|
2561
|
-
const results = await
|
|
2289
|
+
const results = await parseResponse(response);
|
|
2562
2290
|
latestSuccessfulRequestHash = requestHash;
|
|
2563
2291
|
if (results.type === "layout") {
|
|
2564
2292
|
const mappedLayoutResult = {
|
|
@@ -2574,7 +2302,7 @@ var getPerformSearchFunction = (httpClient, mapLayoutToDomainComponent, defaultC
|
|
|
2574
2302
|
return latestSuccessfulResults;
|
|
2575
2303
|
};
|
|
2576
2304
|
};
|
|
2577
|
-
var
|
|
2305
|
+
var parseResponse = async (response) => {
|
|
2578
2306
|
if (response.ok) {
|
|
2579
2307
|
const body = await response.json().catch(() => null);
|
|
2580
2308
|
if (isValidResponseBody(body)) {
|
|
@@ -2591,7 +2319,7 @@ var parseResponse2 = async (response) => {
|
|
|
2591
2319
|
}
|
|
2592
2320
|
throw Error("error response");
|
|
2593
2321
|
};
|
|
2594
|
-
var
|
|
2322
|
+
var addQueryParameter = (url, key, value) => {
|
|
2595
2323
|
const [urlBase, urlQuery] = url.split("?");
|
|
2596
2324
|
const urlQueryParams = new URLSearchParams(urlQuery);
|
|
2597
2325
|
urlQueryParams.set(key, value);
|
|
@@ -2797,8 +2525,6 @@ var mapLayoutToComponent = (uid, layout, mapperProps, schemaComponents) => {
|
|
|
2797
2525
|
return boxLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2798
2526
|
case "button":
|
|
2799
2527
|
return buttonLayoutToComponent(uid, layout, mapperProps);
|
|
2800
|
-
case "collection":
|
|
2801
|
-
return collectionLayoutToComponent(uid, layout, mapperProps);
|
|
2802
2528
|
case "columns":
|
|
2803
2529
|
return columnsLayoutToComponent(uid, layout, mapperProps, schemaComponents);
|
|
2804
2530
|
case "decision":
|
|
@@ -8172,26 +7898,6 @@ var mapBoxControl = ({
|
|
|
8172
7898
|
return control;
|
|
8173
7899
|
};
|
|
8174
7900
|
|
|
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
|
-
|
|
8195
7901
|
// src/renderers/mappers/buttonComponentToProps.ts
|
|
8196
7902
|
var buttonComponentToProps = (component, rendererMapperProps) => {
|
|
8197
7903
|
return __spreadValues(__spreadProps(__spreadValues({
|
|
@@ -8821,8 +8527,6 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
8821
8527
|
return boxComponentToProps(component, rendererMapperProps);
|
|
8822
8528
|
case "button":
|
|
8823
8529
|
return buttonComponentToProps(component, rendererMapperProps);
|
|
8824
|
-
case "collection":
|
|
8825
|
-
return collectionComponentToProps(component, rendererMapperProps);
|
|
8826
8530
|
case "columns":
|
|
8827
8531
|
return columnsComponentToProps(component, rendererMapperProps);
|
|
8828
8532
|
case "container":
|