From f196d144bb78639dadba8a11091544f0fadb3280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bertalan=20K=C3=B6rmendy?= Date: Wed, 13 Nov 2024 15:30:52 +0100 Subject: [PATCH] Remove unnecessary props from `StyleInfoFactory` context param (#6634) ## Problem `metadata` and `elementPathTree` are required by the context param of `StylePlugin.styleInfoFactory`, but they weren't used by the plugins. Because of this, having to pass `metadata` and `elementPathTree` in the context param created unnecessary boilerplate ## Fix Remove `metadata` and `elementPathTree` from the context param of `StylePlugin.styleInfoFactory`, but keep the context param itself so other data can be added to the context later on. --- .../components/canvas/canvas-strategies/canvas-strategies.tsx | 4 ---- .../canvas/canvas-strategies/canvas-strategy-types.ts | 2 -- .../components/canvas/commands/adjust-css-length-command.ts | 2 -- .../canvas/controls/select-mode/flex-gap-control.tsx | 2 -- .../canvas/controls/select-mode/subdued-flex-gap-controls.tsx | 2 -- .../src/components/canvas/plugins/inline-style-plugin.spec.ts | 2 -- editor/src/components/canvas/plugins/style-plugins.ts | 2 -- 7 files changed, 16 deletions(-) diff --git a/editor/src/components/canvas/canvas-strategies/canvas-strategies.tsx b/editor/src/components/canvas/canvas-strategies/canvas-strategies.tsx index d40d6803b304..484d4c9cd659 100644 --- a/editor/src/components/canvas/canvas-strategies/canvas-strategies.tsx +++ b/editor/src/components/canvas/canvas-strategies/canvas-strategies.tsx @@ -225,8 +225,6 @@ export function pickCanvasStateFromEditorState( propertyControlsInfo: editorState.propertyControlsInfo, styleInfoReader: activePlugin.styleInfoFactory({ projectContents: editorState.projectContents, - metadata: editorState.jsxMetadata, - elementPathTree: editorState.elementPathTree, }), } } @@ -254,8 +252,6 @@ export function pickCanvasStateFromEditorStateWithMetadata( propertyControlsInfo: editorState.propertyControlsInfo, styleInfoReader: activePlugin.styleInfoFactory({ projectContents: editorState.projectContents, - metadata: metadata, - elementPathTree: editorState.elementPathTree, }), } } diff --git a/editor/src/components/canvas/canvas-strategies/canvas-strategy-types.ts b/editor/src/components/canvas/canvas-strategies/canvas-strategy-types.ts index e2ab2905af65..6bf08da6cde1 100644 --- a/editor/src/components/canvas/canvas-strategies/canvas-strategy-types.ts +++ b/editor/src/components/canvas/canvas-strategies/canvas-strategy-types.ts @@ -110,8 +110,6 @@ export type StyleInfoReader = (elementPath: ElementPath) => StyleInfo | null export type StyleInfoFactory = (context: { projectContents: ProjectContentTreeRoot - metadata: ElementInstanceMetadataMap - elementPathTree: ElementPathTrees }) => StyleInfoReader export interface InteractionCanvasState { diff --git a/editor/src/components/canvas/commands/adjust-css-length-command.ts b/editor/src/components/canvas/commands/adjust-css-length-command.ts index aa5df344358f..9c5137c5cc2a 100644 --- a/editor/src/components/canvas/commands/adjust-css-length-command.ts +++ b/editor/src/components/canvas/commands/adjust-css-length-command.ts @@ -78,8 +78,6 @@ export const runAdjustCssLengthProperties = ( const styleInfoReader = getActivePlugin(withConflictingPropertiesRemoved).styleInfoFactory({ projectContents: withConflictingPropertiesRemoved.projectContents, - metadata: withConflictingPropertiesRemoved.jsxMetadata, - elementPathTree: withConflictingPropertiesRemoved.elementPathTree, }) const styleInfo = styleInfoReader(command.target) diff --git a/editor/src/components/canvas/controls/select-mode/flex-gap-control.tsx b/editor/src/components/canvas/controls/select-mode/flex-gap-control.tsx index f210ec1e0621..672e28d2f801 100644 --- a/editor/src/components/canvas/controls/select-mode/flex-gap-control.tsx +++ b/editor/src/components/canvas/controls/select-mode/flex-gap-control.tsx @@ -139,8 +139,6 @@ export const FlexGapControl = controlForStrategyMemoized((p maybeFlexGapData( getActivePlugin(store.editor).styleInfoFactory({ projectContents: store.editor.projectContents, - metadata: metadata, - elementPathTree: store.editor.elementPathTree, })(selectedElement), MetadataUtils.findElementByElementPath(store.editor.jsxMetadata, selectedElement), ), diff --git a/editor/src/components/canvas/controls/select-mode/subdued-flex-gap-controls.tsx b/editor/src/components/canvas/controls/select-mode/subdued-flex-gap-controls.tsx index ea4b03eb8455..539d082cc253 100644 --- a/editor/src/components/canvas/controls/select-mode/subdued-flex-gap-controls.tsx +++ b/editor/src/components/canvas/controls/select-mode/subdued-flex-gap-controls.tsx @@ -43,8 +43,6 @@ export const SubduedFlexGapControl = React.memo((pro maybeFlexGapData( getActivePlugin(store.editor).styleInfoFactory({ projectContents: store.editor.projectContents, - metadata: store.editor.jsxMetadata, - elementPathTree: store.editor.elementPathTree, })(selectedElement), MetadataUtils.findElementByElementPath(store.editor.jsxMetadata, selectedElement), ), diff --git a/editor/src/components/canvas/plugins/inline-style-plugin.spec.ts b/editor/src/components/canvas/plugins/inline-style-plugin.spec.ts index fefb978860c4..7be9e9103a53 100644 --- a/editor/src/components/canvas/plugins/inline-style-plugin.spec.ts +++ b/editor/src/components/canvas/plugins/inline-style-plugin.spec.ts @@ -96,9 +96,7 @@ function getStyleInfoFromInlineStyle(editor: EditorRenderResult) { const { jsxMetadata, projectContents, elementPathTree } = editor.getEditorState().editor const styleInfoReader = InlineStylePlugin.styleInfoFactory({ - metadata: jsxMetadata, projectContents: projectContents, - elementPathTree: elementPathTree, }) const styleInfo = styleInfoReader(EP.fromString('sb/scene/div')) return styleInfo diff --git a/editor/src/components/canvas/plugins/style-plugins.ts b/editor/src/components/canvas/plugins/style-plugins.ts index d912ac52cf85..87e771bb8118 100644 --- a/editor/src/components/canvas/plugins/style-plugins.ts +++ b/editor/src/components/canvas/plugins/style-plugins.ts @@ -192,8 +192,6 @@ function getPropertiesToZero( export function patchRemovedProperties(editorState: EditorState): EditorState { const styleInfoReader = getActivePlugin(editorState).styleInfoFactory({ projectContents: editorState.projectContents, - metadata: editorState.jsxMetadata, - elementPathTree: editorState.elementPathTree, }) const propertiesUpdatedDuringInteraction = getPropertiesUpdatedDuringInteraction(editorState)