@firecms/core 3.5.2-canary.a36570e → 3.5.2
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/{de-CUF9f7S-.js → de-CNfJQcnh.js} +1 -1
- package/dist/{de-CUF9f7S-.js.map → de-CNfJQcnh.js.map} +1 -1
- package/dist/{editor-WZytSO_1.js → editor-D0A5yaaJ.js} +1 -1
- package/dist/{editor-WZytSO_1.js.map → editor-D0A5yaaJ.js.map} +1 -1
- package/dist/{fr-DmkMX6hp.js → fr-CBtSvDVp.js} +1 -1
- package/dist/{fr-DmkMX6hp.js.map → fr-CBtSvDVp.js.map} +1 -1
- package/dist/{hi-BKuaMr7w.js → hi-Delc4l61.js} +1 -1
- package/dist/{hi-BKuaMr7w.js.map → hi-Delc4l61.js.map} +1 -1
- package/dist/index.es.js +32 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +24 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/{it-BwQflFGz.js → it-CdsoaRVO.js} +1 -1
- package/dist/{it-BwQflFGz.js.map → it-CdsoaRVO.js.map} +1 -1
- package/dist/{pl-BPsAvZvc.js → pl-DoTvWcwp.js} +1 -1
- package/dist/{pl-BPsAvZvc.js.map → pl-DoTvWcwp.js.map} +1 -1
- package/dist/preview/components/__tests__/DatePreview.test.d.ts +1 -0
- package/dist/{pt-D5q7OQp1.js → pt-DCfk8Nkq.js} +1 -1
- package/dist/{pt-D5q7OQp1.js.map → pt-DCfk8Nkq.js.map} +1 -1
- package/dist/types/locales.d.ts +1 -1
- package/dist/util/__tests__/locales.test.d.ts +1 -0
- package/dist/util/date_fns_locales.d.ts +13 -0
- package/package.json +3 -3
- package/src/form/field_bindings/BlockFieldBinding.tsx +2 -1
- package/src/preview/components/DatePreview.tsx +14 -2
- package/src/preview/components/__tests__/DatePreview.test.tsx +39 -0
- package/src/types/locales.ts +2 -0
- package/src/util/__tests__/locales.test.ts +46 -0
- package/src/util/date_fns_locales.ts +28 -0
|
@@ -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
|
+
}
|