Skip to content

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

:lipstick: Open color settings directly from stacked buttons https://github.com/siyuan-note/siyuan/issues/20530

Danielf5524086e45a
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
index 5f26b931f4..f6dadb2c0e 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
@@ -8,7 +8,7 @@
"title": "Formatting elements",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091509-sg4pt12",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -839,12 +839,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015131447-lgzshyq",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Use "
+ "Data": "Under "
},
{
"Type": "NodeTextMark",
@@ -880,7 +880,7 @@
},
{
"Type": "NodeText",
- "Data": " to choose a color type and manage combined colors, font colors, and background colors."
+ "Data": ", click the corresponding button to manage combined colors, font colors, or background colors."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
index 4d62e710a3..db157b7e93 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210604182832-nm3hapx",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -850,7 +850,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015131447-dbilful",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -891,7 +891,7 @@
},
{
"Type": "NodeText",
- "Data": " 中选择颜色类型,管理颜色、文字颜色和背景颜色。"
+ "Data": " 中点击对应按钮,分别管理颜色、文字颜色和背景颜色。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
index c066d98519..d9035d3a78 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122008-i45akvs",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -846,7 +846,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015131447-7b390sx",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -887,7 +887,7 @@
},
{
"Type": "NodeText",
- "Data": " 中選擇顏色類型,管理顏色、文字顏色和背景顏色。"
+ "Data": " 中點選對應按鈕,分別管理顏色、文字顏色和背景顏色。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
index adc6de6857..913f999e34 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
@@ -9,7 +9,7 @@
"title": "書式要素",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -19,7 +19,7 @@
"Properties": {
"ID": "20240530101000-tfcp9du",
"id": "20240530101000-e1tndfu",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -918,7 +918,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015131447-v0xgm0w",
- "updated": "20261015131447"
+ "updated": "20261016011750"
},
"Children": [
{
@@ -955,7 +955,7 @@
},
{
"Type": "NodeText",
- "Data": " で色の種類を選び、文字色と背景色の組み合わせ、文字色、背景色を管理できます。"
+ "Data": " の各ボタンから、文字色と背景色の組み合わせ、文字色、背景色の管理画面を直接開けます。"
}
]
},
diff --git a/app/src/config/tabs/appearanceTab.test.ts b/app/src/config/tabs/appearanceTab.test.ts
index 60372699c2..5c7b2d55fe 100644
--- a/app/src/config/tabs/appearanceTab.test.ts
+++ b/app/src/config/tabs/appearanceTab.test.ts
@@ -4,6 +4,7 @@ import {resolve} from "node:path";
import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
+import {genStackHtml} from "../render/render";
const {loadMenuToggle} = require("../../../tests/menu-toggle-fixture.cjs");
const {parse} = require("ifdef-loader/preprocessor");
@@ -21,9 +22,6 @@ for (const mobile of [true, false]) {
},
};
const openedColors: string[] = [];
- const colorMenuItems: Array<{label: string; click: () => void}> = [];
- let menuTarget: unknown;
- let menuPosition: unknown;
const windowContext = {siyuan: {
languages: new Proxy({}, {get: (_, key) => String(key)}),
config: {langs: [] as unknown[], readonly: false},
@@ -40,31 +38,18 @@ for (const mobile of [true, false]) {
} : name === "../entryVisibility/ui" ? toolbarSettings :
name === "../../protyle/toolbar/inlineStyleDialog" ? {
openInlineStyleDialog: (type: string) => openedColors.push(type),
- } : name === "../../menus/menuToggle" ? {toggleMenu: (options: {
- target: unknown;
- build: (menu: unknown, session: {show: (render: () => void) => void}) => void;
- }) => {
- menuTarget = options.target;
- options.build(undefined, {show: render => render()});
- }} : name === "../../plugin/Menu" ? {Menu: class {
- addItem(item: typeof colorMenuItems[number]) { colorMenuItems.push(item); }
- open(position: unknown) { menuPosition = position; }
- }} :
+ } : name === "../render/render" ? {genStackHtml} :
new Proxy({}, {get: () => () => ({})}),
});
const groups: string[] = [];
- const slots: Array<{key: string; html: () => string; afterMount: () => void}> = [];
+ const slots: Array<{key: string; keywords: string[]; html: () => string; afterMount: (root?: unknown) => void}> = [];
const switches: Array<{id: string; spec: {title: string; readConfig?: () => boolean; save?: unknown}}> = [];
- const buttons: Array<{id: string; title: string; keywords: string[];
- afterMount: (root: unknown) => void}> = [];
const group = new Proxy({}, {
get: (_, method) => (...args: unknown[]) => {
if (method === "slot") {
slots.push(args[0] as typeof slots[number]);
} else if (method === "switch") {
switches.push({id: args[0] as string, spec: args[1] as typeof switches[number]["spec"]});
- } else if (method === "button") {
- buttons.push(args[0] as typeof buttons[number]);
}
},
});
@@ -87,32 +72,32 @@ for (const mobile of [true, false]) {
assert.equal(typeof pageScrollSwitch.spec.readConfig, "function");
assert.equal(typeof pageScrollSwitch.spec.save, "function");
assert.equal(switches.some(item => item.id === "compactMode"), !mobile);
- const colors = buttons.find(item => item.id === "manageColors");
+ const colors = slots.find(item => item.key === "manageColors");
assert.ok(colors);
- assert.equal(colors.title, "manageColors");
- assert.equal(colors.keywords.join(","), "color,colorFont,colorPrimary");
- let clickColors: (event: {stopPropagation: () => void}) => void;
- const button = {
- disabled: true,
- addEventListener: (_name: string, listener: typeof clickColors) => { clickColors = listener; },
- getBoundingClientRect: () => ({left: 100, bottom: 200, height: 28}),
- };
- const root = {querySelector: (selector: string) => selector === "#manageColors" ? button : undefined};
+ assert.equal(colors.keywords.join(","), "manageColors,color,colorFont,colorPrimary");
+ const html = colors.html();
+ assert.equal((html.match(/<button /g) || []).length, 3);
+ assert.equal((html.match(/xlink:href="#iconSettings"/g) || []).length, 3);
+ const buttons = new Map(["style1", "color", "backgroundColor"].map(type => {
+ const selector = `#manageColors-${type}`;
+ assert.ok(html.includes(`id="${selector.slice(1)}"`));
+ return [selector, {disabled: true, click: () => {},
+ addEventListener(_name: string, listener: () => void) { this.click = listener; }}] as const;
+ }));
+ const root = {querySelector: (selector: string) => buttons.get(selector)};
colors.afterMount(root);
- assert.equal(button.disabled, false);
- clickColors({stopPropagation() {}});
- assert.equal(menuTarget, button);
- assert.equal(colorMenuItems.map(item => item.label).join(","), "color,colorFont,colorPrimary");
- colorMenuItems.forEach(item => item.click());
+ buttons.forEach(button => {
+ assert.equal(button.disabled, false);
+ button.click();
+ });
assert.deepEqual(openedColors, ["style1", "color", "backgroundColor"]);
- assert.equal((menuPosition as {target: unknown}).target, button);
windowContext.siyuan.config.readonly = true;
colors.afterMount(root);
- assert.equal(button.disabled, true);
+ buttons.forEach(button => assert.equal(button.disabled, true));
windowContext.siyuan.config.readonly = false;
windowContext.siyuan.isPublish = true;
colors.afterMount(root);
- assert.equal(button.disabled, true);
+ buttons.forEach(button => assert.equal(button.disabled, true));
});
}
diff --git a/app/src/config/tabs/appearanceTab.ts b/app/src/config/tabs/appearanceTab.ts
index 0130c085f9..6c3508346a 100644
--- a/app/src/config/tabs/appearanceTab.ts
+++ b/app/src/config/tabs/appearanceTab.ts
@@ -139,34 +139,26 @@ const registerAppearanceContentGroup = (tab: SettingTabBuilder) => {
setEditorFontSize(value as number);
},
});
- group.button({
- id: "manageColors",
- title: window.siyuan.languages.manageColors,
- label: window.siyuan.languages.config,
- icon: "iconSettings",
- keywords: [window.siyuan.languages.color, window.siyuan.languages.colorFont, window.siyuan.languages.colorPrimary],
+ const colorOptions: {type: TInlineStyleType; label: string}[] = [
+ {type: "style1", label: window.siyuan.languages.color},
+ {type: "color", label: window.siyuan.languages.colorFont},
+ {type: "backgroundColor", label: window.siyuan.languages.colorPrimary},
+ ];
+ group.slot({
+ key: "manageColors",
+ keywords: [window.siyuan.languages.manageColors, ...colorOptions.map(option => option.label)],
+ html: () => genStackHtml(colorOptions.map((option, index) => ({
+ left: {
+ kind: index === 0 ? "title" : "desc",
+ text: index === 0 ? window.siyuan.languages.manageColors : "",
+ },
+ right: {kind: "button", id: `manageColors-${option.type}`, label: option.label, icon: "iconSettings"},
+ }))),
afterMount: (root) => {
- const button = root.querySelector<HTMLButtonElement>("#manageColors");
- button.disabled = window.siyuan.config.readonly || window.siyuan.isPublish;
- button.addEventListener("click", (event) => {
- event.stopPropagation();
- toggleMenu({
- target: button,
- build: (_menu, session) => {
- const menu = new Menu();
- const options: {type: TInlineStyleType; label: string}[] = [
- {type: "style1", label: window.siyuan.languages.color},
- {type: "color", label: window.siyuan.languages.colorFont},
- {type: "backgroundColor", label: window.siyuan.languages.colorPrimary},
- ];
- options.forEach(({type, label}) => menu.addItem({
- label,
- click: () => { openInlineStyleDialog(type); },
- }));
- const rect = button.getBoundingClientRect();
- session.show(() => menu.open({x: rect.left, y: rect.bottom, h: rect.height, target: button}));
- },
- });
+ colorOptions.forEach(({type}) => {
+ const button = root.querySelector<HTMLButtonElement>(`#manageColors-${type}`);
+ button.disabled = window.siyuan.config.readonly || window.siyuan.isPublish;
+ button.addEventListener("click", () => { openInlineStyleDialog(type); });
});
},
});