graphql-form 0.1.7 → 0.1.9
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/lib/index.d.ts +1 -6
- package/lib/index.js +1 -6
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +34 -77
- package/lib/models.js.map +1 -1
- package/lib/render/fields.d.ts +3 -0
- package/lib/{renderer → render}/fields.js +14 -15
- package/lib/render/fields.js.map +1 -0
- package/lib/render/index.d.ts +4 -0
- package/lib/render/index.js +56 -0
- package/lib/render/index.js.map +1 -0
- package/package.json +2 -2
- package/src/index.tsx +1 -6
- package/src/models.ts +43 -100
- package/src/render/fields.tsx +70 -0
- package/src/render/index.tsx +67 -0
- package/tsconfig.json +3 -2
- package/lib/BuiltInFields/InjectedValue.d.ts +0 -5
- package/lib/BuiltInFields/InjectedValue.js +0 -49
- package/lib/BuiltInFields/InjectedValue.js.map +0 -1
- package/lib/FormBuilder.d.ts +0 -3
- package/lib/FormBuilder.js +0 -78
- package/lib/FormBuilder.js.map +0 -1
- package/lib/FormDisplayer.d.ts +0 -3
- package/lib/FormDisplayer.js +0 -76
- package/lib/FormDisplayer.js.map +0 -1
- package/lib/FormToCode/gql/formToGql.spec.d.ts +0 -1
- package/lib/FormToCode/gql/formToGql.spec.js +0 -50
- package/lib/FormToCode/gql/formToGql.spec.js.map +0 -1
- package/lib/FormToCode/gql/index.d.ts +0 -6
- package/lib/FormToCode/gql/index.js +0 -12
- package/lib/FormToCode/gql/index.js.map +0 -1
- package/lib/FormToCode/gql/reducers.d.ts +0 -6
- package/lib/FormToCode/gql/reducers.js +0 -56
- package/lib/FormToCode/gql/reducers.js.map +0 -1
- package/lib/FormToCode/gql/resolvers.d.ts +0 -4
- package/lib/FormToCode/gql/resolvers.js +0 -54
- package/lib/FormToCode/gql/resolvers.js.map +0 -1
- package/lib/FormToCode/index.d.ts +0 -3
- package/lib/FormToCode/index.js +0 -20
- package/lib/FormToCode/index.js.map +0 -1
- package/lib/FormToCode/models.d.ts +0 -8
- package/lib/FormToCode/models.js +0 -3
- package/lib/FormToCode/models.js.map +0 -1
- package/lib/FormToCode/zeus/formToZeus.spec.d.ts +0 -1
- package/lib/FormToCode/zeus/formToZeus.spec.js +0 -59
- package/lib/FormToCode/zeus/formToZeus.spec.js.map +0 -1
- package/lib/FormToCode/zeus/index.d.ts +0 -6
- package/lib/FormToCode/zeus/index.js +0 -12
- package/lib/FormToCode/zeus/index.js.map +0 -1
- package/lib/FormToCode/zeus/resolvers.d.ts +0 -5
- package/lib/FormToCode/zeus/resolvers.js +0 -57
- package/lib/FormToCode/zeus/resolvers.js.map +0 -1
- package/lib/__tests__/consts.d.ts +0 -11
- package/lib/__tests__/consts.js +0 -38
- package/lib/__tests__/consts.js.map +0 -1
- package/lib/__tests__/index.d.ts +0 -2
- package/lib/__tests__/index.js +0 -19
- package/lib/__tests__/index.js.map +0 -1
- package/lib/__tests__/testUtils.d.ts +0 -1
- package/lib/__tests__/testUtils.js +0 -8
- package/lib/__tests__/testUtils.js.map +0 -1
- package/lib/createWidget.d.ts +0 -4
- package/lib/createWidget.js +0 -19
- package/lib/createWidget.js.map +0 -1
- package/lib/outsideUse.d.ts +0 -11
- package/lib/outsideUse.js +0 -147
- package/lib/outsideUse.js.map +0 -1
- package/lib/renderer/fields.d.ts +0 -3
- package/lib/renderer/fields.js.map +0 -1
- package/lib/renderer/index.d.ts +0 -3
- package/lib/renderer/index.js +0 -74
- package/lib/renderer/index.js.map +0 -1
- package/src/BuiltInFields/InjectedValue.tsx +0 -14
- package/src/FormBuilder.tsx +0 -58
- package/src/FormDisplayer.tsx +0 -48
- package/src/FormToCode/gql/formToGql.spec.ts +0 -75
- package/src/FormToCode/gql/index.ts +0 -9
- package/src/FormToCode/gql/reducers.ts +0 -50
- package/src/FormToCode/gql/resolvers.ts +0 -51
- package/src/FormToCode/index.ts +0 -3
- package/src/FormToCode/models.ts +0 -9
- package/src/FormToCode/zeus/formToZeus.spec.ts +0 -84
- package/src/FormToCode/zeus/index.ts +0 -9
- package/src/FormToCode/zeus/resolvers.tsx +0 -58
- package/src/createWidget.tsx +0 -8
- package/src/outsideUse.tsx +0 -156
- package/src/renderer/fields.tsx +0 -60
- package/src/renderer/index.tsx +0 -53
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -15,10 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./models"), exports);
|
18
|
-
__exportStar(require("./
|
19
|
-
__exportStar(require("./FormDisplayer"), exports);
|
20
|
-
__exportStar(require("./createWidget"), exports);
|
21
|
-
__exportStar(require("./renderer"), exports);
|
22
|
-
__exportStar(require("./FormToCode"), exports);
|
23
|
-
__exportStar(require("./outsideUse"), exports);
|
18
|
+
__exportStar(require("./render"), exports);
|
24
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB"}
|
package/lib/models.d.ts
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
import { ParserField } from 'graphql-js-tree';
|
2
|
+
import { VariableDefinitionWithoutLoc } from 'graphql-js-tree/lib/Models/GqlParserTree';
|
2
3
|
import React from 'react';
|
3
|
-
export declare type FieldComponent = React.FC<PassedFormProps>;
|
4
|
-
export declare type FormLabelProps = React.FC<PassedFormProps & {
|
5
|
-
open?: boolean;
|
6
|
-
setOpen: (b: boolean) => void;
|
7
|
-
}>;
|
8
|
-
export declare type WidgetSavedData = {
|
9
|
-
widget: string;
|
10
|
-
[x: string]: unknown;
|
11
|
-
};
|
12
|
-
export declare type SavedWidgets = {
|
13
|
-
[selector: string]: WidgetSavedData | undefined;
|
14
|
-
};
|
15
4
|
export declare const enum Errs {
|
16
5
|
REQUIRED = "REQUIRED",
|
17
6
|
VALUE_IN_ARRAY_REQUIRED = "VALUE_IN_ARRAY_REQUIRED"
|
@@ -19,76 +8,44 @@ export declare const enum Errs {
|
|
19
8
|
export declare type Errors = {
|
20
9
|
[selector: string]: string;
|
21
10
|
};
|
22
|
-
export declare type
|
23
|
-
[
|
11
|
+
export declare type VariableValue = {
|
12
|
+
[x: string]: VariableValue;
|
13
|
+
} | string | boolean | number | null | undefined | Array<VariableValue>;
|
14
|
+
export declare type VarValues = {
|
15
|
+
[variableName: string]: VariableValue;
|
24
16
|
};
|
25
|
-
export declare type
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
export declare type VarFormFile = {
|
18
|
+
values: VarValues;
|
19
|
+
vars: VariableDefinitionWithoutLoc[];
|
20
|
+
};
|
21
|
+
export declare type VarFormProps = {
|
22
|
+
file: VarFormFile;
|
23
|
+
onChange: (file: VarFormFile) => void;
|
24
|
+
schema: string;
|
25
|
+
shared: Omit<SharedProps, 'nodes'>;
|
30
26
|
};
|
31
|
-
|
32
|
-
f: ParserField;
|
27
|
+
declare type SharedProps = {
|
33
28
|
nodes: ParserField[];
|
34
|
-
formObject: FormObject;
|
35
|
-
onChange: (formObject: FormObject) => void;
|
36
|
-
changeWidget: (widgetData: WidgetSavedData | undefined, path: string) => void;
|
37
|
-
required?: boolean;
|
38
|
-
runQuery: (q: string) => Promise<ReturnedDictType>;
|
39
|
-
widgetComponents: WidgetType[];
|
40
|
-
widgetVariants?: WidgetVariantType[];
|
41
|
-
currentPath: string;
|
42
|
-
presetValues?: Record<string, any>;
|
43
|
-
widgets?: SavedWidgets;
|
44
|
-
widgetData?: WidgetData;
|
45
|
-
errors?: Errors;
|
46
|
-
children?: React.ReactNode;
|
47
29
|
components: {
|
48
|
-
ArrayField:
|
49
|
-
ObjectField:
|
50
|
-
BooleanField:
|
51
|
-
UniversalField:
|
52
|
-
NumberField:
|
53
|
-
EnumField:
|
54
|
-
NullField:
|
55
|
-
FormLabel:
|
56
|
-
FormField:
|
30
|
+
ArrayField: NewFieldComponent;
|
31
|
+
ObjectField: NewFieldComponent;
|
32
|
+
BooleanField: NewFieldComponent;
|
33
|
+
UniversalField: NewFieldComponent;
|
34
|
+
NumberField: NewFieldComponent;
|
35
|
+
EnumField: NewFieldComponent;
|
36
|
+
NullField: NewFieldComponent;
|
37
|
+
FormLabel: NewFormLabelProps;
|
38
|
+
FormField: NewFieldComponent;
|
57
39
|
};
|
58
40
|
};
|
59
|
-
export declare type
|
60
|
-
widgets?: SavedWidgets;
|
61
|
-
forms?: SavedForms;
|
62
|
-
};
|
63
|
-
export declare type FormBuilderProps = Omit<PassedFormProps, 'formObject' | 'onChange' | 'f' | 'currentPath' | 'changeWidget' | 'widgets' | 'nodes'> & {
|
64
|
-
formFile: FormFile;
|
65
|
-
schema: string;
|
66
|
-
onChange: (o: FormFile, query: string) => void;
|
67
|
-
};
|
68
|
-
export declare type FormDisplayerProps = Omit<PassedFormProps, 'formObject' | 'onChange' | 'f' | 'currentPath' | 'changeWidget' | 'widgets' | 'nodes'> & {
|
69
|
-
formFile: FormFile;
|
70
|
-
schema: string;
|
71
|
-
onChange: (o: FormFile, query: string) => void;
|
72
|
-
};
|
73
|
-
export declare type FormLibraryProps = Omit<FormDisplayerProps, 'required' | 'components'>;
|
74
|
-
export declare type CastToWidgetSettingsPassedForm<WidgetData = ReturnedDictType> = Partial<PassedFormProps<Partial<WidgetData>>> & {
|
75
|
-
widgetSettingsChange: (data: WidgetData) => void;
|
76
|
-
};
|
77
|
-
export declare type WidgetProps<Props> = {
|
78
|
-
Component: React.FC<PassedFormProps<Props>>;
|
79
|
-
Settings?: React.FC<CastToWidgetSettingsPassedForm<Props>> | undefined;
|
80
|
-
Description?: React.FC;
|
81
|
-
requirements: (props: PassedFormProps) => boolean;
|
82
|
-
displayName?: string;
|
83
|
-
name: string;
|
84
|
-
};
|
85
|
-
export declare type WidgetType = WidgetProps<ReturnedDictType>;
|
86
|
-
export declare type FormValue = {
|
87
|
-
value: FormValue;
|
88
|
-
} | {
|
89
|
-
[x: string]: FormValue;
|
90
|
-
} | string | boolean | number | null | undefined | FormObject | Array<FormValue>;
|
91
|
-
export declare type FormObject = {
|
92
|
-
value?: FormValue;
|
41
|
+
export declare type NewFieldProps = {
|
93
42
|
node: ParserField;
|
43
|
+
value: VariableValue;
|
44
|
+
shared: SharedProps;
|
45
|
+
mutate: (value: VariableValue) => void;
|
46
|
+
children?: React.ReactNode;
|
47
|
+
required?: boolean;
|
94
48
|
};
|
49
|
+
export declare type NewFieldComponent = React.FC<NewFieldProps>;
|
50
|
+
export declare type NewFormLabelProps = React.FC<NewFieldProps>;
|
51
|
+
export {};
|
package/lib/models.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";;;AAIA,IAAkB,IAGjB;AAHD,WAAkB,IAAI;IAClB,6BAAqB,CAAA;IACrB,2DAAmD,CAAA;AACvD,CAAC,EAHiB,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAGrB"}
|
@@ -15,34 +15,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
exports.Fields = void 0;
|
18
|
-
var outsideUse_1 = require("../outsideUse");
|
19
18
|
var graphql_js_tree_1 = require("graphql-js-tree");
|
20
19
|
var react_1 = __importDefault(require("react"));
|
21
20
|
var Fields = function (props) {
|
22
|
-
var
|
23
|
-
var seekNode = nodes.find(function (n) { return n.name === (0, graphql_js_tree_1.getTypeName)(
|
21
|
+
var node = props.node, _a = props.shared, nodes = _a.nodes, _b = _a.components, ArrayField = _b.ArrayField, ObjectField = _b.ObjectField;
|
22
|
+
var seekNode = nodes.find(function (n) { return n.name === (0, graphql_js_tree_1.getTypeName)(node.type.fieldType); });
|
24
23
|
var isInput = (seekNode === null || seekNode === void 0 ? void 0 : seekNode.data.type) === graphql_js_tree_1.TypeDefinition.InputObjectTypeDefinition;
|
25
|
-
if (
|
24
|
+
if (node.data.type === graphql_js_tree_1.TypeSystemDefinition.FieldDefinition ||
|
25
|
+
node.data.type === graphql_js_tree_1.TypeDefinition.InputObjectTypeDefinition) {
|
26
26
|
return react_1.default.createElement(ObjectField, __assign({}, props));
|
27
27
|
}
|
28
|
-
if (
|
28
|
+
if (node.type.fieldType.type === graphql_js_tree_1.Options.array) {
|
29
29
|
return react_1.default.createElement(ArrayField, __assign({}, props));
|
30
30
|
}
|
31
|
-
if (
|
32
|
-
|
31
|
+
if (node.type.fieldType.type === graphql_js_tree_1.Options.required) {
|
32
|
+
var nodeWithoutRequired = __assign(__assign({}, node), { type: __assign(__assign({}, node.type), { fieldType: __assign({}, node.type.fieldType.nest) }) });
|
33
|
+
return react_1.default.createElement(exports.Fields, __assign({}, props, { required: true, node: nodeWithoutRequired }));
|
33
34
|
}
|
34
|
-
|
35
|
-
|
36
|
-
var data = w.data, Component = w.widget.Component;
|
37
|
-
return react_1.default.createElement(Component, __assign({}, props, { widgetData: data }));
|
35
|
+
if (isInput) {
|
36
|
+
return react_1.default.createElement(ObjectField, __assign({}, props, { node: seekNode }));
|
38
37
|
}
|
39
38
|
return react_1.default.createElement(ScalarField, __assign({}, props));
|
40
39
|
};
|
41
40
|
exports.Fields = Fields;
|
42
41
|
var ScalarField = function (props) {
|
43
|
-
var
|
44
|
-
var typeName = (0, graphql_js_tree_1.getTypeName)(
|
45
|
-
var seekNode = nodes.find(function (n) { return n.name === (0, graphql_js_tree_1.getTypeName)(
|
42
|
+
var node = props.node, _a = props.shared, nodes = _a.nodes, _b = _a.components, BooleanField = _b.BooleanField, NumberField = _b.NumberField, EnumField = _b.EnumField, UniversalField = _b.UniversalField;
|
43
|
+
var typeName = (0, graphql_js_tree_1.getTypeName)(node.type.fieldType);
|
44
|
+
var seekNode = nodes.find(function (n) { return n.name === (0, graphql_js_tree_1.getTypeName)(node.type.fieldType); });
|
46
45
|
if (typeName === graphql_js_tree_1.ScalarTypes.String ||
|
47
46
|
typeName === graphql_js_tree_1.ScalarTypes.ID ||
|
48
47
|
(seekNode === null || seekNode === void 0 ? void 0 : seekNode.data.type) === graphql_js_tree_1.TypeDefinition.ScalarTypeDefinition) {
|
@@ -57,6 +56,6 @@ var ScalarField = function (props) {
|
|
57
56
|
if ((seekNode === null || seekNode === void 0 ? void 0 : seekNode.data.type) === graphql_js_tree_1.TypeDefinition.EnumTypeDefinition) {
|
58
57
|
return react_1.default.createElement(EnumField, __assign({}, props));
|
59
58
|
}
|
60
|
-
return react_1.default.createElement(react_1.default.Fragment, null
|
59
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
61
60
|
};
|
62
61
|
//# sourceMappingURL=fields.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../src/render/fields.tsx"],"names":[],"mappings":"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"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
exports.VariableForm = exports.Render = void 0;
|
18
|
+
var fields_1 = require("./fields");
|
19
|
+
var graphql_js_tree_1 = require("graphql-js-tree");
|
20
|
+
var react_1 = __importDefault(require("react"));
|
21
|
+
var Render = function (props) {
|
22
|
+
var node = props.node, _a = props.shared.components, FormLabel = _a.FormLabel, FormField = _a.FormField;
|
23
|
+
return (react_1.default.createElement(FormField, __assign({}, props, { required: node.type.fieldType.type === graphql_js_tree_1.Options.required }),
|
24
|
+
react_1.default.createElement(FormLabel, __assign({}, props, { required: node.type.fieldType.type === graphql_js_tree_1.Options.required })),
|
25
|
+
react_1.default.createElement(fields_1.Fields, __assign({}, props, { required: node.type.fieldType.type === graphql_js_tree_1.Options.required }))));
|
26
|
+
};
|
27
|
+
exports.Render = Render;
|
28
|
+
var VariableForm = function (props) {
|
29
|
+
var _a = props.file, values = _a.values, vars = _a.vars, onChange = props.onChange, schema = props.schema, shared = props.shared;
|
30
|
+
var nodes = graphql_js_tree_1.Parser.parseAddExtensions(schema).nodes;
|
31
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, vars.map(function (v) {
|
32
|
+
var value = values[v.name];
|
33
|
+
var node = nodes.find(function (n) { return n.name === v.type; }) || {
|
34
|
+
name: v.name,
|
35
|
+
args: [],
|
36
|
+
data: {
|
37
|
+
type: v.type,
|
38
|
+
},
|
39
|
+
directives: [],
|
40
|
+
id: (0, graphql_js_tree_1.generateNodeId)(v.name, v.type, []),
|
41
|
+
interfaces: [],
|
42
|
+
type: {
|
43
|
+
fieldType: (0, graphql_js_tree_1.decompileType)(v.type),
|
44
|
+
},
|
45
|
+
};
|
46
|
+
return (react_1.default.createElement(exports.Render, { node: node, shared: __assign(__assign({}, shared), { nodes: nodes }), mutate: function (val) {
|
47
|
+
var _a;
|
48
|
+
return onChange({
|
49
|
+
values: __assign(__assign({}, values), (_a = {}, _a[v.name] = val, _a)),
|
50
|
+
vars: vars,
|
51
|
+
});
|
52
|
+
}, value: value, key: v.name }));
|
53
|
+
})));
|
54
|
+
};
|
55
|
+
exports.VariableForm = VariableForm;
|
56
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,mDAA8F;AAC9F,gDAA0B;AAEnB,IAAM,MAAM,GAA4B,UAAC,KAAK;IAE7C,IAAA,IAAI,GAIJ,KAAK,KAJD,EAEA,KAEJ,KAAK,kBAFmC,EAAtB,SAAS,eAAA,EAAE,SAAS,eAAE,CAElC;IAEV,OAAO,CACH,8BAAC,SAAS,eAAK,KAAK,IAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,yBAAO,CAAC,QAAQ;QACzE,8BAAC,SAAS,eAAK,KAAK,IAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,yBAAO,CAAC,QAAQ,IAAI;QACjF,8BAAC,eAAM,eAAK,KAAK,IAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,yBAAO,CAAC,QAAQ,IAAI,CACtE,CACf,CAAC;AACN,CAAC,CAAC;AAdW,QAAA,MAAM,UAcjB;AAEK,IAAM,YAAY,GAA2B,UAAC,KAAK;IAElD,IAAA,KAIA,KAAK,KAJiB,EAAd,MAAM,YAAA,EAAE,IAAI,UAAA,EACpB,QAAQ,GAGR,KAAK,SAHG,EACR,MAAM,GAEN,KAAK,OAFC,EACN,MAAM,GACN,KAAK,OADC,CACA;IACF,IAAA,KAAK,GAAK,wBAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAtC,CAAuC;IACpD,OAAO,CACH,8DACK,IAAI,CAAC,GAAG,CAAC,UAAC,CAAC;QACR,IAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAjB,CAAiB,CAAC,IAAI;YACjD,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,EAAE;YACR,IAAI,EAAE;gBACF,IAAI,EAAE,CAAC,CAAC,IAAmB;aAC9B;YACD,UAAU,EAAE,EAAE;YACd,EAAE,EAAE,IAAA,gCAAc,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAmB,EAAE,EAAE,CAAC;YACrD,UAAU,EAAE,EAAE;YACd,IAAI,EAAE;gBACF,SAAS,EAAE,IAAA,+BAAa,EAAC,CAAC,CAAC,IAAI,CAAC;aACnC;SACJ,CAAC;QACF,OAAO,CACH,8BAAC,cAAM,IACH,IAAI,EAAE,IAAI,EACV,MAAM,wBACC,MAAM,KACT,KAAK,OAAA,KAET,MAAM,EAAE,UAAC,GAAG;;gBACR,OAAA,QAAQ,CAAC;oBACL,MAAM,wBAAO,MAAM,gBAAG,CAAC,CAAC,IAAI,IAAG,GAAG,MAAE;oBACpC,IAAI,MAAA;iBACP,CAAC;YAHF,CAGE,EAEN,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,CAAC,CAAC,IAAI,GACb,CACL,CAAC;IACN,CAAC,CAAC,CACH,CACN,CAAC;AACN,CAAC,CAAC;AA7CW,QAAA,YAAY,gBA6CvB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "graphql-form",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.9",
|
4
4
|
"description": "Easy form creation with GraphQL Editor and React",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"scripts": {
|
@@ -27,6 +27,6 @@
|
|
27
27
|
"react-dom": ">=16.8.0"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"graphql-js-tree": "^0.2
|
30
|
+
"graphql-js-tree": "^0.3.2"
|
31
31
|
}
|
32
32
|
}
|
package/src/index.tsx
CHANGED
package/src/models.ts
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
import { ParserField } from 'graphql-js-tree';
|
2
|
+
import { VariableDefinitionWithoutLoc } from 'graphql-js-tree/lib/Models/GqlParserTree';
|
2
3
|
import React from 'react';
|
3
4
|
|
4
|
-
export type FieldComponent = React.FC<PassedFormProps>;
|
5
|
-
|
6
|
-
export type FormLabelProps = React.FC<PassedFormProps & { open?: boolean; setOpen: (b: boolean) => void }>;
|
7
|
-
|
8
|
-
export type WidgetSavedData = {
|
9
|
-
widget: string;
|
10
|
-
[x: string]: unknown;
|
11
|
-
};
|
12
|
-
|
13
|
-
export type SavedWidgets = {
|
14
|
-
[selector: string]: WidgetSavedData | undefined;
|
15
|
-
};
|
16
|
-
|
17
5
|
export const enum Errs {
|
18
6
|
REQUIRED = 'REQUIRED',
|
19
7
|
VALUE_IN_ARRAY_REQUIRED = 'VALUE_IN_ARRAY_REQUIRED',
|
@@ -23,102 +11,57 @@ export type Errors = {
|
|
23
11
|
[selector: string]: string;
|
24
12
|
};
|
25
13
|
|
26
|
-
|
27
|
-
[selector: string]: FormObject;
|
28
|
-
};
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
30
|
-
export type ReturnedDictType = any;
|
14
|
+
// New implementation
|
31
15
|
|
32
|
-
export type
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
export type VariableValue =
|
17
|
+
| {
|
18
|
+
[x: string]: VariableValue;
|
19
|
+
}
|
20
|
+
| string
|
21
|
+
| boolean
|
22
|
+
| number
|
23
|
+
| null
|
24
|
+
| undefined
|
25
|
+
| Array<VariableValue>;
|
37
26
|
|
38
|
-
export type
|
39
|
-
|
40
|
-
nodes: ParserField[];
|
41
|
-
formObject: FormObject;
|
42
|
-
onChange: (formObject: FormObject) => void;
|
43
|
-
changeWidget: (widgetData: WidgetSavedData | undefined, path: string) => void;
|
44
|
-
required?: boolean;
|
45
|
-
runQuery: (q: string) => Promise<ReturnedDictType>;
|
46
|
-
widgetComponents: WidgetType[];
|
47
|
-
widgetVariants?: WidgetVariantType[];
|
48
|
-
currentPath: string;
|
49
|
-
presetValues?: Record<string, any>;
|
50
|
-
widgets?: SavedWidgets;
|
51
|
-
widgetData?: WidgetData;
|
52
|
-
errors?: Errors;
|
53
|
-
children?: React.ReactNode;
|
54
|
-
components: {
|
55
|
-
ArrayField: FieldComponent;
|
56
|
-
ObjectField: FieldComponent;
|
57
|
-
BooleanField: FieldComponent;
|
58
|
-
UniversalField: FieldComponent;
|
59
|
-
NumberField: FieldComponent;
|
60
|
-
EnumField: FieldComponent;
|
61
|
-
NullField: FieldComponent;
|
62
|
-
FormLabel: FormLabelProps;
|
63
|
-
FormField: FieldComponent;
|
64
|
-
};
|
27
|
+
export type VarValues = {
|
28
|
+
[variableName: string]: VariableValue;
|
65
29
|
};
|
66
|
-
export type
|
67
|
-
|
68
|
-
|
30
|
+
export type VarFormFile = {
|
31
|
+
values: VarValues;
|
32
|
+
vars: VariableDefinitionWithoutLoc[];
|
69
33
|
};
|
70
34
|
|
71
|
-
export type
|
72
|
-
|
73
|
-
|
74
|
-
> & {
|
75
|
-
formFile: FormFile;
|
35
|
+
export type VarFormProps = {
|
36
|
+
file: VarFormFile;
|
37
|
+
onChange: (file: VarFormFile) => void;
|
76
38
|
schema: string;
|
77
|
-
|
39
|
+
shared: Omit<SharedProps, 'nodes'>;
|
78
40
|
};
|
79
41
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
> & {
|
94
|
-
widgetSettingsChange: (data: WidgetData) => void;
|
95
|
-
};
|
96
|
-
|
97
|
-
export type WidgetProps<Props> = {
|
98
|
-
Component: React.FC<PassedFormProps<Props>>;
|
99
|
-
Settings?: React.FC<CastToWidgetSettingsPassedForm<Props>> | undefined;
|
100
|
-
Description?: React.FC;
|
101
|
-
requirements: (props: PassedFormProps) => boolean;
|
102
|
-
displayName?: string;
|
103
|
-
name: string;
|
42
|
+
type SharedProps = {
|
43
|
+
nodes: ParserField[];
|
44
|
+
components: {
|
45
|
+
ArrayField: NewFieldComponent;
|
46
|
+
ObjectField: NewFieldComponent;
|
47
|
+
BooleanField: NewFieldComponent;
|
48
|
+
UniversalField: NewFieldComponent;
|
49
|
+
NumberField: NewFieldComponent;
|
50
|
+
EnumField: NewFieldComponent;
|
51
|
+
NullField: NewFieldComponent;
|
52
|
+
FormLabel: NewFormLabelProps;
|
53
|
+
FormField: NewFieldComponent;
|
54
|
+
};
|
104
55
|
};
|
105
56
|
|
106
|
-
export type
|
107
|
-
|
108
|
-
export type FormValue =
|
109
|
-
| { value: FormValue }
|
110
|
-
| {
|
111
|
-
[x: string]: FormValue;
|
112
|
-
}
|
113
|
-
| string
|
114
|
-
| boolean
|
115
|
-
| number
|
116
|
-
| null
|
117
|
-
| undefined
|
118
|
-
| FormObject
|
119
|
-
| Array<FormValue>;
|
120
|
-
|
121
|
-
export type FormObject = {
|
122
|
-
value?: FormValue;
|
57
|
+
export type NewFieldProps = {
|
123
58
|
node: ParserField;
|
59
|
+
value: VariableValue;
|
60
|
+
shared: SharedProps;
|
61
|
+
mutate: (value: VariableValue) => void;
|
62
|
+
children?: React.ReactNode;
|
63
|
+
required?: boolean;
|
124
64
|
};
|
65
|
+
export type NewFieldComponent = React.FC<NewFieldProps>;
|
66
|
+
|
67
|
+
export type NewFormLabelProps = React.FC<NewFieldProps>;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { NewFieldProps } from '@/models';
|
2
|
+
import { getTypeName, Options, ParserField, ScalarTypes, TypeDefinition, TypeSystemDefinition } from 'graphql-js-tree';
|
3
|
+
import React from 'react';
|
4
|
+
|
5
|
+
export const Fields: React.FC<NewFieldProps> = (props) => {
|
6
|
+
const {
|
7
|
+
node,
|
8
|
+
shared: {
|
9
|
+
nodes,
|
10
|
+
components: { ArrayField, ObjectField },
|
11
|
+
},
|
12
|
+
} = props;
|
13
|
+
const seekNode = nodes.find((n) => n.name === getTypeName(node.type.fieldType));
|
14
|
+
const isInput = seekNode?.data.type === TypeDefinition.InputObjectTypeDefinition;
|
15
|
+
if (
|
16
|
+
node.data.type === TypeSystemDefinition.FieldDefinition ||
|
17
|
+
node.data.type === TypeDefinition.InputObjectTypeDefinition
|
18
|
+
) {
|
19
|
+
return <ObjectField {...props} />;
|
20
|
+
}
|
21
|
+
if (node.type.fieldType.type === Options.array) {
|
22
|
+
return <ArrayField {...props} />;
|
23
|
+
}
|
24
|
+
if (node.type.fieldType.type === Options.required) {
|
25
|
+
const nodeWithoutRequired: ParserField = {
|
26
|
+
...node,
|
27
|
+
type: {
|
28
|
+
...node.type,
|
29
|
+
fieldType: {
|
30
|
+
...node.type.fieldType.nest,
|
31
|
+
},
|
32
|
+
},
|
33
|
+
};
|
34
|
+
return <Fields {...props} required={true} node={nodeWithoutRequired} />;
|
35
|
+
}
|
36
|
+
if (isInput) {
|
37
|
+
return <ObjectField {...props} node={seekNode} />;
|
38
|
+
}
|
39
|
+
return <ScalarField {...props} />;
|
40
|
+
};
|
41
|
+
|
42
|
+
const ScalarField: React.FC<NewFieldProps> = (props) => {
|
43
|
+
const {
|
44
|
+
node,
|
45
|
+
shared: {
|
46
|
+
nodes,
|
47
|
+
components: { BooleanField, NumberField, EnumField, UniversalField },
|
48
|
+
},
|
49
|
+
} = props;
|
50
|
+
const typeName = getTypeName(node.type.fieldType);
|
51
|
+
const seekNode = nodes.find((n) => n.name === getTypeName(node.type.fieldType));
|
52
|
+
if (
|
53
|
+
typeName === ScalarTypes.String ||
|
54
|
+
typeName === ScalarTypes.ID ||
|
55
|
+
seekNode?.data.type === TypeDefinition.ScalarTypeDefinition
|
56
|
+
) {
|
57
|
+
return <UniversalField {...props} />;
|
58
|
+
}
|
59
|
+
|
60
|
+
if (typeName === ScalarTypes.Float || typeName === ScalarTypes.Int) {
|
61
|
+
return <NumberField {...props} />;
|
62
|
+
}
|
63
|
+
if (typeName === ScalarTypes.Boolean) {
|
64
|
+
return <BooleanField {...props} />;
|
65
|
+
}
|
66
|
+
if (seekNode?.data.type === TypeDefinition.EnumTypeDefinition) {
|
67
|
+
return <EnumField {...props} />;
|
68
|
+
}
|
69
|
+
return <></>;
|
70
|
+
};
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { NewFieldProps, VarFormProps } from '@/models';
|
2
|
+
import { Fields } from '@/render/fields';
|
3
|
+
import { Parser, ScalarTypes, generateNodeId, decompileType, Options } from 'graphql-js-tree';
|
4
|
+
import React from 'react';
|
5
|
+
|
6
|
+
export const Render: React.FC<NewFieldProps> = (props) => {
|
7
|
+
const {
|
8
|
+
node,
|
9
|
+
shared: {
|
10
|
+
components: { FormLabel, FormField },
|
11
|
+
},
|
12
|
+
} = props;
|
13
|
+
|
14
|
+
return (
|
15
|
+
<FormField {...props} required={node.type.fieldType.type === Options.required}>
|
16
|
+
<FormLabel {...props} required={node.type.fieldType.type === Options.required} />
|
17
|
+
<Fields {...props} required={node.type.fieldType.type === Options.required} />
|
18
|
+
</FormField>
|
19
|
+
);
|
20
|
+
};
|
21
|
+
|
22
|
+
export const VariableForm: React.FC<VarFormProps> = (props) => {
|
23
|
+
const {
|
24
|
+
file: { values, vars },
|
25
|
+
onChange,
|
26
|
+
schema,
|
27
|
+
shared,
|
28
|
+
} = props;
|
29
|
+
const { nodes } = Parser.parseAddExtensions(schema);
|
30
|
+
return (
|
31
|
+
<>
|
32
|
+
{vars.map((v) => {
|
33
|
+
const value = values[v.name];
|
34
|
+
const node = nodes.find((n) => n.name === v.type) || {
|
35
|
+
name: v.name,
|
36
|
+
args: [],
|
37
|
+
data: {
|
38
|
+
type: v.type as ScalarTypes,
|
39
|
+
},
|
40
|
+
directives: [],
|
41
|
+
id: generateNodeId(v.name, v.type as ScalarTypes, []),
|
42
|
+
interfaces: [],
|
43
|
+
type: {
|
44
|
+
fieldType: decompileType(v.type),
|
45
|
+
},
|
46
|
+
};
|
47
|
+
return (
|
48
|
+
<Render
|
49
|
+
node={node}
|
50
|
+
shared={{
|
51
|
+
...shared,
|
52
|
+
nodes,
|
53
|
+
}}
|
54
|
+
mutate={(val) =>
|
55
|
+
onChange({
|
56
|
+
values: { ...values, [v.name]: val },
|
57
|
+
vars,
|
58
|
+
})
|
59
|
+
}
|
60
|
+
value={value}
|
61
|
+
key={v.name}
|
62
|
+
/>
|
63
|
+
);
|
64
|
+
})}
|
65
|
+
</>
|
66
|
+
);
|
67
|
+
};
|
package/tsconfig.json
CHANGED