tinacms 0.67.2 → 0.68.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.js CHANGED
@@ -428,7 +428,7 @@ var __objRest = (source, exclude) => {
428
428
  return false;
429
429
  }
430
430
  }
431
- function useGraphqlFormsUnstable({
431
+ function useGraphqlForms({
432
432
  variables,
433
433
  onSubmit,
434
434
  query,
@@ -446,239 +446,6 @@ var __objRest = (source, exclude) => {
446
446
  });
447
447
  return [state.data, state.status !== "done"];
448
448
  }
449
- function useGraphqlForms({
450
- variables,
451
- onSubmit,
452
- formify: formify2 = null,
453
- query
454
- }) {
455
- const cms = toolkit.useCMS();
456
- const [formValues, setFormValues] = React__default["default"].useState({});
457
- const [data, setData] = React__default["default"].useState(null);
458
- const [initialData, setInitialData] = React__default["default"].useState({});
459
- const [pendingReset, setPendingReset] = React__default["default"].useState(null);
460
- const [isLoading, setIsLoading] = React__default["default"].useState(true);
461
- const [newUpdate, setNewUpdate] = React__default["default"].useState(null);
462
- const { currentBranch } = toolkit.useBranchData();
463
- const updateData = async () => {
464
- var _a;
465
- if (newUpdate) {
466
- const newValue = finalForm.getIn(formValues, newUpdate.get);
467
- const activeForm = finalForm.getIn(data, [newUpdate.queryName, "form"].join("."));
468
- if (!activeForm) {
469
- throw new Error(`Unable to find form for query ${newUpdate.queryName}`);
470
- }
471
- if (activeForm == null ? void 0 : activeForm.paths) {
472
- const asyncUpdate = (_a = activeForm.paths) == null ? void 0 : _a.find((p) => p.dataPath.join(".") === newUpdate.setReference);
473
- if (asyncUpdate) {
474
- const res = await cms.api.tina.request(asyncUpdate.queryString, {
475
- variables: { id: newValue }
476
- });
477
- const newData2 = finalForm.setIn(data, newUpdate.set, res.node);
478
- const newDataAndNewJSONData2 = finalForm.setIn(newData2, newUpdate.set.replace("data", "dataJSON"), newValue);
479
- setData(newDataAndNewJSONData2);
480
- setNewUpdate(null);
481
- return;
482
- }
483
- }
484
- if (newUpdate.lookup) {
485
- const field = getFieldUpdate(newUpdate, activeForm, formValues);
486
- if (field && field.typeMap) {
487
- newValue.forEach((item) => {
488
- if (!item.__typename) {
489
- item["__typename"] = field.typeMap[item._template];
490
- }
491
- });
492
- }
493
- }
494
- const newData = finalForm.setIn(data, newUpdate.set, newValue);
495
- const newDataAndNewJSONData = finalForm.setIn(newData, newUpdate.set.replace("data", "dataJSON"), newValue);
496
- setData(newDataAndNewJSONData);
497
- setNewUpdate(null);
498
- }
499
- };
500
- React__default["default"].useEffect(() => {
501
- updateData();
502
- }, [JSON.stringify(formValues)]);
503
- React__default["default"].useEffect(() => {
504
- if (pendingReset) {
505
- setData(__spreadProps(__spreadValues({}, data), { [pendingReset]: initialData[pendingReset] }));
506
- setPendingReset(null);
507
- }
508
- }, [pendingReset]);
509
- React__default["default"].useEffect(() => {
510
- if (!query) {
511
- setIsLoading(false);
512
- return;
513
- }
514
- const useUnstableFormify = (cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false ? false : true;
515
- const formIds = [];
516
- setIsLoading(true);
517
- cms.api.tina.requestWithForm((gql2) => gql2(query), {
518
- variables,
519
- useUnstableFormify
520
- }).then((payload) => {
521
- cms.plugins.remove(new toolkit.FormMetaPlugin({ name: "tina-admin-link" }));
522
- setData(payload);
523
- setInitialData(payload);
524
- setIsLoading(false);
525
- Object.entries(payload).map(([queryName, result]) => {
526
- formIds.push(queryName);
527
- const canBeFormified = safeAssertShape(result, (yup2) => yup2.object({
528
- values: yup2.object().required(),
529
- form: yup2.object().required()
530
- }));
531
- if (!canBeFormified) {
532
- return;
533
- }
534
- assertShape(result, (yup2) => yup2.object({
535
- values: yup2.object().required(),
536
- form: yup2.object().required()
537
- }), `Unable to build form shape for fields at ${queryName}`);
538
- let formConfig = {};
539
- const formCommon = {
540
- id: queryName,
541
- initialValues: result.values,
542
- reset: () => {
543
- setPendingReset(queryName);
544
- },
545
- onSubmit: async (payload2) => {
546
- try {
547
- const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
548
- const variables2 = { params };
549
- const mutationString = result.form.mutationInfo.string;
550
- if (onSubmit) {
551
- onSubmit({
552
- queryString: mutationString,
553
- mutationString,
554
- variables: variables2
555
- });
556
- } else {
557
- try {
558
- await cms.api.tina.request(mutationString, {
559
- variables: variables2
560
- });
561
- cms.alerts.success("Document saved!");
562
- } catch (e) {
563
- cms.alerts.error("There was a problem saving your document");
564
- console.error(e);
565
- }
566
- }
567
- } catch (e) {
568
- console.error(e);
569
- cms.alerts.error("There was a problem saving your document");
570
- }
571
- }
572
- };
573
- if (cms.api.tina.schema) {
574
- const enrichedSchema = cms.api.tina.schema;
575
- const collection = enrichedSchema.getCollection(result._internalSys.collection.name);
576
- const template = enrichedSchema.getTemplateForData({
577
- collection,
578
- data: result.values
579
- });
580
- const formInfo = schemaTools.resolveForm({
581
- collection,
582
- basename: collection.name,
583
- schema: enrichedSchema,
584
- template
585
- });
586
- formConfig = __spreadValues({
587
- label: formInfo.label,
588
- fields: formInfo.fields
589
- }, formCommon);
590
- } else {
591
- formConfig = __spreadValues({
592
- label: result.form.label,
593
- fields: result.form.fields
594
- }, formCommon);
595
- }
596
- const { createForm, createGlobalForm } = generateFormCreators(cms);
597
- const SKIPPED = "SKIPPED";
598
- let form;
599
- let skipped;
600
- const skip = () => {
601
- skipped = SKIPPED;
602
- };
603
- if (skipped)
604
- return;
605
- if (formify2) {
606
- form = formify2({ formConfig, createForm, createGlobalForm, skip }, cms);
607
- } else {
608
- form = createForm(formConfig);
609
- }
610
- if (!(form instanceof toolkit.Form)) {
611
- if (skipped === SKIPPED) {
612
- return;
613
- }
614
- throw new Error("formify must return a form or skip()");
615
- }
616
- const { change } = form.finalForm;
617
- form.finalForm.change = (name, value) => {
618
- let referenceName = "";
619
- if (typeof name === "string") {
620
- referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
621
- } else {
622
- throw new Error(`Expected name to be of type string for FinalForm change callback`);
623
- }
624
- setNewUpdate({
625
- queryName,
626
- get: [queryName, "values", name].join("."),
627
- set: [queryName, "data", name].join("."),
628
- setReference: [queryName, "data", referenceName].join(".")
629
- });
630
- return change(name, value);
631
- };
632
- const _a = form.finalForm.mutators, { insert, move, remove } = _a, rest = __objRest(_a, ["insert", "move", "remove"]);
633
- const prepareNewUpdate = (name, lookup) => {
634
- const extra = {};
635
- if (lookup) {
636
- extra["lookup"] = lookup;
637
- }
638
- const referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
639
- setNewUpdate(__spreadValues({
640
- queryName,
641
- get: [queryName, "values", name].join("."),
642
- set: [queryName, "data", name].join("."),
643
- setReference: [queryName, "data", referenceName].join(".")
644
- }, extra));
645
- };
646
- form.finalForm.mutators = __spreadValues({
647
- insert: (...args) => {
648
- const fieldName = args[0];
649
- prepareNewUpdate(fieldName, fieldName);
650
- insert(...args);
651
- },
652
- move: (...args) => {
653
- const fieldName = args[0];
654
- prepareNewUpdate(fieldName, fieldName);
655
- move(...args);
656
- },
657
- remove: (...args) => {
658
- const fieldName = args[0];
659
- prepareNewUpdate(fieldName, fieldName);
660
- remove(...args);
661
- }
662
- }, rest);
663
- form.subscribe(({ values }) => {
664
- setFormValues(__spreadProps(__spreadValues({}, formValues), { [queryName]: { values } }));
665
- }, { values: true });
666
- });
667
- }).catch((e) => {
668
- setIsLoading(false);
669
- throw new Error(`There was a problem setting up forms for your query: ${e.message}`);
670
- });
671
- return () => {
672
- formIds.forEach((name) => {
673
- const formPlugin = cms.forms.find(name);
674
- if (formPlugin) {
675
- cms.forms.remove(formPlugin);
676
- }
677
- });
678
- };
679
- }, [query, JSON.stringify(variables), currentBranch]);
680
- return [data, isLoading];
681
- }
682
449
  const transformDocumentIntoMutationRequestPayload = (document, instructions) => {
683
450
  const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
684
451
  const params = transformParams(rest);
@@ -715,37 +482,7 @@ var __objRest = (source, exclude) => {
715
482
  }
716
483
  }
717
484
  };
718
- const getFieldUpdate = (newUpdate, activeForm, formValues) => {
719
- const items = newUpdate.lookup.split(".");
720
- let currentFields = activeForm.fields;
721
- items.map((item, index) => {
722
- const lookupName = items.slice(0, index + 1).join(".");
723
- const value = finalForm.getIn(formValues, [newUpdate.queryName, "values", lookupName].join("."));
724
- if (isNaN(Number(item))) {
725
- if (Array.isArray(currentFields)) {
726
- currentFields = currentFields.find((field) => field.name === item);
727
- }
728
- } else {
729
- const template = currentFields.templates ? currentFields.templates[value._template] : currentFields;
730
- currentFields = template.fields;
731
- }
732
- });
733
- return currentFields;
734
- };
735
- const generateFormCreators = (cms) => {
736
- const createForm = (formConfig) => {
737
- const form = new toolkit.Form(formConfig);
738
- cms.forms.add(form);
739
- return form;
740
- };
741
- const createGlobalForm = (formConfig, options) => {
742
- const form = new toolkit.Form(formConfig);
743
- cms.plugins.add(new toolkit.GlobalFormPlugin(form, options == null ? void 0 : options.icon, options == null ? void 0 : options.layout));
744
- return form;
745
- };
746
- return { createForm, createGlobalForm };
747
- };
748
- const generateFormCreatorsUnstable = (cms, showInSidebar) => {
485
+ const generateFormCreators = (cms, showInSidebar) => {
749
486
  const createForm = (formConfig) => {
750
487
  const form = new toolkit.Form(formConfig);
751
488
  if (showInSidebar) {
@@ -829,7 +566,7 @@ var __objRest = (source, exclude) => {
829
566
  return accum.join(".");
830
567
  };
831
568
  const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
832
- const { createForm, createGlobalForm } = generateFormCreatorsUnstable(cms, showInSidebar);
569
+ const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
833
570
  const SKIPPED = "SKIPPED";
834
571
  let form;
835
572
  let skipped;
@@ -839,25 +576,50 @@ var __objRest = (source, exclude) => {
839
576
  if (skipped)
840
577
  return;
841
578
  const id = doc._internalSys.path;
579
+ const enrichedSchema = cms.api.tina.schema;
580
+ const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
581
+ const template = enrichedSchema.getTemplateForData({
582
+ collection,
583
+ data: doc._values
584
+ });
842
585
  const formCommon = {
843
586
  id,
844
- label: doc.form.label,
845
- initialValues: doc.values,
587
+ label: id,
588
+ initialValues: doc._values,
846
589
  onSubmit: async (payload) => {
847
590
  try {
848
- const params = transformDocumentIntoMutationRequestPayload(payload, doc.form.mutationInfo);
591
+ const params = transformDocumentIntoMutationRequestPayload(payload, {
592
+ includeCollection: false,
593
+ includeTemplate: !!collection.templates
594
+ });
849
595
  const variables = { params };
850
- const mutationString = doc.form.mutationInfo.string;
596
+ const mutationString = `#graphql
597
+ mutation UpdateDocument($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
598
+ updateDocument(collection: $collection, relativePath: $relativePath, params: $params) {
599
+ __typename
600
+ }
601
+ }
602
+ `;
851
603
  if (onSubmit) {
852
604
  onSubmit({
853
605
  queryString: mutationString,
854
606
  mutationString,
855
- variables
607
+ variables: {
608
+ collection: doc._internalSys.collection.name,
609
+ relativePath: doc._internalSys.relativePath,
610
+ params: { [doc._internalSys.collection.name]: variables }
611
+ }
856
612
  });
857
613
  } else {
858
614
  try {
859
615
  await cms.api.tina.request(mutationString, {
860
- variables
616
+ variables: {
617
+ collection: doc._internalSys.collection.name,
618
+ relativePath: doc._internalSys.relativePath,
619
+ params: {
620
+ [doc._internalSys.collection.name]: variables.params
621
+ }
622
+ }
861
623
  });
862
624
  cms.alerts.success("Document saved!");
863
625
  } catch (e) {
@@ -872,29 +634,16 @@ var __objRest = (source, exclude) => {
872
634
  }
873
635
  };
874
636
  let formConfig = {};
875
- if (cms.api.tina.schema) {
876
- const enrichedSchema = cms.api.tina.schema;
877
- const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
878
- const template = enrichedSchema.getTemplateForData({
879
- collection,
880
- data: doc.values
881
- });
882
- const formInfo = schemaTools.resolveForm({
883
- collection,
884
- basename: collection.name,
885
- schema: enrichedSchema,
886
- template
887
- });
888
- formConfig = __spreadValues({
889
- label: formInfo.label,
890
- fields: formInfo.fields
891
- }, formCommon);
892
- } else {
893
- formConfig = __spreadValues({
894
- label: doc.form.label,
895
- fields: doc.form.fields
896
- }, formCommon);
897
- }
637
+ const formInfo = schemaTools.resolveForm({
638
+ collection,
639
+ basename: collection.name,
640
+ schema: enrichedSchema,
641
+ template
642
+ });
643
+ formConfig = __spreadValues({
644
+ label: formInfo.label,
645
+ fields: formInfo.fields
646
+ }, formCommon);
898
647
  if (formify2) {
899
648
  form = formify2({
900
649
  formConfig,
@@ -1013,7 +762,7 @@ var __objRest = (source, exclude) => {
1013
762
  }
1014
763
  return `[]`;
1015
764
  }).join(".");
1016
- const items = [blueprint.id, DATA_NODE_NAME$1, eventPath];
765
+ const items = [blueprint.id, eventPath];
1017
766
  const isList = event.field.data.tinaField.list;
1018
767
  if (isList && !eventPath.endsWith("[]")) {
1019
768
  items.push(`[]`);
@@ -1048,14 +797,13 @@ var __objRest = (source, exclude) => {
1048
797
  if (prefix) {
1049
798
  extra.push(prefix);
1050
799
  }
1051
- const matchName = [blueprintName, DATA_NODE_NAME$1, ...extra, fieldName].join(".");
800
+ const matchName = [blueprintName, ...extra, fieldName].join(".");
1052
801
  return { matchName, fieldName };
1053
802
  };
1054
803
  const getFormNodesFromEvent = (state, event) => {
1055
804
  const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
1056
805
  return formNodes;
1057
806
  };
1058
- const DATA_NODE_NAME$1 = "data";
1059
807
  const printEvent = (event) => {
1060
808
  var _a, _b;
1061
809
  return {
@@ -1261,14 +1009,14 @@ var __objRest = (source, exclude) => {
1261
1009
  }
1262
1010
  const node = G__namespace.parse(`
1263
1011
  query Sample {
1264
- _internalSys: sys {
1012
+ _internalSys: _sys {
1265
1013
  path
1014
+ relativePath
1266
1015
  collection {
1267
1016
  name
1268
1017
  }
1269
1018
  }
1270
- form
1271
- values
1019
+ _values
1272
1020
  }`);
1273
1021
  const metaFields = node.definitions[0].selectionSet.selections;
1274
1022
  const getRelativeBlueprint = (path) => {
@@ -1285,6 +1033,21 @@ var __objRest = (source, exclude) => {
1285
1033
  const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
1286
1034
  return getBlueprintNamePath({ path: documentBlueprintPath });
1287
1035
  };
1036
+ const isSysField = (fieldNode) => {
1037
+ if (fieldNode.name.value === "__typename") {
1038
+ return true;
1039
+ }
1040
+ if (fieldNode.name.value === "_sys") {
1041
+ return true;
1042
+ }
1043
+ if (fieldNode.name.value === "_values") {
1044
+ return true;
1045
+ }
1046
+ if (fieldNode.name.value === "id") {
1047
+ return true;
1048
+ }
1049
+ return false;
1050
+ };
1288
1051
  const getBlueprintId = (path) => {
1289
1052
  const namePath = [];
1290
1053
  const aliasPath = [];
@@ -1302,10 +1065,9 @@ var __objRest = (source, exclude) => {
1302
1065
  const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
1303
1066
  const EDGES_NODE_NAME = "edges";
1304
1067
  const NODE_NAME = "node";
1305
- const COLLECTION_FIELD_NAME = "getCollection";
1306
- const COLLECTIONS_FIELD_NAME = "getCollections";
1068
+ const COLLECTION_FIELD_NAME = "collection";
1069
+ const COLLECTIONS_FIELD_NAME = "collections";
1307
1070
  const COLLECTIONS_DOCUMENTS_NAME = "documents";
1308
- const DATA_NODE_NAME = "data";
1309
1071
  const formify = async ({
1310
1072
  schema,
1311
1073
  query,
@@ -1411,22 +1173,15 @@ var __objRest = (source, exclude) => {
1411
1173
  showInSidebar = false
1412
1174
  }) {
1413
1175
  let extraFields = [];
1414
- let hasDataJSONField = false;
1176
+ const hasDataJSONField = false;
1415
1177
  let hasValuesField = false;
1416
1178
  let shouldFormify = false;
1417
1179
  selection.selectionSet.selections.forEach((selection2) => {
1418
1180
  if (selection2.kind === "Field") {
1419
- if (selection2.name.value === "dataJSON") {
1420
- shouldFormify = true;
1421
- hasDataJSONField = true;
1422
- }
1423
- if (selection2.name.value === "values") {
1424
- shouldFormify = true;
1181
+ shouldFormify = true;
1182
+ if (selection2.name.value === "_values") {
1425
1183
  hasValuesField = true;
1426
1184
  }
1427
- if (selection2.name.value === "data") {
1428
- shouldFormify = true;
1429
- }
1430
1185
  }
1431
1186
  });
1432
1187
  if (shouldFormify) {
@@ -1465,33 +1220,11 @@ var __objRest = (source, exclude) => {
1465
1220
  });
1466
1221
  }
1467
1222
  case "Field": {
1468
- if (selectionNode.name.value === DATA_NODE_NAME) {
1469
- const field = getObjectField(type, selectionNode);
1470
- return __spreadProps(__spreadValues({}, selectionNode), {
1471
- selectionSet: {
1472
- kind: "SelectionSet",
1473
- selections: [
1474
- ...selectionNode.selectionSet.selections.map((subSelectionNode) => {
1475
- switch (subSelectionNode.kind) {
1476
- case "Field":
1477
- return formifyFieldNode({
1478
- fieldNode: subSelectionNode,
1479
- parentType: field.type,
1480
- path: buildPath({
1481
- fieldNode: selectionNode,
1482
- type: field.type,
1483
- path
1484
- })
1485
- });
1486
- default:
1487
- throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
1488
- }
1489
- })
1490
- ]
1491
- }
1492
- });
1493
- }
1494
- return selectionNode;
1223
+ return formifyFieldNode({
1224
+ fieldNode: selectionNode,
1225
+ parentType: type,
1226
+ path
1227
+ });
1495
1228
  }
1496
1229
  default:
1497
1230
  throw new FormifyError("UNEXPECTED");
@@ -1514,16 +1247,19 @@ var __objRest = (source, exclude) => {
1514
1247
  if (!field) {
1515
1248
  return fieldNode;
1516
1249
  }
1517
- const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
1518
- if (!blueprint) {
1519
- return fieldNode;
1520
- }
1521
1250
  const fieldPath = buildPath({
1522
1251
  fieldNode,
1523
1252
  type: field.type,
1524
1253
  parentTypename: G__namespace.getNamedType(parentType).name,
1525
1254
  path
1526
1255
  });
1256
+ const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(fieldPath));
1257
+ if (!blueprint) {
1258
+ return fieldNode;
1259
+ }
1260
+ if (isSysField(fieldNode)) {
1261
+ return fieldNode;
1262
+ }
1527
1263
  blueprint.fields.push({
1528
1264
  id: getBlueprintId(fieldPath),
1529
1265
  documentBlueprintId: blueprint.id,
@@ -2069,10 +1805,10 @@ var __objRest = (source, exclude) => {
2069
1805
  query Node($id: String!) {
2070
1806
  node(id: $id) {
2071
1807
  ...on Document {
2072
- form
2073
- values
2074
- _internalSys: sys {
1808
+ _values
1809
+ _internalSys: _sys {
2075
1810
  path
1811
+ relativePath
2076
1812
  collection {
2077
1813
  name
2078
1814
  }
@@ -2182,9 +1918,7 @@ var __objRest = (source, exclude) => {
2182
1918
  dispatch({
2183
1919
  type: "setIn",
2184
1920
  value: __spreadProps(__spreadValues({}, changeSet), {
2185
- value: __spreadProps(__spreadValues({}, res.node), {
2186
- data
2187
- })
1921
+ value: __spreadValues(__spreadValues({}, res.node), data)
2188
1922
  })
2189
1923
  });
2190
1924
  }).catch((e) => {
@@ -2303,10 +2037,10 @@ var __objRest = (source, exclude) => {
2303
2037
  query Node($id: String!) {
2304
2038
  node(id: $id) {
2305
2039
  ...on Document {
2306
- form
2307
- values
2308
- _internalSys: sys {
2040
+ _values
2041
+ _internalSys: _sys {
2309
2042
  path
2043
+ relativePath
2310
2044
  collection {
2311
2045
  name
2312
2046
  }
@@ -2344,13 +2078,11 @@ var __objRest = (source, exclude) => {
2344
2078
  }
2345
2079
  }
2346
2080
  `, { variables: { id: value } });
2347
- data[keyName] = __spreadProps(__spreadValues({}, res.node), {
2348
- data: await resolveSubFields({
2349
- formNode: subDocumentFormNode,
2350
- form: form2,
2351
- loc: location
2352
- })
2353
- });
2081
+ data[keyName] = __spreadValues(__spreadValues({}, res.node), await resolveSubFields({
2082
+ formNode: subDocumentFormNode,
2083
+ form: form2,
2084
+ loc: location
2085
+ }));
2354
2086
  });
2355
2087
  break;
2356
2088
  default:
@@ -2711,19 +2443,19 @@ mutation addPendingDocumentMutation(
2711
2443
  class TinaAdminApi {
2712
2444
  constructor(cms) {
2713
2445
  this.api = cms.api.tina;
2446
+ this.schema = cms.api.tina.schema;
2714
2447
  }
2715
2448
  async isAuthenticated() {
2716
2449
  return await this.api.isAuthenticated();
2717
2450
  }
2718
2451
  async fetchCollections() {
2719
- const response = await this.api.request(`#graphql
2720
- query{
2721
- getCollections {
2722
- label,
2723
- name
2724
- }
2725
- }`, { variables: {} });
2726
- return response;
2452
+ try {
2453
+ const collections = this.schema.getCollections();
2454
+ return collections;
2455
+ } catch (e) {
2456
+ console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
2457
+ return [];
2458
+ }
2727
2459
  }
2728
2460
  async deleteDocument({
2729
2461
  collection,
@@ -2737,9 +2469,10 @@ mutation addPendingDocumentMutation(
2737
2469
  }`, { variables: { collection, relativePath } });
2738
2470
  }
2739
2471
  async fetchCollection(collectionName, includeDocuments) {
2740
- const response = await this.api.request(`#graphql
2472
+ if (includeDocuments === true) {
2473
+ const response = await this.api.request(`#graphql
2741
2474
  query($collection: String!, $includeDocuments: Boolean!){
2742
- getCollection(collection: $collection){
2475
+ collection(collection: $collection){
2743
2476
  name
2744
2477
  label
2745
2478
  format
@@ -2749,7 +2482,7 @@ mutation addPendingDocumentMutation(
2749
2482
  edges {
2750
2483
  node {
2751
2484
  ... on Document {
2752
- sys {
2485
+ _sys {
2753
2486
  template
2754
2487
  breadcrumbs
2755
2488
  path
@@ -2764,27 +2497,28 @@ mutation addPendingDocumentMutation(
2764
2497
  }
2765
2498
  }
2766
2499
  }`, { variables: { collection: collectionName, includeDocuments } });
2767
- return response;
2500
+ return response.collection;
2501
+ } else {
2502
+ try {
2503
+ const collection = this.schema.getCollection(collectionName);
2504
+ return collection;
2505
+ } catch (e) {
2506
+ console.error(`[TinaAdminAPI] Unable to fetchCollection(): ${e.message}`);
2507
+ return void 0;
2508
+ }
2509
+ }
2768
2510
  }
2769
2511
  async fetchDocument(collectionName, relativePath) {
2770
2512
  const response = await this.api.request(`#graphql
2771
2513
  query($collection: String!, $relativePath: String!) {
2772
- getDocument(collection:$collection, relativePath:$relativePath) {
2514
+ document(collection:$collection, relativePath:$relativePath) {
2773
2515
  ... on Document {
2774
- form
2775
- values
2516
+ _values
2776
2517
  }
2777
2518
  }
2778
2519
  }`, { variables: { collection: collectionName, relativePath } });
2779
2520
  return response;
2780
2521
  }
2781
- async fetchDocumentFields() {
2782
- const response = await this.api.request(`#graphql
2783
- query {
2784
- getDocumentFields
2785
- }`, { variables: {} });
2786
- return response;
2787
- }
2788
2522
  async createDocument(collectionName, relativePath, params) {
2789
2523
  const response = await this.api.request(`#graphql
2790
2524
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
@@ -2805,7 +2539,7 @@ mutation addPendingDocumentMutation(
2805
2539
  async updateDocument(collectionName, relativePath, params) {
2806
2540
  const response = await this.api.request(`#graphql
2807
2541
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
2808
- updateDocument(
2542
+ updateDocument(
2809
2543
  collection: $collection,
2810
2544
  relativePath: $relativePath,
2811
2545
  params: $params
@@ -2996,7 +2730,7 @@ mutation addPendingDocumentMutation(
2996
2730
  } else {
2997
2731
  cms.alerts.info("Document created!");
2998
2732
  if (typeof this.onNewDocument === "function") {
2999
- this.onNewDocument(res.addPendingDocument.sys);
2733
+ this.onNewDocument(res.addPendingDocument._sys);
3000
2734
  }
3001
2735
  }
3002
2736
  } catch (e) {
@@ -3016,7 +2750,7 @@ mutation addPendingDocumentMutation(
3016
2750
  var _a;
3017
2751
  const res = await cms.api.tina.request((gql2) => gql2`
3018
2752
  {
3019
- getCollections {
2753
+ collections {
3020
2754
  label
3021
2755
  slug
3022
2756
  format
@@ -3025,7 +2759,7 @@ mutation addPendingDocumentMutation(
3025
2759
  }
3026
2760
  `, { variables: {} });
3027
2761
  const allCollectionOptions = [];
3028
- res.getCollections.forEach((collection) => {
2762
+ res.collections.forEach((collection) => {
3029
2763
  const value = collection.slug;
3030
2764
  const label = `${collection.label}`;
3031
2765
  allCollectionOptions.push({ value, label });
@@ -3047,7 +2781,7 @@ mutation addPendingDocumentMutation(
3047
2781
  { value: "", label: "Choose Template" }
3048
2782
  ];
3049
2783
  if (values.collection) {
3050
- const filteredCollection = res.getCollections.find((c) => c.slug === values.collection);
2784
+ const filteredCollection = res.collections.find((c) => c.slug === values.collection);
3051
2785
  (_a = filteredCollection == null ? void 0 : filteredCollection.templates) == null ? void 0 : _a.forEach((template) => {
3052
2786
  templateOptions.push({ value: template.name, label: template.label });
3053
2787
  });
@@ -3055,7 +2789,7 @@ mutation addPendingDocumentMutation(
3055
2789
  setPlugin(new ContentCreatorPlugin({
3056
2790
  label: "Add Document",
3057
2791
  onNewDocument: args && args.onNewDocument,
3058
- collections: res.getCollections,
2792
+ collections: res.collections,
3059
2793
  onChange: async ({ values: values2 }) => {
3060
2794
  setValues(values2);
3061
2795
  },
@@ -3152,6 +2886,30 @@ mutation addPendingDocumentMutation(
3152
2886
  isLoading
3153
2887
  };
3154
2888
  }
2889
+ const TINA_HOST = "content.tinajs.io";
2890
+ const parseURL = (url) => {
2891
+ if (url.includes("localhost")) {
2892
+ return { branch: null, isLocalClient: true, clientId: null };
2893
+ }
2894
+ const params = new URL(url);
2895
+ const pattern = new UrlPattern__default["default"]("/content/:clientId/github/*", {
2896
+ escapeChar: " "
2897
+ });
2898
+ const result = pattern.match(params.pathname);
2899
+ const branch = result == null ? void 0 : result._;
2900
+ const clientId = result == null ? void 0 : result.clientId;
2901
+ if (!branch || !clientId) {
2902
+ throw new Error(`Invalid URL format provided. Expected: https://content.tinajs.io/content/<ClientID>/github/<Branch> but but received ${url}`);
2903
+ }
2904
+ if (params.host !== TINA_HOST) {
2905
+ throw new Error(`The only supported hosts are ${TINA_HOST} or localhost, but received ${params.host}.`);
2906
+ }
2907
+ return {
2908
+ branch,
2909
+ clientId,
2910
+ isLocalClient: false
2911
+ };
2912
+ };
3155
2913
  const errorButtonStyles = {
3156
2914
  background: "#eb6337",
3157
2915
  padding: "12px 18px",
@@ -3231,21 +2989,6 @@ mutation addPendingDocumentMutation(
3231
2989
  return this.props.children;
3232
2990
  }
3233
2991
  }
3234
- const parseURL = (url) => {
3235
- if (url.includes("localhost")) {
3236
- return { branch: null, isLocalClient: true, clientId: null };
3237
- }
3238
- const tinaHost = "content.tinajs.io";
3239
- const params = new URL(url);
3240
- const pattern = new UrlPattern__default["default"]("/content/:clientId/github/:branch");
3241
- const result = pattern.match(params.pathname);
3242
- if (params.host !== tinaHost) {
3243
- throw new Error(`The only supported hosts are ${tinaHost} or localhost, but received ${params.host}.`);
3244
- }
3245
- return __spreadProps(__spreadValues({}, result), {
3246
- isLocalClient: false
3247
- });
3248
- };
3249
2992
  const TinaCMSProvider2 = (_c) => {
3250
2993
  var _d = _c, {
3251
2994
  query,
@@ -3267,6 +3010,9 @@ mutation addPendingDocumentMutation(
3267
3010
  clientId: props.clientId,
3268
3011
  isLocalClient: props.isLocalClient
3269
3012
  };
3013
+ if (!schema) {
3014
+ throw new Error("`schema` is required to be passed as a property to `TinaProvider`. You can learn more about this change here: https://github.com/tinacms/tinacms/pull/2823");
3015
+ }
3270
3016
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(TinaCloudProvider, {
3271
3017
  branch,
3272
3018
  clientId,
@@ -3316,25 +3062,13 @@ mutation addPendingDocumentMutation(
3316
3062
  payload: void 0,
3317
3063
  isLoading: true
3318
3064
  });
3319
- const cms = toolkit.useCMS();
3320
- const useUnstableFormify = React__default["default"].useMemo(() => {
3321
- if ((cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false) {
3322
- return false;
3323
- }
3324
- return true;
3325
- }, [cms == null ? void 0 : cms.flags]);
3326
3065
  return /* @__PURE__ */ React__default["default"].createElement(sharedctx.TinaDataContext.Provider, {
3327
3066
  value: {
3328
3067
  setRequest,
3329
3068
  isLoading: state.isLoading,
3330
3069
  state: { payload: state.payload }
3331
3070
  }
3332
- }, useUnstableFormify ? /* @__PURE__ */ React__default["default"].createElement(FormRegistrarUnstable, {
3333
- key: request == null ? void 0 : request.query,
3334
- request,
3335
- formifyCallback,
3336
- onPayloadStateChange: setState
3337
- }) : /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
3071
+ }, /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
3338
3072
  key: request == null ? void 0 : request.query,
3339
3073
  request,
3340
3074
  formifyCallback,
@@ -3363,35 +3097,6 @@ mutation addPendingDocumentMutation(
3363
3097
  }, [JSON.stringify(payload), isLoading]);
3364
3098
  return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
3365
3099
  };
3366
- const FormRegistrarUnstable = (props) => {
3367
- var _a;
3368
- if (!((_a = props.request) == null ? void 0 : _a.query)) {
3369
- return null;
3370
- }
3371
- return /* @__PURE__ */ React__default["default"].createElement(FormRegistrarUnstableInner, __spreadValues({}, props));
3372
- };
3373
- const FormRegistrarUnstableInner = ({
3374
- request,
3375
- formifyCallback,
3376
- onPayloadStateChange
3377
- }) => {
3378
- const cms = toolkit.useCMS();
3379
- const [payload, isLoading] = useGraphqlFormsUnstable({
3380
- query: request == null ? void 0 : request.query,
3381
- variables: request == null ? void 0 : request.variables,
3382
- formify: (args) => {
3383
- if (formifyCallback) {
3384
- return formifyCallback(args, cms);
3385
- } else {
3386
- return args.createForm(args.formConfig);
3387
- }
3388
- }
3389
- });
3390
- React__default["default"].useEffect(() => {
3391
- onPayloadStateChange({ payload, isLoading });
3392
- }, [JSON.stringify(payload), isLoading]);
3393
- return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
3394
- };
3395
3100
  const Loader = (props) => {
3396
3101
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("div", {
3397
3102
  style: {
@@ -3636,8 +3341,8 @@ This will work when developing locally but NOT when deployed to production.
3636
3341
  const fetchCollections = async () => {
3637
3342
  if (await api.isAuthenticated()) {
3638
3343
  try {
3639
- const response = await api.fetchCollections();
3640
- setCollections(response.getCollections);
3344
+ const collections2 = await api.fetchCollections();
3345
+ setCollections(collections2);
3641
3346
  } catch (error2) {
3642
3347
  console.error(error2);
3643
3348
  setCollections([]);
@@ -3940,8 +3645,8 @@ This will work when developing locally but NOT when deployed to production.
3940
3645
  const fetchCollection = async () => {
3941
3646
  if (await api.isAuthenticated()) {
3942
3647
  try {
3943
- const response = await api.fetchCollection(collectionName, includeDocuments);
3944
- setCollection(response.getCollection);
3648
+ const collection2 = await api.fetchCollection(collectionName, includeDocuments);
3649
+ setCollection(collection2);
3945
3650
  } catch (error2) {
3946
3651
  cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
3947
3652
  console.error(error2);
@@ -4007,7 +3712,7 @@ This will work when developing locally but NOT when deployed to production.
4007
3712
  window.location.href = routeOverride;
4008
3713
  return null;
4009
3714
  } else {
4010
- navigate(document.sys.breadcrumbs.join("/"));
3715
+ navigate(document._sys.breadcrumbs.join("/"));
4011
3716
  }
4012
3717
  };
4013
3718
  const CollectionListPage = () => {
@@ -4060,9 +3765,9 @@ This will work when developing locally but NOT when deployed to production.
4060
3765
  }, /* @__PURE__ */ React__default["default"].createElement("tbody", {
4061
3766
  className: "divide-y divide-gray-150"
4062
3767
  }, documents.map((document) => {
4063
- const subfolders = document.node.sys.breadcrumbs.slice(0, -1).join("/");
3768
+ const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
4064
3769
  return /* @__PURE__ */ React__default["default"].createElement("tr", {
4065
- key: `document-${document.node.sys.relativePath}`,
3770
+ key: `document-${document.node._sys.relativePath}`,
4066
3771
  className: ""
4067
3772
  }, /* @__PURE__ */ React__default["default"].createElement("td", {
4068
3773
  className: "px-6 py-2 whitespace-nowrap"
@@ -4079,19 +3784,19 @@ This will work when developing locally but NOT when deployed to production.
4079
3784
  className: "h-5 leading-5 block whitespace-nowrap"
4080
3785
  }, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
4081
3786
  className: "text-xs text-gray-400"
4082
- }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node.sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
3787
+ }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
4083
3788
  className: "px-6 py-4 whitespace-nowrap"
4084
3789
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
4085
3790
  className: "block text-xs text-gray-400 mb-1 uppercase"
4086
3791
  }, "Extension"), /* @__PURE__ */ React__default["default"].createElement("span", {
4087
3792
  className: "h-5 leading-5 block text-sm font-medium text-gray-900"
4088
- }, document.node.sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
3793
+ }, document.node._sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
4089
3794
  className: "px-6 py-4 whitespace-nowrap"
4090
3795
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
4091
3796
  className: "block text-xs text-gray-400 mb-1 uppercase"
4092
3797
  }, "Template"), /* @__PURE__ */ React__default["default"].createElement("span", {
4093
3798
  className: "h-5 leading-5 block text-sm font-medium text-gray-900"
4094
- }, document.node.sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
3799
+ }, document.node._sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
4095
3800
  className: "w-0"
4096
3801
  }, /* @__PURE__ */ React__default["default"].createElement(toolkit.OverflowMenu, {
4097
3802
  showEmbed: true,
@@ -4103,7 +3808,7 @@ This will work when developing locally but NOT when deployed to production.
4103
3808
  size: "1.3rem"
4104
3809
  }),
4105
3810
  onMouseDown: () => {
4106
- navigate(`${document.node.sys.filename}`, { replace: true });
3811
+ navigate(`${document.node._sys.filename}`, { replace: true });
4107
3812
  }
4108
3813
  },
4109
3814
  {
@@ -4116,7 +3821,7 @@ This will work when developing locally but NOT when deployed to production.
4116
3821
  onMouseDown: () => {
4117
3822
  setVars({
4118
3823
  collection: collectionName,
4119
- relativePath: document.node.sys.filename + document.node.sys.extension
3824
+ relativePath: document.node._sys.filename + document.node._sys.extension
4120
3825
  });
4121
3826
  setOpen(true);
4122
3827
  }
@@ -4130,7 +3835,7 @@ This will work when developing locally but NOT when deployed to production.
4130
3835
  const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
4131
3836
  return /* @__PURE__ */ React__default["default"].createElement(toolkit.Modal, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalPopup, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalHeader, {
4132
3837
  close: close2
4133
- }, "Reset"), /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalBody, {
3838
+ }, "Delete ", filename), /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalBody, {
4134
3839
  padded: true
4135
3840
  }, /* @__PURE__ */ React__default["default"].createElement("p", null, `Are you sure you want to delete ${filename}?`)), /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalActions, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.Button, {
4136
3841
  style: { flexGrow: 2 },
@@ -4144,72 +3849,6 @@ This will work when developing locally but NOT when deployed to production.
4144
3849
  }
4145
3850
  }, "Delete"))));
4146
3851
  };
4147
- const useGetDocumentFields = (cms, collectionName, templateName) => {
4148
- const api = new TinaAdminApi(cms);
4149
- const [info, setInfo] = React.useState({
4150
- collection: void 0,
4151
- template: void 0,
4152
- fields: void 0,
4153
- mutationInfo: void 0
4154
- });
4155
- const [loading, setLoading] = React.useState(true);
4156
- const [error, setError] = React.useState(void 0);
4157
- React.useEffect(() => {
4158
- const fetchDocumentFields = async () => {
4159
- if (await api.isAuthenticated()) {
4160
- try {
4161
- const response = await api.fetchDocumentFields();
4162
- const documentFields = response.getDocumentFields;
4163
- const collection = documentFields[collectionName].collection;
4164
- const mutationInfo = documentFields[collectionName].mutationInfo;
4165
- let fields = void 0;
4166
- let template = void 0;
4167
- if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
4168
- template = documentFields[collectionName].templates[templateName].template;
4169
- fields = documentFields[collectionName].templates[templateName].fields;
4170
- } else {
4171
- fields = documentFields[collectionName].fields;
4172
- }
4173
- setInfo({
4174
- collection,
4175
- template,
4176
- fields,
4177
- mutationInfo
4178
- });
4179
- } catch (error2) {
4180
- cms.alerts.error(`[${error2.name}] GetDocumentFields failed: ${error2.message}`, 30 * 1e3);
4181
- console.error(error2);
4182
- setInfo({
4183
- collection: void 0,
4184
- template: void 0,
4185
- fields: void 0,
4186
- mutationInfo: void 0
4187
- });
4188
- setError(error2);
4189
- }
4190
- setLoading(false);
4191
- }
4192
- };
4193
- setLoading(true);
4194
- fetchDocumentFields();
4195
- }, [cms, collectionName]);
4196
- return __spreadProps(__spreadValues({}, info), { loading, error });
4197
- };
4198
- const GetDocumentFields = ({
4199
- cms,
4200
- collectionName,
4201
- templateName,
4202
- children
4203
- }) => {
4204
- const { collection, template, fields, mutationInfo, loading, error } = useGetDocumentFields(cms, collectionName, templateName);
4205
- if (error) {
4206
- return null;
4207
- }
4208
- if (loading) {
4209
- return /* @__PURE__ */ React__default["default"].createElement(LoadingPage, null);
4210
- }
4211
- return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children({ collection, template, fields, mutationInfo, loading }));
4212
- };
4213
3852
  function HiChevronRight(props) {
4214
3853
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 20 20", "fill": "currentColor" }, "child": [{ "tag": "path", "attr": { "fillRule": "evenodd", "d": "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z", "clipRule": "evenodd" } }] })(props);
4215
3854
  }
@@ -4235,38 +3874,39 @@ This will work when developing locally but NOT when deployed to production.
4235
3874
  };
4236
3875
  const CollectionCreatePage = () => {
4237
3876
  const { collectionName, templateName } = reactRouterDom.useParams();
4238
- return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
3877
+ return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
4239
3878
  cms,
4240
3879
  collectionName,
4241
- templateName
4242
- }, ({ collection, template, fields, mutationInfo }) => /* @__PURE__ */ React__default["default"].createElement(RenderForm$1, {
4243
- cms,
4244
- collection,
4245
- template,
4246
- fields,
4247
- mutationInfo
4248
- })));
3880
+ includeDocuments: false
3881
+ }, (collection) => {
3882
+ const mutationInfo = {
3883
+ includeCollection: true,
3884
+ includeTemplate: !!collection.templates
3885
+ };
3886
+ return /* @__PURE__ */ React__default["default"].createElement(RenderForm$1, {
3887
+ cms,
3888
+ collection,
3889
+ templateName,
3890
+ mutationInfo
3891
+ });
3892
+ }));
4249
3893
  };
4250
- const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
3894
+ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
4251
3895
  var _a, _b;
4252
3896
  const navigate = reactRouterDom.useNavigate();
4253
3897
  const [formIsPristine, setFormIsPristine] = React.useState(true);
4254
3898
  const schema = cms.api.tina.schema;
4255
- let schemaFields = fields;
4256
- if (schema) {
4257
- const schemaCollection = schema.getCollection(collection.name);
4258
- const template2 = schema.getTemplateForData({
4259
- collection: schemaCollection,
4260
- data: {}
4261
- });
4262
- const formInfo = schemaTools.resolveForm({
4263
- collection: schemaCollection,
4264
- basename: schemaCollection.name,
4265
- schema,
4266
- template: template2
4267
- });
4268
- schemaFields = formInfo.fields;
4269
- }
3899
+ const schemaCollection = schema.getCollection(collection.name);
3900
+ const template = schema.getTemplateForData({
3901
+ collection: schemaCollection,
3902
+ data: { _template: templateName }
3903
+ });
3904
+ const formInfo = schemaTools.resolveForm({
3905
+ collection: schemaCollection,
3906
+ basename: schemaCollection.name,
3907
+ schema,
3908
+ template
3909
+ });
4270
3910
  const form = React.useMemo(() => {
4271
3911
  return new toolkit.Form({
4272
3912
  id: "create-form",
@@ -4291,7 +3931,7 @@ This will work when developing locally but NOT when deployed to production.
4291
3931
  }
4292
3932
  }
4293
3933
  },
4294
- ...schemaFields
3934
+ ...formInfo.fields
4295
3935
  ],
4296
3936
  onSubmit: async (values) => {
4297
3937
  try {
@@ -4304,7 +3944,7 @@ This will work when developing locally but NOT when deployed to production.
4304
3944
  }
4305
3945
  }
4306
3946
  });
4307
- }, [cms, collection, template, fields, mutationInfo]);
3947
+ }, [cms, collection, mutationInfo]);
4308
3948
  return /* @__PURE__ */ React__default["default"].createElement(PageWrapper, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, ((_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.isLocalMode) && /* @__PURE__ */ React__default["default"].createElement(toolkit.LocalWarning, null), /* @__PURE__ */ React__default["default"].createElement("div", {
4309
3949
  className: "py-4 px-20 border-b border-gray-200 bg-white"
4310
3950
  }, /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -4337,7 +3977,7 @@ This will work when developing locally but NOT when deployed to production.
4337
3977
  if (api.isAuthenticated()) {
4338
3978
  try {
4339
3979
  const response = await api.fetchDocument(collectionName, relativePath);
4340
- setDocument(response.getDocument);
3980
+ setDocument(response.document);
4341
3981
  } catch (error2) {
4342
3982
  cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
4343
3983
  console.error(error2);
@@ -4386,11 +4026,16 @@ This will work when developing locally but NOT when deployed to production.
4386
4026
  const CollectionUpdatePage = () => {
4387
4027
  const _a = reactRouterDom.useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
4388
4028
  const { "*": filename } = rest;
4389
- return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
4029
+ return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
4390
4030
  cms,
4391
- collectionName
4392
- }, ({ collection, mutationInfo }) => {
4031
+ collectionName,
4032
+ includeDocuments: false
4033
+ }, (collection) => {
4393
4034
  const relativePath = `${filename}.${collection.format}`;
4035
+ const mutationInfo = {
4036
+ includeCollection: true,
4037
+ includeTemplate: !!collection.templates
4038
+ };
4394
4039
  return /* @__PURE__ */ React__default["default"].createElement(GetDocument, {
4395
4040
  cms,
4396
4041
  collectionName: collection.name,
@@ -4416,27 +4061,23 @@ This will work when developing locally but NOT when deployed to production.
4416
4061
  var _a, _b;
4417
4062
  const [formIsPristine, setFormIsPristine] = React.useState(true);
4418
4063
  const schema = cms.api.tina.schema;
4419
- let schemaFields = document.form.fields;
4420
- if (schema) {
4421
- const schemaCollection = schema.getCollection(collection.name);
4422
- const template = schema.getTemplateForData({
4423
- collection: schemaCollection,
4424
- data: document.value
4425
- });
4426
- const formInfo = schemaTools.resolveForm({
4427
- collection: schemaCollection,
4428
- basename: schemaCollection.name,
4429
- schema,
4430
- template
4431
- });
4432
- schemaFields = formInfo.fields;
4433
- }
4064
+ const schemaCollection = schema.getCollection(collection.name);
4065
+ const template = schema.getTemplateForData({
4066
+ collection: schemaCollection,
4067
+ data: document._values
4068
+ });
4069
+ const formInfo = schemaTools.resolveForm({
4070
+ collection: schemaCollection,
4071
+ basename: schemaCollection.name,
4072
+ schema,
4073
+ template
4074
+ });
4434
4075
  const form = React.useMemo(() => {
4435
4076
  return new toolkit.Form({
4436
4077
  id: "update-form",
4437
4078
  label: "form",
4438
- fields: schemaFields,
4439
- initialValues: document.values,
4079
+ fields: formInfo.fields,
4080
+ initialValues: document._values,
4440
4081
  onSubmit: async (values) => {
4441
4082
  try {
4442
4083
  await updateDocument(cms, relativePath, collection, mutationInfo, values);
@@ -4578,7 +4219,6 @@ This will work when developing locally but NOT when deployed to production.
4578
4219
  exports2.staticRequest = staticRequest;
4579
4220
  exports2.useDocumentCreatorPlugin = useDocumentCreatorPlugin;
4580
4221
  exports2.useGraphqlForms = useGraphqlForms;
4581
- exports2.useGraphqlFormsUnstable = useGraphqlFormsUnstable;
4582
4222
  exports2.useTinaAuthRedirect = useTinaAuthRedirect;
4583
4223
  Object.keys(toolkit).forEach(function(k) {
4584
4224
  if (k !== "default" && !exports2.hasOwnProperty(k))