bf8cd42aff56cc94fc8ef9f0f84189b0.json 12.3 KB
{"ast":null,"code":"function _slicedToArray(arr, i) {\n  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();\n}\n\nfunction _nonIterableRest() {\n  throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\n\nfunction _unsupportedIterableToArray(o, minLen) {\n  if (!o) return;\n  if (typeof o === \"string\") return _arrayLikeToArray(o, minLen);\n  var n = Object.prototype.toString.call(o).slice(8, -1);\n  if (n === \"Object\" && o.constructor) n = o.constructor.name;\n  if (n === \"Map\" || n === \"Set\") return Array.from(o);\n  if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);\n}\n\nfunction _arrayLikeToArray(arr, len) {\n  if (len == null || len > arr.length) len = arr.length;\n\n  for (var i = 0, arr2 = new Array(len); i < len; i++) {\n    arr2[i] = arr[i];\n  }\n\n  return arr2;\n}\n\nfunction _iterableToArrayLimit(arr, i) {\n  if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return;\n  var _arr = [];\n  var _n = true;\n  var _d = false;\n  var _e = undefined;\n\n  try {\n    for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n      _arr.push(_s.value);\n\n      if (i && _arr.length === i) break;\n    }\n  } catch (err) {\n    _d = true;\n    _e = err;\n  } finally {\n    try {\n      if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n    } finally {\n      if (_d) throw _e;\n    }\n  }\n\n  return _arr;\n}\n\nfunction _arrayWithHoles(arr) {\n  if (Array.isArray(arr)) return arr;\n}\n\nimport * as React from 'react';\nimport { useRef } from 'react';\nimport findDOMNode from \"rc-util/es/Dom/findDOMNode\";\nimport CacheMap from '../utils/CacheMap';\nexport default function useHeights(getKey, onItemAdd, onItemRemove) {\n  var _React$useState = React.useState(0),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      updatedMark = _React$useState2[0],\n      setUpdatedMark = _React$useState2[1];\n\n  var instanceRef = useRef(new Map());\n  var heightsRef = useRef(new CacheMap());\n  var heightUpdateIdRef = useRef(0);\n\n  function collectHeight() {\n    heightUpdateIdRef.current += 1;\n    var currentId = heightUpdateIdRef.current;\n    Promise.resolve().then(function () {\n      // Only collect when it's latest call\n      if (currentId !== heightUpdateIdRef.current) return;\n      instanceRef.current.forEach(function (element, key) {\n        if (element && element.offsetParent) {\n          var htmlElement = findDOMNode(element);\n          var offsetHeight = htmlElement.offsetHeight;\n\n          if (heightsRef.current.get(key) !== offsetHeight) {\n            heightsRef.current.set(key, htmlElement.offsetHeight);\n          }\n        }\n      }); // Always trigger update mark to tell parent that should re-calculate heights when resized\n\n      setUpdatedMark(function (c) {\n        return c + 1;\n      });\n    });\n  }\n\n  function setInstanceRef(item, instance) {\n    var key = getKey(item);\n    var origin = instanceRef.current.get(key);\n\n    if (instance) {\n      instanceRef.current.set(key, instance);\n      collectHeight();\n    } else {\n      instanceRef.current.delete(key);\n    } // Instance changed\n\n\n    if (!origin !== !instance) {\n      if (instance) {\n        onItemAdd === null || onItemAdd === void 0 ? void 0 : onItemAdd(item);\n      } else {\n        onItemRemove === null || onItemRemove === void 0 ? void 0 : onItemRemove(item);\n      }\n    }\n  }\n\n  return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-virtual-list/es/hooks/useHeights.js"],"names":["_slicedToArray","arr","i","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","o","minLen","_arrayLikeToArray","n","Object","prototype","toString","call","slice","constructor","name","Array","from","test","len","length","arr2","Symbol","iterator","_arr","_n","_d","_e","undefined","_i","_s","next","done","push","value","err","isArray","React","useRef","findDOMNode","CacheMap","useHeights","getKey","onItemAdd","onItemRemove","_React$useState","useState","_React$useState2","updatedMark","setUpdatedMark","instanceRef","Map","heightsRef","heightUpdateIdRef","collectHeight","current","currentId","Promise","resolve","then","forEach","element","key","offsetParent","htmlElement","offsetHeight","get","set","c","setInstanceRef","item","instance","origin","delete"],"mappings":"AAAA,SAASA,cAAT,CAAwBC,GAAxB,EAA6BC,CAA7B,EAAgC;AAAE,SAAOC,eAAe,CAACF,GAAD,CAAf,IAAwBG,qBAAqB,CAACH,GAAD,EAAMC,CAAN,CAA7C,IAAyDG,2BAA2B,CAACJ,GAAD,EAAMC,CAAN,CAApF,IAAgGI,gBAAgB,EAAvH;AAA4H;;AAE9J,SAASA,gBAAT,GAA4B;AAAE,QAAM,IAAIC,SAAJ,CAAc,2IAAd,CAAN;AAAmK;;AAEjM,SAASF,2BAAT,CAAqCG,CAArC,EAAwCC,MAAxC,EAAgD;AAAE,MAAI,CAACD,CAAL,EAAQ;AAAQ,MAAI,OAAOA,CAAP,KAAa,QAAjB,EAA2B,OAAOE,iBAAiB,CAACF,CAAD,EAAIC,MAAJ,CAAxB;AAAqC,MAAIE,CAAC,GAAGC,MAAM,CAACC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BP,CAA/B,EAAkCQ,KAAlC,CAAwC,CAAxC,EAA2C,CAAC,CAA5C,CAAR;AAAwD,MAAIL,CAAC,KAAK,QAAN,IAAkBH,CAAC,CAACS,WAAxB,EAAqCN,CAAC,GAAGH,CAAC,CAACS,WAAF,CAAcC,IAAlB;AAAwB,MAAIP,CAAC,KAAK,KAAN,IAAeA,CAAC,KAAK,KAAzB,EAAgC,OAAOQ,KAAK,CAACC,IAAN,CAAWZ,CAAX,CAAP;AAAsB,MAAIG,CAAC,KAAK,WAAN,IAAqB,2CAA2CU,IAA3C,CAAgDV,CAAhD,CAAzB,EAA6E,OAAOD,iBAAiB,CAACF,CAAD,EAAIC,MAAJ,CAAxB;AAAsC;;AAEha,SAASC,iBAAT,CAA2BT,GAA3B,EAAg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AAY,KAAK,KAAK,CAA/C,GAAmD,KAAK,CAAxD,GAA4DA,YAAY,CAAC0B,IAAD,CAAxE;AACD;AACF;AACF;;AAED,SAAO,CAACD,cAAD,EAAiBf,aAAjB,EAAgCF,UAAU,CAACG,OAA3C,EAAoDP,WAApD,CAAP;AACD","sourcesContent":["function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nimport * as React from 'react';\nimport { useRef } from 'react';\nimport findDOMNode from \"rc-util/es/Dom/findDOMNode\";\nimport CacheMap from '../utils/CacheMap';\nexport default function useHeights(getKey, onItemAdd, onItemRemove) {\n  var _React$useState = React.useState(0),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      updatedMark = _React$useState2[0],\n      setUpdatedMark = _React$useState2[1];\n\n  var instanceRef = useRef(new Map());\n  var heightsRef = useRef(new CacheMap());\n  var heightUpdateIdRef = useRef(0);\n\n  function collectHeight() {\n    heightUpdateIdRef.current += 1;\n    var currentId = heightUpdateIdRef.current;\n    Promise.resolve().then(function () {\n      // Only collect when it's latest call\n      if (currentId !== heightUpdateIdRef.current) return;\n      instanceRef.current.forEach(function (element, key) {\n        if (element && element.offsetParent) {\n          var htmlElement = findDOMNode(element);\n          var offsetHeight = htmlElement.offsetHeight;\n\n          if (heightsRef.current.get(key) !== offsetHeight) {\n            heightsRef.current.set(key, htmlElement.offsetHeight);\n          }\n        }\n      }); // Always trigger update mark to tell parent that should re-calculate heights when resized\n\n      setUpdatedMark(function (c) {\n        return c + 1;\n      });\n    });\n  }\n\n  function setInstanceRef(item, instance) {\n    var key = getKey(item);\n    var origin = instanceRef.current.get(key);\n\n    if (instance) {\n      instanceRef.current.set(key, instance);\n      collectHeight();\n    } else {\n      instanceRef.current.delete(key);\n    } // Instance changed\n\n\n    if (!origin !== !instance) {\n      if (instance) {\n        onItemAdd === null || onItemAdd === void 0 ? void 0 : onItemAdd(item);\n      } else {\n        onItemRemove === null || onItemRemove === void 0 ? void 0 : onItemRemove(item);\n      }\n    }\n  }\n\n  return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];\n}"]},"metadata":{},"sourceType":"module"}