Repository navigation
Expand file tree
/
Copy pathui.html
More file actions
2528 lines (2488 loc) · 181 KB
/
Copy pathui.html
File metadata and controls
2528 lines (2488 loc) · 181 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nav Tool</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><defs><linearGradient id='g' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%23635bff'/><stop offset='1' stop-color='%234f46e5'/></linearGradient></defs><rect width='24' height='24' rx='5.3' fill='url(%23g)'/><g fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' transform='translate(2.2 2.2) scale(.82)'><path d='M4 6h16M4 12h10M4 18h7'/><path d='M15 15l2 2 3.5-4.5'/></g></svg>">
<script>
// тема ставится до отрисовки, чтобы не мигало: сохраненный выбор или тема Windows
(function () {
var th = null;
try { th = localStorage.getItem("navtool.theme"); } catch (e) {}
if (th !== "dark" && th !== "light") th = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
document.documentElement.dataset.theme = th;
})();
</script>
<style>
:root {
--bg: #f3f4f8; --surface: #fff; --surface2: #f8f9fb; --border: #e3e6ec; --text: #161b26; --muted: #667085;
--accent: #4f46e5; --accent-weak: #eef0ff; --accent-text: #fff;
--green: #12805c; --green-weak: #e6f6ee; --red: #c0392b; --red-weak: #fdecea; --amber: #b54708; --amber-weak: #fff4e5;
--shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06); --code: #f6f7f9;
}
:root[data-theme="dark"] {
color-scheme: dark;
--bg: #0f1117; --surface: #171a22; --surface2: #1c2029; --border: #2a2f3b; --text: #e7e9ee; --muted: #9098aa;
--accent: #8b85ff; --accent-weak: #25244a; --accent-text: #0f1117;
--green: #4fd39a; --green-weak: #16302a; --red: #ff8578; --red-weak: #3a1f1d; --amber: #f5b14c; --amber-weak: #35291a;
--shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); --code: #12151c;
}
/* переключатель темы: светлая - серая дорожка и белый кружок, темная - зеленая дорожка и черный кружок */
.theme-sw { position: relative; width: 56px; height: 30px; border-radius: 99px; border: 2px solid #d4d6db; padding: 0; cursor: pointer; flex: none;
background: linear-gradient(90deg, #f1f2f4, #c9cbd0); transition: background .25s, border-color .25s; }
.theme-sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .25s, background .25s; }
.theme-sw.dark { background: linear-gradient(90deg, #b6f7a4, #39e639); border-color: #2bd92b; }
.theme-sw.dark::after { left: 28px; background: radial-gradient(circle at 35% 35%, #555, #000 70%); }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.i { width: 16px; height: 16px; flex: none; }
button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover:not(:disabled) { background: var(--accent-weak); border-color: transparent; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.big { padding: 10px 18px; font-size: 15px; }
input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); outline: none; }
input[type=text]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; flex: none; }
label.fl { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.card-head h2 { margin: 0; font-size: 15px; }
.card-body { padding: 0 16px 16px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--accent-weak); color: var(--accent); font-weight: 600; white-space: nowrap; }
.pill.warn { background: var(--amber-weak); color: var(--amber); }
.pill.ok { background: var(--green-weak); color: var(--green); }
.opill { margin-left: 6px; padding: 1px 7px; font-size: 11px; flex: none; }
.opill svg { width: 11px; height: 11px; }
.pill.grey { background: var(--surface2); color: var(--muted); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; }
/* ---------- выбор папки ---------- */
#pick { min-height: 100vh; display: flex; justify-content: center; padding: 48px 16px; }
.pick-wrap { width: 100%; max-width: 820px; }
.pick-wrap h1 { font-size: 26px; margin: 28px 0 4px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 18px 0 22px; }
.rcard { text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 12px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); white-space: normal; }
.rcard b { font-size: 14px; }
.rcard .p { font-size: 12px; color: var(--muted); word-break: break-all; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 0; }
.browser { overflow: hidden; }
.br-top { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.br-top button { padding: 4px 10px; font-size: 13px; }
.br-path { display: flex; align-items: center; gap: 4px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.crumb { padding: 2px 6px; border-radius: 6px; cursor: pointer; }
.crumb:hover { background: var(--accent-weak); }
.br-list { max-height: 46vh; overflow: auto; }
.br-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.br-item:hover { background: var(--accent-weak); }
.br-item.mk { background: var(--green-weak); }
.br-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.br-foot { display: flex; gap: 8px; padding: 12px 14px; align-items: center; background: var(--surface2); flex-wrap: wrap; }
.br-foot input { flex: 1; min-width: 200px; }
/* ---------- приложение ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.proj { flex-direction: column; align-items: flex-start; gap: 0; padding: 4px 10px; max-width: 46vw; min-width: 0; overflow: hidden; }
.proj .pn { font-weight: 700; }
.ver { font-size: 11px; color: var(--muted); background: var(--surface2); border: 1px solid var(--border); border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.ver:empty { display: none; }
.proj .pp { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.grid { display: grid; grid-template-columns: minmax(0, var(--lw, 53%)) 16px minmax(0, 1fr); padding: 16px 18px 40px; align-items: start; }
@media (max-width: 980px) { .grid { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 12px; } .tree-card { position: static !important; height: 70vh !important; } .grid > .split { display: none; } }
.split { align-self: stretch; cursor: col-resize; position: relative; touch-action: none; user-select: none; }
.split::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; border-radius: 2px; background: transparent; transition: background .15s; }
.split::after { content: ""; position: sticky; top: 45vh; display: block; margin: 0 auto; width: 6px; height: 44px; border-radius: 4px; background: var(--border); transition: background .15s; }
.split:hover::before, .split.drag::before { background: var(--accent); }
.split:hover::after, .split.drag::after { background: var(--accent); }
body.dragging, body.dragging * { cursor: col-resize !important; user-select: none !important; }
.tree-card { position: sticky; top: 72px; height: calc(100vh - 90px); display: flex; flex-direction: column; }
.tree-tools { display: flex; gap: 8px; padding: 0 16px 10px; align-items: center; }
.tree-tools input { flex: 1; }
#tree { flex: 1; overflow: auto; padding: 0 8px 12px; }
.tr { display: flex; align-items: center; gap: 7px; padding: 4px 8px 4px calc(6px + var(--d) * 18px); border-radius: 8px; min-height: 30px; cursor: default; position: relative; }
.tr:hover { background: var(--surface2); }
.tr.sec { cursor: pointer; }
.tr.sec .ttl { font-weight: 600; }
.tr.on { background: var(--accent-weak); }
.tr.on .ttl { color: var(--accent); }
.tr.here .ttl, .tr.here .ti { color: var(--green); }
.tr.flash { animation: flash 2.2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--green-weak); box-shadow: inset 3px 0 0 var(--green); } 100% { background: transparent; } }
.tw { width: 18px; height: 18px; padding: 0; border: 0; background: none; justify-content: center; color: var(--muted); flex: none; }
.tw .i { width: 14px; height: 14px; transition: transform .15s; }
.tw.open .i { transform: rotate(90deg); }
.ti { color: var(--muted); }
.tr.sec .ti { color: var(--accent); }
.ttl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pth { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; opacity: .8; }
.cnt { font-size: 11px; color: var(--muted); background: var(--surface2); padding: 0 6px; border-radius: 99px; margin-right: auto; }
.acts { display: none; gap: 2px; margin-left: auto; flex: none; }
.tr:hover .acts, .tr.editing .acts { display: flex; }
.acts button { padding: 5px; border: 0; background: transparent; border-radius: 7px; color: var(--muted); }
.acts button .i { width: 20px; height: 20px; }
.acts button:hover:not(:disabled) { background: var(--surface); color: var(--accent); }
.acts button.del:hover:not(:disabled) { color: var(--red); }
.tr.virt .ttl { font-style: italic; }
.tr.virt .ti { stroke-dasharray: 3 2; }
.gl { align-items: center; }
.gl .rv { margin-left: auto; padding: 2px 6px; border: 0; background: transparent; color: var(--muted); border-radius: 6px; font: 12px "Segoe UI", sans-serif; }
.gl .rv:hover { color: var(--red); background: var(--red-weak); }
.syncbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); }
.yerr { margin: 0 16px 10px; border: 1px solid var(--red); background: var(--red-weak); border-radius: 12px; padding: 12px 14px; color: var(--red); }
.yerr b { display: block; margin-bottom: 4px; }
.yerr pre { margin: 8px 0; background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 0; font: 12px/1.55 Consolas, monospace; overflow: auto; }
.yerr pre div { padding: 0 10px; white-space: pre; }
.yerr pre .bad { background: var(--red-weak); color: var(--red); font-weight: 700; }
.yerr pre .n { display: inline-block; width: 36px; color: var(--muted); user-select: none; }
.ren { padding: 3px 8px !important; max-width: 340px; }
mark { background: var(--amber-weak); color: inherit; border-radius: 3px; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.step { display: flex; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.step-n { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-weak); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.step.done .step-n { background: var(--green); color: #fff; }
.step-b { flex: 1; min-width: 0; }
.step-t { font-weight: 700; margin: 2px 0 8px; }
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: all .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-weak); }
.drop .i { width: 26px; height: 26px; color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filebox { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); }
.filebox .i { width: 22px; height: 22px; color: var(--accent); }
.filebox .fn { font-weight: 600; word-break: break-all; }
.pathline { margin-top: 8px; font: 12px/1.5 Consolas, monospace; background: var(--code); padding: 6px 10px; border-radius: 8px; word-break: break-all; color: var(--muted); }
.pathline b { color: var(--text); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-weak); color: var(--accent); border-radius: 99px; padding: 4px 4px 4px 10px; font-size: 12px; font-weight: 600; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { padding: 2px; border: 0; background: none; color: inherit; border-radius: 50%; }
.chip button:hover { background: var(--surface) !important; }
.chip .i { width: 13px; height: 13px; }
.hint { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.seg { display: inline-flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details input { margin-top: 8px; }
.add-foot { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.note { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-top: 8px; }
.note .i { margin-top: 1px; }
.note.ok { background: var(--green-weak); color: var(--green); }
.note.warn { background: var(--amber-weak); color: var(--amber); }
.note.err { background: var(--red-weak); color: var(--red); }
.note.info { background: var(--accent-weak); color: var(--accent); }
.glist { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; max-height: 200px; overflow-y: auto; }
.gl { display: flex; gap: 10px; padding: 6px 10px; font: 12px/1.5 Consolas, monospace; border-bottom: 1px solid var(--border); }
.gl:last-child { border-bottom: 0; }
.gl .st { width: 22px; font-weight: 700; flex: none; }
.gl .st.M { color: var(--amber); } .gl .st.A, .gl .st.N { color: var(--green); } .gl .st.D { color: var(--red); }
.gl .fp { word-break: break-all; }
.gstep { margin-top: 14px; }
.gstep .lbl { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.gstep .row input { flex: 1; min-width: 160px; }
.out { margin-top: 10px; font: 12px/1.5 Consolas, monospace; background: var(--code); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; word-break: break-all; max-height: 180px; overflow: auto; }
.mr { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--green-weak); color: var(--green); font-weight: 600; text-decoration: none; }
.tabs2 { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.tabs2 button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 10px; color: var(--muted); }
.tabs2 button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs2 .c { font-size: 11px; background: var(--surface2); border-radius: 99px; padding: 0 6px; }
.clist { max-height: 300px; overflow: auto; }
.ci { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.ci:last-child { border-bottom: 0; }
.ci .b { flex: 1; min-width: 0; }
.ci .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 18px 16px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.modal { position: fixed; inset: 0; background: rgba(10,12,20,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); width: 100%; max-width: 760px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-box.wide { max-width: 98vw; width: min(1500px, 98vw); height: 92vh; max-height: 98vh; min-width: 560px; min-height: 380px; resize: both; overflow: hidden; }
.modal.fullmode { padding: 0; }
.modal-box.wide.full { width: 100vw !important; height: 100vh !important; max-width: none; max-height: none; border-radius: 0; resize: none; }
.modal-box.wide .modal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: 0; overflow: hidden; }
.ed-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.ed-bar .fname { font: 600 13px Consolas, monospace; word-break: break-all; }
.ed { flex: 1; display: grid; grid-template-columns: minmax(0, var(--ew, 50%)) 14px minmax(0, 1fr); min-height: 0; }
.ed.nopv { grid-template-columns: 1fr; }
.ed.nopv .split { display: none; }
.ed .split::after { position: absolute; top: 50%; left: 50%; margin: -22px 0 0 -3px; }
@media (max-width: 900px) { .ed { grid-template-columns: 1fr; } .ed .pv, .ed .split { display: none; } }
.ed-code { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--code); min-height: 0; }
.ed-code:focus-within { border-color: var(--accent); }
.mdbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px 6px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); }
.mdbar button { border: 0; background: transparent; padding: 0; width: 32px; height: 30px; justify-content: center; border-radius: 7px; color: var(--text); font: 600 13px "Segoe UI", sans-serif; }
.mdbar button:hover { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.mdbar button .i { width: 17px; height: 17px; }
.mdbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 5px; }
.imgdrop { margin: 4px 10px; border: 2px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; color: var(--muted); }
.imgdrop.over { border-color: var(--accent); background: var(--accent-weak); }
.imgdrop .i { width: 26px; height: 26px; color: var(--accent); }
#imPrev { display: block; max-width: calc(100% - 20px); max-height: 170px; margin: 6px auto; border-radius: 8px; border: 1px solid var(--border); }
.fprow { display: flex; gap: 6px; align-items: center; }
.fprow input { flex: 1; }
.fpi { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px calc(8px + var(--d) * 16px); border-radius: 7px; cursor: pointer; }
.fpi:hover { background: var(--accent-weak); }
.fpi.sel { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.fpi .tw { width: 16px; height: 16px; }
.fpi .add { margin-left: auto; padding: 2px 6px; border: 0; background: none; color: var(--muted); border-radius: 6px; visibility: hidden; }
.fpi:hover .add { visibility: visible; }
.fpi .add:hover { color: var(--accent); background: var(--surface); }
#updBtn.has { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.mdbar .pbtn { width: auto; padding: 0 10px; gap: 6px; color: var(--accent); }
.pmenu { position: absolute; z-index: 70; width: 360px; max-height: 62vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25); padding: 6px; }
.pmenu .pg { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px 4px; }
.pmenu .pi { display: flex; align-items: flex-start; gap: 8px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.pmenu .pi:hover { background: var(--accent-weak); }
.pmenu .pi .d { font-size: 12px; color: var(--muted); }
.pmenu .pi .x { margin-left: auto; padding: 2px 6px; border: 0; background: none; color: var(--muted); border-radius: 6px; }
.pmenu .pi .x:hover { color: var(--red); background: var(--red-weak); }
.mdbar .h { font-size: 12px; letter-spacing: -.02em; }
.mdbar .h sub { font-size: 9px; }
.ed-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 10px; }
.ed-head .ttl2 { display: flex; gap: 8px; align-items: center; font-size: 16px; font-weight: 700; }
.ed-head .ttl2 .i { width: 20px; height: 20px; color: var(--accent); }
.ed-meta { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.ed-meta span { display: inline-flex; gap: 5px; align-items: center; }
.ed-meta b { color: var(--text); font-weight: 600; }
.ed-meta .i { width: 14px; height: 14px; }
.zoom { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.zoom button { border: 0; border-radius: 0; padding: 4px 10px; background: var(--surface); }
.zoom span { min-width: 48px; text-align: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.ptabs { display: flex; gap: 4px; padding: 0 16px 10px; }
.ptabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.ptabs button.on { background: var(--accent-weak); color: var(--accent); }
.ftools { display: flex; gap: 8px; padding: 0 16px 10px; align-items: center; flex-wrap: wrap; }
#ftree { flex: 1; overflow: auto; padding: 0 8px 12px; }
.tr .fsz { font-size: 11px; color: var(--muted); margin-left: 4px; white-space: nowrap; }
.tr.fdir .ttl { font-weight: 600; }
.tr.ffile.txt { cursor: pointer; }
#ftree .tr[draggable="true"] { cursor: grab; }
#ftree .tr.dragging { opacity: .45; }
#ftree .tr.dropok { background: var(--accent-weak); box-shadow: inset 0 0 0 2px var(--accent); }
.tr.ffile.bin .ttl { color: var(--muted); }
.gut { padding: 10px 6px 10px 0; min-width: 46px; text-align: right; color: var(--muted); font: 13px/1.6 Consolas, monospace; overflow: hidden; user-select: none; background: var(--surface2); border-right: 1px solid var(--border); white-space: pre; }
.ed textarea { flex: 1; border: 0; outline: none; resize: none; padding: 10px 12px; font: 13px/1.6 Consolas, monospace; background: transparent; color: var(--text); white-space: pre; overflow: auto; tab-size: 4; }
.pv { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.pv .pvh { font-size: 12px; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.pv iframe { flex: 1; border: 0; width: 100%; background: #fff; }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); display: inline-block; }
.modal-head { display: flex; align-items: center; padding: 16px 18px 8px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 4px 18px 8px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
pre.diff { background: var(--code); border: 1px solid var(--border); border-radius: 10px; padding: 8px 0; overflow: auto; font: 12px/1.6 Consolas, monospace; margin: 12px 0 0; }
pre.diff div { padding: 0 12px; white-space: pre; }
pre.diff .a { background: var(--green-weak); color: var(--green); }
pre.diff .d { background: var(--red-weak); color: var(--red); }
pre.diff .h { color: var(--accent); }
.flist { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 10px; }
.fi { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.fi:hover { background: var(--accent-weak); }
.fi:last-child { border-bottom: 0; }
#serveBtn.run { background: var(--green-weak); border-color: var(--green); color: var(--green); font-weight: 600; }
#serveBtn.busy { background: var(--amber-weak); border-color: var(--amber); color: var(--amber); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.slog { margin-top: 12px; font: 12px/1.5 Consolas, monospace; background: var(--code); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; height: 280px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.sstate { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 10px; font-weight: 600; }
.sstate.run { background: var(--green-weak); color: var(--green); }
.sstate.busy { background: var(--amber-weak); color: var(--amber); }
.sstate.err { background: var(--red-weak); color: var(--red); }
.sstate.idle { background: var(--surface2); color: var(--muted); }
#offline { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; gap: 10px; align-items: center;
max-width: min(760px, calc(100vw - 32px)); background: var(--red); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); font-size: 14px; }
#offline .i { width: 20px; height: 20px; flex: none; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { display: flex; gap: 8px; align-items: flex-start; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; animation: tin .2s ease-out; font-size: 13px; white-space: pre-wrap; }
.toast.err { background: var(--red); color: #fff; }
.toast { align-items: center; }
.toast .tundo { margin-left: 10px; padding: 3px 10px; background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 7px; font-weight: 600; flex: none; }
.toast .tundo:hover { background: rgba(127,127,127,.25); }
.toast.ok .i { color: var(--green); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
</style>
</head>
<body>
<!-- ===== выбор папки ===== -->
<div id="pick" class="hidden">
<div class="pick-wrap">
<div class="row"><div class="brand"><div class="logo" id="logo1"></div>Nav Tool</div><div class="grow"></div>
<button class="ghost hidden" id="pickBack"></button></div>
<h1>Где лежит документация?</h1>
<div class="muted">Выбери папку с mkdocs.yml. Дальше все правки меню, ветка, коммит и push делаются здесь.</div>
<div id="repoBlock"></div>
<div class="sec-title">Или найди папку</div>
<div class="card browser" style="margin-top:10px">
<div class="br-top" id="places"></div>
<div class="br-path"><button class="ghost" id="brUp" title="Наверх"></button><div id="brCrumbs" class="row" style="gap:2px"></div></div>
<div class="br-list" id="brList"></div>
<div class="br-foot">
<input type="text" id="brInput" placeholder="Или вставь путь, например C:\Users\...\documentation">
<button id="brGo">Перейти</button>
<button class="primary" id="brOpen" disabled>Открыть эту папку</button>
</div>
</div>
</div>
</div>
<!-- ===== основной экран ===== -->
<div id="app" class="hidden">
<header class="top">
<div class="brand"><div class="logo" id="logo2"></div></div>
<button class="ghost proj" id="projBtn" title="Сменить папку"><span class="pn" id="projName"></span><span class="pp" id="projPath"></span></button>
<span class="ver" id="verLbl" title="Версия программы"></span>
<span id="branchPill"></span>
<div class="grow"></div>
<button id="serveBtn"></button>
<button class="ghost" id="undoBtn"></button>
<button class="ghost" id="reloadBtn" title="Перечитать mkdocs.yml и git"></button>
<button class="hidden" id="updBtn" title="Обновление программы"></button>
<button class="theme-sw" id="themeSw" title="Светлая / темная тема" aria-label="Переключить тему"></button>
</header>
<main class="grid">
<section class="card tree-card">
<div class="card-head"><h2 id="leftTitle">Меню сайта</h2><span class="muted small" id="treeInfo"></span></div>
<div class="ptabs"><button data-pt="nav" class="on">Меню сайта</button><button data-pt="files">Файлы</button></div>
<div id="filesPane" class="hidden" style="display:flex;flex-direction:column;flex:1;min-height:0">
<div class="ftools">
<button id="fNewFile"></button><button id="fNewDir"></button>
<span class="grow"></span><span class="muted small">Файлы и папки можно перетаскивать мышью</span><button class="ghost" id="fRefresh" title="Обновить"></button>
</div>
<div id="ftree"></div>
</div>
<div id="navPane" style="display:flex;flex-direction:column;flex:1;min-height:0">
<div class="tree-tools">
<input type="text" id="search" placeholder="Поиск по разделам и страницам">
<button class="ghost" id="expandBtn" title="Развернуть все"></button>
<button class="ghost" id="collapseBtn" title="Свернуть"></button>
<button class="ghost" id="pagesBtn" title="Показать или скрыть страницы"></button>
<button class="ghost" id="ymlEditBtn" title="Открыть mkdocs.yml в редакторе"></button>
</div>
<div id="ymlErr"></div>
<div id="tree"></div>
</div>
</section>
<div class="split" id="mainSplit" title="Потяни, чтобы изменить ширину. Двойной щелчок: как было"></div>
<section class="side">
<div class="card" id="addCard">
<div class="card-head"><h2>Добавить страницу</h2></div>
<div class="step" id="st1"><div class="step-n">1</div><div class="step-b">
<div class="step-t">Файл</div>
<div class="drop" id="drop">
<span id="dropIco"></span>
<b>Перетащи .md сюда</b>
<div class="row" style="justify-content:center">
<button id="pickPc">Выбрать на компьютере</button>
<button id="pickDocs">Уже лежит в docs/</button>
</div>
<input type="file" id="fileInput" accept=".md,.markdown" class="hidden">
</div>
<div id="fileBox" class="hidden">
<div class="filebox"><span id="fbIco"></span><div class="grow" style="min-width:0"><div class="fn" id="fbName"></div><div class="small muted" id="fbSub"></div></div>
<button class="ghost" id="fileClear" title="Убрать файл"></button></div>
<label class="fl">Название в меню</label>
<input type="text" id="title">
<div id="dirWrap">
<label class="fl">Папка внутри <span class="docsName">docs</span>/</label>
<input type="text" id="dir" list="dirList" placeholder="подставится по выбранному разделу">
<datalist id="dirList"></datalist>
</div>
<div class="pathline"><span class="docsName">docs</span>/<b id="finalPath"></b></div>
<label class="check" id="owWrap"><input type="checkbox" id="overwrite"> Перезаписать файл, если такой уже есть</label>
<div id="already"></div>
</div>
</div></div>
<div class="step" id="st2"><div class="step-n">2</div><div class="step-b">
<div class="step-t">Куда</div>
<div id="chips"></div>
</div></div>
<div class="step" id="st3"><div class="step-n">3</div><div class="step-b">
<div class="step-t">Как</div>
<div class="seg" id="modeSeg"><button data-m="end" class="on">В конец раздела</button><button data-m="alpha">По порядку номеров</button></div>
<details id="subDet"><summary>Положить в новый подраздел</summary>
<input type="text" id="sub" placeholder="Например: Задание №5. Если такой есть, страница ляжет в него"></details>
</div></div>
<div class="add-foot"><span class="muted small" id="why"></span><button class="primary big" id="previewBtn" disabled>Проверить и добавить</button></div>
</div>
<div class="card" id="gitCard">
<div class="card-head"><h2>Git</h2><span id="gitPill"></span><div class="grow"></div><span class="muted small" id="gitUp"></span></div>
<div class="card-body" id="gitBody"></div>
</div>
<div class="card" id="checkCard">
<div class="card-head"><h2>Проверка</h2></div>
<div class="tabs2"><button data-t="orph" class="on">Нет в меню <span class="c" id="cOrph"></span></button><button data-t="miss">Битые ссылки <span class="c" id="cMiss"></span></button></div>
<div class="clist" id="clist"></div>
</div>
</section>
</main>
</div>
<div id="modal" class="modal hidden"><div class="modal-box">
<div class="modal-head"><h3 id="mTitle"></h3><button class="ghost" id="mClose"></button></div>
<div class="modal-body" id="mBody"></div>
<div class="modal-foot" id="mFoot"></div>
</div></div>
<div id="toasts"></div>
<script>
const $ = s => document.querySelector(s);
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&": "&", "<": "<", ">": ">", '"': """}[c]));
const P = {
logo: '<path d="M4 6h16M4 12h10M4 18h7"/><path d="M17 15l2 2 3-4"/>',
folder: '<path d="M3 7.5A1.5 1.5 0 0 1 4.5 6h4l2 2h9A1.5 1.5 0 0 1 21 9.5v8a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z"/>',
file: '<path d="M6 3h8l4 4v14H6z"/><path d="M14 3v4h4"/>',
edit: '<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13 7l4 4"/>',
up: '<path d="M12 19V5M6 11l6-6 6 6"/>', down: '<path d="M12 5v14M6 13l6 6 6-6"/>',
trash: '<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13"/>',
undo: '<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>',
refresh: '<path d="M20 11a8 8 0 1 0-2.3 5.7"/><path d="M20 4v7h-7"/>',
branch: '<circle cx="6" cy="5" r="2"/><circle cx="6" cy="19" r="2"/><circle cx="18" cy="7" r="2"/><path d="M6 7v10M18 9c0 5-7 4-11 8"/>',
x: '<path d="M6 6l12 12M18 6 6 18"/>', check: '<path d="M5 12l5 5L20 7"/>',
upload: '<path d="M12 16V4M7 9l5-5 5 5"/><path d="M4 20h16"/>', chev: '<path d="M9 6l6 6-6 6"/>',
back: '<path d="M15 6l-6 6 6 6"/>', arrowUp: '<path d="M12 19V5M6 11l6-6 6 6"/>',
expand: '<path d="M7 9l5 5 5-5"/><path d="M4 4h16"/>', collapse: '<path d="M7 15l5-5 5 5"/><path d="M4 20h16"/>',
eye: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>',
warn: '<path d="M12 3 2 20h20z"/><path d="M12 10v4M12 17h.01"/>', info: '<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>',
commit: '<circle cx="12" cy="12" r="3"/><path d="M3 12h6M15 12h6"/>', push: '<path d="M12 20V8M6 13l6-6 6 6"/><path d="M5 4h14"/>',
link: '<path d="M10 14a4 4 0 0 0 6 0l3-3a4 4 0 0 0-6-6l-1 1"/><path d="M14 10a4 4 0 0 0-6 0l-3 3a4 4 0 0 0 6 6l1-1"/>',
plus: '<path d="M12 5v14M5 12h14"/>',
preset: '<rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><path d="M17.5 14v7M14 17.5h7"/>',
redo: '<path d="M15 14l5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>',
strike: '<path d="M4 12h16"/><path d="M16 6.5C15 5 13.5 4.5 12 4.5c-2.5 0-4 1.3-4 3 0 1.5 1 2.3 3 3"/><path d="M8 17.5c1 1.5 2.5 2 4 2 2.5 0 4-1.3 4-3 0-.8-.3-1.5-.9-2"/>',
eraser: '<path d="M7 21h10"/><path d="M5 15l8-8 6 6-6 6H9z"/><path d="M9 11l6 6"/>',
pilcrow: '<path d="M13 4v16M17 4v16M19 4H9.5a4.5 4.5 0 0 0 0 9H13"/>',
indent: '<path d="M3 5h18M11 10h10M11 14h10M3 19h18M3 9l4 3-4 3"/>',
quote: '<path d="M7 7H4v6h3l-1 4M17 7h-3v6h3l-1 4"/>',
ol: '<path d="M10 6h11M10 12h11M10 18h11M4 6h1v4M4 10h2M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>',
ul: '<path d="M9 6h12M9 12h12M9 18h12"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>',
hr: '<path d="M3 12h18"/>',
sub: '<path d="M4 5l8 10M12 5l-8 10"/><path d="M15 19h5c0-1.5-5-2-5-4 0-1 1-1.5 2.5-1.5S20 14 20 15"/>',
table: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>',
block: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M8 10l-2 2 2 2M16 10l2 2-2 2"/>',
unlink: '<path d="M10 14a4 4 0 0 0 6 0l3-3a4 4 0 0 0-5.5-5.8"/><path d="M14 10a4 4 0 0 0-6 0l-3 3a4 4 0 0 0 5.5 5.8"/><path d="M4 4l16 16"/>',
filePlus: '<path d="M6 3h8l4 4v14H6z"/><path d="M14 3v4h4M12 11v6M9 14h6"/>',
image: '<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="2"/><path d="M21 17l-5-5-9 8"/>',
maxi: '<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>', mini: '<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/>',
zoomIn: '<circle cx="11" cy="11" r="7"/><path d="M21 21l-5-5M11 8v6M8 11h6"/>', zoomOut: '<circle cx="11" cy="11" r="7"/><path d="M21 21l-5-5M8 11h6"/>',
code: '<path d="M8 8l-4 4 4 4M16 8l4 4-4 4M13.5 5l-3 14"/>', save: '<path d="M5 3h11l3 3v15H5z"/><path d="M8 3v6h8V3M8 21v-7h8v7"/>',
folderPlus: '<path d="M3 7.5A1.5 1.5 0 0 1 4.5 6h4l2 2h9A1.5 1.5 0 0 1 21 9.5v8a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z"/><path d="M12 11v5M9.5 13.5h5"/>',
download: '<path d="M12 4v12M7 11l5 5 5-5"/><path d="M5 20h14"/>',
merge: '<circle cx="6" cy="5" r="2"/><circle cx="6" cy="19" r="2"/><circle cx="18" cy="12" r="2"/><path d="M6 7v10M6 9c0 3 6 3 10 3"/>', play: '<path d="M7 4v16l13-8z"/>', stop: '<rect x="6" y="6" width="12" height="12" rx="2"/>',
ext: '<path d="M14 4h6v6M20 4l-9 9"/><path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/>', loader: '<path d="M12 3a9 9 0 1 0 9 9"/>', drive: '<rect x="3" y="13" width="18" height="7" rx="2"/><path d="M5 13l2-8h10l2 8M7 17h.01"/>',
};
const ic = (n, cls = "") => `<svg class="i ${cls}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${P[n]}</svg>`;
async function api(url, body) {
let r;
try {
r = await fetch(url, body ? {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(body)} : {});
} catch (e) {
// программа (окно run.bat) не отвечает: одна понятная плашка вместо «Failed to fetch»
showOffline();
const err = new Error("Нет связи с программой");
err.offline = true;
throw err;
}
hideOffline();
const j = await r.json().catch(() => ({error: r.statusText}));
if (!r.ok) throw new Error(j.error || r.statusText);
return j;
}
let offlineTimer = null;
function showOffline() {
if ($("#offline") || window._updating) return;
const el = document.createElement("div");
el.id = "offline";
el.innerHTML = `${ic("warn")}<span><b>Нет связи с программой.</b> Скорее всего, закрыто окно run.bat или программа перезапускается.
Запусти run.bat снова: страница переподключится сама, ничего не потеряется.</span>`;
document.body.appendChild(el);
clearInterval(offlineTimer);
offlineTimer = setInterval(async () => {
try {
const r = await fetch("/api/home", {cache: "no-store"});
if (r.ok) { hideOffline(); if (S) load(); toast("Связь с программой восстановлена", "info", 2500); }
} catch (e) {}
}, 2000);
}
function hideOffline() {
if (offlineTimer) { clearInterval(offlineTimer); offlineTimer = null; }
const el = $("#offline"); if (el) el.remove();
}
function toast(text, kind = "ok", ms = 3500, withUndo = false) {
if (text === "Нет связи с программой") return; // про это уже говорит плашка сверху
if ([...document.querySelectorAll("#toasts .toast span")].some(s => s.textContent === text)) return; // без дублей
const el = document.createElement("div");
el.className = "toast " + kind;
el.innerHTML = (kind === "ok" ? ic("check") : kind === "err" ? ic("warn") : ic("info")) + `<span>${esc(text)}</span>`;
if (withUndo) {
// кнопка отката прямо в сообщении; старые такие сообщения убираем, чтобы откат относился к последнему действию
document.querySelectorAll(".toast.hasundo").forEach(x => x.remove());
el.classList.add("hasundo");
const b = document.createElement("button");
b.className = "tundo"; b.textContent = "Отменить";
b.onclick = () => { el.remove(); undoLast(); };
el.appendChild(b);
}
$("#toasts").appendChild(el);
setTimeout(() => el.remove(), kind === "err" ? 8000 : withUndo ? 10000 : ms);
}
const toastUndo = text => toast(text, "ok", 10000, true);
function modal(title, body, buttons) {
svModal = false;
modalGuard = null;
resetModalBox();
$("#mTitle").textContent = title;
$("#mBody").innerHTML = body;
$("#mFoot").innerHTML = "";
(buttons || [{text: "Закрыть"}]).forEach(b => {
const el = document.createElement("button");
el.className = b.cls || ""; el.innerHTML = b.text; el.disabled = !!b.disabled;
el.onclick = async () => { if (b.onClick) { el.disabled = true; const keep = await b.onClick(); el.disabled = false; if (keep) return; } closeModal(); };
$("#mFoot").appendChild(el);
});
$("#modal").classList.remove("hidden");
}
let modalGuard = null;
function closeModal(force) {
if (!force && modalGuard && !modalGuard()) return;
modalGuard = null;
svModal = false;
document.querySelectorAll(".pmenu").forEach(x => x.remove());
fpEl = null;
$("#modal").classList.add("hidden");
resetModalBox();
}
function resetModalBox() {
const box = document.querySelector(".modal-box");
if (window._edSave) { window._edSave(); window._edSave = null; }
box.classList.remove("wide", "full"); box.style.width = box.style.height = "";
$("#modal").classList.remove("fullmode");
}
$("#mClose").innerHTML = ic("x"); $("#mClose").onclick = () => closeModal();
$("#modal").addEventListener("mousedown", e => { if (e.target.id === "modal") closeModal(); });
document.addEventListener("keydown", e => { if (e.key === "Escape" && !$("#modal").classList.contains("hidden")) closeModal(); });
["#logo1", "#logo2"].forEach(s => $(s).innerHTML = ic("logo"));
/* ================= выбор папки ================= */
let browsePath = null;
async function showPicker() {
$("#app").classList.add("hidden"); $("#pick").classList.remove("hidden");
$("#pickBack").classList.toggle("hidden", !S);
$("#pickBack").innerHTML = ic("back") + "Вернуться к проекту";
$("#brUp").innerHTML = ic("arrowUp");
try {
const h = await api("/api/home");
const card = r => `<button class="rcard" data-open="${esc(r.path)}"><b>${esc(r.name)}</b>
<span class="p">${esc(r.path)}</span>${r.branch ? `<span class="pill grey" style="margin-top:4px">${ic("branch")}${esc(r.branch)}</span>` : ""}</button>`;
$("#repoBlock").innerHTML =
(h.recent.length ? `<div class="sec-title">Недавние</div><div class="cards">${h.recent.map(card).join("")}</div>` : "") +
(h.found.length ? `<div class="sec-title">Найдено на рабочем столе</div><div class="cards">${h.found.map(card).join("")}</div>` : "");
} catch (e) { toast(e.message, "err"); }
browse(browsePath || "");
}
async function browse(path) {
let b;
try { b = await api("/api/browse?path=" + encodeURIComponent(path)); } catch (e) { toast(e.message, "err"); return; }
browsePath = b.path;
$("#places").innerHTML = b.places.map(p => `<button data-go="${esc(p.path)}">${ic("folder")}${esc(p.name)}</button>`).join("") +
b.drives.map(d => `<button data-go="${esc(d)}">${ic("drive")}${esc(d.replace("\\", ""))}</button>`).join("");
const parts = b.path.split(/[\\/]/).filter(Boolean);
let acc = "";
$("#brCrumbs").innerHTML = parts.map((p, i) => {
acc = i === 0 ? p + "\\" : acc.replace(/\\?$/, "\\") + p;
return (i ? `<span class="muted">${ic("chev")}</span>` : "") + `<span class="crumb" data-go="${esc(acc)}">${esc(p)}</span>`;
}).join("");
$("#brUp").disabled = !b.parent; $("#brUp").dataset.go = b.parent || "";
$("#brList").innerHTML = b.dirs.length ? b.dirs.map(d => `
<div class="br-item ${d.mkdocs ? "mk" : ""}" data-go="${esc(d.path)}">
<span style="color:${d.mkdocs ? "var(--green)" : "var(--muted)"}">${ic("folder")}</span><span class="nm">${esc(d.name)}</span>
${d.mkdocs ? `<span class="pill ok">mkdocs</span><button class="primary" data-open="${esc(d.path)}">Открыть</button>` : ""}
</div>`).join("") : `<div class="empty">${ic("info")}Подпапок нет</div>`;
$("#brOpen").disabled = !b.here;
$("#brOpen").textContent = b.here ? "Открыть эту папку" : "Здесь нет mkdocs.yml";
$("#brInput").value = "";
}
$("#pick").addEventListener("click", e => {
const o = e.target.closest("[data-open]");
if (o) { e.stopPropagation(); openRepo(o.dataset.open); return; }
const g = e.target.closest("[data-go]");
if (g && g.dataset.go) browse(g.dataset.go);
});
$("#brOpen").onclick = () => openRepo(browsePath);
$("#brGo").onclick = () => $("#brInput").value.trim() && browse($("#brInput").value.trim().replace(/^"|"$/g, ""));
$("#brInput").addEventListener("keydown", e => { if (e.key === "Enter") $("#brGo").click(); });
$("#pickBack").onclick = () => { $("#pick").classList.add("hidden"); $("#app").classList.remove("hidden"); };
/* ================= состояние ================= */
let S = null, K = [], byKey = {};
let openK = new Set(), checkedK = new Set();
let showPages = true, search = "";
let src = null; // {kind:'upload', filename, content, size} | {kind:'repo', path, title}
let titleTouched = false, dirTouched = false, mode = "end";
let lastAdded = null, gitOut = null, checkTab = "orph";
let pending = []; // пустые разделы, которых еще нет в nav: {pk, title, dir}
const VK = (pk, title) => "V" + pk + "\u0001" + title;
function keyOf(id) {
const parts = []; let n = S.nodes[id];
while (n) { parts.unshift(n.path || n.title); n = n.parent === null ? null : S.nodes[n.parent]; }
return parts.join("\u0001");
}
function vOf(k) { return pending.find(v => VK(v.pk, v.title) === k); }
// пустые разделы могут быть вложены друг в друга: поднимаемся до настоящего раздела и собираем цепочку названий
function vChain(k) {
const titles = []; let cur = k, v;
while ((v = vOf(cur))) { titles.unshift(v.title); cur = v.pk; }
return {id: byKey[cur], key: cur, titles};
}
function targetOf(k) { if (!vOf(k)) return byKey[k]; const c = vChain(k); return {id: c.id, sub: c.titles}; }
function crumbK(k) { if (!vOf(k)) return crumb(byKey[k]); const c = vChain(k); return crumb(c.id) + " › " + c.titles.join(" › "); }
function vDescendants(k) { const out = [k]; pending.filter(v => v.pk === k).forEach(v => out.push(...vDescendants(VK(v.pk, v.title)))); return out; }
function hintK(k) { const v = vOf(k); return v ? v.dir : (S.nodes[byKey[k]].hint || ""); }
function crumb(id) {
const p = []; let n = S.nodes[id];
while (n && n.id !== 0) { p.unshift(n.title); n = S.nodes[n.parent]; }
return p.join(" › ") || "Корень меню";
}
async function openRepo(path) {
S = null; openK = new Set(); checkedK = new Set(); src = null; lastAdded = null; gitOut = null;
if (await load(path)) {
$("#pick").classList.add("hidden"); $("#app").classList.remove("hidden");
browsePath = path;
resetForm();
}
}
async function load(repo, flashKeys) {
let st;
try { st = await api("/api/state?repo=" + encodeURIComponent(repo || S.repo)); } catch (e) { toast(e.message, "err"); return false; }
const first = !S || S.repo !== st.repo;
S = st;
K = S.nodes.map(n => keyOf(n.id));
byKey = {}; K.forEach((k, i) => byKey[k] = i);
if (first) {
openK = new Set([K[0]]); S.nodes[0].children.forEach(c => { openK.add(K[c]); S.nodes[c].children.forEach(g => !S.nodes[g].path && openK.add(K[g])); });
}
// пустой раздел, в который уже добавили страницу, становится настоящим
for (let changed = true; changed;) {
changed = false;
pending = pending.filter(v => {
if (v.pk in byKey) {
const real = S.nodes[byKey[v.pk]].children.find(c => !S.nodes[c].path && S.nodes[c].title === v.title);
if (real === undefined) return true;
const vk = VK(v.pk, v.title), rk = K[real];
if (checkedK.has(vk)) { checkedK.delete(vk); checkedK.add(rk); }
pending.forEach(x => { if (x.pk === vk) x.pk = rk; });
openK.add(rk); changed = true;
return false;
}
if (pending.some(x => VK(x.pk, x.title) === v.pk)) return true;
changed = true;
return false;
});
}
checkedK = new Set([...checkedK].filter(k => k in byKey || pending.some(v => VK(v.pk, v.title) === k)));
document.title = "Nav Tool: " + S.name;
$("#projName").textContent = S.name; $("#projPath").textContent = S.repo;
document.querySelectorAll(".docsName").forEach(e => e.textContent = S.docs_dir);
$("#dirList").innerHTML = S.dirs.map(d => `<option value="${esc(d)}">`).join("");
$("#treeInfo").textContent = `${S.nodes.filter(n => n.path).length} страниц`;
renderTop(); renderYmlErr(); renderTree(flashKeys); renderForm(); renderGit(); renderChecks();
if (first) { ftCache = {}; ftOpen = new Set([""]); setLeftTab(prefGet("navtool.lefttab") || "nav"); }
else if (leftTab === "files") { ftCache = {}; renderFiles2(); }
return true;
}
function renderYmlErr() {
const e = S.yml_error;
if (!e) { $("#ymlErr").innerHTML = ""; return; }
const bad = new Set([e.line, e.ctx_line].filter(Boolean));
$("#ymlErr").innerHTML = `<div class="yerr">
<b>${ic("warn")} ${esc(S.yml)} сломан, mkdocs его не прочитает</b>
<div>Строка ${e.line}${e.ctx_line && e.ctx_line !== e.line ? ` (начало проблемы в строке ${e.ctx_line})` : ""}: ${esc(e.text)}</div>
<pre>${e.snippet.map(x => `<div class="${bad.has(x.n) ? "bad" : ""}"><span class="n">${x.n}</span>${esc(x.s) || " "}</div>`).join("")}</pre>
<div class="small" style="color:var(--text)">Обычно это пропущенное двоеточие, лишний или недостающий пробел в отступе или «: » внутри названия без кавычек.
Пока файл сломан, меню ниже может показываться неточно.</div>
${e.fix ? `<div class="small" style="color:var(--text);margin-top:8px">Можно исправить автоматически: ${esc(e.fix.label)}, строка станет такой:
<pre style="margin:6px 0 0"><div><span class="n">${e.line}</span>${esc(e.fix.line)}</div></pre></div>` : ""}
<div class="row" style="margin-top:10px">
${e.fix ? `<button class="primary" id="yFix">${ic("check")}Исправить</button>` : ""}
<button id="yEdit">${ic("code")}Открыть в редакторе</button>
<button id="yOpen">${ic("edit")}Открыть в Блокноте</button>
<button id="yReload">${ic("refresh")}Проверить снова</button>
${S.undo.length ? `<button id="yUndo" title="${esc(S.undo[S.undo.length - 1])}">${ic("undo")}Отменить последнее действие</button>` : ""}
</div></div>`;
$("#yEdit").onclick = () => openEditor("@mkdocs.yml", e.line);
$("#yOpen").onclick = async () => { try { toast((await api("/api/open-yml", {repo: S.repo})).message, "info", 6000); } catch (x) { toast(x.message, "err"); } };
$("#yReload").onclick = () => load().then(ok => ok && !S.yml_error && toast("mkdocs.yml в порядке"));
if ($("#yUndo")) $("#yUndo").onclick = () => $("#undoBtn").click();
if ($("#yFix")) $("#yFix").onclick = async () => {
try { toastUndo((await api("/api/fix-yml", {repo: S.repo, sha: S.sha})).message); } catch (x) { toast(x.message, "err"); }
await load();
};
}
function renderTop() {
const g = S.git;
const master = g.is_repo && ["master", "main"].includes(g.branch);
$("#branchPill").innerHTML = g.is_repo ? `<span class="pill ${master ? "warn" : ""}" title="${master ? "Ты на основной ветке" : ""}">${ic("branch")}${esc(g.branch || "detached")}</span>${mergedPill(g)}` : "";
const n = S.undo.length;
$("#undoBtn").innerHTML = ic("undo") + "Отменить" + (n ? ` <span class="pill grey">${n}</span>` : "");
$("#undoBtn").disabled = !n;
$("#undoBtn").className = n ? "" : "ghost";
$("#undoBtn").title = n ? "Отменить: " + S.undo[n - 1] : "Пока нечего отменять";
$("#reloadBtn").innerHTML = ic("refresh");
}
$("#projBtn").onclick = showPicker;
$("#reloadBtn").onclick = () => load().then(ok => ok && toast("Обновлено", "info", 1500));
async function undoLast() {
try { const r = await api("/api/undo", {repo: S.repo}); toast(r.message); await load(); } catch (e) { toast(e.message, "err"); }
}
$("#undoBtn").onclick = undoLast;
/* ================= дерево ================= */
const countCache = {};
function pageCount(id) { return S.nodes[id].children.reduce((a, c) => a + (S.nodes[c].path ? 1 : pageCount(c)), 0); }
function hl(t, q) {
t = t || ""; if (!q) return esc(t);
const i = t.toLowerCase().indexOf(q);
return i < 0 ? esc(t) : esc(t.slice(0, i)) + "<mark>" + esc(t.slice(i, i + q.length)) + "</mark>" + esc(t.slice(i + q.length));
}
function renderTree(flashKeys) {
const q = search.trim().toLowerCase();
let vis = null;
if (q) {
vis = new Set();
S.nodes.forEach(n => {
if ((n.title || "").toLowerCase().includes(q) || (n.path || "").toLowerCase().includes(q)) {
let c = n; while (c) { vis.add(c.id); c = c.parent === null ? null : S.nodes[c.parent]; }
}
});
}
const cur = currentPath();
const out = [];
const walk = (id, d) => {
const n = S.nodes[id];
if (vis && !vis.has(id)) return;
if (n.path && !showPages && !q) return;
const sibs = n.parent === null ? [id] : S.nodes[n.parent].children;
const pos = sibs.indexOf(id);
const virt = n.path ? [] : pending.filter(v => v.pk === K[id]);
const isOpen = !n.path && (q ? true : openK.has(K[id]));
const hasKids = n.children.length + virt.length > 0;
const cls = ["tr", n.path ? "pg" : "sec", checkedK.has(K[id]) ? "on" : "", cur && n.path === cur ? "here" : "",
flashKeys && flashKeys.includes(K[id]) ? "flash" : ""].join(" ");
out.push(`<div class="${cls}" data-id="${id}" style="--d:${d}">
${n.path ? `<span class="tw"></span>` : `<button class="tw ${isOpen ? "open" : ""}" data-act="toggle" ${hasKids ? "" : "disabled"}>${hasKids ? ic("chev") : ""}</button>`}
${n.path ? "" : `<input type="checkbox" data-act="check" ${checkedK.has(K[id]) ? "checked" : ""} title="Добавить сюда">`}
${ic(n.path ? "file" : "folder", "ti")}
<span class="ttl">${hl(n.title, q)}</span>${n.path ? originPill(n.path) : ""}
${n.path ? `<span class="pth" title="${esc(n.path)}">${hl(n.path, q)}</span>` : `<span class="cnt">${pageCount(id) || ""}</span>`}
${!id ? `<span class="acts"><button data-act="newpage" title="Новая страница">${ic("filePlus")}</button><button data-act="addsec" title="Новый раздел внутри">${ic("folderPlus")}</button></span>` : ""}
${id ? `<span class="acts">
${n.path ? "" : `<button data-act="newpage" title="Новая страница в этом разделе">${ic("filePlus")}</button><button data-act="addsec" title="Новый раздел внутри">${ic("folderPlus")}</button>`}
${n.path && SV.state === "running" && SV.repo === S.repo ? `<button data-act="site" title="Открыть на локальном сайте">${ic("ext")}</button>` : ""}
${n.path && /\.(md|markdown)$/i.test(n.path) ? `<button data-act="editfile" title="Открыть в редакторе">${ic("code")}</button>` : ""}
<button data-act="rename" title="Переименовать">${ic("edit")}</button>
<button data-act="up" title="Выше" ${pos === 0 ? "disabled" : ""}>${ic("up")}</button>
<button data-act="down" title="Ниже" ${pos === sibs.length - 1 ? "disabled" : ""}>${ic("down")}</button>
<button data-act="delete" class="del" title="Убрать из меню">${ic("trash")}</button></span>` : ""}
</div>`);
if (isOpen) {
n.children.forEach(c => walk(c, d + 1));
const renderVirt = (pk, dd) => pending.filter(v => v.pk === pk).forEach(v => {
const k = VK(v.pk, v.title);
out.push(`<div class="tr sec virt ${checkedK.has(k) ? "on" : ""} ${flashKeys && flashKeys.includes(k) ? "flash" : ""}" data-v="${esc(k)}" style="--d:${dd}">
<span class="tw"></span><input type="checkbox" data-act="vcheck" ${checkedK.has(k) ? "checked" : ""} title="Добавить сюда">
${ic("folder", "ti")}<span class="ttl">${esc(v.title)}</span>
<span class="pill grey" title="В mkdocs.yml появится вместе с первой страницей">пустой</span>
<span class="acts">
<button data-act="vnewpage" title="Новая страница в этом разделе">${ic("filePlus")}</button>
<button data-act="vaddsec" title="Новый раздел внутри">${ic("folderPlus")}</button>
<button data-act="vdel" class="del" title="Убрать пустой раздел">${ic("trash")}</button></span></div>`);
renderVirt(k, dd + 1);
});
if (!q) renderVirt(K[id], d + 1);
}
};
walk(0, 0);
$("#tree").innerHTML = out.join("") || `<div class="empty">${ic("info")}Ничего не найдено</div>`;
const f = $("#tree .flash"); if (f) f.scrollIntoView({block: "center", behavior: "smooth"});
}
function toggleKey(k, on) {
on ? checkedK.add(k) : checkedK.delete(k);
if (on && src && src.kind === "upload" && !dirTouched) $("#dir").value = hintK(k);
renderTree(); renderForm();
}
function toggleCheck(id, on) { toggleKey(K[id], on); }
$("#tree").addEventListener("click", e => {
const row = e.target.closest(".tr"); if (!row || row.classList.contains("editing")) return;
if (row.dataset.v) {
const a = e.target.closest("[data-act]"), k = row.dataset.v;
if (a && a.dataset.act === "vcheck") toggleKey(k, a.checked);
else if (a && a.dataset.act === "vaddsec") newSection(k);
else if (a && a.dataset.act === "vnewpage") newPage(k);
else if (a && a.dataset.act === "vdel") {
const gone = new Set(vDescendants(k));
pending = pending.filter(v => !gone.has(VK(v.pk, v.title)));
gone.forEach(x => checkedK.delete(x));
renderTree(); renderForm();
}
return;
}
const id = +row.dataset.id, n = S.nodes[id];
const actEl = e.target.closest("[data-act]");
const act = actEl ? actEl.dataset.act : (n.path ? null : "toggle");
if (act === "check") { toggleCheck(id, actEl.checked); return; }
if (act === "toggle") { openK.has(K[id]) ? openK.delete(K[id]) : openK.add(K[id]); renderTree(); return; }
if (act === "site") { window.open(pageUrl(n.path), "_blank"); return; }
if (act === "editfile") return openEditor(n.path);
if (act === "addsec") return newSection(K[id]);
if (act === "newpage") return newPage(K[id]);
if (act === "rename") return startRename(row, id);
if (act === "up" || act === "down") return op(act, id);
if (act === "delete") return navDelete(id);
});
/* корзина в меню: пункт или раздел вместе с файлами страниц */
async function navDelete(id) {
let d;
try { d = await api("/api/op", {repo: S.repo, op: "delete", id, files: true, dry: true}); } catch (e) { toast(e.message, "err"); return; }
const fl = d.files;
modal(d.is_page ? "Удалить страницу?" : "Удалить раздел?", `
<div>«<b>${esc(d.title)}</b>»${d.is_page ? "" : ` <span class="muted">раздел, страниц внутри: ${d.pages}</span>`}</div>
${fl.length ? `<label class="check"><input type="checkbox" id="ndFiles" checked><span><b>Удалить и файлы с диска</b> (${fl.length})
<div class="muted small">${fl.slice(0, 8).map(f => esc(S.docs_dir + "/" + f)).join("<br>")}${fl.length > 8 ? "<br>и еще " + (fl.length - 8) : ""}</div></span></label>` : ""}
<div id="ndInfo"></div>
<div class="note info">${ic("info")}<span>Опустевшие разделы меню и папки на диске уберутся сами. Все откатывается кнопкой «Отменить» в сообщении внизу или вверху справа.</span></div>`,
[{text: "Оставить"}, {text: ic("trash") + "Удалить", cls: "danger", onClick: async () => {
const files = $("#ndFiles") ? $("#ndFiles").checked : false;
try {
const r = await api("/api/op", {repo: S.repo, sha: S.sha, op: "delete", id, files});
toastUndo(r.message);
ftCache = {};
await load(null, []);
} catch (e) { toast(e.message, "err"); return true; }
}}]);
const info = () => {
const on = $("#ndFiles") && $("#ndFiles").checked;
$("#ndInfo").innerHTML = !fl.length ? `<div class="note warn">${ic("info")}<span>Файлов страниц на диске нет, уберется только из меню.</span></div>`
: !on ? `<div class="note info">${ic("info")}<span>Уберется только из меню, файлы останутся на диске.</span></div>`
: `<div class="note warn">${ic("warn")}<span>${d.tracked ? `Файлов в git: ${d.tracked}. В коммите они удалятся и из репозитория.` : "Этих файлов нет в git, они просто исчезнут."}
${d.other_nav.length ? `<br>Эти же файлы есть в меню еще в других местах (${d.other_nav.length}), оттуда они тоже уберутся.` : ""}
${d.dirs.length ? `<br>Папки удалятся целиком, в них не останется страниц: ${d.dirs.map(x => "<b>" + esc(S.docs_dir + "/" + x) + "</b>").join(", ")}${d.extra ? `, вместе с прочими файлами (${d.extra}): ${d.extra_list.map(esc).join(", ")}${d.extra > d.extra_list.length ? " ..." : ""}` : ""}.` : ""}</span></div>`;
};
if ($("#ndFiles")) $("#ndFiles").onchange = info;
info();
}
const TR = {а:"a",б:"b",в:"v",г:"g",д:"d",е:"e",ё:"e",ж:"zh",з:"z",и:"i",й:"y",к:"k",л:"l",м:"m",н:"n",о:"o",п:"p",р:"r",с:"s",т:"t",у:"u",ф:"f",х:"h",ц:"c",ч:"ch",ш:"sh",щ:"sch",ъ:"",ы:"y",ь:"",э:"e",ю:"yu",я:"ya"};
function slug(s) {
return s.toLowerCase().split("").map(c => TR[c] ?? c).join("").replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "section";
}
function newSection(pk) {
const isV = !!vOf(pk), ch = isV ? vChain(pk) : {id: byKey[pk], key: pk, titles: []};
const pid = ch.id;
const base = hintK(pk).replace(/\/+$/, "");
modal("Новый раздел", `
<div class="small muted">Внутри: <b>${esc(crumbK(pk))}</b></div>
<label class="fl">Название в меню</label><input type="text" id="nsTitle" placeholder="Например: Задание №5">
<label class="fl">Папка внутри ${esc(S.docs_dir)}/ (создастся на диске)</label><input type="text" id="nsDir" list="dirList" value="${esc(base)}">
<label class="check"><input type="radio" name="nsMode" value="empty" checked><span><b>Пустой раздел.</b> <span class="muted">Появится в дереве сразу, а в ${esc(S.yml)} запишется вместе с первой страницей (пустой раздел mkdocs не собирает).</span></span></label>
<label class="check"><input type="radio" name="nsMode" value="index"><span><b>Сразу со страницей «Главная».</b> <span class="muted">Создаст index.md с заголовком раздела и запишет раздел в ${esc(S.yml)}.</span></span></label>`,
[{text: "Отмена"}, {text: ic("folderPlus") + "Создать", cls: "primary", onClick: async () => {
const title = $("#nsTitle").value.trim(), dir = $("#nsDir").value.trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
const withIndex = document.querySelector("input[name=nsMode]:checked").value === "index";
if (!title) { toast("Напиши название раздела", "err"); return true; }
if (pending.some(v => v.pk === pk && v.title === title)) { toast("Такой пустой раздел уже есть", "err"); return true; }
const rootKey = ch.key, path = [...ch.titles, title];
try {
const r = await api("/api/section", {repo: S.repo, sha: S.sha, parent: pid, chain: ch.titles, title, dir, with_index: withIndex});
withIndex ? toastUndo(r.message) : toast(r.message);
openK.add(rootKey);
if (withIndex) {
await load(null);
let node = S.nodes[byKey[rootKey]];
for (const tt of path) { if (!node) break; openK.add(K[node.id]); const c = node.children.find(x => !S.nodes[x].path && S.nodes[x].title === tt); node = c === undefined ? null : S.nodes[c]; }
if (node) { openK.add(K[node.id]); renderTree([K[node.id]]); }
} else {
pending.push({pk, title, dir});
checkedK.add(VK(pk, title));
if (src && src.kind === "upload" && !dirTouched) $("#dir").value = dir;
await load(null);
renderTree([VK(pk, title)]);
}
} catch (e) { toast(e.message, "err"); return true; }
}}]);
let dirTouchedNs = false;
$("#nsDir").oninput = () => { dirTouchedNs = true; };
$("#nsTitle").oninput = () => { if (!dirTouchedNs) $("#nsDir").value = (base ? base + "/" : "") + slug($("#nsTitle").value); };
withFolderPicker($("#nsDir"));
$("#nsTitle").onkeydown = e => { if (e.key === "Enter") document.querySelectorAll("#mFoot button")[1].click(); };
setTimeout(() => $("#nsTitle").focus(), 50);
}
function startRename(row, id) {
const n = S.nodes[id];
row.classList.add("editing");
const t = row.querySelector(".ttl");
t.innerHTML = `<input type="text" class="ren" value="${esc(n.title)}">`;
const inp = t.querySelector("input"); inp.focus(); inp.select();
let done = false;
const finish = save => {
if (done) return; done = true;
const v = inp.value.trim();
if (save && v && v !== n.title) op("rename", id, v); else renderTree();
};
inp.addEventListener("keydown", e => { if (e.key === "Enter") finish(true); if (e.key === "Escape") finish(false); });
inp.addEventListener("blur", () => finish(true));
}
async function op(kind, id, title) {
const n = S.nodes[id];
const parentKey = K[n.parent];
try {
const r = await api("/api/op", {repo: S.repo, sha: S.sha, op: kind, id, title});
const newKey = kind === "rename" ? parentKey + "\u0001" + (n.path || title) : K[id];
if (kind === "rename" && !n.path) {
[...openK].forEach(k => { if (k === K[id] || k.startsWith(K[id] + "\u0001")) { openK.delete(k); openK.add(newKey + k.slice(K[id].length)); } });
[...checkedK].forEach(k => { if (k === K[id]) { checkedK.delete(k); checkedK.add(newKey); } });
}
toastUndo(r.message);
await load(null, kind === "delete" ? [] : [newKey]);
} catch (e) { toast(e.message, "err"); renderTree(); }
}
let st;
$("#search").addEventListener("input", e => { search = e.target.value; clearTimeout(st); st = setTimeout(renderTree, 120); });
$("#expandBtn").onclick = () => { S.nodes.forEach(n => !n.path && openK.add(K[n.id])); renderTree(); };
$("#collapseBtn").onclick = () => { openK = new Set([K[0]]); S.nodes[0].children.forEach(c => openK.add(K[c])); renderTree(); };
$("#pagesBtn").onclick = () => { showPages = !showPages; $("#pagesBtn").style.opacity = showPages ? 1 : .5; renderTree(); };
$("#ymlEditBtn").innerHTML = ic("code");
$("#ymlEditBtn").onclick = () => openEditor("@mkdocs.yml");
$("#expandBtn").innerHTML = ic("expand"); $("#collapseBtn").innerHTML = ic("collapse"); $("#pagesBtn").innerHTML = ic("eye");
/* ================= ползунки ширины ================= */
const memPrefs = {};
function prefGet(k) { try { const v = localStorage.getItem(k); if (v !== null) return v; } catch (e) {} return memPrefs[k] ?? null; }
function prefSet(k, v) { memPrefs[k] = v; try { localStorage.setItem(k, v); } catch (e) {} }
function makeSplitter(split, box, cssVar, key, def, min, max) {
const apply = v => box.style.setProperty(cssVar, v + "%");
const saved = parseFloat(prefGet(key));
apply(isNaN(saved) ? def : saved);
split.addEventListener("pointerdown", e => {
if (e.button !== 0) return;
e.preventDefault();
split.setPointerCapture(e.pointerId);
split.classList.add("drag"); document.body.classList.add("dragging");
const r = box.getBoundingClientRect();
const move = ev => {
const pct = Math.min(max, Math.max(min, (ev.clientX - r.left) / r.width * 100));
apply(pct.toFixed(1)); prefSet(key, pct.toFixed(1));
};
const up = () => {
split.classList.remove("drag"); document.body.classList.remove("dragging");