Skip to content

2022W49 - Isolated Inspection mode & Improved Scenes Management (WIP) #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b1dc186
bump deps
softmarshmallow Nov 28, 2022
1bcbc93
yarn
softmarshmallow Nov 28, 2022
b6b6918
Merge branch 'main' of https://github.com/gridaco/code into staging
softmarshmallow Nov 28, 2022
9c70922
bump ui packs
softmarshmallow Nov 28, 2022
3c5d5f4
placehold service layers
softmarshmallow Dec 1, 2022
c73713e
fix build
softmarshmallow Dec 1, 2022
3ca7d78
fix build
softmarshmallow Dec 1, 2022
362767c
fix build
softmarshmallow Dec 1, 2022
13bca90
config
softmarshmallow Dec 1, 2022
b1fb5cc
fix build
softmarshmallow Dec 1, 2022
e847293
.
softmarshmallow Dec 1, 2022
e895431
rev
softmarshmallow Dec 1, 2022
a3e994b
add mock api route
softmarshmallow Dec 1, 2022
317ba61
add scaling scene preview on over
softmarshmallow Dec 1, 2022
5e659b6
add auxilary grid positioning guide
softmarshmallow Dec 1, 2022
3320d1f
update dispatch name & add context menu to scene card
softmarshmallow Dec 1, 2022
9c886c4
update dashboard hierarchy view as nested by default - wip
softmarshmallow Dec 1, 2022
a212313
init isolated focus inspection package
softmarshmallow Dec 1, 2022
8712725
config
softmarshmallow Dec 1, 2022
809ae1c
update state structure
softmarshmallow Dec 1, 2022
6f7d449
add ui package & move icon button to it
softmarshmallow Dec 1, 2022
29da4ed
add isolation actions
softmarshmallow Dec 1, 2022
ff17f05
extract cursor info to ui pack
softmarshmallow Dec 1, 2022
118f9e5
add isolate command
softmarshmallow Dec 1, 2022
596410b
update canvas to reflect the marquee config
softmarshmallow Dec 1, 2022
3fab083
add doubleclick to frame title
softmarshmallow Dec 1, 2022
42c77bc
add debug panel to canvas
softmarshmallow Dec 1, 2022
c51c76f
add navigation to isolation
softmarshmallow Dec 2, 2022
32700d4
update dashboard actions
softmarshmallow Dec 2, 2022
3cd54f4
update label
softmarshmallow Dec 2, 2022
805e9eb
update canvas viewbound handling
softmarshmallow Dec 2, 2022
fa34c77
update isolation nav pointer events
softmarshmallow Dec 2, 2022
fe06f1d
fix center-of logic with offset subtraction
softmarshmallow Dec 2, 2022
2d09798
add debug layer
softmarshmallow Dec 2, 2022
18207ba
add toast when zoom to fit
softmarshmallow Dec 4, 2022
63e3895
add expand all, root node ids props to layer hierarchy
softmarshmallow Dec 4, 2022
8fdead0
add hierarchy view for isolation view
softmarshmallow Dec 4, 2022
00b3a4a
rm debug view
softmarshmallow Dec 4, 2022
6b67abd
add log
softmarshmallow Dec 4, 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
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ yarn editor
- packages - core packages contributing to the code-gen logic
- externals - external foundational packages, like [reflect-core](https://github.com/reflect-ui/reflect-core-ts)

# Why 6626?
## QnA

6626 is from `69 68 2 67` Which is a decimal representation of ED2C(Engine: Design 2 Code)
- Why 6626? - 6626 is from `69 68 2 67` Which is a decimal representation of ED2C(Engine: Design 2 Code)

## Utilities

- npx npkill to clean all node_modules folders
- clean: `npx npkill && rm -rf yarn.lock`
122 changes: 100 additions & 22 deletions editor-packages/editor-canvas/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
MenuItem,
} from "@editor-ui/context-menu";
import styled from "@emotion/styled";
import toast from "react-hot-toast";

interface CanvasState {
pageid: string;
Expand All @@ -44,6 +45,10 @@ interface CanvasState {
highlightedLayer?: string;
selectedNodes: string[];
readonly?: boolean;
/**
* displays the debug info on the canvas.
*/
debug?: boolean;
/**
* when provided, it will override the saved value or centering logic and use this transform as initial instead.
*
Expand Down Expand Up @@ -101,6 +106,10 @@ const default_canvas_preferences: CanvsPreferences = {

type CanvasProps = CanvasFocusProps &
CanvasCursorOptions & {
/**
* canvas view bound.
* [(x1) left, (y1) top, (x2) right, (y2) bottom]
*/
viewbound: Box;
onSelectNode?: (...node: ReflectSceneNode[]) => void;
onMoveNodeStart?: (...node: string[]) => void;
Expand Down Expand Up @@ -158,6 +167,7 @@ export function Canvas({
initialTransform,
highlightedLayer,
selectedNodes,
debug,
readonly = true,
config = default_canvas_preferences,
backgroundColor,
Expand Down Expand Up @@ -225,7 +235,9 @@ export function Canvas({
setZoom(_focus_center.scale);
}, [...focus, focusRefreshKey, viewboundmeasured]);

const [transformIntitialized, setTransformInitialized] = useState(false);
const [transformIntitialized, setTransformInitialized] = useState(
!!initialTransform
);
const [zoom, setZoom] = useState(initialTransform?.scale || 1);
const [isZooming, setIsZooming] = useState(false);
const [offset, setOffset] = useState<[number, number]>(
Expand Down Expand Up @@ -429,19 +441,25 @@ export function Canvas({
onMoveNode?.([dx / zoom, dy / zoom], ...selectedNodes);
}

if (marquee) {
const [w, h] = [
x1 - marquee[0], // w
y1 - marquee[1], // h
];
setMarquee([marquee[0], marquee[1], w, h]);
}
if (config.marquee.disabled) {
// skip
} else {
// edge scrolling
// edge scrolling is only enabled when config#marquee is enabled
const [cx, cy] = [x, y];
const [dx, dy] = edge_scrolling(cx, cy, viewbound);
if (dx || dy) {
setOffset([ox + dx, oy + dy]);
}

// edge scrolling
const [cx, cy] = [x, y];
const [dx, dy] = edge_scrolling(cx, cy, viewbound);
if (dx || dy) {
setOffset([ox + dx, oy + dy]);
// update marquee & following selections via effect
if (marquee) {
const [w, h] = [
x1 - marquee[0], // w
y1 - marquee[1], // h
];
setMarquee([marquee[0], marquee[1], w, h]);
}
}
};

Expand Down Expand Up @@ -504,11 +522,35 @@ export function Canvas({
return (
<>
<>
{debug === true && (
<Debug
infos={[
{ label: "zoom", value: zoom },
{ label: "offset", value: offset.join(", ") },
{ label: "isPanning", value: isPanning },
{ label: "isZooming", value: isZooming },
{ label: "isDragging", value: isDragging },
{ label: "isMovingSelections", value: isMovingSelections },
{ label: "isTransforming", value: is_canvas_transforming },
{ label: "selectedNodes", value: selectedNodes.join(", ") },
{ label: "hoveringLayer", value: hoveringLayer?.node?.id },
{ label: "marquee", value: marquee?.join(", ") },
{ label: "viewbound", value: viewbound.join(", ") },
{
label: "initial-transform (xy)",
value: initialTransform ? initialTransform.xy.join(", ") : null,
},
{
label: "initial-transform (zoom)",
value: initialTransform ? initialTransform.scale : null,
},
]}
/>
)}
{/* <ContextMenuProvider> */}
<Container
// todo: viewbound not accurate.
// width={viewbound[2] - viewbound[0]}
// height={viewbound[3] - viewbound[1]}
width={viewbound[2] - viewbound[0]}
height={viewbound[3] - viewbound[1]}
>
<CanvasEventTarget
onPanning={onPanning}
Expand All @@ -524,6 +566,7 @@ export function Canvas({
// const newoffset = zoomToFit(viewbound, offset, zoom, 1);
// setOffset(newoffset);
_canvas_state_store.saveLastTransform(cvtransform);
toast("Zoom to 100%");
}}
onZooming={onZooming}
onZoomingStart={() => {
Expand Down Expand Up @@ -585,12 +628,10 @@ export function Canvas({
);
}

const Container = styled.div`
min-width: 240px;
min-height: 240px;
const Container = styled.div<{ width: number; height: number }>`
/* width: ${(p) => p.width}px; */
/* height: ${(p) => p.height}px; */
`;
/* width: ${(p) => p.width}px; */
/* height: ${(p) => p.height}px; */

/**
* 1. container positioning guide (static per selection)
Expand Down Expand Up @@ -713,9 +754,10 @@ function DisableBackdropFilter({ children }: { children: React.ReactNode }) {
function CanvasBackground({ backgroundColor }: { backgroundColor?: string }) {
return (
<div
id="canvas-background"
style={{
zIndex: -2,
position: "fixed",
position: "absolute",
top: 0,
left: 0,
width: "100%",
Expand Down Expand Up @@ -786,3 +828,39 @@ const viewbound_not_measured = (viewbound: Box) => {
viewbound[3] === 0)
);
};

function Debug({
infos,
}: {
infos: { label: string; value: string | number | boolean }[];
}) {
return (
<DebugInfoContainer>
{infos.map(({ label, value }, i) => {
if (value === undefined || value === null) {
return <></>;
}
return (
<div key={i}>
{label}: {JSON.stringify(value)}
</div>
);
})}
</DebugInfoContainer>
);
}

const DebugInfoContainer = styled.div`
position: absolute;
top: 12px;
left: 12px;
z-index: 9999;
background: rgba(0, 0, 0, 0.5);
border-radius: 4px;
color: white;
padding: 0.5rem;
font-size: 0.8rem;
font-family: monospace;
line-height: 1.2;
white-space: pre;
`;
5 changes: 5 additions & 0 deletions editor-packages/editor-canvas/math/center-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export function centerOf(
vbcenter[1] - boxcenter[1] * scale,
];

// apply viewbound's offset to the translate.
// (this works, but not fully tested)
translate[0] -= viewbound[0];
translate[1] -= viewbound[1];

return {
box: box,
center: boxcenter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @param cx x coordinate of the cursor
* @param cy y coordinate of the cursor
* @param viewbound the viewbound of the canvas (l, t, b, r)
* @param viewbound the viewbound of the canvas (l x1, t y1, r x2, b y2)
* @param margin the margin value (default 40px)
* @param factor the returned value will be multiplied by this factor (default 1/4)
*
Expand All @@ -29,7 +29,7 @@ export function edge_scrolling(
margin = 40,
factor = 1 / 4
): [number, number] {
const [l, t, b, r] = viewbound;
const [l, t, r, b] = viewbound;
let [dx, dy] = [0, 0];

if (cx < l + margin) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from "react";
import styled from "@emotion/styled";
import assert from "assert";

export type AuxilaryGridDropGuideLeftOrRightSpecification = {
left?: boolean;
right?: boolean;
};
type AuxilaryGridDropGuide = AuxilaryGridDropGuideLeftOrRightSpecification & {
onClick?: () => void;
over?: boolean;
};

/**
* This is a guide placed between items
*
* Functions
* 1. Highlight on drop
* 2. Highlight on hover (if new section can be created)
*/
export const AuxilaryDashbaordGridPlacementGuide = React.forwardRef(function (
{ left, right, over, onClick }: AuxilaryGridDropGuide,
ref: React.Ref<HTMLDivElement>
) {
assert(left !== right, 'You can only have one of "left" or "right"');

return (
<Guide
ref={ref}
onClick={onClick}
data-over={over}
data-left={left}
data-right={right}
/>
);
});

const GUIDE_MARGIN = 4;
const GUIDE_ACCESSIBLE_WIDTH = 32;

const Guide = styled.div`
--guide-margin-vertical: 24px;
--color-highlight: rgb(0, 179, 255);

position: absolute;
width: ${GUIDE_ACCESSIBLE_WIDTH}px;
top: var(--guide-margin-vertical);
bottom: calc(var(--guide-margin-vertical) + 44px);

&[data-left="true"] {
left: ${-(GUIDE_MARGIN + GUIDE_ACCESSIBLE_WIDTH)}px;
}

&[data-right="true"] {
right: ${-(GUIDE_MARGIN + GUIDE_ACCESSIBLE_WIDTH)}px;
}

::after {
content: "";
position: absolute;
opacity: 0;
top: 0;
/* center under parent */
left: 50%;

width: 2px;
height: 100%;
background: var(--color-highlight);

transition: opacity 0.2s ease-in-out;
}

&[data-over="true"] {
::after {
opacity: 1;
}
}

&:hover {
::after {
opacity: 1;
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
DashboardItemCardProps,
} from "./dashboard-item-card";

const MAX_WIDTH = 240;

type SceneMeta = {
id: string;
filekey: string;
Expand Down Expand Up @@ -34,6 +36,7 @@ function SceneCardPreview({
return (
<div
ref={visibilityRef}
className="scale-on-over"
style={{
height: height * scale,
width: maxWidth,
Expand Down Expand Up @@ -79,7 +82,7 @@ export const SceneCard = React.forwardRef(function (
{...props}
label={scene.name}
icon={<SceneNodeIcon type={scene.type} color="white" />}
preview={<SceneCardPreview scene={scene} maxWidth={300} />}
preview={<SceneCardPreview scene={scene} maxWidth={MAX_WIDTH} />}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const Card = styled.div`
`;

const PreviewContainer = styled.div`
--color-highlight: rgb(0, 179, 255);
outline: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 2px;
overflow: hidden;
Expand All @@ -136,20 +137,31 @@ const PreviewContainer = styled.div`
transition: all 0.2s ease-in-out;
}

.scale-on-over {
overflow: hidden;
will-change: transform;
transition: all 0.2s ease-in-out;
}

&[data-selected="true"] {
outline: 4px solid rgb(0, 179, 255);
outline: 4px solid var(--color-highlight);

#overlay {
display: block;
}
}

&[data-over="true"] {
outline: 4px solid rgb(0, 179, 255);
outline: 4px solid var(--color-highlight);

#view {
opacity: 0.5;
}

.scale-on-over {
border-radius: 5px;
transform: scale(0.85);
}
}

transition: all 0.2s ease-in-out;
Expand Down
Loading