@graphiql/plugin-collections 1.0.0-beta.0 → 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.
- package/LICENSE +21 -0
- package/dist/components/collection-item-row.js +212 -282
- package/dist/components/collection-item-row.js.map +1 -1
- package/dist/components/collection-row.js +139 -159
- package/dist/components/collection-row.js.map +1 -1
- package/dist/components/collections-panel.js +408 -496
- package/dist/components/collections-panel.js.map +1 -1
- package/dist/components/conflict-dialog.js +148 -164
- package/dist/components/conflict-dialog.js.map +1 -1
- package/dist/components/export-dialog.js +52 -52
- package/dist/components/export-dialog.js.map +1 -1
- package/dist/components/import-dialog.js +100 -112
- package/dist/components/import-dialog.js.map +1 -1
- package/dist/components/save-dialog.js +116 -124
- package/dist/components/save-dialog.js.map +1 -1
- package/dist/components/session-actions.js +23 -31
- package/dist/components/session-actions.js.map +1 -1
- package/dist/icons/check.js +18 -9
- package/dist/icons/check.js.map +1 -1
- package/dist/icons/collections.js +16 -9
- package/dist/icons/collections.js.map +1 -1
- package/dist/icons/download.js +16 -9
- package/dist/icons/download.js.map +1 -1
- package/dist/icons/upload.js +16 -9
- package/dist/icons/upload.js.map +1 -1
- package/dist/index.js +31 -41
- package/dist/index.js.map +1 -1
- package/dist/operation-method.js +24 -24
- package/dist/operation-method.js.map +1 -1
- package/dist/storage/local-storage.js +32 -37
- package/dist/storage/local-storage.js.map +1 -1
- package/dist/storage/tab-links.js +27 -30
- package/dist/storage/tab-links.js.map +1 -1
- package/dist/store.js +365 -402
- package/dist/store.js.map +1 -1
- package/dist/style.css +6 -27
- package/dist/types.js +9 -8
- package/dist/types.js.map +1 -1
- package/dist/utility/uuid.js +11 -9
- package/dist/utility/uuid.js.map +1 -1
- package/package.json +19 -15
|
@@ -1,508 +1,420 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { useGraphiQLActions, useGraphiQL, pick, PanelHeader, Dialog, Button } from "@graphiql/react";
|
|
4
|
-
import { useCollectionsStore, collectionsStore } from "../store.js";
|
|
1
|
+
import { collectionsStore, useCollectionsStore } from "../store.js";
|
|
2
|
+
import SvgUpload from "../icons/upload.js";
|
|
5
3
|
import { CollectionRow } from "./collection-row.js";
|
|
6
4
|
import { ImportDialog } from "./import-dialog.js";
|
|
7
5
|
import { ExportDialog } from "./export-dialog.js";
|
|
8
6
|
import { ConflictDialog } from "./conflict-dialog.js";
|
|
9
7
|
import SvgDownload from "../icons/download.js";
|
|
10
|
-
import
|
|
8
|
+
import { useEffect, useRef, useState } from "react";
|
|
9
|
+
import { Button, Dialog, PanelHeader, pick, useGraphiQL, useGraphiQLActions } from "@graphiql/react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
//#region src/components/collections-panel.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Returns how many collections `text` holds if it is a valid collections
|
|
14
|
+
* export, otherwise `null`. Used to guard paste/drop so non-collections content
|
|
15
|
+
* is ignored rather than mangled.
|
|
16
|
+
*/
|
|
11
17
|
function parseCollectionsExport(text) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return list.length;
|
|
21
|
-
} catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(text);
|
|
20
|
+
const list = Array.isArray(parsed?.collections) ? parsed.collections : Array.isArray(parsed) ? parsed : null;
|
|
21
|
+
if (!list?.length || !list.every((c) => c && typeof c === "object" && Array.isArray(c.items))) return null;
|
|
22
|
+
return list.length;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
function isEditableTarget(el) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable || Boolean(el.closest(".monaco-editor"));
|
|
28
|
+
if (!el) return false;
|
|
29
|
+
return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable || Boolean(el.closest(".monaco-editor"));
|
|
30
30
|
}
|
|
31
|
+
/** Derive a human-readable label from the parsed incoming collections. */
|
|
31
32
|
function deriveSourceLabel(incoming) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return `${incoming.length} collections`;
|
|
33
|
+
if (incoming.length === 1 && incoming[0]) return incoming[0].name;
|
|
34
|
+
return `${incoming.length} collections`;
|
|
36
35
|
}
|
|
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
|
-
children: liveMessage
|
|
418
|
-
}
|
|
419
|
-
),
|
|
420
|
-
/* @__PURE__ */ jsx("div", { className: "graphiql-collections-list", ref: listRef, children: collections.map((collection) => /* @__PURE__ */ jsx(
|
|
421
|
-
CollectionRow,
|
|
422
|
-
{
|
|
423
|
-
collection,
|
|
424
|
-
readOnly,
|
|
425
|
-
expanded: !collapsed.has(collection.id),
|
|
426
|
-
onToggleExpand: () => toggleExpand(collection.id),
|
|
427
|
-
grabbed,
|
|
428
|
-
onGrabToggle: handleGrabToggle,
|
|
429
|
-
onGrabMove: handleGrabMove,
|
|
430
|
-
onGrabCancel: handleGrabCancel,
|
|
431
|
-
onRename: handleRename,
|
|
432
|
-
onDelete: handleDelete,
|
|
433
|
-
onShareCollection: handleShareCollection,
|
|
434
|
-
onOpenItem: handleOpen,
|
|
435
|
-
onShare: handleShareItem,
|
|
436
|
-
onAnnounce: announce,
|
|
437
|
-
onDeleteItem: handleDeleteItem,
|
|
438
|
-
onMoveItem: handleMoveItem,
|
|
439
|
-
onAddItem: handleAddItem,
|
|
440
|
-
onRenameItem: handleRenameItem
|
|
441
|
-
},
|
|
442
|
-
collection.id
|
|
443
|
-
)) }),
|
|
444
|
-
allowImportExport && /* @__PURE__ */ jsx(
|
|
445
|
-
ExportDialog,
|
|
446
|
-
{
|
|
447
|
-
open: openDialog === "export",
|
|
448
|
-
onClose: () => setOpenDialog(null)
|
|
449
|
-
}
|
|
450
|
-
),
|
|
451
|
-
allowImport && /* @__PURE__ */ jsx(
|
|
452
|
-
ImportDialog,
|
|
453
|
-
{
|
|
454
|
-
open: openDialog === "import",
|
|
455
|
-
onClose: () => setOpenDialog(null),
|
|
456
|
-
onImport: runImport,
|
|
457
|
-
allowReplace
|
|
458
|
-
}
|
|
459
|
-
),
|
|
460
|
-
pendingConflict && /* @__PURE__ */ jsx(
|
|
461
|
-
ConflictDialog,
|
|
462
|
-
{
|
|
463
|
-
analysis: pendingConflict.analysis,
|
|
464
|
-
sourceLabel: pendingConflict.sourceLabel,
|
|
465
|
-
open: true,
|
|
466
|
-
onClose: () => setPendingConflict(null),
|
|
467
|
-
onResolve: handleConflictResolve
|
|
468
|
-
}
|
|
469
|
-
),
|
|
470
|
-
/* @__PURE__ */ jsxs(
|
|
471
|
-
Dialog,
|
|
472
|
-
{
|
|
473
|
-
open: pendingReplace !== null,
|
|
474
|
-
onOpenChange: (o) => !o && setPendingReplace(null),
|
|
475
|
-
children: [
|
|
476
|
-
/* @__PURE__ */ jsx(Dialog.Header, { children: "Replace all collections?" }),
|
|
477
|
-
/* @__PURE__ */ jsxs(Dialog.Body, { children: [
|
|
478
|
-
/* @__PURE__ */ jsx("p", { className: "graphiql-conflict-summary", children: "This will remove all existing collections and replace them with the imported data. This cannot be undone." }),
|
|
479
|
-
/* @__PURE__ */ jsxs("div", { className: "graphiql-conflict-actions", children: [
|
|
480
|
-
/* @__PURE__ */ jsx(
|
|
481
|
-
Button,
|
|
482
|
-
{
|
|
483
|
-
type: "button",
|
|
484
|
-
variant: "primary",
|
|
485
|
-
onClick: () => {
|
|
486
|
-
const text = pendingReplace;
|
|
487
|
-
setPendingReplace(null);
|
|
488
|
-
if (text !== null) {
|
|
489
|
-
applyReplace(text);
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
children: "Replace"
|
|
493
|
-
}
|
|
494
|
-
),
|
|
495
|
-
/* @__PURE__ */ jsx(Button, { type: "button", onClick: () => setPendingReplace(null), children: "Cancel" })
|
|
496
|
-
] })
|
|
497
|
-
] })
|
|
498
|
-
]
|
|
499
|
-
}
|
|
500
|
-
)
|
|
501
|
-
]
|
|
502
|
-
}
|
|
503
|
-
);
|
|
504
|
-
};
|
|
505
|
-
export {
|
|
506
|
-
CollectionsPanel
|
|
36
|
+
var CollectionsPanel = ({ readOnly = false, allowImportExport = true, allowReplace = true }) => {
|
|
37
|
+
const allowImport = !readOnly && allowImportExport;
|
|
38
|
+
const actions = useCollectionsStore((s) => s.actions);
|
|
39
|
+
const collections = useCollectionsStore((s) => s.collections);
|
|
40
|
+
const loaded = useCollectionsStore((s) => s.loaded);
|
|
41
|
+
const [openDialog, setOpenDialog] = useState(null);
|
|
42
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
43
|
+
const [status, setStatus] = useState(null);
|
|
44
|
+
const [pendingConflict, setPendingConflict] = useState(null);
|
|
45
|
+
const [pendingReplace, setPendingReplace] = useState(null);
|
|
46
|
+
const [collapsed, setCollapsed] = useState(/* @__PURE__ */ new Set());
|
|
47
|
+
const [grabbed, setGrabbed] = useState(null);
|
|
48
|
+
const [origin, setOrigin] = useState(null);
|
|
49
|
+
const [liveMessage, setLiveMessage] = useState("");
|
|
50
|
+
const listRef = useRef(null);
|
|
51
|
+
const cancelledItemRef = useRef(null);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!status) return;
|
|
54
|
+
const timer = setTimeout(() => setStatus(null), 4e3);
|
|
55
|
+
return () => clearTimeout(timer);
|
|
56
|
+
}, [status]);
|
|
57
|
+
const applyReplace = (text) => {
|
|
58
|
+
const analysis = collectionsStore.getState().actions.analyzeImport(text);
|
|
59
|
+
collectionsStore.getState().actions.applyImport(analysis, { mode: "replace" });
|
|
60
|
+
};
|
|
61
|
+
const runImport = (text, mode) => {
|
|
62
|
+
if (mode === "replace") {
|
|
63
|
+
setPendingReplace(text);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (parseCollectionsExport(text) === null) {
|
|
67
|
+
setStatus({
|
|
68
|
+
ok: false,
|
|
69
|
+
message: "That file isn't a collections export."
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const analysis = collectionsStore.getState().actions.analyzeImport(text);
|
|
74
|
+
if (!analysis.ok) {
|
|
75
|
+
setStatus({
|
|
76
|
+
ok: false,
|
|
77
|
+
message: "Invalid collections export."
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (analysis.changedItems.length === 0) {
|
|
82
|
+
collectionsStore.getState().actions.applyImport(analysis, {
|
|
83
|
+
mode: "merge",
|
|
84
|
+
applyChanges: true
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
setPendingConflict({
|
|
89
|
+
analysis,
|
|
90
|
+
sourceLabel: deriveSourceLabel(analysis._incoming)
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const handleConflictResolve = (resolution) => {
|
|
94
|
+
if (!pendingConflict) return;
|
|
95
|
+
const { analysis } = pendingConflict;
|
|
96
|
+
collectionsStore.getState().actions.applyImport(analysis, resolution);
|
|
97
|
+
setPendingConflict(null);
|
|
98
|
+
};
|
|
99
|
+
const importDroppedFile = async (file) => {
|
|
100
|
+
const text = await file.text();
|
|
101
|
+
if (parseCollectionsExport(text) === null) {
|
|
102
|
+
setStatus({
|
|
103
|
+
ok: false,
|
|
104
|
+
message: "That file isn't a collections export."
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
runImport(text, "merge");
|
|
109
|
+
};
|
|
110
|
+
const allowImportRef = useRef(allowImport);
|
|
111
|
+
allowImportRef.current = allowImport;
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const onPaste = (event) => {
|
|
114
|
+
if (!allowImportRef.current) return;
|
|
115
|
+
if (isEditableTarget(document.activeElement)) return;
|
|
116
|
+
const text = event.clipboardData?.getData("text") ?? "";
|
|
117
|
+
if (parseCollectionsExport(text) === null) return;
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
runImport(text, "merge");
|
|
120
|
+
};
|
|
121
|
+
document.addEventListener("paste", onPaste);
|
|
122
|
+
return () => document.removeEventListener("paste", onPaste);
|
|
123
|
+
}, []);
|
|
124
|
+
const { addTab, changeTab, updateActiveTabValues } = useGraphiQLActions();
|
|
125
|
+
const { queryEditor, variableEditor, headerEditor } = useGraphiQL(pick("queryEditor", "variableEditor", "headerEditor"));
|
|
126
|
+
const tabs = useGraphiQL((s) => s.tabs);
|
|
127
|
+
const activeTabId = useGraphiQL((s) => s.tabs[s.activeTabIndex]?.id);
|
|
128
|
+
const pendingLink = useRef(null);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const link = pendingLink.current;
|
|
131
|
+
if (link && activeTabId) {
|
|
132
|
+
actions.linkTab(activeTabId, link.collectionId, link.itemId);
|
|
133
|
+
pendingLink.current = null;
|
|
134
|
+
}
|
|
135
|
+
}, [activeTabId, actions]);
|
|
136
|
+
const handleOpen = (item) => {
|
|
137
|
+
const { links } = collectionsStore.getState();
|
|
138
|
+
const openIndex = tabs.findIndex((t) => t.id && links[t.id]?.itemId === item.id);
|
|
139
|
+
if (openIndex !== -1) {
|
|
140
|
+
changeTab(openIndex);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const collectionId = collections.find((c) => c.items.some((i) => i.id === item.id))?.id;
|
|
144
|
+
if (collectionId) pendingLink.current = {
|
|
145
|
+
collectionId,
|
|
146
|
+
itemId: item.id
|
|
147
|
+
};
|
|
148
|
+
addTab();
|
|
149
|
+
queryEditor?.setValue(item.query ?? "");
|
|
150
|
+
variableEditor?.setValue(item.variables ?? "");
|
|
151
|
+
headerEditor?.setValue(item.headers ?? "");
|
|
152
|
+
updateActiveTabValues({
|
|
153
|
+
query: item.query,
|
|
154
|
+
variables: item.variables ?? "",
|
|
155
|
+
headers: item.headers ?? "",
|
|
156
|
+
lastSavedQuery: item.query ?? null
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const announce = (message) => setLiveMessage(message);
|
|
160
|
+
const handleShareCollection = async (collectionId) => {
|
|
161
|
+
const json = collectionsStore.getState().actions.exportCollection(collectionId);
|
|
162
|
+
await navigator.clipboard.writeText(json);
|
|
163
|
+
};
|
|
164
|
+
const handleShareItem = async (itemId) => {
|
|
165
|
+
const json = collectionsStore.getState().actions.exportItem(itemId);
|
|
166
|
+
await navigator.clipboard.writeText(json);
|
|
167
|
+
};
|
|
168
|
+
const handleRename = actions.renameCollection;
|
|
169
|
+
const handleDelete = actions.deleteCollection;
|
|
170
|
+
const handleDeleteItem = actions.deleteItem;
|
|
171
|
+
const handleMoveItem = actions.moveItem;
|
|
172
|
+
const handleAddItem = actions.addItem;
|
|
173
|
+
const handleRenameItem = (collectionId, itemId, updates) => {
|
|
174
|
+
collectionsStore.getState().actions.updateItem(collectionId, itemId, {
|
|
175
|
+
name: updates.name,
|
|
176
|
+
description: updates.description || void 0
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
const toggleExpand = (id) => setCollapsed((prev) => {
|
|
180
|
+
const next = new Set(prev);
|
|
181
|
+
if (next.has(id)) next.delete(id);
|
|
182
|
+
else next.add(id);
|
|
183
|
+
return next;
|
|
184
|
+
});
|
|
185
|
+
const expand = (id) => setCollapsed((prev) => {
|
|
186
|
+
if (!prev.has(id)) return prev;
|
|
187
|
+
const next = new Set(prev);
|
|
188
|
+
next.delete(id);
|
|
189
|
+
return next;
|
|
190
|
+
});
|
|
191
|
+
const handleGrabToggle = (collectionId, index, itemId) => {
|
|
192
|
+
if (grabbed) {
|
|
193
|
+
const col = collectionsStore.getState().collections.find((c) => c.id === grabbed.collectionId);
|
|
194
|
+
const droppedItem = col?.items[grabbed.index];
|
|
195
|
+
setLiveMessage(`Dropped ${droppedItem?.name ?? grabbed.itemId} in ${col?.name ?? ""} at position ${grabbed.index + 1}.`);
|
|
196
|
+
setGrabbed(null);
|
|
197
|
+
setOrigin(null);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
setGrabbed({
|
|
201
|
+
collectionId,
|
|
202
|
+
index,
|
|
203
|
+
itemId
|
|
204
|
+
});
|
|
205
|
+
setOrigin({
|
|
206
|
+
collectionId,
|
|
207
|
+
index
|
|
208
|
+
});
|
|
209
|
+
const item = collectionsStore.getState().collections.find((c) => c.id === collectionId)?.items[index];
|
|
210
|
+
setLiveMessage(`Grabbed ${item?.name ?? itemId}. Use arrow keys to move, space to drop, escape to cancel.`);
|
|
211
|
+
};
|
|
212
|
+
const handleGrabMove = (direction) => {
|
|
213
|
+
if (!grabbed) return;
|
|
214
|
+
const cols = collectionsStore.getState().collections;
|
|
215
|
+
const cIdx = cols.findIndex((c) => c.id === grabbed.collectionId);
|
|
216
|
+
const col = cols[cIdx];
|
|
217
|
+
if (!col) return;
|
|
218
|
+
const { moveItem } = collectionsStore.getState().actions;
|
|
219
|
+
if (direction === "down") {
|
|
220
|
+
if (grabbed.index < col.items.length - 1) {
|
|
221
|
+
moveItem(col.id, grabbed.index, col.id, grabbed.index + 1);
|
|
222
|
+
const next = {
|
|
223
|
+
...grabbed,
|
|
224
|
+
index: grabbed.index + 1
|
|
225
|
+
};
|
|
226
|
+
setGrabbed(next);
|
|
227
|
+
setLiveMessage(`Position ${next.index + 1} of ${col.items.length} in ${col.name}.`);
|
|
228
|
+
} else if (cIdx < cols.length - 1) {
|
|
229
|
+
const dest = cols[cIdx + 1];
|
|
230
|
+
expand(dest.id);
|
|
231
|
+
moveItem(col.id, grabbed.index, dest.id, 0);
|
|
232
|
+
setGrabbed({
|
|
233
|
+
collectionId: dest.id,
|
|
234
|
+
index: 0,
|
|
235
|
+
itemId: grabbed.itemId
|
|
236
|
+
});
|
|
237
|
+
setLiveMessage(`Moved to ${dest.name}, position 1 of ${dest.items.length + 1}.`);
|
|
238
|
+
} else setLiveMessage("Already at the end.");
|
|
239
|
+
} else if (grabbed.index > 0) {
|
|
240
|
+
moveItem(col.id, grabbed.index, col.id, grabbed.index - 1);
|
|
241
|
+
const next = {
|
|
242
|
+
...grabbed,
|
|
243
|
+
index: grabbed.index - 1
|
|
244
|
+
};
|
|
245
|
+
setGrabbed(next);
|
|
246
|
+
setLiveMessage(`Position ${next.index + 1} of ${col.items.length} in ${col.name}.`);
|
|
247
|
+
} else if (cIdx > 0) {
|
|
248
|
+
const dest = cols[cIdx - 1];
|
|
249
|
+
expand(dest.id);
|
|
250
|
+
const toIndex = dest.items.length;
|
|
251
|
+
moveItem(col.id, grabbed.index, dest.id, toIndex);
|
|
252
|
+
setGrabbed({
|
|
253
|
+
collectionId: dest.id,
|
|
254
|
+
index: toIndex,
|
|
255
|
+
itemId: grabbed.itemId
|
|
256
|
+
});
|
|
257
|
+
setLiveMessage(`Moved to ${dest.name}, position ${toIndex + 1} of ${dest.items.length + 1}.`);
|
|
258
|
+
} else setLiveMessage("Already at the start.");
|
|
259
|
+
};
|
|
260
|
+
const handleGrabCancel = () => {
|
|
261
|
+
if (!grabbed || !origin) return;
|
|
262
|
+
collectionsStore.getState().actions.moveItem(grabbed.collectionId, grabbed.index, origin.collectionId, origin.index);
|
|
263
|
+
cancelledItemRef.current = grabbed.itemId;
|
|
264
|
+
setGrabbed(null);
|
|
265
|
+
setOrigin(null);
|
|
266
|
+
setLiveMessage("Move cancelled.");
|
|
267
|
+
};
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (grabbed) listRef.current?.querySelector(`[data-collection-drag-handle="${grabbed.itemId}"]`)?.focus();
|
|
270
|
+
else if (cancelledItemRef.current) {
|
|
271
|
+
listRef.current?.querySelector(`[data-collection-drag-handle="${cancelledItemRef.current}"]`)?.focus();
|
|
272
|
+
cancelledItemRef.current = null;
|
|
273
|
+
}
|
|
274
|
+
}, [grabbed]);
|
|
275
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
276
|
+
className: `graphiql-collections-panel${isDragOver ? " graphiql-collections-drop-active" : ""}`,
|
|
277
|
+
onDragOver: (e) => {
|
|
278
|
+
if (!allowImport || !e.dataTransfer.types.includes("Files")) return;
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
setIsDragOver(true);
|
|
281
|
+
},
|
|
282
|
+
onDragLeave: (e) => {
|
|
283
|
+
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
284
|
+
setIsDragOver(false);
|
|
285
|
+
},
|
|
286
|
+
onDrop: (e) => {
|
|
287
|
+
if (!allowImport) return;
|
|
288
|
+
const file = e.dataTransfer.files[0];
|
|
289
|
+
if (!file) return;
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
setIsDragOver(false);
|
|
292
|
+
importDroppedFile(file);
|
|
293
|
+
},
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsx(PanelHeader, {
|
|
296
|
+
title: "Operation Collections",
|
|
297
|
+
subtitle: "Save and organize operations into collections."
|
|
298
|
+
}),
|
|
299
|
+
(!readOnly || allowImportExport) && /* @__PURE__ */ jsxs("div", {
|
|
300
|
+
className: "graphiql-collections-toolbar",
|
|
301
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
302
|
+
className: "graphiql-collections-toolbar-left",
|
|
303
|
+
children: !readOnly && /* @__PURE__ */ jsx("button", {
|
|
304
|
+
type: "button",
|
|
305
|
+
className: "graphiql-collections-action",
|
|
306
|
+
onClick: () => collectionsStore.getState().actions.createCollection("New Collection"),
|
|
307
|
+
"aria-label": "New collection",
|
|
308
|
+
title: "New collection",
|
|
309
|
+
children: "+ New Collection"
|
|
310
|
+
})
|
|
311
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
312
|
+
className: "graphiql-collections-toolbar-right",
|
|
313
|
+
children: [allowImport && /* @__PURE__ */ jsx("button", {
|
|
314
|
+
type: "button",
|
|
315
|
+
className: "graphiql-collections-action",
|
|
316
|
+
onClick: () => setOpenDialog("import"),
|
|
317
|
+
"aria-label": "Import collections",
|
|
318
|
+
title: "Import collections",
|
|
319
|
+
children: /* @__PURE__ */ jsx(SvgDownload, {})
|
|
320
|
+
}), allowImportExport && /* @__PURE__ */ jsx("button", {
|
|
321
|
+
type: "button",
|
|
322
|
+
className: "graphiql-collections-action",
|
|
323
|
+
onClick: () => setOpenDialog("export"),
|
|
324
|
+
"aria-label": "Export collections",
|
|
325
|
+
title: "Export collections",
|
|
326
|
+
children: /* @__PURE__ */ jsx(SvgUpload, {})
|
|
327
|
+
})]
|
|
328
|
+
})]
|
|
329
|
+
}),
|
|
330
|
+
status && /* @__PURE__ */ jsx("div", {
|
|
331
|
+
className: `graphiql-collections-status${status.ok ? "" : " graphiql-collections-status-error"}`,
|
|
332
|
+
role: "status",
|
|
333
|
+
children: status.message
|
|
334
|
+
}),
|
|
335
|
+
!loaded && /* @__PURE__ */ jsx("div", {
|
|
336
|
+
className: "graphiql-collections-loading",
|
|
337
|
+
children: "Loading…"
|
|
338
|
+
}),
|
|
339
|
+
loaded && collections.length === 0 && /* @__PURE__ */ jsx("div", {
|
|
340
|
+
className: "graphiql-collections-empty",
|
|
341
|
+
children: readOnly ? "No collections." : allowImport ? "No collections yet. Save an operation to get started, or drop or paste a collections export to import one." : "No collections yet. Save an operation to get started."
|
|
342
|
+
}),
|
|
343
|
+
/* @__PURE__ */ jsx("div", {
|
|
344
|
+
className: "graphiql-sr-only",
|
|
345
|
+
"aria-live": "assertive",
|
|
346
|
+
"aria-atomic": "true",
|
|
347
|
+
children: liveMessage
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ jsx("div", {
|
|
350
|
+
className: "graphiql-collections-list",
|
|
351
|
+
ref: listRef,
|
|
352
|
+
children: collections.map((collection) => /* @__PURE__ */ jsx(CollectionRow, {
|
|
353
|
+
collection,
|
|
354
|
+
readOnly,
|
|
355
|
+
expanded: !collapsed.has(collection.id),
|
|
356
|
+
onToggleExpand: () => toggleExpand(collection.id),
|
|
357
|
+
grabbed,
|
|
358
|
+
onGrabToggle: handleGrabToggle,
|
|
359
|
+
onGrabMove: handleGrabMove,
|
|
360
|
+
onGrabCancel: handleGrabCancel,
|
|
361
|
+
onRename: handleRename,
|
|
362
|
+
onDelete: handleDelete,
|
|
363
|
+
onShareCollection: handleShareCollection,
|
|
364
|
+
onOpenItem: handleOpen,
|
|
365
|
+
onShare: handleShareItem,
|
|
366
|
+
onAnnounce: announce,
|
|
367
|
+
onDeleteItem: handleDeleteItem,
|
|
368
|
+
onMoveItem: handleMoveItem,
|
|
369
|
+
onAddItem: handleAddItem,
|
|
370
|
+
onRenameItem: handleRenameItem
|
|
371
|
+
}, collection.id))
|
|
372
|
+
}),
|
|
373
|
+
allowImportExport && /* @__PURE__ */ jsx(ExportDialog, {
|
|
374
|
+
open: openDialog === "export",
|
|
375
|
+
onClose: () => setOpenDialog(null)
|
|
376
|
+
}),
|
|
377
|
+
allowImport && /* @__PURE__ */ jsx(ImportDialog, {
|
|
378
|
+
open: openDialog === "import",
|
|
379
|
+
onClose: () => setOpenDialog(null),
|
|
380
|
+
onImport: runImport,
|
|
381
|
+
allowReplace
|
|
382
|
+
}),
|
|
383
|
+
pendingConflict && /* @__PURE__ */ jsx(ConflictDialog, {
|
|
384
|
+
analysis: pendingConflict.analysis,
|
|
385
|
+
sourceLabel: pendingConflict.sourceLabel,
|
|
386
|
+
open: true,
|
|
387
|
+
onClose: () => setPendingConflict(null),
|
|
388
|
+
onResolve: handleConflictResolve
|
|
389
|
+
}),
|
|
390
|
+
/* @__PURE__ */ jsxs(Dialog, {
|
|
391
|
+
open: pendingReplace !== null,
|
|
392
|
+
onOpenChange: (o) => !o && setPendingReplace(null),
|
|
393
|
+
children: [/* @__PURE__ */ jsx(Dialog.Header, { children: "Replace all collections?" }), /* @__PURE__ */ jsxs(Dialog.Body, { children: [/* @__PURE__ */ jsx("p", {
|
|
394
|
+
className: "graphiql-conflict-summary",
|
|
395
|
+
children: "This will remove all existing collections and replace them with the imported data. This cannot be undone."
|
|
396
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
397
|
+
className: "graphiql-conflict-actions",
|
|
398
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
399
|
+
type: "button",
|
|
400
|
+
variant: "primary",
|
|
401
|
+
onClick: () => {
|
|
402
|
+
const text = pendingReplace;
|
|
403
|
+
setPendingReplace(null);
|
|
404
|
+
if (text !== null) applyReplace(text);
|
|
405
|
+
},
|
|
406
|
+
children: "Replace"
|
|
407
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
408
|
+
type: "button",
|
|
409
|
+
onClick: () => setPendingReplace(null),
|
|
410
|
+
children: "Cancel"
|
|
411
|
+
})]
|
|
412
|
+
})] })]
|
|
413
|
+
})
|
|
414
|
+
]
|
|
415
|
+
});
|
|
507
416
|
};
|
|
508
|
-
//#
|
|
417
|
+
//#endregion
|
|
418
|
+
export { CollectionsPanel };
|
|
419
|
+
|
|
420
|
+
//# sourceMappingURL=collections-panel.js.map
|