diff --git a/desktop/plugins/public/ui-debugger/components/Tree.tsx b/desktop/plugins/public/ui-debugger/components/Tree.tsx deleted file mode 100644 index c02292cb6..000000000 --- a/desktop/plugins/public/ui-debugger/components/Tree.tsx +++ /dev/null @@ -1,306 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -import {Id, UINode} from '../types'; -import React, {useEffect, useMemo, useRef} from 'react'; -import { - Tree as ComplexTree, - ControlledTreeEnvironment, - TreeItem, - TreeInformation, - TreeItemRenderContext, - InteractionMode, - TreeEnvironmentRef, -} from 'react-complex-tree'; - -import {plugin} from '../index'; -import { - usePlugin, - useValue, - HighlightManager, - HighlightProvider, - useHighlighter, - theme, - styled, -} from 'flipper-plugin'; - -import {head} from 'lodash'; -import {Dropdown, Menu} from 'antd'; -import {UIDebuggerMenuItem} from './util/UIDebuggerMenuItem'; - -export function Tree(props: { - rootId: Id; - nodes: Map; - selectedNode?: Id; - onSelectNode: (id: Id) => void; -}) { - const instance = usePlugin(plugin); - const expandedItems = useValue(instance.uiState.expandedNodes); - const focused = useValue(instance.uiState.focusedNode); - - const items = useMemo( - () => toComplexTree(focused || props.rootId, props.nodes), - [focused, props.nodes, props.rootId], - ); - const hoveredNodes = useValue(instance.uiState.hoveredNodes); - const treeEnvRef = useRef(); - - const searchTerm = useValue(instance.uiState.searchTerm); - - useEffect(() => { - //this makes the keyboard arrow controls work always, even when using the visualiser - treeEnvRef.current?.focusTree('tree', true); - }, [props.selectedNode]); - - return ( -
{ - instance.uiState.hoveredNodes.set([]); - }} - style={ - { - '--rct-color-tree-bg': theme.white, - '--rct-color-tree-focus-outline': theme.dividerColor, - '--rct-color-focustree-item-focused-border': - theme.selectionBackgroundColor, - '--rct-color-focustree-item-selected-bg': - theme.selectionBackgroundColor, - '--rct-color-nonfocustree-item-selected-bg': - theme.selectionBackgroundColor, - } as React.CSSProperties - }> - - item.data.name} - canRename={false} - canDragAndDrop={false} - viewState={{ - tree: { - focusedItem: head(hoveredNodes), - expandedItems: [...expandedItems], - selectedItems: props.selectedNode ? [props.selectedNode] : [], - }, - }} - onFocusItem={(item) => { - instance.uiState.hoveredNodes.set([item.index]); - }} - onExpandItem={(item) => { - instance.uiState.expandedNodes.update((draft) => { - draft.add(item.index); - }); - }} - onCollapseItem={(item) => - instance.uiState.expandedNodes.update((draft) => { - draft.delete(item.index); - }) - } - renderItem={renderItem} - onSelectItems={(items) => props.onSelectNode(items[0])} - defaultInteractionMode={{ - mode: 'custom', - extends: InteractionMode.DoubleClickItemToExpand, - createInteractiveElementProps: ( - item, - treeId, - actions, - renderFlags, - ) => ({ - onClick: () => { - if (renderFlags.isSelected) { - actions.unselectItem(); - } else { - actions.selectItem(); - } - }, - - onMouseOver: () => { - if (!instance.uiState.isContextMenuOpen.get()) { - instance.uiState.hoveredNodes.set([item.index]); - } - }, - }), - }}> - - - -
- ); -} - -//copied from https://github.com/lukasbach/react-complex-tree/blob/e3dcc435933284376a0fc6e3cc651e67ead678b5/packages/core/src/renderers/createDefaultRenderers.tsx -const cx = (...classNames: Array) => - classNames.filter((cn) => !!cn).join(' '); -const renderDepthOffset = 5; - -const DecorationImage = styled.img({ - height: 12, - marginRight: 5, - width: 12, -}); -function defaultIcon(node: UINode) { - if (node.tags.includes('Litho')) { - return ; - } -} - -function renderItem({ - item, - depth, - children, - arrow, - context, -}: { - item: TreeItem; - depth: number; - children: React.ReactNode | null; - title: React.ReactNode; - arrow: React.ReactNode; - context: TreeItemRenderContext; - info: TreeInformation; -}) { - return ( -
  • - -
    - {arrow} -
    - {defaultIcon(item.data)} - -
    -
    -
    - - {children} -
  • - ); -} - -type ContextMenuProps = {node: UINode; id: Id; title: string}; - -const ContextMenu: React.FC = ({id, title, children}) => { - const instance = usePlugin(plugin); - const focusedNode = instance.uiState.focusedNode.get(); - - return ( - { - instance.uiState.isContextMenuOpen.set(visible); - }} - overlay={() => ( - - {focusedNode !== head(instance.uiState.hoveredNodes.get()) && ( - { - instance.uiState.focusedNode.set(id); - }} - /> - )} - - {focusedNode && ( - { - instance.uiState.focusedNode.set(undefined); - }} - /> - )} - - )} - trigger={['contextMenu']}> -
    {children}
    -
    - ); -}; - -function HighlightedText(props: {text: string}) { - const highlightManager: HighlightManager = useHighlighter(); - return {highlightManager.render(props.text)}; -} - -const FakeNode: UINode = { - id: 'Fakeroot', - qualifiedName: 'Fakeroot', - name: 'Fakeroot', - inlineAttributes: {}, - children: [], - attributes: {}, - bounds: {x: 0, y: 0, height: 0, width: 0}, - tags: [], -}; - -function toComplexTree( - root: Id, - nodes: Map, -): Record> { - const res: Record> = {}; - for (const node of nodes.values()) { - res[node.id] = { - index: node.id, - children: node.children, - data: node, - hasChildren: node.children.length > 0, - }; - } - - //the library doesnt render the root node so we insert a fake one which will never be rendered - //https://github.com/lukasbach/react-complex-tree/issues/42 - res[FakeNode.id] = { - index: FakeNode.id, - children: [root], - hasChildren: true, - data: FakeNode, - }; - return res; -} diff --git a/desktop/plugins/public/ui-debugger/components/main.tsx b/desktop/plugins/public/ui-debugger/components/main.tsx index 05c8512e6..d072746d0 100644 --- a/desktop/plugins/public/ui-debugger/components/main.tsx +++ b/desktop/plugins/public/ui-debugger/components/main.tsx @@ -13,12 +13,11 @@ import {DetailSidebar, Layout, usePlugin, useValue} from 'flipper-plugin'; import {useHotkeys} from 'react-hotkeys-hook'; import {Id, Metadata, MetadataId, UINode} from '../types'; import {PerfStats} from './PerfStats'; -import {Tree} from './Tree'; import {Visualization2D} from './Visualization2D'; import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers'; import {Inspector} from './sidebar/Inspector'; import {Controls} from './Controls'; -import {Input, Spin} from 'antd'; +import {Spin} from 'antd'; import FeedbackRequest from './fb-stubs/feedback'; import {Tree2} from './Tree2'; diff --git a/desktop/plugins/public/ui-debugger/index.tsx b/desktop/plugins/public/ui-debugger/index.tsx index fc7be0d32..3598d1e08 100644 --- a/desktop/plugins/public/ui-debugger/index.tsx +++ b/desktop/plugins/public/ui-debugger/index.tsx @@ -23,7 +23,6 @@ import { Snapshot, UINode, } from './types'; -import './node_modules/react-complex-tree/lib/style.css'; import {Draft} from 'immer'; type SnapshotInfo = {nodeId: Id; base64Image: Snapshot}; diff --git a/desktop/plugins/public/ui-debugger/package.json b/desktop/plugins/public/ui-debugger/package.json index f49560a1c..42af7acea 100644 --- a/desktop/plugins/public/ui-debugger/package.json +++ b/desktop/plugins/public/ui-debugger/package.json @@ -15,7 +15,6 @@ "dependencies": { "lodash": "^4.17.21", "react-color": "^2.19.3", - "react-complex-tree" : "^1.1.11", "react-hotkeys-hook": "^3.4.7" }, "bugs": { diff --git a/desktop/plugins/public/ui-debugger/types.tsx b/desktop/plugins/public/ui-debugger/types.tsx index 37f916fbf..3dd076e5c 100644 --- a/desktop/plugins/public/ui-debugger/types.tsx +++ b/desktop/plugins/public/ui-debugger/types.tsx @@ -7,8 +7,6 @@ * @format */ -import {TreeItemIndex} from 'react-complex-tree'; - export type Events = { init: InitEvent; subtreeUpdate: SubtreeUpdateEvent; @@ -121,7 +119,7 @@ export type Color = { }; export type Snapshot = string; -export type Id = number | TreeItemIndex; +export type Id = number; export type MetadataId = number; export type TreeState = {expandedNodes: Id[]}; diff --git a/desktop/plugins/public/yarn.lock b/desktop/plugins/public/yarn.lock index 9d8cf2472..573cd4398 100644 --- a/desktop/plugins/public/yarn.lock +++ b/desktop/plugins/public/yarn.lock @@ -1644,11 +1644,6 @@ react-color@^2.19.3: reactcss "^1.2.0" tinycolor2 "^1.4.1" -react-complex-tree@^1.1.11: - version "1.1.11" - resolved "https://registry.yarnpkg.com/react-complex-tree/-/react-complex-tree-1.1.11.tgz#430520d12908b033a4b278be0dfd8d0aa6654a85" - integrity sha512-hAkm2ZRH2lwZd7NEzZMQI8db/jI5T2fJsbwHX8oNPrG/WPdakc3eNpm2A4gLk2SBa88HeU6mnauVXg6Q6fJLow== - react-devtools-core@^4.26.1: version "4.26.1" resolved "https://registry.yarnpkg.com/react-devtools-core/-/react-devtools-core-4.26.1.tgz#2893fea58089be64c5356d5bd0eebda8d1bbf317"