pds-dev-kit-web-test 2.4.48 → 2.4.50

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.
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsMounted = void 0;
4
+ var react_1 = require("react");
5
+ function useIsMounted() {
6
+ var isMounted = (0, react_1.useRef)(false);
7
+ (0, react_1.useEffect)(function () {
8
+ isMounted.current = true;
9
+ return function () {
10
+ isMounted.current = false;
11
+ };
12
+ }, []);
13
+ return (0, react_1.useCallback)(function () { return isMounted.current; }, []);
14
+ }
15
+ exports.useIsMounted = useIsMounted;
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from 'react';
2
+ type Size = {
3
+ width: number | undefined;
4
+ height: number | undefined;
5
+ };
6
+ type UseResizeObserverOptions<T extends HTMLElement = HTMLElement> = {
7
+ ref: RefObject<T>;
8
+ onResize?: (size: Size) => void;
9
+ box?: 'border-box' | 'content-box' | 'device-pixel-content-box';
10
+ };
11
+ export declare function useResizeObserver<T extends HTMLElement = HTMLElement>(options: UseResizeObserverOptions<T>): Size;
12
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useResizeObserver = void 0;
15
+ var react_1 = require("react");
16
+ var useIsMounted_1 = require("./useIsMounted");
17
+ var initialSize = {
18
+ width: undefined,
19
+ height: undefined
20
+ };
21
+ function useResizeObserver(options) {
22
+ var ref = options.ref, _a = options.box, box = _a === void 0 ? 'content-box' : _a;
23
+ var _b = (0, react_1.useState)(initialSize), _c = _b[0], width = _c.width, height = _c.height, setSize = _b[1];
24
+ var isMounted = (0, useIsMounted_1.useIsMounted)();
25
+ var previousSize = (0, react_1.useRef)(__assign({}, initialSize));
26
+ var onResize = (0, react_1.useRef)(undefined);
27
+ onResize.current = options.onResize;
28
+ (0, react_1.useEffect)(function () {
29
+ if (!ref.current)
30
+ return;
31
+ if (typeof window === 'undefined' || !('ResizeObserver' in window))
32
+ return;
33
+ var observer = new ResizeObserver(function (_a) {
34
+ var entry = _a[0];
35
+ var boxProp = box === 'border-box'
36
+ ? 'borderBoxSize'
37
+ : box === 'device-pixel-content-box'
38
+ ? 'devicePixelContentBoxSize'
39
+ : 'contentBoxSize';
40
+ var newWidth = extractSize(entry, boxProp, 'inlineSize');
41
+ var newHeight = extractSize(entry, boxProp, 'blockSize');
42
+ var hasChanged = previousSize.current.width !== newWidth || previousSize.current.height !== newHeight;
43
+ if (hasChanged) {
44
+ var newSize = { width: newWidth, height: newHeight };
45
+ previousSize.current.width = newWidth;
46
+ previousSize.current.height = newHeight;
47
+ if (onResize.current) {
48
+ onResize.current(newSize);
49
+ }
50
+ else if (isMounted()) {
51
+ setSize(newSize);
52
+ }
53
+ }
54
+ });
55
+ observer.observe(ref.current, { box: box });
56
+ return function () {
57
+ observer.disconnect();
58
+ };
59
+ }, [box, ref, isMounted]);
60
+ return { width: width, height: height };
61
+ }
62
+ exports.useResizeObserver = useResizeObserver;
63
+ function extractSize(entry, box, sizeType) {
64
+ if (!entry[box]) {
65
+ if (box === 'contentBoxSize') {
66
+ return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height'];
67
+ }
68
+ return undefined;
69
+ }
70
+ return Array.isArray(entry[box])
71
+ ? entry[box][0][sizeType]
72
+ : // @ts-ignore Support Firefox's non-standard behavior
73
+ entry[box][sizeType];
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pds-dev-kit-web-test",
3
- "version": "2.4.48",
3
+ "version": "2.4.50",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "lottie-react": "^2.3.1",
24
24
  "nuka-carousel": "^4.8.4",
25
25
  "publ-echo": "^0.0.45",
26
- "publ-echo-test": "^0.0.21",
26
+ "publ-echo-test": "^0.0.22",
27
27
  "react-hook-form": "^7.28.1",
28
28
  "react-i18next": "^11.12.0",
29
29
  "react-router-dom": "^5.2.0",