tinacms 0.60.2 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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("@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) {
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("url-pattern"), 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", "url-pattern", "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, global.NOOP));
34
+ })(this, function(exports2, toolkit, graphql, set, gql$1, React, styled, yup, sharedctx, finalForm, UrlPattern, reactRouterDom, react) {
35
35
  "use strict";
36
36
  function _interopDefaultLegacy(e) {
37
37
  return e && typeof e === "object" && "default" in e ? e : { "default": e };
@@ -61,6 +61,7 @@ var __objRest = (source, exclude) => {
61
61
  var React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
62
62
  var styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
63
63
  var yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
64
+ var UrlPattern__default = /* @__PURE__ */ _interopDefaultLegacy(UrlPattern);
64
65
  function popupWindow(url, title, window2, w, h) {
65
66
  const y = window2.top.outerHeight / 2 + window2.top.screenY - h / 2;
66
67
  const x = window2.top.outerWidth / 2 + window2.top.screenX - w / 2;
@@ -394,6 +395,11 @@ var __objRest = (source, exclude) => {
394
395
  throw new Error(`Expected an instance of GraphQLUnionType for type ${type.name}`);
395
396
  }
396
397
  }
398
+ const captureBranchName = /^refs\/heads\/(.*)/;
399
+ const parseRefForBranchName = (ref) => {
400
+ const matches = ref.match(captureBranchName);
401
+ return matches[1];
402
+ };
397
403
  class Client {
398
404
  constructor(_a) {
399
405
  var _b = _a, { tokenStorage = "MEMORY" } = _b, options = __objRest(_b, ["tokenStorage"]);
@@ -484,6 +490,9 @@ mutation addPendingDocumentMutation(
484
490
  break;
485
491
  }
486
492
  }
493
+ get isLocalMode() {
494
+ return this.contentApiUrl.includes("localhost");
495
+ }
487
496
  setBranch(branchName) {
488
497
  var _a, _b, _c;
489
498
  const encodedBranch = encodeURIComponent(branchName);
@@ -611,15 +620,15 @@ mutation addPendingDocumentMutation(
611
620
  try {
612
621
  const res = await this.fetchWithToken(url, {
613
622
  method: "POST",
614
- body: {
623
+ body: JSON.stringify({
615
624
  baseBranch,
616
625
  branchName
617
- },
626
+ }),
618
627
  headers: {
619
628
  "Content-Type": "application/json"
620
629
  }
621
630
  });
622
- return JSON.stringify(res);
631
+ return await res.json().then((r) => parseRefForBranchName(r.data.ref));
623
632
  } catch (error) {
624
633
  console.error("There was an error creating a new branch.", error);
625
634
  return null;
@@ -1390,7 +1399,7 @@ mutation addPendingDocumentMutation(
1390
1399
  }));
1391
1400
  };
1392
1401
  run();
1393
- }, [cms, values == null ? void 0 : values.collection]);
1402
+ }, [cms]);
1394
1403
  React__default["default"].useEffect(() => {
1395
1404
  if (plugin) {
1396
1405
  cms.plugins.add(plugin);
@@ -1402,6 +1411,18 @@ mutation addPendingDocumentMutation(
1402
1411
  };
1403
1412
  }, [plugin]);
1404
1413
  };
1414
+ const errorButtonStyles = {
1415
+ background: "#eb6337",
1416
+ padding: "12px 18px",
1417
+ cursor: "pointer",
1418
+ borderRadius: "50px",
1419
+ textTransform: "uppercase",
1420
+ letterSpacing: "2px",
1421
+ fontWeight: "bold",
1422
+ border: "none",
1423
+ color: "white",
1424
+ margin: "1rem 0"
1425
+ };
1405
1426
  const SetupHooks = (props) => {
1406
1427
  const cms = toolkit.useCMS();
1407
1428
  const [payload, isLoading] = useGraphqlForms({
@@ -1431,6 +1452,8 @@ mutation addPendingDocumentMutation(
1431
1452
  return { hasError: true, message: error.message };
1432
1453
  }
1433
1454
  render() {
1455
+ const branchData = window.localStorage.getItem("tinacms-current-branch");
1456
+ const hasBranchData = branchData && branchData.length > 0;
1434
1457
  if (this.state.hasError && !this.state.pageRefresh) {
1435
1458
  return /* @__PURE__ */ React__default["default"].createElement("div", {
1436
1459
  style: {
@@ -1451,25 +1474,21 @@ mutation addPendingDocumentMutation(
1451
1474
  }
1452
1475
  }, /* @__PURE__ */ React__default["default"].createElement("h3", {
1453
1476
  style: { color: "#eb6337" }
1454
- }, "TinaCMS Render Error"), /* @__PURE__ */ React__default["default"].createElement("p", null, "Tina caught an error while updating the page:"), /* @__PURE__ */ React__default["default"].createElement("pre", null, this.state.message), /* @__PURE__ */ React__default["default"].createElement("br", null), /* @__PURE__ */ React__default["default"].createElement("p", null, `If you've just updated the form, undo your most recent changes and click "refresh". If after a few refreshes, you're still encountering this error. There is a bigger issue with the site. Please reach out to your site admin.`), /* @__PURE__ */ React__default["default"].createElement("div", {
1455
- style: { padding: "10px 0" }
1456
- }, /* @__PURE__ */ React__default["default"].createElement("button", {
1457
- style: {
1458
- background: "#eb6337",
1459
- padding: "12px 18px",
1460
- cursor: "pointer",
1461
- borderRadius: "50px",
1462
- textTransform: "uppercase",
1463
- letterSpacing: "2px",
1464
- fontWeight: "bold",
1465
- border: "none",
1466
- color: "white"
1467
- },
1477
+ }, "TinaCMS Render Error"), /* @__PURE__ */ React__default["default"].createElement("p", null, "Tina caught an error while updating the page:"), /* @__PURE__ */ React__default["default"].createElement("pre", {
1478
+ style: { marginTop: "1rem", overflowX: "auto" }
1479
+ }, this.state.message), /* @__PURE__ */ React__default["default"].createElement("br", null), /* @__PURE__ */ React__default["default"].createElement("p", null, `If you've just updated the form, undo your most recent changes and click "refresh". If after a few refreshes, you're still encountering this error. There is a bigger issue with the site. Please reach out to your site admin.`), /* @__PURE__ */ React__default["default"].createElement("button", {
1480
+ style: errorButtonStyles,
1468
1481
  onClick: () => {
1469
1482
  this.setState({ pageRefresh: true });
1470
1483
  setTimeout(() => this.setState({ hasError: false, pageRefresh: false }), 3e3);
1471
1484
  }
1472
- }, "Refresh"))));
1485
+ }, "Refresh"), hasBranchData && /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("p", null, `If you're using the branch switcher, you may currently be on a "stale" branch that has been deleted or whose content is not compatible with the latest version of the site's layout. Click the button below to switch back to the default branch for this deployment.`), /* @__PURE__ */ React__default["default"].createElement("button", {
1486
+ style: errorButtonStyles,
1487
+ onClick: () => {
1488
+ window.localStorage.removeItem("tinacms-current-branch");
1489
+ window.location.reload();
1490
+ }
1491
+ }, "Switch to default branch"))));
1473
1492
  }
1474
1493
  if (this.state.pageRefresh) {
1475
1494
  return /* @__PURE__ */ React__default["default"].createElement(Loader, null, "Let's try that again.");
@@ -1477,20 +1496,29 @@ mutation addPendingDocumentMutation(
1477
1496
  return this.props.children;
1478
1497
  }
1479
1498
  }
1499
+ const parseURL = (url) => {
1500
+ if (url.includes("localhost")) {
1501
+ return { branch: null, isLocalClient: true, clientId: null };
1502
+ }
1503
+ const tinaHost = "content.tinajs.io";
1504
+ const params = new URL(url);
1505
+ const pattern = new UrlPattern__default["default"]("/content/:clientId/github/:branch");
1506
+ const result = pattern.match(params.pathname);
1507
+ if (params.host !== tinaHost) {
1508
+ throw new Error(`The only supported hosts are ${tinaHost} or localhost, but received ${params.host}.`);
1509
+ }
1510
+ return __spreadProps(__spreadValues({}, result), {
1511
+ isLocalClient: false
1512
+ });
1513
+ };
1480
1514
  const TinaCMSProvider2 = (_c) => {
1481
1515
  var _d = _c, {
1482
1516
  children,
1483
- branch,
1484
- clientId,
1485
- isLocalClient,
1486
1517
  cmsCallback,
1487
1518
  mediaStore,
1488
1519
  tinaioConfig
1489
1520
  } = _d, props = __objRest(_d, [
1490
1521
  "children",
1491
- "branch",
1492
- "clientId",
1493
- "isLocalClient",
1494
1522
  "cmsCallback",
1495
1523
  "mediaStore",
1496
1524
  "tinaioConfig"
@@ -1498,6 +1526,14 @@ mutation addPendingDocumentMutation(
1498
1526
  if (typeof props.query === "string") {
1499
1527
  props.query;
1500
1528
  }
1529
+ if (!props.apiURL && !((props == null ? void 0 : props.clientId) || (props == null ? void 0 : props.isLocalClient))) {
1530
+ throw new Error(`apiURL is a required field`);
1531
+ }
1532
+ const { branch, clientId, isLocalClient } = props.apiURL ? parseURL(props.apiURL) : {
1533
+ branch: props.branch,
1534
+ clientId: props.clientId,
1535
+ isLocalClient: props.isLocalClient
1536
+ };
1501
1537
  return /* @__PURE__ */ React__default["default"].createElement(TinaCloudProvider, {
1502
1538
  branch,
1503
1539
  clientId,
@@ -1639,10 +1675,10 @@ mutation addPendingDocumentMutation(
1639
1675
  if (!is_server()) {
1640
1676
  console.warn(`Whoops! Looks like you are using \`staticRequest\` in the browser to fetch data.
1641
1677
 
1642
- The local server is not available outside of \`getStaticProps\` or \`getStaticPaths\` functions.
1678
+ The local server is not available outside of \`getStaticProps\` or \`getStaticPaths\` functions.
1643
1679
  This function should only be called on the server at build time.
1644
1680
 
1645
- This will work when developing locally but NOT when deployed to production.
1681
+ This will work when developing locally but NOT when deployed to production.
1646
1682
  `);
1647
1683
  }
1648
1684
  return client.request(query, { variables });
@@ -1786,7 +1822,7 @@ This will work when developing locally but NOT when deployed to production.
1786
1822
  return /* @__PURE__ */ React__default["default"].createElement("div", {
1787
1823
  className: "h-screen w-full bg-gradient-to-b from-blue-900 to-gray-900 flex items-center justify-center px-4 py-6"
1788
1824
  }, /* @__PURE__ */ React__default["default"].createElement("div", {
1789
- className: "bg-white rounded-lg overflow-hidden shadow-lg w-full max-w-md"
1825
+ className: "bg-white rounded-lg overflow-hidden shadow-lg w-full max-w-lg"
1790
1826
  }, /* @__PURE__ */ React__default["default"].createElement("div", {
1791
1827
  className: "px-5 py-4 border-b border-gray-150"
1792
1828
  }, /* @__PURE__ */ React__default["default"].createElement("h2", {
@@ -1811,9 +1847,7 @@ This will work when developing locally but NOT when deployed to production.
1811
1847
  const LoginPage = () => {
1812
1848
  const { setEdit } = sharedctx.useEditState();
1813
1849
  const login = () => setEdit(true);
1814
- return /* @__PURE__ */ React__default["default"].createElement(AuthTemplate, {
1815
- message: "Please log in to Tina Cloud to access your content."
1816
- }, /* @__PURE__ */ React__default["default"].createElement("a", {
1850
+ return /* @__PURE__ */ React__default["default"].createElement(AuthTemplate, null, /* @__PURE__ */ React__default["default"].createElement("a", {
1817
1851
  href: "/",
1818
1852
  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"
1819
1853
  }, /* @__PURE__ */ React__default["default"].createElement(MdOutlineArrowBack, {
@@ -1825,7 +1859,7 @@ This will work when developing locally but NOT when deployed to production.
1825
1859
  style: { background: "#0084FF" }
1826
1860
  }, /* @__PURE__ */ React__default["default"].createElement(BiLogIn, {
1827
1861
  className: "w-6 h-auto mr-1.5 opacity-80"
1828
- }), " Log in"));
1862
+ }), " Enter edit-mode"));
1829
1863
  };
1830
1864
  const logout = () => {
1831
1865
  sharedctx.setEditing(false);
@@ -1993,11 +2027,11 @@ This will work when developing locally but NOT when deployed to production.
1993
2027
  className: "block text-xs mb-0.5 text-gray-400 uppercase"
1994
2028
  }, "Filename"), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Link, {
1995
2029
  to: `${location2.pathname}/${document2.node.sys.filename}`,
1996
- className: "h-5 leading-5 block"
2030
+ className: "h-5 leading-5 flex max-w-xs"
1997
2031
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
1998
- className: "leading-5 font-medium text-base overflow-ellipsis overflow-hidden whitespace-nowrap text-gray-700"
2032
+ className: "flex-shrink-1 leading-5 font-medium text-base overflow-ellipsis overflow-hidden whitespace-nowrap text-gray-700"
1999
2033
  }, document2.node.sys.filename), /* @__PURE__ */ React__default["default"].createElement("span", {
2000
- className: "leading-5 text-base font-medium text-gray-300"
2034
+ className: "flex-shrink-0 leading-5 text-base font-medium text-gray-300"
2001
2035
  }, document2.node.sys.extension))), /* @__PURE__ */ React__default["default"].createElement("td", {
2002
2036
  className: "px-5 py-3 whitespace-nowrap"
2003
2037
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
@@ -1 +1,118 @@
1
- export * from "../src/rich-text"
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ declare type BaseComponents = {
14
+ h1?: {
15
+ children: JSX.Element;
16
+ };
17
+ h2?: {
18
+ children: JSX.Element;
19
+ };
20
+ h3?: {
21
+ children: JSX.Element;
22
+ };
23
+ h4?: {
24
+ children: JSX.Element;
25
+ };
26
+ h5?: {
27
+ children: JSX.Element;
28
+ };
29
+ h6?: {
30
+ children: JSX.Element;
31
+ };
32
+ p?: {
33
+ children: JSX.Element;
34
+ };
35
+ a?: {
36
+ url: string;
37
+ children: JSX.Element;
38
+ };
39
+ italic?: {
40
+ children: JSX.Element;
41
+ };
42
+ bold?: {
43
+ children: JSX.Element;
44
+ };
45
+ strikethrough?: {
46
+ children: JSX.Element;
47
+ };
48
+ underline?: {
49
+ children: JSX.Element;
50
+ };
51
+ code?: {
52
+ children: JSX.Element;
53
+ };
54
+ ul?: {
55
+ children: JSX.Element;
56
+ };
57
+ ol?: {
58
+ children: JSX.Element;
59
+ };
60
+ block_quote?: {
61
+ children: JSX.Element;
62
+ };
63
+ code_block?: {
64
+ language?: string;
65
+ children: JSX.Element;
66
+ };
67
+ img?: {
68
+ url: string;
69
+ caption?: string;
70
+ alt?: string;
71
+ };
72
+ hr?: {};
73
+ component_missing?: {
74
+ name: string;
75
+ };
76
+ };
77
+ declare type BaseComponentSignature = {
78
+ [BK in keyof BaseComponents]: (props: BaseComponents[BK]) => JSX.Element;
79
+ };
80
+ /**
81
+ * Define the allowed components and their props
82
+ * ```ts
83
+ * const components:
84
+ * Components<{
85
+ * BlockQuote: {
86
+ * children: TinaMarkdownContent;
87
+ * authorName: string;
88
+ * };
89
+ * }> = {
90
+ * BlockQuote: (props: {
91
+ * children: TinaMarkdownContent;
92
+ * authorName: string;
93
+ * }) => {
94
+ * return (
95
+ * <div>
96
+ * <blockquote>
97
+ * <TinaMarkdown content={props.children} />
98
+ * {props.authorName}
99
+ * </blockquote>
100
+ * </div>
101
+ * );
102
+ * }
103
+ * }
104
+ * }
105
+ * ```
106
+ */
107
+ export declare type Components<ComponentAndProps extends object> = {
108
+ [K in keyof ComponentAndProps]: (props: ComponentAndProps[K]) => JSX.Element;
109
+ } & BaseComponentSignature;
110
+ export declare type TinaMarkdownContent = {
111
+ type: string;
112
+ children: TinaMarkdownContent[];
113
+ };
114
+ export declare const TinaMarkdown: ({ content, components, }: {
115
+ content: TinaMarkdownContent | TinaMarkdownContent[];
116
+ components?: Components<{}>;
117
+ }) => JSX.Element;
118
+ export {};