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

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.
@@ -1,3 +1,4 @@
1
1
  export declare function addRecentId(key: string, id: string): string[];
2
2
  export declare function saveSearchedIdsLocally(key: string, ids: string[]): void;
3
3
  export declare function getRecentIds(key: string): string[];
4
+ export declare function removeRecentIds(key: string, ids: string[]): string[];
package/dist/index.es.js CHANGED
@@ -21087,6 +21087,11 @@ function saveSearchedIdsLocally(key, ids) {
21087
21087
  function getRecentIds(key) {
21088
21088
  return getLocalStorageJSON("recent_id_searches::" + key, []);
21089
21089
  }
21090
+ function removeRecentIds(key, ids) {
21091
+ const remaining = getRecentIds(key).filter((id) => !ids.includes(id));
21092
+ saveSearchedIdsLocally(key, remaining);
21093
+ return remaining;
21094
+ }
21090
21095
  const editEntityAction = {
21091
21096
  icon: /* @__PURE__ */ jsx(EditIcon, { size: "small" }),
21092
21097
  key: "edit",
@@ -26598,164 +26603,86 @@ function _temp$e(key_0) {
26598
26603
  return key_0.toString();
26599
26604
  }
26600
26605
  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;
26606
+ function EntityIdHeaderWidget({
26607
+ collection,
26608
+ path,
26609
+ pathSegments,
26610
+ fullIdPath
26611
+ }) {
26609
26612
  const navigation = useNavigationController();
26613
+ const dataSource = useDataSource();
26610
26614
  const [openPopup, setOpenPopup] = React__default.useState(false);
26611
26615
  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);
26616
+ const [recentIds, setRecentIds] = React__default.useState([]);
26617
+ const latestCheck = useRef(0);
26621
26618
  const sideEntityController = useSideEntityController();
26622
26619
  const {
26623
26620
  t
26624
26621
  } = useTranslation();
26622
+ const resolvedPath = navigation.resolveIdsFrom(path, pathSegments);
26623
+ const resolvedPathSegments = pathSegments ? navigation.resolveSegmentsFrom?.(pathSegments) ?? pathSegments : void 0;
26624
+ const entityExists = useCallback(async (entityId) => {
26625
+ try {
26626
+ const entity = await dataSource.fetchEntity({
26627
+ path: resolvedPath,
26628
+ pathSegments: resolvedPathSegments,
26629
+ entityId,
26630
+ collection
26631
+ });
26632
+ return Boolean(entity?.values);
26633
+ } catch (e) {
26634
+ return void 0;
26635
+ }
26636
+ }, [dataSource, resolvedPath, resolvedPathSegments, collection]);
26637
+ const refreshRecentIds = () => {
26638
+ const ids = getRecentIds(fullIdPath);
26639
+ const check = ++latestCheck.current;
26640
+ Promise.all(ids.map(entityExists)).then((results) => {
26641
+ if (check !== latestCheck.current) return;
26642
+ const missing = ids.filter((_, i) => results[i] === false);
26643
+ if (missing.length > 0) removeRecentIds(fullIdPath, missing);
26644
+ setRecentIds(ids.filter((__0, i_0) => results[i_0] === true));
26645
+ });
26646
+ };
26625
26647
  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
- }
26648
+ return /* @__PURE__ */ jsx(Tooltip, { title: !openPopup ? t("find_by_id") : void 0, asChild: false, children: /* @__PURE__ */ jsx(Popover, { open: openPopup, onOpenChange: (open) => {
26649
+ if (open) refreshRecentIds();
26650
+ setOpenPopup(open);
26651
+ }, 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: [
26652
+ /* @__PURE__ */ jsx("form", { noValidate: true, onSubmit: (e_0) => {
26653
+ e_0.preventDefault();
26654
+ const entityId_0 = searchString.trim();
26655
+ if (!entityId_0) return;
26667
26656
  setOpenPopup(false);
26668
- setRecentIds(addRecentId(fullIdPath, entityId));
26657
+ entityExists(entityId_0).then((exists) => {
26658
+ if (exists) addRecentId(fullIdPath, entityId_0);
26659
+ });
26669
26660
  navigateToEntity({
26670
26661
  openEntityMode,
26671
26662
  collection,
26672
- entityId,
26663
+ entityId: entityId_0,
26673
26664
  path,
26674
26665
  pathSegments,
26675
26666
  fullIdPath,
26676
26667
  sideEntityController,
26677
26668
  navigation
26678
26669
  });
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: () => {
26670
+ }, className: "w-96 max-w-full", children: /* @__PURE__ */ jsxs("div", { className: "flex p-2 w-full gap-2", children: [
26671
+ /* @__PURE__ */ jsx(
26672
+ "input",
26673
+ {
26674
+ autoFocus: openPopup,
26675
+ placeholder: t("find_entity_by_id"),
26676
+ onChange: (e_1) => {
26677
+ setSearchString(e_1.target.value);
26678
+ },
26679
+ value: searchString,
26680
+ className: "rounded-lg bg-white dark:bg-surface-800 flex-grow bg-transparent outline-none p-2 " + focusedDisabled
26681
+ }
26682
+ ),
26683
+ /* @__PURE__ */ jsx(Button, { variant: "text", disabled: !searchString.trim(), type: "submit", children: /* @__PURE__ */ jsx(KeyboardTabIcon, {}) })
26684
+ ] }) }),
26685
+ 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
26686
  setOpenPopup(false);
26760
26687
  navigateToEntity({
26761
26688
  openEntityMode,
@@ -26767,51 +26694,8 @@ function EntityIdHeaderWidget(t0) {
26767
26694
  sideEntityController,
26768
26695
  navigation
26769
26696
  });
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;
26697
+ }, includeEntityLink: false, size: "small" }, id)) })
26698
+ ] }) }) });
26815
26699
  }
26816
26700
  const collectionScrollCache = /* @__PURE__ */ new Map();
26817
26701
  function useScrollRestoration() {