Skip to content

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

:art: https://github.com/siyuan-note/siyuan/pull/14380

Vanessad0700b752725
diff --git a/app/src/assets/scss/business/_config.scss b/app/src/assets/scss/business/_config.scss
index c0cc6ffbbf..11f3937d70 100644
--- a/app/src/assets/scss/business/_config.scss
+++ b/app/src/assets/scss/business/_config.scss
@@ -208,6 +208,7 @@
justify-content: center;
overflow: auto;
flex: 1;
+ padding: 0 8px;
margin-top: 8px;
}
}
diff --git a/app/src/assets/scss/mobile.scss b/app/src/assets/scss/mobile.scss
index 2309ea8158..d34534a5b8 100644
--- a/app/src/assets/scss/mobile.scss
+++ b/app/src/assets/scss/mobile.scss
@@ -254,6 +254,29 @@
text-align: center;
}
}
+
+ .config-assets {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ box-sizing: border-box;
+
+ &__list {
+ overflow: auto;
+ flex: 1;
+ }
+
+ &__preview {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ justify-content: center;
+ overflow: auto;
+ flex: 1;
+ margin-top: 8px;
+ padding: 0 8px;
+ }
+ }
}
#menu {
diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.ts
index 12640326b4..e43571ee90 100644
--- a/app/src/boot/globalEvent/click.ts
+++ b/app/src/boot/globalEvent/click.ts
@@ -1,4 +1,6 @@
+/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
+/// #endif
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
import {hideAllElements} from "../../protyle/ui/hideElements";
import {isWindow} from "../../util/functions";
@@ -22,22 +24,6 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
globalClickHideMenu(event.target);
- if (!hasClosestByClassName(event.target, "pdf__outer")) {
- hideAllElements(["pdfutil"]);
- }
- // dock float 时,点击空白处,隐藏 dock。场景:文档树上重命名后
- if (!isWindow() && window.siyuan.layout.leftDock &&
- !hasClosestByClassName(event.target, "b3-dialog--open", true) &&
- !hasClosestByClassName(event.target, "b3-menu") &&
- !hasClosestByClassName(event.target, "block__popover") &&
- !hasClosestByClassName(event.target, "dock") &&
- !hasClosestByClassName(event.target, "layout--float", true)
- ) {
- window.siyuan.layout.bottomDock.hideDock();
- window.siyuan.layout.leftDock.hideDock();
- window.siyuan.layout.rightDock.hideDock();
- }
-
const protyleElement = hasClosestByClassName(event.target, "protyle", true);
if (protyleElement) {
const wysiwygElement = protyleElement.querySelector(".protyle-wysiwyg");
@@ -45,6 +31,7 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
wysiwygElement.dispatchEvent(new Event("focusin"));
}
}
+
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
if (copyElement) {
let text = copyElement.parentElement.nextElementSibling.textContent.replace(/\n$/, "");
@@ -55,6 +42,24 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
return;
}
+ /// #if !MOBILE
+ // dock float 时,点击空白处,隐藏 dock。场景:文档树上重命名后
+ if (!isWindow() && window.siyuan.layout.leftDock &&
+ !hasClosestByClassName(event.target, "b3-dialog--open", true) &&
+ !hasClosestByClassName(event.target, "b3-menu") &&
+ !hasClosestByClassName(event.target, "block__popover") &&
+ !hasClosestByClassName(event.target, "dock") &&
+ !hasClosestByClassName(event.target, "layout--float", true)
+ ) {
+ window.siyuan.layout.bottomDock.hideDock();
+ window.siyuan.layout.leftDock.hideDock();
+ window.siyuan.layout.rightDock.hideDock();
+ }
+
+ if (!hasClosestByClassName(event.target, "pdf__outer")) {
+ hideAllElements(["pdfutil"]);
+ }
+
// 点击空白,pdf 搜索、更多消失
if (hasClosestByAttribute(event.target, "id", "secondaryToolbarToggleButton") ||
hasClosestByAttribute(event.target, "id", "viewFindButton") ||
@@ -81,4 +86,5 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
) {
currentPDFViewerObject.findBar.close();
}
+ /// #endif
};
diff --git a/app/src/config/image.ts b/app/src/config/image.ts
index 164521e908..46a861af8d 100644
--- a/app/src/config/image.ts
+++ b/app/src/config/image.ts
@@ -1,10 +1,12 @@
import {escapeHtml} from "../util/escape";
import {confirmDialog} from "../dialog/confirmDialog";
import {pathPosix} from "../util/pathName";
-import {isBrowser} from "../util/functions";
+import {isBrowser, isMobile} from "../util/functions";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {fetchPost} from "../util/fetch";
+/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
+/// #endif
import {openBy} from "../editor/util";
import {renderAssetsPreview} from "../asset/renderAssets";
import {writeText} from "../protyle/util/compatibility";
@@ -12,6 +14,7 @@ import {writeText} from "../protyle/util/compatibility";
export const image = {
element: undefined as Element,
genHTML: () => {
+ const isM = isMobile();
return `<div class="fn__flex-column" style="height: 100%">
<div class="layout-tab-bar fn__flex">
<div class="item item--full item--focus" data-type="remove">
@@ -26,7 +29,7 @@ export const image = {
</div>
</div>
<div class="fn__flex-1">
- <div class="config-assets" data-type="remove" data-init="true">
+ <div class="config-assets${isM ? " b3-list--mobile" : ""}" data-type="remove" data-init="true">
<div class="fn__hr--b"></div>
<div class="fn__flex">
<div class="fn__space"></div>
@@ -41,7 +44,7 @@ export const image = {
</ul>
<div class="config-assets__preview"></div>
</div>
- <div class="fn__none config-assets" data-type="missing">
+ <div class="fn__none config-assets${isM ? " b3-list--mobile" : ""}" data-type="missing">
<div class="fn__hr"></div>
<ul class="b3-list b3-list--background config-assets__list">
<li class="fn__loading"><img src="/stage/loading-pure.svg"></li>
@@ -60,11 +63,13 @@ export const image = {
if (target.id === "removeAll") {
confirmDialog(window.siyuan.languages.deleteOpConfirm, `${window.siyuan.languages.clearAll}`, () => {
fetchPost("/api/asset/removeUnusedAssets", {}, response => {
+ /// #if !MOBILE
getAllModels().asset.forEach(item => {
if (response.data.paths.includes(item.path)) {
item.parent.close();
}
});
+ /// #endif
assetsListElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
image.element.querySelector(".config-assets__preview").innerHTML = "";
});
@@ -100,11 +105,13 @@ export const image = {
fetchPost("/api/asset/removeUnusedAsset", {
path: pathString,
}, response => {
+ /// #if !MOBILE
getAllModels().asset.forEach(item => {
if (response.data.path === item.path) {
item.parent.parent.removeTab(item.parent.id);
}
});
+ /// #endif
const liElement = target.parentElement;
if (liElement.parentElement.querySelectorAll("li").length === 1) {
liElement.parentElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
@@ -148,10 +155,11 @@ export const image = {
<svg><use xlink:href="#iconTrashcan"></use></svg>
</span>`;
}
+ const isM = isMobile()
data.forEach((item) => {
const idx = item.indexOf("assets/");
const dataPath = item.substr(idx);
- html += `<li data-path="${dataPath}" class="b3-list-item b3-list-item--hide-action">
+ html += `<li data-path="${dataPath}" class="b3-list-item${isM ? "" : " b3-list-item--hide-action"}">
<span class="b3-list-item__text">${escapeHtml(item)}</span>
<span data-type="copy" class="ariaLabel b3-list-item__action" aria-label="${window.siyuan.languages.copy}">
<svg><use xlink:href="#iconCopy"></use></svg>
diff --git a/app/src/layout/getAll.ts b/app/src/layout/getAll.ts
index 04dcdcf6cf..d104e9b925 100644
--- a/app/src/layout/getAll.ts
+++ b/app/src/layout/getAll.ts
@@ -59,8 +59,8 @@ export const getAllEditor = () => {
return editors;
};
+/// #if !MOBILE
export const getAllModels = () => {
- /// #if !MOBILE
const models: IModels = {
editor: [],
graph: [],
@@ -110,7 +110,6 @@ export const getAllModels = () => {
getTabs(window.siyuan.layout.layout);
}
return models;
- /// #endif
};
export const getAllWnds = (layout: Layout, wnds: Wnd[]) => {
@@ -162,3 +161,4 @@ export const getAllDocks = () => {
});
return docks;
};
+/// #endif
diff --git a/app/src/layout/index.ts b/app/src/layout/index.ts
index 91e3050dcc..50b214d6d4 100644
--- a/app/src/layout/index.ts
+++ b/app/src/layout/index.ts
@@ -6,7 +6,6 @@ import {recordBeforeResizeTop} from "../protyle/util/resize";
/// #if MOBILE
// 检测移动端是否引入了桌面端的代码
console.error("Need remove unused code");
-
/// #endif
export class Layout {
diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts
index eba1bbd256..98d0d66968 100644
--- a/app/src/plugin/API.ts
+++ b/app/src/plugin/API.ts
@@ -20,7 +20,10 @@ import {openMobileFileById} from "../mobile/editor";
import {lockScreen, exitSiYuan} from "../dialog/processSystem";
import {Model} from "../layout/Model";
import {getDockByType} from "../layout/tabUtil";
-import {getAllEditor, getAllModels} from "../layout/getAll";
+/// #if !MOBILE
+import {getAllModels} from "../layout/getAll";
+/// #endif
+import {getAllEditor} from "../layout/getAll";
import {openSetting} from "../config";
import {openAttr, openFileAttr} from "../menus/commonMenuItem";
@@ -213,7 +216,9 @@ export const API = {
Menu,
Setting,
getAllEditor,
+ /// #if !MOBILE
getAllModels,
+ /// #endif
platformUtils,
openSetting,
openAttributePanel,
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index dc863860ed..b8351d7755 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -17,7 +17,8 @@ import {Breadcrumb} from "./breadcrumb";
import {
onTransaction,
transaction,
- turnsIntoOneTransaction, turnsIntoTransaction,
+ turnsIntoOneTransaction,
+ turnsIntoTransaction,
updateBatchTransaction,
updateTransaction
} from "./wysiwyg/transaction";
@@ -41,7 +42,9 @@ import {focusBlock, getEditorRange} from "./util/selection";
import {hasClosestBlock} from "./util/hasClosest";
import {setStorageVal} from "./util/compatibility";
import {merge} from "./util/merge";
+/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
+/// #endif
import {isSupportCSSHL} from "./render/searchMarkRender";
import {renderAVAttribute} from "./render/av/blockAttr";
@@ -128,6 +131,7 @@ export class Protyle {
case "reload":
if (data.data === this.protyle.block.rootID) {
reloadProtyle(this.protyle, false);
+ /// #if !MOBILE
getAllModels().outline.forEach(item => {
if (item.blockId === data.data) {
fetchPost("/api/outline/getDocOutline", {
@@ -138,6 +142,7 @@ export class Protyle {
});
}
});
+ /// #endif
}
break;
case "refreshAttributeView":
@@ -159,12 +164,14 @@ export class Protyle {
this.protyle.preview.render(this.protyle);
} else if (options.backlinkData && ["delete", "move"].includes(item.action)) {
// 只对特定情况刷新,否则展开、编辑等操作刷新会频繁
+ /// #if !MOBILE
getAllModels().backlink.find(backlinkItem => {
if (backlinkItem.element.contains(this.protyle.element)) {
backlinkItem.refresh();
return true;
}
});
+ /// #endif
return true;
} else {
onTransaction(this.protyle, item, false);
diff --git a/app/src/protyle/util/resize.ts b/app/src/protyle/util/resize.ts
index 771469c262..c2c1c88752 100644
--- a/app/src/protyle/util/resize.ts
+++ b/app/src/protyle/util/resize.ts
@@ -3,10 +3,13 @@ import {setPadding} from "../ui/initUI";
import {hasClosestBlock} from "./hasClosest";
import {Constants} from "../../constants";
import {lineNumberRender} from "../render/highlightRender";
-import {stickyRow} from "../render/av/row";
+/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
+/// #endif
+import {stickyRow} from "../render/av/row";
export const recordBeforeResizeTop = () => {
+ /// #if !MOBILE
getAllModels().editor.forEach((item) => {
if (item.editor && item.editor.protyle &&
item.element.parentElement && !item.element.classList.contains("fn__none")) {
@@ -26,6 +29,7 @@ export const recordBeforeResizeTop = () => {
topElement.setAttribute("data-resize-top", topElement.getBoundingClientRect().top.toString());
}
});
+ /// #endif
};
export const resize = (protyle: IProtyle) => {