Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/canvas/NodeSelectionToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface NodeSelectionToolbarProps {
/** Group actions: run the members' generation workflow, ungroup, arrange, recolor. */
onRunWorkflow?: () => void;
workflowRunning?: boolean;
onViewGroupPlan?: () => void;
onUngroup?: () => void;
onLayout?: (layout: GroupLayout) => void;
onGroupColor?: (color: string) => void;
Expand Down Expand Up @@ -147,6 +148,7 @@ export function NodeSelectionToolbar({
onDelete,
onRunWorkflow,
workflowRunning = false,
onViewGroupPlan,
onUngroup,
onLayout,
onGroupColor,
Expand Down Expand Up @@ -227,6 +229,8 @@ export function NodeSelectionToolbar({
run: onRunWorkflow,
disabled: workflowRunning || locked,
});
if (onViewGroupPlan)
editing.push({ id: "view-group-plan", label: t("canvas.selection.group.viewPlan"), icon: "text", run: onViewGroupPlan });
if (onUngroup)
editing.push({ id: "ungroup", label: t("canvas.selection.group.ungroup"), icon: "group", run: onUngroup, disabled: locked });
if (onLayout)
Expand Down
18 changes: 13 additions & 5 deletions src/canvas/TextNodeWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import "./text-node-window.css";
export function TextNodeWindow({
node,
locked,
readOnly = false,
selections,
onUpdate,
onClose,
Expand All @@ -31,6 +32,7 @@ export function TextNodeWindow({
}: {
node: CanvasNode;
locked: boolean;
readOnly?: boolean;
selections: TextSelections;
onUpdate: (text: string) => void;
onClose: () => void;
Expand All @@ -39,14 +41,19 @@ export function TextNodeWindow({
}) {
const t = useT();
const panel = useRef<HTMLDivElement>(null);
const previewBody = useRef<HTMLDivElement>(null);
const [preview, setPreview] = useState(false);
const titleId = useId();
const hintId = useId();
const text = node.data.text ?? "";
useLayoutEffect(() => {
if (readOnly) {
previewBody.current?.focus({ preventScroll: true });
return;
}
onBeginEdit();
return onEndEdit;
}, [onBeginEdit, onEndEdit]);
}, [onBeginEdit, onEndEdit, readOnly]);
const keyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key === "Escape" && !event.nativeEvent.isComposing) {
event.preventDefault();
Expand Down Expand Up @@ -93,12 +100,12 @@ export function TextNodeWindow({
{node.data.title || t("canvas.kind.text")}
</strong>
<small id={hintId}>
{locked
{locked || readOnly
? t("canvas.textWindow.locked")
: t("canvas.textWindow.hint")}
</small>
</div>
<div
{!readOnly && <div
className="cw-text-window-modes"
role="group"
aria-label={t("canvas.textWindow.mode")}
Expand All @@ -117,7 +124,7 @@ export function TextNodeWindow({
>
{t("canvas.textWindow.preview")}
</button>
</div>
</div>}
<div className="cw-text-window-controls">
<TooltipButton
label={t("common.close")}
Expand All @@ -129,8 +136,9 @@ export function TextNodeWindow({
</TooltipButton>
</div>
</header>
{preview ? (
{preview || readOnly ? (
<div
ref={previewBody}
className="cw-text-window-input cw-text-window-preview nodrag nopan nowheel"
tabIndex={0}
>
Expand Down
17 changes: 16 additions & 1 deletion src/canvas/workspace/WorkspaceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ export function WorkspaceView({ rt, editingState, editSession }: {
? t("canvas.workspace.loading.switching")
: "";

const canvasItems = creationClient(doc.id).snapshot?.canvasItems;
const selectedGroup = single?.type === "group" ? canvasItems?.find((item) => item.id === single.id) : undefined;
const planNode = selectedGroup?.kind === "group" && selectedGroup.runPlanItemId
? doc.nodes.find((node) => node.type === "text" && node.id === selectedGroup.runPlanItemId)
: undefined;
const viewingPublishedPlan = Boolean(textWindowNode && canvasItems?.some(
(item) => item.kind === "group" && item.runPlanItemId === textWindowNode.id,
));

const workspace = (
<div
inert={!ready || switching || editHandoffPending}
Expand Down Expand Up @@ -1684,6 +1693,7 @@ export function WorkspaceView({ rt, editingState, editSession }: {
}
onRunWorkflow={single.type === "group" ? () => runWorkflow(single.id) : undefined}
workflowRunning={workflowGroups.has(single.id)}
onViewGroupPlan={planNode ? () => setTextWindowId(planNode.id) : undefined}
onUngroup={single.type === "group" ? ungroup : undefined}
onLayout={
single.type === "group" && !single.autoLayout
Expand Down Expand Up @@ -2705,6 +2715,7 @@ export function WorkspaceView({ rt, editingState, editSession }: {
key={textWindowNode.id}
node={textWindowNode}
locked={lockedIds.has(textWindowNode.id)}
readOnly={viewingPublishedPlan}
selections={actions.textSelections}
onUpdate={(text) =>
command({
Expand All @@ -2714,8 +2725,12 @@ export function WorkspaceView({ rt, editingState, editSession }: {
})
}
onClose={() => {
void persist(historyRef.current.present);
setTextWindowId(null);
if (viewingPublishedPlan) {
root.current?.focus({ preventScroll: true });
return;
}
void persist(historyRef.current.present);
if (!lockedIds.has(textWindowNode.id)) setTextEditingId(textWindowNode.id);
else root.current?.focus({ preventScroll: true });
}}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/en-US/canvasShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const canvasShell = {
"canvas.selection.previewFullscreen": "Full-screen preview",
"canvas.selection.group.run": "Run workflow",
"canvas.selection.group.running": "Workflow running",
"canvas.selection.group.viewPlan": "View plan",
"canvas.selection.group.ungroup": "Ungroup",
"canvas.selection.group.layout": "Layout",
"canvas.selection.group.layoutGrid": "Grid",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/messages/zh-CN/canvasShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const canvasShell = {
"canvas.selection.previewFullscreen": "全屏预览",
"canvas.selection.group.run": "运行工作流",
"canvas.selection.group.running": "工作流运行中",
"canvas.selection.group.viewPlan": "查看计划",
"canvas.selection.group.ungroup": "解除编组",
"canvas.selection.group.layout": "布局",
"canvas.selection.group.layoutGrid": "网格排列",
Expand Down
Loading