tinacms 0.67.4 → 0.68.2

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,
@@ -444,241 +444,11 @@ var __objRest = (source, exclude) => {
444
444
  eventList,
445
445
  onSubmit
446
446
  });
447
+ if (!query) {
448
+ return [state.data, false];
449
+ }
447
450
  return [state.data, state.status !== "done"];
448
451
  }
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
452
  const transformDocumentIntoMutationRequestPayload = (document, instructions) => {
683
453
  const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
684
454
  const params = transformParams(rest);
@@ -715,37 +485,7 @@ var __objRest = (source, exclude) => {
715
485
  }
716
486
  }
717
487
  };
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) => {
488
+ const generateFormCreators = (cms, showInSidebar) => {
749
489
  const createForm = (formConfig) => {
750
490
  const form = new toolkit.Form(formConfig);
751
491
  if (showInSidebar) {
@@ -829,7 +569,7 @@ var __objRest = (source, exclude) => {
829
569
  return accum.join(".");
830
570
  };
831
571
  const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
832
- const { createForm, createGlobalForm } = generateFormCreatorsUnstable(cms, showInSidebar);
572
+ const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
833
573
  const SKIPPED = "SKIPPED";
834
574
  let form;
835
575
  let skipped;
@@ -839,25 +579,50 @@ var __objRest = (source, exclude) => {
839
579
  if (skipped)
840
580
  return;
841
581
  const id = doc._internalSys.path;
582
+ const enrichedSchema = cms.api.tina.schema;
583
+ const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
584
+ const template = enrichedSchema.getTemplateForData({
585
+ collection,
586
+ data: doc._values
587
+ });
842
588
  const formCommon = {
843
589
  id,
844
- label: doc.form.label,
845
- initialValues: doc.values,
590
+ label: id,
591
+ initialValues: doc._values,
846
592
  onSubmit: async (payload) => {
847
593
  try {
848
- const params = transformDocumentIntoMutationRequestPayload(payload, doc.form.mutationInfo);
594
+ const params = transformDocumentIntoMutationRequestPayload(payload, {
595
+ includeCollection: false,
596
+ includeTemplate: !!collection.templates
597
+ });
849
598
  const variables = { params };
850
- const mutationString = doc.form.mutationInfo.string;
599
+ const mutationString = `#graphql
600
+ mutation UpdateDocument($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
601
+ updateDocument(collection: $collection, relativePath: $relativePath, params: $params) {
602
+ __typename
603
+ }
604
+ }
605
+ `;
851
606
  if (onSubmit) {
852
607
  onSubmit({
853
608
  queryString: mutationString,
854
609
  mutationString,
855
- variables
610
+ variables: {
611
+ collection: doc._internalSys.collection.name,
612
+ relativePath: doc._internalSys.relativePath,
613
+ params: { [doc._internalSys.collection.name]: variables }
614
+ }
856
615
  });
857
616
  } else {
858
617
  try {
859
618
  await cms.api.tina.request(mutationString, {
860
- variables
619
+ variables: {
620
+ collection: doc._internalSys.collection.name,
621
+ relativePath: doc._internalSys.relativePath,
622
+ params: {
623
+ [doc._internalSys.collection.name]: variables.params
624
+ }
625
+ }
861
626
  });
862
627
  cms.alerts.success("Document saved!");
863
628
  } catch (e) {
@@ -872,29 +637,16 @@ var __objRest = (source, exclude) => {
872
637
  }
873
638
  };
874
639
  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
- }
640
+ const formInfo = schemaTools.resolveForm({
641
+ collection,
642
+ basename: collection.name,
643
+ schema: enrichedSchema,
644
+ template
645
+ });
646
+ formConfig = __spreadValues({
647
+ label: formInfo.label,
648
+ fields: formInfo.fields
649
+ }, formCommon);
898
650
  if (formify2) {
899
651
  form = formify2({
900
652
  formConfig,
@@ -1013,7 +765,7 @@ var __objRest = (source, exclude) => {
1013
765
  }
1014
766
  return `[]`;
1015
767
  }).join(".");
1016
- const items = [blueprint.id, DATA_NODE_NAME$1, eventPath];
768
+ const items = [blueprint.id, eventPath];
1017
769
  const isList = event.field.data.tinaField.list;
1018
770
  if (isList && !eventPath.endsWith("[]")) {
1019
771
  items.push(`[]`);
@@ -1048,14 +800,13 @@ var __objRest = (source, exclude) => {
1048
800
  if (prefix) {
1049
801
  extra.push(prefix);
1050
802
  }
1051
- const matchName = [blueprintName, DATA_NODE_NAME$1, ...extra, fieldName].join(".");
803
+ const matchName = [blueprintName, ...extra, fieldName].join(".");
1052
804
  return { matchName, fieldName };
1053
805
  };
1054
806
  const getFormNodesFromEvent = (state, event) => {
1055
807
  const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
1056
808
  return formNodes;
1057
809
  };
1058
- const DATA_NODE_NAME$1 = "data";
1059
810
  const printEvent = (event) => {
1060
811
  var _a, _b;
1061
812
  return {
@@ -1261,14 +1012,14 @@ var __objRest = (source, exclude) => {
1261
1012
  }
1262
1013
  const node = G__namespace.parse(`
1263
1014
  query Sample {
1264
- _internalSys: sys {
1015
+ _internalSys: _sys {
1265
1016
  path
1017
+ relativePath
1266
1018
  collection {
1267
1019
  name
1268
1020
  }
1269
1021
  }
1270
- form
1271
- values
1022
+ _values
1272
1023
  }`);
1273
1024
  const metaFields = node.definitions[0].selectionSet.selections;
1274
1025
  const getRelativeBlueprint = (path) => {
@@ -1285,6 +1036,21 @@ var __objRest = (source, exclude) => {
1285
1036
  const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
1286
1037
  return getBlueprintNamePath({ path: documentBlueprintPath });
1287
1038
  };
1039
+ const isSysField = (fieldNode) => {
1040
+ if (fieldNode.name.value === "__typename") {
1041
+ return true;
1042
+ }
1043
+ if (fieldNode.name.value === "_sys") {
1044
+ return true;
1045
+ }
1046
+ if (fieldNode.name.value === "_values") {
1047
+ return true;
1048
+ }
1049
+ if (fieldNode.name.value === "id") {
1050
+ return true;
1051
+ }
1052
+ return false;
1053
+ };
1288
1054
  const getBlueprintId = (path) => {
1289
1055
  const namePath = [];
1290
1056
  const aliasPath = [];
@@ -1302,10 +1068,9 @@ var __objRest = (source, exclude) => {
1302
1068
  const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
1303
1069
  const EDGES_NODE_NAME = "edges";
1304
1070
  const NODE_NAME = "node";
1305
- const COLLECTION_FIELD_NAME = "getCollection";
1306
- const COLLECTIONS_FIELD_NAME = "getCollections";
1071
+ const COLLECTION_FIELD_NAME = "collection";
1072
+ const COLLECTIONS_FIELD_NAME = "collections";
1307
1073
  const COLLECTIONS_DOCUMENTS_NAME = "documents";
1308
- const DATA_NODE_NAME = "data";
1309
1074
  const formify = async ({
1310
1075
  schema,
1311
1076
  query,
@@ -1411,22 +1176,15 @@ var __objRest = (source, exclude) => {
1411
1176
  showInSidebar = false
1412
1177
  }) {
1413
1178
  let extraFields = [];
1414
- let hasDataJSONField = false;
1179
+ const hasDataJSONField = false;
1415
1180
  let hasValuesField = false;
1416
1181
  let shouldFormify = false;
1417
1182
  selection.selectionSet.selections.forEach((selection2) => {
1418
1183
  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;
1184
+ shouldFormify = true;
1185
+ if (selection2.name.value === "_values") {
1425
1186
  hasValuesField = true;
1426
1187
  }
1427
- if (selection2.name.value === "data") {
1428
- shouldFormify = true;
1429
- }
1430
1188
  }
1431
1189
  });
1432
1190
  if (shouldFormify) {
@@ -1465,33 +1223,11 @@ var __objRest = (source, exclude) => {
1465
1223
  });
1466
1224
  }
1467
1225
  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;
1226
+ return formifyFieldNode({
1227
+ fieldNode: selectionNode,
1228
+ parentType: type,
1229
+ path
1230
+ });
1495
1231
  }
1496
1232
  default:
1497
1233
  throw new FormifyError("UNEXPECTED");
@@ -1514,16 +1250,19 @@ var __objRest = (source, exclude) => {
1514
1250
  if (!field) {
1515
1251
  return fieldNode;
1516
1252
  }
1517
- const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
1518
- if (!blueprint) {
1519
- return fieldNode;
1520
- }
1521
1253
  const fieldPath = buildPath({
1522
1254
  fieldNode,
1523
1255
  type: field.type,
1524
1256
  parentTypename: G__namespace.getNamedType(parentType).name,
1525
1257
  path
1526
1258
  });
1259
+ const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(fieldPath));
1260
+ if (!blueprint) {
1261
+ return fieldNode;
1262
+ }
1263
+ if (isSysField(fieldNode)) {
1264
+ return fieldNode;
1265
+ }
1527
1266
  blueprint.fields.push({
1528
1267
  id: getBlueprintId(fieldPath),
1529
1268
  documentBlueprintId: blueprint.id,
@@ -2069,10 +1808,10 @@ var __objRest = (source, exclude) => {
2069
1808
  query Node($id: String!) {
2070
1809
  node(id: $id) {
2071
1810
  ...on Document {
2072
- form
2073
- values
2074
- _internalSys: sys {
1811
+ _values
1812
+ _internalSys: _sys {
2075
1813
  path
1814
+ relativePath
2076
1815
  collection {
2077
1816
  name
2078
1817
  }
@@ -2182,9 +1921,7 @@ var __objRest = (source, exclude) => {
2182
1921
  dispatch({
2183
1922
  type: "setIn",
2184
1923
  value: __spreadProps(__spreadValues({}, changeSet), {
2185
- value: __spreadProps(__spreadValues({}, res.node), {
2186
- data
2187
- })
1924
+ value: __spreadValues(__spreadValues({}, res.node), data)
2188
1925
  })
2189
1926
  });
2190
1927
  }).catch((e) => {
@@ -2303,10 +2040,10 @@ var __objRest = (source, exclude) => {
2303
2040
  query Node($id: String!) {
2304
2041
  node(id: $id) {
2305
2042
  ...on Document {
2306
- form
2307
- values
2308
- _internalSys: sys {
2043
+ _values
2044
+ _internalSys: _sys {
2309
2045
  path
2046
+ relativePath
2310
2047
  collection {
2311
2048
  name
2312
2049
  }
@@ -2344,13 +2081,11 @@ var __objRest = (source, exclude) => {
2344
2081
  }
2345
2082
  }
2346
2083
  `, { 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
- });
2084
+ data[keyName] = __spreadValues(__spreadValues({}, res.node), await resolveSubFields({
2085
+ formNode: subDocumentFormNode,
2086
+ form: form2,
2087
+ loc: location
2088
+ }));
2354
2089
  });
2355
2090
  break;
2356
2091
  default:
@@ -2711,19 +2446,19 @@ mutation addPendingDocumentMutation(
2711
2446
  class TinaAdminApi {
2712
2447
  constructor(cms) {
2713
2448
  this.api = cms.api.tina;
2449
+ this.schema = cms.api.tina.schema;
2714
2450
  }
2715
2451
  async isAuthenticated() {
2716
2452
  return await this.api.isAuthenticated();
2717
2453
  }
2718
2454
  async fetchCollections() {
2719
- const response = await this.api.request(`#graphql
2720
- query{
2721
- getCollections {
2722
- label,
2723
- name
2724
- }
2725
- }`, { variables: {} });
2726
- return response;
2455
+ try {
2456
+ const collections = this.schema.getCollections();
2457
+ return collections;
2458
+ } catch (e) {
2459
+ console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
2460
+ return [];
2461
+ }
2727
2462
  }
2728
2463
  async deleteDocument({
2729
2464
  collection,
@@ -2737,9 +2472,10 @@ mutation addPendingDocumentMutation(
2737
2472
  }`, { variables: { collection, relativePath } });
2738
2473
  }
2739
2474
  async fetchCollection(collectionName, includeDocuments) {
2740
- const response = await this.api.request(`#graphql
2475
+ if (includeDocuments === true) {
2476
+ const response = await this.api.request(`#graphql
2741
2477
  query($collection: String!, $includeDocuments: Boolean!){
2742
- getCollection(collection: $collection){
2478
+ collection(collection: $collection){
2743
2479
  name
2744
2480
  label
2745
2481
  format
@@ -2749,7 +2485,7 @@ mutation addPendingDocumentMutation(
2749
2485
  edges {
2750
2486
  node {
2751
2487
  ... on Document {
2752
- sys {
2488
+ _sys {
2753
2489
  template
2754
2490
  breadcrumbs
2755
2491
  path
@@ -2764,27 +2500,28 @@ mutation addPendingDocumentMutation(
2764
2500
  }
2765
2501
  }
2766
2502
  }`, { variables: { collection: collectionName, includeDocuments } });
2767
- return response;
2503
+ return response.collection;
2504
+ } else {
2505
+ try {
2506
+ const collection = this.schema.getCollection(collectionName);
2507
+ return collection;
2508
+ } catch (e) {
2509
+ console.error(`[TinaAdminAPI] Unable to fetchCollection(): ${e.message}`);
2510
+ return void 0;
2511
+ }
2512
+ }
2768
2513
  }
2769
2514
  async fetchDocument(collectionName, relativePath) {
2770
2515
  const response = await this.api.request(`#graphql
2771
2516
  query($collection: String!, $relativePath: String!) {
2772
- getDocument(collection:$collection, relativePath:$relativePath) {
2517
+ document(collection:$collection, relativePath:$relativePath) {
2773
2518
  ... on Document {
2774
- form
2775
- values
2519
+ _values
2776
2520
  }
2777
2521
  }
2778
2522
  }`, { variables: { collection: collectionName, relativePath } });
2779
2523
  return response;
2780
2524
  }
2781
- async fetchDocumentFields() {
2782
- const response = await this.api.request(`#graphql
2783
- query {
2784
- getDocumentFields
2785
- }`, { variables: {} });
2786
- return response;
2787
- }
2788
2525
  async createDocument(collectionName, relativePath, params) {
2789
2526
  const response = await this.api.request(`#graphql
2790
2527
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
@@ -2805,7 +2542,7 @@ mutation addPendingDocumentMutation(
2805
2542
  async updateDocument(collectionName, relativePath, params) {
2806
2543
  const response = await this.api.request(`#graphql
2807
2544
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
2808
- updateDocument(
2545
+ updateDocument(
2809
2546
  collection: $collection,
2810
2547
  relativePath: $relativePath,
2811
2548
  params: $params
@@ -2996,7 +2733,7 @@ mutation addPendingDocumentMutation(
2996
2733
  } else {
2997
2734
  cms.alerts.info("Document created!");
2998
2735
  if (typeof this.onNewDocument === "function") {
2999
- this.onNewDocument(res.addPendingDocument.sys);
2736
+ this.onNewDocument(res.addPendingDocument._sys);
3000
2737
  }
3001
2738
  }
3002
2739
  } catch (e) {
@@ -3016,7 +2753,7 @@ mutation addPendingDocumentMutation(
3016
2753
  var _a;
3017
2754
  const res = await cms.api.tina.request((gql2) => gql2`
3018
2755
  {
3019
- getCollections {
2756
+ collections {
3020
2757
  label
3021
2758
  slug
3022
2759
  format
@@ -3025,7 +2762,7 @@ mutation addPendingDocumentMutation(
3025
2762
  }
3026
2763
  `, { variables: {} });
3027
2764
  const allCollectionOptions = [];
3028
- res.getCollections.forEach((collection) => {
2765
+ res.collections.forEach((collection) => {
3029
2766
  const value = collection.slug;
3030
2767
  const label = `${collection.label}`;
3031
2768
  allCollectionOptions.push({ value, label });
@@ -3047,7 +2784,7 @@ mutation addPendingDocumentMutation(
3047
2784
  { value: "", label: "Choose Template" }
3048
2785
  ];
3049
2786
  if (values.collection) {
3050
- const filteredCollection = res.getCollections.find((c) => c.slug === values.collection);
2787
+ const filteredCollection = res.collections.find((c) => c.slug === values.collection);
3051
2788
  (_a = filteredCollection == null ? void 0 : filteredCollection.templates) == null ? void 0 : _a.forEach((template) => {
3052
2789
  templateOptions.push({ value: template.name, label: template.label });
3053
2790
  });
@@ -3055,7 +2792,7 @@ mutation addPendingDocumentMutation(
3055
2792
  setPlugin(new ContentCreatorPlugin({
3056
2793
  label: "Add Document",
3057
2794
  onNewDocument: args && args.onNewDocument,
3058
- collections: res.getCollections,
2795
+ collections: res.collections,
3059
2796
  onChange: async ({ values: values2 }) => {
3060
2797
  setValues(values2);
3061
2798
  },
@@ -3276,6 +3013,9 @@ mutation addPendingDocumentMutation(
3276
3013
  clientId: props.clientId,
3277
3014
  isLocalClient: props.isLocalClient
3278
3015
  };
3016
+ if (!schema) {
3017
+ 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");
3018
+ }
3279
3019
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(TinaCloudProvider, {
3280
3020
  branch,
3281
3021
  clientId,
@@ -3325,25 +3065,13 @@ mutation addPendingDocumentMutation(
3325
3065
  payload: void 0,
3326
3066
  isLoading: true
3327
3067
  });
3328
- const cms = toolkit.useCMS();
3329
- const useUnstableFormify = React__default["default"].useMemo(() => {
3330
- if ((cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false) {
3331
- return false;
3332
- }
3333
- return true;
3334
- }, [cms == null ? void 0 : cms.flags]);
3335
3068
  return /* @__PURE__ */ React__default["default"].createElement(sharedctx.TinaDataContext.Provider, {
3336
3069
  value: {
3337
3070
  setRequest,
3338
3071
  isLoading: state.isLoading,
3339
3072
  state: { payload: state.payload }
3340
3073
  }
3341
- }, useUnstableFormify ? /* @__PURE__ */ React__default["default"].createElement(FormRegistrarUnstable, {
3342
- key: request == null ? void 0 : request.query,
3343
- request,
3344
- formifyCallback,
3345
- onPayloadStateChange: setState
3346
- }) : /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
3074
+ }, /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
3347
3075
  key: request == null ? void 0 : request.query,
3348
3076
  request,
3349
3077
  formifyCallback,
@@ -3372,35 +3100,6 @@ mutation addPendingDocumentMutation(
3372
3100
  }, [JSON.stringify(payload), isLoading]);
3373
3101
  return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
3374
3102
  };
3375
- const FormRegistrarUnstable = (props) => {
3376
- var _a;
3377
- if (!((_a = props.request) == null ? void 0 : _a.query)) {
3378
- return null;
3379
- }
3380
- return /* @__PURE__ */ React__default["default"].createElement(FormRegistrarUnstableInner, __spreadValues({}, props));
3381
- };
3382
- const FormRegistrarUnstableInner = ({
3383
- request,
3384
- formifyCallback,
3385
- onPayloadStateChange
3386
- }) => {
3387
- const cms = toolkit.useCMS();
3388
- const [payload, isLoading] = useGraphqlFormsUnstable({
3389
- query: request == null ? void 0 : request.query,
3390
- variables: request == null ? void 0 : request.variables,
3391
- formify: (args) => {
3392
- if (formifyCallback) {
3393
- return formifyCallback(args, cms);
3394
- } else {
3395
- return args.createForm(args.formConfig);
3396
- }
3397
- }
3398
- });
3399
- React__default["default"].useEffect(() => {
3400
- onPayloadStateChange({ payload, isLoading });
3401
- }, [JSON.stringify(payload), isLoading]);
3402
- return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
3403
- };
3404
3103
  const Loader = (props) => {
3405
3104
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("div", {
3406
3105
  style: {
@@ -3645,8 +3344,8 @@ This will work when developing locally but NOT when deployed to production.
3645
3344
  const fetchCollections = async () => {
3646
3345
  if (await api.isAuthenticated()) {
3647
3346
  try {
3648
- const response = await api.fetchCollections();
3649
- setCollections(response.getCollections);
3347
+ const collections2 = await api.fetchCollections();
3348
+ setCollections(collections2);
3650
3349
  } catch (error2) {
3651
3350
  console.error(error2);
3652
3351
  setCollections([]);
@@ -3949,8 +3648,8 @@ This will work when developing locally but NOT when deployed to production.
3949
3648
  const fetchCollection = async () => {
3950
3649
  if (await api.isAuthenticated()) {
3951
3650
  try {
3952
- const response = await api.fetchCollection(collectionName, includeDocuments);
3953
- setCollection(response.getCollection);
3651
+ const collection2 = await api.fetchCollection(collectionName, includeDocuments);
3652
+ setCollection(collection2);
3954
3653
  } catch (error2) {
3955
3654
  cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
3956
3655
  console.error(error2);
@@ -4016,7 +3715,7 @@ This will work when developing locally but NOT when deployed to production.
4016
3715
  window.location.href = routeOverride;
4017
3716
  return null;
4018
3717
  } else {
4019
- navigate(document.sys.breadcrumbs.join("/"));
3718
+ navigate(document._sys.breadcrumbs.join("/"));
4020
3719
  }
4021
3720
  };
4022
3721
  const CollectionListPage = () => {
@@ -4069,9 +3768,9 @@ This will work when developing locally but NOT when deployed to production.
4069
3768
  }, /* @__PURE__ */ React__default["default"].createElement("tbody", {
4070
3769
  className: "divide-y divide-gray-150"
4071
3770
  }, documents.map((document) => {
4072
- const subfolders = document.node.sys.breadcrumbs.slice(0, -1).join("/");
3771
+ const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
4073
3772
  return /* @__PURE__ */ React__default["default"].createElement("tr", {
4074
- key: `document-${document.node.sys.relativePath}`,
3773
+ key: `document-${document.node._sys.relativePath}`,
4075
3774
  className: ""
4076
3775
  }, /* @__PURE__ */ React__default["default"].createElement("td", {
4077
3776
  className: "px-6 py-2 whitespace-nowrap"
@@ -4088,22 +3787,21 @@ This will work when developing locally but NOT when deployed to production.
4088
3787
  className: "h-5 leading-5 block whitespace-nowrap"
4089
3788
  }, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
4090
3789
  className: "text-xs text-gray-400"
4091
- }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node.sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
3790
+ }, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
4092
3791
  className: "px-6 py-4 whitespace-nowrap"
4093
3792
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
4094
3793
  className: "block text-xs text-gray-400 mb-1 uppercase"
4095
3794
  }, "Extension"), /* @__PURE__ */ React__default["default"].createElement("span", {
4096
3795
  className: "h-5 leading-5 block text-sm font-medium text-gray-900"
4097
- }, document.node.sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
3796
+ }, document.node._sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
4098
3797
  className: "px-6 py-4 whitespace-nowrap"
4099
3798
  }, /* @__PURE__ */ React__default["default"].createElement("span", {
4100
3799
  className: "block text-xs text-gray-400 mb-1 uppercase"
4101
3800
  }, "Template"), /* @__PURE__ */ React__default["default"].createElement("span", {
4102
3801
  className: "h-5 leading-5 block text-sm font-medium text-gray-900"
4103
- }, document.node.sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
3802
+ }, document.node._sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
4104
3803
  className: "w-0"
4105
3804
  }, /* @__PURE__ */ React__default["default"].createElement(toolkit.OverflowMenu, {
4106
- showEmbed: true,
4107
3805
  toolbarItems: [
4108
3806
  {
4109
3807
  name: "edit",
@@ -4112,7 +3810,7 @@ This will work when developing locally but NOT when deployed to production.
4112
3810
  size: "1.3rem"
4113
3811
  }),
4114
3812
  onMouseDown: () => {
4115
- navigate(`${document.node.sys.filename}`, { replace: true });
3813
+ navigate(`${document.node._sys.filename}`, { replace: true });
4116
3814
  }
4117
3815
  },
4118
3816
  {
@@ -4125,7 +3823,7 @@ This will work when developing locally but NOT when deployed to production.
4125
3823
  onMouseDown: () => {
4126
3824
  setVars({
4127
3825
  collection: collectionName,
4128
- relativePath: document.node.sys.filename + document.node.sys.extension
3826
+ relativePath: document.node._sys.filename + document.node._sys.extension
4129
3827
  });
4130
3828
  setOpen(true);
4131
3829
  }
@@ -4153,72 +3851,6 @@ This will work when developing locally but NOT when deployed to production.
4153
3851
  }
4154
3852
  }, "Delete"))));
4155
3853
  };
4156
- const useGetDocumentFields = (cms, collectionName, templateName) => {
4157
- const api = new TinaAdminApi(cms);
4158
- const [info, setInfo] = React.useState({
4159
- collection: void 0,
4160
- template: void 0,
4161
- fields: void 0,
4162
- mutationInfo: void 0
4163
- });
4164
- const [loading, setLoading] = React.useState(true);
4165
- const [error, setError] = React.useState(void 0);
4166
- React.useEffect(() => {
4167
- const fetchDocumentFields = async () => {
4168
- if (await api.isAuthenticated()) {
4169
- try {
4170
- const response = await api.fetchDocumentFields();
4171
- const documentFields = response.getDocumentFields;
4172
- const collection = documentFields[collectionName].collection;
4173
- const mutationInfo = documentFields[collectionName].mutationInfo;
4174
- let fields = void 0;
4175
- let template = void 0;
4176
- if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
4177
- template = documentFields[collectionName].templates[templateName].template;
4178
- fields = documentFields[collectionName].templates[templateName].fields;
4179
- } else {
4180
- fields = documentFields[collectionName].fields;
4181
- }
4182
- setInfo({
4183
- collection,
4184
- template,
4185
- fields,
4186
- mutationInfo
4187
- });
4188
- } catch (error2) {
4189
- cms.alerts.error(`[${error2.name}] GetDocumentFields failed: ${error2.message}`, 30 * 1e3);
4190
- console.error(error2);
4191
- setInfo({
4192
- collection: void 0,
4193
- template: void 0,
4194
- fields: void 0,
4195
- mutationInfo: void 0
4196
- });
4197
- setError(error2);
4198
- }
4199
- setLoading(false);
4200
- }
4201
- };
4202
- setLoading(true);
4203
- fetchDocumentFields();
4204
- }, [cms, collectionName]);
4205
- return __spreadProps(__spreadValues({}, info), { loading, error });
4206
- };
4207
- const GetDocumentFields = ({
4208
- cms,
4209
- collectionName,
4210
- templateName,
4211
- children
4212
- }) => {
4213
- const { collection, template, fields, mutationInfo, loading, error } = useGetDocumentFields(cms, collectionName, templateName);
4214
- if (error) {
4215
- return null;
4216
- }
4217
- if (loading) {
4218
- return /* @__PURE__ */ React__default["default"].createElement(LoadingPage, null);
4219
- }
4220
- return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children({ collection, template, fields, mutationInfo, loading }));
4221
- };
4222
3854
  function HiChevronRight(props) {
4223
3855
  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);
4224
3856
  }
@@ -4244,34 +3876,39 @@ This will work when developing locally but NOT when deployed to production.
4244
3876
  };
4245
3877
  const CollectionCreatePage = () => {
4246
3878
  const { collectionName, templateName } = reactRouterDom.useParams();
4247
- return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
3879
+ return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
4248
3880
  cms,
4249
3881
  collectionName,
4250
- templateName
4251
- }, ({ collection, template, fields, mutationInfo }) => /* @__PURE__ */ React__default["default"].createElement(RenderForm$1, {
4252
- cms,
4253
- collection,
4254
- template,
4255
- fields,
4256
- mutationInfo
4257
- })));
3882
+ includeDocuments: false
3883
+ }, (collection) => {
3884
+ const mutationInfo = {
3885
+ includeCollection: true,
3886
+ includeTemplate: !!collection.templates
3887
+ };
3888
+ return /* @__PURE__ */ React__default["default"].createElement(RenderForm$1, {
3889
+ cms,
3890
+ collection,
3891
+ templateName,
3892
+ mutationInfo
3893
+ });
3894
+ }));
4258
3895
  };
4259
- const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
3896
+ const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
4260
3897
  var _a, _b;
4261
3898
  const navigate = reactRouterDom.useNavigate();
4262
3899
  const [formIsPristine, setFormIsPristine] = React.useState(true);
4263
3900
  const schema = cms.api.tina.schema;
4264
- let schemaFields = fields;
4265
- if (schema) {
4266
- const schemaCollection = schema.getCollection(collection.name);
4267
- const formInfo = schemaTools.resolveForm({
4268
- collection: schemaCollection,
4269
- basename: schemaCollection.name,
4270
- schema,
4271
- template
4272
- });
4273
- schemaFields = formInfo.fields;
4274
- }
3901
+ const schemaCollection = schema.getCollection(collection.name);
3902
+ const template = schema.getTemplateForData({
3903
+ collection: schemaCollection,
3904
+ data: { _template: templateName }
3905
+ });
3906
+ const formInfo = schemaTools.resolveForm({
3907
+ collection: schemaCollection,
3908
+ basename: schemaCollection.name,
3909
+ schema,
3910
+ template
3911
+ });
4275
3912
  const form = React.useMemo(() => {
4276
3913
  return new toolkit.Form({
4277
3914
  id: "create-form",
@@ -4296,7 +3933,7 @@ This will work when developing locally but NOT when deployed to production.
4296
3933
  }
4297
3934
  }
4298
3935
  },
4299
- ...schemaFields
3936
+ ...formInfo.fields
4300
3937
  ],
4301
3938
  onSubmit: async (values) => {
4302
3939
  try {
@@ -4309,7 +3946,7 @@ This will work when developing locally but NOT when deployed to production.
4309
3946
  }
4310
3947
  }
4311
3948
  });
4312
- }, [cms, collection, template, fields, mutationInfo]);
3949
+ }, [cms, collection, mutationInfo]);
4313
3950
  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", {
4314
3951
  className: "py-4 px-20 border-b border-gray-200 bg-white"
4315
3952
  }, /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -4342,7 +3979,7 @@ This will work when developing locally but NOT when deployed to production.
4342
3979
  if (api.isAuthenticated()) {
4343
3980
  try {
4344
3981
  const response = await api.fetchDocument(collectionName, relativePath);
4345
- setDocument(response.getDocument);
3982
+ setDocument(response.document);
4346
3983
  } catch (error2) {
4347
3984
  cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
4348
3985
  console.error(error2);
@@ -4391,11 +4028,16 @@ This will work when developing locally but NOT when deployed to production.
4391
4028
  const CollectionUpdatePage = () => {
4392
4029
  const _a = reactRouterDom.useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
4393
4030
  const { "*": filename } = rest;
4394
- return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
4031
+ return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
4395
4032
  cms,
4396
- collectionName
4397
- }, ({ collection, mutationInfo }) => {
4033
+ collectionName,
4034
+ includeDocuments: false
4035
+ }, (collection) => {
4398
4036
  const relativePath = `${filename}.${collection.format}`;
4037
+ const mutationInfo = {
4038
+ includeCollection: true,
4039
+ includeTemplate: !!collection.templates
4040
+ };
4399
4041
  return /* @__PURE__ */ React__default["default"].createElement(GetDocument, {
4400
4042
  cms,
4401
4043
  collectionName: collection.name,
@@ -4421,27 +4063,23 @@ This will work when developing locally but NOT when deployed to production.
4421
4063
  var _a, _b;
4422
4064
  const [formIsPristine, setFormIsPristine] = React.useState(true);
4423
4065
  const schema = cms.api.tina.schema;
4424
- let schemaFields = document.form.fields;
4425
- if (schema) {
4426
- const schemaCollection = schema.getCollection(collection.name);
4427
- const template = schema.getTemplateForData({
4428
- collection: schemaCollection,
4429
- data: document.values
4430
- });
4431
- const formInfo = schemaTools.resolveForm({
4432
- collection: schemaCollection,
4433
- basename: schemaCollection.name,
4434
- schema,
4435
- template
4436
- });
4437
- schemaFields = formInfo.fields;
4438
- }
4066
+ const schemaCollection = schema.getCollection(collection.name);
4067
+ const template = schema.getTemplateForData({
4068
+ collection: schemaCollection,
4069
+ data: document._values
4070
+ });
4071
+ const formInfo = schemaTools.resolveForm({
4072
+ collection: schemaCollection,
4073
+ basename: schemaCollection.name,
4074
+ schema,
4075
+ template
4076
+ });
4439
4077
  const form = React.useMemo(() => {
4440
4078
  return new toolkit.Form({
4441
4079
  id: "update-form",
4442
4080
  label: "form",
4443
- fields: schemaFields,
4444
- initialValues: document.values,
4081
+ fields: formInfo.fields,
4082
+ initialValues: document._values,
4445
4083
  onSubmit: async (values) => {
4446
4084
  try {
4447
4085
  await updateDocument(cms, relativePath, collection, mutationInfo, values);
@@ -4583,7 +4221,6 @@ This will work when developing locally but NOT when deployed to production.
4583
4221
  exports2.staticRequest = staticRequest;
4584
4222
  exports2.useDocumentCreatorPlugin = useDocumentCreatorPlugin;
4585
4223
  exports2.useGraphqlForms = useGraphqlForms;
4586
- exports2.useGraphqlFormsUnstable = useGraphqlFormsUnstable;
4587
4224
  exports2.useTinaAuthRedirect = useTinaAuthRedirect;
4588
4225
  Object.keys(toolkit).forEach(function(k) {
4589
4226
  if (k !== "default" && !exports2.hasOwnProperty(k))