🎬 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(guides): add heading and callout block types
Luis Ortizf5f73147f239
diff --git a/src/core/guides/blocks.ts b/src/core/guides/blocks.tsnew file mode 100644index 0000000..50a2134--- /dev/null+++ b/src/core/guides/blocks.ts@@ -0,0 +1,57 @@+import { i18n } from '#imports';+import { hexToRgb, normalizeHex, rgbToHex } from '@/core/screenshot/color';+import type { CalloutVariant, Step } from './types';++export const CALLOUT_VARIANTS: CalloutVariant[] = ['info', 'warning', 'error', 'success', 'custom'];++const VARIANT_LABEL_KEYS = {+ info: 'blocks.variantInfo',+ warning: 'blocks.variantWarning',+ error: 'blocks.variantError',+ success: 'blocks.variantSuccess',+ custom: 'blocks.variantCustom',+} as const satisfies Record<CalloutVariant, string>;++export function variantLabel(variant: CalloutVariant): string {+ return i18n.t(VARIANT_LABEL_KEYS[variant]);+}++export const DEFAULT_CALLOUT_COLOR = '#4F46E5';++const VARIANT_ACCENTS: Record<CalloutVariant, string> = {+ info: '#4F46E5',+ warning: '#D97706',+ error: '#DC2626',+ success: '#059669',+ custom: DEFAULT_CALLOUT_COLOR,+};++export function isBlock(step: Step): boolean {+ return step.blockType !== undefined;+}++export function actionSteps(steps: Step[]): Step[] {+ return steps.filter((step) => step.blockType === undefined);+}++export function stepNumbers(steps: Step[]): Map<string, number> {+ const numbers = new Map<string, number>();+ let n = 0;+ for (const step of steps) {+ if (step.blockType === undefined) numbers.set(step.id, ++n);+ }+ return numbers;+}++export function calloutAccent(step: Step): string {+ const variant = step.calloutVariant ?? 'info';+ if (variant === 'custom') return normalizeHex(step.calloutColor ?? '') ?? DEFAULT_CALLOUT_COLOR;+ return VARIANT_ACCENTS[variant];+}++export function tint(hex: string, ratio = 0.12): string {+ const rgb = hexToRgb(hex);+ if (!rgb) return '#FFFFFF';+ const [r, g, b] = rgb.map((channel) => 255 + (channel - 255) * ratio);+ return rgbToHex(r, g, b);+}diff --git a/src/core/guides/service.ts b/src/core/guides/service.tsindex f203900..5d4e070 100644--- a/src/core/guides/service.ts+++ b/src/core/guides/service.ts@@ -2,7 +2,7 @@ import { i18n } from '#imports';import type { ScreenshotEdits } from '@/core/screenshot/types';import { db } from './db';import { hashPayload } from './snapshot-hash';-import type { Guide, Screenshot, Snapshot, Step } from './types';+import type { BlockType, CalloutVariant, Guide, Screenshot, Snapshot, Step } from './types';export type GuideChangeEvent = { type: 'starred'; id: string; starred: boolean } | { type: 'mutated' };@@ -139,6 +139,37 @@ export async function createStep(step: Step): Promise<void> {await db.steps.add(step);}+export async function insertBlock(+ guideId: string,+ atIndex: number,+ blockType: BlockType,+ description: string,+): Promise<string> {+ const id = crypto.randomUUID();+ await db.transaction('rw', db.steps, db.guides, async () => {+ const steps = await db.steps.where('guideId').equals(guideId).sortBy('index');+ const block: Step = {+ id,+ guideId,+ index: 0,+ description,+ action: blockType,+ url: '',+ timestamp: Date.now(),+ blockType,+ ...(blockType === 'callout' ? { calloutVariant: 'info' as const } : {}),+ };+ steps.splice(Math.max(0, Math.min(atIndex, steps.length)), 0, block);+ await db.steps.bulkPut(steps.map((step, index) => ({ ...step, index })));+ await db.guides.update(guideId, { stepIds: steps.map((step) => step.id), updatedAt: Date.now() });+ });+ return id;+}++export async function updateCallout(stepId: string, variant: CalloutVariant, color?: string): Promise<void> {+ await db.steps.update(stepId, { calloutVariant: variant, calloutColor: color });+}+export async function updateStepDescription(stepId: string, description: string): Promise<void> {await db.steps.update(stepId, { description });}diff --git a/src/core/guides/types.ts b/src/core/guides/types.tsindex c9fb392..9b18a45 100644--- a/src/core/guides/types.ts+++ b/src/core/guides/types.ts@@ -11,6 +11,10 @@ export interface Guide {deletedAt: number | null;}+export type BlockType = 'heading' | 'callout';++export type CalloutVariant = 'info' | 'warning' | 'error' | 'success' | 'custom';+export interface Step {id: string;guideId: string;@@ -23,6 +27,9 @@ export interface Step {elementMeta?: ElementMeta;inputValue?: string;aiPending?: boolean;+ blockType?: BlockType;+ calloutVariant?: CalloutVariant;+ calloutColor?: string;}export interface ScreenshotBounds {diff --git a/src/locales/de.yml b/src/locales/de.ymlindex a9cbc2a..b1f09a6 100644--- a/src/locales/de.yml+++ b/src/locales/de.yml@@ -189,6 +189,20 @@ editor:descriptionErrorSaveFailed: Die Beschreibung wurde erstellt, konnte aber nicht gespeichert werden. Versuche es erneut.writingStepDescription: "Beschreibung wird geschrieben…"+blocks:+ add: "Block hinzufügen"+ heading: "Überschrift"+ callout: Hinweis+ headingPlaceholder: Abschnittstitel+ calloutPlaceholder: Hinweis schreiben+ deleteHeading: "Diese Überschrift löschen?"+ deleteCallout: "Diesen Hinweis löschen?"+ variantInfo: Info+ variantWarning: Warnung+ variantError: Fehler+ variantSuccess: Erfolg+ variantCustom: Benutzerdefiniert+history:title: Versionsverlaufcurrent: Aktuelldiff --git a/src/locales/en.yml b/src/locales/en.ymlindex e85b1ba..c39484a 100644--- a/src/locales/en.yml+++ b/src/locales/en.yml@@ -189,6 +189,20 @@ editor:rewriteErrorFailed: Could not rewrite the selection. Try again.rewriteErrorStale: The text changed. Select it again.+blocks:+ add: Add block+ heading: Heading+ callout: Note+ headingPlaceholder: Section title+ calloutPlaceholder: Write a note+ deleteHeading: "Delete this heading?"+ deleteCallout: "Delete this note?"+ variantInfo: Info+ variantWarning: Warning+ variantError: Error+ variantSuccess: Success+ variantCustom: Custom+history:title: Version Historycurrent: Currentdiff --git a/src/locales/es.yml b/src/locales/es.ymlindex db7ce07..102055c 100644--- a/src/locales/es.yml+++ b/src/locales/es.yml@@ -189,6 +189,20 @@ editor:rewriteErrorFailed: "No se pudo reescribir la selecci\xF3n. Int\xE9ntalo de nuevo."rewriteErrorStale: "El texto cambi\xF3. Vuelve a seleccionarlo."+blocks:+ add: "Añadir bloque"+ heading: Encabezado+ callout: Nota+ headingPlaceholder: "Título de sección"+ calloutPlaceholder: Escribe una nota+ deleteHeading: "¿Eliminar este encabezado?"+ deleteCallout: "¿Eliminar esta nota?"+ variantInfo: "Información"+ variantWarning: Advertencia+ variantError: Error+ variantSuccess: "Éxito"+ variantCustom: Personalizado+history:title: Historial de versionescurrent: Actualdiff --git a/src/locales/fr.yml b/src/locales/fr.ymlindex 86ba2a6..07ff767 100644--- a/src/locales/fr.yml+++ b/src/locales/fr.yml@@ -189,6 +189,20 @@ editor:rewriteErrorFailed: "Impossible de r\xE9\xE9crire la s\xE9lection. R\xE9essayez."rewriteErrorStale: "Le texte a chang\xE9. S\xE9lectionnez-le \xE0 nouveau."+blocks:+ add: Ajouter un bloc+ heading: Titre+ callout: Note+ headingPlaceholder: "Titre de section"+ calloutPlaceholder: "Écrivez une note"+ deleteHeading: "Supprimer ce titre ?"+ deleteCallout: "Supprimer cette note ?"+ variantInfo: Information+ variantWarning: Avertissement+ variantError: Erreur+ variantSuccess: "Succès"+ variantCustom: "Personnalisé"+history:title: Historique des versionscurrent: Actuellediff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.ymlindex 031a572..df7fa98 100644--- a/src/locales/pt-BR.yml+++ b/src/locales/pt-BR.yml@@ -189,6 +189,20 @@ editor:rewriteErrorFailed: "N\xE3o foi poss\xEDvel reescrever a sele\xE7\xE3o. Tente novamente."rewriteErrorStale: O texto mudou. Selecione-o novamente.+blocks:+ add: Adicionar bloco+ heading: "Título"+ callout: Nota+ headingPlaceholder: "Título da seção"+ calloutPlaceholder: Escreva uma nota+ deleteHeading: "Excluir este título?"+ deleteCallout: "Excluir esta nota?"+ variantInfo: "Informação"+ variantWarning: Aviso+ variantError: Erro+ variantSuccess: Sucesso+ variantCustom: Personalizado+history:title: Histórico de versõescurrent: Atualdiff --git a/src/ui/shared/BlockCard.tsx b/src/ui/shared/BlockCard.tsxnew file mode 100644index 0000000..88aab1f--- /dev/null+++ b/src/ui/shared/BlockCard.tsx@@ -0,0 +1,148 @@+import { Trash2 } from 'lucide-react';+import { useEffect, useState } from 'react';+import { i18n } from '#imports';+import { CALLOUT_VARIANTS, calloutAccent, DEFAULT_CALLOUT_COLOR, tint, variantLabel } from '@/core/guides/blocks';+import { updateCallout } from '@/core/guides/service';+import type { CalloutVariant, Step } from '@/core/guides/types';+import ConfirmDialog from '@/ui/shared/ConfirmDialog';++interface DragHandleProps {+ onDragStart: (e: React.DragEvent) => void;+ onDragOver: (e: React.DragEvent) => void;+ onDragEnd: () => void;+}++interface BlockCardProps {+ step: Step;+ onDescriptionChange: (stepId: string, description: string) => void;+ onDelete: (stepId: string) => void;+ onChanged?: () => void;+ dragHandleProps?: DragHandleProps;+ readOnly?: boolean;+}++export default function BlockCard({+ step,+ onDescriptionChange,+ onDelete,+ onChanged,+ dragHandleProps,+ readOnly,+}: BlockCardProps) {+ const [description, setDescription] = useState(step.description);+ const [confirmDelete, setConfirmDelete] = useState(false);++ useEffect(() => {+ setDescription(step.description);+ }, [step.description]);++ const isHeading = step.blockType === 'heading';+ const accent = calloutAccent(step);+ const variant = step.calloutVariant ?? 'info';++ const pickVariant = async (next: CalloutVariant) => {+ await updateCallout(step.id, next, next === 'custom' ? (step.calloutColor ?? DEFAULT_CALLOUT_COLOR) : undefined);+ onChanged?.();+ };++ const pickColor = async (color: string) => {+ await updateCallout(step.id, 'custom', color);+ onChanged?.();+ };++ const textClass = isHeading+ ? 'text-[15px] font-bold leading-tight text-foreground'+ : 'text-[13px] font-medium leading-snug text-foreground';++ return (+ <div+ draggable={!!dragHandleProps}+ onDragStart={dragHandleProps?.onDragStart}+ onDragOver={(e) => {+ e.preventDefault();+ dragHandleProps?.onDragOver(e);+ }}+ onDragEnd={dragHandleProps?.onDragEnd}+ className="mb-3"+ >+ <div+ className={isHeading ? 'border-b border-foreground pb-1.5' : 'rounded-lg px-3 py-2.5 border-l-[3px]'}+ style={isHeading ? undefined : { borderLeftColor: accent, background: tint(accent) }}+ >+ {readOnly ? (+ <p className={`${textClass} whitespace-pre-wrap`}>{step.description}</p>+ ) : (+ <textarea+ className={`${textClass} w-full resize-none outline-none border-0 bg-transparent p-0`}+ value={description}+ rows={1}+ ref={(el) => {+ if (el) {+ el.style.height = '0';+ el.style.height = `${el.scrollHeight}px`;+ }+ }}+ onChange={(e) => {+ setDescription(e.target.value);+ e.target.style.height = '0';+ e.target.style.height = `${e.target.scrollHeight}px`;+ }}+ onBlur={() => {+ if (description !== step.description) onDescriptionChange(step.id, description);+ }}+ placeholder={isHeading ? i18n.t('blocks.headingPlaceholder') : i18n.t('blocks.calloutPlaceholder')}+ />+ )}+ </div>+ {!readOnly && (+ <div className="flex items-center gap-1 mt-1">+ {!isHeading &&+ CALLOUT_VARIANTS.map((option) => (+ <button+ key={option}+ type="button"+ onClick={() => pickVariant(option)}+ title={variantLabel(option)}+ aria-label={variantLabel(option)}+ aria-pressed={variant === option}+ className={`w-3.5 h-3.5 rounded-full border ${variant === option ? 'border-foreground' : 'border-border'}`}+ style={{+ background:+ option === 'custom' && variant !== 'custom'+ ? 'linear-gradient(135deg,#DC2626,#4F46E5,#059669)'+ : calloutAccent({ ...step, calloutVariant: option }),+ }}+ />+ ))}+ {!isHeading && variant === 'custom' && (+ <input+ type="color"+ value={accent}+ onChange={(e) => pickColor(e.target.value)}+ title={variantLabel('custom')}+ className="w-5 h-4 bg-transparent border-0 p-0 cursor-pointer"+ />+ )}+ <button+ type="button"+ onClick={() => setConfirmDelete(true)}+ className="ml-auto p-1 rounded-md transition-colors text-border hover:text-destructive"+ title={isHeading ? i18n.t('blocks.deleteHeading') : i18n.t('blocks.deleteCallout')}+ >+ <Trash2 size={13} />+ </button>+ </div>+ )}+ <ConfirmDialog+ open={confirmDelete}+ title={isHeading ? i18n.t('blocks.deleteHeading') : i18n.t('blocks.deleteCallout')}+ destructive+ onConfirm={() => {+ setConfirmDelete(false);+ onDelete(step.id);+ }}+ onCancel={() => setConfirmDelete(false)}+ />+ </div>+ );+}