tinacms 0.67.2 → 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 +186 -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 +216 -575
- package/dist/index.js +214 -574
- 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.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
|
},
|
|
@@ -3133,6 +2867,30 @@ function useTina({
|
|
|
3133
2867
|
isLoading
|
|
3134
2868
|
};
|
|
3135
2869
|
}
|
|
2870
|
+
const TINA_HOST = "content.tinajs.io";
|
|
2871
|
+
const parseURL = (url) => {
|
|
2872
|
+
if (url.includes("localhost")) {
|
|
2873
|
+
return { branch: null, isLocalClient: true, clientId: null };
|
|
2874
|
+
}
|
|
2875
|
+
const params = new URL(url);
|
|
2876
|
+
const pattern = new UrlPattern("/content/:clientId/github/*", {
|
|
2877
|
+
escapeChar: " "
|
|
2878
|
+
});
|
|
2879
|
+
const result = pattern.match(params.pathname);
|
|
2880
|
+
const branch = result == null ? void 0 : result._;
|
|
2881
|
+
const clientId = result == null ? void 0 : result.clientId;
|
|
2882
|
+
if (!branch || !clientId) {
|
|
2883
|
+
throw new Error(`Invalid URL format provided. Expected: https://content.tinajs.io/content/<ClientID>/github/<Branch> but but received ${url}`);
|
|
2884
|
+
}
|
|
2885
|
+
if (params.host !== TINA_HOST) {
|
|
2886
|
+
throw new Error(`The only supported hosts are ${TINA_HOST} or localhost, but received ${params.host}.`);
|
|
2887
|
+
}
|
|
2888
|
+
return {
|
|
2889
|
+
branch,
|
|
2890
|
+
clientId,
|
|
2891
|
+
isLocalClient: false
|
|
2892
|
+
};
|
|
2893
|
+
};
|
|
3136
2894
|
const errorButtonStyles = {
|
|
3137
2895
|
background: "#eb6337",
|
|
3138
2896
|
padding: "12px 18px",
|
|
@@ -3212,21 +2970,6 @@ class ErrorBoundary extends React.Component {
|
|
|
3212
2970
|
return this.props.children;
|
|
3213
2971
|
}
|
|
3214
2972
|
}
|
|
3215
|
-
const parseURL = (url) => {
|
|
3216
|
-
if (url.includes("localhost")) {
|
|
3217
|
-
return { branch: null, isLocalClient: true, clientId: null };
|
|
3218
|
-
}
|
|
3219
|
-
const tinaHost = "content.tinajs.io";
|
|
3220
|
-
const params = new URL(url);
|
|
3221
|
-
const pattern = new UrlPattern("/content/:clientId/github/:branch");
|
|
3222
|
-
const result = pattern.match(params.pathname);
|
|
3223
|
-
if (params.host !== tinaHost) {
|
|
3224
|
-
throw new Error(`The only supported hosts are ${tinaHost} or localhost, but received ${params.host}.`);
|
|
3225
|
-
}
|
|
3226
|
-
return __spreadProps(__spreadValues({}, result), {
|
|
3227
|
-
isLocalClient: false
|
|
3228
|
-
});
|
|
3229
|
-
};
|
|
3230
2973
|
const TinaCMSProvider2 = (_c) => {
|
|
3231
2974
|
var _d = _c, {
|
|
3232
2975
|
query,
|
|
@@ -3248,6 +2991,9 @@ const TinaCMSProvider2 = (_c) => {
|
|
|
3248
2991
|
clientId: props.clientId,
|
|
3249
2992
|
isLocalClient: props.isLocalClient
|
|
3250
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
|
+
}
|
|
3251
2997
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TinaCloudProvider, {
|
|
3252
2998
|
branch,
|
|
3253
2999
|
clientId,
|
|
@@ -3297,25 +3043,13 @@ const TinaDataProvider = ({
|
|
|
3297
3043
|
payload: void 0,
|
|
3298
3044
|
isLoading: true
|
|
3299
3045
|
});
|
|
3300
|
-
const cms = useCMS();
|
|
3301
|
-
const useUnstableFormify = React.useMemo(() => {
|
|
3302
|
-
if ((cms == null ? void 0 : cms.flags.get("use-unstable-formify")) === false) {
|
|
3303
|
-
return false;
|
|
3304
|
-
}
|
|
3305
|
-
return true;
|
|
3306
|
-
}, [cms == null ? void 0 : cms.flags]);
|
|
3307
3046
|
return /* @__PURE__ */ React.createElement(TinaDataContext.Provider, {
|
|
3308
3047
|
value: {
|
|
3309
3048
|
setRequest,
|
|
3310
3049
|
isLoading: state.isLoading,
|
|
3311
3050
|
state: { payload: state.payload }
|
|
3312
3051
|
}
|
|
3313
|
-
},
|
|
3314
|
-
key: request == null ? void 0 : request.query,
|
|
3315
|
-
request,
|
|
3316
|
-
formifyCallback,
|
|
3317
|
-
onPayloadStateChange: setState
|
|
3318
|
-
}) : /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3052
|
+
}, /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3319
3053
|
key: request == null ? void 0 : request.query,
|
|
3320
3054
|
request,
|
|
3321
3055
|
formifyCallback,
|
|
@@ -3344,35 +3078,6 @@ const FormRegistrar = ({
|
|
|
3344
3078
|
}, [JSON.stringify(payload), isLoading]);
|
|
3345
3079
|
return isLoading ? /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement(React.Fragment, null)) : null;
|
|
3346
3080
|
};
|
|
3347
|
-
const FormRegistrarUnstable = (props) => {
|
|
3348
|
-
var _a;
|
|
3349
|
-
if (!((_a = props.request) == null ? void 0 : _a.query)) {
|
|
3350
|
-
return null;
|
|
3351
|
-
}
|
|
3352
|
-
return /* @__PURE__ */ React.createElement(FormRegistrarUnstableInner, __spreadValues({}, props));
|
|
3353
|
-
};
|
|
3354
|
-
const FormRegistrarUnstableInner = ({
|
|
3355
|
-
request,
|
|
3356
|
-
formifyCallback,
|
|
3357
|
-
onPayloadStateChange
|
|
3358
|
-
}) => {
|
|
3359
|
-
const cms = useCMS();
|
|
3360
|
-
const [payload, isLoading] = useGraphqlFormsUnstable({
|
|
3361
|
-
query: request == null ? void 0 : request.query,
|
|
3362
|
-
variables: request == null ? void 0 : request.variables,
|
|
3363
|
-
formify: (args) => {
|
|
3364
|
-
if (formifyCallback) {
|
|
3365
|
-
return formifyCallback(args, cms);
|
|
3366
|
-
} else {
|
|
3367
|
-
return args.createForm(args.formConfig);
|
|
3368
|
-
}
|
|
3369
|
-
}
|
|
3370
|
-
});
|
|
3371
|
-
React.useEffect(() => {
|
|
3372
|
-
onPayloadStateChange({ payload, isLoading });
|
|
3373
|
-
}, [JSON.stringify(payload), isLoading]);
|
|
3374
|
-
return isLoading ? /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement(React.Fragment, null)) : null;
|
|
3375
|
-
};
|
|
3376
3081
|
const Loader = (props) => {
|
|
3377
3082
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
3378
3083
|
style: {
|
|
@@ -3617,8 +3322,8 @@ const useGetCollections = (cms) => {
|
|
|
3617
3322
|
const fetchCollections = async () => {
|
|
3618
3323
|
if (await api.isAuthenticated()) {
|
|
3619
3324
|
try {
|
|
3620
|
-
const
|
|
3621
|
-
setCollections(
|
|
3325
|
+
const collections2 = await api.fetchCollections();
|
|
3326
|
+
setCollections(collections2);
|
|
3622
3327
|
} catch (error2) {
|
|
3623
3328
|
console.error(error2);
|
|
3624
3329
|
setCollections([]);
|
|
@@ -3921,8 +3626,8 @@ const useGetCollection = (cms, collectionName, includeDocuments = true) => {
|
|
|
3921
3626
|
const fetchCollection = async () => {
|
|
3922
3627
|
if (await api.isAuthenticated()) {
|
|
3923
3628
|
try {
|
|
3924
|
-
const
|
|
3925
|
-
setCollection(
|
|
3629
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments);
|
|
3630
|
+
setCollection(collection2);
|
|
3926
3631
|
} catch (error2) {
|
|
3927
3632
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
3928
3633
|
console.error(error2);
|
|
@@ -3988,7 +3693,7 @@ const handleNavigate = (navigate, cms, collection, document) => {
|
|
|
3988
3693
|
window.location.href = routeOverride;
|
|
3989
3694
|
return null;
|
|
3990
3695
|
} else {
|
|
3991
|
-
navigate(document.
|
|
3696
|
+
navigate(document._sys.breadcrumbs.join("/"));
|
|
3992
3697
|
}
|
|
3993
3698
|
};
|
|
3994
3699
|
const CollectionListPage = () => {
|
|
@@ -4041,9 +3746,9 @@ const CollectionListPage = () => {
|
|
|
4041
3746
|
}, /* @__PURE__ */ React.createElement("tbody", {
|
|
4042
3747
|
className: "divide-y divide-gray-150"
|
|
4043
3748
|
}, documents.map((document) => {
|
|
4044
|
-
const subfolders = document.node.
|
|
3749
|
+
const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
|
|
4045
3750
|
return /* @__PURE__ */ React.createElement("tr", {
|
|
4046
|
-
key: `document-${document.node.
|
|
3751
|
+
key: `document-${document.node._sys.relativePath}`,
|
|
4047
3752
|
className: ""
|
|
4048
3753
|
}, /* @__PURE__ */ React.createElement("td", {
|
|
4049
3754
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -4060,19 +3765,19 @@ const CollectionListPage = () => {
|
|
|
4060
3765
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
4061
3766
|
}, subfolders && /* @__PURE__ */ React.createElement("span", {
|
|
4062
3767
|
className: "text-xs text-gray-400"
|
|
4063
|
-
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node.
|
|
3768
|
+
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React.createElement("td", {
|
|
4064
3769
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4065
3770
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4066
3771
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4067
3772
|
}, "Extension"), /* @__PURE__ */ React.createElement("span", {
|
|
4068
3773
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4069
|
-
}, document.node.
|
|
3774
|
+
}, document.node._sys.extension)), /* @__PURE__ */ React.createElement("td", {
|
|
4070
3775
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4071
3776
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4072
3777
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4073
3778
|
}, "Template"), /* @__PURE__ */ React.createElement("span", {
|
|
4074
3779
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4075
|
-
}, document.node.
|
|
3780
|
+
}, document.node._sys.template)), /* @__PURE__ */ React.createElement("td", {
|
|
4076
3781
|
className: "w-0"
|
|
4077
3782
|
}, /* @__PURE__ */ React.createElement(OverflowMenu, {
|
|
4078
3783
|
showEmbed: true,
|
|
@@ -4084,7 +3789,7 @@ const CollectionListPage = () => {
|
|
|
4084
3789
|
size: "1.3rem"
|
|
4085
3790
|
}),
|
|
4086
3791
|
onMouseDown: () => {
|
|
4087
|
-
navigate(`${document.node.
|
|
3792
|
+
navigate(`${document.node._sys.filename}`, { replace: true });
|
|
4088
3793
|
}
|
|
4089
3794
|
},
|
|
4090
3795
|
{
|
|
@@ -4097,7 +3802,7 @@ const CollectionListPage = () => {
|
|
|
4097
3802
|
onMouseDown: () => {
|
|
4098
3803
|
setVars({
|
|
4099
3804
|
collection: collectionName,
|
|
4100
|
-
relativePath: document.node.
|
|
3805
|
+
relativePath: document.node._sys.filename + document.node._sys.extension
|
|
4101
3806
|
});
|
|
4102
3807
|
setOpen(true);
|
|
4103
3808
|
}
|
|
@@ -4111,7 +3816,7 @@ const CollectionListPage = () => {
|
|
|
4111
3816
|
const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
4112
3817
|
return /* @__PURE__ */ React.createElement(Modal, null, /* @__PURE__ */ React.createElement(ModalPopup, null, /* @__PURE__ */ React.createElement(ModalHeader, {
|
|
4113
3818
|
close: close2
|
|
4114
|
-
}, "
|
|
3819
|
+
}, "Delete ", filename), /* @__PURE__ */ React.createElement(ModalBody, {
|
|
4115
3820
|
padded: true
|
|
4116
3821
|
}, /* @__PURE__ */ React.createElement("p", null, `Are you sure you want to delete ${filename}?`)), /* @__PURE__ */ React.createElement(ModalActions, null, /* @__PURE__ */ React.createElement(Button, {
|
|
4117
3822
|
style: { flexGrow: 2 },
|
|
@@ -4125,72 +3830,6 @@ const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
|
4125
3830
|
}
|
|
4126
3831
|
}, "Delete"))));
|
|
4127
3832
|
};
|
|
4128
|
-
const useGetDocumentFields = (cms, collectionName, templateName) => {
|
|
4129
|
-
const api = new TinaAdminApi(cms);
|
|
4130
|
-
const [info, setInfo] = useState({
|
|
4131
|
-
collection: void 0,
|
|
4132
|
-
template: void 0,
|
|
4133
|
-
fields: void 0,
|
|
4134
|
-
mutationInfo: void 0
|
|
4135
|
-
});
|
|
4136
|
-
const [loading, setLoading] = useState(true);
|
|
4137
|
-
const [error, setError] = useState(void 0);
|
|
4138
|
-
useEffect(() => {
|
|
4139
|
-
const fetchDocumentFields = async () => {
|
|
4140
|
-
if (await api.isAuthenticated()) {
|
|
4141
|
-
try {
|
|
4142
|
-
const response = await api.fetchDocumentFields();
|
|
4143
|
-
const documentFields = response.getDocumentFields;
|
|
4144
|
-
const collection = documentFields[collectionName].collection;
|
|
4145
|
-
const mutationInfo = documentFields[collectionName].mutationInfo;
|
|
4146
|
-
let fields = void 0;
|
|
4147
|
-
let template = void 0;
|
|
4148
|
-
if (templateName && documentFields[collectionName].templates && documentFields[collectionName].templates[templateName]) {
|
|
4149
|
-
template = documentFields[collectionName].templates[templateName].template;
|
|
4150
|
-
fields = documentFields[collectionName].templates[templateName].fields;
|
|
4151
|
-
} else {
|
|
4152
|
-
fields = documentFields[collectionName].fields;
|
|
4153
|
-
}
|
|
4154
|
-
setInfo({
|
|
4155
|
-
collection,
|
|
4156
|
-
template,
|
|
4157
|
-
fields,
|
|
4158
|
-
mutationInfo
|
|
4159
|
-
});
|
|
4160
|
-
} catch (error2) {
|
|
4161
|
-
cms.alerts.error(`[${error2.name}] GetDocumentFields failed: ${error2.message}`, 30 * 1e3);
|
|
4162
|
-
console.error(error2);
|
|
4163
|
-
setInfo({
|
|
4164
|
-
collection: void 0,
|
|
4165
|
-
template: void 0,
|
|
4166
|
-
fields: void 0,
|
|
4167
|
-
mutationInfo: void 0
|
|
4168
|
-
});
|
|
4169
|
-
setError(error2);
|
|
4170
|
-
}
|
|
4171
|
-
setLoading(false);
|
|
4172
|
-
}
|
|
4173
|
-
};
|
|
4174
|
-
setLoading(true);
|
|
4175
|
-
fetchDocumentFields();
|
|
4176
|
-
}, [cms, collectionName]);
|
|
4177
|
-
return __spreadProps(__spreadValues({}, info), { loading, error });
|
|
4178
|
-
};
|
|
4179
|
-
const GetDocumentFields = ({
|
|
4180
|
-
cms,
|
|
4181
|
-
collectionName,
|
|
4182
|
-
templateName,
|
|
4183
|
-
children
|
|
4184
|
-
}) => {
|
|
4185
|
-
const { collection, template, fields, mutationInfo, loading, error } = useGetDocumentFields(cms, collectionName, templateName);
|
|
4186
|
-
if (error) {
|
|
4187
|
-
return null;
|
|
4188
|
-
}
|
|
4189
|
-
if (loading) {
|
|
4190
|
-
return /* @__PURE__ */ React.createElement(LoadingPage, null);
|
|
4191
|
-
}
|
|
4192
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, children({ collection, template, fields, mutationInfo, loading }));
|
|
4193
|
-
};
|
|
4194
3833
|
function HiChevronRight(props) {
|
|
4195
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);
|
|
4196
3835
|
}
|
|
@@ -4216,38 +3855,39 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
|
|
|
4216
3855
|
};
|
|
4217
3856
|
const CollectionCreatePage = () => {
|
|
4218
3857
|
const { collectionName, templateName } = useParams();
|
|
4219
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
3858
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4220
3859
|
cms,
|
|
4221
3860
|
collectionName,
|
|
4222
|
-
|
|
4223
|
-
}, (
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
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
|
+
}));
|
|
4230
3874
|
};
|
|
4231
|
-
const RenderForm$1 = ({ cms, collection,
|
|
3875
|
+
const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
|
|
4232
3876
|
var _a, _b;
|
|
4233
3877
|
const navigate = useNavigate();
|
|
4234
3878
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4235
3879
|
const schema = cms.api.tina.schema;
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
template: template2
|
|
4248
|
-
});
|
|
4249
|
-
schemaFields = formInfo.fields;
|
|
4250
|
-
}
|
|
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
|
+
});
|
|
4251
3891
|
const form = useMemo(() => {
|
|
4252
3892
|
return new Form({
|
|
4253
3893
|
id: "create-form",
|
|
@@ -4272,7 +3912,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4272
3912
|
}
|
|
4273
3913
|
}
|
|
4274
3914
|
},
|
|
4275
|
-
...
|
|
3915
|
+
...formInfo.fields
|
|
4276
3916
|
],
|
|
4277
3917
|
onSubmit: async (values) => {
|
|
4278
3918
|
try {
|
|
@@ -4285,7 +3925,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4285
3925
|
}
|
|
4286
3926
|
}
|
|
4287
3927
|
});
|
|
4288
|
-
}, [cms, collection,
|
|
3928
|
+
}, [cms, collection, mutationInfo]);
|
|
4289
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", {
|
|
4290
3930
|
className: "py-4 px-20 border-b border-gray-200 bg-white"
|
|
4291
3931
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
@@ -4318,7 +3958,7 @@ const useGetDocument = (cms, collectionName, relativePath) => {
|
|
|
4318
3958
|
if (api.isAuthenticated()) {
|
|
4319
3959
|
try {
|
|
4320
3960
|
const response = await api.fetchDocument(collectionName, relativePath);
|
|
4321
|
-
setDocument(response.
|
|
3961
|
+
setDocument(response.document);
|
|
4322
3962
|
} catch (error2) {
|
|
4323
3963
|
cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
|
|
4324
3964
|
console.error(error2);
|
|
@@ -4367,11 +4007,16 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
|
|
|
4367
4007
|
const CollectionUpdatePage = () => {
|
|
4368
4008
|
const _a = useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4369
4009
|
const { "*": filename } = rest;
|
|
4370
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
4010
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4371
4011
|
cms,
|
|
4372
|
-
collectionName
|
|
4373
|
-
|
|
4012
|
+
collectionName,
|
|
4013
|
+
includeDocuments: false
|
|
4014
|
+
}, (collection) => {
|
|
4374
4015
|
const relativePath = `${filename}.${collection.format}`;
|
|
4016
|
+
const mutationInfo = {
|
|
4017
|
+
includeCollection: true,
|
|
4018
|
+
includeTemplate: !!collection.templates
|
|
4019
|
+
};
|
|
4375
4020
|
return /* @__PURE__ */ React.createElement(GetDocument, {
|
|
4376
4021
|
cms,
|
|
4377
4022
|
collectionName: collection.name,
|
|
@@ -4397,27 +4042,23 @@ const RenderForm = ({
|
|
|
4397
4042
|
var _a, _b;
|
|
4398
4043
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4399
4044
|
const schema = cms.api.tina.schema;
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
template
|
|
4412
|
-
});
|
|
4413
|
-
schemaFields = formInfo.fields;
|
|
4414
|
-
}
|
|
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
|
+
});
|
|
4415
4056
|
const form = useMemo(() => {
|
|
4416
4057
|
return new Form({
|
|
4417
4058
|
id: "update-form",
|
|
4418
4059
|
label: "form",
|
|
4419
|
-
fields:
|
|
4420
|
-
initialValues: document.
|
|
4060
|
+
fields: formInfo.fields,
|
|
4061
|
+
initialValues: document._values,
|
|
4421
4062
|
onSubmit: async (values) => {
|
|
4422
4063
|
try {
|
|
4423
4064
|
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
@@ -4537,4 +4178,4 @@ const defineSchema = (config) => {
|
|
|
4537
4178
|
const defineConfig = (config) => {
|
|
4538
4179
|
return config;
|
|
4539
4180
|
};
|
|
4540
|
-
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 };
|