@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,548 +1,453 @@
1
- import { c } from "react-compiler-runtime";
2
- import { useGraphiQL, useGraphiQLActions } from "@graphiql/react";
3
- import { parse, print, Kind, getNamedType, valueFromASTUntyped, parseValue } from "graphql";
4
- import { useState, useRef, useEffect } from "react";
5
- import { findOperation, definitionSelectionOffset, findDefinition } from "../lib/ast-path.js";
6
- import { readVariables, resolveSchemaArg, resolveSchemaArgFromRoot, extractRawArgValue } from "../lib/schema-walk.js";
7
- import { useCursorContext } from "./use-cursor-path.js";
8
- import { toggleFieldSelection } from "../lib/field-selection.js";
1
+ import { definitionSelectionOffset, findDefinition, findOperation } from "../lib/ast-path.js";
2
+ import { extractRawArgValue, readVariables, resolveSchemaArg, resolveSchemaArgFromRoot } from "../lib/schema-walk.js";
9
3
  import { argValueToValueNode } from "../lib/arg-value.js";
4
+ import { toggleFieldSelection } from "../lib/field-selection.js";
10
5
  import { setFieldArgument } from "../lib/arguments.js";
11
- import { suggestVarName, promoteArgToVariable, demoteVariable } from "../lib/variables.js";
6
+ import { demoteVariable, promoteArgToVariable, suggestVarName } from "../lib/variables.js";
7
+ import { createFragmentFromSelection, inlineFragment, listFragments, removeFragmentSpread, renameFragment } from "../lib/fragments.js";
12
8
  import { addInlineFragment, removeInlineFragment } from "../lib/inline-fragments.js";
13
- import { removeFragmentSpread, listFragments, createFragmentFromSelection, renameFragment, inlineFragment } from "../lib/fragments.js";
9
+ import { useCursorContext } from "./use-cursor-path.js";
10
+ import { useGraphiQL, useGraphiQLActions } from "@graphiql/react";
11
+ import { c } from "react-compiler-runtime";
12
+ import { Kind, getNamedType, parse, parseValue, print, valueFromASTUntyped } from "graphql";
13
+ import { useEffect, useRef, useState } from "react";
14
+ //#region src/components/use-working-document.ts
15
+ /**
16
+ * Parse query text into a DocumentNode, or null when it's empty or unparseable
17
+ * (callers keep the last valid document instead).
18
+ */
14
19
  function tryParse(text) {
15
- const src = text == null ? void 0 : text.trim();
16
- if (!src) {
17
- return null;
18
- }
19
- try {
20
- return parse(src);
21
- } catch {
22
- return null;
23
- }
20
+ const src = text?.trim();
21
+ if (!src) return null;
22
+ try {
23
+ return parse(src);
24
+ } catch {
25
+ return null;
26
+ }
24
27
  }
28
+ /** A minimal valid document used to seed the builder when there's no query. */
25
29
  function emptyDoc() {
26
- return parse("{ __typename }");
30
+ return parse("{ __typename }");
27
31
  }
32
+ /**
33
+ * Owns the working document: its state, editor write-back, echo-suppression,
34
+ * external-edit sync, and all document-mutation handlers.
35
+ */
28
36
  function useWorkingDocument() {
29
- var _a, _b, _c, _d, _e;
30
- const $ = c(105);
31
- const schema = useGraphiQL(_temp);
32
- const queryEditor = useGraphiQL(_temp2);
33
- const variableEditor = useGraphiQL(_temp3);
34
- const operationName = useGraphiQL(_temp4);
35
- const {
36
- updateActiveTabValues
37
- } = useGraphiQLActions();
38
- const activeTabIndex = useGraphiQL(_temp5);
39
- const tabs = useGraphiQL(_temp6);
40
- const queryText = (_a = tabs[activeTabIndex]) == null ? void 0 : _a.query;
41
- const variablesText = (_b = tabs[activeTabIndex]) == null ? void 0 : _b.variables;
42
- let t0;
43
- if ($[0] !== queryText) {
44
- t0 = () => tryParse(queryText) ?? emptyDoc();
45
- $[0] = queryText;
46
- $[1] = t0;
47
- } else {
48
- t0 = $[1];
49
- }
50
- const [workingDoc, setWorkingDoc] = useState(t0);
51
- const lastSyncedRef = useRef(queryText ?? null);
52
- let t1;
53
- if ($[2] !== queryEditor || $[3] !== updateActiveTabValues) {
54
- t1 = (printed) => {
55
- if (queryEditor) {
56
- const position = queryEditor.getPosition();
57
- queryEditor.setValue(printed);
58
- if (position) {
59
- queryEditor.setPosition(position);
60
- }
61
- lastSyncedRef.current = queryEditor.getValue();
62
- return;
63
- }
64
- lastSyncedRef.current = printed;
65
- updateActiveTabValues({
66
- query: printed
67
- });
68
- };
69
- $[2] = queryEditor;
70
- $[3] = updateActiveTabValues;
71
- $[4] = t1;
72
- } else {
73
- t1 = $[4];
74
- }
75
- const writeToEditor = t1;
76
- let t2;
77
- let t3;
78
- if ($[5] !== queryText) {
79
- t2 = () => {
80
- if (queryText === lastSyncedRef.current) {
81
- return;
82
- }
83
- lastSyncedRef.current = queryText ?? null;
84
- const parsed = tryParse(queryText);
85
- if (parsed) {
86
- setWorkingDoc(parsed);
87
- } else {
88
- if (!(queryText == null ? void 0 : queryText.trim())) {
89
- setWorkingDoc(emptyDoc());
90
- }
91
- }
92
- };
93
- t3 = [queryText];
94
- $[5] = queryText;
95
- $[6] = t2;
96
- $[7] = t3;
97
- } else {
98
- t2 = $[6];
99
- t3 = $[7];
100
- }
101
- useEffect(t2, t3);
102
- let t4;
103
- if ($[8] !== operationName || $[9] !== workingDoc) {
104
- t4 = (_c = findOperation(workingDoc, operationName)) == null ? void 0 : _c.operation;
105
- $[8] = operationName;
106
- $[9] = workingDoc;
107
- $[10] = t4;
108
- } else {
109
- t4 = $[10];
110
- }
111
- const activeOpKind = t4;
112
- const cursor = useCursorContext();
113
- const [activeFragment, setActiveFragment] = useState(null);
114
- const cursorFragment = ((_d = cursor.target) == null ? void 0 : _d.kind) === "fragment" ? cursor.target.name : ((_e = cursor.target) == null ? void 0 : _e.kind) === "operation" ? null : void 0;
115
- let t5;
116
- let t6;
117
- if ($[11] !== cursorFragment) {
118
- t5 = () => {
119
- if (cursorFragment !== void 0) {
120
- setActiveFragment(cursorFragment);
121
- }
122
- };
123
- t6 = [cursorFragment];
124
- $[11] = cursorFragment;
125
- $[12] = t5;
126
- $[13] = t6;
127
- } else {
128
- t5 = $[12];
129
- t6 = $[13];
130
- }
131
- useEffect(t5, t6);
132
- let t7;
133
- if ($[14] !== activeFragment || $[15] !== operationName) {
134
- t7 = activeFragment != null ? {
135
- kind: "fragment",
136
- name: activeFragment
137
- } : {
138
- kind: "operation",
139
- name: operationName
140
- };
141
- $[14] = activeFragment;
142
- $[15] = operationName;
143
- $[16] = t7;
144
- } else {
145
- t7 = $[16];
146
- }
147
- const target = t7;
148
- const cursorInTarget = cursor.target != null && (activeFragment != null ? cursor.target.kind === "fragment" && cursor.target.name === activeFragment : cursor.target.kind === "operation");
149
- const cursorPath = cursorInTarget ? cursor.path : void 0;
150
- let t8;
151
- if ($[17] !== queryEditor) {
152
- t8 = function moveCursorToTarget2(next) {
153
- setActiveFragment(next.kind === "fragment" ? next.name : null);
154
- if (!queryEditor) {
155
- return;
156
- }
157
- const model = queryEditor.getModel();
158
- if (!model) {
159
- return;
160
- }
161
- let offset;
162
- try {
163
- offset = definitionSelectionOffset(parse(model.getValue()), next);
164
- } catch {
165
- return;
166
- }
167
- if (offset != null) {
168
- queryEditor.setPosition(model.getPositionAt(offset));
169
- }
170
- };
171
- $[17] = queryEditor;
172
- $[18] = t8;
173
- } else {
174
- t8 = $[18];
175
- }
176
- const moveCursorToTarget = t8;
177
- let t9;
178
- if ($[19] !== moveCursorToTarget) {
179
- t9 = function handleFocusFragment2(fragmentName) {
180
- moveCursorToTarget({
181
- kind: "fragment",
182
- name: fragmentName
183
- });
184
- };
185
- $[19] = moveCursorToTarget;
186
- $[20] = t9;
187
- } else {
188
- t9 = $[20];
189
- }
190
- const handleFocusFragment = t9;
191
- let t10;
192
- if ($[21] !== moveCursorToTarget || $[22] !== operationName) {
193
- t10 = function handleBackToQuery2() {
194
- moveCursorToTarget({
195
- kind: "operation",
196
- name: operationName
197
- });
198
- };
199
- $[21] = moveCursorToTarget;
200
- $[22] = operationName;
201
- $[23] = t10;
202
- } else {
203
- t10 = $[23];
204
- }
205
- const handleBackToQuery = t10;
206
- let t11;
207
- if ($[24] !== writeToEditor) {
208
- t11 = function applyDoc2(next_0) {
209
- setWorkingDoc(next_0);
210
- writeToEditor(print(next_0));
211
- };
212
- $[24] = writeToEditor;
213
- $[25] = t11;
214
- } else {
215
- t11 = $[25];
216
- }
217
- const applyDoc = t11;
218
- let t12;
219
- if ($[26] !== updateActiveTabValues || $[27] !== variableEditor) {
220
- t12 = function applyVariables2(next_1) {
221
- const serialized = Object.keys(next_1).length ? JSON.stringify(next_1, null, 2) : "";
222
- if (variableEditor) {
223
- variableEditor.setValue(serialized);
224
- } else {
225
- updateActiveTabValues({
226
- variables: serialized
227
- });
228
- }
229
- };
230
- $[26] = updateActiveTabValues;
231
- $[27] = variableEditor;
232
- $[28] = t12;
233
- } else {
234
- t12 = $[28];
235
- }
236
- const applyVariables = t12;
237
- let t13;
238
- if ($[29] !== applyVariables || $[30] !== variablesText) {
239
- t13 = function reconcileVariablesJson2(next_2) {
240
- const definedVars = /* @__PURE__ */ new Set();
241
- for (const def of next_2.definitions) {
242
- if (def.kind === Kind.OPERATION_DEFINITION) {
243
- for (const vd of def.variableDefinitions ?? []) {
244
- definedVars.add(vd.variable.name.value);
245
- }
246
- }
247
- }
248
- const vars = readVariables(variablesText);
249
- if (Object.keys(vars).some((name_0) => !definedVars.has(name_0))) {
250
- const reconciled = {};
251
- for (const [name, value] of Object.entries(vars)) {
252
- if (definedVars.has(name)) {
253
- reconciled[name] = value;
254
- }
255
- }
256
- applyVariables(reconciled);
257
- }
258
- };
259
- $[29] = applyVariables;
260
- $[30] = variablesText;
261
- $[31] = t13;
262
- } else {
263
- t13 = $[31];
264
- }
265
- const reconcileVariablesJson = t13;
266
- let t14;
267
- if ($[32] !== applyDoc || $[33] !== reconcileVariablesJson || $[34] !== target || $[35] !== workingDoc) {
268
- t14 = function handleToggle2(path) {
269
- const next_3 = toggleFieldSelection(workingDoc, path, target);
270
- applyDoc(next_3);
271
- reconcileVariablesJson(next_3);
272
- };
273
- $[32] = applyDoc;
274
- $[33] = reconcileVariablesJson;
275
- $[34] = target;
276
- $[35] = workingDoc;
277
- $[36] = t14;
278
- } else {
279
- t14 = $[36];
280
- }
281
- const handleToggle = t14;
282
- let t15;
283
- if ($[37] !== activeOpKind || $[38] !== schema || $[39] !== target || $[40] !== workingDoc) {
284
- t15 = function schemaArgFor2(path_0, argName) {
285
- if (!schema) {
286
- return;
287
- }
288
- if (target.kind === "operation") {
289
- return resolveSchemaArg(schema, activeOpKind, path_0, argName);
290
- }
291
- const def_0 = findDefinition(workingDoc, target);
292
- const rootTypeName = (def_0 == null ? void 0 : def_0.kind) === Kind.FRAGMENT_DEFINITION ? def_0.typeCondition.name.value : void 0;
293
- const rootType = rootTypeName ? schema.getType(rootTypeName) ?? void 0 : void 0;
294
- return resolveSchemaArgFromRoot(schema, rootType, path_0, argName);
295
- };
296
- $[37] = activeOpKind;
297
- $[38] = schema;
298
- $[39] = target;
299
- $[40] = workingDoc;
300
- $[41] = t15;
301
- } else {
302
- t15 = $[41];
303
- }
304
- const schemaArgFor = t15;
305
- let t16;
306
- if ($[42] !== applyDoc || $[43] !== schemaArgFor || $[44] !== target || $[45] !== workingDoc) {
307
- t16 = function handleSetArg2(path_1, argName_0, value_0) {
308
- const schemaArg = schemaArgFor(path_1, argName_0);
309
- if (!schemaArg) {
310
- return;
311
- }
312
- const valueNode = argValueToValueNode(schemaArg.type, value_0);
313
- applyDoc(setFieldArgument(workingDoc, path_1, argName_0, valueNode, target));
314
- };
315
- $[42] = applyDoc;
316
- $[43] = schemaArgFor;
317
- $[44] = target;
318
- $[45] = workingDoc;
319
- $[46] = t16;
320
- } else {
321
- t16 = $[46];
322
- }
323
- const handleSetArg = t16;
324
- let t17;
325
- if ($[47] !== applyDoc || $[48] !== applyVariables || $[49] !== operationName || $[50] !== schemaArgFor || $[51] !== variablesText || $[52] !== workingDoc) {
326
- t17 = function handlePromoteArg2(path_2, argName_1, suggestedName) {
327
- const schemaArg_0 = schemaArgFor(path_2, argName_1);
328
- if (!schemaArg_0) {
329
- return;
330
- }
331
- const namedType = getNamedType(schemaArg_0.type);
332
- if (!namedType) {
333
- return;
334
- }
335
- const varName = suggestVarName(workingDoc, suggestedName);
336
- const raw = extractRawArgValue(workingDoc, path_2, argName_1, operationName);
337
- applyDoc(promoteArgToVariable(workingDoc, path_2, argName_1, varName, namedType.name, "", operationName));
338
- if (raw) {
339
- try {
340
- const jsValue = valueFromASTUntyped(parseValue(raw));
341
- applyVariables({
342
- ...readVariables(variablesText),
343
- [varName]: jsValue
344
- });
345
- } catch {
346
- }
347
- }
348
- };
349
- $[47] = applyDoc;
350
- $[48] = applyVariables;
351
- $[49] = operationName;
352
- $[50] = schemaArgFor;
353
- $[51] = variablesText;
354
- $[52] = workingDoc;
355
- $[53] = t17;
356
- } else {
357
- t17 = $[53];
358
- }
359
- const handlePromoteArg = t17;
360
- let t18;
361
- if ($[54] !== applyDoc || $[55] !== applyVariables || $[56] !== operationName || $[57] !== schemaArgFor || $[58] !== variablesText || $[59] !== workingDoc) {
362
- t18 = function handleDemoteArg2(path_3, argName_2, varName_0) {
363
- const vars_0 = readVariables(variablesText);
364
- const jsValue_0 = vars_0[varName_0];
365
- const schemaArg_1 = schemaArgFor(path_3, argName_2);
366
- let inlineValue;
367
- if (schemaArg_1 && jsValue_0 !== void 0) {
368
- inlineValue = argValueToValueNode(schemaArg_1.type, String(jsValue_0));
369
- }
370
- applyDoc(demoteVariable(workingDoc, varName_0, operationName, inlineValue));
371
- const rest = {
372
- ...vars_0
373
- };
374
- delete rest[varName_0];
375
- applyVariables(rest);
376
- };
377
- $[54] = applyDoc;
378
- $[55] = applyVariables;
379
- $[56] = operationName;
380
- $[57] = schemaArgFor;
381
- $[58] = variablesText;
382
- $[59] = workingDoc;
383
- $[60] = t18;
384
- } else {
385
- t18 = $[60];
386
- }
387
- const handleDemoteArg = t18;
388
- let t19;
389
- if ($[61] !== applyDoc || $[62] !== target || $[63] !== workingDoc) {
390
- t19 = function handleAddInlineFragment2(path_4, typeName) {
391
- applyDoc(addInlineFragment(workingDoc, path_4, typeName, target));
392
- };
393
- $[61] = applyDoc;
394
- $[62] = target;
395
- $[63] = workingDoc;
396
- $[64] = t19;
397
- } else {
398
- t19 = $[64];
399
- }
400
- const handleAddInlineFragment = t19;
401
- let t20;
402
- if ($[65] !== applyDoc || $[66] !== reconcileVariablesJson || $[67] !== target || $[68] !== workingDoc) {
403
- t20 = function handleRemoveInlineFragment2(path_5, typeName_0) {
404
- const next_4 = removeInlineFragment(workingDoc, path_5, typeName_0, target);
405
- applyDoc(next_4);
406
- reconcileVariablesJson(next_4);
407
- };
408
- $[65] = applyDoc;
409
- $[66] = reconcileVariablesJson;
410
- $[67] = target;
411
- $[68] = workingDoc;
412
- $[69] = t20;
413
- } else {
414
- t20 = $[69];
415
- }
416
- const handleRemoveInlineFragment = t20;
417
- let t21;
418
- if ($[70] !== applyDoc || $[71] !== reconcileVariablesJson || $[72] !== target || $[73] !== workingDoc) {
419
- t21 = function handleRemoveFragmentSpread2(path_6, fragmentName_0) {
420
- const next_5 = removeFragmentSpread(workingDoc, path_6, fragmentName_0, target);
421
- applyDoc(next_5);
422
- reconcileVariablesJson(next_5);
423
- };
424
- $[70] = applyDoc;
425
- $[71] = reconcileVariablesJson;
426
- $[72] = target;
427
- $[73] = workingDoc;
428
- $[74] = t21;
429
- } else {
430
- t21 = $[74];
431
- }
432
- const handleRemoveFragmentSpread = t21;
433
- let t22;
434
- if ($[75] !== applyDoc || $[76] !== target || $[77] !== workingDoc) {
435
- t22 = function handleExtractFragment2(path_7, typeName_1) {
436
- const base = `${typeName_1}Fields`;
437
- const existing = new Set(listFragments(workingDoc));
438
- let name_1 = base;
439
- for (let n = 2; existing.has(name_1); n++) {
440
- name_1 = `${base}_${n}`;
441
- }
442
- applyDoc(createFragmentFromSelection(workingDoc, path_7, name_1, typeName_1, target));
443
- };
444
- $[75] = applyDoc;
445
- $[76] = target;
446
- $[77] = workingDoc;
447
- $[78] = t22;
448
- } else {
449
- t22 = $[78];
450
- }
451
- const handleExtractFragment = t22;
452
- let t23;
453
- if ($[79] !== applyDoc || $[80] !== workingDoc) {
454
- t23 = function handleRenameFragment2(oldName, newName) {
455
- applyDoc(renameFragment(workingDoc, oldName, newName));
456
- };
457
- $[79] = applyDoc;
458
- $[80] = workingDoc;
459
- $[81] = t23;
460
- } else {
461
- t23 = $[81];
462
- }
463
- const handleRenameFragment = t23;
464
- let t24;
465
- if ($[82] !== activeFragment || $[83] !== applyDoc || $[84] !== moveCursorToTarget || $[85] !== operationName || $[86] !== workingDoc) {
466
- t24 = function handleDeleteFragment2(fragmentName_1) {
467
- applyDoc(inlineFragment(workingDoc, fragmentName_1));
468
- if (activeFragment === fragmentName_1) {
469
- moveCursorToTarget({
470
- kind: "operation",
471
- name: operationName
472
- });
473
- }
474
- };
475
- $[82] = activeFragment;
476
- $[83] = applyDoc;
477
- $[84] = moveCursorToTarget;
478
- $[85] = operationName;
479
- $[86] = workingDoc;
480
- $[87] = t24;
481
- } else {
482
- t24 = $[87];
483
- }
484
- const handleDeleteFragment = t24;
485
- let t25;
486
- if ($[88] !== activeOpKind || $[89] !== cursorPath || $[90] !== handleAddInlineFragment || $[91] !== handleBackToQuery || $[92] !== handleDeleteFragment || $[93] !== handleDemoteArg || $[94] !== handleExtractFragment || $[95] !== handleFocusFragment || $[96] !== handlePromoteArg || $[97] !== handleRemoveFragmentSpread || $[98] !== handleRemoveInlineFragment || $[99] !== handleRenameFragment || $[100] !== handleSetArg || $[101] !== handleToggle || $[102] !== target || $[103] !== workingDoc) {
487
- t25 = {
488
- workingDoc,
489
- activeOpKind,
490
- target,
491
- cursorPath,
492
- handleFocusFragment,
493
- handleBackToQuery,
494
- handleToggle,
495
- handleSetArg,
496
- handlePromoteArg,
497
- handleDemoteArg,
498
- handleAddInlineFragment,
499
- handleRemoveInlineFragment,
500
- handleRemoveFragmentSpread,
501
- handleExtractFragment,
502
- handleRenameFragment,
503
- handleDeleteFragment
504
- };
505
- $[88] = activeOpKind;
506
- $[89] = cursorPath;
507
- $[90] = handleAddInlineFragment;
508
- $[91] = handleBackToQuery;
509
- $[92] = handleDeleteFragment;
510
- $[93] = handleDemoteArg;
511
- $[94] = handleExtractFragment;
512
- $[95] = handleFocusFragment;
513
- $[96] = handlePromoteArg;
514
- $[97] = handleRemoveFragmentSpread;
515
- $[98] = handleRemoveInlineFragment;
516
- $[99] = handleRenameFragment;
517
- $[100] = handleSetArg;
518
- $[101] = handleToggle;
519
- $[102] = target;
520
- $[103] = workingDoc;
521
- $[104] = t25;
522
- } else {
523
- t25 = $[104];
524
- }
525
- return t25;
37
+ const $ = c(105);
38
+ const schema = useGraphiQL(_temp);
39
+ const queryEditor = useGraphiQL(_temp2);
40
+ const variableEditor = useGraphiQL(_temp3);
41
+ const operationName = useGraphiQL(_temp4);
42
+ const { updateActiveTabValues } = useGraphiQLActions();
43
+ const activeTabIndex = useGraphiQL(_temp5);
44
+ const tabs = useGraphiQL(_temp6);
45
+ const queryText = tabs[activeTabIndex]?.query;
46
+ const variablesText = tabs[activeTabIndex]?.variables;
47
+ let t0;
48
+ if ($[0] !== queryText) {
49
+ t0 = () => tryParse(queryText) ?? emptyDoc();
50
+ $[0] = queryText;
51
+ $[1] = t0;
52
+ } else t0 = $[1];
53
+ const [workingDoc, setWorkingDoc] = useState(t0);
54
+ const lastSyncedRef = useRef(queryText ?? null);
55
+ let t1;
56
+ if ($[2] !== queryEditor || $[3] !== updateActiveTabValues) {
57
+ t1 = (printed) => {
58
+ if (queryEditor) {
59
+ const position = queryEditor.getPosition();
60
+ queryEditor.setValue(printed);
61
+ if (position) queryEditor.setPosition(position);
62
+ lastSyncedRef.current = queryEditor.getValue();
63
+ return;
64
+ }
65
+ lastSyncedRef.current = printed;
66
+ updateActiveTabValues({ query: printed });
67
+ };
68
+ $[2] = queryEditor;
69
+ $[3] = updateActiveTabValues;
70
+ $[4] = t1;
71
+ } else t1 = $[4];
72
+ const writeToEditor = t1;
73
+ let t2;
74
+ let t3;
75
+ if ($[5] !== queryText) {
76
+ t2 = () => {
77
+ if (queryText === lastSyncedRef.current) return;
78
+ lastSyncedRef.current = queryText ?? null;
79
+ const parsed = tryParse(queryText);
80
+ if (parsed) setWorkingDoc(parsed);
81
+ else if (!queryText?.trim()) setWorkingDoc(emptyDoc());
82
+ };
83
+ t3 = [queryText];
84
+ $[5] = queryText;
85
+ $[6] = t2;
86
+ $[7] = t3;
87
+ } else {
88
+ t2 = $[6];
89
+ t3 = $[7];
90
+ }
91
+ useEffect(t2, t3);
92
+ let t4;
93
+ if ($[8] !== operationName || $[9] !== workingDoc) {
94
+ t4 = findOperation(workingDoc, operationName)?.operation;
95
+ $[8] = operationName;
96
+ $[9] = workingDoc;
97
+ $[10] = t4;
98
+ } else t4 = $[10];
99
+ const activeOpKind = t4;
100
+ const cursor = useCursorContext();
101
+ const [activeFragment, setActiveFragment] = useState(null);
102
+ const cursorFragment = cursor.target?.kind === "fragment" ? cursor.target.name : cursor.target?.kind === "operation" ? null : void 0;
103
+ let t5;
104
+ let t6;
105
+ if ($[11] !== cursorFragment) {
106
+ t5 = () => {
107
+ if (cursorFragment !== void 0) setActiveFragment(cursorFragment);
108
+ };
109
+ t6 = [cursorFragment];
110
+ $[11] = cursorFragment;
111
+ $[12] = t5;
112
+ $[13] = t6;
113
+ } else {
114
+ t5 = $[12];
115
+ t6 = $[13];
116
+ }
117
+ useEffect(t5, t6);
118
+ let t7;
119
+ if ($[14] !== activeFragment || $[15] !== operationName) {
120
+ t7 = activeFragment != null ? {
121
+ kind: "fragment",
122
+ name: activeFragment
123
+ } : {
124
+ kind: "operation",
125
+ name: operationName
126
+ };
127
+ $[14] = activeFragment;
128
+ $[15] = operationName;
129
+ $[16] = t7;
130
+ } else t7 = $[16];
131
+ const target = t7;
132
+ const cursorPath = cursor.target != null && (activeFragment != null ? cursor.target.kind === "fragment" && cursor.target.name === activeFragment : cursor.target.kind === "operation") ? cursor.path : void 0;
133
+ let t8;
134
+ if ($[17] !== queryEditor) {
135
+ t8 = function moveCursorToTarget(next) {
136
+ setActiveFragment(next.kind === "fragment" ? next.name : null);
137
+ if (!queryEditor) return;
138
+ const model = queryEditor.getModel();
139
+ if (!model) return;
140
+ let offset;
141
+ try {
142
+ offset = definitionSelectionOffset(parse(model.getValue()), next);
143
+ } catch {
144
+ return;
145
+ }
146
+ if (offset != null) queryEditor.setPosition(model.getPositionAt(offset));
147
+ };
148
+ $[17] = queryEditor;
149
+ $[18] = t8;
150
+ } else t8 = $[18];
151
+ const moveCursorToTarget = t8;
152
+ let t9;
153
+ if ($[19] !== moveCursorToTarget) {
154
+ t9 = function handleFocusFragment(fragmentName) {
155
+ moveCursorToTarget({
156
+ kind: "fragment",
157
+ name: fragmentName
158
+ });
159
+ };
160
+ $[19] = moveCursorToTarget;
161
+ $[20] = t9;
162
+ } else t9 = $[20];
163
+ const handleFocusFragment = t9;
164
+ let t10;
165
+ if ($[21] !== moveCursorToTarget || $[22] !== operationName) {
166
+ t10 = function handleBackToQuery() {
167
+ moveCursorToTarget({
168
+ kind: "operation",
169
+ name: operationName
170
+ });
171
+ };
172
+ $[21] = moveCursorToTarget;
173
+ $[22] = operationName;
174
+ $[23] = t10;
175
+ } else t10 = $[23];
176
+ const handleBackToQuery = t10;
177
+ let t11;
178
+ if ($[24] !== writeToEditor) {
179
+ t11 = function applyDoc(next_0) {
180
+ setWorkingDoc(next_0);
181
+ writeToEditor(print(next_0));
182
+ };
183
+ $[24] = writeToEditor;
184
+ $[25] = t11;
185
+ } else t11 = $[25];
186
+ const applyDoc = t11;
187
+ let t12;
188
+ if ($[26] !== updateActiveTabValues || $[27] !== variableEditor) {
189
+ t12 = function applyVariables(next_1) {
190
+ const serialized = Object.keys(next_1).length ? JSON.stringify(next_1, null, 2) : "";
191
+ if (variableEditor) variableEditor.setValue(serialized);
192
+ else updateActiveTabValues({ variables: serialized });
193
+ };
194
+ $[26] = updateActiveTabValues;
195
+ $[27] = variableEditor;
196
+ $[28] = t12;
197
+ } else t12 = $[28];
198
+ const applyVariables = t12;
199
+ let t13;
200
+ if ($[29] !== applyVariables || $[30] !== variablesText) {
201
+ t13 = function reconcileVariablesJson(next_2) {
202
+ const definedVars = /* @__PURE__ */ new Set();
203
+ for (const def of next_2.definitions) if (def.kind === Kind.OPERATION_DEFINITION) for (const vd of def.variableDefinitions ?? []) definedVars.add(vd.variable.name.value);
204
+ const vars = readVariables(variablesText);
205
+ if (Object.keys(vars).some((name_0) => !definedVars.has(name_0))) {
206
+ const reconciled = {};
207
+ for (const [name, value] of Object.entries(vars)) if (definedVars.has(name)) reconciled[name] = value;
208
+ applyVariables(reconciled);
209
+ }
210
+ };
211
+ $[29] = applyVariables;
212
+ $[30] = variablesText;
213
+ $[31] = t13;
214
+ } else t13 = $[31];
215
+ const reconcileVariablesJson = t13;
216
+ let t14;
217
+ if ($[32] !== applyDoc || $[33] !== reconcileVariablesJson || $[34] !== target || $[35] !== workingDoc) {
218
+ t14 = function handleToggle(path) {
219
+ const next_3 = toggleFieldSelection(workingDoc, path, target);
220
+ applyDoc(next_3);
221
+ reconcileVariablesJson(next_3);
222
+ };
223
+ $[32] = applyDoc;
224
+ $[33] = reconcileVariablesJson;
225
+ $[34] = target;
226
+ $[35] = workingDoc;
227
+ $[36] = t14;
228
+ } else t14 = $[36];
229
+ const handleToggle = t14;
230
+ let t15;
231
+ if ($[37] !== activeOpKind || $[38] !== schema || $[39] !== target || $[40] !== workingDoc) {
232
+ t15 = function schemaArgFor(path_0, argName) {
233
+ if (!schema) return;
234
+ if (target.kind === "operation") return resolveSchemaArg(schema, activeOpKind, path_0, argName);
235
+ const def_0 = findDefinition(workingDoc, target);
236
+ const rootTypeName = def_0?.kind === Kind.FRAGMENT_DEFINITION ? def_0.typeCondition.name.value : void 0;
237
+ const rootType = rootTypeName ? schema.getType(rootTypeName) ?? void 0 : void 0;
238
+ return resolveSchemaArgFromRoot(schema, rootType, path_0, argName);
239
+ };
240
+ $[37] = activeOpKind;
241
+ $[38] = schema;
242
+ $[39] = target;
243
+ $[40] = workingDoc;
244
+ $[41] = t15;
245
+ } else t15 = $[41];
246
+ const schemaArgFor = t15;
247
+ let t16;
248
+ if ($[42] !== applyDoc || $[43] !== schemaArgFor || $[44] !== target || $[45] !== workingDoc) {
249
+ t16 = function handleSetArg(path_1, argName_0, value_0) {
250
+ const schemaArg = schemaArgFor(path_1, argName_0);
251
+ if (!schemaArg) return;
252
+ const valueNode = argValueToValueNode(schemaArg.type, value_0);
253
+ applyDoc(setFieldArgument(workingDoc, path_1, argName_0, valueNode, target));
254
+ };
255
+ $[42] = applyDoc;
256
+ $[43] = schemaArgFor;
257
+ $[44] = target;
258
+ $[45] = workingDoc;
259
+ $[46] = t16;
260
+ } else t16 = $[46];
261
+ const handleSetArg = t16;
262
+ let t17;
263
+ if ($[47] !== applyDoc || $[48] !== applyVariables || $[49] !== operationName || $[50] !== schemaArgFor || $[51] !== variablesText || $[52] !== workingDoc) {
264
+ t17 = function handlePromoteArg(path_2, argName_1, suggestedName) {
265
+ const schemaArg_0 = schemaArgFor(path_2, argName_1);
266
+ if (!schemaArg_0) return;
267
+ const namedType = getNamedType(schemaArg_0.type);
268
+ if (!namedType) return;
269
+ const varName = suggestVarName(workingDoc, suggestedName);
270
+ const raw = extractRawArgValue(workingDoc, path_2, argName_1, operationName);
271
+ applyDoc(promoteArgToVariable(workingDoc, path_2, argName_1, varName, namedType.name, "", operationName));
272
+ if (raw) try {
273
+ const jsValue = valueFromASTUntyped(parseValue(raw));
274
+ applyVariables({
275
+ ...readVariables(variablesText),
276
+ [varName]: jsValue
277
+ });
278
+ } catch {}
279
+ };
280
+ $[47] = applyDoc;
281
+ $[48] = applyVariables;
282
+ $[49] = operationName;
283
+ $[50] = schemaArgFor;
284
+ $[51] = variablesText;
285
+ $[52] = workingDoc;
286
+ $[53] = t17;
287
+ } else t17 = $[53];
288
+ const handlePromoteArg = t17;
289
+ let t18;
290
+ if ($[54] !== applyDoc || $[55] !== applyVariables || $[56] !== operationName || $[57] !== schemaArgFor || $[58] !== variablesText || $[59] !== workingDoc) {
291
+ t18 = function handleDemoteArg(path_3, argName_2, varName_0) {
292
+ const vars_0 = readVariables(variablesText);
293
+ const jsValue_0 = vars_0[varName_0];
294
+ const schemaArg_1 = schemaArgFor(path_3, argName_2);
295
+ let inlineValue;
296
+ if (schemaArg_1 && jsValue_0 !== void 0) inlineValue = argValueToValueNode(schemaArg_1.type, String(jsValue_0));
297
+ applyDoc(demoteVariable(workingDoc, varName_0, operationName, inlineValue));
298
+ const rest = { ...vars_0 };
299
+ delete rest[varName_0];
300
+ applyVariables(rest);
301
+ };
302
+ $[54] = applyDoc;
303
+ $[55] = applyVariables;
304
+ $[56] = operationName;
305
+ $[57] = schemaArgFor;
306
+ $[58] = variablesText;
307
+ $[59] = workingDoc;
308
+ $[60] = t18;
309
+ } else t18 = $[60];
310
+ const handleDemoteArg = t18;
311
+ let t19;
312
+ if ($[61] !== applyDoc || $[62] !== target || $[63] !== workingDoc) {
313
+ t19 = function handleAddInlineFragment(path_4, typeName) {
314
+ applyDoc(addInlineFragment(workingDoc, path_4, typeName, target));
315
+ };
316
+ $[61] = applyDoc;
317
+ $[62] = target;
318
+ $[63] = workingDoc;
319
+ $[64] = t19;
320
+ } else t19 = $[64];
321
+ const handleAddInlineFragment = t19;
322
+ let t20;
323
+ if ($[65] !== applyDoc || $[66] !== reconcileVariablesJson || $[67] !== target || $[68] !== workingDoc) {
324
+ t20 = function handleRemoveInlineFragment(path_5, typeName_0) {
325
+ const next_4 = removeInlineFragment(workingDoc, path_5, typeName_0, target);
326
+ applyDoc(next_4);
327
+ reconcileVariablesJson(next_4);
328
+ };
329
+ $[65] = applyDoc;
330
+ $[66] = reconcileVariablesJson;
331
+ $[67] = target;
332
+ $[68] = workingDoc;
333
+ $[69] = t20;
334
+ } else t20 = $[69];
335
+ const handleRemoveInlineFragment = t20;
336
+ let t21;
337
+ if ($[70] !== applyDoc || $[71] !== reconcileVariablesJson || $[72] !== target || $[73] !== workingDoc) {
338
+ t21 = function handleRemoveFragmentSpread(path_6, fragmentName_0) {
339
+ const next_5 = removeFragmentSpread(workingDoc, path_6, fragmentName_0, target);
340
+ applyDoc(next_5);
341
+ reconcileVariablesJson(next_5);
342
+ };
343
+ $[70] = applyDoc;
344
+ $[71] = reconcileVariablesJson;
345
+ $[72] = target;
346
+ $[73] = workingDoc;
347
+ $[74] = t21;
348
+ } else t21 = $[74];
349
+ const handleRemoveFragmentSpread = t21;
350
+ let t22;
351
+ if ($[75] !== applyDoc || $[76] !== target || $[77] !== workingDoc) {
352
+ t22 = function handleExtractFragment(path_7, typeName_1) {
353
+ const base = `${typeName_1}Fields`;
354
+ const existing = new Set(listFragments(workingDoc));
355
+ let name_1 = base;
356
+ for (let n = 2; existing.has(name_1); n++) name_1 = `${base}_${n}`;
357
+ applyDoc(createFragmentFromSelection(workingDoc, path_7, name_1, typeName_1, target));
358
+ };
359
+ $[75] = applyDoc;
360
+ $[76] = target;
361
+ $[77] = workingDoc;
362
+ $[78] = t22;
363
+ } else t22 = $[78];
364
+ const handleExtractFragment = t22;
365
+ let t23;
366
+ if ($[79] !== applyDoc || $[80] !== workingDoc) {
367
+ t23 = function handleRenameFragment(oldName, newName) {
368
+ applyDoc(renameFragment(workingDoc, oldName, newName));
369
+ };
370
+ $[79] = applyDoc;
371
+ $[80] = workingDoc;
372
+ $[81] = t23;
373
+ } else t23 = $[81];
374
+ const handleRenameFragment = t23;
375
+ let t24;
376
+ if ($[82] !== activeFragment || $[83] !== applyDoc || $[84] !== moveCursorToTarget || $[85] !== operationName || $[86] !== workingDoc) {
377
+ t24 = function handleDeleteFragment(fragmentName_1) {
378
+ applyDoc(inlineFragment(workingDoc, fragmentName_1));
379
+ if (activeFragment === fragmentName_1) moveCursorToTarget({
380
+ kind: "operation",
381
+ name: operationName
382
+ });
383
+ };
384
+ $[82] = activeFragment;
385
+ $[83] = applyDoc;
386
+ $[84] = moveCursorToTarget;
387
+ $[85] = operationName;
388
+ $[86] = workingDoc;
389
+ $[87] = t24;
390
+ } else t24 = $[87];
391
+ const handleDeleteFragment = t24;
392
+ let t25;
393
+ if ($[88] !== activeOpKind || $[89] !== cursorPath || $[90] !== handleAddInlineFragment || $[91] !== handleBackToQuery || $[92] !== handleDeleteFragment || $[93] !== handleDemoteArg || $[94] !== handleExtractFragment || $[95] !== handleFocusFragment || $[96] !== handlePromoteArg || $[97] !== handleRemoveFragmentSpread || $[98] !== handleRemoveInlineFragment || $[99] !== handleRenameFragment || $[100] !== handleSetArg || $[101] !== handleToggle || $[102] !== target || $[103] !== workingDoc) {
394
+ t25 = {
395
+ workingDoc,
396
+ activeOpKind,
397
+ target,
398
+ cursorPath,
399
+ handleFocusFragment,
400
+ handleBackToQuery,
401
+ handleToggle,
402
+ handleSetArg,
403
+ handlePromoteArg,
404
+ handleDemoteArg,
405
+ handleAddInlineFragment,
406
+ handleRemoveInlineFragment,
407
+ handleRemoveFragmentSpread,
408
+ handleExtractFragment,
409
+ handleRenameFragment,
410
+ handleDeleteFragment
411
+ };
412
+ $[88] = activeOpKind;
413
+ $[89] = cursorPath;
414
+ $[90] = handleAddInlineFragment;
415
+ $[91] = handleBackToQuery;
416
+ $[92] = handleDeleteFragment;
417
+ $[93] = handleDemoteArg;
418
+ $[94] = handleExtractFragment;
419
+ $[95] = handleFocusFragment;
420
+ $[96] = handlePromoteArg;
421
+ $[97] = handleRemoveFragmentSpread;
422
+ $[98] = handleRemoveInlineFragment;
423
+ $[99] = handleRenameFragment;
424
+ $[100] = handleSetArg;
425
+ $[101] = handleToggle;
426
+ $[102] = target;
427
+ $[103] = workingDoc;
428
+ $[104] = t25;
429
+ } else t25 = $[104];
430
+ return t25;
526
431
  }
527
432
  function _temp6(state_4) {
528
- return state_4.tabs;
433
+ return state_4.tabs;
529
434
  }
530
435
  function _temp5(state_3) {
531
- return state_3.activeTabIndex;
436
+ return state_3.activeTabIndex;
532
437
  }
533
438
  function _temp4(state_2) {
534
- return state_2.operationName;
439
+ return state_2.operationName;
535
440
  }
536
441
  function _temp3(state_1) {
537
- return state_1.variableEditor;
442
+ return state_1.variableEditor;
538
443
  }
539
444
  function _temp2(state_0) {
540
- return state_0.queryEditor;
445
+ return state_0.queryEditor;
541
446
  }
542
447
  function _temp(state) {
543
- return state.schema;
448
+ return state.schema;
544
449
  }
545
- export {
546
- useWorkingDocument
547
- };
548
- //# sourceMappingURL=use-working-document.js.map
450
+ //#endregion
451
+ export { useWorkingDocument };
452
+
453
+ //# sourceMappingURL=use-working-document.js.map