11import { confirmDialog } from "../dialog/confirmDialog" ;
22import { genNotebookOption } from "../menus/onGetnotebookconf" ;
33import { fetchPost } from "../util/fetch" ;
4- import type { SettingBindApi , SettingRow , SettingSection } from "./ui/types" ;
4+ import {
5+ customRow ,
6+ findSettingRowByControlId ,
7+ notebookSavePathRow ,
8+ numberRow ,
9+ switchRow ,
10+ type SettingBindApi ,
11+ type SettingSection ,
12+ } from "./ui/settingRows" ;
513import { filterSettingSections } from "./ui/search" ;
614import { renderSettingTabHtmlFromSections } from "./ui/render" ;
7- import { readDomValueFromEl } from "./ui/formValue" ;
15+ import { readDomValue } from "./ui/formValue" ;
816import { mergeRecordByDottedPath } from "./ui/dotPath" ;
9- import { mountScheduleSettingSave } from "./ui/save" ;
17+ import { mountSettingSaveHandlers } from "./ui/save" ;
1018
1119export const file = {
1220 /**
@@ -17,25 +25,20 @@ export const file = {
1725 mount : async ( root : HTMLElement , searchQuery ?: string ) => {
1826 const sections = filterSettingSections ( buildFileSections ( ) , searchQuery ) ;
1927 root . innerHTML = renderSettingTabHtmlFromSections ( sections ) ;
20- await mountScheduleSettingSave ( root , sections ) ;
28+ await mountSettingSaveHandlers ( root , sections ) ;
2129 } ,
2230
2331 /** 从 DOM 读出 `controlId` 对应值 → `send`;无有效值时不请求 */
24- set ( root : HTMLElement , controlId : string ) {
32+ set ( root : HTMLElement , controlId : string , sections : SettingSection [ ] ) {
2533 if ( ! controlId . startsWith ( "fileTree." ) ) {
2634 return ;
2735 }
28- const rel = controlId . slice ( "fileTree." . length ) ;
2936 const el = root . querySelector < HTMLElement > ( `[id="${ CSS . escape ( controlId ) } "]` ) ;
3037 if ( ! el ) {
3138 return ;
3239 }
33- let value : unknown ;
34- if ( el instanceof HTMLSelectElement && / S a v e B o x $ / . test ( rel ) ) {
35- value = el . value ;
36- } else {
37- value = readDomValueFromEl ( el ) ;
38- }
40+ const row = findSettingRowByControlId ( sections , controlId ) ;
41+ const value = readDomValue ( el , row ) ;
3942 if ( value !== undefined ) {
4043 file . send ( controlId , value ) ;
4144 }
@@ -80,129 +83,76 @@ export function buildFileSections(): SettingSection[] {
8083 {
8184 title : window . siyuan . languages . configGroupTabs ,
8285 items : [
83- {
84- type : "switch" ,
86+ switchRow ( {
8587 id : "fileTree.alwaysSelectOpenedFile" ,
8688 title : window . siyuan . languages . selectOpen ,
8789 desc : window . siyuan . languages . fileTree2 ,
88- } ,
89- {
90- type : "switch" ,
90+ } ) ,
91+ switchRow ( {
9192 id : "fileTree.openFilesUseCurrentTab" ,
9293 title : window . siyuan . languages . fileTree7 ,
9394 desc : window . siyuan . languages . fileTree8 ,
94- } ,
95- {
96- type : "switch" ,
95+ } ) ,
96+ switchRow ( {
9797 id : "fileTree.noSplitScreenWhenOpenTab" ,
9898 title : window . siyuan . languages . noSplitScreenWhenOpenTab ,
9999 desc : window . siyuan . languages . noSplitScreenWhenOpenTabTip ,
100- } ,
101- {
102- type : "number" ,
100+ } ) ,
101+ numberRow ( {
103102 id : "fileTree.maxOpenTabCount" ,
104103 min : 1 ,
105104 max : 32 ,
106105 title : window . siyuan . languages . tabLimit ,
107106 desc : window . siyuan . languages . tabLimit1 ,
108- } ,
109- {
110- type : "switch" ,
107+ } ) ,
108+ switchRow ( {
111109 id : "fileTree.closeTabsOnStart" ,
112110 title : window . siyuan . languages . fileTree9 ,
113111 desc : window . siyuan . languages . fileTree10 ,
114- } ,
112+ } ) ,
115113 ] ,
116114 } ,
117115 {
118116 title : window . siyuan . languages . configGroupNewDocument ,
119117 items : [
120- {
121- type : "switch" ,
118+ switchRow ( {
122119 id : "fileTree.createDocAtTop" ,
123120 title : window . siyuan . languages . fileTree24 ,
124121 desc : window . siyuan . languages . fileTree25 ,
125- } ,
126- {
127- type : "custom" ,
128- keywords : [ window . siyuan . languages . fileTree12 , window . siyuan . languages . fileTree13 ] ,
129- html : ( ) => `<div class="b3-label config__item">
130- ${ window . siyuan . languages . fileTree12 }
131- <div class="b3-label__text">${ window . siyuan . languages . fileTree13 } </div>
132- <span class="fn__hr"></span>
133- <div class="fn__flex">
134- <select style="min-width: 200px" class="b3-select" id="fileTree.docCreateSaveBox">${ genNotebookOption ( window . siyuan . config . fileTree . docCreateSaveBox ) } </select>
135- <div class="fn__space"></div>
136- <input class="b3-text-field fn__flex-1" id="fileTree.docCreateSavePath" value="">
137- </div>
138- </div>` ,
139- bind : async ( api : SettingBindApi ) => {
140- const el = api . root . querySelector < HTMLInputElement > (
141- `[id="${ CSS . escape ( "fileTree.docCreateSavePath" ) } "]`
142- ) ;
143- if ( el ) {
144- el . value = window . siyuan . config . fileTree . docCreateSavePath ;
145- }
146- } ,
147- } ,
148- {
149- type : "custom" ,
150- keywords : [ window . siyuan . languages . fileTree5 , window . siyuan . languages . fileTree6 ] ,
151- html : ( ) => `<div class="b3-label config__item">
152- ${ window . siyuan . languages . fileTree5 }
153- <div class="b3-label__text">${ window . siyuan . languages . fileTree6 } </div>
154- <span class="fn__hr"></span>
155- <div class="fn__flex">
156- <select style="min-width: 200px" class="b3-select" id="fileTree.refCreateSaveBox">${ genNotebookOption ( window . siyuan . config . fileTree . refCreateSaveBox ) } </select>
157- <div class="fn__space"></div>
158- <input class="b3-text-field fn__flex-1" id="fileTree.refCreateSavePath" value="${ window . siyuan . config . fileTree . refCreateSavePath } ">
159- </div>
160- </div>` ,
161- bind : async ( api : SettingBindApi ) => {
162- const el = api . root . querySelector < HTMLInputElement > (
163- `[id="${ CSS . escape ( "fileTree.refCreateSavePath" ) } "]`
164- ) ;
165- if ( el ) {
166- el . value = window . siyuan . config . fileTree . refCreateSavePath ;
167- }
168- } ,
169- } ,
170- ...( isMobileKernelContainer ( )
171- ? ( [
172- {
173- type : "custom" as const ,
174- keywords : [
175- window . siyuan . languages . fileTree26 ,
176- window . siyuan . languages . fileTree27 ,
177- ] ,
178- html : ( ) => `<div class="b3-label config__item">
179- ${ window . siyuan . languages . fileTree26 }
180- <div class="b3-label__text">${ window . siyuan . languages . fileTree27 } </div>
181- <span class="fn__hr"></span>
182- <div class="fn__flex">
183- <select style="min-width: 200px" class="b3-select" id="fileTree.shorthandSaveBox">${ genNotebookOption ( window . siyuan . config . fileTree . shorthandSaveBox , undefined , true ) } </select>
184- <div class="fn__space"></div>
185- <input class="b3-text-field fn__flex-1" id="fileTree.shorthandSavePath" value="${ window . siyuan . config . fileTree . shorthandSavePath } ">
186- </div>
187- </div>` ,
188- bind : async ( api : SettingBindApi ) => {
189- const el = api . root . querySelector < HTMLInputElement > (
190- `[id="${ CSS . escape ( "fileTree.shorthandSavePath" ) } "]`
191- ) ;
192- if ( el ) {
193- el . value = window . siyuan . config . fileTree . shorthandSavePath ;
194- }
195- } ,
196- } ,
197- ] as SettingRow [ ] )
198- : [ ] ) ,
122+ } ) ,
123+ notebookSavePathRow ( {
124+ title : window . siyuan . languages . fileTree12 ,
125+ desc : window . siyuan . languages . fileTree13 ,
126+ selectId : "fileTree.docCreateSaveBox" ,
127+ pathId : "fileTree.docCreateSavePath" ,
128+ getOptionsHtml : ( ) => genNotebookOption ( window . siyuan . config . fileTree . docCreateSaveBox ) ,
129+ getPathValue : ( ) => window . siyuan . config . fileTree . docCreateSavePath ,
130+ } ) ,
131+ notebookSavePathRow ( {
132+ title : window . siyuan . languages . fileTree5 ,
133+ desc : window . siyuan . languages . fileTree6 ,
134+ selectId : "fileTree.refCreateSaveBox" ,
135+ pathId : "fileTree.refCreateSavePath" ,
136+ getOptionsHtml : ( ) => genNotebookOption ( window . siyuan . config . fileTree . refCreateSaveBox ) ,
137+ getPathValue : ( ) => window . siyuan . config . fileTree . refCreateSavePath ,
138+ } ) ,
139+ ...( isMobileKernelContainer ( ) ? [ ] : [
140+ notebookSavePathRow ( {
141+ title : window . siyuan . languages . fileTree26 ,
142+ desc : window . siyuan . languages . fileTree27 ,
143+ selectId : "fileTree.shorthandSaveBox" ,
144+ pathId : "fileTree.shorthandSavePath" ,
145+ getOptionsHtml : ( ) =>
146+ genNotebookOption ( window . siyuan . config . fileTree . shorthandSaveBox , undefined , true ) ,
147+ getPathValue : ( ) => window . siyuan . config . fileTree . shorthandSavePath ,
148+ } )
149+ ] ) ,
199150 ] ,
200151 } ,
201152 {
202153 title : window . siyuan . languages . configGroupFileManagement ,
203154 items : [
204- {
205- type : "custom" ,
155+ customRow ( {
206156 keywords : [
207157 window . siyuan . languages . generateHistory ,
208158 window . siyuan . languages . generateHistoryInterval ,
@@ -251,62 +201,49 @@ export function buildFileSections(): SettingSection[] {
251201 ) ;
252202 } ) ;
253203 } ,
254- } ,
255- {
256- type : "number" ,
204+ } ) ,
205+ numberRow ( {
257206 id : "fileTree.maxListCount" ,
258207 min : 1 ,
259208 max : 10240 ,
260209 title : window . siyuan . languages . fileTree16 ,
261210 desc : window . siyuan . languages . fileTree17 ,
262- } ,
263- {
264- type : "custom" ,
265- keywords : [ window . siyuan . languages . fileTree22 , window . siyuan . languages . fileTree23 ] ,
266- html : ( ) => `<div class="fn__flex b3-label config__item">
267- <div class="fn__flex-1">
268- ${ window . siyuan . languages . fileTree22 }
269- <div class="b3-label__text">${ window . siyuan . languages . fileTree23 } </div>
270- </div>
271- <span class="fn__space"></span>
272- <div class="fn__size200 fn__flex-center fn__flex">
273- <input class="b3-text-field fn__flex-1" id="fileTree.largeFileWarningSize" type="number" min="2" max="10240" value="${ window . siyuan . config . fileTree . largeFileWarningSize } ">
274- <span class="fn__space"></span>
275- <span class="ft__on-surface fn__flex-center">MB</span>
276- </div>
277- </div>` ,
278- } ,
279- {
280- type : "switch" ,
211+ } ) ,
212+ numberRow ( {
213+ id : "fileTree.largeFileWarningSize" ,
214+ min : 2 ,
215+ max : 10240 ,
216+ unit : "MB" ,
217+ title : window . siyuan . languages . fileTree22 ,
218+ desc : window . siyuan . languages . fileTree23 ,
219+ } ) ,
220+ switchRow ( {
281221 id : "fileTree.allowCreateDeeper" ,
282222 title : window . siyuan . languages . fileTree18 ,
283223 desc : window . siyuan . languages . fileTree19 ,
284- } ,
285- {
286- type : "switch" ,
224+ } ) ,
225+ switchRow ( {
287226 id : "fileTree.useSingleLineSave" ,
288227 title : window . siyuan . languages . fileTree20 ,
289228 desc : window . siyuan . languages . fileTree21 ,
290- } ,
291- {
292- type : "switch" ,
229+ } ) ,
230+ switchRow ( {
293231 id : "fileTree.removeDocWithoutConfirm" ,
294232 title : window . siyuan . languages . fileTree3 ,
295233 desc : window . siyuan . languages . fileTree4 ,
296- } ,
234+ } ) ,
297235 ] ,
298236 } ,
299237 {
300238 title : window . siyuan . languages . configGroupOthers ,
301239 items : [
302- {
303- type : "number" ,
240+ numberRow ( {
304241 id : "fileTree.recentDocsMaxListCount" ,
305242 min : 32 ,
306243 max : 256 ,
307244 title : window . siyuan . languages . recentDocsMaxListCount ,
308245 desc : window . siyuan . languages . recentDocsMaxListCountTip ,
309- } ,
246+ } ) ,
310247 ] ,
311248 } ,
312249 ] ;
0 commit comments