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,387 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import * as ToolbarPrimitive from '@radix-ui/react-toolbar';
|
|
4
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
5
|
+
import { type VariantProps, cva } from 'class-variance-authority';
|
|
6
|
+
import { ChevronDown } from 'lucide-react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
DropdownMenuLabel,
|
|
10
|
+
DropdownMenuRadioGroup,
|
|
11
|
+
DropdownMenuSeparator,
|
|
12
|
+
} from '@/components/ui/dropdown-menu';
|
|
13
|
+
import { Separator } from '@/components/ui/separator';
|
|
14
|
+
import { Tooltip, TooltipTrigger } from '@/components/ui/tooltip';
|
|
15
|
+
import { cn } from '@/lib/utils';
|
|
16
|
+
|
|
17
|
+
export function Toolbar({
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}: React.ComponentProps<typeof ToolbarPrimitive.Root>) {
|
|
21
|
+
return (
|
|
22
|
+
<ToolbarPrimitive.Root
|
|
23
|
+
className={cn('relative flex select-none items-center', className)}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function ToolbarToggleGroup({
|
|
30
|
+
className,
|
|
31
|
+
...props
|
|
32
|
+
}: React.ComponentProps<typeof ToolbarPrimitive.ToolbarToggleGroup>) {
|
|
33
|
+
return (
|
|
34
|
+
<ToolbarPrimitive.ToolbarToggleGroup
|
|
35
|
+
className={cn('flex items-center', className)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ToolbarLink({
|
|
42
|
+
className,
|
|
43
|
+
...props
|
|
44
|
+
}: React.ComponentProps<typeof ToolbarPrimitive.Link>) {
|
|
45
|
+
return (
|
|
46
|
+
<ToolbarPrimitive.Link
|
|
47
|
+
className={cn('font-medium underline underline-offset-4', className)}
|
|
48
|
+
{...props}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function ToolbarSeparator({
|
|
54
|
+
className,
|
|
55
|
+
...props
|
|
56
|
+
}: React.ComponentProps<typeof ToolbarPrimitive.Separator>) {
|
|
57
|
+
return (
|
|
58
|
+
<ToolbarPrimitive.Separator
|
|
59
|
+
className={cn('mx-2 my-1 w-px shrink-0 bg-border', className)}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// From toggleVariants
|
|
66
|
+
const toolbarButtonVariants = cva(
|
|
67
|
+
"inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm outline-none transition-[color,box-shadow] hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-checked:bg-accent aria-checked:text-accent-foreground aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
68
|
+
{
|
|
69
|
+
defaultVariants: {
|
|
70
|
+
size: 'default',
|
|
71
|
+
variant: 'default',
|
|
72
|
+
},
|
|
73
|
+
variants: {
|
|
74
|
+
size: {
|
|
75
|
+
default: 'h-9 min-w-9 px-2',
|
|
76
|
+
lg: 'h-10 min-w-10 px-2.5',
|
|
77
|
+
sm: 'h-8 min-w-8 px-1.5',
|
|
78
|
+
},
|
|
79
|
+
variant: {
|
|
80
|
+
default: 'bg-transparent',
|
|
81
|
+
outline:
|
|
82
|
+
'border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const dropdownArrowVariants = cva(
|
|
89
|
+
cn(
|
|
90
|
+
'inline-flex items-center justify-center rounded-r-md font-medium text-foreground text-sm transition-colors disabled:pointer-events-none disabled:opacity-50'
|
|
91
|
+
),
|
|
92
|
+
{
|
|
93
|
+
defaultVariants: {
|
|
94
|
+
size: 'sm',
|
|
95
|
+
variant: 'default',
|
|
96
|
+
},
|
|
97
|
+
variants: {
|
|
98
|
+
size: {
|
|
99
|
+
default: 'h-9 w-6',
|
|
100
|
+
lg: 'h-10 w-8',
|
|
101
|
+
sm: 'h-8 w-4',
|
|
102
|
+
},
|
|
103
|
+
variant: {
|
|
104
|
+
default:
|
|
105
|
+
'bg-transparent hover:bg-muted hover:text-muted-foreground aria-checked:bg-accent aria-checked:text-accent-foreground',
|
|
106
|
+
outline:
|
|
107
|
+
'border border-input border-l-0 bg-transparent hover:bg-accent hover:text-accent-foreground',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
type ToolbarButtonProps = {
|
|
114
|
+
isDropdown?: boolean;
|
|
115
|
+
pressed?: boolean;
|
|
116
|
+
} & Omit<
|
|
117
|
+
React.ComponentPropsWithoutRef<typeof ToolbarToggleItem>,
|
|
118
|
+
'asChild' | 'value'
|
|
119
|
+
> &
|
|
120
|
+
VariantProps<typeof toolbarButtonVariants>;
|
|
121
|
+
|
|
122
|
+
export const ToolbarButton = withTooltip(function ToolbarButton({
|
|
123
|
+
children,
|
|
124
|
+
className,
|
|
125
|
+
isDropdown,
|
|
126
|
+
pressed,
|
|
127
|
+
size = 'sm',
|
|
128
|
+
variant,
|
|
129
|
+
...props
|
|
130
|
+
}: ToolbarButtonProps) {
|
|
131
|
+
return typeof pressed === 'boolean' ? (
|
|
132
|
+
<ToolbarToggleGroup disabled={props.disabled} value="single" type="single">
|
|
133
|
+
<ToolbarToggleItem
|
|
134
|
+
className={cn(
|
|
135
|
+
toolbarButtonVariants({
|
|
136
|
+
size,
|
|
137
|
+
variant,
|
|
138
|
+
}),
|
|
139
|
+
isDropdown && 'justify-between gap-1 pr-1',
|
|
140
|
+
className
|
|
141
|
+
)}
|
|
142
|
+
value={pressed ? 'single' : ''}
|
|
143
|
+
{...props}
|
|
144
|
+
>
|
|
145
|
+
{isDropdown ? (
|
|
146
|
+
<>
|
|
147
|
+
<div className="flex flex-1 items-center gap-2 whitespace-nowrap">
|
|
148
|
+
{children}
|
|
149
|
+
</div>
|
|
150
|
+
<div>
|
|
151
|
+
<ChevronDown
|
|
152
|
+
className="size-3.5 text-muted-foreground"
|
|
153
|
+
data-icon
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
</>
|
|
157
|
+
) : (
|
|
158
|
+
children
|
|
159
|
+
)}
|
|
160
|
+
</ToolbarToggleItem>
|
|
161
|
+
</ToolbarToggleGroup>
|
|
162
|
+
) : (
|
|
163
|
+
<ToolbarPrimitive.Button
|
|
164
|
+
className={cn(
|
|
165
|
+
toolbarButtonVariants({
|
|
166
|
+
size,
|
|
167
|
+
variant,
|
|
168
|
+
}),
|
|
169
|
+
isDropdown && 'pr-1',
|
|
170
|
+
className
|
|
171
|
+
)}
|
|
172
|
+
{...props}
|
|
173
|
+
>
|
|
174
|
+
{children}
|
|
175
|
+
</ToolbarPrimitive.Button>
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export function ToolbarSplitButton({
|
|
180
|
+
className,
|
|
181
|
+
...props
|
|
182
|
+
}: React.ComponentPropsWithoutRef<typeof ToolbarButton>) {
|
|
183
|
+
return (
|
|
184
|
+
<ToolbarButton
|
|
185
|
+
className={cn('group flex gap-0 px-0 hover:bg-transparent', className)}
|
|
186
|
+
{...props}
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
type ToolbarSplitButtonPrimaryProps = Omit<
|
|
192
|
+
React.ComponentPropsWithoutRef<typeof ToolbarToggleItem>,
|
|
193
|
+
'value'
|
|
194
|
+
> &
|
|
195
|
+
VariantProps<typeof toolbarButtonVariants>;
|
|
196
|
+
|
|
197
|
+
export function ToolbarSplitButtonPrimary({
|
|
198
|
+
children,
|
|
199
|
+
className,
|
|
200
|
+
size = 'sm',
|
|
201
|
+
variant,
|
|
202
|
+
...props
|
|
203
|
+
}: ToolbarSplitButtonPrimaryProps) {
|
|
204
|
+
return (
|
|
205
|
+
<span
|
|
206
|
+
className={cn(
|
|
207
|
+
toolbarButtonVariants({
|
|
208
|
+
size,
|
|
209
|
+
variant,
|
|
210
|
+
}),
|
|
211
|
+
'rounded-r-none',
|
|
212
|
+
'group-data-[pressed=true]:bg-accent group-data-[pressed=true]:text-accent-foreground',
|
|
213
|
+
className
|
|
214
|
+
)}
|
|
215
|
+
{...props}
|
|
216
|
+
>
|
|
217
|
+
{children}
|
|
218
|
+
</span>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function ToolbarSplitButtonSecondary({
|
|
223
|
+
className,
|
|
224
|
+
size,
|
|
225
|
+
variant,
|
|
226
|
+
...props
|
|
227
|
+
}: React.ComponentPropsWithoutRef<'span'> &
|
|
228
|
+
VariantProps<typeof dropdownArrowVariants>) {
|
|
229
|
+
return (
|
|
230
|
+
<span
|
|
231
|
+
className={cn(
|
|
232
|
+
dropdownArrowVariants({
|
|
233
|
+
size,
|
|
234
|
+
variant,
|
|
235
|
+
}),
|
|
236
|
+
'group-data-[pressed=true]:bg-accent group-data-[pressed=true]:text-accent-foreground',
|
|
237
|
+
className
|
|
238
|
+
)}
|
|
239
|
+
onClick={(e) => e.stopPropagation()}
|
|
240
|
+
role="button"
|
|
241
|
+
{...props}
|
|
242
|
+
>
|
|
243
|
+
<ChevronDown className="size-3.5 text-muted-foreground" data-icon />
|
|
244
|
+
</span>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function ToolbarToggleItem({
|
|
249
|
+
className,
|
|
250
|
+
size = 'sm',
|
|
251
|
+
variant,
|
|
252
|
+
...props
|
|
253
|
+
}: React.ComponentProps<typeof ToolbarPrimitive.ToggleItem> &
|
|
254
|
+
VariantProps<typeof toolbarButtonVariants>) {
|
|
255
|
+
return (
|
|
256
|
+
<ToolbarPrimitive.ToggleItem
|
|
257
|
+
className={cn(toolbarButtonVariants({ size, variant }), className)}
|
|
258
|
+
{...props}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function ToolbarGroup({
|
|
264
|
+
children,
|
|
265
|
+
className,
|
|
266
|
+
}: React.ComponentProps<'div'>) {
|
|
267
|
+
return (
|
|
268
|
+
<div
|
|
269
|
+
className={cn(
|
|
270
|
+
'group/toolbar-group',
|
|
271
|
+
'relative hidden has-[button]:flex',
|
|
272
|
+
className
|
|
273
|
+
)}
|
|
274
|
+
>
|
|
275
|
+
<div className="flex items-center">{children}</div>
|
|
276
|
+
|
|
277
|
+
<div className="group-last/toolbar-group:hidden! mx-1.5 py-0.5">
|
|
278
|
+
<Separator orientation="vertical" />
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
type TooltipProps<T extends React.ElementType> = {
|
|
285
|
+
tooltip?: React.ReactNode;
|
|
286
|
+
tooltipContentProps?: Omit<
|
|
287
|
+
React.ComponentPropsWithoutRef<typeof TooltipContent>,
|
|
288
|
+
'children'
|
|
289
|
+
>;
|
|
290
|
+
tooltipProps?: Omit<
|
|
291
|
+
React.ComponentPropsWithoutRef<typeof Tooltip>,
|
|
292
|
+
'children'
|
|
293
|
+
>;
|
|
294
|
+
tooltipTriggerProps?: React.ComponentPropsWithoutRef<typeof TooltipTrigger>;
|
|
295
|
+
} & React.ComponentProps<T>;
|
|
296
|
+
|
|
297
|
+
function withTooltip<T extends React.ElementType>(Component: T) {
|
|
298
|
+
return function ExtendComponent({
|
|
299
|
+
tooltip,
|
|
300
|
+
tooltipContentProps,
|
|
301
|
+
tooltipProps,
|
|
302
|
+
tooltipTriggerProps,
|
|
303
|
+
...props
|
|
304
|
+
}: TooltipProps<T>) {
|
|
305
|
+
const [mounted, setMounted] = React.useState(false);
|
|
306
|
+
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
setMounted(true);
|
|
309
|
+
}, []);
|
|
310
|
+
|
|
311
|
+
const component = <Component {...(props as React.ComponentProps<T>)} />;
|
|
312
|
+
|
|
313
|
+
if (tooltip && mounted) {
|
|
314
|
+
return (
|
|
315
|
+
<Tooltip {...tooltipProps}>
|
|
316
|
+
<TooltipTrigger asChild {...tooltipTriggerProps}>
|
|
317
|
+
{component}
|
|
318
|
+
</TooltipTrigger>
|
|
319
|
+
|
|
320
|
+
<TooltipContent {...tooltipContentProps}>{tooltip}</TooltipContent>
|
|
321
|
+
</Tooltip>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return component;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function TooltipContent({
|
|
330
|
+
children,
|
|
331
|
+
className,
|
|
332
|
+
// CHANGE
|
|
333
|
+
sideOffset = 4,
|
|
334
|
+
...props
|
|
335
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
|
336
|
+
return (
|
|
337
|
+
<TooltipPrimitive.Portal>
|
|
338
|
+
<TooltipPrimitive.Content
|
|
339
|
+
className={cn(
|
|
340
|
+
'z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance rounded-md bg-primary px-3 py-1.5 text-primary-foreground text-xs',
|
|
341
|
+
className
|
|
342
|
+
)}
|
|
343
|
+
data-slot="tooltip-content"
|
|
344
|
+
sideOffset={sideOffset}
|
|
345
|
+
{...props}
|
|
346
|
+
>
|
|
347
|
+
{children}
|
|
348
|
+
{/* CHANGE */}
|
|
349
|
+
{/* <TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-primary fill-primary" /> */}
|
|
350
|
+
</TooltipPrimitive.Content>
|
|
351
|
+
</TooltipPrimitive.Portal>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function ToolbarMenuGroup({
|
|
356
|
+
children,
|
|
357
|
+
className,
|
|
358
|
+
label,
|
|
359
|
+
...props
|
|
360
|
+
}: React.ComponentProps<typeof DropdownMenuRadioGroup> & { label?: string }) {
|
|
361
|
+
return (
|
|
362
|
+
<>
|
|
363
|
+
<DropdownMenuSeparator
|
|
364
|
+
className={cn(
|
|
365
|
+
'hidden',
|
|
366
|
+
'mb-0 shrink-0 peer-has-[[role=menuitem]]/menu-group:block peer-has-[[role=menuitemradio]]/menu-group:block peer-has-[[role=option]]/menu-group:block'
|
|
367
|
+
)}
|
|
368
|
+
/>
|
|
369
|
+
|
|
370
|
+
<DropdownMenuRadioGroup
|
|
371
|
+
{...props}
|
|
372
|
+
className={cn(
|
|
373
|
+
'hidden',
|
|
374
|
+
'peer/menu-group group/menu-group my-1.5 has-[[role=menuitem]]:block has-[[role=menuitemradio]]:block has-[[role=option]]:block',
|
|
375
|
+
className
|
|
376
|
+
)}
|
|
377
|
+
>
|
|
378
|
+
{label && (
|
|
379
|
+
<DropdownMenuLabel className="select-none font-semibold text-muted-foreground text-xs">
|
|
380
|
+
{label}
|
|
381
|
+
</DropdownMenuLabel>
|
|
382
|
+
)}
|
|
383
|
+
{children}
|
|
384
|
+
</DropdownMenuRadioGroup>
|
|
385
|
+
</>
|
|
386
|
+
);
|
|
387
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
function TooltipProvider({
|
|
7
|
+
delayDuration = 0,
|
|
8
|
+
...props
|
|
9
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
|
10
|
+
return (
|
|
11
|
+
<TooltipPrimitive.Provider
|
|
12
|
+
data-slot="tooltip-provider"
|
|
13
|
+
delayDuration={delayDuration}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function Tooltip({
|
|
20
|
+
...props
|
|
21
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
|
22
|
+
return (
|
|
23
|
+
<TooltipProvider>
|
|
24
|
+
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
|
25
|
+
</TooltipProvider>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function TooltipTrigger({
|
|
30
|
+
...props
|
|
31
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
|
32
|
+
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function TooltipContent({
|
|
36
|
+
className,
|
|
37
|
+
sideOffset = 0,
|
|
38
|
+
children,
|
|
39
|
+
...props
|
|
40
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
|
41
|
+
return (
|
|
42
|
+
<TooltipPrimitive.Portal>
|
|
43
|
+
<TooltipPrimitive.Content
|
|
44
|
+
data-slot="tooltip-content"
|
|
45
|
+
sideOffset={sideOffset}
|
|
46
|
+
className={cn(
|
|
47
|
+
"bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
|
48
|
+
className
|
|
49
|
+
)}
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
<TooltipPrimitive.Arrow className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
|
54
|
+
</TooltipPrimitive.Content>
|
|
55
|
+
</TooltipPrimitive.Portal>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';
|
|
4
|
+
import type { TElement } from 'platejs';
|
|
5
|
+
|
|
6
|
+
import { DropdownMenuItemIndicator } from '@radix-ui/react-dropdown-menu';
|
|
7
|
+
import {
|
|
8
|
+
CheckIcon,
|
|
9
|
+
ChevronRightIcon,
|
|
10
|
+
Columns3Icon,
|
|
11
|
+
FileCodeIcon,
|
|
12
|
+
Heading1Icon,
|
|
13
|
+
Heading2Icon,
|
|
14
|
+
Heading3Icon,
|
|
15
|
+
Heading4Icon,
|
|
16
|
+
Heading5Icon,
|
|
17
|
+
Heading6Icon,
|
|
18
|
+
ListIcon,
|
|
19
|
+
ListOrderedIcon,
|
|
20
|
+
PilcrowIcon,
|
|
21
|
+
QuoteIcon,
|
|
22
|
+
SquareIcon,
|
|
23
|
+
} from 'lucide-react';
|
|
24
|
+
import { KEYS } from 'platejs';
|
|
25
|
+
import { useEditorRef, useSelectionFragmentProp } from 'platejs/react';
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
DropdownMenu,
|
|
29
|
+
DropdownMenuContent,
|
|
30
|
+
DropdownMenuRadioItem,
|
|
31
|
+
DropdownMenuTrigger,
|
|
32
|
+
} from '@/components/ui/dropdown-menu';
|
|
33
|
+
import {
|
|
34
|
+
getBlockType,
|
|
35
|
+
setBlockType,
|
|
36
|
+
} from '@/components/editor/transforms';
|
|
37
|
+
|
|
38
|
+
import { ToolbarButton, ToolbarMenuGroup } from './toolbar';
|
|
39
|
+
|
|
40
|
+
export const turnIntoItems = [
|
|
41
|
+
{
|
|
42
|
+
icon: <PilcrowIcon />,
|
|
43
|
+
keywords: ['paragraph'],
|
|
44
|
+
label: 'Text',
|
|
45
|
+
value: KEYS.p,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
icon: <Heading1Icon />,
|
|
49
|
+
keywords: ['title', 'h1'],
|
|
50
|
+
label: 'Heading 1',
|
|
51
|
+
value: 'h1',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
icon: <Heading2Icon />,
|
|
55
|
+
keywords: ['subtitle', 'h2'],
|
|
56
|
+
label: 'Heading 2',
|
|
57
|
+
value: 'h2',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
icon: <Heading3Icon />,
|
|
61
|
+
keywords: ['subtitle', 'h3'],
|
|
62
|
+
label: 'Heading 3',
|
|
63
|
+
value: 'h3',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
icon: <Heading4Icon />,
|
|
67
|
+
keywords: ['subtitle', 'h4'],
|
|
68
|
+
label: 'Heading 4',
|
|
69
|
+
value: 'h4',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
icon: <Heading5Icon />,
|
|
73
|
+
keywords: ['subtitle', 'h5'],
|
|
74
|
+
label: 'Heading 5',
|
|
75
|
+
value: 'h5',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
icon: <Heading6Icon />,
|
|
79
|
+
keywords: ['subtitle', 'h6'],
|
|
80
|
+
label: 'Heading 6',
|
|
81
|
+
value: 'h6',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
icon: <ListIcon />,
|
|
85
|
+
keywords: ['unordered', 'ul', '-'],
|
|
86
|
+
label: 'Bulleted list',
|
|
87
|
+
value: KEYS.ul,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
icon: <ListOrderedIcon />,
|
|
91
|
+
keywords: ['ordered', 'ol', '1'],
|
|
92
|
+
label: 'Numbered list',
|
|
93
|
+
value: KEYS.ol,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
icon: <SquareIcon />,
|
|
97
|
+
keywords: ['checklist', 'task', 'checkbox', '[]'],
|
|
98
|
+
label: 'To-do list',
|
|
99
|
+
value: KEYS.listTodo,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
icon: <ChevronRightIcon />,
|
|
103
|
+
keywords: ['collapsible', 'expandable'],
|
|
104
|
+
label: 'Toggle list',
|
|
105
|
+
value: KEYS.toggle,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
icon: <FileCodeIcon />,
|
|
109
|
+
keywords: ['```'],
|
|
110
|
+
label: 'Code',
|
|
111
|
+
value: KEYS.codeBlock,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
icon: <QuoteIcon />,
|
|
115
|
+
keywords: ['citation', 'blockquote', '>'],
|
|
116
|
+
label: 'Quote',
|
|
117
|
+
value: KEYS.blockquote,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
icon: <Columns3Icon />,
|
|
121
|
+
label: '3 columns',
|
|
122
|
+
value: 'action_three_columns',
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
export function TurnIntoToolbarButton(props: DropdownMenuProps) {
|
|
127
|
+
const editor = useEditorRef();
|
|
128
|
+
const [open, setOpen] = React.useState(false);
|
|
129
|
+
|
|
130
|
+
const value = useSelectionFragmentProp({
|
|
131
|
+
defaultValue: KEYS.p,
|
|
132
|
+
getProp: (node) => getBlockType(node as TElement),
|
|
133
|
+
});
|
|
134
|
+
const selectedItem = React.useMemo(
|
|
135
|
+
() =>
|
|
136
|
+
turnIntoItems.find((item) => item.value === (value ?? KEYS.p)) ??
|
|
137
|
+
turnIntoItems[0],
|
|
138
|
+
[value]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<DropdownMenu open={open} onOpenChange={setOpen} modal={false} {...props}>
|
|
143
|
+
<DropdownMenuTrigger asChild>
|
|
144
|
+
<ToolbarButton
|
|
145
|
+
className="min-w-[125px]"
|
|
146
|
+
pressed={open}
|
|
147
|
+
tooltip="Turn into"
|
|
148
|
+
isDropdown
|
|
149
|
+
>
|
|
150
|
+
{selectedItem.label}
|
|
151
|
+
</ToolbarButton>
|
|
152
|
+
</DropdownMenuTrigger>
|
|
153
|
+
|
|
154
|
+
<DropdownMenuContent
|
|
155
|
+
className="ignore-click-outside/toolbar min-w-0"
|
|
156
|
+
onCloseAutoFocus={(e) => {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
editor.tf.focus();
|
|
159
|
+
}}
|
|
160
|
+
align="start"
|
|
161
|
+
>
|
|
162
|
+
<ToolbarMenuGroup
|
|
163
|
+
value={value}
|
|
164
|
+
onValueChange={(type) => {
|
|
165
|
+
setBlockType(editor, type);
|
|
166
|
+
}}
|
|
167
|
+
label="Turn into"
|
|
168
|
+
>
|
|
169
|
+
{turnIntoItems.map(({ icon, label, value: itemValue }) => (
|
|
170
|
+
<DropdownMenuRadioItem
|
|
171
|
+
key={itemValue}
|
|
172
|
+
className="min-w-[180px] pl-2 *:first:[span]:hidden"
|
|
173
|
+
value={itemValue}
|
|
174
|
+
>
|
|
175
|
+
<span className="pointer-events-none absolute right-2 flex size-3.5 items-center justify-center">
|
|
176
|
+
<DropdownMenuItemIndicator>
|
|
177
|
+
<CheckIcon />
|
|
178
|
+
</DropdownMenuItemIndicator>
|
|
179
|
+
</span>
|
|
180
|
+
{icon}
|
|
181
|
+
{label}
|
|
182
|
+
</DropdownMenuRadioItem>
|
|
183
|
+
))}
|
|
184
|
+
</ToolbarMenuGroup>
|
|
185
|
+
</DropdownMenuContent>
|
|
186
|
+
</DropdownMenu>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export const useDebounce = <T>(value: T, delay = 500) => {
|
|
4
|
+
const [debouncedValue, setDebouncedValue] = React.useState(value);
|
|
5
|
+
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
const handler: NodeJS.Timeout = setTimeout(() => {
|
|
8
|
+
setDebouncedValue(value);
|
|
9
|
+
}, delay);
|
|
10
|
+
|
|
11
|
+
// Cancel the timeout if value changes (also on delay change or unmount)
|
|
12
|
+
return () => {
|
|
13
|
+
clearTimeout(handler);
|
|
14
|
+
};
|
|
15
|
+
}, [value, delay]);
|
|
16
|
+
|
|
17
|
+
return debouncedValue;
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function useIsTouchDevice() {
|
|
4
|
+
const [isTouchDevice, setIsTouchDevice] = React.useState(false);
|
|
5
|
+
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
function onResize() {
|
|
8
|
+
setIsTouchDevice(
|
|
9
|
+
'ontouchstart' in window ||
|
|
10
|
+
navigator.maxTouchPoints > 0 ||
|
|
11
|
+
navigator.maxTouchPoints > 0
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
window.addEventListener('resize', onResize);
|
|
16
|
+
onResize();
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
window.removeEventListener('resize', onResize);
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return isTouchDevice;
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
const MOBILE_BREAKPOINT = 768
|
|
4
|
+
|
|
5
|
+
export function useIsMobile() {
|
|
6
|
+
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
|
7
|
+
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
10
|
+
const onChange = () => {
|
|
11
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
12
|
+
}
|
|
13
|
+
mql.addEventListener("change", onChange)
|
|
14
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
15
|
+
return () => mql.removeEventListener("change", onChange)
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
return !!isMobile
|
|
19
|
+
}
|