@milkdown/plugin-slash 7.1.0 → 7.1.2-next.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.
package/lib/index.es.js CHANGED
@@ -1,81 +1,88 @@
1
- var b = Object.defineProperty;
2
- var B = (n, t, e) => t in n ? b(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var c = (n, t, e) => (B(n, typeof t != "symbol" ? t + "" : t, e), e), x = (n, t, e) => {
4
- if (!t.has(n))
1
+ var N = Object.defineProperty;
2
+ var R = (s, t, e) => t in s ? N(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var c = (s, t, e) => (R(s, typeof t != "symbol" ? t + "" : t, e), e), x = (s, t, e) => {
4
+ if (!t.has(s))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var s = (n, t, e) => (x(n, t, "read from private field"), e ? e.call(n) : t.get(n)), i = (n, t, e) => {
8
- if (t.has(n))
7
+ var n = (s, t, e) => (x(s, t, "read from private field"), e ? e.call(s) : t.get(s)), i = (s, t, e) => {
8
+ if (t.has(s))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(n) : t.set(n, e);
11
- }, p = (n, t, e, o) => (x(n, t, "write to private field"), o ? o.call(n, e) : t.set(n, e), e);
12
- var T = (n, t, e) => (x(n, t, "access private method"), e);
13
- import { Plugin as R, PluginKey as _, TextSelection as F } from "@milkdown/prose/state";
14
- import { $ctx as H, $prose as I } from "@milkdown/utils";
15
- import { posToDOMRect as M, findParentNode as N } from "@milkdown/prose";
10
+ t instanceof WeakSet ? t.add(s) : t.set(s, e);
11
+ }, l = (s, t, e, o) => (x(s, t, "write to private field"), o ? o.call(s, e) : t.set(s, e), e);
12
+ var $ = (s, t, e) => (x(s, t, "access private method"), e);
13
+ import { Plugin as T, PluginKey as _, TextSelection as w } from "@milkdown/prose/state";
14
+ import { $ctx as F, $prose as H } from "@milkdown/utils";
15
+ import { posToDOMRect as I, findParentNode as M } from "@milkdown/prose";
16
16
  import O from "lodash.debounce";
17
17
  import q from "tippy.js";
18
- const U = (n) => {
19
- const t = H({}, `${n}_SLASH_SPEC`), e = I((h) => {
20
- const a = h.get(t.key);
21
- return new R({
22
- key: new _(`${n}_SLASH`),
23
- ...a
18
+ const U = (s) => {
19
+ const t = F({}, `${s}_SLASH_SPEC`), e = H((h) => {
20
+ const r = h.get(t.key);
21
+ return new T({
22
+ key: new _(`${s}_SLASH`),
23
+ ...r
24
24
  });
25
25
  }), o = [t, e];
26
- return o.key = t.key, o.pluginKey = e.key, o;
26
+ return o.key = t.key, o.pluginKey = e.key, t.meta = {
27
+ package: "@milkdown/plugin-slash",
28
+ displayName: `Ctx<slashSpec>|${s}`
29
+ }, e.meta = {
30
+ package: "@milkdown/plugin-slash",
31
+ displayName: `Prose<slash>|${s}`
32
+ }, o;
27
33
  };
28
- var r, u, m, d, f, S, $;
34
+ var a, p, m, u, y, f, b;
29
35
  class j {
30
36
  constructor(t) {
31
- i(this, S);
37
+ i(this, f);
32
38
  c(this, "element");
33
- i(this, r, void 0);
34
- i(this, u, void 0);
39
+ i(this, a, void 0);
40
+ i(this, p, void 0);
35
41
  i(this, m, void 0);
36
- i(this, d, void 0);
37
- i(this, f, (t, e) => {
38
- const { state: o, composing: h } = t, { selection: a, doc: k } = o, { ranges: g } = a, y = Math.min(...g.map((l) => l.$from.pos)), C = Math.max(...g.map((l) => l.$to.pos)), P = e && e.doc.eq(k) && e.selection.eq(a);
39
- if (s(this, r) ?? p(this, r, q(t.dom, {
42
+ i(this, u, void 0);
43
+ i(this, y, (t, e) => {
44
+ const { state: o, composing: h } = t, { selection: r, doc: k } = o, { ranges: d } = r, g = Math.min(...d.map((P) => P.$from.pos)), C = Math.max(...d.map((P) => P.$to.pos)), S = e && e.doc.eq(k) && e.selection.eq(r);
45
+ if (n(this, a) ?? l(this, a, q(t.dom, {
40
46
  trigger: "manual",
41
47
  placement: "bottom-start",
42
48
  interactive: !0,
43
- ...s(this, u),
49
+ ...n(this, p),
44
50
  content: this.element
45
- })), !(h || P)) {
46
- if (!s(this, d).call(this, t, e)) {
51
+ })), !(h || S)) {
52
+ if (!n(this, u).call(this, t, e)) {
47
53
  this.hide();
48
54
  return;
49
55
  }
50
- s(this, r).setProps({
51
- getReferenceClientRect: () => M(t, y, C)
56
+ n(this, a).setProps({
57
+ getReferenceClientRect: () => I(t, g, C)
52
58
  }), this.show();
53
59
  }
54
60
  });
55
61
  c(this, "update", (t, e) => {
56
- O(s(this, f), s(this, m))(t, e);
62
+ O(n(this, y), n(this, m))(t, e);
57
63
  });
58
64
  c(this, "getContent", (t) => {
59
- const { selection: e } = t.state, { empty: o } = e, h = t.state.selection instanceof F, a = this.element.contains(document.activeElement), k = !t.hasFocus() && !a, g = !t.editable, y = N(({ type: l }) => l.name === "paragraph")(t.state.selection);
60
- return k || g || !o || !h || !y ? void 0 : y.node.textContent;
65
+ const { selection: e } = t.state, { empty: o } = e, h = t.state.selection instanceof w, r = this.element.contains(document.activeElement), k = !t.hasFocus() && !r, d = !t.editable, g = M(({ type: S }) => S.name === "paragraph")(t.state.selection);
66
+ if (!(k || d || !o || !h || !g))
67
+ return g.node.textContent;
61
68
  });
62
69
  c(this, "destroy", () => {
63
70
  var t;
64
- (t = s(this, r)) == null || t.destroy();
71
+ (t = n(this, a)) == null || t.destroy();
65
72
  });
66
73
  c(this, "show", () => {
67
74
  var t;
68
- (t = s(this, r)) == null || t.show();
75
+ (t = n(this, a)) == null || t.show();
69
76
  });
70
77
  c(this, "hide", () => {
71
78
  var t;
72
- (t = s(this, r)) == null || t.hide();
79
+ (t = n(this, a)) == null || t.hide();
73
80
  });
74
- c(this, "getInstance", () => s(this, r));
75
- this.element = t.content, p(this, u, t.tippyOptions ?? {}), p(this, m, t.debounce ?? 200), p(this, d, t.shouldShow ?? T(this, S, $));
81
+ c(this, "getInstance", () => n(this, a));
82
+ this.element = t.content, l(this, p, t.tippyOptions ?? {}), l(this, m, t.debounce ?? 200), l(this, u, t.shouldShow ?? $(this, f, b));
76
83
  }
77
84
  }
78
- r = new WeakMap(), u = new WeakMap(), m = new WeakMap(), d = new WeakMap(), f = new WeakMap(), S = new WeakSet(), $ = function(t) {
85
+ a = new WeakMap(), p = new WeakMap(), m = new WeakMap(), u = new WeakMap(), y = new WeakMap(), f = new WeakSet(), b = function(t) {
79
86
  const e = this.getContent(t);
80
87
  return e ? e.at(-1) === "/" : !1;
81
88
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/slash-plugin.ts","../src/slash-provider.ts"],"sourcesContent":["/* 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 SlashPluginSpecId<Id extends string> = `${Id}_SLASH_SPEC`\n\n/// @internal\nexport type SlashPlugin<Id extends string, State = any> = [$Ctx<PluginSpec<State>, SlashPluginSpecId<Id>>, $Prose] & {\n key: SliceType<PluginSpec<State>, SlashPluginSpecId<Id>>\n pluginKey: $Prose['key']\n}\n\n/// Create a slash plugin with a unique id.\nexport const slashFactory = <Id extends string, State = any>(id: Id) => {\n const slashSpec = $ctx<PluginSpec<State>, SlashPluginSpecId<Id>>({}, `${id}_SLASH_SPEC`)\n const slashPlugin = $prose((ctx) => {\n const spec = ctx.get(slashSpec.key)\n return new Plugin({\n key: new PluginKey(`${id}_SLASH`),\n ...spec,\n })\n })\n const result = [slashSpec, slashPlugin] as SlashPlugin<Id>\n result.key = slashSpec.key\n result.pluginKey = slashPlugin.key\n\n return result\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { findParentNode, 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 slash provider.\nexport type SlashProviderOptions = {\n /// The slash 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 slash, 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 slash.\nexport class SlashProvider {\n /// The root element of the slash.\n element: HTMLElement\n\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 constructor(options: SlashProviderOptions) {\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 placement: 'bottom-start',\n interactive: true,\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 /// @internal\n #_shouldShow(view: EditorView): boolean {\n const currentTextBlockContent = this.getContent(view)\n\n if (!currentTextBlockContent)\n return false\n\n return currentTextBlockContent.at(-1) === '/'\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 /// Get the content of the current text block.\n getContent = (view: EditorView): string | undefined => {\n const { selection } = view.state\n const { empty } = selection\n const isTextBlock = view.state.selection instanceof TextSelection\n\n const isSlashChildren = this.element.contains(document.activeElement)\n\n const notHasFocus = !view.hasFocus() && !isSlashChildren\n\n const isReadonly = !view.editable\n\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(view.state.selection)\n\n const isNotInParagraph = !paragraph\n\n if (notHasFocus || isReadonly || !empty || !isTextBlock || isNotInParagraph)\n return\n\n const currentTextBlockContent = paragraph.node.textContent\n\n return currentTextBlockContent\n }\n\n /// Destroy the slash.\n destroy = () => {\n this.#tippy?.destroy()\n }\n\n /// Show the slash.\n show = () => {\n this.#tippy?.show()\n }\n\n /// Hide the slash.\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"],"names":["slashFactory","id","slashSpec","$ctx","slashPlugin","$prose","ctx","spec","Plugin","PluginKey","result","SlashProvider","options","__privateAdd","__shouldShow","__publicField","_tippy","_tippyOptions","_debounce","_shouldShow","_onUpdate","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","__privateSet","tippy","posToDOMRect","debounce","empty","isTextBlock","TextSelection","isSlashChildren","notHasFocus","isReadonly","paragraph","findParentNode","type","_a","__privateMethod","_shouldShow_fn","currentTextBlockContent"],"mappings":";;;;;;;;;;;;;;;;;AAiBa,MAAAA,IAAe,CAAiCC,MAAW;AACtE,QAAMC,IAAYC,EAA+C,CAAC,GAAG,GAAGF,cAAe,GACjFG,IAAcC,EAAO,CAACC,MAAQ;AAClC,UAAMC,IAAOD,EAAI,IAAIJ,EAAU,GAAG;AAClC,WAAO,IAAIM,EAAO;AAAA,MAChB,KAAK,IAAIC,EAAU,GAAGR,SAAU;AAAA,MAChC,GAAGM;AAAA,IAAA,CACJ;AA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,eAGAC,IAAA,eAGAC,IAAA,eAUAC,IAAA,eAgCAN,IAAA,eAAAkC,aAAa3B,GAA2B;AAChC,QAAA4B,IAA0B,KAAK,WAAW5B,CAAI;AAEpD,SAAK4B,IAGEA,EAAwB,GAAG,EAAE,MAAM,MAFjC;AAGX;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/slash-plugin.ts","../src/slash-provider.ts"],"sourcesContent":["/* 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 SlashPluginSpecId<Id extends string> = `${Id}_SLASH_SPEC`\n\n/// @internal\nexport type SlashPlugin<Id extends string, State = any> = [$Ctx<PluginSpec<State>, SlashPluginSpecId<Id>>, $Prose] & {\n key: SliceType<PluginSpec<State>, SlashPluginSpecId<Id>>\n pluginKey: $Prose['key']\n}\n\n/// Create a slash plugin with a unique id.\nexport const slashFactory = <Id extends string, State = any>(id: Id) => {\n const slashSpec = $ctx<PluginSpec<State>, SlashPluginSpecId<Id>>({}, `${id}_SLASH_SPEC`)\n const slashPlugin = $prose((ctx) => {\n const spec = ctx.get(slashSpec.key)\n return new Plugin({\n key: new PluginKey(`${id}_SLASH`),\n ...spec,\n })\n })\n const result = [slashSpec, slashPlugin] as SlashPlugin<Id>\n result.key = slashSpec.key\n result.pluginKey = slashPlugin.key\n slashSpec.meta = {\n package: '@milkdown/plugin-slash',\n displayName: `Ctx<slashSpec>|${id}`,\n }\n slashPlugin.meta = {\n package: '@milkdown/plugin-slash',\n displayName: `Prose<slash>|${id}`,\n }\n\n return result\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { findParentNode, 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 slash provider.\nexport type SlashProviderOptions = {\n /// The slash 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 slash, 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 slash.\nexport class SlashProvider {\n /// The root element of the slash.\n element: HTMLElement\n\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 constructor(options: SlashProviderOptions) {\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 placement: 'bottom-start',\n interactive: true,\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 /// @internal\n #_shouldShow(view: EditorView): boolean {\n const currentTextBlockContent = this.getContent(view)\n\n if (!currentTextBlockContent)\n return false\n\n return currentTextBlockContent.at(-1) === '/'\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 /// Get the content of the current text block.\n getContent = (view: EditorView): string | undefined => {\n const { selection } = view.state\n const { empty } = selection\n const isTextBlock = view.state.selection instanceof TextSelection\n\n const isSlashChildren = this.element.contains(document.activeElement)\n\n const notHasFocus = !view.hasFocus() && !isSlashChildren\n\n const isReadonly = !view.editable\n\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(view.state.selection)\n\n const isNotInParagraph = !paragraph\n\n if (notHasFocus || isReadonly || !empty || !isTextBlock || isNotInParagraph)\n return\n\n return paragraph.node.textContent\n }\n\n /// Destroy the slash.\n destroy = () => {\n this.#tippy?.destroy()\n }\n\n /// Show the slash.\n show = () => {\n this.#tippy?.show()\n }\n\n /// Hide the slash.\n hide = () => {\n this.#tippy?.hide()\n }\n\n /// Get the [tippy.js](https://atomiks.github.io/tippyjs/) instance.\n getInstance = () => this.#tippy\n}\n"],"names":["slashFactory","id","slashSpec","$ctx","slashPlugin","$prose","ctx","spec","Plugin","PluginKey","result","SlashProvider","options","__privateAdd","__shouldShow","__publicField","_tippy","_tippyOptions","_debounce","_shouldShow","_onUpdate","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","__privateSet","tippy","posToDOMRect","debounce","empty","isTextBlock","TextSelection","isSlashChildren","notHasFocus","isReadonly","paragraph","findParentNode","type","_a","__privateMethod","_shouldShow_fn","currentTextBlockContent"],"mappings":";;;;;;;;;;;;;;;;;AAiBa,MAAAA,IAAe,CAAiCC,MAAW;AACtE,QAAMC,IAAYC,EAA+C,CAAC,GAAG,GAAGF,cAAe,GACjFG,IAAcC,EAAO,CAACC,MAAQ;AAClC,UAAMC,IAAOD,EAAI,IAAIJ,EAAU,GAAG;AAClC,WAAO,IAAIM,EAAO;AAAA,MAChB,KAAK,IAAIC,EAAU,GAAGR,SAAU;AAAA,MAChC,GAAGM;AAAA,IAAA,CACJ;AAAA,EAAA,CACF,GACKG,IAAS,CAACR,GAAWE,C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,YAAY,MAChCqB,EAAA,MAAAd,GAAcP,EAAQ,cAAcmC,EAAA,MAAKjC,GAAAkC;AAAA,EAChD;AA0FF;AA1GEhC,IAAA,eAGAC,IAAA,eAGAC,IAAA,eAGAC,IAAA,eAUAC,IAAA,eAgCAN,IAAA,eAAAkC,aAAa3B,GAA2B;AAChC,QAAA4B,IAA0B,KAAK,WAAW5B,CAAI;AAEpD,SAAK4B,IAGEA,EAAwB,GAAG,EAAE,MAAM,MAFjC;AAGX;"}
@@ -1 +1 @@
1
- {"version":3,"file":"slash-plugin.d.ts","sourceRoot":"","sources":["../src/slash-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,iBAAiB,CAAC,EAAE,SAAS,MAAM,IAAI,GAAG,EAAE,aAAa,CAAA;AAGrE,MAAM,MAAM,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IACnH,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAA;IACxD,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;CACzB,CAAA;AAGD,eAAO,MAAM,YAAY,kEAcxB,CAAA"}
1
+ {"version":3,"file":"slash-plugin.d.ts","sourceRoot":"","sources":["../src/slash-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;A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KAAG,MAAM,GAAG,SAAS,CAqBlD;IAGD,OAAO,aAEN;IAGD,IAAI,aAEH;IAGD,IAAI,aAEH;IAGD,WAAW,oCAEV;CACF"}
1
+ {"version":3,"file":"slash-provider.d.ts","sourceRoot":"","sources":["../src/slash-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,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAI/C,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,WAAW,CAAA;IAEpB,YAAY,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAE7B,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,WAAW,KAAK,OAAO,CAAA;CACpE,CAAA;AAGD,qBAAa,aAAa;;IAExB,OAAO,EAAE,WAAW,CAAA;gBAcR,OAAO,EAAE,oBAAoB;IAkDzC,MAAM,SAAU,UAAU,cAAc,WAAW,KAAG,IAAI,CAIzD;IAGD,UAAU,SAAU,UAAU,KAAG,MAAM,GAAG,SAAS,CAmBlD;IAGD,OAAO,aAEN;IAGD,IAAI,aAEH;IAGD,IAAI,aAEH;IAGD,WAAW,oCAAoB;CAChC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/plugin-slash",
3
3
  "type": "module",
4
- "version": "7.1.0",
4
+ "version": "7.1.2-next.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -20,23 +20,22 @@
20
20
  "src"
21
21
  ],
22
22
  "peerDependencies": {
23
- "@milkdown/core": "^7.0.0-next.0",
24
- "@milkdown/ctx": "^7.0.0-next.0",
25
- "@milkdown/prose": "^7.0.0-next.0"
23
+ "@milkdown/core": "^7.1.2-next.0",
24
+ "@milkdown/ctx": "^7.1.2-next.0",
25
+ "@milkdown/prose": "^7.1.2-next.0"
26
26
  },
27
27
  "dependencies": {
28
28
  "@types/lodash.debounce": "^4.0.7",
29
29
  "lodash.debounce": "^4.0.8",
30
- "smooth-scroll-into-view-if-needed": "^1.1.32",
31
30
  "tippy.js": "^6.3.7",
32
- "tslib": "^2.4.0",
33
- "@milkdown/exception": "7.1.0",
34
- "@milkdown/utils": "7.1.0"
31
+ "tslib": "^2.5.0",
32
+ "@milkdown/exception": "7.1.2-next.0",
33
+ "@milkdown/utils": "7.1.2-next.0"
35
34
  },
36
35
  "devDependencies": {
37
- "@milkdown/core": "7.1.0",
38
- "@milkdown/ctx": "7.1.0",
39
- "@milkdown/prose": "7.1.0"
36
+ "@milkdown/core": "7.1.2-next.0",
37
+ "@milkdown/ctx": "7.1.2-next.0",
38
+ "@milkdown/prose": "7.1.2-next.0"
40
39
  },
41
40
  "nx": {
42
41
  "targets": {
@@ -27,6 +27,14 @@ export const slashFactory = <Id extends string, State = any>(id: Id) => {
27
27
  const result = [slashSpec, slashPlugin] as SlashPlugin<Id>
28
28
  result.key = slashSpec.key
29
29
  result.pluginKey = slashPlugin.key
30
+ slashSpec.meta = {
31
+ package: '@milkdown/plugin-slash',
32
+ displayName: `Ctx<slashSpec>|${id}`,
33
+ }
34
+ slashPlugin.meta = {
35
+ package: '@milkdown/plugin-slash',
36
+ displayName: `Prose<slash>|${id}`,
37
+ }
30
38
 
31
39
  return result
32
40
  }
@@ -111,9 +111,7 @@ export class SlashProvider {
111
111
  if (notHasFocus || isReadonly || !empty || !isTextBlock || isNotInParagraph)
112
112
  return
113
113
 
114
- const currentTextBlockContent = paragraph.node.textContent
115
-
116
- return currentTextBlockContent
114
+ return paragraph.node.textContent
117
115
  }
118
116
 
119
117
  /// Destroy the slash.
@@ -132,7 +130,5 @@ export class SlashProvider {
132
130
  }
133
131
 
134
132
  /// Get the [tippy.js](https://atomiks.github.io/tippyjs/) instance.
135
- getInstance = () => {
136
- return this.#tippy
137
- }
133
+ getInstance = () => this.#tippy
138
134
  }