From cf795eba58adcebda9052c77456305a48757c993 Mon Sep 17 00:00:00 2001 From: princepride Date: Fri, 20 Nov 2026 16:06:04 +0000 Subject: [PATCH 1/5] [feat] canvas: group toolbar, group colors, and no more node locking - Selecting a group shows its own toolbar above it: run workflow, ungroup, layout (grid / row / column, resizing the group to fit), background color, and download (all group assets as one ZIP). - Run workflow generates the group's configured nodes in reference order: a node waits for the members it references, independent nodes run concurrently, and a failure skips its downstream nodes. - Groups store an optional #rrggbb color (canvas item `color`; '' in canvas.update restores the default). Node equality includes the color so a color-only edit is saved. - The context menu no longer offers lock/unlock or layer reordering. Nodes locked in older projects are unlocked on open, parents first. Co-Authored-By: Claude Opus 5.5 --- .../application/creation_canvas.py | 2 + .../src/opendirector/domain/creation/base.py | 2 + .../opendirector/domain/creation/canvas.py | 3 +- .../opendirector/domain/creation/commands.py | 3 +- src/backend/creationProjection.ts | 5 + src/canvas/NodeSelectionToolbar.tsx | 83 +++- src/canvas/groupWorkflow.ts | 68 +++ src/canvas/history.ts | 1 + src/canvas/model.ts | 2 + src/canvas/node-selection-toolbar.css | 14 + src/canvas/nodes.css | 4 +- src/canvas/operations.ts | 83 ++++ src/canvas/storage.ts | 3 + src/canvas/workspace/WorkspaceView.tsx | 119 +++-- .../workspace/useWorkspaceGeneration.ts | 109 ++++- .../workspace/useWorkspaceInteraction.tsx | 14 +- src/canvas/workspace/useWorkspaceTransfer.ts | 62 ++- src/contracts/creation.schema.json | 421 ++++++++++++++++++ src/contracts/generated.ts | 4 + src/i18n/messages/en-US/canvasShell.ts | 17 + src/i18n/messages/en-US/canvasWorkspace.ts | 11 + src/i18n/messages/zh-CN/canvasShell.ts | 17 + src/i18n/messages/zh-CN/canvasWorkspace.ts | 11 + tests/canvasModel.test.ts | 18 + tests/canvasOperations.test.ts | 62 +++ tests/groupWorkflow.test.ts | 75 ++++ tests/test_creation_canvas_service.py | 21 + 27 files changed, 1136 insertions(+), 98 deletions(-) create mode 100644 src/canvas/groupWorkflow.ts create mode 100644 tests/groupWorkflow.test.ts diff --git a/packages/core/src/opendirector/application/creation_canvas.py b/packages/core/src/opendirector/application/creation_canvas.py index 1d6e9d19d..99bfcbfcb 100644 --- a/packages/core/src/opendirector/application/creation_canvas.py +++ b/packages/core/src/opendirector/application/creation_canvas.py @@ -554,6 +554,8 @@ def _mutate(self, data, kind, payload): elif kind == 'canvas.update': item = self._editable(data, payload.itemId, unlocking=value.get('locked') is False) item.update({key: val for key, val in value.items() if key != 'itemId' and (val is not None or key == 'parentId')}) + if item.get('color') == '': + item.pop('color') elif kind == 'canvas.hide': self._editable(data, payload.itemId)['visible'] = False elif kind == 'canvas.materialize': diff --git a/packages/core/src/opendirector/domain/creation/base.py b/packages/core/src/opendirector/domain/creation/base.py index 6e71c6895..42c5108cd 100644 --- a/packages/core/src/opendirector/domain/creation/base.py +++ b/packages/core/src/opendirector/domain/creation/base.py @@ -12,6 +12,8 @@ Revision = Annotated[int, Field(strict=True, ge=1)] PositiveInt = Annotated[int, Field(strict=True, ge=1)] Identifier = Annotated[str, Field(min_length=1, max_length=100, pattern=r'\S')] +# Canvas presentation color: #RRGGBB, or '' in an update to restore the default. +CanvasColor = Annotated[str, Field(pattern=r'^(#[0-9a-fA-F]{6})?$')] Fingerprint = Annotated[str, Field(pattern=r'^sha256:[0-9a-f]{64}$')] Digest = Annotated[str, Field(pattern=r'^[0-9a-f]{64}$')] MediaKind = Literal['text', 'image', 'video', 'audio', 'file'] diff --git a/packages/core/src/opendirector/domain/creation/canvas.py b/packages/core/src/opendirector/domain/creation/canvas.py index 74cac41a2..181a31f0e 100644 --- a/packages/core/src/opendirector/domain/creation/canvas.py +++ b/packages/core/src/opendirector/domain/creation/canvas.py @@ -7,7 +7,7 @@ from opendirector.domain.projects import ProjectError from .assets import AssetRef -from .base import CanvasItemVersion, Contract, Identifier, Point, Positive, ProjectEntity, unique +from .base import CanvasColor, CanvasItemVersion, Contract, Identifier, Point, Positive, ProjectEntity, unique from .generation import FollowingSource, GenerationSpec, ResolvedReference, validate_generation from .models import ModelConfigPublic @@ -103,6 +103,7 @@ class CanvasItemBase(ProjectEntity): height: Positive = Field(default=198, description='Height in pixels.') zIndex: int = Field(default=0, strict=True, description='Canvas stacking order.') locked: bool = Field(default=False, description='Whether edits to this object are blocked.') + color: CanvasColor | None = Field(default=None, exclude_if=lambda value: not value, description='Group background color in #RRGGBB format.') visible: bool = Field(default=True, description='Whether this object is displayed.') parentId: UUID | None = Field(default=None, description='Parent canvas group ID, or null for the root.') tags: tuple[Identifier, ...] = Field(default=(), description='User-defined search tags.') diff --git a/packages/core/src/opendirector/domain/creation/commands.py b/packages/core/src/opendirector/domain/creation/commands.py index 556b6d6c4..e1894c34e 100644 --- a/packages/core/src/opendirector/domain/creation/commands.py +++ b/packages/core/src/opendirector/domain/creation/commands.py @@ -5,7 +5,7 @@ from pydantic import ConfigDict, Field, TypeAdapter, create_model, model_validator from .assets import AssetRef, MediaMetadata -from .base import Contract, Digest, GenerationKind, MediaKind, ObjectVersion, Point, Positive, Revision, digest, unique +from .base import CanvasColor, Contract, Digest, GenerationKind, MediaKind, ObjectVersion, Point, Positive, Revision, digest, unique from .canvas import CanvasItem from .editors import EditorDocument from opendirector.domain.rule_facts import PROMPT_MAX_LENGTH @@ -109,6 +109,7 @@ class CanvasPresentationUpdate(Contract): height: Positive | None = Field(default=None, description='Height in pixels.') zIndex: int | None = Field(default=None, strict=True, description='Canvas stacking order.') locked: bool | None = Field(default=None, description='Whether edits to this object are blocked.') + color: CanvasColor | None = Field(default=None, description="Group background color in #RRGGBB format, or '' for the default.") parentId: UUID | None = Field(default=None, description='Parent canvas group ID, or null for the root.') # Presence of parentId distinguishes retaining a group from ungrouping. diff --git a/src/backend/creationProjection.ts b/src/backend/creationProjection.ts index 06b43fd04..24c4bdd7b 100644 --- a/src/backend/creationProjection.ts +++ b/src/backend/creationProjection.ts @@ -74,6 +74,7 @@ const presentationFields = [ "height", "zIndex", "locked", + "color", "parentId", ] as const; const extension: Record = { @@ -602,6 +603,7 @@ export class CreationProjection { width: item.width, height: item.height, locked: item.locked, + ...(item.color ? { color: item.color } : {}), zIndex: item.zIndex, parentId: item.parentId ?? undefined, }; @@ -1594,6 +1596,7 @@ export class CreationProjection { height: node.height, zIndex: node.zIndex ?? 0, locked: node.locked ?? false, + ...(node.color ? { color: node.color } : {}), parentId: node.parentId ?? null, binding, } as CanvasItem, @@ -1613,6 +1616,7 @@ export class CreationProjection { height: node.height, zIndex: node.zIndex ?? 0, locked: node.locked ?? false, + color: node.color ?? "", parentId: node.parentId ?? null, }; const oldPresentation = { @@ -1621,6 +1625,7 @@ export class CreationProjection { height: old?.height, zIndex: old?.zIndex ?? 0, locked: old?.locked ?? false, + color: old?.color ?? "", parentId: old?.parentId ?? null, }; const changedFields = presentationFields.filter( diff --git a/src/canvas/NodeSelectionToolbar.tsx b/src/canvas/NodeSelectionToolbar.tsx index cb352bd33..8b6b4c899 100644 --- a/src/canvas/NodeSelectionToolbar.tsx +++ b/src/canvas/NodeSelectionToolbar.tsx @@ -12,6 +12,7 @@ import type { ToolGlyphName } from "./toolGlyphs"; import { TooltipButton } from "./TooltipButton"; import { GridSplitOptions, SelectionToolbarMenu } from "./SelectionToolbarMenu"; import type { CanvasNode } from "./model"; +import type { GroupLayout } from "./operations"; import type { CanvasToolId } from "./toolCatalog"; import { useT } from "../i18n/I18nProvider"; import type { MessageKey } from "../i18n/messages"; @@ -46,8 +47,26 @@ export interface NodeSelectionToolbarProps { onRename?: () => void; onDuplicate?: () => void; onDelete?: () => void; + /** Group actions: run the members' generation workflow, ungroup, arrange, recolor. */ + onRunWorkflow?: () => void; + workflowRunning?: boolean; + onUngroup?: () => void; + onLayout?: (layout: GroupLayout) => void; + onGroupColor?: (color: string) => void; } +/** Group background presets; "" restores the default style. */ +export const GROUP_COLORS: readonly [string, MessageKey][] = [ + ["", "canvas.selection.group.colorDefault"], + ["#8b8f9a", "canvas.selection.group.colorGray"], + ["#e5484d", "canvas.selection.group.colorRed"], + ["#f76b15", "canvas.selection.group.colorOrange"], + ["#ffc53d", "canvas.selection.group.colorYellow"], + ["#30a46c", "canvas.selection.group.colorGreen"], + ["#3e63dd", "canvas.selection.group.colorBlue"], + ["#8e4ec6", "canvas.selection.group.colorPurple"], +]; + type Action = { id: string; label: string; @@ -68,6 +87,10 @@ type MenuOption = { run?: () => void; grid?: boolean; disabled?: boolean; + /** Color swatch shown instead of the icon; "" draws the default swatch. */ + swatch?: string; + /** Marks the current choice, such as the active background color. */ + checked?: boolean; }; type OpenMenu = { nodeId: string; @@ -122,6 +145,11 @@ export function NodeSelectionToolbar({ onRename, onDuplicate, onDelete, + onRunWorkflow, + workflowRunning = false, + onUngroup, + onLayout, + onGroupColor, }: NodeSelectionToolbarProps) { const t = useT(); const toolbar = useRef(null); @@ -190,7 +218,38 @@ export function NodeSelectionToolbar({ disabled: locked, }); }; - if (node.type === "image") { + if (node.type === "group") { + if (onRunWorkflow) + editing.push({ + id: "run-workflow", + label: workflowRunning ? t("canvas.selection.group.running") : t("canvas.selection.group.run"), + icon: "play", + run: onRunWorkflow, + disabled: workflowRunning, + }); + if (onUngroup) + editing.push({ id: "ungroup", label: t("canvas.selection.group.ungroup"), icon: "group", run: onUngroup }); + if (onLayout) + addMenu("layout", t("canvas.selection.group.layout"), "grid", [ + { id: "grid", label: t("canvas.selection.group.layoutGrid"), icon: "grid", run: () => onLayout("grid") }, + { id: "row", label: t("canvas.selection.group.layoutRow"), icon: "referenceArrowsHorizontal", run: () => onLayout("row") }, + { id: "column", label: t("canvas.selection.group.layoutColumn"), icon: "referenceArrowsVertical", run: () => onLayout("column") }, + ]); + if (onGroupColor) + addMenu( + "group-color", + t("canvas.selection.group.color"), + "palette", + GROUP_COLORS.map(([color, label]) => ({ + id: `color-${color || "default"}`, + label: t(label), + icon: "palette", + swatch: color, + checked: (node.color ?? "") === color, + run: () => onGroupColor(color), + })), + ); + } else if (node.type === "image") { for (const [tool, labelKey, icon, glyph] of imageTools) addTool(tool, t(labelKey), icon, glyph); addMenu( @@ -371,17 +430,18 @@ export function NodeSelectionToolbar({ run: onPreview, iconOnly: true, }); - if (onDownload && (hasMedia || node.type === "text")) + if (onDownload && (hasMedia || node.type === "text" || node.type === "group")) outputs.push({ id: "download", - label: t("common.download"), + label: node.type === "group" ? t("canvas.selection.group.download") : t("common.download"), icon: "download", run: onDownload, iconOnly: true, }); const organization: Action[] = []; - if (onRename) + // A group's bar holds only its own actions; rename and delete stay in the context menu. + if (onRename && node.type !== "group") organization.push({ id: "rename", label: t("common.rename"), @@ -390,7 +450,7 @@ export function NodeSelectionToolbar({ iconOnly: true, disabled: locked, }); - if (onDuplicate) + if (onDuplicate && node.type !== "group") organization.push({ id: "duplicate", label: t("canvas.selection.duplicate"), @@ -398,7 +458,7 @@ export function NodeSelectionToolbar({ run: onDuplicate, iconOnly: true, }); - if (onDelete) + if (onDelete && node.type !== "group") organization.push({ id: "delete", label: t("canvas.selection.deleteNode"), @@ -612,12 +672,21 @@ export function NodeSelectionToolbar({ } }} > - + {option.swatch !== undefined ? ( +