Skip to content

Commit

Permalink
fix template build
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Dec 19, 2024
1 parent 89abd4a commit 48c87a8
Show file tree
Hide file tree
Showing 76 changed files with 2,254 additions and 1,035 deletions.
93 changes: 47 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,53 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toolbar": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.3",
"@udecode/cn": "^39.0.0",
"@udecode/plate-ai": "40.2.2",
"@udecode/plate-alignment": "^40.0.0",
"@udecode/plate-autoformat": "^40.0.0",
"@udecode/plate-basic-elements": "^40.2.6",
"@udecode/plate-basic-marks": "^40.0.0",
"@udecode/plate-block-quote": "^40.0.0",
"@udecode/plate-break": "^40.0.0",
"@udecode/plate-callout": "^40.0.0",
"@udecode/plate-caption": "^40.2.5",
"@udecode/plate-code-block": "^40.0.0",
"@udecode/plate-combobox": "^40.0.0",
"@udecode/plate-comments": "^40.0.0",
"@udecode/plate-common": "^40.2.7",
"@udecode/plate-cursor": "^40.0.0",
"@udecode/plate-date": "^40.0.0",
"@udecode/plate-dnd": "40.0.0",
"@udecode/plate-docx": "40.2.7",
"@udecode/plate-emoji": "^40.0.0",
"@udecode/plate-excalidraw": "^40.0.0",
"@udecode/plate-floating": "^40.0.0",
"@udecode/plate-font": "^40.0.0",
"@udecode/plate-heading": "^40.2.6",
"@udecode/plate-highlight": "^40.0.0",
"@udecode/plate-horizontal-rule": "^40.0.0",
"@udecode/plate-indent": "^40.0.0",
"@udecode/plate-indent-list": "^40.0.0",
"@udecode/plate-juice": "^40.0.0",
"@udecode/plate-kbd": "^40.0.0",
"@udecode/plate-layout": "^40.0.0",
"@udecode/plate-line-height": "^40.0.0",
"@udecode/plate-link": "^40.0.0",
"@udecode/plate-markdown": "40.2.2",
"@udecode/plate-math": "^40.0.0",
"@udecode/plate-media": "40.2.7",
"@udecode/plate-mention": "40.0.0",
"@udecode/plate-node-id": "^40.0.0",
"@udecode/plate-reset-node": "^40.0.0",
"@udecode/plate-resizable": "^40.0.0",
"@udecode/plate-select": "^40.0.0",
"@udecode/plate-selection": "40.1.0",
"@udecode/plate-slash-command": "^40.0.0",
"@udecode/plate-tabbable": "^40.0.0",
"@udecode/plate-table": "^40.0.0",
"@udecode/plate-toggle": "^40.0.0",
"@udecode/plate-trailing-block": "^40.0.0",
"@udecode/cmdk": "^0.1.1",
"@udecode/cn": "40.2.8",
"@udecode/plate-ai": "41.0.1",
"@udecode/plate-alignment": "41.0.0",
"@udecode/plate-autoformat": "41.0.0",
"@udecode/plate-basic-elements": "41.0.0",
"@udecode/plate-basic-marks": "41.0.0",
"@udecode/plate-block-quote": "41.0.0",
"@udecode/plate-break": "41.0.0",
"@udecode/plate-callout": "41.0.0",
"@udecode/plate-caption": "41.0.0",
"@udecode/plate-code-block": "41.0.0",
"@udecode/plate-combobox": "41.0.0",
"@udecode/plate-comments": "41.0.0",
"@udecode/plate-common": "41.0.0",
"@udecode/plate-cursor": "41.0.0",
"@udecode/plate-date": "41.0.0",
"@udecode/plate-dnd": "41.0.0",
"@udecode/plate-docx": "41.0.0",
"@udecode/plate-emoji": "41.0.0",
"@udecode/plate-excalidraw": "41.0.0",
"@udecode/plate-floating": "41.0.0",
"@udecode/plate-font": "41.0.0",
"@udecode/plate-heading": "41.0.0",
"@udecode/plate-highlight": "41.0.0",
"@udecode/plate-horizontal-rule": "41.0.0",
"@udecode/plate-indent": "41.0.0",
"@udecode/plate-indent-list": "41.0.0",
"@udecode/plate-juice": "41.0.0",
"@udecode/plate-kbd": "41.0.0",
"@udecode/plate-layout": "41.0.0",
"@udecode/plate-line-height": "41.0.0",
"@udecode/plate-link": "41.0.0",
"@udecode/plate-markdown": "41.0.0",
"@udecode/plate-math": "41.0.0",
"@udecode/plate-media": "41.0.0",
"@udecode/plate-mention": "41.0.0",
"@udecode/plate-node-id": "41.0.0",
"@udecode/plate-reset-node": "41.0.0",
"@udecode/plate-resizable": "41.0.0",
"@udecode/plate-select": "41.0.0",
"@udecode/plate-selection": "41.0.0",
"@udecode/plate-slash-command": "41.0.0",
"@udecode/plate-tabbable": "41.0.0",
"@udecode/plate-table": "41.0.0",
"@udecode/plate-toggle": "41.0.0",
"@udecode/plate-trailing-block": "41.0.0",
"@uploadthing/react": "7.1.0",
"ai": "^3.4.33",
"class-variance-authority": "0.7.0",
Expand Down
1,439 changes: 733 additions & 706 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

114 changes: 54 additions & 60 deletions src/components/editor/plugins/ai-plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,71 @@

import React from 'react';

import { withProps } from '@udecode/cn';
import { AIChatPlugin, AIPlugin } from '@udecode/plate-ai/react';
import {
BoldPlugin,
CodePlugin,
ItalicPlugin,
StrikethroughPlugin,
UnderlinePlugin,
} from '@udecode/plate-basic-marks/react';
import { BlockquotePlugin } from '@udecode/plate-block-quote/react';
BaseBoldPlugin,
BaseCodePlugin,
BaseItalicPlugin,
BaseStrikethroughPlugin,
BaseUnderlinePlugin,
} from '@udecode/plate-basic-marks';
import { BaseBlockquotePlugin } from '@udecode/plate-block-quote';
import {
CodeBlockPlugin,
CodeLinePlugin,
CodeSyntaxPlugin,
} from '@udecode/plate-code-block/react';
import {
ParagraphPlugin,
PlateLeaf,
createPlateEditor,
} from '@udecode/plate-common/react';
import { HEADING_KEYS } from '@udecode/plate-heading';
import { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';
import { LinkPlugin } from '@udecode/plate-link/react';
BaseCodeBlockPlugin,
BaseCodeLinePlugin,
BaseCodeSyntaxPlugin,
} from '@udecode/plate-code-block';
import { BaseParagraphPlugin, createSlateEditor } from '@udecode/plate-common';
import { BaseHeadingPlugin, HEADING_LEVELS } from '@udecode/plate-heading';
import { BaseHorizontalRulePlugin } from '@udecode/plate-horizontal-rule';
import { BaseIndentListPlugin } from '@udecode/plate-indent-list';
import { BaseLinkPlugin } from '@udecode/plate-link';
import { MarkdownPlugin } from '@udecode/plate-markdown';

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';
import { CodeLeaf } from '@/components/plate-ui/code-leaf';
import { CodeLineElement } from '@/components/plate-ui/code-line-element';
import { CodeSyntaxLeaf } from '@/components/plate-ui/code-syntax-leaf';
import { HeadingElement } from '@/components/plate-ui/heading-element';
import { HrElement } from '@/components/plate-ui/hr-element';
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';
import {
TodoLiStatic,
TodoMarkerStatic,
} from '@/components/plate-ui/indent-todo-marker-static';

import { cursorOverlayPlugin } from './cursor-overlay-plugin';
const createAIEditor = () => {
const editor = createPlateEditor({
const editor = createSlateEditor({
id: 'ai',
override: {
components: {
[BlockquotePlugin.key]: BlockquoteElement,
[BoldPlugin.key]: withProps(PlateLeaf, { as: 'strong' }),
[CodeBlockPlugin.key]: CodeBlockElement,
[CodeLinePlugin.key]: CodeLineElement,
[CodePlugin.key]: CodeLeaf,
[CodeSyntaxPlugin.key]: CodeSyntaxLeaf,
[HEADING_KEYS.h1]: withProps(HeadingElement, { variant: 'h1' }),
[HEADING_KEYS.h2]: withProps(HeadingElement, { variant: 'h2' }),
[HEADING_KEYS.h3]: withProps(HeadingElement, { variant: 'h3' }),
[HorizontalRulePlugin.key]: HrElement,
[ItalicPlugin.key]: withProps(PlateLeaf, { as: 'em' }),
[LinkPlugin.key]: LinkElement,
[ParagraphPlugin.key]: ParagraphElement,
[StrikethroughPlugin.key]: withProps(PlateLeaf, { as: 's' }),
[UnderlinePlugin.key]: withProps(PlateLeaf, { as: 'u' }),
},
},
plugins: [
...basicNodesPlugins,
...indentListPlugins,
HorizontalRulePlugin,
linkPlugin,
BaseBlockquotePlugin,
BaseBoldPlugin,
BaseCodeBlockPlugin,
BaseCodeLinePlugin,
BaseCodePlugin,
BaseCodeSyntaxPlugin,
BaseItalicPlugin,
BaseStrikethroughPlugin,
BaseUnderlinePlugin,
BaseHeadingPlugin,
BaseHorizontalRulePlugin,
BaseLinkPlugin,
BaseParagraphPlugin,
BaseIndentListPlugin.extend({
inject: {
targetPlugins: [
BaseParagraphPlugin.key,
...HEADING_LEVELS,
BaseBlockquotePlugin.key,
BaseCodeBlockPlugin.key,
],
},
options: {
listStyleTypes: {
todo: {
liComponent: TodoLiStatic,
markerComponent: TodoMarkerStatic,
type: 'todo',
},
},
},
}),
MarkdownPlugin.configure({ options: { indentList: true } }),
blockSelectionReadOnlyPlugin,
],
});

Expand Down
18 changes: 16 additions & 2 deletions src/components/editor/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { TocPlugin } from '@udecode/plate-heading/react';
import { INDENT_LIST_KEYS, ListStyleType } from '@udecode/plate-indent-list';
import { IndentListPlugin } from '@udecode/plate-indent-list/react';
import { insertColumnGroup, toggleColumnGroup } from '@udecode/plate-layout';
import { ColumnItemPlugin, ColumnPlugin } from '@udecode/plate-layout/react';
import { LinkPlugin, triggerFloatingLink } from '@udecode/plate-link/react';
import { insertEquation, insertInlineEquation } from '@udecode/plate-math';
import {
Expand All @@ -44,9 +45,22 @@ import {
MediaEmbedPlugin,
VideoPlugin,
} from '@udecode/plate-media/react';
import { TablePlugin, insertTable } from '@udecode/plate-table/react';
import { insertTable } from '@udecode/plate-table';
import {
TableCellPlugin,
TablePlugin,
TableRowPlugin,
} from '@udecode/plate-table/react';
import { Path } from 'slate';

export const STRUCTURAL_TYPES = [
ColumnPlugin.key,
ColumnItemPlugin.key,
TablePlugin.key,
TableRowPlugin.key,
TableCellPlugin.key,
];

const ACTION_THREE_COLUMNS = 'action_three_columns';

const insertList = (editor: PlateEditor, type: string) => {
Expand Down Expand Up @@ -185,7 +199,7 @@ export const setBlockType = (
}
}

const entries = getBlocks(editor);
const entries = getBlocks(editor, { mode: 'lowest' });

entries.forEach((entry) => setEntry(entry));
});
Expand Down
65 changes: 56 additions & 9 deletions src/components/plate-ui/ai-chat-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,66 @@

import React, { memo } from 'react';

import { withProps } from '@udecode/cn';
import { AIChatPlugin, useLastAssistantMessage } from '@udecode/plate-ai/react';
import {
type PlateEditor,
Plate,
useEditorPlugin,
} from '@udecode/plate-common/react';
BaseBoldPlugin,
BaseCodePlugin,
BaseItalicPlugin,
BaseStrikethroughPlugin,
BaseUnderlinePlugin,
} from '@udecode/plate-basic-marks';
import { BaseBlockquotePlugin } from '@udecode/plate-block-quote';
import {
BaseCodeBlockPlugin,
BaseCodeLinePlugin,
BaseCodeSyntaxPlugin,
} from '@udecode/plate-code-block';
import { useEditorPlugin } from '@udecode/plate-common/react';
import {
type SlateEditor,
BaseParagraphPlugin,
SlateLeaf,
} from '@udecode/plate-common';
import { HEADING_KEYS } from '@udecode/plate-heading';
import { BaseHorizontalRulePlugin } from '@udecode/plate-horizontal-rule';
import { BaseLinkPlugin } from '@udecode/plate-link';
import { deserializeMd } from '@udecode/plate-markdown';

import { Editor } from './editor';
import { BlockquoteElementStatic } from './blockquote-element-static';
import { CodeBlockElementStatic } from './code-block-element-static';
import { CodeLeafStatic } from './code-leaf-static';
import { CodeLineElementStatic } from './code-line-element-static';
import { CodeSyntaxLeafStatic } from './code-syntax-leaf-static';
import { EditorStatic } from './editor-static';
import { HeadingElementStatic } from './heading-element-static';
import { HrElementStatic } from './hr-element-static';
import { LinkElementStatic } from './link-element-static';
import { ParagraphElementStatic } from './paragraph-element-static';

const staticComponents = {
[BaseBlockquotePlugin.key]: BlockquoteElementStatic,
[BaseBoldPlugin.key]: withProps(SlateLeaf, { as: 'strong' }),
[BaseCodeBlockPlugin.key]: CodeBlockElementStatic,
[BaseCodeLinePlugin.key]: CodeLineElementStatic,
[BaseCodePlugin.key]: CodeLeafStatic,
[BaseCodeSyntaxPlugin.key]: CodeSyntaxLeafStatic,
[BaseHorizontalRulePlugin.key]: HrElementStatic,
[BaseItalicPlugin.key]: withProps(SlateLeaf, { as: 'em' }),
[BaseLinkPlugin.key]: LinkElementStatic,
[BaseParagraphPlugin.key]: ParagraphElementStatic,
[BaseStrikethroughPlugin.key]: withProps(SlateLeaf, { as: 's' }),
[BaseUnderlinePlugin.key]: withProps(SlateLeaf, { as: 'u' }),
[HEADING_KEYS.h1]: withProps(HeadingElementStatic, { variant: 'h1' }),
[HEADING_KEYS.h2]: withProps(HeadingElementStatic, { variant: 'h2' }),
[HEADING_KEYS.h3]: withProps(HeadingElementStatic, { variant: 'h3' }),
};

export const AIChatEditor = memo(
({
aiEditorRef,
}: {
aiEditorRef: React.MutableRefObject<PlateEditor | null>;
aiEditorRef: React.MutableRefObject<SlateEditor | null>;
}) => {
const { getOptions } = useEditorPlugin(AIChatPlugin);
const lastAssistantMessage = useLastAssistantMessage();
Expand Down Expand Up @@ -46,9 +91,11 @@ export const AIChatEditor = memo(
if (!content) return null;

return (
<Plate editor={aiEditor}>
<Editor variant="aiChat" readOnly />
</Plate>
<EditorStatic
variant="aiChat"
components={staticComponents}
editor={aiEditor}
/>
);
}
);
4 changes: 2 additions & 2 deletions src/components/plate-ui/ai-leaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const AILeaf = withRef<typeof PlateLeaf>(
<PlateLeaf
ref={ref}
className={cn(
className,
'border-b-2 border-b-purple-100 bg-purple-50 text-purple-800',
'transition-all duration-200 ease-in-out',
className
'transition-all duration-200 ease-in-out'
)}
{...props}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/plate-ui/ai-menu-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useMemo } from 'react';

import { AIChatPlugin, AIPlugin } from '@udecode/plate-ai/react';
import {
type SlateEditor,
getAncestorNode,
getEndPoint,
getNodeString,
Expand Down Expand Up @@ -193,7 +194,7 @@ Start writing a new paragraph AFTER <Document> ONLY ONE SENTENCE`
aiEditor,
editor,
}: {
aiEditor: PlateEditor;
aiEditor: SlateEditor;
editor: PlateEditor;
}) => void;
}
Expand Down Expand Up @@ -247,7 +248,7 @@ export const AIMenuItems = ({
aiEditorRef,
setValue,
}: {
aiEditorRef: React.MutableRefObject<PlateEditor | null>;
aiEditorRef: React.MutableRefObject<SlateEditor | null>;
setValue: (value: string) => void;
}) => {
const { editor, useOption } = useEditorPlugin(AIChatPlugin);
Expand Down
Loading

0 comments on commit 48c87a8

Please sign in to comment.