doclific 0.1.0
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/.gitattributes +2 -0
- package/.prettierignore +5 -0
- package/.prettierrc +9 -0
- package/.vscode/settings.json +13 -0
- package/dist/bin/doclific.d.ts +3 -0
- package/dist/bin/doclific.d.ts.map +1 -0
- package/dist/bin/doclific.js +11 -0
- package/dist/core/codebase.js +31 -0
- package/dist/core/docs.js +75 -0
- package/dist/core/git.js +47 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +46 -0
- package/dist/server/router.d.ts +9 -0
- package/dist/server/router.d.ts.map +1 -0
- package/dist/server/router.js +55 -0
- package/frontend/README.md +73 -0
- package/frontend/components.json +24 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +25 -0
- package/frontend/package-lock.json +15754 -0
- package/frontend/package.json +122 -0
- package/frontend/public/logo.svg +1 -0
- package/frontend/src/App.tsx +21 -0
- package/frontend/src/components/app-sidebar.tsx +393 -0
- package/frontend/src/components/editor/editor-base-kit.tsx +43 -0
- package/frontend/src/components/editor/editor-kit.tsx +93 -0
- package/frontend/src/components/editor/plugins/align-base-kit.tsx +16 -0
- package/frontend/src/components/editor/plugins/align-kit.tsx +18 -0
- package/frontend/src/components/editor/plugins/autoformat-kit.tsx +236 -0
- package/frontend/src/components/editor/plugins/basic-blocks-base-kit.tsx +35 -0
- package/frontend/src/components/editor/plugins/basic-blocks-kit.tsx +88 -0
- package/frontend/src/components/editor/plugins/basic-marks-base-kit.tsx +27 -0
- package/frontend/src/components/editor/plugins/basic-marks-kit.tsx +41 -0
- package/frontend/src/components/editor/plugins/basic-nodes-kit.tsx +6 -0
- package/frontend/src/components/editor/plugins/block-menu-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/block-placeholder-kit.tsx +17 -0
- package/frontend/src/components/editor/plugins/block-selection-kit.tsx +32 -0
- package/frontend/src/components/editor/plugins/callout-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/callout-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/code-block-base-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/code-block-kit.tsx +26 -0
- package/frontend/src/components/editor/plugins/codebase-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/column-base-kit.tsx +11 -0
- package/frontend/src/components/editor/plugins/column-kit.tsx +10 -0
- package/frontend/src/components/editor/plugins/comment-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/comment-kit.tsx +97 -0
- package/frontend/src/components/editor/plugins/cursor-overlay-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/date-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/date-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/discussion-kit.tsx +148 -0
- package/frontend/src/components/editor/plugins/dnd-kit.tsx +28 -0
- package/frontend/src/components/editor/plugins/docx-kit.tsx +6 -0
- package/frontend/src/components/editor/plugins/emoji-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/excalidraw-kit.tsx +9 -0
- package/frontend/src/components/editor/plugins/exit-break-kit.tsx +12 -0
- package/frontend/src/components/editor/plugins/floating-toolbar-kit.tsx +19 -0
- package/frontend/src/components/editor/plugins/font-base-kit.tsx +20 -0
- package/frontend/src/components/editor/plugins/font-kit.tsx +29 -0
- package/frontend/src/components/editor/plugins/indent-base-kit.tsx +19 -0
- package/frontend/src/components/editor/plugins/indent-kit.tsx +22 -0
- package/frontend/src/components/editor/plugins/line-height-base-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/line-height-kit.tsx +16 -0
- package/frontend/src/components/editor/plugins/link-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/link-kit.tsx +15 -0
- package/frontend/src/components/editor/plugins/list-base-kit.tsx +23 -0
- package/frontend/src/components/editor/plugins/list-kit.tsx +26 -0
- package/frontend/src/components/editor/plugins/markdown-kit.tsx +46 -0
- package/frontend/src/components/editor/plugins/math-base-kit.tsx +11 -0
- package/frontend/src/components/editor/plugins/math-kit.tsx +13 -0
- package/frontend/src/components/editor/plugins/media-base-kit.tsx +31 -0
- package/frontend/src/components/editor/plugins/media-kit.tsx +43 -0
- package/frontend/src/components/editor/plugins/mention-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/mention-kit.tsx +15 -0
- package/frontend/src/components/editor/plugins/slash-kit.tsx +18 -0
- package/frontend/src/components/editor/plugins/suggestion-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/suggestion-kit.tsx +90 -0
- package/frontend/src/components/editor/plugins/table-base-kit.tsx +20 -0
- package/frontend/src/components/editor/plugins/table-kit.tsx +22 -0
- package/frontend/src/components/editor/plugins/toc-base-kit.tsx +5 -0
- package/frontend/src/components/editor/plugins/toc-kit.tsx +14 -0
- package/frontend/src/components/editor/plugins/toggle-base-kit.tsx +7 -0
- package/frontend/src/components/editor/plugins/toggle-kit.tsx +11 -0
- package/frontend/src/components/editor/transforms.ts +194 -0
- package/frontend/src/components/markdown-to-slate-demo.tsx +50 -0
- package/frontend/src/components/mode-toggle.tsx +15 -0
- package/frontend/src/components/theme-provider.tsx +73 -0
- package/frontend/src/components/ui/alert-dialog.tsx +155 -0
- package/frontend/src/components/ui/align-toolbar-button.tsx +84 -0
- package/frontend/src/components/ui/avatar.tsx +51 -0
- package/frontend/src/components/ui/block-context-menu.tsx +199 -0
- package/frontend/src/components/ui/block-discussion.tsx +365 -0
- package/frontend/src/components/ui/block-draggable.tsx +512 -0
- package/frontend/src/components/ui/block-list-static.tsx +80 -0
- package/frontend/src/components/ui/block-list.tsx +87 -0
- package/frontend/src/components/ui/block-selection.tsx +42 -0
- package/frontend/src/components/ui/block-suggestion.tsx +473 -0
- package/frontend/src/components/ui/blockquote-node-static.tsx +11 -0
- package/frontend/src/components/ui/blockquote-node.tsx +13 -0
- package/frontend/src/components/ui/button.tsx +62 -0
- package/frontend/src/components/ui/calendar.tsx +218 -0
- package/frontend/src/components/ui/callout-node-static.tsx +36 -0
- package/frontend/src/components/ui/callout-node.tsx +63 -0
- package/frontend/src/components/ui/caption.tsx +63 -0
- package/frontend/src/components/ui/checkbox.tsx +30 -0
- package/frontend/src/components/ui/code-block-node-static.tsx +35 -0
- package/frontend/src/components/ui/code-block-node.tsx +287 -0
- package/frontend/src/components/ui/code-node-static.tsx +15 -0
- package/frontend/src/components/ui/code-node.tsx +17 -0
- package/frontend/src/components/ui/codebase-snippet-node.tsx +237 -0
- package/frontend/src/components/ui/column-node-static.tsx +29 -0
- package/frontend/src/components/ui/column-node.tsx +317 -0
- package/frontend/src/components/ui/command.tsx +182 -0
- package/frontend/src/components/ui/comment-node-static.tsx +15 -0
- package/frontend/src/components/ui/comment-node.tsx +45 -0
- package/frontend/src/components/ui/comment-toolbar-button.tsx +24 -0
- package/frontend/src/components/ui/comment.tsx +618 -0
- package/frontend/src/components/ui/context-menu.tsx +250 -0
- package/frontend/src/components/ui/cursor-overlay.tsx +66 -0
- package/frontend/src/components/ui/date-node-static.tsx +45 -0
- package/frontend/src/components/ui/date-node.tsx +93 -0
- package/frontend/src/components/ui/dialog.tsx +143 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +255 -0
- package/frontend/src/components/ui/dynamic-icon.tsx +12 -0
- package/frontend/src/components/ui/editor-static.tsx +53 -0
- package/frontend/src/components/ui/editor.tsx +130 -0
- package/frontend/src/components/ui/emoji-node.tsx +69 -0
- package/frontend/src/components/ui/emoji-toolbar-button.tsx +628 -0
- package/frontend/src/components/ui/equation-node-static.tsx +98 -0
- package/frontend/src/components/ui/equation-node.tsx +235 -0
- package/frontend/src/components/ui/equation-toolbar-button.tsx +25 -0
- package/frontend/src/components/ui/excalidraw-node.tsx +36 -0
- package/frontend/src/components/ui/export-toolbar-button.tsx +174 -0
- package/frontend/src/components/ui/file-selector.tsx +339 -0
- package/frontend/src/components/ui/floating-toolbar-buttons.tsx +73 -0
- package/frontend/src/components/ui/floating-toolbar.tsx +85 -0
- package/frontend/src/components/ui/font-color-toolbar-button.tsx +831 -0
- package/frontend/src/components/ui/font-size-toolbar-button.tsx +152 -0
- package/frontend/src/components/ui/heading-node-static.tsx +68 -0
- package/frontend/src/components/ui/heading-node.tsx +58 -0
- package/frontend/src/components/ui/highlight-node-static.tsx +11 -0
- package/frontend/src/components/ui/highlight-node.tsx +13 -0
- package/frontend/src/components/ui/history-toolbar-button.tsx +50 -0
- package/frontend/src/components/ui/hr-node-static.tsx +20 -0
- package/frontend/src/components/ui/hr-node.tsx +33 -0
- package/frontend/src/components/ui/import-toolbar-button.tsx +97 -0
- package/frontend/src/components/ui/indent-toolbar-button.tsx +30 -0
- package/frontend/src/components/ui/inline-combobox.tsx +414 -0
- package/frontend/src/components/ui/input.tsx +21 -0
- package/frontend/src/components/ui/insert-toolbar-button.tsx +254 -0
- package/frontend/src/components/ui/kbd-node-static.tsx +15 -0
- package/frontend/src/components/ui/kbd-node.tsx +17 -0
- package/frontend/src/components/ui/layout-header.tsx +35 -0
- package/frontend/src/components/ui/line-height-toolbar-button.tsx +68 -0
- package/frontend/src/components/ui/link-node-static.tsx +21 -0
- package/frontend/src/components/ui/link-node.tsx +39 -0
- package/frontend/src/components/ui/link-toolbar-button.tsx +22 -0
- package/frontend/src/components/ui/link-toolbar.tsx +206 -0
- package/frontend/src/components/ui/list-toolbar-button.tsx +204 -0
- package/frontend/src/components/ui/mark-toolbar-button.tsx +19 -0
- package/frontend/src/components/ui/media-audio-node-static.tsx +17 -0
- package/frontend/src/components/ui/media-audio-node.tsx +39 -0
- package/frontend/src/components/ui/media-embed-node.tsx +136 -0
- package/frontend/src/components/ui/media-file-node-static.tsx +29 -0
- package/frontend/src/components/ui/media-file-node.tsx +47 -0
- package/frontend/src/components/ui/media-image-node-static.tsx +39 -0
- package/frontend/src/components/ui/media-image-node.tsx +80 -0
- package/frontend/src/components/ui/media-placeholder-node.tsx +249 -0
- package/frontend/src/components/ui/media-preview-dialog.tsx +152 -0
- package/frontend/src/components/ui/media-toolbar-button.tsx +225 -0
- package/frontend/src/components/ui/media-toolbar.tsx +115 -0
- package/frontend/src/components/ui/media-upload-toast.tsx +66 -0
- package/frontend/src/components/ui/media-video-node-static.tsx +30 -0
- package/frontend/src/components/ui/media-video-node.tsx +121 -0
- package/frontend/src/components/ui/mention-node-static.tsx +36 -0
- package/frontend/src/components/ui/mention-node.tsx +194 -0
- package/frontend/src/components/ui/mode-toolbar-button.tsx +123 -0
- package/frontend/src/components/ui/more-toolbar-button.tsx +80 -0
- package/frontend/src/components/ui/paragraph-node-static.tsx +13 -0
- package/frontend/src/components/ui/paragraph-node.tsx +15 -0
- package/frontend/src/components/ui/popover.tsx +46 -0
- package/frontend/src/components/ui/resize-handle.tsx +87 -0
- package/frontend/src/components/ui/separator.tsx +28 -0
- package/frontend/src/components/ui/sheet.tsx +139 -0
- package/frontend/src/components/ui/sidebar.tsx +726 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/slash-node.tsx +233 -0
- package/frontend/src/components/ui/sonner.tsx +38 -0
- package/frontend/src/components/ui/suggestion-node-static.tsx +35 -0
- package/frontend/src/components/ui/suggestion-node.tsx +162 -0
- package/frontend/src/components/ui/suggestion-toolbar-button.tsx +25 -0
- package/frontend/src/components/ui/table-icons.tsx +862 -0
- package/frontend/src/components/ui/table-node-static.tsx +98 -0
- package/frontend/src/components/ui/table-node.tsx +656 -0
- package/frontend/src/components/ui/table-toolbar-button.tsx +264 -0
- package/frontend/src/components/ui/toc-node-static.tsx +92 -0
- package/frontend/src/components/ui/toc-node.tsx +55 -0
- package/frontend/src/components/ui/toggle-node-static.tsx +18 -0
- package/frontend/src/components/ui/toggle-node.tsx +36 -0
- package/frontend/src/components/ui/toggle-toolbar-button.tsx +22 -0
- package/frontend/src/components/ui/toolbar.tsx +387 -0
- package/frontend/src/components/ui/tooltip.tsx +59 -0
- package/frontend/src/components/ui/turn-into-toolbar-button.tsx +188 -0
- package/frontend/src/hooks/use-debounce.ts +18 -0
- package/frontend/src/hooks/use-is-touch-device.ts +24 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/hooks/use-mounted.ts +11 -0
- package/frontend/src/hooks/use-upload-file.ts +128 -0
- package/frontend/src/index.css +128 -0
- package/frontend/src/layout.tsx +42 -0
- package/frontend/src/lib/markdown-joiner-transform.ts +239 -0
- package/frontend/src/lib/orpc.ts +13 -0
- package/frontend/src/lib/uploadthing.ts +19 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +13 -0
- package/frontend/src/pages/editor.tsx +44 -0
- package/frontend/src/types/docs.d.ts +6 -0
- package/frontend/src/types/global.d.ts +9 -0
- package/frontend/src/types/router.d.ts +4 -0
- package/frontend/tsconfig.app.json +33 -0
- package/frontend/tsconfig.json +10 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +14 -0
- package/package.json +30 -0
- package/src/bin/doclific.ts +17 -0
- package/src/core/codebase.ts +39 -0
- package/src/core/docs.ts +90 -0
- package/src/core/git.ts +48 -0
- package/src/server/index.ts +55 -0
- package/src/server/router.ts +65 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';
|
|
4
|
+
|
|
5
|
+
import { TablePlugin, useTableMergeState } from '@platejs/table/react';
|
|
6
|
+
import {
|
|
7
|
+
ArrowDown,
|
|
8
|
+
ArrowLeft,
|
|
9
|
+
ArrowRight,
|
|
10
|
+
ArrowUp,
|
|
11
|
+
Combine,
|
|
12
|
+
Grid3x3Icon,
|
|
13
|
+
Table,
|
|
14
|
+
Trash2Icon,
|
|
15
|
+
Ungroup,
|
|
16
|
+
XIcon,
|
|
17
|
+
} from 'lucide-react';
|
|
18
|
+
import { KEYS } from 'platejs';
|
|
19
|
+
import { useEditorPlugin, useEditorSelector } from 'platejs/react';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
DropdownMenu,
|
|
23
|
+
DropdownMenuContent,
|
|
24
|
+
DropdownMenuGroup,
|
|
25
|
+
DropdownMenuItem,
|
|
26
|
+
DropdownMenuSub,
|
|
27
|
+
DropdownMenuSubContent,
|
|
28
|
+
DropdownMenuSubTrigger,
|
|
29
|
+
DropdownMenuTrigger,
|
|
30
|
+
} from '@/components/ui/dropdown-menu';
|
|
31
|
+
import { cn } from '@/lib/utils';
|
|
32
|
+
|
|
33
|
+
import { ToolbarButton } from './toolbar';
|
|
34
|
+
|
|
35
|
+
export function TableToolbarButton(props: DropdownMenuProps) {
|
|
36
|
+
const tableSelected = useEditorSelector(
|
|
37
|
+
(editor) => editor.api.some({ match: { type: KEYS.table } }),
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const { editor, tf } = useEditorPlugin(TablePlugin);
|
|
42
|
+
const [open, setOpen] = React.useState(false);
|
|
43
|
+
const mergeState = useTableMergeState();
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
|
|
47
|
+
<DropdownMenuTrigger asChild>
|
|
48
|
+
<ToolbarButton pressed={open} tooltip="Table" isDropdown>
|
|
49
|
+
<Table />
|
|
50
|
+
</ToolbarButton>
|
|
51
|
+
</DropdownMenuTrigger>
|
|
52
|
+
|
|
53
|
+
<DropdownMenuContent
|
|
54
|
+
className="flex w-[180px] min-w-0 flex-col"
|
|
55
|
+
align="start"
|
|
56
|
+
>
|
|
57
|
+
<DropdownMenuGroup>
|
|
58
|
+
<DropdownMenuSub>
|
|
59
|
+
<DropdownMenuSubTrigger className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50">
|
|
60
|
+
<Grid3x3Icon className="size-4" />
|
|
61
|
+
<span>Table</span>
|
|
62
|
+
</DropdownMenuSubTrigger>
|
|
63
|
+
<DropdownMenuSubContent className="m-0 p-0">
|
|
64
|
+
<TablePicker />
|
|
65
|
+
</DropdownMenuSubContent>
|
|
66
|
+
</DropdownMenuSub>
|
|
67
|
+
|
|
68
|
+
<DropdownMenuSub>
|
|
69
|
+
<DropdownMenuSubTrigger
|
|
70
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
71
|
+
disabled={!tableSelected}
|
|
72
|
+
>
|
|
73
|
+
<div className="size-4" />
|
|
74
|
+
<span>Cell</span>
|
|
75
|
+
</DropdownMenuSubTrigger>
|
|
76
|
+
<DropdownMenuSubContent>
|
|
77
|
+
<DropdownMenuItem
|
|
78
|
+
className="min-w-[180px]"
|
|
79
|
+
disabled={!mergeState.canMerge}
|
|
80
|
+
onSelect={() => {
|
|
81
|
+
tf.table.merge();
|
|
82
|
+
editor.tf.focus();
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<Combine />
|
|
86
|
+
Merge cells
|
|
87
|
+
</DropdownMenuItem>
|
|
88
|
+
<DropdownMenuItem
|
|
89
|
+
className="min-w-[180px]"
|
|
90
|
+
disabled={!mergeState.canSplit}
|
|
91
|
+
onSelect={() => {
|
|
92
|
+
tf.table.split();
|
|
93
|
+
editor.tf.focus();
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<Ungroup />
|
|
97
|
+
Split cell
|
|
98
|
+
</DropdownMenuItem>
|
|
99
|
+
</DropdownMenuSubContent>
|
|
100
|
+
</DropdownMenuSub>
|
|
101
|
+
|
|
102
|
+
<DropdownMenuSub>
|
|
103
|
+
<DropdownMenuSubTrigger
|
|
104
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
105
|
+
disabled={!tableSelected}
|
|
106
|
+
>
|
|
107
|
+
<div className="size-4" />
|
|
108
|
+
<span>Row</span>
|
|
109
|
+
</DropdownMenuSubTrigger>
|
|
110
|
+
<DropdownMenuSubContent>
|
|
111
|
+
<DropdownMenuItem
|
|
112
|
+
className="min-w-[180px]"
|
|
113
|
+
disabled={!tableSelected}
|
|
114
|
+
onSelect={() => {
|
|
115
|
+
tf.insert.tableRow({ before: true });
|
|
116
|
+
editor.tf.focus();
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<ArrowUp />
|
|
120
|
+
Insert row before
|
|
121
|
+
</DropdownMenuItem>
|
|
122
|
+
<DropdownMenuItem
|
|
123
|
+
className="min-w-[180px]"
|
|
124
|
+
disabled={!tableSelected}
|
|
125
|
+
onSelect={() => {
|
|
126
|
+
tf.insert.tableRow();
|
|
127
|
+
editor.tf.focus();
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<ArrowDown />
|
|
131
|
+
Insert row after
|
|
132
|
+
</DropdownMenuItem>
|
|
133
|
+
<DropdownMenuItem
|
|
134
|
+
className="min-w-[180px]"
|
|
135
|
+
disabled={!tableSelected}
|
|
136
|
+
onSelect={() => {
|
|
137
|
+
tf.remove.tableRow();
|
|
138
|
+
editor.tf.focus();
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<XIcon />
|
|
142
|
+
Delete row
|
|
143
|
+
</DropdownMenuItem>
|
|
144
|
+
</DropdownMenuSubContent>
|
|
145
|
+
</DropdownMenuSub>
|
|
146
|
+
|
|
147
|
+
<DropdownMenuSub>
|
|
148
|
+
<DropdownMenuSubTrigger
|
|
149
|
+
className="gap-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
150
|
+
disabled={!tableSelected}
|
|
151
|
+
>
|
|
152
|
+
<div className="size-4" />
|
|
153
|
+
<span>Column</span>
|
|
154
|
+
</DropdownMenuSubTrigger>
|
|
155
|
+
<DropdownMenuSubContent>
|
|
156
|
+
<DropdownMenuItem
|
|
157
|
+
className="min-w-[180px]"
|
|
158
|
+
disabled={!tableSelected}
|
|
159
|
+
onSelect={() => {
|
|
160
|
+
tf.insert.tableColumn({ before: true });
|
|
161
|
+
editor.tf.focus();
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
<ArrowLeft />
|
|
165
|
+
Insert column before
|
|
166
|
+
</DropdownMenuItem>
|
|
167
|
+
<DropdownMenuItem
|
|
168
|
+
className="min-w-[180px]"
|
|
169
|
+
disabled={!tableSelected}
|
|
170
|
+
onSelect={() => {
|
|
171
|
+
tf.insert.tableColumn();
|
|
172
|
+
editor.tf.focus();
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
<ArrowRight />
|
|
176
|
+
Insert column after
|
|
177
|
+
</DropdownMenuItem>
|
|
178
|
+
<DropdownMenuItem
|
|
179
|
+
className="min-w-[180px]"
|
|
180
|
+
disabled={!tableSelected}
|
|
181
|
+
onSelect={() => {
|
|
182
|
+
tf.remove.tableColumn();
|
|
183
|
+
editor.tf.focus();
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<XIcon />
|
|
187
|
+
Delete column
|
|
188
|
+
</DropdownMenuItem>
|
|
189
|
+
</DropdownMenuSubContent>
|
|
190
|
+
</DropdownMenuSub>
|
|
191
|
+
|
|
192
|
+
<DropdownMenuItem
|
|
193
|
+
className="min-w-[180px]"
|
|
194
|
+
disabled={!tableSelected}
|
|
195
|
+
onSelect={() => {
|
|
196
|
+
tf.remove.table();
|
|
197
|
+
editor.tf.focus();
|
|
198
|
+
}}
|
|
199
|
+
>
|
|
200
|
+
<Trash2Icon />
|
|
201
|
+
Delete table
|
|
202
|
+
</DropdownMenuItem>
|
|
203
|
+
</DropdownMenuGroup>
|
|
204
|
+
</DropdownMenuContent>
|
|
205
|
+
</DropdownMenu>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function TablePicker() {
|
|
210
|
+
const { editor, tf } = useEditorPlugin(TablePlugin);
|
|
211
|
+
|
|
212
|
+
const [tablePicker, setTablePicker] = React.useState({
|
|
213
|
+
grid: Array.from({ length: 8 }, () => Array.from({ length: 8 }).fill(0)),
|
|
214
|
+
size: { colCount: 0, rowCount: 0 },
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const onCellMove = (rowIndex: number, colIndex: number) => {
|
|
218
|
+
const newGrid = [...tablePicker.grid];
|
|
219
|
+
|
|
220
|
+
for (let i = 0; i < newGrid.length; i++) {
|
|
221
|
+
for (let j = 0; j < newGrid[i].length; j++) {
|
|
222
|
+
newGrid[i][j] =
|
|
223
|
+
i >= 0 && i <= rowIndex && j >= 0 && j <= colIndex ? 1 : 0;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
setTablePicker({
|
|
228
|
+
grid: newGrid,
|
|
229
|
+
size: { colCount: colIndex + 1, rowCount: rowIndex + 1 },
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<div
|
|
235
|
+
className="flex! m-0 flex-col p-0"
|
|
236
|
+
onClick={() => {
|
|
237
|
+
tf.insert.table(tablePicker.size, { select: true });
|
|
238
|
+
editor.tf.focus();
|
|
239
|
+
}}
|
|
240
|
+
role="button"
|
|
241
|
+
>
|
|
242
|
+
<div className="grid size-[130px] grid-cols-8 gap-0.5 p-1">
|
|
243
|
+
{tablePicker.grid.map((rows, rowIndex) =>
|
|
244
|
+
rows.map((value, columIndex) => (
|
|
245
|
+
<div
|
|
246
|
+
key={`(${rowIndex},${columIndex})`}
|
|
247
|
+
className={cn(
|
|
248
|
+
'col-span-1 size-3 border border-solid bg-secondary',
|
|
249
|
+
!!value && 'border-current'
|
|
250
|
+
)}
|
|
251
|
+
onMouseMove={() => {
|
|
252
|
+
onCellMove(rowIndex, columIndex);
|
|
253
|
+
}}
|
|
254
|
+
/>
|
|
255
|
+
))
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<div className="text-center text-current text-xs">
|
|
260
|
+
{tablePicker.size.rowCount} x {tablePicker.size.colCount}
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { SlateElementProps } from 'platejs/static';
|
|
2
|
+
|
|
3
|
+
import { type Heading, BaseTocPlugin, isHeading } from '@platejs/toc';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
import { type SlateEditor, type TElement, NodeApi } from 'platejs';
|
|
6
|
+
import { SlateElement } from 'platejs/static';
|
|
7
|
+
|
|
8
|
+
import { Button } from '@/components/ui/button';
|
|
9
|
+
|
|
10
|
+
const headingItemVariants = cva(
|
|
11
|
+
'block h-auto w-full cursor-pointer truncate rounded-none px-0.5 py-1.5 text-left font-medium text-muted-foreground underline decoration-[0.5px] underline-offset-4 hover:bg-accent hover:text-muted-foreground',
|
|
12
|
+
{
|
|
13
|
+
variants: {
|
|
14
|
+
depth: {
|
|
15
|
+
1: 'pl-0.5',
|
|
16
|
+
2: 'pl-[26px]',
|
|
17
|
+
3: 'pl-[50px]',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export function TocElementStatic(props: SlateElementProps) {
|
|
24
|
+
const { editor } = props;
|
|
25
|
+
const headingList = getHeadingList(editor);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<SlateElement {...props} className="mb-1 p-0">
|
|
29
|
+
<div>
|
|
30
|
+
{headingList.length > 0 ? (
|
|
31
|
+
headingList.map((item) => (
|
|
32
|
+
<Button
|
|
33
|
+
key={item.title}
|
|
34
|
+
variant="ghost"
|
|
35
|
+
className={headingItemVariants({
|
|
36
|
+
depth: item.depth as 1 | 2 | 3,
|
|
37
|
+
})}
|
|
38
|
+
>
|
|
39
|
+
{item.title}
|
|
40
|
+
</Button>
|
|
41
|
+
))
|
|
42
|
+
) : (
|
|
43
|
+
<div className="text-gray-500 text-sm">
|
|
44
|
+
Create a heading to display the table of contents.
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
</div>
|
|
48
|
+
{props.children}
|
|
49
|
+
</SlateElement>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const headingDepth: Record<string, number> = {
|
|
54
|
+
h1: 1,
|
|
55
|
+
h2: 2,
|
|
56
|
+
h3: 3,
|
|
57
|
+
h4: 4,
|
|
58
|
+
h5: 5,
|
|
59
|
+
h6: 6,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getHeadingList = (editor?: SlateEditor) => {
|
|
63
|
+
if (!editor) return [];
|
|
64
|
+
|
|
65
|
+
const options = editor.getOptions(BaseTocPlugin);
|
|
66
|
+
|
|
67
|
+
if (options.queryHeading) {
|
|
68
|
+
return options.queryHeading(editor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const headingList: Heading[] = [];
|
|
72
|
+
|
|
73
|
+
const values = editor.api.nodes<TElement>({
|
|
74
|
+
at: [],
|
|
75
|
+
match: (n) => isHeading(n),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!values) return [];
|
|
79
|
+
|
|
80
|
+
Array.from(values).forEach(([node, path]) => {
|
|
81
|
+
const { type } = node;
|
|
82
|
+
const title = NodeApi.string(node);
|
|
83
|
+
const depth = headingDepth[type];
|
|
84
|
+
const id = node.id as string;
|
|
85
|
+
|
|
86
|
+
if (title) {
|
|
87
|
+
headingList.push({ id, depth, path, title, type });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return headingList;
|
|
92
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { PlateElementProps } from 'platejs/react';
|
|
4
|
+
|
|
5
|
+
import { useTocElement, useTocElementState } from '@platejs/toc/react';
|
|
6
|
+
import { cva } from 'class-variance-authority';
|
|
7
|
+
import { PlateElement } from 'platejs/react';
|
|
8
|
+
|
|
9
|
+
import { Button } from '@/components/ui/button';
|
|
10
|
+
|
|
11
|
+
const headingItemVariants = cva(
|
|
12
|
+
'block h-auto w-full cursor-pointer truncate rounded-none px-0.5 py-1.5 text-left font-medium text-muted-foreground underline decoration-[0.5px] underline-offset-4 hover:bg-accent hover:text-muted-foreground',
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
depth: {
|
|
16
|
+
1: 'pl-0.5',
|
|
17
|
+
2: 'pl-[26px]',
|
|
18
|
+
3: 'pl-[50px]',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export function TocElement(props: PlateElementProps) {
|
|
25
|
+
const state = useTocElementState();
|
|
26
|
+
const { props: btnProps } = useTocElement(state);
|
|
27
|
+
const { headingList } = state;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<PlateElement {...props} className="mb-1 p-0">
|
|
31
|
+
<div contentEditable={false}>
|
|
32
|
+
{headingList.length > 0 ? (
|
|
33
|
+
headingList.map((item) => (
|
|
34
|
+
<Button
|
|
35
|
+
key={item.id}
|
|
36
|
+
variant="ghost"
|
|
37
|
+
className={headingItemVariants({
|
|
38
|
+
depth: item.depth as 1 | 2 | 3,
|
|
39
|
+
})}
|
|
40
|
+
onClick={(e) => btnProps.onClick(e, item, 'smooth')}
|
|
41
|
+
aria-current
|
|
42
|
+
>
|
|
43
|
+
{item.title}
|
|
44
|
+
</Button>
|
|
45
|
+
))
|
|
46
|
+
) : (
|
|
47
|
+
<div className="text-gray-500 text-sm">
|
|
48
|
+
Create a heading to display the table of contents.
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
{props.children}
|
|
53
|
+
</PlateElement>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SlateElementProps } from 'platejs/static';
|
|
2
|
+
|
|
3
|
+
import { ChevronRight } from 'lucide-react';
|
|
4
|
+
import { SlateElement } from 'platejs/static';
|
|
5
|
+
|
|
6
|
+
export function ToggleElementStatic(props: SlateElementProps) {
|
|
7
|
+
return (
|
|
8
|
+
<SlateElement {...props} className="pl-6">
|
|
9
|
+
<div
|
|
10
|
+
className="-left-0.5 absolute top-0 size-6 cursor-pointer select-none items-center justify-center rounded-md p-px text-muted-foreground transition-colors hover:bg-accent [&_svg]:size-4"
|
|
11
|
+
contentEditable={false}
|
|
12
|
+
>
|
|
13
|
+
<ChevronRight className="rotate-0 transition-transform duration-75" />
|
|
14
|
+
</div>
|
|
15
|
+
{props.children}
|
|
16
|
+
</SlateElement>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { PlateElementProps } from 'platejs/react';
|
|
4
|
+
|
|
5
|
+
import { useToggleButton, useToggleButtonState } from '@platejs/toggle/react';
|
|
6
|
+
import { ChevronRight } from 'lucide-react';
|
|
7
|
+
import { PlateElement } from 'platejs/react';
|
|
8
|
+
|
|
9
|
+
import { Button } from '@/components/ui/button';
|
|
10
|
+
|
|
11
|
+
export function ToggleElement(props: PlateElementProps) {
|
|
12
|
+
const element = props.element;
|
|
13
|
+
const state = useToggleButtonState(element.id as string);
|
|
14
|
+
const { buttonProps, open } = useToggleButton(state);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<PlateElement {...props} className="pl-6">
|
|
18
|
+
<Button
|
|
19
|
+
size="icon"
|
|
20
|
+
variant="ghost"
|
|
21
|
+
className="-left-0.5 absolute top-0 size-6 cursor-pointer select-none items-center justify-center rounded-md p-px text-muted-foreground transition-colors hover:bg-accent [&_svg]:size-4"
|
|
22
|
+
contentEditable={false}
|
|
23
|
+
{...buttonProps}
|
|
24
|
+
>
|
|
25
|
+
<ChevronRight
|
|
26
|
+
className={
|
|
27
|
+
open
|
|
28
|
+
? 'rotate-90 transition-transform duration-75'
|
|
29
|
+
: 'rotate-0 transition-transform duration-75'
|
|
30
|
+
}
|
|
31
|
+
/>
|
|
32
|
+
</Button>
|
|
33
|
+
{props.children}
|
|
34
|
+
</PlateElement>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useToggleToolbarButton,
|
|
5
|
+
useToggleToolbarButtonState,
|
|
6
|
+
} from '@platejs/toggle/react';
|
|
7
|
+
import { ListCollapseIcon } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import { ToolbarButton } from './toolbar';
|
|
10
|
+
|
|
11
|
+
export function ToggleToolbarButton(
|
|
12
|
+
props: React.ComponentProps<typeof ToolbarButton>
|
|
13
|
+
) {
|
|
14
|
+
const state = useToggleToolbarButtonState();
|
|
15
|
+
const { props: buttonProps } = useToggleToolbarButton(state);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<ToolbarButton {...props} {...buttonProps} tooltip="Toggle">
|
|
19
|
+
<ListCollapseIcon />
|
|
20
|
+
</ToolbarButton>
|
|
21
|
+
);
|
|
22
|
+
}
|