@graphiql/plugin-collections 1.0.0-rc.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { collectionsStore, useCollectionsStore } from "../store.js";
2
2
  import { useEffect, useState } from "react";
3
- import { Button, Dialog, useGraphiQLActions } from "@graphiql/react";
3
+ import { Button, Dialog } from "@graphiql/react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  //#region src/components/save-dialog.tsx
6
6
  var NEW_COLLECTION = "__new__";
@@ -13,7 +13,7 @@ var SaveDialog = () => {
13
13
  const collections = useCollectionsStore((s) => s.collections);
14
14
  const actions = useCollectionsStore((s) => s.actions);
15
15
  const { open, name: initialName } = useCollectionsStore((s) => s.saveDialog);
16
- const { markTabSaved } = useGraphiQLActions();
16
+ const [saving, setSaving] = useState(false);
17
17
  const [name, setName] = useState(initialName);
18
18
  const [description, setDescription] = useState("");
19
19
  const [selectedCollectionId, setSelectedCollectionId] = useState(NEW_COLLECTION);
@@ -25,90 +25,96 @@ var SaveDialog = () => {
25
25
  setDescription("");
26
26
  setSelectedCollectionId(current[0]?.id ?? NEW_COLLECTION);
27
27
  setNewCollectionName("New Collection");
28
+ setSaving(false);
28
29
  }
29
30
  }, [open, initialName]);
30
- const handleSave = () => {
31
- const { saveDialog, actions: a } = collectionsStore.getState();
32
- let collectionId = selectedCollectionId;
33
- if (selectedCollectionId === NEW_COLLECTION) collectionId = a.createCollection(newCollectionName || "New Collection").id;
34
- const item = a.addItem(collectionId, {
35
- name: name || "Unnamed operation",
36
- description: description || void 0,
37
- query: saveDialog.query,
38
- variables: saveDialog.variables,
39
- headers: saveDialog.headers
40
- });
41
- if (saveDialog.tabId) {
42
- a.linkTab(saveDialog.tabId, collectionId, item.id);
43
- markTabSaved(saveDialog.tabId);
31
+ const handleSave = async () => {
32
+ setSaving(true);
33
+ try {
34
+ await collectionsStore.getState().actions.commitSaveDialog({
35
+ name: name || "Unnamed operation",
36
+ description: description || void 0,
37
+ collectionId: selectedCollectionId === NEW_COLLECTION ? void 0 : selectedCollectionId,
38
+ newCollectionName
39
+ });
40
+ } catch {} finally {
41
+ setSaving(false);
44
42
  }
45
- a.closeSaveDialog();
46
43
  };
47
44
  return /* @__PURE__ */ jsxs(Dialog, {
48
45
  open,
49
46
  onOpenChange: (o) => !o && actions.closeSaveDialog(),
50
- children: [/* @__PURE__ */ jsx(Dialog.Header, { children: "Save to collection" }), /* @__PURE__ */ jsxs("form", {
51
- onSubmit: (e) => {
52
- e.preventDefault();
53
- handleSave();
54
- },
55
- children: [/* @__PURE__ */ jsxs(Dialog.Body, { children: [
56
- /* @__PURE__ */ jsxs("label", {
57
- className: "graphiql-save-dialog-field",
58
- children: [/* @__PURE__ */ jsx("span", { children: "Operation name" }), /* @__PURE__ */ jsx("input", {
59
- type: "text",
60
- value: name,
61
- onChange: (e) => setName(e.target.value),
62
- placeholder: "Unnamed operation",
63
- className: "graphiql-save-dialog-input",
64
- autoFocus: true
65
- })]
66
- }),
67
- /* @__PURE__ */ jsxs("label", {
68
- className: "graphiql-save-dialog-field",
69
- children: [/* @__PURE__ */ jsx("span", { children: "Description" }), /* @__PURE__ */ jsx("input", {
70
- type: "text",
71
- value: description,
72
- onChange: (e) => setDescription(e.target.value),
73
- placeholder: "Description (optional)",
74
- className: "graphiql-save-dialog-input"
75
- })]
76
- }),
77
- /* @__PURE__ */ jsxs("label", {
78
- className: "graphiql-save-dialog-field",
79
- children: [/* @__PURE__ */ jsx("span", { children: "Collection" }), /* @__PURE__ */ jsxs("select", {
80
- value: selectedCollectionId,
81
- onChange: (e) => setSelectedCollectionId(e.target.value),
82
- className: "graphiql-save-dialog-select",
83
- children: [/* @__PURE__ */ jsx("option", {
84
- value: NEW_COLLECTION,
85
- children: "+ New collection"
86
- }), collections.map((c) => /* @__PURE__ */ jsx("option", {
87
- value: c.id,
88
- children: c.name
89
- }, c.id))]
90
- })]
91
- }),
92
- selectedCollectionId === NEW_COLLECTION && /* @__PURE__ */ jsxs("label", {
93
- className: "graphiql-save-dialog-field",
94
- children: [/* @__PURE__ */ jsx("span", { children: "Collection name" }), /* @__PURE__ */ jsx("input", {
95
- type: "text",
96
- value: newCollectionName,
97
- onChange: (e) => setNewCollectionName(e.target.value),
98
- placeholder: "Collection name",
99
- className: "graphiql-save-dialog-input"
100
- })]
101
- })
102
- ] }), /* @__PURE__ */ jsxs(Dialog.Footer, { children: [/* @__PURE__ */ jsx(Button, {
103
- type: "button",
104
- onClick: () => actions.closeSaveDialog(),
105
- children: "Cancel"
106
- }), /* @__PURE__ */ jsx(Button, {
107
- type: "submit",
108
- variant: "primary",
109
- children: "Save"
110
- })] })]
111
- })]
47
+ children: [
48
+ /* @__PURE__ */ jsx(Dialog.Header, { children: "Save to collection" }),
49
+ /* @__PURE__ */ jsx(Dialog.Description, {
50
+ className: "graphiql-sr-only",
51
+ children: "Save the current operation to a collection."
52
+ }),
53
+ /* @__PURE__ */ jsxs("form", {
54
+ onSubmit: (e) => {
55
+ e.preventDefault();
56
+ handleSave();
57
+ },
58
+ children: [/* @__PURE__ */ jsxs(Dialog.Body, { children: [
59
+ /* @__PURE__ */ jsxs("label", {
60
+ className: "graphiql-save-dialog-field",
61
+ children: [/* @__PURE__ */ jsx("span", { children: "Operation name" }), /* @__PURE__ */ jsx("input", {
62
+ type: "text",
63
+ value: name,
64
+ onChange: (e) => setName(e.target.value),
65
+ placeholder: "Unnamed operation",
66
+ className: "graphiql-save-dialog-input",
67
+ autoFocus: true
68
+ })]
69
+ }),
70
+ /* @__PURE__ */ jsxs("label", {
71
+ className: "graphiql-save-dialog-field",
72
+ children: [/* @__PURE__ */ jsx("span", { children: "Description" }), /* @__PURE__ */ jsx("input", {
73
+ type: "text",
74
+ value: description,
75
+ onChange: (e) => setDescription(e.target.value),
76
+ placeholder: "Description (optional)",
77
+ className: "graphiql-save-dialog-input"
78
+ })]
79
+ }),
80
+ /* @__PURE__ */ jsxs("label", {
81
+ className: "graphiql-save-dialog-field",
82
+ children: [/* @__PURE__ */ jsx("span", { children: "Collection" }), /* @__PURE__ */ jsxs("select", {
83
+ value: selectedCollectionId,
84
+ onChange: (e) => setSelectedCollectionId(e.target.value),
85
+ className: "graphiql-save-dialog-select",
86
+ children: [/* @__PURE__ */ jsx("option", {
87
+ value: NEW_COLLECTION,
88
+ children: "+ New collection"
89
+ }), collections.map((c) => /* @__PURE__ */ jsx("option", {
90
+ value: c.id,
91
+ children: c.name
92
+ }, c.id))]
93
+ })]
94
+ }),
95
+ selectedCollectionId === NEW_COLLECTION && /* @__PURE__ */ jsxs("label", {
96
+ className: "graphiql-save-dialog-field",
97
+ children: [/* @__PURE__ */ jsx("span", { children: "Collection name" }), /* @__PURE__ */ jsx("input", {
98
+ type: "text",
99
+ value: newCollectionName,
100
+ onChange: (e) => setNewCollectionName(e.target.value),
101
+ placeholder: "Collection name",
102
+ className: "graphiql-save-dialog-input"
103
+ })]
104
+ })
105
+ ] }), /* @__PURE__ */ jsxs(Dialog.Footer, { children: [/* @__PURE__ */ jsx(Button, {
106
+ type: "button",
107
+ disabled: saving,
108
+ onClick: () => actions.closeSaveDialog(),
109
+ children: "Cancel"
110
+ }), /* @__PURE__ */ jsx(Button, {
111
+ type: "submit",
112
+ variant: "primary",
113
+ disabled: saving,
114
+ children: saving ? "Saving…" : "Save"
115
+ })] })]
116
+ })
117
+ ]
112
118
  });
113
119
  };
114
120
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"save-dialog.js","names":[],"sources":["../../src/components/save-dialog.tsx"],"sourcesContent":["import { FC, useEffect, useState } from 'react';\nimport { Button, Dialog, useGraphiQLActions } 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 collections = useCollectionsStore(s => s.collections);\n const actions = useCollectionsStore(s => s.actions);\n const { open, name: initialName } = useCollectionsStore(s => s.saveDialog);\n const { markTabSaved } = useGraphiQLActions();\n\n const [name, setName] = useState(initialName);\n const [description, setDescription] = useState('');\n const [selectedCollectionId, setSelectedCollectionId] =\n useState<string>(NEW_COLLECTION);\n const [newCollectionName, setNewCollectionName] = useState('New Collection');\n\n // Reset the form each time the dialog opens with a fresh operation.\n useEffect(() => {\n if (open) {\n const { collections: current } = collectionsStore.getState();\n setName(initialName);\n setDescription('');\n setSelectedCollectionId(current[0]?.id ?? NEW_COLLECTION);\n setNewCollectionName('New Collection');\n }\n }, [open, initialName]);\n\n const handleSave = () => {\n const { saveDialog, actions: a } = collectionsStore.getState();\n let collectionId = selectedCollectionId;\n if (selectedCollectionId === NEW_COLLECTION) {\n collectionId = a.createCollection(\n newCollectionName || 'New Collection',\n ).id;\n }\n const item = a.addItem(collectionId, {\n name: name || 'Unnamed operation',\n description: description || undefined,\n query: saveDialog.query,\n variables: saveDialog.variables,\n headers: saveDialog.headers,\n });\n if (saveDialog.tabId) {\n a.linkTab(saveDialog.tabId, collectionId, item.id);\n markTabSaved(saveDialog.tabId);\n }\n a.closeSaveDialog();\n };\n\n return (\n <Dialog open={open} onOpenChange={o => !o && actions.closeSaveDialog()}>\n <Dialog.Header>Save to collection</Dialog.Header>\n <form\n onSubmit={e => {\n e.preventDefault();\n 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 className=\"graphiql-save-dialog-input\"\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 className=\"graphiql-save-dialog-input\"\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 className=\"graphiql-save-dialog-select\"\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 className=\"graphiql-save-dialog-input\"\n />\n </label>\n )}\n </Dialog.Body>\n <Dialog.Footer>\n <Button type=\"button\" onClick={() => actions.closeSaveDialog()}>\n Cancel\n </Button>\n <Button type=\"submit\" variant=\"primary\">\n Save\n </Button>\n </Dialog.Footer>\n </form>\n </Dialog>\n );\n};\n"],"mappings":"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"}
1
+ {"version":3,"file":"save-dialog.js","names":[],"sources":["../../src/components/save-dialog.tsx"],"sourcesContent":["import { FC, useEffect, 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 collections = useCollectionsStore(s => s.collections);\n const actions = useCollectionsStore(s => s.actions);\n const { open, name: initialName } = useCollectionsStore(s => s.saveDialog);\n const [saving, setSaving] = useState(false);\n\n const [name, setName] = useState(initialName);\n const [description, setDescription] = useState('');\n const [selectedCollectionId, setSelectedCollectionId] =\n useState<string>(NEW_COLLECTION);\n const [newCollectionName, setNewCollectionName] = useState('New Collection');\n\n // Reset the form each time the dialog opens with a fresh operation.\n useEffect(() => {\n if (open) {\n const { collections: current } = collectionsStore.getState();\n setName(initialName);\n setDescription('');\n setSelectedCollectionId(current[0]?.id ?? NEW_COLLECTION);\n setNewCollectionName('New Collection');\n setSaving(false);\n }\n }, [open, initialName]);\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 <Dialog open={open} onOpenChange={o => !o && actions.closeSaveDialog()}>\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 className=\"graphiql-save-dialog-input\"\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 className=\"graphiql-save-dialog-input\"\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 className=\"graphiql-save-dialog-select\"\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 className=\"graphiql-save-dialog-input\"\n />\n </label>\n )}\n </Dialog.Body>\n <Dialog.Footer>\n <Button\n type=\"button\"\n disabled={saving}\n onClick={() => actions.closeSaveDialog()}\n >\n Cancel\n </Button>\n <Button type=\"submit\" variant=\"primary\" disabled={saving}>\n {saving ? 'Saving…' : 'Save'}\n </Button>\n </Dialog.Footer>\n </form>\n </Dialog>\n );\n};\n"],"mappings":"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"}
@@ -1,18 +1,23 @@
1
- import * as React from "react";
1
+ import "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
2
3
  //#region src/icons/check.svg?react
3
- var SvgCheck = ({ title, titleId, ...props }) => /* @__PURE__ */ React.createElement("svg", {
4
+ var SvgCheck = ({ title, titleId, ...props }) => /* @__PURE__ */ jsxs("svg", {
4
5
  xmlns: "http://www.w3.org/2000/svg",
5
6
  fill: "none",
6
7
  viewBox: "0 0 16 16",
7
8
  "aria-labelledby": titleId,
8
- ...props
9
- }, title ? /* @__PURE__ */ React.createElement("title", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement("path", {
10
- stroke: "currentColor",
11
- strokeLinecap: "round",
12
- strokeLinejoin: "round",
13
- strokeWidth: 1.75,
14
- d: "m3.5 8.5 3 3 6-7"
15
- }));
9
+ ...props,
10
+ children: [title ? /* @__PURE__ */ jsx("title", {
11
+ id: titleId,
12
+ children: title
13
+ }) : null, /* @__PURE__ */ jsx("path", {
14
+ stroke: "currentColor",
15
+ strokeLinecap: "round",
16
+ strokeLinejoin: "round",
17
+ strokeWidth: 1.75,
18
+ d: "m3.5 8.5 3 3 6-7"
19
+ })]
20
+ });
16
21
  //#endregion
17
22
  export { SvgCheck as default };
18
23
 
@@ -1 +1 @@
1
- {"version":3,"file":"check.js","names":[],"sources":["../../src/icons/check.svg?react"],"sourcesContent":["import * as React from \"react\";\nconst SvgCheck = ({\n title,\n titleId,\n ...props\n}) => /* @__PURE__ */ React.createElement(\"svg\", { xmlns: \"http://www.w3.org/2000/svg\", fill: \"none\", viewBox: \"0 0 16 16\", \"aria-labelledby\": titleId, ...props }, title ? /* @__PURE__ */ React.createElement(\"title\", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement(\"path\", { stroke: \"currentColor\", strokeLinecap: \"round\", strokeLinejoin: \"round\", strokeWidth: 1.75, d: \"m3.5 8.5 3 3 6-7\" }));\nexport default SvgCheck;\n"],"mappings":";;AACA,IAAM,YAAY,EAChB,OACA,SACA,GAAG,YACiB,sBAAM,cAAc,OAAO;CAAE,OAAO;CAA8B,MAAM;CAAQ,SAAS;CAAa,mBAAmB;CAAS,GAAG;AAAM,GAAG,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAQ,GAAG,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ;CAAE,QAAQ;CAAgB,eAAe;CAAS,gBAAgB;CAAS,aAAa;CAAM,GAAG;AAAmB,CAAC,CAAC"}
1
+ {"version":3,"file":"check.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,6 +1,7 @@
1
- import * as React from "react";
1
+ import "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
2
3
  //#region src/icons/collections.svg?react
3
- var SvgCollections = ({ title, titleId, ...props }) => /* @__PURE__ */ React.createElement("svg", {
4
+ var SvgCollections = ({ title, titleId, ...props }) => /* @__PURE__ */ jsxs("svg", {
4
5
  xmlns: "http://www.w3.org/2000/svg",
5
6
  fill: "none",
6
7
  stroke: "currentColor",
@@ -9,8 +10,12 @@ var SvgCollections = ({ title, titleId, ...props }) => /* @__PURE__ */ React.cre
9
10
  strokeWidth: 2,
10
11
  viewBox: "0 0 24 24",
11
12
  "aria-labelledby": titleId,
12
- ...props
13
- }, title ? /* @__PURE__ */ React.createElement("title", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement("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" }));
13
+ ...props,
14
+ children: [title ? /* @__PURE__ */ jsx("title", {
15
+ id: titleId,
16
+ children: title
17
+ }) : 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" })]
18
+ });
14
19
  //#endregion
15
20
  export { SvgCollections as default };
16
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"collections.js","names":[],"sources":["../../src/icons/collections.svg?react"],"sourcesContent":["import * as React from \"react\";\nconst SvgCollections = ({\n title,\n titleId,\n ...props\n}) => /* @__PURE__ */ React.createElement(\"svg\", { xmlns: \"http://www.w3.org/2000/svg\", fill: \"none\", stroke: \"currentColor\", strokeLinecap: \"round\", strokeLinejoin: \"round\", strokeWidth: 2, viewBox: \"0 0 24 24\", \"aria-labelledby\": titleId, ...props }, title ? /* @__PURE__ */ React.createElement(\"title\", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement(\"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\" }));\nexport default SvgCollections;\n"],"mappings":";;AACA,IAAM,kBAAkB,EACtB,OACA,SACA,GAAG,YACiB,sBAAM,cAAc,OAAO;CAAE,OAAO;CAA8B,MAAM;CAAQ,QAAQ;CAAgB,eAAe;CAAS,gBAAgB;CAAS,aAAa;CAAG,SAAS;CAAa,mBAAmB;CAAS,GAAG;AAAM,GAAG,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAQ,GAAG,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ,EAAE,GAAG,8EAA8E,CAAC,CAAC"}
1
+ {"version":3,"file":"collections.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,6 +1,7 @@
1
- import * as React from "react";
1
+ import "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
2
3
  //#region src/icons/download.svg?react
3
- var SvgDownload = ({ title, titleId, ...props }) => /* @__PURE__ */ React.createElement("svg", {
4
+ var SvgDownload = ({ title, titleId, ...props }) => /* @__PURE__ */ jsxs("svg", {
4
5
  xmlns: "http://www.w3.org/2000/svg",
5
6
  fill: "none",
6
7
  stroke: "currentColor",
@@ -9,8 +10,12 @@ var SvgDownload = ({ title, titleId, ...props }) => /* @__PURE__ */ React.create
9
10
  strokeWidth: 2,
10
11
  viewBox: "0 0 24 24",
11
12
  "aria-labelledby": titleId,
12
- ...props
13
- }, title ? /* @__PURE__ */ React.createElement("title", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement("path", { d: "M12 3v11m-5-4 5 4 5-4M4 20h16" }));
13
+ ...props,
14
+ children: [title ? /* @__PURE__ */ jsx("title", {
15
+ id: titleId,
16
+ children: title
17
+ }) : null, /* @__PURE__ */ jsx("path", { d: "M12 3v11m-5-4 5 4 5-4M4 20h16" })]
18
+ });
14
19
  //#endregion
15
20
  export { SvgDownload as default };
16
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"download.js","names":[],"sources":["../../src/icons/download.svg?react"],"sourcesContent":["import * as React from \"react\";\nconst SvgDownload = ({\n title,\n titleId,\n ...props\n}) => /* @__PURE__ */ React.createElement(\"svg\", { xmlns: \"http://www.w3.org/2000/svg\", fill: \"none\", stroke: \"currentColor\", strokeLinecap: \"round\", strokeLinejoin: \"round\", strokeWidth: 2, viewBox: \"0 0 24 24\", \"aria-labelledby\": titleId, ...props }, title ? /* @__PURE__ */ React.createElement(\"title\", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement(\"path\", { d: \"M12 3v11m-5-4 5 4 5-4M4 20h16\" }));\nexport default SvgDownload;\n"],"mappings":";;AACA,IAAM,eAAe,EACnB,OACA,SACA,GAAG,YACiB,sBAAM,cAAc,OAAO;CAAE,OAAO;CAA8B,MAAM;CAAQ,QAAQ;CAAgB,eAAe;CAAS,gBAAgB;CAAS,aAAa;CAAG,SAAS;CAAa,mBAAmB;CAAS,GAAG;AAAM,GAAG,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAQ,GAAG,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC"}
1
+ {"version":3,"file":"download.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,6 +1,7 @@
1
- import * as React from "react";
1
+ import "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
2
3
  //#region src/icons/upload.svg?react
3
- var SvgUpload = ({ title, titleId, ...props }) => /* @__PURE__ */ React.createElement("svg", {
4
+ var SvgUpload = ({ title, titleId, ...props }) => /* @__PURE__ */ jsxs("svg", {
4
5
  xmlns: "http://www.w3.org/2000/svg",
5
6
  fill: "none",
6
7
  stroke: "currentColor",
@@ -9,8 +10,12 @@ var SvgUpload = ({ title, titleId, ...props }) => /* @__PURE__ */ React.createEl
9
10
  strokeWidth: 2,
10
11
  viewBox: "0 0 24 24",
11
12
  "aria-labelledby": titleId,
12
- ...props
13
- }, title ? /* @__PURE__ */ React.createElement("title", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement("path", { d: "M12 21V10m-5 4 5-4 5 4M4 4h16" }));
13
+ ...props,
14
+ children: [title ? /* @__PURE__ */ jsx("title", {
15
+ id: titleId,
16
+ children: title
17
+ }) : null, /* @__PURE__ */ jsx("path", { d: "M12 21V10m-5 4 5-4 5 4M4 4h16" })]
18
+ });
14
19
  //#endregion
15
20
  export { SvgUpload as default };
16
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"upload.js","names":[],"sources":["../../src/icons/upload.svg?react"],"sourcesContent":["import * as React from \"react\";\nconst SvgUpload = ({\n title,\n titleId,\n ...props\n}) => /* @__PURE__ */ React.createElement(\"svg\", { xmlns: \"http://www.w3.org/2000/svg\", fill: \"none\", stroke: \"currentColor\", strokeLinecap: \"round\", strokeLinejoin: \"round\", strokeWidth: 2, viewBox: \"0 0 24 24\", \"aria-labelledby\": titleId, ...props }, title ? /* @__PURE__ */ React.createElement(\"title\", { id: titleId }, title) : null, /* @__PURE__ */ React.createElement(\"path\", { d: \"M12 21V10m-5 4 5-4 5 4M4 4h16\" }));\nexport default SvgUpload;\n"],"mappings":";;AACA,IAAM,aAAa,EACjB,OACA,SACA,GAAG,YACiB,sBAAM,cAAc,OAAO;CAAE,OAAO;CAA8B,MAAM;CAAQ,QAAQ;CAAgB,eAAe;CAAS,gBAAgB;CAAS,aAAa;CAAG,SAAS;CAAa,mBAAmB;CAAS,GAAG;AAAM,GAAG,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAQ,GAAG,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ,EAAE,GAAG,gCAAgC,CAAC,CAAC"}
1
+ {"version":3,"file":"upload.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"}
package/dist/store.d.ts CHANGED
@@ -58,11 +58,16 @@ type CollectionsActions = {
58
58
  linkTab(tabId: string, collectionId: string, itemId: string): void;
59
59
  /**
60
60
  * Save the active operation: update the linked item in place if the tab is
61
- * already tied to a collection item, otherwise open the save dialog. Returns
62
- * `true` when it saved in place (so the caller can clear the dirty state),
63
- * `false` when it opened the dialog instead.
61
+ * already tied to a collection item, otherwise open the save dialog. The
62
+ * returned promise settles after storage commits or the dialog is cancelled.
64
63
  */
65
- requestSave(operation: ActiveOperation): boolean;
64
+ requestSave(operation: ActiveOperation): Promise<boolean>;
65
+ commitSaveDialog(input: {
66
+ name: string;
67
+ description?: string;
68
+ collectionId?: string;
69
+ newCollectionName?: string;
70
+ }): Promise<void>;
66
71
  openSaveDialog(input: Omit<SaveDialogState, 'open'>): void;
67
72
  closeSaveDialog(): void;
68
73
  };
package/dist/store.js CHANGED
@@ -30,8 +30,28 @@ function itemContentEqual(a, b) {
30
30
  return a.name === b.name && norm(a.query) === norm(b.query) && norm(a.variables) === norm(b.variables) && norm(a.headers) === norm(b.headers);
31
31
  }
32
32
  var collectionsStore = createStore((set, get) => {
33
+ let pendingDialog;
34
+ let committingDialog = false;
35
+ let lastPersist = Promise.resolve();
36
+ const queueWrite = async (write) => {
37
+ const previous = lastPersist;
38
+ let release;
39
+ lastPersist = new Promise((resolve) => {
40
+ release = resolve;
41
+ });
42
+ await previous;
43
+ try {
44
+ await write();
45
+ } finally {
46
+ release();
47
+ }
48
+ };
33
49
  const persist = async () => {
34
- await get().storage.save(get().collections);
50
+ try {
51
+ await queueWrite(() => get().storage.save(get().collections));
52
+ } catch (error) {
53
+ console.error("Failed to persist collections", error);
54
+ }
35
55
  };
36
56
  return {
37
57
  collections: [],
@@ -331,16 +351,28 @@ var collectionsStore = createStore((set, get) => {
331
351
  } }));
332
352
  saveTabLinks(get().links);
333
353
  },
334
- requestSave(operation) {
354
+ async requestSave(operation) {
335
355
  if (get().config.readOnly) return false;
356
+ if (get().saveDialog.open) return false;
336
357
  const { links, collections, actions } = get();
337
358
  const link = operation.id ? links[operation.id] : void 0;
338
359
  if (link) {
339
360
  if (collections.find((c) => c.id === link.collectionId)?.items.find((i) => i.id === link.itemId)) {
340
- actions.updateItem(link.collectionId, link.itemId, {
341
- query: operation.query ?? "",
342
- variables: operation.variables ?? "",
343
- headers: operation.headers ?? ""
361
+ await queueWrite(async () => {
362
+ if (!get().collections.find((c) => c.id === link.collectionId)?.items.find((i) => i.id === link.itemId)) throw new Error("Saved collection item no longer exists");
363
+ const next = get().collections.map((c) => c.id === link.collectionId ? {
364
+ ...c,
365
+ updatedAt: Date.now(),
366
+ items: c.items.map((i) => i.id === link.itemId ? {
367
+ ...i,
368
+ query: operation.query ?? "",
369
+ variables: operation.variables ?? "",
370
+ headers: operation.headers ?? "",
371
+ updatedAt: Date.now()
372
+ } : i)
373
+ } : c);
374
+ await get().storage.save(next);
375
+ set({ collections: next });
344
376
  });
345
377
  return true;
346
378
  }
@@ -352,7 +384,65 @@ var collectionsStore = createStore((set, get) => {
352
384
  headers: operation.headers ?? "",
353
385
  name: deriveOperationName(operation.query ?? "", operation.operationName)
354
386
  });
355
- return false;
387
+ return new Promise((resolve, reject) => {
388
+ pendingDialog = {
389
+ resolve,
390
+ reject
391
+ };
392
+ });
393
+ },
394
+ async commitSaveDialog(input) {
395
+ const { saveDialog, collections } = get();
396
+ if (!saveDialog.open || committingDialog) return;
397
+ if (input.collectionId && !collections.some((c) => c.id === input.collectionId)) {
398
+ const error = /* @__PURE__ */ new Error("Selected collection no longer exists");
399
+ pendingDialog?.reject(error);
400
+ pendingDialog = void 0;
401
+ get().actions.closeSaveDialog();
402
+ throw error;
403
+ }
404
+ committingDialog = true;
405
+ const now = Date.now();
406
+ const item = {
407
+ id: randomId(),
408
+ name: input.name || "Unnamed operation",
409
+ description: input.description || void 0,
410
+ query: saveDialog.query,
411
+ variables: saveDialog.variables,
412
+ headers: saveDialog.headers,
413
+ createdAt: now,
414
+ updatedAt: now
415
+ };
416
+ const collectionId = input.collectionId ?? randomId();
417
+ try {
418
+ await queueWrite(async () => {
419
+ if (input.collectionId && !get().collections.some((c) => c.id === collectionId)) throw new Error("Selected collection no longer exists");
420
+ const next = input.collectionId ? get().collections.map((c) => c.id === collectionId ? {
421
+ ...c,
422
+ items: [...c.items, item],
423
+ updatedAt: now
424
+ } : c) : [...get().collections, {
425
+ id: collectionId,
426
+ name: input.newCollectionName || "New Collection",
427
+ items: [item],
428
+ createdAt: now,
429
+ updatedAt: now
430
+ }];
431
+ await get().storage.save(next);
432
+ set({ collections: next });
433
+ });
434
+ if (saveDialog.tabId) get().actions.linkTab(saveDialog.tabId, collectionId, item.id);
435
+ pendingDialog?.resolve(true);
436
+ pendingDialog = void 0;
437
+ committingDialog = false;
438
+ get().actions.closeSaveDialog();
439
+ } catch (error) {
440
+ pendingDialog?.reject(error);
441
+ pendingDialog = void 0;
442
+ committingDialog = false;
443
+ get().actions.closeSaveDialog();
444
+ throw error;
445
+ }
356
446
  },
357
447
  openSaveDialog(input) {
358
448
  set({ saveDialog: {
@@ -361,6 +451,9 @@ var collectionsStore = createStore((set, get) => {
361
451
  } });
362
452
  },
363
453
  closeSaveDialog() {
454
+ if (committingDialog) return;
455
+ pendingDialog?.resolve(false);
456
+ pendingDialog = void 0;
364
457
  set((s) => ({ saveDialog: {
365
458
  ...s.saveDialog,
366
459
  open: false