@websolutespa/payload-plugin-bowl 0.0.1

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.
package/dist/index.js ADDED
@@ -0,0 +1,3835 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ BlockDefaults: () => BlockDefaults,
34
+ CategoryDefaults: () => CategoryDefaults,
35
+ CheckboxDefaults: () => CheckboxDefaults,
36
+ CollectionDefault: () => CollectionDefault,
37
+ ColorCell: () => ColorCell,
38
+ ColorConfig: () => ColorConfig,
39
+ ColorField: () => ColorField,
40
+ ComponentsDefaults: () => ComponentsDefaults,
41
+ DateDefaults: () => DateDefaults,
42
+ DebugField: () => DebugField,
43
+ GlobalDefault: () => GlobalDefault,
44
+ InMemoryCache: () => InMemoryCache,
45
+ LocalizedField: () => LocalizedField,
46
+ MarketDefaults: () => MarketDefaults,
47
+ MediaDefaults: () => MediaDefaults,
48
+ MediasDefaults: () => MediasDefaults,
49
+ PageDefault: () => PageDefault,
50
+ RelatedDefaults: () => RelatedDefaults,
51
+ RichTextDefaults: () => RichTextDefaults,
52
+ SelectDefaults: () => SelectDefaults,
53
+ StaticCollectionDefault: () => StaticCollectionDefault,
54
+ TemplateDefaults: () => TemplateDefaults,
55
+ TextDefaults: () => TextDefaults,
56
+ UILanguagesCell: () => UILanguagesCell,
57
+ UILanguagesField: () => UILanguagesField,
58
+ UIStaticCell: () => UIStaticCell,
59
+ UIStaticField: () => UIStaticField,
60
+ afterPageChangeHook: () => afterPageChangeHook,
61
+ afterPageDeleteHook: () => afterPageDeleteHook,
62
+ appearanceOptions: () => appearanceOptions,
63
+ bowl: () => bowl,
64
+ collectionGet: () => collectionGet,
65
+ debugField: () => debugField,
66
+ deepMerge: () => deepMerge,
67
+ default: () => src_default,
68
+ defaultGroup: () => defaultGroup,
69
+ defaultLocale: () => defaultLocale,
70
+ defaultLocales: () => defaultLocales,
71
+ defaultSlug: () => defaultSlug,
72
+ fetchCollection: () => fetchCollection,
73
+ fetchCollectionItems: () => fetchCollectionItems,
74
+ fetchEndpoint: () => fetchEndpoint,
75
+ fetchGlobal: () => fetchGlobal,
76
+ fetchGlobalItems: () => fetchGlobalItems,
77
+ formatSlug: () => formatSlug,
78
+ getApiUrl: () => getApiUrl,
79
+ getLocale: () => getLocale,
80
+ getNumericParam: () => getNumericParam,
81
+ getObjectParam: () => getObjectParam,
82
+ getRoute: () => getRoute,
83
+ getRoutes: () => getRoutes,
84
+ getSearchUrl: () => getSearchUrl,
85
+ getStaticLoader: () => getStaticLoader,
86
+ getStore: () => getStore,
87
+ getStringParam: () => getStringParam,
88
+ getTranslation: () => getTranslation2,
89
+ getTranslations: () => getTranslations,
90
+ internalSlugs: () => internalSlugs,
91
+ isObject: () => isObject,
92
+ keyWithRequest: () => keyWithRequest,
93
+ localeGet: () => localeGet,
94
+ localizeCollection: () => localizeCollection,
95
+ localizedField: () => localizedField,
96
+ logMissingTranslations: () => logMissingTranslations,
97
+ options: () => options,
98
+ populateStaticFields: () => populateStaticFields,
99
+ richTextAfterReadHook: () => richTextAfterReadHook,
100
+ richTextSerialize: () => richTextSerialize,
101
+ routeGet: () => routeGet,
102
+ slugToLabel: () => slugToLabel,
103
+ slugToLabels: () => slugToLabels,
104
+ storeGet: () => storeGet,
105
+ toBlock: () => toBlock,
106
+ toCollection: () => toCollection,
107
+ toField: () => toField,
108
+ toGlobal: () => toGlobal,
109
+ toTab: () => toTab,
110
+ translateBlock: () => translateBlock,
111
+ translateBlocks: () => translateBlocks,
112
+ translateCollection: () => translateCollection,
113
+ translateField: () => translateField,
114
+ translateFields: () => translateFields,
115
+ translateGlobal: () => translateGlobal,
116
+ translateTab: () => translateTab,
117
+ translateTabs: () => translateTabs,
118
+ validateHexColor: () => validateHexColor,
119
+ whereCollection: () => whereCollection,
120
+ withAbstract: () => withAbstract,
121
+ withAbstractRequired: () => withAbstractRequired,
122
+ withBlock: () => withBlock,
123
+ withCategory: () => withCategory,
124
+ withCategoryRequired: () => withCategoryRequired,
125
+ withCheckbox: () => withCheckbox,
126
+ withCheckboxRequired: () => withCheckboxRequired,
127
+ withCollection: () => withCollection,
128
+ withCollectionHook: () => withCollectionHook,
129
+ withColor: () => withColor,
130
+ withColorRequired: () => withColorRequired,
131
+ withComponents: () => withComponents,
132
+ withDate: () => withDate,
133
+ withDateRequired: () => withDateRequired,
134
+ withDescription: () => withDescription,
135
+ withDescriptionRequired: () => withDescriptionRequired,
136
+ withFieldHook: () => withFieldHook,
137
+ withGlobal: () => withGlobal,
138
+ withGlobalHook: () => withGlobalHook,
139
+ withId: () => withId,
140
+ withIdRequired: () => withIdRequired,
141
+ withIsActive: () => withIsActive,
142
+ withIsActiveRequired: () => withIsActiveRequired,
143
+ withIsDefault: () => withIsDefault,
144
+ withIsDefaultRequired: () => withIsDefaultRequired,
145
+ withLink: () => withLink,
146
+ withLocalized: () => withLocalized,
147
+ withMarkets: () => withMarkets,
148
+ withMarketsRequired: () => withMarketsRequired,
149
+ withMedia: () => withMedia,
150
+ withMediaRequired: () => withMediaRequired,
151
+ withMedias: () => withMedias,
152
+ withMediasRequired: () => withMediasRequired,
153
+ withName: () => withName,
154
+ withNameRequired: () => withNameRequired,
155
+ withPage: () => withPage,
156
+ withRelated: () => withRelated,
157
+ withRichText: () => withRichText,
158
+ withRichTextRequired: () => withRichTextRequired,
159
+ withSelect: () => withSelect,
160
+ withSelectRequired: () => withSelectRequired,
161
+ withSlug: () => withSlug,
162
+ withSlugRequired: () => withSlugRequired,
163
+ withStaticCollection: () => withStaticCollection,
164
+ withTemplate: () => withTemplate,
165
+ withTemplateRequired: () => withTemplateRequired,
166
+ withText: () => withText,
167
+ withTextRequired: () => withTextRequired,
168
+ withTitle: () => withTitle,
169
+ withTitleRequired: () => withTitleRequired,
170
+ withUILanguages: () => withUILanguages,
171
+ withUIStatic: () => withUIStatic
172
+ });
173
+ module.exports = __toCommonJS(src_exports);
174
+
175
+ // src/collections/Category.ts
176
+ var Category = /* @__PURE__ */ __name((options2) => ({
177
+ type: "withCollection",
178
+ slug: options2.slug.category,
179
+ admin: {
180
+ group: options2.group.nav,
181
+ useAsTitle: "id",
182
+ defaultColumns: ["id", "title", "category"]
183
+ },
184
+ fields: [
185
+ // inherited fields: id, createdAt, updatedAt
186
+ { type: "withId", required: true },
187
+ { type: "withTitle", required: true },
188
+ {
189
+ type: "withSlug",
190
+ fieldToUse: "title",
191
+ admin: {
192
+ position: "sidebar"
193
+ }
194
+ },
195
+ { type: "withMedia" },
196
+ { type: "withCategory" }
197
+ ]
198
+ }), "Category");
199
+
200
+ // src/collections/Continent.ts
201
+ var Continent = /* @__PURE__ */ __name((options2) => ({
202
+ type: "withStatic",
203
+ src: "https://actarian.github.io/cms-i18n-react/api/continent.json",
204
+ slug: options2.slug.continent,
205
+ fields: [
206
+ {
207
+ name: "id",
208
+ label: "ID",
209
+ type: "text"
210
+ },
211
+ {
212
+ name: "name",
213
+ label: "Name",
214
+ type: "text"
215
+ }
216
+ ]
217
+ }), "Continent");
218
+
219
+ // src/collections/Country.ts
220
+ var Country = /* @__PURE__ */ __name((options2) => ({
221
+ type: "withStatic",
222
+ src: "https://actarian.github.io/cms-i18n-react/api/country.json",
223
+ slug: options2.slug.country,
224
+ /*
225
+ map: {
226
+ continentId: 'continent',
227
+ subContinentId: 'subContinent',
228
+ },
229
+ */
230
+ fields: [
231
+ {
232
+ name: "id",
233
+ label: "ID",
234
+ type: "text"
235
+ },
236
+ {
237
+ name: "name",
238
+ label: "Name",
239
+ type: "text",
240
+ localized: true
241
+ },
242
+ {
243
+ name: "englishName",
244
+ label: "English Name",
245
+ type: "text"
246
+ },
247
+ {
248
+ name: "nativeName",
249
+ label: "Native Name",
250
+ type: "text"
251
+ },
252
+ {
253
+ name: "alpha2Code",
254
+ label: "Alpha2 Code",
255
+ type: "text"
256
+ },
257
+ {
258
+ name: "alpha3Code",
259
+ label: "Alpha3 Code",
260
+ type: "text"
261
+ },
262
+ {
263
+ name: "continent",
264
+ label: "Continent",
265
+ type: "relationship",
266
+ relationTo: options2.slug.continent,
267
+ hasMany: false,
268
+ required: true
269
+ },
270
+ {
271
+ name: "subContinent",
272
+ label: "Sub Continent",
273
+ type: "relationship",
274
+ relationTo: options2.slug.subContinent,
275
+ hasMany: false,
276
+ required: true
277
+ }
278
+ ]
279
+ }), "Country");
280
+
281
+ // src/collections/CountryZone.ts
282
+ var CountryZone = /* @__PURE__ */ __name((options2) => ({
283
+ type: "withStatic",
284
+ src: "https://actarian.github.io/cms-i18n-react/api/countryZone.json",
285
+ slug: options2.slug.countryZone,
286
+ fields: [
287
+ {
288
+ name: "id",
289
+ label: "ID",
290
+ type: "text"
291
+ },
292
+ {
293
+ name: "name",
294
+ label: "Name",
295
+ type: "text"
296
+ }
297
+ ]
298
+ }), "CountryZone");
299
+
300
+ // src/collections/Label.ts
301
+ var Label = /* @__PURE__ */ __name((options2) => ({
302
+ type: "withCollection",
303
+ slug: options2.slug.label,
304
+ admin: {
305
+ group: options2.group.config,
306
+ useAsTitle: "id",
307
+ defaultColumns: ["id", "title"]
308
+ },
309
+ fields: [
310
+ // inherited fields: id, createdAt, updatedAt
311
+ { type: "withId", required: true },
312
+ { type: "withTitle", required: true }
313
+ ]
314
+ }), "Label");
315
+
316
+ // src/collections/Language.ts
317
+ var Language = /* @__PURE__ */ __name((options2) => ({
318
+ type: "withStatic",
319
+ src: "https://actarian.github.io/cms-i18n-react/api/language.json",
320
+ slug: options2.slug.language,
321
+ fields: [
322
+ {
323
+ name: "id",
324
+ label: "ID",
325
+ type: "text"
326
+ },
327
+ {
328
+ name: "name",
329
+ label: "Name",
330
+ type: "text",
331
+ localized: true
332
+ },
333
+ {
334
+ name: "englishName",
335
+ label: "English Name",
336
+ type: "text"
337
+ },
338
+ {
339
+ name: "nativeName",
340
+ label: "Native Name",
341
+ type: "text"
342
+ }
343
+ ]
344
+ }), "Language");
345
+
346
+ // src/collections/Market.ts
347
+ var Market = /* @__PURE__ */ __name((options2) => ({
348
+ type: "withCollection",
349
+ slug: options2.slug.market,
350
+ admin: {
351
+ group: options2.group.config,
352
+ useAsTitle: "title",
353
+ defaultColumns: ["title", "id", "countries", "languages"]
354
+ },
355
+ fields: [
356
+ // inherited fields: id, createdAt, updatedAt
357
+ { type: "withId", required: true },
358
+ { type: "withTitle", required: true, localized: false },
359
+ { type: "withIsActive", required: true },
360
+ { type: "withIsDefault", required: true },
361
+ // !!! todo create a generic withRelation(slug.country) ?
362
+ {
363
+ name: "countries",
364
+ label: "Countries",
365
+ type: "relationship",
366
+ relationTo: options2.slug.country,
367
+ hasMany: true
368
+ },
369
+ {
370
+ name: "languages",
371
+ label: "Languages",
372
+ type: "relationship",
373
+ relationTo: options2.slug.language,
374
+ hasMany: true,
375
+ filterOptions: () => {
376
+ return {
377
+ "id": { in: options2.locales }
378
+ };
379
+ }
380
+ },
381
+ {
382
+ name: "defaultLanguage",
383
+ label: "Default language",
384
+ type: "relationship",
385
+ relationTo: options2.slug.language,
386
+ hasMany: false,
387
+ hooks: {
388
+ beforeChange: [({ data, value }) => {
389
+ const languages = data.languages;
390
+ if (languages && languages.length > 0)
391
+ return value;
392
+ return null;
393
+ }]
394
+ },
395
+ admin: {
396
+ condition: (data) => {
397
+ const languages = data.languages;
398
+ if (languages && languages.length > 0)
399
+ return true;
400
+ return false;
401
+ }
402
+ },
403
+ filterOptions: () => {
404
+ return {
405
+ "id": { in: options2.locales }
406
+ };
407
+ },
408
+ validate: async (val, { data }) => {
409
+ const languages = data.languages;
410
+ if (languages && languages.length > 0 && languages.indexOf(val) < 0) {
411
+ return "You must select a default language from the selected languages.";
412
+ }
413
+ return true;
414
+ }
415
+ }
416
+ ]
417
+ }), "Market");
418
+
419
+ // src/collections/Media.ts
420
+ var Media = /* @__PURE__ */ __name((options2) => ({
421
+ type: "withCollection",
422
+ slug: options2.slug.media,
423
+ admin: {
424
+ group: options2.group.content
425
+ // !!! todo defaultColumns
426
+ },
427
+ access: {
428
+ read: () => true
429
+ // Everyone can read Media
430
+ },
431
+ upload: {
432
+ adminThumbnail: "card",
433
+ imageSizes: [
434
+ {
435
+ name: "card",
436
+ width: 640,
437
+ height: 480
438
+ },
439
+ {
440
+ name: "feature",
441
+ width: 1024,
442
+ height: 576
443
+ }
444
+ ]
445
+ },
446
+ fields: [
447
+ // inherited fields: id, createdAt, updatedAt
448
+ // !!! todo convert to localized text
449
+ {
450
+ name: "alt",
451
+ label: "Alt Text",
452
+ type: "text",
453
+ required: true
454
+ }
455
+ ]
456
+ }), "Media");
457
+
458
+ // src/collections/Municipality.ts
459
+ var Municipality = /* @__PURE__ */ __name((options2) => ({
460
+ type: "withStatic",
461
+ src: "https://actarian.github.io/cms-i18n-react/api/municipality.json",
462
+ slug: options2.slug.municipality,
463
+ /*
464
+ map: {
465
+ countryId: 'country',
466
+ countryZoneId: 'countryZone',
467
+ regionId: 'region',
468
+ provinceId: 'province',
469
+ },
470
+ */
471
+ fields: [
472
+ {
473
+ name: "id",
474
+ label: "ID",
475
+ type: "text"
476
+ },
477
+ {
478
+ name: "name",
479
+ label: "Name",
480
+ type: "text"
481
+ },
482
+ {
483
+ name: "code",
484
+ label: "Code",
485
+ type: "text"
486
+ },
487
+ {
488
+ name: "country",
489
+ label: "Country",
490
+ type: "relationship",
491
+ relationTo: options2.slug.country,
492
+ hasMany: false,
493
+ required: true
494
+ },
495
+ {
496
+ name: "countryZone",
497
+ label: "Country Zone",
498
+ type: "relationship",
499
+ relationTo: options2.slug.countryZone,
500
+ hasMany: false,
501
+ required: true
502
+ },
503
+ {
504
+ name: "region",
505
+ label: "Region",
506
+ type: "relationship",
507
+ relationTo: options2.slug.region,
508
+ hasMany: false,
509
+ required: true
510
+ },
511
+ {
512
+ name: "province",
513
+ label: "Province",
514
+ type: "relationship",
515
+ relationTo: options2.slug.province,
516
+ hasMany: false,
517
+ required: true
518
+ }
519
+ ]
520
+ }), "Municipality");
521
+
522
+ // src/collections/Page.ts
523
+ var Page = /* @__PURE__ */ __name((options2) => ({
524
+ type: "withCollection",
525
+ slug: options2.slug.page,
526
+ admin: {
527
+ group: options2.group.nav
528
+ },
529
+ fields: [
530
+ {
531
+ name: "content",
532
+ label: "Content",
533
+ type: "relationship",
534
+ relationTo: options2.pages,
535
+ hasMany: false,
536
+ required: true,
537
+ admin: {
538
+ readOnly: true
539
+ }
540
+ }
541
+ ]
542
+ }), "Page");
543
+
544
+ // src/collections/Province.ts
545
+ var Province = /* @__PURE__ */ __name((options2) => ({
546
+ type: "withStatic",
547
+ src: "https://actarian.github.io/cms-i18n-react/api/province.json",
548
+ slug: options2.slug.province,
549
+ /*
550
+ map: {
551
+ countryId: 'country',
552
+ countryZoneId: 'countryZone',
553
+ regionId: 'region',
554
+ },
555
+ */
556
+ fields: [
557
+ {
558
+ name: "id",
559
+ label: "ID",
560
+ type: "text"
561
+ },
562
+ {
563
+ name: "name",
564
+ label: "Name",
565
+ type: "text"
566
+ },
567
+ {
568
+ name: "code",
569
+ label: "Code",
570
+ type: "text"
571
+ },
572
+ {
573
+ name: "country",
574
+ label: "Country",
575
+ type: "relationship",
576
+ relationTo: options2.slug.country,
577
+ hasMany: false,
578
+ required: true
579
+ },
580
+ {
581
+ name: "countryZone",
582
+ label: "Country Zone",
583
+ type: "relationship",
584
+ relationTo: options2.slug.countryZone,
585
+ hasMany: false,
586
+ required: true
587
+ },
588
+ {
589
+ name: "region",
590
+ label: "Region",
591
+ type: "relationship",
592
+ relationTo: options2.slug.region,
593
+ hasMany: false,
594
+ required: true
595
+ }
596
+ ]
597
+ }), "Province");
598
+
599
+ // src/collections/Region.ts
600
+ var Region = /* @__PURE__ */ __name((options2) => ({
601
+ type: "withStatic",
602
+ src: "https://actarian.github.io/cms-i18n-react/api/region.json",
603
+ slug: options2.slug.region,
604
+ /*
605
+ map: {
606
+ countryId: 'country',
607
+ countryZoneId: 'countryZone',
608
+ },
609
+ */
610
+ fields: [
611
+ {
612
+ name: "id",
613
+ label: "ID",
614
+ type: "text"
615
+ },
616
+ {
617
+ name: "name",
618
+ label: "Name",
619
+ type: "text"
620
+ },
621
+ {
622
+ name: "country",
623
+ label: "Country",
624
+ type: "relationship",
625
+ relationTo: options2.slug.country,
626
+ hasMany: false,
627
+ required: true
628
+ },
629
+ {
630
+ name: "countryZone",
631
+ label: "Country Zone",
632
+ type: "relationship",
633
+ relationTo: options2.slug.countryZone,
634
+ hasMany: false,
635
+ required: true
636
+ }
637
+ ]
638
+ }), "Region");
639
+
640
+ // src/collections/SubContinent.ts
641
+ var SubContinent = /* @__PURE__ */ __name((options2) => ({
642
+ type: "withStatic",
643
+ src: "https://actarian.github.io/cms-i18n-react/api/subContinent.json",
644
+ slug: options2.slug.subContinent,
645
+ /*
646
+ map: {
647
+ continentId: 'continent',
648
+ },
649
+ */
650
+ fields: [
651
+ {
652
+ name: "id",
653
+ label: "ID",
654
+ type: "text"
655
+ },
656
+ {
657
+ name: "name",
658
+ label: "Name",
659
+ type: "text"
660
+ },
661
+ {
662
+ name: "continent",
663
+ label: "Continent",
664
+ type: "relationship",
665
+ relationTo: options2.slug.continent,
666
+ hasMany: false,
667
+ required: true
668
+ }
669
+ ]
670
+ }), "SubContinent");
671
+
672
+ // src/collections/Template.ts
673
+ var Template = /* @__PURE__ */ __name((options2) => ({
674
+ type: "withCollection",
675
+ slug: options2.slug.template,
676
+ admin: {
677
+ group: options2.group.config,
678
+ useAsTitle: "name",
679
+ defaultColumns: ["name", "id"]
680
+ },
681
+ fields: [
682
+ // inherited fields: id, createdAt, updatedAt
683
+ { type: "withId", required: true },
684
+ { type: "withName", required: true },
685
+ // !!! todo withSelect ?
686
+ {
687
+ name: "compatibleCollections",
688
+ label: "Compatible pages",
689
+ type: "select",
690
+ hasMany: true,
691
+ admin: {
692
+ isClearable: true
693
+ },
694
+ options: options2.pages.map((slug) => {
695
+ return { value: slug, label: slug };
696
+ })
697
+ },
698
+ // !!! todo withCheckbox ?
699
+ {
700
+ name: "hasCompatibleCollections",
701
+ type: "checkbox",
702
+ admin: {
703
+ disabled: true
704
+ },
705
+ hooks: {
706
+ beforeChange: [
707
+ (args) => {
708
+ const { data } = args;
709
+ if (data.compatibleCollections && data.compatibleCollections.length > 0) {
710
+ return true;
711
+ } else {
712
+ return false;
713
+ }
714
+ }
715
+ ]
716
+ }
717
+ }
718
+ ]
719
+ }), "Template");
720
+
721
+ // src/core/api/cache.service.ts
722
+ var CACHE_DURATION = 5 * 60 * 1e3;
723
+ var InMemoryCache = class {
724
+ duration = CACHE_DURATION;
725
+ cache;
726
+ constructor(options2 = {}) {
727
+ this.duration = options2.duration || this.duration;
728
+ this.cache = /* @__PURE__ */ new Map();
729
+ }
730
+ has(key) {
731
+ return this.cache.has(key) && this.cache.get(key).timestamp > (/* @__PURE__ */ new Date()).getTime() - this.duration;
732
+ }
733
+ get(key) {
734
+ return this.cache.get(key).data;
735
+ }
736
+ set(key, data) {
737
+ this.cache.set(key, {
738
+ timestamp: (/* @__PURE__ */ new Date()).getTime(),
739
+ data
740
+ });
741
+ }
742
+ };
743
+ __name(InMemoryCache, "InMemoryCache");
744
+ function keyWithRequest(key, req) {
745
+ const segments = req.url.split("?");
746
+ return segments.length > 1 ? `${key}-${segments[1]}` : key;
747
+ }
748
+ __name(keyWithRequest, "keyWithRequest");
749
+
750
+ // src/core/api/collection.service.ts
751
+ async function getCollectionItems(req, slug) {
752
+ const { url, query, params, payload } = req;
753
+ const { locale, where, sort, depth, draft, page, limit, pagination } = query;
754
+ const response = await payload.find({
755
+ collection: slug,
756
+ draft: draft === "true",
757
+ locale,
758
+ where,
759
+ sort,
760
+ depth: parseInt(String(depth), 10),
761
+ limit: 1e4,
762
+ pagination: false
763
+ });
764
+ const items = response.docs ? response.docs : [];
765
+ return items;
766
+ }
767
+ __name(getCollectionItems, "getCollectionItems");
768
+ var collectionGet = /* @__PURE__ */ __name((slug) => ({
769
+ path: "/",
770
+ method: "get",
771
+ handler: async (req, res, next) => {
772
+ const { query } = req;
773
+ const { pagination } = query;
774
+ if (pagination !== "false") {
775
+ return next();
776
+ }
777
+ try {
778
+ const items = await getCollectionItems(req, slug);
779
+ res.status(200).send(items);
780
+ } catch (error) {
781
+ console.log("collectionGet.error", error);
782
+ res.status(500).send(error);
783
+ }
784
+ }
785
+ }), "collectionGet");
786
+
787
+ // src/translations.ts
788
+ var translations = {
789
+ en: {
790
+ group: {
791
+ content: "Content",
792
+ nav: "Navigation",
793
+ config: "Configuration",
794
+ i18n: "I18N",
795
+ admin: "Admin"
796
+ },
797
+ collection: {
798
+ singular: {
799
+ category: "Category",
800
+ color: "Color",
801
+ country: "Country",
802
+ label: "Label",
803
+ language: "Language",
804
+ market: "Market",
805
+ media: "Media",
806
+ page: "Page",
807
+ province: "Province",
808
+ region: "Region",
809
+ template: "Template",
810
+ users: "User",
811
+ i18n_continent: "Continent",
812
+ i18n_country_zone: "Country Zone",
813
+ i18n_country: "Country",
814
+ i18n_language: "Language",
815
+ i18n_municipality: "Municipality",
816
+ i18n_province: "Province",
817
+ i18n_region: "Region",
818
+ i18n_sub_continent: "Subcontinent"
819
+ },
820
+ plural: {
821
+ category: "Categories",
822
+ color: "Colors",
823
+ country: "Countries",
824
+ label: "Labels",
825
+ language: "Languages",
826
+ market: "Markets",
827
+ media: "Medias",
828
+ page: "Pages",
829
+ province: "Provinces",
830
+ region: "Regions",
831
+ template: "Templates",
832
+ users: "Users",
833
+ i18n_continent: "Continents",
834
+ i18n_country_zone: "Country Zones",
835
+ i18n_country: "Countries",
836
+ i18n_language: "Languages",
837
+ i18n_municipality: "Municipalities",
838
+ i18n_province: "Provinces",
839
+ i18n_region: "Regions",
840
+ i18n_sub_continent: "Subcontinents"
841
+ }
842
+ },
843
+ global: {
844
+ locale: "Locales"
845
+ },
846
+ field: {
847
+ alpha2Code: "Alpha2 Code",
848
+ alpha3Code: "Alpha3 Code",
849
+ abstract: "Abstract",
850
+ alt: "Alt",
851
+ appearance: "Appearance",
852
+ blocks: "Blocks",
853
+ category: "Category",
854
+ category_index: "Index of Category",
855
+ code: "Code",
856
+ color: "Color",
857
+ compatibleCollections: "Collections",
858
+ content: "Content",
859
+ continent: "Continent",
860
+ countries: "Countries",
861
+ country: "Country",
862
+ countryZone: "Country Zone",
863
+ date: "Date",
864
+ description: "Description",
865
+ englishName: "English Name",
866
+ hasCompatibleCollections: "Has Compatible Collections",
867
+ href: "Href",
868
+ id: "ID",
869
+ isActive: "Active",
870
+ isDefault: "Is Default",
871
+ items: "Items",
872
+ label: "Label",
873
+ language: "Language",
874
+ languages: "Languages",
875
+ defaultLanguage: "Default Language",
876
+ link: "Link",
877
+ markets: "Markets",
878
+ media: "Media",
879
+ medias: "Medias",
880
+ name: "Name",
881
+ nativeName: "Native Name",
882
+ newTab: "New Tab",
883
+ price: "Price",
884
+ province: "Province",
885
+ reference: "Reference",
886
+ region: "Region",
887
+ slug: "Slug",
888
+ subContinent: "Subcontinent",
889
+ template: "Template",
890
+ title: "Title",
891
+ type: "Type",
892
+ url: "Url"
893
+ },
894
+ localizedField: {
895
+ changeLocalization: "Change localization",
896
+ saveDocument: "Save document to enable localizations",
897
+ referenceLanguage: "Reference language {{locale}}"
898
+ },
899
+ // override existing translation keys
900
+ general: {
901
+ // dashboard: 'Dashboard',
902
+ }
903
+ },
904
+ it: {
905
+ group: {
906
+ content: "Contenuti",
907
+ nav: "Navigazione",
908
+ config: "Configurazione",
909
+ i18n: "I18N",
910
+ admin: "Admin"
911
+ },
912
+ collection: {
913
+ singular: {
914
+ category: "Categoria",
915
+ color: "Colore",
916
+ country: "Nazione",
917
+ label: "Etichetta",
918
+ language: "Lingua",
919
+ market: "Mercato",
920
+ media: "Media",
921
+ page: "Pagina",
922
+ province: "Provincia",
923
+ region: "Regione",
924
+ template: "Template",
925
+ users: "Utente",
926
+ i18n_continent: "Continente",
927
+ i18n_country_zone: "Area Nazionale",
928
+ i18n_country: "Nazione",
929
+ i18n_language: "Lingua",
930
+ i18n_municipality: "Comune",
931
+ i18n_province: "Provincia",
932
+ i18n_region: "Regione",
933
+ i18n_sub_continent: "Subcontinente"
934
+ },
935
+ plural: {
936
+ category: "Categorie",
937
+ color: "Colori",
938
+ country: "Nazioni",
939
+ label: "Etichette",
940
+ language: "Lingue",
941
+ login: "Login",
942
+ market: "Mercati",
943
+ media: "Media",
944
+ page: "Pagine",
945
+ province: "Province",
946
+ region: "Regioni",
947
+ template: "Templates",
948
+ users: "Utenti",
949
+ i18n_continent: "Continenti",
950
+ i18n_country_zone: "Aree Nazionali",
951
+ i18n_country: "Nazioni",
952
+ i18n_language: "Lingue",
953
+ i18n_municipality: "Comuni",
954
+ i18n_province: "Province",
955
+ i18n_region: "Regioni",
956
+ i18n_sub_continent: "Subcontinenti"
957
+ }
958
+ },
959
+ global: {
960
+ locale: "Localizzazioni"
961
+ },
962
+ field: {
963
+ alpha2Code: "Codice Alpha2",
964
+ alpha3Code: "Codice Alpha3",
965
+ abstract: "Abstract",
966
+ alt: "Testo Alternativo",
967
+ appearance: "Aspetto",
968
+ blocks: "Blocchi",
969
+ category: "Categoria",
970
+ category_index: "Indice di Categoria",
971
+ code: "Codice",
972
+ color: "Colore",
973
+ compatibleCollections: "Collezioni",
974
+ content: "Contenuto",
975
+ continent: "Continente",
976
+ countries: "Nazioni",
977
+ country: "Nazione",
978
+ countryZone: "Area Nazionale",
979
+ date: "Data",
980
+ description: "Descrizione",
981
+ englishName: "Nome Inglese",
982
+ hasCompatibleCollections: "Ha Collezioni Compatibili",
983
+ href: "Href",
984
+ id: "ID",
985
+ isActive: "Attivo",
986
+ isDefault: "Valore di Default",
987
+ items: "Elementi",
988
+ label: "Etichetta",
989
+ language: "Lingua",
990
+ languages: "Lingue",
991
+ defaultLanguage: "Lingua di Default",
992
+ link: "Link",
993
+ markets: "Mercati",
994
+ media: "Media",
995
+ medias: "Media",
996
+ name: "Nome",
997
+ nativeName: "Nome Nativo",
998
+ newTab: "Nuovo Tab",
999
+ price: "Prezzo",
1000
+ province: "Provincia",
1001
+ reference: "Riferimento",
1002
+ region: "Regione",
1003
+ slug: "Slug",
1004
+ subContinent: "Subcontinente",
1005
+ template: "Template",
1006
+ title: "Titolo",
1007
+ type: "Tipo",
1008
+ url: "Url"
1009
+ },
1010
+ localizedField: {
1011
+ changeLocalization: "Modifica localizzazione",
1012
+ saveDocument: "Salva il documento per abilitare le modifiche",
1013
+ referenceLanguage: "Lingua di riferimento {{locale}}"
1014
+ },
1015
+ // override existing translation keys
1016
+ general: {
1017
+ // dashboard: 'Dashboard',
1018
+ }
1019
+ }
1020
+ };
1021
+
1022
+ // src/options.ts
1023
+ var defaultSlug = {
1024
+ category: "category",
1025
+ label: "label",
1026
+ locale: "locale",
1027
+ market: "market",
1028
+ media: "media",
1029
+ page: "page",
1030
+ template: "template",
1031
+ //
1032
+ continent: "i18n_continent",
1033
+ country: "i18n_country",
1034
+ countryZone: "i18n_country_zone",
1035
+ language: "i18n_language",
1036
+ municipality: "i18n_municipality",
1037
+ province: "i18n_province",
1038
+ region: "i18n_region",
1039
+ subContinent: "i18n_sub_continent"
1040
+ };
1041
+ var defaultGroup = {
1042
+ content: "content",
1043
+ nav: "nav",
1044
+ config: "config",
1045
+ i18n: "i18n",
1046
+ admin: "admin"
1047
+ };
1048
+ var defaultLocales = ["en", "it"];
1049
+ var defaultLocale = "en";
1050
+ var options = {
1051
+ collections: [],
1052
+ defaultLocale,
1053
+ group: defaultGroup,
1054
+ locales: defaultLocales,
1055
+ pages: [],
1056
+ slug: defaultSlug,
1057
+ translations
1058
+ };
1059
+ var internalSlugs = Object.entries(defaultSlug).map((x) => x[1]);
1060
+
1061
+ // src/fields/ui-languages/UILanguagesCell.tsx
1062
+ var import_jsx_runtime = require("react/jsx-runtime");
1063
+ var UILanguagesCell = /* @__PURE__ */ __name(({ cellData, colIndex, collection, field, rowData }) => {
1064
+ if (!cellData)
1065
+ return null;
1066
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: cellData.toString() });
1067
+ }, "UILanguagesCell");
1068
+
1069
+ // src/fields/ui-languages/UILanguagesField.tsx
1070
+ var import_utilities = require("payload/components/utilities");
1071
+ var import_qs2 = __toESM(require("qs"));
1072
+ var import_react_router_dom2 = require("react-router-dom");
1073
+
1074
+ // src/fields/ui-languages/useSearchParams.tsx
1075
+ var import_qs = __toESM(require("qs"));
1076
+ var import_react = require("react");
1077
+ var import_react_router_dom = require("react-router-dom");
1078
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1079
+ var Context = (0, import_react.createContext)({});
1080
+ var useSearchParams = /* @__PURE__ */ __name(() => {
1081
+ const location = (0, import_react_router_dom.useLocation)();
1082
+ const params = import_qs.default.parse(
1083
+ location.search,
1084
+ { ignoreQueryPrefix: true, depth: 10 }
1085
+ );
1086
+ return params;
1087
+ }, "useSearchParams");
1088
+
1089
+ // src/fields/ui-languages/UILanguagesField.tsx
1090
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1091
+ var baseClass = "ui-languages";
1092
+ var UILanguagesField = /* @__PURE__ */ __name((props) => {
1093
+ const searchParams = useSearchParams();
1094
+ const { localization } = (0, import_utilities.useConfig)();
1095
+ const currentLocale = (0, import_utilities.useLocale)();
1096
+ const locales = localization ? localization.locales : [];
1097
+ const otherLocales = locales.filter((x) => x !== currentLocale);
1098
+ const documentInfo = (0, import_utilities.useDocumentInfo)();
1099
+ if (!localization) {
1100
+ return null;
1101
+ }
1102
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `${baseClass}`, children: [
1103
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `${baseClass}__head`, children: [
1104
+ documentInfo.id ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${baseClass}__badge`, children: documentInfo.id }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${baseClass}__badge`, children: "Unsaved document" }),
1105
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${baseClass}__badge uppercase`, children: currentLocale })
1106
+ ] }),
1107
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `${baseClass}__locales`, children: otherLocales.map((locale) => {
1108
+ const newParams = {
1109
+ ...searchParams,
1110
+ locale
1111
+ };
1112
+ const search = import_qs2.default.stringify(newParams);
1113
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_router_dom2.Link, { className: "btn", to: { search }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "btn__label", children: locale }) }, locale);
1114
+ }) })
1115
+ ] });
1116
+ }, "UILanguagesField");
1117
+
1118
+ // src/fields/ui-languages/index.ts
1119
+ var withUILanguages = /* @__PURE__ */ __name((options2 = {}) => {
1120
+ const baseOptions = {
1121
+ name: "uiLanguages",
1122
+ type: "ui",
1123
+ admin: {
1124
+ components: {
1125
+ Field: UILanguagesField,
1126
+ Cell: UILanguagesCell
1127
+ }
1128
+ }
1129
+ };
1130
+ return deepMerge(
1131
+ baseOptions,
1132
+ options2
1133
+ );
1134
+ }, "withUILanguages");
1135
+
1136
+ // src/fields/localized-field/LocalizedField.tsx
1137
+ var import_modal2 = require("@faceless-ui/modal");
1138
+ var import_components2 = require("payload/components");
1139
+ var import_utilities5 = require("payload/components/utilities");
1140
+ var import_react7 = require("react");
1141
+ var import_react_i18next5 = require("react-i18next");
1142
+
1143
+ // src/fields/localized-field/LocalizedFieldModal.tsx
1144
+ var import_modal = require("@faceless-ui/modal");
1145
+ var import_components = require("payload/components");
1146
+ var import_forms4 = require("payload/components/forms");
1147
+ var import_utilities4 = require("payload/components/utilities");
1148
+ var import_field_types = __toESM(require("payload/dist/admin/components/forms/field-types"));
1149
+ var import_react6 = require("react");
1150
+ var import_react_i18next4 = require("react-i18next");
1151
+ var import_react_toastify = require("react-toastify");
1152
+
1153
+ // src/fields/localized-field/Publish/Publish.tsx
1154
+ var import_forms = require("payload/components/forms");
1155
+ var import_utilities2 = require("payload/components/utilities");
1156
+ var import_Submit = __toESM(require("payload/dist/admin/components/forms/Submit"));
1157
+ var import_react2 = require("react");
1158
+ var import_react_i18next = require("react-i18next");
1159
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1160
+ var Publish = /* @__PURE__ */ __name(() => {
1161
+ const { unpublishedVersions, publishedDoc } = (0, import_utilities2.useDocumentInfo)();
1162
+ const { submit } = (0, import_forms.useForm)();
1163
+ const modified = (0, import_forms.useFormModified)();
1164
+ const { t } = (0, import_react_i18next.useTranslation)("version");
1165
+ const hasNewerVersions = unpublishedVersions?.totalDocs > 0;
1166
+ const canPublish = modified || hasNewerVersions || !publishedDoc;
1167
+ const publish = (0, import_react2.useCallback)(() => {
1168
+ submit({
1169
+ overrides: {
1170
+ _status: "published"
1171
+ }
1172
+ });
1173
+ }, [submit]);
1174
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_Submit.default, { type: "button", disabled: !canPublish, onClick: publish, children: t("publishChanges") });
1175
+ }, "Publish");
1176
+
1177
+ // src/fields/localized-field/RichTextSerializer.tsx
1178
+ var import_escape_html = __toESM(require("escape-html"));
1179
+ var import_react3 = require("react");
1180
+ var import_slate = require("slate");
1181
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1182
+ var baseClass2 = "wysiwyg";
1183
+ var RichTextSerializer = /* @__PURE__ */ __name(({ value }) => {
1184
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: baseClass2, children: Serializer(value) });
1185
+ }, "RichTextSerializer");
1186
+ function Serializer(children) {
1187
+ return children.map((node, i) => {
1188
+ if (import_slate.Text.isText(node)) {
1189
+ let text = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { dangerouslySetInnerHTML: { __html: (0, import_escape_html.default)(node.text) } });
1190
+ if (node.bold) {
1191
+ text = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: text }, i);
1192
+ }
1193
+ if (node.code) {
1194
+ text = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: text }, i);
1195
+ }
1196
+ if (node.italic) {
1197
+ text = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: text }, i);
1198
+ }
1199
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react3.Fragment, { children: text }, i);
1200
+ }
1201
+ if (!node) {
1202
+ return null;
1203
+ }
1204
+ switch (node.type) {
1205
+ case "h1":
1206
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { children: Serializer(node.children) }, i);
1207
+ case "h6":
1208
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h6", { children: Serializer(node.children) }, i);
1209
+ case "quote":
1210
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("blockquote", { children: Serializer(node.children) }, i);
1211
+ case "ul":
1212
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { children: Serializer(node.children) }, i);
1213
+ case "ol":
1214
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ol", { children: Serializer(node.children) }, i);
1215
+ case "li":
1216
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: Serializer(node.children) }, i);
1217
+ case "link":
1218
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1219
+ "a",
1220
+ {
1221
+ href: (0, import_escape_html.default)(node.url),
1222
+ children: Serializer(node.children)
1223
+ },
1224
+ i
1225
+ );
1226
+ default:
1227
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: Serializer(node.children) }, i);
1228
+ }
1229
+ });
1230
+ }
1231
+ __name(Serializer, "Serializer");
1232
+
1233
+ // src/fields/localized-field/Save/Save.tsx
1234
+ var import_forms2 = require("payload/components/forms");
1235
+ var import_Submit2 = __toESM(require("payload/dist/admin/components/forms/Submit"));
1236
+ var import_react4 = require("react");
1237
+ var import_react_i18next2 = require("react-i18next");
1238
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1239
+ var Save = /* @__PURE__ */ __name(() => {
1240
+ const { submit } = (0, import_forms2.useForm)();
1241
+ const modified = (0, import_forms2.useFormModified)();
1242
+ const { t } = (0, import_react_i18next2.useTranslation)("general");
1243
+ const canSave = modified;
1244
+ const publish = (0, import_react4.useCallback)(() => {
1245
+ submit();
1246
+ }, [submit]);
1247
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_Submit2.default, { type: "button", disabled: !canSave, onClick: publish, children: t("save") });
1248
+ }, "Save");
1249
+
1250
+ // src/fields/localized-field/SaveDraft/SaveDraft.tsx
1251
+ var import_forms3 = require("payload/components/forms");
1252
+ var import_utilities3 = require("payload/components/utilities");
1253
+ var import_Submit3 = __toESM(require("payload/dist/admin/components/forms/Submit"));
1254
+ var import_react5 = require("react");
1255
+ var import_react_i18next3 = require("react-i18next");
1256
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1257
+ var baseClass3 = "save-draft";
1258
+ var SaveDraft = /* @__PURE__ */ __name(() => {
1259
+ const { serverURL, routes: { api } } = (0, import_utilities3.useConfig)();
1260
+ const { submit } = (0, import_forms3.useForm)();
1261
+ const { collection, global, id } = (0, import_utilities3.useDocumentInfo)();
1262
+ const modified = (0, import_forms3.useFormModified)();
1263
+ const { t } = (0, import_react_i18next3.useTranslation)("version");
1264
+ const locale = (0, import_utilities3.useLocale)();
1265
+ const canSaveDraft = modified;
1266
+ const saveDraft = (0, import_react5.useCallback)(() => {
1267
+ const search = `?locale=${locale}&depth=0&fallback-locale=null&draft=true`;
1268
+ let action;
1269
+ let method = "POST";
1270
+ if (collection) {
1271
+ action = `${serverURL}${api}/${collection.slug}${id ? `/${id}` : ""}${search}`;
1272
+ if (id)
1273
+ method = "PATCH";
1274
+ }
1275
+ if (global) {
1276
+ action = `${serverURL}${api}/globals/${global.slug}${search}`;
1277
+ }
1278
+ submit({
1279
+ action,
1280
+ method,
1281
+ skipValidation: true,
1282
+ overrides: {
1283
+ _status: "draft"
1284
+ }
1285
+ });
1286
+ }, [submit, collection, global, serverURL, api, locale, id]);
1287
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_Submit3.default, { className: baseClass3, type: "button", buttonStyle: "secondary", disabled: !canSaveDraft, onClick: saveDraft, children: t("saveDraft") });
1288
+ }, "SaveDraft");
1289
+
1290
+ // src/fields/localized-field/LocalizedFieldModal.tsx
1291
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1292
+ var DEBUG = false;
1293
+ var baseClass4 = "localized-field";
1294
+ var getTranslation = /* @__PURE__ */ __name((label, i18n) => {
1295
+ if (typeof label === "object") {
1296
+ if (label[i18n.language]) {
1297
+ return label[i18n.language];
1298
+ }
1299
+ let fallbacks = [];
1300
+ if (typeof i18n.options.fallbackLng === "string") {
1301
+ fallbacks = [i18n.options.fallbackLng];
1302
+ } else if (Array.isArray(i18n.options.fallbackLng)) {
1303
+ fallbacks = i18n.options.fallbackLng;
1304
+ } else if (typeof i18n.options.fallbackLng === "object") {
1305
+ fallbacks = Object.keys(i18n.options.fallbackLng);
1306
+ } else if (typeof i18n.options.fallbackLng === "function") {
1307
+ console.warn("Use of i18next fallbackLng functions are not supported.");
1308
+ }
1309
+ return label[fallbacks.find((language) => label[language])] ?? label[Object.keys(label)[0]];
1310
+ }
1311
+ return label;
1312
+ }, "getTranslation");
1313
+ var LocalizedFieldModal = /* @__PURE__ */ __name((schema) => {
1314
+ const { t } = (0, import_react_i18next4.useTranslation)("localizedField");
1315
+ const { path, label } = schema;
1316
+ const { closeAllModals } = (0, import_modal.useModal)();
1317
+ const { i18n } = (0, import_react_i18next4.useTranslation)();
1318
+ const config = (0, import_utilities4.useConfig)();
1319
+ const locales = config.localization ? config.localization.locales : [];
1320
+ const defaultLocale2 = config.localization ? config.localization.defaultLocale : null;
1321
+ const initialLocale = (0, import_utilities4.useLocale)();
1322
+ const documentInfo = (0, import_utilities4.useDocumentInfo)();
1323
+ const { id, collection, global } = documentInfo;
1324
+ const field = (0, import_forms4.useFormFields)(([fields]) => fields[path]);
1325
+ const dispatchField = (0, import_forms4.useFormFields)(([_, dispatch]) => dispatch);
1326
+ const [referenceValue, setReferenceValue] = (0, import_react6.useState)(field.value);
1327
+ const [referenceLocale, setReferenceLocale] = (0, import_react6.useState)(initialLocale);
1328
+ const [currentLocale, setCurrentLocale] = (0, import_react6.useState)(initialLocale);
1329
+ const [initialJson, setInitialJson] = (0, import_react6.useState)(null);
1330
+ const [currentJson, setCurrentJson] = (0, import_react6.useState)({});
1331
+ const [emptyLocales, setEmptyLocales] = (0, import_react6.useState)([]);
1332
+ const [filledInLocales, setFilledInLocales] = (0, import_react6.useState)([]);
1333
+ const FieldComponent = import_field_types.default[schema.type];
1334
+ const saveLocale = /* @__PURE__ */ __name(async (locale, json = currentJson, status = "draft") => {
1335
+ try {
1336
+ const search = `?depth=0&locale=${locale}&fallback-locale=null${status === "draft" ? "&draft=true" : ""}`;
1337
+ let url;
1338
+ if (collection) {
1339
+ url = `${config.serverURL}${config.routes.api}/${collection.slug}/${id}${search}`;
1340
+ }
1341
+ if (global) {
1342
+ url = `${config.serverURL}${config.routes.api}/globals/${global.slug}${search}`;
1343
+ }
1344
+ const httpGetResponse = await fetch(url, {
1345
+ method: "GET",
1346
+ headers: {
1347
+ "Content-Type": "application/json"
1348
+ }
1349
+ });
1350
+ if (!httpGetResponse.ok) {
1351
+ throw httpGetResponse;
1352
+ }
1353
+ const localizedDocument = await httpGetResponse.json();
1354
+ const payload = setPathPayload(path, localizedDocument, json[locale]);
1355
+ payload._status = status;
1356
+ if (DEBUG) {
1357
+ console.log("LocalizedFieldModal.saveLocale", path, url, payload);
1358
+ return payload;
1359
+ }
1360
+ const httpResponse = await fetch(url, {
1361
+ method: "PATCH",
1362
+ body: JSON.stringify(payload),
1363
+ headers: {
1364
+ "Content-Type": "application/json"
1365
+ }
1366
+ });
1367
+ if (!httpResponse.ok) {
1368
+ throw httpResponse;
1369
+ }
1370
+ const response = await httpResponse.json();
1371
+ return response;
1372
+ } catch (error) {
1373
+ console.log("LocalizedFieldModal.saveLocale.error", error);
1374
+ }
1375
+ }, "saveLocale");
1376
+ const localeDidChange = /* @__PURE__ */ __name((locale, json = currentJson) => {
1377
+ if (json[locale] === initialJson[locale]) {
1378
+ return false;
1379
+ }
1380
+ return true;
1381
+ }, "localeDidChange");
1382
+ (0, import_react6.useEffect)(() => {
1383
+ const getData = /* @__PURE__ */ __name(async () => {
1384
+ try {
1385
+ const search = "?depth=0&locale=*&draft=true";
1386
+ let url;
1387
+ if (collection) {
1388
+ url = `${config.serverURL}${config.routes.api}/${collection.slug}/${id}${search}`;
1389
+ }
1390
+ if (global) {
1391
+ url = `${config.serverURL}${config.routes.api}/globals/${global.slug}${search}`;
1392
+ }
1393
+ const httpResponse = await fetch(url, {
1394
+ method: "GET",
1395
+ headers: {
1396
+ "Content-Type": "application/json"
1397
+ }
1398
+ });
1399
+ if (!httpResponse.ok) {
1400
+ throw httpResponse;
1401
+ }
1402
+ const document = await httpResponse.json();
1403
+ const json = getPathValue(path, document) || {};
1404
+ json[initialLocale] = field.value;
1405
+ setInitialJson(json);
1406
+ setCurrentJson(json);
1407
+ const emptyLocales2 = locales.filter((locale) => {
1408
+ return json[locale] === void 0;
1409
+ });
1410
+ sortByLocale(emptyLocales2, initialLocale);
1411
+ setEmptyLocales(emptyLocales2);
1412
+ const filledInLocales2 = locales.filter((locale) => {
1413
+ return json[locale] !== void 0;
1414
+ });
1415
+ sortByLocale(filledInLocales2, initialLocale);
1416
+ setFilledInLocales(filledInLocales2);
1417
+ const reference = getReference(json, defaultLocale2, initialLocale, locales);
1418
+ setReferenceValue(reference.value);
1419
+ setReferenceLocale(reference.locale);
1420
+ } catch (error) {
1421
+ console.log("LocalizedFieldModal.error", error);
1422
+ }
1423
+ }, "getData");
1424
+ getData();
1425
+ }, []);
1426
+ const onChangeSelectedLocale = /* @__PURE__ */ __name(async (locale) => {
1427
+ setCurrentLocale(locale);
1428
+ }, "onChangeSelectedLocale");
1429
+ const onAddSelectedLocale = /* @__PURE__ */ __name(async (locale) => {
1430
+ const filledIns = [...filledInLocales];
1431
+ filledIns.push(locale);
1432
+ sortByLocale(filledIns, initialLocale);
1433
+ setFilledInLocales(filledIns);
1434
+ const empties = [...emptyLocales];
1435
+ empties.splice(empties.indexOf(locale), 1);
1436
+ setEmptyLocales(empties);
1437
+ sortByLocale(empties, initialLocale);
1438
+ setCurrentLocale(locale);
1439
+ }, "onAddSelectedLocale");
1440
+ const onSubmit = /* @__PURE__ */ __name(async (fields, data) => {
1441
+ const json = currentJson;
1442
+ if (localeDidChange(initialLocale, json)) {
1443
+ dispatchField({
1444
+ type: "UPDATE",
1445
+ path,
1446
+ value: json[initialLocale]
1447
+ });
1448
+ }
1449
+ try {
1450
+ const promises = locales.filter((x) => localeDidChange(x, json)).map((x) => () => saveLocale(x, json, data._status));
1451
+ const responses = [];
1452
+ for (const promise of promises) {
1453
+ const response = await promise();
1454
+ responses.push(response);
1455
+ }
1456
+ import_react_toastify.toast.success(data._status === "draft" ? "Draft saved successfully." : "Updated successfully.");
1457
+ closeAllModals();
1458
+ } catch (error) {
1459
+ import_react_toastify.toast.error(`There was an error while saving ${collection ? `${collection.slug} ${id}` : global.slug}.`);
1460
+ }
1461
+ }, "onSubmit");
1462
+ const onClose = /* @__PURE__ */ __name(() => {
1463
+ closeAllModals();
1464
+ }, "onClose");
1465
+ const initialFormData = (0, import_react6.useMemo)(() => currentJson, [currentLocale, initialJson]);
1466
+ const fieldOptions = (0, import_react6.useMemo)(() => ({
1467
+ ...schema,
1468
+ validate: (value, args) => {
1469
+ if (args.operation === "update") {
1470
+ setCurrentJson(args.siblingData);
1471
+ }
1472
+ if (typeof schema.validate === "function") {
1473
+ return schema.validate(value, args);
1474
+ }
1475
+ return true;
1476
+ },
1477
+ path: currentLocale,
1478
+ fieldTypes: import_field_types.default
1479
+ }), [currentLocale, initialJson]);
1480
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_components.MinimalTemplate, { children: [
1481
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("header", { className: `${baseClass4}__header`, children: [
1482
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("h3", { children: [
1483
+ label && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: getTranslation(label, i18n) }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: `${baseClass4}__locale`, children: initialLocale }),
1485
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M7.961 7.5h1.303l2.47 6.5h-1.349l-.538-1.5h-2.438l-.535 1.5h-1.392l2.479-6.5zm1.517 3.965l-.857-2.451-.851 2.451h1.708zm8.092-1.402c.062-.243.1-.426.135-.605l-1.1-.214-.109.5c-.371-.054-.767-.061-1.166-.021.009-.268.025-.531.049-.784h1.229v-1.042h-1.081c.054-.265.099-.424.144-.575l-1.074-.322c-.079.263-.145.521-.211.897h-1.226v1.042h1.092c-.028.337-.046.686-.051 1.038-1.207.443-1.719 1.288-1.719 2.054 0 .904.714 1.7 1.842 1.598 1.401-.128 2.337-1.186 2.885-2.487.567.327.805.876.591 1.385-.197.471-.78.919-1.892.896v1.121c1.234.019 2.448-.45 2.925-1.583.465-1.108-.066-2.318-1.263-2.898zm-1.446.766c-.175.387-.404.771-.697 1.075-.045-.323-.076-.676-.093-1.054.268-.035.537-.041.79-.021zm-1.894.362c.03.473.084.909.158 1.298-.997.183-1.037-.801-.158-1.298zm-2.23-8.191c5.514 0 10 3.592 10 8.007 0 4.917-5.145 7.961-9.91 7.961-1.937 0-3.384-.397-4.394-.644-1 .613-1.594 1.037-4.272 1.82.535-1.373.722-2.748.601-4.265-.837-1-2.025-2.4-2.025-4.872 0-4.415 4.486-8.007 10-8.007zm0-2c-6.338 0-12 4.226-12 10.007 0 2.05.739 4.063 2.047 5.625.055 1.83-1.023 4.456-1.993 6.368 2.602-.47 6.301-1.508 7.978-2.536 1.417.345 2.774.503 4.059.503 7.083 0 11.91-4.837 11.91-9.961-.001-5.811-5.702-10.006-12.001-10.006z" }) })
1486
+ ] }),
1487
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Button, { buttonStyle: "none", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.X, {}) })
1488
+ ] }),
1489
+ initialJson ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("main", { className: `${baseClass4}__main`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_forms4.Form, { onSubmit, initialData: initialFormData, children: [
1490
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `${baseClass4}__locales`, children: [
1491
+ filledInLocales.map((locale) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Button, { className: locale === currentLocale ? "active filled" : "filled", buttonStyle: "none", onClick: () => onChangeSelectedLocale(locale), children: locale }, locale)),
1492
+ emptyLocales.map((locale) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Button, { className: locale === currentLocale ? "active empty" : "empty", buttonStyle: "none", onClick: () => onAddSelectedLocale(locale), children: locale }, locale))
1493
+ ] }),
1494
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FieldComponent, { ...fieldOptions }, currentLocale),
1495
+ referenceValue && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1496
+ (schema.type === "text" || schema.type === "richText") && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${baseClass4}__reference`, children: t("referenceLanguage", { locale: referenceLocale.toUpperCase() }) }),
1497
+ schema.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${baseClass4}__preview`, children: referenceValue }),
1498
+ schema.type === "richText" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${baseClass4}__preview`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(RichTextSerializer, { value: referenceValue }) })
1499
+ ] }),
1500
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${baseClass4}__foot`, children: collection?.versions?.drafts || global?.versions?.drafts ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1501
+ !(collection?.versions?.drafts && collection.versions.drafts.autosave) && !(global?.versions?.drafts && global.versions.drafts.autosave) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SaveDraft, {}),
1502
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Publish, {})
1503
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Save, {}) })
1504
+ ] }) }) : null
1505
+ ] });
1506
+ }, "LocalizedFieldModal");
1507
+ function getReference(json, defaultLocale2, initialLocale, locales) {
1508
+ const reference = { locale: initialLocale, value: json[initialLocale] };
1509
+ if (!json[initialLocale]) {
1510
+ if (json[defaultLocale2]) {
1511
+ reference.locale = defaultLocale2;
1512
+ reference.value = json[defaultLocale2];
1513
+ } else {
1514
+ const fallbackLocale = locales.find((l) => json[l]);
1515
+ if (fallbackLocale) {
1516
+ reference.locale = fallbackLocale;
1517
+ reference.value = json[fallbackLocale];
1518
+ }
1519
+ }
1520
+ }
1521
+ return reference;
1522
+ }
1523
+ __name(getReference, "getReference");
1524
+ function getPathValue(pathOrPaths, object) {
1525
+ const paths = Array.isArray(pathOrPaths) ? pathOrPaths : pathOrPaths.split(".");
1526
+ if (paths.length === 1) {
1527
+ return object[paths[0]];
1528
+ } else {
1529
+ const path = paths.shift();
1530
+ return getPathValue(paths, object[path]);
1531
+ }
1532
+ }
1533
+ __name(getPathValue, "getPathValue");
1534
+ function setPathPayload(pathOrPaths, object, value, payload = {}) {
1535
+ const paths = Array.isArray(pathOrPaths) ? pathOrPaths : pathOrPaths.split(".");
1536
+ if (paths.length === 1) {
1537
+ const leafPath = paths[0];
1538
+ if (Array.isArray(value)) {
1539
+ payload[leafPath] = [...value];
1540
+ } else if (typeof value === "object") {
1541
+ payload[leafPath] = { ...value };
1542
+ } else if (value != null) {
1543
+ payload[leafPath] = value;
1544
+ }
1545
+ } else {
1546
+ const path = paths.shift();
1547
+ const subObject = object[path];
1548
+ let subPayload;
1549
+ if (Array.isArray(subObject)) {
1550
+ subPayload = [...subObject];
1551
+ } else if (typeof subObject === "object") {
1552
+ subPayload = { ...subObject };
1553
+ } else {
1554
+ throw "invalid data";
1555
+ }
1556
+ payload[path] = subPayload;
1557
+ setPathPayload(paths, subObject, value, subPayload);
1558
+ }
1559
+ return payload;
1560
+ }
1561
+ __name(setPathPayload, "setPathPayload");
1562
+ function sortByLocale(locales, locale) {
1563
+ locales.sort((a, b) => {
1564
+ if (a === locale) {
1565
+ return -1;
1566
+ } else if (b === locale) {
1567
+ return 1;
1568
+ } else {
1569
+ return a.localeCompare(b);
1570
+ }
1571
+ });
1572
+ }
1573
+ __name(sortByLocale, "sortByLocale");
1574
+
1575
+ // src/fields/localized-field/LocalizedField.tsx
1576
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1577
+ var baseClass5 = "localized-field";
1578
+ var LocalizedField = /* @__PURE__ */ __name((props) => {
1579
+ const { t } = (0, import_react_i18next5.useTranslation)("localizedField");
1580
+ const schema = (0, import_react7.useMemo)(() => {
1581
+ const schema2 = { ...props };
1582
+ schema2.admin = { ...schema2.admin, components: {} };
1583
+ return schema2;
1584
+ }, []);
1585
+ const { path } = schema;
1586
+ const locale = (0, import_utilities5.useLocale)();
1587
+ const documentInfo = (0, import_utilities5.useDocumentInfo)();
1588
+ const { openModal, isModalOpen } = (0, import_modal2.useModal)();
1589
+ const modalKey = `${locale}-localized-field-modal-${path}`;
1590
+ const isModalOpened = isModalOpen(modalKey);
1591
+ const FieldComponent = schema.fieldTypes[schema.type];
1592
+ const fieldKey = `${locale}-localized-field-${path}-${isModalOpened ? "opened" : "closed"}`;
1593
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1594
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FieldComponent, { ...schema }, fieldKey),
1595
+ documentInfo.id ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: baseClass5, children: [
1596
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components2.Button, { className: "btn--localize", buttonStyle: "none", onClick: () => openModal(modalKey), children: [
1597
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${baseClass5}__locale`, children: locale }),
1598
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "M7.961 7.5h1.303l2.47 6.5h-1.349l-.538-1.5h-2.438l-.535 1.5h-1.392l2.479-6.5zm1.517 3.965l-.857-2.451-.851 2.451h1.708zm8.092-1.402c.062-.243.1-.426.135-.605l-1.1-.214-.109.5c-.371-.054-.767-.061-1.166-.021.009-.268.025-.531.049-.784h1.229v-1.042h-1.081c.054-.265.099-.424.144-.575l-1.074-.322c-.079.263-.145.521-.211.897h-1.226v1.042h1.092c-.028.337-.046.686-.051 1.038-1.207.443-1.719 1.288-1.719 2.054 0 .904.714 1.7 1.842 1.598 1.401-.128 2.337-1.186 2.885-2.487.567.327.805.876.591 1.385-.197.471-.78.919-1.892.896v1.121c1.234.019 2.448-.45 2.925-1.583.465-1.108-.066-2.318-1.263-2.898zm-1.446.766c-.175.387-.404.771-.697 1.075-.045-.323-.076-.676-.093-1.054.268-.035.537-.041.79-.021zm-1.894.362c.03.473.084.909.158 1.298-.997.183-1.037-.801-.158-1.298zm-2.23-8.191c5.514 0 10 3.592 10 8.007 0 4.917-5.145 7.961-9.91 7.961-1.937 0-3.384-.397-4.394-.644-1 .613-1.594 1.037-4.272 1.82.535-1.373.722-2.748.601-4.265-.837-1-2.025-2.4-2.025-4.872 0-4.415 4.486-8.007 10-8.007zm0-2c-6.338 0-12 4.226-12 10.007 0 2.05.739 4.063 2.047 5.625.055 1.83-1.023 4.456-1.993 6.368 2.602-.47 6.301-1.508 7.978-2.536 1.417.345 2.774.503 4.059.503 7.083 0 11.91-4.837 11.91-9.961-.001-5.811-5.702-10.006-12.001-10.006z" }) }),
1599
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: t("changeLocalization") })
1600
+ ] }),
1601
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_modal2.Modal, { slug: modalKey, className: `${baseClass5}__modal`, children: isModalOpened && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(LocalizedFieldModal, { ...schema }) })
1602
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: baseClass5, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components2.Button, { className: "btn--localize", buttonStyle: "none", children: [
1603
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${baseClass5}__locale`, children: locale }),
1604
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "M7.961 7.5h1.303l2.47 6.5h-1.349l-.538-1.5h-2.438l-.535 1.5h-1.392l2.479-6.5zm1.517 3.965l-.857-2.451-.851 2.451h1.708zm8.092-1.402c.062-.243.1-.426.135-.605l-1.1-.214-.109.5c-.371-.054-.767-.061-1.166-.021.009-.268.025-.531.049-.784h1.229v-1.042h-1.081c.054-.265.099-.424.144-.575l-1.074-.322c-.079.263-.145.521-.211.897h-1.226v1.042h1.092c-.028.337-.046.686-.051 1.038-1.207.443-1.719 1.288-1.719 2.054 0 .904.714 1.7 1.842 1.598 1.401-.128 2.337-1.186 2.885-2.487.567.327.805.876.591 1.385-.197.471-.78.919-1.892.896v1.121c1.234.019 2.448-.45 2.925-1.583.465-1.108-.066-2.318-1.263-2.898zm-1.446.766c-.175.387-.404.771-.697 1.075-.045-.323-.076-.676-.093-1.054.268-.035.537-.041.79-.021zm-1.894.362c.03.473.084.909.158 1.298-.997.183-1.037-.801-.158-1.298zm-2.23-8.191c5.514 0 10 3.592 10 8.007 0 4.917-5.145 7.961-9.91 7.961-1.937 0-3.384-.397-4.394-.644-1 .613-1.594 1.037-4.272 1.82.535-1.373.722-2.748.601-4.265-.837-1-2.025-2.4-2.025-4.872 0-4.415 4.486-8.007 10-8.007zm0-2c-6.338 0-12 4.226-12 10.007 0 2.05.739 4.063 2.047 5.625.055 1.83-1.023 4.456-1.993 6.368 2.602-.47 6.301-1.508 7.978-2.536 1.417.345 2.774.503 4.059.503 7.083 0 11.91-4.837 11.91-9.961-.001-5.811-5.702-10.006-12.001-10.006z" }) }),
1605
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: t("saveDocument") })
1606
+ ] }) })
1607
+ ] });
1608
+ }, "LocalizedField");
1609
+
1610
+ // src/fields/localized-field/index.ts
1611
+ var localizedField = /* @__PURE__ */ __name((options2) => {
1612
+ const baseOptions = {
1613
+ localized: true,
1614
+ admin: {
1615
+ components: {
1616
+ Field: LocalizedField
1617
+ }
1618
+ }
1619
+ };
1620
+ return deepMerge(
1621
+ baseOptions,
1622
+ options2
1623
+ );
1624
+ }, "localizedField");
1625
+ var withLocalized = /* @__PURE__ */ __name((config, first = true) => {
1626
+ Object.keys(config).forEach((key) => {
1627
+ if (typeof config[key] === "object") {
1628
+ if (config[key].localized === true) {
1629
+ config[key] = localizedField(config[key]);
1630
+ } else {
1631
+ config[key] = withLocalized(config[key], false);
1632
+ }
1633
+ }
1634
+ });
1635
+ if (first && Array.isArray(config.fields)) {
1636
+ if (!config.fields.find((x) => x.type === "ui" && x.name === "uiLanguages")) {
1637
+ config.fields.unshift(
1638
+ withUILanguages()
1639
+ );
1640
+ }
1641
+ }
1642
+ return config;
1643
+ }, "withLocalized");
1644
+
1645
+ // src/core/translations/translations.ts
1646
+ var missingTranslations = [];
1647
+ function getTranslation2(path, defaultText, locale, node, fullPath) {
1648
+ node = node || options.translations[locale];
1649
+ fullPath = fullPath || path;
1650
+ if (path.indexOf(".") !== -1) {
1651
+ const paths = path.split(".");
1652
+ const key = paths.shift();
1653
+ path = paths.join(".");
1654
+ return getTranslation2(path, defaultText, locale, node[key] || {}, fullPath);
1655
+ }
1656
+ if (!node[path] && missingTranslations.indexOf(fullPath) === -1) {
1657
+ missingTranslations.push(fullPath);
1658
+ }
1659
+ return node[path] || defaultText || "";
1660
+ }
1661
+ __name(getTranslation2, "getTranslation");
1662
+ function getTranslations(path, defaultText) {
1663
+ defaultText = defaultText || path;
1664
+ const localizedText = {};
1665
+ options.locales.forEach((locale) => {
1666
+ localizedText[locale] = getTranslation2(path, defaultText, locale);
1667
+ });
1668
+ return localizedText;
1669
+ }
1670
+ __name(getTranslations, "getTranslations");
1671
+ function slugToLabels(slug) {
1672
+ return {
1673
+ singular: getTranslations(`collection.singular.${slug}`, slug),
1674
+ plural: getTranslations(`collection.plural.${slug}`, slug)
1675
+ };
1676
+ }
1677
+ __name(slugToLabels, "slugToLabels");
1678
+ function slugToLabel(slug) {
1679
+ return getTranslations(`global.${slug}`, slug);
1680
+ }
1681
+ __name(slugToLabel, "slugToLabel");
1682
+ function translateTab(tab) {
1683
+ if (tab.label === false) {
1684
+ return tab;
1685
+ }
1686
+ if (typeof tab.label === "object") {
1687
+ return tab;
1688
+ }
1689
+ const label = tab.name || tab.label;
1690
+ if (label) {
1691
+ tab.label = getTranslations(`field.${label}`);
1692
+ }
1693
+ tab.fields = translateFields(tab.fields);
1694
+ return tab;
1695
+ }
1696
+ __name(translateTab, "translateTab");
1697
+ function translateTabs(tabs) {
1698
+ tabs = tabs.map((tab) => translateTab(tab));
1699
+ return tabs;
1700
+ }
1701
+ __name(translateTabs, "translateTabs");
1702
+ function translateBlock(block) {
1703
+ block.labels = slugToLabels(block.slug);
1704
+ block.fields = translateFields(block.fields);
1705
+ return block;
1706
+ }
1707
+ __name(translateBlock, "translateBlock");
1708
+ function translateBlocks(blocks) {
1709
+ blocks = blocks.map((block) => translateBlock(block));
1710
+ return blocks;
1711
+ }
1712
+ __name(translateBlocks, "translateBlocks");
1713
+ function translateField(field) {
1714
+ if (field.type === "ui") {
1715
+ return field;
1716
+ }
1717
+ if (typeof field.label === "object") {
1718
+ return field;
1719
+ }
1720
+ if (field.label === false) {
1721
+ return field;
1722
+ }
1723
+ const label = field["name"] || field.label;
1724
+ if (label) {
1725
+ field.label = getTranslations(`field.${label}`);
1726
+ }
1727
+ switch (field.type) {
1728
+ case "tabs":
1729
+ break;
1730
+ case "group":
1731
+ case "array":
1732
+ case "row":
1733
+ field.fields = translateFields(field.fields);
1734
+ break;
1735
+ case "blocks":
1736
+ field.blocks = translateBlocks(field.blocks);
1737
+ break;
1738
+ }
1739
+ return field;
1740
+ }
1741
+ __name(translateField, "translateField");
1742
+ function translateFields(fields) {
1743
+ fields = fields.map((field) => translateField(field));
1744
+ return fields;
1745
+ }
1746
+ __name(translateFields, "translateFields");
1747
+ function translateCollection(config) {
1748
+ config.labels = slugToLabels(config.slug);
1749
+ config.fields = translateFields(config.fields);
1750
+ if (config.admin && config.admin.group && typeof config.admin.group === "string") {
1751
+ config.admin.group = getTranslations(`group.${config.admin.group}`);
1752
+ }
1753
+ return config;
1754
+ }
1755
+ __name(translateCollection, "translateCollection");
1756
+ function translateGlobal(config) {
1757
+ config.label = slugToLabel(config.slug);
1758
+ config.fields = translateFields(config.fields);
1759
+ if (config.admin && config.admin.group && typeof config.admin.group === "string") {
1760
+ config.admin.group = getTranslations(`group.${config.admin.group}`);
1761
+ }
1762
+ return config;
1763
+ }
1764
+ __name(translateGlobal, "translateGlobal");
1765
+ function logMissingTranslations() {
1766
+ missingTranslations.sort();
1767
+ missingTranslations.forEach((missing) => console.warn(`missing translation ${missing}`));
1768
+ }
1769
+ __name(logMissingTranslations, "logMissingTranslations");
1770
+
1771
+ // src/core/utils/deepMerge.ts
1772
+ function isObject(item) {
1773
+ return item && typeof item === "object" && !Array.isArray(item);
1774
+ }
1775
+ __name(isObject, "isObject");
1776
+ function deepMerge(target, source) {
1777
+ const output = { ...target };
1778
+ if (isObject(target) && isObject(source)) {
1779
+ Object.keys(source).forEach((key) => {
1780
+ if (isObject(source[key])) {
1781
+ if (!(key in target)) {
1782
+ Object.assign(output, { [key]: source[key] });
1783
+ } else {
1784
+ output[key] = deepMerge(target[key], source[key]);
1785
+ }
1786
+ } else {
1787
+ Object.assign(output, { [key]: source[key] });
1788
+ }
1789
+ });
1790
+ }
1791
+ return output;
1792
+ }
1793
+ __name(deepMerge, "deepMerge");
1794
+
1795
+ // src/core/utils/formatSlug.ts
1796
+ var format = /* @__PURE__ */ __name((val) => val.replace(/ /g, "-").replace(/[^\w-]+/g, "").toLowerCase(), "format");
1797
+ var formatSlug = /* @__PURE__ */ __name((fallback) => ({ value, originalDoc, data }) => {
1798
+ if (typeof value === "string") {
1799
+ return format(value);
1800
+ }
1801
+ const fallbackData = data && data[fallback] || originalDoc && originalDoc[fallback];
1802
+ if (fallbackData && typeof fallbackData === "string") {
1803
+ return format(fallbackData);
1804
+ }
1805
+ return value;
1806
+ }, "formatSlug");
1807
+
1808
+ // src/core/utils/hooks.ts
1809
+ function withCollectionHook(config, name, hook) {
1810
+ const hooks = config.hooks || {};
1811
+ const list = hooks[name] || [];
1812
+ list.push(hook);
1813
+ hooks[name] = list;
1814
+ config.hooks = hooks;
1815
+ return config;
1816
+ }
1817
+ __name(withCollectionHook, "withCollectionHook");
1818
+ function withGlobalHook(config, name, hook) {
1819
+ const hooks = config.hooks || {};
1820
+ const list = hooks[name] || [];
1821
+ list.push(hook);
1822
+ hooks[name] = list;
1823
+ config.hooks = hooks;
1824
+ return config;
1825
+ }
1826
+ __name(withGlobalHook, "withGlobalHook");
1827
+ function withFieldHook(field, name, hook) {
1828
+ const hooks = field.hooks || {};
1829
+ const list = hooks[name] || [];
1830
+ list.push(hook);
1831
+ hooks[name] = list;
1832
+ field.hooks = hooks;
1833
+ return field;
1834
+ }
1835
+ __name(withFieldHook, "withFieldHook");
1836
+
1837
+ // src/core/utils/syncPages.ts
1838
+ var afterPageChangeHook = /* @__PURE__ */ __name(async ({
1839
+ doc,
1840
+ // full document data
1841
+ req,
1842
+ // full express request
1843
+ previousDoc,
1844
+ // document data before updating the collection
1845
+ operation
1846
+ // name of the operation ie. 'create', 'update'
1847
+ }) => {
1848
+ if (operation === "create") {
1849
+ const pages = await req.payload.find({
1850
+ collection: "page",
1851
+ where: { "content.value": { equals: doc.id } }
1852
+ });
1853
+ if (pages.totalDocs == 0) {
1854
+ await req.payload.create({
1855
+ collection: "page",
1856
+ data: {
1857
+ content: {
1858
+ value: doc.id,
1859
+ relationTo: req.collection.config.slug
1860
+ }
1861
+ }
1862
+ });
1863
+ }
1864
+ }
1865
+ return doc;
1866
+ }, "afterPageChangeHook");
1867
+ var afterPageDeleteHook = /* @__PURE__ */ __name(async ({
1868
+ req,
1869
+ // full express request
1870
+ id,
1871
+ // id of document to delete
1872
+ doc
1873
+ // deleted document
1874
+ }) => {
1875
+ const pages = await req.payload.find({
1876
+ collection: "page",
1877
+ where: { "content.value": { equals: id } }
1878
+ });
1879
+ if (pages.totalDocs > 0) {
1880
+ pages.docs.map(async ({ id: pageId }) => {
1881
+ await req.payload.delete({
1882
+ collection: "page",
1883
+ id: pageId
1884
+ });
1885
+ });
1886
+ }
1887
+ }, "afterPageDeleteHook");
1888
+
1889
+ // src/core/collections/withBlock.ts
1890
+ var BlockDefaults = {};
1891
+ var withBlock = /* @__PURE__ */ __name((options2) => {
1892
+ const blockConfig = deepMerge({
1893
+ ...BlockDefaults
1894
+ }, options2);
1895
+ delete blockConfig["type"];
1896
+ translateCollection(blockConfig);
1897
+ return withLocalized(blockConfig);
1898
+ }, "withBlock");
1899
+
1900
+ // src/core/collections/withStaticCollection.ts
1901
+ var import_axios = __toESM(require("axios"));
1902
+ var staticCollections = [];
1903
+ var staticCollectionLoaders = {};
1904
+ var ID = 0;
1905
+ var CACHE = {};
1906
+ async function getCollection(url) {
1907
+ const response = await import_axios.default.get(url, {});
1908
+ const items = response.data.items;
1909
+ return items;
1910
+ }
1911
+ __name(getCollection, "getCollection");
1912
+ function mapItems(items, map) {
1913
+ if (typeof map === "object") {
1914
+ items = items.map((x) => {
1915
+ const item = {};
1916
+ Object.entries(x).forEach(([k, v]) => {
1917
+ item[map[k] || k] = v;
1918
+ });
1919
+ return item;
1920
+ });
1921
+ }
1922
+ return items;
1923
+ }
1924
+ __name(mapItems, "mapItems");
1925
+ function getLoader(config, src, map) {
1926
+ return async () => {
1927
+ const key = typeof src === "string" ? src : `static_${++ID}`;
1928
+ let items = CACHE[key];
1929
+ if (!items) {
1930
+ if (typeof src === "string") {
1931
+ items = await getCollection(src);
1932
+ } else if (typeof src === "function") {
1933
+ if (src instanceof Promise) {
1934
+ items = await src(config);
1935
+ } else {
1936
+ items = src(config);
1937
+ }
1938
+ } else {
1939
+ items = src;
1940
+ }
1941
+ items = mapItems(items, map);
1942
+ CACHE[key] = items;
1943
+ }
1944
+ return items;
1945
+ };
1946
+ }
1947
+ __name(getLoader, "getLoader");
1948
+ function getObjectParam(value) {
1949
+ if (typeof value === "object") {
1950
+ return value;
1951
+ }
1952
+ return void 0;
1953
+ }
1954
+ __name(getObjectParam, "getObjectParam");
1955
+ function getNumericParam(value) {
1956
+ if (typeof value === "string") {
1957
+ return parseInt(value);
1958
+ }
1959
+ return void 0;
1960
+ }
1961
+ __name(getNumericParam, "getNumericParam");
1962
+ function getStringParam(value) {
1963
+ if (typeof value === "string") {
1964
+ return value;
1965
+ }
1966
+ return void 0;
1967
+ }
1968
+ __name(getStringParam, "getStringParam");
1969
+ function existsClause(value, exists) {
1970
+ if (typeof exists === "boolean") {
1971
+ return value != null === exists;
1972
+ }
1973
+ return true;
1974
+ }
1975
+ __name(existsClause, "existsClause");
1976
+ function equalsClause(value, equals) {
1977
+ if (typeof equals !== "undefined") {
1978
+ return value === equals;
1979
+ }
1980
+ return true;
1981
+ }
1982
+ __name(equalsClause, "equalsClause");
1983
+ function inClause(value, values) {
1984
+ if (Array.isArray(values)) {
1985
+ return values.indexOf(value) !== -1;
1986
+ }
1987
+ return true;
1988
+ }
1989
+ __name(inClause, "inClause");
1990
+ function notInClause(value, values) {
1991
+ if (Array.isArray(values)) {
1992
+ return values.indexOf(value) === -1;
1993
+ }
1994
+ return true;
1995
+ }
1996
+ __name(notInClause, "notInClause");
1997
+ function likeClause(value, query) {
1998
+ if (typeof query === "string") {
1999
+ return String(value).toLowerCase().indexOf(query.toLowerCase()) !== -1;
2000
+ }
2001
+ return true;
2002
+ }
2003
+ __name(likeClause, "likeClause");
2004
+ function whereItem(item, where) {
2005
+ let has = true;
2006
+ if (typeof where === "object") {
2007
+ Object.entries(where).forEach(([k, v]) => {
2008
+ switch (k) {
2009
+ case "and":
2010
+ if (Array.isArray(v)) {
2011
+ has = v.reduce((p, c) => {
2012
+ return p && whereItem(item, c);
2013
+ }, has);
2014
+ }
2015
+ break;
2016
+ case "or":
2017
+ if (Array.isArray(v)) {
2018
+ has = has && v.reduce((p, c) => {
2019
+ return p || whereItem(item, c);
2020
+ }, false);
2021
+ }
2022
+ break;
2023
+ default:
2024
+ if (typeof v === "object") {
2025
+ const value = item[k];
2026
+ has = has && existsClause(value, v.exists);
2027
+ has = has && equalsClause(value, v.equals);
2028
+ has = has && inClause(value, v.in);
2029
+ has = has && notInClause(value, v.not_in);
2030
+ has = has && likeClause(value, v.like);
2031
+ }
2032
+ }
2033
+ });
2034
+ }
2035
+ return has;
2036
+ }
2037
+ __name(whereItem, "whereItem");
2038
+ async function whereCollection(items, where) {
2039
+ if (typeof where === "object") {
2040
+ items = items.filter((item) => whereItem(item, where));
2041
+ }
2042
+ return items;
2043
+ }
2044
+ __name(whereCollection, "whereCollection");
2045
+ async function populateStaticFields(item, fields, locale = "en") {
2046
+ const x = { ...item };
2047
+ for (const field of fields) {
2048
+ if (field.type === "relationship" && typeof field.relationTo === "string") {
2049
+ const { name } = field;
2050
+ const loader = getStaticLoader(field.relationTo);
2051
+ if (typeof loader === "function") {
2052
+ const items = await loader();
2053
+ if (field.hasMany) {
2054
+ const ids = x[name];
2055
+ x[name] = items.filter((x2) => ids.indexOf(x2.id) !== -1);
2056
+ } else {
2057
+ const id = x[name];
2058
+ x[name] = items.find((x2) => x2.id === id) || id;
2059
+ }
2060
+ }
2061
+ }
2062
+ }
2063
+ return x;
2064
+ }
2065
+ __name(populateStaticFields, "populateStaticFields");
2066
+ function localizeItem(item, localizedFields, locale = "en") {
2067
+ let localizedItem = item;
2068
+ if (localizedFields.length) {
2069
+ localizedItem = { ...item };
2070
+ localizedFields.forEach((field) => {
2071
+ localizedItem[field] = item[field][locale];
2072
+ });
2073
+ }
2074
+ return localizedItem;
2075
+ }
2076
+ __name(localizeItem, "localizeItem");
2077
+ async function localizeCollection(items, localizedFields, locale = "en") {
2078
+ if (localizedFields.length) {
2079
+ items = items.map((item) => localizeItem(item, localizedFields, locale));
2080
+ }
2081
+ return items;
2082
+ }
2083
+ __name(localizeCollection, "localizeCollection");
2084
+ async function sortCollection(items, sort) {
2085
+ if (sort) {
2086
+ const keys = sort.split("-");
2087
+ const reverse = keys.length > 1 ? -1 : 1;
2088
+ const key = keys.pop();
2089
+ items = [...items];
2090
+ items.sort((a, b) => {
2091
+ const aValue = String(a[key]);
2092
+ const bValue = String(b[key]);
2093
+ if (aValue.localeCompare(bValue) < 0) {
2094
+ return -1 * reverse;
2095
+ } else if (aValue.localeCompare(bValue) > 0) {
2096
+ return 1 * reverse;
2097
+ }
2098
+ return 0;
2099
+ });
2100
+ }
2101
+ return items;
2102
+ }
2103
+ __name(sortCollection, "sortCollection");
2104
+ async function getPagination(items, page = 1, limit = 10) {
2105
+ const totalDocs = items.length;
2106
+ const totalPages = Math.ceil(items.length / limit);
2107
+ const hasNextPage = page < totalPages;
2108
+ const hasPrevPage = page > 1;
2109
+ const index = page - 1;
2110
+ const from = index * limit;
2111
+ const to = Math.min(page * limit, totalDocs);
2112
+ const docs = items.slice(from, to);
2113
+ const pagination = {
2114
+ totalDocs,
2115
+ totalPages,
2116
+ page,
2117
+ limit,
2118
+ hasNextPage,
2119
+ hasPrevPage,
2120
+ nextPage: hasNextPage ? page + 1 : null,
2121
+ prevPage: hasPrevPage ? page - 1 : null,
2122
+ pagingCounter: from + 1
2123
+ };
2124
+ return {
2125
+ docs,
2126
+ ...pagination
2127
+ };
2128
+ }
2129
+ __name(getPagination, "getPagination");
2130
+ function getStaticLoader(slug) {
2131
+ return staticCollectionLoaders[slug];
2132
+ }
2133
+ __name(getStaticLoader, "getStaticLoader");
2134
+ var StaticCollectionDefault = {
2135
+ admin: {
2136
+ group: options.group.i18n,
2137
+ useAsTitle: "name",
2138
+ defaultColumns: ["name", "id"],
2139
+ listSearchableFields: ["name", "id"]
2140
+ },
2141
+ access: {
2142
+ read: () => true,
2143
+ create: () => false,
2144
+ update: () => false,
2145
+ delete: () => false,
2146
+ admin: () => true,
2147
+ unlock: () => false
2148
+ }
2149
+ };
2150
+ var withStaticCollection = /* @__PURE__ */ __name(({ src, map, ...config }) => {
2151
+ staticCollections.push(config.slug);
2152
+ const collectionConfig = deepMerge(StaticCollectionDefault, config);
2153
+ const localizedFields = collectionConfig.fields.filter((x) => x["localized"] === true).map((x) => x.name);
2154
+ const loader = getLoader(collectionConfig, src, map);
2155
+ staticCollectionLoaders[collectionConfig.slug] = loader;
2156
+ collectionConfig.endpoints = [
2157
+ {
2158
+ path: "/",
2159
+ method: "get",
2160
+ handler: async (req, res, next) => {
2161
+ try {
2162
+ const collection = await loader();
2163
+ const { url, query, params } = req;
2164
+ const { locale, where, sort, page, limit, depth, draft } = query;
2165
+ let items = await whereCollection(collection, getObjectParam(where));
2166
+ items = await localizeCollection(items, localizedFields, getStringParam(locale));
2167
+ items = await sortCollection(items, getStringParam(sort));
2168
+ const pagination = await getPagination(
2169
+ items,
2170
+ getNumericParam(page),
2171
+ getNumericParam(limit)
2172
+ );
2173
+ res.status(200).send(pagination);
2174
+ } catch (error) {
2175
+ console.log("withStaticCollection.get.error", error);
2176
+ res.status(500).send(error);
2177
+ }
2178
+ }
2179
+ },
2180
+ {
2181
+ path: "/:id/",
2182
+ method: "get",
2183
+ handler: async (req, res, next) => {
2184
+ try {
2185
+ const collection = await loader();
2186
+ const { url, query, params } = req;
2187
+ const { locale } = query;
2188
+ const { id } = params;
2189
+ const depth = getNumericParam(query.depth);
2190
+ let item = collection.find((x) => x.id === id);
2191
+ if (item) {
2192
+ if (depth !== 0 && Array.isArray(collectionConfig.fields)) {
2193
+ item = await populateStaticFields(item, collectionConfig.fields);
2194
+ }
2195
+ item = localizeItem(item, localizedFields, getStringParam(locale));
2196
+ res.status(200).send(item);
2197
+ } else {
2198
+ res.status(404);
2199
+ }
2200
+ } catch (error) {
2201
+ console.log("withStaticCollection.get:id.error", error);
2202
+ res.status(500).send(error);
2203
+ }
2204
+ }
2205
+ }
2206
+ ];
2207
+ collectionConfig.fields.forEach((field) => {
2208
+ const admin = field.admin || {};
2209
+ admin["readOnly"] = true;
2210
+ field.admin = admin;
2211
+ });
2212
+ translateCollection(collectionConfig);
2213
+ return collectionConfig;
2214
+ }, "withStaticCollection");
2215
+
2216
+ // src/core/collections/withCollection.ts
2217
+ var CollectionDefault = {
2218
+ admin: {
2219
+ group: options.group.config,
2220
+ useAsTitle: "id",
2221
+ defaultColumns: ["id", "title"]
2222
+ },
2223
+ access: {
2224
+ read: () => true
2225
+ }
2226
+ };
2227
+ var withCollection = /* @__PURE__ */ __name((config) => {
2228
+ const collectionConfig = deepMerge(CollectionDefault, config);
2229
+ withCollectionHook(collectionConfig, "afterRead", async ({
2230
+ doc,
2231
+ // full document data
2232
+ req,
2233
+ // full express request
2234
+ query,
2235
+ // JSON formatted query
2236
+ findMany
2237
+ // boolean to denote if this hook is running against finding one, or finding many
2238
+ }) => {
2239
+ if (doc && !findMany) {
2240
+ const { query: query2 } = req;
2241
+ const { locale } = query2;
2242
+ const depth = getNumericParam(query2.depth);
2243
+ if (depth !== 0 && Array.isArray(collectionConfig.fields)) {
2244
+ doc = await populateStaticFields(doc, collectionConfig.fields, locale);
2245
+ }
2246
+ }
2247
+ return doc;
2248
+ });
2249
+ collectionConfig.endpoints = [
2250
+ collectionGet(config.slug)
2251
+ ];
2252
+ translateCollection(collectionConfig);
2253
+ return withLocalized(collectionConfig);
2254
+ }, "withCollection");
2255
+
2256
+ // src/core/collections/withGlobal.ts
2257
+ var GlobalDefault = {
2258
+ admin: {
2259
+ group: options.group.config
2260
+ },
2261
+ access: {
2262
+ read: () => true
2263
+ }
2264
+ };
2265
+ var withGlobal = /* @__PURE__ */ __name((config) => {
2266
+ const globalConfig = deepMerge(GlobalDefault, config);
2267
+ withGlobalHook(globalConfig, "afterRead", async ({
2268
+ doc,
2269
+ // full document data
2270
+ req,
2271
+ // full express request
2272
+ query,
2273
+ // JSON formatted query
2274
+ findMany
2275
+ // boolean to denote if this hook is running against finding one, or finding many
2276
+ }) => {
2277
+ if (doc && !findMany) {
2278
+ const { query: query2 } = req;
2279
+ const { locale } = query2;
2280
+ const depth = getNumericParam(query2.depth);
2281
+ if (depth !== 0 && Array.isArray(globalConfig.fields)) {
2282
+ doc = await populateStaticFields(doc, globalConfig.fields, locale);
2283
+ }
2284
+ }
2285
+ return doc;
2286
+ });
2287
+ translateGlobal(globalConfig);
2288
+ return withLocalized(globalConfig);
2289
+ }, "withGlobal");
2290
+
2291
+ // src/core/fields/withRichText.ts
2292
+ var import_escape_html2 = __toESM(require("escape-html"));
2293
+ var import_slate2 = require("slate");
2294
+ var richTextAfterReadHook = /* @__PURE__ */ __name((args) => {
2295
+ const {
2296
+ value,
2297
+ // Typed as `string` as shown above
2298
+ operation,
2299
+ findMany,
2300
+ data,
2301
+ // Typed as a Partial of your ExampleDocumentType
2302
+ siblingData,
2303
+ // Typed as a Partial of SiblingDataType
2304
+ originalDoc,
2305
+ // Typed as ExampleDocumentType
2306
+ req
2307
+ } = args;
2308
+ if (operation === "read" && (findMany || req.query && req.query.richText === "false")) {
2309
+ return richTextSerialize(value);
2310
+ }
2311
+ return value;
2312
+ }, "richTextAfterReadHook");
2313
+ var RichTextDefaults = {
2314
+ name: "richText",
2315
+ type: "richText",
2316
+ localized: true,
2317
+ hooks: {
2318
+ afterRead: [
2319
+ richTextAfterReadHook
2320
+ ]
2321
+ }
2322
+ };
2323
+ var withRichText = /* @__PURE__ */ __name((options2 = {}) => {
2324
+ const field = deepMerge(RichTextDefaults, options2);
2325
+ return field;
2326
+ }, "withRichText");
2327
+ var withRichTextRequired = /* @__PURE__ */ __name((options2 = {}) => {
2328
+ const field = deepMerge({
2329
+ ...RichTextDefaults,
2330
+ required: true
2331
+ }, options2);
2332
+ return field;
2333
+ }, "withRichTextRequired");
2334
+ function richTextSerialize(children) {
2335
+ if (Array.isArray(children)) {
2336
+ return children.map((node, i) => {
2337
+ if (import_slate2.Text.isText(node)) {
2338
+ let text = node.text;
2339
+ if (node.bold) {
2340
+ text = `<strong>${text}</strong>`;
2341
+ }
2342
+ if (node.code) {
2343
+ text = `<code>${text}</code>`;
2344
+ }
2345
+ if (node.italic) {
2346
+ text = `<em>${text}</em>`;
2347
+ }
2348
+ return `<span>${text}</span>`;
2349
+ }
2350
+ if (!node) {
2351
+ return null;
2352
+ }
2353
+ switch (node.type) {
2354
+ case "h1":
2355
+ return `<h1>${richTextSerialize(node.children)}</h1>`;
2356
+ case "h6":
2357
+ return `<h6 >${richTextSerialize(node.children)}</h6>`;
2358
+ case "quote":
2359
+ return `<blockquote >${richTextSerialize(node.children)}</blockquote>`;
2360
+ case "ul":
2361
+ return `<ul >${richTextSerialize(node.children)}</ul>`;
2362
+ case "ol":
2363
+ return `<ol >${richTextSerialize(node.children)}</ol>`;
2364
+ case "li":
2365
+ return `<li>${richTextSerialize(node.children)}</li>`;
2366
+ case "link":
2367
+ return `<a href="${(0, import_escape_html2.default)(node.url)}">${richTextSerialize(node.children)}</a>`;
2368
+ default:
2369
+ return `<p>${richTextSerialize(node.children)}</p>`;
2370
+ }
2371
+ }).join("\n");
2372
+ }
2373
+ return "";
2374
+ }
2375
+ __name(richTextSerialize, "richTextSerialize");
2376
+
2377
+ // src/core/fields/withAbstract.ts
2378
+ var withAbstract = /* @__PURE__ */ __name((options2 = {}) => {
2379
+ return withRichText(deepMerge({
2380
+ name: "abstract"
2381
+ }, options2));
2382
+ }, "withAbstract");
2383
+ var withAbstractRequired = /* @__PURE__ */ __name((options2 = {}) => {
2384
+ return withRichText(deepMerge({
2385
+ name: "abstract",
2386
+ required: true
2387
+ }, options2));
2388
+ }, "withAbstractRequired");
2389
+
2390
+ // src/core/fields/withCategory.ts
2391
+ var CategoryDefaults = {
2392
+ name: "category",
2393
+ type: "relationship",
2394
+ relationTo: options.slug.category,
2395
+ hasMany: false
2396
+ };
2397
+ var withCategory = /* @__PURE__ */ __name((options2 = {}) => {
2398
+ const field = deepMerge(CategoryDefaults, options2);
2399
+ return field;
2400
+ }, "withCategory");
2401
+ var withCategoryRequired = /* @__PURE__ */ __name((options2 = {}) => {
2402
+ const field = deepMerge({
2403
+ ...CategoryDefaults,
2404
+ required: true
2405
+ }, options2);
2406
+ return field;
2407
+ }, "withCategoryRequired");
2408
+
2409
+ // src/core/fields/withCheckbox.ts
2410
+ var CheckboxDefaults = {
2411
+ name: "checkbox",
2412
+ type: "checkbox",
2413
+ defaultValue: false
2414
+ };
2415
+ var withCheckbox = /* @__PURE__ */ __name((options2 = {}) => {
2416
+ const field = deepMerge(CheckboxDefaults, options2);
2417
+ return field;
2418
+ }, "withCheckbox");
2419
+ var withCheckboxRequired = /* @__PURE__ */ __name((options2 = {}) => {
2420
+ const field = deepMerge({
2421
+ ...CheckboxDefaults,
2422
+ required: true
2423
+ }, options2);
2424
+ return field;
2425
+ }, "withCheckboxRequired");
2426
+
2427
+ // src/core/fields/withComponents.ts
2428
+ var ComponentsDefaults = {
2429
+ name: "components",
2430
+ type: "blocks",
2431
+ blocks: []
2432
+ };
2433
+ var withComponents = /* @__PURE__ */ __name((options2) => {
2434
+ const field = deepMerge({
2435
+ ...ComponentsDefaults
2436
+ }, options2);
2437
+ return field;
2438
+ }, "withComponents");
2439
+
2440
+ // src/core/fields/withDate.ts
2441
+ var DateDefaults = {
2442
+ name: "date",
2443
+ type: "date"
2444
+ };
2445
+ var withDate = /* @__PURE__ */ __name((options2 = {}) => {
2446
+ const field = deepMerge(DateDefaults, options2);
2447
+ return field;
2448
+ }, "withDate");
2449
+ var withDateRequired = /* @__PURE__ */ __name((options2 = {}) => {
2450
+ const field = deepMerge({
2451
+ ...DateDefaults,
2452
+ required: true
2453
+ }, options2);
2454
+ return field;
2455
+ }, "withDateRequired");
2456
+
2457
+ // src/core/fields/withDescription.ts
2458
+ var withDescription = /* @__PURE__ */ __name((options2 = {}) => {
2459
+ return withRichText(deepMerge({
2460
+ name: "description"
2461
+ }, options2));
2462
+ }, "withDescription");
2463
+ var withDescriptionRequired = /* @__PURE__ */ __name((options2 = {}) => {
2464
+ return withRichText(deepMerge({
2465
+ name: "description",
2466
+ required: true
2467
+ }, options2));
2468
+ }, "withDescriptionRequired");
2469
+
2470
+ // src/core/fields/withText.ts
2471
+ var TextDefaults = {
2472
+ name: "text",
2473
+ type: "text"
2474
+ };
2475
+ var withText = /* @__PURE__ */ __name((options2 = {}) => {
2476
+ const field = deepMerge(TextDefaults, options2);
2477
+ return field;
2478
+ }, "withText");
2479
+ var withTextRequired = /* @__PURE__ */ __name((options2 = {}) => {
2480
+ const field = deepMerge({
2481
+ ...TextDefaults,
2482
+ required: true
2483
+ }, options2);
2484
+ return field;
2485
+ }, "withTextRequired");
2486
+
2487
+ // src/core/fields/withId.ts
2488
+ var withId = /* @__PURE__ */ __name((options2 = {}) => {
2489
+ return withText(deepMerge({
2490
+ name: "id"
2491
+ }, options2));
2492
+ }, "withId");
2493
+ var withIdRequired = /* @__PURE__ */ __name((options2 = {}) => {
2494
+ return withText(deepMerge({
2495
+ name: "id",
2496
+ required: true
2497
+ }, options2));
2498
+ }, "withIdRequired");
2499
+
2500
+ // src/core/fields/withIsActive.ts
2501
+ var withIsActive = /* @__PURE__ */ __name((options2 = {}) => {
2502
+ return withCheckbox(deepMerge({
2503
+ name: "isActive"
2504
+ }, options2));
2505
+ }, "withIsActive");
2506
+ var withIsActiveRequired = /* @__PURE__ */ __name((options2 = {}) => {
2507
+ return withCheckbox(deepMerge({
2508
+ name: "isActive",
2509
+ required: true
2510
+ }, options2));
2511
+ }, "withIsActiveRequired");
2512
+
2513
+ // src/core/fields/withIsDefault.ts
2514
+ var withIsDefault = /* @__PURE__ */ __name((options2 = {}) => {
2515
+ return withCheckbox(deepMerge({
2516
+ name: "isDefault"
2517
+ }, options2));
2518
+ }, "withIsDefault");
2519
+ var withIsDefaultRequired = /* @__PURE__ */ __name((options2 = {}) => {
2520
+ return withCheckbox(deepMerge({
2521
+ name: "isDefault",
2522
+ required: true
2523
+ }, options2));
2524
+ }, "withIsDefaultRequired");
2525
+
2526
+ // src/core/fields/withLink.ts
2527
+ var appearanceOptions = {
2528
+ text: {
2529
+ label: "Text",
2530
+ value: "text"
2531
+ },
2532
+ primaryButton: {
2533
+ label: "Primary Button",
2534
+ value: "primaryButton"
2535
+ },
2536
+ secondaryButton: {
2537
+ label: "Secondary Button",
2538
+ value: "secondaryButton"
2539
+ }
2540
+ };
2541
+ var withLink = /* @__PURE__ */ __name(({ appearances, disableLabel = false, ...props } = {}) => {
2542
+ const generatedLink = {
2543
+ name: "link",
2544
+ type: "group",
2545
+ fields: [
2546
+ {
2547
+ name: "type",
2548
+ type: "radio",
2549
+ options: [
2550
+ {
2551
+ label: "Internal link",
2552
+ value: "reference"
2553
+ },
2554
+ {
2555
+ label: "Custom URL",
2556
+ value: "custom"
2557
+ }
2558
+ ],
2559
+ defaultValue: "reference",
2560
+ admin: {
2561
+ layout: "horizontal"
2562
+ }
2563
+ }
2564
+ ]
2565
+ };
2566
+ const linkOptions = {
2567
+ type: "row",
2568
+ fields: [
2569
+ {
2570
+ name: "reference",
2571
+ label: "Document to link to",
2572
+ type: "relationship",
2573
+ relationTo: options.pages,
2574
+ required: true,
2575
+ maxDepth: 1,
2576
+ admin: {
2577
+ condition: (_, siblingData) => siblingData?.type === "reference"
2578
+ }
2579
+ },
2580
+ {
2581
+ name: "url",
2582
+ label: "Custom URL",
2583
+ type: "text",
2584
+ required: true,
2585
+ admin: {
2586
+ condition: (_, siblingData) => siblingData?.type === "custom"
2587
+ }
2588
+ }
2589
+ ]
2590
+ };
2591
+ if (!disableLabel) {
2592
+ linkOptions.fields.unshift({
2593
+ name: "label",
2594
+ label: "Label",
2595
+ type: "text",
2596
+ required: true,
2597
+ admin: {
2598
+ width: "50%"
2599
+ }
2600
+ });
2601
+ linkOptions.fields[1].admin.width = "50%";
2602
+ linkOptions.fields[2].admin.width = "50%";
2603
+ generatedLink.fields[0].admin.width = "50%";
2604
+ generatedLink.fields.push(linkOptions);
2605
+ } else {
2606
+ generatedLink.fields.push(linkOptions);
2607
+ }
2608
+ generatedLink.fields.push({
2609
+ name: "newTab",
2610
+ label: "Open In New Tab",
2611
+ type: "checkbox"
2612
+ });
2613
+ if (typeof appearances === "undefined") {
2614
+ generatedLink.fields.unshift({
2615
+ name: "appearance",
2616
+ label: "Appearance",
2617
+ type: "select",
2618
+ defaultValue: "text",
2619
+ options: [
2620
+ appearanceOptions.text,
2621
+ appearanceOptions.primaryButton,
2622
+ appearanceOptions.secondaryButton
2623
+ ]
2624
+ });
2625
+ }
2626
+ if (appearances) {
2627
+ generatedLink.fields.unshift({
2628
+ name: "appearance",
2629
+ label: "Appearance",
2630
+ type: "select",
2631
+ defaultValue: appearances[0],
2632
+ options: appearances.map((appearance) => appearanceOptions[appearance])
2633
+ });
2634
+ }
2635
+ return deepMerge(generatedLink, props);
2636
+ }, "withLink");
2637
+
2638
+ // src/core/fields/withMarkets.ts
2639
+ var MarketDefaults = {
2640
+ name: "markets",
2641
+ type: "relationship",
2642
+ relationTo: options.slug.market,
2643
+ hasMany: true
2644
+ };
2645
+ var withMarkets = /* @__PURE__ */ __name((options2 = {}) => {
2646
+ const field = deepMerge(MarketDefaults, options2);
2647
+ return field;
2648
+ }, "withMarkets");
2649
+ var withMarketsRequired = /* @__PURE__ */ __name((options2 = {}) => {
2650
+ const field = deepMerge({
2651
+ ...MarketDefaults,
2652
+ required: true
2653
+ }, options2);
2654
+ return field;
2655
+ }, "withMarketsRequired");
2656
+
2657
+ // src/core/fields/withMedia.ts
2658
+ var MediaDefaults = {
2659
+ name: "media",
2660
+ type: "upload",
2661
+ relationTo: options.slug.media
2662
+ /*
2663
+ admin: {
2664
+ description: 'Maximum upload file size: 2MB. Recommended file size for images is <500KB.',
2665
+ },
2666
+ */
2667
+ };
2668
+ var withMedia = /* @__PURE__ */ __name((options2 = {}) => {
2669
+ const field = deepMerge(MediaDefaults, options2);
2670
+ return field;
2671
+ }, "withMedia");
2672
+ var withMediaRequired = /* @__PURE__ */ __name((options2 = {}) => {
2673
+ const field = deepMerge({
2674
+ ...MediaDefaults,
2675
+ required: true
2676
+ }, options2);
2677
+ return field;
2678
+ }, "withMediaRequired");
2679
+
2680
+ // src/core/fields/withMedias.ts
2681
+ var MediasDefaults = {
2682
+ name: "medias",
2683
+ type: "array",
2684
+ fields: [
2685
+ withMediaRequired()
2686
+ ]
2687
+ };
2688
+ var withMedias = /* @__PURE__ */ __name((options2 = {}) => {
2689
+ const field = deepMerge(MediasDefaults, options2);
2690
+ return field;
2691
+ }, "withMedias");
2692
+ var withMediasRequired = /* @__PURE__ */ __name((options2 = {}) => {
2693
+ const field = deepMerge({
2694
+ ...MediasDefaults,
2695
+ required: true
2696
+ }, options2);
2697
+ return field;
2698
+ }, "withMediasRequired");
2699
+
2700
+ // src/core/fields/withName.ts
2701
+ var withName = /* @__PURE__ */ __name((options2 = {}) => {
2702
+ return withText(deepMerge({
2703
+ name: "name",
2704
+ localized: true
2705
+ }, options2));
2706
+ }, "withName");
2707
+ var withNameRequired = /* @__PURE__ */ __name((options2 = {}) => {
2708
+ return withText(deepMerge({
2709
+ name: "name",
2710
+ localized: true,
2711
+ required: true
2712
+ }, options2));
2713
+ }, "withNameRequired");
2714
+
2715
+ // src/core/fields/withRelated.ts
2716
+ var RelatedDefaults = {
2717
+ name: "related",
2718
+ type: "blocks",
2719
+ blocks: [],
2720
+ maxRows: 1
2721
+ };
2722
+ var withRelated = /* @__PURE__ */ __name((options2) => {
2723
+ const field = deepMerge({
2724
+ ...RelatedDefaults
2725
+ }, options2);
2726
+ return field;
2727
+ }, "withRelated");
2728
+
2729
+ // src/core/fields/withSelect.ts
2730
+ var SelectDefaults = {
2731
+ name: "select",
2732
+ type: "select",
2733
+ hasMany: false,
2734
+ admin: {
2735
+ isClearable: true
2736
+ },
2737
+ options: []
2738
+ };
2739
+ var withSelect = /* @__PURE__ */ __name((options2 = {}) => {
2740
+ const field = deepMerge(SelectDefaults, options2);
2741
+ return field;
2742
+ }, "withSelect");
2743
+ var withSelectRequired = /* @__PURE__ */ __name((options2 = {}) => {
2744
+ const field = deepMerge({
2745
+ ...SelectDefaults,
2746
+ required: true
2747
+ }, options2);
2748
+ return field;
2749
+ }, "withSelectRequired");
2750
+
2751
+ // src/core/fields/withSlug.ts
2752
+ var withSlug = /* @__PURE__ */ __name(({ fieldToUse, ...options2 } = { fieldToUse: "title" }) => {
2753
+ return withText(deepMerge({
2754
+ name: "slug",
2755
+ localized: true,
2756
+ hooks: {
2757
+ beforeValidate: [formatSlug(fieldToUse)]
2758
+ }
2759
+ }, options2));
2760
+ }, "withSlug");
2761
+ var withSlugRequired = /* @__PURE__ */ __name(({ fieldToUse, ...options2 } = { fieldToUse: "title" }) => {
2762
+ return withText(deepMerge({
2763
+ name: "slug",
2764
+ localized: true,
2765
+ required: true,
2766
+ hooks: {
2767
+ beforeValidate: [formatSlug(fieldToUse)]
2768
+ }
2769
+ }, options2));
2770
+ }, "withSlugRequired");
2771
+
2772
+ // src/core/fields/withTemplate.ts
2773
+ var TemplateDefaults = {
2774
+ name: "template",
2775
+ type: "relationship",
2776
+ relationTo: options.slug.template,
2777
+ hasMany: false
2778
+ };
2779
+ var filterOptionsBySlug = /* @__PURE__ */ __name((slug) => () => {
2780
+ return {
2781
+ or: [
2782
+ {
2783
+ hasCompatibleCollections: { equals: false }
2784
+ },
2785
+ {
2786
+ and: [
2787
+ {
2788
+ hasCompatibleCollections: { equals: true }
2789
+ },
2790
+ {
2791
+ compatibleCollections: { contains: slug }
2792
+ }
2793
+ ]
2794
+ }
2795
+ ]
2796
+ };
2797
+ }, "filterOptionsBySlug");
2798
+ var withTemplate = /* @__PURE__ */ __name(({ slugToUse, ...options2 }) => {
2799
+ const field = deepMerge(TemplateDefaults, options2);
2800
+ field.filterOptions = filterOptionsBySlug(slugToUse);
2801
+ return field;
2802
+ }, "withTemplate");
2803
+ var withTemplateRequired = /* @__PURE__ */ __name(({ slugToUse, ...options2 }) => {
2804
+ const field = deepMerge({
2805
+ ...TemplateDefaults,
2806
+ required: true
2807
+ }, options2);
2808
+ field.filterOptions = filterOptionsBySlug(slugToUse);
2809
+ return field;
2810
+ }, "withTemplateRequired");
2811
+
2812
+ // src/core/fields/withTitle.ts
2813
+ var withTitle = /* @__PURE__ */ __name((options2 = {}) => {
2814
+ return withText(deepMerge({
2815
+ name: "title",
2816
+ localized: true
2817
+ }, options2));
2818
+ }, "withTitle");
2819
+ var withTitleRequired = /* @__PURE__ */ __name((options2 = {}) => {
2820
+ return withText(deepMerge({
2821
+ name: "title",
2822
+ localized: true,
2823
+ required: true
2824
+ }, options2));
2825
+ }, "withTitleRequired");
2826
+
2827
+ // src/core/collections/withPage.ts
2828
+ var PageDefault = {
2829
+ admin: {
2830
+ group: options.group.content,
2831
+ useAsTitle: "title",
2832
+ defaultColumns: ["title", "slug", "template", "createdAt", "_status"]
2833
+ },
2834
+ access: {
2835
+ read: () => true
2836
+ },
2837
+ versions: {
2838
+ drafts: true
2839
+ },
2840
+ hooks: {
2841
+ // beforeValidate: [beforeValidateHook],
2842
+ afterChange: [afterPageChangeHook],
2843
+ afterDelete: [afterPageDeleteHook]
2844
+ }
2845
+ };
2846
+ var withPage = /* @__PURE__ */ __name((config) => {
2847
+ const defaultConfig = { ...PageDefault };
2848
+ defaultConfig.admin.preview = (doc, { locale }) => {
2849
+ const previewUrl = process.env.PREVIEW_URL || "https://localhost:3000/";
2850
+ return `${previewUrl}preview?collection=${config.slug}&id=${doc.id}&slug=${doc.slug}&locale=${locale}&status=${doc._status}`;
2851
+ };
2852
+ const pageConfig = deepMerge(PageDefault, config);
2853
+ pageConfig.fields = [
2854
+ withTitleRequired(),
2855
+ withSlug({
2856
+ fieldToUse: "title",
2857
+ admin: {
2858
+ position: "sidebar"
2859
+ }
2860
+ }),
2861
+ withCategoryRequired({
2862
+ admin: {
2863
+ position: "sidebar"
2864
+ }
2865
+ }),
2866
+ withIsDefaultRequired({
2867
+ admin: {
2868
+ position: "sidebar"
2869
+ }
2870
+ }),
2871
+ withMarkets({
2872
+ admin: {
2873
+ position: "sidebar"
2874
+ }
2875
+ }),
2876
+ withTemplate({
2877
+ slugToUse: config.slug,
2878
+ admin: {
2879
+ position: "sidebar"
2880
+ }
2881
+ }),
2882
+ ...config.fields
2883
+ ];
2884
+ pageConfig.endpoints = [
2885
+ collectionGet(pageConfig.slug)
2886
+ ];
2887
+ translateCollection(pageConfig);
2888
+ const localizedConfig = withLocalized(pageConfig);
2889
+ return localizedConfig;
2890
+ }, "withPage");
2891
+
2892
+ // src/core/api/store.service.ts
2893
+ var import_qs3 = __toESM(require("qs"));
2894
+
2895
+ // src/core/api/route.service.ts
2896
+ var CACHE_ = new InMemoryCache();
2897
+ async function getRoutes(req) {
2898
+ const key = "route";
2899
+ if (CACHE_.has(key)) {
2900
+ return CACHE_.get(key);
2901
+ }
2902
+ const routes = [];
2903
+ let locales = await fetchGlobalItems(req, options.slug.locale, { depth: 0 });
2904
+ locales = locales.filter((x) => x.isActive);
2905
+ const languages = locales.map((x) => x.id);
2906
+ let markets = await fetchCollectionItems(req, options.slug.market, { depth: 0 });
2907
+ markets = markets.filter((x) => x.isActive).map((x) => ({
2908
+ id: x.id,
2909
+ languages: x.languages && x.languages.length ? x.languages : languages
2910
+ }));
2911
+ const categories = await fetchCollectionItems(req, options.slug.category, { depth: 1 });
2912
+ const keys = options.pages;
2913
+ for (const key2 of keys) {
2914
+ const items = await fetchCollectionItems(req, key2, { depth: 0 });
2915
+ for (const item of items) {
2916
+ const segments = getRouteSegments(key2, item, categories);
2917
+ const availableMarkets = item.markets ? markets.filter((x) => item.markets.indexOf(x.id) !== -1) : markets;
2918
+ availableMarkets.forEach((m) => {
2919
+ m.languages.forEach((l) => {
2920
+ const href = segments.reduce((p, c, i) => {
2921
+ let slug = c.slug;
2922
+ if (isLocalizedString(slug)) {
2923
+ slug = localizedToString(slug, l);
2924
+ }
2925
+ slug = `${p}/${slug}`;
2926
+ return slug === "/" ? "" : slug;
2927
+ }, "");
2928
+ let prefix = "";
2929
+ if (languages.length > 1 || markets.length > 1) {
2930
+ prefix = `/${l}`;
2931
+ }
2932
+ if (markets.length > 1) {
2933
+ prefix = `${prefix}-${m.id}`;
2934
+ }
2935
+ const route = {
2936
+ id: `${prefix}${href}`,
2937
+ market: m.id,
2938
+ locale: l,
2939
+ category: item.category,
2940
+ page: item.id,
2941
+ schema: key2,
2942
+ template: item.template
2943
+ };
2944
+ routes.push(route);
2945
+ });
2946
+ });
2947
+ if (key2 === "homepage") {
2948
+ const defaultLanguage = locales.find((x) => x.isDefault);
2949
+ const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
2950
+ const defaultMarketLanguage = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLanguage.id;
2951
+ const route = {
2952
+ id: "/",
2953
+ market: defaultMarket.id,
2954
+ locale: defaultMarketLanguage,
2955
+ category: item.category,
2956
+ page: item.id,
2957
+ schema: key2,
2958
+ template: item.template
2959
+ };
2960
+ routes.push(route);
2961
+ }
2962
+ }
2963
+ }
2964
+ CACHE_.set(key, routes);
2965
+ return routes;
2966
+ }
2967
+ __name(getRoutes, "getRoutes");
2968
+ async function getRoute(req, id) {
2969
+ const routes = await getRoutes(req);
2970
+ const route = routes.find((x) => x.id === id);
2971
+ return route || null;
2972
+ }
2973
+ __name(getRoute, "getRoute");
2974
+ function isLocalizedString(value) {
2975
+ let isLocalizedString2 = false;
2976
+ if (value) {
2977
+ if (!Array.isArray(value) && typeof value === "object") {
2978
+ const matchKeys = Object.keys(value).reduce((p, c) => p && /^(\w{2})(-\w{2})?$/.test(c), true);
2979
+ const matchValues = Object.values(value).reduce((p, c) => p && typeof c === "string", true);
2980
+ isLocalizedString2 = Boolean(matchKeys && matchValues);
2981
+ }
2982
+ }
2983
+ return isLocalizedString2;
2984
+ }
2985
+ __name(isLocalizedString, "isLocalizedString");
2986
+ function localizedToString(json, locale = "en", defaultLocale2 = "en") {
2987
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
2988
+ return localizedString;
2989
+ }
2990
+ __name(localizedToString, "localizedToString");
2991
+ function getRouteSegments(schema, item, categories) {
2992
+ const segments = [];
2993
+ let parentId = item.category || null;
2994
+ while (parentId != null) {
2995
+ const parentCategory = categories.find((c) => c.id === parentId);
2996
+ if (parentCategory) {
2997
+ if (parentCategory.slug) {
2998
+ const segment = { ...parentCategory };
2999
+ segments.unshift(segment);
3000
+ }
3001
+ parentId = parentCategory.category ? parentCategory.category.id : null;
3002
+ } else {
3003
+ parentId = null;
3004
+ }
3005
+ }
3006
+ if (item.isDefault !== true) {
3007
+ segments.push({
3008
+ id: item.id,
3009
+ title: item.title,
3010
+ slug: item.slug,
3011
+ schema,
3012
+ page: item.id,
3013
+ media: null
3014
+ // item.media,
3015
+ });
3016
+ }
3017
+ return segments;
3018
+ }
3019
+ __name(getRouteSegments, "getRouteSegments");
3020
+ var routeGet = {
3021
+ path: "/route",
3022
+ method: "get",
3023
+ handler: async (req, res, next) => {
3024
+ const routes = await getRoutes(req);
3025
+ if (typeof req.query.where === "object") {
3026
+ const items = await whereCollection(routes, req.query.where);
3027
+ if (items.length) {
3028
+ res.status(200).send(items);
3029
+ } else {
3030
+ res.status(404);
3031
+ }
3032
+ } else {
3033
+ res.status(200).send(routes);
3034
+ }
3035
+ }
3036
+ };
3037
+
3038
+ // src/core/api/store.service.ts
3039
+ var CACHE_2 = new InMemoryCache();
3040
+ async function getStore(req) {
3041
+ const key = keyWithRequest("store", req);
3042
+ if (CACHE_2.has(key)) {
3043
+ return CACHE_2.get(key);
3044
+ }
3045
+ const store = {};
3046
+ for (const slug of options.collections) {
3047
+ const collection = await fetchCollection(req, slug);
3048
+ store[slug] = collection.docs;
3049
+ }
3050
+ const locale = await fetchGlobal(req, "locale");
3051
+ store.locale = locale.items;
3052
+ const routes = await getRoutes(req);
3053
+ store.route = routes;
3054
+ CACHE_2.set(key, store);
3055
+ return store;
3056
+ }
3057
+ __name(getStore, "getStore");
3058
+ function getApiUrl(req) {
3059
+ const { payload } = req;
3060
+ const { config } = payload;
3061
+ const url = `${config.serverURL}${config.routes.api}/`;
3062
+ return url;
3063
+ }
3064
+ __name(getApiUrl, "getApiUrl");
3065
+ function getSearchUrl(req, overrideQuery) {
3066
+ const { query } = req;
3067
+ const params = Object.assign({
3068
+ locale: "*",
3069
+ depth: 1,
3070
+ limit: 1e4
3071
+ }, overrideQuery || query);
3072
+ const search = import_qs3.default.stringify(params);
3073
+ const url = search ? `?${search}` : "";
3074
+ return url;
3075
+ }
3076
+ __name(getSearchUrl, "getSearchUrl");
3077
+ async function fetchEndpoint(req, endpoint, query) {
3078
+ try {
3079
+ const apiUrl = getApiUrl(req);
3080
+ const searchUrl = getSearchUrl(req, query);
3081
+ const url = `${apiUrl}${endpoint}${searchUrl}`;
3082
+ const httpGetResponse = await fetch(url, {
3083
+ method: "GET",
3084
+ headers: {
3085
+ "Content-Type": "application/json"
3086
+ }
3087
+ });
3088
+ if (!httpGetResponse.ok) {
3089
+ throw httpGetResponse;
3090
+ }
3091
+ const json = await httpGetResponse.json();
3092
+ return json;
3093
+ } catch (error) {
3094
+ console.log("StoreService.fetchEndpoint.error", error);
3095
+ throw error;
3096
+ }
3097
+ }
3098
+ __name(fetchEndpoint, "fetchEndpoint");
3099
+ async function fetchCollection(req, slug, query) {
3100
+ return await fetchEndpoint(req, slug, query);
3101
+ }
3102
+ __name(fetchCollection, "fetchCollection");
3103
+ async function fetchGlobal(req, slug, query) {
3104
+ return await fetchEndpoint(req, `globals/${slug}`, query);
3105
+ }
3106
+ __name(fetchGlobal, "fetchGlobal");
3107
+ async function fetchCollectionItems(req, slug, query) {
3108
+ const collection = await fetchCollection(req, slug, query);
3109
+ if (collection) {
3110
+ return collection.docs;
3111
+ }
3112
+ return [];
3113
+ }
3114
+ __name(fetchCollectionItems, "fetchCollectionItems");
3115
+ async function fetchGlobalItems(req, slug, query) {
3116
+ const collection = await fetchGlobal(req, slug, query);
3117
+ if (collection) {
3118
+ return collection.items;
3119
+ }
3120
+ return [];
3121
+ }
3122
+ __name(fetchGlobalItems, "fetchGlobalItems");
3123
+ var storeGet = {
3124
+ path: "/store",
3125
+ method: "get",
3126
+ handler: async (req, res, next) => {
3127
+ const store = await getStore(req);
3128
+ res.status(200).send(store);
3129
+ }
3130
+ };
3131
+
3132
+ // src/core/api/locale.service.ts
3133
+ async function getLocale(req) {
3134
+ let locales = await fetchGlobalItems(req, options.slug.locale, { depth: 0 });
3135
+ locales = locales.filter((x) => x.isActive);
3136
+ return locales;
3137
+ }
3138
+ __name(getLocale, "getLocale");
3139
+ var localeGet = {
3140
+ path: "/locale",
3141
+ method: "get",
3142
+ handler: async (req, res, next) => {
3143
+ const loader = getStaticLoader(options.slug.language);
3144
+ const languages = await loader();
3145
+ let items = await getLocale(req);
3146
+ if (typeof req.query.where === "object") {
3147
+ items = await whereCollection(items, req.query.where);
3148
+ }
3149
+ items = items.map((item) => {
3150
+ const language = languages.find((x) => x.id === item.id);
3151
+ item.title = language ? language.name : null;
3152
+ return item;
3153
+ });
3154
+ items = await localizeCollection(items, ["title"], getStringParam(req.query.locale));
3155
+ if (items.length) {
3156
+ res.status(200).send(items);
3157
+ } else {
3158
+ res.status(404);
3159
+ }
3160
+ }
3161
+ };
3162
+
3163
+ // src/globals/Locale.ts
3164
+ var Locale = /* @__PURE__ */ __name((options2) => ({
3165
+ type: "withGlobal",
3166
+ slug: options2.slug.locale,
3167
+ admin: {
3168
+ group: options2.group.admin
3169
+ },
3170
+ access: {
3171
+ read: () => true
3172
+ },
3173
+ hooks: {
3174
+ afterRead: [async ({
3175
+ doc,
3176
+ // full document data
3177
+ req,
3178
+ // full express request
3179
+ findMany
3180
+ // boolean to denote if this hook is running against finding one, or finding many (useful in versions)
3181
+ }) => {
3182
+ doc = doc || {};
3183
+ const newDoc = doc.items ? doc : {
3184
+ items: [],
3185
+ globalType: "locale"
3186
+ };
3187
+ newDoc.items = options2.locales.map((locale) => {
3188
+ const defaultItem = {
3189
+ id: locale,
3190
+ isActive: false,
3191
+ isDefault: false
3192
+ };
3193
+ const item = Object.assign(defaultItem, newDoc.items.find((x) => x.id === locale) || {});
3194
+ item.isDefault = locale === options2.defaultLocale;
3195
+ return item;
3196
+ });
3197
+ return newDoc;
3198
+ }]
3199
+ },
3200
+ fields: [
3201
+ {
3202
+ name: "items",
3203
+ type: "array",
3204
+ minRows: options2.locales.length,
3205
+ maxRows: options2.locales.length,
3206
+ required: true,
3207
+ admin: {
3208
+ components: {
3209
+ RowLabel: ({ data, path, index }) => {
3210
+ return data?.id || options2.locales[index - 1];
3211
+ }
3212
+ }
3213
+ },
3214
+ fields: [
3215
+ {
3216
+ name: "id",
3217
+ type: "relationship",
3218
+ relationTo: options2.slug.language,
3219
+ required: true,
3220
+ admin: {
3221
+ readOnly: true
3222
+ }
3223
+ },
3224
+ { type: "withIsActive", required: true },
3225
+ {
3226
+ type: "withIsDefault",
3227
+ required: true,
3228
+ admin: {
3229
+ readOnly: true
3230
+ }
3231
+ }
3232
+ ]
3233
+ }
3234
+ ]
3235
+ }), "Locale");
3236
+
3237
+ // src/fields/color-picker/ColorCell.tsx
3238
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3239
+ var ColorCell = /* @__PURE__ */ __name((props) => {
3240
+ const { cellData } = props;
3241
+ if (!cellData)
3242
+ return null;
3243
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3244
+ "div",
3245
+ {
3246
+ className: "chip",
3247
+ style: { backgroundColor: cellData }
3248
+ }
3249
+ );
3250
+ }, "ColorCell");
3251
+
3252
+ // src/fields/color-picker/ColorField.tsx
3253
+ var import_react8 = require("react");
3254
+ var import_forms5 = require("payload/components/forms");
3255
+ var import_preferences = require("payload/components/preferences");
3256
+ var import_components3 = require("payload/components");
3257
+ var import_forms6 = require("payload/components/forms");
3258
+ var import_jsx_runtime11 = require("react/jsx-runtime");
3259
+ var defaultColors = [
3260
+ "#333333",
3261
+ "#9A9A9A",
3262
+ "#F3F3F3",
3263
+ "#FF6F76",
3264
+ "#FDFFA4",
3265
+ "#B2FFD6",
3266
+ "#F3DDF3"
3267
+ ];
3268
+ var baseClass6 = "custom-color-picker";
3269
+ var preferenceKey = "color-picker-colors";
3270
+ var ColorField = /* @__PURE__ */ __name((props) => {
3271
+ const { path, label, required } = props;
3272
+ const { value = "", setValue } = (0, import_forms5.useFieldType)({ path, validate: validateHexColor });
3273
+ const { getPreference, setPreference } = (0, import_preferences.usePreferences)();
3274
+ const [colorOptions, setColorOptions] = (0, import_react8.useState)(defaultColors);
3275
+ const [isAdding, setIsAdding] = (0, import_react8.useState)(false);
3276
+ const [colorToAdd, setColorToAdd] = (0, import_react8.useState)("");
3277
+ (0, import_react8.useEffect)(() => {
3278
+ const mergeColorsFromPreferences = /* @__PURE__ */ __name(async () => {
3279
+ const colorPreferences = await getPreference(preferenceKey);
3280
+ if (colorPreferences) {
3281
+ setColorOptions(colorPreferences);
3282
+ }
3283
+ }, "mergeColorsFromPreferences");
3284
+ mergeColorsFromPreferences();
3285
+ }, [getPreference, setColorOptions]);
3286
+ const handleAddColor = (0, import_react8.useCallback)(() => {
3287
+ setIsAdding(false);
3288
+ setValue(colorToAdd);
3289
+ if (colorOptions.indexOf(colorToAdd) > -1) {
3290
+ return;
3291
+ }
3292
+ const newOptions = colorOptions;
3293
+ newOptions.unshift(colorToAdd);
3294
+ setColorOptions(newOptions);
3295
+ setPreference(preferenceKey, newOptions);
3296
+ }, [colorOptions, setPreference, colorToAdd, setIsAdding, setValue]);
3297
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: baseClass6, children: [
3298
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_forms6.Label, { htmlFor: path, label, required }),
3299
+ isAdding && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { children: [
3300
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("input", { className: `${baseClass6}__input`, type: "text", placeholder: "#000000", value: colorToAdd, onChange: (e) => setColorToAdd(e.target.value) }),
3301
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3302
+ import_components3.Button,
3303
+ {
3304
+ className: `${baseClass6}__btn`,
3305
+ buttonStyle: "primary",
3306
+ iconPosition: "left",
3307
+ iconStyle: "with-border",
3308
+ size: "small",
3309
+ disabled: validateHexColor(colorToAdd) !== true,
3310
+ onClick: handleAddColor,
3311
+ children: "Add"
3312
+ }
3313
+ ),
3314
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3315
+ import_components3.Button,
3316
+ {
3317
+ className: `${baseClass6}__btn`,
3318
+ buttonStyle: "secondary",
3319
+ iconPosition: "left",
3320
+ iconStyle: "with-border",
3321
+ size: "small",
3322
+ onClick: () => setIsAdding(false),
3323
+ children: "Cancel"
3324
+ }
3325
+ )
3326
+ ] }),
3327
+ !isAdding && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react8.Fragment, { children: [
3328
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("ul", { className: `${baseClass6}__colors`, children: colorOptions.map((color, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3329
+ "button",
3330
+ {
3331
+ type: "button",
3332
+ className: `chip ${color === value ? "chip--selected" : ""} chip--clickable`,
3333
+ style: { backgroundColor: color },
3334
+ "aria-label": color,
3335
+ onClick: () => setValue(color)
3336
+ },
3337
+ color
3338
+ ) }, i)) }),
3339
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3340
+ import_components3.Button,
3341
+ {
3342
+ className: "add-color",
3343
+ icon: "plus",
3344
+ buttonStyle: "icon-label",
3345
+ iconPosition: "left",
3346
+ iconStyle: "with-border",
3347
+ onClick: () => {
3348
+ setIsAdding(true);
3349
+ setValue("");
3350
+ }
3351
+ }
3352
+ )
3353
+ ] })
3354
+ ] });
3355
+ }, "ColorField");
3356
+
3357
+ // src/fields/color-picker/index.ts
3358
+ var validateHexColor = /* @__PURE__ */ __name((value = "") => {
3359
+ return value.match(/^#(?:[0-9a-fA-F]{3}){1,2}$/) !== null || "Please give a valid hex color";
3360
+ }, "validateHexColor");
3361
+ var ColorConfig = {
3362
+ type: "text",
3363
+ name: "color",
3364
+ validate: validateHexColor,
3365
+ admin: {
3366
+ components: {
3367
+ Field: ColorField,
3368
+ Cell: ColorCell
3369
+ }
3370
+ }
3371
+ };
3372
+ var withColor = /* @__PURE__ */ __name((options2 = {}) => {
3373
+ const field = deepMerge(ColorConfig, options2);
3374
+ return field;
3375
+ }, "withColor");
3376
+ var withColorRequired = /* @__PURE__ */ __name((options2 = {}) => {
3377
+ const field = deepMerge({
3378
+ ...ColorConfig,
3379
+ required: true
3380
+ }, options2);
3381
+ return field;
3382
+ }, "withColorRequired");
3383
+
3384
+ // src/fields/debug-field/DebugField.tsx
3385
+ var import_utilities6 = require("payload/components/utilities");
3386
+ var import_react9 = require("react");
3387
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3388
+ var baseClass7 = "custom-text";
3389
+ var DebugField = /* @__PURE__ */ __name((props) => {
3390
+ const { path, type, fieldTypes: fieldTypes2 } = props;
3391
+ const schema = (0, import_react9.useMemo)(() => ({ ...props, admin: { ...props.admin, components: null } }), [path]);
3392
+ const locale = (0, import_utilities6.useLocale)();
3393
+ const FieldComponent = fieldTypes2[type];
3394
+ const fieldKey = `${locale}-custom-text-${path}`;
3395
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${baseClass7}`, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FieldComponent, { ...schema }, fieldKey) });
3396
+ }, "DebugField");
3397
+
3398
+ // src/fields/debug-field/index.ts
3399
+ var debugField = /* @__PURE__ */ __name((options2 = {}) => {
3400
+ const baseOptions = {
3401
+ name: "text",
3402
+ type: "text",
3403
+ admin: {
3404
+ components: {
3405
+ Field: DebugField
3406
+ }
3407
+ }
3408
+ };
3409
+ return deepMerge(
3410
+ baseOptions,
3411
+ options2
3412
+ );
3413
+ }, "debugField");
3414
+
3415
+ // src/fields/ui-static/UIStaticCell.tsx
3416
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3417
+ var UIStaticCell = /* @__PURE__ */ __name(({ cellData, colIndex, collection, field, rowData }) => {
3418
+ if (!cellData)
3419
+ return null;
3420
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: cellData.toString() });
3421
+ }, "UIStaticCell");
3422
+
3423
+ // src/fields/ui-static/UIStaticField.tsx
3424
+ var import_forms7 = require("payload/components/forms");
3425
+ var import_utilities7 = require("payload/components/utilities");
3426
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3427
+ var UIStaticField = /* @__PURE__ */ __name((props) => {
3428
+ const { path, label, required } = props;
3429
+ const config = (0, import_utilities7.useConfig)();
3430
+ const locales = config.localization ? config.localization.locales : [];
3431
+ const defaultLocale2 = config.localization ? config.localization.defaultLocale : null;
3432
+ const locale = (0, import_utilities7.useLocale)();
3433
+ const documentInfo = (0, import_utilities7.useDocumentInfo)();
3434
+ const { value, setValue } = (0, import_forms7.useField)({ path });
3435
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "field-type text localized-text", children: [
3436
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_forms7.Label, { htmlFor: path, label, required }),
3437
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { type: "text", id: path, name: typeof label === "string" ? label : void 0, value, readOnly: true })
3438
+ ] }) });
3439
+ }, "UIStaticField");
3440
+
3441
+ // src/fields/ui-static/index.ts
3442
+ var withUIStatic = /* @__PURE__ */ __name((options2 = {}) => {
3443
+ const baseOptions = {
3444
+ name: "uiStatic",
3445
+ type: "ui",
3446
+ admin: {
3447
+ components: {
3448
+ Field: UIStaticField,
3449
+ Cell: UIStaticCell
3450
+ }
3451
+ }
3452
+ };
3453
+ return deepMerge(
3454
+ baseOptions,
3455
+ options2
3456
+ );
3457
+ }, "withUIStatic");
3458
+
3459
+ // src/mapper.ts
3460
+ function toCollection(collection) {
3461
+ const type = collection.type;
3462
+ const fields = collection.fields.map((x) => toField(x));
3463
+ delete collection.type;
3464
+ delete collection.fields;
3465
+ const item = {
3466
+ ...collection,
3467
+ fields
3468
+ };
3469
+ switch (type) {
3470
+ case "withPage":
3471
+ return withPage(item);
3472
+ case "withCollection":
3473
+ return withCollection(item);
3474
+ case "withStatic":
3475
+ return withStaticCollection(item);
3476
+ default:
3477
+ return item;
3478
+ }
3479
+ }
3480
+ __name(toCollection, "toCollection");
3481
+ function toGlobal(collection) {
3482
+ const type = collection.type;
3483
+ const fields = collection.fields.map((x) => toField(x));
3484
+ delete collection.type;
3485
+ delete collection.fields;
3486
+ const item = {
3487
+ ...collection,
3488
+ fields
3489
+ };
3490
+ switch (type) {
3491
+ case "withGlobal":
3492
+ return withGlobal(item);
3493
+ default:
3494
+ return item;
3495
+ }
3496
+ }
3497
+ __name(toGlobal, "toGlobal");
3498
+ function toField(item) {
3499
+ if (item["fields"]) {
3500
+ item["fields"] = item["fields"].map((x) => toField(x));
3501
+ }
3502
+ if (item["blocks"]) {
3503
+ item["blocks"] = item["blocks"].map((x) => toBlock(x));
3504
+ }
3505
+ if (item["tabs"]) {
3506
+ item["tabs"] = item["tabs"].map((x) => toTab(x));
3507
+ }
3508
+ switch (item.type) {
3509
+ case "withAbstract":
3510
+ delete item.type;
3511
+ return withAbstract(item);
3512
+ case "withCategory":
3513
+ delete item.type;
3514
+ return withCategory(item);
3515
+ case "withCheckbox":
3516
+ delete item.type;
3517
+ return withCheckbox(item);
3518
+ case "withColor":
3519
+ delete item.type;
3520
+ return withColor(item);
3521
+ case "withComponents":
3522
+ delete item.type;
3523
+ return withComponents(item);
3524
+ case "withDate":
3525
+ delete item.type;
3526
+ return withDate(item);
3527
+ case "withDescription":
3528
+ delete item.type;
3529
+ return withDescription(item);
3530
+ case "withId":
3531
+ delete item.type;
3532
+ return withId(item);
3533
+ case "withIsActive":
3534
+ delete item.type;
3535
+ return withIsActive(item);
3536
+ case "withIsDefault":
3537
+ delete item.type;
3538
+ return withIsDefault(item);
3539
+ case "withLink":
3540
+ delete item.type;
3541
+ return withLink(item);
3542
+ case "withMarkets":
3543
+ delete item.type;
3544
+ return withMarkets(item);
3545
+ case "withMedia":
3546
+ delete item.type;
3547
+ return withMedia(item);
3548
+ case "withMedias":
3549
+ delete item.type;
3550
+ return withMedias(item);
3551
+ case "withName":
3552
+ delete item.type;
3553
+ return withName(item);
3554
+ case "withRelated":
3555
+ delete item.type;
3556
+ return withRelated(item);
3557
+ case "withRichText":
3558
+ delete item.type;
3559
+ return withRichText(item);
3560
+ case "withSelect":
3561
+ delete item.type;
3562
+ return withSelect(item);
3563
+ case "withSlug":
3564
+ delete item.type;
3565
+ return withSlug(item);
3566
+ case "withTemplate":
3567
+ delete item.type;
3568
+ return withTemplate(item);
3569
+ case "withText":
3570
+ delete item.type;
3571
+ return withText(item);
3572
+ case "withTitle":
3573
+ delete item.type;
3574
+ return withTitle(item);
3575
+ case "array":
3576
+ const array = item;
3577
+ array.fields = array.fields.map((x) => toField(x));
3578
+ return array;
3579
+ case "blocks":
3580
+ const blocks = item;
3581
+ blocks.blocks = blocks.blocks.map((x) => toBlock(x));
3582
+ return blocks;
3583
+ case "collapsible":
3584
+ const collapsible = item;
3585
+ collapsible.fields = collapsible.fields.map((x) => toField(x));
3586
+ return collapsible;
3587
+ case "group":
3588
+ const group = item;
3589
+ group.fields = group.fields.map((x) => toField(x));
3590
+ return group;
3591
+ case "row":
3592
+ const row = item;
3593
+ row.fields = row.fields.map((x) => toField(x));
3594
+ return row;
3595
+ case "tabs":
3596
+ const tabs = item;
3597
+ tabs.tabs = tabs.tabs.map((x) => toTab(x));
3598
+ return tabs;
3599
+ default:
3600
+ return item;
3601
+ }
3602
+ }
3603
+ __name(toField, "toField");
3604
+ function toBlock(item) {
3605
+ item.fields = item.fields.map((x) => toField(x));
3606
+ return withBlock(item);
3607
+ }
3608
+ __name(toBlock, "toBlock");
3609
+ function toTab(item) {
3610
+ item.fields = item.fields.map((x) => toField(x));
3611
+ return item;
3612
+ }
3613
+ __name(toTab, "toTab");
3614
+
3615
+ // src/bowl.ts
3616
+ var bowl = /* @__PURE__ */ __name((sourceOptions = {}) => (sourceConfig) => {
3617
+ const bowlCollections = [
3618
+ // Content
3619
+ Media,
3620
+ // Navigation
3621
+ Category,
3622
+ Page,
3623
+ // Configuration
3624
+ Label,
3625
+ Market,
3626
+ Template,
3627
+ // I18N
3628
+ Language,
3629
+ Continent,
3630
+ SubContinent,
3631
+ Country,
3632
+ CountryZone,
3633
+ Region,
3634
+ Province,
3635
+ Municipality
3636
+ // Admin
3637
+ ];
3638
+ const bowlGlobals = [
3639
+ // Admin
3640
+ Locale
3641
+ ];
3642
+ const sourceCollections = sourceConfig.collections || [];
3643
+ const sourceGlobals = sourceConfig.globals || [];
3644
+ const pages = [
3645
+ ...sourceCollections.filter((x) => x.type === "withPage").map((x) => x.slug),
3646
+ ...sourceGlobals.filter((x) => x.type === "withPage").map((x) => x.slug)
3647
+ ];
3648
+ options.pages = pages;
3649
+ if (sourceOptions.group) {
3650
+ options.group = Object.assign(options.group, sourceOptions.group);
3651
+ }
3652
+ if (sourceOptions.slug) {
3653
+ options.slug = Object.assign(options.slug, sourceOptions.slug);
3654
+ }
3655
+ if (sourceConfig.localization && sourceConfig.localization.locales) {
3656
+ options.locales = sourceConfig.localization.locales;
3657
+ }
3658
+ if (sourceConfig.localization && sourceConfig.localization.defaultLocale) {
3659
+ options.defaultLocale = sourceConfig.localization.defaultLocale;
3660
+ }
3661
+ if (sourceConfig.i18n && sourceConfig.i18n.resources) {
3662
+ options.translations = deepMerge(options.translations, sourceConfig.i18n.resources);
3663
+ }
3664
+ const filteredCollections = sourceCollections.filter((x) => !internalSlugs.includes(x.slug));
3665
+ const filteredGlobals = sourceGlobals.filter((x) => !internalSlugs.includes(x.slug));
3666
+ const unmappedCollections = [
3667
+ ...filteredCollections,
3668
+ ...bowlCollections.map((x) => x(options))
3669
+ ];
3670
+ const unmappedGlobals = [
3671
+ ...filteredGlobals,
3672
+ ...bowlGlobals.map((x) => x(options))
3673
+ ];
3674
+ const collections = unmappedCollections.map((x) => toCollection(x));
3675
+ const globals = unmappedGlobals.map((x) => toGlobal(x));
3676
+ options.collections = collections.map((x) => x.slug);
3677
+ const sourceEndpoints = sourceConfig.endpoints || [];
3678
+ const targetConfig = {
3679
+ ...sourceConfig,
3680
+ collections,
3681
+ globals,
3682
+ endpoints: [
3683
+ storeGet,
3684
+ routeGet,
3685
+ localeGet,
3686
+ ...sourceEndpoints
3687
+ ]
3688
+ };
3689
+ logMissingTranslations();
3690
+ return targetConfig;
3691
+ }, "bowl");
3692
+
3693
+ // src/index.ts
3694
+ var src_default = bowl;
3695
+ // Annotate the CommonJS export names for ESM import in node:
3696
+ 0 && (module.exports = {
3697
+ BlockDefaults,
3698
+ CategoryDefaults,
3699
+ CheckboxDefaults,
3700
+ CollectionDefault,
3701
+ ColorCell,
3702
+ ColorConfig,
3703
+ ColorField,
3704
+ ComponentsDefaults,
3705
+ DateDefaults,
3706
+ DebugField,
3707
+ GlobalDefault,
3708
+ InMemoryCache,
3709
+ LocalizedField,
3710
+ MarketDefaults,
3711
+ MediaDefaults,
3712
+ MediasDefaults,
3713
+ PageDefault,
3714
+ RelatedDefaults,
3715
+ RichTextDefaults,
3716
+ SelectDefaults,
3717
+ StaticCollectionDefault,
3718
+ TemplateDefaults,
3719
+ TextDefaults,
3720
+ UILanguagesCell,
3721
+ UILanguagesField,
3722
+ UIStaticCell,
3723
+ UIStaticField,
3724
+ afterPageChangeHook,
3725
+ afterPageDeleteHook,
3726
+ appearanceOptions,
3727
+ bowl,
3728
+ collectionGet,
3729
+ debugField,
3730
+ deepMerge,
3731
+ defaultGroup,
3732
+ defaultLocale,
3733
+ defaultLocales,
3734
+ defaultSlug,
3735
+ fetchCollection,
3736
+ fetchCollectionItems,
3737
+ fetchEndpoint,
3738
+ fetchGlobal,
3739
+ fetchGlobalItems,
3740
+ formatSlug,
3741
+ getApiUrl,
3742
+ getLocale,
3743
+ getNumericParam,
3744
+ getObjectParam,
3745
+ getRoute,
3746
+ getRoutes,
3747
+ getSearchUrl,
3748
+ getStaticLoader,
3749
+ getStore,
3750
+ getStringParam,
3751
+ getTranslation,
3752
+ getTranslations,
3753
+ internalSlugs,
3754
+ isObject,
3755
+ keyWithRequest,
3756
+ localeGet,
3757
+ localizeCollection,
3758
+ localizedField,
3759
+ logMissingTranslations,
3760
+ options,
3761
+ populateStaticFields,
3762
+ richTextAfterReadHook,
3763
+ richTextSerialize,
3764
+ routeGet,
3765
+ slugToLabel,
3766
+ slugToLabels,
3767
+ storeGet,
3768
+ toBlock,
3769
+ toCollection,
3770
+ toField,
3771
+ toGlobal,
3772
+ toTab,
3773
+ translateBlock,
3774
+ translateBlocks,
3775
+ translateCollection,
3776
+ translateField,
3777
+ translateFields,
3778
+ translateGlobal,
3779
+ translateTab,
3780
+ translateTabs,
3781
+ validateHexColor,
3782
+ whereCollection,
3783
+ withAbstract,
3784
+ withAbstractRequired,
3785
+ withBlock,
3786
+ withCategory,
3787
+ withCategoryRequired,
3788
+ withCheckbox,
3789
+ withCheckboxRequired,
3790
+ withCollection,
3791
+ withCollectionHook,
3792
+ withColor,
3793
+ withColorRequired,
3794
+ withComponents,
3795
+ withDate,
3796
+ withDateRequired,
3797
+ withDescription,
3798
+ withDescriptionRequired,
3799
+ withFieldHook,
3800
+ withGlobal,
3801
+ withGlobalHook,
3802
+ withId,
3803
+ withIdRequired,
3804
+ withIsActive,
3805
+ withIsActiveRequired,
3806
+ withIsDefault,
3807
+ withIsDefaultRequired,
3808
+ withLink,
3809
+ withLocalized,
3810
+ withMarkets,
3811
+ withMarketsRequired,
3812
+ withMedia,
3813
+ withMediaRequired,
3814
+ withMedias,
3815
+ withMediasRequired,
3816
+ withName,
3817
+ withNameRequired,
3818
+ withPage,
3819
+ withRelated,
3820
+ withRichText,
3821
+ withRichTextRequired,
3822
+ withSelect,
3823
+ withSelectRequired,
3824
+ withSlug,
3825
+ withSlugRequired,
3826
+ withStaticCollection,
3827
+ withTemplate,
3828
+ withTemplateRequired,
3829
+ withText,
3830
+ withTextRequired,
3831
+ withTitle,
3832
+ withTitleRequired,
3833
+ withUILanguages,
3834
+ withUIStatic
3835
+ });