@meta-1/editor 0.0.27
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 +458 -0
- package/package.json +100 -0
- package/src/editor/constants.tsx +66 -0
- package/src/editor/container.css +46 -0
- package/src/editor/control/character-count/index.tsx +39 -0
- package/src/editor/control/drag-handle/index.tsx +85 -0
- package/src/editor/control/drag-handle/use.content.actions.ts +71 -0
- package/src/editor/control/drag-handle/use.data.ts +29 -0
- package/src/editor/control/drag-handle/use.handle.id.ts +6 -0
- package/src/editor/control/index.tsx +35 -0
- package/src/editor/editor.css +626 -0
- package/src/editor/extension/block-quote-figure/BlockquoteFigure.ts +73 -0
- package/src/editor/extension/block-quote-figure/Quote/Quote.ts +31 -0
- package/src/editor/extension/block-quote-figure/Quote/index.ts +1 -0
- package/src/editor/extension/block-quote-figure/QuoteCaption/QuoteCaption.ts +54 -0
- package/src/editor/extension/block-quote-figure/QuoteCaption/index.ts +1 -0
- package/src/editor/extension/block-quote-figure/index.ts +1 -0
- package/src/editor/extension/document/index.ts +5 -0
- package/src/editor/extension/figcaption/Figcaption.ts +90 -0
- package/src/editor/extension/figcaption/index.ts +1 -0
- package/src/editor/extension/figure/Figure.ts +62 -0
- package/src/editor/extension/figure/index.ts +1 -0
- package/src/editor/extension/font-size/FontSize.ts +64 -0
- package/src/editor/extension/font-size/index.ts +1 -0
- package/src/editor/extension/global-drag-handle/clipboard-serializer.ts +28 -0
- package/src/editor/extension/global-drag-handle/index.ts +377 -0
- package/src/editor/extension/heading/index.ts +13 -0
- package/src/editor/extension/horizontal-rule/HorizontalRule.ts +10 -0
- package/src/editor/extension/horizontal-rule/index.ts +1 -0
- package/src/editor/extension/image/index.ts +5 -0
- package/src/editor/extension/image-block/ImageBlock.ts +103 -0
- package/src/editor/extension/image-block/components/ImageBlockMenu.tsx +100 -0
- package/src/editor/extension/image-block/components/ImageBlockView.tsx +47 -0
- package/src/editor/extension/image-block/components/ImageBlockWidth.tsx +40 -0
- package/src/editor/extension/image-block/index.ts +1 -0
- package/src/editor/extension/image-upload/ImageUpload.ts +58 -0
- package/src/editor/extension/image-upload/index.ts +1 -0
- package/src/editor/extension/image-upload/view/ImageUpload.tsx +27 -0
- package/src/editor/extension/image-upload/view/ImageUploader.tsx +64 -0
- package/src/editor/extension/image-upload/view/hooks.ts +109 -0
- package/src/editor/extension/image-upload/view/index.tsx +1 -0
- package/src/editor/extension/index.ts +30 -0
- package/src/editor/extension/link/Link.ts +39 -0
- package/src/editor/extension/link/index.ts +1 -0
- package/src/editor/extension/multi-column/Column.ts +33 -0
- package/src/editor/extension/multi-column/Columns.ts +65 -0
- package/src/editor/extension/multi-column/index.ts +2 -0
- package/src/editor/extension/multi-column/menus/ColumnsMenu.tsx +82 -0
- package/src/editor/extension/multi-column/menus/index.ts +1 -0
- package/src/editor/extension/selection/Selection.ts +36 -0
- package/src/editor/extension/selection/index.ts +1 -0
- package/src/editor/extension/slash-command/MenuList.tsx +145 -0
- package/src/editor/extension/slash-command/groups.ts +153 -0
- package/src/editor/extension/slash-command/index.ts +277 -0
- package/src/editor/extension/slash-command/types.ts +25 -0
- package/src/editor/extension/table/Cell.ts +126 -0
- package/src/editor/extension/table/Header.ts +89 -0
- package/src/editor/extension/table/Row.ts +8 -0
- package/src/editor/extension/table/Table.ts +9 -0
- package/src/editor/extension/table/index.ts +4 -0
- package/src/editor/extension/table/menus/TableColumn/index.tsx +73 -0
- package/src/editor/extension/table/menus/TableColumn/utils.ts +38 -0
- package/src/editor/extension/table/menus/TableRow/index.tsx +74 -0
- package/src/editor/extension/table/menus/TableRow/utils.ts +38 -0
- package/src/editor/extension/table/menus/index.tsx +2 -0
- package/src/editor/extension/table/utils.ts +258 -0
- package/src/editor/extension/task-item/index.ts +1 -0
- package/src/editor/extension/task-item/task-item.ts +225 -0
- package/src/editor/extension/task-list/index.ts +1 -0
- package/src/editor/extension/task-list/task-list.ts +81 -0
- package/src/editor/extension/trailing-node/index.ts +1 -0
- package/src/editor/extension/trailing-node/trailing-node.ts +70 -0
- package/src/editor/extension/unique-id/index.ts +1 -0
- package/src/editor/extension/unique-id/uniqueId.ts +123 -0
- package/src/editor/hooks.ts +264 -0
- package/src/editor/index.tsx +53 -0
- package/src/editor/menus/LinkMenu/LinkMenu.tsx +75 -0
- package/src/editor/menus/LinkMenu/index.tsx +1 -0
- package/src/editor/menus/TextMenu/TextMenu.tsx +193 -0
- package/src/editor/menus/TextMenu/components/AIDropdown.tsx +140 -0
- package/src/editor/menus/TextMenu/components/ContentTypePicker.tsx +76 -0
- package/src/editor/menus/TextMenu/components/EditLinkPopover.tsx +25 -0
- package/src/editor/menus/TextMenu/components/FontFamilyPicker.tsx +84 -0
- package/src/editor/menus/TextMenu/components/FontSizePicker.tsx +56 -0
- package/src/editor/menus/TextMenu/hooks/useTextmenuCommands.ts +96 -0
- package/src/editor/menus/TextMenu/hooks/useTextmenuContentTypes.ts +86 -0
- package/src/editor/menus/TextMenu/hooks/useTextmenuStates.ts +50 -0
- package/src/editor/menus/TextMenu/index.tsx +2 -0
- package/src/editor/menus/types.ts +21 -0
- package/src/editor/panels/Colorpicker/ColorButton.tsx +35 -0
- package/src/editor/panels/Colorpicker/Colorpicker.tsx +67 -0
- package/src/editor/panels/Colorpicker/index.tsx +2 -0
- package/src/editor/panels/LinkEditorPanel/LinkEditorPanel.tsx +76 -0
- package/src/editor/panels/LinkEditorPanel/index.tsx +1 -0
- package/src/editor/panels/LinkPreviewPanel/LinkPreviewPanel.tsx +32 -0
- package/src/editor/panels/LinkPreviewPanel/index.tsx +1 -0
- package/src/editor/panels/index.tsx +3 -0
- package/src/editor/types.tsx +38 -0
- package/src/editor/ui/Button/Button.tsx +70 -0
- package/src/editor/ui/Button/index.tsx +2 -0
- package/src/editor/ui/Dropdown/Dropdown.tsx +39 -0
- package/src/editor/ui/Dropdown/index.tsx +1 -0
- package/src/editor/ui/Icon.tsx +21 -0
- package/src/editor/ui/Loader/Loader.tsx +39 -0
- package/src/editor/ui/Loader/index.ts +1 -0
- package/src/editor/ui/Loader/types.ts +7 -0
- package/src/editor/ui/Panel/index.tsx +109 -0
- package/src/editor/ui/PopoverMenu.tsx +127 -0
- package/src/editor/ui/Spinner/Spinner.tsx +10 -0
- package/src/editor/ui/Spinner/index.tsx +1 -0
- package/src/editor/ui/Surface.tsx +27 -0
- package/src/editor/ui/Textarea/Textarea.tsx +20 -0
- package/src/editor/ui/Textarea/index.tsx +1 -0
- package/src/editor/ui/Toggle/Toggle.tsx +39 -0
- package/src/editor/ui/Toggle/index.tsx +1 -0
- package/src/editor/ui/Toolbar.tsx +107 -0
- package/src/editor/ui/Tooltip/index.tsx +77 -0
- package/src/editor/ui/Tooltip/types.ts +17 -0
- package/src/editor/utils/cssVar.ts +14 -0
- package/src/editor/utils/getRenderContainer.ts +39 -0
- package/src/editor/utils/index.ts +16 -0
- package/src/editor/utils/isCustomNodeSelected.ts +47 -0
- package/src/editor/utils/isTextSelected.ts +25 -0
- package/src/editor/utils/locale.ts +5 -0
- package/src/editor/viewer/index.tsx +26 -0
- package/src/globals.css +1 -0
- package/src/index.ts +7 -0
- package/src/locales/en-us.ts +133 -0
- package/src/locales/zh-cn.ts +133 -0
- package/src/locales/zh-tw.ts +133 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
+
|
|
3
|
+
export const Column = Node.create({
|
|
4
|
+
name: "column",
|
|
5
|
+
|
|
6
|
+
content: "block+",
|
|
7
|
+
|
|
8
|
+
isolating: true,
|
|
9
|
+
|
|
10
|
+
addAttributes() {
|
|
11
|
+
return {
|
|
12
|
+
position: {
|
|
13
|
+
default: "",
|
|
14
|
+
parseHTML: (element) => element.getAttribute("data-position"),
|
|
15
|
+
renderHTML: (attributes) => ({ "data-position": attributes.position }),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
renderHTML({ HTMLAttributes }) {
|
|
21
|
+
return ["div", mergeAttributes(HTMLAttributes, { "data-type": "column" }), 0];
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
parseHTML() {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
tag: 'div[data-type="column"]',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export default Column;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Node } from "@tiptap/core";
|
|
2
|
+
|
|
3
|
+
export enum ColumnLayout {
|
|
4
|
+
SidebarLeft = "sidebar-left",
|
|
5
|
+
SidebarRight = "sidebar-right",
|
|
6
|
+
TwoColumn = "two-column",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module "@tiptap/core" {
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
columns: {
|
|
12
|
+
setColumns: () => ReturnType;
|
|
13
|
+
setLayout: (layout: ColumnLayout) => ReturnType;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Columns = Node.create({
|
|
19
|
+
name: "columns",
|
|
20
|
+
|
|
21
|
+
group: "columns",
|
|
22
|
+
|
|
23
|
+
content: "column column",
|
|
24
|
+
|
|
25
|
+
defining: true,
|
|
26
|
+
|
|
27
|
+
isolating: true,
|
|
28
|
+
|
|
29
|
+
addAttributes() {
|
|
30
|
+
return {
|
|
31
|
+
layout: {
|
|
32
|
+
default: ColumnLayout.TwoColumn,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
addCommands() {
|
|
38
|
+
return {
|
|
39
|
+
setColumns:
|
|
40
|
+
() =>
|
|
41
|
+
({ commands }) =>
|
|
42
|
+
commands.insertContent(
|
|
43
|
+
`<div data-type="columns"><div data-type="column" data-position="left"><p></p></div><div data-type="column" data-position="right"><p></p></div></div>`,
|
|
44
|
+
),
|
|
45
|
+
setLayout:
|
|
46
|
+
(layout: ColumnLayout) =>
|
|
47
|
+
({ commands }) =>
|
|
48
|
+
commands.updateAttributes("columns", { layout }),
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
renderHTML({ HTMLAttributes }) {
|
|
53
|
+
return ["div", { "data-type": "columns", class: `layout-${HTMLAttributes.layout}` }, 0];
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
parseHTML() {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
tag: 'div[data-type="columns"]',
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export default Columns;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { BubbleMenu as BaseBubbleMenu } from "@tiptap/react";
|
|
3
|
+
import { sticky } from "tippy.js";
|
|
4
|
+
import { v4 as uuid } from "uuid";
|
|
5
|
+
|
|
6
|
+
import type { MenuProps } from "../../../menus/types";
|
|
7
|
+
import { Icon } from "../../../ui/Icon";
|
|
8
|
+
import { Toolbar } from "../../../ui/Toolbar";
|
|
9
|
+
import { getRenderContainer } from "../../../utils";
|
|
10
|
+
import { ColumnLayout } from "../Columns";
|
|
11
|
+
|
|
12
|
+
export const ColumnsMenu = ({ editor, appendTo }: MenuProps) => {
|
|
13
|
+
const getReferenceClientRect = useCallback(() => {
|
|
14
|
+
const renderContainer = getRenderContainer(editor, "columns");
|
|
15
|
+
const rect = renderContainer?.getBoundingClientRect() || new DOMRect(-1000, -1000, 0, 0);
|
|
16
|
+
|
|
17
|
+
return rect;
|
|
18
|
+
}, [editor]);
|
|
19
|
+
|
|
20
|
+
const shouldShow = useCallback(() => {
|
|
21
|
+
const isColumns = editor.isActive("columns");
|
|
22
|
+
return isColumns;
|
|
23
|
+
}, [editor]);
|
|
24
|
+
|
|
25
|
+
const onColumnLeft = useCallback(() => {
|
|
26
|
+
editor.chain().focus().setLayout(ColumnLayout.SidebarLeft).run();
|
|
27
|
+
}, [editor]);
|
|
28
|
+
|
|
29
|
+
const onColumnRight = useCallback(() => {
|
|
30
|
+
editor.chain().focus().setLayout(ColumnLayout.SidebarRight).run();
|
|
31
|
+
}, [editor]);
|
|
32
|
+
|
|
33
|
+
const onColumnTwo = useCallback(() => {
|
|
34
|
+
editor.chain().focus().setLayout(ColumnLayout.TwoColumn).run();
|
|
35
|
+
}, [editor]);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<BaseBubbleMenu
|
|
39
|
+
editor={editor}
|
|
40
|
+
pluginKey={`columnsMenu-${uuid()}`}
|
|
41
|
+
shouldShow={shouldShow}
|
|
42
|
+
tippyOptions={{
|
|
43
|
+
zIndex: 40,
|
|
44
|
+
offset: [0, 8],
|
|
45
|
+
popperOptions: {
|
|
46
|
+
modifiers: [{ name: "flip", enabled: false }],
|
|
47
|
+
},
|
|
48
|
+
getReferenceClientRect,
|
|
49
|
+
appendTo: () => appendTo?.current,
|
|
50
|
+
plugins: [sticky],
|
|
51
|
+
sticky: "popper",
|
|
52
|
+
}}
|
|
53
|
+
updateDelay={0}
|
|
54
|
+
>
|
|
55
|
+
<Toolbar.Wrapper>
|
|
56
|
+
<Toolbar.Button
|
|
57
|
+
active={editor.isActive("columns", { layout: ColumnLayout.SidebarLeft })}
|
|
58
|
+
onClick={onColumnLeft}
|
|
59
|
+
tooltip="Sidebar left"
|
|
60
|
+
>
|
|
61
|
+
<Icon name="PanelLeft" />
|
|
62
|
+
</Toolbar.Button>
|
|
63
|
+
<Toolbar.Button
|
|
64
|
+
active={editor.isActive("columns", { layout: ColumnLayout.TwoColumn })}
|
|
65
|
+
onClick={onColumnTwo}
|
|
66
|
+
tooltip="Two columns"
|
|
67
|
+
>
|
|
68
|
+
<Icon name="Columns2" />
|
|
69
|
+
</Toolbar.Button>
|
|
70
|
+
<Toolbar.Button
|
|
71
|
+
active={editor.isActive("columns", { layout: ColumnLayout.SidebarRight })}
|
|
72
|
+
onClick={onColumnRight}
|
|
73
|
+
tooltip="Sidebar right"
|
|
74
|
+
>
|
|
75
|
+
<Icon name="PanelRight" />
|
|
76
|
+
</Toolbar.Button>
|
|
77
|
+
</Toolbar.Wrapper>
|
|
78
|
+
</BaseBubbleMenu>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default ColumnsMenu;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ColumnsMenu } from "./ColumnsMenu";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
3
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
4
|
+
|
|
5
|
+
export const Selection = Extension.create({
|
|
6
|
+
name: "selection",
|
|
7
|
+
|
|
8
|
+
addProseMirrorPlugins() {
|
|
9
|
+
const { editor } = this;
|
|
10
|
+
|
|
11
|
+
return [
|
|
12
|
+
new Plugin({
|
|
13
|
+
key: new PluginKey("selection"),
|
|
14
|
+
props: {
|
|
15
|
+
decorations(state) {
|
|
16
|
+
if (state.selection.empty) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (editor.isFocused) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return DecorationSet.create(state.doc, [
|
|
25
|
+
Decoration.inline(state.selection.from, state.selection.to, {
|
|
26
|
+
class: "selection",
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export default Selection;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Selection } from "./Selection";
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { DropdownButton } from "../../ui/Dropdown";
|
|
4
|
+
import { Icon } from "../../ui/Icon";
|
|
5
|
+
import { Surface } from "../../ui/Surface";
|
|
6
|
+
import type { Command, MenuListProps } from "./types";
|
|
7
|
+
|
|
8
|
+
export const MenuList = React.forwardRef((props: MenuListProps, ref) => {
|
|
9
|
+
const scrollContainer = useRef<HTMLDivElement>(null);
|
|
10
|
+
const activeItem = useRef<HTMLButtonElement>(null);
|
|
11
|
+
const [selectedGroupIndex, setSelectedGroupIndex] = useState(0);
|
|
12
|
+
const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);
|
|
13
|
+
|
|
14
|
+
// Anytime the groups change, i.e. the user types to narrow it down, we want to
|
|
15
|
+
// reset the current selection to the first menu item
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setSelectedGroupIndex(0);
|
|
18
|
+
setSelectedCommandIndex(0);
|
|
19
|
+
}, [props.items]);
|
|
20
|
+
|
|
21
|
+
const selectItem = useCallback(
|
|
22
|
+
(groupIndex: number, commandIndex: number) => {
|
|
23
|
+
const command = props.items[groupIndex].commands[commandIndex];
|
|
24
|
+
props.command(command);
|
|
25
|
+
},
|
|
26
|
+
[props],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
React.useImperativeHandle(ref, () => ({
|
|
30
|
+
onKeyDown: ({ event }: { event: React.KeyboardEvent }) => {
|
|
31
|
+
if (event.key === "ArrowDown") {
|
|
32
|
+
if (!props.items.length) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const commands = props.items[selectedGroupIndex].commands;
|
|
37
|
+
|
|
38
|
+
let newCommandIndex = selectedCommandIndex + 1;
|
|
39
|
+
let newGroupIndex = selectedGroupIndex;
|
|
40
|
+
|
|
41
|
+
if (commands.length - 1 < newCommandIndex) {
|
|
42
|
+
newCommandIndex = 0;
|
|
43
|
+
newGroupIndex = selectedGroupIndex + 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (props.items.length - 1 < newGroupIndex) {
|
|
47
|
+
newGroupIndex = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setSelectedCommandIndex(newCommandIndex);
|
|
51
|
+
setSelectedGroupIndex(newGroupIndex);
|
|
52
|
+
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (event.key === "ArrowUp") {
|
|
57
|
+
if (!props.items.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let newCommandIndex = selectedCommandIndex - 1;
|
|
62
|
+
let newGroupIndex = selectedGroupIndex;
|
|
63
|
+
|
|
64
|
+
if (newCommandIndex < 0) {
|
|
65
|
+
newGroupIndex = selectedGroupIndex - 1;
|
|
66
|
+
newCommandIndex = props.items[newGroupIndex]?.commands.length - 1 || 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (newGroupIndex < 0) {
|
|
70
|
+
newGroupIndex = props.items.length - 1;
|
|
71
|
+
newCommandIndex = props.items[newGroupIndex].commands.length - 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setSelectedCommandIndex(newCommandIndex);
|
|
75
|
+
setSelectedGroupIndex(newGroupIndex);
|
|
76
|
+
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (event.key === "Enter") {
|
|
81
|
+
if (!props.items.length || selectedGroupIndex === -1 || selectedCommandIndex === -1) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
selectItem(selectedGroupIndex, selectedCommandIndex);
|
|
86
|
+
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (activeItem.current && scrollContainer.current) {
|
|
96
|
+
const offsetTop = activeItem.current.offsetTop;
|
|
97
|
+
const offsetHeight = activeItem.current.offsetHeight;
|
|
98
|
+
scrollContainer.current.scrollTop = offsetTop - offsetHeight;
|
|
99
|
+
}
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
const createCommandClickHandler = useCallback(
|
|
103
|
+
(groupIndex: number, commandIndex: number) => {
|
|
104
|
+
return () => {
|
|
105
|
+
selectItem(groupIndex, commandIndex);
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
[selectItem],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (!props.items.length) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Surface className="mb-8 max-h-[min(80vh,24rem)] flex-wrap overflow-auto p-2 text-black" ref={scrollContainer}>
|
|
117
|
+
<div className="grid grid-cols-1 gap-0.5">
|
|
118
|
+
{props.items.map((group, groupIndex: number) => (
|
|
119
|
+
<React.Fragment key={`${group.title}-wrapper`}>
|
|
120
|
+
<div
|
|
121
|
+
className="col-[1/-1] mx-2 mt-4 select-none font-semibold text-[0.65rem] text-neutral-500 uppercase tracking-wider first:mt-0.5"
|
|
122
|
+
key={`${group.title}`}
|
|
123
|
+
>
|
|
124
|
+
{group.title}
|
|
125
|
+
</div>
|
|
126
|
+
{group.commands.map((command: Command, commandIndex: number) => (
|
|
127
|
+
<DropdownButton
|
|
128
|
+
isActive={selectedGroupIndex === groupIndex && selectedCommandIndex === commandIndex}
|
|
129
|
+
key={`${command.label}`}
|
|
130
|
+
onClick={createCommandClickHandler(groupIndex, commandIndex)}
|
|
131
|
+
>
|
|
132
|
+
<Icon className="mr-1" name={command.iconName} />
|
|
133
|
+
{command.label}
|
|
134
|
+
</DropdownButton>
|
|
135
|
+
))}
|
|
136
|
+
</React.Fragment>
|
|
137
|
+
))}
|
|
138
|
+
</div>
|
|
139
|
+
</Surface>
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
MenuList.displayName = "MenuList";
|
|
144
|
+
|
|
145
|
+
export default MenuList;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { i18n } from "../../utils/locale";
|
|
2
|
+
import type { Group } from "./types";
|
|
3
|
+
|
|
4
|
+
export const getGroups = (): Group[] => [
|
|
5
|
+
{
|
|
6
|
+
name: "format",
|
|
7
|
+
title: i18n("slashCommand.group.format"),
|
|
8
|
+
commands: [
|
|
9
|
+
{
|
|
10
|
+
name: "heading1",
|
|
11
|
+
label: i18n("slashCommand.heading1.title"),
|
|
12
|
+
iconName: "Heading1",
|
|
13
|
+
description: i18n("slashCommand.heading1.description"),
|
|
14
|
+
aliases: ["h1"],
|
|
15
|
+
action: (editor) => {
|
|
16
|
+
editor.chain().focus().setHeading({ level: 1 }).run();
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "heading2",
|
|
21
|
+
label: i18n("slashCommand.heading2.title"),
|
|
22
|
+
iconName: "Heading2",
|
|
23
|
+
description: i18n("slashCommand.heading2.description"),
|
|
24
|
+
aliases: ["h2"],
|
|
25
|
+
action: (editor) => {
|
|
26
|
+
editor.chain().focus().setHeading({ level: 2 }).run();
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "heading3",
|
|
31
|
+
label: i18n("slashCommand.heading3.title"),
|
|
32
|
+
iconName: "Heading3",
|
|
33
|
+
description: i18n("slashCommand.heading3.description"),
|
|
34
|
+
aliases: ["h3"],
|
|
35
|
+
action: (editor) => {
|
|
36
|
+
editor.chain().focus().setHeading({ level: 3 }).run();
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "bulletList",
|
|
41
|
+
label: i18n("slashCommand.bulletList.title"),
|
|
42
|
+
iconName: "List",
|
|
43
|
+
description: i18n("slashCommand.bulletList.description"),
|
|
44
|
+
aliases: ["ul"],
|
|
45
|
+
action: (editor) => {
|
|
46
|
+
editor.chain().focus().toggleBulletList().run();
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "numberedList",
|
|
51
|
+
label: i18n("slashCommand.numberedList.title"),
|
|
52
|
+
iconName: "ListOrdered",
|
|
53
|
+
description: i18n("slashCommand.numberedList.description"),
|
|
54
|
+
aliases: ["ol"],
|
|
55
|
+
action: (editor) => {
|
|
56
|
+
editor.chain().focus().toggleOrderedList().run();
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "taskList",
|
|
61
|
+
label: i18n("slashCommand.taskList.title"),
|
|
62
|
+
iconName: "ListTodo",
|
|
63
|
+
description: i18n("slashCommand.taskList.description"),
|
|
64
|
+
aliases: ["todo"],
|
|
65
|
+
action: (editor) => {
|
|
66
|
+
editor.chain().focus().toggleTaskList().run();
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "blockquote",
|
|
71
|
+
label: i18n("slashCommand.blockquote.title"),
|
|
72
|
+
iconName: "Quote",
|
|
73
|
+
description: i18n("slashCommand.blockquote.description"),
|
|
74
|
+
action: (editor) => {
|
|
75
|
+
editor.chain().focus().setBlockquote().run();
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "codeBlock",
|
|
80
|
+
label: i18n("slashCommand.codeBlock.title"),
|
|
81
|
+
iconName: "SquareCode",
|
|
82
|
+
description: i18n("slashCommand.codeBlock.description"),
|
|
83
|
+
shouldBeHidden: (editor) => editor.isActive("columns"),
|
|
84
|
+
action: (editor) => {
|
|
85
|
+
editor.chain().focus().setCodeBlock().run();
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "insert",
|
|
92
|
+
title: i18n("slashCommand.group.insert"),
|
|
93
|
+
commands: [
|
|
94
|
+
{
|
|
95
|
+
name: "table",
|
|
96
|
+
label: i18n("slashCommand.table.title"),
|
|
97
|
+
iconName: "Table",
|
|
98
|
+
description: i18n("slashCommand.table.description"),
|
|
99
|
+
shouldBeHidden: (editor) => editor.isActive("columns"),
|
|
100
|
+
action: (editor) => {
|
|
101
|
+
editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: false }).run();
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "image",
|
|
106
|
+
label: i18n("slashCommand.image.title"),
|
|
107
|
+
iconName: "Image",
|
|
108
|
+
description: i18n("slashCommand.image.description"),
|
|
109
|
+
aliases: ["img"],
|
|
110
|
+
action: (editor) => {
|
|
111
|
+
editor.chain().focus().setImageUpload().run();
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
// {
|
|
115
|
+
// name: 'columns',
|
|
116
|
+
// label: t("列"),
|
|
117
|
+
// iconName: 'Columns2',
|
|
118
|
+
// description: t("添加两列内容"),
|
|
119
|
+
// aliases: ['cols'],
|
|
120
|
+
// shouldBeHidden: editor => editor.isActive('columns'),
|
|
121
|
+
// action: editor => {
|
|
122
|
+
// editor
|
|
123
|
+
// .chain()
|
|
124
|
+
// .focus()
|
|
125
|
+
// //.setColumns()
|
|
126
|
+
// .focus(editor.state.selection.head - 1)
|
|
127
|
+
// .run()
|
|
128
|
+
// },
|
|
129
|
+
// },
|
|
130
|
+
{
|
|
131
|
+
name: "horizontalRule",
|
|
132
|
+
label: i18n("slashCommand.horizontalRule.title"),
|
|
133
|
+
iconName: "Minus",
|
|
134
|
+
description: i18n("slashCommand.horizontalRule.description"),
|
|
135
|
+
aliases: ["hr"],
|
|
136
|
+
action: (editor) => {
|
|
137
|
+
editor.chain().focus().setHorizontalRule().run();
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
// {
|
|
141
|
+
// name: 'toc',
|
|
142
|
+
// label: t("表格内容"),
|
|
143
|
+
// iconName: 'Book',
|
|
144
|
+
// aliases: ['outline'],
|
|
145
|
+
// description: t("插入表格内容"),
|
|
146
|
+
// shouldBeHidden: editor => editor.isActive('columns'),
|
|
147
|
+
// action: editor => {
|
|
148
|
+
// editor.chain().focus()//.insertTableOfContents().run()
|
|
149
|
+
// },
|
|
150
|
+
// },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
];
|