@uxf/core-react 11.88.0 → 11.90.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.
@@ -1,6 +1,6 @@
1
1
  import { BodyScrollOptions } from "@uxf/core/utils/body-scroll-lock";
2
2
  import { RefObject } from "react";
3
- export interface UseBodyScrollLockOptions extends BodyScrollOptions {
4
- clearAllOnClose?: boolean;
3
+ export interface UseBodyScrollLockOptions<E extends HTMLElement> extends BodyScrollOptions<E> {
4
+ willClearAllOnClose?: boolean;
5
5
  }
6
- export declare function useBodyScrollLock<T extends HTMLElement>(containerRef: RefObject<T | null>, isOpen: boolean, { allowTouchMove, clearAllOnClose, reserveScrollBarGap }?: Partial<UseBodyScrollLockOptions>): void;
6
+ export declare function useBodyScrollLock<E extends HTMLElement = HTMLElement>(containerRef: RefObject<E | null>, isOpen: boolean, { allowTouchMove, willClearAllOnClose, willReserveScrollBarGap }?: Partial<UseBodyScrollLockOptions<E>>): void;
@@ -2,33 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBodyScrollLock = useBodyScrollLock;
4
4
  const body_scroll_lock_1 = require("@uxf/core/utils/body-scroll-lock");
5
+ const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
5
6
  const react_1 = require("react");
6
- function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, clearAllOnClose, reserveScrollBarGap } = {}) {
7
+ function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, willClearAllOnClose, willReserveScrollBarGap } = {}) {
7
8
  (0, react_1.useEffect)(() => {
8
9
  const node = containerRef.current;
9
10
  if (isOpen && node) {
10
11
  (0, body_scroll_lock_1.disableBodyScroll)(node, {
11
12
  allowTouchMove: allowTouchMove ||
12
13
  ((element) => {
13
- var _a;
14
14
  while (element !== document.body) {
15
15
  if (element.getAttribute("data-body-scroll-lock-ignore") !== null) {
16
16
  return true;
17
17
  }
18
- element = (_a = element.parentElement) !== null && _a !== void 0 ? _a : element;
18
+ if ((0, is_not_nil_1.isNotNil)(element.parentElement)) {
19
+ element = element.parentElement;
20
+ }
19
21
  }
20
22
  return false;
21
23
  }),
22
- reserveScrollBarGap,
24
+ willReserveScrollBarGap,
23
25
  });
24
26
  }
25
27
  return () => {
26
28
  if (node) {
27
29
  (0, body_scroll_lock_1.enableBodyScroll)(node);
28
30
  }
29
- if (clearAllOnClose) {
31
+ if (willClearAllOnClose) {
30
32
  (0, body_scroll_lock_1.clearAllBodyScrollLocks)();
31
33
  }
32
34
  };
33
- }, [allowTouchMove, clearAllOnClose, containerRef, isOpen, reserveScrollBarGap]);
35
+ }, [allowTouchMove, willClearAllOnClose, containerRef, isOpen, willReserveScrollBarGap]);
34
36
  }
@@ -16,19 +16,19 @@ describe("usePagination Hook", () => {
16
16
  };
17
17
  const { result } = (0, react_1.renderHook)(() => (0, use_pagination_1.usePagination)(mockConfig));
18
18
  const paginationItems = result.current;
19
- expect(paginationItems[0]).toBe("first");
20
- expect(paginationItems[1]).toBe("previous");
21
- expect(paginationItems[2]).toBe(1);
22
- expect(paginationItems[3]).toBe(2);
23
- expect(paginationItems[4]).toBe("start-ellipsis");
24
- expect(paginationItems[5]).toBe(10);
25
- expect(paginationItems[6]).toBe(11);
26
- expect(paginationItems[7]).toBe(12);
27
- expect(paginationItems[8]).toBe("end-ellipsis");
28
- expect(paginationItems[9]).toBe(99);
29
- expect(paginationItems[10]).toBe(100);
30
- expect(paginationItems[11]).toBe("next");
31
- expect(paginationItems[12]).toBe("last");
19
+ expect(paginationItems.at(0)).toBe("first");
20
+ expect(paginationItems.at(1)).toBe("previous");
21
+ expect(paginationItems.at(2)).toBe(1);
22
+ expect(paginationItems.at(3)).toBe(2);
23
+ expect(paginationItems.at(4)).toBe("start-ellipsis");
24
+ expect(paginationItems.at(5)).toBe(10);
25
+ expect(paginationItems.at(6)).toBe(11);
26
+ expect(paginationItems.at(7)).toBe(12);
27
+ expect(paginationItems.at(8)).toBe("end-ellipsis");
28
+ expect(paginationItems.at(9)).toBe(99);
29
+ expect(paginationItems.at(10)).toBe(100);
30
+ expect(paginationItems.at(11)).toBe("next");
31
+ expect(paginationItems.at(12)).toBe("last");
32
32
  });
33
33
  it("should return correct pagination items with hidden 'Previous' and 'Next' buttons", () => {
34
34
  const mockConfigHidePrevNext = {
@@ -43,16 +43,16 @@ describe("usePagination Hook", () => {
43
43
  };
44
44
  const { result } = (0, react_1.renderHook)(() => (0, use_pagination_1.usePagination)(mockConfigHidePrevNext));
45
45
  const paginationItems = result.current;
46
- expect(paginationItems[0]).toBe("first");
47
- expect(paginationItems[1]).toBe(1);
48
- expect(paginationItems[2]).toBe(2);
49
- expect(paginationItems[3]).toBe(3);
50
- expect(paginationItems[4]).toBe(4);
51
- expect(paginationItems[5]).toBe(5);
52
- expect(paginationItems[6]).toBe(6);
53
- expect(paginationItems[7]).toBe(7);
54
- expect(paginationItems[8]).toBe("end-ellipsis");
55
- expect(paginationItems[9]).toBe(20);
56
- expect(paginationItems[10]).toBe("last");
46
+ expect(paginationItems.at(0)).toBe("first");
47
+ expect(paginationItems.at(1)).toBe(1);
48
+ expect(paginationItems.at(2)).toBe(2);
49
+ expect(paginationItems.at(3)).toBe(3);
50
+ expect(paginationItems.at(4)).toBe(4);
51
+ expect(paginationItems.at(5)).toBe(5);
52
+ expect(paginationItems.at(6)).toBe(6);
53
+ expect(paginationItems.at(7)).toBe(7);
54
+ expect(paginationItems.at(8)).toBe("end-ellipsis");
55
+ expect(paginationItems.at(9)).toBe(20);
56
+ expect(paginationItems.at(10)).toBe("last");
57
57
  });
58
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core-react",
3
- "version": "11.88.0",
3
+ "version": "11.90.0",
4
4
  "description": "UXF Core",
5
5
  "author": "UX Fans s.r.o",
6
6
  "license": "MIT",
@@ -12,13 +12,13 @@
12
12
  "typecheck": "tsc --noEmit --skipLibCheck"
13
13
  },
14
14
  "dependencies": {
15
- "@uxf/core": "11.88.0"
15
+ "@uxf/core": "11.90.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">=18.2.0"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/react": "18.3.26",
21
+ "@types/react": "18.3.27",
22
22
  "react": "18.3.1"
23
23
  }
24
24
  }
@@ -46,9 +46,10 @@ function rotateXYByAngle(pos, angle) {
46
46
  if (angle === 0) {
47
47
  return pos;
48
48
  }
49
+ const [posX, posY] = pos;
49
50
  const angleInRadians = (Math.PI / 180) * angle;
50
- const x = pos[0] * Math.cos(angleInRadians) + pos[1] * Math.sin(angleInRadians);
51
- const y = pos[1] * Math.cos(angleInRadians) - pos[0] * Math.sin(angleInRadians);
51
+ const x = posX * Math.cos(angleInRadians) + posX * Math.sin(angleInRadians);
52
+ const y = posY * Math.cos(angleInRadians) - posY * Math.sin(angleInRadians);
52
53
  return [x, y];
53
54
  }
54
55
  function getHandlers(set, handlerProps) {
@@ -67,6 +68,7 @@ function getHandlers(set, handlerProps) {
67
68
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
68
69
  document.addEventListener(mouseUp, onUp);
69
70
  }
71
+ // eslint-disable-next-line no-restricted-syntax
70
72
  const { clientX, clientY } = isTouch ? event.touches[0] : event;
71
73
  const xy = rotateXYByAngle([clientX, clientY], props.rotationAngle);
72
74
  (_a = props.onTouchStartOrOnMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, { event });
@@ -93,9 +95,12 @@ function getHandlers(set, handlerProps) {
93
95
  if (event.timeStamp - state.start > props.swipeDuration) {
94
96
  return state.swiping ? { ...state, swiping: false } : state;
95
97
  }
98
+ // eslint-disable-next-line no-restricted-syntax
96
99
  const { clientX, clientY } = isTouch ? event.touches[0] : event;
97
100
  const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle);
101
+ // eslint-disable-next-line no-restricted-syntax
98
102
  const deltaX = x - state.xy[0];
103
+ // eslint-disable-next-line no-restricted-syntax
99
104
  const deltaY = y - state.xy[1];
100
105
  const absX = Math.abs(deltaX);
101
106
  const absY = Math.abs(deltaY);
@@ -132,11 +137,11 @@ function getHandlers(set, handlerProps) {
132
137
  (_b = props.onSwiping) === null || _b === void 0 ? void 0 : _b.call(props, eventData);
133
138
  // track if a swipe is cancelable (handler for swiping or swiped(dir) exists)
134
139
  // so we can call preventDefault if needed
135
- let cancelablePageSwipe = false;
140
+ let isCancelablePageSwipe = false;
136
141
  if (props.onSwiping || props.onSwiped || props[`onSwiped${dir}`]) {
137
- cancelablePageSwipe = true;
142
+ isCancelablePageSwipe = true;
138
143
  }
139
- if (cancelablePageSwipe && props.preventScrollOnSwipe && props.trackTouch && event.cancelable) {
144
+ if (isCancelablePageSwipe && props.preventScrollOnSwipe && props.trackTouch && event.cancelable) {
140
145
  event.preventDefault();
141
146
  }
142
147
  return {
@@ -285,7 +290,6 @@ function updateTransientState(state, props, previousProps, attachTouch) {
285
290
  return state;
286
291
  }
287
292
  function useSwipeable(options) {
288
- const { trackMouse } = options;
289
293
  const transientState = (0, react_1.useRef)({ ...initialState });
290
294
  const transientProps = (0, react_1.useRef)({
291
295
  ...defaultProps,
@@ -308,7 +312,7 @@ function useSwipeable(options) {
308
312
  transientProps.current[defaultKey] = defaultProps[defaultKey];
309
313
  }
310
314
  }
311
- const [handlers, attachTouch] = (0, react_1.useMemo)(() => getHandlers((stateSetter) => (transientState.current = stateSetter(transientState.current, transientProps.current)), { trackMouse }), [trackMouse]);
315
+ const [handlers, attachTouch] = (0, react_1.useMemo)(() => getHandlers((stateSetter) => (transientState.current = stateSetter(transientState.current, transientProps.current)), { trackMouse: options.trackMouse }), [options.trackMouse]);
312
316
  transientState.current = updateTransientState(transientState.current, transientProps.current, previousProps.current, attachTouch);
313
317
  return handlers;
314
318
  }
@@ -1,2 +1,3 @@
1
+ import { AnyObject } from "@uxf/core/types";
1
2
  import type { TranslationFunction } from "./types";
2
- export declare function createDefaultT(translationObject: Record<string, any>): TranslationFunction<any>;
3
+ export declare function createDefaultT<Key extends string>(translationObject: AnyObject): TranslationFunction<Key>;
@@ -1,17 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDefaultT = createDefaultT;
4
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
4
5
  const replace_variables_1 = require("./replace-variables");
5
6
  const resolve_plural_key_1 = require("./resolve-plural-key");
6
7
  function createDefaultT(translationObject) {
7
8
  return function (key, options) {
9
+ var _a;
8
10
  const pckg = key.split(":");
9
- const path = pckg[1].split(".");
11
+ const pckgName = pckg.at(0);
12
+ const path = (_a = pckg.at(1)) === null || _a === void 0 ? void 0 : _a.split(".");
10
13
  let translation = key;
11
14
  try {
12
- // eslint-disable-next-line
13
- // @ts-ignore
14
- translation = path.reduce((acc, k) => acc[k], translationObject[pckg[0]]);
15
+ if ((0, is_nil_1.isNil)(pckgName)) {
16
+ throw new Error(`Cannot parse package name for key: "${key}"`);
17
+ }
18
+ if ((0, is_nil_1.isNil)(path)) {
19
+ throw new Error(`Cannot parse package package for key: "${key}"`);
20
+ }
21
+ translation = path.reduce((acc, k) => acc[k], translationObject[pckgName]);
15
22
  if (options) {
16
23
  const pluralKey = (0, resolve_plural_key_1.resolvePluralKey)(options.count);
17
24
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -21,9 +28,9 @@ function createDefaultT(translationObject) {
21
28
  translation = (0, replace_variables_1.replaceVariables)(translation, options);
22
29
  }
23
30
  }
24
- catch {
31
+ catch (err) {
25
32
  // eslint-disable-next-line no-console
26
- console.warn(`Can't find translation for key: "${key}"`);
33
+ console.warn(typeof err === "string" ? err : `Can't find translation for key: "${key}"`);
27
34
  }
28
35
  return translation;
29
36
  };
@@ -1,2 +1,3 @@
1
+ import { AnyObject } from "@uxf/core/types";
1
2
  import type { SupportedLanguages, TranslationFunction } from "./types";
2
- export declare function createDevT(locale: SupportedLanguages, translationObject: Record<string, any>): TranslationFunction<any>;
3
+ export declare function createDevT<Key extends string>(locale: SupportedLanguages, translationObject: AnyObject): TranslationFunction<Key>;
@@ -1,15 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDevT = createDevT;
4
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
4
5
  const replace_variables_1 = require("./replace-variables");
5
6
  const resolve_plural_key_1 = require("./resolve-plural-key");
6
7
  function createDevT(locale, translationObject) {
7
8
  return function (key, options) {
9
+ var _a;
8
10
  const pckg = key.split(":");
9
- const path = pckg[1].split(".");
10
- // eslint-disable-next-line
11
- // @ts-ignore
12
- let translation = path.reduce((acc, k) => acc[k], translationObject[pckg[0]])[locale];
11
+ const pckgName = pckg.at(0);
12
+ const path = (_a = pckg.at(1)) === null || _a === void 0 ? void 0 : _a.split(".");
13
+ if ((0, is_nil_1.isNil)(pckgName)) {
14
+ throw new Error(`Cannot parse package name for key: "${key}"`);
15
+ }
16
+ if ((0, is_nil_1.isNil)(path)) {
17
+ throw new Error(`Cannot parse package package for key: "${key}"`);
18
+ }
19
+ let translation = path.reduce((acc, k) => acc[k], translationObject[pckgName])[locale];
13
20
  if (options) {
14
21
  const pluralKey = (0, resolve_plural_key_1.resolvePluralKey)(options.count);
15
22
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TranslationsProvider = void 0;
5
5
  exports.useUxfTranslation = useUxfTranslation;
6
6
  const react_1 = require("react");
7
- const translationsContext = (0, react_1.createContext)((key) => key);
7
+ /* intellisense and linting is broken with any other more specific type */
8
+ const translationsContext = (0, react_1.createContext)((key) => key); // eslint-disable-line @typescript-eslint/no-explicit-any
8
9
  exports.TranslationsProvider = translationsContext.Provider;
9
10
  function useUxfTranslation() {
10
11
  return (0, react_1.useContext)(translationsContext);
@@ -1 +1,2 @@
1
- export declare function replaceVariables(translation: string, options: Record<string, any>): string;
1
+ import { AnyObject } from "@uxf/core/types";
2
+ export declare function replaceVariables(translation: string, options: AnyObject): string;
@@ -1,6 +1,7 @@
1
+ import { AnyObject } from "@uxf/core/types";
1
2
  export type SupportedLanguages = "cs" | "sk" | "en" | "de";
2
3
  export type SupportedPluralKeywords = "0" | "zero" | "one" | "few" | "many" | "other";
3
- export type TranslationFunction<Key extends string> = (key: Key, options?: Record<string, any>) => string;
4
+ export type TranslationFunction<Key extends string> = (key: Key, options?: AnyObject) => string;
4
5
  export type TranslationsContextValue<Keys extends string> = TranslationFunction<Keys>;
5
6
  type JoinDot<S1, S2> = S1 extends string ? S2 extends string ? S2 extends SupportedPluralKeywords | SupportedLanguages ? S1 : `${S1}.${S2}` : never : never;
6
7
  type JoinNamespace<NS, S> = NS extends string ? (S extends string ? `${NS}:${S}` : never) : never;