tinacms 0.67.4 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +169 -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 +191 -555
- package/dist/index.js +189 -554
- 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,
|
|
@@ -446,239 +446,6 @@ var __objRest = (source, exclude) => {
|
|
|
446
446
|
});
|
|
447
447
|
return [state.data, state.status !== "done"];
|
|
448
448
|
}
|
|
449
|
-
function useGraphqlForms({
|
|
450
|
-
variables,
|
|
451
|
-
onSubmit,
|
|
452
|
-
formify: formify2 = null,
|
|
453
|
-
query
|
|
454
|
-
}) {
|
|
455
|
-
const cms = toolkit.useCMS();
|
|
456
|
-
const [formValues, setFormValues] = React__default["default"].useState({});
|
|
457
|
-
const [data, setData] = React__default["default"].useState(null);
|
|
458
|
-
const [initialData, setInitialData] = React__default["default"].useState({});
|
|
459
|
-
const [pendingReset, setPendingReset] = React__default["default"].useState(null);
|
|
460
|
-
const [isLoading, setIsLoading] = React__default["default"].useState(true);
|
|
461
|
-
const [newUpdate, setNewUpdate] = React__default["default"].useState(null);
|
|
462
|
-
const { currentBranch } = toolkit.useBranchData();
|
|
463
|
-
const updateData = async () => {
|
|
464
|
-
var _a;
|
|
465
|
-
if (newUpdate) {
|
|
466
|
-
const newValue = finalForm.getIn(formValues, newUpdate.get);
|
|
467
|
-
const activeForm = finalForm.getIn(data, [newUpdate.queryName, "form"].join("."));
|
|
468
|
-
if (!activeForm) {
|
|
469
|
-
throw new Error(`Unable to find form for query ${newUpdate.queryName}`);
|
|
470
|
-
}
|
|
471
|
-
if (activeForm == null ? void 0 : activeForm.paths) {
|
|
472
|
-
const asyncUpdate = (_a = activeForm.paths) == null ? void 0 : _a.find((p) => p.dataPath.join(".") === newUpdate.setReference);
|
|
473
|
-
if (asyncUpdate) {
|
|
474
|
-
const res = await cms.api.tina.request(asyncUpdate.queryString, {
|
|
475
|
-
variables: { id: newValue }
|
|
476
|
-
});
|
|
477
|
-
const newData2 = finalForm.setIn(data, newUpdate.set, res.node);
|
|
478
|
-
const newDataAndNewJSONData2 = finalForm.setIn(newData2, newUpdate.set.replace("data", "dataJSON"), newValue);
|
|
479
|
-
setData(newDataAndNewJSONData2);
|
|
480
|
-
setNewUpdate(null);
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (newUpdate.lookup) {
|
|
485
|
-
const field = getFieldUpdate(newUpdate, activeForm, formValues);
|
|
486
|
-
if (field && field.typeMap) {
|
|
487
|
-
newValue.forEach((item) => {
|
|
488
|
-
if (!item.__typename) {
|
|
489
|
-
item["__typename"] = field.typeMap[item._template];
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const newData = finalForm.setIn(data, newUpdate.set, newValue);
|
|
495
|
-
const newDataAndNewJSONData = finalForm.setIn(newData, newUpdate.set.replace("data", "dataJSON"), newValue);
|
|
496
|
-
setData(newDataAndNewJSONData);
|
|
497
|
-
setNewUpdate(null);
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
React__default["default"].useEffect(() => {
|
|
501
|
-
updateData();
|
|
502
|
-
}, [JSON.stringify(formValues)]);
|
|
503
|
-
React__default["default"].useEffect(() => {
|
|
504
|
-
if (pendingReset) {
|
|
505
|
-
setData(__spreadProps(__spreadValues({}, data), { [pendingReset]: initialData[pendingReset] }));
|
|
506
|
-
setPendingReset(null);
|
|
507
|
-
}
|
|
508
|
-
}, [pendingReset]);
|
|
509
|
-
React__default["default"].useEffect(() => {
|
|
510
|
-
if (!query) {
|
|
511
|
-
setIsLoading(false);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
const useUnstableFormify = (cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false ? false : true;
|
|
515
|
-
const formIds = [];
|
|
516
|
-
setIsLoading(true);
|
|
517
|
-
cms.api.tina.requestWithForm((gql2) => gql2(query), {
|
|
518
|
-
variables,
|
|
519
|
-
useUnstableFormify
|
|
520
|
-
}).then((payload) => {
|
|
521
|
-
cms.plugins.remove(new toolkit.FormMetaPlugin({ name: "tina-admin-link" }));
|
|
522
|
-
setData(payload);
|
|
523
|
-
setInitialData(payload);
|
|
524
|
-
setIsLoading(false);
|
|
525
|
-
Object.entries(payload).map(([queryName, result]) => {
|
|
526
|
-
formIds.push(queryName);
|
|
527
|
-
const canBeFormified = safeAssertShape(result, (yup2) => yup2.object({
|
|
528
|
-
values: yup2.object().required(),
|
|
529
|
-
form: yup2.object().required()
|
|
530
|
-
}));
|
|
531
|
-
if (!canBeFormified) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
assertShape(result, (yup2) => yup2.object({
|
|
535
|
-
values: yup2.object().required(),
|
|
536
|
-
form: yup2.object().required()
|
|
537
|
-
}), `Unable to build form shape for fields at ${queryName}`);
|
|
538
|
-
let formConfig = {};
|
|
539
|
-
const formCommon = {
|
|
540
|
-
id: queryName,
|
|
541
|
-
initialValues: result.values,
|
|
542
|
-
reset: () => {
|
|
543
|
-
setPendingReset(queryName);
|
|
544
|
-
},
|
|
545
|
-
onSubmit: async (payload2) => {
|
|
546
|
-
try {
|
|
547
|
-
const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
|
|
548
|
-
const variables2 = { params };
|
|
549
|
-
const mutationString = result.form.mutationInfo.string;
|
|
550
|
-
if (onSubmit) {
|
|
551
|
-
onSubmit({
|
|
552
|
-
queryString: mutationString,
|
|
553
|
-
mutationString,
|
|
554
|
-
variables: variables2
|
|
555
|
-
});
|
|
556
|
-
} else {
|
|
557
|
-
try {
|
|
558
|
-
await cms.api.tina.request(mutationString, {
|
|
559
|
-
variables: variables2
|
|
560
|
-
});
|
|
561
|
-
cms.alerts.success("Document saved!");
|
|
562
|
-
} catch (e) {
|
|
563
|
-
cms.alerts.error("There was a problem saving your document");
|
|
564
|
-
console.error(e);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
} catch (e) {
|
|
568
|
-
console.error(e);
|
|
569
|
-
cms.alerts.error("There was a problem saving your document");
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
if (cms.api.tina.schema) {
|
|
574
|
-
const enrichedSchema = cms.api.tina.schema;
|
|
575
|
-
const collection = enrichedSchema.getCollection(result._internalSys.collection.name);
|
|
576
|
-
const template = enrichedSchema.getTemplateForData({
|
|
577
|
-
collection,
|
|
578
|
-
data: result.values
|
|
579
|
-
});
|
|
580
|
-
const formInfo = schemaTools.resolveForm({
|
|
581
|
-
collection,
|
|
582
|
-
basename: collection.name,
|
|
583
|
-
schema: enrichedSchema,
|
|
584
|
-
template
|
|
585
|
-
});
|
|
586
|
-
formConfig = __spreadValues({
|
|
587
|
-
label: formInfo.label,
|
|
588
|
-
fields: formInfo.fields
|
|
589
|
-
}, formCommon);
|
|
590
|
-
} else {
|
|
591
|
-
formConfig = __spreadValues({
|
|
592
|
-
label: result.form.label,
|
|
593
|
-
fields: result.form.fields
|
|
594
|
-
}, formCommon);
|
|
595
|
-
}
|
|
596
|
-
const { createForm, createGlobalForm } = generateFormCreators(cms);
|
|
597
|
-
const SKIPPED = "SKIPPED";
|
|
598
|
-
let form;
|
|
599
|
-
let skipped;
|
|
600
|
-
const skip = () => {
|
|
601
|
-
skipped = SKIPPED;
|
|
602
|
-
};
|
|
603
|
-
if (skipped)
|
|
604
|
-
return;
|
|
605
|
-
if (formify2) {
|
|
606
|
-
form = formify2({ formConfig, createForm, createGlobalForm, skip }, cms);
|
|
607
|
-
} else {
|
|
608
|
-
form = createForm(formConfig);
|
|
609
|
-
}
|
|
610
|
-
if (!(form instanceof toolkit.Form)) {
|
|
611
|
-
if (skipped === SKIPPED) {
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
throw new Error("formify must return a form or skip()");
|
|
615
|
-
}
|
|
616
|
-
const { change } = form.finalForm;
|
|
617
|
-
form.finalForm.change = (name, value) => {
|
|
618
|
-
let referenceName = "";
|
|
619
|
-
if (typeof name === "string") {
|
|
620
|
-
referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
|
|
621
|
-
} else {
|
|
622
|
-
throw new Error(`Expected name to be of type string for FinalForm change callback`);
|
|
623
|
-
}
|
|
624
|
-
setNewUpdate({
|
|
625
|
-
queryName,
|
|
626
|
-
get: [queryName, "values", name].join("."),
|
|
627
|
-
set: [queryName, "data", name].join("."),
|
|
628
|
-
setReference: [queryName, "data", referenceName].join(".")
|
|
629
|
-
});
|
|
630
|
-
return change(name, value);
|
|
631
|
-
};
|
|
632
|
-
const _a = form.finalForm.mutators, { insert, move, remove } = _a, rest = __objRest(_a, ["insert", "move", "remove"]);
|
|
633
|
-
const prepareNewUpdate = (name, lookup) => {
|
|
634
|
-
const extra = {};
|
|
635
|
-
if (lookup) {
|
|
636
|
-
extra["lookup"] = lookup;
|
|
637
|
-
}
|
|
638
|
-
const referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
|
|
639
|
-
setNewUpdate(__spreadValues({
|
|
640
|
-
queryName,
|
|
641
|
-
get: [queryName, "values", name].join("."),
|
|
642
|
-
set: [queryName, "data", name].join("."),
|
|
643
|
-
setReference: [queryName, "data", referenceName].join(".")
|
|
644
|
-
}, extra));
|
|
645
|
-
};
|
|
646
|
-
form.finalForm.mutators = __spreadValues({
|
|
647
|
-
insert: (...args) => {
|
|
648
|
-
const fieldName = args[0];
|
|
649
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
650
|
-
insert(...args);
|
|
651
|
-
},
|
|
652
|
-
move: (...args) => {
|
|
653
|
-
const fieldName = args[0];
|
|
654
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
655
|
-
move(...args);
|
|
656
|
-
},
|
|
657
|
-
remove: (...args) => {
|
|
658
|
-
const fieldName = args[0];
|
|
659
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
660
|
-
remove(...args);
|
|
661
|
-
}
|
|
662
|
-
}, rest);
|
|
663
|
-
form.subscribe(({ values }) => {
|
|
664
|
-
setFormValues(__spreadProps(__spreadValues({}, formValues), { [queryName]: { values } }));
|
|
665
|
-
}, { values: true });
|
|
666
|
-
});
|
|
667
|
-
}).catch((e) => {
|
|
668
|
-
setIsLoading(false);
|
|
669
|
-
throw new Error(`There was a problem setting up forms for your query: ${e.message}`);
|
|
670
|
-
});
|
|
671
|
-
return () => {
|
|
672
|
-
formIds.forEach((name) => {
|
|
673
|
-
const formPlugin = cms.forms.find(name);
|
|
674
|
-
if (formPlugin) {
|
|
675
|
-
cms.forms.remove(formPlugin);
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
};
|
|
679
|
-
}, [query, JSON.stringify(variables), currentBranch]);
|
|
680
|
-
return [data, isLoading];
|
|
681
|
-
}
|
|
682
449
|
const transformDocumentIntoMutationRequestPayload = (document, instructions) => {
|
|
683
450
|
const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
|
|
684
451
|
const params = transformParams(rest);
|
|
@@ -715,37 +482,7 @@ var __objRest = (source, exclude) => {
|
|
|
715
482
|
}
|
|
716
483
|
}
|
|
717
484
|
};
|
|
718
|
-
const
|
|
719
|
-
const items = newUpdate.lookup.split(".");
|
|
720
|
-
let currentFields = activeForm.fields;
|
|
721
|
-
items.map((item, index) => {
|
|
722
|
-
const lookupName = items.slice(0, index + 1).join(".");
|
|
723
|
-
const value = finalForm.getIn(formValues, [newUpdate.queryName, "values", lookupName].join("."));
|
|
724
|
-
if (isNaN(Number(item))) {
|
|
725
|
-
if (Array.isArray(currentFields)) {
|
|
726
|
-
currentFields = currentFields.find((field) => field.name === item);
|
|
727
|
-
}
|
|
728
|
-
} else {
|
|
729
|
-
const template = currentFields.templates ? currentFields.templates[value._template] : currentFields;
|
|
730
|
-
currentFields = template.fields;
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
return currentFields;
|
|
734
|
-
};
|
|
735
|
-
const generateFormCreators = (cms) => {
|
|
736
|
-
const createForm = (formConfig) => {
|
|
737
|
-
const form = new toolkit.Form(formConfig);
|
|
738
|
-
cms.forms.add(form);
|
|
739
|
-
return form;
|
|
740
|
-
};
|
|
741
|
-
const createGlobalForm = (formConfig, options) => {
|
|
742
|
-
const form = new toolkit.Form(formConfig);
|
|
743
|
-
cms.plugins.add(new toolkit.GlobalFormPlugin(form, options == null ? void 0 : options.icon, options == null ? void 0 : options.layout));
|
|
744
|
-
return form;
|
|
745
|
-
};
|
|
746
|
-
return { createForm, createGlobalForm };
|
|
747
|
-
};
|
|
748
|
-
const generateFormCreatorsUnstable = (cms, showInSidebar) => {
|
|
485
|
+
const generateFormCreators = (cms, showInSidebar) => {
|
|
749
486
|
const createForm = (formConfig) => {
|
|
750
487
|
const form = new toolkit.Form(formConfig);
|
|
751
488
|
if (showInSidebar) {
|
|
@@ -829,7 +566,7 @@ var __objRest = (source, exclude) => {
|
|
|
829
566
|
return accum.join(".");
|
|
830
567
|
};
|
|
831
568
|
const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
832
|
-
const { createForm, createGlobalForm } =
|
|
569
|
+
const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
|
|
833
570
|
const SKIPPED = "SKIPPED";
|
|
834
571
|
let form;
|
|
835
572
|
let skipped;
|
|
@@ -839,25 +576,50 @@ var __objRest = (source, exclude) => {
|
|
|
839
576
|
if (skipped)
|
|
840
577
|
return;
|
|
841
578
|
const id = doc._internalSys.path;
|
|
579
|
+
const enrichedSchema = cms.api.tina.schema;
|
|
580
|
+
const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
|
|
581
|
+
const template = enrichedSchema.getTemplateForData({
|
|
582
|
+
collection,
|
|
583
|
+
data: doc._values
|
|
584
|
+
});
|
|
842
585
|
const formCommon = {
|
|
843
586
|
id,
|
|
844
|
-
label:
|
|
845
|
-
initialValues: doc.
|
|
587
|
+
label: id,
|
|
588
|
+
initialValues: doc._values,
|
|
846
589
|
onSubmit: async (payload) => {
|
|
847
590
|
try {
|
|
848
|
-
const params = transformDocumentIntoMutationRequestPayload(payload,
|
|
591
|
+
const params = transformDocumentIntoMutationRequestPayload(payload, {
|
|
592
|
+
includeCollection: false,
|
|
593
|
+
includeTemplate: !!collection.templates
|
|
594
|
+
});
|
|
849
595
|
const variables = { params };
|
|
850
|
-
const mutationString =
|
|
596
|
+
const mutationString = `#graphql
|
|
597
|
+
mutation UpdateDocument($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
598
|
+
updateDocument(collection: $collection, relativePath: $relativePath, params: $params) {
|
|
599
|
+
__typename
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
`;
|
|
851
603
|
if (onSubmit) {
|
|
852
604
|
onSubmit({
|
|
853
605
|
queryString: mutationString,
|
|
854
606
|
mutationString,
|
|
855
|
-
variables
|
|
607
|
+
variables: {
|
|
608
|
+
collection: doc._internalSys.collection.name,
|
|
609
|
+
relativePath: doc._internalSys.relativePath,
|
|
610
|
+
params: { [doc._internalSys.collection.name]: variables }
|
|
611
|
+
}
|
|
856
612
|
});
|
|
857
613
|
} else {
|
|
858
614
|
try {
|
|
859
615
|
await cms.api.tina.request(mutationString, {
|
|
860
|
-
variables
|
|
616
|
+
variables: {
|
|
617
|
+
collection: doc._internalSys.collection.name,
|
|
618
|
+
relativePath: doc._internalSys.relativePath,
|
|
619
|
+
params: {
|
|
620
|
+
[doc._internalSys.collection.name]: variables.params
|
|
621
|
+
}
|
|
622
|
+
}
|
|
861
623
|
});
|
|
862
624
|
cms.alerts.success("Document saved!");
|
|
863
625
|
} catch (e) {
|
|
@@ -872,29 +634,16 @@ var __objRest = (source, exclude) => {
|
|
|
872
634
|
}
|
|
873
635
|
};
|
|
874
636
|
let formConfig = {};
|
|
875
|
-
|
|
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
|
-
}
|
|
637
|
+
const formInfo = schemaTools.resolveForm({
|
|
638
|
+
collection,
|
|
639
|
+
basename: collection.name,
|
|
640
|
+
schema: enrichedSchema,
|
|
641
|
+
template
|
|
642
|
+
});
|
|
643
|
+
formConfig = __spreadValues({
|
|
644
|
+
label: formInfo.label,
|
|
645
|
+
fields: formInfo.fields
|
|
646
|
+
}, formCommon);
|
|
898
647
|
if (formify2) {
|
|
899
648
|
form = formify2({
|
|
900
649
|
formConfig,
|
|
@@ -1013,7 +762,7 @@ var __objRest = (source, exclude) => {
|
|
|
1013
762
|
}
|
|
1014
763
|
return `[]`;
|
|
1015
764
|
}).join(".");
|
|
1016
|
-
const items = [blueprint.id,
|
|
765
|
+
const items = [blueprint.id, eventPath];
|
|
1017
766
|
const isList = event.field.data.tinaField.list;
|
|
1018
767
|
if (isList && !eventPath.endsWith("[]")) {
|
|
1019
768
|
items.push(`[]`);
|
|
@@ -1048,14 +797,13 @@ var __objRest = (source, exclude) => {
|
|
|
1048
797
|
if (prefix) {
|
|
1049
798
|
extra.push(prefix);
|
|
1050
799
|
}
|
|
1051
|
-
const matchName = [blueprintName,
|
|
800
|
+
const matchName = [blueprintName, ...extra, fieldName].join(".");
|
|
1052
801
|
return { matchName, fieldName };
|
|
1053
802
|
};
|
|
1054
803
|
const getFormNodesFromEvent = (state, event) => {
|
|
1055
804
|
const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
|
|
1056
805
|
return formNodes;
|
|
1057
806
|
};
|
|
1058
|
-
const DATA_NODE_NAME$1 = "data";
|
|
1059
807
|
const printEvent = (event) => {
|
|
1060
808
|
var _a, _b;
|
|
1061
809
|
return {
|
|
@@ -1261,14 +1009,14 @@ var __objRest = (source, exclude) => {
|
|
|
1261
1009
|
}
|
|
1262
1010
|
const node = G__namespace.parse(`
|
|
1263
1011
|
query Sample {
|
|
1264
|
-
_internalSys:
|
|
1012
|
+
_internalSys: _sys {
|
|
1265
1013
|
path
|
|
1014
|
+
relativePath
|
|
1266
1015
|
collection {
|
|
1267
1016
|
name
|
|
1268
1017
|
}
|
|
1269
1018
|
}
|
|
1270
|
-
|
|
1271
|
-
values
|
|
1019
|
+
_values
|
|
1272
1020
|
}`);
|
|
1273
1021
|
const metaFields = node.definitions[0].selectionSet.selections;
|
|
1274
1022
|
const getRelativeBlueprint = (path) => {
|
|
@@ -1285,6 +1033,21 @@ var __objRest = (source, exclude) => {
|
|
|
1285
1033
|
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
|
|
1286
1034
|
return getBlueprintNamePath({ path: documentBlueprintPath });
|
|
1287
1035
|
};
|
|
1036
|
+
const isSysField = (fieldNode) => {
|
|
1037
|
+
if (fieldNode.name.value === "__typename") {
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
if (fieldNode.name.value === "_sys") {
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
if (fieldNode.name.value === "_values") {
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
if (fieldNode.name.value === "id") {
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
return false;
|
|
1050
|
+
};
|
|
1288
1051
|
const getBlueprintId = (path) => {
|
|
1289
1052
|
const namePath = [];
|
|
1290
1053
|
const aliasPath = [];
|
|
@@ -1302,10 +1065,9 @@ var __objRest = (source, exclude) => {
|
|
|
1302
1065
|
const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
|
|
1303
1066
|
const EDGES_NODE_NAME = "edges";
|
|
1304
1067
|
const NODE_NAME = "node";
|
|
1305
|
-
const COLLECTION_FIELD_NAME = "
|
|
1306
|
-
const COLLECTIONS_FIELD_NAME = "
|
|
1068
|
+
const COLLECTION_FIELD_NAME = "collection";
|
|
1069
|
+
const COLLECTIONS_FIELD_NAME = "collections";
|
|
1307
1070
|
const COLLECTIONS_DOCUMENTS_NAME = "documents";
|
|
1308
|
-
const DATA_NODE_NAME = "data";
|
|
1309
1071
|
const formify = async ({
|
|
1310
1072
|
schema,
|
|
1311
1073
|
query,
|
|
@@ -1411,22 +1173,15 @@ var __objRest = (source, exclude) => {
|
|
|
1411
1173
|
showInSidebar = false
|
|
1412
1174
|
}) {
|
|
1413
1175
|
let extraFields = [];
|
|
1414
|
-
|
|
1176
|
+
const hasDataJSONField = false;
|
|
1415
1177
|
let hasValuesField = false;
|
|
1416
1178
|
let shouldFormify = false;
|
|
1417
1179
|
selection.selectionSet.selections.forEach((selection2) => {
|
|
1418
1180
|
if (selection2.kind === "Field") {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
hasDataJSONField = true;
|
|
1422
|
-
}
|
|
1423
|
-
if (selection2.name.value === "values") {
|
|
1424
|
-
shouldFormify = true;
|
|
1181
|
+
shouldFormify = true;
|
|
1182
|
+
if (selection2.name.value === "_values") {
|
|
1425
1183
|
hasValuesField = true;
|
|
1426
1184
|
}
|
|
1427
|
-
if (selection2.name.value === "data") {
|
|
1428
|
-
shouldFormify = true;
|
|
1429
|
-
}
|
|
1430
1185
|
}
|
|
1431
1186
|
});
|
|
1432
1187
|
if (shouldFormify) {
|
|
@@ -1465,33 +1220,11 @@ var __objRest = (source, exclude) => {
|
|
|
1465
1220
|
});
|
|
1466
1221
|
}
|
|
1467
1222
|
case "Field": {
|
|
1468
|
-
|
|
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;
|
|
1223
|
+
return formifyFieldNode({
|
|
1224
|
+
fieldNode: selectionNode,
|
|
1225
|
+
parentType: type,
|
|
1226
|
+
path
|
|
1227
|
+
});
|
|
1495
1228
|
}
|
|
1496
1229
|
default:
|
|
1497
1230
|
throw new FormifyError("UNEXPECTED");
|
|
@@ -1514,16 +1247,19 @@ var __objRest = (source, exclude) => {
|
|
|
1514
1247
|
if (!field) {
|
|
1515
1248
|
return fieldNode;
|
|
1516
1249
|
}
|
|
1517
|
-
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
|
|
1518
|
-
if (!blueprint) {
|
|
1519
|
-
return fieldNode;
|
|
1520
|
-
}
|
|
1521
1250
|
const fieldPath = buildPath({
|
|
1522
1251
|
fieldNode,
|
|
1523
1252
|
type: field.type,
|
|
1524
1253
|
parentTypename: G__namespace.getNamedType(parentType).name,
|
|
1525
1254
|
path
|
|
1526
1255
|
});
|
|
1256
|
+
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(fieldPath));
|
|
1257
|
+
if (!blueprint) {
|
|
1258
|
+
return fieldNode;
|
|
1259
|
+
}
|
|
1260
|
+
if (isSysField(fieldNode)) {
|
|
1261
|
+
return fieldNode;
|
|
1262
|
+
}
|
|
1527
1263
|
blueprint.fields.push({
|
|
1528
1264
|
id: getBlueprintId(fieldPath),
|
|
1529
1265
|
documentBlueprintId: blueprint.id,
|
|
@@ -2069,10 +1805,10 @@ var __objRest = (source, exclude) => {
|
|
|
2069
1805
|
query Node($id: String!) {
|
|
2070
1806
|
node(id: $id) {
|
|
2071
1807
|
...on Document {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
_internalSys: sys {
|
|
1808
|
+
_values
|
|
1809
|
+
_internalSys: _sys {
|
|
2075
1810
|
path
|
|
1811
|
+
relativePath
|
|
2076
1812
|
collection {
|
|
2077
1813
|
name
|
|
2078
1814
|
}
|
|
@@ -2182,9 +1918,7 @@ var __objRest = (source, exclude) => {
|
|
|
2182
1918
|
dispatch({
|
|
2183
1919
|
type: "setIn",
|
|
2184
1920
|
value: __spreadProps(__spreadValues({}, changeSet), {
|
|
2185
|
-
value:
|
|
2186
|
-
data
|
|
2187
|
-
})
|
|
1921
|
+
value: __spreadValues(__spreadValues({}, res.node), data)
|
|
2188
1922
|
})
|
|
2189
1923
|
});
|
|
2190
1924
|
}).catch((e) => {
|
|
@@ -2303,10 +2037,10 @@ var __objRest = (source, exclude) => {
|
|
|
2303
2037
|
query Node($id: String!) {
|
|
2304
2038
|
node(id: $id) {
|
|
2305
2039
|
...on Document {
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
_internalSys: sys {
|
|
2040
|
+
_values
|
|
2041
|
+
_internalSys: _sys {
|
|
2309
2042
|
path
|
|
2043
|
+
relativePath
|
|
2310
2044
|
collection {
|
|
2311
2045
|
name
|
|
2312
2046
|
}
|
|
@@ -2344,13 +2078,11 @@ var __objRest = (source, exclude) => {
|
|
|
2344
2078
|
}
|
|
2345
2079
|
}
|
|
2346
2080
|
`, { variables: { id: value } });
|
|
2347
|
-
data[keyName] =
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
})
|
|
2353
|
-
});
|
|
2081
|
+
data[keyName] = __spreadValues(__spreadValues({}, res.node), await resolveSubFields({
|
|
2082
|
+
formNode: subDocumentFormNode,
|
|
2083
|
+
form: form2,
|
|
2084
|
+
loc: location
|
|
2085
|
+
}));
|
|
2354
2086
|
});
|
|
2355
2087
|
break;
|
|
2356
2088
|
default:
|
|
@@ -2711,19 +2443,19 @@ mutation addPendingDocumentMutation(
|
|
|
2711
2443
|
class TinaAdminApi {
|
|
2712
2444
|
constructor(cms) {
|
|
2713
2445
|
this.api = cms.api.tina;
|
|
2446
|
+
this.schema = cms.api.tina.schema;
|
|
2714
2447
|
}
|
|
2715
2448
|
async isAuthenticated() {
|
|
2716
2449
|
return await this.api.isAuthenticated();
|
|
2717
2450
|
}
|
|
2718
2451
|
async fetchCollections() {
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
}
|
|
2726
|
-
return response;
|
|
2452
|
+
try {
|
|
2453
|
+
const collections = this.schema.getCollections();
|
|
2454
|
+
return collections;
|
|
2455
|
+
} catch (e) {
|
|
2456
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
|
|
2457
|
+
return [];
|
|
2458
|
+
}
|
|
2727
2459
|
}
|
|
2728
2460
|
async deleteDocument({
|
|
2729
2461
|
collection,
|
|
@@ -2737,9 +2469,10 @@ mutation addPendingDocumentMutation(
|
|
|
2737
2469
|
}`, { variables: { collection, relativePath } });
|
|
2738
2470
|
}
|
|
2739
2471
|
async fetchCollection(collectionName, includeDocuments) {
|
|
2740
|
-
|
|
2472
|
+
if (includeDocuments === true) {
|
|
2473
|
+
const response = await this.api.request(`#graphql
|
|
2741
2474
|
query($collection: String!, $includeDocuments: Boolean!){
|
|
2742
|
-
|
|
2475
|
+
collection(collection: $collection){
|
|
2743
2476
|
name
|
|
2744
2477
|
label
|
|
2745
2478
|
format
|
|
@@ -2749,7 +2482,7 @@ mutation addPendingDocumentMutation(
|
|
|
2749
2482
|
edges {
|
|
2750
2483
|
node {
|
|
2751
2484
|
... on Document {
|
|
2752
|
-
|
|
2485
|
+
_sys {
|
|
2753
2486
|
template
|
|
2754
2487
|
breadcrumbs
|
|
2755
2488
|
path
|
|
@@ -2764,27 +2497,28 @@ mutation addPendingDocumentMutation(
|
|
|
2764
2497
|
}
|
|
2765
2498
|
}
|
|
2766
2499
|
}`, { variables: { collection: collectionName, includeDocuments } });
|
|
2767
|
-
|
|
2500
|
+
return response.collection;
|
|
2501
|
+
} else {
|
|
2502
|
+
try {
|
|
2503
|
+
const collection = this.schema.getCollection(collectionName);
|
|
2504
|
+
return collection;
|
|
2505
|
+
} catch (e) {
|
|
2506
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollection(): ${e.message}`);
|
|
2507
|
+
return void 0;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2768
2510
|
}
|
|
2769
2511
|
async fetchDocument(collectionName, relativePath) {
|
|
2770
2512
|
const response = await this.api.request(`#graphql
|
|
2771
2513
|
query($collection: String!, $relativePath: String!) {
|
|
2772
|
-
|
|
2514
|
+
document(collection:$collection, relativePath:$relativePath) {
|
|
2773
2515
|
... on Document {
|
|
2774
|
-
|
|
2775
|
-
values
|
|
2516
|
+
_values
|
|
2776
2517
|
}
|
|
2777
2518
|
}
|
|
2778
2519
|
}`, { variables: { collection: collectionName, relativePath } });
|
|
2779
2520
|
return response;
|
|
2780
2521
|
}
|
|
2781
|
-
async fetchDocumentFields() {
|
|
2782
|
-
const response = await this.api.request(`#graphql
|
|
2783
|
-
query {
|
|
2784
|
-
getDocumentFields
|
|
2785
|
-
}`, { variables: {} });
|
|
2786
|
-
return response;
|
|
2787
|
-
}
|
|
2788
2522
|
async createDocument(collectionName, relativePath, params) {
|
|
2789
2523
|
const response = await this.api.request(`#graphql
|
|
2790
2524
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
@@ -2805,7 +2539,7 @@ mutation addPendingDocumentMutation(
|
|
|
2805
2539
|
async updateDocument(collectionName, relativePath, params) {
|
|
2806
2540
|
const response = await this.api.request(`#graphql
|
|
2807
2541
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2808
|
-
updateDocument(
|
|
2542
|
+
updateDocument(
|
|
2809
2543
|
collection: $collection,
|
|
2810
2544
|
relativePath: $relativePath,
|
|
2811
2545
|
params: $params
|
|
@@ -2996,7 +2730,7 @@ mutation addPendingDocumentMutation(
|
|
|
2996
2730
|
} else {
|
|
2997
2731
|
cms.alerts.info("Document created!");
|
|
2998
2732
|
if (typeof this.onNewDocument === "function") {
|
|
2999
|
-
this.onNewDocument(res.addPendingDocument.
|
|
2733
|
+
this.onNewDocument(res.addPendingDocument._sys);
|
|
3000
2734
|
}
|
|
3001
2735
|
}
|
|
3002
2736
|
} catch (e) {
|
|
@@ -3016,7 +2750,7 @@ mutation addPendingDocumentMutation(
|
|
|
3016
2750
|
var _a;
|
|
3017
2751
|
const res = await cms.api.tina.request((gql2) => gql2`
|
|
3018
2752
|
{
|
|
3019
|
-
|
|
2753
|
+
collections {
|
|
3020
2754
|
label
|
|
3021
2755
|
slug
|
|
3022
2756
|
format
|
|
@@ -3025,7 +2759,7 @@ mutation addPendingDocumentMutation(
|
|
|
3025
2759
|
}
|
|
3026
2760
|
`, { variables: {} });
|
|
3027
2761
|
const allCollectionOptions = [];
|
|
3028
|
-
res.
|
|
2762
|
+
res.collections.forEach((collection) => {
|
|
3029
2763
|
const value = collection.slug;
|
|
3030
2764
|
const label = `${collection.label}`;
|
|
3031
2765
|
allCollectionOptions.push({ value, label });
|
|
@@ -3047,7 +2781,7 @@ mutation addPendingDocumentMutation(
|
|
|
3047
2781
|
{ value: "", label: "Choose Template" }
|
|
3048
2782
|
];
|
|
3049
2783
|
if (values.collection) {
|
|
3050
|
-
const filteredCollection = res.
|
|
2784
|
+
const filteredCollection = res.collections.find((c) => c.slug === values.collection);
|
|
3051
2785
|
(_a = filteredCollection == null ? void 0 : filteredCollection.templates) == null ? void 0 : _a.forEach((template) => {
|
|
3052
2786
|
templateOptions.push({ value: template.name, label: template.label });
|
|
3053
2787
|
});
|
|
@@ -3055,7 +2789,7 @@ mutation addPendingDocumentMutation(
|
|
|
3055
2789
|
setPlugin(new ContentCreatorPlugin({
|
|
3056
2790
|
label: "Add Document",
|
|
3057
2791
|
onNewDocument: args && args.onNewDocument,
|
|
3058
|
-
collections: res.
|
|
2792
|
+
collections: res.collections,
|
|
3059
2793
|
onChange: async ({ values: values2 }) => {
|
|
3060
2794
|
setValues(values2);
|
|
3061
2795
|
},
|
|
@@ -3276,6 +3010,9 @@ mutation addPendingDocumentMutation(
|
|
|
3276
3010
|
clientId: props.clientId,
|
|
3277
3011
|
isLocalClient: props.isLocalClient
|
|
3278
3012
|
};
|
|
3013
|
+
if (!schema) {
|
|
3014
|
+
throw new Error("`schema` is required to be passed as a property to `TinaProvider`. You can learn more about this change here: https://github.com/tinacms/tinacms/pull/2823");
|
|
3015
|
+
}
|
|
3279
3016
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(TinaCloudProvider, {
|
|
3280
3017
|
branch,
|
|
3281
3018
|
clientId,
|
|
@@ -3325,25 +3062,13 @@ mutation addPendingDocumentMutation(
|
|
|
3325
3062
|
payload: void 0,
|
|
3326
3063
|
isLoading: true
|
|
3327
3064
|
});
|
|
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
3065
|
return /* @__PURE__ */ React__default["default"].createElement(sharedctx.TinaDataContext.Provider, {
|
|
3336
3066
|
value: {
|
|
3337
3067
|
setRequest,
|
|
3338
3068
|
isLoading: state.isLoading,
|
|
3339
3069
|
state: { payload: state.payload }
|
|
3340
3070
|
}
|
|
3341
|
-
},
|
|
3342
|
-
key: request == null ? void 0 : request.query,
|
|
3343
|
-
request,
|
|
3344
|
-
formifyCallback,
|
|
3345
|
-
onPayloadStateChange: setState
|
|
3346
|
-
}) : /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
|
|
3071
|
+
}, /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
|
|
3347
3072
|
key: request == null ? void 0 : request.query,
|
|
3348
3073
|
request,
|
|
3349
3074
|
formifyCallback,
|
|
@@ -3372,35 +3097,6 @@ mutation addPendingDocumentMutation(
|
|
|
3372
3097
|
}, [JSON.stringify(payload), isLoading]);
|
|
3373
3098
|
return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
|
|
3374
3099
|
};
|
|
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
3100
|
const Loader = (props) => {
|
|
3405
3101
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
3406
3102
|
style: {
|
|
@@ -3645,8 +3341,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3645
3341
|
const fetchCollections = async () => {
|
|
3646
3342
|
if (await api.isAuthenticated()) {
|
|
3647
3343
|
try {
|
|
3648
|
-
const
|
|
3649
|
-
setCollections(
|
|
3344
|
+
const collections2 = await api.fetchCollections();
|
|
3345
|
+
setCollections(collections2);
|
|
3650
3346
|
} catch (error2) {
|
|
3651
3347
|
console.error(error2);
|
|
3652
3348
|
setCollections([]);
|
|
@@ -3949,8 +3645,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3949
3645
|
const fetchCollection = async () => {
|
|
3950
3646
|
if (await api.isAuthenticated()) {
|
|
3951
3647
|
try {
|
|
3952
|
-
const
|
|
3953
|
-
setCollection(
|
|
3648
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments);
|
|
3649
|
+
setCollection(collection2);
|
|
3954
3650
|
} catch (error2) {
|
|
3955
3651
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
3956
3652
|
console.error(error2);
|
|
@@ -4016,7 +3712,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4016
3712
|
window.location.href = routeOverride;
|
|
4017
3713
|
return null;
|
|
4018
3714
|
} else {
|
|
4019
|
-
navigate(document.
|
|
3715
|
+
navigate(document._sys.breadcrumbs.join("/"));
|
|
4020
3716
|
}
|
|
4021
3717
|
};
|
|
4022
3718
|
const CollectionListPage = () => {
|
|
@@ -4069,9 +3765,9 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4069
3765
|
}, /* @__PURE__ */ React__default["default"].createElement("tbody", {
|
|
4070
3766
|
className: "divide-y divide-gray-150"
|
|
4071
3767
|
}, documents.map((document) => {
|
|
4072
|
-
const subfolders = document.node.
|
|
3768
|
+
const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
|
|
4073
3769
|
return /* @__PURE__ */ React__default["default"].createElement("tr", {
|
|
4074
|
-
key: `document-${document.node.
|
|
3770
|
+
key: `document-${document.node._sys.relativePath}`,
|
|
4075
3771
|
className: ""
|
|
4076
3772
|
}, /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4077
3773
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -4088,19 +3784,19 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4088
3784
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
4089
3785
|
}, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4090
3786
|
className: "text-xs text-gray-400"
|
|
4091
|
-
}, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node.
|
|
3787
|
+
}, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4092
3788
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4093
3789
|
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4094
3790
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4095
3791
|
}, "Extension"), /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4096
3792
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4097
|
-
}, document.node.
|
|
3793
|
+
}, document.node._sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4098
3794
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4099
3795
|
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4100
3796
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4101
3797
|
}, "Template"), /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4102
3798
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4103
|
-
}, document.node.
|
|
3799
|
+
}, document.node._sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4104
3800
|
className: "w-0"
|
|
4105
3801
|
}, /* @__PURE__ */ React__default["default"].createElement(toolkit.OverflowMenu, {
|
|
4106
3802
|
showEmbed: true,
|
|
@@ -4112,7 +3808,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4112
3808
|
size: "1.3rem"
|
|
4113
3809
|
}),
|
|
4114
3810
|
onMouseDown: () => {
|
|
4115
|
-
navigate(`${document.node.
|
|
3811
|
+
navigate(`${document.node._sys.filename}`, { replace: true });
|
|
4116
3812
|
}
|
|
4117
3813
|
},
|
|
4118
3814
|
{
|
|
@@ -4125,7 +3821,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4125
3821
|
onMouseDown: () => {
|
|
4126
3822
|
setVars({
|
|
4127
3823
|
collection: collectionName,
|
|
4128
|
-
relativePath: document.node.
|
|
3824
|
+
relativePath: document.node._sys.filename + document.node._sys.extension
|
|
4129
3825
|
});
|
|
4130
3826
|
setOpen(true);
|
|
4131
3827
|
}
|
|
@@ -4153,72 +3849,6 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4153
3849
|
}
|
|
4154
3850
|
}, "Delete"))));
|
|
4155
3851
|
};
|
|
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
3852
|
function HiChevronRight(props) {
|
|
4223
3853
|
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 20 20", "fill": "currentColor" }, "child": [{ "tag": "path", "attr": { "fillRule": "evenodd", "d": "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z", "clipRule": "evenodd" } }] })(props);
|
|
4224
3854
|
}
|
|
@@ -4244,34 +3874,39 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4244
3874
|
};
|
|
4245
3875
|
const CollectionCreatePage = () => {
|
|
4246
3876
|
const { collectionName, templateName } = reactRouterDom.useParams();
|
|
4247
|
-
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(
|
|
3877
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
|
|
4248
3878
|
cms,
|
|
4249
3879
|
collectionName,
|
|
4250
|
-
|
|
4251
|
-
}, (
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
3880
|
+
includeDocuments: false
|
|
3881
|
+
}, (collection) => {
|
|
3882
|
+
const mutationInfo = {
|
|
3883
|
+
includeCollection: true,
|
|
3884
|
+
includeTemplate: !!collection.templates
|
|
3885
|
+
};
|
|
3886
|
+
return /* @__PURE__ */ React__default["default"].createElement(RenderForm$1, {
|
|
3887
|
+
cms,
|
|
3888
|
+
collection,
|
|
3889
|
+
templateName,
|
|
3890
|
+
mutationInfo
|
|
3891
|
+
});
|
|
3892
|
+
}));
|
|
4258
3893
|
};
|
|
4259
|
-
const RenderForm$1 = ({ cms, collection,
|
|
3894
|
+
const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
|
|
4260
3895
|
var _a, _b;
|
|
4261
3896
|
const navigate = reactRouterDom.useNavigate();
|
|
4262
3897
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4263
3898
|
const schema = cms.api.tina.schema;
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
}
|
|
3899
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
3900
|
+
const template = schema.getTemplateForData({
|
|
3901
|
+
collection: schemaCollection,
|
|
3902
|
+
data: { _template: templateName }
|
|
3903
|
+
});
|
|
3904
|
+
const formInfo = schemaTools.resolveForm({
|
|
3905
|
+
collection: schemaCollection,
|
|
3906
|
+
basename: schemaCollection.name,
|
|
3907
|
+
schema,
|
|
3908
|
+
template
|
|
3909
|
+
});
|
|
4275
3910
|
const form = React.useMemo(() => {
|
|
4276
3911
|
return new toolkit.Form({
|
|
4277
3912
|
id: "create-form",
|
|
@@ -4296,7 +3931,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4296
3931
|
}
|
|
4297
3932
|
}
|
|
4298
3933
|
},
|
|
4299
|
-
...
|
|
3934
|
+
...formInfo.fields
|
|
4300
3935
|
],
|
|
4301
3936
|
onSubmit: async (values) => {
|
|
4302
3937
|
try {
|
|
@@ -4309,7 +3944,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4309
3944
|
}
|
|
4310
3945
|
}
|
|
4311
3946
|
});
|
|
4312
|
-
}, [cms, collection,
|
|
3947
|
+
}, [cms, collection, mutationInfo]);
|
|
4313
3948
|
return /* @__PURE__ */ React__default["default"].createElement(PageWrapper, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, ((_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.isLocalMode) && /* @__PURE__ */ React__default["default"].createElement(toolkit.LocalWarning, null), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4314
3949
|
className: "py-4 px-20 border-b border-gray-200 bg-white"
|
|
4315
3950
|
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -4342,7 +3977,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4342
3977
|
if (api.isAuthenticated()) {
|
|
4343
3978
|
try {
|
|
4344
3979
|
const response = await api.fetchDocument(collectionName, relativePath);
|
|
4345
|
-
setDocument(response.
|
|
3980
|
+
setDocument(response.document);
|
|
4346
3981
|
} catch (error2) {
|
|
4347
3982
|
cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
|
|
4348
3983
|
console.error(error2);
|
|
@@ -4391,11 +4026,16 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4391
4026
|
const CollectionUpdatePage = () => {
|
|
4392
4027
|
const _a = reactRouterDom.useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4393
4028
|
const { "*": filename } = rest;
|
|
4394
|
-
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(
|
|
4029
|
+
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetCollection, {
|
|
4395
4030
|
cms,
|
|
4396
|
-
collectionName
|
|
4397
|
-
|
|
4031
|
+
collectionName,
|
|
4032
|
+
includeDocuments: false
|
|
4033
|
+
}, (collection) => {
|
|
4398
4034
|
const relativePath = `${filename}.${collection.format}`;
|
|
4035
|
+
const mutationInfo = {
|
|
4036
|
+
includeCollection: true,
|
|
4037
|
+
includeTemplate: !!collection.templates
|
|
4038
|
+
};
|
|
4399
4039
|
return /* @__PURE__ */ React__default["default"].createElement(GetDocument, {
|
|
4400
4040
|
cms,
|
|
4401
4041
|
collectionName: collection.name,
|
|
@@ -4421,27 +4061,23 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4421
4061
|
var _a, _b;
|
|
4422
4062
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4423
4063
|
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
|
-
}
|
|
4064
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
4065
|
+
const template = schema.getTemplateForData({
|
|
4066
|
+
collection: schemaCollection,
|
|
4067
|
+
data: document._values
|
|
4068
|
+
});
|
|
4069
|
+
const formInfo = schemaTools.resolveForm({
|
|
4070
|
+
collection: schemaCollection,
|
|
4071
|
+
basename: schemaCollection.name,
|
|
4072
|
+
schema,
|
|
4073
|
+
template
|
|
4074
|
+
});
|
|
4439
4075
|
const form = React.useMemo(() => {
|
|
4440
4076
|
return new toolkit.Form({
|
|
4441
4077
|
id: "update-form",
|
|
4442
4078
|
label: "form",
|
|
4443
|
-
fields:
|
|
4444
|
-
initialValues: document.
|
|
4079
|
+
fields: formInfo.fields,
|
|
4080
|
+
initialValues: document._values,
|
|
4445
4081
|
onSubmit: async (values) => {
|
|
4446
4082
|
try {
|
|
4447
4083
|
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
@@ -4583,7 +4219,6 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4583
4219
|
exports2.staticRequest = staticRequest;
|
|
4584
4220
|
exports2.useDocumentCreatorPlugin = useDocumentCreatorPlugin;
|
|
4585
4221
|
exports2.useGraphqlForms = useGraphqlForms;
|
|
4586
|
-
exports2.useGraphqlFormsUnstable = useGraphqlFormsUnstable;
|
|
4587
4222
|
exports2.useTinaAuthRedirect = useTinaAuthRedirect;
|
|
4588
4223
|
Object.keys(toolkit).forEach(function(k) {
|
|
4589
4224
|
if (k !== "default" && !exports2.hasOwnProperty(k))
|