@graphiql/plugin-query-builder 1.0.0-beta.1 → 1.0.0-beta.2

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/arg-input/arg-input-by-type.js +441 -444
  3. package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
  4. package/dist/components/arg-input/enum-arg-control.js +49 -52
  5. package/dist/components/arg-input/enum-arg-control.js.map +1 -1
  6. package/dist/components/arg-input/index.js +44 -36
  7. package/dist/components/arg-input/index.js.map +1 -1
  8. package/dist/components/arg-input/scalar-arg-control.js +58 -63
  9. package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
  10. package/dist/components/field-row.js +212 -197
  11. package/dist/components/field-row.js.map +1 -1
  12. package/dist/components/field-tree-context.js +23 -27
  13. package/dist/components/field-tree-context.js.map +1 -1
  14. package/dist/components/field-tree-node.js +128 -105
  15. package/dist/components/field-tree-node.js.map +1 -1
  16. package/dist/components/field-tree.js +178 -199
  17. package/dist/components/field-tree.js.map +1 -1
  18. package/dist/components/fragment-editor.js +157 -151
  19. package/dist/components/fragment-editor.js.map +1 -1
  20. package/dist/components/fragment-section.js +215 -203
  21. package/dist/components/fragment-section.js.map +1 -1
  22. package/dist/components/query-builder.js +205 -181
  23. package/dist/components/query-builder.js.map +1 -1
  24. package/dist/components/type-condition-selector.js +417 -462
  25. package/dist/components/type-condition-selector.js.map +1 -1
  26. package/dist/components/use-cursor-path.js +69 -70
  27. package/dist/components/use-cursor-path.js.map +1 -1
  28. package/dist/components/use-cursor-reveal.js +83 -89
  29. package/dist/components/use-cursor-reveal.js.map +1 -1
  30. package/dist/components/use-working-document.js +432 -527
  31. package/dist/components/use-working-document.js.map +1 -1
  32. package/dist/index.js +11 -11
  33. package/dist/index.js.map +1 -1
  34. package/dist/lib/arg-value.js +132 -139
  35. package/dist/lib/arg-value.js.map +1 -1
  36. package/dist/lib/arguments.js +54 -55
  37. package/dist/lib/arguments.js.map +1 -1
  38. package/dist/lib/ast-path.js +266 -291
  39. package/dist/lib/ast-path.js.map +1 -1
  40. package/dist/lib/field-list-view.js +33 -43
  41. package/dist/lib/field-list-view.js.map +1 -1
  42. package/dist/lib/field-selection.js +63 -67
  43. package/dist/lib/field-selection.js.map +1 -1
  44. package/dist/lib/fragments.js +166 -152
  45. package/dist/lib/fragments.js.map +1 -1
  46. package/dist/lib/inline-fragments.js +64 -62
  47. package/dist/lib/inline-fragments.js.map +1 -1
  48. package/dist/lib/schema-walk.js +141 -158
  49. package/dist/lib/schema-walk.js.map +1 -1
  50. package/dist/lib/variables.js +96 -90
  51. package/dist/lib/variables.js.map +1 -1
  52. package/dist/style.css +4 -22
  53. package/package.json +21 -18
@@ -1,459 +1,456 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { c } from "react-compiler-runtime";
3
- import { CloseIcon, PlusIcon, ChevronDownIcon } from "@graphiql/react";
4
- import { isNonNullType, isListType, isInputObjectType, getNamedType, isEnumType, isScalarType } from "graphql";
5
- import { useState } from "react";
6
1
  import { BooleanArgControl, ScalarArgControl } from "./scalar-arg-control.js";
7
2
  import { EnumArgControl } from "./enum-arg-control.js";
3
+ import { ChevronDownIcon, CloseIcon, PlusIcon } from "@graphiql/react";
4
+ import { c } from "react-compiler-runtime";
5
+ import { getNamedType, isEnumType, isInputObjectType, isListType, isNonNullType, isScalarType } from "graphql";
6
+ import { useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/components/arg-input/arg-input-by-type.tsx
9
+ /**
10
+ * True when an arg/field of this type renders as an input-object disclosure
11
+ * (which labels itself via its header). A list of input objects does not — it
12
+ * renders as a list and needs its own `name:` label — so we only unwrap
13
+ * NonNull here, not List. Re-exported as the public predicate from index.
14
+ */
8
15
  function rendersAsInputObject(type) {
9
- const unwrapped = isNonNullType(type) ? type.ofType : type;
10
- if (isListType(unwrapped)) {
11
- return false;
12
- }
13
- return isInputObjectType(getNamedType(unwrapped));
16
+ const unwrapped = isNonNullType(type) ? type.ofType : type;
17
+ if (isListType(unwrapped)) return false;
18
+ return isInputObjectType(getNamedType(unwrapped));
14
19
  }
15
- const ArgInputByType = (t0) => {
16
- const $ = c(58);
17
- const {
18
- type,
19
- name,
20
- value,
21
- onChange,
22
- isVariable: t1,
23
- variableName,
24
- onPromote,
25
- onDemote
26
- } = t0;
27
- const isVariable = t1 === void 0 ? false : t1;
28
- if (isNonNullType(type)) {
29
- let t22;
30
- if ($[0] !== isVariable || $[1] !== name || $[2] !== onChange || $[3] !== onDemote || $[4] !== onPromote || $[5] !== type.ofType || $[6] !== value || $[7] !== variableName) {
31
- t22 = /* @__PURE__ */ jsx(ArgInputByType, { type: type.ofType, name, value, onChange, isVariable, variableName, onPromote, onDemote });
32
- $[0] = isVariable;
33
- $[1] = name;
34
- $[2] = onChange;
35
- $[3] = onDemote;
36
- $[4] = onPromote;
37
- $[5] = type.ofType;
38
- $[6] = value;
39
- $[7] = variableName;
40
- $[8] = t22;
41
- } else {
42
- t22 = $[8];
43
- }
44
- return t22;
45
- }
46
- if (isListType(type)) {
47
- let t22;
48
- if ($[9] !== value) {
49
- t22 = Array.isArray(value) ? value : [];
50
- $[9] = value;
51
- $[10] = t22;
52
- } else {
53
- t22 = $[10];
54
- }
55
- let t32;
56
- if ($[11] !== name || $[12] !== onChange || $[13] !== t22 || $[14] !== type.ofType) {
57
- t32 = /* @__PURE__ */ jsx(ListArgInput, { itemType: type.ofType, name, value: t22, onChange });
58
- $[11] = name;
59
- $[12] = onChange;
60
- $[13] = t22;
61
- $[14] = type.ofType;
62
- $[15] = t32;
63
- } else {
64
- t32 = $[15];
65
- }
66
- return t32;
67
- }
68
- let named;
69
- let t2;
70
- let t3;
71
- let toggleBtn;
72
- if ($[16] !== isVariable || $[17] !== name || $[18] !== onChange || $[19] !== onDemote || $[20] !== onPromote || $[21] !== type || $[22] !== value || $[23] !== variableName) {
73
- t3 = Symbol.for("react.early_return_sentinel");
74
- bb0: {
75
- named = getNamedType(type);
76
- if (isInputObjectType(named)) {
77
- let t42;
78
- if ($[28] !== value) {
79
- t42 = !Array.isArray(value) && typeof value === "object" && value !== null ? value : {};
80
- $[28] = value;
81
- $[29] = t42;
82
- } else {
83
- t42 = $[29];
84
- }
85
- const objValue = t42;
86
- t3 = /* @__PURE__ */ jsx(InputObjectArgInput, { inputType: named, name, value: objValue, onChange });
87
- break bb0;
88
- }
89
- let t4;
90
- if ($[30] !== isVariable || $[31] !== name || $[32] !== onDemote || $[33] !== onPromote || $[34] !== variableName) {
91
- t4 = onPromote ? /* @__PURE__ */ jsx("button", { type: "button", className: "graphiql-qb-var-toggle", "aria-pressed": isVariable, onClick: () => {
92
- if (isVariable) {
93
- if (onDemote && variableName) {
94
- onDemote(name, variableName);
95
- }
96
- } else {
97
- onPromote(name, name);
98
- }
99
- }, children: isVariable ? "Inline argument" : "Use as variable" }) : null;
100
- $[30] = isVariable;
101
- $[31] = name;
102
- $[32] = onDemote;
103
- $[33] = onPromote;
104
- $[34] = variableName;
105
- $[35] = t4;
106
- } else {
107
- t4 = $[35];
108
- }
109
- toggleBtn = t4;
110
- if (isEnumType(named)) {
111
- t3 = /* @__PURE__ */ jsx(WithVariableToggle, { isVariable, name, variableName, toggle: toggleBtn, children: /* @__PURE__ */ jsx(EnumArgControl, { name, value: typeof value === "string" ? value : "", onChange, enumValues: named.getValues().map(_temp) }) });
112
- break bb0;
113
- }
114
- t2 = isScalarType(named);
115
- }
116
- $[16] = isVariable;
117
- $[17] = name;
118
- $[18] = onChange;
119
- $[19] = onDemote;
120
- $[20] = onPromote;
121
- $[21] = type;
122
- $[22] = value;
123
- $[23] = variableName;
124
- $[24] = named;
125
- $[25] = t2;
126
- $[26] = t3;
127
- $[27] = toggleBtn;
128
- } else {
129
- named = $[24];
130
- t2 = $[25];
131
- t3 = $[26];
132
- toggleBtn = $[27];
133
- }
134
- if (t3 !== Symbol.for("react.early_return_sentinel")) {
135
- return t3;
136
- }
137
- if (t2) {
138
- if (named.name === "Boolean") {
139
- const t42 = typeof value === "string" ? value : "";
140
- let t52;
141
- if ($[36] !== name || $[37] !== onChange || $[38] !== t42) {
142
- t52 = /* @__PURE__ */ jsx(BooleanArgControl, { name, value: t42, onChange });
143
- $[36] = name;
144
- $[37] = onChange;
145
- $[38] = t42;
146
- $[39] = t52;
147
- } else {
148
- t52 = $[39];
149
- }
150
- let t62;
151
- if ($[40] !== isVariable || $[41] !== name || $[42] !== t52 || $[43] !== toggleBtn || $[44] !== variableName) {
152
- t62 = /* @__PURE__ */ jsx(WithVariableToggle, { isVariable, name, variableName, toggle: toggleBtn, children: t52 });
153
- $[40] = isVariable;
154
- $[41] = name;
155
- $[42] = t52;
156
- $[43] = toggleBtn;
157
- $[44] = variableName;
158
- $[45] = t62;
159
- } else {
160
- t62 = $[45];
161
- }
162
- return t62;
163
- }
164
- const inputType = named.name === "Int" || named.name === "Float" ? "number" : "text";
165
- const t4 = named.name === "Int" ? "1" : void 0;
166
- const t5 = typeof value === "string" ? value : "";
167
- let t6;
168
- if ($[46] !== inputType || $[47] !== name || $[48] !== onChange || $[49] !== t4 || $[50] !== t5) {
169
- t6 = /* @__PURE__ */ jsx(ScalarArgControl, { name, inputType, step: t4, value: t5, onChange });
170
- $[46] = inputType;
171
- $[47] = name;
172
- $[48] = onChange;
173
- $[49] = t4;
174
- $[50] = t5;
175
- $[51] = t6;
176
- } else {
177
- t6 = $[51];
178
- }
179
- let t7;
180
- if ($[52] !== isVariable || $[53] !== name || $[54] !== t6 || $[55] !== toggleBtn || $[56] !== variableName) {
181
- t7 = /* @__PURE__ */ jsx(WithVariableToggle, { isVariable, name, variableName, toggle: toggleBtn, children: t6 });
182
- $[52] = isVariable;
183
- $[53] = name;
184
- $[54] = t6;
185
- $[55] = toggleBtn;
186
- $[56] = variableName;
187
- $[57] = t7;
188
- } else {
189
- t7 = $[57];
190
- }
191
- return t7;
192
- }
193
- return null;
20
+ var ArgInputByType = (t0) => {
21
+ const $ = c(58);
22
+ const { type, name, value, onChange, isVariable: t1, variableName, onPromote, onDemote } = t0;
23
+ const isVariable = t1 === void 0 ? false : t1;
24
+ if (isNonNullType(type)) {
25
+ let t2;
26
+ if ($[0] !== isVariable || $[1] !== name || $[2] !== onChange || $[3] !== onDemote || $[4] !== onPromote || $[5] !== type.ofType || $[6] !== value || $[7] !== variableName) {
27
+ t2 = /* @__PURE__ */ jsx(ArgInputByType, {
28
+ type: type.ofType,
29
+ name,
30
+ value,
31
+ onChange,
32
+ isVariable,
33
+ variableName,
34
+ onPromote,
35
+ onDemote
36
+ });
37
+ $[0] = isVariable;
38
+ $[1] = name;
39
+ $[2] = onChange;
40
+ $[3] = onDemote;
41
+ $[4] = onPromote;
42
+ $[5] = type.ofType;
43
+ $[6] = value;
44
+ $[7] = variableName;
45
+ $[8] = t2;
46
+ } else t2 = $[8];
47
+ return t2;
48
+ }
49
+ if (isListType(type)) {
50
+ let t2;
51
+ if ($[9] !== value) {
52
+ t2 = Array.isArray(value) ? value : [];
53
+ $[9] = value;
54
+ $[10] = t2;
55
+ } else t2 = $[10];
56
+ let t3;
57
+ if ($[11] !== name || $[12] !== onChange || $[13] !== t2 || $[14] !== type.ofType) {
58
+ t3 = /* @__PURE__ */ jsx(ListArgInput, {
59
+ itemType: type.ofType,
60
+ name,
61
+ value: t2,
62
+ onChange
63
+ });
64
+ $[11] = name;
65
+ $[12] = onChange;
66
+ $[13] = t2;
67
+ $[14] = type.ofType;
68
+ $[15] = t3;
69
+ } else t3 = $[15];
70
+ return t3;
71
+ }
72
+ let named;
73
+ let t2;
74
+ let t3;
75
+ let toggleBtn;
76
+ if ($[16] !== isVariable || $[17] !== name || $[18] !== onChange || $[19] !== onDemote || $[20] !== onPromote || $[21] !== type || $[22] !== value || $[23] !== variableName) {
77
+ t3 = Symbol.for("react.early_return_sentinel");
78
+ bb0: {
79
+ named = getNamedType(type);
80
+ if (isInputObjectType(named)) {
81
+ let t4;
82
+ if ($[28] !== value) {
83
+ t4 = !Array.isArray(value) && typeof value === "object" && value !== null ? value : {};
84
+ $[28] = value;
85
+ $[29] = t4;
86
+ } else t4 = $[29];
87
+ t3 = /* @__PURE__ */ jsx(InputObjectArgInput, {
88
+ inputType: named,
89
+ name,
90
+ value: t4,
91
+ onChange
92
+ });
93
+ break bb0;
94
+ }
95
+ let t4;
96
+ if ($[30] !== isVariable || $[31] !== name || $[32] !== onDemote || $[33] !== onPromote || $[34] !== variableName) {
97
+ t4 = onPromote ? /* @__PURE__ */ jsx("button", {
98
+ type: "button",
99
+ className: "graphiql-qb-var-toggle",
100
+ "aria-pressed": isVariable,
101
+ onClick: () => {
102
+ if (isVariable) {
103
+ if (onDemote && variableName) onDemote(name, variableName);
104
+ } else onPromote(name, name);
105
+ },
106
+ children: isVariable ? "Inline argument" : "Use as variable"
107
+ }) : null;
108
+ $[30] = isVariable;
109
+ $[31] = name;
110
+ $[32] = onDemote;
111
+ $[33] = onPromote;
112
+ $[34] = variableName;
113
+ $[35] = t4;
114
+ } else t4 = $[35];
115
+ toggleBtn = t4;
116
+ if (isEnumType(named)) {
117
+ t3 = /* @__PURE__ */ jsx(WithVariableToggle, {
118
+ isVariable,
119
+ name,
120
+ variableName,
121
+ toggle: toggleBtn,
122
+ children: /* @__PURE__ */ jsx(EnumArgControl, {
123
+ name,
124
+ value: typeof value === "string" ? value : "",
125
+ onChange,
126
+ enumValues: named.getValues().map(_temp)
127
+ })
128
+ });
129
+ break bb0;
130
+ }
131
+ t2 = isScalarType(named);
132
+ }
133
+ $[16] = isVariable;
134
+ $[17] = name;
135
+ $[18] = onChange;
136
+ $[19] = onDemote;
137
+ $[20] = onPromote;
138
+ $[21] = type;
139
+ $[22] = value;
140
+ $[23] = variableName;
141
+ $[24] = named;
142
+ $[25] = t2;
143
+ $[26] = t3;
144
+ $[27] = toggleBtn;
145
+ } else {
146
+ named = $[24];
147
+ t2 = $[25];
148
+ t3 = $[26];
149
+ toggleBtn = $[27];
150
+ }
151
+ if (t3 !== Symbol.for("react.early_return_sentinel")) return t3;
152
+ if (t2) {
153
+ if (named.name === "Boolean") {
154
+ const t4 = typeof value === "string" ? value : "";
155
+ let t5;
156
+ if ($[36] !== name || $[37] !== onChange || $[38] !== t4) {
157
+ t5 = /* @__PURE__ */ jsx(BooleanArgControl, {
158
+ name,
159
+ value: t4,
160
+ onChange
161
+ });
162
+ $[36] = name;
163
+ $[37] = onChange;
164
+ $[38] = t4;
165
+ $[39] = t5;
166
+ } else t5 = $[39];
167
+ let t6;
168
+ if ($[40] !== isVariable || $[41] !== name || $[42] !== t5 || $[43] !== toggleBtn || $[44] !== variableName) {
169
+ t6 = /* @__PURE__ */ jsx(WithVariableToggle, {
170
+ isVariable,
171
+ name,
172
+ variableName,
173
+ toggle: toggleBtn,
174
+ children: t5
175
+ });
176
+ $[40] = isVariable;
177
+ $[41] = name;
178
+ $[42] = t5;
179
+ $[43] = toggleBtn;
180
+ $[44] = variableName;
181
+ $[45] = t6;
182
+ } else t6 = $[45];
183
+ return t6;
184
+ }
185
+ const inputType = named.name === "Int" || named.name === "Float" ? "number" : "text";
186
+ const t4 = named.name === "Int" ? "1" : void 0;
187
+ const t5 = typeof value === "string" ? value : "";
188
+ let t6;
189
+ if ($[46] !== inputType || $[47] !== name || $[48] !== onChange || $[49] !== t4 || $[50] !== t5) {
190
+ t6 = /* @__PURE__ */ jsx(ScalarArgControl, {
191
+ name,
192
+ inputType,
193
+ step: t4,
194
+ value: t5,
195
+ onChange
196
+ });
197
+ $[46] = inputType;
198
+ $[47] = name;
199
+ $[48] = onChange;
200
+ $[49] = t4;
201
+ $[50] = t5;
202
+ $[51] = t6;
203
+ } else t6 = $[51];
204
+ let t7;
205
+ if ($[52] !== isVariable || $[53] !== name || $[54] !== t6 || $[55] !== toggleBtn || $[56] !== variableName) {
206
+ t7 = /* @__PURE__ */ jsx(WithVariableToggle, {
207
+ isVariable,
208
+ name,
209
+ variableName,
210
+ toggle: toggleBtn,
211
+ children: t6
212
+ });
213
+ $[52] = isVariable;
214
+ $[53] = name;
215
+ $[54] = t6;
216
+ $[55] = toggleBtn;
217
+ $[56] = variableName;
218
+ $[57] = t7;
219
+ } else t7 = $[57];
220
+ return t7;
221
+ }
222
+ return null;
194
223
  };
195
- const WithVariableToggle = (t0) => {
196
- const $ = c(8);
197
- const {
198
- isVariable,
199
- name,
200
- variableName,
201
- toggle,
202
- children
203
- } = t0;
204
- let t1;
205
- if ($[0] !== children || $[1] !== isVariable || $[2] !== name || $[3] !== variableName) {
206
- t1 = isVariable ? /* @__PURE__ */ jsxs("span", { className: "graphiql-qb-var-badge", "aria-label": `${name} bound to $${variableName ?? name}`, children: [
207
- "$",
208
- variableName ?? name
209
- ] }) : children;
210
- $[0] = children;
211
- $[1] = isVariable;
212
- $[2] = name;
213
- $[3] = variableName;
214
- $[4] = t1;
215
- } else {
216
- t1 = $[4];
217
- }
218
- let t2;
219
- if ($[5] !== t1 || $[6] !== toggle) {
220
- t2 = /* @__PURE__ */ jsxs("span", { className: "graphiql-qb-arg-with-toggle", children: [
221
- t1,
222
- toggle
223
- ] });
224
- $[5] = t1;
225
- $[6] = toggle;
226
- $[7] = t2;
227
- } else {
228
- t2 = $[7];
229
- }
230
- return t2;
224
+ var WithVariableToggle = (t0) => {
225
+ const $ = c(8);
226
+ const { isVariable, name, variableName, toggle, children } = t0;
227
+ let t1;
228
+ if ($[0] !== children || $[1] !== isVariable || $[2] !== name || $[3] !== variableName) {
229
+ t1 = isVariable ? /* @__PURE__ */ jsxs("span", {
230
+ className: "graphiql-qb-var-badge",
231
+ "aria-label": `${name} bound to $${variableName ?? name}`,
232
+ children: ["$", variableName ?? name]
233
+ }) : children;
234
+ $[0] = children;
235
+ $[1] = isVariable;
236
+ $[2] = name;
237
+ $[3] = variableName;
238
+ $[4] = t1;
239
+ } else t1 = $[4];
240
+ let t2;
241
+ if ($[5] !== t1 || $[6] !== toggle) {
242
+ t2 = /* @__PURE__ */ jsxs("span", {
243
+ className: "graphiql-qb-arg-with-toggle",
244
+ children: [t1, toggle]
245
+ });
246
+ $[5] = t1;
247
+ $[6] = toggle;
248
+ $[7] = t2;
249
+ } else t2 = $[7];
250
+ return t2;
231
251
  };
232
- const withIds = (values) => values.map((value) => ({
233
- id: crypto.randomUUID(),
234
- value
252
+ var withIds = (values) => values.map((value) => ({
253
+ id: crypto.randomUUID(),
254
+ value
235
255
  }));
236
- const projectItems = (items) => items.map((i) => i.value).filter((v) => v !== "");
237
- const ListArgInput = (t0) => {
238
- const $ = c(21);
239
- const {
240
- itemType,
241
- name,
242
- value,
243
- onChange
244
- } = t0;
245
- let t1;
246
- if ($[0] !== value) {
247
- t1 = () => withIds(value);
248
- $[0] = value;
249
- $[1] = t1;
250
- } else {
251
- t1 = $[1];
252
- }
253
- const [items, setItems] = useState(t1);
254
- let t2;
255
- if ($[2] !== value) {
256
- t2 = JSON.stringify(value);
257
- $[2] = value;
258
- $[3] = t2;
259
- } else {
260
- t2 = $[3];
261
- }
262
- const valueJSON = t2;
263
- const [syncedJSON, setSyncedJSON] = useState(valueJSON);
264
- if (valueJSON !== syncedJSON) {
265
- setSyncedJSON(valueJSON);
266
- if (valueJSON !== JSON.stringify(projectItems(items))) {
267
- setItems(withIds(value));
268
- }
269
- }
270
- let t3;
271
- if ($[4] !== onChange) {
272
- t3 = (next) => {
273
- setItems(next);
274
- onChange(next.map(_temp2));
275
- };
276
- $[4] = onChange;
277
- $[5] = t3;
278
- } else {
279
- t3 = $[5];
280
- }
281
- const emit = t3;
282
- let t4;
283
- if ($[6] !== emit || $[7] !== itemType || $[8] !== items || $[9] !== name) {
284
- t4 = items.map((item) => /* @__PURE__ */ jsxs("div", { className: "graphiql-qb-list-item", children: [
285
- /* @__PURE__ */ jsx(ArgInputByType, { type: itemType, name, value: item.value, onChange: (v) => emit(items.map((i_0) => i_0.id === item.id ? {
286
- ...i_0,
287
- value: v
288
- } : i_0)) }),
289
- /* @__PURE__ */ jsx("button", { type: "button", onClick: () => emit(items.filter((i_1) => i_1.id !== item.id)), "aria-label": "Remove item", className: "graphiql-qb-list-remove", children: /* @__PURE__ */ jsx(CloseIcon, {}) })
290
- ] }, item.id));
291
- $[6] = emit;
292
- $[7] = itemType;
293
- $[8] = items;
294
- $[9] = name;
295
- $[10] = t4;
296
- } else {
297
- t4 = $[10];
298
- }
299
- let t5;
300
- if ($[11] !== emit || $[12] !== itemType || $[13] !== items) {
301
- t5 = () => emit([...items, {
302
- id: crypto.randomUUID(),
303
- value: defaultValueForType(itemType)
304
- }]);
305
- $[11] = emit;
306
- $[12] = itemType;
307
- $[13] = items;
308
- $[14] = t5;
309
- } else {
310
- t5 = $[14];
311
- }
312
- let t6;
313
- if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
314
- t6 = /* @__PURE__ */ jsx(PlusIcon, {});
315
- $[15] = t6;
316
- } else {
317
- t6 = $[15];
318
- }
319
- let t7;
320
- if ($[16] !== t5) {
321
- t7 = /* @__PURE__ */ jsxs("button", { type: "button", onClick: t5, "aria-label": "Add item", className: "graphiql-qb-list-add", children: [
322
- t6,
323
- "Add"
324
- ] });
325
- $[16] = t5;
326
- $[17] = t7;
327
- } else {
328
- t7 = $[17];
329
- }
330
- let t8;
331
- if ($[18] !== t4 || $[19] !== t7) {
332
- t8 = /* @__PURE__ */ jsxs("div", { className: "graphiql-qb-list-arg", children: [
333
- t4,
334
- t7
335
- ] });
336
- $[18] = t4;
337
- $[19] = t7;
338
- $[20] = t8;
339
- } else {
340
- t8 = $[20];
341
- }
342
- return t8;
256
+ var projectItems = (items) => items.map((i) => i.value).filter((v) => v !== "");
257
+ var ListArgInput = (t0) => {
258
+ const $ = c(21);
259
+ const { itemType, name, value, onChange } = t0;
260
+ let t1;
261
+ if ($[0] !== value) {
262
+ t1 = () => withIds(value);
263
+ $[0] = value;
264
+ $[1] = t1;
265
+ } else t1 = $[1];
266
+ const [items, setItems] = useState(t1);
267
+ let t2;
268
+ if ($[2] !== value) {
269
+ t2 = JSON.stringify(value);
270
+ $[2] = value;
271
+ $[3] = t2;
272
+ } else t2 = $[3];
273
+ const valueJSON = t2;
274
+ const [syncedJSON, setSyncedJSON] = useState(valueJSON);
275
+ if (valueJSON !== syncedJSON) {
276
+ setSyncedJSON(valueJSON);
277
+ if (valueJSON !== JSON.stringify(projectItems(items))) setItems(withIds(value));
278
+ }
279
+ let t3;
280
+ if ($[4] !== onChange) {
281
+ t3 = (next) => {
282
+ setItems(next);
283
+ onChange(next.map(_temp2));
284
+ };
285
+ $[4] = onChange;
286
+ $[5] = t3;
287
+ } else t3 = $[5];
288
+ const emit = t3;
289
+ let t4;
290
+ if ($[6] !== emit || $[7] !== itemType || $[8] !== items || $[9] !== name) {
291
+ t4 = items.map((item) => /* @__PURE__ */ jsxs("div", {
292
+ className: "graphiql-qb-list-item",
293
+ children: [/* @__PURE__ */ jsx(ArgInputByType, {
294
+ type: itemType,
295
+ name,
296
+ value: item.value,
297
+ onChange: (v) => emit(items.map((i_0) => i_0.id === item.id ? {
298
+ ...i_0,
299
+ value: v
300
+ } : i_0))
301
+ }), /* @__PURE__ */ jsx("button", {
302
+ type: "button",
303
+ onClick: () => emit(items.filter((i_1) => i_1.id !== item.id)),
304
+ "aria-label": "Remove item",
305
+ className: "graphiql-qb-list-remove",
306
+ children: /* @__PURE__ */ jsx(CloseIcon, {})
307
+ })]
308
+ }, item.id));
309
+ $[6] = emit;
310
+ $[7] = itemType;
311
+ $[8] = items;
312
+ $[9] = name;
313
+ $[10] = t4;
314
+ } else t4 = $[10];
315
+ let t5;
316
+ if ($[11] !== emit || $[12] !== itemType || $[13] !== items) {
317
+ t5 = () => emit([...items, {
318
+ id: crypto.randomUUID(),
319
+ value: defaultValueForType(itemType)
320
+ }]);
321
+ $[11] = emit;
322
+ $[12] = itemType;
323
+ $[13] = items;
324
+ $[14] = t5;
325
+ } else t5 = $[14];
326
+ let t6;
327
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
328
+ t6 = /* @__PURE__ */ jsx(PlusIcon, {});
329
+ $[15] = t6;
330
+ } else t6 = $[15];
331
+ let t7;
332
+ if ($[16] !== t5) {
333
+ t7 = /* @__PURE__ */ jsxs("button", {
334
+ type: "button",
335
+ onClick: t5,
336
+ "aria-label": "Add item",
337
+ className: "graphiql-qb-list-add",
338
+ children: [t6, "Add"]
339
+ });
340
+ $[16] = t5;
341
+ $[17] = t7;
342
+ } else t7 = $[17];
343
+ let t8;
344
+ if ($[18] !== t4 || $[19] !== t7) {
345
+ t8 = /* @__PURE__ */ jsxs("div", {
346
+ className: "graphiql-qb-list-arg",
347
+ children: [t4, t7]
348
+ });
349
+ $[18] = t4;
350
+ $[19] = t7;
351
+ $[20] = t8;
352
+ } else t8 = $[20];
353
+ return t8;
343
354
  };
344
355
  function defaultValueForType(type) {
345
- if (isNonNullType(type)) {
346
- return defaultValueForType(type.ofType);
347
- }
348
- if (isListType(type)) {
349
- return [];
350
- }
351
- const named = getNamedType(type);
352
- if (isInputObjectType(named)) {
353
- return {};
354
- }
355
- return "";
356
+ if (isNonNullType(type)) return defaultValueForType(type.ofType);
357
+ if (isListType(type)) return [];
358
+ const named = getNamedType(type);
359
+ if (isInputObjectType(named)) return {};
360
+ return "";
356
361
  }
357
- const InputObjectArgInput = (t0) => {
358
- const $ = c(15);
359
- const {
360
- inputType,
361
- name,
362
- value,
363
- onChange
364
- } = t0;
365
- const [open, setOpen] = useState(false);
366
- let t1;
367
- if ($[0] !== inputType || $[1] !== name || $[2] !== onChange || $[3] !== open || $[4] !== value) {
368
- const fields = inputType.getFields();
369
- const onChangeField = (fieldName, fieldValue) => {
370
- const next = {
371
- ...value
372
- };
373
- if (fieldValue === "" || fieldValue === void 0) {
374
- delete next[fieldName];
375
- } else {
376
- next[fieldName] = fieldValue;
377
- }
378
- onChange(next);
379
- };
380
- let t2;
381
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
382
- t2 = (e) => setOpen(e.currentTarget.open);
383
- $[6] = t2;
384
- } else {
385
- t2 = $[6];
386
- }
387
- const t3 = open ? "graphiql-qb-chevron-expanded" : "graphiql-qb-chevron-collapsed";
388
- let t4;
389
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
390
- t4 = /* @__PURE__ */ jsx(ChevronDownIcon, {});
391
- $[7] = t4;
392
- } else {
393
- t4 = $[7];
394
- }
395
- let t5;
396
- if ($[8] !== t3) {
397
- t5 = /* @__PURE__ */ jsx("span", { className: t3, children: t4 });
398
- $[8] = t3;
399
- $[9] = t5;
400
- } else {
401
- t5 = $[9];
402
- }
403
- let t6;
404
- if ($[10] !== name) {
405
- t6 = /* @__PURE__ */ jsx("span", { className: "graphiql-qb-arg-name", children: name });
406
- $[10] = name;
407
- $[11] = t6;
408
- } else {
409
- t6 = $[11];
410
- }
411
- let t7;
412
- if ($[12] !== t5 || $[13] !== t6) {
413
- t7 = /* @__PURE__ */ jsxs("summary", { className: "graphiql-qb-input-object-summary", children: [
414
- t5,
415
- t6
416
- ] });
417
- $[12] = t5;
418
- $[13] = t6;
419
- $[14] = t7;
420
- } else {
421
- t7 = $[14];
422
- }
423
- t1 = /* @__PURE__ */ jsxs("details", { className: "graphiql-qb-input-object", onToggle: t2, children: [
424
- t7,
425
- open && /* @__PURE__ */ jsx("div", { className: "graphiql-qb-input-object-fields", children: Object.entries(fields).map((t8) => {
426
- const [fieldName_0, field] = t8;
427
- const fieldVal = value[fieldName_0] ?? "";
428
- const isObjectField = rendersAsInputObject(field.type);
429
- return /* @__PURE__ */ jsxs("div", { className: "graphiql-qb-arg-row", children: [
430
- !isObjectField && /* @__PURE__ */ jsxs("span", { className: "graphiql-qb-arg-name", children: [
431
- fieldName_0,
432
- ":"
433
- ] }),
434
- /* @__PURE__ */ jsx(ArgInputByType, { type: field.type, name: fieldName_0, value: fieldVal, onChange: (v) => onChangeField(fieldName_0, v) })
435
- ] }, fieldName_0);
436
- }) })
437
- ] });
438
- $[0] = inputType;
439
- $[1] = name;
440
- $[2] = onChange;
441
- $[3] = open;
442
- $[4] = value;
443
- $[5] = t1;
444
- } else {
445
- t1 = $[5];
446
- }
447
- return t1;
362
+ var InputObjectArgInput = (t0) => {
363
+ const $ = c(15);
364
+ const { inputType, name, value, onChange } = t0;
365
+ const [open, setOpen] = useState(false);
366
+ let t1;
367
+ if ($[0] !== inputType || $[1] !== name || $[2] !== onChange || $[3] !== open || $[4] !== value) {
368
+ const fields = inputType.getFields();
369
+ const onChangeField = (fieldName, fieldValue) => {
370
+ const next = { ...value };
371
+ if (fieldValue === "" || fieldValue === void 0) delete next[fieldName];
372
+ else next[fieldName] = fieldValue;
373
+ onChange(next);
374
+ };
375
+ let t2;
376
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
377
+ t2 = (e) => setOpen(e.currentTarget.open);
378
+ $[6] = t2;
379
+ } else t2 = $[6];
380
+ const t3 = open ? "graphiql-qb-chevron-expanded" : "graphiql-qb-chevron-collapsed";
381
+ let t4;
382
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
383
+ t4 = /* @__PURE__ */ jsx(ChevronDownIcon, {});
384
+ $[7] = t4;
385
+ } else t4 = $[7];
386
+ let t5;
387
+ if ($[8] !== t3) {
388
+ t5 = /* @__PURE__ */ jsx("span", {
389
+ className: t3,
390
+ children: t4
391
+ });
392
+ $[8] = t3;
393
+ $[9] = t5;
394
+ } else t5 = $[9];
395
+ let t6;
396
+ if ($[10] !== name) {
397
+ t6 = /* @__PURE__ */ jsx("span", {
398
+ className: "graphiql-qb-arg-name",
399
+ children: name
400
+ });
401
+ $[10] = name;
402
+ $[11] = t6;
403
+ } else t6 = $[11];
404
+ let t7;
405
+ if ($[12] !== t5 || $[13] !== t6) {
406
+ t7 = /* @__PURE__ */ jsxs("summary", {
407
+ className: "graphiql-qb-input-object-summary",
408
+ children: [t5, t6]
409
+ });
410
+ $[12] = t5;
411
+ $[13] = t6;
412
+ $[14] = t7;
413
+ } else t7 = $[14];
414
+ t1 = /* @__PURE__ */ jsxs("details", {
415
+ className: "graphiql-qb-input-object",
416
+ onToggle: t2,
417
+ children: [t7, open && /* @__PURE__ */ jsx("div", {
418
+ className: "graphiql-qb-input-object-fields",
419
+ children: Object.entries(fields).map((t8) => {
420
+ const [fieldName_0, field] = t8;
421
+ const fieldVal = value[fieldName_0] ?? "";
422
+ const isObjectField = rendersAsInputObject(field.type);
423
+ return /* @__PURE__ */ jsxs("div", {
424
+ className: "graphiql-qb-arg-row",
425
+ children: [!isObjectField && /* @__PURE__ */ jsxs("span", {
426
+ className: "graphiql-qb-arg-name",
427
+ children: [fieldName_0, ":"]
428
+ }), /* @__PURE__ */ jsx(ArgInputByType, {
429
+ type: field.type,
430
+ name: fieldName_0,
431
+ value: fieldVal,
432
+ onChange: (v) => onChangeField(fieldName_0, v)
433
+ })]
434
+ }, fieldName_0);
435
+ })
436
+ })]
437
+ });
438
+ $[0] = inputType;
439
+ $[1] = name;
440
+ $[2] = onChange;
441
+ $[3] = open;
442
+ $[4] = value;
443
+ $[5] = t1;
444
+ } else t1 = $[5];
445
+ return t1;
448
446
  };
449
447
  function _temp(v) {
450
- return v.name;
448
+ return v.name;
451
449
  }
452
450
  function _temp2(i) {
453
- return i.value;
451
+ return i.value;
454
452
  }
455
- export {
456
- ArgInputByType,
457
- rendersAsInputObject
458
- };
459
- //# sourceMappingURL=arg-input-by-type.js.map
453
+ //#endregion
454
+ export { ArgInputByType, rendersAsInputObject };
455
+
456
+ //# sourceMappingURL=arg-input-by-type.js.map