@vuu-ui/vuu-utils 2.0.0-alpha.1 → 2.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/cjs/packages/vuu-utils/src/index.js +4 -0
- package/cjs/packages/vuu-utils/src/index.js.map +1 -1
- package/cjs/packages/vuu-utils/src/useResizeObserver.js +134 -0
- package/cjs/packages/vuu-utils/src/useResizeObserver.js.map +1 -0
- package/esm/packages/vuu-utils/src/index.js +1 -0
- package/esm/packages/vuu-utils/src/index.js.map +1 -1
- package/esm/packages/vuu-utils/src/useResizeObserver.js +130 -0
- package/esm/packages/vuu-utils/src/useResizeObserver.js.map +1 -0
- package/package.json +6 -6
- package/types/index.d.ts +1 -0
- package/types/useResizeObserver.d.ts +15 -0
|
@@ -62,6 +62,7 @@ var typeaheadUtils = require('./typeahead-utils.js');
|
|
|
62
62
|
var urlUtils = require('./url-utils.js');
|
|
63
63
|
var useId = require('./useId.js');
|
|
64
64
|
var useLayoutEffectSkipFirst = require('./useLayoutEffectSkipFirst.js');
|
|
65
|
+
var useResizeObserver = require('./useResizeObserver.js');
|
|
65
66
|
var useStateRef = require('./useStateRef.js');
|
|
66
67
|
var DataContext = require('./context-definitions/DataContext.js');
|
|
67
68
|
var DataProvider = require('./context-definitions/DataProvider.js');
|
|
@@ -434,6 +435,9 @@ exports.getUrlParameter = urlUtils.getUrlParameter;
|
|
|
434
435
|
exports.hasUrlParameter = urlUtils.hasUrlParameter;
|
|
435
436
|
exports.useId = useId.useId;
|
|
436
437
|
exports.useLayoutEffectSkipFirst = useLayoutEffectSkipFirst.useLayoutEffectSkipFirst;
|
|
438
|
+
exports.WidthHeight = useResizeObserver.WidthHeight;
|
|
439
|
+
exports.WidthOnly = useResizeObserver.WidthOnly;
|
|
440
|
+
exports.useResizeObserver = useResizeObserver.useResizeObserver;
|
|
437
441
|
exports.useStateRef = useStateRef.useStateRef;
|
|
438
442
|
exports.DataContext = DataContext.DataContext;
|
|
439
443
|
exports.DataProvider = DataProvider.DataProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
const WidthHeight = ["height", "width"];
|
|
6
|
+
const WidthOnly = ["width"];
|
|
7
|
+
const observedMap = /* @__PURE__ */ new Map();
|
|
8
|
+
const getTargetSize = (element, size, dimension) => {
|
|
9
|
+
switch (dimension) {
|
|
10
|
+
case "height":
|
|
11
|
+
return size.height;
|
|
12
|
+
case "clientHeight":
|
|
13
|
+
return Math.floor(element.clientHeight);
|
|
14
|
+
case "clientWidth":
|
|
15
|
+
return Math.floor(element.clientWidth);
|
|
16
|
+
case "contentHeight":
|
|
17
|
+
return size.contentHeight;
|
|
18
|
+
case "contentWidth":
|
|
19
|
+
return size.contentWidth;
|
|
20
|
+
case "scrollHeight":
|
|
21
|
+
return Math.ceil(Math.floor(element.scrollHeight));
|
|
22
|
+
case "scrollWidth":
|
|
23
|
+
return Math.ceil(Math.floor(element.scrollWidth));
|
|
24
|
+
case "width":
|
|
25
|
+
return size.width;
|
|
26
|
+
default:
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const { target, borderBoxSize, contentBoxSize } = entry;
|
|
33
|
+
const observedTarget = observedMap.get(target);
|
|
34
|
+
if (observedTarget) {
|
|
35
|
+
const [{ blockSize: height, inlineSize: width }] = borderBoxSize;
|
|
36
|
+
const [{ blockSize: contentHeight, inlineSize: contentWidth }] = contentBoxSize;
|
|
37
|
+
const { onResize, measurements } = observedTarget;
|
|
38
|
+
let sizeChanged = false;
|
|
39
|
+
for (const [dimension, size] of Object.entries(measurements)) {
|
|
40
|
+
const newSize = getTargetSize(
|
|
41
|
+
target,
|
|
42
|
+
{ height, width, contentHeight, contentWidth },
|
|
43
|
+
dimension
|
|
44
|
+
);
|
|
45
|
+
if (newSize !== size) {
|
|
46
|
+
sizeChanged = true;
|
|
47
|
+
measurements[dimension] = newSize;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (sizeChanged) {
|
|
51
|
+
onResize && onResize(measurements);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
|
|
57
|
+
const dimensionsRef = React.useRef(dimensions);
|
|
58
|
+
const measure = React.useCallback((target) => {
|
|
59
|
+
const { width, height } = target.getBoundingClientRect();
|
|
60
|
+
const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
|
|
61
|
+
const flooredHeight = Math.floor(height);
|
|
62
|
+
const flooredWidth = Math.floor(width);
|
|
63
|
+
return dimensionsRef.current.reduce(
|
|
64
|
+
(map, dim) => {
|
|
65
|
+
map[dim] = getTargetSize(
|
|
66
|
+
target,
|
|
67
|
+
{
|
|
68
|
+
width: flooredWidth,
|
|
69
|
+
height: flooredHeight,
|
|
70
|
+
contentHeight,
|
|
71
|
+
contentWidth
|
|
72
|
+
},
|
|
73
|
+
dim
|
|
74
|
+
);
|
|
75
|
+
return map;
|
|
76
|
+
},
|
|
77
|
+
{}
|
|
78
|
+
);
|
|
79
|
+
}, []);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
const target = ref.current;
|
|
82
|
+
async function registerObserver() {
|
|
83
|
+
observedMap.set(target, { measurements: {} });
|
|
84
|
+
const observedTarget = observedMap.get(target);
|
|
85
|
+
if (observedTarget) {
|
|
86
|
+
const measurements = measure(target);
|
|
87
|
+
observedTarget.measurements = measurements;
|
|
88
|
+
resizeObserver.observe(target);
|
|
89
|
+
if (reportInitialSize) {
|
|
90
|
+
onResize(measurements);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
console.log(
|
|
94
|
+
`%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,
|
|
95
|
+
"font-weight:bold; color:red;"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (target) {
|
|
100
|
+
if (observedMap.has(target)) {
|
|
101
|
+
console.log(
|
|
102
|
+
`useResizeObserver attemping to observe same element twice`,
|
|
103
|
+
{
|
|
104
|
+
target
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
registerObserver();
|
|
109
|
+
}
|
|
110
|
+
return () => {
|
|
111
|
+
if (target && observedMap.has(target)) {
|
|
112
|
+
resizeObserver.unobserve(target);
|
|
113
|
+
observedMap.delete(target);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, [measure, ref]);
|
|
117
|
+
React.useEffect(() => {
|
|
118
|
+
const target = ref.current;
|
|
119
|
+
const record = observedMap.get(target);
|
|
120
|
+
if (record) {
|
|
121
|
+
if (dimensionsRef.current !== dimensions) {
|
|
122
|
+
dimensionsRef.current = dimensions;
|
|
123
|
+
const measurements = measure(target);
|
|
124
|
+
record.measurements = measurements;
|
|
125
|
+
}
|
|
126
|
+
record.onResize = onResize;
|
|
127
|
+
}
|
|
128
|
+
}, [dimensions, measure, ref, onResize]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exports.WidthHeight = WidthHeight;
|
|
132
|
+
exports.WidthOnly = WidthOnly;
|
|
133
|
+
exports.useResizeObserver = useResizeObserver;
|
|
134
|
+
//# sourceMappingURL=useResizeObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","sources":["../../../../../../packages/vuu-utils/src/useResizeObserver.ts"],"sourcesContent":["import { RefObject, useCallback, useEffect, useRef } from \"react\";\n\nexport const WidthHeight = [\"height\", \"width\"];\nexport const WidthOnly = [\"width\"];\n\nexport type measurements<T = string | number> = {\n height?: T;\n clientHeight?: number;\n clientWidth?: number;\n contentHeight?: number;\n contentWidth?: number;\n scrollHeight?: number;\n scrollWidth?: number;\n width?: T;\n};\ntype measuredDimension = keyof measurements<number>;\n\nexport type ResizeHandler = (measurements: measurements<number>) => void;\n\ntype observedDetails = {\n onResize?: ResizeHandler;\n measurements: measurements<number>;\n};\nconst observedMap = new Map<HTMLElement, observedDetails>();\n\nconst getTargetSize = (\n element: HTMLElement,\n size: {\n height: number;\n width: number;\n contentHeight: number;\n contentWidth: number;\n },\n dimension: measuredDimension,\n): number => {\n switch (dimension) {\n case \"height\":\n return size.height;\n case \"clientHeight\":\n return Math.floor(element.clientHeight);\n case \"clientWidth\":\n return Math.floor(element.clientWidth);\n case \"contentHeight\":\n return size.contentHeight;\n case \"contentWidth\":\n return size.contentWidth;\n case \"scrollHeight\":\n return Math.ceil(Math.floor(element.scrollHeight));\n case \"scrollWidth\":\n return Math.ceil(Math.floor(element.scrollWidth));\n case \"width\":\n return size.width;\n default:\n return 0;\n }\n};\n\n// TODO should we make this create-on-demand\nconst resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n const observedTarget = observedMap.get(target as HTMLElement);\n if (observedTarget) {\n const [{ blockSize: height, inlineSize: width }] = borderBoxSize;\n const [{ blockSize: contentHeight, inlineSize: contentWidth }] =\n contentBoxSize;\n const { onResize, measurements } = observedTarget;\n let sizeChanged = false;\n for (const [dimension, size] of Object.entries(measurements)) {\n const newSize = getTargetSize(\n target as HTMLElement,\n { height, width, contentHeight, contentWidth },\n dimension as measuredDimension,\n );\n\n if (newSize !== size) {\n sizeChanged = true;\n measurements[dimension as measuredDimension] = newSize;\n }\n }\n if (sizeChanged) {\n // TODO only return measured sizes\n onResize && onResize(measurements);\n }\n }\n }\n});\n\n// TODO use an optional lag (default to false) to ask to fire onResize\n// with initial size\nexport function useResizeObserver(\n ref: RefObject<Element | HTMLElement | null>,\n dimensions: readonly string[],\n onResize: ResizeHandler,\n reportInitialSize = false,\n) {\n const dimensionsRef = useRef(dimensions);\n\n const measure = useCallback((target: HTMLElement): measurements<number> => {\n const { width, height } = target.getBoundingClientRect();\n const { clientWidth: contentWidth, clientHeight: contentHeight } = target;\n const flooredHeight = Math.floor(height);\n const flooredWidth = Math.floor(width);\n\n return dimensionsRef.current.reduce(\n (map: { [key: string]: number }, dim) => {\n map[dim] = getTargetSize(\n target,\n {\n width: flooredWidth,\n height: flooredHeight,\n contentHeight,\n contentWidth,\n },\n dim as measuredDimension,\n );\n return map;\n },\n {},\n );\n }, []);\n\n // TODO use ref to store resizeHandler here\n // resize handler registered with REsizeObserver will never change\n // use ref to store user onResize callback here\n // resizeHandler will call user callback.current\n\n // Keep this effect separate in case user inadvertently passes different\n // dimensions or callback instance each time - we only ever want to\n // initiate new observation when ref changes.\n useEffect(() => {\n const target = ref.current as HTMLElement;\n async function registerObserver() {\n // Create the map entry immediately. useEffect may fire below\n // before fonts are ready and attempt to update entry\n observedMap.set(target, { measurements: {} as measurements<number> });\n // await document.fonts.ready;\n const observedTarget = observedMap.get(target);\n if (observedTarget) {\n const measurements = measure(target);\n observedTarget.measurements = measurements;\n resizeObserver.observe(target);\n if (reportInitialSize) {\n onResize(measurements);\n }\n } else {\n console.log(\n `%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,\n \"font-weight:bold; color:red;\",\n );\n }\n }\n\n if (target) {\n // TODO might we want multiple callers to attach a listener to the same element ?\n if (observedMap.has(target)) {\n console.log(\n `useResizeObserver attemping to observe same element twice`,\n {\n target,\n },\n );\n // throw Error(\n // \"useResizeObserver attemping to observe same element twice\"\n // );\n }\n // TODO set a pending entry on map\n registerObserver();\n }\n return () => {\n if (target && observedMap.has(target)) {\n resizeObserver.unobserve(target);\n observedMap.delete(target);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [measure, ref]);\n\n useEffect(() => {\n const target = ref.current as HTMLElement;\n const record = observedMap.get(target);\n if (record) {\n if (dimensionsRef.current !== dimensions) {\n dimensionsRef.current = dimensions;\n const measurements = measure(target);\n record.measurements = measurements;\n }\n // Might not have changed, but no harm ...\n record.onResize = onResize;\n }\n }, [dimensions, measure, ref, onResize]);\n}\n"],"names":["useRef","useCallback","useEffect"],"mappings":";;;;AAEa,MAAA,WAAA,GAAc,CAAC,QAAA,EAAU,OAAO;AAChC,MAAA,SAAA,GAAY,CAAC,OAAO;AAoBjC,MAAM,WAAA,uBAAkB,GAAkC,EAAA;AAE1D,MAAM,aAAgB,GAAA,CACpB,OACA,EAAA,IAAA,EAMA,SACW,KAAA;AACX,EAAA,QAAQ,SAAW;AAAA,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAK,CAAA,MAAA;AAAA,IACd,KAAK,cAAA;AACH,MAAO,OAAA,IAAA,CAAK,KAAM,CAAA,OAAA,CAAQ,YAAY,CAAA;AAAA,IACxC,KAAK,aAAA;AACH,MAAO,OAAA,IAAA,CAAK,KAAM,CAAA,OAAA,CAAQ,WAAW,CAAA;AAAA,IACvC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Ae,QAAQ,MAAM,CAAA;AACnC,QAAA,MAAA,CAAO,YAAe,GAAA,YAAA;AAAA;AAGxB,MAAA,MAAA,CAAO,QAAW,GAAA,QAAA;AAAA;AACpB,KACC,CAAC,UAAA,EAAY,OAAS,EAAA,GAAA,EAAK,QAAQ,CAAC,CAAA;AACzC;;;;;;"}
|
|
@@ -60,6 +60,7 @@ export { NO_DATA_MATCH } from './typeahead-utils.js';
|
|
|
60
60
|
export { getUrlParameter, hasUrlParameter } from './url-utils.js';
|
|
61
61
|
export { useId } from './useId.js';
|
|
62
62
|
export { useLayoutEffectSkipFirst } from './useLayoutEffectSkipFirst.js';
|
|
63
|
+
export { WidthHeight, WidthOnly, useResizeObserver } from './useResizeObserver.js';
|
|
63
64
|
export { useStateRef } from './useStateRef.js';
|
|
64
65
|
export { DataContext } from './context-definitions/DataContext.js';
|
|
65
66
|
export { DataProvider, useData } from './context-definitions/DataProvider.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const WidthHeight = ["height", "width"];
|
|
4
|
+
const WidthOnly = ["width"];
|
|
5
|
+
const observedMap = /* @__PURE__ */ new Map();
|
|
6
|
+
const getTargetSize = (element, size, dimension) => {
|
|
7
|
+
switch (dimension) {
|
|
8
|
+
case "height":
|
|
9
|
+
return size.height;
|
|
10
|
+
case "clientHeight":
|
|
11
|
+
return Math.floor(element.clientHeight);
|
|
12
|
+
case "clientWidth":
|
|
13
|
+
return Math.floor(element.clientWidth);
|
|
14
|
+
case "contentHeight":
|
|
15
|
+
return size.contentHeight;
|
|
16
|
+
case "contentWidth":
|
|
17
|
+
return size.contentWidth;
|
|
18
|
+
case "scrollHeight":
|
|
19
|
+
return Math.ceil(Math.floor(element.scrollHeight));
|
|
20
|
+
case "scrollWidth":
|
|
21
|
+
return Math.ceil(Math.floor(element.scrollWidth));
|
|
22
|
+
case "width":
|
|
23
|
+
return size.width;
|
|
24
|
+
default:
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const { target, borderBoxSize, contentBoxSize } = entry;
|
|
31
|
+
const observedTarget = observedMap.get(target);
|
|
32
|
+
if (observedTarget) {
|
|
33
|
+
const [{ blockSize: height, inlineSize: width }] = borderBoxSize;
|
|
34
|
+
const [{ blockSize: contentHeight, inlineSize: contentWidth }] = contentBoxSize;
|
|
35
|
+
const { onResize, measurements } = observedTarget;
|
|
36
|
+
let sizeChanged = false;
|
|
37
|
+
for (const [dimension, size] of Object.entries(measurements)) {
|
|
38
|
+
const newSize = getTargetSize(
|
|
39
|
+
target,
|
|
40
|
+
{ height, width, contentHeight, contentWidth },
|
|
41
|
+
dimension
|
|
42
|
+
);
|
|
43
|
+
if (newSize !== size) {
|
|
44
|
+
sizeChanged = true;
|
|
45
|
+
measurements[dimension] = newSize;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (sizeChanged) {
|
|
49
|
+
onResize && onResize(measurements);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
|
|
55
|
+
const dimensionsRef = useRef(dimensions);
|
|
56
|
+
const measure = useCallback((target) => {
|
|
57
|
+
const { width, height } = target.getBoundingClientRect();
|
|
58
|
+
const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
|
|
59
|
+
const flooredHeight = Math.floor(height);
|
|
60
|
+
const flooredWidth = Math.floor(width);
|
|
61
|
+
return dimensionsRef.current.reduce(
|
|
62
|
+
(map, dim) => {
|
|
63
|
+
map[dim] = getTargetSize(
|
|
64
|
+
target,
|
|
65
|
+
{
|
|
66
|
+
width: flooredWidth,
|
|
67
|
+
height: flooredHeight,
|
|
68
|
+
contentHeight,
|
|
69
|
+
contentWidth
|
|
70
|
+
},
|
|
71
|
+
dim
|
|
72
|
+
);
|
|
73
|
+
return map;
|
|
74
|
+
},
|
|
75
|
+
{}
|
|
76
|
+
);
|
|
77
|
+
}, []);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const target = ref.current;
|
|
80
|
+
async function registerObserver() {
|
|
81
|
+
observedMap.set(target, { measurements: {} });
|
|
82
|
+
const observedTarget = observedMap.get(target);
|
|
83
|
+
if (observedTarget) {
|
|
84
|
+
const measurements = measure(target);
|
|
85
|
+
observedTarget.measurements = measurements;
|
|
86
|
+
resizeObserver.observe(target);
|
|
87
|
+
if (reportInitialSize) {
|
|
88
|
+
onResize(measurements);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.log(
|
|
92
|
+
`%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,
|
|
93
|
+
"font-weight:bold; color:red;"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (target) {
|
|
98
|
+
if (observedMap.has(target)) {
|
|
99
|
+
console.log(
|
|
100
|
+
`useResizeObserver attemping to observe same element twice`,
|
|
101
|
+
{
|
|
102
|
+
target
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
registerObserver();
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
if (target && observedMap.has(target)) {
|
|
110
|
+
resizeObserver.unobserve(target);
|
|
111
|
+
observedMap.delete(target);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}, [measure, ref]);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const target = ref.current;
|
|
117
|
+
const record = observedMap.get(target);
|
|
118
|
+
if (record) {
|
|
119
|
+
if (dimensionsRef.current !== dimensions) {
|
|
120
|
+
dimensionsRef.current = dimensions;
|
|
121
|
+
const measurements = measure(target);
|
|
122
|
+
record.measurements = measurements;
|
|
123
|
+
}
|
|
124
|
+
record.onResize = onResize;
|
|
125
|
+
}
|
|
126
|
+
}, [dimensions, measure, ref, onResize]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { WidthHeight, WidthOnly, useResizeObserver };
|
|
130
|
+
//# sourceMappingURL=useResizeObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","sources":["../../../../../../packages/vuu-utils/src/useResizeObserver.ts"],"sourcesContent":["import { RefObject, useCallback, useEffect, useRef } from \"react\";\n\nexport const WidthHeight = [\"height\", \"width\"];\nexport const WidthOnly = [\"width\"];\n\nexport type measurements<T = string | number> = {\n height?: T;\n clientHeight?: number;\n clientWidth?: number;\n contentHeight?: number;\n contentWidth?: number;\n scrollHeight?: number;\n scrollWidth?: number;\n width?: T;\n};\ntype measuredDimension = keyof measurements<number>;\n\nexport type ResizeHandler = (measurements: measurements<number>) => void;\n\ntype observedDetails = {\n onResize?: ResizeHandler;\n measurements: measurements<number>;\n};\nconst observedMap = new Map<HTMLElement, observedDetails>();\n\nconst getTargetSize = (\n element: HTMLElement,\n size: {\n height: number;\n width: number;\n contentHeight: number;\n contentWidth: number;\n },\n dimension: measuredDimension,\n): number => {\n switch (dimension) {\n case \"height\":\n return size.height;\n case \"clientHeight\":\n return Math.floor(element.clientHeight);\n case \"clientWidth\":\n return Math.floor(element.clientWidth);\n case \"contentHeight\":\n return size.contentHeight;\n case \"contentWidth\":\n return size.contentWidth;\n case \"scrollHeight\":\n return Math.ceil(Math.floor(element.scrollHeight));\n case \"scrollWidth\":\n return Math.ceil(Math.floor(element.scrollWidth));\n case \"width\":\n return size.width;\n default:\n return 0;\n }\n};\n\n// TODO should we make this create-on-demand\nconst resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n const observedTarget = observedMap.get(target as HTMLElement);\n if (observedTarget) {\n const [{ blockSize: height, inlineSize: width }] = borderBoxSize;\n const [{ blockSize: contentHeight, inlineSize: contentWidth }] =\n contentBoxSize;\n const { onResize, measurements } = observedTarget;\n let sizeChanged = false;\n for (const [dimension, size] of Object.entries(measurements)) {\n const newSize = getTargetSize(\n target as HTMLElement,\n { height, width, contentHeight, contentWidth },\n dimension as measuredDimension,\n );\n\n if (newSize !== size) {\n sizeChanged = true;\n measurements[dimension as measuredDimension] = newSize;\n }\n }\n if (sizeChanged) {\n // TODO only return measured sizes\n onResize && onResize(measurements);\n }\n }\n }\n});\n\n// TODO use an optional lag (default to false) to ask to fire onResize\n// with initial size\nexport function useResizeObserver(\n ref: RefObject<Element | HTMLElement | null>,\n dimensions: readonly string[],\n onResize: ResizeHandler,\n reportInitialSize = false,\n) {\n const dimensionsRef = useRef(dimensions);\n\n const measure = useCallback((target: HTMLElement): measurements<number> => {\n const { width, height } = target.getBoundingClientRect();\n const { clientWidth: contentWidth, clientHeight: contentHeight } = target;\n const flooredHeight = Math.floor(height);\n const flooredWidth = Math.floor(width);\n\n return dimensionsRef.current.reduce(\n (map: { [key: string]: number }, dim) => {\n map[dim] = getTargetSize(\n target,\n {\n width: flooredWidth,\n height: flooredHeight,\n contentHeight,\n contentWidth,\n },\n dim as measuredDimension,\n );\n return map;\n },\n {},\n );\n }, []);\n\n // TODO use ref to store resizeHandler here\n // resize handler registered with REsizeObserver will never change\n // use ref to store user onResize callback here\n // resizeHandler will call user callback.current\n\n // Keep this effect separate in case user inadvertently passes different\n // dimensions or callback instance each time - we only ever want to\n // initiate new observation when ref changes.\n useEffect(() => {\n const target = ref.current as HTMLElement;\n async function registerObserver() {\n // Create the map entry immediately. useEffect may fire below\n // before fonts are ready and attempt to update entry\n observedMap.set(target, { measurements: {} as measurements<number> });\n // await document.fonts.ready;\n const observedTarget = observedMap.get(target);\n if (observedTarget) {\n const measurements = measure(target);\n observedTarget.measurements = measurements;\n resizeObserver.observe(target);\n if (reportInitialSize) {\n onResize(measurements);\n }\n } else {\n console.log(\n `%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,\n \"font-weight:bold; color:red;\",\n );\n }\n }\n\n if (target) {\n // TODO might we want multiple callers to attach a listener to the same element ?\n if (observedMap.has(target)) {\n console.log(\n `useResizeObserver attemping to observe same element twice`,\n {\n target,\n },\n );\n // throw Error(\n // \"useResizeObserver attemping to observe same element twice\"\n // );\n }\n // TODO set a pending entry on map\n registerObserver();\n }\n return () => {\n if (target && observedMap.has(target)) {\n resizeObserver.unobserve(target);\n observedMap.delete(target);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [measure, ref]);\n\n useEffect(() => {\n const target = ref.current as HTMLElement;\n const record = observedMap.get(target);\n if (record) {\n if (dimensionsRef.current !== dimensions) {\n dimensionsRef.current = dimensions;\n const measurements = measure(target);\n record.measurements = measurements;\n }\n // Might not have changed, but no harm ...\n record.onResize = onResize;\n }\n }, [dimensions, measure, ref, onResize]);\n}\n"],"names":[],"mappings":";;AAEa,MAAA,WAAA,GAAc,CAAC,QAAA,EAAU,OAAO;AAChC,MAAA,SAAA,GAAY,CAAC,OAAO;AAoBjC,MAAM,WAAA,uBAAkB,GAAkC,EAAA;AAE1D,MAAM,aAAgB,GAAA,CACpB,OACA,EAAA,IAAA,EAMA,SACW,KAAA;AACX,EAAA,QAAQ,SAAW;AAAA,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAK,CAAA,MAAA;AAAA,IACd,KAAK,cAAA;AACH,MAAO,OAAA,IAAA,CAAK,KAAM,CAAA,OAAA,CAAQ,YAAY,CAAA;AAAA,IACxC,KAAK,aAAA;AACH,MAAO,OAAA,IAAA,CAAK,KAAM,CAAA,OAAA,CAAQ,WAAW,CAAA;AAAA,IACvC,KAAK,eAAA;AACH,MA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C,QAAA,MAAA,CAAO,YAAe,GAAA,YAAA;AAAA;AAGxB,MAAA,MAAA,CAAO,QAAW,GAAA,QAAA;AAAA;AACpB,KACC,CAAC,UAAA,EAAY,OAAS,EAAA,GAAA,EAAK,QAAQ,CAAC,CAAA;AACzC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.0
|
|
2
|
+
"version": "2.0.0",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@vuu-ui/vuu-data-types": "2.0.0
|
|
8
|
-
"@vuu-ui/vuu-table-types": "2.0.0
|
|
9
|
-
"@vuu-ui/vuu-filter-types": "2.0.0
|
|
10
|
-
"@vuu-ui/vuu-protocol-types": "2.0.0
|
|
7
|
+
"@vuu-ui/vuu-data-types": "2.0.0",
|
|
8
|
+
"@vuu-ui/vuu-table-types": "2.0.0",
|
|
9
|
+
"@vuu-ui/vuu-filter-types": "2.0.0",
|
|
10
|
+
"@vuu-ui/vuu-protocol-types": "2.0.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@internationalized/date": "^3.0.0",
|
|
14
|
-
"@vuu-ui/vuu-filter-parser": "2.0.0
|
|
14
|
+
"@vuu-ui/vuu-filter-parser": "2.0.0",
|
|
15
15
|
"clsx": "^2.0.0",
|
|
16
16
|
"react": "^19.2.3",
|
|
17
17
|
"react-dom": "^19.2.3"
|
package/types/index.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export * from "./url-utils";
|
|
|
62
62
|
export * from "./useId";
|
|
63
63
|
export * from "./useLayoutEffectSkipFirst";
|
|
64
64
|
export * from "./user-types";
|
|
65
|
+
export { WidthHeight, WidthOnly, useResizeObserver, type measurements, type ResizeHandler, } from "./useResizeObserver";
|
|
65
66
|
export * from "./useStateRef";
|
|
66
67
|
/** Context declarations hosted in utils to minimize intra package dependencies */
|
|
67
68
|
export { DataContext } from "./context-definitions/DataContext";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
export declare const WidthHeight: string[];
|
|
3
|
+
export declare const WidthOnly: string[];
|
|
4
|
+
export type measurements<T = string | number> = {
|
|
5
|
+
height?: T;
|
|
6
|
+
clientHeight?: number;
|
|
7
|
+
clientWidth?: number;
|
|
8
|
+
contentHeight?: number;
|
|
9
|
+
contentWidth?: number;
|
|
10
|
+
scrollHeight?: number;
|
|
11
|
+
scrollWidth?: number;
|
|
12
|
+
width?: T;
|
|
13
|
+
};
|
|
14
|
+
export type ResizeHandler = (measurements: measurements<number>) => void;
|
|
15
|
+
export declare function useResizeObserver(ref: RefObject<Element | HTMLElement | null>, dimensions: readonly string[], onResize: ResizeHandler, reportInitialSize?: boolean): void;
|