Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b3c28de
add 3d layout inspection
softmarshmallow Nov 17, 2022
4e6ae81
update 3d inspector
softmarshmallow Nov 19, 2022
6530163
zoom to fit - wip
softmarshmallow Nov 19, 2022
a87c859
fix import
softmarshmallow Nov 19, 2022
fdc837a
migrate task queue to workspace state
softmarshmallow Nov 19, 2022
168d37b
add shadow effect preview bg guide for better visibility
softmarshmallow Nov 19, 2022
b9ffc4c
update initial queue state
softmarshmallow Nov 19, 2022
f5b741e
Merge pull request #190 from gridaco/inspector/layout
softmarshmallow Nov 19, 2022
d3a1f9e
rename dir
softmarshmallow Nov 19, 2022
6761903
move dashboard & bitmap frame renderer to module package
softmarshmallow Nov 19, 2022
13b4c63
add dummy file path to match framework type and .ext
softmarshmallow Nov 19, 2022
de5b27d
.
softmarshmallow Nov 19, 2022
aaee582
add dnd to dashboard
softmarshmallow Nov 19, 2022
4035196
cleanup
softmarshmallow Nov 19, 2022
7356277
update task queue indicator style
softmarshmallow Nov 19, 2022
015f5e1
add initial independent dashboard state management
softmarshmallow Nov 19, 2022
233b058
update inspector layout
softmarshmallow Nov 19, 2022
850433b
improve inspector style & ux
softmarshmallow Nov 19, 2022
99ec111
organize
softmarshmallow Nov 19, 2022
455d4ab
add debouncer
softmarshmallow Nov 19, 2022
81681e3
update dashboard provider
softmarshmallow Nov 19, 2022
ac50ba6
add scene hierarchy to dashboard
softmarshmallow Nov 20, 2022
ec09f44
add jest
softmarshmallow Nov 20, 2022
e706a15
add grouping tests, update grouping logic with path tool
softmarshmallow Nov 20, 2022
e930ac9
add collapsible
softmarshmallow Nov 20, 2022
663379a
update scene card style
softmarshmallow Nov 20, 2022
ec6aed6
add id to sections
softmarshmallow Nov 20, 2022
12c4d9a
update preference open on code mode
softmarshmallow Nov 20, 2022
9084fca
update type field key
softmarshmallow Nov 20, 2022
7756589
update hash routing (dirty fix)
softmarshmallow Nov 20, 2022
1652798
fix build
softmarshmallow Nov 20, 2022
e3a7b22
add fold & unfold handler on dashboard
softmarshmallow Nov 20, 2022
0f3aff0
add collapsible to 3d inspector
softmarshmallow Nov 20, 2022
03534d2
add folder item card & new folder action
softmarshmallow Nov 20, 2022
a46a59d
update export
softmarshmallow Nov 20, 2022
aabd612
update bitmap renderer interface
softmarshmallow Nov 20, 2022
a347acc
split dasgboard card dnd management
softmarshmallow Nov 20, 2022
24a634b
wip move item
softmarshmallow Nov 21, 2022
faec643
wip - add selectto marquee
softmarshmallow Nov 22, 2022
edeca49
rd merge
softmarshmallow Nov 22, 2022
92fa1a8
rm log
softmarshmallow Nov 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
import React, { useState, useEffect } from "react";
import { ReflectSceneNode } from "@design-sdk/figma-node";
import type { ReflectSceneNode } from "@design-sdk/figma-node";
import type { FrameOptimizationFactors } from "@code-editor/canvas/frame";
import { blurred_bg_fill } from "./util";
import { blurred_bg_fill } from "@code-editor/canvas-renderer-core";
import { CircularProgress } from "@mui/material";
import { useFigmaImageService } from "scaffolds/editor";

interface BitmapPreviewService {
fetch: (
id: string,
options?: {
scale?: number;
}
) => Promise<string>;
}

const Context = React.createContext<BitmapPreviewService>(null);

const usefigmaBitmapPreviewService = () => {
const context = React.useContext(Context);
if (!context || typeof context.fetch !== "function") {
throw new Error(
"Bitmap service is not available. Are you sure you have an <FigmaNodeBitmapPreviewServiceProvider> above your consumers?"
);
}
return context;
};

export function FigmaNodeBitmapPreviewServiceProvider({
children,
service,
}: React.PropsWithChildren<{ service: BitmapPreviewService }>) {
return <Context.Provider value={service}>{children}</Context.Provider>;
}

type TargetSceneMeta = {
id: string;
filekey: ReflectSceneNode["filekey"];
name: string;
width: number;
height: number;
};

/**
* 1 = 1 scale
* s = 0.2 scale
*/
type ImageSizeVariant = "1" | "s";

export function FigmaStaticImageFrameView({
export function FigmaNodeBitmapView({
target,
zoom,
inViewport,
background,
}: {
target: ReflectSceneNode;
target: TargetSceneMeta;
} & FrameOptimizationFactors & {
background?: React.CSSProperties["background"];
}) {
const service = useFigmaImageService();
const service = usefigmaBitmapPreviewService();
const { filekey: _fk, id, width, height } = target;
const filekey = _fk as string;

Expand All @@ -44,19 +79,17 @@ export function FigmaStaticImageFrameView({

if (service) {
service
.fetch(id, {
debounce: true,
ensure: true,
})
.fetch(id)
.then((res) => {
const src = res[id];
const src = res;
set_image(src);
})
.catch(console.error);
}
}, [filekey, id, service, inViewport]);

const bg_color_str = blurred_bg_fill(target);
const bg_color_str =
"fills" in target ? blurred_bg_fill(target["fills"] as any) : "white";

return (
<div
Expand Down
4 changes: 4 additions & 0 deletions editor-packages/editor-canvas-renderer-bitmap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
FigmaNodeBitmapPreviewServiceProvider,
FigmaNodeBitmapView,
} from "./figma-node-bitmap-preview";
4 changes: 4 additions & 0 deletions editor-packages/editor-canvas-renderer-bitmap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@code-editor/canvas-renderer-bitmap",
"version": "0.0.0"
}
1 change: 1 addition & 0 deletions editor-packages/editor-canvas-renderer-core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./util";
4 changes: 4 additions & 0 deletions editor-packages/editor-canvas-renderer-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@code-editor/canvas-renderer-core",
"version": "0.0.0"
}
8 changes: 8 additions & 0 deletions editor-packages/editor-canvas-renderer-core/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { colorFromFills } from "@design-sdk/core/utils";
import type { Paint } from "@design-sdk/figma";

export const blurred_bg_fill = (fills: ReadonlyArray<Paint>) => {
const __bg = colorFromFills(fills);
const bg_color_str = __bg ? "#" + __bg.hex : "transparent";
return bg_color_str;
};
9 changes: 8 additions & 1 deletion editor-packages/editor-canvas/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
target_of_area,
boundingbox,
is_point_inside_box,
zoomToFit,
} from "../math";
import q from "@design-sdk/query";
import { LazyFrame } from "@code-editor/canvas/lazy-frame";
Expand Down Expand Up @@ -121,6 +122,11 @@ type CanvasFocusProps = {
focusRefreshkey?: string;
};

type CanvasFocusSnap = {
damping?: number;
bounds?: Box;
};

interface HovringNode {
node: ReflectSceneNode;
reason: "frame-title" | "raycast" | "external";
Expand Down Expand Up @@ -515,7 +521,8 @@ export function Canvas({
}}
onZoomToFit={() => {
setZoom(1);
// setOffset([newx, newy]); // TODO: set offset to center of the viewport
// const newoffset = zoomToFit(viewbound, offset, zoom, 1);
// setOffset(newoffset);
_canvas_state_store.saveLastTransform(cvtransform);
}}
onZooming={onZooming}
Expand Down
5 changes: 3 additions & 2 deletions editor-packages/editor-canvas/math/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./bounding-box";
export * from "./target-of-area";
export * from "./target-of-point";
export * from "./guide-spacing"
export * from "./guide-spacing";
export * from "./center-of";
export * from "./viewbound-edge-scrolling";
export * from "./viewbound-edge-scrolling";
export * from "./zoom-to-fit";
28 changes: 28 additions & 0 deletions editor-packages/editor-canvas/math/zoom-to-fit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Box, XY } from "../types";

/**
* this function provides a new offset for the canvas when user executes zoom-to-fit action, which resetting the canvas zoom to 1.
* the givven factors are.
* @param viewbound the viewbound of the canvas.
* @param offset the current offset of the canvas.
* @param scale the current scale of the canvas.
* @param newScale the new scale of the canvas. @default 1
*
* @returns the new offset of the canvas.
*
* @deprecated not tested
*/
export function zoomToFit(
viewbound: Box,
offset: XY,
scale: number,
newScale: number = 1
): XY {
const [x, y, w, h] = viewbound;
const [ox, oy] = offset;
const newOffset: XY = [
(x + w / 2) * (1 - newScale / scale) + ox,
(y + h / 2) * (1 - newScale / scale) + oy,
];
return newOffset;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from "react";
import { SquareIcon } from "@radix-ui/react-icons";
import {
DashboardItemCard,
DashboardItemCardProps,
} from "./dashboard-item-card";
import { DashboardFolderItem } from "../core";

function FolderCardPreview() {
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: 160,
width: 300,
boxSizing: "border-box",
}}
>
<img
style={{
height: "100%",
width: 120,
margin: "auto",
objectFit: "contain",
objectPosition: "center",
}}
src="/assets/mac-folder-icon.png"
/>
</div>
);

//
}

export type FolderCardProps = Omit<
DashboardItemCardProps,
"icon" | "preview" | "label"
> &
Omit<DashboardFolderItem, "$type">;

export const FolderCard = React.forwardRef(function (
{ name, ...props }: FolderCardProps,
ref: React.Ref<HTMLDivElement>
) {
return (
<DashboardItemCard
ref={ref}
id={props.id}
{...props}
label={name}
icon={<SquareIcon color="white" />}
preview={<FolderCardPreview />}
/>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { useRef } from "react";
import { FigmaNodeBitmapView } from "@code-editor/canvas-renderer-bitmap";
import { SceneNodeIcon } from "@code-editor/node-icons";
import { useInViewport } from "react-in-viewport";
import {
DashboardItemCard,
DashboardItemCardProps,
} from "./dashboard-item-card";

type SceneMeta = {
id: string;
filekey: string;
name: string;
width: number;
height: number;
type: any;
};

function SceneCardPreview({
maxWidth,
scene,
}: {
maxWidth: number;
scene: SceneMeta;
}) {
const visibilityRef = useRef();

const { enterCount } = useInViewport(visibilityRef);

// max allowed zoom = 1
const scale = Math.min(maxWidth / scene.width, 1);
const { height, type } = scene;

return (
<div
ref={visibilityRef}
style={{
height: height * scale,
width: maxWidth,
}}
>
{/* transformer */}
<div
id="view"
style={{
transform: `scale(${scale})`,
}}
>
<FigmaNodeBitmapView
background={"white"}
key={scene.id}
target={scene}
isPanning={false}
isZooming={false}
zoom={null}
inViewport={enterCount > 0}
focused={false}
/>
</div>
</div>
);

//
}

export interface SceneCardProps
extends Omit<DashboardItemCardProps, "icon" | "preview" | "label"> {
scene: SceneMeta;
}

export const SceneCard = React.forwardRef(function (
{ scene, ...props }: SceneCardProps,
ref: React.Ref<HTMLDivElement>
) {
return (
<DashboardItemCard
ref={ref}
id={props.id}
{...props}
label={scene.name}
icon={<SceneNodeIcon type={scene.type} color="white" />}
preview={<SceneCardPreview scene={scene} maxWidth={300} />}
/>
);
});
Loading