@humandialog/forms.svelte 1.7.0 → 1.7.2

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.
@@ -26,6 +26,8 @@ import Underline from "@tiptap/extension-underline";
26
26
  import Dropcursor from "@tiptap/extension-dropcursor";
27
27
  import Gapcursor from "@tiptap/extension-gapcursor";
28
28
  import History from "@tiptap/extension-history";
29
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
30
+ import { getAttributes } from "@tiptap/core";
29
31
  import { data_tick_store, contextItemsStore, contextTypesStore, onErrorShowAlert, pushToolsActionsOperations, popToolsActionsOperations } from "../../stores.js";
30
32
  import { informModification, pushChanges } from "../../updates.js";
31
33
  import { isDeviceSmallerThan, parseWidthDirective, refreshToolbarOperations, UI } from "../../utils.js";
@@ -69,6 +71,7 @@ export let onFocusCb = void 0;
69
71
  export let onBlurCb = void 0;
70
72
  export let onAddImage = void 0;
71
73
  export let onRemoveImage = void 0;
74
+ export let onLinkClick = void 0;
72
75
  export let c = "";
73
76
  export let pushChangesImmediately = true;
74
77
  export let chat = void 0;
@@ -555,6 +558,45 @@ const additionalShortcuts = Extension.create({
555
558
  };
556
559
  }
557
560
  });
561
+ export const CustomLink = Link.extend({
562
+ addOptions() {
563
+ return {
564
+ ...this.parent?.(),
565
+ openOnClick: false
566
+ //showMap: () => {},
567
+ //setMapQuery: () => {},
568
+ };
569
+ },
570
+ addProseMirrorPlugins() {
571
+ const plugins = this.parent?.() || [];
572
+ const extensionOptions = this.options;
573
+ const clickHandler = new Plugin({
574
+ key: new PluginKey("handleControlClick"),
575
+ props: {
576
+ handleClick(view, pos, event) {
577
+ if (event.button !== 0) {
578
+ return false;
579
+ }
580
+ if (!view.editable) {
581
+ return false;
582
+ }
583
+ const attrs = getAttributes(view.state, "link");
584
+ const link = event.target?.closest("a");
585
+ if (link && attrs.href) {
586
+ event.preventDefault();
587
+ event.stopPropagation();
588
+ if (onLinkClick)
589
+ onLinkClick(attrs.href, attrs.target);
590
+ return true;
591
+ }
592
+ return false;
593
+ }
594
+ }
595
+ });
596
+ plugins.push(clickHandler);
597
+ return plugins;
598
+ }
599
+ });
558
600
  onMount(() => {
559
601
  editor = new Editor({
560
602
  editable: !readOnly,
@@ -598,7 +640,11 @@ onMount(() => {
598
640
  Italic,
599
641
  Strike,
600
642
  Underline,
601
- Link,
643
+ ...onLinkClick ? [
644
+ CustomLink.configure({
645
+ //showMap: () => { showMap(true); },
646
+ })
647
+ ] : [Link],
602
648
  Dropcursor,
603
649
  Gapcursor,
604
650
  History,
@@ -834,6 +880,9 @@ export function removeTemporaryImage(temporarySrc) {
834
880
  return;
835
881
  editor.commands.deleteRange(image.range);
836
882
  }
883
+ export function addLink(title, href) {
884
+ editor.chain().setLink({ href }).insertContent(title).unsetMark("link").insertContent(" ").focus().run();
885
+ }
837
886
  export function getInnerHtml() {
838
887
  return editor.getHTML();
839
888
  }
@@ -1014,50 +1063,50 @@ export function hasChanged() {
1014
1063
  return hasChangedValue;
1015
1064
  }
1016
1065
  const paletteMarksCommands = () => [
1017
- { caption: i18n({ en: "Bold", es: "Negrita", pl: "Pogrubiony" }), description: "Marks text as bolded", tags: "strong", icon: FaBold, on_choice: makeBold, is_active: () => editor?.isActive("bold") },
1018
- { caption: i18n({ en: "Italic", es: "Cursiva", pl: "Kursywa" }), description: "Marks text as italic", tags: "strong", icon: FaItalic, on_choice: makeItalic, is_active: () => editor?.isActive("italic") },
1019
- { caption: i18n({ en: "Underline", es: "Subrayar", pl: "Podkre\u015Blenie" }), description: "Marks text as underlined", icon: FaUnderline, on_choice: makeUnderline, is_active: () => editor?.isActive("underline") },
1020
- { caption: i18n({ en: "Strikethrough", es: "Tachado", pl: "Przekre\u015Blenie" }), description: "Marks text as strikethrough", icon: FaStrikethrough, on_choice: makeStrikethrough, is_active: () => editor?.isActive("strike") }
1066
+ { caption: i18n({ en: "Bold", es: "Negrita", pl: "Pogrubiony" }), description: "Marks text as bolded", tags: "strong,bold", icon: FaBold, on_choice: makeBold, is_active: () => editor?.isActive("bold") },
1067
+ { caption: i18n({ en: "Italic", es: "Cursiva", pl: "Kursywa" }), description: "Marks text as italic", tags: "italic,em", icon: FaItalic, on_choice: makeItalic, is_active: () => editor?.isActive("italic") },
1068
+ { caption: i18n({ en: "Underline", es: "Subrayar", pl: "Podkre\u015Blenie" }), description: "Marks text as underlined", tags: "under", icon: FaUnderline, on_choice: makeUnderline, is_active: () => editor?.isActive("underline") },
1069
+ { caption: i18n({ en: "Strikethrough", es: "Tachado", pl: "Przekre\u015Blenie" }), description: "Marks text as strikethrough", tags: "strike", icon: FaStrikethrough, on_choice: makeStrikethrough, is_active: () => editor?.isActive("strike") }
1021
1070
  ];
1022
1071
  const paletteStylesCommands = () => [
1023
- { caption: i18n({ en: "Normal", es: "Normal", pl: "Normalny" }), description: "This is normal text style", tags: "paragraph,text", icon: FaRemoveFormat, on_choice: (range) => {
1024
- if (range)
1025
- editor.chain().focus().deleteRange(range).setParagraph().run();
1026
- else
1027
- editor.chain().focus().setParagraph().run();
1028
- }, is_active: () => editor?.isActive("paragraph") },
1029
- { caption: i18n({ en: "Heading 1", es: "T\xEDtulo 1", pl: "Nag\u0142\xF3wek 1" }), description: "Description heading", tags: "h1", icon: IcH1, on_choice: (range) => {
1072
+ { caption: i18n({ en: "Heading 1", es: "T\xEDtulo 1", pl: "Nag\u0142\xF3wek 1" }), description: "Description heading", tags: "h1,head", icon: IcH1, on_choice: (range) => {
1030
1073
  if (range)
1031
1074
  editor.chain().focus().deleteRange(range).setHeading({ level: 1 }).run();
1032
1075
  else
1033
1076
  editor.chain().focus().setHeading({ level: 1 }).run();
1034
1077
  }, is_active: () => editor?.isActive("heading", { level: 1 }) },
1035
- { caption: i18n({ en: "Heading 2", es: "T\xEDtulo 2", pl: "Nag\u0142\xF3wek 2" }), description: "Secondary heading", tags: "h2", icon: IcH2, on_choice: (range) => {
1078
+ { caption: i18n({ en: "Heading 2", es: "T\xEDtulo 2", pl: "Nag\u0142\xF3wek 2" }), description: "Secondary heading", tags: "h2,head", icon: IcH2, on_choice: (range) => {
1036
1079
  if (range)
1037
1080
  editor.chain().focus().deleteRange(range).setHeading({ level: 2 }).run();
1038
1081
  else
1039
1082
  editor.chain().focus().setHeading({ level: 2 }).run();
1040
1083
  }, is_active: () => editor?.isActive("heading", { level: 2 }) },
1041
- { caption: i18n({ en: "Heading 3", es: "T\xEDtulo 3", pl: "Nag\u0142\xF3wek 3" }), description: "Secondary heading", tags: "h3", icon: IcH3, on_choice: (range) => {
1084
+ { caption: i18n({ en: "Heading 3", es: "T\xEDtulo 3", pl: "Nag\u0142\xF3wek 3" }), description: "Secondary heading", tags: "h3,head", icon: IcH3, on_choice: (range) => {
1042
1085
  if (range)
1043
1086
  editor.chain().focus().deleteRange(range).setHeading({ level: 3 }).run();
1044
1087
  else
1045
1088
  editor.chain().focus().setHeading({ level: 3 }).run();
1046
1089
  }, is_active: () => editor?.isActive("heading", { level: 3 }) },
1047
- { caption: i18n({ en: "Heading 4", es: "T\xEDtulo 4", pl: "Nag\u0142\xF3wek 4" }), description: "Secondary heading", tags: "h4", icon: IcH4, on_choice: (range) => {
1090
+ { caption: i18n({ en: "Heading 4", es: "T\xEDtulo 4", pl: "Nag\u0142\xF3wek 4" }), description: "Secondary heading", tags: "h4,head", icon: IcH4, on_choice: (range) => {
1048
1091
  if (range)
1049
1092
  editor.chain().focus().deleteRange(range).setHeading({ level: 4 }).run();
1050
1093
  else
1051
1094
  editor.chain().focus().setHeading({ level: 4 }).run();
1052
1095
  }, is_active: () => editor?.isActive("heading", { level: 4 }) },
1053
- { caption: i18n({ en: "Code", es: "C\xF3digo", pl: "Kod" }), description: "Source code monospace text", icon: FaCode, on_choice: (range) => {
1096
+ { caption: i18n({ en: "Normal", es: "Normal", pl: "Normalny" }), description: "This is normal text style", tags: "paragraph,text,normal", icon: FaRemoveFormat, on_choice: (range) => {
1097
+ if (range)
1098
+ editor.chain().focus().deleteRange(range).setParagraph().run();
1099
+ else
1100
+ editor.chain().focus().setParagraph().run();
1101
+ }, is_active: () => editor?.isActive("paragraph") },
1102
+ { caption: i18n({ en: "Code", es: "C\xF3digo", pl: "Kod" }), description: "Source code monospace text", tags: "code", icon: FaCode, on_choice: (range) => {
1054
1103
  if (range)
1055
1104
  editor.chain().focus().deleteRange(range).setCodeBlock().run();
1056
1105
  else
1057
1106
  editor.chain().focus().setCodeBlock().run();
1058
1107
  }, is_active: () => editor?.isActive("CodeBlock") },
1059
1108
  // { caption: 'Comment', description: 'With this you can comment the above paragraph', icon: FaComment, on_choice: (range) => { if(range) editor.chain().focus().deleteRange(range).setAsComment().run(); else editor.chain().focus().setAsComment().run() }, is_active: () => editor?.isActive('CommentBlock') } ,
1060
- { caption: i18n({ en: "Quote", es: "Cita", pl: "Cytat" }), description: "To quote someone", icon: FaQuoteRight, on_choice: (range) => {
1109
+ { caption: i18n({ en: "Quote", es: "Cita", pl: "Cytat" }), description: "To quote someone", tags: "quote", icon: FaQuoteRight, on_choice: (range) => {
1061
1110
  if (range)
1062
1111
  editor.chain().focus().deleteRange(range).setAsQuote().run();
1063
1112
  else
@@ -1065,7 +1114,7 @@ const paletteStylesCommands = () => [
1065
1114
  }, is_active: () => editor?.isActive("QuoteBlock") },
1066
1115
  // { caption: 'Warning', description: 'An important warning to above paragraph', icon: FaExclamationTriangle, on_choice: (range) => { if(range) editor.chain().focus().deleteRange(range).setAsWarning().run(); else editor.chain().focus().setAsWarning().run() }, is_active: () => editor?.isActive('WarningBlock') } ,
1067
1116
  // { caption: 'Info', description: 'An important info about above paragraph', icon: FaInfo, on_choice: (range) => { if(range) editor.chain().focus().deleteRange(range).setAsInfo().run(); else editor.chain().focus().setAsInfo().run() }, is_active: () => editor?.isActive('InfoBlock') },
1068
- { caption: i18n({ en: "BulletList", es: "Lista con vi\xF1etas", pl: "Lista punktowana" }), description: "Unordered list of items", icon: FaListUl, on_choice: (range) => {
1117
+ { caption: i18n({ en: "BulletList", es: "Lista con vi\xF1etas", pl: "Lista punktowana" }), description: "Unordered list of items", tags: "bullet", icon: FaListUl, on_choice: (range) => {
1069
1118
  if (range)
1070
1119
  editor.chain().focus().deleteRange(range).toggleBulletList().run();
1071
1120
  else
@@ -1079,13 +1128,13 @@ const paletteInsertCommands = () => [
1079
1128
  if (onAddImage)
1080
1129
  onAddImage(onAddedImageReady);
1081
1130
  } },
1082
- { caption: i18n({ en: "Table", es: "Tabla", pl: "Tabela" }), description: "Table", icon: FaTable, on_choice: (range) => {
1131
+ { caption: i18n({ en: "Table", es: "Tabla", pl: "Tabela" }), description: "Table", tags: "table", icon: FaTable, on_choice: (range) => {
1083
1132
  if (range)
1084
1133
  editor.chain().focus().deleteRange(range).insertTable().run();
1085
1134
  else
1086
1135
  editor.chain().focus().insertTable().run();
1087
1136
  }, is_active: () => editor?.isActive("table") },
1088
- { caption: i18n({ en: "Horizontal rule", es: "Regla horizontal", pl: "Pozioma linia" }), description: "Add horizonal role", tags: "hr", icon: FaGripLines, on_choice: (range) => {
1137
+ { caption: i18n({ en: "Horizontal rule", es: "Regla horizontal", pl: "Pozioma linia" }), description: "Add horizonal role", tags: "hr,line", icon: FaGripLines, on_choice: (range) => {
1089
1138
  if (range)
1090
1139
  editor.chain().focus().deleteRange(range).setHorizontalRule().run();
1091
1140
  else
@@ -15,6 +15,7 @@ declare const __propDef: {
15
15
  onBlurCb?: undefined;
16
16
  onAddImage?: undefined;
17
17
  onRemoveImage?: undefined;
18
+ onLinkClick?: Function | undefined;
18
19
  c?: string | undefined;
19
20
  pushChangesImmediately?: boolean | undefined;
20
21
  chat?: object | undefined;
@@ -43,10 +44,12 @@ declare const __propDef: {
43
44
  tbr: string;
44
45
  }) | undefined;
45
46
  scrollIntoView?: ((param: any) => void) | undefined;
47
+ CustomLink?: import("@tiptap/core").Mark<{}, any> | undefined;
46
48
  save?: (() => Promise<void>) | undefined;
47
49
  addTemporaryImage?: ((src: any) => void) | undefined;
48
50
  replaceTemporaryImage?: ((temporarySrc: any, dataPath: any) => void) | undefined;
49
51
  removeTemporaryImage?: ((temporarySrc: any) => void) | undefined;
52
+ addLink?: ((title: any, href: any) => void) | undefined;
50
53
  getInnerHtml?: (() => any) | undefined;
51
54
  setInnerHtml?: ((content: any) => void) | undefined;
52
55
  setBold?: (() => void) | undefined;
@@ -116,10 +119,12 @@ export default class Editor extends SvelteComponentTyped<EditorProps, EditorEven
116
119
  tbr: string;
117
120
  };
118
121
  get scrollIntoView(): (param: any) => void;
122
+ get CustomLink(): import("@tiptap/core").Mark<{}, any>;
119
123
  get save(): () => Promise<void>;
120
124
  get addTemporaryImage(): (src: any) => void;
121
125
  get replaceTemporaryImage(): (temporarySrc: any, dataPath: any) => void;
122
126
  get removeTemporaryImage(): (temporarySrc: any) => void;
127
+ get addLink(): (title: any, href: any) => void;
123
128
  get getInnerHtml(): () => any;
124
129
  get setInnerHtml(): (content: any) => void;
125
130
  get setBold(): () => void;
@@ -57,10 +57,12 @@ export function show(x, y, up = false) {
57
57
  visible = true;
58
58
  dispatch("palette_shown");
59
59
  closeButtonPos = "";
60
- setTimeout(() => {
61
- const rect = paletteElement.getBoundingClientRect();
62
- closeButtonPos = `right: ${15}px; top: calc(${rect.y}px - 1.75rem)`;
63
- }, 0);
60
+ if (isDeviceSmallerThan("sm")) {
61
+ setTimeout(() => {
62
+ const rect = paletteElement.getBoundingClientRect();
63
+ closeButtonPos = `right: ${15}px; top: calc(${rect.y}px - 1.75rem)`;
64
+ }, 0);
65
+ }
64
66
  }
65
67
  export function show_fullscreen(_width_px, _height_px) {
66
68
  isToolbox = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "type": "module",
29
29
  "dependencies": {
30
- "@humandialog/auth.svelte": "^1.8.16",
30
+ "@humandialog/auth.svelte": "^1.8.17",
31
31
  "@tiptap/core": "^2.11.0",
32
32
  "@tiptap/extension-bullet-list": "^2.11.5",
33
33
  "@tiptap/extension-code-block": "^2.11.5",