MCPcopy
hub / github.com/tinyplex/tinybase / Body

Function Body

src/ui-react-inspector/Body.tsx:36–122  ·  view source on GitHub ↗
({s}: StoreProp)

Source from the content-addressed store, hash-verified

34import {StoreView} from './StoreView.tsx';
35
36export const Body = ({s}: StoreProp) => {
37 const articleRef = useRef<HTMLElement>(null);
38 const idleCallbackRef = useRef<number>(0);
39 const [scrolled, setScrolled] = useState(false);
40 const {scrollLeft, scrollTop} = useValues(s);
41
42 useLayoutEffect(() => {
43 const article = articleRef.current;
44 if (article && !scrolled) {
45 const observer = new MutationObserver(() => {
46 if (
47 article.scrollWidth >=
48 mathFloor(scrollLeft as number) + article.clientWidth &&
49 article.scrollHeight >=
50 mathFloor(scrollTop as number) + article.clientHeight
51 ) {
52 article.scrollTo(scrollLeft as number, scrollTop as number);
53 }
54 });
55 observer.observe(article, {childList: true, subtree: true});
56 return () => observer.disconnect();
57 }
58 }, [scrolled, scrollLeft, scrollTop]);
59
60 const handleScroll = useCallback(
61 (event: SyntheticEvent<HTMLElement>) => {
62 const {scrollLeft, scrollTop} = event[CURRENT_TARGET];
63 cancelInspectorIdleCallback(idleCallbackRef.current);
64 idleCallbackRef.current = requestInspectorIdleCallback(() => {
65 setScrolled(true);
66 s.setPartialValues({scrollLeft, scrollTop});
67 });
68 },
69 [s],
70 );
71
72 const store = useStore();
73 const storeIds = useStoreIds();
74 const metrics = useMetrics();
75 const metricsIds = useMetricsIds();
76 const indexes = useIndexes();
77 const indexesIds = useIndexesIds();
78 const relationships = useRelationships();
79 const relationshipsIds = useRelationshipsIds();
80 const queries = useQueries();
81 const queriesIds = useQueriesIds();
82
83 return isUndefined(store) &&
84 arrayIsEmpty(storeIds) &&
85 isUndefined(metrics) &&
86 arrayIsEmpty(metricsIds) &&
87 isUndefined(indexes) &&
88 arrayIsEmpty(indexesIds) &&
89 isUndefined(relationships) &&
90 arrayIsEmpty(relationshipsIds) &&
91 isUndefined(queries) &&
92 arrayIsEmpty(queriesIds) ? (
93 <span className="warn">{NO_PROVIDED_OBJECTS_MESSAGE}</span>

Callers

nothing calls this directly

Calls 15

useValuesFunction · 0.90
useStoreFunction · 0.90
useStoreIdsFunction · 0.90
useMetricsFunction · 0.90
useMetricsIdsFunction · 0.90
useIndexesFunction · 0.90
useIndexesIdsFunction · 0.90
useRelationshipsFunction · 0.90
useRelationshipsIdsFunction · 0.90
useQueriesFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…