From cabbd6f7e05e53ff86e93bfae378f6ebde725105 Mon Sep 17 00:00:00 2001 From: Victor Ilyushchenko Date: Tue, 15 Apr 2025 14:36:13 +0300 Subject: [PATCH] Minor enhancements to the text color feature (#8551) Signed-off-by: Victor Ilyushchenko --- packages/text/src/marks/colors.ts | 2 +- packages/ui/src/popups.ts | 4 +- .../src/components/extension/colors.ts | 60 +++++++++++++------ .../extension/popups/ColorPicker.svelte | 23 ++++++- 4 files changed, 66 insertions(+), 23 deletions(-) diff --git a/packages/text/src/marks/colors.ts b/packages/text/src/marks/colors.ts index d228507a2d..a29f83a49f 100644 --- a/packages/text/src/marks/colors.ts +++ b/packages/text/src/marks/colors.ts @@ -135,7 +135,7 @@ export const TextColor = Extension.create({ unsetTextColor: () => ({ chain }) => { - return chain().setMark('textStyle', { color: null }).removeEmptyTextStyle().run() + return chain().unsetMark('textStyle').run() } } } diff --git a/packages/ui/src/popups.ts b/packages/ui/src/popups.ts index a7424e003e..54bd1f2059 100644 --- a/packages/ui/src/popups.ts +++ b/packages/ui/src/popups.ts @@ -92,12 +92,13 @@ export function showPopup ( overlay: boolean fixed?: boolean refId?: string + id?: string } = { category: 'popup', overlay: true } ): PopupResult { - const id = `${popupId++}` + const id = options?.id ?? `${popupId++}` const closePopupOp = (): void => { modalStore.update((popups) => { const pos = popups.findIndex((p) => (p as CompAndProps).id === id && p.type === 'popup') @@ -107,6 +108,7 @@ export function showPopup ( return popups }) } + closePopupOp() const _element = element instanceof HTMLElement ? getPopupPositionElement(element) : element const data: Omit = { id, diff --git a/plugins/text-editor-resources/src/components/extension/colors.ts b/plugins/text-editor-resources/src/components/extension/colors.ts index cac7e5417c..ec48f1d446 100644 --- a/plugins/text-editor-resources/src/components/extension/colors.ts +++ b/plugins/text-editor-resources/src/components/extension/colors.ts @@ -50,7 +50,7 @@ const palette = { colorSpec('red', 'bg') ], text: [ - { color: 'var(--theme-text-color-primary)' }, + { color: 'var(--theme-text-primary-color)' }, colorSpec('gray'), colorSpec('brown'), colorSpec('orange'), @@ -65,33 +65,55 @@ const palette = { export async function openBackgroundColorOptions (editor: Editor, event: MouseEvent): Promise { await new Promise((resolve) => { - showPopup(ColorPicker, { palette: palette.background }, getEventPositionElement(event), (val) => { - const color: string | undefined = val?.color - if (color === undefined) return + showPopup( + ColorPicker, + { palette: palette.background, id: 'text-editor-background-color-picker' }, + getEventPositionElement(event), + (val) => { + const color: string | undefined = val?.color + if (color === undefined) return - if (color === 'transparent') { - editor.commands.unsetBackgroundColor() - } else { - editor.commands.setBackgroundColor(color) + if (color === 'transparent') { + editor.commands.unsetBackgroundColor() + } else { + editor.commands.setBackgroundColor(color) + } + resolve() + }, + undefined, + { + id: 'text-editor-background-color-picker', + category: 'popup', + overlay: true } - resolve() - }) + ) }) } export async function openTextColorOptions (editor: Editor, event: MouseEvent): Promise { await new Promise((resolve) => { - showPopup(ColorPicker, { palette: palette.text }, getEventPositionElement(event), (val) => { - const color: string | undefined = val?.color - if (color === undefined) return + showPopup( + ColorPicker, + { palette: palette.text, letters: true }, + getEventPositionElement(event), + (val) => { + const color: string | undefined = val?.color + if (color === undefined) return - if (color === 'var(--theme-text-color-primary)') { - editor.commands.unsetTextColor() - } else { - editor.commands.setTextColor(color) + if (color === 'var(--theme-text-primary-color)') { + editor.commands.unsetTextColor() + } else { + editor.commands.setTextColor(color) + } + resolve() + }, + undefined, + { + id: 'text-editor-text-color-picker', + category: 'popup', + overlay: true } - resolve() - }) + ) }) } diff --git a/plugins/text-editor-resources/src/components/extension/popups/ColorPicker.svelte b/plugins/text-editor-resources/src/components/extension/popups/ColorPicker.svelte index b199769bd2..d536c97adc 100644 --- a/plugins/text-editor-resources/src/components/extension/popups/ColorPicker.svelte +++ b/plugins/text-editor-resources/src/components/extension/popups/ColorPicker.svelte @@ -17,6 +17,7 @@ import { Card } from '@hcengineering/presentation' export let palette: Array<{ color: string, preview?: string }> = [{ color: 'transparent' }] + export let letters: boolean = false const dispatch = createEventDispatcher() @@ -32,11 +33,15 @@
{ handleSubmit(k) }} - /> + > + {#if letters}A{/if} +
{/each} @@ -61,6 +66,20 @@ height: 1.5rem; border-radius: 0.25rem; cursor: pointer; + } + + .solid { + background-color: var(--color); box-shadow: var(--text-editor-color-picker-outline) 0px 0px 0px 1px inset; } + + .letters { + display: flex; + align-items: center; + justify-content: center; + background-color: transparent; + border: 1px solid var(--color); + color: var(--color); + font-weight: bold; + }