@clevertask/scribe 0.0.11 → 0.0.13
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 +80 -4
- package/dist/assets/index.css +1 -1
- package/dist/components/Menu/BarMenu.js +21 -21
- package/dist/components/Menu/BubbleMenu.js +1 -1
- package/dist/components/Menu/Mobile/ListOptionBar.d.ts +6 -0
- package/dist/components/Menu/Mobile/ListOptionBar.js +37 -0
- package/dist/components/Scribe/extension/emoji/suggest.js +5 -6
- package/dist/components/Scribe/extension/extension-link.js +240 -244
- package/dist/components/Scribe/extension/extension-selectedText.js +1 -1
- package/dist/components/Scribe/extension/index.d.ts +1 -1
- package/dist/components/Scribe/extension/index.js +24 -25
- package/dist/components/Scribe/extension/slashCommand/SlashCommandList.js +5 -5
- package/dist/components/Scribe/extension/slashCommand/index.js +2 -2
- package/dist/components/Scribe/extension/slashCommand/items.js +6 -7
- package/dist/components/Scribe/extension/slashCommand/renderItems.js +10 -11
- package/dist/components/Scribe/index.d.ts +1 -0
- package/dist/components/Scribe/index.js +101 -79
- package/dist/index-BfaHEr44.js +159 -0
- package/dist/index-Bvgjhwaj.js +2349 -0
- package/dist/{index-CasgquAq.js → index-CWvaDN_2.js} +16838 -5196
- package/dist/{index-DeZ8laak.js → index-flsxByQS.js} +1587 -1527
- package/dist/main.css +4 -4
- package/dist/main.js +8 -6
- package/dist/marked.esm-H7n4rMcO.js +1554 -0
- package/dist/purify.es-DcWaZU6I.js +552 -0
- package/dist/turndown.browser.es-RmA_HBaI.js +649 -0
- package/dist/utils/convert-legacy-math-delimiters.d.ts +1 -0
- package/dist/utils/convert-legacy-math-delimiters.js +13 -0
- package/dist/utils/create-scribe-editor.js +7 -6
- package/dist/utils/html-to-markdown.js +7 -6
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +8 -6
- package/dist/utils/markdown-to-html.js +4 -3
- package/package.json +57 -53
- package/dist/browser-BJWkU9cc.js +0 -2106
- package/dist/components/Scribe/extension/math-extension.d.ts +0 -2
- package/dist/components/Scribe/extension/math-extension.js +0 -11770
- package/dist/index-BqFHWqw6.js +0 -156
- package/dist/index-C_aWB8qt.js +0 -2291
- package/dist/turndown.browser.es-C1wFFc_i.js +0 -1172
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ScribeProps } from '..';
|
|
2
|
-
export declare const initExtensions: (props: ScribeProps) => (import('@tiptap/core').Mark<import('@tiptap/extension-link').LinkOptions, any> | import('@tiptap/core').Extension<any, any> | import('@tiptap/core').Node<
|
|
2
|
+
export declare const initExtensions: (props: ScribeProps) => (import('@tiptap/core').Mark<import('@tiptap/extension-link').LinkOptions, any> | import('@tiptap/core').Extension<any, any> | import('@tiptap/core').Node<import('@tiptap/extension-table-row').TableRowOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-highlight').HighlightOptions, any>)[];
|
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import r from "./extension-link.js";
|
|
2
|
-
import {
|
|
3
|
-
import { S as
|
|
4
|
-
import
|
|
2
|
+
import { T as i, a as o, b as a, H as n, M as l, c as m, S as u, d as c, e as g, f as d, P as f, F as h, I as p, E as b, g as T } from "../../../index-CWvaDN_2.js";
|
|
3
|
+
import { S as y } from "../../../index-BfaHEr44.js";
|
|
4
|
+
import C from "./extension-selectedText.js";
|
|
5
5
|
import E from "./slashCommand/renderItems.js";
|
|
6
|
-
import { getSuggestionItems as
|
|
7
|
-
import { LatexExtension as H } from "./math-extension.js";
|
|
6
|
+
import { getSuggestionItems as H } from "./slashCommand/items.js";
|
|
8
7
|
import S from "./emoji/suggest.js";
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const A = (e) => [
|
|
9
|
+
u.configure({
|
|
11
10
|
dropcursor: {
|
|
12
11
|
width: 4,
|
|
13
12
|
color: "#ebf6fe"
|
|
14
13
|
}
|
|
15
14
|
}),
|
|
16
|
-
|
|
15
|
+
c.configure({
|
|
17
16
|
HTMLAttributes: {
|
|
18
17
|
class: "scribe-task-list"
|
|
19
18
|
}
|
|
20
19
|
}),
|
|
21
|
-
|
|
20
|
+
g.configure({
|
|
22
21
|
nested: !0
|
|
23
22
|
}),
|
|
24
|
-
|
|
23
|
+
d.configure({
|
|
25
24
|
resizable: !0
|
|
26
25
|
}),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
i,
|
|
27
|
+
o,
|
|
28
|
+
a,
|
|
29
|
+
f.configure({
|
|
31
30
|
showOnlyWhenEditable: !0,
|
|
32
31
|
includeChildren: !0,
|
|
33
32
|
showOnlyCurrent: !1,
|
|
@@ -35,31 +34,31 @@ const M = (e) => [
|
|
|
35
34
|
emptyNodeClass: "is-node-empty",
|
|
36
35
|
placeholder: ({ editor: t, node: s }) => t.isDestroyed ? "" : s.type.name === "heading" ? `Heading ${s.attrs.level}` : e.placeholderText || 'Type "/" for commands...'
|
|
37
36
|
}),
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
h.configure({ mode: "deepest", className: "has-focus" }),
|
|
38
|
+
y.configure({
|
|
40
39
|
slashSuggestion: {
|
|
41
|
-
items:
|
|
40
|
+
items: H,
|
|
42
41
|
render: E(e)
|
|
43
42
|
}
|
|
44
43
|
}),
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
n,
|
|
45
|
+
C,
|
|
47
46
|
r,
|
|
48
|
-
|
|
47
|
+
p.configure({
|
|
49
48
|
inline: !0,
|
|
50
49
|
HTMLAttributes: {
|
|
51
50
|
class: "scribe-image-node"
|
|
52
51
|
},
|
|
53
52
|
allowBase64: !0
|
|
54
53
|
}),
|
|
55
|
-
|
|
56
|
-
emojis:
|
|
54
|
+
b.configure({
|
|
55
|
+
emojis: T,
|
|
57
56
|
enableEmoticons: !0,
|
|
58
57
|
suggestion: S(e)
|
|
59
58
|
}),
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
l,
|
|
60
|
+
m
|
|
62
61
|
];
|
|
63
62
|
export {
|
|
64
|
-
|
|
63
|
+
A as initExtensions
|
|
65
64
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
|
-
import { h as n } from "../../../../index-
|
|
2
|
+
import { h as n } from "../../../../index-CWvaDN_2.js";
|
|
3
3
|
import "react";
|
|
4
|
-
import "../../../../
|
|
5
|
-
import "../../../../browser-
|
|
4
|
+
import "../../../../purify.es-DcWaZU6I.js";
|
|
5
|
+
import "../../../../turndown.browser.es-RmA_HBaI.js";
|
|
6
|
+
import "../../../../marked.esm-H7n4rMcO.js";
|
|
6
7
|
import "../../../../utils/is-in-viewport.js";
|
|
7
8
|
import "../extension-link.js";
|
|
8
|
-
import "../../../../index-
|
|
9
|
+
import "../../../../index-BfaHEr44.js";
|
|
9
10
|
import "../extension-selectedText.js";
|
|
10
|
-
import "../math-extension.js";
|
|
11
11
|
import "../emoji/EmojiList.js";
|
|
12
12
|
import "../../../../clsx-OuTLNxxd.js";
|
|
13
13
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../../../../index-
|
|
2
|
-
import { S as o, s as e } from "../../../../index-
|
|
1
|
+
import "../../../../index-flsxByQS.js";
|
|
2
|
+
import { S as o, s as e } from "../../../../index-BfaHEr44.js";
|
|
3
3
|
export {
|
|
4
4
|
o as SlashCommand,
|
|
5
5
|
e as slashMenuPluginKey
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
-
var
|
|
3
|
-
const
|
|
2
|
+
var o = /* @__PURE__ */ ((c) => (c.BASIC_BLOCKS = "Basic", c.ADVANCED_BLOCKS = "Advanced", c))(o || {});
|
|
3
|
+
const C = (c) => {
|
|
4
4
|
const { query: i } = c;
|
|
5
5
|
return [
|
|
6
6
|
{
|
|
@@ -145,15 +145,14 @@ const d = (c) => {
|
|
|
145
145
|
icon: /* @__PURE__ */ t("svg", { className: "slash-menu-icon", viewBox: "0 0 448 512", children: /* @__PURE__ */ t("path", { d: "M432 80c8.8 0 16 7.16 16 16 0 8.8-7.2 16-16 16H16c-8.836 0-16-7.2-16-16 0-8.84 7.164-16 16-16h416zm0 160c8.8 0 16 7.2 16 16s-7.2 16-16 16H144c-8.8 0-16-7.2-16-16s7.2-16 16-16h288zM128 416c0-8.8 7.2-16 16-16h288c8.8 0 16 7.2 16 16s-7.2 16-16 16H144c-8.8 0-16-7.2-16-16zM0 240c0-8.8 7.164-16 16-16 8.84 0 16 7.2 16 16v192c0 8.8-7.16 16-16 16-8.836 0-16-7.2-16-16V240z" }) })
|
|
146
146
|
}
|
|
147
147
|
].filter((e) => {
|
|
148
|
-
var s;
|
|
149
148
|
if (typeof i == "string" && i.length > 0) {
|
|
150
|
-
const
|
|
151
|
-
return e.title.toLowerCase().includes(
|
|
149
|
+
const s = i.toLowerCase();
|
|
150
|
+
return e.title.toLowerCase().includes(s) || e.description.toLowerCase().includes(s) || e.searchTerms?.some((n) => n.includes(s));
|
|
152
151
|
}
|
|
153
152
|
return !0;
|
|
154
153
|
});
|
|
155
154
|
};
|
|
156
155
|
export {
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
o as SuggestionItemType,
|
|
157
|
+
C as getSuggestionItems
|
|
159
158
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { R as
|
|
2
|
-
import { l as
|
|
3
|
-
const
|
|
4
|
-
let r, t = [], n, i = !
|
|
1
|
+
import { R as l, t as c } from "../../../../index-Bvgjhwaj.js";
|
|
2
|
+
import { l as o, h as d } from "../../../../index-CWvaDN_2.js";
|
|
3
|
+
const f = (s) => () => {
|
|
4
|
+
let r, t = [], n, i = !o.isEmpty(t);
|
|
5
5
|
return {
|
|
6
6
|
onStart: (e) => {
|
|
7
|
-
n = { ...e, ...
|
|
7
|
+
n = { ...e, ...s }, r = new l(d, {
|
|
8
8
|
props: n,
|
|
9
9
|
editor: e.editor
|
|
10
|
-
}), e.clientRect && (t =
|
|
10
|
+
}), e.clientRect && (t = c("body", {
|
|
11
11
|
getReferenceClientRect: e.clientRect,
|
|
12
12
|
appendTo: () => document.body,
|
|
13
13
|
content: r.element,
|
|
@@ -15,7 +15,7 @@ const y = (a) => () => {
|
|
|
15
15
|
interactive: !0,
|
|
16
16
|
trigger: "manual",
|
|
17
17
|
placement: "bottom-start"
|
|
18
|
-
}), i = !
|
|
18
|
+
}), i = !o.isEmpty(t));
|
|
19
19
|
},
|
|
20
20
|
onUpdate: (e) => {
|
|
21
21
|
n = e, r.updateProps(e), e.clientRect && i && t[0].setProps({
|
|
@@ -23,10 +23,9 @@ const y = (a) => () => {
|
|
|
23
23
|
});
|
|
24
24
|
},
|
|
25
25
|
onKeyDown(e) {
|
|
26
|
-
var o;
|
|
27
26
|
return e.event.key === "Escape" && i && !t[0].state.isDestroyed ? (t[0].hide(), !0) : (e.event.key === "Enter" && n.items.filter(
|
|
28
|
-
(
|
|
29
|
-
).length === 0 && this.onExit(),
|
|
27
|
+
(a) => a.title.toLowerCase().startsWith(n.query.toLowerCase())
|
|
28
|
+
).length === 0 && this.onExit(), r?.ref?.onKeyDown(e) || !1);
|
|
30
29
|
},
|
|
31
30
|
onExit() {
|
|
32
31
|
i && !t[0].state.isDestroyed && t[0].destroy();
|
|
@@ -34,5 +33,5 @@ const y = (a) => () => {
|
|
|
34
33
|
};
|
|
35
34
|
};
|
|
36
35
|
export {
|
|
37
|
-
|
|
36
|
+
f as default
|
|
38
37
|
};
|
|
@@ -29,5 +29,6 @@ export interface ScribeProps {
|
|
|
29
29
|
mainContainerClassName?: ClassValue;
|
|
30
30
|
onKeyDown?: KeyboardEventHandler;
|
|
31
31
|
darkMode?: boolean;
|
|
32
|
+
mobile?: boolean;
|
|
32
33
|
}
|
|
33
34
|
export declare const Scribe: import('react').ForwardRefExoticComponent<ScribeProps & import('react').RefAttributes<ScribeRef>>;
|
|
@@ -1,94 +1,116 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { c as
|
|
4
|
-
import { html2md as
|
|
5
|
-
import "../../
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
1
|
+
import { jsx as n, jsxs as P } from "react/jsx-runtime";
|
|
2
|
+
import O from "../Menu/BarMenu.js";
|
|
3
|
+
import { c as l } from "../../clsx-OuTLNxxd.js";
|
|
4
|
+
import { html2md as b } from "../../utils/html-to-markdown.js";
|
|
5
|
+
import "../../marked.esm-H7n4rMcO.js";
|
|
6
|
+
import "../../purify.es-DcWaZU6I.js";
|
|
7
|
+
import { E as R } from "../../index-flsxByQS.js";
|
|
8
|
+
import { initExtensions as T } from "./extension/index.js";
|
|
9
|
+
import { E as z } from "../../index-Bvgjhwaj.js";
|
|
10
|
+
import { forwardRef as J, useRef as D, useCallback as s, useImperativeHandle as F, useEffect as i } from "react";
|
|
11
|
+
import { ListOptionBar as I } from "../Menu/Mobile/ListOptionBar.js";
|
|
12
|
+
import '../../assets/index.css';const _ = J((p, g) => {
|
|
11
13
|
const {
|
|
12
|
-
autoFocus:
|
|
13
|
-
content:
|
|
14
|
-
editable:
|
|
15
|
-
editorProps:
|
|
16
|
-
extensions:
|
|
17
|
-
onContentChange:
|
|
18
|
-
showBarMenu:
|
|
19
|
-
editorContentStyle:
|
|
20
|
-
editorContentClassName:
|
|
21
|
-
mainContainerStyle:
|
|
22
|
-
mainContainerClassName:
|
|
23
|
-
onKeyDown:
|
|
24
|
-
externalEditor:
|
|
25
|
-
darkMode:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
autoFocus: u = !1,
|
|
15
|
+
content: f,
|
|
16
|
+
editable: o = !0,
|
|
17
|
+
editorProps: C,
|
|
18
|
+
extensions: x,
|
|
19
|
+
onContentChange: m,
|
|
20
|
+
showBarMenu: h = !0,
|
|
21
|
+
editorContentStyle: w,
|
|
22
|
+
editorContentClassName: y,
|
|
23
|
+
mainContainerStyle: M,
|
|
24
|
+
mainContainerClassName: N,
|
|
25
|
+
onKeyDown: j,
|
|
26
|
+
externalEditor: k,
|
|
27
|
+
darkMode: a,
|
|
28
|
+
mobile: v
|
|
29
|
+
} = p, c = D(k || null), d = s(
|
|
30
|
+
({ editor: e }) => {
|
|
31
|
+
const r = e.getHTML(), H = e.getJSON(), L = !o;
|
|
32
|
+
m && m({
|
|
33
|
+
jsonContent: e.isEmpty ? "" : H,
|
|
34
|
+
htmlContent: e.isEmpty ? "" : r,
|
|
35
|
+
markdownContent: e.isEmpty ? "" : b(r),
|
|
36
|
+
source: L ? "programmatic" : "user"
|
|
34
37
|
});
|
|
35
38
|
},
|
|
36
|
-
[
|
|
39
|
+
[o, m]
|
|
37
40
|
);
|
|
38
|
-
|
|
39
|
-
...
|
|
40
|
-
editable:
|
|
41
|
-
extensions: [...
|
|
41
|
+
c.current || (c.current = new R({
|
|
42
|
+
...C,
|
|
43
|
+
editable: o,
|
|
44
|
+
extensions: [...T(p), ...x ?? []],
|
|
42
45
|
editorProps: {
|
|
43
46
|
attributes: {
|
|
44
47
|
class: "scribe"
|
|
45
48
|
},
|
|
46
|
-
...
|
|
49
|
+
...C?.editorProps
|
|
47
50
|
}
|
|
48
51
|
}));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
}, []), S =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const t = c.current, E = s(() => {
|
|
53
|
+
t?.commands.setContent("");
|
|
54
|
+
}, []), S = s(
|
|
55
|
+
(e) => {
|
|
56
|
+
const r = {
|
|
57
|
+
html: () => t?.getHTML(),
|
|
58
|
+
json: () => t?.getJSON(),
|
|
59
|
+
markdown: () => b(t?.getHTML() || "")
|
|
60
|
+
};
|
|
61
|
+
return t?.isEmpty ? "" : r[e]?.();
|
|
62
|
+
},
|
|
63
|
+
[]
|
|
64
|
+
), B = s((e) => {
|
|
65
|
+
t?.commands.setContent(e);
|
|
61
66
|
}, []);
|
|
62
|
-
return
|
|
63
|
-
resetContent:
|
|
64
|
-
setContent:
|
|
67
|
+
return F(g, () => ({
|
|
68
|
+
resetContent: E,
|
|
69
|
+
setContent: B,
|
|
65
70
|
getContent: S,
|
|
66
|
-
editor:
|
|
67
|
-
}), [
|
|
68
|
-
|
|
69
|
-
}, [
|
|
70
|
-
|
|
71
|
-
}, [
|
|
72
|
-
|
|
73
|
-
}), [
|
|
74
|
-
|
|
75
|
-
}, [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
editor: t
|
|
72
|
+
}), [E]), i(() => {
|
|
73
|
+
t?.commands.setContent(f || "");
|
|
74
|
+
}, [f]), i(() => {
|
|
75
|
+
t?.setEditable(!!o);
|
|
76
|
+
}, [o]), i(() => (t.off("update"), t.on("update", d), () => {
|
|
77
|
+
t.off("update", d);
|
|
78
|
+
}), [d]), i(() => {
|
|
79
|
+
u && t?.commands.focus("end");
|
|
80
|
+
}, [u]), /* @__PURE__ */ n(
|
|
81
|
+
"div",
|
|
82
|
+
{
|
|
83
|
+
className: l("scribe-wrapper", N),
|
|
84
|
+
style: M,
|
|
85
|
+
children: /* @__PURE__ */ P(
|
|
86
|
+
"div",
|
|
87
|
+
{
|
|
88
|
+
className: l(
|
|
89
|
+
o && "rounded-lg border",
|
|
90
|
+
a ? "border-zinc-700" : "border-zinc-200"
|
|
91
|
+
),
|
|
92
|
+
children: [
|
|
93
|
+
t && h && /* @__PURE__ */ n(O, { editor: t, darkMode: !!a }),
|
|
94
|
+
/* @__PURE__ */ n(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
className: l(
|
|
98
|
+
"prose max-w-none",
|
|
99
|
+
o && "w-full p-[16px]",
|
|
100
|
+
a && "prose-invert",
|
|
101
|
+
y
|
|
102
|
+
),
|
|
103
|
+
style: w,
|
|
104
|
+
children: /* @__PURE__ */ n(z, { editor: t, onKeyDown: j })
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
v && /* @__PURE__ */ n(I, { editor: t })
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
);
|
|
91
113
|
});
|
|
92
114
|
export {
|
|
93
|
-
|
|
115
|
+
_ as Scribe
|
|
94
116
|
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { P as L, b as U, D as z, c as G, e as H, a as J } from "./index-flsxByQS.js";
|
|
2
|
+
function Q(y) {
|
|
3
|
+
var i;
|
|
4
|
+
const { char: f, allowSpaces: D, allowToIncludeChar: I, allowedPrefixes: v, startOfLine: K, $position: g } = y, P = D && !I, m = H(f), B = new RegExp(`\\s${m}$`), C = K ? "^" : "", M = I ? "" : m, S = P ? new RegExp(`${C}${m}.*?(?=\\s${M}|$)`, "gm") : new RegExp(`${C}(?:^)?${m}[^\\s${M}]*`, "gm"), p = ((i = g.nodeBefore) === null || i === void 0 ? void 0 : i.isText) && g.nodeBefore.text;
|
|
5
|
+
if (!p)
|
|
6
|
+
return null;
|
|
7
|
+
const k = g.pos - p.length, n = Array.from(p.matchAll(S)).pop();
|
|
8
|
+
if (!n || n.input === void 0 || n.index === void 0)
|
|
9
|
+
return null;
|
|
10
|
+
const e = n.input.slice(Math.max(0, n.index - 1), n.index), $ = new RegExp(`^[${v?.join("")}\0]?$`).test(e);
|
|
11
|
+
if (v !== null && !$)
|
|
12
|
+
return null;
|
|
13
|
+
const o = k + n.index;
|
|
14
|
+
let a = o + n[0].length;
|
|
15
|
+
return P && B.test(p.slice(a - 1, a + 1)) && (n[0] += " ", a += 1), o < g.pos && a >= g.pos ? {
|
|
16
|
+
range: {
|
|
17
|
+
from: o,
|
|
18
|
+
to: a
|
|
19
|
+
},
|
|
20
|
+
query: n[0].slice(f.length),
|
|
21
|
+
text: n[0]
|
|
22
|
+
} : null;
|
|
23
|
+
}
|
|
24
|
+
const V = new L("suggestion");
|
|
25
|
+
function W({ pluginKey: y = V, editor: i, char: f = "@", allowSpaces: D = !1, allowToIncludeChar: I = !1, allowedPrefixes: v = [" "], startOfLine: K = !1, decorationTag: g = "span", decorationClass: P = "suggestion", decorationContent: m = "", decorationEmptyClass: B = "is-empty", command: C = () => null, items: M = () => [], render: S = () => ({}), allow: p = () => !0, findSuggestionMatch: k = Q }) {
|
|
26
|
+
let n;
|
|
27
|
+
const e = S?.(), $ = new U({
|
|
28
|
+
key: y,
|
|
29
|
+
view() {
|
|
30
|
+
return {
|
|
31
|
+
update: async (o, a) => {
|
|
32
|
+
var l, c, r, u, d, w, h;
|
|
33
|
+
const t = (l = this.key) === null || l === void 0 ? void 0 : l.getState(a), s = (c = this.key) === null || c === void 0 ? void 0 : c.getState(o.state), q = t.active && s.active && t.range.from !== s.range.from, b = !t.active && s.active, j = t.active && !s.active, A = !b && !j && t.query !== s.query, _ = b || q && A, R = A || q, N = j || q && A;
|
|
34
|
+
if (!_ && !R && !N)
|
|
35
|
+
return;
|
|
36
|
+
const x = N && !_ ? t : s, F = o.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);
|
|
37
|
+
n = {
|
|
38
|
+
editor: i,
|
|
39
|
+
range: x.range,
|
|
40
|
+
query: x.query,
|
|
41
|
+
text: x.text,
|
|
42
|
+
items: [],
|
|
43
|
+
command: (E) => C({
|
|
44
|
+
editor: i,
|
|
45
|
+
range: x.range,
|
|
46
|
+
props: E
|
|
47
|
+
}),
|
|
48
|
+
decorationNode: F,
|
|
49
|
+
// virtual node for popper.js or tippy.js
|
|
50
|
+
// this can be used for building popups without a DOM node
|
|
51
|
+
clientRect: F ? () => {
|
|
52
|
+
var E;
|
|
53
|
+
const { decorationId: T } = (E = this.key) === null || E === void 0 ? void 0 : E.getState(i.state), O = o.dom.querySelector(`[data-decoration-id="${T}"]`);
|
|
54
|
+
return O?.getBoundingClientRect() || null;
|
|
55
|
+
} : null
|
|
56
|
+
}, _ && ((r = e?.onBeforeStart) === null || r === void 0 || r.call(e, n)), R && ((u = e?.onBeforeUpdate) === null || u === void 0 || u.call(e, n)), (R || _) && (n.items = await M({
|
|
57
|
+
editor: i,
|
|
58
|
+
query: x.query
|
|
59
|
+
})), N && ((d = e?.onExit) === null || d === void 0 || d.call(e, n)), R && ((w = e?.onUpdate) === null || w === void 0 || w.call(e, n)), _ && ((h = e?.onStart) === null || h === void 0 || h.call(e, n));
|
|
60
|
+
},
|
|
61
|
+
destroy: () => {
|
|
62
|
+
var o;
|
|
63
|
+
n && ((o = e?.onExit) === null || o === void 0 || o.call(e, n));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
state: {
|
|
68
|
+
// Initialize the plugin's internal state.
|
|
69
|
+
init() {
|
|
70
|
+
return {
|
|
71
|
+
active: !1,
|
|
72
|
+
range: {
|
|
73
|
+
from: 0,
|
|
74
|
+
to: 0
|
|
75
|
+
},
|
|
76
|
+
query: null,
|
|
77
|
+
text: null,
|
|
78
|
+
composing: !1
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
// Apply changes to the plugin state from a view transaction.
|
|
82
|
+
apply(o, a, l, c) {
|
|
83
|
+
const { isEditable: r } = i, { composing: u } = i.view, { selection: d } = o, { empty: w, from: h } = d, t = { ...a };
|
|
84
|
+
if (t.composing = u, r && (w || i.view.composing)) {
|
|
85
|
+
(h < a.range.from || h > a.range.to) && !u && !a.composing && (t.active = !1);
|
|
86
|
+
const s = k({
|
|
87
|
+
char: f,
|
|
88
|
+
allowSpaces: D,
|
|
89
|
+
allowToIncludeChar: I,
|
|
90
|
+
allowedPrefixes: v,
|
|
91
|
+
startOfLine: K,
|
|
92
|
+
$position: d.$from
|
|
93
|
+
}), q = `id_${Math.floor(Math.random() * 4294967295)}`;
|
|
94
|
+
s && p({
|
|
95
|
+
editor: i,
|
|
96
|
+
state: c,
|
|
97
|
+
range: s.range,
|
|
98
|
+
isActive: a.active
|
|
99
|
+
}) ? (t.active = !0, t.decorationId = a.decorationId ? a.decorationId : q, t.range = s.range, t.query = s.query, t.text = s.text) : t.active = !1;
|
|
100
|
+
} else
|
|
101
|
+
t.active = !1;
|
|
102
|
+
return t.active || (t.decorationId = null, t.range = { from: 0, to: 0 }, t.query = null, t.text = null), t;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
props: {
|
|
106
|
+
// Call the keydown hook if suggestion is active.
|
|
107
|
+
handleKeyDown(o, a) {
|
|
108
|
+
var l;
|
|
109
|
+
const { active: c, range: r } = $.getState(o.state);
|
|
110
|
+
return c && ((l = e?.onKeyDown) === null || l === void 0 ? void 0 : l.call(e, { view: o, event: a, range: r })) || !1;
|
|
111
|
+
},
|
|
112
|
+
// Setup decorator on the currently active suggestion.
|
|
113
|
+
decorations(o) {
|
|
114
|
+
const { active: a, range: l, decorationId: c, query: r } = $.getState(o);
|
|
115
|
+
if (!a)
|
|
116
|
+
return null;
|
|
117
|
+
const u = !r?.length, d = [P];
|
|
118
|
+
return u && d.push(B), z.create(o.doc, [
|
|
119
|
+
G.inline(l.from, l.to, {
|
|
120
|
+
nodeName: g,
|
|
121
|
+
class: d.join(" "),
|
|
122
|
+
"data-decoration-id": c,
|
|
123
|
+
"data-decoration-content": m
|
|
124
|
+
})
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return $;
|
|
130
|
+
}
|
|
131
|
+
const X = new L("slashSuggestion"), Z = J.create({
|
|
132
|
+
name: "slashCommand",
|
|
133
|
+
addOptions() {
|
|
134
|
+
return {
|
|
135
|
+
...this.parent?.(),
|
|
136
|
+
slashSuggestion: {
|
|
137
|
+
char: "/",
|
|
138
|
+
startOfLine: !0,
|
|
139
|
+
command: ({ editor: y, range: i, props: f }) => {
|
|
140
|
+
f.command({ editor: y, range: i, props: f });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
addProseMirrorPlugins() {
|
|
146
|
+
return [
|
|
147
|
+
W({
|
|
148
|
+
pluginKey: X,
|
|
149
|
+
...this.options.slashSuggestion,
|
|
150
|
+
editor: this.editor
|
|
151
|
+
})
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
export {
|
|
156
|
+
Z as S,
|
|
157
|
+
W as a,
|
|
158
|
+
X as s
|
|
159
|
+
};
|