@graphiql/plugin-collections 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/components/collection-item-row.js +7 -8
  2. package/dist/components/collection-item-row.js.map +1 -1
  3. package/dist/components/collection-row.js +20 -18
  4. package/dist/components/collection-row.js.map +1 -1
  5. package/dist/components/collections-panel.js +8 -7
  6. package/dist/components/collections-panel.js.map +1 -1
  7. package/dist/components/conflict-dialog.js +2 -3
  8. package/dist/components/conflict-dialog.js.map +1 -1
  9. package/dist/components/export-dialog.js +4 -5
  10. package/dist/components/export-dialog.js.map +1 -1
  11. package/dist/components/import-dialog.js +5 -6
  12. package/dist/components/import-dialog.js.map +1 -1
  13. package/dist/components/save-dialog.js +82 -93
  14. package/dist/components/save-dialog.js.map +1 -1
  15. package/dist/components/session-actions.d.ts +1 -1
  16. package/dist/components/session-actions.js +4 -5
  17. package/dist/components/session-actions.js.map +1 -1
  18. package/dist/icons/check.js +1 -2
  19. package/dist/icons/check.js.map +1 -1
  20. package/dist/icons/collections.js +1 -2
  21. package/dist/icons/collections.js.map +1 -1
  22. package/dist/icons/download.js +1 -2
  23. package/dist/icons/download.js.map +1 -1
  24. package/dist/icons/upload.js +1 -2
  25. package/dist/icons/upload.js.map +1 -1
  26. package/dist/index.js +4 -5
  27. package/dist/index.js.map +1 -1
  28. package/dist/operation-method.js +1 -2
  29. package/dist/storage/local-storage.js +1 -2
  30. package/dist/storage/tab-links.js +1 -2
  31. package/dist/store.d.ts +3 -1
  32. package/dist/store.js +9 -8
  33. package/dist/store.js.map +1 -1
  34. package/dist/style.css +11 -49
  35. package/dist/types.js +1 -2
  36. package/dist/utility/uuid.js +1 -2
  37. package/package.json +12 -12
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","names":[],"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. The\n * returned promise settles after storage commits or the dialog is cancelled.\n */\n requestSave(operation: ActiveOperation): Promise<boolean>;\n commitSaveDialog(input: {\n name: string;\n description?: string;\n collectionId?: string;\n newCollectionName?: string;\n }): Promise<void>;\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 let pendingDialog:\n | { resolve: (saved: boolean) => void; reject: (error: unknown) => void }\n | undefined;\n let committingDialog = false;\n let lastPersist: Promise<void> = Promise.resolve();\n const queueWrite = async (write: () => Promise<void>) => {\n const previous = lastPersist;\n let release!: () => void;\n lastPersist = new Promise<void>(resolve => {\n release = resolve;\n });\n await previous;\n try {\n await write();\n } finally {\n release();\n }\n };\n const persist = async () => {\n try {\n await queueWrite(() => get().storage.save(get().collections));\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to persist collections', error);\n }\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 async 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 if (get().saveDialog.open) {\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 await queueWrite(async () => {\n const target = get()\n .collections.find(c => c.id === link.collectionId)\n ?.items.find(i => i.id === link.itemId);\n if (!target) {\n throw new Error('Saved collection item no longer exists');\n }\n const next = get().collections.map(c =>\n c.id === link.collectionId\n ? {\n ...c,\n updatedAt: Date.now(),\n items: c.items.map(i =>\n i.id === link.itemId\n ? {\n ...i,\n query: operation.query ?? '',\n variables: operation.variables ?? '',\n headers: operation.headers ?? '',\n updatedAt: Date.now(),\n }\n : i,\n ),\n }\n : c,\n );\n await get().storage.save(next);\n set({ collections: next });\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 new Promise<boolean>((resolve, reject) => {\n pendingDialog = { resolve, reject };\n });\n },\n async commitSaveDialog(input) {\n const { saveDialog, collections } = get();\n if (!saveDialog.open || committingDialog) {\n return;\n }\n if (\n input.collectionId &&\n !collections.some(c => c.id === input.collectionId)\n ) {\n const error = new Error('Selected collection no longer exists');\n pendingDialog?.reject(error);\n pendingDialog = undefined;\n get().actions.closeSaveDialog();\n throw error;\n }\n committingDialog = true;\n const now = Date.now();\n const item: CollectionItem = {\n id: randomId(),\n name: input.name || 'Unnamed operation',\n description: input.description || undefined,\n query: saveDialog.query,\n variables: saveDialog.variables,\n headers: saveDialog.headers,\n createdAt: now,\n updatedAt: now,\n };\n const collectionId = input.collectionId ?? randomId();\n try {\n await queueWrite(async () => {\n if (\n input.collectionId &&\n !get().collections.some(c => c.id === collectionId)\n ) {\n throw new Error('Selected collection no longer exists');\n }\n const next = input.collectionId\n ? get().collections.map(c =>\n c.id === collectionId\n ? { ...c, items: [...c.items, item], updatedAt: now }\n : c,\n )\n : [\n ...get().collections,\n {\n id: collectionId,\n name: input.newCollectionName || 'New Collection',\n items: [item],\n createdAt: now,\n updatedAt: now,\n },\n ];\n await get().storage.save(next);\n set({ collections: next });\n });\n if (saveDialog.tabId) {\n get().actions.linkTab(saveDialog.tabId, collectionId, item.id);\n }\n pendingDialog?.resolve(true);\n pendingDialog = undefined;\n committingDialog = false;\n get().actions.closeSaveDialog();\n } catch (error) {\n pendingDialog?.reject(error);\n pendingDialog = undefined;\n committingDialog = false;\n get().actions.closeSaveDialog();\n throw error;\n }\n },\n openSaveDialog(input) {\n set({ saveDialog: { ...input, open: true } });\n },\n closeSaveDialog() {\n if (committingDialog) {\n return;\n }\n pendingDialog?.resolve(false);\n pendingDialog = undefined;\n set(s => ({ saveDialog: { ...s.saveDialog, open: false } }));\n },\n },\n };\n});\n\nexport const useCollectionsStore = createBoundedUseStore(collectionsStore);\n"],"mappings":";;;;;;;;AA0GA,IAAM,sBAAuC;CAC3C,MAAM;CACN,OAAO;CACP,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,SAAgB,oBACd,OACA,UACQ;CACR,IAAI,UACF,OAAO;CAIT,OADE,8DAA8D,KAAK,KAC9D,CAA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ore } 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 /** Identifies a fresh request, including operations with the same name. */\n requestId?: number;\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. The\n * returned promise settles after storage commits or the dialog is cancelled.\n */\n requestSave(operation: ActiveOperation): Promise<boolean>;\n commitSaveDialog(input: {\n name: string;\n description?: string;\n collectionId?: string;\n newCollectionName?: string;\n }): Promise<void>;\n openSaveDialog(input: Omit<SaveDialogState, 'open' | 'requestId'>): void;\n closeSaveDialog(): void;\n};\n\nconst INITIAL_SAVE_DIALOG: SaveDialogState = {\n open: false,\n requestId: 0,\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 let pendingDialog:\n | { resolve: (saved: boolean) => void; reject: (error: unknown) => void }\n | undefined;\n let committingDialog = false;\n let lastPersist: Promise<void> = Promise.resolve();\n const queueWrite = async (write: () => Promise<void>) => {\n const previous = lastPersist;\n let release!: () => void;\n lastPersist = new Promise<void>(resolve => {\n release = resolve;\n });\n await previous;\n try {\n await write();\n } finally {\n release();\n }\n };\n const persist = async () => {\n try {\n await queueWrite(() => get().storage.save(get().collections));\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to persist collections', error);\n }\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 async 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 if (get().saveDialog.open) {\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 await queueWrite(async () => {\n const target = get()\n .collections.find(c => c.id === link.collectionId)\n ?.items.find(i => i.id === link.itemId);\n if (!target) {\n throw new Error('Saved collection item no longer exists');\n }\n const next = get().collections.map(c =>\n c.id === link.collectionId\n ? {\n ...c,\n updatedAt: Date.now(),\n items: c.items.map(i =>\n i.id === link.itemId\n ? {\n ...i,\n query: operation.query ?? '',\n variables: operation.variables ?? '',\n headers: operation.headers ?? '',\n updatedAt: Date.now(),\n }\n : i,\n ),\n }\n : c,\n );\n await get().storage.save(next);\n set({ collections: next });\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 new Promise<boolean>((resolve, reject) => {\n pendingDialog = { resolve, reject };\n });\n },\n async commitSaveDialog(input) {\n const { saveDialog, collections } = get();\n if (!saveDialog.open || committingDialog) {\n return;\n }\n if (\n input.collectionId &&\n !collections.some(c => c.id === input.collectionId)\n ) {\n const error = new Error('Selected collection no longer exists');\n pendingDialog?.reject(error);\n pendingDialog = undefined;\n get().actions.closeSaveDialog();\n throw error;\n }\n committingDialog = true;\n const now = Date.now();\n const item: CollectionItem = {\n id: randomId(),\n name: input.name || 'Unnamed operation',\n description: input.description || undefined,\n query: saveDialog.query,\n variables: saveDialog.variables,\n headers: saveDialog.headers,\n createdAt: now,\n updatedAt: now,\n };\n const collectionId = input.collectionId ?? randomId();\n try {\n await queueWrite(async () => {\n if (\n input.collectionId &&\n !get().collections.some(c => c.id === collectionId)\n ) {\n throw new Error('Selected collection no longer exists');\n }\n const next = input.collectionId\n ? get().collections.map(c =>\n c.id === collectionId\n ? { ...c, items: [...c.items, item], updatedAt: now }\n : c,\n )\n : [\n ...get().collections,\n {\n id: collectionId,\n name: input.newCollectionName || 'New Collection',\n items: [item],\n createdAt: now,\n updatedAt: now,\n },\n ];\n await get().storage.save(next);\n set({ collections: next });\n });\n if (saveDialog.tabId) {\n get().actions.linkTab(saveDialog.tabId, collectionId, item.id);\n }\n pendingDialog?.resolve(true);\n pendingDialog = undefined;\n committingDialog = false;\n get().actions.closeSaveDialog();\n } catch (error) {\n pendingDialog?.reject(error);\n pendingDialog = undefined;\n committingDialog = false;\n get().actions.closeSaveDialog();\n throw error;\n }\n },\n openSaveDialog(input) {\n set(s => ({\n saveDialog: {\n ...input,\n open: true,\n requestId: (s.saveDialog.requestId ?? 0) + 1,\n },\n }));\n },\n closeSaveDialog() {\n if (committingDialog) {\n return;\n }\n pendingDialog?.resolve(false);\n pendingDialog = undefined;\n set(s => ({ saveDialog: { ...s.saveDialog, open: false } }));\n },\n },\n };\n});\n\nexport const useCollectionsStore = createBoundedUseStore(collectionsStore);\n"],"mappings":";;;;;;;;AA4GA,IAAM,sBAAuC;CAC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;IAChB,KAAI,OAAM,EAAE,YAAY;KAAE,GAAG,EAAE;KAAY,MAAM;IAAM,EAAE,EAAE;GAC7D;EACF;CACF;AACF,CAAC;AAED,IAAa,sBAAsB,sBAAsB,gBAAgB"}
package/dist/style.css CHANGED
@@ -11,7 +11,7 @@
11
11
  }
12
12
 
13
13
  .graphiql-collections-status {
14
- padding: var(--px-4) var(--px-12);
14
+ padding-block: var(--px-4);
15
15
  font-size: var(--font-size-eyebrow);
16
16
  color: oklch(var(--accent-green));
17
17
  }
@@ -26,13 +26,13 @@
26
26
  }
27
27
 
28
28
  .graphiql-collections-empty, .graphiql-collections-loading {
29
- padding: var(--px-8) var(--px-12);
29
+ padding-block: var(--px-8);
30
30
  color: oklch(var(--fg-subtle));
31
31
  font-size: var(--font-size-eyebrow);
32
32
  }
33
33
 
34
34
  .graphiql-collections-toolbar {
35
- padding: var(--px-6) var(--px-8);
35
+ padding-block: var(--px-6);
36
36
  border-bottom: 1px solid oklch(var(--border-default) / .5);
37
37
  justify-content: space-between;
38
38
  align-items: center;
@@ -74,7 +74,7 @@
74
74
  .graphiql-collection-header {
75
75
  align-items: center;
76
76
  gap: var(--px-8);
77
- padding: var(--px-8) var(--px-12);
77
+ padding-block: var(--px-8);
78
78
  cursor: pointer;
79
79
  -webkit-user-select: none;
80
80
  user-select: none;
@@ -112,14 +112,10 @@
112
112
  overflow: hidden;
113
113
  }
114
114
 
115
- .graphiql-collection-rename-input {
116
- font-size: var(--font-size-body);
117
- background: oklch(var(--bg-subtle));
118
- border: 1px solid oklch(var(--border-default));
119
- border-radius: var(--border-radius-4);
120
- padding: 2px var(--px-6);
121
- color: oklch(var(--fg-default));
115
+ .graphiql-collection-rename-field {
116
+ flex-direction: column;
122
117
  flex: 1;
118
+ display: flex;
123
119
  }
124
120
 
125
121
  .graphiql-collection-badge {
@@ -184,17 +180,19 @@
184
180
  }
185
181
 
186
182
  .graphiql-collection-empty-hint {
187
- padding: var(--px-6) var(--px-12) var(--px-8) var(--px-20);
183
+ padding-block: var(--px-6) var(--px-8);
188
184
  font-size: var(--font-size-eyebrow);
189
185
  color: oklch(var(--fg-subtle));
186
+ padding-inline-start: var(--px-8);
190
187
  font-style: italic;
191
188
  }
192
189
 
193
190
  .graphiql-collection-item-row {
194
191
  align-items: center;
195
192
  gap: var(--px-8);
196
- padding: var(--px-6) var(--px-12) var(--px-6) var(--px-20);
193
+ padding-block: var(--px-6);
197
194
  cursor: pointer;
195
+ padding-inline-start: var(--px-8);
198
196
  display: flex;
199
197
  }
200
198
 
@@ -264,16 +262,6 @@
264
262
  display: flex;
265
263
  }
266
264
 
267
- .graphiql-collection-item-edit-input {
268
- font-size: var(--font-size-body);
269
- background: oklch(var(--bg-subtle));
270
- border: 1px solid oklch(var(--border-default));
271
- border-radius: var(--border-radius-4);
272
- padding: 2px var(--px-6);
273
- color: oklch(var(--fg-default));
274
- width: 100%;
275
- }
276
-
277
265
  .graphiql-save-dialog-field {
278
266
  gap: var(--px-4);
279
267
  font-size: var(--font-size-eyebrow);
@@ -282,38 +270,12 @@
282
270
  display: flex;
283
271
  }
284
272
 
285
- .graphiql-save-dialog-input, .graphiql-save-dialog-select {
286
- background: oklch(var(--bg-subtle));
287
- border: 1px solid oklch(var(--border-default));
288
- border-radius: var(--radius-sm);
289
- padding: var(--px-6) var(--px-8);
290
- color: oklch(var(--fg-default));
291
- font-size: var(--font-size-body);
292
- }
293
-
294
- .graphiql-save-dialog-input:focus-visible, .graphiql-save-dialog-select:focus-visible {
295
- outline: 2px solid oklch(var(--accent-blue));
296
- outline-offset: -1px;
297
- }
298
-
299
273
  .graphiql-import-export-section {
300
274
  gap: var(--px-8);
301
275
  flex-direction: column;
302
276
  display: flex;
303
277
  }
304
278
 
305
- .graphiql-import-export-textarea {
306
- background: oklch(var(--bg-subtle));
307
- border: 1px solid oklch(var(--border-default));
308
- border-radius: var(--radius-sm);
309
- width: 100%;
310
- padding: var(--px-8);
311
- color: oklch(var(--fg-default));
312
- font-family: var(--font-family-mono);
313
- resize: vertical;
314
- font-size: 12px;
315
- }
316
-
317
279
  .graphiql-import-export-actions {
318
280
  gap: var(--px-8);
319
281
  align-self: flex-start;
package/dist/types.js CHANGED
@@ -1,10 +1,9 @@
1
- //#region src/types.ts
1
+ // src/types.ts
2
2
  var DEFAULT_COLLECTIONS_CONFIG = {
3
3
  readOnly: false,
4
4
  allowImportExport: true,
5
5
  allowReplace: true
6
6
  };
7
- //#endregion
8
7
  export { DEFAULT_COLLECTIONS_CONFIG };
9
8
 
10
9
  //# sourceMappingURL=types.js.map
@@ -1,4 +1,4 @@
1
- //#region src/utility/uuid.ts
1
+ // src/utility/uuid.ts
2
2
  /** Stable unique id for collections and operations. Uses `crypto.randomUUID`
3
3
  * when available, falling back to a timestamp + random suffix on plain http
4
4
  * where `crypto.randomUUID` is undefined. */
@@ -7,7 +7,6 @@ function randomId() {
7
7
  if (c && typeof c.randomUUID === "function") return c.randomUUID();
8
8
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
9
9
  }
10
- //#endregion
11
10
  export { randomId };
12
11
 
13
12
  //# sourceMappingURL=uuid.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphiql/plugin-collections",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -32,32 +32,32 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "zod": "^4.0.0",
35
+ "zod": "^4.6.6",
36
36
  "zustand": "^5"
37
37
  },
38
38
  "peerDependencies": {
39
- "@graphiql/react": "^1.0.0",
39
+ "@graphiql/react": "^1.1.0",
40
40
  "graphql": "^16.11.0 || ^17.0.0",
41
41
  "react": "^18 || ^19",
42
42
  "react-dom": "^18 || ^19"
43
43
  },
44
44
  "devDependencies": {
45
- "@graphiql/react": "^1.0.0",
46
- "@storybook/react-vite": "^10.3.6",
45
+ "@graphiql/react": "^1.1.0",
46
+ "@storybook/react-vite": "^10.6.9",
47
47
  "@testing-library/dom": "^10.4.0",
48
- "@testing-library/jest-dom": "^7.0.1",
48
+ "@testing-library/jest-dom": "^8.0.0",
49
49
  "@testing-library/react": "^16.3.0",
50
50
  "@types/react": "^19",
51
51
  "@types/react-dom": "^19",
52
- "@typescript/native": "npm:typescript@7.1.0-beta",
53
- "@vitejs/plugin-react": "^5.2.0",
54
- "graphql": "^17.0.2",
52
+ "@typescript/native": "npm:typescript@^7.0.2",
53
+ "@vitejs/plugin-react": "^6.3.0",
54
+ "graphql": "^17.1.0",
55
55
  "react": "^19.1.0",
56
56
  "react-dom": "^19.1.0",
57
- "vite": "^8.2.2",
58
- "vite-plugin-dts": "^4.5.3",
57
+ "vite": "^8.4.0",
58
+ "vite-plugin-dts": "^5.1.2",
59
59
  "vite-plugin-svgr": "^5.2.0",
60
- "typescript": "^5.8.0"
60
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
61
61
  },
62
62
  "scripts": {
63
63
  "types:check": "tsc --noEmit",