@octaviaflow/core 3.1.0-beta.82 → 3.1.0-beta.83

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 CHANGED
@@ -14646,6 +14646,7 @@ function FilePicker({
14646
14646
  searchLimit = 200,
14647
14647
  closeOnEsc = true,
14648
14648
  emptyTitle = "This folder is empty",
14649
+ pathLabels,
14649
14650
  name,
14650
14651
  form,
14651
14652
  id,
@@ -14660,6 +14661,8 @@ function FilePicker({
14660
14661
  const value = valueProp ?? valueState;
14661
14662
  const [open, setOpen] = useState33(false);
14662
14663
  const [navPath, setNavPath] = useState33(rootPath);
14664
+ const [trail, setTrail] = useState33([]);
14665
+ const [nameByPath, setNameByPath] = useState33({});
14663
14666
  const [cache, setCache] = useState33({});
14664
14667
  const cacheRef = useRef24(cache);
14665
14668
  cacheRef.current = cache;
@@ -14681,6 +14684,11 @@ function FilePicker({
14681
14684
  try {
14682
14685
  const items2 = await loadChildren(folder);
14683
14686
  setCache((prev) => ({ ...prev, [folder]: { status: "loaded", items: items2 } }));
14687
+ setNameByPath((prev) => {
14688
+ const next = { ...prev };
14689
+ for (const it of items2) next[it.path] = it.name;
14690
+ return next;
14691
+ });
14684
14692
  return items2;
14685
14693
  } catch (e) {
14686
14694
  const err = e?.message || "Failed to load folder.";
@@ -14693,6 +14701,7 @@ function FilePicker({
14693
14701
  const openAt = useCallback23(() => {
14694
14702
  const start = initialPath ?? (value ? parentOf(value, rootPath, separator) ?? rootPath : rootPath);
14695
14703
  setNavPath(start);
14704
+ setTrail([]);
14696
14705
  setQuery("");
14697
14706
  setActiveIndex(-1);
14698
14707
  setOpen(true);
@@ -14777,12 +14786,13 @@ function FilePicker({
14777
14786
  (item) => {
14778
14787
  if (item.disabled) return;
14779
14788
  if (item.isDirectory) {
14789
+ setTrail((t) => navPath === rootPath ? t : [...t, navPath]);
14780
14790
  navigate(item.path);
14781
14791
  } else if (canSelectFiles) {
14782
14792
  commit(item.path, item);
14783
14793
  }
14784
14794
  },
14785
- [navigate, canSelectFiles, commit]
14795
+ [navigate, canSelectFiles, commit, navPath, rootPath]
14786
14796
  );
14787
14797
  useEffect27(() => {
14788
14798
  if (!open) return;
@@ -14815,11 +14825,30 @@ function FilePicker({
14815
14825
  if (isSearching) return search?.results ?? [];
14816
14826
  return [...rawItems].sort(folderFirstThenName);
14817
14827
  }, [isSearching, search, rawItems]);
14828
+ const displayName = useCallback23(
14829
+ (p) => p === rootPath ? rootLabel : nameByPath[p] ?? pathLabels?.[p] ?? baseName(p, separator),
14830
+ [rootPath, rootLabel, nameByPath, pathLabels, separator]
14831
+ );
14818
14832
  const crumbs = useMemo20(() => {
14819
- const chain = ancestorsOf(navPath, rootPath, separator);
14820
- return chain.map((p, i) => ({ path: p, label: i === 0 ? rootLabel : baseName(p, separator) }));
14821
- }, [navPath, rootPath, rootLabel, separator]);
14822
- const parent = parentOf(navPath, rootPath, separator);
14833
+ if (navPath === rootPath) return [{ path: rootPath, label: rootLabel }];
14834
+ const derived = ancestorsOf(navPath, rootPath, separator);
14835
+ const derivedValid = derived[derived.length - 1] === navPath;
14836
+ const chain = derivedValid && (derived.length > 2 || trail.length === 0) ? derived : [rootPath, ...trail.filter((p) => p !== rootPath), navPath];
14837
+ return chain.map((p, i) => ({ path: p, label: i === 0 ? rootLabel : displayName(p) }));
14838
+ }, [navPath, rootPath, rootLabel, separator, trail, displayName]);
14839
+ const parent = trail.length ? trail[trail.length - 1] : parentOf(navPath, rootPath, separator);
14840
+ const goUp = useCallback23(() => {
14841
+ if (!parent) return;
14842
+ setTrail((t) => t.length ? t.slice(0, -1) : t);
14843
+ navigate(parent);
14844
+ }, [parent, navigate]);
14845
+ const goToCrumb = useCallback23(
14846
+ (path, index) => {
14847
+ setTrail(crumbs.slice(1, index).map((c) => c.path));
14848
+ navigate(path);
14849
+ },
14850
+ [crumbs, navigate]
14851
+ );
14823
14852
  const onPopoverKeyDown = (e) => {
14824
14853
  const inSearch = e.target?.tagName === "INPUT";
14825
14854
  if (e.key === "ArrowDown") {
@@ -14929,7 +14958,7 @@ function FilePicker({
14929
14958
  className: "ods-file-picker__up",
14930
14959
  "aria-label": "Up one folder",
14931
14960
  disabled: !parent,
14932
- onClick: () => parent && navigate(parent),
14961
+ onClick: goUp,
14933
14962
  children: /* @__PURE__ */ jsx62(FolderParentIcon2, { size: "sm" })
14934
14963
  }
14935
14964
  ),
@@ -14946,7 +14975,7 @@ function FilePicker({
14946
14975
  ),
14947
14976
  "aria-current": isLast ? "page" : void 0,
14948
14977
  disabled: isLast,
14949
- onClick: () => !isLast && navigate(c.path),
14978
+ onClick: () => !isLast && goToCrumb(c.path, i),
14950
14979
  children: c.label
14951
14980
  }
14952
14981
  ),
@@ -14998,7 +15027,7 @@ function FilePicker({
14998
15027
  {
14999
15028
  icon: /* @__PURE__ */ jsx62(FolderIcon3, {}),
15000
15029
  title: isSearching ? "No matches" : emptyTitle,
15001
- description: isSearching ? `Nothing under \u201C${baseName(navPath, separator) || rootLabel}\u201D matches \u201C${query.trim()}\u201D.` : void 0
15030
+ description: isSearching ? `Nothing under \u201C${displayName(navPath) || rootLabel}\u201D matches \u201C${query.trim()}\u201D.` : void 0
15002
15031
  }
15003
15032
  ) }) : items.map((it, i) => {
15004
15033
  const active = i === activeIndex;
@@ -15043,14 +15072,14 @@ function FilePicker({
15043
15072
  showFooter && /* @__PURE__ */ jsxs61("div", { className: "ods-file-picker__footer", children: [
15044
15073
  /* @__PURE__ */ jsxs61("span", { className: "ods-file-picker__footer-path", title: navPath, children: [
15045
15074
  /* @__PURE__ */ jsx62("span", { className: "ods-file-picker__footer-label", children: "Selected" }),
15046
- navPath
15075
+ displayName(navPath)
15047
15076
  ] }),
15048
15077
  /* @__PURE__ */ jsxs61(
15049
15078
  "button",
15050
15079
  {
15051
15080
  type: "button",
15052
15081
  className: "ods-file-picker__use",
15053
- onClick: () => commit(navPath, { name: baseName(navPath, separator), path: navPath, isDirectory: true }),
15082
+ onClick: () => commit(navPath, { name: displayName(navPath), path: navPath, isDirectory: true }),
15054
15083
  children: [
15055
15084
  "Use this folder",
15056
15085
  /* @__PURE__ */ jsx62(ChevronRightIcon6, { size: "sm", "aria-hidden": "true" })