From d5c6dd49a2d59c2168e8162a987009768ccf9e9b Mon Sep 17 00:00:00 2001 From: Paulo Menezes Date: Sun, 5 Jan 2020 23:17:24 -0300 Subject: [PATCH] Styles fix (#190) * Styles improvements * Default values when restore elements --- src/index.tsx | 472 ++++++++++++++++++++++++-------------------------- 1 file changed, 229 insertions(+), 243 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 7e4f72b7..1b9c76b4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -842,25 +842,19 @@ function generateDraw(element: ExcalidrawElement) { }; } else if (element.type === "arrow") { const [x1, y1, x2, y2, x3, y3, x4, y4] = getArrowPoints(element); + const options = { + stroke: element.strokeColor, + strokeWidth: element.strokeWidth, + roughness: element.roughness + }; + const shapes = withCustomMathRandom(element.seed, () => [ // \ - generator.line(x3, y3, x2, y2, { - stroke: element.strokeColor, - strokeWidth: element.strokeWidth, - roughness: element.roughness - }), + generator.line(x3, y3, x2, y2, options), // ----- - generator.line(x1, y1, x2, y2, { - stroke: element.strokeColor, - strokeWidth: element.strokeWidth, - roughness: element.roughness - }), + generator.line(x1, y1, x2, y2, options), // / - generator.line(x4, y4, x2, y2, { - stroke: element.strokeColor, - strokeWidth: element.strokeWidth, - roughness: element.roughness - }) + generator.line(x4, y4, x2, y2, options) ]); element.draw = (rc, context, { scrollX, scrollY }) => { @@ -971,7 +965,17 @@ function restore( ? JSON.parse(savedElements) : savedElements) ); - elements.forEach((element: ExcalidrawElement) => generateDraw(element)); + elements.forEach((element: ExcalidrawElement) => { + element.fillStyle = element.fillStyle || "hachure"; + element.strokeWidth = element.strokeWidth || 1; + element.roughness = element.roughness || 1; + element.opacity = + element.opacity === null || element.opacity === undefined + ? 100 + : element.opacity; + + generateDraw(element); + }); } return savedState ? JSON.parse(savedState) : null; @@ -1106,7 +1110,7 @@ function getSelectedIndices() { const someElementIsSelected = () => elements.some(element => element.isSelected); -const someElementIsSelectedIsRectangleOrEllipseOrDiamond = () => +const hasBackground = () => elements.some( element => element.isSelected && @@ -1115,7 +1119,7 @@ const someElementIsSelectedIsRectangleOrEllipseOrDiamond = () => element.type === "diamond") ); -const someElementIsSelectedIsRectangleOrEllipseOrDiamondOrArrow = () => +const hasStroke = () => elements.some( element => element.isSelected && @@ -1514,6 +1518,213 @@ class App extends React.Component<{}, AppState> { +

Colors

+
+
Shape Stroke Color
+
+
+ + {hasBackground() && ( +
+
Shape Background Color
+
+
+ )} + + {hasBackground() && ( + <> +

Fill

+
+ + + + + + + +
+ + )} + + {hasStroke() && ( + <> +

Stroke width

+
+ +
+ +

Roughness

+
+ +
+ + )} + +

Opacity

+ )}

Canvas

@@ -1608,231 +1819,6 @@ class App extends React.Component<{}, AppState> { Load file...
- {someElementIsSelected() && ( - <> - <> -

Colors

-
-
Shape Stroke Color
-
-
- - {someElementIsSelectedIsRectangleOrEllipseOrDiamond() && ( -
-
Shape Background Color
-
-
- )} - - - {someElementIsSelectedIsRectangleOrEllipseOrDiamond() && ( - <> -

Fill

-
- {/* */} -
- - )} - - {someElementIsSelectedIsRectangleOrEllipseOrDiamondOrArrow() && ( - <> -

Stroke width

-
- -
- -

Roughness

-
- -
- - )} - -

Opacity

- - - )}