Skip to content

Apr #2 #147

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 65 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cfb0d6b
fix non org package name resolution on unpkg plugin
softmarshmallow Apr 12, 2022
cdeea9e
add .d.ts support for monaco editor
softmarshmallow Apr 12, 2022
ba68d45
set node version to >=16.14.x
softmarshmallow Apr 12, 2022
84f0f25
Revert "set node version to >=16.14.x"
softmarshmallow Apr 13, 2022
c3f980f
add console feed
softmarshmallow Apr 13, 2022
17f40e7
bump console-feed with custom build
softmarshmallow Apr 13, 2022
884e56e
bump mui (fixing)
softmarshmallow Apr 13, 2022
f187088
update types
softmarshmallow Apr 13, 2022
f10b9eb
revert yarn.lock file
softmarshmallow Apr 14, 2022
666b793
tmp : disable all mui components
softmarshmallow Apr 14, 2022
bdd59fc
fix mui build isses
softmarshmallow Apr 15, 2022
b41182f
allow vanilla frameworkf for realtime scripting
softmarshmallow Apr 15, 2022
23f8788
init canvas page
softmarshmallow Apr 15, 2022
d4010d9
add dl context action
softmarshmallow Apr 15, 2022
bb79d99
Merge branch 'es-dts-support' of https://github.com/gridaco/designto-…
softmarshmallow Apr 15, 2022
2c38f70
export file dl to utils
softmarshmallow Apr 15, 2022
a5c8530
extract types resolver as a independent pacakge
softmarshmallow Apr 15, 2022
9d4057f
add initial preset dependenct types loading
softmarshmallow Apr 15, 2022
8d3c813
add config map for scripting and preview by by frameworks
softmarshmallow Apr 15, 2022
d1c10c8
add vanilla scripting support
softmarshmallow Apr 15, 2022
d92aa4e
add node id as key to preview component
softmarshmallow Apr 15, 2022
054ce50
rename debugger to devtools
softmarshmallow Apr 15, 2022
b2e0e07
organize
softmarshmallow Apr 15, 2022
88d1111
add devtools ui
softmarshmallow Apr 15, 2022
7c415c5
wip
softmarshmallow Apr 15, 2022
3ff9f64
beautify
softmarshmallow Apr 15, 2022
a475a62
add size store
softmarshmallow Apr 15, 2022
8fba20d
add console proxy of preview es runner
softmarshmallow Apr 15, 2022
d811875
add console actions
softmarshmallow Apr 15, 2022
a3bc826
add console reducer
softmarshmallow Apr 15, 2022
24ce106
add console state
softmarshmallow Apr 15, 2022
4b380d5
add editor console feed
softmarshmallow Apr 15, 2022
3860bb1
link events
softmarshmallow Apr 15, 2022
5c338dd
add console was cleared message on clear
softmarshmallow Apr 15, 2022
4b5052c
Merge pull request #151 from gridaco/add-monaco-context-menu
softmarshmallow Apr 15, 2022
b05d6db
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 15, 2022
db528b9
extract preview renderer
softmarshmallow Apr 15, 2022
b541006
update og finder logic
softmarshmallow Apr 15, 2022
d2eeed4
testing webworker version preview canvas
softmarshmallow Apr 15, 2022
e8396c2
bump modules
softmarshmallow Apr 16, 2022
afbd093
Merge pull request #145 from gridaco/editor-console-feed
softmarshmallow Apr 16, 2022
b01611e
wip
softmarshmallow Apr 16, 2022
2f72b96
wip canvas docs
softmarshmallow Apr 17, 2022
050453a
use content-visibility instead of display
softmarshmallow Apr 18, 2022
3d85114
use translate3d for gpu boost
softmarshmallow Apr 18, 2022
4b7096d
add marquee edge scrolling
softmarshmallow Apr 18, 2022
a8de03f
rename
softmarshmallow Apr 18, 2022
fc48a51
fix hovering target math
softmarshmallow Apr 18, 2022
39de7a4
fix marquee logic
softmarshmallow Apr 18, 2022
bda3467
add area raycasting math
softmarshmallow Apr 18, 2022
7be9759
add multi selection support
softmarshmallow Apr 18, 2022
fe9116f
add frame title handling
softmarshmallow Apr 18, 2022
9cf39e3
Merge pull request #150 from gridaco/es-dts-support
softmarshmallow Apr 18, 2022
602399c
Merge pull request #153 from gridaco/canvas/marquee
softmarshmallow Apr 20, 2022
e56a1c4
Merge branch 'main' of https://github.com/gridaco/designto-code into …
softmarshmallow Apr 22, 2022
7d72499
bump reflect core
softmarshmallow Apr 25, 2022
5563efd
init connection line component
softmarshmallow Apr 25, 2022
5a090fe
add connection line renderer
softmarshmallow Apr 25, 2022
d9236cb
qf: bump packages with blend mode map issue fix
softmarshmallow Apr 26, 2022
4ddb36a
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 29, 2022
ed71a08
Merge pull request #156 from gridaco/support-flow-connections
softmarshmallow Apr 29, 2022
c5befc8
Merge pull request #148 from gridaco/vanilla-scripting
softmarshmallow Apr 29, 2022
1c084ff
bump design-sdk
softmarshmallow Apr 29, 2022
155a217
bump design sdk with env modes
softmarshmallow Apr 29, 2022
885f65f
bump design-sdk - max child to 500
softmarshmallow Apr 30, 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
30 changes: 29 additions & 1 deletion editor-packages/editor-canvas/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# A Interactive canvas for runtime frames.
# A Html5 backend Interactive canvas for runtime frames.

## The system

- Canvas
- Hud
- Event
- Math
- Iframe
- Node
- Host

## General architecture

- `ScaffoldCanvas` - A single component canvas that holds both renderer and eventsystem
- `RenderOnlyCanvas + EventSystem` - A Customizable system for complex and heavy rendering. (use saperate render host with iframe)

## Events

gesture events

- move (pan)
- zoom (pinch)

- create node
- remove node
- move node
- resize node
- rename node
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export function CanvasEventTarget({
const [first_wheel_event, set_first_wheel_event] =
useState<FullGestureState<"wheel">>();

// this is a hack to prevent from onDragStart being called even when no movement is detected.
const [drag_start_emitted, set_drag_start_emitted] = useState(false);

useGesture(
{
onPinch: onZooming,
Expand Down Expand Up @@ -150,7 +153,10 @@ export function CanvasEventTarget({
return;
}

onDragStart(s);
if (s.delta[0] || s.delta[1]) {
onDragStart(s);
set_drag_start_emitted(true);
}
},
onDrag: (s) => {
if (isSpacebarPressed) {
Expand All @@ -161,6 +167,10 @@ export function CanvasEventTarget({
return;
}

if ((s.delta[0] || s.delta[1]) && !drag_start_emitted) {
set_drag_start_emitted(true);
onDragStart(s);
}
onDrag(s);
},
onDragEnd: (s) => {
Expand All @@ -169,6 +179,7 @@ export function CanvasEventTarget({
return;
}

set_drag_start_emitted(false);
onDragEnd(s);
},
onMouseDown: onPointerDown,
Expand Down
90 changes: 73 additions & 17 deletions editor-packages/editor-canvas/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import {
OnPointerDownHandler,
OnDragHandler,
} from "../canvas-event-target";
import { get_hovering_target, centerOf } from "../math";
import {
target_of_point,
centerOf,
edge_scrolling,
target_of_area,
} from "../math";
import { utils } from "@design-sdk/core";
import { LazyFrame } from "@code-editor/canvas/lazy-frame";
import { HudCustomRenderers, HudSurface } from "./hud-surface";
import { HudCustomRenderers, HudSurface } from "../hud";
import type { Box, XY, CanvasTransform, XYWH } from "../types";
import type { FrameOptimizationFactors } from "../frame";
const designq = utils.query;
Expand Down Expand Up @@ -89,7 +94,7 @@ export function Canvas({
...props
}: {
viewbound: Box;
onSelectNode?: (node?: ReflectSceneNode) => void;
onSelectNode?: (...node: ReflectSceneNode[]) => void;
onClearSelection?: () => void;
} & CanvasCustomRenderers &
CanvasState & {
Expand Down Expand Up @@ -131,6 +136,7 @@ export function Canvas({
? [offset[0] / zoom, offset[1] / zoom]
: [0, 0];
const [isPanning, setIsPanning] = useState(false);
const [isDraggomg, setIsDragging] = useState(false);
const [marquee, setMarquee] = useState<XYWH>(null);

const cvtransform: CanvasTransform = {
Expand All @@ -151,17 +157,46 @@ export function Canvas({
setHoveringLayer(wshighlight);
}, [highlightedLayer]);

// area selection hook
useEffect(() => {
if (marquee) {
const area: XYWH = [
marquee[0] / zoom,
marquee[1] / zoom,
marquee[2] / zoom,
marquee[3] / zoom,
];

const selections = target_of_area({
area,
tree: nodes,
contain: false,
});

// https://stackoverflow.com/a/19746771
const same =
selectedNodes.length === selections?.length &&
selectedNodes.every((value, index) => value === selections[index].id);

if (!same) {
onSelectNode(...selections);
}
}
//
}, [marquee]);

const onPointerMove: OnPointerMoveHandler = (state) => {
if (isPanning || isZooming) {
if (isPanning || isZooming || isDraggomg) {
// don't perform hover calculation while transforming.
return;
}
const hovering = get_hovering_target({
const hovering = target_of_point({
point: state.xy,
tree: nodes,
zoom: zoom,
offset: nonscaled_offset,
margin: LAYER_HOVER_HIT_MARGIN,
reverse: true,
});

if (!hovering) {
Expand Down Expand Up @@ -223,27 +258,48 @@ export function Canvas({
setOffset([newx, newy]);
};

const onDragStart: OnDragHandler = (s) => {
onClearSelection();
setIsDragging(true);
setHoveringLayer(null);

// set the marquee start point
const [x, y] = s.initial;
const [ox, oy] = offset;
const [x1, y1] = [x - ox, y - oy];
setMarquee([x1, y1, 0, 0]);
};

const onDrag: OnDragHandler = (s) => {
const [x1, y1] = s.initial;
const [x2, y2] = [
const [ox, oy] = offset;
const [x, y] = [
// @ts-ignore
s.event.clientX,
// @ts-ignore
s.event.clientY,
];

const [ox, oy] = offset;
const [x, y, w, h] = [
x1 - ox,
y1 - oy,
x2 - x1, // w
y2 - y1, // h
];
setMarquee([x, y, w, h]);
const [x1, y1] = [x - ox, y - oy];

if (marquee) {
const [w, h] = [
x1 - marquee[0], // w
y1 - marquee[1], // h
];
setMarquee([marquee[0], marquee[1], w, h]);
}

// edge scrolling
const [cx, cy] = [x, y];
const [dx, dy] = edge_scrolling(cx, cy, viewbound);
if (dx || dy) {
setOffset([ox + dx, oy + dy]);
}
};

const onDragEnd: OnDragHandler = (s) => {
setMarquee(null);
setIsDragging(false);
};

const is_canvas_transforming = isPanning || isZooming;
Expand Down Expand Up @@ -299,8 +355,8 @@ export function Canvas({
onPointerMoveStart={() => {}}
onPointerMoveEnd={() => {}}
onPointerDown={onPointerDown}
onDragStart={onDragStart}
onDrag={onDrag}
onDragStart={() => {}} // TODO:
onDragEnd={onDragEnd}
>
<HudSurface
Expand Down Expand Up @@ -363,7 +419,7 @@ function CanvasTransformRoot({
width: 0,
height: 0,
willChange: "transform",
transform: `scale(${scale}) translateX(${xy[0]}px) translateY(${xy[1]}px)`,
transform: `scale(${scale}) translate3d(${xy[0]}px, ${xy[1]}px, 0)`,
isolation: "isolate",
}}
>
Expand Down
7 changes: 7 additions & 0 deletions editor-packages/editor-canvas/docs/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- move back
- move front

- copy
- paste
- move under parent
- lock / unlock
25 changes: 25 additions & 0 deletions editor-packages/editor-canvas/docs/feature-area-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Area selection (Marquee selection)

> This feature yet does not consider vector networks. (boolean operation)

Keymode

- default
- cmd

Parameters

- raycast mode:
- hit - if the target has an intersection with the area.
- contain - if the target is contained in the area.
- type
- frame
- group
- frame
- element (others)
- is root - this only effects to the frame node.

Final output for painting

- selections (each selection will get a highlight)
- bounding box (abstract group)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Canvas Drag Scroll (Scroll / Pan while dragging)

scroll (translate) a canvas while dragging (marquee, move, resize element). if hit the edge of the canvas, the canvas will scroll.
42 changes: 42 additions & 0 deletions editor-packages/editor-canvas/docs/hud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Hud system

node

- hover outline
- resize knob
- rotate knob
- border radius knob
- frame title
- draft editor (text editing)
- multiplayer cursor
- resizing size indicator
- rotating rotation indicator

ruler & guide

- ruler
- guide (user defined guide line)
- highlight guide (hovered, selected guide line)
- snap line (snapping guide line)
- layout grids (grid-template-columns)
- spacing guide (size between 2 nodes)

layout

- layout placement guide (preview the place of an moving item after placement inside a certain lyout - row / col)

- interaction knob
- interaction line

popover

- popovers

feedback (comments)

- pin
- create pin

vector

- TODO:
1 change: 1 addition & 0 deletions editor-packages/editor-canvas/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Html5 Backend Canvas docs
64 changes: 64 additions & 0 deletions editor-packages/editor-canvas/flow-connections/arrow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from "react";
import type { XY } from "../types";

export function Arrow({
b,
color,
size,
width,
direction,
}: {
b: XY;
color: React.CSSProperties["color"];
size: number;
width: number;
direction: "n" | "s" | "e" | "w";
}) {
return (
<path
stroke={color}
strokeWidth={width}
d={make_arrow_svg_path_data(b, direction, {
width: size,
height: size / 2,
})}
/>
);
}

/**
*
* the result will have 3 modifiers,
* if the arrow is facing right, the modifiers will be:
* - M - starting point [edge_x - height, edge_y + width / 2]
* - L - edge [edge_x, edge_y]
* - L - ending point [edge_x - height, edge_y - width / 2]
*
* @param edge the edge of a arrow (triangle)
* @param width
*/
function make_arrow_svg_path_data(
edge: XY,
direction: "n" | "s" | "e" | "w",
{ width, height }: { width: number; height: number }
) {
const [x, y] = edge;
const w = width / 2;
switch (direction) {
case "e": {
return `M${x - height},${y + w} L${x},${y} L${x - height},${y - w}`;
}
case "w": {
return `M${x + height},${y + w} L${x},${y} L${x + height},${y - w}`;
}
case "n": {
return `M${x - w},${y + height} L${x},${y} L${x + w},${y + height}`;
}
case "s": {
return `M${x - w},${y - height} L${x},${y} L${x + w},${y - height}`;
}
default: {
throw new Error(`invalid direction: ${direction}`);
}
}
}
Loading