Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export #3807

Merged
merged 8 commits into from
Nov 26, 2024
Merged

export #3807

Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions apps/www/content/docs/examples/export.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Export
---

<ComponentPreview name="playground-demo" id="basic-elements" />
felixfeng33 marked this conversation as resolved.
Show resolved Hide resolved

<PackageInfo>

## Features

- Export editor content to:
- Client-side export with no server dependencies

</PackageInfo>

## Usage

Install the [PDF Toolbar Button](/docs/plate-ui/pdf-toolbar-button) component.

Note: When using Tailwind CSS, you may encounter background color issues. Please refer to [this link](https://github.com/niklasvh/html2canvas/issues/2775#issuecomment-1204988157) for a solution.

Add the following CSS to fix background color rendering issues with html2canvas:
```css
@layer base {
img {
@apply inline-block;
}
}
```

## Examples

### Plate UI

Refer to the preview above.

### Plate Plus

- Server-side PDF export:
- High-quality PDF generation
- Custom fonts and styling
- Headers and footers
- Page numbers
- Font selectable
- Advanced export options:
- Paper size selection
- Margin controls
- Orientation settings
- Compression level
- Enterprise-ready features:
{/* - Batch processing */}
{/* - Watermarking */}
- Custom templates
- Password protection

Try it out with our server-side PDF export:

<ComponentPreviewPro name="export-demo" />
2 changes: 2 additions & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@
"contentlayer2": "^0.4.6",
"date-fns": "^3.6.0",
"framer-motion": "^11.5.4",
"html2canvas": "^1.4.1",
"lodash.template": "^4.5.0",
"lucide-react": "0.460.0",
"match-sorter": "6.3.4",
"next": "15.0.3",
"next-contentlayer2": "^0.4.6",
"next-themes": "^0.4.3",
"nuqs": "^2.0.3",
"pdf-lib": "^1.17.1",
"prismjs": "^1.29.0",
"react": "^18.3.1",
"react-day-picker": "^8.10.1",
Expand Down
13 changes: 13 additions & 0 deletions apps/www/public/r/styles/default/export-demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": [
{
"content": "'use client';\n\nimport React from 'react';\n\nimport {\n Plate,\n PlateContent,\n usePlateEditor,\n} from '@udecode/plate-common/react';\n\nexport default function BasicEditorDefaultDemo() {\n const editor = usePlateEditor();\n\n return (\n <Plate editor={editor}>\n <PlateContent placeholder=\"Type...\" />\n </Plate>\n );\n}\n",
"path": "example/export-demo.tsx",
"target": "components/export-demo.tsx",
"type": "registry:example"
}
],
"name": "export-demo",
"registryDependencies": [],
"type": "registry:example"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"files": [
{
"content": "'use client';\n\nimport React from 'react';\n\nimport {\n BoldPlugin,\n CodePlugin,\n ItalicPlugin,\n StrikethroughPlugin,\n UnderlinePlugin,\n} from '@udecode/plate-basic-marks/react';\nimport { useEditorReadOnly } from '@udecode/plate-common/react';\nimport {\n FontBackgroundColorPlugin,\n FontColorPlugin,\n} from '@udecode/plate-font/react';\nimport { HighlightPlugin } from '@udecode/plate-highlight/react';\nimport { ListStyleType } from '@udecode/plate-indent-list';\nimport {\n AudioPlugin,\n FilePlugin,\n ImagePlugin,\n VideoPlugin,\n} from '@udecode/plate-media/react';\nimport {\n BaselineIcon,\n BoldIcon,\n Code2Icon,\n HighlighterIcon,\n ItalicIcon,\n PaintBucketIcon,\n StrikethroughIcon,\n UnderlineIcon,\n WandSparklesIcon,\n} from 'lucide-react';\n\nimport { MoreDropdownMenu } from '@/components/plate-ui/more-dropdown-menu';\n\nimport { AIToolbarButton } from './ai-toolbar-button';\nimport { AlignDropdownMenu } from './align-dropdown-menu';\nimport { ColorDropdownMenu } from './color-dropdown-menu';\nimport { CommentToolbarButton } from './comment-toolbar-button';\nimport { EmojiDropdownMenu } from './emoji-dropdown-menu';\nimport { RedoToolbarButton, UndoToolbarButton } from './history-toolbar-button';\nimport { IndentListToolbarButton } from './indent-list-toolbar-button';\nimport { IndentTodoToolbarButton } from './indent-todo-toolbar-button';\nimport { IndentToolbarButton } from './indent-toolbar-button';\nimport { InsertDropdownMenu } from './insert-dropdown-menu';\nimport { LineHeightDropdownMenu } from './line-height-dropdown-menu';\nimport { LinkToolbarButton } from './link-toolbar-button';\nimport { MarkToolbarButton } from './mark-toolbar-button';\nimport { MediaToolbarButton } from './media-toolbar-button';\nimport { ModeDropdownMenu } from './mode-dropdown-menu';\nimport { OutdentToolbarButton } from './outdent-toolbar-button';\nimport { TableDropdownMenu } from './table-dropdown-menu';\nimport { ToggleToolbarButton } from './toggle-toolbar-button';\nimport { ToolbarGroup } from './toolbar';\nimport { TurnIntoDropdownMenu } from './turn-into-dropdown-menu';\n\nexport function FixedToolbarButtons() {\n const readOnly = useEditorReadOnly();\n\n return (\n <div className=\"flex w-full\">\n {!readOnly && (\n <>\n <ToolbarGroup>\n <UndoToolbarButton />\n <RedoToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <AIToolbarButton tooltip=\"AI commands\">\n <WandSparklesIcon />\n </AIToolbarButton>\n </ToolbarGroup>\n\n <ToolbarGroup>\n <InsertDropdownMenu />\n <TurnIntoDropdownMenu />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MarkToolbarButton nodeType={BoldPlugin.key} tooltip=\"Bold (⌘+B)\">\n <BoldIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={ItalicPlugin.key}\n tooltip=\"Italic (⌘+I)\"\n >\n <ItalicIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={UnderlinePlugin.key}\n tooltip=\"Underline (⌘+U)\"\n >\n <UnderlineIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={StrikethroughPlugin.key}\n tooltip=\"Strikethrough (⌘+⇧+M)\"\n >\n <StrikethroughIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton nodeType={CodePlugin.key} tooltip=\"Code (⌘+E)\">\n <Code2Icon />\n </MarkToolbarButton>\n\n <ColorDropdownMenu\n nodeType={FontColorPlugin.key}\n tooltip=\"Text color\"\n >\n <BaselineIcon />\n </ColorDropdownMenu>\n\n <ColorDropdownMenu\n nodeType={FontBackgroundColorPlugin.key}\n tooltip=\"Background color\"\n >\n <PaintBucketIcon />\n </ColorDropdownMenu>\n </ToolbarGroup>\n\n <ToolbarGroup>\n <AlignDropdownMenu />\n\n <IndentListToolbarButton nodeType={ListStyleType.Disc} />\n <IndentListToolbarButton nodeType={ListStyleType.Decimal} />\n <IndentTodoToolbarButton />\n <ToggleToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <LinkToolbarButton />\n <TableDropdownMenu />\n <EmojiDropdownMenu />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MediaToolbarButton nodeType={ImagePlugin.key} />\n <MediaToolbarButton nodeType={VideoPlugin.key} />\n <MediaToolbarButton nodeType={AudioPlugin.key} />\n <MediaToolbarButton nodeType={FilePlugin.key} />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <LineHeightDropdownMenu />\n <OutdentToolbarButton />\n <IndentToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MoreDropdownMenu />\n </ToolbarGroup>\n </>\n )}\n\n <div className=\"grow\" />\n\n <ToolbarGroup>\n <MarkToolbarButton nodeType={HighlightPlugin.key} tooltip=\"Highlight\">\n <HighlighterIcon />\n </MarkToolbarButton>\n <CommentToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <ModeDropdownMenu />\n </ToolbarGroup>\n </div>\n );\n}\n",
"content": "'use client';\n\nimport React from 'react';\n\nimport {\n BoldPlugin,\n CodePlugin,\n ItalicPlugin,\n StrikethroughPlugin,\n UnderlinePlugin,\n} from '@udecode/plate-basic-marks/react';\nimport { useEditorReadOnly } from '@udecode/plate-common/react';\nimport {\n FontBackgroundColorPlugin,\n FontColorPlugin,\n} from '@udecode/plate-font/react';\nimport { HighlightPlugin } from '@udecode/plate-highlight/react';\nimport { ListStyleType } from '@udecode/plate-indent-list';\nimport {\n AudioPlugin,\n FilePlugin,\n ImagePlugin,\n VideoPlugin,\n} from '@udecode/plate-media/react';\nimport {\n ArrowUpToLineIcon,\n BaselineIcon,\n BoldIcon,\n Code2Icon,\n HighlighterIcon,\n ItalicIcon,\n PaintBucketIcon,\n StrikethroughIcon,\n UnderlineIcon,\n WandSparklesIcon,\n} from 'lucide-react';\n\nimport { MoreDropdownMenu } from '@/components/plate-ui/more-dropdown-menu';\n\nimport { AIToolbarButton } from './ai-toolbar-button';\nimport { AlignDropdownMenu } from './align-dropdown-menu';\nimport { ColorDropdownMenu } from './color-dropdown-menu';\nimport { CommentToolbarButton } from './comment-toolbar-button';\nimport { EmojiDropdownMenu } from './emoji-dropdown-menu';\nimport { RedoToolbarButton, UndoToolbarButton } from './history-toolbar-button';\nimport { IndentListToolbarButton } from './indent-list-toolbar-button';\nimport { IndentTodoToolbarButton } from './indent-todo-toolbar-button';\nimport { IndentToolbarButton } from './indent-toolbar-button';\nimport { InsertDropdownMenu } from './insert-dropdown-menu';\nimport { LineHeightDropdownMenu } from './line-height-dropdown-menu';\nimport { LinkToolbarButton } from './link-toolbar-button';\nimport { MarkToolbarButton } from './mark-toolbar-button';\nimport { MediaToolbarButton } from './media-toolbar-button';\nimport { ModeDropdownMenu } from './mode-dropdown-menu';\nimport { OutdentToolbarButton } from './outdent-toolbar-button';\nimport { PdfToolbarButton } from './pdf-toolbar-button';\nimport { TableDropdownMenu } from './table-dropdown-menu';\nimport { ToggleToolbarButton } from './toggle-toolbar-button';\nimport { ToolbarGroup } from './toolbar';\nimport { TurnIntoDropdownMenu } from './turn-into-dropdown-menu';\n\nexport function FixedToolbarButtons() {\n const readOnly = useEditorReadOnly();\n\n return (\n <div className=\"flex w-full\">\n {!readOnly && (\n <>\n <ToolbarGroup>\n <UndoToolbarButton />\n <RedoToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <AIToolbarButton tooltip=\"AI commands\">\n <WandSparklesIcon />\n </AIToolbarButton>\n </ToolbarGroup>\n\n <ToolbarGroup>\n <PdfToolbarButton tooltip=\"Export PDF\">\n <ArrowUpToLineIcon />\n </PdfToolbarButton>\n </ToolbarGroup>\n\n <ToolbarGroup>\n <InsertDropdownMenu />\n <TurnIntoDropdownMenu />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MarkToolbarButton nodeType={BoldPlugin.key} tooltip=\"Bold (⌘+B)\">\n <BoldIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={ItalicPlugin.key}\n tooltip=\"Italic (⌘+I)\"\n >\n <ItalicIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={UnderlinePlugin.key}\n tooltip=\"Underline (⌘+U)\"\n >\n <UnderlineIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton\n nodeType={StrikethroughPlugin.key}\n tooltip=\"Strikethrough (⌘+⇧+M)\"\n >\n <StrikethroughIcon />\n </MarkToolbarButton>\n\n <MarkToolbarButton nodeType={CodePlugin.key} tooltip=\"Code (⌘+E)\">\n <Code2Icon />\n </MarkToolbarButton>\n\n <ColorDropdownMenu\n nodeType={FontColorPlugin.key}\n tooltip=\"Text color\"\n >\n <BaselineIcon />\n </ColorDropdownMenu>\n\n <ColorDropdownMenu\n nodeType={FontBackgroundColorPlugin.key}\n tooltip=\"Background color\"\n >\n <PaintBucketIcon />\n </ColorDropdownMenu>\n </ToolbarGroup>\n\n <ToolbarGroup>\n <AlignDropdownMenu />\n\n <IndentListToolbarButton nodeType={ListStyleType.Disc} />\n <IndentListToolbarButton nodeType={ListStyleType.Decimal} />\n <IndentTodoToolbarButton />\n <ToggleToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <LinkToolbarButton />\n <TableDropdownMenu />\n <EmojiDropdownMenu />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MediaToolbarButton nodeType={ImagePlugin.key} />\n <MediaToolbarButton nodeType={VideoPlugin.key} />\n <MediaToolbarButton nodeType={AudioPlugin.key} />\n <MediaToolbarButton nodeType={FilePlugin.key} />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <LineHeightDropdownMenu />\n <OutdentToolbarButton />\n <IndentToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <MoreDropdownMenu />\n </ToolbarGroup>\n </>\n )}\n\n <div className=\"grow\" />\n\n <ToolbarGroup>\n <MarkToolbarButton nodeType={HighlightPlugin.key} tooltip=\"Highlight\">\n <HighlighterIcon />\n </MarkToolbarButton>\n <CommentToolbarButton />\n </ToolbarGroup>\n\n <ToolbarGroup>\n <ModeDropdownMenu />\n </ToolbarGroup>\n </div>\n );\n}\n",
"path": "plate-ui/fixed-toolbar-buttons.tsx",
"target": "components/plate-ui/fixed-toolbar-buttons.tsx",
"type": "registry:ui"
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/toc-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"files": [
{
"content": "'use client';\n\nimport { cn, withRef } from '@udecode/cn';\nimport {\n useTocElement,\n useTocElementState,\n} from '@udecode/plate-heading/react';\nimport { cva } from 'class-variance-authority';\n\nimport { Button } from './button';\nimport { PlateElement } from './plate-element';\n\nconst headingItemVariants = cva(\n 'block h-auto w-full cursor-pointer truncate rounded-none px-0.5 py-1.5 text-left font-medium text-muted-foreground underline decoration-[0.5px] underline-offset-4 hover:bg-accent hover:text-muted-foreground',\n {\n variants: {\n depth: {\n 1: 'pl-0.5',\n 2: 'pl-[26px]',\n 3: 'pl-[50px]',\n },\n },\n }\n);\n\nexport const TocElement = withRef<typeof PlateElement>(\n ({ children, className, ...props }, ref) => {\n const state = useTocElementState();\n\n const { props: btnProps } = useTocElement(state);\n\n const { headingList } = state;\n\n return (\n <PlateElement\n ref={ref}\n className={cn('relative mb-1 p-0', className)}\n {...props}\n >\n <nav contentEditable={false}>\n {headingList.length > 0 ? (\n headingList.map((item) => (\n <Button\n key={item.id}\n variant=\"ghost\"\n className={cn(\n headingItemVariants({ depth: item.depth as any })\n )}\n onClick={(e) => btnProps.onClick(e, item, 'smooth')}\n aria-current\n >\n {item.title}\n </Button>\n ))\n ) : (\n <div className=\"text-sm text-gray-500\">\n Create a heading to display the table of contents.\n </div>\n )}\n </nav>\n {children}\n </PlateElement>\n );\n }\n);\n",
"content": "'use client';\n\nimport { cn, withRef } from '@udecode/cn';\nimport {\n useTocElement,\n useTocElementState,\n} from '@udecode/plate-heading/react';\nimport { cva } from 'class-variance-authority';\n\nimport { Button } from './button';\nimport { PlateElement } from './plate-element';\n\nconst headingItemVariants = cva(\n 'block h-auto w-full cursor-pointer truncate rounded-none px-0.5 py-1.5 text-left font-medium text-muted-foreground underline decoration-[0.5px] underline-offset-4 hover:bg-accent hover:text-muted-foreground',\n {\n variants: {\n depth: {\n 1: 'pl-0.5',\n 2: 'pl-[26px]',\n 3: 'pl-[50px]',\n },\n },\n }\n);\n\nexport const TocElement = withRef<typeof PlateElement>(\n ({ children, className, ...props }, ref) => {\n const state = useTocElementState();\n\n const { props: btnProps } = useTocElement(state);\n\n const { headingList } = state;\n\n return (\n <PlateElement\n ref={ref}\n className={cn('relative mb-1 p-0', className)}\n {...props}\n >\n <div contentEditable={false}>\n {headingList.length > 0 ? (\n headingList.map((item) => (\n <Button\n key={item.id}\n variant=\"ghost\"\n className={cn(\n headingItemVariants({ depth: item.depth as any })\n )}\n onClick={(e) => btnProps.onClick(e, item, 'smooth')}\n aria-current\n >\n {item.title}\n </Button>\n ))\n ) : (\n <div className=\"text-sm text-gray-500\">\n Create a heading to display the table of contents.\n </div>\n )}\n </div>\n {children}\n </PlateElement>\n );\n }\n);\n",
"path": "plate-ui/toc-element.tsx",
"target": "components/plate-ui/toc-element.tsx",
"type": "registry:ui"
Expand Down
6 changes: 6 additions & 0 deletions apps/www/src/config/docs-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { registryToNav } from '@/config/registry-to-nav';
import { docExamples } from '@/registry/registry-examples';

export const docsExamples: SidebarNavItem[] = [
{
description: 'Export a Plate document to a file.',
href: '/docs/examples/export',
label: 'New',
title: 'Export',
},
{
description:
"Show a diff of two different points in a Plate document's history.",
Expand Down
3 changes: 2 additions & 1 deletion apps/www/src/registry/default/plate-ui/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const EditorContainer = ({
editorContainerVariants({ variant }),
className
)}
role="button"
// Adding this role attribute could cause the content captured by html2canvas to be incorrectly centered.
// role="button"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
VideoPlugin,
} from '@udecode/plate-media/react';
import {
ArrowUpToLineIcon,
BaselineIcon,
BoldIcon,
Code2Icon,
Expand Down Expand Up @@ -52,6 +53,7 @@ import { MarkToolbarButton } from './mark-toolbar-button';
import { MediaToolbarButton } from './media-toolbar-button';
import { ModeDropdownMenu } from './mode-dropdown-menu';
import { OutdentToolbarButton } from './outdent-toolbar-button';
import { PdfToolbarButton } from './pdf-toolbar-button';
import { TableDropdownMenu } from './table-dropdown-menu';
import { ToggleToolbarButton } from './toggle-toolbar-button';
import { ToolbarGroup } from './toolbar';
Expand All @@ -75,6 +77,12 @@ export function FixedToolbarButtons() {
</AIToolbarButton>
</ToolbarGroup>

<ToolbarGroup>
<PdfToolbarButton tooltip="Export PDF">
<ArrowUpToLineIcon />
</PdfToolbarButton>
</ToolbarGroup>

<ToolbarGroup>
<InsertDropdownMenu />
<TurnIntoDropdownMenu />
Expand Down
Loading
Loading