@graphiql/plugin-query-builder 0.0.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +34 -0
  2. package/dist/components/arg-input/arg-input-by-type.d.ts +21 -0
  3. package/dist/components/arg-input/arg-input-by-type.js +459 -0
  4. package/dist/components/arg-input/arg-input-by-type.js.map +1 -0
  5. package/dist/components/arg-input/enum-arg-control.d.ts +9 -0
  6. package/dist/components/arg-input/enum-arg-control.js +56 -0
  7. package/dist/components/arg-input/enum-arg-control.js.map +1 -0
  8. package/dist/components/arg-input/index.d.ts +29 -0
  9. package/dist/components/arg-input/index.js +38 -0
  10. package/dist/components/arg-input/index.js.map +1 -0
  11. package/dist/components/arg-input/scalar-arg-control.d.ts +16 -0
  12. package/dist/components/arg-input/scalar-arg-control.js +66 -0
  13. package/dist/components/arg-input/scalar-arg-control.js.map +1 -0
  14. package/dist/components/field-row.d.ts +34 -0
  15. package/dist/components/field-row.js +199 -0
  16. package/dist/components/field-row.js.map +1 -0
  17. package/dist/components/field-tree-context.d.ts +32 -0
  18. package/dist/components/field-tree-context.js +33 -0
  19. package/dist/components/field-tree-context.js.map +1 -0
  20. package/dist/components/field-tree-node.d.ts +9 -0
  21. package/dist/components/field-tree-node.js +118 -0
  22. package/dist/components/field-tree-node.js.map +1 -0
  23. package/dist/components/field-tree.d.ts +30 -0
  24. package/dist/components/field-tree.js +204 -0
  25. package/dist/components/field-tree.js.map +1 -0
  26. package/dist/components/fragment-editor.d.ts +28 -0
  27. package/dist/components/fragment-editor.js +154 -0
  28. package/dist/components/fragment-editor.js.map +1 -0
  29. package/dist/components/fragment-section.d.ts +23 -0
  30. package/dist/components/fragment-section.js +207 -0
  31. package/dist/components/fragment-section.js.map +1 -0
  32. package/dist/components/query-builder.d.ts +2 -0
  33. package/dist/components/query-builder.js +193 -0
  34. package/dist/components/query-builder.js.map +1 -0
  35. package/dist/components/type-condition-selector.d.ts +18 -0
  36. package/dist/components/type-condition-selector.js +472 -0
  37. package/dist/components/type-condition-selector.js.map +1 -0
  38. package/dist/components/use-cursor-path.d.ts +16 -0
  39. package/dist/components/use-cursor-path.js +79 -0
  40. package/dist/components/use-cursor-path.js.map +1 -0
  41. package/dist/components/use-cursor-reveal.d.ts +15 -0
  42. package/dist/components/use-cursor-reveal.js +92 -0
  43. package/dist/components/use-cursor-reveal.js.map +1 -0
  44. package/dist/components/use-working-document.d.ts +31 -0
  45. package/dist/components/use-working-document.js +548 -0
  46. package/dist/components/use-working-document.js.map +1 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.js +13 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/lib/arg-value.d.ts +42 -0
  51. package/dist/lib/arg-value.js +147 -0
  52. package/dist/lib/arg-value.js.map +1 -0
  53. package/dist/lib/arguments.d.ts +28 -0
  54. package/dist/lib/arguments.js +62 -0
  55. package/dist/lib/arguments.js.map +1 -0
  56. package/dist/lib/ast-path.d.ts +109 -0
  57. package/dist/lib/ast-path.js +330 -0
  58. package/dist/lib/ast-path.js.map +1 -0
  59. package/dist/lib/document-mutator.d.ts +8 -0
  60. package/dist/lib/field-list-view.d.ts +30 -0
  61. package/dist/lib/field-list-view.js +47 -0
  62. package/dist/lib/field-list-view.js.map +1 -0
  63. package/dist/lib/field-selection.d.ts +26 -0
  64. package/dist/lib/field-selection.js +76 -0
  65. package/dist/lib/field-selection.js.map +1 -0
  66. package/dist/lib/fragments.d.ts +63 -0
  67. package/dist/lib/fragments.js +165 -0
  68. package/dist/lib/fragments.js.map +1 -0
  69. package/dist/lib/inline-fragments.d.ts +26 -0
  70. package/dist/lib/inline-fragments.js +71 -0
  71. package/dist/lib/inline-fragments.js.map +1 -0
  72. package/dist/lib/schema-walk.d.ts +47 -0
  73. package/dist/lib/schema-walk.js +177 -0
  74. package/dist/lib/schema-walk.js.map +1 -0
  75. package/dist/lib/variables.d.ts +33 -0
  76. package/dist/lib/variables.js +100 -0
  77. package/dist/lib/variables.js.map +1 -0
  78. package/dist/stories/query-builder.stories.d.ts +43 -0
  79. package/dist/style.css +957 -0
  80. package/package.json +67 -1
@@ -0,0 +1,472 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { c } from "react-compiler-runtime";
3
+ import { ChevronDownIcon } from "@graphiql/react";
4
+ import { isUnionType, isInterfaceType } from "graphql";
5
+ import { useState, useEffect } from "react";
6
+ import { useFieldTreeContext } from "./field-tree-context.js";
7
+ import { FieldTreeList } from "./field-tree.js";
8
+ import { useCursorReveal } from "./use-cursor-reveal.js";
9
+ import { segmentsEqual, inlineFragmentSegment } from "../lib/ast-path.js";
10
+ import { isInlineFragmentPresent } from "../lib/inline-fragments.js";
11
+ function applicableTypeConditions(abstractType, schema) {
12
+ const objects = schema.getPossibleTypes(abstractType);
13
+ if (!isInterfaceType(abstractType)) {
14
+ return [...objects];
15
+ }
16
+ const skip = /* @__PURE__ */ new Set([abstractType.name, ...abstractType.getInterfaces().map((i) => i.name)]);
17
+ const interfaces = /* @__PURE__ */ new Map();
18
+ for (const object of objects) {
19
+ for (const iface of object.getInterfaces()) {
20
+ if (!skip.has(iface.name)) {
21
+ interfaces.set(iface.name, iface);
22
+ }
23
+ }
24
+ }
25
+ return [...objects, ...interfaces.values()];
26
+ }
27
+ const TypeConditionSelector = (t0) => {
28
+ var _a;
29
+ const $ = c(58);
30
+ const {
31
+ fieldPath,
32
+ abstractType
33
+ } = t0;
34
+ const {
35
+ doc,
36
+ schema,
37
+ target,
38
+ cursorPath
39
+ } = useFieldTreeContext();
40
+ let t1;
41
+ if ($[0] !== abstractType || $[1] !== doc || $[2] !== fieldPath || $[3] !== schema || $[4] !== target) {
42
+ let t24;
43
+ if ($[6] !== doc || $[7] !== fieldPath || $[8] !== target) {
44
+ t24 = (t) => isInlineFragmentPresent(doc, fieldPath, t.name, target);
45
+ $[6] = doc;
46
+ $[7] = fieldPath;
47
+ $[8] = target;
48
+ $[9] = t24;
49
+ } else {
50
+ t24 = $[9];
51
+ }
52
+ t1 = (schema ? applicableTypeConditions(abstractType, schema) : []).some(t24);
53
+ $[0] = abstractType;
54
+ $[1] = doc;
55
+ $[2] = fieldPath;
56
+ $[3] = schema;
57
+ $[4] = target;
58
+ $[5] = t1;
59
+ } else {
60
+ t1 = $[5];
61
+ }
62
+ const hasSelectedCondition = t1;
63
+ const [expanded, setExpanded] = useState(hasSelectedCondition);
64
+ let t2;
65
+ let t3;
66
+ if ($[10] !== hasSelectedCondition) {
67
+ t2 = () => {
68
+ if (hasSelectedCondition) {
69
+ setExpanded(true);
70
+ }
71
+ };
72
+ t3 = [hasSelectedCondition];
73
+ $[10] = hasSelectedCondition;
74
+ $[11] = t2;
75
+ $[12] = t3;
76
+ } else {
77
+ t2 = $[11];
78
+ t3 = $[12];
79
+ }
80
+ useEffect(t2, t3);
81
+ let t4;
82
+ if ($[13] !== cursorPath || $[14] !== fieldPath) {
83
+ t4 = cursorPath !== void 0 && cursorPath.length > fieldPath.length && fieldPath.every((seg, i) => segmentsEqual(cursorPath[i], seg)) && ((_a = cursorPath[fieldPath.length]) == null ? void 0 : _a.kind) === "inlineFragment";
84
+ $[13] = cursorPath;
85
+ $[14] = fieldPath;
86
+ $[15] = t4;
87
+ } else {
88
+ t4 = $[15];
89
+ }
90
+ const cursorInCondition = t4;
91
+ let t5;
92
+ if ($[16] !== cursorInCondition) {
93
+ t5 = () => {
94
+ if (cursorInCondition) {
95
+ setExpanded(true);
96
+ }
97
+ };
98
+ $[16] = cursorInCondition;
99
+ $[17] = t5;
100
+ } else {
101
+ t5 = $[17];
102
+ }
103
+ let t6;
104
+ if ($[18] !== cursorInCondition || $[19] !== cursorPath) {
105
+ t6 = [cursorPath, cursorInCondition];
106
+ $[18] = cursorInCondition;
107
+ $[19] = cursorPath;
108
+ $[20] = t6;
109
+ } else {
110
+ t6 = $[20];
111
+ }
112
+ useEffect(t5, t6);
113
+ if (!schema) {
114
+ return null;
115
+ }
116
+ let t10;
117
+ let t11;
118
+ let t7;
119
+ let t8;
120
+ let t9;
121
+ let typeConditions;
122
+ if ($[21] !== abstractType || $[22] !== doc || $[23] !== fieldPath || $[24] !== schema || $[25] !== target) {
123
+ t11 = Symbol.for("react.early_return_sentinel");
124
+ bb0: {
125
+ typeConditions = applicableTypeConditions(abstractType, schema);
126
+ if (typeConditions.length === 0) {
127
+ t11 = null;
128
+ break bb0;
129
+ }
130
+ t7 = "graphiql-qb-type-condition";
131
+ t8 = "group";
132
+ t9 = `Possible types for ${abstractType.name}`;
133
+ let t122;
134
+ if ($[32] !== doc || $[33] !== fieldPath || $[34] !== target) {
135
+ t122 = (conditionType) => {
136
+ const isSelected = isInlineFragmentPresent(doc, fieldPath, conditionType.name, target);
137
+ return /* @__PURE__ */ jsx(TypeConditionEntry, { fieldPath, typeName: conditionType.name, concreteType: conditionType, isInterface: isInterfaceType(conditionType), isSelected }, conditionType.name);
138
+ };
139
+ $[32] = doc;
140
+ $[33] = fieldPath;
141
+ $[34] = target;
142
+ $[35] = t122;
143
+ } else {
144
+ t122 = $[35];
145
+ }
146
+ t10 = typeConditions.map(t122);
147
+ }
148
+ $[21] = abstractType;
149
+ $[22] = doc;
150
+ $[23] = fieldPath;
151
+ $[24] = schema;
152
+ $[25] = target;
153
+ $[26] = t10;
154
+ $[27] = t11;
155
+ $[28] = t7;
156
+ $[29] = t8;
157
+ $[30] = t9;
158
+ $[31] = typeConditions;
159
+ } else {
160
+ t10 = $[26];
161
+ t11 = $[27];
162
+ t7 = $[28];
163
+ t8 = $[29];
164
+ t9 = $[30];
165
+ typeConditions = $[31];
166
+ }
167
+ if (t11 !== Symbol.for("react.early_return_sentinel")) {
168
+ return t11;
169
+ }
170
+ let t12;
171
+ if ($[36] !== t10 || $[37] !== t7 || $[38] !== t8 || $[39] !== t9) {
172
+ t12 = /* @__PURE__ */ jsx("div", { className: t7, role: t8, "aria-label": t9, children: t10 });
173
+ $[36] = t10;
174
+ $[37] = t7;
175
+ $[38] = t8;
176
+ $[39] = t9;
177
+ $[40] = t12;
178
+ } else {
179
+ t12 = $[40];
180
+ }
181
+ const entries = t12;
182
+ if (isUnionType(abstractType)) {
183
+ return entries;
184
+ }
185
+ const t13 = `calc(${fieldPath.length * 12}px + var(--px-8))`;
186
+ let t14;
187
+ if ($[41] !== t13) {
188
+ t14 = {
189
+ paddingLeft: t13
190
+ };
191
+ $[41] = t13;
192
+ $[42] = t14;
193
+ } else {
194
+ t14 = $[42];
195
+ }
196
+ let t15;
197
+ if ($[43] === Symbol.for("react.memo_cache_sentinel")) {
198
+ t15 = () => setExpanded(_temp);
199
+ $[43] = t15;
200
+ } else {
201
+ t15 = $[43];
202
+ }
203
+ const t16 = expanded ? "graphiql-qb-chevron-expanded" : "graphiql-qb-chevron-collapsed";
204
+ let t17;
205
+ if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
206
+ t17 = /* @__PURE__ */ jsx(ChevronDownIcon, {});
207
+ $[44] = t17;
208
+ } else {
209
+ t17 = $[44];
210
+ }
211
+ let t18;
212
+ if ($[45] !== t16) {
213
+ t18 = /* @__PURE__ */ jsx("span", { className: t16, children: t17 });
214
+ $[45] = t16;
215
+ $[46] = t18;
216
+ } else {
217
+ t18 = $[46];
218
+ }
219
+ let t19;
220
+ if ($[47] === Symbol.for("react.memo_cache_sentinel")) {
221
+ t19 = /* @__PURE__ */ jsx("span", { className: "graphiql-qb-possible-types-label", children: "Possible types" });
222
+ $[47] = t19;
223
+ } else {
224
+ t19 = $[47];
225
+ }
226
+ let t20;
227
+ if ($[48] !== typeConditions.length) {
228
+ t20 = /* @__PURE__ */ jsx("span", { className: "graphiql-qb-possible-types-count", children: typeConditions.length });
229
+ $[48] = typeConditions.length;
230
+ $[49] = t20;
231
+ } else {
232
+ t20 = $[49];
233
+ }
234
+ let t21;
235
+ if ($[50] !== expanded || $[51] !== t14 || $[52] !== t18 || $[53] !== t20) {
236
+ t21 = /* @__PURE__ */ jsxs("button", { type: "button", className: "graphiql-qb-field-toggle graphiql-qb-possible-types-header", style: t14, onClick: t15, "aria-expanded": expanded, children: [
237
+ t18,
238
+ t19,
239
+ t20
240
+ ] });
241
+ $[50] = expanded;
242
+ $[51] = t14;
243
+ $[52] = t18;
244
+ $[53] = t20;
245
+ $[54] = t21;
246
+ } else {
247
+ t21 = $[54];
248
+ }
249
+ const t22 = expanded && entries;
250
+ let t23;
251
+ if ($[55] !== t21 || $[56] !== t22) {
252
+ t23 = /* @__PURE__ */ jsxs("div", { className: "graphiql-qb-possible-types", children: [
253
+ t21,
254
+ t22
255
+ ] });
256
+ $[55] = t21;
257
+ $[56] = t22;
258
+ $[57] = t23;
259
+ } else {
260
+ t23 = $[57];
261
+ }
262
+ return t23;
263
+ };
264
+ const TypeConditionEntry = (t0) => {
265
+ const $ = c(48);
266
+ const {
267
+ fieldPath,
268
+ typeName,
269
+ concreteType,
270
+ isInterface,
271
+ isSelected
272
+ } = t0;
273
+ const {
274
+ cursorPath,
275
+ onAddInlineFragment,
276
+ onRemoveInlineFragment
277
+ } = useFieldTreeContext();
278
+ const [expanded, setExpanded] = useState(false);
279
+ let t1;
280
+ if ($[0] !== typeName) {
281
+ t1 = inlineFragmentSegment(typeName);
282
+ $[0] = typeName;
283
+ $[1] = t1;
284
+ } else {
285
+ t1 = $[1];
286
+ }
287
+ let t2;
288
+ if ($[2] !== fieldPath || $[3] !== t1) {
289
+ t2 = [...fieldPath, t1];
290
+ $[2] = fieldPath;
291
+ $[3] = t1;
292
+ $[4] = t2;
293
+ } else {
294
+ t2 = $[4];
295
+ }
296
+ const fragmentPath = t2;
297
+ const {
298
+ flash,
299
+ current,
300
+ nodeRef
301
+ } = useCursorReveal(fragmentPath, cursorPath, setExpanded);
302
+ let t3;
303
+ if ($[5] !== fieldPath || $[6] !== isSelected || $[7] !== onAddInlineFragment || $[8] !== onRemoveInlineFragment || $[9] !== typeName) {
304
+ t3 = function handleToggle2() {
305
+ if (isSelected) {
306
+ onRemoveInlineFragment == null ? void 0 : onRemoveInlineFragment(fieldPath, typeName);
307
+ } else {
308
+ onAddInlineFragment == null ? void 0 : onAddInlineFragment(fieldPath, typeName);
309
+ }
310
+ };
311
+ $[5] = fieldPath;
312
+ $[6] = isSelected;
313
+ $[7] = onAddInlineFragment;
314
+ $[8] = onRemoveInlineFragment;
315
+ $[9] = typeName;
316
+ $[10] = t3;
317
+ } else {
318
+ t3 = $[10];
319
+ }
320
+ const handleToggle = t3;
321
+ const t4 = `graphiql-qb-inline-fragment${flash ? " graphiql-qb-flash" : ""}${current ? " graphiql-qb-current" : ""}`;
322
+ const t5 = `calc(${fieldPath.length * 12}px + var(--px-8))`;
323
+ let t6;
324
+ if ($[11] !== t5) {
325
+ t6 = {
326
+ paddingLeft: t5
327
+ };
328
+ $[11] = t5;
329
+ $[12] = t6;
330
+ } else {
331
+ t6 = $[12];
332
+ }
333
+ const t7 = `Toggle ... on ${typeName}`;
334
+ let t8;
335
+ if ($[13] !== handleToggle || $[14] !== isSelected || $[15] !== t7) {
336
+ t8 = /* @__PURE__ */ jsx("input", { type: "checkbox", checked: isSelected, onChange: handleToggle, "aria-label": t7, className: "graphiql-qb-field-checkbox" });
337
+ $[13] = handleToggle;
338
+ $[14] = isSelected;
339
+ $[15] = t7;
340
+ $[16] = t8;
341
+ } else {
342
+ t8 = $[16];
343
+ }
344
+ let t9;
345
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
346
+ t9 = () => setExpanded(_temp2);
347
+ $[17] = t9;
348
+ } else {
349
+ t9 = $[17];
350
+ }
351
+ const t10 = `${expanded ? "Collapse" : "Expand"} ... on ${typeName}`;
352
+ const t11 = expanded ? "graphiql-qb-chevron-expanded" : "graphiql-qb-chevron-collapsed";
353
+ let t12;
354
+ if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
355
+ t12 = /* @__PURE__ */ jsx(ChevronDownIcon, {});
356
+ $[18] = t12;
357
+ } else {
358
+ t12 = $[18];
359
+ }
360
+ let t13;
361
+ if ($[19] !== t11) {
362
+ t13 = /* @__PURE__ */ jsx("span", { className: t11, children: t12 });
363
+ $[19] = t11;
364
+ $[20] = t13;
365
+ } else {
366
+ t13 = $[20];
367
+ }
368
+ let t14;
369
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
370
+ t14 = /* @__PURE__ */ jsx("span", { className: "graphiql-qb-spread", children: "..." });
371
+ $[21] = t14;
372
+ } else {
373
+ t14 = $[21];
374
+ }
375
+ let t15;
376
+ if ($[22] !== typeName) {
377
+ t15 = /* @__PURE__ */ jsx("span", { className: "graphiql-qb-type-name", children: typeName });
378
+ $[22] = typeName;
379
+ $[23] = t15;
380
+ } else {
381
+ t15 = $[23];
382
+ }
383
+ let t16;
384
+ if ($[24] !== isInterface) {
385
+ t16 = isInterface && /* @__PURE__ */ jsx("span", { className: "graphiql-qb-type-kind-tag", children: "interface" });
386
+ $[24] = isInterface;
387
+ $[25] = t16;
388
+ } else {
389
+ t16 = $[25];
390
+ }
391
+ let t17;
392
+ if ($[26] !== t15 || $[27] !== t16) {
393
+ t17 = /* @__PURE__ */ jsxs("span", { className: "graphiql-qb-inline-fragment-label", children: [
394
+ t14,
395
+ " on ",
396
+ t15,
397
+ t16
398
+ ] });
399
+ $[26] = t15;
400
+ $[27] = t16;
401
+ $[28] = t17;
402
+ } else {
403
+ t17 = $[28];
404
+ }
405
+ let t18;
406
+ if ($[29] !== expanded || $[30] !== t10 || $[31] !== t13 || $[32] !== t17) {
407
+ t18 = /* @__PURE__ */ jsxs("button", { type: "button", className: "graphiql-qb-field-toggle", onClick: t9, "aria-expanded": expanded, "aria-label": t10, children: [
408
+ t13,
409
+ t17
410
+ ] });
411
+ $[29] = expanded;
412
+ $[30] = t10;
413
+ $[31] = t13;
414
+ $[32] = t17;
415
+ $[33] = t18;
416
+ } else {
417
+ t18 = $[33];
418
+ }
419
+ let t19;
420
+ if ($[34] !== t18 || $[35] !== t6 || $[36] !== t8) {
421
+ t19 = /* @__PURE__ */ jsxs("div", { className: "graphiql-qb-inline-fragment-header", style: t6, children: [
422
+ t8,
423
+ t18
424
+ ] });
425
+ $[34] = t18;
426
+ $[35] = t6;
427
+ $[36] = t8;
428
+ $[37] = t19;
429
+ } else {
430
+ t19 = $[37];
431
+ }
432
+ let t20;
433
+ if ($[38] !== concreteType || $[39] !== expanded || $[40] !== fragmentPath || $[41] !== isInterface) {
434
+ t20 = expanded && /* @__PURE__ */ jsxs(Fragment, { children: [
435
+ /* @__PURE__ */ jsx(FieldTreeList, { type: concreteType, path: fragmentPath }),
436
+ isInterface && /* @__PURE__ */ jsx(TypeConditionSelector, { fieldPath: fragmentPath, abstractType: concreteType })
437
+ ] });
438
+ $[38] = concreteType;
439
+ $[39] = expanded;
440
+ $[40] = fragmentPath;
441
+ $[41] = isInterface;
442
+ $[42] = t20;
443
+ } else {
444
+ t20 = $[42];
445
+ }
446
+ let t21;
447
+ if ($[43] !== nodeRef || $[44] !== t19 || $[45] !== t20 || $[46] !== t4) {
448
+ t21 = /* @__PURE__ */ jsxs("div", { className: t4, ref: nodeRef, children: [
449
+ t19,
450
+ t20
451
+ ] });
452
+ $[43] = nodeRef;
453
+ $[44] = t19;
454
+ $[45] = t20;
455
+ $[46] = t4;
456
+ $[47] = t21;
457
+ } else {
458
+ t21 = $[47];
459
+ }
460
+ return t21;
461
+ };
462
+ function _temp(prev) {
463
+ return !prev;
464
+ }
465
+ function _temp2(prev) {
466
+ return !prev;
467
+ }
468
+ export {
469
+ TypeConditionSelector,
470
+ applicableTypeConditions
471
+ };
472
+ //# sourceMappingURL=type-condition-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-condition-selector.js","sources":["../../src/components/type-condition-selector.tsx"],"sourcesContent":["import { ChevronDownIcon } from '@graphiql/react';\nimport {\n isInterfaceType,\n isUnionType,\n type GraphQLAbstractType,\n type GraphQLInterfaceType,\n type GraphQLObjectType,\n type GraphQLSchema,\n} from 'graphql';\nimport { type FC, useEffect, useState } from 'react';\nimport {\n inlineFragmentSegment,\n isInlineFragmentPresent,\n segmentsEqual,\n} from '../lib/document-mutator';\nimport { type PathSegment } from '../lib/ast-path';\nimport { useFieldTreeContext } from './field-tree-context';\nimport { FieldTreeList } from './field-tree';\nimport { useCursorReveal } from './use-cursor-reveal';\n\n/**\n * The type conditions worth offering for an abstract field: every concrete\n * object type, plus (for interface fields) the other interfaces that share an\n * implementor, so you can narrow to a sibling/sub-interface (`... on Node`).\n * The field's own interface and the interfaces it already implements are\n * skipped, since those fields are selectable directly. A union contributes just\n * its member object types.\n */\nexport function applicableTypeConditions(\n abstractType: GraphQLAbstractType,\n schema: GraphQLSchema,\n): (GraphQLObjectType | GraphQLInterfaceType)[] {\n const objects = schema.getPossibleTypes(abstractType);\n if (!isInterfaceType(abstractType)) {\n return [...objects];\n }\n\n const skip = new Set<string>([\n abstractType.name,\n ...abstractType.getInterfaces().map(i => i.name),\n ]);\n const interfaces = new Map<string, GraphQLInterfaceType>();\n for (const object of objects) {\n for (const iface of object.getInterfaces()) {\n if (!skip.has(iface.name)) {\n interfaces.set(iface.name, iface);\n }\n }\n }\n return [...objects, ...interfaces.values()];\n}\n\n// ---------------------------------------------------------------------------\n// TypeConditionSelector\n// ---------------------------------------------------------------------------\n\ntype TypeConditionSelectorProps = {\n fieldPath: PathSegment[];\n abstractType: GraphQLAbstractType;\n};\n\nexport const TypeConditionSelector: FC<TypeConditionSelectorProps> = ({\n fieldPath,\n abstractType,\n}) => {\n const { doc, schema, target, cursorPath } = useFieldTreeContext();\n // Whether the document currently has a type condition selected under this\n // field. Recomputed each render so a fragment added after mount can open the\n // section (see the effect below).\n const hasSelectedCondition = (\n schema ? applicableTypeConditions(abstractType, schema) : []\n ).some(t => isInlineFragmentPresent(doc, fieldPath, t.name, target));\n const [expanded, setExpanded] = useState(hasSelectedCondition);\n\n // Open the section when a type condition becomes selected in the document.\n // Only opens, never force-closes, so the user can still collapse it manually.\n useEffect(() => {\n if (hasSelectedCondition) {\n setExpanded(true);\n }\n }, [hasSelectedCondition]);\n\n // Open the section when the editor cursor sits inside one of its type\n // conditions, so the reveal can cascade down to a field nested in a\n // `... on TypeName`. (A condition contributes an inlineFragment path segment\n // right after this field's path; a directly-selectable interface field does\n // not, so it won't force the section open.)\n const cursorInCondition =\n cursorPath !== undefined &&\n cursorPath.length > fieldPath.length &&\n fieldPath.every((seg, i) => segmentsEqual(cursorPath[i]!, seg)) &&\n cursorPath[fieldPath.length]?.kind === 'inlineFragment';\n useEffect(() => {\n if (cursorInCondition) {\n setExpanded(true);\n }\n }, [cursorPath, cursorInCondition]);\n\n if (!schema) {\n return null;\n }\n\n const typeConditions = applicableTypeConditions(abstractType, schema);\n\n if (typeConditions.length === 0) {\n return null;\n }\n\n const entries = (\n <div\n className=\"graphiql-qb-type-condition\"\n role=\"group\"\n aria-label={`Possible types for ${abstractType.name}`}\n >\n {typeConditions.map(conditionType => {\n const isSelected = isInlineFragmentPresent(\n doc,\n fieldPath,\n conditionType.name,\n target,\n );\n\n return (\n <TypeConditionEntry\n key={conditionType.name}\n fieldPath={fieldPath}\n typeName={conditionType.name}\n concreteType={conditionType}\n isInterface={isInterfaceType(conditionType)}\n isSelected={isSelected}\n />\n );\n })}\n </div>\n );\n\n // A union has no fields of its own, so its type conditions are the only\n // content under the field; render them directly rather than behind a\n // collapse. Interfaces fold them into a labeled, collapsible section.\n if (isUnionType(abstractType)) {\n return entries;\n }\n\n return (\n <div className=\"graphiql-qb-possible-types\">\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle graphiql-qb-possible-types-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-possible-types-label\">Possible types</span>\n <span className=\"graphiql-qb-possible-types-count\">\n {typeConditions.length}\n </span>\n </button>\n {expanded && entries}\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// TypeConditionEntry\n// ---------------------------------------------------------------------------\n\ntype TypeConditionEntryProps = {\n fieldPath: PathSegment[];\n typeName: string;\n concreteType: GraphQLObjectType | GraphQLInterfaceType;\n /** Whether this type condition is an interface (matches several types). */\n isInterface: boolean;\n isSelected: boolean;\n};\n\nconst TypeConditionEntry: FC<TypeConditionEntryProps> = ({\n fieldPath,\n typeName,\n concreteType,\n isInterface,\n isSelected,\n}) => {\n const { cursorPath, onAddInlineFragment, onRemoveInlineFragment } =\n useFieldTreeContext();\n const [expanded, setExpanded] = useState(false);\n const fragmentPath = [...fieldPath, inlineFragmentSegment(typeName)];\n const { flash, current, nodeRef } = useCursorReveal(\n fragmentPath,\n cursorPath,\n setExpanded,\n );\n\n function handleToggle() {\n if (isSelected) {\n onRemoveInlineFragment?.(fieldPath, typeName);\n } else {\n onAddInlineFragment?.(fieldPath, typeName);\n }\n }\n\n return (\n <div\n className={`graphiql-qb-inline-fragment${\n flash ? ' graphiql-qb-flash' : ''\n }${current ? ' graphiql-qb-current' : ''}`}\n ref={nodeRef}\n >\n <div\n className=\"graphiql-qb-inline-fragment-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n >\n <input\n type=\"checkbox\"\n checked={isSelected}\n onChange={handleToggle}\n aria-label={`Toggle ... on ${typeName}`}\n className=\"graphiql-qb-field-checkbox\"\n />\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle\"\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n aria-label={`${expanded ? 'Collapse' : 'Expand'} ... on ${typeName}`}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-inline-fragment-label\">\n <span className=\"graphiql-qb-spread\">...</span>\n {' on '}\n <span className=\"graphiql-qb-type-name\">{typeName}</span>\n {isInterface && (\n <span className=\"graphiql-qb-type-kind-tag\">interface</span>\n )}\n </span>\n </button>\n </div>\n {expanded && (\n <>\n <FieldTreeList type={concreteType} path={fragmentPath} />\n {/* When the condition is itself an interface, keep recursing: offer\n its own possible types so you can narrow further (`... on Node`\n then `... on Concrete`). */}\n {isInterface && (\n <TypeConditionSelector\n fieldPath={fragmentPath}\n abstractType={concreteType as GraphQLAbstractType}\n />\n )}\n </>\n )}\n </div>\n );\n};\n"],"names":["applicableTypeConditions","abstractType","schema","objects","getPossibleTypes","isInterfaceType","skip","Set","name","getInterfaces","map","i","interfaces","Map","object","iface","has","set","values","TypeConditionSelector","t0","$","_c","fieldPath","doc","target","cursorPath","useFieldTreeContext","t1","t2","t","isInlineFragmentPresent","some","hasSelectedCondition","expanded","setExpanded","useState","t3","useEffect","t4","undefined","length","every","seg","segmentsEqual","kind","cursorInCondition","t5","t6","t10","t11","t7","t8","t9","typeConditions","Symbol","for","bb0","t12","conditionType","isSelected","entries","isUnionType","t13","t14","paddingLeft","t15","_temp","t16","t17","t18","t19","t20","t21","t22","t23","TypeConditionEntry","typeName","concreteType","isInterface","onAddInlineFragment","onRemoveInlineFragment","inlineFragmentSegment","fragmentPath","flash","current","nodeRef","useCursorReveal","handleToggle","_temp2","prev"],"mappings":";;;;;;;;;;AA4BgBA,SAAAA,yBACdC,cACAC,QAC8C;AACxCC,QAAAA,UAAUD,OAAOE,iBAAiBH,YAAY;AAChD,MAAA,CAACI,gBAAgBJ,YAAY,GAAG;AAC3B,WAAA,CAAC,GAAGE,OAAO;AAAA,EAAA;AAGpB,QAAMG,OAAO,oBAAIC,IAAY,CAC3BN,aAAaO,MACb,GAAGP,aAAaQ,gBAAgBC,IAAIC,CAAAA,MAAKA,EAAEH,IAAI,CAAC,CACjD;AACKI,QAAAA,iCAAiBC,IAAkC;AACzD,aAAWC,UAAUX,SAAS;AACjBY,eAAAA,SAASD,OAAOL,iBAAiB;AAC1C,UAAI,CAACH,KAAKU,IAAID,MAAMP,IAAI,GAA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A,EAAA;AAAAoD,MAAAA;AAAA,MAAApD,EAAA,EAAA,MAAAiE,WAAAjE,EAAAkD,EAAAA,MAAAA,OAAAlD,EAAAmD,EAAAA,MAAAA,OAAAnD,UAAAkB,IAAA;AA1DHkC,UAAA,qBAAA,OAAA,EACa,WAAAlC,IAGN+C,cAELf,UAAAA;AAAAA,MAAAA;AAAAA,MAuCCC;AAAAA,IAAAA,GAcH;AAAMnD,YAAAiE;AAAAjE,YAAAkD;AAAAlD,YAAAmD;AAAAnD,YAAAkB;AAAAlB,YAAAoD;AAAAA,EAAAA,OAAA;AAAAA,UAAApD,EAAA,EAAA;AAAA,EAAA;AA3DNoD,SAAAA;AA2DM;AAlN2D,SAAAN,MAAAuB,MAAA;AAAA,SAAA,CA0FzBA;AAAI;AAmCQ,SAAAD,OAAAC,MAAA;AAAA,SAAA,CAgDVA;AAAI;"}
@@ -0,0 +1,16 @@
1
+ import { DefinitionTarget, PathSegment } from '../lib/ast-path';
2
+ export interface CursorContext {
3
+ /** The definition the cursor sits in, or undefined when it's outside one. */
4
+ target: DefinitionTarget | undefined;
5
+ /** Field path under the cursor within `target`; empty when not on a field. */
6
+ path: PathSegment[];
7
+ }
8
+ /**
9
+ * Tracks the definition (operation or fragment) and field path under the editor
10
+ * cursor. The builder follows this: the cursor's definition is the one being
11
+ * edited, and the path expands the tree down to the cursor. Subscribes to the
12
+ * query editor directly (debounced to avoid thrashing while typing), reacting
13
+ * only to explicit user cursor moves — not the cursor resets our own writes
14
+ * cause.
15
+ */
16
+ export declare function useCursorContext(): CursorContext;
@@ -0,0 +1,79 @@
1
+ import { c } from "react-compiler-runtime";
2
+ import { useGraphiQL, useMonaco } from "@graphiql/react";
3
+ import { parse } from "graphql";
4
+ import { useState, useEffect } from "react";
5
+ import { cursorContextAtOffset } from "../lib/schema-walk.js";
6
+ const EMPTY_CONTEXT = {
7
+ target: void 0,
8
+ path: []
9
+ };
10
+ function useCursorContext() {
11
+ const $ = c(6);
12
+ const queryEditor = useGraphiQL(_temp);
13
+ const monaco = useMonaco(_temp2);
14
+ const [context, setContext] = useState(EMPTY_CONTEXT);
15
+ let t0;
16
+ if ($[0] !== (monaco == null ? void 0 : monaco.editor) || $[1] !== queryEditor) {
17
+ t0 = () => {
18
+ if (!queryEditor) {
19
+ return;
20
+ }
21
+ let timer;
22
+ const recompute = () => {
23
+ const model = queryEditor.getModel();
24
+ const pos = queryEditor.getPosition();
25
+ if (!model || !pos) {
26
+ return;
27
+ }
28
+ const offset = model.getOffsetAt(pos);
29
+ let resolved;
30
+ try {
31
+ resolved = cursorContextAtOffset(parse(model.getValue()), offset);
32
+ } catch {
33
+ return;
34
+ }
35
+ setContext(resolved ?? EMPTY_CONTEXT);
36
+ };
37
+ const schedule = () => {
38
+ clearTimeout(timer);
39
+ timer = setTimeout(recompute, 80);
40
+ };
41
+ const disposable = queryEditor.onDidChangeCursorPosition((e) => {
42
+ if (e.reason === (monaco == null ? void 0 : monaco.editor.CursorChangeReason.Explicit)) {
43
+ schedule();
44
+ }
45
+ });
46
+ recompute();
47
+ return () => {
48
+ clearTimeout(timer);
49
+ disposable.dispose();
50
+ };
51
+ };
52
+ $[0] = monaco == null ? void 0 : monaco.editor;
53
+ $[1] = queryEditor;
54
+ $[2] = t0;
55
+ } else {
56
+ t0 = $[2];
57
+ }
58
+ let t1;
59
+ if ($[3] !== monaco || $[4] !== queryEditor) {
60
+ t1 = [queryEditor, monaco];
61
+ $[3] = monaco;
62
+ $[4] = queryEditor;
63
+ $[5] = t1;
64
+ } else {
65
+ t1 = $[5];
66
+ }
67
+ useEffect(t0, t1);
68
+ return context;
69
+ }
70
+ function _temp2(state_0) {
71
+ return state_0.monaco;
72
+ }
73
+ function _temp(state) {
74
+ return state.queryEditor;
75
+ }
76
+ export {
77
+ useCursorContext
78
+ };
79
+ //# sourceMappingURL=use-cursor-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-cursor-path.js","sources":["../../src/components/use-cursor-path.ts"],"sourcesContent":["import { useGraphiQL, useMonaco } from '@graphiql/react';\nimport { parse } from 'graphql';\nimport { useEffect, useState } from 'react';\nimport { type DefinitionTarget, type PathSegment } from '../lib/ast-path';\nimport { cursorContextAtOffset } from '../lib/schema-walk';\n\nexport interface CursorContext {\n /** The definition the cursor sits in, or undefined when it's outside one. */\n target: DefinitionTarget | undefined;\n /** Field path under the cursor within `target`; empty when not on a field. */\n path: PathSegment[];\n}\n\nconst EMPTY_CONTEXT: CursorContext = { target: undefined, path: [] };\n\n/**\n * Tracks the definition (operation or fragment) and field path under the editor\n * cursor. The builder follows this: the cursor's definition is the one being\n * edited, and the path expands the tree down to the cursor. Subscribes to the\n * query editor directly (debounced to avoid thrashing while typing), reacting\n * only to explicit user cursor moves — not the cursor resets our own writes\n * cause.\n */\nexport function useCursorContext(): CursorContext {\n const queryEditor = useGraphiQL(state => state.queryEditor);\n const monaco = useMonaco(state => state.monaco);\n\n const [context, setContext] = useState<CursorContext>(EMPTY_CONTEXT);\n useEffect(() => {\n if (!queryEditor) {\n return;\n }\n let timer: ReturnType<typeof setTimeout> | undefined;\n const recompute = () => {\n const model = queryEditor.getModel();\n const pos = queryEditor.getPosition();\n if (!model || !pos) {\n return;\n }\n const offset = model.getOffsetAt(pos);\n let resolved:\n | { target: DefinitionTarget | undefined; path: PathSegment[] }\n | undefined;\n try {\n resolved = cursorContextAtOffset(parse(model.getValue()), offset);\n } catch {\n // Unparseable in-progress edit — leave the context as-is.\n return;\n }\n setContext(resolved ?? EMPTY_CONTEXT);\n };\n const schedule = () => {\n clearTimeout(timer);\n timer = setTimeout(recompute, 80);\n };\n const disposable = queryEditor.onDidChangeCursorPosition(e => {\n // Only react to explicit (user) cursor moves, not content-flush/programmatic ones.\n if (e.reason === monaco?.editor.CursorChangeReason.Explicit) {\n schedule();\n }\n });\n recompute();\n return () => {\n clearTimeout(timer);\n disposable.dispose();\n };\n }, [queryEditor, monaco]);\n\n return context;\n}\n"],"names":["EMPTY_CONTEXT","target","undefined","path","useCursorContext","$","_c","queryEditor","useGraphiQL","_temp","monaco","useMonaco","_temp2","context","setContext","useState","t0","editor","timer","recompute","model","getModel","pos","getPosition","offset","getOffsetAt","resolved","getValue","schedule","clearTimeout","disposable","onDidChangeCursorPosition","e","reason","CursorChangeReason","Explicit","dispose","t1","useEffect","state_0","state"],"mappings":";;;;;AAaA,MAAMA,gBAA+B;AAAA,EAAEC,QAAQC;AAAAA,EAAWC,MAAM,CAAA;AAAG;AAU5D,SAAAC,mBAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AACLC,QAAAA,cAAoBC,YAAAC,KAAsC;AAC1DC,QAAAA,SAAeC,UAAAC,MAA+B;AAE9C,QAAA,CAAAC,SAAAC,UAAA,IAA8BC,SAAAf,aAAqC;AAAEgB,MAAAA;AAAAX,MAAAA,UAAAK,iCAAAO,WAAAZ,SAAAE,aAAA;AAC3DS,SAAAA,MAAA;AAAA,UAAA,CACHT,aAAW;AAAA;AAAA,MAAA;AAGZW,UAAAA;AACJ,YAAAC,YAAAA,MAAA;AACEC,cAAAA,QAAcb,YAAWc,SAAU;AACnCC,cAAAA,MAAYf,YAAWgB,YAAa;AAChC,YAAA,CAACH,SAAK,CAAKE,KAAG;AAAA;AAAA,QAAA;AAGlBE,cAAAA,SAAeJ,MAAKK,YAAaH,GAAG;AAChCI,YAAAA;AAES,YAAA;AAEXA,qBAAWA,sBAAsBA,MAAMN,MAAKO,SAAU,CAAC,GAAGH,MAAM;AAAA,QAAA,QAAxD;AAAA;AAAA,QAAA;AAKVV,mBAAWY,YAAQ1B,aAAiB;AAAA,MAAC;AAEvC,YAAA4B,WAAAA,MAAA;AACEC,qBAAaX,KAAK;AACVA,gBAAAA,WAAWC,aAAa;AAAA,MAA3B;AAEPW,YAAAA,aAAmBvB,YAAWwB,0BAAAC,CAAA,MAAA;AAAA,YAExBA,EAACC,YAAYvB,iCAAMO,OAAAiB,mBAAAC,WAAoC;AAChD,mBAAA;AAAA,QAAA;AAAA,MAAC,CAEb;AACS,gBAAA;AAAC,aAAA,MAAA;AAETN,qBAAaX,KAAK;AAClBY,mBAAUM,QAAS;AAAA,MAAC;AAAA,IAAA;AAEvB,MAAA,CAAA,IAAA1B,iCAAAO;AAAAZ,WAAAE;AAAAF,WAAAW;AAAAA,EAAAA,OAAA;AAAAA,SAAAX,EAAA,CAAA;AAAA,EAAA;AAAAgC,MAAAA;AAAA,MAAAhC,EAAAK,CAAAA,MAAAA,UAAAL,SAAAE,aAAA;AAAE,SAAA,CAACA,aAAaG,MAAM;AAACL,WAAAK;AAAAL,WAAAE;AAAAF,WAAAgC;AAAAA,EAAAA,OAAA;AAAAA,SAAAhC,EAAA,CAAA;AAAA,EAAA;AAtCxBiC,YAAUtB,IAsCPqB,EAAqB;AAEjBxB,SAAAA;AAAO;AA7CT,SAAAD,OAAA2B,SAAA;AAAA,SAE6BC,QAAK9B;AAAA;AAFlC,SAAAD,MAAA+B,OAAA;AAAA,SACoCA,MAAKjC;AAAA;"}
@@ -0,0 +1,15 @@
1
+ import { PathSegment } from '../lib/ast-path';
2
+ /**
3
+ * Reveals a tree node as the editor cursor moves onto it or a descendant:
4
+ * auto-expands it when it's an ancestor of the cursor's field, and (only when
5
+ * the cursor lands exactly on it) flashes it, scrolls it into view, and marks it
6
+ * as the current node so the row can show a persistent highlight. Ancestors
7
+ * expand but neither flash nor highlight, to keep the "you are here" signal on
8
+ * the one field the cursor sits in. Shared by field rows and inline-fragment
9
+ * rows so both react to the cursor.
10
+ */
11
+ export declare function useCursorReveal(fullPath: PathSegment[], cursorPath: PathSegment[] | undefined, setExpanded: (value: boolean) => void): {
12
+ flash: boolean;
13
+ current: boolean;
14
+ nodeRef: import('react').RefObject<HTMLDivElement | null>;
15
+ };