Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1ce5e45
update meta zooming handler
softmarshmallow Jan 29, 2022
a21a45b
fix build
softmarshmallow Jan 30, 2022
da6c4e1
add marquee
softmarshmallow Jan 31, 2022
6005e0a
add marquee docs
softmarshmallow Feb 1, 2022
b1dd5f0
add meta wheel disable on firefox
softmarshmallow Feb 2, 2022
33165ae
fix scene card being stretched by image size on safari
softmarshmallow Feb 2, 2022
6956b2d
wip add iframe canvas model
softmarshmallow Feb 2, 2022
c45d530
temporal disable of marquee
softmarshmallow Feb 4, 2022
2a20640
add initial rn builder packages
softmarshmallow Feb 4, 2022
e42339d
organize rn package, add RNText declaration as an initial example
softmarshmallow Feb 4, 2022
8603da8
bump package version to match rn's npm package version - 0.67.0
softmarshmallow Feb 4, 2022
bd71169
add RN View declaration
softmarshmallow Feb 4, 2022
58069d2
update rn view types
softmarshmallow Feb 6, 2022
f23a8fd
bump design sdk
softmarshmallow Feb 7, 2022
bcba540
rm unused page
softmarshmallow Feb 7, 2022
2e3a240
add inline-css config
softmarshmallow Feb 7, 2022
f28e055
rm log
softmarshmallow Feb 7, 2022
47164bf
add inline css builder (attributes modification not ready)
softmarshmallow Feb 7, 2022
3a9fe89
add self closing jsx support
softmarshmallow Feb 8, 2022
c26b679
add initial support for inline css object support for react
softmarshmallow Feb 8, 2022
6022a79
dirty fix of string literal complex of object expression under js obj
softmarshmallow Feb 8, 2022
e373d03
Merge pull request #118 from gridaco/support-css-in-js
softmarshmallow Feb 8, 2022
683f858
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Feb 8, 2022
2c29a8b
update coli url for git submodule
softmarshmallow Feb 15, 2022
43a40d1
add react-native framework config
softmarshmallow Feb 15, 2022
955747b
add boilerplate rn build support (wip)
softmarshmallow Feb 16, 2022
92b857f
update names
softmarshmallow Feb 17, 2022
cb56d75
add css module build support for react
softmarshmallow Feb 17, 2022
59712cf
add code control option for react css module style building
softmarshmallow Feb 17, 2022
e517eb4
setup packages
softmarshmallow Feb 17, 2022
72268f0
move core packages for react to react-core
softmarshmallow Feb 17, 2022
0ebfb82
update rn packages
softmarshmallow Feb 17, 2022
c580329
update margin, padding handling with reflect core utils
softmarshmallow Feb 17, 2022
7e244bd
mimic updates
softmarshmallow Feb 17, 2022
06272eb
add react-native as dev deps for typings
softmarshmallow Feb 17, 2022
4fad7d7
relocation
softmarshmallow Feb 17, 2022
95090b6
add react-native jsx based widgets
softmarshmallow Feb 17, 2022
dfe82ef
add initial react-native code gen support
softmarshmallow Feb 18, 2022
5eb27f3
add initial StyleSheet build support for react-native
softmarshmallow Feb 19, 2022
834e363
fix image src attr assignment
softmarshmallow Feb 19, 2022
d9b0313
fix coli type
softmarshmallow Feb 19, 2022
4a05757
add styled-components support for react-native (styled-components/nat…
softmarshmallow Feb 19, 2022
f592616
add react-native-svg support (incomplete)
softmarshmallow Feb 19, 2022
77576b4
update rm rn unsupported properties
softmarshmallow Feb 19, 2022
d066ad1
add react-native inline-style styling support
softmarshmallow Feb 19, 2022
f5c1dcc
fix rn style extensoin to allow only valid rn properties
softmarshmallow Feb 19, 2022
b09c45f
Merge pull request #117 from gridaco/react-native
softmarshmallow Feb 19, 2022
93318b2
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Feb 19, 2022
8fb5040
add meta data to import page
softmarshmallow Feb 20, 2022
e7f8f7c
Merge branch 'main' of https://github.com/gridaco/designto-code into …
softmarshmallow Feb 20, 2022
39dac80
fix import
softmarshmallow Feb 20, 2022
b774334
fix flex-grow property handling
softmarshmallow Feb 22, 2022
45d4c2d
add elliptical border radius fallback
softmarshmallow Feb 22, 2022
3729384
add rn border style building safety
softmarshmallow Feb 22, 2022
038cac9
update result signature & prevent editor flickering by state
softmarshmallow Feb 22, 2022
5f41834
Merge pull request #121 from gridaco/support-flex
softmarshmallow Feb 22, 2022
6c1ede3
Merge branch 'main' of https://github.com/gridaco/designto-code into …
softmarshmallow Feb 22, 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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
url = https://github.com/gridaco/base-sdk
[submodule "externals/coli"]
path = externals/coli
url = https://github.com/bridgedxyz/coli
url = https://github.com/gridaco/coli
[submodule "externals/design-sdk"]
path = externals/design-sdk
url = https://github.com/gridaco/design-sdk
Expand Down
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,65 @@ yarn editor

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

## Platforms / Frameworks

| **Frameworks** | |
| ------------------ | :---: |
| ReactJS | ✅ |
| Flutter | ✅ |
| React Native | ✅ |
| Vanilla (html/css) | ✅ |
| Vue | (wip) |

| **ReactJS** | |
| ------------------- | :---: |
| `styled-components` | ✅ |
| `@emotion/styled` | ✅ |
| css-modules | ✅ |
| inline-css | ✅ |
| `@mui/material` | (wip) |
| breakpoints | (wip) |
| components | (wip) |

| **ReactNative** | |
| ------------------------------ | :---: |
| `StyleSheet` | ✅ |
| `styled-components/native` | ✅ |
| `@emotion/native` | ✅ |
| `react-native-linear-gradient` | (wip) |
| `react-native-svg` | (wip) |
| `expo` | (wip) |

| **Vanilla** | |
| ----------- | :-----------: |
| reflect-ui | right-aligned |
| css | ✅ |
| scss | are neat |

| **Flutter** | |
| ----------- | :---: |
| material | ✅ |
| cupertino | (wip) |
| reflect-ui | (wip) |

| **Svelte** | |
| ------------------- | :---: |
| `styled-components` | ✅ |
| `@mui/material` | (wip) |

| **Vue** | |
| ------------------- | :---: |
| `styled-components` | ✅ |
| `@mui/material` | (wip) |

| **iOS** | |
| ------- | :---: |
| SwiftUI | (wip) |

| **Android** | |
| --------------- | :---: |
| Jetpack Compose | (wip) |

## What does it mean?

### By "design". What does it mean?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Handler,
WebKitGestureEvent,
SharedGestureState,
FullGestureState,
} from "@use-gesture/react";

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

export type OnPointerMoveHandler = Handler<"move">;

export type OnDragHandler = Handler<"drag">;

export type OnPointerDownHandler = (
e: { event: React.MouseEvent<EventTarget, MouseEvent> } & SharedGestureState
) => void;
Expand All @@ -32,6 +35,9 @@ export function CanvasEventTarget({
onPointerMoveStart,
onPointerMoveEnd,
onPointerDown,
onDrag,
onDragStart,
onDragEnd,
children,
}: {
onPanning: OnPanningHandler;
Expand All @@ -44,6 +50,9 @@ export function CanvasEventTarget({
onPointerMoveStart: OnPointerMoveHandler;
onPointerMoveEnd: OnPointerMoveHandler;
onPointerDown: OnPointerDownHandler;
onDrag: OnDragHandler;
onDragStart: OnDragHandler;
onDragEnd: OnDragHandler;
children?: React.ReactNode;
}) {
const interactionEventTargetRef = useRef();
Expand Down Expand Up @@ -84,6 +93,9 @@ export function CanvasEventTarget({
};
};

const [first_wheel_event, set_first_wheel_event] =
useState<FullGestureState<"wheel">>();

useGesture(
{
onPinch: onZooming,
Expand All @@ -99,40 +111,65 @@ export function CanvasEventTarget({
return;
} else {
// only for mac
if (s.metaKey) {
// TODO: on firefox, cmd + scroll resizes the window zoom level. this should be prevented.
if (s.metaKey && first_wheel_event?.metaKey) {
onZooming(transform_wheel_to_zoom(s));
// TODO: on firefox, cmd + scroll resizes the window zoom level. this should be prevented.
return;
}
if (first_wheel_event && first_wheel_event.metaKey) {
if (
Math.sign(first_wheel_event.direction[0]) ==
Math.sign(s.direction[0])
) {
onZooming(transform_wheel_to_zoom(s));
return;
} else {
// direction inverted, setting new state.
set_first_wheel_event(s);
}
}
}
onPanning(s);
s.event.stopPropagation();
s.event.preventDefault();
},
onWheelStart: (s) => {
set_first_wheel_event(s);
onPanningStart(s);
s.event.stopPropagation();
s.event.preventDefault();
},
onWheelEnd: onPanningEnd,
onWheelEnd: (s) => {
set_first_wheel_event(undefined);
onPanningEnd(s);
},
onMove: onPointerMove,
onDragStart: (s) => {
if (isSpacebarPressed) {
onPanningStart(s as any);
return;
}

onDragStart(s);
},
onDrag: (s) => {
if (isSpacebarPressed) {
onPanning({
...s,
delta: [-s.delta[0], -s.delta[1]],
} as any);
return;
}

onDrag(s);
},
onDragEnd: (s) => {
if (isSpacebarPressed) {
onPanningEnd(s as any);
return;
}

onDragEnd(s);
},
onMouseDown: onPointerDown,
onMoveStart: onPointerMoveStart,
Expand Down
49 changes: 48 additions & 1 deletion editor-packages/editor-canvas/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
OnZoomingHandler,
OnPointerMoveHandler,
OnPointerDownHandler,
OnDragHandler,
} from "../canvas-event-target";
import { get_hovering_target, centerOf } from "../math";
import { utils } from "@design-sdk/core";
import { LazyFrame } from "@code-editor/canvas/lazy-frame";
import { HudCustomRenderers, HudSurface } from "./hud-surface";
import type { Box, XY, CanvasTransform } from "../types";
import type { Box, XY, CanvasTransform, XYWH } from "../types";
import type { FrameOptimizationFactors } from "../frame";
const designq = utils.query;

Expand Down Expand Up @@ -48,10 +49,23 @@ type CanvasCustomRenderers = HudCustomRenderers & {

interface CanvsPreferences {
can_highlight_selected_layer?: boolean;
marquee: MarqueeOprions;
}

interface MarqueeOprions {
/**
* disable marquee - events and selection with dragging.
*
* @default false
*/
disabled?: boolean;
}

const default_canvas_preferences: CanvsPreferences = {
can_highlight_selected_layer: false,
marquee: {
disabled: false,
},
};

interface HovringNode {
Expand Down Expand Up @@ -117,6 +131,8 @@ export function Canvas({
? [offset[0] / zoom, offset[1] / zoom]
: [0, 0];
const [isPanning, setIsPanning] = useState(false);
const [marquee, setMarquee] = useState<XYWH>(null);

const cvtransform: CanvasTransform = {
scale: zoom,
xy: offset,
Expand Down Expand Up @@ -207,6 +223,29 @@ export function Canvas({
setOffset([newx, newy]);
};

const onDrag: OnDragHandler = (s) => {
const [x1, y1] = s.initial;
const [x2, y2] = [
// @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 onDragEnd: OnDragHandler = (s) => {
setMarquee(null);
};

const is_canvas_transforming = isPanning || isZooming;
const selected_nodes = selectedNodes
?.map((id) => designq.find_node_by_id_under_inpage_nodes(id, nodes))
Expand All @@ -217,6 +256,9 @@ export function Canvas({
node["filekey"] = filekey;
return (
<LazyFrame key={node.id} xy={[node.x, node.y]} size={node}>
{/* 👇 dev only (for performance tracking) 👇 */}
{/* <div style={{ width: "100%", height: "100%", background: "grey" }} /> */}
{/* 👆 ----------------------------------- 👆 */}
{renderItem({
node: node as ReflectSceneNode & { filekey: string },
zoom, // ? use scaled_zoom ?
Expand Down Expand Up @@ -257,12 +299,17 @@ export function Canvas({
onPointerMoveStart={() => {}}
onPointerMoveEnd={() => {}}
onPointerDown={onPointerDown}
onDrag={onDrag}
onDragStart={() => {}} // TODO:
onDragEnd={onDragEnd}
>
<HudSurface
offset={nonscaled_offset}
zoom={zoom}
hide={is_canvas_transforming}
readonly={readonly}
disableMarquee={config.marquee.disabled}
marquee={marquee}
labelDisplayNodes={nodes}
selectedNodes={selected_nodes}
highlights={
Expand Down
7 changes: 6 additions & 1 deletion editor-packages/editor-canvas/canvas/hud-surface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { HoverOutlineHighlight, ReadonlySelectHightlight } from "../overlay";
import { FrameTitle, FrameTitleProps } from "../frame-title";
import type { XY, XYWH } from "../types";

import { Marquee } from "../marquee";
interface HudControls {
onSelectNode: (node: string) => void;
onHoverNode: (node: string) => void;
Expand Down Expand Up @@ -34,6 +34,8 @@ export function HudSurface({
readonly,
onSelectNode,
onHoverNode,
marquee,
disableMarquee = false,
//
renderFrameTitle = frame_title_default_renderer,
}: {
Expand All @@ -43,6 +45,8 @@ export function HudSurface({
labelDisplayNodes: DisplayNodeMeta[];
selectedNodes: DisplayNodeMeta[];
hide: boolean;
marquee?: XYWH;
disableMarquee?: boolean;
readonly: boolean;
} & HudControls &
HudCustomRenderers) {
Expand All @@ -63,6 +67,7 @@ export function HudSurface({
}}
id="hud-surface"
>
{!disableMarquee && marquee && <Marquee rect={marquee} />}
{!hide && (
<>
{labelDisplayNodes &&
Expand Down
3 changes: 3 additions & 0 deletions editor-packages/editor-canvas/marquee/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Marquee (Drag selection)

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.
1 change: 1 addition & 0 deletions editor-packages/editor-canvas/marquee/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Marquee } from "./marquee";
39 changes: 39 additions & 0 deletions editor-packages/editor-canvas/marquee/marquee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";
import type { XYWH } from "../types";

const canvasSelectionRectBackgroundColor = "rgba(0, 87, 255, 0.15)";
const canvasSelectionRectBorderColor = "rgb(0, 87, 255)";

export function Marquee({ rect }: { rect: XYWH }) {
const [x, y, ow, oh] = rect;

let [w, h, r] = [ow, oh, 0];
if (w < 0 && h >= 0) {
w = oh;
h = ow;
r = 90;
} else if (h < 0 && w >= 0) {
r = -90;
w = oh;
h = ow;
} else if (w < 0 && h < 0) {
r = 180;
} else {
r = 0;
}

return (
<div
style={{
position: "absolute",
backgroundColor: canvasSelectionRectBackgroundColor,
width: Math.abs(w),
height: Math.abs(h),
willChange: "transform, opacity",
transformOrigin: "0px 0px",
transform: `translateX(${x}px) translateY(${y}px) rotate(${r}deg)`,
border: `${canvasSelectionRectBorderColor} 1px solid`,
}}
></div>
);
}
2 changes: 0 additions & 2 deletions editor-packages/editor-canvas/math/center-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export function centerOf(
vbcenter[1] - boxcenter[1] * scale,
];

console.log(translate, scale);

return {
box: box,
center: boxcenter,
Expand Down
Loading