Skip to content

Commit 7ac256e

Browse files
Merge pull request #188 from gridaco/staging
Coding playground & transpiler updates
2 parents d85e866 + 187fc4c commit 7ac256e

183 files changed

Lines changed: 10119 additions & 6988 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.

CONTRIBUTING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Installation & Build
32

43
```
@@ -8,20 +7,13 @@ yarn
87
yarn editor
98
```
109

11-
12-
## Setup credentials for development
13-
14-
visit http://localhost:6626/preferences/access-tokens and set pats for api calls
15-
16-
1710
## Structure
1811

1912
- editor - visual editor for development
2013
- editor-packages - editor related packages
2114
- packages - core packages contributing to the code-gen logic
2215
- externals - external foundational packages, like [reflect-core](https://github.com/reflect-ui/reflect-core-ts)
2316

24-
2517
# Why 6626?
2618

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

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

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import type {
99

1010
export type OnPanningHandler = Handler<"wheel", WheelEvent>;
1111

12+
export type OnPanningStartHandler = () => void;
13+
14+
export type OnPanningEndHandler = () => void;
15+
1216
export type OnZoomingHandler = Handler<
1317
"pinch",
1418
WheelEvent | PointerEvent | TouchEvent | WebKitGestureEvent
@@ -45,8 +49,8 @@ export function CanvasEventTarget({
4549
{
4650
onZoomToFit?: () => void;
4751
onPanning: OnPanningHandler;
48-
onPanningStart: OnPanningHandler;
49-
onPanningEnd: OnPanningHandler;
52+
onPanningStart: OnPanningStartHandler;
53+
onPanningEnd: OnPanningEndHandler;
5054
onZooming: OnZoomingHandler;
5155
onZoomingStart: OnZoomingHandler;
5256
onZoomingEnd: OnZoomingHandler;
@@ -64,37 +68,68 @@ export function CanvasEventTarget({
6468
const interactionEventTargetRef = useRef();
6569

6670
const [isSpacebarPressed, setIsSpacebarPressed] = useState(false);
71+
const [isAuxPressed, setIsAuxPressed] = useState(false);
72+
73+
const panningMetaKeyPressed = isSpacebarPressed || isAuxPressed;
74+
6775
let platform: PlatformName = "other";
6876
useEffect(() => {
6977
platform = getCurrentPlatform(window.navigator);
7078
});
7179

7280
useEffect(() => {
7381
const kd = (e) => {
74-
// if spacebar is pressed, enable panning wirt dragging.
82+
// if spacebar is pressed, enable panning with dragging.
7583
if (e.code === "Space") {
7684
setIsSpacebarPressed(true);
7785
}
86+
7887
// if shift + 0
7988
else if (e.code === "Digit0" && e.shiftKey) {
8089
onZoomToFit?.();
8190
}
8291
};
8392
const ku = (e) => {
93+
// space bar
8494
if (e.code === "Space") {
8595
setIsSpacebarPressed(false);
8696
}
8797
};
98+
const md = (e) => {
99+
// mouse weehl (physical) - as well as space bar, mouse wheel + drag will enable panning.
100+
if (e.button === 1) {
101+
setIsAuxPressed(true);
102+
}
103+
};
104+
105+
const mu = (e) => {
106+
// mouse wheel (physical)
107+
if (e.button === 1) {
108+
setIsAuxPressed(false);
109+
}
110+
};
88111

89112
document.addEventListener("keydown", kd);
90113
document.addEventListener("keyup", ku);
114+
document.addEventListener("mousedown", md);
115+
document.addEventListener("mouseup", mu);
91116

92117
return () => {
93118
document.removeEventListener("keydown", kd);
94119
document.removeEventListener("keyup", ku);
120+
document.removeEventListener("mousedown", md);
121+
document.removeEventListener("mouseup", mu);
95122
};
96123
}, []);
97124

125+
useEffect(() => {
126+
if (isAuxPressed) {
127+
onPanningStart?.();
128+
} else {
129+
onPanningEnd?.();
130+
}
131+
}, [isAuxPressed]);
132+
98133
const transform_wheel_to_zoom = (s) => {
99134
return {
100135
...s,
@@ -148,18 +183,30 @@ export function CanvasEventTarget({
148183
},
149184
onWheelStart: (s) => {
150185
set_first_wheel_event(s);
151-
onPanningStart(s);
186+
onPanningStart();
152187
s.event.stopPropagation();
153188
s.event.preventDefault();
154189
},
155190
onWheelEnd: (s) => {
156191
set_first_wheel_event(undefined);
157-
onPanningEnd(s);
192+
onPanningEnd();
193+
},
194+
onMove: (s) => {
195+
if (isAuxPressed) {
196+
// @ts-ignore
197+
onPanning({
198+
...s,
199+
// reverse delta
200+
delta: [-s.delta[0], -s.delta[1]],
201+
});
202+
return;
203+
} else {
204+
onPointerMove(s);
205+
}
158206
},
159-
onMove: onPointerMove,
160207
onDragStart: (s) => {
161-
if (isSpacebarPressed) {
162-
onPanningStart(s as any);
208+
if (panningMetaKeyPressed) {
209+
onPanningStart();
163210
return;
164211
}
165212

@@ -169,7 +216,7 @@ export function CanvasEventTarget({
169216
}
170217
},
171218
onDrag: (s) => {
172-
if (isSpacebarPressed) {
219+
if (panningMetaKeyPressed) {
173220
onPanning({
174221
...s,
175222
delta: [-s.delta[0], -s.delta[1]],
@@ -184,8 +231,8 @@ export function CanvasEventTarget({
184231
onDrag(s);
185232
},
186233
onDragEnd: (s) => {
187-
if (isSpacebarPressed) {
188-
onPanningEnd(s as any);
234+
if (panningMetaKeyPressed) {
235+
onPanningEnd();
189236
return;
190237
}
191238

@@ -214,7 +261,7 @@ export function CanvasEventTarget({
214261
inset: 0,
215262
overflow: "hidden",
216263
touchAction: "none",
217-
cursor: isSpacebarPressed ? "grab" : cursor,
264+
cursor: panningMetaKeyPressed ? "grab" : cursor,
218265
userSelect: "none",
219266
WebkitUserSelect: "none",
220267
}}

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import {
2929
CANVAS_INITIAL_SCALE,
3030
CANVAS_MIN_ZOOM,
3131
} from "../k";
32-
import { ContextMenuRoot as ContextMenu } from "@editor-ui/context-menu";
32+
import {
33+
ContextMenuRoot as ContextMenu,
34+
MenuItem,
35+
} from "@editor-ui/context-menu";
3336
import styled from "@emotion/styled";
3437

3538
interface CanvasState {
@@ -435,7 +438,8 @@ export function Canvas({
435438

436439
return (
437440
<>
438-
<ContextMenuProvider>
441+
<>
442+
{/* <ContextMenuProvider> */}
439443
<Container
440444
// todo: viewbound not accurate.
441445
// width={viewbound[2] - viewbound[0]}
@@ -505,7 +509,8 @@ export function Canvas({
505509
/>
506510
</CanvasEventTarget>
507511
</Container>
508-
</ContextMenuProvider>
512+
{/* </ContextMenuProvider> */}
513+
</>
509514
<CanvasBackground backgroundColor={backgroundColor} />
510515
<CanvasTransformRoot scale={zoom} xy={nonscaled_offset}>
511516
<DisableBackdropFilter>{items}</DisableBackdropFilter>
@@ -600,18 +605,20 @@ function position_guide({
600605
}
601606

602607
function ContextMenuProvider({ children }: React.PropsWithChildren<{}>) {
608+
const items: MenuItem<string>[] = [
609+
{ title: "Show all layers", value: "canvas-focus-all-to-fit" },
610+
"separator",
611+
{ title: "Run", value: "run" },
612+
{ title: "Deploy", value: "deploy-to-vercel" },
613+
{ title: "Open in Figma", value: "open-in-figma" },
614+
{ title: "Get sharable link", value: "make-sharable-link" },
615+
{ title: "Copy CSS", value: "make-css" },
616+
{ title: "Refresh (fetch from origin)", value: "refresh" },
617+
];
618+
603619
return (
604620
<ContextMenu
605-
items={[
606-
{ title: "Show all layers", value: "canvas-focus-all-to-fit" },
607-
"separator",
608-
{ title: "Run", value: "run" },
609-
{ title: "Deploy", value: "deploy-to-vercel" },
610-
{ title: "Open in Figma", value: "open-in-figma" },
611-
{ title: "Get sharable link", value: "make-sharable-link" },
612-
{ title: "Copy CSS", value: "make-css" },
613-
{ title: "Refresh (fetch from origin)", value: "refresh" },
614-
]}
621+
items={items}
615622
onSelect={(v) => {
616623
console.log("exec canvas cmd", v);
617624
}}

editor-packages/editor-canvas/math/target-of-point.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export function target_of_point<T extends Tree>(
3636
},
3737
depth = 0
3838
): T | undefined {
39+
// prevalidators
40+
if (!tree) return;
41+
3942
const [ox, oy] = offset;
4043

4144
const items = reverse ? Array.from(tree).reverse() : tree;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export { Css3Icon } from "./module-css3-icon";
2+
export { ExpoIcon } from "./module-expo-icon";
3+
export { Html5Icon } from "./module-html5-icon";
4+
export { FlutterIcon } from "./module-icon-flutter";
5+
export { ReactIcon } from "./module-icon-react";
6+
export { SolidJsIcon } from "./module-icon-solid";
7+
export { SvelteIcon } from "./module-icon-svelte";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
3+
export function Css3Icon({
4+
size,
5+
color,
6+
}: {
7+
size: number;
8+
color: React.CSSProperties["color"];
9+
}) {
10+
return (
11+
<svg
12+
width={size}
13+
height={size}
14+
viewBox="0 0 64 64"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
fillRule="evenodd"
20+
clipRule="evenodd"
21+
d="M54.1947 56.4142L59.2001 0.341797H4.2583L9.25833 56.423L31.6956 62.6517L54.1947 56.4142ZM31.7052 11.8059H31.7051H14.4818L15.1071 18.6841L31.7052 18.6841L31.7289 18.6841L41.3972 18.6841L40.7713 25.7274H31.7052V25.7279H15.7206L16.337 32.606H31.729V32.6055H40.1749L39.3765 41.5259L31.7052 43.5964V43.5965L31.6991 43.5981L24.0389 41.5297L23.5492 36.0441H19.8269H16.6447L17.6083 46.8437L31.6976 50.755L31.7293 50.7462V50.7456L45.8057 46.8443L45.9092 45.6823L47.5255 27.5744L47.6933 25.7274L48.935 11.8059H31.7289H31.7052Z"
22+
fill={color}
23+
/>
24+
</svg>
25+
);
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
3+
export function ExpoIcon({
4+
size,
5+
color,
6+
}: {
7+
size: number;
8+
color: React.CSSProperties["color"];
9+
}) {
10+
return (
11+
<svg
12+
width={size}
13+
height={size}
14+
viewBox="0 0 64 64"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
d="M31.0303 25.3423C31.5383 24.5937 32.094 24.4984 32.5455 24.4984C32.9966 24.4984 33.7478 24.5937 34.2559 25.3423C38.2592 30.8419 44.868 41.7956 49.743 49.8763C52.9218 55.146 55.3635 59.193 55.8645 59.7081C57.7448 61.6418 60.3242 60.4363 61.8227 58.2436C63.2982 56.0843 63.7074 54.5682 63.7074 52.9506C63.7074 51.8489 42.3327 12.0956 40.1801 8.78659C38.11 5.60424 37.4356 4.80005 33.8922 4.80005H31.2408C27.7085 4.80005 27.1978 5.6038 25.1277 8.78659C22.9751 12.096 1.59998 51.8489 1.59998 52.951C1.59998 54.5682 2.00958 56.0843 3.48467 58.2431C4.9836 60.4368 7.56302 61.6418 9.44329 59.7085C9.94426 59.193 12.386 55.146 15.5652 49.8763C20.4394 41.7956 27.027 30.8419 31.0303 25.3423Z"
20+
fill={color}
21+
/>
22+
</svg>
23+
);
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
3+
export function Html5Icon({
4+
size,
5+
color,
6+
}: {
7+
size: number;
8+
color: React.CSSProperties["color"];
9+
}) {
10+
return (
11+
<svg
12+
width={size}
13+
height={size}
14+
viewBox="0 0 64 64"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
fillRule="evenodd"
20+
clipRule="evenodd"
21+
d="M4 0L9.13369 57.6218L32.1731 64L55.3058 57.5907L60.4395 0H4ZM14.0631 11.776H31.7665H31.7977H49.4699L48.8166 18.8387H31.7977H31.7665H21.8103L22.4637 26.0726H31.7665H31.7977H48.1787L46.2341 47.7585L31.7977 51.7635V51.8033L17.2989 47.7585L16.3033 36.6666H23.3971L23.8949 42.3137L31.7821 44.4252L39.6537 42.3137L40.4782 33.1353H31.7665V33.1197H15.9921L14.0631 11.776Z"
22+
fill={color}
23+
/>
24+
</svg>
25+
);
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
3+
export function FlutterIcon({
4+
size,
5+
color,
6+
}: {
7+
size: number;
8+
color: React.CSSProperties["color"];
9+
}) {
10+
return (
11+
<svg
12+
width={size}
13+
height={size}
14+
viewBox="0 0 64 64"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
fillRule="evenodd"
20+
clipRule="evenodd"
21+
d="M37.3859 1.62127L56.6024 1.6001L24.3624 33.8236L15.96 42.1789L6.40002 32.6072L37.3859 1.62127ZM37.2071 30.393C37.3835 30.1601 37.6646 30.1731 37.9373 30.1857H37.9373C38.0502 30.1909 38.1616 30.196 38.2636 30.1836L56.5859 30.1883L39.8873 46.8705L39.9271 46.9126L30.28 56.4702L20.6989 46.8867L30.2777 37.3196L30.2779 37.3199L37.2071 30.393ZM39.9272 46.9126L30.2801 56.4702L36.9578 63.1549C37.0023 63.1944 37.0466 63.2387 37.0916 63.2837C37.2775 63.4694 37.477 63.6687 37.7648 63.6044C40.9024 63.5973 44.04 63.5985 47.1779 63.5997C50.3159 63.6008 53.4542 63.602 56.593 63.595L39.9272 46.9126Z"
22+
fill={color}
23+
/>
24+
</svg>
25+
);
26+
}

0 commit comments

Comments
 (0)