Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
-145
@@ -1,145 +0,0 @@
|
||||
/**
|
||||
* Shared types between the API and UI packages.
|
||||
*/
|
||||
export type Message = {
|
||||
id: string;
|
||||
createdAt?: Date;
|
||||
content: string;
|
||||
role: "system" | "user" | "assistant";
|
||||
};
|
||||
|
||||
export type CreateMessage = {
|
||||
id?: string;
|
||||
createdAt?: Date;
|
||||
content: string;
|
||||
role: "system" | "user" | "assistant";
|
||||
};
|
||||
|
||||
export type RequestOptions = {
|
||||
headers?: Record<string, string> | Headers;
|
||||
body?: object;
|
||||
};
|
||||
|
||||
export type UseChatOptions = {
|
||||
/**
|
||||
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
||||
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
||||
*/
|
||||
api?: string;
|
||||
|
||||
/**
|
||||
* An unique identifier for the chat. If not provided, a random one will be
|
||||
* generated. When provided, the `useChat` hook with the same `id` will
|
||||
* have shared states across components.
|
||||
*/
|
||||
id?: string;
|
||||
|
||||
/**
|
||||
* Initial messages of the chat. Useful to load an existing chat history.
|
||||
*/
|
||||
initialMessages?: Message[];
|
||||
|
||||
/**
|
||||
* Initial input of the chat.
|
||||
*/
|
||||
initialInput?: string;
|
||||
|
||||
/**
|
||||
* Callback function to be called when the API response is received.
|
||||
*/
|
||||
onResponse?: (response: Response) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* Callback function to be called when the chat is finished streaming.
|
||||
*/
|
||||
onFinish?: (message: Message) => void;
|
||||
|
||||
/**
|
||||
* Callback function to be called when an error is encountered.
|
||||
*/
|
||||
onError?: (error: Error) => void;
|
||||
|
||||
/**
|
||||
* HTTP headers to be sent with the API request.
|
||||
*/
|
||||
headers?: Record<string, string> | Headers;
|
||||
|
||||
/**
|
||||
* Extra body object to be sent with the API request.
|
||||
* @example
|
||||
* Send a `sessionId` to the API along with the messages.
|
||||
* ```js
|
||||
* useChat({
|
||||
* body: {
|
||||
* sessionId: '123',
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
body?: object;
|
||||
|
||||
/**
|
||||
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
||||
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
||||
* handle the extra fields before forwarding the request to the AI service.
|
||||
*/
|
||||
sendExtraMessageFields?: boolean;
|
||||
};
|
||||
|
||||
export type UseCompletionOptions = {
|
||||
/**
|
||||
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
||||
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
||||
*/
|
||||
api: string;
|
||||
/**
|
||||
* An unique identifier for the chat. If not provided, a random one will be
|
||||
* generated. When provided, the `useChat` hook with the same `id` will
|
||||
* have shared states across components.
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Initial prompt input of the completion.
|
||||
*/
|
||||
initialInput?: string;
|
||||
|
||||
/**
|
||||
* Initial completion result. Useful to load an existing history.
|
||||
*/
|
||||
initialCompletion?: string;
|
||||
|
||||
/**
|
||||
* Callback function to be called when the API response is received.
|
||||
*/
|
||||
onResponse?: (response: Response) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* Callback function to be called when the completion is finished streaming.
|
||||
*/
|
||||
onFinish?: (prompt: string, completion: string) => void;
|
||||
|
||||
/**
|
||||
* Callback function to be called when an error is encountered.
|
||||
*/
|
||||
onError?: (error: Error) => void;
|
||||
|
||||
/**
|
||||
* HTTP headers to be sent with the API request.
|
||||
*/
|
||||
headers?: Record<string, string> | Headers;
|
||||
|
||||
/**
|
||||
* Extra body object to be sent with the API request.
|
||||
* @example
|
||||
* Send a `sessionId` to the API along with the prompt.
|
||||
* ```js
|
||||
* useChat({
|
||||
* body: {
|
||||
* sessionId: '123',
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
body?: object;
|
||||
};
|
||||
-238
@@ -1,238 +0,0 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { t as i18nT } from "i18next";
|
||||
import useSWRMutation from "swr/mutation";
|
||||
import useSWR from "swr";
|
||||
|
||||
import { createChunkDecoder } from "./utils";
|
||||
import { UseCompletionOptions, RequestOptions } from "./types";
|
||||
|
||||
export type UseCompletionHelpers = {
|
||||
/** The current completion result */
|
||||
completion: string;
|
||||
/**
|
||||
* Send a new prompt to the API endpoint and update the completion state.
|
||||
*/
|
||||
complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
|
||||
/** The error object of the API request */
|
||||
error: undefined | Error;
|
||||
/**
|
||||
* Abort the current API request but keep the generated tokens.
|
||||
*/
|
||||
stop: () => void;
|
||||
/**
|
||||
* Update the `completion` state locally.
|
||||
*/
|
||||
setCompletion: (completion: string) => void;
|
||||
/** The current value of the input */
|
||||
input: string;
|
||||
/** setState-powered method to update the input value */
|
||||
setInput: React.Dispatch<React.SetStateAction<string>>;
|
||||
/**
|
||||
* An input/textarea-ready onChange handler to control the value of the input
|
||||
* @example
|
||||
* ```jsx
|
||||
* <input onChange={handleInputChange} value={input} />
|
||||
* ```
|
||||
*/
|
||||
handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
||||
/**
|
||||
* Form submission handler to automattically reset input and append a user message
|
||||
* @example
|
||||
* ```jsx
|
||||
* <form onSubmit={handleSubmit}>
|
||||
* <input onChange={handleInputChange} value={input} />
|
||||
* </form>
|
||||
* ```
|
||||
*/
|
||||
handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
|
||||
/** Whether the API request is in progress */
|
||||
isLoading: boolean;
|
||||
};
|
||||
|
||||
export function useCompletion({
|
||||
api,
|
||||
id,
|
||||
initialCompletion = "",
|
||||
initialInput = "",
|
||||
headers,
|
||||
body,
|
||||
onResponse,
|
||||
onFinish,
|
||||
onError,
|
||||
}: UseCompletionOptions): UseCompletionHelpers {
|
||||
// Generate an unique id for the completion if not provided.
|
||||
const completionId = id;
|
||||
|
||||
// Store the completion state in SWR, using the completionId as the key to share states.
|
||||
const { data, mutate } = useSWR<string>([api, completionId], null, {
|
||||
fallbackData: initialCompletion,
|
||||
});
|
||||
const completion = data!;
|
||||
|
||||
// Abort controller to cancel the current API call.
|
||||
const [abortController, setAbortController] = useState<AbortController | null>(null);
|
||||
|
||||
const extraMetadataRef = useRef<any>({
|
||||
headers,
|
||||
body,
|
||||
});
|
||||
useEffect(() => {
|
||||
extraMetadataRef.current = {
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
}, [headers, body]);
|
||||
|
||||
// Actual mutation hook to send messages to the API endpoint and update the
|
||||
// chat state.
|
||||
const { error, trigger, isMutating } = useSWRMutation<
|
||||
string | null,
|
||||
any,
|
||||
[string, string],
|
||||
{
|
||||
prompt: string;
|
||||
options?: RequestOptions;
|
||||
}
|
||||
>(
|
||||
[api, completionId],
|
||||
async (_, { arg }) => {
|
||||
try {
|
||||
const { prompt, options } = arg;
|
||||
|
||||
const abortController = new AbortController();
|
||||
setAbortController(abortController);
|
||||
|
||||
// Empty the completion immediately.
|
||||
mutate("", false);
|
||||
|
||||
const res = await fetch(api, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
prompt,
|
||||
...extraMetadataRef.current.body,
|
||||
...options?.body,
|
||||
}),
|
||||
headers: {
|
||||
...extraMetadataRef.current.headers,
|
||||
...options?.headers,
|
||||
},
|
||||
signal: abortController.signal,
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
if (onResponse) {
|
||||
try {
|
||||
await onResponse(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error((await res.text()) || i18nT("novel.editor.errors.fetchFailed"));
|
||||
}
|
||||
|
||||
if (!res.body) {
|
||||
throw new Error(i18nT("novel.editor.errors.emptyResponse"));
|
||||
}
|
||||
|
||||
let result = "";
|
||||
const reader = res.body.getReader();
|
||||
const decoder = createChunkDecoder();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the completion state with the new message tokens.
|
||||
result += decoder(value);
|
||||
mutate(result, false);
|
||||
|
||||
// The request has been aborted, stop reading the stream.
|
||||
if (abortController === null) {
|
||||
reader.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (onFinish) {
|
||||
onFinish(prompt, result);
|
||||
}
|
||||
|
||||
setAbortController(null);
|
||||
return result;
|
||||
} catch (err) {
|
||||
// Ignore abort errors as they are expected.
|
||||
if ((err as any).name === "AbortError") {
|
||||
setAbortController(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (onError && err instanceof Error) {
|
||||
onError(err);
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
{
|
||||
populateCache: false,
|
||||
revalidate: false,
|
||||
}
|
||||
);
|
||||
|
||||
const stop = useCallback(() => {
|
||||
if (abortController) {
|
||||
abortController.abort();
|
||||
setAbortController(null);
|
||||
}
|
||||
}, [abortController]);
|
||||
|
||||
const setCompletion = useCallback(
|
||||
(completion: string) => {
|
||||
mutate(completion, false);
|
||||
},
|
||||
[mutate]
|
||||
);
|
||||
|
||||
const complete = useCallback<UseCompletionHelpers["complete"]>(
|
||||
async (prompt, options) => {
|
||||
return trigger({
|
||||
prompt,
|
||||
options,
|
||||
});
|
||||
},
|
||||
[trigger]
|
||||
);
|
||||
|
||||
const [input, setInput] = useState(initialInput);
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
if (!input) return;
|
||||
return complete(input);
|
||||
},
|
||||
[input, complete]
|
||||
);
|
||||
|
||||
const handleInputChange = (e: any) => {
|
||||
setInput(e.target.value);
|
||||
};
|
||||
|
||||
return {
|
||||
completion,
|
||||
complete,
|
||||
error,
|
||||
setCompletion,
|
||||
stop,
|
||||
input,
|
||||
setInput,
|
||||
handleInputChange,
|
||||
handleSubmit,
|
||||
isLoading: isMutating,
|
||||
};
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
import { customAlphabet } from "nanoid";
|
||||
|
||||
// 7-character random string
|
||||
export const nanoid = customAlphabet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 7);
|
||||
|
||||
export function createChunkDecoder() {
|
||||
const decoder = new TextDecoder();
|
||||
return function (chunk: Uint8Array | undefined): string {
|
||||
if (!chunk) return "";
|
||||
return decoder.decode(chunk, { stream: true });
|
||||
};
|
||||
}
|
||||
+16
-70
@@ -1,15 +1,8 @@
|
||||
import { EditorView } from "@tiptap/pm/view";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
import { toast } from "sonner";
|
||||
import { apiPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
export type ImageUploadOptions = {
|
||||
apiBaseUrl?: string;
|
||||
tenantSlug?: string | null;
|
||||
tenantId?: string | null;
|
||||
};
|
||||
|
||||
export const handleImageUpload = (file: File, view: EditorView, event: ClipboardEvent | DragEvent | Event, options: ImageUploadOptions = {}) => {
|
||||
export const handleImageUpload = (file: File, view: EditorView, event: ClipboardEvent | DragEvent | Event) => {
|
||||
// check if the file is an image
|
||||
if (!file.type.includes("image/")) {
|
||||
toast.error(i18nT("novel.editor.upload.unsupportedType"));
|
||||
@@ -18,69 +11,22 @@ export const handleImageUpload = (file: File, view: EditorView, event: Clipboard
|
||||
} else if (file.size / 1024 / 1024 > 50) {
|
||||
toast.error(i18nT("novel.editor.upload.tooLarge"));
|
||||
} else {
|
||||
// const reader = new FileReader();
|
||||
// reader.onload = (e) => {
|
||||
// const { schema } = view.state;
|
||||
// const node = schema.nodes.image.create({
|
||||
// src: e.target?.result,
|
||||
// alt: file,
|
||||
// title: file.name,
|
||||
// }); // creates the image element
|
||||
// const transaction = view.state.tr.replaceSelectionWith(node);
|
||||
// view.dispatch(transaction);
|
||||
// };
|
||||
// reader.readAsDataURL(file);
|
||||
|
||||
const tenantId = options.tenantId ?? "";
|
||||
const uploadUrl = options.apiBaseUrl && tenantId ? new URL(apiPath("ai/upload", { mode: "host-aware" }), options.apiBaseUrl).toString() : null;
|
||||
if (!uploadUrl) {
|
||||
toast.error(i18nT("novel.editor.upload.unavailable"));
|
||||
return;
|
||||
}
|
||||
|
||||
toast.promise(
|
||||
fetch(uploadUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": file?.type || "application/octet-stream",
|
||||
"x-filename": file?.name || "image.png",
|
||||
"x-tenant-id": tenantId,
|
||||
},
|
||||
body: file,
|
||||
}).then(async (res) => {
|
||||
// Successfully uploaded image
|
||||
if (res.status === 200) {
|
||||
const { url } = await res.json();
|
||||
// preload the image
|
||||
let image = new Image();
|
||||
image.src = url;
|
||||
image.onload = () => {
|
||||
insertImage(url);
|
||||
};
|
||||
|
||||
// No blob store configured
|
||||
} else if (res.status === 401) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
insertImage(e.target?.result as string);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
throw new Error(i18nT("novel.editor.upload.localFallback"));
|
||||
|
||||
// Unknown error
|
||||
} else {
|
||||
throw new Error(i18nT("novel.editor.upload.error"));
|
||||
}
|
||||
}),
|
||||
{
|
||||
loading: i18nT("novel.editor.upload.loading"),
|
||||
success: i18nT("novel.editor.upload.success"),
|
||||
error: (e) => e.message,
|
||||
const reader = new FileReader();
|
||||
reader.onload = (readerEvent) => {
|
||||
const dataUrl = readerEvent.target?.result;
|
||||
if (typeof dataUrl === "string") {
|
||||
insertImage(dataUrl);
|
||||
return;
|
||||
}
|
||||
);
|
||||
toast.error(i18nT("novel.editor.upload.error"));
|
||||
};
|
||||
reader.onerror = () => {
|
||||
toast.error(i18nT("novel.editor.upload.error"));
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
const insertImage = (url: string) => {
|
||||
function insertImage(url: string) {
|
||||
// for paste events
|
||||
if (event instanceof ClipboardEvent) {
|
||||
return view.dispatch(
|
||||
@@ -120,5 +66,5 @@ export const handleImageUpload = (file: File, view: EditorView, event: Clipboard
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
+116
-5
@@ -1,8 +1,21 @@
|
||||
// @vitest-environment node
|
||||
// @vitest-environment jsdom
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { EditorView } from "@tiptap/pm/view";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { toast } from "sonner";
|
||||
import { handleImageUpload } from "./lib/utils/editor";
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: {
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/request-scoped-t", () => ({
|
||||
requestScopedT: (key: string) => key,
|
||||
}));
|
||||
|
||||
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const editorSource = readFileSync(path.join(moduleDir, "ui/editor/index.tsx"), "utf8");
|
||||
@@ -14,10 +27,108 @@ describe("Novel editor routing", () => {
|
||||
expect(editorSource).not.toContain("internal/ai/generate");
|
||||
expect(slashCommandSource).not.toContain("internal/ai/generate");
|
||||
expect(uploadSource).not.toContain("internal/ai/upload");
|
||||
expect(editorSource).not.toContain("useCompletion");
|
||||
expect(slashCommandSource).not.toContain("useCompletion");
|
||||
expect(slashCommandSource).not.toContain("continue-writing");
|
||||
});
|
||||
|
||||
it("uploads through the canonical API host with tenant scope", () => {
|
||||
expect(uploadSource).toContain('apiPath("ai/upload"');
|
||||
expect(uploadSource).toContain('"x-tenant-id": tenantId');
|
||||
it("keeps inserted images local instead of calling the retired API upload", () => {
|
||||
expect(uploadSource).not.toContain('apiPath("ai/upload"');
|
||||
expect(uploadSource).not.toContain("fetch(");
|
||||
expect(uploadSource).toContain("reader.readAsDataURL(file)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Novel editor local image insertion", () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
const file = (overrides: Partial<File> = {}) =>
|
||||
({
|
||||
name: "pilot.png",
|
||||
size: 1024,
|
||||
type: "image/png",
|
||||
...overrides,
|
||||
}) as File;
|
||||
|
||||
const editorView = () => {
|
||||
const create = vi.fn((attributes) => attributes);
|
||||
const replaceSelectionWith = vi.fn((node) => ({ node }));
|
||||
const dispatch = vi.fn();
|
||||
return {
|
||||
create,
|
||||
dispatch,
|
||||
replaceSelectionWith,
|
||||
view: {
|
||||
dispatch,
|
||||
state: {
|
||||
schema: { nodes: { image: { create } } },
|
||||
tr: { replaceSelectionWith },
|
||||
},
|
||||
} as unknown as EditorView,
|
||||
};
|
||||
};
|
||||
|
||||
const installFileReader = (result: string = "data:image/png;base64,cGlsb3Q=") => {
|
||||
vi.stubGlobal("ClipboardEvent", class extends Event {});
|
||||
vi.stubGlobal("DragEvent", class extends Event {});
|
||||
class TestFileReader {
|
||||
onerror: ((event: ProgressEvent<FileReader>) => void) | null = null;
|
||||
onload: ((event: ProgressEvent<FileReader>) => void) | null = null;
|
||||
|
||||
readAsDataURL() {
|
||||
this.onload?.({ target: { result } } as unknown as ProgressEvent<FileReader>);
|
||||
}
|
||||
}
|
||||
vi.stubGlobal("FileReader", TestFileReader);
|
||||
};
|
||||
|
||||
it("reads a valid image as a data URL and preserves insertion metadata", () => {
|
||||
installFileReader();
|
||||
const fetchSpy = vi.fn();
|
||||
vi.stubGlobal("fetch", fetchSpy);
|
||||
const { create, dispatch, replaceSelectionWith, view } = editorView();
|
||||
|
||||
handleImageUpload(file(), view, new Event("change"));
|
||||
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
expect(create).toHaveBeenCalledWith({
|
||||
src: "data:image/png;base64,cGlsb3Q=",
|
||||
alt: "pilot.png",
|
||||
title: "pilot.png",
|
||||
});
|
||||
expect(replaceSelectionWith).toHaveBeenCalledOnce();
|
||||
expect(dispatch).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("rejects non-images and files larger than 50 MB before reading", () => {
|
||||
const readAsDataURL = vi.fn();
|
||||
class TestFileReader {
|
||||
onerror: ((event: ProgressEvent<FileReader>) => void) | null = null;
|
||||
onload: ((event: ProgressEvent<FileReader>) => void) | null = null;
|
||||
readAsDataURL = readAsDataURL;
|
||||
}
|
||||
vi.stubGlobal("FileReader", TestFileReader);
|
||||
const { dispatch, view } = editorView();
|
||||
|
||||
handleImageUpload(file({ type: "application/pdf" }), view, new Event("change"));
|
||||
handleImageUpload(file({ size: 50 * 1024 * 1024 + 1 }), view, new Event("change"));
|
||||
|
||||
expect(toast.error).toHaveBeenNthCalledWith(1, "novel.editor.upload.unsupportedType");
|
||||
expect(toast.error).toHaveBeenNthCalledWith(2, "novel.editor.upload.tooLarge");
|
||||
expect(readAsDataURL).not.toHaveBeenCalled();
|
||||
expect(dispatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps the existing inclusive 50 MB limit", () => {
|
||||
installFileReader();
|
||||
const { dispatch, view } = editorView();
|
||||
|
||||
handleImageUpload(file({ size: 50 * 1024 * 1024 }), view, new Event("change"));
|
||||
|
||||
expect(toast.error).not.toHaveBeenCalled();
|
||||
expect(dispatch).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
import { JSONContent } from "@tiptap/core";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
const DEFAULT_EDITOR_CONTENT: JSONContent = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "heading",
|
||||
attrs: { level: 2 },
|
||||
content: [{ type: "text", text: i18nT("novel.editor.defaultContent.title") }],
|
||||
},
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: i18nT("novel.editor.defaultContent.introLead"),
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://tiptap.dev/",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: "Tiptap",
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.commaSeparator") },
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://sdk.vercel.ai/docs",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: "AI SDK",
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.andThe") },
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://sdk.vercel.ai/docs",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: "Vercel AI SDK",
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.arrowSeparator") },
|
||||
{ type: "text", marks: [{ type: "code" }], text: "npm i ai" },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "heading",
|
||||
attrs: { level: 3 },
|
||||
content: [{ type: "text", text: i18nT("novel.editor.defaultContent.learnMore") }],
|
||||
},
|
||||
{
|
||||
type: "orderedList",
|
||||
attrs: { start: 1 },
|
||||
content: [
|
||||
{
|
||||
type: "listItem",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.checkOutThe") },
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://twitter.com/steventey/status/1669762868416512000",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: i18nT("novel.editor.defaultContent.launchVideo"),
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.period") },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "listItem",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.starUsOn") },
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://github.com/steven-tey/novel",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: "GitHub",
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.period") },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "listItem",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
marks: [
|
||||
{
|
||||
type: "link",
|
||||
attrs: {
|
||||
href: "https://vercel.com/templates/next.js/novel",
|
||||
target: "_blank",
|
||||
class: "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer",
|
||||
},
|
||||
},
|
||||
],
|
||||
text: i18nT("novel.editor.defaultContent.deploy"),
|
||||
},
|
||||
{ type: "text", text: i18nT("novel.editor.defaultContent.yourOwn") },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ type: "paragraph" },
|
||||
],
|
||||
};
|
||||
|
||||
export default DEFAULT_EDITOR_CONTENT;
|
||||
+6
-6
@@ -11,11 +11,11 @@ import Collaboration from "@tiptap/extension-collaboration";
|
||||
import CollaborationCursor from "@tiptap/extension-collaboration-cursor";
|
||||
import type { HocuspocusProvider } from "@hocuspocus/provider";
|
||||
import type * as Y from "yjs";
|
||||
import { t as i18nT, type TFunction } from "i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
|
||||
import SlashCommand, { createSlashCommand } from "./slash-command";
|
||||
import SlashCommand from "./slash-command";
|
||||
import { InputRule } from "@tiptap/core";
|
||||
import type { ImageUploadOptions } from "~/modules/novel/lib/utils/editor";
|
||||
|
||||
export type CollaborationConfig = {
|
||||
/** Y.Doc instance shared between Collaboration + HocuspocusProvider. */
|
||||
@@ -30,7 +30,7 @@ export type CollaborationConfig = {
|
||||
};
|
||||
};
|
||||
|
||||
export function createTiptapExtensions(options: ImageUploadOptions = {}, collab: CollaborationConfig | null = null, t: TFunction = i18nT) {
|
||||
export function createTiptapExtensions(collab: CollaborationConfig | null = null, t: TFunction = i18nT) {
|
||||
// When collab is enabled we must remove StarterKit.history — Collaboration
|
||||
// ships its own Y.js-aware history extension, and having two history
|
||||
// implementations registered raises a Tiptap warning + breaks undo/redo.
|
||||
@@ -81,7 +81,7 @@ export function createTiptapExtensions(options: ImageUploadOptions = {}, collab:
|
||||
return [
|
||||
new InputRule({
|
||||
find: /^(?:---|—-|___\s|\*\*\*\s)$/,
|
||||
handler: ({ state, range, match }) => {
|
||||
handler: ({ state, range, match: _match }) => {
|
||||
const attributes = {};
|
||||
|
||||
const { tr } = state;
|
||||
@@ -121,7 +121,7 @@ export function createTiptapExtensions(options: ImageUploadOptions = {}, collab:
|
||||
},
|
||||
includeChildren: true,
|
||||
}),
|
||||
options.apiBaseUrl ? createSlashCommand(options) : SlashCommand,
|
||||
SlashCommand,
|
||||
TiptapUnderline,
|
||||
TextStyle,
|
||||
Color,
|
||||
|
||||
+2
-2
@@ -8,15 +8,15 @@ describe("novel slash command i18n", () => {
|
||||
it("keeps visible command copy behind semantic translation keys", () => {
|
||||
const source = fs.readFileSync(sourcePath, "utf8");
|
||||
|
||||
expect(source).toContain("novel.editor.commands.continueWriting");
|
||||
expect(source).toContain("novel.editor.commands.heading1");
|
||||
expect(source).toContain("novel.editor.commands.orderedList");
|
||||
expect(source).toContain("novel.editor.commandDescriptions.continueWriting");
|
||||
expect(source).toContain("novel.editor.commandDescriptions.text");
|
||||
expect(source).toContain("novel.editor.commandDescriptions.image");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
expect(source).not.toContain("Continue writing");
|
||||
expect(source).not.toContain("Use AI to expand your thoughts");
|
||||
expect(source).not.toContain("Just start typing with plain text");
|
||||
expect(source).not.toContain("continue-writing");
|
||||
expect(source).not.toContain("useCompletion");
|
||||
});
|
||||
});
|
||||
+10
-52
@@ -1,15 +1,11 @@
|
||||
import React, { useState, useEffect, useCallback, ReactNode, useRef, useLayoutEffect } from "react";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
import { Editor, Range, Extension } from "@tiptap/core";
|
||||
import Suggestion from "@tiptap/suggestion";
|
||||
import { ReactRenderer } from "@tiptap/react";
|
||||
import { useCompletion } from "../../../lib/ai/react/useCompletion";
|
||||
import tippy from "tippy.js";
|
||||
import { Heading1, Heading2, Heading3, List, ListOrdered, Text, TextQuote, Image as ImageIcon, Code } from "~/components/ui/icons/vendor";
|
||||
import LoadingCircle from "~/modules/novel/ui/shared/loading-circle";
|
||||
import { toast } from "sonner";
|
||||
import Magic from "~/modules/novel/ui/shared/magic";
|
||||
import { handleImageUpload, type ImageUploadOptions } from "~/modules/novel/lib/utils/editor";
|
||||
import { handleImageUpload } from "~/modules/novel/lib/utils/editor";
|
||||
|
||||
interface CommandItemProps {
|
||||
id: string;
|
||||
@@ -45,15 +41,8 @@ const CommandExtension = Extension.create({
|
||||
},
|
||||
});
|
||||
|
||||
const getSuggestionItems = ({ query, options = {} }: { query: string; options?: ImageUploadOptions }) => {
|
||||
const apiBaseUrl = options.apiBaseUrl;
|
||||
const getSuggestionItems = ({ query }: { query: string }) => {
|
||||
return [
|
||||
{
|
||||
id: "continue-writing",
|
||||
title: i18nT("novel.editor.commands.continueWriting"),
|
||||
description: i18nT("novel.editor.commandDescriptions.continueWriting"),
|
||||
icon: <Magic className="w-7 text-black" />,
|
||||
},
|
||||
// {
|
||||
// title: "Send Feedback",
|
||||
// description: "Let us know how we can improve.",
|
||||
@@ -145,7 +134,7 @@ const getSuggestionItems = ({ query, options = {} }: { query: string; options?:
|
||||
input.onchange = async (event) => {
|
||||
if (input.files?.length) {
|
||||
const file = input.files[0];
|
||||
return handleImageUpload(file, editor.view, event, { ...options, apiBaseUrl });
|
||||
return handleImageUpload(file, editor.view, event);
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
@@ -182,47 +171,18 @@ export const updateScrollView = (container: HTMLElement, item: HTMLElement) => {
|
||||
}
|
||||
};
|
||||
|
||||
const CommandList = ({ items, command, editor, range }: { items: CommandItemProps[]; command: any; editor: any; range: any }) => {
|
||||
const CommandList = ({ items, command }: { items: CommandItemProps[]; command: any }) => {
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
|
||||
const { complete, isLoading } = useCompletion({
|
||||
id: "novel",
|
||||
api: "",
|
||||
onResponse: (response) => {
|
||||
if (response.status === 429) {
|
||||
toast.error(i18nT("novel.editor.errors.requestLimit"));
|
||||
// va.track("Rate Limit Reached");
|
||||
return;
|
||||
}
|
||||
editor.chain().focus().deleteRange(range).run();
|
||||
},
|
||||
onFinish: (_prompt, completion) => {
|
||||
// highlight the generated text
|
||||
editor.commands.setTextSelection({
|
||||
from: range.from,
|
||||
to: range.from + completion.length,
|
||||
});
|
||||
},
|
||||
onError: (e) => {
|
||||
toast.error(e?.message ?? i18nT("novel.editor.errors.generic"));
|
||||
},
|
||||
});
|
||||
|
||||
const selectItem = useCallback(
|
||||
(index: number) => {
|
||||
const item = items[index];
|
||||
// va.track("Slash Command Used", {
|
||||
// command: item.title,
|
||||
// });
|
||||
if (item) {
|
||||
if (item.id === "continue-writing") {
|
||||
toast.error(i18nT("novel.editor.errors.aiWritingDisabled"));
|
||||
} else {
|
||||
command(item);
|
||||
}
|
||||
}
|
||||
if (item) command(item);
|
||||
},
|
||||
[complete, command, editor, items]
|
||||
[command, items]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -281,9 +241,7 @@ const CommandList = ({ items, command, editor, range }: { items: CommandItemProp
|
||||
key={index}
|
||||
onClick={() => selectItem(index)}
|
||||
>
|
||||
<div className="bg-background flex h-10 w-10 items-center justify-center rounded-md border border-stone-200">
|
||||
{item.id === "continue-writing" && isLoading ? <LoadingCircle /> : item.icon}
|
||||
</div>
|
||||
<div className="bg-background flex h-10 w-10 items-center justify-center rounded-md border border-stone-200">{item.icon}</div>
|
||||
<div>
|
||||
<p className="font-medium">{item.title}</p>
|
||||
<p className="text-xs text-stone-500">{item.description}</p>
|
||||
@@ -342,10 +300,10 @@ const renderItems = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export function createSlashCommand(options: ImageUploadOptions = {}) {
|
||||
export function createSlashCommand() {
|
||||
return CommandExtension.configure({
|
||||
suggestion: {
|
||||
items: ({ query }: { query: string }) => getSuggestionItems({ query, options }),
|
||||
items: ({ query }: { query: string }) => getSuggestionItems({ query }),
|
||||
render: renderItems,
|
||||
},
|
||||
});
|
||||
|
||||
+6
-95
@@ -1,14 +1,11 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useEditor, EditorContent, UseEditorOptions } from "@tiptap/react";
|
||||
import { createTiptapEditorProps } from "./props";
|
||||
import { createTiptapExtensions, type CollaborationConfig } from "./extensions";
|
||||
import { useHocuspocusProvider } from "./useHocuspocusProvider";
|
||||
import { useCompletion } from "../../lib/ai/react/useCompletion";
|
||||
import { toast } from "sonner";
|
||||
import { EditorBubbleMenu } from "./components";
|
||||
import { Editor, EditorOptions, JSONContent } from "@tiptap/core";
|
||||
import { Editor, JSONContent } from "@tiptap/core";
|
||||
import clsx from "clsx";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type ValueDto = {
|
||||
@@ -57,14 +54,9 @@ export default function NovelEditor({
|
||||
collab,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const rootData = useRootData();
|
||||
const [saveStatusKey, setSaveStatusKey] = useState("novel.editor.status.saved");
|
||||
|
||||
const [hydrated, setHydrated] = useState(false);
|
||||
const imageUploadOptions = useMemo(
|
||||
() => ({ apiBaseUrl: rootData.apiBaseUrl, tenantId: rootData.currentTenant?.id ?? null, tenantSlug: rootData.currentTenant?.slug ?? null }),
|
||||
[rootData.apiBaseUrl, rootData.currentTenant?.id, rootData.currentTenant?.slug]
|
||||
);
|
||||
const hocuspocus = useHocuspocusProvider({
|
||||
url: collab?.url ?? null,
|
||||
token: collab?.token ?? null,
|
||||
@@ -78,8 +70,8 @@ export default function NovelEditor({
|
||||
user: collab.user,
|
||||
};
|
||||
}, [collab, hocuspocus]);
|
||||
const extensions = useMemo(() => createTiptapExtensions(imageUploadOptions, collaborationConfig, t), [collaborationConfig, imageUploadOptions, t]);
|
||||
const editorProps = useMemo(() => createTiptapEditorProps(imageUploadOptions), [imageUploadOptions]);
|
||||
const extensions = useMemo(() => createTiptapExtensions(collaborationConfig, t), [collaborationConfig, t]);
|
||||
const editorProps = useMemo(() => createTiptapEditorProps(), []);
|
||||
const collabStatus = hocuspocus?.status ?? null;
|
||||
const collabSynced = hocuspocus?.synced ?? false;
|
||||
|
||||
@@ -109,18 +101,7 @@ export default function NovelEditor({
|
||||
editorProps,
|
||||
onUpdate: (e) => {
|
||||
setSaveStatusKey("novel.editor.status.saving");
|
||||
const selection = e.editor.state.selection;
|
||||
const lastTwo = e.editor.state.doc.textBetween(selection.from - 2, selection.from, "\n");
|
||||
if (lastTwo === "++" && !isLoading) {
|
||||
e.editor.commands.deleteRange({
|
||||
from: selection.from - 2,
|
||||
to: selection.from,
|
||||
});
|
||||
toast.error(t("novel.editor.errors.aiWritingDisabled"));
|
||||
// va.track("Autocomplete Shortcut Used");
|
||||
} else {
|
||||
debouncedUpdates(e);
|
||||
}
|
||||
debouncedUpdates(e);
|
||||
},
|
||||
};
|
||||
if (autoFocus) {
|
||||
@@ -130,76 +111,6 @@ export default function NovelEditor({
|
||||
}
|
||||
const editor = useEditor(options);
|
||||
|
||||
const { complete, completion, isLoading, stop } = useCompletion({
|
||||
id: "novel",
|
||||
api: "",
|
||||
onResponse: (response) => {
|
||||
if (response.status === 429) {
|
||||
toast.error(t("novel.editor.errors.requestLimit"));
|
||||
// va.track("Rate Limit Reached");
|
||||
return;
|
||||
}
|
||||
},
|
||||
onFinish: (_prompt, completion) => {
|
||||
editor?.commands.setTextSelection({
|
||||
from: editor.state.selection.from - completion.length,
|
||||
to: editor.state.selection.from,
|
||||
});
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t("novel.editor.errors.generic"));
|
||||
},
|
||||
});
|
||||
|
||||
const prev = useRef("");
|
||||
|
||||
// Insert chunks of the generated text
|
||||
useEffect(() => {
|
||||
const diff = completion.slice(prev.current.length);
|
||||
prev.current = completion;
|
||||
editor?.commands.insertContent(diff, {
|
||||
parseOptions: {
|
||||
preserveWhitespace: "full",
|
||||
},
|
||||
});
|
||||
}, [isLoading, editor, completion]);
|
||||
|
||||
useEffect(() => {
|
||||
// if user presses escape or cmd + z and it's loading,
|
||||
// stop the request, delete the completion, and insert back the "++"
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" || (e.metaKey && e.key === "z")) {
|
||||
stop();
|
||||
if (e.key === "Escape") {
|
||||
editor?.commands.deleteRange({
|
||||
from: editor.state.selection.from - completion.length,
|
||||
to: editor.state.selection.from,
|
||||
});
|
||||
}
|
||||
editor?.commands.insertContent("++");
|
||||
}
|
||||
};
|
||||
const mousedownHandler = (e: MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
stop();
|
||||
if (window.confirm(t("novel.editor.confirm.aiWritingPaused"))) {
|
||||
toast.error(t("novel.editor.errors.aiWritingDisabled"));
|
||||
}
|
||||
};
|
||||
if (isLoading) {
|
||||
document.addEventListener("keydown", onKeyDown);
|
||||
window.addEventListener("mousedown", mousedownHandler);
|
||||
} else {
|
||||
document.removeEventListener("keydown", onKeyDown);
|
||||
window.removeEventListener("mousedown", mousedownHandler);
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener("keydown", onKeyDown);
|
||||
window.removeEventListener("mousedown", mousedownHandler);
|
||||
};
|
||||
}, [stop, isLoading, editor, complete, completion.length, t]);
|
||||
|
||||
// Hydrate the editor with the content from localStorage.
|
||||
//
|
||||
// When realtime-collab is active, the Y.Doc is the canonical source of
|
||||
@@ -247,7 +158,7 @@ export default function NovelEditor({
|
||||
{collabStatus && collabStatus !== "connected" && (
|
||||
<div
|
||||
data-testid="novel-collab-status"
|
||||
className="bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-200 absolute top-5 left-5 mb-5 rounded-lg px-2 py-1 text-sm"
|
||||
className="absolute top-5 left-5 mb-5 rounded-lg bg-amber-100 px-2 py-1 text-sm text-amber-900 dark:bg-amber-950 dark:text-amber-200"
|
||||
>
|
||||
{collabStatus === "connecting" ? t("novel.editor.collab.connecting") : t("novel.editor.collab.offline")}
|
||||
</div>
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
import { handleImageUpload, type ImageUploadOptions } from "~/modules/novel/lib/utils/editor";
|
||||
import { handleImageUpload } from "~/modules/novel/lib/utils/editor";
|
||||
import { EditorProps } from "@tiptap/pm/view";
|
||||
|
||||
export function createTiptapEditorProps(options: ImageUploadOptions = {}): EditorProps {
|
||||
export function createTiptapEditorProps(): EditorProps {
|
||||
return {
|
||||
attributes: {
|
||||
class: "prose-lg prose-headings:font-display focus:outline-hidden",
|
||||
@@ -21,7 +21,7 @@ export function createTiptapEditorProps(options: ImageUploadOptions = {}): Edito
|
||||
if (event.clipboardData && event.clipboardData.files && event.clipboardData.files[0]) {
|
||||
event.preventDefault();
|
||||
const file = event.clipboardData.files[0];
|
||||
return handleImageUpload(file, view, event, options);
|
||||
return handleImageUpload(file, view, event);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
@@ -29,7 +29,7 @@ export function createTiptapEditorProps(options: ImageUploadOptions = {}): Edito
|
||||
if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
|
||||
event.preventDefault();
|
||||
const file = event.dataTransfer.files[0];
|
||||
return handleImageUpload(file, view, event, options);
|
||||
return handleImageUpload(file, view, event);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
export default function LoadingCircle({ dimensions }: { dimensions?: string }) {
|
||||
return (
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
className={`${
|
||||
dimensions || "h-4 w-4"
|
||||
} animate-spin fill-stone-600 text-stone-200`}
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
export default function Magic({ className }: { className: string }) {
|
||||
return (
|
||||
<svg
|
||||
width="469"
|
||||
height="469"
|
||||
viewBox="0 0 469 469"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
shapeRendering="geometricPrecision"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="1.5"
|
||||
className={className}
|
||||
>
|
||||
<path
|
||||
d="M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user