1 line
22 KiB
JSON
1 line
22 KiB
JSON
|
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport classNames from 'classnames';\nimport Dropdown from 'rc-dropdown';\nimport Menu, { MenuItem } from 'rc-menu';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { getRemovable } from \"../util\";\nimport AddButton from \"./AddButton\";\nvar OperationNode = /*#__PURE__*/React.forwardRef(function (props, ref) {\n var prefixCls = props.prefixCls,\n id = props.id,\n tabs = props.tabs,\n locale = props.locale,\n mobile = props.mobile,\n _props$more = props.more,\n moreProps = _props$more === void 0 ? {} : _props$more,\n style = props.style,\n className = props.className,\n editable = props.editable,\n tabBarGutter = props.tabBarGutter,\n rtl = props.rtl,\n removeAriaLabel = props.removeAriaLabel,\n onTabClick = props.onTabClick,\n getPopupContainer = props.getPopupContainer,\n popupClassName = props.popupClassName;\n // ======================== Dropdown ========================\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n open = _useState2[0],\n setOpen = _useState2[1];\n var _useState3 = useState(null),\n _useState4 = _slicedToArray(_useState3, 2),\n selectedKey = _useState4[0],\n setSelectedKey = _useState4[1];\n var _moreProps$icon = moreProps.icon,\n moreIcon = _moreProps$icon === void 0 ? 'More' : _moreProps$icon;\n var popupId = \"\".concat(id, \"-more-popup\");\n var dropdownPrefix = \"\".concat(prefixCls, \"-dropdown\");\n var selectedItemId = selectedKey !== null ? \"\".concat(popupId, \"-\").concat(selectedKey) : null;\n var dropdownAriaLabel = locale === null || locale === void 0 ? void 0 : locale.dropdownAriaLabel;\n function onRemoveTab(event, key) {\n event.preventDefault();\n event.stopPropagation();\n editable.onEdit('remove', {\n key: key,\n event: event\n });\n }\n var menu = /*#__PURE__*/React.createElement(Menu, {\n onClick: function onClick(_ref) {\n var key = _ref.key,\n domEvent = _ref.domEvent;\n onTabClick(key, domEvent);\n setOpen(false);\n },\n prefixCls: \"\".concat(dropdownPrefix, \"-menu\"),\n id: popupId,\n tabIndex: -1,\n role: \"listbox\",\n \"aria-activedescendant\": selectedItemId,\n selectedKeys: [selectedKey],\n \"aria-label\": dropdownAriaLabel !== undefined ? dropdownAriaLabel : 'expanded dropdown'\n }, tabs.map(function (tab) {\n var closable = tab.closable,\n disabled = tab.disabled,\n closeIcon = tab.closeIcon,\n key = tab.key,\n label = tab.label;\n var removable = getRemovable(closable, closeIcon, editable, disabled);\n return /*#__PURE__*/React.createElement(MenuItem, {\n key: key,\n id: \"\".concat(popupId, \"-\").concat(key),\n role: \"option\",\n \"aria-controls\": id && \"\".concat(id, \"-panel-\").concat(key),\n disabled: disabled\n }, /*#__PURE__*/React.createElement(\"span\", null, label), removable && /*#__PURE__*/React.createElement(\"button\", {\n type: \"button\",\n \"aria-label\": removeAriaLabel || 'remove',\n tabIndex: 0,\n className: \"\".concat(dropdownPrefix, \"-menu-item-remove\"),\n onClick: function onClick(e) {\n e.stopPropagation();\n onRemoveTab(e, key);\n }\n }, closeIcon || editable.removeIcon || '×'));\n }));\n function selectOffset(offset) {\n var enabledTabs = tabs.filter(function (tab) {\n return !tab.disabled;\n });\n var selectedIndex = enabledTabs.findIndex(function (tab) {\n return tab.key === selectedKey;\n }) || 0;\n var len = enabledTabs.length;\n for (var i = 0; i < len; i += 1) {\n selectedIndex = (selectedIndex + offset + len) % len;\n var tab = enabledTabs[selectedIndex];\n if (!tab.disabled) {\n
|