@milkdown/plugin-slash 7.2.1 → 7.2.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/README.md CHANGED
@@ -4,7 +4,7 @@ The slash plugin of [milkdown](https://milkdown.dev/).
4
4
 
5
5
  # Official Documentation
6
6
 
7
- Documentation can be found on the [Milkdown website](https://milkdown.dev/plugin-slash).
7
+ Documentation can be found on the [Milkdown website](https://milkdown.dev/docs/api/plugin-slash).
8
8
 
9
9
  # License
10
10
 
package/lib/index.es.js CHANGED
@@ -2,7 +2,7 @@ var x = (e, s, t) => {
2
2
  if (!s.has(e))
3
3
  throw TypeError("Cannot " + t);
4
4
  };
5
- var n = (e, s, t) => (x(e, s, "read from private field"), t ? t.call(e) : s.get(e)), a = (e, s, t) => {
5
+ var n = (e, s, t) => (x(e, s, "read from private field"), t ? t.call(e) : s.get(e)), c = (e, s, t) => {
6
6
  if (s.has(e))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  s instanceof WeakSet ? s.add(e) : s.set(e, t);
@@ -14,8 +14,8 @@ import { posToDOMRect as F, findParentNode as H } from "@milkdown/prose";
14
14
  import I from "lodash.debounce";
15
15
  import M from "tippy.js";
16
16
  const L = (e) => {
17
- const s = _({}, `${e}_SLASH_SPEC`), t = w((c) => {
18
- const h = c.get(s.key);
17
+ const s = _({}, `${e}_SLASH_SPEC`), t = w((a) => {
18
+ const h = a.get(s.key);
19
19
  return new N({
20
20
  key: new R(`${e}_SLASH`),
21
21
  ...h
@@ -33,38 +33,38 @@ var i, l, p, m, u, f, b;
33
33
  class D {
34
34
  constructor(s) {
35
35
  /// @internal
36
- a(this, f);
36
+ c(this, f);
37
37
  /// @internal
38
- a(this, i, void 0);
38
+ c(this, i, void 0);
39
39
  /// @internal
40
- a(this, l, void 0);
40
+ c(this, l, void 0);
41
41
  /// @internal
42
- a(this, p, void 0);
42
+ c(this, p, void 0);
43
43
  /// @internal
44
- a(this, m, void 0);
45
- a(this, u, void 0);
44
+ c(this, m, void 0);
45
+ c(this, u, void 0);
46
46
  r(this, u, (t, o) => {
47
- const { state: c, composing: h } = t, { selection: d, doc: k } = c, { ranges: g } = d, y = Math.min(...g.map((P) => P.$from.pos)), C = Math.max(...g.map((P) => P.$to.pos)), S = o && o.doc.eq(k) && o.selection.eq(d);
47
+ const { state: a, composing: h } = t, { selection: d, doc: k } = a, { ranges: g } = d, S = Math.min(...g.map((P) => P.$from.pos)), y = Math.max(...g.map((P) => P.$to.pos)), C = o && o.doc.eq(k) && o.selection.eq(d);
48
48
  if (n(this, i) ?? r(this, i, M(t.dom, {
49
49
  trigger: "manual",
50
50
  placement: "bottom-start",
51
51
  interactive: !0,
52
52
  ...n(this, l),
53
53
  content: this.element
54
- })), !(h || S)) {
54
+ })), !(h || C)) {
55
55
  if (!n(this, m).call(this, t, o)) {
56
56
  this.hide();
57
57
  return;
58
58
  }
59
59
  n(this, i).setProps({
60
- getReferenceClientRect: () => F(t, y, C)
60
+ getReferenceClientRect: () => F(t, S, y)
61
61
  }), this.show();
62
62
  }
63
63
  }), this.update = (t, o) => {
64
64
  I(n(this, u), n(this, p))(t, o);
65
- }, this.getContent = (t) => {
66
- const { selection: o } = t.state, { empty: c } = o, h = t.state.selection instanceof T, d = this.element.contains(document.activeElement), k = !t.hasFocus() && !d, g = !t.editable, y = H(({ type: S }) => S.name === "paragraph")(t.state.selection);
67
- if (!(k || g || !c || !h || !y))
65
+ }, this.getContent = (t, o = (a) => a.type.name === "paragraph") => {
66
+ const { selection: a } = t.state, { empty: h } = a, d = t.state.selection instanceof T, k = this.element.contains(document.activeElement), g = !t.hasFocus() && !k, S = !t.editable, y = H(o)(t.state.selection);
67
+ if (!(g || S || !h || !d || !y))
68
68
  return y.node.textContent;
69
69
  }, this.destroy = () => {
70
70
  var t;
@@ -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 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","_tippy","_tippyOptions","_debounce","_shouldShow","_onUpdate","__privateSet","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","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,CAAW;AACtC,SAAAM,EAAO,MAAMR,EAAU,KACvBQ,EAAO,YAAYN,EAAY,KAC/BF,EAAU,OAAO;AAAA,IACf,SAAS;AAAA,IACT,aAAa,kBAAkBD;AAAA,EAAA,GAEjCG,EAAY,OAAO;AAAA,IACjB,SAAS;AAAA,IACT,aAAa,gBAAgBH;AAAA,EAAA,GAGxBS;AACT;;ACjBO,MAAMC,EAAc;AAAA,EAgBzB,YAAYC,GAA+B;AAwC3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{"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 type { Node } from '@milkdown/prose/model'\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 /// Pass the `matchNode` function to determine whether the current node should be matched, by default, it will match the paragraph node.\n getContent = (view: EditorView, matchNode: (node: Node) => boolean = node => node.type.name === 'paragraph'): 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(matchNode)(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","_tippy","_tippyOptions","_debounce","_shouldShow","_onUpdate","__privateSet","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","tippy","posToDOMRect","debounce","matchNode","node","empty","isTextBlock","TextSelection","isSlashChildren","notHasFocus","isReadonly","paragraph","findParentNode","_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,CAAW;AACtC,SAAAM,EAAO,MAAMR,EAAU,KACvBQ,EAAO,YAAYN,EAAY,KAC/BF,EAAU,OAAO;AAAA,IAC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AA,eAGAC,IAAA,eAGAC,IAAA,eAUAC,IAAA,eAgCAL,IAAA,eAAAkC,aAAa3B,GAA2B;AAChC,QAAA4B,IAA0B,KAAK,WAAW5B,CAAI;AAEpD,SAAK4B,IAGEA,EAAwB,GAAG,EAAE,MAAM,MAFjC;AAGX;"}
@@ -1,4 +1,5 @@
1
1
  import type { EditorState } from '@milkdown/prose/state';
2
+ import type { Node } from '@milkdown/prose/model';
2
3
  import type { EditorView } from '@milkdown/prose/view';
3
4
  import type { Instance, Props } from 'tippy.js';
4
5
  export type SlashProviderOptions = {
@@ -12,7 +13,7 @@ export declare class SlashProvider {
12
13
  element: HTMLElement;
13
14
  constructor(options: SlashProviderOptions);
14
15
  update: (view: EditorView, prevState?: EditorState) => void;
15
- getContent: (view: EditorView) => string | undefined;
16
+ getContent: (view: EditorView, matchNode?: (node: Node) => boolean) => string | undefined;
16
17
  destroy: () => void;
17
18
  show: () => void;
18
19
  hide: () => void;
@@ -1 +1 @@
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"}
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;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,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;IAID,UAAU,SAAU,UAAU,qBAAoB,IAAI,KAAK,OAAO,KAA4C,MAAM,GAAG,SAAS,CAmB/H;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.2.1",
4
+ "version": "7.2.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -29,13 +29,13 @@
29
29
  "lodash.debounce": "^4.0.8",
30
30
  "tippy.js": "^6.3.7",
31
31
  "tslib": "^2.5.0",
32
- "@milkdown/exception": "7.2.1",
33
- "@milkdown/utils": "7.2.1"
32
+ "@milkdown/exception": "7.2.3",
33
+ "@milkdown/utils": "7.2.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@milkdown/core": "7.2.1",
37
- "@milkdown/ctx": "7.2.1",
38
- "@milkdown/prose": "7.2.1"
36
+ "@milkdown/core": "7.2.3",
37
+ "@milkdown/ctx": "7.2.3",
38
+ "@milkdown/prose": "7.2.3"
39
39
  },
40
40
  "nx": {
41
41
  "targets": {
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { findParentNode, posToDOMRect } from '@milkdown/prose'
3
3
  import type { EditorState } from '@milkdown/prose/state'
4
+ import type { Node } from '@milkdown/prose/model'
4
5
  import { TextSelection } from '@milkdown/prose/state'
5
6
  import type { EditorView } from '@milkdown/prose/view'
6
7
  import debounce from 'lodash.debounce'
@@ -93,7 +94,8 @@ export class SlashProvider {
93
94
  }
94
95
 
95
96
  /// Get the content of the current text block.
96
- getContent = (view: EditorView): string | undefined => {
97
+ /// Pass the `matchNode` function to determine whether the current node should be matched, by default, it will match the paragraph node.
98
+ getContent = (view: EditorView, matchNode: (node: Node) => boolean = node => node.type.name === 'paragraph'): string | undefined => {
97
99
  const { selection } = view.state
98
100
  const { empty } = selection
99
101
  const isTextBlock = view.state.selection instanceof TextSelection
@@ -104,7 +106,7 @@ export class SlashProvider {
104
106
 
105
107
  const isReadonly = !view.editable
106
108
 
107
- const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(view.state.selection)
109
+ const paragraph = findParentNode(matchNode)(view.state.selection)
108
110
 
109
111
  const isNotInParagraph = !paragraph
110
112