An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve table header controls and styling https://github.com/siyuan-note/siyuan/issues/18503
Daniel01bdc9e72141
diff --git a/app/src/assets/scss/component/_typography.scss b/app/src/assets/scss/component/_typography.scssindex 671c9e8a56..8988e2b29d 100644--- a/app/src/assets/scss/component/_typography.scss+++ b/app/src/assets/scss/component/_typography.scss@@ -350,10 +350,6 @@border-bottom-right-radius: 0;}- tr:nth-child(even) td {- background-color: var(--b3-table-even-background);- }-td,th {padding: 4px 8px;@@ -385,9 +381,15 @@font-weight: normal;}+ [data-type="NodeTable"]:not([custom-table-header-row="false"]) thead th,+ [data-type="NodeTable"]:not([custom-table-header-row="false"]) thead td {+ background-color: var(--b3-table-even-background);+ }+[data-type="NodeTable"][custom-table-header-column="true"] tr > th:first-child,[data-type="NodeTable"][custom-table-header-column="true"] tr > td:first-child {font-weight: 600;+ background-color: var(--b3-table-even-background);}code:not(.hljs),diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex 123d18e865..c84d99bb54 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -15,11 +15,13 @@ import {insertColumn,insertRow,insertRowAbove,+ isTableHeaderEnabled,moveColumnToLeft,moveColumnToRight,moveRowToDown,moveRowToUp,setTableAlign,+ toggleTableHeader,updateTableTitle} from "../protyle/util/table";import {mathRender} from "../protyle/render/mathRender";@@ -2274,30 +2276,14 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:otherMenus.push({id: "tableHeaderRow",label: window.siyuan.languages.tableHeaderRow,- checked: nodeElement.getAttribute("custom-table-header-row") !== "false",- click: () => {- const html = nodeElement.outerHTML;- if (nodeElement.getAttribute("custom-table-header-row") === "false") {- nodeElement.removeAttribute("custom-table-header-row");- } else {- nodeElement.setAttribute("custom-table-header-row", "false");- }- updateTransaction(protyle, nodeElement, html);- }+ checked: isTableHeaderEnabled(nodeElement, "row"),+ click: () => toggleTableHeader(protyle, nodeElement, "row")});otherMenus.push({id: "tableHeaderColumn",label: window.siyuan.languages.tableHeaderColumn,- checked: nodeElement.getAttribute("custom-table-header-column") === "true",- click: () => {- const html = nodeElement.outerHTML;- if (nodeElement.getAttribute("custom-table-header-column") === "true") {- nodeElement.removeAttribute("custom-table-header-column");- } else {- nodeElement.setAttribute("custom-table-header-column", "true");- }- updateTransaction(protyle, nodeElement, html);- }+ checked: isTableHeaderEnabled(nodeElement, "column"),+ click: () => toggleTableHeader(protyle, nodeElement, "column")});otherMenus.push({icon: "iconHeadings",diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.tsindex 45c66cb1c6..6a43358f96 100644--- a/app/src/protyle/util/table.ts+++ b/app/src/protyle/util/table.ts@@ -41,6 +41,28 @@ export const getColIndex = (cellElement: HTMLElement) => {return index;};+export const isTableHeaderEnabled = (nodeElement: Element, type: "row" | "column") => {+ return type === "row" ? nodeElement.getAttribute("custom-table-header-row") !== "false" :+ nodeElement.getAttribute("custom-table-header-column") === "true";+};++export const toggleTableHeader = (protyle: IProtyle, nodeElement: Element, type: "row" | "column") => {+ const html = nodeElement.outerHTML;+ const attribute = `custom-table-header-${type}`;+ if (isTableHeaderEnabled(nodeElement, type)) {+ if (type === "row") {+ nodeElement.setAttribute(attribute, "false");+ } else {+ nodeElement.removeAttribute(attribute);+ }+ } else if (type === "row") {+ nodeElement.removeAttribute(attribute);+ } else {+ nodeElement.setAttribute(attribute, "true");+ }+ updateTransaction(protyle, nodeElement, html);+};+// 光标设置到前一个表格中const goPreviousCell = (cellElement: HTMLElement, range: Range, isSelected = true) => {let previousElement = cellElement.previousElementSibling;diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.tsindex 319a8c790d..520e6ab9e0 100644--- a/app/src/protyle/util/tableControl.ts+++ b/app/src/protyle/util/tableControl.ts@@ -11,8 +11,10 @@ import {getTableFullColumnSelection,getTableFullRowSelection,getTableRangeHTML,+ isTableHeaderEnabled,ITableCellInfo,ITableGrid,+ toggleTableHeader,} from "./table";import {constrainTableResizeCount,@@ -1204,6 +1206,16 @@ export class TableControl {actionLabel: merged ? window.siyuan.languages.splitMergedCellTip : undefined,click: () => this.duplicateRowsOrColumns(),}).element);+ if (this.selection.indexes.size === 1 && this.selection.indexes.has(0)) {+ const headerType = this.selection.mode === "row" ? "row" : "column";+ menu.append(new MenuItem({+ id: headerType === "row" ? "tableHeaderRow" : "tableHeaderColumn",+ label: headerType === "row" ? window.siyuan.languages.tableHeaderRow :+ window.siyuan.languages.tableHeaderColumn,+ checked: isTableHeaderEnabled(this.selection.node, headerType),+ click: () => toggleTableHeader(this.protyle, this.selection.node, headerType),+ }).element);+ }menu.append(new MenuItem({type: "separator"}).element);}menu.append(new MenuItem({