1a57e79da0cc32856f13bda30ce64d41.json
16.8 KB
{"ast":null,"code":"import _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 * as React from 'react';\nimport { useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport MultipleSelector from './MultipleSelector';\nimport SingleSelector from './SingleSelector';\nimport useLock from '../hooks/useLock';\n\nvar Selector = function Selector(props, ref) {\n var inputRef = useRef(null);\n var compositionStatusRef = useRef(false);\n var prefixCls = props.prefixCls,\n multiple = props.multiple,\n open = props.open,\n mode = props.mode,\n showSearch = props.showSearch,\n tokenWithEnter = props.tokenWithEnter,\n onSearch = props.onSearch,\n onSearchSubmit = props.onSearchSubmit,\n onToggleOpen = props.onToggleOpen,\n onInputKeyDown = props.onInputKeyDown,\n domRef = props.domRef; // ======================= Ref =======================\n\n React.useImperativeHandle(ref, function () {\n return {\n focus: function focus() {\n inputRef.current.focus();\n },\n blur: function blur() {\n inputRef.current.blur();\n }\n };\n }); // ====================== Input ======================\n\n var _useLock = useLock(0),\n _useLock2 = _slicedToArray(_useLock, 2),\n getInputMouseDown = _useLock2[0],\n setInputMouseDown = _useLock2[1];\n\n var onInternalInputKeyDown = function onInternalInputKeyDown(event) {\n var which = event.which;\n\n if (which === KeyCode.UP || which === KeyCode.DOWN) {\n event.preventDefault();\n }\n\n if (onInputKeyDown) {\n onInputKeyDown(event);\n }\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(event.target.value);\n }\n\n if (![KeyCode.SHIFT, KeyCode.TAB, KeyCode.BACKSPACE, KeyCode.ESC].includes(which)) {\n onToggleOpen(true);\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\n\n var onInternalInputMouseDown = function onInternalInputMouseDown() {\n setInputMouseDown(true);\n }; // When paste come, ignore next onChange\n\n\n var pastedTextRef = useRef(null);\n\n var triggerOnSearch = function triggerOnSearch(value) {\n if (onSearch(value, true, compositionStatusRef.current) !== false) {\n onToggleOpen(true);\n }\n };\n\n var onInputCompositionStart = function onInputCompositionStart() {\n compositionStatusRef.current = true;\n };\n\n var onInputCompositionEnd = function onInputCompositionEnd() {\n compositionStatusRef.current = false;\n };\n\n var onInputChange = function onInputChange(event) {\n var value = event.target.value; // Pasted text should replace back to origin content\n\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/g, ' ').replace(/[\\r\\n]/g, ' ');\n value = value.replace(replacedText, pastedTextRef.current);\n }\n\n pastedTextRef.current = null;\n triggerOnSearch(value);\n };\n\n var onInputPaste = function onInputPaste(e) {\n var clipboardData = e.clipboardData;\n var value = clipboardData.getData('text');\n pastedTextRef.current = value;\n };\n\n var onClick = function onClick(_ref) {\n var target = _ref.target;\n\n if (target !== inputRef.current) {\n // Should focus input if click the selector\n var isIE = document.body.style.msTouchAction !== undefined;\n\n if (isIE) {\n setTimeout(function () {\n inputRef.current.focus();\n });\n } else {\n inputRef.current.focus();\n }\n }\n };\n\n var onMouseDown = function onMouseDown(event) {\n var inputMouseDown = getInputMouseDown();\n\n if (event.target !== inputRef.current && !inputMouseDown) {\n event.preventDefault();\n }\n\n if (mode !== 'combobox' && (!showSearch || !inputMouseDown) || !open) {\n if (open) {\n onSearch('', true, false);\n }\n\n onToggleOpen();\n }\n }; // ================= Inner Selector ==================\n\n\n var sharedProps = {\n inputRef: inputRef,\n onInputKeyDown: onInternalInputKeyDown,\n onInputMouseDown: onInternalInputMouseDown,\n onInputChange: onInputChange,\n onInputPaste: onInputPaste,\n onInputCompositionStart: onInputCompositionStart,\n onInputCompositionEnd: onInputCompositionEnd\n };\n var selectNode = multiple ? React.createElement(MultipleSelector, Object.assign({}, props, sharedProps)) : React.createElement(SingleSelector, Object.assign({}, props, sharedProps));\n return React.createElement(\"div\", {\n ref: domRef,\n className: \"\".concat(prefixCls, \"-selector\"),\n onClick: onClick,\n onMouseDown: onMouseDown\n }, selectNode);\n};\n\nvar ForwardSelector = React.forwardRef(Selector);\nForwardSelector.displayName = 'Selector';\nexport default ForwardSelector;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-select/es/Selector/index.js"],"names":["_slicedToArray","React","useRef","KeyCode","MultipleSelector","SingleSelector","useLock","Selector","props","ref","inputRef","compositionStatusRef","prefixCls","multiple","open","mode","showSearch","tokenWithEnter","onSearch","onSearchSubmit","onToggleOpen","onInputKeyDown","domRef","useImperativeHandle","focus","current","blur","_useLock","_useLock2","getInputMouseDown","setInputMouseDown","onInternalInputKeyDown","event","which","UP","DOWN","preventDefault","ENTER","target","value","SHIFT","TAB","BACKSPACE","ESC","includes","onInternalInputMouseDown","pastedTextRef","triggerOnSearch","onInputCompositionStart","onInputCompositionEnd","onInputChange","test","replacedText","replace","onInputPaste","e","clipboardData","getData","onClick","_ref","isIE","document","body","style","msTouchAction","undefined","setTimeout","onMouseDown","inputMouseDown","sharedProps","onInputMouseDown","selectNode","createElement","Object","assign","className","concat","ForwardSelector","forwardRef","displayName"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,0CAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,MAAT,QAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,oBAApB;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,OAAP,MAAoB,kBAApB;;AAEA,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AK,CAACuE,aAAN,CAAoBnE,cAApB,EAAoCoE,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBlE,KAAlB,EAAyB6D,WAAzB,CAApC,CAA3G;AACA,SAAOpE,KAAK,CAACuE,aAAN,CAAoB,KAApB,EAA2B;AAChC/D,IAAAA,GAAG,EAAEa,MAD2B;AAEhCqD,IAAAA,SAAS,EAAE,GAAGC,MAAH,CAAUhE,SAAV,EAAqB,WAArB,CAFqB;AAGhC8C,IAAAA,OAAO,EAAEA,OAHuB;AAIhCS,IAAAA,WAAW,EAAEA;AAJmB,GAA3B,EAKJI,UALI,CAAP;AAMD,CApJD;;AAsJA,IAAIM,eAAe,GAAG5E,KAAK,CAAC6E,UAAN,CAAiBvE,QAAjB,CAAtB;AACAsE,eAAe,CAACE,WAAhB,GAA8B,UAA9B;AACA,eAAeF,eAAf","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\n\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 */\nimport * as React from 'react';\nimport { useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport MultipleSelector from './MultipleSelector';\nimport SingleSelector from './SingleSelector';\nimport useLock from '../hooks/useLock';\n\nvar Selector = function Selector(props, ref) {\n var inputRef = useRef(null);\n var compositionStatusRef = useRef(false);\n var prefixCls = props.prefixCls,\n multiple = props.multiple,\n open = props.open,\n mode = props.mode,\n showSearch = props.showSearch,\n tokenWithEnter = props.tokenWithEnter,\n onSearch = props.onSearch,\n onSearchSubmit = props.onSearchSubmit,\n onToggleOpen = props.onToggleOpen,\n onInputKeyDown = props.onInputKeyDown,\n domRef = props.domRef; // ======================= Ref =======================\n\n React.useImperativeHandle(ref, function () {\n return {\n focus: function focus() {\n inputRef.current.focus();\n },\n blur: function blur() {\n inputRef.current.blur();\n }\n };\n }); // ====================== Input ======================\n\n var _useLock = useLock(0),\n _useLock2 = _slicedToArray(_useLock, 2),\n getInputMouseDown = _useLock2[0],\n setInputMouseDown = _useLock2[1];\n\n var onInternalInputKeyDown = function onInternalInputKeyDown(event) {\n var which = event.which;\n\n if (which === KeyCode.UP || which === KeyCode.DOWN) {\n event.preventDefault();\n }\n\n if (onInputKeyDown) {\n onInputKeyDown(event);\n }\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(event.target.value);\n }\n\n if (![KeyCode.SHIFT, KeyCode.TAB, KeyCode.BACKSPACE, KeyCode.ESC].includes(which)) {\n onToggleOpen(true);\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\n\n var onInternalInputMouseDown = function onInternalInputMouseDown() {\n setInputMouseDown(true);\n }; // When paste come, ignore next onChange\n\n\n var pastedTextRef = useRef(null);\n\n var triggerOnSearch = function triggerOnSearch(value) {\n if (onSearch(value, true, compositionStatusRef.current) !== false) {\n onToggleOpen(true);\n }\n };\n\n var onInputCompositionStart = function onInputCompositionStart() {\n compositionStatusRef.current = true;\n };\n\n var onInputCompositionEnd = function onInputCompositionEnd() {\n compositionStatusRef.current = false;\n };\n\n var onInputChange = function onInputChange(event) {\n var value = event.target.value; // Pasted text should replace back to origin content\n\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/g, ' ').replace(/[\\r\\n]/g, ' ');\n value = value.replace(replacedText, pastedTextRef.current);\n }\n\n pastedTextRef.current = null;\n triggerOnSearch(value);\n };\n\n var onInputPaste = function onInputPaste(e) {\n var clipboardData = e.clipboardData;\n var value = clipboardData.getData('text');\n pastedTextRef.current = value;\n };\n\n var onClick = function onClick(_ref) {\n var target = _ref.target;\n\n if (target !== inputRef.current) {\n // Should focus input if click the selector\n var isIE = document.body.style.msTouchAction !== undefined;\n\n if (isIE) {\n setTimeout(function () {\n inputRef.current.focus();\n });\n } else {\n inputRef.current.focus();\n }\n }\n };\n\n var onMouseDown = function onMouseDown(event) {\n var inputMouseDown = getInputMouseDown();\n\n if (event.target !== inputRef.current && !inputMouseDown) {\n event.preventDefault();\n }\n\n if (mode !== 'combobox' && (!showSearch || !inputMouseDown) || !open) {\n if (open) {\n onSearch('', true, false);\n }\n\n onToggleOpen();\n }\n }; // ================= Inner Selector ==================\n\n\n var sharedProps = {\n inputRef: inputRef,\n onInputKeyDown: onInternalInputKeyDown,\n onInputMouseDown: onInternalInputMouseDown,\n onInputChange: onInputChange,\n onInputPaste: onInputPaste,\n onInputCompositionStart: onInputCompositionStart,\n onInputCompositionEnd: onInputCompositionEnd\n };\n var selectNode = multiple ? React.createElement(MultipleSelector, Object.assign({}, props, sharedProps)) : React.createElement(SingleSelector, Object.assign({}, props, sharedProps));\n return React.createElement(\"div\", {\n ref: domRef,\n className: \"\".concat(prefixCls, \"-selector\"),\n onClick: onClick,\n onMouseDown: onMouseDown\n }, selectNode);\n};\n\nvar ForwardSelector = React.forwardRef(Selector);\nForwardSelector.displayName = 'Selector';\nexport default ForwardSelector;"]},"metadata":{},"sourceType":"module"}