Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/assets/stylesheets/lexxy-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@
padding: 1ch;
position: relative;

&[aria-pressed="true"] {
&[aria-checked="true"] {
background-color: var(--lexxy-color-selected);

&:hover {
Expand Down Expand Up @@ -782,6 +782,10 @@
grid-template-columns: repeat(auto-fill, minmax(var(--lexxy-toolbar-button-size), 1fr));
max-inline-size: var(--max-inline-size);

.lexxy-highlight-colors__group {
display: contents;
}

button {
block-size: unset;
inline-size: 100%;
Expand All @@ -796,7 +800,7 @@
position: absolute;
}

&[aria-pressed="true"] {
&[aria-checked="true"] {
background-color: transparent;
box-shadow: 0 0 0 2px currentColor inset;

Expand Down Expand Up @@ -830,8 +834,7 @@
position: absolute;
z-index: 2;

button,
summary {
button {
align-items: center;
background: transparent;
block-size: var(--button-size);
Expand All @@ -849,7 +852,7 @@

@media(any-hover: hover) {
&:hover:not([aria-disabled="true"]),
[open] &:is(summary) {
&.lexxy-table-control__more-menu-trigger[aria-expanded="true"] {
background: var(--lexxy-color-ink-medium);

svg {
Expand Down Expand Up @@ -880,8 +883,10 @@
}
}

summary {
.lexxy-table-control__more-menu-trigger {
aspect-ratio: auto;
box-shadow: 0 0 0 1px inset rgba(128, 128, 128, 0.3);
font-weight: normal;
padding: 0 1.25ch;
}

Expand Down Expand Up @@ -909,6 +914,7 @@
white-space: nowrap;

.lexxy-table-control__more-menu {
display: flex;
gap: 0;
position: relative;

Expand All @@ -924,6 +930,10 @@
position: absolute;
transform: translateX(-50%);

&[hidden] {
display: none;
}

button {
aspect-ratio: unset;
flex-direction: row;
Expand Down
8 changes: 4 additions & 4 deletions app/assets/stylesheets/lexxy-variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@

--highlight-bg-1: rgba(229, 223, 6, 0.3);
--highlight-bg-2: rgba(255, 185, 87, 0.3);
--highlight-bg-3: rgba(255, 118, 118, 0.3);
--highlight-bg-3: rgba(255, 118, 118, 0.3);
--highlight-bg-4: rgba(248, 137, 216, 0.3);
--highlight-bg-5: rgba(190, 165, 255, 0.3);
--highlight-bg-5: rgba(190, 165, 255, 0.3);
--highlight-bg-6: rgba(124, 192, 252, 0.3);
--highlight-bg-7: rgba(140, 255, 129, 0.3);
--highlight-bg-7: rgba(140, 255, 129, 0.3);
--highlight-bg-8: rgba(221, 170, 123, 0.3);
--highlight-bg-9: rgba(200, 200, 200, 0.3);

Expand Down Expand Up @@ -84,4 +84,4 @@
--lexxy-radius: 0.5ch;
--lexxy-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
--lexxy-z-popup: 1000;
}
}
25 changes: 22 additions & 3 deletions src/config/lexxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Configuration from "./configuration"
import { range } from "../helpers/array_helper.js"

const global = new Configuration({
attachmentTagName: "action-text-attachment",
Expand All @@ -21,8 +20,28 @@ const presets = new Configuration({
headings: [ "h2", "h3", "h4" ],
highlight: {
buttons: {
color: range(1, 9).map(n => `var(--highlight-${n})`),
"background-color": range(1, 9).map(n => `var(--highlight-bg-${n})`),
color: [
{ value: "var(--highlight-1)", label: "Yellow" },
{ value: "var(--highlight-2)", label: "Orange" },
{ value: "var(--highlight-3)", label: "Red" },
{ value: "var(--highlight-4)", label: "Magenta" },
{ value: "var(--highlight-5)", label: "Purple" },
{ value: "var(--highlight-6)", label: "Blue" },
{ value: "var(--highlight-7)", label: "Green" },
{ value: "var(--highlight-8)", label: "Sand" },
{ value: "var(--highlight-9)", label: "Gray" },
],
"background-color": [
{ value: "var(--highlight-bg-1)", label: "Yellow" },
{ value: "var(--highlight-bg-2)", label: "Orange" },
{ value: "var(--highlight-bg-3)", label: "Red" },
{ value: "var(--highlight-bg-4)", label: "Magenta" },
{ value: "var(--highlight-bg-5)", label: "Purple" },
{ value: "var(--highlight-bg-6)", label: "Blue" },
{ value: "var(--highlight-bg-7)", label: "Green" },
{ value: "var(--highlight-bg-8)", label: "Sand" },
{ value: "var(--highlight-bg-9)", label: "Gray" },
],
},
permit: {
color: [],
Expand Down
6 changes: 3 additions & 3 deletions src/elements/dropdown/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class HeadingDropdown extends HTMLElement {
updateActiveHeading(tag) {
this.#headingButtons.forEach(button => {
const next = (button.dataset.heading === tag).toString()
if (button.getAttribute("aria-pressed") !== next) {
button.setAttribute("aria-pressed", next)
if (button.getAttribute("aria-checked") !== next) {
button.setAttribute("aria-checked", next)
}
})
}
Expand Down Expand Up @@ -110,7 +110,7 @@ export class HeadingDropdown extends HTMLElement {
button.classList.add("lexxy-heading-button")
button.name = name
button.title = label
button.setAttribute("role", "menuitem")
button.setAttribute("role", "menuitemradio")
button.innerHTML = `${icon} <span>${label}</span>`
return button
}
Expand Down
34 changes: 20 additions & 14 deletions src/elements/dropdown/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { $getSelectionStyleValueForProperty } from "@lexical/selection"
import { ToolbarDropdown } from "../toolbar_dropdown"
import { registerEventListener } from "../../helpers/listener_helper"
import { createElement } from "../../helpers/html_helper"
import { normalizeColorButtons } from "../../helpers/format_helper"

const APPLY_HIGHLIGHT_SELECTOR = "button.lexxy-highlight-button"
const REMOVE_HIGHLIGHT_SELECTOR = "[data-command='removeHighlight']"
Expand Down Expand Up @@ -35,27 +36,36 @@ export class HighlightDropdown extends ToolbarDropdown {

const colorGroups = this.editorElement.config.get("highlight.buttons")

this.#populateButtonGroup("color", colorGroups.color)
this.#populateButtonGroup("background-color", colorGroups["background-color"])
this.#appendColorGroup("Text color", "color", colorGroups.color)
this.#appendColorGroup("Background color", "background-color", colorGroups["background-color"])

const maxNumberOfColors = Math.max(colorGroups.color.length, colorGroups["background-color"].length)
this.panel.style.setProperty("--max-colors", maxNumberOfColors)
}

#populateButtonGroup(attribute, values) {
values.forEach((value, index) => {
this.#buttonContainer.appendChild(this.#createButton(attribute, value, index))
#appendColorGroup(label, attribute, buttons) {
const group = createElement("div", {
role: "group",
class: "lexxy-highlight-colors__group",
"aria-label": label
})

normalizeColorButtons(buttons).forEach((button, index) => {
group.appendChild(this.#createButton(attribute, button, index))
})

this.#buttonContainer.append(group)
}

#createButton(attribute, value, index) {
#createButton(attribute, button, index) {
return createElement("button", {
type: "button",
dataset: { value, style: attribute },
style: `${attribute}: ${value}`,
dataset: { value: button.value, style: attribute },
style: `${attribute}: ${button.value}`,
class: "lexxy-editor__toolbar-button lexxy-highlight-button",
name: `${attribute}-${index}`,
role: "menuitem"
role: "menuitemcheckbox",
"aria-label": button.label
Comment thread
brunoprietog marked this conversation as resolved.
})
Comment thread
brunoprietog marked this conversation as resolved.
}

Expand All @@ -79,11 +89,7 @@ export class HighlightDropdown extends ToolbarDropdown {
const backgroundColor = $getSelectionStyleValueForProperty(selection, "background-color", NO_STYLE)

this.#colorButtons.forEach(button => {
const matchesSelection = button.dataset.value === textColor || button.dataset.value === backgroundColor
const next = matchesSelection.toString()
if (button.getAttribute("aria-pressed") !== next) {
button.setAttribute("aria-pressed", next)
}
button.ariaChecked = button.dataset.value === textColor || button.dataset.value === backgroundColor
})

const hasHighlight = textColor !== NO_STYLE || backgroundColor !== NO_STYLE
Expand Down
13 changes: 7 additions & 6 deletions src/elements/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Contents from "../editor/contents"
import Clipboard from "../editor/clipboard"
import Extensions from "../editor/extensions"
import { BrowserAdapter } from "../editor/adapters/browser_adapter"
import { getHighlightStyles } from "../helpers/format_helper"
import { getHighlightStyles, normalizeColorButtons } from "../helpers/format_helper"
import { styleResolverRoot } from "../helpers/style_resolver_root"

import { CustomActionTextAttachmentNode } from "../nodes/custom_action_text_attachment_node"
Expand Down Expand Up @@ -867,21 +867,22 @@ export class LexicalEditorElement extends HTMLElement {
// — triggering at most one forced reflow. The previous implementation interleaved
// setProperty/getComputedStyle/removeProperty on the same element, forcing a style
// recalc on every iteration during editor initialization.
#resolveColors(property, cssValues) {
#resolveColors(property, buttons) {
const container = document.createElement("span")
container.style.display = "none"

const resolvers = cssValues.map(cssValue => {
const resolvers = normalizeColorButtons(buttons).map(({ value, label }) => {
const element = document.createElement("span")
element.style.setProperty(property, cssValue)
element.style.setProperty(property, value)
container.appendChild(element)
return { element, name: cssValue }
return { element, name: value, label }
})

styleResolverRoot().appendChild(container)

const resolved = resolvers.map(({ element, name }) => ({
const resolved = resolvers.map(({ element, name, label }) => ({
name,
label,
value: window.getComputedStyle(element).getPropertyValue(property)
}))

Expand Down
Loading
Loading