Skip to content

Commit

Permalink
new defauts + dropcursor block drop
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 26, 2023
1 parent 310c127 commit 999ebc9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
38 changes: 37 additions & 1 deletion packages/dante3/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ onUpdate func will return the entire instance of the editor, so you can use all
<div>
<DanteEditor onUpdate={(editor) => setState({ data: editor.getHTML() })} />

<div class="p-4 border-green-600 rounded-md border-2 overflow-auto">
<div className="p-4 border-green-600 rounded-md border-2 overflow-auto">
{`${state.data}`}
</div>
</div>
Expand Down Expand Up @@ -130,6 +130,42 @@ Editor Props
},
transformPastedText(text) {
return text.toUpperCase()
},
handleDrop: function (view, event, slice, moved) {
if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
let file = event.dataTransfer.files[0];
let filesize = ((file.size/1024)/1024).toFixed(4);

const { schema } = view.state;
const coordinates = view.posAtCoords({ left: event.clientX, top: event.clientY });

let _URL = window.URL || window.webkitURL;

if (file.type.startsWith("image/")) {
let image = new Image();
image.src = _URL.createObjectURL(file);
image.onload = function() {
const node = schema.nodes.ImageBlock.create({ src: image.src });
const transaction = view.state.tr.insert(coordinates.pos, node);
view.dispatch(transaction);
}
} else if (file.type.startsWith("video/")) {
const node = schema.nodes.VideoRecorderBlock.create({ url: _URL.createObjectURL(file) });
const transaction = view.state.tr.insert(coordinates.pos, node);
view.dispatch(transaction);
} else if (file.type.startsWith("audio/")) {
const node = schema.nodes.AudioRecorderBlock.create({ url: _URL.createObjectURL(file) });
const transaction = view.state.tr.insert(coordinates.pos, node);
view.dispatch(transaction);
} else {
const node = schema.nodes.FileBlock.create({ url: _URL.createObjectURL(file) });
const transaction = view.state.tr.insert(coordinates.pos, node);
view.dispatch(transaction);
}
return true
}

return false; // not handled use default behaviour
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dante3/src/blocks/audioRecorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default function AudioRecorderBlock(props: any) {
data-drag-handle="true"
>
<div
className="flex space-x-2 bg-white dark:bg-gray-800 justify-center items-center"
className="flex space-x-2 justify-center items-center"
contentEditable={false}
>

Expand Down
4 changes: 4 additions & 0 deletions packages/dante3/src/editor/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import GiphyBlock, { GiphyBlockConfig } from "../blocks/giphy/giphyBlock";
import SpeechToTextBlock, {
SpeechToTextBlockConfig,
} from "../blocks/speechToText";
import { AudioRecorderBlockConfig } from "../blocks/audioRecorder";
import { FileBlockConfig } from "../blocks/file";

//export {DanteEditor}
export { darkTheme, defaultTheme };
Expand All @@ -63,11 +65,13 @@ const defaultPlugins = [
CodeBlockConfig(),
DividerBlockConfig(),
EmbedBlockConfig(),
AudioRecorderBlockConfig(),
PlaceholderBlockConfig(),
VideoBlockConfig(),
GiphyBlockConfig(),
VideoRecorderBlockConfig(),
SpeechToTextBlockConfig(),
FileBlockConfig()
];

export { defaultPlugins };
Expand Down
3 changes: 3 additions & 0 deletions packages/dante3/src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import TextStyle from "@tiptap/extension-text-style";
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
import Focus from "@tiptap/extension-focus";
import Link from "@tiptap/extension-link";
import Dropcursor from '@tiptap/extension-dropcursor'


import { extensionFactory } from "../blocks/extension";
import {AddButtonConfig} from "../popovers/addButton";
Expand Down Expand Up @@ -112,6 +114,7 @@ const DanteEditor = ({
Color,
Focus,
Link,
Dropcursor,
/*Link.extend({
addNodeView() {
return ReactNodeViewRenderer(CodeBlock);
Expand Down

0 comments on commit 999ebc9

Please sign in to comment.