@uxf/core 10.0.0-beta.9 → 10.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.
package/README.md CHANGED
@@ -378,6 +378,36 @@ import { trimTrailingZeros } from "@uxf/core/utils/trimTrailingZeros";
378
378
  const example = trimTrailingZeros("120,450") /* returns "120,45" */
379
379
  ```
380
380
 
381
+ ```tsx
382
+ import { filterNullish } from "@uxf/core/utils/filter-nullish";
383
+
384
+ filterNullish([0, "text", null, undefined, [], {}]) /* returns [0, "text", [], {}] */
385
+ ```
386
+
387
+ ```tsx
388
+ import { isNil } from "@uxf/core/utils/is-nil";
389
+
390
+ isNil(null) /* returns true */
391
+ isNil(undefined) /* returns true */
392
+ isNil(true) /* returns false */
393
+ isNil(1) /* returns false */
394
+ isNil(0) /* returns false */
395
+ isNil([]) /* returns false */
396
+ isNil("string") /* returns false */
397
+ ```
398
+
399
+ ```tsx
400
+ import { isNotNil } from "@uxf/core/utils/is-not-nil";
401
+
402
+ isNotNil(null) /* returns false */
403
+ isNotNil(undefined) /* returns false */
404
+ isNotNil(true) /* returns true */
405
+ isNotNil(1) /* returns true */
406
+ isNotNil(0) /* returns true */
407
+ isNotNil([]) /* returns true */
408
+ isNotNil("string") /* returns true */
409
+ ```
410
+
381
411
  ## Validators
382
412
  ```tsx
383
413
  import { Validator } from "@uxf/core";
@@ -0,0 +1,7 @@
1
+ import React, { ReactNode } from "react";
2
+ interface HideProps {
3
+ when: boolean;
4
+ children?: ReactNode;
5
+ }
6
+ export declare function Hide(props: HideProps): React.JSX.Element | null;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Hide = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ function Hide(props) {
9
+ if (props.when) {
10
+ return null;
11
+ }
12
+ return react_1.default.createElement(react_1.default.Fragment, null, props.children);
13
+ }
14
+ exports.Hide = Hide;
@@ -0,0 +1,7 @@
1
+ import React, { ReactNode } from "react";
2
+ interface ShowProps {
3
+ when: boolean;
4
+ children?: ReactNode;
5
+ }
6
+ export declare function Show(props: ShowProps): React.JSX.Element | null;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Show = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ function Show(props) {
9
+ if (!props.when) {
10
+ return null;
11
+ }
12
+ return react_1.default.createElement(react_1.default.Fragment, null, props.children);
13
+ }
14
+ exports.Show = Show;
@@ -1,5 +1,5 @@
1
- import { BodyScrollOptions } from "body-scroll-lock";
2
1
  import { RefObject } from "react";
2
+ import { BodyScrollOptions } from "../utils/bodyScrollLock";
3
3
  export interface UseBodyScrollLockOptions extends BodyScrollOptions {
4
4
  clearAllOnClose?: boolean;
5
5
  }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBodyScrollLock = void 0;
4
- const body_scroll_lock_1 = require("body-scroll-lock");
5
4
  const react_1 = require("react");
5
+ const bodyScrollLock_1 = require("../utils/bodyScrollLock");
6
6
  function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, clearAllOnClose, reserveScrollBarGap } = {}) {
7
7
  (0, react_1.useEffect)(() => {
8
8
  const node = containerRef.current;
9
9
  if (isOpen && node) {
10
- (0, body_scroll_lock_1.disableBodyScroll)(node, {
10
+ (0, bodyScrollLock_1.disableBodyScroll)(node, {
11
11
  allowTouchMove: allowTouchMove ||
12
12
  ((element) => {
13
13
  var _a;
@@ -24,10 +24,10 @@ function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, clearAllOnClo
24
24
  }
25
25
  return () => {
26
26
  if (node) {
27
- (0, body_scroll_lock_1.enableBodyScroll)(node);
27
+ (0, bodyScrollLock_1.enableBodyScroll)(node);
28
28
  }
29
29
  if (clearAllOnClose) {
30
- (0, body_scroll_lock_1.clearAllBodyScrollLocks)();
30
+ (0, bodyScrollLock_1.clearAllBodyScrollLocks)();
31
31
  }
32
32
  };
33
33
  }, [allowTouchMove, clearAllOnClose, containerRef, isOpen, reserveScrollBarGap]);
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./Validators/Validator";
2
1
  export * from "./Validators/FormValidator";
2
+ export * from "./Validators/Validator";
package/index.js CHANGED
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // TODO @vejvis - remove me
18
- __exportStar(require("./Validators/Validator"), exports);
19
18
  __exportStar(require("./Validators/FormValidator"), exports);
19
+ __exportStar(require("./Validators/Validator"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "10.0.0-beta.9",
3
+ "version": "10.0.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -17,25 +17,17 @@
17
17
  },
18
18
  "scripts": {
19
19
  "build": "tsc -P tsconfig.json",
20
- "jest": "jest",
21
- "test": "npm run jest",
22
20
  "typecheck": "tsc --noEmit --skipLibCheck"
23
21
  },
24
22
  "bugs": {
25
23
  "url": "https://gitlab.com/uxf-npm/core/issues"
26
24
  },
27
- "devDependencies": {
28
- "@types/body-scroll-lock": "^3.1.0",
29
- "@types/jest": "^27.4.0",
30
- "@types/react": "^18.2.6",
31
- "body-scroll-lock": "^4.0.0-beta.0",
32
- "jest": "^27.4.5",
33
- "react": "^18.2.0",
34
- "ts-jest": "^27.1.2"
35
- },
36
25
  "peerDependencies": {
37
- "body-scroll-lock": "^4.0.0-beta.0",
38
- "react": "^17.0.0 || ^18.0.0"
26
+ "react": ">=18.2.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "18.2.27",
30
+ "react": "18.2.0"
39
31
  },
40
32
  "gitHead": "a2dee6aa67621f6eda17e63e88d0edf14f88455a"
41
33
  }
@@ -0,0 +1 @@
1
+ export type Nullish = null | undefined;
package/types/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface BodyScrollOptions {
2
+ reserveScrollBarGap?: boolean;
3
+ allowTouchMove?: (el: any) => boolean;
4
+ }
5
+ export declare const disableBodyScroll: (targetElement: any, options?: BodyScrollOptions) => void;
6
+ export declare const clearAllBodyScrollLocks: () => void;
7
+ export declare const enableBodyScroll: (targetElement: any) => void;
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ // Forked from "body-scroll-lock" https://github.com/willmcpo/body-scroll-lock
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.enableBodyScroll = exports.clearAllBodyScrollLocks = exports.disableBodyScroll = void 0;
5
+ function noop() {
6
+ return void null;
7
+ }
8
+ // Older browsers don't support event options, feature detect it.
9
+ let hasPassiveEvents = false;
10
+ if (typeof window !== "undefined") {
11
+ const passiveTestOptions = {
12
+ get passive() {
13
+ hasPassiveEvents = true;
14
+ return undefined;
15
+ },
16
+ };
17
+ window.addEventListener("testPassive", noop, passiveTestOptions);
18
+ window.removeEventListener("testPassive", noop);
19
+ }
20
+ const isIosDevice = typeof window !== "undefined" &&
21
+ typeof window.navigator !== "undefined" &&
22
+ typeof window.navigator.platform !== "undefined" &&
23
+ (/iP(ad|hone|od)/.test(window.navigator.platform) ||
24
+ (window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1));
25
+ let locks = [];
26
+ let documentListenerAdded = false;
27
+ let initialClientY = -1;
28
+ let previousBodyOverflowSetting;
29
+ let previousBodyPosition;
30
+ let previousBodyPaddingRight;
31
+ // returns true if `el` should be allowed to receive touchmove events.
32
+ const allowTouchMove = (el) => locks.some((lock) => !!(lock.options.allowTouchMove && lock.options.allowTouchMove(el)));
33
+ const preventDefault = (rawEvent) => {
34
+ const e = typeof rawEvent !== "undefined" ? rawEvent : window.event;
35
+ // For the case whereby consumers adds a touchmove event listener to document.
36
+ // Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })
37
+ // in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then
38
+ // the touchmove event on document will break.
39
+ if ((e === null || e === void 0 ? void 0 : e.target) && allowTouchMove(e.target)) {
40
+ return true;
41
+ }
42
+ // Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
43
+ if ((e === null || e === void 0 ? void 0 : e.touches.length) > 1) {
44
+ return true;
45
+ }
46
+ if (e === null || e === void 0 ? void 0 : e.preventDefault) {
47
+ e.preventDefault();
48
+ }
49
+ return false;
50
+ };
51
+ const setOverflowHidden = (options) => {
52
+ // If previousBodyPaddingRight is already set, don't set it again.
53
+ if (previousBodyPaddingRight === undefined) {
54
+ const reserveScrollBarGap = !!options && options.reserveScrollBarGap === true;
55
+ const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
56
+ if (reserveScrollBarGap && scrollBarGap > 0) {
57
+ const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"), 10);
58
+ previousBodyPaddingRight = document.body.style.paddingRight;
59
+ document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`;
60
+ }
61
+ }
62
+ // If previousBodyOverflowSetting is already set, don't set it again.
63
+ if (previousBodyOverflowSetting === undefined) {
64
+ previousBodyOverflowSetting = document.body.style.overflow;
65
+ document.body.style.overflow = "hidden";
66
+ }
67
+ };
68
+ const restoreOverflowSetting = () => {
69
+ if (previousBodyPaddingRight !== undefined) {
70
+ document.body.style.paddingRight = previousBodyPaddingRight;
71
+ // Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it
72
+ // can be set again.
73
+ previousBodyPaddingRight = undefined;
74
+ }
75
+ if (previousBodyOverflowSetting !== undefined) {
76
+ document.body.style.overflow = previousBodyOverflowSetting;
77
+ // Restore previousBodyOverflowSetting to undefined
78
+ // so setOverflowHidden knows it can be set again.
79
+ previousBodyOverflowSetting = undefined;
80
+ }
81
+ };
82
+ const setPositionFixed = () => window.requestAnimationFrame(() => {
83
+ // If previousBodyPosition is already set, don't set it again.
84
+ if (previousBodyPosition === undefined) {
85
+ previousBodyPosition = {
86
+ position: document.body.style.position,
87
+ top: document.body.style.top,
88
+ left: document.body.style.left,
89
+ };
90
+ // Update the dom inside an animation frame
91
+ const { scrollY, scrollX, innerHeight } = window;
92
+ document.body.style.position = "fixed";
93
+ document.body.style.top = `${-scrollY}px`;
94
+ document.body.style.left = `${-scrollX}px`;
95
+ setTimeout(() => window.requestAnimationFrame(() => {
96
+ // Attempt to check if the bottom bar appeared due to the position change
97
+ const bottomBarHeight = innerHeight - window.innerHeight;
98
+ if (bottomBarHeight && scrollY >= innerHeight) {
99
+ // Move the content further up so that the bottom bar doesn't hide it
100
+ document.body.style.top = `${-(scrollY + bottomBarHeight)}px`;
101
+ }
102
+ }), 300);
103
+ }
104
+ });
105
+ const restorePositionSetting = () => {
106
+ if (previousBodyPosition !== undefined) {
107
+ // Convert the position from "px" to Int
108
+ const y = -parseInt(document.body.style.top, 10);
109
+ const x = -parseInt(document.body.style.left, 10);
110
+ // Restore styles
111
+ document.body.style.position = previousBodyPosition.position;
112
+ document.body.style.top = previousBodyPosition.top;
113
+ document.body.style.left = previousBodyPosition.left;
114
+ // Restore scroll
115
+ window.scrollTo(x, y);
116
+ previousBodyPosition = undefined;
117
+ }
118
+ };
119
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
120
+ const isTargetElementTotallyScrolled = (targetElement) => targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false;
121
+ const handleScroll = (event, targetElement) => {
122
+ const clientY = event.targetTouches[0].clientY - initialClientY;
123
+ if (event.target && allowTouchMove(event.target)) {
124
+ return false;
125
+ }
126
+ if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {
127
+ // element is at the top of its scroll.
128
+ return preventDefault(event);
129
+ }
130
+ if (isTargetElementTotallyScrolled(targetElement) && clientY < 0) {
131
+ // element is at the bottom of its scroll.
132
+ return preventDefault(event);
133
+ }
134
+ event.stopPropagation();
135
+ return true;
136
+ };
137
+ const disableBodyScroll = (targetElement, options) => {
138
+ // targetElement must be provided
139
+ if (!targetElement) {
140
+ // eslint-disable-next-line no-console
141
+ console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.");
142
+ return;
143
+ }
144
+ // disableBodyScroll must not have been called on this targetElement before
145
+ if (locks.some((lock) => lock.targetElement === targetElement)) {
146
+ return;
147
+ }
148
+ const lock = {
149
+ targetElement,
150
+ options: options || {},
151
+ };
152
+ locks = [...locks, lock];
153
+ if (isIosDevice) {
154
+ setPositionFixed();
155
+ }
156
+ else {
157
+ setOverflowHidden(options);
158
+ }
159
+ if (isIosDevice) {
160
+ targetElement.ontouchstart = (event) => {
161
+ if (event.targetTouches.length === 1) {
162
+ // detect single touch.
163
+ initialClientY = event.targetTouches[0].clientY;
164
+ }
165
+ };
166
+ targetElement.ontouchmove = (event) => {
167
+ if (event.targetTouches.length === 1) {
168
+ // detect single touch.
169
+ handleScroll(event, targetElement);
170
+ }
171
+ };
172
+ if (!documentListenerAdded) {
173
+ document.addEventListener("touchmove", preventDefault, hasPassiveEvents ? { passive: false } : undefined);
174
+ documentListenerAdded = true;
175
+ }
176
+ }
177
+ };
178
+ exports.disableBodyScroll = disableBodyScroll;
179
+ const clearAllBodyScrollLocks = () => {
180
+ if (isIosDevice) {
181
+ // Clear all locks ontouchstart/ontouchmove handlers, and the references.
182
+ locks.forEach((lock) => {
183
+ lock.targetElement.ontouchstart = null;
184
+ lock.targetElement.ontouchmove = null;
185
+ });
186
+ if (documentListenerAdded) {
187
+ document.removeEventListener("touchmove", preventDefault);
188
+ documentListenerAdded = false;
189
+ }
190
+ // Reset initial clientY.
191
+ initialClientY = -1;
192
+ }
193
+ if (isIosDevice) {
194
+ restorePositionSetting();
195
+ }
196
+ else {
197
+ restoreOverflowSetting();
198
+ }
199
+ locks = [];
200
+ };
201
+ exports.clearAllBodyScrollLocks = clearAllBodyScrollLocks;
202
+ const enableBodyScroll = (targetElement) => {
203
+ if (!targetElement) {
204
+ // eslint-disable-next-line no-console
205
+ console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.");
206
+ return;
207
+ }
208
+ locks = locks.filter((lock) => lock.targetElement !== targetElement);
209
+ if (isIosDevice) {
210
+ targetElement.ontouchstart = null;
211
+ targetElement.ontouchmove = null;
212
+ if (documentListenerAdded && locks.length === 0) {
213
+ document.removeEventListener("touchmove", preventDefault);
214
+ documentListenerAdded = false;
215
+ }
216
+ }
217
+ if (isIosDevice) {
218
+ restorePositionSetting();
219
+ }
220
+ else {
221
+ restoreOverflowSetting();
222
+ }
223
+ };
224
+ exports.enableBodyScroll = enableBodyScroll;
@@ -1,21 +1,9 @@
1
- export declare function buildArray<T>(): {
2
- add: (data: T) => {
3
- add: any;
4
- when: (condition: boolean, data: T) => {
5
- add: any;
6
- when: any;
7
- get: () => T[];
8
- };
9
- get: () => T[];
10
- };
11
- when: (condition: boolean, data: T) => {
12
- add: (data: T) => {
13
- add: any;
14
- when: any;
15
- get: () => T[];
16
- };
17
- when: any;
18
- get: () => T[];
19
- };
20
- get: () => T[];
21
- };
1
+ type Element<T> = T;
2
+ type WhenFn<T> = (when: boolean, element: Element<T>) => ProxiedArray<T>;
3
+ type AddFn<T> = (element: Element<T>) => ProxiedArray<T>;
4
+ type ProxiedArray<T> = {
5
+ when: WhenFn<T>;
6
+ add: AddFn<T>;
7
+ } & T[];
8
+ export declare function buildArray<T = unknown>(initial?: T[]): ProxiedArray<T>;
9
+ export {};
@@ -1,28 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildArray = void 0;
4
- function get(array) {
5
- return () => {
6
- return array;
7
- };
8
- }
9
- function add(array) {
10
- return (data) => {
11
- array.push(data);
12
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
13
- return { add: add(array), when: when(array), get: get(array) };
14
- };
15
- }
16
- function when(array) {
17
- return (condition, data) => {
18
- if (condition) {
19
- array.push(data);
20
- }
21
- return { add: add(array), when: when(array), get: get(array) };
22
- };
23
- }
24
- function buildArray() {
25
- const array = [];
26
- return { add: add(array), when: when(array), get: get(array) };
4
+ function buildArray(initial) {
5
+ const initialArray = (initial ? [...initial] : []);
6
+ const proxiedArray = new Proxy(initialArray, {
7
+ get: (target, prop, receiver) => {
8
+ if ("add" === prop) {
9
+ return (element) => {
10
+ target.push(element);
11
+ return proxiedArray;
12
+ };
13
+ }
14
+ if ("when" === prop) {
15
+ return (when, element) => {
16
+ if (when) {
17
+ target.push(element);
18
+ }
19
+ return proxiedArray;
20
+ };
21
+ }
22
+ return Reflect.get(target, prop, receiver);
23
+ },
24
+ });
25
+ return proxiedArray;
27
26
  }
28
27
  exports.buildArray = buildArray;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const buildArray_1 = require("./buildArray");
4
4
  test("buildArray", () => {
5
- expect((0, buildArray_1.buildArray)().get()).toStrictEqual([]);
6
- expect((0, buildArray_1.buildArray)().add("uxf").get()).toStrictEqual(["uxf"]);
7
- expect((0, buildArray_1.buildArray)().add("ux").add("fans").get()).toStrictEqual(["ux", "fans"]);
8
- expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans").get()).toStrictEqual(["ux", "fans"]);
9
- expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans").get()).toStrictEqual(["ux"]);
5
+ expect((0, buildArray_1.buildArray)()).toStrictEqual([]);
6
+ expect((0, buildArray_1.buildArray)().add("uxf")).toStrictEqual(["uxf"]);
7
+ expect((0, buildArray_1.buildArray)().add("ux").add("fans")).toStrictEqual(["ux", "fans"]);
8
+ expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans")).toStrictEqual(["ux", "fans"]);
9
+ expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans")).toStrictEqual(["ux"]);
10
10
  });
@@ -9,7 +9,7 @@ function copyToClipboardFallback(text) {
9
9
  textArea.style.left = "0";
10
10
  textArea.style.position = "fixed";
11
11
  document.body.appendChild(textArea);
12
- textArea.focus();
12
+ textArea.focus({ preventScroll: true });
13
13
  textArea.select();
14
14
  document.execCommand("copy");
15
15
  document.body.removeChild(textArea);
@@ -0,0 +1 @@
1
+ export declare function filterNullish<T>(val: Array<T | null | undefined>): T[];
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterNullish = void 0;
4
+ const is_not_nil_1 = require("./is-not-nil");
5
+ function filterNullish(val) {
6
+ return val.filter(is_not_nil_1.isNotNil);
7
+ }
8
+ exports.filterNullish = filterNullish;
package/utils/image.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { ImageSource, ResizerImageProps } from "./resizer";
2
1
  import { FC } from "react";
2
+ import { ImageSource, ResizerImageProps } from "./resizer";
3
3
  export type Dimension = number | "auto";
4
4
  export type Format = "avif" | "webp" | "original";
5
5
  export type Quality = number | Record<Format, number>;
6
6
  export declare function getSvgImgUrl(src: ImageSource): string | undefined;
7
7
  export declare function getImgQuality(quality: Quality | undefined, format: Format): number | undefined;
8
8
  export declare function getImgUniqueIdentifier(src: ImageSource): string | undefined;
9
+ export declare function getImgElementHeight(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
10
+ export declare function getImgElementWidth(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
9
11
  export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: ResizerImageProps): string | undefined;
10
12
  interface ImageSourcesProps {
11
13
  breakpointIndex?: number;
package/utils/image.js CHANGED
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ImgSources = exports.getImgSrcSet = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
6
+ exports.ImgSources = exports.getImgSrcSet = exports.getImgElementWidth = exports.getImgElementHeight = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
7
+ const react_1 = __importDefault(require("react"));
7
8
  const file_1 = require("./file");
8
9
  const resizer_1 = require("./resizer");
9
- const react_1 = __importDefault(require("react"));
10
10
  function toImageResponse(src) {
11
11
  return typeof src !== "string" && "uuid" in src ? src : undefined;
12
12
  }
@@ -41,6 +41,20 @@ function getImgUniqueIdentifier(src) {
41
41
  return typeof src === "string" ? src : (_b = (_a = toImageResponse(src)) === null || _a === void 0 ? void 0 : _a.uuid) !== null && _b !== void 0 ? _b : (_c = toStaticImageData(src)) === null || _c === void 0 ? void 0 : _c.src;
42
42
  }
43
43
  exports.getImgUniqueIdentifier = getImgUniqueIdentifier;
44
+ function getImgElementHeight(src, width, height) {
45
+ var _a, _b;
46
+ return typeof src === "string"
47
+ ? height
48
+ : height !== null && height !== void 0 ? height : (Math.floor((((_a = src.height) !== null && _a !== void 0 ? _a : 0) / ((_b = src.width) !== null && _b !== void 0 ? _b : 0)) * (width || 0)) || undefined);
49
+ }
50
+ exports.getImgElementHeight = getImgElementHeight;
51
+ function getImgElementWidth(src, width, height) {
52
+ var _a, _b;
53
+ return typeof src === "string"
54
+ ? width
55
+ : width !== null && width !== void 0 ? width : (Math.floor(((_a = src.width) !== null && _a !== void 0 ? _a : 0) / ((_b = src.height) !== null && _b !== void 0 ? _b : 0)) * (height || 0) || undefined);
56
+ }
57
+ exports.getImgElementWidth = getImgElementWidth;
44
58
  const HIDPI_SIZES = [3, 2, 1];
45
59
  function getImgSrcSet(src, width, height, options = {}) {
46
60
  var _a, _b;
@@ -72,7 +86,7 @@ function getImgSrcSet(src, width, height, options = {}) {
72
86
  w = w || staticImageData.width;
73
87
  }
74
88
  if (typeof h === "number" || typeof w === "number") {
75
- return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, w * size, h * size, {
89
+ return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, typeof w === "number" ? w * size : "auto", typeof h === "number" ? h * size : "auto", {
76
90
  toFormat,
77
91
  ...options,
78
92
  }) + (size > 1 ? ` ${size}x` : "")).join(", ");
@@ -0,0 +1 @@
1
+ export declare function isNil(value: any): value is null | undefined;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNil = void 0;
4
+ function isNil(value) {
5
+ return value === null || value === undefined;
6
+ }
7
+ exports.isNil = isNil;
@@ -0,0 +1 @@
1
+ export declare function isNotNil<T>(val: T | null | undefined): val is T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotNil = void 0;
4
+ function isNotNil(val) {
5
+ return val !== null && val !== undefined;
6
+ }
7
+ exports.isNotNil = isNotNil;
package/utils/resizer.js CHANGED
@@ -48,7 +48,7 @@ const resizerStaticImageUrl = (src, width = "auto", height = "auto", props = {},
48
48
  };
49
49
  const resizerImageUrl = (source, width = "auto", height = "auto", props = {}, version = 1) => {
50
50
  var _a, _b;
51
- if (source === null || source === undefined) {
51
+ if (source === null || source === undefined || source === "") {
52
52
  return undefined;
53
53
  }
54
54
  if (typeof source === "string" || "src" in source) {
@@ -0,0 +1 @@
1
+ export declare function sortObjectKeys<T extends Record<string, any>>(object: T): T;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortObjectKeys = void 0;
4
+ function sortObjectKeys(object) {
5
+ const sortedObject = {};
6
+ const keys = Object.keys(object);
7
+ keys.sort();
8
+ keys.forEach((key) => {
9
+ if (typeof object[key] === "string") {
10
+ sortedObject[key] = object[key];
11
+ }
12
+ else {
13
+ sortedObject[key] = sortObjectKeys(object[key]);
14
+ }
15
+ });
16
+ return sortedObject;
17
+ }
18
+ exports.sortObjectKeys = sortObjectKeys;
@@ -1,10 +0,0 @@
1
- import { ForwardedRef, ForwardRefExoticComponent, PropsWithoutRef, ReactElement, RefAttributes } from "react";
2
- export type ForwardRefRenderFunction<T, P> = {
3
- (props: P, ref: ForwardedRef<T>): ReactElement | null;
4
- displayName?: string;
5
- /** defaultProps are not supported on render functions */
6
- defaultProps?: never;
7
- /** propTypes are not supported on render functions */
8
- propTypes?: never;
9
- };
10
- export declare const forwardRef: <T, P>(name: string, render: ForwardRefRenderFunction<T, P>) => ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.forwardRef = void 0;
4
- const react_1 = require("react");
5
- const forwardRef = (name, render) => {
6
- const Component = (0, react_1.forwardRef)(render);
7
- Component.displayName = name;
8
- return Component;
9
- };
10
- exports.forwardRef = forwardRef;