@flexiui/svelte-rich-text 0.0.78 → 0.0.80

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.
@@ -135,7 +135,7 @@
135
135
  };
136
136
 
137
137
  let {
138
- id = "fl-rich-text-editor",
138
+ id = `fl-r-text-${crypto.randomUUID().slice(0, 8)}`,
139
139
  className,
140
140
  editable,
141
141
  content,
@@ -237,6 +237,7 @@
237
237
  }
238
238
 
239
239
  let focused = $state(false);
240
+ let shouldClearSelectionOnFocus = false;
240
241
 
241
242
  let bubbleOffset =
242
243
  $editor?.storage.tableCell.customTableSelection === "column" ? 18 : 8;
@@ -593,29 +594,36 @@
593
594
  editorEvents.onSelectionUpdate({ editor });
594
595
  },
595
596
 
596
- onFocus({ editor, event }) {
597
+ onFocus({ editor }) {
597
598
  focused = true;
598
- editorEvents.onFocus({ editor, event });
599
+
600
+ editorEvents.onFocus({ editor });
599
601
  },
600
602
  onBlur({ editor, event }) {
601
603
  const relatedTarget = event.relatedTarget as HTMLElement;
602
604
 
603
- const isFontSizeEditor = relatedTarget && relatedTarget.closest(".fl-font-size-editor");
605
+ const isSameEditor = relatedTarget?.closest(`#${id}`); // usa el id del editor actual
604
606
 
605
- if((relatedTarget && relatedTarget.classList.contains("fl-bubble-menu-mark-button")) || isFontSizeEditor) {
607
+ const isBubbleMenu = relatedTarget?.closest(".fl-bubble-menu");
608
+ const isToolbarDropdown = relatedTarget?.closest(".fl-toolbar-dropdown-panel");
609
+ const isFontSizeEditor = relatedTarget?.closest(".fl-font-size-editor");
610
+
611
+ if (relatedTarget?.classList.contains("fl-bubble-menu-mark-button") || isFontSizeEditor) {
606
612
  return;
607
613
  }
608
614
 
609
- focused = false;
610
-
611
- const { state, view } = editor;
612
-
613
- const pos = state.selection.to;
614
-
615
- const tr = state.tr.setSelection(TextSelection.create(state.doc, pos));
615
+ // Solo saltar la limpieza si el foco va al MISMO editor
616
+ if (isSameEditor || isBubbleMenu || isToolbarDropdown) {
617
+ focused = false;
618
+ editorEvents.onBlur({ editor, event });
619
+ return;
620
+ }
616
621
 
617
- view.dispatch(tr);
622
+ // Foco fue fuera o a OTRO editor → limpiar
623
+ shouldClearSelectionOnFocus = true;
624
+ clearSelection(editor);
618
625
 
626
+ focused = false;
619
627
  editorEvents.onBlur({ editor, event });
620
628
  },
621
629
  onDestroy() {
@@ -813,6 +821,19 @@
813
821
  }
814
822
  }
815
823
  }
824
+
825
+
826
+ function clearSelection(editor) {
827
+ const { state, view } = editor;
828
+
829
+ const pos = state.selection.to;
830
+
831
+ const tr = state.tr.setSelection(
832
+ TextSelection.create(state.doc, pos)
833
+ );
834
+
835
+ view.dispatch(tr);
836
+ }
816
837
  </script>
817
838
 
818
839
  {#if cleanMode}
@@ -832,6 +853,7 @@
832
853
  {/if}
833
854
  {:else}
834
855
  <div
856
+ id={id}
835
857
  class="fl-rich-text {className}"
836
858
  class:editable
837
859
  style="
@@ -7,6 +7,7 @@
7
7
  </script>
8
8
 
9
9
  <button
10
+ class="fl-bubble-menu-mark-button"
10
11
  aria-label={ariaLabel}
11
12
  type="button"
12
13
  onclick={() => $editor.chain().focus().unsetAllMarks().run()}
@@ -7,6 +7,7 @@
7
7
  </script>
8
8
 
9
9
  <button
10
+ class="fl-bubble-menu-mark-button"
10
11
  type="button"
11
12
  onclick={() => $editor.chain().focus().clearNodes().run()}
12
13
  aria-label={ariaLabel}
@@ -4,7 +4,7 @@
4
4
  let {
5
5
  editor,
6
6
  accenSoft = false,
7
- ariaLabel = "Blockquote",
7
+ ariaLabel = "Font size",
8
8
  fontSize
9
9
  } = $props();
10
10
 
@@ -50,7 +50,7 @@
50
50
 
51
51
  </script>
52
52
 
53
- <div class="fl-font-size-editor">
53
+ <div class="fl-font-size-editor fl-bubble-menu-mark-button">
54
54
  <button
55
55
  type="button"
56
56
  aria-label="Decrease font size"
@@ -15,6 +15,7 @@
15
15
  <!-- Text align -->
16
16
  <button
17
17
  type="button"
18
+ class="fl-bubble-menu-mark-button"
18
19
  onclick={() => $editor.chain().focus().toggleTextAlign(position).run()}
19
20
  class:is-active={$editor.isActive({ textAlign: position })}
20
21
  class:accent-soft={accenSoft}
@@ -3,9 +3,10 @@
3
3
  </script>
4
4
 
5
5
  <button
6
+ class="fl-bubble-menu-mark-button"
6
7
  type="button"
7
8
  onclick={() => $editor.chain().focus().toggleBlockquote().run()}
8
- class={$editor.isActive("blockquote") ? "is-active" : ""}
9
+ class:is-active={$editor.isActive("blockquote")}
9
10
  aria-label={ariaLabel}
10
11
  class:accent-soft={accenSoft}
11
12
  >
@@ -4,9 +4,10 @@
4
4
 
5
5
  <!-- Code block -->
6
6
  <button
7
+ class="fl-bubble-menu-mark-button"
7
8
  type="button"
8
9
  onclick={() => $editor.chain().focus().toggleCodeBlock().run()}
9
- class={$editor.isActive("codeBlock") ? "is-active" : ""}
10
+ class:is-active={$editor.isActive("codeBlock")}
10
11
  aria-label={ariaLabel}
11
12
  class:accent-soft={accenSoft}
12
13
  >
@@ -4,6 +4,7 @@
4
4
 
5
5
  <!-- Horizontal rule -->
6
6
  <button
7
+ class="fl-bubble-menu-mark-button"
7
8
  type="button"
8
9
  onclick={() => $editor.chain().focus().setHorizontalRule().run()}
9
10
  aria-label={ariaLabel}
@@ -40,6 +40,7 @@
40
40
 
41
41
  <!-- Image -->
42
42
  <button
43
+ class="fl-bubble-menu-mark-button"
43
44
  type="button"
44
45
  onclick={addImage}
45
46
  aria-label={ariaLabel}
@@ -28,6 +28,7 @@
28
28
  </script>
29
29
 
30
30
  <button
31
+ class="fl-bubble-menu-mark-button"
31
32
  type="button"
32
33
  onclick={addInlineMath}
33
34
  aria-label={ariaLabel}
@@ -33,6 +33,7 @@
33
33
  </script>
34
34
 
35
35
  <button
36
+ class="fl-bubble-menu-mark-button"
36
37
  type="button"
37
38
  onclick={() => $editor.chain().focus().toggleList(type, itemType).run()}
38
39
  class:is-active={$editor.isActive(type)}
@@ -32,6 +32,7 @@
32
32
 
33
33
  <!-- Grid -->
34
34
  <button
35
+ class="fl-bubble-menu-mark-button"
35
36
  type="button"
36
37
  onclick={addMediaGrid}
37
38
  aria-label={ariaLabel}
@@ -36,6 +36,7 @@
36
36
 
37
37
  <!-- Table -->
38
38
  <button
39
+ class="fl-bubble-menu-mark-button"
39
40
  type="button"
40
41
  onclick={addTable}
41
42
  aria-label={ariaLabel}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",