tinacms 0.67.3 → 0.68.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +188 -0
- package/dist/admin/api.d.ts +5 -9
- package/dist/admin/types.d.ts +4 -21
- package/dist/hooks/formify/formify-utils.d.ts +1 -0
- package/dist/hooks/formify/formify.d.ts +0 -1
- package/dist/hooks/formify/types.d.ts +3 -11
- package/dist/hooks/use-graphql-forms.d.ts +4 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +219 -576
- package/dist/index.js +217 -575
- package/dist/utils/parseUrl.d.ts +18 -0
- package/package.json +2 -2
- package/dist/admin/components/GetDocumentFields.d.ts +0 -40
package/dist/index.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,
|
|
@@ -425,241 +425,11 @@ function useGraphqlFormsUnstable({
|
|
|
425
425
|
eventList,
|
|
426
426
|
onSubmit
|
|
427
427
|
});
|
|
428
|
+
if (!query) {
|
|
429
|
+
return [state.data, false];
|
|
430
|
+
}
|
|
428
431
|
return [state.data, state.status !== "done"];
|
|
429
432
|
}
|
|
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
433
|
const transformDocumentIntoMutationRequestPayload = (document, instructions) => {
|
|
664
434
|
const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
|
|
665
435
|
const params = transformParams(rest);
|
|
@@ -696,37 +466,7 @@ const transformParams = (data) => {
|
|
|
696
466
|
}
|
|
697
467
|
}
|
|
698
468
|
};
|
|
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) => {
|
|
469
|
+
const generateFormCreators = (cms, showInSidebar) => {
|
|
730
470
|
const createForm = (formConfig) => {
|
|
731
471
|
const form = new Form(formConfig);
|
|
732
472
|
if (showInSidebar) {
|
|
@@ -810,7 +550,7 @@ const getPathToChange = (documentBlueprint, formNode, event) => {
|
|
|
810
550
|
return accum.join(".");
|
|
811
551
|
};
|
|
812
552
|
const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
813
|
-
const { createForm, createGlobalForm } =
|
|
553
|
+
const { createForm, createGlobalForm } = generateFormCreators(cms, showInSidebar);
|
|
814
554
|
const SKIPPED = "SKIPPED";
|
|
815
555
|
let form;
|
|
816
556
|
let skipped;
|
|
@@ -820,25 +560,50 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
|
820
560
|
if (skipped)
|
|
821
561
|
return;
|
|
822
562
|
const id = doc._internalSys.path;
|
|
563
|
+
const enrichedSchema = cms.api.tina.schema;
|
|
564
|
+
const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
|
|
565
|
+
const template = enrichedSchema.getTemplateForData({
|
|
566
|
+
collection,
|
|
567
|
+
data: doc._values
|
|
568
|
+
});
|
|
823
569
|
const formCommon = {
|
|
824
570
|
id,
|
|
825
|
-
label:
|
|
826
|
-
initialValues: doc.
|
|
571
|
+
label: id,
|
|
572
|
+
initialValues: doc._values,
|
|
827
573
|
onSubmit: async (payload) => {
|
|
828
574
|
try {
|
|
829
|
-
const params = transformDocumentIntoMutationRequestPayload(payload,
|
|
575
|
+
const params = transformDocumentIntoMutationRequestPayload(payload, {
|
|
576
|
+
includeCollection: false,
|
|
577
|
+
includeTemplate: !!collection.templates
|
|
578
|
+
});
|
|
830
579
|
const variables = { params };
|
|
831
|
-
const mutationString =
|
|
580
|
+
const mutationString = `#graphql
|
|
581
|
+
mutation UpdateDocument($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
582
|
+
updateDocument(collection: $collection, relativePath: $relativePath, params: $params) {
|
|
583
|
+
__typename
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
`;
|
|
832
587
|
if (onSubmit) {
|
|
833
588
|
onSubmit({
|
|
834
589
|
queryString: mutationString,
|
|
835
590
|
mutationString,
|
|
836
|
-
variables
|
|
591
|
+
variables: {
|
|
592
|
+
collection: doc._internalSys.collection.name,
|
|
593
|
+
relativePath: doc._internalSys.relativePath,
|
|
594
|
+
params: { [doc._internalSys.collection.name]: variables }
|
|
595
|
+
}
|
|
837
596
|
});
|
|
838
597
|
} else {
|
|
839
598
|
try {
|
|
840
599
|
await cms.api.tina.request(mutationString, {
|
|
841
|
-
variables
|
|
600
|
+
variables: {
|
|
601
|
+
collection: doc._internalSys.collection.name,
|
|
602
|
+
relativePath: doc._internalSys.relativePath,
|
|
603
|
+
params: {
|
|
604
|
+
[doc._internalSys.collection.name]: variables.params
|
|
605
|
+
}
|
|
606
|
+
}
|
|
842
607
|
});
|
|
843
608
|
cms.alerts.success("Document saved!");
|
|
844
609
|
} catch (e) {
|
|
@@ -853,29 +618,16 @@ const buildForm = (doc, cms, formify2, showInSidebar = false, onSubmit) => {
|
|
|
853
618
|
}
|
|
854
619
|
};
|
|
855
620
|
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
|
-
}
|
|
621
|
+
const formInfo = resolveForm({
|
|
622
|
+
collection,
|
|
623
|
+
basename: collection.name,
|
|
624
|
+
schema: enrichedSchema,
|
|
625
|
+
template
|
|
626
|
+
});
|
|
627
|
+
formConfig = __spreadValues({
|
|
628
|
+
label: formInfo.label,
|
|
629
|
+
fields: formInfo.fields
|
|
630
|
+
}, formCommon);
|
|
879
631
|
if (formify2) {
|
|
880
632
|
form = formify2({
|
|
881
633
|
formConfig,
|
|
@@ -994,7 +746,7 @@ const getEventPath = (event, blueprint) => {
|
|
|
994
746
|
}
|
|
995
747
|
return `[]`;
|
|
996
748
|
}).join(".");
|
|
997
|
-
const items = [blueprint.id,
|
|
749
|
+
const items = [blueprint.id, eventPath];
|
|
998
750
|
const isList = event.field.data.tinaField.list;
|
|
999
751
|
if (isList && !eventPath.endsWith("[]")) {
|
|
1000
752
|
items.push(`[]`);
|
|
@@ -1029,14 +781,13 @@ const getMatchName = ({ field, prefix, blueprint }) => {
|
|
|
1029
781
|
if (prefix) {
|
|
1030
782
|
extra.push(prefix);
|
|
1031
783
|
}
|
|
1032
|
-
const matchName = [blueprintName,
|
|
784
|
+
const matchName = [blueprintName, ...extra, fieldName].join(".");
|
|
1033
785
|
return { matchName, fieldName };
|
|
1034
786
|
};
|
|
1035
787
|
const getFormNodesFromEvent = (state, event) => {
|
|
1036
788
|
const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
|
|
1037
789
|
return formNodes;
|
|
1038
790
|
};
|
|
1039
|
-
const DATA_NODE_NAME$1 = "data";
|
|
1040
791
|
const printEvent = (event) => {
|
|
1041
792
|
var _a, _b;
|
|
1042
793
|
return {
|
|
@@ -1242,14 +993,14 @@ function buildPath({
|
|
|
1242
993
|
}
|
|
1243
994
|
const node = G.parse(`
|
|
1244
995
|
query Sample {
|
|
1245
|
-
_internalSys:
|
|
996
|
+
_internalSys: _sys {
|
|
1246
997
|
path
|
|
998
|
+
relativePath
|
|
1247
999
|
collection {
|
|
1248
1000
|
name
|
|
1249
1001
|
}
|
|
1250
1002
|
}
|
|
1251
|
-
|
|
1252
|
-
values
|
|
1003
|
+
_values
|
|
1253
1004
|
}`);
|
|
1254
1005
|
const metaFields = node.definitions[0].selectionSet.selections;
|
|
1255
1006
|
const getRelativeBlueprint = (path) => {
|
|
@@ -1266,6 +1017,21 @@ const getRelativeBlueprint = (path) => {
|
|
|
1266
1017
|
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
|
|
1267
1018
|
return getBlueprintNamePath({ path: documentBlueprintPath });
|
|
1268
1019
|
};
|
|
1020
|
+
const isSysField = (fieldNode) => {
|
|
1021
|
+
if (fieldNode.name.value === "__typename") {
|
|
1022
|
+
return true;
|
|
1023
|
+
}
|
|
1024
|
+
if (fieldNode.name.value === "_sys") {
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
if (fieldNode.name.value === "_values") {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
if (fieldNode.name.value === "id") {
|
|
1031
|
+
return true;
|
|
1032
|
+
}
|
|
1033
|
+
return false;
|
|
1034
|
+
};
|
|
1269
1035
|
const getBlueprintId = (path) => {
|
|
1270
1036
|
const namePath = [];
|
|
1271
1037
|
const aliasPath = [];
|
|
@@ -1283,10 +1049,9 @@ const NOOP = "This is either an error or is not yet supported";
|
|
|
1283
1049
|
const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
|
|
1284
1050
|
const EDGES_NODE_NAME = "edges";
|
|
1285
1051
|
const NODE_NAME = "node";
|
|
1286
|
-
const COLLECTION_FIELD_NAME = "
|
|
1287
|
-
const COLLECTIONS_FIELD_NAME = "
|
|
1052
|
+
const COLLECTION_FIELD_NAME = "collection";
|
|
1053
|
+
const COLLECTIONS_FIELD_NAME = "collections";
|
|
1288
1054
|
const COLLECTIONS_DOCUMENTS_NAME = "documents";
|
|
1289
|
-
const DATA_NODE_NAME = "data";
|
|
1290
1055
|
const formify = async ({
|
|
1291
1056
|
schema,
|
|
1292
1057
|
query,
|
|
@@ -1392,22 +1157,15 @@ const formify = async ({
|
|
|
1392
1157
|
showInSidebar = false
|
|
1393
1158
|
}) {
|
|
1394
1159
|
let extraFields = [];
|
|
1395
|
-
|
|
1160
|
+
const hasDataJSONField = false;
|
|
1396
1161
|
let hasValuesField = false;
|
|
1397
1162
|
let shouldFormify = false;
|
|
1398
1163
|
selection.selectionSet.selections.forEach((selection2) => {
|
|
1399
1164
|
if (selection2.kind === "Field") {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
hasDataJSONField = true;
|
|
1403
|
-
}
|
|
1404
|
-
if (selection2.name.value === "values") {
|
|
1405
|
-
shouldFormify = true;
|
|
1165
|
+
shouldFormify = true;
|
|
1166
|
+
if (selection2.name.value === "_values") {
|
|
1406
1167
|
hasValuesField = true;
|
|
1407
1168
|
}
|
|
1408
|
-
if (selection2.name.value === "data") {
|
|
1409
|
-
shouldFormify = true;
|
|
1410
|
-
}
|
|
1411
1169
|
}
|
|
1412
1170
|
});
|
|
1413
1171
|
if (shouldFormify) {
|
|
@@ -1446,33 +1204,11 @@ const formify = async ({
|
|
|
1446
1204
|
});
|
|
1447
1205
|
}
|
|
1448
1206
|
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;
|
|
1207
|
+
return formifyFieldNode({
|
|
1208
|
+
fieldNode: selectionNode,
|
|
1209
|
+
parentType: type,
|
|
1210
|
+
path
|
|
1211
|
+
});
|
|
1476
1212
|
}
|
|
1477
1213
|
default:
|
|
1478
1214
|
throw new FormifyError("UNEXPECTED");
|
|
@@ -1495,16 +1231,19 @@ const formify = async ({
|
|
|
1495
1231
|
if (!field) {
|
|
1496
1232
|
return fieldNode;
|
|
1497
1233
|
}
|
|
1498
|
-
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
|
|
1499
|
-
if (!blueprint) {
|
|
1500
|
-
return fieldNode;
|
|
1501
|
-
}
|
|
1502
1234
|
const fieldPath = buildPath({
|
|
1503
1235
|
fieldNode,
|
|
1504
1236
|
type: field.type,
|
|
1505
1237
|
parentTypename: G.getNamedType(parentType).name,
|
|
1506
1238
|
path
|
|
1507
1239
|
});
|
|
1240
|
+
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(fieldPath));
|
|
1241
|
+
if (!blueprint) {
|
|
1242
|
+
return fieldNode;
|
|
1243
|
+
}
|
|
1244
|
+
if (isSysField(fieldNode)) {
|
|
1245
|
+
return fieldNode;
|
|
1246
|
+
}
|
|
1508
1247
|
blueprint.fields.push({
|
|
1509
1248
|
id: getBlueprintId(fieldPath),
|
|
1510
1249
|
documentBlueprintId: blueprint.id,
|
|
@@ -2050,10 +1789,10 @@ const useFormify = ({
|
|
|
2050
1789
|
query Node($id: String!) {
|
|
2051
1790
|
node(id: $id) {
|
|
2052
1791
|
...on Document {
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
_internalSys: sys {
|
|
1792
|
+
_values
|
|
1793
|
+
_internalSys: _sys {
|
|
2056
1794
|
path
|
|
1795
|
+
relativePath
|
|
2057
1796
|
collection {
|
|
2058
1797
|
name
|
|
2059
1798
|
}
|
|
@@ -2163,9 +1902,7 @@ const useFormify = ({
|
|
|
2163
1902
|
dispatch({
|
|
2164
1903
|
type: "setIn",
|
|
2165
1904
|
value: __spreadProps(__spreadValues({}, changeSet), {
|
|
2166
|
-
value:
|
|
2167
|
-
data
|
|
2168
|
-
})
|
|
1905
|
+
value: __spreadValues(__spreadValues({}, res.node), data)
|
|
2169
1906
|
})
|
|
2170
1907
|
});
|
|
2171
1908
|
}).catch((e) => {
|
|
@@ -2284,10 +2021,10 @@ const useFormify = ({
|
|
|
2284
2021
|
query Node($id: String!) {
|
|
2285
2022
|
node(id: $id) {
|
|
2286
2023
|
...on Document {
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
_internalSys: sys {
|
|
2024
|
+
_values
|
|
2025
|
+
_internalSys: _sys {
|
|
2290
2026
|
path
|
|
2027
|
+
relativePath
|
|
2291
2028
|
collection {
|
|
2292
2029
|
name
|
|
2293
2030
|
}
|
|
@@ -2325,13 +2062,11 @@ const useFormify = ({
|
|
|
2325
2062
|
}
|
|
2326
2063
|
}
|
|
2327
2064
|
`, { variables: { id: value } });
|
|
2328
|
-
data[keyName] =
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
})
|
|
2334
|
-
});
|
|
2065
|
+
data[keyName] = __spreadValues(__spreadValues({}, res.node), await resolveSubFields({
|
|
2066
|
+
formNode: subDocumentFormNode,
|
|
2067
|
+
form: form2,
|
|
2068
|
+
loc: location
|
|
2069
|
+
}));
|
|
2335
2070
|
});
|
|
2336
2071
|
break;
|
|
2337
2072
|
default:
|
|
@@ -2692,19 +2427,19 @@ const useTinaAuthRedirect = () => {
|
|
|
2692
2427
|
class TinaAdminApi {
|
|
2693
2428
|
constructor(cms) {
|
|
2694
2429
|
this.api = cms.api.tina;
|
|
2430
|
+
this.schema = cms.api.tina.schema;
|
|
2695
2431
|
}
|
|
2696
2432
|
async isAuthenticated() {
|
|
2697
2433
|
return await this.api.isAuthenticated();
|
|
2698
2434
|
}
|
|
2699
2435
|
async fetchCollections() {
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
return response;
|
|
2436
|
+
try {
|
|
2437
|
+
const collections = this.schema.getCollections();
|
|
2438
|
+
return collections;
|
|
2439
|
+
} catch (e) {
|
|
2440
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollections(): ${e.message}`);
|
|
2441
|
+
return [];
|
|
2442
|
+
}
|
|
2708
2443
|
}
|
|
2709
2444
|
async deleteDocument({
|
|
2710
2445
|
collection,
|
|
@@ -2718,9 +2453,10 @@ class TinaAdminApi {
|
|
|
2718
2453
|
}`, { variables: { collection, relativePath } });
|
|
2719
2454
|
}
|
|
2720
2455
|
async fetchCollection(collectionName, includeDocuments) {
|
|
2721
|
-
|
|
2456
|
+
if (includeDocuments === true) {
|
|
2457
|
+
const response = await this.api.request(`#graphql
|
|
2722
2458
|
query($collection: String!, $includeDocuments: Boolean!){
|
|
2723
|
-
|
|
2459
|
+
collection(collection: $collection){
|
|
2724
2460
|
name
|
|
2725
2461
|
label
|
|
2726
2462
|
format
|
|
@@ -2730,7 +2466,7 @@ class TinaAdminApi {
|
|
|
2730
2466
|
edges {
|
|
2731
2467
|
node {
|
|
2732
2468
|
... on Document {
|
|
2733
|
-
|
|
2469
|
+
_sys {
|
|
2734
2470
|
template
|
|
2735
2471
|
breadcrumbs
|
|
2736
2472
|
path
|
|
@@ -2745,27 +2481,28 @@ class TinaAdminApi {
|
|
|
2745
2481
|
}
|
|
2746
2482
|
}
|
|
2747
2483
|
}`, { variables: { collection: collectionName, includeDocuments } });
|
|
2748
|
-
|
|
2484
|
+
return response.collection;
|
|
2485
|
+
} else {
|
|
2486
|
+
try {
|
|
2487
|
+
const collection = this.schema.getCollection(collectionName);
|
|
2488
|
+
return collection;
|
|
2489
|
+
} catch (e) {
|
|
2490
|
+
console.error(`[TinaAdminAPI] Unable to fetchCollection(): ${e.message}`);
|
|
2491
|
+
return void 0;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2749
2494
|
}
|
|
2750
2495
|
async fetchDocument(collectionName, relativePath) {
|
|
2751
2496
|
const response = await this.api.request(`#graphql
|
|
2752
2497
|
query($collection: String!, $relativePath: String!) {
|
|
2753
|
-
|
|
2498
|
+
document(collection:$collection, relativePath:$relativePath) {
|
|
2754
2499
|
... on Document {
|
|
2755
|
-
|
|
2756
|
-
values
|
|
2500
|
+
_values
|
|
2757
2501
|
}
|
|
2758
2502
|
}
|
|
2759
2503
|
}`, { variables: { collection: collectionName, relativePath } });
|
|
2760
2504
|
return response;
|
|
2761
2505
|
}
|
|
2762
|
-
async fetchDocumentFields() {
|
|
2763
|
-
const response = await this.api.request(`#graphql
|
|
2764
|
-
query {
|
|
2765
|
-
getDocumentFields
|
|
2766
|
-
}`, { variables: {} });
|
|
2767
|
-
return response;
|
|
2768
|
-
}
|
|
2769
2506
|
async createDocument(collectionName, relativePath, params) {
|
|
2770
2507
|
const response = await this.api.request(`#graphql
|
|
2771
2508
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
@@ -2786,7 +2523,7 @@ class TinaAdminApi {
|
|
|
2786
2523
|
async updateDocument(collectionName, relativePath, params) {
|
|
2787
2524
|
const response = await this.api.request(`#graphql
|
|
2788
2525
|
mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2789
|
-
updateDocument(
|
|
2526
|
+
updateDocument(
|
|
2790
2527
|
collection: $collection,
|
|
2791
2528
|
relativePath: $relativePath,
|
|
2792
2529
|
params: $params
|
|
@@ -2977,7 +2714,7 @@ class ContentCreatorPlugin {
|
|
|
2977
2714
|
} else {
|
|
2978
2715
|
cms.alerts.info("Document created!");
|
|
2979
2716
|
if (typeof this.onNewDocument === "function") {
|
|
2980
|
-
this.onNewDocument(res.addPendingDocument.
|
|
2717
|
+
this.onNewDocument(res.addPendingDocument._sys);
|
|
2981
2718
|
}
|
|
2982
2719
|
}
|
|
2983
2720
|
} catch (e) {
|
|
@@ -2997,7 +2734,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
2997
2734
|
var _a;
|
|
2998
2735
|
const res = await cms.api.tina.request((gql2) => gql2`
|
|
2999
2736
|
{
|
|
3000
|
-
|
|
2737
|
+
collections {
|
|
3001
2738
|
label
|
|
3002
2739
|
slug
|
|
3003
2740
|
format
|
|
@@ -3006,7 +2743,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3006
2743
|
}
|
|
3007
2744
|
`, { variables: {} });
|
|
3008
2745
|
const allCollectionOptions = [];
|
|
3009
|
-
res.
|
|
2746
|
+
res.collections.forEach((collection) => {
|
|
3010
2747
|
const value = collection.slug;
|
|
3011
2748
|
const label = `${collection.label}`;
|
|
3012
2749
|
allCollectionOptions.push({ value, label });
|
|
@@ -3028,7 +2765,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3028
2765
|
{ value: "", label: "Choose Template" }
|
|
3029
2766
|
];
|
|
3030
2767
|
if (values.collection) {
|
|
3031
|
-
const filteredCollection = res.
|
|
2768
|
+
const filteredCollection = res.collections.find((c) => c.slug === values.collection);
|
|
3032
2769
|
(_a = filteredCollection == null ? void 0 : filteredCollection.templates) == null ? void 0 : _a.forEach((template) => {
|
|
3033
2770
|
templateOptions.push({ value: template.name, label: template.label });
|
|
3034
2771
|
});
|
|
@@ -3036,7 +2773,7 @@ const useDocumentCreatorPlugin = (args) => {
|
|
|
3036
2773
|
setPlugin(new ContentCreatorPlugin({
|
|
3037
2774
|
label: "Add Document",
|
|
3038
2775
|
onNewDocument: args && args.onNewDocument,
|
|
3039
|
-
collections: res.
|
|
2776
|
+
collections: res.collections,
|
|
3040
2777
|
onChange: async ({ values: values2 }) => {
|
|
3041
2778
|
setValues(values2);
|
|
3042
2779
|
},
|
|
@@ -3133,6 +2870,30 @@ function useTina({
|
|
|
3133
2870
|
isLoading
|
|
3134
2871
|
};
|
|
3135
2872
|
}
|
|
2873
|
+
const TINA_HOST = "content.tinajs.io";
|
|
2874
|
+
const parseURL = (url) => {
|
|
2875
|
+
if (url.includes("localhost")) {
|
|
2876
|
+
return { branch: null, isLocalClient: true, clientId: null };
|
|
2877
|
+
}
|
|
2878
|
+
const params = new URL(url);
|
|
2879
|
+
const pattern = new UrlPattern("/content/:clientId/github/*", {
|
|
2880
|
+
escapeChar: " "
|
|
2881
|
+
});
|
|
2882
|
+
const result = pattern.match(params.pathname);
|
|
2883
|
+
const branch = result == null ? void 0 : result._;
|
|
2884
|
+
const clientId = result == null ? void 0 : result.clientId;
|
|
2885
|
+
if (!branch || !clientId) {
|
|
2886
|
+
throw new Error(`Invalid URL format provided. Expected: https://content.tinajs.io/content/<ClientID>/github/<Branch> but but received ${url}`);
|
|
2887
|
+
}
|
|
2888
|
+
if (params.host !== TINA_HOST) {
|
|
2889
|
+
throw new Error(`The only supported hosts are ${TINA_HOST} or localhost, but received ${params.host}.`);
|
|
2890
|
+
}
|
|
2891
|
+
return {
|
|
2892
|
+
branch,
|
|
2893
|
+
clientId,
|
|
2894
|
+
isLocalClient: false
|
|
2895
|
+
};
|
|
2896
|
+
};
|
|
3136
2897
|
const errorButtonStyles = {
|
|
3137
2898
|
background: "#eb6337",
|
|
3138
2899
|
padding: "12px 18px",
|
|
@@ -3212,21 +2973,6 @@ class ErrorBoundary extends React.Component {
|
|
|
3212
2973
|
return this.props.children;
|
|
3213
2974
|
}
|
|
3214
2975
|
}
|
|
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
2976
|
const TinaCMSProvider2 = (_c) => {
|
|
3231
2977
|
var _d = _c, {
|
|
3232
2978
|
query,
|
|
@@ -3248,6 +2994,9 @@ const TinaCMSProvider2 = (_c) => {
|
|
|
3248
2994
|
clientId: props.clientId,
|
|
3249
2995
|
isLocalClient: props.isLocalClient
|
|
3250
2996
|
};
|
|
2997
|
+
if (!schema) {
|
|
2998
|
+
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");
|
|
2999
|
+
}
|
|
3251
3000
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TinaCloudProvider, {
|
|
3252
3001
|
branch,
|
|
3253
3002
|
clientId,
|
|
@@ -3297,25 +3046,13 @@ const TinaDataProvider = ({
|
|
|
3297
3046
|
payload: void 0,
|
|
3298
3047
|
isLoading: true
|
|
3299
3048
|
});
|
|
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
3049
|
return /* @__PURE__ */ React.createElement(TinaDataContext.Provider, {
|
|
3308
3050
|
value: {
|
|
3309
3051
|
setRequest,
|
|
3310
3052
|
isLoading: state.isLoading,
|
|
3311
3053
|
state: { payload: state.payload }
|
|
3312
3054
|
}
|
|
3313
|
-
},
|
|
3314
|
-
key: request == null ? void 0 : request.query,
|
|
3315
|
-
request,
|
|
3316
|
-
formifyCallback,
|
|
3317
|
-
onPayloadStateChange: setState
|
|
3318
|
-
}) : /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3055
|
+
}, /* @__PURE__ */ React.createElement(FormRegistrar, {
|
|
3319
3056
|
key: request == null ? void 0 : request.query,
|
|
3320
3057
|
request,
|
|
3321
3058
|
formifyCallback,
|
|
@@ -3344,35 +3081,6 @@ const FormRegistrar = ({
|
|
|
3344
3081
|
}, [JSON.stringify(payload), isLoading]);
|
|
3345
3082
|
return isLoading ? /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement(React.Fragment, null)) : null;
|
|
3346
3083
|
};
|
|
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
3084
|
const Loader = (props) => {
|
|
3377
3085
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
3378
3086
|
style: {
|
|
@@ -3617,8 +3325,8 @@ const useGetCollections = (cms) => {
|
|
|
3617
3325
|
const fetchCollections = async () => {
|
|
3618
3326
|
if (await api.isAuthenticated()) {
|
|
3619
3327
|
try {
|
|
3620
|
-
const
|
|
3621
|
-
setCollections(
|
|
3328
|
+
const collections2 = await api.fetchCollections();
|
|
3329
|
+
setCollections(collections2);
|
|
3622
3330
|
} catch (error2) {
|
|
3623
3331
|
console.error(error2);
|
|
3624
3332
|
setCollections([]);
|
|
@@ -3921,8 +3629,8 @@ const useGetCollection = (cms, collectionName, includeDocuments = true) => {
|
|
|
3921
3629
|
const fetchCollection = async () => {
|
|
3922
3630
|
if (await api.isAuthenticated()) {
|
|
3923
3631
|
try {
|
|
3924
|
-
const
|
|
3925
|
-
setCollection(
|
|
3632
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments);
|
|
3633
|
+
setCollection(collection2);
|
|
3926
3634
|
} catch (error2) {
|
|
3927
3635
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
3928
3636
|
console.error(error2);
|
|
@@ -3988,7 +3696,7 @@ const handleNavigate = (navigate, cms, collection, document) => {
|
|
|
3988
3696
|
window.location.href = routeOverride;
|
|
3989
3697
|
return null;
|
|
3990
3698
|
} else {
|
|
3991
|
-
navigate(document.
|
|
3699
|
+
navigate(document._sys.breadcrumbs.join("/"));
|
|
3992
3700
|
}
|
|
3993
3701
|
};
|
|
3994
3702
|
const CollectionListPage = () => {
|
|
@@ -4041,9 +3749,9 @@ const CollectionListPage = () => {
|
|
|
4041
3749
|
}, /* @__PURE__ */ React.createElement("tbody", {
|
|
4042
3750
|
className: "divide-y divide-gray-150"
|
|
4043
3751
|
}, documents.map((document) => {
|
|
4044
|
-
const subfolders = document.node.
|
|
3752
|
+
const subfolders = document.node._sys.breadcrumbs.slice(0, -1).join("/");
|
|
4045
3753
|
return /* @__PURE__ */ React.createElement("tr", {
|
|
4046
|
-
key: `document-${document.node.
|
|
3754
|
+
key: `document-${document.node._sys.relativePath}`,
|
|
4047
3755
|
className: ""
|
|
4048
3756
|
}, /* @__PURE__ */ React.createElement("td", {
|
|
4049
3757
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -4060,22 +3768,21 @@ const CollectionListPage = () => {
|
|
|
4060
3768
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
4061
3769
|
}, subfolders && /* @__PURE__ */ React.createElement("span", {
|
|
4062
3770
|
className: "text-xs text-gray-400"
|
|
4063
|
-
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node.
|
|
3771
|
+
}, `${subfolders}/`), /* @__PURE__ */ React.createElement("span", null, document.node._sys.filename))))), /* @__PURE__ */ React.createElement("td", {
|
|
4064
3772
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4065
3773
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4066
3774
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4067
3775
|
}, "Extension"), /* @__PURE__ */ React.createElement("span", {
|
|
4068
3776
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4069
|
-
}, document.node.
|
|
3777
|
+
}, document.node._sys.extension)), /* @__PURE__ */ React.createElement("td", {
|
|
4070
3778
|
className: "px-6 py-4 whitespace-nowrap"
|
|
4071
3779
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
4072
3780
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
4073
3781
|
}, "Template"), /* @__PURE__ */ React.createElement("span", {
|
|
4074
3782
|
className: "h-5 leading-5 block text-sm font-medium text-gray-900"
|
|
4075
|
-
}, document.node.
|
|
3783
|
+
}, document.node._sys.template)), /* @__PURE__ */ React.createElement("td", {
|
|
4076
3784
|
className: "w-0"
|
|
4077
3785
|
}, /* @__PURE__ */ React.createElement(OverflowMenu, {
|
|
4078
|
-
showEmbed: true,
|
|
4079
3786
|
toolbarItems: [
|
|
4080
3787
|
{
|
|
4081
3788
|
name: "edit",
|
|
@@ -4084,7 +3791,7 @@ const CollectionListPage = () => {
|
|
|
4084
3791
|
size: "1.3rem"
|
|
4085
3792
|
}),
|
|
4086
3793
|
onMouseDown: () => {
|
|
4087
|
-
navigate(`${document.node.
|
|
3794
|
+
navigate(`${document.node._sys.filename}`, { replace: true });
|
|
4088
3795
|
}
|
|
4089
3796
|
},
|
|
4090
3797
|
{
|
|
@@ -4097,7 +3804,7 @@ const CollectionListPage = () => {
|
|
|
4097
3804
|
onMouseDown: () => {
|
|
4098
3805
|
setVars({
|
|
4099
3806
|
collection: collectionName,
|
|
4100
|
-
relativePath: document.node.
|
|
3807
|
+
relativePath: document.node._sys.filename + document.node._sys.extension
|
|
4101
3808
|
});
|
|
4102
3809
|
setOpen(true);
|
|
4103
3810
|
}
|
|
@@ -4111,7 +3818,7 @@ const CollectionListPage = () => {
|
|
|
4111
3818
|
const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
4112
3819
|
return /* @__PURE__ */ React.createElement(Modal, null, /* @__PURE__ */ React.createElement(ModalPopup, null, /* @__PURE__ */ React.createElement(ModalHeader, {
|
|
4113
3820
|
close: close2
|
|
4114
|
-
}, "
|
|
3821
|
+
}, "Delete ", filename), /* @__PURE__ */ React.createElement(ModalBody, {
|
|
4115
3822
|
padded: true
|
|
4116
3823
|
}, /* @__PURE__ */ React.createElement("p", null, `Are you sure you want to delete ${filename}?`)), /* @__PURE__ */ React.createElement(ModalActions, null, /* @__PURE__ */ React.createElement(Button, {
|
|
4117
3824
|
style: { flexGrow: 2 },
|
|
@@ -4125,72 +3832,6 @@ const DeleteModal = ({ close: close2, deleteFunc, filename }) => {
|
|
|
4125
3832
|
}
|
|
4126
3833
|
}, "Delete"))));
|
|
4127
3834
|
};
|
|
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
3835
|
function HiChevronRight(props) {
|
|
4195
3836
|
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
3837
|
}
|
|
@@ -4216,38 +3857,39 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
|
|
|
4216
3857
|
};
|
|
4217
3858
|
const CollectionCreatePage = () => {
|
|
4218
3859
|
const { collectionName, templateName } = useParams();
|
|
4219
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
3860
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4220
3861
|
cms,
|
|
4221
3862
|
collectionName,
|
|
4222
|
-
|
|
4223
|
-
}, (
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
3863
|
+
includeDocuments: false
|
|
3864
|
+
}, (collection) => {
|
|
3865
|
+
const mutationInfo = {
|
|
3866
|
+
includeCollection: true,
|
|
3867
|
+
includeTemplate: !!collection.templates
|
|
3868
|
+
};
|
|
3869
|
+
return /* @__PURE__ */ React.createElement(RenderForm$1, {
|
|
3870
|
+
cms,
|
|
3871
|
+
collection,
|
|
3872
|
+
templateName,
|
|
3873
|
+
mutationInfo
|
|
3874
|
+
});
|
|
3875
|
+
}));
|
|
4230
3876
|
};
|
|
4231
|
-
const RenderForm$1 = ({ cms, collection,
|
|
3877
|
+
const RenderForm$1 = ({ cms, collection, templateName, mutationInfo }) => {
|
|
4232
3878
|
var _a, _b;
|
|
4233
3879
|
const navigate = useNavigate();
|
|
4234
3880
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4235
3881
|
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
|
-
}
|
|
3882
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
3883
|
+
const template = schema.getTemplateForData({
|
|
3884
|
+
collection: schemaCollection,
|
|
3885
|
+
data: { _template: templateName }
|
|
3886
|
+
});
|
|
3887
|
+
const formInfo = resolveForm({
|
|
3888
|
+
collection: schemaCollection,
|
|
3889
|
+
basename: schemaCollection.name,
|
|
3890
|
+
schema,
|
|
3891
|
+
template
|
|
3892
|
+
});
|
|
4251
3893
|
const form = useMemo(() => {
|
|
4252
3894
|
return new Form({
|
|
4253
3895
|
id: "create-form",
|
|
@@ -4272,7 +3914,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4272
3914
|
}
|
|
4273
3915
|
}
|
|
4274
3916
|
},
|
|
4275
|
-
...
|
|
3917
|
+
...formInfo.fields
|
|
4276
3918
|
],
|
|
4277
3919
|
onSubmit: async (values) => {
|
|
4278
3920
|
try {
|
|
@@ -4285,7 +3927,7 @@ const RenderForm$1 = ({ cms, collection, template, fields, mutationInfo }) => {
|
|
|
4285
3927
|
}
|
|
4286
3928
|
}
|
|
4287
3929
|
});
|
|
4288
|
-
}, [cms, collection,
|
|
3930
|
+
}, [cms, collection, mutationInfo]);
|
|
4289
3931
|
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
3932
|
className: "py-4 px-20 border-b border-gray-200 bg-white"
|
|
4291
3933
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
@@ -4318,7 +3960,7 @@ const useGetDocument = (cms, collectionName, relativePath) => {
|
|
|
4318
3960
|
if (api.isAuthenticated()) {
|
|
4319
3961
|
try {
|
|
4320
3962
|
const response = await api.fetchDocument(collectionName, relativePath);
|
|
4321
|
-
setDocument(response.
|
|
3963
|
+
setDocument(response.document);
|
|
4322
3964
|
} catch (error2) {
|
|
4323
3965
|
cms.alerts.error(`[${error2.name}] GetDocument failed: ${error2.message}`, 30 * 1e3);
|
|
4324
3966
|
console.error(error2);
|
|
@@ -4367,11 +4009,16 @@ const updateDocument = async (cms, relativePath, collection, mutationInfo, value
|
|
|
4367
4009
|
const CollectionUpdatePage = () => {
|
|
4368
4010
|
const _a = useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4369
4011
|
const { "*": filename } = rest;
|
|
4370
|
-
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(
|
|
4012
|
+
return /* @__PURE__ */ React.createElement(GetCMS, null, (cms) => /* @__PURE__ */ React.createElement(GetCollection, {
|
|
4371
4013
|
cms,
|
|
4372
|
-
collectionName
|
|
4373
|
-
|
|
4014
|
+
collectionName,
|
|
4015
|
+
includeDocuments: false
|
|
4016
|
+
}, (collection) => {
|
|
4374
4017
|
const relativePath = `${filename}.${collection.format}`;
|
|
4018
|
+
const mutationInfo = {
|
|
4019
|
+
includeCollection: true,
|
|
4020
|
+
includeTemplate: !!collection.templates
|
|
4021
|
+
};
|
|
4375
4022
|
return /* @__PURE__ */ React.createElement(GetDocument, {
|
|
4376
4023
|
cms,
|
|
4377
4024
|
collectionName: collection.name,
|
|
@@ -4397,27 +4044,23 @@ const RenderForm = ({
|
|
|
4397
4044
|
var _a, _b;
|
|
4398
4045
|
const [formIsPristine, setFormIsPristine] = useState(true);
|
|
4399
4046
|
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
|
-
}
|
|
4047
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
4048
|
+
const template = schema.getTemplateForData({
|
|
4049
|
+
collection: schemaCollection,
|
|
4050
|
+
data: document._values
|
|
4051
|
+
});
|
|
4052
|
+
const formInfo = resolveForm({
|
|
4053
|
+
collection: schemaCollection,
|
|
4054
|
+
basename: schemaCollection.name,
|
|
4055
|
+
schema,
|
|
4056
|
+
template
|
|
4057
|
+
});
|
|
4415
4058
|
const form = useMemo(() => {
|
|
4416
4059
|
return new Form({
|
|
4417
4060
|
id: "update-form",
|
|
4418
4061
|
label: "form",
|
|
4419
|
-
fields:
|
|
4420
|
-
initialValues: document.
|
|
4062
|
+
fields: formInfo.fields,
|
|
4063
|
+
initialValues: document._values,
|
|
4421
4064
|
onSubmit: async (values) => {
|
|
4422
4065
|
try {
|
|
4423
4066
|
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
@@ -4537,4 +4180,4 @@ const defineSchema = (config) => {
|
|
|
4537
4180
|
const defineConfig = (config) => {
|
|
4538
4181
|
return config;
|
|
4539
4182
|
};
|
|
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,
|
|
4183
|
+
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 };
|