Skip to content

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

:bug: Refresh pinned document icon tooltips and align API contracts https://github.com/siyuan-note/siyuan/pull/20178

Daniel8e625c1f2058
diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts
index 846b3c78d5..7192641c48 100644
--- a/app/src/layout/dock/Files.ts
+++ b/app/src/layout/dock/Files.ts
@@ -1355,6 +1355,7 @@ export class Files extends Model {
}
public updateDocActions() {
+ this.pinnedDocs?.updateDocActions();
this.element.querySelectorAll<HTMLElement>(
'li[data-type="navigation-file"], li[data-type="navigation-root"]'
).forEach((item) => {
diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.ts
index 754d45d934..5498030486 100644
--- a/app/src/layout/dock/PinnedDocs.test.ts
+++ b/app/src/layout/dock/PinnedDocs.test.ts
@@ -14,6 +14,7 @@ interface IPanelHarness {
heading: unknown;
sourceTree: unknown;
clearSelection(): void;
+ updateDocActions(): void;
refresh(dirtyChildren?: Set<string>): Promise<void>;
onFileTreeMessage(data: {cmd: string, data?: {id: string}}): void;
collapse(): void;
@@ -221,6 +222,63 @@ test("pinned icons respect editing, expansion and readonly settings", () => {
assert.equal(calls[2].kind, "open");
});
+test("document action updates refresh existing pinned icons without reloading their documents", () => {
+ const {panel, config, runtime, calls} = loadPanel();
+ Object.assign(runtime.languages, {changeIcon: "Change icon", docIconClickExpand: "Expand children", openDocument: "Open"});
+ const makeRow = (count: number) => {
+ const attributes = new Map<string, string>();
+ const classes = new Set<string>();
+ const icon = {
+ classList: {toggle: (name: string, enabled: boolean) => {
+ if (enabled) { classes.add(name); } else { classes.delete(name); }
+ }},
+ setAttribute: (name: string, value: string) => attributes.set(name, value),
+ removeAttribute: (name: string) => attributes.delete(name),
+ };
+ return {dataset: {count: String(count)}, querySelector: () => icon, attributes, classes};
+ };
+ const rows = [makeRow(2), makeRow(0)];
+ panel.list = {querySelectorAll: () => rows};
+ panel.expanded = new Set(["parent"]);
+ const file = "Files.ts";
+ const source = ts.createSourceFile(file, readFileSync(join(__dirname, file), "utf8"), ts.ScriptTarget.Latest, true);
+ let method: ts.MethodDeclaration;
+ const visit = (node: ts.Node) => {
+ if (ts.isMethodDeclaration(node) && node.name.getText(source) === "updateDocActions") { method = node; }
+ ts.forEachChild(node, visit);
+ };
+ visit(source);
+ assert.ok(method?.body);
+ const exports = {} as {update: () => void};
+ runInNewContext(ts.transpileModule(`exports.update = function() ${method.body.getText(source)};`, {
+ compilerOptions: {target: ts.ScriptTarget.ES2020},
+ }).outputText, {exports});
+ const regularRow = {};
+ const regularUpdates: unknown[] = [];
+ const files = {pinnedDocs: panel, element: {querySelectorAll: () => [regularRow]},
+ updateDocActionElement: (row: unknown) => regularUpdates.push(row)};
+ for (const mode of [1, 0, 1]) {
+ config.fileTree.docIconClickMode = mode;
+ exports.update.call(files);
+ rows.forEach(row => {
+ assert.equal(row.classes.has("ariaLabel"), mode === 0);
+ assert.equal(row.attributes.get("aria-label"), mode === 0 ? "Change icon" : undefined);
+ });
+ }
+ assert.equal(regularUpdates.length, 3);
+ assert.equal(regularUpdates[0], regularRow);
+ assert.deepEqual([...panel.expanded], ["parent"]);
+ assert.equal(calls.length, 0);
+ panel.mobile = true;
+ for (const mode of [0, 1]) {
+ config.fileTree.docIconClickMode = mode;
+ panel.updateDocActions();
+ assert.equal(rows[0].attributes.get("aria-label"), "Expand children");
+ assert.equal(rows[1].attributes.get("aria-label"), "Open");
+ assert.equal(rows.every(row => row.classes.has("ariaLabel")), true);
+ }
+});
+
test("root drops create an entry without invoking source movement", async () => {
const {panel, calls} = loadPanel();
panel.previewDrop = () => { panel.dropTarget = {id: "parent", position: "pin-before"}; return true; };
diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.ts
index 489a9d8eb2..f53b14180f 100644
--- a/app/src/layout/dock/PinnedDocs.ts
+++ b/app/src/layout/dock/PinnedDocs.ts
@@ -226,6 +226,28 @@ export class PinnedDocs {
this.scheduleRefresh();
}
+ private getDocIconLabel(subFileCount: number) {
+ if (this.mobile) {
+ return subFileCount > 0 ? window.siyuan.languages.docIconClickExpand : window.siyuan.languages.openDocument;
+ }
+ return window.siyuan.config.fileTree.docIconClickMode === 1 ? "" : window.siyuan.languages.changeIcon;
+ }
+
+ public updateDocActions() {
+ // 直接更新现有图标提示,保留展开状态并避开文档快照缓存。
+ this.list.querySelectorAll<HTMLElement>("[data-pin-row]").forEach(row => {
+ const icon = row.querySelector<HTMLElement>(".b3-list-item__icon");
+ if (!icon) { return; }
+ const label = this.getDocIconLabel(Number(row.dataset.count));
+ icon.classList.toggle("ariaLabel", Boolean(label));
+ if (label) {
+ icon.setAttribute("aria-label", label);
+ } else {
+ icon.removeAttribute("aria-label");
+ }
+ });
+ }
+
private setCollapsed(collapsed: boolean, animate = false) {
setFileTreeVisibility(this.list, !collapsed, animate);
this.heading.setAttribute("aria-expanded", String(!collapsed));
@@ -301,10 +323,7 @@ export class PinnedDocs {
row.setAttribute("aria-disabled", String(Boolean(doc.unavailable)));
if (doc.subFileCount) { row.setAttribute("aria-expanded", "false"); }
// 桌面端点击会修改图标时给出提示,移动端保留无障碍标签
- const iconExpands = this.mobile || window.siyuan.config.fileTree.docIconClickMode === 1;
- const iconLabel = iconExpands ? (this.mobile ?
- (doc.subFileCount ? window.siyuan.languages.docIconClickExpand : window.siyuan.languages.openDocument) : "") :
- window.siyuan.languages.changeIcon;
+ const iconLabel = this.getDocIconLabel(doc.subFileCount);
if (!doc.icon) { row.dataset.defaultIcon = doc.subFileCount ? "folder" : "file"; }
row.innerHTML = `<span data-pin-toggle="true" style="padding-left:${paddingLeft}px" class="b3-list-item__toggle b3-list-item__toggle--hl${doc.subFileCount ? "" : " fn__hidden"}"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon${iconLabel ? " ariaLabel" : ""}" data-position="8east"${iconLabel ? ` aria-label="${iconLabel}"` : ""}>${getFileTreeIconHTML(doc.icon, doc.subFileCount ? "folder" : "file")}</span><span class="b3-list-item__text">${escapeHtml(doc.name)}${doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : ""}</span><span data-pin-more="true" class="b3-list-item__action" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`;
if (!doc.unavailable && !window.siyuan.config.readonly) {
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.ts
index e812c6eb5e..0109c6fdca 100644
--- a/app/src/types/api/index.d.ts
+++ b/app/src/types/api/index.d.ts
@@ -1400,9 +1400,9 @@ export type NetworkEchoAttributeTypeAndValue = { "Type": Array<number> | null; "
export type NetworkEchoBitString = { "BitLength": number; "Bytes": string | null; };
-export type NetworkEchoCertificate = { "AuthorityKeyId": string | null; "BasicConstraintsValid": boolean; "CRLDistributionPoints": Array<string> | null; "DNSNames": Array<string> | null; "EmailAddresses": Array<string> | null; "ExcludedDNSDomains": Array<string> | null; "ExcludedEmailAddresses": Array<string> | null; "ExcludedIPRanges": Array<NetworkEchoIPNet | null> | null; "ExcludedURIDomains": Array<string> | null; "ExtKeyUsage": Array<number> | null; "Extensions": Array<NetworkEchoExtension> | null; "ExtraExtensions": Array<NetworkEchoExtension> | null; "IPAddresses": Array<string> | null; "InhibitAnyPolicy": number; "InhibitAnyPolicyZero": boolean; "InhibitPolicyMapping": number; "InhibitPolicyMappingZero": boolean; "IsCA": boolean; "Issuer": NetworkEchoName; "IssuingCertificateURL": Array<string> | null; "KeyUsage": number; "MaxPathLen": number; "MaxPathLenZero": boolean; "NotAfter": string; "NotBefore": string; "OCSPServer": Array<string> | null; "PermittedDNSDomains": Array<string> | null; "PermittedDNSDomainsCritical": boolean; "PermittedEmailAddresses": Array<string> | null; "PermittedIPRanges": Array<NetworkEchoIPNet | null> | null; "PermittedURIDomains": Array<string> | null; "Policies": Array<string> | null; "PolicyIdentifiers": Array<Array<number> | null> | null; "PolicyMappings": Array<NetworkEchoPolicyMapping> | null; "PublicKey": null | string | (NetworkEchoRSAPublicKey & { "Curve"?: never; "G"?: never; "P"?: never; "Q"?: never; "X"?: never; "Y"?: never; }) | (NetworkEchoECDSAPublicKey & { "E"?: never; "G"?: never; "N"?: never; "P"?: never; "Q"?: never; }) | (NetworkEchoDSAPublicKey & { "Curve"?: never; "E"?: never; "N"?: never; "X"?: never; }); "PublicKeyAlgorithm": number; "Raw": string | null; "RawIssuer": string | null; "RawSignatureAlgorithm": string | null; "RawSubject": string | null; "RawSubjectPublicKeyInfo": string | null; "RawTBSCertificate": string | null; "RequireExplicitPolicy": number; "RequireExplicitPolicyZero": boolean; "SerialNumber": number | null; "Signature": string | null; "SignatureAlgorithm": number; "Subject": NetworkEchoName; "SubjectKeyId": string | null; "URIs": Array<NetworkEchoURL | null> | null; "UnhandledCriticalExtensions": Array<Array<number> | null> | null; "UnknownExtKeyUsage": Array<Array<number> | null> | null; "Version": number; };
+export type NetworkEchoCertificate = { "AuthorityKeyId": string | null; "BasicConstraintsValid": boolean; "CRLDistributionPoints": Array<string> | null; "DNSNames": Array<string> | null; "EmailAddresses": Array<string> | null; "ExcludedDNSDomains": Array<string> | null; "ExcludedEmailAddresses": Array<string> | null; "ExcludedIPRanges": Array<NetworkEchoIPNet | null> | null; "ExcludedURIDomains": Array<string> | null; "ExtKeyUsage": Array<number> | null; "Extensions": Array<NetworkEchoExtension> | null; "ExtraExtensions": Array<NetworkEchoExtension> | null; "IPAddresses": Array<string> | null; "InhibitAnyPolicy": number; "InhibitAnyPolicyZero": boolean; "InhibitPolicyMapping": number; "InhibitPolicyMappingZero": boolean; "IsCA": boolean; "Issuer": NetworkEchoName; "IssuingCertificateURL": Array<string> | null; "KeyUsage": number; "MaxPathLen": number; "MaxPathLenZero": boolean; "NotAfter": string; "NotBefore": string; "OCSPServer": Array<string> | null; "PermittedDNSDomains": Array<string> | null; "PermittedDNSDomainsCritical": boolean; "PermittedEmailAddresses": Array<string> | null; "PermittedIPRanges": Array<NetworkEchoIPNet | null> | null; "PermittedURIDomains": Array<string> | null; "Policies": Array<string> | null; "PolicyIdentifiers": Array<Array<number> | null> | null; "PolicyMappings": Array<NetworkEchoPolicyMapping> | null; "PublicKey": null | string | (NetworkEchoRSAPublicKey & { "Curve"?: never; "G"?: never; "P"?: never; "Q"?: never; "X"?: never; "Y"?: never; }) | (NetworkEchoECDSAPublicKey & { "E"?: never; "G"?: never; "N"?: never; "P"?: never; "Q"?: never; }) | (NetworkEchoDSAPublicKey & { "Curve"?: never; "E"?: never; "N"?: never; "X"?: never; }); "PublicKeyAlgorithm": number; "Raw": string | null; "RawIssuer": string | null; "RawSubject": string | null; "RawSubjectPublicKeyInfo": string | null; "RawTBSCertificate": string | null; "RequireExplicitPolicy": number; "RequireExplicitPolicyZero": boolean; "SerialNumber": number | null; "Signature": string | null; "SignatureAlgorithm": number; "Subject": NetworkEchoName; "SubjectKeyId": string | null; "URIs": Array<NetworkEchoURL | null> | null; "UnhandledCriticalExtensions": Array<Array<number> | null> | null; "UnknownExtKeyUsage": Array<Array<number> | null> | null; "Version": number; };
-export type NetworkEchoConnectionState = { "CipherSuite": number; "CurveID": number; "DidResume": boolean; "ECHAccepted": boolean; "HandshakeComplete": boolean; "HelloRetryRequest": boolean; "LocalCertificate": Array<string | null> | null; "NegotiatedProtocol": string; "NegotiatedProtocolIsMutual": boolean; "OCSPResponse": string | null; "PeerCertificates": Array<NetworkEchoCertificate | null> | null; "ServerName": string; "SignedCertificateTimestamps": Array<string | null> | null; "TLSUnique": string | null; "VerifiedChains": Array<Array<NetworkEchoCertificate | null> | null> | null; "Version": number; };
+export type NetworkEchoConnectionState = { "CipherSuite": number; "CurveID": number; "DidResume": boolean; "ECHAccepted": boolean; "HandshakeComplete": boolean; "HelloRetryRequest": boolean; "NegotiatedProtocol": string; "NegotiatedProtocolIsMutual": boolean; "OCSPResponse": string | null; "PeerCertificates": Array<NetworkEchoCertificate | null> | null; "ServerName": string; "SignedCertificateTimestamps": Array<string | null> | null; "TLSUnique": string | null; "VerifiedChains": Array<Array<NetworkEchoCertificate | null> | null> | null; "Version": number; };
export type NetworkEchoContext = { "ClientIP": string; "ContentType": string; "FullPath": string; "HandlerNames": Array<string> | null; "IsWebsocket": boolean; "Params": Array<NetworkEchoParam> | null; "RawData": string | null; "RemoteIP": string; };
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index accb786cae..90b153bdd6 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -926,12 +926,13 @@ declare namespace Config {
*/
alwaysSelectOpenedFile: boolean;
/**
- * Behavior of clicking a document or notebook icon: 0 changes the icon, 1 expands or collapses its child documents
+ * 桌面端单击文档图标的行为:0 修改图标,1 展开或折叠子文档;没有子文档时打开文档
+ * 桌面端笔记本图标始终用于修改图标;旧的布尔配置不迁移
*/
docIconClickMode: number;
/**
- * Behavior of clicking a parent document title: 0 opens the document, 1 expands or collapses its child documents,
- * 2 expands or collapses on a single click and opens the parent on a double-click
+ * 点击父文档标题的行为:0 打开文档,1 立即展开或折叠子文档,2 单击展开或折叠、双击打开父文档
+ * 取 2 时单击等待约 300 毫秒;没有子文档时直接打开;旧的布尔配置不迁移
*/
parentDocTitleClickMode: number;
/**
diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.json
index cb323237a2..c9f00e2e7c 100644
--- a/kernel/apicontract/schema.json
+++ b/kernel/apicontract/schema.json
@@ -31235,16 +31235,6 @@
}
]
},
- "RawSignatureAlgorithm": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ]
- },
"RawSubject": {
"anyOf": [
{
@@ -31426,7 +31416,6 @@
"PublicKeyAlgorithm",
"Raw",
"RawIssuer",
- "RawSignatureAlgorithm",
"RawSubject",
"RawSubjectPublicKeyInfo",
"RawTBSCertificate",
@@ -31465,26 +31454,6 @@
"HelloRetryRequest": {
"type": "boolean"
},
- "LocalCertificate": {
- "anyOf": [
- {
- "type": "array",
- "items": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ]
- }
- },
- {
- "type": "null"
- }
- ]
- },
"NegotiatedProtocol": {
"type": "string"
},
@@ -31595,7 +31564,6 @@
"ECHAccepted",
"HandshakeComplete",
"HelloRetryRequest",
- "LocalCertificate",
"NegotiatedProtocol",
"NegotiatedProtocolIsMutual",
"OCSPResponse",