tinacms 1.0.2 → 1.1.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.
@@ -20,7 +20,7 @@ export declare class TinaAdminApi {
20
20
  schema: TinaSchema;
21
21
  constructor(cms: TinaCMS);
22
22
  isAuthenticated(): Promise<boolean>;
23
- fetchCollections(): Promise<Collection[]>;
23
+ fetchCollections(): import("@tinacms/schema-tools").TinaCloudCollection<true>[];
24
24
  deleteDocument({ collection, relativePath, }: {
25
25
  collection: string;
26
26
  relativePath: string;
@@ -10,12 +10,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import type { Collection } from '../types';
14
13
  import type { TinaCMS } from '@tinacms/toolkit';
15
14
  export declare const useGetCollections: (cms: TinaCMS) => {
16
- collections: Collection[];
17
- loading: boolean;
18
- error: Error;
15
+ collections: import("@tinacms/schema-tools").TinaCloudCollection<true>[];
19
16
  };
20
17
  declare const GetCollections: ({ cms, children }: {
21
18
  cms: TinaCMS;
@@ -10,5 +10,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
+ export declare const LogoutRedirect: () => JSX.Element;
13
14
  declare const LogoutPage: () => JSX.Element;
14
15
  export default LogoutPage;
package/dist/index.es.js CHANGED
@@ -12,7 +12,7 @@ import gql$1 from "graphql-tag";
12
12
  import * as yup from "yup";
13
13
  import { setEditing, TinaDataContext, EditContext, useEditState } from "@tinacms/sharedctx";
14
14
  import UrlPattern from "url-pattern";
15
- import { NavLink, useNavigate, useParams, useLocation, Link, HashRouter, Routes, Route } from "react-router-dom";
15
+ import { NavLink, useSearchParams, useNavigate, useParams, useLocation, Link, HashRouter, Routes, Route } from "react-router-dom";
16
16
  import { Transition, Menu } from "@headlessui/react";
17
17
  import { useWindowWidth } from "@react-hook/window-size";
18
18
  function popupWindow(url, title, window2, w, h) {
@@ -2117,7 +2117,7 @@ const parseRefForBranchName = (ref) => {
2117
2117
  };
2118
2118
  class Client {
2119
2119
  constructor({ tokenStorage = "MEMORY", ...options }) {
2120
- var _a, _b, _c, _d;
2120
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2121
2121
  this.events = new EventBus();
2122
2122
  this.addPendingContent = async (props) => {
2123
2123
  const mutation = `#graphql
@@ -2166,6 +2166,7 @@ mutation addPendingDocumentMutation(
2166
2166
  return parse(data.getOptimizedQuery);
2167
2167
  };
2168
2168
  this.onLogin = (_d = (_c = (_b = (_a = options.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.admin) == null ? void 0 : _c.auth) == null ? void 0 : _d.onLogin;
2169
+ this.onLogout = (_h = (_g = (_f = (_e = options.schema) == null ? void 0 : _e.config) == null ? void 0 : _f.admin) == null ? void 0 : _g.auth) == null ? void 0 : _h.onLogout;
2169
2170
  if (options.schema) {
2170
2171
  const enrichedSchema = new TinaSchema({
2171
2172
  version: { fullVersion: "", major: "", minor: "", patch: "" },
@@ -2354,7 +2355,7 @@ mutation addPendingDocumentMutation(
2354
2355
  async isAuthenticated() {
2355
2356
  return !!await this.getUser();
2356
2357
  }
2357
- async onLogout() {
2358
+ async logout() {
2358
2359
  this.setToken(null);
2359
2360
  }
2360
2361
  async authenticate() {
@@ -2434,7 +2435,7 @@ class LocalClient extends Client {
2434
2435
  get isLocalMode() {
2435
2436
  return true;
2436
2437
  }
2437
- async onLogout() {
2438
+ async logout() {
2438
2439
  localStorage.removeItem(LOCAL_CLIENT_KEY);
2439
2440
  }
2440
2441
  async authenticate() {
@@ -2502,14 +2503,8 @@ class TinaAdminApi {
2502
2503
  async isAuthenticated() {
2503
2504
  return await this.api.isAuthenticated();
2504
2505
  }
2505
- async fetchCollections() {
2506
- try {
2507
- const collections = this.schema.getCollections();
2508
- return collections;
2509
- } catch (e) {
2510
- console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
2511
- return [];
2512
- }
2506
+ fetchCollections() {
2507
+ return this.schema.getCollections();
2513
2508
  }
2514
2509
  async deleteDocument({
2515
2510
  collection,
@@ -4498,28 +4493,7 @@ function ImFilesEmpty(props) {
4498
4493
  }
4499
4494
  const useGetCollections = (cms) => {
4500
4495
  const api = new TinaAdminApi(cms);
4501
- const [collections, setCollections] = useState([]);
4502
- const [loading, setLoading] = useState(true);
4503
- const [error, setError] = useState(void 0);
4504
- useEffect(() => {
4505
- const fetchCollections = async () => {
4506
- if (await api.isAuthenticated()) {
4507
- try {
4508
- const collections2 = await api.fetchCollections();
4509
- setCollections(collections2);
4510
- } catch (error2) {
4511
- console.error(error2);
4512
- setCollections([]);
4513
- setError(error2);
4514
- throw new Error(`[${error2.name}] GetCollections failed: ${error2.message}`);
4515
- }
4516
- setLoading(false);
4517
- }
4518
- };
4519
- setLoading(true);
4520
- fetchCollections();
4521
- }, [cms]);
4522
- return { collections, loading, error };
4496
+ return { collections: api.fetchCollections() };
4523
4497
  };
4524
4498
  function IoMdClose(props) {
4525
4499
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 512 512" }, "child": [{ "tag": "path", "attr": { "d": "M405 136.798L375.202 107 256 226.202 136.798 107 107 136.798 226.202 256 107 375.202 136.798 405 256 285.798 375.202 405 405 375.202 285.798 256z" } }] })(props);
@@ -4748,6 +4722,28 @@ const LoginPage = () => {
4748
4722
  className: "w-6 h-auto mr-2 opacity-80"
4749
4723
  }), " Edit With Tina")));
4750
4724
  };
4725
+ const LogoutRedirect = () => {
4726
+ const cms = useCMS();
4727
+ const { setEdit } = useEditState();
4728
+ const [searchParams] = useSearchParams();
4729
+ const slug = searchParams.get("slug") || "/";
4730
+ const logout2 = async () => {
4731
+ var _a, _b, _c, _d, _e, _f;
4732
+ if ((_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.logout) {
4733
+ await cms.api.tina.logout();
4734
+ if ((_d = (_c = cms == null ? void 0 : cms.api) == null ? void 0 : _c.tina) == null ? void 0 : _d.onLogout) {
4735
+ await ((_f = (_e = cms == null ? void 0 : cms.api) == null ? void 0 : _e.tina) == null ? void 0 : _f.onLogout());
4736
+ }
4737
+ }
4738
+ setEdit(false);
4739
+ };
4740
+ useEffect(() => {
4741
+ logout2().then(() => {
4742
+ window.location.href = slug;
4743
+ });
4744
+ }, []);
4745
+ return /* @__PURE__ */ React.createElement("div", null, "Redirecting to ", slug, " ...");
4746
+ };
4751
4747
  const logout = () => {
4752
4748
  setEditing(false);
4753
4749
  window.location.href = "/";
@@ -5711,6 +5707,11 @@ const TinaAdmin = ({
5711
5707
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5712
5708
  cms
5713
5709
  }, /* @__PURE__ */ React.createElement(ScreenPage, null))
5710
+ }), /* @__PURE__ */ React.createElement(Route, {
5711
+ path: "logout",
5712
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5713
+ cms
5714
+ }, /* @__PURE__ */ React.createElement(LogoutRedirect, null))
5714
5715
  }), /* @__PURE__ */ React.createElement(Route, {
5715
5716
  path: "/",
5716
5717
  element: /* @__PURE__ */ React.createElement(MaybeRedirectToPreview, {
package/dist/index.js CHANGED
@@ -2133,7 +2133,7 @@
2133
2133
  };
2134
2134
  class Client {
2135
2135
  constructor({ tokenStorage = "MEMORY", ...options }) {
2136
- var _a, _b, _c, _d;
2136
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2137
2137
  this.events = new toolkit.EventBus();
2138
2138
  this.addPendingContent = async (props) => {
2139
2139
  const mutation = `#graphql
@@ -2182,6 +2182,7 @@ mutation addPendingDocumentMutation(
2182
2182
  return G.parse(data.getOptimizedQuery);
2183
2183
  };
2184
2184
  this.onLogin = (_d = (_c = (_b = (_a = options.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.admin) == null ? void 0 : _c.auth) == null ? void 0 : _d.onLogin;
2185
+ this.onLogout = (_h = (_g = (_f = (_e = options.schema) == null ? void 0 : _e.config) == null ? void 0 : _f.admin) == null ? void 0 : _g.auth) == null ? void 0 : _h.onLogout;
2185
2186
  if (options.schema) {
2186
2187
  const enrichedSchema = new schemaTools.TinaSchema({
2187
2188
  version: { fullVersion: "", major: "", minor: "", patch: "" },
@@ -2370,7 +2371,7 @@ mutation addPendingDocumentMutation(
2370
2371
  async isAuthenticated() {
2371
2372
  return !!await this.getUser();
2372
2373
  }
2373
- async onLogout() {
2374
+ async logout() {
2374
2375
  this.setToken(null);
2375
2376
  }
2376
2377
  async authenticate() {
@@ -2450,7 +2451,7 @@ mutation addPendingDocumentMutation(
2450
2451
  get isLocalMode() {
2451
2452
  return true;
2452
2453
  }
2453
- async onLogout() {
2454
+ async logout() {
2454
2455
  localStorage.removeItem(LOCAL_CLIENT_KEY);
2455
2456
  }
2456
2457
  async authenticate() {
@@ -2518,14 +2519,8 @@ mutation addPendingDocumentMutation(
2518
2519
  async isAuthenticated() {
2519
2520
  return await this.api.isAuthenticated();
2520
2521
  }
2521
- async fetchCollections() {
2522
- try {
2523
- const collections = this.schema.getCollections();
2524
- return collections;
2525
- } catch (e) {
2526
- console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
2527
- return [];
2528
- }
2522
+ fetchCollections() {
2523
+ return this.schema.getCollections();
2529
2524
  }
2530
2525
  async deleteDocument({
2531
2526
  collection,
@@ -4514,28 +4509,7 @@ This will work when developing locally but NOT when deployed to production.
4514
4509
  }
4515
4510
  const useGetCollections = (cms) => {
4516
4511
  const api = new TinaAdminApi(cms);
4517
- const [collections, setCollections] = React.useState([]);
4518
- const [loading, setLoading] = React.useState(true);
4519
- const [error, setError] = React.useState(void 0);
4520
- React.useEffect(() => {
4521
- const fetchCollections = async () => {
4522
- if (await api.isAuthenticated()) {
4523
- try {
4524
- const collections2 = await api.fetchCollections();
4525
- setCollections(collections2);
4526
- } catch (error2) {
4527
- console.error(error2);
4528
- setCollections([]);
4529
- setError(error2);
4530
- throw new Error(`[${error2.name}] GetCollections failed: ${error2.message}`);
4531
- }
4532
- setLoading(false);
4533
- }
4534
- };
4535
- setLoading(true);
4536
- fetchCollections();
4537
- }, [cms]);
4538
- return { collections, loading, error };
4512
+ return { collections: api.fetchCollections() };
4539
4513
  };
4540
4514
  function IoMdClose(props) {
4541
4515
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 512 512" }, "child": [{ "tag": "path", "attr": { "d": "M405 136.798L375.202 107 256 226.202 136.798 107 107 136.798 226.202 256 107 375.202 136.798 405 256 285.798 375.202 405 405 375.202 285.798 256z" } }] })(props);
@@ -4764,6 +4738,28 @@ This will work when developing locally but NOT when deployed to production.
4764
4738
  className: "w-6 h-auto mr-2 opacity-80"
4765
4739
  }), " Edit With Tina")));
4766
4740
  };
4741
+ const LogoutRedirect = () => {
4742
+ const cms = toolkit.useCMS();
4743
+ const { setEdit } = sharedctx.useEditState();
4744
+ const [searchParams] = reactRouterDom.useSearchParams();
4745
+ const slug = searchParams.get("slug") || "/";
4746
+ const logout2 = async () => {
4747
+ var _a, _b, _c, _d, _e, _f;
4748
+ if ((_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.logout) {
4749
+ await cms.api.tina.logout();
4750
+ if ((_d = (_c = cms == null ? void 0 : cms.api) == null ? void 0 : _c.tina) == null ? void 0 : _d.onLogout) {
4751
+ await ((_f = (_e = cms == null ? void 0 : cms.api) == null ? void 0 : _e.tina) == null ? void 0 : _f.onLogout());
4752
+ }
4753
+ }
4754
+ setEdit(false);
4755
+ };
4756
+ React.useEffect(() => {
4757
+ logout2().then(() => {
4758
+ window.location.href = slug;
4759
+ });
4760
+ }, []);
4761
+ return /* @__PURE__ */ React__default["default"].createElement("div", null, "Redirecting to ", slug, " ...");
4762
+ };
4767
4763
  const logout = () => {
4768
4764
  sharedctx.setEditing(false);
4769
4765
  window.location.href = "/";
@@ -5727,6 +5723,11 @@ This will work when developing locally but NOT when deployed to production.
5727
5723
  element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5728
5724
  cms
5729
5725
  }, /* @__PURE__ */ React__default["default"].createElement(ScreenPage, null))
5726
+ }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5727
+ path: "logout",
5728
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5729
+ cms
5730
+ }, /* @__PURE__ */ React__default["default"].createElement(LogoutRedirect, null))
5730
5731
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5731
5732
  path: "/",
5732
5733
  element: /* @__PURE__ */ React__default["default"].createElement(MaybeRedirectToPreview, {
@@ -35,7 +35,8 @@ interface ServerOptions {
35
35
  tokenStorage?: 'MEMORY' | 'LOCAL_STORAGE' | 'CUSTOM';
36
36
  }
37
37
  export declare class Client {
38
- onLogin: OnLoginFunc;
38
+ onLogin?: OnLoginFunc;
39
+ onLogout?: () => Promise<void>;
39
40
  frontendUrl: string;
40
41
  contentApiUrl: string;
41
42
  identityApiUrl: string;
@@ -112,7 +113,7 @@ export declare class Client {
112
113
  getRefreshedToken(tokens: string): Promise<TokenObject>;
113
114
  isAuthorized(): Promise<boolean>;
114
115
  isAuthenticated(): Promise<boolean>;
115
- onLogout(): Promise<void>;
116
+ logout(): Promise<void>;
116
117
  authenticate(): Promise<TokenObject>;
117
118
  /**
118
119
  * Wraps the normal fetch function with same API but adds the authorization header token.
@@ -135,7 +136,7 @@ export declare class LocalClient extends Client {
135
136
  schema?: TinaCloudSchema<false>;
136
137
  } & Omit<ServerOptions, 'clientId' | 'branch'>);
137
138
  get isLocalMode(): boolean;
138
- onLogout(): Promise<void>;
139
+ logout(): Promise<void>;
139
140
  authenticate(): Promise<{
140
141
  access_token: string;
141
142
  id_token: string;
@@ -51,6 +51,9 @@ declare type BaseComponents = {
51
51
  code?: {
52
52
  children: JSX.Element;
53
53
  };
54
+ text?: {
55
+ children: string;
56
+ };
54
57
  ul?: {
55
58
  children: JSX.Element;
56
59
  };
@@ -60,6 +63,9 @@ declare type BaseComponents = {
60
63
  li?: {
61
64
  children: JSX.Element;
62
65
  };
66
+ lic?: {
67
+ children: JSX.Element;
68
+ };
63
69
  block_quote?: {
64
70
  children: JSX.Element;
65
71
  };
@@ -79,6 +79,10 @@ const Leaf = (props) => {
79
79
  ...rest
80
80
  }));
81
81
  }
82
+ if (props.components.text) {
83
+ const Component = props.components.text;
84
+ return /* @__PURE__ */ React.createElement(Component, null, props.text);
85
+ }
82
86
  return /* @__PURE__ */ React.createElement(React.Fragment, null, props.text);
83
87
  };
84
88
  const MemoNode = (props) => {
@@ -117,6 +121,15 @@ const Node = ({ components, child }) => {
117
121
  })
118
122
  });
119
123
  case "lic":
124
+ if (components.lic) {
125
+ const Component2 = components.lic;
126
+ return /* @__PURE__ */ React.createElement(Component2, {
127
+ ...props
128
+ }, /* @__PURE__ */ React.createElement(TinaMarkdown, {
129
+ components,
130
+ content: children
131
+ }));
132
+ }
120
133
  return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(TinaMarkdown, {
121
134
  components,
122
135
  content: child.children
@@ -86,6 +86,10 @@
86
86
  ...rest
87
87
  }));
88
88
  }
89
+ if (props.components.text) {
90
+ const Component = props.components.text;
91
+ return /* @__PURE__ */ React__default["default"].createElement(Component, null, props.text);
92
+ }
89
93
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, props.text);
90
94
  };
91
95
  const MemoNode = (props) => {
@@ -124,6 +128,15 @@
124
128
  })
125
129
  });
126
130
  case "lic":
131
+ if (components.lic) {
132
+ const Component2 = components.lic;
133
+ return /* @__PURE__ */ React__default["default"].createElement(Component2, {
134
+ ...props
135
+ }, /* @__PURE__ */ React__default["default"].createElement(TinaMarkdown, {
136
+ components,
137
+ content: children
138
+ }));
139
+ }
127
140
  return /* @__PURE__ */ React__default["default"].createElement("div", null, /* @__PURE__ */ React__default["default"].createElement(TinaMarkdown, {
128
141
  components,
129
142
  content: child.children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -55,9 +55,9 @@
55
55
  "@headlessui/react": "^1.5.0",
56
56
  "@heroicons/react": "^1.0.4",
57
57
  "@react-hook/window-size": "^3.0.7",
58
- "@tinacms/schema-tools": "1.0.2",
58
+ "@tinacms/schema-tools": "1.0.3",
59
59
  "@tinacms/sharedctx": "1.0.0",
60
- "@tinacms/toolkit": "1.1.0",
60
+ "@tinacms/toolkit": "1.1.1",
61
61
  "crypto-js": "^4.0.0",
62
62
  "encoding": "0.1.13",
63
63
  "fetch-ponyfill": "^7.1.0",