@pega/cosmos-react-core 8.7.4 → 8.8.1
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/lib/hooks/useItemIntersection.d.ts +2 -1
- package/lib/hooks/useItemIntersection.d.ts.map +1 -1
- package/lib/hooks/useItemIntersection.js +10 -6
- package/lib/hooks/useItemIntersection.js.map +1 -1
- package/lib/utils/isInstance.d.ts +4 -4
- package/lib/utils/isInstance.d.ts.map +1 -1
- package/lib/utils/isInstance.js +20 -8
- package/lib/utils/isInstance.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,8 +5,9 @@ import type { RefObject } from 'react';
|
|
|
5
5
|
* @param offset Index of the list item which needs to be observed.
|
|
6
6
|
* @param cb Callback that needs to be fired on intersect
|
|
7
7
|
* @param itemSelector Selector used to get the node list of items
|
|
8
|
+
* @param boundingRef Ref to use as the bounding root for querying items, needed if component may be rendered in ShadowDOM.
|
|
8
9
|
* @returns void.
|
|
9
10
|
*/
|
|
10
|
-
declare const useItemIntersection: (containerRef: RefObject<HTMLElement>, offset: number, cb: () => void, itemSelector: string) => void;
|
|
11
|
+
declare const useItemIntersection: (containerRef: RefObject<HTMLElement>, offset: number, cb: () => void, itemSelector: string, boundingRef?: RefObject<HTMLElement>) => void;
|
|
11
12
|
export default useItemIntersection;
|
|
12
13
|
//# sourceMappingURL=useItemIntersection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useItemIntersection.d.ts","sourceRoot":"","sources":["../../src/hooks/useItemIntersection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useItemIntersection.d.ts","sourceRoot":"","sources":["../../src/hooks/useItemIntersection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC;;;;;;;;GAQG;AAEH,QAAA,MAAM,mBAAmB,GACvB,cAAc,SAAS,CAAC,WAAW,CAAC,EACpC,QAAQ,MAAM,EACd,IAAI,MAAM,IAAI,EACd,cAAc,MAAM,EACpB,cAAc,SAAS,CAAC,WAAW,CAAC,SAmCrC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
+
import { isInstance } from '../utils';
|
|
2
3
|
/**
|
|
3
4
|
* @example useItemIntersection(listRef,offset,() => { do_some_thing; });
|
|
4
5
|
* @param containerRef The ref of the List.
|
|
5
6
|
* @param offset Index of the list item which needs to be observed.
|
|
6
7
|
* @param cb Callback that needs to be fired on intersect
|
|
7
8
|
* @param itemSelector Selector used to get the node list of items
|
|
9
|
+
* @param boundingRef Ref to use as the bounding root for querying items, needed if component may be rendered in ShadowDOM.
|
|
8
10
|
* @returns void.
|
|
9
11
|
*/
|
|
10
|
-
const useItemIntersection = (containerRef, offset, cb, itemSelector) => {
|
|
12
|
+
const useItemIntersection = (containerRef, offset, cb, itemSelector, boundingRef) => {
|
|
11
13
|
useEffect(() => {
|
|
12
|
-
if (!containerRef.current)
|
|
13
|
-
return;
|
|
14
14
|
let item = null;
|
|
15
15
|
if (offset > 0) {
|
|
16
|
-
const
|
|
16
|
+
const elementToQuery = containerRef?.current ?? boundingRef?.current?.getRootNode() ?? document;
|
|
17
|
+
if (!isInstance(elementToQuery, HTMLElement, SVGElement, Document, ShadowRoot)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const items = elementToQuery.querySelectorAll(itemSelector);
|
|
17
21
|
if (items.length > offset) {
|
|
18
22
|
item = items[offset];
|
|
19
23
|
}
|
|
@@ -24,14 +28,14 @@ const useItemIntersection = (containerRef, offset, cb, itemSelector) => {
|
|
|
24
28
|
cb();
|
|
25
29
|
}
|
|
26
30
|
}, {
|
|
27
|
-
root: containerRef.current
|
|
31
|
+
root: containerRef.current ?? null
|
|
28
32
|
});
|
|
29
33
|
intersectionObserver.observe(item);
|
|
30
34
|
return () => {
|
|
31
35
|
intersectionObserver.disconnect();
|
|
32
36
|
};
|
|
33
37
|
}
|
|
34
|
-
}, [cb,
|
|
38
|
+
}, [cb, offset]);
|
|
35
39
|
};
|
|
36
40
|
export default useItemIntersection;
|
|
37
41
|
//# sourceMappingURL=useItemIntersection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useItemIntersection.js","sourceRoot":"","sources":["../../src/hooks/useItemIntersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC
|
|
1
|
+
{"version":3,"file":"useItemIntersection.js","sourceRoot":"","sources":["../../src/hooks/useItemIntersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;GAQG;AAEH,MAAM,mBAAmB,GAAG,CAC1B,YAAoC,EACpC,MAAc,EACd,EAAc,EACd,YAAoB,EACpB,WAAoC,EACpC,EAAE;IACF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,IAAI,GAAuB,IAAI,CAAC;QACpC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,cAAc,GAClB,YAAY,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,QAAQ,CAAC;YAE3E,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC;gBAC/E,OAAO;YACT,CAAC;YAED,MAAM,KAAK,GAA4B,cAAc,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAErF,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;gBAC1B,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;QACD,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,CACnD,CAAC,OAAoC,EAAE,EAAE;gBACvC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC;oBAC9B,EAAE,EAAE,CAAC;gBACP,CAAC;YACH,CAAC,EACD;gBACE,IAAI,EAAE,YAAY,CAAC,OAAO,IAAI,IAAI;aACnC,CACF,CAAC;YACF,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnC,OAAO,GAAG,EAAE;gBACV,oBAAoB,CAAC,UAAU,EAAE,CAAC;YACpC,CAAC,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["import { useEffect } from 'react';\nimport type { RefObject } from 'react';\n\nimport { isInstance } from '../utils';\n\n/**\n * @example useItemIntersection(listRef,offset,() => { do_some_thing; });\n * @param containerRef The ref of the List.\n * @param offset Index of the list item which needs to be observed.\n * @param cb Callback that needs to be fired on intersect\n * @param itemSelector Selector used to get the node list of items\n * @param boundingRef Ref to use as the bounding root for querying items, needed if component may be rendered in ShadowDOM.\n * @returns void.\n */\n\nconst useItemIntersection = (\n containerRef: RefObject<HTMLElement>,\n offset: number,\n cb: () => void,\n itemSelector: string,\n boundingRef?: RefObject<HTMLElement>\n) => {\n useEffect(() => {\n let item: HTMLElement | null = null;\n if (offset > 0) {\n const elementToQuery =\n containerRef?.current ?? boundingRef?.current?.getRootNode() ?? document;\n\n if (!isInstance(elementToQuery, HTMLElement, SVGElement, Document, ShadowRoot)) {\n return;\n }\n\n const items: NodeListOf<HTMLElement> = elementToQuery.querySelectorAll(itemSelector);\n\n if (items.length > offset) {\n item = items[offset];\n }\n }\n if (item) {\n const intersectionObserver = new IntersectionObserver(\n (entries: IntersectionObserverEntry[]) => {\n if (entries[0].isIntersecting) {\n cb();\n }\n },\n {\n root: containerRef.current ?? null\n }\n );\n intersectionObserver.observe(item);\n return () => {\n intersectionObserver.disconnect();\n };\n }\n }, [cb, offset]);\n};\n\nexport default useItemIntersection;\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This function checks if an object is an instance of
|
|
2
|
+
* This function checks if an object is an instance of one of the given types.
|
|
3
3
|
* It works similarly to the `instanceof` operator, but works across frame boundaries.
|
|
4
4
|
*
|
|
5
5
|
* @param obj The object to check.
|
|
6
|
-
* @param
|
|
7
|
-
* @returns True if the object is an instance of the given
|
|
6
|
+
* @param types The constructor functions or classes to check against.
|
|
7
|
+
* @returns True if the object is an instance of one of the given types, false otherwise.
|
|
8
8
|
*/
|
|
9
|
-
declare const isInstance: <T
|
|
9
|
+
declare const isInstance: <T extends (abstract new (...args: never[]) => unknown)[]>(obj: unknown, ...types: T) => obj is InstanceType<T[number]>;
|
|
10
10
|
export default isInstance;
|
|
11
11
|
//# sourceMappingURL=isInstance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isInstance.d.ts","sourceRoot":"","sources":["../../src/utils/isInstance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isInstance.d.ts","sourceRoot":"","sources":["../../src/utils/isInstance.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,SAAS,CAAC,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,EAAE,EAC1E,KAAK,OAAO,EACZ,GAAG,OAAO,CAAC,KACV,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAgC/B,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/lib/utils/isInstance.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
+
const objTargetString = Object.prototype.toString();
|
|
1
2
|
/**
|
|
2
|
-
* This function checks if an object is an instance of
|
|
3
|
+
* This function checks if an object is an instance of one of the given types.
|
|
3
4
|
* It works similarly to the `instanceof` operator, but works across frame boundaries.
|
|
4
5
|
*
|
|
5
6
|
* @param obj The object to check.
|
|
6
|
-
* @param
|
|
7
|
-
* @returns True if the object is an instance of the given
|
|
7
|
+
* @param types The constructor functions or classes to check against.
|
|
8
|
+
* @returns True if the object is an instance of one of the given types, false otherwise.
|
|
8
9
|
*/
|
|
9
|
-
const isInstance = (obj,
|
|
10
|
-
if (
|
|
10
|
+
const isInstance = (obj, ...types) => {
|
|
11
|
+
if (types.length === 0)
|
|
11
12
|
return false;
|
|
12
|
-
if (obj
|
|
13
|
+
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function'))
|
|
14
|
+
return false;
|
|
15
|
+
if (types.some(type => obj instanceof type))
|
|
13
16
|
return true;
|
|
14
|
-
const
|
|
17
|
+
const targetStrings = new Set(types.flatMap(type => {
|
|
18
|
+
const str = Object.prototype.toString.call(type.prototype);
|
|
19
|
+
// If str is '[object Object]', but type.prototype is not Object.prototype bail to avoid false positives.
|
|
20
|
+
if (str === objTargetString && type.prototype !== Object.prototype) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
return str;
|
|
24
|
+
}));
|
|
25
|
+
if (targetStrings.size === 0)
|
|
26
|
+
return false;
|
|
15
27
|
let current = obj;
|
|
16
28
|
while (current) {
|
|
17
|
-
if (Object.prototype.toString.call(current)
|
|
29
|
+
if (targetStrings.has(Object.prototype.toString.call(current))) {
|
|
18
30
|
return true;
|
|
19
31
|
}
|
|
20
32
|
current = Object.getPrototypeOf(current);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isInstance.js","sourceRoot":"","sources":["../../src/utils/isInstance.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"isInstance.js","sourceRoot":"","sources":["../../src/utils/isInstance.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAA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","sourcesContent":["const objTargetString = Object.prototype.toString();\n\n/**\n * This function checks if an object is an instance of one of the given types.\n * It works similarly to the `instanceof` operator, but works across frame boundaries.\n *\n * @param obj The object to check.\n * @param types The constructor functions or classes to check against.\n * @returns True if the object is an instance of one of the given types, false otherwise.\n */\nconst isInstance = <T extends (abstract new (...args: never[]) => unknown)[]>(\n obj: unknown,\n ...types: T\n): obj is InstanceType<T[number]> => {\n if (types.length === 0) return false;\n\n if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) return false;\n\n if (types.some(type => obj instanceof type)) return true;\n\n const targetStrings = new Set(\n types.flatMap(type => {\n const str = Object.prototype.toString.call(type.prototype);\n\n // If str is '[object Object]', but type.prototype is not Object.prototype bail to avoid false positives.\n if (str === objTargetString && type.prototype !== Object.prototype) {\n return [];\n }\n\n return str;\n })\n );\n\n if (targetStrings.size === 0) return false;\n\n let current: object | null = obj;\n while (current) {\n if (targetStrings.has(Object.prototype.toString.call(current))) {\n return true;\n }\n\n current = Object.getPrototypeOf(current);\n }\n\n return false;\n};\n\nexport default isInstance;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.1",
|
|
4
4
|
"description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Pegasystems",
|