Skip to content

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

:sparkles: Support document tabs on mobile https://github.com/siyuan-note/siyuan/issues/16094

Danielcbc433c844e0
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index 7319290514..c4683b639f 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,4 +1,12 @@
{
+ "newTab": "علامة تبويب جديدة",
+ "mobileTabs": "علامات التبويب",
+ "tabStartupClose": "إغلاق علامات التبويب المفتوحة",
+ "tabStartupNew": "فتح علامة تبويب فارغة جديدة",
+ "tabStartupRestore": "استعادة علامات التبويب السابقة",
+ "tabStartupModeTip": "اختر كيفية التعامل مع علامات التبويب عند بدء الواجهة",
+ "tabStartupMode": "عند بدء التشغيل",
+ "tabStartup": "بدء علامات التبويب",
"configGroupMarkdownBlockSyntax": "صيغة كتل Markdown",
"codeBlockMiddleDot": "اختصار كتلة التعليمات البرمجية بالنقطة الوسطى",
"codeBlockMiddleDotTip": "عند التمكين، يؤدي إدخال <code class='fn__code'>···</code> ثم الضغط على Enter أو إدخال نقطة وسطى أخرى إلى التحويل إلى كتلة تعليمات برمجية",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index e44928e97a..6748e0838f 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Neuer Tab",
+ "mobileTabs": "Tabs",
+ "tabStartupClose": "Geöffnete Tabs schließen",
+ "tabStartupNew": "Neuen leeren Tab öffnen",
+ "tabStartupRestore": "Vorherige Tabs wiederherstellen",
+ "tabStartupModeTip": "Wählen Sie, wie Tabs beim Start der Oberfläche behandelt werden",
+ "tabStartupMode": "Beim Start",
+ "tabStartup": "Tab-Start",
"configGroupMarkdownBlockSyntax": "Markdown-Blocksyntax",
"codeBlockMiddleDot": "Codeblock-Kürzel mit Mittelpunkt",
"codeBlockMiddleDotTip": "Wenn aktiviert, wird die Eingabe von <code class='fn__code'>···</code> gefolgt von der Eingabetaste oder einem weiteren Mittelpunkt in einen Codeblock umgewandelt",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index 2298b1d2c9..71e0f06907 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,4 +1,12 @@
{
+ "newTab": "New Tab",
+ "mobileTabs": "Tabs",
+ "tabStartupClose": "Close Open Tabs",
+ "tabStartupNew": "Open a New Blank Tab",
+ "tabStartupRestore": "Restore Previous Tabs",
+ "tabStartupModeTip": "Choose how tabs are handled when the interface starts",
+ "tabStartupMode": "At Startup",
+ "tabStartup": "Tab Startup",
"configGroupMarkdownBlockSyntax": "Markdown Block Syntax",
"codeBlockMiddleDot": "Middle dot code block shortcut",
"codeBlockMiddleDotTip": "When enabled, entering <code class='fn__code'>···</code> followed by Enter or another middle dot converts it to a code block",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index 4075d214b1..748c6bacd6 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nueva pestaña",
+ "mobileTabs": "Pestañas",
+ "tabStartupClose": "Cerrar pestañas abiertas",
+ "tabStartupNew": "Abrir una pestaña nueva en blanco",
+ "tabStartupRestore": "Restaurar pestañas anteriores",
+ "tabStartupModeTip": "Elige cómo se gestionan las pestañas al iniciar la interfaz",
+ "tabStartupMode": "Al iniciar",
+ "tabStartup": "Inicio de pestañas",
"configGroupMarkdownBlockSyntax": "Sintaxis de bloques Markdown",
"codeBlockMiddleDot": "Atajo de bloque de código con punto medio",
"codeBlockMiddleDotTip": "Cuando está activado, al introducir <code class='fn__code'>···</code> y pulsar Intro o escribir otro punto medio, se convierte en un bloque de código",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index 7210c9e9f9..8c6ab1a1b3 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nouvel onglet",
+ "mobileTabs": "Onglets",
+ "tabStartupClose": "Fermer les onglets ouverts",
+ "tabStartupNew": "Ouvrir un nouvel onglet vide",
+ "tabStartupRestore": "Restaurer les onglets précédents",
+ "tabStartupModeTip": "Choisissez comment les onglets sont gérés au démarrage de l’interface",
+ "tabStartupMode": "Au démarrage",
+ "tabStartup": "Démarrage des onglets",
"configGroupMarkdownBlockSyntax": "Syntaxe de bloc Markdown",
"codeBlockMiddleDot": "Raccourci de bloc de code avec point médian",
"codeBlockMiddleDotTip": "Lorsque cette option est activée, la saisie de <code class='fn__code'>···</code> suivie d’Entrée ou d’un autre point médian est convertie en bloc de code",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index 7dbc67f60d..7138b28f84 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,4 +1,12 @@
{
+ "newTab": "כרטיסייה חדשה",
+ "mobileTabs": "כרטיסיות",
+ "tabStartupClose": "סגירת כרטיסיות פתוחות",
+ "tabStartupNew": "פתיחת כרטיסייה ריקה חדשה",
+ "tabStartupRestore": "שחזור הכרטיסיות הקודמות",
+ "tabStartupModeTip": "בחר כיצד לטפל בכרטיסיות בעת הפעלת הממשק",
+ "tabStartupMode": "בעת ההפעלה",
+ "tabStartup": "הפעלת כרטיסיות",
"configGroupMarkdownBlockSyntax": "תחביר בלוקים של Markdown",
"codeBlockMiddleDot": "קיצור לבלוק קוד באמצעות נקודה אמצעית",
"codeBlockMiddleDotTip": "כאשר האפשרות מופעלת, הקלדת <code class='fn__code'>···</code> ולאחריה Enter או נקודה אמצעית נוספת ממירה את הטקסט לבלוק קוד",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index 20e075fedf..0b79099114 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,4 +1,12 @@
{
+ "newTab": "नया टैब",
+ "mobileTabs": "टैब",
+ "tabStartupClose": "खुले टैब बंद करें",
+ "tabStartupNew": "नया खाली टैब खोलें",
+ "tabStartupRestore": "पिछले टैब पुनर्स्थापित करें",
+ "tabStartupModeTip": "इंटरफ़ेस शुरू होने पर टैब प्रबंधित करने का तरीका चुनें",
+ "tabStartupMode": "शुरू करते समय",
+ "tabStartup": "टैब प्रारंभ",
"configGroupMarkdownBlockSyntax": "Markdown ब्लॉक सिंटैक्स",
"codeBlockMiddleDot": "मध्य बिंदु कोड ब्लॉक शॉर्टकट",
"codeBlockMiddleDotTip": "सक्षम होने पर, <code class='fn__code'>···</code> दर्ज करके Enter या एक और मध्य बिंदु दबाने से यह कोड ब्लॉक में बदल जाता है",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index f0f76482c7..c20e6c184a 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Tab baru",
+ "mobileTabs": "Tab",
+ "tabStartupClose": "Tutup tab yang terbuka",
+ "tabStartupNew": "Buka tab kosong baru",
+ "tabStartupRestore": "Pulihkan tab sebelumnya",
+ "tabStartupModeTip": "Pilih cara menangani tab saat antarmuka dimulai",
+ "tabStartupMode": "Saat memulai",
+ "tabStartup": "Pembukaan tab",
"configGroupMarkdownBlockSyntax": "Sintaks Blok Markdown",
"codeBlockMiddleDot": "Pintasan blok kode titik tengah",
"codeBlockMiddleDotTip": "Jika diaktifkan, memasukkan <code class='fn__code'>···</code> lalu menekan Enter atau mengetik titik tengah lainnya akan mengubahnya menjadi blok kode",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index 84dbb89a2e..bf3fa5eb66 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nuova scheda",
+ "mobileTabs": "Schede",
+ "tabStartupClose": "Chiudi le schede aperte",
+ "tabStartupNew": "Apri una nuova scheda vuota",
+ "tabStartupRestore": "Ripristina le schede precedenti",
+ "tabStartupModeTip": "Scegli come gestire le schede all’avvio dell’interfaccia",
+ "tabStartupMode": "All’avvio",
+ "tabStartup": "Avvio delle schede",
"configGroupMarkdownBlockSyntax": "Sintassi Markdown a blocchi",
"codeBlockMiddleDot": "Scorciatoia per blocco di codice con punto centrale",
"codeBlockMiddleDotTip": "Quando è attiva, digitando <code class='fn__code'>···</code> seguito da Invio o da un altro punto centrale il testo viene convertito in un blocco di codice",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 37c260b009..725c229bcd 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,4 +1,12 @@
{
+ "newTab": "新しいタブ",
+ "mobileTabs": "タブ",
+ "tabStartupClose": "開いているタブを閉じる",
+ "tabStartupNew": "新しい空白タブを開く",
+ "tabStartupRestore": "前回のタブを復元する",
+ "tabStartupModeTip": "画面起動時のタブの処理方法を選択します",
+ "tabStartupMode": "起動時",
+ "tabStartup": "タブの起動",
"configGroupMarkdownBlockSyntax": "Markdown ブロック構文",
"codeBlockMiddleDot": "中点によるコードブロック入力",
"codeBlockMiddleDotTip": "有効にすると、<code class='fn__code'>···</code> を入力して Enter キーまたは別の中点を入力したときにコードブロックへ変換されます",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index 05d6fdcbe4..73abdf80df 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,4 +1,12 @@
{
+ "newTab": "새 탭",
+ "mobileTabs": "탭",
+ "tabStartupClose": "열린 탭 닫기",
+ "tabStartupNew": "새 빈 탭 열기",
+ "tabStartupRestore": "이전 탭 복원",
+ "tabStartupModeTip": "인터페이스 시작 시 탭 처리 방식을 선택합니다",
+ "tabStartupMode": "시작할 때",
+ "tabStartup": "탭 시작",
"configGroupMarkdownBlockSyntax": "Markdown 블록 구문",
"codeBlockMiddleDot": "가운뎃점 코드 블록 단축 입력",
"codeBlockMiddleDotTip": "활성화하면 <code class='fn__code'>···</code> 입력 후 Enter 키 또는 가운뎃점을 하나 더 입력할 때 코드 블록으로 변환됩니다",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index 1eb3a34032..65c430ab57 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nieuw tabblad",
+ "mobileTabs": "Tabbladen",
+ "tabStartupClose": "Geopende tabbladen sluiten",
+ "tabStartupNew": "Een nieuw leeg tabblad openen",
+ "tabStartupRestore": "Vorige tabbladen herstellen",
+ "tabStartupModeTip": "Kies hoe tabbladen worden verwerkt wanneer de interface start",
+ "tabStartupMode": "Bij opstarten",
+ "tabStartup": "Tabbladen bij opstarten",
"configGroupMarkdownBlockSyntax": "Markdown-bloksyntaxis",
"codeBlockMiddleDot": "Snelkoppeling voor codeblok met middelpunt",
"codeBlockMiddleDotTip": "Indien ingeschakeld, wordt het invoeren van <code class='fn__code'>···</code> gevolgd door Enter of nog een middelpunt omgezet in een codeblok",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index 10f2cf8c90..74c2278d63 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nowa karta",
+ "mobileTabs": "Karty",
+ "tabStartupClose": "Zamknij otwarte karty",
+ "tabStartupNew": "Otwórz nową pustą kartę",
+ "tabStartupRestore": "Przywróć poprzednie karty",
+ "tabStartupModeTip": "Wybierz sposób obsługi kart podczas uruchamiania interfejsu",
+ "tabStartupMode": "Przy uruchamianiu",
+ "tabStartup": "Uruchamianie kart",
"configGroupMarkdownBlockSyntax": "Składnia blokowa Markdown",
"codeBlockMiddleDot": "Skrót bloku kodu ze środkową kropką",
"codeBlockMiddleDotTip": "Po włączeniu wpisanie <code class='fn__code'>···</code> i naciśnięcie Enter lub wpisanie kolejnej środkowej kropki przekształca tekst w blok kodu",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index 51b4118de7..8034384d44 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nova aba",
+ "mobileTabs": "Abas",
+ "tabStartupClose": "Fechar abas abertas",
+ "tabStartupNew": "Abrir uma nova aba em branco",
+ "tabStartupRestore": "Restaurar abas anteriores",
+ "tabStartupModeTip": "Escolha como as abas são tratadas ao iniciar a interface",
+ "tabStartupMode": "Ao iniciar",
+ "tabStartup": "Inicialização das abas",
"configGroupMarkdownBlockSyntax": "Sintaxe de bloco Markdown",
"codeBlockMiddleDot": "Atalho de bloco de código com ponto médio",
"codeBlockMiddleDotTip": "Quando ativado, inserir <code class='fn__code'>···</code> seguido de Enter ou de outro ponto médio converte o texto em um bloco de código",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index f8f8311734..24c65ecbfe 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Новая вкладка",
+ "mobileTabs": "Вкладки",
+ "tabStartupClose": "Закрыть открытые вкладки",
+ "tabStartupNew": "Открыть новую пустую вкладку",
+ "tabStartupRestore": "Восстановить предыдущие вкладки",
+ "tabStartupModeTip": "Выберите способ обработки вкладок при запуске интерфейса",
+ "tabStartupMode": "При запуске",
+ "tabStartup": "Запуск вкладок",
"configGroupMarkdownBlockSyntax": "Блочный синтаксис Markdown",
"codeBlockMiddleDot": "Быстрый ввод блока кода через среднюю точку",
"codeBlockMiddleDotTip": "Если включено, ввод <code class='fn__code'>···</code> с последующим нажатием Enter или вводом ещё одной средней точки преобразует текст в блок кода",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index 705bb7ef57..df88138fdc 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Nová karta",
+ "mobileTabs": "Karty",
+ "tabStartupClose": "Zavrieť otvorené karty",
+ "tabStartupNew": "Otvoriť novú prázdnu kartu",
+ "tabStartupRestore": "Obnoviť predchádzajúce karty",
+ "tabStartupModeTip": "Vyberte spôsob spracovania kariet pri spustení rozhrania",
+ "tabStartupMode": "Pri spustení",
+ "tabStartup": "Spustenie kariet",
"configGroupMarkdownBlockSyntax": "Bloková syntax Markdown",
"codeBlockMiddleDot": "Skratka bloku kódu so stredovou bodkou",
"codeBlockMiddleDotTip": "Ak je zapnuté, zadanie <code class='fn__code'>···</code> a následné stlačenie Enter alebo zadanie ďalšej stredovej bodky prevedie text na blok kódu",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index 367efba1ef..b9a4b815ce 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,4 +1,12 @@
{
+ "newTab": "แท็บใหม่",
+ "mobileTabs": "แท็บ",
+ "tabStartupClose": "ปิดแท็บที่เปิดอยู่",
+ "tabStartupNew": "เปิดแท็บว่างใหม่",
+ "tabStartupRestore": "คืนค่าแท็บก่อนหน้า",
+ "tabStartupModeTip": "เลือกวิธีจัดการแท็บเมื่อเริ่มอินเทอร์เฟซ",
+ "tabStartupMode": "เมื่อเริ่มต้น",
+ "tabStartup": "การเริ่มต้นแท็บ",
"configGroupMarkdownBlockSyntax": "ไวยากรณ์บล็อก Markdown",
"codeBlockMiddleDot": "ทางลัดบล็อกโค้ดด้วยจุดกึ่งกลาง",
"codeBlockMiddleDotTip": "เมื่อเปิดใช้งาน การป้อน <code class='fn__code'>···</code> แล้วกด Enter หรือป้อนจุดกึ่งกลางอีกหนึ่งตัวจะแปลงเป็นบล็อกโค้ด",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index ea4fde91c0..3badc5a3bf 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Yeni sekme",
+ "mobileTabs": "Sekmeler",
+ "tabStartupClose": "Açık sekmeleri kapat",
+ "tabStartupNew": "Yeni boş sekme aç",
+ "tabStartupRestore": "Önceki sekmeleri geri yükle",
+ "tabStartupModeTip": "Arayüz başlatıldığında sekmelerin nasıl işleneceğini seçin",
+ "tabStartupMode": "Başlangıçta",
+ "tabStartup": "Sekme başlangıcı",
"configGroupMarkdownBlockSyntax": "Markdown Blok Sözdizimi",
"codeBlockMiddleDot": "Orta nokta kod bloğu kısayolu",
"codeBlockMiddleDotTip": "Etkinleştirildiğinde, <code class='fn__code'>···</code> yazıp Enter tuşuna basmak veya bir orta nokta daha girmek metni kod bloğuna dönüştürür",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index 31d03ebe72..1721486d0d 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,4 +1,12 @@
{
+ "newTab": "Нова вкладка",
+ "mobileTabs": "Вкладки",
+ "tabStartupClose": "Закрити відкриті вкладки",
+ "tabStartupNew": "Відкрити нову порожню вкладку",
+ "tabStartupRestore": "Відновити попередні вкладки",
+ "tabStartupModeTip": "Виберіть спосіб обробки вкладок під час запуску інтерфейсу",
+ "tabStartupMode": "Під час запуску",
+ "tabStartup": "Запуск вкладок",
"configGroupMarkdownBlockSyntax": "Блоковий синтаксис Markdown",
"codeBlockMiddleDot": "Швидке введення блоку коду через середню крапку",
"codeBlockMiddleDotTip": "Якщо ввімкнено, введення <code class='fn__code'>···</code> з подальшим натисканням Enter або введенням ще однієї середньої крапки перетворює текст на блок коду",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 6da25780aa..54e29a0c10 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,4 +1,12 @@
{
+ "newTab": "新建页签",
+ "mobileTabs": "页签",
+ "tabStartupClose": "关闭已打开的页签",
+ "tabStartupNew": "打开新的空白页签",
+ "tabStartupRestore": "恢复上次的页签",
+ "tabStartupModeTip": "选择界面启动时页签的处理方式",
+ "tabStartupMode": "启动时",
+ "tabStartup": "页签启动",
"configGroupMarkdownBlockSyntax": "Markdown 块级语法",
"codeBlockMiddleDot": "中点代码块快捷输入",
"codeBlockMiddleDotTip": "启用后,输入 <code class='fn__code'>···</code> 并按回车或继续输入中点时将转换为代码块",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index 8f747412b9..4538d2fb73 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,4 +1,12 @@
{
+ "newTab": "新增頁籤",
+ "mobileTabs": "頁籤",
+ "tabStartupClose": "關閉已開啟的頁籤",
+ "tabStartupNew": "開啟新的空白頁籤",
+ "tabStartupRestore": "還原上次的頁籤",
+ "tabStartupModeTip": "選擇介面啟動時頁籤的處理方式",
+ "tabStartupMode": "啟動時",
+ "tabStartup": "頁籤啟動",
"configGroupMarkdownBlockSyntax": "Markdown 區塊級語法",
"codeBlockMiddleDot": "中點程式碼區塊快捷輸入",
"codeBlockMiddleDotTip": "啟用後,輸入 <code class='fn__code'>···</code> 並按下回車或繼續輸入中點時將轉換為程式碼區塊",
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index 1a5fcbdf5e..21d4772e35 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -147,6 +147,112 @@
min-height: 30px;
line-height: 30px;
}
+
+ &__tabs {
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ height: 40px;
+ min-width: 40px;
+ padding: 0 8px;
+ border: 0;
+ border-radius: var(--b3-border-radius);
+ color: var(--b3-theme-on-surface);
+ background: transparent;
+
+ svg {
+ width: 18px;
+ height: 18px;
+ }
+
+ &:hover,
+ &:focus {
+ background-color: var(--b3-list-hover);
+ }
+ }
+
+ &__tabs-count {
+ min-width: 14px;
+ font-size: 12px;
+ line-height: 16px;
+ text-align: center;
+ }
+}
+
+.mobile-tabs {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+
+ &__list {
+ flex: 1;
+ min-height: 0;
+ padding: 12px;
+ overflow: auto;
+ }
+
+ &__item {
+ display: flex;
+ align-items: center;
+ min-height: 48px;
+ margin-bottom: 8px;
+ padding: 4px 6px 4px 12px;
+ border: 1px solid var(--b3-border-color);
+ border-radius: var(--b3-border-radius-b);
+ background-color: var(--b3-theme-background);
+
+ &--active {
+ border-color: var(--b3-theme-primary);
+ box-shadow: 0 0 0 1px var(--b3-theme-primary-lightest);
+ }
+ }
+
+ &__item-icon {
+ width: 18px;
+ height: 18px;
+ flex-shrink: 0;
+ margin-right: 10px;
+ color: var(--b3-theme-on-surface-light);
+ }
+
+ &__item-title {
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &__close {
+ width: 36px;
+ height: 36px;
+ padding: 8px;
+
+ svg {
+ width: 18px;
+ height: 18px;
+ }
+ }
+
+ &__actions {
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: 8px;
+ padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
+ border-top: 1px solid var(--b3-border-color);
+
+ .b3-button {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 6px;
+
+ svg {
+ width: 16px;
+ height: 16px;
+ }
+ }
+ }
}
.side-panel {
diff --git a/app/src/assets/template/mobile/index.tpl b/app/src/assets/template/mobile/index.tpl
index c40f5a77d6..6198831fff 100644
--- a/app/src/assets/template/mobile/index.tpl
+++ b/app/src/assets/template/mobile/index.tpl
@@ -19,6 +19,10 @@
<svg id="toolbarSync" class="toolbar__icon toolbar__icon-deactivate fn__none">
<use xlink:href="#iconCloudSucc"></use>
</svg>
+ <button id="toolbarTabs" class="toolbar__tabs" type="button">
+ <svg><use xlink:href="#iconLayoutGrid"></use></svg>
+ <span class="toolbar__tabs-count">0</span>
+ </button>
<svg id="toolbarMore" class="toolbar__icon">
<use xlink:href="#iconSettings"></use>
</svg>
diff --git a/app/src/config/tabs/fileTab.ts b/app/src/config/tabs/fileTab.ts
index 4a278236d0..7509a40483 100644
--- a/app/src/config/tabs/fileTab.ts
+++ b/app/src/config/tabs/fileTab.ts
@@ -70,18 +70,28 @@ const registerFileTreeBehaviorGroup = (tab: SettingTabBuilder) => {
title: window.siyuan.languages.noSplitScreenWhenOpenTab,
desc: window.siyuan.languages.noSplitScreenWhenOpenTabTip,
});
+};
+/// #endif
+
+const registerTabStartupGroup = (tab: SettingTabBuilder) => {
+ const group = tab.group("tabStartup", window.siyuan.languages.tabStartup);
group.number("fileTree.maxOpenTabCount", {
title: window.siyuan.languages.tabLimit,
desc: window.siyuan.languages.tabLimit1,
min: 1,
max: 32,
});
- group.switch("fileTree.closeTabsOnStart", {
- title: window.siyuan.languages.fileTree9,
- desc: window.siyuan.languages.fileTree10,
+ group.select("fileTree.tabStartupMode", {
+ title: window.siyuan.languages.tabStartupMode,
+ desc: window.siyuan.languages.tabStartupModeTip,
+ options: [
+ {value: 0, label: window.siyuan.languages.tabStartupRestore},
+ {value: 1, label: window.siyuan.languages.tabStartupNew},
+ {value: 2, label: window.siyuan.languages.tabStartupClose},
+ ],
+ save: (value) => fileConfigApi.patch("tabStartupMode", value),
});
};
-/// #endif
const registerFileNewDocumentGroup = (tab: SettingTabBuilder) => {
const group = tab.group("newDocument", window.siyuan.languages.configGroupNewDocument);
@@ -321,6 +331,7 @@ export const registerFileTab = (tab: SettingTabBuilder) => {
/// #if !MOBILE
registerFileTreeBehaviorGroup(tab);
/// #endif
+ registerTabStartupGroup(tab);
registerFileNewDocumentGroup(tab);
registerFileManagementGroup(tab);
registerFileOthersGroup(tab);
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 63fe8fbe74..0138d94a5d 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -157,6 +157,7 @@ export abstract class Constants {
public static readonly LOCAL_SEARCHASSET = "local-searchasset";
public static readonly LOCAL_SEARCHUNREF = "local-searchunref";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
+ public static readonly LOCAL_MOBILE_TABS = "local-mobile-tabs"; // only mobile
public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
public static readonly LOCAL_HISTORY = "local-history";
public static readonly LOCAL_CODELANG = "local-codelang"; // string
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index f6ef447ee0..7c4f77185c 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -473,26 +473,20 @@ export const JSONToCenter = (
export const JSONToLayout = (app: App, isStart: boolean) => {
JSONToCenter(app, window.siyuan.config.uiLayout.layout, undefined);
JSONToDock(window.siyuan.config.uiLayout, app);
- // 启动时不打开页签,需要移除没有钉住的页签
- if (window.siyuan.config.fileTree.closeTabsOnStart) {
- /// #if BROWSER
- if (!sessionStorage.getItem(Constants.LOCAL_SESSION_FIRSTLOAD)) {
- getAllTabs().forEach(item => {
- if (item.headElement && !item.headElement.classList.contains("item--pin")) {
- item.parent.removeTab(item.id, false, false, false);
- }
- });
- sessionStorage.setItem(Constants.LOCAL_SESSION_FIRSTLOAD, "true");
- }
- /// #else
- if (isStart) {
- getAllTabs().forEach(item => {
- if (item.headElement && !item.headElement.classList.contains("item--pin")) {
- item.parent.removeTab(item.id, false, false, false);
- }
- });
- }
- /// #endif
+ let applyTabStartupMode = isStart;
+ /// #if BROWSER
+ applyTabStartupMode = !sessionStorage.getItem(Constants.LOCAL_SESSION_FIRSTLOAD);
+ if (applyTabStartupMode) {
+ sessionStorage.setItem(Constants.LOCAL_SESSION_FIRSTLOAD, "true");
+ }
+ /// #endif
+ // 关闭已打开页签时保留钉住的页签
+ if (applyTabStartupMode && window.siyuan.config.fileTree.tabStartupMode === 2) {
+ getAllTabs().forEach(item => {
+ if (item.headElement && !item.headElement.classList.contains("item--pin")) {
+ item.parent.removeTab(item.id, false, false, false);
+ }
+ });
}
// 移除没有插件的 tab
document.querySelectorAll('li[data-type="tab-header"]').forEach((item: HTMLElement) => {
@@ -541,6 +535,15 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
},
});
} else {
+ if (applyTabStartupMode && window.siyuan.config.fileTree.tabStartupMode === 1) {
+ document.querySelectorAll('li[data-type="tab-header"][data-init-active="true"]').forEach((item) => {
+ item.removeAttribute("data-init-active");
+ });
+ const wnd = getWndByLayout(window.siyuan.layout.centerLayout);
+ if (wnd && !wnd.children.some((item) => !item.headElement)) {
+ wnd.addTab(newCenterEmptyTab(app), false, false);
+ }
+ }
let latestTabHeaderElement: HTMLElement;
document.querySelectorAll('li[data-type="tab-header"][data-init-active="true"]').forEach((item: HTMLElement) => {
if (!latestTabHeaderElement) {
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index da0b552d9c..7469024283 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -37,6 +37,7 @@ import {exportMarkdownZip} from "../protyle/export/exportMd";
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
/// #if MOBILE
import {openEmojiPanel} from "../emoji";
+import {openMobileFileByIdInNewTab} from "../mobile/editor";
/// #endif
const confirmEncryptedExport = (notebookId: string, callback: () => void) => {
@@ -492,6 +493,17 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
const id = liElement.getAttribute("data-node-id");
let name = liElement.getAttribute("data-name");
name = getDisplayName(name, false, true);
+ /// #if MOBILE
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "openInNewTab",
+ label: window.siyuan.languages.openInNewTab,
+ icon: "iconAdd",
+ click: () => {
+ openMobileFileByIdInNewTab(app, id, [Constants.CB_GET_SCROLL], undefined, notebookId);
+ }
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({id: "separator_open", type: "separator"}).element);
+ /// #endif
/// #if !MOBILE
if (window.siyuan.config.fileTree.parentDocClickExpand && Number(liElement.getAttribute("data-count")) > 0) {
window.siyuan.menus.menu.append(new MenuItem({
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index f0d146623d..3fb74aa5d8 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -9,7 +9,6 @@ import {highlightById, scrollCenter} from "../util/highlightById";
import {isInEmbedBlock} from "../protyle/util/hasClosest";
import {setEditMode} from "../protyle/util/setEditMode";
import {hideElements} from "../protyle/ui/hideElements";
-import {pushBack} from "./util/MobileBackFoward";
import {setStorageVal} from "../protyle/util/compatibility";
import {showMessage} from "../dialog/message";
import type {App} from "../index";
@@ -55,11 +54,14 @@ export const updateRecentDocSwitchTime = (update: TRecentDocUpdate) => {
});
};
-export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],
+export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],
scrollPosition?: ScrollLogicalPosition, notebookId?: string,
- afterOpen?: (protyle: IProtyle) => void, forceReload = false) => {
- window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
- setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
+ afterOpen?: (protyle: IProtyle) => void, forceReload = false,
+ isValid: () => boolean = () => true, signal?: AbortSignal,
+ scrollAttr?: IScrollAttr, updateRecent = true) => {
+ if (!isValid()) {
+ return;
+ }
const avPanelElement = document.querySelector(".av__panel");
if (avPanelElement && !avPanelElement.classList.contains("fn__none")) {
avPanelElement.dispatchEvent(new CustomEvent("click", {detail: "close"}));
@@ -82,7 +84,6 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
(action.includes(Constants.CB_GET_ALL) && (!protyle.block.showAll || protyle.block.id !== id)) ||
blockElement?.clientHeight === 0;
if (blockElement && !shouldReload) {
- pushBack();
if (action.includes(Constants.CB_GET_HL)) {
highlightById(protyle, id, scrollPosition);
} else {
@@ -91,7 +92,9 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
closePanel();
// 更新文档浏览时间
const rootID = protyle.block.rootID;
- updateRecentDocSwitchTime(createRecentDocUpdate(rootID, rootID));
+ if (updateRecent) {
+ updateRecentDocSwitchTime(createRecentDocUpdate(rootID, rootID));
+ }
afterOpen?.(protyle);
return;
}
@@ -103,6 +106,9 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
blockInfoParam.notebook = targetNotebookId;
}
fetchPost("/api/block/getBlockInfo", blockInfoParam, (data) => {
+ if (!isValid()) {
+ return;
+ }
if (data.code === 3) {
showMessage(data.msg);
return;
@@ -131,25 +137,36 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
actions: ["mp-wechat", "zhihu", "yuque"]
},
after: (editor) => {
- updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ if (!isValid()) {
+ return;
+ }
+ if (updateRecent) {
+ updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ }
afterOpen?.(editor.protyle);
},
};
if (window.siyuan.mobile.editor) {
window.siyuan.mobile.editor.protyle.notebookId = data.data.box;
window.siyuan.mobile.editor.protyle.title.element.removeAttribute("data-render");
- pushBack();
addLoading(window.siyuan.mobile.editor.protyle);
if (previousRootID !== data.data.rootID) {
window.siyuan.mobile.editor.protyle.wysiwyg.element.innerHTML = "";
}
- if (actionList.includes(Constants.CB_GET_SCROLL) && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID]) {
+ const targetScrollAttr = scrollAttr || window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID];
+ if (actionList.includes(Constants.CB_GET_SCROLL) && targetScrollAttr) {
getDocByScroll({
protyle: window.siyuan.mobile.editor.protyle,
- scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID],
+ scrollAttr: targetScrollAttr,
mergedOptions: protyleOptions,
+ signal,
cb() {
- updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ if (!isValid()) {
+ return;
+ }
+ if (updateRecent) {
+ updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ }
app.plugins.forEach(item => {
item.eventBus.emit("switch-protyle", {protyle: window.siyuan.mobile.editor.protyle});
});
@@ -166,20 +183,28 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
getDocParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
}
fetchPost("/api/filetree/getDoc", getDocParam, getResponse => {
+ if (!isValid()) {
+ return;
+ }
onGet({
data: getResponse,
protyle: window.siyuan.mobile.editor.protyle,
action: actionList,
scrollPosition,
afterCB() {
- updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ if (!isValid()) {
+ return;
+ }
+ if (updateRecent) {
+ updateRecentDocSwitchTime(createRecentDocUpdate(data.data.rootID, previousRootID));
+ }
app.plugins.forEach(item => {
item.eventBus.emit("switch-protyle", {protyle: window.siyuan.mobile.editor.protyle});
});
afterOpen?.(window.siyuan.mobile.editor.protyle);
}
});
- });
+ }, undefined, undefined, signal);
}
window.siyuan.mobile.editor.protyle.undo.clear();
// 切换文档后校准新文档的撤销镜像(语义 B:各文档栈隔离)
@@ -191,5 +216,33 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
}
setEditor();
closePanel();
- });
+ }, undefined, undefined, signal);
+};
+
+export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],
+ scrollPosition?: ScrollLogicalPosition, notebookId?: string,
+ afterOpen?: (protyle: IProtyle) => void, forceReload = false) => {
+ if (window.siyuan.mobile.tabs) {
+ const options = {action, scrollPosition, notebookId, afterOpen, forceReload};
+ if (action.includes(Constants.CB_GET_OPENNEW)) {
+ void window.siyuan.mobile.tabs.openInNewTab(id, options);
+ } else {
+ void window.siyuan.mobile.tabs.open(id, options);
+ }
+ return;
+ }
+ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
+ setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
+ loadMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen, forceReload);
+};
+
+export const openMobileFileByIdInNewTab = (app: App, id: string,
+ action: TProtyleAction[] = [Constants.CB_GET_HL],
+ scrollPosition?: ScrollLogicalPosition, notebookId?: string,
+ afterOpen?: (protyle: IProtyle) => void) => {
+ if (window.siyuan.mobile.tabs) {
+ void window.siyuan.mobile.tabs.openInNewTab(id, {action, scrollPosition, notebookId, afterOpen});
+ } else {
+ openMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen);
+ }
};
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 0b676a1ad6..eb47cc9b79 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -36,7 +36,6 @@ import {initRightMenu} from "./menu";
import {openChangelog} from "../boot/openChangelog";
import {registerServiceWorker} from "../util/serviceWorker";
import {loadPlugins} from "../plugin/loader";
-import {saveScroll} from "../protyle/scroll/saveScroll";
import {removeBlock} from "../protyle/wysiwyg/remove";
import {isNotEditBlock} from "../protyle/wysiwyg/getBlock";
import {updateCardHV} from "../card/util";
@@ -153,14 +152,10 @@ class App {
};
}
window.addEventListener("beforeunload", () => {
- if (window.siyuan.mobile.editor?.protyle) {
- saveScroll(window.siyuan.mobile.editor.protyle);
- }
+ window.siyuan.mobile.tabs?.save();
}, false);
window.addEventListener("pagehide", () => {
- if (window.siyuan.mobile.editor?.protyle) {
- saveScroll(window.siyuan.mobile.editor.protyle);
- }
+ window.siyuan.mobile.tabs?.save();
}, false);
// 判断手机横竖屏状态
window.matchMedia("(orientation:portrait)").addEventListener("change", () => {
diff --git a/app/src/mobile/tabs/MobileTabs.ts b/app/src/mobile/tabs/MobileTabs.ts
new file mode 100644
index 0000000000..5c29da76a9
--- /dev/null
+++ b/app/src/mobile/tabs/MobileTabs.ts
@@ -0,0 +1,558 @@
+import {Constants} from "../../constants";
+import type {App} from "../../index";
+import {saveScroll} from "../../protyle/scroll/saveScroll";
+import {setStorageVal} from "../../protyle/util/compatibility";
+import {escapeAttr, escapeHtml} from "../../util/escape";
+import {fetchPost} from "../../util/fetch";
+import {genUUID} from "../../util/genID";
+import {loadMobileFileById, updateRecentDocSwitchTime} from "../editor";
+import {openModel} from "../menu/model";
+import {closeModel} from "../util/closePanel";
+import {setEmpty} from "../util/setEmpty";
+
+const MAX_HISTORY = 32;
+
+export type MobileTabEntry = {
+ id: string;
+ rootID: string;
+ notebookID: string;
+ path: string;
+ title: string;
+ action: TProtyleAction[];
+ scroll?: IScrollAttr;
+};
+
+type MobileTab = {
+ id: string;
+ current?: MobileTabEntry;
+ backStack: MobileTabEntry[];
+ forwardStack: MobileTabEntry[];
+ activeAt: number;
+};
+
+type MobileTabsState = {
+ version: 1;
+ activeTabID?: string;
+ tabs: MobileTab[];
+};
+
+type OpenOptions = {
+ action?: TProtyleAction[];
+ scrollPosition?: ScrollLogicalPosition;
+ notebookId?: string;
+ afterOpen?: (protyle: IProtyle) => void;
+ forceReload?: boolean;
+ newTab?: boolean;
+ replace?: boolean;
+ scroll?: IScrollAttr;
+ tabID?: string;
+ recentPreviousRootID?: string;
+};
+
+const isEntry = (value: unknown): value is MobileTabEntry => {
+ const entry = value as MobileTabEntry;
+ return !!entry && typeof entry.id === "string" && typeof entry.rootID === "string" &&
+ typeof entry.notebookID === "string" && typeof entry.path === "string" &&
+ typeof entry.title === "string" && Array.isArray(entry.action);
+};
+
+const normalizeTab = (value: unknown): MobileTab | undefined => {
+ const tab = value as MobileTab;
+ if (!tab || typeof tab.id !== "string") {
+ return;
+ }
+ return {
+ id: tab.id,
+ current: isEntry(tab.current) ? tab.current : undefined,
+ backStack: Array.isArray(tab.backStack) ? tab.backStack.filter(isEntry).slice(-MAX_HISTORY) : [],
+ forwardStack: Array.isArray(tab.forwardStack) ? tab.forwardStack.filter(isEntry).slice(-MAX_HISTORY) : [],
+ activeAt: typeof tab.activeAt === "number" ? tab.activeAt : 0,
+ };
+};
+
+export class MobileTabs {
+ private state: MobileTabsState;
+ private navigationEpoch = 0;
+ private abortController?: AbortController;
+
+ constructor(private readonly app: App) {
+ const stored = window.siyuan.storage[Constants.LOCAL_MOBILE_TABS] as MobileTabsState | undefined;
+ const tabs = stored?.version === 1 && Array.isArray(stored.tabs) ?
+ stored.tabs.map(normalizeTab).filter((item): item is MobileTab => !!item) : [];
+ this.state = {
+ version: 1,
+ activeTabID: tabs.some((item) => item.id === stored?.activeTabID) ? stored.activeTabID : tabs[0]?.id,
+ tabs,
+ };
+ this.trimTabs();
+ this.persist();
+ this.updateCounter();
+ }
+
+ private get maxTabs() {
+ return Math.max(1, Math.min(32, window.siyuan.config.fileTree.maxOpenTabCount || 8));
+ }
+
+ private get activeTab() {
+ return this.state.tabs.find((item) => item.id === this.state.activeTabID);
+ }
+
+ private cancelNavigation() {
+ this.abortController?.abort();
+ this.navigationEpoch++;
+ }
+
+ private persist() {
+ window.siyuan.storage[Constants.LOCAL_MOBILE_TABS] = this.state;
+ setStorageVal(Constants.LOCAL_MOBILE_TABS, this.state);
+ }
+
+ private updateCounter() {
+ const countElement = document.querySelector("#toolbarTabs .toolbar__tabs-count");
+ if (countElement) {
+ countElement.textContent = this.state.tabs.length.toString();
+ }
+ }
+
+ private snapshot(tab = this.activeTab) {
+ if (!tab?.current || !window.siyuan.mobile.editor?.protyle) {
+ return;
+ }
+ const protyle = window.siyuan.mobile.editor.protyle;
+ if (protyle.block.rootID === tab.current.rootID) {
+ tab.current.scroll = saveScroll(protyle, true) as IScrollAttr | undefined;
+ tab.current.title = (document.getElementById("toolbarName") as HTMLInputElement)?.value || tab.current.title;
+ tab.current.id = protyle.block.showAll ? protyle.block.id : protyle.block.rootID;
+ tab.current.notebookID = protyle.notebookId;
+ tab.current.path = protyle.path;
+ tab.current.action = protyle.block.action;
+ }
+ }
+
+ private entryFromProtyle(id: string, action: TProtyleAction[], protyle: IProtyle): MobileTabEntry {
+ return {
+ id,
+ rootID: protyle.block.rootID,
+ notebookID: protyle.notebookId,
+ path: protyle.path,
+ title: (document.getElementById("toolbarName") as HTMLInputElement)?.value || window.siyuan.languages.untitled,
+ action,
+ scroll: saveScroll(protyle, true) as IScrollAttr | undefined,
+ };
+ }
+
+ private pushHistory(stack: MobileTabEntry[], entry?: MobileTabEntry) {
+ if (!entry) {
+ return;
+ }
+ stack.push({
+ ...entry,
+ action: [...entry.action],
+ scroll: entry.scroll ? {...entry.scroll} : undefined,
+ });
+ if (stack.length > MAX_HISTORY) {
+ stack.splice(0, stack.length - MAX_HISTORY);
+ }
+ }
+
+ private createTab(current?: MobileTabEntry) {
+ const tab: MobileTab = {
+ id: genUUID(),
+ current,
+ backStack: [],
+ forwardStack: [],
+ activeAt: Date.now(),
+ };
+ this.state.tabs.push(tab);
+ this.state.activeTabID = tab.id;
+ this.trimTabs();
+ return tab;
+ }
+
+ private trimTabs() {
+ while (this.state.tabs.length > this.maxTabs) {
+ const inactive = this.state.tabs
+ .filter((item) => item.id !== this.state.activeTabID)
+ .sort((a, b) => a.activeAt - b.activeAt)[0];
+ if (!inactive) {
+ break;
+ }
+ this.state.tabs.splice(this.state.tabs.indexOf(inactive), 1);
+ if (inactive.current?.rootID) {
+ fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: inactive.current.rootID});
+ }
+ }
+ }
+
+ private resolveRoot(id: string, notebookId?: string, signal?: AbortSignal) {
+ return new Promise<{rootID: string; box: string}>((resolve, reject) => {
+ signal?.addEventListener("abort", () => reject(new DOMException("Aborted", "AbortError")), {once: true});
+ const data: IObject = {id};
+ if (notebookId) {
+ data.notebook = notebookId;
+ }
+ fetchPost("/api/block/getBlockInfo", data, (response) => {
+ if (response.code === 0 && response.data?.rootID) {
+ resolve(response.data);
+ } else {
+ reject(new Error(response.msg));
+ }
+ }, undefined, undefined, signal);
+ });
+ }
+
+ async open(id: string, options: OpenOptions = {}) {
+ const action = options.action || [Constants.CB_GET_HL];
+ this.abortController?.abort();
+ const abortController = new AbortController();
+ this.abortController = abortController;
+ const epoch = ++this.navigationEpoch;
+ let info: {rootID: string; box: string};
+ try {
+ info = await this.resolveRoot(id, options.notebookId, abortController.signal);
+ } catch {
+ return abortController.signal.aborted;
+ }
+ if (epoch !== this.navigationEpoch) {
+ return true;
+ }
+
+ this.snapshot();
+ const activeBefore = this.activeTab;
+ let tab: MobileTab;
+ if (options.tabID) {
+ tab = this.state.tabs.find((item) => item.id === options.tabID);
+ } else if (!options.newTab) {
+ tab = [...this.state.tabs]
+ .filter((item) => item.current?.rootID === info.rootID)
+ .sort((a, b) => b.activeAt - a.activeAt)[0];
+ }
+ tab ||= this.activeTab;
+ const switchedExisting = !!tab && tab.id !== activeBefore?.id && !options.newTab;
+ const createOnSuccess = options.newTab || !tab;
+ if (createOnSuccess) {
+ tab = {
+ id: genUUID(),
+ backStack: [],
+ forwardStack: [],
+ activeAt: Date.now(),
+ };
+ }
+ const previous = tab.current;
+ const loadID = switchedExisting && previous ? previous.id : id;
+ const loadAction = switchedExisting ? [Constants.CB_GET_SCROLL] as TProtyleAction[] : action;
+ const loadScroll = switchedExisting ? previous?.scroll : options.scroll;
+ const shouldReplace = options.replace || switchedExisting || previous?.id === id;
+ const targetTabID = tab.id;
+ loadMobileFileById(this.app, loadID, loadAction, options.scrollPosition, info.box, (protyle) => {
+ if (epoch !== this.navigationEpoch || targetTabID !== tab.id) {
+ return;
+ }
+ if (!shouldReplace) {
+ this.pushHistory(tab.backStack, previous);
+ tab.forwardStack = [];
+ }
+ if (createOnSuccess) {
+ this.state.tabs.push(tab);
+ }
+ tab.current = this.entryFromProtyle(loadID, loadAction, protyle);
+ tab.activeAt = Date.now();
+ this.state.activeTabID = tab.id;
+ this.trimTabs();
+ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id: loadID};
+ setStorageVal(Constants.LOCAL_DOCINFO, {id: loadID});
+ this.persist();
+ this.updateCounter();
+ const previousRootID = options.recentPreviousRootID || previous?.rootID;
+ if (switchedExisting || previousRootID === protyle.block.rootID) {
+ updateRecentDocSwitchTime({type: "view", rootID: protyle.block.rootID});
+ } else if (previousRootID) {
+ updateRecentDocSwitchTime({
+ type: "switch",
+ rootID: protyle.block.rootID,
+ previousRootID,
+ });
+ } else {
+ updateRecentDocSwitchTime({type: "open", rootID: protyle.block.rootID});
+ }
+ options.afterOpen?.(protyle);
+ }, options.forceReload, () => epoch === this.navigationEpoch, abortController.signal, loadScroll, false);
+ return true;
+ }
+
+ openInNewTab(id: string, options: Omit<OpenOptions, "newTab"> = {}) {
+ return this.open(id, {...options, newTab: true});
+ }
+
+ async restore(): Promise<boolean> {
+ const tab = this.activeTab;
+ if (!tab) {
+ setEmpty(this.app);
+ return false;
+ }
+ tab.activeAt = Date.now();
+ if (!tab.current) {
+ setEmpty(this.app);
+ this.persist();
+ this.updateCounter();
+ return true;
+ }
+ const launched = await this.open(tab.current.id, {
+ action: [Constants.CB_GET_SCROLL],
+ notebookId: tab.current.notebookID,
+ forceReload: true,
+ replace: true,
+ scroll: tab.current.scroll,
+ tabID: tab.id,
+ });
+ if (!launched) {
+ this.state.tabs = this.state.tabs.filter((item) => item.id !== tab.id);
+ this.state.activeTabID = [...this.state.tabs].sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
+ this.persist();
+ this.updateCounter();
+ return this.restore();
+ }
+ return true;
+ }
+
+ createBlank() {
+ this.cancelNavigation();
+ this.snapshot();
+ this.createTab();
+ setEmpty(this.app);
+ this.persist();
+ this.updateCounter();
+ }
+
+ async switchTo(tabID: string) {
+ const tab = this.state.tabs.find((item) => item.id === tabID);
+ if (!tab || tab.id === this.state.activeTabID) {
+ closeModel();
+ return;
+ }
+ this.snapshot();
+ this.state.activeTabID = tab.id;
+ tab.activeAt = Date.now();
+ if (tab.current) {
+ await this.open(tab.current.id, {
+ action: [Constants.CB_GET_SCROLL],
+ notebookId: tab.current.notebookID,
+ forceReload: true,
+ replace: true,
+ scroll: tab.current.scroll,
+ tabID: tab.id,
+ });
+ } else {
+ this.cancelNavigation();
+ setEmpty(this.app);
+ this.persist();
+ this.updateCounter();
+ }
+ closeModel();
+ }
+
+ async goBack(): Promise<boolean> {
+ const tab = this.activeTab;
+ if (!tab?.backStack.length) {
+ return false;
+ }
+ this.snapshot(tab);
+ const target = tab.backStack.pop();
+ const previous = tab.current;
+ const previousRootID = tab.current?.rootID;
+ this.pushHistory(tab.forwardStack, tab.current);
+ tab.current = target;
+ this.persist();
+ const launched = await this.open(target.id, {
+ action: [Constants.CB_GET_SCROLL],
+ notebookId: target.notebookID,
+ forceReload: true,
+ replace: true,
+ scroll: target.scroll,
+ tabID: tab.id,
+ recentPreviousRootID: previousRootID,
+ });
+ if (!launched) {
+ tab.current = previous;
+ tab.forwardStack.pop();
+ this.persist();
+ return this.goBack();
+ }
+ return true;
+ }
+
+ async goForward(): Promise<boolean> {
+ const tab = this.activeTab;
+ if (!tab?.forwardStack.length) {
+ return false;
+ }
+ this.snapshot(tab);
+ const target = tab.forwardStack.pop();
+ const previous = tab.current;
+ const previousRootID = tab.current?.rootID;
+ this.pushHistory(tab.backStack, tab.current);
+ tab.current = target;
+ this.persist();
+ const launched = await this.open(target.id, {
+ action: [Constants.CB_GET_SCROLL],
+ notebookId: target.notebookID,
+ forceReload: true,
+ replace: true,
+ scroll: target.scroll,
+ tabID: tab.id,
+ recentPreviousRootID: previousRootID,
+ });
+ if (!launched) {
+ tab.current = previous;
+ tab.backStack.pop();
+ this.persist();
+ return this.goForward();
+ }
+ return true;
+ }
+
+ async close(tabID: string) {
+ const index = this.state.tabs.findIndex((item) => item.id === tabID);
+ if (index < 0) {
+ return;
+ }
+ const wasActive = this.state.activeTabID === tabID;
+ const closedRootID = this.state.tabs[index].current?.rootID;
+ this.state.tabs.splice(index, 1);
+ if (closedRootID) {
+ fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: closedRootID});
+ }
+ if (wasActive) {
+ const next = [...this.state.tabs].sort((a, b) => b.activeAt - a.activeAt)[0];
+ if (next?.current) {
+ this.state.activeTabID = undefined;
+ await this.switchTo(next.id);
+ } else {
+ this.state.activeTabID = next?.id;
+ setEmpty(this.app);
+ }
+ }
+ this.persist();
+ this.updateCounter();
+ if (wasActive) {
+ closeModel();
+ } else {
+ this.openOverview();
+ }
+ }
+
+ closeAll() {
+ this.cancelNavigation();
+ this.state.tabs.forEach((tab) => {
+ if (tab.current?.rootID) {
+ fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: tab.current.rootID});
+ }
+ });
+ this.state = {version: 1, tabs: []};
+ setEmpty(this.app);
+ this.persist();
+ this.updateCounter();
+ closeModel();
+ }
+
+ removeNotebook(notebookID: string) {
+ this.state.tabs.forEach((tab) => {
+ if (tab.current?.notebookID === notebookID) {
+ fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: tab.current.rootID});
+ }
+ });
+ this.filterEntries((entry) => entry.notebookID !== notebookID);
+ }
+
+ removeRoots(rootIDs: string[]) {
+ const roots = new Set(rootIDs);
+ this.state.tabs.forEach((tab) => {
+ if (tab.current && roots.has(tab.current.rootID)) {
+ fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: tab.current.rootID});
+ }
+ });
+ this.filterEntries((entry) => !roots.has(entry.rootID));
+ }
+
+ private filterEntries(predicate: (entry: MobileTabEntry) => boolean) {
+ this.state.tabs.forEach((tab) => {
+ tab.backStack = tab.backStack.filter(predicate);
+ tab.forwardStack = tab.forwardStack.filter(predicate);
+ });
+ this.state.tabs = this.state.tabs.filter((tab) => !tab.current || predicate(tab.current));
+ if (!this.state.tabs.some((tab) => tab.id === this.state.activeTabID)) {
+ this.state.activeTabID = [...this.state.tabs].sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
+ if (this.state.activeTabID) {
+ void this.restore();
+ } else {
+ setEmpty(this.app);
+ }
+ }
+ this.persist();
+ this.updateCounter();
+ }
+
+ save() {
+ this.snapshot();
+ this.persist();
+ }
+
+ pushCurrent() {
+ const tab = this.activeTab;
+ if (!tab?.current) {
+ return;
+ }
+ this.snapshot(tab);
+ this.pushHistory(tab.backStack, tab.current);
+ tab.forwardStack = [];
+ this.persist();
+ }
+
+ openOverview() {
+ const active = this.state.activeTabID;
+ const rows = this.state.tabs.map((tab) => `<div class="mobile-tabs__item${tab.id === active ? " mobile-tabs__item--active" : ""}" data-tab-id="${escapeAttr(tab.id)}">
+ <svg class="mobile-tabs__item-icon"><use xlink:href="#iconFile"></use></svg>
+ <span class="mobile-tabs__item-title">${escapeHtml(tab.current?.title || window.siyuan.languages.newTab)}</span>
+ <button class="b3-button b3-button--text mobile-tabs__close" data-action="close" aria-label="${escapeAttr(window.siyuan.languages.close)}">
+ <svg><use xlink:href="#iconClose"></use></svg>
+ </button>
+</div>`).join("");
+ const tab = this.activeTab;
+ openModel({
+ title: `${window.siyuan.languages.mobileTabs} ${this.state.tabs.length}`,
+ html: `<div class="mobile-tabs">
+ <div class="mobile-tabs__list">${rows || `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`}</div>
+ <div class="mobile-tabs__actions">
+ <button class="b3-button b3-button--outline" data-action="back"${tab?.backStack.length ? "" : " disabled"}><svg><use xlink:href="#iconLeft"></use></svg>${window.siyuan.languages.goBack}</button>
+ <button class="b3-button b3-button--outline" data-action="forward"${tab?.forwardStack.length ? "" : " disabled"}><svg><use xlink:href="#iconRight"></use></svg>${window.siyuan.languages.goForward}</button>
+ <button class="b3-button b3-button--outline" data-action="new"><svg><use xlink:href="#iconAdd"></use></svg>${window.siyuan.languages.newTab}</button>
+ <button class="b3-button b3-button--outline" data-action="close-all"${this.state.tabs.length ? "" : " disabled"}><svg><use xlink:href="#iconTrashcan"></use></svg>${window.siyuan.languages.closeAll}</button>
+ </div>
+</div>`,
+ bindEvent: (element) => {
+ element.addEventListener("click", (event) => {
+ const target = (event.target as HTMLElement).closest<HTMLElement>("[data-action], [data-tab-id]");
+ if (!target) {
+ return;
+ }
+ const action = target.dataset.action;
+ const tabID = target.closest<HTMLElement>("[data-tab-id]")?.dataset.tabId;
+ if (action === "close" && tabID) {
+ void this.close(tabID);
+ } else if (action === "back") {
+ void this.goBack().then(() => closeModel());
+ } else if (action === "forward") {
+ void this.goForward().then(() => closeModel());
+ } else if (action === "new") {
+ this.createBlank();
+ closeModel();
+ } else if (action === "close-all") {
+ this.closeAll();
+ } else if (tabID) {
+ void this.switchTo(tabID);
+ }
+ });
+ },
+ });
+ }
+}
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index a085e36ac3..36c0b2559d 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -1,169 +1,22 @@
-import {Constants} from "../../constants";
+import {showMessage} from "../../dialog/message";
import {hideElements} from "../../protyle/ui/hideElements";
-import {setEditMode} from "../../protyle/util/setEditMode";
-import {fetchPost} from "../../util/fetch";
-import {zoomOut} from "../../menus/protyle";
-import {processRender} from "../../protyle/util/processCode";
-import {highlightRender} from "../../protyle/render/highlightRender";
-import {blockRender} from "../../protyle/render/blockRender";
-import {disabledForeverProtyle, setReadonlyByConfig} from "../../protyle/util/onGet";
-import {setStorageVal} from "../../protyle/util/compatibility";
+import {getCurrentEditor} from "../editor";
import {closePanel} from "./closePanel";
-import {showMessage} from "../../dialog/message";
-import {createRecentDocUpdate, getCurrentEditor, updateRecentDocSwitchTime} from "../editor";
-import {avRender} from "../../protyle/render/av/render";
-import {setTitle} from "../../util/processTitle";
-import {isEncryptedBox} from "../../util/pathName";
-
-const forwardStack: IBackStack[] = [];
export const clearMobileBackForward = (notebookId?: string) => {
- if (!notebookId) {
+ if (notebookId) {
+ window.siyuan.mobile.tabs?.removeNotebook(notebookId);
+ } else {
window.siyuan.backStack = [];
- forwardStack.length = 0;
- return;
- }
- window.siyuan.backStack = window.siyuan.backStack.filter(item => item.data?.notebookId !== notebookId);
- for (let i = forwardStack.length - 1; i >= 0; i--) {
- if (forwardStack[i].data?.notebookId === notebookId) {
- forwardStack.splice(i, 1);
- }
}
};
-const focusStack = (backStack: IBackStack) => {
- const protyle = getCurrentEditor().protyle;
- const updateRecentDocTime = (previousRootID: string) => {
- updateRecentDocSwitchTime(createRecentDocUpdate(backStack.data.rootID, previousRootID));
- };
- // 前进后快速后退会导致滚动错位 https://ld246.com/article/1734018624070
- protyle.observerLoad?.disconnect();
-
- window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
- id: backStack.id,
- };
- setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
- hideElements(["toolbar", "hint", "util"], protyle);
- if (protyle.contentElement.classList.contains("fn__none")) {
- setEditMode(protyle, "wysiwyg");
- }
-
- protyle.notebookId = backStack.data.notebookId;
- protyle.path = backStack.data.path;
-
- if (backStack.data.startId === protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") &&
- backStack.data.endId === protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id")) {
- protyle.contentElement.scrollTo({
- top: backStack.scrollTop,
- behavior: "smooth"
- });
- return;
- }
-
- if (backStack.id !== protyle.block.rootID) {
- const docInfoParam: IObject = {
- id: backStack.id,
- };
- if (isEncryptedBox(protyle.notebookId)) {
- docInfoParam.notebook = protyle.notebookId;
- }
- fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
- setTitle(response.data.name);
- protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");
- protyle.background.render(response.data.ial, protyle.block.rootID);
- protyle.wysiwyg.renderCustom(response.data.ial);
- });
- }
- const exitFocusElement = protyle.breadcrumb.element.parentElement.querySelector('[data-type="exit-focus"]');
- if (backStack.zoomId) {
- if (backStack.zoomId !== protyle.block.id) {
- fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
- if (existResponse.data) {
- const previousRootID = protyle.block.rootID;
- zoomOut({
- protyle,
- id: backStack.id,
- isPushBack: false,
- callback: () => {
- updateRecentDocTime(previousRootID);
- protyle.contentElement.scrollTop = backStack.scrollTop;
- }
- });
- }
- });
- } else {
- updateRecentDocTime(protyle.block.rootID);
- protyle.contentElement.scrollTop = backStack.scrollTop;
- }
- exitFocusElement.classList.remove("fn__none");
- return;
- }
-
- const getDocParam: IObject = {
- id: backStack.id,
- startID: backStack.data.startId,
- endID: backStack.data.endId,
- };
- if (isEncryptedBox(protyle.notebookId)) {
- getDocParam.notebook = protyle.notebookId;
- }
- fetchPost("/api/filetree/getDoc", getDocParam, getResponse => {
- if (getResponse.code !== 0) {
- return;
- }
- const previousRootID = protyle.block.rootID;
- protyle.block.parentID = getResponse.data.parentID;
- protyle.block.parent2ID = getResponse.data.parent2ID;
- protyle.block.rootID = getResponse.data.rootID;
- protyle.block.showAll = false;
- protyle.block.mode = getResponse.data.mode;
- protyle.block.blockCount = getResponse.data.blockCount;
- protyle.block.id = getResponse.data.id;
- protyle.block.action = backStack.callback;
- protyle.wysiwyg.element.setAttribute("data-doc-type", getResponse.data.type);
- protyle.wysiwyg.element.innerHTML = getResponse.data.content;
- processRender(protyle.wysiwyg.element);
- highlightRender(protyle.wysiwyg.element);
- avRender(protyle.wysiwyg.element, protyle);
- blockRender(protyle, protyle.wysiwyg.element, backStack.scrollTop);
- protyle.databaseAttributePanel?.render();
- if (getResponse.data.isSyncing) {
- disabledForeverProtyle(protyle);
- } else {
- setReadonlyByConfig(protyle, true);
- }
- protyle.contentElement.scrollTop = backStack.scrollTop;
- // 等待 av 等加载 https://ld246.com/article/1734018624070
- setTimeout(() => {
- protyle.contentElement.scrollTop = backStack.scrollTop;
- }, Constants.TIMEOUT_LOAD);
-
- protyle.app.plugins.forEach(item => {
- item.eventBus.emit("switch-protyle", {protyle});
- item.eventBus.emit("loaded-protyle-static", {protyle});
- });
- updateRecentDocTime(previousRootID);
- exitFocusElement.classList.add("fn__none");
- });
+export const pushBack = () => {
+ window.siyuan.mobile.tabs?.pushCurrent();
};
-export const pushBack = () => {
- const protyle = getCurrentEditor().protyle;
- if (protyle.wysiwyg.element.firstElementChild) {
- window.siyuan.backStack.push({
- id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
- data: {
- startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
- endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
- notebookId: protyle.notebookId,
- path: protyle.path,
- rootID: protyle.block.rootID,
- },
- scrollTop: protyle.contentElement.scrollTop,
- callback: protyle.block.action,
- zoomId: protyle.block.showAll ? protyle.block.id : undefined
- });
- }
+export const goForward = () => {
+ void window.siyuan.mobile.tabs?.goForward();
};
export const goBack = () => {
@@ -195,38 +48,18 @@ export const goBack = () => {
closePanel();
return;
}
- if ((window.JSAndroid || window.JSHarmony) && window.siyuan.backStack.length < 1) {
+ void window.siyuan.mobile.tabs?.goBack().then((handled) => {
+ if (handled || !(window.JSAndroid || window.JSHarmony)) {
+ return;
+ }
if (document.querySelector('#message [data-id="exitTip"]')) {
if (window.JSAndroid) {
window.JSAndroid.returnDesktop();
- } else if (window.JSHarmony) {
+ } else {
window.JSHarmony.returnDesktop();
}
} else {
showMessage(window.siyuan.languages.returnDesktop, 3000, "info", "exitTip");
}
- return;
- }
- if (window.siyuan.backStack.length < 1) {
- return;
- }
- if (forwardStack.length === 0 && editor) {
- const protyle = editor.protyle;
- forwardStack.push({
- id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
- data: {
- startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
- endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
- notebookId: protyle.notebookId,
- path: protyle.path,
- rootID: protyle.block.rootID,
- },
- scrollTop: protyle.contentElement.scrollTop,
- callback: protyle.block.action,
- zoomId: protyle.block.showAll ? protyle.block.id : undefined
- });
- }
- const item = window.siyuan.backStack.pop();
- forwardStack.push(item);
- focusStack(item);
+ });
};
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index e9b32965b3..a0a6dffda3 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -26,6 +26,7 @@ import {Menu} from "../../plugin/Menu";
import {showMessage} from "../../dialog/message";
import {setTitle} from "../../util/processTitle";
import {activateQueuedAVLocate, queueAVLocateRequest} from "../../protyle/render/av/locate";
+import {MobileTabs} from "../tabs/MobileTabs";
let custom: MobileCustom;
const openDockMenu = (app: App) => {
@@ -171,7 +172,17 @@ export const initFramework = async (app: App, isStart: boolean) => {
document.getElementById("modelClose").addEventListener("click", () => {
closeModel();
});
+ window.siyuan.mobile.tabs = new MobileTabs(app);
+ const toolbarTabsElement = document.getElementById("toolbarTabs");
+ toolbarTabsElement.setAttribute("aria-label", window.siyuan.languages.mobileTabs);
+ toolbarTabsElement.addEventListener("click", () => {
+ activeBlur();
+ window.siyuan.mobile.tabs.openOverview();
+ });
initEditorName();
+ if (isStart && window.siyuan.config.fileTree.tabStartupMode === 2) {
+ window.siyuan.mobile.tabs.closeAll();
+ }
if (getOpenNotebookCount() > 0) {
if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {
return;
@@ -193,12 +204,18 @@ export const initFramework = async (app: App, isStart: boolean) => {
if (openMobileOnboarding(app)) {
return;
}
- if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
- setEmpty(app);
+ if (isStart && window.siyuan.config.fileTree.tabStartupMode === 1) {
+ window.siyuan.mobile.tabs.createBlank();
+ return;
+ }
+ if (isStart && window.siyuan.config.fileTree.tabStartupMode === 2) {
+ return;
+ }
+ if (await window.siyuan.mobile.tabs.restore()) {
return;
}
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
- fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
+ fetchPost("/api/block/checkBlockExist", {id: localDoc?.id}, existResponse => {
if (existResponse.data) {
openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL]);
} else {
@@ -215,7 +232,11 @@ export const initFramework = async (app: App, isStart: boolean) => {
});
return;
}
- setEmpty(app);
+ if (isStart && window.siyuan.config.fileTree.tabStartupMode === 1) {
+ window.siyuan.mobile.tabs.createBlank();
+ } else {
+ setEmpty(app);
+ }
};
const initEditorName = () => {
diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts
index 8c066f28a2..1b789587dc 100644
--- a/app/src/mobile/util/onMessage.ts
+++ b/app/src/mobile/util/onMessage.ts
@@ -12,9 +12,7 @@ import {reloadEmoji} from "../../emoji";
import {renderSnippet} from "../../config/util/snippets";
import {redirectToCheckAuth} from "../../util/pathName";
import {reloadSync} from "../../util/reloadSync";
-import {setEmpty} from "./setEmpty";
import {activateOnboarding} from "../../onboarding";
-import {clearMobileBackForward} from "./MobileBackFoward";
let statusTimeout: number;
const statusElement = document.querySelector("#status") as HTMLElement;
@@ -78,20 +76,14 @@ export const onMessage = (app: App, data: IWebSocketData) => {
break;
case "closeBox":
case "removeBox": {
- const closesCurrentEditor = window.siyuan.mobile.editor?.protyle.notebookId === data.data.box;
- clearMobileBackForward(closesCurrentEditor ? undefined : data.data.box);
- if (closesCurrentEditor) {
- window.siyuan.mobile.editor.destroy();
- window.siyuan.mobile.editor.protyle.element.innerHTML = "";
- window.siyuan.mobile.editor = undefined;
- setEmpty(app);
- }
+ window.siyuan.mobile.tabs?.removeNotebook(data.data.box);
break;
}
case "onboarding":
void activateOnboarding(app, data.data);
break;
case "removeDoc":
+ window.siyuan.mobile.tabs?.removeRoots(data.data.ids);
if (window.siyuan.config.onboarding?.newUser && !window.siyuan.config.onboarding.dismissed &&
data.data.ids.includes(window.siyuan.config.onboarding.documentID)) {
void activateOnboarding(app, window.siyuan.config.onboarding);
diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts
index 5d4860bb3a..39133e4dfc 100644
--- a/app/src/protyle/scroll/saveScroll.ts
+++ b/app/src/protyle/scroll/saveScroll.ts
@@ -66,7 +66,8 @@ export const getDocByScroll = (options: {
mergedOptions?: IProtyleOptions,
cb?: (keys: string[]) => void
focus?: boolean,
- updateReadonly?: boolean
+ updateReadonly?: boolean,
+ signal?: AbortSignal
}) => {
let actions: TProtyleAction[] = [];
if (options.mergedOptions) {
@@ -116,7 +117,7 @@ export const getDocByScroll = (options: {
} : undefined,
updateReadonly: options.updateReadonly
});
- });
+ }, undefined, undefined, options.signal);
} else {
actions.push(Constants.CB_GET_ALL);
onGet({
@@ -131,7 +132,7 @@ export const getDocByScroll = (options: {
updateReadonly: options.updateReadonly
});
}
- });
+ }, undefined, undefined, options.signal);
return;
}
const getDocParam: Record<string, any> = {
@@ -159,5 +160,5 @@ export const getDocByScroll = (options: {
} : undefined,
updateReadonly: options.updateReadonly
});
- });
+ }, undefined, undefined, options.signal);
};
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 53a688b1fb..27d971c520 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -557,6 +557,10 @@ export const getLocalStorage = (cb: () => void) => {
defaultStorage[Constants.LOCAL_DOCINFO] = {
id: "",
};
+ defaultStorage[Constants.LOCAL_MOBILE_TABS] = {
+ version: 1,
+ tabs: [],
+ };
defaultStorage[Constants.LOCAL_IMAGES] = {
file: "1f4c4",
note: "1f5c3",
@@ -588,7 +592,8 @@ export const getLocalStorage = (cb: () => void) => {
defaultStorage[Constants.LOCAL_RECENT_DOCS] = {type: "viewedAt"}; // TRecentDocsSort
[Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR,
- Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES,
+ Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_MOBILE_TABS,
+ Constants.LOCAL_FONTSTYLES,
Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI,
Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD,
Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF, Constants.LOCAL_HISTORY,
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index bcd203932b..79450c9cd8 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -807,6 +807,7 @@ declare namespace Config {
* Whether to close all tabs when starting
*/
closeTabsOnStart: boolean;
+ tabStartupMode: 0 | 1 | 2;
/**
* The storage path of the new document
*/
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 4a9551f779..355f2c4f9a 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -578,6 +578,7 @@ interface ISiyuan {
}
editor?: import("../protyle").Protyle
popEditor?: import("../protyle").Protyle
+ tabs?: import("../mobile/tabs/MobileTabs").MobileTabs
docks?: {
outline: import("../mobile/dock/MobileOutline").MobileOutline | null,
file: import("../mobile/dock/MobileFiles").MobileFiles | null,
diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.ts
index 35bd8981e3..02eb664f86 100644
--- a/app/src/util/reloadSync.ts
+++ b/app/src/util/reloadSync.ts
@@ -32,8 +32,11 @@ export const reloadSync = (
}
if (document.getElementById("empty").classList.contains("fn__none") &&
window.siyuan.mobile.editor && window.siyuan.mobile.editor.protyle) {
+ window.siyuan.mobile.tabs?.removeRoots(data.removeRootIDs);
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
- setEmpty(app);
+ if (!window.siyuan.mobile.tabs) {
+ setEmpty(app);
+ }
} else {
window.siyuan.mobile.editor.reload(false, updateReadonly);
const docInfoParam: IObject = {
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 002c63cc73..28408499bc 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -566,6 +566,16 @@ func setFiletree(c *gin.Context) {
if 32 < fileTree.MaxOpenTabCount {
fileTree.MaxOpenTabCount = 32
}
+ if nil == fileTree.TabStartupMode {
+ fileTree.TabStartupMode = new(int)
+ if fileTree.CloseTabsOnStart {
+ *fileTree.TabStartupMode = 2
+ }
+ }
+ if 0 > *fileTree.TabStartupMode || 2 < *fileTree.TabStartupMode {
+ *fileTree.TabStartupMode = 0
+ }
+ fileTree.CloseTabsOnStart = 2 == *fileTree.TabStartupMode
if conf.MinFileTreeRecentDocsListCount > fileTree.RecentDocsMaxListCount {
fileTree.RecentDocsMaxListCount = conf.MinFileTreeRecentDocsListCount
diff --git a/kernel/conf/filetree.go b/kernel/conf/filetree.go
index 01a882d6b6..6e700f1587 100644
--- a/kernel/conf/filetree.go
+++ b/kernel/conf/filetree.go
@@ -38,6 +38,7 @@ type FileTree struct {
AllowCreateDeeper bool `json:"allowCreateDeeper"` // 允许创建超过 7 层深度的子文档
RemoveDocWithoutConfirm bool `json:"removeDocWithoutConfirm"` // 删除文档时是否不需要确认
CloseTabsOnStart bool `json:"closeTabsOnStart"` // 启动时关闭所有页签
+ TabStartupMode *int `json:"tabStartupMode"` // 页签启动策略:0 恢复,1 新建空白页签,2 关闭已打开页签
UseSingleLineSave bool `json:"useSingleLineSave"` // 使用单行保存文档 .sy 和属性视图 .json
LargeFileWarningSize int `json:"largeFileWarningSize"` // 大文件警告大小(单位:MB)
CreateDocAtTop *bool `json:"createDocAtTop"` // 在顶部创建新文档 https://github.com/siyuan-note/siyuan/issues/16327
@@ -58,6 +59,7 @@ func NewFileTree() *FileTree {
MaxOpenTabCount: 8,
AllowCreateDeeper: false,
CloseTabsOnStart: false,
+ TabStartupMode: new(int),
UseSingleLineSave: util.UseSingleLineSave,
LargeFileWarningSize: util.LargeFileWarningSize,
CreateDocAtTop: new(bool),
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index fd4f003315..ca33927fc2 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -323,6 +323,16 @@ func InitConf() {
if 32 < Conf.FileTree.MaxOpenTabCount {
Conf.FileTree.MaxOpenTabCount = 32
}
+ if nil == Conf.FileTree.TabStartupMode {
+ Conf.FileTree.TabStartupMode = new(int)
+ if Conf.FileTree.CloseTabsOnStart {
+ *Conf.FileTree.TabStartupMode = 2
+ }
+ }
+ if 0 > *Conf.FileTree.TabStartupMode || 2 < *Conf.FileTree.TabStartupMode {
+ *Conf.FileTree.TabStartupMode = 0
+ }
+ Conf.FileTree.CloseTabsOnStart = 2 == *Conf.FileTree.TabStartupMode
Conf.FileTree.DocCreateSavePath = util.TrimSpaceInPath(Conf.FileTree.DocCreateSavePath)
Conf.FileTree.DocCreateTemplatePath = util.NormalizeTemplatePath(Conf.FileTree.DocCreateTemplatePath)
Conf.FileTree.RefCreateSavePath = util.TrimSpaceInPath(Conf.FileTree.RefCreateSavePath)