Repository navigation
improvement(editor): refine previews and compact formatting controls #8860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
542fb1b
improvement(editor): refine previews and compact formatting controls
waleedlatif1 516fb13
fix(editor): retain focus after choosing a format
waleedlatif1 a9cfa2f
fix(emcn): centralize neutral chip keyboard focus
waleedlatif1 f7adb15
fix(emcn): preserve selected segment focus surfaces
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 8 additions & 3 deletions
11
...orkspaceId]/files/components/file-viewer/rich-markdown-editor/menus/bubble-menu-chrome.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| /** Shared floating toolbar chrome for text, table, and image selections. */ | ||
| export const BUBBLE_MENU_CLASS = | ||
| 'scrollbar-none fade-in-0 z-[var(--z-popover)] flex max-w-[calc(100%_-_1rem)] animate-in items-center gap-0.5 overflow-x-auto rounded-lg border border-[var(--border)] bg-[var(--bg)] p-1 shadow-xs duration-150 ease-out motion-reduce:animate-none' | ||
| import { cn, MENU_STYLES } from '@sim/emcn' | ||
|
|
||
| /** Shared floating toolbar chrome for text and table selections. */ | ||
| export const BUBBLE_MENU_CLASS = cn( | ||
| MENU_STYLES.surface, | ||
| MENU_STYLES.padding, | ||
| 'scrollbar-none fade-in-0 z-[var(--z-popover)] flex max-w-[calc(100%_-_1rem)] animate-in items-center gap-0.5 overflow-x-auto duration-150 ease-out motion-reduce:animate-none' | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ce/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus/toolbar-menu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import type { ComponentType, SVGProps } from 'react' | ||
| import { | ||
| Button, | ||
| Chip, | ||
| cn, | ||
| DropdownMenu, | ||
| DropdownMenuContent, | ||
| DropdownMenuItem, | ||
| DropdownMenuItemLabel, | ||
| DropdownMenuShortcut, | ||
| DropdownMenuTrigger, | ||
| Tooltip, | ||
| } from '@sim/emcn' | ||
| import { Check, ChevronDown, MoreHorizontal } from '@sim/emcn/icons' | ||
| import type { Editor } from '@tiptap/react' | ||
|
|
||
| interface ToolbarMenuProps { | ||
| editor: Editor | ||
| label: string | ||
| value?: string | ||
| active?: boolean | ||
| items: { | ||
| label: string | ||
| icon: ComponentType<SVGProps<SVGSVGElement>> | ||
| shortcut?: string | ||
| active: boolean | ||
| disabled?: boolean | ||
| onSelect: () => void | ||
| }[] | ||
| } | ||
|
|
||
| /** | ||
| * Formatting commands share the platform menu while retaining the editor's selection. | ||
| * Focusing the trigger before its portal opens keeps TipTap's blur handler inside the toolbar. | ||
| */ | ||
| export function ToolbarMenu({ editor, label, value, active, items }: ToolbarMenuProps) { | ||
| if (!editor.isEditable) return null | ||
|
|
||
| return ( | ||
| <DropdownMenu modal={false}> | ||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <DropdownMenuTrigger asChild> | ||
| {value ? ( | ||
| <Chip | ||
| rightIcon={ChevronDown} | ||
| aria-label={label} | ||
| className='h-10 w-[76px] sm:h-[28px]' | ||
| onPointerDown={(event) => event.currentTarget.focus()} | ||
| > | ||
| {value} | ||
| </Chip> | ||
| ) : ( | ||
| <Button | ||
| type='button' | ||
| variant={active ? 'active' : 'ghost'} | ||
| size='icon' | ||
| aria-label={label} | ||
| className={cn( | ||
| 'size-10 focus-visible:bg-[var(--surface-hover)] sm:size-[28px]', | ||
| !active && 'hover-hover:bg-[var(--surface-hover)]' | ||
| )} | ||
| onPointerDown={(event) => event.currentTarget.focus()} | ||
| > | ||
| <MoreHorizontal className='size-[14px]' /> | ||
| </Button> | ||
| )} | ||
| </DropdownMenuTrigger> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content>{label}</Tooltip.Content> | ||
| </Tooltip.Root> | ||
| <DropdownMenuContent | ||
| align='start' | ||
| className='w-[220px]' | ||
| onCloseAutoFocus={(event) => { | ||
| if (editor.isFocused) event.preventDefault() | ||
| }} | ||
| onKeyDown={(event) => event.stopPropagation()} | ||
| > | ||
| {items.map(({ label: itemLabel, icon: Icon, shortcut, active, disabled, onSelect }) => ( | ||
| <DropdownMenuItem | ||
| key={itemLabel} | ||
| role='menuitemcheckbox' | ||
| aria-checked={active} | ||
| active={active} | ||
| disabled={disabled} | ||
| onSelect={() => { | ||
| if (!editor.isDestroyed && editor.isEditable) onSelect() | ||
| }} | ||
| > | ||
| <Icon className='size-[14px]' /> | ||
| <DropdownMenuItemLabel label={itemLabel} /> | ||
| {shortcut && <DropdownMenuShortcut>{shortcut}</DropdownMenuShortcut>} | ||
| {active && <Check className='size-[14px]' />} | ||
| </DropdownMenuItem> | ||
| ))} | ||
| </DropdownMenuContent> | ||
| </DropdownMenu> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.