-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathdatasorter.html
More file actions
1720 lines (1446 loc) · 64.1 KB
/
Copy pathdatasorter.html
File metadata and controls
1720 lines (1446 loc) · 64.1 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="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SimpleArmory JSON Editor</title>
<!-- SortableJS for Drag and Drop -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.0/Sortable.min.js"></script>
<!-- Wowhead Tooltips -->
<script>const whTooltips = {colorLinks: true, iconizeLinks: false, renameLinks: false};</script>
<script src="https://wow.zamimg.com/js/tooltips.js"></script>
<style>
:root {
--bg-dark: #1e1e1e;
--bg-panel: #2b2b2b;
--bg-sidebar: #252526;
--border: #444;
--accent: #f8b700;
--text-main: #e0e0e0;
--text-muted: #888;
--card-size: 36px;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: var(--bg-dark);
color: var(--text-main);
margin: 0;
display: flex;
height: 100vh;
overflow: hidden;
width: 100vw; /* Ensure full width usage */
}
/* --- SIDEBAR --- */
.sidebar {
width: 250px;
background: var(--bg-sidebar);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
flex-shrink: 0;
transition: margin-left 0.2s ease-in-out;
margin-left: 0;
height: 100%;
position: relative; /* Ensure it stays in flow */
z-index: 20;
}
.sidebar.hidden {
margin-left: -250px; /* Slide out instead of width: 0 */
border: none;
}
.sidebar-header {
padding: 15px;
border-bottom: 1px solid #333;
display: flex;
flex-direction: column;
gap: 10px;
background: #2d2d30;
flex-shrink: 0;
}
.sidebar-title-row {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
font-weight: bold;
color: #ccc;
text-transform: uppercase;
}
.file-list {
flex-grow: 1;
overflow-y: auto;
padding: 5px 0;
}
.file-item {
padding: 8px 20px;
cursor: pointer;
font-size: 14px;
color: #bbb;
display: flex;
align-items: center;
gap: 8px;
border-left: 3px solid transparent;
}
.file-item:hover {
background-color: #2a2d2e;
color: #fff;
}
.file-item.active {
background-color: #37373d;
color: #fff;
border-left-color: var(--accent);
}
.file-item.dirty::after {
content: '●';
font-size: 10px;
color: var(--accent);
margin-left: auto;
}
/* Sidebar Save Button */
#btn-save-disk {
width: 100%;
justify-content: center;
transition: background-color 0.3s;
}
#btn-save-disk.dirty {
background-color: var(--accent);
color: #000;
border: none;
}
#btn-save-disk:disabled {
background-color: #333;
color: #666;
border: 1px solid #444;
}
/* --- MAIN CONTENT --- */
.main-content {
flex-grow: 1;
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
position: relative;
min-width: 0; /* Prevents flex child from overflowing */
}
/* Controls Area */
.controls {
background: rgba(30, 30, 30, 0.95);
padding: 10px 20px;
border-bottom: 1px solid #333;
z-index: 2000;
display: flex;
gap: 15px;
align-items: center;
flex-shrink: 0;
height: 60px; /* Fixed height for consistency */
box-sizing: border-box;
}
.btn {
background-color: #333;
color: #ddd;
border: 1px solid #555;
padding: 8px 16px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
border-radius: 4px;
transition: all 0.2s;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
min-width: 80px;
white-space: nowrap;
}
.btn:hover:not(:disabled) {
background-color: #444;
color: #fff;
border-color: #777;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-danger { background-color: #d32f2f; border-color: #b71c1c; color: white; }
.btn-danger:hover:not(:disabled) { background-color: #b71c1c; }
.btn-primary { background-color: var(--accent); color: #111; border: none; }
.btn-primary:hover:not(:disabled) { background-color: #e0a600; color: #000; }
.btn-success { background-color: #2e7d32; border-color: #1b5e20; color: white; }
.btn-success:hover:not(:disabled) { background-color: #1b5e20; }
/* Full width button for sidebar */
.btn-block { width: 100%; }
/* --- MODE TOGGLE GROUP --- */
.mode-toggle {
display: flex;
background: #111;
border: 1px solid #444;
border-radius: 6px;
padding: 2px;
gap: 2px;
}
.btn-mode {
background: transparent;
border: none;
color: #888;
padding: 6px 16px;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
font-size: 13px;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s;
}
.btn-mode:hover { color: #fff; background: rgba(255,255,255,0.05); }
.btn-mode#mode-sort.active { background: var(--accent); color: #000; box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
.btn-mode#mode-edit.active { background: #43a047; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
input[type="file"] { display: none; }
/* Scrollable Editor Area */
#editor-scroll {
flex-grow: 1;
overflow-y: auto;
padding: 20px;
position: relative;
}
/* Layout Structure */
.container {
max-width: 1800px;
margin: 0 auto;
padding-bottom: 100px;
}
/* --- HIERARCHY STYLING & PERFORMANCE --- */
.supercat {
margin-bottom: 40px;
padding-left: 10px;
border-left: 2px solid #444;
contain: layout;
transition: box-shadow 0.2s, border-color 0.2s;
}
.cat {
margin-bottom: 40px;
contain: layout style;
transition: box-shadow 0.2s, border-color 0.2s;
}
.subcat-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
align-items: flex-start;
}
.subcat {
display: flex;
flex-direction: column;
max-width: 320px;
min-width: 40px;
contain: layout;
transition: box-shadow 0.2s, background 0.2s;
border-radius: 4px;
}
.editing-target {
box-shadow: 0 0 0 2px var(--accent);
background: rgba(248, 183, 0, 0.05);
z-index: 2500;
position: relative;
}
/* --- HEADERS --- */
.header-row {
display: flex;
align-items: baseline;
gap: 10px;
cursor: grab;
user-select: none;
margin-bottom: 6px;
padding: 4px;
border-radius: 4px;
transition: background-color 0.2s;
}
body.edit-mode .header-row:hover {
background-color: rgba(255, 255, 255, 0.1);
cursor: pointer;
}
.cat > .header-row .header-title { font-size: 1.5em; color: #fff; font-weight: 400; }
.supercat > .header-row .header-title { font-size: 1.8em; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; }
.subcat > .header-row { margin-bottom: 4px; }
.subcat > .header-row .header-title { font-size: 0.95em; color: #999; font-weight: normal; }
.count-badge { font-size: 0.75em; color: #555; display: none; }
.cat > .header-row .count-badge { display: inline-block; }
/* --- ITEM GRID --- */
.item-list {
display: flex;
flex-wrap: wrap;
gap: 2px;
min-height: 40px;
background: transparent;
border: 1px dashed transparent;
border-radius: 4px;
transition: border-color 0.2s;
contain: layout;
}
.faction-list {
display: flex;
flex-direction: column;
gap: 5px;
background: rgba(0,0,0,0.2);
padding: 10px;
border-radius: 4px;
min-height: 40px;
}
.item-list:empty, .item-list.sortable-drag-active {
border-color: #333;
min-width: 40px;
}
/* Individual Item */
.item-card {
width: var(--card-size);
height: var(--card-size);
position: relative;
cursor: grab;
border: 1px solid #000;
border-radius: 0;
background: #000;
box-sizing: border-box;
will-change: transform;
transform: translate3d(0,0,0);
z-index: 1;
}
.item-card:hover {
transform: scale(1.2);
z-index: 1000;
border-color: #fff;
box-shadow: 0 0 5px rgba(0,0,0,0.8);
}
/* Faction Item */
.faction-card {
background: #333;
padding: 8px 12px;
border-radius: 4px;
cursor: grab;
border: 1px solid #444;
color: #ddd;
font-size: 14px;
display: flex;
align-items: center;
}
.faction-card:hover {
background: #444;
border-color: #666;
}
/* Edit Mode Styles */
body.edit-mode .item-card { cursor: pointer; }
body.edit-mode .item-card:hover { border-color: #43a047; box-shadow: 0 0 8px rgba(67, 160, 71, 0.6); }
/* Selected State */
body.edit-mode .item-card.selected {
border-color: #fff;
box-shadow: 0 0 0 2px #43a047, 0 0 10px rgba(67, 160, 71, 0.8);
z-index: 100 !important;
}
body.edit-mode .header-row { cursor: pointer; }
.item-icon { width: 100%; height: 100%; object-fit: cover; display: block; }
/* --- INDICATORS --- */
.indicator {
position: absolute;
z-index: 5;
pointer-events: none;
display: flex;
align-items: center;
justify-content: center;
font-family: sans-serif;
font-weight: 700;
line-height: 1;
box-shadow: 0 1px 3px rgba(0,0,0,0.8);
background: rgba(0, 0, 0, 0.85);
padding: 1px 2px;
font-size: 10px;
}
.ind-new { top: 0; left: 0; color: #00ff00; border-radius: 0 0 3px 0; border-right: 1px solid #006400; border-bottom: 1px solid #006400; }
.ind-dupe { bottom: 0; right: 0; color: #00e5ff; font-size: 9px; border-radius: 3px 0 0 0; border-left: 1px solid #00838f; border-top: 1px solid #00838f; }
.ind-status { top: 0; right: 0; border-radius: 0 0 0 3px; border-left: 1px solid #555; border-bottom: 1px solid #555; }
.status-unob { color: #ff3333; border-color: #b71c1c; }
.status-clock { color: #ffaa00; border-color: #e65100; }
.status-resale { color: #ffd700; border-color: #ff8f00; }
.ind-side { bottom: 0; left: 0; font-size: 10px; padding: 0 2px; border-radius: 0 3px 0 0; border-right: 1px solid #555; border-top: 1px solid #555; }
.side-alliance { color: #2196f3; border-color: #0d47a1; }
.side-horde { color: #f44336; border-color: #b71c1c; }
/* Tooltip mimic */
.item-card::after {
content: attr(data-title);
position: absolute;
bottom: 120%;
left: 50%;
transform: translateX(-50%);
background: rgba(10,10,10,0.95);
color: var(--accent);
padding: 4px 8px;
border-radius: 2px;
white-space: nowrap;
font-size: 12px;
pointer-events: none;
opacity: 0;
transition: opacity 0.1s;
z-index: 1000;
border: 1px solid #333;
box-shadow: 0 4px 6px rgba(0,0,0,0.5);
}
/* Only show custom tooltip if NOT in edit mode OR if it's the preview (handled specially) */
/* UPDATE: Per user request, show simple tooltip everywhere except modal preview */
.item-card:hover::after { opacity: 1; }
#editor-preview .item-card:hover::after { opacity: 0 !important; }
/* Sortable States */
.sortable-ghost { opacity: 0.2; background: var(--accent); }
.sortable-drag { cursor: grabbing; }
/* Empty State */
.empty-state {
text-align: center;
padding: 80px;
color: #555;
border: 2px dashed #333;
border-radius: 10px;
margin-top: 40px;
}
/* --- ADD BUTTONS --- */
.add-btn {
border: 2px dashed #444;
color: #888;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 14px;
transition: all 0.2s;
border-radius: 4px;
box-sizing: border-box;
}
.add-btn:hover {
border-color: var(--accent);
color: var(--accent);
background: rgba(255,255,255,0.05);
}
body:not(.edit-mode) .add-btn { display: none !important; }
.add-supercat { width: 100%; padding: 20px; margin-top: 20px; text-transform: uppercase; font-size: 16px; }
.add-cat { width: 100%; padding: 15px; margin-top: 15px; font-size: 16px; }
.add-subcat { width: 100px; height: 70px; flex-shrink: 0; margin-top: 0; font-size: 28px; }
/* --- POPUPS --- */
.overlay {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
z-index: 2999;
display: none;
background: rgba(0,0,0,0.5);
}
.popup {
position: fixed;
background: #2b2b2b;
border: 1px solid #555;
border-radius: 6px;
padding: 15px;
box-shadow: 0 5px 25px rgba(0,0,0,0.8);
z-index: 3000;
display: none;
}
#prop-editor { min-width: 220px; }
#struct-editor { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; }
.editor-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #444; }
h4 { margin: 0; font-size: 14px; color: var(--accent); border-bottom: none; padding-bottom: 0; white-space: normal; line-height: 1.3; overflow: visible; }
input[type="text"] {
width: 100%; padding: 8px; background: #111; border: 1px solid #444; color: #fff;
border-radius: 4px; margin-bottom: 15px; box-sizing: border-box;
}
input[type="text"]:focus { border-color: var(--accent); outline: none; }
#editor-preview { flex-shrink: 0; }
/* Link styling for preview */
#editor-preview a { display: block; border: 1px solid #000; transition: border-color 0.2s; }
#editor-preview a:hover { border-color: var(--accent); }
#editor-preview img { display: block; width: 36px; height: 36px; }
.prop-row { display: flex; align-items: center; margin-bottom: 8px; cursor: pointer; user-select: none; }
.prop-row:hover { background: rgba(255,255,255,0.05); }
.prop-row input { margin-right: 10px; cursor: pointer; }
.prop-row label { font-size: 13px; cursor: pointer; flex-grow: 1; }
.prop-section-label { font-size: 11px; color: #999; text-transform: uppercase; margin: 10px 0 5px 0; border-bottom: 1px solid #444; padding-bottom: 2px; }
.btn-icon { min-width: 32px !important; width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
/* Visibility utility classes */
.d-none { display: none !important; }
.d-flex { display: flex !important; }
</style>
</head>
<body>
<!-- Sidebar for Folder Mode -->
<div id="sidebar" class="sidebar hidden">
<div class="sidebar-header">
<div class="sidebar-title-row">
<span>Project Files</span>
<button class="btn btn-icon" style="min-width:24px;width:24px;height:24px;font-size:12px;" onclick="refreshDirectory()" title="Refresh">↻</button>
</div>
<!-- Moved Save Button to Sidebar -->
<button class="btn btn-primary btn-block" id="btn-save-disk" onclick="saveToDisk()" disabled title="Save (Ctrl+S)">
💾 Save Changes
</button>
</div>
<div id="file-list" class="file-list">
<!-- Files injected here -->
</div>
</div>
<div class="main-content">
<div class="controls">
<!-- Start Group: Context Sensitive -->
<!-- Project Mode Trigger -->
<div id="group-init">
<div style="display:flex; gap:10px;">
<button class="btn btn-primary" id="btn-open-folder">Open Project Folder</button>
<label class="btn" for="fileInput">Upload JSON</label>
<input type="file" id="fileInput" accept=".json">
</div>
</div>
<!-- Manual Mode Export (Visible only when file loaded manually) -->
<div id="group-manual-export" class="d-none">
<button class="btn" id="btn-export" onclick="exportJSON()">Download JSON</button>
</div>
<!-- Separator (Visible when file loaded) -->
<div id="controls-sep" class="d-none" style="width: 1px; height: 20px; background: #555; margin: 0 10px;"></div>
<!-- Editor Modes (Visible when file loaded) -->
<div id="group-modes" class="mode-toggle d-none">
<button id="mode-sort" class="btn-mode active" onclick="setMode('sort')">
<span style="font-size:16px">✥</span> Sorting
</button>
<button id="mode-edit" class="btn-mode" onclick="setMode('edit')">
<span style="font-size:16px">✎</span> Editing
</button>
</div>
<div id="status" style="margin-left: auto; color: var(--accent); font-weight: 600; font-size: 14px;">Waiting for file...</div>
</div>
<div id="editor-scroll">
<div id="editor-root" class="container">
<div class="empty-state">
<h2>SimpleArmory Layout Editor</h2>
<p style="margin-bottom:20px; color:#aaa;">A tool for organizing World of Warcraft collection data.</p>
<div style="display:inline-flex; gap:20px; text-align:left;">
<div>
<strong style="color:var(--accent)">Project Mode</strong><br>
- Edit files directly on disk<br>
- Best for Chrome/Edge users
</div>
<div style="border-left:1px solid #444; padding-left:20px;">
<strong style="color:var(--accent)">Manual Mode</strong><br>
- Upload/Download files<br>
- Works in all browsers
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Overlays -->
<div id="prop-overlay" class="overlay" onclick="closeAllEditors()"></div>
<!-- Item Property Editor -->
<div id="prop-editor" class="popup">
<div class="editor-header">
<div id="editor-preview"></div>
<h4 id="editor-title">Item Name</h4>
</div>
<div class="prop-section-label">Flags</div>
<label class="prop-row"><input type="checkbox" id="chk-new"> <label for="chk-new">New (<span style="color:#00ff00; background:black; padding:0 2px;">★</span>)</label></label>
<label class="prop-row"><input type="checkbox" id="chk-dupe"> <label for="chk-dupe">Dupe (<span style="color:#00e5ff; background:black; padding:0 2px;">⧉</span>)</label></label>
<div class="prop-section-label">Availability Status</div>
<label class="prop-row"><input type="radio" name="status" value="obtainable" id="rad-obt"> <label for="rad-obt">Obtainable (Default)</label></label>
<label class="prop-row"><input type="radio" name="status" value="resale" id="rad-resale"> <label for="rad-resale">Resale (<span style="color:#ffd700; background:black; padding:0 2px;">$</span>)</label></label>
<label class="prop-row"><input type="radio" name="status" value="unobtainable" id="rad-unob"> <label for="rad-unob">Not Obtainable (<span style="color:#ff3333; background:black; padding:0 2px;">✖</span>)</label></label>
<label class="prop-row"><input type="radio" name="status" value="unreleased" id="rad-rel"> <label for="rad-rel">Not Released (<span style="color:#ffaa00; background:black; padding:0 2px;">⏲</span>)</label></label>
<div class="prop-section-label">Faction</div>
<label class="prop-row"><input type="radio" name="side" value="neutral" id="rad-neutral"> <label for="rad-neutral">Neutral (Default)</label></label>
<label class="prop-row"><input type="radio" name="side" value="A" id="rad-alliance"> <label for="rad-alliance">Alliance (<span style="color:#2196f3; background:black; padding:0 2px;">A</span>)</label></label>
<label class="prop-row"><input type="radio" name="side" value="H" id="rad-horde"> <label for="rad-horde">Horde (<span style="color:#f44336; background:black; padding:0 2px;">H</span>)</label></label>
<div style="margin-top: 15px; display: flex; justify-content: flex-end;">
<button class="btn btn-danger btn-icon" id="btn-delete-item" title="Delete Item">🗑</button>
</div>
</div>
<!-- Structure Editor (Renaming/Deleting Categories) -->
<div id="struct-editor" class="popup">
<h4 id="struct-title">Edit Category</h4>
<input type="text" id="struct-name" placeholder="Category Name" autocomplete="off">
<div style="display:flex; justify-content:space-between; margin-top:10px;">
<button id="btn-delete-struct" class="btn btn-danger" type="button">Delete</button>
<button id="btn-save-struct" class="btn btn-primary" type="button">Save</button>
</div>
</div>
<script>
let currentFileStructure = null;
let currentFileName = "data.json";
let isEditMode = false;
let activeSortables = [];
let deleteConfirmTimer = null;
// Editor State
let currentEditingItemElement = null;
let currentPreviewElement = null;
let currentEditingStructElement = null;
let selectedElements = new Set();
// File System API State
let dirHandle = null;
let activeFileHandle = null;
let isDirty = false;
const fileInput = document.getElementById('fileInput');
const root = document.getElementById('editor-root');
const status = document.getElementById('status');
const sidebar = document.getElementById('sidebar');
const fileList = document.getElementById('file-list');
const btnSaveDisk = document.getElementById('btn-save-disk');
const btnExport = document.getElementById('btn-export');
// Popup Elements
const propEditor = document.getElementById('prop-editor');
const structEditor = document.getElementById('struct-editor');
const propOverlay = document.getElementById('prop-overlay');
// Prop Editor Fields
const editorTitle = document.getElementById('editor-title');
const editorPreview = document.getElementById('editor-preview');
const chkNew = document.getElementById('chk-new');
const chkDupe = document.getElementById('chk-dupe');
const radiosStatus = document.getElementsByName('status');
const radiosSide = document.getElementsByName('side');
const btnDeleteItem = document.getElementById('btn-delete-item');
// Struct Editor Fields
const structTitle = document.getElementById('struct-title');
const structNameInput = document.getElementById('struct-name');
const btnDeleteStruct = document.getElementById('btn-delete-struct');
const btnSaveStruct = document.getElementById('btn-save-struct');
fileInput.addEventListener('change', handleFileUpload);
document.getElementById('btn-open-folder').addEventListener('click', openDirectory);
chkNew.addEventListener('change', saveItemChanges);
chkDupe.addEventListener('change', saveItemChanges);
radiosStatus.forEach(r => r.addEventListener('change', saveItemChanges));
radiosSide.forEach(r => r.addEventListener('change', saveItemChanges));
btnDeleteStruct.addEventListener('click', deleteStructure);
btnSaveStruct.addEventListener('click', saveStructure);
btnDeleteItem.addEventListener('click', deleteItem);
structNameInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') saveStructure();
});
// Global Keyboard Shortcut for Save
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
if (activeFileHandle) {
saveToDisk();
} else if(currentFileStructure) {
exportJSON();
}
}
});
// --- IndexedDB Persistence ---
const DB_NAME = 'SimpleArmoryEditor';
const STORE_NAME = 'settings';
function getDB() {
return new Promise((resolve, reject) => {
const request = indexedDB.open(DB_NAME, 1);
request.onupgradeneeded = (event) => {
event.target.result.createObjectStore(STORE_NAME);
};
request.onsuccess = (event) => resolve(event.target.result);
request.onerror = (event) => reject(event.target.error);
});
}
async function saveDirHandle(handle) {
const db = await getDB();
const tx = db.transaction(STORE_NAME, 'readwrite');
tx.objectStore(STORE_NAME).put(handle, 'projectDir');
}
async function getDirHandle() {
const db = await getDB();
return new Promise((resolve) => {
const tx = db.transaction(STORE_NAME, 'readonly');
const req = tx.objectStore(STORE_NAME).get('projectDir');
req.onsuccess = () => resolve(req.result);
req.onerror = () => resolve(null);
});
}
// --- File System Access API ---
async function openDirectory() {
try {
// Feature Detection specifically for permission model
const options = { mode: 'readwrite' };
try {
const lastHandle = await getDirHandle();
if (lastHandle) options.startIn = lastHandle;
} catch(e) { console.log('No saved handle'); }
dirHandle = await window.showDirectoryPicker(options);
await saveDirHandle(dirHandle);
sidebar.classList.remove('hidden');
// Hide Init Buttons, Show File List UI
setAppState('project_active');
await refreshDirectory();
} catch (err) {
// If it's a security error (like in iframe), fallback gracefully
// Catch all security errors including those from subframes
if(err.name === 'SecurityError' || err.message.includes('sub frames') || err.message.includes('user gesture')) {
alert("Project Folder access requires running this file directly in the browser (not in a preview frame). \n\nPlease use 'Upload JSON' for now, or download this HTML file and open it locally.");
} else if (err.name !== 'AbortError') {
console.error(err);
}
}
}
async function refreshDirectory() {
if (!dirHandle) return;
fileList.innerHTML = '';
const entries = [];
for await (const entry of dirHandle.values()) {
if (entry.kind === 'file' && entry.name.endsWith('.json')) {
entries.push(entry);
}
}
entries.sort((a, b) => a.name.localeCompare(b.name));
entries.forEach(entry => {
const div = document.createElement('div');
div.className = 'file-item';
div.textContent = entry.name;
div.onclick = () => loadFileFromHandle(entry, div);
fileList.appendChild(div);
});
}
async function loadFileFromHandle(handle, element) {
// Guard against discarding unsaved changes
if (isDirty) {
if (!confirm("You have unsaved changes in the current file. switching files will discard them.\n\nAre you sure you want to continue?")) {
return;
}
}
activeFileHandle = handle;
currentFileName = handle.name;
document.querySelectorAll('.file-item').forEach(el => el.classList.remove('active'));
element.classList.add('active');
try {
const file = await handle.getFile();
const text = await file.text();
const json = JSON.parse(text);
renderEditor(json);
status.textContent = `Editing: ${handle.name}`;
setMode('sort');
markDirty(false);
btnSaveDisk.disabled = false;
} catch (err) {
console.error(err);
alert("Error reading file.");
}
}
async function saveToDisk() {
if (!activeFileHandle) return;
try {
const output = getCurrentJSON();
if (!output) return;
const writable = await activeFileHandle.createWritable();
await writable.write(deterministicStringify(output) + '\n');
await writable.close();
markDirty(false);
const originalText = btnSaveDisk.textContent;
btnSaveDisk.textContent = "Saved!";
setTimeout(() => {
if(!isDirty) btnSaveDisk.textContent = "💾 Save Changes";
}, 1500);
} catch (err) {
console.error(err);
alert("Error saving file.");
}
}
function markDirty(dirty) {
isDirty = dirty;
const activeItem = document.querySelector('.file-item.active');
if (activeItem) {
if (dirty) activeItem.classList.add('dirty');
else activeItem.classList.remove('dirty');
}
if(dirty) {
btnSaveDisk.classList.add('dirty');
btnSaveDisk.textContent = "💾 Save Changes *";
} else {
btnSaveDisk.classList.remove('dirty');
btnSaveDisk.textContent = "💾 Save Changes";
}
}
// Guard against closing tab
window.onbeforeunload = function(e) {
if (isDirty) {
e.preventDefault();
e.returnValue = '';
return "You have unsaved changes.";
}
};
// --- Helper: UI State Management ---
function setAppState(state) {
const groupInit = document.getElementById('group-init');
const groupManualExport = document.getElementById('group-manual-export');
const groupModes = document.getElementById('group-modes');
const controlsSep = document.getElementById('controls-sep');
if (state === 'manual_active') {
groupInit.classList.add('d-none');
groupManualExport.classList.remove('d-none');
groupModes.classList.remove('d-none');
controlsSep.classList.remove('d-none');
sidebar.classList.add('hidden');
} else if (state === 'project_active') {
groupInit.classList.add('d-none');
groupManualExport.classList.add('d-none'); // Hide download button in project mode
groupModes.classList.remove('d-none');
controlsSep.classList.remove('d-none');
}
}
// --- Serializer ---
function deterministicStringify(obj) {
function deepSort(value) {
if (Array.isArray(value)) {
return value.map(deepSort);
} else if (value !== null && typeof value === 'object') {
const keys = Object.keys(value);
// Check if map keys are numeric (e.g. "0", "500", "1000")
const isNumeric = keys.length > 0 && keys.every(k => !isNaN(parseFloat(k)) && isFinite(k));
if (isNumeric) {
keys.sort((a, b) => parseFloat(a) - parseFloat(b));
} else {
keys.sort(); // Lexicographical
}
const sorted = {};
keys.forEach(k => {
sorted[k] = deepSort(value[k]);
});
return sorted;
}
return value;
}
return JSON.stringify(deepSort(obj), null, 2);
}
// --- Manual Upload Fallback ---
function handleFileUpload(event) {
const file = event.target.files[0];
if (!file) return;
currentFileName = file.name;
activeFileHandle = null;
const reader = new FileReader();
reader.onload = (e) => {
try {
const json = JSON.parse(e.target.result);
renderEditor(json);
status.textContent = `${file.name} (Manual Mode)`;
setAppState('manual_active');
setMode('sort');
} catch (err) {
alert("Invalid JSON file");
}
};
reader.readAsText(file);
}
function getWowheadUrl(item) {
if (item.wowheadUrl) return item.wowheadUrl;
if (item.spellid) return `https://www.wowhead.com/spell=${item.spellid}`;
if (item.creatureId) return `https://www.wowhead.com/npc=${item.creatureId}`;
if (item.itemId) return `https://www.wowhead.com/item=${item.itemId}`;
if (item.points !== undefined) return `https://www.wowhead.com/achievement=${item.id}`;
return null;
}
function getIconUrl(iconName) {
if (!iconName) return 'https://wow.zamimg.com/images/wow/icons/large/inv_misc_questionmark.jpg';
const cleanName = iconName.replace(/\.(jpg|png)$/i, '').toLowerCase();
return `https://wow.zamimg.com/images/wow/icons/large/${cleanName}.jpg`;
}
// --- Edit Mode Logic ---
function setMode(mode) {
isEditMode = (mode === 'edit');
document.body.classList.toggle('edit-mode', isEditMode);
document.getElementById('mode-sort').classList.toggle('active', mode === 'sort');
document.getElementById('mode-edit').classList.toggle('active', mode === 'edit');
if(!isEditMode) {
closeAllEditors();
clearSelection();
}
activeSortables.forEach(sortable => {
sortable.option("disabled", isEditMode);
});
}
// --- Selection Logic ---
function toggleSelection(element, forceAdd = false) {
if (selectedElements.has(element) && !forceAdd) {