@swan-io/lake 8.8.4 → 8.9.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/package.json +1 -1
- package/src/components/Flag.d.ts +10 -4
- package/src/components/Flag.js +14 -26
- package/src/utils/flagCountry.d.ts +3 -0
- package/src/utils/flagCountry.js +3 -0
- package/src/utils/object.d.ts +1 -0
- package/src/utils/object.js +20 -0
package/package.json
CHANGED
package/src/components/Flag.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { CountryCCA3 } from "@swan-io/shared-business/src/constants/countries";
|
|
1
|
+
import { CountryCCA2, CountryCCA3 } from "@swan-io/shared-business/src/constants/countries";
|
|
2
2
|
type Props = {
|
|
3
|
+
width?: number;
|
|
4
|
+
} & ({
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use cca2 prop instead
|
|
7
|
+
*/
|
|
3
8
|
icon: CountryCCA3;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
} | {
|
|
10
|
+
cca2: CountryCCA2;
|
|
11
|
+
});
|
|
12
|
+
export declare const Flag: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
7
13
|
export {};
|
package/src/components/Flag.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Lazy } from "@swan-io/boxed";
|
|
3
|
-
import {
|
|
3
|
+
import { getCCA2forCCA3, } from "@swan-io/shared-business/src/constants/countries";
|
|
4
4
|
import { useEffect, useMemo, useState } from "react";
|
|
5
5
|
import { Svg, Use } from "./Svg";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const UNICODE_OFFSET = 127462 - 65;
|
|
7
|
+
let svgUrl;
|
|
8
|
+
const svgUrlGetter = Lazy(async () => {
|
|
8
9
|
const { default: value } = await import("../assets/images/flags.svg");
|
|
9
|
-
|
|
10
|
+
svgUrl = value;
|
|
10
11
|
return value;
|
|
11
12
|
});
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
13
|
+
export const Flag = (props) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const cca2 = "cca2" in props ? props.cca2 : getCCA2forCCA3(props.icon);
|
|
16
|
+
const width = (_a = props.width) !== null && _a !== void 0 ? _a : 18;
|
|
17
|
+
const [url, setUrl] = useState(svgUrl);
|
|
15
18
|
useEffect(() => {
|
|
16
|
-
if (
|
|
17
|
-
void
|
|
19
|
+
if (svgUrl == null) {
|
|
20
|
+
void svgUrlGetter.get().then(setUrl);
|
|
18
21
|
}
|
|
19
22
|
}, []);
|
|
20
|
-
const flag = useMemo(() => {
|
|
21
|
-
|
|
22
|
-
const cca2 = (_a = countries.find(item => item.cca3 === icon)) === null || _a === void 0 ? void 0 : _a.cca2;
|
|
23
|
-
if (cca2 == null) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return ((UNICODE_OFFSET + cca2.charCodeAt(0)).toString(16) +
|
|
27
|
-
"-" +
|
|
28
|
-
(UNICODE_OFFSET + cca2.charCodeAt(1)).toString(16));
|
|
29
|
-
}, [icon]);
|
|
30
|
-
return (_jsx(Svg, { viewBox: "0 0 18 18",
|
|
31
|
-
// eslint-disable-next-line react-native/no-inline-styles
|
|
32
|
-
style: {
|
|
33
|
-
borderRadius: 2,
|
|
34
|
-
width,
|
|
35
|
-
height: width,
|
|
36
|
-
}, children: url != null && flag != null ? _jsx(Use, { xlinkHref: `${url}#${flag}` }) : null }));
|
|
23
|
+
const flag = useMemo(() => `${(UNICODE_OFFSET + cca2.charCodeAt(0)).toString(16)}-${(UNICODE_OFFSET + cca2.charCodeAt(1)).toString(16)}`, [cca2]);
|
|
24
|
+
return (_jsx(Svg, { viewBox: "0 0 18 18", style: { height: width, width }, children: url != null && flag != null ? _jsx(Use, { xlinkHref: `${url}#${flag}` }) : null }));
|
|
37
25
|
};
|
package/src/utils/flagCountry.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use the Flag component instead
|
|
3
|
+
*/
|
|
1
4
|
export const getFlagGlyphName = (flag) => { var _a, _b, _c, _d; return `${(_b = (_a = flag.codePointAt(0)) === null || _a === void 0 ? void 0 : _a.toString(16)) !== null && _b !== void 0 ? _b : ""}-${(_d = (_c = flag.codePointAt(2)) === null || _c === void 0 ? void 0 : _c.toString(16)) !== null && _d !== void 0 ? _d : ""}`; };
|
package/src/utils/object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const isPlainObject: (value: unknown) => boolean;
|
|
2
2
|
export declare const pick: <T extends Record<PropertyKey, unknown>, const K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
|
|
3
3
|
export declare const omit: <T extends Record<PropertyKey, unknown>, const K extends keyof T>(object: T, keys: K[]) => Omit<T, K>;
|
|
4
|
+
export declare const deepEqual: (a: unknown, b: unknown) => boolean;
|
package/src/utils/object.js
CHANGED
|
@@ -9,3 +9,23 @@ export const omit = (object, keys) => {
|
|
|
9
9
|
const disallowedKeys = new Set(keys);
|
|
10
10
|
return Object.fromEntries(Object.entries(object).filter(([key]) => !disallowedKeys.has(key)));
|
|
11
11
|
};
|
|
12
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
13
|
+
export const deepEqual = (a, b) => {
|
|
14
|
+
if (Object.is(a, b)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const aKeys = Object.keys(a);
|
|
21
|
+
const bKeys = Object.keys(b);
|
|
22
|
+
if (aKeys.length !== bKeys.length) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
for (const key of aKeys) {
|
|
26
|
+
if (!hasOwnProperty.call(b, key) || !deepEqual(a[key], b[key])) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
};
|