forked from niklasbuschmann/contrast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
2047 lines (1938 loc) · 84.2 KB
/
Copy patheditor.html
File metadata and controls
2047 lines (1938 loc) · 84.2 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
---
title: "المحرر"
layout: default
sitemap: false
---
<style>
/* Override site max-width for full-width editor */
body { max-width: 100% !important; }
main#main-content { padding: 0 !important; animation: none !important; }
.editor-container {
display: flex;
/* --header-h is set by site.js; fall back to 4rem on first paint */
height: calc(100dvh - var(--header-h, 4rem));
overflow: hidden;
}
/* Sidebar (drafts list) */
.editor-sidebar {
width: 220px;
flex-shrink: 0;
background: var(--bg-surface);
border-inline-end: 1px solid var(--border-subtle);
display: flex;
flex-direction: column;
overflow: hidden;
transition: width 0.18s ease;
}
.editor-sidebar.collapsed { width: 0; border-inline-end: none; }
.sidebar-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 12px;
border-bottom: 1px solid var(--border-subtle);
font-size: 0.75em;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.05em;
flex-shrink: 0;
}
.sidebar-header button {
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
padding: 4px 10px;
border-radius: 4px;
font-size: 1.05em;
line-height: 1;
}
.sidebar-header button:hover { background: var(--border-subtle); color: var(--text-primary); }
.drafts-list {
flex: 1;
overflow-y: auto;
padding: 6px;
}
.draft-item {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 10px;
border-radius: 6px;
cursor: pointer;
color: var(--text-secondary);
font-size: 0.85em;
transition: background 0.15s, color 0.15s;
}
.draft-item:hover { background: rgba(127, 127, 127, 0.08); color: var(--text-primary); }
.draft-item.active { background: var(--tag-bg); color: var(--text-primary); }
.draft-title {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.draft-delete {
background: transparent;
border: none;
color: var(--text-tertiary);
cursor: pointer;
padding: 2px 6px;
border-radius: 3px;
visibility: hidden;
font-size: 1em;
line-height: 1;
}
.draft-item:hover .draft-delete { visibility: visible; }
.draft-delete:hover { color: #ef4444; background: rgba(239,68,68,0.1); }
.draft-empty { padding: 12px; color: var(--text-tertiary); font-size: 0.8em; text-align: center; }
.editor-main {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
overflow: hidden;
}
/* Toolbar */
.editor-toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
padding: 8px 12px;
background: var(--bg-surface);
border-bottom: 1px solid var(--border-subtle);
user-select: none;
overflow-x: auto;
}
.toolbar-group {
display: flex;
gap: 2px;
padding-inline-end: 8px;
border-inline-end: 1px solid var(--border-subtle);
}
.toolbar-group:last-child {
border-inline-end: none;
margin-inline-start: auto;
}
.editor-toolbar button {
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
padding: 6px 8px;
border-radius: 6px;
transition: background 0.15s, color 0.15s;
display: flex;
align-items: center;
justify-content: center;
font-family: inherit;
font-size: 0.8em;
font-weight: 600;
line-height: 1;
min-width: 32px;
white-space: nowrap;
}
.editor-toolbar button:hover {
background: var(--border-subtle);
color: var(--text-primary);
}
.editor-toolbar button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 1px;
}
.editor-toolbar button:active {
background: var(--border-default);
}
.editor-toolbar button svg {
width: 16px;
height: 16px;
stroke: currentColor;
fill: none;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
/* Mobile tab toggle */
.mobile-tabs {
display: none;
background: var(--bg-surface);
border-bottom: 1px solid var(--border-subtle);
}
.mobile-tabs button {
flex: 1;
padding: 10px;
background: transparent;
border: none;
color: var(--text-secondary);
font-family: inherit;
font-size: 0.85em;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: color 0.15s, border-color 0.15s;
}
.mobile-tabs button.active {
color: var(--text-primary);
border-bottom-color: var(--accent);
}
/* Split panes */
.editor-panes {
display: flex;
flex: 1;
min-height: 0;
}
.editor-input-pane,
.editor-preview-pane {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.pane-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: var(--space-3);
padding: 6px 16px;
background: var(--bg-surface-hover);
font-size: 0.75em;
color: var(--text-tertiary);
border-bottom: 1px solid var(--border-subtle);
user-select: none;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.pane-header input.draft-name {
background: transparent;
border: none;
color: var(--text-primary);
font-family: inherit;
font-size: 0.95em;
text-transform: none;
letter-spacing: 0;
font-weight: 600;
outline: none;
min-width: 0;
flex: 1;
padding: 2px 4px;
border-radius: 4px;
}
.pane-header input.draft-name:focus {
background: rgba(127, 127, 127, 0.08);
}
.autosave-indicator {
color: var(--accent);
opacity: 0;
transition: opacity 0.3s, color 0.2s;
text-transform: none;
letter-spacing: 0;
flex-shrink: 0;
}
.autosave-indicator.visible { opacity: 1; }
.autosave-indicator.error { color: #ef4444; opacity: 1 !important; font-weight: 600; }
/* Textarea */
#md-input {
flex: 1;
background: var(--bg-base);
color: var(--text-primary);
border: none;
resize: none;
padding: 20px;
font-family: "Cairo", ui-monospace, "Cascadia Mono", "Consolas", monospace;
font-size: 0.95em;
line-height: 1.8;
direction: rtl;
outline: none;
tab-size: 2;
}
#md-input::placeholder { color: var(--text-tertiary); }
#md-input.drag-over {
background: var(--tag-bg);
outline: 2px dashed var(--accent);
outline-offset: -8px;
}
/* Resize handle */
.editor-resize-handle {
width: 4px;
cursor: col-resize;
background: var(--border-subtle);
transition: background 0.2s;
flex-shrink: 0;
}
.editor-resize-handle:hover,
.editor-resize-handle.dragging {
background: var(--accent);
}
/* Preview */
.preview-content {
flex: 1;
overflow-y: auto;
padding: 20px;
direction: rtl;
line-height: 1.7;
background: var(--bg-base);
border-inline-start: 1px solid var(--border-subtle);
}
.preview-content h1 { font-size: 1.8em; font-weight: 700; margin: 0.8em 0 0.4em; color: var(--text-primary); }
.preview-content h2 { font-size: 1.4em; font-weight: 700; margin: 0.8em 0 0.4em; color: var(--text-primary); }
.preview-content h3 { font-size: 1.15em; font-weight: 600; margin: 0.6em 0 0.3em; color: var(--text-primary); }
.preview-content p { margin: 0.6em 0; color: var(--text-primary); }
.preview-content a { color: var(--accent); text-decoration: none; }
.preview-content a:hover { text-decoration: underline; }
.preview-content code {
background: var(--bg-elevated);
padding: 2px 6px;
border-radius: 4px;
font-size: 0.9em;
font-family: "Courier New", monospace;
}
.preview-content pre {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 8px;
padding: 16px;
overflow-x: auto;
margin: 1em 0;
direction: ltr;
text-align: left;
}
.preview-content pre code { background: none; padding: 0; }
.preview-content blockquote {
border-inline-start: 3px solid var(--accent);
padding: 0.5em 1em;
margin: 1em 0;
background: var(--tag-bg);
border-radius: 0 8px 8px 0;
color: var(--text-secondary);
}
.preview-content table {
width: 100%;
border-collapse: collapse;
margin: 1em 0;
}
.preview-content th, .preview-content td {
border: 1px solid var(--border-default);
padding: 8px 12px;
text-align: right;
}
.preview-content th {
background: var(--bg-surface);
font-weight: 600;
}
.preview-content img { max-width: 100%; border-radius: 8px; }
.preview-content hr {
border: none;
border-top: 1px solid var(--border-default);
margin: 1.5em 0;
}
.preview-content ul, .preview-content ol {
padding-inline-start: 1.5em;
margin: 0.5em 0;
}
.preview-content li { margin: 0.3em 0; }
/* Empty state */
.preview-empty {
color: var(--text-tertiary);
text-align: center;
margin-top: 30vh;
font-size: 0.9em;
}
/* Toast */
.editor-toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: var(--bg-elevated);
color: var(--text-primary);
padding: 10px 20px;
border-radius: 8px;
border: 1px solid var(--border-default);
font-size: 0.85em;
font-family: inherit;
z-index: 300;
transition: transform 0.3s ease;
pointer-events: none;
max-width: 90vw;
text-align: center;
}
.editor-toast.visible { transform: translateX(-50%) translateY(0); }
.editor-toast.error { border-color: rgba(239,68,68,0.4); }
.editor-toast.success { border-color: rgba(34,197,94,0.4); }
/* Publish button */
.editor-toolbar .btn-publish {
background: var(--accent);
color: #fff;
padding: 6px 14px;
border-radius: 6px;
gap: 6px;
}
.editor-toolbar .btn-publish:hover { background: var(--accent-hover); }
.editor-toolbar #btn-export-post:hover { background: #16a34a; }
.editor-toolbar .btn-settings { color: var(--text-tertiary); }
.editor-toolbar .btn-settings:hover { color: var(--text-secondary); }
/* Modal overlay */
.modal-overlay {
display: none;
position: fixed;
inset: 0;
background: rgba(0,0,0,0.7);
backdrop-filter: blur(4px);
z-index: 200;
align-items: center;
justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
background: var(--bg-surface);
border: 1px solid var(--border-default);
border-radius: 12px;
width: 90%;
max-width: 480px;
max-height: 90vh;
overflow-y: auto;
padding: 24px;
direction: rtl;
}
.modal h3 {
margin: 0 0 20px;
font-size: 1.1em;
color: var(--text-primary);
}
.modal label {
display: block;
font-size: 0.8em;
color: var(--text-secondary);
margin-bottom: 6px;
}
.modal input, .modal textarea {
width: 100%;
background: var(--bg-base);
border: 1px solid var(--border-default);
border-radius: 8px;
padding: 10px 12px;
color: var(--text-primary);
font-family: inherit;
font-size: 0.9em;
margin-bottom: 16px;
outline: none;
box-sizing: border-box;
transition: border-color 0.15s;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; min-height: 60px; }
.modal-actions {
display: flex;
gap: 8px;
justify-content: flex-start;
margin-top: 8px;
}
.modal-actions button {
padding: 10px 20px;
border-radius: 8px;
border: none;
font-family: inherit;
font-size: 0.9em;
cursor: pointer;
transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-elevated); color: var(--text-secondary); }
.btn-secondary:hover { background: var(--bg-surface-hover); }
/* Token status */
.token-status {
display: flex;
align-items: center;
gap: 6px;
font-size: 0.75em;
margin-bottom: 16px;
padding: 8px 12px;
border-radius: 8px;
background: var(--bg-base);
}
.token-status.connected { color: #22c55e; }
.token-status.disconnected { color: #ef4444; }
.token-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
}
.token-remove {
margin-inline-start: auto;
background: none;
border: none;
color: #ef4444;
cursor: pointer;
font-size: 0.9em;
padding: 2px 8px;
}
.token-remove:hover { text-decoration: underline; }
.token-help {
font-size: 0.75em;
color: var(--text-tertiary);
margin-bottom: 16px;
line-height: 1.6;
}
.token-help a { color: var(--accent); text-decoration: none; }
.token-help a:hover { text-decoration: underline; }
.token-help p { margin: 4px 0; }
.token-help ul { margin: 4px 0; padding-inline-start: 1.2em; }
.token-help li { margin: 2px 0; }
/* Mobile */
@media (max-width: 768px) {
.editor-sidebar { position: absolute; top: 0; bottom: 0; inset-inline-end: 0; z-index: 50; box-shadow: -4px 0 12px rgba(0,0,0,0.4); }
.editor-sidebar.collapsed { display: none; }
.mobile-tabs { display: flex; }
.editor-resize-handle { display: none; }
.editor-panes { flex-direction: column; }
.editor-input-pane.hidden,
.editor-preview-pane.hidden { display: none; }
.preview-content { border-inline-start: none; border-top: 1px solid var(--border-subtle); }
.toolbar-group:last-child { margin-inline-start: 0; }
}
/* Open-published-post picker */
#open-post-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.open-post-item { text-align: start; background: var(--bg-base); border: 1px solid var(--border-subtle); color: var(--text-primary); border-radius: 8px; padding: 10px 12px; cursor: pointer; font-family: inherit; font-size: 0.85em; transition: background 0.15s, border-color 0.15s; }
.open-post-item:hover { background: var(--bg-surface-hover); border-color: var(--border-default); }
.draft-item.draft-linked .draft-title::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #0ea5e9; margin-inline-end: 6px; vertical-align: middle; }
</style>
<div class="editor-container">
<!-- Sidebar: drafts — collapsed by default on mobile via JS -->
<aside class="editor-sidebar" id="editor-sidebar" aria-label="المسودات">
<div class="sidebar-header">
<span>المسودات</span>
<button type="button" id="btn-new-draft" title="مسودة جديدة" aria-label="مسودة جديدة">+</button>
</div>
<div class="drafts-list" id="drafts-list"></div>
</aside>
<div class="editor-main">
<!-- Toolbar -->
<div class="editor-toolbar" role="toolbar" aria-label="أدوات التحرير">
<div class="toolbar-group">
<button type="button" data-action="toggle-sidebar" title="المسودات" aria-label="المسودات"><svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg></button>
</div>
<div class="toolbar-group">
<button type="button" data-action="h1" title="عنوان 1">H1</button>
<button type="button" data-action="h2" title="عنوان 2">H2</button>
<button type="button" data-action="h3" title="عنوان 3">H3</button>
</div>
<div class="toolbar-group">
<button type="button" data-action="bold" title="عريض (Ctrl+B)" aria-label="عريض"><svg viewBox="0 0 24 24"><path d="M6 4h8a4 4 0 0 1 0 8H6zM6 12h9a4 4 0 0 1 0 8H6z"/></svg></button>
<button type="button" data-action="italic" title="مائل (Ctrl+I)" aria-label="مائل"><svg viewBox="0 0 24 24"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg></button>
<button type="button" data-action="strike" title="شطب" aria-label="شطب"><svg viewBox="0 0 24 24"><line x1="4" y1="12" x2="20" y2="12"/><path d="M17.3 4.9c-.5-.4-1.3-.9-2.7-.9-2.5 0-3.8 1.7-3.8 3 0 2.1 1.6 2.8 3.5 3.5"/><path d="M8.3 15.1c0 2 1.5 3.9 4.1 3.9 1.3 0 2.5-.5 3.2-1.3"/></svg></button>
<button type="button" data-action="code" title="كود (Ctrl+E)" aria-label="كود"><svg viewBox="0 0 24 24"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg></button>
</div>
<div class="toolbar-group">
<button type="button" data-action="link" title="رابط (Ctrl+K)" aria-label="رابط"><svg viewBox="0 0 24 24"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7.1-7.1l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7.1 7.1l1.7-1.7"/></svg></button>
<button type="button" data-action="image" title="صورة (أو اسحب وأفلت)" aria-label="صورة"><svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg></button>
</div>
<div class="toolbar-group">
<button type="button" data-action="ul" title="قائمة" aria-label="قائمة"><svg viewBox="0 0 24 24"><line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4" cy="6" r="1"/><circle cx="4" cy="12" r="1"/><circle cx="4" cy="18" r="1"/></svg></button>
<button type="button" data-action="ol" title="قائمة مرقمة" aria-label="قائمة مرقمة"><svg viewBox="0 0 24 24"><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><text x="1" y="8" font-size="8" fill="currentColor" stroke="none">1</text><text x="1" y="14" font-size="8" fill="currentColor" stroke="none">2</text><text x="1" y="20" font-size="8" fill="currentColor" stroke="none">3</text></svg></button>
<button type="button" data-action="quote" title="اقتباس" aria-label="اقتباس"><svg viewBox="0 0 24 24"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.76-2.02-2-2H5c-1.25 0-2 .76-2 2v6c0 1.25.76 2 2 2h2c.85 0 1.14.27 1.14 1C8 17 5 19 3 21z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.76-2.02-2-2h-3c-1.25 0-2 .76-2 2v6c0 1.25.76 2 2 2h2c.85 0 1.14.27 1.14 1C20 17 17 19 15 21z"/></svg></button>
<button type="button" data-action="table" title="جدول" aria-label="جدول"><svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg></button>
<button type="button" data-action="hr" title="فاصل" aria-label="فاصل">—</button>
</div>
<div class="toolbar-group">
<button type="button" data-action="open-post" title="فتح مقالة منشورة للتعديل" aria-label="فتح مقالة منشورة"><svg viewBox="0 0 24 24"><path d="M3 7a1 1 0 0 1 1-1h5l2 2h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z"/><polyline points="9 13 12 16 15 13"/><line x1="12" y1="10" x2="12" y2="16"/></svg></button>
<button type="button" data-action="import" title="استيراد ملف" aria-label="استيراد"><svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></button>
<button type="button" data-action="export-md" title="تصدير Markdown (Ctrl+S)" aria-label="تصدير"><svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg></button>
<button type="button" data-action="copy-md" title="نسخ Markdown" aria-label="نسخ Markdown">MD</button>
<button type="button" data-action="copy-html" title="نسخ HTML" aria-label="نسخ HTML">HTML</button>
<button type="button" data-action="settings" class="btn-settings" title="إعدادات" aria-label="إعدادات"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.32 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg></button>
<button type="button" data-action="export-post" id="btn-export-post" class="btn-publish" title="تصدير كمقالة جاهزة" style="background:#22c55e;"><svg viewBox="0 0 24 24" width="14" height="14"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg> تصدير مقالة</button>
<button type="button" data-action="publish" id="btn-publish-action" class="btn-publish" title="نشر المقالة" style="display:none;"><svg viewBox="0 0 24 24" width="14" height="14"><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/></svg> نشر</button>
<button type="button" data-action="update-post" id="btn-update-post" class="btn-publish" title="تحديث المقالة المنشورة" style="display:none;background:#0ea5e9;">تحديث المقالة</button>
</div>
</div>
<!-- Mobile tabs -->
<div class="mobile-tabs" role="tablist">
<button type="button" id="tab-editor" class="active" role="tab" aria-selected="true" data-tab="editor">المحرر</button>
<button type="button" id="tab-preview" role="tab" aria-selected="false" data-tab="preview">المعاينة</button>
</div>
<!-- Split Panes -->
<div class="editor-panes">
<div class="editor-input-pane" id="input-pane">
<div class="pane-header">
<input type="text" class="draft-name" id="draft-name" placeholder="اسم المسودة" aria-label="اسم المسودة">
<span class="autosave-indicator" id="autosave-indicator" aria-live="polite">تم الحفظ</span>
</div>
<textarea id="md-input" dir="rtl" spellcheck="true" placeholder="ابدأ الكتابة هنا... (يمكن سحب وإفلات الصور للرفع التلقائي)" aria-label="محرر Markdown"></textarea>
</div>
<div class="editor-resize-handle" id="resize-handle" role="separator" aria-orientation="vertical" aria-label="تغيير حجم اللوح"></div>
<div class="editor-preview-pane" id="preview-pane">
<div class="pane-header"><span>PREVIEW</span></div>
<div id="md-preview" class="preview-content" dir="rtl" aria-live="polite">
<div class="preview-empty">المعاينة ستظهر هنا</div>
</div>
</div>
</div>
</div>
</div>
<!-- Hidden file inputs -->
<input type="file" id="file-import" accept=".md,.txt,.markdown" hidden>
<input type="file" id="file-image" accept="image/*" hidden>
<!-- Publish Modal -->
<div class="modal-overlay" id="publish-modal">
<div class="modal" role="dialog" aria-modal="true" aria-label="نشر مقالة جديدة">
<h3>نشر مقالة جديدة</h3>
<div id="publish-token-warning" style="display:none;padding:12px;background:rgba(239,68,68,0.1);border:1px solid rgba(239,68,68,0.3);border-radius:8px;margin-bottom:16px;font-size:0.8em;color:#ef4444;">
يجب إعداد GitHub Token أولاً من الإعدادات
</div>
<label for="publish-title">عنوان المقالة *</label>
<input type="text" id="publish-title" placeholder="مثال: كيفية إعداد سيرفر خاص">
<label for="publish-desc">الوصف</label>
<textarea id="publish-desc" placeholder="وصف مختصر للمقالة (اختياري)"></textarea>
<label for="publish-excerpt">الملخص (يظهر في الصفحة الرئيسية)</label>
<textarea id="publish-excerpt" placeholder="اختياري — يُستخدم أول جزء من المقالة إذا تُرك فارغاً"></textarea>
<label for="publish-tags">الوسوم (مفصولة بفاصلة)</label>
<input type="text" id="publish-tags" placeholder="مثال: تقنية, لينكس, سيرفر">
<label for="publish-slug">اسم الملف (slug) — بالإنجليزية موصى به</label>
<input type="text" id="publish-slug" placeholder="my-post-slug (اختياري — يُولَّد من العنوان)">
<div class="modal-actions">
<button type="button" class="btn-primary" id="publish-btn" data-modal-action="publish">نشر الآن</button>
<button type="button" class="btn-secondary" data-modal-action="close" data-modal-target="publish-modal">إلغاء</button>
</div>
</div>
</div>
<!-- Settings Modal -->
<div class="modal-overlay" id="settings-modal">
<div class="modal" role="dialog" aria-modal="true" aria-label="إعدادات المحرر">
<h3>إعدادات المحرر</h3>
<div id="token-status-display"></div>
<label for="settings-token">GitHub Personal Access Token</label>
<input type="password" id="settings-token" placeholder="ghp_xxxxxxxxxxxx" autocomplete="off">
<div class="token-help">
<p>أنشئ توكن محدود الصلاحية من
<a href="https://github.com/settings/personal-access-tokens/new" target="_blank" rel="noopener noreferrer">GitHub Settings → Fine-grained Tokens</a></p>
<p>الإعدادات المطلوبة:</p>
<ul>
<li><strong>Repository access</strong> → Only select repositories → <strong>roko-tech.github.io</strong></li>
<li><strong>Permissions</strong> → Contents → <strong>Read and write</strong></li>
<li>حدد مدة انتهاء قصيرة (30-90 يوم)</li>
</ul>
<p>التوكن يُحفظ في المتصفح (sessionStorage) ولا يُرسل لأي طرف آخر.</p>
</div>
<div class="modal-actions">
<button type="button" class="btn-primary" data-modal-action="save-settings">حفظ</button>
<button type="button" class="btn-secondary" data-modal-action="close" data-modal-target="settings-modal">إغلاق</button>
</div>
</div>
</div>
<!-- Generic Prompt Modal (for link / image) -->
<div class="modal-overlay" id="prompt-modal">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="prompt-title">
<h3 id="prompt-title">إدخال</h3>
<div id="prompt-fields"></div>
<div class="modal-actions">
<button type="button" class="btn-primary" id="prompt-ok">موافق</button>
<button type="button" class="btn-secondary" id="prompt-cancel">إلغاء</button>
</div>
</div>
</div>
<!-- Publish Preview Modal — full-width preview of the rendered post before committing -->
<div class="modal-overlay" id="publish-preview-modal">
<div class="modal" style="max-width: 720px; width: 92%;" role="dialog" aria-modal="true" aria-labelledby="publish-preview-title">
<h3 id="publish-preview-title">معاينة المقالة قبل النشر</h3>
<div id="publish-preview-meta" style="font-size:0.8em;color:var(--text-secondary);margin-bottom:12px;"></div>
<div id="publish-preview-body" class="preview-content" dir="rtl" style="border:1px solid var(--border-subtle);border-radius:var(--radius-md);padding:var(--space-5);max-height:60vh;overflow-y:auto;margin-bottom:16px;"></div>
<div class="modal-actions">
<button type="button" class="btn-primary" data-modal-action="publish-confirm">متابعة النشر</button>
<button type="button" class="btn-secondary" data-modal-action="close" data-modal-target="publish-preview-modal">رجوع للتحرير</button>
</div>
</div>
</div>
<!-- Confirm Modal -->
<div class="modal-overlay" id="confirm-modal">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="confirm-title">
<h3 id="confirm-title">تأكيد</h3>
<p id="confirm-message" style="color:var(--text-secondary);margin:0 0 20px;line-height:1.6;"></p>
<div class="modal-actions">
<button type="button" class="btn-primary" id="confirm-ok">موافق</button>
<button type="button" class="btn-secondary" id="confirm-cancel">إلغاء</button>
</div>
</div>
</div>
<!-- Open Published Post Modal -->
<div class="modal-overlay" id="open-post-modal">
<div class="modal" role="dialog" aria-modal="true" aria-label="فتح مقالة منشورة">
<h3>فتح مقالة منشورة للتعديل</h3>
<div id="open-post-list">جارٍ التحميل...</div>
<div class="modal-actions">
<button type="button" class="btn-secondary" data-modal-action="close" data-modal-target="open-post-modal">إغلاق</button>
</div>
</div>
</div>
<!-- Toast -->
<div class="editor-toast" id="editor-toast" role="status" aria-live="polite"></div>
<!-- Markdown parser + sanitizer + syntax highlighting -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/16.3.0/lib/marked.umd.min.js" integrity="sha512-V6rGY7jjOEUc7q5Ews8mMlretz1Vn2wLdMW/qgABLWunzsLfluM0FwHuGjGQ1lc8jO5vGpGIGFE+rTzB+63HdA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" integrity="sha384-wFjoQjtV1y5jVHbt0p35Ui8aV8GVpEZkyF99OXWqP/eNJDU93D3Ugxkoyh6Y2I4A" crossorigin="anonymous" referrerpolicy="no-referrer">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" integrity="sha384-06z5D//U/xpvxZHuUz92xBvq3DqBBFi7Up53HRrbV7Jlv7Yvh/MZ7oenfUe9iCEt" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha384-Uq05+JLko69eOiPr39ta9bh7kld5PKZoU+fF7g0EXTAriEollhZ+DrN8Q/Oi8J2Q" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/turndown/7.2.1/turndown.min.js" integrity="sha384-HJ5HEeMp8mUyP3rNRTMurw70EDxoPixtQ78PiXe3MMuk18YCV6VKnDTFhQnt8nMw" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
(function() {
'use strict';
// Constants declared first — avoid hoisting-based ordering bugs
var REPO = 'roko-tech/roko-tech.github.io';
var TOKEN_KEY = 'roko-editor-gh-token';
var DRAFTS_KEY = 'roko-editor-drafts';
var CURRENT_KEY = 'roko-editor-current';
var RESIZE_KEY = 'roko-editor-ratio';
var LEGACY_KEY = 'roko-editor-content';
var MAX_IMAGE_BYTES = 5 * 1024 * 1024;
// DOM refs
var input = document.getElementById('md-input');
var preview = document.getElementById('md-preview');
var saveIndicator = document.getElementById('autosave-indicator');
var fileInput = document.getElementById('file-import');
var imageInput = document.getElementById('file-image');
var toast = document.getElementById('editor-toast');
var handle = document.getElementById('resize-handle');
var inputPane = document.getElementById('input-pane');
var previewPane = document.getElementById('preview-pane');
var sidebar = document.getElementById('editor-sidebar');
var draftsList = document.getElementById('drafts-list');
var draftNameInput = document.getElementById('draft-name');
var debounceTimer, saveTimer;
var currentDraftId = null;
var savedSelection = { start: 0, end: 0 };
// === Markdown config ===
if (typeof marked !== 'undefined') {
marked.setOptions({ gfm: true, breaks: true });
}
// === Preview (sanitized + syntax-highlighted) ===
function renderPreview() {
if (typeof marked === 'undefined') {
preview.innerHTML = '<div class="preview-empty">تعذر تحميل محرك المعاينة</div>';
return;
}
var val = input.value.trim();
if (!val) {
preview.innerHTML = '<div class="preview-empty">المعاينة ستظهر هنا</div>';
return;
}
var raw = marked.parse(val);
preview.innerHTML = (typeof DOMPurify !== 'undefined')
? DOMPurify.sanitize(raw, { ADD_ATTR: ['target', 'rel'] })
: raw;
if (typeof Prism !== 'undefined') {
preview.querySelectorAll('pre code').forEach(function (el) { Prism.highlightElement(el); });
}
}
input.addEventListener('input', function () {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(function () {
renderPreview();
scheduleAutoSave();
}, 150);
});
// Always keep the selection up to date — avoids losing it when a modal takes focus
['keyup', 'mouseup', 'click', 'select'].forEach(function (ev) {
input.addEventListener(ev, function () {
savedSelection = { start: input.selectionStart, end: input.selectionEnd };
});
});
// === Drafts model ===
function loadDrafts() {
try {
var json = localStorage.getItem(DRAFTS_KEY);
return json ? JSON.parse(json) : {};
} catch (e) { return {}; }
}
function saveDrafts(drafts) {
try { localStorage.setItem(DRAFTS_KEY, JSON.stringify(drafts)); } catch (e) {}
}
function uid() {
return 'd-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
}
function migrateLegacy() {
var legacy = localStorage.getItem(LEGACY_KEY);
// Always drop the legacy key — stale copies from before multi-draft
// support shouldn't persist even if drafts already exist.
localStorage.removeItem(LEGACY_KEY);
if (!legacy) return;
var drafts = loadDrafts();
if (!Object.keys(drafts).length) {
var id = uid();
drafts[id] = { name: 'مسودة سابقة', content: legacy, updatedAt: Date.now() };
saveDrafts(drafts);
localStorage.setItem(CURRENT_KEY, id);
}
}
function renderDrafts() {
var drafts = loadDrafts();
var ids = Object.keys(drafts).sort(function (a, b) { return (drafts[b].updatedAt || 0) - (drafts[a].updatedAt || 0); });
if (ids.length === 0) {
draftsList.innerHTML = '<div class="draft-empty">لا توجد مسودات</div>';
return;
}
draftsList.innerHTML = '';
ids.forEach(function (id) {
var d = drafts[id];
var item = document.createElement('div');
item.className = 'draft-item' + (id === currentDraftId ? ' active' : '');
item.dataset.id = id;
item.setAttribute('role', 'button');
item.setAttribute('tabindex', '0');
if (d.repo) { item.classList.add('draft-linked'); item.title = 'مقالة منشورة: ' + d.repo.path; }
var title = document.createElement('span');
title.className = 'draft-title';
title.textContent = d.name || 'بدون اسم';
item.appendChild(title);
var del = document.createElement('button');
del.type = 'button';
del.className = 'draft-delete';
del.textContent = '×';
del.setAttribute('aria-label', 'حذف المسودة');
del.addEventListener('click', function (e) {
e.stopPropagation();
confirmDialog('حذف مسودة "' + (d.name || 'بدون اسم') + '"؟', function () {
var drafts = loadDrafts();
delete drafts[id];
saveDrafts(drafts);
if (id === currentDraftId) {
var remaining = Object.keys(drafts);
if (remaining.length > 0) switchDraft(remaining[0]);
else newDraft();
} else {
renderDrafts();
}
});
});
item.appendChild(del);
var open = function () { switchDraft(id); };
item.addEventListener('click', open);
item.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(); }
});
draftsList.appendChild(item);
});
}
function switchDraft(id) {
flushSave();
clearTimeout(saveTimer);
var drafts = loadDrafts();
if (!drafts[id]) return;
currentDraftId = id;
localStorage.setItem(CURRENT_KEY, id);
input.value = drafts[id].content || '';
draftNameInput.value = drafts[id].name || '';
renderPreview();
renderDrafts();
updatePublishVisibility();
input.focus();
}
function newDraft() {
flushSave();
clearTimeout(saveTimer);
var id = uid();
var drafts = loadDrafts();
drafts[id] = { name: 'مسودة جديدة', content: '', updatedAt: Date.now() };
saveDrafts(drafts);
currentDraftId = id;
localStorage.setItem(CURRENT_KEY, id);
input.value = '';
draftNameInput.value = drafts[id].name;
renderPreview();
renderDrafts();
updatePublishVisibility();
input.focus();
}
function deleteCurrentDraftSilent() {
if (!currentDraftId) return;
var drafts = loadDrafts();
delete drafts[currentDraftId];
saveDrafts(drafts);
currentDraftId = null;
localStorage.removeItem(CURRENT_KEY);
}
draftNameInput.addEventListener('input', function () {
if (!currentDraftId) return;
var drafts = loadDrafts();
if (!drafts[currentDraftId]) return;
drafts[currentDraftId].name = draftNameInput.value.trim() || 'بدون اسم';
drafts[currentDraftId].updatedAt = Date.now();
saveDrafts(drafts);
clearTimeout(saveTimer);
saveTimer = setTimeout(renderDrafts, 500);
});
document.getElementById('btn-new-draft').addEventListener('click', newDraft);
// === Auto-save ===
function scheduleAutoSave() {
clearTimeout(saveTimer);
saveTimer = setTimeout(flushSave, 1000);
}
function flushSave() {
if (!currentDraftId) return;
try {
var drafts = loadDrafts();
if (!drafts[currentDraftId]) return;
drafts[currentDraftId].content = input.value;
drafts[currentDraftId].updatedAt = Date.now();
saveDrafts(drafts);
// Recovered from a previous failure — show success and drop the error state
saveIndicator.classList.remove('error');
saveIndicator.textContent = 'تم الحفظ';
saveIndicator.classList.add('visible');
setTimeout(function () { saveIndicator.classList.remove('visible'); }, 2000);
} catch (e) {
// Likely QuotaExceededError or similar — surface permanently until next success
saveIndicator.classList.add('error', 'visible');
saveIndicator.textContent = 'تعذر الحفظ — المساحة ممتلئة';
showToast('تعذر الحفظ: ' + (e.message || 'المساحة ممتلئة. احذف مسودات قديمة.'), 'error');
}
}
function loadInitial() {
migrateLegacy();
var drafts = loadDrafts();
var ids = Object.keys(drafts);
if (ids.length === 0) { newDraft(); return; }
var saved = localStorage.getItem(CURRENT_KEY);
var id = (saved && drafts[saved]) ? saved : ids[0];
switchDraft(id);
}
window.addEventListener('beforeunload', flushSave);
// === Toast ===
function showToast(msg, type) {
toast.textContent = msg;
toast.className = 'editor-toast visible' + (type ? ' ' + type : '');
setTimeout(function () { toast.className = 'editor-toast'; }, 3000);
}
// === Modals (with focus trap) ===
var activeModal = null;
var previouslyFocused = null;
function focusables(el) {
return Array.prototype.slice.call(el.querySelectorAll(
'button:not([disabled]), [href], input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
));
}
function trapFocus(e) {
if (!activeModal || e.key !== 'Tab') return;
var f = focusables(activeModal.querySelector('.modal'));
if (!f.length) return;
var first = f[0], last = f[f.length - 1];
if (e.shiftKey && document.activeElement === first) { last.focus(); e.preventDefault(); }
else if (!e.shiftKey && document.activeElement === last) { first.focus(); e.preventDefault(); }
}
window.openModal = function (id) {
var el = document.getElementById(id);
previouslyFocused = document.activeElement;
el.classList.add('active');
activeModal = el;
setTimeout(function () {
var f = focusables(el.querySelector('.modal'));
if (f.length) f[0].focus();
}, 10);
document.addEventListener('keydown', trapFocus);
};
window.closeModal = function (id) {
document.getElementById(id).classList.remove('active');
if (activeModal && activeModal.id === id) activeModal = null;
document.removeEventListener('keydown', trapFocus);
if (previouslyFocused && previouslyFocused.focus) previouslyFocused.focus();
// Restore saved selection when we came back from a modal
if (document.activeElement === input || !previouslyFocused) {
try {
input.selectionStart = savedSelection.start;
input.selectionEnd = savedSelection.end;
} catch (e) {}
}
};