Skip to content

Commit da89ecd

Browse files
Merge pull request #186 from gridaco/staging
2022.11 W45 Release
2 parents 1841ab1 + f2c9255 commit da89ecd

130 files changed

Lines changed: 4641 additions & 1225 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

editor-packages/editor-canvas/canvas-event-target/canvas-event-target.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import { useGesture } from "@use-gesture/react";
33
import type {
44
Handler,
@@ -39,24 +39,28 @@ export function CanvasEventTarget({
3939
onDrag,
4040
onDragStart,
4141
onDragEnd,
42+
cursor,
4243
children,
43-
}: {
44-
onZoomToFit?: () => void;
45-
onPanning: OnPanningHandler;
46-
onPanningStart: OnPanningHandler;
47-
onPanningEnd: OnPanningHandler;
48-
onZooming: OnZoomingHandler;
49-
onZoomingStart: OnZoomingHandler;
50-
onZoomingEnd: OnZoomingHandler;
51-
onPointerMove: OnPointerMoveHandler;
52-
onPointerMoveStart: OnPointerMoveHandler;
53-
onPointerMoveEnd: OnPointerMoveHandler;
54-
onPointerDown: OnPointerDownHandler;
55-
onDrag: OnDragHandler;
56-
onDragStart: OnDragHandler;
57-
onDragEnd: OnDragHandler;
58-
children?: React.ReactNode;
59-
}) {
44+
}: React.PropsWithChildren<
45+
{
46+
onZoomToFit?: () => void;
47+
onPanning: OnPanningHandler;
48+
onPanningStart: OnPanningHandler;
49+
onPanningEnd: OnPanningHandler;
50+
onZooming: OnZoomingHandler;
51+
onZoomingStart: OnZoomingHandler;
52+
onZoomingEnd: OnZoomingHandler;
53+
onPointerMove: OnPointerMoveHandler;
54+
onPointerMoveStart: OnPointerMoveHandler;
55+
onPointerMoveEnd: OnPointerMoveHandler;
56+
onPointerDown: OnPointerDownHandler;
57+
onDrag: OnDragHandler;
58+
onDragStart: OnDragHandler;
59+
onDragEnd: OnDragHandler;
60+
} & {
61+
cursor?: React.CSSProperties["cursor"];
62+
}
63+
>) {
6064
const interactionEventTargetRef = useRef();
6165

6266
const [isSpacebarPressed, setIsSpacebarPressed] = useState(false);
@@ -210,7 +214,7 @@ export function CanvasEventTarget({
210214
inset: 0,
211215
overflow: "hidden",
212216
touchAction: "none",
213-
cursor: isSpacebarPressed ? "grab" : "default",
217+
cursor: isSpacebarPressed ? "grab" : cursor,
214218
userSelect: "none",
215219
WebkitUserSelect: "none",
216220
}}

editor-packages/editor-canvas/canvas/canvas.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ interface GroupingOptions {
8181
disabled?: boolean;
8282
}
8383

84+
interface CanvasCursorOptions {
85+
cursor?: React.CSSProperties["cursor"];
86+
}
87+
8488
const default_canvas_preferences: CanvsPreferences = {
8589
can_highlight_selected_layer: false,
8690
marquee: {
@@ -91,6 +95,18 @@ const default_canvas_preferences: CanvsPreferences = {
9195
},
9296
};
9397

98+
type CanvasProps = CanvasCursorOptions & {
99+
viewbound: Box;
100+
onSelectNode?: (...node: ReflectSceneNode[]) => void;
101+
onMoveNodeStart?: (...node: string[]) => void;
102+
onMoveNode?: (delta: XY, ...node: string[]) => void;
103+
onMoveNodeEnd?: (delta: XY, ...node: string[]) => void;
104+
onClearSelection?: () => void;
105+
} & CanvasCustomRenderers &
106+
CanvasState & {
107+
config?: CanvsPreferences;
108+
};
109+
94110
interface HovringNode {
95111
node: ReflectSceneNode;
96112
reason: "frame-title" | "raycast" | "external";
@@ -113,18 +129,9 @@ export function Canvas({
113129
readonly = true,
114130
config = default_canvas_preferences,
115131
backgroundColor,
132+
cursor,
116133
...props
117-
}: {
118-
viewbound: Box;
119-
onSelectNode?: (...node: ReflectSceneNode[]) => void;
120-
onMoveNodeStart?: (...node: string[]) => void;
121-
onMoveNode?: (delta: XY, ...node: string[]) => void;
122-
onMoveNodeEnd?: (delta: XY, ...node: string[]) => void;
123-
onClearSelection?: () => void;
124-
} & CanvasCustomRenderers &
125-
CanvasState & {
126-
config?: CanvsPreferences;
127-
}) {
134+
}: CanvasProps) {
128135
useEffect(() => {
129136
if (transformIntitialized) {
130137
return;
@@ -430,8 +437,9 @@ export function Canvas({
430437
<>
431438
<ContextMenuProvider>
432439
<Container
433-
width={viewbound[2] - viewbound[0]}
434-
height={viewbound[3] - viewbound[1]}
440+
// todo: viewbound not accurate.
441+
// width={viewbound[2] - viewbound[0]}
442+
// height={viewbound[3] - viewbound[1]}
435443
>
436444
<CanvasEventTarget
437445
onPanning={onPanning}
@@ -462,6 +470,7 @@ export function Canvas({
462470
onDragStart={onDragStart}
463471
onDrag={onDrag}
464472
onDragEnd={onDragEnd}
473+
cursor={cursor}
465474
>
466475
<HudSurface
467476
offset={nonscaled_offset}
@@ -505,10 +514,12 @@ export function Canvas({
505514
);
506515
}
507516

508-
const Container = styled.div<{ width: number; height: number }>`
509-
width: ${(p) => p.width}px;
510-
height: ${(p) => p.height}px;
517+
const Container = styled.div`
518+
min-width: 240px;
519+
min-height: 240px;
511520
`;
521+
/* width: ${(p) => p.width}px; */
522+
/* height: ${(p) => p.height}px; */
512523

513524
/**
514525
* 1. container positioning guide (static per selection)

editor-packages/editor-canvas/hud/hud-surface.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ function PositionGuides({
168168
}) {
169169
return (
170170
<>
171-
{guides.map((guide) => {
172-
return <PositionGuide a={guide.a} b={guide.b} zoom={zoom} />;
171+
{guides.map((guide, i) => {
172+
return <PositionGuide key={i} a={guide.a} b={guide.b} zoom={zoom} />;
173173
})}
174174
</>
175175
);

editor-packages/editor-canvas/overlay/guide-positioning/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ function SpacingMeterLabel({
135135
return (
136136
<MeterLabel
137137
label={(Math.round(length * 10) / 10).toString()}
138-
background={"orange"}
138+
background={"darkorange"}
139139
x={tx}
140140
y={ty}
141+
weight={"bolder"}
141142
margin={4}
142143
anchor={__label_anchor_map[side]}
143144
zoom={zoom}
@@ -173,7 +174,7 @@ function GuideLine({
173174
direction,
174175
length,
175176
width,
176-
color = "orange",
177+
color = "darkorange",
177178
dashed,
178179
}: GuideLineProps) {
179180
const tl = length * zoom;
@@ -230,7 +231,7 @@ function SpacingGuideLine({
230231
length={length}
231232
direction={rotation}
232233
width={1}
233-
color={"orange"}
234+
color={"darkorange"}
234235
/>
235236
);
236237
}
@@ -257,7 +258,7 @@ function AuxiliaryLine({
257258
direction={rotation}
258259
width={1}
259260
dashed
260-
color={"orange"}
261+
color={"darkorange"}
261262
/>
262263
);
263264
}

editor-packages/editor-canvas/overlay/handle.tsx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
import React, { forwardRef } from "react";
22
import * as k from "./k";
33

4-
export const Handle = forwardRef(function ({
5-
color,
6-
anchor,
7-
box,
8-
outlineWidth = 1,
9-
outlineColor = "transparent",
10-
size = 4,
11-
borderRadius = 0,
12-
cursor,
13-
readonly,
14-
}: {
15-
color: string;
16-
/**
17-
* the width of the outline
18-
*/
19-
outlineWidth?: number;
20-
outlineColor?: string;
21-
size: number;
22-
anchor: "nw" | "ne" | "sw" | "se";
23-
box: [number, number, number, number];
24-
borderRadius?: React.CSSProperties["borderRadius"];
25-
cursor?: React.CSSProperties["cursor"];
26-
readonly?: boolean;
27-
}) {
4+
export const Handle = forwardRef(function (
5+
{
6+
color,
7+
anchor,
8+
box,
9+
outlineWidth = 1,
10+
outlineColor = "transparent",
11+
size = 4,
12+
borderRadius = 0,
13+
cursor,
14+
readonly,
15+
}: {
16+
color: string;
17+
/**
18+
* the width of the outline
19+
*/
20+
outlineWidth?: number;
21+
outlineColor?: string;
22+
size: number;
23+
anchor: "nw" | "ne" | "sw" | "se";
24+
box: [number, number, number, number];
25+
borderRadius?: React.CSSProperties["borderRadius"];
26+
cursor?: React.CSSProperties["cursor"];
27+
readonly?: boolean;
28+
},
29+
ref
30+
) {
2831
let dx = 0;
2932
let dy = 0;
3033
switch (anchor) {

editor-packages/editor-canvas/overlay/meter-label.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ export function MeterLabel({
4545
zoom,
4646
margin = 0,
4747
zIndex = k.Z_INDEX_GUIDE_LABEL,
48+
weight = 500,
4849
}: {
4950
x: number;
5051
y: number;
52+
weight?: React.CSSProperties["fontWeight"];
5153
background?: React.CSSProperties["background"];
5254
label: string;
5355
anchor: "w" | "n" | "s" | "e";
@@ -98,7 +100,7 @@ export function MeterLabel({
98100
color: "white",
99101
fontSize: font_size,
100102
fontFamily: "Inter, sans-serif",
101-
fontWeight: 500,
103+
fontWeight: weight,
102104
textAlign: "center",
103105
zIndex: zIndex,
104106
}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./stores";
2+
export * from "./repository";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@editor/figma-file",
3+
"version": "0.0.0"
4+
}

editor/repository/figma-design-repository/index.ts renamed to editor-packages/editor-figma-file/repository.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fetch } from "@design-sdk/figma-remote";
2-
import { FileResponse } from "@design-sdk/figma-remote-types";
3-
import { FigmaFileStore, FileResponseRecord } from "@editor/figma-file-store";
2+
import { FigmaFileStore, FigmaFileMetaStore } from "./stores";
3+
import type { FileResponseRecord } from "./stores";
44

55
export type TFetchFileForApp = (
66
| fetch.FetchFileGeneratorReturnType
@@ -20,23 +20,29 @@ export class FigmaDesignRepository {
2020
) {}
2121

2222
static async fetchCachedFile(fileId: string) {
23+
const metastore = new FigmaFileMetaStore();
2324
const store = new FigmaFileStore(fileId);
2425
const existing = await store.get();
2526
if (existing) {
27+
// everytime the file is consumed consider it as used, we upsert the file so that the lastUsed can be updated.
28+
metastore.upsert(existing.key, existing);
2629
return { ...existing, __initial: false } as TFetchFileForApp;
2730
} else {
2831
throw new Error("file not found");
2932
}
3033
}
3134

32-
async *fetchFile(fileId: string) {
33-
const store = new FigmaFileStore(fileId);
35+
async *fetchFile(filekey: string) {
36+
const metastore = new FigmaFileMetaStore();
37+
const store = new FigmaFileStore(filekey);
3438
const existing = await store.get();
3539
if (existing) {
40+
// everytime the file is consumed consider it as used, we upsert the file so that the lastUsed can be updated.
41+
metastore.upsert(existing.key, existing);
3642
yield { ...existing, __initial: false } as TFetchFileForApp;
3743
}
3844

39-
const _iter = fetch.fetchFile({ file: fileId, auth: this.auth });
45+
const _iter = fetch.fetchFile({ file: filekey, auth: this.auth });
4046
let next: IteratorResult<fetch.FetchFileGeneratorReturnType>;
4147
while ((next = await _iter.next()).done === false) {
4248
switch (next.value.__response_type) {
@@ -48,6 +54,7 @@ export class FigmaDesignRepository {
4854
__type: "file-fetched-for-app",
4955
} as TFetchFileForApp;
5056
store.upsert(next.value);
57+
metastore.upsert(filekey, next.value);
5158
}
5259
break;
5360
case "roots":
@@ -58,6 +65,7 @@ export class FigmaDesignRepository {
5865
__type: "file-fetched-for-app",
5966
} as TFetchFileForApp;
6067
store.upsert(next.value);
68+
metastore.upsert(filekey, next.value);
6169
}
6270
break;
6371
case "whole":
@@ -67,6 +75,7 @@ export class FigmaDesignRepository {
6775
__type: "file-fetched-for-app",
6876
} as TFetchFileForApp;
6977
store.upsert(next.value);
78+
metastore.upsert(filekey, next.value);
7079
break;
7180
}
7281
}

0 commit comments

Comments
 (0)