a9ffb1a7315b40f9ee6b0b53d84cbc55.json
12 KB
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useEffect, useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport { addGlobalMouseDownEvent } from '../utils/uiUtil';\nexport default function usePickerInput(_ref) {\n var open = _ref.open,\n value = _ref.value,\n isClickOutside = _ref.isClickOutside,\n triggerOpen = _ref.triggerOpen,\n forwardKeyDown = _ref.forwardKeyDown,\n blurToCancel = _ref.blurToCancel,\n onSubmit = _ref.onSubmit,\n onCancel = _ref.onCancel,\n _onFocus = _ref.onFocus,\n _onBlur = _ref.onBlur;\n\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n typing = _useState2[0],\n setTyping = _useState2[1];\n\n var _useState3 = useState(false),\n _useState4 = _slicedToArray(_useState3, 2),\n focused = _useState4[0],\n setFocused = _useState4[1];\n /**\n * We will prevent blur to handle open event when user click outside,\n * since this will repeat trigger `onOpenChange` event.\n */\n\n\n var preventBlurRef = useRef(false);\n var valueChangedRef = useRef(false);\n var inputProps = {\n onMouseDown: function onMouseDown() {\n setTyping(true);\n triggerOpen(true);\n },\n onKeyDown: function onKeyDown(e) {\n switch (e.which) {\n case KeyCode.ENTER:\n {\n if (!open) {\n triggerOpen(true);\n } else if (onSubmit() !== false) {\n setTyping(true);\n }\n\n e.preventDefault();\n return;\n }\n\n case KeyCode.TAB:\n {\n if (typing && open && !e.shiftKey) {\n setTyping(false);\n e.preventDefault();\n } else if (!typing && open) {\n if (!forwardKeyDown(e) && e.shiftKey) {\n setTyping(true);\n e.preventDefault();\n }\n }\n\n return;\n }\n\n case KeyCode.ESC:\n {\n setTyping(true);\n onCancel();\n return;\n }\n }\n\n if (!open && ![KeyCode.SHIFT].includes(e.which)) {\n triggerOpen(true);\n } else if (!typing) {\n // Let popup panel handle keyboard\n forwardKeyDown(e);\n }\n },\n onFocus: function onFocus(e) {\n setTyping(true);\n setFocused(true);\n\n if (_onFocus) {\n _onFocus(e);\n }\n },\n onBlur: function onBlur(e) {\n if (preventBlurRef.current || !isClickOutside(document.activeElement)) {\n preventBlurRef.current = false;\n return;\n }\n\n if (blurToCancel) {\n setTimeout(function () {\n if (isClickOutside(document.activeElement)) {\n onCancel();\n }\n }, 0);\n } else if (open) {\n triggerOpen(false);\n\n if (valueChangedRef.current) {\n onSubmit();\n }\n }\n\n setFocused(false);\n\n if (_onBlur) {\n _onBlur(e);\n }\n }\n }; // check if value changed\n\n useEffect(function () {\n valueChangedRef.current = false;\n }, [open]);\n useEffect(function () {\n valueChangedRef.current = true;\n }, [value]); // Global click handler\n\n useEffect(function () {\n return addGlobalMouseDownEvent(function (_ref2) {\n var target = _ref2.target;\n\n if (open) {\n if (!isClickOutside(target)) {\n preventBlurRef.current = true; // Always set back in case `onBlur` prevented by user\n\n requestAnimationFrame(function () {\n preventBlurRef.current = false;\n });\n } else if (!focused) {\n triggerOpen(false);\n }\n }\n });\n });\n return [inputProps, {\n focused: focused,\n typing: typing\n }];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-picker/es/hooks/usePickerInput.js"],"names":["_slicedToArray","useState","useEffect","useRef","KeyCode","addGlobalMouseDownEvent","usePickerInput","_ref","open","value","isClickOutside","triggerOpen","forwardKeyDown","blurToCancel","onSubmit","onCancel","_onFocus","onFocus","_onBlur","onBlur","_useState","_useState2","typing","setTyping","_useState3","_useState4","focused","setFocused","preventBlurRef","valueChangedRef","inputProps","onMouseDown","onKeyDown","e","which","ENTER","preventDefault","TAB","shiftKey","ESC","SHIFT","includes","current","document","activeElement","setTimeout","_ref2","target","requestAnimationFrame"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,0CAA3B;AACA,SAASC,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,QAA4C,OAA5C;AACA,OAAOC,OAAP,MAAoB,oBAApB;AACA,SAASC,uBAAT,QAAwC,iBAAxC;AACA,eAAe,S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,EAAU;AACR,YAAI,CAACE,cAAc,CAACqC,MAAD,CAAnB,EAA6B;AAC3BnB,UAAAA,cAAc,CAACc,OAAf,GAAyB,IAAzB,CAD2B,CACI;;AAE/BM,UAAAA,qBAAqB,CAAC,YAAY;AAChCpB,YAAAA,cAAc,CAACc,OAAf,GAAyB,KAAzB;AACD,WAFoB,CAArB;AAGD,SAND,MAMO,IAAI,CAAChB,OAAL,EAAc;AACnBf,UAAAA,WAAW,CAAC,KAAD,CAAX;AACD;AACF;AACF,KAd6B,CAA9B;AAeD,GAhBQ,CAAT;AAiBA,SAAO,CAACmB,UAAD,EAAa;AAClBJ,IAAAA,OAAO,EAAEA,OADS;AAElBJ,IAAAA,MAAM,EAAEA;AAFU,GAAb,CAAP;AAID","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useEffect, useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport { addGlobalMouseDownEvent } from '../utils/uiUtil';\nexport default function usePickerInput(_ref) {\n var open = _ref.open,\n value = _ref.value,\n isClickOutside = _ref.isClickOutside,\n triggerOpen = _ref.triggerOpen,\n forwardKeyDown = _ref.forwardKeyDown,\n blurToCancel = _ref.blurToCancel,\n onSubmit = _ref.onSubmit,\n onCancel = _ref.onCancel,\n _onFocus = _ref.onFocus,\n _onBlur = _ref.onBlur;\n\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n typing = _useState2[0],\n setTyping = _useState2[1];\n\n var _useState3 = useState(false),\n _useState4 = _slicedToArray(_useState3, 2),\n focused = _useState4[0],\n setFocused = _useState4[1];\n /**\n * We will prevent blur to handle open event when user click outside,\n * since this will repeat trigger `onOpenChange` event.\n */\n\n\n var preventBlurRef = useRef(false);\n var valueChangedRef = useRef(false);\n var inputProps = {\n onMouseDown: function onMouseDown() {\n setTyping(true);\n triggerOpen(true);\n },\n onKeyDown: function onKeyDown(e) {\n switch (e.which) {\n case KeyCode.ENTER:\n {\n if (!open) {\n triggerOpen(true);\n } else if (onSubmit() !== false) {\n setTyping(true);\n }\n\n e.preventDefault();\n return;\n }\n\n case KeyCode.TAB:\n {\n if (typing && open && !e.shiftKey) {\n setTyping(false);\n e.preventDefault();\n } else if (!typing && open) {\n if (!forwardKeyDown(e) && e.shiftKey) {\n setTyping(true);\n e.preventDefault();\n }\n }\n\n return;\n }\n\n case KeyCode.ESC:\n {\n setTyping(true);\n onCancel();\n return;\n }\n }\n\n if (!open && ![KeyCode.SHIFT].includes(e.which)) {\n triggerOpen(true);\n } else if (!typing) {\n // Let popup panel handle keyboard\n forwardKeyDown(e);\n }\n },\n onFocus: function onFocus(e) {\n setTyping(true);\n setFocused(true);\n\n if (_onFocus) {\n _onFocus(e);\n }\n },\n onBlur: function onBlur(e) {\n if (preventBlurRef.current || !isClickOutside(document.activeElement)) {\n preventBlurRef.current = false;\n return;\n }\n\n if (blurToCancel) {\n setTimeout(function () {\n if (isClickOutside(document.activeElement)) {\n onCancel();\n }\n }, 0);\n } else if (open) {\n triggerOpen(false);\n\n if (valueChangedRef.current) {\n onSubmit();\n }\n }\n\n setFocused(false);\n\n if (_onBlur) {\n _onBlur(e);\n }\n }\n }; // check if value changed\n\n useEffect(function () {\n valueChangedRef.current = false;\n }, [open]);\n useEffect(function () {\n valueChangedRef.current = true;\n }, [value]); // Global click handler\n\n useEffect(function () {\n return addGlobalMouseDownEvent(function (_ref2) {\n var target = _ref2.target;\n\n if (open) {\n if (!isClickOutside(target)) {\n preventBlurRef.current = true; // Always set back in case `onBlur` prevented by user\n\n requestAnimationFrame(function () {\n preventBlurRef.current = false;\n });\n } else if (!focused) {\n triggerOpen(false);\n }\n }\n });\n });\n return [inputProps, {\n focused: focused,\n typing: typing\n }];\n}"]},"metadata":{},"sourceType":"module"}