Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 22x 119x 119x 119x 119x 119x 119x 119x 119x 119x 2x 117x 117x 117x 117x 117x 22x | import { useStore } from '../store';
import { useExpandsStore } from '../store/Expands';
import { BracketsClose } from '../symbol/';
import { type SectionElementResult } from '../store/Section';
import type * as CSS from 'csstype';
interface NestedCloseProps<T extends object> extends SectionElementResult<T> {
expandKey: string;
level: number;
}
export const NestedClose = <T extends object>(props: NestedCloseProps<T>) => {
const { keyName, value, expandKey, parentValue, level, keys = [] } = props;
const expands = useExpandsStore();
const { collapsed, shouldExpandNodeInitially } = useStore();
const defaultExpanded =
typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
const isExpanded = expands[expandKey] ?? (shouldExpandNodeInitially ? false : defaultExpanded);
const shouldExpand =
shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, { value, keys, level, keyName, parentValue });
Iif (expands[expandKey] === undefined && !shouldExpand) {
return null;
}
const len = Object.keys(value!).length;
if (isExpanded || len === 0) {
return null;
}
const style: CSS.Properties<string | number> = {
paddingLeft: 4,
};
const compProps = { keyName, value, keys, parentValue };
const isArray = Array.isArray(value);
const isMySet = value instanceof Set;
return (
<div style={style}>
<BracketsClose isBrackets={isArray || isMySet} {...compProps} isVisiable={true} />
</div>
);
};
NestedClose.displayName = 'JVR.NestedClose';
|