@graphiql/plugin-query-builder 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/components/arg-input/arg-input-by-type.js +441 -444
- package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
- package/dist/components/arg-input/enum-arg-control.js +49 -52
- package/dist/components/arg-input/enum-arg-control.js.map +1 -1
- package/dist/components/arg-input/index.js +44 -36
- package/dist/components/arg-input/index.js.map +1 -1
- package/dist/components/arg-input/scalar-arg-control.js +58 -63
- package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
- package/dist/components/field-row.js +212 -197
- package/dist/components/field-row.js.map +1 -1
- package/dist/components/field-tree-context.js +23 -27
- package/dist/components/field-tree-context.js.map +1 -1
- package/dist/components/field-tree-node.js +128 -105
- package/dist/components/field-tree-node.js.map +1 -1
- package/dist/components/field-tree.js +178 -199
- package/dist/components/field-tree.js.map +1 -1
- package/dist/components/fragment-editor.js +157 -151
- package/dist/components/fragment-editor.js.map +1 -1
- package/dist/components/fragment-section.js +215 -203
- package/dist/components/fragment-section.js.map +1 -1
- package/dist/components/query-builder.js +205 -181
- package/dist/components/query-builder.js.map +1 -1
- package/dist/components/type-condition-selector.js +417 -462
- package/dist/components/type-condition-selector.js.map +1 -1
- package/dist/components/use-cursor-path.js +69 -70
- package/dist/components/use-cursor-path.js.map +1 -1
- package/dist/components/use-cursor-reveal.js +83 -89
- package/dist/components/use-cursor-reveal.js.map +1 -1
- package/dist/components/use-working-document.js +432 -527
- package/dist/components/use-working-document.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/arg-value.js +132 -139
- package/dist/lib/arg-value.js.map +1 -1
- package/dist/lib/arguments.js +54 -55
- package/dist/lib/arguments.js.map +1 -1
- package/dist/lib/ast-path.js +266 -291
- package/dist/lib/ast-path.js.map +1 -1
- package/dist/lib/field-list-view.js +33 -43
- package/dist/lib/field-list-view.js.map +1 -1
- package/dist/lib/field-selection.js +63 -67
- package/dist/lib/field-selection.js.map +1 -1
- package/dist/lib/fragments.js +166 -152
- package/dist/lib/fragments.js.map +1 -1
- package/dist/lib/inline-fragments.js +64 -62
- package/dist/lib/inline-fragments.js.map +1 -1
- package/dist/lib/schema-walk.js +141 -158
- package/dist/lib/schema-walk.js.map +1 -1
- package/dist/lib/variables.js +96 -90
- package/dist/lib/variables.js.map +1 -1
- package/dist/style.css +4 -22
- package/package.json +21 -18
|
@@ -1,548 +1,453 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
433
|
+
return state_4.tabs;
|
|
529
434
|
}
|
|
530
435
|
function _temp5(state_3) {
|
|
531
|
-
|
|
436
|
+
return state_3.activeTabIndex;
|
|
532
437
|
}
|
|
533
438
|
function _temp4(state_2) {
|
|
534
|
-
|
|
439
|
+
return state_2.operationName;
|
|
535
440
|
}
|
|
536
441
|
function _temp3(state_1) {
|
|
537
|
-
|
|
442
|
+
return state_1.variableEditor;
|
|
538
443
|
}
|
|
539
444
|
function _temp2(state_0) {
|
|
540
|
-
|
|
445
|
+
return state_0.queryEditor;
|
|
541
446
|
}
|
|
542
447
|
function _temp(state) {
|
|
543
|
-
|
|
448
|
+
return state.schema;
|
|
544
449
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
//# sourceMappingURL=use-working-document.js.map
|
|
450
|
+
//#endregion
|
|
451
|
+
export { useWorkingDocument };
|
|
452
|
+
|
|
453
|
+
//# sourceMappingURL=use-working-document.js.map
|