File tree 5 files changed +31
-9
lines changed
components/contents/details
5 files changed +31
-9
lines changed Original file line number Diff line number Diff line change 19
19
/**
20
20
* @import { Component } from 'svelte';
21
21
* @import { Writable } from 'svelte/store';
22
- * @import { InternalLocaleCode } from '$lib/types/private';
22
+ * @import { InternalLocaleCode, WidgetContext } from '$lib/types/private';
23
23
* @import {
24
24
* BooleanField,
25
25
* Field,
38
38
* @property {InternalLocaleCode} locale Current pane’s locale.
39
39
* @property {FieldKeyPath} keyPath Field key path.
40
40
* @property {Field} fieldConfig Field configuration.
41
+ * @property {WidgetContext} [context] Where the widget is rendered.
41
42
*/
42
43
43
44
/** @type {Props} */
46
47
locale,
47
48
keyPath,
48
49
fieldConfig,
50
+ context = undefined ,
49
51
/* eslint-enable prefer-const */
50
52
} = $props ();
51
53
267
269
{readonly}
268
270
{required}
269
271
{invalid}
272
+ {context}
270
273
/ >
271
274
{: else }
272
275
{#if beforeInputLabel}
286
289
{readonly}
287
290
{required}
288
291
{invalid}
292
+ {context}
289
293
/ >
290
294
{#if suffix}
291
295
< div role= " none" class = " suffix" > {suffix}< / div>
Original file line number Diff line number Diff line change 51
51
required = true ,
52
52
readonly = false ,
53
53
invalid = false ,
54
- inEditorComponent = false ,
54
+ context = undefined ,
55
55
/* eslint-enable prefer-const */
56
56
} = $props ();
57
57
85
85
const { maxFileSize , fileTransformations } = $derived (getMediaLibraryConfig ({ fieldConfig }));
86
86
const collection = $derived ($entryDraft? .collection );
87
87
const entry = $derived ($entryDraft? .originalEntry );
88
+ const showRemoveButton = $derived (
89
+ ! required &&
90
+ (! context || ! [' markdown-editor-component' , ' single-field-list-widget' ].includes (context)),
91
+ );
88
92
89
93
/**
90
94
* Reset the current selection.
245
249
showSelectAssetsDialog = true ;
246
250
}}
247
251
/ >
248
- {#if ! inEditorComponent }
252
+ {#if showRemoveButton }
249
253
< Button
250
254
disabled= {readonly}
251
255
variant= " tertiary"
Original file line number Diff line number Diff line change 6
6
<script >
7
7
import {
8
8
Button ,
9
- Divider ,
10
9
Group ,
11
10
Icon ,
12
11
Menu ,
436
435
onclick= {() => addItem ({ index: index + 1 })}
437
436
/ >
438
437
{/ if }
439
- < Divider / >
440
- < MenuItem label= {$_ (' remove' )} onclick= {() => removeItem (index)} / >
441
438
< / Menu>
442
439
{/ snippet}
443
440
< / 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>
444
452
{/ snippet}
445
453
< / ObjectHeader>
446
454
< div role= " none" class = " item-body" id= " list-{widgetId}-item-{index}-body" >
453
461
: ` ${ keyPath} .${ index} .${ subField .name } ` }
454
462
{locale}
455
463
fieldConfig= {subField}
464
+ context= {hasSingleSubField ? ' single-field-list-widget' : undefined }
456
465
/ >
457
466
{/ await }
458
467
{/ each}
Original file line number Diff line number Diff line change 141
141
fieldId= {generateElementId (' field' )}
142
142
fieldLabel= {fieldLabel ?? name}
143
143
fieldConfig= {{ name, widget }}
144
- inEditorComponent = { true }
144
+ context = " markdown-editor-component "
145
145
bind: currentValue= {inputValues[name]}
146
146
{... rest}
147
147
/ >
Original file line number Diff line number Diff line change 678
678
* @property {FileFormatter } [formatter] Formatter method.
679
679
*/
680
680
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
+
681
686
/**
682
687
* Common properties to be passed to a field widget’s editor component.
683
688
* @typedef {object } WidgetEditorProps
688
693
* @property {boolean } [required] Whether to mark the field required.
689
694
* @property {boolean } [readonly] Whether to mark the field read-only.
690
695
* @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.
693
697
*/
694
698
695
699
/**
696
700
* Common properties to be passed to a field widget’s preview component.
697
701
* @typedef {object } WidgetPreviewProps
698
702
* @property {InternalLocaleCode } locale Current pane’s locale.
699
703
* @property {FieldKeyPath } keyPath Field key path.
704
+ * @property {WidgetContext } [context] Where the widget is rendered.
700
705
*/
701
706
702
707
/**
You can’t perform that action at this time.
0 commit comments