Skip to content

Commit e20359f

Browse files
Merge pull request #192 from gridaco/staging
2022W49 - Isolated Inspection mode & Improved Scenes Management (WIP)
2 parents c82c46f + 6b67abd commit e20359f

Some content is hidden

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

42 files changed

+3786
-3080
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ yarn editor
1414
- packages - core packages contributing to the code-gen logic
1515
- externals - external foundational packages, like [reflect-core](https://github.com/reflect-ui/reflect-core-ts)
1616

17-
# Why 6626?
17+
## QnA
1818

19-
6626 is from `69 68 2 67` Which is a decimal representation of ED2C(Engine: Design 2 Code)
19+
- Why 6626? - 6626 is from `69 68 2 67` Which is a decimal representation of ED2C(Engine: Design 2 Code)
20+
21+
## Utilities
22+
23+
- npx npkill to clean all node_modules folders
24+
- clean: `npx npkill && rm -rf yarn.lock`

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

Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
MenuItem,
3636
} from "@editor-ui/context-menu";
3737
import styled from "@emotion/styled";
38+
import toast from "react-hot-toast";
3839

3940
interface CanvasState {
4041
pageid: string;
@@ -44,6 +45,10 @@ interface CanvasState {
4445
highlightedLayer?: string;
4546
selectedNodes: string[];
4647
readonly?: boolean;
48+
/**
49+
* displays the debug info on the canvas.
50+
*/
51+
debug?: boolean;
4752
/**
4853
* when provided, it will override the saved value or centering logic and use this transform as initial instead.
4954
*
@@ -101,6 +106,10 @@ const default_canvas_preferences: CanvsPreferences = {
101106

102107
type CanvasProps = CanvasFocusProps &
103108
CanvasCursorOptions & {
109+
/**
110+
* canvas view bound.
111+
* [(x1) left, (y1) top, (x2) right, (y2) bottom]
112+
*/
104113
viewbound: Box;
105114
onSelectNode?: (...node: ReflectSceneNode[]) => void;
106115
onMoveNodeStart?: (...node: string[]) => void;
@@ -158,6 +167,7 @@ export function Canvas({
158167
initialTransform,
159168
highlightedLayer,
160169
selectedNodes,
170+
debug,
161171
readonly = true,
162172
config = default_canvas_preferences,
163173
backgroundColor,
@@ -225,7 +235,9 @@ export function Canvas({
225235
setZoom(_focus_center.scale);
226236
}, [...focus, focusRefreshKey, viewboundmeasured]);
227237

228-
const [transformIntitialized, setTransformInitialized] = useState(false);
238+
const [transformIntitialized, setTransformInitialized] = useState(
239+
!!initialTransform
240+
);
229241
const [zoom, setZoom] = useState(initialTransform?.scale || 1);
230242
const [isZooming, setIsZooming] = useState(false);
231243
const [offset, setOffset] = useState<[number, number]>(
@@ -429,19 +441,25 @@ export function Canvas({
429441
onMoveNode?.([dx / zoom, dy / zoom], ...selectedNodes);
430442
}
431443

432-
if (marquee) {
433-
const [w, h] = [
434-
x1 - marquee[0], // w
435-
y1 - marquee[1], // h
436-
];
437-
setMarquee([marquee[0], marquee[1], w, h]);
438-
}
444+
if (config.marquee.disabled) {
445+
// skip
446+
} else {
447+
// edge scrolling
448+
// edge scrolling is only enabled when config#marquee is enabled
449+
const [cx, cy] = [x, y];
450+
const [dx, dy] = edge_scrolling(cx, cy, viewbound);
451+
if (dx || dy) {
452+
setOffset([ox + dx, oy + dy]);
453+
}
439454

440-
// edge scrolling
441-
const [cx, cy] = [x, y];
442-
const [dx, dy] = edge_scrolling(cx, cy, viewbound);
443-
if (dx || dy) {
444-
setOffset([ox + dx, oy + dy]);
455+
// update marquee & following selections via effect
456+
if (marquee) {
457+
const [w, h] = [
458+
x1 - marquee[0], // w
459+
y1 - marquee[1], // h
460+
];
461+
setMarquee([marquee[0], marquee[1], w, h]);
462+
}
445463
}
446464
};
447465

@@ -504,11 +522,35 @@ export function Canvas({
504522
return (
505523
<>
506524
<>
525+
{debug === true && (
526+
<Debug
527+
infos={[
528+
{ label: "zoom", value: zoom },
529+
{ label: "offset", value: offset.join(", ") },
530+
{ label: "isPanning", value: isPanning },
531+
{ label: "isZooming", value: isZooming },
532+
{ label: "isDragging", value: isDragging },
533+
{ label: "isMovingSelections", value: isMovingSelections },
534+
{ label: "isTransforming", value: is_canvas_transforming },
535+
{ label: "selectedNodes", value: selectedNodes.join(", ") },
536+
{ label: "hoveringLayer", value: hoveringLayer?.node?.id },
537+
{ label: "marquee", value: marquee?.join(", ") },
538+
{ label: "viewbound", value: viewbound.join(", ") },
539+
{
540+
label: "initial-transform (xy)",
541+
value: initialTransform ? initialTransform.xy.join(", ") : null,
542+
},
543+
{
544+
label: "initial-transform (zoom)",
545+
value: initialTransform ? initialTransform.scale : null,
546+
},
547+
]}
548+
/>
549+
)}
507550
{/* <ContextMenuProvider> */}
508551
<Container
509-
// todo: viewbound not accurate.
510-
// width={viewbound[2] - viewbound[0]}
511-
// height={viewbound[3] - viewbound[1]}
552+
width={viewbound[2] - viewbound[0]}
553+
height={viewbound[3] - viewbound[1]}
512554
>
513555
<CanvasEventTarget
514556
onPanning={onPanning}
@@ -524,6 +566,7 @@ export function Canvas({
524566
// const newoffset = zoomToFit(viewbound, offset, zoom, 1);
525567
// setOffset(newoffset);
526568
_canvas_state_store.saveLastTransform(cvtransform);
569+
toast("Zoom to 100%");
527570
}}
528571
onZooming={onZooming}
529572
onZoomingStart={() => {
@@ -585,12 +628,10 @@ export function Canvas({
585628
);
586629
}
587630

588-
const Container = styled.div`
589-
min-width: 240px;
590-
min-height: 240px;
631+
const Container = styled.div<{ width: number; height: number }>`
632+
/* width: ${(p) => p.width}px; */
633+
/* height: ${(p) => p.height}px; */
591634
`;
592-
/* width: ${(p) => p.width}px; */
593-
/* height: ${(p) => p.height}px; */
594635

595636
/**
596637
* 1. container positioning guide (static per selection)
@@ -713,9 +754,10 @@ function DisableBackdropFilter({ children }: { children: React.ReactNode }) {
713754
function CanvasBackground({ backgroundColor }: { backgroundColor?: string }) {
714755
return (
715756
<div
757+
id="canvas-background"
716758
style={{
717759
zIndex: -2,
718-
position: "fixed",
760+
position: "absolute",
719761
top: 0,
720762
left: 0,
721763
width: "100%",
@@ -786,3 +828,39 @@ const viewbound_not_measured = (viewbound: Box) => {
786828
viewbound[3] === 0)
787829
);
788830
};
831+
832+
function Debug({
833+
infos,
834+
}: {
835+
infos: { label: string; value: string | number | boolean }[];
836+
}) {
837+
return (
838+
<DebugInfoContainer>
839+
{infos.map(({ label, value }, i) => {
840+
if (value === undefined || value === null) {
841+
return <></>;
842+
}
843+
return (
844+
<div key={i}>
845+
{label}: {JSON.stringify(value)}
846+
</div>
847+
);
848+
})}
849+
</DebugInfoContainer>
850+
);
851+
}
852+
853+
const DebugInfoContainer = styled.div`
854+
position: absolute;
855+
top: 12px;
856+
left: 12px;
857+
z-index: 9999;
858+
background: rgba(0, 0, 0, 0.5);
859+
border-radius: 4px;
860+
color: white;
861+
padding: 0.5rem;
862+
font-size: 0.8rem;
863+
font-family: monospace;
864+
line-height: 1.2;
865+
white-space: pre;
866+
`;

editor-packages/editor-canvas/math/center-of.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export function centerOf(
6363
vbcenter[1] - boxcenter[1] * scale,
6464
];
6565

66+
// apply viewbound's offset to the translate.
67+
// (this works, but not fully tested)
68+
translate[0] -= viewbound[0];
69+
translate[1] -= viewbound[1];
70+
6671
return {
6772
box: box,
6873
center: boxcenter,

editor-packages/editor-canvas/math/viewbound-edge-scrolling.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @param cx x coordinate of the cursor
1818
* @param cy y coordinate of the cursor
19-
* @param viewbound the viewbound of the canvas (l, t, b, r)
19+
* @param viewbound the viewbound of the canvas (l x1, t y1, r x2, b y2)
2020
* @param margin the margin value (default 40px)
2121
* @param factor the returned value will be multiplied by this factor (default 1/4)
2222
*
@@ -29,7 +29,7 @@ export function edge_scrolling(
2929
margin = 40,
3030
factor = 1 / 4
3131
): [number, number] {
32-
const [l, t, b, r] = viewbound;
32+
const [l, t, r, b] = viewbound;
3333
let [dx, dy] = [0, 0];
3434

3535
if (cx < l + margin) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from "react";
2+
import styled from "@emotion/styled";
3+
import assert from "assert";
4+
5+
export type AuxilaryGridDropGuideLeftOrRightSpecification = {
6+
left?: boolean;
7+
right?: boolean;
8+
};
9+
type AuxilaryGridDropGuide = AuxilaryGridDropGuideLeftOrRightSpecification & {
10+
onClick?: () => void;
11+
over?: boolean;
12+
};
13+
14+
/**
15+
* This is a guide placed between items
16+
*
17+
* Functions
18+
* 1. Highlight on drop
19+
* 2. Highlight on hover (if new section can be created)
20+
*/
21+
export const AuxilaryDashbaordGridPlacementGuide = React.forwardRef(function (
22+
{ left, right, over, onClick }: AuxilaryGridDropGuide,
23+
ref: React.Ref<HTMLDivElement>
24+
) {
25+
assert(left !== right, 'You can only have one of "left" or "right"');
26+
27+
return (
28+
<Guide
29+
ref={ref}
30+
onClick={onClick}
31+
data-over={over}
32+
data-left={left}
33+
data-right={right}
34+
/>
35+
);
36+
});
37+
38+
const GUIDE_MARGIN = 4;
39+
const GUIDE_ACCESSIBLE_WIDTH = 32;
40+
41+
const Guide = styled.div`
42+
--guide-margin-vertical: 24px;
43+
--color-highlight: rgb(0, 179, 255);
44+
45+
position: absolute;
46+
width: ${GUIDE_ACCESSIBLE_WIDTH}px;
47+
top: var(--guide-margin-vertical);
48+
bottom: calc(var(--guide-margin-vertical) + 44px);
49+
50+
&[data-left="true"] {
51+
left: ${-(GUIDE_MARGIN + GUIDE_ACCESSIBLE_WIDTH)}px;
52+
}
53+
54+
&[data-right="true"] {
55+
right: ${-(GUIDE_MARGIN + GUIDE_ACCESSIBLE_WIDTH)}px;
56+
}
57+
58+
::after {
59+
content: "";
60+
position: absolute;
61+
opacity: 0;
62+
top: 0;
63+
/* center under parent */
64+
left: 50%;
65+
66+
width: 2px;
67+
height: 100%;
68+
background: var(--color-highlight);
69+
70+
transition: opacity 0.2s ease-in-out;
71+
}
72+
73+
&[data-over="true"] {
74+
::after {
75+
opacity: 1;
76+
}
77+
}
78+
79+
&:hover {
80+
::after {
81+
opacity: 1;
82+
}
83+
}
84+
`;

editor-packages/editor-dashboard/components/dashboard-item-card-scene.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
DashboardItemCardProps,
88
} from "./dashboard-item-card";
99

10+
const MAX_WIDTH = 240;
11+
1012
type SceneMeta = {
1113
id: string;
1214
filekey: string;
@@ -34,6 +36,7 @@ function SceneCardPreview({
3436
return (
3537
<div
3638
ref={visibilityRef}
39+
className="scale-on-over"
3740
style={{
3841
height: height * scale,
3942
width: maxWidth,
@@ -79,7 +82,7 @@ export const SceneCard = React.forwardRef(function (
7982
{...props}
8083
label={scene.name}
8184
icon={<SceneNodeIcon type={scene.type} color="white" />}
82-
preview={<SceneCardPreview scene={scene} maxWidth={300} />}
85+
preview={<SceneCardPreview scene={scene} maxWidth={MAX_WIDTH} />}
8386
/>
8487
);
8588
});

editor-packages/editor-dashboard/components/dashboard-item-card.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const Card = styled.div`
114114
`;
115115

116116
const PreviewContainer = styled.div`
117+
--color-highlight: rgb(0, 179, 255);
117118
outline: 1px solid rgba(0, 0, 0, 0.1);
118119
border-radius: 2px;
119120
overflow: hidden;
@@ -136,20 +137,31 @@ const PreviewContainer = styled.div`
136137
transition: all 0.2s ease-in-out;
137138
}
138139
140+
.scale-on-over {
141+
overflow: hidden;
142+
will-change: transform;
143+
transition: all 0.2s ease-in-out;
144+
}
145+
139146
&[data-selected="true"] {
140-
outline: 4px solid rgb(0, 179, 255);
147+
outline: 4px solid var(--color-highlight);
141148
142149
#overlay {
143150
display: block;
144151
}
145152
}
146153
147154
&[data-over="true"] {
148-
outline: 4px solid rgb(0, 179, 255);
155+
outline: 4px solid var(--color-highlight);
149156
150157
#view {
151158
opacity: 0.5;
152159
}
160+
161+
.scale-on-over {
162+
border-radius: 5px;
163+
transform: scale(0.85);
164+
}
153165
}
154166
155167
transition: all 0.2s ease-in-out;

0 commit comments

Comments
 (0)