tinacms 0.59.0 → 0.60.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/index.es.js CHANGED
@@ -29,16 +29,17 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, useLocalStorage, TinaCMS, BranchSwitcherPlugin, BranchDataProvider, TinaProvider, useCMS, useBranchData, FormMetaPlugin, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
33
+ export * from "@tinacms/toolkit";
32
34
  import { TypeInfo, visit, visitWithTypeInfo, getNamedType, GraphQLObjectType, isLeafType, GraphQLUnionType, isScalarType, getIntrospectionQuery, buildClientSchema, print } from "graphql";
33
35
  import set from "lodash.set";
34
36
  import gql$1 from "graphql-tag";
35
- import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, useLocalStorage, TinaCMS, BranchSwitcherPlugin, BranchDataProvider, TinaProvider, useCMS, useBranchData, FormMetaPlugin, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
36
- export * from "@tinacms/toolkit";
37
37
  import React, { useState, useCallback, useEffect, Fragment } from "react";
38
38
  import styled from "styled-components";
39
39
  import * as yup from "yup";
40
+ import { setEditing, useEditState } from "@tinacms/sharedctx";
40
41
  import { getIn, setIn } from "final-form";
41
- import { useLocation, useParams, Link, useHistory, BrowserRouter, NavLink, Switch, Route } from "react-router-dom";
42
+ import { NavLink, useLocation, useParams, Link, useNavigate, BrowserRouter, Routes, Route } from "react-router-dom";
42
43
  import { Menu, Transition } from "@headlessui/react";
43
44
  function popupWindow(url, title, window2, w, h) {
44
45
  const y = window2.top.outerHeight / 2 + window2.top.screenY - h / 2;
@@ -423,10 +424,10 @@ mutation addPendingDocumentMutation(
423
424
  this.clientId = options.clientId;
424
425
  switch (tokenStorage) {
425
426
  case "LOCAL_STORAGE":
426
- this.getToken = function() {
427
+ this.getToken = async function() {
427
428
  const tokens = localStorage.getItem(AUTH_TOKEN_KEY) || null;
428
429
  if (tokens) {
429
- return JSON.parse(tokens);
430
+ return await this.getRefreshedToken(tokens);
430
431
  } else {
431
432
  return {
432
433
  access_token: null,
@@ -440,9 +441,9 @@ mutation addPendingDocumentMutation(
440
441
  };
441
442
  break;
442
443
  case "MEMORY":
443
- this.getToken = () => {
444
+ this.getToken = async () => {
444
445
  if (this.token) {
445
- return JSON.parse(this.token);
446
+ return await this.getRefreshedToken(this.token);
446
447
  } else {
447
448
  return {
448
449
  access_token: null,
@@ -481,13 +482,16 @@ mutation addPendingDocumentMutation(
481
482
  method: "POST",
482
483
  headers: {
483
484
  "Content-Type": "application/json",
484
- Authorization: "Bearer " + this.getToken().id_token
485
+ Authorization: "Bearer " + (await this.getToken()).id_token
485
486
  },
486
487
  body: JSON.stringify({
487
488
  query: typeof query === "function" ? print(query(gql$1)) : query,
488
489
  variables
489
490
  })
490
491
  });
492
+ if (res.status !== 200) {
493
+ throw new Error(`Unable to complete request, ${res.statusText}`);
494
+ }
491
495
  const json = await res.json();
492
496
  if (json.errors) {
493
497
  throw new Error(`Unable to fetch, errors:
@@ -495,6 +499,47 @@ mutation addPendingDocumentMutation(
495
499
  }
496
500
  return json.data;
497
501
  }
502
+ parseJwt(token) {
503
+ const base64Url = token.split(".")[1];
504
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
505
+ const jsonPayload = decodeURIComponent(atob(base64).split("").map(function(c) {
506
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
507
+ }).join(""));
508
+ return JSON.parse(jsonPayload);
509
+ }
510
+ async getRefreshedToken(tokens) {
511
+ const { access_token, id_token, refresh_token } = JSON.parse(tokens);
512
+ const { exp, iss, client_id } = this.parseJwt(access_token);
513
+ if (Date.now() / 1e3 >= exp) {
514
+ const refreshResponse = await fetch(iss, {
515
+ method: "POST",
516
+ headers: {
517
+ "Content-Type": "application/x-amz-json-1.1",
518
+ "x-amz-target": "AWSCognitoIdentityProviderService.InitiateAuth"
519
+ },
520
+ body: JSON.stringify({
521
+ ClientId: client_id,
522
+ AuthFlow: "REFRESH_TOKEN_AUTH",
523
+ AuthParameters: {
524
+ REFRESH_TOKEN: refresh_token,
525
+ DEVICE_KEY: null
526
+ }
527
+ })
528
+ });
529
+ if (refreshResponse.status !== 200) {
530
+ throw new Error("Unable to refresh auth tokens");
531
+ }
532
+ const responseJson = await refreshResponse.json();
533
+ const newToken = {
534
+ access_token: responseJson.AuthenticationResult.AccessToken,
535
+ id_token: responseJson.AuthenticationResult.IdToken,
536
+ refresh_token
537
+ };
538
+ this.setToken(newToken);
539
+ return Promise.resolve(newToken);
540
+ }
541
+ return Promise.resolve({ access_token, id_token, refresh_token });
542
+ }
498
543
  async isAuthorized() {
499
544
  return this.isAuthenticated();
500
545
  }
@@ -510,7 +555,7 @@ mutation addPendingDocumentMutation(
510
555
  const headers = (init == null ? void 0 : init.headers) || {};
511
556
  return await fetch(input, __spreadProps(__spreadValues({}, init), {
512
557
  headers: new Headers(__spreadValues({
513
- Authorization: "Bearer " + this.getToken().id_token
558
+ Authorization: "Bearer " + (await this.getToken()).id_token
514
559
  }, headers))
515
560
  }));
516
561
  }
@@ -652,24 +697,6 @@ function safeAssertShape(value, yupSchema) {
652
697
  return false;
653
698
  }
654
699
  }
655
- const LOCALSTORAGEKEY = "tina.isEditing";
656
- const isSSR = typeof window === "undefined";
657
- const isEditing = () => {
658
- if (!isSSR) {
659
- const isEdit = window.localStorage.getItem(LOCALSTORAGEKEY);
660
- return isEdit && isEdit === "true";
661
- }
662
- return false;
663
- };
664
- const setEditing = (isEditing2) => {
665
- if (!isSSR) {
666
- window.localStorage.setItem(LOCALSTORAGEKEY, isEditing2 ? "true" : "false");
667
- }
668
- };
669
- React.createContext({
670
- edit: isEditing(),
671
- setEdit: void 0
672
- });
673
700
  function sleep(ms) {
674
701
  return new Promise((resolve) => setTimeout(resolve, ms));
675
702
  }
@@ -892,6 +919,9 @@ function BiLinkExternal(props) {
892
919
  function BiLogIn(props) {
893
920
  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);
894
921
  }
922
+ function BiLogOut(props) {
923
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M16 13v-2H7V8l-5 4 5 4v-3z" } }, { "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);
924
+ }
895
925
  function useGraphqlForms({
896
926
  query,
897
927
  variables,
@@ -1009,25 +1039,30 @@ function useGraphqlForms({
1009
1039
  setPendingReset(queryName);
1010
1040
  },
1011
1041
  onSubmit: async (payload2) => {
1012
- const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
1013
- const variables2 = { params };
1014
- const mutationString = result.form.mutationInfo.string;
1015
- if (onSubmit) {
1016
- onSubmit({
1017
- queryString: mutationString,
1018
- mutationString,
1019
- variables: variables2
1020
- });
1021
- } else {
1022
- try {
1023
- await cms.api.tina.request(mutationString, {
1042
+ try {
1043
+ const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
1044
+ const variables2 = { params };
1045
+ const mutationString = result.form.mutationInfo.string;
1046
+ if (onSubmit) {
1047
+ onSubmit({
1048
+ queryString: mutationString,
1049
+ mutationString,
1024
1050
  variables: variables2
1025
1051
  });
1026
- cms.alerts.success("Document saved!");
1027
- } catch (e) {
1028
- cms.alerts.error("There was a problem saving your document");
1029
- console.error(e);
1052
+ } else {
1053
+ try {
1054
+ await cms.api.tina.request(mutationString, {
1055
+ variables: variables2
1056
+ });
1057
+ cms.alerts.success("Document saved!");
1058
+ } catch (e) {
1059
+ cms.alerts.error("There was a problem saving your document");
1060
+ console.error(e);
1061
+ }
1030
1062
  }
1063
+ } catch (e) {
1064
+ console.error(e);
1065
+ cms.alerts.error("There was a problem saving your document");
1031
1066
  }
1032
1067
  }
1033
1068
  };
@@ -1139,6 +1174,9 @@ const transformParams = (data) => {
1139
1174
  return { [_template]: nested };
1140
1175
  } catch (e) {
1141
1176
  if (e.message === "Failed to assertShape - _template is a required field") {
1177
+ if (!data) {
1178
+ return [];
1179
+ }
1142
1180
  const accum = {};
1143
1181
  Object.entries(data).map(([keyName, value]) => {
1144
1182
  accum[keyName] = transformParams(value);
@@ -1596,12 +1634,6 @@ function gql(strings, ...args) {
1596
1634
  });
1597
1635
  return str;
1598
1636
  }
1599
- function ImFilesEmpty(props) {
1600
- return GenIcon({ "tag": "svg", "attr": { "version": "1.1", "viewBox": "0 0 16 16" }, "child": [{ "tag": "path", "attr": { "d": "M14.341 5.579c-0.347-0.473-0.831-1.027-1.362-1.558s-1.085-1.015-1.558-1.362c-0.806-0.591-1.197-0.659-1.421-0.659h-5.75c-0.689 0-1.25 0.561-1.25 1.25v11.5c0 0.689 0.561 1.25 1.25 1.25h9.5c0.689 0 1.25-0.561 1.25-1.25v-7.75c0-0.224-0.068-0.615-0.659-1.421zM12.271 4.729c0.48 0.48 0.856 0.912 1.134 1.271h-2.406v-2.405c0.359 0.278 0.792 0.654 1.271 1.134v0zM14 14.75c0 0.136-0.114 0.25-0.25 0.25h-9.5c-0.136 0-0.25-0.114-0.25-0.25v-11.5c0-0.135 0.114-0.25 0.25-0.25 0 0 5.749-0 5.75 0v3.5c0 0.276 0.224 0.5 0.5 0.5h3.5v7.75z" } }, { "tag": "path", "attr": { "d": "M9.421 0.659c-0.806-0.591-1.197-0.659-1.421-0.659h-5.75c-0.689 0-1.25 0.561-1.25 1.25v11.5c0 0.604 0.43 1.109 1 1.225v-12.725c0-0.135 0.115-0.25 0.25-0.25h7.607c-0.151-0.124-0.297-0.238-0.437-0.341z" } }] })(props);
1601
- }
1602
- function VscOpenPreview(props) {
1603
- return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 16 16", "fill": "currentColor" }, "child": [{ "tag": "path", "attr": { "fillRule": "evenodd", "clipRule": "evenodd", "d": "M3 1h11l1 1v5.3a3.21 3.21 0 0 0-1-.3V2H9v10.88L7.88 14H3l-1-1V2l1-1zm0 12h5V2H3v11zm10.379-4.998a2.53 2.53 0 0 0-1.19.348h-.03a2.51 2.51 0 0 0-.799 3.53L9 14.23l.71.71 2.35-2.36c.325.22.7.358 1.09.4a2.47 2.47 0 0 0 1.14-.13 2.51 2.51 0 0 0 1-.63 2.46 2.46 0 0 0 .58-1 2.63 2.63 0 0 0 .07-1.15 2.53 2.53 0 0 0-1.35-1.81 2.53 2.53 0 0 0-1.211-.258zm.24 3.992a1.5 1.5 0 0 1-.979-.244 1.55 1.55 0 0 1-.56-.68 1.49 1.49 0 0 1-.08-.86 1.49 1.49 0 0 1 1.18-1.18 1.49 1.49 0 0 1 .86.08c.276.117.512.311.68.56a1.5 1.5 0 0 1-1.1 2.324z" } }] })(props);
1604
- }
1605
1637
  const Layout = ({ children }) => {
1606
1638
  return /* @__PURE__ */ React.createElement("div", {
1607
1639
  style: {
@@ -1616,14 +1648,12 @@ const Layout = ({ children }) => {
1616
1648
  }
1617
1649
  }, children);
1618
1650
  };
1619
- const GetCMS = ({ children }) => {
1620
- try {
1621
- const cms = useCMS();
1622
- return /* @__PURE__ */ React.createElement(React.Fragment, null, children(cms));
1623
- } catch (e) {
1624
- return null;
1625
- }
1626
- };
1651
+ function ImFilesEmpty(props) {
1652
+ return GenIcon({ "tag": "svg", "attr": { "version": "1.1", "viewBox": "0 0 16 16" }, "child": [{ "tag": "path", "attr": { "d": "M14.341 5.579c-0.347-0.473-0.831-1.027-1.362-1.558s-1.085-1.015-1.558-1.362c-0.806-0.591-1.197-0.659-1.421-0.659h-5.75c-0.689 0-1.25 0.561-1.25 1.25v11.5c0 0.689 0.561 1.25 1.25 1.25h9.5c0.689 0 1.25-0.561 1.25-1.25v-7.75c0-0.224-0.068-0.615-0.659-1.421zM12.271 4.729c0.48 0.48 0.856 0.912 1.134 1.271h-2.406v-2.405c0.359 0.278 0.792 0.654 1.271 1.134v0zM14 14.75c0 0.136-0.114 0.25-0.25 0.25h-9.5c-0.136 0-0.25-0.114-0.25-0.25v-11.5c0-0.135 0.114-0.25 0.25-0.25 0 0 5.749-0 5.75 0v3.5c0 0.276 0.224 0.5 0.5 0.5h3.5v7.75z" } }, { "tag": "path", "attr": { "d": "M9.421 0.659c-0.806-0.591-1.197-0.659-1.421-0.659h-5.75c-0.689 0-1.25 0.561-1.25 1.25v11.5c0 0.604 0.43 1.109 1 1.225v-12.725c0-0.135 0.115-0.25 0.25-0.25h7.607c-0.151-0.124-0.297-0.238-0.437-0.341z" } }] })(props);
1653
+ }
1654
+ function VscOpenPreview(props) {
1655
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 16 16", "fill": "currentColor" }, "child": [{ "tag": "path", "attr": { "fillRule": "evenodd", "clipRule": "evenodd", "d": "M3 1h11l1 1v5.3a3.21 3.21 0 0 0-1-.3V2H9v10.88L7.88 14H3l-1-1V2l1-1zm0 12h5V2H3v11zm10.379-4.998a2.53 2.53 0 0 0-1.19.348h-.03a2.51 2.51 0 0 0-.799 3.53L9 14.23l.71.71 2.35-2.36c.325.22.7.358 1.09.4a2.47 2.47 0 0 0 1.14-.13 2.51 2.51 0 0 0 1-.63 2.46 2.46 0 0 0 .58-1 2.63 2.63 0 0 0 .07-1.15 2.53 2.53 0 0 0-1.35-1.81 2.53 2.53 0 0 0-1.211-.258zm.24 3.992a1.5 1.5 0 0 1-.979-.244 1.55 1.55 0 0 1-.56-.68 1.49 1.49 0 0 1-.08-.86 1.49 1.49 0 0 1 1.18-1.18 1.49 1.49 0 0 1 .86.08c.276.117.512.311.68.56a1.5 1.5 0 0 1-1.1 2.324z" } }] })(props);
1656
+ }
1627
1657
  const useGetCollections = (cms) => {
1628
1658
  const [collections, setCollections] = useState([]);
1629
1659
  useEffect(() => {
@@ -1641,14 +1671,98 @@ const GetCollections = ({ cms, children }) => {
1641
1671
  return null;
1642
1672
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children(collections));
1643
1673
  };
1674
+ const Sidebar = ({ cms }) => {
1675
+ const { setEdit } = useEditState();
1676
+ const logout2 = () => setEdit(false);
1677
+ return /* @__PURE__ */ React.createElement(GetCollections, {
1678
+ cms
1679
+ }, (collections) => /* @__PURE__ */ React.createElement("div", {
1680
+ className: "flex flex-col w-80 lg:w-96 flex-shrink-0 bg-gradient-to-b from-white to-gray-50 border-r border-gray-200"
1681
+ }, /* @__PURE__ */ React.createElement("div", {
1682
+ className: "border-b border-gray-200"
1683
+ }, /* @__PURE__ */ React.createElement(Menu, {
1684
+ as: "div",
1685
+ className: "relative block"
1686
+ }, ({ open }) => /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Menu.Button, {
1687
+ className: `group w-full px-6 py-4 flex justify-between items-center transition-colors duration-150 ease-out ${open ? `bg-gray-50` : `bg-transparent`}`
1688
+ }, /* @__PURE__ */ React.createElement("span", {
1689
+ className: "text-left inline-flex items-center text-2xl tracking-wide text-gray-800 flex-1 gap-1 opacity-80 group-hover:opacity-100 transition-opacity duration-150 ease-out"
1690
+ }, /* @__PURE__ */ React.createElement("svg", {
1691
+ viewBox: "0 0 32 32",
1692
+ fill: "#EC4815",
1693
+ xmlns: "http://www.w3.org/2000/svg",
1694
+ className: "w-10 h-auto -ml-1"
1695
+ }, /* @__PURE__ */ React.createElement("path", {
1696
+ d: "M18.6466 14.5553C19.9018 13.5141 20.458 7.36086 21.0014 5.14903C21.5447 2.9372 23.7919 3.04938 23.7919 3.04938C23.7919 3.04938 23.2085 4.06764 23.4464 4.82751C23.6844 5.58738 25.3145 6.26662 25.3145 6.26662L24.9629 7.19622C24.9629 7.19622 24.2288 7.10204 23.7919 7.9785C23.355 8.85496 24.3392 17.4442 24.3392 17.4442C24.3392 17.4442 21.4469 22.7275 21.4469 24.9206C21.4469 27.1136 22.4819 28.9515 22.4819 28.9515H21.0296C21.0296 28.9515 18.899 26.4086 18.462 25.1378C18.0251 23.8669 18.1998 22.596 18.1998 22.596C18.1998 22.596 15.8839 22.4646 13.8303 22.596C11.7767 22.7275 10.4072 24.498 10.16 25.4884C9.91287 26.4787 9.81048 28.9515 9.81048 28.9515H8.66211C7.96315 26.7882 7.40803 26.0129 7.70918 24.9206C8.54334 21.8949 8.37949 20.1788 8.18635 19.4145C7.99321 18.6501 6.68552 17.983 6.68552 17.983C7.32609 16.6741 7.97996 16.0452 10.7926 15.9796C13.6052 15.914 17.3915 15.5965 18.6466 14.5553Z"
1697
+ }), /* @__PURE__ */ React.createElement("path", {
1698
+ d: "M11.1268 24.7939C11.1268 24.7939 11.4236 27.5481 13.0001 28.9516H14.3511C13.0001 27.4166 12.8527 23.4155 12.8527 23.4155C12.1656 23.6399 11.3045 24.3846 11.1268 24.7939Z"
1699
+ })), /* @__PURE__ */ React.createElement("span", null, "Tina Admin")), /* @__PURE__ */ React.createElement("svg", {
1700
+ width: "20",
1701
+ height: "20",
1702
+ viewBox: "0 0 20 20",
1703
+ fill: "none",
1704
+ xmlns: "http://www.w3.org/2000/svg",
1705
+ className: `flex-0 inline-block opacity-50 group-hover:opacity-80 transition-all duration-300 ease-in-out transform ${open ? `rotate-90 opacity-100` : `rotate-0`}`
1706
+ }, /* @__PURE__ */ React.createElement("g", {
1707
+ opacity: "0.3"
1708
+ }, /* @__PURE__ */ React.createElement("path", {
1709
+ d: "M7.91675 13.8086L9.16675 15.0586L14.2253 10L9.16675 4.9414L7.91675 6.1914L11.7253 10L7.91675 13.8086Z",
1710
+ fill: "currentColor"
1711
+ })))), /* @__PURE__ */ React.createElement("div", {
1712
+ className: "transform translate-y-full absolute bottom-3 right-5 w-2/3 z-50"
1713
+ }, /* @__PURE__ */ React.createElement(Transition, {
1714
+ enter: "transition duration-150 ease-out",
1715
+ enterFrom: "transform opacity-0 -translate-y-2",
1716
+ enterTo: "transform opacity-100 translate-y-0",
1717
+ leave: "transition duration-75 ease-in",
1718
+ leaveFrom: "transform opacity-100 translate-y-0",
1719
+ leaveTo: "transform opacity-0 -translate-y-2"
1720
+ }, /* @__PURE__ */ React.createElement(Menu.Items, {
1721
+ className: "w-full py-1 bg-white border border-gray-150 rounded-lg shadow-lg"
1722
+ }, /* @__PURE__ */ React.createElement(Menu.Item, null, ({ active }) => /* @__PURE__ */ React.createElement("a", {
1723
+ className: `w-full text-lg px-4 py-2 tracking-wide flex items-center opacity-80 text-gray-600 ${active && "text-gray-800 opacity-100"}`,
1724
+ href: "/"
1725
+ }, /* @__PURE__ */ React.createElement(VscOpenPreview, {
1726
+ className: "w-6 h-auto mr-1.5 text-blue-400"
1727
+ }), " ", "View Website")), /* @__PURE__ */ React.createElement(Menu.Item, null, ({ active }) => /* @__PURE__ */ React.createElement("button", {
1728
+ className: `w-full text-lg px-4 py-2 tracking-wide flex items-center opacity-80 text-gray-600 ${active && "text-gray-800 opacity-100"}`,
1729
+ onClick: () => logout2()
1730
+ }, /* @__PURE__ */ React.createElement(BiExit, {
1731
+ className: "w-6 h-auto mr-1.5 text-blue-400"
1732
+ }), " ", "Log out")))))))), /* @__PURE__ */ React.createElement("div", {
1733
+ className: "px-6 py-7 flex-1"
1734
+ }, /* @__PURE__ */ React.createElement("h4", {
1735
+ className: "uppercase font-bold text-sm mb-3"
1736
+ }, "Collections"), /* @__PURE__ */ React.createElement("ul", {
1737
+ className: "flex flex-col gap-4"
1738
+ }, collections.map((collection) => {
1739
+ return /* @__PURE__ */ React.createElement("li", {
1740
+ key: `${collection.name}-link`
1741
+ }, /* @__PURE__ */ React.createElement(NavLink, {
1742
+ className: ({ isActive }) => {
1743
+ return `text-lg tracking-wide ${isActive ? "text-blue-600" : ""} hover:text-blue-600 flex items-center opacity-90 hover:opacity-100`;
1744
+ },
1745
+ to: `/admin/collections/${collection.name}`
1746
+ }, /* @__PURE__ */ React.createElement(ImFilesEmpty, {
1747
+ className: "mr-2 h-6 opacity-80 w-auto"
1748
+ }), " ", collection.label));
1749
+ })))));
1750
+ };
1751
+ const GetCMS = ({ children }) => {
1752
+ try {
1753
+ const cms = useCMS();
1754
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children(cms));
1755
+ } catch (e) {
1756
+ return null;
1757
+ }
1758
+ };
1644
1759
  function MdOutlineArrowBack(props) {
1645
1760
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "fill": "none", "d": "M0 0h24v24H0V0z" } }, { "tag": "path", "attr": { "d": "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" } }] })(props);
1646
1761
  }
1647
- const login = () => {
1648
- setEditing(true);
1649
- window.location.reload();
1650
- };
1651
- const LoginPage = () => {
1762
+ const AuthTemplate = ({
1763
+ message,
1764
+ children
1765
+ }) => {
1652
1766
  return /* @__PURE__ */ React.createElement("div", {
1653
1767
  className: "h-screen w-full bg-gradient-to-b from-blue-900 to-gray-900 flex items-center justify-center px-4 py-6"
1654
1768
  }, /* @__PURE__ */ React.createElement("div", {
@@ -1666,12 +1780,19 @@ const LoginPage = () => {
1666
1780
  d: "M18.6466 14.5553C19.9018 13.5141 20.458 7.36086 21.0014 5.14903C21.5447 2.9372 23.7919 3.04938 23.7919 3.04938C23.7919 3.04938 23.2085 4.06764 23.4464 4.82751C23.6844 5.58738 25.3145 6.26662 25.3145 6.26662L24.9629 7.19622C24.9629 7.19622 24.2288 7.10204 23.7919 7.9785C23.355 8.85496 24.3392 17.4442 24.3392 17.4442C24.3392 17.4442 21.4469 22.7275 21.4469 24.9206C21.4469 27.1136 22.4819 28.9515 22.4819 28.9515H21.0296C21.0296 28.9515 18.899 26.4086 18.462 25.1378C18.0251 23.8669 18.1998 22.596 18.1998 22.596C18.1998 22.596 15.8839 22.4646 13.8303 22.596C11.7767 22.7275 10.4072 24.498 10.16 25.4884C9.91287 26.4787 9.81048 28.9515 9.81048 28.9515H8.66211C7.96315 26.7882 7.40803 26.0129 7.70918 24.9206C8.54334 21.8949 8.37949 20.1788 8.18635 19.4145C7.99321 18.6501 6.68552 17.983 6.68552 17.983C7.32609 16.6741 7.97996 16.0452 10.7926 15.9796C13.6052 15.914 17.3915 15.5965 18.6466 14.5553Z"
1667
1781
  }), /* @__PURE__ */ React.createElement("path", {
1668
1782
  d: "M11.1268 24.7939C11.1268 24.7939 11.4236 27.5481 13.0001 28.9516H14.3511C13.0001 27.4166 12.8527 23.4155 12.8527 23.4155C12.1656 23.6399 11.3045 24.3846 11.1268 24.7939Z"
1669
- })), /* @__PURE__ */ React.createElement("span", null, "Tina Admin"))), /* @__PURE__ */ React.createElement("div", {
1783
+ })), /* @__PURE__ */ React.createElement("span", null, "Tina Admin"))), message && /* @__PURE__ */ React.createElement("div", {
1670
1784
  className: "px-5 py-4 "
1671
1785
  }, /* @__PURE__ */ React.createElement("p", {
1672
1786
  className: "text-base font-sans leading-normal"
1673
- }, "Please log in to Tina Cloud to access your admin dashboard.")), /* @__PURE__ */ React.createElement("div", {
1787
+ }, message)), /* @__PURE__ */ React.createElement("div", {
1674
1788
  className: "px-5 py-4 flex gap-4 w-full justify-between"
1789
+ }, children)));
1790
+ };
1791
+ const LoginPage = () => {
1792
+ const { setEdit } = useEditState();
1793
+ const login = () => setEdit(true);
1794
+ return /* @__PURE__ */ React.createElement(AuthTemplate, {
1795
+ message: "Please log in to Tina Cloud to access your content."
1675
1796
  }, /* @__PURE__ */ React.createElement("a", {
1676
1797
  href: "/",
1677
1798
  className: "flex-1 text-center inline-flex justify-center items-center px-8 py-3 shadow-sm text-sm leading-4 font-medium rounded-full text-gray-600 border border-gray-150 hover:opacity-80 hover:bg-gray-50 focus:outline-none focus:shadow-outline-blue transition duration-150 ease-out"
@@ -1684,7 +1805,26 @@ const LoginPage = () => {
1684
1805
  style: { background: "#0084FF" }
1685
1806
  }, /* @__PURE__ */ React.createElement(BiLogIn, {
1686
1807
  className: "w-6 h-auto mr-1.5 opacity-80"
1687
- }), " Log in"))));
1808
+ }), " Log in"));
1809
+ };
1810
+ const logout = () => {
1811
+ setEditing(false);
1812
+ window.location.href = "/";
1813
+ };
1814
+ const LogoutPage = () => {
1815
+ return /* @__PURE__ */ React.createElement(AuthTemplate, null, /* @__PURE__ */ React.createElement("a", {
1816
+ href: "/",
1817
+ className: "flex-1 text-center inline-flex justify-center items-center px-8 py-3 shadow-sm text-sm leading-4 font-medium rounded-full text-gray-600 border border-gray-150 hover:opacity-80 hover:bg-gray-50 focus:outline-none focus:shadow-outline-blue transition duration-150 ease-out"
1818
+ }, /* @__PURE__ */ React.createElement(MdOutlineArrowBack, {
1819
+ className: "w-6 h-auto mr-1.5 opacity-80"
1820
+ }), " Back to site"), /* @__PURE__ */ React.createElement("button", {
1821
+ type: "submit",
1822
+ onClick: () => logout(),
1823
+ className: "flex-1 justify-center text-center inline-flex items-center px-8 py-3 shadow-sm border border-transparent text-sm leading-4 font-medium rounded-full text-white hover:opacity-80 focus:outline-none focus:shadow-outline-blue transition duration-150 ease-out",
1824
+ style: { background: "#0084FF" }
1825
+ }, /* @__PURE__ */ React.createElement(BiLogOut, {
1826
+ className: "w-6 h-auto mr-1.5 opacity-80"
1827
+ }), " Log out"));
1688
1828
  };
1689
1829
  const DashboardPage = () => {
1690
1830
  return /* @__PURE__ */ React.createElement("div", {
@@ -1930,7 +2070,7 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
1930
2070
  };
1931
2071
  const CollectionCreatePage = () => {
1932
2072
  const { collectionName, templateName } = useParams();
1933
- const history = useHistory();
2073
+ const navigate = useNavigate();
1934
2074
  return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetDocumentFields, {
1935
2075
  cms,
1936
2076
  collectionName,
@@ -1951,7 +2091,7 @@ const CollectionCreatePage = () => {
1951
2091
  ],
1952
2092
  onSubmit: async (values) => {
1953
2093
  await createDocument(cms, collection, template, mutationInfo, values);
1954
- history.push(`/admin/collections/${collection.name}`);
2094
+ navigate(`/admin/collections/${collection.name}`);
1955
2095
  }
1956
2096
  });
1957
2097
  const formLabel = template ? `${collection.label} - Create New ${template.label}` : `${collection.label} - Create New`;
@@ -2018,7 +2158,7 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
2018
2158
  };
2019
2159
  const CollectionUpdatePage = () => {
2020
2160
  const { collectionName, filename } = useParams();
2021
- const history = useHistory();
2161
+ const navigate = useNavigate();
2022
2162
  return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetDocumentFields, {
2023
2163
  cms,
2024
2164
  collectionName
@@ -2036,7 +2176,7 @@ const CollectionUpdatePage = () => {
2036
2176
  initialValues: document2.values,
2037
2177
  onSubmit: async (values) => {
2038
2178
  await updateDocument(cms, relativePath, collection, mutationInfo, values);
2039
- history.push(`/admin/collections/${collection.name}`);
2179
+ navigate(`/collections/${collection.name}`);
2040
2180
  }
2041
2181
  });
2042
2182
  return /* @__PURE__ */ React.createElement("div", {
@@ -2052,8 +2192,8 @@ const CollectionUpdatePage = () => {
2052
2192
  };
2053
2193
  const useEmbedTailwind = () => {
2054
2194
  useEffect(() => {
2055
- const isSSR2 = typeof window === "undefined";
2056
- if (!isSSR2) {
2195
+ const isSSR = typeof window === "undefined";
2196
+ if (!isSSR) {
2057
2197
  const head = document.head;
2058
2198
  const link = document.createElement("link");
2059
2199
  link.id = "tina-admin-stylesheet";
@@ -2064,106 +2204,59 @@ const useEmbedTailwind = () => {
2064
2204
  }
2065
2205
  }, []);
2066
2206
  };
2067
- const logout = () => {
2068
- setEditing(false);
2069
- window.location.reload();
2207
+ const Redirect = () => {
2208
+ React.useEffect(() => {
2209
+ if (window) {
2210
+ window.location.assign("/");
2211
+ }
2212
+ }, []);
2213
+ return null;
2070
2214
  };
2071
2215
  const TinaAdmin = () => {
2072
2216
  useEmbedTailwind();
2073
- const isSSR2 = typeof window === "undefined";
2074
- if (isSSR2) {
2217
+ const isSSR = typeof window === "undefined";
2218
+ const { edit } = useEditState();
2219
+ if (isSSR) {
2075
2220
  return null;
2076
2221
  }
2077
- const isEdit = isEditing();
2078
- if (!isEdit) {
2222
+ if (!edit) {
2079
2223
  return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(LoginPage, null));
2080
2224
  }
2081
- return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollections, {
2082
- cms
2083
- }, (collections) => /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(BrowserRouter, null, /* @__PURE__ */ React.createElement("div", {
2084
- className: "flex items-stretch h-screen overflow-hidden"
2085
- }, /* @__PURE__ */ React.createElement("div", {
2086
- className: "flex flex-col w-80 lg:w-96 flex-shrink-0 bg-gradient-to-b from-white to-gray-50 border-r border-gray-200"
2087
- }, /* @__PURE__ */ React.createElement("div", {
2088
- className: "border-b border-gray-200"
2089
- }, /* @__PURE__ */ React.createElement(Menu, {
2090
- as: "div",
2091
- className: "relative block"
2092
- }, ({ open }) => /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Menu.Button, {
2093
- className: `group w-full px-6 py-4 flex justify-between items-center transition-colors duration-150 ease-out ${open ? `bg-gray-50` : `bg-transparent`}`
2094
- }, /* @__PURE__ */ React.createElement("span", {
2095
- className: "text-left inline-flex items-center text-2xl tracking-wide text-gray-800 flex-1 gap-1 opacity-80 group-hover:opacity-100 transition-opacity duration-150 ease-out"
2096
- }, /* @__PURE__ */ React.createElement("svg", {
2097
- viewBox: "0 0 32 32",
2098
- fill: "#EC4815",
2099
- xmlns: "http://www.w3.org/2000/svg",
2100
- className: "w-10 h-auto -ml-1"
2101
- }, /* @__PURE__ */ React.createElement("path", {
2102
- d: "M18.6466 14.5553C19.9018 13.5141 20.458 7.36086 21.0014 5.14903C21.5447 2.9372 23.7919 3.04938 23.7919 3.04938C23.7919 3.04938 23.2085 4.06764 23.4464 4.82751C23.6844 5.58738 25.3145 6.26662 25.3145 6.26662L24.9629 7.19622C24.9629 7.19622 24.2288 7.10204 23.7919 7.9785C23.355 8.85496 24.3392 17.4442 24.3392 17.4442C24.3392 17.4442 21.4469 22.7275 21.4469 24.9206C21.4469 27.1136 22.4819 28.9515 22.4819 28.9515H21.0296C21.0296 28.9515 18.899 26.4086 18.462 25.1378C18.0251 23.8669 18.1998 22.596 18.1998 22.596C18.1998 22.596 15.8839 22.4646 13.8303 22.596C11.7767 22.7275 10.4072 24.498 10.16 25.4884C9.91287 26.4787 9.81048 28.9515 9.81048 28.9515H8.66211C7.96315 26.7882 7.40803 26.0129 7.70918 24.9206C8.54334 21.8949 8.37949 20.1788 8.18635 19.4145C7.99321 18.6501 6.68552 17.983 6.68552 17.983C7.32609 16.6741 7.97996 16.0452 10.7926 15.9796C13.6052 15.914 17.3915 15.5965 18.6466 14.5553Z"
2103
- }), /* @__PURE__ */ React.createElement("path", {
2104
- d: "M11.1268 24.7939C11.1268 24.7939 11.4236 27.5481 13.0001 28.9516H14.3511C13.0001 27.4166 12.8527 23.4155 12.8527 23.4155C12.1656 23.6399 11.3045 24.3846 11.1268 24.7939Z"
2105
- })), /* @__PURE__ */ React.createElement("span", null, "Tina Admin")), /* @__PURE__ */ React.createElement("svg", {
2106
- width: "20",
2107
- height: "20",
2108
- viewBox: "0 0 20 20",
2109
- fill: "none",
2110
- xmlns: "http://www.w3.org/2000/svg",
2111
- className: `flex-0 inline-block opacity-50 group-hover:opacity-80 transition-all duration-300 ease-in-out transform ${open ? `rotate-90 opacity-100` : `rotate-0`}`
2112
- }, /* @__PURE__ */ React.createElement("g", {
2113
- opacity: "0.3"
2114
- }, /* @__PURE__ */ React.createElement("path", {
2115
- d: "M7.91675 13.8086L9.16675 15.0586L14.2253 10L9.16675 4.9414L7.91675 6.1914L11.7253 10L7.91675 13.8086Z",
2116
- fill: "currentColor"
2117
- })))), /* @__PURE__ */ React.createElement("div", {
2118
- className: "transform translate-y-full absolute bottom-3 right-5 w-2/3 z-50"
2119
- }, /* @__PURE__ */ React.createElement(Transition, {
2120
- enter: "transition duration-150 ease-out",
2121
- enterFrom: "transform opacity-0 -translate-y-2",
2122
- enterTo: "transform opacity-100 translate-y-0",
2123
- leave: "transition duration-75 ease-in",
2124
- leaveFrom: "transform opacity-100 translate-y-0",
2125
- leaveTo: "transform opacity-0 -translate-y-2"
2126
- }, /* @__PURE__ */ React.createElement(Menu.Items, {
2127
- className: "w-full py-1 bg-white border border-gray-150 rounded-lg shadow-lg"
2128
- }, /* @__PURE__ */ React.createElement(Menu.Item, null, ({ active }) => /* @__PURE__ */ React.createElement("a", {
2129
- className: `w-full text-lg px-4 py-2 tracking-wide flex items-center opacity-80 text-gray-600 ${active && "text-gray-800 opacity-100"}`,
2130
- href: "/"
2131
- }, /* @__PURE__ */ React.createElement(VscOpenPreview, {
2132
- className: "w-6 h-auto mr-1.5 text-blue-400"
2133
- }), " ", "View Website")), /* @__PURE__ */ React.createElement(Menu.Item, null, ({ active }) => /* @__PURE__ */ React.createElement("button", {
2134
- className: `w-full text-lg px-4 py-2 tracking-wide flex items-center opacity-80 text-gray-600 ${active && "text-gray-800 opacity-100"}`,
2135
- onClick: () => logout()
2136
- }, /* @__PURE__ */ React.createElement(BiExit, {
2137
- className: "w-6 h-auto mr-1.5 text-blue-400"
2138
- }), " ", "Log out")))))))), /* @__PURE__ */ React.createElement("div", {
2139
- className: "px-6 py-7 flex-1"
2140
- }, /* @__PURE__ */ React.createElement("h4", {
2141
- className: "uppercase font-bold text-sm mb-3"
2142
- }, "Collections"), /* @__PURE__ */ React.createElement("ul", {
2143
- className: "flex flex-col gap-4"
2144
- }, collections.map((collection) => {
2145
- return /* @__PURE__ */ React.createElement("li", {
2146
- key: `${collection.name}-link`
2147
- }, /* @__PURE__ */ React.createElement(NavLink, {
2148
- className: `text-lg tracking-wide hover:text-blue-600 flex items-center opacity-90 hover:opacity-100`,
2149
- activeClassName: "text-blue-600",
2150
- to: `/admin/collections/${collection.name}`
2151
- }, /* @__PURE__ */ React.createElement(ImFilesEmpty, {
2152
- className: "mr-2 h-6 opacity-80 w-auto"
2153
- }), " ", collection.label));
2154
- })))), /* @__PURE__ */ React.createElement("div", {
2155
- className: "flex-1"
2156
- }, /* @__PURE__ */ React.createElement(Switch, null, /* @__PURE__ */ React.createElement(Route, {
2157
- path: `/admin/collections/:collectionName/new`
2158
- }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null)), /* @__PURE__ */ React.createElement(Route, {
2159
- path: `/admin/collections/:collectionName/:templateName/new`
2160
- }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null)), /* @__PURE__ */ React.createElement(Route, {
2161
- path: `/admin/collections/:collectionName/:filename`
2162
- }, /* @__PURE__ */ React.createElement(CollectionUpdatePage, null)), /* @__PURE__ */ React.createElement(Route, {
2163
- path: `/admin/collections/:collectionName`
2164
- }, /* @__PURE__ */ React.createElement(CollectionListPage, null)), /* @__PURE__ */ React.createElement(Route, {
2165
- path: `/admin`
2166
- }, /* @__PURE__ */ React.createElement(DashboardPage, null)))))))));
2225
+ return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => {
2226
+ const isTinaAdminEnabled = cms.flags.get("tina-admin");
2227
+ if (isTinaAdminEnabled) {
2228
+ return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(BrowserRouter, null, /* @__PURE__ */ React.createElement("div", {
2229
+ className: "flex items-stretch h-screen overflow-hidden"
2230
+ }, /* @__PURE__ */ React.createElement(Sidebar, {
2231
+ cms
2232
+ }), /* @__PURE__ */ React.createElement("div", {
2233
+ className: "flex-1"
2234
+ }, /* @__PURE__ */ React.createElement(Routes, null, /* @__PURE__ */ React.createElement(Route, {
2235
+ path: "/admin/collections/:collectionName/new",
2236
+ element: /* @__PURE__ */ React.createElement(CollectionCreatePage, null)
2237
+ }), /* @__PURE__ */ React.createElement(Route, {
2238
+ path: "/admin/collections/:collectionName/:templateName/new",
2239
+ element: /* @__PURE__ */ React.createElement(CollectionCreatePage, null)
2240
+ }), /* @__PURE__ */ React.createElement(Route, {
2241
+ path: "/admin/collections/:collectionName/:filename",
2242
+ element: /* @__PURE__ */ React.createElement(CollectionUpdatePage, null)
2243
+ }), /* @__PURE__ */ React.createElement(Route, {
2244
+ path: "/admin/collections/:collectionName",
2245
+ element: /* @__PURE__ */ React.createElement(CollectionListPage, null)
2246
+ }), /* @__PURE__ */ React.createElement(Route, {
2247
+ path: "/admin",
2248
+ element: /* @__PURE__ */ React.createElement(DashboardPage, null)
2249
+ }))))));
2250
+ } else {
2251
+ return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(BrowserRouter, null, /* @__PURE__ */ React.createElement(Routes, null, /* @__PURE__ */ React.createElement(Route, {
2252
+ path: "/admin/logout",
2253
+ element: /* @__PURE__ */ React.createElement(LogoutPage, null)
2254
+ }), /* @__PURE__ */ React.createElement(Route, {
2255
+ path: "/admin",
2256
+ element: /* @__PURE__ */ React.createElement(Redirect, null)
2257
+ }))));
2258
+ }
2259
+ });
2167
2260
  };
2168
2261
  class RouteMappingPlugin {
2169
2262
  constructor(mapper) {