tinacms 0.69.4 → 0.69.7

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.
@@ -10,4 +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 TinaAdmin: () => JSX.Element;
13
+ export declare const TinaAdmin: ({ preview }: {
14
+ preview?: JSX.Element;
15
+ }) => JSX.Element;
@@ -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.d.ts CHANGED
@@ -20,11 +20,13 @@ export * from '@tinacms/toolkit';
20
20
  export { TinaAdmin } from './admin';
21
21
  export { RouteMappingPlugin } from './admin/plugins/route-mapping';
22
22
  export { TinaAdminApi } from './admin/api';
23
- import { TinaCMSProvider2 } from './tina-cms';
23
+ import { TinaCMSProvider2, DocumentCreatorCallback } from './tina-cms';
24
24
  import type { TinaCMSProviderDefaultProps } from './types/cms';
25
25
  export type { TinaCMSProviderDefaultProps };
26
26
  export default TinaCMSProvider2;
27
- import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from '@tinacms/schema-tools';
27
+ import { TinaCMS } from '@tinacms/toolkit';
28
+ import { formifyCallback } from './hooks/use-graphql-forms';
29
+ import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase, TinaCMSConfig } from '@tinacms/schema-tools';
28
30
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
29
31
  export declare type TinaCloudCollection = TinaCloudCollectionBase<false>;
30
32
  export declare type TinaCollection = TinaCloudCollectionBase<false>;
@@ -32,3 +34,4 @@ export declare type TinaField = TinaFieldBase;
32
34
  export type { TinaTemplate };
33
35
  export declare const defineSchema: (config: TinaCloudSchema) => TinaCloudSchema;
34
36
  export declare const defineConfig: (config: Omit<TinaCMSProviderDefaultProps, 'children'>) => Omit<TinaCMSProviderDefaultProps, "children">;
37
+ export declare const defineStaticConfig: (config: TinaCMSConfig<(cms: TinaCMS) => TinaCMS, formifyCallback, import("./hooks/use-content-creator").DocumentCreatorArgs, undefined>) => TinaCMSConfig<(cms: TinaCMS) => TinaCMS, formifyCallback, import("./hooks/use-content-creator").DocumentCreatorArgs, undefined>;
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
@@ -2288,6 +2294,15 @@ mutation addPendingDocumentMutation(
2288
2294
  const jsonRes = await res.json();
2289
2295
  return jsonRes;
2290
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
+ }
2291
2306
  parseJwt(token) {
2292
2307
  const base64Url = token.split(".")[1];
2293
2308
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
@@ -2780,7 +2795,7 @@ const TinaCloudProvider = (props) => {
2780
2795
  })));
2781
2796
  };
2782
2797
  const TinaCloudAuthWall = TinaCloudProvider;
2783
- var styles = /* @__PURE__ */ (() => `.tina-tailwind {
2798
+ var styles = `.tina-tailwind {
2784
2799
  line-height: 1.5;
2785
2800
  -webkit-text-size-adjust: 100%;
2786
2801
  -moz-tab-size: 4;
@@ -3718,7 +3733,7 @@ var styles = /* @__PURE__ */ (() => `.tina-tailwind {
3718
3733
  --tw-ring-opacity: 1;
3719
3734
  --tw-ring-color: rgb(0 132 255 / var(--tw-ring-opacity));
3720
3735
  }
3721
- `)();
3736
+ `;
3722
3737
  class ContentCreatorPlugin {
3723
3738
  constructor(options) {
3724
3739
  this.__type = "content-creator";
@@ -4422,12 +4437,12 @@ const Sidebar = ({ cms }) => {
4422
4437
  contentCreators: [],
4423
4438
  RenderNavSite: ({ view }) => /* @__PURE__ */ React.createElement(SidebarLink, {
4424
4439
  label: view.name,
4425
- to: `screens/${slugify(view.name)}`,
4440
+ to: `/screens/${slugify(view.name)}`,
4426
4441
  Icon: view.Icon ? view.Icon : ImFilesEmpty
4427
4442
  }),
4428
4443
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React.createElement(SidebarLink, {
4429
4444
  label: collection.label ? collection.label : collection.name,
4430
- to: `collections/${collection.name}`,
4445
+ to: `/collections/${collection.name}`,
4431
4446
  Icon: ImFilesEmpty
4432
4447
  })
4433
4448
  }), !renderDesktopNav && /* @__PURE__ */ React.createElement(Transition, {
@@ -4451,7 +4466,7 @@ const Sidebar = ({ cms }) => {
4451
4466
  contentCreators: [],
4452
4467
  RenderNavSite: ({ view }) => /* @__PURE__ */ React.createElement(SidebarLink, {
4453
4468
  label: view.name,
4454
- to: `screens/${slugify(view.name)}`,
4469
+ to: `/screens/${slugify(view.name)}`,
4455
4470
  Icon: view.Icon ? view.Icon : ImFilesEmpty,
4456
4471
  onClick: () => {
4457
4472
  setMenuIsOpen(false);
@@ -4459,7 +4474,7 @@ const Sidebar = ({ cms }) => {
4459
4474
  }),
4460
4475
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React.createElement(SidebarLink, {
4461
4476
  label: collection.label ? collection.label : collection.name,
4462
- to: `collections/${collection.name}`,
4477
+ to: `/collections/${collection.name}`,
4463
4478
  Icon: ImFilesEmpty,
4464
4479
  onClick: () => {
4465
4480
  setMenuIsOpen(false);
@@ -4820,12 +4835,17 @@ const TemplateMenu = ({ templates }) => {
4820
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"}`
4821
4836
  }, template.label))))))));
4822
4837
  };
4823
- const handleNavigate = (navigate, cms, collection, document) => {
4838
+ const handleNavigate = (navigate, cms, collection, collectionDefinition, document) => {
4839
+ var _a, _b;
4824
4840
  const plugins = cms.plugins.all("tina-admin");
4825
4841
  const routeMapping = plugins.find(({ name }) => name === "route-mapping");
4826
- const routeOverride = routeMapping ? routeMapping.mapper(collection, document) : void 0;
4842
+ const tinaPreview = cms.flags.get("tina-preview") || false;
4843
+ const routeOverride = ((_a = collectionDefinition.ui) == null ? void 0 : _a.router) ? (_b = collectionDefinition.ui) == null ? void 0 : _b.router({
4844
+ document,
4845
+ collection: collectionDefinition
4846
+ }) : routeMapping ? routeMapping.mapper(collection, document) : void 0;
4827
4847
  if (routeOverride) {
4828
- window.location.href = routeOverride;
4848
+ tinaPreview ? navigate(`/preview?iframe-url=${encodeURIComponent(routeOverride)}`) : window.location.href = routeOverride;
4829
4849
  return null;
4830
4850
  } else {
4831
4851
  navigate(document._sys.breadcrumbs.join("/"));
@@ -4868,7 +4888,8 @@ const CollectionListPage = () => {
4868
4888
  const documents = collection.documents.edges;
4869
4889
  const admin = cms.api.admin;
4870
4890
  const pageInfo = collection.documents.pageInfo;
4871
- const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime"].includes(x.type));
4891
+ const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime", "boolean"].includes(x.type));
4892
+ const collectionDefinition = cms.api.tina.schema.getCollection(collection.name);
4872
4893
  return /* @__PURE__ */ React.createElement(PageWrapper, null, /* @__PURE__ */ React.createElement(React.Fragment, null, open && /* @__PURE__ */ React.createElement(DeleteModal, {
4873
4894
  filename: vars.relativePath,
4874
4895
  deleteFunc: async () => {
@@ -4959,7 +4980,7 @@ const CollectionListPage = () => {
4959
4980
  }, /* @__PURE__ */ React.createElement("a", {
4960
4981
  className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer",
4961
4982
  onClick: () => {
4962
- handleNavigate(navigate, cms, collection, document.node);
4983
+ handleNavigate(navigate, cms, collection, collectionDefinition, document.node);
4963
4984
  }
4964
4985
  }, /* @__PURE__ */ React.createElement(BiEdit, {
4965
4986
  className: "inline-block h-6 w-auto opacity-70"
@@ -5359,7 +5380,18 @@ const Redirect = () => {
5359
5380
  }, []);
5360
5381
  return null;
5361
5382
  };
5362
- const TinaAdmin = () => {
5383
+ const SetPreviewFlag = ({
5384
+ preview,
5385
+ cms
5386
+ }) => {
5387
+ React.useEffect(() => {
5388
+ if (preview) {
5389
+ cms.flags.set("tina-iframe", true);
5390
+ }
5391
+ }, [preview]);
5392
+ return null;
5393
+ };
5394
+ const TinaAdmin = ({ preview }) => {
5363
5395
  const isSSR2 = typeof window === "undefined";
5364
5396
  const { edit } = useEditState();
5365
5397
  if (isSSR2) {
@@ -5371,31 +5403,43 @@ const TinaAdmin = () => {
5371
5403
  return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => {
5372
5404
  const isTinaAdminEnabled = cms.flags.get("tina-admin") === false ? false : true;
5373
5405
  if (isTinaAdminEnabled) {
5374
- return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(HashRouter, null, /* @__PURE__ */ React.createElement("div", {
5375
- className: "flex items-stretch h-screen overflow-hidden"
5376
- }, /* @__PURE__ */ React.createElement(Sidebar, {
5406
+ return /* @__PURE__ */ React.createElement(HashRouter, null, /* @__PURE__ */ React.createElement(SetPreviewFlag, {
5407
+ preview,
5377
5408
  cms
5378
- }), /* @__PURE__ */ React.createElement("div", {
5379
- className: "flex-1 relative"
5380
- }, /* @__PURE__ */ React.createElement(Routes, null, /* @__PURE__ */ React.createElement(Route, {
5409
+ }), /* @__PURE__ */ React.createElement(Routes, null, preview && /* @__PURE__ */ React.createElement(Route, {
5410
+ path: "preview",
5411
+ element: preview
5412
+ }), /* @__PURE__ */ React.createElement(Route, {
5381
5413
  path: "collections/:collectionName/new",
5382
- element: /* @__PURE__ */ React.createElement(CollectionCreatePage, null)
5414
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5415
+ cms
5416
+ }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
5383
5417
  }), /* @__PURE__ */ React.createElement(Route, {
5384
5418
  path: "collections/:collectionName/:templateName/new",
5385
- element: /* @__PURE__ */ React.createElement(CollectionCreatePage, null)
5419
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5420
+ cms
5421
+ }, /* @__PURE__ */ React.createElement(CollectionCreatePage, null))
5386
5422
  }), /* @__PURE__ */ React.createElement(Route, {
5387
5423
  path: "collections/:collectionName/*",
5388
- element: /* @__PURE__ */ React.createElement(CollectionUpdatePage, null)
5424
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5425
+ cms
5426
+ }, /* @__PURE__ */ React.createElement(CollectionUpdatePage, null))
5389
5427
  }), /* @__PURE__ */ React.createElement(Route, {
5390
5428
  path: "collections/:collectionName",
5391
- element: /* @__PURE__ */ React.createElement(CollectionListPage, null)
5429
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5430
+ cms
5431
+ }, /* @__PURE__ */ React.createElement(CollectionListPage, null))
5392
5432
  }), /* @__PURE__ */ React.createElement(Route, {
5393
5433
  path: "screens/:screenName",
5394
- element: /* @__PURE__ */ React.createElement(ScreenPage, null)
5434
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5435
+ cms
5436
+ }, /* @__PURE__ */ React.createElement(ScreenPage, null))
5395
5437
  }), /* @__PURE__ */ React.createElement(Route, {
5396
5438
  path: "/",
5397
- element: /* @__PURE__ */ React.createElement(DashboardPage, null)
5398
- }))))));
5439
+ element: /* @__PURE__ */ React.createElement(DefaultWrapper, {
5440
+ cms
5441
+ }, /* @__PURE__ */ React.createElement(DashboardPage, null))
5442
+ })));
5399
5443
  } else {
5400
5444
  return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement(HashRouter, null, /* @__PURE__ */ React.createElement(Routes, null, /* @__PURE__ */ React.createElement(Route, {
5401
5445
  path: "logout",
@@ -5407,6 +5451,18 @@ const TinaAdmin = () => {
5407
5451
  }
5408
5452
  });
5409
5453
  };
5454
+ const DefaultWrapper = ({
5455
+ cms,
5456
+ children
5457
+ }) => {
5458
+ return /* @__PURE__ */ React.createElement(Layout, null, /* @__PURE__ */ React.createElement("div", {
5459
+ className: "flex items-stretch h-screen overflow-hidden"
5460
+ }, /* @__PURE__ */ React.createElement(Sidebar, {
5461
+ cms
5462
+ }), /* @__PURE__ */ React.createElement("div", {
5463
+ className: "flex-1 relative"
5464
+ }, children)));
5465
+ };
5410
5466
  class RouteMappingPlugin {
5411
5467
  constructor(mapper) {
5412
5468
  this.__type = "tina-admin";
@@ -5421,4 +5477,7 @@ const defineSchema = (config) => {
5421
5477
  const defineConfig = (config) => {
5422
5478
  return config;
5423
5479
  };
5424
- export { AuthWallInner, Client, DEFAULT_LOCAL_TINA_GQL_SERVER_URL, LocalClient, RouteMappingPlugin, TinaAdmin, TinaAdminApi, TinaCMSProvider2, TinaCloudAuthWall, TinaCloudProvider, TinaDataProvider, assertShape, createClient, TinaCMSProvider2 as default, defineConfig, defineSchema, getStaticPropsForTina, gql, safeAssertShape, staticRequest, useDocumentCreatorPlugin, useGraphqlForms, useTinaAuthRedirect };
5480
+ const defineStaticConfig = (config) => {
5481
+ return config;
5482
+ };
5483
+ export { AuthWallInner, Client, DEFAULT_LOCAL_TINA_GQL_SERVER_URL, LocalClient, RouteMappingPlugin, TinaAdmin, TinaAdminApi, TinaCMSProvider2, TinaCloudAuthWall, TinaCloudProvider, TinaDataProvider, assertShape, createClient, TinaCMSProvider2 as default, defineConfig, defineSchema, defineStaticConfig, getStaticPropsForTina, gql, safeAssertShape, staticRequest, useDocumentCreatorPlugin, useGraphqlForms, useTinaAuthRedirect };
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
@@ -2306,6 +2312,15 @@ mutation addPendingDocumentMutation(
2306
2312
  const jsonRes = await res.json();
2307
2313
  return jsonRes;
2308
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
+ }
2309
2324
  parseJwt(token) {
2310
2325
  const base64Url = token.split(".")[1];
2311
2326
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
@@ -2798,7 +2813,7 @@ mutation addPendingDocumentMutation(
2798
2813
  })));
2799
2814
  };
2800
2815
  const TinaCloudAuthWall = TinaCloudProvider;
2801
- var styles = /* @__PURE__ */ (() => `.tina-tailwind {
2816
+ var styles = `.tina-tailwind {
2802
2817
  line-height: 1.5;
2803
2818
  -webkit-text-size-adjust: 100%;
2804
2819
  -moz-tab-size: 4;
@@ -3736,7 +3751,7 @@ mutation addPendingDocumentMutation(
3736
3751
  --tw-ring-opacity: 1;
3737
3752
  --tw-ring-color: rgb(0 132 255 / var(--tw-ring-opacity));
3738
3753
  }
3739
- `)();
3754
+ `;
3740
3755
  class ContentCreatorPlugin {
3741
3756
  constructor(options) {
3742
3757
  this.__type = "content-creator";
@@ -4440,12 +4455,12 @@ This will work when developing locally but NOT when deployed to production.
4440
4455
  contentCreators: [],
4441
4456
  RenderNavSite: ({ view }) => /* @__PURE__ */ React__default["default"].createElement(SidebarLink, {
4442
4457
  label: view.name,
4443
- to: `screens/${slugify(view.name)}`,
4458
+ to: `/screens/${slugify(view.name)}`,
4444
4459
  Icon: view.Icon ? view.Icon : ImFilesEmpty
4445
4460
  }),
4446
4461
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React__default["default"].createElement(SidebarLink, {
4447
4462
  label: collection.label ? collection.label : collection.name,
4448
- to: `collections/${collection.name}`,
4463
+ to: `/collections/${collection.name}`,
4449
4464
  Icon: ImFilesEmpty
4450
4465
  })
4451
4466
  }), !renderDesktopNav && /* @__PURE__ */ React__default["default"].createElement(react.Transition, {
@@ -4469,7 +4484,7 @@ This will work when developing locally but NOT when deployed to production.
4469
4484
  contentCreators: [],
4470
4485
  RenderNavSite: ({ view }) => /* @__PURE__ */ React__default["default"].createElement(SidebarLink, {
4471
4486
  label: view.name,
4472
- to: `screens/${slugify(view.name)}`,
4487
+ to: `/screens/${slugify(view.name)}`,
4473
4488
  Icon: view.Icon ? view.Icon : ImFilesEmpty,
4474
4489
  onClick: () => {
4475
4490
  setMenuIsOpen(false);
@@ -4477,7 +4492,7 @@ This will work when developing locally but NOT when deployed to production.
4477
4492
  }),
4478
4493
  RenderNavCollection: ({ collection }) => /* @__PURE__ */ React__default["default"].createElement(SidebarLink, {
4479
4494
  label: collection.label ? collection.label : collection.name,
4480
- to: `collections/${collection.name}`,
4495
+ to: `/collections/${collection.name}`,
4481
4496
  Icon: ImFilesEmpty,
4482
4497
  onClick: () => {
4483
4498
  setMenuIsOpen(false);
@@ -4838,12 +4853,17 @@ This will work when developing locally but NOT when deployed to production.
4838
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"}`
4839
4854
  }, template.label))))))));
4840
4855
  };
4841
- const handleNavigate = (navigate, cms, collection, document) => {
4856
+ const handleNavigate = (navigate, cms, collection, collectionDefinition, document) => {
4857
+ var _a, _b;
4842
4858
  const plugins = cms.plugins.all("tina-admin");
4843
4859
  const routeMapping = plugins.find(({ name }) => name === "route-mapping");
4844
- const routeOverride = routeMapping ? routeMapping.mapper(collection, document) : void 0;
4860
+ const tinaPreview = cms.flags.get("tina-preview") || false;
4861
+ const routeOverride = ((_a = collectionDefinition.ui) == null ? void 0 : _a.router) ? (_b = collectionDefinition.ui) == null ? void 0 : _b.router({
4862
+ document,
4863
+ collection: collectionDefinition
4864
+ }) : routeMapping ? routeMapping.mapper(collection, document) : void 0;
4845
4865
  if (routeOverride) {
4846
- window.location.href = routeOverride;
4866
+ tinaPreview ? navigate(`/preview?iframe-url=${encodeURIComponent(routeOverride)}`) : window.location.href = routeOverride;
4847
4867
  return null;
4848
4868
  } else {
4849
4869
  navigate(document._sys.breadcrumbs.join("/"));
@@ -4886,7 +4906,8 @@ This will work when developing locally but NOT when deployed to production.
4886
4906
  const documents = collection.documents.edges;
4887
4907
  const admin = cms.api.admin;
4888
4908
  const pageInfo = collection.documents.pageInfo;
4889
- const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime"].includes(x.type));
4909
+ const fields = (_a = collectionExtra.fields) == null ? void 0 : _a.filter((x) => ["string", "number", "datetime", "boolean"].includes(x.type));
4910
+ const collectionDefinition = cms.api.tina.schema.getCollection(collection.name);
4890
4911
  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, {
4891
4912
  filename: vars.relativePath,
4892
4913
  deleteFunc: async () => {
@@ -4977,7 +4998,7 @@ This will work when developing locally but NOT when deployed to production.
4977
4998
  }, /* @__PURE__ */ React__default["default"].createElement("a", {
4978
4999
  className: "text-blue-600 hover:text-blue-400 flex items-center gap-3 cursor-pointer",
4979
5000
  onClick: () => {
4980
- handleNavigate(navigate, cms, collection, document.node);
5001
+ handleNavigate(navigate, cms, collection, collectionDefinition, document.node);
4981
5002
  }
4982
5003
  }, /* @__PURE__ */ React__default["default"].createElement(BiEdit, {
4983
5004
  className: "inline-block h-6 w-auto opacity-70"
@@ -5377,7 +5398,18 @@ This will work when developing locally but NOT when deployed to production.
5377
5398
  }, []);
5378
5399
  return null;
5379
5400
  };
5380
- const TinaAdmin = () => {
5401
+ const SetPreviewFlag = ({
5402
+ preview,
5403
+ cms
5404
+ }) => {
5405
+ React__default["default"].useEffect(() => {
5406
+ if (preview) {
5407
+ cms.flags.set("tina-iframe", true);
5408
+ }
5409
+ }, [preview]);
5410
+ return null;
5411
+ };
5412
+ const TinaAdmin = ({ preview }) => {
5381
5413
  const isSSR2 = typeof window === "undefined";
5382
5414
  const { edit } = sharedctx.useEditState();
5383
5415
  if (isSSR2) {
@@ -5389,31 +5421,43 @@ This will work when developing locally but NOT when deployed to production.
5389
5421
  return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => {
5390
5422
  const isTinaAdminEnabled = cms.flags.get("tina-admin") === false ? false : true;
5391
5423
  if (isTinaAdminEnabled) {
5392
- return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.HashRouter, null, /* @__PURE__ */ React__default["default"].createElement("div", {
5393
- className: "flex items-stretch h-screen overflow-hidden"
5394
- }, /* @__PURE__ */ React__default["default"].createElement(Sidebar, {
5424
+ return /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.HashRouter, null, /* @__PURE__ */ React__default["default"].createElement(SetPreviewFlag, {
5425
+ preview,
5395
5426
  cms
5396
- }), /* @__PURE__ */ React__default["default"].createElement("div", {
5397
- className: "flex-1 relative"
5398
- }, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5427
+ }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, preview && /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5428
+ path: "preview",
5429
+ element: preview
5430
+ }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5399
5431
  path: "collections/:collectionName/new",
5400
- element: /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)
5432
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5433
+ cms
5434
+ }, /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null))
5401
5435
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5402
5436
  path: "collections/:collectionName/:templateName/new",
5403
- element: /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)
5437
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5438
+ cms
5439
+ }, /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null))
5404
5440
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5405
5441
  path: "collections/:collectionName/*",
5406
- element: /* @__PURE__ */ React__default["default"].createElement(CollectionUpdatePage, null)
5442
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5443
+ cms
5444
+ }, /* @__PURE__ */ React__default["default"].createElement(CollectionUpdatePage, null))
5407
5445
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5408
5446
  path: "collections/:collectionName",
5409
- element: /* @__PURE__ */ React__default["default"].createElement(CollectionListPage, null)
5447
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5448
+ cms
5449
+ }, /* @__PURE__ */ React__default["default"].createElement(CollectionListPage, null))
5410
5450
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5411
5451
  path: "screens/:screenName",
5412
- element: /* @__PURE__ */ React__default["default"].createElement(ScreenPage, null)
5452
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5453
+ cms
5454
+ }, /* @__PURE__ */ React__default["default"].createElement(ScreenPage, null))
5413
5455
  }), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5414
5456
  path: "/",
5415
- element: /* @__PURE__ */ React__default["default"].createElement(DashboardPage, null)
5416
- }))))));
5457
+ element: /* @__PURE__ */ React__default["default"].createElement(DefaultWrapper, {
5458
+ cms
5459
+ }, /* @__PURE__ */ React__default["default"].createElement(DashboardPage, null))
5460
+ })));
5417
5461
  } else {
5418
5462
  return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.HashRouter, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
5419
5463
  path: "logout",
@@ -5425,6 +5469,18 @@ This will work when developing locally but NOT when deployed to production.
5425
5469
  }
5426
5470
  });
5427
5471
  };
5472
+ const DefaultWrapper = ({
5473
+ cms,
5474
+ children
5475
+ }) => {
5476
+ return /* @__PURE__ */ React__default["default"].createElement(Layout, null, /* @__PURE__ */ React__default["default"].createElement("div", {
5477
+ className: "flex items-stretch h-screen overflow-hidden"
5478
+ }, /* @__PURE__ */ React__default["default"].createElement(Sidebar, {
5479
+ cms
5480
+ }), /* @__PURE__ */ React__default["default"].createElement("div", {
5481
+ className: "flex-1 relative"
5482
+ }, children)));
5483
+ };
5428
5484
  class RouteMappingPlugin {
5429
5485
  constructor(mapper) {
5430
5486
  this.__type = "tina-admin";
@@ -5439,6 +5495,9 @@ This will work when developing locally but NOT when deployed to production.
5439
5495
  const defineConfig = (config) => {
5440
5496
  return config;
5441
5497
  };
5498
+ const defineStaticConfig = (config) => {
5499
+ return config;
5500
+ };
5442
5501
  exports2.AuthWallInner = AuthWallInner;
5443
5502
  exports2.Client = Client;
5444
5503
  exports2.DEFAULT_LOCAL_TINA_GQL_SERVER_URL = DEFAULT_LOCAL_TINA_GQL_SERVER_URL;
@@ -5455,6 +5514,7 @@ This will work when developing locally but NOT when deployed to production.
5455
5514
  exports2["default"] = TinaCMSProvider2;
5456
5515
  exports2.defineConfig = defineConfig;
5457
5516
  exports2.defineSchema = defineSchema;
5517
+ exports2.defineStaticConfig = defineStaticConfig;
5458
5518
  exports2.getStaticPropsForTina = getStaticPropsForTina;
5459
5519
  exports2.gql = gql;
5460
5520
  exports2.safeAssertShape = safeAssertShape;
@@ -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>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This is an experimental version of the useTina hook,
3
+ * it is only meant to be used with Tina in "iframe mode".
4
+ */
5
+ export declare function useTina<T extends object>(props: {
6
+ query: string;
7
+ variables: object;
8
+ data: T;
9
+ }): {
10
+ data: T;
11
+ };
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ function useTina(props) {
3
+ const [data, setData] = React.useState(props.data);
4
+ React.useEffect(() => {
5
+ const id = btoa(JSON.stringify({ query: props.query }));
6
+ parent.postMessage({ type: "open", ...props, id }, window.location.origin);
7
+ window.addEventListener("message", (event) => {
8
+ if (event.data.id === id) {
9
+ console.log("child: event received");
10
+ setData(event.data.data);
11
+ }
12
+ });
13
+ return () => parent.postMessage({ type: "close", id }, window.location.origin);
14
+ }, []);
15
+ return { data };
16
+ }
17
+ export { useTina };
package/dist/react.js ADDED
@@ -0,0 +1,26 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
+ })(this, function(exports2, React) {
4
+ "use strict";
5
+ function _interopDefaultLegacy(e) {
6
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
7
+ }
8
+ var React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
9
+ function useTina(props) {
10
+ const [data, setData] = React__default["default"].useState(props.data);
11
+ React__default["default"].useEffect(() => {
12
+ const id = btoa(JSON.stringify({ query: props.query }));
13
+ parent.postMessage({ type: "open", ...props, id }, window.location.origin);
14
+ window.addEventListener("message", (event) => {
15
+ if (event.data.id === id) {
16
+ console.log("child: event received");
17
+ setData(event.data.data);
18
+ }
19
+ });
20
+ return () => parent.postMessage({ type: "close", id }, window.location.origin);
21
+ }, []);
22
+ return { data };
23
+ }
24
+ exports2.useTina = useTina;
25
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
26
+ });
@@ -11,8 +11,10 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import type { formifyCallback } from './hooks/use-graphql-forms';
14
+ import { useDocumentCreatorPlugin } from './hooks/use-content-creator';
14
15
  import { TinaCMSProviderDefaultProps } from './types/cms';
15
16
  export declare const TinaCMSProvider2: ({ query, documentCreatorCallback, formifyCallback, schema, ...props }: TinaCMSProviderDefaultProps) => JSX.Element;
17
+ export declare type DocumentCreatorCallback = Parameters<typeof useDocumentCreatorPlugin>[0];
16
18
  export declare const TinaDataProvider: ({ children, formifyCallback, }: {
17
19
  children: any;
18
20
  formifyCallback: formifyCallback;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "0.69.4",
3
+ "version": "0.69.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -19,6 +19,11 @@
19
19
  "import": "./dist/edit-state.es.js",
20
20
  "require": "./dist/edit-state.js"
21
21
  },
22
+ "./dist/react": {
23
+ "types": "./dist/react.d.ts",
24
+ "import": "./dist/react.es.js",
25
+ "require": "./dist/react.js"
26
+ },
22
27
  "./dist/rich-text": {
23
28
  "types": "./dist/rich-text/index.d.ts",
24
29
  "import": "./dist/rich-text/index.es.js",
@@ -38,6 +43,7 @@
38
43
  "src/index.ts",
39
44
  "src/edit-state.tsx",
40
45
  "src/rich-text/index.tsx",
46
+ "src/react.tsx",
41
47
  "src/client.ts"
42
48
  ]
43
49
  },
@@ -48,9 +54,9 @@
48
54
  "@headlessui/react": "^1.5.0",
49
55
  "@heroicons/react": "^1.0.4",
50
56
  "@react-hook/window-size": "^3.0.7",
51
- "@tinacms/schema-tools": "0.1.0",
57
+ "@tinacms/schema-tools": "0.1.3",
52
58
  "@tinacms/sharedctx": "0.1.2",
53
- "@tinacms/toolkit": "0.57.2",
59
+ "@tinacms/toolkit": "0.57.4",
54
60
  "crypto-js": "^4.0.0",
55
61
  "fetch-ponyfill": "^7.1.0",
56
62
  "final-form": "4.20.1",