@firecms/core 3.5.2-canary.09e1281 → 3.5.2-canary.a0001bd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/components/EntityCollectionView/utils.d.ts +1 -0
  2. package/dist/{de-CUF9f7S-.js → de-CNfJQcnh.js} +1 -1
  3. package/dist/{de-CUF9f7S-.js.map → de-CNfJQcnh.js.map} +1 -1
  4. package/dist/{editor-WZytSO_1.js → editor-D0A5yaaJ.js} +1 -1
  5. package/dist/{editor-WZytSO_1.js.map → editor-D0A5yaaJ.js.map} +1 -1
  6. package/dist/{fr-DmkMX6hp.js → fr-CBtSvDVp.js} +1 -1
  7. package/dist/{fr-DmkMX6hp.js.map → fr-CBtSvDVp.js.map} +1 -1
  8. package/dist/{hi-BKuaMr7w.js → hi-Delc4l61.js} +1 -1
  9. package/dist/{hi-BKuaMr7w.js.map → hi-Delc4l61.js.map} +1 -1
  10. package/dist/index.es.js +101 -197
  11. package/dist/index.es.js.map +1 -1
  12. package/dist/index.umd.js +93 -189
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/{it-BwQflFGz.js → it-CdsoaRVO.js} +1 -1
  15. package/dist/{it-BwQflFGz.js.map → it-CdsoaRVO.js.map} +1 -1
  16. package/dist/{pl-BPsAvZvc.js → pl-DoTvWcwp.js} +1 -1
  17. package/dist/{pl-BPsAvZvc.js.map → pl-DoTvWcwp.js.map} +1 -1
  18. package/dist/preview/components/__tests__/DatePreview.test.d.ts +1 -0
  19. package/dist/{pt-D5q7OQp1.js → pt-DCfk8Nkq.js} +1 -1
  20. package/dist/{pt-D5q7OQp1.js.map → pt-DCfk8Nkq.js.map} +1 -1
  21. package/dist/types/locales.d.ts +1 -1
  22. package/dist/util/__tests__/locales.test.d.ts +1 -0
  23. package/dist/util/date_fns_locales.d.ts +13 -0
  24. package/package.json +3 -3
  25. package/src/components/EntityCollectionView/EntityIdHeaderWidget.tsx +50 -8
  26. package/src/components/EntityCollectionView/utils.ts +6 -0
  27. package/src/form/field_bindings/BlockFieldBinding.tsx +2 -1
  28. package/src/preview/components/DatePreview.tsx +14 -2
  29. package/src/preview/components/__tests__/DatePreview.test.tsx +39 -0
  30. package/src/types/locales.ts +2 -0
  31. package/src/util/__tests__/locales.test.ts +46 -0
  32. package/src/util/date_fns_locales.ts +28 -0
@@ -96,6 +96,7 @@ export function BlockFieldBinding<T extends Array<any>>({
96
96
  </div>
97
97
  );
98
98
 
99
+ const canAddElements = !property.disabled && !isSubmitting && !disabled && (property.canAddElements ?? true);
99
100
  const firstOneOfKey = Object.keys(property.oneOf.properties)[0];
100
101
  const body = <ArrayContainer value={value}
101
102
  className={"flex flex-col gap-3"}
@@ -104,7 +105,7 @@ export function BlockFieldBinding<T extends Array<any>>({
104
105
  buildEntry={buildEntry}
105
106
  onInternalIdAdded={setLastAddedId}
106
107
  disabled={isSubmitting || Boolean(property.disabled)}
107
- canAddElements={!property.disabled}
108
+ canAddElements={canAddElements}
108
109
  onValueChange={(value) => setFieldValue(propertyKey, value)}
109
110
  newDefaultEntry={{
110
111
  [property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE]: firstOneOfKey,
@@ -2,7 +2,7 @@ import React from "react";
2
2
 
3
3
  import { format } from "date-fns";
4
4
  import { useCustomizationController } from "../../hooks";
5
- import { defaultDateFormat, useDateFnsLocale } from "../../util";
5
+ import { defaultDateFormat, localeToLanguageTag, useDateFnsLocale } from "../../util";
6
6
 
7
7
  export interface DatePreviewProps {
8
8
  date: Date;
@@ -17,6 +17,18 @@ export interface DatePreviewProps {
17
17
  timezone?: string;
18
18
  }
19
19
 
20
+ /**
21
+ * The locale is a date-fns key ("enUS", "ptBR"), which `Intl` refuses: it threw here,
22
+ * and took the field down with it, for every region locale.
23
+ */
24
+ function dateTimeFormat(locale: string | undefined, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {
25
+ try {
26
+ return new Intl.DateTimeFormat(locale ? localeToLanguageTag(locale) : "en-US", options);
27
+ } catch {
28
+ return new Intl.DateTimeFormat("en-US", options);
29
+ }
30
+ }
31
+
20
32
  /**
21
33
  * @group Preview components
22
34
  */
@@ -47,7 +59,7 @@ export function DatePreview({
47
59
  options.minute = "2-digit";
48
60
  }
49
61
 
50
- const formatter = new Intl.DateTimeFormat(customizationController?.locale ?? "en-US", options);
62
+ const formatter = dateTimeFormat(customizationController?.locale, options);
51
63
  const formattedDate = formatter.format(date);
52
64
 
53
65
  // Get timezone abbreviation
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import { describe, expect, it } from "@jest/globals";
5
+ import React from "react";
6
+ import { render } from "@testing-library/react";
7
+
8
+ import { DatePreview } from "../DatePreview";
9
+ import { CustomizationControllerContext } from "../../../contexts/CustomizationControllerContext";
10
+ import { CustomizationController } from "../../../types";
11
+
12
+ // FireCMS locales are date-fns keys. Intl.DateTimeFormat threw on a region key such as
13
+ // "enUS", so a date with a timezone took its whole field down for those projects.
14
+
15
+ function renderWithLocale(locale: string | undefined) {
16
+ return render(
17
+ <CustomizationControllerContext.Provider value={{ locale } as CustomizationController}>
18
+ <DatePreview date={new Date("2026-11-10T09:30:00Z")} mode="date" timezone="Europe/Madrid"/>
19
+ </CustomizationControllerContext.Provider>
20
+ );
21
+ }
22
+
23
+ describe("DatePreview with a timezone", () => {
24
+
25
+ it("formats in a region locale's language tag", () => {
26
+ const { container } = renderWithLocale("ptBR");
27
+ expect(container.textContent).toContain("2026");
28
+ expect(container.textContent).toContain("nov");
29
+ });
30
+
31
+ it("formats with a plain language key", () => {
32
+ expect(renderWithLocale("es").container.textContent).toContain("2026");
33
+ expect(renderWithLocale(undefined).container.textContent).toContain("Nov 10, 2026");
34
+ });
35
+
36
+ it("falls back to en-US for a stored value Intl can't read", () => {
37
+ expect(renderWithLocale("en_US").container.textContent).toContain("Nov 10, 2026");
38
+ });
39
+ });
@@ -17,6 +17,8 @@ export type Locale =
17
17
  "da" |
18
18
  "de" |
19
19
  "el" |
20
+ // date-fns's built-in English (en-US), what FireCMS Cloud stores for English
21
+ "en" |
20
22
  "enAU" |
21
23
  "enCA" |
22
24
  "enGB" |
@@ -0,0 +1,46 @@
1
+ import { describe, expect, it } from "@jest/globals";
2
+ import { localeToLanguageTag, resolveLocale } from "../date_fns_locales";
3
+
4
+ // FireCMS locales are date-fns keys ("enUS", "ptBR"). On 2026-11-10 FireCMS Cloud stored
5
+ // "en_US" through the MCP server, and a key such as "enUS" itself made
6
+ // Intl.DateTimeFormat throw in DatePreview.
7
+
8
+ describe("resolveLocale", () => {
9
+
10
+ it("keeps the keys as they are", () => {
11
+ expect(resolveLocale("es")).toBe("es");
12
+ expect(resolveLocale("ptBR")).toBe("ptBR");
13
+ expect(resolveLocale("srLatn")).toBe("srLatn");
14
+ expect(resolveLocale("en")).toBe("en");
15
+ });
16
+
17
+ it("reads a language tag in any spelling as its key", () => {
18
+ expect(resolveLocale("en_US")).toBe("enUS");
19
+ expect(resolveLocale("en-US")).toBe("enUS");
20
+ expect(resolveLocale("EN-us")).toBe("enUS");
21
+ expect(resolveLocale("pt-BR")).toBe("ptBR");
22
+ expect(resolveLocale("sr-Latn")).toBe("srLatn");
23
+ expect(resolveLocale(" de ")).toBe("de");
24
+ });
25
+
26
+ it("falls back to the language for a region date-fns doesn't have", () => {
27
+ expect(resolveLocale("es-MX")).toBe("es");
28
+ expect(resolveLocale("en-ZA")).toBe("en");
29
+ });
30
+
31
+ it("gives nothing for what isn't a locale", () => {
32
+ for (const value of ["", " ", "xx", "klingon", "not a locale", 42, null, undefined, {}]) {
33
+ expect(resolveLocale(value)).toBeUndefined();
34
+ }
35
+ });
36
+ });
37
+
38
+ describe("localeToLanguageTag", () => {
39
+
40
+ it("turns region and script keys into tags Intl accepts", () => {
41
+ for (const [key, tag] of [["enUS", "en-US"], ["ptBR", "pt-BR"], ["srLatn", "sr-Latn"], ["faIR", "fa-IR"], ["es", "es"], ["en", "en"]]) {
42
+ expect(localeToLanguageTag(key)).toBe(tag);
43
+ expect(() => new Intl.DateTimeFormat(localeToLanguageTag(key))).not.toThrow();
44
+ }
45
+ });
46
+ });
@@ -166,3 +166,31 @@ export function useDateFnsLocale(locale?: Locale): DateFnsLocale | undefined {
166
166
 
167
167
  return locale ? cache.get(locale) : undefined;
168
168
  }
169
+
170
+ /** Every value of {@link Locale}, folded to lower case without separators. */
171
+ const supportedLocales = new Map<string, Locale>(
172
+ ([...Object.keys(loaders), "en", "fil"] as Locale[]).map((locale) => [locale.toLowerCase(), locale])
173
+ );
174
+
175
+ /**
176
+ * The {@link Locale} a stored or typed value stands for, or undefined.
177
+ *
178
+ * Locales are date-fns keys ("enUS", "ptBR"), but the same setting is often written as
179
+ * a language tag ("en-US", "pt_BR"). Both spellings resolve to the key; a region
180
+ * date-fns doesn't have falls back to its language ("es-MX" to "es").
181
+ */
182
+ export function resolveLocale(value: unknown): Locale | undefined {
183
+ if (typeof value !== "string") return undefined;
184
+ const parts = value.trim().split(/[-_\s]+/).filter(Boolean);
185
+ if (parts.length === 0) return undefined;
186
+ return supportedLocales.get(parts.join("").toLowerCase())
187
+ ?? supportedLocales.get(parts[0].toLowerCase());
188
+ }
189
+
190
+ /**
191
+ * The BCP 47 language tag of a locale key, for `Intl`: "ptBR" is "pt-BR" and "srLatn"
192
+ * is "sr-Latn". `Intl.DateTimeFormat` throws on the key itself.
193
+ */
194
+ export function localeToLanguageTag(locale: string): string {
195
+ return locale.replace(/^([a-z]{2,3})([A-Z][A-Za-z]+)$/, "$1-$2");
196
+ }