UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

64 lines (63 loc) 2.35 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef, useMemo, useRef, useState } from "react"; import { context } from "./context.js"; import { getAllIds } from "./navigation/get-all-ids.js"; import { getIdsBetweenNodes } from "./utils/get-ids-between-nodes.js"; import { useCombinedRefs, useEvent } from "@1771technologies/lytenyte-core/yinternal"; export const TreeRoot = forwardRef((p, forwarded) => { const [panel, setPanel] = useState(null); const [expansions, onExpansionChange] = useState({}); const [selection, setSelections] = useState(() => new Set()); const ref = useCombinedRefs(setPanel, forwarded); const selectionPivotRef = useRef(null); const allIds = useEvent((el) => { if (p.getAllIds) return p.getAllIds(el); return getAllIds(el); }); const idsBetween = useEvent((left, right, panel) => { if (p.getIdsBetweenNodes) return p.getIdsBetweenNodes(left, right, panel); return getIdsBetweenNodes(left, right, panel); }); const onFocusChange = useEvent((el) => { p.onFocusChange?.(el); }); const value = useMemo(() => { return { panel, panelRef: ref, selectionMode: p.selectMode ?? "single", transitionEnterMs: p.transitionEnter ?? 0, transitionExitMs: p.transitionExit ?? 0, gridWrappedBranches: p.gridWrappedBranches ?? false, expansions: p.expansions ?? expansions, onExpansionChange: p.onExpansionChange ?? onExpansionChange, selection: p.selection ?? selection, onSelectionChange: p.onSelectionChange ?? setSelections, selectionPivotRef, expansionDefault: p.expansionDefault ?? false, onFocusChange, getAllIds: allIds, getIdsBetweenNodes: idsBetween, }; }, [ allIds, expansions, idsBetween, onFocusChange, p.expansionDefault, p.expansions, p.gridWrappedBranches, p.onExpansionChange, p.onSelectionChange, p.selectMode, p.selection, p.transitionEnter, p.transitionExit, panel, ref, selection, ]); return _jsx(context.Provider, { value: value, children: p.children }); });