@graphiql/plugin-collections 0.0.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +162 -0
  2. package/dist/collections.stories.d.ts +14 -0
  3. package/dist/components/collection-item-row.d.ts +25 -0
  4. package/dist/components/collection-item-row.js +286 -0
  5. package/dist/components/collection-item-row.js.map +1 -0
  6. package/dist/components/collection-row.d.ts +32 -0
  7. package/dist/components/collection-row.js +162 -0
  8. package/dist/components/collection-row.js.map +1 -0
  9. package/dist/components/collections-panel.d.ts +9 -0
  10. package/dist/components/collections-panel.js +508 -0
  11. package/dist/components/collections-panel.js.map +1 -0
  12. package/dist/components/conflict-dialog.d.ts +11 -0
  13. package/dist/components/conflict-dialog.js +169 -0
  14. package/dist/components/conflict-dialog.js.map +1 -0
  15. package/dist/components/export-dialog.d.ts +7 -0
  16. package/dist/components/export-dialog.js +54 -0
  17. package/dist/components/export-dialog.js.map +1 -0
  18. package/dist/components/import-dialog.d.ts +10 -0
  19. package/dist/components/import-dialog.js +114 -0
  20. package/dist/components/import-dialog.js.map +1 -0
  21. package/dist/components/save-dialog.d.ts +7 -0
  22. package/dist/components/save-dialog.js +125 -0
  23. package/dist/components/save-dialog.js.map +1 -0
  24. package/dist/components/session-actions.d.ts +9 -0
  25. package/dist/components/session-actions.js +34 -0
  26. package/dist/components/session-actions.js.map +1 -0
  27. package/dist/icons/check.js +10 -0
  28. package/dist/icons/check.js.map +1 -0
  29. package/dist/icons/collections.js +10 -0
  30. package/dist/icons/collections.js.map +1 -0
  31. package/dist/icons/download.js +10 -0
  32. package/dist/icons/download.js.map +1 -0
  33. package/dist/icons/upload.js +10 -0
  34. package/dist/icons/upload.js.map +1 -0
  35. package/dist/index.d.ts +17 -0
  36. package/dist/index.js +46 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/operation-method.d.ts +10 -0
  39. package/dist/operation-method.js +28 -0
  40. package/dist/operation-method.js.map +1 -0
  41. package/dist/storage/local-storage.d.ts +3 -0
  42. package/dist/storage/local-storage.js +39 -0
  43. package/dist/storage/local-storage.js.map +1 -0
  44. package/dist/storage/tab-links.d.ts +7 -0
  45. package/dist/storage/tab-links.js +36 -0
  46. package/dist/storage/tab-links.js.map +1 -0
  47. package/dist/store.d.ts +78 -0
  48. package/dist/store.js +413 -0
  49. package/dist/store.js.map +1 -0
  50. package/dist/style.css +442 -0
  51. package/dist/types.d.ts +80 -0
  52. package/dist/types.js +9 -0
  53. package/dist/types.js.map +1 -0
  54. package/dist/utility/uuid.d.ts +4 -0
  55. package/dist/utility/uuid.js +11 -0
  56. package/dist/utility/uuid.js.map +1 -0
  57. package/package.json +60 -1
package/dist/store.js ADDED
@@ -0,0 +1,413 @@
1
+ import { createStore } from "zustand";
2
+ import { createBoundedUseStore } from "@graphiql/react";
3
+ import { z } from "zod";
4
+ import { randomId } from "./utility/uuid.js";
5
+ import { DEFAULT_COLLECTIONS_CONFIG } from "./types.js";
6
+ import { localStorageAdapter } from "./storage/local-storage.js";
7
+ import { saveTabLinks, loadTabLinks } from "./storage/tab-links.js";
8
+ const INITIAL_SAVE_DIALOG = {
9
+ open: false,
10
+ query: "",
11
+ variables: "",
12
+ headers: "",
13
+ name: ""
14
+ };
15
+ function deriveOperationName(query, fallback) {
16
+ if (fallback) {
17
+ return fallback;
18
+ }
19
+ const match = /(?:query|mutation|subscription)\s+([A-Za-z_][A-Za-z0-9_]*)/i.exec(query);
20
+ return (match == null ? void 0 : match[1]) ?? "Unnamed operation";
21
+ }
22
+ function pruneLinksForItems(links, itemIds) {
23
+ const next = {};
24
+ for (const [tabId, link] of Object.entries(links)) {
25
+ if (!itemIds.has(link.itemId)) {
26
+ next[tabId] = link;
27
+ }
28
+ }
29
+ return next;
30
+ }
31
+ const norm = (v) => v ?? "";
32
+ function itemContentEqual(a, b) {
33
+ return a.name === b.name && norm(a.query) === norm(b.query) && norm(a.variables) === norm(b.variables) && norm(a.headers) === norm(b.headers);
34
+ }
35
+ const collectionsStore = createStore((set, get) => {
36
+ const persist = async () => {
37
+ await get().storage.save(get().collections);
38
+ };
39
+ return {
40
+ collections: [],
41
+ loaded: false,
42
+ storage: localStorageAdapter,
43
+ config: DEFAULT_COLLECTIONS_CONFIG,
44
+ links: {},
45
+ saveDialog: INITIAL_SAVE_DIALOG,
46
+ actions: {
47
+ async init(storage, config) {
48
+ const collections = await storage.load();
49
+ set({
50
+ collections,
51
+ loaded: true,
52
+ storage,
53
+ config: { ...DEFAULT_COLLECTIONS_CONFIG, ...config },
54
+ // Restore tab↔item links so ⌘S on a tab reopened from the previous
55
+ // session still updates its saved operation in place.
56
+ links: loadTabLinks()
57
+ });
58
+ },
59
+ setCollections(collections) {
60
+ set({ collections });
61
+ },
62
+ async reload() {
63
+ const collections = await get().storage.load();
64
+ set({ collections });
65
+ },
66
+ createCollection(name, description) {
67
+ const c = {
68
+ id: randomId(),
69
+ name,
70
+ description,
71
+ items: [],
72
+ createdAt: Date.now(),
73
+ updatedAt: Date.now()
74
+ };
75
+ set((s) => ({ collections: [...s.collections, c] }));
76
+ void persist();
77
+ return c;
78
+ },
79
+ deleteCollection(id) {
80
+ const removed = get().collections.find((c) => c.id === id);
81
+ const removedItemIds = new Set((removed == null ? void 0 : removed.items.map((i) => i.id)) ?? []);
82
+ set((s) => ({
83
+ collections: s.collections.filter((c) => c.id !== id),
84
+ links: pruneLinksForItems(s.links, removedItemIds)
85
+ }));
86
+ void persist();
87
+ saveTabLinks(get().links);
88
+ },
89
+ renameCollection(id, name) {
90
+ set((s) => ({
91
+ collections: s.collections.map(
92
+ (c) => c.id === id ? { ...c, name, updatedAt: Date.now() } : c
93
+ )
94
+ }));
95
+ void persist();
96
+ },
97
+ addItem(collectionId, item) {
98
+ const newItem = {
99
+ ...item,
100
+ id: randomId(),
101
+ createdAt: Date.now(),
102
+ updatedAt: Date.now()
103
+ };
104
+ set((s) => ({
105
+ collections: s.collections.map(
106
+ (c) => c.id === collectionId ? { ...c, items: [...c.items, newItem], updatedAt: Date.now() } : c
107
+ )
108
+ }));
109
+ void persist();
110
+ return newItem;
111
+ },
112
+ updateItem(collectionId, itemId, updates) {
113
+ set((s) => ({
114
+ collections: s.collections.map(
115
+ (c) => c.id === collectionId ? {
116
+ ...c,
117
+ updatedAt: Date.now(),
118
+ items: c.items.map(
119
+ (i) => i.id === itemId ? { ...i, ...updates, updatedAt: Date.now() } : i
120
+ )
121
+ } : c
122
+ )
123
+ }));
124
+ void persist();
125
+ },
126
+ deleteItem(collectionId, itemId) {
127
+ set((s) => ({
128
+ collections: s.collections.map(
129
+ (c) => c.id === collectionId ? {
130
+ ...c,
131
+ items: c.items.filter((i) => i.id !== itemId),
132
+ updatedAt: Date.now()
133
+ } : c
134
+ ),
135
+ links: pruneLinksForItems(s.links, /* @__PURE__ */ new Set([itemId]))
136
+ }));
137
+ void persist();
138
+ saveTabLinks(get().links);
139
+ },
140
+ moveItem(fromCollectionId, fromIndex, toCollectionId, toIndex) {
141
+ const { collections } = get();
142
+ const fromCollection = collections.find((c) => c.id === fromCollectionId);
143
+ if (!fromCollection || fromIndex < 0 || fromIndex >= fromCollection.items.length) {
144
+ return;
145
+ }
146
+ const item = fromCollection.items[fromIndex];
147
+ if (!item) {
148
+ return;
149
+ }
150
+ const newCollections = collections.map((c) => {
151
+ if (c.id === fromCollectionId && c.id === toCollectionId) {
152
+ const items = [...c.items];
153
+ items.splice(fromIndex, 1);
154
+ items.splice(toIndex, 0, item);
155
+ return { ...c, items, updatedAt: Date.now() };
156
+ }
157
+ if (c.id === fromCollectionId) {
158
+ return {
159
+ ...c,
160
+ items: c.items.filter((_, i) => i !== fromIndex),
161
+ updatedAt: Date.now()
162
+ };
163
+ }
164
+ if (c.id === toCollectionId) {
165
+ const items = [...c.items];
166
+ items.splice(toIndex, 0, item);
167
+ return { ...c, items, updatedAt: Date.now() };
168
+ }
169
+ return c;
170
+ });
171
+ set({ collections: newCollections });
172
+ void persist();
173
+ },
174
+ analyzeImport(json) {
175
+ const empty = {
176
+ ok: false,
177
+ newCollections: [],
178
+ newItems: [],
179
+ changedItems: [],
180
+ unchangedCount: 0,
181
+ _incoming: []
182
+ };
183
+ const CollectionItemSchema = z.object({
184
+ id: z.string(),
185
+ name: z.string(),
186
+ query: z.string(),
187
+ variables: z.string().optional(),
188
+ headers: z.string().optional(),
189
+ description: z.string().optional(),
190
+ createdAt: z.number(),
191
+ updatedAt: z.number()
192
+ });
193
+ const CollectionSchema = z.object({
194
+ id: z.string(),
195
+ name: z.string(),
196
+ description: z.string().optional(),
197
+ createdAt: z.number(),
198
+ updatedAt: z.number(),
199
+ items: z.array(CollectionItemSchema)
200
+ });
201
+ const EnvelopeSchema = z.union([
202
+ z.object({
203
+ version: z.number().optional(),
204
+ collections: z.array(CollectionSchema)
205
+ }),
206
+ z.array(CollectionSchema)
207
+ ]);
208
+ let parsed;
209
+ try {
210
+ parsed = JSON.parse(json);
211
+ } catch {
212
+ return empty;
213
+ }
214
+ const result = EnvelopeSchema.safeParse(parsed);
215
+ if (!result.success) {
216
+ return empty;
217
+ }
218
+ const incoming = Array.isArray(result.data) ? result.data : result.data.collections;
219
+ if (incoming.length === 0) {
220
+ return empty;
221
+ }
222
+ const localCollections = get().collections;
223
+ const localItemMap = /* @__PURE__ */ new Map();
224
+ for (const col of localCollections) {
225
+ for (const item of col.items) {
226
+ localItemMap.set(item.id, { item, collectionId: col.id });
227
+ }
228
+ }
229
+ const localCollectionIds = new Set(localCollections.map((c) => c.id));
230
+ const newCollections = [];
231
+ const newItems = [];
232
+ const changedItems = [];
233
+ let unchangedCount = 0;
234
+ for (const incomingCol of incoming) {
235
+ const genuinelyNewItems = incomingCol.items.filter(
236
+ (item) => !localItemMap.has(item.id)
237
+ );
238
+ if (!localCollectionIds.has(incomingCol.id) && (incomingCol.items.length === 0 || genuinelyNewItems.length > 0)) {
239
+ newCollections.push({ ...incomingCol, items: [] });
240
+ }
241
+ for (const incomingItem of incomingCol.items) {
242
+ const local = localItemMap.get(incomingItem.id);
243
+ if (!local) {
244
+ newItems.push({
245
+ item: incomingItem,
246
+ // Land in the incoming parent; if that parent is new it will be
247
+ // created during apply, otherwise it already exists locally.
248
+ targetCollectionId: incomingCol.id
249
+ });
250
+ } else if (itemContentEqual(incomingItem, local.item)) {
251
+ unchangedCount++;
252
+ } else {
253
+ changedItems.push({
254
+ incoming: incomingItem,
255
+ current: local.item,
256
+ // Use where the recipient actually keeps it, not the incoming parent.
257
+ currentCollectionId: local.collectionId
258
+ });
259
+ }
260
+ }
261
+ }
262
+ return {
263
+ ok: true,
264
+ newCollections,
265
+ newItems,
266
+ changedItems,
267
+ unchangedCount,
268
+ _incoming: incoming
269
+ };
270
+ },
271
+ applyImport(analysis, resolution) {
272
+ if (!analysis.ok) {
273
+ return;
274
+ }
275
+ if (resolution.mode === "replace") {
276
+ set({ collections: analysis._incoming });
277
+ void persist();
278
+ return;
279
+ }
280
+ const now = Date.now();
281
+ let collections = [...get().collections];
282
+ for (const shell of analysis.newCollections) {
283
+ collections.push({ ...shell, items: [] });
284
+ }
285
+ for (const { item, targetCollectionId } of analysis.newItems) {
286
+ collections = collections.map(
287
+ (c) => c.id === targetCollectionId ? { ...c, items: [...c.items, item], updatedAt: now } : c
288
+ );
289
+ }
290
+ const shouldApply = (itemId) => {
291
+ if ("applyChanges" in resolution) {
292
+ return resolution.applyChanges;
293
+ }
294
+ return resolution.changedItemIds.has(itemId);
295
+ };
296
+ for (const conflict of analysis.changedItems) {
297
+ if (!shouldApply(conflict.incoming.id)) {
298
+ continue;
299
+ }
300
+ collections = collections.map((c) => {
301
+ if (c.id !== conflict.currentCollectionId) {
302
+ return c;
303
+ }
304
+ return {
305
+ ...c,
306
+ updatedAt: now,
307
+ items: c.items.map(
308
+ (i) => i.id === conflict.incoming.id ? {
309
+ // Replace content fields; keep the local createdAt.
310
+ ...conflict.incoming,
311
+ createdAt: conflict.current.createdAt,
312
+ updatedAt: now
313
+ } : i
314
+ )
315
+ };
316
+ });
317
+ }
318
+ set({ collections });
319
+ void persist();
320
+ },
321
+ exportCollections() {
322
+ return JSON.stringify(
323
+ { version: 1, collections: get().collections },
324
+ null,
325
+ 2
326
+ );
327
+ },
328
+ exportCollection(id) {
329
+ const collection = get().collections.find((c) => c.id === id);
330
+ return JSON.stringify(
331
+ { version: 1, collections: collection ? [collection] : [] },
332
+ null,
333
+ 2
334
+ );
335
+ },
336
+ exportItem(itemId) {
337
+ for (const col of get().collections) {
338
+ const item = col.items.find((i) => i.id === itemId);
339
+ if (item) {
340
+ const shell = {
341
+ id: col.id,
342
+ name: col.name,
343
+ description: col.description,
344
+ createdAt: col.createdAt,
345
+ updatedAt: col.updatedAt,
346
+ items: [item]
347
+ };
348
+ return JSON.stringify(
349
+ { version: 1, collections: [shell] },
350
+ null,
351
+ 2
352
+ );
353
+ }
354
+ }
355
+ return JSON.stringify({ version: 1, collections: [] }, null, 2);
356
+ },
357
+ linkTab(tabId, collectionId, itemId) {
358
+ set((s) => ({
359
+ // An item lives in exactly one tab: drop any stale link to it (e.g. a
360
+ // closed tab's) before recording the new one.
361
+ links: {
362
+ ...pruneLinksForItems(s.links, /* @__PURE__ */ new Set([itemId])),
363
+ [tabId]: { collectionId, itemId }
364
+ }
365
+ }));
366
+ saveTabLinks(get().links);
367
+ },
368
+ requestSave(operation) {
369
+ if (get().config.readOnly) {
370
+ return false;
371
+ }
372
+ const { links, collections, actions } = get();
373
+ const link = operation.id ? links[operation.id] : void 0;
374
+ if (link) {
375
+ const collection = collections.find((c) => c.id === link.collectionId);
376
+ const item = collection == null ? void 0 : collection.items.find((i) => i.id === link.itemId);
377
+ if (item) {
378
+ actions.updateItem(link.collectionId, link.itemId, {
379
+ query: operation.query ?? "",
380
+ variables: operation.variables ?? "",
381
+ headers: operation.headers ?? ""
382
+ });
383
+ return true;
384
+ }
385
+ }
386
+ actions.openSaveDialog({
387
+ tabId: operation.id,
388
+ query: operation.query ?? "",
389
+ variables: operation.variables ?? "",
390
+ headers: operation.headers ?? "",
391
+ name: deriveOperationName(
392
+ operation.query ?? "",
393
+ operation.operationName
394
+ )
395
+ });
396
+ return false;
397
+ },
398
+ openSaveDialog(input) {
399
+ set({ saveDialog: { ...input, open: true } });
400
+ },
401
+ closeSaveDialog() {
402
+ set((s) => ({ saveDialog: { ...s.saveDialog, open: false } }));
403
+ }
404
+ }
405
+ };
406
+ });
407
+ const useCollectionsStore = createBoundedUseStore(collectionsStore);
408
+ export {
409
+ collectionsStore,
410
+ deriveOperationName,
411
+ useCollectionsStore
412
+ };
413
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { createStore } from 'zustand';\nimport { createBoundedUseStore } from '@graphiql/react';\nimport { z } from 'zod';\nimport { randomId } from './utility/uuid';\nimport type {\n Collection,\n CollectionItem,\n CollectionsConfig,\n CollectionsStorage,\n ImportAnalysis,\n ImportResolution,\n} from './types';\nimport { DEFAULT_COLLECTIONS_CONFIG } from './types';\nimport { localStorageAdapter } from './storage/local-storage';\nimport { loadTabLinks, saveTabLinks, type TabLink } from './storage/tab-links';\n\n/** The active operation being saved, as seen by the save dialog. */\nexport type SaveDialogState = {\n open: boolean;\n /** The tab this save originated from, linked to the item once saved. */\n tabId?: string;\n query: string;\n variables: string;\n headers: string;\n name: string;\n};\n\n/** The current operation handed to `requestSave` from ⌘S or the save button. */\nexport type ActiveOperation = {\n id?: string;\n query: string | null;\n variables?: string | null;\n headers?: string | null;\n operationName?: string | null;\n};\n\ntype CollectionsState = {\n collections: Collection[];\n loaded: boolean;\n storage: CollectionsStorage;\n /** Host-controlled capability flags; set on init from the plugin options. */\n config: CollectionsConfig;\n /** Maps a tab id to the collection item it is linked to. */\n links: Record<string, TabLink>;\n saveDialog: SaveDialogState;\n};\n\ntype CollectionsActions = {\n init(\n storage: CollectionsStorage,\n config?: Partial<CollectionsConfig>,\n ): Promise<void>;\n /**\n * Replace the in-memory collections wholesale without persisting. Use this\n * to reflect state loaded or merged externally — writing it back would be\n * redundant and, for a DB adapter, an unwanted extra write.\n */\n setCollections(collections: Collection[]): void;\n /** Re-read collections from the configured storage — call after an external/remote change to refresh the UI. */\n reload(): Promise<void>;\n createCollection(name: string, description?: string): Collection;\n deleteCollection(id: string): void;\n renameCollection(id: string, name: string): void;\n addItem(\n collectionId: string,\n item: Omit<CollectionItem, 'id' | 'createdAt' | 'updatedAt'>,\n ): CollectionItem;\n updateItem(\n collectionId: string,\n itemId: string,\n updates: Partial<Omit<CollectionItem, 'id' | 'createdAt'>>,\n ): void;\n deleteItem(collectionId: string, itemId: string): void;\n moveItem(\n fromCollectionId: string,\n fromIndex: number,\n toCollectionId: string,\n toIndex: number,\n ): void;\n /** Pure analysis of an import JSON string against current store state. Never mutates. */\n analyzeImport(json: string): ImportAnalysis;\n /** Commit an analysis to the store using the given resolution strategy. */\n applyImport(analysis: ImportAnalysis, resolution: ImportResolution): void;\n exportCollections(): string;\n /** Export a single collection as a (one-collection) export envelope. */\n exportCollection(id: string): string;\n /** Export a single item as a (one-item, one-collection) export envelope. */\n exportItem(itemId: string): string;\n /** Link a tab to a collection item so ⌘S updates it in place. */\n linkTab(tabId: string, collectionId: string, itemId: string): void;\n /**\n * Save the active operation: update the linked item in place if the tab is\n * already tied to a collection item, otherwise open the save dialog. Returns\n * `true` when it saved in place (so the caller can clear the dirty state),\n * `false` when it opened the dialog instead.\n */\n requestSave(operation: ActiveOperation): boolean;\n openSaveDialog(input: Omit<SaveDialogState, 'open'>): void;\n closeSaveDialog(): void;\n};\n\nconst INITIAL_SAVE_DIALOG: SaveDialogState = {\n open: false,\n query: '',\n variables: '',\n headers: '',\n name: '',\n};\n\nexport function deriveOperationName(\n query: string,\n fallback?: string | null,\n): string {\n if (fallback) {\n return fallback;\n }\n const match =\n /(?:query|mutation|subscription)\\s+([A-Za-z_][A-Za-z0-9_]*)/i.exec(query);\n return match?.[1] ?? 'Unnamed operation';\n}\n\ntype StoreShape = CollectionsState & { actions: CollectionsActions };\n\n/** Drop every link that points at one of `itemIds`. */\nfunction pruneLinksForItems(\n links: Record<string, TabLink>,\n itemIds: Set<string>,\n): Record<string, TabLink> {\n const next: Record<string, TabLink> = {};\n for (const [tabId, link] of Object.entries(links)) {\n if (!itemIds.has(link.itemId)) {\n next[tabId] = link;\n }\n }\n return next;\n}\n\n/** Normalize optional string fields so undefined and '' are treated identically. */\nconst norm = (v: string | undefined): string => v ?? '';\n\n/** Compare only the user-visible content fields of two items, ignoring id and timestamps. */\nfunction itemContentEqual(a: CollectionItem, b: CollectionItem): boolean {\n return (\n a.name === b.name &&\n norm(a.query) === norm(b.query) &&\n norm(a.variables) === norm(b.variables) &&\n norm(a.headers) === norm(b.headers)\n );\n}\n\nexport const collectionsStore = createStore<StoreShape>((set, get) => {\n const persist = async () => {\n await get().storage.save(get().collections);\n };\n\n return {\n collections: [],\n loaded: false,\n storage: localStorageAdapter,\n config: DEFAULT_COLLECTIONS_CONFIG,\n links: {},\n saveDialog: INITIAL_SAVE_DIALOG,\n actions: {\n async init(storage, config) {\n const collections = await storage.load();\n set({\n collections,\n loaded: true,\n storage,\n config: { ...DEFAULT_COLLECTIONS_CONFIG, ...config },\n // Restore tab↔item links so ⌘S on a tab reopened from the previous\n // session still updates its saved operation in place.\n links: loadTabLinks(),\n });\n },\n setCollections(collections) {\n set({ collections });\n },\n async reload() {\n const collections = await get().storage.load();\n set({ collections });\n },\n createCollection(name, description) {\n const c: Collection = {\n id: randomId(),\n name,\n description,\n items: [],\n createdAt: Date.now(),\n updatedAt: Date.now(),\n };\n set(s => ({ collections: [...s.collections, c] }));\n void persist();\n return c;\n },\n deleteCollection(id) {\n const removed = get().collections.find(c => c.id === id);\n const removedItemIds = new Set(removed?.items.map(i => i.id) ?? []);\n set(s => ({\n collections: s.collections.filter(c => c.id !== id),\n links: pruneLinksForItems(s.links, removedItemIds),\n }));\n void persist();\n saveTabLinks(get().links);\n },\n renameCollection(id, name) {\n set(s => ({\n collections: s.collections.map(c =>\n c.id === id ? { ...c, name, updatedAt: Date.now() } : c,\n ),\n }));\n void persist();\n },\n addItem(collectionId, item) {\n const newItem: CollectionItem = {\n ...item,\n id: randomId(),\n createdAt: Date.now(),\n updatedAt: Date.now(),\n };\n set(s => ({\n collections: s.collections.map(c =>\n c.id === collectionId\n ? { ...c, items: [...c.items, newItem], updatedAt: Date.now() }\n : c,\n ),\n }));\n void persist();\n return newItem;\n },\n updateItem(collectionId, itemId, updates) {\n set(s => ({\n collections: s.collections.map(c =>\n c.id === collectionId\n ? {\n ...c,\n updatedAt: Date.now(),\n items: c.items.map(i =>\n i.id === itemId\n ? { ...i, ...updates, updatedAt: Date.now() }\n : i,\n ),\n }\n : c,\n ),\n }));\n void persist();\n },\n deleteItem(collectionId, itemId) {\n set(s => ({\n collections: s.collections.map(c =>\n c.id === collectionId\n ? {\n ...c,\n items: c.items.filter(i => i.id !== itemId),\n updatedAt: Date.now(),\n }\n : c,\n ),\n links: pruneLinksForItems(s.links, new Set([itemId])),\n }));\n void persist();\n saveTabLinks(get().links);\n },\n moveItem(fromCollectionId, fromIndex, toCollectionId, toIndex) {\n const { collections } = get();\n const fromCollection = collections.find(c => c.id === fromCollectionId);\n if (\n !fromCollection ||\n fromIndex < 0 ||\n fromIndex >= fromCollection.items.length\n ) {\n return;\n }\n\n const item = fromCollection.items[fromIndex];\n if (!item) {\n return;\n }\n const newCollections = collections.map(c => {\n if (c.id === fromCollectionId && c.id === toCollectionId) {\n const items = [...c.items];\n items.splice(fromIndex, 1);\n items.splice(toIndex, 0, item);\n return { ...c, items, updatedAt: Date.now() };\n }\n if (c.id === fromCollectionId) {\n return {\n ...c,\n items: c.items.filter((_, i) => i !== fromIndex),\n updatedAt: Date.now(),\n };\n }\n if (c.id === toCollectionId) {\n const items = [...c.items];\n items.splice(toIndex, 0, item);\n return { ...c, items, updatedAt: Date.now() };\n }\n return c;\n });\n set({ collections: newCollections });\n void persist();\n },\n analyzeImport(json) {\n const empty: ImportAnalysis = {\n ok: false,\n newCollections: [],\n newItems: [],\n changedItems: [],\n unchangedCount: 0,\n _incoming: [],\n };\n\n // Zod schemas for the import envelope.\n const CollectionItemSchema = z.object({\n id: z.string(),\n name: z.string(),\n query: z.string(),\n variables: z.string().optional(),\n headers: z.string().optional(),\n description: z.string().optional(),\n createdAt: z.number(),\n updatedAt: z.number(),\n });\n\n const CollectionSchema = z.object({\n id: z.string(),\n name: z.string(),\n description: z.string().optional(),\n createdAt: z.number(),\n updatedAt: z.number(),\n items: z.array(CollectionItemSchema),\n });\n\n const EnvelopeSchema = z.union([\n z.object({\n version: z.number().optional(),\n collections: z.array(CollectionSchema),\n }),\n z.array(CollectionSchema),\n ]);\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(json);\n } catch {\n return empty;\n }\n\n const result = EnvelopeSchema.safeParse(parsed);\n if (!result.success) {\n return empty;\n }\n\n const incoming: Collection[] = Array.isArray(result.data)\n ? result.data\n : result.data.collections;\n\n if (incoming.length === 0) {\n return empty;\n }\n\n const localCollections = get().collections;\n\n // Build a flat map: item id → { item, collectionId } for all local items.\n const localItemMap = new Map<\n string,\n { item: CollectionItem; collectionId: string }\n >();\n for (const col of localCollections) {\n for (const item of col.items) {\n localItemMap.set(item.id, { item, collectionId: col.id });\n }\n }\n\n const localCollectionIds = new Set(localCollections.map(c => c.id));\n\n const newCollections: Collection[] = [];\n const newItems: ImportAnalysis['newItems'] = [];\n const changedItems: ImportAnalysis['changedItems'] = [];\n let unchangedCount = 0;\n\n for (const incomingCol of incoming) {\n // Determine which items in this collection are genuinely new locally.\n const genuinelyNewItems = incomingCol.items.filter(\n item => !localItemMap.has(item.id),\n );\n\n // Register a new collection shell only when:\n // - the collection id is absent locally, AND\n // - it is intentionally empty OR it contributes at least one genuinely new item.\n // A new-to-us collection that only re-homes already-known items must NOT be created.\n if (\n !localCollectionIds.has(incomingCol.id) &&\n (incomingCol.items.length === 0 || genuinelyNewItems.length > 0)\n ) {\n newCollections.push({ ...incomingCol, items: [] });\n }\n\n for (const incomingItem of incomingCol.items) {\n const local = localItemMap.get(incomingItem.id);\n if (!local) {\n newItems.push({\n item: incomingItem,\n // Land in the incoming parent; if that parent is new it will be\n // created during apply, otherwise it already exists locally.\n targetCollectionId: incomingCol.id,\n });\n } else if (itemContentEqual(incomingItem, local.item)) {\n unchangedCount++;\n } else {\n changedItems.push({\n incoming: incomingItem,\n current: local.item,\n // Use where the recipient actually keeps it, not the incoming parent.\n currentCollectionId: local.collectionId,\n });\n }\n }\n }\n\n return {\n ok: true,\n newCollections,\n newItems,\n changedItems,\n unchangedCount,\n _incoming: incoming,\n };\n },\n applyImport(analysis, resolution) {\n if (!analysis.ok) {\n return;\n }\n\n if (resolution.mode === 'replace') {\n set({ collections: analysis._incoming });\n void persist();\n return;\n }\n\n // Merge mode.\n const now = Date.now();\n let collections = [...get().collections];\n\n // 1. Create new collection shells.\n for (const shell of analysis.newCollections) {\n collections.push({ ...shell, items: [] });\n }\n\n // 2. Add new items into their target collections.\n for (const { item, targetCollectionId } of analysis.newItems) {\n collections = collections.map(c =>\n c.id === targetCollectionId\n ? { ...c, items: [...c.items, item], updatedAt: now }\n : c,\n );\n }\n\n // 3. Apply changed items per resolution.\n const shouldApply = (itemId: string): boolean => {\n if ('applyChanges' in resolution) {\n return resolution.applyChanges;\n }\n return resolution.changedItemIds.has(itemId);\n };\n\n for (const conflict of analysis.changedItems) {\n if (!shouldApply(conflict.incoming.id)) {\n continue;\n }\n collections = collections.map(c => {\n if (c.id !== conflict.currentCollectionId) {\n return c;\n }\n return {\n ...c,\n updatedAt: now,\n items: c.items.map(i =>\n i.id === conflict.incoming.id\n ? {\n // Replace content fields; keep the local createdAt.\n ...conflict.incoming,\n createdAt: conflict.current.createdAt,\n updatedAt: now,\n }\n : i,\n ),\n };\n });\n }\n\n set({ collections });\n void persist();\n },\n exportCollections() {\n return JSON.stringify(\n { version: 1, collections: get().collections },\n null,\n 2,\n );\n },\n exportCollection(id) {\n const collection = get().collections.find(c => c.id === id);\n return JSON.stringify(\n { version: 1, collections: collection ? [collection] : [] },\n null,\n 2,\n );\n },\n exportItem(itemId) {\n for (const col of get().collections) {\n const item = col.items.find(i => i.id === itemId);\n if (item) {\n const shell: Collection = {\n id: col.id,\n name: col.name,\n description: col.description,\n createdAt: col.createdAt,\n updatedAt: col.updatedAt,\n items: [item],\n };\n return JSON.stringify(\n { version: 1, collections: [shell] },\n null,\n 2,\n );\n }\n }\n return JSON.stringify({ version: 1, collections: [] }, null, 2);\n },\n linkTab(tabId, collectionId, itemId) {\n set(s => ({\n // An item lives in exactly one tab: drop any stale link to it (e.g. a\n // closed tab's) before recording the new one.\n links: {\n ...pruneLinksForItems(s.links, new Set([itemId])),\n [tabId]: { collectionId, itemId },\n },\n }));\n saveTabLinks(get().links);\n },\n requestSave(operation) {\n // Authoritative gate: saving is disabled in read-only mode regardless\n // of how it was triggered (⌘S, save button, etc.).\n if (get().config.readOnly) {\n return false;\n }\n const { links, collections, actions } = get();\n const link = operation.id ? links[operation.id] : undefined;\n if (link) {\n const collection = collections.find(c => c.id === link.collectionId);\n const item = collection?.items.find(i => i.id === link.itemId);\n if (item) {\n actions.updateItem(link.collectionId, link.itemId, {\n query: operation.query ?? '',\n variables: operation.variables ?? '',\n headers: operation.headers ?? '',\n });\n return true;\n }\n }\n actions.openSaveDialog({\n tabId: operation.id,\n query: operation.query ?? '',\n variables: operation.variables ?? '',\n headers: operation.headers ?? '',\n name: deriveOperationName(\n operation.query ?? '',\n operation.operationName,\n ),\n });\n return false;\n },\n openSaveDialog(input) {\n set({ saveDialog: { ...input, open: true } });\n },\n closeSaveDialog() {\n set(s => ({ saveDialog: { ...s.saveDialog, open: false } }));\n },\n },\n };\n});\n\nexport const useCollectionsStore = createBoundedUseStore(collectionsStore);\n"],"names":[],"mappings":";;;;;;;AAqGA,MAAM,sBAAuC;AAAA,EAC3C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,WAAW;AAAA,EACX,SAAS;AAAA,EACT,MAAM;AACR;AAEgB,SAAA,oB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