|
| 1 | +import React, { useCallback, useState } from "react"; |
| 2 | +import styled from "@emotion/styled"; |
| 3 | +import { EditorPropertyThemeProvider, one } from "@editor-ui/property"; |
| 4 | +import { InfoSection } from "./section-info"; |
| 5 | +import { LayoutSection } from "./section-layout"; |
| 6 | +import { ColorsSection } from "./section-colors"; |
| 7 | +import { TypographySection } from "./section-typography"; |
| 8 | +import { useTargetContainer } from "hooks/use-target-node"; |
| 9 | +import { |
| 10 | + HorizontalHierarchyTreeVisualization, |
| 11 | + JsonTree, |
| 12 | +} from "@code-editor/devtools"; |
| 13 | +import useMeasure from "react-use-measure"; |
| 14 | + |
| 15 | +const figma_json_sortkeys = [ |
| 16 | + // essential |
| 17 | + "id", |
| 18 | + "name", |
| 19 | + "type", |
| 20 | + // geometry |
| 21 | + "x", |
| 22 | + "y", |
| 23 | + "width", |
| 24 | + "height", |
| 25 | + // hierarchical |
| 26 | + "parent", |
| 27 | + "children", |
| 28 | + // appearance |
| 29 | + "visible", |
| 30 | + "opacity", |
| 31 | + "blendMode", |
| 32 | + "isMask", |
| 33 | + // fills, strokes, effects |
| 34 | + "fills", |
| 35 | + "strokes", |
| 36 | + "strokeStyleId", |
| 37 | + "strokeWeight", |
| 38 | + "strokeMiterLimit", |
| 39 | + "strokeAlign", |
| 40 | + "strokeCap", |
| 41 | + "strokeJoin", |
| 42 | + "dashPattern", |
| 43 | + "effects", |
| 44 | + "effectStyleId", |
| 45 | +]; |
| 46 | + |
| 47 | +export function DebugInspector() { |
| 48 | + const [ref, { width }] = useMeasure(); |
| 49 | + const { target } = useTargetContainer(); |
| 50 | + // target |
| 51 | + |
| 52 | + return ( |
| 53 | + <div ref={ref}> |
| 54 | + <EditorPropertyThemeProvider theme={one.dark}> |
| 55 | + <InfoSection /> |
| 56 | + <GraphInspectionSection> |
| 57 | + <h5>document - api-response</h5> |
| 58 | + <JsonTree |
| 59 | + sortkeys={figma_json_sortkeys} |
| 60 | + backgroundColor="transparent" |
| 61 | + data={{}} |
| 62 | + /> |
| 63 | + </GraphInspectionSection> |
| 64 | + <GraphInspectionSection> |
| 65 | + <h5>document - mapped</h5> |
| 66 | + <JsonTree |
| 67 | + sortkeys={figma_json_sortkeys} |
| 68 | + backgroundColor="transparent" |
| 69 | + data={{}} |
| 70 | + /> |
| 71 | + </GraphInspectionSection> |
| 72 | + <GraphInspectionSection> |
| 73 | + <h5>token - figma-to-reflect</h5> |
| 74 | + <JsonTree |
| 75 | + sortkeys={figma_json_sortkeys} |
| 76 | + backgroundColor="transparent" |
| 77 | + data={target} |
| 78 | + /> |
| 79 | + </GraphInspectionSection> |
| 80 | + <GraphInspectionSection> |
| 81 | + <h5>widget - widget-tree</h5> |
| 82 | + <JsonTree |
| 83 | + sortkeys={figma_json_sortkeys} |
| 84 | + backgroundColor="transparent" |
| 85 | + data={{}} |
| 86 | + /> |
| 87 | + </GraphInspectionSection> |
| 88 | + <GraphInspectionSection> |
| 89 | + <h5>widget - framework-dedicated</h5> |
| 90 | + <JsonTree |
| 91 | + sortkeys={figma_json_sortkeys} |
| 92 | + backgroundColor="transparent" |
| 93 | + data={{}} |
| 94 | + /> |
| 95 | + </GraphInspectionSection> |
| 96 | + <GraphInspectionSection> |
| 97 | + <h5>graph</h5> |
| 98 | + {target && ( |
| 99 | + <div data-no-padding> |
| 100 | + <HorizontalHierarchyTreeVisualization |
| 101 | + width={width} |
| 102 | + height={400} |
| 103 | + tree={target} |
| 104 | + /> |
| 105 | + </div> |
| 106 | + )} |
| 107 | + </GraphInspectionSection> |
| 108 | + <LayoutSection /> |
| 109 | + <TypographySection /> |
| 110 | + <ColorsSection /> |
| 111 | + </EditorPropertyThemeProvider> |
| 112 | + </div> |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +function GraphInspectionSection({ children }: React.PropsWithChildren<{}>) { |
| 117 | + return <Section>{children}</Section>; |
| 118 | +} |
| 119 | + |
| 120 | +const Section = styled.section` |
| 121 | + display: flex; |
| 122 | + flex-direction: column; |
| 123 | +
|
| 124 | + margin: 16px 0; |
| 125 | +
|
| 126 | + h1, |
| 127 | + h2, |
| 128 | + h3, |
| 129 | + h4, |
| 130 | + h5, |
| 131 | + h6 { |
| 132 | + cursor: default; |
| 133 | + color: white; |
| 134 | + margin: 0; |
| 135 | + padding: 0; |
| 136 | + font-family: "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", |
| 137 | + monospace; |
| 138 | + } |
| 139 | +
|
| 140 | + /* apply padding to top level elements */ |
| 141 | + > * { |
| 142 | + padding: 14px; |
| 143 | + } |
| 144 | +
|
| 145 | + * { |
| 146 | + &[data-no-padding="true"] { |
| 147 | + padding: 0; |
| 148 | + } |
| 149 | + } |
| 150 | +
|
| 151 | + &:hover { |
| 152 | + background-color: rgba(255, 255, 255, 0.05); |
| 153 | + } |
| 154 | +
|
| 155 | + transition: background-color 0.2s ease-in-out; |
| 156 | +`; |
0 commit comments