@open-pioneer/react-utils 4.7.0-dev.20260713101438 → 4.7.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/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # @open-pioneer/react-utils
2
2
 
3
- ## 4.7.0-dev.20260713101438
3
+ ## 4.7.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - e433296: Update Chakra UI to 3.36.0
7
+ - e433296: Update Chakra UI to 3.36.1
8
+
9
+ ### Patch Changes
10
+
11
+ - 9d84f1e: Migrated from eslint to oxlint and from prettier to oxfmt.
8
12
 
9
13
  ## 4.6.0
10
14
 
@@ -27,7 +31,9 @@
27
31
  This allows to use the hook in components which do not necessarily need to be used inside a `TitledSection`.
28
32
 
29
33
  ```tsx
30
- const currentHeading: number | undefined = useHeadingLevel({ required: false });
34
+ const currentHeading: number | undefined = useHeadingLevel({
35
+ required: false
36
+ });
31
37
  ```
32
38
 
33
39
  ## 4.5.0
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedMessage.js","sources":["FormattedMessage.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { getValue, ReactiveGetter, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport type { PackageIntl, RichTextValue } from \"@open-pioneer/runtime\";\nimport {\n type FormatXMLElementFn,\n type Options as IntlMessageFormatOptions,\n type PrimitiveType\n} from \"intl-messageformat\"; // not a dependency, this is a dependency of formatjs\nimport { useMemo } from \"react\";\n\n/**\n * Shared formatting operations.\n *\n * @group Formatting\n */\nexport interface FormattingBaseProps {\n /**\n * The `intl` object of the package rendering the message.\n * Must contain a message associated with the given {@link id}.\n *\n * Note that this value can be a direct instance, or a signal / reactive getter implemented\n * in terms of the Reactivity API.\n */\n intl: PackageIntl | ReadonlyReactive<PackageIntl> | ReactiveGetter<PackageIntl>;\n}\n\n/**\n * Props supported by {@link FormattedMessage}.\n *\n * @group Formatting\n */\nexport interface FormattedMessageProps extends FormattingBaseProps {\n /** The message's id. */\n id: string;\n\n /**\n * Formatting values used to parametrize the message.\n * Also supports callbacks, see {@link PackageIntl.formatMessage}.\n */\n values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>;\n\n /** Additional options for the formatting operation. */\n opts?: IntlMessageFormatOptions;\n}\n\n/**\n * Renders the result of formatting a message using the provided intl object.\n *\n * Example:\n *\n * ```tsx\n * <FormattedMessage intl={intl} id=\"message.id\" />\n * ```\n *\n * @expandType FormattedMessageProps\n * @group Formatting\n */\nexport function FormattedMessage(props: FormattedMessageProps) {\n const { id, values, opts } = props;\n const intl = useReactiveIntl(props);\n return useMemo(\n () => String(intl.formatMessage({ id }, values, opts)),\n [intl, id, values, opts]\n );\n}\n\n/**\n * Props supported by {@link FormattedRichMessage}.\n *\n * @group Formatting\n */\nexport interface FormattedRichMessageProps extends FormattingBaseProps {\n /** The message's id. */\n id: string;\n\n /**\n * Formatting values used to parametrize the message.\n * Also supports callbacks, see {@link PackageIntl.formatRichMessage}.\n */\n values?: Record<string, RichTextValue>;\n\n /** Additional options for the formatting operation. */\n opts?: IntlMessageFormatOptions;\n}\n\n/**\n * Renders the result of formatting a message using the provided intl object.\n *\n * Example:\n *\n * ```tsx\n * <FormattedRichMessage intl={intl} id=\"message.id\" />\n * ```\n *\n * @expandType FormattedRichMessageProps\n * @group Formatting\n */\nexport function FormattedRichMessage(props: FormattedRichMessageProps) {\n const { id, values, opts } = props;\n const intl = useReactiveIntl(props);\n return useMemo(() => intl.formatRichMessage({ id }, values, opts), [intl, id, values, opts]);\n}\n\nfunction useReactiveIntl({ intl }: FormattingBaseProps) {\n return useReactiveSnapshot(() => {\n if (typeof intl === \"function\") {\n // reactive getter\n return intl();\n }\n return getValue(intl);\n }, [intl]);\n}\n"],"names":[],"mappings":";;;;AA2DO,SAAS,iBAAiB,KAAA,EAA8B;AAC3D,EAAA,MAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,IAAA,EAAK,GAAI,KAAA;AAC7B,EAAA,MAAM,IAAA,GAAO,gBAAgB,KAAK,CAAA;AAClC,EAAA,OAAO,OAAA;AAAA,IACH,MAAM,OAAO,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAG,EAAG,MAAA,EAAQ,IAAI,CAAC,CAAA;AAAA,IACrD,CAAC,IAAA,EAAM,EAAA,EAAI,MAAA,EAAQ,IAAI;AAAA,GAC3B;AACJ;AAiCO,SAAS,qBAAqB,KAAA,EAAkC;AACnE,EAAA,MAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,IAAA,EAAK,GAAI,KAAA;AAC7B,EAAA,MAAM,IAAA,GAAO,gBAAgB,KAAK,CAAA;AAClC,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAA,CAAK,iBAAA,CAAkB,EAAE,EAAA,EAAG,EAAG,MAAA,EAAQ,IAAI,GAAG,CAAC,IAAA,EAAM,EAAA,EAAI,MAAA,EAAQ,IAAI,CAAC,CAAA;AAC/F;AAEA,SAAS,eAAA,CAAgB,EAAE,IAAA,EAAK,EAAwB;AACpD,EAAA,OAAO,oBAAoB,MAAM;AAC7B,IAAA,IAAI,OAAO,SAAS,UAAA,EAAY;AAE5B,MAAA,OAAO,IAAA,EAAK;AAAA,IAChB;AACA,IAAA,OAAO,SAAS,IAAI,CAAA;AAAA,EACxB,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACb;;;;"}
1
+ {"version":3,"file":"FormattedMessage.js","sources":["FormattedMessage.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getValue, ReactiveGetter, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport type { PackageIntl, RichTextValue } from \"@open-pioneer/runtime\";\nimport {\n type FormatXMLElementFn,\n type Options as IntlMessageFormatOptions,\n type PrimitiveType\n} from \"intl-messageformat\"; // not a dependency, this is a dependency of formatjs\nimport { useMemo } from \"react\";\n\n/**\n * Shared formatting operations.\n *\n * @group Formatting\n */\nexport interface FormattingBaseProps {\n /**\n * The `intl` object of the package rendering the message.\n * Must contain a message associated with the given {@link id}.\n *\n * Note that this value can be a direct instance, or a signal / reactive getter implemented\n * in terms of the Reactivity API.\n */\n intl: PackageIntl | ReadonlyReactive<PackageIntl> | ReactiveGetter<PackageIntl>;\n}\n\n/**\n * Props supported by {@link FormattedMessage}.\n *\n * @group Formatting\n */\nexport interface FormattedMessageProps extends FormattingBaseProps {\n /** The message's id. */\n id: string;\n\n /**\n * Formatting values used to parametrize the message.\n * Also supports callbacks, see {@link PackageIntl.formatMessage}.\n */\n values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>;\n\n /** Additional options for the formatting operation. */\n opts?: IntlMessageFormatOptions;\n}\n\n/**\n * Renders the result of formatting a message using the provided intl object.\n *\n * Example:\n *\n * ```tsx\n * <FormattedMessage intl={intl} id=\"message.id\" />\n * ```\n *\n * @expandType FormattedMessageProps\n * @group Formatting\n */\nexport function FormattedMessage(props: FormattedMessageProps) {\n const { id, values, opts } = props;\n const intl = useReactiveIntl(props);\n return useMemo(\n () => String(intl.formatMessage({ id }, values, opts)),\n [intl, id, values, opts]\n );\n}\n\n/**\n * Props supported by {@link FormattedRichMessage}.\n *\n * @group Formatting\n */\nexport interface FormattedRichMessageProps extends FormattingBaseProps {\n /** The message's id. */\n id: string;\n\n /**\n * Formatting values used to parametrize the message.\n * Also supports callbacks, see {@link PackageIntl.formatRichMessage}.\n */\n values?: Record<string, RichTextValue>;\n\n /** Additional options for the formatting operation. */\n opts?: IntlMessageFormatOptions;\n}\n\n/**\n * Renders the result of formatting a message using the provided intl object.\n *\n * Example:\n *\n * ```tsx\n * <FormattedRichMessage intl={intl} id=\"message.id\" />\n * ```\n *\n * @expandType FormattedRichMessageProps\n * @group Formatting\n */\nexport function FormattedRichMessage(props: FormattedRichMessageProps) {\n const { id, values, opts } = props;\n const intl = useReactiveIntl(props);\n return useMemo(() => intl.formatRichMessage({ id }, values, opts), [intl, id, values, opts]);\n}\n\nfunction useReactiveIntl({ intl }: FormattingBaseProps) {\n return useReactiveSnapshot(() => {\n if (typeof intl === \"function\") {\n // reactive getter\n return intl();\n }\n return getValue(intl);\n }, [intl]);\n}\n"],"names":[],"mappings":";;;;AA4DO,SAAS,iBAAiB,KAAA,EAA8B;AAC3D,EAAA,MAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,IAAA,EAAK,GAAI,KAAA;AAC7B,EAAA,MAAM,IAAA,GAAO,gBAAgB,KAAK,CAAA;AAClC,EAAA,OAAO,OAAA;AAAA,IACH,MAAM,OAAO,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAG,EAAG,MAAA,EAAQ,IAAI,CAAC,CAAA;AAAA,IACrD,CAAC,IAAA,EAAM,EAAA,EAAI,MAAA,EAAQ,IAAI;AAAA,GAC3B;AACJ;AAiCO,SAAS,qBAAqB,KAAA,EAAkC;AACnE,EAAA,MAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,IAAA,EAAK,GAAI,KAAA;AAC7B,EAAA,MAAM,IAAA,GAAO,gBAAgB,KAAK,CAAA;AAClC,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAA,CAAK,iBAAA,CAAkB,EAAE,EAAA,EAAG,EAAG,MAAA,EAAQ,IAAI,GAAG,CAAC,IAAA,EAAM,EAAA,EAAI,MAAA,EAAQ,IAAI,CAAC,CAAA;AAC/F;AAEA,SAAS,eAAA,CAAgB,EAAE,IAAA,EAAK,EAAwB;AACpD,EAAA,OAAO,oBAAoB,MAAM;AAC7B,IAAA,IAAI,OAAO,SAAS,UAAA,EAAY;AAE5B,MAAA,OAAO,IAAA,EAAK;AAAA,IAChB;AACA,IAAA,OAAO,SAAS,IAAI,CAAA;AAAA,EACxB,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACb;;;;"}
package/README.md CHANGED
@@ -173,8 +173,6 @@ For the time being, these properties are `className` (combined component class a
173
173
  Example:
174
174
 
175
175
  ```tsx
176
- // SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)
177
- // SPDX-License-Identifier: Apache-2.0
178
176
  import { CommonComponentProps, useCommonComponentProps } from "@open-pioneer/react-utils";
179
177
  // ...
180
178
 
@@ -1 +1 @@
1
- {"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/**\n * Properties of the {@link TitledSection} component.\n *\n * @group Headings\n **/\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n *\n * @group Headings\n * @expandType TitledSectionProps\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n *\n * @group Headings\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n *\n * @group Headings\n * @expandType SectionHeadingProps\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n *\n * @group Headings\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n * @group Headings\n * @expandType ConfigureTitledSectionProps\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/**\n * The level of a html heading.\n * @group Headings\n **/\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n * If you use it outside of a TitledSection, it will throw an error by default.\n * You can set `required: false` to make it return `undefined` instead of throwing an error\n *\n * @group Headings\n */\nexport function useHeadingLevel(): HeadingLevel;\nexport function useHeadingLevel(props: { required: false }): HeadingLevel | undefined;\nexport function useHeadingLevel(props: { required?: true }): HeadingLevel;\nexport function useHeadingLevel(props?: { required?: boolean }): HeadingLevel | undefined {\n const level = useContext(LevelContext);\n if (level == null) {\n if (props?.required === false) {\n return undefined;\n }\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,WAAA,GAAc,cAAA;AAgGpB,SAAS,cAAc,KAAA,EAAsC;AAChE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAA,EAAqB,QAAA,EAAS,GAAI,KAAA;AACjD,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,YAAY,CAAA,IAAK,CAAA;AACjD,EAAA,MAAM,OAAA,GACF,OAAO,KAAA,KAAU,QAAA,uBACZ,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAsB,QAAA,EAAA,KAAA,EAAM,CAAA,GAEhD,KAAA;AAGR,EAAA,uBACI,IAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,YAAA,GAAe,CAAA,EAC/B,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA;AAAA,GAAA,EACL,CAAA;AAER;AAwBO,SAAS,eAAe,KAAA,EAAuC;AAClE,EAAA,MAAM,EAAE,QAAA,EAAU,GAAA,EAAK,GAAG,MAAK,GAAI,KAAA;AACnC,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,GAAA,GAAM,cAAc,KAAK,CAAA;AAC/B,EAAA,2BACK,OAAA,EAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAW,GAAG,MAC3B,QAAA,EACL,CAAA;AAER;AAgDO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,GAAQ,CAAA;AAC5B,EAAA,uBAAO,GAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,KAAA,EAAQ,gBAAM,QAAA,EAAS,CAAA;AACvD;AAoBO,SAAS,gBAAgB,KAAA,EAA0D;AACtF,EAAA,MAAM,KAAA,GAAQ,WAAW,YAAY,CAAA;AACrC,EAAA,IAAI,SAAS,IAAA,EAAM;AACf,IAAA,IAAI,KAAA,EAAO,aAAa,KAAA,EAAO;AAC3B,MAAA,OAAO,MAAA;AAAA,IACX;AACA,IAAA,MAAM,IAAI,MAAM,2DAA2D,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,KAAA,EAAO,CAAC,CAAC,CAAA;AACzC;AAEA,SAAS,cAAc,KAAA,EAAyC;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA;AACpB;;;;"}
1
+ {"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/**\n * Properties of the {@link TitledSection} component.\n *\n * @group Headings\n **/\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n *\n * @group Headings\n * @expandType TitledSectionProps\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n *\n * @group Headings\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n *\n * @group Headings\n * @expandType SectionHeadingProps\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n *\n * @group Headings\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n * @group Headings\n * @expandType ConfigureTitledSectionProps\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/**\n * The level of a html heading.\n * @group Headings\n **/\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n * If you use it outside of a TitledSection, it will throw an error by default.\n * You can set `required: false` to make it return `undefined` instead of throwing an error\n *\n * @group Headings\n */\nexport function useHeadingLevel(): HeadingLevel;\nexport function useHeadingLevel(props: { required: false }): HeadingLevel | undefined;\nexport function useHeadingLevel(props: { required?: true }): HeadingLevel;\nexport function useHeadingLevel(props?: { required?: boolean }): HeadingLevel | undefined {\n const level = useContext(LevelContext);\n if (level == null) {\n if (props?.required === false) {\n return undefined;\n }\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAMA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,WAAA,GAAc,cAAA;AAgGpB,SAAS,cAAc,KAAA,EAAsC;AAChE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAA,EAAqB,QAAA,EAAS,GAAI,KAAA;AACjD,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,YAAY,CAAA,IAAK,CAAA;AACjD,EAAA,MAAM,OAAA,GACF,OAAO,KAAA,KAAU,QAAA,uBACZ,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAsB,QAAA,EAAA,KAAA,EAAM,CAAA,GAEhD,KAAA;AAGR,EAAA,uBACI,IAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,YAAA,GAAe,CAAA,EAC/B,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA;AAAA,GAAA,EACL,CAAA;AAER;AAwBO,SAAS,eAAe,KAAA,EAAuC;AAClE,EAAA,MAAM,EAAE,QAAA,EAAU,GAAA,EAAK,GAAG,MAAK,GAAI,KAAA;AACnC,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,GAAA,GAAM,cAAc,KAAK,CAAA;AAC/B,EAAA,2BACK,OAAA,EAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAW,GAAG,MAC3B,QAAA,EACL,CAAA;AAER;AAgDO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,GAAQ,CAAA;AAC5B,EAAA,uBAAO,GAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,KAAA,EAAQ,gBAAM,QAAA,EAAS,CAAA;AACvD;AAoBO,SAAS,gBAAgB,KAAA,EAA0D;AACtF,EAAA,MAAM,KAAA,GAAQ,WAAW,YAAY,CAAA;AACrC,EAAA,IAAI,SAAS,IAAA,EAAM;AACf,IAAA,IAAI,KAAA,EAAO,aAAa,KAAA,EAAO;AAC3B,MAAA,OAAO,MAAA;AAAA,IACX;AACA,IAAA,MAAM,IAAI,MAAM,2DAA2D,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,KAAA,EAAO,CAAC,CAAC,CAAA;AACzC;AAEA,SAAS,cAAc,KAAA,EAAyC;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA;AACpB;;;;"}
package/classNames.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"classNames.js","sources":["classNames.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nexport type ClassValue =\n string | number | boolean | null | undefined | ClassDictionary | ClassValue[];\nexport interface ClassDictionary {\n [key: string]: unknown;\n}\n\n/**\n * Joins arguments into a single string.\n * Accepts strings, numbers, arrays and plain objects (recursively).\n * For objects, each key is included when its value is true.\n */\nexport function classNames(...args: ClassValue[]): string {\n const parts: string[] = [];\n for (const arg of args) {\n if (!arg) {\n continue;\n }\n if (typeof arg === \"string\" || typeof arg === \"number\") {\n parts.push(String(arg));\n } else if (Array.isArray(arg)) {\n const inner = classNames(...arg);\n if (inner) {\n parts.push(inner);\n }\n } else if (typeof arg === \"object\") {\n for (const key of Object.keys(arg)) {\n // only include keys with truthy values\n if (arg[key]) {\n parts.push(key);\n }\n }\n }\n }\n return parts.join(\" \");\n}\n"],"names":[],"mappings":"AAcO,SAAS,cAAc,IAAA,EAA4B;AACtD,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACpB,IAAA,IAAI,CAAC,GAAA,EAAK;AACN,MAAA;AAAA,IACJ;AACA,IAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,OAAO,QAAQ,QAAA,EAAU;AACpD,MAAA,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,IAC1B,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,EAAG;AAC3B,MAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,GAAG,GAAG,CAAA;AAC/B,MAAA,IAAI,KAAA,EAAO;AACP,QAAA,KAAA,CAAM,KAAK,KAAK,CAAA;AAAA,MACpB;AAAA,IACJ,CAAA,MAAA,IAAW,OAAO,GAAA,KAAQ,QAAA,EAAU;AAChC,MAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,EAAG;AAEhC,QAAA,IAAI,GAAA,CAAI,GAAG,CAAA,EAAG;AACV,UAAA,KAAA,CAAM,KAAK,GAAG,CAAA;AAAA,QAClB;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,GAAG,CAAA;AACzB;;;;"}
1
+ {"version":3,"file":"classNames.js","sources":["classNames.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nexport type ClassValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | ClassDictionary\n | ClassValue[];\nexport interface ClassDictionary {\n [key: string]: unknown;\n}\n\n/**\n * Joins arguments into a single string.\n * Accepts strings, numbers, arrays and plain objects (recursively).\n * For objects, each key is included when its value is true.\n */\nexport function classNames(...args: ClassValue[]): string {\n const parts: string[] = [];\n for (const arg of args) {\n if (!arg) {\n continue;\n }\n if (typeof arg === \"string\" || typeof arg === \"number\") {\n parts.push(String(arg));\n } else if (Array.isArray(arg)) {\n const inner = classNames(...arg);\n if (inner) {\n parts.push(inner);\n }\n } else if (typeof arg === \"object\") {\n for (const key of Object.keys(arg)) {\n // only include keys with truthy values\n if (arg[key]) {\n parts.push(key);\n }\n }\n }\n }\n return parts.join(\" \");\n}\n"],"names":[],"mappings":"AAoBO,SAAS,cAAc,IAAA,EAA4B;AACtD,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACpB,IAAA,IAAI,CAAC,GAAA,EAAK;AACN,MAAA;AAAA,IACJ;AACA,IAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,OAAO,QAAQ,QAAA,EAAU;AACpD,MAAA,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,IAC1B,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,EAAG;AAC3B,MAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,GAAG,GAAG,CAAA;AAC/B,MAAA,IAAI,KAAA,EAAO;AACP,QAAA,KAAA,CAAM,KAAK,KAAK,CAAA;AAAA,MACpB;AAAA,IACJ,CAAA,MAAA,IAAW,OAAO,GAAA,KAAQ,QAAA,EAAU;AAChC,MAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,EAAG;AAEhC,QAAA,IAAI,GAAA,CAAI,GAAG,CAAA,EAAG;AACV,UAAA,KAAA,CAAM,KAAK,GAAG,CAAA;AAAA,QAClB;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,GAAG,CAAA;AACzB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeChakraProps.js","sources":["mergeChakraProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { mergeProps, SystemStyleObject } from \"@chakra-ui/react\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Merges multiple `props` objects from left to right.\n *\n * This function works like Chakra's {@link mergeProps}, but has additional support for Chakra's `css` property.\n * If multiple `css` objects are defined, their values are combined into an array.\n * This way, multiple css rules may match and will not override each other.\n */\nexport function mergeChakraProps<T extends {}>(\n ...args: T[]\n): Omit<UnionToIntersection<T>, \"css\"> & { css?: SystemStyleObject | SystemStyleObject[] } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const mergedProps = mergeProps(...args) as Record<string, any>;\n\n // mergeProps handles plain html attributes only; merge chakra css on our own.\n let mergedCss: SystemStyleObject | SystemStyleObject[] | undefined;\n for (const props of args) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const localCss = (props as any).css as SystemStyleObject | SystemStyleObject[] | undefined;\n if (!localCss || typeof localCss !== \"object\") {\n continue;\n }\n\n if (!mergedCss) {\n if (Array.isArray(localCss)) {\n mergedCss = [...localCss];\n } else {\n mergedCss = localCss;\n }\n } else if (!Array.isArray(mergedCss)) {\n mergedCss = [mergedCss, ...wrap(localCss)];\n } else {\n mergedCss.push(...wrap(localCss));\n }\n }\n if (mergedCss) {\n mergedProps.css = mergedCss;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return mergedProps as any;\n}\n\nfunction wrap<T>(v: T | T[]): T[] {\n if (Array.isArray(v)) {\n return v;\n }\n return [v];\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,oBACT,IAAA,EACoF;AAEvF,EAAA,MAAM,WAAA,GAAc,UAAA,CAAW,GAAG,IAAI,CAAA;AAGtC,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AAEtB,IAAA,MAAM,WAAY,KAAA,CAAc,GAAA;AAChC,IAAA,IAAI,CAAC,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,EAAU;AAC3C,MAAA;AAAA,IACJ;AAEA,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,EAAG;AACzB,QAAA,SAAA,GAAY,CAAC,GAAG,QAAQ,CAAA;AAAA,MAC5B,CAAA,MAAO;AACH,QAAA,SAAA,GAAY,QAAA;AAAA,MAChB;AAAA,IACJ,CAAA,MAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,EAAG;AAClC,MAAA,SAAA,GAAY,CAAC,SAAA,EAAW,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IAC7C,CAAA,MAAO;AACH,MAAA,SAAA,CAAU,IAAA,CAAK,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IACpC;AAAA,EACJ;AACA,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,WAAA,CAAY,GAAA,GAAM,SAAA;AAAA,EACtB;AAEA,EAAA,OAAO,WAAA;AACX;AAEA,SAAS,KAAQ,CAAA,EAAiB;AAC9B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,EAAG;AAClB,IAAA,OAAO,CAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAC,CAAC,CAAA;AACb;;;;"}
1
+ {"version":3,"file":"mergeChakraProps.js","sources":["mergeChakraProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { mergeProps, SystemStyleObject } from \"@chakra-ui/react\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Merges multiple `props` objects from left to right.\n *\n * This function works like Chakra's {@link mergeProps}, but has additional support for Chakra's `css` property.\n * If multiple `css` objects are defined, their values are combined into an array.\n * This way, multiple css rules may match and will not override each other.\n */\nexport function mergeChakraProps<T extends {}>(\n ...args: T[]\n): Omit<UnionToIntersection<T>, \"css\"> & { css?: SystemStyleObject | SystemStyleObject[] } {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const mergedProps = mergeProps(...args) as Record<string, any>;\n\n // mergeProps handles plain html attributes only; merge chakra css on our own.\n let mergedCss: SystemStyleObject | SystemStyleObject[] | undefined;\n for (const props of args) {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const localCss = (props as any).css as SystemStyleObject | SystemStyleObject[] | undefined;\n if (!localCss || typeof localCss !== \"object\") {\n continue;\n }\n\n if (!mergedCss) {\n if (Array.isArray(localCss)) {\n mergedCss = [...localCss];\n } else {\n mergedCss = localCss;\n }\n } else if (!Array.isArray(mergedCss)) {\n mergedCss = [mergedCss, ...wrap(localCss)];\n } else {\n mergedCss.push(...wrap(localCss));\n }\n }\n if (mergedCss) {\n mergedProps.css = mergedCss;\n }\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n return mergedProps as any;\n}\n\nfunction wrap<T>(v: T | T[]): T[] {\n if (Array.isArray(v)) {\n return v;\n }\n return [v];\n}\n"],"names":[],"mappings":";;AAiBO,SAAS,oBACT,IAAA,EACoF;AAEvF,EAAA,MAAM,WAAA,GAAc,UAAA,CAAW,GAAG,IAAI,CAAA;AAGtC,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AAEtB,IAAA,MAAM,WAAY,KAAA,CAAc,GAAA;AAChC,IAAA,IAAI,CAAC,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,EAAU;AAC3C,MAAA;AAAA,IACJ;AAEA,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,EAAG;AACzB,QAAA,SAAA,GAAY,CAAC,GAAG,QAAQ,CAAA;AAAA,MAC5B,CAAA,MAAO;AACH,QAAA,SAAA,GAAY,QAAA;AAAA,MAChB;AAAA,IACJ,CAAA,MAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,EAAG;AAClC,MAAA,SAAA,GAAY,CAAC,SAAA,EAAW,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IAC7C,CAAA,MAAO;AACH,MAAA,SAAA,CAAU,IAAA,CAAK,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IACpC;AAAA,EACJ;AACA,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,WAAA,CAAY,GAAA,GAAM,SAAA;AAAA,EACtB;AAEA,EAAA,OAAO,WAAA;AACX;AAEA,SAAS,KAAQ,CAAA,EAAiB;AAC9B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,EAAG;AAClB,IAAA,OAAO,CAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAC,CAAC,CAAA;AACb;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/react-utils",
4
- "version": "4.7.0-dev.20260713101438",
4
+ "version": "4.7.0",
5
5
  "description": "Contains common react utilities used by the open pioneer trails project",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -14,11 +14,11 @@
14
14
  "directory": "src/packages/react-utils"
15
15
  },
16
16
  "dependencies": {
17
- "@chakra-ui/react": "^3.36.0",
17
+ "@chakra-ui/react": "^3.36.1",
18
18
  "@conterra/reactivity-core": "^0.8.6",
19
- "react": "^19.2.7",
20
- "@open-pioneer/core": "4.7.0-dev.20260713101438",
21
- "@open-pioneer/reactivity": "4.7.0-dev.20260713101438"
19
+ "react": "^19.2.8",
20
+ "@open-pioneer/core": "4.7.0",
21
+ "@open-pioneer/reactivity": "4.7.0"
22
22
  },
23
23
  "exports": {
24
24
  "./package.json": "./package.json",
@@ -1 +1 @@
1
- {"version":3,"file":"RovingMenuRoot.js","sources":["RovingMenuRoot.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { FC, memo, ReactNode } from \"react\";\nimport { RovingMenuState, MenuStateContext } from \"./RovingMenuState\";\nimport { type useRovingMenu } from \"./useRovingMenu\";\n\n/**\n *\n * @group Roving menu\n */\nexport interface RovingMenuRootProps {\n /**\n * The menu state provided by {@link useRovingMenu}.\n */\n menuState: RovingMenuState;\n children?: ReactNode;\n}\n\n/**\n * This component must be the parent of all roving menu items.\n *\n * @group Roving menu\n * @expandType RovingMenuRootProps\n */\nexport const RovingMenuRoot: FC<RovingMenuRootProps> = memo(function RovingMenuRoot(\n props: RovingMenuRootProps\n) {\n const { menuState, children } = props;\n return <MenuStateContext.Provider value={menuState}>{children}</MenuStateContext.Provider>;\n});\n"],"names":["RovingMenuRoot"],"mappings":";;;;AAwBO,MAAM,cAAA,GAA0C,IAAA,CAAK,SAASA,eAAAA,CACjE,KAAA,EACF;AACE,EAAA,MAAM,EAAE,SAAA,EAAW,QAAA,EAAS,GAAI,KAAA;AAChC,EAAA,2BAAQ,gBAAA,CAAiB,QAAA,EAAjB,EAA0B,KAAA,EAAO,WAAY,QAAA,EAAS,CAAA;AAClE,CAAC;;;;"}
1
+ {"version":3,"file":"RovingMenuRoot.js","sources":["RovingMenuRoot.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { FC, memo, ReactNode } from \"react\";\nimport { RovingMenuState, MenuStateContext } from \"./RovingMenuState\";\n// oxlint-disable-next-line @typescript-eslint/no-unused-vars\nimport { type useRovingMenu } from \"./useRovingMenu\";\n\n/**\n *\n * @group Roving menu\n */\nexport interface RovingMenuRootProps {\n /**\n * The menu state provided by {@link useRovingMenu}.\n */\n menuState: RovingMenuState;\n children?: ReactNode;\n}\n\n/**\n * This component must be the parent of all roving menu items.\n *\n * @group Roving menu\n * @expandType RovingMenuRootProps\n */\nexport const RovingMenuRoot: FC<RovingMenuRootProps> = memo(function RovingMenuRoot(\n props: RovingMenuRootProps\n) {\n const { menuState, children } = props;\n return <MenuStateContext.Provider value={menuState}>{children}</MenuStateContext.Provider>;\n});\n"],"names":["RovingMenuRoot"],"mappings":";;;;AA0BO,MAAM,cAAA,GAA0C,IAAA,CAAK,SAASA,eAAAA,CACjE,KAAA,EACF;AACE,EAAA,MAAM,EAAE,SAAA,EAAW,QAAA,EAAS,GAAI,KAAA;AAChC,EAAA,2BAAQ,gBAAA,CAAiB,QAAA,EAAjB,EAA0B,KAAA,EAAO,WAAY,QAAA,EAAS,CAAA;AAClE,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"RovingMenuState.js","sources":["RovingMenuState.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Reactive, reactive } from \"@conterra/reactivity-core\";\nimport { createLogger } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createContext, KeyboardEvent, FocusEvent, RefObject } from \"react\";\n\nconst LOG = createLogger(sourceId);\n\n// Mostly for debugging parent/child links. Not used for lookups.\nexport const MENU_ID_ATTR = \"data-roving-menu-id\";\n\n// Children of the menu have this attribute to signal which menu they belong to.\nexport const MENU_OWNER_ATTR = \"data-roving-menu-parent\";\n\n// Children of the menu use this as their unique id (in the context of the menu).\nexport const MENU_VALUE_ATTR = \"data-roving-menu-value\";\n\n// Same as above, but for access via node.dataset\nexport const MENU_VALUE_JS = \"rovingMenuValue\";\n\nconst NOT_DISABLED_SELECTOR = \":not([disabled],[aria-disabled='true'])\";\n\n/**\n * Shared context for Menu <--> MenuItem coordination.\n *\n * @internal\n */\nexport const MenuStateContext = createContext<RovingMenuState | undefined>(undefined);\n\ndeclare const MENU_STATE_BRAND: unique symbol;\n\n/**\n * The menu state represents the internal state of the menu.\n *\n * The internals are currently hidden.\n *\n * @group Roving menu\n */\nexport interface RovingMenuState {\n [MENU_STATE_BRAND]: void;\n}\n\n/**\n * Checked cast for the internal menu state.\n * @internal\n */\nexport function getInternalState(menuState: RovingMenuState): InternalMenuState {\n if (!(menuState instanceof InternalMenuState)) {\n throw new Error(\"Invalid menu state.\");\n }\n return menuState as unknown as InternalMenuState;\n}\n\nexport interface MenuStateOptions {\n menuId: string;\n orientation: \"horizontal\" | \"vertical\";\n menuRef: RefObject<HTMLElement | null>;\n wrap: boolean;\n active: boolean;\n isActiveInParent?: () => boolean;\n}\n\n/**\n * Internal model class; created by the menu and accessible by the menu items.\n *\n * @internal\n */\nexport class InternalMenuState {\n #active: Reactive<boolean>;\n\n // True if the menu is currently active in its parent menu (used for nesting).\n // Note: reactive function\n #isActiveInParent: () => boolean;\n\n #menuRef: RefObject<HTMLElement | null>;\n\n // Value of the currently active item\n #current = reactive<string | undefined>();\n\n readonly menuId: string;\n readonly orientation: \"horizontal\" | \"vertical\";\n readonly wrap: boolean;\n\n constructor(options: MenuStateOptions) {\n this.menuId = options.menuId;\n this.wrap = options.wrap;\n this.orientation = options.orientation;\n this.#active = reactive(options.active);\n this.#menuRef = options.menuRef;\n this.#isActiveInParent = options.isActiveInParent ?? (() => true);\n }\n\n get active(): boolean {\n return this.#active.value;\n }\n\n set active(value: boolean) {\n this.#active.value = value;\n }\n\n get #currentValue(): string | undefined {\n return this.#current.value;\n }\n\n /**\n * Returns true if the menu item with the given value is currently active.\n *\n * The active menu item can receive the focus via keyboard navigation (tab).\n */\n isActive(value: string): boolean {\n return this.active && this.#isActiveInParent() && this.#currentValue === value;\n }\n\n /**\n * Called when the menu itself is focused.\n * The focus handler moves focus to the active child.\n *\n * This is used to implement nested menus.\n */\n onFocus(e: FocusEvent) {\n if (e.target !== e.currentTarget) {\n return; // Focus event from child\n }\n\n const activeValue = this.#currentValue;\n if (activeValue != null) {\n const item = getMenuItem(this.#menuRef, this.menuId, activeValue);\n if (item) {\n LOG.debug(\"Forwarding menu focus to item\", item);\n item.focus();\n } else {\n LOG.debug(\"Failed to find menu item for active value\");\n }\n }\n }\n\n /**\n * Called when a key is pressed on the menu root element.\n */\n onKeyDown(event: KeyboardEvent): void {\n if (event.defaultPrevented) {\n return; // Keyboard event from child\n }\n\n const direction = getNavDirection(event, this.orientation);\n if (!direction) {\n return;\n }\n\n const items = getMenuItems(this.#menuRef, this.menuId);\n const target = getFocusTarget(items, this.#currentValue, direction, this.wrap);\n if (!target) {\n // No candidate in the requested direction.\n return;\n }\n\n event.preventDefault();\n this.#navigateToItem(target);\n target.focus();\n }\n\n /**\n * Called by items when they mount.\n *\n * This will activate the first item to ensure that at least one item is focusable.\n */\n onItemMount(value: string): void {\n if (!this.#currentValue) {\n this.#activateItem(value);\n }\n }\n\n /**\n * Called by items when they unmount.\n * Also used to handle the case when an item becomes disabled while focused.\n *\n * This will move the active value to another item to ensure that one item is focusable.\n */\n onItemUnmount(value: string, hadFocus: boolean): void {\n if (!this.isActive(value)) {\n return;\n }\n\n this.#navigateToNextFocusableItem(value, hadFocus);\n }\n\n /**\n * Called by items when they receive focus.\n *\n * This is redundant when using arrow key navigation, but its important if\n * the item receives focus from the outside (e.g. programmatically) to sync it\n * with the menu's state.\n */\n onItemFocus(value: string): void {\n this.#activateItem(value);\n }\n\n #navigateToNextFocusableItem(disabledValue: string, hadFocus: boolean): void {\n const items = getMenuItems(this.#menuRef, this.menuId, true, false);\n const disabledIndex = findItemIndex(items, disabledValue);\n\n let target;\n if (disabledIndex === -1) {\n target = getFocusTarget(items, -1, \"home\", false);\n } else {\n // Attempt to move focus to something sensible\n target =\n getFocusTarget(items, disabledIndex, \"forward\", false) ??\n getFocusTarget(items, disabledIndex, \"backward\", false);\n }\n\n if (target) {\n this.#navigateToItem(target);\n if (hadFocus) {\n LOG.debug(\"Restoring focus within menu to\", target);\n requestAnimationFrame(() => target.focus());\n }\n return;\n }\n this.#activateItem(undefined);\n }\n\n #navigateToItem(target: HTMLElement) {\n const value = getItemValue(target);\n if (!value) {\n LOG.warn(\"Menu item without a value\", value);\n return;\n }\n this.#activateItem(value);\n }\n\n #activateItem(value: string | undefined): void {\n this.#current.value = value;\n }\n}\n\ntype NavDirection = \"backward\" | \"forward\" | \"home\" | \"end\";\n\nfunction getNavDirection(\n event: KeyboardEvent,\n orientation: \"horizontal\" | \"vertical\"\n): NavDirection | undefined {\n switch (event.key) {\n case \"ArrowUp\": {\n if (orientation === \"vertical\") {\n return \"backward\";\n }\n break;\n }\n case \"ArrowDown\": {\n if (orientation === \"vertical\") {\n return \"forward\";\n }\n break;\n }\n case \"ArrowLeft\": {\n if (orientation === \"horizontal\") {\n return \"backward\";\n }\n break;\n }\n case \"ArrowRight\": {\n if (orientation === \"horizontal\") {\n return \"forward\";\n }\n break;\n }\n case \"Home\":\n return \"home\";\n case \"End\":\n return \"end\";\n }\n}\n\nfunction getFocusTarget(\n items: HTMLElement[],\n current: string | number | undefined,\n direction: NavDirection,\n wrap: boolean\n): HTMLElement | undefined {\n if (items.length === 0) {\n return undefined;\n }\n\n let currentIndex = -1;\n if (typeof current === \"number\") {\n currentIndex = current;\n } else if (typeof current === \"string\") {\n currentIndex = findItemIndex(items, current);\n }\n\n if (currentIndex === -1 || direction === \"home\") {\n const index = items.findIndex((item) => !isDisabled(item));\n const el = items[index];\n return el;\n }\n if (direction === \"end\") {\n const index = items.findLastIndex((item) => !isDisabled(item));\n const el = items[index];\n return el;\n }\n\n if (direction === \"forward\") {\n for (let nextIndex = currentIndex + 1; ;) {\n if (nextIndex >= items.length) {\n if (!wrap) {\n break;\n }\n nextIndex = 0;\n }\n if (nextIndex === currentIndex) {\n break;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const item = items[nextIndex]!;\n if (!isDisabled(item)) {\n return item;\n }\n nextIndex += 1;\n }\n } else {\n for (let nextIndex = currentIndex - 1; ;) {\n if (nextIndex < 0) {\n if (!wrap) {\n break;\n }\n nextIndex = items.length - 1;\n }\n if (nextIndex === currentIndex) {\n break;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const item = items[nextIndex]!;\n if (!isDisabled(item)) {\n return item;\n }\n nextIndex -= 1;\n }\n }\n return undefined;\n}\n\nfunction findItemIndex(items: HTMLElement[], value: string) {\n return items.findIndex((item) => getItemValue(item) === value);\n}\n\nfunction getMenuItems(\n menuRef: RefObject<HTMLElement | null>,\n menuId: string,\n unmount = false,\n excludeDisabled = true\n): HTMLElement[] {\n const owner = menuRef.current;\n if (!owner) {\n if (unmount) {\n // List may no longer be in the DOM\n return [];\n } else {\n throw new Error(\n \"Menu parent not found in DOM. Was the 'ref' prop applied correctly to the container?\"\n );\n }\n }\n\n const escapedId = CSS.escape(menuId);\n let selector = `[${MENU_OWNER_ATTR}=${escapedId}]`;\n if (excludeDisabled) {\n selector += NOT_DISABLED_SELECTOR;\n }\n const children = owner.querySelectorAll(selector);\n return Array.from(children) as HTMLElement[];\n}\n\nfunction getMenuItem(\n menuRef: RefObject<HTMLElement | null>,\n menuId: string,\n value: string\n): HTMLElement | undefined {\n const owner = menuRef.current;\n if (!owner) {\n return undefined;\n }\n\n const escapedMenuId = CSS.escape(menuId);\n const escapedValue = CSS.escape(value);\n const node = owner.querySelector(\n `[${MENU_OWNER_ATTR}=${escapedMenuId}][${MENU_VALUE_ATTR}=${escapedValue}]${NOT_DISABLED_SELECTOR}`\n );\n return (node ?? undefined) as HTMLElement | undefined;\n}\n\nfunction getItemValue(item: HTMLElement | undefined): string | undefined {\n return item?.dataset[MENU_VALUE_JS] ?? undefined;\n}\n\nfunction isDisabled(item: HTMLElement): boolean {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return !!(item as any).disabled || item.ariaDisabled === \"true\";\n}\n"],"names":[],"mappings":";;;;;AAOA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAG1B,MAAM,YAAA,GAAe;AAGrB,MAAM,eAAA,GAAkB;AAGxB,MAAM,eAAA,GAAkB;AAGxB,MAAM,aAAA,GAAgB,iBAAA;AAE7B,MAAM,qBAAA,GAAwB,yCAAA;AAOvB,MAAM,gBAAA,GAAmB,cAA2C,MAAS;AAmB7E,SAAS,iBAAiB,SAAA,EAA+C;AAC5E,EAAA,IAAI,EAAE,qBAAqB,iBAAA,CAAA,EAAoB;AAC3C,IAAA,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAAA,EACzC;AACA,EAAA,OAAO,SAAA;AACX;AAgBO,MAAM,iBAAA,CAAkB;AAAA,EAC3B,OAAA;AAAA;AAAA;AAAA,EAIA,iBAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAGA,WAAW,QAAA,EAA6B;AAAA,EAE/B,MAAA;AAAA,EACA,WAAA;AAAA,EACA,IAAA;AAAA,EAET,YAAY,OAAA,EAA2B;AACnC,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ,WAAA;AAC3B,IAAA,IAAA,CAAK,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,MAAM,CAAA;AACtC,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACxB,IAAA,IAAA,CAAK,iBAAA,GAAoB,OAAA,CAAQ,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AAW,IAAA,EAA4B;AAE5C,EAAA,OAAO,CAAC,CAAE,IAAA,CAAa,QAAA,IAAY,KAAK,YAAA,KAAiB,MAAA;AAC7D;;;;"}
1
+ {"version":3,"file":"RovingMenuState.js","sources":["RovingMenuState.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Reactive, reactive } from \"@conterra/reactivity-core\";\nimport { createLogger } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createContext, KeyboardEvent, FocusEvent, RefObject } from \"react\";\n\nconst LOG = createLogger(sourceId);\n\n// Mostly for debugging parent/child links. Not used for lookups.\nexport const MENU_ID_ATTR = \"data-roving-menu-id\";\n\n// Children of the menu have this attribute to signal which menu they belong to.\nexport const MENU_OWNER_ATTR = \"data-roving-menu-parent\";\n\n// Children of the menu use this as their unique id (in the context of the menu).\nexport const MENU_VALUE_ATTR = \"data-roving-menu-value\";\n\n// Same as above, but for access via node.dataset\nexport const MENU_VALUE_JS = \"rovingMenuValue\";\n\nconst NOT_DISABLED_SELECTOR = \":not([disabled],[aria-disabled='true'])\";\n\n/**\n * Shared context for Menu <--> MenuItem coordination.\n *\n * @internal\n */\nexport const MenuStateContext = createContext<RovingMenuState | undefined>(undefined);\n\ndeclare const MENU_STATE_BRAND: unique symbol;\n\n/**\n * The menu state represents the internal state of the menu.\n *\n * The internals are currently hidden.\n *\n * @group Roving menu\n */\nexport interface RovingMenuState {\n [MENU_STATE_BRAND]: void;\n}\n\n/**\n * Checked cast for the internal menu state.\n * @internal\n */\nexport function getInternalState(menuState: RovingMenuState): InternalMenuState {\n if (!(menuState instanceof InternalMenuState)) {\n throw new Error(\"Invalid menu state.\");\n }\n return menuState as unknown as InternalMenuState;\n}\n\nexport interface MenuStateOptions {\n menuId: string;\n orientation: \"horizontal\" | \"vertical\";\n menuRef: RefObject<HTMLElement | null>;\n wrap: boolean;\n active: boolean;\n isActiveInParent?: () => boolean;\n}\n\n/**\n * Internal model class; created by the menu and accessible by the menu items.\n *\n * @internal\n */\nexport class InternalMenuState {\n #active: Reactive<boolean>;\n\n // True if the menu is currently active in its parent menu (used for nesting).\n // Note: reactive function\n #isActiveInParent: () => boolean;\n\n #menuRef: RefObject<HTMLElement | null>;\n\n // Value of the currently active item\n #current = reactive<string | undefined>();\n\n readonly menuId: string;\n readonly orientation: \"horizontal\" | \"vertical\";\n readonly wrap: boolean;\n\n constructor(options: MenuStateOptions) {\n this.menuId = options.menuId;\n this.wrap = options.wrap;\n this.orientation = options.orientation;\n this.#active = reactive(options.active);\n this.#menuRef = options.menuRef;\n this.#isActiveInParent = options.isActiveInParent ?? (() => true);\n }\n\n get active(): boolean {\n return this.#active.value;\n }\n\n set active(value: boolean) {\n this.#active.value = value;\n }\n\n get #currentValue(): string | undefined {\n return this.#current.value;\n }\n\n /**\n * Returns true if the menu item with the given value is currently active.\n *\n * The active menu item can receive the focus via keyboard navigation (tab).\n */\n isActive(value: string): boolean {\n return this.active && this.#isActiveInParent() && this.#currentValue === value;\n }\n\n /**\n * Called when the menu itself is focused.\n * The focus handler moves focus to the active child.\n *\n * This is used to implement nested menus.\n */\n onFocus(e: FocusEvent) {\n if (e.target !== e.currentTarget) {\n return; // Focus event from child\n }\n\n const activeValue = this.#currentValue;\n if (activeValue != null) {\n const item = getMenuItem(this.#menuRef, this.menuId, activeValue);\n if (item) {\n LOG.debug(\"Forwarding menu focus to item\", item);\n item.focus();\n } else {\n LOG.debug(\"Failed to find menu item for active value\");\n }\n }\n }\n\n /**\n * Called when a key is pressed on the menu root element.\n */\n onKeyDown(event: KeyboardEvent): void {\n if (event.defaultPrevented) {\n return; // Keyboard event from child\n }\n\n const direction = getNavDirection(event, this.orientation);\n if (!direction) {\n return;\n }\n\n const items = getMenuItems(this.#menuRef, this.menuId);\n const target = getFocusTarget(items, this.#currentValue, direction, this.wrap);\n if (!target) {\n // No candidate in the requested direction.\n return;\n }\n\n event.preventDefault();\n this.#navigateToItem(target);\n target.focus();\n }\n\n /**\n * Called by items when they mount.\n *\n * This will activate the first item to ensure that at least one item is focusable.\n */\n onItemMount(value: string): void {\n if (!this.#currentValue) {\n this.#activateItem(value);\n }\n }\n\n /**\n * Called by items when they unmount.\n * Also used to handle the case when an item becomes disabled while focused.\n *\n * This will move the active value to another item to ensure that one item is focusable.\n */\n onItemUnmount(value: string, hadFocus: boolean): void {\n if (!this.isActive(value)) {\n return;\n }\n\n this.#navigateToNextFocusableItem(value, hadFocus);\n }\n\n /**\n * Called by items when they receive focus.\n *\n * This is redundant when using arrow key navigation, but its important if\n * the item receives focus from the outside (e.g. programmatically) to sync it\n * with the menu's state.\n */\n onItemFocus(value: string): void {\n this.#activateItem(value);\n }\n\n #navigateToNextFocusableItem(disabledValue: string, hadFocus: boolean): void {\n const items = getMenuItems(this.#menuRef, this.menuId, true, false);\n const disabledIndex = findItemIndex(items, disabledValue);\n\n let target;\n if (disabledIndex === -1) {\n target = getFocusTarget(items, -1, \"home\", false);\n } else {\n // Attempt to move focus to something sensible\n target =\n getFocusTarget(items, disabledIndex, \"forward\", false) ??\n getFocusTarget(items, disabledIndex, \"backward\", false);\n }\n\n if (target) {\n this.#navigateToItem(target);\n if (hadFocus) {\n LOG.debug(\"Restoring focus within menu to\", target);\n requestAnimationFrame(() => target.focus());\n }\n return;\n }\n this.#activateItem(undefined);\n }\n\n #navigateToItem(target: HTMLElement) {\n const value = getItemValue(target);\n if (!value) {\n LOG.warn(\"Menu item without a value\", value);\n return;\n }\n this.#activateItem(value);\n }\n\n #activateItem(value: string | undefined): void {\n this.#current.value = value;\n }\n}\n\ntype NavDirection = \"backward\" | \"forward\" | \"home\" | \"end\";\n\nfunction getNavDirection(\n event: KeyboardEvent,\n orientation: \"horizontal\" | \"vertical\"\n): NavDirection | undefined {\n switch (event.key) {\n case \"ArrowUp\": {\n if (orientation === \"vertical\") {\n return \"backward\";\n }\n break;\n }\n case \"ArrowDown\": {\n if (orientation === \"vertical\") {\n return \"forward\";\n }\n break;\n }\n case \"ArrowLeft\": {\n if (orientation === \"horizontal\") {\n return \"backward\";\n }\n break;\n }\n case \"ArrowRight\": {\n if (orientation === \"horizontal\") {\n return \"forward\";\n }\n break;\n }\n case \"Home\":\n return \"home\";\n case \"End\":\n return \"end\";\n }\n}\n\nfunction getFocusTarget(\n items: HTMLElement[],\n current: string | number | undefined,\n direction: NavDirection,\n wrap: boolean\n): HTMLElement | undefined {\n if (items.length === 0) {\n return undefined;\n }\n\n let currentIndex = -1;\n if (typeof current === \"number\") {\n currentIndex = current;\n } else if (typeof current === \"string\") {\n currentIndex = findItemIndex(items, current);\n }\n\n if (currentIndex === -1 || direction === \"home\") {\n const index = items.findIndex((item) => !isDisabled(item));\n const el = items[index];\n return el;\n }\n if (direction === \"end\") {\n const index = items.findLastIndex((item) => !isDisabled(item));\n const el = items[index];\n return el;\n }\n\n if (direction === \"forward\") {\n for (let nextIndex = currentIndex + 1; ; ) {\n if (nextIndex >= items.length) {\n if (!wrap) {\n break;\n }\n nextIndex = 0;\n }\n if (nextIndex === currentIndex) {\n break;\n }\n\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n const item = items[nextIndex]!;\n if (!isDisabled(item)) {\n return item;\n }\n nextIndex += 1;\n }\n } else {\n for (let nextIndex = currentIndex - 1; ; ) {\n if (nextIndex < 0) {\n if (!wrap) {\n break;\n }\n nextIndex = items.length - 1;\n }\n if (nextIndex === currentIndex) {\n break;\n }\n\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n const item = items[nextIndex]!;\n if (!isDisabled(item)) {\n return item;\n }\n nextIndex -= 1;\n }\n }\n return undefined;\n}\n\nfunction findItemIndex(items: HTMLElement[], value: string) {\n return items.findIndex((item) => getItemValue(item) === value);\n}\n\nfunction getMenuItems(\n menuRef: RefObject<HTMLElement | null>,\n menuId: string,\n unmount = false,\n excludeDisabled = true\n): HTMLElement[] {\n const owner = menuRef.current;\n if (!owner) {\n if (unmount) {\n // List may no longer be in the DOM\n return [];\n } else {\n throw new Error(\n \"Menu parent not found in DOM. Was the 'ref' prop applied correctly to the container?\"\n );\n }\n }\n\n const escapedId = CSS.escape(menuId);\n let selector = `[${MENU_OWNER_ATTR}=${escapedId}]`;\n if (excludeDisabled) {\n selector += NOT_DISABLED_SELECTOR;\n }\n const children = owner.querySelectorAll(selector);\n return Array.from(children) as HTMLElement[];\n}\n\nfunction getMenuItem(\n menuRef: RefObject<HTMLElement | null>,\n menuId: string,\n value: string\n): HTMLElement | undefined {\n const owner = menuRef.current;\n if (!owner) {\n return undefined;\n }\n\n const escapedMenuId = CSS.escape(menuId);\n const escapedValue = CSS.escape(value);\n const node = owner.querySelector(\n `[${MENU_OWNER_ATTR}=${escapedMenuId}][${MENU_VALUE_ATTR}=${escapedValue}]${NOT_DISABLED_SELECTOR}`\n );\n return (node ?? undefined) as HTMLElement | undefined;\n}\n\nfunction getItemValue(item: HTMLElement | undefined): string | undefined {\n return item?.dataset[MENU_VALUE_JS] ?? undefined;\n}\n\nfunction isDisabled(item: HTMLElement): boolean {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n return !!(item as any).disabled || item.ariaDisabled === \"true\";\n}\n"],"names":[],"mappings":";;;;;AAQA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAG1B,MAAM,YAAA,GAAe;AAGrB,MAAM,eAAA,GAAkB;AAGxB,MAAM,eAAA,GAAkB;AAGxB,MAAM,aAAA,GAAgB,iBAAA;AAE7B,MAAM,qBAAA,GAAwB,yCAAA;AAOvB,MAAM,gBAAA,GAAmB,cAA2C,MAAS;AAmB7E,SAAS,iBAAiB,SAAA,EAA+C;AAC5E,EAAA,IAAI,EAAE,qBAAqB,iBAAA,CAAA,EAAoB;AAC3C,IAAA,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAAA,EACzC;AACA,EAAA,OAAO,SAAA;AACX;AAgBO,MAAM,iBAAA,CAAkB;AAAA,EAC3B,OAAA;AAAA;AAA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,EACX;AAEA,EAAA,MAAM,aAAA,GAAgB,GAAA,CAAI,MAAA,CAAO,MAAM,CAAA;AACvC,EAAA,MAAM,YAAA,GAAe,GAAA,CAAI,MAAA,CAAO,KAAK,CAAA;AACrC,EAAA,MAAM,OAAO,KAAA,CAAM,aAAA;AAAA,IACf,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA,EAAI,aAAa,KAAK,eAAe,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA,EAAI,qBAAqB,CAAA;AAAA,GACrG;AACA,EAAA,OAAQ,IAAA,IAAQ,MAAA;AACpB;AAEA,SAAS,aAAa,IAAA,EAAmD;AACrE,EAAA,OAAO,IAAA,EAAM,OAAA,CAAQ,aAAa,CAAA,IAAK,MAAA;AAC3C;AAEA,SAAS,WAAW,IAAA,EAA4B;AAE5C,EAAA,OAAO,CAAC,CAAE,IAAA,CAAa,QAAA,IAAY,KAAK,YAAA,KAAiB,MAAA;AAC7D;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMenuState.js","sources":["useMenuState.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext } from \"react\";\nimport { InternalMenuState, MenuStateContext, getInternalState } from \"./RovingMenuState\";\n\nexport function useMenuState(): InternalMenuState;\nexport function useMenuState(required: true): InternalMenuState;\nexport function useMenuState(required: boolean): InternalMenuState | undefined;\nexport function useMenuState(required = true): InternalMenuState | undefined {\n const state = useContext(MenuStateContext);\n if (!state) {\n if (required) {\n throw new Error(\n \"Failed to find the outer menu. Is the menu item surrounded by the RovingMenuRoot?\"\n );\n }\n return undefined;\n }\n return getInternalState(state);\n}\n"],"names":[],"mappings":";;;AAQO,SAAS,YAAA,CAAa,WAAW,IAAA,EAAqC;AACzE,EAAA,MAAM,KAAA,GAAQ,WAAW,gBAAgB,CAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO;AACR,IAAA,IAAI,QAAA,EAAU;AACV,MAAA,MAAM,IAAI,KAAA;AAAA,QACN;AAAA,OACJ;AAAA,IACJ;AACA,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,OAAO,iBAAiB,KAAK,CAAA;AACjC;;;;"}
1
+ {"version":3,"file":"useMenuState.js","sources":["useMenuState.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from \"react\";\nimport { InternalMenuState, MenuStateContext, getInternalState } from \"./RovingMenuState\";\n\nexport function useMenuState(): InternalMenuState;\nexport function useMenuState(required: true): InternalMenuState;\nexport function useMenuState(required: boolean): InternalMenuState | undefined;\nexport function useMenuState(required = true): InternalMenuState | undefined {\n const state = useContext(MenuStateContext);\n if (!state) {\n if (required) {\n throw new Error(\n \"Failed to find the outer menu. Is the menu item surrounded by the RovingMenuRoot?\"\n );\n }\n return undefined;\n }\n return getInternalState(state);\n}\n"],"names":[],"mappings":";;;AASO,SAAS,YAAA,CAAa,WAAW,IAAA,EAAqC;AACzE,EAAA,MAAM,KAAA,GAAQ,WAAW,gBAAgB,CAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO;AACR,IAAA,IAAI,QAAA,EAAU;AACV,MAAA,MAAM,IAAI,KAAA;AAAA,QACN;AAAA,OACJ;AAAA,IACJ;AACA,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,OAAO,iBAAiB,KAAK,CAAA;AACjC;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { useCallback, useMemo, useId, useRef, useEffect } from 'react';
2
2
  import { useEvent } from '../useEvent.js';
3
3
  import { InternalMenuState, MENU_ID_ATTR } from './RovingMenuState.js';
4
- import { useRovingMenuItemImpl } from './useRovingMenuItem.js';
5
4
  import { useMenuState } from './useMenuState.js';
5
+ import { useRovingMenuItemImpl } from './useRovingMenuItem.js';
6
6
 
7
7
  function useRovingMenu(props = {}) {
8
8
  return useRovingMenuImpl(props);
@@ -1 +1 @@
1
- {"version":3,"file":"useRovingMenu.js","sources":["useRovingMenu.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { KeyboardEvent, FocusEvent, RefObject, useCallback, useId, useMemo, useRef } from \"react\";\nimport { useEvent } from \"../useEvent\";\nimport { type RovingMenuRoot } from \"./RovingMenuRoot\";\nimport { InternalMenuState, MENU_ID_ATTR, RovingMenuState } from \"./RovingMenuState\";\nimport { RovingMenuItemDomProps, useRovingMenuItemImpl } from \"./useRovingMenuItem\";\nimport { useMenuState } from \"./useMenuState\";\nimport { useEffect } from \"react\";\n\n/**\n * Properties supported when creating a new menu via {@link useRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuProps {\n /**\n * Configures the orientation of the menu (default: `horizontal`).\n *\n * Horizontal menus can be navigated using left/right, vertical menus use up/down.\n */\n orientation?: \"vertical\" | \"horizontal\";\n\n /**\n * Wrap around when pressing an arrow key at the start or the end of the menu.\n *\n * Default: `true`.\n */\n wrap?: boolean;\n\n /**\n * Whether the menu is active.\n * Only active menus are focusable by the user through keyboard navigation.\n *\n * Default: `true`\n */\n active?: boolean;\n}\n\n/** @internal */\nexport interface RovingMenuDomProps {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref: RefObject<any>;\n role: string;\n tabIndex: number;\n [MENU_ID_ATTR]: string;\n \"aria-orientation\": \"horizontal\" | \"vertical\";\n onKeyDown: (event: KeyboardEvent) => void;\n onFocus: (event: FocusEvent) => void;\n}\n\n/**\n * The return value of {@link useRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuResult {\n /**\n * DOM-Properties that must be applied to the menu's dom element.\n *\n * Note that other properties may be added in a future release.\n */\n menuProps: RovingMenuDomProps;\n\n /**\n * Properties that should be passed to the {@link RovingMenuRoot}.\n *\n * The specific internals of this object are an implementation detail.\n */\n menuState: RovingMenuState;\n}\n\n/**\n * The roving menu is a render-less component for lists that support keyboard navigation.\n * It implements the basics for an accessible, keyboard navigable menu using the \"roving tab index\" pattern.\n *\n * Items can be navigated using arrow keys and home/end keys.\n *\n * @group Roving menu\n * @expandType RovingMenuProps\n */\nexport function useRovingMenu(props: RovingMenuProps = {}): RovingMenuResult {\n return useRovingMenuImpl(props);\n}\n\n/**\n * Properties supported when creating a new nested menu via {@link useNestedRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface NestedRovingMenuProps extends RovingMenuProps {\n /**\n * The value of the menu within its parent menu.\n */\n value: string;\n}\n\n/**\n * The return value of {@link useNestedRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface NestedRovingMenuResult extends RovingMenuResult {\n menuProps: RovingMenuDomProps & RovingMenuItemDomProps;\n}\n\n/**\n * Like {@link useRovingMenu}, but suitable for nested menus.\n *\n * Only a single level of nested is supported at this time (i.e. horizontal in vertical, or the other way around).\n *\n * @group Roving menu\n * @expandType NestedRovingMenuProps\n */\nexport function useNestedRovingMenu(props: NestedRovingMenuProps): NestedRovingMenuResult {\n const parentMenuState = useMenuState();\n const { menuProps, menuState } = useRovingMenuImpl(\n props,\n useCallback(() => parentMenuState.isActive(props.value), [parentMenuState, props.value])\n );\n const { itemProps } = useRovingMenuItemImpl(props, \"nested\");\n\n return useMemo(() => {\n return {\n menuProps: {\n ...menuProps,\n ...itemProps,\n onFocus(e: FocusEvent) {\n // Tracks active state in parent\n itemProps.onFocus(e);\n\n // Focuses the correct child\n menuProps.onFocus(e);\n }\n },\n menuState\n };\n }, [menuProps, menuState, itemProps]);\n}\n\nfunction useRovingMenuImpl(\n props: RovingMenuProps,\n isActiveInParent?: () => boolean\n): RovingMenuResult {\n const { orientation = \"horizontal\", active = true, wrap = true } = props;\n const menuId = useId();\n const menuRef = useRef<HTMLElement>(null);\n\n const initialActive = useRef(active);\n\n // Shared state between items and root\n const state = useMemo(\n () =>\n new InternalMenuState({\n menuId,\n orientation,\n menuRef,\n wrap,\n active: initialActive.current,\n isActiveInParent\n }),\n [menuRef, orientation, menuId, wrap, isActiveInParent]\n );\n\n // Fine grained updates without losing state\n useEffect(() => {\n state.active = active;\n }, [state, active]);\n\n const onKeyDown = useEvent((event: KeyboardEvent) => {\n state.onKeyDown(event);\n });\n const onFocus = useEvent((event: FocusEvent) => {\n state.onFocus(event);\n });\n const result = useMemo(\n (): RovingMenuResult => ({\n menuProps: {\n ref: menuRef,\n role: \"toolbar\",\n \"aria-orientation\": orientation,\n tabIndex: -1,\n [MENU_ID_ATTR]: menuId,\n onKeyDown,\n onFocus\n },\n menuState: state as unknown as RovingMenuState\n }),\n [menuId, orientation, onKeyDown, onFocus, state]\n );\n return result;\n}\n"],"names":[],"mappings":";;;;;;AAiFO,SAAS,aAAA,CAAc,KAAA,GAAyB,EAAC,EAAqB;AACzE,EAAA,OAAO,kBAAkB,KAAK,CAAA;AAClC;AA+BO,SAAS,oBAAoB,KAAA,EAAsD;AACtF,EAAA,MAAM,kBAAkB,YAAA,EAAa;AACrC,EAAA,MAAM,EAAE,SAAA,EAAW,SAAA,EAAU,GAAI,iBAAA;AAAA,IAC7B,KAAA;AAAA,IACA,WAAA,CAAY,MAAM,eAAA,CAAgB,QAAA,CAAS,KAAA,CAAM,KAAK,CAAA,EAAG,CAAC,eAAA,EAAiB,KAAA,CAAM,KAAK,CAAC;AAAA,GAC3F;AACA,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,qBAAA,CAAsB,OAAO,QAAQ,CAAA;AAE3D,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAA,OAAO;AAAA,MACH,SAAA,EAAW;AAAA,QACP,GAAG,SAAA;AAAA,QACH,GAAG,SAAA;AAAA,QACH,QAAQ,CAAA,EAAe;AAEnB,UAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAGnB,UAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA,QACvB;AAAA,OACJ;AAAA,MACA;AAAA,KACJ;AAAA,EACJ,CAAA,EAAG,C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A;AAAA,QAChB,SAAA;AAAA,QACA;AAAA,OACJ;AAAA,MACA,SAAA,EAAW;AAAA,KACf,CAAA;AAAA,IACA,CAAC,MAAA,EAAQ,WAAA,EAAa,SAAA,EAAW,SAAS,KAAK;AAAA,GACnD;AACA,EAAA,OAAO,MAAA;AACX;;;;"}
1
+ {"version":3,"file":"useRovingMenu.js","sources":["useRovingMenu.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n KeyboardEvent,\n FocusEvent,\n RefObject,\n useCallback,\n useId,\n useMemo,\n useRef,\n useEffect\n} from \"react\";\nimport { useEvent } from \"../useEvent\";\n// oxlint-disable-next-line @typescript-eslint/no-unused-vars\nimport { type RovingMenuRoot } from \"./RovingMenuRoot\";\nimport { InternalMenuState, MENU_ID_ATTR, RovingMenuState } from \"./RovingMenuState\";\nimport { useMenuState } from \"./useMenuState\";\nimport { RovingMenuItemDomProps, useRovingMenuItemImpl } from \"./useRovingMenuItem\";\n\n/**\n * Properties supported when creating a new menu via {@link useRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuProps {\n /**\n * Configures the orientation of the menu (default: `horizontal`).\n *\n * Horizontal menus can be navigated using left/right, vertical menus use up/down.\n */\n orientation?: \"vertical\" | \"horizontal\";\n\n /**\n * Wrap around when pressing an arrow key at the start or the end of the menu.\n *\n * Default: `true`.\n */\n wrap?: boolean;\n\n /**\n * Whether the menu is active.\n * Only active menus are focusable by the user through keyboard navigation.\n *\n * Default: `true`\n */\n active?: boolean;\n}\n\n/** @internal */\nexport interface RovingMenuDomProps {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ref: RefObject<any>;\n role: string;\n tabIndex: number;\n [MENU_ID_ATTR]: string;\n \"aria-orientation\": \"horizontal\" | \"vertical\";\n onKeyDown: (event: KeyboardEvent) => void;\n onFocus: (event: FocusEvent) => void;\n}\n\n/**\n * The return value of {@link useRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuResult {\n /**\n * DOM-Properties that must be applied to the menu's dom element.\n *\n * Note that other properties may be added in a future release.\n */\n menuProps: RovingMenuDomProps;\n\n /**\n * Properties that should be passed to the {@link RovingMenuRoot}.\n *\n * The specific internals of this object are an implementation detail.\n */\n menuState: RovingMenuState;\n}\n\n/**\n * The roving menu is a render-less component for lists that support keyboard navigation.\n * It implements the basics for an accessible, keyboard navigable menu using the \"roving tab index\" pattern.\n *\n * Items can be navigated using arrow keys and home/end keys.\n *\n * @group Roving menu\n * @expandType RovingMenuProps\n */\nexport function useRovingMenu(props: RovingMenuProps = {}): RovingMenuResult {\n return useRovingMenuImpl(props);\n}\n\n/**\n * Properties supported when creating a new nested menu via {@link useNestedRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface NestedRovingMenuProps extends RovingMenuProps {\n /**\n * The value of the menu within its parent menu.\n */\n value: string;\n}\n\n/**\n * The return value of {@link useNestedRovingMenu}.\n *\n * @group Roving menu\n */\nexport interface NestedRovingMenuResult extends RovingMenuResult {\n menuProps: RovingMenuDomProps & RovingMenuItemDomProps;\n}\n\n/**\n * Like {@link useRovingMenu}, but suitable for nested menus.\n *\n * Only a single level of nested is supported at this time (i.e. horizontal in vertical, or the other way around).\n *\n * @group Roving menu\n * @expandType NestedRovingMenuProps\n */\nexport function useNestedRovingMenu(props: NestedRovingMenuProps): NestedRovingMenuResult {\n const parentMenuState = useMenuState();\n const { menuProps, menuState } = useRovingMenuImpl(\n props,\n useCallback(() => parentMenuState.isActive(props.value), [parentMenuState, props.value])\n );\n const { itemProps } = useRovingMenuItemImpl(props, \"nested\");\n\n return useMemo(() => {\n return {\n menuProps: {\n ...menuProps,\n ...itemProps,\n onFocus(e: FocusEvent) {\n // Tracks active state in parent\n itemProps.onFocus(e);\n\n // Focuses the correct child\n menuProps.onFocus(e);\n }\n },\n menuState\n };\n }, [menuProps, menuState, itemProps]);\n}\n\nfunction useRovingMenuImpl(\n props: RovingMenuProps,\n isActiveInParent?: () => boolean\n): RovingMenuResult {\n const { orientation = \"horizontal\", active = true, wrap = true } = props;\n const menuId = useId();\n const menuRef = useRef<HTMLElement>(null);\n\n const initialActive = useRef(active);\n\n // Shared state between items and root\n const state = useMemo(\n () =>\n new InternalMenuState({\n menuId,\n orientation,\n menuRef,\n wrap,\n active: initialActive.current,\n isActiveInParent\n }),\n [menuRef, orientation, menuId, wrap, isActiveInParent]\n );\n\n // Fine grained updates without losing state\n useEffect(() => {\n state.active = active;\n }, [state, active]);\n\n const onKeyDown = useEvent((event: KeyboardEvent) => {\n state.onKeyDown(event);\n });\n const onFocus = useEvent((event: FocusEvent) => {\n state.onFocus(event);\n });\n const result = useMemo(\n (): RovingMenuResult => ({\n menuProps: {\n ref: menuRef,\n role: \"toolbar\",\n \"aria-orientation\": orientation,\n tabIndex: -1,\n [MENU_ID_ATTR]: menuId,\n onKeyDown,\n onFocus\n },\n menuState: state as unknown as RovingMenuState\n }),\n [menuId, orientation, onKeyDown, onFocus, state]\n );\n return result;\n}\n"],"names":[],"mappings":";;;;;;AA2FO,SAAS,aAAA,CAAc,KAAA,GAAyB,EAAC,EAAqB;AACzE,EAAA,OAAO,kBAAkB,KAAK,CAAA;AAClC;AA+BO,SAAS,oBAAoB,KAAA,EAAsD;AACtF,EAAA,MAAM,kBAAkB,YAAA,EAAa;AACrC,EAAA,MAAM,EAAE,SAAA,EAAW,SAAA,EAAU,GAAI,iBAAA;AAAA,IAC7B,KAAA;AAAA,IACA,WAAA,CAAY,MAAM,eAAA,CAAgB,QAAA,CAAS,KAAA,CAAM,KAAK,CAAA,EAAG,CAAC,eAAA,EAAiB,KAAA,CAAM,KAAK,CAAC;AAAA,GAC3F;AACA,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,qBAAA,CAAsB,OAAO,QAAQ,CAAA;AAE3D,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAA,OAAO;AAAA,MACH,SAAA,EAAW;AAAA,QACP,GAAG,S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,MAAM,MAAA,GAAS,OAAA;AAAA,IACX,OAAyB;AAAA,MACrB,SAAA,EAAW;AAAA,QACP,GAAA,EAAK,OAAA;AAAA,QACL,IAAA,EAAM,SAAA;AAAA,QACN,kBAAA,EAAoB,WAAA;AAAA,QACpB,QAAA,EAAU,EAAA;AAAA,QACV,CAAC,YAAY,GAAG,MAAA;AAAA,QAChB,SAAA;AAAA,QACA;AAAA,OACJ;AAAA,MACA,SAAA,EAAW;AAAA,KACf,CAAA;AAAA,IACA,CAAC,MAAA,EAAQ,WAAA,EAAa,SAAA,EAAW,SAAS,KAAK;AAAA,GACnD;AACA,EAAA,OAAO,MAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRovingMenuItem.js","sources":["useRovingMenuItem.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FocusEventHandler, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { MENU_OWNER_ATTR, MENU_VALUE_ATTR } from \"./RovingMenuState\";\nimport { useMenuState } from \"./useMenuState\";\n\n/**\n * Properties support when creating a new menu item via {@link useRovingMenuItem}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuItemProps {\n /**\n * A unique value for the current item (in the context of this menu).\n */\n value: string;\n\n /**\n * Set this to true if your item is disabled.\n *\n * This tells the menu that the item cannot be focused.\n */\n disabled?: boolean;\n\n /**\n * By default, a menu item parent is required.\n *\n * Set this to `false` to make the parent optional.\n * The hook will become inactive and will return `undefined` if no parent is present.\n * This is useful for components that may or may not be used within a menu.\n *\n * Default: `true`\n */\n required?: boolean;\n}\n\n/** @internal */\nexport interface RovingMenuItemDomProps {\n [MENU_OWNER_ATTR]: string;\n [MENU_VALUE_ATTR]: string;\n tabIndex: number;\n onFocus: FocusEventHandler;\n onBlur: FocusEventHandler;\n}\n\n/**\n * The return value of {@link useRovingMenuItem}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuItemResult {\n /**\n * DOM-Properties that must be applied to the menu item's dom element.\n *\n * Most importantly, this will apply the item's tab index and data attributes\n * that allow the menu to find the item in the DOM.\n *\n * Note that other properties may be added in a future release.\n */\n itemProps: RovingMenuItemDomProps;\n}\n\n/**\n * Declares a new menu item using the given `props`.\n * @group Roving menu\n * @expandType RovingMenuItemProps\n */\nexport function useRovingMenuItem(\n props: RovingMenuItemProps & { required?: true }\n): RovingMenuItemResult;\nexport function useRovingMenuItem(props: RovingMenuItemProps): RovingMenuItemResult | undefined;\nexport function useRovingMenuItem(props: RovingMenuItemProps): RovingMenuItemResult | undefined {\n return useRovingMenuItemImpl(props, \"item\");\n}\n\n/**\n * @internal\n */\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps & { required?: true },\n context: \"item\" | \"nested\"\n): RovingMenuItemResult;\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps,\n context: \"item\" | \"nested\"\n): RovingMenuItemResult | undefined;\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps,\n context: \"item\" | \"nested\"\n): RovingMenuItemResult | undefined {\n const { value, disabled = false, required = true } = props;\n const state = useMenuState(required);\n\n const hasFocus = useRef(false);\n\n useLayoutEffect(() => {\n if (!state || disabled) {\n return;\n }\n state.onItemMount(value);\n return () => state.onItemUnmount(value, hasFocus.current);\n }, [state, value, disabled]);\n\n const isActiveValue = useReactiveSnapshot(() => state?.isActive(value), [state, value]);\n const isActive = !disabled && isActiveValue;\n const result = useMemo((): RovingMenuItemResult | undefined => {\n if (!state) {\n return undefined;\n }\n const menuId = state.menuId;\n return {\n itemProps: {\n [MENU_OWNER_ATTR]: menuId,\n [MENU_VALUE_ATTR]: value,\n\n // items can be reached via user tab, nested menus can't\n tabIndex: context === \"item\" && isActive ? 0 : -1,\n\n onFocus: (_event) => {\n hasFocus.current = true;\n state?.onItemFocus(value);\n },\n onBlur: (_event) => {\n hasFocus.current = false;\n }\n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A,EAAS,CAAC,MAAA,KAAW;AACjB,UAAA,QAAA,CAAS,OAAA,GAAU,IAAA;AACnB,UAAA,KAAA,EAAO,YAAY,KAAK,CAAA;AAAA,QAC5B,CAAA;AAAA,QACA,MAAA,EAAQ,CAAC,MAAA,KAAW;AAChB,UAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAAA,QACvB;AAAA;AACJ,KACJ;AAAA,EACJ,GAAG,CAAC,KAAA,EAAO,KAAA,EAAO,QAAA,EAAU,OAAO,CAAC,CAAA;AACpC,EAAA,OAAO,MAAA;AACX;;;;"}
1
+ {"version":3,"file":"useRovingMenuItem.js","sources":["useRovingMenuItem.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FocusEventHandler, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { MENU_OWNER_ATTR, MENU_VALUE_ATTR } from \"./RovingMenuState\";\nimport { useMenuState } from \"./useMenuState\";\n\n/**\n * Properties support when creating a new menu item via {@link useRovingMenuItem}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuItemProps {\n /**\n * A unique value for the current item (in the context of this menu).\n */\n value: string;\n\n /**\n * Set this to true if your item is disabled.\n *\n * This tells the menu that the item cannot be focused.\n */\n disabled?: boolean;\n\n /**\n * By default, a menu item parent is required.\n *\n * Set this to `false` to make the parent optional.\n * The hook will become inactive and will return `undefined` if no parent is present.\n * This is useful for components that may or may not be used within a menu.\n *\n * Default: `true`\n */\n required?: boolean;\n}\n\n/** @internal */\nexport interface RovingMenuItemDomProps {\n [MENU_OWNER_ATTR]: string;\n [MENU_VALUE_ATTR]: string;\n tabIndex: number;\n onFocus: FocusEventHandler;\n onBlur: FocusEventHandler;\n}\n\n/**\n * The return value of {@link useRovingMenuItem}.\n *\n * @group Roving menu\n */\nexport interface RovingMenuItemResult {\n /**\n * DOM-Properties that must be applied to the menu item's dom element.\n *\n * Most importantly, this will apply the item's tab index and data attributes\n * that allow the menu to find the item in the DOM.\n *\n * Note that other properties may be added in a future release.\n */\n itemProps: RovingMenuItemDomProps;\n}\n\n/**\n * Declares a new menu item using the given `props`.\n * @group Roving menu\n * @expandType RovingMenuItemProps\n */\nexport function useRovingMenuItem(\n props: RovingMenuItemProps & { required?: true }\n): RovingMenuItemResult;\nexport function useRovingMenuItem(props: RovingMenuItemProps): RovingMenuItemResult | undefined;\nexport function useRovingMenuItem(props: RovingMenuItemProps): RovingMenuItemResult | undefined {\n return useRovingMenuItemImpl(props, \"item\");\n}\n\n/**\n * @internal\n */\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps & { required?: true },\n context: \"item\" | \"nested\"\n): RovingMenuItemResult;\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps,\n context: \"item\" | \"nested\"\n): RovingMenuItemResult | undefined;\nexport function useRovingMenuItemImpl(\n props: RovingMenuItemProps,\n context: \"item\" | \"nested\"\n): RovingMenuItemResult | undefined {\n const { value, disabled = false, required = true } = props;\n const state = useMenuState(required);\n\n const hasFocus = useRef(false);\n\n useLayoutEffect(() => {\n if (!state || disabled) {\n return;\n }\n state.onItemMount(value);\n return () => state.onItemUnmount(value, hasFocus.current);\n }, [state, value, disabled]);\n\n const isActiveValue = useReactiveSnapshot(() => state?.isActive(value), [state, value]);\n const isActive = !disabled && isActiveValue;\n const result = useMemo((): RovingMenuItemResult | undefined => {\n if (!state) {\n return undefined;\n }\n const menuId = state.menuId;\n return {\n itemProps: {\n [MENU_OWNER_ATTR]: menuId,\n [MENU_VALUE_ATTR]: value,\n\n // items can be reached via user tab, nested menus can't\n tabIndex: context === \"item\" && isActive ? 0 : -1,\n\n onFocus: (_event) => {\n hasFocus.current = true;\n state?.onItemFocus(value);\n },\n onBlur: (_event) => {\n hasFocus.current = false;\n }\n }\n };\n }, [state, value, isActive, context]);\n return result;\n}\n"],"names":[],"mappings":";;;;;AAyEO,SAA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;AACnB,UAAA,KAAA,EAAO,YAAY,KAAK,CAAA;AAAA,QAC5B,CAAA;AAAA,QACA,MAAA,EAAQ,CAAC,MAAA,KAAW;AAChB,UAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAAA,QACvB;AAAA;AACJ,KACJ;AAAA,EACJ,GAAG,CAAC,KAAA,EAAO,KAAA,EAAO,QAAA,EAAU,OAAO,CAAC,CAAA;AACpC,EAAA,OAAO,MAAA;AACX;;;;"}
@@ -1,5 +1,5 @@
1
- import { classNames } from './classNames.js';
2
1
  import { useMemo } from 'react';
2
+ import { classNames } from './classNames.js';
3
3
 
4
4
  const COPY_PROP_RE = /^(data|aria)-/;
5
5
  function useCommonComponentProps(componentClassName, props) {
@@ -1 +1 @@
1
- {"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemStyleObject } from \"@chakra-ui/react\";\nimport { classNames } from \"./classNames\";\nimport { HTMLAttributes, AriaAttributes, useMemo, AriaRole } from \"react\";\n\n/**\n * Common properties supported by all public react components.\n *\n * This type allows for the customization of\n * - the css `className`\n * - a Chakra `css` property\n * - \"role\" and `aria-*` properties\n * - arbitrary `data-*` properties\n *\n * Prop types for react components typically inherit from this interface.\n *\n * @group Common component props\n */\nexport interface CommonComponentProps extends AriaAttributes {\n /**\n * Additional class name(s).\n */\n className?: string;\n\n /**\n * Custom style rules using Chakra's style objects.\n */\n css?: SystemStyleObject | SystemStyleObject[];\n\n /**\n * Custom ARIA role.\n */\n role?: AriaRole;\n\n /**\n * Used for testing.\n */\n \"data-testid\"?: string;\n\n /**\n * Arbitrary data attributes.\n *\n * NOTE: The component may use data properties for its own behavior.\n * Make sure not to overwrite required attributes.\n */\n [key: `data-${string}`]: unknown;\n}\n\nconst COPY_PROP_RE = /^(data|aria)-/;\n\n/**\n * @group Common component props\n */\nexport interface CommonComponentContainerProps\n extends Pick<HTMLAttributes<HTMLElement>, \"className\" | \"role\">, AriaAttributes {\n css?: SystemStyleObject | SystemStyleObject[];\n [key: `data-${string}`]: unknown;\n}\n\n/**\n * A helper hook that computes react properties for the topmost container in a public react component.\n *\n * Example:\n *\n * ```jsx\n * function MyComponent(props) {\n * const { containerProps } = useCommonComponentProps(\"my-component\", props);\n * // automatically applies css classes and testid\n * return <Box {...containerProps}>Content</Box>;\n * }\n * ```\n *\n * @group Common component props\n * @expandType CommonComponentProps\n */\nexport function useCommonComponentProps(\n componentClassName: string,\n props: CommonComponentProps\n): { containerProps: CommonComponentContainerProps } {\n const result = useMemo(() => {\n const containerProps: Record<string, unknown> = {\n className: classNames(componentClassName, props.className)\n };\n if (props.role) {\n containerProps.role = props.role;\n }\n if (props.css) {\n containerProps.css = props.css;\n }\n for (const k in props) {\n if (!Object.hasOwn(props, k)) {\n continue;\n }\n if (COPY_PROP_RE.test(k)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n containerProps[k] = (props as any)[k];\n }\n }\n return { containerProps };\n }, [componentClassName, props]);\n return result;\n}\n"],"names":[],"mappings":";;;AAiDA,MAAM,YAAA,GAAe,eAAA;AA2Bd,SAAS,uBAAA,CACZ,oBACA,KAAA,EACiD;AACjD,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM;AACzB,IAAA,MAAM,cAAA,GAA0C;AAAA,MAC5C,SAAA,EAAW,UAAA,CAAW,kBAAA,EAAoB,KAAA,CAAM,SAAS;AAAA,KAC7D;AACA,IAAA,IAAI,MAAM,IAAA,EAAM;AACZ,MAAA,cAAA,CAAe,OAAO,KAAA,CAAM,IAAA;AAAA,IAChC;AACA,IAAA,IAAI,MAAM,GAAA,EAAK;AACX,MAAA,cAAA,CAAe,MAAM,KAAA,CAAM,GAAA;AAAA,IAC/B;AACA,IAAA,KAAA,MAAW,KAAK,KAAA,EAAO;AACnB,MAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA,EAAG;AAC1B,QAAA;AAAA,MACJ;AACA,MAAA,IAAI,YAAA,CAAa,IAAA,CAAK,CAAC,CAAA,EAAG;AAEtB,QAAA,cAAA,CAAe,CAAC,CAAA,GAAK,KAAA,CAAc,CAAC,CAAA;AAAA,MACxC;AAAA,IACJ;AACA,IAAA,OAAO,EAAE,cAAA,EAAe;AAAA,EAC5B,CAAA,EAAG,CAAC,kBAAA,EAAoB,KAAK,CAAC,CAAA;AAC9B,EAAA,OAAO,MAAA;AACX;;;;"}
1
+ {"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemStyleObject } from \"@chakra-ui/react\";\nimport { HTMLAttributes, AriaAttributes, useMemo, AriaRole } from \"react\";\nimport { classNames } from \"./classNames\";\n\n/**\n * Common properties supported by all public react components.\n *\n * This type allows for the customization of\n * - the css `className`\n * - a Chakra `css` property\n * - \"role\" and `aria-*` properties\n * - arbitrary `data-*` properties\n *\n * Prop types for react components typically inherit from this interface.\n *\n * @group Common component props\n */\nexport interface CommonComponentProps extends AriaAttributes {\n /**\n * Additional class name(s).\n */\n className?: string;\n\n /**\n * Custom style rules using Chakra's style objects.\n */\n css?: SystemStyleObject | SystemStyleObject[];\n\n /**\n * Custom ARIA role.\n */\n role?: AriaRole;\n\n /**\n * Used for testing.\n */\n \"data-testid\"?: string;\n\n /**\n * Arbitrary data attributes.\n *\n * NOTE: The component may use data properties for its own behavior.\n * Make sure not to overwrite required attributes.\n */\n [key: `data-${string}`]: unknown;\n}\n\nconst COPY_PROP_RE = /^(data|aria)-/;\n\n/**\n * @group Common component props\n */\nexport interface CommonComponentContainerProps\n extends Pick<HTMLAttributes<HTMLElement>, \"className\" | \"role\">, AriaAttributes {\n css?: SystemStyleObject | SystemStyleObject[];\n [key: `data-${string}`]: unknown;\n}\n\n/**\n * A helper hook that computes react properties for the topmost container in a public react component.\n *\n * Example:\n *\n * ```jsx\n * function MyComponent(props) {\n * const { containerProps } = useCommonComponentProps(\"my-component\", props);\n * // automatically applies css classes and testid\n * return <Box {...containerProps}>Content</Box>;\n * }\n * ```\n *\n * @group Common component props\n * @expandType CommonComponentProps\n */\nexport function useCommonComponentProps(\n componentClassName: string,\n props: CommonComponentProps\n): { containerProps: CommonComponentContainerProps } {\n const result = useMemo(() => {\n const containerProps: Record<string, unknown> = {\n className: classNames(componentClassName, props.className)\n };\n if (props.role) {\n containerProps.role = props.role;\n }\n if (props.css) {\n containerProps.css = props.css;\n }\n for (const k in props) {\n if (!Object.hasOwn(props, k)) {\n continue;\n }\n if (COPY_PROP_RE.test(k)) {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n containerProps[k] = (props as any)[k];\n }\n }\n return { containerProps };\n }, [componentClassName, props]);\n return result;\n}\n"],"names":[],"mappings":";;;AAkDA,MAAM,YAAA,GAAe,eAAA;AA2Bd,SAAS,uBAAA,CACZ,oBACA,KAAA,EACiD;AACjD,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM;AACzB,IAAA,MAAM,cAAA,GAA0C;AAAA,MAC5C,SAAA,EAAW,UAAA,CAAW,kBAAA,EAAoB,KAAA,CAAM,SAAS;AAAA,KAC7D;AACA,IAAA,IAAI,MAAM,IAAA,EAAM;AACZ,MAAA,cAAA,CAAe,OAAO,KAAA,CAAM,IAAA;AAAA,IAChC;AACA,IAAA,IAAI,MAAM,GAAA,EAAK;AACX,MAAA,cAAA,CAAe,MAAM,KAAA,CAAM,GAAA;AAAA,IAC/B;AACA,IAAA,KAAA,MAAW,KAAK,KAAA,EAAO;AACnB,MAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA,EAAG;AAC1B,QAAA;AAAA,MACJ;AACA,MAAA,IAAI,YAAA,CAAa,IAAA,CAAK,CAAC,CAAA,EAAG;AAEtB,QAAA,cAAA,CAAe,CAAC,CAAA,GAAK,KAAA,CAAc,CAAC,CAAA;AAAA,MACxC;AAAA,IACJ;AACA,IAAA,OAAO,EAAE,cAAA,EAAe;AAAA,EAC5B,CAAA,EAAG,CAAC,kBAAA,EAAoB,KAAK,CAAC,CAAA;AAC9B,EAAA,OAAO,MAAA;AACX;;;;"}
package/useEvent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useInsertionEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler>(undefined);\n\n // Earliest timing as of React 19\n useInsertionEffect(() => {\n handlerRef.current = handler;\n });\n\n // useRef instead of useMemo/useCallback for guaranteed single time construction.\n const stableRef = useRef<typeof handler>(undefined);\n stableRef.current ??= function useEventHandler(...args: Args): Ret {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n };\n return stableRef.current;\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,SACZ,OAAA,EACc;AACd,EAAA,MAAM,UAAA,GAAa,OAAuB,MAAS,CAAA;AAGnD,EAAA,kBAAA,CAAmB,MAAM;AACrB,IAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAAA,EACzB,CAAC,CAAA;AAGD,EAAA,MAAM,SAAA,GAAY,OAAuB,MAAS,CAAA;AAClD,EAAA,SAAA,CAAU,OAAA,KAAY,SAAS,eAAA,CAAA,GAAmB,IAAA,EAAiB;AAE/D,IAAA,MAAM,iBAAiB,UAAA,CAAW,OAAA;AAClC,IAAA,OAAO,cAAA,CAAe,GAAG,IAAI,CAAA;AAAA,EACjC,CAAA;AACA,EAAA,OAAO,SAAA,CAAU,OAAA;AACrB;;;;"}
1
+ {"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useInsertionEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler>(undefined);\n\n // Earliest timing as of React 19\n useInsertionEffect(() => {\n handlerRef.current = handler;\n });\n\n // useRef instead of useMemo/useCallback for guaranteed single time construction.\n const stableRef = useRef<typeof handler>(undefined);\n stableRef.current ??= function useEventHandler(...args: Args): Ret {\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n };\n return stableRef.current;\n}\n"],"names":[],"mappings":";;AAiBO,SAAS,SACZ,OAAA,EACc;AACd,EAAA,MAAM,UAAA,GAAa,OAAuB,MAAS,CAAA;AAGnD,EAAA,kBAAA,CAAmB,MAAM;AACrB,IAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAAA,EACzB,CAAC,CAAA;AAGD,EAAA,MAAM,SAAA,GAAY,OAAuB,MAAS,CAAA;AAClD,EAAA,SAAA,CAAU,OAAA,KAAY,SAAS,eAAA,CAAA,GAAmB,IAAA,EAAiB;AAE/D,IAAA,MAAM,iBAAiB,UAAA,CAAW,OAAA;AAClC,IAAA,OAAO,cAAA,CAAe,GAAG,IAAI,CAAA;AAAA,EACjC,CAAA;AACA,EAAA,OAAO,SAAA,CAAU,OAAA;AACrB;;;;"}