PromoCursed/node_modules/.cache/babel-loader/70da40eac25fd59b5ab0febd2a97efdfefcf1e2705b511f48acb54a2d139a278.json

1 line
19 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\n/**\n * Cursor rule:\n * 1. Only `showSearch` enabled\n * 2. Only `open` is `true`\n * 3. When typing, set `open` to `true` which hit rule of 2\n *\n * Accessibility:\n * - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html\n */\n\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport * as React from 'react';\nimport { useRef } from 'react';\nimport useLock from \"../hooks/useLock\";\nimport { isValidateOpenKey } from \"../utils/keyUtil\";\nimport MultipleSelector from \"./MultipleSelector\";\nimport SingleSelector from \"./SingleSelector\";\nvar Selector = function Selector(props, ref) {\n var inputRef = useRef(null);\n var compositionStatusRef = useRef(false);\n var prefixCls = props.prefixCls,\n open = props.open,\n mode = props.mode,\n showSearch = props.showSearch,\n tokenWithEnter = props.tokenWithEnter,\n disabled = props.disabled,\n autoClearSearchValue = props.autoClearSearchValue,\n onSearch = props.onSearch,\n onSearchSubmit = props.onSearchSubmit,\n onToggleOpen = props.onToggleOpen,\n onInputKeyDown = props.onInputKeyDown,\n domRef = props.domRef;\n\n // ======================= Ref =======================\n React.useImperativeHandle(ref, function () {\n return {\n focus: function focus(options) {\n inputRef.current.focus(options);\n },\n blur: function blur() {\n inputRef.current.blur();\n }\n };\n });\n\n // ====================== Input ======================\n var _useLock = useLock(0),\n _useLock2 = _slicedToArray(_useLock, 2),\n getInputMouseDown = _useLock2[0],\n setInputMouseDown = _useLock2[1];\n var onInternalInputKeyDown = function onInternalInputKeyDown(event) {\n var which = event.which;\n if (which === KeyCode.UP || which === KeyCode.DOWN) {\n event.preventDefault();\n }\n if (onInputKeyDown) {\n onInputKeyDown(event);\n }\n if (which === KeyCode.ENTER && mode === 'tags' && !compositionStatusRef.current && !open) {\n // When menu isn't open, OptionList won't trigger a value change\n // So when enter is pressed, the tag's input value should be emitted here to let selector know\n onSearchSubmit === null || onSearchSubmit === void 0 || onSearchSubmit(event.target.value);\n }\n if (isValidateOpenKey(which)) {\n onToggleOpen(true);\n }\n };\n\n /**\n * We can not use `findDOMNode` sine it will get warning,\n * have to use timer to check if is input element.\n */\n var onInternalInputMouseDown = function onInternalInputMouseDown() {\n setInputMouseDown(true);\n };\n\n // When paste come, ignore next onChange\n var pastedTextRef = useRef(null);\n var triggerOnSearch = function triggerOnSearch(value) {\n if (onSearch(value, true, compositionStatusRef.current) !== false) {\n onToggleOpen(true);\n }\n };\n var onInputCompositionStart = function onInputCompositionStart() {\n compositionStatusRef.current = true;\n };\n var onInputCompositionEnd = function onInputCompositionEnd(e) {\n compositionStatusRef.current = false;\n\n // Trigger search again to support `tokenSeparators` with typewriting\n if (mode !== 'combobox') {\n triggerOnSearch(e.target.value);\n }\n };\n var onInputChange = function onInputChange(event) {\n var value = event.target.value;\n\n // Pasted text should replace back to origin content\n if (tokenWithEnter && pastedTextRef.current && /[\\r\\n]/.test(pastedTextRef.current)) {\n // CRLF will be treated as a single space for input element\n var replacedText = pastedTextRef.current.replace(/[\\r\\n]+$/, '').replace(/\\r\\n/g, ' ').replace(/[\\r\\n]/g, ' ');\n value = value.replace(replacedText, pastedTextRef.current);\n }\n pastedTextRef.current = null;\n triggerOnSearch(value);\n };\n var onInputPaste = function onInputPaste(e) {\n var clipboardData = e.clipboar