tinacms 0.69.2 → 0.69.5

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.
@@ -33,7 +33,10 @@ export declare const transformDocumentIntoMutationRequestPayload: (document: {
33
33
  includeCollection?: boolean;
34
34
  includeTemplate?: boolean;
35
35
  }) => any;
36
- export declare const generateFormCreators: (cms: TinaCMS, showInSidebar?: boolean) => {
36
+ export declare const generateFormCreators: (cms: TinaCMS, showInSidebar?: boolean, global?: boolean | {
37
+ icon?: any;
38
+ layout: 'fullscreen' | 'popup';
39
+ }) => {
37
40
  createForm: (formConfig: any) => Form<any, import("@tinacms/toolkit").AnyField>;
38
41
  createGlobalForm: GlobalFormCreator;
39
42
  };
package/dist/index.es.js CHANGED
@@ -436,11 +436,16 @@ const transformParams = (data) => {
436
436
  }
437
437
  }
438
438
  };
439
- const generateFormCreators = (cms, showInSidebar) => {
439
+ const generateFormCreators = (cms, showInSidebar, global) => {
440
440
  const createForm = (formConfig) => {
441
441
  const form = new Form(formConfig);
442
442
  if (showInSidebar) {
443
- cms.forms.add(form);
443
+ if (global) {
444
+ const options = typeof global === "boolean" ? [null, "fullscreen"] : [global.icon, global.layout];
445
+ cms.plugins.add(new GlobalFormPlugin(form, ...options));
446
+ } else {
447
+ cms.forms.add(form);
448
+ }
444
449
  }
445
450
  return form;
446
451
  };
@@ -520,7 +525,11 @@ const getPathToChange = (documentBlueprint, formNode, event) => {
520
525
  return accum.join(".");
521
526
  };
522
527
  const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
523
- const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
528
+ var _a;
529
+ const id = doc._internalSys.path;
530
+ const enrichedSchema = cms.api.tina.schema;
531
+ const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
532
+ const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar, (_a = collection.ui) == null ? void 0 : _a.global);
524
533
  const SKIPPED = "SKIPPED";
525
534
  let form;
526
535
  let skipped;
@@ -529,9 +538,6 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
529
538
  };
530
539
  if (skipped)
531
540
  return;
532
- const id = doc._internalSys.path;
533
- const enrichedSchema = cms.api.tina.schema;
534
- const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
535
541
  const template = enrichedSchema.getTemplateForData({
536
542
  collection,
537
543
  data: doc._values
@@ -577,13 +583,13 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
577
583
  });
578
584
  cms.alerts.success("Document saved!");
579
585
  } catch (e) {
580
- cms.alerts.error("There was a problem saving your document");
586
+ cms.alerts.error("There was a problem saving your document.");
581
587
  console.error(e);
582
588
  }
583
589
  }
584
590
  } catch (e) {
585
591
  console.error(e);
586
- cms.alerts.error("There was a problem saving your document");
592
+ cms.alerts.error("There was a problem saving your document.");
587
593
  }
588
594
  }
589
595
  };
@@ -964,14 +970,16 @@ function buildPath({
964
970
  }
965
971
  const node = G.parse(`
966
972
  query Sample {
967
- _internalSys: _sys {
968
- path
969
- relativePath
970
- collection {
971
- name
972
- }
973
- }
974
- _values
973
+ ...on Document {
974
+ _internalSys: _sys {
975
+ path
976
+ relativePath
977
+ collection {
978
+ name
979
+ }
980
+ }
981
+ _values
982
+ }
975
983
  }`);
976
984
  const metaFields = node.definitions[0].selectionSet.selections;
977
985
  const getRelativeBlueprint = (path) => {
@@ -1906,7 +1914,7 @@ const useFormify = ({
1906
1914
  }
1907
1915
  });
1908
1916
  }).catch((e) => {
1909
- cms.alerts.error(`Unexpected error fetching reference`);
1917
+ cms.alerts.error(`Unexpected error fetching reference.`);
1910
1918
  console.log(e);
1911
1919
  });
1912
1920
  }
@@ -2286,6 +2294,15 @@ mutation addPendingDocumentMutation(
2286
2294
  const jsonRes = await res.json();
2287
2295
  return jsonRes;
2288
2296
  }
2297
+ async fetchEvents(limit, cursor) {
2298
+ if (this.isLocalMode) {
2299
+ return {
2300
+ events: []
2301
+ };
2302
+ } else {
2303
+ return (await this.fetchWithToken(`${this.contentApiBase}/events/${this.clientId}/${this.branch}?limit=${limit || 1}${cursor ? `&cursor=${cursor}` : ""}`, { method: "GET" })).json();
2304
+ }
2305
+ }
2289
2306
  parseJwt(token) {
2290
2307
  const base64Url = token.split(".")[1];
2291
2308
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
@@ -4758,7 +4775,7 @@ const useGetCollection = (cms, collectionName, includeDocuments = true, after =
4758
4775
  const collection2 = await api.fetchCollection(collectionName, includeDocuments, after, validSortKey, order);
4759
4776
  setCollection(collection2);
4760
4777
  } catch (error2) {
4761
- cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
4778
+ cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`);
4762
4779
  console.error(error2);
4763
4780
  setCollection(void 0);
4764
4781
  setError(error2);
@@ -4818,10 +4835,14 @@ const TemplateMenu = ({ templates }) => {
4818
4835
  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"}`
4819
4836
  }, template.label))))))));
4820
4837
  };
4821
- const handleNavigate = (navigate, cms, collection, document) => {
4838
+ const handleNavigate = (navigate, cms, collection, collectionDefinition, document) => {
4839
+ var _a, _b;
4822
4840
  const plugins = cms.plugins.all("tina-admin");
4823
4841
  const routeMapping = plugins.find(({ name }) => name === "route-mapping");
4824
- const routeOverride = routeMapping ? routeMapping.mapper(collection, document) : void 0;
4842
+ const routeOverride = ((_a = collectionDefinition.ui) == null ? void 0 : _a.router) ? (_b = collectionDefinition.ui) == null ? void 0 : _b.router({
4843
+ document,
4844
+ collection: collectionDefinition
4845
+ }) : routeMapping ? routeMapping.mapper(collection, document) : void 0;
4825
4846
  if (routeOverride) {
4826
4847
  window.location.href = routeOverride;
4827
4848
  return null;
@@ -4866,7 +4887,8 @@ const CollectionListPage = () => {
4866
4887
  const documents = collection.documents.edges;
4867
4888
  const admin = cms.api.admin;
4868
4889
  const pageInfo = collection.documents.pageInfo;
4869
- const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime"].includes(x.type));
4890
+ const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime", "boolean"].includes(x.type));
4891
+ const collectionDefinition = cms.api.tina.schema.getCollection(collection.name);
4870
4892
  return /* @__PURE__ */ React.createElement(PageWrapper, null, /* @__PURE__ */ React.createElement(React.Fragment, null, open && /* @__PURE__ */ React.createElement(DeleteModal, {
4871
4893
  filename: vars.relativePath,
4872
4894
  deleteFunc: async () => {
@@ -4887,7 +4909,7 @@ const CollectionListPage = () => {
4887
4909
  className: "flex flex-col gap-4"
4888
4910
  }, /* @__PURE__ */ React.createElement("h3", {
4889
4911
  className: "font-sans text-2xl text-gray-700"
4890
- }, collection.label ? collection.label : collection.name), fields.length > 0 && /* @__PURE__ */ React.createElement("div", {
4912
+ }, collection.label ? collection.label : collection.name), (fields == null ? void 0 : fields.length) > 0 && /* @__PURE__ */ React.createElement("div", {
4891
4913
  className: "flex gap-2 items-center"
4892
4914
  }, /* @__PURE__ */ React.createElement("label", {
4893
4915
  htmlFor: "sort",
@@ -4957,7 +4979,7 @@ const CollectionListPage = () => {
4957
4979
  }, /* @__PURE__ */ React.createElement("a", {
4958
4980
  className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer",
4959
4981
  onClick: () => {
4960
- handleNavigate(navigate, cms, collection, document.node);
4982
+ handleNavigate(navigate, cms, collection, collectionDefinition, document.node);
4961
4983
  }
4962
4984
  }, /* @__PURE__ */ React.createElement(BiEdit, {
4963
4985
  className: "inline-block h-6 w-auto opacity-70"
@@ -5075,8 +5097,8 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
5075
5097
  if (await api.isAuthenticated()) {
5076
5098
  await api.createDocument(collection.name, relativePath, params);
5077
5099
  } else {
5078
- const authMessage = `[Error] CreateDocument failed: User is no longer authenticated; please login and try again.`;
5079
- cms.alerts.error(authMessage, 30 * 1e3);
5100
+ const authMessage = `CreateDocument failed: User is no longer authenticated; please login and try again.`;
5101
+ cms.alerts.error(authMessage);
5080
5102
  console.error(authMessage);
5081
5103
  return false;
5082
5104
  }
@@ -5192,7 +5214,7 @@ const useGetDocument = (cms, collectionName, relativePath) => {
5192
5214
  const response = await api.fetchDocument(collectionName, relativePath);
5193
5215
  setDocument(response.document);
5194
5216
  } catch (error2) {
5195
- cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
5217
+ cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`);
5196
5218
  console.error(error2);
5197
5219
  setDocument(void 0);
5198
5220
  setError(error2);
@@ -5230,8 +5252,8 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
5230
5252
  if (await api.isAuthenticated()) {
5231
5253
  await api.updateDocument(collection.name, relativePath, params);
5232
5254
  } else {
5233
- const authMessage = `[Error] UpdateDocument failed: User is no longer authenticated; please login and try again.`;
5234
- cms.alerts.error(authMessage, 30 * 1e3);
5255
+ const authMessage = `UpdateDocument failed: User is no longer authenticated; please login and try again.`;
5256
+ cms.alerts.error(authMessage);
5235
5257
  console.error(authMessage);
5236
5258
  return false;
5237
5259
  }
package/dist/index.js CHANGED
@@ -454,11 +454,16 @@
454
454
  }
455
455
  }
456
456
  };
457
- const generateFormCreators = (cms, showInSidebar) => {
457
+ const generateFormCreators = (cms, showInSidebar, global) => {
458
458
  const createForm = (formConfig) => {
459
459
  const form = new toolkit.Form(formConfig);
460
460
  if (showInSidebar) {
461
- cms.forms.add(form);
461
+ if (global) {
462
+ const options = typeof global === "boolean" ? [null, "fullscreen"] : [global.icon, global.layout];
463
+ cms.plugins.add(new toolkit.GlobalFormPlugin(form, ...options));
464
+ } else {
465
+ cms.forms.add(form);
466
+ }
462
467
  }
463
468
  return form;
464
469
  };
@@ -538,7 +543,11 @@
538
543
  return accum.join(".");
539
544
  };
540
545
  const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
541
- const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
546
+ var _a;
547
+ const id = doc._internalSys.path;
548
+ const enrichedSchema = cms.api.tina.schema;
549
+ const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
550
+ const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar, (_a = collection.ui) == null ? void 0 : _a.global);
542
551
  const SKIPPED = "SKIPPED";
543
552
  let form;
544
553
  let skipped;
@@ -547,9 +556,6 @@
547
556
  };
548
557
  if (skipped)
549
558
  return;
550
- const id = doc._internalSys.path;
551
- const enrichedSchema = cms.api.tina.schema;
552
- const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
553
559
  const template = enrichedSchema.getTemplateForData({
554
560
  collection,
555
561
  data: doc._values
@@ -595,13 +601,13 @@
595
601
  });
596
602
  cms.alerts.success("Document saved!");
597
603
  } catch (e) {
598
- cms.alerts.error("There was a problem saving your document");
604
+ cms.alerts.error("There was a problem saving your document.");
599
605
  console.error(e);
600
606
  }
601
607
  }
602
608
  } catch (e) {
603
609
  console.error(e);
604
- cms.alerts.error("There was a problem saving your document");
610
+ cms.alerts.error("There was a problem saving your document.");
605
611
  }
606
612
  }
607
613
  };
@@ -982,14 +988,16 @@
982
988
  }
983
989
  const node = G__namespace.parse(`
984
990
  query Sample {
985
- _internalSys: _sys {
986
- path
987
- relativePath
988
- collection {
989
- name
990
- }
991
- }
992
- _values
991
+ ...on Document {
992
+ _internalSys: _sys {
993
+ path
994
+ relativePath
995
+ collection {
996
+ name
997
+ }
998
+ }
999
+ _values
1000
+ }
993
1001
  }`);
994
1002
  const metaFields = node.definitions[0].selectionSet.selections;
995
1003
  const getRelativeBlueprint = (path) => {
@@ -1924,7 +1932,7 @@
1924
1932
  }
1925
1933
  });
1926
1934
  }).catch((e) => {
1927
- cms.alerts.error(`Unexpected error fetching reference`);
1935
+ cms.alerts.error(`Unexpected error fetching reference.`);
1928
1936
  console.log(e);
1929
1937
  });
1930
1938
  }
@@ -2304,6 +2312,15 @@ mutation addPendingDocumentMutation(
2304
2312
  const jsonRes = await res.json();
2305
2313
  return jsonRes;
2306
2314
  }
2315
+ async fetchEvents(limit, cursor) {
2316
+ if (this.isLocalMode) {
2317
+ return {
2318
+ events: []
2319
+ };
2320
+ } else {
2321
+ return (await this.fetchWithToken(`${this.contentApiBase}/events/${this.clientId}/${this.branch}?limit=${limit || 1}${cursor ? `&cursor=${cursor}` : ""}`, { method: "GET" })).json();
2322
+ }
2323
+ }
2307
2324
  parseJwt(token) {
2308
2325
  const base64Url = token.split(".")[1];
2309
2326
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
@@ -4776,7 +4793,7 @@ This will work when developing locally but NOT when deployed to production.
4776
4793
  const collection2 = await api.fetchCollection(collectionName, includeDocuments, after, validSortKey, order);
4777
4794
  setCollection(collection2);
4778
4795
  } catch (error2) {
4779
- cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
4796
+ cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`);
4780
4797
  console.error(error2);
4781
4798
  setCollection(void 0);
4782
4799
  setError(error2);
@@ -4836,10 +4853,14 @@ This will work when developing locally but NOT when deployed to production.
4836
4853
  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"}`
4837
4854
  }, template.label))))))));
4838
4855
  };
4839
- const handleNavigate = (navigate, cms, collection, document) => {
4856
+ const handleNavigate = (navigate, cms, collection, collectionDefinition, document) => {
4857
+ var _a, _b;
4840
4858
  const plugins = cms.plugins.all("tina-admin");
4841
4859
  const routeMapping = plugins.find(({ name }) => name === "route-mapping");
4842
- const routeOverride = routeMapping ? routeMapping.mapper(collection, document) : void 0;
4860
+ const routeOverride = ((_a = collectionDefinition.ui) == null ? void 0 : _a.router) ? (_b = collectionDefinition.ui) == null ? void 0 : _b.router({
4861
+ document,
4862
+ collection: collectionDefinition
4863
+ }) : routeMapping ? routeMapping.mapper(collection, document) : void 0;
4843
4864
  if (routeOverride) {
4844
4865
  window.location.href = routeOverride;
4845
4866
  return null;
@@ -4884,7 +4905,8 @@ This will work when developing locally but NOT when deployed to production.
4884
4905
  const documents = collection.documents.edges;
4885
4906
  const admin = cms.api.admin;
4886
4907
  const pageInfo = collection.documents.pageInfo;
4887
- const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime"].includes(x.type));
4908
+ const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime", "boolean"].includes(x.type));
4909
+ const collectionDefinition = cms.api.tina.schema.getCollection(collection.name);
4888
4910
  return /* @__PURE__ */ React__default["default"].createElement(PageWrapper, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, open && /* @__PURE__ */ React__default["default"].createElement(DeleteModal, {
4889
4911
  filename: vars.relativePath,
4890
4912
  deleteFunc: async () => {
@@ -4905,7 +4927,7 @@ This will work when developing locally but NOT when deployed to production.
4905
4927
  className: "flex flex-col gap-4"
4906
4928
  }, /* @__PURE__ */ React__default["default"].createElement("h3", {
4907
4929
  className: "font-sans text-2xl text-gray-700"
4908
- }, collection.label ? collection.label : collection.name), fields.length > 0 && /* @__PURE__ */ React__default["default"].createElement("div", {
4930
+ }, collection.label ? collection.label : collection.name), (fields == null ? void 0 : fields.length) > 0 && /* @__PURE__ */ React__default["default"].createElement("div", {
4909
4931
  className: "flex gap-2 items-center"
4910
4932
  }, /* @__PURE__ */ React__default["default"].createElement("label", {
4911
4933
  htmlFor: "sort",
@@ -4975,7 +4997,7 @@ This will work when developing locally but NOT when deployed to production.
4975
4997
  }, /* @__PURE__ */ React__default["default"].createElement("a", {
4976
4998
  className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer",
4977
4999
  onClick: () => {
4978
- handleNavigate(navigate, cms, collection, document.node);
5000
+ handleNavigate(navigate, cms, collection, collectionDefinition, document.node);
4979
5001
  }
4980
5002
  }, /* @__PURE__ */ React__default["default"].createElement(BiEdit, {
4981
5003
  className: "inline-block h-6 w-auto opacity-70"
@@ -5093,8 +5115,8 @@ This will work when developing locally but NOT when deployed to production.
5093
5115
  if (await api.isAuthenticated()) {
5094
5116
  await api.createDocument(collection.name, relativePath, params);
5095
5117
  } else {
5096
- const authMessage = `[Error] CreateDocument failed: User is no longer authenticated; please login and try again.`;
5097
- cms.alerts.error(authMessage, 30 * 1e3);
5118
+ const authMessage = `CreateDocument failed: User is no longer authenticated; please login and try again.`;
5119
+ cms.alerts.error(authMessage);
5098
5120
  console.error(authMessage);
5099
5121
  return false;
5100
5122
  }
@@ -5210,7 +5232,7 @@ This will work when developing locally but NOT when deployed to production.
5210
5232
  const response = await api.fetchDocument(collectionName, relativePath);
5211
5233
  setDocument(response.document);
5212
5234
  } catch (error2) {
5213
- cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
5235
+ cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`);
5214
5236
  console.error(error2);
5215
5237
  setDocument(void 0);
5216
5238
  setError(error2);
@@ -5248,8 +5270,8 @@ This will work when developing locally but NOT when deployed to production.
5248
5270
  if (await api.isAuthenticated()) {
5249
5271
  await api.updateDocument(collection.name, relativePath, params);
5250
5272
  } else {
5251
- const authMessage = `[Error] UpdateDocument failed: User is no longer authenticated; please login and try again.`;
5252
- cms.alerts.error(authMessage, 30 * 1e3);
5273
+ const authMessage = `UpdateDocument failed: User is no longer authenticated; please login and try again.`;
5274
+ cms.alerts.error(authMessage);
5253
5275
  console.error(authMessage);
5254
5276
  return false;
5255
5277
  }
@@ -93,6 +93,16 @@ export declare class Client {
93
93
  }): Promise<{
94
94
  assetsSyncing: string[];
95
95
  }>;
96
+ fetchEvents(limit?: number, cursor?: string): Promise<{
97
+ events: {
98
+ message: string;
99
+ timestamp: number;
100
+ id: string;
101
+ isError: boolean;
102
+ isGlobal: boolean;
103
+ }[];
104
+ cursor?: string;
105
+ }>;
96
106
  parseJwt(token: any): any;
97
107
  getRefreshedToken(tokens: string): Promise<TokenObject>;
98
108
  isAuthorized(): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "0.69.2",
3
+ "version": "0.69.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -48,9 +48,9 @@
48
48
  "@headlessui/react": "^1.5.0",
49
49
  "@heroicons/react": "^1.0.4",
50
50
  "@react-hook/window-size": "^3.0.7",
51
- "@tinacms/schema-tools": "0.1.0",
51
+ "@tinacms/schema-tools": "0.1.1",
52
52
  "@tinacms/sharedctx": "0.1.2",
53
- "@tinacms/toolkit": "0.57.1",
53
+ "@tinacms/toolkit": "0.57.3",
54
54
  "crypto-js": "^4.0.0",
55
55
  "fetch-ponyfill": "^7.1.0",
56
56
  "final-form": "4.20.1",