AI-native design editor. Open-source Figma alternative.
refactor(ui): add AppCopyButton and move every copy button onto it (#1701)
Danila Poyarkov2bd3f31f231b
diff --git a/changes/1701/fixed.md b/changes/1701/fixed.mdnew file mode 100644index 000000000..8914c6d70--- /dev/null+++ b/changes/1701/fixed.md@@ -0,0 +1 @@+- Initials on collaborator and account avatars stay readable on light colors: the avatar darkens the person's color just enough, as the follow frame already did.diff --git a/src/AGENTS.md b/src/AGENTS.mdindex 5dc49673d..31fbfe6d1 100644--- a/src/AGENTS.md+++ b/src/AGENTS.md@@ -101,10 +101,12 @@ The supported browser baseline lives in `src/app/shell/support/baseline.ts` and### Feedback and forms+- `AppButton` and `IconButton` set their own `data-slot`, which panel themes target (`src/theme/panel/header.ts`), so a `data-slot` passed to them never reaches the DOM; name a button for tests with `data-test-id`.- `AppAlert` (`src/components/ui/feedback/AppAlert.vue`, theme `src/theme/feedback/alert.ts`) for persistent contextual errors, warnings, recovery guidance, and informative results, with translated `heading`/`description` and an `actions` slot. Do not hand-roll alert markup or colored error paragraphs. Alerts announce changes without taking keyboard focus.- Rows under labelled columns are a TanStack Table drawn by `AppDataTable` from the table parts (`src/components/ui/table/`): each column renders its own cell, plain values through `accessor` and anything richer as a cell component through `h()`, with widths or container-width hiding in its `meta`; do not hand-roll `<ul>` rows with aligned spans or pass cells through slots. Portal lists the server pages go through `usePortalList` and `PortalTable` (`src/components/cloud-portal/console/PortalPeople.vue`).- Content that is loading shows `AppSkeleton` placeholders in its own shape, which fade in after a moment so fast answers replace nothing; a refresh keeps what was shown, and an empty state appears only once a load finished with nothing in it (`src/components/ui/table/AppTablePlaceholder.vue`, `src/components/cloud-portal/layout/PortalPageSkeleton.vue`).-- The toast service is for transient confirmations without a visible control to carry them, such as a copy from a menu or shortcut, or an action completed after its view closes. A copy button confirms in place instead: a leading copy icon that turns into a check and the label `common.copied` (`src/components/ui/input/AppCopyField.vue`). Never show a toast and an alert for the same event; partial saves and actionable failures must not disappear in a toast.+- The toast service is for transient confirmations without a visible control to carry them, such as a copy from a menu or shortcut, or an action completed after its view closes. Never show a toast and an alert for the same event; partial saves and actionable failures must not disappear in a toast.+- A copy button confirms in place, never with a toast: `AppCopyButton`, labelled or `icon`, turns its copy icon into a check and its label into the copied label. Text built when clicked is passed as a function, and the button emits `copied` and `failed`; do not hand-roll the copied state or icon swap (`src/components/ui/button/AppCopyButton.vue`).- Field validation stays inline in the shared field component with `aria-invalid`, error text before hints, and first-invalid-field focus.- Ordinary labels such as Running/Stopped remain status text or badges. Destructive confirmation belongs in the shared confirmation dialog.diff --git a/src/components/CodePanel.vue b/src/components/CodePanel.vueindex c49db4f8a..9d13aaf09 100644--- a/src/components/CodePanel.vue+++ b/src/components/CodePanel.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import { useClipboard, useDebounceFn } from '@vueuse/core'+import { useDebounceFn } from '@vueuse/core'import { tv } from 'tailwind-variants'import {computed,@@ -39,8 +39,8 @@ import { codeStyling } from '@/app/code/styling'import { starterSourceFor, type CodeSource } from '@/app/code/templates'import { useEditorStore } from '@/app/editor/active-store'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppPlaceholder from '@/components/ui/feedback/AppPlaceholder.vue'-import Tip from '@/components/ui/overlay/Tip.vue'import AppSelect from '@/components/ui/select/AppSelect.vue'import SegmentedControl from '@/components/ui/select/SegmentedControl.vue'import statusTheme from '@/theme/feedback/status'@@ -55,8 +55,6 @@ const { active = true, initialSource = 'design-jsx' } = defineProps<{const store = useEditorStore()const editorActive = computed(() => active)const { code, common } = useI18n()-const { copy, copied } = useClipboard({ copiedDuring: 2000 })-const { copy: copyReference, copied: copiedReference } = useClipboard({ copiedDuring: 2000 })const source = ref<CodeSource>(initialSource)const draft = ref('')/** The person has written in the code since it was generated for the current selection. */@@ -414,19 +412,16 @@ watch(:ui="{ root: 'shrink-0' }"@update:model-value="changeStyling"/>- <Tip v-if="source === 'design-jsx'" :label="code.copyJSXReference">- <AppButton- color="neutral"- variant="ghost"- size="xs"- shape="square"- data-test-id="code-panel-copy-ref"- @click="copyReference(JSX_REFERENCE)"- >- <icon-lucide-check v-if="copiedReference" class="size-3 text-success" />- <icon-lucide-book-open v-else class="size-3" />- </AppButton>- </Tip>+ <AppCopyButton+ v-if="source === 'design-jsx'"+ icon+ :value="JSX_REFERENCE"+ :label="code.copyJSXReference"+ :copied-label="common.copied"+ data-test-id="code-panel-copy-ref"+ >+ <template #icon><icon-lucide-book-open class="size-3" aria-hidden="true" /></template>+ </AppCopyButton></header><AppPlaceholder@@ -498,17 +493,13 @@ watch(<icon-lucide-rotate-ccw class="size-3" />{{ code.reset }}</AppButton>- <AppButton- color="neutral"- variant="ghost"+ <AppCopyButton+ :value="draft"+ :label="common.copy"+ :copied-label="common.copied"size="xs"data-test-id="code-panel-copy"- @click="copy(draft)"- >- <icon-lucide-check v-if="copied" class="size-3 text-success" />- <icon-lucide-copy v-else class="size-3" />- {{ copied ? common.copied : common.copy }}- </AppButton>+ /></div></footer></div>diff --git a/src/components/chat/ChatInput.vue b/src/components/chat/ChatInput.vueindex 0c9dbd9e1..6e2b12692 100644--- a/src/components/chat/ChatInput.vue+++ b/src/components/chat/ChatInput.vue@@ -181,7 +181,6 @@ const selectedProfileName = computed(:label="ai.mentionSelection"size="sm":disabled="disabled || !canMentionSelection"- data-slot="chat-mention-selection"@click="composer?.insert(selectionMentions())"><icon-lucide-mouse-pointer-2 class="size-4" />diff --git a/src/components/chat/ChatMessage.vue b/src/components/chat/ChatMessage.vueindex 5162d00ce..346af1a72 100644--- a/src/components/chat/ChatMessage.vue+++ b/src/components/chat/ChatMessage.vue@@ -1,5 +1,4 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { isReasoningUIPart, isTextUIPart } from 'ai'import type { UIMessage } from 'ai'import { computed, ref } from 'vue'@@ -27,6 +26,7 @@ import ChatCompactionDivider from '@/components/chat/turn/ChatCompactionDivider.import ChatMessageEditor from '@/components/chat/turn/ChatMessageEditor.vue'import ChatTurnActions from '@/components/chat/turn/ChatTurnActions.vue'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import IconButton from '@/components/ui/button/IconButton.vue'import { usageParts } from './turn/usage'@@ -88,12 +88,9 @@ const firstAssistantTextPartIndex = computed(() =>const lastAssistantTextPartIndex = computed(() =>message.parts.findLastIndex((part) => isTextUIPart(part) && part.text.length > 0))-const { copy, copied, isSupported: clipboardSupported } = useClipboard({ copiedDuring: 1500 })const ui = chatReplyTheme()/** The text the copy button sits on: the reply's first, when there is text to copy. */-const copyPartIndex = computed(() =>- assistantText.value && clipboardSupported.value ? firstAssistantTextPartIndex.value : -1-)+const copyPartIndex = computed(() => (assistantText.value ? firstAssistantTextPartIndex.value : -1))// The AI SDK updates parts in place and replaces only the message, so copy each part for// the cards' computed state to see the new values.@@ -206,16 +203,13 @@ function groupKey(group: MessagePartGroup): string {>{{ usageOnHover }}</span>- <IconButton+ <AppCopyButtonv-if="group.index === copyPartIndex"- :label="copied ? ai.responseCopied : ai.copyResponse"- size="xs"- data-slot="chat-copy-response"- @click="copy(assistantText)"- >- <icon-lucide-check v-if="copied" class="size-3 text-success" />- <icon-lucide-copy v-else class="size-3" />- </IconButton>+ icon+ :value="assistantText"+ :label="ai.copyResponse"+ :copied-label="ai.responseCopied"+ /></div></div></template>@@ -256,7 +250,6 @@ function groupKey(group: MessagePartGroup): string {v-if="canEdit":label="ai.editMessage"size="xs"- data-slot="chat-edit-message"class="absolute top-1/2 -left-7 -translate-y-1/2 opacity-0 focus-visible:opacity-100 group-hover/request:opacity-100"@click="editing = true">diff --git a/src/components/chat/tool/ChatToolChangeView.vue b/src/components/chat/tool/ChatToolChangeView.vueindex 1237d1938..1386affb0 100644--- a/src/components/chat/tool/ChatToolChangeView.vue+++ b/src/components/chat/tool/ChatToolChangeView.vue@@ -49,7 +49,6 @@ const aspectRatio = computed(() =>:active="highlight":aria-pressed="highlight":label="ai.changeHighlight"- data-slot="chat-tool-change-highlight"@click="highlight = !highlight"><icon-lucide-highlighter class="size-3.5" />diff --git a/src/components/cloud-portal/account/PortalRecoveryCodes.vue b/src/components/cloud-portal/account/PortalRecoveryCodes.vueindex 96bf63d1b..72300d3e5 100644--- a/src/components/cloud-portal/account/PortalRecoveryCodes.vue+++ b/src/components/cloud-portal/account/PortalRecoveryCodes.vue@@ -1,11 +1,11 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { ref } from 'vue'import { useCloudPortalMessages } from '@open-pencil/vue/i18n'import { downloadBlob } from '@/app/document/io/browser'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppDialogBody from '@/components/ui/dialog/AppDialogBody.vue'import AppDialogFooter from '@/components/ui/dialog/AppDialogFooter.vue'import AppDialogHeader from '@/components/ui/dialog/AppDialogHeader.vue'@@ -19,14 +19,8 @@ const { codes } = defineProps<{ codes: string[] }>()const open = defineModel<boolean>('open', { default: false })const messages = useCloudPortalMessages()-const { copy, copied } = useClipboard({ copiedDuring: 1500 })const saved = ref(false)-async function copyCodes() {- await copy(codes.join('\n'))- saved.value = true-}-function downloadCodes() {downloadBlob(new TextEncoder().encode(`${codes.join('\n')}\n`),@@ -54,13 +48,13 @@ function downloadCodes() {</AppDialogBody><AppDialogFooter :ui="{ footer: 'justify-between' }"><div class="flex items-center gap-1">- <AppButton variant="outline" @click="copyCodes">- <template #leading>- <icon-lucide-check v-if="copied" class="size-3.5" />- <icon-lucide-copy v-else class="size-3.5" />- </template>- {{ copied ? messages.copied : messages.copyCodes }}- </AppButton>+ <AppCopyButton+ :value="codes.join('\n')"+ :label="messages.copyCodes"+ :copied-label="messages.copied"+ variant="outline"+ @copied="saved = true"+ /><AppButton variant="ghost" @click="downloadCodes"><template #leading><icon-lucide-download class="size-3.5" /></template>{{ messages.downloadCodes }}diff --git a/src/components/cloud/workspace/CloudWorkspaceMembersDialog.vue b/src/components/cloud/workspace/CloudWorkspaceMembersDialog.vueindex 7a84aa829..133c5d1e6 100644--- a/src/components/cloud/workspace/CloudWorkspaceMembersDialog.vue+++ b/src/components/cloud/workspace/CloudWorkspaceMembersDialog.vue@@ -1,5 +1,4 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { computed, ref, watch } from 'vue'import type { WorkspaceMembers, WorkspaceRole } from '@open-pencil/cloud/contract'@@ -8,7 +7,7 @@ import { useCloudMessages, useCommonMessages } from '@open-pencil/vue/i18n'import { useDateFormat } from '@/app/i18n/date'import AccountAvatar from '@/components/presence/AccountAvatar.vue'import AppButton from '@/components/ui/button/AppButton.vue'-import IconButton from '@/components/ui/button/IconButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppConfirmationDialog from '@/components/ui/dialog/AppConfirmationDialog.vue'import AppDialogBody from '@/components/ui/dialog/AppDialogBody.vue'import AppDialogFooter from '@/components/ui/dialog/AppDialogFooter.vue'@@ -73,7 +72,6 @@ const emit = defineEmits<{}>()const ui = cloudWorkspace()-const { copy, copied } = useClipboard({ copiedDuring: 1500 })const t = useCloudMessages()const common = useCommonMessages()const dates = useDateFormat()@@ -265,18 +263,16 @@ function invite() {</form><div v-if="invitationLink" :class="ui.sent()"><p :class="ui.note()">{{ t.invitationSentNote }}</p>- <AppButton+ <AppCopyButtonclass="self-start"+ :value="invitationLink"+ :label="t.copyInvitationLink"+ :copied-label="common.copied"size="sm"variant="outline"- @click="copy(invitationLink)">- <template #leading>- <icon-lucide-check v-if="copied" class="size-3.5" />- <icon-lucide-link v-else class="size-3.5" />- </template>- {{ copied ? common.copied : t.copyInvitationLink }}- </AppButton>+ <template #icon><icon-lucide-link aria-hidden="true" /></template>+ </AppCopyButton></div></section>@@ -334,10 +330,16 @@ function invite() {<span :class="ui.role()">{{ roleLabels[invitation.role] }}</span><template v-if="resent?.invitationId === invitation.id"><AppBadge>{{ t.invitationResent }}</AppBadge>- <IconButton :label="t.copyInvitationLink" @click="copy(resent.link)">- <icon-lucide-check v-if="copied" class="size-3.5" />- <icon-lucide-link v-else class="size-3.5" />- </IconButton>+ <AppCopyButton+ icon+ :value="resent.link"+ :label="t.copyInvitationLink"+ :copied-label="common.copied"+ >+ <template #icon+ ><icon-lucide-link class="size-3" aria-hidden="true"+ /></template>+ </AppCopyButton></template><AppButtonv-elsediff --git a/src/components/collab-panel/ConnectedRoom.vue b/src/components/collab-panel/ConnectedRoom.vueindex d4e514b91..06779eb9c 100644--- a/src/components/collab-panel/ConnectedRoom.vue+++ b/src/components/collab-panel/ConnectedRoom.vue@@ -8,6 +8,7 @@ import { useCollabPanelContext } from '@/components/collab-panel/context'import { roomStatusText } from '@/components/collab-room/statusText'import { useRoomActions } from '@/components/collab-room/useRoomActions'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppInput from '@/components/ui/input/AppInput.vue'import roomStatusTheme from '@/theme/collaboration/room-status'@@ -38,18 +39,14 @@ const statusText = computed(() =>class="min-w-0 flex-1"@focus="selectTarget($event)"/>- <AppButton+ <AppCopyButton+ :value="collab.shareURL"+ :label="collab.messages.copyLink"+ :copied-label="collab.messages.linkCopied"color="primary"variant="solid"data-test-id="collab-copy-link"- @click="collab.copyLink"- >- <template #leading>- <icon-lucide-check v-if="collab.copied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ collab.copied ? collab.messages.linkCopied : collab.messages.copyLink }}- </AppButton>+ /></div><label for="collab-room-name-input" class="mb-1 block text-xs text-muted">diff --git a/src/components/collab-panel/context.ts b/src/components/collab-panel/context.tsindex 533d11342..5bf6cd701 100644--- a/src/components/collab-panel/context.ts+++ b/src/components/collab-panel/context.ts@@ -18,7 +18,7 @@ import { getShareURL } from '@/constants'function createCollabPanelContext() {const collab = useCollabInjected()const joinRoomFromInput = useJoinRoom()- const { copy, copied } = useClipboard({ copiedDuring: 2000 })+ const { copy } = useClipboard()const { common, collaboration } = useI18n()const notifications = useNotificationMessages()@@ -64,12 +64,6 @@ function createCollabPanelContext() {const callRows = computed(() => presenceRows.value.filter((row) => row.voice))const shareURL = computed(() => (state.value.roomId ? getShareURL(state.value.roomId) : ''))- function copyLink() {- if (!shareURL.value) return- void copy(shareURL.value)- toast.info(notifications.value.linkCopied)- }-function saveName() {const name = nameDraft.value.trim()if (name && name !== state.value.localName) collab?.setLocalName(name)@@ -116,7 +110,6 @@ function createCollabPanelContext() {return {common,messages: collaboration,- copied,joinInput,joinError,nameDraft,@@ -126,7 +119,6 @@ function createCollabPanelContext() {presenceRows,callRows,shareURL,- copyLink,saveName,share,join,diff --git a/src/components/collab-room/ActiveRoomOverlay.vue b/src/components/collab-room/ActiveRoomOverlay.vueindex 1b226ce42..8fafb02c8 100644--- a/src/components/collab-room/ActiveRoomOverlay.vue+++ b/src/components/collab-room/ActiveRoomOverlay.vue@@ -14,10 +14,9 @@ const room = useRoomActions():sender="room.sender.value":others-waiting="room.othersWaiting.value":name="room.state.value.localName"- :copied="room.copied.value"+ :link="room.shareLink.value":desktop-link="room.desktopLink.value":downloadURL="room.downloadURL.value"- @copy-link="room.copyLink"@leave="room.leave"@rename="room.rename"/>diff --git a/src/components/collab-room/RoomScreen.stories.ts b/src/components/collab-room/RoomScreen.stories.tsindex 3b11fb0e6..3a9052f1b 100644--- a/src/components/collab-room/RoomScreen.stories.ts+++ b/src/components/collab-room/RoomScreen.stories.ts@@ -10,10 +10,9 @@ type Args = {sender: string | nullothersWaiting: string[]name: string- copied: boolean+ link: stringdesktopLink: string | nulldownloadURL: string | null- onCopyLink: () => voidonLeave: () => voidonRename: (name: string) => void}@@ -27,10 +26,9 @@ const meta = {sender: null,othersWaiting: [],name: 'Teal Fox',- copied: false,+ link: 'https://app.openpencil.dev/room/abcdefghijklmnopqrstuvwxyz012345',desktopLink: null,downloadURL: null,- onCopyLink: fn(),onLeave: fn(),onRename: fn()},@@ -73,15 +71,12 @@ export const WaitingInDesktopBrowser: Story = {}}-export const LinkCopied: Story = {- args: { copied: true }-}-export const Actions: Story = {play: async ({ canvasElement, args }) => {const canvas = within(canvasElement)await userEvent.click(canvas.getByRole('button', { name: 'Copy link' }))- await expect(args.onCopyLink).toHaveBeenCalledOnce()+ // The button says so in place.+ await expect(await canvas.findByRole('button', { name: 'Copied' })).toBeVisible()await userEvent.click(canvas.getByRole('button', { name: 'Leave' }))await expect(args.onLeave).toHaveBeenCalledOnce()}diff --git a/src/components/collab-room/RoomScreen.vue b/src/components/collab-room/RoomScreen.vueindex 9eb18816c..7d8ba632c 100644--- a/src/components/collab-room/RoomScreen.vue+++ b/src/components/collab-room/RoomScreen.vue@@ -5,6 +5,7 @@ import { useCollaborationMessages } from '@open-pencil/vue/i18n'import { isFetchingRoom, type PendingRoomStatus } from '@/app/collab/room/status'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppPlaceholder from '@/components/ui/feedback/AppPlaceholder.vue'import RoomNameLine from './RoomNameLine.vue'@@ -20,7 +21,7 @@ const {sender = null,othersWaiting = [],name,- copied = false,+ link,desktopLink = null,downloadURL = null} = defineProps<{@@ -31,7 +32,8 @@ const {othersWaiting?: string[]/** The person's name in the room, generated until they set one. */name: string- copied?: boolean+ /** The room's link, which Copy link copies. */+ link: string/** An `openpencil://join` link, offered in desktop browsers. */desktopLink?: string | null/** Where to get the desktop app, offered beside `desktopLink`. */@@ -39,7 +41,6 @@ const {}>()const emit = defineEmits<{- copyLink: []leave: []rename: [name: string]}>()@@ -131,18 +132,14 @@ const progress = computed(() => {<template #action><div :class="ui.actions()"><div :class="ui.buttons()">- <AppButton+ <AppCopyButton+ :value="link"+ :label="messages.copyLink"+ :copied-label="messages.linkCopied"color="neutral"variant="outline"data-test-id="room-screen-copy-link"- @click="emit('copyLink')"- >- <template #leading>- <icon-lucide-check v-if="copied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ copied ? messages.linkCopied : messages.copyLink }}- </AppButton>+ /><AppButtoncolor="neutral"variant="ghost"diff --git a/src/components/collab-room/useRoomActions.ts b/src/components/collab-room/useRoomActions.tsindex 6c5d0c5f2..5ee13bd48 100644--- a/src/components/collab-room/useRoomActions.ts+++ b/src/components/collab-room/useRoomActions.ts@@ -1,4 +1,3 @@-import { useClipboard } from '@vueuse/core'import { computed } from 'vue'import { useViewportKind } from '@open-pencil/vue/editor/viewport-kind'@@ -6,16 +5,12 @@ import { useViewportKind } from '@open-pencil/vue/editor/viewport-kind'import { roomLinkURL } from '@/app/collab/room/links'import { showsRoomDocument, type PendingRoomStatus } from '@/app/collab/room/status'import { DEFAULT_COLLAB_STATE, useCollabInjected } from '@/app/collab/use'-import { useNotificationMessages } from '@/app/i18n/notifications'-import { toast } from '@/app/shell/ui'import { DESKTOP_DOWNLOAD_URL, getShareURL, IS_BROWSER, IS_TAURI } from '@/constants'/** What the room screens offer for the active tab's room: its link, a desktop handoff, Leave. */export function useRoomActions() {const collab = useCollabInjected()- const notifications = useNotificationMessages()const { isMobile } = useViewportKind()- const { copy, copied } = useClipboard({ copiedDuring: 2000 })const state = computed(() => collab?.state.value ?? DEFAULT_COLLAB_STATE)const leftRoom = computed(() => collab?.leftRoom.value ?? false)@@ -40,12 +35,8 @@ export function useRoomActions() {/** Offered beside the desktop link, for people without the app. */const downloadURL = computed(() => (desktopLink.value ? DESKTOP_DOWNLOAD_URL : null))- function copyLink() {- const roomId = state.value.roomId- if (!roomId) return- void copy(getShareURL(roomId))- toast.info(notifications.value.linkCopied)- }+ /** The link that invites someone into the room. */+ const shareLink = computed(() => (state.value.roomId ? getShareURL(state.value.roomId) : ''))function leave() {collab?.disconnect()@@ -66,10 +57,9 @@ export function useRoomActions() {pendingStatus,sender,othersWaiting,- copied,desktopLink,downloadURL,- copyLink,+ shareLink,leave,rename,dismissLeftRoomNotediff --git a/src/components/presence/FollowFrame.vue b/src/components/presence/FollowFrame.vueindex 419673d60..a6f5e909e 100644--- a/src/components/presence/FollowFrame.vue+++ b/src/components/presence/FollowFrame.vue@@ -3,13 +3,14 @@ import { useEventListener } from '@vueuse/core'import { tv } from 'tailwind-variants'import { computed } from 'vue'-import { colorToCSS, darkenForContrast } from '@open-pencil/scene-graph/color'import { useI18n } from '@open-pencil/vue/i18n'import type { FollowedLabel } from '@/app/presence/registry'import { isEditing } from '@/app/shell/keyboard/focus'import followFrameTheme from '@/theme/collaboration/follow-frame'+import { personFill } from './color'+const followFrame = tv(followFrameTheme)const { followed } = defineProps<{ followed: FollowedLabel }>()@@ -18,10 +19,8 @@ const emit = defineEmits<{ stop: [] }>()const { collaboration: messages } = useI18n()const ui = followFrame()-// People's colors range from pale to deep, so the frame takes theirs darkened just enough for-// the bar's white label to read at WCAG AA, keeping its hue. A peer's color can arrive with-// alpha; the bar is drawn opaque, so the contrast holds over any canvas.-const color = computed(() => colorToCSS(darkenForContrast({ ...followed.color, a: 1 })))+// The bar's white label reads on the followed person's color.+const color = computed(() => personFill(followed.color))const text = computed(() =>followed.owner? messages.value.followingAgent({ agent: followed.name, owner: followed.owner })diff --git a/src/components/presence/PersonAvatar.vue b/src/components/presence/PersonAvatar.vueindex 0b86938e1..b4831d1cd 100644--- a/src/components/presence/PersonAvatar.vue+++ b/src/components/presence/PersonAvatar.vue@@ -7,6 +7,7 @@ import { useCollaborationMessages } from '@open-pencil/vue/i18n'import { initials } from '@/app/presence/initials'+import { personFill } from './color'import type { PresenceVoice } from './rows'import { avatar, avatarStack } from './ui'@@ -41,7 +42,7 @@ const voiceState = computed(() => {<span :class="ui.person()" :data-voice="voiceState === 'none' ? undefined : voiceState"><span:class="avatar({ size, bordered: true, following, interactive, voice: voiceState })"- :style="{ background: colorToCSS(color) }"+ :style="{ background: personFill(color) }">{{ initials(name) }}</span>diff --git a/src/components/presence/PresenceList.vue b/src/components/presence/PresenceList.vueindex 99aa297f9..82fc0262c 100644--- a/src/components/presence/PresenceList.vue+++ b/src/components/presence/PresenceList.vue@@ -10,6 +10,7 @@ import type { FollowTarget } from '@/app/presence/types'import IconButton from '@/components/ui/button/IconButton.vue'import presenceListTheme from '@/theme/collaboration/presence-list'+import { personFill } from './color'import { isFollowing, type PresenceAgentRow, type PresencePersonRow } from './rows'import { avatar } from './ui'@@ -60,7 +61,7 @@ function followLabel(name: string, target: FollowTarget): string {<ul data-test-id="collab-presence-list" :class="ui.root()"><li v-for="person in rows" :key="person.clientId ?? 'self'"><div data-slot="person" :class="ui.person()">- <div :class="avatar()" :style="{ background: colorToCSS(person.color) }">+ <div :class="avatar()" :style="{ background: personFill(person.color) }">{{ initials(person.name || common.you) }}</div><span :class="ui.name()">diff --git a/src/components/presence/color.ts b/src/components/presence/color.tsnew file mode 100644index 000000000..5c5bd4a41--- /dev/null+++ b/src/components/presence/color.ts@@ -0,0 +1,16 @@+import { colorToCSS, darkenForContrast } from '@open-pencil/scene-graph/color'+import type { Color } from '@open-pencil/scene-graph/primitives'++/**+ * A person's color for white text drawn on it, such as their avatar's initials or the follow+ * frame's label. People's colors range from pale to deep, so theirs is darkened just enough for+ * the text to read at WCAG AA, keeping its hue. A peer's color can arrive with alpha; what it+ * fills is drawn opaque, so the contrast holds over anything behind it.+ */+export function personFill(color: Color): string {+ const fill = darkenForContrast({ ...color, a: 1 })+ // CSS draws whole 8-bit channels; rounding one up could take the contrast just under the+ // ratio, while rounding down only darkens it further.+ const channel = (value: number) => Math.floor(value * 255) / 255+ return colorToCSS({ r: channel(fill.r), g: channel(fill.g), b: channel(fill.b), a: 1 })+}diff --git a/src/components/properties/component-properties/behaviour/BehaviourBindingField.vue b/src/components/properties/component-properties/behaviour/BehaviourBindingField.vueindex 97471bf39..c3a4319f5 100644--- a/src/components/properties/component-properties/behaviour/BehaviourBindingField.vue+++ b/src/components/properties/component-properties/behaviour/BehaviourBindingField.vue@@ -53,7 +53,6 @@ const items = computed(() => options.map((option) => ({ value: option.id, label:<AppButtonsize="xs"class="w-full justify-start"- data-slot="action"@click="() => {close()diff --git a/src/components/settings/agents/AgentSetup.vue b/src/components/settings/agents/AgentSetup.vueindex 7108b69e8..cd1307613 100644--- a/src/components/settings/agents/AgentSetup.vue+++ b/src/components/settings/agents/AgentSetup.vue@@ -1,5 +1,4 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { tv } from 'tailwind-variants'import { computed } from 'vue'@@ -10,6 +9,7 @@ import { codingAgentGuideURL, codingAgentSetupPrompt } from '@/app/ai/agents/setimport { agentSetupView, type AgentSetupState } from '@/app/ai/agents/setup/view'import SettingsLink from '@/components/settings/layout/SettingsLink.vue'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppAlert from '@/components/ui/feedback/AppAlert.vue'import AppCopyField from '@/components/ui/input/AppCopyField.vue'import { NODE_DOWNLOAD_URL } from '@/constants'@@ -31,7 +31,6 @@ const emit = defineEmits<{const { ai, common } = useI18n()const styles = tv(theme)()const setupProblemMessage = useSetupProblemMessage()-const { copy, copied } = useClipboard({ copiedDuring: 1500 })const detected = computed(() => setup.detected)const prompt = computed(() => codingAgentSetupPrompt(agent.id))@@ -192,13 +191,13 @@ function agentState(): string {<p :class="styles.help()">{{ ai.aiSetupAgentPromptHint({ agent: agent.name }) }}</p><div :class="styles.actions()">- <AppButton size="xs" variant="outline" @click="copy(prompt)">- <template #leading>- <icon-lucide-check v-if="copied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ copied ? common.copied : ai.aiSetupAgentCopyPrompt }}- </AppButton>+ <AppCopyButton+ :value="prompt"+ :label="ai.aiSetupAgentCopyPrompt"+ :copied-label="common.copied"+ size="xs"+ variant="outline"+ /><AppButtonv-if="setup.supported"size="xs"diff --git a/src/components/settings/diagnostics/DiagnosticsSettingsPanel.vue b/src/components/settings/diagnostics/DiagnosticsSettingsPanel.vueindex f93884432..c5f9c1c1a 100644--- a/src/components/settings/diagnostics/DiagnosticsSettingsPanel.vue+++ b/src/components/settings/diagnostics/DiagnosticsSettingsPanel.vue@@ -1,5 +1,4 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { computed, ref } from 'vue'import { useI18n } from '@open-pencil/vue/i18n'@@ -20,12 +19,12 @@ import SettingsGroup from '@/components/settings/layout/SettingsGroup.vue'import SettingsRow from '@/components/settings/layout/SettingsRow.vue'import SettingsSection from '@/components/settings/layout/SettingsSection.vue'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import { AppConfirmationDialog } from '@/components/ui/dialog'import PresetNumberField from '@/components/ui/input/PresetNumberField.vue'import AppSwitch from '@/components/ui/toggle/AppSwitch.vue'const { common, diagnostics: diagnosticMessages } = useI18n()-const { copy: copyText, copied } = useClipboard({ copiedDuring: 1500 })const clearOpen = ref(false)const { diagnosticsEnabled, diagnosticsRetention } = useDiagnosticsSettings()@@ -63,12 +62,9 @@ async function clearDiagnostics() {toast.info(diagnosticMessages.value.cleared)}-async function exportDiagnostics() {- try {- await copyText(await diagnostics.export(diagnosticsEnvironment()))- } catch {- toast.error(diagnosticMessages.value.copyFailed)- }+/** The report, read when it is copied so it has every event so far. */+function diagnosticsReport(): Promise<string> {+ return diagnostics.export(diagnosticsEnvironment())}async function saveDiagnostics() {@@ -128,11 +124,15 @@ async function saveDiagnostics() {})}}</span><div class="flex flex-wrap items-center gap-1.5">- <AppButton size="xs" color="neutral" variant="ghost" @click="exportDiagnostics"- ><template #leading- ><icon-lucide-check v-if="copied" /><icon-lucide-copy v-else /></template- >{{ copied ? common.copied : diagnosticMessages.copy }}</AppButton- >+ <AppCopyButton+ :value="diagnosticsReport"+ :label="diagnosticMessages.copy"+ :copied-label="common.copied"+ size="xs"+ color="neutral"+ variant="ghost"+ @failed="toast.error(diagnosticMessages.copyFailed)"+ /><AppButton size="xs" color="neutral" variant="ghost" @click="saveDiagnostics"><template #leading><icon-lucide-download /></template>{{ diagnosticMessages.save }}</AppButtondiff --git a/src/components/settings/mcp/MCPFailureAlert.vue b/src/components/settings/mcp/MCPFailureAlert.vueindex 3a27b7254..dee53812d 100644--- a/src/components/settings/mcp/MCPFailureAlert.vue+++ b/src/components/settings/mcp/MCPFailureAlert.vue@@ -1,5 +1,4 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { compact } from 'es-toolkit/array'import { computed, ref } from 'vue'@@ -16,6 +15,7 @@ import { APP_VERSION } from '@/app/runtime/version'import { useSetupProblemMessage } from '@/components/settings/agents/problem'import SettingsLink from '@/components/settings/layout/SettingsLink.vue'import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import AppCollapsible from '@/components/ui/collapsible/AppCollapsible.vue'import AppAlert from '@/components/ui/feedback/AppAlert.vue'import AppCopyField from '@/components/ui/input/AppCopyField.vue'@@ -53,8 +53,6 @@ const restartFixes = computed(() => restartFixesMCPFailure(failure))const automation = useAutomationMessages()const { ai, common } = useI18n()const setupProblemMessage = useSetupProblemMessage()-const { copy: copyDetailsText, copied: detailsCopied } = useClipboard({ copiedDuring: 1500 })-const { copy: copyPrompt, copied: promptCopied } = useClipboard({ copiedDuring: 1500 })const detailsOpen = ref(false)/** One-click install or update first; a command and an agent prompt only where it cannot help. */@@ -130,13 +128,10 @@ const detail = computed(() =>EXPLAINED_REASONS.has(failure.code) ? null : failure.detail?.trim() || null)-async function copyDetails(): Promise<void> {- const payload = compact([- `code=${failure.code}`,- failure.detail ? `detail=${failure.detail}` : null- ]).join('\n')- await copyDetailsText(payload)-}+/** What a bug report needs: the failure's code and its detail. */+const details = computed(() =>+ compact([`code=${failure.code}`, failure.detail ? `detail=${failure.detail}` : null]).join('\n')+)</script><template>@@ -189,20 +184,16 @@ async function copyDetails(): Promise<void> {@click="emit('install')">{{ installAction }}</AppButton>- <AppButton+ <AppCopyButtonv-if="manualCommand"+ :value="mcpServerSetupPrompt(failure, manualCommand)"+ :label="automation.mcpCopyAgentPrompt"+ :copied-label="common.copied"size="xs":color="installAction ? 'neutral' : 'primary'":variant="installAction ? 'outline' : 'solid'"data-test-id="settings-mcp-copy-agent-prompt"- @click="copyPrompt(mcpServerSetupPrompt(failure, manualCommand))"- >- <template #leading>- <icon-lucide-check v-if="promptCopied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ promptCopied ? common.copied : automation.mcpCopyAgentPrompt }}- </AppButton>+ /><AppButtonv-if="restartFixes"size="xs"@@ -222,13 +213,13 @@ async function copyDetails(): Promise<void> {@click="emit('check')">{{ ai.aiSetupAgentCheckAgain }}</AppButton>- <AppButton size="xs" variant="outline" @click="copyDetails">- <template #leading>- <icon-lucide-check v-if="detailsCopied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ detailsCopied ? common.copied : automation.mcpFailureCopy }}- </AppButton>+ <AppCopyButton+ :value="details"+ :label="automation.mcpFailureCopy"+ :copied-label="common.copied"+ size="xs"+ variant="outline"+ /></template></AppAlert></template>diff --git a/src/components/ui/binding/VariablePicker.vue b/src/components/ui/binding/VariablePicker.vueindex 11be03a68..0d20363da 100644--- a/src/components/ui/binding/VariablePicker.vue+++ b/src/components/ui/binding/VariablePicker.vue@@ -134,7 +134,6 @@ defineOptions({ inheritAttrs: false })v-if="state !== 'unbound'"size="xs"class="w-full justify-start"- data-slot="action"@click="detach"><template #leading><icon-lucide-unlink class="size-3" /></template>@@ -154,13 +153,7 @@ defineOptions({ inheritAttrs: false }):class="styles.createInput"data-slot="createInput"/>- <AppButton- size="xs"- variant="soft"- :disabled="!canCreate"- data-slot="createSubmit"- type="submit"- >+ <AppButton size="xs" variant="soft" :disabled="!canCreate" type="submit">{{ createSubmitLabel }}</AppButton></form>@@ -168,7 +161,6 @@ defineOptions({ inheritAttrs: false })v-else-if="createLabel"size="xs"class="w-full justify-start"- data-slot="action"@click="startCreate"><template #leading><icon-lucide-plus class="size-3" /></template>diff --git a/src/components/ui/button/AppCopyButton.stories.ts b/src/components/ui/button/AppCopyButton.stories.tsnew file mode 100644index 000000000..1c07df31d--- /dev/null+++ b/src/components/ui/button/AppCopyButton.stories.ts@@ -0,0 +1,85 @@+import type { Meta, StoryObj } from '@storybook/vue3-vite'+import { expect, fn, userEvent, waitFor, within } from 'storybook/test'++import AppCopyButton from './AppCopyButton.vue'++type AppCopyButtonStoryArgs = {+ value: string | (() => Promise<string>)+ label: string+ copiedLabel: string+ icon: boolean+ variant: 'solid' | 'outline' | 'soft' | 'subtle' | 'ghost' | 'link'+ onCopied: () => void+ onFailed: (error: unknown) => void+}++type Story = StoryObj<AppCopyButtonStoryArgs>++const meta = {+ title: 'Design System/Actions/Copy Button',+ component: AppCopyButton,+ args: {+ value: 'npx @open-pencil/mcp',+ label: 'Copy command',+ copiedLabel: 'Copied',+ icon: false,+ variant: 'outline',+ onCopied: fn(),+ onFailed: fn()+ },+ render: (args) => ({+ components: { AppCopyButton },+ setup: () => ({ args }),+ template: '<div class="flex items-center gap-3 p-6"><AppCopyButton v-bind="args" /></div>'+ })+} satisfies Meta<AppCopyButtonStoryArgs>++export default meta++/** It says it copied in place, then goes back to its label. */+export const Labelled: Story = {+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement)+ await userEvent.click(canvas.getByRole('button', { name: 'Copy command' }))+ await expect(await canvas.findByRole('button', { name: 'Copied' })).toBeVisible()+ await expect(args.onCopied).toHaveBeenCalledOnce()+ }+}++export const Icon: Story = { args: { icon: true, label: 'Copy response' } }++/** Text built when clicked, such as an export, is read then. */+export const BuiltWhenClicked: Story = {+ args: { value: async () => 'A report read when copied', label: 'Copy report' }+}++/**+ * A failure to build the text is the owner's to report, and the button does not say it copied,+ * even right after an earlier copy that did.+ */+export const Failed: Story = {+ args: { label: 'Copy report' },+ render: (args) => ({+ components: { AppCopyButton },+ setup: () => {+ // The report can be read until it has been copied once; after that, reading it fails.+ let read = false+ const value = () =>+ read ? Promise.reject(new Error('Export failed')) : Promise.resolve('A report')+ const copied = () => {+ read = true+ args.onCopied()+ }+ return { args, value, copied }+ },+ template:+ '<div class="flex items-center gap-3 p-6"><AppCopyButton v-bind="args" :value="value" @copied="copied" /></div>'+ }),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement)+ await userEvent.click(canvas.getByRole('button', { name: 'Copy report' }))+ await userEvent.click(await canvas.findByRole('button', { name: 'Copied' }))+ await waitFor(() => expect(args.onFailed).toHaveBeenCalledOnce())+ await expect(canvas.getByRole('button', { name: 'Copy report' })).toBeVisible()+ }+}diff --git a/src/components/ui/button/AppCopyButton.vue b/src/components/ui/button/AppCopyButton.vuenew file mode 100644index 000000000..2bc26d1ac--- /dev/null+++ b/src/components/ui/button/AppCopyButton.vue@@ -0,0 +1,80 @@+<script setup lang="ts">+import { refAutoReset, useClipboard } from '@vueuse/core'++import AppButton from '@/components/ui/button/AppButton.vue'+import IconButton from '@/components/ui/button/IconButton.vue'++import type { AppButtonColor, AppButtonSize, AppButtonVariant } from './button'++/** How long a copy button says it copied. */+const COPIED_DURING = 1500++/**+ * Copies text and confirms in place for a moment: its copy icon turns into a check, and a+ * labelled button says it copied. Text built or read when clicked, such as an export, comes+ * from a function, which the clipboard waits for so Safari keeps the click's permission. The+ * button tells its owner once the text is copied, or that copying it failed.+ */+const {+ value,+ label,+ copiedLabel,+ icon = false,+ size,+ color,+ variant,+ side+} = defineProps<{+ value: string | (() => Promise<string>)+ label: string+ copiedLabel: string+ /** Only the icon, with the label as its tooltip and accessible name. */+ icon?: boolean+ /** The button's own size when left out: `sm` with a label, `xs` as an icon. */+ size?: AppButtonSize+ color?: AppButtonColor+ variant?: AppButtonVariant+ /** Where an icon button's tooltip opens. */+ side?: 'top' | 'bottom' | 'left' | 'right'+}>()+const emit = defineEmits<{ copied: []; failed: [error: unknown] }>()+defineSlots<{+ /** The icon at rest, when what is copied is not plain text, such as a link. */+ icon?(): unknown+}>()++const { copy } = useClipboard({ legacy: true })+/** Set once a copy succeeds; a later one that fails clears it, since the clipboard kept the earlier text. */+const copied = refAutoReset(false, COPIED_DURING)++async function copyValue(): Promise<void> {+ try {+ await copy(value)+ copied.value = true+ emit('copied')+ } catch (error) {+ copied.value = false+ emit('failed', error)+ }+}+</script>++<template>+ <IconButton+ v-if="icon"+ :label="copied ? copiedLabel : label"+ :size="size"+ :side="side"+ @click="copyValue"+ >+ <icon-lucide-check v-if="copied" class="size-3" aria-hidden="true" />+ <slot v-else name="icon"><icon-lucide-copy class="size-3" aria-hidden="true" /></slot>+ </IconButton>+ <AppButton v-else :size="size" :color="color" :variant="variant" @click="copyValue">+ <template #leading>+ <icon-lucide-check v-if="copied" aria-hidden="true" />+ <slot v-else name="icon"><icon-lucide-copy aria-hidden="true" /></slot>+ </template>+ {{ copied ? copiedLabel : label }}+ </AppButton>+</template>diff --git a/src/components/ui/input/AppCopyField.vue b/src/components/ui/input/AppCopyField.vueindex 507fadad1..2a41eba00 100644--- a/src/components/ui/input/AppCopyField.vue+++ b/src/components/ui/input/AppCopyField.vue@@ -1,9 +1,8 @@<script setup lang="ts">-import { useClipboard } from '@vueuse/core'import { tv, type VariantProps } from 'tailwind-variants'import { computed } from 'vue'-import AppButton from '@/components/ui/button/AppButton.vue'+import AppCopyButton from '@/components/ui/button/AppCopyButton.vue'import type { ComponentUI } from '@/components/ui/types'import theme from '@/theme/input/copy-field'@@ -25,19 +24,18 @@ const {ui?: ComponentUI<typeof theme>}>()-const { copy, copied } = useClipboard({ copiedDuring: 1500 })const cls = computed(() => copyField({ look }))</script><template><div data-slot="copy-field" :data-look="look" :class="cls.root({ class: ui?.root })"><code :class="cls.value({ class: ui?.value })">{{ value }}</code>- <AppButton size="xs" :variant="look === 'plain' ? 'link' : 'ghost'" @click="copy(value)">- <template #leading>- <icon-lucide-check v-if="copied" class="size-3" />- <icon-lucide-copy v-else class="size-3" />- </template>- {{ copied ? copiedLabel : copyLabel }}- </AppButton>+ <AppCopyButton+ :value="value"+ :label="copyLabel"+ :copied-label="copiedLabel"+ size="xs"+ :variant="look === 'plain' ? 'link' : 'ghost'"+ /></div></template>diff --git a/src/components/ui/panel/PanelDrillIn.vue b/src/components/ui/panel/PanelDrillIn.vueindex 9b14abf8b..35cfa7f2a 100644--- a/src/components/ui/panel/PanelDrillIn.vue+++ b/src/components/ui/panel/PanelDrillIn.vue@@ -55,7 +55,7 @@ function uncover(element: Element) {@mount-auto-focus="emit('openAutoFocus', $event)"><div v-if="parent" data-slot="header" :class="styles.header({ class: ui?.header })">- <AppButton variant="ghost" size="sm" data-slot="back" @click="emit('back')">+ <AppButton variant="ghost" size="sm" @click="emit('back')"><template #leading><icon-lucide-chevron-left class="size-4" /></template><span class="sr-only">{{ back }}:</span>{{ parent }}