@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
package/dist/index.es.js CHANGED
@@ -4851,6 +4851,16 @@ function useDateFnsLocale(locale) {
4851
4851
  function _temp$C(count) {
4852
4852
  return count + 1;
4853
4853
  }
4854
+ const supportedLocales = new Map([...Object.keys(loaders), "en", "fil"].map((locale) => [locale.toLowerCase(), locale]));
4855
+ function resolveLocale(value) {
4856
+ if (typeof value !== "string") return void 0;
4857
+ const parts = value.trim().split(/[-_\s]+/).filter(Boolean);
4858
+ if (parts.length === 0) return void 0;
4859
+ return supportedLocales.get(parts.join("").toLowerCase()) ?? supportedLocales.get(parts[0].toLowerCase());
4860
+ }
4861
+ function localeToLanguageTag(locale) {
4862
+ return locale.replace(/^([a-z]{2,3})([A-Z][A-Za-z]+)$/, "$1-$2");
4863
+ }
4854
4864
  const CONTAINER_FULL_WIDTH = "100vw";
4855
4865
  const ADDITIONAL_TAB_WIDTH = "55vw";
4856
4866
  const FORM_CONTAINER_WIDTH = "768px";
@@ -7733,6 +7743,13 @@ function ArrayOneOfPreview(t0) {
7733
7743
  }
7734
7744
  return t3;
7735
7745
  }
7746
+ function dateTimeFormat(locale, options) {
7747
+ try {
7748
+ return new Intl.DateTimeFormat(locale ? localeToLanguageTag(locale) : "en-US", options);
7749
+ } catch {
7750
+ return new Intl.DateTimeFormat("en-US", options);
7751
+ }
7752
+ }
7736
7753
  function DatePreview(t0) {
7737
7754
  const $ = c(22);
7738
7755
  const {
@@ -7766,7 +7783,7 @@ function DatePreview(t0) {
7766
7783
  options.hour = "2-digit";
7767
7784
  options.minute = "2-digit";
7768
7785
  }
7769
- const formatter = new Intl.DateTimeFormat(customizationController?.locale ?? "en-US", options);
7786
+ const formatter = dateTimeFormat(customizationController?.locale, options);
7770
7787
  t22 = formatter.format(date);
7771
7788
  $[1] = customizationController?.locale;
7772
7789
  $[2] = date;
@@ -15875,10 +15892,11 @@ function BlockFieldBinding({
15875
15892
  setValue(null);
15876
15893
  }, children: /* @__PURE__ */ jsx(CloseIcon, { size: "small" }) })
15877
15894
  ] });
15895
+ const canAddElements = !property.disabled && !isSubmitting && !disabled && (property.canAddElements ?? true);
15878
15896
  const firstOneOfKey = Object.keys(property.oneOf.properties)[0];
15879
15897
  const body = /* @__PURE__ */ jsx(ArrayContainer, { value, className: "flex flex-col gap-3", droppableId: propertyKey, addLabel: property.name ? t("add_to_field", {
15880
15898
  fieldName: property.name
15881
- }) : t("add_entry"), buildEntry, onInternalIdAdded: setLastAddedId, disabled: isSubmitting || Boolean(property.disabled), canAddElements: !property.disabled, onValueChange: (value_0) => setFieldValue(propertyKey, value_0), newDefaultEntry: {
15899
+ }) : t("add_entry"), buildEntry, onInternalIdAdded: setLastAddedId, disabled: isSubmitting || Boolean(property.disabled), canAddElements, onValueChange: (value_0) => setFieldValue(propertyKey, value_0), newDefaultEntry: {
15882
15900
  [property.oneOf.typeField ?? DEFAULT_ONE_OF_TYPE]: firstOneOfKey,
15883
15901
  [property.oneOf.valueField ?? DEFAULT_ONE_OF_VALUE]: getDefaultValueFor(property.oneOf.properties[firstOneOfKey])
15884
15902
  } });
@@ -16100,7 +16118,7 @@ function CircularProgressCenter(t0) {
16100
16118
  }
16101
16119
  return t3;
16102
16120
  }
16103
- const FireCMSEditor$1 = lazyEager(() => import("./editor-WZytSO_1.js"), "FireCMSEditor");
16121
+ const FireCMSEditor$1 = lazyEager(() => import("./editor-D0A5yaaJ.js"), "FireCMSEditor");
16104
16122
  function MarkdownEditorFieldBinding$1({
16105
16123
  property,
16106
16124
  propertyKey,
@@ -21087,6 +21105,11 @@ function saveSearchedIdsLocally(key, ids) {
21087
21105
  function getRecentIds(key) {
21088
21106
  return getLocalStorageJSON("recent_id_searches::" + key, []);
21089
21107
  }
21108
+ function removeRecentIds(key, ids) {
21109
+ const remaining = getRecentIds(key).filter((id) => !ids.includes(id));
21110
+ saveSearchedIdsLocally(key, remaining);
21111
+ return remaining;
21112
+ }
21090
21113
  const editEntityAction = {
21091
21114
  icon: /* @__PURE__ */ jsx(EditIcon, { size: "small" }),
21092
21115
  key: "edit",
@@ -26598,164 +26621,86 @@ function _temp$e(key_0) {
26598
26621
  return key_0.toString();
26599
26622
  }
26600
26623
  const DEFAULT_ENTITY_OPEN_MODE$1 = "side_panel";
26601
- function EntityIdHeaderWidget(t0) {
26602
- const $ = c(53);
26603
- const {
26604
- collection,
26605
- path,
26606
- pathSegments,
26607
- fullIdPath
26608
- } = t0;
26624
+ function EntityIdHeaderWidget({
26625
+ collection,
26626
+ path,
26627
+ pathSegments,
26628
+ fullIdPath
26629
+ }) {
26609
26630
  const navigation = useNavigationController();
26631
+ const dataSource = useDataSource();
26610
26632
  const [openPopup, setOpenPopup] = React__default.useState(false);
26611
26633
  const [searchString, setSearchString] = React__default.useState("");
26612
- let t1;
26613
- if ($[0] !== fullIdPath) {
26614
- t1 = () => getRecentIds(fullIdPath);
26615
- $[0] = fullIdPath;
26616
- $[1] = t1;
26617
- } else {
26618
- t1 = $[1];
26619
- }
26620
- const [recentIds, setRecentIds] = React__default.useState(t1);
26634
+ const [recentIds, setRecentIds] = React__default.useState([]);
26635
+ const latestCheck = useRef(0);
26621
26636
  const sideEntityController = useSideEntityController();
26622
26637
  const {
26623
26638
  t
26624
26639
  } = useTranslation();
26640
+ const resolvedPath = navigation.resolveIdsFrom(path, pathSegments);
26641
+ const resolvedPathSegments = pathSegments ? navigation.resolveSegmentsFrom?.(pathSegments) ?? pathSegments : void 0;
26642
+ const entityExists = useCallback(async (entityId) => {
26643
+ try {
26644
+ const entity = await dataSource.fetchEntity({
26645
+ path: resolvedPath,
26646
+ pathSegments: resolvedPathSegments,
26647
+ entityId,
26648
+ collection
26649
+ });
26650
+ return Boolean(entity?.values);
26651
+ } catch (e) {
26652
+ return void 0;
26653
+ }
26654
+ }, [dataSource, resolvedPath, resolvedPathSegments, collection]);
26655
+ const refreshRecentIds = () => {
26656
+ const ids = getRecentIds(fullIdPath);
26657
+ const check = ++latestCheck.current;
26658
+ Promise.all(ids.map(entityExists)).then((results) => {
26659
+ if (check !== latestCheck.current) return;
26660
+ const missing = ids.filter((_, i) => results[i] === false);
26661
+ if (missing.length > 0) removeRecentIds(fullIdPath, missing);
26662
+ setRecentIds(ids.filter((__0, i_0) => results[i_0] === true));
26663
+ });
26664
+ };
26625
26665
  const openEntityMode = collection?.openEntityMode ?? DEFAULT_ENTITY_OPEN_MODE$1;
26626
- let t2;
26627
- if ($[2] !== openPopup || $[3] !== t) {
26628
- t2 = !openPopup ? t("find_by_id") : void 0;
26629
- $[2] = openPopup;
26630
- $[3] = t;
26631
- $[4] = t2;
26632
- } else {
26633
- t2 = $[4];
26634
- }
26635
- let t3;
26636
- if ($[5] !== fullIdPath) {
26637
- t3 = (open) => {
26638
- if (open) {
26639
- setRecentIds(getRecentIds(fullIdPath));
26640
- }
26641
- setOpenPopup(open);
26642
- };
26643
- $[5] = fullIdPath;
26644
- $[6] = t3;
26645
- } else {
26646
- t3 = $[6];
26647
- }
26648
- let t4;
26649
- let t5;
26650
- if ($[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
26651
- t4 = /* @__PURE__ */ jsx(IconButton, { size: "small", children: /* @__PURE__ */ jsx(SearchIcon, { size: "small" }) });
26652
- t5 = cls("my-2 rounded-lg bg-surface-50 dark:bg-surface-950 text-surface-900 dark:text-white");
26653
- $[7] = t4;
26654
- $[8] = t5;
26655
- } else {
26656
- t4 = $[7];
26657
- t5 = $[8];
26658
- }
26659
- let t6;
26660
- if ($[9] !== collection || $[10] !== fullIdPath || $[11] !== navigation || $[12] !== openEntityMode || $[13] !== path || $[14] !== pathSegments || $[15] !== searchString || $[16] !== sideEntityController) {
26661
- t6 = (e) => {
26662
- e.preventDefault();
26663
- const entityId = searchString.trim();
26664
- if (!entityId) {
26665
- return;
26666
- }
26666
+ return /* @__PURE__ */ jsx(Tooltip, { title: !openPopup ? t("find_by_id") : void 0, asChild: false, children: /* @__PURE__ */ jsx(Popover, { open: openPopup, onOpenChange: (open) => {
26667
+ if (open) refreshRecentIds();
26668
+ setOpenPopup(open);
26669
+ }, sideOffset: 0, align: "start", alignOffset: -117, trigger: /* @__PURE__ */ jsx(IconButton, { size: "small", children: /* @__PURE__ */ jsx(SearchIcon, { size: "small" }) }), children: /* @__PURE__ */ jsxs("div", { className: cls("my-2 rounded-lg bg-surface-50 dark:bg-surface-950 text-surface-900 dark:text-white"), children: [
26670
+ /* @__PURE__ */ jsx("form", { noValidate: true, onSubmit: (e_0) => {
26671
+ e_0.preventDefault();
26672
+ const entityId_0 = searchString.trim();
26673
+ if (!entityId_0) return;
26667
26674
  setOpenPopup(false);
26668
- setRecentIds(addRecentId(fullIdPath, entityId));
26675
+ entityExists(entityId_0).then((exists) => {
26676
+ if (exists) addRecentId(fullIdPath, entityId_0);
26677
+ });
26669
26678
  navigateToEntity({
26670
26679
  openEntityMode,
26671
26680
  collection,
26672
- entityId,
26681
+ entityId: entityId_0,
26673
26682
  path,
26674
26683
  pathSegments,
26675
26684
  fullIdPath,
26676
26685
  sideEntityController,
26677
26686
  navigation
26678
26687
  });
26679
- };
26680
- $[9] = collection;
26681
- $[10] = fullIdPath;
26682
- $[11] = navigation;
26683
- $[12] = openEntityMode;
26684
- $[13] = path;
26685
- $[14] = pathSegments;
26686
- $[15] = searchString;
26687
- $[16] = sideEntityController;
26688
- $[17] = t6;
26689
- } else {
26690
- t6 = $[17];
26691
- }
26692
- let t7;
26693
- if ($[18] !== t) {
26694
- t7 = t("find_entity_by_id");
26695
- $[18] = t;
26696
- $[19] = t7;
26697
- } else {
26698
- t7 = $[19];
26699
- }
26700
- let t8;
26701
- if ($[20] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
26702
- t8 = (e_0) => {
26703
- setSearchString(e_0.target.value);
26704
- };
26705
- $[20] = t8;
26706
- } else {
26707
- t8 = $[20];
26708
- }
26709
- let t9;
26710
- if ($[21] !== openPopup || $[22] !== searchString || $[23] !== t7) {
26711
- t9 = /* @__PURE__ */ jsx("input", { autoFocus: openPopup, placeholder: t7, onChange: t8, value: searchString, className: "rounded-lg bg-white dark:bg-surface-800 flex-grow bg-transparent outline-none p-2 " + focusedDisabled });
26712
- $[21] = openPopup;
26713
- $[22] = searchString;
26714
- $[23] = t7;
26715
- $[24] = t9;
26716
- } else {
26717
- t9 = $[24];
26718
- }
26719
- const t10 = !searchString.trim();
26720
- let t11;
26721
- if ($[25] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
26722
- t11 = /* @__PURE__ */ jsx(KeyboardTabIcon, {});
26723
- $[25] = t11;
26724
- } else {
26725
- t11 = $[25];
26726
- }
26727
- let t12;
26728
- if ($[26] !== t10) {
26729
- t12 = /* @__PURE__ */ jsx(Button, { variant: "text", disabled: t10, type: "submit", children: t11 });
26730
- $[26] = t10;
26731
- $[27] = t12;
26732
- } else {
26733
- t12 = $[27];
26734
- }
26735
- let t13;
26736
- if ($[28] !== t12 || $[29] !== t9) {
26737
- t13 = /* @__PURE__ */ jsxs("div", { className: "flex p-2 w-full gap-2", children: [
26738
- t9,
26739
- t12
26740
- ] });
26741
- $[28] = t12;
26742
- $[29] = t9;
26743
- $[30] = t13;
26744
- } else {
26745
- t13 = $[30];
26746
- }
26747
- let t14;
26748
- if ($[31] !== t13 || $[32] !== t6) {
26749
- t14 = /* @__PURE__ */ jsx("form", { noValidate: true, onSubmit: t6, className: "w-96 max-w-full", children: t13 });
26750
- $[31] = t13;
26751
- $[32] = t6;
26752
- $[33] = t14;
26753
- } else {
26754
- t14 = $[33];
26755
- }
26756
- let t15;
26757
- if ($[34] !== collection || $[35] !== fullIdPath || $[36] !== navigation || $[37] !== openEntityMode || $[38] !== path || $[39] !== pathSegments || $[40] !== recentIds || $[41] !== sideEntityController) {
26758
- t15 = recentIds && recentIds.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 p-2", children: recentIds.map((id) => /* @__PURE__ */ jsx(ReferencePreview, { reference: new EntityReference(id, path, void 0, pathSegments), hover: true, onClick: () => {
26688
+ }, className: "w-96 max-w-full", children: /* @__PURE__ */ jsxs("div", { className: "flex p-2 w-full gap-2", children: [
26689
+ /* @__PURE__ */ jsx(
26690
+ "input",
26691
+ {
26692
+ autoFocus: openPopup,
26693
+ placeholder: t("find_entity_by_id"),
26694
+ onChange: (e_1) => {
26695
+ setSearchString(e_1.target.value);
26696
+ },
26697
+ value: searchString,
26698
+ className: "rounded-lg bg-white dark:bg-surface-800 flex-grow bg-transparent outline-none p-2 " + focusedDisabled
26699
+ }
26700
+ ),
26701
+ /* @__PURE__ */ jsx(Button, { variant: "text", disabled: !searchString.trim(), type: "submit", children: /* @__PURE__ */ jsx(KeyboardTabIcon, {}) })
26702
+ ] }) }),
26703
+ recentIds && recentIds.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 p-2", children: recentIds.map((id) => /* @__PURE__ */ jsx(ReferencePreview, { reference: new EntityReference(id, path, void 0, pathSegments), hover: true, onClick: () => {
26759
26704
  setOpenPopup(false);
26760
26705
  navigateToEntity({
26761
26706
  openEntityMode,
@@ -26767,51 +26712,8 @@ function EntityIdHeaderWidget(t0) {
26767
26712
  sideEntityController,
26768
26713
  navigation
26769
26714
  });
26770
- }, includeEntityLink: false, size: "small" }, id)) });
26771
- $[34] = collection;
26772
- $[35] = fullIdPath;
26773
- $[36] = navigation;
26774
- $[37] = openEntityMode;
26775
- $[38] = path;
26776
- $[39] = pathSegments;
26777
- $[40] = recentIds;
26778
- $[41] = sideEntityController;
26779
- $[42] = t15;
26780
- } else {
26781
- t15 = $[42];
26782
- }
26783
- let t16;
26784
- if ($[43] !== t14 || $[44] !== t15) {
26785
- t16 = /* @__PURE__ */ jsxs("div", { className: t5, children: [
26786
- t14,
26787
- t15
26788
- ] });
26789
- $[43] = t14;
26790
- $[44] = t15;
26791
- $[45] = t16;
26792
- } else {
26793
- t16 = $[45];
26794
- }
26795
- let t17;
26796
- if ($[46] !== openPopup || $[47] !== t16 || $[48] !== t3) {
26797
- t17 = /* @__PURE__ */ jsx(Popover, { open: openPopup, onOpenChange: t3, sideOffset: 0, align: "start", alignOffset: -117, trigger: t4, children: t16 });
26798
- $[46] = openPopup;
26799
- $[47] = t16;
26800
- $[48] = t3;
26801
- $[49] = t17;
26802
- } else {
26803
- t17 = $[49];
26804
- }
26805
- let t18;
26806
- if ($[50] !== t17 || $[51] !== t2) {
26807
- t18 = /* @__PURE__ */ jsx(Tooltip, { title: t2, asChild: false, children: t17 });
26808
- $[50] = t17;
26809
- $[51] = t2;
26810
- $[52] = t18;
26811
- } else {
26812
- t18 = $[52];
26813
- }
26814
- return t18;
26715
+ }, includeEntityLink: false, size: "small" }, id)) })
26716
+ ] }) }) });
26815
26717
  }
26816
26718
  const collectionScrollCache = /* @__PURE__ */ new Map();
26817
26719
  function useScrollRestoration() {
@@ -32771,7 +32673,7 @@ function FireCMS(props) {
32771
32673
  children,
32772
32674
  entityLinkBuilder,
32773
32675
  userConfigPersistence,
32774
- dateTimeFormat,
32676
+ dateTimeFormat: dateTimeFormat2,
32775
32677
  locale,
32776
32678
  authController,
32777
32679
  storageSource,
@@ -32820,7 +32722,7 @@ function FireCMS(props) {
32820
32722
  const pluginsLoading = plugins?.some((p_0) => p_0.loading) ?? false;
32821
32723
  const loading = authController.initialLoading || navigationController.loading || pluginsLoading;
32822
32724
  const customizationController = {
32823
- dateTimeFormat,
32725
+ dateTimeFormat: dateTimeFormat2,
32824
32726
  locale,
32825
32727
  entityLinkBuilder,
32826
32728
  plugins,
@@ -35963,12 +35865,12 @@ const es = {
35963
35865
  };
35964
35866
  const FIRECMS_NS = "firecms_core";
35965
35867
  const localeLoaders = {
35966
- de: () => import("./de-CUF9f7S-.js").then((m) => m.de),
35967
- fr: () => import("./fr-DmkMX6hp.js").then((m) => m.fr),
35968
- it: () => import("./it-BwQflFGz.js").then((m) => m.it),
35969
- hi: () => import("./hi-BKuaMr7w.js").then((m) => m.hi),
35970
- pt: () => import("./pt-D5q7OQp1.js").then((m) => m.pt),
35971
- pl: () => import("./pl-BPsAvZvc.js").then((m) => m.pl)
35868
+ de: () => import("./de-CNfJQcnh.js").then((m) => m.de),
35869
+ fr: () => import("./fr-CBtSvDVp.js").then((m) => m.fr),
35870
+ it: () => import("./it-CdsoaRVO.js").then((m) => m.it),
35871
+ hi: () => import("./hi-Delc4l61.js").then((m) => m.hi),
35872
+ pt: () => import("./pt-DCfk8Nkq.js").then((m) => m.pt),
35873
+ pl: () => import("./pl-DoTvWcwp.js").then((m) => m.pl)
35972
35874
  };
35973
35875
  const loadedLocales = {
35974
35876
  en,
@@ -36137,7 +36039,7 @@ function buildResources(translations) {
36137
36039
  }
36138
36040
  return resources;
36139
36041
  }
36140
- const LazyFireCMSEditor = React__default.lazy(() => import("./editor-WZytSO_1.js").then((module) => ({
36042
+ const LazyFireCMSEditor = React__default.lazy(() => import("./editor-D0A5yaaJ.js").then((module) => ({
36141
36043
  default: module.FireCMSEditor
36142
36044
  })));
36143
36045
  function FireCMSEditor(props) {
@@ -36388,6 +36290,7 @@ export {
36388
36290
  jsonStringifyReplacer,
36389
36291
  lazyEager,
36390
36292
  loadDateFnsLocale,
36293
+ localeToLanguageTag,
36391
36294
  makePropertiesEditable,
36392
36295
  mergeCallbacks,
36393
36296
  mergeCollection,
@@ -36425,6 +36328,7 @@ export {
36425
36328
  resolveEntityAction,
36426
36329
  resolveEntityView,
36427
36330
  resolveEnumValues,
36331
+ resolveLocale,
36428
36332
  resolveNavigationFrom,
36429
36333
  resolvePermissions,
36430
36334
  resolveProperties,