tinacms 1.3.3 → 1.4.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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
- export declare const TinaAdmin: ({ preview, config, schemaJson, }: {
2
+ export declare const TinaAdmin: ({ preview, Playground, config, schemaJson, }: {
3
3
  schemaJson?: any;
4
4
  preview?: (props: object) => JSX.Element;
5
+ Playground?: (props: object) => JSX.Element;
5
6
  config: object;
6
7
  }) => JSX.Element;
@@ -1,6 +1,3 @@
1
- /**
2
-
3
- */
4
1
  /// <reference types="react" />
5
2
  declare const CollectionCreatePage: () => JSX.Element;
6
3
  export default CollectionCreatePage;
package/dist/index.es.js CHANGED
@@ -4,7 +4,7 @@ export * from "@tinacms/toolkit";
4
4
  export { MdxFieldPluginExtendible } from "@tinacms/toolkit";
5
5
  import { getIntrospectionQuery, buildClientSchema, print, parse, buildSchema } from "graphql";
6
6
  import gql$1 from "graphql-tag";
7
- import { TinaSchema, addNamespaceToSchema, parseURL, resolveForm, validateSchema } from "@tinacms/schema-tools";
7
+ import { TinaSchema, addNamespaceToSchema, parseURL, resolveForm, normalizePath, validateSchema } from "@tinacms/schema-tools";
8
8
  export { NAMER, resolveForm } from "@tinacms/schema-tools";
9
9
  import React, { useState, useCallback, useEffect, Fragment, useMemo } from "react";
10
10
  import * as yup from "yup";
@@ -126,6 +126,7 @@ mutation addPendingDocumentMutation(
126
126
  });
127
127
  return parse(data.getOptimizedQuery);
128
128
  };
129
+ this.tinaGraphQLVersion = options.tinaGraphQLVersion;
129
130
  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;
130
131
  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;
131
132
  if ((_l = (_k = (_j = (_i = options.schema) == null ? void 0 : _i.config) == null ? void 0 : _j.admin) == null ? void 0 : _k.auth) == null ? void 0 : _l.logout) {
@@ -210,7 +211,7 @@ mutation addPendingDocumentMutation(
210
211
  this.frontendUrl = ((_b = this.options.tinaioConfig) == null ? void 0 : _b.frontendUrlOverride) || "https://app.tina.io";
211
212
  this.identityApiUrl = ((_c = this.options.tinaioConfig) == null ? void 0 : _c.identityApiUrlOverride) || "https://identity.tinajs.io";
212
213
  this.contentApiBase = ((_d = this.options.tinaioConfig) == null ? void 0 : _d.contentApiUrlOverride) || `https://content.tinajs.io`;
213
- this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
214
+ this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/${this.tinaGraphQLVersion}/content/${this.options.clientId}/github/${encodedBranch}`;
214
215
  }
215
216
  async request(query, { variables }) {
216
217
  const res = await fetch(this.contentApiUrl, {
@@ -462,6 +463,7 @@ class LocalClient extends Client {
462
463
  ...props,
463
464
  clientId: "",
464
465
  branch: "",
466
+ tinaGraphQLVersion: "",
465
467
  customContentApiUrl: props && props.customContentApiUrl ? props.customContentApiUrl : DEFAULT_LOCAL_TINA_GQL_SERVER_URL
466
468
  };
467
469
  super(clientProps);
@@ -533,14 +535,16 @@ const createClient = ({
533
535
  branch,
534
536
  tinaioConfig,
535
537
  schema,
536
- apiUrl
538
+ apiUrl,
539
+ tinaGraphQLVersion
537
540
  }) => {
538
541
  return isLocalClient ? new LocalClient({ customContentApiUrl: apiUrl, schema }) : new Client({
539
542
  clientId: clientId || "",
540
543
  branch: branch || "main",
541
544
  tokenStorage: "LOCAL_STORAGE",
542
545
  tinaioConfig,
543
- schema
546
+ schema,
547
+ tinaGraphQLVersion
544
548
  });
545
549
  };
546
550
  function assertShape(value, yupSchema, errorMessage) {
@@ -2302,7 +2306,8 @@ const TinaCMSProvider2 = ({
2302
2306
  cmsCallback: props.cmsCallback,
2303
2307
  mediaStore: props.mediaStore,
2304
2308
  apiUrl: apiURL,
2305
- schema: { ...schema, config: { ...schema.config, ...props } }
2309
+ schema: { ...schema, config: { ...schema.config, ...props } },
2310
+ tinaGraphQLVersion: props.tinaGraphQLVersion
2306
2311
  }, /* @__PURE__ */ React.createElement("style", null, styles), /* @__PURE__ */ React.createElement(ErrorBoundary, null, props.children)));
2307
2312
  };
2308
2313
  const Loader = (props) => {
@@ -3765,6 +3770,7 @@ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3765
3770
  description: /* @__PURE__ */ React.createElement("span", null, "A unique filename for the content.", /* @__PURE__ */ React.createElement("br", null), "Examples: ", /* @__PURE__ */ React.createElement("code", null, "My_Document"), ", ", /* @__PURE__ */ React.createElement("code", null, "My_Document.en"), ",", " ", /* @__PURE__ */ React.createElement("code", null, "sub-folder/My_Document")),
3766
3771
  placeholder: `My_Document`,
3767
3772
  validate: (value, allValues, meta) => {
3773
+ var _a3, _b3;
3768
3774
  if (!value) {
3769
3775
  if (meta.dirty) {
3770
3776
  return "Required";
@@ -3775,6 +3781,16 @@ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
3775
3781
  if (value && !isValid) {
3776
3782
  return "Must begin with a-z, A-Z, 0-9, or _ and contain only a-z, A-Z, 0-9, -, _, ., or /.";
3777
3783
  }
3784
+ if (((_a3 = schemaCollection.match) == null ? void 0 : _a3.exclude) || ((_b3 = schemaCollection.match) == null ? void 0 : _b3.include)) {
3785
+ const filePath = `${normalizePath(schemaCollection.path)}/${value}.${schemaCollection.format || "md"}`;
3786
+ const match = schema.matchFiles({
3787
+ files: [filePath],
3788
+ collection: schemaCollection
3789
+ });
3790
+ if (match.length === 0) {
3791
+ return `The filename "${value}" is not allowed for this collection.`;
3792
+ }
3793
+ }
3778
3794
  }
3779
3795
  }
3780
3796
  ],
@@ -4081,6 +4097,7 @@ const CheckSchema = ({
4081
4097
  };
4082
4098
  const TinaAdmin = ({
4083
4099
  preview,
4100
+ Playground,
4084
4101
  config,
4085
4102
  schemaJson
4086
4103
  }) => {
@@ -4113,6 +4130,9 @@ const TinaAdmin = ({
4113
4130
  config,
4114
4131
  preview
4115
4132
  })
4133
+ }), /* @__PURE__ */ React.createElement(Route, {
4134
+ path: "graphql",
4135
+ element: /* @__PURE__ */ React.createElement(PlainLayout, null, /* @__PURE__ */ React.createElement(Playground, null))
4116
4136
  }), /* @__PURE__ */ React.createElement(Route, {
4117
4137
  path: "collections/:collectionName/new",
4118
4138
  element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
@@ -4174,6 +4194,21 @@ const DefaultWrapper = ({
4174
4194
  className: "flex-1 relative"
4175
4195
  }, children)));
4176
4196
  };
4197
+ const PlainLayout = ({ children }) => {
4198
+ return /* @__PURE__ */ React.createElement("div", {
4199
+ style: {
4200
+ position: "fixed",
4201
+ top: 0,
4202
+ left: 0,
4203
+ width: "100%",
4204
+ height: "100%",
4205
+ overflow: "auto",
4206
+ background: "#F6F6F9",
4207
+ fontFamily: "'Inter', sans-serif",
4208
+ zIndex: 9999
4209
+ }
4210
+ }, children);
4211
+ };
4177
4212
  class RouteMappingPlugin {
4178
4213
  constructor(mapper) {
4179
4214
  this.__type = "tina-admin";
package/dist/index.js CHANGED
@@ -141,6 +141,7 @@ mutation addPendingDocumentMutation(
141
141
  });
142
142
  return graphql.parse(data.getOptimizedQuery);
143
143
  };
144
+ this.tinaGraphQLVersion = options.tinaGraphQLVersion;
144
145
  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;
145
146
  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;
146
147
  if ((_l = (_k = (_j = (_i = options.schema) == null ? void 0 : _i.config) == null ? void 0 : _j.admin) == null ? void 0 : _k.auth) == null ? void 0 : _l.logout) {
@@ -225,7 +226,7 @@ mutation addPendingDocumentMutation(
225
226
  this.frontendUrl = ((_b = this.options.tinaioConfig) == null ? void 0 : _b.frontendUrlOverride) || "https://app.tina.io";
226
227
  this.identityApiUrl = ((_c = this.options.tinaioConfig) == null ? void 0 : _c.identityApiUrlOverride) || "https://identity.tinajs.io";
227
228
  this.contentApiBase = ((_d = this.options.tinaioConfig) == null ? void 0 : _d.contentApiUrlOverride) || `https://content.tinajs.io`;
228
- this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
229
+ this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/${this.tinaGraphQLVersion}/content/${this.options.clientId}/github/${encodedBranch}`;
229
230
  }
230
231
  async request(query, { variables }) {
231
232
  const res = await fetch(this.contentApiUrl, {
@@ -477,6 +478,7 @@ mutation addPendingDocumentMutation(
477
478
  ...props,
478
479
  clientId: "",
479
480
  branch: "",
481
+ tinaGraphQLVersion: "",
480
482
  customContentApiUrl: props && props.customContentApiUrl ? props.customContentApiUrl : DEFAULT_LOCAL_TINA_GQL_SERVER_URL
481
483
  };
482
484
  super(clientProps);
@@ -548,14 +550,16 @@ mutation addPendingDocumentMutation(
548
550
  branch,
549
551
  tinaioConfig,
550
552
  schema,
551
- apiUrl
553
+ apiUrl,
554
+ tinaGraphQLVersion
552
555
  }) => {
553
556
  return isLocalClient ? new LocalClient({ customContentApiUrl: apiUrl, schema }) : new Client({
554
557
  clientId: clientId || "",
555
558
  branch: branch || "main",
556
559
  tokenStorage: "LOCAL_STORAGE",
557
560
  tinaioConfig,
558
- schema
561
+ schema,
562
+ tinaGraphQLVersion
559
563
  });
560
564
  };
561
565
  function assertShape(value, yupSchema, errorMessage) {
@@ -2317,7 +2321,8 @@ mutation addPendingDocumentMutation(
2317
2321
  cmsCallback: props.cmsCallback,
2318
2322
  mediaStore: props.mediaStore,
2319
2323
  apiUrl: apiURL,
2320
- schema: { ...schema, config: { ...schema.config, ...props } }
2324
+ schema: { ...schema, config: { ...schema.config, ...props } },
2325
+ tinaGraphQLVersion: props.tinaGraphQLVersion
2321
2326
  }, /* @__PURE__ */ React__default["default"].createElement("style", null, styles), /* @__PURE__ */ React__default["default"].createElement(ErrorBoundary, null, props.children)));
2322
2327
  };
2323
2328
  const Loader = (props) => {
@@ -3780,6 +3785,7 @@ This will work when developing locally but NOT when deployed to production.
3780
3785
  description: /* @__PURE__ */ React__default["default"].createElement("span", null, "A unique filename for the content.", /* @__PURE__ */ React__default["default"].createElement("br", null), "Examples: ", /* @__PURE__ */ React__default["default"].createElement("code", null, "My_Document"), ", ", /* @__PURE__ */ React__default["default"].createElement("code", null, "My_Document.en"), ",", " ", /* @__PURE__ */ React__default["default"].createElement("code", null, "sub-folder/My_Document")),
3781
3786
  placeholder: `My_Document`,
3782
3787
  validate: (value, allValues, meta) => {
3788
+ var _a3, _b3;
3783
3789
  if (!value) {
3784
3790
  if (meta.dirty) {
3785
3791
  return "Required";
@@ -3790,6 +3796,16 @@ This will work when developing locally but NOT when deployed to production.
3790
3796
  if (value && !isValid) {
3791
3797
  return "Must begin with a-z, A-Z, 0-9, or _ and contain only a-z, A-Z, 0-9, -, _, ., or /.";
3792
3798
  }
3799
+ if (((_a3 = schemaCollection.match) == null ? void 0 : _a3.exclude) || ((_b3 = schemaCollection.match) == null ? void 0 : _b3.include)) {
3800
+ const filePath = `${schemaTools.normalizePath(schemaCollection.path)}/${value}.${schemaCollection.format || "md"}`;
3801
+ const match = schema.matchFiles({
3802
+ files: [filePath],
3803
+ collection: schemaCollection
3804
+ });
3805
+ if (match.length === 0) {
3806
+ return `The filename "${value}" is not allowed for this collection.`;
3807
+ }
3808
+ }
3793
3809
  }
3794
3810
  }
3795
3811
  ],
@@ -4096,6 +4112,7 @@ This will work when developing locally but NOT when deployed to production.
4096
4112
  };
4097
4113
  const TinaAdmin = ({
4098
4114
  preview,
4115
+ Playground,
4099
4116
  config,
4100
4117
  schemaJson
4101
4118
  }) => {
@@ -4128,6 +4145,9 @@ This will work when developing locally but NOT when deployed to production.
4128
4145
  config,
4129
4146
  preview
4130
4147
  })
4148
+ }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
4149
+ path: "graphql",
4150
+ element: /* @__PURE__ */ React__default["default"].createElement(PlainLayout, null, /* @__PURE__ */ React__default["default"].createElement(Playground, null))
4131
4151
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
4132
4152
  path: "collections/:collectionName/new",
4133
4153
  element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
@@ -4189,6 +4209,21 @@ This will work when developing locally but NOT when deployed to production.
4189
4209
  className: "flex-1 relative"
4190
4210
  }, children)));
4191
4211
  };
4212
+ const PlainLayout = ({ children }) => {
4213
+ return /* @__PURE__ */ React__default["default"].createElement("div", {
4214
+ style: {
4215
+ position: "fixed",
4216
+ top: 0,
4217
+ left: 0,
4218
+ width: "100%",
4219
+ height: "100%",
4220
+ overflow: "auto",
4221
+ background: "#F6F6F9",
4222
+ fontFamily: "'Inter', sans-serif",
4223
+ zIndex: 9999
4224
+ }
4225
+ }, children);
4226
+ };
4192
4227
  class RouteMappingPlugin {
4193
4228
  constructor(mapper) {
4194
4229
  this.__type = "tina-admin";
@@ -16,6 +16,7 @@ interface ServerOptions {
16
16
  schema?: Schema;
17
17
  clientId: string;
18
18
  branch: string;
19
+ tinaGraphQLVersion: string;
19
20
  customContentApiUrl?: string;
20
21
  getTokenFn?: () => Promise<TokenObject>;
21
22
  tinaioConfig?: TinaIOConfig;
@@ -117,6 +118,7 @@ export declare class Client {
117
118
  clientId: string;
118
119
  contentApiBase: string;
119
120
  query: string;
121
+ tinaGraphQLVersion: string;
120
122
  setToken: (_token: TokenObject) => void;
121
123
  private getToken;
122
124
  private token;
@@ -226,7 +228,7 @@ export declare class LocalClient extends Client {
226
228
  constructor(props?: {
227
229
  customContentApiUrl?: string;
228
230
  schema?: Schema;
229
- } & Omit<ServerOptions, 'clientId' | 'branch'>);
231
+ } & Omit<ServerOptions, 'clientId' | 'branch' | 'tinaGraphQLVersion'>);
230
232
  get isLocalMode(): boolean;
231
233
  logout(): Promise<void>;
232
234
  authenticate(): Promise<{
@@ -51,5 +51,7 @@ declare type QueryProviderProps = {
51
51
  /** The `data` from getStaticProps */
52
52
  data?: never;
53
53
  };
54
- export declare type TinaCMSProviderDefaultProps = QueryProviderProps & APIProviderProps & BaseProviderProps & Config;
54
+ export declare type TinaCMSProviderDefaultProps = QueryProviderProps & APIProviderProps & BaseProviderProps & Config & {
55
+ tinaGraphQLVersion: string;
56
+ };
55
57
  export {};
@@ -14,7 +14,8 @@ export interface CreateClientProps {
14
14
  branch?: string;
15
15
  schema?: Schema;
16
16
  apiUrl?: string;
17
+ tinaGraphQLVersion: string;
17
18
  }
18
- export declare const createClient: ({ clientId, isLocalClient, branch, tinaioConfig, schema, apiUrl, }: CreateClientProps) => Client;
19
+ export declare const createClient: ({ clientId, isLocalClient, branch, tinaioConfig, schema, apiUrl, tinaGraphQLVersion, }: CreateClientProps) => Client;
19
20
  export declare function assertShape<T extends unknown>(value: unknown, yupSchema: (args: typeof yup) => yup.AnySchema, errorMessage?: string): asserts value is T;
20
21
  export declare function safeAssertShape<T extends unknown>(value: unknown, yupSchema: (args: typeof yup) => yup.AnySchema): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -56,9 +56,9 @@
56
56
  "@headlessui/react": "^1.5.0",
57
57
  "@heroicons/react": "^1.0.4",
58
58
  "@react-hook/window-size": "^3.0.7",
59
- "@tinacms/schema-tools": "1.3.4",
59
+ "@tinacms/schema-tools": "1.4.0",
60
60
  "@tinacms/sharedctx": "1.0.1",
61
- "@tinacms/toolkit": "1.5.2",
61
+ "@tinacms/toolkit": "1.6.0",
62
62
  "crypto-js": "^4.0.0",
63
63
  "encoding": "0.1.13",
64
64
  "fetch-ponyfill": "^7.1.0",
@@ -78,7 +78,7 @@
78
78
  "@testing-library/react": "^12.0.0",
79
79
  "@testing-library/react-hooks": "^7.0.2",
80
80
  "@testing-library/user-event": "^12.7.0",
81
- "@tinacms/scripts": "1.0.4",
81
+ "@tinacms/scripts": "1.1.0",
82
82
  "@types/jest": "^27.0.1",
83
83
  "@types/lodash": "^4.14.169",
84
84
  "@types/node": "^14.0.13",