@fluentui/react-carousel 0.0.0-nightly-20241025-0408.1 → 0.0.0-nightly-20241029-0406.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/CHANGELOG.md +14 -14
- package/dist/index.d.ts +1 -1
- package/lib/components/Carousel/useCarousel.js +2 -1
- package/lib/components/Carousel/useCarousel.js.map +1 -1
- package/lib/components/CarouselContext.types.js.map +1 -1
- package/lib/components/pointerEvents.js +57 -0
- package/lib/components/pointerEvents.js.map +1 -0
- package/lib/components/useEmblaCarousel.js +21 -3
- package/lib/components/useEmblaCarousel.js.map +1 -1
- package/lib-commonjs/components/Carousel/useCarousel.js +2 -1
- package/lib-commonjs/components/Carousel/useCarousel.js.map +1 -1
- package/lib-commonjs/components/CarouselContext.types.js.map +1 -1
- package/lib-commonjs/components/pointerEvents.js +67 -0
- package/lib-commonjs/components/pointerEvents.js.map +1 -0
- package/lib-commonjs/components/useEmblaCarousel.js +20 -2
- package/lib-commonjs/components/useEmblaCarousel.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-carousel
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 29 Oct 2024 04:11:17 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## [0.0.0-nightly-
|
|
7
|
+
## [0.0.0-nightly-20241029-0406.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-carousel_v0.0.0-nightly-20241029-0406.1)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-carousel_v9.2.0..@fluentui/react-carousel_v0.0.0-nightly-
|
|
9
|
+
Tue, 29 Oct 2024 04:11:17 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-carousel_v9.2.0..@fluentui/react-carousel_v0.0.0-nightly-20241029-0406.1)
|
|
11
11
|
|
|
12
12
|
### Changes
|
|
13
13
|
|
|
14
14
|
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
|
15
|
-
- Bump @fluentui/react-aria to v0.0.0-nightly-
|
|
16
|
-
- Bump @fluentui/react-button to v0.0.0-nightly-
|
|
17
|
-
- Bump @fluentui/react-context-selector to v0.0.0-nightly-
|
|
18
|
-
- Bump @fluentui/react-jsx-runtime to v0.0.0-nightly-
|
|
19
|
-
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
|
20
|
-
- Bump @fluentui/react-tabster to v0.0.0-nightly-
|
|
21
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
|
22
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
|
23
|
-
- Bump @fluentui/react-conformance to v0.0.0-nightly-
|
|
24
|
-
- Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-
|
|
15
|
+
- Bump @fluentui/react-aria to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
16
|
+
- Bump @fluentui/react-button to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
17
|
+
- Bump @fluentui/react-context-selector to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
18
|
+
- Bump @fluentui/react-jsx-runtime to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
19
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
20
|
+
- Bump @fluentui/react-tabster to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
21
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
22
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
23
|
+
- Bump @fluentui/react-conformance to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
24
|
+
- Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20241029-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/4ad6cff3a29abf29cc2ed98241bd31e5e2481564) by beachball)
|
|
25
25
|
|
|
26
26
|
## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-carousel_v9.2.0)
|
|
27
27
|
|
package/dist/index.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ export declare type CarouselContextValues = {
|
|
|
151
151
|
carousel: CarouselContextValue;
|
|
152
152
|
};
|
|
153
153
|
|
|
154
|
-
export declare type CarouselIndexChangeData = EventData<'click' | 'focus', React_2.FocusEvent |
|
|
154
|
+
export declare type CarouselIndexChangeData = (EventData<'click', React_2.MouseEvent<HTMLButtonElement | HTMLAnchorElement>> | EventData<'focus', React_2.FocusEvent> | EventData<'drag', PointerEvent | MouseEvent>) & {
|
|
155
155
|
/**
|
|
156
156
|
* The index to be set after event has occurred.
|
|
157
157
|
*/
|
|
@@ -24,7 +24,8 @@ import { useAnnounce } from '@fluentui/react-shared-contexts';
|
|
|
24
24
|
activeIndex: props.activeIndex,
|
|
25
25
|
watchDrag: draggable,
|
|
26
26
|
containScroll: whitespace ? false : 'keepSnaps',
|
|
27
|
-
motion
|
|
27
|
+
motion,
|
|
28
|
+
onDragIndexChange: onActiveIndexChange
|
|
28
29
|
});
|
|
29
30
|
const selectPageByElement = useEventCallback((event, element, jump)=>{
|
|
30
31
|
const foundIndex = carouselApi.scrollToElement(element, jump);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCarousel.ts"],"sourcesContent":["import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n getIntrinsicElementProps,\n slot,\n useEventCallback,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselProps, CarouselState } from './Carousel.types';\nimport type { CarouselContextValue } from '../CarouselContext.types';\nimport { useEmblaCarousel } from '../useEmblaCarousel';\nimport { useAnnounce } from '@fluentui/react-shared-contexts';\n\n/**\n * Create the state required to render Carousel.\n *\n * The returned state can be modified with hooks such as useCarouselStyles_unstable,\n * before being passed to renderCarousel_unstable.\n *\n * @param props - props from this instance of Carousel\n * @param ref - reference to root HTMLDivElement of Carousel\n */\nexport function useCarousel_unstable(props: CarouselProps, ref: React.Ref<HTMLDivElement>): CarouselState {\n 'use no memo';\n\n const {\n align = 'center',\n circular = false,\n onActiveIndexChange,\n groupSize = 'auto',\n draggable = false,\n whitespace = false,\n announcement,\n motion = 'slide',\n } = props;\n\n const { dir } = useFluent();\n const { activeIndex, carouselApi, containerRef, subscribeForValues, enableAutoplay, resetAutoplay } =\n useEmblaCarousel({\n align,\n direction: dir,\n loop: circular,\n slidesToScroll: groupSize,\n defaultActiveIndex: props.defaultActiveIndex,\n activeIndex: props.activeIndex,\n watchDrag: draggable,\n containScroll: whitespace ? false : 'keepSnaps',\n motion,\n });\n\n const selectPageByElement: CarouselContextValue['selectPageByElement'] = useEventCallback((event, element, jump) => {\n const foundIndex = carouselApi.scrollToElement(element, jump);\n onActiveIndexChange?.(event, { event, type: 'focus', index: foundIndex });\n\n return foundIndex;\n });\n\n const selectPageByIndex: CarouselContextValue['selectPageByIndex'] = useEventCallback((event, index, jump) => {\n carouselApi.scrollToIndex(index, jump);\n\n onActiveIndexChange?.(event, { event, type: 'click', index });\n });\n\n const selectPageByDirection: CarouselContextValue['selectPageByDirection'] = useEventCallback((event, direction) => {\n const nextPageIndex = carouselApi.scrollInDirection(direction);\n onActiveIndexChange?.(event, { event, type: 'click', index: nextPageIndex });\n\n return nextPageIndex;\n });\n\n const mergedRefs = useMergedRefs(ref, containerRef);\n\n // Announce carousel updates\n const announcementTextRef = React.useRef<string>('');\n const totalNavLength = React.useRef<number>(0);\n const navGroupRef = React.useRef<number[][]>([]);\n\n const { announce } = useAnnounce();\n\n const updateAnnouncement = useEventCallback(() => {\n if (totalNavLength.current <= 0 || !announcement) {\n // Ignore announcements until slides discovered\n return;\n }\n\n const announcementText = announcement(activeIndex, totalNavLength.current, navGroupRef.current);\n\n if (announcementText !== announcementTextRef.current) {\n announcementTextRef.current = announcementText;\n announce(announcementText, { polite: true });\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n // Subscribe to any non-index carousel state changes\n return subscribeForValues(data => {\n if (totalNavLength.current <= 0 && data.navItemsCount > 0 && announcement) {\n const announcementText = announcement(data.activeIndex, data.navItemsCount, data.groupIndexList);\n // Initialize our string to prevent updateAnnouncement from reading an initial load\n announcementTextRef.current = announcementText;\n }\n totalNavLength.current = data.navItemsCount;\n navGroupRef.current = data.groupIndexList;\n updateAnnouncement();\n });\n }, [subscribeForValues, updateAnnouncement, announcement]);\n\n useIsomorphicLayoutEffect(() => {\n updateAnnouncement();\n }, [activeIndex, updateAnnouncement]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: mergedRefs,\n role: 'region',\n ...props,\n }),\n { elementType: 'div' },\n ),\n\n activeIndex,\n circular,\n containerRef: mergedRefs,\n selectPageByElement,\n selectPageByDirection,\n selectPageByIndex,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useFluent_unstable","useFluent","getIntrinsicElementProps","slot","useEventCallback","useIsomorphicLayoutEffect","useMergedRefs","React","useEmblaCarousel","useAnnounce","useCarousel_unstable","props","ref","align","circular","onActiveIndexChange","groupSize","draggable","whitespace","announcement","motion","dir","activeIndex","carouselApi","containerRef","subscribeForValues","enableAutoplay","resetAutoplay","direction","loop","slidesToScroll","defaultActiveIndex","watchDrag","containScroll","selectPageByElement","event","element","jump","foundIndex","scrollToElement","type","index","selectPageByIndex","scrollToIndex","selectPageByDirection","nextPageIndex","scrollInDirection","mergedRefs","announcementTextRef","useRef","totalNavLength","navGroupRef","announce","updateAnnouncement","current","announcementText","polite","data","navItemsCount","groupIndexList","components","root","always","role","elementType"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["useCarousel.ts"],"sourcesContent":["import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n getIntrinsicElementProps,\n slot,\n useEventCallback,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselProps, CarouselState } from './Carousel.types';\nimport type { CarouselContextValue } from '../CarouselContext.types';\nimport { useEmblaCarousel } from '../useEmblaCarousel';\nimport { useAnnounce } from '@fluentui/react-shared-contexts';\n\n/**\n * Create the state required to render Carousel.\n *\n * The returned state can be modified with hooks such as useCarouselStyles_unstable,\n * before being passed to renderCarousel_unstable.\n *\n * @param props - props from this instance of Carousel\n * @param ref - reference to root HTMLDivElement of Carousel\n */\nexport function useCarousel_unstable(props: CarouselProps, ref: React.Ref<HTMLDivElement>): CarouselState {\n 'use no memo';\n\n const {\n align = 'center',\n circular = false,\n onActiveIndexChange,\n groupSize = 'auto',\n draggable = false,\n whitespace = false,\n announcement,\n motion = 'slide',\n } = props;\n\n const { dir } = useFluent();\n const { activeIndex, carouselApi, containerRef, subscribeForValues, enableAutoplay, resetAutoplay } =\n useEmblaCarousel({\n align,\n direction: dir,\n loop: circular,\n slidesToScroll: groupSize,\n defaultActiveIndex: props.defaultActiveIndex,\n activeIndex: props.activeIndex,\n watchDrag: draggable,\n containScroll: whitespace ? false : 'keepSnaps',\n motion,\n onDragIndexChange: onActiveIndexChange,\n });\n\n const selectPageByElement: CarouselContextValue['selectPageByElement'] = useEventCallback((event, element, jump) => {\n const foundIndex = carouselApi.scrollToElement(element, jump);\n onActiveIndexChange?.(event, { event, type: 'focus', index: foundIndex });\n\n return foundIndex;\n });\n\n const selectPageByIndex: CarouselContextValue['selectPageByIndex'] = useEventCallback((event, index, jump) => {\n carouselApi.scrollToIndex(index, jump);\n\n onActiveIndexChange?.(event, { event, type: 'click', index });\n });\n\n const selectPageByDirection: CarouselContextValue['selectPageByDirection'] = useEventCallback((event, direction) => {\n const nextPageIndex = carouselApi.scrollInDirection(direction);\n onActiveIndexChange?.(event, { event, type: 'click', index: nextPageIndex });\n\n return nextPageIndex;\n });\n\n const mergedRefs = useMergedRefs(ref, containerRef);\n\n // Announce carousel updates\n const announcementTextRef = React.useRef<string>('');\n const totalNavLength = React.useRef<number>(0);\n const navGroupRef = React.useRef<number[][]>([]);\n\n const { announce } = useAnnounce();\n\n const updateAnnouncement = useEventCallback(() => {\n if (totalNavLength.current <= 0 || !announcement) {\n // Ignore announcements until slides discovered\n return;\n }\n\n const announcementText = announcement(activeIndex, totalNavLength.current, navGroupRef.current);\n\n if (announcementText !== announcementTextRef.current) {\n announcementTextRef.current = announcementText;\n announce(announcementText, { polite: true });\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n // Subscribe to any non-index carousel state changes\n return subscribeForValues(data => {\n if (totalNavLength.current <= 0 && data.navItemsCount > 0 && announcement) {\n const announcementText = announcement(data.activeIndex, data.navItemsCount, data.groupIndexList);\n // Initialize our string to prevent updateAnnouncement from reading an initial load\n announcementTextRef.current = announcementText;\n }\n totalNavLength.current = data.navItemsCount;\n navGroupRef.current = data.groupIndexList;\n updateAnnouncement();\n });\n }, [subscribeForValues, updateAnnouncement, announcement]);\n\n useIsomorphicLayoutEffect(() => {\n updateAnnouncement();\n }, [activeIndex, updateAnnouncement]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: mergedRefs,\n role: 'region',\n ...props,\n }),\n { elementType: 'div' },\n ),\n\n activeIndex,\n circular,\n containerRef: mergedRefs,\n selectPageByElement,\n selectPageByDirection,\n selectPageByIndex,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useFluent_unstable","useFluent","getIntrinsicElementProps","slot","useEventCallback","useIsomorphicLayoutEffect","useMergedRefs","React","useEmblaCarousel","useAnnounce","useCarousel_unstable","props","ref","align","circular","onActiveIndexChange","groupSize","draggable","whitespace","announcement","motion","dir","activeIndex","carouselApi","containerRef","subscribeForValues","enableAutoplay","resetAutoplay","direction","loop","slidesToScroll","defaultActiveIndex","watchDrag","containScroll","onDragIndexChange","selectPageByElement","event","element","jump","foundIndex","scrollToElement","type","index","selectPageByIndex","scrollToIndex","selectPageByDirection","nextPageIndex","scrollInDirection","mergedRefs","announcementTextRef","useRef","totalNavLength","navGroupRef","announce","updateAnnouncement","current","announcementText","polite","data","navItemsCount","groupIndexList","components","root","always","role","elementType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SACEC,wBAAwB,EACxBC,IAAI,EACJC,gBAAgB,EAChBC,yBAAyB,EACzBC,aAAa,QACR,4BAA4B;AACnC,YAAYC,WAAW,QAAQ;AAI/B,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,WAAW,QAAQ,kCAAkC;AAE9D;;;;;;;;CAQC,G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ources":["CarouselContext.types.ts"],"sourcesContent":["import type { EventData } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselUpdateData } from '../Carousel';\n\nexport type CarouselIndexChangeData =
|
|
1
|
+
{"version":3,"sources":["CarouselContext.types.ts"],"sourcesContent":["import type { EventData } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselUpdateData } from '../Carousel';\n\nexport type CarouselIndexChangeData = (\n | EventData<'click', React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>>\n | EventData<'focus', React.FocusEvent>\n | EventData<'drag', PointerEvent | MouseEvent>\n) & {\n /**\n * The index to be set after event has occurred.\n */\n index: number;\n};\n\nexport type CarouselContextValue = {\n activeIndex: number;\n circular: boolean;\n selectPageByElement: (event: React.FocusEvent, element: HTMLElement, jump?: boolean) => number;\n selectPageByDirection: (\n event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>,\n direction: 'next' | 'prev',\n ) => number;\n selectPageByIndex: (\n event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>,\n value: number,\n jump?: boolean,\n ) => void;\n subscribeForValues: (listener: (data: CarouselUpdateData) => void) => () => void;\n enableAutoplay: (autoplay: boolean) => void;\n resetAutoplay: () => void;\n containerRef?: React.RefObject<HTMLDivElement>;\n};\n\n/**\n * Context shared between Carousel and its children components\n */\nexport type CarouselContextValues = {\n carousel: CarouselContextValue;\n};\n"],"names":["React"],"rangeMappings":"","mappings":"AACA,YAAYA,WAAW,QAAQ"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { carouselClassNames } from '../Carousel';
|
|
2
|
+
export function pointerEventPlugin(options) {
|
|
3
|
+
let emblaApi;
|
|
4
|
+
let pointerEvent;
|
|
5
|
+
function documentDownListener(event) {
|
|
6
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
7
|
+
if (event.target) {
|
|
8
|
+
const targetNode = event.target;
|
|
9
|
+
if (targetNode.classList.contains(carouselClassNames.root) || emblaApi.containerNode().contains(targetNode)) {
|
|
10
|
+
pointerEvent = event;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
targetDocument.removeEventListener('mousedown', documentDownListener);
|
|
14
|
+
targetDocument.removeEventListener('pointerdown', documentDownListener);
|
|
15
|
+
}
|
|
16
|
+
function pointerUpListener() {
|
|
17
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
18
|
+
targetDocument.addEventListener('mousedown', documentDownListener);
|
|
19
|
+
targetDocument.addEventListener('pointerdown', documentDownListener);
|
|
20
|
+
}
|
|
21
|
+
function clearPointerEvent() {
|
|
22
|
+
pointerEvent = undefined;
|
|
23
|
+
}
|
|
24
|
+
function selectListener() {
|
|
25
|
+
if (pointerEvent) {
|
|
26
|
+
var _emblaApi_selectedScrollSnap;
|
|
27
|
+
const newIndex = (_emblaApi_selectedScrollSnap = emblaApi.selectedScrollSnap()) !== null && _emblaApi_selectedScrollSnap !== void 0 ? _emblaApi_selectedScrollSnap : 0;
|
|
28
|
+
options.onSelectViaDrag(pointerEvent, newIndex);
|
|
29
|
+
clearPointerEvent();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function init(emblaApiInstance, optionsHandler) {
|
|
33
|
+
emblaApi = emblaApiInstance;
|
|
34
|
+
// Initialize the listener for first mouse/pointerDown event
|
|
35
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
36
|
+
targetDocument.addEventListener('mousedown', documentDownListener);
|
|
37
|
+
targetDocument.addEventListener('pointerdown', documentDownListener);
|
|
38
|
+
emblaApi.on('pointerUp', pointerUpListener);
|
|
39
|
+
emblaApi.on('select', selectListener);
|
|
40
|
+
// Settle is used to clear pointer in cases where active index does not change
|
|
41
|
+
emblaApi.on('settle', clearPointerEvent);
|
|
42
|
+
}
|
|
43
|
+
function destroy() {
|
|
44
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
45
|
+
targetDocument.removeEventListener('mousedown', documentDownListener);
|
|
46
|
+
targetDocument.removeEventListener('pointerdown', documentDownListener);
|
|
47
|
+
emblaApi.off('pointerUp', pointerUpListener);
|
|
48
|
+
emblaApi.off('select', selectListener);
|
|
49
|
+
emblaApi.off('settle', clearPointerEvent);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
name: 'pointerEvent',
|
|
53
|
+
options,
|
|
54
|
+
init,
|
|
55
|
+
destroy
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["pointerEvents.ts"],"sourcesContent":["import type { CreatePluginType, EmblaCarouselType, OptionsHandlerType } from 'embla-carousel';\nimport { carouselClassNames } from '../Carousel';\n\nexport type PointerEventPluginOptions = {\n onSelectViaDrag: (event: PointerEvent | MouseEvent, index: number) => void;\n};\n\nexport type PointerEventPlugin = CreatePluginType<{}, PointerEventPluginOptions>;\n\nexport function pointerEventPlugin(options: PointerEventPluginOptions): PointerEventPlugin {\n let emblaApi: EmblaCarouselType;\n let pointerEvent: PointerEvent | MouseEvent | undefined;\n\n function documentDownListener(event: PointerEvent | MouseEvent) {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n\n if (event.target) {\n const targetNode = event.target as Element;\n if (targetNode.classList.contains(carouselClassNames.root) || emblaApi.containerNode().contains(targetNode)) {\n pointerEvent = event;\n }\n }\n\n targetDocument.removeEventListener('mousedown', documentDownListener);\n targetDocument.removeEventListener('pointerdown', documentDownListener);\n }\n\n function pointerUpListener() {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n\n targetDocument.addEventListener('mousedown', documentDownListener);\n targetDocument.addEventListener('pointerdown', documentDownListener);\n }\n\n function clearPointerEvent() {\n pointerEvent = undefined;\n }\n\n function selectListener() {\n if (pointerEvent) {\n const newIndex = emblaApi.selectedScrollSnap() ?? 0;\n\n options.onSelectViaDrag(pointerEvent, newIndex);\n clearPointerEvent();\n }\n }\n\n function init(emblaApiInstance: EmblaCarouselType, optionsHandler: OptionsHandlerType): void {\n emblaApi = emblaApiInstance;\n\n // Initialize the listener for first mouse/pointerDown event\n const targetDocument = emblaApi.containerNode().ownerDocument;\n targetDocument.addEventListener('mousedown', documentDownListener);\n targetDocument.addEventListener('pointerdown', documentDownListener);\n\n emblaApi.on('pointerUp', pointerUpListener);\n emblaApi.on('select', selectListener);\n // Settle is used to clear pointer in cases where active index does not change\n emblaApi.on('settle', clearPointerEvent);\n }\n\n function destroy(): void {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n targetDocument.removeEventListener('mousedown', documentDownListener);\n targetDocument.removeEventListener('pointerdown', documentDownListener);\n emblaApi.off('pointerUp', pointerUpListener);\n emblaApi.off('select', selectListener);\n emblaApi.off('settle', clearPointerEvent);\n }\n\n return {\n name: 'pointerEvent',\n options,\n init,\n destroy,\n };\n}\n"],"names":["carouselClassNames","pointerEventPlugin","options","emblaApi","pointerEvent","documentDownListener","event","targetDocument","containerNode","ownerDocument","target","targetNode","classList","contains","root","removeEventListener","pointerUpListener","addEventListener","clearPointerEvent","undefined","selectListener","newIndex","selectedScrollSnap","onSelectViaDrag","init","emblaApiInstance","optionsHandler","on","destroy","off","name"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,kBAAkB,QAAQ,cAAc;AAQjD,OAAO,SAASC,mBAAmBC,OAAkC;IACnE,IAAIC;IACJ,IAAIC;IAEJ,SAASC,qBAAqBC,KAAgC;QAC5D,MAAMC,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAE7D,IAAIH,MAAMI,MAAM,EAAE;YAChB,MAAMC,aAAaL,MAAMI,MAAM;YAC/B,IAAIC,WAAWC,SAAS,CAACC,QAAQ,CAACb,mBAAmBc,IAAI,KAAKX,SAASK,aAAa,GAAGK,QAAQ,CAACF,aAAa;gBAC3GP,eAAeE;YACjB;QACF;QAEAC,eAAeQ,mBAAmB,CAAC,aAAaV;QAChDE,eAAeQ,mBAAmB,CAAC,eAAeV;IACpD;IAEA,SAASW;QACP,MAAMT,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAE7DF,eAAeU,gBAAgB,CAAC,aAAaZ;QAC7CE,eAAeU,gBAAgB,CAAC,eAAeZ;IACjD;IAEA,SAASa;QACPd,eAAee;IACjB;IAEA,SAASC;QACP,IAAIhB,cAAc;gBACCD;YAAjB,MAAMkB,WAAWlB,CAAAA,+BAAAA,SAASmB,kBAAkB,gBAA3BnB,0CAAAA,+BAAiC;YAElDD,QAAQqB,eAAe,CAACnB,cAAciB;YACtCH;QACF;IACF;IAEA,SAASM,KAAKC,gBAAmC,EAAEC,cAAkC;QACnFvB,WAAWsB;QAEX,4DAA4D;QAC5D,MAAMlB,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAC7DF,eAAeU,gBAAgB,CAAC,aAAaZ;QAC7CE,eAAeU,gBAAgB,CAAC,eAAeZ;QAE/CF,SAASwB,EAAE,CAAC,aAAaX;QACzBb,SAASwB,EAAE,CAAC,UAAUP;QACtB,8EAA8E;QAC9EjB,SAASwB,EAAE,CAAC,UAAUT;IACxB;IAEA,SAASU;QACP,MAAMrB,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAC7DF,eAAeQ,mBAAmB,CAAC,aAAaV;QAChDE,eAAeQ,mBAAmB,CAAC,eAAeV;QAClDF,SAAS0B,GAAG,CAAC,aAAab;QAC1Bb,SAAS0B,GAAG,CAAC,UAAUT;QACvBjB,SAAS0B,GAAG,CAAC,UAAUX;IACzB;IAEA,OAAO;QACLY,MAAM;QACN5B;QACAsB;QACAI;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useControllableState } from '@fluentui/react-utilities';
|
|
1
|
+
import { useControllableState, useEventCallback } from '@fluentui/react-utilities';
|
|
2
2
|
import EmblaCarousel from 'embla-carousel';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { carouselCardClassNames } from './CarouselCard/useCarouselCardStyles.styles';
|
|
5
5
|
import { carouselSliderClassNames } from './CarouselSlider/useCarouselSliderStyles.styles';
|
|
6
6
|
import Autoplay from 'embla-carousel-autoplay';
|
|
7
7
|
import Fade from 'embla-carousel-fade';
|
|
8
|
+
import { pointerEventPlugin } from './pointerEvents';
|
|
8
9
|
const sliderClassname = `.${carouselSliderClassNames.root}`;
|
|
9
10
|
const DEFAULT_EMBLA_OPTIONS = {
|
|
10
11
|
containScroll: 'trimSnaps',
|
|
@@ -27,12 +28,19 @@ export function setTabsterDefault(element, isDefault) {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
export function useEmblaCarousel(options) {
|
|
30
|
-
const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion } = options;
|
|
31
|
+
const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion, onDragIndexChange } = options;
|
|
31
32
|
const [activeIndex, setActiveIndex] = useControllableState({
|
|
32
33
|
defaultState: options.defaultActiveIndex,
|
|
33
34
|
state: options.activeIndex,
|
|
34
35
|
initialState: 0
|
|
35
36
|
});
|
|
37
|
+
const onDragEvent = useEventCallback((event, index)=>{
|
|
38
|
+
onDragIndexChange === null || onDragIndexChange === void 0 ? void 0 : onDragIndexChange(event, {
|
|
39
|
+
event,
|
|
40
|
+
type: 'drag',
|
|
41
|
+
index
|
|
42
|
+
});
|
|
43
|
+
});
|
|
36
44
|
const emblaOptions = React.useRef({
|
|
37
45
|
align,
|
|
38
46
|
direction,
|
|
@@ -79,9 +87,16 @@ export function useEmblaCarousel(options) {
|
|
|
79
87
|
if (motion === 'fade') {
|
|
80
88
|
plugins.push(Fade());
|
|
81
89
|
}
|
|
90
|
+
if (watchDrag) {
|
|
91
|
+
plugins.push(pointerEventPlugin({
|
|
92
|
+
onSelectViaDrag: onDragEvent
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
82
95
|
return plugins;
|
|
83
96
|
}, [
|
|
84
|
-
motion
|
|
97
|
+
motion,
|
|
98
|
+
onDragEvent,
|
|
99
|
+
watchDrag
|
|
85
100
|
]);
|
|
86
101
|
// Listeners contains callbacks for UI elements that may require state update based on embla changes
|
|
87
102
|
const listeners = React.useRef(new Set());
|
|
@@ -200,7 +215,9 @@ export function useEmblaCarousel(options) {
|
|
|
200
215
|
React.useEffect(()=>{
|
|
201
216
|
var _emblaApi_current;
|
|
202
217
|
var _emblaApi_current_selectedScrollSnap;
|
|
218
|
+
// Scroll to controlled values on update
|
|
203
219
|
const currentActiveIndex = (_emblaApi_current_selectedScrollSnap = (_emblaApi_current = emblaApi.current) === null || _emblaApi_current === void 0 ? void 0 : _emblaApi_current.selectedScrollSnap()) !== null && _emblaApi_current_selectedScrollSnap !== void 0 ? _emblaApi_current_selectedScrollSnap : 0;
|
|
220
|
+
emblaOptions.current.startIndex = activeIndex;
|
|
204
221
|
if (activeIndex !== currentActiveIndex) {
|
|
205
222
|
var _emblaApi_current1;
|
|
206
223
|
(_emblaApi_current1 = emblaApi.current) === null || _emblaApi_current1 === void 0 ? void 0 : _emblaApi_current1.scrollTo(activeIndex);
|
|
@@ -212,6 +229,7 @@ export function useEmblaCarousel(options) {
|
|
|
212
229
|
var _emblaApi_current;
|
|
213
230
|
const plugins = getPlugins();
|
|
214
231
|
emblaOptions.current = {
|
|
232
|
+
startIndex: emblaOptions.current.startIndex,
|
|
215
233
|
align,
|
|
216
234
|
direction,
|
|
217
235
|
loop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEmblaCarousel.ts"],"sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport EmblaCarousel, { EmblaPluginType, type EmblaCarouselType, type EmblaOptionsType } from 'embla-carousel';\nimport * as React from 'react';\n\nimport { carouselCardClassNames } from './CarouselCard/useCarouselCardStyles.styles';\nimport { carouselSliderClassNames } from './CarouselSlider/useCarouselSliderStyles.styles';\nimport { CarouselMotion, CarouselUpdateData, CarouselVisibilityEventDetail } from '../Carousel';\nimport Autoplay from 'embla-carousel-autoplay';\nimport Fade from 'embla-carousel-fade';\n\nconst sliderClassname = `.${carouselSliderClassNames.root}`;\n\nconst DEFAULT_EMBLA_OPTIONS: EmblaOptionsType = {\n containScroll: 'trimSnaps',\n inViewThreshold: 0.99,\n watchDrag: false,\n skipSnaps: true,\n\n container: sliderClassname,\n slides: `.${carouselCardClassNames.root}`,\n};\n\nexport const EMBLA_VISIBILITY_EVENT = 'embla:visibilitychange';\n\nexport function setTabsterDefault(element: Element, isDefault: boolean) {\n const tabsterAttr = element.getAttribute('data-tabster');\n\n if (tabsterAttr) {\n const tabsterAttributes = JSON.parse(tabsterAttr);\n if (tabsterAttributes.focusable) {\n // If tabster.focusable isn't present, we will ignore.\n tabsterAttributes.focusable.isDefault = isDefault;\n element.setAttribute('data-tabster', JSON.stringify(tabsterAttributes));\n }\n }\n}\n\nexport function useEmblaCarousel(\n options: Pick<EmblaOptionsType, 'align' | 'direction' | 'loop' | 'slidesToScroll' | 'watchDrag' | 'containScroll'> & {\n defaultActiveIndex: number | undefined;\n activeIndex: number | undefined;\n motion?: CarouselMotion;\n },\n) {\n const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion } = options;\n const [activeIndex, setActiveIndex] = useControllableState({\n defaultState: options.defaultActiveIndex,\n state: options.activeIndex,\n initialState: 0,\n });\n\n const emblaOptions = React.useRef<EmblaOptionsType>({\n align,\n direction,\n loop,\n slidesToScroll,\n startIndex: activeIndex,\n watchDrag,\n containScroll,\n });\n\n const emblaApi = React.useRef<EmblaCarouselType | null>(null);\n const autoplayRef = React.useRef<boolean>(false);\n\n const resetAutoplay = React.useCallback(() => {\n emblaApi.current?.plugins().autoplay.reset();\n }, []);\n\n /* Our autoplay button, which is required by standards for autoplay to be enabled, will handle controlled state */\n const enableAutoplay = React.useCallback(\n (autoplay: boolean) => {\n autoplayRef.current = autoplay;\n if (autoplay) {\n emblaApi.current?.plugins().autoplay.play();\n // Reset after play to ensure timing and any focus/mouse pause state is reset.\n resetAutoplay();\n } else {\n emblaApi.current?.plugins().autoplay.stop();\n }\n },\n [resetAutoplay],\n );\n\n const getPlugins = React.useCallback(() => {\n const plugins: EmblaPluginType[] = [\n Autoplay({\n playOnInit: autoplayRef.current,\n stopOnInteraction: !autoplayRef.current,\n stopOnMouseEnter: true,\n stopOnFocusIn: true,\n rootNode: (emblaRoot: HTMLElement) => {\n return emblaRoot.querySelector(sliderClassname) ?? emblaRoot;\n },\n }),\n ];\n\n // Optionally add Fade plugin\n if (motion === 'fade') {\n plugins.push(Fade());\n }\n\n return plugins;\n }, [motion]);\n\n // Listeners contains callbacks for UI elements that may require state update based on embla changes\n const listeners = React.useRef(new Set<(data: CarouselUpdateData) => void>());\n const subscribeForValues = React.useCallback((listener: (data: CarouselUpdateData) => void) => {\n listeners.current.add(listener);\n\n return () => {\n listeners.current.delete(listener);\n };\n }, []);\n\n const containerRef: React.RefObject<HTMLDivElement> = React.useMemo(() => {\n let currentElement: HTMLDivElement | null = null;\n\n const handleIndexChange = () => {\n const newIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n const slides = emblaApi.current?.slideNodes();\n const actualIndex = emblaApi.current?.internalEngine().slideRegistry[newIndex][0] ?? 0;\n // We set the active or first index of group on-screen as the selected tabster index\n slides?.forEach((slide, slideIndex) => {\n setTabsterDefault(slide, slideIndex === actualIndex);\n });\n setActiveIndex(newIndex);\n };\n const handleReinit = () => {\n const nodes: HTMLElement[] = emblaApi.current?.slideNodes() ?? [];\n const groupIndexList: number[][] = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const navItemsCount = groupIndexList.length > 0 ? groupIndexList.length : nodes.length;\n\n const data: CarouselUpdateData = {\n navItemsCount,\n activeIndex: emblaApi.current?.selectedScrollSnap() ?? 0,\n groupIndexList,\n slideNodes: nodes,\n };\n\n for (const listener of listeners.current) {\n listener(data);\n }\n };\n const handleVisibilityChange = () => {\n const cardElements = emblaApi.current?.slideNodes();\n const visibleIndexes = emblaApi.current?.slidesInView() ?? [];\n\n cardElements?.forEach((cardElement, index) => {\n cardElement.dispatchEvent(\n new CustomEvent<CarouselVisibilityEventDetail>(EMBLA_VISIBILITY_EVENT, {\n bubbles: false,\n detail: { isVisible: visibleIndexes.includes(index) },\n }),\n );\n });\n };\n\n const plugins = getPlugins();\n\n return {\n set current(newElement: HTMLDivElement | null) {\n if (currentElement) {\n emblaApi.current?.off('slidesInView', handleVisibilityChange);\n emblaApi.current?.off('select', handleIndexChange);\n emblaApi.current?.off('reInit', handleReinit);\n emblaApi.current?.destroy();\n }\n\n if (newElement) {\n currentElement = newElement;\n emblaApi.current = EmblaCarousel(\n newElement,\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n\n emblaApi.current?.on('reInit', handleReinit);\n emblaApi.current?.on('slidesInView', handleVisibilityChange);\n emblaApi.current?.on('select', handleIndexChange);\n }\n },\n };\n }, [getPlugins, setActiveIndex]);\n\n const carouselApi = React.useMemo(\n () => ({\n scrollToElement: (element: HTMLElement, jump?: boolean) => {\n const cardElements = emblaApi.current?.slideNodes();\n const groupIndexList = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const cardIndex = cardElements?.indexOf(element) ?? 0;\n const groupIndex = groupIndexList.findIndex(group => {\n return group.includes(cardIndex);\n });\n const indexFocus = groupIndex ?? cardIndex;\n emblaApi.current?.scrollTo(indexFocus, jump);\n\n return indexFocus;\n },\n scrollToIndex: (index: number, jump?: boolean) => {\n emblaApi.current?.scrollTo(index, jump);\n },\n scrollInDirection: (dir: 'prev' | 'next') => {\n if (dir === 'prev') {\n emblaApi.current?.scrollPrev();\n } else {\n emblaApi.current?.scrollNext();\n }\n\n return emblaApi.current?.selectedScrollSnap() ?? 0;\n },\n }),\n [],\n );\n\n React.useEffect(() => {\n const currentActiveIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n\n if (activeIndex !== currentActiveIndex) {\n emblaApi.current?.scrollTo(activeIndex);\n }\n }, [activeIndex]);\n\n React.useEffect(() => {\n const plugins = getPlugins();\n\n emblaOptions.current = { align, direction, loop, slidesToScroll, watchDrag, containScroll };\n emblaApi.current?.reInit(\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n }, [align, direction, loop, slidesToScroll, watchDrag, containScroll, getPlugins]);\n\n return {\n activeIndex,\n carouselApi,\n containerRef,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useControllableState","EmblaCarousel","React","carouselCardClassNames","carouselSliderClassNames","Autoplay","Fade","sliderClassname","root","DEFAULT_EMBLA_OPTIONS","containScroll","inViewThreshold","watchDrag","skipSnaps","container","slides","EMBLA_VISIBILITY_EVENT","setTabsterDefault","element","isDefault","tabsterAttr","getAttribute","tabsterAttributes","JSON","parse","focusable","setAttribute","stringify","useEmblaCarousel","options","align","direction","loop","slidesToScroll","motion","activeIndex","setActiveIndex","defaultState","defaultActiveIndex","state","initialState","emblaOptions","useRef","startIndex","emblaApi","autoplayRef","resetAutoplay","useCallback","current","plugins","autoplay","reset","enableAutoplay","play","stop","getPlugins","playOnInit","stopOnInteraction","stopOnMouseEnter","stopOnFocusIn","rootNode","emblaRoot","querySelector","push","listeners","Set","subscribeForValues","listener","add","delete","containerRef","useMemo","currentElement","handleIndexChange","newIndex","selectedScrollSnap","slideNodes","actualIndex","internalEngine","slideRegistry","forEach","slide","slideIndex","handleReinit","nodes","groupIndexList","navItemsCount","length","data","handleVisibilityChange","cardElements","visibleIndexes","slidesInView","cardElement","index","dispatchEvent","CustomEvent","bubbles","detail","isVisible","includes","newElement","off","destroy","on","carouselApi","scrollToElement","jump","cardIndex","indexOf","groupIndex","findIndex","group","indexFocus","scrollTo","scrollToIndex","scrollInDirection","dir","scrollPrev","scrollNext","useEffect","currentActiveIndex","reInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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hBJ,yCAAAA,mBAAkB0E,UAAU;gBAC9B,OAAO;wBACL1E;qBAAAA,qBAAAA,SAASI,OAAO,cAAhBJ,yCAAAA,mBAAkB2E,UAAU;gBAC9B;oBAEO3E;gBAAP,OAAOA,CAAAA,wCAAAA,oBAAAA,SAASI,OAAO,cAAhBJ,wCAAAA,kBAAkB+B,kBAAkB,gBAApC/B,kDAAAA,uCAA0C;YACnD;QACF,CAAA,GACA,EAAE;IAGJ1C,MAAMsH,SAAS,CAAC;YACa5E;YAAAA;QAA3B,MAAM6E,qBAAqB7E,CAAAA,wCAAAA,oBAAAA,SAASI,OAAO,cAAhBJ,wCAAAA,kBAAkB+B,kBAAkB,gBAApC/B,kDAAAA,uCAA0C;QAErE,IAAIT,gBAAgBsF,oBAAoB;gBACtC7E;aAAAA,qBAAAA,SAASI,OAAO,cAAhBJ,yCAAAA,mBAAkBsE,QAAQ,CAAC/E;QAC7B;IACF,GAAG;QAACA;KAAY;IAEhBjC,MAAMsH,SAAS,CAAC;YAId5E;QAHA,MAAMK,UAAUM;QAEhBd,aAAaO,OAAO,GAAG;YAAElB;YAAOC;YAAWC;YAAMC;YAAgBrB;YAAWF;QAAc;SAC1FkC,oBAAAA,SAASI,OAAO,cAAhBJ,wCAAAA,kBAAkB8E,MAAM,CACtB;YACE,GAAGjH,qBAAqB;YACxB,GAAGgC,aAAaO,OAAO;QACzB,GACAC;IAEJ,GAAG;QAACnB;QAAOC;QAAWC;QAAMC;QAAgBrB;QAAWF;QAAe6C;KAAW;IAEjF,OAAO;QACLpB;QACAsE;QACAnC;QACAJ;QACAd;QACAN;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["useEmblaCarousel.ts"],"sourcesContent":["import { type EventHandler, useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport EmblaCarousel, { EmblaPluginType, type EmblaCarouselType, type EmblaOptionsType } from 'embla-carousel';\nimport * as React from 'react';\n\nimport { carouselCardClassNames } from './CarouselCard/useCarouselCardStyles.styles';\nimport { carouselSliderClassNames } from './CarouselSlider/useCarouselSliderStyles.styles';\nimport { CarouselMotion, CarouselUpdateData, CarouselVisibilityEventDetail } from '../Carousel';\nimport Autoplay from 'embla-carousel-autoplay';\nimport Fade from 'embla-carousel-fade';\nimport { pointerEventPlugin } from './pointerEvents';\nimport type { CarouselIndexChangeData } from './CarouselContext.types';\n\nconst sliderClassname = `.${carouselSliderClassNames.root}`;\n\nconst DEFAULT_EMBLA_OPTIONS: EmblaOptionsType = {\n containScroll: 'trimSnaps',\n inViewThreshold: 0.99,\n watchDrag: false,\n skipSnaps: true,\n\n container: sliderClassname,\n slides: `.${carouselCardClassNames.root}`,\n};\n\nexport const EMBLA_VISIBILITY_EVENT = 'embla:visibilitychange';\n\nexport function setTabsterDefault(element: Element, isDefault: boolean) {\n const tabsterAttr = element.getAttribute('data-tabster');\n\n if (tabsterAttr) {\n const tabsterAttributes = JSON.parse(tabsterAttr);\n if (tabsterAttributes.focusable) {\n // If tabster.focusable isn't present, we will ignore.\n tabsterAttributes.focusable.isDefault = isDefault;\n element.setAttribute('data-tabster', JSON.stringify(tabsterAttributes));\n }\n }\n}\n\nexport function useEmblaCarousel(\n options: Pick<EmblaOptionsType, 'align' | 'direction' | 'loop' | 'slidesToScroll' | 'watchDrag' | 'containScroll'> & {\n defaultActiveIndex: number | undefined;\n activeIndex: number | undefined;\n motion?: CarouselMotion;\n onDragIndexChange?: EventHandler<CarouselIndexChangeData>;\n },\n) {\n const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion, onDragIndexChange } = options;\n const [activeIndex, setActiveIndex] = useControllableState({\n defaultState: options.defaultActiveIndex,\n state: options.activeIndex,\n initialState: 0,\n });\n\n const onDragEvent = useEventCallback((event: PointerEvent | MouseEvent, index: number) => {\n onDragIndexChange?.(event, { event, type: 'drag', index });\n });\n\n const emblaOptions = React.useRef<EmblaOptionsType>({\n align,\n direction,\n loop,\n slidesToScroll,\n startIndex: activeIndex,\n watchDrag,\n containScroll,\n });\n\n const emblaApi = React.useRef<EmblaCarouselType | null>(null);\n const autoplayRef = React.useRef<boolean>(false);\n\n const resetAutoplay = React.useCallback(() => {\n emblaApi.current?.plugins().autoplay.reset();\n }, []);\n\n /* Our autoplay button, which is required by standards for autoplay to be enabled, will handle controlled state */\n const enableAutoplay = React.useCallback(\n (autoplay: boolean) => {\n autoplayRef.current = autoplay;\n if (autoplay) {\n emblaApi.current?.plugins().autoplay.play();\n // Reset after play to ensure timing and any focus/mouse pause state is reset.\n resetAutoplay();\n } else {\n emblaApi.current?.plugins().autoplay.stop();\n }\n },\n [resetAutoplay],\n );\n\n const getPlugins = React.useCallback(() => {\n const plugins: EmblaPluginType[] = [\n Autoplay({\n playOnInit: autoplayRef.current,\n stopOnInteraction: !autoplayRef.current,\n stopOnMouseEnter: true,\n stopOnFocusIn: true,\n rootNode: (emblaRoot: HTMLElement) => {\n return emblaRoot.querySelector(sliderClassname) ?? emblaRoot;\n },\n }),\n ];\n\n // Optionally add Fade plugin\n if (motion === 'fade') {\n plugins.push(Fade());\n }\n\n if (watchDrag) {\n plugins.push(\n pointerEventPlugin({\n onSelectViaDrag: onDragEvent,\n }),\n );\n }\n\n return plugins;\n }, [motion, onDragEvent, watchDrag]);\n\n // Listeners contains callbacks for UI elements that may require state update based on embla changes\n const listeners = React.useRef(new Set<(data: CarouselUpdateData) => void>());\n const subscribeForValues = React.useCallback((listener: (data: CarouselUpdateData) => void) => {\n listeners.current.add(listener);\n\n return () => {\n listeners.current.delete(listener);\n };\n }, []);\n\n const containerRef: React.RefObject<HTMLDivElement> = React.useMemo(() => {\n let currentElement: HTMLDivElement | null = null;\n\n const handleIndexChange = () => {\n const newIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n const slides = emblaApi.current?.slideNodes();\n const actualIndex = emblaApi.current?.internalEngine().slideRegistry[newIndex][0] ?? 0;\n\n // We set the active or first index of group on-screen as the selected tabster index\n slides?.forEach((slide, slideIndex) => {\n setTabsterDefault(slide, slideIndex === actualIndex);\n });\n setActiveIndex(newIndex);\n };\n const handleReinit = () => {\n const nodes: HTMLElement[] = emblaApi.current?.slideNodes() ?? [];\n const groupIndexList: number[][] = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const navItemsCount = groupIndexList.length > 0 ? groupIndexList.length : nodes.length;\n\n const data: CarouselUpdateData = {\n navItemsCount,\n activeIndex: emblaApi.current?.selectedScrollSnap() ?? 0,\n groupIndexList,\n slideNodes: nodes,\n };\n\n for (const listener of listeners.current) {\n listener(data);\n }\n };\n const handleVisibilityChange = () => {\n const cardElements = emblaApi.current?.slideNodes();\n const visibleIndexes = emblaApi.current?.slidesInView() ?? [];\n\n cardElements?.forEach((cardElement, index) => {\n cardElement.dispatchEvent(\n new CustomEvent<CarouselVisibilityEventDetail>(EMBLA_VISIBILITY_EVENT, {\n bubbles: false,\n detail: { isVisible: visibleIndexes.includes(index) },\n }),\n );\n });\n };\n\n const plugins = getPlugins();\n\n return {\n set current(newElement: HTMLDivElement | null) {\n if (currentElement) {\n emblaApi.current?.off('slidesInView', handleVisibilityChange);\n emblaApi.current?.off('select', handleIndexChange);\n emblaApi.current?.off('reInit', handleReinit);\n emblaApi.current?.destroy();\n }\n\n if (newElement) {\n currentElement = newElement;\n emblaApi.current = EmblaCarousel(\n newElement,\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n\n emblaApi.current?.on('reInit', handleReinit);\n emblaApi.current?.on('slidesInView', handleVisibilityChange);\n emblaApi.current?.on('select', handleIndexChange);\n }\n },\n };\n }, [getPlugins, setActiveIndex]);\n\n const carouselApi = React.useMemo(\n () => ({\n scrollToElement: (element: HTMLElement, jump?: boolean) => {\n const cardElements = emblaApi.current?.slideNodes();\n const groupIndexList = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const cardIndex = cardElements?.indexOf(element) ?? 0;\n const groupIndex = groupIndexList.findIndex(group => {\n return group.includes(cardIndex);\n });\n const indexFocus = groupIndex ?? cardIndex;\n emblaApi.current?.scrollTo(indexFocus, jump);\n\n return indexFocus;\n },\n scrollToIndex: (index: number, jump?: boolean) => {\n emblaApi.current?.scrollTo(index, jump);\n },\n scrollInDirection: (dir: 'prev' | 'next') => {\n if (dir === 'prev') {\n emblaApi.current?.scrollPrev();\n } else {\n emblaApi.current?.scrollNext();\n }\n\n return emblaApi.current?.selectedScrollSnap() ?? 0;\n },\n }),\n [],\n );\n\n React.useEffect(() => {\n // Scroll to controlled values on update\n const currentActiveIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n emblaOptions.current.startIndex = activeIndex;\n if (activeIndex !== currentActiveIndex) {\n emblaApi.current?.scrollTo(activeIndex);\n }\n }, [activeIndex]);\n\n React.useEffect(() => {\n const plugins = getPlugins();\n\n emblaOptions.current = {\n startIndex: emblaOptions.current.startIndex,\n align,\n direction,\n loop,\n slidesToScroll,\n watchDrag,\n containScroll,\n };\n emblaApi.current?.reInit(\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n }, [align, direction, loop, slidesToScroll, watchDrag, containScroll, getPlugins]);\n\n return {\n activeIndex,\n carouselApi,\n containerRef,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useControllableState","useEventCallback","EmblaCarousel","React","carouselCardClassNames","carouselSliderClassNames","Autoplay","Fade","pointerEventPlugin","sliderClassname","root","DEFAULT_EMBLA_OPTIONS","containScroll","inViewThreshold","watchDrag","skipSnaps","container","slides","EMBLA_VISIBILITY_EVENT","setTabsterDefault","element","isDefault","tabsterAttr","getAttribute","tabsterAttributes","JSON","parse","focusable","setAttribute","stringify","useEmblaCarousel","options","align","direction","loop","slidesToScroll","motion","onDragIndexChange","activeIndex","setActiveIndex","defaultState","defaultActiveIndex","state","initialState","onDragEvent","event","index","type","emblaOptions","useRef","startIndex","emblaApi","autoplayRef","resetAutoplay","useCallback","current","plugins","autoplay","reset","enableAutoplay","play","stop","getPlugins","playOnInit","stopOnInteraction","stopOnMouseEnter","stopOnFocusIn","rootNode","emblaRoot","querySelector","push","onSelectViaDrag","listeners","Set","subscribeForValues","listener","add","delete","containerRef","useMemo","currentElement","handleIndexChange","newIndex","selectedScrollSnap","slideNodes","actualIndex","internalEngine","slideRegistry","forEach","slide","slideIndex","handleReinit","nodes","groupIndexList","navItemsCount","length","data","handleVisibilityChange","cardElements","visibleIndexes","slidesInView","cardElement","dispatchEvent","CustomEvent","bubbles","detail","isVisible","includes","newElement","off","destroy","on","carouselApi","scrollToElement","jump","cardIndex","indexOf","groupIndex","findIndex","group","indexFocus","scrollTo","scrollToIndex","scrollInDirection","dir","scrollPrev","scrollNext","useEffect","currentActiveIndex","reInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAA4BA,oBAAoB,EAAEC,gBAAgB,QAAQ,4BAA4B;AACtG,OAAOC,mBAAuF,iBAAiB;AAC/G,YAAYC,WAAW,QAAQ;AAE/B,SAASC,sBAAsB,QAAQ,8CAA8C;AACrF,SAASC,wBAAwB,QAAQ,kDAAkD;AAE3F,OAAOC,cAAc,0BAA0B;AAC/C,OAAOC,UAAU,sBAAsB;AACvC,SAASC,kBAAkB,QAAQ,kBAAkB;AAGrD,MAAMC,kBAAkB,CAAC,CAAC,EAAEJ,yBAAyBK,IAAI,CAAC,CAAC;AAE3D,MAAMC,wBAA0C;IAC9CC,eAAe;IACfC,iBAAiB;IACjBC,WAAW;IACXC,WAAW;IAEXC,WAAWP;IACXQ,QAAQ,CAAC,CAAC,EAAEb,uBAAuBM,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SAAS,CAAC;YAEa5E;YAAAA;QAD3B,wCAAwC;QACxC,MAAM6E,qBAAqB7E,CAAAA,wCAAAA,oBAAAA,SAASI,OAAO,cAAhBJ,wCAAAA,kBAAkBgC,kBAAkB,gBAApChC,kDAAAA,uCAA0C;QACrEH,aAAaO,OAAO,CAACL,UAAU,GAAGZ;QAClC,IAAIA,gBAAgB0F,oBAAoB;gBACtC7E;aAAAA,qBAAAA,SAASI,OAAO,cAAhBJ,yCAAAA,mBAAkBsE,QAAQ,CAACnF;QAC7B;IACF,GAAG;QAACA;KAAY;IAEhBnC,MAAM4H,SAAS,CAAC;YAYd5E;QAXA,MAAMK,UAAUM;QAEhBd,aAAaO,OAAO,GAAG;YACrBL,YAAYF,aAAaO,OAAO,CAACL,UAAU;YAC3ClB;YACAC;YACAC;YACAC;YACArB;YACAF;QACF;SACAuC,oBAAAA,SAASI,OAAO,cAAhBJ,wCAAAA,kBAAkB8E,MAAM,CACtB;YACE,GAAGtH,qBAAqB;YACxB,GAAGqC,aAAaO,OAAO;QACzB,GACAC;IAEJ,GAAG;QAACxB;QAAOC;QAAWC;QAAMC;QAAgBrB;QAAWF;QAAekD;KAAW;IAEjF,OAAO;QACLxB;QACA0E;QACAlC;QACAJ;QACAf;QACAN;IACF;AACF"}
|
|
@@ -26,7 +26,8 @@ function useCarousel_unstable(props, ref) {
|
|
|
26
26
|
activeIndex: props.activeIndex,
|
|
27
27
|
watchDrag: draggable,
|
|
28
28
|
containScroll: whitespace ? false : 'keepSnaps',
|
|
29
|
-
motion
|
|
29
|
+
motion,
|
|
30
|
+
onDragIndexChange: onActiveIndexChange
|
|
30
31
|
});
|
|
31
32
|
const selectPageByElement = (0, _reactutilities.useEventCallback)((event, element, jump)=>{
|
|
32
33
|
const foundIndex = carouselApi.scrollToElement(element, jump);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCarousel.ts"],"sourcesContent":["import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n getIntrinsicElementProps,\n slot,\n useEventCallback,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselProps, CarouselState } from './Carousel.types';\nimport type { CarouselContextValue } from '../CarouselContext.types';\nimport { useEmblaCarousel } from '../useEmblaCarousel';\nimport { useAnnounce } from '@fluentui/react-shared-contexts';\n\n/**\n * Create the state required to render Carousel.\n *\n * The returned state can be modified with hooks such as useCarouselStyles_unstable,\n * before being passed to renderCarousel_unstable.\n *\n * @param props - props from this instance of Carousel\n * @param ref - reference to root HTMLDivElement of Carousel\n */\nexport function useCarousel_unstable(props: CarouselProps, ref: React.Ref<HTMLDivElement>): CarouselState {\n 'use no memo';\n\n const {\n align = 'center',\n circular = false,\n onActiveIndexChange,\n groupSize = 'auto',\n draggable = false,\n whitespace = false,\n announcement,\n motion = 'slide',\n } = props;\n\n const { dir } = useFluent();\n const { activeIndex, carouselApi, containerRef, subscribeForValues, enableAutoplay, resetAutoplay } =\n useEmblaCarousel({\n align,\n direction: dir,\n loop: circular,\n slidesToScroll: groupSize,\n defaultActiveIndex: props.defaultActiveIndex,\n activeIndex: props.activeIndex,\n watchDrag: draggable,\n containScroll: whitespace ? false : 'keepSnaps',\n motion,\n });\n\n const selectPageByElement: CarouselContextValue['selectPageByElement'] = useEventCallback((event, element, jump) => {\n const foundIndex = carouselApi.scrollToElement(element, jump);\n onActiveIndexChange?.(event, { event, type: 'focus', index: foundIndex });\n\n return foundIndex;\n });\n\n const selectPageByIndex: CarouselContextValue['selectPageByIndex'] = useEventCallback((event, index, jump) => {\n carouselApi.scrollToIndex(index, jump);\n\n onActiveIndexChange?.(event, { event, type: 'click', index });\n });\n\n const selectPageByDirection: CarouselContextValue['selectPageByDirection'] = useEventCallback((event, direction) => {\n const nextPageIndex = carouselApi.scrollInDirection(direction);\n onActiveIndexChange?.(event, { event, type: 'click', index: nextPageIndex });\n\n return nextPageIndex;\n });\n\n const mergedRefs = useMergedRefs(ref, containerRef);\n\n // Announce carousel updates\n const announcementTextRef = React.useRef<string>('');\n const totalNavLength = React.useRef<number>(0);\n const navGroupRef = React.useRef<number[][]>([]);\n\n const { announce } = useAnnounce();\n\n const updateAnnouncement = useEventCallback(() => {\n if (totalNavLength.current <= 0 || !announcement) {\n // Ignore announcements until slides discovered\n return;\n }\n\n const announcementText = announcement(activeIndex, totalNavLength.current, navGroupRef.current);\n\n if (announcementText !== announcementTextRef.current) {\n announcementTextRef.current = announcementText;\n announce(announcementText, { polite: true });\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n // Subscribe to any non-index carousel state changes\n return subscribeForValues(data => {\n if (totalNavLength.current <= 0 && data.navItemsCount > 0 && announcement) {\n const announcementText = announcement(data.activeIndex, data.navItemsCount, data.groupIndexList);\n // Initialize our string to prevent updateAnnouncement from reading an initial load\n announcementTextRef.current = announcementText;\n }\n totalNavLength.current = data.navItemsCount;\n navGroupRef.current = data.groupIndexList;\n updateAnnouncement();\n });\n }, [subscribeForValues, updateAnnouncement, announcement]);\n\n useIsomorphicLayoutEffect(() => {\n updateAnnouncement();\n }, [activeIndex, updateAnnouncement]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: mergedRefs,\n role: 'region',\n ...props,\n }),\n { elementType: 'div' },\n ),\n\n activeIndex,\n circular,\n containerRef: mergedRefs,\n selectPageByElement,\n selectPageByDirection,\n selectPageByIndex,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useCarousel_unstable","props","ref","align","circular","onActiveIndexChange","groupSize","draggable","whitespace","announcement","motion","dir","useFluent","activeIndex","carouselApi","containerRef","subscribeForValues","enableAutoplay","resetAutoplay","useEmblaCarousel","direction","loop","slidesToScroll","defaultActiveIndex","watchDrag","containScroll","selectPageByElement","useEventCallback","event","element","jump","foundIndex","scrollToElement","type","index","selectPageByIndex","scrollToIndex","selectPageByDirection","nextPageIndex","scrollInDirection","mergedRefs","useMergedRefs","announcementTextRef","React","useRef","totalNavLength","navGroupRef","announce","useAnnounce","updateAnnouncement","current","announcementText","polite","useIsomorphicLayoutEffect","data","navItemsCount","groupIndexList","components","root","slot","always","getIntrinsicElementProps","role","elementType"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["useCarousel.ts"],"sourcesContent":["import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n getIntrinsicElementProps,\n slot,\n useEventCallback,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselProps, CarouselState } from './Carousel.types';\nimport type { CarouselContextValue } from '../CarouselContext.types';\nimport { useEmblaCarousel } from '../useEmblaCarousel';\nimport { useAnnounce } from '@fluentui/react-shared-contexts';\n\n/**\n * Create the state required to render Carousel.\n *\n * The returned state can be modified with hooks such as useCarouselStyles_unstable,\n * before being passed to renderCarousel_unstable.\n *\n * @param props - props from this instance of Carousel\n * @param ref - reference to root HTMLDivElement of Carousel\n */\nexport function useCarousel_unstable(props: CarouselProps, ref: React.Ref<HTMLDivElement>): CarouselState {\n 'use no memo';\n\n const {\n align = 'center',\n circular = false,\n onActiveIndexChange,\n groupSize = 'auto',\n draggable = false,\n whitespace = false,\n announcement,\n motion = 'slide',\n } = props;\n\n const { dir } = useFluent();\n const { activeIndex, carouselApi, containerRef, subscribeForValues, enableAutoplay, resetAutoplay } =\n useEmblaCarousel({\n align,\n direction: dir,\n loop: circular,\n slidesToScroll: groupSize,\n defaultActiveIndex: props.defaultActiveIndex,\n activeIndex: props.activeIndex,\n watchDrag: draggable,\n containScroll: whitespace ? false : 'keepSnaps',\n motion,\n onDragIndexChange: onActiveIndexChange,\n });\n\n const selectPageByElement: CarouselContextValue['selectPageByElement'] = useEventCallback((event, element, jump) => {\n const foundIndex = carouselApi.scrollToElement(element, jump);\n onActiveIndexChange?.(event, { event, type: 'focus', index: foundIndex });\n\n return foundIndex;\n });\n\n const selectPageByIndex: CarouselContextValue['selectPageByIndex'] = useEventCallback((event, index, jump) => {\n carouselApi.scrollToIndex(index, jump);\n\n onActiveIndexChange?.(event, { event, type: 'click', index });\n });\n\n const selectPageByDirection: CarouselContextValue['selectPageByDirection'] = useEventCallback((event, direction) => {\n const nextPageIndex = carouselApi.scrollInDirection(direction);\n onActiveIndexChange?.(event, { event, type: 'click', index: nextPageIndex });\n\n return nextPageIndex;\n });\n\n const mergedRefs = useMergedRefs(ref, containerRef);\n\n // Announce carousel updates\n const announcementTextRef = React.useRef<string>('');\n const totalNavLength = React.useRef<number>(0);\n const navGroupRef = React.useRef<number[][]>([]);\n\n const { announce } = useAnnounce();\n\n const updateAnnouncement = useEventCallback(() => {\n if (totalNavLength.current <= 0 || !announcement) {\n // Ignore announcements until slides discovered\n return;\n }\n\n const announcementText = announcement(activeIndex, totalNavLength.current, navGroupRef.current);\n\n if (announcementText !== announcementTextRef.current) {\n announcementTextRef.current = announcementText;\n announce(announcementText, { polite: true });\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n // Subscribe to any non-index carousel state changes\n return subscribeForValues(data => {\n if (totalNavLength.current <= 0 && data.navItemsCount > 0 && announcement) {\n const announcementText = announcement(data.activeIndex, data.navItemsCount, data.groupIndexList);\n // Initialize our string to prevent updateAnnouncement from reading an initial load\n announcementTextRef.current = announcementText;\n }\n totalNavLength.current = data.navItemsCount;\n navGroupRef.current = data.groupIndexList;\n updateAnnouncement();\n });\n }, [subscribeForValues, updateAnnouncement, announcement]);\n\n useIsomorphicLayoutEffect(() => {\n updateAnnouncement();\n }, [activeIndex, updateAnnouncement]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: mergedRefs,\n role: 'region',\n ...props,\n }),\n { elementType: 'div' },\n ),\n\n activeIndex,\n circular,\n containerRef: mergedRefs,\n selectPageByElement,\n selectPageByDirection,\n selectPageByIndex,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["useCarousel_unstable","props","ref","align","circular","onActiveIndexChange","groupSize","draggable","whitespace","announcement","motion","dir","useFluent","activeIndex","carouselApi","containerRef","subscribeForValues","enableAutoplay","resetAutoplay","useEmblaCarousel","direction","loop","slidesToScroll","defaultActiveIndex","watchDrag","containScroll","onDragIndexChange","selectPageByElement","useEventCallback","event","element","jump","foundIndex","scrollToElement","type","index","selectPageByIndex","scrollToIndex","selectPageByDirection","nextPageIndex","scrollInDirection","mergedRefs","useMergedRefs","announcementTextRef","React","useRef","totalNavLength","navGroupRef","announce","useAnnounce","updateAnnouncement","current","announcementText","polite","useIsomorphicLayoutEffect","data","navItemsCount","groupIndexList","components","root","slot","always","getIntrinsicElementProps","role","elementType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAwBgBA;;;eAAAA;;;;qCAxBgC;gCAOzC;iEACgB;kCAIU;AAY1B,SAASA,qBAAqBC,KAAoB,EAAEC,GAA8B;IACvF;IAEA,MAAM,EACJC,QAAQ,QAAQ,EAChBC,WAAW,KAAK,EAChBC,mBAAmB,EACnBC,YAAY,MAAM,EAClBC,YAAY,KAAK,EACjBC,aAAa,KAAK,EAClBC,YAAY,EACZC,SAAS,OAAO,EACjB,GAAGT;IAEJ,MAAM,EAAEU,GAAG,EAAE,GAAGC,IAAAA,uCAAAA;IAChB,MAAM,EAAEC,WAAW,EAAEC,WAAW,EAAEC,YAAY,EAAEC,kBAAkB,EAAEC,cAAc,EAAEC,aAAa,EAAE,GACjGC,IAAAA,kCAAAA,EAAiB;QACfhB;QACAiB,WAAWT;QACXU,MAAMjB;QACNkB,gBAAgBhB;QAChBiB,oBAAoBtB,MAAMsB,kBAAkB;QAC5CV,aAAaZ,MAAMY,WAAW;QAC9BW,WAAWjB;QACXkB,eAAejB,aAAa,QAAQ;QACpCE;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BQ,OAAO,EAAE;YACpDR,oBAAoBQ,OAAO,GAAGC;YAC9BJ,SAASI,kBAAkB;gBAAEC,QAAQ;YAAK;QAC5C;IACF;IAEAC,IAAAA,yCAAAA,EAA0B;QACxB,oDAAoD;QACpD,OAAOtC,mBAAmBuC,CAAAA;YACxB,IAAIT,eAAeK,OAAO,IAAI,KAAKI,KAAKC,aAAa,GAAG,KAAK/C,cAAc;gBACzE,MAAM2C,mBAAmB3C,aAAa8C,KAAK1C,WAAW,EAAE0C,KAAKC,aAAa,EAAED,KAAKE,cAAc;gBAC/F,mFAAmF;gBACnFd,oBAAoBQ,OAAO,GAAGC;YAChC;YACAN,eAAeK,OAAO,GAAGI,KAAKC,aAAa;YAC3CT,YAAYI,OAAO,GAAGI,KAAKE,cAAc;YACzCP;QACF;IACF,GAAG;QAAClC;QAAoBkC;QAAoBzC;KAAa;IAEzD6C,IAAAA,yCAAAA,EAA0B;QACxBJ;IACF,GAAG;QAACrC;QAAaqC;KAAmB;IAEpC,OAAO;QACLQ,YAAY;YACVC,MAAM;QACR;QACAA,MAAMC,oBAAAA,CAAKC,MAAM,CACfC,IAAAA,wCAAAA,EAAyB,OAAO;YAC9B5D,KAAKuC;YACLsB,MAAM;YACN,GAAG9D,KAAK;QACV,IACA;YAAE+D,aAAa;QAAM;QAGvBnD;QACAT;QACAW,cAAc0B;QACdd;QACAW;QACAF;QACApB;QACAC;QACAC;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["CarouselContext.types.ts"],"sourcesContent":["import type { EventData } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselUpdateData } from '../Carousel';\n\nexport type CarouselIndexChangeData =
|
|
1
|
+
{"version":3,"sources":["CarouselContext.types.ts"],"sourcesContent":["import type { EventData } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport type { CarouselUpdateData } from '../Carousel';\n\nexport type CarouselIndexChangeData = (\n | EventData<'click', React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>>\n | EventData<'focus', React.FocusEvent>\n | EventData<'drag', PointerEvent | MouseEvent>\n) & {\n /**\n * The index to be set after event has occurred.\n */\n index: number;\n};\n\nexport type CarouselContextValue = {\n activeIndex: number;\n circular: boolean;\n selectPageByElement: (event: React.FocusEvent, element: HTMLElement, jump?: boolean) => number;\n selectPageByDirection: (\n event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>,\n direction: 'next' | 'prev',\n ) => number;\n selectPageByIndex: (\n event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>,\n value: number,\n jump?: boolean,\n ) => void;\n subscribeForValues: (listener: (data: CarouselUpdateData) => void) => () => void;\n enableAutoplay: (autoplay: boolean) => void;\n resetAutoplay: () => void;\n containerRef?: React.RefObject<HTMLDivElement>;\n};\n\n/**\n * Context shared between Carousel and its children components\n */\nexport type CarouselContextValues = {\n carousel: CarouselContextValue;\n};\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEACuB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "pointerEventPlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return pointerEventPlugin;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _Carousel = require("../Carousel");
|
|
12
|
+
function pointerEventPlugin(options) {
|
|
13
|
+
let emblaApi;
|
|
14
|
+
let pointerEvent;
|
|
15
|
+
function documentDownListener(event) {
|
|
16
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
17
|
+
if (event.target) {
|
|
18
|
+
const targetNode = event.target;
|
|
19
|
+
if (targetNode.classList.contains(_Carousel.carouselClassNames.root) || emblaApi.containerNode().contains(targetNode)) {
|
|
20
|
+
pointerEvent = event;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
targetDocument.removeEventListener('mousedown', documentDownListener);
|
|
24
|
+
targetDocument.removeEventListener('pointerdown', documentDownListener);
|
|
25
|
+
}
|
|
26
|
+
function pointerUpListener() {
|
|
27
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
28
|
+
targetDocument.addEventListener('mousedown', documentDownListener);
|
|
29
|
+
targetDocument.addEventListener('pointerdown', documentDownListener);
|
|
30
|
+
}
|
|
31
|
+
function clearPointerEvent() {
|
|
32
|
+
pointerEvent = undefined;
|
|
33
|
+
}
|
|
34
|
+
function selectListener() {
|
|
35
|
+
if (pointerEvent) {
|
|
36
|
+
var _emblaApi_selectedScrollSnap;
|
|
37
|
+
const newIndex = (_emblaApi_selectedScrollSnap = emblaApi.selectedScrollSnap()) !== null && _emblaApi_selectedScrollSnap !== void 0 ? _emblaApi_selectedScrollSnap : 0;
|
|
38
|
+
options.onSelectViaDrag(pointerEvent, newIndex);
|
|
39
|
+
clearPointerEvent();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function init(emblaApiInstance, optionsHandler) {
|
|
43
|
+
emblaApi = emblaApiInstance;
|
|
44
|
+
// Initialize the listener for first mouse/pointerDown event
|
|
45
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
46
|
+
targetDocument.addEventListener('mousedown', documentDownListener);
|
|
47
|
+
targetDocument.addEventListener('pointerdown', documentDownListener);
|
|
48
|
+
emblaApi.on('pointerUp', pointerUpListener);
|
|
49
|
+
emblaApi.on('select', selectListener);
|
|
50
|
+
// Settle is used to clear pointer in cases where active index does not change
|
|
51
|
+
emblaApi.on('settle', clearPointerEvent);
|
|
52
|
+
}
|
|
53
|
+
function destroy() {
|
|
54
|
+
const targetDocument = emblaApi.containerNode().ownerDocument;
|
|
55
|
+
targetDocument.removeEventListener('mousedown', documentDownListener);
|
|
56
|
+
targetDocument.removeEventListener('pointerdown', documentDownListener);
|
|
57
|
+
emblaApi.off('pointerUp', pointerUpListener);
|
|
58
|
+
emblaApi.off('select', selectListener);
|
|
59
|
+
emblaApi.off('settle', clearPointerEvent);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
name: 'pointerEvent',
|
|
63
|
+
options,
|
|
64
|
+
init,
|
|
65
|
+
destroy
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["pointerEvents.ts"],"sourcesContent":["import type { CreatePluginType, EmblaCarouselType, OptionsHandlerType } from 'embla-carousel';\nimport { carouselClassNames } from '../Carousel';\n\nexport type PointerEventPluginOptions = {\n onSelectViaDrag: (event: PointerEvent | MouseEvent, index: number) => void;\n};\n\nexport type PointerEventPlugin = CreatePluginType<{}, PointerEventPluginOptions>;\n\nexport function pointerEventPlugin(options: PointerEventPluginOptions): PointerEventPlugin {\n let emblaApi: EmblaCarouselType;\n let pointerEvent: PointerEvent | MouseEvent | undefined;\n\n function documentDownListener(event: PointerEvent | MouseEvent) {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n\n if (event.target) {\n const targetNode = event.target as Element;\n if (targetNode.classList.contains(carouselClassNames.root) || emblaApi.containerNode().contains(targetNode)) {\n pointerEvent = event;\n }\n }\n\n targetDocument.removeEventListener('mousedown', documentDownListener);\n targetDocument.removeEventListener('pointerdown', documentDownListener);\n }\n\n function pointerUpListener() {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n\n targetDocument.addEventListener('mousedown', documentDownListener);\n targetDocument.addEventListener('pointerdown', documentDownListener);\n }\n\n function clearPointerEvent() {\n pointerEvent = undefined;\n }\n\n function selectListener() {\n if (pointerEvent) {\n const newIndex = emblaApi.selectedScrollSnap() ?? 0;\n\n options.onSelectViaDrag(pointerEvent, newIndex);\n clearPointerEvent();\n }\n }\n\n function init(emblaApiInstance: EmblaCarouselType, optionsHandler: OptionsHandlerType): void {\n emblaApi = emblaApiInstance;\n\n // Initialize the listener for first mouse/pointerDown event\n const targetDocument = emblaApi.containerNode().ownerDocument;\n targetDocument.addEventListener('mousedown', documentDownListener);\n targetDocument.addEventListener('pointerdown', documentDownListener);\n\n emblaApi.on('pointerUp', pointerUpListener);\n emblaApi.on('select', selectListener);\n // Settle is used to clear pointer in cases where active index does not change\n emblaApi.on('settle', clearPointerEvent);\n }\n\n function destroy(): void {\n const targetDocument = emblaApi.containerNode().ownerDocument;\n targetDocument.removeEventListener('mousedown', documentDownListener);\n targetDocument.removeEventListener('pointerdown', documentDownListener);\n emblaApi.off('pointerUp', pointerUpListener);\n emblaApi.off('select', selectListener);\n emblaApi.off('settle', clearPointerEvent);\n }\n\n return {\n name: 'pointerEvent',\n options,\n init,\n destroy,\n };\n}\n"],"names":["pointerEventPlugin","options","emblaApi","pointerEvent","documentDownListener","event","targetDocument","containerNode","ownerDocument","target","targetNode","classList","contains","carouselClassNames","root","removeEventListener","pointerUpListener","addEventListener","clearPointerEvent","undefined","selectListener","newIndex","selectedScrollSnap","onSelectViaDrag","init","emblaApiInstance","optionsHandler","on","destroy","off","name"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASgBA;;;eAAAA;;;0BARmB;AAQ5B,SAASA,mBAAmBC,OAAkC;IACnE,IAAIC;IACJ,IAAIC;IAEJ,SAASC,qBAAqBC,KAAgC;QAC5D,MAAMC,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAE7D,IAAIH,MAAMI,MAAM,EAAE;YAChB,MAAMC,aAAaL,MAAMI,MAAM;YAC/B,IAAIC,WAAWC,SAAS,CAACC,QAAQ,CAACC,4BAAAA,CAAmBC,IAAI,KAAKZ,SAASK,aAAa,GAAGK,QAAQ,CAACF,aAAa;gBAC3GP,eAAeE;YACjB;QACF;QAEAC,eAAeS,mBAAmB,CAAC,aAAaX;QAChDE,eAAeS,mBAAmB,CAAC,eAAeX;IACpD;IAEA,SAASY;QACP,MAAMV,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAE7DF,eAAeW,gBAAgB,CAAC,aAAab;QAC7CE,eAAeW,gBAAgB,CAAC,eAAeb;IACjD;IAEA,SAASc;QACPf,eAAegB;IACjB;IAEA,SAASC;QACP,IAAIjB,cAAc;gBACCD;YAAjB,MAAMmB,WAAWnB,CAAAA,+BAAAA,SAASoB,kBAAkB,EAAA,MAAA,QAA3BpB,iCAAAA,KAAAA,IAAAA,+BAAiC;YAElDD,QAAQsB,eAAe,CAACpB,cAAckB;YACtCH;QACF;IACF;IAEA,SAASM,KAAKC,gBAAmC,EAAEC,cAAkC;QACnFxB,WAAWuB;QAEX,4DAA4D;QAC5D,MAAMnB,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAC7DF,eAAeW,gBAAgB,CAAC,aAAab;QAC7CE,eAAeW,gBAAgB,CAAC,eAAeb;QAE/CF,SAASyB,EAAE,CAAC,aAAaX;QACzBd,SAASyB,EAAE,CAAC,UAAUP;QACtB,8EAA8E;QAC9ElB,SAASyB,EAAE,CAAC,UAAUT;IACxB;IAEA,SAASU;QACP,MAAMtB,iBAAiBJ,SAASK,aAAa,GAAGC,aAAa;QAC7DF,eAAeS,mBAAmB,CAAC,aAAaX;QAChDE,eAAeS,mBAAmB,CAAC,eAAeX;QAClDF,SAAS2B,GAAG,CAAC,aAAab;QAC1Bd,SAAS2B,GAAG,CAAC,UAAUT;QACvBlB,SAAS2B,GAAG,CAAC,UAAUX;IACzB;IAEA,OAAO;QACLY,MAAM;QACN7B;QACAuB;QACAI;IACF;AACF"}
|
|
@@ -28,6 +28,7 @@ const _useCarouselCardStylesstyles = require("./CarouselCard/useCarouselCardStyl
|
|
|
28
28
|
const _useCarouselSliderStylesstyles = require("./CarouselSlider/useCarouselSliderStyles.styles");
|
|
29
29
|
const _emblacarouselautoplay = /*#__PURE__*/ _interop_require_default._(require("embla-carousel-autoplay"));
|
|
30
30
|
const _emblacarouselfade = /*#__PURE__*/ _interop_require_default._(require("embla-carousel-fade"));
|
|
31
|
+
const _pointerEvents = require("./pointerEvents");
|
|
31
32
|
const sliderClassname = `.${_useCarouselSliderStylesstyles.carouselSliderClassNames.root}`;
|
|
32
33
|
const DEFAULT_EMBLA_OPTIONS = {
|
|
33
34
|
containScroll: 'trimSnaps',
|
|
@@ -50,12 +51,19 @@ function setTabsterDefault(element, isDefault) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
function useEmblaCarousel(options) {
|
|
53
|
-
const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion } = options;
|
|
54
|
+
const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion, onDragIndexChange } = options;
|
|
54
55
|
const [activeIndex, setActiveIndex] = (0, _reactutilities.useControllableState)({
|
|
55
56
|
defaultState: options.defaultActiveIndex,
|
|
56
57
|
state: options.activeIndex,
|
|
57
58
|
initialState: 0
|
|
58
59
|
});
|
|
60
|
+
const onDragEvent = (0, _reactutilities.useEventCallback)((event, index)=>{
|
|
61
|
+
onDragIndexChange === null || onDragIndexChange === void 0 ? void 0 : onDragIndexChange(event, {
|
|
62
|
+
event,
|
|
63
|
+
type: 'drag',
|
|
64
|
+
index
|
|
65
|
+
});
|
|
66
|
+
});
|
|
59
67
|
const emblaOptions = _react.useRef({
|
|
60
68
|
align,
|
|
61
69
|
direction,
|
|
@@ -102,9 +110,16 @@ function useEmblaCarousel(options) {
|
|
|
102
110
|
if (motion === 'fade') {
|
|
103
111
|
plugins.push((0, _emblacarouselfade.default)());
|
|
104
112
|
}
|
|
113
|
+
if (watchDrag) {
|
|
114
|
+
plugins.push((0, _pointerEvents.pointerEventPlugin)({
|
|
115
|
+
onSelectViaDrag: onDragEvent
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
105
118
|
return plugins;
|
|
106
119
|
}, [
|
|
107
|
-
motion
|
|
120
|
+
motion,
|
|
121
|
+
onDragEvent,
|
|
122
|
+
watchDrag
|
|
108
123
|
]);
|
|
109
124
|
// Listeners contains callbacks for UI elements that may require state update based on embla changes
|
|
110
125
|
const listeners = _react.useRef(new Set());
|
|
@@ -223,7 +238,9 @@ function useEmblaCarousel(options) {
|
|
|
223
238
|
_react.useEffect(()=>{
|
|
224
239
|
var _emblaApi_current;
|
|
225
240
|
var _emblaApi_current_selectedScrollSnap;
|
|
241
|
+
// Scroll to controlled values on update
|
|
226
242
|
const currentActiveIndex = (_emblaApi_current_selectedScrollSnap = (_emblaApi_current = emblaApi.current) === null || _emblaApi_current === void 0 ? void 0 : _emblaApi_current.selectedScrollSnap()) !== null && _emblaApi_current_selectedScrollSnap !== void 0 ? _emblaApi_current_selectedScrollSnap : 0;
|
|
243
|
+
emblaOptions.current.startIndex = activeIndex;
|
|
227
244
|
if (activeIndex !== currentActiveIndex) {
|
|
228
245
|
var _emblaApi_current1;
|
|
229
246
|
(_emblaApi_current1 = emblaApi.current) === null || _emblaApi_current1 === void 0 ? void 0 : _emblaApi_current1.scrollTo(activeIndex);
|
|
@@ -235,6 +252,7 @@ function useEmblaCarousel(options) {
|
|
|
235
252
|
var _emblaApi_current;
|
|
236
253
|
const plugins = getPlugins();
|
|
237
254
|
emblaOptions.current = {
|
|
255
|
+
startIndex: emblaOptions.current.startIndex,
|
|
238
256
|
align,
|
|
239
257
|
direction,
|
|
240
258
|
loop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEmblaCarousel.ts"],"sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport EmblaCarousel, { EmblaPluginType, type EmblaCarouselType, type EmblaOptionsType } from 'embla-carousel';\nimport * as React from 'react';\n\nimport { carouselCardClassNames } from './CarouselCard/useCarouselCardStyles.styles';\nimport { carouselSliderClassNames } from './CarouselSlider/useCarouselSliderStyles.styles';\nimport { CarouselMotion, CarouselUpdateData, CarouselVisibilityEventDetail } from '../Carousel';\nimport Autoplay from 'embla-carousel-autoplay';\nimport Fade from 'embla-carousel-fade';\n\nconst sliderClassname = `.${carouselSliderClassNames.root}`;\n\nconst DEFAULT_EMBLA_OPTIONS: EmblaOptionsType = {\n containScroll: 'trimSnaps',\n inViewThreshold: 0.99,\n watchDrag: false,\n skipSnaps: true,\n\n container: sliderClassname,\n slides: `.${carouselCardClassNames.root}`,\n};\n\nexport const EMBLA_VISIBILITY_EVENT = 'embla:visibilitychange';\n\nexport function setTabsterDefault(element: Element, isDefault: boolean) {\n const tabsterAttr = element.getAttribute('data-tabster');\n\n if (tabsterAttr) {\n const tabsterAttributes = JSON.parse(tabsterAttr);\n if (tabsterAttributes.focusable) {\n // If tabster.focusable isn't present, we will ignore.\n tabsterAttributes.focusable.isDefault = isDefault;\n element.setAttribute('data-tabster', JSON.stringify(tabsterAttributes));\n }\n }\n}\n\nexport function useEmblaCarousel(\n options: Pick<EmblaOptionsType, 'align' | 'direction' | 'loop' | 'slidesToScroll' | 'watchDrag' | 'containScroll'> & {\n defaultActiveIndex: number | undefined;\n activeIndex: number | undefined;\n motion?: CarouselMotion;\n },\n) {\n const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion } = options;\n const [activeIndex, setActiveIndex] = useControllableState({\n defaultState: options.defaultActiveIndex,\n state: options.activeIndex,\n initialState: 0,\n });\n\n const emblaOptions = React.useRef<EmblaOptionsType>({\n align,\n direction,\n loop,\n slidesToScroll,\n startIndex: activeIndex,\n watchDrag,\n containScroll,\n });\n\n const emblaApi = React.useRef<EmblaCarouselType | null>(null);\n const autoplayRef = React.useRef<boolean>(false);\n\n const resetAutoplay = React.useCallback(() => {\n emblaApi.current?.plugins().autoplay.reset();\n }, []);\n\n /* Our autoplay button, which is required by standards for autoplay to be enabled, will handle controlled state */\n const enableAutoplay = React.useCallback(\n (autoplay: boolean) => {\n autoplayRef.current = autoplay;\n if (autoplay) {\n emblaApi.current?.plugins().autoplay.play();\n // Reset after play to ensure timing and any focus/mouse pause state is reset.\n resetAutoplay();\n } else {\n emblaApi.current?.plugins().autoplay.stop();\n }\n },\n [resetAutoplay],\n );\n\n const getPlugins = React.useCallback(() => {\n const plugins: EmblaPluginType[] = [\n Autoplay({\n playOnInit: autoplayRef.current,\n stopOnInteraction: !autoplayRef.current,\n stopOnMouseEnter: true,\n stopOnFocusIn: true,\n rootNode: (emblaRoot: HTMLElement) => {\n return emblaRoot.querySelector(sliderClassname) ?? emblaRoot;\n },\n }),\n ];\n\n // Optionally add Fade plugin\n if (motion === 'fade') {\n plugins.push(Fade());\n }\n\n return plugins;\n }, [motion]);\n\n // Listeners contains callbacks for UI elements that may require state update based on embla changes\n const listeners = React.useRef(new Set<(data: CarouselUpdateData) => void>());\n const subscribeForValues = React.useCallback((listener: (data: CarouselUpdateData) => void) => {\n listeners.current.add(listener);\n\n return () => {\n listeners.current.delete(listener);\n };\n }, []);\n\n const containerRef: React.RefObject<HTMLDivElement> = React.useMemo(() => {\n let currentElement: HTMLDivElement | null = null;\n\n const handleIndexChange = () => {\n const newIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n const slides = emblaApi.current?.slideNodes();\n const actualIndex = emblaApi.current?.internalEngine().slideRegistry[newIndex][0] ?? 0;\n // We set the active or first index of group on-screen as the selected tabster index\n slides?.forEach((slide, slideIndex) => {\n setTabsterDefault(slide, slideIndex === actualIndex);\n });\n setActiveIndex(newIndex);\n };\n const handleReinit = () => {\n const nodes: HTMLElement[] = emblaApi.current?.slideNodes() ?? [];\n const groupIndexList: number[][] = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const navItemsCount = groupIndexList.length > 0 ? groupIndexList.length : nodes.length;\n\n const data: CarouselUpdateData = {\n navItemsCount,\n activeIndex: emblaApi.current?.selectedScrollSnap() ?? 0,\n groupIndexList,\n slideNodes: nodes,\n };\n\n for (const listener of listeners.current) {\n listener(data);\n }\n };\n const handleVisibilityChange = () => {\n const cardElements = emblaApi.current?.slideNodes();\n const visibleIndexes = emblaApi.current?.slidesInView() ?? [];\n\n cardElements?.forEach((cardElement, index) => {\n cardElement.dispatchEvent(\n new CustomEvent<CarouselVisibilityEventDetail>(EMBLA_VISIBILITY_EVENT, {\n bubbles: false,\n detail: { isVisible: visibleIndexes.includes(index) },\n }),\n );\n });\n };\n\n const plugins = getPlugins();\n\n return {\n set current(newElement: HTMLDivElement | null) {\n if (currentElement) {\n emblaApi.current?.off('slidesInView', handleVisibilityChange);\n emblaApi.current?.off('select', handleIndexChange);\n emblaApi.current?.off('reInit', handleReinit);\n emblaApi.current?.destroy();\n }\n\n if (newElement) {\n currentElement = newElement;\n emblaApi.current = EmblaCarousel(\n newElement,\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n\n emblaApi.current?.on('reInit', handleReinit);\n emblaApi.current?.on('slidesInView', handleVisibilityChange);\n emblaApi.current?.on('select', handleIndexChange);\n }\n },\n };\n }, [getPlugins, setActiveIndex]);\n\n const carouselApi = React.useMemo(\n () => ({\n scrollToElement: (element: HTMLElement, jump?: boolean) => {\n const cardElements = emblaApi.current?.slideNodes();\n const groupIndexList = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const cardIndex = cardElements?.indexOf(element) ?? 0;\n const groupIndex = groupIndexList.findIndex(group => {\n return group.includes(cardIndex);\n });\n const indexFocus = groupIndex ?? cardIndex;\n emblaApi.current?.scrollTo(indexFocus, jump);\n\n return indexFocus;\n },\n scrollToIndex: (index: number, jump?: boolean) => {\n emblaApi.current?.scrollTo(index, jump);\n },\n scrollInDirection: (dir: 'prev' | 'next') => {\n if (dir === 'prev') {\n emblaApi.current?.scrollPrev();\n } else {\n emblaApi.current?.scrollNext();\n }\n\n return emblaApi.current?.selectedScrollSnap() ?? 0;\n },\n }),\n [],\n );\n\n React.useEffect(() => {\n const currentActiveIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n\n if (activeIndex !== currentActiveIndex) {\n emblaApi.current?.scrollTo(activeIndex);\n }\n }, [activeIndex]);\n\n React.useEffect(() => {\n const plugins = getPlugins();\n\n emblaOptions.current = { align, direction, loop, slidesToScroll, watchDrag, containScroll };\n emblaApi.current?.reInit(\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n }, [align, direction, loop, slidesToScroll, watchDrag, containScroll, getPlugins]);\n\n return {\n activeIndex,\n carouselApi,\n containerRef,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["EMBLA_VISIBILITY_EVENT","setTabsterDefault","useEmblaCarousel","sliderClassname","carouselSliderClassNames","root","DEFAULT_EMBLA_OPTIONS","containScroll","inViewThreshold","watchDrag","skipSnaps","container","slides","carouselCardClassNames","element","isDefault","tabsterAttr","getAttribute","tabsterAttributes","JSON","parse","focusable","setAttribute","stringify","options","align","direction","loop","slidesToScroll","motion","activeIndex","setActiveIndex","useControllableState","defaultState","defaultActiveIndex","state","initialState","emblaOptions","React","useRef","startIndex","emblaApi","autoplayRef","resetAutoplay","useCallback","current","plugins","autoplay","reset","enableAutoplay","play","stop","getPlugins","Autoplay","playOnInit","stopOnInteraction","stopOnMouseEnter","stopOnFocusIn","rootNode","emblaRoot","querySelector","push","Fade","listeners","Set","subscribeForValues","listener","add","delete","containerRef","useMemo","currentElement","handleIndexChange","newIndex","selectedScrollSnap","slideNodes","actualIndex","internalEngine","slideRegistry","forEach","slide","slideIndex","handleReinit","nodes","groupIndexList","navItemsCount","length","data","handleVisibilityChange","cardElements","visibleIndexes","slidesInView","cardElement","index","dispatchEvent","CustomEvent","bubbles","detail","isVisible","includes","newElement","off","destroy","EmblaCarousel","on","carouselApi","scrollToElement","jump","cardIndex","indexOf","groupIndex","findIndex","group","indexFocus","scrollTo","scrollToIndex","scrollInDirection","dir","scrollPrev","scrollNext","useEffect","currentActiveIndex","reInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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IAAAA,KAAAA,IAAAA,kBAAkBiF,MAAM,CACtB;YACE,GAAGpH,qBAAqB;YACxB,GAAG+B,aAAaQ,OAAO;QACzB,GACAC;IAEJ,GAAG;QAACrB;QAAOC;QAAWC;QAAMC;QAAgBnB;QAAWF;QAAe6C;KAAW;IAEjF,OAAO;QACLtB;QACA2E;QACApC;QACAJ;QACAhB;QACAN;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["useEmblaCarousel.ts"],"sourcesContent":["import { type EventHandler, useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport EmblaCarousel, { EmblaPluginType, type EmblaCarouselType, type EmblaOptionsType } from 'embla-carousel';\nimport * as React from 'react';\n\nimport { carouselCardClassNames } from './CarouselCard/useCarouselCardStyles.styles';\nimport { carouselSliderClassNames } from './CarouselSlider/useCarouselSliderStyles.styles';\nimport { CarouselMotion, CarouselUpdateData, CarouselVisibilityEventDetail } from '../Carousel';\nimport Autoplay from 'embla-carousel-autoplay';\nimport Fade from 'embla-carousel-fade';\nimport { pointerEventPlugin } from './pointerEvents';\nimport type { CarouselIndexChangeData } from './CarouselContext.types';\n\nconst sliderClassname = `.${carouselSliderClassNames.root}`;\n\nconst DEFAULT_EMBLA_OPTIONS: EmblaOptionsType = {\n containScroll: 'trimSnaps',\n inViewThreshold: 0.99,\n watchDrag: false,\n skipSnaps: true,\n\n container: sliderClassname,\n slides: `.${carouselCardClassNames.root}`,\n};\n\nexport const EMBLA_VISIBILITY_EVENT = 'embla:visibilitychange';\n\nexport function setTabsterDefault(element: Element, isDefault: boolean) {\n const tabsterAttr = element.getAttribute('data-tabster');\n\n if (tabsterAttr) {\n const tabsterAttributes = JSON.parse(tabsterAttr);\n if (tabsterAttributes.focusable) {\n // If tabster.focusable isn't present, we will ignore.\n tabsterAttributes.focusable.isDefault = isDefault;\n element.setAttribute('data-tabster', JSON.stringify(tabsterAttributes));\n }\n }\n}\n\nexport function useEmblaCarousel(\n options: Pick<EmblaOptionsType, 'align' | 'direction' | 'loop' | 'slidesToScroll' | 'watchDrag' | 'containScroll'> & {\n defaultActiveIndex: number | undefined;\n activeIndex: number | undefined;\n motion?: CarouselMotion;\n onDragIndexChange?: EventHandler<CarouselIndexChangeData>;\n },\n) {\n const { align, direction, loop, slidesToScroll, watchDrag, containScroll, motion, onDragIndexChange } = options;\n const [activeIndex, setActiveIndex] = useControllableState({\n defaultState: options.defaultActiveIndex,\n state: options.activeIndex,\n initialState: 0,\n });\n\n const onDragEvent = useEventCallback((event: PointerEvent | MouseEvent, index: number) => {\n onDragIndexChange?.(event, { event, type: 'drag', index });\n });\n\n const emblaOptions = React.useRef<EmblaOptionsType>({\n align,\n direction,\n loop,\n slidesToScroll,\n startIndex: activeIndex,\n watchDrag,\n containScroll,\n });\n\n const emblaApi = React.useRef<EmblaCarouselType | null>(null);\n const autoplayRef = React.useRef<boolean>(false);\n\n const resetAutoplay = React.useCallback(() => {\n emblaApi.current?.plugins().autoplay.reset();\n }, []);\n\n /* Our autoplay button, which is required by standards for autoplay to be enabled, will handle controlled state */\n const enableAutoplay = React.useCallback(\n (autoplay: boolean) => {\n autoplayRef.current = autoplay;\n if (autoplay) {\n emblaApi.current?.plugins().autoplay.play();\n // Reset after play to ensure timing and any focus/mouse pause state is reset.\n resetAutoplay();\n } else {\n emblaApi.current?.plugins().autoplay.stop();\n }\n },\n [resetAutoplay],\n );\n\n const getPlugins = React.useCallback(() => {\n const plugins: EmblaPluginType[] = [\n Autoplay({\n playOnInit: autoplayRef.current,\n stopOnInteraction: !autoplayRef.current,\n stopOnMouseEnter: true,\n stopOnFocusIn: true,\n rootNode: (emblaRoot: HTMLElement) => {\n return emblaRoot.querySelector(sliderClassname) ?? emblaRoot;\n },\n }),\n ];\n\n // Optionally add Fade plugin\n if (motion === 'fade') {\n plugins.push(Fade());\n }\n\n if (watchDrag) {\n plugins.push(\n pointerEventPlugin({\n onSelectViaDrag: onDragEvent,\n }),\n );\n }\n\n return plugins;\n }, [motion, onDragEvent, watchDrag]);\n\n // Listeners contains callbacks for UI elements that may require state update based on embla changes\n const listeners = React.useRef(new Set<(data: CarouselUpdateData) => void>());\n const subscribeForValues = React.useCallback((listener: (data: CarouselUpdateData) => void) => {\n listeners.current.add(listener);\n\n return () => {\n listeners.current.delete(listener);\n };\n }, []);\n\n const containerRef: React.RefObject<HTMLDivElement> = React.useMemo(() => {\n let currentElement: HTMLDivElement | null = null;\n\n const handleIndexChange = () => {\n const newIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n const slides = emblaApi.current?.slideNodes();\n const actualIndex = emblaApi.current?.internalEngine().slideRegistry[newIndex][0] ?? 0;\n\n // We set the active or first index of group on-screen as the selected tabster index\n slides?.forEach((slide, slideIndex) => {\n setTabsterDefault(slide, slideIndex === actualIndex);\n });\n setActiveIndex(newIndex);\n };\n const handleReinit = () => {\n const nodes: HTMLElement[] = emblaApi.current?.slideNodes() ?? [];\n const groupIndexList: number[][] = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const navItemsCount = groupIndexList.length > 0 ? groupIndexList.length : nodes.length;\n\n const data: CarouselUpdateData = {\n navItemsCount,\n activeIndex: emblaApi.current?.selectedScrollSnap() ?? 0,\n groupIndexList,\n slideNodes: nodes,\n };\n\n for (const listener of listeners.current) {\n listener(data);\n }\n };\n const handleVisibilityChange = () => {\n const cardElements = emblaApi.current?.slideNodes();\n const visibleIndexes = emblaApi.current?.slidesInView() ?? [];\n\n cardElements?.forEach((cardElement, index) => {\n cardElement.dispatchEvent(\n new CustomEvent<CarouselVisibilityEventDetail>(EMBLA_VISIBILITY_EVENT, {\n bubbles: false,\n detail: { isVisible: visibleIndexes.includes(index) },\n }),\n );\n });\n };\n\n const plugins = getPlugins();\n\n return {\n set current(newElement: HTMLDivElement | null) {\n if (currentElement) {\n emblaApi.current?.off('slidesInView', handleVisibilityChange);\n emblaApi.current?.off('select', handleIndexChange);\n emblaApi.current?.off('reInit', handleReinit);\n emblaApi.current?.destroy();\n }\n\n if (newElement) {\n currentElement = newElement;\n emblaApi.current = EmblaCarousel(\n newElement,\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n\n emblaApi.current?.on('reInit', handleReinit);\n emblaApi.current?.on('slidesInView', handleVisibilityChange);\n emblaApi.current?.on('select', handleIndexChange);\n }\n },\n };\n }, [getPlugins, setActiveIndex]);\n\n const carouselApi = React.useMemo(\n () => ({\n scrollToElement: (element: HTMLElement, jump?: boolean) => {\n const cardElements = emblaApi.current?.slideNodes();\n const groupIndexList = emblaApi.current?.internalEngine().slideRegistry ?? [];\n const cardIndex = cardElements?.indexOf(element) ?? 0;\n const groupIndex = groupIndexList.findIndex(group => {\n return group.includes(cardIndex);\n });\n const indexFocus = groupIndex ?? cardIndex;\n emblaApi.current?.scrollTo(indexFocus, jump);\n\n return indexFocus;\n },\n scrollToIndex: (index: number, jump?: boolean) => {\n emblaApi.current?.scrollTo(index, jump);\n },\n scrollInDirection: (dir: 'prev' | 'next') => {\n if (dir === 'prev') {\n emblaApi.current?.scrollPrev();\n } else {\n emblaApi.current?.scrollNext();\n }\n\n return emblaApi.current?.selectedScrollSnap() ?? 0;\n },\n }),\n [],\n );\n\n React.useEffect(() => {\n // Scroll to controlled values on update\n const currentActiveIndex = emblaApi.current?.selectedScrollSnap() ?? 0;\n emblaOptions.current.startIndex = activeIndex;\n if (activeIndex !== currentActiveIndex) {\n emblaApi.current?.scrollTo(activeIndex);\n }\n }, [activeIndex]);\n\n React.useEffect(() => {\n const plugins = getPlugins();\n\n emblaOptions.current = {\n startIndex: emblaOptions.current.startIndex,\n align,\n direction,\n loop,\n slidesToScroll,\n watchDrag,\n containScroll,\n };\n emblaApi.current?.reInit(\n {\n ...DEFAULT_EMBLA_OPTIONS,\n ...emblaOptions.current,\n },\n plugins,\n );\n }, [align, direction, loop, slidesToScroll, watchDrag, containScroll, getPlugins]);\n\n return {\n activeIndex,\n carouselApi,\n containerRef,\n subscribeForValues,\n enableAutoplay,\n resetAutoplay,\n };\n}\n"],"names":["EMBLA_VISIBILITY_EVENT","setTabsterDefault","useEmblaCarousel","sliderClassname","carouselSliderClassNames","root","DEFAULT_EMBLA_OPTIONS","containScroll","inViewThreshold","watchDrag","skipSnaps","container","slides","carouselCardClassNames","element","isDefault","tabsterAttr","getAttribute","tabsterAttributes","JSON","parse","focusable","setAttribute","stringify","options","align","direction","loop","slidesToScroll","motion","onDragIndexChange","activeIndex","setActiveIndex","useControllableState","defaultState","defaultActiveIndex","state","initialState","onDragEvent","useEventCallback","event","index","type","emblaOptions","React","useRef","startIndex","emblaApi","autoplayRef","resetAutoplay","useCallback","current","plugins","autoplay","reset","enableAutoplay","play","stop","getPlugins","Autoplay","playOnInit","stopOnInteraction","stopOnMouseEnter","stopOnFocusIn","rootNode","emblaRoot","querySelector","push","Fade","pointerEventPlugin","onSelectViaDrag","listeners","Set","subscribeForValues","listener","add","delete","containerRef","useMemo","currentElement","handleIndexChange","newIndex","selectedScrollSnap","slideNodes","actualIndex","internalEngine","slideRegistry","forEach","slide","slideIndex","handleReinit","nodes","groupIndexList","navItemsCount","length","data","handleVisibilityChange","cardElements","visibleIndexes","slidesInView","cardElement","dispatchEvent","CustomEvent","bubbles","detail","isVisible","includes","newElement","off","destroy","EmblaCarousel","on","carouselApi","scrollToElement","jump","cardIndex","indexOf","groupIndex","findIndex","group","indexFocus","scrollTo","scrollToIndex","scrollInDirection","dir","scrollPrev","scrollNext","useEffect","currentActiveIndex","reInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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PA,MAAO,QAAhBJ,uBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,mBAAkB0E,QAAQ,CAAC1F;QAC7B;IACF,GAAG;QAACA;KAAY;IAEhBa,OAAMmF,SAAS,CAAC;YAYdhF;QAXA,MAAMK,UAAUM;QAEhBf,aAAaQ,OAAO,GAAG;YACrBL,YAAYH,aAAaQ,OAAO,CAACL,UAAU;YAC3CrB;YACAC;YACAC;YACAC;YACAnB;YACAF;QACF;QACAwC,CAAAA,oBAAAA,SAASI,OAAO,AAAPA,MAAO,QAAhBJ,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkBkF,MAAM,CACtB;YACE,GAAG3H,qBAAqB;YACxB,GAAGqC,aAAaQ,OAAO;QACzB,GACAC;IAEJ,GAAG;QAAC3B;QAAOC;QAAWC;QAAMC;QAAgBnB;QAAWF;QAAemD;KAAW;IAEjF,OAAO;QACL3B;QACAiF;QACAnC;QACAJ;QACAlB;QACAN;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-carousel",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20241029-0406.1",
|
|
4
4
|
"description": "A composable carousel component that enables pagination with minimal rerenders",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@fluentui/eslint-plugin": "*",
|
|
32
|
-
"@fluentui/react-conformance": "0.0.0-nightly-
|
|
33
|
-
"@fluentui/react-conformance-griffel": "0.0.0-nightly-
|
|
32
|
+
"@fluentui/react-conformance": "0.0.0-nightly-20241029-0406.1",
|
|
33
|
+
"@fluentui/react-conformance-griffel": "0.0.0-nightly-20241029-0406.1",
|
|
34
34
|
"@fluentui/scripts-api-extractor": "*",
|
|
35
35
|
"@fluentui/scripts-tasks": "*"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fluentui/react-aria": "0.0.0-nightly-
|
|
39
|
-
"@fluentui/react-button": "0.0.0-nightly-
|
|
40
|
-
"@fluentui/react-context-selector": "0.0.0-nightly-
|
|
38
|
+
"@fluentui/react-aria": "0.0.0-nightly-20241029-0406.1",
|
|
39
|
+
"@fluentui/react-button": "0.0.0-nightly-20241029-0406.1",
|
|
40
|
+
"@fluentui/react-context-selector": "0.0.0-nightly-20241029-0406.1",
|
|
41
41
|
"@fluentui/react-icons": "^2.0.245",
|
|
42
|
-
"@fluentui/react-jsx-runtime": "0.0.0-nightly-
|
|
43
|
-
"@fluentui/react-shared-contexts": "0.0.0-nightly-
|
|
44
|
-
"@fluentui/react-tabster": "0.0.0-nightly-
|
|
45
|
-
"@fluentui/react-theme": "0.0.0-nightly-
|
|
46
|
-
"@fluentui/react-utilities": "0.0.0-nightly-
|
|
42
|
+
"@fluentui/react-jsx-runtime": "0.0.0-nightly-20241029-0406.1",
|
|
43
|
+
"@fluentui/react-shared-contexts": "0.0.0-nightly-20241029-0406.1",
|
|
44
|
+
"@fluentui/react-tabster": "0.0.0-nightly-20241029-0406.1",
|
|
45
|
+
"@fluentui/react-theme": "0.0.0-nightly-20241029-0406.1",
|
|
46
|
+
"@fluentui/react-utilities": "0.0.0-nightly-20241029-0406.1",
|
|
47
47
|
"@griffel/react": "^1.5.22",
|
|
48
48
|
"@swc/helpers": "^0.5.1",
|
|
49
49
|
"embla-carousel": "^8.3.0",
|