UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

72 lines (71 loc) 2.31 kB
"use client"; import "core-js/modules/web.dom-collections.iterator.js"; import { isValidElement, useCallback, useContext, useRef } from 'react'; import pointer from '../utils/json-pointer'; import DataContext from '../DataContext/Context'; export default function ListAllProps(props) { const { log, generateRef, filterData, children } = props || {}; const { fieldInternalsRef, valueInternalsRef, data, hasContext } = useContext(DataContext); const dataRef = useRef({}); dataRef.current = data; const generate = useCallback(() => { const propsOfFields = Object.entries((fieldInternalsRef === null || fieldInternalsRef === void 0 ? void 0 : fieldInternalsRef.current) || {}).reduce((acc, _ref) => { let [path, { props }] = _ref; if (path.startsWith('/')) { const propertyValue = {}; for (const prop in props) { if (props[prop] !== undefined && typeof props[prop] !== 'function' && !isValidElement(props[prop])) { propertyValue[prop] = props[prop]; } } if ((filterData === null || filterData === void 0 ? void 0 : filterData[path]) !== false) { pointer.set(acc, path, propertyValue); } } return acc; }, {}); const propsOfValues = Object.entries((valueInternalsRef === null || valueInternalsRef === void 0 ? void 0 : valueInternalsRef.current) || {}).reduce((acc, _ref2) => { let [path, { props }] = _ref2; if (path.startsWith('/')) { const propertyValue = {}; for (const prop in props) { if (props[prop] !== undefined && typeof props[prop] !== 'function' && !isValidElement(props[prop])) { propertyValue[prop] = props[prop]; } } if ((filterData === null || filterData === void 0 ? void 0 : filterData[path]) !== false) { pointer.set(acc, path, propertyValue); } } return acc; }, {}); return { propsOfFields, propsOfValues }; }, [fieldInternalsRef, filterData, valueInternalsRef]); if (hasContext) { if (log) { console.log(generate()); } if (generateRef) { generateRef.current = generate; } } return children; } //# sourceMappingURL=ListAllProps.js.map