Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Nov 4, 2024
1 parent 5bcc4d4 commit 42ee535
Show file tree
Hide file tree
Showing 44 changed files with 71 additions and 60 deletions.
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/ai-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/align-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/basic-elements-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/basic-marks-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/basic-nodes-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/block-menu-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/block-selection-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/column-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/comment-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/copilot-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/date-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/dnd-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/emoji-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/excalidraw-demo.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/font-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/highlight-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/hr-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/image-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"files": [
{
"content": "'use client';\n\nimport React from 'react';\n\nimport { cn, withRef } from '@udecode/cn';\nimport { withHOC } from '@udecode/plate-common/react';\nimport { Image, ImagePlugin, useMediaState } from '@udecode/plate-media/react';\nimport { ResizableProvider, useResizableStore } from '@udecode/plate-resizable';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport { PlateElement } from './plate-element';\nimport {\n Resizable,\n ResizeHandle,\n mediaResizeHandleVariants,\n} from './resizable';\n\nexport const ImageElement = withHOC(\n ResizableProvider,\n withRef<typeof PlateElement>(\n ({ children, className, nodeProps, ...props }, ref) => {\n const { align = 'center', focused, readOnly, selected } = useMediaState();\n\n const width = useResizableStore().get.width();\n\n return (\n <MediaPopover plugin={ImagePlugin}>\n <PlateElement\n ref={ref}\n className={cn('py-2.5', className)}\n {...props}\n >\n <figure className=\"group relative m-0\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n align,\n readOnly,\n }}\n >\n <ResizeHandle\n className={mediaResizeHandleVariants({ direction: 'left' })}\n options={{ direction: 'left' }}\n />\n <Image\n className={cn(\n 'block w-full max-w-full cursor-pointer object-cover px-0',\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2'\n )}\n alt=\"\"\n {...nodeProps}\n />\n <ResizeHandle\n className={mediaResizeHandleVariants({\n direction: 'right',\n })}\n options={{ direction: 'right' }}\n />\n </Resizable>\n\n <Caption style={{ width }} align={align}>\n <CaptionTextarea\n readOnly={readOnly}\n placeholder=\"Write a caption...\"\n />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n }\n )\n);\n",
"content": "'use client';\n\nimport React from 'react';\n\nimport { cn, withRef } from '@udecode/cn';\nimport { withHOC } from '@udecode/plate-common/react';\nimport { useDraggable, useDraggableState } from '@udecode/plate-dnd';\nimport { Image, ImagePlugin, useMediaState } from '@udecode/plate-media/react';\nimport { ResizableProvider, useResizableStore } from '@udecode/plate-resizable';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport { PlateElement } from './plate-element';\nimport {\n Resizable,\n ResizeHandle,\n mediaResizeHandleVariants,\n} from './resizable';\n\nexport const ImageElement = withHOC(\n ResizableProvider,\n withRef<typeof PlateElement>(\n ({ children, className, nodeProps, ...props }, ref) => {\n const { align = 'center', focused, readOnly, selected } = useMediaState();\n\n const width = useResizableStore().get.width();\n\n const state = useDraggableState({ element: props.element });\n const { isDragging } = state;\n const { handleRef } = useDraggable(state);\n\n return (\n <MediaPopover plugin={ImagePlugin}>\n <PlateElement\n ref={ref}\n className={cn('py-2.5', className)}\n {...props}\n >\n <figure className=\"group relative m-0\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n align,\n readOnly,\n }}\n >\n <ResizeHandle\n className={mediaResizeHandleVariants({ direction: 'left' })}\n options={{ direction: 'left' }}\n />\n <Image\n ref={handleRef}\n className={cn(\n 'block w-full max-w-full cursor-pointer object-cover px-0',\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2',\n isDragging && 'opacity-50'\n )}\n alt=\"\"\n {...nodeProps}\n />\n <ResizeHandle\n className={mediaResizeHandleVariants({\n direction: 'right',\n })}\n options={{ direction: 'right' }}\n />\n </Resizable>\n\n <Caption style={{ width }} align={align}>\n <CaptionTextarea\n readOnly={readOnly}\n onFocus={(e) => {\n e.preventDefault();\n }}\n placeholder=\"Write a caption...\"\n />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n }\n )\n);\n",
"path": "plate-ui/image-element.tsx",
"target": "components/plate-ui/image-element.tsx",
"type": "registry:ui"
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/indent-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/kbd-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/line-height-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/link-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/list-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/media-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/mention-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/mode-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/placeholder-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/playground-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/resizable-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/slash-command-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/table-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/toc-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/toggle-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/toolbar-demo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/upload-demo.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions apps/www/src/registry/default/example/playground-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ export const usePlaygroundEditor = (id: any = '', scrollSelector?: string) => {
DndPlugin.configure({
options: {
enableScroller: true,
onDropFiles: (editor, props) => {
onDropFiles: ({ dragItem, editor, target }) => {
editor
.getTransforms(ImagePlugin)
.insertImageFromFiles(props.dragItem.files, {
at: props.dropPath,
.insert.imageFromFiles(dragItem.files, {
at: target,
nextBlock: false,
});
},
Expand Down
12 changes: 11 additions & 1 deletion apps/www/src/registry/default/plate-ui/image-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';

import { cn, withRef } from '@udecode/cn';
import { withHOC } from '@udecode/plate-common/react';
import { useDraggable, useDraggableState } from '@udecode/plate-dnd';
import { Image, ImagePlugin, useMediaState } from '@udecode/plate-media/react';
import { ResizableProvider, useResizableStore } from '@udecode/plate-resizable';

Expand All @@ -24,6 +25,10 @@ export const ImageElement = withHOC(

const width = useResizableStore().get.width();

const state = useDraggableState({ element: props.element });
const { isDragging } = state;
const { handleRef } = useDraggable(state);

return (
<MediaPopover plugin={ImagePlugin}>
<PlateElement
Expand All @@ -44,10 +49,12 @@ export const ImageElement = withHOC(
options={{ direction: 'left' }}
/>
<Image
ref={handleRef}
className={cn(
'block w-full max-w-full cursor-pointer object-cover px-0',
'rounded-sm',
focused && selected && 'ring-2 ring-ring ring-offset-2'
focused && selected && 'ring-2 ring-ring ring-offset-2',
isDragging && 'opacity-50'
)}
alt=""
{...nodeProps}
Expand All @@ -63,6 +70,9 @@ export const ImageElement = withHOC(
<Caption style={{ width }} align={align}>
<CaptionTextarea
readOnly={readOnly}
onFocus={(e) => {
e.preventDefault();
}}
placeholder="Write a caption..."
/>
</Caption>
Expand Down
18 changes: 8 additions & 10 deletions packages/dnd/src/DndPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ export type DndConfig = PluginConfig<
enableScroller?: boolean;
isDragging?: boolean;
scrollerProps?: Partial<ScrollerProps>;
onDropFiles?: (
props: {
editor: PlateEditor;
id: string;
dragItem: FileDragItemNode;
monitor: DropTargetMonitor<DragItemNode, unknown>;
nodeRef: any;
dropPath?: Path;
}
) => void;
onDropFiles?: (props: {
id: string;
dragItem: FileDragItemNode;
editor: PlateEditor;
monitor: DropTargetMonitor<DragItemNode, unknown>;
nodeRef: any;
target?: Path;
}) => void;
}
>;

Expand Down
5 changes: 3 additions & 2 deletions packages/dnd/src/hooks/useDropNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ export const useDropNode = (

if (!result || !onDropFiles) return;

return onDropFiles(editor, {
return onDropFiles({
id,
dragItem: dragItem as FileDragItemNode,
dropPath: result.to,
editor,
monitor,
nodeRef,
target: result.to,
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/media/src/lib/image/BaseImagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const BaseImagePlugin = createTSlatePlugin<ImageConfig>({
},
})
.extendEditorTransforms(({ editor }) => ({
insertImageFromFiles: bindFirst(insertImageFromFiles, editor),
insert: {
imageFromFiles: bindFirst(insertImageFromFiles, editor as any),
},
}))
.extend(({ plugin }) => ({
parsers: {
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/lib/image/withImageEmbed.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getEditorPlugin } from '@udecode/plate-common';
import { createSlateEditor } from '@udecode/plate-common';
import { jsx } from '@udecode/plate-test-utils';

import { BaseImagePlugin } from './BaseImagePlugin';
import { ImagePlugin } from '../../react';
import { withImageEmbed } from './withImageEmbed';

jsx;
Expand All @@ -27,7 +27,7 @@ describe('withImageEmbed', () => {

it('should insert image from the text', () => {
const editor = withImageEmbed(
getEditorPlugin(createSlateEditor({ editor: input }), BaseImagePlugin)
getEditorPlugin(createSlateEditor({ editor: input }), ImagePlugin as any)
);

const data = {
Expand Down
8 changes: 4 additions & 4 deletions packages/media/src/lib/image/withImageUpload.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { createPlateEditor } from '@udecode/plate-common/react';
import { jsx } from '@udecode/plate-test-utils';
import { ImagePlugin } from '../../react';

import { BaseImagePlugin } from './BaseImagePlugin';

jsx;

Expand All @@ -24,7 +24,7 @@ describe('withImageUpload', () => {
it('should insert image from the file(s)', () => {
const editor = createPlateEditor({
editor: input,
plugins: [BaseImagePlugin],
plugins: [ImagePlugin],
});

const data = {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('withImageUpload', () => {

const editor = createPlateEditor({
editor: input,
plugins: [BaseImagePlugin],
plugins: [ImagePlugin],
});

const data = {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('withImageUpload', () => {
it('should insert image from the file(s)', () => {
const editor = createPlateEditor({
editor: input,
plugins: [BaseImagePlugin],
plugins: [ImagePlugin],
});

const data = {
Expand Down
2 changes: 1 addition & 1 deletion packages/media/src/lib/image/withImageUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const withImageUpload: ExtendEditor<ImageConfig> = ({
return insertData(dataTransfer);
}

editor.getTransforms(ImagePlugin).insertImageFromFiles(files);
editor.getTransforms(ImagePlugin).insert.imageFromFiles(files);
} else {
return insertData(dataTransfer);
}
Expand Down

0 comments on commit 42ee535

Please sign in to comment.