PromoCursed/node_modules/.cache/babel-loader/5ab2b3c16ed421d2fb5a91700a36172b67fdf4e95cb4fac90117585e97874cbd.json

1 line
6.7 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { COMMON_PROPS } from \"../common\";\n/**\n * Merge props provided `items` or context collected images\n */\nexport default function usePreviewItems(items) {\n // Context collection image data\n var _React$useState = React.useState({}),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n images = _React$useState2[0],\n setImages = _React$useState2[1];\n var registerImage = React.useCallback(function (id, data) {\n setImages(function (imgs) {\n return _objectSpread(_objectSpread({}, imgs), {}, _defineProperty({}, id, data));\n });\n return function () {\n setImages(function (imgs) {\n var cloneImgs = _objectSpread({}, imgs);\n delete cloneImgs[id];\n return cloneImgs;\n });\n };\n }, []);\n\n // items\n var mergedItems = React.useMemo(function () {\n // use `items` first\n if (items) {\n return items.map(function (item) {\n if (typeof item === 'string') {\n return {\n data: {\n src: item\n }\n };\n }\n var data = {};\n Object.keys(item).forEach(function (key) {\n if (['src'].concat(_toConsumableArray(COMMON_PROPS)).includes(key)) {\n data[key] = item[key];\n }\n });\n return {\n data: data\n };\n });\n }\n\n // use registered images secondly\n return Object.keys(images).reduce(function (total, id) {\n var _images$id = images[id],\n canPreview = _images$id.canPreview,\n data = _images$id.data;\n if (canPreview) {\n total.push({\n data: data,\n id: id\n });\n }\n return total;\n }, []);\n }, [items, images]);\n return [mergedItems, registerImage, !!items];\n}","map":{"version":3,"names":["_toConsumableArray","_defineProperty","_objectSpread","_slicedToArray","React","COMMON_PROPS","usePreviewItems","items","_React$useState","useState","_React$useState2","images","setImages","registerImage","useCallback","id","data","imgs","cloneImgs","mergedItems","useMemo","map","item","src","Object","keys","forEach","key","concat","includes","reduce","total","_images$id","canPreview","push"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-image/es/hooks/usePreviewItems.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { COMMON_PROPS } from \"../common\";\n/**\n * Merge props provided `items` or context collected images\n */\nexport default function usePreviewItems(items) {\n // Context collection image data\n var _React$useState = React.useState({}),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n images = _React$useState2[0],\n setImages = _React$useState2[1];\n var registerImage = React.useCallback(function (id, data) {\n setImages(function (imgs) {\n return _objectSpread(_objectSpread({}, imgs), {}, _defineProperty({}, id, data));\n });\n return function () {\n setImages(function (imgs) {\n var cloneImgs = _objectSpread({}, imgs);\n delete cloneImgs[id];\n return cloneImgs;\n });\n };\n }, []);\n\n // items\n var mergedItems = React.useMemo(function () {\n // use `items` first\n if (items) {\n return items.map(function (item) {\n if (typeof item === 'string') {\n return {\n data: {\n src: item\n }\n };\