Private
Public Access
1
0

feat: Fluent UI Outlook Lite + connections mockup

This commit is contained in:
2026-04-14 18:52:25 +00:00
parent 1199eff6c3
commit dfa4010406
34820 changed files with 1003813 additions and 205 deletions

View File

@@ -0,0 +1,18 @@
export { useArrowNavigationGroup } from './useArrowNavigationGroup';
export { useFocusableGroup } from './useFocusableGroup';
export { useFocusFinders } from './useFocusFinders';
export { useFocusVisible } from './useFocusVisible';
export { useFocusWithin } from './useFocusWithin';
export { useKeyboardNavAttribute } from './useKeyboardNavAttribute';
export { useOnKeyboardNavigationChange } from './useOnKeyboardNavigationChange';
export { useDangerousNeverHidden_unstable, useModalAttributes } from './useModalAttributes';
export { useTabsterAttributes } from './useTabsterAttributes';
export { useObservedElement } from './useObservedElement';
export { useMergedTabsterAttributes_unstable } from './useMergeTabsterAttributes';
export { useFocusObserved } from './useFocusObserved';
export { useRestoreFocusSource, useRestoreFocusTarget } from './useRestoreFocus';
export { useUncontrolledFocus } from './useUncontrolledFocus';
export { useIsNavigatingWithKeyboard } from './useIsNavigatingWithKeyboard';
export { useSetKeyboardNavigation } from './useSetKeyboardNavigation';
export { useFocusedElementChange } from './useFocusedElementChange';
export { useActivateModal } from './useActivateModal';

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/index.ts"],"sourcesContent":["export type { UseArrowNavigationGroupOptions } from './useArrowNavigationGroup';\nexport { useArrowNavigationGroup } from './useArrowNavigationGroup';\nexport type { UseFocusableGroupOptions } from './useFocusableGroup';\nexport { useFocusableGroup } from './useFocusableGroup';\nexport { useFocusFinders } from './useFocusFinders';\nexport { useFocusVisible } from './useFocusVisible';\nexport { useFocusWithin } from './useFocusWithin';\nexport { useKeyboardNavAttribute } from './useKeyboardNavAttribute';\nexport { useOnKeyboardNavigationChange } from './useOnKeyboardNavigationChange';\nexport type { UseModalAttributesOptions } from './useModalAttributes';\nexport { useDangerousNeverHidden_unstable, useModalAttributes } from './useModalAttributes';\nexport { useTabsterAttributes } from './useTabsterAttributes';\nexport { useObservedElement } from './useObservedElement';\nexport { useMergedTabsterAttributes_unstable } from './useMergeTabsterAttributes';\nexport { useFocusObserved } from './useFocusObserved';\nexport { useRestoreFocusSource, useRestoreFocusTarget } from './useRestoreFocus';\nexport { useUncontrolledFocus } from './useUncontrolledFocus';\nexport { useIsNavigatingWithKeyboard } from './useIsNavigatingWithKeyboard';\nexport { useSetKeyboardNavigation } from './useSetKeyboardNavigation';\nexport { useFocusedElementChange } from './useFocusedElementChange';\nexport { useActivateModal } from './useActivateModal';\n"],"names":["useArrowNavigationGroup","useFocusableGroup","useFocusFinders","useFocusVisible","useFocusWithin","useKeyboardNavAttribute","useOnKeyboardNavigationChange","useDangerousNeverHidden_unstable","useModalAttributes","useTabsterAttributes","useObservedElement","useMergedTabsterAttributes_unstable","useFocusObserved","useRestoreFocusSource","useRestoreFocusTarget","useUncontrolledFocus","useIsNavigatingWithKeyboard","useSetKeyboardNavigation","useFocusedElementChange","useActivateModal"],"mappings":"AACA,SAASA,uBAAuB,QAAQ,4BAA4B;AAEpE,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,6BAA6B,QAAQ,kCAAkC;AAEhF,SAASC,gCAAgC,EAAEC,kBAAkB,QAAQ,uBAAuB;AAC5F,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,mCAAmC,QAAQ,8BAA8B;AAClF,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,oBAAoB;AACjF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,2BAA2B,QAAQ,gCAAgC;AAC5E,SAASC,wBAAwB,QAAQ,6BAA6B;AACtE,SAASC,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,gBAAgB,QAAQ,qBAAqB"}

View File

@@ -0,0 +1,25 @@
'use client';
import * as React from 'react';
import { getModalizer } from 'tabster';
import { useTimeout } from '@fluentui/react-utilities';
import { useTabster } from './useTabster';
/**
* Returns a function that activates a modal by element from the modal or modal container.
*/ export function useActivateModal() {
const modalizerRefAPI = useTabster(getModalizer);
const [setActivateModalTimeout] = useTimeout();
const activateModal = React.useCallback((elementFromModal)=>{
// We call the actual activation function on the next tick, because with the typical use case,
// the hook will be called on the same tick when other Tabster attributes are being applied,
// and on the current tick the element has just received the attributes, but Tabster has not
// instantiated the Modalizer yet.
setActivateModalTimeout(()=>{
var _modalizerRefAPI_current;
(_modalizerRefAPI_current = modalizerRefAPI.current) === null || _modalizerRefAPI_current === void 0 ? void 0 : _modalizerRefAPI_current.activate(elementFromModal);
}, 0);
}, [
modalizerRefAPI,
setActivateModalTimeout
]);
return activateModal;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useActivateModal.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { getModalizer } from 'tabster';\nimport { useTimeout } from '@fluentui/react-utilities';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a function that activates a modal by element from the modal or modal container.\n */\nexport function useActivateModal(): (elementFromModal: HTMLElement | undefined) => void {\n const modalizerRefAPI = useTabster(getModalizer);\n\n const [setActivateModalTimeout] = useTimeout();\n const activateModal = React.useCallback(\n (elementFromModal: HTMLElement | undefined) => {\n // We call the actual activation function on the next tick, because with the typical use case,\n // the hook will be called on the same tick when other Tabster attributes are being applied,\n // and on the current tick the element has just received the attributes, but Tabster has not\n // instantiated the Modalizer yet.\n setActivateModalTimeout(() => {\n modalizerRefAPI.current?.activate(elementFromModal);\n }, 0);\n },\n [modalizerRefAPI, setActivateModalTimeout],\n );\n\n return activateModal;\n}\n"],"names":["React","getModalizer","useTimeout","useTabster","useActivateModal","modalizerRefAPI","setActivateModalTimeout","activateModal","useCallback","elementFromModal","current","activate"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,YAAY,QAAQ,UAAU;AACvC,SAASC,UAAU,QAAQ,4BAA4B;AACvD,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,kBAAkBF,WAAWF;IAEnC,MAAM,CAACK,wBAAwB,GAAGJ;IAClC,MAAMK,gBAAgBP,MAAMQ,WAAW,CACrC,CAACC;QACC,8FAA8F;QAC9F,4FAA4F;QAC5F,4FAA4F;QAC5F,kCAAkC;QAClCH,wBAAwB;gBACtBD;aAAAA,2BAAAA,gBAAgBK,OAAO,cAAvBL,+CAAAA,yBAAyBM,QAAQ,CAACF;QACpC,GAAG;IACL,GACA;QAACJ;QAAiBC;KAAwB;IAG5C,OAAOC;AACT"}

View File

@@ -0,0 +1,41 @@
'use client';
import { getMover, MoverDirections } from 'tabster';
import { useTabsterAttributes } from './useTabsterAttributes';
import { useTabster } from './useTabster';
/**
* A hook that returns the necessary tabster attributes to support arrow key navigation
* @param options - Options to configure keyboard navigation
*/ export const useArrowNavigationGroup = (options = {})=>{
const { circular, axis, memorizeCurrent = true, tabbable, ignoreDefaultKeydown, // eslint-disable-next-line @typescript-eslint/naming-convention
unstable_hasDefault } = options;
useTabster(getMover);
return useTabsterAttributes({
mover: {
cyclic: !!circular,
direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
memorizeCurrent,
tabbable,
hasDefault: unstable_hasDefault
},
...ignoreDefaultKeydown && {
focusable: {
ignoreKeydown: ignoreDefaultKeydown
}
}
});
};
function axisToMoverDirection(axis) {
switch(axis){
case 'horizontal':
return MoverDirections.Horizontal;
case 'grid':
return MoverDirections.Grid;
case 'grid-linear':
return MoverDirections.GridLinear;
case 'both':
return MoverDirections.Both;
case 'vertical':
default:
return MoverDirections.Vertical;
}
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useArrowNavigationGroup.ts"],"sourcesContent":["'use client';\n\nimport { Types, getMover, MoverDirections } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseArrowNavigationGroupOptions {\n /**\n * Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally\n * @defaultValue vertical\n */\n axis?: 'vertical' | 'horizontal' | 'grid' | 'grid-linear' | 'both';\n /**\n * Focus will cycle to the first/last elements of the group without stopping\n */\n circular?: boolean;\n /**\n * Last focused element in the group will be remembered and focused (if still\n * available) when tabbing from outside of the group\n * @default true\n */\n memorizeCurrent?: boolean;\n /**\n * Allow tabbing within the arrow navigation group items.\n */\n tabbable?: boolean;\n /**\n * Tabster should ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\n /**\n * The default focusable item in the group will be an element with Focusable.isDefault property.\n * Note that there is no way in \\@fluentui/react-tabster to set default focusable element,\n * and this option is currently for internal testing purposes only.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault?: boolean;\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support arrow key navigation\n * @param options - Options to configure keyboard navigation\n */\nexport const useArrowNavigationGroup = (options: UseArrowNavigationGroupOptions = {}): Types.TabsterDOMAttribute => {\n const {\n circular,\n axis,\n memorizeCurrent = true,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n\n useTabster(getMover);\n\n return useTabsterAttributes({\n mover: {\n cyclic: !!circular,\n direction: axisToMoverDirection(axis ?? 'vertical'),\n memorizeCurrent,\n tabbable,\n hasDefault: unstable_hasDefault,\n },\n ...(ignoreDefaultKeydown && {\n focusable: {\n ignoreKeydown: ignoreDefaultKeydown,\n },\n }),\n });\n};\n\nfunction axisToMoverDirection(axis: UseArrowNavigationGroupOptions['axis']): Types.MoverDirection {\n switch (axis) {\n case 'horizontal':\n return MoverDirections.Horizontal;\n case 'grid':\n return MoverDirections.Grid;\n case 'grid-linear':\n return MoverDirections.GridLinear;\n case 'both':\n return MoverDirections.Both;\n\n case 'vertical':\n default:\n return MoverDirections.Vertical;\n }\n}\n"],"names":["getMover","MoverDirections","useTabsterAttributes","useTabster","useArrowNavigationGroup","options","circular","axis","memorizeCurrent","tabbable","ignoreDefaultKeydown","unstable_hasDefault","mover","cyclic","direction","axisToMoverDirection","hasDefault","focusable","ignoreKeydown","Horizontal","Grid","GridLinear","Both","Vertical"],"mappings":"AAAA;AAEA,SAAgBA,QAAQ,EAAEC,eAAe,QAAQ,UAAU;AAC3D,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAmC1C;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC,UAA0C,CAAC,CAAC;IAClF,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,kBAAkB,IAAI,EACtBC,QAAQ,EACRC,oBAAoB,EACpB,gEAAgE;IAChEC,mBAAmB,EACpB,GAAGN;IAEJF,WAAWH;IAEX,OAAOE,qBAAqB;QAC1BU,OAAO;YACLC,QAAQ,CAAC,CAACP;YACVQ,WAAWC,qBAAqBR,iBAAAA,kBAAAA,OAAQ;YACxCC;YACAC;YACAO,YAAYL;QACd;QACA,GAAID,wBAAwB;YAC1BO,WAAW;gBACTC,eAAeR;YACjB;QACF,CAAC;IACH;AACF,EAAE;AAEF,SAASK,qBAAqBR,IAA4C;IACxE,OAAQA;QACN,KAAK;YACH,OAAON,gBAAgBkB,UAAU;QACnC,KAAK;YACH,OAAOlB,gBAAgBmB,IAAI;QAC7B,KAAK;YACH,OAAOnB,gBAAgBoB,UAAU;QACnC,KAAK;YACH,OAAOpB,gBAAgBqB,IAAI;QAE7B,KAAK;QACL;YACE,OAAOrB,gBAAgBsB,QAAQ;IACnC;AACF"}

View File

@@ -0,0 +1,69 @@
'use client';
import * as React from 'react';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { useTabster } from './useTabster';
/**
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
*/ export const useFocusFinders = ()=>{
const tabsterRef = useTabster();
const { targetDocument } = useFluent();
// Narrow props for now and let need dictate additional props in the future
const findAllFocusable = React.useCallback((container, acceptCondition)=>{
var _tabsterRef_current;
return container && ((_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findAll({
container,
acceptCondition
})) || [];
}, [
tabsterRef
]);
const findFirstFocusable = React.useCallback((container)=>{
var _tabsterRef_current;
return container && ((_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findFirst({
container
}));
}, [
tabsterRef
]);
const findLastFocusable = React.useCallback((container)=>{
var _tabsterRef_current;
return container && ((_tabsterRef_current = tabsterRef.current) === null || _tabsterRef_current === void 0 ? void 0 : _tabsterRef_current.focusable.findLast({
container
}));
}, [
tabsterRef
]);
const findNextFocusable = React.useCallback((currentElement, options = {})=>{
if (!tabsterRef.current || !targetDocument || !currentElement) {
return null;
}
const { container = targetDocument.body } = options;
return tabsterRef.current.focusable.findNext({
currentElement,
container
});
}, [
tabsterRef,
targetDocument
]);
const findPrevFocusable = React.useCallback((currentElement, options = {})=>{
if (!tabsterRef.current || !targetDocument || !currentElement) {
return null;
}
const { container = targetDocument.body } = options;
return tabsterRef.current.focusable.findPrev({
currentElement,
container
});
}, [
tabsterRef,
targetDocument
]);
return {
findAllFocusable,
findFirstFocusable,
findLastFocusable,
findNextFocusable,
findPrevFocusable
};
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusFinders.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element\n */\nexport const useFocusFinders = (): {\n findAllFocusable: (container: HTMLElement | null, acceptCondition?: (el: HTMLElement) => boolean) => HTMLElement[];\n findFirstFocusable: (container: HTMLElement | null) => HTMLElement | null | undefined;\n findLastFocusable: (container: HTMLElement | null) => HTMLElement | null | undefined;\n findNextFocusable: (\n currentElement: HTMLElement | null,\n options?: { container?: HTMLElement },\n ) => HTMLElement | null | undefined;\n findPrevFocusable: (\n currentElement: HTMLElement | null,\n options?: { container?: HTMLElement },\n ) => HTMLElement | null | undefined;\n} => {\n const tabsterRef = useTabster();\n const { targetDocument } = useFluent();\n\n // Narrow props for now and let need dictate additional props in the future\n const findAllFocusable = React.useCallback(\n (container: HTMLElement | null, acceptCondition?: (el: HTMLElement) => boolean) =>\n (container && tabsterRef.current?.focusable.findAll({ container, acceptCondition })) || [],\n [tabsterRef],\n );\n\n const findFirstFocusable = React.useCallback(\n (container: HTMLElement | null) => container && tabsterRef.current?.focusable.findFirst({ container }),\n [tabsterRef],\n );\n\n const findLastFocusable = React.useCallback(\n (container: HTMLElement | null) => container && tabsterRef.current?.focusable.findLast({ container }),\n [tabsterRef],\n );\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement | null, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabsterRef.current || !targetDocument || !currentElement) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabsterRef.current.focusable.findNext({ currentElement, container });\n },\n [tabsterRef, targetDocument],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement | null, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabsterRef.current || !targetDocument || !currentElement) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabsterRef.current.focusable.findPrev({ currentElement, container });\n },\n [tabsterRef, targetDocument],\n );\n\n return {\n findAllFocusable,\n findFirstFocusable,\n findLastFocusable,\n findNextFocusable,\n findPrevFocusable,\n };\n};\n"],"names":["React","useFluent_unstable","useFluent","useTabster","useFocusFinders","tabsterRef","targetDocument","findAllFocusable","useCallback","container","acceptCondition","current","focusable","findAll","findFirstFocusable","findFirst","findLastFocusable","findLast","findNextFocusable","currentElement","options","body","findNext","findPrevFocusable","findPrev"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,MAAMC,kBAAkB;IAa7B,MAAMC,aAAaF;IACnB,MAAM,EAAEG,cAAc,EAAE,GAAGJ;IAE3B,2EAA2E;IAC3E,MAAMK,mBAAmBP,MAAMQ,WAAW,CACxC,CAACC,WAA+BC;YAChBL;eAAd,AAACI,eAAaJ,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACC,OAAO,CAAC;YAAEJ;YAAWC;QAAgB,OAAO,EAAE;OAC5F;QAACL;KAAW;IAGd,MAAMS,qBAAqBd,MAAMQ,WAAW,CAC1C,CAACC;YAA+CJ;eAAbI,eAAaJ,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACG,SAAS,CAAC;YAAEN;QAAU;OACpG;QAACJ;KAAW;IAGd,MAAMW,oBAAoBhB,MAAMQ,WAAW,CACzC,CAACC;YAA+CJ;eAAbI,eAAaJ,sBAAAA,WAAWM,OAAO,cAAlBN,0CAAAA,oBAAoBO,SAAS,CAACK,QAAQ,CAAC;YAAER;QAAU;OACnG;QAACJ;KAAW;IAGd,MAAMa,oBAAoBlB,MAAMQ,WAAW,CACzC,CAACW,gBAAoCC,UAAkE,CAAC,CAAC;QACvG,IAAI,CAACf,WAAWM,OAAO,IAAI,CAACL,kBAAkB,CAACa,gBAAgB;YAC7D,OAAO;QACT;QAEA,MAAM,EAAEV,YAAYH,eAAee,IAAI,EAAE,GAAGD;QAE5C,OAAOf,WAAWM,OAAO,CAACC,SAAS,CAACU,QAAQ,CAAC;YAAEH;YAAgBV;QAAU;IAC3E,GACA;QAACJ;QAAYC;KAAe;IAG9B,MAAMiB,oBAAoBvB,MAAMQ,WAAW,CACzC,CAACW,gBAAoCC,UAAkE,CAAC,CAAC;QACvG,IAAI,CAACf,WAAWM,OAAO,IAAI,CAACL,kBAAkB,CAACa,gBAAgB;YAC7D,OAAO;QACT;QAEA,MAAM,EAAEV,YAAYH,eAAee,IAAI,EAAE,GAAGD;QAE5C,OAAOf,WAAWM,OAAO,CAACC,SAAS,CAACY,QAAQ,CAAC;YAAEL;YAAgBV;QAAU;IAC3E,GACA;QAACJ;QAAYC;KAAe;IAG9B,OAAO;QACLC;QACAO;QACAE;QACAE;QACAK;IACF;AACF,EAAE"}

View File

@@ -0,0 +1,27 @@
'use client';
import * as React from 'react';
import { getObservedElement } from 'tabster';
import { useTabster } from './useTabster';
/**
* @param name - The observed element to focus
* @param options - Options for the focus observed
*
* @returns Function that will focus an element
*/ export function useFocusObserved(name, options = {}) {
const { timeout = 1000 } = options;
const observedAPIRef = useTabster(getObservedElement);
return React.useCallback(()=>{
const observerAPI = observedAPIRef.current;
if (observerAPI) {
return observerAPI.requestFocus(name, timeout);
}
return {
result: Promise.resolve(false),
cancel: ()=>null
};
}, [
observedAPIRef,
name,
timeout
]);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusObserved.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { getObservedElement, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\ninterface UseFocusObservedOptions {\n /**\n * After timeout the focus attempt fails\n */\n timeout?: number;\n}\n\n/**\n * @param name - The observed element to focus\n * @param options - Options for the focus observed\n *\n * @returns Function that will focus an element\n */\nexport function useFocusObserved(\n name: string,\n options: UseFocusObservedOptions = {},\n): () => TabsterTypes.ObservedElementAsyncRequest<boolean> {\n const { timeout = 1000 } = options;\n const observedAPIRef = useTabster(getObservedElement);\n\n return React.useCallback(() => {\n const observerAPI = observedAPIRef.current;\n\n if (observerAPI) {\n return observerAPI.requestFocus(name, timeout);\n }\n\n return {\n result: Promise.resolve(false),\n cancel: () => null,\n };\n }, [observedAPIRef, name, timeout]);\n}\n"],"names":["React","getObservedElement","useTabster","useFocusObserved","name","options","timeout","observedAPIRef","useCallback","observerAPI","current","requestFocus","result","Promise","resolve","cancel"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,kBAAkB,QAA+B,UAAU;AACpE,SAASC,UAAU,QAAQ,eAAe;AAS1C;;;;;CAKC,GACD,OAAO,SAASC,iBACdC,IAAY,EACZC,UAAmC,CAAC,CAAC;IAErC,MAAM,EAAEC,UAAU,IAAI,EAAE,GAAGD;IAC3B,MAAME,iBAAiBL,WAAWD;IAElC,OAAOD,MAAMQ,WAAW,CAAC;QACvB,MAAMC,cAAcF,eAAeG,OAAO;QAE1C,IAAID,aAAa;YACf,OAAOA,YAAYE,YAAY,CAACP,MAAME;QACxC;QAEA,OAAO;YACLM,QAAQC,QAAQC,OAAO,CAAC;YACxBC,QAAQ,IAAM;QAChB;IACF,GAAG;QAACR;QAAgBH;QAAME;KAAQ;AACpC"}

View File

@@ -0,0 +1,19 @@
'use client';
import * as React from 'react';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';
export function useFocusVisible(options = {}) {
const contextValue = useFluent();
const scopeRef = React.useRef(null);
var _options_targetDocument;
const targetDocument = (_options_targetDocument = options.targetDocument) !== null && _options_targetDocument !== void 0 ? _options_targetDocument : contextValue.targetDocument;
React.useEffect(()=>{
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && scopeRef.current) {
return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);
}
}, [
scopeRef,
targetDocument
]);
return scopeRef;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusVisible.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\ntype UseFocusVisibleOptions = {\n targetDocument?: Document;\n};\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>(\n options: UseFocusVisibleOptions = {},\n): React.RefObject<TElement | null> {\n const contextValue = useFluent();\n const scopeRef = React.useRef<TElement>(null);\n\n const targetDocument = options.targetDocument ?? contextValue.targetDocument;\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && scopeRef.current) {\n return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);\n }\n }, [scopeRef, targetDocument]);\n\n return scopeRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusVisiblePolyfill","useFocusVisible","options","contextValue","scopeRef","useRef","targetDocument","useEffect","defaultView","current"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,SAASC,yBAAyB,QAAQ,gCAAgC;AAM1E,OAAO,SAASC,gBACdC,UAAkC,CAAC,CAAC;IAEpC,MAAMC,eAAeJ;IACrB,MAAMK,WAAWP,MAAMQ,MAAM,CAAW;QAEjBH;IAAvB,MAAMI,iBAAiBJ,CAAAA,0BAAAA,QAAQI,cAAc,cAAtBJ,qCAAAA,0BAA0BC,aAAaG,cAAc;IAE5ET,MAAMU,SAAS,CAAC;QACd,IAAID,CAAAA,2BAAAA,qCAAAA,eAAgBE,WAAW,KAAIJ,SAASK,OAAO,EAAE;YACnD,OAAOT,0BAA0BI,SAASK,OAAO,EAAEH,eAAeE,WAAW;QAC/E;IACF,GAAG;QAACJ;QAAUE;KAAe;IAE7B,OAAOF;AACT"}

View File

@@ -0,0 +1,21 @@
'use client';
import * as React from 'react';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';
/**
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
* @returns ref to the element that uses `:focus-within` styles
*/ export function useFocusWithin() {
const { targetDocument } = useFluent();
const elementRef = React.useRef(null);
React.useEffect(()=>{
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
}
}, [
elementRef,
targetDocument
]);
return elementRef;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusWithin.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';\n\n/**\n * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation\n * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151\n * @returns ref to the element that uses `:focus-within` styles\n */\nexport function useFocusWithin<TElement extends HTMLElement = HTMLElement>(): React.RefObject<TElement | null> {\n const { targetDocument } = useFluent();\n const elementRef = React.useRef<TElement>(null);\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && elementRef.current) {\n return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);\n }\n }, [elementRef, targetDocument]);\n\n return elementRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusWithinPolyfill","useFocusWithin","targetDocument","elementRef","useRef","useEffect","defaultView","current"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGH;IAC3B,MAAMI,aAAaN,MAAMO,MAAM,CAAW;IAE1CP,MAAMQ,SAAS,CAAC;QACd,IAAIH,CAAAA,2BAAAA,qCAAAA,eAAgBI,WAAW,KAAIH,WAAWI,OAAO,EAAE;YACrD,OAAOP,yBAAyBG,WAAWI,OAAO,EAAEL,eAAeI,WAAW;QAChF;IACF,GAAG;QAACH;QAAYD;KAAe;IAE/B,OAAOC;AACT"}

View File

@@ -0,0 +1,30 @@
'use client';
import { getGroupper, GroupperTabbabilities } from 'tabster';
import { useTabsterAttributes } from './useTabsterAttributes';
import { useTabster } from './useTabster';
/**
* A hook that returns the necessary tabster attributes to support groupping.
* @param options - Options to configure keyboard navigation
*/ export const useFocusableGroup = (options)=>{
useTabster(getGroupper);
return useTabsterAttributes({
groupper: {
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
},
focusable: {
ignoreKeydown: options === null || options === void 0 ? void 0 : options.ignoreDefaultKeydown
}
});
};
const getTabbability = (tabBehavior)=>{
switch(tabBehavior){
case 'unlimited':
return GroupperTabbabilities.Unlimited;
case 'limited':
return GroupperTabbabilities.Limited;
case 'limited-trap-focus':
return GroupperTabbabilities.LimitedTrapFocus;
default:
return undefined;
}
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusableGroup.ts"],"sourcesContent":["'use client';\n\nimport { Types, getGroupper, GroupperTabbabilities } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseFocusableGroupOptions {\n /**\n * Behavior for the Tab key.\n */\n tabBehavior?: 'unlimited' | 'limited' | 'limited-trap-focus';\n\n /**\n * Tabster can ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support groupping.\n * @param options - Options to configure keyboard navigation\n */\nexport const useFocusableGroup = (options?: UseFocusableGroupOptions): Types.TabsterDOMAttribute => {\n useTabster(getGroupper);\n\n return useTabsterAttributes({\n groupper: {\n tabbability: getTabbability(options?.tabBehavior),\n },\n focusable: {\n ignoreKeydown: options?.ignoreDefaultKeydown,\n },\n });\n};\n\nconst getTabbability = (\n tabBehavior?: UseFocusableGroupOptions['tabBehavior'],\n): Types.GroupperTabbability | undefined => {\n switch (tabBehavior) {\n case 'unlimited':\n return GroupperTabbabilities.Unlimited;\n case 'limited':\n return GroupperTabbabilities.Limited;\n case 'limited-trap-focus':\n return GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"names":["getGroupper","GroupperTabbabilities","useTabsterAttributes","useTabster","useFocusableGroup","options","groupper","tabbability","getTabbability","tabBehavior","focusable","ignoreKeydown","ignoreDefaultKeydown","Unlimited","Limited","LimitedTrapFocus","undefined"],"mappings":"AAAA;AAEA,SAAgBA,WAAW,EAAEC,qBAAqB,QAAQ,UAAU;AACpE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAc1C;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC;IAChCF,WAAWH;IAEX,OAAOE,qBAAqB;QAC1BI,UAAU;YACRC,aAAaC,eAAeH,oBAAAA,8BAAAA,QAASI,WAAW;QAClD;QACAC,WAAW;YACTC,aAAa,EAAEN,oBAAAA,8BAAAA,QAASO,oBAAoB;QAC9C;IACF;AACF,EAAE;AAEF,MAAMJ,iBAAiB,CACrBC;IAEA,OAAQA;QACN,KAAK;YACH,OAAOR,sBAAsBY,SAAS;QACxC,KAAK;YACH,OAAOZ,sBAAsBa,OAAO;QACtC,KAAK;YACH,OAAOb,sBAAsBc,gBAAgB;QAC/C;YACE,OAAOC;IACX;AACF"}

View File

@@ -0,0 +1,26 @@
'use client';
import { disposeTabster } from 'tabster';
import * as React from 'react';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { useEventCallback } from '@fluentui/react-utilities';
import { createTabsterWithConfig } from './useTabster';
/**
* Subscribes to the tabster focused element. Calls the callback when the focused element changes.
* @param callback - Callback to subscribe to the focused element.
*/ export function useFocusedElementChange(callback) {
const { targetDocument } = useFluent();
const listener = useEventCallback(callback);
React.useEffect(()=>{
const tabster = createTabsterWithConfig(targetDocument);
if (tabster) {
tabster.focusedElement.subscribe(listener);
return ()=>{
tabster.focusedElement.unsubscribe(listener);
disposeTabster(tabster);
};
}
}, [
listener,
targetDocument
]);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useFocusedElementChange.ts"],"sourcesContent":["'use client';\n\nimport { type Types as TabsterTypes, disposeTabster } from 'tabster';\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useEventCallback } from '@fluentui/react-utilities';\n\nimport { createTabsterWithConfig } from './useTabster';\n\n/**\n * Subscribes to the tabster focused element. Calls the callback when the focused element changes.\n * @param callback - Callback to subscribe to the focused element.\n */\nexport function useFocusedElementChange(\n callback: TabsterTypes.SubscribableCallback<HTMLElement | undefined, TabsterTypes.FocusedElementDetail>,\n): void {\n const { targetDocument } = useFluent();\n const listener = useEventCallback(callback);\n\n React.useEffect(() => {\n const tabster = createTabsterWithConfig(targetDocument);\n\n if (tabster) {\n tabster.focusedElement.subscribe(listener);\n\n return () => {\n tabster.focusedElement.unsubscribe(listener);\n disposeTabster(tabster);\n };\n }\n }, [listener, targetDocument]);\n}\n"],"names":["disposeTabster","React","useFluent_unstable","useFluent","useEventCallback","createTabsterWithConfig","useFocusedElementChange","callback","targetDocument","listener","useEffect","tabster","focusedElement","subscribe","unsubscribe"],"mappings":"AAAA;AAEA,SAAqCA,cAAc,QAAQ,UAAU;AACrE,YAAYC,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,uBAAuB,QAAQ,eAAe;AAEvD;;;CAGC,GACD,OAAO,SAASC,wBACdC,QAAuG;IAEvG,MAAM,EAAEC,cAAc,EAAE,GAAGL;IAC3B,MAAMM,WAAWL,iBAAiBG;IAElCN,MAAMS,SAAS,CAAC;QACd,MAAMC,UAAUN,wBAAwBG;QAExC,IAAIG,SAAS;YACXA,QAAQC,cAAc,CAACC,SAAS,CAACJ;YAEjC,OAAO;gBACLE,QAAQC,cAAc,CAACE,WAAW,CAACL;gBACnCT,eAAeW;YACjB;QACF;IACF,GAAG;QAACF;QAAUD;KAAe;AAC/B"}

View File

@@ -0,0 +1,16 @@
'use client';
import * as React from 'react';
import { useKeyborgRef } from './useKeyborgRef';
/**
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and checks if the user is navigating with the keyboard.
* @returns
*/ export function useIsNavigatingWithKeyboard() {
const keyborgRef = useKeyborgRef();
return React.useCallback(()=>{
var _keyborgRef_current;
var _keyborgRef_current_isNavigatingWithKeyboard;
return (_keyborgRef_current_isNavigatingWithKeyboard = (_keyborgRef_current = keyborgRef.current) === null || _keyborgRef_current === void 0 ? void 0 : _keyborgRef_current.isNavigatingWithKeyboard()) !== null && _keyborgRef_current_isNavigatingWithKeyboard !== void 0 ? _keyborgRef_current_isNavigatingWithKeyboard : false;
}, [
keyborgRef
]);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useIsNavigatingWithKeyboard.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useKeyborgRef } from './useKeyborgRef';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and checks if the user is navigating with the keyboard.\n * @returns\n */\nexport function useIsNavigatingWithKeyboard(): () => boolean {\n const keyborgRef = useKeyborgRef();\n\n return React.useCallback(() => {\n return keyborgRef.current?.isNavigatingWithKeyboard() ?? false;\n }, [keyborgRef]);\n}\n"],"names":["React","useKeyborgRef","useIsNavigatingWithKeyboard","keyborgRef","useCallback","current","isNavigatingWithKeyboard"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,QAAQ,kBAAkB;AAEhD;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,aAAaF;IAEnB,OAAOD,MAAMI,WAAW,CAAC;YAChBD;YAAAA;QAAP,OAAOA,CAAAA,gDAAAA,sBAAAA,WAAWE,OAAO,cAAlBF,0CAAAA,oBAAoBG,wBAAwB,gBAA5CH,0DAAAA,+CAAkD;IAC3D,GAAG;QAACA;KAAW;AACjB"}

View File

@@ -0,0 +1,39 @@
'use client';
import * as React from 'react';
import { createKeyborg } from 'keyborg';
import { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
/**
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
* attribute to a referenced element to ensure keyboard navigation awareness
* synced to keyborg logic without having to cause a re-render on react tree.
*/ export function useKeyboardNavAttribute() {
const { targetDocument } = useFluent();
const keyborg = React.useMemo(()=>targetDocument && createKeyborg(targetDocument.defaultView), [
targetDocument
]);
const ref = React.useRef(null);
React.useEffect(()=>{
if (keyborg) {
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());
const cb = (next)=>{
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);
};
keyborg.subscribe(cb);
return ()=>keyborg.unsubscribe(cb);
}
}, [
keyborg
]);
return ref;
}
function setBooleanAttribute(elementRef, attribute, value) {
if (!elementRef.current) {
return;
}
if (value) {
elementRef.current.setAttribute(attribute, '');
} else {
elementRef.current.removeAttribute(attribute);
}
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useKeyboardNavAttribute.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createKeyborg } from 'keyborg';\nimport { KEYBOARD_NAV_ATTRIBUTE } from '../focus/constants';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport type { KeyborgCallback } from 'keyborg';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`\n * attribute to a referenced element to ensure keyboard navigation awareness\n * synced to keyborg logic without having to cause a re-render on react tree.\n */\nexport function useKeyboardNavAttribute<E extends HTMLElement>(): React.RefObject<E | null> {\n const { targetDocument } = useFluent();\n const keyborg = React.useMemo(() => targetDocument && createKeyborg(targetDocument.defaultView!), [targetDocument]);\n const ref = React.useRef<E>(null);\n React.useEffect(() => {\n if (keyborg) {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());\n const cb: KeyborgCallback = next => {\n setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);\n };\n keyborg.subscribe(cb);\n return () => keyborg.unsubscribe(cb);\n }\n }, [keyborg]);\n\n return ref;\n}\n\nfunction setBooleanAttribute(elementRef: React.RefObject<HTMLElement | null>, attribute: string, value: boolean) {\n if (!elementRef.current) {\n return;\n }\n if (value) {\n elementRef.current.setAttribute(attribute, '');\n } else {\n elementRef.current.removeAttribute(attribute);\n }\n}\n"],"names":["React","createKeyborg","KEYBOARD_NAV_ATTRIBUTE","useFluent_unstable","useFluent","useKeyboardNavAttribute","targetDocument","keyborg","useMemo","defaultView","ref","useRef","useEffect","setBooleanAttribute","isNavigatingWithKeyboard","cb","next","subscribe","unsubscribe","elementRef","attribute","value","current","setAttribute","removeAttribute"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,sBAAsB,QAAQ,qBAAqB;AAC5D,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAGlF;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGF;IAC3B,MAAMG,UAAUP,MAAMQ,OAAO,CAAC,IAAMF,kBAAkBL,cAAcK,eAAeG,WAAW,GAAI;QAACH;KAAe;IAClH,MAAMI,MAAMV,MAAMW,MAAM,CAAI;IAC5BX,MAAMY,SAAS,CAAC;QACd,IAAIL,SAAS;YACXM,oBAAoBH,KAAKR,wBAAwBK,QAAQO,wBAAwB;YACjF,MAAMC,KAAsBC,CAAAA;gBAC1BH,oBAAoBH,KAAKR,wBAAwBc;YACnD;YACAT,QAAQU,SAAS,CAACF;YAClB,OAAO,IAAMR,QAAQW,WAAW,CAACH;QACnC;IACF,GAAG;QAACR;KAAQ;IAEZ,OAAOG;AACT;AAEA,SAASG,oBAAoBM,UAA+C,EAAEC,SAAiB,EAAEC,KAAc;IAC7G,IAAI,CAACF,WAAWG,OAAO,EAAE;QACvB;IACF;IACA,IAAID,OAAO;QACTF,WAAWG,OAAO,CAACC,YAAY,CAACH,WAAW;IAC7C,OAAO;QACLD,WAAWG,OAAO,CAACE,eAAe,CAACJ;IACrC;AACF"}

View File

@@ -0,0 +1,26 @@
'use client';
import * as React from 'react';
import { createKeyborg, disposeKeyborg } from 'keyborg';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
/**
* @internal
* Instantiates [keyborg](https://github.com/microsoft/keyborg)
* @returns - keyborg instance
*/ export function useKeyborgRef() {
const { targetDocument } = useFluent();
const keyborgRef = React.useRef(null);
React.useEffect(()=>{
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
if (targetWindow) {
const keyborg = createKeyborg(targetWindow);
keyborgRef.current = keyborg;
return ()=>{
disposeKeyborg(keyborg);
keyborgRef.current = null;
};
}
}, [
targetDocument
]);
return keyborgRef;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useKeyborgRef.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createKeyborg, disposeKeyborg, type Keyborg } from 'keyborg';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * @internal\n * Instantiates [keyborg](https://github.com/microsoft/keyborg)\n * @returns - keyborg instance\n */\nexport function useKeyborgRef(): React.RefObject<Keyborg | null> {\n const { targetDocument } = useFluent();\n const keyborgRef = React.useRef<Keyborg | null>(null);\n\n React.useEffect(() => {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n const keyborg = createKeyborg(targetWindow);\n keyborgRef.current = keyborg;\n\n return () => {\n disposeKeyborg(keyborg);\n keyborgRef.current = null;\n };\n }\n }, [targetDocument]);\n\n return keyborgRef;\n}\n"],"names":["React","createKeyborg","disposeKeyborg","useFluent_unstable","useFluent","useKeyborgRef","targetDocument","keyborgRef","useRef","useEffect","targetWindow","defaultView","keyborg","current"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,cAAc,QAAsB,UAAU;AACtE,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGF;IAC3B,MAAMG,aAAaP,MAAMQ,MAAM,CAAiB;IAEhDR,MAAMS,SAAS,CAAC;QACd,MAAMC,eAAeJ,2BAAAA,qCAAAA,eAAgBK,WAAW;QAEhD,IAAID,cAAc;YAChB,MAAME,UAAUX,cAAcS;YAC9BH,WAAWM,OAAO,GAAGD;YAErB,OAAO;gBACLV,eAAeU;gBACfL,WAAWM,OAAO,GAAG;YACvB;QACF;IACF,GAAG;QAACP;KAAe;IAEnB,OAAOC;AACT"}

View File

@@ -0,0 +1,76 @@
'use client';
import * as React from 'react';
import { TABSTER_ATTRIBUTE_NAME } from 'tabster';
/**
* Merges a collection of tabster attributes.
*
* ⚠The attributes passed as arguments to this hook cannot change at runtime.
* @internal
* @param attributes - collection of tabster attributes from other react-tabster hooks
* @returns single merged tabster attribute
*/ export const useMergedTabsterAttributes_unstable = (...attributes)=>{
'use no memo';
const stringAttributes = attributes.reduce((acc, curr)=>{
if (curr === null || curr === void 0 ? void 0 : curr[TABSTER_ATTRIBUTE_NAME]) {
acc.push(curr[TABSTER_ATTRIBUTE_NAME]);
}
return acc;
}, []);
if (process.env.NODE_ENV !== 'production') {
// ignoring rules of hooks because this is a condition based on the environment
// it's safe to ignore the rule
// eslint-disable-next-line react-hooks/rules-of-hooks
useWarnIfUnstableAttributes(stringAttributes);
}
return React.useMemo(()=>({
[TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined
}), // disable exhaustive-deps because we want to memoize the result of the reduction
// this is safe because the collection of attributes is not expected to change at runtime
// eslint-disable-next-line react-hooks/exhaustive-deps
stringAttributes);
};
/**
* Merges two JSON strings into one.
*/ const mergeJSONStrings = (a, b)=>JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));
/**
* Tries to parse a JSON string and returns an object.
* If the JSON string is invalid, an empty object is returned.
*/ const safelyParseJSON = (json)=>{
try {
return JSON.parse(json);
} catch {
return {};
}
};
/**
* Helper hook that ensures that the attributes passed to the hook are stable.
* This is necessary because the attributes are expected to not change at runtime.
*
* This hook will console.warn if the attributes change at runtime.
*/ const useWarnIfUnstableAttributes = (attributes)=>{
'use no memo';
const initialAttributesRef = React.useRef(attributes);
let isStable = initialAttributesRef.current.length === attributes.length;
if (initialAttributesRef.current !== attributes && isStable) {
for(let i = 0; i < attributes.length; i++){
if (initialAttributesRef.current[i] !== attributes[i]) {
isStable = false;
break;
}
}
}
React.useEffect(()=>{
if (!isStable) {
const error = new Error();
// eslint-disable-next-line no-console
console.warn(/** #__DE-INDENT__ */ `
@fluentui/react-tabster [useMergedTabsterAttributes]:
The attributes passed to the hook changed at runtime.
This might lead to unexpected behavior, please ensure that the attributes are stable.
${error.stack}
`);
}
}, [
isStable
]);
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
'use client';
import { useId } from '@fluentui/react-utilities';
import { useTabsterAttributes } from './useTabsterAttributes';
import { getModalizer, getRestorer, RestorerTypes } from 'tabster';
import { useTabster } from './useTabster';
const DangerousNeverHiddenAttribute = 'data-tabster-never-hide';
const DangerousNeverHiddenPropObject = {
[DangerousNeverHiddenAttribute]: ''
};
/**
* !!DANGEROUS!! Designates an element that will not be hidden even when outside an open modal.
* Only works for top-level elements; should be used with extreme care.
* @returns Attribute to apply to the target element that should never receive aria-hidden
*/ export function useDangerousNeverHidden_unstable() {
return DangerousNeverHiddenPropObject;
}
const tabsterAccessibleCheck = (element)=>{
return element.hasAttribute(DangerousNeverHiddenAttribute);
};
function initTabsterModules(tabster) {
getModalizer(tabster, undefined, tabsterAccessibleCheck);
getRestorer(tabster);
}
/**
* Applies modal dialog behaviour through DOM attributes
* Modal element will focus trap and hide other content on the page
* The trigger element will be focused if focus is lost after the modal element is removed
*
* @returns DOM attributes to apply to the modal element and its trigger
*/ export const useModalAttributes = (options = {})=>{
const { trapFocus, alwaysFocusable, legacyTrapFocus } = options;
// Initializes the modalizer and restorer APIs
useTabster(initTabsterModules);
const id = useId('modal-', options.id);
const modalAttributes = useTabsterAttributes({
restorer: {
type: RestorerTypes.Source
},
...trapFocus && {
modalizer: {
id,
isOthersAccessible: !trapFocus,
isAlwaysAccessible: alwaysFocusable,
isTrapped: legacyTrapFocus && trapFocus
}
}
});
const triggerAttributes = useTabsterAttributes({
restorer: {
type: RestorerTypes.Target
}
});
return {
modalAttributes,
triggerAttributes
};
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useModalAttributes.ts"],"sourcesContent":["'use client';\n\nimport { useId } from '@fluentui/react-utilities';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { getModalizer, getRestorer, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\nconst DangerousNeverHiddenAttribute = 'data-tabster-never-hide';\nconst DangerousNeverHiddenPropObject = { [DangerousNeverHiddenAttribute]: '' };\n\nexport interface UseModalAttributesOptions {\n /**\n * Traps focus inside the elements the attributes are applied.\n * it forbids users to tab out of the focus trap into the actual browser.\n */\n trapFocus?: boolean;\n\n /**\n * Traps focus inside the elements the attributes are applied.\n * This prop enables traditional force-focus behavior to match previous versions of Fluent.\n * Without this, users can tab out of the focus trap and into the browser chrome.\n * This matches the behavior of the native <dialog> element and inert.\n * We recommend setting this to true based on user feedback and consistency.\n */\n legacyTrapFocus?: boolean;\n\n /**\n * Always reachabled in Tab order\n */\n alwaysFocusable?: boolean;\n\n /**\n * Id to use for the modalizer. An id will be generated if not provided.\n */\n id?: string;\n}\n\n/**\n * !!DANGEROUS!! Designates an element that will not be hidden even when outside an open modal.\n * Only works for top-level elements; should be used with extreme care.\n * @returns Attribute to apply to the target element that should never receive aria-hidden\n */\nexport function useDangerousNeverHidden_unstable(): { [key: string]: string } {\n return DangerousNeverHiddenPropObject;\n}\n\nconst tabsterAccessibleCheck: TabsterTypes.ModalizerElementAccessibleCheck = element => {\n return element.hasAttribute(DangerousNeverHiddenAttribute);\n};\n\nfunction initTabsterModules(tabster: TabsterTypes.TabsterCore) {\n getModalizer(tabster, undefined, tabsterAccessibleCheck);\n getRestorer(tabster);\n}\n\n/**\n * Applies modal dialog behaviour through DOM attributes\n * Modal element will focus trap and hide other content on the page\n * The trigger element will be focused if focus is lost after the modal element is removed\n *\n * @returns DOM attributes to apply to the modal element and its trigger\n */\nexport const useModalAttributes = (\n options: UseModalAttributesOptions = {},\n): { modalAttributes: TabsterTypes.TabsterDOMAttribute; triggerAttributes: TabsterTypes.TabsterDOMAttribute } => {\n const { trapFocus, alwaysFocusable, legacyTrapFocus } = options;\n\n // Initializes the modalizer and restorer APIs\n useTabster(initTabsterModules);\n\n const id = useId('modal-', options.id);\n const modalAttributes = useTabsterAttributes({\n restorer: { type: RestorerTypes.Source },\n ...(trapFocus && {\n modalizer: {\n id,\n isOthersAccessible: !trapFocus,\n isAlwaysAccessible: alwaysFocusable,\n isTrapped: legacyTrapFocus && trapFocus,\n },\n }),\n });\n\n const triggerAttributes = useTabsterAttributes({\n restorer: { type: RestorerTypes.Target },\n });\n\n return { modalAttributes, triggerAttributes };\n};\n"],"names":["useId","useTabsterAttributes","getModalizer","getRestorer","RestorerTypes","useTabster","DangerousNeverHiddenAttribute","DangerousNeverHiddenPropObject","useDangerousNeverHidden_unstable","tabsterAccessibleCheck","element","hasAttribute","initTabsterModules","tabster","undefined","useModalAttributes","options","trapFocus","alwaysFocusable","legacyTrapFocus","id","modalAttributes","restorer","type","Source","modalizer","isOthersAccessible","isAlwaysAccessible","isTrapped","triggerAttributes","Target"],"mappings":"AAAA;AAEA,SAASA,KAAK,QAAQ,4BAA4B;AAClD,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,YAAY,EAAEC,WAAW,EAAyBC,aAAa,QAAQ,UAAU;AAC1F,SAASC,UAAU,QAAQ,eAAe;AAE1C,MAAMC,gCAAgC;AACtC,MAAMC,iCAAiC;IAAE,CAACD,8BAA8B,EAAE;AAAG;AA6B7E;;;;CAIC,GACD,OAAO,SAASE;IACd,OAAOD;AACT;AAEA,MAAME,yBAAuEC,CAAAA;IAC3E,OAAOA,QAAQC,YAAY,CAACL;AAC9B;AAEA,SAASM,mBAAmBC,OAAiC;IAC3DX,aAAaW,SAASC,WAAWL;IACjCN,YAAYU;AACd;AAEA;;;;;;CAMC,GACD,OAAO,MAAME,qBAAqB,CAChCC,UAAqC,CAAC,CAAC;IAEvC,MAAM,EAAEC,SAAS,EAAEC,eAAe,EAAEC,eAAe,EAAE,GAAGH;IAExD,8CAA8C;IAC9CX,WAAWO;IAEX,MAAMQ,KAAKpB,MAAM,UAAUgB,QAAQI,EAAE;IACrC,MAAMC,kBAAkBpB,qBAAqB;QAC3CqB,UAAU;YAAEC,MAAMnB,cAAcoB,MAAM;QAAC;QACvC,GAAIP,aAAa;YACfQ,WAAW;gBACTL;gBACAM,oBAAoB,CAACT;gBACrBU,oBAAoBT;gBACpBU,WAAWT,mBAAmBF;YAChC;QACF,CAAC;IACH;IAEA,MAAMY,oBAAoB5B,qBAAqB;QAC7CqB,UAAU;YAAEC,MAAMnB,cAAc0B,MAAM;QAAC;IACzC;IAEA,OAAO;QAAET;QAAiBQ;IAAkB;AAC9C,EAAE"}

View File

@@ -0,0 +1,14 @@
'use client';
import { getObservedElement } from 'tabster';
import { useTabster } from './useTabster';
import { useTabsterAttributes } from './useTabsterAttributes';
export function useObservedElement(name) {
useTabster(getObservedElement);
return useTabsterAttributes({
observed: {
names: Array.isArray(name) ? name : [
name
]
}
});
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useObservedElement.ts"],"sourcesContent":["'use client';\n\nimport { getObservedElement, Types as TabsterTypes } from 'tabster';\n\nimport { useTabster } from './useTabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\n\nexport function useObservedElement(name: string | string[]): TabsterTypes.TabsterDOMAttribute {\n useTabster(getObservedElement);\n\n return useTabsterAttributes({ observed: { names: Array.isArray(name) ? name : [name] } });\n}\n"],"names":["getObservedElement","useTabster","useTabsterAttributes","useObservedElement","name","observed","names","Array","isArray"],"mappings":"AAAA;AAEA,SAASA,kBAAkB,QAA+B,UAAU;AAEpE,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,oBAAoB,QAAQ,yBAAyB;AAE9D,OAAO,SAASC,mBAAmBC,IAAuB;IACxDH,WAAWD;IAEX,OAAOE,qBAAqB;QAAEG,UAAU;YAAEC,OAAOC,MAAMC,OAAO,CAACJ,QAAQA,OAAO;gBAACA;aAAK;QAAC;IAAE;AACzF"}

View File

@@ -0,0 +1,29 @@
'use client';
import * as React from 'react';
import { useEventCallback } from '@fluentui/react-utilities';
import { useKeyborgRef } from './useKeyborgRef';
/**
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and subscribes to changes
* in the keyboard navigation mode.
*
* @param callback - called every time the keyboard navigation state changes
*/ export function useOnKeyboardNavigationChange(callback) {
const keyborgRef = useKeyborgRef();
const eventCallback = useEventCallback(callback);
React.useEffect(()=>{
const keyborg = keyborgRef.current;
if (keyborg) {
const cb = (next)=>{
eventCallback(next);
};
keyborg.subscribe(cb);
cb(keyborg.isNavigatingWithKeyboard());
return ()=>{
keyborg.unsubscribe(cb);
};
}
}, [
keyborgRef,
eventCallback
]);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useOnKeyboardNavigationChange.ts"],"sourcesContent":["'use client';\n\nimport type { KeyborgCallback } from 'keyborg';\nimport * as React from 'react';\nimport { useEventCallback } from '@fluentui/react-utilities';\n\nimport { useKeyborgRef } from './useKeyborgRef';\n\n/**\n * Instantiates [keyborg](https://github.com/microsoft/keyborg) and subscribes to changes\n * in the keyboard navigation mode.\n *\n * @param callback - called every time the keyboard navigation state changes\n */\nexport function useOnKeyboardNavigationChange(callback: (isNavigatingWithKeyboard: boolean) => void): void {\n const keyborgRef = useKeyborgRef();\n const eventCallback = useEventCallback(callback);\n\n React.useEffect(() => {\n const keyborg = keyborgRef.current;\n\n if (keyborg) {\n const cb: KeyborgCallback = next => {\n eventCallback(next);\n };\n\n keyborg.subscribe(cb);\n cb(keyborg.isNavigatingWithKeyboard());\n\n return () => {\n keyborg.unsubscribe(cb);\n };\n }\n }, [keyborgRef, eventCallback]);\n}\n"],"names":["React","useEventCallback","useKeyborgRef","useOnKeyboardNavigationChange","callback","keyborgRef","eventCallback","useEffect","keyborg","current","cb","next","subscribe","isNavigatingWithKeyboard","unsubscribe"],"mappings":"AAAA;AAGA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,aAAa,QAAQ,kBAAkB;AAEhD;;;;;CAKC,GACD,OAAO,SAASC,8BAA8BC,QAAqD;IACjG,MAAMC,aAAaH;IACnB,MAAMI,gBAAgBL,iBAAiBG;IAEvCJ,MAAMO,SAAS,CAAC;QACd,MAAMC,UAAUH,WAAWI,OAAO;QAElC,IAAID,SAAS;YACX,MAAME,KAAsBC,CAAAA;gBAC1BL,cAAcK;YAChB;YAEAH,QAAQI,SAAS,CAACF;YAClBA,GAAGF,QAAQK,wBAAwB;YAEnC,OAAO;gBACLL,QAAQM,WAAW,CAACJ;YACtB;QACF;IACF,GAAG;QAACL;QAAYC;KAAc;AAChC"}

View File

@@ -0,0 +1,27 @@
'use client';
import { getRestorer, getTabsterAttribute, RestorerTypes } from 'tabster';
import { useTabster } from './useTabster';
/**
* Focus will be restored to the most recent target element when it is lost from a source
* @returns Attribute to apply to the target element where focus is restored
*/ export function useRestoreFocusTarget() {
// Initializes the restorer API
useTabster(getRestorer);
return getTabsterAttribute({
restorer: {
type: RestorerTypes.Target
}
});
}
/**
* Focus will be restored to the most recent target element when it is lost from a source
* @returns Attribute to apply to the element that might lose focus
*/ export function useRestoreFocusSource() {
// Initializes the restorer API
useTabster(getRestorer);
return getTabsterAttribute({
restorer: {
type: RestorerTypes.Source
}
});
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useRestoreFocus.ts"],"sourcesContent":["'use client';\n\nimport { getRestorer, getTabsterAttribute, Types as TabsterTypes, RestorerTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Focus will be restored to the most recent target element when it is lost from a source\n * @returns Attribute to apply to the target element where focus is restored\n */\nexport function useRestoreFocusTarget(): TabsterTypes.TabsterDOMAttribute {\n // Initializes the restorer API\n useTabster(getRestorer);\n\n return getTabsterAttribute({ restorer: { type: RestorerTypes.Target } });\n}\n\n/**\n * Focus will be restored to the most recent target element when it is lost from a source\n * @returns Attribute to apply to the element that might lose focus\n */\nexport function useRestoreFocusSource(): TabsterTypes.TabsterDOMAttribute {\n // Initializes the restorer API\n useTabster(getRestorer);\n\n return getTabsterAttribute({ restorer: { type: RestorerTypes.Source } });\n}\n"],"names":["getRestorer","getTabsterAttribute","RestorerTypes","useTabster","useRestoreFocusTarget","restorer","type","Target","useRestoreFocusSource","Source"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,mBAAmB,EAAyBC,aAAa,QAAQ,UAAU;AACjG,SAASC,UAAU,QAAQ,eAAe;AAE1C;;;CAGC,GACD,OAAO,SAASC;IACd,+BAA+B;IAC/BD,WAAWH;IAEX,OAAOC,oBAAoB;QAAEI,UAAU;YAAEC,MAAMJ,cAAcK,MAAM;QAAC;IAAE;AACxE;AAEA;;;CAGC,GACD,OAAO,SAASC;IACd,+BAA+B;IAC/BL,WAAWH;IAEX,OAAOC,oBAAoB;QAAEI,UAAU;YAAEC,MAAMJ,cAAcO,MAAM;QAAC;IAAE;AACxE"}

View File

@@ -0,0 +1,13 @@
'use client';
import * as React from 'react';
import { useKeyborgRef } from './useKeyborgRef';
/**
*/ export function useSetKeyboardNavigation() {
const keyborgRef = useKeyborgRef();
return React.useCallback((isNavigatingWithKeyboard)=>{
var _keyborgRef_current;
(_keyborgRef_current = keyborgRef.current) === null || _keyborgRef_current === void 0 ? void 0 : _keyborgRef_current.setVal(isNavigatingWithKeyboard);
}, [
keyborgRef
]);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useSetKeyboardNavigation.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useKeyborgRef } from './useKeyborgRef';\n\n/**\n */\nexport function useSetKeyboardNavigation(): (isNavigatingWithKeyboard: boolean) => void {\n const keyborgRef = useKeyborgRef();\n\n return React.useCallback(\n (isNavigatingWithKeyboard: boolean) => {\n keyborgRef.current?.setVal(isNavigatingWithKeyboard);\n },\n [keyborgRef],\n );\n}\n"],"names":["React","useKeyborgRef","useSetKeyboardNavigation","keyborgRef","useCallback","isNavigatingWithKeyboard","current","setVal"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,QAAQ,kBAAkB;AAEhD;CACC,GACD,OAAO,SAASC;IACd,MAAMC,aAAaF;IAEnB,OAAOD,MAAMI,WAAW,CACtB,CAACC;YACCF;SAAAA,sBAAAA,WAAWG,OAAO,cAAlBH,0CAAAA,oBAAoBI,MAAM,CAACF;IAC7B,GACA;QAACF;KAAW;AAEhB"}

View File

@@ -0,0 +1,60 @@
'use client';
import * as React from 'react';
import { createTabster, disposeTabster } from 'tabster';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { getParent, useIsomorphicLayoutEffect, usePrevious } from '@fluentui/react-utilities';
const DEFAULT_FACTORY = (tabster)=>{
return tabster;
};
/**
* Creates a tabster instance with the provided configuration
*
* @internal
* @param targetDocument
*/ export function createTabsterWithConfig(targetDocument) {
const defaultView = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) || undefined;
const shadowDOMAPI = defaultView === null || defaultView === void 0 ? void 0 : defaultView.__tabsterShadowDOMAPI;
if (defaultView) {
return createTabster(defaultView, {
autoRoot: {},
controlTab: false,
getParent,
// The non-undefined return value of checkUncontrolledCompletely() dominates the value that the element might
// have in its `uncontrolled: { completely: true }` part of the tabster attribute. We must make sure to return
// undefined if we want the value from tabster attribute to be respected.
checkUncontrolledCompletely: (element)=>{
var _element_firstElementChild;
return ((_element_firstElementChild = element.firstElementChild) === null || _element_firstElementChild === void 0 ? void 0 : _element_firstElementChild.hasAttribute('data-is-focus-trap-zone-bumper')) === true || undefined;
},
DOMAPI: shadowDOMAPI
});
}
}
export function useTabster(factory = DEFAULT_FACTORY) {
const { targetDocument } = useFluent();
const factoryResultRef = React.useRef(null);
useIsomorphicLayoutEffect(()=>{
const tabster = createTabsterWithConfig(targetDocument);
if (tabster) {
factoryResultRef.current = factory(tabster);
return ()=>{
disposeTabster(tabster);
factoryResultRef.current = null;
};
}
}, [
targetDocument,
factory
]);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line
const previousFactory = usePrevious(factory);
if (previousFactory !== null && previousFactory !== factory) {
throw new Error([
'@fluentui/react-tabster: ',
'The factory function passed to useTabster has changed. This should not ever happen.'
].join('\n'));
}
}
return factoryResultRef;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useTabster.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createTabster, disposeTabster, Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { getParent, useIsomorphicLayoutEffect, usePrevious } from '@fluentui/react-utilities';\n\ninterface WindowWithTabsterShadowDOMAPI extends Window {\n __tabsterShadowDOMAPI?: TabsterTypes.DOMAPI;\n}\n\ntype UseTabsterFactory<FactoryResult> = (tabster: TabsterTypes.TabsterCore) => FactoryResult;\n\nconst DEFAULT_FACTORY: UseTabsterFactory<TabsterTypes.TabsterCore> = tabster => {\n return tabster;\n};\n\n/**\n * Creates a tabster instance with the provided configuration\n *\n * @internal\n * @param targetDocument\n */\nexport function createTabsterWithConfig(targetDocument: Document | undefined): TabsterTypes.TabsterCore | undefined {\n const defaultView = targetDocument?.defaultView || undefined;\n const shadowDOMAPI = (defaultView as WindowWithTabsterShadowDOMAPI | undefined)?.__tabsterShadowDOMAPI;\n\n if (defaultView) {\n return createTabster(defaultView, {\n autoRoot: {},\n controlTab: false,\n getParent,\n // The non-undefined return value of checkUncontrolledCompletely() dominates the value that the element might\n // have in its `uncontrolled: { completely: true }` part of the tabster attribute. We must make sure to return\n // undefined if we want the value from tabster attribute to be respected.\n checkUncontrolledCompletely: element =>\n element.firstElementChild?.hasAttribute('data-is-focus-trap-zone-bumper') === true || undefined,\n DOMAPI: shadowDOMAPI,\n });\n }\n}\n\n/**\n * Tries to get a tabster instance on the current window or creates a new one\n * Since Tabster is single instance only, feel free to call this hook to ensure Tabster exists if necessary\n *\n * @internal\n * @returns Tabster a ref to core instance or a factory result\n */\nexport function useTabster(): React.RefObject<TabsterTypes.TabsterCore | null>;\nexport function useTabster<FactoryResult>(\n factory: UseTabsterFactory<FactoryResult>,\n): React.RefObject<FactoryResult | null>;\n\nexport function useTabster<FactoryResult>(factory = DEFAULT_FACTORY): React.RefObject<FactoryResult | null> {\n const { targetDocument } = useFluent();\n const factoryResultRef = React.useRef<FactoryResult | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n const tabster = createTabsterWithConfig(targetDocument);\n\n if (tabster) {\n factoryResultRef.current = factory(tabster) as FactoryResult;\n\n return () => {\n disposeTabster(tabster);\n factoryResultRef.current = null;\n };\n }\n }, [targetDocument, factory]);\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line\n const previousFactory = usePrevious(factory);\n\n if (previousFactory !== null && previousFactory !== factory) {\n throw new Error(\n [\n '@fluentui/react-tabster: ',\n 'The factory function passed to useTabster has changed. This should not ever happen.',\n ].join('\\n'),\n );\n }\n }\n\n return factoryResultRef;\n}\n"],"names":["React","createTabster","disposeTabster","useFluent_unstable","useFluent","getParent","useIsomorphicLayoutEffect","usePrevious","DEFAULT_FACTORY","tabster","createTabsterWithConfig","targetDocument","defaultView","undefined","shadowDOMAPI","__tabsterShadowDOMAPI","autoRoot","controlTab","checkUncontrolledCompletely","element","firstElementChild","hasAttribute","DOMAPI","useTabster","factory","factoryResultRef","useRef","current","process","env","NODE_ENV","previousFactory","Error","join"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,cAAc,QAA+B,UAAU;AAC/E,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,SAAS,EAAEC,yBAAyB,EAAEC,WAAW,QAAQ,4BAA4B;AAQ9F,MAAMC,kBAA+DC,CAAAA;IACnE,OAAOA;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASC,wBAAwBC,cAAoC;IAC1E,MAAMC,cAAcD,CAAAA,2BAAAA,qCAAAA,eAAgBC,WAAW,KAAIC;IACnD,MAAMC,eAAgBF,wBAAAA,kCAAD,AAACA,YAA2DG,qBAAqB;IAEtG,IAAIH,aAAa;QACf,OAAOX,cAAcW,aAAa;YAChCI,UAAU,CAAC;YACXC,YAAY;YACZZ;YACA,6GAA6G;YAC7G,8GAA8G;YAC9G,yEAAyE;YACzEa,6BAA6BC,CAAAA;oBAC3BA;uBAAAA,EAAAA,6BAAAA,QAAQC,iBAAiB,cAAzBD,iDAAAA,2BAA2BE,YAAY,CAAC,uCAAsC,QAAQR;;YACxFS,QAAQR;QACV;IACF;AACF;AAcA,OAAO,SAASS,WAA0BC,UAAUhB,eAAe;IACjE,MAAM,EAAEG,cAAc,EAAE,GAAGP;IAC3B,MAAMqB,mBAAmBzB,MAAM0B,MAAM,CAAuB;IAE5DpB,0BAA0B;QACxB,MAAMG,UAAUC,wBAAwBC;QAExC,IAAIF,SAAS;YACXgB,iBAAiBE,OAAO,GAAGH,QAAQf;YAEnC,OAAO;gBACLP,eAAeO;gBACfgB,iBAAiBE,OAAO,GAAG;YAC7B;QACF;IACF,GAAG;QAAChB;QAAgBa;KAAQ;IAE5B,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,2BAA2B;QAC3B,MAAMC,kBAAkBxB,YAAYiB;QAEpC,IAAIO,oBAAoB,QAAQA,oBAAoBP,SAAS;YAC3D,MAAM,IAAIQ,MACR;gBACE;gBACA;aACD,CAACC,IAAI,CAAC;QAEX;IACF;IAEA,OAAOR;AACT"}

View File

@@ -0,0 +1,18 @@
'use client';
import { getTabsterAttribute, TABSTER_ATTRIBUTE_NAME } from 'tabster';
import { useTabster } from './useTabster';
import * as React from 'react';
/**
* @internal
* Hook that returns tabster attributes while ensuring tabster exists
*/ export const useTabsterAttributes = (props)=>{
// A tabster instance is not necessary to generate tabster attributes
// but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same
useTabster();
const strAttr = getTabsterAttribute(props, true);
return React.useMemo(()=>({
[TABSTER_ATTRIBUTE_NAME]: strAttr
}), [
strAttr
]);
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useTabsterAttributes.ts"],"sourcesContent":["'use client';\n\nimport { getTabsterAttribute, Types as TabsterTypes, TABSTER_ATTRIBUTE_NAME } from 'tabster';\nimport { useTabster } from './useTabster';\nimport * as React from 'react';\n\n/**\n * @internal\n * Hook that returns tabster attributes while ensuring tabster exists\n */\nexport const useTabsterAttributes = (props: TabsterTypes.TabsterAttributeProps): TabsterTypes.TabsterDOMAttribute => {\n // A tabster instance is not necessary to generate tabster attributes\n // but calling the hook will ensure that a tabster instance exists internally and avoids consumers doing the same\n useTabster();\n\n const strAttr = getTabsterAttribute(props, true);\n\n return React.useMemo(\n () => ({\n [TABSTER_ATTRIBUTE_NAME]: strAttr,\n }),\n [strAttr],\n );\n};\n"],"names":["getTabsterAttribute","TABSTER_ATTRIBUTE_NAME","useTabster","React","useTabsterAttributes","props","strAttr","useMemo"],"mappings":"AAAA;AAEA,SAASA,mBAAmB,EAAyBC,sBAAsB,QAAQ,UAAU;AAC7F,SAASC,UAAU,QAAQ,eAAe;AAC1C,YAAYC,WAAW,QAAQ;AAE/B;;;CAGC,GACD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,qEAAqE;IACrE,iHAAiH;IACjHH;IAEA,MAAMI,UAAUN,oBAAoBK,OAAO;IAE3C,OAAOF,MAAMI,OAAO,CAClB,IAAO,CAAA;YACL,CAACN,uBAAuB,EAAEK;QAC5B,CAAA,GACA;QAACA;KAAQ;AAEb,EAAE"}

View File

@@ -0,0 +1,12 @@
'use client';
import { getTabsterAttribute } from 'tabster';
import { useTabster } from './useTabster';
/**
* Designates an area where tabster does not control focus
* @returns Attribute to apply to the target element that should be uncontrolled by tabster
*/ export function useUncontrolledFocus() {
useTabster();
return getTabsterAttribute({
uncontrolled: {}
});
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useUncontrolledFocus.ts"],"sourcesContent":["'use client';\n\nimport { getTabsterAttribute, Types as TabsterTypes } from 'tabster';\nimport { useTabster } from './useTabster';\n\n/**\n * Designates an area where tabster does not control focus\n * @returns Attribute to apply to the target element that should be uncontrolled by tabster\n */\nexport function useUncontrolledFocus(): TabsterTypes.TabsterDOMAttribute {\n useTabster();\n\n return getTabsterAttribute({ uncontrolled: {} });\n}\n"],"names":["getTabsterAttribute","useTabster","useUncontrolledFocus","uncontrolled"],"mappings":"AAAA;AAEA,SAASA,mBAAmB,QAA+B,UAAU;AACrE,SAASC,UAAU,QAAQ,eAAe;AAE1C;;;CAGC,GACD,OAAO,SAASC;IACdD;IAEA,OAAOD,oBAAoB;QAAEG,cAAc,CAAC;IAAE;AAChD"}