@flexiui/svelte-rich-text 0.0.72 → 0.0.74

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.
@@ -21,10 +21,11 @@
21
21
  createEditor,
22
22
  Editor,
23
23
  // EditorContent,
24
- BubbleMenu,
24
+ // BubbleMenu,
25
25
  } from "svelte-tiptap";
26
26
 
27
27
  import EditorContent from "./svelte-tiptap-extends/EditorContent.svelte";
28
+ import BubbleMenu from "./svelte-tiptap-extends/BubbleMenu.svelte";
28
29
  import { getRichTextExtensions } from "./getExtensions";
29
30
  import { rgbToHex } from "./utils";
30
31
 
@@ -226,6 +227,8 @@
226
227
  editorConfig.toolbarJustifyContent = "flex-end";
227
228
  }
228
229
 
230
+ let focused = $state(false);
231
+
229
232
  let bubbleOffset =
230
233
  $editor?.storage.tableCell.customTableSelection === "column" ? 18 : 8;
231
234
 
@@ -570,9 +573,11 @@
570
573
  },
571
574
 
572
575
  onFocus({ editor, event }) {
576
+ focused = true;
573
577
  editorEvents.onFocus({ editor, event });
574
578
  },
575
579
  onBlur({ editor, event }) {
580
+ focused = false;
576
581
  editorEvents.onBlur({ editor, event });
577
582
  },
578
583
  onDestroy() {
@@ -1273,7 +1278,7 @@ function onOpenChangeHighlight(open: boolean) {
1273
1278
  {/if}
1274
1279
  </div>
1275
1280
 
1276
- {#if editor}
1281
+ {#if editor && focused}
1277
1282
  <div class="hidden">
1278
1283
  <BubbleMenu
1279
1284
  options={{
@@ -0,0 +1,56 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { BubbleMenuPlugin, type BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
4
+
5
+ import type { ComponentInputProps } from './types';
6
+ import { invariant } from './utils';
7
+
8
+ type Props = ComponentInputProps<BubbleMenuPluginProps>;
9
+
10
+ const {
11
+ editor,
12
+ options = {},
13
+ pluginKey = 'SvelteTiptapBubbleMenu',
14
+ shouldShow = null,
15
+ updateDelay = 250,
16
+ appendTo = null,
17
+ children,
18
+ class: className,
19
+ }: Props = $props();
20
+
21
+ invariant(editor, 'Missing editor instance.');
22
+
23
+ let element: HTMLElement;
24
+
25
+ onMount(() => {
26
+ element.style.visibility = 'hidden';
27
+ element.style.position = 'absolute';
28
+
29
+ const plugin = BubbleMenuPlugin({
30
+ pluginKey,
31
+ editor,
32
+ element,
33
+ options,
34
+ shouldShow,
35
+ updateDelay,
36
+ appendTo,
37
+ });
38
+
39
+ editor.registerPlugin(plugin);
40
+
41
+ return () => {
42
+ editor?.unregisterPlugin(pluginKey);
43
+ window.requestAnimationFrame(() => {
44
+ if (element && element.parentNode) {
45
+ element.parentNode.removeChild(element);
46
+ }
47
+ });
48
+ };
49
+ });
50
+ </script>
51
+
52
+ <div bind:this={element} class={className} style="visibility: hidden;">
53
+ {#if children}
54
+ {@render children()}
55
+ {/if}
56
+ </div>
@@ -0,0 +1,14 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {};
8
+ };
9
+ export type BubbleMenuProps = typeof __propDef.props;
10
+ export type BubbleMenuEvents = typeof __propDef.events;
11
+ export type BubbleMenuSlots = typeof __propDef.slots;
12
+ export default class BubbleMenu extends SvelteComponentTyped<BubbleMenuProps, BubbleMenuEvents, BubbleMenuSlots> {
13
+ }
14
+ export {};
@@ -0,0 +1,4 @@
1
+ type Invariant = (condition: unknown, message?: string) => asserts condition;
2
+ export declare const invariant: Invariant;
3
+ export declare const runIfFn: <T>(value: T | ((...args: unknown[]) => T), ...args: unknown[]) => T;
4
+ export {};
@@ -0,0 +1,8 @@
1
+ export const invariant = (condition, msg) => {
2
+ if (!condition) {
3
+ throw new Error(msg);
4
+ }
5
+ };
6
+ export const runIfFn = (value, ...args) => {
7
+ return typeof value === 'function' ? value(...args) : value;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",