π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
feat(editor): insert, edit and reorder heading and callout blocks
Luis Ortiza1c3bb14223b
diff --git a/src/ui/fullview/GuideContent.tsx b/src/ui/fullview/GuideContent.tsxindex 66008fd..c01989c 100644--- a/src/ui/fullview/GuideContent.tsx+++ b/src/ui/fullview/GuideContent.tsx@@ -2,6 +2,7 @@ import { History, Loader2, Play, Sparkles } from 'lucide-react';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { TypeAnimation } from 'react-type-animation';import { i18n } from '#imports';+import { actionSteps } from '@/core/guides/blocks';import {deleteStep,getGuide,@@ -118,7 +119,7 @@ export default function GuideContent({ guideId, initialStepId, initialTool }: Gu}document.title = `${newTitle} β ${i18n.t('app_name')}`;setGuideTitle(newTitle);- setGuideStepCount(result.steps.length);+ setGuideStepCount(actionSteps(result.steps).length);setGuideExportData({ guideId, ...result });}setLoading(false);@@ -287,6 +288,7 @@ export default function GuideContent({ guideId, initialStepId, initialTool }: Guconst previewView = preview && previewData?.snapshotId === preview.id ? previewData : null;const viewSteps = previewView ? previewView.steps : data.steps;const viewScreenshots = previewView ? previewView.screenshots : data.screenshots;+ const actionCount = actionSteps(viewSteps).length;const domain = getMostCommonDomain(viewSteps);const editingScreenshot = editingStepId ? data.screenshots.get(editingStepId) : undefined;const animatingTitle = preview ? null : typingTitle;@@ -431,9 +433,9 @@ export default function GuideContent({ guideId, initialStepId, initialTool }: Gu{formatDate(data.guide.createdAt)}</span><span className="inline-flex items-center text-[11px] font-medium text-muted-foreground bg-card border border-border px-2.5 py-0.5 rounded-full">- {viewSteps.length !== 1- ? i18n.t('fullview_stepCountPlural', [String(viewSteps.length)])- : i18n.t('fullview_stepCount', [String(viewSteps.length)])}+ {actionCount !== 1+ ? i18n.t('fullview_stepCountPlural', [String(actionCount)])+ : i18n.t('fullview_stepCount', [String(actionCount)])}</span>{domain && (<span className="inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground bg-card border border-border pl-1.5 pr-2.5 py-0.5 rounded-full">diff --git a/src/ui/fullview/components/GuideStepList.tsx b/src/ui/fullview/components/GuideStepList.tsxindex bdbe7b3..bd3a234 100644--- a/src/ui/fullview/components/GuideStepList.tsx+++ b/src/ui/fullview/components/GuideStepList.tsx@@ -1,9 +1,12 @@import { useEffect, useRef, useState } from 'react';-import { reorderSteps } from '@/core/guides/service';-import type { Screenshot, Step } from '@/core/guides/types';+import { isBlock, stepNumbers } from '@/core/guides/blocks';+import { insertBlock, reorderSteps } from '@/core/guides/service';+import type { BlockType, Screenshot, Step } from '@/core/guides/types';import { useFullview } from '@/stores/fullview';+import BlockCard from '@/ui/shared/BlockCard';import EmptyGuideState from '@/ui/shared/EmptyGuideState';import { dominantRatio } from '@/ui/shared/ImagePlaceholder';+import InsertBlockMenu from '@/ui/shared/InsertBlockMenu';import StepCard from '@/ui/sidepanel/StepCard';interface GuideStepListProps {@@ -40,6 +43,7 @@ export default function GuideStepList({const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);const stepRefs = useRef<Map<string, HTMLDivElement>>(new Map());const frameRatio = dominantRatio(screenshots);+ const numbers = stepNumbers(steps);useEffect(() => {if (scrollToStepId) {@@ -78,12 +82,38 @@ export default function GuideStepList({setDragOverIndex(null);};+ const handleInsertBlock = async (atIndex: number, blockType: BlockType) => {+ await insertBlock(guideId, atIndex, blockType, '');+ onChanged?.();+ };++ const dragHandlers = (idx: number) =>+ readOnly+ ? undefined+ : {+ onDragStart: (e: React.DragEvent) => {+ setDragIndex(idx);+ e.dataTransfer.effectAllowed = 'move';+ },+ onDragOver: (e: React.DragEvent) => {+ e.preventDefault();+ setDragOverIndex(idx);+ },+ onDragEnd: handleDragEnd,+ };+if (steps.length === 0) {- return <EmptyGuideState />;+ return (+ <div className="flex flex-col">+ <EmptyGuideState />+ {!readOnly && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(0, blockType)} />}+ </div>+ );}return (<div className="space-y-6">+ {!readOnly && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(0, blockType)} />}{steps.map((step, idx) => (<divkey={step.id}@@ -96,33 +126,32 @@ export default function GuideStepList({{dragOverIndex === idx && dragIndex !== null && dragIndex !== idx && (<div className="h-1 bg-accent rounded-full mx-4 mb-2" />)}- <StepCard- step={step}- screenshot={screenshots.get(step.id)}- placeholderRatio={frameRatio}- frameRatio={frameRatio}- onDescriptionChange={onDescriptionChange}- onDelete={onDelete}- onOpenEditor={onOpenEditor}- readOnly={readOnly}- hasApiKey={hasApiKey}- onChanged={onChanged}- dragHandleProps={- readOnly- ? undefined- : {- onDragStart: (e: React.DragEvent) => {- setDragIndex(idx);- e.dataTransfer.effectAllowed = 'move';- },- onDragOver: (e: React.DragEvent) => {- e.preventDefault();- setDragOverIndex(idx);- },- onDragEnd: handleDragEnd,- }- }- />+ {isBlock(step) ? (+ <BlockCard+ step={step}+ onDescriptionChange={onDescriptionChange}+ onDelete={onDelete}+ onChanged={onChanged}+ readOnly={readOnly}+ dragHandleProps={dragHandlers(idx)}+ />+ ) : (+ <StepCard+ step={step}+ number={numbers.get(step.id) ?? 0}+ screenshot={screenshots.get(step.id)}+ placeholderRatio={frameRatio}+ frameRatio={frameRatio}+ onDescriptionChange={onDescriptionChange}+ onDelete={onDelete}+ onOpenEditor={onOpenEditor}+ readOnly={readOnly}+ hasApiKey={hasApiKey}+ onChanged={onChanged}+ dragHandleProps={dragHandlers(idx)}+ />+ )}+ {!readOnly && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(idx + 1, blockType)} />}</div>))}</div>diff --git a/src/ui/shared/InsertBlockMenu.tsx b/src/ui/shared/InsertBlockMenu.tsxnew file mode 100644index 0000000..7e38dd1--- /dev/null+++ b/src/ui/shared/InsertBlockMenu.tsx@@ -0,0 +1,71 @@+import { Heading, Plus, StickyNote } from 'lucide-react';+import { useEffect, useRef, useState } from 'react';+import { i18n } from '#imports';+import type { BlockType } from '@/core/guides/types';++interface InsertBlockMenuProps {+ onInsert: (blockType: BlockType) => void;+}++export default function InsertBlockMenu({ onInsert }: InsertBlockMenuProps) {+ const [open, setOpen] = useState(false);+ const rowRef = useRef<HTMLDivElement>(null);+ const triggerRef = useRef<HTMLButtonElement>(null);++ useEffect(() => {+ if (!open) return;+ const handlePointerDown = (e: MouseEvent) => {+ if (rowRef.current && !rowRef.current.contains(e.target as Node)) setOpen(false);+ };+ document.addEventListener('mousedown', handlePointerDown);+ return () => document.removeEventListener('mousedown', handlePointerDown);+ }, [open]);++ const choices = [+ { type: 'heading' as const, icon: Heading, label: i18n.t('blocks.heading') },+ { type: 'callout' as const, icon: StickyNote, label: i18n.t('blocks.callout') },+ ];++ return (+ <div+ ref={rowRef}+ onKeyDown={(e) => {+ if (e.key !== 'Escape' || !open) return;+ setOpen(false);+ triggerRef.current?.focus();+ }}+ className="group relative flex items-center justify-center gap-1 h-6 my-1"+ >+ <span+ aria-hidden="true"+ className={`absolute inset-x-0 top-1/2 border-t border-dashed border-border transition-opacity ${open ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 group-focus-within:opacity-100'}`}+ />+ <button+ type="button"+ ref={triggerRef}+ onClick={() => setOpen((prev) => !prev)}+ title={i18n.t('blocks.add')}+ aria-label={i18n.t('blocks.add')}+ aria-expanded={open}+ className={`relative flex items-center justify-center w-5 h-5 rounded-full border border-border bg-card text-purple transition-opacity hover:text-accent focus-visible:opacity-100 group-hover:opacity-100 ${open ? 'opacity-100 text-accent' : 'opacity-0'}`}+ >+ <Plus size={13} />+ </button>+ {open &&+ choices.map((choice) => (+ <button+ key={choice.type}+ type="button"+ onClick={() => {+ setOpen(false);+ onInsert(choice.type);+ }}+ className="relative flex items-center gap-1 rounded-full border border-border bg-card px-2 py-0.5 text-[11px] font-medium text-purple hover:text-accent hover:bg-secondary"+ >+ <choice.icon size={13} />+ {choice.label}+ </button>+ ))}+ </div>+ );+}diff --git a/src/ui/sidepanel/GuideEditor.tsx b/src/ui/sidepanel/GuideEditor.tsxindex 0800999..b5165a4 100644--- a/src/ui/sidepanel/GuideEditor.tsx+++ b/src/ui/sidepanel/GuideEditor.tsx@@ -1,27 +1,31 @@import { ArrowLeft, Check, Layers, Loader2, Maximize2, Pencil, Play, Sparkles } from 'lucide-react';import { useCallback, useEffect, useRef, useState } from 'react';import { i18n } from '#imports';+import { actionSteps, isBlock, stepNumbers } from '@/core/guides/blocks';import {createSnapshot,deleteStep,getGuide,+ insertBlock,onGuidesChanged,reorderSteps,updateGuideDescription,updateGuideTitle,updateStepDescription,} from '@/core/guides/service';-import type { Guide, Screenshot, Step } from '@/core/guides/types';+import type { BlockType, Guide, Screenshot, Step } from '@/core/guides/types';import { createTab, focusWindow, getExtensionURL, localStorage, queryTabs, updateTab } from '@/lib/browser-api';import { logger } from '@/lib/logger';import { sendMessage } from '@/lib/messaging';import { getMostCommonDomain } from '@/lib/utils';import { Input } from '@/ui/components/ui/input';import { useAskAi } from '@/ui/shared/AskAi';+import BlockCard from '@/ui/shared/BlockCard';import EmptyGuideState from '@/ui/shared/EmptyGuideState';import FaviconImg from '@/ui/shared/FaviconImg';import { guideDescriptionErrorMessage } from '@/ui/shared/guide-description-error';import { dominantRatio } from '@/ui/shared/ImagePlaceholder';+import InsertBlockMenu from '@/ui/shared/InsertBlockMenu';import Toast from '@/ui/shared/Toast';import ExportMenu from './ExportMenu';import StepCard from './StepCard';@@ -161,6 +165,14 @@ export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorP[guideId, loadGuide, applyGuide],);+ const handleInsertBlock = useCallback(+ async (atIndex: number, blockType: BlockType) => {+ await insertBlock(guideId, atIndex, blockType, '');+ await loadGuide();+ },+ [guideId, loadGuide],+ );+const openInFullView = useCallback((targetGuideId: string, options?: OpenInFullViewOptions) => {const params = new URLSearchParams({ guideId: targetGuideId });if (options?.stepId) params.set('stepId', options.stepId);@@ -201,6 +213,39 @@ export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorP}const metaGenerating = title === i18n.t('fullview.untitledGuide') && data.steps.length > 0 && !description;+ const actionCount = actionSteps(data.steps).length;+ const numbers = stepNumbers(data.steps);++ const dragHandlers = (idx: number) =>+ editing+ ? {+ onDragStart: (e: React.DragEvent) => {+ setDragIndex(idx);+ e.dataTransfer.effectAllowed = 'move';+ },+ onDragOver: (e: React.DragEvent) => {+ e.preventDefault();+ setDragOverIndex(idx);+ },+ onDragEnd: () => {+ if (dragIndex !== null && dragOverIndex !== null && dragIndex !== dragOverIndex) {+ setData((prev) => {+ if (!prev) return prev;+ const newSteps = [...prev.steps];+ const [moved] = newSteps.splice(dragIndex, 1);+ newSteps.splice(dragOverIndex, 0, moved);+ reorderSteps(+ guideId,+ newSteps.map((s) => s.id),+ );+ return { ...prev, steps: newSteps };+ });+ }+ setDragIndex(null);+ setDragOverIndex(null);+ },+ }+ : undefined;return (<div className="min-h-screen bg-card flex flex-col">@@ -305,9 +350,9 @@ export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorP<div className="text-[11px] flex items-center gap-2 text-muted-foreground" style={{ marginLeft: '34px' }}><span className="flex items-center gap-1"><Layers size={11} />- {data.steps.length !== 1- ? i18n.t('fullview.stepCountPlural', [String(data.steps.length)])- : i18n.t('fullview.stepCount', [String(data.steps.length)])}+ {actionCount !== 1+ ? i18n.t('fullview.stepCountPlural', [String(actionCount)])+ : i18n.t('fullview.stepCount', [String(actionCount)])}</span>{(() => {const d = getMostCommonDomain(data.steps);@@ -324,58 +369,47 @@ export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorP</div><div className="px-4 pt-1 pb-4 flex-1 flex flex-col">{data.steps.length === 0 ? (- <EmptyGuideState />+ <>+ <EmptyGuideState />+ {editing && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(0, blockType)} />}+ </>) : (- data.steps.map((step, idx) => (- <div key={step.id}>- {dragOverIndex === idx && dragIndex !== null && dragIndex !== idx && (- <div className="h-1 bg-accent rounded-full mx-4 mb-1" />- )}- <StepCard- step={step}- screenshot={data.screenshots.get(step.id)}- placeholderRatio={dominantRatio(data.screenshots)}- frameRatio={dominantRatio(data.screenshots)}- onDescriptionChange={handleDescriptionChange}- onDelete={handleDeleteStep}- onOpenEditor={(stepId, tool) => openInFullView(guideId, { stepId, tool })}- readOnly={!editing}- hasApiKey={hasApiKey}- onChanged={loadGuide}- dragHandleProps={- editing- ? {- onDragStart: (e: React.DragEvent) => {- setDragIndex(idx);- e.dataTransfer.effectAllowed = 'move';- },- onDragOver: (e: React.DragEvent) => {- e.preventDefault();- setDragOverIndex(idx);- },- onDragEnd: () => {- if (dragIndex !== null && dragOverIndex !== null && dragIndex !== dragOverIndex) {- setData((prev) => {- if (!prev) return prev;- const newSteps = [...prev.steps];- const [moved] = newSteps.splice(dragIndex, 1);- newSteps.splice(dragOverIndex, 0, moved);- reorderSteps(- guideId,- newSteps.map((s) => s.id),- );- return { ...prev, steps: newSteps };- });- }- setDragIndex(null);- setDragOverIndex(null);- },- }- : undefined- }- />- </div>- ))+ <>+ {editing && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(0, blockType)} />}+ {data.steps.map((step, idx) => (+ <div key={step.id}>+ {dragOverIndex === idx && dragIndex !== null && dragIndex !== idx && (+ <div className="h-1 bg-accent rounded-full mx-4 mb-1" />+ )}+ {isBlock(step) ? (+ <BlockCard+ step={step}+ onDescriptionChange={handleDescriptionChange}+ onDelete={handleDeleteStep}+ onChanged={loadGuide}+ readOnly={!editing}+ dragHandleProps={dragHandlers(idx)}+ />+ ) : (+ <StepCard+ step={step}+ number={numbers.get(step.id) ?? 0}+ screenshot={data.screenshots.get(step.id)}+ placeholderRatio={dominantRatio(data.screenshots)}+ frameRatio={dominantRatio(data.screenshots)}+ onDescriptionChange={handleDescriptionChange}+ onDelete={handleDeleteStep}+ onOpenEditor={(stepId, tool) => openInFullView(guideId, { stepId, tool })}+ readOnly={!editing}+ hasApiKey={hasApiKey}+ onChanged={loadGuide}+ dragHandleProps={dragHandlers(idx)}+ />+ )}+ {editing && <InsertBlockMenu onInsert={(blockType) => handleInsertBlock(idx + 1, blockType)} />}+ </div>+ ))}+ </>)}</div></div>diff --git a/src/ui/sidepanel/StepCard.tsx b/src/ui/sidepanel/StepCard.tsxindex 57de166..aabb871 100644--- a/src/ui/sidepanel/StepCard.tsx+++ b/src/ui/sidepanel/StepCard.tsx@@ -18,6 +18,7 @@ interface DragHandleProps {interface StepCardProps {step: Step;+ number: number;screenshot: Screenshot | undefined;onDescriptionChange: (stepId: string, description: string) => void;onDelete: (stepId: string) => void;@@ -33,6 +34,7 @@ interface StepCardProps {export default function StepCard({step,+ number,screenshot,onDescriptionChange,onDelete,@@ -121,7 +123,7 @@ export default function StepCard({{screenshot ? (<ScreenshotViewscreenshot={screenshot}- alt={`Step ${step.index + 1} screenshot`}+ alt={`Step ${number} screenshot`}className="!rounded-none !border-0"cropframeRatio={frameRatio}@@ -141,7 +143,7 @@ export default function StepCard({<div className="px-3 pt-2 pb-2"><div className="flex items-center gap-2"><span className="flex items-center justify-center w-[22px] h-[22px] rounded-full text-[11px] font-bold shrink-0 bg-primary text-primary-foreground">- {step.index + 1}+ {number}</span>{step.aiPending ? (<span className="flex items-center gap-1.5 text-[13px] font-medium leading-snug flex-1 text-muted-foreground">diff --git a/src/ui/sidepanel/__tests__/step-card-upload.test.tsx b/src/ui/sidepanel/__tests__/step-card-upload.test.tsxindex 7fb7a8e..56d9035 100644--- a/src/ui/sidepanel/__tests__/step-card-upload.test.tsx+++ b/src/ui/sidepanel/__tests__/step-card-upload.test.tsx@@ -22,6 +22,7 @@ function renderCard(readOnly: boolean) {return render(<StepCardstep={step}+ number={1}screenshot={undefined}readOnly={readOnly}onDescriptionChange={vi.fn()}