Skip to content

Commit a5424aa

Browse files
Merge pull request #120 from gridaco/staging
Feb - React Native build support & editor UX improvements
2 parents 275e06a + 6c1ede3 commit a5424aa

File tree

189 files changed

+7019
-3078
lines changed

Some content is hidden

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

189 files changed

+7019
-3078
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
url = https://github.com/gridaco/base-sdk
1010
[submodule "externals/coli"]
1111
path = externals/coli
12-
url = https://github.com/bridgedxyz/coli
12+
url = https://github.com/gridaco/coli
1313
[submodule "externals/design-sdk"]
1414
path = externals/design-sdk
1515
url = https://github.com/gridaco/design-sdk

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,65 @@ yarn editor
2525

2626
update pulling - `git submodule update --init --recursive`
2727

28+
## Platforms / Frameworks
29+
30+
| **Frameworks** | |
31+
| ------------------ | :---: |
32+
| ReactJS ||
33+
| Flutter ||
34+
| React Native ||
35+
| Vanilla (html/css) ||
36+
| Vue | (wip) |
37+
38+
| **ReactJS** | |
39+
| ------------------- | :---: |
40+
| `styled-components` ||
41+
| `@emotion/styled` ||
42+
| css-modules ||
43+
| inline-css ||
44+
| `@mui/material` | (wip) |
45+
| breakpoints | (wip) |
46+
| components | (wip) |
47+
48+
| **ReactNative** | |
49+
| ------------------------------ | :---: |
50+
| `StyleSheet` ||
51+
| `styled-components/native` ||
52+
| `@emotion/native` ||
53+
| `react-native-linear-gradient` | (wip) |
54+
| `react-native-svg` | (wip) |
55+
| `expo` | (wip) |
56+
57+
| **Vanilla** | |
58+
| ----------- | :-----------: |
59+
| reflect-ui | right-aligned |
60+
| css ||
61+
| scss | are neat |
62+
63+
| **Flutter** | |
64+
| ----------- | :---: |
65+
| material ||
66+
| cupertino | (wip) |
67+
| reflect-ui | (wip) |
68+
69+
| **Svelte** | |
70+
| ------------------- | :---: |
71+
| `styled-components` ||
72+
| `@mui/material` | (wip) |
73+
74+
| **Vue** | |
75+
| ------------------- | :---: |
76+
| `styled-components` ||
77+
| `@mui/material` | (wip) |
78+
79+
| **iOS** | |
80+
| ------- | :---: |
81+
| SwiftUI | (wip) |
82+
83+
| **Android** | |
84+
| --------------- | :---: |
85+
| Jetpack Compose | (wip) |
86+
2887
## What does it mean?
2988

3089
### By "design". What does it mean?

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
Handler,
55
WebKitGestureEvent,
66
SharedGestureState,
7+
FullGestureState,
78
} from "@use-gesture/react";
89

910
export type OnPanningHandler = Handler<"wheel", WheelEvent>;
@@ -15,6 +16,8 @@ export type OnZoomingHandler = Handler<
1516

1617
export type OnPointerMoveHandler = Handler<"move">;
1718

19+
export type OnDragHandler = Handler<"drag">;
20+
1821
export type OnPointerDownHandler = (
1922
e: { event: React.MouseEvent<EventTarget, MouseEvent> } & SharedGestureState
2023
) => void;
@@ -32,6 +35,9 @@ export function CanvasEventTarget({
3235
onPointerMoveStart,
3336
onPointerMoveEnd,
3437
onPointerDown,
38+
onDrag,
39+
onDragStart,
40+
onDragEnd,
3541
children,
3642
}: {
3743
onPanning: OnPanningHandler;
@@ -44,6 +50,9 @@ export function CanvasEventTarget({
4450
onPointerMoveStart: OnPointerMoveHandler;
4551
onPointerMoveEnd: OnPointerMoveHandler;
4652
onPointerDown: OnPointerDownHandler;
53+
onDrag: OnDragHandler;
54+
onDragStart: OnDragHandler;
55+
onDragEnd: OnDragHandler;
4756
children?: React.ReactNode;
4857
}) {
4958
const interactionEventTargetRef = useRef();
@@ -84,6 +93,9 @@ export function CanvasEventTarget({
8493
};
8594
};
8695

96+
const [first_wheel_event, set_first_wheel_event] =
97+
useState<FullGestureState<"wheel">>();
98+
8799
useGesture(
88100
{
89101
onPinch: onZooming,
@@ -99,40 +111,65 @@ export function CanvasEventTarget({
99111
return;
100112
} else {
101113
// only for mac
102-
if (s.metaKey) {
114+
// TODO: on firefox, cmd + scroll resizes the window zoom level. this should be prevented.
115+
if (s.metaKey && first_wheel_event?.metaKey) {
103116
onZooming(transform_wheel_to_zoom(s));
104-
// TODO: on firefox, cmd + scroll resizes the window zoom level. this should be prevented.
105117
return;
106118
}
119+
if (first_wheel_event && first_wheel_event.metaKey) {
120+
if (
121+
Math.sign(first_wheel_event.direction[0]) ==
122+
Math.sign(s.direction[0])
123+
) {
124+
onZooming(transform_wheel_to_zoom(s));
125+
return;
126+
} else {
127+
// direction inverted, setting new state.
128+
set_first_wheel_event(s);
129+
}
130+
}
107131
}
108132
onPanning(s);
109133
s.event.stopPropagation();
110134
s.event.preventDefault();
111135
},
112136
onWheelStart: (s) => {
137+
set_first_wheel_event(s);
113138
onPanningStart(s);
114139
s.event.stopPropagation();
115140
s.event.preventDefault();
116141
},
117-
onWheelEnd: onPanningEnd,
142+
onWheelEnd: (s) => {
143+
set_first_wheel_event(undefined);
144+
onPanningEnd(s);
145+
},
118146
onMove: onPointerMove,
119147
onDragStart: (s) => {
120148
if (isSpacebarPressed) {
121149
onPanningStart(s as any);
150+
return;
122151
}
152+
153+
onDragStart(s);
123154
},
124155
onDrag: (s) => {
125156
if (isSpacebarPressed) {
126157
onPanning({
127158
...s,
128159
delta: [-s.delta[0], -s.delta[1]],
129160
} as any);
161+
return;
130162
}
163+
164+
onDrag(s);
131165
},
132166
onDragEnd: (s) => {
133167
if (isSpacebarPressed) {
134168
onPanningEnd(s as any);
169+
return;
135170
}
171+
172+
onDragEnd(s);
136173
},
137174
onMouseDown: onPointerDown,
138175
onMoveStart: onPointerMoveStart,

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import {
77
OnZoomingHandler,
88
OnPointerMoveHandler,
99
OnPointerDownHandler,
10+
OnDragHandler,
1011
} from "../canvas-event-target";
1112
import { get_hovering_target, centerOf } from "../math";
1213
import { utils } from "@design-sdk/core";
1314
import { LazyFrame } from "@code-editor/canvas/lazy-frame";
1415
import { HudCustomRenderers, HudSurface } from "./hud-surface";
15-
import type { Box, XY, CanvasTransform } from "../types";
16+
import type { Box, XY, CanvasTransform, XYWH } from "../types";
1617
import type { FrameOptimizationFactors } from "../frame";
1718
const designq = utils.query;
1819

@@ -48,10 +49,23 @@ type CanvasCustomRenderers = HudCustomRenderers & {
4849

4950
interface CanvsPreferences {
5051
can_highlight_selected_layer?: boolean;
52+
marquee: MarqueeOprions;
53+
}
54+
55+
interface MarqueeOprions {
56+
/**
57+
* disable marquee - events and selection with dragging.
58+
*
59+
* @default false
60+
*/
61+
disabled?: boolean;
5162
}
5263

5364
const default_canvas_preferences: CanvsPreferences = {
5465
can_highlight_selected_layer: false,
66+
marquee: {
67+
disabled: false,
68+
},
5569
};
5670

5771
interface HovringNode {
@@ -117,6 +131,8 @@ export function Canvas({
117131
? [offset[0] / zoom, offset[1] / zoom]
118132
: [0, 0];
119133
const [isPanning, setIsPanning] = useState(false);
134+
const [marquee, setMarquee] = useState<XYWH>(null);
135+
120136
const cvtransform: CanvasTransform = {
121137
scale: zoom,
122138
xy: offset,
@@ -207,6 +223,29 @@ export function Canvas({
207223
setOffset([newx, newy]);
208224
};
209225

226+
const onDrag: OnDragHandler = (s) => {
227+
const [x1, y1] = s.initial;
228+
const [x2, y2] = [
229+
// @ts-ignore
230+
s.event.clientX,
231+
// @ts-ignore
232+
s.event.clientY,
233+
];
234+
235+
const [ox, oy] = offset;
236+
const [x, y, w, h] = [
237+
x1 - ox,
238+
y1 - oy,
239+
x2 - x1, // w
240+
y2 - y1, // h
241+
];
242+
setMarquee([x, y, w, h]);
243+
};
244+
245+
const onDragEnd: OnDragHandler = (s) => {
246+
setMarquee(null);
247+
};
248+
210249
const is_canvas_transforming = isPanning || isZooming;
211250
const selected_nodes = selectedNodes
212251
?.map((id) => designq.find_node_by_id_under_inpage_nodes(id, nodes))
@@ -217,6 +256,9 @@ export function Canvas({
217256
node["filekey"] = filekey;
218257
return (
219258
<LazyFrame key={node.id} xy={[node.x, node.y]} size={node}>
259+
{/* 👇 dev only (for performance tracking) 👇 */}
260+
{/* <div style={{ width: "100%", height: "100%", background: "grey" }} /> */}
261+
{/* 👆 ----------------------------------- 👆 */}
220262
{renderItem({
221263
node: node as ReflectSceneNode & { filekey: string },
222264
zoom, // ? use scaled_zoom ?
@@ -257,12 +299,17 @@ export function Canvas({
257299
onPointerMoveStart={() => {}}
258300
onPointerMoveEnd={() => {}}
259301
onPointerDown={onPointerDown}
302+
onDrag={onDrag}
303+
onDragStart={() => {}} // TODO:
304+
onDragEnd={onDragEnd}
260305
>
261306
<HudSurface
262307
offset={nonscaled_offset}
263308
zoom={zoom}
264309
hide={is_canvas_transforming}
265310
readonly={readonly}
311+
disableMarquee={config.marquee.disabled}
312+
marquee={marquee}
266313
labelDisplayNodes={nodes}
267314
selectedNodes={selected_nodes}
268315
highlights={

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { HoverOutlineHighlight, ReadonlySelectHightlight } from "../overlay";
33
import { FrameTitle, FrameTitleProps } from "../frame-title";
44
import type { XY, XYWH } from "../types";
5-
5+
import { Marquee } from "../marquee";
66
interface HudControls {
77
onSelectNode: (node: string) => void;
88
onHoverNode: (node: string) => void;
@@ -34,6 +34,8 @@ export function HudSurface({
3434
readonly,
3535
onSelectNode,
3636
onHoverNode,
37+
marquee,
38+
disableMarquee = false,
3739
//
3840
renderFrameTitle = frame_title_default_renderer,
3941
}: {
@@ -43,6 +45,8 @@ export function HudSurface({
4345
labelDisplayNodes: DisplayNodeMeta[];
4446
selectedNodes: DisplayNodeMeta[];
4547
hide: boolean;
48+
marquee?: XYWH;
49+
disableMarquee?: boolean;
4650
readonly: boolean;
4751
} & HudControls &
4852
HudCustomRenderers) {
@@ -63,6 +67,7 @@ export function HudSurface({
6367
}}
6468
id="hud-surface"
6569
>
70+
{!disableMarquee && marquee && <Marquee rect={marquee} />}
6671
{!hide && (
6772
<>
6873
{labelDisplayNodes &&
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Marquee (Drag selection)
2+
3+
This directory only contributes to the drawn visible area of the drag, not contributes or contains any logic related to selection calculation. - VIEW ONLY COMPONENT.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Marquee } from "./marquee";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from "react";
2+
import type { XYWH } from "../types";
3+
4+
const canvasSelectionRectBackgroundColor = "rgba(0, 87, 255, 0.15)";
5+
const canvasSelectionRectBorderColor = "rgb(0, 87, 255)";
6+
7+
export function Marquee({ rect }: { rect: XYWH }) {
8+
const [x, y, ow, oh] = rect;
9+
10+
let [w, h, r] = [ow, oh, 0];
11+
if (w < 0 && h >= 0) {
12+
w = oh;
13+
h = ow;
14+
r = 90;
15+
} else if (h < 0 && w >= 0) {
16+
r = -90;
17+
w = oh;
18+
h = ow;
19+
} else if (w < 0 && h < 0) {
20+
r = 180;
21+
} else {
22+
r = 0;
23+
}
24+
25+
return (
26+
<div
27+
style={{
28+
position: "absolute",
29+
backgroundColor: canvasSelectionRectBackgroundColor,
30+
width: Math.abs(w),
31+
height: Math.abs(h),
32+
willChange: "transform, opacity",
33+
transformOrigin: "0px 0px",
34+
transform: `translateX(${x}px) translateY(${y}px) rotate(${r}deg)`,
35+
border: `${canvasSelectionRectBorderColor} 1px solid`,
36+
}}
37+
></div>
38+
);
39+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export function centerOf(
5555
vbcenter[1] - boxcenter[1] * scale,
5656
];
5757

58-
console.log(translate, scale);
59-
6058
return {
6159
box: box,
6260
center: boxcenter,

0 commit comments

Comments
 (0)