-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimplehtmleditor.js
More file actions
3332 lines (2885 loc) · 148 KB
/
simplehtmleditor.js
File metadata and controls
3332 lines (2885 loc) · 148 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
/*!
* Simple HTML Editor v2.0.1
* A lightweight, customizable WYSIWYG HTML editor for modern web applications
*
* @author FranBarInstance
* @license MIT
* @version 2.0.1
* @link https://github.com/FranBarInstance/simple-html-editor
* @copyright (c) 2022-2025
*/
(function () {
window.ncsedtRestorable = function () {
var _this = this;
this.elementsWithTag = document.querySelectorAll('ncsedt-restorable');
this.elementsWithAttribute = document.querySelectorAll('[data-ncsedt-restorable="true"]');
this.savedHTML = [];
this.savedAttributes = [];
this.undoHistoryHTML = [];
this.undoHistoryAttributes = [];
this.htmlElementCount = 0;
this.attributeElementCount = 0;
this.elementsWithTag.forEach(function (node) {
_this.savedHTML[_this.htmlElementCount++] = node.innerHTML;
});
this.elementsWithAttribute.forEach(function (node) {
_this.savedAttributes[_this.attributeElementCount++] = node.cloneNode().attributes;
});
}
/**
* Restores the saved state of all restorable elements
*
* @method restore
* @description This method restores both the HTML content and attributes
* of all elements marked as restorable to their previously
* saved state. Before restoring, it saves the current state
* to enable undo functionality.
*
* @fires editorchanges - When restoration is complete
* @returns {void}
*/
ncsedtRestorable.prototype.restore = function () {
var _this = this;
var count = 0;
/**
* Step 1: Save current state for undo functionality
* Stores the current HTML content of all <ncsedt-restorable> elements
* before making any changes, enabling the undo operation
*/
count = 0;
this.elementsWithTag.forEach(function (node) {
_this.undoHistoryHTML[count++] = node.innerHTML;
});
/**
* Step 2: Save current attributes for undo functionality
* Stores the current attributes of all data-ncsedt-restorable elements
* before making any changes, enabling the undo operation
*/
count = 0;
this.elementsWithAttribute.forEach(function (node) {
_this.undoHistoryAttributes[count++] = node.cloneNode().attributes;
});
/**
* Step 3: Restore saved HTML content
* Restores the previously saved HTML content to all <ncsedt-restorable>
* elements, effectively reverting them to their initial state
*/
for (let i = 0; i < this.elementsWithTag.length; i++) {
this.elementsWithTag[i].innerHTML = this.savedHTML[i];
}
/**
* Step 4: Clean current attributes
* Removes all existing attributes from data-ncsedt-restorable elements
* to prepare them for restoration of their saved state
*/
for (let i = 0; i < this.elementsWithAttribute.length; i++) {
Array.prototype.slice.call(this.elementsWithAttribute[i].attributes).forEach(
function (cur) {
_this.elementsWithAttribute[i].removeAttribute(cur.name);
}
)
}
/**
* Step 5: Restore saved attributes
* Applies the previously saved attributes back to the data-ncsedt-restorable
* elements, completing the restoration process
*
* @fires editorchanges - When restoration is complete
*/
for (let i = 0; i < this.elementsWithAttribute.length; i++) {
Array.prototype.slice.call(this.savedAttributes[i]).forEach(
function (cur) {
_this.elementsWithAttribute[i].setAttribute(cur.name, cur.value);
}
)
}
document.dispatchEvent(new Event("editorchanges"));
};
/**
* Reverts the last restoration operation
*
* @method undoRestore
* @description Reverts the changes made by the last restore() operation.
* This method uses the saved undo state to return elements
* to their state before the last restoration.
*
* @fires editorchanges - When undo operation is complete
* @returns {void}
*/
ncsedtRestorable.prototype.undoRestore = function () {
var _this = this;
/**
* Step 1: Restore HTML content from undo history
* Reverts the HTML content of all <ncsedt-restorable> elements
* to their state before the last restore operation
*/
for (let i = 0; i < this.elementsWithTag.length; i++) {
this.elementsWithTag[i].innerHTML = this.undoHistoryHTML[i];
}
/**
* Step 2: Restore attributes from undo history
* Reverts the attributes of all data-ncsedt-restorable elements
* to their state before the last restore operation
*/
for (let i = 0; i < this.elementsWithAttribute.length; i++) {
Array.prototype.slice.call(this.undoHistoryAttributes[i]).forEach(
function (cur) {
_this.elementsWithAttribute[i].setAttribute(cur.name, cur.value);
}
)
}
document.dispatchEvent(new Event("editorchanges"));
};
})();
/**
* Initialize the global restorable object
* This initialization must happen immediately to ensure proper state management
* @global
*/
if (!("ncsedtRestorableObj" in window)) {
var ncsedtRestorableObj = new ncsedtRestorable();
}
(function () {
const MAX_IMAGE_SIZE_BYTES = 1200000; // 1.2MB - Large base64 images degrade DOM performance
const MAX_ALLOWED_IMAGE_SIZE_BYTES = 5000000; // 5MB absolute maximum
const MIN_GROUPING_WINDOW_MS = 100; // Minimum time window for grouping mutations
const TIME_SCALE_FACTOR = 10000; // Time scaling factor for mutation timestamps
/**
* Simple HTML Editor main class
*/
window.ncSimpleHtmlEditor = function (options = {}) {
var _this = this;
/**
* Reference to the global restorable object for state management
*/
this.restorable = window.ncsedtRestorableObj || new ncsedtRestorable();
/**
* Editor state object
* Maintains the current state of the editor including editing mode,
* clipboard contents, and history stacks
*/
this.state = {
isEditing: false,
clipboard: null,
history: {
undo: [],
redo: [],
force: []
},
selection: null
};
/**
* Validate and process configuration options
*/
this.validateOptions(options);
/**
* Default configuration options
*/
const defaults = {
editableContentSelector: "body",
usesLinearUndoHistory: true,
mutationGroupingWindowMs: 200,
aiModelParams: {
temperature: 0.5,
top_p: 0.9
},
aiBackends: {
ollama: {
enabled: true,
url: 'http://localhost:11434/api/generate',
model: 'qwen2.5-coder:7b'
},
openrouter: {
enabled: false,
url: 'https://openrouter.ai/api/v1/chat/completions',
model: 'qwen/qwen-2.5-coder-32b-instruct:free'
},
anthropic: {
enabled: false,
url: 'https://api.anthropic.com/v1/messages',
model: 'claude-3-opus-20240229'
},
azure: {
enabled: false,
url: '',
model: ''
},
gemini: {
enabled: false,
url: 'https://generativelanguage.googleapis.com/v1beta/models/',
model: 'gemini-pro'
},
openai: {
enabled: false,
url: 'https://api.openai.com/v1/chat/completions',
model: 'gpt-4-turbo'
}
},
additionalPrompts: {
"only replacement": 'Iinstructions:\nProvide only what is requested, including all code or text in input that does not change, without additional comments, without Markdown. The div id ncsedt-implement code must never be modified.'
},
customPrompts: {
"translate": 'Translate to English',
"traduce": 'Traduce a Español',
},
toolbarCols: null,
/**
* Timeout in milliseconds to disable the save button after clicking
* Prevents accidental double-saves
*/
saveTimeout: 500,
maxImageSizeBytes: MAX_IMAGE_SIZE_BYTES,
/**
* Determines which features are available and how they are presented
*/
toolbar: ['edit', 'undo', 'redo', 'up', 'down', 'previous', 'next', 'cut', 'copy', 'paste', 'head', 'code', 'agent', 'link', 'image', 'save', 'github'],
/**
* Toolbar button configurations
* Each button configuration includes:
* - name: Button identifier
* - icon: Base64 encoded icon image
* - icon2: Alternative icon for toggled state (optional)
* - title: Tooltip text
* - disabled: Function that determines if button should be disabled
* - action: Function to execute when button is clicked
* @type {Object}
*/
buttons: {
edit: {
name: 'edit',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABP0lEQVRo3u3YMU4CQRTG8T+7nkM3HkUTK26BHa2Vt9BGGlAEgl5Dz2E2XoFGGqLNTljJDDNLwXtD3pdMQTIkv+/tsNkFLBaLxQIV8AmsgAeglAZ1yTnwBfy21jtwJg07FJ9NiX34LEoMI3i3Fij+TdwnlniUhrpUwNUBJVbScIevgR/gpmOJDy14B+pSogYuJPGhu80a6O/svdvZ8w1casSnlBDHV/w/NqHlO07D5vtiCU1+AgyADfErIZYK/+THQNHsucV/Ja6l8fsm7/A94MmzR/zMnyT++ZTwo1zxRfM5G/yS7eNvAbwY3vBpePfqlx3+rYUvc8dPDW/4OL79X41aPPgfiedsb5UlMPPsqRF+GXGJTf4VpZMPFWhPfo7iyYcKOLz6yYcKhJZKfGoBtfiUAqrxsQLq8RaLxXKc/AH+RGvPIDl6DwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxNDo1ODoyMyswMDowMGRD6r4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTQ6NTk6MzIrMDA6MDCQATIWAAAAAElFTkSuQmCC',
icon2: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAACI0lEQVRo3u3YsWoUURTG8Z9ICIiNsDEiioioKGEbK0uxUWwkjU9kbRUbn8BitQkE0byBTUSx0FgkisaAaCGITSx2Bzezd3buzM7OzJL9YNhqzvy/c+45995lrrnmmmsuOljHL6xhoWmgIlrCFg6GnnUsNg1WFn5mTCzhTQZ8aRMdbKJbg4E7+Jtj4AA9kT3R8b+c+zWZWI00sRYT7FXqpWmY6AZixpj4GRN8BXtTNNEdxAvFzDPxMvYjV/El9fIP3KgIflzMe/gTgN/GcpGPXcHnCk2k4YuY2B/wFNZl7FZgIgs+xsRv3CyZNHAJO8r3RB78uJiruDsJfKIL+muwaCWy4Hu4b3StV9FnY018ishaDHyyIT0QV4nKdB4fIz/4Igf+OJ7WbQDO4J380p90eFMchj+GJwH479OGT7SMtxEmFvE8AP+4SfhEoUqEyr/g8CHskQaWTZZOGz0Kj5skD7Ug82ndFpfRE0YvLY1lPtG4TSpUiVN4rSWZj9lhQxmu87JUGH5DP7OtWiax8MmovIav4hu7VfAGvxtaNCqLwj+T3RONVaIK+MZMTAL/Hrc03BMx8L0M+OQOG0pCbT1RJvMfcDYVp7HplIbLy/w2zmXEaqQSacAEPpT5HVzMiVd7JfKmSvLs6v8BEKNaTcTAfxtAFVFtJvLg93C9ZOxaTOSdNlcmjN/qs9ORMhEasZtNQxXVcCW29C8/M6eufuZnEv7o6h+WFd8aD3ft0gAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxNDo1OTozMiswMDowMOFciqoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTQ6NTk6MzIrMDA6MDCQATIWAAAAAElFTkSuQmCC',
title: 'Edit',
disabled: function () { return _this.isEditButtonDisabled() },
action: function () { _this.editToggle() }
},
code: {
name: 'code',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAACIElEQVRo3u2ZsUscQRjFf8ZCMFVSmFIskiqkUxEkXbAJFmJO0MQmraSxDYLYJVVII5axCakEm5C/IBwh2ClBxPaKWNhEjMlZXA7mHrPZmZ3ZGYR9cMXevO99783s7c7tQoMGDRrkxHCiPgvAHjADjAO/gE7u8D54A3SNz9tYwrcSBZiS43aivlEwDJwzuALjuU354JGYj3ruh55Cyw6cSTluV9CoBS3gtwNvh8EVeC3jV8CLXOa7DtwDCfBExrupQ5jmywKMCvcvcMcSIFkINV8W4LFwjywcc7zWEMv/GpgNy34D68LftXB0Qq6o4Ydtm3mXRp+kZs3CWQQuqXElqpoHOJW6yQJebSFCzI9J3QUw8h9+9BAh5gHmpfarQ020EKHmAbak/p1jXXCIGOYBvojGc4/ayiFimR8CzkTnvqeGUwjXzdyQZ/MHDN5xz4BjT42ivqXbl6JVWPFovCr1nz2NLxZ4cD4NnwUKvJfaTQ/zob2jCLWl7mlq8yGCI/RuWmbNvRzmqwpPC/fEoUfLs0e0ELbr8ivhfcxtvo+lgkaKXeGsl+jatuhLsc33Ybu8KX7I+GyJZsjlOkoIE3fp/W00Z/O2Y4Ak5m0hTMwxOKPfHbSSmzdDXMp3GxJg20Eni/k+WnK8LwFeVtDIio4EeJjbkA8mxPw5Cd4/xHy8ro/QvwF/bnKAJO8AYi5xh95N7Ce9Dd0H4DBFiAYNGjTIh2vrWlwSpGLTnQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxNTowMjowNCswMDowMFgiNkMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTU6MDI6MDQrMDA6MDApf47/AAAAAElFTkSuQmCC',
title: 'Code',
disabled: function () { return _this.isCodeButtonDisabled() },
action: function () { _this.editCode() }
},
undo: {
name: 'undo',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABhklEQVRo3u3WMWsUURDA8Z9i5CQaG5toIURMIRLUJo3Gyi5fxVYbwWATIYVo48ewsLJUsFFMYZVCiyTNhQhBwXDEnGfxVjiWvTWn7xED84dpdpeZ+e/Mg0cQBEEQBEEQ/E88PuwG/pXBUZI4MeL5ffSwNEauCdzELdzAZUzjNH7gC7axibd4g1Xs55YaDMVBBK7iedXgYMzYwZNKtohAm8QVvMTPv2i8Hv0q12wJgfqZmJBWbC9D4/XYq2p1cgv8nsRFaW9zN16PDzh/kGaPjRAYxXdMtrzfxWu8wntsoVvlPCcd6nncxh2cacm1iUV8zDWBtuji3h8aqjOFu/jUkvcr5koK9LGMU+MWGaIjrWdvRI11aXLZBb5Jq5CLa9LaNNV6h5MlJrCUUQAuSDvfVOtBCYES145pbDTU2cWlEgIlJnFd85l4UUqgxCQeNdToY6aUQO5JdPC5ocbK8EfHM/+1hxklenhae9aVrhut5LgK5JI4izU8w4L8PzwIgiAIgiAIgiPML+zxM5YSM3skAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIyLTA5LTE2VDE1OjAxOjUyKzAwOjAwmCW2HgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0wOS0xNlQxNDo1OTo1NiswMDowME3jdLwAAAAASUVORK5CYII=',
title: 'Undo',
disabled: function () { return _this.isUndoButtonDisabled() },
action: function () { _this.undo() }
},
redo: {
name: 'redo',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABiklEQVRo3u3WT0tUURjH8U+hhoSuijQqd4oECS1aBJK73ktvoCCs2am7auHLCIJatSraRFjbsDYFUVAgRqFWji7uLPQ4c+femWO6eL5wFvfP8/D9nXMv5xAEQRAEQRAEQTUaRy3Qr/xOenMgQ+MBXMUNXMdFnMUZDOIXvuID3uIlXuFfTfn7uWdkEg+x1pqZOuM7lnG5ovze2r6ZwjM0exBPRxNPMF1Rvq8Ag7iNzQzi6fiLRZzqIt9zgPNYOQTxdKxgokT+QIATFeRn8BQXSt75ied4gdf4hh+t/mM4h2u4qfjZh0t6/cbpkudVnPfJr5fMxipuYaRGz1HcaYXsZZUqM47PHZpsYB5DdRomDGMJ24cRYAhvOjT4hCt9iKfMKT7BrAHudih+11qZnDRqyFcKMKHYPdPCL8p/5P8hXynAY+2/+ZljIN81wCXFGSUtundM5LsGWGhT8NH+HfIo5Q8EOJlc/1GcHPfyAFsZ5bOfKtuFmsUjvFdsPLnkcxw3giAIgiAIgiAIwC7w7i5ZynjYFQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxNTowMjowNCswMDowMFgiNkMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTU6MDI6MDQrMDA6MDApf47/AAAAAElFTkSuQmCC',
title: 'Redo',
disabled: function () { return _this.isRedoButtonDisabled() },
action: function () { _this.redo() }
},
up: {
name: 'up',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAAAsUlEQVRo3u3VTQqCUBhG4dMP0aBZbaLVNWzaRlqJm2gpzmoSNXGQYJJe7bsXzgOCA9H3CCJIkqRei+gBKS7AFVhGDxk7/tUcxUV8ji8uomt8MRF947OP+GV8thFDxmcXMWZ8NhEp4yeJWCWMPwFn4PHl2NL+C9fAveO6I7AHqr+88gFq2m/6MMdDsviIDCiZAdEMiGZANAOiGRDNgGjFB6xnvPcN2DXnG+AZHStJkqb2BvfBZVUwT6fHAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIyLTA5LTI3VDExOjAxOjU1KzAwOjAwYMkoEwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0wOS0yN1QwMTowMTo1NSswMDowMBGUkK8AAAAASUVORK5CYII=',
title: 'Select up',
disabled: function () { return _this.isUpButtonDisabled() },
action: function () { _this.up() }
},
down: {
name: 'down',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAAArUlEQVRo3u2XvQrCMBgAT9FJEAqu4vO4+BgOvrSv4NjJOgm10Gp/vwTv4JuSkLtsAREREelkBxTAKlqkLw+gqs1hjkvW0ZUGRAsYEC1gQLSAAdECBkQLGBAtYEC0wN8HbEacPQLbjvXm45yAfcveCrgvHX8GSj5/XUPmCdyWlp8qIlR+bEQS8kMjkpLvG5Gk/K8RSct/i8hCvi0iK/lmRJbyby7ANVpCRERE5uIFO9pmz/tN+9wAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDktMjdUMDE6MDE6MzcrMDA6MDAxOTC9AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA5LTE2VDE1OjAxOjE1KzAwOjAwqJU+1gAAAABJRU5ErkJggg==',
title: 'Selenct down',
disabled: function () { return _this.isDownButtonDisabled() },
action: function () { _this.down() }
},
previous: {
name: 'previous',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABGklEQVRoQ+1XOQ7CMBBMREFBwQPgWdRU/IqGf1DxmVDRUFBQAOsikmUFa61ZgkaaSC6i7I7nSGyn78ivnpx/JwH/TlAJKAHQAb1CoIFwuxKALQQBlABoINyuBAoL93Z/tnGFrXUCRCaQyJ9sbG0MzvnhsigBI/mEt2ETkJNPjlIJKMlTCZgiTyPgG3kKAQdjeawsHzt7dgOXl7f1XzwYratQzXnPfN6alxUuPMUtAuYin3g/bSyZBTyM/CpaQMKbK4W7zbX+hQCPCIqNjHoZHZOl3shqIiheofz7oj7MTSVBl0ApgvKHJhdB+0vp2XfCa1rOQuGTRwBKQISLCIYSQNyL6FUCES4iGEoAcS+iVwlEuIhgKAHEvYjeD0hbKjFLoDaVAAAAAElFTkSuQmCC',
title: 'Select previous sibling',
disabled: function () { return _this.isPreviousButtonDisabled() },
action: function () { _this.previous() }
},
next: {
name: 'next',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABHklEQVRoQ+2WQQrCUAxE25WXEEHwEh7MnaAuXOmdPIggiAfRZK82k/yQX5hCV02m82bk13GY+TXO3P9AgOoG2QAbCCbAn1AwwPA6GwhHGBRgA8EAw+tswBHhQXZOjr2vKxUNvMXJTu5rC4gqAPXeBKISoAlENUAYogeAEEQvAG4IBGArb1k0ODlufzT28uyMvAMBeInwEhF3zkKnEwLwFEMrpyl0zQyBADzExRp14pzXL/XRsosA3EVwYxENzugXWhswXQiASdAwpH8lfl2QeRXpCQA23xOAy3wvAG7zPQCEzFcDhM1XAjQxXwVwQc75qWO54hid8gQ9JwAUV8IwG0gIFZJkA1BcCcNsICFUSJINQHElDLOBhFAhydk38AELbCYxoaSv8QAAAABJRU5ErkJggg==',
title: 'Select next sibling',
disabled: function () { return _this.isNextButtonDisabled() },
action: function () { _this.next() }
},
cut: {
name: 'cut',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAAB9klEQVRo3u2YTU7CQBiGHzHqCgzXELmAceERSIhncUndGRFTAtHD+BNdeAAFI3HJDQSXGFxMScgU2pnOtDOLvskkJP2m87ztVzp9oVSpUmlqAn1gDPxGYwyEwLFruCQdAHfAH7DcMhbAENh3DbsJ/jkBXB5Plk0ECWsp6V4DfjUGBcArGWgSb5sp0Aaq0WgBE+Lt1MgZPlA5SShN+gLqG+rqkbH12lvX8ACf0sRWQu25VDtyDQ8wkyZXE2prUu3MNbyugUOp9sc1POi1UFuq/XAND/GHeML2h/hbqr12DQ9ie7CQTjhFPLC1aLQ3wC+Bnmv4lYYpi2QFKAQexLbg0bKJwuDXTQyIt1NWE4FGrVU1EG/YETBH/FW+A11Ez5uayBVeRRcpJq4S6jumi+9aMPAG7ABnW46fRsdfpPpX4NLWVbQh3TvhpQIJ+gRxB3Lr90rOhiqIdlmpk4cJWwpQ/4v1rp104L0zkQW+UBNyLjRDvNRuUHuRpRkM8gJXyYVUwQo3oZsLebeZy5ILebOdzpoLefNBE0on1MmFuopr5GrCJBfy4qPeJBfyIlYxyYW8CLZMciEvosVQmqyTC3kR7mbNhRbAkYEBqyay5EJ9Q3hVE0rSzYUegD1LBtJMKEslF1ogrrxNeOuSc6F59LuHec+XKlXKUP835G8IanS10wAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0yN1QwNDo0MDowNCswMDowMFFlZxoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMjdUMDQ6NDA6MDQrMDA6MDAgON+mAAAAAElFTkSuQmCC',
title: 'Cut',
disabled: function () { return _this.isCutButtonDisabled() },
action: function () { _this.cut() }
},
copy: {
name: 'copy',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAAA7klEQVRo3u2ZSw6CMBRFj4apcQMyZu0aEscO3JGagAvAATqQQOTTvlfiPQmTQuk9bdKXtCDSJAdKoAaayE+U8HeD4NEESsPwiwU2PW01sIsxMxMyLOrcjPgmGbbeASTgHcBLwKJO1MAZKKaG+7XNWdeJx3vMYALWdaIBTkNh52yj1nXiM+Y+lIBVnRg1zt/uQskgAW8k4I0EvJGANxLwRgLeSMAbCXizeoGspy3ps9Auq18BCXgjAW8k4E02o8+T78PdKFelHaqhF3NW4GoQuMsl5M8K2ksHq7uBG3AIPSM57aVDFTF4BRxjhBcheQHmPezLx9HoXgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0yN1QwNDozOTozNCswMDowMArEXrAAAAAElFTkSuQmCC',
title: 'Copy',
disabled: function () { return _this.isCopyButtonDisabled() },
action: function () { _this.copy() }
},
paste: {
name: 'paste',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABG0lEQVRo3u2ZzWrCUBBGj9WtUNc1a99KfT1F6KYoXbgVq6+iQiK4TRcmoGKS3h/7WToHZhHIzP0OCVlkID4dYAxsgVNRG2AEtB9wXlR6wBeQV9QaeFWHrKLdEL6sFfCiDnuP8Q/ClzX8rVAJMAMyh3BlfQBvQB+Ye/RnwDswCAm/9zi4rP7NLN85h6LfmVnAoTEFcmDqI+Dz2lzWvJBIgEXgrLQqZKtGIG+4NycuTfPvZn3Kz5kLJqDGBNR0AnpbAb3R+PNPwATUmIAaE1BjAmpMQI0JqDEBNSagxgTUmIAaE1BjAmrq/swdge7Fdex9gAuVC466J7AUBr7l06dpwHnBFrIailE7rvdtTiScF2ypIHgKTELCG8Z/4BuHD+VLGLARSgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0yN1QwNDozOTo1MCswMDowMDjkcyQAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMjdUMDQ6Mzk6NTArMDA6MDCQATIWAAAAAElFTkSuQmCC',
title: 'Paste',
disabled: function () { return _this.isPasteButtonDisabled() },
action: function () { _this.paste() }
},
link: {
name: 'link',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAADHElEQVRo3u2ZzUsUYRzHP7uBSh0qLTtUKKuBQdGpOkSkFBQEnZLqYJEQBL0IEkT0B1QQhYc6mG1u18B7eRGtSxHUUahs7WZrmEX4Eurh2YHxO2+77szOCvuFYXlmvvP7fZ6Z53n2eZ6Bqqqqal0rEVPeOuAo0AQ0ADngO/AWmI/7ofgpBWSAv8Cyy/EHSAPNcYO6qRdY8ADXYx64HjewpSTwrEBwPfqCgm8oA3wa6Ha59g0YAoaBL0A9sFk8hzH940PEnJ7wgzifag7oxDmAJIEuYEb8c5jOXhHwk0BrwL37XSrxvFLgUwXG6JJ7Z4GacsFnSoS34mQlRsd6gbf0QuK4DQQkQ6zAAHBRzv0A2jEjTrGaknJDlBW4DVwOER5gu5R/hcTq0D7gP4U1mx3AAYIfXAKYoEx9YEgSTQEtLr5TwL+85zX+o8oFnKNQbRTw9cCiJDvt4R0WX7+HrxWYFm86CniA85Loo4/3Kc4R6ph4GjDTap3YNUdVgbuS7J6PdwswLv5R8WzKA9s9N8OCTQJtcu6xJOsJiHEIWLL5l4Cd4hkluJmtgioUPg2ck/O/pbw1IM57YMxWTgAnxPM5/5sBroZRAQv+EqbT2pWVcnsB8UakrDPN6Tx8N+YNlSz7YkST78LZJA4GxOthdbN7JNfbCHGG0CvJ5oCN4hkTzzimw3rpgfjvhAWrSuFcw04C28TXgXN4fOIT95N4z0ZVAZ1Z5vBejOia942H74z4FvB/W2tWHc6tj04ffw1merCMmS6cdPG0AD8l5qso4MEMbfZEXwneBEtiJmqNLtdSmOZnj7kI7I2qAlck2UAJsdzgl4FbYYB6DVf6h5QrAX4E2C3n08DDKCugi4fGoEBFwL/EvOFIdZzVrztLcX8uXs0mU2ScNasWs9FqT95VIvxgueAtpQVgBrPp5Kc9lQIPZhGhc/MZzM6DwiQwy0BdScUGb+mGC5DVJwaB+5j9mwkPX6zwlvo84IKO/kqAt3QNMxMt9ONEaMvAMNWE2SWe9QCP5fPQWj7y1QBH8qCNmH2gLPCOCv9AV1VVVVWgVgAPDHRgefYM4AAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxNDo1OTozMiswMDowMOFciqoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTQ6NTk6MzIrMDA6MDCQATIWAAAAAElFTkSuQmCC',
title: 'Link',
disabled: function () { return _this.isLinkButtonDisabled() },
action: function () { _this.editLink() }
},
image: {
name: 'image',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABzUlEQVRo3u2ZyUrDUBSGvzosxLEqqAj6AKJvIK58AKdncOXeCUdc+BKiILoQhYLgwpUg4hOIIu4UdyotKDi0LpJLQ8hNk7S9p4X7wYHCPWn+L0N7cwMWWRqr/P0bwARwJS2aNHzBrTXpMHHZdIN/u1UAVqRDJQk/BUx7JFalw8UNr5ihDs6ELrxiFvhxe5alw/rZKhE+SGJJOnTc8Io5j8RiuTtPlRgfBNaBcaBPs32X+/kXyEXcbwfF/6B3TU8OyODc+NkkcsPAM8Xfcql69BykWJzUQHhVe7qQYZdQFmhPYl4FPoB03I38R8EkvVH332A4WMWxAtJYAWmsgDRWQBorII0VkKbSAmmgW1pKkWQ6fQZcUv6SZeTpdCUFFjy9OyV6Sz2LGxcYA748vXmcJZQg+oFroKdWBNqA+4D+HDDi620Bbt3xc/T3oFGBQ/QP4w9Ap9uXAo5847oVOmMC8yHhVWXc8NsBY3/ApJTAKPAZQUBdLnnN2CswYFqgFbiLGD5K3QDNJgX2Kxhe1a5JgWpj14XqhroXaAoZy+Ks4ytM3wdedO8QQs/AhWBgP6dJNhoCXpB/N/BEcTqSSOIYZ33edPA34ABn9mqpWf4B0/l4sgdYXjsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDktMTZUMTU6MDE6MTUrMDA6MDDZyIZqAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA5LTE2VDE1OjAxOjE1KzAwOjAwqJU+1gAAAABJRU5ErkJggg==',
title: 'Image',
disabled: function () { return _this.isImageButtonDisabled() },
action: function () { _this.editImage() }
},
head: {
name: 'head',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAADI0lEQVRo3u2ZT09TQRTFf4KtCRBNwJIodK0LdwgWd+BnMBDdgaisCYluXAqu1QBxSeKfGFeKSz6AAZMaNzRxYQWbKC6gKGWhdTGvyePOtH3TzrQYe5JZzOvMmXPfu3PvnSm00ML/jWOOeNqBIWAEGADOA2eAruD3PeArsAGsA6vAO+BPs19AEpgHNoGiZfsCzAH9zRCeAJaAgxqEy3YALACnGyX+GvDDgXDZtoFxn8JjwJMKAnaAp8ANYDD4SrGgJYJnU8AzYLcCz2Iwxyk6gLdlFtwAJoIxNnyTQKYM54olX9U3bxL/C5gBjtfJPQvsG/jf4OhLmNwmA1xw9YaAFCrMynUW6iW+biB9j/Jp1+gH0ob1xmolTKBHm4wn8WEjcmLN70BPLWRL6D7v0m3KIQUUxNqPbUmS6ElqpgHiS7gn1i5gmbHn0UNlPdHGFl3orjQXdXI7em0z0UDxJUwLDVmgLcrEYTFxB4dJxQKdQF5oGZKDTBaNiP4KagM3Gj+DtcMYjWLAgOivNkF8ubWlNqMB50Q/Lfpx4AEqc26hNnzc0xi5ttRmhExesk6XEaoYPPMxphc9qVWFjP/yrZhqlpynMSfQ88EhRApLAkXDs9+exlSFyYA90T8p+suGOcuexpwS/XwUoz5SOfbGUb66ReUN6mJMSmj5EMWAV2LSVJRJnnBLaHkpB5hcaE30R2kerlTRZoT8bLscnVJiMMrENtSlU3jiZBMMmBIaPmMRNefE5AwerjoqIA58Ehru2xD0oye02QYacAc9gfXZkiwIkn3U/vCNy+hHyoe1EHWjag+Z6pMexZ9FP0xtU8e96Th6vZLGz41yEpWo5HpX6yVeNJDmcOtOw+hn4CLwyAV5DHUykuQF1O1BZx3cceAuus8Xgdc4vEjoKGNE6WtMWxrSCdxED5Vh8c6TZww9MoVbHniOql8uoQ4j8aD1Bs9uAy/QM6x0G69XOGPo0clF+4aDDRsVPajrPpPv2rYCKs53N0p8GH2osiNbg/AsqjywzrBhuPqbtQ24iCq9B1C3B30c/pt1E1VTraGuS9Y5An+zttDCv46/K53XmFVUFdIAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDktMjRUMDc6MTM6NTQrMDA6MDAX56YDAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA5LTI0VDA3OjEzOjU0KzAwOjAwZroevwAAAABJRU5ErkJggg==',
title: 'Edit head',
disabled: function () { return _this.isHeadButtonDisabled() },
action: function () { _this.editHead() }
},
save: {
name: 'save',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABvklEQVRo3u2Zu0oDQRSGv0jUWKigTZAIYiH2Bn0FOx/AQiSVVV4hpYiVta3YeEGsLSwEo40+gRcQO4MXtIzF7uKyzGSzs3NmDcwPU+25/N/mZGaXBS8vL6//rEXgFPgAusKrZdv8LPDmwLgYxJFj89YhXIyNKESyqJSWUI/q9qAAiEHoAGyNiTiEawDrEEUA9IIYGACAlX7jSykAqlhbf+hSyvVuP/FDlswUJg9QtMoGOWmz61QD/wt4gKIlAVABmkAb+ArXNbAFjGSo85rXiMlRXgPu0Z++hxn6jwIN4DlD/1wAlRTzB8C4gY9p4NwFQLOH+V3ybb9GuVkB2ujvfCFnR1aAT0XOIzBh2L/qGuBbkbNu2LtO8E5gmm8EcJuIf8Jsm64DnbDGD7DsCmAzEW/yGhg3H60rVwBl4CYWv6qJm8lg/gGYcwUAMMXfblRTXG+FJuvS5k0BIJj7DWBYYT6qFYcQMZ8HQKedRL0OwaOCiHkJgBKwr6ib3LnmbZgHeE9plrbWFDXLwJkm3tqdj3SSE2BPU3cMuJQ2D7BAvg8cLwSPxCpNAneS5uMQx5iPU6NH7SpwIWney8vLS16/eT7oBHxeUFYAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDktMTdUMTY6Mjk6NTQrMDA6MDCj7IdOAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA5LTE3VDE2OjI5OjU0KzAwOjAw0rE/8gAAAABJRU5ErkJggg==',
icon2: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAABvklEQVRo3u2Zu0oDQRSGv0jUWKigTZAIYiH2Bn0FOx/AQiSVVV4hpYiVta3YeEGsLSwEo40+gRcQO4MXtIzF7uKyzGSzs3NmDcwPU+25/N/mZGaXBS8vL6//rEXgFPgAusKrZdv8LPDmwLgYxJFj89YhXIyNKESyqJSWUI/q9qAAiEHoAGyNiTiEawDrEEUA9IIYGACAlX7jSykAqlhbf+hSyvVuP/FDlswUJg9QtMoGOWmz61QD/wt4gKIlAVABmkAb+ArXNbAFjGSo85rXiMlRXgPu0Z++hxn6jwIN4DlD/1wAlRTzB8C4gY9p4NwFQLOH+V3ybb9GuVkB2ujvfCFnR1aAT0XOIzBh2L/qGuBbkbNu2LtO8E5gmm8EcJuIf8Jsm64DnbDGD7DsCmAzEW/yGhg3H60rVwBl4CYWv6qJm8lg/gGYcwUAMMXfblRTXG+FJuvS5k0BIJj7DWBYYT6qFYcQMZ8HQKedRL0OwaOCiHkJgBKwr6ib3LnmbZgHeE9plrbWFDXLwJkm3tqdj3SSE2BPU3cMuJQ2D7BAvg8cLwSPxCpNAneS5uMQx5iPU6NH7SpwIWney8vLS16/eT7oBHxeUFYAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDktMTdUMTY6Mjk6NTQrMDA6MDCj7IdOAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA5LTE3VDE2OjI5OjU0KzAwOjAw0rE/8gAAAABJRU5ErkJggg==',
title: 'Save',
disabled: function () { return _this.isSaveButtonDisabled() },
action: function () { _this.save() }
},
agent: {
name: 'agent',
icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0iIzAwMCIgZD0iTTEyIDJDNi40NzcgMiAyIDYuNDc3IDIgMTJzNC40NzcgMTAgMTAgMTAgMTAtNC40NzcgMTAtMTBTMTcuNTIzIDIgMTIgMnptMCAyYzQuNDE4IDAgOCAzLjU4MiA4IDhzLTMuNTgyIDgtOCA4LTgtMy41ODItOC04IDMuNTgyLTggOC04eiIvPjxwYXRoIGZpbGw9IiMwMDAiIGQ9Ik0xMiA2Yy0zLjMxNCAwLTYgMi42ODYtNiA2czIuNjg2IDYgNiA2IDYtMi42ODYgNi02LTIuNjg2LTYtNi02em0wIDJjMi4yMDkgMCA0IDEuNzkxIDQgNHMtMS43OTEgNC00IDQtNC0xLjc5MS00LTQgMS43OTEtNCA0LTR6Ii8+PC9zdmc+',
title: 'AI Agent',
disabled: function () { return _this.isAgentButtonDisabled() },
action: function () { _this.editAgent() }
},
github: {
name: 'github',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAADIklEQVRo3u2Y20tUQRzHPyrdzFKoxUv5WlGhkCX10JUgejQquzxE/0IQRBYVBAoSJSZmvfYqFpQEQXSBoCihx+olSreLRmDXLWt7mFl2nT0zZ845c45B+4UB2d+c7+/7nRln5jdQQgn/N8oc8VQArcBWoAVYAdQDVTL+BUgDz4GnwB3gMfBnpgegEegCRoFswPYG6ASWzoTwFDAAZEIIV1sG6AcWJyX+APDRgXC1TQD74hQ+C7gSg3C1XZK5nKISGE5AfK7dlDmdjXyS4nPtNjDbhYEklo2u9UcVf1BDfAHYBfQB7yMIfAdclFw9mj7tYcWn0O82Kwv6zQM6gM8yNoU4sB4ilt6w/PuFjGVl3w75bQ6rNLnGgUVhDAxoCL9p+jcAG8mfvl6okn0aNPHvmpx9QcU3oj+kJsKMhiV0M/6DgCd2F/p1+5vpU+8KlZJbl7fTlqgC/7tNUwwGmnxyvgbKbYg2+BANxCA+h8s+uVttSI4bCCYJuSNYIkV+N/Nqx9QPvKZkrSHBEOIfLS6MA9cN8RYbA8sMBPdiFJ/DXUNsuY2BegPBWAIGRg2xIm1eBkwH0UxjgY2BKQNBElVTyhAr0uZlwHTS1iVgwLSEi7R5GRg3EGxKwMBmQ+yDjYFXBoJtOKyUPDAf2GKIF2nzMvDAQFAFHInRwFHMA3TfhqQZ83E+CayOQXwz4gEs8h2sHPHoZCJKy4SusAZRnTm5zAGcUD7+BLxUfssAZ4HaCMKXAN3ALx/xWcQdzRq1TC9oeuXv6xDlomrkFuKitRNYaOCtAdqAk4j3URvhWUSlZjofPNGrkFxF1AqN6Av5Z8BcA+ccYMRStPqIEBjViLVeSHRGxnaQL9AL22EL3vaA4sd8ZtWIPQrZV/Kn8XbgEfATccDcwG6aGwIa2B1WfA7nFMLzEfkqAojvjioexNY1VEA6BRyKyGkjfpAA26YfKoFrSoJhYD+wHlEptTk0MEgMLx9lwGmfxC4M9OBw5L2wl+LdyYWBNGLTSAQ1iOc+9fUujIEM4oG3OinxhagDTiFG70mA70aAt4glmUSRVEIJJfyr+AubsTWHiHv2sgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0yOVQxNjozMzoyNCswMDowMAydbHEAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMjlUMTY6MzM6MjQrMDA6MDB9wNTNAAAAAElFTkSuQmCC',
title: 'Github',
disabled: function () { return false },
action: function () {
var link = document.createElement('a');
var ncsedt = document.querySelector('#ncsedt-implement');
link.setAttribute('href', 'https://github.com/FranBarInstance/simple-html-editor');
link.setAttribute('target', '_blank');
ncsedt.appendChild(link);
link.click();
}
}
},
draggerIcon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABgAAAAYADwa0LPAAAA+klEQVRo3u3ZUQ7CIBAE0NGDGOL9r+SHJ6k/bWJIkV3KDrvCJHx3XgwsrcDKiuukfYXMA8ALwBvAc3SZ1vLbvkIh8vKhEKXyIRC18q4R0vIuEdryrhCt5bshboa4jfGsuyGAkukAidDJ7BnHhpUm37DSmJxO36eNNaD7EZsflQxAN8TZOc8CXEaUhhQT0Iz4NWHZADXi6vXAaokQXssXEeEn8Vm8/grd9oE0wzZxDcEGdJ8FTIDJNGYBzO5DDIDpjdQaYPqynwgAzTPWS/3wTA/QTOy/+zrnonwrwlV5LcJleSnCdfkaIkT5EiJU+RwRsvyRhMB/dK9MkQ9aiYmYo9JGZAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wOS0xNlQxMjoyOTo1MSswMDowMJ8FU+4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDktMTZUMTQ6Mjk6NTErMDA6MDDuWOtSAAAAAElFTkSuQmCC'
}
this.options = this.deepMerge(defaults, options);
this.options.mutationGroupingWindowMs = this.options.mutationGroupingWindowMs / TIME_SCALE_FACTOR;
this.sessionConfig = {
aiBackends: JSON.parse(JSON.stringify(this.options.aiBackends))
};
/*
<div id="ncsedt-implement">:
The code to run the editor, the developer or user of the editor creates it. There can only be one.
<ncsedt-editable id="ncsedt-editable">:
Container that creates this script for editable HTML. Internal use of this application.
Initial tree (editable = 'body'):
html
|-- head
`-- body (editable)
|-- body content ...
`-- ncsedt-implement
`-- new ncSimpleHtmlEditor()
Necessary tree:
html
|-- head
`-- body
|-- ncsedt-editable (editable)
| `-- body content ...
`-- ncsedt-implement
`-- new ncSimpleHtmlEditor()
Initial tree (editable = 'div'):
html
|-- head
`-- body
|-- div (editable)
`-- ncsedt-implement
`-- new ncSimpleHtmlEditor()
Necessary tree:
html
|-- head
`-- body
|-- ncsedt-editable (editable)
| `-- div
`-- ncsedt-implement
`-- new ncSimpleHtmlEditor()
Then:
- The highest node that can be edited is body.
- Wrap editable in ncsedt-editable.
- Ensure that the implement is the last child of the body.
*/
this.editingEnabled = null;
this.clipboard = null;
this.editable = document.querySelector(this.options.editableContentSelector);
this.editableInBody();
this.wrapEditable();
this.implement = document.querySelector('#ncsedt-implement');
this.implementToLastBody();
this.focusedElement = this.editable;
this.previousFocusedElement = this.focusedElement;
this.observer = this.setObserver();
this.historyUndo = [];
this.historyRedo = [];
this.historyForce = [];
/*
* Events that must be available before "start".
*/
this.setEventEditorChanges();
}
ncSimpleHtmlEditor.prototype.deepMerge = function (target, source) {
for (key of Object.keys(source)) {
if (!target.hasOwnProperty(key) || typeof source[key] !== 'object') {
target[key] = source[key];
} else {
this.deepMerge(target[key], source[key]);
}
}
return target;
}
ncSimpleHtmlEditor.prototype.isEditingEnabled = function () {
return this.editingEnabled;
}
ncSimpleHtmlEditor.prototype.getCurrentFocusedElement = function () {
return this.focusedElement;
}
ncSimpleHtmlEditor.prototype.getPreviousFocusedElement = function () {
return this.previousFocusedElement;
}
ncSimpleHtmlEditor.prototype.getEditable = function (target, source) {
return this.editable;
}
/**
* Get clipboard content, can be null.
*/
ncSimpleHtmlEditor.prototype.getClipboard = function (target, source) {
return this.clipboard;
}
/**
* The highest node that can be editable is body
*/
ncSimpleHtmlEditor.prototype.editableInBody = function () {
if (this.editable.contains(document.body) && this.editable != document.body) {
console.log('The highest node that can be edited is body, set options.editableContentSelector = "body"');
this.options.editableContentSelectorContentSelector = 'body';
this.editable = document.querySelector(this.options.editableContentSelector);
}
};
/**
* Wrap editable content/innerHTML
*/
ncSimpleHtmlEditor.prototype.wrapEditable = function () {
const wrapContent = (target, wrapper = document.createElement('ncsedt-editable')) => {
;[...target.childNodes].forEach(child => wrapper.appendChild(child))
target.appendChild(wrapper);
return wrapper;
}
this.editable = wrapContent(this.editable);
this.editable.id = "ncsedt-editable";
this.editable.setAttribute("contentEditable", "true");
};
/**
* Separate the editor code from the editable content,
* preventing the code from being part of the editable content.
*/
ncSimpleHtmlEditor.prototype.implementToLastBody = function () {
var implement = document.createDocumentFragment();
implement.appendChild(this.implement);
document.body.appendChild(implement);
this.implement.insertAdjacentHTML('beforeend', '<div id="ncsedt-container"></div>');
this.implement.insertAdjacentHTML('beforebegin', '<!-- ncsedt-implement:begin -->');
this.implement.insertAdjacentHTML('afterend', '<!-- ncsedt-implement:end -->');
this.container = document.getElementById('ncsedt-container');
this.container.insertAdjacentHTML('beforebegin', '<!-- ncsedt-container:begin -->');
this.container.insertAdjacentHTML('afterend', '<!-- ncsedt-container:end -->');
};
/**
* Start the editor, the editorstart event is called at the end.
*/
ncSimpleHtmlEditor.prototype.start = function () {
this.editOff();
this.tollbar = this.renderTollbar();
this.dialogCode = this.renderDialogCode();
this.dialogImage = this.renderDialogImage();
this.dialogLink = this.renderDialogLink();
this.dialogHead = this.renderDialogHead();
this.dialogAgent = this.renderDialogAgent();
this.dialogConfig = this.renderConfigDialog();
this.movable('#ncsedt-toolbar', '#ncsedt-toolbar-dragger');
this.movable('#ncsedt-dialog-code', '#ncsedt-dialog-code .dragger');
this.movable('#ncsedt-dialog-image', '#ncsedt-dialog-image .dragger');
this.movable('#ncsedt-dialog-link', '#ncsedt-dialog-link .dragger');
this.movable('#ncsedt-dialog-head', '#ncsedt-dialog-head .dragger');
this.movable('#ncsedt-dialog-agent', '#ncsedt-dialog-agent .dragger');
this.movable('#ncsedt-dialog-config', '#ncsedt-dialog-config .dragger');
this.setEvents();
this.setEventsToolbar();
this.setEventsDialogCode();
this.setEventsDialogImage();
this.setEventsDialogLink();
this.setEventsDialogHead();
this.setEventsDialogAgent();
this.setupConfigDialogEvents();
document.dispatchEvent(new Event("editorstart"));
};
/**
* Activate editing, set this.editEnable=true which allows you to
* desterminate if the editor is active
*/
ncSimpleHtmlEditor.prototype.editOn = function () {
var btnsEdit = document.querySelectorAll('.ncsedt-toolbar-btn-edit img');
this.editable.setAttribute("contentEditable", "true");
for (element of btnsEdit) {
element.src = this.options.buttons.edit.icon2;
}
this.editingEnabled = true;
this.setFocus(this.focusedElement);
this.observe();
document.dispatchEvent(new Event("editorchanges"));
};
/**
* Deactivate editing, set this.editEnable=false which allows you to
* desterminate if the editor is deactivated
*/
ncSimpleHtmlEditor.prototype.editOff = function () {
this.observer.disconnect();
var editable = document.querySelectorAll('*[contentEditable]');
var btnsEdit = document.querySelectorAll('.ncsedt-toolbar-btn-edit img');
for (element of editable) {
element.setAttribute("contentEditable", "false");
}
for (element of btnsEdit) {
element.src = this.options.buttons.edit.icon;
}
for (focused of document.querySelectorAll(".focused")) {
focused.classList.remove('focused');
}
this.editingEnabled = false;
document.dispatchEvent(new Event("editorchanges"));
};
/**
* Sets the focus on the element currently being edited.
* Receives the element on which the focus will be set.
*/
ncSimpleHtmlEditor.prototype.setFocus = function (element) {
if (!this.editingEnabled) {
return;
}
if (!element) {
return;
}
if (!element.isContentEditable) {
return;
}
for (oldfocused of document.querySelectorAll(".focused")) {
oldfocused.classList.remove('focused');
}
this.previousFocusedElement = this.focusedElement;
this.focusedElement = element;
this.focusedElement.focus();
this.focusedElement.classList.add('focused');
document.dispatchEvent(new Event("focusedchange"));
};
/**
* Download html with the current changes.
* You may need to replace this function with your own.
*/
ncSimpleHtmlEditor.prototype.save = function () {
var _this = this;
var templatesource = this.getDocumentHTML();
var download = document.createElement('a');
var btnsSave = document.querySelectorAll('.ncsedt-toolbar-btn-save img');
this.saving = true;
this.editOff();
for (button of btnsSave) {
button.src = this.options.buttons.save.icon2;
button.parentNode.disabled = true;
}
download.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(templatesource));
download.setAttribute('download', 'index.html');
this.container.appendChild(download);
download.click();
setTimeout(function () {
_this.saving = false;
for (button of btnsSave) {
button.src = _this.options.buttons.save.icon;
button.parentNode.disabled = false;
}
}, this.options.saveTimeout);
this.container.removeChild(download);
this.editOn();
};
/**
* Get the HTML with the current changes.
* If no selector is indicated, the complete document.
*/
ncSimpleHtmlEditor.prototype.getDocumentHTML = function (selector = null) {
var html = '';
window.scrollTo({
top: 0,
left: 0,
behavior: 'instant'
});
this.restorable.restore();
this.removable();
if (selector) {
html = document.querySelector(selector).innerHTML;
} else {
html = new XMLSerializer().serializeToString(document);
}
this.undoRemovable();
this.restorable.undoRestore();
return this.ncsedtRemover(html);
};
/**
* Removes the code from the HTML editor.
*/
ncSimpleHtmlEditor.prototype.ncsedtRemover = function (html) {
/*
* Everything between <!-- ncsedt-implement:before --> and </ncsedt-editable>
* was created dynamically and must be removed.
*/
html = html.replace(/<ncsedt-removable>\s*<\/ncsedt-removable>/gsi, '');
html = html.replace(/<!--\s*ncsedt-implement:before\s*-->.*<\/ncsedt-editable>/gsi, '</ncsedt-editable>');
html = html.replace(/<!--\s*ncsedt-implement:begin\s*-->.*<!--\s*ncsedt-implement:end\s*-->/gsi, '');
html = html.replace(/<!--\s*ncsedt-container:begin\s*-->.*<!--\s*ncsedt-container:end\s*-->/gsi, '');
html = html.replace(/<\/?ncsedt-editable[^>]*>/gsi, '');
return html;
};
ncSimpleHtmlEditor.prototype.removable = function () {
var _this = this;
var count = 0;
this.removableHtml = [];
document.querySelectorAll('ncsedt-removable').forEach(function (node) {
_this.removableHtml[count++] = node.innerHTML;
node.innerHTML = '';
});
};
ncSimpleHtmlEditor.prototype.undoRemovable = function () {
var _this = this;
var count = 0;
document.querySelectorAll('ncsedt-removable').forEach(function (node) {
node.innerHTML = _this.removableHtml[count++];
});
};
ncSimpleHtmlEditor.prototype.editToggle = function () {
if (this.editingEnabled) {
this.editOff();
} else {
this.editOn();
}
};
ncSimpleHtmlEditor.prototype.undo = function () {
this.undoredo(true);
};
ncSimpleHtmlEditor.prototype.redo = function () {
this.undoredo(false);
};
/**
* Focus on parent
*/
ncSimpleHtmlEditor.prototype.up = function () {
if (this.focusedElement.parentElement) {
this.setFocus(this.focusedElement.parentElement);
this.focusedElement.scrollIntoView({ block: "center" });
}
};
/**
* Focus on first child
*/
ncSimpleHtmlEditor.prototype.down = function () {
if (this.focusedElement.firstElementChild) {
this.setFocus(this.focusedElement.firstElementChild);
this.focusedElement.scrollIntoView({ block: "center" });
}
};
/**
* Focus on previous sibling or previous parent sibling
*/
ncSimpleHtmlEditor.prototype.previous = function () {
if (this.focusedElement.previousElementSibling) {
this.setFocus(this.focusedElement.previousElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
} else if (this.focusedElement.parentElement.previousElementSibling) {
this.setFocus(this.focusedElement.parentElement.previousElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
} else if (this.focusedElement.parentElement.parentElement &&
this.focusedElement.parentElement.parentElement.previousElementSibling) {
this.setFocus(this.focusedElement.parentElement.parentElement.previousElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
}
};
/**
* Focus on next sibling or next parent sibling
*/
ncSimpleHtmlEditor.prototype.next = function () {
if (this.focusedElement.nextElementSibling) {
this.setFocus(this.focusedElement.nextElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
} else if (this.focusedElement.parentElement.nextElementSibling) {
this.setFocus(this.focusedElement.parentElement.nextElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
} else if (this.focusedElement.parentElement.parentElement &&
this.focusedElement.parentElement.parentElement.nextElementSibling) {
this.setFocus(this.focusedElement.parentElement.parentElement.nextElementSibling);
this.focusedElement.scrollIntoView({ block: "center" });
}
};
ncSimpleHtmlEditor.prototype.copy = function () {
if (this.focusedElement != this.editable) {
this.clipboard = this.focusedElement.outerHTML;
document.dispatchEvent(new Event("editorchanges"));
}
};
ncSimpleHtmlEditor.prototype.cut = function () {
if (this.focusedElement != this.editable) {
this.clipboard = this.focusedElement.outerHTML;
this.focusedElement.parentElement.removeChild(this.focusedElement);
this.setFocus(this.focusedElement.parentElement);
}
};
ncSimpleHtmlEditor.prototype.paste = function () {
if (this.clipboard && this.focusedElement != this.editable) {
this.focusedElement.insertAdjacentHTML('afterend', this.clipboard);
}
};
ncSimpleHtmlEditor.prototype.isAgentButtonDisabled = function () {
return !this.editingEnabled;
};
ncSimpleHtmlEditor.prototype.isEditButtonDisabled = function () {
return false;
};
ncSimpleHtmlEditor.prototype.isSaveButtonDisabled = function () {
return !this.editingEnabled || this.saving;
};
ncSimpleHtmlEditor.prototype.isUndoButtonDisabled = function () {
return !this.isEditingEnabled() || !this.hasUndoHistory();
};
ncSimpleHtmlEditor.prototype.hasUndoHistory = function () {
return this.historyUndo.length > 0;
};
ncSimpleHtmlEditor.prototype.isRedoButtonDisabled = function () {
return !this.isEditingEnabled() || !this.hasRedoHistory();
};
ncSimpleHtmlEditor.prototype.hasRedoHistory = function () {
return this.historyRedo.length > 0;
};
ncSimpleHtmlEditor.prototype.isUpButtonDisabled = function () {
return !this.editingEnabled || !this.canMoveUp();
};
ncSimpleHtmlEditor.prototype.canMoveUp = function () {
return this.focusedElement.parentElement && this.focusedElement.parentElement.isContentEditable;
};
ncSimpleHtmlEditor.prototype.isDownButtonDisabled = function () {
return !this.editingEnabled || !this.canMoveDown();
};
ncSimpleHtmlEditor.prototype.canMoveDown = function () {
return this.focusedElement.firstElementChild;
};
ncSimpleHtmlEditor.prototype.isPreviousButtonDisabled = function () {
return !this.editingEnabled || !this.canMovePrevious();
};
ncSimpleHtmlEditor.prototype.canMovePrevious = function () {
return this.focusedElement.previousElementSibling ||
(this.focusedElement.parentElement &&
this.focusedElement.parentElement.previousElementSibling) ||
(this.focusedElement.parentElement &&
this.focusedElement.parentElement.parentElement &&
this.focusedElement.parentElement.parentElement.previousElementSibling);
};
ncSimpleHtmlEditor.prototype.isNextButtonDisabled = function () {
return !this.editingEnabled || !this.canMoveNext();
};
ncSimpleHtmlEditor.prototype.canMoveNext = function () {
return this.focusedElement.nextElementSibling ||
(this.focusedElement.parentElement &&
this.focusedElement.parentElement.nextElementSibling) ||
(this.focusedElement.parentElement &&
this.focusedElement.parentElement.parentElement &&
this.focusedElement.parentElement.parentElement.nextElementSibling);
};
ncSimpleHtmlEditor.prototype.isCutButtonDisabled = function () {
return !this.editingEnabled || this.focusedElement == this.editable;
};
ncSimpleHtmlEditor.prototype.isCopyButtonDisabled = function () {
return !this.editingEnabled || this.focusedElement == this.editable;
};
ncSimpleHtmlEditor.prototype.isPasteButtonDisabled = function () {
return !this.editingEnabled || !this.clipboard || this.focusedElement == this.editable;
};
ncSimpleHtmlEditor.prototype.isLinkButtonDisabled = function () {
return !this.editingEnabled;
};
ncSimpleHtmlEditor.prototype.isImageButtonDisabled = function () {
return !this.editingEnabled;
};
ncSimpleHtmlEditor.prototype.isHeadButtonDisabled = function () {
return !this.editingEnabled;
};
ncSimpleHtmlEditor.prototype.isCodeButtonDisabled = function () {
return !this.editingEnabled;
};
/**
* Validate editor options
*/
ncSimpleHtmlEditor.prototype.validateOptions = function (options) {
if (options.editableContentSelector && typeof options.editableContentSelector !== 'string') {
throw new Error('Option "editable" must be a string selector');
}
if (options.maxImageSizeBytes && typeof options.maxImageSizeBytes !== 'number') {
throw new Error('Option "maxImageUpload" must be a number');
}
if (options.toolbar && !Array.isArray(options.toolbar)) {
throw new Error('Option "toolbar" must be an array');
}
if (options.mutationGroupingWindowMs) {
options.mutationGroupingWindowMs = Math.max(MIN_GROUPING_WINDOW_MS, options.mutationGroupingWindowMs);
}
if (options.maxImageSizeBytes) {
options.maxImageSizeBytes = Math.min(options.maxImageSizeBytes, MAX_ALLOWED_IMAGE_SIZE_BYTES);
}
if (options.aiBackends) {
const validBackends = ['ollama', 'openrouter', 'anthropic', 'azure', 'gemini', 'openai'];
for (const backend of validBackends) {
if (options.aiBackends[backend]) {
if (typeof options.aiBackends[backend].enabled !== 'boolean') {
options.aiBackends[backend].enabled = false;
}
if (backend === 'azure') {
if (!options.aiBackends[backend].url || !options.aiBackends[backend].model) {
options.aiBackends[backend].enabled = false;
console.warn(`Azure backend disabled - URL and model must be configured`);
}
} else if (backend !== 'ollama') {
if (!options.aiBackends[backend].apiKey) {
options.aiBackends[backend].enabled = false;