{"ast":null,"code":"import { isFocusVisible, useHover, usePress } from \"@react-aria/interactions\";\nimport { getItemCount } from \"@react-stately/collections\";\nimport { useSelectableList, useSelectableItem } from \"@react-aria/selection\";\nimport _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nimport { useOverlayTrigger } from \"@react-aria/overlays\";\nimport { useId, filterDOMProps, mergeProps, useSlotId } from \"@react-aria/utils\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nexport function useMenuTrigger(props, state, ref) {\n  var _props$type = props.type,\n      type = _props$type === void 0 ? 'menu' : _props$type;\n  var menuTriggerId = useId();\n\n  var _useOverlayTrigger = useOverlayTrigger({\n    type: type\n  }, state, ref),\n      triggerProps = _useOverlayTrigger.triggerProps,\n      overlayProps = _useOverlayTrigger.overlayProps;\n\n  var onKeyDown = function onKeyDown(e) {\n    if (typeof e.isDefaultPrevented === 'function' && e.isDefaultPrevented() || e.defaultPrevented) {\n      return;\n    }\n\n    if (ref && ref.current) {\n      switch (e.key) {\n        case 'ArrowDown':\n          e.preventDefault();\n          state.toggle('first');\n          break;\n\n        case 'ArrowUp':\n          e.preventDefault();\n          state.toggle('last');\n          break;\n      }\n    }\n  };\n\n  return {\n    menuTriggerProps: _babelRuntimeHelpersEsmExtends({}, triggerProps, {\n      id: menuTriggerId,\n      onPressStart: function onPressStart(e) {\n        if (e.pointerType !== 'touch') {\n          state.toggle(e.pointerType === 'keyboard' || e.pointerType === 'virtual' ? 'first' : null);\n        }\n      },\n      onPress: function onPress(e) {\n        if (e.pointerType === 'touch') {\n          state.toggle();\n        }\n      },\n      onKeyDown: onKeyDown\n    }),\n    menuProps: _babelRuntimeHelpersEsmExtends({}, overlayProps, {\n      'aria-labelledby': menuTriggerId\n    })\n  };\n}\nexport function useMenu(props, state, ref) {\n  var _props$shouldFocusWra = props.shouldFocusWrap,\n      shouldFocusWrap = _props$shouldFocusWra === void 0 ? true : _props$shouldFocusWra,\n      otherProps = _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose(props, [\"shouldFocusWrap\"]);\n\n  if (!props['aria-label'] && !props['aria-labelledby']) {\n    console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n  }\n\n  var domProps = filterDOMProps(props, {\n    labelable: true\n  });\n\n  var _useSelectableList = useSelectableList(_babelRuntimeHelpersEsmExtends({}, otherProps, {\n    ref: ref,\n    selectionManager: state.selectionManager,\n    collection: state.collection,\n    disabledKeys: state.disabledKeys,\n    shouldFocusWrap: shouldFocusWrap\n  })),\n      listProps = _useSelectableList.listProps;\n\n  return {\n    menuProps: mergeProps(domProps, _babelRuntimeHelpersEsmExtends({\n      role: 'menu'\n    }, listProps))\n  };\n}\nexport function useMenuItem(props, state, ref) {\n  var isSelected = props.isSelected,\n      isDisabled = props.isDisabled,\n      key = props.key,\n      onClose = props.onClose,\n      _props$closeOnSelect = props.closeOnSelect,\n      closeOnSelect = _props$closeOnSelect === void 0 ? true : _props$closeOnSelect,\n      isVirtualized = props.isVirtualized,\n      onAction = props.onAction;\n  var role = 'menuitem';\n\n  if (state.selectionManager.selectionMode === 'single') {\n    role = 'menuitemradio';\n  } else if (state.selectionManager.selectionMode === 'multiple') {\n    role = 'menuitemcheckbox';\n  }\n\n  var labelId = useSlotId();\n  var descriptionId = useSlotId();\n  var keyboardId = useSlotId();\n  var ariaProps = {\n    'aria-disabled': isDisabled,\n    role: role,\n    'aria-label': props['aria-label'],\n    'aria-labelledby': labelId,\n    'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n  };\n\n  if (state.selectionManager.selectionMode !== 'none') {\n    ariaProps['aria-checked'] = isSelected;\n  }\n\n  if (isVirtualized) {\n    ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n    ariaProps['aria-setsize'] = getItemCount(state.collection);\n  }\n\n  var onKeyDown = function onKeyDown(e) {\n    if (e.repeat) {\n      return;\n    }\n\n    switch (e.key) {\n      case ' ':\n        if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect && onClose) {\n          onClose();\n        }\n\n        break;\n\n      case 'Enter':\n        if (!isDisabled && closeOnSelect && onClose) {\n          onClose();\n        }\n\n        break;\n    }\n  };\n\n  var onPressStart = function onPressStart(e) {\n    if (e.pointerType === 'keyboard' && onAction) {\n      onAction(key);\n    }\n  };\n\n  var onPressUp = function onPressUp(e) {\n    if (e.pointerType !== 'keyboard') {\n      if (onAction) {\n        onAction(key);\n      }\n\n      if (closeOnSelect && onClose) {\n        onClose();\n      }\n    }\n  };\n\n  var _useSelectableItem = useSelectableItem({\n    selectionManager: state.selectionManager,\n    key: key,\n    ref: ref,\n    shouldSelectOnPressUp: true\n  }),\n      itemProps = _useSelectableItem.itemProps;\n\n  var _usePress = usePress(mergeProps({\n    onPressStart: onPressStart,\n    onPressUp: onPressUp,\n    onKeyDown: onKeyDown,\n    isDisabled: isDisabled\n  }, itemProps)),\n      pressProps = _usePress.pressProps;\n\n  var _useHover = useHover({\n    isDisabled: isDisabled,\n    onHoverStart: function onHoverStart() {\n      if (!isFocusVisible()) {\n        state.selectionManager.setFocused(true);\n        state.selectionManager.setFocusedKey(key);\n      }\n    }\n  }),\n      hoverProps = _useHover.hoverProps;\n\n  return {\n    menuItemProps: _babelRuntimeHelpersEsmExtends({}, ariaProps, mergeProps(pressProps, hoverProps)),\n    labelProps: {\n      id: labelId\n    },\n    descriptionProps: {\n      id: descriptionId\n    },\n    keyboardShortcutProps: {\n      id: keyboardId\n    }\n  };\n}\nexport function useMenuSection(props) {\n  var heading = props.heading,\n      ariaLabel = props['aria-label'];\n  var headingId = useId();\n  return {\n    itemProps: {\n      role: 'presentation'\n    },\n    headingProps: heading ? {\n      id: headingId,\n      'aria-hidden': true\n    } : {},\n    groupProps: {\n      role: 'group',\n      'aria-label': ariaLabel,\n      'aria-labelledby': heading ? headingId : undefined\n    }\n  };\n}","map":{"version":3,"sources":["packages/@react-aria/menu/src/useMenuTrigger.ts","packages/@react-aria/menu/src/useMenu.ts","packages/@react-aria/menu/src/useMenuItem.ts","packages/@react-aria/menu/src/useMenuSection.ts"],"names":["type","menuTriggerId","useId","overlayProps","useOverlayTrigger","onKeyDown","e","ref","state","menuTriggerProps","id","onPressStart","onPress","menuProps","shouldFocusWrap","props","console","domProps","filterDOMProps","labelable","listProps","useSelectableList","selectionManager","collection","disabledKeys","mergeProps","role","closeOnSelect","onAction","labelId","useSlotId","descriptionId","keyboardId","ariaProps","undefined","getItemCount","onClose","onPressUp","itemProps","useSelectableItem","key","shouldSelectOnPressUp","pressProps","usePress","isDisabled","hoverProps","useHover","onHoverStart","isFocusVisible","menuItemProps","labelProps","descriptionProps","keyboardShortcutProps","ariaLabel","headingId","headingProps","heading","groupProps"],"mappings":";;;;;;;OAoCO,SAAA,cAAA,CAAA,KAAA,EAAA,KAAA,EAAA,GAAA,EAA4H;AAAA,oBACjI,KADiI,CAE/HA,IAF+H;AAAA,MAE/HA,IAF+H,4BAExH,MAFwH;AAKjI,MAAIC,aAAa,GAAGC,KAApB,EAAA;;AALiI,2BAM9FE,iBAAiB,CAAC;AAACJ,IAAAA,IAAAA,EAAAA;AAAD,GAAD,EAAA,KAAA,EAApD,GAAoD,CAN6E;AAAA,MAM7H,YAN6H,sBAM7H,YAN6H;AAAA,MAM9GG,YAN8G,sBAM9GA,YAN8G;;AAQjI,MAAIE,SAAS,GAAIC,SAAbD,SAAaC,CAAAA,CAAD,EAAO;AACrB,QAAK,OAAOA,CAAC,CAAR,kBAAA,KAAA,UAAA,IAA8CA,CAAC,CAAhD,kBAA+CA,EAA9C,IAAyEA,CAAC,CAA/E,gBAAA,EAAkG;AAChG;AACD;;AAED,QAAIC,GAAG,IAAIA,GAAG,CAAd,OAAA,EAAwB;AACtB,cAAQD,CAAC,CAAT,GAAA;AACE,aAAA,WAAA;AACEA,UAAAA,CAAC,CAADA,cAAAA;AACAE,UAAAA,KAAK,CAALA,MAAAA,CAAAA,OAAAA;AACA;;AACF,aAAA,SAAA;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AA,SAAA,EAERxB,UAAU,CAAA,UAAA,EAHV,UAGU,CAFF,CADR;AAKLyB,IAAAA,UAAU,EAAE;AACVxC,MAAAA,EAAE,EAAEmB;AADM,KALP;AAQLsB,IAAAA,gBAAgB,EAAE;AAChBzC,MAAAA,EAAE,EAAEqB;AADY,KARb;AAWLqB,IAAAA,qBAAqB,EAAE;AACrB1C,MAAAA,EAAE,EAAEsB;AADiB;AAXlB,GAAP;AAeD;OC9IM,SAAA,cAAA,CAAA,KAAA,EAAsE;AAAA,MACvE,OADuE,GAC3E,KAD2E,CACvE,OADuE;AAAA,MAC/CqB,SAD+C,GAC3E,KAD2E,CAC7D,YAD6D;AAE3E,MAAIC,SAAS,GAAGpD,KAAhB,EAAA;AAEA,SAAO;AACLoC,IAAAA,SAAS,EAAE;AACTZ,MAAAA,IAAI,EAAE;AADG,KADN;AAIL6B,IAAAA,YAAY,EAAEC,OAAO,GAAG;AAItB9C,MAAAA,EAAE,EAJoB,SAAA;AAKtB,qBAAe;AALO,KAAH,GAJhB,EAAA;AAWL+C,IAAAA,UAAU,EAAE;AACV/B,MAAAA,IAAI,EADM,OAAA;AAEV,oBAFU,SAAA;AAGV,yBAAmB8B,OAAO,GAAA,SAAA,GAAetB;AAH/B;AAXP,GAAP;AAiBD","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {useId} from '@react-aria/utils';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\ninterface MenuTriggerAriaProps {\n  /** The type of menu that the menu trigger opens. */\n  type?: 'menu' | 'listbox'\n}\n\ninterface MenuTriggerAria {\n  /** Props for the menu trigger element. */\n  menuTriggerProps: AriaButtonProps,\n\n  /** Props for the menu. */\n  menuProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n */\nexport function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerState, ref: RefObject<HTMLElement>): MenuTriggerAria {\n  let {\n    type = 'menu' as MenuTriggerAriaProps['type']\n  } = props;\n\n  let menuTriggerId = useId();\n  let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n  let onKeyDown = (e) => {\n    if ((typeof e.isDefaultPrevented === 'function' && e.isDefaultPrevented()) || e.defaultPrevented) {\n      return;\n    }\n\n    if (ref && ref.current) {\n      switch (e.key) {\n        case 'ArrowDown':\n          e.preventDefault();\n          state.toggle('first');\n          break;\n        case 'ArrowUp':\n          e.preventDefault();\n          state.toggle('last');\n          break;\n      }\n    }\n  };\n\n  return {\n    menuTriggerProps: {\n      ...triggerProps,\n      id: menuTriggerId,\n      onPressStart(e) {\n        // For consistency with native, open the menu on mouse/key down, but touch up.\n        if (e.pointerType !== 'touch') {\n          // If opened with a keyboard or screen reader, auto focus the first item.\n          // Otherwise, the menu itself will be focused.\n          state.toggle(e.pointerType === 'keyboard' || e.pointerType === 'virtual' ? 'first' : null);\n        }\n      },\n      onPress(e) {\n        if (e.pointerType === 'touch') {\n          state.toggle();\n        }\n      },\n      onKeyDown\n    },\n    menuProps: {\n      ...overlayProps,\n      'aria-labelledby': menuTriggerId\n    }\n  };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaMenuProps} from '@react-types/menu';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\ninterface MenuAria {\n  /** Props for the menu element. */\n  menuProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuOptions<T> extends AriaMenuProps<T> {\n  /** Whether the menu uses virtual scrolling. */\n  isVirtualized?: boolean,\n\n  /**\n   * An optional keyboard delegate implementation for type to select,\n   * to override the default.\n   */\n  keyboardDelegate?: KeyboardDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuAria {\n  let {\n    shouldFocusWrap = true,\n    ...otherProps\n  } = props;\n\n  if (!props['aria-label'] && !props['aria-labelledby']) {\n    console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n  }\n\n  let domProps = filterDOMProps(props, {labelable: true});\n  let {listProps} = useSelectableList({\n    ...otherProps,\n    ref,\n    selectionManager: state.selectionManager,\n    collection: state.collection,\n    disabledKeys: state.disabledKeys,\n    shouldFocusWrap\n  });\n\n  return {\n    menuProps: mergeProps(domProps, {\n      role: 'menu',\n      ...listProps\n    })\n  };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {getItemCount} from '@react-stately/collections';\nimport {HTMLAttributes, Key, RefObject} from 'react';\nimport {isFocusVisible, useHover, usePress} from '@react-aria/interactions';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\nimport {PressEvent} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\ninterface MenuItemAria {\n  /** Props for the menu item element. */\n  menuItemProps: HTMLAttributes<HTMLElement>,\n\n  /** Props for the main text element inside the menu item. */\n  labelProps: HTMLAttributes<HTMLElement>,\n\n  /** Props for the description text element inside the menu item, if any. */\n  descriptionProps: HTMLAttributes<HTMLElement>,\n\n  /** Props for the keyboard shortcut text element inside the item, if any. */\n  keyboardShortcutProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuItemProps {\n  /** Whether the menu item is disabled. */\n  isDisabled?: boolean,\n\n  /** Whether the menu item is selected. */\n  isSelected?: boolean,\n\n  /** A screen reader only label for the menu item. */\n  'aria-label'?: string,\n\n  /** The unique key for the menu item. */\n  key?: Key,\n\n  /** Handler that is called when the menu should close after selecting an item. */\n  onClose?: () => void,\n\n  /**\n   * Whether the menu should close when the menu item is selected.\n   * @default true\n   */\n  closeOnSelect?: boolean,\n\n  /** Whether the menu item is contained in a virtual scrolling menu. */\n  isVirtualized?: boolean,\n\n  /** Handler that is called when the user activates the item. */\n  onAction?: (key: Key) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuItemAria {\n  let {\n    isSelected,\n    isDisabled,\n    key,\n    onClose,\n    closeOnSelect = true,\n    isVirtualized,\n    onAction\n  } = props;\n\n  let role = 'menuitem';\n  if (state.selectionManager.selectionMode === 'single') {\n    role = 'menuitemradio';\n  } else if (state.selectionManager.selectionMode === 'multiple') {\n    role = 'menuitemcheckbox';\n  }\n\n  let labelId = useSlotId();\n  let descriptionId = useSlotId();\n  let keyboardId = useSlotId();\n\n  let ariaProps = {\n    'aria-disabled': isDisabled,\n    role,\n    'aria-label': props['aria-label'],\n    'aria-labelledby': labelId,\n    'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n  };\n\n  if (state.selectionManager.selectionMode !== 'none') {\n    ariaProps['aria-checked'] = isSelected;\n  }\n\n  if (isVirtualized) {\n    ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n    ariaProps['aria-setsize'] = getItemCount(state.collection);\n  }\n\n  let onKeyDown = (e: KeyboardEvent) => {\n    // Ignore repeating events, which may have started on the menu trigger before moving\n    // focus to the menu item. We want to wait for a second complete key press sequence.\n    if (e.repeat) {\n      return;\n    }\n\n    switch (e.key) {\n      case ' ':\n        if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect && onClose) {\n          onClose();\n        }\n        break;\n      case 'Enter':\n        if (!isDisabled && closeOnSelect && onClose) {\n          onClose();\n        }\n        break;\n    }\n  };\n\n  let onPressStart = (e: PressEvent) => {\n    if (e.pointerType === 'keyboard' && onAction) {\n      onAction(key);\n    }\n  };\n\n  let onPressUp = (e: PressEvent) => {\n    if (e.pointerType !== 'keyboard') {\n      if (onAction) {\n        onAction(key);\n      }\n\n      if (closeOnSelect && onClose) {\n        onClose();\n      }\n    }\n  };\n\n  let {itemProps} = useSelectableItem({\n    selectionManager: state.selectionManager,\n    key,\n    ref,\n    shouldSelectOnPressUp: true\n  });\n\n  let {pressProps} = usePress(mergeProps({onPressStart, onPressUp, onKeyDown, isDisabled}, itemProps));\n  let {hoverProps} = useHover({\n    isDisabled,\n    onHoverStart() {\n      if (!isFocusVisible()) {\n        state.selectionManager.setFocused(true);\n        state.selectionManager.setFocusedKey(key);\n      }\n    }\n  });\n\n  return {\n    menuItemProps: {\n      ...ariaProps,\n      ...mergeProps(pressProps, hoverProps)\n    },\n    labelProps: {\n      id: labelId\n    },\n    descriptionProps: {\n      id: descriptionId\n    },\n    keyboardShortcutProps: {\n      id: keyboardId\n    }\n  };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HTMLAttributes, ReactNode} from 'react';\nimport {useId} from '@react-aria/utils';\n\ninterface AriaMenuSectionProps {\n  /** The heading for the section. */\n  heading?: ReactNode,\n  /** An accessibility label for the section. Required if `heading` is not present. */\n  'aria-label'?: string\n}\n\ninterface MenuSectionAria {\n  /** Props for the wrapper list item. */\n  itemProps: HTMLAttributes<HTMLElement>,\n\n  /** Props for the heading element, if any. */\n  headingProps: HTMLAttributes<HTMLElement>,\n\n  /** Props for the group element. */\n  groupProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the section.\n */\nexport function useMenuSection(props: AriaMenuSectionProps): MenuSectionAria {\n  let {heading, 'aria-label': ariaLabel} = props;\n  let headingId = useId();\n\n  return {\n    itemProps: {\n      role: 'presentation'\n    },\n    headingProps: heading ? {\n      // Techincally, menus cannot contain headings according to ARIA.\n      // We hide the heading from assistive technology, and only use it\n      // as a label for the nested group.\n      id: headingId,\n      'aria-hidden': true\n    } : {},\n    groupProps: {\n      role: 'group',\n      'aria-label': ariaLabel,\n      'aria-labelledby': heading ? headingId : undefined\n    }\n  };\n}\n"]},"metadata":{},"sourceType":"module"}