Skip to content

Commit af21a1e

Browse files
committed
Don't show embed in dropdown if, closes code16/sharp-dev#404
1 parent 78bc37b commit af21a1e

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { __ } from "@/utils/i18n";
33
import { FormEditorFieldData } from "@/types";
4-
import { provide, ref, watch } from "vue";
4+
import { computed, provide, ref, watch } from "vue";
55
import { Editor, BubbleMenu, isActive } from "@tiptap/vue-3";
66
import debounce from 'lodash/debounce';
77
import { EditorContent } from '@tiptap/vue-3';
@@ -150,6 +150,11 @@
150150
return editor;
151151
}
152152
);
153+
154+
const dropdownEmbeds = computed(() =>
155+
Object.values(props.field.embeds ?? {})
156+
.filter(embed => !props.field.toolbar?.includes(`embed:${embed.key}`))
157+
);
153158
</script>
154159

155160
<template>
@@ -198,15 +203,15 @@
198203
</Toggle>
199204
</template>
200205
</template>
201-
<template v-if="Object.values(props.field.embeds ?? {}).length > 0">
206+
<template v-if="dropdownEmbeds.length > 0">
202207
<DropdownMenu :modal="false">
203208
<DropdownMenuTrigger as-child>
204209
<Button class="px-3" variant="ghost" size="sm" :disabled="props.field.readOnly">
205210
{{ __('sharp::form.editor.dropdown.embeds') }}
206211
</Button>
207212
</DropdownMenuTrigger>
208213
<DropdownMenuContent>
209-
<template v-for="embed in props.field.embeds">
214+
<template v-for="embed in dropdownEmbeds">
210215
<DropdownMenuItem @click="embedModal.open({ embed })">
211216
{{ embed.label }}
212217
</DropdownMenuItem>

resources/js/types/generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export type FormEditorFieldData = {
368368
showCharacterCount: boolean;
369369
uploads: FormEditorFieldUploadData | null;
370370
embeds: { [embedKey: string]: EmbedData };
371-
toolbar: Array<FormEditorToolbarButton>;
371+
toolbar: Array<FormEditorToolbarButton | `embed:${string}`>;
372372
maxHeight: number | null;
373373
maxLength: number | null;
374374
placeholder: string | null;

src/Data/Form/Fields/FormEditorFieldData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
public ?array $uploads = null,
3636
#[LiteralTypeScriptType('{ [embedKey:string]:EmbedData }')]
3737
public ?array $embeds = null,
38-
#[LiteralTypeScriptType('Array<FormEditorToolbarButton>')]
38+
#[LiteralTypeScriptType('Array<FormEditorToolbarButton | `embed:${string}`>')]
3939
public ?array $toolbar = null,
4040
public ?int $maxHeight = null,
4141
public ?int $maxLength = null,

0 commit comments

Comments
 (0)