Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -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;
@@ -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,
@@ -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");
});
});
@@ -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,
},
});
@@ -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>
@@ -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;
},
@@ -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>
);
}
@@ -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>
);
}