Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions resources/css/shadcn.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
--sidebar-border: 240 3.7% 15.9%;
--sidebar-ring: 240 4.9% 83.9%;
}

.dark {
--text-destructive: oklch(0.704 0.191 22.216);
}
}

@layer utilities {
.text-destructive {
@apply dark:text-[var(--text-destructive)];
}
}


Expand Down
3 changes: 3 additions & 0 deletions resources/js/form/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
postFn?: (data: FormData['data']) => Promise<ApiResponse<any>>,
showErrorAlert?: boolean,
errorAlertMessage?: string,
persistThumbnailUrl?: boolean,
tab?: string,
}>();

Expand Down Expand Up @@ -227,6 +228,7 @@
:value="form.data[fieldLayout.key]"
:locale="(form.getMeta(fieldLayout.key) as FieldMeta)?.locale ?? form.defaultLocale"
:parent-data="form.data"
:persist-thumbnail-url="props.persistThumbnailUrl"
:row="row"
root
@input="(value, options) => onFieldInput(fieldLayout.key, value, options)"
Expand All @@ -253,6 +255,7 @@
:locale="(form.getMeta(fieldLayout.key) as FieldMeta)?.locale ?? form.currentLocale"
:row="row as LayoutFieldData[]"
:parent-data="form.data"
:persist-thumbnail-url="props.persistThumbnailUrl"
root
@input="(value, options) => onFieldInput(fieldLayout.key, value, options)"
@locale-change="onFieldLocaleChange(fieldLayout.key, $event)"
Expand Down
4 changes: 4 additions & 0 deletions resources/js/form/components/FormFieldLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

import LocaleSelectTrigger from "@/components/LocaleSelectTrigger.vue";

defineOptions({
inheritAttrs: false
});

const props = defineProps<FormFieldProps<FormFieldData, any> & {
class?: string,
fieldGroup?: boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Extension } from "@tiptap/core";
import { Command, Extension } from "@tiptap/core";
import { Plugin } from '@tiptap/pm/state';
import { DOMParser, Schema } from '@tiptap/pm/model';
import { __ } from "@/utils/i18n";

export const Paste = Extension.create({
name: 'paste',
export const Clipboard = Extension.create({
name: 'clipboard',
addOptions() {
return {
schema: null,
Expand All @@ -19,7 +20,7 @@ export const Paste = Extension.create({
return [
new Plugin({
props: {
clipboardParser: parser,
// clipboardParser: parser,
clipboardTextParser: (text, $context) => {
if(this.options.inline) {
const dom = document.createElement('div');
Expand All @@ -44,8 +45,45 @@ export const Paste = Extension.create({
})
]
},
addCommands() {
return {
copyNode: (pos: number): Command => ({ editor, dispatch }) => {
if(dispatch) {
editor.commands.setNodeSelection(pos);
const clipboardData = new DataTransfer();
const event = new ClipboardEvent('copy', {
bubbles: true,
cancelable: true,
clipboardData,
});

editor.view.dom.dispatchEvent(event);

const clipboardItem = new ClipboardItem({
'text/html': clipboardData.getData('text/html'),
'text/plain': clipboardData.getData('text/plain'),
});

navigator.clipboard.write([clipboardItem]).then(() => {
}).catch(err => {
alert(__('sharp::errors.failed_to_write_to_clipboard'));
});
}

return true;
},
}
}
});

declare module '@tiptap/core' {
interface Commands<ReturnType> {
'clipboard': {
copyNode: (pos: number) => ReturnType
}
}
}

// needed to keep same references of node/mark types
function getNormalizedSchema(target, source) {
const schema = new Schema(target.spec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Selection = Extension.create({

state.doc.nodesBetween(selection.from, selection.to, (node, position) => {
if (node.isBlock) {
decorations.push(Decoration.node(position, position + node.nodeSize, { class: 'selected' }));
decorations.push(Decoration.node(position, position + node.nodeSize, { 'data-textselected': 'true' }));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const embedData = computed(() => embedManager.getEmbed(props.node.attrs['data-key'], props.extension.options.embed));

function onRemove() {
props.editor.commands.setNodeSelection(props.getPos());
props.deleteNode();
setTimeout(() => {
props.editor.commands.focus();
Expand All @@ -42,7 +43,7 @@

<template>
<NodeRenderer
class="my-4 first:mt-0 last:mb-0 border rounded-md items-center p-4 flex gap-4"
class="my-4 first:mt-0 last:mb-0 border rounded-md items-center p-4 flex gap-4 group-focus/editor:data-[textselected]:border-primary"
:class="{ 'group-focus/editor:border-primary': props.selected }"
:node="node"
>
Expand All @@ -67,8 +68,11 @@
<DropdownMenuItem @click="embedModal.open({ id: node.attrs['data-key'], embed: extension.options.embed })">
{{ __('sharp::form.editor.extension_node.edit_button') }}
</DropdownMenuItem>
<DropdownMenuSeparator />
</template>
<DropdownMenuItem @click="props.editor.commands.copyNode(props.getPos())">
{{ __('sharp::form.editor.extension_node.copy_button') }}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem class="text-destructive" @click="onRemove">
{{ __('sharp::form.editor.extension_node.remove_button') }}
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}

function onRemove() {
props.editor.commands.setNodeSelection(props.getPos());
props.deleteNode();
setTimeout(() => {
props.editor.commands.focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
}

function onRemove() {
props.editor.commands.setNodeSelection(props.getPos());
props.deleteNode();
setTimeout(() => {
props.editor.commands.focus();
Expand Down Expand Up @@ -114,6 +115,9 @@
<DropdownMenuItem @click="onEdit()">
{{ __('sharp::form.editor.extension_node.edit_button') }}
</DropdownMenuItem>
<DropdownMenuItem @click="props.editor.commands.copyNode(props.getPos())">
{{ __('sharp::form.editor.extension_node.copy_button') }}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem class="text-destructive" @click="onRemove()">
{{ __('sharp::form.editor.extension_node.remove_button') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Selection } from './Selection';
import { Html } from './html/Html';
import { TrailingNode } from './TrailingNode';
import { Iframe } from './iframe/Iframe';
import { Paste } from './Paste';
import { Clipboard } from './Clipboard';
import { Small } from './Small';
import { CharacterCount } from '@tiptap/extension-character-count';
import { FormEditorFieldData, FormEditorToolbarButton } from "@/types";
Expand Down Expand Up @@ -120,7 +120,7 @@ function getExtensions(field: FormEditorFieldData) {
export function getExtensionsForEditor(field: FormEditorFieldData) {
return [
...getExtensions(field),
Paste.configure({
Clipboard.configure({
schema: getSchema(getExtensions({
...field,
toolbar: field.toolbar ?? [], // if no toolbar, prevent pasting formatted HTML
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { FormFieldProps } from "@/form/types";
import { FormEditorFieldData } from "@/types";
import { nextTick, ref, useTemplateRef } from "vue";
import { Form } from "@/form/Form";
Expand Down Expand Up @@ -104,6 +103,7 @@
<SharpForm
:form="modalUpload.form"
:post-fn="postForm"
persist-thumbnail-url
modal
ref="modalForm"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { ExtensionNodeProps } from "@/form/components/fields/editor/types";
import { useParentEditor } from "@/form/components/fields/editor/useParentEditor";
import { useEditorNode } from "@/form/components/fields/editor/useEditorNode";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";

const props = defineProps<ExtensionNodeProps<typeof UploadExtension, UploadNodeAttributes>>();

Expand Down Expand Up @@ -57,6 +58,7 @@
}

function onRemove() {
props.editor.commands.setNodeSelection(props.getPos());
props.deleteNode();
setTimeout(() => {
props.editor.commands.focus();
Expand Down Expand Up @@ -85,6 +87,7 @@
:field-error-key="`${parentEditor.props.fieldErrorKey}-upload-${props.node.attrs['data-key']}`"
:value="upload?.file"
as-editor-embed
persist-thumbnail-url
:legend="upload.legend"
:dropdown-edit-label="parentEditor.props.field.uploads.fields.legend ? __('sharp::form.editor.extension_node.edit_button') : null"
:aria-label="props.node.attrs.isImage
Expand All @@ -97,6 +100,12 @@
@remove="onRemove"
@edit="onEdit"
ref="uploadComponent"
/>
>
<template #dropdown-menu>
<DropdownMenuItem @click="props.editor.commands.copyNode(props.getPos())">
{{ __('sharp::form.editor.extension_node.copy_button') }}
</DropdownMenuItem>
</template>
</Upload>
</NodeRenderer>
</template>
9 changes: 9 additions & 0 deletions resources/js/form/components/fields/upload/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
legend?: string,
dropdownEditLabel?: string,
ariaLabel?: string,
persistThumbnailUrl?: boolean,
}>();

defineOptions({
Expand Down Expand Up @@ -131,6 +132,10 @@
});
await onImageTransform(cropper);
cropper.destroy();
} else if(props.persistThumbnailUrl) {
const response = await fetch(preview);
const blob = await response.blob();
transformedImg.value = URL.createObjectURL(blob);
}
})
.on('upload', () => {
Expand Down Expand Up @@ -381,6 +386,9 @@

onUnmounted(() => {
uppy.destroy();
if(!props.persistThumbnailUrl && transformedImg.value) {
URL.revokeObjectURL(transformedImg.value);
}
emit('uploading', false);
});
</script>
Expand Down Expand Up @@ -482,6 +490,7 @@
{{ props.dropdownEditLabel ?? __('sharp::form.upload.edit_button') }}
</DropdownMenuItem>
</template>
<slot name="dropdown-menu"></slot>
<DropdownMenuSeparator class="first:hidden" />
<DropdownMenuItem class="text-destructive" @click="onRemove">
{{ __('sharp::form.upload.remove_button') }}
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
return [
'file_not_found' => 'This file can not be found.',
'419.status_displayed_in_login_page' => 'Your session has expired. Please login again.',
'failed_to_write_to_clipboard' => 'Failed to write to clipboard. Please check your browser settings.',
];
1 change: 1 addition & 0 deletions resources/lang/en/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'editor.extension_node.dropdown_button.aria_label' => 'Actions',
'editor.extension_node.edit_button' => 'Edit...',
'editor.extension_node.remove_button' => 'Remove',
'editor.extension_node.copy_button' => 'Copy',
'editor.extension_node.upload.aria_label' => 'Embedded file',
'editor.extension_node.upload_image.aria_label' => 'Embedded image',

Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
return [
'file_not_found' => 'Ce fichier est introuvable.',
'419.status_displayed_in_login_page' => 'Votre session a expirée. Veuillez vous reconnecter.',
'failed_to_write_to_clipboard' => 'Erreur lord de l’écriture dans le presse-papiers. Veuillez vérifier les paramètres de votre navigateur.',
];
1 change: 1 addition & 0 deletions resources/lang/fr/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'editor.extension_node.dropdown_button.aria_label' => 'Actions',
'editor.extension_node.edit_button' => 'Modifier...',
'editor.extension_node.remove_button' => 'Supprimer',
'editor.extension_node.copy_button' => 'Copier',
'editor.extension_node.upload.aria_label' => 'Fichier intégré',
'editor.extension_node.upload_image.aria_label' => 'Image intégré',

Expand Down
1 change: 1 addition & 0 deletions src/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function share(Request $request)
'sharp::form',
'sharp::menu',
'sharp::modals',
'sharp::errors',
'sharp::pages/auth/forgot-password',
'sharp::pages/auth/login',
'sharp::pages/auth/impersonate',
Expand Down
Loading