Skip to content

Commit 985c729

Browse files
committed
Refactor field type definitions to improve clarity
Fix #597
1 parent ec91b59 commit 985c729

1 file changed

Lines changed: 41 additions & 43 deletions

File tree

src/lib/types/public.js

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,22 @@
198198
* Common field properties that are shared among all field types.
199199
* @typedef {object} CommonFieldProps
200200
* @property {string} name Unique identifier for the field. It cannot include periods and spaces.
201+
* @property {boolean | 'duplicate' | 'translate' | 'none'} [i18n] Whether to enable the editor UI
202+
* in locales other than the default locale. Default: `false`. `duplicate` disables the UI in
203+
* non-default like `false` but automatically copies the default locale’s value to other locales.
204+
* `translate` and `none` are aliases of `true` and `false`, respectively. This option only works
205+
* when i18n is set up with the global and collection-level `i18n` option.
201206
*/
202207

203208
/**
204209
* Standard field properties for a built-in field type.
205-
* @typedef {object} StandardFieldProps
210+
* @typedef {object} VisibleFieldProps
206211
* @property {string} [label] Label of the field to be displayed in the editor UI. Default: `name`
207212
* field value.
208213
* @property {string} [comment] Short description of the field to be displayed in the editor UI.
209214
* @property {string} [hint] Help message to be displayed below the input UI. Limited Markdown
210215
* formatting is supported: bold, italic, strikethrough and links.
211216
* @property {boolean} [preview] Whether to show the preview of the field. Default: `true`.
212-
* @property {boolean | 'duplicate' | 'translate' | 'none'} [i18n] Whether to enable the editor UI
213-
* in locales other than the default locale. Default: `false`. `duplicate` disables the UI in
214-
* non-default like `false` but automatically copies the default locale’s value to other locales.
215-
* `translate` and `none` are aliases of `true` and `false`, respectively. This option only works
216-
* when i18n is set up with the global and collection-level `i18n` option.
217217
* @property {boolean | LocaleCode[]} [required] Whether to make data input on the field required.
218218
* Default: `true`. This option also affects data output if the `omit_empty_optional_fields` global
219219
* output option is `true`. If i18n is enabled and the field doesn’t require input in all locales,
@@ -225,11 +225,6 @@
225225
* @see https://sveltiacms.app/en/docs/fields
226226
*/
227227

228-
/**
229-
* Properties for a field that is visible in the editor UI.
230-
* @typedef {CommonFieldProps & StandardFieldProps} VisibleFieldProps
231-
*/
232-
233228
/**
234229
* Field validation properties.
235230
* @typedef {object} FieldValidationProps
@@ -349,7 +344,8 @@
349344

350345
/**
351346
* Boolean field definition.
352-
* @typedef {VisibleFieldProps & BooleanFieldProps & AdjacentLabelProps} BooleanField
347+
* @typedef {CommonFieldProps & VisibleFieldProps & BooleanFieldProps &
348+
* AdjacentLabelProps} BooleanField
353349
*/
354350

355351
/**
@@ -372,7 +368,7 @@
372368

373369
/**
374370
* Code field definition.
375-
* @typedef {VisibleFieldProps & FieldValidationProps & CodeFieldProps} CodeField
371+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & CodeFieldProps} CodeField
376372
*/
377373

378374
/**
@@ -390,7 +386,8 @@
390386

391387
/**
392388
* Color field definition.
393-
* @typedef {VisibleFieldProps & FieldValidationProps & ColorFieldProps} ColorField
389+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps &
390+
* ColorFieldProps} ColorField
394391
*/
395392

396393
/**
@@ -403,7 +400,7 @@
403400

404401
/**
405402
* Compute field definition.
406-
* @typedef {VisibleFieldProps & ComputeFieldProps} ComputeField
403+
* @typedef {CommonFieldProps & VisibleFieldProps & ComputeFieldProps} ComputeField
407404
*/
408405

409406
/**
@@ -429,7 +426,8 @@
429426

430427
/**
431428
* DateTime field definition.
432-
* @typedef {VisibleFieldProps & FieldValidationProps & DateTimeFieldProps} DateTimeField
429+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps &
430+
* DateTimeFieldProps} DateTimeField
433431
*/
434432

435433
/**
@@ -442,7 +440,8 @@
442440

443441
/**
444442
* File field definition.
445-
* @typedef {VisibleFieldProps & FieldValidationProps & MediaFieldProps & FileFieldProps } FileField
443+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & MediaFieldProps &
444+
* FileFieldProps} FileField
446445
*/
447446

448447
/**
@@ -451,11 +450,6 @@
451450
* @property {'hidden'} widget Field type.
452451
* @property {any} [default] Default value. Accepts any data type that can be stored with the
453452
* configured file format.
454-
* @property {false | 'duplicate' | 'none'} [i18n] Whether to enable the field in locales other than
455-
* the default. Unlike other visible fields, hidden fields can be configured to be enabled in
456-
* non-default locales only when set to `duplicate`. In that case, the default locale’s value is
457-
* automatically copied to other locales. Default: `false`. This option only works when i18n is set
458-
* up with the global and collection-level `i18n` option.
459453
* @see https://decapcms.org/docs/widgets/#Hidden
460454
* @see https://sveltiacms.app/en/docs/fields/hidden
461455
*/
@@ -475,8 +469,8 @@
475469

476470
/**
477471
* Image field definition.
478-
* @typedef {VisibleFieldProps & FieldValidationProps & MediaFieldProps & ImageFieldProps
479-
* } ImageField
472+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & MediaFieldProps &
473+
* ImageFieldProps} ImageField
480474
*/
481475

482476
/**
@@ -492,7 +486,8 @@
492486

493487
/**
494488
* KeyValue field definition.
495-
* @typedef {VisibleFieldProps & KeyValueFieldProps & MultiValueFieldProps} KeyValueField
489+
* @typedef {CommonFieldProps & VisibleFieldProps & KeyValueFieldProps &
490+
* MultiValueFieldProps} KeyValueField
496491
*/
497492

498493
/**
@@ -508,7 +503,8 @@
508503

509504
/**
510505
* Base properties for a List field.
511-
* @typedef {VisibleFieldProps & ListFieldProps & MultiValueFieldProps} ListFieldBaseProps
506+
* @typedef {CommonFieldProps & VisibleFieldProps & ListFieldProps &
507+
* MultiValueFieldProps} ListFieldBaseProps
512508
*/
513509

514510
/**
@@ -606,7 +602,7 @@
606602

607603
/**
608604
* Map field definition.
609-
* @typedef {VisibleFieldProps & FieldValidationProps & MapFieldProps} MapField
605+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & MapFieldProps} MapField
610606
*/
611607

612608
/**
@@ -666,8 +662,8 @@
666662

667663
/**
668664
* RichText field definition.
669-
* @typedef {VisibleFieldProps & FieldValidationProps & RichTextFieldBaseProps & RichTextFieldProps
670-
* } RichTextField
665+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & RichTextFieldBaseProps &
666+
* RichTextFieldProps} RichTextField
671667
*/
672668

673669
/**
@@ -678,8 +674,8 @@
678674

679675
/**
680676
* Markdown field definition.
681-
* @typedef {VisibleFieldProps & FieldValidationProps & RichTextFieldBaseProps & MarkdownFieldProps
682-
* } MarkdownField
677+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & RichTextFieldBaseProps &
678+
* MarkdownFieldProps} MarkdownField
683679
*/
684680

685681
/**
@@ -701,8 +697,8 @@
701697

702698
/**
703699
* Number field definition.
704-
* @typedef {VisibleFieldProps & FieldValidationProps & NumberFieldProps & AdjacentLabelProps
705-
* } NumberField
700+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & NumberFieldProps &
701+
* AdjacentLabelProps} NumberField
706702
*/
707703

708704
/**
@@ -720,7 +716,7 @@
720716

721717
/**
722718
* Base properties for a complex Object field with subfields or variable types.
723-
* @typedef {VisibleFieldProps & ObjectFieldProps} ComplexObjectFieldProps
719+
* @typedef {CommonFieldProps & VisibleFieldProps & ObjectFieldProps} ComplexObjectFieldProps
724720
*/
725721

726722
/**
@@ -776,8 +772,8 @@
776772

777773
/**
778774
* Relation field definition.
779-
* @typedef {VisibleFieldProps & FieldValidationProps & RelationFieldProps & MultiOptionFieldProps
780-
* } RelationField
775+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & RelationFieldProps &
776+
* MultiOptionFieldProps} RelationField
781777
*/
782778

783779
/**
@@ -798,8 +794,8 @@
798794

799795
/**
800796
* Select field definition.
801-
* @typedef {VisibleFieldProps & FieldValidationProps & SelectFieldProps & MultiOptionFieldProps
802-
* } SelectField
797+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & SelectFieldProps &
798+
* MultiOptionFieldProps} SelectField
803799
*/
804800

805801
/**
@@ -817,8 +813,8 @@
817813

818814
/**
819815
* String field definition.
820-
* @typedef {VisibleFieldProps & FieldValidationProps & StringFieldProps & AdjacentLabelProps &
821-
* CharCountProps} StringField
816+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & StringFieldProps &
817+
* AdjacentLabelProps & CharCountProps} StringField
822818
*/
823819

824820
/**
@@ -832,7 +828,8 @@
832828

833829
/**
834830
* Text field definition.
835-
* @typedef {VisibleFieldProps & FieldValidationProps & TextFieldProps & CharCountProps } TextField
831+
* @typedef {CommonFieldProps & VisibleFieldProps & FieldValidationProps & TextFieldProps &
832+
* CharCountProps} TextField
836833
*/
837834

838835
/**
@@ -850,7 +847,7 @@
850847

851848
/**
852849
* UUID field definition.
853-
* @typedef {VisibleFieldProps & UuidFieldProps} UuidField
850+
* @typedef {CommonFieldProps & VisibleFieldProps & UuidFieldProps} UuidField
854851
*/
855852

856853
/**
@@ -912,7 +909,8 @@
912909

913910
/**
914911
* Entry field using a custom field type.
915-
* @typedef {CommonFieldProps & CustomFieldProps & Record<string, any>} CustomField
912+
* @typedef {CommonFieldProps & VisibleFieldProps & CustomFieldProps &
913+
* Record<string, any>} CustomField
916914
*/
917915

918916
/**

0 commit comments

Comments
 (0)