@swan-io/lake 1.0.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.
Files changed (288) hide show
  1. package/HISTORY.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/package.json +60 -0
  5. package/src/components/Alert.d.ts +10 -0
  6. package/src/components/Alert.js +36 -0
  7. package/src/components/AppOpeningAnimation.d.ts +10 -0
  8. package/src/components/AppOpeningAnimation.js +50 -0
  9. package/src/components/AutoWidthImage.d.ts +8 -0
  10. package/src/components/AutoWidthImage.js +26 -0
  11. package/src/components/Avatar.d.ts +7 -0
  12. package/src/components/Avatar.js +42 -0
  13. package/src/components/BorderedButton.d.ts +16 -0
  14. package/src/components/BorderedButton.js +98 -0
  15. package/src/components/BorderedIcon.d.ts +12 -0
  16. package/src/components/BorderedIcon.js +25 -0
  17. package/src/components/BottomPanel.d.ts +9 -0
  18. package/src/components/BottomPanel.js +94 -0
  19. package/src/components/Box.d.ts +65 -0
  20. package/src/components/Box.js +31 -0
  21. package/src/components/Breadcrumbs.d.ts +18 -0
  22. package/src/components/Breadcrumbs.js +362 -0
  23. package/src/components/Button.d.ts +15 -0
  24. package/src/components/Button.js +83 -0
  25. package/src/components/Caption.d.ts +6 -0
  26. package/src/components/Caption.js +11 -0
  27. package/src/components/Checkbox.d.ts +12 -0
  28. package/src/components/Checkbox.js +83 -0
  29. package/src/components/ChoicePicker.d.ts +11 -0
  30. package/src/components/ChoicePicker.js +99 -0
  31. package/src/components/Combobox.d.ts +29 -0
  32. package/src/components/Combobox.js +182 -0
  33. package/src/components/FailureIcon.d.ts +8 -0
  34. package/src/components/FailureIcon.js +4 -0
  35. package/src/components/FileTile.d.ts +11 -0
  36. package/src/components/FileTile.js +37 -0
  37. package/src/components/Fill.d.ts +8 -0
  38. package/src/components/Fill.js +24 -0
  39. package/src/components/FilterChooser.d.ts +15 -0
  40. package/src/components/FilterChooser.js +52 -0
  41. package/src/components/Filters.d.ts +57 -0
  42. package/src/components/Filters.js +229 -0
  43. package/src/components/FixedListView.d.ts +104 -0
  44. package/src/components/FixedListView.js +821 -0
  45. package/src/components/FixedListViewCells.d.ts +55 -0
  46. package/src/components/FixedListViewCells.js +157 -0
  47. package/src/components/Flag.d.ts +8 -0
  48. package/src/components/Flag.js +36 -0
  49. package/src/components/FlowPresentation.d.ts +12 -0
  50. package/src/components/FlowPresentation.js +70 -0
  51. package/src/components/FocusTrap.d.ts +16 -0
  52. package/src/components/FocusTrap.js +90 -0
  53. package/src/components/Form.d.ts +8 -0
  54. package/src/components/Form.js +17 -0
  55. package/src/components/FullViewportLayer.d.ts +7 -0
  56. package/src/components/FullViewportLayer.js +91 -0
  57. package/src/components/Grid.d.ts +13 -0
  58. package/src/components/Grid.js +33 -0
  59. package/src/components/Heading.d.ts +61 -0
  60. package/src/components/Heading.js +27 -0
  61. package/src/components/Icon.d.ts +191 -0
  62. package/src/components/Icon.js +11 -0
  63. package/src/components/Input.d.ts +34 -0
  64. package/src/components/Input.js +115 -0
  65. package/src/components/InputError.d.ts +8 -0
  66. package/src/components/InputError.js +16 -0
  67. package/src/components/Label.d.ts +10 -0
  68. package/src/components/Label.js +19 -0
  69. package/src/components/LakeAlert.d.ts +14 -0
  70. package/src/components/LakeAlert.js +75 -0
  71. package/src/components/LakeButton.d.ts +36 -0
  72. package/src/components/LakeButton.js +171 -0
  73. package/src/components/LakeCheckbox.d.ts +16 -0
  74. package/src/components/LakeCheckbox.js +54 -0
  75. package/src/components/LakeCombobox.d.ts +28 -0
  76. package/src/components/LakeCombobox.js +166 -0
  77. package/src/components/LakeCopyButton.d.ts +10 -0
  78. package/src/components/LakeCopyButton.js +16 -0
  79. package/src/components/LakeDownloadButton.d.ts +8 -0
  80. package/src/components/LakeDownloadButton.js +6 -0
  81. package/src/components/LakeHeading.d.ts +10 -0
  82. package/src/components/LakeHeading.js +19 -0
  83. package/src/components/LakeLabel.d.ts +19 -0
  84. package/src/components/LakeLabel.js +43 -0
  85. package/src/components/LakeModal.d.ts +14 -0
  86. package/src/components/LakeModal.js +132 -0
  87. package/src/components/LakeRadio.d.ts +9 -0
  88. package/src/components/LakeRadio.js +44 -0
  89. package/src/components/LakeScrollView.d.ts +10 -0
  90. package/src/components/LakeScrollView.js +35 -0
  91. package/src/components/LakeSearchField.d.ts +10 -0
  92. package/src/components/LakeSearchField.js +111 -0
  93. package/src/components/LakeSelect.d.ts +30 -0
  94. package/src/components/LakeSelect.js +183 -0
  95. package/src/components/LakeSlider.d.ts +12 -0
  96. package/src/components/LakeSlider.js +31 -0
  97. package/src/components/LakeStepper.d.ts +21 -0
  98. package/src/components/LakeStepper.js +134 -0
  99. package/src/components/LakeText.d.ts +19 -0
  100. package/src/components/LakeText.js +20 -0
  101. package/src/components/LakeTextInput.d.ts +36 -0
  102. package/src/components/LakeTextInput.js +154 -0
  103. package/src/components/LakeTooltip.d.ts +24 -0
  104. package/src/components/LakeTooltip.js +188 -0
  105. package/src/components/Link.d.ts +138 -0
  106. package/src/components/Link.js +23 -0
  107. package/src/components/ListRightPanel.d.ts +17 -0
  108. package/src/components/ListRightPanel.js +79 -0
  109. package/src/components/LoadingView.d.ts +9 -0
  110. package/src/components/LoadingView.js +24 -0
  111. package/src/components/Modal.d.ts +12 -0
  112. package/src/components/Modal.js +80 -0
  113. package/src/components/MultiSelect.d.ts +27 -0
  114. package/src/components/MultiSelect.js +223 -0
  115. package/src/components/MultilineInput.d.ts +15 -0
  116. package/src/components/MultilineInput.js +55 -0
  117. package/src/components/Picker.d.ts +26 -0
  118. package/src/components/Picker.js +116 -0
  119. package/src/components/PlainListView.d.ts +36 -0
  120. package/src/components/PlainListView.js +208 -0
  121. package/src/components/Popover.d.ts +23 -0
  122. package/src/components/Popover.js +147 -0
  123. package/src/components/PopoverContent.d.ts +8 -0
  124. package/src/components/PopoverContent.js +9 -0
  125. package/src/components/Portal.d.ts +7 -0
  126. package/src/components/Portal.js +9 -0
  127. package/src/components/Pressable.d.ts +348 -0
  128. package/src/components/Pressable.js +91 -0
  129. package/src/components/ProgressBar.d.ts +11 -0
  130. package/src/components/ProgressBar.js +46 -0
  131. package/src/components/ProjectEnvTag.d.ts +7 -0
  132. package/src/components/ProjectEnvTag.js +12 -0
  133. package/src/components/QuickActions.d.ts +15 -0
  134. package/src/components/QuickActions.js +38 -0
  135. package/src/components/RadioGroup.d.ts +16 -0
  136. package/src/components/RadioGroup.js +34 -0
  137. package/src/components/ReadOnlyFieldList.d.ts +6 -0
  138. package/src/components/ReadOnlyFieldList.js +8 -0
  139. package/src/components/ResponsiveContainer.d.ts +13 -0
  140. package/src/components/ResponsiveContainer.js +23 -0
  141. package/src/components/RightPanel.d.ts +10 -0
  142. package/src/components/RightPanel.js +102 -0
  143. package/src/components/SegmentedControl.d.ts +19 -0
  144. package/src/components/SegmentedControl.js +74 -0
  145. package/src/components/Separator.d.ts +10 -0
  146. package/src/components/Separator.js +19 -0
  147. package/src/components/SidebarNavigationTracker.d.ts +13 -0
  148. package/src/components/SidebarNavigationTracker.js +93 -0
  149. package/src/components/Slider.d.ts +11 -0
  150. package/src/components/Slider.js +119 -0
  151. package/src/components/SmsOpeningAnimation.d.ts +8 -0
  152. package/src/components/SmsOpeningAnimation.js +52 -0
  153. package/src/components/Space.d.ts +10 -0
  154. package/src/components/Space.js +23 -0
  155. package/src/components/Stack.d.ts +12 -0
  156. package/src/components/Stack.js +23 -0
  157. package/src/components/StepDots.d.ts +7 -0
  158. package/src/components/StepDots.js +24 -0
  159. package/src/components/Stepper.d.ts +9 -0
  160. package/src/components/Stepper.js +67 -0
  161. package/src/components/SuccessIcon.d.ts +8 -0
  162. package/src/components/SuccessIcon.js +4 -0
  163. package/src/components/Svg.d.ts +145 -0
  164. package/src/components/Svg.js +24 -0
  165. package/src/components/SwanLogo.d.ts +8 -0
  166. package/src/components/SwanLogo.js +11 -0
  167. package/src/components/Switch.d.ts +9 -0
  168. package/src/components/Switch.js +74 -0
  169. package/src/components/TabView.d.ts +16 -0
  170. package/src/components/TabView.js +398 -0
  171. package/src/components/Table.d.ts +34 -0
  172. package/src/components/Table.js +79 -0
  173. package/src/components/Tag.d.ts +17 -0
  174. package/src/components/Tag.js +76 -0
  175. package/src/components/Tile.d.ts +34 -0
  176. package/src/components/Tile.js +130 -0
  177. package/src/components/TilePlaceholder.d.ts +6 -0
  178. package/src/components/TilePlaceholder.js +51 -0
  179. package/src/components/ToastStack.d.ts +2 -0
  180. package/src/components/ToastStack.js +96 -0
  181. package/src/components/Tooltip.d.ts +18 -0
  182. package/src/components/Tooltip.js +162 -0
  183. package/src/components/TransitionGroupView.d.ts +12 -0
  184. package/src/components/TransitionGroupView.js +43 -0
  185. package/src/components/TransitionView.d.ts +12 -0
  186. package/src/components/TransitionView.js +43 -0
  187. package/src/components/WithCurrentColor.d.ts +12 -0
  188. package/src/components/WithCurrentColor.js +65 -0
  189. package/src/components/WithPartnerAccentColor.d.ts +7 -0
  190. package/src/components/WithPartnerAccentColor.js +91 -0
  191. package/src/constants/colors.d.ts +42 -0
  192. package/src/constants/colors.js +42 -0
  193. package/src/constants/commonStyles.d.ts +66 -0
  194. package/src/constants/commonStyles.js +45 -0
  195. package/src/constants/design.d.ts +168 -0
  196. package/src/constants/design.js +564 -0
  197. package/src/constants/insets.d.ts +10 -0
  198. package/src/constants/insets.js +22 -0
  199. package/src/constants/typography.d.ts +26 -0
  200. package/src/constants/typography.js +54 -0
  201. package/src/hooks/useAnimatedValue.d.ts +2 -0
  202. package/src/hooks/useAnimatedValue.js +3 -0
  203. package/src/hooks/useBodyClassName.d.ts +3 -0
  204. package/src/hooks/useBodyClassName.js +14 -0
  205. package/src/hooks/useBoolean.d.ts +8 -0
  206. package/src/hooks/useBoolean.js +12 -0
  207. package/src/hooks/useComputedColors.d.ts +10 -0
  208. package/src/hooks/useComputedColors.js +42 -0
  209. package/src/hooks/useDebounce.d.ts +1 -0
  210. package/src/hooks/useDebounce.js +12 -0
  211. package/src/hooks/useDisclosure.d.ts +8 -0
  212. package/src/hooks/useDisclosure.js +12 -0
  213. package/src/hooks/useFirstMountState.d.ts +1 -0
  214. package/src/hooks/useFirstMountState.js +9 -0
  215. package/src/hooks/useForceableState.d.ts +1 -0
  216. package/src/hooks/useForceableState.js +6 -0
  217. package/src/hooks/useHover.d.ts +11 -0
  218. package/src/hooks/useHover.js +4 -0
  219. package/src/hooks/useInterval.d.ts +1 -0
  220. package/src/hooks/useInterval.js +11 -0
  221. package/src/hooks/useLazyRef.d.ts +2 -0
  222. package/src/hooks/useLazyRef.js +9 -0
  223. package/src/hooks/useMergeRefs.d.ts +2 -0
  224. package/src/hooks/useMergeRefs.js +5 -0
  225. package/src/hooks/useNativeProp.d.ts +2 -0
  226. package/src/hooks/useNativeProp.js +9 -0
  227. package/src/hooks/useOutsideClick.d.ts +8 -0
  228. package/src/hooks/useOutsideClick.js +54 -0
  229. package/src/hooks/usePersistedState.d.ts +1 -0
  230. package/src/hooks/usePersistedState.js +21 -0
  231. package/src/hooks/usePressEvents.d.ts +31 -0
  232. package/src/hooks/usePressEvents.js +4 -0
  233. package/src/hooks/usePreviousValue.d.ts +1 -0
  234. package/src/hooks/usePreviousValue.js +8 -0
  235. package/src/hooks/useResponsive.d.ts +7 -0
  236. package/src/hooks/useResponsive.js +20 -0
  237. package/src/hooks/useUpdateEffect.d.ts +2 -0
  238. package/src/hooks/useUpdateEffect.js +10 -0
  239. package/src/hooks/useUrqlMutation.d.ts +4 -0
  240. package/src/hooks/useUrqlMutation.js +30 -0
  241. package/src/hooks/useUrqlQuery.d.ts +19 -0
  242. package/src/hooks/useUrqlQuery.js +73 -0
  243. package/src/state/toasts.d.ts +21 -0
  244. package/src/state/toasts.js +61 -0
  245. package/src/utils/__tests__/array.test.d.ts +1 -0
  246. package/src/utils/__tests__/array.test.js +127 -0
  247. package/src/utils/__tests__/base64.test.d.ts +1 -0
  248. package/src/utils/__tests__/base64.test.js +27 -0
  249. package/src/utils/__tests__/function.test.d.ts +1 -0
  250. package/src/utils/__tests__/function.test.js +36 -0
  251. package/src/utils/__tests__/object.test.d.ts +1 -0
  252. package/src/utils/__tests__/object.test.js +17 -0
  253. package/src/utils/__tests__/rifm.test.d.ts +1 -0
  254. package/src/utils/__tests__/rifm.test.js +124 -0
  255. package/src/utils/__tests__/string.test.d.ts +1 -0
  256. package/src/utils/__tests__/string.test.js +16 -0
  257. package/src/utils/a11y.d.ts +1 -0
  258. package/src/utils/a11y.js +18 -0
  259. package/src/utils/array.d.ts +6 -0
  260. package/src/utils/array.js +71 -0
  261. package/src/utils/base64.d.ts +2 -0
  262. package/src/utils/base64.js +20 -0
  263. package/src/utils/file.d.ts +2 -0
  264. package/src/utils/file.js +10 -0
  265. package/src/utils/flagCountry.d.ts +1 -0
  266. package/src/utils/flagCountry.js +1 -0
  267. package/src/utils/function.d.ts +4 -0
  268. package/src/utils/function.js +19 -0
  269. package/src/utils/math.d.ts +16 -0
  270. package/src/utils/math.js +47 -0
  271. package/src/utils/nullish.d.ts +10 -0
  272. package/src/utils/nullish.js +8 -0
  273. package/src/utils/object.d.ts +2 -0
  274. package/src/utils/object.js +7 -0
  275. package/src/utils/popper.d.ts +3 -0
  276. package/src/utils/popper.js +30 -0
  277. package/src/utils/rifm.d.ts +14 -0
  278. package/src/utils/rifm.js +53 -0
  279. package/src/utils/string.d.ts +4 -0
  280. package/src/utils/string.js +233 -0
  281. package/src/utils/timer.d.ts +11 -0
  282. package/src/utils/timer.js +46 -0
  283. package/src/utils/types.d.ts +8 -0
  284. package/src/utils/types.js +1 -0
  285. package/src/utils/userAgent.d.ts +4 -0
  286. package/src/utils/userAgent.js +9 -0
  287. package/src/utils/viewport.d.ts +1 -0
  288. package/src/utils/viewport.js +12 -0
@@ -0,0 +1,127 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { first, groupBy, last, partition, sortBy, sortedIndexOf } from "../array";
3
+ describe("first", () => {
4
+ test("returns the first element of an array", () => {
5
+ const numberArray = [1, 2, 3];
6
+ const stringArray = [];
7
+ expect(first(numberArray)).toBe(1);
8
+ expect(first(stringArray)).toBe(undefined);
9
+ });
10
+ });
11
+ describe("last", () => {
12
+ test("returns the last element of an array", () => {
13
+ const emptyArray = [];
14
+ const stringArray = ["foo", "bar"];
15
+ expect(last(emptyArray)).toBe(undefined);
16
+ expect(last(stringArray)).toBe("bar");
17
+ });
18
+ });
19
+ describe("partition", () => {
20
+ test("Returns the first element as truth if id_verified = true, and the second element as false", () => {
21
+ const output = [
22
+ {
23
+ id: "123",
24
+ id_verified: true,
25
+ email: "joe@gmail.com",
26
+ },
27
+ {
28
+ id: "456",
29
+ id_verified: false,
30
+ email: "doe@gmail.com",
31
+ },
32
+ {
33
+ id: "789",
34
+ id_verified: true,
35
+ email: "john@gmail.com",
36
+ },
37
+ ];
38
+ expect(partition(output, member => member.id_verified === true)).toStrictEqual([
39
+ [
40
+ {
41
+ id: "123",
42
+ id_verified: true,
43
+ email: "joe@gmail.com",
44
+ },
45
+ {
46
+ id: "789",
47
+ id_verified: true,
48
+ email: "john@gmail.com",
49
+ },
50
+ ],
51
+ [
52
+ {
53
+ id: "456",
54
+ id_verified: false,
55
+ email: "doe@gmail.com",
56
+ },
57
+ ],
58
+ ]);
59
+ });
60
+ test("Returns 2 empty arrays if the output is empty", () => {
61
+ const output = [];
62
+ expect(partition(output, member => member.id_verified === true)).toStrictEqual([[], []]);
63
+ });
64
+ test("Returns an empty first array, and a second containing the output if the function is looking for an inexistant parameter", () => {
65
+ const output = [
66
+ {
67
+ id: "123",
68
+ id_verified: true,
69
+ email: "joe@gmail.com",
70
+ },
71
+ {
72
+ id: "456",
73
+ id_verified: false,
74
+ email: "doe@gmail.com",
75
+ },
76
+ ];
77
+ expect(partition(output, member => member.id_verified === undefined)).toStrictEqual([
78
+ [],
79
+ [
80
+ {
81
+ id: "123",
82
+ id_verified: true,
83
+ email: "joe@gmail.com",
84
+ },
85
+ {
86
+ id: "456",
87
+ id_verified: false,
88
+ email: "doe@gmail.com",
89
+ },
90
+ ],
91
+ ]);
92
+ });
93
+ });
94
+ describe("sortBy", () => {
95
+ test("should sort", () => {
96
+ expect(sortBy([
97
+ { a: 1, b: 2 },
98
+ { a: 2, b: 2 },
99
+ { a: 1, b: 1 },
100
+ ], ["a", "b"])).toEqual([
101
+ { a: 1, b: 1 },
102
+ { a: 1, b: 2 },
103
+ { a: 2, b: 2 },
104
+ ]);
105
+ });
106
+ });
107
+ describe("sortedIndexOf", () => {
108
+ test("should find", () => {
109
+ expect(sortedIndexOf(Array.from({ length: 1000 }, (_, index) => index), 25)).toEqual(25);
110
+ });
111
+ test("should return -1 if not found", () => {
112
+ expect(sortedIndexOf(Array.from({ length: 1000 }, (_, index) => index), 1001)).toEqual(-1);
113
+ });
114
+ });
115
+ describe("groupBy", () => {
116
+ test("groups", () => {
117
+ expect(groupBy([1, 2, 3, 4, 5, 6], item => (item % 2 === 0 ? "even" : "odd"))).toEqual({
118
+ even: [2, 4, 6],
119
+ odd: [1, 3, 5],
120
+ });
121
+ expect(groupBy([0, 1, 2, 3, 4, 5, 6], item => item === 0 ? "zero" : item % 2 === 0 ? "even" : "odd")).toEqual({
122
+ zero: [0],
123
+ even: [2, 4, 6],
124
+ odd: [1, 3, 5],
125
+ });
126
+ });
127
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { expect, test } from "vitest";
2
+ import { decodeBase64, encodeBase64 } from "../base64";
3
+ test("decodeBase64", () => {
4
+ expect(decodeBase64("ZA==")).toBe("d");
5
+ expect(decodeBase64("ZGE=")).toBe("da");
6
+ expect(decodeBase64("ZGFu")).toBe("dan");
7
+ expect(decodeBase64("Z A==")).toBe("d");
8
+ expect(decodeBase64("ZG E=")).toBe("da");
9
+ expect(decodeBase64("ZGF u")).toBe("dan");
10
+ expect(decodeBase64("AA==")).toBe("\0");
11
+ expect(decodeBase64("AAA=")).toBe("\0\0");
12
+ expect(decodeBase64("AAAA")).toBe("\0\0\0");
13
+ expect(decodeBase64("5bCP6aO85by+")).toBe("小飼弾");
14
+ expect(decodeBase64("5bCP6aO85by-")).toBe("小飼弾");
15
+ expect(decodeBase64("8KCut+mHjuWutg==")).toBe("𠮷野家");
16
+ expect(decodeBase64("8KCut-mHjuWutg")).toBe("𠮷野家");
17
+ });
18
+ test("encodeBase64", () => {
19
+ expect(encodeBase64("d")).toBe("ZA==");
20
+ expect(encodeBase64("da")).toBe("ZGE=");
21
+ expect(encodeBase64("dan")).toBe("ZGFu");
22
+ expect(encodeBase64("\0")).toBe("AA==");
23
+ expect(encodeBase64("\0\0")).toBe("AAA=");
24
+ expect(encodeBase64("\0\0\0")).toBe("AAAA");
25
+ expect(encodeBase64("小飼弾")).toBe("5bCP6aO85by+");
26
+ expect(encodeBase64("𠮷野家")).toBe("8KCut+mHjuWutg==");
27
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { identity, memoize, noop, stubTrue } from "../function";
3
+ describe("stubTrue", () => {
4
+ test("returns true", () => {
5
+ expect(stubTrue()).toBe(true);
6
+ });
7
+ });
8
+ describe("identity", () => {
9
+ test("returns the first argument", () => {
10
+ const obj = {
11
+ val: 1,
12
+ };
13
+ expect(identity(obj)).toBe(obj);
14
+ });
15
+ });
16
+ describe("noop", () => {
17
+ test("returns `undefined`", () => {
18
+ expect(noop()).toBe(undefined);
19
+ });
20
+ });
21
+ describe("memoize", () => {
22
+ test("memoizes", () => {
23
+ let callCount = 0;
24
+ const expensiveFunction = (input) => {
25
+ ++callCount;
26
+ return input * 2;
27
+ };
28
+ const memoizedExpensiveFunction = memoize(expensiveFunction, x => String(x));
29
+ expect(memoizedExpensiveFunction(1)).toEqual(2);
30
+ expect(memoizedExpensiveFunction(1)).toEqual(2);
31
+ expect(callCount).toEqual(1);
32
+ expect(memoizedExpensiveFunction(2)).toEqual(4);
33
+ expect(memoizedExpensiveFunction(2)).toEqual(4);
34
+ expect(callCount).toEqual(2);
35
+ });
36
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { isPlainObject, pick } from "../object";
3
+ describe("isPlainObject", () => {
4
+ test("returns true if it's a plain object", () => {
5
+ const json = {
6
+ foo: "foo",
7
+ bar: false,
8
+ baz: 1,
9
+ };
10
+ expect(isPlainObject(json)).toBe(true);
11
+ });
12
+ });
13
+ describe("pick", () => {
14
+ test("picks", () => {
15
+ expect(pick({ foo: 1, bar: 2, baz: 3, quux: 4 }, ["foo", "bar"])).toEqual({ foo: 1, bar: 2 });
16
+ });
17
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cleanup, fireEvent, render } from "@testing-library/react";
3
+ import { useState } from "react";
4
+ import { Rifm } from "rifm";
5
+ import { afterEach, expect, test } from "vitest";
6
+ import { getRifmProps } from "../rifm";
7
+ const typeInInput = (input, value) => fireEvent.input(input, { target: { value } });
8
+ const clearInput = (input) => fireEvent.input(input, { target: { value: "" } });
9
+ afterEach(() => {
10
+ cleanup();
11
+ });
12
+ test('it respects accept: "alpha" param', async () => {
13
+ const props = getRifmProps({
14
+ accept: "alpha",
15
+ charMap: { 2: " ", 4: "/" },
16
+ maxLength: 6,
17
+ });
18
+ const Test = () => {
19
+ const [value, setValue] = useState("");
20
+ return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
21
+ };
22
+ const utils = render(_jsx(Test, {}));
23
+ const input = await utils.findByRole("textbox");
24
+ typeInInput(input, "test");
25
+ expect(input).toHaveValue("te st/");
26
+ clearInput(input);
27
+ typeInInput(input, "1234");
28
+ expect(input).toHaveValue("");
29
+ clearInput(input);
30
+ typeInInput(input, "te34");
31
+ expect(input).toHaveValue("te ");
32
+ clearInput(input);
33
+ });
34
+ test('it respects accept: "numeric" param', async () => {
35
+ const props = getRifmProps({
36
+ accept: "numeric",
37
+ charMap: { 2: " ", 4: "/" },
38
+ maxLength: 6,
39
+ });
40
+ const Test = () => {
41
+ const [value, setValue] = useState("");
42
+ return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
43
+ };
44
+ const utils = render(_jsx(Test, {}));
45
+ const input = await utils.findByRole("textbox");
46
+ typeInInput(input, "test");
47
+ expect(input).toHaveValue("");
48
+ clearInput(input);
49
+ typeInInput(input, "1234");
50
+ expect(input).toHaveValue("12 34/");
51
+ clearInput(input);
52
+ typeInInput(input, "te34");
53
+ expect(input).toHaveValue("34 ");
54
+ clearInput(input);
55
+ });
56
+ test('it respects accept: "alphanumeric" param', async () => {
57
+ const props = getRifmProps({
58
+ accept: "alphanumeric",
59
+ charMap: { 2: " ", 4: "/" },
60
+ maxLength: 6,
61
+ });
62
+ const Test = () => {
63
+ const [value, setValue] = useState("");
64
+ return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
65
+ };
66
+ const utils = render(_jsx(Test, {}));
67
+ const input = await utils.findByRole("textbox");
68
+ typeInInput(input, "test");
69
+ expect(input).toHaveValue("te st/");
70
+ clearInput(input);
71
+ typeInInput(input, "1234");
72
+ expect(input).toHaveValue("12 34/");
73
+ clearInput(input);
74
+ typeInInput(input, "te34");
75
+ expect(input).toHaveValue("te 34/");
76
+ clearInput(input);
77
+ typeInInput(input, "t__4");
78
+ expect(input).toHaveValue("t4 ");
79
+ clearInput(input);
80
+ });
81
+ test("it appends characters at given indexes", async () => {
82
+ const props = getRifmProps({
83
+ accept: "numeric",
84
+ charMap: { 2: " ", 4: "/" },
85
+ maxLength: 6,
86
+ });
87
+ const Test = () => {
88
+ const [value, setValue] = useState("");
89
+ return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
90
+ };
91
+ const utils = render(_jsx(Test, {}));
92
+ const input = await utils.findByRole("textbox");
93
+ typeInInput(input, "12");
94
+ expect(input).toHaveValue("12 ");
95
+ clearInput(input);
96
+ typeInInput(input, "1234");
97
+ expect(input).toHaveValue("12 34/");
98
+ clearInput(input);
99
+ typeInInput(input, "123456");
100
+ expect(input).toHaveValue("12 34/56");
101
+ clearInput(input);
102
+ });
103
+ test("it truncates the formatted text to the maximum length", async () => {
104
+ const props = getRifmProps({
105
+ accept: "numeric",
106
+ charMap: { 2: " ", 4: "/" },
107
+ maxLength: 6,
108
+ });
109
+ const Test = () => {
110
+ const [value, setValue] = useState("");
111
+ return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
112
+ };
113
+ const utils = render(_jsx(Test, {}));
114
+ const input = await utils.findByRole("textbox");
115
+ typeInInput(input, "1234");
116
+ expect(input).toHaveValue("12 34/");
117
+ clearInput(input);
118
+ typeInInput(input, "123456");
119
+ expect(input).toHaveValue("12 34/56");
120
+ clearInput(input);
121
+ typeInInput(input, "12345678");
122
+ expect(input).toHaveValue("12 34/56");
123
+ clearInput(input);
124
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { expect, test } from "vitest";
2
+ import { deburr, safeSplitAround, words } from "../string";
3
+ test("string safeSplitAround", () => {
4
+ expect(safeSplitAround("bar", "foo")).toEqual(["bar"]);
5
+ expect(safeSplitAround("foo", "foo")).toEqual(["foo"]);
6
+ expect(safeSplitAround("foo bar baz foo", "foo")).toEqual(["foo", " bar baz ", "foo"]);
7
+ expect(safeSplitAround("foo bar baz foo", "bar")).toEqual(["foo ", "bar", " baz foo"]);
8
+ });
9
+ test("deburr", () => {
10
+ expect(deburr("Bonjour à toutes & à tous")).toEqual("Bonjour a toutes & a tous");
11
+ });
12
+ test("words", () => {
13
+ expect(words("john doe")).toEqual(["john", "doe"]);
14
+ expect(words("john' doe")).toEqual(["john", "doe"]);
15
+ expect(words("john-doe")).toEqual(["john", "doe"]);
16
+ });
@@ -0,0 +1 @@
1
+ export declare const getFocusableElements: (rootNode?: Element, includeRoot?: boolean) => HTMLElement[];
@@ -0,0 +1,18 @@
1
+ // Pulled from https://github.com/KittyGiraudel/focusable-selectors
2
+ const FOCUSABLE_SELECTOR = [
3
+ 'a[href]:not([tabindex^="-"])',
4
+ 'area[href]:not([tabindex^="-"])',
5
+ 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])',
6
+ 'input[type="radio"]:not([disabled]):not([tabindex^="-"])',
7
+ 'select:not([disabled]):not([tabindex^="-"])',
8
+ 'textarea:not([disabled]):not([tabindex^="-"])',
9
+ 'button:not([disabled]):not([tabindex^="-"])',
10
+ 'iframe:not([tabindex^="-"])',
11
+ 'audio[controls]:not([tabindex^="-"])',
12
+ 'video[controls]:not([tabindex^="-"])',
13
+ '[contenteditable]:not([tabindex^="-"])',
14
+ '[tabindex]:not([tabindex^="-"])',
15
+ ].join(", ");
16
+ export const getFocusableElements = (rootNode = document.documentElement, includeRoot = true) => {
17
+ return (includeRoot && rootNode.matches(FOCUSABLE_SELECTOR) ? [rootNode] : []).concat(Array.from(rootNode.querySelectorAll(FOCUSABLE_SELECTOR)));
18
+ };
@@ -0,0 +1,6 @@
1
+ export declare const sortBy: <K extends string, T extends Record<K, unknown>>(array: T[], keys: K[]) => T[];
2
+ export declare const first: <T>(array: readonly T[]) => T | undefined;
3
+ export declare const last: <T>(array: readonly T[]) => T | undefined;
4
+ export declare const partition: <T>(array: T[], predicate: (value: T) => boolean) => [T[], T[]];
5
+ export declare const sortedIndexOf: <T>(array: T[], value: T) => number;
6
+ export declare const groupBy: <T, K extends string>(array: T[], getGroupName: (item: T) => K) => Partial<Record<K, T[]>>;
@@ -0,0 +1,71 @@
1
+ export const sortBy = (array, keys) => {
2
+ return [...array].sort((a, b) => {
3
+ let index = -1;
4
+ while (++index < keys.length) {
5
+ const key = keys[index];
6
+ if (key == undefined) {
7
+ return 0;
8
+ }
9
+ if (b[key] === a[key]) {
10
+ continue;
11
+ }
12
+ return b[key] > a[key] ? -1 : 1;
13
+ }
14
+ return 0;
15
+ });
16
+ };
17
+ export const first = (array) => {
18
+ return array[0];
19
+ };
20
+ export const last = (array) => {
21
+ return array[array.length - 1];
22
+ };
23
+ export const partition = (array, predicate) => {
24
+ const truthy = [];
25
+ const falsy = [];
26
+ for (const value of array) {
27
+ if (predicate(value)) {
28
+ truthy.push(value);
29
+ }
30
+ else {
31
+ falsy.push(value);
32
+ }
33
+ }
34
+ return [truthy, falsy];
35
+ };
36
+ export const sortedIndexOf = (array, value) => {
37
+ let startIndex = 0;
38
+ let endIndex = array.length;
39
+ // eslint-disable-next-line no-constant-condition
40
+ while (true) {
41
+ const searchIndex = startIndex + Math.round((endIndex - startIndex) / 2);
42
+ const item = array[searchIndex];
43
+ if (searchIndex === endIndex || searchIndex === startIndex) {
44
+ if (item === value) {
45
+ return startIndex;
46
+ }
47
+ return -1;
48
+ }
49
+ if (item === value) {
50
+ return searchIndex;
51
+ }
52
+ if (typeof item === "number") {
53
+ if (item > value) {
54
+ endIndex = searchIndex;
55
+ continue;
56
+ }
57
+ if (item < value) {
58
+ startIndex = searchIndex;
59
+ continue;
60
+ }
61
+ }
62
+ }
63
+ };
64
+ export const groupBy = (array, getGroupName) => {
65
+ const grouped = {};
66
+ array.forEach(item => {
67
+ const groupName = getGroupName(item);
68
+ grouped[groupName] = [...(grouped[groupName] ?? []), item];
69
+ });
70
+ return grouped;
71
+ };
@@ -0,0 +1,2 @@
1
+ export declare const encodeBase64: (value: string) => string;
2
+ export declare const decodeBase64: (base64: string) => string;
@@ -0,0 +1,20 @@
1
+ // Extracted from https://github.com/dankogai/js-base64
2
+ // Compared to atob / btoa, these functions are safe with non-Latin1 characters
3
+ const decodeUTF8 = TextDecoder.prototype.decode.bind(new TextDecoder());
4
+ const encodeUTF8 = TextEncoder.prototype.encode.bind(new TextEncoder());
5
+ const u8From = Uint8Array.from.bind(Uint8Array);
6
+ const fromCharCode = String.fromCharCode.bind(String);
7
+ export const encodeBase64 = (value) => {
8
+ const u8 = encodeUTF8(value);
9
+ // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
10
+ const maxArgs = 0x1000;
11
+ const data = [];
12
+ for (let index = 0; index < u8.length; index += maxArgs) {
13
+ data.push(fromCharCode(...u8.subarray(index, index + maxArgs)));
14
+ }
15
+ return btoa(data.join(""));
16
+ };
17
+ const unURI = (base64) => base64
18
+ .replace(/[-_]/g, substring => (substring == "-" ? "+" : "/"))
19
+ .replace(/[^A-Za-z0-9+/]/g, "");
20
+ export const decodeBase64 = (base64) => decodeUTF8(u8From(atob(unURI(base64)), value => value.charCodeAt(0)));
@@ -0,0 +1,2 @@
1
+ import type { IconName } from "../components/Icon";
2
+ export declare const getIconNameFromFilename: (filename: string) => IconName;
@@ -0,0 +1,10 @@
1
+ import { match } from "ts-pattern";
2
+ export const getIconNameFromFilename = (filename) => {
3
+ const ext = filename.split(".").pop()?.toLowerCase();
4
+ return match(ext)
5
+ .with("png", () => "lake-document-png")
6
+ .with("xls", () => "lake-document-xls")
7
+ .with("pdf", () => "lake-document-pdf")
8
+ .with("jpg", () => "lake-document-jpg")
9
+ .otherwise(() => "document-regular");
10
+ };
@@ -0,0 +1 @@
1
+ export declare const getFlagGlyphName: (flag: string) => string;
@@ -0,0 +1 @@
1
+ export const getFlagGlyphName = (flag) => `${flag.codePointAt(0)?.toString(16) ?? ""}-${flag.codePointAt(2)?.toString(16) ?? ""}`;
@@ -0,0 +1,4 @@
1
+ export declare const stubTrue: () => true;
2
+ export declare const identity: <T>(value: T) => T;
3
+ export declare const noop: () => void;
4
+ export declare const memoize: <Input extends unknown[], Output>(func: (...input: Input) => Output, getCacheKey: (...input: Input) => string) => (...input: Input) => Output;
@@ -0,0 +1,19 @@
1
+ export const stubTrue = () => {
2
+ return true;
3
+ };
4
+ export const identity = (value) => {
5
+ return value;
6
+ };
7
+ export const noop = () => { };
8
+ export const memoize = (func, getCacheKey) => {
9
+ const cache = new Map();
10
+ return (...input) => {
11
+ const key = getCacheKey(...input);
12
+ if (cache.has(key)) {
13
+ return cache.get(key);
14
+ }
15
+ const output = func(...input);
16
+ cache.set(key, output);
17
+ return output;
18
+ };
19
+ };
@@ -0,0 +1,16 @@
1
+ type InterpolateTuple = [number, number, ...number[]];
2
+ type FixedLength<L extends number> = number[] & {
3
+ 0: number;
4
+ length: L;
5
+ };
6
+ type InterpolateParams<T extends InterpolateTuple> = {
7
+ inputRange: T;
8
+ outputRange: FixedLength<T["length"]>;
9
+ clamp?: boolean;
10
+ };
11
+ /**
12
+ * This function is similar to `Animated.interpolate` except this one can be used with numbers
13
+ * Whereas `Animated.interpolate` works only with animated values and return a listener, not a single value
14
+ */
15
+ export declare const interpolate: <T extends InterpolateTuple>({ inputRange: input, outputRange: output, clamp, }: InterpolateParams<T>) => (value: number) => number;
16
+ export {};
@@ -0,0 +1,47 @@
1
+ import { isNotNullish, isNullish } from "./nullish";
2
+ const getValue = (array, index, name) => {
3
+ const value = array[index];
4
+ if (isNullish(value)) {
5
+ throw new Error(`Interpolation Error: index "${index}" doesn't exists in ${name}`);
6
+ }
7
+ return value;
8
+ };
9
+ const clampValue = (min, max) => (value) => Math.max(Math.min(value, max), min);
10
+ // Here we can disable no-non-null-assertion because this function is called in interpolate which have types checking if there is at least 2 values in range
11
+ const getRangeIndexes = (range, value) => {
12
+ if (value < range[0]) {
13
+ return [0, 1];
14
+ }
15
+ const maxIndex = range.length - 1;
16
+ for (let i = 0; i <= maxIndex; i += 1) {
17
+ const nextIndex = i + 1;
18
+ const startRange = getValue(range, i, "range");
19
+ const endRange = range[nextIndex];
20
+ if (isNotNullish(endRange) && value > startRange && value < endRange) {
21
+ return [i, nextIndex];
22
+ }
23
+ }
24
+ // if no values was found, it means value is upper than last range value
25
+ return [maxIndex - 1, maxIndex];
26
+ };
27
+ /**
28
+ * This function is similar to `Animated.interpolate` except this one can be used with numbers
29
+ * Whereas `Animated.interpolate` works only with animated values and return a listener, not a single value
30
+ */
31
+ export const interpolate = ({ inputRange: input, outputRange: output, clamp = true, }) => {
32
+ return (value) => {
33
+ const [startIndex, endIndex] = getRangeIndexes(input, value);
34
+ const inputStart = getValue(input, startIndex, "inputRange");
35
+ const inputEnd = getValue(input, endIndex, "inputRange");
36
+ const lastInput = getValue(input, input.length - 1, "inputRange");
37
+ const outputStart = getValue(output, startIndex, "outputRange");
38
+ const outputEnd = getValue(output, endIndex, "outputRange");
39
+ const inputRange = inputEnd - inputStart;
40
+ const outputRange = outputEnd - outputStart;
41
+ const valueToConvert = clamp ? clampValue(input[0], lastInput)(value) : value;
42
+ const valueWithoutOffset = valueToConvert - inputStart;
43
+ const outputWithoutOffset = (outputRange * valueWithoutOffset) / inputRange;
44
+ const outputValue = outputWithoutOffset + outputStart;
45
+ return outputValue;
46
+ };
47
+ };
@@ -0,0 +1,10 @@
1
+ type Nullish = null | undefined;
2
+ export declare const isNullish: (value: unknown) => value is Nullish;
3
+ export declare const isNotNullish: <T>(value: Nullish | T) => value is T;
4
+ export declare const isEmpty: (value: unknown) => value is "";
5
+ export declare const isNotEmpty: <T extends string>(value: T) => value is Exclude<T, "">;
6
+ export declare const isNullishOrEmpty: (value: unknown) => value is "" | Nullish;
7
+ export declare const isNotNullishOrEmpty: <T extends string>(value: Nullish | T) => value is Exclude<T, "">;
8
+ export declare const emptyToUndefined: <T extends string>(value: T) => Exclude<T, ""> | undefined;
9
+ export declare const nullishOrEmptyToUndefined: <T extends string>(value: Nullish | T) => Exclude<T, ""> | undefined;
10
+ export {};
@@ -0,0 +1,8 @@
1
+ export const isNullish = (value) => value == null;
2
+ export const isNotNullish = (value) => value != null;
3
+ export const isEmpty = (value) => value === "";
4
+ export const isNotEmpty = (value) => value !== "";
5
+ export const isNullishOrEmpty = (value) => value == null || value === "";
6
+ export const isNotNullishOrEmpty = (value) => value != null && value !== "";
7
+ export const emptyToUndefined = (value) => isNotEmpty(value) ? value : undefined;
8
+ export const nullishOrEmptyToUndefined = (value) => isNotNullishOrEmpty(value) ? value : undefined;
@@ -0,0 +1,2 @@
1
+ export declare const isPlainObject: (value: unknown) => boolean;
2
+ export declare const pick: <T extends Record<K, unknown>, K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
@@ -0,0 +1,7 @@
1
+ export const isPlainObject = (value) => {
2
+ return Object.prototype.toString.call(value) === "[object Object]";
3
+ };
4
+ export const pick = (object, keys) => {
5
+ const allowedKeys = new Set(keys);
6
+ return Object.fromEntries(Object.entries(object).filter(([key]) => allowedKeys.has(key)));
7
+ };
@@ -0,0 +1,3 @@
1
+ import { Modifier } from "react-popper";
2
+ export declare const getRootElement: (element: Element | null) => Element | null;
3
+ export declare const matchReferenceWidthModifier: Modifier<"matchReferenceWidth">;