import { assertExists } from '@blockeditor/global/utils'; import type { EditorHost } from '@blockeditor/lit'; import { computePosition, flip, offset, shift } from '@floating-ui/dom'; import { html } from 'lit'; import { ref, type RefOrCallback } from 'lit/directives/ref.js'; import { whenHover } from '../../../../../_common/components/hover/index.js'; import { ArrowDownIcon, HighLightDuotoneIcon, TextBackgroundDuotoneIcon, TextForegroundDuotoneIcon, } from '../../../../../_common/icons/index.js'; import type { AffineTextAttributes } from '../../../../../_common/inline/presets/affine-inline-specs.js'; import type { AffineFormatBarWidget } from '../../format-bar.js'; import { backgroundConfig, foregroundConfig } from './consts.js'; enum HighlightType { Foreground, Background, } let lastUsedColor: string | null = null; let lastUsedHighlightType: HighlightType = HighlightType.Background; const updateHighlight = ( host: EditorHost, color: string | null, highlightType: HighlightType ) => { lastUsedColor = color; lastUsedHighlightType = highlightType; const payload: { styles: AffineTextAttributes; } = { styles: { color: highlightType === HighlightType.Foreground ? color : null, background: highlightType === HighlightType.Background ? color : null, }, }; host.std.command .pipe() .withHost() .try(chain => [ chain.getTextSelection().formatText(payload), chain.getBlockSelections().formatBlock(payload), chain.formatNative(payload), ]) .run(); }; const HighlightPanel = ( formatBar: AffineFormatBarWidget, containerRef?: RefOrCallback ) => { return html`