tinacms 1.4.5 → 1.5.0

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.es.js CHANGED
@@ -10,7 +10,7 @@ import React, { useState, useCallback, useEffect, Fragment, useMemo } from "reac
10
10
  import * as yup from "yup";
11
11
  import { setEditing, useEditState } from "@tinacms/sharedctx";
12
12
  import { diff } from "@graphql-inspector/core";
13
- import { NavLink, useSearchParams, useNavigate, useParams, useLocation, Link, HashRouter, Routes, Route } from "react-router-dom";
13
+ import { NavLink, useSearchParams, useNavigate, useLocation, useParams, Link, HashRouter, Routes, Route } from "react-router-dom";
14
14
  import { Transition, Menu } from "@headlessui/react";
15
15
  import { useWindowWidth } from "@react-hook/window-size";
16
16
  function popupWindow(url, title, window2, w, h) {
@@ -218,12 +218,16 @@ mutation addPendingDocumentMutation(
218
218
  this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/${this.tinaGraphQLVersion}/content/${this.options.clientId}/github/${encodedBranch}`;
219
219
  }
220
220
  async request(query, { variables }) {
221
+ const token = await this.getToken();
222
+ const headers = {
223
+ "Content-Type": "application/json"
224
+ };
225
+ if (token == null ? void 0 : token.id_token) {
226
+ headers["Authorization"] = "Bearer " + (token == null ? void 0 : token.id_token);
227
+ }
221
228
  const res = await fetch(this.contentApiUrl, {
222
229
  method: "POST",
223
- headers: {
224
- "Content-Type": "application/json",
225
- Authorization: "Bearer " + (await this.getToken()).id_token
226
- },
230
+ headers,
227
231
  body: JSON.stringify({
228
232
  query: typeof query === "function" ? print(query(gql$1)) : query,
229
233
  variables
@@ -335,12 +339,13 @@ mutation addPendingDocumentMutation(
335
339
  }
336
340
  async fetchWithToken(input, init) {
337
341
  const headers = (init == null ? void 0 : init.headers) || {};
342
+ const token = await this.getToken();
343
+ if (token == null ? void 0 : token.id_token) {
344
+ headers["Authorization"] = "Bearer " + (token == null ? void 0 : token.id_token);
345
+ }
338
346
  return await fetch(input, {
339
347
  ...init,
340
- headers: new Headers({
341
- Authorization: "Bearer " + (await this.getToken()).id_token,
342
- ...headers
343
- })
348
+ headers: new Headers(headers)
344
349
  });
345
350
  }
346
351
  async getUser() {
@@ -617,7 +622,7 @@ class TinaAdminApi {
617
622
  }
618
623
  }`, { variables: { collection, relativePath } });
619
624
  }
620
- async fetchCollection(collectionName, includeDocuments, after, sortKey, order, filterArgs) {
625
+ async fetchCollection(collectionName, includeDocuments, folder = "", after, sortKey, order, filterArgs) {
621
626
  let filter = null;
622
627
  const filterField = filterArgs == null ? void 0 : filterArgs.filterField;
623
628
  if (filterField) {
@@ -654,13 +659,13 @@ class TinaAdminApi {
654
659
  if (includeDocuments === true) {
655
660
  const sort = sortKey || this.schema.getIsTitleFieldName(collectionName);
656
661
  const response = order === "asc" ? await this.api.request(`#graphql
657
- query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String, $filter: DocumentFilter){
662
+ query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String, $filter: DocumentFilter, $folder: String){
658
663
  collection(collection: $collection){
659
664
  name
660
665
  label
661
666
  format
662
667
  templates
663
- documents(sort: $sort, after: $after, first: $limit, filter: $filter) @include(if: $includeDocuments) {
668
+ documents(sort: $sort, after: $after, first: $limit, filter: $filter, folder: $folder) @include(if: $includeDocuments) {
664
669
  totalCount
665
670
  pageInfo {
666
671
  hasPreviousPage
@@ -670,6 +675,11 @@ class TinaAdminApi {
670
675
  }
671
676
  edges {
672
677
  node {
678
+ __typename
679
+ ... on Folder {
680
+ name
681
+ path
682
+ }
673
683
  ... on Document {
674
684
  _sys {
675
685
  title
@@ -690,19 +700,20 @@ class TinaAdminApi {
690
700
  variables: {
691
701
  collection: collectionName,
692
702
  includeDocuments,
703
+ folder,
693
704
  sort,
694
705
  limit: 50,
695
706
  after,
696
707
  filter
697
708
  }
698
709
  }) : await this.api.request(`#graphql
699
- query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String, $filter: DocumentFilter){
710
+ query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String, $filter: DocumentFilter, $folder: String) {
700
711
  collection(collection: $collection){
701
712
  name
702
713
  label
703
714
  format
704
715
  templates
705
- documents(sort: $sort, before: $after, last: $limit, filter: $filter) @include(if: $includeDocuments) {
716
+ documents(sort: $sort, before: $after, last: $limit, filter: $filter, folder: $folder) @include(if: $includeDocuments) {
706
717
  totalCount
707
718
  pageInfo {
708
719
  hasPreviousPage
@@ -712,6 +723,11 @@ class TinaAdminApi {
712
723
  }
713
724
  edges {
714
725
  node {
726
+ __typename
727
+ ... on Folder {
728
+ name
729
+ path
730
+ }
715
731
  ... on Document {
716
732
  _sys {
717
733
  title
@@ -732,6 +748,7 @@ class TinaAdminApi {
732
748
  variables: {
733
749
  collection: collectionName,
734
750
  includeDocuments,
751
+ folder,
735
752
  sort,
736
753
  limit: 50,
737
754
  after,
@@ -1464,6 +1481,9 @@ var styles = `.tina-tailwind {
1464
1481
  .tina-tailwind .flex-shrink-0 {
1465
1482
  flex-shrink: 0;
1466
1483
  }
1484
+ .tina-tailwind .shrink-0 {
1485
+ flex-shrink: 0;
1486
+ }
1467
1487
  .tina-tailwind .flex-grow-0 {
1468
1488
  flex-grow: 0;
1469
1489
  }
@@ -1526,6 +1546,9 @@ var styles = `.tina-tailwind {
1526
1546
  .tina-tailwind .items-stretch {
1527
1547
  align-items: stretch;
1528
1548
  }
1549
+ .tina-tailwind .justify-start {
1550
+ justify-content: flex-start;
1551
+ }
1529
1552
  .tina-tailwind .justify-end {
1530
1553
  justify-content: flex-end;
1531
1554
  }
@@ -1541,6 +1564,9 @@ var styles = `.tina-tailwind {
1541
1564
  .tina-tailwind .gap-0\\.5 {
1542
1565
  gap: 2px;
1543
1566
  }
1567
+ .tina-tailwind .gap-1 {
1568
+ gap: 4px;
1569
+ }
1544
1570
  .tina-tailwind .gap-2 {
1545
1571
  gap: 8px;
1546
1572
  }
@@ -1601,9 +1627,15 @@ var styles = `.tina-tailwind {
1601
1627
  .tina-tailwind .border {
1602
1628
  border-width: 1px;
1603
1629
  }
1630
+ .tina-tailwind .border-0 {
1631
+ border-width: 0;
1632
+ }
1604
1633
  .tina-tailwind .border-b {
1605
1634
  border-bottom-width: 1px;
1606
1635
  }
1636
+ .tina-tailwind .border-r {
1637
+ border-right-width: 1px;
1638
+ }
1607
1639
  .tina-tailwind .border-gray-100 {
1608
1640
  --tw-border-opacity: 1;
1609
1641
  border-color: rgb(237 236 243 / var(--tw-border-opacity));
@@ -1628,6 +1660,12 @@ var styles = `.tina-tailwind {
1628
1660
  --tw-bg-opacity: 1;
1629
1661
  background-color: rgb(246 246 249 / var(--tw-bg-opacity));
1630
1662
  }
1663
+ .tina-tailwind .bg-gray-50\\/30 {
1664
+ background-color: rgb(246 246 249 / .3);
1665
+ }
1666
+ .tina-tailwind .bg-transparent {
1667
+ background-color: transparent;
1668
+ }
1631
1669
  .tina-tailwind .bg-white {
1632
1670
  --tw-bg-opacity: 1;
1633
1671
  background-color: rgb(255 255 255 / var(--tw-bg-opacity));
@@ -1669,6 +1707,9 @@ var styles = `.tina-tailwind {
1669
1707
  .tina-tailwind .fill-current {
1670
1708
  fill: currentColor;
1671
1709
  }
1710
+ .tina-tailwind .p-0 {
1711
+ padding: 0px;
1712
+ }
1672
1713
  .tina-tailwind .px-12 {
1673
1714
  padding-left: 48px;
1674
1715
  padding-right: 48px;
@@ -1737,6 +1778,12 @@ var styles = `.tina-tailwind {
1737
1778
  .tina-tailwind .pl-8 {
1738
1779
  padding-left: 32px;
1739
1780
  }
1781
+ .tina-tailwind .pr-0 {
1782
+ padding-right: 0px;
1783
+ }
1784
+ .tina-tailwind .pr-0\\.5 {
1785
+ padding-right: 2px;
1786
+ }
1740
1787
  .tina-tailwind .pr-3 {
1741
1788
  padding-right: 12px;
1742
1789
  }
@@ -1807,6 +1854,10 @@ var styles = `.tina-tailwind {
1807
1854
  .tina-tailwind .tracking-wide {
1808
1855
  letter-spacing: 0.025em;
1809
1856
  }
1857
+ .tina-tailwind .text-blue-400 {
1858
+ --tw-text-opacity: 1;
1859
+ color: rgb(34 150 254 / var(--tw-text-opacity));
1860
+ }
1810
1861
  .tina-tailwind .text-blue-500 {
1811
1862
  --tw-text-opacity: 1;
1812
1863
  color: rgb(0 132 255 / var(--tw-text-opacity));
@@ -1818,6 +1869,10 @@ var styles = `.tina-tailwind {
1818
1869
  .tina-tailwind .text-current {
1819
1870
  color: currentColor;
1820
1871
  }
1872
+ .tina-tailwind .text-gray-200 {
1873
+ --tw-text-opacity: 1;
1874
+ color: rgb(225 221 236 / var(--tw-text-opacity));
1875
+ }
1821
1876
  .tina-tailwind .text-gray-300 {
1822
1877
  --tw-text-opacity: 1;
1823
1878
  color: rgb(178 173 190 / var(--tw-text-opacity));
@@ -1838,10 +1893,6 @@ var styles = `.tina-tailwind {
1838
1893
  --tw-text-opacity: 1;
1839
1894
  color: rgb(67 62 82 / var(--tw-text-opacity));
1840
1895
  }
1841
- .tina-tailwind .text-gray-800 {
1842
- --tw-text-opacity: 1;
1843
- color: rgb(54 49 69 / var(--tw-text-opacity));
1844
- }
1845
1896
  .tina-tailwind .text-gray-900 {
1846
1897
  --tw-text-opacity: 1;
1847
1898
  color: rgb(37 35 54 / var(--tw-text-opacity));
@@ -1861,6 +1912,15 @@ var styles = `.tina-tailwind {
1861
1912
  .tina-tailwind .underline {
1862
1913
  text-decoration-line: underline;
1863
1914
  }
1915
+ .tina-tailwind .decoration-blue-200 {
1916
+ text-decoration-color: #85C5FE;
1917
+ }
1918
+ .tina-tailwind .decoration-1 {
1919
+ text-decoration-thickness: 1px;
1920
+ }
1921
+ .tina-tailwind .underline-offset-2 {
1922
+ text-underline-offset: 2px;
1923
+ }
1864
1924
  .tina-tailwind .opacity-0 {
1865
1925
  opacity: 0;
1866
1926
  }
@@ -1972,14 +2032,24 @@ var styles = `.tina-tailwind {
1972
2032
  --tw-bg-opacity: 1;
1973
2033
  background-color: rgb(5 116 228 / var(--tw-bg-opacity));
1974
2034
  }
2035
+ .tina-tailwind .hover\\:bg-gray-50\\/50:hover {
2036
+ background-color: rgb(246 246 249 / .5);
2037
+ }
1975
2038
  .tina-tailwind .hover\\:text-blue-400:hover {
1976
2039
  --tw-text-opacity: 1;
1977
2040
  color: rgb(34 150 254 / var(--tw-text-opacity));
1978
2041
  }
2042
+ .tina-tailwind .hover\\:text-blue-500:hover {
2043
+ --tw-text-opacity: 1;
2044
+ color: rgb(0 132 255 / var(--tw-text-opacity));
2045
+ }
1979
2046
  .tina-tailwind .hover\\:text-blue-600:hover {
1980
2047
  --tw-text-opacity: 1;
1981
2048
  color: rgb(5 116 228 / var(--tw-text-opacity));
1982
2049
  }
2050
+ .tina-tailwind .hover\\:decoration-blue-400:hover {
2051
+ text-decoration-color: #2296fe;
2052
+ }
1983
2053
  .tina-tailwind .hover\\:opacity-100:hover {
1984
2054
  opacity: 1;
1985
2055
  }
@@ -2563,12 +2633,24 @@ const useGetCollections = (cms) => {
2563
2633
  function IoMdClose(props) {
2564
2634
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 512 512" }, "child": [{ "tag": "path", "attr": { "d": "M405 136.798L375.202 107 256 226.202 136.798 107 107 136.798 226.202 256 107 375.202 136.798 405 256 285.798 375.202 405 405 375.202 285.798 256z" } }] })(props);
2565
2635
  }
2636
+ function BiArrowBack(props) {
2637
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M21 11H6.414l5.293-5.293-1.414-1.414L2.586 12l7.707 7.707 1.414-1.414L6.414 13H21z" } }] })(props);
2638
+ }
2639
+ function BiCopy(props) {
2640
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z" } }] })(props);
2641
+ }
2566
2642
  function BiEdit(props) {
2567
2643
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "m7 17.013 4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z" } }, { "tag": "path", "attr": { "d": "M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z" } }] })(props);
2568
2644
  }
2569
2645
  function BiError(props) {
2570
2646
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M11.001 10h2v5h-2zM11 16h2v2h-2z" } }, { "tag": "path", "attr": { "d": "M13.768 4.2C13.42 3.545 12.742 3.138 12 3.138s-1.42.407-1.768 1.063L2.894 18.064a1.986 1.986 0 0 0 .054 1.968A1.984 1.984 0 0 0 4.661 21h14.678c.708 0 1.349-.362 1.714-.968a1.989 1.989 0 0 0 .054-1.968L13.768 4.2zM4.661 19 12 5.137 19.344 19H4.661z" } }] })(props);
2571
2647
  }
2648
+ function BiFile(props) {
2649
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M19.903 8.586a.997.997 0 0 0-.196-.293l-6-6a.997.997 0 0 0-.293-.196c-.03-.014-.062-.022-.094-.033a.991.991 0 0 0-.259-.051C13.04 2.011 13.021 2 13 2H6c-1.103 0-2 .897-2 2v16c0 1.103.897 2 2 2h12c1.103 0 2-.897 2-2V9c0-.021-.011-.04-.013-.062a.952.952 0 0 0-.051-.259c-.01-.032-.019-.063-.033-.093zM16.586 8H14V5.414L16.586 8zM6 20V4h6v5a1 1 0 0 0 1 1h5l.002 10H6z" } }, { "tag": "path", "attr": { "d": "M8 12h8v2H8zm0 4h8v2H8zm0-8h2v2H8z" } }] })(props);
2650
+ }
2651
+ function BiFolder(props) {
2652
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M20 5h-8.586L9.707 3.293A.997.997 0 0 0 9 3H4c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h16c1.103 0 2-.897 2-2V7c0-1.103-.897-2-2-2zM4 19V7h16l.002 12H4z" } }] })(props);
2653
+ }
2572
2654
  function BiLogIn(props) {
2573
2655
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "m13 16 5-4-5-4v3H4v2h9z" } }, { "tag": "path", "attr": { "d": "M20 3h-9c-1.103 0-2 .897-2 2v4h2V5h9v14h-9v-4H9v4c0 1.103.897 2 2 2h9c1.103 0 2-.897 2-2V5c0-1.103-.897-2-2-2z" } }] })(props);
2574
2656
  }
@@ -2627,7 +2709,7 @@ const Sidebar = ({ cms }) => {
2627
2709
  }),
2628
2710
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React.createElement(SidebarLink, {
2629
2711
  label: collection.label ? collection.label : collection.name,
2630
- to: `/collections/${collection.name}`,
2712
+ to: `/collections/${collection.name}/~`,
2631
2713
  Icon: ImFilesEmpty
2632
2714
  })
2633
2715
  }), !renderDesktopNav && /* @__PURE__ */ React.createElement(Transition, {
@@ -2664,7 +2746,7 @@ const Sidebar = ({ cms }) => {
2664
2746
  }),
2665
2747
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React.createElement(SidebarLink, {
2666
2748
  label: collection.label ? collection.label : collection.name,
2667
- to: `/collections/${collection.name}`,
2749
+ to: `/collections/${collection.name}/~`,
2668
2750
  Icon: ImFilesEmpty,
2669
2751
  onClick: () => {
2670
2752
  setMenuIsOpen(false);
@@ -2902,6 +2984,9 @@ const DashboardPage = () => {
2902
2984
  }, "Welcome to Tina!")), /* @__PURE__ */ React.createElement(PageBodyNarrow, null, "This is your dashboard for editing or creating content. Select a collection on the left to begin.")));
2903
2985
  });
2904
2986
  };
2987
+ function RiHome2Line(props) {
2988
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "g", "attr": {}, "child": [{ "tag": "path", "attr": { "fill": "none", "d": "M0 0h24v24H0z" } }, { "tag": "path", "attr": { "d": "M19 21H5a1 1 0 0 1-1-1v-9H1l10.327-9.388a1 1 0 0 1 1.346 0L23 11h-3v9a1 1 0 0 1-1 1zM6 19h12V9.157l-6-5.454-6 5.454V19z" } }] }] })(props);
2989
+ }
2905
2990
  const LoadingPage = () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
2906
2991
  style: {
2907
2992
  position: "absolute",
@@ -3020,7 +3105,7 @@ const FullscreenError = ({
3020
3105
  className: "w-7 h-auto fill-current opacity-70 mr-1"
3021
3106
  }), " Reload"));
3022
3107
  };
3023
- const useGetCollection = (cms, collectionName, includeDocuments = true, after = "", sortKey, filterArgs) => {
3108
+ const useGetCollection = (cms, collectionName, includeDocuments = true, folder, after = "", sortKey, filterArgs) => {
3024
3109
  const api = new TinaAdminApi(cms);
3025
3110
  const schema = cms.api.tina.schema;
3026
3111
  const collectionExtra = schema.getCollection(collectionName);
@@ -3029,13 +3114,14 @@ const useGetCollection = (cms, collectionName, includeDocuments = true, after =
3029
3114
  const [error, setError] = useState(void 0);
3030
3115
  const [resetState, setResetSate] = useState(0);
3031
3116
  useEffect(() => {
3117
+ let cancelled = false;
3032
3118
  const fetchCollection = async () => {
3033
3119
  var _a;
3034
- if (await api.isAuthenticated()) {
3120
+ if (await api.isAuthenticated() && !folder.loading && !cancelled) {
3035
3121
  const { name, order } = JSON.parse(sortKey || "{}");
3036
3122
  const validSortKey = ((_a = collectionExtra.fields) == null ? void 0 : _a.map((x) => x.name).includes(name)) ? name : void 0;
3037
3123
  try {
3038
- const collection2 = await api.fetchCollection(collectionName, includeDocuments, after, validSortKey, order, filterArgs);
3124
+ const collection2 = await api.fetchCollection(collectionName, includeDocuments, (filterArgs == null ? void 0 : filterArgs.filterField) ? "" : folder.fullyQualifiedName, after, validSortKey, order, filterArgs);
3039
3125
  setCollection(collection2);
3040
3126
  } catch (error2) {
3041
3127
  cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`);
@@ -3046,15 +3132,29 @@ const useGetCollection = (cms, collectionName, includeDocuments = true, after =
3046
3132
  setLoading(false);
3047
3133
  }
3048
3134
  };
3135
+ if (cancelled)
3136
+ return;
3049
3137
  setLoading(true);
3050
3138
  fetchCollection();
3051
- }, [cms, collectionName, resetState, after, sortKey]);
3139
+ return () => {
3140
+ cancelled = true;
3141
+ };
3142
+ }, [
3143
+ cms,
3144
+ collectionName,
3145
+ folder.loading,
3146
+ folder.fullyQualifiedName,
3147
+ resetState,
3148
+ after,
3149
+ sortKey
3150
+ ]);
3052
3151
  const reFetchCollection = () => setResetSate((x) => x + 1);
3053
3152
  return { collection, loading, error, reFetchCollection, collectionExtra };
3054
3153
  };
3055
3154
  const GetCollection = ({
3056
3155
  cms,
3057
3156
  collectionName,
3157
+ folder,
3058
3158
  includeDocuments = true,
3059
3159
  startCursor,
3060
3160
  sortKey,
@@ -3062,7 +3162,7 @@ const GetCollection = ({
3062
3162
  filterArgs
3063
3163
  }) => {
3064
3164
  const navigate = useNavigate();
3065
- const { collection, loading, error, reFetchCollection, collectionExtra } = useGetCollection(cms, collectionName, includeDocuments, startCursor || "", sortKey, filterArgs) || {};
3165
+ const { collection, loading, error, reFetchCollection, collectionExtra } = useGetCollection(cms, collectionName, includeDocuments, folder, startCursor || "", sortKey, filterArgs) || {};
3066
3166
  useEffect(() => {
3067
3167
  var _a, _b, _c, _d, _e, _f, _g, _h;
3068
3168
  if (loading)
@@ -3072,7 +3172,11 @@ const GetCollection = ({
3072
3172
  const allowDelete = (_f = (_e = (_d = collectionDefinition == null ? void 0 : collectionDefinition.ui) == null ? void 0 : _d.allowedActions) == null ? void 0 : _e.delete) != null ? _f : true;
3073
3173
  if (!allowCreate && !allowDelete && ((_h = (_g = collection.documents) == null ? void 0 : _g.edges) == null ? void 0 : _h.length) === 1) {
3074
3174
  const doc = collection.documents.edges[0].node;
3075
- handleNavigate(navigate, cms, collection, collectionDefinition, doc);
3175
+ const pathToDoc = doc._sys.breadcrumbs;
3176
+ if (folder.fullyQualifiedName) {
3177
+ pathToDoc.unshift("~");
3178
+ }
3179
+ navigate(`/${["collections", "edit", collectionName, ...pathToDoc].join("/")}`, { replace: true });
3076
3180
  }
3077
3181
  }, [(collection == null ? void 0 : collection.name) || "", loading]);
3078
3182
  if (error) {
@@ -3083,6 +3187,42 @@ const GetCollection = ({
3083
3187
  }
3084
3188
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children(collection, loading, reFetchCollection, collectionExtra));
3085
3189
  };
3190
+ const folderRegex = /^.*\/~\/*(.*)$/;
3191
+ const parentFolder = (folder) => {
3192
+ return {
3193
+ ...folder,
3194
+ name: folder.name.split("/").slice(0, -1).join("/"),
3195
+ fullyQualifiedName: folder.fullyQualifiedName.split("/").slice(0, -1).join("/"),
3196
+ parentName: folder.parentName.split("/").slice(0, -1).join("/")
3197
+ };
3198
+ };
3199
+ const useCollectionFolder = () => {
3200
+ const [folder, setFolder] = useState({
3201
+ loading: true,
3202
+ name: "",
3203
+ fullyQualifiedName: "",
3204
+ parentName: ""
3205
+ });
3206
+ const loc = useLocation();
3207
+ useEffect(() => {
3208
+ const match = loc.pathname.match(folderRegex);
3209
+ const update = {
3210
+ name: match ? match[1] : "",
3211
+ fullyQualifiedName: match ? match[1] ? `~/${match[1]}` : "~" : "",
3212
+ loading: false,
3213
+ parentName: ""
3214
+ };
3215
+ if (update.fullyQualifiedName) {
3216
+ const pathParts = update.fullyQualifiedName.split("/");
3217
+ update.parentName = `/${pathParts.slice(0, pathParts.length - 1).join("/")}`;
3218
+ }
3219
+ setFolder({
3220
+ ...folder,
3221
+ ...update
3222
+ });
3223
+ }, [loc]);
3224
+ return folder;
3225
+ };
3086
3226
  const LOCAL_STORAGE_KEY = "tinacms.admin.collection.list.page";
3087
3227
  const isSSR = typeof window === "undefined";
3088
3228
  const TemplateMenu = ({ templates }) => {
@@ -3102,14 +3242,14 @@ const TemplateMenu = ({ templates }) => {
3102
3242
  leaveFrom: "transform opacity-100 scale-100",
3103
3243
  leaveTo: "transform opacity-0 scale-95"
3104
3244
  }, /* @__PURE__ */ React.createElement(Menu.Items, {
3105
- className: "origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
3245
+ className: "origin-top-right absolute right-0 mt-2 z-menu w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
3106
3246
  }, /* @__PURE__ */ React.createElement("div", {
3107
3247
  className: "py-1"
3108
3248
  }, templates.map((template) => /* @__PURE__ */ React.createElement(Menu.Item, {
3109
3249
  key: `${template.label}-${template.name}`
3110
3250
  }, ({ active }) => /* @__PURE__ */ React.createElement(Link, {
3111
3251
  to: `${template.name}/new`,
3112
- className: `w-full text-md px-4 py-2 tracking-wide flex items-center opacity-80 text-gray-600 ${active && "text-gray-800 opacity-100"}`
3252
+ className: `w-full text-md px-4 py-2 tracking-wide flex items-center transition ease-out duration-100 ${active ? "text-blue-600 opacity-100 bg-gray-50" : "opacity-80 text-gray-600"}`
3113
3253
  }, template.label))))))));
3114
3254
  };
3115
3255
  const handleNavigate = (navigate, cms, collection, collectionDefinition, document) => {
@@ -3128,7 +3268,8 @@ const handleNavigate = (navigate, cms, collection, collectionDefinition, documen
3128
3268
  tinaPreview ? navigate(`/~/${routeOverride}`) : window.location.href = routeOverride;
3129
3269
  return null;
3130
3270
  } else {
3131
- navigate(document._sys.breadcrumbs.join("/"));
3271
+ const pathToDoc = document._sys.breadcrumbs;
3272
+ navigate(`/${["collections", "edit", collection.name, ...pathToDoc].join("/")}`, { replace: true });
3132
3273
  }
3133
3274
  };
3134
3275
  const CollectionListPage = () => {
@@ -3147,15 +3288,17 @@ const CollectionListPage = () => {
3147
3288
  after: "",
3148
3289
  booleanEquals: null
3149
3290
  });
3291
+ const [activeSearch, setActiveSearch] = React.useState(false);
3150
3292
  const [endCursor, setEndCursor] = useState("");
3151
3293
  const [prevCursors, setPrevCursors] = useState([]);
3152
3294
  const [sortKey, setSortKey] = useState(isSSR ? "" : window.localStorage.getItem(`${LOCAL_STORAGE_KEY}.${collectionName}`) || JSON.stringify({
3153
3295
  order: "asc",
3154
3296
  name: ""
3155
3297
  }));
3156
- const { order = "asc" } = JSON.parse(sortKey || "{}");
3298
+ const { order = "asc", name: sortName } = JSON.parse(sortKey || "{}");
3157
3299
  const [sortOrder, setSortOrder] = useState(order);
3158
3300
  const loc = useLocation();
3301
+ const folder = useCollectionFolder();
3159
3302
  useEffect(() => {
3160
3303
  setSortKey(window.localStorage.getItem(`${LOCAL_STORAGE_KEY}.${collectionName}`) || JSON.stringify({
3161
3304
  order: "asc",
@@ -3185,6 +3328,7 @@ const CollectionListPage = () => {
3185
3328
  includeDocuments: true,
3186
3329
  startCursor: endCursor,
3187
3330
  sortKey,
3331
+ folder,
3188
3332
  filterArgs: collectionName === vars.collection ? vars : {
3189
3333
  collection: collectionName,
3190
3334
  relativePath: "",
@@ -3203,6 +3347,7 @@ const CollectionListPage = () => {
3203
3347
  const admin = cms.api.admin;
3204
3348
  const pageInfo = collection.documents.pageInfo;
3205
3349
  const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime", "boolean"].includes(x.type));
3350
+ const sortField = fields.find((field) => field.name === sortName);
3206
3351
  const filterFields = (_b = collectionExtra.fields) == null ? void 0 : _b.filter((x) => {
3207
3352
  return ["string", "datetime", "boolean"].includes(x.type) && !x.list;
3208
3353
  });
@@ -3213,6 +3358,7 @@ const CollectionListPage = () => {
3213
3358
  const collectionDefinition = cms.api.tina.schema.getCollection(collection.name);
3214
3359
  const allowCreate = (_e = (_d = (_c = collectionDefinition == null ? void 0 : collectionDefinition.ui) == null ? void 0 : _c.allowedActions) == null ? void 0 : _d.create) != null ? _e : true;
3215
3360
  const allowDelete = (_h = (_g = (_f = collectionDefinition == null ? void 0 : collectionDefinition.ui) == null ? void 0 : _f.allowedActions) == null ? void 0 : _g.delete) != null ? _h : true;
3361
+ const folderView = folder.fullyQualifiedName !== "";
3216
3362
  return /* @__PURE__ */ React.createElement(React.Fragment, null, deleteModalOpen && /* @__PURE__ */ React.createElement(DeleteModal, {
3217
3363
  filename: vars.relativePath,
3218
3364
  deleteFunc: async () => {
@@ -3260,9 +3406,9 @@ const CollectionListPage = () => {
3260
3406
  className: "flex flex-col gap-4"
3261
3407
  }, /* @__PURE__ */ React.createElement("h3", {
3262
3408
  className: "font-sans text-2xl text-gray-700"
3263
- }, collection.label ? collection.label : collection.name), (fields == null ? void 0 : fields.length) > 0 && /* @__PURE__ */ React.createElement("div", {
3409
+ }, collection.label ? collection.label : collection.name), /* @__PURE__ */ React.createElement("div", {
3264
3410
  className: "flex gap-4 items-end flex-wrap"
3265
- }, /* @__PURE__ */ React.createElement("div", {
3411
+ }, (fields == null ? void 0 : fields.length) > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
3266
3412
  className: "flex flex-col gap-2 items-start"
3267
3413
  }, /* @__PURE__ */ React.createElement("label", {
3268
3414
  htmlFor: "sort",
@@ -3425,6 +3571,7 @@ const CollectionListPage = () => {
3425
3571
  className: "flex gap-3"
3426
3572
  }, /* @__PURE__ */ React.createElement(Button, {
3427
3573
  onClick: () => {
3574
+ setActiveSearch(true);
3428
3575
  setEndCursor("");
3429
3576
  setPrevCursors([]);
3430
3577
  reFetchCollection();
@@ -3435,8 +3582,10 @@ const CollectionListPage = () => {
3435
3582
  className: "w-5 h-full ml-1.5 opacity-70"
3436
3583
  })), (vars.startsWith || vars.after || vars.before || vars.booleanEquals) && /* @__PURE__ */ React.createElement(Button, {
3437
3584
  onClick: () => {
3585
+ setActiveSearch(false);
3438
3586
  setVars((old) => ({
3439
3587
  ...old,
3588
+ filterField: "",
3440
3589
  startsWith: "",
3441
3590
  after: "",
3442
3591
  before: "",
@@ -3449,10 +3598,16 @@ const CollectionListPage = () => {
3449
3598
  variant: "white"
3450
3599
  }, "Clear", " ", /* @__PURE__ */ React.createElement(BiX, {
3451
3600
  className: "w-5 h-full ml-1 opacity-70"
3452
- })))))), /* @__PURE__ */ React.createElement("div", {
3601
+ }))))))), /* @__PURE__ */ React.createElement("div", {
3453
3602
  className: "flex self-end justify-self-end"
3454
3603
  }, !collection.templates && allowCreate && /* @__PURE__ */ React.createElement(Link, {
3455
- to: `new`,
3604
+ to: `/${folder.fullyQualifiedName ? [
3605
+ "collections",
3606
+ "new",
3607
+ collectionName,
3608
+ "~",
3609
+ folder.name
3610
+ ].join("/") : ["collections", "new", collectionName].join("/")}`,
3456
3611
  className: "icon-parent inline-flex items-center font-medium focus:outline-none focus:ring-2 focus:shadow-outline text-center rounded-full justify-center transition-all duration-150 ease-out whitespace-nowrap shadow text-white bg-blue-500 hover:bg-blue-600 focus:ring-blue-500 text-sm h-10 px-6"
3457
3612
  }, "Create New", " ", /* @__PURE__ */ React.createElement(BiPlus, {
3458
3613
  className: "w-5 h-full ml-1 opacity-70"
@@ -3460,25 +3615,73 @@ const CollectionListPage = () => {
3460
3615
  templates: collection.templates
3461
3616
  })))), /* @__PURE__ */ React.createElement(PageBody, null, /* @__PURE__ */ React.createElement("div", {
3462
3617
  className: "w-full mx-auto max-w-screen-xl"
3463
- }, documents.length > 0 ? /* @__PURE__ */ React.createElement("table", {
3618
+ }, sortField && !sortField.required && /* @__PURE__ */ React.createElement("p", {
3619
+ className: "mb-4 text-gray-500"
3620
+ }, /* @__PURE__ */ React.createElement("em", null, "Sorting on a non-required field. Some documents may be excluded (if they don't have a value for", " ", sortName, ")")), documents.length > 0 ? /* @__PURE__ */ React.createElement("table", {
3464
3621
  className: "table-auto shadow bg-white border-b border-gray-200 w-full max-w-full rounded-lg"
3465
3622
  }, /* @__PURE__ */ React.createElement("tbody", {
3466
3623
  className: "divide-y divide-gray-150"
3467
- }, documents.map((document) => {
3624
+ }, !activeSearch && folder.name && /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("td", {
3625
+ colSpan: 5
3626
+ }, /* @__PURE__ */ React.createElement(Breadcrumb, {
3627
+ folder,
3628
+ navigate,
3629
+ collectionName
3630
+ }))), documents.map((document) => {
3468
3631
  var _a2;
3632
+ if (document.node.__typename === "Folder") {
3633
+ return /* @__PURE__ */ React.createElement("tr", {
3634
+ key: `folder-${document.node.path}`
3635
+ }, /* @__PURE__ */ React.createElement("td", {
3636
+ className: "pl-5 pr-3 py-3 truncate max-w-0"
3637
+ }, /* @__PURE__ */ React.createElement("a", {
3638
+ className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer truncate",
3639
+ onClick: () => {
3640
+ navigate(`/${[
3641
+ "collections",
3642
+ collectionName,
3643
+ document.node.path
3644
+ ].join("/")}`, { replace: true });
3645
+ }
3646
+ }, /* @__PURE__ */ React.createElement(BiFolder, {
3647
+ className: "inline-block h-6 w-auto flex-shrink-0 opacity-70"
3648
+ }), /* @__PURE__ */ React.createElement("span", {
3649
+ className: "truncate block"
3650
+ }, /* @__PURE__ */ React.createElement("span", {
3651
+ className: "block text-xs text-gray-400 mb-1 uppercase"
3652
+ }, "Name"), /* @__PURE__ */ React.createElement("span", {
3653
+ className: "h-5 leading-5 block truncate"
3654
+ }, /* @__PURE__ */ React.createElement("span", null, document.node.name))))), /* @__PURE__ */ React.createElement("td", {
3655
+ className: "px-3 py-3 truncate max-w-0",
3656
+ colSpan: 4
3657
+ }, /* @__PURE__ */ React.createElement("span", {
3658
+ className: "block text-xs text-gray-400 mb-1 uppercase"
3659
+ }, "Path"), /* @__PURE__ */ React.createElement("span", {
3660
+ className: "leading-5 block text-sm font-medium text-gray-900 truncate"
3661
+ }, document.node.path.substring(2).split("/").map((node) => {
3662
+ return /* @__PURE__ */ React.createElement("span", {
3663
+ key: node
3664
+ }, /* @__PURE__ */ React.createElement("span", {
3665
+ className: "text-gray-300 pr-0.5"
3666
+ }, "/"), /* @__PURE__ */ React.createElement("span", {
3667
+ className: "pr-0.5"
3668
+ }, node));
3669
+ }))));
3670
+ }
3469
3671
  const hasTitle = Boolean(document.node._sys.title);
3470
3672
  const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
3471
3673
  return /* @__PURE__ */ React.createElement("tr", {
3472
3674
  key: `document-${document.node._sys.relativePath}`,
3473
3675
  className: ""
3474
3676
  }, /* @__PURE__ */ React.createElement("td", {
3475
- className: "pl-5 pr-3 py-2 truncate max-w-0"
3677
+ className: "pl-5 pr-3 py-3 truncate max-w-0",
3678
+ colSpan: hasTitle ? 1 : 2
3476
3679
  }, /* @__PURE__ */ React.createElement("a", {
3477
3680
  className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer truncate",
3478
3681
  onClick: () => {
3479
3682
  handleNavigate(navigate, cms, collection, collectionDefinition, document.node);
3480
3683
  }
3481
- }, /* @__PURE__ */ React.createElement(BiEdit, {
3684
+ }, /* @__PURE__ */ React.createElement(BiFile, {
3482
3685
  className: "inline-block h-6 w-auto flex-shrink-0 opacity-70"
3483
3686
  }), /* @__PURE__ */ React.createElement("span", {
3484
3687
  className: "truncate block"
@@ -3486,24 +3689,24 @@ const CollectionListPage = () => {
3486
3689
  className: "block text-xs text-gray-400 mb-1 uppercase"
3487
3690
  }, hasTitle ? "Title" : "Filename"), /* @__PURE__ */ React.createElement("span", {
3488
3691
  className: "h-5 leading-5 block truncate"
3489
- }, !hasTitle && subfolders && /* @__PURE__ */ React.createElement("span", {
3692
+ }, !folderView && !hasTitle && subfolders && /* @__PURE__ */ React.createElement("span", {
3490
3693
  className: "text-xs text-gray-400"
3491
3694
  }, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, hasTitle ? (_a2 = document.node._sys) == null ? void 0 : _a2.title : document.node._sys.filename))))), hasTitle && /* @__PURE__ */ React.createElement("td", {
3492
- className: "px-3 py-4 truncate max-w-0 "
3695
+ className: "px-3 py-3 truncate max-w-0"
3493
3696
  }, /* @__PURE__ */ React.createElement("span", {
3494
3697
  className: "block text-xs text-gray-400 mb-1 uppercase"
3495
3698
  }, "Filename"), /* @__PURE__ */ React.createElement("span", {
3496
3699
  className: "h-5 leading-5 block text-sm font-medium text-gray-900 truncate"
3497
- }, subfolders && /* @__PURE__ */ React.createElement("span", {
3700
+ }, !folderView && subfolders && /* @__PURE__ */ React.createElement("span", {
3498
3701
  className: "text-xs text-gray-400"
3499
3702
  }, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node._sys.filename))), /* @__PURE__ */ React.createElement("td", {
3500
- className: "px-3 py-4 truncate w-[15%]"
3703
+ className: "px-3 py-3 truncate w-[15%]"
3501
3704
  }, /* @__PURE__ */ React.createElement("span", {
3502
3705
  className: "block text-xs text-gray-400 mb-1 uppercase"
3503
3706
  }, "Extension"), /* @__PURE__ */ React.createElement("span", {
3504
3707
  className: "h-5 leading-5 block text-sm font-medium text-gray-900"
3505
3708
  }, document.node._sys.extension)), /* @__PURE__ */ React.createElement("td", {
3506
- className: "px-3 py-4 truncate w-[15%]"
3709
+ className: "px-3 py-3 truncate w-[15%]"
3507
3710
  }, /* @__PURE__ */ React.createElement("span", {
3508
3711
  className: "block text-xs text-gray-400 mb-1 uppercase"
3509
3712
  }, "Template"), /* @__PURE__ */ React.createElement("span", {
@@ -3519,7 +3722,35 @@ const CollectionListPage = () => {
3519
3722
  size: "1.3rem"
3520
3723
  }),
3521
3724
  onMouseDown: () => {
3522
- navigate(`${document.node._sys.breadcrumbs.join("/")}`, { replace: true });
3725
+ const pathToDoc = document.node._sys.breadcrumbs;
3726
+ if (folder.fullyQualifiedName) {
3727
+ pathToDoc.unshift("~");
3728
+ }
3729
+ navigate(`/${[
3730
+ "collections",
3731
+ "edit",
3732
+ collectionName,
3733
+ ...pathToDoc
3734
+ ].join("/")}`, { replace: true });
3735
+ }
3736
+ },
3737
+ allowCreate && {
3738
+ name: "duplicate",
3739
+ label: "Duplicate",
3740
+ Icon: /* @__PURE__ */ React.createElement(BiCopy, {
3741
+ size: "1.3rem"
3742
+ }),
3743
+ onMouseDown: () => {
3744
+ const pathToDoc = document.node._sys.breadcrumbs;
3745
+ if (folder.fullyQualifiedName) {
3746
+ pathToDoc.unshift("~");
3747
+ }
3748
+ navigate(`/${[
3749
+ "collections",
3750
+ "duplicate",
3751
+ collectionName,
3752
+ ...pathToDoc
3753
+ ].join("/")}`, { replace: true });
3523
3754
  }
3524
3755
  },
3525
3756
  allowDelete && {
@@ -3581,6 +3812,51 @@ const CollectionListPage = () => {
3581
3812
  }));
3582
3813
  });
3583
3814
  };
3815
+ const Breadcrumb = ({ folder, navigate, collectionName }) => {
3816
+ const folderArray = folder.name.split("/");
3817
+ return /* @__PURE__ */ React.createElement("div", {
3818
+ className: "w-full bg-gray-50/30 flex items-stretch"
3819
+ }, /* @__PURE__ */ React.createElement("button", {
3820
+ onClick: () => {
3821
+ const folders = folder.fullyQualifiedName.split("/");
3822
+ navigate(`/${[
3823
+ "collections",
3824
+ collectionName,
3825
+ ...folders.slice(0, folders.length - 1)
3826
+ ].join("/")}`, { replace: true });
3827
+ },
3828
+ className: "px-3 py-2 bg-white hover:bg-gray-50/50 transition ease-out duration-100 border-r border-gray-100 text-blue-500 hover:text-blue-600"
3829
+ }, /* @__PURE__ */ React.createElement(BiArrowBack, {
3830
+ className: "w-6 h-full opacity-70"
3831
+ })), /* @__PURE__ */ React.createElement("span", {
3832
+ className: "px-3 py-2 text-gray-600 flex flex-wrap items-center justify-start gap-1"
3833
+ }, /* @__PURE__ */ React.createElement("button", {
3834
+ onClick: () => {
3835
+ navigate(`/collections/${collectionName}/~`, {
3836
+ replace: true
3837
+ });
3838
+ },
3839
+ className: "shrink-0 bg-transparent p-0 border-0 text-blue-400 hover:text-blue-500 transition-all ease-out duration-100 opacity-70 hover:opacity-100"
3840
+ }, /* @__PURE__ */ React.createElement(RiHome2Line, {
3841
+ className: "w-5 h-auto"
3842
+ })), folderArray.map((node, index) => {
3843
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
3844
+ className: "text-gray-200 shrink-0"
3845
+ }, "/"), index < folderArray.length - 1 ? /* @__PURE__ */ React.createElement("button", {
3846
+ className: "bg-transparent whitespace-nowrap truncate p-0 border-0 text-blue-500 hover:text-blue-600 transition-all ease-out duration-100 underline underline-offset-2 decoration-1 decoration-blue-200 hover:decoration-blue-400",
3847
+ onClick: () => {
3848
+ const folders = folder.fullyQualifiedName.split("/");
3849
+ navigate(`/${[
3850
+ "collections",
3851
+ collectionName,
3852
+ ...folders.slice(0, folders.length - (folders.length - (index + 2)))
3853
+ ].join("/")}`, { replace: true });
3854
+ }
3855
+ }, node) : /* @__PURE__ */ React.createElement("span", {
3856
+ className: "whitespace-nowrap truncate"
3857
+ }, node));
3858
+ })));
3859
+ };
3584
3860
  const NoDocumentsPlaceholder = () => {
3585
3861
  return /* @__PURE__ */ React.createElement("div", {
3586
3862
  className: "text-center px-5 py-3 flex flex-col items-center justify-center shadow border border-gray-100 bg-gray-50 border-b border-gray-200 w-full max-w-full rounded-lg"
@@ -3643,10 +3919,10 @@ function FaLock(props) {
3643
3919
  function FaUnlock(props) {
3644
3920
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 448 512" }, "child": [{ "tag": "path", "attr": { "d": "M400 256H152V152.9c0-39.6 31.7-72.5 71.3-72.9 40-.4 72.7 32.1 72.7 72v16c0 13.3 10.7 24 24 24h32c13.3 0 24-10.7 24-24v-16C376 68 307.5-.3 223.5 0 139.5.3 72 69.5 72 153.5V256H48c-26.5 0-48 21.5-48 48v160c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V304c0-26.5-21.5-48-48-48z" } }] })(props);
3645
3921
  }
3646
- const createDocument = async (cms, collection, template, mutationInfo, values) => {
3922
+ const createDocument = async (cms, collection, template, mutationInfo, folder, values) => {
3647
3923
  const api = new TinaAdminApi(cms);
3648
3924
  const { filename, ...leftover } = values;
3649
- const relativePath = `${filename}.${collection.format}`;
3925
+ const relativePath = `${folder ? `${folder}/` : ""}${filename}.${collection.format}`;
3650
3926
  const params = api.schema.transformPayload(collection.name, {
3651
3927
  _collection: collection.name,
3652
3928
  ...template && { _template: template.name },
@@ -3662,10 +3938,12 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
3662
3938
  }
3663
3939
  };
3664
3940
  const CollectionCreatePage = () => {
3941
+ const folder = useCollectionFolder();
3665
3942
  const { collectionName, templateName } = useParams();
3666
3943
  return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
3667
3944
  cms,
3668
3945
  collectionName,
3946
+ folder,
3669
3947
  includeDocuments: false
3670
3948
  }, (collection) => {
3671
3949
  const mutationInfo = {
@@ -3676,7 +3954,8 @@ const CollectionCreatePage = () => {
3676
3954
  cms,
3677
3955
  collection,
3678
3956
  templateName,
3679
- mutationInfo
3957
+ mutationInfo,
3958
+ folder
3680
3959
  });
3681
3960
  }));
3682
3961
  };
@@ -3698,7 +3977,14 @@ const FilenameInput = (props) => {
3698
3977
  className: `text-blue-500 absolute top-1/2 left-2 -translate-y-1/2 pointer-events-none h-5 w-auto transition-opacity duration-150 ease-out ${!filenameTouched && !props.readonly ? "opacity-0 group-hover:opacity-80 group-active:opacity-80" : "opacity-0"}`
3699
3978
  }));
3700
3979
  };
3701
- const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3980
+ const RenderForm$1 = ({
3981
+ cms,
3982
+ collection,
3983
+ folder,
3984
+ templateName,
3985
+ mutationInfo,
3986
+ customDefaults
3987
+ }) => {
3702
3988
  var _a, _b, _c, _d, _e, _f;
3703
3989
  const navigate = useNavigate();
3704
3990
  const [formIsPristine, setFormIsPristine] = useState(true);
@@ -3724,7 +4010,7 @@ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3724
4010
  };
3725
4011
  }
3726
4012
  }
3727
- const defaultItem = ((_d = template.ui) == null ? void 0 : _d.defaultItem) || (template == null ? void 0 : template.defaultItem);
4013
+ const defaultItem = customDefaults || ((_d = template.ui) == null ? void 0 : _d.defaultItem) || (template == null ? void 0 : template.defaultItem);
3728
4014
  const form = useMemo(() => {
3729
4015
  var _a2, _b2;
3730
4016
  return new Form({
@@ -3781,9 +4067,12 @@ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3781
4067
  ],
3782
4068
  onSubmit: async (values) => {
3783
4069
  try {
3784
- await createDocument(cms, collection, template, mutationInfo, values);
4070
+ const folderName = folder.fullyQualifiedName ? folder.name : "";
4071
+ await createDocument(cms, collection, template, mutationInfo, folderName, values);
3785
4072
  cms.alerts.success("Document created!");
3786
- navigate(`/collections/${collection.name}`);
4073
+ setTimeout(() => {
4074
+ navigate(`/collections/${collection.name}${folder.fullyQualifiedName ? `/${folder.fullyQualifiedName}` : ""}`);
4075
+ }, 10);
3787
4076
  } catch (error) {
3788
4077
  console.error(error);
3789
4078
  const defaultErrorText = "There was a problem saving your document.";
@@ -3810,7 +4099,7 @@ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3810
4099
  }, /* @__PURE__ */ React.createElement("span", {
3811
4100
  className: "block text-sm leading-tight uppercase text-gray-400 mb-1"
3812
4101
  }, /* @__PURE__ */ React.createElement(Link, {
3813
- to: `/collections/${collection.name}`,
4102
+ to: `/collections/${collection.name}${folder.fullyQualifiedName ? `/${folder.fullyQualifiedName}` : ""}`,
3814
4103
  className: "inline-block text-current hover:text-blue-400 focus:underline focus:outline-none focus:text-blue-400 font-medium transition-colors duration-150 ease-out"
3815
4104
  }, collection.label ? collection.label : collection.name), /* @__PURE__ */ React.createElement(HiChevronRight, {
3816
4105
  className: "inline-block -mt-0.5 opacity-50"
@@ -3863,6 +4152,38 @@ const GetDocument = ({
3863
4152
  }
3864
4153
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children(document, loading));
3865
4154
  };
4155
+ const CollectionDuplicatePage = () => {
4156
+ const folder = useCollectionFolder();
4157
+ const { collectionName, ...rest } = useParams();
4158
+ const { "*": filename } = rest;
4159
+ return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
4160
+ cms,
4161
+ collectionName,
4162
+ folder,
4163
+ includeDocuments: false
4164
+ }, (collection) => {
4165
+ const relativePath = `${filename.startsWith("~/") ? filename.substring(2) : filename}.${collection.format}`;
4166
+ const mutationInfo = {
4167
+ includeCollection: true,
4168
+ includeTemplate: !!collection.templates
4169
+ };
4170
+ return /* @__PURE__ */ React.createElement(GetDocument, {
4171
+ cms,
4172
+ collectionName: collection.name,
4173
+ relativePath
4174
+ }, (document) => {
4175
+ var _a;
4176
+ return /* @__PURE__ */ React.createElement(RenderForm$1, {
4177
+ cms,
4178
+ collection,
4179
+ templateName: (_a = document._values) == null ? void 0 : _a._template,
4180
+ folder: parentFolder(folder),
4181
+ mutationInfo,
4182
+ customDefaults: document._values
4183
+ });
4184
+ });
4185
+ }));
4186
+ };
3866
4187
  const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
3867
4188
  const api = new TinaAdminApi(cms);
3868
4189
  const params = api.schema.transformPayload(collection.name, values);
@@ -3877,13 +4198,16 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
3877
4198
  };
3878
4199
  const CollectionUpdatePage = () => {
3879
4200
  const { collectionName, ...rest } = useParams();
4201
+ const folder = useCollectionFolder();
3880
4202
  const { "*": filename } = rest;
4203
+ const resolvedFile = folder.fullyQualifiedName ? folder.name : filename;
3881
4204
  return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
3882
4205
  cms,
3883
4206
  collectionName,
4207
+ folder,
3884
4208
  includeDocuments: false
3885
4209
  }, (collection) => {
3886
- const relativePath = `${filename}.${collection.format}`;
4210
+ const relativePath = `${resolvedFile}.${collection.format}`;
3887
4211
  const mutationInfo = {
3888
4212
  includeCollection: true,
3889
4213
  includeTemplate: !!collection.templates
@@ -3895,7 +4219,7 @@ const CollectionUpdatePage = () => {
3895
4219
  }, (document) => /* @__PURE__ */ React.createElement(RenderForm, {
3896
4220
  cms,
3897
4221
  document,
3898
- filename,
4222
+ filename: resolvedFile,
3899
4223
  relativePath,
3900
4224
  collection,
3901
4225
  mutationInfo
@@ -3913,6 +4237,7 @@ const RenderForm = ({
3913
4237
  var _a, _b;
3914
4238
  const [formIsPristine, setFormIsPristine] = useState(true);
3915
4239
  const schema = cms.api.tina.schema;
4240
+ const parentFolder2 = relativePath.split("/").slice(0, -1).join("/");
3916
4241
  const schemaCollection = schema.getCollection(collection.name);
3917
4242
  const template = schema.getTemplateForData({
3918
4243
  collection: schemaCollection,
@@ -3954,7 +4279,7 @@ const RenderForm = ({
3954
4279
  }, /* @__PURE__ */ React.createElement("span", {
3955
4280
  className: "block text-sm leading-tight uppercase text-gray-400 mb-1"
3956
4281
  }, /* @__PURE__ */ React.createElement(Link, {
3957
- to: `/collections/${collection.name}`,
4282
+ to: `/collections/${collection.name}/~${parentFolder2}`,
3958
4283
  className: "inline-block text-current hover:text-blue-400 focus:underline focus:outline-none focus:text-blue-400 font-medium transition-colors duration-150 ease-out"
3959
4284
  }, collection.label ? collection.label : collection.name), /* @__PURE__ */ React.createElement(HiChevronRight, {
3960
4285
  className: "inline-block -mt-0.5 opacity-50"
@@ -4115,22 +4440,42 @@ const TinaAdmin = ({
4115
4440
  path: "graphql",
4116
4441
  element: /* @__PURE__ */ React.createElement(PlainLayout, null, /* @__PURE__ */ React.createElement(Playground, null))
4117
4442
  }), /* @__PURE__ */ React.createElement(Route, {
4118
- path: "collections/:collectionName/new",
4443
+ path: "collections/new/:collectionName",
4119
4444
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4120
4445
  cms
4121
4446
  }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
4122
4447
  }), /* @__PURE__ */ React.createElement(Route, {
4123
- path: "collections/:collectionName/:templateName/new",
4448
+ path: "collections/duplicate/:collectionName/~/*",
4449
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4450
+ cms
4451
+ }, /* @__PURE__ */ React.createElement(CollectionDuplicatePage, null))
4452
+ }), /* @__PURE__ */ React.createElement(Route, {
4453
+ path: "collections/duplicate/:collectionName/*",
4454
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4455
+ cms
4456
+ }, /* @__PURE__ */ React.createElement(CollectionDuplicatePage, null))
4457
+ }), /* @__PURE__ */ React.createElement(Route, {
4458
+ path: "collections/new/:collectionName/:templateName",
4124
4459
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4125
4460
  cms
4126
4461
  }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
4127
4462
  }), /* @__PURE__ */ React.createElement(Route, {
4128
- path: "collections/:collectionName/*",
4463
+ path: "collections/new/:collectionName/:templateName/~/*",
4464
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4465
+ cms
4466
+ }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
4467
+ }), /* @__PURE__ */ React.createElement(Route, {
4468
+ path: "collections/new/:collectionName/~/*",
4469
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4470
+ cms
4471
+ }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
4472
+ }), /* @__PURE__ */ React.createElement(Route, {
4473
+ path: "collections/edit/:collectionName/*",
4129
4474
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4130
4475
  cms
4131
4476
  }, /* @__PURE__ */ React.createElement(CollectionUpdatePage, null))
4132
4477
  }), /* @__PURE__ */ React.createElement(Route, {
4133
- path: "collections/:collectionName",
4478
+ path: "collections/:collectionName/*",
4134
4479
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
4135
4480
  cms
4136
4481
  }, /* @__PURE__ */ React.createElement(CollectionListPage, null))