1 line
7.6 KiB
JSON
1 line
7.6 KiB
JSON
|
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useLockEffect from \"./useLockEffect\";\n/**\n * When user first focus one input, any submit will trigger focus another one.\n * When second time focus one input, submit will not trigger focus again.\n * When click outside to close the panel, trigger event if it can trigger onChange.\n */\nexport default function useRangeActive(disabled) {\n var empty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n var mergedOpen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var _React$useState = React.useState(0),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n activeIndex = _React$useState2[0],\n setActiveIndex = _React$useState2[1];\n var _React$useState3 = React.useState(false),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n focused = _React$useState4[0],\n setFocused = _React$useState4[1];\n var activeListRef = React.useRef([]);\n var lastOperationRef = React.useRef(null);\n var triggerFocus = function triggerFocus(nextFocus) {\n setFocused(nextFocus);\n };\n\n // ============================= Record =============================\n var lastOperation = function lastOperation(type) {\n if (type) {\n lastOperationRef.current = type;\n }\n return lastOperationRef.current;\n };\n\n // ============================ Strategy ============================\n // Trigger when input enter or input blur or panel close\n var nextActiveIndex = function nextActiveIndex(nextValue) {\n var list = activeListRef.current;\n var filledActiveSet = new Set(list.filter(function (index) {\n return nextValue[index] || empty[index];\n }));\n var nextIndex = list[list.length - 1] === 0 ? 1 : 0;\n if (filledActiveSet.size >= 2 || disabled[nextIndex]) {\n return null;\n }\n return nextIndex;\n };\n\n // ============================= Effect =============================\n // Wait in case it's from the click outside to blur\n useLockEffect(focused || mergedOpen, function () {\n if (!focused) {\n activeListRef.current = [];\n }\n });\n React.useEffect(function () {\n if (focused) {\n activeListRef.current.push(activeIndex);\n }\n }, [focused, activeIndex]);\n return [focused, triggerFocus, lastOperation, activeIndex, setActiveIndex, nextActiveIndex, activeListRef.current];\n}","map":{"version":3,"names":["_slicedToArray","React","useLockEffect","useRangeActive","disabled","empty","arguments","length","undefined","mergedOpen","_React$useState","useState","_React$useState2","activeIndex","setActiveIndex","_React$useState3","_React$useState4","focused","setFocused","activeListRef","useRef","lastOperationRef","triggerFocus","nextFocus","lastOperation","type","current","nextActiveIndex","nextValue","list","filledActiveSet","Set","filter","index","nextIndex","size","useEffect","push"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-picker/es/PickerInput/hooks/useRangeActive.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useLockEffect from \"./useLockEffect\";\n/**\n * When user first focus one input, any submit will trigger focus another one.\n * When second time focus one input, submit will not trigger focus again.\n * When click outside to close the panel, trigger event if it can trigger onChange.\n */\nexport default function useRangeActive(disabled) {\n var empty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n var mergedOpen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var _React$useState = React.useState(0),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n activeIndex = _React$useState2[0],\n setActiveIndex = _React$useState2[1];\n var _React$useState3 = React.useState(false),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n f
|