Minor enhancements to the text color feature (#8551)
Some checks are pending
CI / test (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko 2025-04-15 14:36:13 +03:00 committed by GitHub
parent ab228b376b
commit cabbd6f7e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 23 deletions

View File

@ -135,7 +135,7 @@ export const TextColor = Extension.create<TextColorOptions>({
unsetTextColor: unsetTextColor:
() => () =>
({ chain }) => { ({ chain }) => {
return chain().setMark('textStyle', { color: null }).removeEmptyTextStyle().run() return chain().unsetMark('textStyle').run()
} }
} }
} }

View File

@ -92,12 +92,13 @@ export function showPopup (
overlay: boolean overlay: boolean
fixed?: boolean fixed?: boolean
refId?: string refId?: string
id?: string
} = { } = {
category: 'popup', category: 'popup',
overlay: true overlay: true
} }
): PopupResult { ): PopupResult {
const id = `${popupId++}` const id = options?.id ?? `${popupId++}`
const closePopupOp = (): void => { const closePopupOp = (): void => {
modalStore.update((popups) => { modalStore.update((popups) => {
const pos = popups.findIndex((p) => (p as CompAndProps).id === id && p.type === 'popup') const pos = popups.findIndex((p) => (p as CompAndProps).id === id && p.type === 'popup')
@ -107,6 +108,7 @@ export function showPopup (
return popups return popups
}) })
} }
closePopupOp()
const _element = element instanceof HTMLElement ? getPopupPositionElement(element) : element const _element = element instanceof HTMLElement ? getPopupPositionElement(element) : element
const data: Omit<CompAndProps, 'is'> = { const data: Omit<CompAndProps, 'is'> = {
id, id,

View File

@ -50,7 +50,7 @@ const palette = {
colorSpec('red', 'bg') colorSpec('red', 'bg')
], ],
text: [ text: [
{ color: 'var(--theme-text-color-primary)' }, { color: 'var(--theme-text-primary-color)' },
colorSpec('gray'), colorSpec('gray'),
colorSpec('brown'), colorSpec('brown'),
colorSpec('orange'), colorSpec('orange'),
@ -65,33 +65,55 @@ const palette = {
export async function openBackgroundColorOptions (editor: Editor, event: MouseEvent): Promise<void> { export async function openBackgroundColorOptions (editor: Editor, event: MouseEvent): Promise<void> {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
showPopup(ColorPicker, { palette: palette.background }, getEventPositionElement(event), (val) => { showPopup(
const color: string | undefined = val?.color ColorPicker,
if (color === undefined) return { 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') { if (color === 'transparent') {
editor.commands.unsetBackgroundColor() editor.commands.unsetBackgroundColor()
} else { } else {
editor.commands.setBackgroundColor(color) 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<void> { export async function openTextColorOptions (editor: Editor, event: MouseEvent): Promise<void> {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
showPopup(ColorPicker, { palette: palette.text }, getEventPositionElement(event), (val) => { showPopup(
const color: string | undefined = val?.color ColorPicker,
if (color === undefined) return { 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)') { if (color === 'var(--theme-text-primary-color)') {
editor.commands.unsetTextColor() editor.commands.unsetTextColor()
} else { } else {
editor.commands.setTextColor(color) editor.commands.setTextColor(color)
}
resolve()
},
undefined,
{
id: 'text-editor-text-color-picker',
category: 'popup',
overlay: true
} }
resolve() )
})
}) })
} }

View File

@ -17,6 +17,7 @@
import { Card } from '@hcengineering/presentation' import { Card } from '@hcengineering/presentation'
export let palette: Array<{ color: string, preview?: string }> = [{ color: 'transparent' }] export let palette: Array<{ color: string, preview?: string }> = [{ color: 'transparent' }]
export let letters: boolean = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -32,11 +33,15 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="colorBox" class="colorBox"
style:background-color={k.preview ?? k.color} class:letters
class:solid={!letters}
style:--color={k.preview ?? k.color}
on:click={() => { on:click={() => {
handleSubmit(k) handleSubmit(k)
}} }}
/> >
{#if letters}A{/if}
</div>
{/each} {/each}
</div> </div>
</div> </div>
@ -61,6 +66,20 @@
height: 1.5rem; height: 1.5rem;
border-radius: 0.25rem; border-radius: 0.25rem;
cursor: pointer; cursor: pointer;
}
.solid {
background-color: var(--color);
box-shadow: var(--text-editor-color-picker-outline) 0px 0px 0px 1px inset; 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;
}
</style> </style>