Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Refine table cell background color menu https://github.com/siyuan-note/siyuan/issues/18489

Daniel5d48fa394187
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index d4b7368480..d3777d54b8 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -859,15 +859,4 @@ table + .protyle-action__table {
background-color: var(--b3-theme-primary);
pointer-events: none;
}
-
- &__color {
- display: inline-block;
- align-self: center;
- flex-shrink: 0;
- width: 16px;
- height: 16px;
- margin-right: 8px;
- border: 1px solid var(--b3-border-color);
- border-radius: 50%;
- }
}
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index b1cdf058e1..92ec0c0317 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -141,15 +141,31 @@ export const setTableCellStyle = (protyle: IProtyle, node: HTMLElement, cells: H
updateTransaction(protyle, node, oldHTML);
};
-export const getTableCellBackgroundMenus = (cells: HTMLTableCellElement[], onChange: (color: string) => void) => {
+export const getTableCellBackgroundMenus = (cells: HTMLTableCellElement[],
+ onChange: (color: string) => void): IMenu[] => {
const backgroundColor = getCommonTableCellStyle(cells, "background-color");
const colors = ["", ...Array.from({length: 13}, (_, index) => `var(--b3-font-background${index + 1})`)];
- return colors.map((color, index) => ({
- label: index === 0 ? window.siyuan.languages.default : `${window.siyuan.languages.colorPrimary} ${index}`,
- iconHTML: `<span class="protyle-table-control__color" style="${color ? `background-color: ${color}` : ""}"></span>`,
- checked: backgroundColor === color,
- click: () => onChange(color),
- }));
+ const colorHTML = colors.map(color => {
+ const currentClass = backgroundColor === color ? " color__square--current" : "";
+ const defaultClass = color ? "" : " ariaLabel";
+ const attributes = color ? ` style="background-color:${color}"` :
+ ` aria-label="${window.siyuan.languages.default}" data-position="3south"`;
+ return `<button type="button" data-color="${color}" class="color__square${currentClass}${defaultClass}"${attributes}></button>`;
+ }).join("");
+ return [{
+ type: "empty",
+ label: `<div class="fn__flex fn__flex-wrap" style="width: 238px">${colorHTML}</div>`,
+ bind: element => {
+ element.addEventListener("click", event => {
+ const colorTarget = (event.target as Element).closest<HTMLElement>(".color__square");
+ if (!colorTarget || !element.contains(colorTarget)) {
+ return;
+ }
+ onChange(colorTarget.dataset.color);
+ window.siyuan.menus.menu.remove();
+ });
+ },
+ }];
};
const TABLE_HANDLE_THICKNESS = 16;