From 2c7c97af9c766d0579f969e4eb03a115acd7b418 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 23 Aug 2023 12:14:49 +0200 Subject: [PATCH] [fix] style changes (#1814) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR updates the way that styles are changed. It splits `setStyle` and `setOpacity` into `setStyleForNext Shape` and `setOpacityForNextShape` and `setStyleForSelectedShapes` and `setOpacityForSelectedShapes`. It fixes the issue with setting one style re-setting other styles. ### Change Type - [x] `major` — Breaking change ### Test Plan 1. Set styles when shapes are not selected. 2. Set styles when shapes are selected. 3. Set styles when shapes are selected and the selected tool is not select. - [x] Unit Tests --- apps/examples/src/examples/APIExample.tsx | 3 +- .../CustomStylesExample/FilterStyleUi.tsx | 9 +- packages/editor/api-report.md | 6 +- packages/editor/src/lib/editor/Editor.ts | 221 ++++++++++-------- .../ui/components/StylePanel/StylePanel.tsx | 20 +- packages/tldraw/src/test/Editor.test.tsx | 15 +- .../src/test/commands/createShapes.test.ts | 5 +- .../tldraw/src/test/commands/getSvg.test.ts | 3 +- packages/tldraw/src/test/frames.test.ts | 15 +- packages/tldraw/src/test/groups.test.ts | 3 +- packages/tldraw/src/test/styles2.test.tsx | 12 +- 11 files changed, 190 insertions(+), 122 deletions(-) diff --git a/apps/examples/src/examples/APIExample.tsx b/apps/examples/src/examples/APIExample.tsx index 61fc1f470..668eb8e04 100644 --- a/apps/examples/src/examples/APIExample.tsx +++ b/apps/examples/src/examples/APIExample.tsx @@ -90,7 +90,8 @@ const InsideOfEditorContext = () => { const interval = setInterval(() => { const selection = [...editor.selectedShapeIds] editor.selectAll() - editor.setStyle(DefaultColorStyle, i % 2 ? 'blue' : 'light-blue') + editor.setStyleForSelectedShapes(DefaultColorStyle, i % 2 ? 'blue' : 'light-blue') + editor.setStyleForNextShapes(DefaultColorStyle, i % 2 ? 'blue' : 'light-blue') editor.setSelectedShapes(selection) i++ }, 1000) diff --git a/apps/examples/src/examples/CustomStylesExample/FilterStyleUi.tsx b/apps/examples/src/examples/CustomStylesExample/FilterStyleUi.tsx index 1dacd8b22..f8c6e4bef 100644 --- a/apps/examples/src/examples/CustomStylesExample/FilterStyleUi.tsx +++ b/apps/examples/src/examples/CustomStylesExample/FilterStyleUi.tsx @@ -13,7 +13,14 @@ export const FilterStyleUi = track(function FilterStyleUi() { filter:{' '}