Skip to content

Commit c1b3f7b

Browse files
committed
Hide image widget’s remove button in some cases
Fix #372
1 parent 1327a87 commit c1b3f7b

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

Diff for: src/lib/components/contents/details/editor/field-editor.svelte

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @import { Component } from 'svelte';
2121
* @import { Writable } from 'svelte/store';
22-
* @import { InternalLocaleCode } from '$lib/types/private';
22+
* @import { InternalLocaleCode, WidgetContext } from '$lib/types/private';
2323
* @import {
2424
* BooleanField,
2525
* Field,
@@ -38,6 +38,7 @@
3838
* @property {InternalLocaleCode} locale Current pane’s locale.
3939
* @property {FieldKeyPath} keyPath Field key path.
4040
* @property {Field} fieldConfig Field configuration.
41+
* @property {WidgetContext} [context] Where the widget is rendered.
4142
*/
4243
4344
/** @type {Props} */
@@ -46,6 +47,7 @@
4647
locale,
4748
keyPath,
4849
fieldConfig,
50+
context = undefined,
4951
/* eslint-enable prefer-const */
5052
} = $props();
5153
@@ -267,6 +269,7 @@
267269
{readonly}
268270
{required}
269271
{invalid}
272+
{context}
270273
/>
271274
{:else}
272275
{#if beforeInputLabel}
@@ -286,6 +289,7 @@
286289
{readonly}
287290
{required}
288291
{invalid}
292+
{context}
289293
/>
290294
{#if suffix}
291295
<div role="none" class="suffix">{suffix}</div>

Diff for: src/lib/components/contents/details/widgets/file/file-editor.svelte

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
required = true,
5252
readonly = false,
5353
invalid = false,
54-
inEditorComponent = false,
54+
context = undefined,
5555
/* eslint-enable prefer-const */
5656
} = $props();
5757
@@ -85,6 +85,10 @@
8585
const { maxFileSize, fileTransformations } = $derived(getMediaLibraryConfig({ fieldConfig }));
8686
const collection = $derived($entryDraft?.collection);
8787
const entry = $derived($entryDraft?.originalEntry);
88+
const showRemoveButton = $derived(
89+
!required &&
90+
(!context || !['markdown-editor-component', 'single-field-list-widget'].includes(context)),
91+
);
8892
8993
/**
9094
* Reset the current selection.
@@ -245,7 +249,7 @@
245249
showSelectAssetsDialog = true;
246250
}}
247251
/>
248-
{#if !inEditorComponent}
252+
{#if showRemoveButton}
249253
<Button
250254
disabled={readonly}
251255
variant="tertiary"

Diff for: src/lib/components/contents/details/widgets/list/list-editor.svelte

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<script>
77
import {
88
Button,
9-
Divider,
109
Group,
1110
Icon,
1211
Menu,
@@ -436,11 +435,20 @@
436435
onclick={() => addItem({ index: index + 1 })}
437436
/>
438437
{/if}
439-
<Divider />
440-
<MenuItem label={$_('remove')} onclick={() => removeItem(index)} />
441438
</Menu>
442439
{/snippet}
443440
</MenuButton>
441+
<Button
442+
variant="ghost"
443+
size="small"
444+
iconic
445+
aria-label={$_('remove')}
446+
onclick={() => removeItem(index)}
447+
>
448+
{#snippet startIcon()}
449+
<Icon name="close" />
450+
{/snippet}
451+
</Button>
444452
{/snippet}
445453
</ObjectHeader>
446454
<div role="none" class="item-body" id="list-{widgetId}-item-{index}-body">
@@ -453,6 +461,7 @@
453461
: `${keyPath}.${index}.${subField.name}`}
454462
{locale}
455463
fieldConfig={subField}
464+
context={hasSingleSubField ? 'single-field-list-widget' : undefined}
456465
/>
457466
{/await}
458467
{/each}

Diff for: src/lib/components/contents/details/widgets/markdown/component.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
fieldId={generateElementId('field')}
142142
fieldLabel={fieldLabel ?? name}
143143
fieldConfig={{ name, widget }}
144-
inEditorComponent={true}
144+
context="markdown-editor-component"
145145
bind:currentValue={inputValues[name]}
146146
{...rest}
147147
/>

Diff for: src/lib/types/private.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@
678678
* @property {FileFormatter} [formatter] Formatter method.
679679
*/
680680

681+
/**
682+
* Context for a widget, which may change the behavior of the editor/preview.
683+
* @typedef {'markdown-editor-component' | 'single-field-list-widget'} WidgetContext
684+
*/
685+
681686
/**
682687
* Common properties to be passed to a field widget’s editor component.
683688
* @typedef {object} WidgetEditorProps
@@ -688,15 +693,15 @@
688693
* @property {boolean} [required] Whether to mark the field required.
689694
* @property {boolean} [readonly] Whether to mark the field read-only.
690695
* @property {boolean} [invalid] Whether to mark the field invalid.
691-
* @property {boolean} [inEditorComponent] Whether the widget is used in the Markdown widget’s
692-
* editor component.
696+
* @property {WidgetContext} [context] Where the widget is rendered.
693697
*/
694698

695699
/**
696700
* Common properties to be passed to a field widget’s preview component.
697701
* @typedef {object} WidgetPreviewProps
698702
* @property {InternalLocaleCode} locale Current pane’s locale.
699703
* @property {FieldKeyPath} keyPath Field key path.
704+
* @property {WidgetContext} [context] Where the widget is rendered.
700705
*/
701706

702707
/**

0 commit comments

Comments
 (0)