@graphiql/plugin-collections 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/collection-item-row.js +212 -282
  3. package/dist/components/collection-item-row.js.map +1 -1
  4. package/dist/components/collection-row.js +139 -159
  5. package/dist/components/collection-row.js.map +1 -1
  6. package/dist/components/collections-panel.js +408 -496
  7. package/dist/components/collections-panel.js.map +1 -1
  8. package/dist/components/conflict-dialog.js +148 -164
  9. package/dist/components/conflict-dialog.js.map +1 -1
  10. package/dist/components/export-dialog.js +52 -52
  11. package/dist/components/export-dialog.js.map +1 -1
  12. package/dist/components/import-dialog.js +100 -112
  13. package/dist/components/import-dialog.js.map +1 -1
  14. package/dist/components/save-dialog.js +116 -124
  15. package/dist/components/save-dialog.js.map +1 -1
  16. package/dist/components/session-actions.js +23 -31
  17. package/dist/components/session-actions.js.map +1 -1
  18. package/dist/icons/check.js +18 -9
  19. package/dist/icons/check.js.map +1 -1
  20. package/dist/icons/collections.js +16 -9
  21. package/dist/icons/collections.js.map +1 -1
  22. package/dist/icons/download.js +16 -9
  23. package/dist/icons/download.js.map +1 -1
  24. package/dist/icons/upload.js +16 -9
  25. package/dist/icons/upload.js.map +1 -1
  26. package/dist/index.js +31 -41
  27. package/dist/index.js.map +1 -1
  28. package/dist/operation-method.js +24 -24
  29. package/dist/operation-method.js.map +1 -1
  30. package/dist/storage/local-storage.js +32 -37
  31. package/dist/storage/local-storage.js.map +1 -1
  32. package/dist/storage/tab-links.js +27 -30
  33. package/dist/storage/tab-links.js.map +1 -1
  34. package/dist/store.js +365 -402
  35. package/dist/store.js.map +1 -1
  36. package/dist/style.css +6 -27
  37. package/dist/types.js +9 -8
  38. package/dist/types.js.map +1 -1
  39. package/dist/utility/uuid.js +11 -9
  40. package/dist/utility/uuid.js.map +1 -1
  41. package/package.json +19 -15
package/dist/store.js.map CHANGED
@@ -1 +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,oBACd,OACA,UACQ;AACR,MAAI,UAAU;AACL,WAAA;AAAA,EAAA;AAEH,QAAA,QACJ,8DAA8D,KAAK,KAAK;AACnE,UAAA,+BAAQ,OAAM;AACvB;AAKA,SAAS,mBACP,OACA,SACyB;AACzB,QAAM,OAAgC,CAAC;AACvC,aAAW,CAAC,OAAO,IAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AACjD,QAAI,CAAC,QAAQ,IAAI,KAAK,MAAM,GAAG;AAC7B,WAAK,KAAK,IAAI;AAAA,IAAA;AAAA,EAChB;AAEK,SAAA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,EAAE,YAAY,EAAE,GAAG,OAAO,MAAM,KAAA,GAAQ;AAAA,MAC9C;AAAA,MACA,kBAAkB;AACZ,YAAA,CAAA,OAAM,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,MAAM,MAAM,EAAA,EAAI;AAAA,MAAA;AAAA,IAC7D;AAAA,EAEJ;AACF,CAAC;AAEY,MAAA,sBAAsB,sBAAsB,gBAAgB;"}
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. 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"],"mappings":";;;;;;;;AAqGA,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,CAAA,GAAQ,MAAM;AACvB;;AAKA,SAAS,mBACP,OACA,SACyB;CACzB,MAAM,OAAgC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AAE,GAAG,MAAM,CAAC;GAChE;GACA,QAAQ,OAAO,cAAc,QAAQ;IACnC,KAAI,OAAM,EAGR,OAAO;KACL,GAAG,mBAAmB,EAAE,uBAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;MAC/C,QAAQ;MAAE;MAAc;KAAO;IAClC,EACF,EAAE;IACF,aAAa,IAAI,CAAC,CAAC,KAAK;GAC1B;GACA,YAAY,WAAW;IAGrB,IAAI,IAAI,CAAC,CAAC,OAAO,UACf,OAAO;IAET,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI;IAC5C,MAAM,OAAO,UAAU,KAAK,MAAM,UAAU,MAAM,KAAA;IAClD,IAAI,MACiB;SAAA,YAAY,MAAK,MAAK,EAAE,OAAO,KAAK,YAC1C,CAAA,EAAY,MAAM,MAAK,MAAK,EAAE,OAAO,KAAK,MAAM,GACnD;MACR,QAAQ,WAAW,KAAK,cAAc,KAAK,QAAQ;OACjD,OAAO,UAAU,SAAS;OAC1B,WAAW,UAAU,aAAa;OAClC,SAAS,UAAU,WAAW;MAChC,CAAC;MACD,OAAO;KACT;;IAEF,QAAQ,eAAe;KACrB,OAAO,UAAU;KACjB,OAAO,UAAU,SAAS;KAC1B,WAAW,UAAU,aAAa;KAClC,SAAS,UAAU,WAAW;KAC9B,MAAM,oBACJ,UAAU,SAAS,IACnB,UAAU,aACZ;IACF,CAAC;IACD,OAAO;GACT;GACA,eAAe,OAAO;IACpB,IAAI,EAAE,YAAY;KAAE,GAAG;KAAO,MAAM;IAAK,EAAE,CAAC;GAC9C;GACA,kBAAkB;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
@@ -155,15 +155,7 @@
155
155
  display: flex;
156
156
  }
157
157
 
158
- .graphiql-collection-header:hover .graphiql-collection-header-action, .graphiql-collection-item-row:hover .graphiql-collection-item-action {
159
- opacity: 1;
160
- }
161
-
162
- .graphiql-collection-header-action:focus-visible {
163
- opacity: 1;
164
- }
165
-
166
- .graphiql-collection-item-action:focus-visible {
158
+ .graphiql-collection-header:hover .graphiql-collection-header-action, .graphiql-collection-item-row:hover .graphiql-collection-item-action, .graphiql-collection-header-action:focus-visible, .graphiql-collection-item-action:focus-visible {
167
159
  opacity: 1;
168
160
  }
169
161
 
@@ -172,12 +164,7 @@
172
164
  background: oklch(var(--bg-subtle));
173
165
  }
174
166
 
175
- .graphiql-collection-header-action:focus-visible {
176
- outline: 2px solid oklch(var(--accent-blue));
177
- outline-offset: -2px;
178
- }
179
-
180
- .graphiql-collection-item-action:focus-visible {
167
+ .graphiql-collection-header-action:focus-visible, .graphiql-collection-item-action:focus-visible {
181
168
  outline: 2px solid oklch(var(--accent-blue));
182
169
  outline-offset: -2px;
183
170
  }
@@ -250,12 +237,8 @@
250
237
  }
251
238
 
252
239
  .graphiql-collection-method-pill-mix {
253
- color: #f8f8f8;
254
- color: color(display-p3 .973691 .973691 .973691);
255
- color: lab(97.68% -.0000298023 .0000119209);
256
- background: #6d717e;
257
- background: color(display-p3 .429873 .443602 .48851);
258
- background: lab(47.6814% .289828 -7.49383);
240
+ color: oklch(98% 0 0);
241
+ background: oklch(55% .02 270);
259
242
  }
260
243
 
261
244
  .graphiql-collection-item-main {
@@ -308,12 +291,7 @@
308
291
  font-size: var(--font-size-body);
309
292
  }
310
293
 
311
- .graphiql-save-dialog-input:focus-visible {
312
- outline: 2px solid oklch(var(--accent-blue));
313
- outline-offset: -1px;
314
- }
315
-
316
- .graphiql-save-dialog-select:focus-visible {
294
+ .graphiql-save-dialog-input:focus-visible, .graphiql-save-dialog-select:focus-visible {
317
295
  outline: 2px solid oklch(var(--accent-blue));
318
296
  outline-offset: -1px;
319
297
  }
@@ -440,3 +418,4 @@
440
418
  position: absolute;
441
419
  overflow: hidden;
442
420
  }
421
+ /*$vite$:1*/
package/dist/types.js CHANGED
@@ -1,9 +1,10 @@
1
- const DEFAULT_COLLECTIONS_CONFIG = {
2
- readOnly: false,
3
- allowImportExport: true,
4
- allowReplace: true
1
+ //#region src/types.ts
2
+ var DEFAULT_COLLECTIONS_CONFIG = {
3
+ readOnly: false,
4
+ allowImportExport: true,
5
+ allowReplace: true
5
6
  };
6
- export {
7
- DEFAULT_COLLECTIONS_CONFIG
8
- };
9
- //# sourceMappingURL=types.js.map
7
+ //#endregion
8
+ export { DEFAULT_COLLECTIONS_CONFIG };
9
+
10
+ //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["export type Collection = {\n id: string;\n name: string;\n description?: string;\n createdAt: number;\n updatedAt: number;\n items: CollectionItem[];\n};\n\nexport type CollectionItem = {\n id: string;\n name: string;\n query: string;\n variables?: string;\n headers?: string;\n description?: string;\n createdAt: number;\n updatedAt: number;\n};\n\n/**\n * Host-controlled capability flags. All capabilities are on by default; a host\n * can turn any of them off to run a governed, read-only, or share-disabled\n * collections experience.\n */\nexport type CollectionsConfig = {\n /** When true, no write operations are possible (export & copy still allowed). */\n readOnly: boolean;\n /** Master switch for the import/export feature (hides both import and export). */\n allowImportExport: boolean;\n /** When false, the destructive \"Replace\" import option is hidden. */\n allowReplace: boolean;\n};\n\nexport const DEFAULT_COLLECTIONS_CONFIG: CollectionsConfig = {\n readOnly: false,\n allowImportExport: true,\n allowReplace: true,\n};\n\n/** Pluggable storage interface. Default localStorage adapter ships with the plugin. */\nexport type CollectionsStorage = {\n storageKey?: string;\n load(): Promise<Collection[]>;\n save(collections: Collection[]): Promise<void>;\n};\n\n/** An incoming item paired with the collection it should land in. */\nexport type PlacedItem = {\n item: CollectionItem;\n targetCollectionId: string;\n};\n\n/** An incoming item whose id matches a local item but whose content differs. */\nexport type ItemConflict = {\n incoming: CollectionItem;\n /** The local copy of the item before any merge. */\n current: CollectionItem;\n /** The collection where the recipient currently keeps this item (may differ from incoming parent). */\n currentCollectionId: string;\n};\n\n/** Result of `analyzeImport`. Pure — does not mutate store state. */\nexport type ImportAnalysis = {\n ok: boolean;\n /** Collection shells (no items) whose id is absent locally — to be created on apply. */\n newCollections: Collection[];\n /** Items whose id exists nowhere locally. */\n newItems: PlacedItem[];\n /** Items whose id matches a local item but content differs. */\n changedItems: ItemConflict[];\n /** Items that are byte-for-byte identical to the local copy — nothing to do. */\n unchangedCount: number;\n /** @internal Full parsed incoming list, needed for replace mode in applyImport. */\n _incoming: Collection[];\n};\n\n/**\n * How to resolve the import when applying.\n * - `replace` — wholesale overwrite (equivalent to old replace mode).\n * - `merge` with `applyChanges` — apply all or none of the changed items.\n * - `merge` with `changedItemIds` — apply only the listed subset of changed items.\n */\nexport type ImportResolution =\n | { mode: 'replace' }\n | { mode: 'merge'; applyChanges: boolean }\n | { mode: 'merge'; changedItemIds: Set<string> };\n"],"names":[],"mappings":"AAkCO,MAAM,6BAAgD;AAAA,EAC3D,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,cAAc;AAChB;"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type Collection = {\n id: string;\n name: string;\n description?: string;\n createdAt: number;\n updatedAt: number;\n items: CollectionItem[];\n};\n\nexport type CollectionItem = {\n id: string;\n name: string;\n query: string;\n variables?: string;\n headers?: string;\n description?: string;\n createdAt: number;\n updatedAt: number;\n};\n\n/**\n * Host-controlled capability flags. All capabilities are on by default; a host\n * can turn any of them off to run a governed, read-only, or share-disabled\n * collections experience.\n */\nexport type CollectionsConfig = {\n /** When true, no write operations are possible (export & copy still allowed). */\n readOnly: boolean;\n /** Master switch for the import/export feature (hides both import and export). */\n allowImportExport: boolean;\n /** When false, the destructive \"Replace\" import option is hidden. */\n allowReplace: boolean;\n};\n\nexport const DEFAULT_COLLECTIONS_CONFIG: CollectionsConfig = {\n readOnly: false,\n allowImportExport: true,\n allowReplace: true,\n};\n\n/** Pluggable storage interface. Default localStorage adapter ships with the plugin. */\nexport type CollectionsStorage = {\n storageKey?: string;\n load(): Promise<Collection[]>;\n save(collections: Collection[]): Promise<void>;\n};\n\n/** An incoming item paired with the collection it should land in. */\nexport type PlacedItem = {\n item: CollectionItem;\n targetCollectionId: string;\n};\n\n/** An incoming item whose id matches a local item but whose content differs. */\nexport type ItemConflict = {\n incoming: CollectionItem;\n /** The local copy of the item before any merge. */\n current: CollectionItem;\n /** The collection where the recipient currently keeps this item (may differ from incoming parent). */\n currentCollectionId: string;\n};\n\n/** Result of `analyzeImport`. Pure — does not mutate store state. */\nexport type ImportAnalysis = {\n ok: boolean;\n /** Collection shells (no items) whose id is absent locally — to be created on apply. */\n newCollections: Collection[];\n /** Items whose id exists nowhere locally. */\n newItems: PlacedItem[];\n /** Items whose id matches a local item but content differs. */\n changedItems: ItemConflict[];\n /** Items that are byte-for-byte identical to the local copy — nothing to do. */\n unchangedCount: number;\n /** @internal Full parsed incoming list, needed for replace mode in applyImport. */\n _incoming: Collection[];\n};\n\n/**\n * How to resolve the import when applying.\n * - `replace` — wholesale overwrite (equivalent to old replace mode).\n * - `merge` with `applyChanges` — apply all or none of the changed items.\n * - `merge` with `changedItemIds` — apply only the listed subset of changed items.\n */\nexport type ImportResolution =\n | { mode: 'replace' }\n | { mode: 'merge'; applyChanges: boolean }\n | { mode: 'merge'; changedItemIds: Set<string> };\n"],"mappings":";AAkCA,IAAa,6BAAgD;CAC3D,UAAU;CACV,mBAAmB;CACnB,cAAc;AAChB"}
@@ -1,11 +1,13 @@
1
+ //#region src/utility/uuid.ts
2
+ /** Stable unique id for collections and operations. Uses `crypto.randomUUID`
3
+ * when available, falling back to a timestamp + random suffix on plain http
4
+ * where `crypto.randomUUID` is undefined. */
1
5
  function randomId() {
2
- const c = globalThis.crypto;
3
- if (c && typeof c.randomUUID === "function") {
4
- return c.randomUUID();
5
- }
6
- return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
6
+ const c = globalThis.crypto;
7
+ if (c && typeof c.randomUUID === "function") return c.randomUUID();
8
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
7
9
  }
8
- export {
9
- randomId
10
- };
11
- //# sourceMappingURL=uuid.js.map
10
+ //#endregion
11
+ export { randomId };
12
+
13
+ //# sourceMappingURL=uuid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.js","sources":["../../src/utility/uuid.ts"],"sourcesContent":["/** Stable unique id for collections and operations. Uses `crypto.randomUUID`\n * when available, falling back to a timestamp + random suffix on plain http\n * where `crypto.randomUUID` is undefined. */\nexport function randomId(): string {\n const c = globalThis.crypto;\n if (c && typeof c.randomUUID === 'function') {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"names":[],"mappings":"AAGO,SAAS,WAAmB;AACjC,QAAM,IAAI,WAAW;AACrB,MAAI,KAAK,OAAO,EAAE,eAAe,YAAY;AAC3C,WAAO,EAAE,WAAW;AAAA,EAAA;AAEtB,SAAO,GAAG,KAAK,IAAA,EAAM,SAAS,EAAE,CAAC,IAAI,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AAC9E;"}
1
+ {"version":3,"file":"uuid.js","names":[],"sources":["../../src/utility/uuid.ts"],"sourcesContent":["/** Stable unique id for collections and operations. Uses `crypto.randomUUID`\n * when available, falling back to a timestamp + random suffix on plain http\n * where `crypto.randomUUID` is undefined. */\nexport function randomId(): string {\n const c = globalThis.crypto;\n if (c && typeof c.randomUUID === 'function') {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;AAGA,SAAgB,WAAmB;CACjC,MAAM,IAAI,WAAW;CACrB,IAAI,KAAK,OAAO,EAAE,eAAe,YAC/B,OAAO,EAAE,WAAW;CAEtB,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAC7E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphiql/plugin-collections",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -31,33 +31,37 @@
31
31
  "files": [
32
32
  "dist"
33
33
  ],
34
- "scripts": {
35
- "types:check": "tsgo --noEmit",
36
- "dev": "vite build --watch --emptyOutDir=false",
37
- "build": "vite build",
38
- "test": "vitest run"
39
- },
40
34
  "dependencies": {
41
35
  "zod": "^4.0.0",
42
36
  "zustand": "^5"
43
37
  },
44
38
  "peerDependencies": {
45
- "@graphiql/react": "1.0.0-beta.1",
46
- "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
39
+ "@graphiql/react": "1.0.0-beta.2",
40
+ "graphql": "^16.11.0 || ^17.0.0",
47
41
  "react": "^18 || ^19",
48
42
  "react-dom": "^18 || ^19"
49
43
  },
50
44
  "devDependencies": {
51
- "@graphiql/react": "1.0.0-beta.1",
45
+ "@graphiql/react": "1.0.0-beta.2",
46
+ "@storybook/react-vite": "^10.3.6",
52
47
  "@testing-library/dom": "^10.4.0",
53
- "@testing-library/jest-dom": "^6.6.3",
48
+ "@testing-library/jest-dom": "^7.0.1",
54
49
  "@testing-library/react": "^16.3.0",
55
- "@vitejs/plugin-react": "^4.4.1",
56
- "graphql": "^16.9.0",
50
+ "@types/react": "^19",
51
+ "@types/react-dom": "^19",
52
+ "@typescript/native-preview": "^7.0.0-dev.20260707.2",
53
+ "@vitejs/plugin-react": "^5.2.0",
54
+ "graphql": "^16.14.2",
57
55
  "react": "^19.1.0",
58
56
  "react-dom": "^19.1.0",
59
- "vite": "^6.3.4",
57
+ "vite": "^8.2.2",
60
58
  "vite-plugin-dts": "^4.5.3",
61
59
  "vite-plugin-svgr": "^4.3.0"
60
+ },
61
+ "scripts": {
62
+ "types:check": "tsgo --noEmit",
63
+ "dev": "vite build --watch --emptyOutDir=false",
64
+ "build": "pnpm types:check && vite build",
65
+ "test": "vitest run"
62
66
  }
63
- }
67
+ }