Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Nov 20, 2024
1 parent c461420 commit b671a27
Show file tree
Hide file tree
Showing 79 changed files with 688 additions and 397 deletions.
16 changes: 8 additions & 8 deletions templates/plate-playground-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"@ai-sdk/openai": "^0.0.72",
"@ariakit/react": "^0.4.13",
"@faker-js/faker": "^9.2.0",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-context-menu": "^2.2.2",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-separator": "^1.1.0",
Expand Down Expand Up @@ -74,11 +74,6 @@
"@udecode/plate-toggle": "^40.0.0",
"@udecode/plate-trailing-block": "^40.0.0",
"@uploadthing/react": "7.1.0",
"uploadthing": "7.2.0",
"zod": "^3.23.8",
"react-player": "^2.16.0",
"sonner": "^1.5.0",
"use-file-picker": "^2.1.2",
"ai": "^3.4.33",
"class-variance-authority": "0.7.0",
"clsx": "^2.1.1",
Expand All @@ -93,19 +88,23 @@
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"react-lite-youtube-embed": "^2.4.0",
"react-player": "^2.16.0",
"react-resizable-panels": "^2.1.6",
"react-tweet": "^3.2.1",
"slate": "^0.110.2",
"slate-dom": "^0.111.0",
"slate-history": "^0.110.3",
"slate-hyperscript": "^0.100.0",
"slate-react": "^0.111.0",
"sonner": "^1.7.0",
"tailwind-merge": "2.5.4",
"tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "1.0.7"
"tailwindcss-animate": "1.0.7",
"uploadthing": "7.2.0",
"use-file-picker": "^2.1.2",
"zod": "^3.23.8"
},
"devDependencies": {
"eslint-plugin-prettier": "^5.2.1",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
Expand All @@ -116,6 +115,7 @@
"eslint-config-next": "15.0.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-perfectionist": "3.9.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-tailwindcss": "^3.17.5",
"eslint-plugin-unused-imports": "^4.1.3",
Expand Down
4 changes: 2 additions & 2 deletions templates/plate-playground-template/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ import { createRouteHandler, createUploadthing } from 'uploadthing/next';

const f = createUploadthing();

// FileRouter for your app, can contain multiple FileRoutes
const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
imageUploader: f(['image', 'text', 'blob', 'pdf', 'video', 'audio'])
// Set permissions and file types for this FileRoute
.middleware(async ({ req }) => {
// This code runs on your server before upload

// Whatever is returned here is accessible in onUploadComplete as `metadata`
editorUploader: f(['image', 'text', 'blob', 'pdf', 'video', 'audio'])
.middleware(() => {
return {};
})
.onUploadComplete(({ file, metadata }) => {
// This code RUNS ON YOUR SERVER after upload

// !!! Whatever is returned here is sent to the clientside `onClientUploadComplete` callback
.onUploadComplete(({ file }) => {
return { file };
}),
} satisfies FileRouter;

export type OurFileRouter = typeof ourFileRouter;

// Export routes for Next App Router
export const { GET, POST } = createRouteHandler({
router: ourFileRouter,

// Apply an (optional) custom config:
// config: { ... },
});
3 changes: 0 additions & 3 deletions templates/plate-playground-template/src/app/editor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Toaster } from 'sonner';

import { PlateEditor } from '@/components/editor/plate-editor';
import { OpenAIProvider } from '@/components/editor/use-chat';

Expand All @@ -8,7 +6,6 @@ export default function Page() {
<div className="h-screen w-full" data-registry="plate">
<OpenAIProvider>
<PlateEditor />
<Toaster />
</OpenAIProvider>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { HTML5Backend } from 'react-dnd-html5-backend';

import { Plate } from '@udecode/plate-common/react';

import { SettingsDialog } from '@/components/editor/use-chat';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { SettingsDialog } from '@/components/editor/use-chat';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';

export function PlateEditor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { HEADING_KEYS } from '@udecode/plate-heading';
import { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';
import { LinkPlugin } from '@udecode/plate-link/react';
import { MarkdownPlugin } from '@udecode/plate-markdown';
import { BlockSelectionPlugin } from '@udecode/plate-selection/react';

import { cursorOverlayPlugin } from '@/components/editor/plugins/cursor-overlay-plugin';
import { AIMenu } from '@/components/plate-ui/ai-menu';
import { BlockquoteElement } from '@/components/plate-ui/blockquote-element';
import { CodeBlockElement } from '@/components/plate-ui/code-block-element';
Expand All @@ -40,6 +40,7 @@ import { LinkElement } from '@/components/plate-ui/link-element';
import { ParagraphElement } from '@/components/plate-ui/paragraph-element';

import { basicNodesPlugins } from './basic-nodes-plugins';
import { blockSelectionReadOnlyPlugin } from './block-selection-plugins';
import { indentListPlugins } from './indent-list-plugins';
import { linkPlugin } from './link-plugin';

Expand All @@ -66,23 +67,13 @@ const createAIEditor = () => {
},
},
plugins: [
ParagraphPlugin,
...basicNodesPlugins,
...indentListPlugins,
HorizontalRulePlugin,
linkPlugin,
...indentListPlugins,
MarkdownPlugin.configure({ options: { indentList: true } }),
// FIXME
BlockSelectionPlugin.configure({
api: {},
extendEditor: null,
options: {},
render: {},
useHooks: null,
handlers: {},
}),
blockSelectionReadOnlyPlugin,
],
value: [{ children: [{ text: '' }], type: 'p' }],
});

return editor;
Expand Down Expand Up @@ -170,6 +161,7 @@ export const PROMPT_TEMPLATES = {
};

export const aiPlugins = [
cursorOverlayPlugin,
MarkdownPlugin.configure({ options: { indentList: true } }),
AIPlugin,
AIChatPlugin.configure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ export const blockSelectionPlugins = [
},
}),
] as const;

export const blockSelectionReadOnlyPlugin = BlockSelectionPlugin.configure({
api: {},
extendEditor: null,
options: {},
render: {},
useHooks: null,
handlers: {},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client';

import type { TElement } from '@udecode/plate-common';

import { faker } from '@faker-js/faker';
import { CopilotPlugin } from '@udecode/plate-ai/react';
import { getAncestorNode } from '@udecode/plate-common';
import { serializeMdNodes, stripMarkdown } from '@udecode/plate-markdown';

import { GhostText } from '@/components/plate-ui/ghost-text';

export const copilotPlugins = [
CopilotPlugin.configure(({ api }) => ({
options: {
completeOptions: {
api: '/api/ai/copilot',
body: {
system: `You are an advanced AI writing assistant, similar to VSCode Copilot but for general text. Your task is to predict and generate the next part of the text based on the given context.
Rules:
- Continue the text naturally up to the next punctuation mark (., ,, ;, :, ?, or !).
- Maintain style and tone. Don't repeat given text.
- For unclear context, provide the most likely continuation.
- Handle code snippets, lists, or structured text if needed.
- Don't include """ in your response.
- CRITICAL: Always end with a punctuation mark.
- CRITICAL: Avoid starting a new block. Do not use block formatting like >, #, 1., 2., -, etc. The suggestion should continue in the same block as the context.
- If no context is provided or you can't generate a continuation, return "0" without explanation.`,
},
onError: () => {
// Mock the API response. Remove it when you implement the route /api/ai/copilot
api.copilot.setBlockSuggestion({
text: stripMarkdown(faker.lorem.sentence()),
});
},
onFinish: (_, completion) => {
if (completion === '0') return;

api.copilot.setBlockSuggestion({
text: stripMarkdown(completion),
});
},
},
debounceDelay: 500,
getPrompt: ({ editor }) => {
const contextEntry = getAncestorNode(editor);

if (!contextEntry) return '';

const prompt = serializeMdNodes([contextEntry[0] as TElement]);

return `Continue the text up to the next punctuation mark:
"""
${prompt}
"""`;
},
renderGhostText: GhostText,
},
})),
] as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client';

import { CursorOverlayPlugin } from '@udecode/plate-selection/react';

import { CursorOverlay } from '@/components/plate-ui/cursor-overlay';

export const cursorOverlayPlugin = CursorOverlayPlugin.configure({
render: {
afterEditable: () => <CursorOverlay />,
},
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
'use client';

import { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';
import { ImagePlugin, MediaEmbedPlugin } from '@udecode/plate-media/react';
import {
AudioPlugin,
FilePlugin,
ImagePlugin,
MediaEmbedPlugin,
VideoPlugin,
} from '@udecode/plate-media/react';
import { DeletePlugin, SelectOnBackspacePlugin } from '@udecode/plate-select';

export const deletePlugins = [
Expand All @@ -10,6 +16,9 @@ export const deletePlugins = [
query: {
allow: [
ImagePlugin.key,
VideoPlugin.key,
AudioPlugin.key,
FilePlugin.key,
MediaEmbedPlugin.key,
HorizontalRulePlugin.key,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ import {
EquationPlugin,
InlineEquationPlugin,
} from '@udecode/plate-math/react';
import { CursorOverlayPlugin } from '@udecode/plate-selection/react';
import { SlashPlugin } from '@udecode/plate-slash-command/react';
import { TogglePlugin } from '@udecode/plate-toggle/react';
import { TrailingBlockPlugin } from '@udecode/plate-trailing-block';

import { CursorOverlay } from '@/components/plate-ui/cursor-overlay';
import { FixedToolbarPlugin } from '@/components/editor/plugins/fixed-toolbar-plugin';
import { FloatingToolbarPlugin } from '@/components/editor/plugins/floating-toolbar-plugin';

import { aiPlugins } from './ai-plugins';
import { alignPlugin } from './align-plugin';
import { autoformatPlugin } from './autoformat-plugin';
import { basicNodesPlugins } from './basic-nodes-plugins';
import { blockMenuPlugins } from './block-menu-plugins';
import { commentsPlugin } from './comments-plugin';
import { cursorOverlayPlugin } from './cursor-overlay-plugin';
import { deletePlugins } from './delete-plugins';
import { dndPlugins } from './dnd-plugins';
import { exitBreakPlugin } from './exit-break-plugin';
Expand All @@ -46,17 +47,12 @@ import { softBreakPlugin } from './soft-break-plugin';
import { tablePlugin } from './table-plugin';
import { tocPlugin } from './toc-plugin';

export const editorPlugins = [
// AI
...aiPlugins,

// Nodes
export const viewPlugins = [
...basicNodesPlugins,
HorizontalRulePlugin,
linkPlugin,
DatePlugin,
mentionPlugin,
SlashPlugin,
tablePlugin,
TogglePlugin,
tocPlugin,
Expand All @@ -78,11 +74,21 @@ export const editorPlugins = [
...indentListPlugins,
lineHeightPlugin,

// Collaboration
commentsPlugin,
] as const;

export const editorPlugins = [
// AI
...aiPlugins,

// Nodes
...viewPlugins,

// Functionality
SlashPlugin,
autoformatPlugin,
CursorOverlayPlugin.configure({
render: { afterEditable: () => <CursorOverlay /> },
}),
cursorOverlayPlugin,
...blockMenuPlugins,
...dndPlugins,
EmojiPlugin,
Expand All @@ -92,11 +98,12 @@ export const editorPlugins = [
softBreakPlugin,
TrailingBlockPlugin.configure({ options: { type: ParagraphPlugin.key } }),

// Collaboration
commentsPlugin,

// Deserialization
DocxPlugin,
MarkdownPlugin.configure({ options: { indentList: true } }),
JuicePlugin,

// UI
FixedToolbarPlugin,
FloatingToolbarPlugin,
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
FireLiComponent,
FireMarker,
} from '@/components/plate-ui/indent-fire-marker';
import { TodoLi, TodoMarker } from '@/components/plate-ui/indent-todo-marker';
import {
TodoLi,
TodoMarker,
} from '@/components/plate-ui/indent-todo-marker';

export const indentListPlugins = [
IndentPlugin.extend({
Expand Down
Loading

0 comments on commit b671a27

Please sign in to comment.