Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(workflows): edit SOPs inline with consistent spacing (#7275)

Louis Beaumontb7493b57550a
diff --git a/apps/screenpipe-app-tauri/lib/workflows/guide.test.tsx b/apps/screenpipe-app-tauri/lib/workflows/guide.test.tsx
index dc2859d77..87e4fe1e5 100644
--- a/apps/screenpipe-app-tauri/lib/workflows/guide.test.tsx
+++ b/apps/screenpipe-app-tauri/lib/workflows/guide.test.tsx
@@ -1,7 +1,7 @@
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com
import React, { useMemo, useState } from "react";
-import { describe, it, expect, vi, afterEach } from "vitest";
+import { describe, it, expect, vi, afterEach, beforeAll, afterAll } from "vitest";
import {
render,
screen,
@@ -78,6 +78,21 @@ const guide: Guide = {
completion: ["Sources are linked"],
questions: ["Who reviews this?"],
};
+// jsdom lacks native dialog methods; actual modal behavior is covered in the browser eval.
+const originalShow = HTMLDialogElement.prototype.showModal;
+const originalClose = HTMLDialogElement.prototype.close;
+beforeAll(() => {
+ HTMLDialogElement.prototype.showModal = function () {
+ this.setAttribute("open", "");
+ };
+ HTMLDialogElement.prototype.close = function () {
+ this.removeAttribute("open");
+ };
+});
+afterAll(() => {
+ HTMLDialogElement.prototype.showModal = originalShow;
+ HTMLDialogElement.prototype.close = originalClose;
+});
afterEach(cleanup);
describe("guide contracts and export", () => {
it("rejects invented source stages and another workflow identity", () => {
@@ -197,9 +212,8 @@ describe("guide editor", () => {
close={() => {}}
/>,
);
- await screen.findByRole("heading", { name: "Research guide" });
+ await screen.findByRole("textbox", { name: "SOP title" });
expect(platform.generate).not.toHaveBeenCalled();
- fireEvent.click(screen.getByRole("button", { name: "Edit SOP" }));
fireEvent.change(screen.getByLabelText("SOP title"), {
target: { value: "Team research handbook" },
});
@@ -208,6 +222,7 @@ describe("guide editor", () => {
expect.objectContaining({ title: "Team research handbook" }),
),
);
+ fireEvent.click(screen.getByLabelText("Step 2 actions"));
fireEvent.click(screen.getByRole("button", { name: "Move step 2 up" }));
await waitFor(() =>
expect(platform.save.mock.calls.at(-1)?.[0].steps[0].title).toBe(
@@ -215,6 +230,70 @@ describe("guide editor", () => {
),
);
});
+ it("edits in place and reorders complete steps from the keyboard", async () => {
+ const platform = host();
+ render(
+ <WorkflowGuide
+ workflow={workflow}
+ platform={platform}
+ close={() => {}}
+ />,
+ );
+ await screen.findByRole("textbox", { name: "SOP title" });
+ expect(screen.queryByRole("button", { name: "Edit SOP" })).toBeNull();
+ fireEvent.change(screen.getByLabelText("Step 1 title"), {
+ target: { value: "Find the original sources" },
+ });
+ fireEvent.keyDown(screen.getByRole("button", { name: "Reorder step 1" }), {
+ key: "ArrowDown",
+ altKey: true,
+ });
+ await waitFor(() =>
+ expect(platform.save.mock.calls.at(-1)?.[0].steps[1]).toEqual({
+ ...guide.steps[0],
+ title: "Find the original sources",
+ }),
+ );
+ expect(screen.getByLabelText("Step 2 title")).toHaveValue(
+ "Find the original sources",
+ );
+ expect(screen.getByLabelText("Step 2 instructions")).toHaveTextContent(
+ "Gather the documents.",
+ );
+ fireEvent.change(screen.getByLabelText("Step 2 expected result"), {
+ target: { value: "Original sources ready" },
+ });
+ await waitFor(() =>
+ expect(platform.save.mock.calls.at(-1)?.[0].steps[1].expectedResult).toBe(
+ "Original sources ready",
+ ),
+ );
+ });
+ it("keeps inline edits available after a save failure and retries the latest draft", async () => {
+ const platform = host();
+ platform.save.mockRejectedValueOnce(new Error("disk full"));
+ render(
+ <WorkflowGuide
+ workflow={workflow}
+ platform={platform}
+ close={() => {}}
+ />,
+ );
+ fireEvent.change(await screen.findByLabelText("Guide summary"), {
+ target: { value: "Keep my revision" },
+ });
+ const retry = await screen.findByRole("button", { name: "Retry save" });
+ expect(screen.getByLabelText("Guide summary")).toHaveValue(
+ "Keep my revision",
+ );
+ fireEvent.click(retry);
+ await waitFor(() =>
+ expect(screen.queryByRole("button", { name: "Retry save" })).toBeNull(),
+ );
+ expect(platform.save.mock.calls.at(-1)?.[0].summary).toBe(
+ "Keep my revision",
+ );
+ });
it("lets an older saved SOP review and include a local screenshot without regenerating", async () => {
const w = structuredClone(workflow);
delete w.stages[0].screenshot!.visualVerified;
@@ -225,7 +304,7 @@ describe("guide editor", () => {
const view = render(
<WorkflowGuide workflow={w} platform={platform} close={() => {}} />,
);
- await screen.findByRole("heading", { name: "Research guide" });
+ await screen.findByRole("textbox", { name: "SOP title" });
expect(screen.queryByRole("img")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "Review screenshot" }));
const preview = screen.getByRole("img", {
@@ -252,7 +331,6 @@ describe("guide editor", () => {
);
await screen.findByRole("img", { name: "Source for Collect sources" });
expect(platform.generate).not.toHaveBeenCalled();
- fireEvent.click(screen.getByRole("button", { name: "Edit SOP" }));
fireEvent.click(screen.getByRole("button", { name: "Remove screenshot" }));
await waitFor(() =>
expect(platform.save.mock.calls.at(-1)![0].steps[0].includeImage).toBe(
@@ -283,7 +361,7 @@ describe("guide editor", () => {
render(
<WorkflowGuide workflow={workflow} platform={host()} close={() => {}} />,
);
- await screen.findByRole("heading", { name: "Research guide" });
+ await screen.findByRole("textbox", { name: "SOP title" });
document.getElementById("guide-completion")!.scrollIntoView = scroll;
const event = new MouseEvent("click", { bubbles: true, cancelable: true });
screen
@@ -311,7 +389,7 @@ describe("guide editor", () => {
"Your saved guide could not be opened. Its files are unchanged.",
);
fireEvent.click(screen.getByRole("button", { name: "Try again" }));
- await screen.findByRole("heading", { name: "Research guide" });
+ await screen.findByRole("textbox", { name: "SOP title" });
expect(platform.generate).not.toHaveBeenCalled();
});
it("aborts generation on exit and ignores late results", async () => {
@@ -356,7 +434,7 @@ describe("guide editor", () => {
fireEvent.click(screen.getByRole("button", { name: /Try again|Retry/ }));
await screen.findByText("Saved your SOP on this device. Review its steps on the page.");
expect(platform.generate).toHaveBeenCalledTimes(2);
- await screen.findByRole("heading", { name: "Research guide" });
+ await screen.findByRole("textbox", { name: "SOP title" });
});
});
@@ -407,7 +485,7 @@ describe("SOP assistant and web editor", () => {
fireEvent.change(await screen.findByRole("textbox", { name: "Ask Screenpipe" }), { target: { value: "Shorten the title" } });
await waitFor(() => expect(screen.getByLabelText("Send message")).toBeEnabled());
fireEvent.click(screen.getByLabelText("Send message"));
- expect(await screen.findByRole("heading", { name: "Shorter research SOP" })).toBeInTheDocument();
+ await waitFor(() => expect(screen.getByRole("textbox", { name: "SOP title" })).toHaveValue("Shorter research SOP"));
await waitFor(() => expect(save).toHaveBeenCalledWith(expect.objectContaining({ title: "Shorter research SOP" })));
fireEvent.click(screen.getByLabelText("Minimize chat"));
fireEvent.click(screen.getByRole("button", { name: "Ask Screenpipe" }));
diff --git a/apps/screenpipe-workflows-web/scripts/eval-sop-chat.cjs b/apps/screenpipe-workflows-web/scripts/eval-sop-chat.cjs
index fe7842f64..a55e06a86 100644
--- a/apps/screenpipe-workflows-web/scripts/eval-sop-chat.cjs
+++ b/apps/screenpipe-workflows-web/scripts/eval-sop-chat.cjs
@@ -28,7 +28,7 @@ const assert = require("node:assert/strict"),
await p.getByRole("button", { name: "Minimize chat", exact: true }).click();
await p.screenshot({ path: dir + "/desktop-document.png" });
assert.equal(
- await p.locator('article[aria-label="SOP document"] h1').innerText(),
+ await p.getByRole("textbox", { name: "SOP title", exact: true }).inputValue(),
"Research synthesis",
);
await p.reload();
diff --git a/apps/screenpipe-workflows-web/scripts/eval-sop-inline-editor.cjs b/apps/screenpipe-workflows-web/scripts/eval-sop-inline-editor.cjs
new file mode 100644
index 000000000..0d13484d5
--- /dev/null
+++ b/apps/screenpipe-workflows-web/scripts/eval-sop-inline-editor.cjs
@@ -0,0 +1,308 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+// Uses the main app's browser-mock mode, with fictional data only.
+const { chromium } = require("playwright");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const base = process.env.SOP_APP_URL || "http://127.0.0.1:1457";
+const out = process.env.SOP_SCREENSHOTS || "/tmp/sop-inline-editor";
+fs.mkdirSync(out, { recursive: true });
+(async () => {
+ const browser = await chromium.launch({ headless: true, channel: "chrome" });
+ try {
+ const page = await browser.newPage({
+ viewport: { width: 1440, height: 1000 },
+ });
+ page.setDefaultTimeout(20000);
+ const errors = [];
+ page.on("pageerror", (e) => {
+ errors.push(e.message);
+ console.error("Browser error:", e.stack);
+ });
+ async function dismiss() {
+ await page
+ .getByRole("button", { name: "Do later", exact: true })
+ .click({ timeout: 5000 })
+ .catch(() => {});
+ await page
+ .getByRole("alertdialog")
+ .waitFor({ state: "hidden", timeout: 5000 })
+ .catch(() => {});
+ }
+ async function snap(name) {
+ console.log("capture", name);
+ await page.screenshot({
+ path: `${out}/${name}.png`,
+ animations: "disabled",
+ });
+ }
+ async function open() {
+ await page.goto(base + "/home?mode=workflows");
+ await page.getByText("Research synthesis", { exact: true }).waitFor();
+ await dismiss();
+ await page
+ .getByRole("button", { name: "Open map", exact: true })
+ .first()
+ .click();
+ await page
+ .getByRole("button", { name: "Create SOP", exact: true })
+ .click();
+ await page
+ .getByRole("textbox", { name: "SOP title", exact: true })
+ .waitFor()
+ .catch(async (error) => {
+ console.log((await page.locator("body").innerText()).slice(-5000));
+ throw error;
+ });
+ const minimize = page.getByRole("button", {
+ name: "Minimize chat",
+ exact: true,
+ });
+ if (await minimize.isVisible()) await minimize.click();
+ }
+ await open();
+ assert.equal(
+ await page
+ .getByRole("button", { name: "Open web editor", exact: true })
+ .innerText(),
+ "Open on web",
+ );
+ assert.equal(
+ await page
+ .getByRole("button", { name: "Export SOP", exact: true })
+ .innerText(),
+ "Export",
+ );
+ const title = page.getByRole("textbox", { name: "SOP title", exact: true });
+ assert.equal(
+ await page.getByRole("button", { name: "Edit SOP", exact: true }).count(),
+ 0,
+ );
+ await page.mouse.move(900, 200);
+ await snap("after-idle");
+ const grip = page.getByRole("button", {
+ name: "Reorder step 1",
+ exact: true,
+ });
+ assert.equal(
+ await grip.evaluate((el) => getComputedStyle(el).opacity),
+ "0",
+ );
+ await page.locator("#guide-step-0").scrollIntoViewIfNeeded();
+ await page.getByLabel("Step 1 title", { exact: true }).hover();
+ await page.waitForTimeout(200);
+ assert.equal(
+ await grip.evaluate((el) => getComputedStyle(el).opacity),
+ "1",
+ );
+ await snap("after-hover");
+ await page.getByLabel("Step 1 actions", { exact: true }).click();
+ await snap("after-menu");
+ await page
+ .getByRole("button", { name: "Move step 1 down", exact: true })
+ .click();
+ assert.equal(
+ await page.locator("details[data-step-actions][open]").count(),
+ 0,
+ );
+ await page
+ .getByRole("button", { name: "Reorder step 2", exact: true })
+ .focus();
+ await page.keyboard.press("Alt+ArrowUp");
+ await grip.focus();
+ await page.keyboard.press("Alt+ArrowDown");
+ assert.equal(
+ await page.getByLabel("Step 2 title", { exact: true }).inputValue(),
+ "Collect sources",
+ );
+ await page.keyboard.press("Alt+ArrowUp");
+ assert.equal(
+ await page.getByLabel("Step 1 title", { exact: true }).inputValue(),
+ "Collect sources",
+ );
+ // Real HTML drag/drop into the instruction editor must reorder the whole step.
+ await page.getByLabel("Step 1 title", { exact: true }).hover();
+ await grip.scrollIntoViewIfNeeded();
+ await grip.focus();
+ assert.equal(
+ await grip.evaluate((el) => getComputedStyle(el).webkitUserDrag),
+ "element",
+ );
+ const sourceBox = await grip.boundingBox();
+ await page.mouse.move(
+ sourceBox.x + sourceBox.width / 2,
+ sourceBox.y + sourceBox.height / 2,
+ );
+ await page.mouse.down();
+ await page.mouse.move(sourceBox.x + 40, sourceBox.y + 10, { steps: 10 });
+ await page
+ .getByLabel("Step 2 instructions", { exact: true })
+ .scrollIntoViewIfNeeded();
+ const targetBox = await page
+ .getByLabel("Step 2 instructions", { exact: true })
+ .boundingBox();
+ await page.mouse.move(targetBox.x + 30, targetBox.y + 15, { steps: 15 });
+ await page.mouse.move(targetBox.x + 35, targetBox.y + 15, { steps: 2 });
+ await page.mouse.up();
+ assert.equal(
+ await page.getByLabel("Step 2 title", { exact: true }).inputValue(),
+ "Collect sources",
+ );
+ await page
+ .getByRole("button", { name: "Reorder step 2", exact: true })
+ .focus();
+ await page.keyboard.press("Alt+ArrowUp");
+ await title.fill(
+ "Research synthesis: a repeatable guide for reviewing evidence and sharing findings",
+ );
+ await snap("after-editing");
+ const summary = page.getByLabel("Guide summary", { exact: true });
+ await summary.fill(
+ "Collect evidence, compare findings, and share a clear brief.",
+ );
+ await page
+ .getByLabel("Step 1 instructions", { exact: true })
+ .fill("Keep the original sources and their references.");
+ await page
+ .getByLabel("Step 1 expected result", { exact: true })
+ .fill("Sources ready to review.");
+ await page
+ .getByLabel("Before you start", { exact: true })
+ .fill("A clear research question\nAccess to source documents");
+ await page.getByRole("button", { name: "Add step", exact: true }).click();
+ await page
+ .getByLabel("Step 4 title", { exact: true })
+ .fill("Share the brief");
+ await page.getByLabel("Step 4 actions", { exact: true }).click();
+ await page
+ .getByRole("button", { name: "Remove step 4", exact: true })
+ .click();
+ await open();
+ assert.equal(
+ await title.inputValue(),
+ "Research synthesis: a repeatable guide for reviewing evidence and sharing findings",
+ );
+ assert.equal(
+ await summary.inputValue(),
+ "Collect evidence, compare findings, and share a clear brief.",
+ );
+ assert.match(
+ await page.getByLabel("Step 1 instructions", { exact: true }).innerText(),
+ /Keep the original sources/,
+ );
+ assert.equal(
+ await page
+ .getByLabel("Step 1 expected result", { exact: true })
+ .inputValue(),
+ "Sources ready to review.",
+ );
+ const before = await title.boundingBox();
+ await page
+ .getByRole("button", { name: "Open web editor", exact: true })
+ .click();
+ await page.getByRole("dialog", { name: "Open SOP on the web" }).waitFor();
+ assert.deepEqual(
+ await title.boundingBox(),
+ before,
+ "Sharing does not move the document",
+ );
+ await snap("after-share");
+ await page
+ .getByRole("button", { name: "Continue to web editor", exact: true })
+ .click();
+ await page
+ .getByRole("alert")
+ .filter({ hasText: "fictional preview does not publish" })
+ .waitFor();
+ await snap("after-share-error");
+ await page.keyboard.press("Escape");
+ await page.getByRole("button", { name: "Export SOP", exact: true }).click();
+ await snap("after-export");
+ const download = page.waitForEvent("download");
+ await page
+ .getByRole("button", { name: "Export HTML", exact: true })
+ .click();
+ assert.match((await download).suggestedFilename(), /\.html$/);
+ await title.focus();
+ await snap("after-focus");
+ await page.emulateMedia({ reducedMotion: "reduce" });
+ await page.evaluate(() => document.documentElement.classList.add("dark"));
+ await page.mouse.move(900, 200);
+ await title.blur();
+ await snap("after-system-dark");
+ await page.evaluate(() =>
+ document.documentElement.classList.remove("dark"),
+ );
+ for (const width of [800, 390]) {
+ await page.setViewportSize({ width, height: 900 });
+ await title.scrollIntoViewIfNeeded();
+ await page.waitForTimeout(250);
+ await snap(`after-${width}`);
+ assert(
+ await page.evaluate(
+ () => document.documentElement.scrollWidth <= innerWidth,
+ ),
+ );
+ assert(
+ await title.evaluate((el) => el.scrollHeight <= el.clientHeight + 2),
+ "Title wraps without clipping",
+ );
+ }
+ await page.getByLabel("Step 1 title", { exact: true }).hover();
+ const narrowGrip = await grip.boundingBox();
+ assert(narrowGrip.x >= 0, "Drag handle stays inside a narrow window");
+ await page.getByLabel("Step 1 actions", { exact: true }).click();
+ await snap("after-narrow-controls");
+ await page.keyboard.press("Escape");
+ // Regression: the main workflow editor shares the inline field and drag styles.
+ await page.setViewportSize({ width: 1440, height: 1000 });
+ await page
+ .getByRole("button", { name: "Back to workflow", exact: true })
+ .click();
+ const workflowTitle = page.getByRole("textbox", {
+ name: "Workflow title",
+ exact: true,
+ });
+ await page.mouse.move(900, 150);
+ await snap("workflow-toolbar");
+ assert.equal(
+ await page
+ .getByRole("button", { name: "Create SOP", exact: true })
+ .innerText(),
+ "Create SOP",
+ );
+ await workflowTitle.fill("Research synthesis updated");
+ await page
+ .getByRole("status", { name: "Save status", exact: true })
+ .filter({ hasText: /^Saved$/ })
+ .waitFor();
+ const workflowGrip = page.getByRole("button", {
+ name: "Move step 1",
+ exact: true,
+ });
+ assert.equal(
+ await workflowGrip.evaluate((el) => getComputedStyle(el).webkitUserDrag),
+ "element",
+ );
+ await workflowGrip.focus();
+ await page.keyboard.press("Alt+ArrowDown");
+ assert.equal(
+ await page.getByLabel("Step 2 title", { exact: true }).inputValue(),
+ "Collect sources",
+ );
+ await page.keyboard.press("Alt+ArrowUp");
+ assert.equal(
+ await page.getByLabel("Step 1 title", { exact: true }).inputValue(),
+ "Collect sources",
+ );
+ assert.deepEqual(errors, []);
+ console.log(
+ "PASS main app SOP: inline editing, keyboard + drag reordering, add/delete, reload persistence, sharing confirmation/error, export, hover/focus/system-dark/800px/390px",
+ );
+ } finally {
+ await browser.close();
+ }
+})().catch((e) => {
+ console.error(e);
+ process.exit(1);
+});
diff --git a/packages/workflows-ui/src/inline-text.tsx b/packages/workflows-ui/src/inline-text.tsx
new file mode 100644
index 000000000..466c2c856
--- /dev/null
+++ b/packages/workflows-ui/src/inline-text.tsx
@@ -0,0 +1,65 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+"use client";
+import { useLayoutEffect, useRef } from "react";
+import { WorkflowRichText } from "./rich-text";
+
+export function InlineText({
+ label,
+ value,
+ onChange,
+ placeholder = label,
+ rich = false,
+ className,
+ maxLength = 8000,
+}: {
+ label: string;
+ value: string;
+ onChange: (text: string) => void;
+ placeholder?: string;
+ rich?: boolean;
+ className?: string;
+ maxLength?: number;
+}) {
+ const ref = useRef<HTMLTextAreaElement>(null);
+ useLayoutEffect(() => {
+ const field = ref.current;
+ if (!field) return;
+ const resize = () => {
+ field.style.height = "auto";
+ field.style.height = `${field.scrollHeight + field.offsetHeight - field.clientHeight}px`;
+ };
+ resize();
+ let width = field.clientWidth;
+ const observer = new ResizeObserver(() => {
+ if (field.clientWidth !== width) {
+ width = field.clientWidth;
+ resize();
+ }
+ });
+ observer.observe(field);
+ return () => observer.disconnect();
+ }, [value]);
+ if (rich)
+ return (
+ <WorkflowRichText
+ label={label}
+ value={value}
+ onChange={onChange}
+ placeholder={placeholder}
+ maxLength={maxLength}
+ />
+ );
+ return (
+ <textarea
+ ref={ref}
+ rows={1}
+ aria-label={label}
+ placeholder={placeholder}
+ className={className}
+ value={value}
+ maxLength={maxLength}
+ onChange={(e) => onChange(e.target.value)}
+ />
+ );
+}
diff --git a/packages/workflows-ui/src/sop-document.module.css b/packages/workflows-ui/src/sop-document.module.css
index 89b1b245d..76eb5c151 100644
--- a/packages/workflows-ui/src/sop-document.module.css
+++ b/packages/workflows-ui/src/sop-document.module.css
@@ -11,18 +11,18 @@
overflow-wrap: anywhere;
}
.heading {
- padding: 28px 0 32px;
- margin-bottom: 24px;
- border-bottom: 1px solid var(--line, #dfe1d9);
+ padding: 20px 0 16px;
+ margin-bottom: 12px;
}
.kind {
font-size: 11px;
letter-spacing: 0.06em;
color: inherit;
opacity: 0.55;
- margin: 0 0 14px;
+ margin: 0 0 10px 5px;
}
-.document .title {
+.document h1.title,
+.document textarea.title {
font-family: inherit;
font-size: clamp(26px, 3vw, 38px);
font-weight: 600;
@@ -32,16 +32,19 @@
width: 100%;
background: transparent;
color: inherit;
- border: 0;
+ border: 1px solid transparent;
border-radius: 4px;
- padding: 0;
+ padding: 3px 5px;
+ box-sizing: border-box;
+ resize: none;
+ overflow: hidden;
}
.title:focus-visible {
- outline: 2px solid currentColor;
- outline-offset: 6px;
+ outline: none;
+ border-color: var(--muted, currentColor);
}
.subtitle {
- margin-top: 18px;
+ margin: 12px 0 0 5px;
font-size: 14px;
opacity: 0.65;
}
diff --git a/packages/workflows-ui/src/sop-document.tsx b/packages/workflows-ui/src/sop-document.tsx
index afa68e32f..7b7379cde 100644
--- a/packages/workflows-ui/src/sop-document.tsx
+++ b/packages/workflows-ui/src/sop-document.tsx
@@ -2,6 +2,7 @@
// https://screenpipe.com
"use client";
import type { ReactNode } from "react";
+import { InlineText } from "./inline-text";
import { WorkflowRichText } from "./rich-text";
import styles from "./sop-document.module.css";
@@ -26,12 +27,12 @@ export function SopDocument({
<header className={styles.heading}>
<p className={styles.kind}>Standard operating procedure</p>
{onTitleChange ? (
- <input
+ <InlineText
className={styles.title}
- aria-label="SOP title"
+ label="SOP title"
maxLength={300}
value={title}
- onChange={(event) => onTitleChange(event.target.value)}
+ onChange={onTitleChange}
/>
) : (
<h1 className={styles.title}>{title}</h1>
diff --git a/packages/workflows-ui/src/workflow-editor.module.css b/packages/workflows-ui/src/workflow-editor.module.css
index 6dfbdbd3d..1fa70df41 100644
--- a/packages/workflows-ui/src/workflow-editor.module.css
+++ b/packages/workflows-ui/src/workflow-editor.module.css
@@ -46,7 +46,8 @@
.number { padding-top: 7px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.step .title { font-family: var(--heading-font); min-width: 0; font-size: 17px; font-weight: 550; line-height: 1.4; }
.step > textarea, .step > div[data-testid="procedure-markdown"] { width: calc(100% - 24px); margin-left: 24px; }
-.editor .grip { cursor: grab; color: var(--muted); }
+.editor .grip {
+ -webkit-user-drag: element; cursor: grab; color: var(--muted); }
.editor .grip:active { cursor: grabbing; }
.stepTop > .grip { position: absolute; left: -30px; top: 0; }
.controls { position: relative; }
diff --git a/packages/workflows-ui/src/workflow-editor.tsx b/packages/workflows-ui/src/workflow-editor.tsx
index f0b044046..08350d2f9 100644
--- a/packages/workflows-ui/src/workflow-editor.tsx
+++ b/packages/workflows-ui/src/workflow-editor.tsx
@@ -1,7 +1,7 @@
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com
"use client";
-import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import { useEffect, useRef, useState, type ReactNode } from "react";
import {
ArrowDown,
ArrowUp,
@@ -19,56 +19,11 @@ import {
type WorkflowEdit,
type StageEdit,
} from "./workflow-edits";
-import { WorkflowRichText } from "./rich-text";
+import { InlineText } from "./inline-text";
import styles from "./workflow-editor.module.css";
-function Text({
- label,
- value,
- onChange,
- title = false,
- placeholder = label,
- rich = false,
-}: {
- label: string;
- value: string;
- onChange: (text: string) => void;
- title?: boolean;
- placeholder?: string;
- rich?: boolean;
-}) {
- const ref = useRef<HTMLTextAreaElement>(null);
- useLayoutEffect(() => {
- const field = ref.current;
- if (!field) return;
- const resize = () => {
- field.style.height = "0px";
- field.style.height = `${field.scrollHeight}px`;
- };
- resize();
- let width = field.clientWidth;
- const observer = new ResizeObserver(() => {
- if (field.clientWidth !== width) {
- width = field.clientWidth;
- resize();
- }
- });
- observer.observe(field);
- return () => observer.disconnect();
- }, [value]);
- if (rich) return <WorkflowRichText label={label} value={value} onChange={onChange} placeholder={placeholder} maxLength={8000} />;
- return (
- <textarea
- ref={ref}
- rows={1}
- aria-label={label}
- placeholder={placeholder}
- className={title ? styles.title : undefined}
- value={value}
- maxLength={8000}
- onChange={(e) => onChange(e.target.value)}
- />
- );
+function Text(props: Parameters<typeof InlineText>[0] & { title?: boolean }) {
+ return <InlineText {...props} className={props.title ? styles.title : undefined} />;
}
type EditorStage = Omit<StageEdit, "procedure"> & { key: string; procedure: (StageEdit["procedure"][number] & { key: string })[] };
diff --git a/packages/workflows-ui/src/workflow-guide.module.css b/packages/workflows-ui/src/workflow-guide.module.css
index d637359f8..f985eded5 100644
--- a/packages/workflows-ui/src/workflow-guide.module.css
+++ b/packages/workflows-ui/src/workflow-guide.module.css
@@ -34,11 +34,11 @@
}
.toolbar {
display: flex;
+ flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 16px;
- padding: 0 0 24px;
- border-bottom: 1px solid var(--line, #dfe1d9);
+ padding: 0 0 12px;
}
.toolbar > button {
border: 0;
@@ -47,6 +47,7 @@
}
.toolbar > div {
display: flex;
+ flex-wrap: wrap;
align-items: center;
gap: 10px;
}
@@ -54,21 +55,23 @@
color: var(--muted, #777b70);
font-size: 12px;
}
-.guide .iconButton {
- width: 40px;
- height: 40px;
- padding: 0;
- flex-shrink: 0;
+.guide .actionButton {
+ min-height: 34px;
+ padding: 6px 8px;
+ border-color: transparent;
+ background: transparent;
+ color: var(--muted);
+ white-space: nowrap;
}
-.guide .iconButton:hover,
-.guide .iconButton[aria-pressed="true"] {
+.guide .actionButton:hover {
background: var(--soft, #f1f2ec);
- border-color: var(--muted, #777b70);
+ color: var(--ink);
}
.saveStatus {
display: inline-flex;
align-items: center;
- gap: 8px;
+ gap: 6px;
+ padding: 0 8px;
}
.srOnly {
position: absolute;
@@ -86,12 +89,14 @@
grid-template-columns: 205px minmax(0, 820px);
gap: 48px;
justify-content: center;
- padding-top: 38px;
+ padding-top: 24px;
+ padding-bottom: 64px;
}
.outline {
align-self: start;
position: sticky;
- top: 25px;
+ top: 24px;
+ padding-top: 28px;
}
.eyebrow {
font-size: 10px;
@@ -160,72 +165,62 @@
font-size: 11px;
}
.section {
- padding: 22px 26px;
- background: var(--soft, #f1f2ec);
- border: 1px solid var(--line, #dfe1d9);
- border-radius: 9px;
- margin: 20px 0;
- scroll-margin-top: 25px;
+ margin: 28px 0;
+ scroll-margin-top: 24px;
}
.section h2 {
- margin: 0 0 12px;
- font-size: 16px;
- letter-spacing: -0.02em;
-}
-.section ul {
- margin: 0;
- padding-left: 19px;
- line-height: 1.9;
+ margin: 0 0 8px 5px;
+ font-size: 15px;
+ font-weight: 600;
+ line-height: 1.5;
}
.muted {
- color: var(--muted, #777b70);
- font-size: 13px;
- line-height: 1.65;
- margin: 0;
+ color: var(--muted);
+ font-size: 12px;
+ line-height: 1.6;
+ margin: 10px 5px;
}
.steps {
- margin-top: 30px;
+ margin: 32px 0 0;
}
.step {
- padding: 26px 0;
- border-top: 1px solid var(--line, #dfe1d9);
- scroll-margin-top: 25px;
+ position: relative;
+ margin: 0 0 32px;
+ scroll-margin-top: 24px;
}
-.stepHeading {
- display: flex;
- gap: 13px;
- align-items: center;
+.step.drop {
+ box-shadow: 0 -2px 0 var(--ink);
}
-.stepHeading h2 {
- font-size: 19px;
- letter-spacing: -0.025em;
- margin: 0;
- flex: 1;
+.stepHeading {
+ position: relative;
+ display: grid;
+ grid-template-columns: 28px minmax(0, 1fr) 28px;
+ align-items: start;
+ gap: 4px;
}
.number {
- width: 28px;
- height: 28px;
- display: grid;
- place-items: center;
- border-radius: 50%;
- background: var(--ink, #171815);
- color: var(--panel, #fff);
- flex-shrink: 0;
+ padding-top: 8px;
+ color: var(--muted);
font-size: 12px;
+ font-variant-numeric: tabular-nums;
+}
+.guide .stepTitle {
+ font-size: 19px;
+ font-weight: 600;
+ letter-spacing: -0.02em;
+ line-height: 1.4;
}
-.step p {
- line-height: 1.75;
- margin: 15px 0;
- white-space: pre-wrap;
+.stepBody {
+ margin: 6px 32px 0;
}
.step figure {
- margin: 20px 0;
+ margin: 16px 5px;
position: relative;
}
.step img {
display: block;
width: 100%;
- border: 1px solid var(--line, #dfe1d9);
+ border: 1px solid var(--line);
border-radius: 8px;
}
.step figure button {
@@ -233,24 +228,135 @@
bottom: 12px;
right: 12px;
}
-.stepTools {
+.guide .grip {
+ -webkit-user-drag: element;
+ position: absolute;
+ left: -28px;
+ top: 3px;
+ padding: 4px;
+ min-height: 28px;
+ border: 0;
+ background: transparent;
+ color: var(--muted);
+ cursor: grab;
+}
+.guide .grip:active {
+ cursor: grabbing;
+}
+.step::before {
+ content: "";
+ position: absolute;
+ left: -28px;
+ top: 0;
+ bottom: 0;
+ width: 28px;
+}
+.grip,
+.controls,
+.step figure button {
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 150ms ease;
+}
+.step:hover .grip,
+.step:hover .controls,
+.step:focus-within .grip,
+.step:focus-within .controls,
+.controls[open],
+.step figure:hover button,
+.step figure:focus-within button {
+ opacity: 1;
+ pointer-events: auto;
+}
+.controls {
+ position: relative;
+ margin-top: 4px;
+}
+.controls > summary {
display: flex;
- gap: 4px;
+ align-items: center;
+ justify-content: center;
+ list-style: none;
+ min-height: 28px;
+ border-radius: 4px;
+ color: var(--muted);
+ cursor: pointer;
+}
+.controls > summary::-webkit-details-marker {
+ display: none;
+}
+.controls > summary:hover {
+ background: var(--soft);
+}
+.controls > summary:focus-visible {
+ outline: 2px solid var(--muted);
+ outline-offset: 2px;
+}
+.stepTools {
+ position: absolute;
+ right: 0;
+ top: 30px;
+ z-index: 5;
+ width: 150px;
+ padding: 4px;
+ border: 1px solid var(--line);
+ border-radius: 6px;
+ background: var(--panel);
+ box-shadow: 0 4px 12px #0000000d;
}
.stepTools button {
- min-height: 30px;
- padding: 6px;
+ width: 100%;
+ justify-content: flex-start;
+ border: 0;
+ min-height: 32px;
+ background: transparent;
+ font-size: 12px;
+}
+.stepTools button:hover {
+ background: var(--soft);
}
.result {
- display: flex;
- align-items: center;
- gap: 9px;
- color: var(--muted, #777b70);
- font-size: 13px;
+ margin: 12px 0 0;
+ color: var(--muted);
}
-label.result {
+.result > span {
display: block;
- margin-top: 18px;
+ padding-left: 5px;
+ font-size: 11px;
+}
+.guide .addStep {
+ margin: 0 0 8px 32px;
+ border: 0;
+ background: transparent;
+ color: var(--muted);
+ padding: 4px 5px;
+}
+.guide .addStep:hover {
+ background: var(--soft);
+ color: var(--ink);
+}
+.guide textarea {
+ display: block;
+ box-sizing: border-box;
+ width: 100%;
+ resize: none;
+ overflow: hidden;
+ min-height: 30px;
+ border: 1px solid transparent;
+ border-radius: 4px;
+ padding: 3px 5px;
+ background: transparent;
+ color: inherit;
+ font: inherit;
+ font-size: 14px;
+ line-height: 1.65;
+}
+.guide textarea:focus-visible {
+ outline: none;
+ border-color: var(--muted);
+}
+.guide textarea::placeholder {
+ color: var(--muted);
}
.imageReview {
border: 1px solid var(--line, #dfe1d9);
@@ -274,28 +380,6 @@ label.result {
border-bottom: 1px solid var(--line, #dfe1d9);
border-radius: 0;
}
-.guide input:not([type="checkbox"]),
-.guide textarea {
- display: block;
- width: 100%;
- box-sizing: border-box;
- background: var(--panel, #fff);
- color: var(--ink, #171815);
- border: 1px solid var(--line, #dfe1d9);
- border-radius: 6px;
- padding: 12px;
- margin: 8px 0;
- font: inherit;
- line-height: 1.6;
-}
-.guide textarea {
- min-height: 92px;
- resize: vertical;
-}
-.guide input[aria-label="Guide title"] {
- font-size: 28px;
- font-weight: 600;
-}
.empty {
max-width: 650px;
min-height: 470px;
@@ -412,21 +496,32 @@ label.result {
}
@media (max-width: 650px) {
.toolbar {
- align-items: flex-start;
- flex-direction: column;
+ gap: 8px;
}
.toolbar > div {
- flex-wrap: wrap;
+ margin-left: auto;
+ gap: 4px;
+ }
+ .guide .grip {
+ left: 0;
+ z-index: 1;
+ }
+ .step:hover .number,
+ .step:focus-within .number {
+ opacity: 0;
}
- .section {
- padding: 18px;
+ .stepBody {
+ margin-right: 0;
}
.stepHeading {
- flex-wrap: wrap;
+ grid-template-columns: 24px minmax(0, 1fr) 28px;
}
- .stepTools {
- margin-left: auto;
+ .number {
+ font-size: 11px;
+ }
+ .guide .stepTitle {
+ font-size: 17px;
}
.phases {
gap: 12px;
@@ -435,3 +530,43 @@ label.result {
margin: 40px auto;
}
}
+
+.guide {
+ container-type: inline-size;
+ container-name: sop-guide;
+}
+.dialogActions {
+ margin-top: 24px;
+ flex-wrap: wrap;
+ justify-content: flex-end !important;
+ gap: 12px;
+}
+@container sop-guide (max-width: 1050px) {
+ .layout {
+ grid-template-columns: minmax(0, 780px);
+ }
+ .outline {
+ display: none;
+ }
+}
+@media (hover: none) {
+ .grip,
+ .controls,
+ .step figure button {
+ opacity: 1;
+ pointer-events: auto;
+ }
+}
+@media (prefers-reduced-motion: reduce) {
+ .grip,
+ .controls,
+ .step figure button {
+ transition: none;
+ }
+}
+
+@media (hover: none) and (max-width: 650px) {
+ .step .number {
+ opacity: 0;
+ }
+}
diff --git a/packages/workflows-ui/src/workflow-guide.tsx b/packages/workflows-ui/src/workflow-guide.tsx
index f36500267..1703f8088 100644
--- a/packages/workflows-ui/src/workflow-guide.tsx
+++ b/packages/workflows-ui/src/workflow-guide.tsx
@@ -12,7 +12,8 @@ import {
ExternalLink,
ImageOff,
Loader2,
- Pencil,
+ GripVertical,
+ MoreHorizontal,
Plus,
Trash2,
X,
@@ -26,6 +27,7 @@ import {
type WorkflowGuide as Guide,
} from "./guide";
import { WorkflowRichText } from "./rich-text";
+import { InlineText } from "./inline-text";
import { SopDocument } from "./sop-document";
import { GuideAssistant } from "./guide-assistant";
import styles from "./workflow-guide.module.css";
@@ -49,11 +51,15 @@ export function WorkflowGuide({
const [busy, setBusy] = useState(true);
const [error, setError] = useState("");
const [saved, setSaved] = useState("");
- const [editing, setEditing] = useState(false);
+ const [dragOver, setDragOver] = useState<number | null>(null);
+ const [announcement, setAnnouncement] = useState("");
+ const dragging = useRef<number | null>(null);
+ const stepKeys = useRef<string[]>([]);
+ const root = useRef<HTMLDivElement>(null);
const [images, setImages] = useState(false);
const [exporting, setExporting] = useState(false);
const [openingWeb, setOpeningWeb] = useState(false);
- const [webReview, setWebReview] = useState(false);
+ const webDialog = useRef<HTMLDialogElement>(null);
const [webError, setWebError] = useState("");
const [exportError, setExportError] = useState("");
const dialog = useRef<HTMLDialogElement>(null);
@@ -87,6 +93,7 @@ export function WorkflowGuide({
const existing = await platform.load(workflow);
if (version !== loadVersion.current) return;
if (existing) {
+ stepKeys.current = existing.steps.map(() => crypto.randomUUID());
latest.current = existing;
setDraft(existing);
setSaved("Saved on this device");
@@ -123,6 +130,47 @@ export function WorkflowGuide({
?.scrollIntoView({ block: "start" });
}
const stale = draft && draft.sourceRevision !== (workflow.revision ?? 0);
+ function moveStep(from: number, to: number) {
+ const current = latest.current;
+ if (!current || from === to || to < 0 || to >= current.steps.length) return;
+ root.current
+ ?.querySelectorAll<HTMLDetailsElement>("details[data-step-actions][open]")
+ .forEach((menu) => {
+ menu.open = false;
+ menu.querySelector("summary")?.focus();
+ });
+ const steps = [...current.steps];
+ const [step] = steps.splice(from, 1);
+ steps.splice(to, 0, step);
+ const [key] = stepKeys.current.splice(from, 1);
+ stepKeys.current.splice(to, 0, key);
+ update({ ...current, steps });
+ setAnnouncement(`Step moved to position ${to + 1}`);
+ }
+ function changeStep(index: number, patch: Partial<Guide["steps"][number]>) {
+ const current = latest.current;
+ if (current)
+ update({
+ ...current,
+ steps: current.steps.map((step, i) =>
+ i === index ? { ...step, ...patch } : step,
+ ),
+ });
+ }
+ useEffect(() => {
+ const dismiss = (event: PointerEvent) => {
+ root.current
+ ?.querySelectorAll<HTMLDetailsElement>(
+ "details[data-step-actions][open]",
+ )
+ .forEach((menu) => {
+ if (event.target instanceof Node && !menu.contains(event.target))
+ menu.open = false;
+ });
+ };
+ document.addEventListener("pointerdown", dismiss);
+ return () => document.removeEventListener("pointerdown", dismiss);
+ }, []);
function lines(
label: string,
key: "prerequisites" | "exceptions" | "completion" | "questions",
@@ -132,29 +180,20 @@ export function WorkflowGuide({
return (
<section className={styles.section} id={`guide-${key}`}>
<h2>{label}</h2>
- {editing ? (
- <textarea
- aria-label={label}
- placeholder={placeholder}
- value={draft[key].join("\n")}
- onChange={(e) =>
- update({ ...draft, [key]: e.target.value.split("\n") })
- }
- />
- ) : draft[key].filter(Boolean).length ? (
- <ul>
- {draft[key].filter(Boolean).map((line, i) => (
- <li key={i}>{line}</li>
- ))}
- </ul>
- ) : (
- <p className={styles.muted}>{placeholder}</p>
- )}
+ <InlineText
+ label={label}
+ placeholder={placeholder}
+ value={draft[key].join("\n")}
+ onChange={(text) => update({ ...draft, [key]: text.split("\n") })}
+ />
</section>
);
}
return (
- <div className={styles.guide}>
+ <div ref={root} className={styles.guide}>
+ <span role="status" className={styles.srOnly}>
+ {announcement}
+ </span>
<header className={styles.toolbar}>
<button
onClick={() => {
@@ -179,7 +218,13 @@ export function WorkflowGuide({
) : saved ? (
<Check size={16} aria-hidden="true" />
) : null}
- <span className={styles.srOnly}>{saved}</span>
+ <span aria-label={saved}>
+ {saved === "Saving…"
+ ? ui("Saving…")
+ : saved
+ ? ui("Saved")
+ : ""}
+ </span>
</>
)}
</span>
@@ -196,32 +241,20 @@ export function WorkflowGuide({
<>
{platform.openWeb && (
<button
- className={styles.iconButton}
+ className={styles.actionButton}
aria-label={ui("Open web editor")}
title={ui("Open web editor")}
onClick={() => {
- setWebReview(true);
+ webDialog.current?.showModal();
setWebError("");
}}
>
- <ExternalLink size={18} aria-hidden="true" />
+ <ExternalLink size={16} aria-hidden="true" />
+ {ui("Open on web")}
</button>
)}
<button
- className={styles.iconButton}
- aria-label={editing ? ui("Done editing") : ui("Edit SOP")}
- title={editing ? ui("Done editing") : ui("Edit SOP")}
- aria-pressed={editing}
- onClick={() => setEditing(!editing)}
- >
- {editing ? (
- <Check size={18} aria-hidden="true" />
- ) : (
- <Pencil size={18} aria-hidden="true" />
- )}
- </button>
- <button
- className={styles.iconButton}
+ className={styles.actionButton}
aria-label={ui("Export SOP")}
title={ui("Export SOP")}
onClick={() => {
@@ -230,7 +263,8 @@ export function WorkflowGuide({
dialog.current?.showModal();
}}
>
- <Download size={18} aria-hidden="true" />
+ <Download size={16} aria-hidden="true" />
+ {ui("Export")}
</button>
</>
)}
@@ -245,31 +279,53 @@ export function WorkflowGuide({
update={async (next) => {
await persist(next);
if (!mounted.current) return;
+ stepKeys.current = next.steps.map(() => crypto.randomUUID());
latest.current = next;
setDraft(next);
}}
/>
)}
- {draft && webReview && (
- <section
- className={styles.section}
- aria-label={ui("Open SOP on the web")}
- >
- <h2>Open your SOP on the web</h2>
- <p>
- Save the reviewed SOP text to your Screenpipe account to edit and
- share it. Recordings and screenshots stay on this device. Existing
- web edits are preserved when you reopen.
- </p>
- {webError && <p role="alert">{webError}</p>}
+ <dialog
+ ref={webDialog}
+ className={styles.exportDialog}
+ aria-labelledby="sop-web-title"
+ onCancel={(event) => {
+ if (openingWeb) event.preventDefault();
+ }}
+ >
+ <div>
+ <h2 id="sop-web-title">Open SOP on the web</h2>
+ <button
+ aria-label="Close web editor confirmation"
+ disabled={openingWeb}
+ onClick={() => webDialog.current?.close()}
+ >
+ <X size={18} />
+ </button>
+ </div>
+ <p>
+ Save this SOP’s text to your Screenpipe account to edit and share it.
+ Recordings and screenshots stay on this device. Existing web edits are
+ preserved.
+ </p>
+ {webError && <p role="alert">{webError}</p>}
+ <div className={styles.dialogActions}>
<button
disabled={openingWeb}
+ onClick={() => webDialog.current?.close()}
+ >
+ Cancel
+ </button>
+ <button
+ className={styles.primary}
+ disabled={openingWeb || !draft}
onClick={async () => {
+ if (!draft) return;
setOpeningWeb(true);
setWebError("");
try {
await platform.openWeb?.(draft);
- setWebReview(false);
+ webDialog.current?.close();
} catch (e) {
setWebError(
e instanceof Error ? e.message : "Could not open SOP",
@@ -281,11 +337,8 @@ export function WorkflowGuide({
>
{openingWeb ? ui("Opening…") : ui("Continue to web editor")}
</button>
- <button disabled={openingWeb} onClick={() => setWebReview(false)}>
- Cancel
- </button>
- </section>
- )}
+ </div>
+ </dialog>
{!draft ? (
<SopDocument title={workflow.title} subtitle="Draft for review">
<p role="status">
@@ -299,7 +352,7 @@ export function WorkflowGuide({
) : (
<div className={styles.layout}>
<aside className={styles.outline}>
- <p className={styles.eyebrow}>IN THIS GUIDE</p>
+ <p className={styles.eyebrow}>In this guide</p>
<a onClick={jump} href="#guide-prerequisites">
Before you start
</a>
@@ -323,22 +376,14 @@ export function WorkflowGuide({
</aside>
<SopDocument
title={draft.title}
- onTitleChange={
- editing ? (title) => update({ ...draft, title }) : undefined
- }
+ onTitleChange={(title) => update({ ...draft, title })}
subtitle={<>{draft.steps.length} steps · Draft for review</>}
>
- {editing ? (
- <textarea
- aria-label="Guide summary"
- value={draft.summary}
- onChange={(event) =>
- update({ ...draft, summary: event.target.value })
- }
- />
- ) : (
- <p>{draft.summary}</p>
- )}
+ <InlineText
+ label="Guide summary"
+ value={draft.summary}
+ onChange={(summary) => update({ ...draft, summary })}
+ />
{stale && (
<p className={styles.notice}>
This workflow has changed since the SOP was drafted. Your edits
@@ -362,109 +407,155 @@ export function WorkflowGuide({
: null;
return (
<section
- className={styles.step}
- key={i}
+ className={`${styles.step} ${dragOver === i ? styles.drop : ""}`}
+ key={stepKeys.current[i] ?? i}
id={`guide-step-${i}`}
+ onDragOverCapture={(event) => {
+ if (dragging.current !== null) {
+ event.preventDefault();
+ event.dataTransfer.dropEffect = "move";
+ setDragOver(i);
+ }
+ }}
+ onDragLeave={(event) => {
+ if (
+ !event.currentTarget.contains(
+ event.relatedTarget as Node,
+ )
+ )
+ setDragOver(null);
+ }}
+ onDropCapture={(event) => {
+ if (dragging.current !== null) {
+ event.preventDefault();
+ event.stopPropagation();
+ moveStep(dragging.current, i);
+ dragging.current = null;
+ setDragOver(null);
+ }
+ }}
>
<div className={styles.stepHeading}>
- <span className={styles.number}>{i + 1}</span>
- {editing ? (
- <input
- aria-label={ui("Step {value1} title", {
- value1: i + 1,
- })}
- value={step.title}
- onChange={(e) =>
- update({
- ...draft,
- steps: draft.steps.map((s, j) =>
- j === i ? { ...s, title: e.target.value } : s,
- ),
- })
+ <button
+ className={styles.grip}
+ aria-label={`Reorder step ${i + 1}`}
+ title="Drag to reorder. Use Alt + arrow keys to move."
+ draggable
+ onDragStart={(event) => {
+ dragging.current = i;
+ event.dataTransfer.effectAllowed = "move";
+ event.dataTransfer.setData(
+ "application/x-screenpipe-workflow",
+ String(i),
+ );
+ }}
+ onDragEnd={() => {
+ dragging.current = null;
+ setDragOver(null);
+ }}
+ onKeyDown={(event) => {
+ if (
+ event.altKey &&
+ ["ArrowUp", "ArrowDown"].includes(event.key)
+ ) {
+ event.preventDefault();
+ moveStep(i, i + (event.key === "ArrowUp" ? -1 : 1));
}
- />
- ) : (
- <h2>{step.title}</h2>
- )}
- {editing && (
+ }}
+ >
+ <GripVertical size={16} />
+ </button>
+ <span className={styles.number}>
+ {String(i + 1).padStart(2, "0")}
+ </span>
+ <InlineText
+ className={styles.stepTitle}
+ label={ui("Step {value1} title", { value1: i + 1 })}
+ value={step.title}
+ onChange={(title) => changeStep(i, { title })}
+ />
+ <details
+ className={styles.controls}
+ data-step-actions
+ onKeyDown={(event) => {
+ if (event.key === "Escape") {
+ event.currentTarget.open = false;
+ event.currentTarget
+ .querySelector("summary")
+ ?.focus();
+ }
+ }}
+ >
+ <summary aria-label={`Step ${i + 1} actions`}>
+ <MoreHorizontal size={18} />
+ </summary>
<div className={styles.stepTools}>
<button
aria-label={ui("Move step {value1} up", {
value1: i + 1,
})}
disabled={i === 0}
- onClick={() => {
- const steps = [...draft.steps];
- [steps[i - 1], steps[i]] = [
- steps[i],
- steps[i - 1],
- ];
- update({ ...draft, steps });
- }}
+ onClick={() => moveStep(i, i - 1)}
>
<ArrowUp size={14} />
+ Move up
</button>
<button
aria-label={ui("Move step {value1} down", {
value1: i + 1,
})}
disabled={i === draft.steps.length - 1}
- onClick={() => {
- const steps = [...draft.steps];
- [steps[i + 1], steps[i]] = [
- steps[i],
- steps[i + 1],
- ];
- update({ ...draft, steps });
- }}
+ onClick={() => moveStep(i, i + 1)}
>
<ArrowDown size={14} />
+ Move down
</button>
<button
aria-label={ui("Remove step {value1}", {
value1: i + 1,
})}
disabled={draft.steps.length === 1}
- onClick={() =>
+ onClick={() => {
+ stepKeys.current.splice(i, 1);
update({
...draft,
steps: draft.steps.filter((_, j) => j !== i),
- })
- }
+ });
+ requestAnimationFrame(() =>
+ root.current
+ ?.querySelector<HTMLTextAreaElement>(
+ `#guide-step-${Math.min(i, draft.steps.length - 2)} textarea`,
+ )
+ ?.focus(),
+ );
+ }}
>
<Trash2 size={14} />
+ Delete step
</button>
</div>
- )}
+ </details>
</div>
- <WorkflowRichText
- value={step.instruction}
- label={ui("Step {value1} instructions", {
- value1: i + 1,
- })}
- fullDocument
- onChange={
- editing
- ? (instruction) =>
- update({
- ...draft,
- steps: draft.steps.map((step, index) =>
- index === i ? { ...step, instruction } : step,
- ),
- })
- : undefined
- }
- />
- {image ? (
- <figure>
- <img
- src={image}
- alt={ui("Source for {value1}", {
- value1: step.title,
- })}
- draggable={false}
- />
- {editing && (
+ <div className={styles.stepBody}>
+ <WorkflowRichText
+ value={step.instruction}
+ label={ui("Step {value1} instructions", {
+ value1: i + 1,
+ })}
+ fullDocument
+ onChange={(instruction) =>
+ changeStep(i, { instruction })
+ }
+ />
+ {image ? (
+ <figure>
+ <img
+ src={image}
+ alt={ui("Source for {value1}", {
+ value1: step.title,
+ })}
+ draggable={false}
+ />
<button
onClick={() =>
update({
@@ -478,75 +569,62 @@ export function WorkflowGuide({
<ImageOff size={14} />
Remove screenshot
</button>
- )}
- </figure>
- ) : source ? (
- <ScreenshotReview
- key={`${step.sourceStage}:${source.dataUrl}`}
- source={source}
- title={step.title}
- include={() => {
- update({
- ...draft,
- steps: draft.steps.map((s, j) =>
- j === i
- ? {
- ...s,
- includeImage: true,
- imageReview: {
- frameId: source.frameId,
- timestamp: source.timestamp,
- },
- }
- : s,
- ),
- });
- }}
- />
- ) : (
- <p className={styles.muted}>
- {stale
- ? ui(
- "Source changed. Regenerate this SOP to review its screenshots.",
- )
- : ui("No captured screenshot for this step.")}
- </p>
- )}
- {editing ? (
- <label className={styles.result}>
- Expected result
- <input
- aria-label={ui("Step {value1} expected result", {
- value1: i + 1,
- })}
- value={step.expectedResult}
- onChange={(e) =>
+ </figure>
+ ) : source ? (
+ <ScreenshotReview
+ key={`${step.sourceStage}:${source.dataUrl}`}
+ source={source}
+ title={step.title}
+ include={() => {
update({
...draft,
steps: draft.steps.map((s, j) =>
j === i
- ? { ...s, expectedResult: e.target.value }
+ ? {
+ ...s,
+ includeImage: true,
+ imageReview: {
+ frameId: source.frameId,
+ timestamp: source.timestamp,
+ },
+ }
: s,
),
- })
- }
+ });
+ }}
/>
- </label>
- ) : (
- step.expectedResult && (
- <p className={styles.result}>
- <Check size={15} />
- {step.expectedResult}
+ ) : (
+ <p className={styles.muted}>
+ {stale
+ ? ui(
+ "Source changed. Regenerate this SOP to review its screenshots.",
+ )
+ : ui("No captured screenshot for this step.")}
</p>
- )
- )}
+ )}
+ <div className={styles.result}>
+ <span>Expected result</span>
+ <InlineText
+ label={ui("Step {value1} expected result", {
+ value1: i + 1,
+ })}
+ placeholder="Add an expected result…"
+ value={step.expectedResult}
+ onChange={(expectedResult) =>
+ changeStep(i, { expectedResult })
+ }
+ />
+ </div>
+ </div>
</section>
);
})}
</div>
- {editing && draft.steps.length < 40 && (
+ {draft.steps.length < 40 && (
<button
- onClick={() =>
+ className={styles.addStep}
+ onClick={() => {
+ stepKeys.current.push(crypto.randomUUID());
update({
...draft,
steps: [
@@ -559,8 +637,15 @@ export function WorkflowGuide({
includeImage: false,
},
],
- })
- }
+ });
+ requestAnimationFrame(() =>
+ root.current
+ ?.querySelector<HTMLTextAreaElement>(
+ `#guide-step-${draft.steps.length} textarea`,
+ )
+ ?.focus(),
+ );
+ }}
>
<Plus size={15} />
Add step
diff --git a/packages/workflows-ui/src/workflows-app.tsx b/packages/workflows-ui/src/workflows-app.tsx
index 83a94f0e2..a1da5cd50 100644
--- a/packages/workflows-ui/src/workflows-app.tsx
+++ b/packages/workflows-ui/src/workflows-app.tsx
@@ -994,7 +994,7 @@ function WorkflowDetail({ workflow, navigate, platform, workProfile, saveCorrect
return next;
});
const agentActions = workflowAgentActions?.(workflow);
- const workflowActions = <div className={styles.workflowActions}>{agentActions}{platform.guides && <button className={styles.skillButton} type="button" aria-label="Create SOP" title="Create SOP" onClick={() => setGuideOpen(true)}><BookOpen size={16} aria-hidden="true"/></button>}{platform.generateWorkflowSkill && platform.saveWorkflowSkill && <button className={styles.skillButton} type="button" onClick={openSkill}><Sparkles size={14} />{skillGenerating ? ui("Creating skill…") : skillSaved ? platform.skillInstallMode === "preview" ? ui("Skill preview") : ui("Skill installed") : skillDraft ? ui("Review skill") : ui("Create skill")}</button>}{onShareWorkflow && <button className={styles.skillButton} type="button" onClick={() => onShareWorkflow(workflow)}><Share2 size={14} />Share with team</button>}{platform.assistant?.saveFeedback && <button className={styles.skillButton} type="button" onClick={() => window.dispatchEvent(new CustomEvent("workflows:feedback", { detail: { key: `feedback:${workflow.id || workflow.title}`, title: workflow.title, workflow, purpose: "feedback" } }))}><MessageCircle size={14} />Feedback</button>}</div>;
+ const workflowActions = <div className={styles.workflowActions}>{agentActions}{platform.guides && <button className={styles.skillButton} type="button" aria-label="Create SOP" title="Create SOP" onClick={() => setGuideOpen(true)}><BookOpen size={16} aria-hidden="true"/>{ui("Create SOP")}</button>}{platform.generateWorkflowSkill && platform.saveWorkflowSkill && <button className={styles.skillButton} type="button" onClick={openSkill}><Sparkles size={14} />{skillGenerating ? ui("Creating skill…") : skillSaved ? platform.skillInstallMode === "preview" ? ui("Skill preview") : ui("Skill installed") : skillDraft ? ui("Review skill") : ui("Create skill")}</button>}{onShareWorkflow && <button className={styles.skillButton} type="button" onClick={() => onShareWorkflow(workflow)}><Share2 size={14} />Share with team</button>}{platform.assistant?.saveFeedback && <button className={styles.skillButton} type="button" onClick={() => window.dispatchEvent(new CustomEvent("workflows:feedback", { detail: { key: `feedback:${workflow.id || workflow.title}`, title: workflow.title, workflow, purpose: "feedback" } }))}><MessageCircle size={14} />Feedback</button>}</div>;
return (
<>
<button className={styles.backButton} onClick={() => navigate("workflows")}><ArrowLeft size={14} />All workflows</button>