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.es.js
CHANGED
|
@@ -29,7 +29,7 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import { useCMS,
|
|
32
|
+
import { useCMS, Form, GlobalFormPlugin, EventBus, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, useLocalStorage, TinaCMS, BranchSwitcherPlugin, BranchDataProvider, TinaProvider, Nav, LocalWarning, OverflowMenu, FormStatus, FormBuilder } from "@tinacms/toolkit";
|
|
33
33
|
export * from "@tinacms/toolkit";
|
|
34
34
|
import * as G from "graphql";
|
|
35
35
|
import { TypeInfo, visit, visitWithTypeInfo, getNamedType, GraphQLObjectType, isLeafType, GraphQLUnionType, isScalarType as isScalarType$1, getIntrospectionQuery, buildClientSchema, print, parse } from "graphql";
|
|
@@ -409,7 +409,7 @@ function safeAssertShape(value, yupSchema) {
|
|
|
409
409
|
return false;
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
function
|
|
412
|
+
function useGraphqlForms({
|
|
413
413
|
variables,
|
|
414
414
|
onSubmit,
|
|
415
415
|
query,
|
|
@@ -427,239 +427,6 @@ function useGraphqlFormsUnstable({
|
|
|
427
427
|
});
|
|
428
428
|
return [state.data, state.status !== "done"];
|
|
429
429
|
}
|
|
430
|
-
function useGraphqlForms({
|
|
431
|
-
variables,
|
|
432
|
-
onSubmit,
|
|
433
|
-
formify: formify2 = null,
|
|
434
|
-
query
|
|
435
|
-
}) {
|
|
436
|
-
const cms = useCMS();
|
|
437
|
-
const [formValues, setFormValues] = React.useState({});
|
|
438
|
-
const [data, setData] = React.useState(null);
|
|
439
|
-
const [initialData, setInitialData] = React.useState({});
|
|
440
|
-
const [pendingReset, setPendingReset] = React.useState(null);
|
|
441
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
442
|
-
const [newUpdate, setNewUpdate] = React.useState(null);
|
|
443
|
-
const { currentBranch } = useBranchData();
|
|
444
|
-
const updateData = async () => {
|
|
445
|
-
var _a;
|
|
446
|
-
if (newUpdate) {
|
|
447
|
-
const newValue = getIn(formValues, newUpdate.get);
|
|
448
|
-
const activeForm = getIn(data, [newUpdate.queryName, "form"].join("."));
|
|
449
|
-
if (!activeForm) {
|
|
450
|
-
throw new Error(`Unable to find form for query ${newUpdate.queryName}`);
|
|
451
|
-
}
|
|
452
|
-
if (activeForm == null ? void 0 : activeForm.paths) {
|
|
453
|
-
const asyncUpdate = (_a = activeForm.paths) == null ? void 0 : _a.find((p) => p.dataPath.join(".") === newUpdate.setReference);
|
|
454
|
-
if (asyncUpdate) {
|
|
455
|
-
const res = await cms.api.tina.request(asyncUpdate.queryString, {
|
|
456
|
-
variables: { id: newValue }
|
|
457
|
-
});
|
|
458
|
-
const newData2 = setIn(data, newUpdate.set, res.node);
|
|
459
|
-
const newDataAndNewJSONData2 = setIn(newData2, newUpdate.set.replace("data", "dataJSON"), newValue);
|
|
460
|
-
setData(newDataAndNewJSONData2);
|
|
461
|
-
setNewUpdate(null);
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (newUpdate.lookup) {
|
|
466
|
-
const field = getFieldUpdate(newUpdate, activeForm, formValues);
|
|
467
|
-
if (field && field.typeMap) {
|
|
468
|
-
newValue.forEach((item) => {
|
|
469
|
-
if (!item.__typename) {
|
|
470
|
-
item["__typename"] = field.typeMap[item._template];
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
const newData = setIn(data, newUpdate.set, newValue);
|
|
476
|
-
const newDataAndNewJSONData = setIn(newData, newUpdate.set.replace("data", "dataJSON"), newValue);
|
|
477
|
-
setData(newDataAndNewJSONData);
|
|
478
|
-
setNewUpdate(null);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
React.useEffect(() => {
|
|
482
|
-
updateData();
|
|
483
|
-
}, [JSON.stringify(formValues)]);
|
|
484
|
-
React.useEffect(() => {
|
|
485
|
-
if (pendingReset) {
|
|
486
|
-
setData(__spreadProps(__spreadValues({}, data), { [pendingReset]: initialData[pendingReset] }));
|
|
487
|
-
setPendingReset(null);
|
|
488
|
-
}
|
|
489
|
-
}, [pendingReset]);
|
|
490
|
-
React.useEffect(() => {
|
|
491
|
-
if (!query) {
|
|
492
|
-
setIsLoading(false);
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
const useUnstableFormify = (cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false ? false : true;
|
|
496
|
-
const formIds = [];
|
|
497
|
-
setIsLoading(true);
|
|
498
|
-
cms.api.tina.requestWithForm((gql2) => gql2(query), {
|
|
499
|
-
variables,
|
|
500
|
-
useUnstableFormify
|
|
501
|
-
}).then((payload) => {
|
|
502
|
-
cms.plugins.remove(new FormMetaPlugin({ name: "tina-admin-link" }));
|
|
503
|
-
setData(payload);
|
|
504
|
-
setInitialData(payload);
|
|
505
|
-
setIsLoading(false);
|
|
506
|
-
Object.entries(payload).map(([queryName, result]) => {
|
|
507
|
-
formIds.push(queryName);
|
|
508
|
-
const canBeFormified = safeAssertShape(result, (yup2) => yup2.object({
|
|
509
|
-
values: yup2.object().required(),
|
|
510
|
-
form: yup2.object().required()
|
|
511
|
-
}));
|
|
512
|
-
if (!canBeFormified) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
assertShape(result, (yup2) => yup2.object({
|
|
516
|
-
values: yup2.object().required(),
|
|
517
|
-
form: yup2.object().required()
|
|
518
|
-
}), `Unable to build form shape for fields at ${queryName}`);
|
|
519
|
-
let formConfig = {};
|
|
520
|
-
const formCommon = {
|
|
521
|
-
id: queryName,
|
|
522
|
-
initialValues: result.values,
|
|
523
|
-
reset: () => {
|
|
524
|
-
setPendingReset(queryName);
|
|
525
|
-
},
|
|
526
|
-
onSubmit: async (payload2) => {
|
|
527
|
-
try {
|
|
528
|
-
const params = transformDocumentIntoMutationRequestPayload(payload2, result.form.mutationInfo);
|
|
529
|
-
const variables2 = { params };
|
|
530
|
-
const mutationString = result.form.mutationInfo.string;
|
|
531
|
-
if (onSubmit) {
|
|
532
|
-
onSubmit({
|
|
533
|
-
queryString: mutationString,
|
|
534
|
-
mutationString,
|
|
535
|
-
variables: variables2
|
|
536
|
-
});
|
|
537
|
-
} else {
|
|
538
|
-
try {
|
|
539
|
-
await cms.api.tina.request(mutationString, {
|
|
540
|
-
variables: variables2
|
|
541
|
-
});
|
|
542
|
-
cms.alerts.success("Document saved!");
|
|
543
|
-
} catch (e) {
|
|
544
|
-
cms.alerts.error("There was a problem saving your document");
|
|
545
|
-
console.error(e);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
} catch (e) {
|
|
549
|
-
console.error(e);
|
|
550
|
-
cms.alerts.error("There was a problem saving your document");
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
if (cms.api.tina.schema) {
|
|
555
|
-
const enrichedSchema = cms.api.tina.schema;
|
|
556
|
-
const collection = enrichedSchema.getCollection(result._internalSys.collection.name);
|
|
557
|
-
const template = enrichedSchema.getTemplateForData({
|
|
558
|
-
collection,
|
|
559
|
-
data: result.values
|
|
560
|
-
});
|
|
561
|
-
const formInfo = resolveForm({
|
|
562
|
-
collection,
|
|
563
|
-
basename: collection.name,
|
|
564
|
-
schema: enrichedSchema,
|
|
565
|
-
template
|
|
566
|
-
});
|
|
567
|
-
formConfig = __spreadValues({
|
|
568
|
-
label: formInfo.label,
|
|
569
|
-
fields: formInfo.fields
|
|
570
|
-
}, formCommon);
|
|
571
|
-
} else {
|
|
572
|
-
formConfig = __spreadValues({
|
|
573
|
-
label: result.form.label,
|
|
574
|
-
fields: result.form.fields
|
|
575
|
-
}, formCommon);
|
|
576
|
-
}
|
|
577
|
-
const { createForm, createGlobalForm } = generateFormCreators(cms);
|
|
578
|
-
const SKIPPED = "SKIPPED";
|
|
579
|
-
let form;
|
|
580
|
-
let skipped;
|
|
581
|
-
const skip = () => {
|
|
582
|
-
skipped = SKIPPED;
|
|
583
|
-
};
|
|
584
|
-
if (skipped)
|
|
585
|
-
return;
|
|
586
|
-
if (formify2) {
|
|
587
|
-
form = formify2({ formConfig, createForm, createGlobalForm, skip }, cms);
|
|
588
|
-
} else {
|
|
589
|
-
form = createForm(formConfig);
|
|
590
|
-
}
|
|
591
|
-
if (!(form instanceof Form)) {
|
|
592
|
-
if (skipped === SKIPPED) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
throw new Error("formify must return a form or skip()");
|
|
596
|
-
}
|
|
597
|
-
const { change } = form.finalForm;
|
|
598
|
-
form.finalForm.change = (name, value) => {
|
|
599
|
-
let referenceName = "";
|
|
600
|
-
if (typeof name === "string") {
|
|
601
|
-
referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
|
|
602
|
-
} else {
|
|
603
|
-
throw new Error(`Expected name to be of type string for FinalForm change callback`);
|
|
604
|
-
}
|
|
605
|
-
setNewUpdate({
|
|
606
|
-
queryName,
|
|
607
|
-
get: [queryName, "values", name].join("."),
|
|
608
|
-
set: [queryName, "data", name].join("."),
|
|
609
|
-
setReference: [queryName, "data", referenceName].join(".")
|
|
610
|
-
});
|
|
611
|
-
return change(name, value);
|
|
612
|
-
};
|
|
613
|
-
const _a = form.finalForm.mutators, { insert, move, remove } = _a, rest = __objRest(_a, ["insert", "move", "remove"]);
|
|
614
|
-
const prepareNewUpdate = (name, lookup) => {
|
|
615
|
-
const extra = {};
|
|
616
|
-
if (lookup) {
|
|
617
|
-
extra["lookup"] = lookup;
|
|
618
|
-
}
|
|
619
|
-
const referenceName = name.split(".").filter((item) => isNaN(Number(item))).join(".");
|
|
620
|
-
setNewUpdate(__spreadValues({
|
|
621
|
-
queryName,
|
|
622
|
-
get: [queryName, "values", name].join("."),
|
|
623
|
-
set: [queryName, "data", name].join("."),
|
|
624
|
-
setReference: [queryName, "data", referenceName].join(".")
|
|
625
|
-
}, extra));
|
|
626
|
-
};
|
|
627
|
-
form.finalForm.mutators = __spreadValues({
|
|
628
|
-
insert: (...args) => {
|
|
629
|
-
const fieldName = args[0];
|
|
630
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
631
|
-
insert(...args);
|
|
632
|
-
},
|
|
633
|
-
move: (...args) => {
|
|
634
|
-
const fieldName = args[0];
|
|
635
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
636
|
-
move(...args);
|
|
637
|
-
},
|
|
638
|
-
remove: (...args) => {
|
|
639
|
-
const fieldName = args[0];
|
|
640
|
-
prepareNewUpdate(fieldName, fieldName);
|
|
641
|
-
remove(...args);
|
|
642
|
-
}
|
|
643
|
-
}, rest);
|
|
644
|
-
form.subscribe(({ values }) => {
|
|
645
|
-
setFormValues(__spreadProps(__spreadValues({}, formValues), { [queryName]: { values } }));
|
|
646
|
-
}, { values: true });
|
|
647
|
-
});
|
|
648
|
-
}).catch((e) => {
|
|
649
|
-
setIsLoading(false);
|
|
650
|
-
throw new Error(`There was a problem setting up forms for your query: ${e.message}`);
|
|
651
|
-
});
|
|
652
|
-
return () => {
|
|
653
|
-
formIds.forEach((name) => {
|
|
654
|
-
const formPlugin = cms.forms.find(name);
|
|
655
|
-
if (formPlugin) {
|
|
656
|
-
cms.forms.remove(formPlugin);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
};
|
|
660
|
-
}, [query, JSON.stringify(variables), currentBranch]);
|
|
661
|
-
return [data, isLoading];
|
|
662
|
-
}
|
|
663
430
|
const transformDocumentIntoMutationRequestPayload = (document, instructions) => {
|
|
664
431
|
const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
|
|
665
432
|
const params = transformParams(rest);
|
|
@@ -696,37 +463,7 @@ const transformParams = (data) => {
|
|
|
696
463
|
}
|
|
697
464
|
}
|
|
698
465
|
};
|
|
699
|
-
const
|
|
700
|
-
const items = newUpdate.lookup.split(".");
|
|
701
|
-
let currentFields = activeForm.fields;
|
|
702
|
-
items.map((item, index) => {
|
|
703
|
-
const lookupName = items.slice(0, index + 1).join(".");
|
|
704
|
-
const value = getIn(formValues, [newUpdate.queryName, "values", lookupName].join("."));
|
|
705
|
-
if (isNaN(Number(item))) {
|
|
706
|
-
if (Array.isArray(currentFields)) {
|
|
707
|
-
currentFields = currentFields.find((field) => field.name === item);
|
|
708
|
-
}
|
|
709
|
-
} else {
|
|
710
|
-
const template = currentFields.templates ? currentFields.templates[value._template] : currentFields;
|
|
711
|
-
currentFields = template.fields;
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
return currentFields;
|
|
715
|
-
};
|
|
716
|
-
const generateFormCreators = (cms) => {
|
|
717
|
-
const createForm = (formConfig) => {
|
|
718
|
-
const form = new Form(formConfig);
|
|
719
|
-
cms.forms.add(form);
|
|
720
|
-
return form;
|
|
721
|
-
};
|
|
722
|
-
const createGlobalForm = (formConfig, options) => {
|
|
723
|
-
const form = new Form(formConfig);
|
|
724
|
-
cms.plugins.add(new GlobalFormPlugin(form, options == null ? void 0 : options.icon, options == null ? void 0 : options.layout));
|
|
725
|
-
return form;
|
|
726
|
-
};
|
|
727
|
-
return { createForm, createGlobalForm };
|
|
728
|
-
};
|
|
729
|
-
const generateFormCreatorsUnstable = (cms, showInSidebar) => {
|
|
466
|
+
const generateFormCreators = (cms, showInSidebar) => {
|
|
730
467
|
const createForm = (formConfig) => {
|
|
731
468
|
const form = new Form(formConfig);
|
|
732
469
|
if (showInSidebar) {
|
|
@@ -810,7 +547,7 @@ const getPathToChange = (documentBlueprint, formNode, event) => {
|
|
|
810
547
|
return accum.join(".");
|
|
811
548
|
};
|
|
812
549
|
const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
813
|
-
const { createForm, createGlobalForm } =
|
|
550
|
+
const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
|
|
814
551
|
const SKIPPED = "SKIPPED";
|
|
815
552
|
let form;
|
|
816
553
|
let skipped;
|
|
@@ -820,25 +557,50 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
|
820
557
|
if (skipped)
|
|
821
558
|
return;
|
|
822
559
|
const id = doc._internalSys.path;
|
|
560
|
+
const enrichedSchema = cms.api.tina.schema;
|
|
561
|
+
const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
|
|
562
|
+
const template = enrichedSchema.getTemplateForData({
|
|
563
|
+
collection,
|
|
564
|
+
data: doc._values
|
|
565
|
+
});
|
|
823
566
|
const formCommon = {
|
|
824
567
|
id,
|
|
825
|
-
label:
|
|
826
|
-
initialValues: doc.
|
|
568
|
+
label: id,
|
|
569
|
+
initialValues: doc._values,
|
|
827
570
|
onSubmit: async (payload) => {
|
|
828
571
|
try {
|
|
829
|
-
const params = transformDocumentIntoMutationRequestPayload(payload,
|
|
572
|
+
const params = transformDocumentIntoMutationRequestPayload(payload, {
|
|
573
|
+
includeCollection: false,
|
|
574
|
+
includeTemplate: !!collection.templates
|
|
575
|
+
});
|
|
830
576
|
const variables = { params };
|
|
831
|
-
const mutationString =
|
|
577
|
+
const mutationString = `#graphql
|
|
578
|
+
mutation UpdateDocument($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
579
|
+
updateDocument(collection: $collection, relativePath: $relativePath, params: $params) {
|
|
580
|
+
__typename
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
`;
|
|
832
584
|
if (onSubmit) {
|
|
833
585
|
onSubmit({
|
|
834
586
|
queryString: mutationString,
|
|
835
587
|
mutationString,
|
|
836
|
-
variables
|
|
588
|
+
variables: {
|
|
589
|
+
collection: doc._internalSys.collection.name,
|
|
590
|
+
relativePath: doc._internalSys.relativePath,
|
|
591
|
+
params: { [doc._internalSys.collection.name]: variables }
|
|
592
|
+
}
|
|
837
593
|
});
|
|
838
594
|
} else {
|
|
839
595
|
try {
|
|
840
596
|
await cms.api.tina.request(mutationString, {
|
|
841
|
-
variables
|
|
597
|
+
variables: {
|
|
598
|
+
collection: doc._internalSys.collection.name,
|
|
599
|
+
relativePath: doc._internalSys.relativePath,
|
|
600
|
+
params: {
|
|
601
|
+
[doc._internalSys.collection.name]: variables.params
|
|
602
|
+
}
|
|
603
|
+
}
|
|
842
604
|
});
|
|
843
605
|
cms.alerts.success("Document saved!");
|
|
844
606
|
} catch (e) {
|
|
@@ -853,29 +615,16 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
|
853
615
|
}
|
|
854
616
|
};
|
|
855
617
|
let formConfig = {};
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
schema: enrichedSchema,
|
|
867
|
-
template
|
|
868
|
-
});
|
|
869
|
-
formConfig = __spreadValues({
|
|
870
|
-
label: formInfo.label,
|
|
871
|
-
fields: formInfo.fields
|
|
872
|
-
}, formCommon);
|
|
873
|
-
} else {
|
|
874
|
-
formConfig = __spreadValues({
|
|
875
|
-
label: doc.form.label,
|
|
876
|
-
fields: doc.form.fields
|
|
877
|
-
}, formCommon);
|
|
878
|
-
}
|
|
618
|
+
const formInfo = resolveForm({
|
|
619
|
+
collection,
|
|
620
|
+
basename: collection.name,
|
|
621
|
+
schema: enrichedSchema,
|
|
622
|
+
template
|
|
623
|
+
});
|
|
624
|
+
formConfig = __spreadValues({
|
|
625
|
+
label: formInfo.label,
|
|
626
|
+
fields: formInfo.fields
|
|
627
|
+
}, formCommon);
|
|
879
628
|
if (formify2) {
|
|
880
629
|
form = formify2({
|
|
881
630
|
formConfig,
|
|
@@ -994,7 +743,7 @@ const getEventPath = (event, blueprint) => {
|
|
|
994
743
|
}
|
|
995
744
|
return `[]`;
|
|
996
745
|
}).join(".");
|
|
997
|
-
const items = [blueprint.id,
|
|
746
|
+
const items = [blueprint.id, eventPath];
|
|
998
747
|
const isList = event.field.data.tinaField.list;
|
|
999
748
|
if (isList && !eventPath.endsWith("[]")) {
|
|
1000
749
|
items.push(`[]`);
|
|
@@ -1029,14 +778,13 @@ const getMatchName = ({ field, prefix, blueprint }) => {
|
|
|
1029
778
|
if (prefix) {
|
|
1030
779
|
extra.push(prefix);
|
|
1031
780
|
}
|
|
1032
|
-
const matchName = [blueprintName,
|
|
781
|
+
const matchName = [blueprintName, ...extra, fieldName].join(".");
|
|
1033
782
|
return { matchName, fieldName };
|
|
1034
783
|
};
|
|
1035
784
|
const getFormNodesFromEvent = (state, event) => {
|
|
1036
785
|
const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
|
|
1037
786
|
return formNodes;
|
|
1038
787
|
};
|
|
1039
|
-
const DATA_NODE_NAME$1 = "data";
|
|
1040
788
|
const printEvent = (event) => {
|
|
1041
789
|
var _a, _b;
|
|
1042
790
|
return {
|
|
@@ -1242,14 +990,14 @@ function buildPath({
|
|
|
1242
990
|
}
|
|
1243
991
|
const node = G.parse(`
|
|
1244
992
|
query Sample {
|
|
1245
|
-
_internalSys:
|
|
993
|
+
_internalSys: _sys {
|
|
1246
994
|
path
|
|
995
|
+
relativePath
|
|
1247
996
|
collection {
|
|
1248
997
|
name
|
|
1249
998
|
}
|
|
1250
999
|
}
|
|
1251
|
-
|
|
1252
|
-
values
|
|
1000
|
+
_values
|
|
1253
1001
|
}`);
|
|
1254
1002
|
const metaFields = node.definitions[0].selectionSet.selections;
|
|
1255
1003
|
const getRelativeBlueprint = (path) => {
|
|
@@ -1266,6 +1014,21 @@ const getRelativeBlueprint = (path) => {
|
|
|
1266
1014
|
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
|
|
1267
1015
|
return getBlueprintNamePath({ path: documentBlueprintPath });
|
|
1268
1016
|
};
|
|
1017
|
+
const isSysField = (fieldNode) => {
|
|
1018
|
+
if (fieldNode.name.value === "__typename") {
|
|
1019
|
+
return true;
|
|
1020
|
+
}
|
|
1021
|
+
if (fieldNode.name.value === "_sys") {
|
|
1022
|
+
return true;
|
|
1023
|
+
}
|
|
1024
|
+
if (fieldNode.name.value === "_values") {
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
if (fieldNode.name.value === "id") {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
return false;
|
|
1031
|
+
};
|
|
1269
1032
|
const getBlueprintId = (path) => {
|
|
1270
1033
|
const namePath = [];
|
|
1271
1034
|
const aliasPath = [];
|
|
@@ -1283,10 +1046,9 @@ const NOOP = "This is either an error or is not yet supported";
|
|
|
1283
1046
|
const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
|
|
1284
1047
|
const EDGES_NODE_NAME = "edges";
|
|
1285
1048
|
const NODE_NAME = "node";
|
|
1286
|
-
const COLLECTION_FIELD_NAME = "
|
|
1287
|
-
const COLLECTIONS_FIELD_NAME = "
|
|
1049
|
+
const COLLECTION_FIELD_NAME = "collection";
|
|
1050
|
+
const COLLECTIONS_FIELD_NAME = "collections";
|
|
1288
1051
|
const COLLECTIONS_DOCUMENTS_NAME = "documents";
|
|
1289
|
-
const DATA_NODE_NAME = "data";
|
|
1290
1052
|
const formify = async ({
|
|
1291
1053
|
schema,
|
|
1292
1054
|
query,
|
|
@@ -1392,22 +1154,15 @@ const formify = async ({
|
|
|
1392
1154
|
showInSidebar = false
|
|
1393
1155
|
}) {
|
|
1394
1156
|
let extraFields = [];
|
|
1395
|
-
|
|
1157
|
+
const hasDataJSONField = false;
|
|
1396
1158
|
let hasValuesField = false;
|
|
1397
1159
|
let shouldFormify = false;
|
|
1398
1160
|
selection.selectionSet.selections.forEach((selection2) => {
|
|
1399
1161
|
if (selection2.kind === "Field") {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
hasDataJSONField = true;
|
|
1403
|
-
}
|
|
1404
|
-
if (selection2.name.value === "values") {
|
|
1405
|
-
shouldFormify = true;
|
|
1162
|
+
shouldFormify = true;
|
|
1163
|
+
if (selection2.name.value === "_values") {
|
|
1406
1164
|
hasValuesField = true;
|
|
1407
1165
|
}
|
|
1408
|
-
if (selection2.name.value === "data") {
|
|
1409
|
-
shouldFormify = true;
|
|
1410
|
-
}
|
|
1411
1166
|
}
|
|
1412
1167
|
});
|
|
1413
1168
|
if (shouldFormify) {
|
|
@@ -1446,33 +1201,11 @@ const formify = async ({
|
|
|
1446
1201
|
});
|
|
1447
1202
|
}
|
|
1448
1203
|
case "Field": {
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
selections: [
|
|
1455
|
-
...selectionNode.selectionSet.selections.map((subSelectionNode) => {
|
|
1456
|
-
switch (subSelectionNode.kind) {
|
|
1457
|
-
case "Field":
|
|
1458
|
-
return formifyFieldNode({
|
|
1459
|
-
fieldNode: subSelectionNode,
|
|
1460
|
-
parentType: field.type,
|
|
1461
|
-
path: buildPath({
|
|
1462
|
-
fieldNode: selectionNode,
|
|
1463
|
-
type: field.type,
|
|
1464
|
-
path
|
|
1465
|
-
})
|
|
1466
|
-
});
|
|
1467
|
-
default:
|
|
1468
|
-
throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
|
|
1469
|
-
}
|
|
1470
|
-
})
|
|
1471
|
-
]
|
|
1472
|
-
}
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
return selectionNode;
|
|
1204
|
+
return formifyFieldNode({
|
|
1205
|
+
fieldNode: selectionNode,
|
|
1206
|
+
parentType: type,
|
|
1207
|
+
path
|
|
1208
|
+
});
|
|
1476
1209
|
}
|
|
1477
1210
|
default:
|
|
1478
1211
|
throw new FormifyError("UNEXPECTED");
|
|
@@ -1495,16 +1228,19 @@ const formify = async ({
|
|
|
1495
1228
|
if (!field) {
|
|
1496
1229
|
return fieldNode;
|
|
1497
1230
|
}
|
|
1498
|
-
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
|
|
1499
|
-
if (!blueprint) {
|
|
1500
|
-
return fieldNode;
|
|
1501
|
-
}
|
|
1502
1231
|
const fieldPath = buildPath({
|
|
1503
1232
|
fieldNode,
|
|
1504
1233
|
type: field.type,
|
|
1505
1234
|
parentTypename: G.getNamedType(parentType).name,
|
|
1506
1235
|
path
|
|
1507
1236
|
});
|
|
1237
|
+
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(fieldPath));
|
|
1238
|
+
if (!blueprint) {
|
|
1239
|
+
return fieldNode;
|
|
1240
|
+
}
|
|
1241
|
+
if (isSysField(fieldNode)) {
|
|
1242
|
+
return fieldNode;
|
|
1243
|
+
}
|
|
1508
1244
|
blueprint.fields.push({
|
|
1509
1245
|
id: getBlueprintId(fieldPath),
|
|
1510
1246
|
documentBlueprintId: blueprint.id,
|
|
@@ -2050,10 +1786,10 @@ const useFormify = ({
|
|
|
2050
1786
|
query Node($id: String!) {
|
|
2051
1787
|
node(id: $id) {
|
|
2052
1788
|
...on Document {
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
_internalSys: sys {
|
|
1789
|
+
_values
|
|
1790
|
+
_internalSys: _sys {
|
|
2056
1791
|
path
|
|
1792
|
+
relativePath
|
|
2057
1793
|
collection {
|
|
2058
1794
|
name
|
|
2059
1795
|
}
|
|
@@ -2163,9 +1899,7 @@ const useFormify = ({
|
|
|
2163
1899
|
dispatch({
|
|
2164
1900
|
type: "setIn",
|
|
2165
1901
|
value: __spreadProps(__spreadValues({}, changeSet), {
|
|
2166
|
-
value:
|
|
2167
|
-
data
|
|
2168
|
-
})
|
|
1902
|
+
value: __spreadValues(__spreadValues({}, res.node), data)
|
|
2169
1903
|
})
|
|
2170
1904
|
});
|
|
2171
1905
|
}).catch((e) => {
|
|
@@ -2284,10 +2018,10 @@ const useFormify = ({
|
|
|
2284
2018
|
query Node($id: String!) {
|
|
2285
2019
|
node(id: $id) {
|
|
2286
2020
|
...on Document {
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
_internalSys: sys {
|
|
2021
|
+
_values
|
|
2022
|
+
_internalSys: _sys {
|
|
2290
2023
|
path
|
|
2024
|
+
relativePath
|
|
2291
2025
|
collection {
|
|
2292
2026
|
name
|
|
2293
2027
|
}
|
|
@@ -2325,13 +2059,11 @@ const useFormify = ({
|
|
|
2325
2059
|
}
|
|
2326
2060
|
}
|
|
2327
2061
|
`, { variables: { id: value } });
|
|
2328
|
-
data[keyName] =
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
})
|
|
2334
|
-
});
|
|
2062
|
+
data[keyName] = __spreadValues(__spreadValues({}, res.node), await resolveSubFields({
|
|
2063
|
+
formNode: subDocumentFormNode,
|
|
2064
|
+
form: form2,
|
|
2065
|
+
loc: location
|
|
2066
|
+
}));
|
|
2335
2067
|
});
|
|
2336
2068
|
break;
|
|
2337
2069
|
default:
|
|
@@ -2692,19 +2424,19 @@ const useTinaAuthRedirect = () => {
|
|
|
2692
2424
|
class TinaAdminApi {
|
|
2693
2425
|
constructor(cms) {
|
|
2694
2426
|
this.api = cms.api.tina;
|
|
2427
|
+
this.schema = cms.api.tina.schema;
|
|
2695
2428
|
}
|
|
2696
2429
|
async isAuthenticated() {
|
|
2697
2430
|
return await this.api.isAuthenticated();
|
|
2698
2431
|
}
|
|
2699
2432
|
async fetchCollections() {
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
return response;
|
|
2433
|
+
try {
|
|
2434
|
+
const collections = this.schema.getCollections();
|
|
2435
|
+
return collections;
|
|
2436
|
+
} catch (e) {
|
|
2437
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
|
|
2438
|
+
return [];
|
|
2439
|
+
}
|
|
2708
2440
|
}
|
|
2709
2441
|
async deleteDocument({
|
|
2710
2442
|
collection,
|
|
@@ -2718,9 +2450,10 @@ class TinaAdminApi {
|
|
|
2718
2450
|
}`, { variables: { collection, relativePath } });
|
|
2719
2451
|
}
|
|
2720
2452
|
async fetchCollection(collectionName, includeDocuments) {
|
|
2721
|
-
|
|
2453
|
+
if (includeDocuments === true) {
|
|
2454
|
+
const response = await this.api.request(`#graphql
|
|
2722
2455
|
query($collection: String!, $includeDocuments: Boolean!){
|
|
2723
|
-
|
|
2456
|
+
collection(collection: $collection){
|
|
2724
2457
|
name
|
|
2725
2458
|
label
|
|
2726
2459
|
format
|
|
@@ -2730,7 +2463,7 @@ class TinaAdminApi {
|
|
|
2730
2463
|
edges {
|
|
2731
2464
|
node {
|
|
2732
2465
|
... on Document {
|
|
2733
|
-
|
|
2466
|
+
_sys {
|
|
2734
2467
|
template
|
|
2735
2468
|
breadcrumbs
|
|
2736
2469
|
path
|
|
@@ -2745,27 +2478,28 @@ class TinaAdminApi {
|
|
|
2745
2478
|
}
|
|
2746
2479
|
}
|
|
2747
2480
|
}`, { variables: { collection: collectionName, includeDocuments } });
|
|
2748
|
-
|
|
2481
|
+
return response.collection;
|
|
2482
|
+
} else {
|
|
2483
|
+
try {
|
|
2484
|
+
const collection = this.schema.getCollection(collectionName);
|
|
2485
|
+
return collection;
|
|
2486
|
+
} catch (e) {
|
|
2487
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollection(): ${e.message}`);
|
|
2488
|
+
return void 0;
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2749
2491
|
}
|
|
2750
2492
|
async fetchDocument(collectionName, relativePath) {
|
|
2751
2493
|
const response = await this.api.request(`#graphql
|
|
2752
2494
|
query($collection: String!, $relativePath: String!) {
|
|
2753
|
-
|
|
2495
|
+
document(collection:$collection, relativePath:$relativePath) {
|
|
2754
2496
|
... on Document {
|
|
2755
|
-
|
|
2756
|
-
values
|
|
2497
|
+
_values
|
|
2757
2498
|
}
|
|
2758
2499
|
}
|
|
2759
2500
|
}`, { variables: { collection: collectionName, relativePath } });
|
|
2760
2501
|
return response;
|
|
2761
2502
|
}
|
|
2762
|
-
async fetchDocumentFields() {
|
|
2763
|
-
const response = await this.api.request(`#graphql
|
|
2764
|
-
query {
|
|
2765
|
-
getDocumentFields
|
|
2766
|
-
}`, { variables: {} });
|
|
2767
|
-
return response;
|
|
2768
|
-
}
|
|
2769
2503
|
async createDocument(collectionName, relativePath, params) {
|
|
2770
2504
|
const response = await this.api.request(`#graphql
|
|
2771
2505
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
@@ -2786,7 +2520,7 @@ class TinaAdminApi {
|
|
|
2786
2520
|
async updateDocument(collectionName, relativePath, params) {
|
|
2787
2521
|
const response = await this.api.request(`#graphql
|
|
2788
2522
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2789
|
-
updateDocument(
|
|
2523
|
+
updateDocument(
|
|
2790
2524
|
collection: $collection,
|
|
2791
2525
|
relativePath: $relativePath,
|
|
2792
2526
|
params: $params
|
|
@@ -2977,7 +2711,7 @@ class ContentCreatorPlugin {
|
|
|
2977
2711
|
} else {
|
|
2978
2712
|
cms.alerts.info("Document created!");
|
|
2979
2713
|
if (typeof this.onNewDocument === "function") {
|
|
2980
|
-
this.onNewDocument(res.addPendingDocument.
|
|
2714
|
+
this.onNewDocument(res.addPendingDocument._sys);
|
|
2981
2715
|
}
|
|
2982
2716
|
}
|
|
2983
2717
|
} catch (e) {
|
|
@@ -2997,7 +2731,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
2997
2731
|
var _a;
|
|
2998
2732
|
const res = await cms.api.tina.request((gql2) => gql2`
|
|
2999
2733
|
{
|
|
3000
|
-
|
|
2734
|
+
collections {
|
|
3001
2735
|
label
|
|
3002
2736
|
slug
|
|
3003
2737
|
format
|
|
@@ -3006,7 +2740,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3006
2740
|
}
|
|
3007
2741
|
`, { variables: {} });
|
|
3008
2742
|
const allCollectionOptions = [];
|
|
3009
|
-
res.
|
|
2743
|
+
res.collections.forEach((collection) => {
|
|
3010
2744
|
const value = collection.slug;
|
|
3011
2745
|
const label = `${collection.label}`;
|
|
3012
2746
|
allCollectionOptions.push({ value, label });
|
|
@@ -3028,7 +2762,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3028
2762
|
{ value: "", label: "Choose Template" }
|
|
3029
2763
|
];
|
|
3030
2764
|
if (values.collection) {
|
|
3031
|
-
const filteredCollection = res.
|
|
2765
|
+
const filteredCollection = res.collections.find((c) => c.slug === values.collection);
|
|
3032
2766
|
(_a = filteredCollection == null ? void 0 : filteredCollection.templates) == null ? void 0 : _a.forEach((template) => {
|
|
3033
2767
|
templateOptions.push({ value: template.name, label: template.label });
|
|
3034
2768
|
});
|
|
@@ -3036,7 +2770,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3036
2770
|
setPlugin(new ContentCreatorPlugin({
|
|
3037
2771
|
label: "Add Document",
|
|
3038
2772
|
onNewDocument: args && args.onNewDocument,
|
|
3039
|
-
collections: res.
|
|
2773
|
+
collections: res.collections,
|
|
3040
2774
|
onChange: async ({ values: values2 }) => {
|
|
3041
2775
|
setValues(values2);
|
|
3042
2776
|
},
|
|
@@ -3257,6 +2991,9 @@ const TinaCMSProvider2 = (_c) => {
|
|
|
3257
2991
|
clientId: props.clientId,
|
|
3258
2992
|
isLocalClient: props.isLocalClient
|
|
3259
2993
|
};
|
|
2994
|
+
if (!schema) {
|
|
2995
|
+
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");
|
|
2996
|
+
}
|
|
3260
2997
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TinaCloudProvider, {
|
|
3261
2998
|
branch,
|
|
3262
2999
|
clientId,
|
|
@@ -3306,25 +3043,13 @@ const TinaDataProvider = ({
|
|
|
3306
3043
|
payload: void 0,
|
|
3307
3044
|
isLoading: true
|
|
3308
3045
|
});
|
|
3309
|
-
const cms = useCMS();
|
|
3310
|
-
const useUnstableFormify = React.useMemo(() => {
|
|
3311
|
-
if ((cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false) {
|
|
3312
|
-
return false;
|
|
3313
|
-
}
|
|
3314
|
-
return true;
|
|
3315
|
-
}, [cms == null ? void 0 : cms.flags]);
|
|
3316
3046
|
return /* @__PURE__ */ React.createElement(TinaDataContext.Provider, {
|
|
3317
3047
|
value: {
|
|
3318
3048
|
setRequest,
|
|
3319
3049
|
isLoading: state.isLoading,
|
|
3320
3050
|
state: { payload: state.payload }
|
|
3321
3051
|
}
|
|
3322
|
-
},
|
|
3323
|
-
key: request == null ? void 0 : request.query,
|
|
3324
|
-
request,
|
|
3325
|
-
formifyCallback,
|
|
3326
|
-
onPayloadStateChange: setState
|
|
3327
|
-
}) : /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3052
|
+
}, /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3328
3053
|
key: request == null ? void 0 : request.query,
|
|
3329
3054
|
request,
|
|
3330
3055
|
formifyCallback,
|
|
@@ -3353,35 +3078,6 @@ const FormRegistrar = ({
|
|
|
3353
3078
|
}, [JSON.stringify(payload), isLoading]);
|
|
3354
3079
|
return isLoading ? /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement(React.Fragment, null)) : null;
|
|
3355
3080
|
};
|
|
3356
|
-
const FormRegistrarUnstable = (props) => {
|
|
3357
|
-
var _a;
|
|
3358
|
-
if (!((_a = props.request) == null ? void 0 : _a.query)) {
|
|
3359
|
-
return null;
|
|
3360
|
-
}
|
|
3361
|
-
return /* @__PURE__ */ React.createElement(FormRegistrarUnstableInner, __spreadValues({}, props));
|
|
3362
|
-
};
|
|
3363
|
-
const FormRegistrarUnstableInner = ({
|
|
3364
|
-
request,
|
|
3365
|
-
formifyCallback,
|
|
3366
|
-
onPayloadStateChange
|
|
3367
|
-
}) => {
|
|
3368
|
-
const cms = useCMS();
|
|
3369
|
-
const [payload, isLoading] = useGraphqlFormsUnstable({
|
|
3370
|
-
query: request == null ? void 0 : request.query,
|
|
3371
|
-
variables: request == null ? void 0 : request.variables,
|
|
3372
|
-
formify: (args) => {
|
|
3373
|
-
if (formifyCallback) {
|
|
3374
|
-
return formifyCallback(args, cms);
|
|
3375
|
-
} else {
|
|
3376
|
-
return args.createForm(args.formConfig);
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
});
|
|
3380
|
-
React.useEffect(() => {
|
|
3381
|
-
onPayloadStateChange({ payload, isLoading });
|
|
3382
|
-
}, [JSON.stringify(payload), isLoading]);
|
|
3383
|
-
return isLoading ? /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement(React.Fragment, null)) : null;
|
|
3384
|
-
};
|
|
3385
3081
|
const Loader = (props) => {
|
|
3386
3082
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
3387
3083
|
style: {
|
|
@@ -3626,8 +3322,8 @@ const useGetCollections = (cms) => {
|
|
|
3626
3322
|
const fetchCollections = async () => {
|
|
3627
3323
|
if (await api.isAuthenticated()) {
|
|
3628
3324
|
try {
|
|
3629
|
-
const
|
|
3630
|
-
setCollections(
|
|
3325
|
+
const collections2 = await api.fetchCollections();
|
|
3326
|
+
setCollections(collections2);
|
|
3631
3327
|
} catch (error2) {
|
|
3632
3328
|
console.error(error2);
|
|
3633
3329
|
setCollections([]);
|
|
@@ -3930,8 +3626,8 @@ const useGetCollection = (cms, collectionName, includeDocuments = true) => {
|
|
|
3930
3626
|
const fetchCollection = async () => {
|
|
3931
3627
|
if (await api.isAuthenticated()) {
|
|
3932
3628
|
try {
|
|
3933
|
-
const
|
|
3934
|
-
setCollection(
|
|
3629
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments);
|
|
3630
|
+
setCollection(collection2);
|
|
3935
3631
|
} catch (error2) {
|
|
3936
3632
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
3937
3633
|
console.error(error2);
|
|
@@ -3997,7 +3693,7 @@ const handleNavigate = (navigate, cms, collection, document) => {
|
|
|
3997
3693
|
window.location.href = routeOverride;
|
|
3998
3694
|
return null;
|
|
3999
3695
|
} else {
|
|
4000
|
-
navigate(document.
|
|
3696
|
+
navigate(document._sys.breadcrumbs.join("/"));
|
|
4001
3697
|
}
|
|
4002
3698
|
};
|
|
4003
3699
|
const CollectionListPage = () => {
|
|
@@ -4050,9 +3746,9 @@ const CollectionListPage = () => {
|
|
|
4050
3746
|
}, /* @__PURE__ */ React.createElement("tbody", {
|
|
4051
3747
|
className: "divide-y divide-gray-150"
|
|
4052
3748
|
}, documents.map((document) => {
|
|
4053
|
-
const subfolders = document.node.
|
|
3749
|
+
const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
|
|
4054
3750
|
return /* @__PURE__ */ React.createElement("tr", {
|
|
4055
|
-
key: `document-${document.node.
|
|
3751
|
+
key: `document-${document.node._sys.relativePath}`,
|
|
4056
3752
|
className: ""
|
|
4057
3753
|
}, /* @__PURE__ */ React.createElement("td", {
|
|
4058
3754
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -4069,19 +3765,19 @@ const CollectionListPage = () => {
|
|
|
4069
3765
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
4070
3766
|
}, subfolders && /* @__PURE__ */ React.createElement("span", {
|
|
4071
3767
|
className: "text-xs text-gray-400"
|
|
4072
|
-
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node.
|
|
3768
|
+
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React.createElement("td", {
|
|
4073
3769
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4074
3770
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4075
3771
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4076
3772
|
}, "Extension"), /* @__PURE__ */ React.createElement("span", {
|
|
4077
3773
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4078
|
-
}, document.node.
|
|
3774
|
+
}, document.node._sys.extension)), /* @__PURE__ */ React.createElement("td", {
|
|
4079
3775
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4080
3776
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4081
3777
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4082
3778
|
}, "Template"), /* @__PURE__ */ React.createElement("span", {
|
|
4083
3779
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4084
|
-
}, document.node.
|
|
3780
|
+
}, document.node._sys.template)), /* @__PURE__ */ React.createElement("td", {
|
|
4085
3781
|
className: "w-0"
|
|
4086
3782
|
}, /* @__PURE__ */ React.createElement(OverflowMenu, {
|
|
4087
3783
|
showEmbed: true,
|
|
@@ -4093,7 +3789,7 @@ const CollectionListPage = () => {
|
|
|
4093
3789
|
size: "1.3rem"
|
|
4094
3790
|
}),
|
|
4095
3791
|
onMouseDown: () => {
|
|
4096
|
-
navigate(`${document.node.
|
|
3792
|
+
navigate(`${document.node._sys.filename}`, { replace: true });
|
|
4097
3793
|
}
|
|
4098
3794
|
},
|
|
4099
3795
|
{
|
|
@@ -4106,7 +3802,7 @@ const CollectionListPage = () => {
|
|
|
4106
3802
|
onMouseDown: () => {
|
|
4107
3803
|
setVars({
|
|
4108
3804
|
collection: collectionName,
|
|
4109
|
-
relativePath: document.node.
|
|
3805
|
+
relativePath: document.node._sys.filename + document.node._sys.extension
|
|
4110
3806
|
});
|
|
4111
3807
|
setOpen(true);
|
|
4112
3808
|
}
|
|
@@ -4134,72 +3830,6 @@ const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
|
4134
3830
|
}
|
|
4135
3831
|
}, "Delete"))));
|
|
4136
3832
|
};
|
|
4137
|
-
const useGetDocumentFields = (cms, collectionName, templateName) => {
|
|
4138
|
-
const api = new TinaAdminApi(cms);
|
|
4139
|
-
const [info, setInfo] = useState({
|
|
4140
|
-
collection: void 0,
|
|
4141
|
-
template: void 0,
|
|
4142
|
-
fields: void 0,
|
|
4143
|
-
mutationInfo: void 0
|
|
4144
|
-
});
|
|
4145
|
-
const [loading, setLoading] = useState(true);
|
|
4146
|
-
const [error, setError] = useState(void 0);
|
|
4147
|
-
useEffect(() => {
|
|
4148
|
-
const fetchDocumentFields = async () => {
|
|
4149
|
-
if (await api.isAuthenticated()) {
|
|
4150
|
-
try {
|
|
4151
|
-
const response = await api.fetchDocumentFields();
|
|
4152
|
-
const documentFields = response.getDocumentFields;
|
|
4153
|
-
const collection = documentFields[collectionName].collection;
|
|
4154
|
-
const mutationInfo = documentFields[collectionName].mutationInfo;
|
|
4155
|
-
let fields = void 0;
|
|
4156
|
-
let template = void 0;
|
|
4157
|
-
if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
|
|
4158
|
-
template = documentFields[collectionName].templates[templateName].template;
|
|
4159
|
-
fields = documentFields[collectionName].templates[templateName].fields;
|
|
4160
|
-
} else {
|
|
4161
|
-
fields = documentFields[collectionName].fields;
|
|
4162
|
-
}
|
|
4163
|
-
setInfo({
|
|
4164
|
-
collection,
|
|
4165
|
-
template,
|
|
4166
|
-
fields,
|
|
4167
|
-
mutationInfo
|
|
4168
|
-
});
|
|
4169
|
-
} catch (error2) {
|
|
4170
|
-
cms.alerts.error(`[${error2.name}] GetDocumentFields failed: ${error2.message}`, 30 * 1e3);
|
|
4171
|
-
console.error(error2);
|
|
4172
|
-
setInfo({
|
|
4173
|
-
collection: void 0,
|
|
4174
|
-
template: void 0,
|
|
4175
|
-
fields: void 0,
|
|
4176
|
-
mutationInfo: void 0
|
|
4177
|
-
});
|
|
4178
|
-
setError(error2);
|
|
4179
|
-
}
|
|
4180
|
-
setLoading(false);
|
|
4181
|
-
}
|
|
4182
|
-
};
|
|
4183
|
-
setLoading(true);
|
|
4184
|
-
fetchDocumentFields();
|
|
4185
|
-
}, [cms, collectionName]);
|
|
4186
|
-
return __spreadProps(__spreadValues({}, info), { loading, error });
|
|
4187
|
-
};
|
|
4188
|
-
const GetDocumentFields = ({
|
|
4189
|
-
cms,
|
|
4190
|
-
collectionName,
|
|
4191
|
-
templateName,
|
|
4192
|
-
children
|
|
4193
|
-
}) => {
|
|
4194
|
-
const { collection, template, fields, mutationInfo, loading, error } = useGetDocumentFields(cms, collectionName, templateName);
|
|
4195
|
-
if (error) {
|
|
4196
|
-
return null;
|
|
4197
|
-
}
|
|
4198
|
-
if (loading) {
|
|
4199
|
-
return /* @__PURE__ */ React.createElement(LoadingPage, null);
|
|
4200
|
-
}
|
|
4201
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, children({ collection, template, fields, mutationInfo, loading }));
|
|
4202
|
-
};
|
|
4203
3833
|
function HiChevronRight(props) {
|
|
4204
3834
|
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);
|
|
4205
3835
|
}
|
|
@@ -4225,34 +3855,39 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
|
|
|
4225
3855
|
};
|
|
4226
3856
|
const CollectionCreatePage = () => {
|
|
4227
3857
|
const { collectionName, templateName } = useParams();
|
|
4228
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
3858
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4229
3859
|
cms,
|
|
4230
3860
|
collectionName,
|
|
4231
|
-
|
|
4232
|
-
}, (
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
3861
|
+
includeDocuments: false
|
|
3862
|
+
}, (collection) => {
|
|
3863
|
+
const mutationInfo = {
|
|
3864
|
+
includeCollection: true,
|
|
3865
|
+
includeTemplate: !!collection.templates
|
|
3866
|
+
};
|
|
3867
|
+
return /* @__PURE__ */ React.createElement(RenderForm$1, {
|
|
3868
|
+
cms,
|
|
3869
|
+
collection,
|
|
3870
|
+
templateName,
|
|
3871
|
+
mutationInfo
|
|
3872
|
+
});
|
|
3873
|
+
}));
|
|
4239
3874
|
};
|
|
4240
|
-
const RenderForm$1 = ({ cms, collection,
|
|
3875
|
+
const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
|
|
4241
3876
|
var _a, _b;
|
|
4242
3877
|
const navigate = useNavigate();
|
|
4243
3878
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4244
3879
|
const schema = cms.api.tina.schema;
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
}
|
|
3880
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
3881
|
+
const template = schema.getTemplateForData({
|
|
3882
|
+
collection: schemaCollection,
|
|
3883
|
+
data: { _template: templateName }
|
|
3884
|
+
});
|
|
3885
|
+
const formInfo = resolveForm({
|
|
3886
|
+
collection: schemaCollection,
|
|
3887
|
+
basename: schemaCollection.name,
|
|
3888
|
+
schema,
|
|
3889
|
+
template
|
|
3890
|
+
});
|
|
4256
3891
|
const form = useMemo(() => {
|
|
4257
3892
|
return new Form({
|
|
4258
3893
|
id: "create-form",
|
|
@@ -4277,7 +3912,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4277
3912
|
}
|
|
4278
3913
|
}
|
|
4279
3914
|
},
|
|
4280
|
-
...
|
|
3915
|
+
...formInfo.fields
|
|
4281
3916
|
],
|
|
4282
3917
|
onSubmit: async (values) => {
|
|
4283
3918
|
try {
|
|
@@ -4290,7 +3925,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4290
3925
|
}
|
|
4291
3926
|
}
|
|
4292
3927
|
});
|
|
4293
|
-
}, [cms, collection,
|
|
3928
|
+
}, [cms, collection, mutationInfo]);
|
|
4294
3929
|
return /* @__PURE__ */ React.createElement(PageWrapper, null, /* @__PURE__ */ React.createElement(React.Fragment, null, ((_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.isLocalMode) && /* @__PURE__ */ React.createElement(LocalWarning, null), /* @__PURE__ */ React.createElement("div", {
|
|
4295
3930
|
className: "py-4 px-20 border-b border-gray-200 bg-white"
|
|
4296
3931
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
@@ -4323,7 +3958,7 @@ const useGetDocument = (cms, collectionName, relativePath) => {
|
|
|
4323
3958
|
if (api.isAuthenticated()) {
|
|
4324
3959
|
try {
|
|
4325
3960
|
const response = await api.fetchDocument(collectionName, relativePath);
|
|
4326
|
-
setDocument(response.
|
|
3961
|
+
setDocument(response.document);
|
|
4327
3962
|
} catch (error2) {
|
|
4328
3963
|
cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
|
|
4329
3964
|
console.error(error2);
|
|
@@ -4372,11 +4007,16 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
|
|
|
4372
4007
|
const CollectionUpdatePage = () => {
|
|
4373
4008
|
const _a = useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4374
4009
|
const { "*": filename } = rest;
|
|
4375
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
4010
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4376
4011
|
cms,
|
|
4377
|
-
collectionName
|
|
4378
|
-
|
|
4012
|
+
collectionName,
|
|
4013
|
+
includeDocuments: false
|
|
4014
|
+
}, (collection) => {
|
|
4379
4015
|
const relativePath = `${filename}.${collection.format}`;
|
|
4016
|
+
const mutationInfo = {
|
|
4017
|
+
includeCollection: true,
|
|
4018
|
+
includeTemplate: !!collection.templates
|
|
4019
|
+
};
|
|
4380
4020
|
return /* @__PURE__ */ React.createElement(GetDocument, {
|
|
4381
4021
|
cms,
|
|
4382
4022
|
collectionName: collection.name,
|
|
@@ -4402,27 +4042,23 @@ const RenderForm = ({
|
|
|
4402
4042
|
var _a, _b;
|
|
4403
4043
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4404
4044
|
const schema = cms.api.tina.schema;
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
template
|
|
4417
|
-
});
|
|
4418
|
-
schemaFields = formInfo.fields;
|
|
4419
|
-
}
|
|
4045
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
4046
|
+
const template = schema.getTemplateForData({
|
|
4047
|
+
collection: schemaCollection,
|
|
4048
|
+
data: document._values
|
|
4049
|
+
});
|
|
4050
|
+
const formInfo = resolveForm({
|
|
4051
|
+
collection: schemaCollection,
|
|
4052
|
+
basename: schemaCollection.name,
|
|
4053
|
+
schema,
|
|
4054
|
+
template
|
|
4055
|
+
});
|
|
4420
4056
|
const form = useMemo(() => {
|
|
4421
4057
|
return new Form({
|
|
4422
4058
|
id: "update-form",
|
|
4423
4059
|
label: "form",
|
|
4424
|
-
fields:
|
|
4425
|
-
initialValues: document.
|
|
4060
|
+
fields: formInfo.fields,
|
|
4061
|
+
initialValues: document._values,
|
|
4426
4062
|
onSubmit: async (values) => {
|
|
4427
4063
|
try {
|
|
4428
4064
|
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
@@ -4542,4 +4178,4 @@ const defineSchema = (config) => {
|
|
|
4542
4178
|
const defineConfig = (config) => {
|
|
4543
4179
|
return config;
|
|
4544
4180
|
};
|
|
4545
|
-
export { AuthWallInner, Client, DEFAULT_LOCAL_TINA_GQL_SERVER_URL, LocalClient, RouteMappingPlugin, TinaAdmin, TinaAdminApi, TinaCMSProvider2, TinaCloudAuthWall, TinaCloudProvider, TinaDataProvider, assertShape, createClient, TinaCMSProvider2 as default, defineConfig, defineSchema, getStaticPropsForTina, gql, safeAssertShape, staticRequest, useDocumentCreatorPlugin, useGraphqlForms,
|
|
4181
|
+
export { AuthWallInner, Client, DEFAULT_LOCAL_TINA_GQL_SERVER_URL, LocalClient, RouteMappingPlugin, TinaAdmin, TinaAdminApi, TinaCMSProvider2, TinaCloudAuthWall, TinaCloudProvider, TinaDataProvider, assertShape, createClient, TinaCMSProvider2 as default, defineConfig, defineSchema, getStaticPropsForTina, gql, safeAssertShape, staticRequest, useDocumentCreatorPlugin, useGraphqlForms, useTinaAuthRedirect };
|