@kirill.konshin/utils 0.0.17 → 0.0.19

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 (170) hide show
  1. package/.turbo/turbo-build.log +38 -38
  2. package/.turbo/turbo-test.log +37 -37
  3. package/CHANGELOG.md +12 -0
  4. package/dist/bootstrap/adaptiveContainer.d.ts +2 -1
  5. package/dist/bootstrap/adaptiveContainer.d.ts.map +1 -1
  6. package/dist/bootstrap/adaptiveContainer.js +2 -2
  7. package/dist/bootstrap/adaptiveContainer.js.map +1 -1
  8. package/dist/bootstrap/controls.d.ts +6 -6
  9. package/dist/bootstrap/controls.d.ts.map +1 -1
  10. package/dist/bootstrap/controls.js.map +1 -1
  11. package/dist/bootstrap/error.d.ts +4 -2
  12. package/dist/bootstrap/error.d.ts.map +1 -1
  13. package/dist/bootstrap/error.js +2 -7
  14. package/dist/bootstrap/error.js.map +1 -1
  15. package/dist/bootstrap/field.d.ts +4 -2
  16. package/dist/bootstrap/field.d.ts.map +1 -1
  17. package/dist/bootstrap/field.js +2 -2
  18. package/dist/bootstrap/field.js.map +1 -1
  19. package/dist/bootstrap/footer.d.ts +5 -5
  20. package/dist/bootstrap/footer.d.ts.map +1 -1
  21. package/dist/bootstrap/footer.js +9 -4
  22. package/dist/bootstrap/footer.js.map +1 -1
  23. package/dist/bootstrap/globalLoading.d.ts +4 -2
  24. package/dist/bootstrap/globalLoading.d.ts.map +1 -1
  25. package/dist/bootstrap/globalLoading.js +2 -2
  26. package/dist/bootstrap/globalLoading.js.map +1 -1
  27. package/dist/bootstrap/loading.d.ts +4 -2
  28. package/dist/bootstrap/loading.d.ts.map +1 -1
  29. package/dist/bootstrap/loading.js +3 -2
  30. package/dist/bootstrap/loading.js.map +1 -1
  31. package/dist/bootstrap/responsiveHelper.d.ts +2 -1
  32. package/dist/bootstrap/responsiveHelper.d.ts.map +1 -1
  33. package/dist/bootstrap/responsiveHelper.js +5 -5
  34. package/dist/bootstrap/responsiveHelper.js.map +1 -1
  35. package/dist/bootstrap/screen.d.ts +4 -2
  36. package/dist/bootstrap/screen.d.ts.map +1 -1
  37. package/dist/bootstrap/screen.js +3 -2
  38. package/dist/bootstrap/screen.js.map +1 -1
  39. package/dist/bootstrap/toaster.d.ts +4 -2
  40. package/dist/bootstrap/toaster.d.ts.map +1 -1
  41. package/dist/bootstrap/toaster.js +2 -5
  42. package/dist/bootstrap/toaster.js.map +1 -1
  43. package/dist/bootstrap/useModal.d.ts +2 -1
  44. package/dist/bootstrap/useModal.d.ts.map +1 -1
  45. package/dist/bootstrap/useModal.js +3 -3
  46. package/dist/bootstrap/useModal.js.map +1 -1
  47. package/dist/bootstrap/useWrappedForm.d.ts +1 -1
  48. package/dist/bootstrap/useWrappedForm.d.ts.map +1 -1
  49. package/dist/bootstrap/useWrappedForm.js.map +1 -1
  50. package/dist/core/cache.d.ts +2 -2
  51. package/dist/core/cache.d.ts.map +1 -1
  52. package/dist/core/cache.js.map +1 -1
  53. package/dist/core/errors.d.ts.map +1 -1
  54. package/dist/core/errors.js.map +1 -1
  55. package/dist/core/files.d.ts +2 -1
  56. package/dist/core/files.d.ts.map +1 -1
  57. package/dist/core/files.js +7 -3
  58. package/dist/core/files.js.map +1 -1
  59. package/dist/core/index.js +2 -1
  60. package/dist/core/ls.d.ts +1 -1
  61. package/dist/core/ls.d.ts.map +1 -1
  62. package/dist/core/ls.js.map +1 -1
  63. package/dist/core/measure.d.ts +4 -4
  64. package/dist/core/measure.d.ts.map +1 -1
  65. package/dist/core/measure.js +5 -1
  66. package/dist/core/measure.js.map +1 -1
  67. package/dist/core/worker.d.ts +3 -3
  68. package/dist/core/worker.d.ts.map +1 -1
  69. package/dist/core/worker.js.map +1 -1
  70. package/dist/core/wrpc.d.ts +4 -4
  71. package/dist/core/wrpc.d.ts.map +1 -1
  72. package/dist/core/wrpc.fixture.d.ts +1 -4
  73. package/dist/core/wrpc.fixture.d.ts.map +1 -1
  74. package/dist/core/wrpc.js.map +1 -1
  75. package/dist/electron/createWindow.d.ts.map +1 -1
  76. package/dist/electron/createWindow.js.map +1 -1
  77. package/dist/electron/updater.d.ts +1 -1
  78. package/dist/electron/updater.d.ts.map +1 -1
  79. package/dist/electron/updater.js +1 -1
  80. package/dist/electron/updater.js.map +1 -1
  81. package/dist/electron-builder/images.d.ts.map +1 -1
  82. package/dist/electron-builder/images.js.map +1 -1
  83. package/dist/mui/formControlFieldset.d.ts +2 -2
  84. package/dist/mui/formControlFieldset.d.ts.map +1 -1
  85. package/dist/mui/formControlFieldset.js.map +1 -1
  86. package/dist/mui/formLabelLegend.d.ts +2 -2
  87. package/dist/mui/formLabelLegend.d.ts.map +1 -1
  88. package/dist/mui/formLabelLegend.js.map +1 -1
  89. package/dist/mui/genericControl.d.ts +2 -2
  90. package/dist/mui/genericControl.d.ts.map +1 -1
  91. package/dist/mui/genericControl.js.map +1 -1
  92. package/dist/mui/readOnly.d.ts +2 -2
  93. package/dist/mui/readOnly.d.ts.map +1 -1
  94. package/dist/mui/readOnly.js.map +1 -1
  95. package/dist/next/measure.d.ts.map +1 -1
  96. package/dist/next/measure.js.map +1 -1
  97. package/dist/next/noSSR.d.ts +27 -3
  98. package/dist/next/noSSR.d.ts.map +1 -1
  99. package/dist/next/noSSR.js +2 -4
  100. package/dist/next/noSSR.js.map +1 -1
  101. package/dist/react/form/client.d.ts.map +1 -1
  102. package/dist/react/form/client.js.map +1 -1
  103. package/dist/react/form/form.d.ts +22 -8
  104. package/dist/react/form/form.d.ts.map +1 -1
  105. package/dist/react/form/form.js +27 -7
  106. package/dist/react/form/form.js.map +1 -1
  107. package/dist/react/index.js +2 -1
  108. package/dist/react/keyboard.d.ts +5 -6
  109. package/dist/react/keyboard.d.ts.map +1 -1
  110. package/dist/react/keyboard.js.map +1 -1
  111. package/dist/react/useFetcher.d.ts.map +1 -1
  112. package/dist/react/useFetcher.js.map +1 -1
  113. package/dist/react-native/share.d.ts +1 -1
  114. package/dist/react-native/share.d.ts.map +1 -1
  115. package/dist/react-native/share.js.map +1 -1
  116. package/dist/react-native/update.d.ts +2 -3
  117. package/dist/react-native/update.d.ts.map +1 -1
  118. package/dist/react-native/update.js +2 -2
  119. package/dist/react-native/update.js.map +1 -1
  120. package/dist/react-native/useAppState.d.ts +1 -1
  121. package/dist/react-native/useAppState.d.ts.map +1 -1
  122. package/dist/react-native/useAppState.js.map +1 -1
  123. package/dist/tailwind/fullpage.d.ts +2 -6
  124. package/dist/tailwind/fullpage.d.ts.map +1 -1
  125. package/dist/tailwind/fullpage.js.map +1 -1
  126. package/dist/tailwind/responsiveHelper.d.ts +2 -1
  127. package/dist/tailwind/responsiveHelper.d.ts.map +1 -1
  128. package/dist/tailwind/responsiveHelper.js +2 -2
  129. package/dist/tailwind/responsiveHelper.js.map +1 -1
  130. package/package.json +1 -1
  131. package/src/bootstrap/adaptiveContainer.tsx +3 -3
  132. package/src/bootstrap/controls.stories.tsx +1 -1
  133. package/src/bootstrap/controls.tsx +12 -12
  134. package/src/bootstrap/error.tsx +7 -10
  135. package/src/bootstrap/field.tsx +11 -9
  136. package/src/bootstrap/footer.tsx +17 -5
  137. package/src/bootstrap/globalLoading.tsx +5 -3
  138. package/src/bootstrap/loading.tsx +10 -8
  139. package/src/bootstrap/responsiveHelper.tsx +11 -6
  140. package/src/bootstrap/screen.tsx +24 -22
  141. package/src/bootstrap/toaster.tsx +8 -6
  142. package/src/bootstrap/useModal.tsx +12 -7
  143. package/src/bootstrap/useWrappedForm.ts +9 -7
  144. package/src/core/cache.ts +15 -8
  145. package/src/core/errors.ts +4 -1
  146. package/src/core/files.ts +8 -4
  147. package/src/core/ls.ts +8 -4
  148. package/src/core/measure.ts +55 -7
  149. package/src/core/worker.ts +18 -11
  150. package/src/core/wrpc.fixture.ts +40 -6
  151. package/src/core/wrpc.ts +23 -5
  152. package/src/electron/createWindow.ts +3 -3
  153. package/src/electron/updater.ts +1 -1
  154. package/src/electron-builder/images.ts +1 -1
  155. package/src/mui/formControlFieldset.tsx +2 -2
  156. package/src/mui/formLabelLegend.tsx +2 -2
  157. package/src/mui/genericControl.tsx +2 -2
  158. package/src/mui/readOnly.tsx +2 -2
  159. package/src/next/measure.ts +19 -2
  160. package/src/next/noSSR.tsx +26 -7
  161. package/src/react/form/client.tsx +13 -2
  162. package/src/react/form/form.tsx +67 -18
  163. package/src/react/keyboard.tsx +9 -4
  164. package/src/react/useFetcher.ts +8 -3
  165. package/src/react-native/share.ts +1 -1
  166. package/src/react-native/update.tsx +3 -3
  167. package/src/react-native/useAppState.ts +1 -1
  168. package/src/tailwind/fullpage.tsx +2 -2
  169. package/src/tailwind/responsiveHelper.tsx +3 -3
  170. package/tsconfig.json +1 -0
@@ -1,19 +1,16 @@
1
1
  'use client';
2
2
 
3
- import React from 'react';
3
+ import React, { FC } from 'react';
4
4
  import { Alert, AlertProps, Button, ButtonProps } from 'react-bootstrap';
5
5
 
6
- //TODO Create MUI-specific?
7
- export function ErrorAlert({
8
- onRetry,
9
- children,
10
- buttonProps,
11
- ...props
12
- }: {
6
+ export type ErrorAlertProps = {
13
7
  children?: Error | string | any;
14
8
  onRetry?: () => any;
15
9
  buttonProps?: ButtonProps;
16
- }) {
10
+ };
11
+
12
+ //TODO Create MUI-specific?
13
+ export const ErrorAlert: FC<ErrorAlertProps> = function ErrorAlert({ onRetry, children, buttonProps, ...props }) {
17
14
  if (!children) return null;
18
15
 
19
16
  return (
@@ -37,4 +34,4 @@ export function ErrorAlert({
37
34
  )}
38
35
  </Alert>
39
36
  );
40
- }
37
+ };
@@ -1,7 +1,15 @@
1
- import React from 'react';
1
+ import React, { FC } from 'react';
2
2
  import { Form, FormGroupProps, FormLabelProps, FormTextProps } from 'react-bootstrap';
3
3
 
4
- export function FieldGroup({
4
+ export type FieldGroupProps = FormGroupProps & {
5
+ label?: any;
6
+ labelProps?: FormLabelProps;
7
+ text?: any;
8
+ textProps?: FormTextProps;
9
+ horizontal?: boolean;
10
+ };
11
+
12
+ export const FieldGroup: FC<FieldGroupProps> = function FieldGroup({
5
13
  label,
6
14
  labelProps = {},
7
15
  text,
@@ -9,12 +17,6 @@ export function FieldGroup({
9
17
  horizontal,
10
18
  children,
11
19
  ...props
12
- }: FormGroupProps & {
13
- label?: any;
14
- labelProps?: FormLabelProps;
15
- text?: any;
16
- textProps?: FormTextProps;
17
- horizontal?: boolean;
18
20
  }) {
19
21
  if (horizontal) {
20
22
  props.className = 'hstack gap-3 ' + (props.className || '');
@@ -32,4 +34,4 @@ export function FieldGroup({
32
34
  {text && !horizontal && <Form.Text {...textProps}>{text}</Form.Text>}{' '}
33
35
  </Form.Group>
34
36
  );
35
- }
37
+ };
@@ -1,9 +1,21 @@
1
- import React from 'react';
1
+ import React, { FC } from 'react';
2
2
  import { Nav, Navbar } from 'react-bootstrap';
3
3
  import { useBreakpoint } from './responsiveHelper';
4
4
  import { AdaptiveContainer } from './adaptiveContainer';
5
5
 
6
- export function FooterNavItem({ href, icon, active = false, children = '' }) {
6
+ export type FooterNavItemProps = {
7
+ href: any;
8
+ icon: any;
9
+ active?: boolean | undefined;
10
+ children?: string | undefined;
11
+ };
12
+
13
+ export const FooterNavItem: FC<FooterNavItemProps> = function FooterNavItem({
14
+ href,
15
+ icon,
16
+ active = false,
17
+ children = '',
18
+ }) {
7
19
  // const pathname = usePathname();
8
20
 
9
21
  const isFilepath = icon.includes('.');
@@ -30,9 +42,9 @@ export function FooterNavItem({ href, icon, active = false, children = '' }) {
30
42
  );
31
43
 
32
44
  return <Nav.Item style={{ flex: 1 }}>{link}</Nav.Item>;
33
- }
45
+ };
34
46
 
35
- export function Footer({ children }) {
47
+ export const Footer: FC<any> = function Footer({ children }) {
36
48
  const { isDesktop } = useBreakpoint();
37
49
 
38
50
  return (
@@ -46,4 +58,4 @@ export function Footer({ children }) {
46
58
  </Navbar>
47
59
  </div>
48
60
  );
49
- }
61
+ };
@@ -1,8 +1,10 @@
1
- import React from 'react';
1
+ import React, { FC } from 'react';
2
2
  // import { useLoading, useLoadingTimeout } from '../redux/loadingSlice';
3
3
  import { Loading } from './loading';
4
4
 
5
- export function GlobalLoading({ loading }: { loading: boolean }) {
5
+ export type GlobalLoadingProps = { loading: boolean };
6
+
7
+ export const GlobalLoading: FC<GlobalLoadingProps> = function GlobalLoading({ loading }) {
6
8
  // const { loading } = useLoading();
7
9
 
8
10
  // useLoadingTimeout(15000); // escape latch if something is stuck
@@ -14,4 +16,4 @@ export function GlobalLoading({ loading }: { loading: boolean }) {
14
16
  <Loading />
15
17
  </div>
16
18
  );
17
- }
19
+ };
@@ -1,16 +1,18 @@
1
1
  import { Spinner, SpinnerProps, Stack } from 'react-bootstrap';
2
- import React from 'react';
2
+ import React, { FC, memo } from 'react';
3
3
 
4
- export function Loading({
5
- children = 'Loading...' as any,
6
- show = true,
7
- className = '',
8
- size,
9
- }: {
4
+ export type LoadingProps = {
10
5
  children?: any;
11
6
  show?: boolean;
12
7
  className?: string;
13
8
  size?: SpinnerProps['size'];
9
+ };
10
+
11
+ export const Loading: FC<LoadingProps> = memo(function Loading({
12
+ children = 'Loading...' as any,
13
+ show = true,
14
+ className = '',
15
+ size,
14
16
  }) {
15
17
  if (!show) return null;
16
18
  return (
@@ -19,4 +21,4 @@ export function Loading({
19
21
  <span>{children}</span>
20
22
  </Stack>
21
23
  );
22
- }
24
+ });
@@ -1,11 +1,15 @@
1
1
  'use client';
2
2
 
3
- import React from 'react';
3
+ import React, { FC, useEffect, useState } from 'react';
4
4
 
5
- export function useBreakpoint() {
6
- const [breakpoint, setBreakpoint] = React.useState('xs');
5
+ export function useBreakpoint(): {
6
+ breakpoint: string;
7
+ isMobile: boolean;
8
+ isDesktop: boolean;
9
+ } {
10
+ const [breakpoint, setBreakpoint] = useState('xs');
7
11
 
8
- React.useEffect(() => {
12
+ useEffect(() => {
9
13
  const updateBreakpoint = () => {
10
14
  const width = window.innerWidth;
11
15
  if (width < 576) {
@@ -24,6 +28,7 @@ export function useBreakpoint() {
24
28
  };
25
29
 
26
30
  updateBreakpoint();
31
+
27
32
  window.addEventListener('resize', updateBreakpoint);
28
33
 
29
34
  return () => {
@@ -36,7 +41,7 @@ export function useBreakpoint() {
36
41
  return { breakpoint, isMobile, isDesktop: !isMobile };
37
42
  }
38
43
 
39
- export function ResponsiveHelperBS() {
44
+ export const ResponsiveHelperBS: FC = function ResponsiveHelperBS() {
40
45
  return (
41
46
  <span className="small position-fixed bottom-0 z-3" style={{ fontSize: '9px', right: 1, lineHeight: 1 }}>
42
47
  <small className="d-block d-sm-none">XS</small>
@@ -47,4 +52,4 @@ export function ResponsiveHelperBS() {
47
52
  <small className="d-none d-xxl-block">XXL</small>
48
53
  </span>
49
54
  );
50
- }
55
+ };
@@ -1,10 +1,31 @@
1
- import React from 'react';
1
+ import React, { FC, memo } from 'react';
2
2
  import { Button, Navbar, Nav, Stack } from 'react-bootstrap';
3
3
  import { useBreakpoint } from './responsiveHelper';
4
4
  import { AdaptiveContainer } from './adaptiveContainer';
5
5
 
6
+ export type ScreenProps = {
7
+ backBtn?: any;
8
+ backCb?: any;
9
+ backIcon?: any;
10
+ forwardBtn?: any;
11
+ forwardIcon?: any;
12
+ forwardCb?: any;
13
+ children: any;
14
+ contentClassName?: string;
15
+ noContentPadding?: boolean;
16
+ header?: any; // resides on top panel in mobile, does not scroll, before content on desktop
17
+ footer?: any; // resides on bottom menu panel in mobile, does not scroll, or after content on desktop
18
+ menu?: any;
19
+ title?: any;
20
+ centerContent?: boolean;
21
+ noHeader?: boolean;
22
+ noFooter?: boolean;
23
+ noMenu?: boolean;
24
+ // noFolders?: boolean;
25
+ };
26
+
6
27
  //TODO Footer -> menu
7
- export function Screen({
28
+ export const Screen: FC<ScreenProps> = memo(function Screen({
8
29
  backBtn,
9
30
  backCb,
10
31
  backIcon,
@@ -23,25 +44,6 @@ export function Screen({
23
44
  noFooter = false,
24
45
  noMenu = false,
25
46
  // noFolders = false,
26
- }: {
27
- backBtn?;
28
- backCb?;
29
- backIcon?;
30
- forwardBtn?;
31
- forwardIcon?;
32
- forwardCb?;
33
- children: any;
34
- contentClassName?: string;
35
- noContentPadding?: boolean;
36
- header?: any; // resides on top panel in mobile, does not scroll, before content on desktop
37
- footer?: any; // resides on bottom menu panel in mobile, does not scroll, or after content on desktop
38
- menu?: any;
39
- title?: any;
40
- centerContent?: boolean;
41
- noHeader?: boolean;
42
- noFooter?: boolean;
43
- noMenu?: boolean;
44
- // noFolders?: boolean;
45
47
  }) {
46
48
  // const router = useRouter();
47
49
 
@@ -141,4 +143,4 @@ export function Screen({
141
143
  )}
142
144
  </div>
143
145
  );
144
- }
146
+ });
@@ -1,17 +1,19 @@
1
1
  'use client';
2
2
 
3
- import React, { useState } from 'react';
3
+ import React, { useState, FC } from 'react';
4
4
  import { Toast, ToastProps } from 'react-bootstrap';
5
5
  // import { useToaster } from '../redux/toasterSlice';
6
6
 
7
- export function Toaster({
8
- toast,
9
- }: { toast: string | { message: string; title?: string; variant?: 'dark' | 'success' | 'danger' } } & ToastProps) {
7
+ export type ToasterProps = {
8
+ toast: string | { message: string; title?: string; variant?: 'dark' | 'success' | 'danger' };
9
+ } & ToastProps;
10
+
11
+ export const Toaster: FC<ToasterProps> = function Toaster({ toast }) {
10
12
  //const { toast, setToast } = useToaster();
11
13
  const [dismissed, setDismissed] = useState(false);
12
14
 
13
15
  const msg = typeof toast === 'string' ? toast : toast?.message;
14
- const title = typeof toast === 'string' ? 'Notification' : toast?.title;
16
+ // const title = typeof toast === 'string' ? 'Notification' : toast?.title;
15
17
  const variant = typeof toast === 'string' ? '' : toast?.variant;
16
18
 
17
19
  return (
@@ -35,4 +37,4 @@ export function Toaster({
35
37
  </Toast.Body>
36
38
  </Toast>
37
39
  );
38
- }
40
+ };
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useMemo, useState } from 'react';
1
+ import React, { useCallback, useMemo, useState, JSX, FC, memo } from 'react';
2
2
  import { Button, Modal, ModalProps, Offcanvas, OffcanvasProps, Stack } from 'react-bootstrap';
3
3
 
4
4
  export type UseModalArgs = { onClose?: any; showOnMount?: boolean };
@@ -14,18 +14,23 @@ export type UseModalProps = {
14
14
  containerProps?: ModalProps | OffcanvasProps;
15
15
  };
16
16
 
17
- export function useModal({ onClose, showOnMount }: UseModalArgs = {}) {
17
+ export function useModal({ onClose, showOnMount }: UseModalArgs = {}): {
18
+ show: boolean | undefined;
19
+ close: () => void;
20
+ open: () => void;
21
+ ModalDialog: FC<ModalProps>;
22
+ } {
18
23
  const [show, setShow] = useState(showOnMount);
19
24
 
20
- const close = useCallback(() => {
25
+ const close = useCallback((): void => {
21
26
  setShow(false);
22
27
  onClose?.();
23
28
  }, [onClose]);
24
29
 
25
- const open = useCallback(() => setShow(true), []);
30
+ const open = useCallback((): void => setShow(true), []);
26
31
 
27
32
  const defaultOnSubmit = useCallback(
28
- (e) => {
33
+ (e: any) => {
29
34
  e.preventDefault();
30
35
  close();
31
36
  },
@@ -34,7 +39,7 @@ export function useModal({ onClose, showOnMount }: UseModalArgs = {}) {
34
39
 
35
40
  const ModalDialog = useMemo(
36
41
  () =>
37
- function ModalDialog({
42
+ memo(function ModalDialog({
38
43
  children,
39
44
  show,
40
45
  onSubmit = defaultOnSubmit,
@@ -80,7 +85,7 @@ export function useModal({ onClose, showOnMount }: UseModalArgs = {}) {
80
85
  </form>
81
86
  </Container>
82
87
  );
83
- },
88
+ }),
84
89
  [close, defaultOnSubmit],
85
90
  );
86
91
 
@@ -1,7 +1,7 @@
1
1
  import { useForm, FormState } from 'react-hook-form';
2
2
  import { useCallback } from 'react';
3
3
 
4
- export const isFormLoading = (formState: FormState<any>) => formState.isLoading || formState.isSubmitting;
4
+ export const isFormLoading = (formState: FormState<any>): boolean => formState.isLoading || formState.isSubmitting;
5
5
 
6
6
  export const useWrappedForm: typeof useForm = (options) => {
7
7
  const form = useForm(options);
@@ -12,7 +12,7 @@ export const useWrappedForm: typeof useForm = (options) => {
12
12
  try {
13
13
  await onSubmit(data);
14
14
  } catch (e) {
15
- form.setError('root', { type: 'server', message: e.message });
15
+ form.setError('root', { type: 'server', message: (e as Error).message });
16
16
  console.error('Error submitting form', e);
17
17
  }
18
18
  };
@@ -33,8 +33,10 @@ export const useWrappedForm: typeof useForm = (options) => {
33
33
  * https://codesandbox.io/s/react-hook-form-nested-portal-6x3fvy?file=/src/App.tsx:1905-2261
34
34
  * https://github.com/react-hook-form/react-hook-form/issues/1005#issuecomment-988380981
35
35
  */
36
- export const stopPropagation = (callback) => (e) => {
37
- e.stopPropagation();
38
- e.preventDefault();
39
- callback(e);
40
- };
36
+ export const stopPropagation =
37
+ (callback: any) =>
38
+ (e: Event): void => {
39
+ e.stopPropagation();
40
+ e.preventDefault();
41
+ callback(e);
42
+ };
package/src/core/cache.ts CHANGED
@@ -2,20 +2,20 @@ import ManyKeysMap from 'many-keys-map';
2
2
 
3
3
  export type MaybePromise<T> = T | Promise<T>;
4
4
 
5
- export const shallowCompare = (prev: any, next: any) =>
5
+ export const shallowCompare = (prev: any, next: any): boolean =>
6
6
  Array.from(new Set([...Object.keys(prev), ...Object.keys(next)])).every((key) => prev[key] === next[key]);
7
7
 
8
- export const equal = (prev: any, next: any) => prev === next;
8
+ export const equal = (prev: any, next: any): boolean => prev === next;
9
9
 
10
10
  const UNUSED = Symbol('UNUSED');
11
- export const ANY = Symbol('*');
11
+ export const ANY: unique symbol = Symbol('*');
12
12
 
13
13
  export function createTracker<Dep = any>(whenDifferent: (next: Dep, prev?: Dep) => any, shallow = false) {
14
14
  let lastDependency: Dep = UNUSED as any;
15
15
 
16
16
  const comparator = shallow ? shallowCompare : equal;
17
17
 
18
- return function tracker(dependency: Dep) {
18
+ return function tracker(dependency: Dep): Dep | false {
19
19
  // console.log('Tracker', lastDependency, dependency);
20
20
 
21
21
  if (lastDependency !== UNUSED && comparator(lastDependency, dependency)) {
@@ -61,7 +61,14 @@ export function memo<Key extends any[], Val, SerializedKey extends any[] = Key>(
61
61
  invalidate?: (prev: Val, ...key: SerializedKey) => boolean;
62
62
  dispose?: (prev: Val, ...key: SerializedKey) => void;
63
63
  } = {},
64
- ) {
64
+ ): {
65
+ (...args: Key): Promise<{
66
+ value?: Val;
67
+ hit: boolean;
68
+ }>;
69
+ clear: (...condition: Key | any[]) => void;
70
+ size: () => number;
71
+ } {
65
72
  const map = new ManyKeysMap<SerializedKey, Val>();
66
73
 
67
74
  //TODO Extend ManyKeysMap
@@ -194,7 +201,7 @@ export abstract class TransformerMap<Key, Val = Key> extends Map<Key, Val> {
194
201
  return oldValue;
195
202
  }
196
203
 
197
- delete(key: Key) {
204
+ delete(key: Key): boolean {
198
205
  const val = this.get(key);
199
206
  const has = typeof val !== 'undefined';
200
207
  if (has) this.dispose(val, key);
@@ -206,9 +213,9 @@ export abstract class TransformerMap<Key, Val = Key> extends Map<Key, Val> {
206
213
  * Do something with the value and key before removing it from cache
207
214
  * For example, close a file or a bitmap
208
215
  */
209
- protected dispose(value: Val, key: Key) {}
216
+ protected dispose(value: Val, key: Key): void {}
210
217
 
211
- clear() {
218
+ clear(): void {
212
219
  console.log('CLEAR cache', this.name);
213
220
  this.forEach(this.dispose);
214
221
  super.clear();
@@ -1,5 +1,8 @@
1
1
  // @see https://www.youtube.com/watch?v=AdmGHwvgaVs
2
- export function catchErrors<T, E extends Error = Error>(promise: Promise<T>, errors?: E[]) {
2
+ export function catchErrors<T, E extends Error = Error>(
3
+ promise: Promise<T>,
4
+ errors?: E[],
5
+ ): Promise<any[] | (T | undefined)[]> {
3
6
  return promise
4
7
  .then((data) => [undefined, data])
5
8
  .catch((error) => {
package/src/core/files.ts CHANGED
@@ -1,9 +1,13 @@
1
- import * as saver from 'file-saver';
1
+ export const downloadFile = async (file: File): Promise<void> => {
2
+ //FIXME https://github.com/eligrey/FileSaver.js/issues/471
3
+ const { saveAs } = require('file-saver');
2
4
 
3
- export const downloadFile = async (filename, text, type = 'application/json') => {
4
5
  //FIXME https://github.com/eligrey/FileSaver.js/issues/731
5
- //FIXME https://github.com/eligrey/FileSaver.js/issues/471
6
- saver.saveAs(new Blob([text], { type }), filename);
6
+ return saveAs(file, file.name);
7
+ };
8
+
9
+ export const createFile = async (text: any, filename = 'file.json', type = 'application/json'): Promise<File> => {
10
+ return new File([new Blob([text], { type })], filename);
7
11
  };
8
12
 
9
13
  export const openFile = (): Promise<string> =>
package/src/core/ls.ts CHANGED
@@ -1,11 +1,15 @@
1
- export function getStorage(pref: string) {
1
+ export function getStorage(pref: string): {
2
+ read: (key: string) => null | any;
3
+ write: (key: string, value: any) => void;
4
+ remove: (key: string) => void;
5
+ } {
2
6
  const prefix = (key) => `${pref}-${key}`;
3
7
 
4
8
  const ls = (typeof window !== 'undefined' ? localStorage : null) as Storage;
5
9
 
6
- const read = (key: string) => JSON.parse(ls?.getItem(prefix(key)) || 'null');
7
- const write = (key: string, value: any) => ls?.setItem(prefix(key), JSON.stringify(value));
8
- const remove = (key: string) => ls?.removeItem(prefix(key));
10
+ const read = (key: string): any => JSON.parse(ls?.getItem(prefix(key)) || 'null');
11
+ const write = (key: string, value: any): void => ls?.setItem(prefix(key), JSON.stringify(value));
12
+ const remove = (key: string): void => ls?.removeItem(prefix(key));
9
13
 
10
14
  return { read, write, remove };
11
15
  }
@@ -1,6 +1,13 @@
1
1
  import { bold, magenta, cyan, yellow, red, green } from 'colors/safe';
2
2
 
3
- export const colored = {
3
+ export const colored: {
4
+ important: typeof bold;
5
+ subject: typeof magenta;
6
+ arg: typeof cyan;
7
+ sup: typeof yellow;
8
+ err: typeof red;
9
+ ok: typeof green;
10
+ } = {
4
11
  important: bold,
5
12
  subject: magenta,
6
13
  arg: cyan,
@@ -11,7 +18,14 @@ export const colored = {
11
18
 
12
19
  const noColor = (str) => str;
13
20
 
14
- export const uncolored = {
21
+ export const uncolored: {
22
+ important: (str: any) => any;
23
+ subject: (str: any) => any;
24
+ arg: (str: any) => any;
25
+ sup: (str: any) => any;
26
+ err: (str: any) => any;
27
+ ok: (str: any) => any;
28
+ } = {
15
29
  important: noColor,
16
30
  subject: noColor,
17
31
  arg: noColor,
@@ -20,10 +34,44 @@ export const uncolored = {
20
34
  ok: noColor,
21
35
  };
22
36
 
23
- export function createMeasurer({ colors = true, prepend = 'LOG', padding = 10 }) {
37
+ export function createMeasurer({
38
+ colors = true,
39
+ prepend = 'LOG',
40
+ padding = 10,
41
+ }: {
42
+ colors?: boolean;
43
+ prepend?: string;
44
+ padding?: number;
45
+ }): {
46
+ measure: (
47
+ what: string,
48
+ step: string,
49
+ supplemental?: string,
50
+ ...args: any[]
51
+ ) => {
52
+ done: (result?: string, ...args2: any[]) => void;
53
+ fail: (result?: string, ...args2: any[]) => void;
54
+ log: (...args2: any[]) => void;
55
+ };
56
+ important: (str: any) => any;
57
+ subject: (str: any) => any;
58
+ arg: (str: any) => any;
59
+ sup: (str: any) => any;
60
+ ok: (str: any) => any;
61
+ err: (str: any) => any;
62
+ } {
24
63
  const { important, subject, arg, sup, ok, err } = colors ? colored : uncolored;
25
64
 
26
- function measure(what: string, step: string, supplemental: string = '', ...args) {
65
+ function measure(
66
+ what: string,
67
+ step: string,
68
+ supplemental: string = '',
69
+ ...args: any[]
70
+ ): {
71
+ done: (result?: string, ...args2: any[]) => void;
72
+ fail: (result?: string, ...args2: any[]) => void;
73
+ log: (...args2: any[]) => void;
74
+ } {
27
75
  const time = performance.now();
28
76
 
29
77
  const prefix = [
@@ -34,7 +82,7 @@ export function createMeasurer({ colors = true, prepend = 'LOG', padding = 10 })
34
82
  ...args,
35
83
  ];
36
84
 
37
- const done = (result: string = ok('DONE'), ...args2) => {
85
+ const done = (result: string = ok('DONE'), ...args2: any[]): void => {
38
86
  console.log(
39
87
  ...[
40
88
  ...prefix,
@@ -48,9 +96,9 @@ export function createMeasurer({ colors = true, prepend = 'LOG', padding = 10 })
48
96
  console.groupEnd();
49
97
  };
50
98
 
51
- const fail = (result: string = err('FAIL'), ...args2) => done(result, ...args2);
99
+ const fail = (result: string = err('FAIL'), ...args2: any[]): void => done(result, ...args2);
52
100
 
53
- const log = (...args2) => {
101
+ const log = (...args2: any[]): void => {
54
102
  console.log(...prefix, ...args2);
55
103
  };
56
104