tinacms 0.58.1 → 0.60.1
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/CHANGELOG.md +43 -0
- package/dist/admin/components/AuthTemplate.d.ts +17 -0
- package/dist/admin/components/Sidebar.d.ts +17 -0
- package/dist/admin/pages/LogoutPage.d.ts +14 -0
- package/dist/client/index.d.ts +7 -4
- package/dist/edit-state.d.ts +2 -11
- package/dist/edit-state.es.js +14 -38
- package/dist/edit-state.js +29 -42
- package/dist/index.es.js +306 -209
- package/dist/index.js +305 -209
- package/package.json +4 -18
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
(function(global, factory) {
|
|
33
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("graphql"), require("lodash.set"), require("graphql-tag"), require("
|
|
34
|
-
})(this, function(exports2, graphql, set, gql$1,
|
|
33
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@tinacms/toolkit"), require("graphql"), require("lodash.set"), require("graphql-tag"), require("react"), require("styled-components"), require("yup"), require("@tinacms/sharedctx"), require("final-form"), require("react-router-dom"), require("@headlessui/react")) : typeof define === "function" && define.amd ? define(["exports", "@tinacms/toolkit", "graphql", "lodash.set", "graphql-tag", "react", "styled-components", "yup", "@tinacms/sharedctx", "final-form", "react-router-dom", "@headlessui/react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP));
|
|
34
|
+
})(this, function(exports2, toolkit, graphql, set, gql$1, React, styled, yup, sharedctx, finalForm, reactRouterDom, react) {
|
|
35
35
|
"use strict";
|
|
36
36
|
function _interopDefaultLegacy(e) {
|
|
37
37
|
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
@@ -397,6 +397,7 @@ var __objRest = (source, exclude) => {
|
|
|
397
397
|
class Client {
|
|
398
398
|
constructor(_a) {
|
|
399
399
|
var _b = _a, { tokenStorage = "MEMORY" } = _b, options = __objRest(_b, ["tokenStorage"]);
|
|
400
|
+
this.events = new toolkit.EventBus();
|
|
400
401
|
this.addPendingContent = async (props) => {
|
|
401
402
|
const mutation = `#graphql
|
|
402
403
|
mutation addPendingDocumentMutation(
|
|
@@ -437,17 +438,16 @@ mutation addPendingDocumentMutation(
|
|
|
437
438
|
};
|
|
438
439
|
this.options = options;
|
|
439
440
|
this.setBranch(options.branch);
|
|
440
|
-
this.events
|
|
441
|
-
this.events.subscribe("branch-switcher:change-branch", ({ branchName }) => {
|
|
441
|
+
this.events.subscribe("branch:change", ({ branchName }) => {
|
|
442
442
|
this.setBranch(branchName);
|
|
443
443
|
});
|
|
444
444
|
this.clientId = options.clientId;
|
|
445
445
|
switch (tokenStorage) {
|
|
446
446
|
case "LOCAL_STORAGE":
|
|
447
|
-
this.getToken = function() {
|
|
447
|
+
this.getToken = async function() {
|
|
448
448
|
const tokens = localStorage.getItem(AUTH_TOKEN_KEY) || null;
|
|
449
449
|
if (tokens) {
|
|
450
|
-
return
|
|
450
|
+
return await this.getRefreshedToken(tokens);
|
|
451
451
|
} else {
|
|
452
452
|
return {
|
|
453
453
|
access_token: null,
|
|
@@ -461,9 +461,9 @@ mutation addPendingDocumentMutation(
|
|
|
461
461
|
};
|
|
462
462
|
break;
|
|
463
463
|
case "MEMORY":
|
|
464
|
-
this.getToken = () => {
|
|
464
|
+
this.getToken = async () => {
|
|
465
465
|
if (this.token) {
|
|
466
|
-
return
|
|
466
|
+
return await this.getRefreshedToken(this.token);
|
|
467
467
|
} else {
|
|
468
468
|
return {
|
|
469
469
|
access_token: null,
|
|
@@ -489,8 +489,8 @@ mutation addPendingDocumentMutation(
|
|
|
489
489
|
const encodedBranch = encodeURIComponent(branchName);
|
|
490
490
|
this.frontendUrl = ((_a = this.options.tinaioConfig) == null ? void 0 : _a.frontendUrlOverride) || "https://app.tina.io";
|
|
491
491
|
this.identityApiUrl = ((_b = this.options.tinaioConfig) == null ? void 0 : _b.identityApiUrlOverride) || "https://identity.tinajs.io";
|
|
492
|
-
|
|
493
|
-
this.contentApiUrl = this.options.customContentApiUrl || `${contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
492
|
+
this.contentApiBase = ((_c = this.options.tinaioConfig) == null ? void 0 : _c.contentApiUrlOverride) || `https://content.tinajs.io`;
|
|
493
|
+
this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
494
494
|
}
|
|
495
495
|
async requestWithForm(query, { variables }) {
|
|
496
496
|
const schema = await this.getSchema();
|
|
@@ -502,13 +502,16 @@ mutation addPendingDocumentMutation(
|
|
|
502
502
|
method: "POST",
|
|
503
503
|
headers: {
|
|
504
504
|
"Content-Type": "application/json",
|
|
505
|
-
Authorization: "Bearer " + this.getToken().id_token
|
|
505
|
+
Authorization: "Bearer " + (await this.getToken()).id_token
|
|
506
506
|
},
|
|
507
507
|
body: JSON.stringify({
|
|
508
508
|
query: typeof query === "function" ? graphql.print(query(gql__default["default"])) : query,
|
|
509
509
|
variables
|
|
510
510
|
})
|
|
511
511
|
});
|
|
512
|
+
if (res.status !== 200) {
|
|
513
|
+
throw new Error(`Unable to complete request, ${res.statusText}`);
|
|
514
|
+
}
|
|
512
515
|
const json = await res.json();
|
|
513
516
|
if (json.errors) {
|
|
514
517
|
throw new Error(`Unable to fetch, errors:
|
|
@@ -516,6 +519,47 @@ mutation addPendingDocumentMutation(
|
|
|
516
519
|
}
|
|
517
520
|
return json.data;
|
|
518
521
|
}
|
|
522
|
+
parseJwt(token) {
|
|
523
|
+
const base64Url = token.split(".")[1];
|
|
524
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
525
|
+
const jsonPayload = decodeURIComponent(atob(base64).split("").map(function(c) {
|
|
526
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
527
|
+
}).join(""));
|
|
528
|
+
return JSON.parse(jsonPayload);
|
|
529
|
+
}
|
|
530
|
+
async getRefreshedToken(tokens) {
|
|
531
|
+
const { access_token, id_token, refresh_token } = JSON.parse(tokens);
|
|
532
|
+
const { exp, iss, client_id } = this.parseJwt(access_token);
|
|
533
|
+
if (Date.now() / 1e3 >= exp) {
|
|
534
|
+
const refreshResponse = await fetch(iss, {
|
|
535
|
+
method: "POST",
|
|
536
|
+
headers: {
|
|
537
|
+
"Content-Type": "application/x-amz-json-1.1",
|
|
538
|
+
"x-amz-target": "AWSCognitoIdentityProviderService.InitiateAuth"
|
|
539
|
+
},
|
|
540
|
+
body: JSON.stringify({
|
|
541
|
+
ClientId: client_id,
|
|
542
|
+
AuthFlow: "REFRESH_TOKEN_AUTH",
|
|
543
|
+
AuthParameters: {
|
|
544
|
+
REFRESH_TOKEN: refresh_token,
|
|
545
|
+
DEVICE_KEY: null
|
|
546
|
+
}
|
|
547
|
+
})
|
|
548
|
+
});
|
|
549
|
+
if (refreshResponse.status !== 200) {
|
|
550
|
+
throw new Error("Unable to refresh auth tokens");
|
|
551
|
+
}
|
|
552
|
+
const responseJson = await refreshResponse.json();
|
|
553
|
+
const newToken = {
|
|
554
|
+
access_token: responseJson.AuthenticationResult.AccessToken,
|
|
555
|
+
id_token: responseJson.AuthenticationResult.IdToken,
|
|
556
|
+
refresh_token
|
|
557
|
+
};
|
|
558
|
+
this.setToken(newToken);
|
|
559
|
+
return Promise.resolve(newToken);
|
|
560
|
+
}
|
|
561
|
+
return Promise.resolve({ access_token, id_token, refresh_token });
|
|
562
|
+
}
|
|
519
563
|
async isAuthorized() {
|
|
520
564
|
return this.isAuthenticated();
|
|
521
565
|
}
|
|
@@ -531,7 +575,7 @@ mutation addPendingDocumentMutation(
|
|
|
531
575
|
const headers = (init == null ? void 0 : init.headers) || {};
|
|
532
576
|
return await fetch(input, __spreadProps(__spreadValues({}, init), {
|
|
533
577
|
headers: new Headers(__spreadValues({
|
|
534
|
-
Authorization: "Bearer " + this.getToken().id_token
|
|
578
|
+
Authorization: "Bearer " + (await this.getToken()).id_token
|
|
535
579
|
}, headers))
|
|
536
580
|
}));
|
|
537
581
|
}
|
|
@@ -555,28 +599,24 @@ mutation addPendingDocumentMutation(
|
|
|
555
599
|
return null;
|
|
556
600
|
}
|
|
557
601
|
}
|
|
558
|
-
async listBranches(
|
|
559
|
-
const url = `${this.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return JSON.stringify(res);
|
|
565
|
-
} catch (e) {
|
|
566
|
-
console.error("There was an issue fetching the branch list.", e);
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
602
|
+
async listBranches() {
|
|
603
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/list_branches`;
|
|
604
|
+
const res = await this.fetchWithToken(url, {
|
|
605
|
+
method: "GET"
|
|
606
|
+
});
|
|
607
|
+
return res.json();
|
|
569
608
|
}
|
|
570
|
-
async createBranch({
|
|
571
|
-
const url = `${this.
|
|
609
|
+
async createBranch({ baseBranch, branchName }) {
|
|
610
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/create_branch`;
|
|
572
611
|
try {
|
|
573
612
|
const res = await this.fetchWithToken(url, {
|
|
574
613
|
method: "POST",
|
|
575
614
|
body: {
|
|
576
|
-
owner,
|
|
577
|
-
repo,
|
|
578
615
|
baseBranch,
|
|
579
616
|
branchName
|
|
617
|
+
},
|
|
618
|
+
headers: {
|
|
619
|
+
"Content-Type": "application/json"
|
|
580
620
|
}
|
|
581
621
|
});
|
|
582
622
|
return JSON.stringify(res);
|
|
@@ -677,24 +717,6 @@ mutation addPendingDocumentMutation(
|
|
|
677
717
|
return false;
|
|
678
718
|
}
|
|
679
719
|
}
|
|
680
|
-
const LOCALSTORAGEKEY = "tina.isEditing";
|
|
681
|
-
const isSSR = typeof window === "undefined";
|
|
682
|
-
const isEditing = () => {
|
|
683
|
-
if (!isSSR) {
|
|
684
|
-
const isEdit = window.localStorage.getItem(LOCALSTORAGEKEY);
|
|
685
|
-
return isEdit && isEdit === "true";
|
|
686
|
-
}
|
|
687
|
-
return false;
|
|
688
|
-
};
|
|
689
|
-
const setEditing = (isEditing2) => {
|
|
690
|
-
if (!isSSR) {
|
|
691
|
-
window.localStorage.setItem(LOCALSTORAGEKEY, isEditing2 ? "true" : "false");
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
React__default["default"].createContext({
|
|
695
|
-
edit: isEditing(),
|
|
696
|
-
setEdit: void 0
|
|
697
|
-
});
|
|
698
720
|
function sleep(ms) {
|
|
699
721
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
700
722
|
}
|
|
@@ -740,7 +762,7 @@ mutation addPendingDocumentMutation(
|
|
|
740
762
|
...otherModalActions,
|
|
741
763
|
{
|
|
742
764
|
action: async () => {
|
|
743
|
-
setEditing(false);
|
|
765
|
+
sharedctx.setEditing(false);
|
|
744
766
|
window.location.reload();
|
|
745
767
|
},
|
|
746
768
|
name: "Close",
|
|
@@ -758,13 +780,15 @@ mutation addPendingDocumentMutation(
|
|
|
758
780
|
}), showChildren ? children : loginScreen ? loginScreen : null);
|
|
759
781
|
};
|
|
760
782
|
const TinaCloudProvider = (props) => {
|
|
783
|
+
const baseBranch = props.branch || "main";
|
|
784
|
+
const [currentBranch, setCurrentBranch] = toolkit.useLocalStorage("tinacms-current-branch", baseBranch);
|
|
761
785
|
useTinaAuthRedirect();
|
|
762
786
|
const cms = React__default["default"].useMemo(() => props.cms || new toolkit.TinaCMS({
|
|
763
787
|
enabled: true,
|
|
764
788
|
sidebar: true
|
|
765
789
|
}), [props.cms]);
|
|
766
790
|
if (!cms.api.tina) {
|
|
767
|
-
cms.
|
|
791
|
+
cms.registerApi("tina", createClient(props));
|
|
768
792
|
}
|
|
769
793
|
const setupMedia = async () => {
|
|
770
794
|
var _a;
|
|
@@ -780,45 +804,54 @@ mutation addPendingDocumentMutation(
|
|
|
780
804
|
const handleListBranches = async () => {
|
|
781
805
|
const { owner, repo } = props;
|
|
782
806
|
const branches = await cms.api.tina.listBranches({ owner, repo });
|
|
783
|
-
|
|
807
|
+
if (!Array.isArray(branches)) {
|
|
808
|
+
return [];
|
|
809
|
+
}
|
|
810
|
+
return branches;
|
|
784
811
|
};
|
|
785
812
|
const handleCreateBranch = async (data) => {
|
|
786
813
|
const newBranch = await cms.api.tina.createBranch(data);
|
|
787
814
|
return newBranch;
|
|
788
815
|
};
|
|
789
816
|
setupMedia();
|
|
790
|
-
const branchingEnabled = cms.flags.get("branch-switcher");
|
|
817
|
+
const [branchingEnabled, setBranchingEnabled] = React__default["default"].useState(() => cms.flags.get("branch-switcher"));
|
|
818
|
+
React__default["default"].useEffect(() => {
|
|
819
|
+
cms.events.subscribe("flag:set", ({ key, value }) => {
|
|
820
|
+
if (key === "branch-switcher") {
|
|
821
|
+
setBranchingEnabled(value);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}, [cms.events]);
|
|
791
825
|
React__default["default"].useEffect(() => {
|
|
792
826
|
let branchSwitcher;
|
|
793
827
|
if (branchingEnabled) {
|
|
794
828
|
branchSwitcher = new toolkit.BranchSwitcherPlugin({
|
|
795
|
-
cms,
|
|
796
|
-
owner: props.owner,
|
|
797
|
-
repo: props.repo,
|
|
798
|
-
baseBranch: props.branch || "main",
|
|
799
|
-
currentBranch: props.branch || "main",
|
|
800
829
|
listBranches: handleListBranches,
|
|
801
|
-
createBranch: handleCreateBranch
|
|
802
|
-
setCurrentBranch: () => console.log(props.branch)
|
|
830
|
+
createBranch: handleCreateBranch
|
|
803
831
|
});
|
|
804
832
|
cms.plugins.add(branchSwitcher);
|
|
805
833
|
}
|
|
806
834
|
return () => {
|
|
807
|
-
if (
|
|
808
|
-
|
|
809
|
-
cms.plugins.remove(branchSwitcher);
|
|
810
|
-
}
|
|
835
|
+
if (branchingEnabled && branchSwitcher) {
|
|
836
|
+
cms.plugins.remove(branchSwitcher);
|
|
811
837
|
}
|
|
812
838
|
};
|
|
813
839
|
}, [branchingEnabled, props.branch]);
|
|
814
|
-
|
|
815
|
-
props.cmsCallback
|
|
816
|
-
|
|
817
|
-
|
|
840
|
+
React__default["default"].useEffect(() => {
|
|
841
|
+
if (props.cmsCallback) {
|
|
842
|
+
props.cmsCallback(cms);
|
|
843
|
+
}
|
|
844
|
+
}, []);
|
|
845
|
+
return /* @__PURE__ */ React__default["default"].createElement(toolkit.BranchDataProvider, {
|
|
846
|
+
currentBranch,
|
|
847
|
+
setCurrentBranch: (b) => {
|
|
848
|
+
setCurrentBranch(b);
|
|
849
|
+
}
|
|
850
|
+
}, /* @__PURE__ */ React__default["default"].createElement(toolkit.TinaProvider, {
|
|
818
851
|
cms
|
|
819
852
|
}, /* @__PURE__ */ React__default["default"].createElement(AuthWallInner, __spreadProps(__spreadValues({}, props), {
|
|
820
853
|
cms
|
|
821
|
-
})));
|
|
854
|
+
}))));
|
|
822
855
|
};
|
|
823
856
|
const TinaCloudAuthWall = TinaCloudProvider;
|
|
824
857
|
var DefaultContext = {
|
|
@@ -906,6 +939,9 @@ mutation addPendingDocumentMutation(
|
|
|
906
939
|
function BiLogIn(props) {
|
|
907
940
|
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);
|
|
908
941
|
}
|
|
942
|
+
function BiLogOut(props) {
|
|
943
|
+
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);
|
|
944
|
+
}
|
|
909
945
|
function useGraphqlForms({
|
|
910
946
|
query,
|
|
911
947
|
variables,
|
|
@@ -919,6 +955,7 @@ mutation addPendingDocumentMutation(
|
|
|
919
955
|
const [pendingReset, setPendingReset] = React__default["default"].useState(null);
|
|
920
956
|
const [isLoading, setIsLoading] = React__default["default"].useState(true);
|
|
921
957
|
const [newUpdate, setNewUpdate] = React__default["default"].useState(null);
|
|
958
|
+
const { currentBranch } = toolkit.useBranchData();
|
|
922
959
|
const updateData = async () => {
|
|
923
960
|
var _a;
|
|
924
961
|
if (newUpdate) {
|
|
@@ -1022,25 +1059,30 @@ mutation addPendingDocumentMutation(
|
|
|
1022
1059
|
setPendingReset(queryName);
|
|
1023
1060
|
},
|
|
1024
1061
|
onSubmit: async (payload2) => {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
onSubmit
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
});
|
|
1034
|
-
} else {
|
|
1035
|
-
try {
|
|
1036
|
-
await cms.api.tina.request(mutationString, {
|
|
1062
|
+
try {
|
|
1063
|
+
const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
|
|
1064
|
+
const variables2 = { params };
|
|
1065
|
+
const mutationString = result.form.mutationInfo.string;
|
|
1066
|
+
if (onSubmit) {
|
|
1067
|
+
onSubmit({
|
|
1068
|
+
queryString: mutationString,
|
|
1069
|
+
mutationString,
|
|
1037
1070
|
variables: variables2
|
|
1038
1071
|
});
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1072
|
+
} else {
|
|
1073
|
+
try {
|
|
1074
|
+
await cms.api.tina.request(mutationString, {
|
|
1075
|
+
variables: variables2
|
|
1076
|
+
});
|
|
1077
|
+
cms.alerts.success("Document saved!");
|
|
1078
|
+
} catch (e) {
|
|
1079
|
+
cms.alerts.error("There was a problem saving your document");
|
|
1080
|
+
console.error(e);
|
|
1081
|
+
}
|
|
1043
1082
|
}
|
|
1083
|
+
} catch (e) {
|
|
1084
|
+
console.error(e);
|
|
1085
|
+
cms.alerts.error("There was a problem saving your document");
|
|
1044
1086
|
}
|
|
1045
1087
|
}
|
|
1046
1088
|
};
|
|
@@ -1129,7 +1171,7 @@ mutation addPendingDocumentMutation(
|
|
|
1129
1171
|
}
|
|
1130
1172
|
});
|
|
1131
1173
|
};
|
|
1132
|
-
}, [queryString, JSON.stringify(variables)]);
|
|
1174
|
+
}, [queryString, JSON.stringify(variables), currentBranch]);
|
|
1133
1175
|
return [data, isLoading];
|
|
1134
1176
|
}
|
|
1135
1177
|
const transformDocumentIntoMutationRequestPayload = (document2, instructions) => {
|
|
@@ -1152,6 +1194,9 @@ mutation addPendingDocumentMutation(
|
|
|
1152
1194
|
return { [_template]: nested };
|
|
1153
1195
|
} catch (e) {
|
|
1154
1196
|
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
1197
|
+
if (!data) {
|
|
1198
|
+
return [];
|
|
1199
|
+
}
|
|
1155
1200
|
const accum = {};
|
|
1156
1201
|
Object.entries(data).map(([keyName, value]) => {
|
|
1157
1202
|
accum[keyName] = transformParams(value);
|
|
@@ -1609,12 +1654,6 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1609
1654
|
});
|
|
1610
1655
|
return str;
|
|
1611
1656
|
}
|
|
1612
|
-
function ImFilesEmpty(props) {
|
|
1613
|
-
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);
|
|
1614
|
-
}
|
|
1615
|
-
function VscOpenPreview(props) {
|
|
1616
|
-
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);
|
|
1617
|
-
}
|
|
1618
1657
|
const Layout = ({ children }) => {
|
|
1619
1658
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1620
1659
|
style: {
|
|
@@ -1629,14 +1668,12 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1629
1668
|
}
|
|
1630
1669
|
}, children);
|
|
1631
1670
|
};
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
}
|
|
1639
|
-
};
|
|
1671
|
+
function ImFilesEmpty(props) {
|
|
1672
|
+
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);
|
|
1673
|
+
}
|
|
1674
|
+
function VscOpenPreview(props) {
|
|
1675
|
+
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);
|
|
1676
|
+
}
|
|
1640
1677
|
const useGetCollections = (cms) => {
|
|
1641
1678
|
const [collections, setCollections] = React.useState([]);
|
|
1642
1679
|
React.useEffect(() => {
|
|
@@ -1654,14 +1691,98 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1654
1691
|
return null;
|
|
1655
1692
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(collections));
|
|
1656
1693
|
};
|
|
1694
|
+
const Sidebar = ({ cms }) => {
|
|
1695
|
+
const { setEdit } = sharedctx.useEditState();
|
|
1696
|
+
const logout2 = () => setEdit(false);
|
|
1697
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCollections, {
|
|
1698
|
+
cms
|
|
1699
|
+
}, (collections) => /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1700
|
+
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"
|
|
1701
|
+
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1702
|
+
className: "border-b border-gray-200"
|
|
1703
|
+
}, /* @__PURE__ */ React__default["default"].createElement(react.Menu, {
|
|
1704
|
+
as: "div",
|
|
1705
|
+
className: "relative block"
|
|
1706
|
+
}, ({ open }) => /* @__PURE__ */ React__default["default"].createElement("div", null, /* @__PURE__ */ React__default["default"].createElement(react.Menu.Button, {
|
|
1707
|
+
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`}`
|
|
1708
|
+
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
1709
|
+
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"
|
|
1710
|
+
}, /* @__PURE__ */ React__default["default"].createElement("svg", {
|
|
1711
|
+
viewBox: "0 0 32 32",
|
|
1712
|
+
fill: "#EC4815",
|
|
1713
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1714
|
+
className: "w-10 h-auto -ml-1"
|
|
1715
|
+
}, /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1716
|
+
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"
|
|
1717
|
+
}), /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1718
|
+
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"
|
|
1719
|
+
})), /* @__PURE__ */ React__default["default"].createElement("span", null, "Tina Admin")), /* @__PURE__ */ React__default["default"].createElement("svg", {
|
|
1720
|
+
width: "20",
|
|
1721
|
+
height: "20",
|
|
1722
|
+
viewBox: "0 0 20 20",
|
|
1723
|
+
fill: "none",
|
|
1724
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1725
|
+
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`}`
|
|
1726
|
+
}, /* @__PURE__ */ React__default["default"].createElement("g", {
|
|
1727
|
+
opacity: "0.3"
|
|
1728
|
+
}, /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1729
|
+
d: "M7.91675 13.8086L9.16675 15.0586L14.2253 10L9.16675 4.9414L7.91675 6.1914L11.7253 10L7.91675 13.8086Z",
|
|
1730
|
+
fill: "currentColor"
|
|
1731
|
+
})))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1732
|
+
className: "transform translate-y-full absolute bottom-3 right-5 w-2/3 z-50"
|
|
1733
|
+
}, /* @__PURE__ */ React__default["default"].createElement(react.Transition, {
|
|
1734
|
+
enter: "transition duration-150 ease-out",
|
|
1735
|
+
enterFrom: "transform opacity-0 -translate-y-2",
|
|
1736
|
+
enterTo: "transform opacity-100 translate-y-0",
|
|
1737
|
+
leave: "transition duration-75 ease-in",
|
|
1738
|
+
leaveFrom: "transform opacity-100 translate-y-0",
|
|
1739
|
+
leaveTo: "transform opacity-0 -translate-y-2"
|
|
1740
|
+
}, /* @__PURE__ */ React__default["default"].createElement(react.Menu.Items, {
|
|
1741
|
+
className: "w-full py-1 bg-white border border-gray-150 rounded-lg shadow-lg"
|
|
1742
|
+
}, /* @__PURE__ */ React__default["default"].createElement(react.Menu.Item, null, ({ active }) => /* @__PURE__ */ React__default["default"].createElement("a", {
|
|
1743
|
+
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"}`,
|
|
1744
|
+
href: "/"
|
|
1745
|
+
}, /* @__PURE__ */ React__default["default"].createElement(VscOpenPreview, {
|
|
1746
|
+
className: "w-6 h-auto mr-1.5 text-blue-400"
|
|
1747
|
+
}), " ", "View Website")), /* @__PURE__ */ React__default["default"].createElement(react.Menu.Item, null, ({ active }) => /* @__PURE__ */ React__default["default"].createElement("button", {
|
|
1748
|
+
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"}`,
|
|
1749
|
+
onClick: () => logout2()
|
|
1750
|
+
}, /* @__PURE__ */ React__default["default"].createElement(BiExit, {
|
|
1751
|
+
className: "w-6 h-auto mr-1.5 text-blue-400"
|
|
1752
|
+
}), " ", "Log out")))))))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1753
|
+
className: "px-6 py-7 flex-1"
|
|
1754
|
+
}, /* @__PURE__ */ React__default["default"].createElement("h4", {
|
|
1755
|
+
className: "uppercase font-bold text-sm mb-3"
|
|
1756
|
+
}, "Collections"), /* @__PURE__ */ React__default["default"].createElement("ul", {
|
|
1757
|
+
className: "flex flex-col gap-4"
|
|
1758
|
+
}, collections.map((collection) => {
|
|
1759
|
+
return /* @__PURE__ */ React__default["default"].createElement("li", {
|
|
1760
|
+
key: `${collection.name}-link`
|
|
1761
|
+
}, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.NavLink, {
|
|
1762
|
+
className: ({ isActive }) => {
|
|
1763
|
+
return `text-lg tracking-wide ${isActive ? "text-blue-600" : ""} hover:text-blue-600 flex items-center opacity-90 hover:opacity-100`;
|
|
1764
|
+
},
|
|
1765
|
+
to: `/admin/collections/${collection.name}`
|
|
1766
|
+
}, /* @__PURE__ */ React__default["default"].createElement(ImFilesEmpty, {
|
|
1767
|
+
className: "mr-2 h-6 opacity-80 w-auto"
|
|
1768
|
+
}), " ", collection.label));
|
|
1769
|
+
})))));
|
|
1770
|
+
};
|
|
1771
|
+
const GetCMS = ({ children }) => {
|
|
1772
|
+
try {
|
|
1773
|
+
const cms = toolkit.useCMS();
|
|
1774
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(cms));
|
|
1775
|
+
} catch (e) {
|
|
1776
|
+
return null;
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1657
1779
|
function MdOutlineArrowBack(props) {
|
|
1658
1780
|
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);
|
|
1659
1781
|
}
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
const LoginPage = () => {
|
|
1782
|
+
const AuthTemplate = ({
|
|
1783
|
+
message,
|
|
1784
|
+
children
|
|
1785
|
+
}) => {
|
|
1665
1786
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1666
1787
|
className: "h-screen w-full bg-gradient-to-b from-blue-900 to-gray-900 flex items-center justify-center px-4 py-6"
|
|
1667
1788
|
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -1679,12 +1800,19 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1679
1800
|
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"
|
|
1680
1801
|
}), /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1681
1802
|
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"
|
|
1682
|
-
})), /* @__PURE__ */ React__default["default"].createElement("span", null, "Tina Admin"))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1803
|
+
})), /* @__PURE__ */ React__default["default"].createElement("span", null, "Tina Admin"))), message && /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1683
1804
|
className: "px-5 py-4 "
|
|
1684
1805
|
}, /* @__PURE__ */ React__default["default"].createElement("p", {
|
|
1685
1806
|
className: "text-base font-sans leading-normal"
|
|
1686
|
-
},
|
|
1807
|
+
}, message)), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
1687
1808
|
className: "px-5 py-4 flex gap-4 w-full justify-between"
|
|
1809
|
+
}, children)));
|
|
1810
|
+
};
|
|
1811
|
+
const LoginPage = () => {
|
|
1812
|
+
const { setEdit } = sharedctx.useEditState();
|
|
1813
|
+
const login = () => setEdit(true);
|
|
1814
|
+
return /* @__PURE__ */ React__default["default"].createElement(AuthTemplate, {
|
|
1815
|
+
message: "Please log in to Tina Cloud to access your content."
|
|
1688
1816
|
}, /* @__PURE__ */ React__default["default"].createElement("a", {
|
|
1689
1817
|
href: "/",
|
|
1690
1818
|
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"
|
|
@@ -1697,7 +1825,26 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1697
1825
|
style: { background: "#0084FF" }
|
|
1698
1826
|
}, /* @__PURE__ */ React__default["default"].createElement(BiLogIn, {
|
|
1699
1827
|
className: "w-6 h-auto mr-1.5 opacity-80"
|
|
1700
|
-
}), " Log in"))
|
|
1828
|
+
}), " Log in"));
|
|
1829
|
+
};
|
|
1830
|
+
const logout = () => {
|
|
1831
|
+
sharedctx.setEditing(false);
|
|
1832
|
+
window.location.href = "/";
|
|
1833
|
+
};
|
|
1834
|
+
const LogoutPage = () => {
|
|
1835
|
+
return /* @__PURE__ */ React__default["default"].createElement(AuthTemplate, null, /* @__PURE__ */ React__default["default"].createElement("a", {
|
|
1836
|
+
href: "/",
|
|
1837
|
+
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"
|
|
1838
|
+
}, /* @__PURE__ */ React__default["default"].createElement(MdOutlineArrowBack, {
|
|
1839
|
+
className: "w-6 h-auto mr-1.5 opacity-80"
|
|
1840
|
+
}), " Back to site"), /* @__PURE__ */ React__default["default"].createElement("button", {
|
|
1841
|
+
type: "submit",
|
|
1842
|
+
onClick: () => logout(),
|
|
1843
|
+
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",
|
|
1844
|
+
style: { background: "#0084FF" }
|
|
1845
|
+
}, /* @__PURE__ */ React__default["default"].createElement(BiLogOut, {
|
|
1846
|
+
className: "w-6 h-auto mr-1.5 opacity-80"
|
|
1847
|
+
}), " Log out"));
|
|
1701
1848
|
};
|
|
1702
1849
|
const DashboardPage = () => {
|
|
1703
1850
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -1927,13 +2074,15 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1927
2074
|
includeCollection,
|
|
1928
2075
|
includeTemplate
|
|
1929
2076
|
});
|
|
1930
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
1931
|
-
createDocument(
|
|
2077
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2078
|
+
createDocument(
|
|
2079
|
+
collection: $collection,
|
|
1932
2080
|
relativePath: $relativePath,
|
|
1933
2081
|
params: $params
|
|
1934
2082
|
){__typename}
|
|
1935
2083
|
}`, {
|
|
1936
2084
|
variables: {
|
|
2085
|
+
collection: collection.name,
|
|
1937
2086
|
relativePath,
|
|
1938
2087
|
params
|
|
1939
2088
|
}
|
|
@@ -1941,7 +2090,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1941
2090
|
};
|
|
1942
2091
|
const CollectionCreatePage = () => {
|
|
1943
2092
|
const { collectionName, templateName } = reactRouterDom.useParams();
|
|
1944
|
-
const
|
|
2093
|
+
const navigate = reactRouterDom.useNavigate();
|
|
1945
2094
|
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
|
|
1946
2095
|
cms,
|
|
1947
2096
|
collectionName,
|
|
@@ -1962,7 +2111,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1962
2111
|
],
|
|
1963
2112
|
onSubmit: async (values) => {
|
|
1964
2113
|
await createDocument(cms, collection, template, mutationInfo, values);
|
|
1965
|
-
|
|
2114
|
+
navigate(`/admin/collections/${collection.name}`);
|
|
1966
2115
|
}
|
|
1967
2116
|
});
|
|
1968
2117
|
const formLabel = template ? `${collection.label} - Create New ${template.label}` : `${collection.label} - Create New`;
|
|
@@ -2007,19 +2156,21 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2007
2156
|
}
|
|
2008
2157
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(document2));
|
|
2009
2158
|
};
|
|
2010
|
-
const updateDocument = async (cms, relativePath, mutationInfo, values) => {
|
|
2159
|
+
const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
|
|
2011
2160
|
const { includeCollection, includeTemplate } = mutationInfo;
|
|
2012
2161
|
const params = transformDocumentIntoMutationRequestPayload(values, {
|
|
2013
2162
|
includeCollection,
|
|
2014
2163
|
includeTemplate
|
|
2015
2164
|
});
|
|
2016
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
2165
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2017
2166
|
updateDocument(
|
|
2167
|
+
collection: $collection,
|
|
2018
2168
|
relativePath: $relativePath,
|
|
2019
2169
|
params: $params
|
|
2020
2170
|
){__typename}
|
|
2021
2171
|
}`, {
|
|
2022
2172
|
variables: {
|
|
2173
|
+
collection: collection.name,
|
|
2023
2174
|
relativePath,
|
|
2024
2175
|
params
|
|
2025
2176
|
}
|
|
@@ -2027,7 +2178,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2027
2178
|
};
|
|
2028
2179
|
const CollectionUpdatePage = () => {
|
|
2029
2180
|
const { collectionName, filename } = reactRouterDom.useParams();
|
|
2030
|
-
const
|
|
2181
|
+
const navigate = reactRouterDom.useNavigate();
|
|
2031
2182
|
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
|
|
2032
2183
|
cms,
|
|
2033
2184
|
collectionName
|
|
@@ -2044,8 +2195,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2044
2195
|
fields: document2.form.fields,
|
|
2045
2196
|
initialValues: document2.values,
|
|
2046
2197
|
onSubmit: async (values) => {
|
|
2047
|
-
await updateDocument(cms, relativePath, mutationInfo, values);
|
|
2048
|
-
|
|
2198
|
+
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
2199
|
+
navigate(`/collections/${collection.name}`);
|
|
2049
2200
|
}
|
|
2050
2201
|
});
|
|
2051
2202
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -2061,8 +2212,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2061
2212
|
};
|
|
2062
2213
|
const useEmbedTailwind = () => {
|
|
2063
2214
|
React.useEffect(() => {
|
|
2064
|
-
const
|
|
2065
|
-
if (!
|
|
2215
|
+
const isSSR = typeof window === "undefined";
|
|
2216
|
+
if (!isSSR) {
|
|
2066
2217
|
const head = document.head;
|
|
2067
2218
|
const link = document.createElement("link");
|
|
2068
2219
|
link.id = "tina-admin-stylesheet";
|
|
@@ -2073,106 +2224,51 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2073
2224
|
}
|
|
2074
2225
|
}, []);
|
|
2075
2226
|
};
|
|
2076
|
-
const logout = () => {
|
|
2077
|
-
setEditing(false);
|
|
2078
|
-
window.location.reload();
|
|
2079
|
-
};
|
|
2080
2227
|
const TinaAdmin = () => {
|
|
2081
2228
|
useEmbedTailwind();
|
|
2082
|
-
const
|
|
2083
|
-
|
|
2229
|
+
const isSSR = typeof window === "undefined";
|
|
2230
|
+
const { edit } = sharedctx.useEditState();
|
|
2231
|
+
if (isSSR) {
|
|
2084
2232
|
return null;
|
|
2085
2233
|
}
|
|
2086
|
-
|
|
2087
|
-
if (!isEdit) {
|
|
2234
|
+
if (!edit) {
|
|
2088
2235
|
return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement(LoginPage, null));
|
|
2089
2236
|
}
|
|
2090
|
-
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) =>
|
|
2091
|
-
cms
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
fill: "currentColor"
|
|
2126
|
-
})))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2127
|
-
className: "transform translate-y-full absolute bottom-3 right-5 w-2/3 z-50"
|
|
2128
|
-
}, /* @__PURE__ */ React__default["default"].createElement(react.Transition, {
|
|
2129
|
-
enter: "transition duration-150 ease-out",
|
|
2130
|
-
enterFrom: "transform opacity-0 -translate-y-2",
|
|
2131
|
-
enterTo: "transform opacity-100 translate-y-0",
|
|
2132
|
-
leave: "transition duration-75 ease-in",
|
|
2133
|
-
leaveFrom: "transform opacity-100 translate-y-0",
|
|
2134
|
-
leaveTo: "transform opacity-0 -translate-y-2"
|
|
2135
|
-
}, /* @__PURE__ */ React__default["default"].createElement(react.Menu.Items, {
|
|
2136
|
-
className: "w-full py-1 bg-white border border-gray-150 rounded-lg shadow-lg"
|
|
2137
|
-
}, /* @__PURE__ */ React__default["default"].createElement(react.Menu.Item, null, ({ active }) => /* @__PURE__ */ React__default["default"].createElement("a", {
|
|
2138
|
-
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"}`,
|
|
2139
|
-
href: "/"
|
|
2140
|
-
}, /* @__PURE__ */ React__default["default"].createElement(VscOpenPreview, {
|
|
2141
|
-
className: "w-6 h-auto mr-1.5 text-blue-400"
|
|
2142
|
-
}), " ", "View Website")), /* @__PURE__ */ React__default["default"].createElement(react.Menu.Item, null, ({ active }) => /* @__PURE__ */ React__default["default"].createElement("button", {
|
|
2143
|
-
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"}`,
|
|
2144
|
-
onClick: () => logout()
|
|
2145
|
-
}, /* @__PURE__ */ React__default["default"].createElement(BiExit, {
|
|
2146
|
-
className: "w-6 h-auto mr-1.5 text-blue-400"
|
|
2147
|
-
}), " ", "Log out")))))))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2148
|
-
className: "px-6 py-7 flex-1"
|
|
2149
|
-
}, /* @__PURE__ */ React__default["default"].createElement("h4", {
|
|
2150
|
-
className: "uppercase font-bold text-sm mb-3"
|
|
2151
|
-
}, "Collections"), /* @__PURE__ */ React__default["default"].createElement("ul", {
|
|
2152
|
-
className: "flex flex-col gap-4"
|
|
2153
|
-
}, collections.map((collection) => {
|
|
2154
|
-
return /* @__PURE__ */ React__default["default"].createElement("li", {
|
|
2155
|
-
key: `${collection.name}-link`
|
|
2156
|
-
}, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.NavLink, {
|
|
2157
|
-
className: `text-lg tracking-wide hover:text-blue-600 flex items-center opacity-90 hover:opacity-100`,
|
|
2158
|
-
activeClassName: "text-blue-600",
|
|
2159
|
-
to: `/admin/collections/${collection.name}`
|
|
2160
|
-
}, /* @__PURE__ */ React__default["default"].createElement(ImFilesEmpty, {
|
|
2161
|
-
className: "mr-2 h-6 opacity-80 w-auto"
|
|
2162
|
-
}), " ", collection.label));
|
|
2163
|
-
})))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2164
|
-
className: "flex-1"
|
|
2165
|
-
}, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Switch, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2166
|
-
path: `/admin/collections/:collectionName/new`
|
|
2167
|
-
}, /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2168
|
-
path: `/admin/collections/:collectionName/:templateName/new`
|
|
2169
|
-
}, /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2170
|
-
path: `/admin/collections/:collectionName/:filename`
|
|
2171
|
-
}, /* @__PURE__ */ React__default["default"].createElement(CollectionUpdatePage, null)), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2172
|
-
path: `/admin/collections/:collectionName`
|
|
2173
|
-
}, /* @__PURE__ */ React__default["default"].createElement(CollectionListPage, null)), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2174
|
-
path: `/admin`
|
|
2175
|
-
}, /* @__PURE__ */ React__default["default"].createElement(DashboardPage, null)))))))));
|
|
2237
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => {
|
|
2238
|
+
const isTinaAdminEnabled = cms.flags.get("tina-admin");
|
|
2239
|
+
if (isTinaAdminEnabled) {
|
|
2240
|
+
return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.BrowserRouter, null, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2241
|
+
className: "flex items-stretch h-screen overflow-hidden"
|
|
2242
|
+
}, /* @__PURE__ */ React__default["default"].createElement(Sidebar, {
|
|
2243
|
+
cms
|
|
2244
|
+
}), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2245
|
+
className: "flex-1"
|
|
2246
|
+
}, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2247
|
+
path: "/admin/collections/:collectionName/new",
|
|
2248
|
+
element: /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)
|
|
2249
|
+
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2250
|
+
path: "/admin/collections/:collectionName/:templateName/new",
|
|
2251
|
+
element: /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)
|
|
2252
|
+
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2253
|
+
path: "/admin/collections/:collectionName/:filename",
|
|
2254
|
+
element: /* @__PURE__ */ React__default["default"].createElement(CollectionUpdatePage, null)
|
|
2255
|
+
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2256
|
+
path: "/admin/collections/:collectionName",
|
|
2257
|
+
element: /* @__PURE__ */ React__default["default"].createElement(CollectionListPage, null)
|
|
2258
|
+
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2259
|
+
path: "/admin",
|
|
2260
|
+
element: /* @__PURE__ */ React__default["default"].createElement(DashboardPage, null)
|
|
2261
|
+
}))))));
|
|
2262
|
+
} else {
|
|
2263
|
+
return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.BrowserRouter, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2264
|
+
path: "/admin/logout"
|
|
2265
|
+
}, /* @__PURE__ */ React__default["default"].createElement(LogoutPage, null)), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
2266
|
+
path: "/admin"
|
|
2267
|
+
}, () => {
|
|
2268
|
+
window.location.href = "/";
|
|
2269
|
+
}))));
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2176
2272
|
};
|
|
2177
2273
|
class RouteMappingPlugin {
|
|
2178
2274
|
constructor(mapper) {
|