@humandialog/forms.svelte 1.3.16 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Fab.svelte +77 -46
- package/components/Floating_container.svelte +1 -1
- package/components/combo/combo.svelte +18 -15
- package/components/combo/combo.svelte.d.ts +1 -0
- package/components/contextmenu.svelte +25 -6
- package/components/date.svelte +10 -4
- package/components/date.svelte.d.ts +1 -0
- package/components/date_utils.d.ts +1 -0
- package/components/date_utils.js +10 -0
- package/components/delayed.spinner.svelte +1 -2
- package/components/document/editor.svelte +419 -46
- package/components/document/editor.svelte.d.ts +115 -0
- package/components/document/internal/palette.svelte +20 -0
- package/components/list/List.d.ts +6 -0
- package/components/list/List.js +6 -0
- package/components/list/internal/list.element.props.svelte +23 -8
- package/components/list/internal/list.element.svelte +43 -18
- package/components/list/internal/list.element.svelte.d.ts +1 -0
- package/components/list/list.combo.svelte +6 -0
- package/components/list/list.combo.svelte.d.ts +3 -0
- package/components/list/list.date.svelte +8 -0
- package/components/list/list.date.svelte.d.ts +4 -0
- package/components/list/list.static.svelte +6 -0
- package/components/list/list.static.svelte.d.ts +3 -0
- package/components/list/list.svelte +17 -17
- package/components/list/list.tags.svelte +32 -0
- package/components/list/list.tags.svelte.d.ts +24 -0
- package/components/sidebar/sidebar.item.svelte +25 -8
- package/components/tags.svelte +15 -7
- package/components/tags.svelte.d.ts +2 -0
- package/desk.svelte +9 -6
- package/index.d.ts +7 -2
- package/index.js +7 -2
- package/operations.svelte +61 -12
- package/package.json +4 -2
- package/stores.d.ts +3 -0
- package/stores.js +25 -2
- package/tenant.members.svelte +61 -59
- package/tenant.members.svelte.d.ts +2 -0
|
@@ -69,6 +69,11 @@ export let onAddImage = void 0;
|
|
|
69
69
|
export let onRemoveImage = void 0;
|
|
70
70
|
export let c = "";
|
|
71
71
|
export let pushChangesImmediately = true;
|
|
72
|
+
export let chat = void 0;
|
|
73
|
+
export let readOnly = false;
|
|
74
|
+
export let extraFrontPaletteCommands = [];
|
|
75
|
+
export let extraBackPaletteCommands = [];
|
|
76
|
+
export let extraInsertPaletteCommands = [];
|
|
72
77
|
let onFinishEditing = void 0;
|
|
73
78
|
export function run(onStop = void 0) {
|
|
74
79
|
onFinishEditing = onStop;
|
|
@@ -77,7 +82,7 @@ export function run(onStop = void 0) {
|
|
|
77
82
|
let suggestionRange = void 0;
|
|
78
83
|
export function getFormattingOperations(withCaptions = false) {
|
|
79
84
|
let result = [];
|
|
80
|
-
|
|
85
|
+
paletteCommands.forEach((c2) => {
|
|
81
86
|
if (c2.separator) {
|
|
82
87
|
result.push({ separator: true });
|
|
83
88
|
} else {
|
|
@@ -92,6 +97,80 @@ export function getFormattingOperations(withCaptions = false) {
|
|
|
92
97
|
});
|
|
93
98
|
return result;
|
|
94
99
|
}
|
|
100
|
+
export function getMarksOperations(tbr = "A") {
|
|
101
|
+
let operations = [];
|
|
102
|
+
paletteMarksCommands.forEach((c2) => {
|
|
103
|
+
if (!c2.separator) {
|
|
104
|
+
operations.push({
|
|
105
|
+
caption: c2.caption,
|
|
106
|
+
icon: c2.icon ?? void 0,
|
|
107
|
+
action: (f) => c2.on_choice(suggestionRange),
|
|
108
|
+
activeFunc: c2.is_active
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
caption: "Text",
|
|
114
|
+
operations,
|
|
115
|
+
preAction: (f) => {
|
|
116
|
+
if (editor.isFocused)
|
|
117
|
+
lockNextBlurCallbacks++;
|
|
118
|
+
},
|
|
119
|
+
tbr
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function getStylesOperations(tbr = "A") {
|
|
123
|
+
let operations = [];
|
|
124
|
+
paletteStylesCommands.forEach((c2) => {
|
|
125
|
+
if (!c2.separator) {
|
|
126
|
+
operations.push({
|
|
127
|
+
caption: c2.caption,
|
|
128
|
+
icon: c2.icon ?? void 0,
|
|
129
|
+
action: (f) => c2.on_choice(suggestionRange),
|
|
130
|
+
activeFunc: c2.is_active
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
caption: "Styles",
|
|
136
|
+
operations,
|
|
137
|
+
preAction: (f) => {
|
|
138
|
+
if (editor.isFocused)
|
|
139
|
+
lockNextBlurCallbacks++;
|
|
140
|
+
},
|
|
141
|
+
tbr
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function getInsertOperations(tbr = "A") {
|
|
145
|
+
let operations = [];
|
|
146
|
+
if (extraInsertPaletteCommands && extraInsertPaletteCommands.length > 0) {
|
|
147
|
+
extraInsertPaletteCommands.forEach((exc) => {
|
|
148
|
+
operations = [...operations, exc];
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
paletteInsertCommands.forEach((c2) => {
|
|
152
|
+
if (!c2.separator) {
|
|
153
|
+
operations.push({
|
|
154
|
+
caption: c2.caption,
|
|
155
|
+
icon: c2.icon ?? void 0,
|
|
156
|
+
action: (f) => c2.on_choice(suggestionRange),
|
|
157
|
+
activeFunc: c2.is_active
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
caption: "Insert",
|
|
163
|
+
operations,
|
|
164
|
+
preAction: (f) => {
|
|
165
|
+
if (editor.isFocused)
|
|
166
|
+
lockNextBlurCallbacks++;
|
|
167
|
+
},
|
|
168
|
+
tbr
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function scrollIntoView(param) {
|
|
172
|
+
editorElement.scrollIntoView(param);
|
|
173
|
+
}
|
|
95
174
|
let item = null;
|
|
96
175
|
let changedValue = "";
|
|
97
176
|
let hasChangedValue = false;
|
|
@@ -244,8 +323,8 @@ const _CodeBlock = Paragraph.extend({
|
|
|
244
323
|
},
|
|
245
324
|
addCommands() {
|
|
246
325
|
return {
|
|
247
|
-
setAsCode: () => ({ commands
|
|
248
|
-
return
|
|
326
|
+
setAsCode: () => ({ commands }) => {
|
|
327
|
+
return commands.setNode(this.name);
|
|
249
328
|
}
|
|
250
329
|
};
|
|
251
330
|
}
|
|
@@ -275,8 +354,8 @@ const CommentBlock = Paragraph.extend({
|
|
|
275
354
|
},
|
|
276
355
|
addCommands() {
|
|
277
356
|
return {
|
|
278
|
-
setAsComment: () => ({ commands
|
|
279
|
-
return
|
|
357
|
+
setAsComment: () => ({ commands }) => {
|
|
358
|
+
return commands.setNode(this.name);
|
|
280
359
|
}
|
|
281
360
|
};
|
|
282
361
|
}
|
|
@@ -306,8 +385,8 @@ const WarningBlock = Paragraph.extend({
|
|
|
306
385
|
},
|
|
307
386
|
addCommands() {
|
|
308
387
|
return {
|
|
309
|
-
setAsWarning: () => ({ commands
|
|
310
|
-
return
|
|
388
|
+
setAsWarning: () => ({ commands }) => {
|
|
389
|
+
return commands.setNode(this.name);
|
|
311
390
|
}
|
|
312
391
|
};
|
|
313
392
|
}
|
|
@@ -337,8 +416,8 @@ const InfoBlock = Paragraph.extend({
|
|
|
337
416
|
},
|
|
338
417
|
addCommands() {
|
|
339
418
|
return {
|
|
340
|
-
setAsInfo: () => ({ commands
|
|
341
|
-
return
|
|
419
|
+
setAsInfo: () => ({ commands }) => {
|
|
420
|
+
return commands.setNode(this.name);
|
|
342
421
|
}
|
|
343
422
|
};
|
|
344
423
|
}
|
|
@@ -359,8 +438,8 @@ const QuoteBlock = Paragraph.extend({
|
|
|
359
438
|
},
|
|
360
439
|
addCommands() {
|
|
361
440
|
return {
|
|
362
|
-
setAsQuote: () => ({ commands
|
|
363
|
-
return
|
|
441
|
+
setAsQuote: () => ({ commands }) => {
|
|
442
|
+
return commands.setNode(this.name);
|
|
364
443
|
}
|
|
365
444
|
};
|
|
366
445
|
}
|
|
@@ -399,8 +478,7 @@ const CrossImage = Image.extend({
|
|
|
399
478
|
if (res.ok) {
|
|
400
479
|
res.blob().then((blob) => {
|
|
401
480
|
newEntry.url = URL.createObjectURL(blob);
|
|
402
|
-
|
|
403
|
-
editorElement.querySelectorAll("img").forEach((img) => {
|
|
481
|
+
editorElement?.querySelectorAll("img").forEach((img) => {
|
|
404
482
|
if (img.getAttribute("data-path") == dataPath)
|
|
405
483
|
img.src = newEntry.url;
|
|
406
484
|
});
|
|
@@ -424,12 +502,60 @@ const CrossImage = Image.extend({
|
|
|
424
502
|
return {};
|
|
425
503
|
}
|
|
426
504
|
}
|
|
505
|
+
},
|
|
506
|
+
temporary: {
|
|
507
|
+
default: "",
|
|
508
|
+
parseHTML: (element) => {
|
|
509
|
+
return element.getAttribute("temporary");
|
|
510
|
+
},
|
|
511
|
+
renderHTML: (attributes) => {
|
|
512
|
+
const temporary = attributes.temporary;
|
|
513
|
+
if (temporary) {
|
|
514
|
+
return {
|
|
515
|
+
temporary,
|
|
516
|
+
src: temporary
|
|
517
|
+
};
|
|
518
|
+
} else
|
|
519
|
+
return {};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
const chatShortcuts = Extension.create({
|
|
526
|
+
name: "chatShortcuts",
|
|
527
|
+
addKeyboardShortcuts() {
|
|
528
|
+
return {
|
|
529
|
+
Enter: () => {
|
|
530
|
+
if (chat && chat.onSubmit)
|
|
531
|
+
chat.onSubmit(changedValue);
|
|
532
|
+
return this.editor.commands.clearContent();
|
|
533
|
+
},
|
|
534
|
+
"Shift-Enter": () => {
|
|
535
|
+
console.log("chatShortcut Shift-Enter");
|
|
536
|
+
return this.editor.commands.first(({ commands }) => [
|
|
537
|
+
() => commands.newlineInCode(),
|
|
538
|
+
() => commands.createParagraphNear(),
|
|
539
|
+
() => commands.liftEmptyBlock(),
|
|
540
|
+
() => commands.splitBlock()
|
|
541
|
+
]);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
const additionalShortcuts = Extension.create({
|
|
547
|
+
name: "additionalShortcuts",
|
|
548
|
+
addKeyboardShortcuts() {
|
|
549
|
+
return {
|
|
550
|
+
"Mod-s": () => {
|
|
551
|
+
console.log("todo: save content");
|
|
427
552
|
}
|
|
428
553
|
};
|
|
429
554
|
}
|
|
430
555
|
});
|
|
431
556
|
onMount(() => {
|
|
432
557
|
editor = new Editor({
|
|
558
|
+
editable: !readOnly,
|
|
433
559
|
editorProps: {
|
|
434
560
|
attributes: {
|
|
435
561
|
class: `${cs} ${appearance_class} prose prose-base sm:prose-base dark:prose-invert ${additional_class} whitespace-pre-wrap focus:outline-none`
|
|
@@ -474,6 +600,7 @@ onMount(() => {
|
|
|
474
600
|
Dropcursor,
|
|
475
601
|
Gapcursor,
|
|
476
602
|
History,
|
|
603
|
+
...chat ? [chatShortcuts] : [],
|
|
477
604
|
PalletePlugin.configure({
|
|
478
605
|
suggestion
|
|
479
606
|
})
|
|
@@ -554,7 +681,6 @@ function saveData() {
|
|
|
554
681
|
if (!hasChangedValue)
|
|
555
682
|
return false;
|
|
556
683
|
hasChangedValue = false;
|
|
557
|
-
console.log("editor: saveData");
|
|
558
684
|
if (onChange) {
|
|
559
685
|
onChange(changedValue);
|
|
560
686
|
return true;
|
|
@@ -673,6 +799,37 @@ function show_big_command_palette(cursor_rect, client_rect) {
|
|
|
673
799
|
else
|
|
674
800
|
palette.show(x, y, show_above);
|
|
675
801
|
}
|
|
802
|
+
export function addTemporaryImage(src) {
|
|
803
|
+
editor.commands.insertContent({
|
|
804
|
+
type: "image",
|
|
805
|
+
attrs: {
|
|
806
|
+
src: "",
|
|
807
|
+
temporary: src
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
export function replaceTemporaryImage(temporarySrc, dataPath) {
|
|
812
|
+
const image = editor.$node("image", { temporary: temporarySrc });
|
|
813
|
+
if (!image)
|
|
814
|
+
return;
|
|
815
|
+
image.setAttribute({
|
|
816
|
+
dataPath,
|
|
817
|
+
src: "",
|
|
818
|
+
temporary: ""
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
export function removeTemporaryImage(temporarySrc) {
|
|
822
|
+
const image = editor.$node("image", { temporary: temporarySrc });
|
|
823
|
+
if (!image)
|
|
824
|
+
return;
|
|
825
|
+
editor.commands.deleteRange(image.range);
|
|
826
|
+
}
|
|
827
|
+
export function getInnerHtml() {
|
|
828
|
+
return editor.getHTML();
|
|
829
|
+
}
|
|
830
|
+
export function setInnerHtml(content) {
|
|
831
|
+
editor.commands.SetContent(content);
|
|
832
|
+
}
|
|
676
833
|
async function onAddedImageReady(dataPath) {
|
|
677
834
|
editor.commands.insertContent({
|
|
678
835
|
type: "image",
|
|
@@ -687,7 +844,10 @@ function handleImagesChanges(transaction) {
|
|
|
687
844
|
let srcs = /* @__PURE__ */ new Set();
|
|
688
845
|
fragment.forEach((node) => {
|
|
689
846
|
if (node.type.name === "image") {
|
|
690
|
-
|
|
847
|
+
if (node.attrs.dataPath)
|
|
848
|
+
srcs.add(node.attrs.dataPath);
|
|
849
|
+
else if (node.attrs.temporary)
|
|
850
|
+
srcs.add(node.attrs.temporary);
|
|
691
851
|
}
|
|
692
852
|
});
|
|
693
853
|
return srcs;
|
|
@@ -701,100 +861,235 @@ function handleImagesChanges(transaction) {
|
|
|
701
861
|
if (onRemoveImage)
|
|
702
862
|
deletedImageSrcs.forEach((src) => onRemoveImage(src));
|
|
703
863
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
864
|
+
export function setBold() {
|
|
865
|
+
makeBold(suggestionRange);
|
|
866
|
+
}
|
|
867
|
+
export function setItalic() {
|
|
868
|
+
makeItalic(suggestionRange);
|
|
869
|
+
}
|
|
870
|
+
export function setUnderline() {
|
|
871
|
+
makeUnderline(suggestionRange);
|
|
872
|
+
}
|
|
873
|
+
export function setStrikethrough() {
|
|
874
|
+
makeStrikethrough(suggestionRange);
|
|
875
|
+
}
|
|
876
|
+
export function setNormal() {
|
|
877
|
+
if (suggestionRange)
|
|
878
|
+
editor.chain().focus().deleteRange(suggestionRange).setParagraph().run();
|
|
879
|
+
else
|
|
880
|
+
editor.chain().focus().setParagraph().run();
|
|
881
|
+
}
|
|
882
|
+
export function setHeading(level) {
|
|
883
|
+
if (suggestionRange)
|
|
884
|
+
editor.chain().focus().deleteRange(suggestionRange).setHeading({ level }).run();
|
|
885
|
+
else
|
|
886
|
+
editor.chain().focus().setHeading({ level }).run();
|
|
887
|
+
}
|
|
888
|
+
export function setCode() {
|
|
889
|
+
if (suggestionRange)
|
|
890
|
+
editor.chain().focus().deleteRange(suggestionRange).setCodeBlock().run();
|
|
891
|
+
else
|
|
892
|
+
editor.chain().focus().setCodeBlock().run();
|
|
893
|
+
}
|
|
894
|
+
export function setComment() {
|
|
895
|
+
if (suggestionRange)
|
|
896
|
+
editor.chain().focus().deleteRange(suggestionRange).setAsComment().run();
|
|
897
|
+
else
|
|
898
|
+
editor.chain().focus().setAsComment().run();
|
|
899
|
+
}
|
|
900
|
+
export function setQuote() {
|
|
901
|
+
if (suggestionRange)
|
|
902
|
+
editor.chain().focus().deleteRange(suggestionRange).setAsQuote().run();
|
|
903
|
+
else
|
|
904
|
+
editor.chain().focus().setAsQuote().run();
|
|
905
|
+
}
|
|
906
|
+
export function setWarning() {
|
|
907
|
+
if (suggestionRange)
|
|
908
|
+
editor.chain().focus().deleteRange(suggestionRange).setAsWarning().run();
|
|
909
|
+
else
|
|
910
|
+
editor.chain().focus().setAsWarning().run();
|
|
911
|
+
}
|
|
912
|
+
export function setInfo() {
|
|
913
|
+
if (suggestionRange)
|
|
914
|
+
editor.chain().focus().deleteRange(suggestionRange).setAsInfo().run();
|
|
915
|
+
else
|
|
916
|
+
editor.chain().focus().setAsInfo().run();
|
|
917
|
+
}
|
|
918
|
+
export function setBulletList() {
|
|
919
|
+
if (suggestionRange)
|
|
920
|
+
editor.chain().focus().deleteRange(suggestionRange).toggleBulletList().run();
|
|
921
|
+
else
|
|
922
|
+
editor.chain().focus().toggleBulletList().run();
|
|
923
|
+
}
|
|
924
|
+
export function setImage() {
|
|
925
|
+
if (suggestionRange)
|
|
926
|
+
editor.chain().focus().deleteRange(suggestionRange).run();
|
|
927
|
+
if (onAddImage)
|
|
928
|
+
onAddImage(onAddedImageReady);
|
|
929
|
+
}
|
|
930
|
+
export function setTable() {
|
|
931
|
+
if (suggestionRange)
|
|
932
|
+
editor.chain().focus().deleteRange(suggestionRange).insertTable().run();
|
|
933
|
+
else
|
|
934
|
+
editor.chain().focus().insertTable().run();
|
|
935
|
+
}
|
|
936
|
+
export function setHorizontalRule() {
|
|
937
|
+
if (suggestionRange)
|
|
938
|
+
editor.chain().focus().deleteRange(suggestionRange).setHorizontalRule().run();
|
|
939
|
+
else
|
|
940
|
+
editor.chain().focus().setHorizontalRule().run();
|
|
941
|
+
}
|
|
942
|
+
export function isActiveBold() {
|
|
943
|
+
return editor?.isActive("bold");
|
|
944
|
+
}
|
|
945
|
+
export function isActiveItalic() {
|
|
946
|
+
return editor?.isActive("italic");
|
|
947
|
+
}
|
|
948
|
+
export function isActiveUnderlie() {
|
|
949
|
+
return editor?.isActive("underline");
|
|
950
|
+
}
|
|
951
|
+
export function isActiveStrikethrough() {
|
|
952
|
+
return editor?.isActive("strike");
|
|
953
|
+
}
|
|
954
|
+
export function isActiveNormal() {
|
|
955
|
+
return editor?.isActive("paragraph");
|
|
956
|
+
}
|
|
957
|
+
export function isActiveHeading(level) {
|
|
958
|
+
return editor?.isActive("heading", { level });
|
|
959
|
+
}
|
|
960
|
+
export function isActiveCode() {
|
|
961
|
+
return editor?.isActive("CodeBlock");
|
|
962
|
+
}
|
|
963
|
+
export function isActiveComment() {
|
|
964
|
+
return editor?.isActive("CommentBlock");
|
|
965
|
+
}
|
|
966
|
+
export function isActiveQuote() {
|
|
967
|
+
return editor?.isActive("QuoteBlock");
|
|
968
|
+
}
|
|
969
|
+
export function isActiveWarning() {
|
|
970
|
+
return editor?.isActive("WarningBlock");
|
|
971
|
+
}
|
|
972
|
+
export function isActiveInfo() {
|
|
973
|
+
return editor?.isActive("InfoBlock");
|
|
974
|
+
}
|
|
975
|
+
export function isActiveBulletList() {
|
|
976
|
+
return editor?.isActive("bulletList");
|
|
977
|
+
}
|
|
978
|
+
export function isActiveImage() {
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
export function isActiveTable() {
|
|
982
|
+
editor?.isActive("table");
|
|
983
|
+
}
|
|
984
|
+
export function isActiveHorizontalRule() {
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
export function preventBlur() {
|
|
988
|
+
if (editor.isFocused)
|
|
989
|
+
lockNextBlurCallbacks++;
|
|
990
|
+
}
|
|
991
|
+
const paletteMarksCommands = [
|
|
992
|
+
{ caption: "Bold", description: "Marks text as bolded", tags: "strong", icon: FaBold, on_choice: makeBold, is_active: () => editor?.isActive("bold") },
|
|
993
|
+
{ caption: "Italic", description: "Marks text as italic", tags: "strong", icon: FaItalic, on_choice: makeItalic, is_active: () => editor?.isActive("italic") },
|
|
994
|
+
{ caption: "Underlie", description: "Marks text as underlined", icon: FaUnderline, on_choice: makeUnderline, is_active: () => editor?.isActive("underline") },
|
|
995
|
+
{ caption: "Strikethrough", description: "Marks text as strikethrough", icon: FaStrikethrough, on_choice: makeStrikethrough, is_active: () => editor?.isActive("strike") }
|
|
996
|
+
];
|
|
997
|
+
const paletteStylesCommands = [
|
|
998
|
+
{ caption: "Normal", description: "This is normal text style", tags: "paragraph,text", icon: FaRemoveFormat, on_choice: (range) => {
|
|
708
999
|
if (range)
|
|
709
1000
|
editor.chain().focus().deleteRange(range).setParagraph().run();
|
|
710
1001
|
else
|
|
711
|
-
editor.
|
|
1002
|
+
editor.chain().focus().setParagraph().run();
|
|
712
1003
|
}, is_active: () => editor?.isActive("paragraph") },
|
|
713
1004
|
{ caption: "Heading 1", description: "Description heading", tags: "h1", icon: IcH1, on_choice: (range) => {
|
|
714
1005
|
if (range)
|
|
715
1006
|
editor.chain().focus().deleteRange(range).setHeading({ level: 1 }).run();
|
|
716
1007
|
else
|
|
717
|
-
editor.
|
|
1008
|
+
editor.chain().focus().setHeading({ level: 1 }).run();
|
|
718
1009
|
}, is_active: () => editor?.isActive("heading", { level: 1 }) },
|
|
719
1010
|
{ caption: "Heading 2", description: "Secondary heading", tags: "h2", icon: IcH2, on_choice: (range) => {
|
|
720
1011
|
if (range)
|
|
721
1012
|
editor.chain().focus().deleteRange(range).setHeading({ level: 2 }).run();
|
|
722
1013
|
else
|
|
723
|
-
editor.
|
|
1014
|
+
editor.chain().focus().setHeading({ level: 2 }).run();
|
|
724
1015
|
}, is_active: () => editor?.isActive("heading", { level: 2 }) },
|
|
725
1016
|
{ caption: "Heading 3", description: "Secondary heading", tags: "h3", icon: IcH3, on_choice: (range) => {
|
|
726
1017
|
if (range)
|
|
727
1018
|
editor.chain().focus().deleteRange(range).setHeading({ level: 3 }).run();
|
|
728
1019
|
else
|
|
729
|
-
editor.
|
|
1020
|
+
editor.chain().focus().setHeading({ level: 3 }).run();
|
|
730
1021
|
}, is_active: () => editor?.isActive("heading", { level: 3 }) },
|
|
731
1022
|
{ caption: "Heading 4", description: "Secondary heading", tags: "h4", icon: IcH4, on_choice: (range) => {
|
|
732
1023
|
if (range)
|
|
733
1024
|
editor.chain().focus().deleteRange(range).setHeading({ level: 4 }).run();
|
|
734
1025
|
else
|
|
735
|
-
editor.
|
|
1026
|
+
editor.chain().focus().setHeading({ level: 4 }).run();
|
|
736
1027
|
}, is_active: () => editor?.isActive("heading", { level: 4 }) },
|
|
737
1028
|
{ caption: "Code", description: "Source code monospace text", icon: FaCode, on_choice: (range) => {
|
|
738
1029
|
if (range)
|
|
739
1030
|
editor.chain().focus().deleteRange(range).setCodeBlock().run();
|
|
740
1031
|
else
|
|
741
|
-
editor.
|
|
1032
|
+
editor.chain().focus().setCodeBlock().run();
|
|
742
1033
|
}, is_active: () => editor?.isActive("CodeBlock") },
|
|
743
1034
|
{ caption: "Comment", description: "With this you can comment the above paragraph", icon: FaComment, on_choice: (range) => {
|
|
744
1035
|
if (range)
|
|
745
1036
|
editor.chain().focus().deleteRange(range).setAsComment().run();
|
|
746
1037
|
else
|
|
747
|
-
editor.
|
|
1038
|
+
editor.chain().focus().setAsComment().run();
|
|
748
1039
|
}, is_active: () => editor?.isActive("CommentBlock") },
|
|
749
1040
|
{ caption: "Quote", description: "To quote someone", icon: FaQuoteRight, on_choice: (range) => {
|
|
750
1041
|
if (range)
|
|
751
1042
|
editor.chain().focus().deleteRange(range).setAsQuote().run();
|
|
752
1043
|
else
|
|
753
|
-
editor.
|
|
1044
|
+
editor.chain().focus().setAsQuote().run();
|
|
754
1045
|
}, is_active: () => editor?.isActive("QuoteBlock") },
|
|
755
1046
|
{ caption: "Warning", description: "An important warning to above paragraph", icon: FaExclamationTriangle, on_choice: (range) => {
|
|
756
1047
|
if (range)
|
|
757
1048
|
editor.chain().focus().deleteRange(range).setAsWarning().run();
|
|
758
1049
|
else
|
|
759
|
-
editor.
|
|
1050
|
+
editor.chain().focus().setAsWarning().run();
|
|
760
1051
|
}, is_active: () => editor?.isActive("WarningBlock") },
|
|
761
1052
|
{ caption: "Info", description: "An important info about above paragraph", icon: FaInfo, on_choice: (range) => {
|
|
762
1053
|
if (range)
|
|
763
1054
|
editor.chain().focus().deleteRange(range).setAsInfo().run();
|
|
764
1055
|
else
|
|
765
|
-
editor.
|
|
1056
|
+
editor.chain().focus().setAsInfo().run();
|
|
766
1057
|
}, is_active: () => editor?.isActive("InfoBlock") },
|
|
767
1058
|
{ caption: "Bullet list", description: "Unordered list of items", icon: FaListUl, on_choice: (range) => {
|
|
768
1059
|
if (range)
|
|
769
1060
|
editor.chain().focus().deleteRange(range).toggleBulletList().run();
|
|
770
1061
|
else
|
|
771
|
-
editor.
|
|
772
|
-
}, is_active: () => editor?.isActive("bulletList") }
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
else
|
|
777
|
-
editor.commands.insertTable();
|
|
778
|
-
}, is_active: () => editor?.isActive("table") },
|
|
779
|
-
{ caption: "Format", separator: true },
|
|
780
|
-
{ caption: "Bold", description: "Marks text as bolded", tags: "strong", icon: FaBold, on_choice: makeBold, is_active: () => editor?.isActive("bold") },
|
|
781
|
-
{ caption: "Italic", description: "Marks text as italic", tags: "strong", icon: FaItalic, on_choice: makeItalic, is_active: () => editor?.isActive("italic") },
|
|
782
|
-
{ caption: "Underlie", description: "Marks text as underlined", icon: FaUnderline, on_choice: makeUnderline, is_active: () => editor?.isActive("underline") },
|
|
783
|
-
{ caption: "Strikethrough", description: "Marks text as strikethrough", icon: FaStrikethrough, on_choice: makeStrikethrough, is_active: () => editor?.isActive("strike") },
|
|
784
|
-
{ caption: "Other blocks", separator: true },
|
|
785
|
-
{ caption: "Image", description: "Add image to document", icon: FaImage, on_choice: (range) => {
|
|
1062
|
+
editor.chain().focus().toggleBulletList().run();
|
|
1063
|
+
}, is_active: () => editor?.isActive("bulletList") }
|
|
1064
|
+
];
|
|
1065
|
+
const paletteInsertCommands = [
|
|
1066
|
+
{ caption: "Image", description: "Add image to document", tags: "img,picture", icon: FaImage, on_choice: (range) => {
|
|
786
1067
|
if (range)
|
|
787
1068
|
editor.chain().focus().deleteRange(range).run();
|
|
788
1069
|
if (onAddImage)
|
|
789
1070
|
onAddImage(onAddedImageReady);
|
|
790
1071
|
} },
|
|
1072
|
+
{ caption: "Table", description: "Table", icon: FaTable, on_choice: (range) => {
|
|
1073
|
+
if (range)
|
|
1074
|
+
editor.chain().focus().deleteRange(range).insertTable().run();
|
|
1075
|
+
else
|
|
1076
|
+
editor.chain().focus().insertTable().run();
|
|
1077
|
+
}, is_active: () => editor?.isActive("table") },
|
|
791
1078
|
{ caption: "Horizontal rule", description: "Add horizonal role", tags: "hr", icon: FaGripLines, on_choice: (range) => {
|
|
792
1079
|
if (range)
|
|
793
1080
|
editor.chain().focus().deleteRange(range).setHorizontalRule().run();
|
|
794
1081
|
else
|
|
795
|
-
editor.
|
|
1082
|
+
editor.chain().focus().setHorizontalRule().run();
|
|
796
1083
|
} }
|
|
797
1084
|
];
|
|
1085
|
+
const paletteCommands = [
|
|
1086
|
+
{ caption: "Text", separator: true },
|
|
1087
|
+
...paletteMarksCommands,
|
|
1088
|
+
{ caption: "Styles", separator: true },
|
|
1089
|
+
...paletteStylesCommands,
|
|
1090
|
+
{ caption: "Insert", separator: true },
|
|
1091
|
+
...paletteInsertCommands
|
|
1092
|
+
];
|
|
798
1093
|
function makeBold(range) {
|
|
799
1094
|
if (range) {
|
|
800
1095
|
editor.chain().focus().deleteRange(range).toggleBold().run();
|
|
@@ -823,13 +1118,91 @@ function makeStrikethrough(range) {
|
|
|
823
1118
|
editor.chain().focus().toggleStrike().run();
|
|
824
1119
|
}
|
|
825
1120
|
}
|
|
1121
|
+
function getPaletteCommands() {
|
|
1122
|
+
let commands = [];
|
|
1123
|
+
if (extraFrontPaletteCommands && extraFrontPaletteCommands.length > 0) {
|
|
1124
|
+
extraFrontPaletteCommands.forEach((exc) => {
|
|
1125
|
+
commands.push({
|
|
1126
|
+
caption: exc.caption,
|
|
1127
|
+
description: exc.description,
|
|
1128
|
+
tags: exc.tags,
|
|
1129
|
+
icon: exc.icon,
|
|
1130
|
+
on_choice: (range) => {
|
|
1131
|
+
if (range)
|
|
1132
|
+
editor.chain().focus().deleteRange(range).run();
|
|
1133
|
+
if (exc.action)
|
|
1134
|
+
exc.action();
|
|
1135
|
+
},
|
|
1136
|
+
is_active: () => {
|
|
1137
|
+
if (exc.is_active)
|
|
1138
|
+
return exc.is_active();
|
|
1139
|
+
else
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
commands.push({ separator: true });
|
|
1145
|
+
}
|
|
1146
|
+
commands = [...commands, { caption: "Text", separator: true }];
|
|
1147
|
+
commands = [...commands, ...paletteMarksCommands];
|
|
1148
|
+
commands = [...commands, { caption: "Styles", separator: true }];
|
|
1149
|
+
commands = [...commands, ...paletteStylesCommands];
|
|
1150
|
+
commands = [...commands, { caption: "Insert", separator: true }];
|
|
1151
|
+
if (extraInsertPaletteCommands && extraInsertPaletteCommands.length > 0) {
|
|
1152
|
+
extraInsertPaletteCommands.forEach((exc) => {
|
|
1153
|
+
commands.push({
|
|
1154
|
+
caption: exc.caption,
|
|
1155
|
+
description: exc.description,
|
|
1156
|
+
tags: exc.tags,
|
|
1157
|
+
icon: exc.icon,
|
|
1158
|
+
on_choice: (range) => {
|
|
1159
|
+
if (range)
|
|
1160
|
+
editor.chain().focus().deleteRange(range).run();
|
|
1161
|
+
if (exc.action)
|
|
1162
|
+
exc.action();
|
|
1163
|
+
},
|
|
1164
|
+
is_active: () => {
|
|
1165
|
+
if (exc.is_active)
|
|
1166
|
+
return exc.is_active();
|
|
1167
|
+
else
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
commands = [...commands, ...paletteInsertCommands];
|
|
1174
|
+
if (extraBackPaletteCommands && extraBackPaletteCommands.length > 0) {
|
|
1175
|
+
commands.push({ separator: true });
|
|
1176
|
+
extraBackPaletteCommands.forEach((exc) => {
|
|
1177
|
+
commands.push({
|
|
1178
|
+
caption: exc.caption,
|
|
1179
|
+
description: exc.description,
|
|
1180
|
+
tags: exc.tags,
|
|
1181
|
+
icon: exc.icon,
|
|
1182
|
+
on_choice: (range) => {
|
|
1183
|
+
if (range)
|
|
1184
|
+
editor.chain().focus().deleteRange(range).run();
|
|
1185
|
+
if (exc.action)
|
|
1186
|
+
exc.action();
|
|
1187
|
+
},
|
|
1188
|
+
is_active: () => {
|
|
1189
|
+
if (exc.is_active)
|
|
1190
|
+
return exc.is_active();
|
|
1191
|
+
else
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
return commands;
|
|
1198
|
+
}
|
|
826
1199
|
</script>
|
|
827
1200
|
|
|
828
1201
|
|
|
829
1202
|
|
|
830
1203
|
<div bind:this={editorElement} />
|
|
831
1204
|
|
|
832
|
-
<Palette commands={
|
|
1205
|
+
<Palette commands={getPaletteCommands()}
|
|
833
1206
|
bind:this={palette}
|
|
834
1207
|
on:palette_shown={on_palette_shown}
|
|
835
1208
|
on:palette_hidden={on_palette_hidden}
|