@rabbitio/ui-kit 1.0.0-beta.37 → 1.0.0-beta.38
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/dist/index.cjs +107 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +80 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +102 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +107 -0
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/common/errorUtils.js +15 -0
- package/src/components/utils/uiUtils.js +14 -0
- package/src/components/utils/urlQueryUtils.js +87 -0
- package/src/index.js +7 -0
package/dist/index.modern.js
CHANGED
|
@@ -1599,6 +1599,74 @@ function useReferredState(initialValue) {
|
|
|
1599
1599
|
return [reference, setReferredState];
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
|
+
const handleClickOutside = (exceptionsRefs, callback) => {
|
|
1603
|
+
function handleClick(event) {
|
|
1604
|
+
const isExceptionClicked = exceptionsRefs.find(ref => (ref == null ? void 0 : ref.current) && ref.current.contains(event.target));
|
|
1605
|
+
if (!isExceptionClicked) {
|
|
1606
|
+
callback();
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
document.addEventListener("click", handleClick);
|
|
1610
|
+
return () => document.removeEventListener("click", handleClick);
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
const PARAMETER_VALUES_SEPARATOR = "|*|"; // Sting that with high probability will not be in the user's data
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Adds specified parameter with values to the URL query string
|
|
1617
|
+
*
|
|
1618
|
+
* @param parameterName - String - name of the parameter
|
|
1619
|
+
* @param values - Array of String values
|
|
1620
|
+
* @param updateURLCallback - callback that will be called with the updated query string. Can be used to save it to URL
|
|
1621
|
+
*/
|
|
1622
|
+
function saveQueryParameterAndValues(parameterName, values, updateURLCallback = newQueryString => {}) {
|
|
1623
|
+
let parametersAndValues = parseSearchString();
|
|
1624
|
+
parametersAndValues = parametersAndValues.filter(parameterAndValues => parameterAndValues[0] !== parameterName);
|
|
1625
|
+
const parameterValuesForURL = encodeURIComponent(values.join(PARAMETER_VALUES_SEPARATOR));
|
|
1626
|
+
parametersAndValues.push([parameterName, parameterValuesForURL]);
|
|
1627
|
+
const newQueryString = `?${parametersAndValues.map(parameterAndValues => parameterAndValues.join("=")).join("&")}`;
|
|
1628
|
+
updateURLCallback(newQueryString);
|
|
1629
|
+
return newQueryString;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Removes specified parameter with values from the URL query string
|
|
1634
|
+
*
|
|
1635
|
+
* @param parameterName - String - name of the parameter
|
|
1636
|
+
* @param updateURLCallback - callback that will be called with the updated query string. Can be used to save it to URL
|
|
1637
|
+
*/
|
|
1638
|
+
// TODO: [tests, moderate] units required the same as or other functions in this module
|
|
1639
|
+
function removeQueryParameterAndValues(parameterName, updateURLCallback = newQueryString => {}) {
|
|
1640
|
+
let parametersAndValues = parseSearchString();
|
|
1641
|
+
parametersAndValues = parametersAndValues.filter(parameterAndValues => parameterAndValues[0] !== parameterName);
|
|
1642
|
+
const newQueryString = `?${parametersAndValues.map(parameterAndValues => parameterAndValues.join("=")).join("&")}`;
|
|
1643
|
+
updateURLCallback(newQueryString);
|
|
1644
|
+
return newQueryString;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* Retrieves parameter values from the URL query string.
|
|
1649
|
+
*
|
|
1650
|
+
* If there are several parameters with the same name in the URL then all their values are returned
|
|
1651
|
+
*
|
|
1652
|
+
* @param name {string} - parameter name
|
|
1653
|
+
* @return {string[]} [] - if the parameter is not present in URL. [""] - if parameter present but has empty value
|
|
1654
|
+
*/
|
|
1655
|
+
function getQueryParameterValues(name) {
|
|
1656
|
+
return parseSearchString().filter(parameterAndValue => parameterAndValue[0] === name).reduce((allValues, parameterAndValue) => {
|
|
1657
|
+
const values = decodeURIComponent(parameterAndValue[1] || "").split(PARAMETER_VALUES_SEPARATOR);
|
|
1658
|
+
return [...allValues, ...values];
|
|
1659
|
+
}, []);
|
|
1660
|
+
}
|
|
1661
|
+
function parseSearchString() {
|
|
1662
|
+
var _window$location$sear;
|
|
1663
|
+
const trimmed = (((_window$location$sear = window.location.search) == null ? void 0 : _window$location$sear.slice(1)) || "").trim();
|
|
1664
|
+
return trimmed && trimmed.split("&").map(parameterAndValue => parameterAndValue.split("=")) || [];
|
|
1665
|
+
}
|
|
1666
|
+
function getQueryParameterSingleValue(name) {
|
|
1667
|
+
return (getQueryParameterValues(name) || [])[0];
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1602
1670
|
/**
|
|
1603
1671
|
* This function improves the passed error object (its message) by adding the passed function name
|
|
1604
1672
|
* and additional message to it.
|
|
@@ -1624,6 +1692,17 @@ function improvedErrorMessage(e, settingFunction, additionalMessage) {
|
|
|
1624
1692
|
additionalMessage && (message += `${additionalMessage} `);
|
|
1625
1693
|
return message;
|
|
1626
1694
|
}
|
|
1695
|
+
function logErrorOrOutputToConsole(e) {
|
|
1696
|
+
try {
|
|
1697
|
+
// TODO: [dev] remove this after few weeks of testing output in real life
|
|
1698
|
+
// eslint-disable-next-line no-console
|
|
1699
|
+
console.log("BEFORE SAFE", e);
|
|
1700
|
+
Logger.log("logErrorOrOutputToConsole", safeStringify(e));
|
|
1701
|
+
} catch (e) {
|
|
1702
|
+
// eslint-disable-next-line no-console
|
|
1703
|
+
console.log("logErrorOrOutputToConsole", e);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1627
1706
|
|
|
1628
1707
|
class FiatCurrenciesService {
|
|
1629
1708
|
static getFullCurrencyNameByCode(code = "") {
|
|
@@ -3848,5 +3927,5 @@ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS = {
|
|
|
3848
3927
|
};
|
|
3849
3928
|
PublicSwapService._fiatDecimalsCount = FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
|
|
3850
3929
|
|
|
3851
|
-
export { AmountUtils, AssetIcon, BaseSwapCreationInfo, Blockchain, Button, Cache, Coin, EmailsApi, ExistingSwap, ExistingSwapWithFiatData, FiatCurrenciesService, LoadingDots, Logger, LogsStorage, Protocol, PublicSwapService, SupportChat, SwapProvider, SwapUtils, SwapspaceSwapProvider, improveAndRethrow, safeStringify, useCallHandlingErrors, useReferredState };
|
|
3930
|
+
export { AmountUtils, AssetIcon, BaseSwapCreationInfo, Blockchain, Button, Cache, Coin, EmailsApi, ExistingSwap, ExistingSwapWithFiatData, FiatCurrenciesService, LoadingDots, Logger, LogsStorage, Protocol, PublicSwapService, SupportChat, SwapProvider, SwapUtils, SwapspaceSwapProvider, getQueryParameterSingleValue, getQueryParameterValues, handleClickOutside, improveAndRethrow, logErrorOrOutputToConsole, removeQueryParameterAndValues, safeStringify, saveQueryParameterAndValues, useCallHandlingErrors, useReferredState };
|
|
3852
3931
|
//# sourceMappingURL=index.modern.js.map
|