@collabchron/notiq 0.2.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/README.md +71 -0
- package/components.json +21 -0
- package/eslint.config.mjs +16 -0
- package/next.config.ts +12 -0
- package/package.json +108 -0
- package/postcss.config.mjs +5 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/images/icons/plus.svg +10 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/actions.ts +2 -0
- package/src/app/api/ai/route.ts +175 -0
- package/src/app/api/edgestore/[...edgestore]/route.ts +28 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +205 -0
- package/src/app/layout.tsx +38 -0
- package/src/app/page.tsx +12 -0
- package/src/components/editor/Core.tsx +220 -0
- package/src/components/editor/hooks/instructions-messages.ts +300 -0
- package/src/components/editor/hooks/use-mobile.ts +19 -0
- package/src/components/editor/hooks/useReport.ts +67 -0
- package/src/components/editor/hooks/useResizeObservert.ts +22 -0
- package/src/components/editor/index.tsx +39 -0
- package/src/components/editor/lexical-on-change.tsx +28 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +92 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +65 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +105 -0
- package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +143 -0
- package/src/components/editor/nodes/EquationNode/EquationNode.tsx +170 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +228 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +137 -0
- package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +317 -0
- package/src/components/editor/nodes/ExcalidrawNode/index.tsx +204 -0
- package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +134 -0
- package/src/components/editor/nodes/Hint/HintComponet.tsx +221 -0
- package/src/components/editor/nodes/Hint/index.tsx +190 -0
- package/src/components/editor/nodes/ImageNode/index.tsx +328 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +383 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +94 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +309 -0
- package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +146 -0
- package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +79 -0
- package/src/components/editor/nodes/PollNode/index.tsx +204 -0
- package/src/components/editor/nodes/Stepper/index.tsx +260 -0
- package/src/components/editor/nodes/TweetNode/index.tsx +214 -0
- package/src/components/editor/nodes/index.ts +81 -0
- package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +350 -0
- package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +56 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +70 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +192 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +217 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +26 -0
- package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +76 -0
- package/src/components/editor/plugins/CollapsiblePlugin/index.ts +228 -0
- package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +44 -0
- package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +52 -0
- package/src/components/editor/plugins/EquationsPlugin/index.tsx +85 -0
- package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +98 -0
- package/src/components/editor/plugins/FigmaPlugin/index.tsx +42 -0
- package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +445 -0
- package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +275 -0
- package/src/components/editor/plugins/ImagesPlugin/index.tsx +222 -0
- package/src/components/editor/plugins/InlineImagePlugin/index.tsx +351 -0
- package/src/components/editor/plugins/LayoutPlugin/index.tsx +238 -0
- package/src/components/editor/plugins/LinkPlugin/index.tsx +36 -0
- package/src/components/editor/plugins/LinkWithMetaData/index.tsx +271 -0
- package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +11 -0
- package/src/components/editor/plugins/MarkdownTransformers/index.tsx +304 -0
- package/src/components/editor/plugins/PollPlugin/index.tsx +49 -0
- package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +180 -0
- package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +253 -0
- package/src/components/editor/plugins/SlashCommand/index.tsx +621 -0
- package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +127 -0
- package/src/components/editor/plugins/TabFocusPlugin/index.ts +58 -0
- package/src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx +759 -0
- package/src/components/editor/plugins/TableCellResizer/index.tsx +438 -0
- package/src/components/editor/plugins/TableHoverActionsPlugin/index.tsx +314 -0
- package/src/components/editor/plugins/TablePlugin/index.tsx +99 -0
- package/src/components/editor/plugins/ToolbarPlugin/index.tsx +522 -0
- package/src/components/editor/plugins/TwitterPlugin/index.ts +35 -0
- package/src/components/editor/plugins/YouTubeNode/index.tsx +179 -0
- package/src/components/editor/plugins/YouTubePlugin/index.ts +41 -0
- package/src/components/editor/themes/editor-theme.ts +113 -0
- package/src/components/editor/themes/theme.css +377 -0
- package/src/components/editor/utils/ai.ts +291 -0
- package/src/components/editor/utils/canUseDOM.ts +12 -0
- package/src/components/editor/utils/editorFormatting.ts +282 -0
- package/src/components/editor/utils/environment.ts +50 -0
- package/src/components/editor/utils/extract-data.ts +166 -0
- package/src/components/editor/utils/getAllLexicalChildren.ts +13 -0
- package/src/components/editor/utils/getDOMRangeRect.ts +27 -0
- package/src/components/editor/utils/getSelectedNode.ts +27 -0
- package/src/components/editor/utils/gif.ts +29 -0
- package/src/components/editor/utils/invariant.ts +15 -0
- package/src/components/editor/utils/setFloatingElemPosition.ts +51 -0
- package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +40 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +51 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +15 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +114 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +6 -0
- package/src/components/editor/utils/url.ts +109 -0
- package/src/components/editor/utils/useLayoutEffect.ts +13 -0
- package/src/components/providers/QueryProvider.tsx +15 -0
- package/src/components/providers/SharedHistoryContext.tsx +28 -0
- package/src/components/providers/ToolbarContext.tsx +123 -0
- package/src/components/providers/theme-provider.tsx +11 -0
- package/src/components/theme/ModeToggle.tsx +40 -0
- package/src/components/ui/FileInput.tsx +40 -0
- package/src/components/ui/Input.css +32 -0
- package/src/components/ui/Select.css +42 -0
- package/src/components/ui/Select.tsx +36 -0
- package/src/components/ui/TextInput.tsx +48 -0
- package/src/components/ui/ai/ai-button.tsx +574 -0
- package/src/components/ui/ai/border.tsx +99 -0
- package/src/components/ui/ai/placeholder-input-vanish.tsx +282 -0
- package/src/components/ui/button.tsx +89 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/command.tsx +153 -0
- package/src/components/ui/dialog/Dialog.css +25 -0
- package/src/components/ui/dialog/Dialog.tsx +34 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/drop-downs/background-color.tsx +183 -0
- package/src/components/ui/drop-downs/block-format.tsx +159 -0
- package/src/components/ui/drop-downs/code.tsx +42 -0
- package/src/components/ui/drop-downs/color.tsx +177 -0
- package/src/components/ui/drop-downs/font-size.tsx +138 -0
- package/src/components/ui/drop-downs/font.tsx +155 -0
- package/src/components/ui/drop-downs/index.tsx +122 -0
- package/src/components/ui/drop-downs/insert-node.tsx +213 -0
- package/src/components/ui/drop-downs/text-align.tsx +123 -0
- package/src/components/ui/drop-downs/text-format.tsx +104 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/equation/EquationEditor.css +38 -0
- package/src/components/ui/equation/EquationEditor.tsx +56 -0
- package/src/components/ui/equation/KatexEquationAlterer.css +41 -0
- package/src/components/ui/equation/KatexEquationAlterer.tsx +83 -0
- package/src/components/ui/equation/KatexRenderer.tsx +66 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.css +64 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.tsx +234 -0
- package/src/components/ui/excalidraw/Modal.css +62 -0
- package/src/components/ui/excalidraw/Modal.tsx +110 -0
- package/src/components/ui/hover-card.tsx +29 -0
- package/src/components/ui/image/error-image.tsx +17 -0
- package/src/components/ui/image/file-upload.tsx +240 -0
- package/src/components/ui/image/image-resizer.tsx +297 -0
- package/src/components/ui/image/image-toolbar.tsx +264 -0
- package/src/components/ui/image/index.tsx +408 -0
- package/src/components/ui/image/lazy-image.tsx +68 -0
- package/src/components/ui/image/lazy-video.tsx +71 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/models/custom-dialog.tsx +320 -0
- package/src/components/ui/models/insert-gif.tsx +90 -0
- package/src/components/ui/models/insert-image.tsx +52 -0
- package/src/components/ui/models/insert-poll.tsx +29 -0
- package/src/components/ui/models/insert-table.tsx +62 -0
- package/src/components/ui/models/use-model.tsx +91 -0
- package/src/components/ui/poll/poll-component.tsx +304 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/progress.tsx +28 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/stepper/step.tsx +179 -0
- package/src/components/ui/stepper/stepper.tsx +89 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/toggle.tsx +71 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/components/ui/write/text-format-floting-toolbar.tsx +346 -0
- package/src/lib/edgestore.ts +9 -0
- package/src/lib/pinecone-client.ts +0 -0
- package/src/lib/utils.ts +6 -0
- package/src/utils/docSerialization.ts +77 -0
- package/src/utils/emoji-list.ts +16615 -0
- package/src/utils/getDOMRangeRect.ts +27 -0
- package/src/utils/getSelectedNode.ts +27 -0
- package/src/utils/getThemeSelector.ts +25 -0
- package/src/utils/isMobileWidth.ts +7 -0
- package/src/utils/joinClasses.ts +13 -0
- package/src/utils/setFloatingElemPosition.ts +74 -0
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/utils/swipe.ts +127 -0
- package/src/utils/url.ts +38 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
2
|
+
import { cn } from "@/lib/utils";
|
|
3
|
+
import { CSSProperties, JSX, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
const imageCache = new Set();
|
|
6
|
+
|
|
7
|
+
export default function LazyImage({
|
|
8
|
+
altText,
|
|
9
|
+
style,
|
|
10
|
+
imageRef,
|
|
11
|
+
src,
|
|
12
|
+
onError,
|
|
13
|
+
}: {
|
|
14
|
+
altText: string;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
imageRef: { current: null | HTMLImageElement };
|
|
17
|
+
src: string;
|
|
18
|
+
onError: () => void;
|
|
19
|
+
}): JSX.Element {
|
|
20
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (imageCache.has(src)) {
|
|
24
|
+
setIsLoading(false);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const img = new Image();
|
|
29
|
+
img.src = src;
|
|
30
|
+
|
|
31
|
+
img.onload = () => {
|
|
32
|
+
imageCache.add(src);
|
|
33
|
+
setIsLoading(false);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
img.onerror = () => {
|
|
37
|
+
imageCache.add(src);
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
onError();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return () => {
|
|
43
|
+
img.onload = null;
|
|
44
|
+
img.onerror = null;
|
|
45
|
+
};
|
|
46
|
+
}, [src, onError]);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
{isLoading && (
|
|
53
|
+
<Skeleton
|
|
54
|
+
style={style}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
<img
|
|
58
|
+
className={cn("max-w-full transition-opacity border-amber-500 border-2", isLoading ? "opacity-0" : "opacity-100")}
|
|
59
|
+
src={src}
|
|
60
|
+
alt={altText}
|
|
61
|
+
ref={imageRef}
|
|
62
|
+
style={style}
|
|
63
|
+
onError={onError}
|
|
64
|
+
draggable="false"
|
|
65
|
+
/>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
2
|
+
import { cn } from "@/lib/utils";
|
|
3
|
+
import { CSSProperties, JSX, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
const videoCache = new Set<string>();
|
|
6
|
+
|
|
7
|
+
export default function LazyVideo({
|
|
8
|
+
videoRef,
|
|
9
|
+
src,
|
|
10
|
+
style,
|
|
11
|
+
onError,
|
|
12
|
+
rounded,
|
|
13
|
+
controls = true,
|
|
14
|
+
}: {
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
videoRef: { current: null | HTMLVideoElement };
|
|
17
|
+
src: string;
|
|
18
|
+
onError: () => void;
|
|
19
|
+
rounded: number;
|
|
20
|
+
controls?: boolean;
|
|
21
|
+
}): JSX.Element {
|
|
22
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (videoCache.has(src)) {
|
|
26
|
+
setIsLoading(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Create a video element to check if it can load the source
|
|
31
|
+
const video = document.createElement("video");
|
|
32
|
+
video.src = src;
|
|
33
|
+
|
|
34
|
+
// When the video has loaded enough data to be playable, mark it as loaded
|
|
35
|
+
video.onloadeddata = () => {
|
|
36
|
+
videoCache.add(src);
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
video.onerror = () => {
|
|
41
|
+
videoCache.add(src);
|
|
42
|
+
setIsLoading(false);
|
|
43
|
+
onError();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
video.onloadeddata = null;
|
|
48
|
+
video.onerror = null;
|
|
49
|
+
};
|
|
50
|
+
}, [src, onError]);
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{isLoading && (
|
|
56
|
+
<Skeleton
|
|
57
|
+
style={style}
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
<video
|
|
61
|
+
className={cn(" transition-opacity", isLoading ? "opacity-0" : "opacity-100")}
|
|
62
|
+
src={src}
|
|
63
|
+
ref={videoRef}
|
|
64
|
+
style={style}
|
|
65
|
+
onError={onError}
|
|
66
|
+
controls={controls}
|
|
67
|
+
draggable="false"
|
|
68
|
+
/>
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
|
6
|
+
({ className, type, ...props }, ref) => {
|
|
7
|
+
return (
|
|
8
|
+
<input
|
|
9
|
+
type={type}
|
|
10
|
+
className={cn(
|
|
11
|
+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
12
|
+
className
|
|
13
|
+
)}
|
|
14
|
+
ref={ref}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
Input.displayName = "Input"
|
|
21
|
+
|
|
22
|
+
export { Input }
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { AnimatePresence, motion, Transition, Variants } from 'framer-motion';
|
|
3
|
+
import React, { createContext, useContext, useEffect, useRef } from 'react';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
import { useId } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
import { X } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
const DialogContext = createContext<{
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
setIsOpen: (open: boolean) => void;
|
|
12
|
+
dialogRef: React.RefObject<HTMLDialogElement | null>;
|
|
13
|
+
variants: Variants;
|
|
14
|
+
transition?: Transition;
|
|
15
|
+
ids: {
|
|
16
|
+
dialog: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
onAnimationComplete: (definition: string) => void;
|
|
21
|
+
handleTrigger: () => void;
|
|
22
|
+
} | null>(null);
|
|
23
|
+
|
|
24
|
+
const defaultVariants: Variants = {
|
|
25
|
+
initial: {
|
|
26
|
+
opacity: 0,
|
|
27
|
+
scale: 0.9,
|
|
28
|
+
},
|
|
29
|
+
animate: {
|
|
30
|
+
opacity: 1,
|
|
31
|
+
scale: 1,
|
|
32
|
+
},
|
|
33
|
+
exit: {
|
|
34
|
+
opacity: 0,
|
|
35
|
+
scale: 0.9,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const defaultTransition: Transition = {
|
|
40
|
+
ease: 'easeOut',
|
|
41
|
+
duration: 0.2,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type DialogProps = {
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
variants?: Variants;
|
|
47
|
+
transition?: Transition;
|
|
48
|
+
className?: string;
|
|
49
|
+
defaultOpen?: boolean;
|
|
50
|
+
onOpenChange?: (open: boolean) => void;
|
|
51
|
+
open?: boolean;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function Dialog({
|
|
55
|
+
children,
|
|
56
|
+
variants = defaultVariants,
|
|
57
|
+
transition = defaultTransition,
|
|
58
|
+
defaultOpen,
|
|
59
|
+
onOpenChange,
|
|
60
|
+
open,
|
|
61
|
+
}: DialogProps) {
|
|
62
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(
|
|
63
|
+
defaultOpen || false
|
|
64
|
+
);
|
|
65
|
+
const dialogRef = useRef<HTMLDialogElement>(null);
|
|
66
|
+
|
|
67
|
+
const isOpen = open !== undefined ? open : uncontrolledOpen;
|
|
68
|
+
|
|
69
|
+
const setIsOpen = React.useCallback(
|
|
70
|
+
(value: boolean) => {
|
|
71
|
+
// Update the uncontrolled state if `open` is not provided
|
|
72
|
+
if (open === undefined) {
|
|
73
|
+
setUncontrolledOpen(value);
|
|
74
|
+
}
|
|
75
|
+
// Notify the parent component of the state change
|
|
76
|
+
onOpenChange?.(value);
|
|
77
|
+
},
|
|
78
|
+
[open, onOpenChange]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const dialog = dialogRef.current;
|
|
83
|
+
if (!dialog) return;
|
|
84
|
+
|
|
85
|
+
if (isOpen) {
|
|
86
|
+
document.body.classList.add('overflow-hidden');
|
|
87
|
+
dialog.showModal();
|
|
88
|
+
} else {
|
|
89
|
+
document.body.classList.remove('overflow-hidden');
|
|
90
|
+
dialog.close();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const handleCancel = (e: Event) => {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
setIsOpen(false);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
dialog.addEventListener('cancel', handleCancel);
|
|
99
|
+
return () => {
|
|
100
|
+
dialog.removeEventListener('cancel', handleCancel);
|
|
101
|
+
document.body.classList.remove('overflow-hidden');
|
|
102
|
+
};
|
|
103
|
+
}, [isOpen, setIsOpen]);
|
|
104
|
+
|
|
105
|
+
const handleTrigger = () => {
|
|
106
|
+
setIsOpen(true);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const onAnimationComplete = (definition: string) => {
|
|
110
|
+
if (definition === 'exit' && !isOpen) {
|
|
111
|
+
dialogRef.current?.close();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const baseId = useId();
|
|
116
|
+
const ids = {
|
|
117
|
+
dialog: `motion-ui-dialog-${baseId}`,
|
|
118
|
+
title: `motion-ui-dialog-title-${baseId}`,
|
|
119
|
+
description: `motion-ui-dialog-description-${baseId}`,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<DialogContext.Provider
|
|
126
|
+
value={{
|
|
127
|
+
isOpen,
|
|
128
|
+
setIsOpen,
|
|
129
|
+
dialogRef,
|
|
130
|
+
variants,
|
|
131
|
+
transition,
|
|
132
|
+
ids,
|
|
133
|
+
onAnimationComplete,
|
|
134
|
+
handleTrigger,
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{children}
|
|
138
|
+
</DialogContext.Provider>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type DialogTriggerProps = {
|
|
143
|
+
children: React.ReactNode;
|
|
144
|
+
className?: string;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function DialogTrigger({ children, className }: DialogTriggerProps) {
|
|
148
|
+
const context = useContext(DialogContext);
|
|
149
|
+
if (!context) throw new Error('DialogTrigger must be used within Dialog');
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<button
|
|
153
|
+
onClick={context.handleTrigger}
|
|
154
|
+
className={cn(
|
|
155
|
+
'inline-flex items-center justify-center rounded-md text-sm font-medium',
|
|
156
|
+
'transition-colors focus-visible:outline-none focus-visible:ring-2',
|
|
157
|
+
'focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
|
158
|
+
className
|
|
159
|
+
)}
|
|
160
|
+
>
|
|
161
|
+
{children}
|
|
162
|
+
</button>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
type DialogPortalProps = {
|
|
167
|
+
children: React.ReactNode;
|
|
168
|
+
container?: HTMLElement | null;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function DialogPortal({ children }: DialogPortalProps) {
|
|
172
|
+
if (typeof window !== "undefined") {
|
|
173
|
+
return createPortal(children, document.body);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
type DialogContentProps = {
|
|
178
|
+
children: React.ReactNode;
|
|
179
|
+
className?: string;
|
|
180
|
+
container?: HTMLElement;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
function DialogContent({ children, className, container }: DialogContentProps) {
|
|
184
|
+
const context = useContext(DialogContext);
|
|
185
|
+
if (!context) throw new Error('DialogContent must be used within Dialog');
|
|
186
|
+
const {
|
|
187
|
+
isOpen,
|
|
188
|
+
setIsOpen,
|
|
189
|
+
dialogRef,
|
|
190
|
+
variants,
|
|
191
|
+
transition,
|
|
192
|
+
ids,
|
|
193
|
+
onAnimationComplete,
|
|
194
|
+
} = context;
|
|
195
|
+
|
|
196
|
+
const content = (
|
|
197
|
+
<AnimatePresence mode='wait'>
|
|
198
|
+
{isOpen && (
|
|
199
|
+
<motion.dialog
|
|
200
|
+
key={ids.dialog}
|
|
201
|
+
ref={dialogRef as React.RefObject<HTMLDialogElement>}
|
|
202
|
+
id={ids.dialog}
|
|
203
|
+
aria-labelledby={ids.title}
|
|
204
|
+
aria-describedby={ids.description}
|
|
205
|
+
aria-modal='true'
|
|
206
|
+
role='dialog'
|
|
207
|
+
onClick={(e: React.MouseEvent<HTMLDialogElement>) => {
|
|
208
|
+
if (e.target === dialogRef.current) {
|
|
209
|
+
setIsOpen(false);
|
|
210
|
+
}
|
|
211
|
+
}}
|
|
212
|
+
initial='initial'
|
|
213
|
+
animate='animate'
|
|
214
|
+
exit='exit'
|
|
215
|
+
variants={variants}
|
|
216
|
+
transition={transition}
|
|
217
|
+
onAnimationComplete={onAnimationComplete}
|
|
218
|
+
className={cn(
|
|
219
|
+
'fixed rounded-lg border z-[40] border-zinc-200 p-0 shadow-lg dark:border dark:border-zinc-700',
|
|
220
|
+
'backdrop:bg-black/50 backdrop:backdrop-blur-sm',
|
|
221
|
+
'open:flex open:flex-col',
|
|
222
|
+
className
|
|
223
|
+
)}
|
|
224
|
+
>
|
|
225
|
+
<div className='w-full'>{children}</div>
|
|
226
|
+
</motion.dialog>
|
|
227
|
+
)}
|
|
228
|
+
</AnimatePresence>
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
return <DialogPortal container={container}>{content}</DialogPortal>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
type DialogHeaderProps = {
|
|
235
|
+
children: React.ReactNode;
|
|
236
|
+
className?: string;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
function DialogHeader({ children, className }: DialogHeaderProps) {
|
|
240
|
+
return (
|
|
241
|
+
<div className={cn('flex flex-col space-y-0', className)}>{children}</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
type DialogTitleProps = {
|
|
246
|
+
children: React.ReactNode;
|
|
247
|
+
className?: string;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
function DialogTitle({ children, className }: DialogTitleProps) {
|
|
251
|
+
const context = useContext(DialogContext);
|
|
252
|
+
if (!context) throw new Error('DialogTitle must be used within Dialog');
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<h2
|
|
256
|
+
id={context.ids.title}
|
|
257
|
+
className={cn('text-base font-medium', className)}
|
|
258
|
+
>
|
|
259
|
+
{children}
|
|
260
|
+
</h2>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
type DialogDescriptionProps = {
|
|
265
|
+
children: React.ReactNode;
|
|
266
|
+
className?: string;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
function DialogDescription({ children, className }: DialogDescriptionProps) {
|
|
270
|
+
const context = useContext(DialogContext);
|
|
271
|
+
if (!context) throw new Error('DialogDescription must be used within Dialog');
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<p
|
|
275
|
+
id={context.ids.description}
|
|
276
|
+
className={cn('text-base text-zinc-500', className)}
|
|
277
|
+
>
|
|
278
|
+
{children}
|
|
279
|
+
</p>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type DialogCloseProps = {
|
|
284
|
+
className?: string;
|
|
285
|
+
children?: React.ReactNode;
|
|
286
|
+
disabled?: boolean;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
function DialogClose({ className, children, disabled }: DialogCloseProps) {
|
|
290
|
+
const context = useContext(DialogContext);
|
|
291
|
+
if (!context) throw new Error('DialogClose must be used within Dialog');
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<button
|
|
295
|
+
onClick={() => context.setIsOpen(false)}
|
|
296
|
+
type='button'
|
|
297
|
+
aria-label='Close dialog'
|
|
298
|
+
className={cn(
|
|
299
|
+
'absolute right-4 top-4 rounded-sm opacity-70 transition-opacity',
|
|
300
|
+
'hover:opacity-100 focus:outline-none focus:ring-2',
|
|
301
|
+
'focus:ring-zinc-500 focus:ring-offset-2 disabled:pointer-events-none',
|
|
302
|
+
className
|
|
303
|
+
)}
|
|
304
|
+
disabled={disabled}
|
|
305
|
+
>
|
|
306
|
+
{children || <X className='h-4 w-4' />}
|
|
307
|
+
<span className='sr-only'>Close</span>
|
|
308
|
+
</button>
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
Dialog,
|
|
314
|
+
DialogTrigger,
|
|
315
|
+
DialogContent,
|
|
316
|
+
DialogHeader,
|
|
317
|
+
DialogTitle,
|
|
318
|
+
DialogDescription,
|
|
319
|
+
DialogClose,
|
|
320
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { InsertImagePayload } from "../../editor/plugins/ImagesPlugin";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import fetchGifs from "../../editor/utils/gif";
|
|
5
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { Search, X } from "lucide-react";
|
|
8
|
+
import { Input } from "@/components/ui/input";
|
|
9
|
+
|
|
10
|
+
export interface InsertGifProps {
|
|
11
|
+
insertGifOnClick: (payload: InsertImagePayload) => void;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Gif {
|
|
16
|
+
id: string;
|
|
17
|
+
url: string;
|
|
18
|
+
alt_text: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function InsertGif({ insertGifOnClick, onClose }: InsertGifProps) {
|
|
22
|
+
const [search, setSearch] = useState("");
|
|
23
|
+
const [debouncedSearch, setDebouncedSearch] = useState("");
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const handler = setTimeout(() => {
|
|
27
|
+
setDebouncedSearch(search);
|
|
28
|
+
}, 500);
|
|
29
|
+
|
|
30
|
+
return () => clearTimeout(handler);
|
|
31
|
+
}, [search]);
|
|
32
|
+
|
|
33
|
+
const { data: gifs, isPending } = useQuery({
|
|
34
|
+
queryKey: ["gifs", debouncedSearch],
|
|
35
|
+
queryFn: async () => {
|
|
36
|
+
const { gifs } = await fetchGifs({ q: debouncedSearch || "trending" });
|
|
37
|
+
return gifs;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="flex flex-col space-y-1">
|
|
43
|
+
<form onSubmit={(e) => e.preventDefault()} className="relative mb-3">
|
|
44
|
+
<Button
|
|
45
|
+
type="submit"
|
|
46
|
+
className="absolute text-gray-500 left-1 top-[50%] -translate-y-1/2"
|
|
47
|
+
variant="ghost"
|
|
48
|
+
size="sm"
|
|
49
|
+
>
|
|
50
|
+
<Search className="w-4 h-4" />
|
|
51
|
+
</Button>
|
|
52
|
+
<Input
|
|
53
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
54
|
+
value={search}
|
|
55
|
+
placeholder="Search for GIFs"
|
|
56
|
+
className="pl-9"
|
|
57
|
+
/>
|
|
58
|
+
{search && (
|
|
59
|
+
<X
|
|
60
|
+
onClick={() => setSearch("")}
|
|
61
|
+
className="w-4 h-4 absolute cursor-pointer transition-colors text-gray-500 right-3 top-[50%] hover:text-white -translate-y-1/2"
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
</form>
|
|
65
|
+
|
|
66
|
+
<div className="grid grid-cols-3 gap-2">
|
|
67
|
+
{isPending &&
|
|
68
|
+
Array(9)
|
|
69
|
+
.fill(0)
|
|
70
|
+
.map((_, i) => <Skeleton key={i} className="rounded-md w-full h-full" />)}
|
|
71
|
+
|
|
72
|
+
{!isPending &&
|
|
73
|
+
gifs?.map((gif: Gif) => (
|
|
74
|
+
<button
|
|
75
|
+
key={gif.id}
|
|
76
|
+
onClick={() => {
|
|
77
|
+
insertGifOnClick({ src: gif.url, altText: gif.alt_text });
|
|
78
|
+
onClose();
|
|
79
|
+
}}
|
|
80
|
+
className="w-full h-full"
|
|
81
|
+
>
|
|
82
|
+
<img src={gif.url} alt={gif.alt_text} className="rounded-md w-full h-full" />
|
|
83
|
+
</button>
|
|
84
|
+
))}
|
|
85
|
+
|
|
86
|
+
{!isPending && gifs?.length === 0 && <p className="text-center text-gray-500">No GIFs found</p>}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { JSX, useEffect, useRef } from "react";
|
|
2
|
+
import { INSERT_IMAGE_COMMAND, InsertImagePayload } from "../../editor/plugins/ImagesPlugin";
|
|
3
|
+
import FileUploadZone from "../image/file-upload";
|
|
4
|
+
import { LexicalEditor } from "lexical";
|
|
5
|
+
|
|
6
|
+
export function InsertImageDialog({
|
|
7
|
+
activeEditor,
|
|
8
|
+
onClose,
|
|
9
|
+
}: {
|
|
10
|
+
activeEditor: LexicalEditor;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
}): JSX.Element {
|
|
13
|
+
const hasModifier = useRef(false);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
hasModifier.current = false;
|
|
17
|
+
const handler = (e: KeyboardEvent) => {
|
|
18
|
+
hasModifier.current = e.altKey;
|
|
19
|
+
};
|
|
20
|
+
document.addEventListener("keydown", handler);
|
|
21
|
+
return () => {
|
|
22
|
+
document.removeEventListener("keydown", handler);
|
|
23
|
+
};
|
|
24
|
+
}, [activeEditor]);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const handleInsertImage = (payload: InsertImagePayload) => {
|
|
28
|
+
activeEditor.dispatchCommand(INSERT_IMAGE_COMMAND, payload);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const InsertMedia = (files?: {url:string,alt:string}[]) => {
|
|
32
|
+
|
|
33
|
+
if (!files) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (let index = 0; index < files.length; index++) {
|
|
37
|
+
console.log(files);
|
|
38
|
+
|
|
39
|
+
const payload: InsertImagePayload = {
|
|
40
|
+
altText: files[index].alt || "image",
|
|
41
|
+
src: files[index].url ,
|
|
42
|
+
};
|
|
43
|
+
handleInsertImage(payload);
|
|
44
|
+
|
|
45
|
+
if (index === files.length - 1) {
|
|
46
|
+
onClose();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return <FileUploadZone InsertMedia={InsertMedia}/>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LexicalEditor } from "lexical";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { INSERT_POLL_COMMAND } from "../../editor/plugins/PollPlugin";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import { Input } from "@/components/ui/input";
|
|
6
|
+
|
|
7
|
+
export function InsertPoll({
|
|
8
|
+
activeEditor,
|
|
9
|
+
onClose,
|
|
10
|
+
}: {
|
|
11
|
+
activeEditor: LexicalEditor;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
}): React.JSX.Element {
|
|
14
|
+
const [question, setQuestion] = useState('');
|
|
15
|
+
|
|
16
|
+
const onClick = () => {
|
|
17
|
+
activeEditor.dispatchCommand(INSERT_POLL_COMMAND, question);
|
|
18
|
+
onClose();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className='space-y-4'>
|
|
23
|
+
<Input placeholder='Question?' onChange={(e)=>setQuestion(e.target.value)} value={question} />
|
|
24
|
+
<Button disabled={question.trim() === ''} onClick={onClick}>
|
|
25
|
+
Confirm
|
|
26
|
+
</Button>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|