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/CHANGELOG.md +185 -0
- package/dist/admin/api.d.ts +5 -9
- package/dist/admin/types.d.ts +4 -21
- package/dist/hooks/formify/formify-utils.d.ts +1 -0
- package/dist/hooks/formify/formify.d.ts +0 -1
- package/dist/hooks/formify/types.d.ts +3 -11
- package/dist/hooks/use-graphql-forms.d.ts +4 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +194 -556
- package/dist/index.js +192 -555
- package/package.json +2 -2
- package/dist/admin/components/GetDocumentFields.d.ts +0 -40
package/dist/index.js
CHANGED
|
@@ -428,7 +428,7 @@ var __objRest = (source, exclude) => {
|
|
|
428
428
|
return false;
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
-
function
|
|
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
|
|
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 } =
|
|
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:
|
|
845
|
-
initialValues: doc.
|
|
590
|
+
label: id,
|
|
591
|
+
initialValues: doc._values,
|
|
846
592
|
onSubmit: async (payload) => {
|
|
847
593
|
try {
|
|
848
|
-
const params = transformDocumentIntoMutationRequestPayload(payload,
|
|
594
|
+
const params = transformDocumentIntoMutationRequestPayload(payload, {
|
|
595
|
+
includeCollection: false,
|
|
596
|
+
includeTemplate: !!collection.templates
|
|
597
|
+
});
|
|
849
598
|
const variables = { params };
|
|
850
|
-
const mutationString =
|
|
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
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
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,
|
|
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,
|
|
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:
|
|
1015
|
+
_internalSys: _sys {
|
|
1265
1016
|
path
|
|
1017
|
+
relativePath
|
|
1266
1018
|
collection {
|
|
1267
1019
|
name
|
|
1268
1020
|
}
|
|
1269
1021
|
}
|
|
1270
|
-
|
|
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 = "
|
|
1306
|
-
const COLLECTIONS_FIELD_NAME = "
|
|
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
|
-
|
|
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
|
-
|
|
1420
|
-
|
|
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
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
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
|
-
|
|
2073
|
-
|
|
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:
|
|
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
|
-
|
|
2307
|
-
|
|
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] =
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
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
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
}
|
|
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
|
-
|
|
2475
|
+
if (includeDocuments === true) {
|
|
2476
|
+
const response = await this.api.request(`#graphql
|
|
2741
2477
|
query($collection: String!, $includeDocuments: Boolean!){
|
|
2742
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2517
|
+
document(collection:$collection, relativePath:$relativePath) {
|
|
2773
2518
|
... on Document {
|
|
2774
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
},
|
|
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
|
|
3649
|
-
setCollections(
|
|
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
|
|
3953
|
-
setCollection(
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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(
|
|
3879
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
|
|
4248
3880
|
cms,
|
|
4249
3881
|
collectionName,
|
|
4250
|
-
|
|
4251
|
-
}, (
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
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,
|
|
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
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
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
|
-
...
|
|
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,
|
|
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.
|
|
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(
|
|
4031
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
|
|
4395
4032
|
cms,
|
|
4396
|
-
collectionName
|
|
4397
|
-
|
|
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
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
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:
|
|
4444
|
-
initialValues: document.
|
|
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))
|