@milkdown/plugin-slash 7.3.3 → 7.3.4
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 +45 -42
- package/lib/index.es.js.map +1 -1
- package/lib/slash-provider.d.ts.map +1 -1
- package/package.json +12 -6
- package/src/slash-provider.ts +5 -2
package/lib/index.es.js
CHANGED
|
@@ -1,73 +1,76 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (!
|
|
1
|
+
var $ = (s, e, t) => {
|
|
2
|
+
if (!e.has(s))
|
|
3
3
|
throw TypeError("Cannot " + t);
|
|
4
4
|
};
|
|
5
|
-
var o = (
|
|
6
|
-
if (
|
|
5
|
+
var o = (s, e, t) => ($(s, e, "read from private field"), t ? t.call(s) : e.get(s)), a = (s, e, t) => {
|
|
6
|
+
if (e.has(s))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
|
|
9
|
-
}, c = (
|
|
10
|
-
var b = (
|
|
11
|
-
import { Plugin as
|
|
12
|
-
import { $ctx as
|
|
13
|
-
import { posToDOMRect as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
function D(
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
return new
|
|
20
|
-
key: new
|
|
21
|
-
...
|
|
8
|
+
e instanceof WeakSet ? e.add(s) : e.set(s, t);
|
|
9
|
+
}, c = (s, e, t, n) => ($(s, e, "write to private field"), n ? n.call(s, t) : e.set(s, t), t);
|
|
10
|
+
var b = (s, e, t) => ($(s, e, "access private method"), t);
|
|
11
|
+
import { Plugin as O, PluginKey as A, TextSelection as M } from "@milkdown/prose/state";
|
|
12
|
+
import { $ctx as N, $prose as R } from "@milkdown/utils";
|
|
13
|
+
import { posToDOMRect as T, findParentNode as _ } from "@milkdown/prose";
|
|
14
|
+
import B from "lodash.debounce";
|
|
15
|
+
import F from "tippy.js";
|
|
16
|
+
function D(s) {
|
|
17
|
+
const e = N({}, `${s}_SLASH_SPEC`), t = R((r) => {
|
|
18
|
+
const p = r.get(e.key);
|
|
19
|
+
return new O({
|
|
20
|
+
key: new A(`${s}_SLASH`),
|
|
21
|
+
...p
|
|
22
22
|
});
|
|
23
|
-
}), n = [
|
|
24
|
-
return n.key =
|
|
23
|
+
}), n = [e, t];
|
|
24
|
+
return n.key = e.key, n.pluginKey = t.key, e.meta = {
|
|
25
25
|
package: "@milkdown/plugin-slash",
|
|
26
|
-
displayName: `Ctx<slashSpec>|${
|
|
26
|
+
displayName: `Ctx<slashSpec>|${s}`
|
|
27
27
|
}, t.meta = {
|
|
28
28
|
package: "@milkdown/plugin-slash",
|
|
29
|
-
displayName: `Prose<slash>|${
|
|
29
|
+
displayName: `Prose<slash>|${s}`
|
|
30
30
|
}, n;
|
|
31
31
|
}
|
|
32
|
-
var i,
|
|
32
|
+
var i, u, d, h, g, f, k, w;
|
|
33
33
|
class U {
|
|
34
|
-
constructor(
|
|
34
|
+
constructor(e) {
|
|
35
35
|
/// @internal
|
|
36
36
|
a(this, k);
|
|
37
37
|
/// @internal
|
|
38
38
|
a(this, i, void 0);
|
|
39
39
|
/// @internal
|
|
40
|
-
a(this,
|
|
40
|
+
a(this, u, void 0);
|
|
41
41
|
/// @internal
|
|
42
|
-
a(this,
|
|
42
|
+
a(this, d, void 0);
|
|
43
43
|
/// @internal
|
|
44
44
|
a(this, h, void 0);
|
|
45
45
|
/// @internal
|
|
46
|
-
a(this,
|
|
47
|
-
a(this,
|
|
48
|
-
c(this,
|
|
49
|
-
const { state: r, composing:
|
|
50
|
-
if (o(this, i) ?? c(this, i,
|
|
46
|
+
a(this, g, void 0);
|
|
47
|
+
a(this, f, void 0);
|
|
48
|
+
c(this, f, (t, n) => {
|
|
49
|
+
const { state: r, composing: p } = t, { selection: l, doc: S } = r, { ranges: y } = l, x = Math.min(...y.map((m) => m.$from.pos)), P = Math.max(...y.map((m) => m.$to.pos)), C = n && n.doc.eq(S) && n.selection.eq(l);
|
|
50
|
+
if (o(this, i) ?? c(this, i, F(t.dom, {
|
|
51
51
|
trigger: "manual",
|
|
52
52
|
placement: "bottom-start",
|
|
53
53
|
interactive: !0,
|
|
54
|
-
|
|
54
|
+
delay: 0,
|
|
55
|
+
arrow: !1,
|
|
56
|
+
duration: 0,
|
|
57
|
+
...o(this, u),
|
|
55
58
|
content: this.element
|
|
56
|
-
})), !(
|
|
57
|
-
if (!o(this,
|
|
59
|
+
})), !(p || C)) {
|
|
60
|
+
if (!o(this, g).call(this, t, n)) {
|
|
58
61
|
this.hide();
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
61
64
|
o(this, i).setProps({
|
|
62
|
-
getReferenceClientRect: () =>
|
|
65
|
+
getReferenceClientRect: () => T(t, x, P)
|
|
63
66
|
}), this.show();
|
|
64
67
|
}
|
|
65
68
|
}), this.update = (t, n) => {
|
|
66
|
-
|
|
69
|
+
B(o(this, f), o(this, d))(t, n);
|
|
67
70
|
}, this.getContent = (t, n = (r) => r.type.name === "paragraph") => {
|
|
68
|
-
const { selection: r } = t.state, { empty: l } = r,
|
|
69
|
-
if (!(
|
|
70
|
-
return
|
|
71
|
+
const { selection: r } = t.state, { empty: p, $from: l } = r, S = t.state.selection instanceof M, y = this.element.contains(document.activeElement), x = !t.hasFocus() && !y, P = !t.editable, m = !_(n)(t.state.selection);
|
|
72
|
+
if (!(x || P || !p || !S || m))
|
|
73
|
+
return l.parent.textBetween(Math.max(0, l.parentOffset - 500), l.parentOffset, void 0, "");
|
|
71
74
|
}, this.destroy = () => {
|
|
72
75
|
var t;
|
|
73
76
|
(t = o(this, i)) == null || t.destroy();
|
|
@@ -77,11 +80,11 @@ class U {
|
|
|
77
80
|
}, this.hide = () => {
|
|
78
81
|
var t;
|
|
79
82
|
(t = o(this, i)) == null || t.hide();
|
|
80
|
-
}, this.getInstance = () => o(this, i), this.element =
|
|
83
|
+
}, this.getInstance = () => o(this, i), this.element = e.content, c(this, u, e.tippyOptions ?? {}), c(this, d, e.debounce ?? 200), c(this, g, e.shouldShow ?? b(this, k, w)), c(this, h, e.trigger ?? "/");
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
i = new WeakMap(),
|
|
84
|
-
const t = this.getContent(
|
|
86
|
+
i = new WeakMap(), u = new WeakMap(), d = new WeakMap(), h = new WeakMap(), g = new WeakMap(), f = new WeakMap(), k = new WeakSet(), w = function(e) {
|
|
87
|
+
const t = this.getContent(e);
|
|
85
88
|
if (!t)
|
|
86
89
|
return !1;
|
|
87
90
|
const n = t.at(-1);
|
package/lib/index.es.js.map
CHANGED
|
@@ -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 function 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 interface 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 /// The key trigger for shouldShow, '/' by default.\n trigger?: string | string[]\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 #trigger: string | string[]\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 this.#trigger = options.trigger ?? '/'\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 const target = currentTextBlockContent.at(-1)\n\n if (!target)\n return false\n\n return Array.isArray(this.#trigger) ? this.#trigger.includes(target) : this.#trigger === target\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
|
|
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 function 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 interface 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 /// The key trigger for shouldShow, '/' by default.\n trigger?: string | string[]\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 #trigger: string | string[]\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 this.#trigger = options.trigger ?? '/'\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 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 /// @internal\n #_shouldShow(view: EditorView): boolean {\n const currentTextBlockContent = this.getContent(view)\n\n if (!currentTextBlockContent)\n return false\n\n const target = currentTextBlockContent.at(-1)\n\n if (!target)\n return false\n\n return Array.isArray(this.#trigger) ? this.#trigger.includes(target) : this.#trigger === target\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, $from } = 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 $from.parent.textBetween(Math.max(0, $from.parentOffset - 500), $from.parentOffset, undefined, '\\uFFFC')\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","_trigger","_shouldShow","_onUpdate","__privateSet","view","prevState","state","composing","selection","doc","ranges","from","range","to","isSame","__privateGet","tippy","posToDOMRect","debounce","matchNode","node","empty","$from","isTextBlock","TextSelection","isSlashChildren","notHasFocus","isReadonly","isNotInParagraph","findParentNode","_a","__privateMethod","_shouldShow_fn","currentTextBlockContent","target"],"mappings":";;;;;;;;;;;;;;;AAiBO,SAASA,EAA6CC,GAAQ;AACnE,QAAMC,IAAYC,EAA+C,CAAI,GAAA,GAAGF,CAAE,aAAa,GACjFG,IAAcC,EAAO,CAACC,MAAQ;AAClC,UAAMC,IAAOD,EAAI,IAAIJ,EAAU,GAAG;AAClC,WAAO,IAAIM,EAAO;AAAA,MAChB,KAAK,IAAIC,EAAU,GAAGR,CAAE,QAAQ;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,CAAE;AAAA,EAAA,GAEnCG,EAAY,OAAO;AAAA,IACjB,SAAS;AAAA,IACT,aAAa,gBAAgBH,CAAE;AAAA,EAAA,GAG1BS;AACT;;ACdO,MAAMC,EAAc;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H,GAAWN,EAAQ,WAAW;AAAA,EACrC;AAmGF;AAvHEG,IAAA,eAGAC,IAAA,eAGAC,IAAA,eAGAC,IAAA,eAGAC,IAAA,eAWAC,IAAA,eAmCAN,IAAA,eAAAoC,aAAa5B,GAA2B;AAChC,QAAA6B,IAA0B,KAAK,WAAW7B,CAAI;AAEpD,MAAI,CAAC6B;AACI,WAAA;AAEH,QAAAC,IAASD,EAAwB,GAAG,EAAE;AAE5C,SAAKC,IAGE,MAAM,QAAQnB,EAAA,MAAKf,EAAQ,IAAIe,EAAA,MAAKf,GAAS,SAASkC,CAAM,IAAInB,EAAA,MAAKf,OAAakC,IAFhF;AAGX;"}
|
|
@@ -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;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,WAAW,oBAAoB;IAEnC,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;IAEnE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC5B;AAGD,qBAAa,aAAa;;IAExB,OAAO,EAAE,WAAW,CAAA;gBAiBR,OAAO,EAAE,oBAAoB;
|
|
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,WAAW,oBAAoB;IAEnC,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;IAEnE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC5B;AAGD,qBAAa,aAAa;;IAExB,OAAO,EAAE,WAAW,CAAA;gBAiBR,OAAO,EAAE,oBAAoB;IA2DzC,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.3.
|
|
4
|
+
"version": "7.3.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
"milkdown plugin"
|
|
14
14
|
],
|
|
15
15
|
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./lib/index.es.js",
|
|
19
|
+
"types": "./lib/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
16
22
|
"main": "./lib/index.es.js",
|
|
17
23
|
"files": [
|
|
18
24
|
"lib",
|
|
@@ -28,13 +34,13 @@
|
|
|
28
34
|
"lodash.debounce": "^4.0.8",
|
|
29
35
|
"tippy.js": "^6.3.7",
|
|
30
36
|
"tslib": "^2.5.0",
|
|
31
|
-
"@milkdown/exception": "7.3.
|
|
32
|
-
"@milkdown/utils": "7.3.
|
|
37
|
+
"@milkdown/exception": "7.3.4",
|
|
38
|
+
"@milkdown/utils": "7.3.4"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
35
|
-
"@milkdown/core": "7.3.
|
|
36
|
-
"@milkdown/ctx": "7.3.
|
|
37
|
-
"@milkdown/prose": "7.3.
|
|
41
|
+
"@milkdown/core": "7.3.4",
|
|
42
|
+
"@milkdown/ctx": "7.3.4",
|
|
43
|
+
"@milkdown/prose": "7.3.4"
|
|
38
44
|
},
|
|
39
45
|
"nx": {
|
|
40
46
|
"targets": {
|
package/src/slash-provider.ts
CHANGED
|
@@ -63,6 +63,9 @@ export class SlashProvider {
|
|
|
63
63
|
trigger: 'manual',
|
|
64
64
|
placement: 'bottom-start',
|
|
65
65
|
interactive: true,
|
|
66
|
+
delay: 0,
|
|
67
|
+
arrow: false,
|
|
68
|
+
duration: 0,
|
|
66
69
|
...this.#tippyOptions,
|
|
67
70
|
content: this.element,
|
|
68
71
|
})
|
|
@@ -108,7 +111,7 @@ export class SlashProvider {
|
|
|
108
111
|
/// Pass the `matchNode` function to determine whether the current node should be matched, by default, it will match the paragraph node.
|
|
109
112
|
getContent = (view: EditorView, matchNode: (node: Node) => boolean = node => node.type.name === 'paragraph'): string | undefined => {
|
|
110
113
|
const { selection } = view.state
|
|
111
|
-
const { empty } = selection
|
|
114
|
+
const { empty, $from } = selection
|
|
112
115
|
const isTextBlock = view.state.selection instanceof TextSelection
|
|
113
116
|
|
|
114
117
|
const isSlashChildren = this.element.contains(document.activeElement)
|
|
@@ -124,7 +127,7 @@ export class SlashProvider {
|
|
|
124
127
|
if (notHasFocus || isReadonly || !empty || !isTextBlock || isNotInParagraph)
|
|
125
128
|
return
|
|
126
129
|
|
|
127
|
-
return
|
|
130
|
+
return $from.parent.textBetween(Math.max(0, $from.parentOffset - 500), $from.parentOffset, undefined, '\uFFFC')
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
/// Destroy the slash.
|