lingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
39 lines • 2.53 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
import { useLayoutEffect, useMemo, useState } from "preact/hooks";
import Model from "../../display/Model";
import ModelTreeItem from "./ModelTreeItem";
import getDisplayName from "../utils/getDisplayName";
import BaseTreeItem from "../component/treeItems/BaseTreeItem";
import CubeIcon from "./icons/CubeIcon";
import AnimationManager from "../../display/core/AnimatedObjectManager/AnimationManager";
import PlayIcon from "./icons/PlayIcon";
import { setSceneGraphExpanded } from "../../states/useSceneGraphExpanded";
import handleTreeItemClick from "../utils/handleTreeItemClick";
import useSelected from "./useSelected";
import useExpanded from "./useExpanded";
import useSceneGraphRefresh from "../hooks/useSceneGraphRefresh";
import moveSelected from "../../engine/hotkeys/moveSelected";
const TreeItem = ({ appendable, children, expandable }) => {
const refresh = useSceneGraphRefresh();
const appendableChildren = useMemo(() => appendable.children
? [...appendable.children].filter((item) => !item.$disableSceneGraph)
: undefined, [refresh]);
const selected = useSelected(appendable);
const expandedSignal = useExpanded(appendable);
const IconComponent = useMemo(() => {
if (appendable instanceof AnimationManager)
return PlayIcon;
return CubeIcon;
}, [appendable]);
const [name, setName] = useState("");
useLayoutEffect(() => {
setName(getDisplayName(appendable));
const handle = appendable.$events.on("name", () => setName(getDisplayName(appendable)));
return () => {
handle.cancel();
};
}, [appendable]);
return (_jsx(BaseTreeItem, { label: name, selected: selected, draggable: true, myDraggingItem: appendable, onDrop: () => moveSelected(appendable), expandedSignal: expandedSignal, onCollapse: () => setSceneGraphExpanded(undefined), expandable: expandable ?? !!appendableChildren?.length, onClick: (e) => handleTreeItemClick(e, appendable), onContextMenu: (e) => handleTreeItemClick(e, appendable, true), IconComponent: IconComponent, children: () => (_jsxs(_Fragment, { children: [appendableChildren?.map((childAppendable) => childAppendable instanceof Model ? (_jsx(ModelTreeItem, { appendable: childAppendable }, childAppendable.uuid)) : (_jsx(TreeItem, { appendable: childAppendable }, childAppendable.uuid))), children] })) }));
};
export default TreeItem;
//# sourceMappingURL=TreeItem.js.map