Skip to content

Commit 6772e06

Browse files
committed
wip improve editor
1 parent ef06b6d commit 6772e06

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

resources/js/form/components/fields/editor/Editor.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
setTimeout(() => editor.value.commands.focus());
198198
});
199199
200-
async function onLocaleChange(locale: string, focus?:boolean) {
200+
async function onLocaleChange(locale: string, focus?: boolean) {
201201
emit('locale-change', locale);
202202
if(focus) {
203203
setTimeout(() => {
@@ -230,12 +230,12 @@
230230
:style="{'--height':`${fullscreenPlaceholderHeight}px`}"
231231
></div>
232232

233-
<EditorMaybeFullscreenDialog v-model:fullscreen="isFullscreen">
233+
<EditorMaybeFullscreenDialog v-bind="props" v-model:fullscreen="isFullscreen">
234234
<div
235235
:class="cn(
236236
'editor flex flex-col rounded-md overflow-clip border border-input bg-background',
237237
isFullscreen
238-
? 'border-none rounded-none'
238+
? 'border-none rounded-none bg-transparent'
239239
: 'focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background'
240240
)"
241241
:data-fullscreen="isFullscreen ? true : null"

resources/js/form/components/fields/editor/EditorMaybeFullscreenDialog.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang="ts">
2-
import { Dialog, DialogScrollContent } from "@/components/ui/dialog";
2+
import { Dialog, DialogTitle } from "@/components/ui/dialog";
33
import { cn } from "@/utils/cn";
44
import { DialogContent, DialogOverlay, DialogPortal } from "reka-ui";
5+
import { FormFieldProps } from "@/form/types";
6+
import { FormEditorFieldData } from "@/types";
57
8+
const props = defineProps<FormFieldProps<FormEditorFieldData>>();
69
const isFullscreen = defineModel<boolean>('fullscreen');
710
811
function onBackdropPointerDown(pointerDownEvent: PointerEvent) {
@@ -26,8 +29,11 @@
2629
cn(
2730
'relative z-50 grid grid-cols-1 grid-rows-1 w-full max-w-7xl gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg',
2831
)"
29-
@pointer-down-outside.prevent="onBackdropPointerDown($event.detail.originalEvent)"
32+
@pointer-down-outside.prevent="onBackdropPointerDown($event.detail.originalEvent)"
3033
>
34+
<DialogTitle class="sr-only">
35+
{{ field.label }}
36+
</DialogTitle>
3137
<slot />
3238
</DialogContent>
3339
</DialogOverlay>

resources/js/form/components/fields/editor/extensions/Clipboard.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Plugin } from '@tiptap/pm/state';
33
import { DOMParser } from '@tiptap/pm/model';
44
import { __ } from "@/utils/i18n";
55
import { EditorView } from "@tiptap/pm/view";
6+
import { NodeSelection } from "@tiptap/pm/state";
67

78
function dispatchCopy(view: EditorView) {
89
const clipboardData = new DataTransfer();
@@ -62,16 +63,20 @@ export const Clipboard = Extension.create({
6263
handleKeyDown(view, event) {
6364
// fix bug when copy isn't working in chrome https://github.com/ProseMirror/prosemirror/issues/884
6465
if((event.metaKey || event.ctrlKey) && event.key === 'c') {
65-
let copied = false;
66-
view.dom.addEventListener('copy', () => {
67-
copied = true;
68-
}, { once: true });
69-
setTimeout(() => {
70-
if(!copied) {
71-
dispatchCopy(view);
72-
}
73-
}, 50);
74-
66+
if(view.state.selection instanceof NodeSelection
67+
&& view.state.selection.node.isBlock
68+
&& view.state.selection.node.isAtom
69+
) {
70+
let copied = false;
71+
view.dom.addEventListener('copy', () => {
72+
copied = true;
73+
}, { once: true });
74+
setTimeout(() => {
75+
if(!copied) {
76+
dispatchCopy(view);
77+
}
78+
}, 50);
79+
}
7580
}
7681
},
7782

0 commit comments

Comments
 (0)