tinacms 0.67.3 → 0.68.1
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 +188 -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 +219 -576
- package/dist/index.js +217 -575
- package/dist/utils/parseUrl.d.ts +18 -0
- 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
|
},
|
|
@@ -3152,6 +2889,30 @@ mutation addPendingDocumentMutation(
|
|
|
3152
2889
|
isLoading
|
|
3153
2890
|
};
|
|
3154
2891
|
}
|
|
2892
|
+
const TINA_HOST = "content.tinajs.io";
|
|
2893
|
+
const parseURL = (url) => {
|
|
2894
|
+
if (url.includes("localhost")) {
|
|
2895
|
+
return { branch: null, isLocalClient: true, clientId: null };
|
|
2896
|
+
}
|
|
2897
|
+
const params = new URL(url);
|
|
2898
|
+
const pattern = new UrlPattern__default["default"]("/content/:clientId/github/*", {
|
|
2899
|
+
escapeChar: " "
|
|
2900
|
+
});
|
|
2901
|
+
const result = pattern.match(params.pathname);
|
|
2902
|
+
const branch = result == null ? void 0 : result._;
|
|
2903
|
+
const clientId = result == null ? void 0 : result.clientId;
|
|
2904
|
+
if (!branch || !clientId) {
|
|
2905
|
+
throw new Error(`Invalid URL format provided. Expected: https://content.tinajs.io/content/<ClientID>/github/<Branch> but but received ${url}`);
|
|
2906
|
+
}
|
|
2907
|
+
if (params.host !== TINA_HOST) {
|
|
2908
|
+
throw new Error(`The only supported hosts are ${TINA_HOST} or localhost, but received ${params.host}.`);
|
|
2909
|
+
}
|
|
2910
|
+
return {
|
|
2911
|
+
branch,
|
|
2912
|
+
clientId,
|
|
2913
|
+
isLocalClient: false
|
|
2914
|
+
};
|
|
2915
|
+
};
|
|
3155
2916
|
const errorButtonStyles = {
|
|
3156
2917
|
background: "#eb6337",
|
|
3157
2918
|
padding: "12px 18px",
|
|
@@ -3231,21 +2992,6 @@ mutation addPendingDocumentMutation(
|
|
|
3231
2992
|
return this.props.children;
|
|
3232
2993
|
}
|
|
3233
2994
|
}
|
|
3234
|
-
const parseURL = (url) => {
|
|
3235
|
-
if (url.includes("localhost")) {
|
|
3236
|
-
return { branch: null, isLocalClient: true, clientId: null };
|
|
3237
|
-
}
|
|
3238
|
-
const tinaHost = "content.tinajs.io";
|
|
3239
|
-
const params = new URL(url);
|
|
3240
|
-
const pattern = new UrlPattern__default["default"]("/content/:clientId/github/:branch");
|
|
3241
|
-
const result = pattern.match(params.pathname);
|
|
3242
|
-
if (params.host !== tinaHost) {
|
|
3243
|
-
throw new Error(`The only supported hosts are ${tinaHost} or localhost, but received ${params.host}.`);
|
|
3244
|
-
}
|
|
3245
|
-
return __spreadProps(__spreadValues({}, result), {
|
|
3246
|
-
isLocalClient: false
|
|
3247
|
-
});
|
|
3248
|
-
};
|
|
3249
2995
|
const TinaCMSProvider2 = (_c) => {
|
|
3250
2996
|
var _d = _c, {
|
|
3251
2997
|
query,
|
|
@@ -3267,6 +3013,9 @@ mutation addPendingDocumentMutation(
|
|
|
3267
3013
|
clientId: props.clientId,
|
|
3268
3014
|
isLocalClient: props.isLocalClient
|
|
3269
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
|
+
}
|
|
3270
3019
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(TinaCloudProvider, {
|
|
3271
3020
|
branch,
|
|
3272
3021
|
clientId,
|
|
@@ -3316,25 +3065,13 @@ mutation addPendingDocumentMutation(
|
|
|
3316
3065
|
payload: void 0,
|
|
3317
3066
|
isLoading: true
|
|
3318
3067
|
});
|
|
3319
|
-
const cms = toolkit.useCMS();
|
|
3320
|
-
const useUnstableFormify = React__default["default"].useMemo(() => {
|
|
3321
|
-
if ((cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false) {
|
|
3322
|
-
return false;
|
|
3323
|
-
}
|
|
3324
|
-
return true;
|
|
3325
|
-
}, [cms == null ? void 0 : cms.flags]);
|
|
3326
3068
|
return /* @__PURE__ */ React__default["default"].createElement(sharedctx.TinaDataContext.Provider, {
|
|
3327
3069
|
value: {
|
|
3328
3070
|
setRequest,
|
|
3329
3071
|
isLoading: state.isLoading,
|
|
3330
3072
|
state: { payload: state.payload }
|
|
3331
3073
|
}
|
|
3332
|
-
},
|
|
3333
|
-
key: request == null ? void 0 : request.query,
|
|
3334
|
-
request,
|
|
3335
|
-
formifyCallback,
|
|
3336
|
-
onPayloadStateChange: setState
|
|
3337
|
-
}) : /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
|
|
3074
|
+
}, /* @__PURE__ */ React__default["default"].createElement(FormRegistrar, {
|
|
3338
3075
|
key: request == null ? void 0 : request.query,
|
|
3339
3076
|
request,
|
|
3340
3077
|
formifyCallback,
|
|
@@ -3363,35 +3100,6 @@ mutation addPendingDocumentMutation(
|
|
|
3363
3100
|
}, [JSON.stringify(payload), isLoading]);
|
|
3364
3101
|
return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
|
|
3365
3102
|
};
|
|
3366
|
-
const FormRegistrarUnstable = (props) => {
|
|
3367
|
-
var _a;
|
|
3368
|
-
if (!((_a = props.request) == null ? void 0 : _a.query)) {
|
|
3369
|
-
return null;
|
|
3370
|
-
}
|
|
3371
|
-
return /* @__PURE__ */ React__default["default"].createElement(FormRegistrarUnstableInner, __spreadValues({}, props));
|
|
3372
|
-
};
|
|
3373
|
-
const FormRegistrarUnstableInner = ({
|
|
3374
|
-
request,
|
|
3375
|
-
formifyCallback,
|
|
3376
|
-
onPayloadStateChange
|
|
3377
|
-
}) => {
|
|
3378
|
-
const cms = toolkit.useCMS();
|
|
3379
|
-
const [payload, isLoading] = useGraphqlFormsUnstable({
|
|
3380
|
-
query: request == null ? void 0 : request.query,
|
|
3381
|
-
variables: request == null ? void 0 : request.variables,
|
|
3382
|
-
formify: (args) => {
|
|
3383
|
-
if (formifyCallback) {
|
|
3384
|
-
return formifyCallback(args, cms);
|
|
3385
|
-
} else {
|
|
3386
|
-
return args.createForm(args.formConfig);
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
});
|
|
3390
|
-
React__default["default"].useEffect(() => {
|
|
3391
|
-
onPayloadStateChange({ payload, isLoading });
|
|
3392
|
-
}, [JSON.stringify(payload), isLoading]);
|
|
3393
|
-
return isLoading ? /* @__PURE__ */ React__default["default"].createElement(Loader, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null)) : null;
|
|
3394
|
-
};
|
|
3395
3103
|
const Loader = (props) => {
|
|
3396
3104
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
3397
3105
|
style: {
|
|
@@ -3636,8 +3344,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3636
3344
|
const fetchCollections = async () => {
|
|
3637
3345
|
if (await api.isAuthenticated()) {
|
|
3638
3346
|
try {
|
|
3639
|
-
const
|
|
3640
|
-
setCollections(
|
|
3347
|
+
const collections2 = await api.fetchCollections();
|
|
3348
|
+
setCollections(collections2);
|
|
3641
3349
|
} catch (error2) {
|
|
3642
3350
|
console.error(error2);
|
|
3643
3351
|
setCollections([]);
|
|
@@ -3940,8 +3648,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3940
3648
|
const fetchCollection = async () => {
|
|
3941
3649
|
if (await api.isAuthenticated()) {
|
|
3942
3650
|
try {
|
|
3943
|
-
const
|
|
3944
|
-
setCollection(
|
|
3651
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments);
|
|
3652
|
+
setCollection(collection2);
|
|
3945
3653
|
} catch (error2) {
|
|
3946
3654
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
3947
3655
|
console.error(error2);
|
|
@@ -4007,7 +3715,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4007
3715
|
window.location.href = routeOverride;
|
|
4008
3716
|
return null;
|
|
4009
3717
|
} else {
|
|
4010
|
-
navigate(document.
|
|
3718
|
+
navigate(document._sys.breadcrumbs.join("/"));
|
|
4011
3719
|
}
|
|
4012
3720
|
};
|
|
4013
3721
|
const CollectionListPage = () => {
|
|
@@ -4060,9 +3768,9 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4060
3768
|
}, /* @__PURE__ */ React__default["default"].createElement("tbody", {
|
|
4061
3769
|
className: "divide-y divide-gray-150"
|
|
4062
3770
|
}, documents.map((document) => {
|
|
4063
|
-
const subfolders = document.node.
|
|
3771
|
+
const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
|
|
4064
3772
|
return /* @__PURE__ */ React__default["default"].createElement("tr", {
|
|
4065
|
-
key: `document-${document.node.
|
|
3773
|
+
key: `document-${document.node._sys.relativePath}`,
|
|
4066
3774
|
className: ""
|
|
4067
3775
|
}, /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4068
3776
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -4079,22 +3787,21 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4079
3787
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
4080
3788
|
}, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4081
3789
|
className: "text-xs text-gray-400"
|
|
4082
|
-
}, `${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", {
|
|
4083
3791
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4084
3792
|
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4085
3793
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4086
3794
|
}, "Extension"), /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4087
3795
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4088
|
-
}, document.node.
|
|
3796
|
+
}, document.node._sys.extension)), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4089
3797
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4090
3798
|
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4091
3799
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4092
3800
|
}, "Template"), /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4093
3801
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4094
|
-
}, document.node.
|
|
3802
|
+
}, document.node._sys.template)), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
4095
3803
|
className: "w-0"
|
|
4096
3804
|
}, /* @__PURE__ */ React__default["default"].createElement(toolkit.OverflowMenu, {
|
|
4097
|
-
showEmbed: true,
|
|
4098
3805
|
toolbarItems: [
|
|
4099
3806
|
{
|
|
4100
3807
|
name: "edit",
|
|
@@ -4103,7 +3810,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4103
3810
|
size: "1.3rem"
|
|
4104
3811
|
}),
|
|
4105
3812
|
onMouseDown: () => {
|
|
4106
|
-
navigate(`${document.node.
|
|
3813
|
+
navigate(`${document.node._sys.filename}`, { replace: true });
|
|
4107
3814
|
}
|
|
4108
3815
|
},
|
|
4109
3816
|
{
|
|
@@ -4116,7 +3823,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4116
3823
|
onMouseDown: () => {
|
|
4117
3824
|
setVars({
|
|
4118
3825
|
collection: collectionName,
|
|
4119
|
-
relativePath: document.node.
|
|
3826
|
+
relativePath: document.node._sys.filename + document.node._sys.extension
|
|
4120
3827
|
});
|
|
4121
3828
|
setOpen(true);
|
|
4122
3829
|
}
|
|
@@ -4130,7 +3837,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4130
3837
|
const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
4131
3838
|
return /* @__PURE__ */ React__default["default"].createElement(toolkit.Modal, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalPopup, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalHeader, {
|
|
4132
3839
|
close: close2
|
|
4133
|
-
}, "
|
|
3840
|
+
}, "Delete ", filename), /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalBody, {
|
|
4134
3841
|
padded: true
|
|
4135
3842
|
}, /* @__PURE__ */ React__default["default"].createElement("p", null, `Are you sure you want to delete ${filename}?`)), /* @__PURE__ */ React__default["default"].createElement(toolkit.ModalActions, null, /* @__PURE__ */ React__default["default"].createElement(toolkit.Button, {
|
|
4136
3843
|
style: { flexGrow: 2 },
|
|
@@ -4144,72 +3851,6 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4144
3851
|
}
|
|
4145
3852
|
}, "Delete"))));
|
|
4146
3853
|
};
|
|
4147
|
-
const useGetDocumentFields = (cms, collectionName, templateName) => {
|
|
4148
|
-
const api = new TinaAdminApi(cms);
|
|
4149
|
-
const [info, setInfo] = React.useState({
|
|
4150
|
-
collection: void 0,
|
|
4151
|
-
template: void 0,
|
|
4152
|
-
fields: void 0,
|
|
4153
|
-
mutationInfo: void 0
|
|
4154
|
-
});
|
|
4155
|
-
const [loading, setLoading] = React.useState(true);
|
|
4156
|
-
const [error, setError] = React.useState(void 0);
|
|
4157
|
-
React.useEffect(() => {
|
|
4158
|
-
const fetchDocumentFields = async () => {
|
|
4159
|
-
if (await api.isAuthenticated()) {
|
|
4160
|
-
try {
|
|
4161
|
-
const response = await api.fetchDocumentFields();
|
|
4162
|
-
const documentFields = response.getDocumentFields;
|
|
4163
|
-
const collection = documentFields[collectionName].collection;
|
|
4164
|
-
const mutationInfo = documentFields[collectionName].mutationInfo;
|
|
4165
|
-
let fields = void 0;
|
|
4166
|
-
let template = void 0;
|
|
4167
|
-
if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
|
|
4168
|
-
template = documentFields[collectionName].templates[templateName].template;
|
|
4169
|
-
fields = documentFields[collectionName].templates[templateName].fields;
|
|
4170
|
-
} else {
|
|
4171
|
-
fields = documentFields[collectionName].fields;
|
|
4172
|
-
}
|
|
4173
|
-
setInfo({
|
|
4174
|
-
collection,
|
|
4175
|
-
template,
|
|
4176
|
-
fields,
|
|
4177
|
-
mutationInfo
|
|
4178
|
-
});
|
|
4179
|
-
} catch (error2) {
|
|
4180
|
-
cms.alerts.error(`[${error2.name}] GetDocumentFields failed: ${error2.message}`, 30 * 1e3);
|
|
4181
|
-
console.error(error2);
|
|
4182
|
-
setInfo({
|
|
4183
|
-
collection: void 0,
|
|
4184
|
-
template: void 0,
|
|
4185
|
-
fields: void 0,
|
|
4186
|
-
mutationInfo: void 0
|
|
4187
|
-
});
|
|
4188
|
-
setError(error2);
|
|
4189
|
-
}
|
|
4190
|
-
setLoading(false);
|
|
4191
|
-
}
|
|
4192
|
-
};
|
|
4193
|
-
setLoading(true);
|
|
4194
|
-
fetchDocumentFields();
|
|
4195
|
-
}, [cms, collectionName]);
|
|
4196
|
-
return __spreadProps(__spreadValues({}, info), { loading, error });
|
|
4197
|
-
};
|
|
4198
|
-
const GetDocumentFields = ({
|
|
4199
|
-
cms,
|
|
4200
|
-
collectionName,
|
|
4201
|
-
templateName,
|
|
4202
|
-
children
|
|
4203
|
-
}) => {
|
|
4204
|
-
const { collection, template, fields, mutationInfo, loading, error } = useGetDocumentFields(cms, collectionName, templateName);
|
|
4205
|
-
if (error) {
|
|
4206
|
-
return null;
|
|
4207
|
-
}
|
|
4208
|
-
if (loading) {
|
|
4209
|
-
return /* @__PURE__ */ React__default["default"].createElement(LoadingPage, null);
|
|
4210
|
-
}
|
|
4211
|
-
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children({ collection, template, fields, mutationInfo, loading }));
|
|
4212
|
-
};
|
|
4213
3854
|
function HiChevronRight(props) {
|
|
4214
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);
|
|
4215
3856
|
}
|
|
@@ -4235,38 +3876,39 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4235
3876
|
};
|
|
4236
3877
|
const CollectionCreatePage = () => {
|
|
4237
3878
|
const { collectionName, templateName } = reactRouterDom.useParams();
|
|
4238
|
-
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, {
|
|
4239
3880
|
cms,
|
|
4240
3881
|
collectionName,
|
|
4241
|
-
|
|
4242
|
-
}, (
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
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
|
+
}));
|
|
4249
3895
|
};
|
|
4250
|
-
const RenderForm$1 = ({ cms, collection,
|
|
3896
|
+
const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
|
|
4251
3897
|
var _a, _b;
|
|
4252
3898
|
const navigate = reactRouterDom.useNavigate();
|
|
4253
3899
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4254
3900
|
const schema = cms.api.tina.schema;
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
template: template2
|
|
4267
|
-
});
|
|
4268
|
-
schemaFields = formInfo.fields;
|
|
4269
|
-
}
|
|
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
|
+
});
|
|
4270
3912
|
const form = React.useMemo(() => {
|
|
4271
3913
|
return new toolkit.Form({
|
|
4272
3914
|
id: "create-form",
|
|
@@ -4291,7 +3933,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4291
3933
|
}
|
|
4292
3934
|
}
|
|
4293
3935
|
},
|
|
4294
|
-
...
|
|
3936
|
+
...formInfo.fields
|
|
4295
3937
|
],
|
|
4296
3938
|
onSubmit: async (values) => {
|
|
4297
3939
|
try {
|
|
@@ -4304,7 +3946,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4304
3946
|
}
|
|
4305
3947
|
}
|
|
4306
3948
|
});
|
|
4307
|
-
}, [cms, collection,
|
|
3949
|
+
}, [cms, collection, mutationInfo]);
|
|
4308
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", {
|
|
4309
3951
|
className: "py-4 px-20 border-b border-gray-200 bg-white"
|
|
4310
3952
|
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -4337,7 +3979,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4337
3979
|
if (api.isAuthenticated()) {
|
|
4338
3980
|
try {
|
|
4339
3981
|
const response = await api.fetchDocument(collectionName, relativePath);
|
|
4340
|
-
setDocument(response.
|
|
3982
|
+
setDocument(response.document);
|
|
4341
3983
|
} catch (error2) {
|
|
4342
3984
|
cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
|
|
4343
3985
|
console.error(error2);
|
|
@@ -4386,11 +4028,16 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4386
4028
|
const CollectionUpdatePage = () => {
|
|
4387
4029
|
const _a = reactRouterDom.useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4388
4030
|
const { "*": filename } = rest;
|
|
4389
|
-
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, {
|
|
4390
4032
|
cms,
|
|
4391
|
-
collectionName
|
|
4392
|
-
|
|
4033
|
+
collectionName,
|
|
4034
|
+
includeDocuments: false
|
|
4035
|
+
}, (collection) => {
|
|
4393
4036
|
const relativePath = `${filename}.${collection.format}`;
|
|
4037
|
+
const mutationInfo = {
|
|
4038
|
+
includeCollection: true,
|
|
4039
|
+
includeTemplate: !!collection.templates
|
|
4040
|
+
};
|
|
4394
4041
|
return /* @__PURE__ */ React__default["default"].createElement(GetDocument, {
|
|
4395
4042
|
cms,
|
|
4396
4043
|
collectionName: collection.name,
|
|
@@ -4416,27 +4063,23 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4416
4063
|
var _a, _b;
|
|
4417
4064
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4418
4065
|
const schema = cms.api.tina.schema;
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
template
|
|
4431
|
-
});
|
|
4432
|
-
schemaFields = formInfo.fields;
|
|
4433
|
-
}
|
|
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
|
+
});
|
|
4434
4077
|
const form = React.useMemo(() => {
|
|
4435
4078
|
return new toolkit.Form({
|
|
4436
4079
|
id: "update-form",
|
|
4437
4080
|
label: "form",
|
|
4438
|
-
fields:
|
|
4439
|
-
initialValues: document.
|
|
4081
|
+
fields: formInfo.fields,
|
|
4082
|
+
initialValues: document._values,
|
|
4440
4083
|
onSubmit: async (values) => {
|
|
4441
4084
|
try {
|
|
4442
4085
|
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
@@ -4578,7 +4221,6 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4578
4221
|
exports2.staticRequest = staticRequest;
|
|
4579
4222
|
exports2.useDocumentCreatorPlugin = useDocumentCreatorPlugin;
|
|
4580
4223
|
exports2.useGraphqlForms = useGraphqlForms;
|
|
4581
|
-
exports2.useGraphqlFormsUnstable = useGraphqlFormsUnstable;
|
|
4582
4224
|
exports2.useTinaAuthRedirect = useTinaAuthRedirect;
|
|
4583
4225
|
Object.keys(toolkit).forEach(function(k) {
|
|
4584
4226
|
if (k !== "default" && !exports2.hasOwnProperty(k))
|