@milkdown/plugin-tooltip 7.3.6 → 7.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA"}
package/lib/index.es.js CHANGED
@@ -1,87 +1,93 @@
1
- var $ = (e, o, t) => {
2
- if (!o.has(e))
3
- throw TypeError("Cannot " + t);
1
+ var w = (o, t, e) => {
2
+ if (!t.has(o))
3
+ throw TypeError("Cannot " + e);
4
4
  };
5
- var n = (e, o, t) => ($(e, o, "read from private field"), t ? t.call(e) : o.get(e)), c = (e, o, t) => {
6
- if (o.has(e))
5
+ var n = (o, t, e) => (w(o, t, "read from private field"), e ? e.call(o) : t.get(o)), l = (o, t, e) => {
6
+ if (t.has(o))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
- o instanceof WeakSet ? o.add(e) : o.set(e, t);
9
- }, l = (e, o, t, s) => ($(e, o, "write to private field"), s ? s.call(e, t) : o.set(e, t), t);
10
- var x = (e, o, t) => ($(e, o, "access private method"), t);
11
- import { posToDOMRect as S } from "@milkdown/prose";
12
- import { TextSelection as b, Plugin as C, PluginKey as R } from "@milkdown/prose/state";
13
- import _ from "lodash.debounce";
14
- import E from "tippy.js";
15
- import { $ctx as F, $prose as I } from "@milkdown/utils";
16
- var i, h, a, m, u, f, O;
17
- class D {
18
- constructor(o) {
8
+ t instanceof WeakSet ? t.add(o) : t.set(o, e);
9
+ }, c = (o, t, e, s) => (w(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
10
+ var T = (o, t, e) => (w(o, t, "access private method"), e);
11
+ import { TextSelection as B, Plugin as F, PluginKey as H } from "@milkdown/prose/state";
12
+ import M from "lodash.debounce";
13
+ import { computePosition as O, flip as S, offset as b } from "@floating-ui/dom";
14
+ import { posToDOMRect as R } from "@milkdown/prose";
15
+ import { $ctx as j, $prose as q } from "@milkdown/utils";
16
+ var r, d, h, a, u, y, C;
17
+ class A {
18
+ constructor(t) {
19
19
  /// @internal
20
- c(this, f);
20
+ l(this, y);
21
21
  /// @internal
22
- c(this, i, void 0);
22
+ l(this, r, void 0);
23
23
  /// @internal
24
- c(this, h, void 0);
24
+ l(this, d, void 0);
25
+ l(this, h, void 0);
25
26
  /// @internal
26
- c(this, a, void 0);
27
- /// @internal
28
- c(this, m, void 0);
29
- c(this, u, void 0);
30
- l(this, u, (t, s) => {
31
- const { state: r, composing: p } = t, { selection: d, doc: g } = r, { ranges: y } = d, k = Math.min(...y.map((T) => T.$from.pos)), P = Math.max(...y.map((T) => T.$to.pos)), w = s && s.doc.eq(g) && s.selection.eq(d);
32
- if (n(this, i) ?? l(this, i, E(t.dom, {
33
- trigger: "manual",
34
- interactive: !0,
35
- delay: 0,
36
- arrow: !1,
37
- duration: 0,
38
- ...n(this, h),
39
- content: this.element
40
- })), !(p || w)) {
41
- if (!n(this, m).call(this, t, s)) {
42
- this.hide();
43
- return;
44
- }
45
- n(this, i).setProps({
46
- getReferenceClientRect: () => S(t, k, P)
47
- }), this.show();
27
+ l(this, a, void 0);
28
+ l(this, u, void 0);
29
+ c(this, h, !1), this.onShow = () => {
30
+ }, this.onHide = () => {
31
+ }, c(this, u, (e, s) => {
32
+ var P;
33
+ const { state: i, composing: p } = e, { selection: f, doc: $ } = i, { ranges: g } = f, x = Math.min(...g.map((m) => m.$from.pos)), k = Math.max(...g.map((m) => m.$to.pos)), E = s && s.doc.eq($) && s.selection.eq(f);
34
+ if (n(this, h) || ((P = e.dom.parentElement) == null || P.appendChild(this.element), c(this, h, !0)), p || E)
35
+ return;
36
+ if (!n(this, d).call(this, e, s)) {
37
+ this.hide();
38
+ return;
48
39
  }
49
- }), this.update = (t, s) => {
50
- _(n(this, u), n(this, a))(t, s);
40
+ O({
41
+ getBoundingClientRect: () => R(e, x, k)
42
+ }, this.element, {
43
+ placement: "top",
44
+ middleware: [S(), b(n(this, a))]
45
+ }).then(({ x: m, y: _ }) => {
46
+ Object.assign(this.element.style, {
47
+ left: `${m}px`,
48
+ top: `${_}px`
49
+ });
50
+ }), this.show();
51
+ }), this.update = (e, s) => {
52
+ M(n(this, u), n(this, r))(e, s);
51
53
  }, this.destroy = () => {
52
- var t;
53
- (t = n(this, i)) == null || t.destroy();
54
- }, this.show = () => {
55
- var t;
56
- (t = n(this, i)) == null || t.show();
54
+ }, this.show = (e) => {
55
+ this.element.dataset.show = "true", e && O(e, this.element, {
56
+ placement: "top",
57
+ middleware: [S(), b(n(this, a))]
58
+ }).then(({ x: s, y: i }) => {
59
+ Object.assign(this.element.style, {
60
+ left: `${s}px`,
61
+ top: `${i}px`
62
+ });
63
+ }), this.onShow();
57
64
  }, this.hide = () => {
58
- var t;
59
- (t = n(this, i)) == null || t.hide();
60
- }, this.getInstance = () => n(this, i), this.element = o.content, l(this, h, o.tippyOptions ?? {}), l(this, a, o.debounce ?? 200), l(this, m, o.shouldShow ?? x(this, f, O));
65
+ this.element.dataset.show = "false", this.onHide();
66
+ }, this.element = t.content, c(this, r, t.debounce ?? 200), c(this, d, t.shouldShow ?? T(this, y, C)), c(this, a, t.offset);
61
67
  }
62
68
  }
63
- i = new WeakMap(), h = new WeakMap(), a = new WeakMap(), m = new WeakMap(), u = new WeakMap(), f = new WeakSet(), O = function(o) {
64
- const { doc: t, selection: s } = o.state, { empty: r, from: p, to: d } = s, g = !t.textBetween(p, d).length && o.state.selection instanceof b, y = this.element.contains(document.activeElement), k = !o.hasFocus() && !y, P = !o.editable;
65
- return !(k || r || g || P);
69
+ r = new WeakMap(), d = new WeakMap(), h = new WeakMap(), a = new WeakMap(), u = new WeakMap(), y = new WeakSet(), C = function(t) {
70
+ const { doc: e, selection: s } = t.state, { empty: i, from: p, to: f } = s, $ = !e.textBetween(p, f).length && t.state.selection instanceof B, g = this.element.contains(document.activeElement), x = !t.hasFocus() && !g, k = !t.editable;
71
+ return !(x || i || $ || k);
66
72
  };
67
- function H(e) {
68
- const o = F({}, `${e}_TOOLTIP_SPEC`), t = I((r) => {
69
- const p = r.get(o.key);
70
- return new C({
71
- key: new R(`${e}_TOOLTIP`),
73
+ function G(o) {
74
+ const t = j({}, `${o}_TOOLTIP_SPEC`), e = q((i) => {
75
+ const p = i.get(t.key);
76
+ return new F({
77
+ key: new H(`${o}_TOOLTIP`),
72
78
  ...p
73
79
  });
74
- }), s = [o, t];
75
- return s.key = o.key, s.pluginKey = t.key, o.meta = {
80
+ }), s = [t, e];
81
+ return s.key = t.key, s.pluginKey = e.key, t.meta = {
76
82
  package: "@milkdown/plugin-tooltip",
77
- displayName: `Ctx<tooltipSpec>|${e}`
78
- }, t.meta = {
83
+ displayName: `Ctx<tooltipSpec>|${o}`
84
+ }, e.meta = {
79
85
  package: "@milkdown/plugin-tooltip",
80
- displayName: `Prose<tooltip>|${e}`
86
+ displayName: `Prose<tooltip>|${o}`
81
87
  }, s;
82
88
  }
83
89
  export {
84
- D as TooltipProvider,
85
- H as tooltipFactory
90
+ A as TooltipProvider,
91
+ G as tooltipFactory
86
92
  };
87
93
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/tooltip-provider.ts","../src/tooltip-plugin.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { posToDOMRect } from '@milkdown/prose'\nimport type { EditorState } from '@milkdown/prose/state'\nimport { TextSelection } from '@milkdown/prose/state'\nimport type { EditorView } from '@milkdown/prose/view'\nimport debounce from 'lodash.debounce'\nimport type { Instance, Props } from 'tippy.js'\nimport tippy from 'tippy.js'\n\n/// Options for tooltip provider.\nexport interface TooltipProviderOptions {\n /// The tooltip content.\n content: HTMLElement\n /// The options for creating [tippy.js](https://atomiks.github.io/tippyjs/) instance.\n tippyOptions?: Partial<Props>\n /// The debounce time for updating tooltip, 200ms by default.\n debounce?: number\n /// The function to determine whether the tooltip should be shown.\n shouldShow?: (view: EditorView, prevState?: EditorState) => boolean\n}\n\n/// A provider for creating tooltip.\nexport class TooltipProvider {\n /// @internal\n #tippy: Instance | undefined\n\n /// @internal\n #tippyOptions: Partial<Props>\n\n /// @internal\n #debounce: number\n\n /// @internal\n #shouldShow: (view: EditorView, prevState?: EditorState) => boolean\n\n /// The root element of the tooltip.\n element: HTMLElement\n\n constructor(options: TooltipProviderOptions) {\n this.element = options.content\n this.#tippyOptions = options.tippyOptions ?? {}\n this.#debounce = options.debounce ?? 200\n this.#shouldShow = options.shouldShow ?? this.#_shouldShow\n }\n\n /// @internal\n #onUpdate = (view: EditorView, prevState?: EditorState): void => {\n const { state, composing } = view\n const { selection, doc } = state\n const { ranges } = selection\n const from = Math.min(...ranges.map(range => range.$from.pos))\n const to = Math.max(...ranges.map(range => range.$to.pos))\n const isSame = prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection)\n\n this.#tippy ??= tippy(view.dom, {\n trigger: 'manual',\n interactive: true,\n delay: 0,\n arrow: false,\n duration: 0,\n ...this.#tippyOptions,\n content: this.element,\n })\n\n if (composing || isSame)\n return\n\n if (!this.#shouldShow(view, prevState)) {\n this.hide()\n return\n }\n\n this.#tippy.setProps({\n getReferenceClientRect: () => posToDOMRect(view, from, to),\n })\n\n this.show()\n }\n\n /// Update provider state by editor view.\n update = (view: EditorView, prevState?: EditorState): void => {\n const updater = debounce(this.#onUpdate, this.#debounce)\n\n updater(view, prevState)\n }\n\n /// @internal\n #_shouldShow(view: EditorView): boolean {\n const { doc, selection } = view.state\n const { empty, from, to } = selection\n\n const isEmptyTextBlock = !doc.textBetween(from, to).length && view.state.selection instanceof TextSelection\n\n const isTooltipChildren = this.element.contains(document.activeElement)\n\n const notHasFocus = !view.hasFocus() && !isTooltipChildren\n\n const isReadonly = !view.editable\n\n if (\n notHasFocus\n || empty\n || isEmptyTextBlock\n || isReadonly\n )\n return false\n\n return true\n }\n\n /// Destroy the tooltip.\n destroy = () => {\n this.#tippy?.destroy()\n }\n\n /// Show the tooltip.\n show = () => {\n this.#tippy?.show()\n }\n\n /// Hide the tooltip.\n hide = () => {\n this.#tippy?.hide()\n }\n\n /// Get the [tippy.js](https://atomiks.github.io/tippyjs/) instance.\n getInstance = () => {\n return this.#tippy\n }\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { SliceType } from '@milkdown/ctx'\nimport type { PluginSpec } from '@milkdown/prose/state'\nimport { Plugin, PluginKey } from '@milkdown/prose/state'\nimport type { $Ctx, $Prose } from '@milkdown/utils'\nimport { $ctx, $prose } from '@milkdown/utils'\n\n/// @internal\nexport type TooltipSpecId<Id extends string> = `${Id}_TOOLTIP_SPEC`\n\n/// @internal\nexport type TooltipPlugin<Id extends string, State = any> = [$Ctx<PluginSpec<State>, TooltipSpecId<Id>>, $Prose] & {\n key: SliceType<PluginSpec<State>, TooltipSpecId<Id>>\n pluginKey: $Prose['key']\n}\n\n/// Create a tooltip plugin with a unique id.\nexport function tooltipFactory<Id extends string, State = any>(id: Id) {\n const tooltipSpec = $ctx<PluginSpec<State>, TooltipSpecId<Id>>({}, `${id}_TOOLTIP_SPEC`)\n const tooltipPlugin = $prose((ctx) => {\n const spec = ctx.get(tooltipSpec.key)\n return new Plugin({\n key: new PluginKey(`${id}_TOOLTIP`),\n ...spec,\n })\n })\n const result = [tooltipSpec, tooltipPlugin] as TooltipPlugin<Id>\n result.key = tooltipSpec.key\n result.pluginKey = tooltipPlugin.key\n tooltipSpec.meta = {\n package: '@milkdown/plugin-tooltip',\n displayName: `Ctx<tooltipSpec>|${id}`,\n }\n tooltipPlugin.meta = {\n package: '@milkdown/plugin-tooltip',\n displayName: `Prose<tooltip>|${id}`,\n }\n\n return result\n}\n"],"names":["TooltipProvider","options","__privateAdd","__shouldShow","_tippy","_tippyOptions","_debounce","_shouldShow","_onUpdate","__privateSet","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","tippy","posToDOMRect","debounce","_a","__privateMethod","_shouldShow_fn","empty","isEmptyTextBlock","TextSelection","isTooltipChildren","notHasFocus","isReadonly","tooltipFactory","id","tooltipSpec","$ctx","tooltipPlugin","$prose","ctx","spec","Plugin","PluginKey","result"],"mappings":";;;;;;;;;;;;;;;;AAsBO,MAAMA,EAAgB;AAAA,EAgB3B,YAAYC,GAAiC;AAiD7C;AAAA,IAAAC,EAAA,MAAAC;AA/DA;AAAA,IAAAD,EAAA,MAAAE,GAAA;AAGA;AAAA,IAAAF,EAAA,MAAAG,GAAA;AAGA;AAAA,IAAAH,EAAA,MAAAI,GAAA;AAGA;AAAA,IAAAJ,EAAA,MAAAK,GAAA;AAaA,IAAAL,EAAA,MAAAM,GAAA;AAAY,IAAAC,EAAA,MAAAD,GAAA,CAACE,GAAkBC,MAAkC;AACzD,YAAA,EAAE,OAAAC,GAAO,WAAAC,EAAc,IAAAH,GACvB,EAAE,WAAAI,GAAW,KAAAC,EAAQ,IAAAH,GACrB,EAAE,QAAAI,EAAW,IAAAF,GACbG,IAAO,KAAK,IAAI,GAAGD,EAAO,IAAI,CAASE,MAAAA,EAAM,MAAM,GAAG,CAAC,GACvDC,IAAK,KAAK,IAAI,GAAGH,EAAO,IAAI,CAASE,MAAAA,EAAM,IAAI,GAAG,CAAC,GACnDE,IAAST,KAAaA,EAAU,IAAI,GAAGI,CAAG,KAAKJ,EAAU,UAAU,GAAGG,CAAS;AAYrF,UAVKO,EAAA,MAAAjB,MAAAK,EAAA,MAAAL,GAAWkB,EAAMZ,EAAK,KAAK;AAAA,QAC9B,SAAS;AAAA,QACT,aAAa;AAAA,QACb,OAAO;AAAA,QACP,OAAO;AAAA,QACP,UAAU;AAAA,QACV,GAAGW,EAAA,MAAKhB;AAAA,QACR,SAAS,KAAK;AAAA,MAAA,CACf,IAEG,EAAAQ,KAAaO,IAGjB;AAAA,YAAI,CAACC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SAAS,aAAa,GAEhEC,IAAc,CAACtB,EAAK,cAAc,CAACqB,GAEnCE,IAAa,CAACvB,EAAK;AAGvB,SAAA,EAAAsB,KACGJ,KACAC,KACAI;AAKP;AC3FK,SAASC,EAA+CC,GAAQ;AACrE,QAAMC,IAAcC,EAA2C,CAAI,GAAA,GAAGF,CAAE,eAAe,GACjFG,IAAgBC,EAAO,CAACC,MAAQ;AACpC,UAAMC,IAAOD,EAAI,IAAIJ,EAAY,GAAG;AACpC,WAAO,IAAIM,EAAO;AAAA,MAChB,KAAK,IAAIC,EAAU,GAAGR,CAAE,UAAU;AAAA,MAClC,GAAGM;AAAA,IAAA,CACJ;AAAA,EAAA,CACF,GACKG,IAAS,CAACR,GAAaE,CAAa;AAC1C,SAAAM,EAAO,MAAMR,EAAY,KACzBQ,EAAO,YAAYN,EAAc,KACjCF,EAAY,OAAO;AAAA,IACjB,SAAS;AAAA,IACT,aAAa,oBAAoBD,CAAE;AAAA,EAAA,GAErCG,EAAc,OAAO;AAAA,IACnB,SAAS;AAAA,IACT,aAAa,kBAAkBH,CAAE;AAAA,EAAA,GAG5BS;AACT;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/tooltip-provider.ts","../src/tooltip-plugin.ts"],"sourcesContent":["import type { EditorState } from '@milkdown/prose/state'\nimport { TextSelection } from '@milkdown/prose/state'\nimport type { EditorView } from '@milkdown/prose/view'\nimport debounce from 'lodash.debounce'\nimport type { VirtualElement } from '@floating-ui/dom'\nimport { computePosition, flip, offset } from '@floating-ui/dom'\nimport { posToDOMRect } from '@milkdown/prose'\n\n/// Options for tooltip provider.\nexport interface TooltipProviderOptions {\n /// The tooltip content.\n content: HTMLElement\n /// The debounce time for updating tooltip, 200ms by default.\n debounce?: number\n /// The function to determine whether the tooltip should be shown.\n shouldShow?: (view: EditorView, prevState?: EditorState) => boolean\n /// The offset to get the block. Default is 0.\n offset?: number | {\n mainAxis?: number\n crossAxis?: number\n alignmentAxis?: number | null\n }\n}\n\n/// A provider for creating tooltip.\nexport class TooltipProvider {\n /// @internal\n readonly #debounce: number\n\n /// @internal\n readonly #shouldShow: (view: EditorView, prevState?: EditorState) => boolean\n\n /// @internal\n #initialized = false\n\n /// @internal\n readonly #offset?: number | {\n mainAxis?: number\n crossAxis?: number\n alignmentAxis?: number | null\n }\n\n /// The root element of the tooltip.\n element: HTMLElement\n\n /// On show callback.\n onShow = () => {}\n\n /// On hide callback.\n onHide = () => {}\n\n constructor(options: TooltipProviderOptions) {\n this.element = options.content\n this.#debounce = options.debounce ?? 200\n this.#shouldShow = options.shouldShow ?? this.#_shouldShow\n this.#offset = options.offset\n }\n\n /// @internal\n #onUpdate = (view: EditorView, prevState?: EditorState): void => {\n const { state, composing } = view\n const { selection, doc } = state\n const { ranges } = selection\n const from = Math.min(...ranges.map(range => range.$from.pos))\n const to = Math.max(...ranges.map(range => range.$to.pos))\n const isSame = prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection)\n\n if (!this.#initialized) {\n view.dom.parentElement?.appendChild(this.element)\n this.#initialized = true\n }\n\n if (composing || isSame)\n return\n\n if (!this.#shouldShow(view, prevState)) {\n this.hide()\n return\n }\n\n const virtualEl: VirtualElement = {\n getBoundingClientRect: () => posToDOMRect(view, from, to),\n }\n computePosition(virtualEl, this.element, {\n placement: 'top',\n middleware: [flip(), offset(this.#offset)],\n })\n .then(({ x, y }) => {\n Object.assign(this.element.style, {\n left: `${x}px`,\n top: `${y}px`,\n })\n })\n\n this.show()\n }\n\n /// Update provider state by editor view.\n update = (view: EditorView, prevState?: EditorState): void => {\n const updater = debounce(this.#onUpdate, this.#debounce)\n\n updater(view, prevState)\n }\n\n /// @internal\n #_shouldShow(view: EditorView): boolean {\n const { doc, selection } = view.state\n const { empty, from, to } = selection\n\n const isEmptyTextBlock = !doc.textBetween(from, to).length && view.state.selection instanceof TextSelection\n\n const isTooltipChildren = this.element.contains(document.activeElement)\n\n const notHasFocus = !view.hasFocus() && !isTooltipChildren\n\n const isReadonly = !view.editable\n\n if (\n notHasFocus\n || empty\n || isEmptyTextBlock\n || isReadonly\n )\n return false\n\n return true\n }\n\n /// Destroy the tooltip.\n destroy = () => {}\n\n /// Show the tooltip.\n show = (virtualElement?: VirtualElement) => {\n this.element.dataset.show = 'true'\n\n if (virtualElement) {\n computePosition(virtualElement, this.element, {\n placement: 'top',\n middleware: [flip(), offset(this.#offset)],\n })\n .then(({ x, y }) => {\n Object.assign(this.element.style, {\n left: `${x}px`,\n top: `${y}px`,\n })\n })\n }\n\n this.onShow()\n }\n\n /// Hide the tooltip.\n hide = () => {\n this.element.dataset.show = 'false'\n\n this.onHide()\n }\n}\n","import type { SliceType } from '@milkdown/ctx'\nimport type { PluginSpec } from '@milkdown/prose/state'\nimport { Plugin, PluginKey } from '@milkdown/prose/state'\nimport type { $Ctx, $Prose } from '@milkdown/utils'\nimport { $ctx, $prose } from '@milkdown/utils'\n\n/// @internal\nexport type TooltipSpecId<Id extends string> = `${Id}_TOOLTIP_SPEC`\n\n/// @internal\nexport type TooltipPlugin<Id extends string, State = any> = [$Ctx<PluginSpec<State>, TooltipSpecId<Id>>, $Prose] & {\n key: SliceType<PluginSpec<State>, TooltipSpecId<Id>>\n pluginKey: $Prose['key']\n}\n\n/// Create a tooltip plugin with a unique id.\nexport function tooltipFactory<Id extends string, State = any>(id: Id) {\n const tooltipSpec = $ctx<PluginSpec<State>, TooltipSpecId<Id>>({}, `${id}_TOOLTIP_SPEC`)\n const tooltipPlugin = $prose((ctx) => {\n const spec = ctx.get(tooltipSpec.key)\n return new Plugin({\n key: new PluginKey(`${id}_TOOLTIP`),\n ...spec,\n })\n })\n const result = [tooltipSpec, tooltipPlugin] as TooltipPlugin<Id>\n result.key = tooltipSpec.key\n result.pluginKey = tooltipPlugin.key\n tooltipSpec.meta = {\n package: '@milkdown/plugin-tooltip',\n displayName: `Ctx<tooltipSpec>|${id}`,\n }\n tooltipPlugin.meta = {\n package: '@milkdown/plugin-tooltip',\n displayName: `Prose<tooltip>|${id}`,\n }\n\n return result\n}\n"],"names":["TooltipProvider","options","__privateAdd","__shouldShow","_debounce","_shouldShow","_initialized","_offset","_onUpdate","__privateSet","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","_a","computePosition","posToDOMRect","flip","offset","x","y","debounce","virtualElement","__privateMethod","_shouldShow_fn","empty","isEmptyTextBlock","TextSelection","isTooltipChildren","notHasFocus","isReadonly","tooltipFactory","id","tooltipSpec","$ctx","tooltipPlugin","$prose","ctx","spec","Plugin","PluginKey","result"],"mappings":";;;;;;;;;;;;;;;;AAyBO,MAAMA,EAAgB;AAAA,EA0B3B,YAAYC,GAAiC;AAsD7C;AAAA,IAAAC,EAAA,MAAAC;AA9ES;AAAA,IAAAD,EAAA,MAAAE,GAAA;AAGA;AAAA,IAAAF,EAAA,MAAAG,GAAA;AAGT,IAAAH,EAAA,MAAAI,GAAA;AAGS;AAAA,IAAAJ,EAAA,MAAAK,GAAA;AAuBT,IAAAL,EAAA,MAAAM,GAAA;AA1Be,IAAAC,EAAA,MAAAH,GAAA,KAaf,KAAA,SAAS,MAAM;AAAA,IAAA,GAGf,KAAA,SAAS,MAAM;AAAA,IAAA,GAUHG,EAAA,MAAAD,GAAA,CAACE,GAAkBC,MAAkC;;AACzD,YAAA,EAAE,OAAAC,GAAO,WAAAC,EAAc,IAAAH,GACvB,EAAE,WAAAI,GAAW,KAAAC,EAAQ,IAAAH,GACrB,EAAE,QAAAI,EAAW,IAAAF,GACbG,IAAO,KAAK,IAAI,GAAGD,EAAO,IAAI,CAASE,MAAAA,EAAM,MAAM,GAAG,CAAC,GACvDC,IAAK,KAAK,IAAI,GAAGH,EAAO,IAAI,CAASE,MAAAA,EAAM,IAAI,GAAG,CAAC,GACnDE,IAAST,KAAaA,EAAU,IAAI,GAAGI,CAAG,KAAKJ,EAAU,UAAU,GAAGG,CAAS;AAOrF,UALKO,EAAA,MAAKf,QACRgB,IAAAZ,EAAK,IAAI,kBAAT,QAAAY,EAAwB,YAAY,KAAK,UACzCb,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BS;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-plugin.d.ts","sourceRoot":"","sources":["../src/tooltip-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAInD,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,IAAI,GAAG,EAAE,eAAe,CAAA;AAGnE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IACjH,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;CACzB,CAAA;AAGD,wBAAgB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,GAAG,GAAG,EAAE,EAAE,EAAE,EAAE,0BAsBpE"}
1
+ {"version":3,"file":"tooltip-plugin.d.ts","sourceRoot":"","sources":["../src/tooltip-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAInD,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,IAAI,GAAG,EAAE,eAAe,CAAA;AAGnE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IACjH,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;CACzB,CAAA;AAGD,wBAAgB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,GAAG,GAAG,EAAE,EAAE,EAAE,EAAE,0BAsBpE"}
@@ -1,20 +1,25 @@
1
1
  import type { EditorState } from '@milkdown/prose/state';
2
2
  import type { EditorView } from '@milkdown/prose/view';
3
- import type { Instance, Props } from 'tippy.js';
3
+ import type { VirtualElement } from '@floating-ui/dom';
4
4
  export interface TooltipProviderOptions {
5
5
  content: HTMLElement;
6
- tippyOptions?: Partial<Props>;
7
6
  debounce?: number;
8
7
  shouldShow?: (view: EditorView, prevState?: EditorState) => boolean;
8
+ offset?: number | {
9
+ mainAxis?: number;
10
+ crossAxis?: number;
11
+ alignmentAxis?: number | null;
12
+ };
9
13
  }
10
14
  export declare class TooltipProvider {
11
15
  #private;
12
16
  element: HTMLElement;
17
+ onShow: () => void;
18
+ onHide: () => void;
13
19
  constructor(options: TooltipProviderOptions);
14
20
  update: (view: EditorView, prevState?: EditorState) => void;
15
21
  destroy: () => void;
16
- show: () => void;
22
+ show: (virtualElement?: VirtualElement) => void;
17
23
  hide: () => void;
18
- getInstance: () => Instance<Props> | undefined;
19
24
  }
20
25
  //# sourceMappingURL=tooltip-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-provider.d.ts","sourceRoot":"","sources":["../src/tooltip-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,KAAK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AW;gBAEL,OAAO,EAAE,sBAAsB;IA+C3C,MAAM,SAAU,UAAU,cAAc,WAAW,KAAG,IAAI,CAIzD;IA2BD,OAAO,aAAW;IAGlB,IAAI,oBAAqB,cAAc,UAiBtC;IAGD,IAAI,aAIH;CACF"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@milkdown/plugin-tooltip",
3
3
  "type": "module",
4
- "version": "7.3.6",
4
+ "version": "7.5.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/Milkdown/milkdown.git",
9
- "directory": "packages/plugin-tooltip"
9
+ "directory": "packages/plugins/plugin-tooltip"
10
10
  },
11
11
  "keywords": [
12
12
  "milkdown",
@@ -30,17 +30,18 @@
30
30
  "@milkdown/prose": "^7.2.0"
31
31
  },
32
32
  "dependencies": {
33
+ "@floating-ui/dom": "^1.5.1",
33
34
  "@types/lodash.debounce": "^4.0.7",
34
35
  "lodash.debounce": "^4.0.8",
35
36
  "tippy.js": "^6.3.7",
36
37
  "tslib": "^2.5.0",
37
- "@milkdown/exception": "7.3.6",
38
- "@milkdown/utils": "7.3.6"
38
+ "@milkdown/exception": "7.5.0",
39
+ "@milkdown/utils": "7.5.0"
39
40
  },
40
41
  "devDependencies": {
41
- "@milkdown/core": "7.3.6",
42
- "@milkdown/ctx": "7.3.6",
43
- "@milkdown/prose": "7.3.6"
42
+ "@milkdown/core": "7.5.0",
43
+ "@milkdown/ctx": "7.5.0",
44
+ "@milkdown/prose": "7.5.0"
44
45
  },
45
46
  "nx": {
46
47
  "targets": {
@@ -49,19 +50,13 @@
49
50
  "{projectRoot}/lib"
50
51
  ],
51
52
  "dependsOn": [
52
- {
53
- "target": "build",
54
- "projects": "dependencies"
55
- }
53
+ "build"
56
54
  ]
57
55
  },
58
56
  "tsc": {
59
57
  "outputs": [],
60
58
  "dependsOn": [
61
- {
62
- "target": "build",
63
- "projects": "dependencies"
64
- }
59
+ "build"
65
60
  ]
66
61
  }
67
62
  }
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
1
  export * from './tooltip-provider'
3
2
  export * from './tooltip-plugin'
@@ -1,4 +1,3 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
1
  import type { SliceType } from '@milkdown/ctx'
3
2
  import type { PluginSpec } from '@milkdown/prose/state'
4
3
  import { Plugin, PluginKey } from '@milkdown/prose/state'
@@ -1,46 +1,59 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { posToDOMRect } from '@milkdown/prose'
3
1
  import type { EditorState } from '@milkdown/prose/state'
4
2
  import { TextSelection } from '@milkdown/prose/state'
5
3
  import type { EditorView } from '@milkdown/prose/view'
6
4
  import debounce from 'lodash.debounce'
7
- import type { Instance, Props } from 'tippy.js'
8
- import tippy from 'tippy.js'
5
+ import type { VirtualElement } from '@floating-ui/dom'
6
+ import { computePosition, flip, offset } from '@floating-ui/dom'
7
+ import { posToDOMRect } from '@milkdown/prose'
9
8
 
10
9
  /// Options for tooltip provider.
11
10
  export interface TooltipProviderOptions {
12
11
  /// The tooltip content.
13
12
  content: HTMLElement
14
- /// The options for creating [tippy.js](https://atomiks.github.io/tippyjs/) instance.
15
- tippyOptions?: Partial<Props>
16
13
  /// The debounce time for updating tooltip, 200ms by default.
17
14
  debounce?: number
18
15
  /// The function to determine whether the tooltip should be shown.
19
16
  shouldShow?: (view: EditorView, prevState?: EditorState) => boolean
17
+ /// The offset to get the block. Default is 0.
18
+ offset?: number | {
19
+ mainAxis?: number
20
+ crossAxis?: number
21
+ alignmentAxis?: number | null
22
+ }
20
23
  }
21
24
 
22
25
  /// A provider for creating tooltip.
23
26
  export class TooltipProvider {
24
27
  /// @internal
25
- #tippy: Instance | undefined
28
+ readonly #debounce: number
26
29
 
27
30
  /// @internal
28
- #tippyOptions: Partial<Props>
31
+ readonly #shouldShow: (view: EditorView, prevState?: EditorState) => boolean
29
32
 
30
33
  /// @internal
31
- #debounce: number
34
+ #initialized = false
32
35
 
33
36
  /// @internal
34
- #shouldShow: (view: EditorView, prevState?: EditorState) => boolean
37
+ readonly #offset?: number | {
38
+ mainAxis?: number
39
+ crossAxis?: number
40
+ alignmentAxis?: number | null
41
+ }
35
42
 
36
43
  /// The root element of the tooltip.
37
44
  element: HTMLElement
38
45
 
46
+ /// On show callback.
47
+ onShow = () => {}
48
+
49
+ /// On hide callback.
50
+ onHide = () => {}
51
+
39
52
  constructor(options: TooltipProviderOptions) {
40
53
  this.element = options.content
41
- this.#tippyOptions = options.tippyOptions ?? {}
42
54
  this.#debounce = options.debounce ?? 200
43
55
  this.#shouldShow = options.shouldShow ?? this.#_shouldShow
56
+ this.#offset = options.offset
44
57
  }
45
58
 
46
59
  /// @internal
@@ -52,15 +65,10 @@ export class TooltipProvider {
52
65
  const to = Math.max(...ranges.map(range => range.$to.pos))
53
66
  const isSame = prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection)
54
67
 
55
- this.#tippy ??= tippy(view.dom, {
56
- trigger: 'manual',
57
- interactive: true,
58
- delay: 0,
59
- arrow: false,
60
- duration: 0,
61
- ...this.#tippyOptions,
62
- content: this.element,
63
- })
68
+ if (!this.#initialized) {
69
+ view.dom.parentElement?.appendChild(this.element)
70
+ this.#initialized = true
71
+ }
64
72
 
65
73
  if (composing || isSame)
66
74
  return
@@ -70,9 +78,19 @@ export class TooltipProvider {
70
78
  return
71
79
  }
72
80
 
73
- this.#tippy.setProps({
74
- getReferenceClientRect: () => posToDOMRect(view, from, to),
81
+ const virtualEl: VirtualElement = {
82
+ getBoundingClientRect: () => posToDOMRect(view, from, to),
83
+ }
84
+ computePosition(virtualEl, this.element, {
85
+ placement: 'top',
86
+ middleware: [flip(), offset(this.#offset)],
75
87
  })
88
+ .then(({ x, y }) => {
89
+ Object.assign(this.element.style, {
90
+ left: `${x}px`,
91
+ top: `${y}px`,
92
+ })
93
+ })
76
94
 
77
95
  this.show()
78
96
  }
@@ -109,22 +127,32 @@ export class TooltipProvider {
109
127
  }
110
128
 
111
129
  /// Destroy the tooltip.
112
- destroy = () => {
113
- this.#tippy?.destroy()
114
- }
130
+ destroy = () => {}
115
131
 
116
132
  /// Show the tooltip.
117
- show = () => {
118
- this.#tippy?.show()
133
+ show = (virtualElement?: VirtualElement) => {
134
+ this.element.dataset.show = 'true'
135
+
136
+ if (virtualElement) {
137
+ computePosition(virtualElement, this.element, {
138
+ placement: 'top',
139
+ middleware: [flip(), offset(this.#offset)],
140
+ })
141
+ .then(({ x, y }) => {
142
+ Object.assign(this.element.style, {
143
+ left: `${x}px`,
144
+ top: `${y}px`,
145
+ })
146
+ })
147
+ }
148
+
149
+ this.onShow()
119
150
  }
120
151
 
121
152
  /// Hide the tooltip.
122
153
  hide = () => {
123
- this.#tippy?.hide()
124
- }
154
+ this.element.dataset.show = 'false'
125
155
 
126
- /// Get the [tippy.js](https://atomiks.github.io/tippyjs/) instance.
127
- getInstance = () => {
128
- return this.#tippy
156
+ this.onHide()
129
157
  }
130
158
  }