Skip to content

AI-native design editor. Open-source Figma alternative.

fix: show only the panel controls Figma gives sticky notes and per-side strokes (#1332)

Danila Poyarkov089b0a0bfcc6
diff --git a/changes/1332/fixed.md b/changes/1332/fixed.md
new file mode 100644
index 000000000..b615fcc5b
--- /dev/null
+++ b/changes/1332/fixed.md
@@ -0,0 +1 @@
+- The Stroke section offers per-side weights only on rectangles, frames, components, component sets, and instances, as Figma does.
diff --git a/packages/scene-graph/src/connectors/sublayers.ts b/packages/scene-graph/src/connectors/sublayers.ts
index bb5c11e73..8016b8e44 100644
--- a/packages/scene-graph/src/connectors/sublayers.ts
+++ b/packages/scene-graph/src/connectors/sublayers.ts
@@ -103,6 +103,7 @@ export const CONNECTOR_KIND: GeneratedFrameKind = {
text: (graph, frame) => connectorSublayers(graph, frame)?.label,
rotates: false,
resizes: false,
+ strokesAndEffects: true,
namedByText: false
}
diff --git a/packages/scene-graph/src/generated/index.ts b/packages/scene-graph/src/generated/index.ts
index 33c49026c..9cf3727f4 100644
--- a/packages/scene-graph/src/generated/index.ts
+++ b/packages/scene-graph/src/generated/index.ts
@@ -71,6 +71,11 @@ export function layerResizes(node: Pick<SceneNode, 'type'>): boolean {
return generatedFrameKind(node)?.resizes ?? true
}
+/** Whether a layer takes strokes and effects: any layer but a sticky note. */
+export function layerStrokesAndEffects(node: Pick<SceneNode, 'type'>): boolean {
+ return generatedFrameKind(node)?.strokesAndEffects ?? true
+}
+
export type { GeneratedFrameKind } from './kind'
export * from './shape-with-text'
export * from './sticky'
diff --git a/packages/scene-graph/src/generated/kind.ts b/packages/scene-graph/src/generated/kind.ts
index a955632d0..82f4dd43c 100644
--- a/packages/scene-graph/src/generated/kind.ts
+++ b/packages/scene-graph/src/generated/kind.ts
@@ -14,6 +14,8 @@ export interface GeneratedFrameKind {
rotates: boolean
/** Whether the frame's resize handles and W and H fields resize it freely. */
resizes: boolean
+ /** Whether it takes strokes and effects; a sticky note has neither, its shadow is its own. */
+ strokesAndEffects: boolean
/** Whether it takes its name from its text until the user names it, as a sticky note does. */
namedByText: boolean
/**
diff --git a/packages/scene-graph/src/generated/shape-with-text.ts b/packages/scene-graph/src/generated/shape-with-text.ts
index 2ab4556bb..9f0802aae 100644
--- a/packages/scene-graph/src/generated/shape-with-text.ts
+++ b/packages/scene-graph/src/generated/shape-with-text.ts
@@ -78,6 +78,7 @@ export const SHAPE_WITH_TEXT_KIND: GeneratedFrameKind = {
text: (graph, frame) => shapeWithTextLabel(graph, frame) ?? undefined,
rotates: true,
resizes: true,
+ strokesAndEffects: true,
namedByText: true,
sized: ({ width, height }) => ({
...(width !== undefined && { shapeUserWidth: width }),
diff --git a/packages/scene-graph/src/generated/sticky.ts b/packages/scene-graph/src/generated/sticky.ts
index ff6f1d8be..20e7f99b2 100644
--- a/packages/scene-graph/src/generated/sticky.ts
+++ b/packages/scene-graph/src/generated/sticky.ts
@@ -145,6 +145,7 @@ export const STICKY_KIND: GeneratedFrameKind = {
text: (graph, frame) => stickySublayers(graph, frame)?.body,
rotates: false,
resizes: false,
+ strokesAndEffects: false,
namedByText: true
}
diff --git a/packages/scene-graph/src/index.ts b/packages/scene-graph/src/index.ts
index 7b0b4a527..98b609880 100644
--- a/packages/scene-graph/src/index.ts
+++ b/packages/scene-graph/src/index.ts
@@ -68,7 +68,8 @@ export {
createDefaultNode,
defaultStrokeAlign,
FITTED_CONTAINER_TYPES,
- newStrokeGeometry
+ newStrokeGeometry,
+ SIDE_STROKE_TYPES
} from './node-defaults'
export {
copyInstanceComponentProps,
diff --git a/packages/scene-graph/src/node-defaults.ts b/packages/scene-graph/src/node-defaults.ts
index 00c9ff31d..e9784adc0 100644
--- a/packages/scene-graph/src/node-defaults.ts
+++ b/packages/scene-graph/src/node-defaults.ts
@@ -231,6 +231,15 @@ export const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
'BOOLEAN_OPERATION'
])
+/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */
+export const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
+ 'RECTANGLE',
+ 'FRAME',
+ 'COMPONENT',
+ 'COMPONENT_SET',
+ 'INSTANCE'
+])
+
export const CONTAINER_TYPES = new Set<NodeType>([
'CANVAS',
'FRAME',
diff --git a/packages/vue/src/controls/position/use.ts b/packages/vue/src/controls/position/use.ts
index 646e5742c..137ed4fe5 100644
--- a/packages/vue/src/controls/position/use.ts
+++ b/packages/vue/src/controls/position/use.ts
@@ -6,7 +6,7 @@ import {
panelRotation,
panelRotationChange
} from '@open-pencil/core/geometry'
-import type { NumericNodeProperty, SceneNode } from '@open-pencil/scene-graph'
+import { layerRotates, type NumericNodeProperty, type SceneNode } from '@open-pencil/scene-graph'
import { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'
import { usePropScrub } from '#vue/controls/prop-scrub/use'
@@ -23,6 +23,8 @@ export function usePosition() {
const { nodes, node, active, isMulti, prop } = useNodeProps()
const ids = computed(() => nodes.value.map((n) => n.id))
+ /** Whether the selection turns and flips; a sticky note or connector stays upright. */
+ const rotates = computed(() => nodes.value.every(layerRotates))
// X, Y, and rotation read as Figma's panel shows them: the turned layer's box on the canvas and
// its counterclockwise angle; see `panelPosition` and `panelRotation`.
@@ -121,6 +123,7 @@ export function usePosition() {
width,
height,
rotation,
+ rotates,
inAutoLayout,
ignoresAutoLayout,
toggleIgnoreAutoLayout,
diff --git a/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue b/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
index 3cd5ac54f..4902be3ab 100644
--- a/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
+++ b/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
@@ -19,6 +19,7 @@ const {
x,
y,
rotation,
+ rotates,
inAutoLayout,
ignoresAutoLayout,
toggleIgnoreAutoLayout
@@ -53,6 +54,7 @@ const actions = {
:w-value="wValue"
:h-value="hValue"
:rotation-value="rotationValue"
+ :rotates="rotates"
:in-auto-layout="inAutoLayout"
:ignores-auto-layout="ignoresAutoLayout"
:mixed="MIXED"
diff --git a/src/components/DesignPanel.vue b/src/components/DesignPanel.vue
index 10fc642c6..cb27c13a6 100644
--- a/src/components/DesignPanel.vue
+++ b/src/components/DesignPanel.vue
@@ -2,7 +2,7 @@
import { computed } from 'vue'
import { getNodeEditCapability } from '@open-pencil/core/editor'
-import { layerResizes, readIcon } from '@open-pencil/scene-graph'
+import { layerResizes, layerStrokesAndEffects, readIcon } from '@open-pencil/scene-graph'
import { useI18n, useSceneComputed, useSelectionState, useEditorCommands } from '@open-pencil/vue'
import { useEditorStore } from '@/app/editor/active-store'
@@ -87,6 +87,10 @@ const supportsLayoutGuides = useSceneComputed(() => {
const nodes = store.getSelectedNodes()
return nodes.length > 0 && nodes.every((selected) => LAYOUT_GUIDE_TYPES.has(selected.type))
})
+// A sticky note has no strokes or effects, so a selection holding one offers neither.
+const strokesAndEffects = useSceneComputed(() =>
+ store.getSelectedNodes().every((selected) => layerStrokesAndEffects(selected))
+)
const { panels } = useI18n()
</script>
@@ -124,8 +128,10 @@ const { panels } = useI18n()
<AppearanceSection />
<TypographySection />
<FillSection />
- <StrokeSection />
- <EffectsSection />
+ <template v-if="strokesAndEffects">
+ <StrokeSection />
+ <EffectsSection />
+ </template>
<SelectionColorsSection />
<LayoutGridSection v-if="supportsLayoutGuides" />
<ExportSection />
@@ -228,8 +234,10 @@ const { panels } = useI18n()
<MaskSection />
<TypographySection v-if="node.type === 'TEXT'" />
<FillSection />
- <StrokeSection />
- <EffectsSection />
+ <template v-if="strokesAndEffects">
+ <StrokeSection />
+ <EffectsSection />
+ </template>
</template>
<SelectionColorsSection />
<LayoutGridSection v-if="supportsLayoutGuides" />
diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vue
index b58418794..c77fd3640 100644
--- a/src/components/properties/PositionSection.vue
+++ b/src/components/properties/PositionSection.vue
@@ -27,7 +27,16 @@ function handleAlign(
<template>
<PositionControlsRoot
- v-slot="{ active, xValue, yValue, rotationValue, inAutoLayout, ignoresAutoLayout, actions }"
+ v-slot="{
+ active,
+ xValue,
+ yValue,
+ rotationValue,
+ rotates,
+ inAutoLayout,
+ ignoresAutoLayout,
+ actions
+ }"
>
<PanelSection v-if="active" :label="panels.position">
<template v-if="inAutoLayout" #actions>
@@ -113,7 +122,7 @@ function handleAlign(
</Tip>
</PanelGrid>
- <PanelGrid :columns="2" class="mt-1.5">
+ <PanelGrid v-if="rotates" :columns="2" class="mt-1.5">
<Tip :label="panels.rotation">
<NumberField
suffix="°"
diff --git a/src/components/properties/stroke/StrokeSection.vue b/src/components/properties/stroke/StrokeSection.vue
index 372ede82b..7041b70cc 100644
--- a/src/components/properties/stroke/StrokeSection.vue
+++ b/src/components/properties/stroke/StrokeSection.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
+import { SIDE_STROKE_TYPES } from '@open-pencil/scene-graph'
import type { Color, Fill, SceneNode, Stroke } from '@open-pencil/scene-graph'
import { colorToHexRaw } from '@open-pencil/scene-graph/color'
import {
@@ -70,6 +71,13 @@ function onPickerOpenChange(
}
const { panels, common } = useI18n()
const expandedSides = ref(false)
+/** Figma strokes each side apart only on rectangles, frames, components, and instances. */
+const sidesOffered = computed(
+ () =>
+ selectedNodes.value.length > 0 &&
+ selectedNodes.value.every((node) => SIDE_STROKE_TYPES.has(node.type))
+)
+const sidesShown = computed(() => sidesOffered.value && expandedSides.value)
/** A bound variable colours the swatch, but only a solid stroke has one colour to replace. */
function displayStroke(stroke: Stroke, resolvedColor: Color | undefined): Fill {
@@ -235,7 +243,7 @@ function onToggleSides(nodes: readonly SceneNode[]) {
/>
<Tip :label="panels.strokeWeight">
<NumberField
- v-if="!expandedSides"
+ v-if="!sidesShown"
class="flex-1"
icon="W"
:model-value="items[0]?.weight ?? 1"
@@ -250,6 +258,7 @@ function onToggleSides(nodes: readonly SceneNode[]) {
@patch="actions.patch(0, $event)"
/>
<IconButton
+ v-if="sidesOffered"
:label="panels.strokeSides"
size="xs"
class="size-[26px] shrink-0"
@@ -264,7 +273,7 @@ function onToggleSides(nodes: readonly SceneNode[]) {
<StrokeSettingsPopover v-if="isMixed && advancedActive" />
<div
- v-if="!isMixed && items.length > 0 && expandedSides"
+ v-if="!isMixed && items.length > 0 && sidesShown"
class="mt-1.5 grid grid-cols-2 gap-1.5"
>
<NumberField
diff --git a/tests/e2e/properties/corner/stroke-toggles.spec.ts b/tests/e2e/properties/corner/stroke-toggles.spec.ts
index 8417dc845..66ebaad40 100644
--- a/tests/e2e/properties/corner/stroke-toggles.spec.ts
+++ b/tests/e2e/properties/corner/stroke-toggles.spec.ts
@@ -1,7 +1,7 @@
import { expect, test, type Page } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
-import { propertySection } from '#tests/helpers/properties'
+import { propertyField, propertySection } from '#tests/helpers/properties'
let page: Page
let canvas: CanvasHelper
@@ -122,3 +122,18 @@ test('stroke sides toggle shows per-side weight inputs', async () => {
const sectionInputsFinal = await propertySection(page, 'Stroke').getByRole('spinbutton').count()
expect(sectionInputsFinal).toBe(sectionInputsBefore)
})
+
+// Figma strokes each side apart only on rectangles, frames, components, and instances.
+test('an ellipse strokes all its sides at one weight, with no sides toggle', async () => {
+ await canvas.pressKey('o')
+ await canvas.drag(300, 250, 400, 330)
+ await canvas.waitForRender()
+ expect((await getSelectedNodeFlags())?.type).toBe('ELLIPSE')
+
+ const stroke = propertySection(page, 'Stroke')
+ await stroke.getByRole('button', { name: 'Add stroke' }).click()
+ await canvas.waitForRender()
+
+ await expect(propertyField(page, 'stroke-weight')).toBeVisible()
+ await expect(propertyField(page, 'stroke-sides')).toHaveCount(0)
+})
diff --git a/tests/e2e/tools/sticky.spec.ts b/tests/e2e/tools/sticky.spec.ts
index 2da7fb552..734755474 100644
--- a/tests/e2e/tools/sticky.spec.ts
+++ b/tests/e2e/tools/sticky.spec.ts
@@ -2,6 +2,7 @@ import type { Vector } from '@open-pencil/scene-graph/primitives'
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
import { stickyDriver } from '#tests/helpers/canvas/sticky-driver'
+import { propertyField, propertySection } from '#tests/helpers/properties'
import { toolbarToolTestId } from '#tests/helpers/test-ids'
const editor = useEditorSetupWithClear()
@@ -129,6 +130,35 @@ test('the Sticky note section recolours a note, sizes its text, and hides its au
await expect.poll(async () => (await lastNote()).author.visible).toBe(false)
})
+// Figma keeps a note upright and gives it no strokes or effects: its shadow is part of the note.
+test("a note's panel has its fill and opacity, but no rotation, stroke, or effects", async () => {
+ await sticky.add([{ x: 300, y: 200, text: 'Upright' }])
+ await clickNote(300, 200)
+
+ await expect(propertySection(editor.page, 'Fill')).toBeVisible()
+ await expect(propertySection(editor.page, 'Appearance')).toBeVisible()
+ await expect(propertyField(editor.page, 'x')).toBeVisible()
+ await expect(propertyField(editor.page, 'rotation')).toHaveCount(0)
+ await expect(propertySection(editor.page, 'Stroke')).toHaveCount(0)
+ await expect(propertySection(editor.page, 'Effects')).toHaveCount(0)
+})
+
+test('a note selected with a rectangle offers no stroke or effects either', async () => {
+ await sticky.add([{ x: 150, y: 150, text: 'One' }])
+ const from = sticky.point(550, 100)
+ const to = sticky.point(650, 200)
+ await editor.canvas.pressKey('r')
+ await editor.canvas.drag(from.x, from.y, to.x, to.y)
+ await editor.page.keyboard.down('Shift')
+ await clickNote(150, 150)
+ await editor.page.keyboard.up('Shift')
+
+ await expect(editor.page.getByTestId('design-panel-multi')).toBeVisible()
+ await expect(propertySection(editor.page, 'Fill')).toBeVisible()
+ await expect(propertySection(editor.page, 'Stroke')).toHaveCount(0)
+ await expect(propertySection(editor.page, 'Effects')).toHaveCount(0)
+})
+
test('the sticky tool places notes in the colour picked last', async () => {
await sticky.add([{ x: 150, y: 150, text: 'First' }])
await clickNote(150, 150)