@frontify/fondue 13.7.6 → 13.7.8
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/dist/components/Accordion/Accordion.es.js +2 -2
- package/dist/components/Accordion/Accordion.es.js.map +1 -1
- package/dist/components/Button/Button.es.js +5 -5
- package/dist/components/Button/ButtonClasses.es.js +1 -1
- package/dist/components/FormControl/FormControl.es.js +2 -2
- package/dist/components/FrontifyPattern/FrontifyPattern.es.js +3 -3
- package/dist/components/Toast/Toast.es.js +1 -1
- package/dist/components/Tree/Tree.es.js +9 -9
- package/dist/components/Tree/TreeItem/TreeItemMultiselect.es.js +6 -6
- package/dist/components/Tree/helpers/reducer.es.js +3 -3
- package/dist/components/Tree/helpers/treeHandleKeyDown.es.js +6 -0
- package/dist/components/Tree/helpers/treeHandleKeyDown.es.js.map +1 -1
- package/dist/components/Tree/utils/keyboardCoordinates.es.js +4 -0
- package/dist/components/Tree/utils/keyboardCoordinates.es.js.map +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +122 -122
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/node_modules/.pnpm/framer-motion@12.43.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/gestures/drag/VisualElementDragControls.es.js +7 -7
- package/dist/node_modules/.pnpm/framer-motion@12.43.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/gestures/drag/VisualElementDragControls.es.js.map +1 -1
- package/dist/node_modules/.pnpm/framer-motion@12.43.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/motion/features/layout/MeasureLayout.es.js +6 -6
- package/dist/node_modules/.pnpm/motion-dom@12.43.0/node_modules/motion-dom/dist/es/projection/animation/mix-values.es.js +4 -4
- package/dist/node_modules/.pnpm/motion-dom@12.43.0/node_modules/motion-dom/dist/es/utils/interpolate.es.js +8 -8
- package/dist/node_modules/.pnpm/motion-dom@12.43.0/node_modules/motion-dom/dist/es/value/types/color/hsla.es.js +3 -3
- package/dist/node_modules/.pnpm/motion-dom@12.43.0/node_modules/motion-dom/dist/es/value/types/color/rgba.es.js +3 -3
- package/dist/packages/charts/fondue-charts.umd.cjs +1 -1
- package/dist/packages/charts/style.css +1 -1
- package/dist/packages/components/fondue-components.umd.cjs +1 -1
- package/dist/packages/components/style.css +1 -1
- package/dist/packages/icons/fondue-icons.umd.cjs +1 -1
- package/dist/packages/rte/fondue-rte.umd.cjs +1 -1
- package/dist/packages/rte/style.css +1 -1
- package/dist/packages/tokens/fondue-tokens.umd.cjs +1 -1
- package/dist/style.css +1 -1
- package/dist/tools/codemod/index.js +1 -165
- package/dist/tools/internal/index.js +1 -165
- package/package.json +9 -9
|
@@ -4,7 +4,7 @@ import { useFocusRing as O } from "@react-aria/focus";
|
|
|
4
4
|
import { mergeProps as R } from "@react-aria/utils";
|
|
5
5
|
import { Item as T } from "@react-stately/collections";
|
|
6
6
|
import { useTreeState as _ } from "@react-stately/tree";
|
|
7
|
-
import {
|
|
7
|
+
import { useRef as w, Children as p, useEffect as L, isValidElement as v } from "react";
|
|
8
8
|
import { FOCUS_STYLE_NO_OFFSET as U } from "../../utilities/focusStyle.es.js";
|
|
9
9
|
import { merge as C } from "../../utilities/merge.es.js";
|
|
10
10
|
import { AccordionHeader as M } from "./AccordionHeader.es.js";
|
|
@@ -53,7 +53,7 @@ const V = "fondue-accordion", I = "fondue-accordion-item", j = ({
|
|
|
53
53
|
}, W = (e) => {
|
|
54
54
|
const t = p.map(e, (o, i) => {
|
|
55
55
|
const { header: n, children: c } = o.props;
|
|
56
|
-
return /* @__PURE__ */ l(T, { textValue: n.children, children: c ? () => c : null }, i);
|
|
56
|
+
return /* @__PURE__ */ l(T, { textValue: n.children, children: c ? (() => c) : null }, i);
|
|
57
57
|
}), r = t.map((o) => o.key).filter((o, i) => {
|
|
58
58
|
var n, c;
|
|
59
59
|
return o && !!((c = (n = e[i]) == null ? void 0 : n.props.header) != null && c.active);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.es.js","sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useAccordion, useAccordionItem } from '@react-aria/accordion';\nimport { useFocusRing } from '@react-aria/focus';\nimport { mergeProps } from '@react-aria/utils';\nimport { Item as StatelyItem } from '@react-stately/collections';\nimport { type TreeProps, useTreeState } from '@react-stately/tree';\nimport {\n Children,\n type Key,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n isValidElement,\n useEffect,\n useRef,\n} from 'react';\n\nimport { CollapsibleWrap } from '@components/CollapsibleWrap';\nimport { FOCUS_STYLE_NO_OFFSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nimport { AccordionHeader } from './AccordionHeader';\nimport { type AccordionItemProps, type AccordionProps, type AriaAccordionItemProps } from './types';\n\nconst ACCORDION_ID = 'fondue-accordion';\nconst ACCORDION_ITEM_ID = 'fondue-accordion-item';\n\nconst AriaAccordionItem = ({\n item,\n state,\n header,\n padding = true,\n divider = false,\n headerComponent: HeaderComponent = AccordionHeader,\n 'data-test-id': dataTestId = ACCORDION_ITEM_ID,\n}: AriaAccordionItemProps): ReactElement => {\n const { active, ...headerProps } = header;\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const { buttonProps, regionProps } = useAccordionItem({ item }, state, triggerRef);\n const isOpen = state.expandedKeys.has(item.key);\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n <div\n key={item.key}\n className={merge([\n isFocusVisible ? `${FOCUS_STYLE_NO_OFFSET} tw-relative tw-rounded` : '',\n divider && 'tw-divide-y tw-divide-black-10',\n ])}\n >\n <button\n type=\"button\"\n {...mergeProps(buttonProps, focusProps)}\n data-test-id={dataTestId}\n ref={triggerRef}\n onClick={(event) => {\n if (header.onClick) {\n header.onClick();\n }\n\n if (buttonProps.onClick) {\n buttonProps.onClick(event);\n }\n }}\n onKeyUp={(event) => {\n if (header.onClick && event.key === 'Enter') {\n header.onClick();\n }\n\n if (buttonProps.onKeyUp) {\n buttonProps.onKeyUp(event);\n }\n }}\n className=\"tw-w-full focus-visible:tw-outline-none\"\n >\n <HeaderComponent isOpen={isOpen} {...headerProps} />\n </button>\n <CollapsibleWrap isOpen={isOpen} preventInitialAnimation={active}>\n <div {...regionProps} className={merge([padding && 'tw-px-8 tw-pb-6', 'tw-mt-2'])}>\n {item.props.children?.()}\n </div>\n </CollapsibleWrap>\n </div>\n );\n};\n\n/**\n * @deprecated Please use a custom component instead.\n */\nconst mapToAriaProps = (children: ReactElement<AccordionItemProps>[]): TreeProps<AccordionItemProps> => {\n const ariaChildren = Children.map(children, (child, index) => {\n const { header, children } = child.props;\n\n return (\n <StatelyItem key={index} textValue={header.children}>\n {children ? ((() => children) as unknown as ReactNode) : null}\n </StatelyItem>\n );\n });\n\n const defaultExpandedKeys = (ariaChildren\n .map((item) => item.key)\n .filter((key, index) => key && !!children[index]?.props.header?.active) || []) as Key[];\n\n // @ts-expect-error Type missmatch from library update\n return { children: ariaChildren, defaultExpandedKeys };\n};\n\nconst filterValidChildren = ({ children }: AccordionProps): ReactElement<AccordionItemProps>[] =>\n Children.toArray(children).reduce<ReactElement<AccordionItemProps>[]>((validChildren, child) => {\n if (isValidElement(child) && !child.props.header) {\n console.warn('Use `AccordionItem` as children of `Accordion` and set the `header` prop accordingly.');\n return validChildren;\n }\n\n if (isValidElement(child)) {\n validChildren.push(child as ReactElement<AccordionItemProps>);\n }\n\n return validChildren;\n }, []);\n\n/**\n * @deprecated Please use updated Accordion component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#accordion the migration guide}.\n */\nexport const AccordionItem = ({ children }: AccordionItemProps): ReactElement => <>{children}</>;\nAccordionItem.displayName = 'FondueAccordionItem';\n\nconst lastChildrenActive = (children: ReactNode | undefined): boolean | undefined => {\n const childrenArray = Children.toArray(children) as { key: string; props?: { header?: { active?: boolean } } }[];\n return childrenArray[childrenArray.length - 1]?.props?.header?.active === true;\n};\n\n/**\n * @deprecated Please use updated Accordion component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#accordion the migration guide}.\n */\nexport const Accordion = (props: AccordionProps): ReactElement => {\n const { divider = true, border = true, 'data-test-id': dataTestId = ACCORDION_ID } = props;\n const children = filterValidChildren(props);\n const ariaProps = mapToAriaProps(children);\n\n const ref = useRef<HTMLDivElement | null>(null);\n const state = useTreeState<AccordionItemProps>(ariaProps);\n\n // We need to detect the firstRender and childrenLength to not toggle any panel\n const accordionChildren = useRef({ firstRender: true, childLength: Children.toArray(props.children).length });\n const childrenLength = Children.toArray(props.children).length;\n useEffect(() => {\n /**\n * Checks if the last child in the Array is active\n * Only works when adding Children to end of Accordion\n */\n const childrenIsActive = lastChildrenActive(props.children);\n if (\n !!childrenIsActive &&\n !accordionChildren.current.firstRender &&\n Children.toArray(props.children).length > accordionChildren.current.childLength\n ) {\n // @ts-expect-error Type missmatch from library update\n state.toggleKey(ariaProps.defaultExpandedKeys[ariaProps.defaultExpandedKeys.length - 1]);\n }\n accordionChildren.current = { firstRender: false, childLength: Children.toArray(props.children).length };\n }, [ariaProps.defaultExpandedKeys, childrenLength, props.children, state]);\n\n const {\n // @react-aria prevents default action for onMouseDown as implemented here: https://github.com/adobe/react-spectrum/blob/e14523fedd93ac1a4ede355aed70988af572ae74/packages/%40react-aria/selection/src/useSelectableCollection.ts#L370\n // This makes it impossible to edit or select text in input fields inside the accordion\n // onKeydown automatically navigates away from child elements, including dropdown menus etc.\n // Focus should only be passed if the accordion item itself is focused\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n accordionProps: { onMouseDown, onKeyDown, ...accordionProps },\n // @react-aria enable by default typeahead which result in an event fired up on keypress and select the section\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } = useAccordion({ ...ariaProps, disallowTypeAhead: true }, state, ref);\n\n const accordionKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const key = (event.target as HTMLButtonElement).dataset.key;\n const isFocused = state.selectionManager.focusedKey === key;\n if (key && isFocused) {\n onKeyDown?.(event);\n }\n };\n\n const propsWithModifiedKeyDown = { ...accordionProps, onKeyDown: accordionKeyDown };\n\n return (\n <div\n {...propsWithModifiedKeyDown}\n ref={ref}\n data-test-id={dataTestId}\n className={merge([\n divider && 'tw-divide-y tw-divide-black-10',\n border && 'tw-border-t tw-border-b tw-border-black-10',\n ])}\n >\n {[...state.collection].map((item, index) => {\n const {\n header,\n padding,\n headerComponent,\n divider,\n 'data-test-id': itemDataTestId = ACCORDION_ITEM_ID,\n } = children[index].props;\n return (\n <AriaAccordionItem\n key={item.key}\n item={item}\n state={state}\n divider={divider}\n header={header}\n padding={padding}\n headerComponent={headerComponent}\n data-test-id={itemDataTestId}\n />\n );\n })}\n </div>\n );\n};\nAccordion.displayName = 'FondueAccordion';\n"],"names":["ACCORDION_ID","ACCORDION_ITEM_ID","AriaAccordionItem","item","state","header","padding","divider","HeaderComponent","AccordionHeader","dataTestId","active","headerProps","triggerRef","useRef","buttonProps","regionProps","useAccordionItem","isOpen","isFocusVisible","focusProps","useFocusRing","jsxs","merge","FOCUS_STYLE_NO_OFFSET","jsx","mergeProps","event","CollapsibleWrap","_b","_a","mapToAriaProps","children","ariaChildren","Children","child","index","StatelyItem","defaultExpandedKeys","key","filterValidChildren","validChildren","isValidElement","AccordionItem","lastChildrenActive","childrenArray","_c","Accordion","props","border","ariaProps","ref","useTreeState","accordionChildren","childrenLength","useEffect","onMouseDown","onKeyDown","accordionProps","useAccordion","propsWithModifiedKeyDown","isFocused","headerComponent","itemDataTestId"],"mappings":";;;;;;;;;;;AAyBA,MAAMA,IAAe,oBACfC,IAAoB,yBAEpBC,IAAoB,CAAC;AAAA,EACvB,MAAAC;AAAA,EACA,OAAAC;A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,EAEpB,EAEiE;AAEjE,SACI,gBAAAF;AAAA,IAAC;AAAA,IAAA;AAAA,MACI,GAAGmC;AAAA,MACJ,KAAAT;AAAA,MACA,gBAAczC;AAAA,MACd,WAAWa,EAAM;AAAA,QACbhB,KAAW;AAAA,QACX0C,KAAU;AAAA,MAAA,CACb;AAAA,MAEA,UAAA,CAAC,GAAG7C,EAAM,UAAU,EAAE,IAAI,CAACD,GAAMiC,MAAU;AACxC,cAAM;AAAA,UACF,QAAA/B;AAAA,UACA,SAAAC;AAAA,UACA,iBAAAwD;AAAA,UACA,SAAAvD;AAAAA,UACA,gBAAgBwD,IAAiB9D;AAAA,QAAA,IACjC+B,EAASI,CAAK,EAAE;AACpB,eACI,gBAAAX;AAAA,UAACvB;AAAA,UAAA;AAAA,YAEG,MAAAC;AAAA,YACA,OAAAC;AAAA,YACA,SAASG;AAAAA,YACT,QAAAF;AAAA,YACA,SAAAC;AAAA,YACA,iBAAAwD;AAAA,YACA,gBAAcC;AAAA,UAAA;AAAA,UAPT5D,EAAK;AAAA,QAAA;AAAA,MAUtB,CAAC;AAAA,IAAA;AAAA,EAAA;AAGb;AACA4C,EAAU,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Accordion.es.js","sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useAccordion, useAccordionItem } from '@react-aria/accordion';\nimport { useFocusRing } from '@react-aria/focus';\nimport { mergeProps } from '@react-aria/utils';\nimport { Item as StatelyItem } from '@react-stately/collections';\nimport { type TreeProps, useTreeState } from '@react-stately/tree';\nimport {\n Children,\n type Key,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n isValidElement,\n useEffect,\n useRef,\n} from 'react';\n\nimport { CollapsibleWrap } from '@components/CollapsibleWrap';\nimport { FOCUS_STYLE_NO_OFFSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nimport { AccordionHeader } from './AccordionHeader';\nimport { type AccordionItemProps, type AccordionProps, type AriaAccordionItemProps } from './types';\n\nconst ACCORDION_ID = 'fondue-accordion';\nconst ACCORDION_ITEM_ID = 'fondue-accordion-item';\n\nconst AriaAccordionItem = ({\n item,\n state,\n header,\n padding = true,\n divider = false,\n headerComponent: HeaderComponent = AccordionHeader,\n 'data-test-id': dataTestId = ACCORDION_ITEM_ID,\n}: AriaAccordionItemProps): ReactElement => {\n const { active, ...headerProps } = header;\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const { buttonProps, regionProps } = useAccordionItem({ item }, state, triggerRef);\n const isOpen = state.expandedKeys.has(item.key);\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n <div\n key={item.key}\n className={merge([\n isFocusVisible ? `${FOCUS_STYLE_NO_OFFSET} tw-relative tw-rounded` : '',\n divider && 'tw-divide-y tw-divide-black-10',\n ])}\n >\n <button\n type=\"button\"\n {...mergeProps(buttonProps, focusProps)}\n data-test-id={dataTestId}\n ref={triggerRef}\n onClick={(event) => {\n if (header.onClick) {\n header.onClick();\n }\n\n if (buttonProps.onClick) {\n buttonProps.onClick(event);\n }\n }}\n onKeyUp={(event) => {\n if (header.onClick && event.key === 'Enter') {\n header.onClick();\n }\n\n if (buttonProps.onKeyUp) {\n buttonProps.onKeyUp(event);\n }\n }}\n className=\"tw-w-full focus-visible:tw-outline-none\"\n >\n <HeaderComponent isOpen={isOpen} {...headerProps} />\n </button>\n <CollapsibleWrap isOpen={isOpen} preventInitialAnimation={active}>\n <div {...regionProps} className={merge([padding && 'tw-px-8 tw-pb-6', 'tw-mt-2'])}>\n {item.props.children?.()}\n </div>\n </CollapsibleWrap>\n </div>\n );\n};\n\n/**\n * @deprecated Please use a custom component instead.\n */\nconst mapToAriaProps = (children: ReactElement<AccordionItemProps>[]): TreeProps<AccordionItemProps> => {\n const ariaChildren = Children.map(children, (child, index) => {\n const { header, children } = child.props;\n\n return (\n <StatelyItem key={index} textValue={header.children}>\n {children ? ((() => children) as unknown as ReactNode) : null}\n </StatelyItem>\n );\n });\n\n const defaultExpandedKeys = (ariaChildren\n .map((item) => item.key)\n .filter((key, index) => key && !!children[index]?.props.header?.active) || []) as Key[];\n\n // @ts-expect-error Type missmatch from library update\n return { children: ariaChildren, defaultExpandedKeys };\n};\n\nconst filterValidChildren = ({ children }: AccordionProps): ReactElement<AccordionItemProps>[] =>\n Children.toArray(children).reduce<ReactElement<AccordionItemProps>[]>((validChildren, child) => {\n if (isValidElement(child) && !child.props.header) {\n console.warn('Use `AccordionItem` as children of `Accordion` and set the `header` prop accordingly.');\n return validChildren;\n }\n\n if (isValidElement(child)) {\n validChildren.push(child as ReactElement<AccordionItemProps>);\n }\n\n return validChildren;\n }, []);\n\n/**\n * @deprecated Please use updated Accordion component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#accordion the migration guide}.\n */\nexport const AccordionItem = ({ children }: AccordionItemProps): ReactElement => <>{children}</>;\nAccordionItem.displayName = 'FondueAccordionItem';\n\nconst lastChildrenActive = (children: ReactNode | undefined): boolean | undefined => {\n const childrenArray = Children.toArray(children) as { key: string; props?: { header?: { active?: boolean } } }[];\n return childrenArray[childrenArray.length - 1]?.props?.header?.active === true;\n};\n\n/**\n * @deprecated Please use updated Accordion component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#accordion the migration guide}.\n */\nexport const Accordion = (props: AccordionProps): ReactElement => {\n const { divider = true, border = true, 'data-test-id': dataTestId = ACCORDION_ID } = props;\n const children = filterValidChildren(props);\n const ariaProps = mapToAriaProps(children);\n\n const ref = useRef<HTMLDivElement | null>(null);\n const state = useTreeState<AccordionItemProps>(ariaProps);\n\n // We need to detect the firstRender and childrenLength to not toggle any panel\n const accordionChildren = useRef({ firstRender: true, childLength: Children.toArray(props.children).length });\n const childrenLength = Children.toArray(props.children).length;\n useEffect(() => {\n /**\n * Checks if the last child in the Array is active\n * Only works when adding Children to end of Accordion\n */\n const childrenIsActive = lastChildrenActive(props.children);\n if (\n !!childrenIsActive &&\n !accordionChildren.current.firstRender &&\n Children.toArray(props.children).length > accordionChildren.current.childLength\n ) {\n // @ts-expect-error Type missmatch from library update\n state.toggleKey(ariaProps.defaultExpandedKeys[ariaProps.defaultExpandedKeys.length - 1]);\n }\n accordionChildren.current = { firstRender: false, childLength: Children.toArray(props.children).length };\n }, [ariaProps.defaultExpandedKeys, childrenLength, props.children, state]);\n\n const {\n // @react-aria prevents default action for onMouseDown as implemented here: https://github.com/adobe/react-spectrum/blob/e14523fedd93ac1a4ede355aed70988af572ae74/packages/%40react-aria/selection/src/useSelectableCollection.ts#L370\n // This makes it impossible to edit or select text in input fields inside the accordion\n // onKeydown automatically navigates away from child elements, including dropdown menus etc.\n // Focus should only be passed if the accordion item itself is focused\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n accordionProps: { onMouseDown, onKeyDown, ...accordionProps },\n // @react-aria enable by default typeahead which result in an event fired up on keypress and select the section\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } = useAccordion({ ...ariaProps, disallowTypeAhead: true }, state, ref);\n\n const accordionKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const key = (event.target as HTMLButtonElement).dataset.key;\n const isFocused = state.selectionManager.focusedKey === key;\n if (key && isFocused) {\n onKeyDown?.(event);\n }\n };\n\n const propsWithModifiedKeyDown = { ...accordionProps, onKeyDown: accordionKeyDown };\n\n return (\n <div\n {...propsWithModifiedKeyDown}\n ref={ref}\n data-test-id={dataTestId}\n className={merge([\n divider && 'tw-divide-y tw-divide-black-10',\n border && 'tw-border-t tw-border-b tw-border-black-10',\n ])}\n >\n {[...state.collection].map((item, index) => {\n const {\n header,\n padding,\n headerComponent,\n divider,\n 'data-test-id': itemDataTestId = ACCORDION_ITEM_ID,\n } = children[index].props;\n return (\n <AriaAccordionItem\n key={item.key}\n item={item}\n state={state}\n divider={divider}\n header={header}\n padding={padding}\n headerComponent={headerComponent}\n data-test-id={itemDataTestId}\n />\n );\n })}\n </div>\n );\n};\nAccordion.displayName = 'FondueAccordion';\n"],"names":["ACCORDION_ID","ACCORDION_ITEM_ID","AriaAccordionItem","item","state","header","padding","divider","HeaderComponent","AccordionHeader","dataTestId","active","headerProps","triggerRef","useRef","buttonProps","regionProps","useAccordionItem","isOpen","isFocusVisible","focusProps","useFocusRing","jsxs","merge","FOCUS_STYLE_NO_OFFSET","jsx","mergeProps","event","CollapsibleWrap","_b","_a","mapToAriaProps","children","ariaChildren","Children","child","index","StatelyItem","defaultExpandedKeys","key","filterValidChildren","validChildren","isValidElement","AccordionItem","lastChildrenActive","childrenArray","_c","Accordion","props","border","ariaProps","ref","useTreeState","accordionChildren","childrenLength","useEffect","onMouseDown","onKeyDown","accordionProps","useAccordion","propsWithModifiedKeyDown","isFocused","headerComponent","itemDataTestId"],"mappings":";;;;;;;;;;;AAyBA,MAAMA,IAAe,oBACfC,IAAoB,yBAEpBC,IAAoB,CAAC;AAAA,EACvB,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,SAAAC,IAAU;AAAA,EACV,iBAAiBC,IAAkBC;AAAA,EACnC,gBAAgBC,IAAaT;AACjC,MAA4C;;AACxC,QAAM,EAAE,QAAAU,GAAQ,GAAGC,EAAA,IAAgBP,GAC7BQ,IAAaC,EAAiC,IAAI,GAClD,EAAE,aAAAC,GAAa,aAAAC,MAAgBC,EAAiB,EAAE,MAAAd,EAAA,GAAQC,GAAOS,CAAU,GAC3EK,IAASd,EAAM,aAAa,IAAID,EAAK,GAAG,GACxC,EAAE,gBAAAgB,GAAgB,YAAAC,EAAA,IAAeC,EAAA;AAEvC,SACI,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MAEG,WAAWC,EAAM;AAAA,QACbJ,IAAiB,GAAGK,CAAqB,4BAA4B;AAAA,QACrEjB,KAAW;AAAA,MAAA,CACd;AAAA,MAED,UAAA;AAAA,QAAA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wD;AAAA,YACA,gBAAcC;AAAA,UAAA;AAAA,UAPT5D,EAAK;AAAA,QAAA;AAAA,MAUtB,CAAC;AAAA,IAAA;AAAA,EAAA;AAGb;AACA4C,EAAU,cAAc;"}
|
|
@@ -6,7 +6,7 @@ import { buttonTypeMap as k, buttonIconSizeMap as z } from "./mappings.es.js";
|
|
|
6
6
|
import { FOCUS_VISIBLE_STYLE as T } from "../../utilities/focusStyle.es.js";
|
|
7
7
|
import { merge as r } from "../../utilities/merge.es.js";
|
|
8
8
|
import { useForwardedRef as U } from "../../utilities/useForwardedRef.es.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ButtonCommonClasses as W, ButtonRoundingClasses as Y, ButtonSizeClasses as d, IconSpacingClasses as q, ButtonStyleClasses as v, ButtonDisabledClasses as A } from "./ButtonClasses.es.js";
|
|
10
10
|
import { ButtonType as G, ButtonRounding as H, ButtonSize as J, ButtonStyle as o, ButtonEmphasis as u } from "./ButtonTypes.es.js";
|
|
11
11
|
const K = ({
|
|
12
12
|
type: S = G.Button,
|
|
@@ -38,10 +38,10 @@ const K = ({
|
|
|
38
38
|
type: k[S]
|
|
39
39
|
},
|
|
40
40
|
c
|
|
41
|
-
), { isFocusVisible: E, focusProps: M } = O(), f = ($) => e ?
|
|
41
|
+
), { isFocusVisible: E, focusProps: M } = O(), f = ($) => e ? A : `${v[s][t][$]}`, P = r([
|
|
42
42
|
f("button"),
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
W,
|
|
44
|
+
Y[y],
|
|
45
45
|
m && !a || i ? d[n].iconOnly : d[n].default,
|
|
46
46
|
!C && "tw-w-full"
|
|
47
47
|
]);
|
|
@@ -64,7 +64,7 @@ const K = ({
|
|
|
64
64
|
"span",
|
|
65
65
|
{
|
|
66
66
|
"data-test-id": `${l}-icon`,
|
|
67
|
-
className: r([a && !i ?
|
|
67
|
+
className: r([a && !i ? q[n] : "", f("icon")]),
|
|
68
68
|
children: _(m, { size: z[n] })
|
|
69
69
|
}
|
|
70
70
|
) : null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ButtonRounding as n, ButtonSize as e, ButtonEmphasis as o, ButtonStyle as t } from "./ButtonTypes.es.js";
|
|
2
2
|
const s = "tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-cursor-pointer tw-outline-none tw-font-body tw-font-medium ", g = "tw-not-allowed tw-pointer-events-none tw-border-transparent tw-text-box-disabled-inverse tw-bg-box-disabled ", b = {
|
|
3
3
|
[n.Medium]: "tw-rounded",
|
|
4
4
|
[n.Full]: "tw-rounded-full"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as u, jsx as s } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { isValidElement as v, cloneElement as g } from "react";
|
|
3
3
|
import { InputLabel as V } from "../InputLabel/InputLabel.es.js";
|
|
4
4
|
import { merge as d } from "../../utilities/merge.es.js";
|
|
5
5
|
import { Validation as c } from "../../utilities/validation.es.js";
|
|
@@ -98,7 +98,7 @@ const H = ({
|
|
|
98
98
|
"div",
|
|
99
99
|
{
|
|
100
100
|
className: o === "Vertical" ? "tw-w-full tw-grid tw-grid-cols-1 tw-gap-5" : "",
|
|
101
|
-
children:
|
|
101
|
+
children: v(e) ? g(e, {
|
|
102
102
|
id: (t == null ? void 0 : t.htmlFor) ?? e.props.id,
|
|
103
103
|
disabled: r,
|
|
104
104
|
validation: N[f]
|
|
@@ -2,19 +2,19 @@ import { jsx as o } from "react/jsx-runtime";
|
|
|
2
2
|
import { cloneElement as i } from "react";
|
|
3
3
|
import { patternDesigns as m, PatternDesign as s } from "../../foundation/Pattern/PatternDesigns.es.js";
|
|
4
4
|
import { patternScales as p, PatternScale as f } from "../../foundation/Pattern/PatternScale.es.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PatternTheme as l, patternThemes as c } from "../../foundation/Pattern/PatternTheme.es.js";
|
|
6
6
|
import { merge as d } from "../../utilities/merge.es.js";
|
|
7
7
|
const g = ({
|
|
8
8
|
pattern: t = s.DigitalAssets,
|
|
9
9
|
scale: e = f.SM,
|
|
10
10
|
scaleOrigin: r = ["top", "left"],
|
|
11
|
-
foregroundColor: a =
|
|
11
|
+
foregroundColor: a = l.Black,
|
|
12
12
|
"data-test-id": n = "frontify-pattern"
|
|
13
13
|
}) => /* @__PURE__ */ o(
|
|
14
14
|
"div",
|
|
15
15
|
{
|
|
16
16
|
"data-test-id": n,
|
|
17
|
-
className: d(["tw-w-[260px]",
|
|
17
|
+
className: d(["tw-w-[260px]", c[a]]),
|
|
18
18
|
style: { transformOrigin: `${r.join(" ")}`, transform: `scale(${p[e]})` },
|
|
19
19
|
children: i(m[t])
|
|
20
20
|
}
|
|
@@ -2,7 +2,7 @@ import { jsx as e, jsxs as w } from "react/jsx-runtime";
|
|
|
2
2
|
import { motion as p } from "../../node_modules/.pnpm/motion@12.43.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/motion/dist/es/react.es.js";
|
|
3
3
|
import { MIGHTY_INSET_BORDER as T, INSET_BORDER as S } from "../../utilities/borderStyle.es.js";
|
|
4
4
|
import { merge as o } from "../../utilities/merge.es.js";
|
|
5
|
-
import {
|
|
5
|
+
import { ToastAnimationDirection as r, toastStylesBackgroundColorsMap as y } from "./types.es.js";
|
|
6
6
|
import { AnimatePresence as A } from "../../node_modules/.pnpm/framer-motion@12.43.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/components/AnimatePresence/index.es.js";
|
|
7
7
|
const f = "tw-min-h-[2rem] tw-rounded-lg tw-shadow-mid tw-z-[120000] before:!tw-rounded-lg", g = o([S, "tw-bg-base"]), h = o([T, "tw-bg-box-neutral-mighty"]), a = (t) => t === r.BottomToTop ? "150%" : "-150%", N = (t) => o([f, t === "dark" ? h : g]), u = ({
|
|
8
8
|
isOpen: t,
|
|
@@ -10,13 +10,13 @@ import { TreeContext as Pe } from "./TreeContext.es.js";
|
|
|
10
10
|
import { getTreeNodesWithoutElements as Me, getNodesToRender as je, getReactNodeIdsInFlatArray as Ge, removeReactNodesFromFlatArray as ke } from "./helpers/nodes.es.js";
|
|
11
11
|
import { handleKeyDownEvent as He } from "./helpers/treeHandleKeyDown.es.js";
|
|
12
12
|
import { sortableTreeKeyboardCoordinates as Ke } from "./utils/keyboardCoordinates.es.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { getAnnouncements as Fe } from "./helpers/getMovementAnnouncements.es.js";
|
|
14
|
+
import { useDeepCompareEffect as L } from "./utils/useDeepCompareEffect.es.js";
|
|
15
|
+
import { getProjection as Ue } from "./helpers/projection.es.js";
|
|
15
16
|
import { TreeItemOverlay as We } from "./TreeItem/TreeItemOverlay.es.js";
|
|
16
17
|
import { findIndexById as Be, getNodeChildrenIds as Xe, currentNodesChanged as Ve, getCurrentChildrenForNewNodesIfExpanded as J, updateNodeWithNewChildren as Ye, shouldUpdateTreeState as $ } from "./helpers/reducer.es.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { getProjection as $e } from "./helpers/projection.es.js";
|
|
18
|
+
import { sensorsActivationConstraint as Je } from "./helpers/sensorsActivationConstraint.es.js";
|
|
19
|
+
import { recursivelyRemoveFragmentsAndEnrichChildren as $e } from "./utils/removeFragmentsAndEnrichChildren.es.js";
|
|
20
20
|
import { ROOT_ID as qe } from "./helpers/constants.es.js";
|
|
21
21
|
const ze = {
|
|
22
22
|
droppable: {
|
|
@@ -217,14 +217,14 @@ const Qe = Oe((o, n) => {
|
|
|
217
217
|
), x = Le({
|
|
218
218
|
nodes: t.nodes,
|
|
219
219
|
offset: N ?? 0
|
|
220
|
-
}), de = g(() => Ke(x), [x]), ae =
|
|
220
|
+
}), de = g(() => Ke(x), [x]), ae = Je({ dragHandlerPosition: h, enableDragDelay: q }), le = Ie(
|
|
221
221
|
V(Ne, { activationConstraint: ae }),
|
|
222
222
|
V(Se, { coordinateGetter: de })
|
|
223
|
-
), ie = g(() =>
|
|
223
|
+
), ie = g(() => Fe(t, k, _), [k, t]);
|
|
224
224
|
L(() => {
|
|
225
225
|
I && a({
|
|
226
226
|
type: "REGISTER_ROOT_NODES",
|
|
227
|
-
payload:
|
|
227
|
+
payload: $e(I, { parentId: qe, level: 0 })
|
|
228
228
|
});
|
|
229
229
|
}, [I]), L(() => {
|
|
230
230
|
t.rootNodes.length !== 0 && Z(() => {
|
|
@@ -250,7 +250,7 @@ const Qe = Oe((o, n) => {
|
|
|
250
250
|
offset: N ?? 0
|
|
251
251
|
};
|
|
252
252
|
}, [N, t.nodes]), C(() => {
|
|
253
|
-
const e = f && T ?
|
|
253
|
+
const e = f && T ? Ue({
|
|
254
254
|
nodes: t.nodes,
|
|
255
255
|
activeId: f,
|
|
256
256
|
overId: T,
|
|
@@ -6,9 +6,9 @@ import { Container as Z } from "../../Container/Container.es.js";
|
|
|
6
6
|
import { getMultiselectBackgroundClassName as ee, getMultiselectLiClassName as te, getMultiselectContainerClassName as ae } from "../helpers/multiselectTreeItemstyling.es.js";
|
|
7
7
|
import { ExpandButton as se } from "./ExpandButton.es.js";
|
|
8
8
|
import { useMultiselectTreeItem as oe } from "./useMultiselectTreeItem.es.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { removeFragmentsAndEnrichChildren as ne } from "../utils/removeFragmentsAndEnrichChildren.es.js";
|
|
10
|
+
import { useDeepCompareEffect as re } from "../utils/useDeepCompareEffect.es.js";
|
|
11
|
+
import { getMultiselectCheckBoxState as le } from "../helpers/multiselect.es.js";
|
|
12
12
|
import { INDENTATION_WIDTH as ce } from "../helpers/constants.es.js";
|
|
13
13
|
const ie = $(
|
|
14
14
|
({
|
|
@@ -40,7 +40,7 @@ const ie = $(
|
|
|
40
40
|
k && !s && r && r(e, !0);
|
|
41
41
|
}, [e, r, k, s]);
|
|
42
42
|
const I = M.count(m) > 0, { enrichedChildren: C, childrenIds: B } = w(() => {
|
|
43
|
-
const n =
|
|
43
|
+
const n = ne(m, {
|
|
44
44
|
parentId: e,
|
|
45
45
|
level: i + 1
|
|
46
46
|
});
|
|
@@ -49,7 +49,7 @@ const ie = $(
|
|
|
49
49
|
childrenIds: n.map((K) => K.props.id)
|
|
50
50
|
};
|
|
51
51
|
}, [m, e, i]);
|
|
52
|
-
|
|
52
|
+
re(() => {
|
|
53
53
|
if (M.count(C) === 0 || !o) {
|
|
54
54
|
u == null || u(e);
|
|
55
55
|
return;
|
|
@@ -83,7 +83,7 @@ const ie = $(
|
|
|
83
83
|
label: "",
|
|
84
84
|
onChange: _,
|
|
85
85
|
size: V.Default,
|
|
86
|
-
state: a ? Q.Unchecked :
|
|
86
|
+
state: a ? Q.Unchecked : le(s, S),
|
|
87
87
|
tooltip: [],
|
|
88
88
|
value: e
|
|
89
89
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isEqualWith as a } from "lodash-es";
|
|
2
|
-
import {
|
|
2
|
+
import { getReactNodesInFlatArray as l, getReactNodeIdsInFlatArray as h, removeReactNodesFromFlatArray as I } from "./nodes.es.js";
|
|
3
3
|
const x = (t, r) => r && (t.key === "Meta" || t.ctrlKey), m = (t, r) => t.findIndex((o) => o.props.id === r), F = (t, r) => t.filter((o) => o.props.parentId === r).map((o) => o.props.id), N = (t, r, o) => {
|
|
4
|
-
const s =
|
|
4
|
+
const s = h(t, r), e = s.length > 0 ? I(t, s) : t, n = m(e, r);
|
|
5
5
|
return n === -1 ? t : [...e.slice(0, n + 1), ...o, ...e.slice(n + 1)];
|
|
6
6
|
}, C = (t, r, o) => {
|
|
7
7
|
const s = [];
|
|
8
8
|
for (const e of o)
|
|
9
9
|
if (s.push(e), !!r.has(e.props.id))
|
|
10
|
-
for (const n of
|
|
10
|
+
for (const n of l(t, e.props.id))
|
|
11
11
|
s.push(n);
|
|
12
12
|
return s;
|
|
13
13
|
}, A = (t, r, o) => {
|
|
@@ -20,17 +20,21 @@ const y = (r, h, d, I, x, b) => {
|
|
|
20
20
|
t[n].focus();
|
|
21
21
|
};
|
|
22
22
|
switch (g) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
23
24
|
case o.Enter:
|
|
24
25
|
l();
|
|
25
26
|
break;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
26
28
|
case o.Space:
|
|
27
29
|
i ? u() : l();
|
|
28
30
|
break;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
29
32
|
case o.Right:
|
|
30
33
|
if (!i)
|
|
31
34
|
break;
|
|
32
35
|
p ? m() : u();
|
|
33
36
|
break;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
34
38
|
case o.Left:
|
|
35
39
|
if (i && p)
|
|
36
40
|
k();
|
|
@@ -39,9 +43,11 @@ const y = (r, h, d, I, x, b) => {
|
|
|
39
43
|
t[n].focus();
|
|
40
44
|
}
|
|
41
45
|
break;
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
42
47
|
case o.Up:
|
|
43
48
|
r.preventDefault(), D();
|
|
44
49
|
break;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
45
51
|
case o.Down:
|
|
46
52
|
r.preventDefault(), m();
|
|
47
53
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeHandleKeyDown.es.js","sources":["../../../../src/components/Tree/helpers/treeHandleKeyDown.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { KeyboardCode } from '@dnd-kit/core';\nimport { type KeyboardEvent } from 'react';\n\nimport { type TreeState } from '../types';\n\nimport { ROOT_ID } from './constants';\n\n/**\n * @deprecated Please use updated Tree component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#tree the migration guide}.\n */\nexport const handleKeyDownEvent = (\n event: KeyboardEvent<HTMLUListElement>,\n expandedIds: TreeState['expandedIds'],\n nodes: TreeState['nodes'],\n handleSelect: (id: string) => void,\n handleShrink: (id: string) => void,\n handleExpand: (id: string) => void,\n) => {\n const activeElement = document.activeElement;\n\n if (\n !activeElement?.parentElement ||\n activeElement.getAttribute('role') !== 'treeitem' ||\n !(activeElement instanceof HTMLLIElement)\n ) {\n return;\n }\n\n const items = Array.from(activeElement.parentElement.children).filter(\n (child) => child.nodeName === 'LI',\n ) as HTMLLIElement[];\n\n const currentIndex = items.indexOf(activeElement);\n\n const node = nodes[currentIndex];\n\n const id: string = node.props.id;\n const isExpanded = expandedIds.has(id);\n const parentId: string | undefined = node.props.parentId;\n const hasChildren = activeElement.getAttribute('data-has-children') === 'true';\n\n const { code } = event;\n\n const toggleSelect = () => {\n event.preventDefault();\n\n handleSelect(id);\n };\n\n const expandItem = () => {\n event.preventDefault();\n\n handleExpand(id);\n };\n\n const shrinkItem = () => {\n event.preventDefault();\n\n handleShrink(id);\n };\n\n const focusPrevious = () => {\n const previousIndex = (currentIndex + items.length - 1) % items.length;\n items[previousIndex].focus();\n };\n\n const focusNext = () => {\n const nextIndex = (currentIndex + 1) % items.length;\n items[nextIndex].focus();\n };\n\n switch (code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Enter:\n toggleSelect();\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Space:\n if (hasChildren) {\n expandItem();\n } else {\n toggleSelect();\n }\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Right:\n if (!hasChildren) {\n break;\n }\n\n if (isExpanded) {\n focusNext();\n } else {\n expandItem();\n }\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Left:\n if (hasChildren && isExpanded) {\n shrinkItem();\n } else if (parentId && parentId !== ROOT_ID) {\n const parentIndex = nodes.findIndex((node) => node.props.id === parentId);\n\n items[parentIndex].focus();\n }\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Up:\n event.preventDefault();\n focusPrevious();\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Down:\n event.preventDefault();\n focusNext();\n\n break;\n\n default:\n break;\n }\n};\n"],"names":["handleKeyDownEvent","event","expandedIds","nodes","handleSelect","handleShrink","handleExpand","activeElement","items","child","currentIndex","node","id","isExpanded","parentId","hasChildren","code","toggleSelect","expandItem","shrinkItem","focusPrevious","previousIndex","focusNext","nextIndex","KeyboardCode","ROOT_ID","parentIndex"],"mappings":";;AAYO,MAAMA,IAAqB,CAC9BC,GACAC,GACAC,GACAC,GACAC,GACAC,MACC;AACD,QAAMC,IAAgB,SAAS;AAE/B,MACI,EAACA,KAAA,QAAAA,EAAe,kBAChBA,EAAc,aAAa,MAAM,MAAM,cACvC,EAAEA,aAAyB;AAE3B;AAGJ,QAAMC,IAAQ,MAAM,KAAKD,EAAc,cAAc,QAAQ,EAAE;AAAA,IAC3D,CAACE,MAAUA,EAAM,aAAa;AAAA,EAAA,GAG5BC,IAAeF,EAAM,QAAQD,CAAa,GAE1CI,IAAOR,EAAMO,CAAY,GAEzBE,IAAaD,EAAK,MAAM,IACxBE,IAAaX,EAAY,IAAIU,CAAE,GAC/BE,IAA+BH,EAAK,MAAM,UAC1CI,IAAcR,EAAc,aAAa,mBAAmB,MAAM,QAElE,EAAE,MAAAS,MAASf,GAEXgB,IAAe,MAAM;AACvB,IAAAhB,EAAM,eAAA,GAENG,EAAaQ,CAAE;AAAA,EACnB,GAEMM,IAAa,MAAM;AACrB,IAAAjB,EAAM,eAAA,GAENK,EAAaM,CAAE;AAAA,EACnB,GAEMO,IAAa,MAAM;AACrB,IAAAlB,EAAM,eAAA,GAENI,EAAaO,CAAE;AAAA,EACnB,GAEMQ,IAAgB,MAAM;AACxB,UAAMC,KAAiBX,IAAeF,EAAM,SAAS,KAAKA,EAAM;AAChE,IAAAA,EAAMa,CAAa,EAAE,MAAA;AAAA,EACzB,GAEMC,IAAY,MAAM;AACpB,UAAMC,KAAab,IAAe,KAAKF,EAAM;AAC7C,IAAAA,EAAMe,CAAS,EAAE,MAAA;AAAA,EACrB;AAEA,UAAQP,GAAA;AAAA,IAEJ,KAAKQ,EAAa;AACd,MAAAP,EAAA;AAEA;AAAA,IAGJ,KAAKO,EAAa;AACd,MAAIT,IACAG,EAAA,IAEAD,EAAA;AAGJ;AAAA,IAGJ,KAAKO,EAAa;AACd,UAAI,CAACT;AACD;AAGJ,MAAIF,IACAS,EAAA,IAEAJ,EAAA;AAGJ;AAAA,IAGJ,KAAKM,EAAa;AACd,UAAIT,KAAeF;AACf,QAAAM,EAAA;AAAA,eACOL,KAAYA,MAAaW,GAAS;AACzC,cAAMC,IAAcvB,EAAM,UAAU,CAACQ,MAASA,EAAK,MAAM,OAAOG,CAAQ;AAExE,QAAAN,EAAMkB,CAAW,EAAE,MAAA;AAAA,MACvB;AACA;AAAA,IAGJ,KAAKF,EAAa;AACd,MAAAvB,EAAM,eAAA,GACNmB,EAAA;AAEA;AAAA,IAGJ,KAAKI,EAAa;AACd,MAAAvB,EAAM,eAAA,GACNqB,EAAA;AAEA;AAAA,EAGA;AAEZ;"}
|
|
1
|
+
{"version":3,"file":"treeHandleKeyDown.es.js","sources":["../../../../src/components/Tree/helpers/treeHandleKeyDown.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { KeyboardCode } from '@dnd-kit/core';\nimport { type KeyboardEvent } from 'react';\n\nimport { type TreeState } from '../types';\n\nimport { ROOT_ID } from './constants';\n\n/**\n * @deprecated Please use updated Tree component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#tree the migration guide}.\n */\nexport const handleKeyDownEvent = (\n event: KeyboardEvent<HTMLUListElement>,\n expandedIds: TreeState['expandedIds'],\n nodes: TreeState['nodes'],\n handleSelect: (id: string) => void,\n handleShrink: (id: string) => void,\n handleExpand: (id: string) => void,\n) => {\n const activeElement = document.activeElement;\n\n if (\n !activeElement?.parentElement ||\n activeElement.getAttribute('role') !== 'treeitem' ||\n !(activeElement instanceof HTMLLIElement)\n ) {\n return;\n }\n\n const items = Array.from(activeElement.parentElement.children).filter(\n (child) => child.nodeName === 'LI',\n ) as HTMLLIElement[];\n\n const currentIndex = items.indexOf(activeElement);\n\n const node = nodes[currentIndex];\n\n const id: string = node.props.id;\n const isExpanded = expandedIds.has(id);\n const parentId: string | undefined = node.props.parentId;\n const hasChildren = activeElement.getAttribute('data-has-children') === 'true';\n\n const { code } = event;\n\n const toggleSelect = () => {\n event.preventDefault();\n\n handleSelect(id);\n };\n\n const expandItem = () => {\n event.preventDefault();\n\n handleExpand(id);\n };\n\n const shrinkItem = () => {\n event.preventDefault();\n\n handleShrink(id);\n };\n\n const focusPrevious = () => {\n const previousIndex = (currentIndex + items.length - 1) % items.length;\n items[previousIndex].focus();\n };\n\n const focusNext = () => {\n const nextIndex = (currentIndex + 1) % items.length;\n items[nextIndex].focus();\n };\n\n switch (code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Enter:\n toggleSelect();\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Space:\n if (hasChildren) {\n expandItem();\n } else {\n toggleSelect();\n }\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Right:\n if (!hasChildren) {\n break;\n }\n\n if (isExpanded) {\n focusNext();\n } else {\n expandItem();\n }\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Left:\n if (hasChildren && isExpanded) {\n shrinkItem();\n } else if (parentId && parentId !== ROOT_ID) {\n const parentIndex = nodes.findIndex((node) => node.props.id === parentId);\n\n items[parentIndex].focus();\n }\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Up:\n event.preventDefault();\n focusPrevious();\n\n break;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Down:\n event.preventDefault();\n focusNext();\n\n break;\n\n default:\n break;\n }\n};\n"],"names":["handleKeyDownEvent","event","expandedIds","nodes","handleSelect","handleShrink","handleExpand","activeElement","items","child","currentIndex","node","id","isExpanded","parentId","hasChildren","code","toggleSelect","expandItem","shrinkItem","focusPrevious","previousIndex","focusNext","nextIndex","KeyboardCode","ROOT_ID","parentIndex"],"mappings":";;AAYO,MAAMA,IAAqB,CAC9BC,GACAC,GACAC,GACAC,GACAC,GACAC,MACC;AACD,QAAMC,IAAgB,SAAS;AAE/B,MACI,EAACA,KAAA,QAAAA,EAAe,kBAChBA,EAAc,aAAa,MAAM,MAAM,cACvC,EAAEA,aAAyB;AAE3B;AAGJ,QAAMC,IAAQ,MAAM,KAAKD,EAAc,cAAc,QAAQ,EAAE;AAAA,IAC3D,CAACE,MAAUA,EAAM,aAAa;AAAA,EAAA,GAG5BC,IAAeF,EAAM,QAAQD,CAAa,GAE1CI,IAAOR,EAAMO,CAAY,GAEzBE,IAAaD,EAAK,MAAM,IACxBE,IAAaX,EAAY,IAAIU,CAAE,GAC/BE,IAA+BH,EAAK,MAAM,UAC1CI,IAAcR,EAAc,aAAa,mBAAmB,MAAM,QAElE,EAAE,MAAAS,MAASf,GAEXgB,IAAe,MAAM;AACvB,IAAAhB,EAAM,eAAA,GAENG,EAAaQ,CAAE;AAAA,EACnB,GAEMM,IAAa,MAAM;AACrB,IAAAjB,EAAM,eAAA,GAENK,EAAaM,CAAE;AAAA,EACnB,GAEMO,IAAa,MAAM;AACrB,IAAAlB,EAAM,eAAA,GAENI,EAAaO,CAAE;AAAA,EACnB,GAEMQ,IAAgB,MAAM;AACxB,UAAMC,KAAiBX,IAAeF,EAAM,SAAS,KAAKA,EAAM;AAChE,IAAAA,EAAMa,CAAa,EAAE,MAAA;AAAA,EACzB,GAEMC,IAAY,MAAM;AACpB,UAAMC,KAAab,IAAe,KAAKF,EAAM;AAC7C,IAAAA,EAAMe,CAAS,EAAE,MAAA;AAAA,EACrB;AAEA,UAAQP,GAAA;AAAA;AAAA,IAEJ,KAAKQ,EAAa;AACd,MAAAP,EAAA;AAEA;AAAA;AAAA,IAGJ,KAAKO,EAAa;AACd,MAAIT,IACAG,EAAA,IAEAD,EAAA;AAGJ;AAAA;AAAA,IAGJ,KAAKO,EAAa;AACd,UAAI,CAACT;AACD;AAGJ,MAAIF,IACAS,EAAA,IAEAJ,EAAA;AAGJ;AAAA;AAAA,IAGJ,KAAKM,EAAa;AACd,UAAIT,KAAeF;AACf,QAAAM,EAAA;AAAA,eACOL,KAAYA,MAAaW,GAAS;AACzC,cAAMC,IAAcvB,EAAM,UAAU,CAACQ,MAASA,EAAK,MAAM,OAAOG,CAAQ;AAExE,QAAAN,EAAMkB,CAAW,EAAE,MAAA;AAAA,MACvB;AACA;AAAA;AAAA,IAGJ,KAAKF,EAAa;AACd,MAAAvB,EAAM,eAAA,GACNmB,EAAA;AAEA;AAAA;AAAA,IAGJ,KAAKI,EAAa;AACd,MAAAvB,EAAM,eAAA,GACNqB,EAAA;AAEA;AAAA,EAGA;AAEZ;"}
|
|
@@ -17,6 +17,7 @@ const B = [n.Down, n.Right, n.Up, n.Left], K = [n.Left, n.Right], F = (N) => (c,
|
|
|
17
17
|
dragOffset: k
|
|
18
18
|
});
|
|
19
19
|
switch (c.code) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
20
21
|
case n.Left:
|
|
21
22
|
if (e > s)
|
|
22
23
|
return {
|
|
@@ -24,6 +25,7 @@ const B = [n.Down, n.Right, n.Up, n.Left], K = [n.Left, n.Right], F = (N) => (c,
|
|
|
24
25
|
x: a.x - g
|
|
25
26
|
};
|
|
26
27
|
break;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
27
29
|
case n.Right:
|
|
28
30
|
if (e < i)
|
|
29
31
|
return {
|
|
@@ -41,9 +43,11 @@ const B = [n.Down, n.Right, n.Up, n.Left], K = [n.Left, n.Right], F = (N) => (c,
|
|
|
41
43
|
const s = h.get(e);
|
|
42
44
|
if (s)
|
|
43
45
|
switch (c.code) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
44
47
|
case n.Down:
|
|
45
48
|
r.top < s.top && l.push(i);
|
|
46
49
|
break;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
47
51
|
case n.Up:
|
|
48
52
|
r.top > s.top && l.push(i);
|
|
49
53
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardCoordinates.es.js","sources":["../../../../src/components/Tree/utils/keyboardCoordinates.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport {\n type DroppableContainer,\n KeyboardCode,\n type KeyboardCoordinateGetter,\n closestCorners,\n getFirstCollision,\n} from '@dnd-kit/core';\n\nimport { INDENTATION_WIDTH, getProjection } from '../helpers';\nimport { type SensorContext } from '../types';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst horizontal: string[] = [KeyboardCode.Left, KeyboardCode.Right];\n\n/**\n * @deprecated Please use updated Tree component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#tree the migration guide}.\n */\nexport const sortableTreeKeyboardCoordinates: (context: SensorContext) => KeyboardCoordinateGetter =\n (context) =>\n (event, { currentCoordinates, context: { active, over, collisionRect, droppableRects, droppableContainers } }) => {\n if (directions.includes(event.code)) {\n if (!active || !collisionRect) {\n return;\n }\n\n event.preventDefault();\n\n const {\n current: { nodes, offset },\n } = context;\n\n if (horizontal.includes(event.code) && over?.id) {\n const { depth, maxDepth, minDepth } = getProjection({\n nodes,\n activeId: active.id as string,\n overId: over.id as string,\n dragOffset: offset,\n });\n\n switch (event.code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Left:\n if (depth > minDepth) {\n return {\n ...currentCoordinates,\n x: currentCoordinates.x - INDENTATION_WIDTH,\n };\n }\n break;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Right:\n if (depth < maxDepth) {\n return {\n ...currentCoordinates,\n x: currentCoordinates.x + INDENTATION_WIDTH,\n };\n }\n break;\n }\n\n return undefined;\n }\n\n const containers: DroppableContainer[] = [];\n\n for (const [containerId, container] of droppableContainers) {\n if (container?.disabled || containerId === over?.id) {\n continue;\n }\n\n const rect = droppableRects.get(containerId);\n\n if (!rect) {\n continue;\n }\n\n switch (event.code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Down:\n if (collisionRect.top < rect.top) {\n containers.push(container);\n }\n break;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Up:\n if (collisionRect.top > rect.top) {\n containers.push(container);\n }\n break;\n }\n }\n\n const collisions = closestCorners({\n active,\n collisionRect,\n pointerCoordinates: null,\n droppableRects,\n droppableContainers: containers,\n });\n\n let closestId = getFirstCollision(collisions, 'id');\n\n if (closestId === over?.id && collisions.length > 1) {\n closestId = collisions[1].id;\n }\n\n if (closestId && over?.id) {\n const activeRect = droppableRects.get(active.id);\n const newRect = droppableRects.get(closestId);\n const newDroppable = droppableContainers.get(closestId);\n\n if (activeRect && newRect && newDroppable) {\n const newIndex = nodes.findIndex(({ props }) => props.id === closestId);\n const newNode = nodes[newIndex];\n const activeIndex = nodes.findIndex(({ props }) => props.id === active.id);\n const activeNode = nodes[activeIndex];\n\n const dragOffset = (newNode.props.level - activeNode.props.level) * INDENTATION_WIDTH;\n\n if (newNode && activeNode) {\n const { depth } = getProjection({\n nodes,\n activeId: active.id as string,\n overId: closestId as string,\n dragOffset,\n });\n\n const isBelow = newIndex > activeIndex;\n const modifier = isBelow ? 1 : -1;\n const offset = (collisionRect.height - activeRect.height) / 2;\n\n const newCoordinates = {\n x: newRect.left + depth * INDENTATION_WIDTH,\n y: newRect.top + modifier * offset,\n };\n\n return newCoordinates;\n }\n }\n }\n }\n\n return undefined;\n };\n"],"names":["directions","KeyboardCode","horizontal","sortableTreeKeyboardCoordinates","context","event","currentCoordinates","active","over","collisionRect","droppableRects","droppableContainers","nodes","offset","depth","maxDepth","minDepth","getProjection","INDENTATION_WIDTH","containers","containerId","container","rect","collisions","closestCorners","closestId","getFirstCollision","activeRect","newRect","newDroppable","newIndex","props","newNode","activeIndex","activeNode","dragOffset","modifier"],"mappings":";;;AAaA,MAAMA,IAAuB,CAACC,EAAa,MAAMA,EAAa,OAAOA,EAAa,IAAIA,EAAa,IAAI,GAEjGC,IAAuB,CAACD,EAAa,MAAMA,EAAa,KAAK,GAKtDE,IACT,CAACC,MACD,CAACC,GAAO,EAAE,oBAAAC,GAAoB,SAAS,EAAE,QAAAC,GAAQ,MAAAC,GAAM,eAAAC,GAAe,gBAAAC,GAAgB,qBAAAC,EAAA,QAA4B;AAC9G,MAAIX,EAAW,SAASK,EAAM,IAAI,GAAG;AACjC,QAAI,CAACE,KAAU,CAACE;AACZ;AAGJ,IAAAJ,EAAM,eAAA;AAEN,UAAM;AAAA,MACF,SAAS,EAAE,OAAAO,GAAO,QAAAC,EAAA;AAAA,IAAO,IACzBT;AAEJ,QAAIF,EAAW,SAASG,EAAM,IAAI,MAAKG,KAAA,QAAAA,EAAM,KAAI;AAC7C,YAAM,EAAE,OAAAM,GAAO,UAAAC,GAAU,UAAAC,EAAA,IAAaC,EAAc;AAAA,QAChD,OAAAL;AAAA,QACA,UAAUL,EAAO;AAAA,QACjB,QAAQC,EAAK;AAAA,QACb,YAAYK;AAAA,MAAA,CACf;AAED,cAAQR,EAAM,MAAA;AAAA,QAEV,KAAKJ,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AAAmB,QAAYA,EAAM,OAAON,CAAS,GAChEO,IAAUpB,EAAMkB,CAAQ,GACxBG,IAAcrB,EAAM,UAAU,CAAC,EAAE,OAAAmB,QAAYA,EAAM,OAAOxB,EAAO,EAAE,GACnE2B,IAAatB,EAAMqB,CAAW,GAE9BE,KAAcH,EAAQ,MAAM,QAAQE,EAAW,MAAM,SAAShB;AAEpE,YAAIc,KAAWE,GAAY;AACvB,gBAAM,EAAE,OAAApB,EAAA,IAAUG,EAAc;AAAA,YAC5B,OAAAL;AAAA,YACA,UAAUL,EAAO;AAAA,YACjB,QAAQkB;AAAA,YACR,YAAAU;AAAA,UAAA,CACH,GAGKC,IADUN,IAAWG,IACA,IAAI,IACzBpB,KAAUJ,EAAc,SAASkB,EAAW,UAAU;AAO5D,iBALuB;AAAA,YACnB,GAAGC,EAAQ,OAAOd,IAAQI;AAAA,YAC1B,GAAGU,EAAQ,MAAMQ,IAAWvB;AAAAA,UAAA;AAAA,QAIpC;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAGJ;"}
|
|
1
|
+
{"version":3,"file":"keyboardCoordinates.es.js","sources":["../../../../src/components/Tree/utils/keyboardCoordinates.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport {\n type DroppableContainer,\n KeyboardCode,\n type KeyboardCoordinateGetter,\n closestCorners,\n getFirstCollision,\n} from '@dnd-kit/core';\n\nimport { INDENTATION_WIDTH, getProjection } from '../helpers';\nimport { type SensorContext } from '../types';\n\nconst directions: string[] = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];\n\nconst horizontal: string[] = [KeyboardCode.Left, KeyboardCode.Right];\n\n/**\n * @deprecated Please use updated Tree component from `@frontify/fondue/components` instead. Also check {@link https://github.com/Frontify/fondue/blob/main/packages/components/MIGRATING.md#tree the migration guide}.\n */\nexport const sortableTreeKeyboardCoordinates: (context: SensorContext) => KeyboardCoordinateGetter =\n (context) =>\n (event, { currentCoordinates, context: { active, over, collisionRect, droppableRects, droppableContainers } }) => {\n if (directions.includes(event.code)) {\n if (!active || !collisionRect) {\n return;\n }\n\n event.preventDefault();\n\n const {\n current: { nodes, offset },\n } = context;\n\n if (horizontal.includes(event.code) && over?.id) {\n const { depth, maxDepth, minDepth } = getProjection({\n nodes,\n activeId: active.id as string,\n overId: over.id as string,\n dragOffset: offset,\n });\n\n switch (event.code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Left:\n if (depth > minDepth) {\n return {\n ...currentCoordinates,\n x: currentCoordinates.x - INDENTATION_WIDTH,\n };\n }\n break;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Right:\n if (depth < maxDepth) {\n return {\n ...currentCoordinates,\n x: currentCoordinates.x + INDENTATION_WIDTH,\n };\n }\n break;\n }\n\n return undefined;\n }\n\n const containers: DroppableContainer[] = [];\n\n for (const [containerId, container] of droppableContainers) {\n if (container?.disabled || containerId === over?.id) {\n continue;\n }\n\n const rect = droppableRects.get(containerId);\n\n if (!rect) {\n continue;\n }\n\n switch (event.code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Down:\n if (collisionRect.top < rect.top) {\n containers.push(container);\n }\n break;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n case KeyboardCode.Up:\n if (collisionRect.top > rect.top) {\n containers.push(container);\n }\n break;\n }\n }\n\n const collisions = closestCorners({\n active,\n collisionRect,\n pointerCoordinates: null,\n droppableRects,\n droppableContainers: containers,\n });\n\n let closestId = getFirstCollision(collisions, 'id');\n\n if (closestId === over?.id && collisions.length > 1) {\n closestId = collisions[1].id;\n }\n\n if (closestId && over?.id) {\n const activeRect = droppableRects.get(active.id);\n const newRect = droppableRects.get(closestId);\n const newDroppable = droppableContainers.get(closestId);\n\n if (activeRect && newRect && newDroppable) {\n const newIndex = nodes.findIndex(({ props }) => props.id === closestId);\n const newNode = nodes[newIndex];\n const activeIndex = nodes.findIndex(({ props }) => props.id === active.id);\n const activeNode = nodes[activeIndex];\n\n const dragOffset = (newNode.props.level - activeNode.props.level) * INDENTATION_WIDTH;\n\n if (newNode && activeNode) {\n const { depth } = getProjection({\n nodes,\n activeId: active.id as string,\n overId: closestId as string,\n dragOffset,\n });\n\n const isBelow = newIndex > activeIndex;\n const modifier = isBelow ? 1 : -1;\n const offset = (collisionRect.height - activeRect.height) / 2;\n\n const newCoordinates = {\n x: newRect.left + depth * INDENTATION_WIDTH,\n y: newRect.top + modifier * offset,\n };\n\n return newCoordinates;\n }\n }\n }\n }\n\n return undefined;\n };\n"],"names":["directions","KeyboardCode","horizontal","sortableTreeKeyboardCoordinates","context","event","currentCoordinates","active","over","collisionRect","droppableRects","droppableContainers","nodes","offset","depth","maxDepth","minDepth","getProjection","INDENTATION_WIDTH","containers","containerId","container","rect","collisions","closestCorners","closestId","getFirstCollision","activeRect","newRect","newDroppable","newIndex","props","newNode","activeIndex","activeNode","dragOffset","modifier"],"mappings":";;;AAaA,MAAMA,IAAuB,CAACC,EAAa,MAAMA,EAAa,OAAOA,EAAa,IAAIA,EAAa,IAAI,GAEjGC,IAAuB,CAACD,EAAa,MAAMA,EAAa,KAAK,GAKtDE,IACT,CAACC,MACD,CAACC,GAAO,EAAE,oBAAAC,GAAoB,SAAS,EAAE,QAAAC,GAAQ,MAAAC,GAAM,eAAAC,GAAe,gBAAAC,GAAgB,qBAAAC,EAAA,QAA4B;AAC9G,MAAIX,EAAW,SAASK,EAAM,IAAI,GAAG;AACjC,QAAI,CAACE,KAAU,CAACE;AACZ;AAGJ,IAAAJ,EAAM,eAAA;AAEN,UAAM;AAAA,MACF,SAAS,EAAE,OAAAO,GAAO,QAAAC,EAAA;AAAA,IAAO,IACzBT;AAEJ,QAAIF,EAAW,SAASG,EAAM,IAAI,MAAKG,KAAA,QAAAA,EAAM,KAAI;AAC7C,YAAM,EAAE,OAAAM,GAAO,UAAAC,GAAU,UAAAC,EAAA,IA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