Skip to content

Commit

Permalink
Add screenshot feature
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed May 23, 2024
1 parent 8372aa2 commit 1bd7c51
Show file tree
Hide file tree
Showing 16 changed files with 392 additions and 182 deletions.
418 changes: 281 additions & 137 deletions client/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@devbookhq/splitter": "^1.4.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@hello-pangea/dnd": "^16.6.0",
"@monaco-editor/react": "^4.5.2",
"@mui/icons-material": "^5.15.10",
"@mui/lab": "^5.0.0-alpha.146",
Expand Down Expand Up @@ -49,7 +50,6 @@
"protocol": "file:../protocol",
"react": "^19.0.0-beta-26f2496093-20240514",
"react-async-hook": "^4.0.0",
"react-beautiful-dnd": "^13.1.1",
"react-colorful": "^5.6.1",
"react-d3-tree": "^3.6.1",
"react-dnd": "^16.0.1",
Expand Down
6 changes: 5 additions & 1 deletion client/src/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export function useSidebarBackground() {
);
}

function Divider2() {
return <Divider sx={{ mx: 2, my: 1 }} />;
}

export function Sidebar({ children }: { children?: ReactNode }) {
const { isPrimary } = useSyncStatus();
const { Content, produceRoot, root, setRoot, setOpen, tab, open } =
Expand Down Expand Up @@ -150,7 +154,7 @@ export function Sidebar({ children }: { children?: ReactNode }) {
)
.flatMap((c, i, cx) => [
!sm && !!i && c.color !== cx[i - 1].color && (
<Divider key={`divider-${i}`} sx={{ mx: 2, my: 1 }} />
<Divider2 key={`divider-${i}`} />
),
<Tab
onClick={() => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/client/internal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Dictionary, chain as _, entries, find, map } from "lodash";
import { PathfindingTask, Scheme } from "protocol/SolveTask";
import memoizee from "memoizee";
import { Scheme } from "protocol/SolveTask";
import url from "url-parse";
import { Transport } from "./Transport";
import memoizee from "memoizee";

const paths = import.meta.glob("/public/maps/*.grid", {
as: "url",
Expand Down
16 changes: 11 additions & 5 deletions client/src/components/generic/ListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ClearOutlined as DeleteIcon,
DragHandleOutlined,
EditOutlined as EditIcon,
LabelOutlined as LabelIcon,
} from "@mui/icons-material";
import {
Box,
Expand All @@ -19,12 +18,11 @@ import {
SxProps,
Theme,
Typography,
alpha,
useTheme,
} from "@mui/material";
import { defer, filter, map, sortBy, uniqBy } from "lodash";
import { nanoid as id } from "nanoid";
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
import { DragDropContext, Draggable, Droppable } from "@hello-pangea/dnd";

import {
CSSProperties,
Expand All @@ -41,7 +39,10 @@ import { useAcrylic, usePaper } from "theme";
import { Flex } from "./Flex";

export const DefaultListEditorInput = forwardRef(function StyledInputBase(
props: ComponentProps<typeof InputBase>,
{
onValueChange,
...props
}: ComponentProps<typeof InputBase> & { onValueChange?: (v: string) => void },
ref
) {
return (
Expand Down Expand Up @@ -381,7 +382,12 @@ export default function Editor<T>(props: Props<T>) {
}
>
<Box mt={getCategory ? -1 : 0}>
<Droppable droppableId="list">
<Droppable
droppableId="list"
isDropDisabled={false}
isCombineEnabled={false}
ignoreContainerClipping={true}
>
{(provided) => (
<div {...provided.droppableProps} ref={provided.innerRef}>
{(() => {
Expand Down
19 changes: 6 additions & 13 deletions client/src/components/layer-editor/LayerEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@ import {
startCase,
truncate,
} from "lodash";
import {
ForwardedRef,
ReactNode,
createElement,
forwardRef,
useEffect,
useMemo,
useState,
} from "react";
import { ReactNode, createElement, useEffect, useMemo, useState } from "react";
import { Layer } from "slices/layers";
import { useAcrylic, usePaper } from "theme";
import { usePaper } from "theme";

const compositeOperations = [
"color",
Expand Down Expand Up @@ -100,7 +92,10 @@ function useDraft<T>(
] as const;
}

function Component({ value, onValueChange: onChange }: LayerEditorProps) {
export function LayerEditor({
value,
onValueChange: onChange,
}: LayerEditorProps) {
const paper = usePaper();
const [draft, setDraft] = useDraft(value, onChange, 300, [
"name",
Expand Down Expand Up @@ -273,5 +268,3 @@ function Component({ value, onValueChange: onChange }: LayerEditorProps) {
</>
);
}

export const LayerEditor = forwardRef(Component);
4 changes: 2 additions & 2 deletions client/src/layers/trace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const controller = {
notify("Opening trace...");
try {
const output = readUploadedTrace(file);
return { trace: { ...(await output.read()) } };
return { trace: await output.read() };
} catch (e) {
console.error(e);
notify(`Error opening, ${get(e, "message")}`);
Expand Down Expand Up @@ -274,7 +274,7 @@ export const controller = {
const parsedTrace = await parseTrace();
produce((l) => {
set(l, "source.parsedTrace", parsedTrace);
// set(l, "viewKey", id());
set(l, "viewKey", id());
});
}
}, [loading, parseTrace]);
Expand Down
8 changes: 6 additions & 2 deletions client/src/pages/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ export function SettingsPage({ template: Page }: PageContentProps) {
const a = keys(mapParsers).map((c) => ({ key: c }));
type A = (typeof a)[number];

function Sink({ children }: { children?: ReactNode }) {
return children;
}

export function MapParserListEditor() {
return (
<Box sx={{ mx: -2 }}>
Expand All @@ -298,12 +302,12 @@ export function MapParserListEditor() {
addable={false}
deletable={false}
editor={(v) => (
<Box key={v.key}>
<Sink key={v.key}>
<ListItemText
primary={startCase(v.key)}
secondary={`Support for *.${v.key} maps`}
/>
</Box>
</Sink>
)}
icon={null}
value={a}
Expand Down
11 changes: 2 additions & 9 deletions client/src/pages/TreePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function TreeGraph({
});

const numParents: Dictionary<Set<string | number>> = {};
forEach(trace?.events, ({ id, pId, type }, i) => {
forEach(trace?.events, ({ id, pId }) => {
if (id && pId) {
numParents[id] = numParents[id] ?? new Set();
numParents[id].add(pId);
Expand Down Expand Up @@ -400,8 +400,6 @@ export function TreePage({ template: Page }: PageContentProps) {
const [trackedProperty, setTrackedProperty] = useState<string>("");

const trace = layer?.source?.trace?.content;
const lastModified = layer?.source?.trace?.lastModified;
const id = layer?.source?.trace?.key;

// Reset tracked property
useEffect(() => {
Expand All @@ -422,12 +420,7 @@ export function TreePage({ template: Page }: PageContentProps) {
return { events, current: findLast(events, (c) => c.step <= step) };
}, [selection, step]);

const params = useMemo(
() => ({ trace, mode }),
[trace, id, lastModified, mode]
);

const { result: tree, loading } = useTreeMemo(params, [params]);
const { result: tree, loading } = useTreeMemo({ trace, mode }, [key, mode]);

const settings = useMemo(
() =>
Expand Down
17 changes: 16 additions & 1 deletion client/src/pages/ViewportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BlurCircularOutlined,
CameraOutlined,
CenterFocusWeakOutlined,
LayersOutlined,
TimesOneMobiledataOutlined,
Expand All @@ -11,6 +12,7 @@ import { Flex } from "components/generic/Flex";
import { IconButtonWithTooltip } from "components/generic/IconButtonWithTooltip";
import { TraceRenderer } from "components/inspector/TraceRenderer";
import { useViewTreeContext } from "components/inspector/ViewTree";
import download from "downloadjs";
import { inferLayerName } from "layers/inferLayerName";
import {
Dictionary,
Expand All @@ -29,6 +31,7 @@ import { useLayers } from "slices/layers";
import { Renderer, useRenderers } from "slices/renderers";
import { PanelState } from "slices/view";
import { useAcrylic, usePaper } from "theme";
import { generateUsername as id } from "unique-username-generator";
import { PageContentProps } from "./PageMeta";
import { useRendererResolver } from "./useRendererResolver";

Expand Down Expand Up @@ -122,7 +125,6 @@ export function ViewportPage({ template: Page }: PageContentProps) {
label="Fit"
icon={<CenterFocusWeakOutlined />}
/>
{divider}
<IconButtonWithTooltip
color="primary"
disabled={!rendererInstance}
Expand All @@ -132,6 +134,19 @@ export function ViewportPage({ template: Page }: PageContentProps) {
icon={<TimesOneMobiledataOutlined />}
label="1 to 1"
/>
{divider}
<IconButtonWithTooltip
color="primary"
disabled={!rendererInstance}
onClick={async () => {
const a = await rendererInstance?.toDataUrl();
if (a) {
download(a, id("-"));
}
}}
icon={<CameraOutlined />}
label="capture-screenshot"
/>
</Stack>
</Stack>
</Box>
Expand Down
5 changes: 2 additions & 3 deletions client/src/services/BootstrapService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export function BootstrapService() {
const { load } = useWorkspace();
useAsync(async () => {
try {
const param = new URLSearchParams(location.search).get("workspace");
if (param) {
const workspace = decodeURIComponent(param);
const workspace = new URLSearchParams(location.search).get("workspace");
if (workspace && isWorkspace(workspace)) {
if (isWorkspace(workspace)) {
const name = workspace.split("/").pop() ?? workspace;
const a = await fetch(workspace);
Expand Down
4 changes: 2 additions & 2 deletions client/src/services/LayerService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSyncStatus } from "./SyncService";

function useLayerServices() {
const { isPrimary } = useSyncStatus();
const [{ layers }, setLayers] = useLayers();
const [{ layers }, setLayers, , c1] = useLayers();
return useMemo(() => {
return !isPrimary
? []
Expand All @@ -23,7 +23,7 @@ function useLayerServices() {
});
}
});
}, [layers, setLayers, isPrimary]);
}, [c1, setLayers, isPrimary]);
}

export function LayerService() {
Expand Down
3 changes: 2 additions & 1 deletion client/src/services/SettingsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export function SettingsService() {
useSettings();
const [, setUIState] = useUIState();
useEffect(() => {
if (!minimal && showOnStart && initialised) {
const workspace = new URLSearchParams(location.search).get("workspace");
if (!minimal && showOnStart && initialised && !workspace) {
setUIState(() => ({ fullscreenModal: showOnStart }));
}
}, [initialised, minimal]);
Expand Down
2 changes: 1 addition & 1 deletion client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig(({ mode }) => ({
plugins: [
react({
babel: {
plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
// plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
},
}),
viteTsconfigPaths(),
Expand Down
50 changes: 49 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"url": "https://github.com/ShortestPathLab/posthoc-app/issues"
},
"homepage": "posthoc.pathfinding.ai",
"dependencies": {},
"dependencies": {
"react": "^19.0.0-beta-26f2496093-20240514",
"react-dom": "^19.0.0-beta-26f2496093-20240514"
},
"type": "module"
}

0 comments on commit 1bd7c51

Please sign in to comment.