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,152 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PreviewImage,
|
|
5
|
+
useImagePreview,
|
|
6
|
+
useImagePreviewValue,
|
|
7
|
+
useScaleInput,
|
|
8
|
+
} from '@platejs/media/react';
|
|
9
|
+
import { cva } from 'class-variance-authority';
|
|
10
|
+
import { ArrowLeft, ArrowRight, Download, Minus, Plus, X } from 'lucide-react';
|
|
11
|
+
import { useEditorRef } from 'platejs/react';
|
|
12
|
+
|
|
13
|
+
import { cn } from '@/lib/utils';
|
|
14
|
+
|
|
15
|
+
const buttonVariants = cva('rounded bg-[rgba(0,0,0,0.5)] px-1', {
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
variant: 'default',
|
|
18
|
+
},
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
default: 'text-white',
|
|
22
|
+
disabled: 'cursor-not-allowed text-gray-400',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const SCROLL_SPEED = 4;
|
|
28
|
+
|
|
29
|
+
export function MediaPreviewDialog() {
|
|
30
|
+
const editor = useEditorRef();
|
|
31
|
+
const isOpen = useImagePreviewValue('isOpen', editor.id);
|
|
32
|
+
const scale = useImagePreviewValue('scale');
|
|
33
|
+
const isEditingScale = useImagePreviewValue('isEditingScale');
|
|
34
|
+
const {
|
|
35
|
+
closeProps,
|
|
36
|
+
currentUrlIndex,
|
|
37
|
+
maskLayerProps,
|
|
38
|
+
nextDisabled,
|
|
39
|
+
nextProps,
|
|
40
|
+
prevDisabled,
|
|
41
|
+
prevProps,
|
|
42
|
+
scaleTextProps,
|
|
43
|
+
zommOutProps,
|
|
44
|
+
zoomInDisabled,
|
|
45
|
+
zoomInProps,
|
|
46
|
+
zoomOutDisabled,
|
|
47
|
+
} = useImagePreview({ scrollSpeed: SCROLL_SPEED });
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div
|
|
51
|
+
className={cn(
|
|
52
|
+
'fixed top-0 left-0 z-50 h-screen w-screen select-none',
|
|
53
|
+
!isOpen && 'hidden'
|
|
54
|
+
)}
|
|
55
|
+
onContextMenu={(e) => e.stopPropagation()}
|
|
56
|
+
{...maskLayerProps}
|
|
57
|
+
>
|
|
58
|
+
<div className="absolute inset-0 size-full bg-black opacity-30" />
|
|
59
|
+
<div className="absolute inset-0 size-full bg-black opacity-30" />
|
|
60
|
+
<div className="absolute inset-0 flex items-center justify-center">
|
|
61
|
+
<div className="relative flex max-h-screen w-full items-center">
|
|
62
|
+
<PreviewImage
|
|
63
|
+
className={cn(
|
|
64
|
+
'mx-auto block max-h-[calc(100vh-4rem)] w-auto object-contain transition-transform'
|
|
65
|
+
)}
|
|
66
|
+
/>
|
|
67
|
+
<div
|
|
68
|
+
className="-translate-x-1/2 absolute bottom-0 left-1/2 z-40 flex w-fit justify-center gap-4 p-2 text-center text-white"
|
|
69
|
+
onClick={(e) => e.stopPropagation()}
|
|
70
|
+
>
|
|
71
|
+
<div className="flex gap-1">
|
|
72
|
+
<button
|
|
73
|
+
{...prevProps}
|
|
74
|
+
className={cn(
|
|
75
|
+
buttonVariants({
|
|
76
|
+
variant: prevDisabled ? 'disabled' : 'default',
|
|
77
|
+
})
|
|
78
|
+
)}
|
|
79
|
+
type="button"
|
|
80
|
+
>
|
|
81
|
+
<ArrowLeft />
|
|
82
|
+
</button>
|
|
83
|
+
{(currentUrlIndex ?? 0) + 1}
|
|
84
|
+
<button
|
|
85
|
+
{...nextProps}
|
|
86
|
+
className={cn(
|
|
87
|
+
buttonVariants({
|
|
88
|
+
variant: nextDisabled ? 'disabled' : 'default',
|
|
89
|
+
})
|
|
90
|
+
)}
|
|
91
|
+
type="button"
|
|
92
|
+
>
|
|
93
|
+
<ArrowRight />
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
<div className="flex">
|
|
97
|
+
<button
|
|
98
|
+
className={cn(
|
|
99
|
+
buttonVariants({
|
|
100
|
+
variant: zoomOutDisabled ? 'disabled' : 'default',
|
|
101
|
+
})
|
|
102
|
+
)}
|
|
103
|
+
{...zommOutProps}
|
|
104
|
+
type="button"
|
|
105
|
+
>
|
|
106
|
+
<Minus className="size-4" />
|
|
107
|
+
</button>
|
|
108
|
+
<div className="mx-px">
|
|
109
|
+
{isEditingScale ? (
|
|
110
|
+
<>
|
|
111
|
+
<ScaleInput className="w-10 rounded px-1 text-slate-500 outline" />{' '}
|
|
112
|
+
<span>%</span>
|
|
113
|
+
</>
|
|
114
|
+
) : (
|
|
115
|
+
<span {...scaleTextProps}>{`${scale * 100}%`}</span>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
<button
|
|
119
|
+
className={cn(
|
|
120
|
+
buttonVariants({
|
|
121
|
+
variant: zoomInDisabled ? 'disabled' : 'default',
|
|
122
|
+
})
|
|
123
|
+
)}
|
|
124
|
+
{...zoomInProps}
|
|
125
|
+
type="button"
|
|
126
|
+
>
|
|
127
|
+
<Plus className="size-4" />
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
{/* TODO: downLoad the image */}
|
|
131
|
+
<button className={cn(buttonVariants())} type="button">
|
|
132
|
+
<Download className="size-4" />
|
|
133
|
+
</button>
|
|
134
|
+
<button
|
|
135
|
+
{...closeProps}
|
|
136
|
+
className={cn(buttonVariants())}
|
|
137
|
+
type="button"
|
|
138
|
+
>
|
|
139
|
+
<X className="size-4" />
|
|
140
|
+
</button>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function ScaleInput(props: React.ComponentProps<'input'>) {
|
|
149
|
+
const { props: scaleInputProps, ref } = useScaleInput();
|
|
150
|
+
|
|
151
|
+
return <input {...scaleInputProps} {...props} ref={ref} />;
|
|
152
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';
|
|
4
|
+
|
|
5
|
+
import { PlaceholderPlugin } from '@platejs/media/react';
|
|
6
|
+
import {
|
|
7
|
+
AudioLinesIcon,
|
|
8
|
+
FileUpIcon,
|
|
9
|
+
FilmIcon,
|
|
10
|
+
ImageIcon,
|
|
11
|
+
LinkIcon,
|
|
12
|
+
} from 'lucide-react';
|
|
13
|
+
import { isUrl, KEYS } from 'platejs';
|
|
14
|
+
import { useEditorRef } from 'platejs/react';
|
|
15
|
+
import { toast } from 'sonner';
|
|
16
|
+
import { useFilePicker } from 'use-file-picker';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
AlertDialog,
|
|
20
|
+
AlertDialogAction,
|
|
21
|
+
AlertDialogCancel,
|
|
22
|
+
AlertDialogContent,
|
|
23
|
+
AlertDialogDescription,
|
|
24
|
+
AlertDialogFooter,
|
|
25
|
+
AlertDialogHeader,
|
|
26
|
+
AlertDialogTitle,
|
|
27
|
+
} from '@/components/ui/alert-dialog';
|
|
28
|
+
import {
|
|
29
|
+
DropdownMenu,
|
|
30
|
+
DropdownMenuContent,
|
|
31
|
+
DropdownMenuGroup,
|
|
32
|
+
DropdownMenuItem,
|
|
33
|
+
DropdownMenuTrigger,
|
|
34
|
+
} from '@/components/ui/dropdown-menu';
|
|
35
|
+
import { Input } from '@/components/ui/input';
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
ToolbarSplitButton,
|
|
39
|
+
ToolbarSplitButtonPrimary,
|
|
40
|
+
ToolbarSplitButtonSecondary,
|
|
41
|
+
} from './toolbar';
|
|
42
|
+
|
|
43
|
+
const MEDIA_CONFIG: Record<
|
|
44
|
+
string,
|
|
45
|
+
{
|
|
46
|
+
accept: string[];
|
|
47
|
+
icon: React.ReactNode;
|
|
48
|
+
title: string;
|
|
49
|
+
tooltip: string;
|
|
50
|
+
}
|
|
51
|
+
> = {
|
|
52
|
+
[KEYS.audio]: {
|
|
53
|
+
accept: ['audio/*'],
|
|
54
|
+
icon: <AudioLinesIcon className="size-4" />,
|
|
55
|
+
title: 'Insert Audio',
|
|
56
|
+
tooltip: 'Audio',
|
|
57
|
+
},
|
|
58
|
+
[KEYS.file]: {
|
|
59
|
+
accept: ['*'],
|
|
60
|
+
icon: <FileUpIcon className="size-4" />,
|
|
61
|
+
title: 'Insert File',
|
|
62
|
+
tooltip: 'File',
|
|
63
|
+
},
|
|
64
|
+
[KEYS.img]: {
|
|
65
|
+
accept: ['image/*'],
|
|
66
|
+
icon: <ImageIcon className="size-4" />,
|
|
67
|
+
title: 'Insert Image',
|
|
68
|
+
tooltip: 'Image',
|
|
69
|
+
},
|
|
70
|
+
[KEYS.video]: {
|
|
71
|
+
accept: ['video/*'],
|
|
72
|
+
icon: <FilmIcon className="size-4" />,
|
|
73
|
+
title: 'Insert Video',
|
|
74
|
+
tooltip: 'Video',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export function MediaToolbarButton({
|
|
79
|
+
nodeType,
|
|
80
|
+
...props
|
|
81
|
+
}: DropdownMenuProps & { nodeType: string }) {
|
|
82
|
+
const currentConfig = MEDIA_CONFIG[nodeType];
|
|
83
|
+
|
|
84
|
+
const editor = useEditorRef();
|
|
85
|
+
const [open, setOpen] = React.useState(false);
|
|
86
|
+
const [dialogOpen, setDialogOpen] = React.useState(false);
|
|
87
|
+
|
|
88
|
+
const { openFilePicker } = useFilePicker({
|
|
89
|
+
accept: currentConfig.accept,
|
|
90
|
+
multiple: true,
|
|
91
|
+
onFilesSelected: ({ plainFiles: updatedFiles }) => {
|
|
92
|
+
editor.getTransforms(PlaceholderPlugin).insert.media(updatedFiles);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<ToolbarSplitButton
|
|
99
|
+
onClick={() => {
|
|
100
|
+
openFilePicker();
|
|
101
|
+
}}
|
|
102
|
+
onKeyDown={(e) => {
|
|
103
|
+
if (e.key === 'ArrowDown') {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
setOpen(true);
|
|
106
|
+
}
|
|
107
|
+
}}
|
|
108
|
+
pressed={open}
|
|
109
|
+
>
|
|
110
|
+
<ToolbarSplitButtonPrimary>
|
|
111
|
+
{currentConfig.icon}
|
|
112
|
+
</ToolbarSplitButtonPrimary>
|
|
113
|
+
|
|
114
|
+
<DropdownMenu
|
|
115
|
+
open={open}
|
|
116
|
+
onOpenChange={setOpen}
|
|
117
|
+
modal={false}
|
|
118
|
+
{...props}
|
|
119
|
+
>
|
|
120
|
+
<DropdownMenuTrigger asChild>
|
|
121
|
+
<ToolbarSplitButtonSecondary />
|
|
122
|
+
</DropdownMenuTrigger>
|
|
123
|
+
|
|
124
|
+
<DropdownMenuContent
|
|
125
|
+
onClick={(e) => e.stopPropagation()}
|
|
126
|
+
align="start"
|
|
127
|
+
alignOffset={-32}
|
|
128
|
+
>
|
|
129
|
+
<DropdownMenuGroup>
|
|
130
|
+
<DropdownMenuItem onSelect={() => openFilePicker()}>
|
|
131
|
+
{currentConfig.icon}
|
|
132
|
+
Upload from computer
|
|
133
|
+
</DropdownMenuItem>
|
|
134
|
+
<DropdownMenuItem onSelect={() => setDialogOpen(true)}>
|
|
135
|
+
<LinkIcon />
|
|
136
|
+
Insert via URL
|
|
137
|
+
</DropdownMenuItem>
|
|
138
|
+
</DropdownMenuGroup>
|
|
139
|
+
</DropdownMenuContent>
|
|
140
|
+
</DropdownMenu>
|
|
141
|
+
</ToolbarSplitButton>
|
|
142
|
+
|
|
143
|
+
<AlertDialog
|
|
144
|
+
open={dialogOpen}
|
|
145
|
+
onOpenChange={(value) => {
|
|
146
|
+
setDialogOpen(value);
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<AlertDialogContent className="gap-6">
|
|
150
|
+
<MediaUrlDialogContent
|
|
151
|
+
currentConfig={currentConfig}
|
|
152
|
+
nodeType={nodeType}
|
|
153
|
+
setOpen={setDialogOpen}
|
|
154
|
+
/>
|
|
155
|
+
</AlertDialogContent>
|
|
156
|
+
</AlertDialog>
|
|
157
|
+
</>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function MediaUrlDialogContent({
|
|
162
|
+
currentConfig,
|
|
163
|
+
nodeType,
|
|
164
|
+
setOpen,
|
|
165
|
+
}: {
|
|
166
|
+
currentConfig: (typeof MEDIA_CONFIG)[string];
|
|
167
|
+
nodeType: string;
|
|
168
|
+
setOpen: (value: boolean) => void;
|
|
169
|
+
}) {
|
|
170
|
+
const editor = useEditorRef();
|
|
171
|
+
const [url, setUrl] = React.useState('');
|
|
172
|
+
|
|
173
|
+
const embedMedia = React.useCallback(() => {
|
|
174
|
+
if (!isUrl(url)) return toast.error('Invalid URL');
|
|
175
|
+
|
|
176
|
+
setOpen(false);
|
|
177
|
+
editor.tf.insertNodes({
|
|
178
|
+
children: [{ text: '' }],
|
|
179
|
+
name: nodeType === KEYS.file ? url.split('/').pop() : undefined,
|
|
180
|
+
type: nodeType,
|
|
181
|
+
url,
|
|
182
|
+
});
|
|
183
|
+
}, [url, editor, nodeType, setOpen]);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<>
|
|
187
|
+
<AlertDialogHeader>
|
|
188
|
+
<AlertDialogTitle>{currentConfig.title}</AlertDialogTitle>
|
|
189
|
+
</AlertDialogHeader>
|
|
190
|
+
|
|
191
|
+
<AlertDialogDescription className="group relative w-full">
|
|
192
|
+
<label
|
|
193
|
+
className="-translate-y-1/2 absolute top-1/2 block cursor-text px-1 text-muted-foreground/70 text-sm transition-all group-focus-within:pointer-events-none group-focus-within:top-0 group-focus-within:cursor-default group-focus-within:font-medium group-focus-within:text-foreground group-focus-within:text-xs has-[+input:not(:placeholder-shown)]:pointer-events-none has-[+input:not(:placeholder-shown)]:top-0 has-[+input:not(:placeholder-shown)]:cursor-default has-[+input:not(:placeholder-shown)]:font-medium has-[+input:not(:placeholder-shown)]:text-foreground has-[+input:not(:placeholder-shown)]:text-xs"
|
|
194
|
+
htmlFor="url"
|
|
195
|
+
>
|
|
196
|
+
<span className="inline-flex bg-background px-2">URL</span>
|
|
197
|
+
</label>
|
|
198
|
+
<Input
|
|
199
|
+
id="url"
|
|
200
|
+
className="w-full"
|
|
201
|
+
value={url}
|
|
202
|
+
onChange={(e) => setUrl(e.target.value)}
|
|
203
|
+
onKeyDown={(e) => {
|
|
204
|
+
if (e.key === 'Enter') embedMedia();
|
|
205
|
+
}}
|
|
206
|
+
placeholder=""
|
|
207
|
+
type="url"
|
|
208
|
+
autoFocus
|
|
209
|
+
/>
|
|
210
|
+
</AlertDialogDescription>
|
|
211
|
+
|
|
212
|
+
<AlertDialogFooter>
|
|
213
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
214
|
+
<AlertDialogAction
|
|
215
|
+
onClick={(e) => {
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
embedMedia();
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
Accept
|
|
221
|
+
</AlertDialogAction>
|
|
222
|
+
</AlertDialogFooter>
|
|
223
|
+
</>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { WithRequiredKey } from 'platejs';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
FloatingMedia as FloatingMediaPrimitive,
|
|
7
|
+
FloatingMediaStore,
|
|
8
|
+
useFloatingMediaValue,
|
|
9
|
+
useImagePreviewValue,
|
|
10
|
+
} from '@platejs/media/react';
|
|
11
|
+
import { cva } from 'class-variance-authority';
|
|
12
|
+
import { Link, Trash2Icon } from 'lucide-react';
|
|
13
|
+
import {
|
|
14
|
+
useEditorRef,
|
|
15
|
+
useEditorSelector,
|
|
16
|
+
useElement,
|
|
17
|
+
useFocusedLast,
|
|
18
|
+
useReadOnly,
|
|
19
|
+
useRemoveNodeButton,
|
|
20
|
+
useSelected,
|
|
21
|
+
} from 'platejs/react';
|
|
22
|
+
|
|
23
|
+
import { Button, buttonVariants } from '@/components/ui/button';
|
|
24
|
+
import {
|
|
25
|
+
Popover,
|
|
26
|
+
PopoverAnchor,
|
|
27
|
+
PopoverContent,
|
|
28
|
+
} from '@/components/ui/popover';
|
|
29
|
+
import { Separator } from '@/components/ui/separator';
|
|
30
|
+
|
|
31
|
+
import { CaptionButton } from './caption';
|
|
32
|
+
|
|
33
|
+
const inputVariants = cva(
|
|
34
|
+
'flex h-[28px] w-full rounded-md border-none bg-transparent px-1.5 py-1 text-base placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-transparent md:text-sm'
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export function MediaToolbar({
|
|
38
|
+
children,
|
|
39
|
+
plugin,
|
|
40
|
+
}: {
|
|
41
|
+
children: React.ReactNode;
|
|
42
|
+
plugin: WithRequiredKey;
|
|
43
|
+
}) {
|
|
44
|
+
const editor = useEditorRef();
|
|
45
|
+
const readOnly = useReadOnly();
|
|
46
|
+
const selected = useSelected();
|
|
47
|
+
const isFocusedLast = useFocusedLast();
|
|
48
|
+
const selectionCollapsed = useEditorSelector(
|
|
49
|
+
(editor) => !editor.api.isExpanded(),
|
|
50
|
+
[]
|
|
51
|
+
);
|
|
52
|
+
const isImagePreviewOpen = useImagePreviewValue('isOpen', editor.id);
|
|
53
|
+
const open =
|
|
54
|
+
isFocusedLast &&
|
|
55
|
+
!readOnly &&
|
|
56
|
+
selected &&
|
|
57
|
+
selectionCollapsed &&
|
|
58
|
+
!isImagePreviewOpen;
|
|
59
|
+
const isEditing = useFloatingMediaValue('isEditing');
|
|
60
|
+
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (!open && isEditing) {
|
|
63
|
+
FloatingMediaStore.set('isEditing', false);
|
|
64
|
+
}
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [open]);
|
|
67
|
+
|
|
68
|
+
const element = useElement();
|
|
69
|
+
const { props: buttonProps } = useRemoveNodeButton({ element });
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Popover open={open} modal={false}>
|
|
73
|
+
<PopoverAnchor>{children}</PopoverAnchor>
|
|
74
|
+
|
|
75
|
+
<PopoverContent
|
|
76
|
+
className="w-auto p-1"
|
|
77
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
78
|
+
>
|
|
79
|
+
{isEditing ? (
|
|
80
|
+
<div className="flex w-[330px] flex-col">
|
|
81
|
+
<div className="flex items-center">
|
|
82
|
+
<div className="flex items-center pr-1 pl-2 text-muted-foreground">
|
|
83
|
+
<Link className="size-4" />
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<FloatingMediaPrimitive.UrlInput
|
|
87
|
+
className={inputVariants()}
|
|
88
|
+
placeholder="Paste the embed link..."
|
|
89
|
+
options={{ plugin }}
|
|
90
|
+
/>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
) : (
|
|
94
|
+
<div className="box-content flex items-center">
|
|
95
|
+
<FloatingMediaPrimitive.EditButton
|
|
96
|
+
className={buttonVariants({ size: 'sm', variant: 'ghost' })}
|
|
97
|
+
>
|
|
98
|
+
Edit link
|
|
99
|
+
</FloatingMediaPrimitive.EditButton>
|
|
100
|
+
|
|
101
|
+
<CaptionButton size="sm" variant="ghost">
|
|
102
|
+
Caption
|
|
103
|
+
</CaptionButton>
|
|
104
|
+
|
|
105
|
+
<Separator orientation="vertical" className="mx-1 h-6" />
|
|
106
|
+
|
|
107
|
+
<Button size="sm" variant="ghost" {...buttonProps}>
|
|
108
|
+
<Trash2Icon />
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
)}
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</Popover>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { PlaceholderPlugin, UploadErrorCode } from '@platejs/media/react';
|
|
4
|
+
import { usePluginOption } from 'platejs/react';
|
|
5
|
+
import { toast } from 'sonner';
|
|
6
|
+
|
|
7
|
+
export function MediaUploadToast() {
|
|
8
|
+
useUploadErrorToast();
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const useUploadErrorToast = () => {
|
|
14
|
+
const uploadError = usePluginOption(PlaceholderPlugin, 'error');
|
|
15
|
+
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (!uploadError) return;
|
|
18
|
+
|
|
19
|
+
const { code, data } = uploadError;
|
|
20
|
+
|
|
21
|
+
switch (code) {
|
|
22
|
+
case UploadErrorCode.INVALID_FILE_SIZE: {
|
|
23
|
+
toast.error(
|
|
24
|
+
`The size of files ${data.files
|
|
25
|
+
.map((f) => f.name)
|
|
26
|
+
.join(', ')} is invalid`
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case UploadErrorCode.INVALID_FILE_TYPE: {
|
|
32
|
+
toast.error(
|
|
33
|
+
`The type of files ${data.files
|
|
34
|
+
.map((f) => f.name)
|
|
35
|
+
.join(', ')} is invalid`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case UploadErrorCode.TOO_LARGE: {
|
|
41
|
+
toast.error(
|
|
42
|
+
`The size of files ${data.files
|
|
43
|
+
.map((f) => f.name)
|
|
44
|
+
.join(', ')} is too large than ${data.maxFileSize}`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case UploadErrorCode.TOO_LESS_FILES: {
|
|
50
|
+
toast.error(
|
|
51
|
+
`The mini um number of files is ${data.minFileCount} for ${data.fileType}`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case UploadErrorCode.TOO_MANY_FILES: {
|
|
57
|
+
toast.error(
|
|
58
|
+
`The maximum number of files is ${data.maxFileCount} ${data.fileType ? `for ${data.fileType}` : ''
|
|
59
|
+
}`
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, [uploadError]);
|
|
66
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TCaptionElement, TResizableProps, TVideoElement } from 'platejs';
|
|
2
|
+
import type { SlateElementProps } from 'platejs/static';
|
|
3
|
+
|
|
4
|
+
import { NodeApi } from 'platejs';
|
|
5
|
+
import { SlateElement } from 'platejs/static';
|
|
6
|
+
|
|
7
|
+
export function VideoElementStatic(
|
|
8
|
+
props: SlateElementProps<TVideoElement & TCaptionElement & TResizableProps>
|
|
9
|
+
) {
|
|
10
|
+
const { align = 'center', caption, url, width } = props.element;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<SlateElement className="py-2.5" {...props}>
|
|
14
|
+
<div style={{ textAlign: align }}>
|
|
15
|
+
<figure
|
|
16
|
+
className="group relative m-0 inline-block cursor-default"
|
|
17
|
+
style={{ width }}
|
|
18
|
+
>
|
|
19
|
+
<video
|
|
20
|
+
className="w-full max-w-full rounded-sm object-cover px-0"
|
|
21
|
+
src={url}
|
|
22
|
+
controls
|
|
23
|
+
/>
|
|
24
|
+
{caption && <figcaption>{NodeApi.string(caption[0])}</figcaption>}
|
|
25
|
+
</figure>
|
|
26
|
+
</div>
|
|
27
|
+
{props.children}
|
|
28
|
+
</SlateElement>
|
|
29
|
+
);
|
|
30
|
+
}
|