Skip to content

Commit 5d87771

Browse files
updating with new universal design sdk
1 parent e39d7ca commit 5d87771

51 files changed

Lines changed: 200 additions & 101 deletions

Some content is hidden

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

editor/components/figma/screen-importer.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import React, { useEffect, useState } from "react";
2-
import { api } from "@bridged.xyz/design-sdk/lib/figma-remote";
1+
import React, { useState } from "react";
2+
import { remote, utils, nodes } from "@design-sdk/figma";
3+
import { convert } from "@design-sdk/figma";
34
import { utils_figma } from "../../utils";
4-
import { utils, convert } from "@bridged.xyz/design-sdk";
5-
import { mapFigmaRemoteToFigma } from "@bridged.xyz/design-sdk/lib/figma-remote/mapper";
6-
import { ReflectSceneNode } from "@bridged.xyz/design-sdk/lib/nodes";
75
import { UserInputCache } from "../../utils/user-input-value-cache";
8-
import * as figrem from "@bridged.xyz/design-sdk/lib/figma-remote/types";
96

10-
export type OnImportedCallback = (reflect: ReflectSceneNode) => void;
11-
type _OnRemoteLoadedCallback = (reflect: figrem.Node) => void;
7+
export type OnImportedCallback = (reflect: nodes.ReflectSceneNode) => void;
8+
type _OnRemoteLoadedCallback = (reflect: remote.types.Node) => void;
129

1310
async function fetchTarget(file: string, node: string) {
14-
const client = api.Client({
11+
const client = remote.api.Client({
1512
personalAccessToken: utils_figma.figmaPersonalAccessToken(),
1613
});
1714

@@ -27,7 +24,7 @@ async function fetchTarget(file: string, node: string) {
2724

2825
async function fetchDemo() {
2926
const _nid = utils_figma.FIGMA_BRIDGED_DEMO_APP_ENTRY_NODE_ID;
30-
const client = api.Client({
27+
const client = remote.api.Client({
3128
personalAccessToken: utils_figma.figmaPersonalAccessToken(),
3229
});
3330

@@ -46,11 +43,11 @@ async function fetchDemo() {
4643
}
4744

4845
export function FigmaScreenImporter(props: { onImported: OnImportedCallback }) {
49-
const [reflect, setReflect] = useState<ReflectSceneNode>();
46+
const [reflect, setReflect] = useState<nodes.ReflectSceneNode>();
5047

51-
const handleLocalDataLoad = (d: figrem.Node) => {
48+
const handleLocalDataLoad = (d: remote.types.Node) => {
5249
console.log("api raw", d);
53-
const _mapped = mapFigmaRemoteToFigma(d as any);
50+
const _mapped = remote.mapper.mapFigmaRemoteToFigma(d as any);
5451
console.log("mapped", _mapped);
5552
const _converted = convert.intoReflectNode(_mapped);
5653
console.log("converted", _converted);
@@ -85,7 +82,7 @@ function _DefaultImporterSegment(props: { onLoaded: _OnRemoteLoadedCallback }) {
8582
const handleOnLoadDefaultDesignClick = () => {
8683
fetchDemo().then((d) => {
8784
// it's okay to force cast here. since the typings are the same (following official figma remote api spec)
88-
props.onLoaded(d as figrem.Node);
85+
props.onLoaded(d as remote.types.Node);
8986
});
9087
};
9188

@@ -111,7 +108,7 @@ function _UrlImporterSegment(props: { onLoaded: _OnRemoteLoadedCallback }) {
111108
UserInputCache.set(_FIGMA_FILE_URL_IMPORT_INPUT_CACHE_KEY, urlInput);
112109
const q = utils.figmaApi.parseFileAndNodeIdFromUrl_Figma(urlInput);
113110
fetchTarget(q.file, q.node).then((d) => {
114-
props.onLoaded(d as figrem.Node);
111+
props.onLoaded(d as remote.types.Node);
115112
});
116113
};
117114

editor/next.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const withTM = require("next-transpile-modules")([
55
"@designto/web",
66
"@designto/react",
77
"@bridged.xyz/flutter-builder",
8-
"@bridged.xyz/design-sdk",
8+
"@design-sdk/core",
9+
"@design-sdk/universal",
10+
"@design-sdk/figma",
11+
"@design-sdk/sketch",
912
"@reflect-ui/core",
1013
"@reflect-ui/detection",
1114
]);

editor/pages/_development/figma.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useEffect, useState } from "react";
2-
import { figmacomp, canvas, code, runner } from "../../components";
31
import dynamic from "next/dynamic";
4-
import { flutter } from "@designto/code";
5-
import { composeAppWithHome } from "@bridged.xyz/flutter-builder/dist/lib/composer";
6-
import { utils_dart } from "../../utils";
2+
import React, { useEffect, useState } from "react";
73
import styled from "@emotion/styled";
4+
import { figmacomp, canvas, runner } from "../../components";
5+
import { flutter } from "@designto/code";
6+
import { composeAppWithHome } from "@bridged.xyz/flutter-builder";
87
import { features, types, hosting } from "@bridged.xyz/base-sdk";
9-
import { ReflectSceneNode } from "@bridged.xyz/design-sdk/lib/nodes";
8+
import { ReflectSceneNode } from "@design-sdk/core/nodes";
9+
import { utils_dart } from "../../utils";
1010
import { nanoid } from "nanoid";
1111

1212
const CodemirrorEditor = dynamic(

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"workspaces": [
88
"editor",
99
"packages/*",
10-
"packages/coli/packages/*"
10+
"packages/design-sdk/*",
11+
"packages/coli/packages/*",
12+
"packages/coli-web-builder/*"
1113
]
1214
}

packages/coli

Submodule coli updated from 398e147 to b78dff7

packages/coli-web-builder

packages/design-sdk

packages/designto-clean/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReflectSceneNode } from "@bridged.xyz/design-sdk/lib/nodes";
1+
import { ReflectSceneNode } from "@design-sdk/core/nodes";
22
import { ReflectLintFeedback } from "@reflect-ui/lint/lib/feedbacks/feedback";
33
import { DefaultSeectionLintRunner } from "@reflect-ui/lint/lib/linter";
44

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { convertToSize } from "../convert";
2+
import {
3+
ReflectRectangleNode,
4+
ReflectEllipseNode,
5+
ReflectFrameNode,
6+
ReflectGroupNode,
7+
} from "@design-sdk/core/nodes";
8+
import { makeEdgeInsets } from "../make";
9+
import { array } from "@reflect-ui/uiutils";
10+
import {
11+
Container,
12+
Widget,
13+
EdgeInsetsGeometry,
14+
Padding,
15+
Alignment,
16+
AlignmentGeometry,
17+
Color,
18+
BoxDecoration,
19+
Size,
20+
} from "@bridged.xyz/flutter-builder";
21+
import { makeBoxDecoration } from "../make/box-decoration.make";
22+
import { roundDouble } from "../convert/double.convert";
23+
24+
export function wrapWithContainer(
25+
node:
26+
| ReflectRectangleNode
27+
| ReflectEllipseNode
28+
| ReflectFrameNode
29+
| ReflectGroupNode,
30+
child?: Widget,
31+
options?: { size: Size }
32+
): Widget {
33+
// ignore the view when size is zero or less
34+
// while technically it shouldn't get less than 0, due to rounding errors,
35+
// it can get to values like: -0.000004196293048153166
36+
if (node.width <= 0 || node.height <= 0) {
37+
return child;
38+
}
39+
40+
// ignore for Groups
41+
const propBoxDecoration =
42+
node instanceof ReflectGroupNode ? undefined : makeBoxDecoration(node);
43+
// if option passed, use option's value
44+
const propSize = array.filters.notEmpty(options?.size)
45+
? options.size
46+
: convertToSize(node);
47+
console.log("propSize", propSize);
48+
49+
// todo Image, Gradient & multiple fills
50+
51+
let propPadding: EdgeInsetsGeometry;
52+
if (node instanceof ReflectFrameNode) {
53+
propPadding = makeEdgeInsets(node);
54+
}
55+
56+
if (propSize || propBoxDecoration) {
57+
// Container is a container if [propSize] or [propBoxDecoration] are set.
58+
// console.log("wrapping with container. child - ", child)
59+
return new Container({
60+
width: roundDouble(propSize.width),
61+
height: roundDouble(propSize.height),
62+
child: child,
63+
padding: propPadding,
64+
decoration:
65+
propBoxDecoration instanceof BoxDecoration
66+
? propBoxDecoration
67+
: undefined,
68+
color: propBoxDecoration instanceof Color ? propBoxDecoration : undefined,
69+
});
70+
} else if (propPadding) {
71+
// console.log("wrapping with padding")
72+
return new Padding({
73+
padding: propPadding,
74+
child: child,
75+
});
76+
// if there is just a padding, add Padding
77+
} else {
78+
return child;
79+
}
80+
}
81+
82+
type GradientDirection = {
83+
begin: AlignmentGeometry;
84+
end: AlignmentGeometry;
85+
};
86+
87+
export function gradientDirection(angle: number): GradientDirection {
88+
switch (
89+
array.nearestValue(angle, [-180, -135, -90, -45, 0, 45, 90, 135, 180])
90+
) {
91+
case 0:
92+
return { begin: Alignment.centerLeft, end: Alignment.centerRight };
93+
case 45:
94+
return { begin: Alignment.topLeft, end: Alignment.bottomRight };
95+
case 90:
96+
return { begin: Alignment.topCenter, end: Alignment.bottomCenter };
97+
case 135:
98+
return { begin: Alignment.topRight, end: Alignment.bottomLeft };
99+
case -45:
100+
return { begin: Alignment.bottomLeft, end: Alignment.topRight };
101+
case -90:
102+
return { begin: Alignment.bottomCenter, end: Alignment.topCenter };
103+
case -135:
104+
return { begin: Alignment.bottomRight, end: Alignment.topLeft };
105+
default:
106+
// when 180 or -180
107+
return { begin: Alignment.centerRight, end: Alignment.centerLeft };
108+
}
109+
}

packages/designto-code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@designto/flutter": "0.0.1",
99
"@designto/react": "0.0.0",
1010
"@designto/web": "0.0.0",
11-
"@bridged.xyz/design-sdk": "^0.1.0",
11+
"@design-sdk/universal": "0.0.0",
1212
"@reflect-ui/detection": "0.1.1",
1313
"@bridged.xyz/flutter-builder": "^1.23.0-7.0.pre.42"
1414
},

0 commit comments

Comments
 (0)