@graphiql/plugin-collections 1.0.1 → 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.
- package/dist/components/collection-item-row.js +8 -8
- package/dist/components/collection-item-row.js.map +1 -1
- package/dist/components/collection-row.js +20 -17
- package/dist/components/collection-row.js.map +1 -1
- package/dist/components/collections-panel.js +8 -6
- package/dist/components/collections-panel.js.map +1 -1
- package/dist/components/conflict-dialog.js +1 -1
- package/dist/components/conflict-dialog.js.map +1 -1
- package/dist/components/export-dialog.js +3 -3
- package/dist/components/export-dialog.js.map +1 -1
- package/dist/components/import-dialog.js +4 -4
- package/dist/components/import-dialog.js.map +1 -1
- package/dist/components/save-dialog.js +8 -12
- package/dist/components/save-dialog.js.map +1 -1
- package/dist/components/session-actions.js +2 -2
- package/dist/components/session-actions.js.map +1 -1
- package/dist/icons/{check.svg_react.js → check.js} +1 -1
- package/dist/icons/check.js.map +1 -0
- package/dist/icons/{collections.svg_react.js → collections.js} +1 -1
- package/dist/icons/collections.js.map +1 -0
- package/dist/icons/{download.svg_react.js → download.js} +1 -1
- package/dist/icons/download.js.map +1 -0
- package/dist/icons/{upload.svg_react.js → upload.js} +1 -1
- package/dist/icons/upload.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/store.js +3 -3
- package/dist/store.js.map +1 -1
- package/dist/style.css +11 -49
- package/package.json +8 -8
- package/dist/icons/check.svg_react.js.map +0 -1
- package/dist/icons/collections.svg_react.js.map +0 -1
- package/dist/icons/download.svg_react.js.map +0 -1
- package/dist/icons/upload.svg_react.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getDocumentMethod } from "../operation-method.js";
|
|
2
|
-
import SvgUpload from "../icons/upload.svg_react.js";
|
|
3
|
-
import SvgCheck from "../icons/check.svg_react.js";
|
|
4
1
|
import { useEffect, useRef, useState } from "react";
|
|
5
|
-
import { CopyIcon, MethodPill, PenIcon, TrashIcon } from "@graphiql/react";
|
|
2
|
+
import { CopyIcon, Input, MethodPill, PenIcon, TrashIcon } from "@graphiql/react";
|
|
3
|
+
import { getDocumentMethod } from "../operation-method.js";
|
|
4
|
+
import SvgUpload from "../icons/upload.js";
|
|
5
|
+
import SvgCheck from "../icons/check.js";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// src/components/collection-item-row.tsx
|
|
8
8
|
var CollectionItemRow = ({ item, collectionId, index, readOnly = false, isGrabbed, onGrabToggle, onGrabMove, onGrabCancel, onOpen, onShare, onAnnounce, onDelete, onMove, onRenameItem }) => {
|
|
@@ -126,8 +126,8 @@ var CollectionItemRow = ({ item, collectionId, index, readOnly = false, isGrabbe
|
|
|
126
126
|
ref: editFormRef,
|
|
127
127
|
className: "graphiql-collection-item-edit-form",
|
|
128
128
|
onClick: (e) => e.stopPropagation(),
|
|
129
|
-
children: [/* @__PURE__ */ jsx(
|
|
130
|
-
|
|
129
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
130
|
+
compact: true,
|
|
131
131
|
value: editName,
|
|
132
132
|
autoFocus: true,
|
|
133
133
|
placeholder: item.name,
|
|
@@ -138,8 +138,8 @@ var CollectionItemRow = ({ item, collectionId, index, readOnly = false, isGrabbe
|
|
|
138
138
|
if (e.key === "Escape") cancelEdit();
|
|
139
139
|
e.stopPropagation();
|
|
140
140
|
}
|
|
141
|
-
}), /* @__PURE__ */ jsx(
|
|
142
|
-
|
|
141
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
142
|
+
compact: true,
|
|
143
143
|
value: editDescription,
|
|
144
144
|
placeholder: "Description (optional)",
|
|
145
145
|
onChange: (e) => setEditDescription(e.target.value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-item-row.js","names":["CheckIcon","UploadIcon"],"sources":["../../src/components/collection-item-row.tsx"],"sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport { MethodPill, PenIcon, CopyIcon, TrashIcon } from '@graphiql/react';\nimport type { CollectionItem } from '../types';\nimport { getDocumentMethod } from '../operation-method';\nimport UploadIcon from '../icons/upload.svg?react';\nimport CheckIcon from '../icons/check.svg?react';\n\ntype CollectionItemRowProps = {\n item: CollectionItem;\n collectionId: string;\n /** The item's position within its collection, used for drag reorder. */\n index: number;\n /** Hide write affordances (Move, Delete) and disable drag-reorder when true. */\n readOnly?: boolean;\n isGrabbed: boolean;\n onGrabToggle(): void;\n onGrabMove(direction: 'up' | 'down'): void;\n onGrabCancel(): void;\n onOpen(item: CollectionItem): void;\n onShare(itemId: string): Promise<void>;\n onAnnounce(message: string): void;\n onDelete(collectionId: string, itemId: string): void;\n onMove(\n fromCollectionId: string,\n fromIndex: number,\n toCollectionId: string,\n toIndex: number,\n ): void;\n onRenameItem(\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ): void;\n};\n\nexport const CollectionItemRow: FC<CollectionItemRowProps> = ({\n item,\n collectionId,\n index,\n readOnly = false,\n isGrabbed,\n onGrabToggle,\n onGrabMove,\n onGrabCancel,\n onOpen,\n onShare,\n onAnnounce,\n onDelete,\n onMove,\n onRenameItem,\n}) => {\n const [isDragOver, setIsDragOver] = useState(false);\n const [isEditing, setIsEditing] = useState(false);\n const [confirmed, setConfirmed] = useState<'copy' | 'share' | null>(null);\n const [confirmToken, setConfirmToken] = useState(0);\n const editFormRef = useRef<HTMLDivElement>(null);\n const [editName, setEditName] = useState(item.name);\n const [editDescription, setEditDescription] = useState(\n item.description ?? '',\n );\n const method = getDocumentMethod(item.query);\n\n // Action buttons stop propagation so their clicks don't also trigger the\n // row's open handler.\n const startEdit = (e: React.MouseEvent) => {\n e.stopPropagation();\n setEditName(item.name);\n setEditDescription(item.description ?? '');\n setIsEditing(true);\n };\n\n useEffect(() => {\n if (!confirmed) {\n return;\n }\n const timer = setTimeout(() => setConfirmed(null), 1500);\n return () => clearTimeout(timer);\n }, [confirmed, confirmToken]);\n\n const runAction = async (\n kind: 'copy' | 'share',\n write: () => Promise<void>,\n message: string,\n failureMessage: string,\n ) => {\n try {\n await write();\n onAnnounce(message);\n setConfirmed(kind);\n setConfirmToken(t => t + 1);\n } catch {\n onAnnounce(failureMessage);\n }\n };\n\n const handleDelete = (e: React.MouseEvent) => {\n e.stopPropagation();\n onDelete(collectionId, item.id);\n };\n\n const commitEdit = () => {\n const name = editName.trim() || item.name;\n onRenameItem(collectionId, item.id, {\n name,\n description: editDescription,\n });\n setIsEditing(false);\n };\n\n // Commit only when focus leaves the whole form; moving between the name and\n // description inputs must not tear down the edit UI mid-edit.\n const handleBlur = (e: React.FocusEvent) => {\n if (editFormRef.current?.contains(e.relatedTarget as Node | null)) {\n return;\n }\n commitEdit();\n };\n\n const cancelEdit = () => {\n setEditName(item.name);\n setEditDescription(item.description ?? '');\n setIsEditing(false);\n };\n\n return (\n <div\n className={`graphiql-collection-item-row${isDragOver ? ' graphiql-collection-drop-target' : ''}`}\n data-grabbed={isGrabbed || undefined}\n draggable={!readOnly && !isEditing}\n onDragStart={\n readOnly || isEditing\n ? undefined\n : e => {\n e.dataTransfer.setData(\n 'application/x-graphiql-item',\n JSON.stringify({ collectionId, index }),\n );\n e.dataTransfer.effectAllowed = 'move';\n }\n }\n onDragOver={\n readOnly\n ? undefined\n : e => {\n e.preventDefault();\n e.dataTransfer.dropEffect = 'move';\n setIsDragOver(true);\n }\n }\n onDragLeave={readOnly ? undefined : () => setIsDragOver(false)}\n onDrop={\n readOnly\n ? undefined\n : e => {\n e.preventDefault();\n setIsDragOver(false);\n try {\n const data = JSON.parse(\n e.dataTransfer.getData('application/x-graphiql-item'),\n );\n onMove(data.collectionId, data.index, collectionId, index);\n } catch {\n // malformed drag data\n }\n }\n }\n onClick={() => {\n if (!isEditing) {\n onOpen(item);\n }\n }}\n >\n <button\n type=\"button\"\n className=\"graphiql-collection-drag-handle\"\n data-collection-drag-handle={item.id}\n aria-label={`Reorder ${item.name}. Press space to grab, arrow keys to move, escape to cancel.`}\n aria-pressed={isGrabbed}\n disabled={readOnly}\n onClick={e => e.stopPropagation()}\n onKeyDown={e => {\n if (e.key === ' ' || e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n onGrabToggle();\n } else if (isGrabbed && e.key === 'ArrowDown') {\n e.preventDefault();\n e.stopPropagation();\n onGrabMove('down');\n } else if (isGrabbed && e.key === 'ArrowUp') {\n e.preventDefault();\n e.stopPropagation();\n onGrabMove('up');\n } else if (isGrabbed && e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n onGrabCancel();\n }\n }}\n >\n ⠿\n </button>\n {method === 'mix' ? (\n <span\n className=\"graphiql-method-pill graphiql-collection-method-pill-mix\"\n aria-hidden\n >\n MIX\n </span>\n ) : (\n <MethodPill operation={method} aria-hidden />\n )}\n {isEditing ? (\n <div\n ref={editFormRef}\n className=\"graphiql-collection-item-edit-form\"\n onClick={e => e.stopPropagation()}\n >\n <input\n className=\"graphiql-collection-item-edit-input\"\n value={editName}\n autoFocus\n placeholder={item.name}\n onChange={e => setEditName(e.target.value)}\n onBlur={handleBlur}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n commitEdit();\n }\n if (e.key === 'Escape') {\n cancelEdit();\n }\n e.stopPropagation();\n }}\n />\n <input\n className=\"graphiql-collection-item-edit-input\"\n value={editDescription}\n placeholder=\"Description (optional)\"\n onChange={e => setEditDescription(e.target.value)}\n onBlur={handleBlur}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n commitEdit();\n }\n if (e.key === 'Escape') {\n cancelEdit();\n }\n e.stopPropagation();\n }}\n />\n </div>\n ) : (\n <div className=\"graphiql-collection-item-main\">\n <span className=\"graphiql-collection-item-name\" title={item.name}>\n {item.name}\n </span>\n {item.description && (\n <span\n className=\"graphiql-collection-item-description\"\n title={item.description}\n >\n {item.description}\n </span>\n )}\n </div>\n )}\n {!isEditing && (\n <div className=\"graphiql-collection-item-actions\">\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Rename ${item.name}`}\n title=\"Rename\"\n onClick={startEdit}\n >\n <PenIcon aria-hidden=\"true\" />\n </button>\n )}\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Copy operation ${item.name}`}\n title=\"Copy operation\"\n data-confirmed={confirmed === 'copy' || undefined}\n onClick={e => {\n e.stopPropagation();\n void runAction(\n 'copy',\n () => navigator.clipboard.writeText(item.query),\n 'Copied query to clipboard.',\n 'Could not copy to clipboard.',\n );\n }}\n >\n {confirmed === 'copy' ? (\n <CheckIcon aria-hidden=\"true\" />\n ) : (\n <CopyIcon aria-hidden=\"true\" />\n )}\n </button>\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Share ${item.name} as collection`}\n title=\"Share as collection\"\n data-confirmed={confirmed === 'share' || undefined}\n onClick={e => {\n e.stopPropagation();\n void runAction(\n 'share',\n () => onShare(item.id),\n 'Shared operation to clipboard.',\n 'Could not share to clipboard.',\n );\n }}\n >\n {confirmed === 'share' ? (\n <CheckIcon aria-hidden=\"true\" />\n ) : (\n <UploadIcon aria-hidden=\"true\" />\n )}\n </button>\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Delete ${item.name}`}\n title=\"Delete\"\n onClick={handleDelete}\n >\n <TrashIcon aria-hidden=\"true\" />\n </button>\n )}\n </div>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;AAmCA,IAAa,qBAAiD,EAC5D,MACA,cACA,OACA,WAAW,OACX,WACA,cACA,YACA,cACA,QACA,SACA,YACA,UACA,QACA,mBACI;CACJ,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,WAAW,gBAAgB,SAAkC,IAAI;CACxE,MAAM,CAAC,cAAc,mBAAmB,SAAS,CAAC;CAClD,MAAM,cAAc,OAAuB,IAAI;CAC/C,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK,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,oBAAC,UAAD,EAAU,eAAY,OAAQ,CAAA;KAE1B,CAAA;KACR,oBAAC,UAAD;MACE,MAAK;MACL,WAAU;MACV,cAAY,SAAS,KAAK,KAAK;MAC/B,OAAM;MACN,kBAAgB,cAAc,WAAW,KAAA;MACzC,UAAS,MAAK;OACZ,EAAE,gBAAgB;OAClB,UACE,eACM,QAAQ,KAAK,EAAE,GACrB,kCACA,+BACF;MACF;MAEC,UAAA,cAAc,UACb,oBAACA,UAAD,EAAW,eAAY,OAAQ,CAAA,IAE/B,oBAACC,WAAD,EAAY,eAAY,OAAQ,CAAA;KAE5B,CAAA;KACP,CAAC,YACA,oBAAC,UAAD;MACE,MAAK;MACL,WAAU;MACV,cAAY,UAAU,KAAK;MAC3B,OAAM;MACN,SAAS;MAET,UAAA,oBAAC,WAAD,EAAW,eAAY,OAAQ,CAAA;KACzB,CAAA;IAEP;;EAEJ;;AAET"}
|
|
1
|
+
{"version":3,"file":"collection-item-row.js","names":["_jsxs","_jsx","CheckIcon","UploadIcon"],"sources":["../../src/components/collection-item-row.tsx"],"sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport {\n Input,\n MethodPill,\n PenIcon,\n CopyIcon,\n TrashIcon,\n} from '@graphiql/react';\nimport type { CollectionItem } from '../types';\nimport { getDocumentMethod } from '../operation-method';\nimport UploadIcon from '../icons/upload.svg?react';\nimport CheckIcon from '../icons/check.svg?react';\n\ntype CollectionItemRowProps = {\n item: CollectionItem;\n collectionId: string;\n /** The item's position within its collection, used for drag reorder. */\n index: number;\n /** Hide write affordances (Move, Delete) and disable drag-reorder when true. */\n readOnly?: boolean;\n isGrabbed: boolean;\n onGrabToggle(): void;\n onGrabMove(direction: 'up' | 'down'): void;\n onGrabCancel(): void;\n onOpen(item: CollectionItem): void;\n onShare(itemId: string): Promise<void>;\n onAnnounce(message: string): void;\n onDelete(collectionId: string, itemId: string): void;\n onMove(\n fromCollectionId: string,\n fromIndex: number,\n toCollectionId: string,\n toIndex: number,\n ): void;\n onRenameItem(\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ): void;\n};\n\nexport const CollectionItemRow: FC<CollectionItemRowProps> = ({\n item,\n collectionId,\n index,\n readOnly = false,\n isGrabbed,\n onGrabToggle,\n onGrabMove,\n onGrabCancel,\n onOpen,\n onShare,\n onAnnounce,\n onDelete,\n onMove,\n onRenameItem,\n}) => {\n const [isDragOver, setIsDragOver] = useState(false);\n const [isEditing, setIsEditing] = useState(false);\n const [confirmed, setConfirmed] = useState<'copy' | 'share' | null>(null);\n const [confirmToken, setConfirmToken] = useState(0);\n const editFormRef = useRef<HTMLDivElement>(null);\n const [editName, setEditName] = useState(item.name);\n const [editDescription, setEditDescription] = useState(\n item.description ?? '',\n );\n const method = getDocumentMethod(item.query);\n\n // Action buttons stop propagation so their clicks don't also trigger the\n // row's open handler.\n const startEdit = (e: React.MouseEvent) => {\n e.stopPropagation();\n setEditName(item.name);\n setEditDescription(item.description ?? '');\n setIsEditing(true);\n };\n\n useEffect(() => {\n if (!confirmed) {\n return;\n }\n const timer = setTimeout(() => setConfirmed(null), 1500);\n return () => clearTimeout(timer);\n }, [confirmed, confirmToken]);\n\n const runAction = async (\n kind: 'copy' | 'share',\n write: () => Promise<void>,\n message: string,\n failureMessage: string,\n ) => {\n try {\n await write();\n onAnnounce(message);\n setConfirmed(kind);\n setConfirmToken(t => t + 1);\n } catch {\n onAnnounce(failureMessage);\n }\n };\n\n const handleDelete = (e: React.MouseEvent) => {\n e.stopPropagation();\n onDelete(collectionId, item.id);\n };\n\n const commitEdit = () => {\n const name = editName.trim() || item.name;\n onRenameItem(collectionId, item.id, {\n name,\n description: editDescription,\n });\n setIsEditing(false);\n };\n\n // Commit only when focus leaves the whole form; moving between the name and\n // description inputs must not tear down the edit UI mid-edit.\n const handleBlur = (e: React.FocusEvent) => {\n if (editFormRef.current?.contains(e.relatedTarget as Node | null)) {\n return;\n }\n commitEdit();\n };\n\n const cancelEdit = () => {\n setEditName(item.name);\n setEditDescription(item.description ?? '');\n setIsEditing(false);\n };\n\n return (\n <div\n className={`graphiql-collection-item-row${isDragOver ? ' graphiql-collection-drop-target' : ''}`}\n data-grabbed={isGrabbed || undefined}\n draggable={!readOnly && !isEditing}\n onDragStart={\n readOnly || isEditing\n ? undefined\n : e => {\n e.dataTransfer.setData(\n 'application/x-graphiql-item',\n JSON.stringify({ collectionId, index }),\n );\n e.dataTransfer.effectAllowed = 'move';\n }\n }\n onDragOver={\n readOnly\n ? undefined\n : e => {\n e.preventDefault();\n e.dataTransfer.dropEffect = 'move';\n setIsDragOver(true);\n }\n }\n onDragLeave={readOnly ? undefined : () => setIsDragOver(false)}\n onDrop={\n readOnly\n ? undefined\n : e => {\n e.preventDefault();\n setIsDragOver(false);\n try {\n const data = JSON.parse(\n e.dataTransfer.getData('application/x-graphiql-item'),\n );\n onMove(data.collectionId, data.index, collectionId, index);\n } catch {\n // malformed drag data\n }\n }\n }\n onClick={() => {\n if (!isEditing) {\n onOpen(item);\n }\n }}\n >\n <button\n type=\"button\"\n className=\"graphiql-collection-drag-handle\"\n data-collection-drag-handle={item.id}\n aria-label={`Reorder ${item.name}. Press space to grab, arrow keys to move, escape to cancel.`}\n aria-pressed={isGrabbed}\n disabled={readOnly}\n onClick={e => e.stopPropagation()}\n onKeyDown={e => {\n if (e.key === ' ' || e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n onGrabToggle();\n } else if (isGrabbed && e.key === 'ArrowDown') {\n e.preventDefault();\n e.stopPropagation();\n onGrabMove('down');\n } else if (isGrabbed && e.key === 'ArrowUp') {\n e.preventDefault();\n e.stopPropagation();\n onGrabMove('up');\n } else if (isGrabbed && e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n onGrabCancel();\n }\n }}\n >\n ⠿\n </button>\n {method === 'mix' ? (\n <span\n className=\"graphiql-method-pill graphiql-collection-method-pill-mix\"\n aria-hidden\n >\n MIX\n </span>\n ) : (\n <MethodPill operation={method} aria-hidden />\n )}\n {isEditing ? (\n <div\n ref={editFormRef}\n className=\"graphiql-collection-item-edit-form\"\n onClick={e => e.stopPropagation()}\n >\n <Input\n compact\n value={editName}\n autoFocus\n placeholder={item.name}\n onChange={e => setEditName(e.target.value)}\n onBlur={handleBlur}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n commitEdit();\n }\n if (e.key === 'Escape') {\n cancelEdit();\n }\n e.stopPropagation();\n }}\n />\n <Input\n compact\n value={editDescription}\n placeholder=\"Description (optional)\"\n onChange={e => setEditDescription(e.target.value)}\n onBlur={handleBlur}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n commitEdit();\n }\n if (e.key === 'Escape') {\n cancelEdit();\n }\n e.stopPropagation();\n }}\n />\n </div>\n ) : (\n <div className=\"graphiql-collection-item-main\">\n <span className=\"graphiql-collection-item-name\" title={item.name}>\n {item.name}\n </span>\n {item.description && (\n <span\n className=\"graphiql-collection-item-description\"\n title={item.description}\n >\n {item.description}\n </span>\n )}\n </div>\n )}\n {!isEditing && (\n <div className=\"graphiql-collection-item-actions\">\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Rename ${item.name}`}\n title=\"Rename\"\n onClick={startEdit}\n >\n <PenIcon aria-hidden=\"true\" />\n </button>\n )}\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Copy operation ${item.name}`}\n title=\"Copy operation\"\n data-confirmed={confirmed === 'copy' || undefined}\n onClick={e => {\n e.stopPropagation();\n void runAction(\n 'copy',\n () => navigator.clipboard.writeText(item.query),\n 'Copied query to clipboard.',\n 'Could not copy to clipboard.',\n );\n }}\n >\n {confirmed === 'copy' ? (\n <CheckIcon aria-hidden=\"true\" />\n ) : (\n <CopyIcon aria-hidden=\"true\" />\n )}\n </button>\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Share ${item.name} as collection`}\n title=\"Share as collection\"\n data-confirmed={confirmed === 'share' || undefined}\n onClick={e => {\n e.stopPropagation();\n void runAction(\n 'share',\n () => onShare(item.id),\n 'Shared operation to clipboard.',\n 'Could not share to clipboard.',\n );\n }}\n >\n {confirmed === 'share' ? (\n <CheckIcon aria-hidden=\"true\" />\n ) : (\n <UploadIcon aria-hidden=\"true\" />\n )}\n </button>\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-item-action\"\n aria-label={`Delete ${item.name}`}\n title=\"Delete\"\n onClick={handleDelete}\n >\n <TrashIcon aria-hidden=\"true\" />\n </button>\n )}\n </div>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;AAyCA,IAAa,qBAAiD,EAC5D,MACA,cACA,OACA,WAAW,OACX,WACA,cACA,YACA,cACA,QACA,SACA,YACA,UACA,QACA,mBACI;CACJ,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,WAAW,gBAAgB,SAAkC,IAAI;CACxE,MAAM,CAAC,cAAc,mBAAmB,SAAS,CAAC;CAClD,MAAM,cAAc,OAAuB,IAAI;CAC/C,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK,IAAI;CAClD,MAAM,CAAC,iBAAiB,sBAAsB,SAC5C,KAAK,eAAe,EACtB;CACA,MAAM,SAAS,kBAAkB,KAAK,KAAK;CAI3C,MAAM,aAAa,MAAwB;EACzC,EAAE,gBAAgB;EAClB,YAAY,KAAK,IAAI;EACrB,mBAAmB,KAAK,eAAe,EAAE;EACzC,aAAa,IAAI;CACnB;CAEA,gBAAgB;EACd,IAAI,CAAC,WACH;EAEF,MAAM,QAAQ,iBAAiB,aAAa,IAAI,GAAG,IAAI;EACvD,aAAa,aAAa,KAAK;CACjC,GAAG,CAAC,WAAW,YAAY,CAAC;CAE5B,MAAM,YAAY,OAChB,MACA,OACA,SACA,mBACG;EACH,IAAI;GACF,MAAM,MAAM;GACZ,WAAW,OAAO;GAClB,aAAa,IAAI;GACjB,iBAAgB,MAAK,IAAI,CAAC;EAC5B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AW,eAAY,OAAQ,CAAA;KACzB,CAAA;IAEP;;EAEJ;;AAET"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CollectionItemRow } from "./collection-item-row.js";
|
|
2
|
-
import SvgUpload from "../icons/upload.svg_react.js";
|
|
3
|
-
import SvgCheck from "../icons/check.svg_react.js";
|
|
4
1
|
import { useEffect, useState } from "react";
|
|
5
|
-
import { PenIcon, TrashIcon } from "@graphiql/react";
|
|
2
|
+
import { Input, PenIcon, TrashIcon } from "@graphiql/react";
|
|
3
|
+
import { CollectionItemRow } from "./collection-item-row.js";
|
|
4
|
+
import SvgUpload from "../icons/upload.js";
|
|
5
|
+
import SvgCheck from "../icons/check.js";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// src/components/collection-row.tsx
|
|
8
8
|
var CollectionRow = ({ collection, expanded, onToggleExpand, readOnly = false, grabbed, onGrabToggle, onGrabMove, onGrabCancel, onRename, onDelete, onShareCollection, onOpenItem, onShare, onAnnounce, onDeleteItem, onMoveItem, onRenameItem }) => {
|
|
@@ -35,20 +35,23 @@ var CollectionRow = ({ collection, expanded, onToggleExpand, readOnly = false, g
|
|
|
35
35
|
/* @__PURE__ */ jsxs("div", {
|
|
36
36
|
className: "graphiql-collection-header",
|
|
37
37
|
children: [
|
|
38
|
-
isRenaming ? /* @__PURE__ */ jsx("
|
|
39
|
-
className: "graphiql-collection-rename-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
isRenaming ? /* @__PURE__ */ jsx("div", {
|
|
39
|
+
className: "graphiql-collection-rename-field",
|
|
40
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
41
|
+
compact: true,
|
|
42
|
+
value: renameValue,
|
|
43
|
+
autoFocus: true,
|
|
44
|
+
onChange: (e) => setRenameValue(e.target.value),
|
|
45
|
+
onBlur: commitRename,
|
|
46
|
+
onKeyDown: (e) => {
|
|
47
|
+
if (e.key === "Enter") commitRename();
|
|
48
|
+
if (e.key === "Escape") {
|
|
49
|
+
setRenameValue(collection.name);
|
|
50
|
+
setIsRenaming(false);
|
|
51
|
+
}
|
|
52
|
+
e.stopPropagation();
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
}
|
|
54
|
+
})
|
|
52
55
|
}) : /* @__PURE__ */ jsxs("button", {
|
|
53
56
|
type: "button",
|
|
54
57
|
className: "graphiql-collection-toggle",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-row.js","names":["CheckIcon","UploadIcon"],"sources":["../../src/components/collection-row.tsx"],"sourcesContent":["import { FC, useEffect, useState } from 'react';\nimport { PenIcon, TrashIcon } from '@graphiql/react';\nimport type { Collection, CollectionItem } from '../types';\nimport { CollectionItemRow } from './collection-item-row';\nimport UploadIcon from '../icons/upload.svg?react';\nimport CheckIcon from '../icons/check.svg?react';\n\ntype CollectionRowProps = {\n collection: Collection;\n expanded: boolean;\n onToggleExpand(): void;\n /** Hide write affordances (Rename, Delete, add-item) when true. */\n readOnly?: boolean;\n grabbed: { collectionId: string; index: number; itemId: string } | null;\n onGrabToggle(collectionId: string, index: number, itemId: string): void;\n onGrabMove(direction: 'up' | 'down'): void;\n onGrabCancel(): void;\n onRename(id: string, name: string): void;\n onDelete(id: string): void;\n onShareCollection(id: string): Promise<void>;\n onOpenItem(item: CollectionItem): void;\n onShare(itemId: string): Promise<void>;\n onAnnounce(message: string): void;\n onDeleteItem(collectionId: string, itemId: string): void;\n onMoveItem(\n fromCollectionId: string,\n fromIndex: number,\n toCollectionId: string,\n toIndex: number,\n ): void;\n onAddItem(\n collectionId: string,\n item: Omit<CollectionItem, 'id' | 'createdAt' | 'updatedAt'>,\n ): CollectionItem;\n onRenameItem(\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ): void;\n};\n\nexport const CollectionRow: FC<CollectionRowProps> = ({\n collection,\n expanded,\n onToggleExpand,\n readOnly = false,\n grabbed,\n onGrabToggle,\n onGrabMove,\n onGrabCancel,\n onRename,\n onDelete,\n onShareCollection,\n onOpenItem,\n onShare,\n onAnnounce,\n onDeleteItem,\n onMoveItem,\n onRenameItem,\n}) => {\n const [isRenaming, setIsRenaming] = useState(false);\n const [renameValue, setRenameValue] = useState(collection.name);\n const [confirmed, setConfirmed] = useState(false);\n const [confirmToken, setConfirmToken] = useState(0);\n\n useEffect(() => {\n if (!confirmed) {\n return;\n }\n const timer = setTimeout(() => setConfirmed(false), 1500);\n return () => clearTimeout(timer);\n }, [confirmed, confirmToken]);\n\n const runShareCollection = async () => {\n try {\n await onShareCollection(collection.id);\n onAnnounce('Shared collection to clipboard.');\n setConfirmed(true);\n setConfirmToken(t => t + 1);\n } catch {\n onAnnounce('Could not share to clipboard.');\n }\n };\n\n const commitRename = () => {\n if (renameValue.trim()) {\n onRename(collection.id, renameValue.trim());\n }\n setIsRenaming(false);\n };\n\n return (\n <div className=\"graphiql-collection-row\">\n <div className=\"graphiql-collection-header\">\n {isRenaming ? (\n <
|
|
1
|
+
{"version":3,"file":"collection-row.js","names":["_jsxs","_jsx","CheckIcon","UploadIcon"],"sources":["../../src/components/collection-row.tsx"],"sourcesContent":["import { FC, useEffect, useState } from 'react';\nimport { Input, PenIcon, TrashIcon } from '@graphiql/react';\nimport type { Collection, CollectionItem } from '../types';\nimport { CollectionItemRow } from './collection-item-row';\nimport UploadIcon from '../icons/upload.svg?react';\nimport CheckIcon from '../icons/check.svg?react';\n\ntype CollectionRowProps = {\n collection: Collection;\n expanded: boolean;\n onToggleExpand(): void;\n /** Hide write affordances (Rename, Delete, add-item) when true. */\n readOnly?: boolean;\n grabbed: { collectionId: string; index: number; itemId: string } | null;\n onGrabToggle(collectionId: string, index: number, itemId: string): void;\n onGrabMove(direction: 'up' | 'down'): void;\n onGrabCancel(): void;\n onRename(id: string, name: string): void;\n onDelete(id: string): void;\n onShareCollection(id: string): Promise<void>;\n onOpenItem(item: CollectionItem): void;\n onShare(itemId: string): Promise<void>;\n onAnnounce(message: string): void;\n onDeleteItem(collectionId: string, itemId: string): void;\n onMoveItem(\n fromCollectionId: string,\n fromIndex: number,\n toCollectionId: string,\n toIndex: number,\n ): void;\n onAddItem(\n collectionId: string,\n item: Omit<CollectionItem, 'id' | 'createdAt' | 'updatedAt'>,\n ): CollectionItem;\n onRenameItem(\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ): void;\n};\n\nexport const CollectionRow: FC<CollectionRowProps> = ({\n collection,\n expanded,\n onToggleExpand,\n readOnly = false,\n grabbed,\n onGrabToggle,\n onGrabMove,\n onGrabCancel,\n onRename,\n onDelete,\n onShareCollection,\n onOpenItem,\n onShare,\n onAnnounce,\n onDeleteItem,\n onMoveItem,\n onRenameItem,\n}) => {\n const [isRenaming, setIsRenaming] = useState(false);\n const [renameValue, setRenameValue] = useState(collection.name);\n const [confirmed, setConfirmed] = useState(false);\n const [confirmToken, setConfirmToken] = useState(0);\n\n useEffect(() => {\n if (!confirmed) {\n return;\n }\n const timer = setTimeout(() => setConfirmed(false), 1500);\n return () => clearTimeout(timer);\n }, [confirmed, confirmToken]);\n\n const runShareCollection = async () => {\n try {\n await onShareCollection(collection.id);\n onAnnounce('Shared collection to clipboard.');\n setConfirmed(true);\n setConfirmToken(t => t + 1);\n } catch {\n onAnnounce('Could not share to clipboard.');\n }\n };\n\n const commitRename = () => {\n if (renameValue.trim()) {\n onRename(collection.id, renameValue.trim());\n }\n setIsRenaming(false);\n };\n\n return (\n <div className=\"graphiql-collection-row\">\n <div className=\"graphiql-collection-header\">\n {isRenaming ? (\n <div className=\"graphiql-collection-rename-field\">\n <Input\n compact\n value={renameValue}\n autoFocus\n onChange={e => setRenameValue(e.target.value)}\n onBlur={commitRename}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n commitRename();\n }\n if (e.key === 'Escape') {\n setRenameValue(collection.name);\n setIsRenaming(false);\n }\n e.stopPropagation();\n }}\n />\n </div>\n ) : (\n <button\n type=\"button\"\n className=\"graphiql-collection-toggle\"\n aria-expanded={expanded}\n aria-label={`Toggle ${collection.name}`}\n onClick={onToggleExpand}\n >\n <span className=\"graphiql-collection-chevron\" aria-hidden=\"true\">\n {expanded ? '▾' : '▸'}\n </span>\n <span className=\"graphiql-collection-name\">{collection.name}</span>\n </button>\n )}\n <span className=\"graphiql-collection-badge\">\n {collection.items.length}\n </span>\n <div className=\"graphiql-collection-header-actions\">\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-header-action\"\n aria-label={`Rename ${collection.name}`}\n title=\"Rename\"\n onClick={e => {\n e.stopPropagation();\n setRenameValue(collection.name);\n setIsRenaming(true);\n }}\n >\n <PenIcon aria-hidden=\"true\" />\n </button>\n )}\n <button\n type=\"button\"\n className=\"graphiql-collection-header-action\"\n aria-label={`Share ${collection.name}`}\n title=\"Share collection\"\n data-confirmed={confirmed || undefined}\n onClick={e => {\n e.stopPropagation();\n void runShareCollection();\n }}\n >\n {confirmed ? (\n <CheckIcon aria-hidden=\"true\" />\n ) : (\n <UploadIcon aria-hidden=\"true\" />\n )}\n </button>\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collection-header-action\"\n aria-label={`Delete ${collection.name}`}\n title=\"Delete\"\n onClick={e => {\n e.stopPropagation();\n onDelete(collection.id);\n }}\n >\n <TrashIcon aria-hidden=\"true\" />\n </button>\n )}\n </div>\n </div>\n {expanded && collection.items.length > 0 && (\n <div className=\"graphiql-collection-items\">\n {collection.items.map((item, i) => (\n <CollectionItemRow\n key={item.id}\n item={item}\n collectionId={collection.id}\n index={i}\n readOnly={readOnly}\n isGrabbed={\n grabbed?.collectionId === collection.id && grabbed.index === i\n }\n onGrabToggle={() => onGrabToggle(collection.id, i, item.id)}\n onGrabMove={onGrabMove}\n onGrabCancel={onGrabCancel}\n onOpen={onOpenItem}\n onShare={onShare}\n onAnnounce={onAnnounce}\n onDelete={onDeleteItem}\n onMove={onMoveItem}\n onRenameItem={onRenameItem}\n />\n ))}\n </div>\n )}\n {expanded && collection.items.length === 0 && (\n <div className=\"graphiql-collection-empty-hint\">\n {readOnly\n ? 'No operations here yet.'\n : 'No operations here yet. Save a query to add it to this collection.'}\n </div>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;AAyCA,IAAa,iBAAyC,EACpD,YACA,UACA,gBACA,WAAW,OACX,SACA,cACA,YACA,cACA,UACA,UACA,mBACA,YACA,SACA,YACA,cACA,YACA,mBACI;CACJ,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,aAAa,kBAAkB,SAAS,WAAW,IAAI;CAC9D,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,cAAc,mBAAmB,SAAS,CAAC;CAElD,gBAAgB;EACd,IAAI,CAAC,WACH;EAEF,MAAM,QAAQ,iBAAiB,aAAa,KAAK,GAAG,IAAI;EACxD,aAAa,aAAa,KAAK;CACjC,GAAG,CAAC,WAAW,YAAY,CAAC;CAE5B,MAAM,qBAAqB,YAAY;EACrC,IAAI;GACF,MAAM,kBAAkB,WAAW,EAAE;GACrC,WAAW,iCAAiC;GAC5C,aAAa,IAAI;GACjB,iBAAgB,MAAK,IAAI,CAAC;EAC5B,QAAQ;GACN,WAAW,+BAA+B;EAC5C;CACF;CAEA,MAAM,qBAAqB;EACzB,IAAI,YAAY,KAAK,GACnB,SAAS,WAAW,IAAI,YAAY,KAAK,CAAC;EAE5C,cAAc,KAAK;CACrB;CAEA,OACEA,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACEA,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA;KACG,aACCC,oBAAC,OAAD;MAAK,WAAU;MACb,UAAAA,oBAAC,OAAD;OACE,SAAA;OACA,OAAO;OACP,WAAA;OACA,WAAU,MAAK,eAAe,EAAE,OAAO,KAAK;OAC5C,QAAQ;OACR,YAAW,MAAK;QACd,IAAI,EAAE,QAAQ,SACZ,aAAa;QAEf,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,YAAY,WAAW,MAAM,SAAS,KACrCA,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA,WAAW,MAAM,KAAK,MAAM,MAC3BA,oBAAC,mBAAD;KAEQ;KACN,cAAc,WAAW;KACzB,OAAO;KACG;KACV,WACE,SAAS,iBAAiB,WAAW,MAAM,QAAQ,UAAU;KAE/D,oBAAoB,aAAa,WAAW,IAAI,GAAG,KAAK,EAAE;KAC9C;KACE;KACd,QAAQ;KACC;KACG;KACZ,UAAU;KACV,QAAQ;KACM;IACf,GAjBM,KAAK,EAiBX,CACF;GACE,CAAA;GAEN,YAAY,WAAW,MAAM,WAAW,KACvCA,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA,WACG,4BACA;GACD,CAAA;EAEJ;;AAET"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Button, Dialog, PanelHeader, pick, useGraphiQL, useGraphiQLActions } from "@graphiql/react";
|
|
1
3
|
import { collectionsStore, useCollectionsStore } from "../store.js";
|
|
2
4
|
import { CollectionRow } from "./collection-row.js";
|
|
3
5
|
import { ImportDialog } from "./import-dialog.js";
|
|
4
6
|
import { ExportDialog } from "./export-dialog.js";
|
|
5
7
|
import { ConflictDialog } from "./conflict-dialog.js";
|
|
6
|
-
import SvgDownload from "../icons/download.
|
|
7
|
-
import SvgUpload from "../icons/upload.
|
|
8
|
-
import { useEffect, useRef, useState } from "react";
|
|
9
|
-
import { Button, Dialog, PanelHeader, pick, useGraphiQL, useGraphiQLActions } from "@graphiql/react";
|
|
8
|
+
import SvgDownload from "../icons/download.js";
|
|
9
|
+
import SvgUpload from "../icons/upload.js";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
// src/components/collections-panel.tsx
|
|
12
12
|
/**
|
|
@@ -108,7 +108,9 @@ var CollectionsPanel = ({ readOnly = false, allowImportExport = true, allowRepla
|
|
|
108
108
|
runImport(text, "merge");
|
|
109
109
|
};
|
|
110
110
|
const allowImportRef = useRef(allowImport);
|
|
111
|
-
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
allowImportRef.current = allowImport;
|
|
113
|
+
}, [allowImport]);
|
|
112
114
|
useEffect(() => {
|
|
113
115
|
const onPaste = (event) => {
|
|
114
116
|
if (!allowImportRef.current) return;
|
|
@@ -273,7 +275,7 @@ var CollectionsPanel = ({ readOnly = false, allowImportExport = true, allowRepla
|
|
|
273
275
|
}
|
|
274
276
|
}, [grabbed]);
|
|
275
277
|
return /* @__PURE__ */ jsxs("div", {
|
|
276
|
-
className: `graphiql-collections-panel${isDragOver ? " graphiql-collections-drop-active" : ""}`,
|
|
278
|
+
className: `graphiql-collections-panel graphiql-side-panel-content${isDragOver ? " graphiql-collections-drop-active" : ""}`,
|
|
277
279
|
onDragOver: (e) => {
|
|
278
280
|
if (!allowImport || !e.dataTransfer.types.includes("Files")) return;
|
|
279
281
|
e.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections-panel.js","names":["DownloadIcon","UploadIcon"],"sources":["../../src/components/collections-panel.tsx"],"sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport {\n Button,\n Dialog,\n PanelHeader,\n pick,\n useGraphiQL,\n useGraphiQLActions,\n} from '@graphiql/react';\nimport { useCollectionsStore, collectionsStore } from '../store';\nimport { CollectionRow } from './collection-row';\nimport { ImportDialog } from './import-dialog';\nimport { ExportDialog } from './export-dialog';\nimport { ConflictDialog } from './conflict-dialog';\nimport DownloadIcon from '../icons/download.svg?react';\nimport UploadIcon from '../icons/upload.svg?react';\nimport type {\n CollectionItem,\n ImportAnalysis,\n ImportResolution,\n} from '../types';\n\ntype CollectionsPanelProps = {\n /** Capability flags; all default on. See `CollectionsConfig`. */\n readOnly?: boolean;\n allowImportExport?: boolean;\n allowReplace?: boolean;\n};\n\n/**\n * Returns how many collections `text` holds if it is a valid collections\n * export, otherwise `null`. Used to guard paste/drop so non-collections content\n * is ignored rather than mangled.\n */\nfunction parseCollectionsExport(text: string): number | null {\n try {\n const parsed = JSON.parse(text);\n const list = Array.isArray(parsed?.collections)\n ? parsed.collections\n : Array.isArray(parsed)\n ? parsed\n : null;\n if (\n !list?.length ||\n !list.every(\n (c: unknown) =>\n c &&\n typeof c === 'object' &&\n Array.isArray((c as { items?: unknown }).items),\n )\n ) {\n return null;\n }\n return list.length;\n } catch {\n return null;\n }\n}\n\nfunction isEditableTarget(el: Element | null): boolean {\n if (!el) {\n return false;\n }\n return (\n el.tagName === 'INPUT' ||\n el.tagName === 'TEXTAREA' ||\n (el as HTMLElement).isContentEditable ||\n Boolean(el.closest('.monaco-editor'))\n );\n}\n\n/** Derive a human-readable label from the parsed incoming collections. */\nfunction deriveSourceLabel(incoming: ImportAnalysis['_incoming']): string {\n if (incoming.length === 1 && incoming[0]) {\n return incoming[0].name;\n }\n return `${incoming.length} collections`;\n}\n\nexport const CollectionsPanel: FC<CollectionsPanelProps> = ({\n readOnly = false,\n allowImportExport = true,\n allowReplace = true,\n}) => {\n // Importing is a write; it's available only when both writes and the\n // import/export feature are enabled.\n const allowImport = !readOnly && allowImportExport;\n const actions = useCollectionsStore(s => s.actions);\n const collections = useCollectionsStore(s => s.collections);\n const loaded = useCollectionsStore(s => s.loaded);\n const [openDialog, setOpenDialog] = useState<'import' | 'export' | null>(\n null,\n );\n const [isDragOver, setIsDragOver] = useState(false);\n const [status, setStatus] = useState<{ ok: boolean; message: string } | null>(\n null,\n );\n const [pendingConflict, setPendingConflict] = useState<{\n analysis: ImportAnalysis;\n sourceLabel: string;\n } | null>(null);\n // Text awaiting replace confirmation (destructive, so we prompt before applying).\n const [pendingReplace, setPendingReplace] = useState<string | null>(null);\n\n // Expand/collapse state (collapsed collection ids).\n const [collapsed, setCollapsed] = useState<Set<string>>(new Set());\n const [grabbed, setGrabbed] = useState<{\n collectionId: string;\n index: number;\n itemId: string;\n } | null>(null);\n const [origin, setOrigin] = useState<{\n collectionId: string;\n index: number;\n } | null>(null);\n const [liveMessage, setLiveMessage] = useState('');\n const listRef = useRef<HTMLDivElement>(null);\n const cancelledItemRef = useRef<string | null>(null);\n\n // Clear the import feedback after a few seconds.\n useEffect(() => {\n if (!status) {\n return;\n }\n const timer = setTimeout(() => setStatus(null), 4000);\n return () => clearTimeout(timer);\n }, [status]);\n\n const applyReplace = (text: string) => {\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n collectionsStore\n .getState()\n .actions.applyImport(analysis, { mode: 'replace' });\n };\n\n const runImport = (text: string, mode: 'merge' | 'replace') => {\n if (mode === 'replace') {\n setPendingReplace(text);\n return;\n }\n\n // merge path\n const count = parseCollectionsExport(text);\n if (count === null) {\n setStatus({\n ok: false,\n message: \"That file isn't a collections export.\",\n });\n return;\n }\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n if (!analysis.ok) {\n setStatus({ ok: false, message: 'Invalid collections export.' });\n return;\n }\n if (analysis.changedItems.length === 0) {\n // No conflicts — apply immediately.\n collectionsStore\n .getState()\n .actions.applyImport(analysis, { mode: 'merge', applyChanges: true });\n return;\n }\n // Conflicts present — open the dialog.\n setPendingConflict({\n analysis,\n sourceLabel: deriveSourceLabel(analysis._incoming),\n });\n };\n\n const handleConflictResolve = (resolution: ImportResolution) => {\n if (!pendingConflict) {\n return;\n }\n const { analysis } = pendingConflict;\n collectionsStore.getState().actions.applyImport(analysis, resolution);\n setPendingConflict(null);\n };\n\n const importDroppedFile = async (file: File) => {\n const text = await file.text();\n if (parseCollectionsExport(text) === null) {\n setStatus({\n ok: false,\n message: \"That file isn't a collections export.\",\n });\n return;\n }\n runImport(text, 'merge');\n };\n\n // Keep a live ref so the once-bound paste listener honors current config.\n const allowImportRef = useRef(allowImport);\n allowImportRef.current = allowImport;\n\n // Paste a collections export anywhere in the open panel to merge it in.\n // Guarded so it never hijacks a normal paste: ignored while typing in an\n // editor/input, ignored unless the clipboard parses as an export, and\n // ignored entirely when importing is disabled.\n useEffect(() => {\n const onPaste = (event: ClipboardEvent) => {\n if (!allowImportRef.current) {\n return;\n }\n if (isEditableTarget(document.activeElement)) {\n return;\n }\n const text = event.clipboardData?.getData('text') ?? '';\n if (parseCollectionsExport(text) === null) {\n return;\n }\n event.preventDefault();\n runImport(text, 'merge');\n };\n document.addEventListener('paste', onPaste);\n return () => document.removeEventListener('paste', onPaste);\n // bound once: only stable refs (store, setStatus) are used\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const { addTab, changeTab, updateActiveTabValues } = useGraphiQLActions();\n const { queryEditor, variableEditor, headerEditor } = useGraphiQL(\n pick('queryEditor', 'variableEditor', 'headerEditor'),\n );\n const tabs = useGraphiQL(s => s.tabs);\n const activeTabId = useGraphiQL(s => s.tabs[s.activeTabIndex]?.id);\n\n // Opening an item creates a tab, then links it once the new tab is active so\n // ⌘S updates the saved item in place rather than reopening the dialog.\n const pendingLink = useRef<{ collectionId: string; itemId: string } | null>(\n null,\n );\n useEffect(() => {\n const link = pendingLink.current;\n if (link && activeTabId) {\n actions.linkTab(activeTabId, link.collectionId, link.itemId);\n pendingLink.current = null;\n }\n }, [activeTabId, actions]);\n\n const handleOpen = (item: CollectionItem) => {\n // A saved operation is married to its tab. If that tab is still open, just\n // focus it rather than opening a duplicate — and leave its contents alone so\n // any in-progress edits survive. Links persist across reloads, so this holds\n // after a page refresh too.\n const { links } = collectionsStore.getState();\n const openIndex = tabs.findIndex(\n t => t.id && links[t.id]?.itemId === item.id,\n );\n if (openIndex !== -1) {\n changeTab(openIndex);\n return;\n }\n\n const collectionId = collections.find(c =>\n c.items.some(i => i.id === item.id),\n )?.id;\n if (collectionId) {\n pendingLink.current = { collectionId, itemId: item.id };\n }\n addTab();\n // `addTab` resets the editors to the new empty tab, so populate them with\n // the saved operation. The editors' change handlers sync this back to tab\n // state; `updateActiveTabValues` covers the case where an editor isn't\n // mounted yet. Seed `lastSavedQuery` too so the freshly opened tab matches\n // its saved item and doesn't show as dirty.\n queryEditor?.setValue(item.query ?? '');\n variableEditor?.setValue(item.variables ?? '');\n headerEditor?.setValue(item.headers ?? '');\n updateActiveTabValues({\n query: item.query,\n variables: item.variables ?? '',\n headers: item.headers ?? '',\n lastSavedQuery: item.query ?? null,\n });\n };\n\n const announce = (message: string) => setLiveMessage(message);\n\n const handleShareCollection = async (collectionId: string) => {\n const json = collectionsStore\n .getState()\n .actions.exportCollection(collectionId);\n await navigator.clipboard.writeText(json);\n };\n\n const handleShareItem = async (itemId: string) => {\n const json = collectionsStore.getState().actions.exportItem(itemId);\n await navigator.clipboard.writeText(json);\n };\n\n const handleRename = actions.renameCollection;\n const handleDelete = actions.deleteCollection;\n const handleDeleteItem = actions.deleteItem;\n const handleMoveItem = actions.moveItem;\n const handleAddItem = actions.addItem;\n const handleRenameItem = (\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ) => {\n collectionsStore.getState().actions.updateItem(collectionId, itemId, {\n name: updates.name,\n description: updates.description || undefined,\n });\n };\n\n const toggleExpand = (id: string) =>\n setCollapsed(prev => {\n const next = new Set(prev);\n if (next.has(id)) {\n next.delete(id);\n } else {\n next.add(id);\n }\n return next;\n });\n\n const expand = (id: string) =>\n setCollapsed(prev => {\n if (!prev.has(id)) {\n return prev;\n }\n const next = new Set(prev);\n next.delete(id);\n return next;\n });\n\n const handleGrabToggle = (\n collectionId: string,\n index: number,\n itemId: string,\n ) => {\n if (grabbed) {\n const cols = collectionsStore.getState().collections;\n const col = cols.find(c => c.id === grabbed.collectionId);\n const droppedItem = col?.items[grabbed.index];\n setLiveMessage(\n `Dropped ${droppedItem?.name ?? grabbed.itemId} in ${col?.name ?? ''} at position ${grabbed.index + 1}.`,\n );\n setGrabbed(null);\n setOrigin(null);\n return;\n }\n setGrabbed({ collectionId, index, itemId });\n setOrigin({ collectionId, index });\n const item = collectionsStore\n .getState()\n .collections.find(c => c.id === collectionId)?.items[index];\n setLiveMessage(\n `Grabbed ${item?.name ?? itemId}. Use arrow keys to move, space to drop, escape to cancel.`,\n );\n };\n\n const handleGrabMove = (direction: 'up' | 'down') => {\n if (!grabbed) {\n return;\n }\n const cols = collectionsStore.getState().collections;\n const cIdx = cols.findIndex(c => c.id === grabbed.collectionId);\n const col = cols[cIdx];\n if (!col) {\n return;\n }\n const { moveItem } = collectionsStore.getState().actions;\n\n if (direction === 'down') {\n if (grabbed.index < col.items.length - 1) {\n moveItem(col.id, grabbed.index, col.id, grabbed.index + 1);\n const next = { ...grabbed, index: grabbed.index + 1 };\n setGrabbed(next);\n setLiveMessage(\n `Position ${next.index + 1} of ${col.items.length} in ${col.name}.`,\n );\n } else if (cIdx < cols.length - 1) {\n const dest = cols[cIdx + 1]!;\n expand(dest.id);\n moveItem(col.id, grabbed.index, dest.id, 0);\n setGrabbed({ collectionId: dest.id, index: 0, itemId: grabbed.itemId });\n setLiveMessage(\n `Moved to ${dest.name}, position 1 of ${dest.items.length + 1}.`,\n );\n } else {\n setLiveMessage('Already at the end.');\n }\n } else if (grabbed.index > 0) {\n moveItem(col.id, grabbed.index, col.id, grabbed.index - 1);\n const next = { ...grabbed, index: grabbed.index - 1 };\n setGrabbed(next);\n setLiveMessage(\n `Position ${next.index + 1} of ${col.items.length} in ${col.name}.`,\n );\n } else if (cIdx > 0) {\n const dest = cols[cIdx - 1]!;\n expand(dest.id);\n const toIndex = dest.items.length;\n moveItem(col.id, grabbed.index, dest.id, toIndex);\n setGrabbed({\n collectionId: dest.id,\n index: toIndex,\n itemId: grabbed.itemId,\n });\n setLiveMessage(\n `Moved to ${dest.name}, position ${toIndex + 1} of ${dest.items.length + 1}.`,\n );\n } else {\n setLiveMessage('Already at the start.');\n }\n };\n\n const handleGrabCancel = () => {\n if (!grabbed || !origin) {\n return;\n }\n collectionsStore\n .getState()\n .actions.moveItem(\n grabbed.collectionId,\n grabbed.index,\n origin.collectionId,\n origin.index,\n );\n cancelledItemRef.current = grabbed.itemId;\n setGrabbed(null);\n setOrigin(null);\n setLiveMessage('Move cancelled.');\n };\n\n useEffect(() => {\n if (grabbed) {\n listRef.current\n ?.querySelector<HTMLElement>(\n `[data-collection-drag-handle=\"${grabbed.itemId}\"]`,\n )\n ?.focus();\n } else if (cancelledItemRef.current) {\n listRef.current\n ?.querySelector<HTMLElement>(\n `[data-collection-drag-handle=\"${cancelledItemRef.current}\"]`,\n )\n ?.focus();\n cancelledItemRef.current = null;\n }\n }, [grabbed]);\n\n return (\n <div\n className={`graphiql-collections-panel${isDragOver ? ' graphiql-collections-drop-active' : ''}`}\n onDragOver={e => {\n if (!allowImport || !e.dataTransfer.types.includes('Files')) {\n return;\n }\n e.preventDefault();\n setIsDragOver(true);\n }}\n onDragLeave={e => {\n if (e.currentTarget.contains(e.relatedTarget as Node | null)) {\n return;\n }\n setIsDragOver(false);\n }}\n onDrop={e => {\n if (!allowImport) {\n return;\n }\n const file = e.dataTransfer.files[0];\n if (!file) {\n return; // not a file drop (e.g. an item being reordered)\n }\n e.preventDefault();\n setIsDragOver(false);\n void importDroppedFile(file);\n }}\n >\n <PanelHeader\n title=\"Operation Collections\"\n subtitle=\"Save and organize operations into collections.\"\n />\n {(!readOnly || allowImportExport) && (\n <div className=\"graphiql-collections-toolbar\">\n <div className=\"graphiql-collections-toolbar-left\">\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() =>\n collectionsStore\n .getState()\n .actions.createCollection('New Collection')\n }\n aria-label=\"New collection\"\n title=\"New collection\"\n >\n + New Collection\n </button>\n )}\n </div>\n <div className=\"graphiql-collections-toolbar-right\">\n {allowImport && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() => setOpenDialog('import')}\n aria-label=\"Import collections\"\n title=\"Import collections\"\n >\n <DownloadIcon />\n </button>\n )}\n {allowImportExport && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() => setOpenDialog('export')}\n aria-label=\"Export collections\"\n title=\"Export collections\"\n >\n <UploadIcon />\n </button>\n )}\n </div>\n </div>\n )}\n {status && (\n <div\n className={`graphiql-collections-status${status.ok ? '' : ' graphiql-collections-status-error'}`}\n role=\"status\"\n >\n {status.message}\n </div>\n )}\n {!loaded && <div className=\"graphiql-collections-loading\">Loading…</div>}\n {loaded && collections.length === 0 && (\n <div className=\"graphiql-collections-empty\">\n {readOnly\n ? 'No collections.'\n : allowImport\n ? 'No collections yet. Save an operation to get started, or drop or paste a collections export to import one.'\n : 'No collections yet. Save an operation to get started.'}\n </div>\n )}\n <div\n className=\"graphiql-sr-only\"\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n >\n {liveMessage}\n </div>\n <div className=\"graphiql-collections-list\" ref={listRef}>\n {collections.map(collection => (\n <CollectionRow\n key={collection.id}\n collection={collection}\n readOnly={readOnly}\n expanded={!collapsed.has(collection.id)}\n onToggleExpand={() => toggleExpand(collection.id)}\n grabbed={grabbed}\n onGrabToggle={handleGrabToggle}\n onGrabMove={handleGrabMove}\n onGrabCancel={handleGrabCancel}\n onRename={handleRename}\n onDelete={handleDelete}\n onShareCollection={handleShareCollection}\n onOpenItem={handleOpen}\n onShare={handleShareItem}\n onAnnounce={announce}\n onDeleteItem={handleDeleteItem}\n onMoveItem={handleMoveItem}\n onAddItem={handleAddItem}\n onRenameItem={handleRenameItem}\n />\n ))}\n </div>\n {allowImportExport && (\n <ExportDialog\n open={openDialog === 'export'}\n onClose={() => setOpenDialog(null)}\n />\n )}\n {allowImport && (\n <ImportDialog\n open={openDialog === 'import'}\n onClose={() => setOpenDialog(null)}\n onImport={runImport}\n allowReplace={allowReplace}\n />\n )}\n {pendingConflict && (\n <ConflictDialog\n analysis={pendingConflict.analysis}\n sourceLabel={pendingConflict.sourceLabel}\n open\n onClose={() => setPendingConflict(null)}\n onResolve={handleConflictResolve}\n />\n )}\n <Dialog\n open={pendingReplace !== null}\n onOpenChange={o => !o && setPendingReplace(null)}\n >\n <Dialog.Header>Replace all collections?</Dialog.Header>\n <Dialog.Body>\n <Dialog.Description className=\"graphiql-conflict-summary\">\n This will remove all existing collections and replace them with the\n imported data. This cannot be undone.\n </Dialog.Description>\n <div className=\"graphiql-conflict-actions\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() => {\n const text = pendingReplace;\n setPendingReplace(null);\n if (text !== null) {\n applyReplace(text);\n }\n }}\n >\n Replace\n </Button>\n <Button type=\"button\" onClick={() => setPendingReplace(null)}>\n Cancel\n </Button>\n </div>\n </Dialog.Body>\n </Dialog>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAS,uBAAuB,MAA6B;CAC3D,IAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,MAAM,OAAO,MAAM,QAAQ,QAAQ,WAAW,IAC1C,OAAO,cACP,MAAM,QAAQ,MAAM,IAClB,SACA;EACN,IACE,CAAC,MAAM,UACP,CAAC,KAAK,OACH,MACC,KACA,OAAO,MAAM,YACb,MAAM,QAAS,EAA0B,KAAK,CAClD,GAEA,OAAO;EAET,OAAO,KAAK;CACd,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB,IAA6B;CACrD,IAAI,CAAC,IACH,OAAO;CAET,OACE,GAAG,YAAY,WACf,GAAG,YAAY,cACd,GAAmB,qBACpB,QAAQ,GAAG,QAAQ,gBAAgB,CAAC;AAExC;;AAGA,SAAS,kBAAkB,UAA+C;CACxE,IAAI,SAAS,WAAW,KAAK,SAAS,IACpC,OAAO,SAAS,EAAE,CAAC;CAErB,OAAO,GAAG,SAAS,OAAO;AAC5B;AAEA,IAAa,oBAA+C,EAC1D,WAAW,OACX,oBAAoB,MACpB,eAAe,WACX;CAGJ,MAAM,cAAc,CAAC,YAAY;CACjC,MAAM,UAAU,qBAAoB,MAAK,EAAE,OAAO;CAClD,MAAM,cAAc,qBAAoB,MAAK,EAAE,WAAW;CAC1D,MAAM,SAAS,qBAAoB,MAAK,EAAE,MAAM;CAChD,MAAM,CAAC,YAAY,iBAAiB,SAClC,IACF;CACA,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,QAAQ,aA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CAAA;GAEH,qBAAC,QAAD;IACE,MAAM,mBAAmB;IACzB,eAAc,MAAK,CAAC,KAAK,kBAAkB,IAAI;IAFjD,UAAA,CAIE,oBAAC,OAAO,QAAR,EAAA,UAAe,2BAAuC,CAAA,GACtD,qBAAC,OAAO,MAAR,EAAA,UAAA,CACE,oBAAC,OAAO,aAAR;KAAoB,WAAU;KAA4B,UAAA;IAGtC,CAAA,GACpB,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,oBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,eAAe;OACb,MAAM,OAAO;OACb,kBAAkB,IAAI;OACtB,IAAI,SAAS,MACX,aAAa,IAAI;MAErB;MACD,UAAA;KAEO,CAAA,GACR,oBAAC,QAAD;MAAQ,MAAK;MAAS,eAAe,kBAAkB,IAAI;MAAG,UAAA;KAEtD,CAAA,CACL;IACM,CAAA,CAAA,EAAA,CAAA,CACP;;EACL;;AAET"}
|
|
1
|
+
{"version":3,"file":"collections-panel.js","names":["_jsxs","_jsx","DownloadIcon","UploadIcon"],"sources":["../../src/components/collections-panel.tsx"],"sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport {\n Button,\n Dialog,\n PanelHeader,\n pick,\n useGraphiQL,\n useGraphiQLActions,\n} from '@graphiql/react';\nimport { useCollectionsStore, collectionsStore } from '../store';\nimport { CollectionRow } from './collection-row';\nimport { ImportDialog } from './import-dialog';\nimport { ExportDialog } from './export-dialog';\nimport { ConflictDialog } from './conflict-dialog';\nimport DownloadIcon from '../icons/download.svg?react';\nimport UploadIcon from '../icons/upload.svg?react';\nimport type {\n CollectionItem,\n ImportAnalysis,\n ImportResolution,\n} from '../types';\n\ntype CollectionsPanelProps = {\n /** Capability flags; all default on. See `CollectionsConfig`. */\n readOnly?: boolean;\n allowImportExport?: boolean;\n allowReplace?: boolean;\n};\n\n/**\n * Returns how many collections `text` holds if it is a valid collections\n * export, otherwise `null`. Used to guard paste/drop so non-collections content\n * is ignored rather than mangled.\n */\nfunction parseCollectionsExport(text: string): number | null {\n try {\n const parsed = JSON.parse(text);\n const list = Array.isArray(parsed?.collections)\n ? parsed.collections\n : Array.isArray(parsed)\n ? parsed\n : null;\n if (\n !list?.length ||\n !list.every(\n (c: unknown) =>\n c &&\n typeof c === 'object' &&\n Array.isArray((c as { items?: unknown }).items),\n )\n ) {\n return null;\n }\n return list.length;\n } catch {\n return null;\n }\n}\n\nfunction isEditableTarget(el: Element | null): boolean {\n if (!el) {\n return false;\n }\n return (\n el.tagName === 'INPUT' ||\n el.tagName === 'TEXTAREA' ||\n (el as HTMLElement).isContentEditable ||\n Boolean(el.closest('.monaco-editor'))\n );\n}\n\n/** Derive a human-readable label from the parsed incoming collections. */\nfunction deriveSourceLabel(incoming: ImportAnalysis['_incoming']): string {\n if (incoming.length === 1 && incoming[0]) {\n return incoming[0].name;\n }\n return `${incoming.length} collections`;\n}\n\nexport const CollectionsPanel: FC<CollectionsPanelProps> = ({\n readOnly = false,\n allowImportExport = true,\n allowReplace = true,\n}) => {\n // Importing is a write; it's available only when both writes and the\n // import/export feature are enabled.\n const allowImport = !readOnly && allowImportExport;\n const actions = useCollectionsStore(s => s.actions);\n const collections = useCollectionsStore(s => s.collections);\n const loaded = useCollectionsStore(s => s.loaded);\n const [openDialog, setOpenDialog] = useState<'import' | 'export' | null>(\n null,\n );\n const [isDragOver, setIsDragOver] = useState(false);\n const [status, setStatus] = useState<{ ok: boolean; message: string } | null>(\n null,\n );\n const [pendingConflict, setPendingConflict] = useState<{\n analysis: ImportAnalysis;\n sourceLabel: string;\n } | null>(null);\n // Text awaiting replace confirmation (destructive, so we prompt before applying).\n const [pendingReplace, setPendingReplace] = useState<string | null>(null);\n\n // Expand/collapse state (collapsed collection ids).\n const [collapsed, setCollapsed] = useState<Set<string>>(new Set());\n const [grabbed, setGrabbed] = useState<{\n collectionId: string;\n index: number;\n itemId: string;\n } | null>(null);\n const [origin, setOrigin] = useState<{\n collectionId: string;\n index: number;\n } | null>(null);\n const [liveMessage, setLiveMessage] = useState('');\n const listRef = useRef<HTMLDivElement>(null);\n const cancelledItemRef = useRef<string | null>(null);\n\n // Clear the import feedback after a few seconds.\n useEffect(() => {\n if (!status) {\n return;\n }\n const timer = setTimeout(() => setStatus(null), 4000);\n return () => clearTimeout(timer);\n }, [status]);\n\n const applyReplace = (text: string) => {\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n collectionsStore\n .getState()\n .actions.applyImport(analysis, { mode: 'replace' });\n };\n\n const runImport = (text: string, mode: 'merge' | 'replace') => {\n if (mode === 'replace') {\n setPendingReplace(text);\n return;\n }\n\n // merge path\n const count = parseCollectionsExport(text);\n if (count === null) {\n setStatus({\n ok: false,\n message: \"That file isn't a collections export.\",\n });\n return;\n }\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n if (!analysis.ok) {\n setStatus({ ok: false, message: 'Invalid collections export.' });\n return;\n }\n if (analysis.changedItems.length === 0) {\n // No conflicts — apply immediately.\n collectionsStore\n .getState()\n .actions.applyImport(analysis, { mode: 'merge', applyChanges: true });\n return;\n }\n // Conflicts present — open the dialog.\n setPendingConflict({\n analysis,\n sourceLabel: deriveSourceLabel(analysis._incoming),\n });\n };\n\n const handleConflictResolve = (resolution: ImportResolution) => {\n if (!pendingConflict) {\n return;\n }\n const { analysis } = pendingConflict;\n collectionsStore.getState().actions.applyImport(analysis, resolution);\n setPendingConflict(null);\n };\n\n const importDroppedFile = async (file: File) => {\n const text = await file.text();\n if (parseCollectionsExport(text) === null) {\n setStatus({\n ok: false,\n message: \"That file isn't a collections export.\",\n });\n return;\n }\n runImport(text, 'merge');\n };\n\n // Keep a live ref so the once-bound paste listener honors current config.\n const allowImportRef = useRef(allowImport);\n useEffect(() => {\n allowImportRef.current = allowImport;\n }, [allowImport]);\n\n // Paste a collections export anywhere in the open panel to merge it in.\n // Guarded so it never hijacks a normal paste: ignored while typing in an\n // editor/input, ignored unless the clipboard parses as an export, and\n // ignored entirely when importing is disabled.\n useEffect(() => {\n const onPaste = (event: ClipboardEvent) => {\n if (!allowImportRef.current) {\n return;\n }\n if (isEditableTarget(document.activeElement)) {\n return;\n }\n const text = event.clipboardData?.getData('text') ?? '';\n if (parseCollectionsExport(text) === null) {\n return;\n }\n event.preventDefault();\n runImport(text, 'merge');\n };\n document.addEventListener('paste', onPaste);\n return () => document.removeEventListener('paste', onPaste);\n // bound once: only stable refs (store, setStatus) are used\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const { addTab, changeTab, updateActiveTabValues } = useGraphiQLActions();\n const { queryEditor, variableEditor, headerEditor } = useGraphiQL(\n pick('queryEditor', 'variableEditor', 'headerEditor'),\n );\n const tabs = useGraphiQL(s => s.tabs);\n const activeTabId = useGraphiQL(s => s.tabs[s.activeTabIndex]?.id);\n\n // Opening an item creates a tab, then links it once the new tab is active so\n // ⌘S updates the saved item in place rather than reopening the dialog.\n const pendingLink = useRef<{ collectionId: string; itemId: string } | null>(\n null,\n );\n useEffect(() => {\n const link = pendingLink.current;\n if (link && activeTabId) {\n actions.linkTab(activeTabId, link.collectionId, link.itemId);\n pendingLink.current = null;\n }\n }, [activeTabId, actions]);\n\n const handleOpen = (item: CollectionItem) => {\n // A saved operation is married to its tab. If that tab is still open, just\n // focus it rather than opening a duplicate — and leave its contents alone so\n // any in-progress edits survive. Links persist across reloads, so this holds\n // after a page refresh too.\n const { links } = collectionsStore.getState();\n const openIndex = tabs.findIndex(\n t => t.id && links[t.id]?.itemId === item.id,\n );\n if (openIndex !== -1) {\n changeTab(openIndex);\n return;\n }\n\n const collectionId = collections.find(c =>\n c.items.some(i => i.id === item.id),\n )?.id;\n if (collectionId) {\n pendingLink.current = { collectionId, itemId: item.id };\n }\n addTab();\n // `addTab` resets the editors to the new empty tab, so populate them with\n // the saved operation. The editors' change handlers sync this back to tab\n // state; `updateActiveTabValues` covers the case where an editor isn't\n // mounted yet. Seed `lastSavedQuery` too so the freshly opened tab matches\n // its saved item and doesn't show as dirty.\n queryEditor?.setValue(item.query ?? '');\n variableEditor?.setValue(item.variables ?? '');\n headerEditor?.setValue(item.headers ?? '');\n updateActiveTabValues({\n query: item.query,\n variables: item.variables ?? '',\n headers: item.headers ?? '',\n lastSavedQuery: item.query ?? null,\n });\n };\n\n const announce = (message: string) => setLiveMessage(message);\n\n const handleShareCollection = async (collectionId: string) => {\n const json = collectionsStore\n .getState()\n .actions.exportCollection(collectionId);\n await navigator.clipboard.writeText(json);\n };\n\n const handleShareItem = async (itemId: string) => {\n const json = collectionsStore.getState().actions.exportItem(itemId);\n await navigator.clipboard.writeText(json);\n };\n\n const handleRename = actions.renameCollection;\n const handleDelete = actions.deleteCollection;\n const handleDeleteItem = actions.deleteItem;\n const handleMoveItem = actions.moveItem;\n const handleAddItem = actions.addItem;\n const handleRenameItem = (\n collectionId: string,\n itemId: string,\n updates: { name: string; description: string },\n ) => {\n collectionsStore.getState().actions.updateItem(collectionId, itemId, {\n name: updates.name,\n description: updates.description || undefined,\n });\n };\n\n const toggleExpand = (id: string) =>\n setCollapsed(prev => {\n const next = new Set(prev);\n if (next.has(id)) {\n next.delete(id);\n } else {\n next.add(id);\n }\n return next;\n });\n\n const expand = (id: string) =>\n setCollapsed(prev => {\n if (!prev.has(id)) {\n return prev;\n }\n const next = new Set(prev);\n next.delete(id);\n return next;\n });\n\n const handleGrabToggle = (\n collectionId: string,\n index: number,\n itemId: string,\n ) => {\n if (grabbed) {\n const cols = collectionsStore.getState().collections;\n const col = cols.find(c => c.id === grabbed.collectionId);\n const droppedItem = col?.items[grabbed.index];\n setLiveMessage(\n `Dropped ${droppedItem?.name ?? grabbed.itemId} in ${col?.name ?? ''} at position ${grabbed.index + 1}.`,\n );\n setGrabbed(null);\n setOrigin(null);\n return;\n }\n setGrabbed({ collectionId, index, itemId });\n setOrigin({ collectionId, index });\n const item = collectionsStore\n .getState()\n .collections.find(c => c.id === collectionId)?.items[index];\n setLiveMessage(\n `Grabbed ${item?.name ?? itemId}. Use arrow keys to move, space to drop, escape to cancel.`,\n );\n };\n\n const handleGrabMove = (direction: 'up' | 'down') => {\n if (!grabbed) {\n return;\n }\n const cols = collectionsStore.getState().collections;\n const cIdx = cols.findIndex(c => c.id === grabbed.collectionId);\n const col = cols[cIdx];\n if (!col) {\n return;\n }\n const { moveItem } = collectionsStore.getState().actions;\n\n if (direction === 'down') {\n if (grabbed.index < col.items.length - 1) {\n moveItem(col.id, grabbed.index, col.id, grabbed.index + 1);\n const next = { ...grabbed, index: grabbed.index + 1 };\n setGrabbed(next);\n setLiveMessage(\n `Position ${next.index + 1} of ${col.items.length} in ${col.name}.`,\n );\n } else if (cIdx < cols.length - 1) {\n const dest = cols[cIdx + 1]!;\n expand(dest.id);\n moveItem(col.id, grabbed.index, dest.id, 0);\n setGrabbed({ collectionId: dest.id, index: 0, itemId: grabbed.itemId });\n setLiveMessage(\n `Moved to ${dest.name}, position 1 of ${dest.items.length + 1}.`,\n );\n } else {\n setLiveMessage('Already at the end.');\n }\n } else if (grabbed.index > 0) {\n moveItem(col.id, grabbed.index, col.id, grabbed.index - 1);\n const next = { ...grabbed, index: grabbed.index - 1 };\n setGrabbed(next);\n setLiveMessage(\n `Position ${next.index + 1} of ${col.items.length} in ${col.name}.`,\n );\n } else if (cIdx > 0) {\n const dest = cols[cIdx - 1]!;\n expand(dest.id);\n const toIndex = dest.items.length;\n moveItem(col.id, grabbed.index, dest.id, toIndex);\n setGrabbed({\n collectionId: dest.id,\n index: toIndex,\n itemId: grabbed.itemId,\n });\n setLiveMessage(\n `Moved to ${dest.name}, position ${toIndex + 1} of ${dest.items.length + 1}.`,\n );\n } else {\n setLiveMessage('Already at the start.');\n }\n };\n\n const handleGrabCancel = () => {\n if (!grabbed || !origin) {\n return;\n }\n collectionsStore\n .getState()\n .actions.moveItem(\n grabbed.collectionId,\n grabbed.index,\n origin.collectionId,\n origin.index,\n );\n cancelledItemRef.current = grabbed.itemId;\n setGrabbed(null);\n setOrigin(null);\n setLiveMessage('Move cancelled.');\n };\n\n useEffect(() => {\n if (grabbed) {\n listRef.current\n ?.querySelector<HTMLElement>(\n `[data-collection-drag-handle=\"${grabbed.itemId}\"]`,\n )\n ?.focus();\n } else if (cancelledItemRef.current) {\n listRef.current\n ?.querySelector<HTMLElement>(\n `[data-collection-drag-handle=\"${cancelledItemRef.current}\"]`,\n )\n ?.focus();\n cancelledItemRef.current = null;\n }\n }, [grabbed]);\n\n return (\n <div\n className={`graphiql-collections-panel graphiql-side-panel-content${isDragOver ? ' graphiql-collections-drop-active' : ''}`}\n onDragOver={e => {\n if (!allowImport || !e.dataTransfer.types.includes('Files')) {\n return;\n }\n e.preventDefault();\n setIsDragOver(true);\n }}\n onDragLeave={e => {\n if (e.currentTarget.contains(e.relatedTarget as Node | null)) {\n return;\n }\n setIsDragOver(false);\n }}\n onDrop={e => {\n if (!allowImport) {\n return;\n }\n const file = e.dataTransfer.files[0];\n if (!file) {\n return; // not a file drop (e.g. an item being reordered)\n }\n e.preventDefault();\n setIsDragOver(false);\n void importDroppedFile(file);\n }}\n >\n <PanelHeader\n title=\"Operation Collections\"\n subtitle=\"Save and organize operations into collections.\"\n />\n {(!readOnly || allowImportExport) && (\n <div className=\"graphiql-collections-toolbar\">\n <div className=\"graphiql-collections-toolbar-left\">\n {!readOnly && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() =>\n collectionsStore\n .getState()\n .actions.createCollection('New Collection')\n }\n aria-label=\"New collection\"\n title=\"New collection\"\n >\n + New Collection\n </button>\n )}\n </div>\n <div className=\"graphiql-collections-toolbar-right\">\n {allowImport && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() => setOpenDialog('import')}\n aria-label=\"Import collections\"\n title=\"Import collections\"\n >\n <DownloadIcon />\n </button>\n )}\n {allowImportExport && (\n <button\n type=\"button\"\n className=\"graphiql-collections-action\"\n onClick={() => setOpenDialog('export')}\n aria-label=\"Export collections\"\n title=\"Export collections\"\n >\n <UploadIcon />\n </button>\n )}\n </div>\n </div>\n )}\n {status && (\n <div\n className={`graphiql-collections-status${status.ok ? '' : ' graphiql-collections-status-error'}`}\n role=\"status\"\n >\n {status.message}\n </div>\n )}\n {!loaded && <div className=\"graphiql-collections-loading\">Loading…</div>}\n {loaded && collections.length === 0 && (\n <div className=\"graphiql-collections-empty\">\n {readOnly\n ? 'No collections.'\n : allowImport\n ? 'No collections yet. Save an operation to get started, or drop or paste a collections export to import one.'\n : 'No collections yet. Save an operation to get started.'}\n </div>\n )}\n <div\n className=\"graphiql-sr-only\"\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n >\n {liveMessage}\n </div>\n <div className=\"graphiql-collections-list\" ref={listRef}>\n {collections.map(collection => (\n <CollectionRow\n key={collection.id}\n collection={collection}\n readOnly={readOnly}\n expanded={!collapsed.has(collection.id)}\n onToggleExpand={() => toggleExpand(collection.id)}\n grabbed={grabbed}\n onGrabToggle={handleGrabToggle}\n onGrabMove={handleGrabMove}\n onGrabCancel={handleGrabCancel}\n onRename={handleRename}\n onDelete={handleDelete}\n onShareCollection={handleShareCollection}\n onOpenItem={handleOpen}\n onShare={handleShareItem}\n onAnnounce={announce}\n onDeleteItem={handleDeleteItem}\n onMoveItem={handleMoveItem}\n onAddItem={handleAddItem}\n onRenameItem={handleRenameItem}\n />\n ))}\n </div>\n {allowImportExport && (\n <ExportDialog\n open={openDialog === 'export'}\n onClose={() => setOpenDialog(null)}\n />\n )}\n {allowImport && (\n <ImportDialog\n open={openDialog === 'import'}\n onClose={() => setOpenDialog(null)}\n onImport={runImport}\n allowReplace={allowReplace}\n />\n )}\n {pendingConflict && (\n <ConflictDialog\n analysis={pendingConflict.analysis}\n sourceLabel={pendingConflict.sourceLabel}\n open\n onClose={() => setPendingConflict(null)}\n onResolve={handleConflictResolve}\n />\n )}\n <Dialog\n open={pendingReplace !== null}\n onOpenChange={o => !o && setPendingReplace(null)}\n >\n <Dialog.Header>Replace all collections?</Dialog.Header>\n <Dialog.Body>\n <Dialog.Description className=\"graphiql-conflict-summary\">\n This will remove all existing collections and replace them with the\n imported data. This cannot be undone.\n </Dialog.Description>\n <div className=\"graphiql-conflict-actions\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() => {\n const text = pendingReplace;\n setPendingReplace(null);\n if (text !== null) {\n applyReplace(text);\n }\n }}\n >\n Replace\n </Button>\n <Button type=\"button\" onClick={() => setPendingReplace(null)}>\n Cancel\n </Button>\n </div>\n </Dialog.Body>\n </Dialog>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAS,uBAAuB,MAA6B;CAC3D,IAAI;EACF,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,MAAM,OAAO,MAAM,QAAQ,QAAQ,WAAW,IAC1C,OAAO,cACP,MAAM,QAAQ,MAAM,IAClB,SACA;EACN,IACE,CAAC,MAAM,UACP,CAAC,KAAK,OACH,MACC,KACA,OAAO,MAAM,YACb,MAAM,QAAS,EAA0B,KAAK,CAClD,GAEA,OAAO;EAET,OAAO,KAAK;CACd,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB,IAA6B;CACrD,IAAI,CAAC,IACH,OAAO;CAET,OACE,GAAG,YAAY,WACf,GAAG,YAAY,cACd,GAAmB,qBACpB,QAAQ,GAAG,QAAQ,gBAAgB,CAAC;AAExC;;AAGA,SAAS,kBAAkB,UAA+C;CACxE,IAAI,SAAS,WAAW,KAAK,SAAS,IACpC,OAAO,SAAS,EAAE,CAAC;CAErB,OAAO,GAAG,SAAS,OAAO;AAC5B;AAEA,IAAa,oBAA+C,EAC1D,WAAW,OACX,oBAAoB,MACpB,eAAe,WACX;CAGJ,MAAM,cAAc,CAAC,YAAY;CACjC,MAAM,UAAU,qBAAoB,MAAK,EAAE,OAAO;CAClD,MAAM,cAAc,qBAAoB,MAAK,EAAE,WAAW;CAC1D,MAAM,SAAS,qBAAoB,MAAK,EAAE,MAAM;CAChD,MAAM,CAAC,YAAY,iBAAiB,SAClC,IACF;CACA,MAAM,CAAC,YAAY,iBAAiB,SAAS,KA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ACE,UAAU,gBAAgB;IAC1B,aAAa,gBAAgB;IAC7B,MAAA;IACA,eAAe,mBAAmB,IAAI;IACtC,WAAW;GACZ,CAAA;GAEHD,qBAAC,QAAD;IACE,MAAM,mBAAmB;IACzB,eAAc,MAAK,CAAC,KAAK,kBAAkB,IAAI;IAFjD,UAAA,CAIEC,oBAAC,OAAO,QAAR,EAAA,UAAe,2BAAuC,CAAA,GACtDD,qBAAC,OAAO,MAAR,EAAA,UAAA,CACEC,oBAAC,OAAO,aAAR;KAAoB,WAAU;KAA4B,UAAA;IAGtC,CAAA,GACpBD,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACEC,oBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,eAAe;OACb,MAAM,OAAO;OACb,kBAAkB,IAAI;OACtB,IAAI,SAAS,MACX,aAAa,IAAI;MAErB;MACD,UAAA;KAEO,CAAA,GACRA,oBAAC,QAAD;MAAQ,MAAK;MAAS,eAAe,kBAAkB,IAAI;MAAG,UAAA;KAEtD,CAAA,CACL;IACM,CAAA,CAAA,EAAA,CAAA,CACP;;EACL;;AAET"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useCollectionsStore } from "../store.js";
|
|
2
1
|
import { useState } from "react";
|
|
3
2
|
import { Button, Dialog } from "@graphiql/react";
|
|
3
|
+
import { useCollectionsStore } from "../store.js";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/components/conflict-dialog.tsx
|
|
6
6
|
/** Returns a human-readable relative time hint comparing two timestamps. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict-dialog.js","names":[],"sources":["../../src/components/conflict-dialog.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport { Button, Dialog } from '@graphiql/react';\nimport { useCollectionsStore } from '../store';\nimport type { ImportAnalysis, ImportResolution, ItemConflict } from '../types';\n\ntype ConflictDialogProps = {\n analysis: ImportAnalysis;\n sourceLabel: string;\n open: boolean;\n onClose(): void;\n onResolve(resolution: ImportResolution): void;\n};\n\n/** Returns a human-readable relative time hint comparing two timestamps. */\nfunction updatedAtHint(incoming: number, current: number): string {\n const diffMs = incoming - current;\n if (Math.abs(diffMs) < 60_000) {\n return 'same time';\n }\n const diffMin = Math.round(Math.abs(diffMs) / 60_000);\n const diffHr = Math.round(Math.abs(diffMs) / 3_600_000);\n const diffDays = Math.round(Math.abs(diffMs) / 86_400_000);\n let magnitude: string;\n if (diffDays >= 1) {\n magnitude = `${diffDays}d`;\n } else if (diffHr >= 1) {\n magnitude = `${diffHr}h`;\n } else {\n magnitude = `${diffMin}m`;\n }\n return diffMs > 0\n ? `theirs: ${magnitude} newer`\n : `theirs: ${magnitude} older`;\n}\n\ntype ReviewRowProps = {\n conflict: ItemConflict;\n checked: boolean;\n onChange(id: string, checked: boolean): void;\n collectionName: string | undefined;\n};\n\nconst ReviewRow: FC<ReviewRowProps> = ({\n conflict,\n checked,\n onChange,\n collectionName,\n}) => {\n const hint = updatedAtHint(\n conflict.incoming.updatedAt,\n conflict.current.updatedAt,\n );\n return (\n <label className=\"graphiql-conflict-review-row\">\n <input\n type=\"checkbox\"\n checked={checked}\n onChange={e => onChange(conflict.incoming.id, e.target.checked)}\n className=\"graphiql-conflict-review-checkbox\"\n />\n <span className=\"graphiql-conflict-review-name\">\n {conflict.incoming.name}\n </span>\n {collectionName && (\n <span className=\"graphiql-conflict-review-collection\">\n in {collectionName}\n </span>\n )}\n <span className=\"graphiql-conflict-review-hint\">{hint}</span>\n </label>\n );\n};\n\nexport const ConflictDialog: FC<ConflictDialogProps> = ({\n analysis,\n sourceLabel,\n open,\n onClose,\n onResolve,\n}) => {\n const [reviewing, setReviewing] = useState(false);\n // Default all to unchecked (keep mine = safe default)\n const [checked, setChecked] = useState<Set<string>>(new Set());\n // Conflicts always reference a collection the recipient already has, so the\n // \"in X\" label comes from local collections, not the incoming envelope.\n const localCollections = useCollectionsStore(s => s.collections);\n\n const handleCheckChange = (id: string, isChecked: boolean) => {\n setChecked(prev => {\n const next = new Set(prev);\n if (isChecked) {\n next.add(id);\n } else {\n next.delete(id);\n }\n return next;\n });\n };\n\n const handleOpenChange = (isOpen: boolean) => {\n if (!isOpen) {\n onClose();\n }\n };\n\n const collectionNameById = new Map(localCollections.map(c => [c.id, c.name]));\n\n const summary = [\n analysis.newItems.length > 0 && `${analysis.newItems.length} new`,\n analysis.changedItems.length > 0 &&\n `${analysis.changedItems.length} with changes`,\n analysis.unchangedCount > 0 && `${analysis.unchangedCount} unchanged`,\n ]\n .filter(Boolean)\n .join(', ');\n\n const newCollectionCount = analysis.newCollections.length;\n\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <Dialog.Header>Import conflicts</Dialog.Header>\n <Dialog.Body>\n <Dialog.Description className=\"graphiql-conflict-summary\">\n Importing <strong>{sourceLabel}</strong>: {summary} operation\n {analysis.newItems.length +\n analysis.changedItems.length +\n analysis.unchangedCount !==\n 1\n ? 's'\n : ''}\n {newCollectionCount > 0 &&\n `, ${newCollectionCount} new collection${newCollectionCount !== 1 ? 's' : ''}`}\n .\n </Dialog.Description>\n\n {!reviewing ? (\n <div className=\"graphiql-conflict-actions\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() => onResolve({ mode: 'merge', applyChanges: true })}\n >\n Apply changes\n </Button>\n <Button\n type=\"button\"\n onClick={() => onResolve({ mode: 'merge', applyChanges: false })}\n >\n Keep my versions\n </Button>\n <Button\n type=\"button\"\n onClick={() => {\n setChecked(new Set());\n setReviewing(true);\n }}\n >\n Review each…\n </Button>\n </div>\n ) : (\n <div className=\"graphiql-conflict-review\">\n <p className=\"graphiql-conflict-review-hint-label\">\n Check which incoming versions to accept (unchecked = keep yours):\n </p>\n <div className=\"graphiql-conflict-review-list\">\n {analysis.changedItems.map(conflict => (\n <ReviewRow\n key={conflict.incoming.id}\n conflict={conflict}\n checked={checked.has(conflict.incoming.id)}\n onChange={handleCheckChange}\n collectionName={collectionNameById.get(\n conflict.currentCollectionId,\n )}\n />\n ))}\n </div>\n <div className=\"graphiql-conflict-review-confirm\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() =>\n onResolve({ mode: 'merge', changedItemIds: new Set(checked) })\n }\n >\n Confirm selection\n </Button>\n <Button\n type=\"button\"\n onClick={() => {\n setReviewing(false);\n setChecked(new Set());\n }}\n >\n Back\n </Button>\n </div>\n </div>\n )}\n </Dialog.Body>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;AAcA,SAAS,cAAc,UAAkB,SAAyB;CAChE,MAAM,SAAS,WAAW;CAC1B,IAAI,KAAK,IAAI,MAAM,IAAI,KACrB,OAAO;CAET,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,GAAM;CACpD,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,IAAS;CACtD,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,KAAU;CACzD,IAAI;CACJ,IAAI,YAAY,GACd,YAAY,GAAG,SAAS;MACnB,IAAI,UAAU,GACnB,YAAY,GAAG,OAAO;MAEtB,YAAY,GAAG,QAAQ;CAEzB,OAAO,SAAS,IACZ,WAAW,UAAU,UACrB,WAAW,UAAU;AAC3B;AASA,IAAM,aAAiC,EACrC,UACA,SACA,UACA,qBACI;CACJ,MAAM,OAAO,cACX,SAAS,SAAS,WAClB,SAAS,QAAQ,SACnB;CACA,
|
|
1
|
+
{"version":3,"file":"conflict-dialog.js","names":["_jsxs","_jsx"],"sources":["../../src/components/conflict-dialog.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport { Button, Dialog } from '@graphiql/react';\nimport { useCollectionsStore } from '../store';\nimport type { ImportAnalysis, ImportResolution, ItemConflict } from '../types';\n\ntype ConflictDialogProps = {\n analysis: ImportAnalysis;\n sourceLabel: string;\n open: boolean;\n onClose(): void;\n onResolve(resolution: ImportResolution): void;\n};\n\n/** Returns a human-readable relative time hint comparing two timestamps. */\nfunction updatedAtHint(incoming: number, current: number): string {\n const diffMs = incoming - current;\n if (Math.abs(diffMs) < 60_000) {\n return 'same time';\n }\n const diffMin = Math.round(Math.abs(diffMs) / 60_000);\n const diffHr = Math.round(Math.abs(diffMs) / 3_600_000);\n const diffDays = Math.round(Math.abs(diffMs) / 86_400_000);\n let magnitude: string;\n if (diffDays >= 1) {\n magnitude = `${diffDays}d`;\n } else if (diffHr >= 1) {\n magnitude = `${diffHr}h`;\n } else {\n magnitude = `${diffMin}m`;\n }\n return diffMs > 0\n ? `theirs: ${magnitude} newer`\n : `theirs: ${magnitude} older`;\n}\n\ntype ReviewRowProps = {\n conflict: ItemConflict;\n checked: boolean;\n onChange(id: string, checked: boolean): void;\n collectionName: string | undefined;\n};\n\nconst ReviewRow: FC<ReviewRowProps> = ({\n conflict,\n checked,\n onChange,\n collectionName,\n}) => {\n const hint = updatedAtHint(\n conflict.incoming.updatedAt,\n conflict.current.updatedAt,\n );\n return (\n <label className=\"graphiql-conflict-review-row\">\n <input\n type=\"checkbox\"\n checked={checked}\n onChange={e => onChange(conflict.incoming.id, e.target.checked)}\n className=\"graphiql-conflict-review-checkbox\"\n />\n <span className=\"graphiql-conflict-review-name\">\n {conflict.incoming.name}\n </span>\n {collectionName && (\n <span className=\"graphiql-conflict-review-collection\">\n in {collectionName}\n </span>\n )}\n <span className=\"graphiql-conflict-review-hint\">{hint}</span>\n </label>\n );\n};\n\nexport const ConflictDialog: FC<ConflictDialogProps> = ({\n analysis,\n sourceLabel,\n open,\n onClose,\n onResolve,\n}) => {\n const [reviewing, setReviewing] = useState(false);\n // Default all to unchecked (keep mine = safe default)\n const [checked, setChecked] = useState<Set<string>>(new Set());\n // Conflicts always reference a collection the recipient already has, so the\n // \"in X\" label comes from local collections, not the incoming envelope.\n const localCollections = useCollectionsStore(s => s.collections);\n\n const handleCheckChange = (id: string, isChecked: boolean) => {\n setChecked(prev => {\n const next = new Set(prev);\n if (isChecked) {\n next.add(id);\n } else {\n next.delete(id);\n }\n return next;\n });\n };\n\n const handleOpenChange = (isOpen: boolean) => {\n if (!isOpen) {\n onClose();\n }\n };\n\n const collectionNameById = new Map(localCollections.map(c => [c.id, c.name]));\n\n const summary = [\n analysis.newItems.length > 0 && `${analysis.newItems.length} new`,\n analysis.changedItems.length > 0 &&\n `${analysis.changedItems.length} with changes`,\n analysis.unchangedCount > 0 && `${analysis.unchangedCount} unchanged`,\n ]\n .filter(Boolean)\n .join(', ');\n\n const newCollectionCount = analysis.newCollections.length;\n\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <Dialog.Header>Import conflicts</Dialog.Header>\n <Dialog.Body>\n <Dialog.Description className=\"graphiql-conflict-summary\">\n Importing <strong>{sourceLabel}</strong>: {summary} operation\n {analysis.newItems.length +\n analysis.changedItems.length +\n analysis.unchangedCount !==\n 1\n ? 's'\n : ''}\n {newCollectionCount > 0 &&\n `, ${newCollectionCount} new collection${newCollectionCount !== 1 ? 's' : ''}`}\n .\n </Dialog.Description>\n\n {!reviewing ? (\n <div className=\"graphiql-conflict-actions\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() => onResolve({ mode: 'merge', applyChanges: true })}\n >\n Apply changes\n </Button>\n <Button\n type=\"button\"\n onClick={() => onResolve({ mode: 'merge', applyChanges: false })}\n >\n Keep my versions\n </Button>\n <Button\n type=\"button\"\n onClick={() => {\n setChecked(new Set());\n setReviewing(true);\n }}\n >\n Review each…\n </Button>\n </div>\n ) : (\n <div className=\"graphiql-conflict-review\">\n <p className=\"graphiql-conflict-review-hint-label\">\n Check which incoming versions to accept (unchecked = keep yours):\n </p>\n <div className=\"graphiql-conflict-review-list\">\n {analysis.changedItems.map(conflict => (\n <ReviewRow\n key={conflict.incoming.id}\n conflict={conflict}\n checked={checked.has(conflict.incoming.id)}\n onChange={handleCheckChange}\n collectionName={collectionNameById.get(\n conflict.currentCollectionId,\n )}\n />\n ))}\n </div>\n <div className=\"graphiql-conflict-review-confirm\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() =>\n onResolve({ mode: 'merge', changedItemIds: new Set(checked) })\n }\n >\n Confirm selection\n </Button>\n <Button\n type=\"button\"\n onClick={() => {\n setReviewing(false);\n setChecked(new Set());\n }}\n >\n Back\n </Button>\n </div>\n </div>\n )}\n </Dialog.Body>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;AAcA,SAAS,cAAc,UAAkB,SAAyB;CAChE,MAAM,SAAS,WAAW;CAC1B,IAAI,KAAK,IAAI,MAAM,IAAI,KACrB,OAAO;CAET,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,GAAM;CACpD,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,IAAS;CACtD,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,KAAU;CACzD,IAAI;CACJ,IAAI,YAAY,GACd,YAAY,GAAG,SAAS;MACnB,IAAI,UAAU,GACnB,YAAY,GAAG,OAAO;MAEtB,YAAY,GAAG,QAAQ;CAEzB,OAAO,SAAS,IACZ,WAAW,UAAU,UACrB,WAAW,UAAU;AAC3B;AASA,IAAM,aAAiC,EACrC,UACA,SACA,UACA,qBACI;CACJ,MAAM,OAAO,cACX,SAAS,SAAS,WAClB,SAAS,QAAQ,SACnB;CACA,OACEA,qBAAC,SAAD;EAAO,WAAU;EAAjB,UAAA;GACEC,oBAAC,SAAD;IACE,MAAK;IACI;IACT,WAAU,MAAK,SAAS,SAAS,SAAS,IAAI,EAAE,OAAO,OAAO;IAC9D,WAAU;GACX,CAAA;GACDA,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,SAAS,SAAS;GACf,CAAA;GACL,kBACCD,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CAAsD,OAChD,cACA;;GAERC,oBAAC,QAAD;IAAM,WAAU;IAAiC,UAAA;GAAW,CAAA;EACvD;;AAEX;AAEA,IAAa,kBAA2C,EACtD,UACA,aACA,MACA,SACA,gBACI;CACJ,MAAM,CAAC,WAAW,gBAAgB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ACL,SAAQ;KACR,eAAe,UAAU;MAAE,MAAM;MAAS,cAAc;KAAK,CAAC;KAC/D,UAAA;IAEO,CAAA;IACRA,oBAAC,QAAD;KACE,MAAK;KACL,eAAe,UAAU;MAAE,MAAM;MAAS,cAAc;KAAM,CAAC;KAChE,UAAA;IAEO,CAAA;IACRA,oBAAC,QAAD;KACE,MAAK;KACL,eAAe;MACb,2BAAW,IAAI,IAAI,CAAC;MACpB,aAAa,IAAI;KACnB;KACD,UAAA;IAEO,CAAA;GACL;EAEL,CAAA,IAAAD,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACEC,oBAAC,KAAD;KAAG,WAAU;KAAsC,UAAA;IAEhD,CAAA;IACHA,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,SAAS,aAAa,KAAI,aACzBA,oBAAC,WAAD;MAEY;MACV,SAAS,QAAQ,IAAI,SAAS,SAAS,EAAE;MACzC,UAAU;MACV,gBAAgB,mBAAmB,IACjC,SAAS,mBACX;KACD,GAPM,SAAS,SAAS,EAOxB,CACF;IACE,CAAA;IACLD,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACEC,oBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,eACE,UAAU;OAAE,MAAM;OAAS,gBAAgB,IAAI,IAAI,OAAO;MAAE,CAAC;MAEhE,UAAA;KAEO,CAAA,GACRA,oBAAC,QAAD;MACE,MAAK;MACL,eAAe;OACb,aAAa,KAAK;OAClB,2BAAW,IAAI,IAAI,CAAC;MACtB;MACD,UAAA;KAEO,CAAA,CACL;;GACF;EAEI,CAAA,CAAA,EAAA,CAAA,CACP;;AAEZ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Button, Dialog, Textarea } from "@graphiql/react";
|
|
1
2
|
import { collectionsStore } from "../store.js";
|
|
2
|
-
import { Button, Dialog } from "@graphiql/react";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
// src/components/export-dialog.tsx
|
|
5
5
|
var ExportDialog = ({ open, onClose }) => {
|
|
@@ -33,9 +33,9 @@ var ExportDialog = ({ open, onClose }) => {
|
|
|
33
33
|
}),
|
|
34
34
|
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs("div", {
|
|
35
35
|
className: "graphiql-import-export-section",
|
|
36
|
-
children: [/* @__PURE__ */ jsx(
|
|
36
|
+
children: [/* @__PURE__ */ jsx(Textarea, {
|
|
37
37
|
readOnly: true,
|
|
38
|
-
|
|
38
|
+
monospace: true,
|
|
39
39
|
value: exported,
|
|
40
40
|
rows: 12
|
|
41
41
|
}), /* @__PURE__ */ jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-dialog.js","names":[],"sources":["../../src/components/export-dialog.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { Button, Dialog } from '@graphiql/react';\nimport { collectionsStore } from '../store';\n\ntype ExportDialogProps = {\n open: boolean;\n onClose(): void;\n};\n\nexport const ExportDialog: FC<ExportDialogProps> = ({ open, onClose }) => {\n const exported = open\n ? collectionsStore.getState().actions.exportCollections()\n : '';\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(exported);\n } catch {\n // clipboard unavailable; leave the dialog open so the textarea stays\n // selectable as a fallback.\n return;\n }\n onClose();\n };\n\n const handleDownload = () => {\n const blob = new Blob([exported], { type: 'application/json' });\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = 'graphiql-collections.json';\n a.click();\n setTimeout(() => URL.revokeObjectURL(url), 0);\n onClose();\n };\n\n return (\n <Dialog open={open} onOpenChange={o => !o && onClose()}>\n <Dialog.Header>Export collections</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Copy or download all collections as JSON.\n </Dialog.Description>\n <Dialog.Body>\n <div className=\"graphiql-import-export-section\">\n <
|
|
1
|
+
{"version":3,"file":"export-dialog.js","names":["_jsxs","_jsx"],"sources":["../../src/components/export-dialog.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { Button, Dialog, Textarea } from '@graphiql/react';\nimport { collectionsStore } from '../store';\n\ntype ExportDialogProps = {\n open: boolean;\n onClose(): void;\n};\n\nexport const ExportDialog: FC<ExportDialogProps> = ({ open, onClose }) => {\n const exported = open\n ? collectionsStore.getState().actions.exportCollections()\n : '';\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(exported);\n } catch {\n // clipboard unavailable; leave the dialog open so the textarea stays\n // selectable as a fallback.\n return;\n }\n onClose();\n };\n\n const handleDownload = () => {\n const blob = new Blob([exported], { type: 'application/json' });\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = 'graphiql-collections.json';\n a.click();\n setTimeout(() => URL.revokeObjectURL(url), 0);\n onClose();\n };\n\n return (\n <Dialog open={open} onOpenChange={o => !o && onClose()}>\n <Dialog.Header>Export collections</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Copy or download all collections as JSON.\n </Dialog.Description>\n <Dialog.Body>\n <div className=\"graphiql-import-export-section\">\n <Textarea readOnly monospace value={exported} rows={12} />\n <div className=\"graphiql-import-export-actions\">\n <Button\n type=\"button\"\n variant=\"primary\"\n onClick={() => void handleCopy()}\n >\n Copy JSON\n </Button>\n <Button type=\"button\" onClick={handleDownload}>\n Download JSON\n </Button>\n </div>\n </div>\n </Dialog.Body>\n </Dialog>\n );\n};\n"],"mappings":";;;;AASA,IAAa,gBAAuC,EAAE,MAAM,cAAc;CACxE,MAAM,WAAW,OACb,iBAAiB,SAAS,CAAC,CAAC,QAAQ,kBAAkB,IACtD;CAEJ,MAAM,aAAa,YAAY;EAC7B,IAAI;GACF,MAAM,UAAU,UAAU,UAAU,QAAQ;EAC9C,QAAQ;GAGN;EACF;EACA,QAAQ;CACV;CAEA,MAAM,uBAAuB;EAC3B,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,GAAG,EAAE,MAAM,mBAAmB,CAAC;EAC9D,MAAM,MAAM,IAAI,gBAAgB,IAAI;EACpC,MAAM,IAAI,SAAS,cAAc,GAAG;EACpC,EAAE,OAAO;EACT,EAAE,WAAW;EACb,EAAE,MAAM;EACR,iBAAiB,IAAI,gBAAgB,GAAG,GAAG,CAAC;EAC5C,QAAQ;CACV;CAEA,OACEA,qBAAC,QAAD;EAAc;EAAM,eAAc,MAAK,CAAC,KAAK,QAAQ;EAArD,UAAA;GACEC,oBAAC,OAAO,QAAR,EAAA,UAAe,qBAAiC,CAAA;GAChDA,oBAAC,OAAO,aAAR;IAAoB,WAAU;IAAmB,UAAA;GAE7B,CAAA;GACpBA,oBAAC,OAAO,MAAR,EAAA,UACED,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACEC,oBAAC,UAAD;KAAU,UAAA;KAAS,WAAA;KAAU,OAAO;KAAU,MAAM;IAAK,CAAA,GACzDD,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACEC,oBAAC,QAAD;MACE,MAAK;MACL,SAAQ;MACR,eAAe,KAAK,WAAW;MAChC,UAAA;KAEO,CAAA,GACRA,oBAAC,QAAD;MAAQ,MAAK;MAAS,SAAS;MAAgB,UAAA;KAEvC,CAAA,CACL;IACF,CAAA,CAAA;GACM,CAAA,EAAA,CAAA;EACP;;AAEZ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { collectionsStore } from "../store.js";
|
|
2
1
|
import { useRef, useState } from "react";
|
|
3
|
-
import { Button, Dialog } from "@graphiql/react";
|
|
2
|
+
import { Button, Dialog, Textarea } from "@graphiql/react";
|
|
3
|
+
import { collectionsStore } from "../store.js";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/components/import-dialog.tsx
|
|
6
6
|
var ImportDialog = ({ open, onClose, onImport, allowReplace = true }) => {
|
|
@@ -51,8 +51,8 @@ var ImportDialog = ({ open, onClose, onImport, allowReplace = true }) => {
|
|
|
51
51
|
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs("div", {
|
|
52
52
|
className: "graphiql-import-export-section",
|
|
53
53
|
children: [
|
|
54
|
-
/* @__PURE__ */ jsx(
|
|
55
|
-
|
|
54
|
+
/* @__PURE__ */ jsx(Textarea, {
|
|
55
|
+
monospace: true,
|
|
56
56
|
rows: 6,
|
|
57
57
|
"aria-label": "Paste collections export JSON",
|
|
58
58
|
placeholder: "Paste a collections export (JSON)…",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-dialog.js","names":[],"sources":["../../src/components/import-dialog.tsx"],"sourcesContent":["import { FC, useRef, useState } from 'react';\nimport { Button, Dialog } from '@graphiql/react';\nimport { collectionsStore } from '../store';\n\ntype ImportDialogProps = {\n open: boolean;\n onClose(): void;\n onImport(text: string, mode: 'merge' | 'replace'): void;\n /** Hide the \"Replace\" import option (force merge) when false. */\n allowReplace?: boolean;\n};\n\nexport const ImportDialog: FC<ImportDialogProps> = ({\n open,\n onClose,\n onImport,\n allowReplace = true,\n}) => {\n const [importMode, setImportMode] = useState<'merge' | 'replace'>('merge');\n const [importError, setImportError] = useState<string | null>(null);\n const [pastedText, setPastedText] = useState('');\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const validateAndImport = (text: string) => {\n try {\n JSON.parse(text);\n } catch {\n setImportError(\n 'Invalid JSON. Please paste or select a valid collections export.',\n );\n return;\n }\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n if (!analysis.ok) {\n setImportError('This isn’t a valid collections export.');\n return;\n }\n onImport(text, allowReplace ? importMode : 'merge');\n onClose();\n };\n\n const handleImport = () => {\n const pasted = pastedText.trim();\n if (pasted) {\n validateAndImport(pasted);\n return;\n }\n const file = fileInputRef.current?.files?.[0];\n if (!file) {\n setImportError('Paste a collections export or choose a file.');\n return;\n }\n const reader = new FileReader();\n reader.onload = e => {\n validateAndImport(e.target?.result as string);\n };\n reader.readAsText(file);\n };\n\n return (\n <Dialog open={open} onOpenChange={o => !o && onClose()}>\n <Dialog.Header>Import collections</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Import collections from a JSON export.\n </Dialog.Description>\n <Dialog.Body>\n <div className=\"graphiql-import-export-section\">\n <
|
|
1
|
+
{"version":3,"file":"import-dialog.js","names":["_jsxs","_jsx"],"sources":["../../src/components/import-dialog.tsx"],"sourcesContent":["import { FC, useRef, useState } from 'react';\nimport { Button, Dialog, Textarea } from '@graphiql/react';\nimport { collectionsStore } from '../store';\n\ntype ImportDialogProps = {\n open: boolean;\n onClose(): void;\n onImport(text: string, mode: 'merge' | 'replace'): void;\n /** Hide the \"Replace\" import option (force merge) when false. */\n allowReplace?: boolean;\n};\n\nexport const ImportDialog: FC<ImportDialogProps> = ({\n open,\n onClose,\n onImport,\n allowReplace = true,\n}) => {\n const [importMode, setImportMode] = useState<'merge' | 'replace'>('merge');\n const [importError, setImportError] = useState<string | null>(null);\n const [pastedText, setPastedText] = useState('');\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const validateAndImport = (text: string) => {\n try {\n JSON.parse(text);\n } catch {\n setImportError(\n 'Invalid JSON. Please paste or select a valid collections export.',\n );\n return;\n }\n const analysis = collectionsStore.getState().actions.analyzeImport(text);\n if (!analysis.ok) {\n setImportError('This isn’t a valid collections export.');\n return;\n }\n onImport(text, allowReplace ? importMode : 'merge');\n onClose();\n };\n\n const handleImport = () => {\n const pasted = pastedText.trim();\n if (pasted) {\n validateAndImport(pasted);\n return;\n }\n const file = fileInputRef.current?.files?.[0];\n if (!file) {\n setImportError('Paste a collections export or choose a file.');\n return;\n }\n const reader = new FileReader();\n reader.onload = e => {\n validateAndImport(e.target?.result as string);\n };\n reader.readAsText(file);\n };\n\n return (\n <Dialog open={open} onOpenChange={o => !o && onClose()}>\n <Dialog.Header>Import collections</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Import collections from a JSON export.\n </Dialog.Description>\n <Dialog.Body>\n <div className=\"graphiql-import-export-section\">\n <Textarea\n monospace\n rows={6}\n aria-label=\"Paste collections export JSON\"\n placeholder=\"Paste a collections export (JSON)…\"\n value={pastedText}\n onChange={e => {\n setPastedText(e.target.value);\n setImportError(null);\n }}\n />\n <input\n ref={fileInputRef}\n type=\"file\"\n accept=\".json,application/json\"\n onChange={() => setImportError(null)}\n />\n <fieldset className=\"graphiql-import-export-mode\">\n <legend>Import mode</legend>\n <label>\n <input\n type=\"radio\"\n name=\"import-mode\"\n value=\"merge\"\n checked={!allowReplace || importMode === 'merge'}\n onChange={() => setImportMode('merge')}\n />\n Merge (add new, update changed in place)\n </label>\n {allowReplace && (\n <label>\n <input\n type=\"radio\"\n name=\"import-mode\"\n value=\"replace\"\n checked={importMode === 'replace'}\n onChange={() => setImportMode('replace')}\n />\n Replace (remove all existing collections)\n </label>\n )}\n </fieldset>\n {importError && (\n <p className=\"graphiql-import-export-error\">{importError}</p>\n )}\n <Button type=\"button\" variant=\"primary\" onClick={handleImport}>\n Import\n </Button>\n </div>\n </Dialog.Body>\n </Dialog>\n );\n};\n"],"mappings":";;;;;AAYA,IAAa,gBAAuC,EAClD,MACA,SACA,UACA,eAAe,WACX;CACJ,MAAM,CAAC,YAAY,iBAAiB,SAA8B,OAAO;CACzE,MAAM,CAAC,aAAa,kBAAkB,SAAwB,IAAI;CAClE,MAAM,CAAC,YAAY,iBAAiB,SAAS,EAAE;CAC/C,MAAM,eAAe,OAAyB,IAAI;CAElD,MAAM,qBAAqB,SAAiB;EAC1C,IAAI;GACF,KAAK,MAAM,IAAI;EACjB,QAAQ;GACN,eACE,kEACF;GACA;EACF;EAEA,IAAI,CADa,iBAAiB,SAAS,CAAC,CAAC,QAAQ,cAAc,IAC9D,CAAA,CAAS,IAAI;GAChB,eAAe,wCAAwC;GACvD;EACF;EACA,SAAS,MAAM,eAAe,aAAa,OAAO;EAClD,QAAQ;CACV;CAEA,MAAM,qBAAqB;EACzB,MAAM,SAAS,WAAW,KAAK;EAC/B,IAAI,QAAQ;GACV,kBAAkB,MAAM;GACxB;EACF;EACA,MAAM,OAAO,aAA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BAAC,QAAD;MAAQ,MAAK;MAAS,SAAQ;MAAU,SAAS;MAAc,UAAA;KAEvD,CAAA;IACL;GACM,CAAA,EAAA,CAAA;EACP;;AAEZ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { collectionsStore, useCollectionsStore } from "../store.js";
|
|
2
1
|
import { useState } from "react";
|
|
3
|
-
import { Button, Dialog } from "@graphiql/react";
|
|
2
|
+
import { Button, Dialog, Input, Select } from "@graphiql/react";
|
|
3
|
+
import { collectionsStore, useCollectionsStore } from "../store.js";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/components/save-dialog.tsx
|
|
6
6
|
var NEW_COLLECTION = "__new__";
|
|
@@ -53,31 +53,28 @@ var SaveDialogForm = ({ initialName }) => {
|
|
|
53
53
|
children: [/* @__PURE__ */ jsxs(Dialog.Body, { children: [
|
|
54
54
|
/* @__PURE__ */ jsxs("label", {
|
|
55
55
|
className: "graphiql-save-dialog-field",
|
|
56
|
-
children: [/* @__PURE__ */ jsx("span", { children: "Operation name" }), /* @__PURE__ */ jsx(
|
|
56
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Operation name" }), /* @__PURE__ */ jsx(Input, {
|
|
57
57
|
type: "text",
|
|
58
58
|
value: name,
|
|
59
59
|
onChange: (e) => setName(e.target.value),
|
|
60
60
|
placeholder: "Unnamed operation",
|
|
61
|
-
className: "graphiql-save-dialog-input",
|
|
62
61
|
autoFocus: true
|
|
63
62
|
})]
|
|
64
63
|
}),
|
|
65
64
|
/* @__PURE__ */ jsxs("label", {
|
|
66
65
|
className: "graphiql-save-dialog-field",
|
|
67
|
-
children: [/* @__PURE__ */ jsx("span", { children: "Description" }), /* @__PURE__ */ jsx(
|
|
66
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Description" }), /* @__PURE__ */ jsx(Input, {
|
|
68
67
|
type: "text",
|
|
69
68
|
value: description,
|
|
70
69
|
onChange: (e) => setDescription(e.target.value),
|
|
71
|
-
placeholder: "Description (optional)"
|
|
72
|
-
className: "graphiql-save-dialog-input"
|
|
70
|
+
placeholder: "Description (optional)"
|
|
73
71
|
})]
|
|
74
72
|
}),
|
|
75
73
|
/* @__PURE__ */ jsxs("label", {
|
|
76
74
|
className: "graphiql-save-dialog-field",
|
|
77
|
-
children: [/* @__PURE__ */ jsx("span", { children: "Collection" }), /* @__PURE__ */ jsxs(
|
|
75
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Collection" }), /* @__PURE__ */ jsxs(Select, {
|
|
78
76
|
value: selectedCollectionId,
|
|
79
77
|
onChange: (e) => setSelectedCollectionId(e.target.value),
|
|
80
|
-
className: "graphiql-save-dialog-select",
|
|
81
78
|
children: [/* @__PURE__ */ jsx("option", {
|
|
82
79
|
value: NEW_COLLECTION,
|
|
83
80
|
children: "+ New collection"
|
|
@@ -89,12 +86,11 @@ var SaveDialogForm = ({ initialName }) => {
|
|
|
89
86
|
}),
|
|
90
87
|
selectedCollectionId === NEW_COLLECTION && /* @__PURE__ */ jsxs("label", {
|
|
91
88
|
className: "graphiql-save-dialog-field",
|
|
92
|
-
children: [/* @__PURE__ */ jsx("span", { children: "Collection name" }), /* @__PURE__ */ jsx(
|
|
89
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Collection name" }), /* @__PURE__ */ jsx(Input, {
|
|
93
90
|
type: "text",
|
|
94
91
|
value: newCollectionName,
|
|
95
92
|
onChange: (e) => setNewCollectionName(e.target.value),
|
|
96
|
-
placeholder: "Collection name"
|
|
97
|
-
className: "graphiql-save-dialog-input"
|
|
93
|
+
placeholder: "Collection name"
|
|
98
94
|
})]
|
|
99
95
|
})
|
|
100
96
|
] }), /* @__PURE__ */ jsxs(Dialog.Footer, { children: [/* @__PURE__ */ jsx(Button, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-dialog.js","names":["_Fragment"],"sources":["../../src/components/save-dialog.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport { Button, Dialog } from '@graphiql/react';\nimport { useCollectionsStore, collectionsStore } from '../store';\n\nconst NEW_COLLECTION = '__new__';\n\n/**\n * The single \"Save to collection\" dialog. Its open state and the operation\n * being saved live in the collections store, so ⌘S and the save button can open\n * it imperatively via `requestSave`.\n */\nexport const SaveDialog: FC = () => {\n const { open, name, requestId } = useCollectionsStore(s => s.saveDialog);\n const closeSaveDialog = useCollectionsStore(s => s.actions.closeSaveDialog);\n\n return (\n <Dialog open={open} onOpenChange={o => !o && closeSaveDialog()}>\n {open && <SaveDialogForm key={requestId} initialName={name} />}\n </Dialog>\n );\n};\n\nconst SaveDialogForm: FC<{ initialName: string }> = ({ initialName }) => {\n const collections = useCollectionsStore(s => s.collections);\n const closeSaveDialog = useCollectionsStore(s => s.actions.closeSaveDialog);\n const [saving, setSaving] = useState(false);\n const [name, setName] = useState(initialName);\n const [description, setDescription] = useState('');\n const [selectedCollectionId, setSelectedCollectionId] = useState(\n () => collections[0]?.id ?? NEW_COLLECTION,\n );\n const [newCollectionName, setNewCollectionName] = useState('New Collection');\n\n const handleSave = async () => {\n setSaving(true);\n try {\n await collectionsStore.getState().actions.commitSaveDialog({\n name: name || 'Unnamed operation',\n description: description || undefined,\n collectionId:\n selectedCollectionId === NEW_COLLECTION\n ? undefined\n : selectedCollectionId,\n newCollectionName,\n });\n } catch {\n // The editor displays the rejected save; it retains the dirty state.\n } finally {\n setSaving(false);\n }\n };\n\n return (\n <>\n <Dialog.Header>Save to collection</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Save the current operation to a collection.\n </Dialog.Description>\n <form\n onSubmit={e => {\n e.preventDefault();\n void handleSave();\n }}\n >\n <Dialog.Body>\n <label className=\"graphiql-save-dialog-field\">\n <span>Operation name</span>\n <
|
|
1
|
+
{"version":3,"file":"save-dialog.js","names":["_jsx","_jsxs","_Fragment"],"sources":["../../src/components/save-dialog.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport { Button, Dialog, Input, Select } from '@graphiql/react';\nimport { useCollectionsStore, collectionsStore } from '../store';\n\nconst NEW_COLLECTION = '__new__';\n\n/**\n * The single \"Save to collection\" dialog. Its open state and the operation\n * being saved live in the collections store, so ⌘S and the save button can open\n * it imperatively via `requestSave`.\n */\nexport const SaveDialog: FC = () => {\n const { open, name, requestId } = useCollectionsStore(s => s.saveDialog);\n const closeSaveDialog = useCollectionsStore(s => s.actions.closeSaveDialog);\n\n return (\n <Dialog open={open} onOpenChange={o => !o && closeSaveDialog()}>\n {open && <SaveDialogForm key={requestId} initialName={name} />}\n </Dialog>\n );\n};\n\nconst SaveDialogForm: FC<{ initialName: string }> = ({ initialName }) => {\n const collections = useCollectionsStore(s => s.collections);\n const closeSaveDialog = useCollectionsStore(s => s.actions.closeSaveDialog);\n const [saving, setSaving] = useState(false);\n const [name, setName] = useState(initialName);\n const [description, setDescription] = useState('');\n const [selectedCollectionId, setSelectedCollectionId] = useState(\n () => collections[0]?.id ?? NEW_COLLECTION,\n );\n const [newCollectionName, setNewCollectionName] = useState('New Collection');\n\n const handleSave = async () => {\n setSaving(true);\n try {\n await collectionsStore.getState().actions.commitSaveDialog({\n name: name || 'Unnamed operation',\n description: description || undefined,\n collectionId:\n selectedCollectionId === NEW_COLLECTION\n ? undefined\n : selectedCollectionId,\n newCollectionName,\n });\n } catch {\n // The editor displays the rejected save; it retains the dirty state.\n } finally {\n setSaving(false);\n }\n };\n\n return (\n <>\n <Dialog.Header>Save to collection</Dialog.Header>\n <Dialog.Description className=\"graphiql-sr-only\">\n Save the current operation to a collection.\n </Dialog.Description>\n <form\n onSubmit={e => {\n e.preventDefault();\n void handleSave();\n }}\n >\n <Dialog.Body>\n <label className=\"graphiql-save-dialog-field\">\n <span>Operation name</span>\n <Input\n type=\"text\"\n value={name}\n onChange={e => setName(e.target.value)}\n placeholder=\"Unnamed operation\"\n autoFocus\n />\n </label>\n <label className=\"graphiql-save-dialog-field\">\n <span>Description</span>\n <Input\n type=\"text\"\n value={description}\n onChange={e => setDescription(e.target.value)}\n placeholder=\"Description (optional)\"\n />\n </label>\n <label className=\"graphiql-save-dialog-field\">\n <span>Collection</span>\n <Select\n value={selectedCollectionId}\n onChange={e => setSelectedCollectionId(e.target.value)}\n >\n <option value={NEW_COLLECTION}>+ New collection</option>\n {collections.map(c => (\n <option key={c.id} value={c.id}>\n {c.name}\n </option>\n ))}\n </Select>\n </label>\n {selectedCollectionId === NEW_COLLECTION && (\n <label className=\"graphiql-save-dialog-field\">\n <span>Collection name</span>\n <Input\n type=\"text\"\n value={newCollectionName}\n onChange={e => setNewCollectionName(e.target.value)}\n placeholder=\"Collection name\"\n />\n </label>\n )}\n </Dialog.Body>\n <Dialog.Footer>\n <Button type=\"button\" disabled={saving} onClick={closeSaveDialog}>\n Cancel\n </Button>\n <Button type=\"submit\" variant=\"primary\" disabled={saving}>\n {saving ? 'Saving…' : 'Save'}\n </Button>\n </Dialog.Footer>\n </form>\n </>\n );\n};\n"],"mappings":";;;;;AAIA,IAAM,iBAAiB;;;;;;AAOvB,IAAa,mBAAuB;CAClC,MAAM,EAAE,MAAM,MAAM,cAAc,qBAAoB,MAAK,EAAE,UAAU;CACvE,MAAM,kBAAkB,qBAAoB,MAAK,EAAE,QAAQ,eAAe;CAE1E,OACEA,oBAAC,QAAD;EAAc;EAAM,eAAc,MAAK,CAAC,KAAK,gBAAgB;EAC1D,UAAA,QAAQA,oBAAC,gBAAD,EAAgC,aAAa,KAAO,GAA/B,SAA+B;CACvD,CAAA;AAEZ;AAEA,IAAM,kBAA+C,EAAE,kBAAkB;CACvE,MAAM,cAAc,qBAAoB,MAAK,EAAE,WAAW;CAC1D,MAAM,kBAAkB,qBAAoB,MAAK,EAAE,QAAQ,eAAe;CAC1E,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;CAC1C,MAAM,CAAC,MAAM,WAAW,SAAS,WAAW;CAC5C,MAAM,CAAC,aAAa,kBAAkB,SAAS,EAAE;CACjD,MAAM,CAAC,sBAAsB,2BAA2B,eAChD,YAAY,EAAE,EAA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AA;MAAwB,CAAA,GACtD,YAAY,KAAI,MACfA,oBAAC,UAAD;OAAmB,OAAO,EAAE;OACzB,UAAA,EAAE;MACG,GAFK,EAAE,EAEP,CACT,CACK;KACH,CAAA,CAAA;;IACN,yBAAyB,kBACxBC,qBAAC,SAAD;KAAO,WAAU;KAAjB,UAAA,CACED,oBAAC,QAAD,EAAA,UAAM,kBAAqB,CAAA,GAC3BA,oBAAC,OAAD;MACE,MAAK;MACL,OAAO;MACP,WAAU,MAAK,qBAAqB,EAAE,OAAO,KAAK;MAClD,aAAY;KACb,CAAA,CACI;;GAEE,EAAA,CAAA,GACbC,qBAAC,OAAO,QAAR,EAAA,UAAA,CACED,oBAAC,QAAD;IAAQ,MAAK;IAAS,UAAU;IAAQ,SAAS;IAAiB,UAAA;GAE1D,CAAA,GACRA,oBAAC,QAAD;IAAQ,MAAK;IAAS,SAAQ;IAAU,UAAU;IAC/C,UAAA,SAAS,YAAY;GAChB,CAAA,CACK,EAAA,CAAA,CACX;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useGraphiQLActions } from "@graphiql/react";
|
|
1
3
|
import { collectionsStore } from "../store.js";
|
|
2
4
|
import { localStorageAdapter } from "../storage/local-storage.js";
|
|
3
5
|
import { SaveDialog } from "./save-dialog.js";
|
|
4
|
-
import { useEffect } from "react";
|
|
5
|
-
import { useGraphiQLActions } from "@graphiql/react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
// src/components/session-actions.tsx
|
|
8
8
|
var CollectionsSessionActions = ({ storage, readOnly = false, allowImportExport = true, allowReplace = true }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-actions.js","names":[],"sources":["../../src/components/session-actions.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useGraphiQLActions } from '@graphiql/react';\nimport { collectionsStore } from '../store';\nimport { localStorageAdapter } from '../storage/local-storage';\nimport { SaveDialog } from './save-dialog';\nimport type { CollectionsStorage } from '../types';\n\ntype CollectionsSessionActionsProps = {\n storage?: CollectionsStorage;\n readOnly?: boolean;\n allowImportExport?: boolean;\n allowReplace?: boolean;\n};\n\nexport const CollectionsSessionActions = ({\n storage,\n readOnly = false,\n allowImportExport = true,\n allowReplace = true,\n}: CollectionsSessionActionsProps) => {\n useEffect(() => {\n void collectionsStore\n .getState()\n .actions.init(storage ?? localStorageAdapter, {\n readOnly,\n allowImportExport,\n allowReplace,\n });\n // storage/config are intentionally only read on mount\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const { registerSaveHandler } = useGraphiQLActions();\n\n useEffect(() => {\n if (readOnly) {\n return;\n }\n return registerSaveHandler(tab =>\n collectionsStore.getState().actions.requestSave(tab),\n );\n }, [readOnly, registerSaveHandler]);\n\n return <SaveDialog />;\n};\n"],"mappings":";;;;;;;AAcA,IAAa,6BAA6B,EACxC,SACA,WAAW,OACX,oBAAoB,MACpB,eAAe,WACqB;CACpC,gBAAgB;
|
|
1
|
+
{"version":3,"file":"session-actions.js","names":["_jsx"],"sources":["../../src/components/session-actions.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useGraphiQLActions } from '@graphiql/react';\nimport { collectionsStore } from '../store';\nimport { localStorageAdapter } from '../storage/local-storage';\nimport { SaveDialog } from './save-dialog';\nimport type { CollectionsStorage } from '../types';\n\ntype CollectionsSessionActionsProps = {\n storage?: CollectionsStorage;\n readOnly?: boolean;\n allowImportExport?: boolean;\n allowReplace?: boolean;\n};\n\nexport const CollectionsSessionActions = ({\n storage,\n readOnly = false,\n allowImportExport = true,\n allowReplace = true,\n}: CollectionsSessionActionsProps) => {\n useEffect(() => {\n void collectionsStore\n .getState()\n .actions.init(storage ?? localStorageAdapter, {\n readOnly,\n allowImportExport,\n allowReplace,\n });\n // storage/config are intentionally only read on mount\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const { registerSaveHandler } = useGraphiQLActions();\n\n useEffect(() => {\n if (readOnly) {\n return;\n }\n return registerSaveHandler(tab =>\n collectionsStore.getState().actions.requestSave(tab),\n );\n }, [readOnly, registerSaveHandler]);\n\n return <SaveDialog />;\n};\n"],"mappings":";;;;;;;AAcA,IAAa,6BAA6B,EACxC,SACA,WAAW,OACX,oBAAoB,MACpB,eAAe,WACqB;CACpC,gBAAgB;EACT,iBACF,SAAS,CAAC,CACV,QAAQ,KAAK,WAAW,qBAAqB;GAC5C;GACA;GACA;EACF,CAAC;CAGL,GAAG,CAAC,CAAC;CAEL,MAAM,EAAE,wBAAwB,mBAAmB;CAEnD,gBAAgB;EACd,IAAI,UACF;EAEF,OAAO,qBAAoB,QACzB,iBAAiB,SAAS,CAAC,CAAC,QAAQ,YAAY,GAAG,CACrD;CACF,GAAG,CAAC,UAAU,mBAAmB,CAAC;CAElC,OAAOA,oBAAC,YAAD,CAAa,CAAA;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","names":["_jsxs","_jsx"],"sources":["../../src/icons/check.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgCheck = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tviewBox: \"0 0 16 16\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", {\n\t\tstroke: \"currentColor\",\n\t\tstrokeLinecap: \"round\",\n\t\tstrokeLinejoin: \"round\",\n\t\tstrokeWidth: 1.75,\n\t\td: \"m3.5 8.5 3 3 6-7\"\n\t})]\n});\nexport default SvgCheck;\n"],"mappings":";;;AAEA,IAAM,YAAY,EAAE,OAAO,SAAS,GAAG,YAA4BA,qBAAM,OAAO;CAC/E,OAAO;CACP,MAAM;CACN,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwBC,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsBA,oBAAK,QAAQ;EACvC,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,aAAa;EACb,GAAG;CACJ,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","names":["_jsxs","_jsx"],"sources":["../../src/icons/collections.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgCollections = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z\" })]\n});\nexport default SvgCollections;\n"],"mappings":";;;AAEA,IAAM,kBAAkB,EAAE,OAAO,SAAS,GAAG,YAA4BA,qBAAM,OAAO;CACrF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwBC,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsBA,oBAAK,QAAQ,EAAE,GAAG,8EAA8E,CAAC,CAAC;AAC9H,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","names":["_jsxs","_jsx"],"sources":["../../src/icons/download.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgDownload = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M12 3v11m-5-4 5 4 5-4M4 20h16\" })]\n});\nexport default SvgDownload;\n"],"mappings":";;;AAEA,IAAM,eAAe,EAAE,OAAO,SAAS,GAAG,YAA4BA,qBAAM,OAAO;CAClF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwBC,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsBA,oBAAK,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","names":["_jsxs","_jsx"],"sources":["../../src/icons/upload.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgUpload = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M12 21V10m-5 4 5-4 5 4M4 4h16\" })]\n});\nexport default SvgUpload;\n"],"mappings":";;;AAEA,IAAM,aAAa,EAAE,OAAO,SAAS,GAAG,YAA4BA,qBAAM,OAAO;CAChF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwBC,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsBA,oBAAK,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC;AAChF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CollectionsPanel } from "./components/collections-panel.js";
|
|
2
2
|
import { CollectionsSessionActions } from "./components/session-actions.js";
|
|
3
|
-
import SvgCollections from "./icons/collections.
|
|
3
|
+
import SvgCollections from "./icons/collections.js";
|
|
4
4
|
/* empty css */
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { collectionsStore, useCollectionsStore } from "./store.js";
|
|
6
7
|
import { createLocalStorageAdapter, localStorageAdapter } from "./storage/local-storage.js";
|
|
7
8
|
import { SaveDialog } from "./components/save-dialog.js";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
// src/index.tsx
|
|
10
10
|
var collectionsPlugin = (options) => {
|
|
11
11
|
function CollectionsPanelWithOptions() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["CollectionsIcon"],"sources":["../src/index.tsx"],"sourcesContent":["import type { GraphiQLPlugin } from '@graphiql/react';\nimport { CollectionsPanel } from './components/collections-panel';\nimport { CollectionsSessionActions } from './components/session-actions';\nimport CollectionsIcon from './icons/collections.svg?react';\nimport type { CollectionsStorage } from './types';\nimport './index.css';\n\nexport type {\n CollectionsStorage,\n CollectionsConfig,\n Collection,\n CollectionItem,\n} from './types';\nexport {\n collectionsStore,\n useCollectionsStore,\n type ActiveOperation,\n} from './store';\nexport {\n createLocalStorageAdapter,\n localStorageAdapter,\n} from './storage/local-storage';\nexport { SaveDialog as CollectionsSaveDialog } from './components/save-dialog';\n\nexport type CollectionsPluginOptions = {\n /** Custom storage adapter. Defaults to localStorage with key 'graphiql:collections'. */\n storage?: CollectionsStorage;\n /** Disable all write operations (export & copy still allowed). Default false. */\n readOnly?: boolean;\n /** Master switch for the import/export feature. Default true. */\n allowImportExport?: boolean;\n /** Allow the destructive \"Replace\" import option. Default true. */\n allowReplace?: boolean;\n};\n\nexport const collectionsPlugin = (\n options?: CollectionsPluginOptions,\n): GraphiQLPlugin => {\n function CollectionsPanelWithOptions() {\n return (\n <CollectionsPanel\n readOnly={options?.readOnly}\n allowImportExport={options?.allowImportExport}\n allowReplace={options?.allowReplace}\n />\n );\n }\n function CollectionsSessionActionsWithOptions() {\n return (\n <CollectionsSessionActions\n storage={options?.storage}\n readOnly={options?.readOnly}\n allowImportExport={options?.allowImportExport}\n allowReplace={options?.allowReplace}\n />\n );\n }\n return {\n title: 'Collections',\n icon: CollectionsIcon,\n content: CollectionsPanelWithOptions,\n sessionActions: CollectionsSessionActionsWithOptions,\n };\n};\n\nexport const COLLECTIONS_PLUGIN = collectionsPlugin();\n"],"mappings":";;;;;;;;;AAmCA,IAAa,qBACX,YACmB;CACnB,SAAS,8BAA8B;EACrC,
|
|
1
|
+
{"version":3,"file":"index.js","names":["_jsx","CollectionsIcon"],"sources":["../src/index.tsx"],"sourcesContent":["import type { GraphiQLPlugin } from '@graphiql/react';\nimport { CollectionsPanel } from './components/collections-panel';\nimport { CollectionsSessionActions } from './components/session-actions';\nimport CollectionsIcon from './icons/collections.svg?react';\nimport type { CollectionsStorage } from './types';\nimport './index.css';\n\nexport type {\n CollectionsStorage,\n CollectionsConfig,\n Collection,\n CollectionItem,\n} from './types';\nexport {\n collectionsStore,\n useCollectionsStore,\n type ActiveOperation,\n} from './store';\nexport {\n createLocalStorageAdapter,\n localStorageAdapter,\n} from './storage/local-storage';\nexport { SaveDialog as CollectionsSaveDialog } from './components/save-dialog';\n\nexport type CollectionsPluginOptions = {\n /** Custom storage adapter. Defaults to localStorage with key 'graphiql:collections'. */\n storage?: CollectionsStorage;\n /** Disable all write operations (export & copy still allowed). Default false. */\n readOnly?: boolean;\n /** Master switch for the import/export feature. Default true. */\n allowImportExport?: boolean;\n /** Allow the destructive \"Replace\" import option. Default true. */\n allowReplace?: boolean;\n};\n\nexport const collectionsPlugin = (\n options?: CollectionsPluginOptions,\n): GraphiQLPlugin => {\n function CollectionsPanelWithOptions() {\n return (\n <CollectionsPanel\n readOnly={options?.readOnly}\n allowImportExport={options?.allowImportExport}\n allowReplace={options?.allowReplace}\n />\n );\n }\n function CollectionsSessionActionsWithOptions() {\n return (\n <CollectionsSessionActions\n storage={options?.storage}\n readOnly={options?.readOnly}\n allowImportExport={options?.allowImportExport}\n allowReplace={options?.allowReplace}\n />\n );\n }\n return {\n title: 'Collections',\n icon: CollectionsIcon,\n content: CollectionsPanelWithOptions,\n sessionActions: CollectionsSessionActionsWithOptions,\n };\n};\n\nexport const COLLECTIONS_PLUGIN = collectionsPlugin();\n"],"mappings":";;;;;;;;;AAmCA,IAAa,qBACX,YACmB;CACnB,SAAS,8BAA8B;EACrC,OACEA,oBAAC,kBAAD;GACE,UAAU,SAAS;GACnB,mBAAmB,SAAS;GAC5B,cAAc,SAAS;EACxB,CAAA;CAEL;CACA,SAAS,uCAAuC;EAC9C,OACEA,oBAAC,2BAAD;GACE,SAAS,SAAS;GAClB,UAAU,SAAS;GACnB,mBAAmB,SAAS;GAC5B,cAAc,SAAS;EACxB,CAAA;CAEL;CACA,OAAO;EACL,OAAO;EACP,MAAMC;EACN,SAAS;EACT,gBAAgB;CAClB;AACF;AAEA,IAAa,qBAAqB,kBAAkB"}
|
package/dist/store.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { createStore } from "zustand";
|
|
2
|
+
import { createBoundedUseStore } from "@graphiql/react";
|
|
3
|
+
import { z } from "zod";
|
|
1
4
|
import { randomId } from "./utility/uuid.js";
|
|
2
5
|
import { DEFAULT_COLLECTIONS_CONFIG } from "./types.js";
|
|
3
6
|
import { localStorageAdapter } from "./storage/local-storage.js";
|
|
4
7
|
import { loadTabLinks, saveTabLinks } from "./storage/tab-links.js";
|
|
5
|
-
import { createBoundedUseStore } from "@graphiql/react";
|
|
6
|
-
import { createStore } from "zustand";
|
|
7
|
-
import { z } from "zod";
|
|
8
8
|
// src/store.ts
|
|
9
9
|
var INITIAL_SAVE_DIALOG = {
|
|
10
10
|
open: false,
|
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 /** 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;CAC3C,MAAM;CACN,WAAW;CACX,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,CAAC;CACvC,KAAK,MAAM,CAAC,OAAO,SAAS,OAAO,QAAQ,KAAK,GAC9C,IAAI,CAAC,QAAQ,IAAI,KAAK,MAAM,GAC1B,KAAK,SAAS;CAGlB,OAAO;AACT;;AAGA,IAAM,QAAQ,MAAkC,KAAK;;AAGrD,SAAS,iBAAiB,GAAmB,GAA4B;CACvE,OACE,EAAE,SAAS,EAAE,QACb,KAAK,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,KAC9B,KAAK,EAAE,S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C,OAAO,CAAC,IAAI;OACZ,WAAW;OACX,WAAW;MACb,CACF;MACJ,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI;MAC7B,IAAI,EAAE,aAAa,KAAK,CAAC;KAC3B,CAAC;KACD,IAAI,WAAW,OACb,IAAI,CAAC,CAAC,QAAQ,QAAQ,WAAW,OAAO,cAAc,KAAK,EAAE;KAE/D,eAAe,QAAQ,IAAI;KAC3B,gBAAgB,KAAA;KAChB,mBAAmB;KACnB,IAAI,CAAC,CAAC,QAAQ,gBAAgB;IAChC,SAAS,OAAO;KACd,eAAe,OAAO,KAAK;KAC3B,gBAAgB,KAAA;KAChB,mBAAmB;KACnB,IAAI,CAAC,CAAC,QAAQ,gBAAgB;KAC9B,MAAM;IACR;GACF;GACA,eAAe,OAAO;IACpB,KAAI,OAAM,EACR,YAAY;KACV,GAAG;KACH,MAAM;KACN,YAAY,EAAE,WAAW,aAAa,KAAK;IAC7C,EACF,EAAE;GACJ;GACA,kBAAkB;IAChB,IAAI,kBACF;IAEF,eAAe,QAAQ,KAAK;IAC5B,gBAAgB,KAAA;IAChB,KAAI,OAAM,EAAE,YAAY;KAAE,GAAG,EAAE;KAAY,MAAM;IAAM,EAAE,EAAE;GAC7D;EACF;CACF;AACF,CAAC;AAED,IAAa,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 /** 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;CAC3C,MAAM;CACN,WAAW;CACX,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,CAAC;CACvC,KAAK,MAAM,CAAC,OAAO,SAAS,OAAO,QAAQ,KAAK,GAC9C,IAAI,CAAC,QAAQ,IAAI,KAAK,MAAM,GAC1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I,CAAC,CAAC,YAAY,KAAI,MACpB,EAAE,OAAO,eACL;OAAE,GAAG;OAAG,OAAO,CAAC,GAAG,EAAE,OAAO,IAAI;OAAG,WAAW;MAAI,IAClD,CACN,IACA,CACE,GAAG,IAAI,CAAC,CAAC,aACT;OACE,IAAI;OACJ,MAAM,MAAM,qBAAqB;OACjC,OAAO,CAAC,IAAI;OACZ,WAAW;OACX,WAAW;MACb,CACF;MACJ,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI;MAC7B,IAAI,EAAE,aAAa,KAAK,CAAC;KAC3B,CAAC;KACD,IAAI,WAAW,OACb,IAAI,CAAC,CAAC,QAAQ,QAAQ,WAAW,OAAO,cAAc,KAAK,EAAE;KAE/D,eAAe,QAAQ,IAAI;KAC3B,gBAAgB,KAAA;KAChB,mBAAmB;KACnB,IAAI,CAAC,CAAC,QAAQ,gBAAgB;IAChC,SAAS,OAAO;KACd,eAAe,OAAO,KAAK;KAC3B,gBAAgB,KAAA;KAChB,mBAAmB;KACnB,IAAI,CAAC,CAAC,QAAQ,gBAAgB;KAC9B,MAAM;IACR;GACF;GACA,eAAe,OAAO;IACpB,KAAI,OAAM,EACR,YAAY;KACV,GAAG;KACH,MAAM;KACN,YAAY,EAAE,WAAW,aAAa,KAAK;IAC7C,EACF,EAAE;GACJ;GACA,kBAAkB;IAChB,IAAI,kBACF;IAEF,eAAe,QAAQ,KAAK;IAC5B,gBAAgB,KAAA;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)
|
|
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)
|
|
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)
|
|
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)
|
|
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-
|
|
116
|
-
|
|
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-
|
|
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)
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-collections",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
"zustand": "^5"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@graphiql/react": "^1.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
|
|
46
|
-
"@storybook/react-vite": "^10.
|
|
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": "^
|
|
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
52
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
53
|
-
"@vitejs/plugin-react": "^6.
|
|
54
|
-
"graphql": "^17.0
|
|
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.
|
|
57
|
+
"vite": "^8.4.0",
|
|
58
58
|
"vite-plugin-dts": "^5.1.2",
|
|
59
59
|
"vite-plugin-svgr": "^5.2.0",
|
|
60
60
|
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.svg_react.js","names":[],"sources":["../../src/icons/check.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgCheck = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tviewBox: \"0 0 16 16\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", {\n\t\tstroke: \"currentColor\",\n\t\tstrokeLinecap: \"round\",\n\t\tstrokeLinejoin: \"round\",\n\t\tstrokeWidth: 1.75,\n\t\td: \"m3.5 8.5 3 3 6-7\"\n\t})]\n});\nexport default SvgCheck;\n"],"mappings":";;;AAEA,IAAM,YAAY,EAAE,OAAO,SAAS,GAAG,YAA4B,qBAAM,OAAO;CAC/E,OAAO;CACP,MAAM;CACN,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwB,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsB,oBAAK,QAAQ;EACvC,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,aAAa;EACb,GAAG;CACJ,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.svg_react.js","names":[],"sources":["../../src/icons/collections.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgCollections = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z\" })]\n});\nexport default SvgCollections;\n"],"mappings":";;;AAEA,IAAM,kBAAkB,EAAE,OAAO,SAAS,GAAG,YAA4B,qBAAM,OAAO;CACrF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwB,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsB,oBAAK,QAAQ,EAAE,GAAG,8EAA8E,CAAC,CAAC;AAC9H,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.svg_react.js","names":[],"sources":["../../src/icons/download.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgDownload = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M12 3v11m-5-4 5 4 5-4M4 20h16\" })]\n});\nexport default SvgDownload;\n"],"mappings":";;;AAEA,IAAM,eAAe,EAAE,OAAO,SAAS,GAAG,YAA4B,qBAAM,OAAO;CAClF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwB,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsB,oBAAK,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload.svg_react.js","names":[],"sources":["../../src/icons/upload.svg?react"],"sourcesContent":["import * as React from \"react\";\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst SvgUpload = ({ title, titleId, ...props }) => /* @__PURE__ */ _jsxs(\"svg\", {\n\txmlns: \"http://www.w3.org/2000/svg\",\n\tfill: \"none\",\n\tstroke: \"currentColor\",\n\tstrokeLinecap: \"round\",\n\tstrokeLinejoin: \"round\",\n\tstrokeWidth: 2,\n\tviewBox: \"0 0 24 24\",\n\t\"aria-labelledby\": titleId,\n\t...props,\n\tchildren: [title ? /* @__PURE__ */ _jsx(\"title\", {\n\t\tid: titleId,\n\t\tchildren: title\n\t}) : null, /* @__PURE__ */ _jsx(\"path\", { d: \"M12 21V10m-5 4 5-4 5 4M4 4h16\" })]\n});\nexport default SvgUpload;\n"],"mappings":";;;AAEA,IAAM,aAAa,EAAE,OAAO,SAAS,GAAG,YAA4B,qBAAM,OAAO;CAChF,OAAO;CACP,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;CACT,mBAAmB;CACnB,GAAG;CACH,UAAU,CAAC,QAAwB,oBAAK,SAAS;EAChD,IAAI;EACJ,UAAU;CACX,CAAC,IAAI,MAAsB,oBAAK,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC;AAChF,CAAC"}
|