tinacms 0.57.1 → 0.58.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/CHANGELOG.md +36 -0
- package/dist/admin/components/GetCollection.d.ts +7 -0
- package/dist/admin/components/GetDocumentFields.d.ts +6 -3
- package/dist/admin/plugins/route-mapping.d.ts +32 -0
- package/dist/auth/TinaCloudProvider.d.ts +1 -1
- package/dist/edit-state.es.js +3 -0
- package/dist/edit-state.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +289 -163
- package/dist/index.js +287 -160
- package/dist/tina-cms.d.ts +2 -2
- package/dist/utils/client.d.ts +29 -0
- package/package.json +6 -9
package/dist/index.es.js
CHANGED
|
@@ -32,9 +32,9 @@ var __objRest = (source, exclude) => {
|
|
|
32
32
|
import { TypeInfo, visit, visitWithTypeInfo, getNamedType, GraphQLObjectType, isLeafType, GraphQLUnionType, isScalarType, getIntrospectionQuery, buildClientSchema, print } from "graphql";
|
|
33
33
|
import set from "lodash.set";
|
|
34
34
|
import gql$1 from "graphql-tag";
|
|
35
|
-
import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, TinaCMS, BranchSwitcherPlugin, TinaProvider, useCMS, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
|
|
35
|
+
import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, TinaCMS, BranchSwitcherPlugin, TinaProvider, useCMS, FormMetaPlugin, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
|
|
36
36
|
export * from "@tinacms/toolkit";
|
|
37
|
-
import React, { useState, useCallback, useEffect } from "react";
|
|
37
|
+
import React, { useState, useCallback, useEffect, Fragment } from "react";
|
|
38
38
|
import styled from "styled-components";
|
|
39
39
|
import * as yup from "yup";
|
|
40
40
|
import { getIn, setIn } from "final-form";
|
|
@@ -746,8 +746,14 @@ const TinaCloudProvider = (props) => {
|
|
|
746
746
|
cms.api.tina = createClient(props);
|
|
747
747
|
}
|
|
748
748
|
const setupMedia = async () => {
|
|
749
|
+
var _a;
|
|
749
750
|
if (props.mediaStore) {
|
|
750
|
-
|
|
751
|
+
if ((_a = props.mediaStore.prototype) == null ? void 0 : _a.persist) {
|
|
752
|
+
cms.media.store = new props.mediaStore(cms.api.tina);
|
|
753
|
+
} else {
|
|
754
|
+
const MediaClass = await props.mediaStore();
|
|
755
|
+
cms.media.store = new MediaClass(cms.api.tina);
|
|
756
|
+
}
|
|
751
757
|
}
|
|
752
758
|
};
|
|
753
759
|
const handleListBranches = async () => {
|
|
@@ -794,6 +800,91 @@ const TinaCloudProvider = (props) => {
|
|
|
794
800
|
})));
|
|
795
801
|
};
|
|
796
802
|
const TinaCloudAuthWall = TinaCloudProvider;
|
|
803
|
+
var DefaultContext = {
|
|
804
|
+
color: void 0,
|
|
805
|
+
size: void 0,
|
|
806
|
+
className: void 0,
|
|
807
|
+
style: void 0,
|
|
808
|
+
attr: void 0
|
|
809
|
+
};
|
|
810
|
+
var IconContext = React.createContext && React.createContext(DefaultContext);
|
|
811
|
+
var __assign = function() {
|
|
812
|
+
__assign = Object.assign || function(t) {
|
|
813
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
814
|
+
s = arguments[i];
|
|
815
|
+
for (var p in s)
|
|
816
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
817
|
+
t[p] = s[p];
|
|
818
|
+
}
|
|
819
|
+
return t;
|
|
820
|
+
};
|
|
821
|
+
return __assign.apply(this, arguments);
|
|
822
|
+
};
|
|
823
|
+
var __rest = function(s, e) {
|
|
824
|
+
var t = {};
|
|
825
|
+
for (var p in s)
|
|
826
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
827
|
+
t[p] = s[p];
|
|
828
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
829
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
830
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
831
|
+
t[p[i]] = s[p[i]];
|
|
832
|
+
}
|
|
833
|
+
return t;
|
|
834
|
+
};
|
|
835
|
+
function Tree2Element(tree) {
|
|
836
|
+
return tree && tree.map(function(node, i) {
|
|
837
|
+
return React.createElement(node.tag, __assign({
|
|
838
|
+
key: i
|
|
839
|
+
}, node.attr), Tree2Element(node.child));
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
function GenIcon(data) {
|
|
843
|
+
return function(props) {
|
|
844
|
+
return React.createElement(IconBase, __assign({
|
|
845
|
+
attr: __assign({}, data.attr)
|
|
846
|
+
}, props), Tree2Element(data.child));
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function IconBase(props) {
|
|
850
|
+
var elem = function(conf) {
|
|
851
|
+
var attr = props.attr, size = props.size, title = props.title, svgProps = __rest(props, ["attr", "size", "title"]);
|
|
852
|
+
var computedSize = size || conf.size || "1em";
|
|
853
|
+
var className;
|
|
854
|
+
if (conf.className)
|
|
855
|
+
className = conf.className;
|
|
856
|
+
if (props.className)
|
|
857
|
+
className = (className ? className + " " : "") + props.className;
|
|
858
|
+
return React.createElement("svg", __assign({
|
|
859
|
+
stroke: "currentColor",
|
|
860
|
+
fill: "currentColor",
|
|
861
|
+
strokeWidth: "0"
|
|
862
|
+
}, conf.attr, attr, svgProps, {
|
|
863
|
+
className,
|
|
864
|
+
style: __assign(__assign({
|
|
865
|
+
color: props.color || conf.color
|
|
866
|
+
}, conf.style), props.style),
|
|
867
|
+
height: computedSize,
|
|
868
|
+
width: computedSize,
|
|
869
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
870
|
+
}), title && React.createElement("title", null, title), props.children);
|
|
871
|
+
};
|
|
872
|
+
return IconContext !== void 0 ? React.createElement(IconContext.Consumer, null, function(conf) {
|
|
873
|
+
return elem(conf);
|
|
874
|
+
}) : elem(DefaultContext);
|
|
875
|
+
}
|
|
876
|
+
function BiEdit(props) {
|
|
877
|
+
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);
|
|
878
|
+
}
|
|
879
|
+
function BiExit(props) {
|
|
880
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M19.002 3h-14c-1.103 0-2 .897-2 2v4h2V5h14v14h-14v-4h-2v4c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2V5c0-1.103-.898-2-2-2z" } }, { "tag": "path", "attr": { "d": "m11 16 5-4-5-4v3.001H3v2h8z" } }] })(props);
|
|
881
|
+
}
|
|
882
|
+
function BiLinkExternal(props) {
|
|
883
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "m13 3 3.293 3.293-7 7 1.414 1.414 7-7L21 11V3z" } }, { "tag": "path", "attr": { "d": "M19 19H5V5h7l-2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5l-2-2v7z" } }] })(props);
|
|
884
|
+
}
|
|
885
|
+
function BiLogIn(props) {
|
|
886
|
+
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);
|
|
887
|
+
}
|
|
797
888
|
function useGraphqlForms({
|
|
798
889
|
query,
|
|
799
890
|
variables,
|
|
@@ -807,7 +898,6 @@ function useGraphqlForms({
|
|
|
807
898
|
const [pendingReset, setPendingReset] = React.useState(null);
|
|
808
899
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
809
900
|
const [newUpdate, setNewUpdate] = React.useState(null);
|
|
810
|
-
React.useState([]);
|
|
811
901
|
const updateData = async () => {
|
|
812
902
|
var _a;
|
|
813
903
|
if (newUpdate) {
|
|
@@ -856,12 +946,15 @@ function useGraphqlForms({
|
|
|
856
946
|
}
|
|
857
947
|
}, [pendingReset]);
|
|
858
948
|
React.useEffect(() => {
|
|
949
|
+
const formIds = [];
|
|
859
950
|
setIsLoading(true);
|
|
860
951
|
cms.api.tina.requestWithForm(query, { variables }).then((payload) => {
|
|
952
|
+
cms.plugins.remove(new FormMetaPlugin({ name: "tina-admin-link" }));
|
|
861
953
|
setData(payload);
|
|
862
954
|
setInitialData(payload);
|
|
863
955
|
setIsLoading(false);
|
|
864
956
|
Object.entries(payload).map(([queryName, result]) => {
|
|
957
|
+
formIds.push(queryName);
|
|
865
958
|
const canBeFormified = safeAssertShape(result, (yup2) => yup2.object({
|
|
866
959
|
values: yup2.object().required(),
|
|
867
960
|
form: yup2.object().required()
|
|
@@ -873,6 +966,32 @@ function useGraphqlForms({
|
|
|
873
966
|
values: yup2.object().required(),
|
|
874
967
|
form: yup2.object().required()
|
|
875
968
|
}), `Unable to build form shape for fields at ${queryName}`);
|
|
969
|
+
if (cms.flags.get("tina-admin")) {
|
|
970
|
+
const TinaAdminLink = new FormMetaPlugin({
|
|
971
|
+
name: "tina-admin-link",
|
|
972
|
+
Component: () => /* @__PURE__ */ React.createElement("a", {
|
|
973
|
+
href: `/admin/collections/${result._internalSys.collection.name}/${result._internalSys.filename}`,
|
|
974
|
+
style: {
|
|
975
|
+
display: "flex",
|
|
976
|
+
alignItems: "center",
|
|
977
|
+
padding: "10px 20px",
|
|
978
|
+
borderTop: "1px solid var(--tina-color-grey-2)",
|
|
979
|
+
textTransform: "uppercase",
|
|
980
|
+
fontSize: "11px",
|
|
981
|
+
fontWeight: 500,
|
|
982
|
+
background: "var(--tina-color-grey-0)"
|
|
983
|
+
}
|
|
984
|
+
}, /* @__PURE__ */ React.createElement(BiLinkExternal, {
|
|
985
|
+
style: {
|
|
986
|
+
height: "1.25em",
|
|
987
|
+
width: "auto",
|
|
988
|
+
opacity: "0.8",
|
|
989
|
+
marginRight: "8px"
|
|
990
|
+
}
|
|
991
|
+
}), " ", "Edit in Tina Admin")
|
|
992
|
+
});
|
|
993
|
+
cms.plugins.add(TinaAdminLink);
|
|
994
|
+
}
|
|
876
995
|
const formConfig = {
|
|
877
996
|
id: queryName,
|
|
878
997
|
label: result.form.label,
|
|
@@ -981,6 +1100,14 @@ function useGraphqlForms({
|
|
|
981
1100
|
console.error(e);
|
|
982
1101
|
setIsLoading(false);
|
|
983
1102
|
});
|
|
1103
|
+
return () => {
|
|
1104
|
+
formIds.forEach((name) => {
|
|
1105
|
+
const formPlugin = cms.forms.find(name);
|
|
1106
|
+
if (formPlugin) {
|
|
1107
|
+
cms.forms.remove(formPlugin);
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
984
1111
|
}, [queryString, JSON.stringify(variables)]);
|
|
985
1112
|
return [data, isLoading];
|
|
986
1113
|
}
|
|
@@ -1454,81 +1581,12 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1454
1581
|
}
|
|
1455
1582
|
return client.request(query, { variables });
|
|
1456
1583
|
};
|
|
1457
|
-
function gql(strings) {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
color: void 0,
|
|
1462
|
-
size: void 0,
|
|
1463
|
-
className: void 0,
|
|
1464
|
-
style: void 0,
|
|
1465
|
-
attr: void 0
|
|
1466
|
-
};
|
|
1467
|
-
var IconContext = React.createContext && React.createContext(DefaultContext);
|
|
1468
|
-
var __assign = function() {
|
|
1469
|
-
__assign = Object.assign || function(t) {
|
|
1470
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1471
|
-
s = arguments[i];
|
|
1472
|
-
for (var p in s)
|
|
1473
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1474
|
-
t[p] = s[p];
|
|
1475
|
-
}
|
|
1476
|
-
return t;
|
|
1477
|
-
};
|
|
1478
|
-
return __assign.apply(this, arguments);
|
|
1479
|
-
};
|
|
1480
|
-
var __rest = function(s, e) {
|
|
1481
|
-
var t = {};
|
|
1482
|
-
for (var p in s)
|
|
1483
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1484
|
-
t[p] = s[p];
|
|
1485
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1486
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1487
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1488
|
-
t[p[i]] = s[p[i]];
|
|
1489
|
-
}
|
|
1490
|
-
return t;
|
|
1491
|
-
};
|
|
1492
|
-
function Tree2Element(tree) {
|
|
1493
|
-
return tree && tree.map(function(node, i) {
|
|
1494
|
-
return React.createElement(node.tag, __assign({
|
|
1495
|
-
key: i
|
|
1496
|
-
}, node.attr), Tree2Element(node.child));
|
|
1584
|
+
function gql(strings, ...args) {
|
|
1585
|
+
let str = "";
|
|
1586
|
+
strings.forEach((string, i) => {
|
|
1587
|
+
str += string + (args[i] || "");
|
|
1497
1588
|
});
|
|
1498
|
-
|
|
1499
|
-
function GenIcon(data) {
|
|
1500
|
-
return function(props) {
|
|
1501
|
-
return React.createElement(IconBase, __assign({
|
|
1502
|
-
attr: __assign({}, data.attr)
|
|
1503
|
-
}, props), Tree2Element(data.child));
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
function IconBase(props) {
|
|
1507
|
-
var elem = function(conf) {
|
|
1508
|
-
var attr = props.attr, size = props.size, title = props.title, svgProps = __rest(props, ["attr", "size", "title"]);
|
|
1509
|
-
var computedSize = size || conf.size || "1em";
|
|
1510
|
-
var className;
|
|
1511
|
-
if (conf.className)
|
|
1512
|
-
className = conf.className;
|
|
1513
|
-
if (props.className)
|
|
1514
|
-
className = (className ? className + " " : "") + props.className;
|
|
1515
|
-
return React.createElement("svg", __assign({
|
|
1516
|
-
stroke: "currentColor",
|
|
1517
|
-
fill: "currentColor",
|
|
1518
|
-
strokeWidth: "0"
|
|
1519
|
-
}, conf.attr, attr, svgProps, {
|
|
1520
|
-
className,
|
|
1521
|
-
style: __assign(__assign({
|
|
1522
|
-
color: props.color || conf.color
|
|
1523
|
-
}, conf.style), props.style),
|
|
1524
|
-
height: computedSize,
|
|
1525
|
-
width: computedSize,
|
|
1526
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
1527
|
-
}), title && React.createElement("title", null, title), props.children);
|
|
1528
|
-
};
|
|
1529
|
-
return IconContext !== void 0 ? React.createElement(IconContext.Consumer, null, function(conf) {
|
|
1530
|
-
return elem(conf);
|
|
1531
|
-
}) : elem(DefaultContext);
|
|
1589
|
+
return str;
|
|
1532
1590
|
}
|
|
1533
1591
|
function ImFilesEmpty(props) {
|
|
1534
1592
|
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);
|
|
@@ -1575,15 +1633,6 @@ const GetCollections = ({ cms, children }) => {
|
|
|
1575
1633
|
return null;
|
|
1576
1634
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, children(collections));
|
|
1577
1635
|
};
|
|
1578
|
-
function BiEdit(props) {
|
|
1579
|
-
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);
|
|
1580
|
-
}
|
|
1581
|
-
function BiExit(props) {
|
|
1582
|
-
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M19.002 3h-14c-1.103 0-2 .897-2 2v4h2V5h14v14h-14v-4h-2v4c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2V5c0-1.103-.898-2-2-2z" } }, { "tag": "path", "attr": { "d": "m11 16 5-4-5-4v3.001H3v2h8z" } }] })(props);
|
|
1583
|
-
}
|
|
1584
|
-
function BiLogIn(props) {
|
|
1585
|
-
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);
|
|
1586
|
-
}
|
|
1587
1636
|
function MdOutlineArrowBack(props) {
|
|
1588
1637
|
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);
|
|
1589
1638
|
}
|
|
@@ -1656,12 +1705,14 @@ const useGetCollection = (cms, collectionName, includeDocuments = true) => {
|
|
|
1656
1705
|
name
|
|
1657
1706
|
label
|
|
1658
1707
|
format
|
|
1708
|
+
templates
|
|
1659
1709
|
documents @include(if: $includeDocuments) {
|
|
1660
1710
|
totalCount
|
|
1661
1711
|
edges {
|
|
1662
1712
|
node {
|
|
1663
1713
|
... on Document {
|
|
1664
1714
|
sys {
|
|
1715
|
+
template
|
|
1665
1716
|
breadcrumbs
|
|
1666
1717
|
path
|
|
1667
1718
|
basename
|
|
@@ -1693,59 +1744,119 @@ const GetCollection = ({
|
|
|
1693
1744
|
}
|
|
1694
1745
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, children(collection));
|
|
1695
1746
|
};
|
|
1747
|
+
const TemplateMenu = ({ templates }) => {
|
|
1748
|
+
return /* @__PURE__ */ React.createElement(Menu, {
|
|
1749
|
+
as: "div",
|
|
1750
|
+
className: "relative inline-block text-left"
|
|
1751
|
+
}, ({ open }) => /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Menu.Button, {
|
|
1752
|
+
className: "inline-flex items-center px-8 py-2.5 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",
|
|
1753
|
+
style: { background: "#0084FF" }
|
|
1754
|
+
}, "Create New", /* @__PURE__ */ React.createElement("svg", {
|
|
1755
|
+
width: "20",
|
|
1756
|
+
height: "20",
|
|
1757
|
+
viewBox: "0 0 20 20",
|
|
1758
|
+
fill: "none",
|
|
1759
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1760
|
+
className: `ml-1 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`}`
|
|
1761
|
+
}, /* @__PURE__ */ React.createElement("g", {
|
|
1762
|
+
opacity: "1.0"
|
|
1763
|
+
}, /* @__PURE__ */ React.createElement("path", {
|
|
1764
|
+
d: "M7.91675 13.8086L9.16675 15.0586L14.2253 10L9.16675 4.9414L7.91675 6.1914L11.7253 10L7.91675 13.8086Z",
|
|
1765
|
+
fill: "currentColor"
|
|
1766
|
+
}))))), /* @__PURE__ */ React.createElement(Transition, {
|
|
1767
|
+
as: Fragment,
|
|
1768
|
+
enter: "transition ease-out duration-100",
|
|
1769
|
+
enterFrom: "transform opacity-0 scale-95",
|
|
1770
|
+
enterTo: "transform opacity-100 scale-100",
|
|
1771
|
+
leave: "transition ease-in duration-75",
|
|
1772
|
+
leaveFrom: "transform opacity-100 scale-100",
|
|
1773
|
+
leaveTo: "transform opacity-0 scale-95"
|
|
1774
|
+
}, /* @__PURE__ */ React.createElement(Menu.Items, {
|
|
1775
|
+
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"
|
|
1776
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1777
|
+
className: "py-1"
|
|
1778
|
+
}, templates.map((template) => /* @__PURE__ */ React.createElement(Menu.Item, {
|
|
1779
|
+
key: `${template.label}-${template.name}`
|
|
1780
|
+
}, ({ active }) => /* @__PURE__ */ React.createElement(Link, {
|
|
1781
|
+
to: `${location.pathname}/${template.name}/new`,
|
|
1782
|
+
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"}`
|
|
1783
|
+
}, template.label))))))));
|
|
1784
|
+
};
|
|
1696
1785
|
const CollectionListPage = () => {
|
|
1697
|
-
const
|
|
1786
|
+
const location2 = useLocation();
|
|
1698
1787
|
const { collectionName } = useParams();
|
|
1699
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) =>
|
|
1700
|
-
cms
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1788
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => {
|
|
1789
|
+
const plugins = cms.plugins.all("tina-admin");
|
|
1790
|
+
const routeMapping = plugins.find(({ name }) => name === "route-mapping");
|
|
1791
|
+
return /* @__PURE__ */ React.createElement(GetCollection, {
|
|
1792
|
+
cms,
|
|
1793
|
+
collectionName,
|
|
1794
|
+
includeDocuments: true
|
|
1795
|
+
}, (collection) => {
|
|
1796
|
+
const totalCount = collection.documents.totalCount;
|
|
1797
|
+
const documents = collection.documents.edges;
|
|
1798
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1799
|
+
className: "px-6 py-14 h-screen overflow-y-auto flex justify-center"
|
|
1800
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1801
|
+
className: "max-w-screen-md w-full"
|
|
1802
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1803
|
+
className: "w-full flex justify-between items-end"
|
|
1804
|
+
}, /* @__PURE__ */ React.createElement("h3", {
|
|
1805
|
+
className: "text-3xl"
|
|
1806
|
+
}, collection.label), !collection.templates && /* @__PURE__ */ React.createElement(Link, {
|
|
1807
|
+
to: `${location2.pathname}/new`,
|
|
1808
|
+
className: "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",
|
|
1809
|
+
style: { background: "#0084FF" }
|
|
1810
|
+
}, "Create New"), collection.templates && /* @__PURE__ */ React.createElement(TemplateMenu, {
|
|
1811
|
+
templates: collection.templates
|
|
1812
|
+
})), totalCount > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
1813
|
+
className: "mt-8 shadow overflow-hidden border-b border-gray-200 sm:rounded-lg"
|
|
1814
|
+
}, /* @__PURE__ */ React.createElement("table", {
|
|
1815
|
+
className: "min-w-full"
|
|
1816
|
+
}, /* @__PURE__ */ React.createElement("tbody", {
|
|
1817
|
+
className: "bg-white divide-y divide-gray-150"
|
|
1818
|
+
}, documents.map((document2) => {
|
|
1819
|
+
const livesiteRoute = routeMapping ? routeMapping.mapper(collection, document2.node) : void 0;
|
|
1820
|
+
return /* @__PURE__ */ React.createElement("tr", {
|
|
1821
|
+
key: document2.node.sys.relativePath
|
|
1822
|
+
}, /* @__PURE__ */ React.createElement("td", {
|
|
1823
|
+
className: "px-5 py-3 whitespace-nowrap"
|
|
1824
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1825
|
+
className: "block text-xs mb-0.5 text-gray-400 uppercase"
|
|
1826
|
+
}, "Filename"), /* @__PURE__ */ React.createElement(Link, {
|
|
1827
|
+
to: `${location2.pathname}/${document2.node.sys.filename}`,
|
|
1828
|
+
className: "h-5 leading-5 block"
|
|
1829
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1830
|
+
className: "leading-5 font-medium text-base overflow-ellipsis overflow-hidden whitespace-nowrap text-gray-700"
|
|
1831
|
+
}, document2.node.sys.filename), /* @__PURE__ */ React.createElement("span", {
|
|
1832
|
+
className: "leading-5 text-base font-medium text-gray-300"
|
|
1833
|
+
}, document2.node.sys.extension))), /* @__PURE__ */ React.createElement("td", {
|
|
1834
|
+
className: "px-5 py-3 whitespace-nowrap"
|
|
1835
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1836
|
+
className: "block text-xs mb-0.5 text-gray-400 uppercase"
|
|
1837
|
+
}, "Template"), /* @__PURE__ */ React.createElement("span", {
|
|
1838
|
+
className: "h-5 block leading-5 font-regular text-base overflow-ellipsis overflow-hidden whitespace-nowrap text-gray-500"
|
|
1839
|
+
}, document2.node.sys.template)), /* @__PURE__ */ React.createElement("td", {
|
|
1840
|
+
className: "px-5 py-3 whitespace-nowrap flex gap-3 items-center justify-end"
|
|
1841
|
+
}, livesiteRoute && /* @__PURE__ */ React.createElement("a", {
|
|
1842
|
+
href: livesiteRoute,
|
|
1843
|
+
className: "flex gap-1.5 items-center px-4 py-1.5 rounded-full transition-all ease-out duration-150 text-gray-500 hover:text-blue-500"
|
|
1844
|
+
}, /* @__PURE__ */ React.createElement(BiLinkExternal, {
|
|
1845
|
+
className: "inline-block h-5 w-auto opacity-70"
|
|
1846
|
+
}), " ", "View"), /* @__PURE__ */ React.createElement(Link, {
|
|
1847
|
+
to: `${location2.pathname}/${document2.node.sys.filename}`,
|
|
1848
|
+
className: "flex gap-1.5 items-center px-4 py-1.5 rounded-full border border-gray-150 transition-all ease-out duration-150 text-gray-700 hover:bg-gray-50 hover:text-blue-500"
|
|
1849
|
+
}, /* @__PURE__ */ React.createElement(BiEdit, {
|
|
1850
|
+
className: "inline-block h-5 w-auto opacity-70"
|
|
1851
|
+
}), " ", "Edit")));
|
|
1852
|
+
}))))));
|
|
1853
|
+
});
|
|
1854
|
+
});
|
|
1745
1855
|
};
|
|
1746
|
-
const useGetDocumentFields = (cms, collectionName) => {
|
|
1856
|
+
const useGetDocumentFields = (cms, collectionName, templateName) => {
|
|
1747
1857
|
const [info, setInfo] = useState({
|
|
1748
1858
|
collection: void 0,
|
|
1859
|
+
template: void 0,
|
|
1749
1860
|
fields: void 0,
|
|
1750
1861
|
mutationInfo: void 0
|
|
1751
1862
|
});
|
|
@@ -1754,10 +1865,18 @@ const useGetDocumentFields = (cms, collectionName) => {
|
|
|
1754
1865
|
const response = await cms.api.tina.request(`query { getDocumentFields }`, {});
|
|
1755
1866
|
const documentFields = response.getDocumentFields;
|
|
1756
1867
|
const collection = documentFields[collectionName].collection;
|
|
1757
|
-
const fields = documentFields[collectionName].fields;
|
|
1758
1868
|
const mutationInfo = documentFields[collectionName].mutationInfo;
|
|
1869
|
+
let fields = void 0;
|
|
1870
|
+
let template = void 0;
|
|
1871
|
+
if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
|
|
1872
|
+
template = documentFields[collectionName].templates[templateName].template;
|
|
1873
|
+
fields = documentFields[collectionName].templates[templateName].fields;
|
|
1874
|
+
} else {
|
|
1875
|
+
fields = documentFields[collectionName].fields;
|
|
1876
|
+
}
|
|
1759
1877
|
setInfo({
|
|
1760
1878
|
collection,
|
|
1879
|
+
template,
|
|
1761
1880
|
fields,
|
|
1762
1881
|
mutationInfo
|
|
1763
1882
|
});
|
|
@@ -1769,44 +1888,44 @@ const useGetDocumentFields = (cms, collectionName) => {
|
|
|
1769
1888
|
const GetDocumentFields = ({
|
|
1770
1889
|
cms,
|
|
1771
1890
|
collectionName,
|
|
1891
|
+
templateName,
|
|
1772
1892
|
children
|
|
1773
1893
|
}) => {
|
|
1774
|
-
const { collection, fields, mutationInfo } = useGetDocumentFields(cms, collectionName);
|
|
1775
|
-
if (!collection
|
|
1894
|
+
const { collection, template, fields, mutationInfo } = useGetDocumentFields(cms, collectionName, templateName);
|
|
1895
|
+
if (!collection) {
|
|
1776
1896
|
return null;
|
|
1777
1897
|
}
|
|
1778
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, children(collection, fields, mutationInfo));
|
|
1898
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children({ collection, template, fields, mutationInfo }));
|
|
1779
1899
|
};
|
|
1780
|
-
const createDocument = async (cms, collection, mutationInfo, values) => {
|
|
1900
|
+
const createDocument = async (cms, collection, template, mutationInfo, values) => {
|
|
1781
1901
|
const _a = values, { relativePath } = _a, leftover = __objRest(_a, ["relativePath"]);
|
|
1782
1902
|
const { includeCollection, includeTemplate } = mutationInfo;
|
|
1783
|
-
const params = transformDocumentIntoMutationRequestPayload(__spreadValues({
|
|
1903
|
+
const params = transformDocumentIntoMutationRequestPayload(__spreadValues(__spreadValues({
|
|
1784
1904
|
_collection: collection.name
|
|
1785
|
-
}, leftover), {
|
|
1905
|
+
}, template && { _template: template.name }), leftover), {
|
|
1786
1906
|
includeCollection,
|
|
1787
1907
|
includeTemplate
|
|
1788
1908
|
});
|
|
1789
|
-
await cms.api.tina.request(`mutation($
|
|
1790
|
-
createDocument(
|
|
1791
|
-
collection: $collection,
|
|
1909
|
+
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
1910
|
+
createDocument(
|
|
1792
1911
|
relativePath: $relativePath,
|
|
1793
1912
|
params: $params
|
|
1794
1913
|
){__typename}
|
|
1795
1914
|
}`, {
|
|
1796
1915
|
variables: {
|
|
1797
|
-
collection: collection.name,
|
|
1798
1916
|
relativePath,
|
|
1799
1917
|
params
|
|
1800
1918
|
}
|
|
1801
1919
|
});
|
|
1802
1920
|
};
|
|
1803
1921
|
const CollectionCreatePage = () => {
|
|
1804
|
-
const { collectionName } = useParams();
|
|
1922
|
+
const { collectionName, templateName } = useParams();
|
|
1805
1923
|
const history = useHistory();
|
|
1806
1924
|
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetDocumentFields, {
|
|
1807
1925
|
cms,
|
|
1808
|
-
collectionName
|
|
1809
|
-
|
|
1926
|
+
collectionName,
|
|
1927
|
+
templateName
|
|
1928
|
+
}, ({ collection, template, fields, mutationInfo }) => {
|
|
1810
1929
|
const form = new Form({
|
|
1811
1930
|
id: "create-form",
|
|
1812
1931
|
label: "form",
|
|
@@ -1821,16 +1940,17 @@ const CollectionCreatePage = () => {
|
|
|
1821
1940
|
...fields
|
|
1822
1941
|
],
|
|
1823
1942
|
onSubmit: async (values) => {
|
|
1824
|
-
await createDocument(cms, collection, mutationInfo, values);
|
|
1943
|
+
await createDocument(cms, collection, template, mutationInfo, values);
|
|
1825
1944
|
history.push(`/admin/collections/${collection.name}`);
|
|
1826
1945
|
}
|
|
1827
1946
|
});
|
|
1947
|
+
const formLabel = template ? `${collection.label} - Create New ${template.label}` : `${collection.label} - Create New`;
|
|
1828
1948
|
return /* @__PURE__ */ React.createElement("div", {
|
|
1829
1949
|
className: "w-full h-screen"
|
|
1830
1950
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
1831
1951
|
className: "flex flex-col items-center w-full flex-1"
|
|
1832
1952
|
}, /* @__PURE__ */ React.createElement(FullscreenFormBuilder, {
|
|
1833
|
-
label:
|
|
1953
|
+
label: formLabel,
|
|
1834
1954
|
form
|
|
1835
1955
|
})));
|
|
1836
1956
|
}));
|
|
@@ -1866,21 +1986,19 @@ const GetDocument = ({
|
|
|
1866
1986
|
}
|
|
1867
1987
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, children(document2));
|
|
1868
1988
|
};
|
|
1869
|
-
const updateDocument = async (cms,
|
|
1870
|
-
const { includeCollection, includeTemplate } =
|
|
1989
|
+
const updateDocument = async (cms, relativePath, mutationInfo, values) => {
|
|
1990
|
+
const { includeCollection, includeTemplate } = mutationInfo;
|
|
1871
1991
|
const params = transformDocumentIntoMutationRequestPayload(values, {
|
|
1872
1992
|
includeCollection,
|
|
1873
1993
|
includeTemplate
|
|
1874
1994
|
});
|
|
1875
|
-
await cms.api.tina.request(`mutation($
|
|
1876
|
-
updateDocument(
|
|
1877
|
-
collection: $collection,
|
|
1995
|
+
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
1996
|
+
updateDocument(
|
|
1878
1997
|
relativePath: $relativePath,
|
|
1879
1998
|
params: $params
|
|
1880
1999
|
){__typename}
|
|
1881
2000
|
}`, {
|
|
1882
2001
|
variables: {
|
|
1883
|
-
collection: collection.name,
|
|
1884
2002
|
relativePath,
|
|
1885
2003
|
params
|
|
1886
2004
|
}
|
|
@@ -1889,11 +2007,10 @@ const updateDocument = async (cms, collection, document2, relativePath, values)
|
|
|
1889
2007
|
const CollectionUpdatePage = () => {
|
|
1890
2008
|
const { collectionName, filename } = useParams();
|
|
1891
2009
|
const history = useHistory();
|
|
1892
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
2010
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetDocumentFields, {
|
|
1893
2011
|
cms,
|
|
1894
|
-
collectionName
|
|
1895
|
-
|
|
1896
|
-
}, (collection) => {
|
|
2012
|
+
collectionName
|
|
2013
|
+
}, ({ collection, mutationInfo }) => {
|
|
1897
2014
|
const relativePath = `${filename}.${collection.format}`;
|
|
1898
2015
|
return /* @__PURE__ */ React.createElement(GetDocument, {
|
|
1899
2016
|
cms,
|
|
@@ -1906,7 +2023,7 @@ const CollectionUpdatePage = () => {
|
|
|
1906
2023
|
fields: document2.form.fields,
|
|
1907
2024
|
initialValues: document2.values,
|
|
1908
2025
|
onSubmit: async (values) => {
|
|
1909
|
-
await updateDocument(cms,
|
|
2026
|
+
await updateDocument(cms, relativePath, mutationInfo, values);
|
|
1910
2027
|
history.push(`/admin/collections/${collection.name}`);
|
|
1911
2028
|
}
|
|
1912
2029
|
});
|
|
@@ -2026,6 +2143,8 @@ const TinaAdmin = () => {
|
|
|
2026
2143
|
className: "flex-1"
|
|
2027
2144
|
}, /* @__PURE__ */ React.createElement(Switch, null, /* @__PURE__ */ React.createElement(Route, {
|
|
2028
2145
|
path: `/admin/collections/:collectionName/new`
|
|
2146
|
+
}, /* @__PURE__ */ React.createElement(CollectionCreatePage, null)), /* @__PURE__ */ React.createElement(Route, {
|
|
2147
|
+
path: `/admin/collections/:collectionName/:templateName/new`
|
|
2029
2148
|
}, /* @__PURE__ */ React.createElement(CollectionCreatePage, null)), /* @__PURE__ */ React.createElement(Route, {
|
|
2030
2149
|
path: `/admin/collections/:collectionName/:filename`
|
|
2031
2150
|
}, /* @__PURE__ */ React.createElement(CollectionUpdatePage, null)), /* @__PURE__ */ React.createElement(Route, {
|
|
@@ -2034,4 +2153,11 @@ const TinaAdmin = () => {
|
|
|
2034
2153
|
path: `/admin`
|
|
2035
2154
|
}, /* @__PURE__ */ React.createElement(DashboardPage, null)))))))));
|
|
2036
2155
|
};
|
|
2037
|
-
|
|
2156
|
+
class RouteMappingPlugin {
|
|
2157
|
+
constructor(mapper) {
|
|
2158
|
+
this.__type = "tina-admin";
|
|
2159
|
+
this.name = "route-mapping";
|
|
2160
|
+
this.mapper = mapper;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
export { AuthWallInner, Client, DEFAULT_LOCAL_TINA_GQL_SERVER_URL, LocalClient, RouteMappingPlugin, TinaAdmin, TinaCMSProvider2, TinaCloudAuthWall, TinaCloudProvider, assertShape, createClient, TinaCMSProvider2 as default, getStaticPropsForTina, gql, safeAssertShape, staticRequest, useDocumentCreatorPlugin, useGraphqlForms, useTinaAuthRedirect };
|