-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.ts
105 lines (95 loc) · 3 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// NOTE: [guide] Add a `Tool` by creating a new file in this directory, importing it and adding it to the `tools: Tool[]` array below! If you import a tiptap extension that also renders content, make sure to add it to /shared/extensions.ts as well!
import heading from "./heading";
import history from "./history";
import relationBlock from "./relation-block";
import relationInlineBlock from "./relation-inline-block";
import paragraph from "./paragraph";
import codeBlock from "./code-block";
import bold from "./bold";
import italic from "./italic";
import strike from "./strike";
import code from "./code";
import subscript from "./subscript";
import superscript from "./superscript";
import link from "./link";
import relationMark from "./relation-mark";
import hardBreak from "./hard-break";
import horizontalRule from "./horizontal-rule";
import textAlign from "./text-align";
import bulletList from "./bullet-list";
import orderedList from "./ordered-list";
import blockquote from "./blockquote";
import table from "./table";
import fullscreen from "./fullscreen";
import type { AnyExtension } from "@tiptap/core";
import type { Tool, ToolSelection, InterfaceOption } from "../types";
const tools: Tool[] = [
relationBlock,
relationInlineBlock,
paragraph,
codeBlock,
heading(1),
heading(2),
heading(3),
heading(4),
heading(5),
heading(6),
bold,
italic,
strike,
code,
subscript,
superscript,
link.add,
link.remove,
link.auto,
relationMark,
hardBreak,
horizontalRule,
textAlign,
bulletList,
orderedList,
blockquote,
table,
history.undo,
history.redo,
fullscreen,
];
export const selectedTools = (
selection: ToolSelection,
includeRelationNodes = false
) =>
tools.filter(
({ key }) =>
selection.indexOf(key) >= 0 ||
(includeRelationNodes &&
[
"relation-block",
"relation-inline-block",
"relation-mark",
].indexOf(key) >= 0)
);
export const toolsExtensions = (selection: ToolSelection): AnyExtension[] => {
const toolsExtensions: AnyExtension[] = [];
const uniqueNames: string[] = [];
selectedTools(selection).forEach(({ extension }) =>
extension.forEach((item) => {
const extensionItem =
typeof item === "function" ? item(selection) : item;
const extensionNotExists =
uniqueNames.indexOf(extensionItem.name) < 0;
if (extensionNotExists) {
uniqueNames.push(extensionItem.name);
toolsExtensions.push(extensionItem);
}
})
);
return toolsExtensions;
};
const optionalTools: Tool[] = tools.filter((tool) => !tool.excludeFromOptions);
export const interfaceOptions: InterfaceOption[] = optionalTools.map(
({ key, name }) => ({ text: name, value: key })
);
export const interfaceOptionsDefault: string[] = optionalTools.map(
({ key }) => key
);