tinacms 0.66.9 → 0.66.10
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 +58 -0
- package/dist/client/index.d.ts +5 -1
- package/dist/hooks/formify/formify-utils.d.ts +89 -0
- package/dist/hooks/formify/reducer.d.ts +1 -0
- package/dist/hooks/formify/{test → spec}/runner.d.ts +1 -1
- package/dist/hooks/formify/{test → spec}/util.d.ts +0 -0
- package/dist/hooks/formify/types.d.ts +11 -4
- package/dist/hooks/formify/util.d.ts +61 -73
- package/dist/hooks/use-graphql-forms.d.ts +2 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.es.js +595 -479
- package/dist/index.js +593 -478
- package/dist/rich-text.d.ts +1 -0
- package/dist/rich-text.es.js +10 -0
- package/dist/rich-text.js +10 -0
- package/dist/tina-cms.d.ts +3 -1
- package/dist/utils/index.d.ts +3 -1
- package/package.json +4 -3
- package/dist/types/SchemaTypes.d.ts +0 -258
- package/dist/types/index.d.ts +0 -18
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
(function(global, factory) {
|
|
33
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@tinacms/toolkit"), require("graphql"), require("lodash.set"), require("react"), require("final-form"), require("
|
|
34
|
-
})(this, function(exports2, toolkit, G, set, React, finalForm,
|
|
33
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@tinacms/toolkit"), require("graphql"), require("lodash.set"), require("react"), require("final-form"), require("@tinacms/schema-tools"), require("graphql-tag"), require("yup"), require("styled-components"), require("@tinacms/sharedctx"), require("url-pattern"), require("react-router-dom"), require("@headlessui/react")) : typeof define === "function" && define.amd ? define(["exports", "@tinacms/toolkit", "graphql", "lodash.set", "react", "final-form", "@tinacms/schema-tools", "graphql-tag", "yup", "styled-components", "@tinacms/sharedctx", "url-pattern", "react-router-dom", "@headlessui/react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP, global.NOOP));
|
|
34
|
+
})(this, function(exports2, toolkit, G, set, React, finalForm, schemaTools, gql$1, yup, styled, sharedctx, UrlPattern, reactRouterDom, react) {
|
|
35
35
|
"use strict";
|
|
36
36
|
function _interopDefaultLegacy(e) {
|
|
37
37
|
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
@@ -59,8 +59,8 @@ var __objRest = (source, exclude) => {
|
|
|
59
59
|
var G__namespace = /* @__PURE__ */ _interopNamespace(G);
|
|
60
60
|
var set__default = /* @__PURE__ */ _interopDefaultLegacy(set);
|
|
61
61
|
var React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
|
|
62
|
-
var yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
63
62
|
var gql__default = /* @__PURE__ */ _interopDefaultLegacy(gql$1);
|
|
63
|
+
var yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
64
64
|
var styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
|
|
65
65
|
var UrlPattern__default = /* @__PURE__ */ _interopDefaultLegacy(UrlPattern);
|
|
66
66
|
function popupWindow(url, title, window2, w, h) {
|
|
@@ -400,13 +400,15 @@ var __objRest = (source, exclude) => {
|
|
|
400
400
|
clientId,
|
|
401
401
|
isLocalClient = true,
|
|
402
402
|
branch,
|
|
403
|
-
tinaioConfig
|
|
403
|
+
tinaioConfig,
|
|
404
|
+
schema
|
|
404
405
|
}) => {
|
|
405
|
-
return isLocalClient ? new LocalClient() : new Client({
|
|
406
|
+
return isLocalClient ? new LocalClient({ schema }) : new Client({
|
|
406
407
|
clientId: clientId || "",
|
|
407
408
|
branch: branch || "main",
|
|
408
409
|
tokenStorage: "LOCAL_STORAGE",
|
|
409
|
-
tinaioConfig
|
|
410
|
+
tinaioConfig,
|
|
411
|
+
schema
|
|
410
412
|
});
|
|
411
413
|
};
|
|
412
414
|
function assertShape(value, yupSchema, errorMessage) {
|
|
@@ -535,11 +537,10 @@ var __objRest = (source, exclude) => {
|
|
|
535
537
|
values: yup2.object().required(),
|
|
536
538
|
form: yup2.object().required()
|
|
537
539
|
}), `Unable to build form shape for fields at ${queryName}`);
|
|
538
|
-
|
|
540
|
+
let formConfig = {};
|
|
541
|
+
const formCommon = {
|
|
539
542
|
id: queryName,
|
|
540
|
-
label: result.form.label,
|
|
541
543
|
initialValues: result.values,
|
|
542
|
-
fields: result.form.fields,
|
|
543
544
|
reset: () => {
|
|
544
545
|
setPendingReset(queryName);
|
|
545
546
|
},
|
|
@@ -571,6 +572,29 @@ var __objRest = (source, exclude) => {
|
|
|
571
572
|
}
|
|
572
573
|
}
|
|
573
574
|
};
|
|
575
|
+
if (cms.api.tina.schema) {
|
|
576
|
+
const enrichedSchema = cms.api.tina.schema;
|
|
577
|
+
const collection = enrichedSchema.getCollection(result._internalSys.collection.name);
|
|
578
|
+
const template = enrichedSchema.getTemplateForData({
|
|
579
|
+
collection,
|
|
580
|
+
data: result.values
|
|
581
|
+
});
|
|
582
|
+
const formInfo = schemaTools.resolveForm({
|
|
583
|
+
collection,
|
|
584
|
+
basename: collection.name,
|
|
585
|
+
schema: enrichedSchema,
|
|
586
|
+
template
|
|
587
|
+
});
|
|
588
|
+
formConfig = __spreadValues({
|
|
589
|
+
label: formInfo.label,
|
|
590
|
+
fields: formInfo.fields
|
|
591
|
+
}, formCommon);
|
|
592
|
+
} else {
|
|
593
|
+
formConfig = __spreadValues({
|
|
594
|
+
label: result.form.label,
|
|
595
|
+
fields: result.form.fields
|
|
596
|
+
}, formCommon);
|
|
597
|
+
}
|
|
574
598
|
const { createForm, createGlobalForm } = generateFormCreators(cms);
|
|
575
599
|
const SKIPPED = "SKIPPED";
|
|
576
600
|
let form;
|
|
@@ -742,100 +766,7 @@ var __objRest = (source, exclude) => {
|
|
|
742
766
|
};
|
|
743
767
|
return { createForm, createGlobalForm };
|
|
744
768
|
};
|
|
745
|
-
const
|
|
746
|
-
if (G__namespace.isUnionType(type)) {
|
|
747
|
-
return type.getTypes().every((type2) => {
|
|
748
|
-
return type2.getInterfaces().find((intfc) => intfc.name === "Node");
|
|
749
|
-
});
|
|
750
|
-
} else if (G__namespace.isObjectType(type)) {
|
|
751
|
-
return !!type.getInterfaces().find((intfc) => intfc.name === "Node");
|
|
752
|
-
} else if (G__namespace.isInterfaceType(type)) {
|
|
753
|
-
if (type.name === "Node") {
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
} else {
|
|
757
|
-
return false;
|
|
758
|
-
}
|
|
759
|
-
};
|
|
760
|
-
const isConnectionField = (type) => {
|
|
761
|
-
if (G__namespace.isObjectType(type)) {
|
|
762
|
-
return !!type.getInterfaces().find((intfc) => intfc.name === "Connection");
|
|
763
|
-
} else {
|
|
764
|
-
throw new Error(`Expected GraphQLObjectType for isConnectionField check`);
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
const getObjectField = (object, selectionNode) => {
|
|
768
|
-
return object.getFields()[selectionNode.name.value];
|
|
769
|
-
};
|
|
770
|
-
const getSelectedUnionType = (unionType, selectionNode) => {
|
|
771
|
-
return unionType.getTypes().find((type) => type.name === selectionNode.typeCondition.name.value);
|
|
772
|
-
};
|
|
773
|
-
function isListType(type) {
|
|
774
|
-
if (G__namespace.isListType(type)) {
|
|
775
|
-
return true;
|
|
776
|
-
} else if (G__namespace.isNonNullType(type)) {
|
|
777
|
-
if (G__namespace.isListType(type.ofType)) {
|
|
778
|
-
return true;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return false;
|
|
782
|
-
}
|
|
783
|
-
function ensureNodeField(field) {
|
|
784
|
-
if (!isNodeField(field)) {
|
|
785
|
-
throw new Error(`Expected field to implement Node interface`);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
function ensureUnionType(type) {
|
|
789
|
-
if (!G__namespace.isUnionType(type)) {
|
|
790
|
-
throw new Error(`Expected type to be GraphQLUnionType`);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
function ensureObjectType(type) {
|
|
794
|
-
if (!G__namespace.isObjectType(type)) {
|
|
795
|
-
console.log(type);
|
|
796
|
-
throw new Error(`Expected type to be GraphQLObjectType`);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
function ensureOperationDefinition(type) {
|
|
800
|
-
if (type.kind !== "OperationDefinition") {
|
|
801
|
-
throw new Error(`Expected top-level definition to be an OperationDefinition node, ensure your query has been optimized before calling formify`);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
function getNameAndAlias(fieldNode, list, isNode) {
|
|
805
|
-
return {
|
|
806
|
-
name: fieldNode.name.value,
|
|
807
|
-
alias: fieldNode.alias ? fieldNode.alias.value : fieldNode.name.value,
|
|
808
|
-
list: !!list,
|
|
809
|
-
isNode: !!isNode
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
const node = G__namespace.parse(`
|
|
813
|
-
query Sample {
|
|
814
|
-
_internalSys: sys {
|
|
815
|
-
path
|
|
816
|
-
collection {
|
|
817
|
-
name
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
form
|
|
821
|
-
values
|
|
822
|
-
}`);
|
|
823
|
-
const metaFields = node.definitions[0].selectionSet.selections;
|
|
824
|
-
const getRelativeBlueprint = (path) => {
|
|
825
|
-
let indexOfLastNode = 0;
|
|
826
|
-
path.forEach((item, i) => {
|
|
827
|
-
if (item.isNode) {
|
|
828
|
-
if (i === path.length - 1)
|
|
829
|
-
;
|
|
830
|
-
else {
|
|
831
|
-
indexOfLastNode = i;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
|
|
836
|
-
return getBlueprintNamePath({ path: documentBlueprintPath });
|
|
837
|
-
};
|
|
838
|
-
const getIn2 = (state, path) => {
|
|
769
|
+
const getValueForBlueprint = (state, path) => {
|
|
839
770
|
const pathArray = path.split(".");
|
|
840
771
|
let latest = state;
|
|
841
772
|
pathArray.every((item, index) => {
|
|
@@ -845,7 +776,7 @@ var __objRest = (source, exclude) => {
|
|
|
845
776
|
const next = [];
|
|
846
777
|
if (Array.isArray(latest)) {
|
|
847
778
|
latest.forEach((latest2, index2) => {
|
|
848
|
-
const res =
|
|
779
|
+
const res = getValueForBlueprint(latest2, restOfItems.join("."));
|
|
849
780
|
next.push(res);
|
|
850
781
|
});
|
|
851
782
|
} else {
|
|
@@ -912,9 +843,8 @@ var __objRest = (source, exclude) => {
|
|
|
912
843
|
if (skipped)
|
|
913
844
|
return;
|
|
914
845
|
const id = doc._internalSys.path;
|
|
915
|
-
const
|
|
916
|
-
id
|
|
917
|
-
}, doc.form), {
|
|
846
|
+
const formCommon = {
|
|
847
|
+
id,
|
|
918
848
|
label: doc.form.label,
|
|
919
849
|
initialValues: doc.values,
|
|
920
850
|
onSubmit: async (payload) => {
|
|
@@ -944,7 +874,31 @@ var __objRest = (source, exclude) => {
|
|
|
944
874
|
cms.alerts.error("There was a problem saving your document");
|
|
945
875
|
}
|
|
946
876
|
}
|
|
947
|
-
}
|
|
877
|
+
};
|
|
878
|
+
let formConfig = {};
|
|
879
|
+
if (cms.api.tina.schema) {
|
|
880
|
+
const enrichedSchema = cms.api.tina.schema;
|
|
881
|
+
const collection = enrichedSchema.getCollection(doc._internalSys.collection.name);
|
|
882
|
+
const template = enrichedSchema.getTemplateForData({
|
|
883
|
+
collection,
|
|
884
|
+
data: doc.values
|
|
885
|
+
});
|
|
886
|
+
const formInfo = schemaTools.resolveForm({
|
|
887
|
+
collection,
|
|
888
|
+
basename: collection.name,
|
|
889
|
+
schema: enrichedSchema,
|
|
890
|
+
template
|
|
891
|
+
});
|
|
892
|
+
formConfig = __spreadValues({
|
|
893
|
+
label: formInfo.label,
|
|
894
|
+
fields: formInfo.fields
|
|
895
|
+
}, formCommon);
|
|
896
|
+
} else {
|
|
897
|
+
formConfig = __spreadValues({
|
|
898
|
+
label: doc.form.label,
|
|
899
|
+
fields: doc.form.fields
|
|
900
|
+
}, formCommon);
|
|
901
|
+
}
|
|
948
902
|
if (formify2) {
|
|
949
903
|
form = formify2({
|
|
950
904
|
formConfig,
|
|
@@ -990,19 +944,6 @@ var __objRest = (source, exclude) => {
|
|
|
990
944
|
}
|
|
991
945
|
return accum;
|
|
992
946
|
};
|
|
993
|
-
const getBlueprintId = (path) => {
|
|
994
|
-
const namePath = [];
|
|
995
|
-
const aliasPath = [];
|
|
996
|
-
path.forEach((p) => {
|
|
997
|
-
namePath.push(p.name);
|
|
998
|
-
aliasPath.push(p.alias);
|
|
999
|
-
if (p.list) {
|
|
1000
|
-
namePath.push("[]");
|
|
1001
|
-
aliasPath.push("[]");
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
return namePath.join(".");
|
|
1005
|
-
};
|
|
1006
947
|
const getFormNodesStartingWith = (string, state) => {
|
|
1007
948
|
return state.formNodes.filter((subFormNode) => {
|
|
1008
949
|
return subFormNode.documentBlueprintId.startsWith(string);
|
|
@@ -1018,44 +959,6 @@ var __objRest = (source, exclude) => {
|
|
|
1018
959
|
const existing = finalForm.getIn(state.data, pathToChange);
|
|
1019
960
|
return { pathToChange, formNodes, eventLocation, existing };
|
|
1020
961
|
};
|
|
1021
|
-
const matchLocation = (eventLocation, formNode) => {
|
|
1022
|
-
return eventLocation.every((item, index) => item === formNode.location[index]);
|
|
1023
|
-
};
|
|
1024
|
-
const bumpLocation = (location) => {
|
|
1025
|
-
return location.map((item, index) => {
|
|
1026
|
-
if (index === location.length - 1) {
|
|
1027
|
-
return item + 1;
|
|
1028
|
-
}
|
|
1029
|
-
return item;
|
|
1030
|
-
});
|
|
1031
|
-
};
|
|
1032
|
-
const maybeLowerLocation = (location, at) => {
|
|
1033
|
-
return location.map((item, index) => {
|
|
1034
|
-
if (index === location.length - 1) {
|
|
1035
|
-
return item < at ? item : item - 1;
|
|
1036
|
-
}
|
|
1037
|
-
return item;
|
|
1038
|
-
});
|
|
1039
|
-
};
|
|
1040
|
-
const matchesAt = (location, at) => {
|
|
1041
|
-
let matches = false;
|
|
1042
|
-
location.map((item, index) => {
|
|
1043
|
-
if (index === location.length - 1) {
|
|
1044
|
-
if (item === at) {
|
|
1045
|
-
matches = true;
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
return matches;
|
|
1050
|
-
};
|
|
1051
|
-
const swapLocation = (location, mapping) => {
|
|
1052
|
-
return location.map((item, index) => {
|
|
1053
|
-
if (index === location.length - 1) {
|
|
1054
|
-
return mapping[item];
|
|
1055
|
-
}
|
|
1056
|
-
return item;
|
|
1057
|
-
});
|
|
1058
|
-
};
|
|
1059
962
|
const getBlueprintAliasPath = (blueprint) => {
|
|
1060
963
|
const namePath = [];
|
|
1061
964
|
const aliasPath = [];
|
|
@@ -1071,22 +974,56 @@ var __objRest = (source, exclude) => {
|
|
|
1071
974
|
};
|
|
1072
975
|
const getBlueprintFieldsForEvent = (blueprint, event) => {
|
|
1073
976
|
return blueprint.fields.filter((fbp) => {
|
|
1074
|
-
|
|
977
|
+
if (getBlueprintNamePath(fbp) === getEventPath(event, blueprint)) {
|
|
978
|
+
return true;
|
|
979
|
+
}
|
|
980
|
+
}).filter((fbp) => {
|
|
981
|
+
return filterFieldBlueprintsByParentTypename(fbp, event.field.data.tinaField.parentTypename);
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
const filterFieldBlueprintsByParentTypename = (fbp, typename) => {
|
|
985
|
+
let lastDisambiguator;
|
|
986
|
+
fbp.path.forEach((path) => {
|
|
987
|
+
if (path.parentTypename) {
|
|
988
|
+
lastDisambiguator = path.parentTypename;
|
|
989
|
+
}
|
|
1075
990
|
});
|
|
991
|
+
if (lastDisambiguator) {
|
|
992
|
+
return typename === lastDisambiguator;
|
|
993
|
+
} else {
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
1076
996
|
};
|
|
1077
|
-
const getBlueprintNamePath = (blueprint) => {
|
|
997
|
+
const getBlueprintNamePath = (blueprint, disambiguator) => {
|
|
1078
998
|
const namePath = [];
|
|
1079
|
-
const aliasPath = [];
|
|
1080
999
|
blueprint.path.forEach((p) => {
|
|
1000
|
+
if (disambiguator) {
|
|
1001
|
+
if (p.parentTypename) {
|
|
1002
|
+
namePath.push(p.parentTypename);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1081
1005
|
namePath.push(p.name);
|
|
1082
|
-
aliasPath.push(p.alias);
|
|
1083
1006
|
if (p.list) {
|
|
1084
1007
|
namePath.push("[]");
|
|
1085
|
-
aliasPath.push("[]");
|
|
1086
1008
|
}
|
|
1087
1009
|
});
|
|
1088
1010
|
return namePath.join(".");
|
|
1089
1011
|
};
|
|
1012
|
+
const getEventPath = (event, blueprint) => {
|
|
1013
|
+
const stringArray = event.field.name.split(".");
|
|
1014
|
+
const eventPath = stringArray.map((item) => {
|
|
1015
|
+
if (isNaN(Number(item))) {
|
|
1016
|
+
return item;
|
|
1017
|
+
}
|
|
1018
|
+
return `[]`;
|
|
1019
|
+
}).join(".");
|
|
1020
|
+
const items = [blueprint.id, DATA_NODE_NAME$1, eventPath];
|
|
1021
|
+
const isList = event.field.data.tinaField.list;
|
|
1022
|
+
if (isList && !eventPath.endsWith("[]")) {
|
|
1023
|
+
items.push(`[]`);
|
|
1024
|
+
}
|
|
1025
|
+
return items.join(".");
|
|
1026
|
+
};
|
|
1090
1027
|
const stripIndices = (string) => {
|
|
1091
1028
|
const accum = [];
|
|
1092
1029
|
const stringArray = string.split(".");
|
|
@@ -1108,20 +1045,21 @@ var __objRest = (source, exclude) => {
|
|
|
1108
1045
|
return "[]";
|
|
1109
1046
|
}).join(".");
|
|
1110
1047
|
};
|
|
1048
|
+
const getMatchName = ({ field, prefix, blueprint }) => {
|
|
1049
|
+
const fieldName = field.list ? `${field.name}.[]` : field.name;
|
|
1050
|
+
const blueprintName = getBlueprintNamePath(blueprint);
|
|
1051
|
+
const extra = [];
|
|
1052
|
+
if (prefix) {
|
|
1053
|
+
extra.push(prefix);
|
|
1054
|
+
}
|
|
1055
|
+
const matchName = [blueprintName, DATA_NODE_NAME$1, ...extra, fieldName].join(".");
|
|
1056
|
+
return { matchName, fieldName };
|
|
1057
|
+
};
|
|
1111
1058
|
const getFormNodesFromEvent = (state, event) => {
|
|
1112
1059
|
const formNodes = state.formNodes.filter((formNode) => formNode.documentFormId === event.formId);
|
|
1113
1060
|
return formNodes;
|
|
1114
1061
|
};
|
|
1115
1062
|
const DATA_NODE_NAME$1 = "data";
|
|
1116
|
-
const getEventPath = (event, blueprint) => {
|
|
1117
|
-
const eventPath = replaceRealNum(event.field.name);
|
|
1118
|
-
const items = [blueprint.id, DATA_NODE_NAME$1, eventPath];
|
|
1119
|
-
const isList = event.field.data.tinaField.list;
|
|
1120
|
-
if (isList && !eventPath.endsWith("[]")) {
|
|
1121
|
-
items.push("[]");
|
|
1122
|
-
}
|
|
1123
|
-
return items.join(".");
|
|
1124
|
-
};
|
|
1125
1063
|
const printEvent = (event) => {
|
|
1126
1064
|
var _a, _b;
|
|
1127
1065
|
return {
|
|
@@ -1190,17 +1128,43 @@ var __objRest = (source, exclude) => {
|
|
|
1190
1128
|
}
|
|
1191
1129
|
return newOrderObject;
|
|
1192
1130
|
};
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1131
|
+
const matchLocation = (eventLocation, formNode) => {
|
|
1132
|
+
return eventLocation.every((item, index) => item === formNode.location[index]);
|
|
1133
|
+
};
|
|
1134
|
+
const bumpLocation = (location) => {
|
|
1135
|
+
return location.map((item, index) => {
|
|
1136
|
+
if (index === location.length - 1) {
|
|
1137
|
+
return item + 1;
|
|
1138
|
+
}
|
|
1139
|
+
return item;
|
|
1140
|
+
});
|
|
1141
|
+
};
|
|
1142
|
+
const maybeLowerLocation = (location, at) => {
|
|
1143
|
+
return location.map((item, index) => {
|
|
1144
|
+
if (index === location.length - 1) {
|
|
1145
|
+
return item < at ? item : item - 1;
|
|
1146
|
+
}
|
|
1147
|
+
return item;
|
|
1148
|
+
});
|
|
1149
|
+
};
|
|
1150
|
+
const matchesAt = (location, at) => {
|
|
1151
|
+
let matches = false;
|
|
1152
|
+
location.map((item, index) => {
|
|
1153
|
+
if (index === location.length - 1) {
|
|
1154
|
+
if (item === at) {
|
|
1155
|
+
matches = true;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
return matches;
|
|
1160
|
+
};
|
|
1161
|
+
const swapLocation = (location, mapping) => {
|
|
1162
|
+
return location.map((item, index) => {
|
|
1163
|
+
if (index === location.length - 1) {
|
|
1164
|
+
return mapping[item];
|
|
1165
|
+
}
|
|
1166
|
+
return item;
|
|
1202
1167
|
});
|
|
1203
|
-
return pathsToChange;
|
|
1204
1168
|
};
|
|
1205
1169
|
const getSubFields = (changeSet) => {
|
|
1206
1170
|
var _a;
|
|
@@ -1211,6 +1175,133 @@ var __objRest = (source, exclude) => {
|
|
|
1211
1175
|
}
|
|
1212
1176
|
return { fields, __typename };
|
|
1213
1177
|
};
|
|
1178
|
+
const isFormifiableDocument = (t) => {
|
|
1179
|
+
const type = G__namespace.getNamedType(t);
|
|
1180
|
+
if (G__namespace.isUnionType(type)) {
|
|
1181
|
+
return type.getTypes().every((type2) => {
|
|
1182
|
+
return type2.getInterfaces().find((intfc) => intfc.name === "Node");
|
|
1183
|
+
});
|
|
1184
|
+
} else if (G__namespace.isObjectType(type)) {
|
|
1185
|
+
return !!type.getInterfaces().find((intfc) => intfc.name === "Node");
|
|
1186
|
+
} else {
|
|
1187
|
+
return false;
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
const isScalarType = (t) => {
|
|
1191
|
+
const namedType = G__namespace.getNamedType(t);
|
|
1192
|
+
return G__namespace.isScalarType(namedType);
|
|
1193
|
+
};
|
|
1194
|
+
const isConnectionField = (t) => {
|
|
1195
|
+
const type = G__namespace.getNamedType(t);
|
|
1196
|
+
if (G__namespace.isObjectType(type)) {
|
|
1197
|
+
return !!type.getInterfaces().find((intfc) => intfc.name === "Connection");
|
|
1198
|
+
} else {
|
|
1199
|
+
throw new Error(`Expected GraphQLObjectType for isConnectionField check`);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
const getObjectField = (object, selectionNode) => {
|
|
1203
|
+
const namedType = G__namespace.getNamedType(object);
|
|
1204
|
+
ensureObjectOrInterfaceType(namedType);
|
|
1205
|
+
return namedType.getFields()[selectionNode.name.value];
|
|
1206
|
+
};
|
|
1207
|
+
const getSelectedUnionType = (unionType, selectionNode) => {
|
|
1208
|
+
const namedType = G__namespace.getNamedType(unionType);
|
|
1209
|
+
if (!G__namespace.isUnionType(namedType)) {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const types = namedType.getTypes();
|
|
1213
|
+
const typeCondition = selectionNode.typeCondition.name.value;
|
|
1214
|
+
let intfc;
|
|
1215
|
+
types.forEach((type) => {
|
|
1216
|
+
intfc = type.getInterfaces().find((intfc2) => intfc2.name === typeCondition);
|
|
1217
|
+
});
|
|
1218
|
+
if (intfc) {
|
|
1219
|
+
return intfc;
|
|
1220
|
+
}
|
|
1221
|
+
return namedType.getTypes().find((type) => type.name === typeCondition);
|
|
1222
|
+
};
|
|
1223
|
+
function isListType(type) {
|
|
1224
|
+
if (G__namespace.isListType(type)) {
|
|
1225
|
+
return true;
|
|
1226
|
+
} else if (G__namespace.isNonNullType(type)) {
|
|
1227
|
+
if (G__namespace.isListType(type.ofType)) {
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
function ensureObjectOrInterfaceType(type) {
|
|
1234
|
+
if (G__namespace.isInterfaceType(type) || G__namespace.isObjectType(type))
|
|
1235
|
+
;
|
|
1236
|
+
else {
|
|
1237
|
+
console.log("Expected type to be GraphQLObjectType or GraphQLInterfaceType", type);
|
|
1238
|
+
throw new Error(`Expected type to be GraphQLObjectType or GraphQLInterfaceType`);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function ensureOperationDefinition(type) {
|
|
1242
|
+
if (type.kind !== "OperationDefinition") {
|
|
1243
|
+
throw new Error(`Expected top-level definition to be an OperationDefinition node, ensure your query has been optimized before calling formify`);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
function buildPath({
|
|
1247
|
+
fieldNode,
|
|
1248
|
+
type,
|
|
1249
|
+
parentTypename,
|
|
1250
|
+
path
|
|
1251
|
+
}) {
|
|
1252
|
+
const p = path || [];
|
|
1253
|
+
const list = isListType(type);
|
|
1254
|
+
const isNode = isFormifiableDocument(type);
|
|
1255
|
+
return [
|
|
1256
|
+
...p,
|
|
1257
|
+
{
|
|
1258
|
+
name: fieldNode.name.value,
|
|
1259
|
+
alias: fieldNode.alias ? fieldNode.alias.value : fieldNode.name.value,
|
|
1260
|
+
parentTypename,
|
|
1261
|
+
list: !!list,
|
|
1262
|
+
isNode: !!isNode
|
|
1263
|
+
}
|
|
1264
|
+
];
|
|
1265
|
+
}
|
|
1266
|
+
const node = G__namespace.parse(`
|
|
1267
|
+
query Sample {
|
|
1268
|
+
_internalSys: sys {
|
|
1269
|
+
path
|
|
1270
|
+
collection {
|
|
1271
|
+
name
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
form
|
|
1275
|
+
values
|
|
1276
|
+
}`);
|
|
1277
|
+
const metaFields = node.definitions[0].selectionSet.selections;
|
|
1278
|
+
const getRelativeBlueprint = (path) => {
|
|
1279
|
+
let indexOfLastNode = 0;
|
|
1280
|
+
path.forEach((item, i) => {
|
|
1281
|
+
if (item.isNode) {
|
|
1282
|
+
if (i === path.length - 1)
|
|
1283
|
+
;
|
|
1284
|
+
else {
|
|
1285
|
+
indexOfLastNode = i;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
const documentBlueprintPath = path.slice(0, indexOfLastNode + 1);
|
|
1290
|
+
return getBlueprintNamePath({ path: documentBlueprintPath });
|
|
1291
|
+
};
|
|
1292
|
+
const getBlueprintId = (path) => {
|
|
1293
|
+
const namePath = [];
|
|
1294
|
+
const aliasPath = [];
|
|
1295
|
+
path.forEach((p) => {
|
|
1296
|
+
namePath.push(p.name);
|
|
1297
|
+
aliasPath.push(p.alias);
|
|
1298
|
+
if (p.list) {
|
|
1299
|
+
namePath.push("[]");
|
|
1300
|
+
aliasPath.push("[]");
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
return namePath.join(".");
|
|
1304
|
+
};
|
|
1214
1305
|
const NOOP = "This is either an error or is not yet supported";
|
|
1215
1306
|
const UNEXPECTED = "Formify encountered an unexpected error, please contact support";
|
|
1216
1307
|
const EDGES_NODE_NAME = "edges";
|
|
@@ -1243,11 +1334,10 @@ var __objRest = (source, exclude) => {
|
|
|
1243
1334
|
const optimizedQuery = await getOptimizedQuery(documentNodeWithName);
|
|
1244
1335
|
const typeInfo = new G__namespace.TypeInfo(schema);
|
|
1245
1336
|
const formifyConnection = ({
|
|
1246
|
-
|
|
1337
|
+
parentType,
|
|
1247
1338
|
selectionNode,
|
|
1248
1339
|
path
|
|
1249
1340
|
}) => {
|
|
1250
|
-
ensureObjectType(namedFieldType);
|
|
1251
1341
|
return __spreadProps(__spreadValues({}, selectionNode), {
|
|
1252
1342
|
selectionSet: {
|
|
1253
1343
|
kind: "SelectionSet",
|
|
@@ -1255,13 +1345,12 @@ var __objRest = (source, exclude) => {
|
|
|
1255
1345
|
switch (selectionNode2.kind) {
|
|
1256
1346
|
case "Field":
|
|
1257
1347
|
if (selectionNode2.name.value === EDGES_NODE_NAME) {
|
|
1258
|
-
const edgeField =
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
];
|
|
1348
|
+
const edgeField = getObjectField(parentType, selectionNode2);
|
|
1349
|
+
const edgesPath = buildPath({
|
|
1350
|
+
fieldNode: selectionNode2,
|
|
1351
|
+
type: edgeField.type,
|
|
1352
|
+
path
|
|
1353
|
+
});
|
|
1265
1354
|
return __spreadProps(__spreadValues({}, selectionNode2), {
|
|
1266
1355
|
selectionSet: {
|
|
1267
1356
|
kind: "SelectionSet",
|
|
@@ -1269,15 +1358,15 @@ var __objRest = (source, exclude) => {
|
|
|
1269
1358
|
switch (subSelectionNode.kind) {
|
|
1270
1359
|
case "Field":
|
|
1271
1360
|
if (subSelectionNode.name.value === NODE_NAME) {
|
|
1272
|
-
const nodeField =
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
getNameAndAlias(subSelectionNode, false, true)
|
|
1276
|
-
];
|
|
1277
|
-
return formifyNode({
|
|
1278
|
-
fieldOrInlineFragmentNode: subSelectionNode,
|
|
1361
|
+
const nodeField = getObjectField(edgeField.type, subSelectionNode);
|
|
1362
|
+
return formifyFieldNodeDocument({
|
|
1363
|
+
fieldNode: subSelectionNode,
|
|
1279
1364
|
type: nodeField.type,
|
|
1280
|
-
path:
|
|
1365
|
+
path: buildPath({
|
|
1366
|
+
fieldNode: subSelectionNode,
|
|
1367
|
+
type: nodeField.type,
|
|
1368
|
+
path: edgesPath
|
|
1369
|
+
}),
|
|
1281
1370
|
showInSidebar: false
|
|
1282
1371
|
});
|
|
1283
1372
|
} else {
|
|
@@ -1298,28 +1387,48 @@ var __objRest = (source, exclude) => {
|
|
|
1298
1387
|
}
|
|
1299
1388
|
});
|
|
1300
1389
|
};
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1390
|
+
function formifyInlineFragmentDocument({
|
|
1391
|
+
inlineFragmentNode,
|
|
1392
|
+
type,
|
|
1393
|
+
path,
|
|
1394
|
+
showInSidebar = false
|
|
1395
|
+
}) {
|
|
1396
|
+
return formifyDocument({
|
|
1397
|
+
selection: inlineFragmentNode,
|
|
1398
|
+
type,
|
|
1399
|
+
path,
|
|
1400
|
+
showInSidebar
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
function formifyFieldNodeDocument({
|
|
1404
|
+
fieldNode,
|
|
1405
|
+
type,
|
|
1406
|
+
path,
|
|
1407
|
+
showInSidebar = false
|
|
1408
|
+
}) {
|
|
1409
|
+
return formifyDocument({ selection: fieldNode, type, path, showInSidebar });
|
|
1410
|
+
}
|
|
1411
|
+
function formifyDocument({
|
|
1412
|
+
selection,
|
|
1303
1413
|
type,
|
|
1304
1414
|
path,
|
|
1305
1415
|
showInSidebar = false
|
|
1306
1416
|
}) {
|
|
1307
1417
|
let extraFields = [];
|
|
1308
|
-
const namedType = G__namespace.getNamedType(type);
|
|
1309
1418
|
let hasDataJSONField = false;
|
|
1310
1419
|
let hasValuesField = false;
|
|
1311
1420
|
let shouldFormify = false;
|
|
1312
|
-
|
|
1313
|
-
if (
|
|
1314
|
-
if (
|
|
1421
|
+
selection.selectionSet.selections.forEach((selection2) => {
|
|
1422
|
+
if (selection2.kind === "Field") {
|
|
1423
|
+
if (selection2.name.value === "dataJSON") {
|
|
1315
1424
|
shouldFormify = true;
|
|
1316
1425
|
hasDataJSONField = true;
|
|
1317
1426
|
}
|
|
1318
|
-
if (
|
|
1427
|
+
if (selection2.name.value === "values") {
|
|
1319
1428
|
shouldFormify = true;
|
|
1320
1429
|
hasValuesField = true;
|
|
1321
1430
|
}
|
|
1322
|
-
if (
|
|
1431
|
+
if (selection2.name.value === "data") {
|
|
1323
1432
|
shouldFormify = true;
|
|
1324
1433
|
}
|
|
1325
1434
|
}
|
|
@@ -1328,7 +1437,7 @@ var __objRest = (source, exclude) => {
|
|
|
1328
1437
|
blueprints.push({
|
|
1329
1438
|
id: getBlueprintId(path),
|
|
1330
1439
|
path,
|
|
1331
|
-
selection
|
|
1440
|
+
selection,
|
|
1332
1441
|
fields: [],
|
|
1333
1442
|
showInSidebar,
|
|
1334
1443
|
hasDataJSONField,
|
|
@@ -1336,71 +1445,58 @@ var __objRest = (source, exclude) => {
|
|
|
1336
1445
|
});
|
|
1337
1446
|
extraFields = metaFields;
|
|
1338
1447
|
}
|
|
1339
|
-
|
|
1448
|
+
return __spreadProps(__spreadValues({}, selection), {
|
|
1340
1449
|
selectionSet: {
|
|
1341
1450
|
kind: "SelectionSet",
|
|
1342
1451
|
selections: [
|
|
1343
|
-
...
|
|
1452
|
+
...selection.selectionSet.selections.map((selectionNode) => {
|
|
1344
1453
|
switch (selectionNode.kind) {
|
|
1345
|
-
case "InlineFragment":
|
|
1454
|
+
case "InlineFragment": {
|
|
1455
|
+
const namedType = G__namespace.getNamedType(type);
|
|
1346
1456
|
if (G__namespace.isInterfaceType(namedType)) {
|
|
1347
|
-
const
|
|
1348
|
-
return
|
|
1349
|
-
|
|
1350
|
-
type:
|
|
1457
|
+
const subType = schema.getImplementations(namedType).objects.find((item) => item.name === selectionNode.typeCondition.name.value);
|
|
1458
|
+
return formifyInlineFragmentDocument({
|
|
1459
|
+
inlineFragmentNode: selectionNode,
|
|
1460
|
+
type: subType,
|
|
1351
1461
|
path,
|
|
1352
|
-
showInSidebar:
|
|
1462
|
+
showInSidebar: true
|
|
1353
1463
|
});
|
|
1354
1464
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
type: subType,
|
|
1360
|
-
path,
|
|
1361
|
-
showInSidebar
|
|
1465
|
+
return formifyInlineFragmentNode({
|
|
1466
|
+
inlineFragmentNode: selectionNode,
|
|
1467
|
+
parentType: type,
|
|
1468
|
+
path
|
|
1362
1469
|
});
|
|
1363
|
-
|
|
1470
|
+
}
|
|
1471
|
+
case "Field": {
|
|
1364
1472
|
if (selectionNode.name.value === DATA_NODE_NAME) {
|
|
1365
|
-
const
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
...path2,
|
|
1390
|
-
getNameAndAlias(subSelectionNode, isListType(subSelectionField.type), isNodeField(subSelectionType))
|
|
1391
|
-
]
|
|
1392
|
-
});
|
|
1393
|
-
default:
|
|
1394
|
-
throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
|
|
1395
|
-
}
|
|
1396
|
-
})
|
|
1397
|
-
]
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
throw new FormifyError("UNEXPECTED");
|
|
1473
|
+
const field = getObjectField(type, selectionNode);
|
|
1474
|
+
return __spreadProps(__spreadValues({}, selectionNode), {
|
|
1475
|
+
selectionSet: {
|
|
1476
|
+
kind: "SelectionSet",
|
|
1477
|
+
selections: [
|
|
1478
|
+
...selectionNode.selectionSet.selections.map((subSelectionNode) => {
|
|
1479
|
+
switch (subSelectionNode.kind) {
|
|
1480
|
+
case "Field":
|
|
1481
|
+
return formifyFieldNode({
|
|
1482
|
+
fieldNode: subSelectionNode,
|
|
1483
|
+
parentType: field.type,
|
|
1484
|
+
path: buildPath({
|
|
1485
|
+
fieldNode: selectionNode,
|
|
1486
|
+
type: field.type,
|
|
1487
|
+
path
|
|
1488
|
+
})
|
|
1489
|
+
});
|
|
1490
|
+
default:
|
|
1491
|
+
throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
|
|
1492
|
+
}
|
|
1493
|
+
})
|
|
1494
|
+
]
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1402
1497
|
}
|
|
1403
1498
|
return selectionNode;
|
|
1499
|
+
}
|
|
1404
1500
|
default:
|
|
1405
1501
|
throw new FormifyError("UNEXPECTED");
|
|
1406
1502
|
}
|
|
@@ -1409,32 +1505,35 @@ var __objRest = (source, exclude) => {
|
|
|
1409
1505
|
]
|
|
1410
1506
|
}
|
|
1411
1507
|
});
|
|
1412
|
-
return formifiedNode;
|
|
1413
1508
|
}
|
|
1414
|
-
const
|
|
1509
|
+
const formifyFieldNode = ({
|
|
1415
1510
|
fieldNode,
|
|
1416
1511
|
parentType,
|
|
1417
1512
|
path
|
|
1418
1513
|
}) => {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1514
|
+
if (fieldNode.name.value === "__typename") {
|
|
1515
|
+
return fieldNode;
|
|
1516
|
+
}
|
|
1517
|
+
const field = getObjectField(parentType, fieldNode);
|
|
1422
1518
|
if (!field) {
|
|
1423
|
-
|
|
1424
|
-
return fieldNode;
|
|
1425
|
-
} else {
|
|
1426
|
-
throw new FormifyError("UNEXPECTED", `field with no associated type ${fieldNode.name.value}`);
|
|
1427
|
-
}
|
|
1519
|
+
return fieldNode;
|
|
1428
1520
|
}
|
|
1429
|
-
const namedType = G__namespace.getNamedType(field.type);
|
|
1430
|
-
const fieldBlueprint = {
|
|
1431
|
-
id: getBlueprintId([...path]),
|
|
1432
|
-
documentBlueprintId: getRelativeBlueprint(path),
|
|
1433
|
-
path: [...path]
|
|
1434
|
-
};
|
|
1435
1521
|
const blueprint = blueprints.find((blueprint2) => blueprint2.id === getRelativeBlueprint(path));
|
|
1436
|
-
blueprint
|
|
1437
|
-
|
|
1522
|
+
if (!blueprint) {
|
|
1523
|
+
return fieldNode;
|
|
1524
|
+
}
|
|
1525
|
+
const fieldPath = buildPath({
|
|
1526
|
+
fieldNode,
|
|
1527
|
+
type: field.type,
|
|
1528
|
+
parentTypename: G__namespace.getNamedType(parentType).name,
|
|
1529
|
+
path
|
|
1530
|
+
});
|
|
1531
|
+
blueprint.fields.push({
|
|
1532
|
+
id: getBlueprintId(fieldPath),
|
|
1533
|
+
documentBlueprintId: blueprint.id,
|
|
1534
|
+
path: fieldPath
|
|
1535
|
+
});
|
|
1536
|
+
if (isScalarType(field.type)) {
|
|
1438
1537
|
return fieldNode;
|
|
1439
1538
|
}
|
|
1440
1539
|
return __spreadProps(__spreadValues({}, fieldNode), {
|
|
@@ -1443,121 +1542,20 @@ var __objRest = (source, exclude) => {
|
|
|
1443
1542
|
selections: [
|
|
1444
1543
|
...fieldNode.selectionSet.selections.map((selectionNode) => {
|
|
1445
1544
|
switch (selectionNode.kind) {
|
|
1446
|
-
case "Field":
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
const subField = getObjectField(namedType, selectionNode);
|
|
1452
|
-
if (!subField) {
|
|
1453
|
-
return fieldNode;
|
|
1454
|
-
}
|
|
1455
|
-
if (G__namespace.isScalarType(G__namespace.getNamedType(subField.type))) {
|
|
1456
|
-
const newPath2 = [
|
|
1457
|
-
...path,
|
|
1458
|
-
getNameAndAlias(selectionNode, isListType(subField.type), false)
|
|
1459
|
-
];
|
|
1460
|
-
const fieldBlueprint3 = {
|
|
1461
|
-
id: getBlueprintId(newPath2),
|
|
1462
|
-
documentBlueprintId: getRelativeBlueprint(newPath2),
|
|
1463
|
-
path: newPath2
|
|
1464
|
-
};
|
|
1465
|
-
const blueprint3 = blueprints.find((blueprint4) => blueprint4.id === getRelativeBlueprint(path));
|
|
1466
|
-
blueprint3.fields.push(fieldBlueprint3);
|
|
1467
|
-
return selectionNode;
|
|
1468
|
-
}
|
|
1469
|
-
const subFieldType = subField.type;
|
|
1470
|
-
const namedSubFieldType = G__namespace.getNamedType(subFieldType);
|
|
1471
|
-
const newPath = [
|
|
1472
|
-
...path,
|
|
1473
|
-
getNameAndAlias(selectionNode, isListType(subFieldType), isNodeField(namedSubFieldType))
|
|
1474
|
-
];
|
|
1475
|
-
const fieldBlueprint2 = {
|
|
1476
|
-
id: getBlueprintId(newPath),
|
|
1477
|
-
documentBlueprintId: getRelativeBlueprint(newPath),
|
|
1478
|
-
path: newPath
|
|
1479
|
-
};
|
|
1480
|
-
const blueprint2 = blueprints.find((blueprint3) => blueprint3.id === getRelativeBlueprint(path));
|
|
1481
|
-
blueprint2.fields.push(fieldBlueprint2);
|
|
1482
|
-
return __spreadProps(__spreadValues({}, selectionNode), {
|
|
1483
|
-
selectionSet: {
|
|
1484
|
-
kind: "SelectionSet",
|
|
1485
|
-
selections: selectionNode.selectionSet.selections.map((subSelectionNode) => {
|
|
1486
|
-
switch (subSelectionNode.kind) {
|
|
1487
|
-
case "Field":
|
|
1488
|
-
if (subSelectionNode.name.value === "__typename") {
|
|
1489
|
-
return subSelectionNode;
|
|
1490
|
-
}
|
|
1491
|
-
ensureObjectType(namedSubFieldType);
|
|
1492
|
-
const subField1 = getObjectField(namedSubFieldType, subSelectionNode);
|
|
1493
|
-
const subType1 = subField1.type;
|
|
1494
|
-
const namedSubType2 = G__namespace.getNamedType(subType1);
|
|
1495
|
-
return formifyField({
|
|
1496
|
-
fieldNode: subSelectionNode,
|
|
1497
|
-
parentType: subFieldType,
|
|
1498
|
-
path: [
|
|
1499
|
-
...path,
|
|
1500
|
-
getNameAndAlias(subSelectionNode, isListType(subType1), isNodeField(namedSubType2))
|
|
1501
|
-
]
|
|
1502
|
-
});
|
|
1503
|
-
case "InlineFragment":
|
|
1504
|
-
const subNamedType = G__namespace.getNamedType(subField.type);
|
|
1505
|
-
ensureNodeField(subNamedType);
|
|
1506
|
-
ensureUnionType(subNamedType);
|
|
1507
|
-
const subType2 = getSelectedUnionType(subNamedType, subSelectionNode);
|
|
1508
|
-
const newPath2 = [
|
|
1509
|
-
...path,
|
|
1510
|
-
getNameAndAlias(selectionNode, isListType(subField.type), true)
|
|
1511
|
-
];
|
|
1512
|
-
return formifyNode({
|
|
1513
|
-
fieldOrInlineFragmentNode: subSelectionNode,
|
|
1514
|
-
type: subType2,
|
|
1515
|
-
path: newPath2,
|
|
1516
|
-
showInSidebar: false
|
|
1517
|
-
});
|
|
1518
|
-
default:
|
|
1519
|
-
throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
|
|
1520
|
-
}
|
|
1521
|
-
})
|
|
1522
|
-
}
|
|
1545
|
+
case "Field": {
|
|
1546
|
+
return formifyFieldNode({
|
|
1547
|
+
fieldNode: selectionNode,
|
|
1548
|
+
parentType: field.type,
|
|
1549
|
+
path: fieldPath
|
|
1523
1550
|
});
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
type: parentType2,
|
|
1531
|
-
path,
|
|
1532
|
-
showInSidebar: false
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
const subType = getSelectedUnionType(namedType, selectionNode);
|
|
1536
|
-
const namedSubType = G__namespace.getNamedType(subType);
|
|
1537
|
-
return __spreadProps(__spreadValues({}, selectionNode), {
|
|
1538
|
-
selectionSet: {
|
|
1539
|
-
kind: "SelectionSet",
|
|
1540
|
-
selections: selectionNode.selectionSet.selections.map((subSelectionNode) => {
|
|
1541
|
-
switch (subSelectionNode.kind) {
|
|
1542
|
-
case "Field":
|
|
1543
|
-
ensureObjectType(namedSubType);
|
|
1544
|
-
const subField2 = getObjectField(namedSubType, subSelectionNode);
|
|
1545
|
-
const subType2 = subField2.type;
|
|
1546
|
-
const namedSubType2 = G__namespace.getNamedType(subType2);
|
|
1547
|
-
return formifyField({
|
|
1548
|
-
fieldNode: subSelectionNode,
|
|
1549
|
-
parentType: subType,
|
|
1550
|
-
path: [
|
|
1551
|
-
...path,
|
|
1552
|
-
getNameAndAlias(subSelectionNode, isListType(subType2), isNodeField(namedSubType2))
|
|
1553
|
-
]
|
|
1554
|
-
});
|
|
1555
|
-
default:
|
|
1556
|
-
throw new FormifyError("UNEXPECTED", `selection ${subSelectionNode.kind}`);
|
|
1557
|
-
}
|
|
1558
|
-
})
|
|
1559
|
-
}
|
|
1551
|
+
}
|
|
1552
|
+
case "InlineFragment": {
|
|
1553
|
+
return formifyInlineFragmentNode({
|
|
1554
|
+
inlineFragmentNode: selectionNode,
|
|
1555
|
+
parentType: field.type,
|
|
1556
|
+
path: fieldPath
|
|
1560
1557
|
});
|
|
1558
|
+
}
|
|
1561
1559
|
default:
|
|
1562
1560
|
throw new FormifyError("UNEXPECTED", `selection ${selectionNode.kind}`);
|
|
1563
1561
|
}
|
|
@@ -1566,43 +1564,77 @@ var __objRest = (source, exclude) => {
|
|
|
1566
1564
|
}
|
|
1567
1565
|
});
|
|
1568
1566
|
};
|
|
1567
|
+
const formifyInlineFragmentNode = ({
|
|
1568
|
+
inlineFragmentNode,
|
|
1569
|
+
parentType,
|
|
1570
|
+
path
|
|
1571
|
+
}) => {
|
|
1572
|
+
const type = getSelectedUnionType(parentType, inlineFragmentNode);
|
|
1573
|
+
if (!type) {
|
|
1574
|
+
return inlineFragmentNode;
|
|
1575
|
+
}
|
|
1576
|
+
if (isFormifiableDocument(type)) {
|
|
1577
|
+
return formifyInlineFragmentDocument({
|
|
1578
|
+
inlineFragmentNode,
|
|
1579
|
+
type,
|
|
1580
|
+
path,
|
|
1581
|
+
showInSidebar: false
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
return __spreadProps(__spreadValues({}, inlineFragmentNode), {
|
|
1585
|
+
selectionSet: {
|
|
1586
|
+
kind: "SelectionSet",
|
|
1587
|
+
selections: inlineFragmentNode.selectionSet.selections.map((selectionNode) => {
|
|
1588
|
+
switch (selectionNode.kind) {
|
|
1589
|
+
case "Field":
|
|
1590
|
+
return formifyFieldNode({
|
|
1591
|
+
fieldNode: selectionNode,
|
|
1592
|
+
parentType: type,
|
|
1593
|
+
path
|
|
1594
|
+
});
|
|
1595
|
+
default:
|
|
1596
|
+
throw new FormifyError("UNEXPECTED", `selection ${selectionNode.kind}`);
|
|
1597
|
+
}
|
|
1598
|
+
})
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
};
|
|
1569
1602
|
const formifiedQuery = {
|
|
1570
1603
|
kind: "Document",
|
|
1571
1604
|
definitions: optimizedQuery.definitions.map((definition) => {
|
|
1572
1605
|
typeInfo.enter(definition);
|
|
1573
1606
|
ensureOperationDefinition(definition);
|
|
1574
|
-
const
|
|
1575
|
-
const namedType = G__namespace.getNamedType(type);
|
|
1576
|
-
ensureObjectType(namedType);
|
|
1607
|
+
const parentType = typeInfo.getType();
|
|
1577
1608
|
return __spreadProps(__spreadValues({}, definition), {
|
|
1578
1609
|
selectionSet: {
|
|
1579
1610
|
kind: "SelectionSet",
|
|
1580
1611
|
selections: definition.selectionSet.selections.map((selectionNode) => {
|
|
1581
1612
|
switch (selectionNode.kind) {
|
|
1582
1613
|
case "Field":
|
|
1583
|
-
const
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
if (
|
|
1589
|
-
return
|
|
1590
|
-
|
|
1614
|
+
const field = getObjectField(parentType, selectionNode);
|
|
1615
|
+
const path = buildPath({
|
|
1616
|
+
fieldNode: selectionNode,
|
|
1617
|
+
type: field.type
|
|
1618
|
+
});
|
|
1619
|
+
if (isFormifiableDocument(field.type)) {
|
|
1620
|
+
return formifyFieldNodeDocument({
|
|
1621
|
+
fieldNode: selectionNode,
|
|
1591
1622
|
type: field.type,
|
|
1592
|
-
path
|
|
1623
|
+
path,
|
|
1593
1624
|
showInSidebar: true
|
|
1594
1625
|
});
|
|
1595
|
-
} else if (isConnectionField(
|
|
1626
|
+
} else if (isConnectionField(field.type)) {
|
|
1596
1627
|
return formifyConnection({
|
|
1597
|
-
|
|
1628
|
+
parentType: field.type,
|
|
1598
1629
|
selectionNode,
|
|
1599
|
-
path
|
|
1630
|
+
path
|
|
1600
1631
|
});
|
|
1601
1632
|
}
|
|
1602
1633
|
if (selectionNode.name.value === COLLECTION_FIELD_NAME || selectionNode.name.value === COLLECTIONS_FIELD_NAME) {
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1605
|
-
|
|
1634
|
+
const path2 = buildPath({
|
|
1635
|
+
fieldNode: selectionNode,
|
|
1636
|
+
type: field.type
|
|
1637
|
+
});
|
|
1606
1638
|
return __spreadProps(__spreadValues({}, selectionNode), {
|
|
1607
1639
|
selectionSet: {
|
|
1608
1640
|
kind: "SelectionSet",
|
|
@@ -1610,16 +1642,15 @@ var __objRest = (source, exclude) => {
|
|
|
1610
1642
|
switch (subSelectionNode.kind) {
|
|
1611
1643
|
case "Field":
|
|
1612
1644
|
if (subSelectionNode.name.value === COLLECTIONS_DOCUMENTS_NAME) {
|
|
1613
|
-
|
|
1614
|
-
const n = namedFieldType.getFields()[COLLECTIONS_DOCUMENTS_NAME];
|
|
1615
|
-
const docType = G__namespace.getNamedType(n.type);
|
|
1645
|
+
const subField = getObjectField(field.type, subSelectionNode);
|
|
1616
1646
|
return formifyConnection({
|
|
1617
|
-
|
|
1647
|
+
parentType: subField.type,
|
|
1618
1648
|
selectionNode: subSelectionNode,
|
|
1619
|
-
path:
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1649
|
+
path: buildPath({
|
|
1650
|
+
fieldNode: subSelectionNode,
|
|
1651
|
+
type: subField.type,
|
|
1652
|
+
path: path2
|
|
1653
|
+
})
|
|
1623
1654
|
});
|
|
1624
1655
|
}
|
|
1625
1656
|
return subSelectionNode;
|
|
@@ -1659,9 +1690,27 @@ var __objRest = (source, exclude) => {
|
|
|
1659
1690
|
this.name = "FormifyError";
|
|
1660
1691
|
}
|
|
1661
1692
|
}
|
|
1693
|
+
const defaultState = {
|
|
1694
|
+
status: "idle",
|
|
1695
|
+
schema: void 0,
|
|
1696
|
+
query: null,
|
|
1697
|
+
queryString: null,
|
|
1698
|
+
data: {},
|
|
1699
|
+
changeSets: [],
|
|
1700
|
+
count: 0,
|
|
1701
|
+
blueprints: [],
|
|
1702
|
+
formNodes: [],
|
|
1703
|
+
documentForms: []
|
|
1704
|
+
};
|
|
1662
1705
|
function reducer(state, action) {
|
|
1663
1706
|
var _a, _b, _c, _d;
|
|
1664
1707
|
switch (action.type) {
|
|
1708
|
+
case "start":
|
|
1709
|
+
return __spreadProps(__spreadValues(__spreadValues({}, state), defaultState), {
|
|
1710
|
+
query: action.value.query ? G__namespace.parse(action.value.query) : null,
|
|
1711
|
+
queryString: action.value.query,
|
|
1712
|
+
status: "initialized"
|
|
1713
|
+
});
|
|
1665
1714
|
case "addDocumentBlueprints":
|
|
1666
1715
|
return __spreadProps(__spreadValues({}, state), {
|
|
1667
1716
|
status: "formified",
|
|
@@ -1716,16 +1765,21 @@ var __objRest = (source, exclude) => {
|
|
|
1716
1765
|
}
|
|
1717
1766
|
if (event.mutationType.type === "change") {
|
|
1718
1767
|
if (!action.value.form) {
|
|
1719
|
-
|
|
1768
|
+
getBlueprintFieldsForEvent(blueprint, event).forEach((fieldBlueprint) => {
|
|
1769
|
+
const { pathToChange } = getFormNodesForField(fieldBlueprint, formNode, event, state);
|
|
1720
1770
|
changeSets.push(__spreadValues({
|
|
1721
1771
|
path: pathToChange
|
|
1722
|
-
}, buildChangeSet(event,
|
|
1772
|
+
}, buildChangeSet(event, formNode)));
|
|
1723
1773
|
});
|
|
1724
1774
|
}
|
|
1725
1775
|
} else if (event.mutationType.type === "referenceChange") {
|
|
1726
1776
|
getBlueprintFieldsForEvent(blueprint, event).forEach((fieldBlueprint) => {
|
|
1727
|
-
const {
|
|
1728
|
-
|
|
1777
|
+
const {
|
|
1778
|
+
pathToChange,
|
|
1779
|
+
formNodes: subFormNodes,
|
|
1780
|
+
eventLocation
|
|
1781
|
+
} = getFormNodesForField(fieldBlueprint, formNode, event, state);
|
|
1782
|
+
if (action.value.form && state.blueprints.find((blueprint2) => blueprint2.id === fieldBlueprint.id)) {
|
|
1729
1783
|
const newFormNode = {
|
|
1730
1784
|
documentBlueprintId: fieldBlueprint.id,
|
|
1731
1785
|
documentFormId: action.value.form.id,
|
|
@@ -1736,8 +1790,15 @@ var __objRest = (source, exclude) => {
|
|
|
1736
1790
|
path: pathToChange
|
|
1737
1791
|
}, buildChangeSet(event, newFormNode)));
|
|
1738
1792
|
}
|
|
1739
|
-
|
|
1793
|
+
subFormNodes.forEach((subFormNode) => {
|
|
1740
1794
|
if (matchLocation(eventLocation, subFormNode)) {
|
|
1795
|
+
if (!action.value.form) {
|
|
1796
|
+
changeSets.push(__spreadProps(__spreadValues({
|
|
1797
|
+
path: pathToChange
|
|
1798
|
+
}, buildChangeSet(event, subFormNode)), {
|
|
1799
|
+
value: null
|
|
1800
|
+
}));
|
|
1801
|
+
}
|
|
1741
1802
|
formNodesToReplace.push(subFormNode);
|
|
1742
1803
|
}
|
|
1743
1804
|
});
|
|
@@ -1890,7 +1951,7 @@ var __objRest = (source, exclude) => {
|
|
|
1890
1951
|
}) => {
|
|
1891
1952
|
const formIds = React__default["default"].useRef([]);
|
|
1892
1953
|
const [state, dispatch] = React__default["default"].useReducer(reducer, {
|
|
1893
|
-
status: "
|
|
1954
|
+
status: "idle",
|
|
1894
1955
|
schema: void 0,
|
|
1895
1956
|
query: query ? G__namespace.parse(query) : null,
|
|
1896
1957
|
queryString: query,
|
|
@@ -1901,6 +1962,17 @@ var __objRest = (source, exclude) => {
|
|
|
1901
1962
|
formNodes: [],
|
|
1902
1963
|
documentForms: []
|
|
1903
1964
|
});
|
|
1965
|
+
React__default["default"].useEffect(() => {
|
|
1966
|
+
if (query) {
|
|
1967
|
+
dispatch({ type: "start", value: { query } });
|
|
1968
|
+
formIds.current.forEach((formId) => {
|
|
1969
|
+
const form = cms.forms.find(formId);
|
|
1970
|
+
if (form) {
|
|
1971
|
+
cms.plugins.remove(form);
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
}, [query, JSON.stringify(variables)]);
|
|
1904
1976
|
React__default["default"].useEffect(() => {
|
|
1905
1977
|
if (state.status === "initialized") {
|
|
1906
1978
|
cms.api.tina.request(query, { variables }).then((res) => {
|
|
@@ -1932,7 +2004,7 @@ var __objRest = (source, exclude) => {
|
|
|
1932
2004
|
variables
|
|
1933
2005
|
});
|
|
1934
2006
|
state.blueprints.map((blueprint) => {
|
|
1935
|
-
const responseAtBlueprint =
|
|
2007
|
+
const responseAtBlueprint = getValueForBlueprint(result, getBlueprintAliasPath(blueprint));
|
|
1936
2008
|
const location = [];
|
|
1937
2009
|
const findFormNodes = (res, location2) => {
|
|
1938
2010
|
if (Array.isArray(res)) {
|
|
@@ -1981,6 +2053,9 @@ var __objRest = (source, exclude) => {
|
|
|
1981
2053
|
React__default["default"].useEffect(() => {
|
|
1982
2054
|
if (state.status === "ready") {
|
|
1983
2055
|
cms.events.subscribe(`forms:reset`, (event) => {
|
|
2056
|
+
if (eventList) {
|
|
2057
|
+
eventList.push(printEvent(event));
|
|
2058
|
+
}
|
|
1984
2059
|
dispatch({ type: "formOnReset", value: { event } });
|
|
1985
2060
|
});
|
|
1986
2061
|
cms.events.subscribe(`forms:fields:onChange`, async (event) => {
|
|
@@ -2002,6 +2077,9 @@ var __objRest = (source, exclude) => {
|
|
|
2002
2077
|
values
|
|
2003
2078
|
_internalSys: sys {
|
|
2004
2079
|
path
|
|
2080
|
+
collection {
|
|
2081
|
+
name
|
|
2082
|
+
}
|
|
2005
2083
|
}
|
|
2006
2084
|
}
|
|
2007
2085
|
}
|
|
@@ -2032,7 +2110,8 @@ var __objRest = (source, exclude) => {
|
|
|
2032
2110
|
const form = cms.forms.find(changeSet.formId);
|
|
2033
2111
|
resolveSubFields({
|
|
2034
2112
|
formNode: changeSet.formNode,
|
|
2035
|
-
form
|
|
2113
|
+
form,
|
|
2114
|
+
loc: []
|
|
2036
2115
|
}).then((res) => {
|
|
2037
2116
|
dispatch({
|
|
2038
2117
|
type: "setIn",
|
|
@@ -2141,22 +2220,15 @@ var __objRest = (source, exclude) => {
|
|
|
2141
2220
|
const data = {};
|
|
2142
2221
|
await sequential(form.fields, async (field) => {
|
|
2143
2222
|
const value = form.values[field.name];
|
|
2144
|
-
const fieldName = field.list ? `${field.name}.[]` : field.name;
|
|
2145
2223
|
const blueprint = getFormNodeBlueprint(formNode, state);
|
|
2146
|
-
const
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
}
|
|
2151
|
-
const matchName = [
|
|
2152
|
-
blueprintName,
|
|
2153
|
-
DATA_NODE_NAME,
|
|
2154
|
-
...extra,
|
|
2155
|
-
fieldName
|
|
2156
|
-
].join(".");
|
|
2224
|
+
const { matchName, fieldName } = getMatchName({
|
|
2225
|
+
field,
|
|
2226
|
+
prefix,
|
|
2227
|
+
blueprint
|
|
2228
|
+
});
|
|
2157
2229
|
const fieldBlueprints = blueprint.fields.filter((fieldBlueprint) => {
|
|
2158
2230
|
return matchName === getBlueprintNamePath(fieldBlueprint);
|
|
2159
|
-
});
|
|
2231
|
+
}).filter((fbp) => filterFieldBlueprintsByParentTypename(fbp, field.parentTypename));
|
|
2160
2232
|
switch (field.type) {
|
|
2161
2233
|
case "object":
|
|
2162
2234
|
if (field.templates) {
|
|
@@ -2170,18 +2242,17 @@ var __objRest = (source, exclude) => {
|
|
|
2170
2242
|
if (!Array.isArray(value)) {
|
|
2171
2243
|
throw new Error(`Expected value for object list field to be an array`);
|
|
2172
2244
|
}
|
|
2173
|
-
|
|
2174
|
-
await sequential(value, async (item, index) => {
|
|
2245
|
+
data[keyName] = await sequential(value, async (item, index) => {
|
|
2175
2246
|
const template = field.templates[item._template];
|
|
2176
|
-
|
|
2247
|
+
return __spreadProps(__spreadValues({}, await resolveSubFields({
|
|
2177
2248
|
formNode,
|
|
2178
2249
|
form: { fields: template.fields, values: item },
|
|
2179
|
-
prefix: [prefix, fieldName].join("."),
|
|
2250
|
+
prefix: prefix ? [prefix, fieldName].join(".") : fieldName,
|
|
2180
2251
|
loc: [...loc, index]
|
|
2252
|
+
})), {
|
|
2253
|
+
__typename: field.typeMap[item._template]
|
|
2181
2254
|
});
|
|
2182
|
-
d.push(d2);
|
|
2183
2255
|
});
|
|
2184
|
-
data[keyName] = d;
|
|
2185
2256
|
});
|
|
2186
2257
|
} else {
|
|
2187
2258
|
throw new Error("blocks without list true is not yet supported");
|
|
@@ -2197,18 +2268,14 @@ var __objRest = (source, exclude) => {
|
|
|
2197
2268
|
if (!Array.isArray(value)) {
|
|
2198
2269
|
throw new Error(`Expected value for object list field to be an array`);
|
|
2199
2270
|
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
const d2 = await resolveSubFields({
|
|
2271
|
+
data[keyName] = await sequential(value, async (item, index) => {
|
|
2272
|
+
return resolveSubFields({
|
|
2203
2273
|
formNode,
|
|
2204
2274
|
form: { fields: field.fields, values: item },
|
|
2205
2275
|
prefix: [prefix, fieldName].join("."),
|
|
2206
2276
|
loc: [...loc, index]
|
|
2207
2277
|
});
|
|
2208
|
-
d.push(d2);
|
|
2209
|
-
return true;
|
|
2210
2278
|
});
|
|
2211
|
-
data[keyName] = d;
|
|
2212
2279
|
return true;
|
|
2213
2280
|
});
|
|
2214
2281
|
} else {
|
|
@@ -2218,13 +2285,12 @@ var __objRest = (source, exclude) => {
|
|
|
2218
2285
|
data[keyName] = null;
|
|
2219
2286
|
return true;
|
|
2220
2287
|
}
|
|
2221
|
-
|
|
2288
|
+
data[keyName] = await resolveSubFields({
|
|
2222
2289
|
formNode,
|
|
2223
2290
|
form: { fields: field.fields, values: value },
|
|
2224
2291
|
prefix: [prefix, fieldName].join("."),
|
|
2225
2292
|
loc
|
|
2226
2293
|
});
|
|
2227
|
-
data[keyName] = d;
|
|
2228
2294
|
return true;
|
|
2229
2295
|
});
|
|
2230
2296
|
}
|
|
@@ -2245,6 +2311,9 @@ var __objRest = (source, exclude) => {
|
|
|
2245
2311
|
values
|
|
2246
2312
|
_internalSys: sys {
|
|
2247
2313
|
path
|
|
2314
|
+
collection {
|
|
2315
|
+
name
|
|
2316
|
+
}
|
|
2248
2317
|
}
|
|
2249
2318
|
}
|
|
2250
2319
|
}
|
|
@@ -2279,12 +2348,13 @@ var __objRest = (source, exclude) => {
|
|
|
2279
2348
|
}
|
|
2280
2349
|
}
|
|
2281
2350
|
`, { variables: { id: value } });
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2351
|
+
data[keyName] = __spreadProps(__spreadValues({}, res.node), {
|
|
2352
|
+
data: await resolveSubFields({
|
|
2353
|
+
formNode: subDocumentFormNode,
|
|
2354
|
+
form: form2,
|
|
2355
|
+
loc: location
|
|
2356
|
+
})
|
|
2286
2357
|
});
|
|
2287
|
-
data[keyName] = __spreadProps(__spreadValues({}, res.node), { data: d });
|
|
2288
2358
|
});
|
|
2289
2359
|
break;
|
|
2290
2360
|
default:
|
|
@@ -2352,13 +2422,13 @@ mutation addPendingDocumentMutation(
|
|
|
2352
2422
|
return result;
|
|
2353
2423
|
};
|
|
2354
2424
|
this.getSchema = async () => {
|
|
2355
|
-
if (!this.
|
|
2425
|
+
if (!this.gqlSchema) {
|
|
2356
2426
|
const data = await this.request(G.getIntrospectionQuery(), {
|
|
2357
2427
|
variables: {}
|
|
2358
2428
|
});
|
|
2359
|
-
this.
|
|
2429
|
+
this.gqlSchema = G.buildClientSchema(data);
|
|
2360
2430
|
}
|
|
2361
|
-
return this.
|
|
2431
|
+
return this.gqlSchema;
|
|
2362
2432
|
};
|
|
2363
2433
|
this.getOptimizedQuery = async (documentNode) => {
|
|
2364
2434
|
const data = await this.request(`query GetOptimizedQuery($queryString: String!) {
|
|
@@ -2368,6 +2438,13 @@ mutation addPendingDocumentMutation(
|
|
|
2368
2438
|
});
|
|
2369
2439
|
return G.parse(data.getOptimizedQuery);
|
|
2370
2440
|
};
|
|
2441
|
+
if (options.schema) {
|
|
2442
|
+
const enrichedSchema = new schemaTools.TinaSchema(__spreadValues({
|
|
2443
|
+
version: { fullVersion: "", major: "", minor: "", patch: "" },
|
|
2444
|
+
meta: { flags: [] }
|
|
2445
|
+
}, schemaTools.addNamespaceToSchema(options.schema, [])));
|
|
2446
|
+
this.schema = enrichedSchema;
|
|
2447
|
+
}
|
|
2371
2448
|
this.options = options;
|
|
2372
2449
|
this.setBranch(options.branch);
|
|
2373
2450
|
this.events.subscribe("branch:change", ({ branchName }) => {
|
|
@@ -2577,11 +2654,11 @@ mutation addPendingDocumentMutation(
|
|
|
2577
2654
|
const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = "http://localhost:4001/graphql";
|
|
2578
2655
|
class LocalClient extends Client {
|
|
2579
2656
|
constructor(props) {
|
|
2580
|
-
const clientProps = {
|
|
2657
|
+
const clientProps = __spreadProps(__spreadValues({}, props), {
|
|
2581
2658
|
clientId: "",
|
|
2582
2659
|
branch: "",
|
|
2583
2660
|
customContentApiUrl: props && props.customContentApiUrl ? props.customContentApiUrl : DEFAULT_LOCAL_TINA_GQL_SERVER_URL
|
|
2584
|
-
};
|
|
2661
|
+
});
|
|
2585
2662
|
super(clientProps);
|
|
2586
2663
|
}
|
|
2587
2664
|
async isAuthorized() {
|
|
@@ -3156,11 +3233,13 @@ mutation addPendingDocumentMutation(
|
|
|
3156
3233
|
var _d = _c, {
|
|
3157
3234
|
query,
|
|
3158
3235
|
documentCreatorCallback,
|
|
3159
|
-
formifyCallback
|
|
3236
|
+
formifyCallback,
|
|
3237
|
+
schema
|
|
3160
3238
|
} = _d, props = __objRest(_d, [
|
|
3161
3239
|
"query",
|
|
3162
3240
|
"documentCreatorCallback",
|
|
3163
|
-
"formifyCallback"
|
|
3241
|
+
"formifyCallback",
|
|
3242
|
+
"schema"
|
|
3164
3243
|
]);
|
|
3165
3244
|
const validOldSetup = new Boolean(props == null ? void 0 : props.isLocalClient) || new Boolean(props == null ? void 0 : props.clientId) && new Boolean(props == null ? void 0 : props.branch);
|
|
3166
3245
|
if (!props.apiURL && !validOldSetup) {
|
|
@@ -3177,7 +3256,8 @@ mutation addPendingDocumentMutation(
|
|
|
3177
3256
|
tinaioConfig: props.tinaioConfig,
|
|
3178
3257
|
isLocalClient,
|
|
3179
3258
|
cmsCallback: props.cmsCallback,
|
|
3180
|
-
mediaStore: props.mediaStore
|
|
3259
|
+
mediaStore: props.mediaStore,
|
|
3260
|
+
schema
|
|
3181
3261
|
}, /* @__PURE__ */ React__default["default"].createElement("style", null, styles), /* @__PURE__ */ React__default["default"].createElement(ErrorBoundary, null, /* @__PURE__ */ React__default["default"].createElement(DocumentCreator, {
|
|
3182
3262
|
documentCreatorCallback
|
|
3183
3263
|
}), /* @__PURE__ */ React__default["default"].createElement(TinaDataProvider, {
|
|
@@ -3905,7 +3985,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3905
3985
|
window.location.href = routeOverride;
|
|
3906
3986
|
return null;
|
|
3907
3987
|
} else {
|
|
3908
|
-
navigate(document.sys.
|
|
3988
|
+
navigate(document.sys.breadcrumbs.join("/"));
|
|
3909
3989
|
}
|
|
3910
3990
|
};
|
|
3911
3991
|
const CollectionListPage = () => {
|
|
@@ -3938,8 +4018,9 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3938
4018
|
}, /* @__PURE__ */ React__default["default"].createElement("tbody", {
|
|
3939
4019
|
className: "divide-y divide-gray-150"
|
|
3940
4020
|
}, documents.map((document) => {
|
|
4021
|
+
const subfolders = document.node.sys.breadcrumbs.slice(0, -1).join("/");
|
|
3941
4022
|
return /* @__PURE__ */ React__default["default"].createElement("tr", {
|
|
3942
|
-
key: `document-${document.node.sys.
|
|
4023
|
+
key: `document-${document.node.sys.relativePath}`,
|
|
3943
4024
|
className: ""
|
|
3944
4025
|
}, /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
3945
4026
|
className: "px-6 py-2 whitespace-nowrap"
|
|
@@ -3954,7 +4035,9 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
3954
4035
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
3955
4036
|
}, "Filename"), /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
3956
4037
|
className: "h-5 leading-5 block whitespace-nowrap"
|
|
3957
|
-
},
|
|
4038
|
+
}, subfolders && /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
4039
|
+
className: "text-xs text-gray-400"
|
|
4040
|
+
}, `${subfolders}/`), /* @__PURE__ */ React__default["default"].createElement("span", null, document.node.sys.filename))))), /* @__PURE__ */ React__default["default"].createElement("td", {
|
|
3958
4041
|
className: "px-6 py-4 whitespace-nowrap"
|
|
3959
4042
|
}, /* @__PURE__ */ React__default["default"].createElement("span", {
|
|
3960
4043
|
className: "block text-xs text-gray-400 mb-1 uppercase"
|
|
@@ -4078,6 +4161,22 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4078
4161
|
var _a, _b;
|
|
4079
4162
|
const navigate = reactRouterDom.useNavigate();
|
|
4080
4163
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4164
|
+
const schema = cms.api.tina.schema;
|
|
4165
|
+
let schemaFields = fields;
|
|
4166
|
+
if (schema) {
|
|
4167
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
4168
|
+
const template2 = schema.getTemplateForData({
|
|
4169
|
+
collection: schemaCollection,
|
|
4170
|
+
data: {}
|
|
4171
|
+
});
|
|
4172
|
+
const formInfo = schemaTools.resolveForm({
|
|
4173
|
+
collection: schemaCollection,
|
|
4174
|
+
basename: schemaCollection.name,
|
|
4175
|
+
schema,
|
|
4176
|
+
template: template2
|
|
4177
|
+
});
|
|
4178
|
+
schemaFields = formInfo.fields;
|
|
4179
|
+
}
|
|
4081
4180
|
const form = React.useMemo(() => {
|
|
4082
4181
|
return new toolkit.Form({
|
|
4083
4182
|
id: "create-form",
|
|
@@ -4087,7 +4186,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4087
4186
|
name: "filename",
|
|
4088
4187
|
label: "Filename",
|
|
4089
4188
|
component: "text",
|
|
4090
|
-
description:
|
|
4189
|
+
description: /* @__PURE__ */ React__default["default"].createElement("span", null, "A unique filename for the content.", /* @__PURE__ */ React__default["default"].createElement("br", null), "Examples: ", /* @__PURE__ */ React__default["default"].createElement("code", null, "My_Document"), ", ", /* @__PURE__ */ React__default["default"].createElement("code", null, "My_Document.en"), ",", " ", /* @__PURE__ */ React__default["default"].createElement("code", null, "sub-folder/My_Document")),
|
|
4091
4190
|
placeholder: `My_Document`,
|
|
4092
4191
|
validate: (value, allValues, meta) => {
|
|
4093
4192
|
if (!value) {
|
|
@@ -4096,13 +4195,13 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4096
4195
|
}
|
|
4097
4196
|
return true;
|
|
4098
4197
|
}
|
|
4099
|
-
const isValid = /^[_a-zA-Z][
|
|
4198
|
+
const isValid = /^[_a-zA-Z][\.\-_\/a-zA-Z0-9]*$/.test(value);
|
|
4100
4199
|
if (value && !isValid) {
|
|
4101
|
-
return "Must begin with a-z, A-Z, or _ and contain only a-z, A-Z, 0-9, -, ., or
|
|
4200
|
+
return "Must begin with a-z, A-Z, or _ and contain only a-z, A-Z, 0-9, -, _, ., or /.";
|
|
4102
4201
|
}
|
|
4103
4202
|
}
|
|
4104
4203
|
},
|
|
4105
|
-
...
|
|
4204
|
+
...schemaFields
|
|
4106
4205
|
],
|
|
4107
4206
|
onSubmit: async (values) => {
|
|
4108
4207
|
try {
|
|
@@ -4195,7 +4294,8 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4195
4294
|
}
|
|
4196
4295
|
};
|
|
4197
4296
|
const CollectionUpdatePage = () => {
|
|
4198
|
-
const { collectionName
|
|
4297
|
+
const _a = reactRouterDom.useParams(), { collectionName } = _a, rest = __objRest(_a, ["collectionName"]);
|
|
4298
|
+
const { "*": filename } = rest;
|
|
4199
4299
|
return /* @__PURE__ */ React__default["default"].createElement(GetCMS, null, (cms) => /* @__PURE__ */ React__default["default"].createElement(GetDocumentFields, {
|
|
4200
4300
|
cms,
|
|
4201
4301
|
collectionName
|
|
@@ -4224,13 +4324,28 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4224
4324
|
mutationInfo
|
|
4225
4325
|
}) => {
|
|
4226
4326
|
var _a, _b;
|
|
4227
|
-
reactRouterDom.useNavigate();
|
|
4228
4327
|
const [formIsPristine, setFormIsPristine] = React.useState(true);
|
|
4328
|
+
const schema = cms.api.tina.schema;
|
|
4329
|
+
let schemaFields = document.form.fields;
|
|
4330
|
+
if (schema) {
|
|
4331
|
+
const schemaCollection = schema.getCollection(collection.name);
|
|
4332
|
+
const template = schema.getTemplateForData({
|
|
4333
|
+
collection: schemaCollection,
|
|
4334
|
+
data: document.value
|
|
4335
|
+
});
|
|
4336
|
+
const formInfo = schemaTools.resolveForm({
|
|
4337
|
+
collection: schemaCollection,
|
|
4338
|
+
basename: schemaCollection.name,
|
|
4339
|
+
schema,
|
|
4340
|
+
template
|
|
4341
|
+
});
|
|
4342
|
+
schemaFields = formInfo.fields;
|
|
4343
|
+
}
|
|
4229
4344
|
const form = React.useMemo(() => {
|
|
4230
4345
|
return new toolkit.Form({
|
|
4231
4346
|
id: "update-form",
|
|
4232
4347
|
label: "form",
|
|
4233
|
-
fields:
|
|
4348
|
+
fields: schemaFields,
|
|
4234
4349
|
initialValues: document.values,
|
|
4235
4350
|
onSubmit: async (values) => {
|
|
4236
4351
|
try {
|
|
@@ -4314,7 +4429,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4314
4429
|
path: "collections/:collectionName/:templateName/new",
|
|
4315
4430
|
element: /* @__PURE__ */ React__default["default"].createElement(CollectionCreatePage, null)
|
|
4316
4431
|
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
4317
|
-
path: "collections/:collectionName
|
|
4432
|
+
path: "collections/:collectionName/*",
|
|
4318
4433
|
element: /* @__PURE__ */ React__default["default"].createElement(CollectionUpdatePage, null)
|
|
4319
4434
|
}), /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
4320
4435
|
path: "collections/:collectionName",
|