@redsift/design-system 12.6.6-alpha.2 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +20 -8
- package/_internal/AppContainer.js +1 -1
- package/_internal/AppContainer.js.map +1 -1
- package/_internal/Button2.js +1 -1
- package/_internal/Button2.js.map +1 -1
- package/_internal/Checkbox2.js +8 -3
- package/_internal/Checkbox2.js.map +1 -1
- package/_internal/DetailedCard.js +17 -1352
- package/_internal/DetailedCard.js.map +1 -1
- package/_internal/DetailedCardCollapsibleSectionItems.js +14 -4
- package/_internal/DetailedCardCollapsibleSectionItems.js.map +1 -1
- package/_internal/DetailedCardSection.js +4 -2
- package/_internal/DetailedCardSection.js.map +1 -1
- package/_internal/IconButton.js +1 -1
- package/_internal/IconButton.js.map +1 -1
- package/_internal/Item2.js +2 -2
- package/_internal/Item2.js.map +1 -1
- package/_internal/LinkButton.js +1 -1
- package/_internal/LinkButton.js.map +1 -1
- package/_internal/Listbox2.js +5 -5
- package/_internal/Listbox2.js.map +1 -1
- package/_internal/NumberField.js +2 -0
- package/_internal/NumberField.js.map +1 -1
- package/_internal/Radio2.js +14 -7
- package/_internal/Radio2.js.map +1 -1
- package/_internal/RadioGroup.js +6 -1
- package/_internal/RadioGroup.js.map +1 -1
- package/_internal/SideNavigationMenu.js +9 -4
- package/_internal/SideNavigationMenu.js.map +1 -1
- package/_internal/SideNavigationMenuItem.js +2 -2
- package/_internal/SideNavigationMenuItem.js.map +1 -1
- package/_internal/Switch2.js +8 -3
- package/_internal/Switch2.js.map +1 -1
- package/_internal/Tabs2.js.map +1 -1
- package/_internal/TextArea.js +5 -1
- package/_internal/TextArea.js.map +1 -1
- package/_internal/TextField.js +5 -1
- package/_internal/TextField.js.map +1 -1
- package/_internal/context.js.map +1 -1
- package/_internal/filterComponents.js +3 -0
- package/_internal/filterComponents.js.map +1 -1
- package/_internal/getElementRef.js +25 -0
- package/_internal/getElementRef.js.map +1 -0
- package/_internal/getTextWidth.js +32 -0
- package/_internal/getTextWidth.js.map +1 -0
- package/_internal/isComponent.js +3 -0
- package/_internal/isComponent.js.map +1 -1
- package/_internal/reactVersion.js +14 -0
- package/_internal/reactVersion.js.map +1 -0
- package/_internal/styles4.js +72 -72
- package/_internal/styles4.js.map +1 -1
- package/_internal/types.js.map +1 -1
- package/_internal/useFocusOnListItem.js +1 -1
- package/_internal/useFocusOnListItem.js.map +1 -1
- package/_internal/useId.js +1 -1
- package/_internal/useId.js.map +1 -1
- package/_internal/useListboxItem.js.map +1 -1
- package/_internal/useSideNavigationMenuBar.js +2 -2
- package/_internal/useSideNavigationMenuBar.js.map +1 -1
- package/_internal/warnIfNoAccessibleLabelFound.js.map +1 -1
- package/index.d.ts +48 -24
- package/index.js +3 -31
- package/index.js.map +1 -1
- package/package.json +18 -26
package/_internal/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../../src/react-aria/react-aria/i18n/utils.ts","../../src/react-aria/react-aria/ssr/SSRProvider.tsx","../../src/react-aria/react-aria/i18n/useDefaultLocale.ts","../../src/react-aria/react-aria/i18n/context.tsx"],"sourcesContent":["/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// https://en.wikipedia.org/wiki/Right-to-left\nconst RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);\nconst RTL_LANGS = new Set([\n 'ae',\n 'ar',\n 'arc',\n 'bcc',\n 'bqi',\n 'ckb',\n 'dv',\n 'fa',\n 'glk',\n 'he',\n 'ku',\n 'mzn',\n 'nqo',\n 'pnb',\n 'ps',\n 'sd',\n 'ug',\n 'ur',\n 'yi',\n]);\n\n/**\n * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.\n */\nexport function isRTL(localeString: string) {\n // If the Intl.Locale API is available, use it to get the locale's text direction.\n // @ts-ignore\n if (Intl.Locale) {\n let locale = new Intl.Locale(localeString).maximize();\n\n // Use the text info object to get the direction if possible.\n // @ts-ignore - this was implemented as a property by some browsers before it was standardized as a function.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo\n let textInfo = typeof locale.getTextInfo === 'function' ? locale.getTextInfo() : locale.textInfo;\n if (textInfo) {\n return textInfo.direction === 'rtl';\n }\n\n // Fallback: guess using the script.\n // This is more accurate than guessing by language, since languages can be written in multiple scripts.\n if (locale.script) {\n return RTL_SCRIPTS.has(locale.script);\n }\n }\n\n // If not, just guess by the language (first part of the locale)\n let lang = localeString.split('-')[0];\n return RTL_LANGS.has(lang);\n}\n","/* eslint-disable prefer-const */\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\nimport React, { ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState } from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string;\n current: number;\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0,\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\nconst IsSSRContext = React.createContext(false);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode;\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(\n () => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0,\n }),\n [cur, counter]\n );\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n <IsSSRContext.Provider value={isSSR}>{props.children}</IsSSRContext.Provider>\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState,\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n ref.current = ++ctx.current;\n }\n\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn(\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.'\n );\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useContext(IsSSRContext);\n}\n","/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Direction } from '../../react-types/shared';\nimport { isRTL } from './utils';\nimport { useEffect, useState } from 'react';\nimport { useIsSSR } from '../ssr';\n\nexport interface Locale {\n /** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */\n locale: string;\n /** The writing direction for the locale. */\n direction: Direction;\n}\n\n// Locale passed from server by PackageLocalizationProvider.\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\n\n/**\n * Gets the locale setting of the browser.\n */\nexport function getDefaultLocale(): Locale {\n let locale =\n (typeof window !== 'undefined' && window[localeSymbol]) ||\n // @ts-ignore\n (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) ||\n 'en-US';\n\n try {\n // @ts-ignore\n Intl.DateTimeFormat.supportedLocalesOf([locale]);\n } catch (_err) {\n locale = 'en-US';\n }\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr',\n };\n}\n\nlet currentLocale = getDefaultLocale();\nlet listeners = new Set<(locale: Locale) => void>();\n\nfunction updateLocale() {\n currentLocale = getDefaultLocale();\n for (let listener of listeners) {\n listener(currentLocale);\n }\n}\n\n/**\n * Returns the current browser/system language, and updates when it changes.\n */\nexport function useDefaultLocale(): Locale {\n let isSSR = useIsSSR();\n let [defaultLocale, setDefaultLocale] = useState(currentLocale);\n\n useEffect(() => {\n if (listeners.size === 0) {\n window.addEventListener('languagechange', updateLocale);\n }\n\n listeners.add(setDefaultLocale);\n\n return () => {\n listeners.delete(setDefaultLocale);\n if (listeners.size === 0) {\n window.removeEventListener('languagechange', updateLocale);\n }\n };\n }, []);\n\n // We cannot determine the browser's language on the server, so default to\n // en-US. This will be updated after hydration on the client to the correct value.\n if (isSSR) {\n return {\n locale: 'en-US',\n direction: 'ltr',\n };\n }\n\n return defaultLocale;\n}\n","/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { isRTL } from './utils';\nimport { Locale, useDefaultLocale } from './useDefaultLocale';\nimport React, { ReactNode, useContext } from 'react';\n\nexport interface I18nProviderProps {\n /** Contents that should have the locale applied. */\n children: ReactNode;\n /** The locale to apply to the children. */\n locale?: string;\n}\n\nconst I18nContext = React.createContext<Locale | null>(null);\n\n/**\n * Provides the locale for the application to all child components.\n */\nexport function I18nProvider(props: I18nProviderProps) {\n let { locale, children } = props;\n let defaultLocale = useDefaultLocale();\n\n let value: Locale = React.useMemo(() => {\n if (!locale) {\n return defaultLocale;\n }\n\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr',\n };\n }, [defaultLocale, locale]);\n\n return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;\n}\n\n/**\n * Returns the current locale and layout direction.\n */\nexport function useLocale(): Locale {\n let defaultLocale = useDefaultLocale();\n let context = useContext(I18nContext);\n return context || defaultLocale;\n}\n"],"names":["RTL_SCRIPTS","Set","RTL_LANGS","isRTL","localeString","Intl","Locale","locale","maximize","textInfo","getTextInfo","direction","script","has","lang","split","defaultContext","prefix","String","Math","round","random","current","SSRContext","React","createContext","IsSSRContext","LegacySSRProvider","props","cur","useContext","counter","useCounter","isSSR","setIsSSR","useState","value","useMemo","document","useLayoutEffect","createElement","Provider","children","warnedAboutSSRProvider","SSRProvider","process","env","NODE_ENV","console","warn","Fragment","canUseDOM","Boolean","window","componentIds","WeakMap","isDisabled","arguments","length","undefined","ctx","ref","useRef","_React$__SECRET_INTER","_React$__SECRET_INTER2","currentOwner","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentOwner","prevComponentValue","get","set","id","state","memoizedState","delete","useLegacySSRSafeId","defaultId","useModernSSRSafeId","useId","didSSR","useIsSSR","useSSRSafeId","getSnapshot","getServerSnapshot","subscribe","onStoreChange","localeSymbol","Symbol","for","getDefaultLocale","navigator","language","userLanguage","DateTimeFormat","supportedLocalesOf","_err","currentLocale","listeners","updateLocale","listener","useDefaultLocale","defaultLocale","setDefaultLocale","useEffect","size","addEventListener","add","removeEventListener","I18nContext","I18nProvider","useLocale","context"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAC7G,MAAMC,SAAS,GAAG,IAAID,GAAG,CAAC,CACxB,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,CACL,CAAC,CAAA;;AAEF;AACA;AACA;AACO,SAASE,KAAKA,CAACC,YAAoB,EAAE;AAC1C;AACA;EACA,IAAIC,IAAI,CAACC,MAAM,EAAE;AACf,IAAA,IAAIC,MAAM,GAAG,IAAIF,IAAI,CAACC,MAAM,CAACF,YAAY,CAAC,CAACI,QAAQ,EAAE,CAAA;;AAErD;AACA;AACA;AACA,IAAA,IAAIC,QAAQ,GAAG,OAAOF,MAAM,CAACG,WAAW,KAAK,UAAU,GAAGH,MAAM,CAACG,WAAW,EAAE,GAAGH,MAAM,CAACE,QAAQ,CAAA;AAChG,IAAA,IAAIA,QAAQ,EAAE;AACZ,MAAA,OAAOA,QAAQ,CAACE,SAAS,KAAK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EAAE,KAAA;KACZ,CAAA;AACH,GAAA;AAEA,EAAA,OAAO0F,aAAa,CAAA;AACtB;;AC7FA;AAyBA,MAAMO,WAAW,gBAAGpF,cAAK,CAACC,aAAa,CAAgB,IAAI,CAAC,CAAA;;AAE5D;AACA;AACA;AACO,SAASoF,YAAYA,CAACjF,KAAwB,EAAE;EACrD,IAAI;IAAErB,MAAM;AAAEmC,IAAAA,QAAAA;AAAS,GAAC,GAAGd,KAAK,CAAA;AAChC,EAAA,IAAIyE,aAAa,GAAGD,gBAAgB,EAAE,CAAA;AAEtC,EAAA,IAAIhE,KAAa,GAAGZ,cAAK,CAACa,OAAO,CAAC,MAAM;IACtC,IAAI,CAAC9B,MAAM,EAAE;AACX,MAAA,OAAO8F,aAAa,CAAA;AACtB,KAAA;IAEA,OAAO;MACL9F,MAAM;AACNI,MAAAA,SAAS,EAAER,KAAK,CAACI,MAAM,CAAC,GAAG,KAAK,GAAG,KAAA;KACpC,CAAA;AACH,GAAC,EAAE,CAAC8F,aAAa,EAAE9F,MAAM,CAAC,CAAC,CAAA;AAE3B,EAAA,oBAAOiB,cAAA,CAAAgB,aAAA,CAACoE,WAAW,CAACnE,QAAQ,EAAA;AAACL,IAAAA,KAAK,EAAEA,KAAAA;AAAM,GAAA,EAAEM,QAA+B,CAAC,CAAA;AAC9E,CAAA;;AAEA;AACA;AACA;AACO,SAASoE,SAASA,GAAW;AAClC,EAAA,IAAIT,aAAa,GAAGD,gBAAgB,EAAE,CAAA;AACtC,EAAA,IAAIW,OAAO,GAAGjF,UAAU,CAAC8E,WAAW,CAAC,CAAA;EACrC,OAAOG,OAAO,IAAIV,aAAa,CAAA;AACjC;;;;"}
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../src/react-aria/react-aria/i18n/utils.ts","../../src/react-aria/react-aria/ssr/SSRProvider.tsx","../../src/react-aria/react-aria/i18n/useDefaultLocale.ts","../../src/react-aria/react-aria/i18n/context.tsx"],"sourcesContent":["/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// https://en.wikipedia.org/wiki/Right-to-left\nconst RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);\nconst RTL_LANGS = new Set([\n 'ae',\n 'ar',\n 'arc',\n 'bcc',\n 'bqi',\n 'ckb',\n 'dv',\n 'fa',\n 'glk',\n 'he',\n 'ku',\n 'mzn',\n 'nqo',\n 'pnb',\n 'ps',\n 'sd',\n 'ug',\n 'ur',\n 'yi',\n]);\n\n/**\n * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.\n */\nexport function isRTL(localeString: string) {\n // If the Intl.Locale API is available, use it to get the locale's text direction.\n // @ts-ignore\n if (Intl.Locale) {\n let locale = new Intl.Locale(localeString).maximize();\n\n // Use the text info object to get the direction if possible.\n // @ts-ignore - this was implemented as a property by some browsers before it was standardized as a function.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo\n let textInfo = typeof locale.getTextInfo === 'function' ? locale.getTextInfo() : locale.textInfo;\n if (textInfo) {\n return textInfo.direction === 'rtl';\n }\n\n // Fallback: guess using the script.\n // This is more accurate than guessing by language, since languages can be written in multiple scripts.\n if (locale.script) {\n return RTL_SCRIPTS.has(locale.script);\n }\n }\n\n // If not, just guess by the language (first part of the locale)\n let lang = localeString.split('-')[0];\n return RTL_LANGS.has(lang);\n}\n","/* eslint-disable prefer-const */\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\nimport React, { ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState } from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string;\n current: number;\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0,\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\nconst IsSSRContext = React.createContext(false);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode;\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): React.JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(\n () => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0,\n }),\n [cur, counter]\n );\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n <IsSSRContext.Provider value={isSSR}>{props.children}</IsSSRContext.Provider>\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): React.JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState,\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n ref.current = ++ctx.current;\n }\n\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn(\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.'\n );\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useContext(IsSSRContext);\n}\n","/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Direction } from '../../react-types/shared';\nimport { isRTL } from './utils';\nimport { useEffect, useState } from 'react';\nimport { useIsSSR } from '../ssr';\n\nexport interface Locale {\n /** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */\n locale: string;\n /** The writing direction for the locale. */\n direction: Direction;\n}\n\n// Locale passed from server by PackageLocalizationProvider.\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\n\n/**\n * Gets the locale setting of the browser.\n */\nexport function getDefaultLocale(): Locale {\n let locale =\n (typeof window !== 'undefined' && window[localeSymbol]) ||\n // @ts-ignore\n (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) ||\n 'en-US';\n\n try {\n // @ts-ignore\n Intl.DateTimeFormat.supportedLocalesOf([locale]);\n } catch (_err) {\n locale = 'en-US';\n }\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr',\n };\n}\n\nlet currentLocale = getDefaultLocale();\nlet listeners = new Set<(locale: Locale) => void>();\n\nfunction updateLocale() {\n currentLocale = getDefaultLocale();\n for (let listener of listeners) {\n listener(currentLocale);\n }\n}\n\n/**\n * Returns the current browser/system language, and updates when it changes.\n */\nexport function useDefaultLocale(): Locale {\n let isSSR = useIsSSR();\n let [defaultLocale, setDefaultLocale] = useState(currentLocale);\n\n useEffect(() => {\n if (listeners.size === 0) {\n window.addEventListener('languagechange', updateLocale);\n }\n\n listeners.add(setDefaultLocale);\n\n return () => {\n listeners.delete(setDefaultLocale);\n if (listeners.size === 0) {\n window.removeEventListener('languagechange', updateLocale);\n }\n };\n }, []);\n\n // We cannot determine the browser's language on the server, so default to\n // en-US. This will be updated after hydration on the client to the correct value.\n if (isSSR) {\n return {\n locale: 'en-US',\n direction: 'ltr',\n };\n }\n\n return defaultLocale;\n}\n","/* eslint-disable prefer-const */\n// @ts-nocheck\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { isRTL } from './utils';\nimport { Locale, useDefaultLocale } from './useDefaultLocale';\nimport React, { ReactNode, useContext } from 'react';\n\nexport interface I18nProviderProps {\n /** Contents that should have the locale applied. */\n children: ReactNode;\n /** The locale to apply to the children. */\n locale?: string;\n}\n\nconst I18nContext = React.createContext<Locale | null>(null);\n\n/**\n * Provides the locale for the application to all child components.\n */\nexport function I18nProvider(props: I18nProviderProps) {\n let { locale, children } = props;\n let defaultLocale = useDefaultLocale();\n\n let value: Locale = React.useMemo(() => {\n if (!locale) {\n return defaultLocale;\n }\n\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr',\n };\n }, [defaultLocale, locale]);\n\n return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;\n}\n\n/**\n * Returns the current locale and layout direction.\n */\nexport function useLocale(): Locale {\n let defaultLocale = useDefaultLocale();\n let context = useContext(I18nContext);\n return context || defaultLocale;\n}\n"],"names":["RTL_SCRIPTS","Set","RTL_LANGS","isRTL","localeString","Intl","Locale","locale","maximize","textInfo","getTextInfo","direction","script","has","lang","split","defaultContext","prefix","String","Math","round","random","current","SSRContext","React","createContext","IsSSRContext","LegacySSRProvider","props","cur","useContext","counter","useCounter","isSSR","setIsSSR","useState","value","useMemo","document","useLayoutEffect","createElement","Provider","children","warnedAboutSSRProvider","SSRProvider","process","env","NODE_ENV","console","warn","Fragment","canUseDOM","Boolean","window","componentIds","WeakMap","isDisabled","arguments","length","undefined","ctx","ref","useRef","_React$__SECRET_INTER","_React$__SECRET_INTER2","currentOwner","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentOwner","prevComponentValue","get","set","id","state","memoizedState","delete","useLegacySSRSafeId","defaultId","useModernSSRSafeId","useId","didSSR","useIsSSR","useSSRSafeId","getSnapshot","getServerSnapshot","subscribe","onStoreChange","localeSymbol","Symbol","for","getDefaultLocale","navigator","language","userLanguage","DateTimeFormat","supportedLocalesOf","_err","currentLocale","listeners","updateLocale","listener","useDefaultLocale","defaultLocale","setDefaultLocale","useEffect","size","addEventListener","add","removeEventListener","I18nContext","I18nProvider","useLocale","context"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAC7G,MAAMC,SAAS,GAAG,IAAID,GAAG,CAAC,CACxB,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,IAA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AEA,KAAAA;AAAM,GAAA,EAAEM,QAA+B,CAAC,CAAA;AAC9E,CAAA;;AAEA;AACA;AACA;AACO,SAASoE,SAASA,GAAW;AAClC,EAAA,IAAIT,aAAa,GAAGD,gBAAgB,EAAE,CAAA;AACtC,EAAA,IAAIW,OAAO,GAAGjF,UAAU,CAAC8E,WAAW,CAAC,CAAA;EACrC,OAAOG,OAAO,IAAIV,aAAa,CAAA;AACjC;;;;"}
|
|
@@ -4,6 +4,9 @@ import { i as isComponent } from './isComponent.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Create an array containing only valid and specific components.
|
|
6
6
|
*
|
|
7
|
+
* The elements' props are `any`, spelled out: a bare `ReactElement` means `ReactElement<unknown>` under
|
|
8
|
+
* @types/react 19, where it meant `ReactElement<any>` under 18.
|
|
9
|
+
*
|
|
7
10
|
* @param component React function component or the component name
|
|
8
11
|
* @return an array of components
|
|
9
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterComponents.js","sources":["../../src/utils/filterComponents.ts"],"sourcesContent":["import React, { ReactNode, ReactElement } from 'react';\nimport { Comp } from '../types';\nimport { isComponent } from './isComponent';\n\n/**\n * Create an array containing only valid and specific components.\n *\n * @param component React function component or the component name\n * @return an array of components\n */\nexport const filterComponents =\n (component: Comp<any, any> | string | Comp<any, any>[] | string[]) =>\n (children: ReactNode): ReactElement[] => {\n const components = Array.isArray(component) ? component : [component];\n const childArray: ReactElement[] = [];\n\n React.Children.forEach(children, (child) => {\n components.forEach((comp) => {\n if (isComponent(comp)(child)) {\n childArray.push(child);\n }\n });\n });\n\n return childArray;\n };\n"],"names":["filterComponents","component","children","components","Array","isArray","childArray","React","Children","forEach","child","comp","isComponent","push"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;MACaA,gBAAgB,GAC1BC,SAAgE,IAChEC,QAAmB,
|
|
1
|
+
{"version":3,"file":"filterComponents.js","sources":["../../src/utils/filterComponents.ts"],"sourcesContent":["import React, { ReactNode, ReactElement } from 'react';\nimport { Comp } from '../types';\nimport { isComponent } from './isComponent';\n\n/**\n * Create an array containing only valid and specific components.\n *\n * The elements' props are `any`, spelled out: a bare `ReactElement` means `ReactElement<unknown>` under\n * @types/react 19, where it meant `ReactElement<any>` under 18.\n *\n * @param component React function component or the component name\n * @return an array of components\n */\nexport const filterComponents =\n (component: Comp<any, any> | string | Comp<any, any>[] | string[]) =>\n (children: ReactNode): ReactElement<any>[] => {\n const components = Array.isArray(component) ? component : [component];\n const childArray: ReactElement<any>[] = [];\n\n React.Children.forEach(children, (child) => {\n components.forEach((comp) => {\n if (isComponent(comp)(child)) {\n childArray.push(child);\n }\n });\n });\n\n return childArray;\n };\n"],"names":["filterComponents","component","children","components","Array","isArray","childArray","React","Children","forEach","child","comp","isComponent","push"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,gBAAgB,GAC1BC,SAAgE,IAChEC,QAAmB,IAA0B;AAC5C,EAAA,MAAMC,UAAU,GAAGC,KAAK,CAACC,OAAO,CAACJ,SAAS,CAAC,GAAGA,SAAS,GAAG,CAACA,SAAS,CAAC,CAAA;EACrE,MAAMK,UAA+B,GAAG,EAAE,CAAA;EAE1CC,cAAK,CAACC,QAAQ,CAACC,OAAO,CAACP,QAAQ,EAAGQ,KAAK,IAAK;AAC1CP,IAAAA,UAAU,CAACM,OAAO,CAAEE,IAAI,IAAK;AAC3B,MAAA,IAAIC,WAAW,CAACD,IAAI,CAAC,CAACD,KAAK,CAAC,EAAE;AAC5BJ,QAAAA,UAAU,CAACO,IAAI,CAACH,KAAK,CAAC,CAAA;AACxB,OAAA;AACF,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOJ,UAAU,CAAA;AACnB;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { I as IS_REACT_19_OR_LATER } from './reactVersion.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ref an element was created with, under React 18 and React 19.
|
|
6
|
+
*
|
|
7
|
+
* React 18 keeps it on the element (`element.ref`). React 19 makes `ref` an ordinary prop
|
|
8
|
+
* (`element.props.ref`), and reading `element.ref` there logs a deprecation warning. A component that
|
|
9
|
+
* clones its child and merges the child's ref with its own must read it from the right place, and must
|
|
10
|
+
* pass its merged ref after the child's props, which include `ref` from React 19 onwards.
|
|
11
|
+
*
|
|
12
|
+
* @param element the element, typically a component's `children`, which may also be any other value
|
|
13
|
+
* @return the element's ref, or undefined when it has none or is not an element
|
|
14
|
+
*/
|
|
15
|
+
const getElementRef = element => {
|
|
16
|
+
var _node$props$ref, _ref;
|
|
17
|
+
const node = element;
|
|
18
|
+
if (! /*#__PURE__*/React__default.isValidElement(node)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return IS_REACT_19_OR_LATER ? (_node$props$ref = node.props.ref) !== null && _node$props$ref !== void 0 ? _node$props$ref : undefined : (_ref = node.ref) !== null && _ref !== void 0 ? _ref : undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { getElementRef as g };
|
|
25
|
+
//# sourceMappingURL=getElementRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getElementRef.js","sources":["../../src/utils/getElementRef.ts"],"sourcesContent":["import React, { Ref } from 'react';\nimport { IS_REACT_19_OR_LATER } from './reactVersion';\n\n/**\n * The ref an element was created with, under React 18 and React 19.\n *\n * React 18 keeps it on the element (`element.ref`). React 19 makes `ref` an ordinary prop\n * (`element.props.ref`), and reading `element.ref` there logs a deprecation warning. A component that\n * clones its child and merges the child's ref with its own must read it from the right place, and must\n * pass its merged ref after the child's props, which include `ref` from React 19 onwards.\n *\n * @param element the element, typically a component's `children`, which may also be any other value\n * @return the element's ref, or undefined when it has none or is not an element\n */\nexport const getElementRef = <T = unknown>(element: unknown): Ref<T> | undefined => {\n const node = element as object | null | undefined;\n if (!React.isValidElement<{ ref?: Ref<T> }>(node)) {\n return undefined;\n }\n return IS_REACT_19_OR_LATER\n ? node.props.ref ?? undefined\n : (node as unknown as { ref?: Ref<T> | null }).ref ?? undefined;\n};\n"],"names":["getElementRef","element","_node$props$ref","_ref","node","React","isValidElement","undefined","IS_REACT_19_OR_LATER","props","ref"],"mappings":";;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,MAAAA,aAAa,GAAiBC,OAAgB,IAAyB;EAAA,IAAAC,eAAA,EAAAC,IAAA,CAAA;EAClF,MAAMC,IAAI,GAAGH,OAAoC,CAAA;AACjD,EAAA,IAAI,eAACI,cAAK,CAACC,cAAc,CAAmBF,IAAI,CAAC,EAAE;AACjD,IAAA,OAAOG,SAAS,CAAA;AAClB,GAAA;EACA,OAAOC,oBAAoB,GAAAN,CAAAA,eAAA,GACvBE,IAAI,CAACK,KAAK,CAACC,GAAG,MAAAR,IAAAA,IAAAA,eAAA,KAAAA,KAAAA,CAAAA,GAAAA,eAAA,GAAIK,SAAS,GAAA,CAAAJ,IAAA,GAC1BC,IAAI,CAAwCM,GAAG,MAAA,IAAA,IAAAP,IAAA,KAAA,KAAA,CAAA,GAAAA,IAAA,GAAII,SAAS,CAAA;AACnE;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const getCssStyle = (element, prop) => {
|
|
2
|
+
return window.getComputedStyle(element, null).getPropertyValue(prop);
|
|
3
|
+
};
|
|
4
|
+
const getCanvasFont = function () {
|
|
5
|
+
let el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body;
|
|
6
|
+
const fontWeight = getCssStyle(el, 'font-weight') || 'normal';
|
|
7
|
+
const fontSize = getCssStyle(el, 'font-size') || '16px';
|
|
8
|
+
const fontFamily = getCssStyle(el, 'font-family') || 'Times New Roman';
|
|
9
|
+
return `${fontWeight} ${fontSize} ${fontFamily}`;
|
|
10
|
+
};
|
|
11
|
+
const getTextWidth = function (text, font) {
|
|
12
|
+
let angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
13
|
+
const canvas = document.createElement('canvas');
|
|
14
|
+
const context = canvas.getContext('2d');
|
|
15
|
+
context.font = font;
|
|
16
|
+
const metrics = context.measureText(text);
|
|
17
|
+
const radians = angle * (Math.PI / 180);
|
|
18
|
+
const cosTheta = Math.abs(Math.cos(radians));
|
|
19
|
+
const sinTheta = Math.abs(Math.sin(radians));
|
|
20
|
+
const boundingBoxHeight = metrics.width * sinTheta + 15 * cosTheta;
|
|
21
|
+
// console.log(text, metrics.width, boundingBoxHeight);
|
|
22
|
+
|
|
23
|
+
// return metrics.width;
|
|
24
|
+
return boundingBoxHeight;
|
|
25
|
+
};
|
|
26
|
+
const getMaxTextWidth = function (texts, font) {
|
|
27
|
+
let angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
28
|
+
return Math.max(...texts.map(text => getTextWidth(text, font, angle)));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { getCanvasFont as a, getTextWidth as b, getMaxTextWidth as c, getCssStyle as g };
|
|
32
|
+
//# sourceMappingURL=getTextWidth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTextWidth.js","sources":["../../src/utils/getTextWidth.ts"],"sourcesContent":["export const getCssStyle = (element: Element, prop: string) => {\n return window.getComputedStyle(element, null).getPropertyValue(prop);\n};\n\nexport const getCanvasFont = (el = document.body) => {\n const fontWeight = getCssStyle(el, 'font-weight') || 'normal';\n const fontSize = getCssStyle(el, 'font-size') || '16px';\n const fontFamily = getCssStyle(el, 'font-family') || 'Times New Roman';\n\n return `${fontWeight} ${fontSize} ${fontFamily}`;\n};\n\nexport const getTextWidth: (text: string, font: string, angle?: number) => number = (text, font, angle = 0) => {\n const canvas = document.createElement('canvas');\n const context = canvas.getContext('2d');\n context!.font = font;\n const metrics = context!.measureText(text);\n\n const radians = angle * (Math.PI / 180);\n const cosTheta = Math.abs(Math.cos(radians));\n const sinTheta = Math.abs(Math.sin(radians));\n\n const boundingBoxHeight = metrics.width * sinTheta + 15 * cosTheta;\n // console.log(text, metrics.width, boundingBoxHeight);\n\n // return metrics.width;\n return boundingBoxHeight;\n};\n\nexport const getMaxTextWidth: (texts: string[], font: string, angle?: number) => number = (texts, font, angle = 0) => {\n return Math.max(...texts.map((text) => getTextWidth(text, font, angle)));\n};\n"],"names":["getCssStyle","element","prop","window","getComputedStyle","getPropertyValue","getCanvasFont","el","arguments","length","undefined","document","body","fontWeight","fontSize","fontFamily","getTextWidth","text","font","angle","canvas","createElement","context","getContext","metrics","measureText","radians","Math","PI","cosTheta","abs","cos","sinTheta","sin","boundingBoxHeight","width","getMaxTextWidth","texts","max","map"],"mappings":"MAAaA,WAAW,GAAGA,CAACC,OAAgB,EAAEC,IAAY,KAAK;AAC7D,EAAA,OAAOC,MAAM,CAACC,gBAAgB,CAACH,OAAO,EAAE,IAAI,CAAC,CAACI,gBAAgB,CAACH,IAAI,CAAC,CAAA;AACtE,EAAC;AAEYI,MAAAA,aAAa,GAAG,YAAwB;AAAA,EAAA,IAAvBC,EAAE,GAAAC,SAAA,CAAAC,MAAA,GAAAD,CAAAA,IAAAA,SAAA,CAAAE,CAAAA,CAAAA,KAAAA,SAAA,GAAAF,SAAA,CAAGG,CAAAA,CAAAA,GAAAA,QAAQ,CAACC,IAAI,CAAA;EAC9C,MAAMC,UAAU,GAAGb,WAAW,CAACO,EAAE,EAAE,aAAa,CAAC,IAAI,QAAQ,CAAA;EAC7D,MAAMO,QAAQ,GAAGd,WAAW,CAACO,EAAE,EAAE,WAAW,CAAC,IAAI,MAAM,CAAA;EACvD,MAAMQ,UAAU,GAAGf,WAAW,CAACO,EAAE,EAAE,aAAa,CAAC,IAAI,iBAAiB,CAAA;AAEtE,EAAA,OAAQ,GAAEM,UAAW,CAAA,CAAA,EAAGC,QAAS,CAAA,CAAA,EAAGC,UAAW,CAAC,CAAA,CAAA;AAClD,EAAC;AAEM,MAAMC,YA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YAAY,CAACC,IAAI,EAAEC,IAAI,EAAEC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC1E;;;;"}
|
package/_internal/isComponent.js
CHANGED
|
@@ -3,6 +3,9 @@ import React__default from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a predicate function that checks if a ReactNode is a react element from the given component.
|
|
5
5
|
*
|
|
6
|
+
* The element's props are `any`, spelled out: a bare `ReactElement` means `ReactElement<unknown>` under
|
|
7
|
+
* @types/react 19. (A `ReactNode` narrowed by it keeps its own `ReactElement<unknown>` member there.)
|
|
8
|
+
*
|
|
6
9
|
* @param component React function component or the component name
|
|
7
10
|
* @return predicate returning true if value is instance of the component
|
|
8
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isComponent.js","sources":["../../src/utils/isComponent.ts"],"sourcesContent":["import React, { ReactNode, ReactElement } from 'react';\nimport { Comp } from '../types';\n\n/**\n * Create a predicate function that checks if a ReactNode is a react element from the given component.\n *\n * @param component React function component or the component name\n * @return predicate returning true if value is instance of the component\n */\nexport const isComponent =\n <C>(component: Comp<C, any> | string) =>\n (instance: ReactNode): instance is ReactElement => {\n const componentName = typeof component === 'string' ? component : component.displayName;\n\n return React.isValidElement(instance) && (instance.type as Comp<any>).displayName === componentName;\n };\n"],"names":["isComponent","component","instance","componentName","displayName","React","isValidElement","type"],"mappings":";;AAGA;AACA;AACA;AACA;AACA;AACA;MACaA,WAAW,GAClBC,SAAgC,IACnCC,QAAmB,
|
|
1
|
+
{"version":3,"file":"isComponent.js","sources":["../../src/utils/isComponent.ts"],"sourcesContent":["import React, { ReactNode, ReactElement } from 'react';\nimport { Comp } from '../types';\n\n/**\n * Create a predicate function that checks if a ReactNode is a react element from the given component.\n *\n * The element's props are `any`, spelled out: a bare `ReactElement` means `ReactElement<unknown>` under\n * @types/react 19. (A `ReactNode` narrowed by it keeps its own `ReactElement<unknown>` member there.)\n *\n * @param component React function component or the component name\n * @return predicate returning true if value is instance of the component\n */\nexport const isComponent =\n <C>(component: Comp<C, any> | string) =>\n (instance: ReactNode): instance is ReactElement<any> => {\n const componentName = typeof component === 'string' ? component : component.displayName;\n\n return React.isValidElement(instance) && (instance.type as Comp<any>).displayName === componentName;\n };\n"],"names":["isComponent","component","instance","componentName","displayName","React","isValidElement","type"],"mappings":";;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,WAAW,GAClBC,SAAgC,IACnCC,QAAmB,IAAoC;EACtD,MAAMC,aAAa,GAAG,OAAOF,SAAS,KAAK,QAAQ,GAAGA,SAAS,GAAGA,SAAS,CAACG,WAAW,CAAA;AAEvF,EAAA,oBAAOC,cAAK,CAACC,cAAc,CAACJ,QAAQ,CAAC,IAAKA,QAAQ,CAACK,IAAI,CAAeH,WAAW,KAAKD,aAAa,CAAA;AACrG;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether the React rendering this package is 19 or later, for the few places that must tell the two
|
|
5
|
+
* apart: an element's ref is a prop from 19 (`getElementRef`), and `inert` a boolean attribute
|
|
6
|
+
* (`SideNavigationMenu`).
|
|
7
|
+
*
|
|
8
|
+
* Not exported from the package entry point: it is an implementation detail, and a consumer has
|
|
9
|
+
* `React.version` itself.
|
|
10
|
+
*/
|
|
11
|
+
const IS_REACT_19_OR_LATER = parseInt(React__default.version, 10) >= 19;
|
|
12
|
+
|
|
13
|
+
export { IS_REACT_19_OR_LATER as I };
|
|
14
|
+
//# sourceMappingURL=reactVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactVersion.js","sources":["../../src/utils/reactVersion.ts"],"sourcesContent":["import React from 'react';\n\n/**\n * Whether the React rendering this package is 19 or later, for the few places that must tell the two\n * apart: an element's ref is a prop from 19 (`getElementRef`), and `inert` a boolean attribute\n * (`SideNavigationMenu`).\n *\n * Not exported from the package entry point: it is an implementation detail, and a consumer has\n * `React.version` itself.\n */\nexport const IS_REACT_19_OR_LATER = parseInt(React.version, 10) >= 19;\n"],"names":["IS_REACT_19_OR_LATER","parseInt","React","version"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,MAAAA,oBAAoB,GAAGC,QAAQ,CAACC,cAAK,CAACC,OAAO,EAAE,EAAE,CAAC,IAAI;;;;"}
|
package/_internal/styles4.js
CHANGED
|
@@ -42,85 +42,85 @@ const StyledLink = styled.a`
|
|
|
42
42
|
} = _ref2;
|
|
43
43
|
return !$isDisabled ? css`
|
|
44
44
|
${$color && $color === 'radar' ? css`
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);
|
|
46
|
+
background-clip: text;
|
|
47
|
+
color: transparent;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
49
|
+
path {
|
|
50
|
+
fill: url(#${$color}-gradient-default);
|
|
51
|
+
}
|
|
52
|
+
` : Object.keys(NotificationsColorPalette).indexOf($color) !== -1 ? css`
|
|
53
|
+
&,
|
|
54
|
+
.redsift-icon:not(.colored) {
|
|
55
|
+
color: var(--redsift-color-notifications-${$color}-primary);
|
|
56
|
+
}
|
|
57
|
+
` : Object.keys(NeutralColorPalette).indexOf($color) !== -1 ? css`
|
|
58
|
+
&,
|
|
59
|
+
.redsift-icon:not(.colored) {
|
|
60
|
+
color: var(--redsift-color-neutral-${$color});
|
|
61
|
+
}
|
|
62
|
+
` : Object.keys(ProductColorPalette).indexOf($color) !== -1 ? css`
|
|
63
|
+
&,
|
|
64
|
+
.redsift-icon:not(.colored) {
|
|
65
|
+
color: var(--redsift-color-product-${$color});
|
|
66
|
+
}
|
|
67
|
+
` : css`
|
|
68
|
+
&,
|
|
69
|
+
.redsift-icon:not(.colored) {
|
|
70
|
+
color: ${$color || css`var(--redsift-color-${$theme}-components-text-primary)`};
|
|
71
|
+
}
|
|
72
|
+
`}
|
|
73
73
|
|
|
74
74
|
${$color && $color === 'radar' && !$hasIcons ? css`
|
|
75
|
-
|
|
75
|
+
position: relative;
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
&:hover::before,
|
|
78
|
+
&:focus-visible::before {
|
|
79
|
+
content: '';
|
|
80
|
+
position: absolute;
|
|
81
|
+
bottom: 3px;
|
|
82
|
+
width: 100%;
|
|
83
|
+
left: 0;
|
|
84
|
+
height: 1px;
|
|
85
|
+
background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);
|
|
86
|
+
}
|
|
87
|
+
` : $color && $color === 'radar' && $hasIcons ? css`
|
|
88
|
+
position: relative;
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
.text::before {
|
|
91
|
+
content: '';
|
|
92
|
+
position: absolute;
|
|
93
|
+
bottom: 3px;
|
|
94
|
+
width: 100%;
|
|
95
|
+
left: 0;
|
|
96
|
+
height: 1px;
|
|
97
|
+
background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);
|
|
98
|
+
transform: scaleX(0);
|
|
99
|
+
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
&:hover .text::before,
|
|
102
|
+
.icon:hover + .text::before,
|
|
103
|
+
.text:hover::before {
|
|
104
|
+
transform: scaleX(1);
|
|
105
|
+
}
|
|
106
|
+
` : css`
|
|
107
|
+
text-decoration: underline;
|
|
108
|
+
text-decoration-color: transparent;
|
|
109
|
+
text-underline-offset: 2px;
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
111
|
+
&:hover,
|
|
112
|
+
&:focus-visible {
|
|
113
|
+
${Object.keys(NotificationsColorPalette).indexOf($color) !== -1 ? css`
|
|
114
|
+
text-decoration-color: var(--redsift-color-notifications-${$color}-primary);
|
|
115
|
+
` : Object.keys(NeutralColorPalette).indexOf($color) !== -1 ? css`
|
|
116
|
+
text-decoration-color: var(--redsift-color-neutral-${$color});
|
|
117
|
+
` : Object.keys(ProductColorPalette).indexOf($color) !== -1 ? css`
|
|
118
|
+
text-decoration-color: var(--redsift-color-product-${$color});
|
|
119
|
+
` : css`
|
|
120
|
+
text-decoration-color: ${$color || css`var(--redsift-color-${$theme}-components-text-primary)`};
|
|
121
|
+
`}
|
|
122
|
+
}
|
|
123
|
+
`}
|
|
124
124
|
` : css`
|
|
125
125
|
cursor: text !important;
|
|
126
126
|
text-decoration: none;
|
package/_internal/styles4.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles4.js","sources":["../../src/components/link/styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport { baseStyling } from '../shared';\nimport { StyledLinkProps } from './types';\nimport { NotificationsColorPalette, NeutralColorPalette, ProductColorPalette } from '../../types';\n\n/**\n * Component style.\n */\nexport const StyledLink = styled.a<StyledLinkProps>`\n background: none;\n border: none;\n color: unset;\n display: inline-flex;\n gap: 4px;\n align-items: center;\n font-family: var(--redsift-typography-link-font-family);\n font-size: var(--redsift-typography-link-font-size);\n font-weight: var(--redsift-typography-link-font-weight);\n height: var(--redsift-typography-link-line-height);\n line-height: var(--redsift-typography-link-line-height);\n padding: unset;\n position: relative;\n width: fit-content;\n cursor: pointer;\n\n ${({ $hasIcons }) =>\n $hasIcons\n ? css`\n bottom: -2px;\n `\n : ''}\n\n ${baseStyling}\n\n ${({ $isDisabled, $color, $theme, $hasIcons }) =>\n !$isDisabled\n ? css`\n ${
|
|
1
|
+
{"version":3,"file":"styles4.js","sources":["../../src/components/link/styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport { baseStyling } from '../shared';\nimport { StyledLinkProps } from './types';\nimport { NotificationsColorPalette, NeutralColorPalette, ProductColorPalette } from '../../types';\n\n/**\n * Component style.\n */\nexport const StyledLink = styled.a<StyledLinkProps>`\n background: none;\n border: none;\n color: unset;\n display: inline-flex;\n gap: 4px;\n align-items: center;\n font-family: var(--redsift-typography-link-font-family);\n font-size: var(--redsift-typography-link-font-size);\n font-weight: var(--redsift-typography-link-font-weight);\n height: var(--redsift-typography-link-line-height);\n line-height: var(--redsift-typography-link-line-height);\n padding: unset;\n position: relative;\n width: fit-content;\n cursor: pointer;\n\n ${({ $hasIcons }) =>\n $hasIcons\n ? css`\n bottom: -2px;\n `\n : ''}\n\n ${baseStyling}\n\n ${({ $isDisabled, $color, $theme, $hasIcons }) =>\n !$isDisabled\n ? css`\n ${$color && $color === 'radar'\n ? css`\n background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);\n background-clip: text;\n color: transparent;\n\n path {\n fill: url(#${$color}-gradient-default);\n }\n `\n : Object.keys(NotificationsColorPalette).indexOf($color!) !== -1\n ? css`\n &,\n .redsift-icon:not(.colored) {\n color: var(--redsift-color-notifications-${$color}-primary);\n }\n `\n : Object.keys(NeutralColorPalette).indexOf($color!) !== -1\n ? css`\n &,\n .redsift-icon:not(.colored) {\n color: var(--redsift-color-neutral-${$color});\n }\n `\n : Object.keys(ProductColorPalette).indexOf($color!) !== -1\n ? css`\n &,\n .redsift-icon:not(.colored) {\n color: var(--redsift-color-product-${$color});\n }\n `\n : css`\n &,\n .redsift-icon:not(.colored) {\n color: ${$color || css`var(--redsift-color-${$theme}-components-text-primary)`};\n }\n `}\n\n ${$color && $color === 'radar' && !$hasIcons\n ? css`\n position: relative;\n\n &:hover::before,\n &:focus-visible::before {\n content: '';\n position: absolute;\n bottom: 3px;\n width: 100%;\n left: 0;\n height: 1px;\n background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);\n }\n `\n : $color && $color === 'radar' && $hasIcons\n ? css`\n position: relative;\n\n .text::before {\n content: '';\n position: absolute;\n bottom: 3px;\n width: 100%;\n left: 0;\n height: 1px;\n background: linear-gradient(90deg, #51b78e 0%, #0081c3 100%);\n transform: scaleX(0);\n }\n\n &:hover .text::before,\n .icon:hover + .text::before,\n .text:hover::before {\n transform: scaleX(1);\n }\n `\n : css`\n text-decoration: underline;\n text-decoration-color: transparent;\n text-underline-offset: 2px;\n\n &:hover,\n &:focus-visible {\n ${Object.keys(NotificationsColorPalette).indexOf($color!) !== -1\n ? css`\n text-decoration-color: var(--redsift-color-notifications-${$color}-primary);\n `\n : Object.keys(NeutralColorPalette).indexOf($color!) !== -1\n ? css`\n text-decoration-color: var(--redsift-color-neutral-${$color});\n `\n : Object.keys(ProductColorPalette).indexOf($color!) !== -1\n ? css`\n text-decoration-color: var(--redsift-color-product-${$color});\n `\n : css`\n text-decoration-color: ${$color || css`var(--redsift-color-${$theme}-components-text-primary)`};\n `}\n }\n `}\n `\n : css`\n cursor: text !important;\n text-decoration: none;\n `}\n\n &:focus-visible {\n outline: 2px solid var(--redsift-color-primary-n);\n }\n`;\n"],"names":["StyledLink","styled","a","_ref","$hasIcons","css","baseStyling","_ref2","$isDisabled","$color","$theme","Object","keys","NotificationsColorPalette","indexOf","NeutralColorPalette","ProductColorPalette"],"mappings":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;AACxB;AACA,cAAgB,CAAA,CAAA;AAChB,QAAA,CAAS,GACDL,GAAI,CAAA;AACZ;AACA;AACA,QAAS,CAAA,CAAA;AAAA,CAAC,CAAA;AACV;AACA;AACA;AACA;AACA;;;;"}
|
package/_internal/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../src/components/app-side-panel/types.ts"],"sourcesContent":["import { ReactElement, ComponentProps, RefObject, MouseEvent } from 'react';\nimport { Theme, ValueOf } from '../../types';\nimport { IconButtonProps } from '../icon-button';\n\n/**\n * Component variant.\n */\nexport const AppSidePanelVariant = {\n shrinked: 'shrinked',\n standard: 'standard',\n hidden: 'hidden',\n} as const;\nexport type AppSidePanelVariant = ValueOf<typeof AppSidePanelVariant>;\n\n/**\n * Component props.\n */\nexport interface AppSidePanelProps extends ComponentProps<'div'> {\n /** Elements to display on top of the navigation menu. Usually a button. */\n featuredElements?: ReactElement | ReactElement[];\n /** Custom props to pass to the IconButton used to collapse the side panel. */\n iconButtonProps?: Omit<IconButtonProps, 'icon'>;\n /** Custom ref to pass to the IconButton used to collapse the side panel. */\n iconButtonRef?: RefObject<HTMLButtonElement>;\n /** Place to display the logo app. */\n logo?: ReactElement | ComponentProps<'img'>;\n /**\n * When set, persists menu expand/collapse states in localStorage using this key as prefix.\n * Each menu is identified by its `aria-label` prop.\n */\n menuStorageKey?: string;\n /** Method called when a click occurs on the top open button - which is displayed only in shrinked variant. */\n onOpen?: (e: MouseEvent) => void;\n /** Theme. */\n theme?: Theme;\n /** Variant. */\n variant?: AppSidePanelVariant;\n}\n\nexport type StyledAppSidePanelProps = Omit<AppSidePanelProps, 'isCollapsed' | 'logo'> & {\n $variant: AppSidePanelProps['variant'];\n $theme: AppSidePanelProps['theme'];\n};\n"],"names":["AppSidePanelVariant","shrinked","standard","hidden"],"mappings":"AAIA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAG;AACjCC,EAAAA,QAAQ,EAAE,UAAU;AACpBC,EAAAA,QAAQ,EAAE,UAAU;AACpBC,EAAAA,MAAM,EAAE,QAAA;AACV,EAAU;;AAGV;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/components/app-side-panel/types.ts"],"sourcesContent":["import { ReactElement, ComponentProps, RefObject, MouseEvent } from 'react';\nimport { Theme, ValueOf } from '../../types';\nimport { IconButtonProps } from '../icon-button';\n\n/**\n * Component variant.\n */\nexport const AppSidePanelVariant = {\n shrinked: 'shrinked',\n standard: 'standard',\n hidden: 'hidden',\n} as const;\nexport type AppSidePanelVariant = ValueOf<typeof AppSidePanelVariant>;\n\n/**\n * Component props.\n */\nexport interface AppSidePanelProps extends ComponentProps<'div'> {\n /** Elements to display on top of the navigation menu. Usually a button. */\n featuredElements?: ReactElement | ReactElement[];\n /** Custom props to pass to the IconButton used to collapse the side panel. */\n iconButtonProps?: Omit<IconButtonProps, 'icon'>;\n /** Custom ref to pass to the IconButton used to collapse the side panel. */\n iconButtonRef?: RefObject<HTMLButtonElement | null>;\n /** Place to display the logo app. */\n logo?: ReactElement | ComponentProps<'img'>;\n /**\n * When set, persists menu expand/collapse states in localStorage using this key as prefix.\n * Each menu is identified by its `aria-label` prop.\n */\n menuStorageKey?: string;\n /** Method called when a click occurs on the top open button - which is displayed only in shrinked variant. */\n onOpen?: (e: MouseEvent) => void;\n /** Theme. */\n theme?: Theme;\n /** Variant. */\n variant?: AppSidePanelVariant;\n}\n\nexport type StyledAppSidePanelProps = Omit<AppSidePanelProps, 'isCollapsed' | 'logo'> & {\n $variant: AppSidePanelProps['variant'];\n $theme: AppSidePanelProps['theme'];\n};\n"],"names":["AppSidePanelVariant","shrinked","standard","hidden"],"mappings":"AAIA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAG;AACjCC,EAAAA,QAAQ,EAAE,UAAU;AACpBC,EAAAA,QAAQ,EAAE,UAAU;AACpBC,EAAAA,MAAM,EAAE,QAAA;AACV,EAAU;;AAGV;AACA;AACA;;;;"}
|
|
@@ -64,7 +64,7 @@ function uniqueId() {
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Includes the given DOM element in the current roving tabindex.
|
|
67
|
-
* @param {RefObject<Element>} domElementRef The DOM element to include.
|
|
67
|
+
* @param {RefObject<Element | null>} domElementRef The DOM element to include.
|
|
68
68
|
* This must be the same DOM element for the lifetime of the containing
|
|
69
69
|
* component.
|
|
70
70
|
* @param {boolean} isDisabled Whether or not the DOM element is currently
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusOnListItem.js","sources":["../../src/components/focus-within-group/types.ts","../../src/components/focus-within-group/context.ts","../../src/components/focus-within-group/useFocusOnListItem.ts"],"sourcesContent":["import { ComponentProps } from 'react';\n\nexport enum EventKey {\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n Home = 'Home',\n End = 'End',\n Enter = 'Enter',\n}\n\nexport type KeyDirection = 'horizontal' | 'vertical' | 'both';\n\nexport enum Navigation {\n PREVIOUS = 'PREVIOUS',\n NEXT = 'NEXT',\n VERY_FIRST = 'VERY_FIRST',\n VERY_LAST = 'VERY_LAST',\n PREVIOUS_ROW = 'PREVIOUS_ROW',\n NEXT_ROW = 'NEXT_ROW',\n FIRST_IN_ROW = 'FIRST_IN_ROW',\n LAST_IN_ROW = 'LAST_IN_ROW',\n}\n\nexport type TabStop = Readonly<{\n id: string;\n domElementRef: React.RefObject<Element>;\n isDisabled: boolean;\n rowIndex: number | null;\n value: string;\n}>;\n\nexport type RowStartMap = Map<Exclude<TabStop['rowIndex'], null>, number>;\n\nexport type FocusWithinGroupState = Readonly<{\n selectedId: string | null;\n allowFocusing: boolean;\n tabStops: readonly TabStop[];\n direction: KeyDirection;\n focusOnClick: boolean;\n focusOnInit: boolean;\n loopAround: boolean;\n rowStartMap: RowStartMap | null;\n focusType: 'roving-tabindex' | 'virtual-focus';\n listRole: 'listbox' | 'menu';\n activedescendant?: [string, string];\n filter?: {\n value: string;\n type: 'startsWith' | 'contains' | 'endsWith';\n caseSensitive?: boolean;\n };\n delayedAction?: BaseFocusWithinGroupAction;\n maxOptionsLength?: number;\n}>;\n\nexport type FocusWithinGroupOptions = Partial<\n Pick<\n FocusWithinGroupState,\n | 'direction'\n | 'focusOnClick'\n | 'focusOnInit'\n | 'loopAround'\n | 'focusType'\n | 'listRole'\n | 'activedescendant'\n | 'maxOptionsLength'\n >\n>;\n\nexport enum FocusWithinGroupActionType {\n REGISTER_TAB_STOP = 'REGISTER_TAB_STOP',\n UNREGISTER_TAB_STOP = 'UNREGISTER_TAB_STOP',\n KEY_DOWN_ON_ITEM = 'KEY_DOWN_ON_ITEM',\n CLICK_ON_ITEM = 'CLICK_ON_ITEM',\n KEY_DOWN_ON_LIST = 'KEY_DOWN_ON_LIST',\n FOCUS_ON_LIST = 'FOCUS_ON_LIST',\n BLUR_ON_LIST = 'BLUR_ON_LIST',\n TAB_STOP_UPDATED = 'TAB_STOP_UPDATED',\n OPTIONS_UPDATED = 'OPTIONS_UPDATED',\n FILTER_LIST = 'FILTER_LIST',\n DELAY_ACTION = 'DELAY_ACTION',\n}\n\nexport type BaseFocusWithinGroupAction =\n | {\n type: FocusWithinGroupActionType.REGISTER_TAB_STOP;\n payload: TabStop;\n }\n | {\n type: FocusWithinGroupActionType.UNREGISTER_TAB_STOP;\n payload: { id: TabStop['id'] };\n }\n | {\n type: FocusWithinGroupActionType.TAB_STOP_UPDATED;\n payload: {\n id: TabStop['id'];\n rowIndex: TabStop['rowIndex'];\n isDisabled: TabStop['isDisabled'];\n value: string;\n };\n }\n | {\n type: FocusWithinGroupActionType.KEY_DOWN_ON_ITEM;\n payload: {\n id: TabStop['id'];\n key: EventKey;\n ctrlKey: boolean;\n };\n }\n | {\n type: FocusWithinGroupActionType.CLICK_ON_ITEM;\n payload: { id: TabStop['id'] };\n }\n | {\n type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST;\n payload: {\n key: EventKey;\n ctrlKey: boolean;\n };\n }\n | {\n type: FocusWithinGroupActionType.FOCUS_ON_LIST;\n payload: { id: TabStop['id']; filter?: FocusWithinGroupState['filter'] };\n }\n | {\n type: FocusWithinGroupActionType.BLUR_ON_LIST;\n payload: {};\n }\n | {\n type: FocusWithinGroupActionType.OPTIONS_UPDATED;\n payload: FocusWithinGroupOptions;\n }\n | {\n type: FocusWithinGroupActionType.FILTER_LIST;\n payload: { filter: FocusWithinGroupState['filter'] };\n };\nexport type FocusWithinGroupAction =\n | BaseFocusWithinGroupAction\n | {\n type: FocusWithinGroupActionType.DELAY_ACTION;\n payload: BaseFocusWithinGroupAction;\n };\n\nexport type UseFocusWithinGroupProps = {\n tabIndex?: number;\n isFocused: boolean;\n handleKeyDown: (event: React.KeyboardEvent) => void;\n handleClick: () => void;\n};\n\nexport type UseFocusGroupProps = {\n activedescendant: [string, string] | undefined;\n handleKeyDown: (event: React.KeyboardEvent) => void;\n handleFocus: () => void;\n handleBlur: () => void;\n};\n\nexport type FocusWithinGroupContextProps = {\n state: FocusWithinGroupState;\n dispatch: React.Dispatch<FocusWithinGroupAction>;\n};\n\n/**\n * Component props.\n */\nexport interface FocusWithinGroupProps extends ComponentProps<'div'>, FocusWithinGroupOptions {}\n","import React from 'react';\nimport { FocusWithinGroupContextProps, FocusWithinGroupState } from './types';\n\nexport const FOCUS_WITHING_GROUP_INITIAL_STATE: FocusWithinGroupState = {\n selectedId: null,\n allowFocusing: false,\n tabStops: [],\n direction: 'vertical',\n focusOnClick: false,\n focusOnInit: true,\n loopAround: false,\n rowStartMap: null,\n focusType: 'roving-tabindex',\n listRole: 'listbox',\n};\n\nexport const FocusWithinGroupContext = React.createContext<FocusWithinGroupContextProps>({\n state: FOCUS_WITHING_GROUP_INITIAL_STATE,\n dispatch: () => {},\n});\n","import { useCallback, useRef, useContext, useEffect, RefObject, KeyboardEvent } from 'react';\nimport { FocusWithinGroupContext } from './context';\nimport { FocusWithinGroupActionType, EventKey, UseFocusWithinGroupProps } from './types';\n\nlet counter = 0;\n\nexport function uniqueId(): string {\n return `rti_${++counter}`;\n}\n\n/**\n * Includes the given DOM element in the current roving tabindex.\n * @param {RefObject<Element>} domElementRef The DOM element to include.\n * This must be the same DOM element for the lifetime of the containing\n * component.\n * @param {boolean} isDisabled Whether or not the DOM element is currently\n * enabled. This value can be updated as appropriate throughout the lifetime\n * of the containing component.\n * @param {number?} rowIndex An optional integer value that must be\n * populated if the roving tabindex is being used in a grid. In that case,\n * set it to the zero-based index of the row that the given DOM element\n * is currently part of. You can update this row index as appropriate\n * throughout the lifetime of the containing component, for example if\n * the shape of the grid can change dynamically.\n * @returns A tuple of values to be applied by the containing\n * component for the roving tabindex to work correctly.\n * First tuple value: The tabIndex value to apply to the tab stop\n * element.\n * Second tuple value: Whether or not focus() should be invoked on the\n * tab stop element.\n * Third tuple value: The onKeyDown callback to apply to the tab\n * stop element. If the key press is relevant to the hook then\n * event.preventDefault() will be invoked on the event.\n * Fourth tuple value: The onClick callback to apply to the tab\n * stop element.\n */\nexport function useFocusOnListItem(props: {\n domElementRef: RefObject<Element>;\n isDisabled: boolean;\n id?: string;\n value?: string;\n rowIndex?: number | null;\n}): UseFocusWithinGroupProps {\n const { domElementRef, isDisabled, id, value, rowIndex = null } = props;\n // Create a stable ID for the lifetime of the component:\n const idRef = useRef<string | null>(null);\n\n function getId() {\n if (id) {\n return id;\n }\n\n if (!idRef.current) {\n idRef.current = uniqueId();\n }\n return idRef.current;\n }\n\n const isMounted = useRef(false);\n const context = useContext(FocusWithinGroupContext);\n\n // Register the tab stop on mount and unregister it on unmount:\n useEffect(() => {\n const id = getId();\n context.dispatch({\n type: FocusWithinGroupActionType.REGISTER_TAB_STOP,\n payload: {\n id,\n domElementRef,\n rowIndex,\n isDisabled,\n value: value!,\n },\n });\n return (): void => {\n context.dispatch({\n type: FocusWithinGroupActionType.UNREGISTER_TAB_STOP,\n payload: { id },\n });\n };\n }, []);\n\n // Update the tab stop data if rowIndex or isDisabled change.\n // The isMounted flag is used to prevent this effect running\n // on mount, which is benign but redundant (as the\n // REGISTER_TAB_STOP action would have just been dispatched).\n useEffect(() => {\n if (isMounted.current) {\n context.dispatch({\n type: FocusWithinGroupActionType.TAB_STOP_UPDATED,\n payload: {\n id: getId(),\n rowIndex,\n isDisabled,\n value: value || '',\n },\n });\n } else {\n isMounted.current = true;\n }\n }, [rowIndex, isDisabled]);\n\n // Create a stable callback function for handling key down events:\n const handleKeyDown = useCallback((event: KeyboardEvent) => {\n const key = EventKey[event.key as EventKey];\n if (!key) {\n return;\n }\n context.dispatch({\n type: FocusWithinGroupActionType.KEY_DOWN_ON_ITEM,\n payload: { id: getId(), key, ctrlKey: event.ctrlKey },\n });\n event.preventDefault();\n }, []);\n\n // Create a stable callback function for handling click events:\n const handleClick = useCallback(() => {\n context.dispatch({\n type: FocusWithinGroupActionType.CLICK_ON_ITEM,\n payload: { id: getId() },\n });\n }, []);\n\n // Determine if the current tab stop is the currently active one:\n const selected = getId() === context.state.selectedId;\n\n const tabIndex = context.state.focusType === 'roving-tabindex' ? (selected ? 0 : -1) : undefined;\n const isFocused = selected && context.state.allowFocusing;\n\n useEffect(() => {\n if (isFocused && domElementRef.current && context.state.focusType === 'roving-tabindex') {\n (domElementRef as RefObject<SVGElement | HTMLElement>).current?.focus();\n }\n }, [isFocused]);\n\n return {\n tabIndex,\n isFocused:\n context.state.focusType === 'roving-tabindex'\n ? isFocused && document.activeElement === (domElementRef as RefObject<SVGElement | HTMLElement>).current\n : selected && context.state.activedescendant?.[0] === getId(),\n handleKeyDown,\n handleClick,\n };\n}\n"],"names":["EventKey","Navigation","FocusWithinGroupActionType","FOCUS_WITHING_GROUP_INITIAL_STATE","selectedId","allowFocusing","tabStops","direction","focusOnClick","focusOnInit","loopAround","rowStartMap","focusType","listRole","FocusWithinGroupContext","React","createContext","state","dispatch","counter","uniqueId","useFocusOnListItem","props","_context$state$active","domElementRef","isDisabled","id","value","rowIndex","idRef","useRef","getId","current","isMounted","context","useContext","useEffect","type","REGISTER_TAB_STOP","payload","UNREGISTER_TAB_STOP","TAB_STOP_UPDATED","handleKeyDown","useCallback","event","key","KEY_DOWN_ON_ITEM","ctrlKey","preventDefault","handleClick","CLICK_ON_ITEM","selected","tabIndex","undefined","isFocused","_current","focus","document","activeElement","activedescendant"],"mappings":";;AAEYA,IAAAA,QAAQ,0BAARA,QAAQ,EAAA;EAARA,QAAQ,CAAA,WAAA,CAAA,GAAA,WAAA,CAAA;EAARA,QAAQ,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAARA,QAAQ,CAAA,SAAA,CAAA,GAAA,SAAA,CAAA;EAARA,QAAQ,CAAA,WAAA,CAAA,GAAA,WAAA,CAAA;EAARA,QAAQ,CAAA,MAAA,CAAA,GAAA,MAAA,CAAA;EAARA,QAAQ,CAAA,KAAA,CAAA,GAAA,KAAA,CAAA;EAARA,QAAQ,CAAA,OAAA,CAAA,GAAA,OAAA,CAAA;AAAA,EAAA,OAARA,QAAQ,CAAA;AAAA,CAAA,CAAA,EAAA,EAAA;AAYRC,IAAAA,UAAU,0BAAVA,UAAU,EAAA;EAAVA,UAAU,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAVA,UAAU,CAAA,MAAA,CAAA,GAAA,MAAA,CAAA;EAAVA,UAAU,CAAA,YAAA,CAAA,GAAA,YAAA,CAAA;EAAVA,UAAU,CAAA,WAAA,CAAA,GAAA,WAAA,CAAA;EAAVA,UAAU,CAAA,cAAA,CAAA,GAAA,cAAA,CAAA;EAAVA,UAAU,CAAA,UAAA,CAAA,GAAA,UAAA,CAAA;EAAVA,UAAU,CAAA,cAAA,CAAA,GAAA,cAAA,CAAA;EAAVA,UAAU,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AAAA,EAAA,OAAVA,UAAU,CAAA;AAAA,CAAA,CAAA,EAAA,EAAA;AAwDVC,IAAAA,0BAA0B,0BAA1BA,0BAA0B,EAAA;EAA1BA,0BAA0B,CAAA,mBAAA,CAAA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ACjEW,aAAa;AACbO,IAAAA,WAAAA;GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"useFocusOnListItem.js","sources":["../../src/components/focus-within-group/types.ts","../../src/components/focus-within-group/context.ts","../../src/components/focus-within-group/useFocusOnListItem.ts"],"sourcesContent":["import { ComponentProps } from 'react';\n\nexport enum EventKey {\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n Home = 'Home',\n End = 'End',\n Enter = 'Enter',\n}\n\nexport type KeyDirection = 'horizontal' | 'vertical' | 'both';\n\nexport enum Navigation {\n PREVIOUS = 'PREVIOUS',\n NEXT = 'NEXT',\n VERY_FIRST = 'VERY_FIRST',\n VERY_LAST = 'VERY_LAST',\n PREVIOUS_ROW = 'PREVIOUS_ROW',\n NEXT_ROW = 'NEXT_ROW',\n FIRST_IN_ROW = 'FIRST_IN_ROW',\n LAST_IN_ROW = 'LAST_IN_ROW',\n}\n\nexport type TabStop = Readonly<{\n id: string;\n domElementRef: React.RefObject<Element | null>;\n isDisabled: boolean;\n rowIndex: number | null;\n value: string;\n}>;\n\nexport type RowStartMap = Map<Exclude<TabStop['rowIndex'], null>, number>;\n\nexport type FocusWithinGroupState = Readonly<{\n selectedId: string | null;\n allowFocusing: boolean;\n tabStops: readonly TabStop[];\n direction: KeyDirection;\n focusOnClick: boolean;\n focusOnInit: boolean;\n loopAround: boolean;\n rowStartMap: RowStartMap | null;\n focusType: 'roving-tabindex' | 'virtual-focus';\n listRole: 'listbox' | 'menu';\n activedescendant?: [string, string];\n filter?: {\n value: string;\n type: 'startsWith' | 'contains' | 'endsWith';\n caseSensitive?: boolean;\n };\n delayedAction?: BaseFocusWithinGroupAction;\n maxOptionsLength?: number;\n}>;\n\nexport type FocusWithinGroupOptions = Partial<\n Pick<\n FocusWithinGroupState,\n | 'direction'\n | 'focusOnClick'\n | 'focusOnInit'\n | 'loopAround'\n | 'focusType'\n | 'listRole'\n | 'activedescendant'\n | 'maxOptionsLength'\n >\n>;\n\nexport enum FocusWithinGroupActionType {\n REGISTER_TAB_STOP = 'REGISTER_TAB_STOP',\n UNREGISTER_TAB_STOP = 'UNREGISTER_TAB_STOP',\n KEY_DOWN_ON_ITEM = 'KEY_DOWN_ON_ITEM',\n CLICK_ON_ITEM = 'CLICK_ON_ITEM',\n KEY_DOWN_ON_LIST = 'KEY_DOWN_ON_LIST',\n FOCUS_ON_LIST = 'FOCUS_ON_LIST',\n BLUR_ON_LIST = 'BLUR_ON_LIST',\n TAB_STOP_UPDATED = 'TAB_STOP_UPDATED',\n OPTIONS_UPDATED = 'OPTIONS_UPDATED',\n FILTER_LIST = 'FILTER_LIST',\n DELAY_ACTION = 'DELAY_ACTION',\n}\n\nexport type BaseFocusWithinGroupAction =\n | {\n type: FocusWithinGroupActionType.REGISTER_TAB_STOP;\n payload: TabStop;\n }\n | {\n type: FocusWithinGroupActionType.UNREGISTER_TAB_STOP;\n payload: { id: TabStop['id'] };\n }\n | {\n type: FocusWithinGroupActionType.TAB_STOP_UPDATED;\n payload: {\n id: TabStop['id'];\n rowIndex: TabStop['rowIndex'];\n isDisabled: TabStop['isDisabled'];\n value: string;\n };\n }\n | {\n type: FocusWithinGroupActionType.KEY_DOWN_ON_ITEM;\n payload: {\n id: TabStop['id'];\n key: EventKey;\n ctrlKey: boolean;\n };\n }\n | {\n type: FocusWithinGroupActionType.CLICK_ON_ITEM;\n payload: { id: TabStop['id'] };\n }\n | {\n type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST;\n payload: {\n key: EventKey;\n ctrlKey: boolean;\n };\n }\n | {\n type: FocusWithinGroupActionType.FOCUS_ON_LIST;\n payload: { id: TabStop['id']; filter?: FocusWithinGroupState['filter'] };\n }\n | {\n type: FocusWithinGroupActionType.BLUR_ON_LIST;\n payload: {};\n }\n | {\n type: FocusWithinGroupActionType.OPTIONS_UPDATED;\n payload: FocusWithinGroupOptions;\n }\n | {\n type: FocusWithinGroupActionType.FILTER_LIST;\n payload: { filter: FocusWithinGroupState['filter'] };\n };\nexport type FocusWithinGroupAction =\n | BaseFocusWithinGroupAction\n | {\n type: FocusWithinGroupActionType.DELAY_ACTION;\n payload: BaseFocusWithinGroupAction;\n };\n\nexport type UseFocusWithinGroupProps = {\n tabIndex?: number;\n isFocused: boolean;\n handleKeyDown: (event: React.KeyboardEvent) => void;\n handleClick: () => void;\n};\n\nexport type UseFocusGroupProps = {\n activedescendant: [string, string] | undefined;\n handleKeyDown: (event: React.KeyboardEvent) => void;\n handleFocus: () => void;\n handleBlur: () => void;\n};\n\nexport type FocusWithinGroupContextProps = {\n state: FocusWithinGroupState;\n dispatch: React.Dispatch<FocusWithinGroupAction>;\n};\n\n/**\n * Component props.\n */\nexport interface FocusWithinGroupProps extends ComponentProps<'div'>, FocusWithinGroupOptions {}\n","import React from 'react';\nimport { FocusWithinGroupContextProps, FocusWithinGroupState } from './types';\n\nexport const FOCUS_WITHING_GROUP_INITIAL_STATE: FocusWithinGroupState = {\n selectedId: null,\n allowFocusing: false,\n tabStops: [],\n direction: 'vertical',\n focusOnClick: false,\n focusOnInit: true,\n loopAround: false,\n rowStartMap: null,\n focusType: 'roving-tabindex',\n listRole: 'listbox',\n};\n\nexport const FocusWithinGroupContext = React.createContext<FocusWithinGroupContextProps>({\n state: FOCUS_WITHING_GROUP_INITIAL_STATE,\n dispatch: () => {},\n});\n","import { useCallback, useRef, useContext, useEffect, RefObject, KeyboardEvent } from 'react';\nimport { FocusWithinGroupContext } from './context';\nimport { FocusWithinGroupActionType, EventKey, UseFocusWithinGroupProps } from './types';\n\nlet counter = 0;\n\nexport function uniqueId(): string {\n return `rti_${++counter}`;\n}\n\n/**\n * Includes the given DOM element in the current roving tabindex.\n * @param {RefObject<Element | null>} domElementRef The DOM element to include.\n * This must be the same DOM element for the lifetime of the containing\n * component.\n * @param {boolean} isDisabled Whether or not the DOM element is currently\n * enabled. This value can be updated as appropriate throughout the lifetime\n * of the containing component.\n * @param {number?} rowIndex An optional integer value that must be\n * populated if the roving tabindex is being used in a grid. In that case,\n * set it to the zero-based index of the row that the given DOM element\n * is currently part of. You can update this row index as appropriate\n * throughout the lifetime of the containing component, for example if\n * the shape of the grid can change dynamically.\n * @returns A tuple of values to be applied by the containing\n * component for the roving tabindex to work correctly.\n * First tuple value: The tabIndex value to apply to the tab stop\n * element.\n * Second tuple value: Whether or not focus() should be invoked on the\n * tab stop element.\n * Third tuple value: The onKeyDown callback to apply to the tab\n * stop element. If the key press is relevant to the hook then\n * event.preventDefault() will be invoked on the event.\n * Fourth tuple value: The onClick callback to apply to the tab\n * stop element.\n */\nexport function useFocusOnListItem(props: {\n domElementRef: RefObject<Element | null>;\n isDisabled: boolean;\n id?: string;\n value?: string;\n rowIndex?: number | null;\n}): UseFocusWithinGroupProps {\n const { domElementRef, isDisabled, id, value, rowIndex = null } = props;\n // Create a stable ID for the lifetime of the component:\n const idRef = useRef<string | null>(null);\n\n function getId() {\n if (id) {\n return id;\n }\n\n if (!idRef.current) {\n idRef.current = uniqueId();\n }\n return idRef.current;\n }\n\n const isMounted = useRef(false);\n const context = useContext(FocusWithinGroupContext);\n\n // Register the tab stop on mount and unregister it on unmount:\n useEffect(() => {\n const id = getId();\n context.dispatch({\n type: FocusWithinGroupActionType.REGISTER_TAB_STOP,\n payload: {\n id,\n domElementRef,\n rowIndex,\n isDisabled,\n value: value!,\n },\n });\n return (): void => {\n context.dispatch({\n type: FocusWithinGroupActionType.UNREGISTER_TAB_STOP,\n payload: { id },\n });\n };\n }, []);\n\n // Update the tab stop data if rowIndex or isDisabled change.\n // The isMounted flag is used to prevent this effect running\n // on mount, which is benign but redundant (as the\n // REGISTER_TAB_STOP action would have just been dispatched).\n useEffect(() => {\n if (isMounted.current) {\n context.dispatch({\n type: FocusWithinGroupActionType.TAB_STOP_UPDATED,\n payload: {\n id: getId(),\n rowIndex,\n isDisabled,\n value: value || '',\n },\n });\n } else {\n isMounted.current = true;\n }\n }, [rowIndex, isDisabled]);\n\n // Create a stable callback function for handling key down events:\n const handleKeyDown = useCallback((event: KeyboardEvent) => {\n const key = EventKey[event.key as EventKey];\n if (!key) {\n return;\n }\n context.dispatch({\n type: FocusWithinGroupActionType.KEY_DOWN_ON_ITEM,\n payload: { id: getId(), key, ctrlKey: event.ctrlKey },\n });\n event.preventDefault();\n }, []);\n\n // Create a stable callback function for handling click events:\n const handleClick = useCallback(() => {\n context.dispatch({\n type: FocusWithinGroupActionType.CLICK_ON_ITEM,\n payload: { id: getId() },\n });\n }, []);\n\n // Determine if the current tab stop is the currently active one:\n const selected = getId() === context.state.selectedId;\n\n const tabIndex = context.state.focusType === 'roving-tabindex' ? (selected ? 0 : -1) : undefined;\n const isFocused = selected && context.state.allowFocusing;\n\n useEffect(() => {\n if (isFocused && domElementRef.current && context.state.focusType === 'roving-tabindex') {\n (domElementRef as RefObject<SVGElement | HTMLElement>).current?.focus();\n }\n }, [isFocused]);\n\n return {\n tabIndex,\n isFocused:\n context.state.focusType === 'roving-tabindex'\n ? isFocused && document.activeElement === (domElementRef as RefObject<SVGElement | HTMLElement>).current\n : selected && context.state.activedescendant?.[0] === getId(),\n handleKeyDown,\n handleClick,\n };\n}\n"],"names":["EventKey","Navigation","FocusWithinGroupActionType","FOCUS_WITHING_GROUP_INITIAL_STATE","selectedId","allowFocusing","tabStops","direction","focusOnClick","focusOnInit","loopAround","rowStartMap","focusType","listRole","FocusWithinGroupContext","React","createContext","state","dispatch","counter","uniqueId","useFocusOnListItem","props","_context$state$active","domElementRef","isDisabled","id","value","rowIndex","idRef","useRef","getId","current","isMounted","context","useContext","useEffect","type","REGISTER_TAB_STOP","payload","UNREGISTER_TAB_STOP","TAB_STOP_UPDATED","handleKeyDown","useCallback","event","key","KEY_DOWN_ON_ITEM","ctrlKey","preventDefault","handleClick","CLICK_ON_ITEM","selected","tabIndex","undefined","isFocused","_current","focus","document","activeElement","activedescendant"],"mappings":";;AAEYA,IAAAA,QAAQ,0BAARA,QAAQ,EAAA;EAARA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