tinacms 1.0.1 → 1.1.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.es.js CHANGED
@@ -2117,6 +2117,7 @@ const parseRefForBranchName = (ref) => {
2117
2117
  };
2118
2118
  class Client {
2119
2119
  constructor({ tokenStorage = "MEMORY", ...options }) {
2120
+ var _a, _b, _c, _d;
2120
2121
  this.events = new EventBus();
2121
2122
  this.addPendingContent = async (props) => {
2122
2123
  const mutation = `#graphql
@@ -2131,7 +2132,7 @@ mutation addPendingDocumentMutation(
2131
2132
  collection: $collection
2132
2133
  ) {
2133
2134
  ... on Document {
2134
- sys {
2135
+ _sys {
2135
2136
  relativePath
2136
2137
  path
2137
2138
  breadcrumbs
@@ -2164,6 +2165,7 @@ mutation addPendingDocumentMutation(
2164
2165
  });
2165
2166
  return parse(data.getOptimizedQuery);
2166
2167
  };
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;
2167
2169
  if (options.schema) {
2168
2170
  const enrichedSchema = new TinaSchema({
2169
2171
  version: { fullVersion: "", major: "", minor: "", patch: "" },
@@ -2221,7 +2223,7 @@ mutation addPendingDocumentMutation(
2221
2223
  }
2222
2224
  }
2223
2225
  get isLocalMode() {
2224
- return this.contentApiUrl.includes("localhost");
2226
+ return false;
2225
2227
  }
2226
2228
  setBranch(branchName) {
2227
2229
  var _a, _b, _c, _d;
@@ -2352,6 +2354,9 @@ mutation addPendingDocumentMutation(
2352
2354
  async isAuthenticated() {
2353
2355
  return !!await this.getUser();
2354
2356
  }
2357
+ async onLogout() {
2358
+ this.setToken(null);
2359
+ }
2355
2360
  async authenticate() {
2356
2361
  const token = await authenticate(this.clientId, this.frontendUrl);
2357
2362
  this.setToken(token);
@@ -2415,6 +2420,7 @@ mutation addPendingDocumentMutation(
2415
2420
  }
2416
2421
  }
2417
2422
  const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = "http://localhost:4001/graphql";
2423
+ const LOCAL_CLIENT_KEY = "tina.local.isLogedIn";
2418
2424
  class LocalClient extends Client {
2419
2425
  constructor(props) {
2420
2426
  const clientProps = {
@@ -2425,11 +2431,21 @@ class LocalClient extends Client {
2425
2431
  };
2426
2432
  super(clientProps);
2427
2433
  }
2428
- async isAuthorized() {
2434
+ get isLocalMode() {
2429
2435
  return true;
2430
2436
  }
2437
+ async onLogout() {
2438
+ localStorage.removeItem(LOCAL_CLIENT_KEY);
2439
+ }
2440
+ async authenticate() {
2441
+ localStorage.setItem(LOCAL_CLIENT_KEY, "true");
2442
+ return { access_token: "LOCAL", id_token: "LOCAL", refresh_token: "LOCAL" };
2443
+ }
2444
+ async isAuthorized() {
2445
+ return localStorage.getItem(LOCAL_CLIENT_KEY) === "true";
2446
+ }
2431
2447
  async isAuthenticated() {
2432
- return true;
2448
+ return localStorage.getItem(LOCAL_CLIENT_KEY) === "true";
2433
2449
  }
2434
2450
  }
2435
2451
  function ModalBuilder(modalProps) {
@@ -2659,6 +2675,7 @@ const AuthWallInner = ({
2659
2675
  getModalActions
2660
2676
  }) => {
2661
2677
  const client = cms.api.tina;
2678
+ const isLocal = client.isLocalMode;
2662
2679
  const [activeModal, setActiveModal] = useState(null);
2663
2680
  const [showChildren, setShowChildren] = useState(false);
2664
2681
  React.useEffect(() => {
@@ -2687,8 +2704,8 @@ const AuthWallInner = ({
2687
2704
  }
2688
2705
  }) : [];
2689
2706
  return /* @__PURE__ */ React.createElement(React.Fragment, null, activeModal === "authenticate" && /* @__PURE__ */ React.createElement(ModalBuilder, {
2690
- title: "Tina Cloud Authorization",
2691
- message: "To save edits, Tina Cloud authorization is required. On save, changes will get commited using your account.",
2707
+ title: isLocal ? "Enter into edit mode" : "Tina Cloud Authorization",
2708
+ message: isLocal ? "To save edits, enter into edit mode. On save, changes will saved to the local filesystem." : "To save edits, Tina Cloud authorization is required. On save, changes will get commited using your account.",
2692
2709
  close,
2693
2710
  actions: [
2694
2711
  ...otherModalActions,
@@ -2701,9 +2718,12 @@ const AuthWallInner = ({
2701
2718
  primary: false
2702
2719
  },
2703
2720
  {
2704
- name: "Continue to Tina Cloud",
2721
+ name: isLocal ? "Enter Edit Mode" : "Continue to Tina Cloud",
2705
2722
  action: async () => {
2706
- await client.authenticate();
2723
+ const token = await client.authenticate();
2724
+ if (typeof (client == null ? void 0 : client.onLogin) === "function") {
2725
+ await (client == null ? void 0 : client.onLogin({ token }));
2726
+ }
2707
2727
  onAuthSuccess();
2708
2728
  },
2709
2729
  primary: true
@@ -5130,7 +5150,7 @@ const CollectionListPage = () => {
5130
5150
  className: "block text-xs text-gray-400 mb-1 uppercase"
5131
5151
  }, hasTitle ? "Title" : "Filename"), /* @__PURE__ */ React.createElement("span", {
5132
5152
  className: "h-5 leading-5 block truncate"
5133
- }, subfolders && /* @__PURE__ */ React.createElement("span", {
5153
+ }, !hasTitle && subfolders && /* @__PURE__ */ React.createElement("span", {
5134
5154
  className: "text-xs text-gray-400"
5135
5155
  }, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, hasTitle ? (_a2 = document.node._sys) == null ? void 0 : _a2.title : document.node._sys.filename))))), hasTitle && /* @__PURE__ */ React.createElement("td", {
5136
5156
  className: "px-3 py-4 truncate max-w-0 "
@@ -5138,7 +5158,9 @@ const CollectionListPage = () => {
5138
5158
  className: "block text-xs text-gray-400 mb-1 uppercase"
5139
5159
  }, "Filename"), /* @__PURE__ */ React.createElement("span", {
5140
5160
  className: "h-5 leading-5 block text-sm font-medium text-gray-900 truncate"
5141
- }, document.node._sys.filename)), /* @__PURE__ */ React.createElement("td", {
5161
+ }, subfolders && /* @__PURE__ */ React.createElement("span", {
5162
+ className: "text-xs text-gray-400"
5163
+ }, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node._sys.filename))), /* @__PURE__ */ React.createElement("td", {
5142
5164
  className: "px-3 py-4 truncate w-[15%]"
5143
5165
  }, /* @__PURE__ */ React.createElement("span", {
5144
5166
  className: "block text-xs text-gray-400 mb-1 uppercase"
package/dist/index.js CHANGED
@@ -2133,6 +2133,7 @@
2133
2133
  };
2134
2134
  class Client {
2135
2135
  constructor({ tokenStorage = "MEMORY", ...options }) {
2136
+ var _a, _b, _c, _d;
2136
2137
  this.events = new toolkit.EventBus();
2137
2138
  this.addPendingContent = async (props) => {
2138
2139
  const mutation = `#graphql
@@ -2147,7 +2148,7 @@ mutation addPendingDocumentMutation(
2147
2148
  collection: $collection
2148
2149
  ) {
2149
2150
  ... on Document {
2150
- sys {
2151
+ _sys {
2151
2152
  relativePath
2152
2153
  path
2153
2154
  breadcrumbs
@@ -2180,6 +2181,7 @@ mutation addPendingDocumentMutation(
2180
2181
  });
2181
2182
  return G.parse(data.getOptimizedQuery);
2182
2183
  };
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;
2183
2185
  if (options.schema) {
2184
2186
  const enrichedSchema = new schemaTools.TinaSchema({
2185
2187
  version: { fullVersion: "", major: "", minor: "", patch: "" },
@@ -2237,7 +2239,7 @@ mutation addPendingDocumentMutation(
2237
2239
  }
2238
2240
  }
2239
2241
  get isLocalMode() {
2240
- return this.contentApiUrl.includes("localhost");
2242
+ return false;
2241
2243
  }
2242
2244
  setBranch(branchName) {
2243
2245
  var _a, _b, _c, _d;
@@ -2368,6 +2370,9 @@ mutation addPendingDocumentMutation(
2368
2370
  async isAuthenticated() {
2369
2371
  return !!await this.getUser();
2370
2372
  }
2373
+ async onLogout() {
2374
+ this.setToken(null);
2375
+ }
2371
2376
  async authenticate() {
2372
2377
  const token = await authenticate(this.clientId, this.frontendUrl);
2373
2378
  this.setToken(token);
@@ -2431,6 +2436,7 @@ mutation addPendingDocumentMutation(
2431
2436
  }
2432
2437
  }
2433
2438
  const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = "http://localhost:4001/graphql";
2439
+ const LOCAL_CLIENT_KEY = "tina.local.isLogedIn";
2434
2440
  class LocalClient extends Client {
2435
2441
  constructor(props) {
2436
2442
  const clientProps = {
@@ -2441,11 +2447,21 @@ mutation addPendingDocumentMutation(
2441
2447
  };
2442
2448
  super(clientProps);
2443
2449
  }
2444
- async isAuthorized() {
2450
+ get isLocalMode() {
2445
2451
  return true;
2446
2452
  }
2453
+ async onLogout() {
2454
+ localStorage.removeItem(LOCAL_CLIENT_KEY);
2455
+ }
2456
+ async authenticate() {
2457
+ localStorage.setItem(LOCAL_CLIENT_KEY, "true");
2458
+ return { access_token: "LOCAL", id_token: "LOCAL", refresh_token: "LOCAL" };
2459
+ }
2460
+ async isAuthorized() {
2461
+ return localStorage.getItem(LOCAL_CLIENT_KEY) === "true";
2462
+ }
2447
2463
  async isAuthenticated() {
2448
- return true;
2464
+ return localStorage.getItem(LOCAL_CLIENT_KEY) === "true";
2449
2465
  }
2450
2466
  }
2451
2467
  function ModalBuilder(modalProps) {
@@ -2675,6 +2691,7 @@ mutation addPendingDocumentMutation(
2675
2691
  getModalActions
2676
2692
  }) => {
2677
2693
  const client = cms.api.tina;
2694
+ const isLocal = client.isLocalMode;
2678
2695
  const [activeModal, setActiveModal] = React.useState(null);
2679
2696
  const [showChildren, setShowChildren] = React.useState(false);
2680
2697
  React__default["default"].useEffect(() => {
@@ -2703,8 +2720,8 @@ mutation addPendingDocumentMutation(
2703
2720
  }
2704
2721
  }) : [];
2705
2722
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, activeModal === "authenticate" && /* @__PURE__ */ React__default["default"].createElement(ModalBuilder, {
2706
- title: "Tina Cloud Authorization",
2707
- message: "To save edits, Tina Cloud authorization is required. On save, changes will get commited using your account.",
2723
+ title: isLocal ? "Enter into edit mode" : "Tina Cloud Authorization",
2724
+ message: isLocal ? "To save edits, enter into edit mode. On save, changes will saved to the local filesystem." : "To save edits, Tina Cloud authorization is required. On save, changes will get commited using your account.",
2708
2725
  close,
2709
2726
  actions: [
2710
2727
  ...otherModalActions,
@@ -2717,9 +2734,12 @@ mutation addPendingDocumentMutation(
2717
2734
  primary: false
2718
2735
  },
2719
2736
  {
2720
- name: "Continue to Tina Cloud",
2737
+ name: isLocal ? "Enter Edit Mode" : "Continue to Tina Cloud",
2721
2738
  action: async () => {
2722
- await client.authenticate();
2739
+ const token = await client.authenticate();
2740
+ if (typeof (client == null ? void 0 : client.onLogin) === "function") {
2741
+ await (client == null ? void 0 : client.onLogin({ token }));
2742
+ }
2723
2743
  onAuthSuccess();
2724
2744
  },
2725
2745
  primary: true
@@ -5146,7 +5166,7 @@ This will work when developing locally but NOT when deployed to production.
5146
5166
  className: "block text-xs text-gray-400 mb-1 uppercase"
5147
5167
  }, hasTitle ? "Title" : "Filename"), /* @__PURE__ */ React__default["default"].createElement("span", {
5148
5168
  className: "h-5 leading-5 block truncate"
5149
- }, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
5169
+ }, !hasTitle && subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
5150
5170
  className: "text-xs text-gray-400"
5151
5171
  }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, hasTitle ? (_a2 = document.node._sys) == null ? void 0 : _a2.title : document.node._sys.filename))))), hasTitle && /* @__PURE__ */ React__default["default"].createElement("td", {
5152
5172
  className: "px-3 py-4 truncate max-w-0 "
@@ -5154,7 +5174,9 @@ This will work when developing locally but NOT when deployed to production.
5154
5174
  className: "block text-xs text-gray-400 mb-1 uppercase"
5155
5175
  }, "Filename"), /* @__PURE__ */ React__default["default"].createElement("span", {
5156
5176
  className: "h-5 leading-5 block text-sm font-medium text-gray-900 truncate"
5157
- }, document.node._sys.filename)), /* @__PURE__ */ React__default["default"].createElement("td", {
5177
+ }, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
5178
+ className: "text-xs text-gray-400"
5179
+ }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node._sys.filename))), /* @__PURE__ */ React__default["default"].createElement("td", {
5158
5180
  className: "px-3 py-4 truncate w-[15%]"
5159
5181
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
5160
5182
  className: "block text-xs text-gray-400 mb-1 uppercase"
@@ -15,6 +15,9 @@ import { BranchData, EventBus } from '@tinacms/toolkit';
15
15
  import { DocumentNode, GraphQLSchema } from 'graphql';
16
16
  import gql from 'graphql-tag';
17
17
  import { TinaSchema, TinaCloudSchema } from '@tinacms/schema-tools';
18
+ export declare type OnLoginFunc = (args: {
19
+ token: TokenObject;
20
+ }) => Promise<void>;
18
21
  export declare type TinaIOConfig = {
19
22
  assetsApiUrlOverride?: string;
20
23
  frontendUrlOverride?: string;
@@ -27,10 +30,12 @@ interface ServerOptions {
27
30
  branch: string;
28
31
  customContentApiUrl?: string;
29
32
  getTokenFn?: () => Promise<TokenObject>;
33
+ onLogin?: OnLoginFunc;
30
34
  tinaioConfig?: TinaIOConfig;
31
35
  tokenStorage?: 'MEMORY' | 'LOCAL_STORAGE' | 'CUSTOM';
32
36
  }
33
37
  export declare class Client {
38
+ onLogin: OnLoginFunc;
34
39
  frontendUrl: string;
35
40
  contentApiUrl: string;
36
41
  identityApiUrl: string;
@@ -107,6 +112,7 @@ export declare class Client {
107
112
  getRefreshedToken(tokens: string): Promise<TokenObject>;
108
113
  isAuthorized(): Promise<boolean>;
109
114
  isAuthenticated(): Promise<boolean>;
115
+ onLogout(): Promise<void>;
110
116
  authenticate(): Promise<TokenObject>;
111
117
  /**
112
118
  * Wraps the normal fetch function with same API but adds the authorization header token.
@@ -127,7 +133,14 @@ export declare class LocalClient extends Client {
127
133
  constructor(props?: {
128
134
  customContentApiUrl?: string;
129
135
  schema?: TinaCloudSchema<false>;
130
- });
136
+ } & Omit<ServerOptions, 'clientId' | 'branch'>);
137
+ get isLocalMode(): boolean;
138
+ onLogout(): Promise<void>;
139
+ authenticate(): Promise<{
140
+ access_token: string;
141
+ id_token: string;
142
+ refresh_token: string;
143
+ }>;
131
144
  isAuthorized(): Promise<boolean>;
132
145
  isAuthenticated(): Promise<boolean>;
133
146
  }
package/dist/react.d.ts CHANGED
@@ -12,3 +12,15 @@ export declare function useTina<T extends object>(props: {
12
12
  export declare function useEditState(): {
13
13
  edit: boolean;
14
14
  };
15
+ /**
16
+ * Grab the field name for the given attribute
17
+ * to signal to Tina which DOM element the field
18
+ * is working with.
19
+ */
20
+ export declare const tinaField: <T extends object & {
21
+ __meta__?: {
22
+ id: string;
23
+ name?: string;
24
+ fields: Record<string, string>;
25
+ };
26
+ }>(obj: T, field?: Exclude<keyof T, "__typename" | "_sys">) => string;
package/dist/react.es.js CHANGED
@@ -31,4 +31,16 @@ function useEditState() {
31
31
  }, []);
32
32
  return { edit };
33
33
  }
34
- export { useEditState, useTina };
34
+ const tinaField = (obj, field) => {
35
+ var _a, _b, _c;
36
+ if (!field) {
37
+ return `${(_a = obj.__meta__) == null ? void 0 : _a.id}#${(_b = obj.__meta__) == null ? void 0 : _b.name}`;
38
+ }
39
+ if (obj == null ? void 0 : obj.__meta__) {
40
+ if (typeof field === "string") {
41
+ return `${(_c = obj.__meta__) == null ? void 0 : _c.id}#${obj.__meta__.fields[field]}`;
42
+ }
43
+ }
44
+ return "";
45
+ };
46
+ export { tinaField, useEditState, useTina };
package/dist/react.js CHANGED
@@ -38,6 +38,19 @@
38
38
  }, []);
39
39
  return { edit };
40
40
  }
41
+ const tinaField = (obj, field) => {
42
+ var _a, _b, _c;
43
+ if (!field) {
44
+ return `${(_a = obj.__meta__) == null ? void 0 : _a.id}#${(_b = obj.__meta__) == null ? void 0 : _b.name}`;
45
+ }
46
+ if (obj == null ? void 0 : obj.__meta__) {
47
+ if (typeof field === "string") {
48
+ return `${(_c = obj.__meta__) == null ? void 0 : _c.id}#${obj.__meta__.fields[field]}`;
49
+ }
50
+ }
51
+ return "";
52
+ };
53
+ exports2.tinaField = tinaField;
41
54
  exports2.useEditState = useEditState;
42
55
  exports2.useTina = useTina;
43
56
  Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
@@ -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
  };
@@ -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) => {
@@ -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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
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.1",
58
+ "@tinacms/schema-tools": "1.0.2",
59
59
  "@tinacms/sharedctx": "1.0.0",
60
- "@tinacms/toolkit": "1.0.1",
60
+ "@tinacms/toolkit": "1.1.0",
61
61
  "crypto-js": "^4.0.0",
62
62
  "encoding": "0.1.13",
63
63
  "fetch-ponyfill": "^7.1.0",