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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: allow rich text controls in a shared selection toolbar (#7751)
Louis Beaumont13216302a9ac
diff --git a/packages/workflows-ui/src/rich-text.module.css b/packages/workflows-ui/src/rich-text.module.cssindex a2229648e..bcbfb7b24 100644--- a/packages/workflows-ui/src/rich-text.module.css+++ b/packages/workflows-ui/src/rich-text.module.css@@ -85,14 +85,16 @@.expand:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }.error { font-size: 12px; color: #b42318; }.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 0 0 12px; padding: 4px 0; border-bottom: 1px solid var(--line, #ddd); }-.root .toolbar button { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }-.root .toolbar button[aria-pressed="true"], .root .toolbar button:hover { background: color-mix(in srgb, currentColor 7%, transparent); }-.root .toolbar button:disabled { opacity: .3; cursor: default; }-.root .toolbar button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }+.toolbar button { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }+.toolbar button[aria-pressed="true"], .toolbar button:hover { background: color-mix(in srgb, currentColor 7%, transparent); }+.toolbar button:disabled { opacity: .3; cursor: default; }+.toolbar button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }@media print { .toolbar { display: none; } }-.root .toolbar button svg { flex-shrink: 0; }+.toolbar button svg { flex-shrink: 0; }.image { display: inline-flex; flex-direction: column; gap: 8px; max-width: 100%; margin: 16px 0; }.image img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line, #deded5); border-radius: 8px; }.image button { align-self: flex-start; font: inherit; font-size: 12px; }++.embeddedToolbar { margin: 0; padding: 0; border: 0; }diff --git a/packages/workflows-ui/src/rich-text.tsx b/packages/workflows-ui/src/rich-text.tsxindex af3c9b365..15d3bd180 100644--- a/packages/workflows-ui/src/rich-text.tsx+++ b/packages/workflows-ui/src/rich-text.tsx@@ -5,6 +5,7 @@"use client";import { useEffect, useId, useRef, useState } from "react";+import { createPortal } from "react-dom";import { Slice } from "prosemirror-model";import { EditorState, TextSelection } from "prosemirror-state";import { EditorView } from "prosemirror-view";@@ -31,6 +32,7 @@ export function WorkflowRichText({className = "",fullDocument = false,imageUrl,+ toolbarHost,}: {value: string;onChange?: (value: string) => void;@@ -40,8 +42,11 @@ export function WorkflowRichText({className?: string;fullDocument?: boolean;imageUrl?: (src: string) => string | null;+ /** Undefined keeps the inline toolbar; null suppresses it until a shared host is ready. */+ toolbarHost?: HTMLElement | null;}) {const host = useRef<HTMLDivElement>(null);+ const toolbarRef = useRef<HTMLDivElement>(null);const view = useRef<EditorView>();const current = useRef({ value, onChange, maxLength, imageUrl });current.current = { value, onChange, maxLength, imageUrl };@@ -235,24 +240,25 @@ export function WorkflowRichText({{ label: "Undo", icon: Undo2, command: undo },{ label: "Redo", icon: Redo2, command: redo },] : [];+ const toolbar = editable && fullDocument && focusWithin && hasTextSelection ? <div ref={toolbarRef} className={`${styles.toolbar} ${toolbarHost ? styles.embeddedToolbar : ""}`} role={toolbarHost ? "group" : "toolbar"} aria-label={`${label} formatting`}>+ {controls.map(control => <button key={control.label} type="button" aria-label={control.label} title={control.label} aria-pressed={control.active}+ disabled={!view.current || !control.command(view.current.state)}+ onMouseDown={event => event.preventDefault()}+ onClick={() => { const editor = view.current; if (editor) { control.command(editor.state, editor.dispatch, editor); editor.focus(); } }}>+ <control.icon size={15} />+ </button>)}+ </div> : null;return (<divclassName={`${styles.root} ${className}`}data-testid="procedure-markdown"onFocusCapture={() => setFocusWithin(true)}onBlurCapture={event => {- if (!event.currentTarget.contains(event.relatedTarget as Node | null))+ if (!event.currentTarget.contains(event.relatedTarget as Node | null) && !toolbarRef.current?.contains(event.relatedTarget as Node | null))setFocusWithin(false);}}>- {editable && fullDocument && focusWithin && hasTextSelection && <div className={styles.toolbar} role="toolbar" aria-label={`${label} formatting`}>- {controls.map(control => <button key={control.label} type="button" aria-label={control.label} title={control.label} aria-pressed={control.active}- disabled={!view.current || !control.command(view.current.state)}- onMouseDown={event => event.preventDefault()}- onClick={() => { const editor = view.current; if (editor) { control.command(editor.state, editor.dispatch, editor); editor.focus(); } }}>- <control.icon size={15} />- </button>)}- </div>}+ {toolbarHost === undefined ? toolbar : toolbarHost && toolbar ? createPortal(toolbar, toolbarHost) : null}<divid={id}className={!fullDocument && long && !expanded ? styles.collapsed : undefined}