1 line
13 KiB
JSON
1 line
13 KiB
JSON
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useCallback } from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { nextSlice } from \"../utils/timeUtil\";\nvar PATH_SPLIT = '__RC_UTIL_PATH_SPLIT__';\nvar getPathStr = function getPathStr(keyPath) {\n return keyPath.join(PATH_SPLIT);\n};\nvar getPathKeys = function getPathKeys(keyPathStr) {\n return keyPathStr.split(PATH_SPLIT);\n};\nexport var OVERFLOW_KEY = 'rc-menu-more';\nexport default function useKeyRecords() {\n var _React$useState = React.useState({}),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n internalForceUpdate = _React$useState2[1];\n var key2pathRef = useRef(new Map());\n var path2keyRef = useRef(new Map());\n var _React$useState3 = React.useState([]),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n overflowKeys = _React$useState4[0],\n setOverflowKeys = _React$useState4[1];\n var updateRef = useRef(0);\n var destroyRef = useRef(false);\n var forceUpdate = function forceUpdate() {\n if (!destroyRef.current) {\n internalForceUpdate({});\n }\n };\n var registerPath = useCallback(function (key, keyPath) {\n // Warning for invalidate or duplicated `key`\n if (process.env.NODE_ENV !== 'production') {\n warning(!key2pathRef.current.has(key), \"Duplicated key '\".concat(key, \"' used in Menu by path [\").concat(keyPath.join(' > '), \"]\"));\n }\n\n // Fill map\n var connectedPath = getPathStr(keyPath);\n path2keyRef.current.set(connectedPath, key);\n key2pathRef.current.set(key, connectedPath);\n updateRef.current += 1;\n var id = updateRef.current;\n nextSlice(function () {\n if (id === updateRef.current) {\n forceUpdate();\n }\n });\n }, []);\n var unregisterPath = useCallback(function (key, keyPath) {\n var connectedPath = getPathStr(keyPath);\n path2keyRef.current.delete(connectedPath);\n key2pathRef.current.delete(key);\n }, []);\n var refreshOverflowKeys = useCallback(function (keys) {\n setOverflowKeys(keys);\n }, []);\n var getKeyPath = useCallback(function (eventKey, includeOverflow) {\n var fullPath = key2pathRef.current.get(eventKey) || '';\n var keys = getPathKeys(fullPath);\n if (includeOverflow && overflowKeys.includes(keys[0])) {\n keys.unshift(OVERFLOW_KEY);\n }\n return keys;\n }, [overflowKeys]);\n var isSubPathKey = useCallback(function (pathKeys, eventKey) {\n return pathKeys.filter(function (item) {\n return item !== undefined;\n }).some(function (pathKey) {\n var pathKeyList = getKeyPath(pathKey, true);\n return pathKeyList.includes(eventKey);\n });\n }, [getKeyPath]);\n var getKeys = function getKeys() {\n var keys = _toConsumableArray(key2pathRef.current.keys());\n if (overflowKeys.length) {\n keys.push(OVERFLOW_KEY);\n }\n return keys;\n };\n\n /**\n * Find current key related child path keys\n */\n var getSubPathKeys = useCallback(function (key) {\n var connectedPath = \"\".concat(key2pathRef.current.get(key)).concat(PATH_SPLIT);\n var pathKeys = new Set();\n _toConsumableArray(path2keyRef.current.keys()).forEach(function (pathKey) {\n if (pathKey.startsWith(connectedPath)) {\n pathKeys.add(path2keyRef.current.get(pathKey));\n }\n });\n return pathKeys;\n }, []);\n React.useEffect(function () {\n return function () {\n destroyRef.current = true;\n };\n }, []);\n return {\n // Register\n registerPath: registerPath,\n unregisterPath: unregisterPath,\n refreshOverflowKeys: refreshOverflowKeys,\n // Util\n isSubPathKey: isSubPathKey,\n getKeyPath: getKeyPath,\n getKeys: getKeys,\n getSubPathKeys: getSubPathKeys\n };\n}","map":{"version":3,"names":["_toConsumableArray","_slicedToArray","React","useRef","useCallback","warning","nextSlice","PATH_SPLIT","getPathStr","keyPath","join","getPathKeys","keyPathStr","split","OVERFLOW_KEY","useKeyRecords","_React$useState","useState","_React$useState2","internalForceUpdate","key2pathRef","Map","path2keyRef","_React$useState3","_React$useState4","overflowKeys","setOverflowKeys","updateRef","destroyRef","forceUpdate","current","registerPath","key","process","env","NODE_ENV","has","concat","connectedPath","set","id","unregisterPath","delete","refreshOverflowKeys","keys","getKeyPath","eventKey","includeOverflow","fullPath","get","includes","unshift","isSubPathKey","pathKeys","filter","item","undefined","some","pathKey","pathKeyList","getKeys","length","push","getSubPathKeys","Set","forEach","startsWith","add","useEffect"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-menu/es/hooks/useKeyRecords.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useCallback } from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { nextSlice } from \"../utils/timeUtil\";\nvar PATH_SPLIT = '__RC_UTIL_PATH_SPLIT__';\nvar getPathStr = function getPathStr(keyPath) {\n return keyPath.join(PATH_SPLIT);\n};\nvar getPathKeys = function getPathKeys(keyPathStr) {\n return keyPathStr.split(PATH_SPLIT);\n};\nexport var OVERFLOW_KEY = 'rc-menu-more';\nexport default function useKeyRecords() {\n var _React$useState = React.useState({}),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n internalForceUpdate = _React$useState2[1];\n var key2pathRef = useRef(new Map());\n var path2keyRef = useRef(new Map());\n var _React$useState3 = React.useState([]),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n overflowKeys = _React$useState4[0],\n setOverflowKeys = _React$useState4[1];\n var updateRef = useRef(0);\n var destroyRef = useRef(false);\n var forceUpdate = function forceUpdate() {\n if (!destroyRef.current) {\n internalForceUpdate({});\n }\n };\n var registerPath = useCallback(function (key, keyPath) {\n // Warning for invalidate or duplicated `key`\n if (process.env.NODE_ENV !== 'production') {\n warning(!key2pathRef.current.has(key), \"Duplicated key '\".concat(key, \"' used in Menu by path [\").concat(keyPath.join(' > '), \"]\"));\n }\n\n // Fill map\n var connectedPath = getPathStr(keyPath);\n path2keyRef.current.set(connectedPath, key);\n key2pathRef.current.set(key, connectedPath);\n updateRef.current += 1;\n var id = updateRef.current;\n nextSlice(function () {\n if (id === updateRef.current) {\n forceUpdate();\n }\n });\n }, []);\n var unregisterPath = useCallback(function (key, keyPath) {\n var connectedPath = getPathStr(keyPath);\n path2keyRef.current.delete(connectedPath);\n key2pathRef.current.delete(key);\n }, []);\n var refreshOverflowKeys = useCallback(function (keys) {\n setOverflowKeys(keys);\n }, []);\n var getKeyPath = useCallback(function (eventKey, includeOverflow) {\n var fullPath = key2pathRef.current.get(eventKey) || '';\n var keys = getPathKeys(fullPath);\n if (includeOverflow && overflowKeys.includes(keys[0])) {\n keys.unshift(OVERFLOW_KEY);\n }\n return keys;\n }, [overflowKeys]);\n var isSubPathKey = useCallback(function (pathKeys, eventKey) {\n return pathKeys.filter(function (item) {\n return item !== undefined;\n }).some(function (pathKey) {\n var pathKeyList = getKeyPath(pathKey, true);\n return pathKeyList.includes(eventKey);\n });\n }, [getKeyPath]);\n var getKeys = function getKeys() {\n var keys = _toConsumableArray(key2pathRef.current.keys());\n if (overflowKeys.length) {\n keys.push(OVERFLOW_KEY);\n }\n return keys;\n };\n\n /**\n * Find current key related child path keys\n */\n var getSubPathKeys = useCallback(function (key) {\n var connectedPath = \"\".concat(key2pathRef.current.get(key)).concat(PATH_SPLIT);\n var pathKeys = new Set();\n _toConsumableArray(path2keyRef.current.keys()).forEach(function (pathKey) {\n if (pathKey.startsWith(connectedPath)) {\n pathKeys.add(path2keyRef.current.get(pathKey));\n }\n });\n return pathKeys;\n }, []);\n React.useEffect(function () {\n return function () {\n destroyRef.current = true;\n };\n }, []);\n return {\n // Register\n registerPath: registerPath,\n unregisterPath: unregisterPath,\n refreshOverflowKeys: refreshOverflowKeys,\n // Util\n isSubPathKey: isSubPathKey,\n getKeyPath: getKeyPath,\n getKeys: getKeys,\n getSubPathKeys: getSubPathKeys\n };\n}"],"mappings":"AAAA,OAAOA,kBAAkB,MAAM,8CAA8C;AAC7E,OAAOC,cAAc,MAAM,0CAA0C;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,EAAEC,WAAW,QAAQ,OAAO;AAC3C,OAAOC,OAAO,M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