@threadlabs/looma 0.6.2 → 0.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadlabs/looma",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "type": "module",
5
5
  "description": "Looma components as HTML, Vue, and plain DOM, with design tokens.",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, reactive, ref, useId, watch } from "vue";
2
2
  import { DEFAULT_MENTION_RESULT_LIMIT, LOOMA_ICONS, createLoomaMentionExtension, createLoomaSlashCommandExtension, getActiveTableUiState, getDefaultEditorExtensions, getVisualViewportRect, handleTableAction, handleTableOverlayAction, measureTableOverlayGeometry, normalizeActiveTableColumnWidths, resolveTableCellAt, shouldShowTextFormattingToolbar } from "@threadlabs/looma/editor";
3
- import { EditorInsertTableGrid, EditorMentionMenu, EditorSlashMenu, EditorTableContextMenu, EditorTableOverlay, EditorTableToolbar, EditorToolbar, IconButton, Popover } from "@threadlabs/looma/vue";
3
+ import { EditorInsertTableGrid, EditorMentionMenu, EditorSlashMenu, EditorTableContextMenu, EditorTableOverlay, EditorTableToolbar, EditorToolbar, IconButton, Popover, Tooltip } from "@threadlabs/looma/vue";
4
4
  import { BubbleMenu, EditorContent, useEditor } from "@tiptap/vue-3";
5
5
  import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
6
6
  import { Extension } from "@tiptap/core";
@@ -314,6 +314,32 @@ var LoomaEditor = defineComponent({
314
314
  const root = ref(null);
315
315
  const fileInput = ref(null);
316
316
  const tablePickerAnchorId = `looma-editor-table-picker-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
317
+ const toolbarScope = `looma-editor-tool-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
318
+ const tooltipFor = ref("");
319
+ const tooltipLabel = ref("");
320
+ const tooltipOpen = ref(false);
321
+ let tooltipTimer = 0;
322
+ const clearTooltipTimer = () => {
323
+ if (tooltipTimer) window.clearTimeout(tooltipTimer);
324
+ tooltipTimer = 0;
325
+ };
326
+ const showTool = (id, label, immediate) => {
327
+ clearTooltipTimer();
328
+ tooltipFor.value = id;
329
+ tooltipLabel.value = label;
330
+ if (immediate || tooltipOpen.value) {
331
+ tooltipOpen.value = true;
332
+ return;
333
+ }
334
+ tooltipTimer = window.setTimeout(() => {
335
+ tooltipOpen.value = true;
336
+ }, 400);
337
+ };
338
+ const hideTool = () => {
339
+ clearTooltipTimer();
340
+ tooltipOpen.value = false;
341
+ };
342
+ onBeforeUnmount(clearTooltipTimer);
317
343
  const tableToolbarShell = ref(null);
318
344
  const tableOverlayShell = ref(null);
319
345
  const tableMenuShell = ref(null);
@@ -788,11 +814,16 @@ var LoomaEditor = defineComponent({
788
814
  const button = vnode.el instanceof HTMLButtonElement ? vnode.el : vnode.el.querySelector("button");
789
815
  if (button) button.disabled = disabled;
790
816
  };
817
+ const id = `${toolbarScope}-${label.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
791
818
  return h(IconButton, {
819
+ id,
792
820
  class: "looma-editor__toolbar-button",
793
821
  label,
794
- title: label,
795
822
  size: "sm",
823
+ onPointerenter: () => showTool(id, label, false),
824
+ onPointerleave: hideTool,
825
+ onFocusin: () => showTool(id, label, true),
826
+ onFocusout: hideTool,
796
827
  variant: "ghost",
797
828
  disabled,
798
829
  "aria-pressed": active ? "true" : "false",
@@ -831,8 +862,11 @@ var LoomaEditor = defineComponent({
831
862
  id: tablePickerAnchorId,
832
863
  class: "looma-editor__toolbar-button",
833
864
  label: "Insert table",
834
- title: "Insert table",
835
865
  size: "sm",
866
+ onPointerenter: () => showTool(tablePickerAnchorId, "Insert table", false),
867
+ onPointerleave: hideTool,
868
+ onFocusin: () => showTool(tablePickerAnchorId, "Insert table", true),
869
+ onFocusout: hideTool,
836
870
  variant: tablePickerOpen.value ? "solid" : "ghost",
837
871
  "aria-expanded": tablePickerOpen.value ? "true" : "false",
838
872
  onClick: () => {
@@ -847,7 +881,13 @@ var LoomaEditor = defineComponent({
847
881
  commandButton("Undo", "undo", false, !instance.can().undo(), () => instance.chain().focus().undo().run()),
848
882
  commandButton("Redo", "redo", false, !instance.can().redo(), () => instance.chain().focus().redo().run())
849
883
  ];
850
- return h(EditorToolbar, { floating }, () => buttons);
884
+ return h(EditorToolbar, { floating }, () => [...buttons, h(Tooltip, {
885
+ class: "looma-editor__toolbar-tip",
886
+ for: tooltipFor.value,
887
+ open: tooltipOpen.value,
888
+ placement: floating ? "top" : "bottom",
889
+ trigger: "focus"
890
+ }, () => tooltipLabel.value)]);
851
891
  };
852
892
  const focus = (position = "start") => {
853
893
  editor.value?.commands.focus(position);