Skip to content

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

:sparkles: Improve mobile database toolbar layout

Danielf7a9ca472808
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index 9c3fd3d421..4f74fbd409 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -161,6 +161,85 @@
}
}
+ &__views--mobile {
+ gap: 4px;
+ min-width: 0;
+
+ > .layout-tab-bar,
+ > .fn__space,
+ > .fn__flex-1,
+ > [data-type="av-add"],
+ > [data-type="av-filter"],
+ > [data-type="av-context-filter"],
+ > [data-type="av-sort"],
+ > [data-type="av-more"],
+ > [data-type="av-switcher"]:not(.av__mobile-view) {
+ display: none;
+ }
+
+ > .av__mobile-view {
+ flex: 1;
+ min-width: 64px;
+ overflow: hidden;
+ gap: 4px;
+
+ span {
+ flex: 1;
+ text-align: left;
+ }
+ }
+
+ > .block__icon {
+ min-height: 32px;
+ }
+
+ > [data-type="av-search-icon"] {
+ order: 1;
+ }
+
+ > .av__mobile-more {
+ order: 2;
+ }
+
+ > .av__new {
+ order: 3;
+ flex-shrink: 0;
+ }
+
+ > .av__search,
+ > .av__search-close {
+ display: none;
+ }
+
+ &.av__views--search {
+ > .av__mobile-view,
+ > .av__mobile-more,
+ > .av__new {
+ display: none;
+ }
+
+ > .av__search {
+ display: flex;
+ flex: 1;
+ min-width: 0;
+ order: 2;
+
+ [data-type="av-search"] {
+ width: 100% !important;
+ min-width: 0;
+ margin-right: 0 !important;
+ box-sizing: border-box;
+ padding-right: 24px !important;
+ }
+ }
+
+ > .av__search-close {
+ display: flex;
+ order: 3;
+ }
+ }
+ }
+
&__new {
.b3-button {
font-size: inherit;
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 809882037b..fcb3bf0ebf 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -421,6 +421,32 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
+ } else if (type === "av-mobile-more" && !protyle.disabled) {
+ const menu = new Menu();
+ const entries: Array<{type: "filters" | "contextFilter" | "sorts" | "config", action: string, icon: string, label: string}> = [
+ {type: "filters", action: "av-filter", icon: "iconFilter", label: window.siyuan.languages.filter},
+ {type: "contextFilter", action: "av-context-filter", icon: "iconFocus", label: window.siyuan.languages.contextFilter},
+ {type: "sorts", action: "av-sort", icon: "iconSort", label: window.siyuan.languages.sort},
+ {type: "config", action: "av-more", icon: "iconSettings", label: window.siyuan.languages.config},
+ ];
+ entries.forEach(entry => {
+ const control = blockElement.querySelector(`[data-type="${entry.action}"]`);
+ if (!control) {
+ return;
+ }
+ menu.addItem({
+ icon: entry.icon,
+ label: entry.label,
+ checked: control.classList.contains("block__icon--active"),
+ click() {
+ openMenuPanel({protyle, blockElement, type: entry.type});
+ }
+ });
+ });
+ menu.fullscreen();
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
} else if (type === "av-more" && !protyle.disabled) {
openMenuPanel({protyle, blockElement, type: "config"});
event.preventDefault();
@@ -785,6 +811,14 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
+ } else if (type === "av-search-close") {
+ const searchElement = blockElement.querySelector<HTMLElement>('[data-type="av-search"]');
+ searchElement.textContent = "";
+ searchElement.blur();
+ searchElement.dispatchEvent(new Event("input", {bubbles: true}));
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
} else if (type === "av-search-icon") {
const searchElement = blockElement.querySelector('div[data-type="av-search"]') as HTMLInputElement;
searchElement.style.width = "128px";
@@ -792,7 +826,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
searchElement.style.marginRight = "1em";
const viewsElement = hasClosestByClassName(searchElement, "av__views");
if (viewsElement) {
- viewsElement.classList.add("av__views--show");
+ viewsElement.classList.add("av__views--show", "av__views--search");
}
if (window.JSAndroid && window.JSAndroid.showKeyboard || window.JSHarmony && window.JSHarmony.showKeyboard) {
callMobileAppShowKeyboard();
diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts
index 6b573ecb53..5e825dd34b 100644
--- a/app/src/protyle/render/av/render.ts
+++ b/app/src/protyle/render/av/render.ts
@@ -131,7 +131,17 @@ export const genTabHeaderHTML = (data: IAV, showSearch: boolean, editable: boole
defaultTemplate.primaryKeyTemplate || Object.keys(defaultTemplate.fieldValues || {}).length) ? defaultTemplate.id : "";
const editingState = getAVHeaderEditingState(editable, includeEditingControls);
return `<div class="av__header" data-default-template-id="${defaultTemplateID}" data-current-view-id="${escapeAttr(data.viewID)}" data-view-count="${data.views.length}" data-view-ids="${data.views.map((view) => view.id).join(",")}" data-view-pages="${escapeAttr(serializeAVViewPageSizes(data.views))}">
- <div class="fn__flex av__views${showSearch ? " av__views--show" : ""}">
+ <div class="fn__flex av__views${isMobile() ? " av__views--mobile" : ""}${showSearch ? " av__views--show av__views--search" : ""}">
+ ${isMobile() ? `<button data-type="av-switcher" class="block__icon block__icon--show av__mobile-view" aria-label="${escapeAriaLabel(window.siyuan.languages.allViews)}">
+ <span class="fn__ellipsis">${escapeHtml(viewData?.name || data.name || "")}</span>
+ <svg><use xlink:href="#iconDown"></use></svg>
+ </button>
+ <button data-type="av-mobile-more" class="block__icon block__icon--show av__mobile-more${hasFilter || data.view.sorts.length > 0 || getContextFilterKeyID(data.contextFilter) ? " block__icon--active" : ""}" aria-label="${window.siyuan.languages.more}">
+ <svg><use xlink:href="#iconMore"></use></svg>
+ </button>
+ <button data-type="av-search-close" class="block__icon block__icon--show av__search-close" aria-label="${window.siyuan.languages.close}">
+ <svg><use xlink:href="#iconClose"></use></svg>
+ </button>` : ""}
<div class="av__selection-toolbar">
<span class="av__selection-count"></span>
${editingState.selectionHTML}
@@ -162,7 +172,7 @@ export const genTabHeaderHTML = (data: IAV, showSearch: boolean, editable: boole
<button data-type="av-search-icon" aria-label="${window.siyuan.languages.search}" data-position="8south" class="ariaLabel block__icon">
<svg><use xlink:href="#iconSearch"></use></svg>
</button>
- <div style="position: relative" class="fn__flex">
+ <div style="position: relative" class="fn__flex av__search">
<div contenteditable="plaintext-only" style="${showSearch ? "width:128px" : "width:0;padding-left: 0;padding-right: 0;"}" data-type="av-search" class="b3-text-field b3-text-field--text" placeholder="${window.siyuan.languages.searchPlaceholder}"></div>
</div>
<div class="fn__space"></div>
diff --git a/app/src/protyle/render/av/search.ts b/app/src/protyle/render/av/search.ts
index 16c2d22823..257890498d 100644
--- a/app/src/protyle/render/av/search.ts
+++ b/app/src/protyle/render/av/search.ts
@@ -6,7 +6,7 @@ import {activeBlur} from "../../../mobile/util/keyboardToolbar";
/// #endif
const collapseAvSearch = (searchInputElement: HTMLElement, viewsElement: HTMLElement) => {
- viewsElement.classList.remove("av__views--show");
+ viewsElement.classList.remove("av__views--show", "av__views--search");
searchInputElement.style.width = "0";
searchInputElement.style.paddingLeft = "0";
searchInputElement.style.marginRight = "0";
@@ -39,9 +39,9 @@ export const bindAvSearch = (options: {
return;
}
if (searchInputElement.textContent || document.activeElement === searchInputElement) {
- viewsElement.classList.add("av__views--show");
+ viewsElement.classList.add("av__views--show", "av__views--search");
} else {
- viewsElement.classList.remove("av__views--show");
+ viewsElement.classList.remove("av__views--show", "av__views--search");
}
options.onChange();
};