@webiny/api-headless-cms 6.0.0-rc.2 → 6.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/crud/contentEntry/searchableFields.js +6 -2
  2. package/crud/contentEntry/searchableFields.js.map +1 -1
  3. package/crud/contentModel/validation.d.ts +9 -9
  4. package/crud/contentModel/validation.js +3 -3
  5. package/crud/contentModel/validation.js.map +1 -1
  6. package/domain/contentModel/errors.d.ts +1 -1
  7. package/domain/contentModel/errors.js.map +1 -1
  8. package/domain/contentModel/schemas.d.ts +126 -8
  9. package/domain/contentModel/schemas.js +12 -13
  10. package/domain/contentModel/schemas.js.map +1 -1
  11. package/export/graphql/index.js +1 -1
  12. package/export/graphql/index.js.map +1 -1
  13. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesUseCase.d.ts +2 -2
  14. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesUseCase.js +3 -4
  15. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesUseCase.js.map +1 -1
  16. package/features/contentModel/CreateModel/CreateModelRepository.js +4 -1
  17. package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
  18. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +12 -3
  19. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
  20. package/features/contentModel/UpdateModel/UpdateModelRepository.js +8 -2
  21. package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
  22. package/features/contentModel/UpdateModel/UpdateModelUseCase.js +4 -1
  23. package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
  24. package/features/modelBuilder/feature.js +2 -2
  25. package/features/modelBuilder/feature.js.map +1 -1
  26. package/features/modelBuilder/fields/BaseFieldBuilder.d.ts +36 -0
  27. package/features/modelBuilder/fields/BaseFieldBuilder.js +41 -0
  28. package/features/modelBuilder/fields/BaseFieldBuilder.js.map +1 -0
  29. package/features/modelBuilder/fields/DataFieldBuilder.d.ts +228 -0
  30. package/features/modelBuilder/fields/DataFieldBuilder.js +219 -0
  31. package/features/modelBuilder/fields/DataFieldBuilder.js.map +1 -0
  32. package/features/modelBuilder/fields/DynamicZoneFieldType.d.ts +2 -2
  33. package/features/modelBuilder/fields/DynamicZoneFieldType.js +6 -3
  34. package/features/modelBuilder/fields/DynamicZoneFieldType.js.map +1 -1
  35. package/features/modelBuilder/fields/FieldBuilder.d.ts +5 -228
  36. package/features/modelBuilder/fields/FieldBuilder.js +3 -231
  37. package/features/modelBuilder/fields/FieldBuilder.js.map +1 -1
  38. package/features/modelBuilder/fields/LayoutFieldBuilder.d.ts +7 -0
  39. package/features/modelBuilder/fields/LayoutFieldBuilder.js +9 -0
  40. package/features/modelBuilder/fields/LayoutFieldBuilder.js.map +1 -0
  41. package/features/modelBuilder/fields/ObjectFieldType.d.ts +4 -3
  42. package/features/modelBuilder/fields/ObjectFieldType.js +19 -4
  43. package/features/modelBuilder/fields/ObjectFieldType.js.map +1 -1
  44. package/features/modelBuilder/fields/UiAlertFieldType.d.ts +8 -4
  45. package/features/modelBuilder/fields/UiAlertFieldType.js +23 -6
  46. package/features/modelBuilder/fields/UiAlertFieldType.js.map +1 -1
  47. package/features/modelBuilder/fields/UiSeparatorFieldType.d.ts +6 -4
  48. package/features/modelBuilder/fields/UiSeparatorFieldType.js +18 -4
  49. package/features/modelBuilder/fields/UiSeparatorFieldType.js.map +1 -1
  50. package/features/modelBuilder/fields/UiTabsFieldType.d.ts +28 -0
  51. package/features/modelBuilder/fields/UiTabsFieldType.js +75 -0
  52. package/features/modelBuilder/fields/UiTabsFieldType.js.map +1 -0
  53. package/features/modelBuilder/fields/abstractions.d.ts +2 -2
  54. package/features/modelBuilder/fields/abstractions.js.map +1 -1
  55. package/features/modelBuilder/index.d.ts +2 -0
  56. package/features/modelBuilder/index.js +2 -0
  57. package/features/modelBuilder/index.js.map +1 -1
  58. package/features/modelBuilder/models/BaseModelBuilder.d.ts +8 -3
  59. package/features/modelBuilder/models/BaseModelBuilder.js +19 -0
  60. package/features/modelBuilder/models/BaseModelBuilder.js.map +1 -1
  61. package/features/modelBuilder/models/PrivateModelBuilder.js +4 -2
  62. package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
  63. package/features/modelBuilder/models/PublicModelBuilder.js +16 -11
  64. package/features/modelBuilder/models/PublicModelBuilder.js.map +1 -1
  65. package/graphql/schema/cms/helpers/index.d.ts +1 -0
  66. package/graphql/schema/cms/helpers/index.js +1 -0
  67. package/graphql/schema/cms/helpers/index.js.map +1 -1
  68. package/graphql/schema/cms/helpers/transformWhereToNested.d.ts +17 -0
  69. package/graphql/schema/cms/helpers/transformWhereToNested.js +54 -0
  70. package/graphql/schema/cms/helpers/transformWhereToNested.js.map +1 -0
  71. package/graphql/schema/cms/helpers.d.ts +1 -0
  72. package/graphql/schema/cms/helpers.js +1 -0
  73. package/graphql/schema/cms/helpers.js.map +1 -1
  74. package/graphql/schema/cms/listEntriesResolver.js +6 -2
  75. package/graphql/schema/cms/listEntriesResolver.js.map +1 -1
  76. package/graphql/schema/contentModels.js +21 -3
  77. package/graphql/schema/contentModels.js.map +1 -1
  78. package/graphqlFields/index.js +1 -2
  79. package/graphqlFields/index.js.map +1 -1
  80. package/package.json +20 -20
  81. package/plugins/CmsModelPlugin.js +19 -4
  82. package/plugins/CmsModelPlugin.js.map +1 -1
  83. package/types/fields/objectField.d.ts +2 -0
  84. package/types/fields/objectField.js.map +1 -1
  85. package/types/model.d.ts +32 -3
  86. package/types/model.js.map +1 -1
  87. package/types/modelField.d.ts +19 -3
  88. package/types/modelField.js.map +1 -1
  89. package/utils/createModelField.js +4 -2
  90. package/utils/createModelField.js.map +1 -1
  91. package/features/modelBuilder/fields/UiFieldType.d.ts +0 -18
  92. package/features/modelBuilder/fields/UiFieldType.js +0 -25
  93. package/features/modelBuilder/fields/UiFieldType.js.map +0 -1
  94. package/graphqlFields/ui.d.ts +0 -2
  95. package/graphqlFields/ui.js +0 -32
  96. package/graphqlFields/ui.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ import type { CmsModelField, CmsModelLayoutCell } from "../../../types/index.js";
2
+ export interface DataFieldBuildResult {
3
+ type: "data";
4
+ field: CmsModelField;
5
+ }
6
+ export interface LayoutFieldBuildResult {
7
+ type: "layout";
8
+ layoutCell: CmsModelLayoutCell;
9
+ fields?: CmsModelField[];
10
+ }
11
+ export type FieldBuildResult = DataFieldBuildResult | LayoutFieldBuildResult;
12
+ export interface BaseFieldBuilderConfig {
13
+ label: string;
14
+ help?: string | null;
15
+ description?: string | null;
16
+ note?: string | null;
17
+ _fieldId?: string;
18
+ }
19
+ /**
20
+ * Minimal shared base class for all field builders (data and layout).
21
+ */
22
+ export declare abstract class BaseFieldBuilder<TType extends string = string> {
23
+ readonly type: TType;
24
+ protected config: BaseFieldBuilderConfig;
25
+ constructor(type: TType, label?: string);
26
+ label(text: string): this;
27
+ help(text: string): this;
28
+ description(text: string): this;
29
+ note(text: string): this;
30
+ fieldId(id: string): this;
31
+ /**
32
+ * Build the final field result.
33
+ * @internal
34
+ */
35
+ abstract build(): FieldBuildResult;
36
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Minimal shared base class for all field builders (data and layout).
3
+ */
4
+ export class BaseFieldBuilder {
5
+ constructor(type, label) {
6
+ this.type = type;
7
+ this.config = {
8
+ label: label || "",
9
+ help: null,
10
+ description: null,
11
+ note: null
12
+ };
13
+ }
14
+ label(text) {
15
+ this.config.label = text;
16
+ return this;
17
+ }
18
+ help(text) {
19
+ this.config.help = text;
20
+ return this;
21
+ }
22
+ description(text) {
23
+ this.config.description = text;
24
+ return this;
25
+ }
26
+ note(text) {
27
+ this.config.note = text;
28
+ return this;
29
+ }
30
+ fieldId(id) {
31
+ this.config._fieldId = id;
32
+ return this;
33
+ }
34
+
35
+ /**
36
+ * Build the final field result.
37
+ * @internal
38
+ */
39
+ }
40
+
41
+ //# sourceMappingURL=BaseFieldBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BaseFieldBuilder","constructor","type","label","config","help","description","note","text","fieldId","id","_fieldId"],"sources":["BaseFieldBuilder.ts"],"sourcesContent":["import type { CmsModelField, CmsModelLayoutCell } from \"~/types/index.js\";\n\nexport interface DataFieldBuildResult {\n type: \"data\";\n field: CmsModelField;\n}\n\nexport interface LayoutFieldBuildResult {\n type: \"layout\";\n layoutCell: CmsModelLayoutCell;\n fields?: CmsModelField[];\n}\n\nexport type FieldBuildResult = DataFieldBuildResult | LayoutFieldBuildResult;\n\nexport interface BaseFieldBuilderConfig {\n label: string;\n help?: string | null;\n description?: string | null;\n note?: string | null;\n _fieldId?: string;\n}\n\n/**\n * Minimal shared base class for all field builders (data and layout).\n */\nexport abstract class BaseFieldBuilder<TType extends string = string> {\n public readonly type: TType;\n protected config: BaseFieldBuilderConfig;\n\n public constructor(type: TType, label?: string) {\n this.type = type;\n this.config = {\n label: label || \"\",\n help: null,\n description: null,\n note: null\n };\n }\n\n label(text: string): this {\n this.config.label = text;\n return this;\n }\n\n help(text: string): this {\n this.config.help = text;\n return this;\n }\n\n description(text: string): this {\n this.config.description = text;\n return this;\n }\n\n note(text: string): this {\n this.config.note = text;\n return this;\n }\n\n fieldId(id: string): this {\n this.config._fieldId = id;\n return this;\n }\n\n /**\n * Build the final field result.\n * @internal\n */\n abstract build(): FieldBuildResult;\n}\n"],"mappings":"AAuBA;AACA;AACA;AACA,OAAO,MAAeA,gBAAgB,CAAgC;EAI3DC,WAAWA,CAACC,IAAW,EAAEC,KAAc,EAAE;IAC5C,IAAI,CAACD,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACE,MAAM,GAAG;MACVD,KAAK,EAAEA,KAAK,IAAI,EAAE;MAClBE,IAAI,EAAE,IAAI;MACVC,WAAW,EAAE,IAAI;MACjBC,IAAI,EAAE;IACV,CAAC;EACL;EAEAJ,KAAKA,CAACK,IAAY,EAAQ;IACtB,IAAI,CAACJ,MAAM,CAACD,KAAK,GAAGK,IAAI;IACxB,OAAO,IAAI;EACf;EAEAH,IAAIA,CAACG,IAAY,EAAQ;IACrB,IAAI,CAACJ,MAAM,CAACC,IAAI,GAAGG,IAAI;IACvB,OAAO,IAAI;EACf;EAEAF,WAAWA,CAACE,IAAY,EAAQ;IAC5B,IAAI,CAACJ,MAAM,CAACE,WAAW,GAAGE,IAAI;IAC9B,OAAO,IAAI;EACf;EAEAD,IAAIA,CAACC,IAAY,EAAQ;IACrB,IAAI,CAACJ,MAAM,CAACG,IAAI,GAAGC,IAAI;IACvB,OAAO,IAAI;EACf;EAEAC,OAAOA,CAACC,EAAU,EAAQ;IACtB,IAAI,CAACN,MAAM,CAACO,QAAQ,GAAGD,EAAE;IACzB,OAAO,IAAI;EACf;;EAEA;AACJ;AACA;AACA;AAEA","ignoreList":[]}
@@ -0,0 +1,228 @@
1
+ import type { CmsModelField, CmsModelFieldPredefinedValues, CmsModelFieldValidation } from "../../../types/index.js";
2
+ import { BaseFieldBuilder, type DataFieldBuildResult } from "./BaseFieldBuilder.js";
3
+ export interface FieldBuilderConfig extends Omit<CmsModelField, "id" | "fieldId" | "storageId" | "type"> {
4
+ _storageId?: string;
5
+ _fieldId?: string;
6
+ description?: string | null;
7
+ note?: string | null;
8
+ }
9
+ /**
10
+ * Augmentable renderer registry.
11
+ * Each entry maps a renderer name to its applicable field type(s) and settings.
12
+ *
13
+ * Example:
14
+ * declare module "@webiny/api-headless-cms/features/modelBuilder/fields/FieldBuilder" {
15
+ * interface FieldRendererRegistry {
16
+ * "my-renderer": { fieldType: "text" | "long-text"; settings: { color: string } };
17
+ * }
18
+ * }
19
+ */
20
+ export interface FieldRendererRegistry {
21
+ switch: {
22
+ fieldType: "boolean";
23
+ settings: undefined;
24
+ };
25
+ checkboxes: {
26
+ fieldType: "text" | "number";
27
+ settings: undefined;
28
+ };
29
+ dateTimeInput: {
30
+ fieldType: "datetime";
31
+ settings: undefined;
32
+ };
33
+ dateTimeInputs: {
34
+ fieldType: "datetime";
35
+ settings?: {
36
+ multiValue?: {
37
+ addValueButtonLabel?: string;
38
+ };
39
+ };
40
+ };
41
+ dynamicZone: {
42
+ fieldType: "dynamicZone";
43
+ settings?: {
44
+ open?: boolean;
45
+ };
46
+ };
47
+ hidden: {
48
+ fieldType: string;
49
+ settings: undefined;
50
+ };
51
+ lexicalEditor: {
52
+ fieldType: "rich-text";
53
+ settings: undefined;
54
+ };
55
+ lexicalEditors: {
56
+ fieldType: "rich-text";
57
+ settings?: {
58
+ multiValue?: {
59
+ addValueButtonLabel?: string;
60
+ };
61
+ };
62
+ };
63
+ textarea: {
64
+ fieldType: "long-text";
65
+ settings: undefined;
66
+ };
67
+ textareas: {
68
+ fieldType: "long-text";
69
+ settings: {
70
+ multiValue?: {
71
+ addValueButtonLabel?: string;
72
+ };
73
+ };
74
+ };
75
+ numberInput: {
76
+ fieldType: "number";
77
+ settings: undefined;
78
+ };
79
+ numberInputs: {
80
+ fieldType: "number";
81
+ settings?: {
82
+ multiValue?: {
83
+ addValueButtonLabel?: string;
84
+ };
85
+ };
86
+ };
87
+ objectAccordionSingle: {
88
+ fieldType: "object";
89
+ settings?: {
90
+ open?: boolean;
91
+ };
92
+ };
93
+ objectAccordionMultiple: {
94
+ fieldType: "object";
95
+ settings?: {
96
+ open?: boolean;
97
+ multiValue?: {
98
+ addValueButtonLabel?: string;
99
+ };
100
+ };
101
+ };
102
+ passthrough: {
103
+ fieldType: string;
104
+ settings: undefined;
105
+ };
106
+ radioButtons: {
107
+ fieldType: "text" | "number";
108
+ settings: undefined;
109
+ };
110
+ refDialogSingle: {
111
+ fieldType: "ref";
112
+ settings: undefined;
113
+ };
114
+ refDialogMultiple: {
115
+ fieldType: "ref";
116
+ settings?: {
117
+ newItemPosition?: "first" | "last";
118
+ };
119
+ };
120
+ refAutocompleteSingle: {
121
+ fieldType: "ref";
122
+ settings: undefined;
123
+ };
124
+ refAutocompleteMultiple: {
125
+ fieldType: "ref";
126
+ settings: undefined;
127
+ };
128
+ refCheckboxes: {
129
+ fieldType: "ref";
130
+ settings: undefined;
131
+ };
132
+ refRadioButtons: {
133
+ fieldType: "ref";
134
+ settings: undefined;
135
+ };
136
+ dropdown: {
137
+ fieldType: "text" | "number";
138
+ settings: undefined;
139
+ };
140
+ tags: {
141
+ fieldType: "text";
142
+ settings: undefined;
143
+ };
144
+ textInput: {
145
+ fieldType: "text";
146
+ settings: undefined;
147
+ };
148
+ textInputs: {
149
+ fieldType: "text";
150
+ settings?: {
151
+ multiValue?: {
152
+ addValueButtonLabel?: string;
153
+ };
154
+ };
155
+ };
156
+ file: {
157
+ fieldType: "file";
158
+ settings?: {
159
+ imagesOnly?: boolean;
160
+ };
161
+ };
162
+ files: {
163
+ fieldType: "file";
164
+ settings?: {
165
+ imagesOnly?: boolean;
166
+ };
167
+ };
168
+ uiSeparator: {
169
+ fieldType: "ui";
170
+ settings: undefined;
171
+ };
172
+ uiAlert: {
173
+ fieldType: "ui";
174
+ settings: {
175
+ type: "info" | "success" | "warning" | "danger";
176
+ };
177
+ };
178
+ uiTabs: {
179
+ fieldType: "ui";
180
+ settings: undefined;
181
+ };
182
+ }
183
+ /**
184
+ * Extracts renderer names valid for the given field type.
185
+ * When TType is a broad `string`, all renderer names are returned.
186
+ */
187
+ export type FieldRendererName<TType extends string = string> = string extends TType ? keyof FieldRendererRegistry & string : {
188
+ [K in keyof FieldRendererRegistry]: TType extends FieldRendererRegistry[K]["fieldType"] ? K : never;
189
+ }[keyof FieldRendererRegistry] & string;
190
+ export type FieldRendererSettings<TName extends string> = TName extends keyof FieldRendererRegistry ? FieldRendererRegistry[TName]["settings"] : Record<string, any> | undefined;
191
+ /**
192
+ * DataFieldBuilder class for data fields that produce CmsModelField instances.
193
+ * Provides storageId, list, validation, renderer, and other data-field methods.
194
+ */
195
+ export declare class DataFieldBuilder<TType extends string = string> extends BaseFieldBuilder<TType> {
196
+ protected config: FieldBuilderConfig;
197
+ constructor(type: TType, label?: string);
198
+ placeholder(text: string): this;
199
+ storageId(id: string): this;
200
+ defaultValue(value: any): this;
201
+ list(): this;
202
+ tags(tags: string[]): this;
203
+ /**
204
+ * List validators - these methods are available after calling list()
205
+ */
206
+ listMinLength(value: number, message?: string): this;
207
+ listMaxLength(value: number, message?: string): this;
208
+ /**
209
+ * Add a validation rule to this field.
210
+ * This method is protected and should only be used by field-specific validator methods.
211
+ * @internal
212
+ */
213
+ protected validation(validation: CmsModelFieldValidation): this;
214
+ /**
215
+ * Add a list validation rule to this field (for list fields).
216
+ * This method is protected and should only be used by field-specific validator methods.
217
+ * @internal
218
+ */
219
+ protected listValidation(validation: CmsModelFieldValidation): this;
220
+ predefinedValues(values: CmsModelFieldPredefinedValues["values"]): this;
221
+ renderer<TName extends FieldRendererName<TType>>(name: TName, ...args: undefined extends FieldRendererSettings<TName> ? [settings?: FieldRendererSettings<TName>] : FieldRendererSettings<TName> extends undefined ? [] : [settings: FieldRendererSettings<TName>]): this;
222
+ settings(settings: Record<string, any>): this;
223
+ /**
224
+ * Build the final CmsModelField
225
+ * @internal
226
+ */
227
+ build(): DataFieldBuildResult;
228
+ }
@@ -0,0 +1,219 @@
1
+ import camelCase from "lodash/camelCase.js";
2
+ import { getBaseFieldType } from "../../../utils/getBaseFieldType.js";
3
+ import { BaseFieldBuilder } from "./BaseFieldBuilder.js";
4
+
5
+ /**
6
+ * Augmentable renderer registry.
7
+ * Each entry maps a renderer name to its applicable field type(s) and settings.
8
+ *
9
+ * Example:
10
+ * declare module "@webiny/api-headless-cms/features/modelBuilder/fields/FieldBuilder" {
11
+ * interface FieldRendererRegistry {
12
+ * "my-renderer": { fieldType: "text" | "long-text"; settings: { color: string } };
13
+ * }
14
+ * }
15
+ */
16
+
17
+ /**
18
+ * Maps camelCase renderer names (used in the builder API) to the
19
+ * kebab-case names expected by the frontend renderer registry.
20
+ */
21
+ const rendererNameMap = {
22
+ switch: "boolean-input",
23
+ checkboxes: "checkboxes",
24
+ dateTimeInput: "date-time-input",
25
+ dateTimeInputs: "date-time-inputs",
26
+ dynamicZone: "dynamicZone",
27
+ hidden: "hidden",
28
+ lexicalEditor: "lexical-text-input",
29
+ lexicalEditors: "lexical-text-inputs",
30
+ textarea: "long-text-text-area",
31
+ textareas: "long-text-inputs",
32
+ numberInput: "number-input",
33
+ numberInputs: "number-inputs",
34
+ objectAccordionSingle: "object-accordion",
35
+ objectAccordionMultiple: "objects-accordion",
36
+ passthrough: "passthrough",
37
+ radioButtons: "radio-buttons",
38
+ refDialogSingle: "ref-advanced-single",
39
+ refDialogMultiple: "ref-advanced-multiple",
40
+ refAutocompleteSingle: "ref-input",
41
+ refAutocompleteMultiple: "ref-inputs",
42
+ refCheckboxes: "ref-simple-multiple",
43
+ refRadioButtons: "ref-simple-single",
44
+ dropdown: "select-box",
45
+ tags: "tags",
46
+ textInput: "text-input",
47
+ textInputs: "text-inputs",
48
+ file: "file-input",
49
+ files: "file-inputs",
50
+ uiSeparator: "uiSeparator",
51
+ uiAlert: "uiAlert",
52
+ uiTabs: "uiTabs"
53
+ };
54
+
55
+ /**
56
+ * Resolves a camelCase renderer name to the kebab-case name used by the frontend.
57
+ */
58
+ function resolveRendererName(name) {
59
+ return rendererNameMap[name] ?? name;
60
+ }
61
+
62
+ /**
63
+ * Extracts renderer names valid for the given field type.
64
+ * When TType is a broad `string`, all renderer names are returned.
65
+ */
66
+
67
+ /**
68
+ * DataFieldBuilder class for data fields that produce CmsModelField instances.
69
+ * Provides storageId, list, validation, renderer, and other data-field methods.
70
+ */
71
+ export class DataFieldBuilder extends BaseFieldBuilder {
72
+ constructor(type, label) {
73
+ super(type, label);
74
+ this.config = {
75
+ label: label || "",
76
+ validation: [],
77
+ listValidation: [],
78
+ list: false,
79
+ predefinedValues: {
80
+ enabled: false,
81
+ values: []
82
+ },
83
+ help: null,
84
+ placeholder: null,
85
+ description: null,
86
+ note: null,
87
+ renderer: null,
88
+ settings: {},
89
+ tags: []
90
+ };
91
+ }
92
+ placeholder(text) {
93
+ this.config.placeholder = text;
94
+ return this;
95
+ }
96
+ storageId(id) {
97
+ // We do not allow developers to specify the field type!
98
+ this.config._storageId = id.split("@").pop();
99
+ return this;
100
+ }
101
+ defaultValue(value) {
102
+ this.config.settings = {
103
+ ...this.config.settings,
104
+ defaultValue: value
105
+ };
106
+ return this;
107
+ }
108
+ list() {
109
+ this.config.list = true;
110
+ return this;
111
+ }
112
+ tags(tags) {
113
+ this.config.tags = tags;
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * List validators - these methods are available after calling list()
119
+ */
120
+ listMinLength(value, message) {
121
+ return this.listValidation({
122
+ name: "minLength",
123
+ message: message || `At least ${value} item(s) required.`,
124
+ settings: {
125
+ value
126
+ }
127
+ });
128
+ }
129
+ listMaxLength(value, message) {
130
+ return this.listValidation({
131
+ name: "maxLength",
132
+ message: message || `At most ${value} item(s) allowed.`,
133
+ settings: {
134
+ value
135
+ }
136
+ });
137
+ }
138
+
139
+ /**
140
+ * Add a validation rule to this field.
141
+ * This method is protected and should only be used by field-specific validator methods.
142
+ * @internal
143
+ */
144
+ validation(validation) {
145
+ this.config.validation = this.config.validation || [];
146
+ this.config.validation.push(validation);
147
+ return this;
148
+ }
149
+
150
+ /**
151
+ * Add a list validation rule to this field (for list fields).
152
+ * This method is protected and should only be used by field-specific validator methods.
153
+ * @internal
154
+ */
155
+ listValidation(validation) {
156
+ this.config.listValidation = this.config.listValidation || [];
157
+ this.config.listValidation.push(validation);
158
+ return this;
159
+ }
160
+ predefinedValues(values) {
161
+ this.config.predefinedValues = {
162
+ enabled: true,
163
+ values
164
+ };
165
+ return this;
166
+ }
167
+ renderer(name, ...args) {
168
+ this.config.renderer = {
169
+ name: resolveRendererName(name),
170
+ settings: args[0] ?? null
171
+ };
172
+ return this;
173
+ }
174
+ settings(settings) {
175
+ this.config.settings = {
176
+ ...this.config.settings,
177
+ ...settings
178
+ };
179
+ return this;
180
+ }
181
+
182
+ /**
183
+ * Build the final CmsModelField
184
+ * @internal
185
+ */
186
+ build() {
187
+ const fieldId = this.config._fieldId || camelCase(this.config.label);
188
+ const baseType = getBaseFieldType({
189
+ type: this.type
190
+ });
191
+ const storageId = `${baseType}@${this.config._storageId ?? fieldId}`;
192
+ return {
193
+ type: "data",
194
+ field: {
195
+ id: fieldId,
196
+ fieldId,
197
+ storageId,
198
+ type: this.type,
199
+ label: this.config.label,
200
+ validation: this.config.validation || [],
201
+ listValidation: this.config.listValidation || [],
202
+ list: this.config.list || false,
203
+ predefinedValues: this.config.predefinedValues || {
204
+ enabled: false,
205
+ values: []
206
+ },
207
+ help: this.config.help || null,
208
+ placeholder: this.config.placeholder || null,
209
+ description: this.config.description || null,
210
+ note: this.config.note || null,
211
+ renderer: this.config.renderer || null,
212
+ settings: this.config.settings || {},
213
+ tags: this.config.tags || []
214
+ }
215
+ };
216
+ }
217
+ }
218
+
219
+ //# sourceMappingURL=DataFieldBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["camelCase","getBaseFieldType","BaseFieldBuilder","rendererNameMap","switch","checkboxes","dateTimeInput","dateTimeInputs","dynamicZone","hidden","lexicalEditor","lexicalEditors","textarea","textareas","numberInput","numberInputs","objectAccordionSingle","objectAccordionMultiple","passthrough","radioButtons","refDialogSingle","refDialogMultiple","refAutocompleteSingle","refAutocompleteMultiple","refCheckboxes","refRadioButtons","dropdown","tags","textInput","textInputs","file","files","uiSeparator","uiAlert","uiTabs","resolveRendererName","name","DataFieldBuilder","constructor","type","label","config","validation","listValidation","list","predefinedValues","enabled","values","help","placeholder","description","note","renderer","settings","text","storageId","id","_storageId","split","pop","defaultValue","value","listMinLength","message","listMaxLength","push","args","build","fieldId","_fieldId","baseType","field"],"sources":["DataFieldBuilder.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport type {\n CmsModelField,\n CmsModelFieldPredefinedValues,\n CmsModelFieldValidation\n} from \"~/types/index.js\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType.js\";\nimport { BaseFieldBuilder, type DataFieldBuildResult } from \"./BaseFieldBuilder.js\";\n\nexport interface FieldBuilderConfig\n extends Omit<CmsModelField, \"id\" | \"fieldId\" | \"storageId\" | \"type\"> {\n _storageId?: string;\n _fieldId?: string;\n description?: string | null;\n note?: string | null;\n}\n\n/**\n * Augmentable renderer registry.\n * Each entry maps a renderer name to its applicable field type(s) and settings.\n *\n * Example:\n * declare module \"@webiny/api-headless-cms/features/modelBuilder/fields/FieldBuilder\" {\n * interface FieldRendererRegistry {\n * \"my-renderer\": { fieldType: \"text\" | \"long-text\"; settings: { color: string } };\n * }\n * }\n */\nexport interface FieldRendererRegistry {\n switch: {\n fieldType: \"boolean\";\n settings: undefined;\n };\n checkboxes: {\n fieldType: \"text\" | \"number\";\n settings: undefined;\n };\n dateTimeInput: {\n fieldType: \"datetime\";\n settings: undefined;\n };\n dateTimeInputs: {\n fieldType: \"datetime\";\n settings?: {\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n dynamicZone: {\n fieldType: \"dynamicZone\";\n settings?: {\n open?: boolean;\n };\n };\n hidden: {\n fieldType: string;\n settings: undefined;\n };\n lexicalEditor: {\n fieldType: \"rich-text\";\n settings: undefined;\n };\n lexicalEditors: {\n fieldType: \"rich-text\";\n settings?: {\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n textarea: {\n fieldType: \"long-text\";\n settings: undefined;\n };\n textareas: {\n fieldType: \"long-text\";\n settings: {\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n numberInput: {\n fieldType: \"number\";\n settings: undefined;\n };\n numberInputs: {\n fieldType: \"number\";\n settings?: {\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n objectAccordionSingle: {\n fieldType: \"object\";\n settings?: {\n open?: boolean;\n };\n };\n objectAccordionMultiple: {\n fieldType: \"object\";\n settings?: {\n open?: boolean;\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n passthrough: {\n fieldType: string;\n settings: undefined;\n };\n radioButtons: {\n fieldType: \"text\" | \"number\";\n settings: undefined;\n };\n refDialogSingle: {\n fieldType: \"ref\";\n settings: undefined;\n };\n refDialogMultiple: {\n fieldType: \"ref\";\n settings?: {\n newItemPosition?: \"first\" | \"last\";\n };\n };\n refAutocompleteSingle: {\n fieldType: \"ref\";\n settings: undefined;\n };\n refAutocompleteMultiple: {\n fieldType: \"ref\";\n settings: undefined;\n };\n refCheckboxes: {\n fieldType: \"ref\";\n settings: undefined;\n };\n refRadioButtons: {\n fieldType: \"ref\";\n settings: undefined;\n };\n dropdown: {\n fieldType: \"text\" | \"number\";\n settings: undefined;\n };\n tags: {\n fieldType: \"text\";\n settings: undefined;\n };\n textInput: {\n fieldType: \"text\";\n settings: undefined;\n };\n textInputs: {\n fieldType: \"text\";\n settings?: {\n multiValue?: {\n addValueButtonLabel?: string;\n };\n };\n };\n file: {\n fieldType: \"file\";\n settings?: {\n imagesOnly?: boolean;\n };\n };\n files: {\n fieldType: \"file\";\n settings?: {\n imagesOnly?: boolean;\n };\n };\n uiSeparator: {\n fieldType: \"ui\";\n settings: undefined;\n };\n uiAlert: {\n fieldType: \"ui\";\n settings: {\n type: \"info\" | \"success\" | \"warning\" | \"danger\";\n };\n };\n uiTabs: {\n fieldType: \"ui\";\n settings: undefined;\n };\n}\n\n/**\n * Maps camelCase renderer names (used in the builder API) to the\n * kebab-case names expected by the frontend renderer registry.\n */\nconst rendererNameMap: Record<keyof FieldRendererRegistry, string> = {\n switch: \"boolean-input\",\n checkboxes: \"checkboxes\",\n dateTimeInput: \"date-time-input\",\n dateTimeInputs: \"date-time-inputs\",\n dynamicZone: \"dynamicZone\",\n hidden: \"hidden\",\n lexicalEditor: \"lexical-text-input\",\n lexicalEditors: \"lexical-text-inputs\",\n textarea: \"long-text-text-area\",\n textareas: \"long-text-inputs\",\n numberInput: \"number-input\",\n numberInputs: \"number-inputs\",\n objectAccordionSingle: \"object-accordion\",\n objectAccordionMultiple: \"objects-accordion\",\n passthrough: \"passthrough\",\n radioButtons: \"radio-buttons\",\n refDialogSingle: \"ref-advanced-single\",\n refDialogMultiple: \"ref-advanced-multiple\",\n refAutocompleteSingle: \"ref-input\",\n refAutocompleteMultiple: \"ref-inputs\",\n refCheckboxes: \"ref-simple-multiple\",\n refRadioButtons: \"ref-simple-single\",\n dropdown: \"select-box\",\n tags: \"tags\",\n textInput: \"text-input\",\n textInputs: \"text-inputs\",\n file: \"file-input\",\n files: \"file-inputs\",\n uiSeparator: \"uiSeparator\",\n uiAlert: \"uiAlert\",\n uiTabs: \"uiTabs\"\n};\n\n/**\n * Resolves a camelCase renderer name to the kebab-case name used by the frontend.\n */\nfunction resolveRendererName(name: string): string {\n return rendererNameMap[name as keyof FieldRendererRegistry] ?? name;\n}\n\n/**\n * Extracts renderer names valid for the given field type.\n * When TType is a broad `string`, all renderer names are returned.\n */\nexport type FieldRendererName<TType extends string = string> = string extends TType\n ? keyof FieldRendererRegistry & string\n : {\n [K in keyof FieldRendererRegistry]: TType extends FieldRendererRegistry[K][\"fieldType\"]\n ? K\n : never;\n }[keyof FieldRendererRegistry] &\n string;\n\nexport type FieldRendererSettings<TName extends string> = TName extends keyof FieldRendererRegistry\n ? FieldRendererRegistry[TName][\"settings\"]\n : Record<string, any> | undefined;\n\n/**\n * DataFieldBuilder class for data fields that produce CmsModelField instances.\n * Provides storageId, list, validation, renderer, and other data-field methods.\n */\nexport class DataFieldBuilder<TType extends string = string> extends BaseFieldBuilder<TType> {\n protected override config: FieldBuilderConfig;\n\n public constructor(type: TType, label?: string) {\n super(type, label);\n this.config = {\n label: label || \"\",\n validation: [],\n listValidation: [],\n list: false,\n predefinedValues: {\n enabled: false,\n values: []\n },\n help: null,\n placeholder: null,\n description: null,\n note: null,\n renderer: null,\n settings: {},\n tags: []\n };\n }\n\n placeholder(text: string): this {\n this.config.placeholder = text;\n return this;\n }\n\n storageId(id: string): this {\n // We do not allow developers to specify the field type!\n this.config._storageId = id.split(\"@\").pop();\n return this;\n }\n\n defaultValue(value: any): this {\n this.config.settings = { ...this.config.settings, defaultValue: value };\n return this;\n }\n\n list(): this {\n this.config.list = true;\n return this as this;\n }\n\n tags(tags: string[]): this {\n this.config.tags = tags;\n return this;\n }\n\n /**\n * List validators - these methods are available after calling list()\n */\n listMinLength(value: number, message?: string): this {\n return this.listValidation({\n name: \"minLength\",\n message: message || `At least ${value} item(s) required.`,\n settings: { value }\n });\n }\n\n listMaxLength(value: number, message?: string): this {\n return this.listValidation({\n name: \"maxLength\",\n message: message || `At most ${value} item(s) allowed.`,\n settings: { value }\n });\n }\n\n /**\n * Add a validation rule to this field.\n * This method is protected and should only be used by field-specific validator methods.\n * @internal\n */\n protected validation(validation: CmsModelFieldValidation): this {\n this.config.validation = this.config.validation || [];\n this.config.validation.push(validation);\n return this;\n }\n\n /**\n * Add a list validation rule to this field (for list fields).\n * This method is protected and should only be used by field-specific validator methods.\n * @internal\n */\n protected listValidation(validation: CmsModelFieldValidation): this {\n this.config.listValidation = this.config.listValidation || [];\n this.config.listValidation.push(validation);\n return this;\n }\n\n predefinedValues(values: CmsModelFieldPredefinedValues[\"values\"]): this {\n this.config.predefinedValues = {\n enabled: true,\n values\n };\n return this;\n }\n\n renderer<TName extends FieldRendererName<TType>>(\n name: TName,\n ...args: undefined extends FieldRendererSettings<TName>\n ? [settings?: FieldRendererSettings<TName>]\n : FieldRendererSettings<TName> extends undefined\n ? []\n : [settings: FieldRendererSettings<TName>]\n ): this {\n this.config.renderer = {\n name: resolveRendererName(name),\n settings: args[0] ?? null\n };\n return this;\n }\n\n settings(settings: Record<string, any>): this {\n this.config.settings = { ...this.config.settings, ...settings };\n return this;\n }\n\n /**\n * Build the final CmsModelField\n * @internal\n */\n build(): DataFieldBuildResult {\n const fieldId = this.config._fieldId || camelCase(this.config.label);\n const baseType = getBaseFieldType({\n type: this.type\n });\n const storageId = `${baseType}@${this.config._storageId ?? fieldId}`;\n\n return {\n type: \"data\",\n field: {\n id: fieldId,\n fieldId,\n storageId,\n type: this.type,\n label: this.config.label,\n validation: this.config.validation || [],\n listValidation: this.config.listValidation || [],\n list: this.config.list || false,\n predefinedValues: this.config.predefinedValues || {\n enabled: false,\n values: []\n },\n help: this.config.help || null,\n placeholder: this.config.placeholder || null,\n description: this.config.description || null,\n note: this.config.note || null,\n renderer: this.config.renderer || null,\n settings: this.config.settings || {},\n tags: this.config.tags || []\n }\n };\n }\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAM3C,SAASC,gBAAgB;AACzB,SAASC,gBAAgB;;AAUzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqKA;AACA;AACA;AACA;AACA,MAAMC,eAA4D,GAAG;EACjEC,MAAM,EAAE,eAAe;EACvBC,UAAU,EAAE,YAAY;EACxBC,aAAa,EAAE,iBAAiB;EAChCC,cAAc,EAAE,kBAAkB;EAClCC,WAAW,EAAE,aAAa;EAC1BC,MAAM,EAAE,QAAQ;EAChBC,aAAa,EAAE,oBAAoB;EACnCC,cAAc,EAAE,qBAAqB;EACrCC,QAAQ,EAAE,qBAAqB;EAC/BC,SAAS,EAAE,kBAAkB;EAC7BC,WAAW,EAAE,cAAc;EAC3BC,YAAY,EAAE,eAAe;EAC7BC,qBAAqB,EAAE,kBAAkB;EACzCC,uBAAuB,EAAE,mBAAmB;EAC5CC,WAAW,EAAE,aAAa;EAC1BC,YAAY,EAAE,eAAe;EAC7BC,eAAe,EAAE,qBAAqB;EACtCC,iBAAiB,EAAE,uBAAuB;EAC1CC,qBAAqB,EAAE,WAAW;EAClCC,uBAAuB,EAAE,YAAY;EACrCC,aAAa,EAAE,qBAAqB;EACpCC,eAAe,EAAE,mBAAmB;EACpCC,QAAQ,EAAE,YAAY;EACtBC,IAAI,EAAE,MAAM;EACZC,SAAS,EAAE,YAAY;EACvBC,UAAU,EAAE,aAAa;EACzBC,IAAI,EAAE,YAAY;EAClBC,KAAK,EAAE,aAAa;EACpBC,WAAW,EAAE,aAAa;EAC1BC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE;AACZ,CAAC;;AAED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ACdC,MAAM,EAAE;QACZ,CAAC;QACDC,IAAI,EAAE,IAAI,CAACP,MAAM,CAACO,IAAI,IAAI,IAAI;QAC9BC,WAAW,EAAE,IAAI,CAACR,MAAM,CAACQ,WAAW,IAAI,IAAI;QAC5CC,WAAW,EAAE,IAAI,CAACT,MAAM,CAACS,WAAW,IAAI,IAAI;QAC5CC,IAAI,EAAE,IAAI,CAACV,MAAM,CAACU,IAAI,IAAI,IAAI;QAC9BC,QAAQ,EAAE,IAAI,CAACX,MAAM,CAACW,QAAQ,IAAI,IAAI;QACtCC,QAAQ,EAAE,IAAI,CAACZ,MAAM,CAACY,QAAQ,IAAI,CAAC,CAAC;QACpC1B,IAAI,EAAE,IAAI,CAACc,MAAM,CAACd,IAAI,IAAI;MAC9B;IACJ,CAAC;EACL;AACJ","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { type IFieldTypeFactory } from "./abstractions.js";
2
- import { FieldBuilder } from "./FieldBuilder.js";
2
+ import { FieldBuilder, type BaseFieldBuilder } from "./FieldBuilder.js";
3
3
  import { type IFieldBuilderRegistry } from "../abstractions.js";
4
4
  import type { CmsIcon } from "../../../types/index.js";
5
5
  export interface IDynamicZoneFieldBuilder extends FieldBuilder<"dynamicZone"> {
@@ -9,7 +9,7 @@ export interface IDynamicZoneFieldBuilder extends FieldBuilder<"dynamicZone"> {
9
9
  gqlTypeName: string;
10
10
  icon?: CmsIcon;
11
11
  description?: string;
12
- fields: (registry: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>;
12
+ fields: (registry: IFieldBuilderRegistry) => Record<string, BaseFieldBuilder<any>>;
13
13
  layout?: string[][];
14
14
  }): this;
15
15
  }
@@ -17,10 +17,13 @@ class DynamicZoneFieldBuilder extends FieldBuilder {
17
17
  const fieldBuilders = config.fields(this.registry);
18
18
  const fields = [];
19
19
  for (const [key, fieldBuilder] of Object.entries(fieldBuilders)) {
20
- // Automatically set the fieldId from the object key
21
- // This ensures the key and fieldId are always in sync
22
20
  fieldBuilder.fieldId(key);
23
- fields.push(fieldBuilder.build());
21
+ const result = fieldBuilder.build();
22
+ if (result.type === "data") {
23
+ fields.push(result.field);
24
+ } else if (result.fields) {
25
+ fields.push(...result.fields);
26
+ }
24
27
  }
25
28
  this.templates.push({
26
29
  id,
@@ -1 +1 @@
1
- {"version":3,"names":["FieldType","FieldBuilder","DynamicZoneFieldBuilder","templates","constructor","registry","required","message","validation","name","settings","template","id","config","fieldBuilders","fields","key","fieldBuilder","Object","entries","fieldId","push","build","gqlTypeName","icon","description","layout","listValidation","DynamicZoneFieldTypeFactory","type","create","DynamicZoneFieldType","createImplementation","implementation","dependencies"],"sources":["DynamicZoneFieldType.ts"],"sourcesContent":["import { FieldType, type IFieldTypeFactory } from \"./abstractions.js\";\nimport { FieldBuilder } from \"./FieldBuilder.js\";\nimport { type IFieldBuilderRegistry } from \"../abstractions.js\";\nimport type { CmsIcon, CmsModelFieldValidation } from \"~/types/index.js\";\n\ninterface IDynamicZoneTemplate {\n id: string;\n name: string;\n gqlTypeName: string;\n icon: CmsIcon | undefined;\n description: string;\n fields: any[];\n layout: string[][];\n validation: CmsModelFieldValidation[];\n}\n\nexport interface IDynamicZoneFieldBuilder extends FieldBuilder<\"dynamicZone\"> {\n required(message?: string): this;\n template(\n id: string,\n config: {\n name: string;\n gqlTypeName: string;\n icon?: CmsIcon;\n description?: string;\n fields: (registry: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>;\n layout?: string[][];\n }\n ): this;\n}\n\ninterface IDynamicZoneFieldBuilderTemplateConfig {\n name: string;\n gqlTypeName: string;\n icon?: CmsIcon;\n description?: string;\n fields: (registry: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>;\n layout?: string[][];\n}\n\nclass DynamicZoneFieldBuilder\n extends FieldBuilder<\"dynamicZone\">\n implements IDynamicZoneFieldBuilder\n{\n private readonly templates: IDynamicZoneTemplate[] = [];\n\n public constructor(private registry: IFieldBuilderRegistry) {\n super(\"dynamicZone\");\n }\n\n public required(message?: string): this {\n return this.validation({\n name: \"required\",\n message: message || \"Field is required\",\n settings: {}\n });\n }\n\n public template(id: string, config: IDynamicZoneFieldBuilderTemplateConfig): this {\n const fieldBuilders = config.fields(this.registry);\n const fields: any[] = [];\n\n for (const [key, fieldBuilder] of Object.entries(fieldBuilders)) {\n // Automatically set the fieldId from the object key\n // This ensures the key and fieldId are always in sync\n fieldBuilder.fieldId(key);\n fields.push((fieldBuilder as any).build());\n }\n\n this.templates.push({\n id,\n name: config.name,\n gqlTypeName: config.gqlTypeName,\n icon: config.icon,\n description: config.description || \"\",\n fields,\n layout: config.layout || [],\n validation: []\n });\n\n return this;\n }\n\n public override build() {\n // Set templates in settings before building\n this.config.settings = this.config.settings || {};\n this.config.settings.templates = this.templates;\n this.config.listValidation = [{ name: \"dynamicZone\", message: \"\" }];\n return super.build();\n }\n}\n\nclass DynamicZoneFieldTypeFactory implements IFieldTypeFactory {\n public readonly type = \"dynamicZone\";\n\n public create(registry: IFieldBuilderRegistry): IDynamicZoneFieldBuilder {\n return new DynamicZoneFieldBuilder(registry);\n }\n}\n\nexport const DynamicZoneFieldType = FieldType.createImplementation({\n implementation: DynamicZoneFieldTypeFactory,\n dependencies: []\n});\n\n// Module augmentation for TypeScript autocomplete\ndeclare module \"../abstractions.js\" {\n interface IFieldBuilderRegistry {\n dynamicZone(): IDynamicZoneFieldBuilder;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS;AAClB,SAASC,YAAY;AAuCrB,MAAMC,uBAAuB,SACjBD,YAAY,CAExB;EACqBE,SAAS,GAA2B,EAAE;EAEhDC,WAAWA,CAASC,QAA+B,EAAE;IACxD,KAAK,CAAC,aAAa,CAAC;IAAC,KADEA,QAA+B,GAA/BA,QAA+B;EAE1D;EAEOC,QAAQA,CAACC,OAAgB,EAAQ;IACpC,OAAO,IAAI,CAACC,UAAU,CAAC;MACnBC,IAAI,EAAE,UAAU;MAChBF,OAAO,EAAEA,OAAO,IAAI,mBAAmB;MACvCG,QAAQ,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rE,OAAO,IAAIH,uBAAuB,CAACG,QAAQ,CAAC;EAChD;AACJ;AAEA,OAAO,MAAM0B,oBAAoB,GAAG/B,SAAS,CAACgC,oBAAoB,CAAC;EAC/DC,cAAc,EAAEL,2BAA2B;EAC3CM,YAAY,EAAE;AAClB,CAAC,CAAC;;AAEF","ignoreList":[]}
1
+ {"version":3,"names":["FieldType","FieldBuilder","DynamicZoneFieldBuilder","templates","constructor","registry","required","message","validation","name","settings","template","id","config","fieldBuilders","fields","key","fieldBuilder","Object","entries","fieldId","result","build","type","push","field","gqlTypeName","icon","description","layout","listValidation","DynamicZoneFieldTypeFactory","create","DynamicZoneFieldType","createImplementation","implementation","dependencies"],"sources":["DynamicZoneFieldType.ts"],"sourcesContent":["import { FieldType, type IFieldTypeFactory } from \"./abstractions.js\";\nimport { type FieldBuildResult } from \"./BaseFieldBuilder.js\";\nimport { FieldBuilder, type BaseFieldBuilder } from \"./FieldBuilder.js\";\nimport { type IFieldBuilderRegistry } from \"../abstractions.js\";\nimport type { CmsIcon, CmsModelField, CmsModelFieldValidation } from \"~/types/index.js\";\n\ninterface IDynamicZoneTemplate {\n id: string;\n name: string;\n gqlTypeName: string;\n icon: CmsIcon | undefined;\n description: string;\n fields: any[];\n layout: string[][];\n validation: CmsModelFieldValidation[];\n}\n\nexport interface IDynamicZoneFieldBuilder extends FieldBuilder<\"dynamicZone\"> {\n required(message?: string): this;\n template(\n id: string,\n config: {\n name: string;\n gqlTypeName: string;\n icon?: CmsIcon;\n description?: string;\n fields: (registry: IFieldBuilderRegistry) => Record<string, BaseFieldBuilder<any>>;\n layout?: string[][];\n }\n ): this;\n}\n\ninterface IDynamicZoneFieldBuilderTemplateConfig {\n name: string;\n gqlTypeName: string;\n icon?: CmsIcon;\n description?: string;\n fields: (registry: IFieldBuilderRegistry) => Record<string, BaseFieldBuilder<any>>;\n layout?: string[][];\n}\n\nclass DynamicZoneFieldBuilder\n extends FieldBuilder<\"dynamicZone\">\n implements IDynamicZoneFieldBuilder\n{\n private readonly templates: IDynamicZoneTemplate[] = [];\n\n public constructor(private registry: IFieldBuilderRegistry) {\n super(\"dynamicZone\");\n }\n\n public required(message?: string): this {\n return this.validation({\n name: \"required\",\n message: message || \"Field is required\",\n settings: {}\n });\n }\n\n public template(id: string, config: IDynamicZoneFieldBuilderTemplateConfig): this {\n const fieldBuilders = config.fields(this.registry);\n const fields: CmsModelField[] = [];\n\n for (const [key, fieldBuilder] of Object.entries(fieldBuilders)) {\n fieldBuilder.fieldId(key);\n const result: FieldBuildResult = (fieldBuilder as any).build();\n if (result.type === \"data\") {\n fields.push(result.field);\n } else if (result.fields) {\n fields.push(...result.fields);\n }\n }\n\n this.templates.push({\n id,\n name: config.name,\n gqlTypeName: config.gqlTypeName,\n icon: config.icon,\n description: config.description || \"\",\n fields,\n layout: config.layout || [],\n validation: []\n });\n\n return this;\n }\n\n public override build() {\n // Set templates in settings before building\n this.config.settings = this.config.settings || {};\n this.config.settings.templates = this.templates;\n this.config.listValidation = [{ name: \"dynamicZone\", message: \"\" }];\n return super.build();\n }\n}\n\nclass DynamicZoneFieldTypeFactory implements IFieldTypeFactory {\n public readonly type = \"dynamicZone\";\n\n public create(registry: IFieldBuilderRegistry): IDynamicZoneFieldBuilder {\n return new DynamicZoneFieldBuilder(registry);\n }\n}\n\nexport const DynamicZoneFieldType = FieldType.createImplementation({\n implementation: DynamicZoneFieldTypeFactory,\n dependencies: []\n});\n\n// Module augmentation for TypeScript autocomplete\ndeclare module \"../abstractions.js\" {\n interface IFieldBuilderRegistry {\n dynamicZone(): IDynamicZoneFieldBuilder;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS;AAElB,SAASC,YAAY;AAuCrB,MAAMC,uBAAuB,SACjBD,YAAY,CAExB;EACqBE,SAAS,GAA2B,EAAE;EAEhDC,WAAWA,CAASC,QAA+B,EAAE;IACxD,KAAK,CAAC,aAAa,CAAC;IAAC,KADEA,QAA+B,GAA/BA,QAA+B;EAE1D;EAEOC,QAAQA,CAAC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