Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Dec 13, 2024
1 parent 8a00478 commit 298a0ad
Show file tree
Hide file tree
Showing 13 changed files with 722 additions and 142 deletions.
24 changes: 23 additions & 1 deletion apps/www/src/app/(app)/dev/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ import { BaseIndentListPlugin } from '@udecode/plate-indent-list';
import { BaseKbdPlugin } from '@udecode/plate-kbd';
import { BaseLineHeightPlugin } from '@udecode/plate-line-height';
import { BaseLinkPlugin } from '@udecode/plate-link';
import { BaseImagePlugin, BaseMediaEmbedPlugin } from '@udecode/plate-media';
import {
BaseAudioPlugin,
BaseFilePlugin,
BaseImagePlugin,
BaseMediaEmbedPlugin,
BaseVideoPlugin,
} from '@udecode/plate-media';
import {
BaseTableCellHeaderPlugin,
BaseTableCellPlugin,
Expand All @@ -58,6 +64,7 @@ import { indentValue } from '@/registry/default/example/values/indent-value';
import { kbdValue } from '@/registry/default/example/values/kbd-value';
import { lineHeightValue } from '@/registry/default/example/values/line-height-value';
import { linkValue } from '@/registry/default/example/values/link-value';
import { mediaValue } from '@/registry/default/example/values/media-value';
import { tableValue } from '@/registry/default/example/values/table-value';
import { BlockquoteStaticElement } from '@/registry/default/plate-static-ui/blockquote-element';
import { CodeBlockElementStatic } from '@/registry/default/plate-static-ui/code-block-element';
Expand All @@ -66,12 +73,16 @@ import { CodeLineStaticElement } from '@/registry/default/plate-static-ui/code-l
import { CodeSyntaxStaticLeaf } from '@/registry/default/plate-static-ui/code-syntax-leaf';
import { HeadingStaticElement } from '@/registry/default/plate-static-ui/heading-element';
import { HrStaticElement } from '@/registry/default/plate-static-ui/hr-element';
import { ImageStaticElement } from '@/registry/default/plate-static-ui/image-element';
import {
TodoLi,
TodoMarker,
} from '@/registry/default/plate-static-ui/indent-todo-marker';
import { KbdStaticLeaf } from '@/registry/default/plate-static-ui/kbd-leaf';
import { LinkStaticElement } from '@/registry/default/plate-static-ui/link-element';
import { MediaAudioStaticElement } from '@/registry/default/plate-static-ui/media-audio-element';
import { MediaFileStaticElement } from '@/registry/default/plate-static-ui/media-file-element';
import { MediaVideoStaticElement } from '@/registry/default/plate-static-ui/media-video-element';
import { ParagraphStaticElement } from '@/registry/default/plate-static-ui/paragraph-element';
import {
TableCellHeaderStaticElement,
Expand All @@ -82,13 +93,16 @@ import { TableRowStaticElement } from '@/registry/default/plate-static-ui/table-

export default async function DevPage() {
const staticComponents = {
[BaseAudioPlugin.key]: MediaAudioStaticElement,
[BaseBlockquotePlugin.key]: BlockquoteStaticElement,
[BaseBoldPlugin.key]: withProps(PlateStaticLeaf, { as: 'strong' }),
[BaseCodeBlockPlugin.key]: CodeBlockElementStatic,
[BaseCodeLinePlugin.key]: CodeLineStaticElement,
[BaseCodePlugin.key]: CodeStaticLeaf,
[BaseCodeSyntaxPlugin.key]: CodeSyntaxStaticLeaf,
[BaseFilePlugin.key]: MediaFileStaticElement,
[BaseHorizontalRulePlugin.key]: HrStaticElement,
[BaseImagePlugin.key]: ImageStaticElement,
[BaseItalicPlugin.key]: withProps(PlateStaticLeaf, { as: 'em' }),
[BaseKbdPlugin.key]: KbdStaticLeaf,
[BaseLinkPlugin.key]: LinkStaticElement,
Expand All @@ -101,6 +115,7 @@ export default async function DevPage() {
[BaseTablePlugin.key]: TableStaticElement,
[BaseTableRowPlugin.key]: TableRowStaticElement,
[BaseUnderlinePlugin.key]: withProps(PlateStaticLeaf, { as: 'u' }),
[BaseVideoPlugin.key]: MediaVideoStaticElement,
[HEADING_KEYS.h1]: withProps(HeadingStaticElement, { variant: 'h1' }),
[HEADING_KEYS.h2]: withProps(HeadingStaticElement, { variant: 'h2' }),
[HEADING_KEYS.h3]: withProps(HeadingStaticElement, { variant: 'h3' }),
Expand All @@ -111,8 +126,11 @@ export default async function DevPage() {

const editorStatic = createSlateEditor({
plugins: [
BaseVideoPlugin,
BaseAudioPlugin,
BaseParagraphPlugin,
BaseHeadingPlugin,
BaseMediaEmbedPlugin,
BaseBoldPlugin,
BaseCodePlugin,
BaseItalicPlugin,
Expand Down Expand Up @@ -177,6 +195,8 @@ export default async function DevPage() {
}),
BaseLineHeightPlugin,
BaseHighlightPlugin,
BaseFilePlugin,
BaseImagePlugin,
],
value: [
...basicNodesValue,
Expand All @@ -190,6 +210,8 @@ export default async function DevPage() {
...lineHeightValue,
...indentValue,
...indentListValue,
...mediaValue,
...alignValue,
],
});

Expand Down
49 changes: 49 additions & 0 deletions apps/www/src/registry/default/plate-static-ui/image-element.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';

import type { StaticElementProps } from '@udecode/plate-common';
import type { TImageElement } from '@udecode/plate-media';

import { cn } from '@udecode/cn';
import { PlateStaticElement } from '@udecode/plate-common';

export function ImageStaticElement({
children,
className,
element,
nodeProps,
...props
}: StaticElementProps) {
const {
align = 'center',
url,
width,
} = element as TImageElement & {
width: number;
};

return (
<PlateStaticElement
className={cn('py-2.5', className)}
element={element}
{...props}
>
<figure
className="group relative m-0"
style={{ textAlign: align, width: width }}
>
<div style={{ width: width }}>
<img
className={cn(
'inline-block w-full max-w-full object-cover px-0',
'rounded-sm'
)}
alt=""
src={url}
{...nodeProps}
/>
</div>
</figure>
{children}
</PlateStaticElement>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

import type { StaticElementProps } from '@udecode/plate-common';
import type { TAudioElement } from '@udecode/plate-media';

import { cn } from '@udecode/cn';
import { PlateStaticElement } from '@udecode/plate-common';

export function MediaAudioStaticElement({
children,
className,
element,
...props
}: StaticElementProps) {
const { url } = element as TAudioElement;

return (
<PlateStaticElement
className={cn('relative mb-1', className)}
element={element}
{...props}
>
<figure className="group relative">
<div className="h-16">
<audio className="size-full" src={url} controls />
</div>
</figure>
{children}
</PlateStaticElement>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';

import type { StaticElementProps } from '@udecode/plate-common';
import type { TFileElement } from '@udecode/plate-media';

import { cn } from '@udecode/cn';
import { PlateStaticElement } from '@udecode/plate-common';
import { FileUp } from 'lucide-react';

export const MediaFileStaticElement = ({
children,
className,
element,
...props
}: StaticElementProps) => {
const { name } = element as TFileElement;

return (
<PlateStaticElement
className={cn('relative my-px rounded-sm', className)}
element={element}
{...props}
>
<div
className="hover:bg-muted group relative m-0 flex cursor-pointer items-center rounded px-0.5 py-[3px]"
role="button"
>
<div className="flex items-center gap-1 p-1">
<FileUp className="size-5" />
<div>{name}</div>
</div>
</div>
{children}
</PlateStaticElement>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';

import type { StaticElementProps } from '@udecode/plate-common';
import type { TVideoElement } from '@udecode/plate-media';

import { cn } from '@udecode/cn';
import { PlateStaticElement } from '@udecode/plate-common';

export function MediaVideoStaticElement({
children,
className,
element,
...props
}: StaticElementProps) {
const { align, url, width } = element as TVideoElement & {
width: number;
};

console.log('🚀 ~ align:', align);

return (
<PlateStaticElement
className={cn('relative my-px rounded-sm', className)}
element={element}
{...props}
>
<div style={{ textAlign: align }}>
<video
className="inline-block"
src={url}
width={width}
controls
></video>
</div>
{children}
</PlateStaticElement>
);
}
Loading

0 comments on commit 298a0ad

Please sign in to comment.