@graphiql/plugin-collections 0.0.0 → 1.0.0-beta.1
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/README.md +162 -0
- package/dist/collections.stories.d.ts +14 -0
- package/dist/components/collection-item-row.d.ts +25 -0
- package/dist/components/collection-item-row.js +286 -0
- package/dist/components/collection-item-row.js.map +1 -0
- package/dist/components/collection-row.d.ts +32 -0
- package/dist/components/collection-row.js +162 -0
- package/dist/components/collection-row.js.map +1 -0
- package/dist/components/collections-panel.d.ts +9 -0
- package/dist/components/collections-panel.js +508 -0
- package/dist/components/collections-panel.js.map +1 -0
- package/dist/components/conflict-dialog.d.ts +11 -0
- package/dist/components/conflict-dialog.js +169 -0
- package/dist/components/conflict-dialog.js.map +1 -0
- package/dist/components/export-dialog.d.ts +7 -0
- package/dist/components/export-dialog.js +54 -0
- package/dist/components/export-dialog.js.map +1 -0
- package/dist/components/import-dialog.d.ts +10 -0
- package/dist/components/import-dialog.js +114 -0
- package/dist/components/import-dialog.js.map +1 -0
- package/dist/components/save-dialog.d.ts +7 -0
- package/dist/components/save-dialog.js +125 -0
- package/dist/components/save-dialog.js.map +1 -0
- package/dist/components/session-actions.d.ts +9 -0
- package/dist/components/session-actions.js +34 -0
- package/dist/components/session-actions.js.map +1 -0
- package/dist/icons/check.js +10 -0
- package/dist/icons/check.js.map +1 -0
- package/dist/icons/collections.js +10 -0
- package/dist/icons/collections.js.map +1 -0
- package/dist/icons/download.js +10 -0
- package/dist/icons/download.js.map +1 -0
- package/dist/icons/upload.js +10 -0
- package/dist/icons/upload.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/operation-method.d.ts +10 -0
- package/dist/operation-method.js +28 -0
- package/dist/operation-method.js.map +1 -0
- package/dist/storage/local-storage.d.ts +3 -0
- package/dist/storage/local-storage.js +39 -0
- package/dist/storage/local-storage.js.map +1 -0
- package/dist/storage/tab-links.d.ts +7 -0
- package/dist/storage/tab-links.js +36 -0
- package/dist/storage/tab-links.js.map +1 -0
- package/dist/store.d.ts +78 -0
- package/dist/store.js +413 -0
- package/dist/store.js.map +1 -0
- package/dist/style.css +442 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utility/uuid.d.ts +4 -0
- package/dist/utility/uuid.js +11 -0
- package/dist/utility/uuid.js.map +1 -0
- package/package.json +60 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const SvgDownload = ({
|
|
3
|
+
title,
|
|
4
|
+
titleId,
|
|
5
|
+
...props
|
|
6
|
+
}) => /* @__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" }));
|
|
7
|
+
export {
|
|
8
|
+
SvgDownload as default
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","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"],"names":[],"mappings":";AACK,MAAC,cAAc,CAAC;AAAA,EACnB;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAsB,sBAAM,cAAc,OAAO,EAAE,OAAO,8BAA8B,MAAM,QAAQ,QAAQ,gBAAgB,eAAe,SAAS,gBAAgB,SAAS,aAAa,GAAG,SAAS,aAAa,mBAAmB,SAAS,GAAG,MAAK,GAAI,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAS,GAAE,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ,EAAE,GAAG,iCAAiC,CAAC;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const SvgUpload = ({
|
|
3
|
+
title,
|
|
4
|
+
titleId,
|
|
5
|
+
...props
|
|
6
|
+
}) => /* @__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" }));
|
|
7
|
+
export {
|
|
8
|
+
SvgUpload as default
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","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"],"names":[],"mappings":";AACK,MAAC,YAAY,CAAC;AAAA,EACjB;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAsB,sBAAM,cAAc,OAAO,EAAE,OAAO,8BAA8B,MAAM,QAAQ,QAAQ,gBAAgB,eAAe,SAAS,gBAAgB,SAAS,aAAa,GAAG,SAAS,aAAa,mBAAmB,SAAS,GAAG,MAAK,GAAI,QAAwB,sBAAM,cAAc,SAAS,EAAE,IAAI,QAAS,GAAE,KAAK,IAAI,MAAsB,sBAAM,cAAc,QAAQ,EAAE,GAAG,iCAAiC,CAAC;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GraphiQLPlugin } from '@graphiql/react';
|
|
2
|
+
import { CollectionsStorage } from './types';
|
|
3
|
+
export type { CollectionsStorage, CollectionsConfig, Collection, CollectionItem, } from './types';
|
|
4
|
+
export { collectionsStore, useCollectionsStore, type ActiveOperation, } from './store';
|
|
5
|
+
export { createLocalStorageAdapter, localStorageAdapter, } from './storage/local-storage';
|
|
6
|
+
export { SaveDialog as CollectionsSaveDialog } from './components/save-dialog';
|
|
7
|
+
export type CollectionsPluginOptions = {
|
|
8
|
+
/** Custom storage adapter. Defaults to localStorage with key 'graphiql:collections'. */
|
|
9
|
+
storage?: CollectionsStorage;
|
|
10
|
+
/** Disable all write operations (export & copy still allowed). Default false. */
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
/** Master switch for the import/export feature. Default true. */
|
|
13
|
+
allowImportExport?: boolean;
|
|
14
|
+
/** Allow the destructive "Replace" import option. Default true. */
|
|
15
|
+
allowReplace?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const collectionsPlugin: (options?: CollectionsPluginOptions) => GraphiQLPlugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CollectionsPanel } from "./components/collections-panel.js";
|
|
3
|
+
import { CollectionsSessionActions } from "./components/session-actions.js";
|
|
4
|
+
import SvgCollections from "./icons/collections.js";
|
|
5
|
+
/* empty css */
|
|
6
|
+
import { collectionsStore, useCollectionsStore } from "./store.js";
|
|
7
|
+
import { createLocalStorageAdapter, localStorageAdapter } from "./storage/local-storage.js";
|
|
8
|
+
import { SaveDialog } from "./components/save-dialog.js";
|
|
9
|
+
const collectionsPlugin = (options) => {
|
|
10
|
+
function CollectionsPanelWithOptions() {
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
CollectionsPanel,
|
|
13
|
+
{
|
|
14
|
+
readOnly: options == null ? void 0 : options.readOnly,
|
|
15
|
+
allowImportExport: options == null ? void 0 : options.allowImportExport,
|
|
16
|
+
allowReplace: options == null ? void 0 : options.allowReplace
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function CollectionsSessionActionsWithOptions() {
|
|
21
|
+
return /* @__PURE__ */ jsx(
|
|
22
|
+
CollectionsSessionActions,
|
|
23
|
+
{
|
|
24
|
+
storage: options == null ? void 0 : options.storage,
|
|
25
|
+
readOnly: options == null ? void 0 : options.readOnly,
|
|
26
|
+
allowImportExport: options == null ? void 0 : options.allowImportExport,
|
|
27
|
+
allowReplace: options == null ? void 0 : options.allowReplace
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
title: "Collections",
|
|
33
|
+
icon: SvgCollections,
|
|
34
|
+
content: CollectionsPanelWithOptions,
|
|
35
|
+
sessionActions: CollectionsSessionActionsWithOptions
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
SaveDialog as CollectionsSaveDialog,
|
|
40
|
+
collectionsPlugin,
|
|
41
|
+
collectionsStore,
|
|
42
|
+
createLocalStorageAdapter,
|
|
43
|
+
localStorageAdapter,
|
|
44
|
+
useCollectionsStore
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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"],"names":["CollectionsIcon"],"mappings":";;;;;;;;AAmCa,MAAA,oBAAoB,CAC/B,YACmB;AACnB,WAAS,8BAA8B;AAEnC,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAU,mCAAS;AAAA,QACnB,mBAAmB,mCAAS;AAAA,QAC5B,cAAc,mCAAS;AAAA,MAAA;AAAA,IACzB;AAAA,EAAA;AAGJ,WAAS,uCAAuC;AAE5C,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAAS,mCAAS;AAAA,QAClB,UAAU,mCAAS;AAAA,QACnB,mBAAmB,mCAAS;AAAA,QAC5B,cAAc,mCAAS;AAAA,MAAA;AAAA,IACzB;AAAA,EAAA;AAGG,SAAA;AAAA,IACL,OAAO;AAAA,IACP,MAAMA;AAAAA,IACN,SAAS;AAAA,IACT,gBAAgB;AAAA,EAClB;AACF;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Operation } from '@graphiql/react';
|
|
2
|
+
/** The pill shown for a saved item: a single operation's type, or `'mix'`. */
|
|
3
|
+
export type DocumentMethod = Operation | 'mix';
|
|
4
|
+
/**
|
|
5
|
+
* A saved item holds a whole document, which may contain more than one
|
|
6
|
+
* operation. Return the single operation's type, or `'mix'` when there are
|
|
7
|
+
* several so the row shows a neutral pill instead of just the first one's.
|
|
8
|
+
* Anonymous shorthand (`{ ... }`) and unparseable text resolve to `'query'`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getDocumentMethod(query: string): DocumentMethod;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parse, Kind } from "graphql";
|
|
2
|
+
function inferOperationType(query) {
|
|
3
|
+
var _a;
|
|
4
|
+
const match = /^\s*(query|mutation|subscription)/i.exec(query);
|
|
5
|
+
const keyword = (_a = match == null ? void 0 : match[1]) == null ? void 0 : _a.toLowerCase();
|
|
6
|
+
if (keyword === "mutation" || keyword === "subscription") {
|
|
7
|
+
return keyword;
|
|
8
|
+
}
|
|
9
|
+
return "query";
|
|
10
|
+
}
|
|
11
|
+
function getDocumentMethod(query) {
|
|
12
|
+
try {
|
|
13
|
+
const operations = parse(query).definitions.filter(
|
|
14
|
+
(def) => def.kind === Kind.OPERATION_DEFINITION
|
|
15
|
+
);
|
|
16
|
+
if (operations.length > 1) {
|
|
17
|
+
return "mix";
|
|
18
|
+
}
|
|
19
|
+
const [operation] = operations;
|
|
20
|
+
return operation ? operation.operation : "query";
|
|
21
|
+
} catch {
|
|
22
|
+
return inferOperationType(query);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
getDocumentMethod
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=operation-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-method.js","sources":["../src/operation-method.ts"],"sourcesContent":["import { Kind, parse } from 'graphql';\nimport type { Operation } from '@graphiql/react';\n\n/** The pill shown for a saved item: a single operation's type, or `'mix'`. */\nexport type DocumentMethod = Operation | 'mix';\n\n/** Cheap regex fallback for when a document can't be parsed. */\nfunction inferOperationType(query: string): Operation {\n const match = /^\\s*(query|mutation|subscription)/i.exec(query);\n const keyword = match?.[1]?.toLowerCase();\n if (keyword === 'mutation' || keyword === 'subscription') {\n return keyword;\n }\n return 'query';\n}\n\n/**\n * A saved item holds a whole document, which may contain more than one\n * operation. Return the single operation's type, or `'mix'` when there are\n * several so the row shows a neutral pill instead of just the first one's.\n * Anonymous shorthand (`{ ... }`) and unparseable text resolve to `'query'`.\n */\nexport function getDocumentMethod(query: string): DocumentMethod {\n try {\n const operations = parse(query).definitions.filter(\n def => def.kind === Kind.OPERATION_DEFINITION,\n );\n if (operations.length > 1) {\n return 'mix';\n }\n const [operation] = operations;\n return operation ? operation.operation : 'query';\n } catch {\n return inferOperationType(query);\n }\n}\n"],"names":[],"mappings":";AAOA,SAAS,mBAAmB,OAA0B;;AAC9C,QAAA,QAAQ,qCAAqC,KAAK,KAAK;AAC7D,QAAM,WAAU,oCAAQ,OAAR,mBAAY;AACxB,MAAA,YAAY,cAAc,YAAY,gBAAgB;AACjD,WAAA;AAAA,EAAA;AAEF,SAAA;AACT;AAQO,SAAS,kBAAkB,OAA+B;AAC3D,MAAA;AACF,UAAM,aAAa,MAAM,KAAK,EAAE,YAAY;AAAA,MAC1C,CAAA,QAAO,IAAI,SAAS,KAAK;AAAA,IAC3B;AACI,QAAA,WAAW,SAAS,GAAG;AAClB,aAAA;AAAA,IAAA;AAEH,UAAA,CAAC,SAAS,IAAI;AACb,WAAA,YAAY,UAAU,YAAY;AAAA,EAAA,QACnC;AACN,WAAO,mBAAmB,KAAK;AAAA,EAAA;AAEnC;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const DEFAULT_KEY = "graphiql:collections";
|
|
2
|
+
const VERSION = 1;
|
|
3
|
+
function createLocalStorageAdapter(storageKey = DEFAULT_KEY) {
|
|
4
|
+
return {
|
|
5
|
+
async load() {
|
|
6
|
+
try {
|
|
7
|
+
const raw = localStorage.getItem(storageKey);
|
|
8
|
+
if (!raw) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const parsed = JSON.parse(raw);
|
|
12
|
+
if (parsed.version !== VERSION) {
|
|
13
|
+
console.warn(
|
|
14
|
+
`[graphiql/plugin-collections] Storage version mismatch (found ${parsed.version}, expected ${VERSION}). Attempting to load collections as-is.`
|
|
15
|
+
);
|
|
16
|
+
return Array.isArray(parsed.collections) ? parsed.collections : [];
|
|
17
|
+
}
|
|
18
|
+
return parsed.collections ?? [];
|
|
19
|
+
} catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
async save(collections) {
|
|
24
|
+
try {
|
|
25
|
+
localStorage.setItem(
|
|
26
|
+
storageKey,
|
|
27
|
+
JSON.stringify({ version: VERSION, collections })
|
|
28
|
+
);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const localStorageAdapter = createLocalStorageAdapter();
|
|
35
|
+
export {
|
|
36
|
+
createLocalStorageAdapter,
|
|
37
|
+
localStorageAdapter
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=local-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage.js","sources":["../../src/storage/local-storage.ts"],"sourcesContent":["import type { Collection, CollectionsStorage } from '../types';\n\nconst DEFAULT_KEY = 'graphiql:collections';\nconst VERSION = 1;\n\ntype StorageEnvelope = {\n version: number;\n collections: Collection[];\n};\n\nexport function createLocalStorageAdapter(\n storageKey = DEFAULT_KEY,\n): CollectionsStorage {\n return {\n async load() {\n try {\n const raw = localStorage.getItem(storageKey);\n if (!raw) {\n return [];\n }\n const parsed: StorageEnvelope = JSON.parse(raw);\n if (parsed.version !== VERSION) {\n // Version mismatch: attempt a best-effort migration.\n // V1 has the same shape — just update the version stamp and return collections.\n // Future migrations go here when VERSION is bumped.\n // eslint-disable-next-line no-console\n console.warn(\n `[graphiql/plugin-collections] Storage version mismatch (found ${parsed.version}, expected ${VERSION}). Attempting to load collections as-is.`,\n );\n return Array.isArray(parsed.collections) ? parsed.collections : [];\n }\n return parsed.collections ?? [];\n } catch {\n return [];\n }\n },\n async save(collections) {\n try {\n localStorage.setItem(\n storageKey,\n JSON.stringify({ version: VERSION, collections }),\n );\n } catch {\n // Storage quota exceeded or unavailable — silent no-op\n }\n },\n };\n}\n\nexport const localStorageAdapter = createLocalStorageAdapter();\n"],"names":[],"mappings":"AAEA,MAAM,cAAc;AACpB,MAAM,UAAU;AAOA,SAAA,0BACd,aAAa,aACO;AACb,SAAA;AAAA,IACL,MAAM,OAAO;AACP,UAAA;AACI,cAAA,MAAM,aAAa,QAAQ,UAAU;AAC3C,YAAI,CAAC,KAAK;AACR,iBAAO,CAAC;AAAA,QAAA;AAEJ,cAAA,SAA0B,KAAK,MAAM,GAAG;AAC1C,YAAA,OAAO,YAAY,SAAS;AAKtB,kBAAA;AAAA,YACN,iEAAiE,OAAO,OAAO,cAAc,OAAO;AAAA,UACtG;AACA,iBAAO,MAAM,QAAQ,OAAO,WAAW,IAAI,OAAO,cAAc,CAAC;AAAA,QAAA;AAE5D,eAAA,OAAO,eAAe,CAAC;AAAA,MAAA,QACxB;AACN,eAAO,CAAC;AAAA,MAAA;AAAA,IAEZ;AAAA,IACA,MAAM,KAAK,aAAa;AAClB,UAAA;AACW,qBAAA;AAAA,UACX;AAAA,UACA,KAAK,UAAU,EAAE,SAAS,SAAS,YAAa,CAAA;AAAA,QAClD;AAAA,MAAA,QACM;AAAA,MAAA;AAAA,IAER;AAAA,EAEJ;AACF;AAEO,MAAM,sBAAsB,0BAA0B;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A link from an editor tab to the collection item it was opened from or saved as. */
|
|
2
|
+
export type TabLink = {
|
|
3
|
+
collectionId: string;
|
|
4
|
+
itemId: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function loadTabLinks(): Record<string, TabLink>;
|
|
7
|
+
export declare function saveTabLinks(links: Record<string, TabLink>): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const LINKS_KEY = "graphiql:collections:tab-links";
|
|
2
|
+
function isTabLink(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && typeof value.collectionId === "string" && typeof value.itemId === "string";
|
|
4
|
+
}
|
|
5
|
+
function loadTabLinks() {
|
|
6
|
+
try {
|
|
7
|
+
const raw = localStorage.getItem(LINKS_KEY);
|
|
8
|
+
if (!raw) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const parsed = JSON.parse(raw);
|
|
12
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const links = {};
|
|
16
|
+
for (const [tabId, link] of Object.entries(parsed)) {
|
|
17
|
+
if (isTabLink(link)) {
|
|
18
|
+
links[tabId] = link;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return links;
|
|
22
|
+
} catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function saveTabLinks(links) {
|
|
27
|
+
try {
|
|
28
|
+
localStorage.setItem(LINKS_KEY, JSON.stringify(links));
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
loadTabLinks,
|
|
34
|
+
saveTabLinks
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=tab-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab-links.js","sources":["../../src/storage/tab-links.ts"],"sourcesContent":["/** A link from an editor tab to the collection item it was opened from or saved as. */\nexport type TabLink = { collectionId: string; itemId: string };\n\n/**\n * Tab↔item links are browser-local: they key off GraphiQL's own tab ids, which\n * live in localStorage and are stable across reloads. They are deliberately\n * kept out of `CollectionsStorage` — a remote/DB collections backend shared\n * between machines must not receive another client's tab ids.\n */\nconst LINKS_KEY = 'graphiql:collections:tab-links';\n\nfunction isTabLink(value: unknown): value is TabLink {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as TabLink).collectionId === 'string' &&\n typeof (value as TabLink).itemId === 'string'\n );\n}\n\nexport function loadTabLinks(): Record<string, TabLink> {\n try {\n const raw = localStorage.getItem(LINKS_KEY);\n if (!raw) {\n return {};\n }\n const parsed: unknown = JSON.parse(raw);\n if (typeof parsed !== 'object' || parsed === null) {\n return {};\n }\n const links: Record<string, TabLink> = {};\n for (const [tabId, link] of Object.entries(parsed)) {\n if (isTabLink(link)) {\n links[tabId] = link;\n }\n }\n return links;\n } catch {\n return {};\n }\n}\n\nexport function saveTabLinks(links: Record<string, TabLink>): void {\n try {\n localStorage.setItem(LINKS_KEY, JSON.stringify(links));\n } catch {\n // Storage quota exceeded or unavailable — silent no-op.\n }\n}\n"],"names":[],"mappings":"AASA,MAAM,YAAY;AAElB,SAAS,UAAU,OAAkC;AAEjD,SAAA,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAkB,iBAAiB,YAC3C,OAAQ,MAAkB,WAAW;AAEzC;AAEO,SAAS,eAAwC;AAClD,MAAA;AACI,UAAA,MAAM,aAAa,QAAQ,SAAS;AAC1C,QAAI,CAAC,KAAK;AACR,aAAO,CAAC;AAAA,IAAA;AAEJ,UAAA,SAAkB,KAAK,MAAM,GAAG;AACtC,QAAI,OAAO,WAAW,YAAY,WAAW,MAAM;AACjD,aAAO,CAAC;AAAA,IAAA;AAEV,UAAM,QAAiC,CAAC;AACxC,eAAW,CAAC,OAAO,IAAI,KAAK,OAAO,QAAQ,MAAM,GAAG;AAC9C,UAAA,UAAU,IAAI,GAAG;AACnB,cAAM,KAAK,IAAI;AAAA,MAAA;AAAA,IACjB;AAEK,WAAA;AAAA,EAAA,QACD;AACN,WAAO,CAAC;AAAA,EAAA;AAEZ;AAEO,SAAS,aAAa,OAAsC;AAC7D,MAAA;AACF,iBAAa,QAAQ,WAAW,KAAK,UAAU,KAAK,CAAC;AAAA,EAAA,QAC/C;AAAA,EAAA;AAGV;"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Collection, CollectionItem, CollectionsConfig, CollectionsStorage, ImportAnalysis, ImportResolution } from './types';
|
|
2
|
+
import { TabLink } from './storage/tab-links';
|
|
3
|
+
/** The active operation being saved, as seen by the save dialog. */
|
|
4
|
+
export type SaveDialogState = {
|
|
5
|
+
open: boolean;
|
|
6
|
+
/** The tab this save originated from, linked to the item once saved. */
|
|
7
|
+
tabId?: string;
|
|
8
|
+
query: string;
|
|
9
|
+
variables: string;
|
|
10
|
+
headers: string;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
/** The current operation handed to `requestSave` from ⌘S or the save button. */
|
|
14
|
+
export type ActiveOperation = {
|
|
15
|
+
id?: string;
|
|
16
|
+
query: string | null;
|
|
17
|
+
variables?: string | null;
|
|
18
|
+
headers?: string | null;
|
|
19
|
+
operationName?: string | null;
|
|
20
|
+
};
|
|
21
|
+
type CollectionsState = {
|
|
22
|
+
collections: Collection[];
|
|
23
|
+
loaded: boolean;
|
|
24
|
+
storage: CollectionsStorage;
|
|
25
|
+
/** Host-controlled capability flags; set on init from the plugin options. */
|
|
26
|
+
config: CollectionsConfig;
|
|
27
|
+
/** Maps a tab id to the collection item it is linked to. */
|
|
28
|
+
links: Record<string, TabLink>;
|
|
29
|
+
saveDialog: SaveDialogState;
|
|
30
|
+
};
|
|
31
|
+
type CollectionsActions = {
|
|
32
|
+
init(storage: CollectionsStorage, config?: Partial<CollectionsConfig>): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Replace the in-memory collections wholesale without persisting. Use this
|
|
35
|
+
* to reflect state loaded or merged externally — writing it back would be
|
|
36
|
+
* redundant and, for a DB adapter, an unwanted extra write.
|
|
37
|
+
*/
|
|
38
|
+
setCollections(collections: Collection[]): void;
|
|
39
|
+
/** Re-read collections from the configured storage — call after an external/remote change to refresh the UI. */
|
|
40
|
+
reload(): Promise<void>;
|
|
41
|
+
createCollection(name: string, description?: string): Collection;
|
|
42
|
+
deleteCollection(id: string): void;
|
|
43
|
+
renameCollection(id: string, name: string): void;
|
|
44
|
+
addItem(collectionId: string, item: Omit<CollectionItem, 'id' | 'createdAt' | 'updatedAt'>): CollectionItem;
|
|
45
|
+
updateItem(collectionId: string, itemId: string, updates: Partial<Omit<CollectionItem, 'id' | 'createdAt'>>): void;
|
|
46
|
+
deleteItem(collectionId: string, itemId: string): void;
|
|
47
|
+
moveItem(fromCollectionId: string, fromIndex: number, toCollectionId: string, toIndex: number): void;
|
|
48
|
+
/** Pure analysis of an import JSON string against current store state. Never mutates. */
|
|
49
|
+
analyzeImport(json: string): ImportAnalysis;
|
|
50
|
+
/** Commit an analysis to the store using the given resolution strategy. */
|
|
51
|
+
applyImport(analysis: ImportAnalysis, resolution: ImportResolution): void;
|
|
52
|
+
exportCollections(): string;
|
|
53
|
+
/** Export a single collection as a (one-collection) export envelope. */
|
|
54
|
+
exportCollection(id: string): string;
|
|
55
|
+
/** Export a single item as a (one-item, one-collection) export envelope. */
|
|
56
|
+
exportItem(itemId: string): string;
|
|
57
|
+
/** Link a tab to a collection item so ⌘S updates it in place. */
|
|
58
|
+
linkTab(tabId: string, collectionId: string, itemId: string): void;
|
|
59
|
+
/**
|
|
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.
|
|
64
|
+
*/
|
|
65
|
+
requestSave(operation: ActiveOperation): boolean;
|
|
66
|
+
openSaveDialog(input: Omit<SaveDialogState, 'open'>): void;
|
|
67
|
+
closeSaveDialog(): void;
|
|
68
|
+
};
|
|
69
|
+
export declare function deriveOperationName(query: string, fallback?: string | null): string;
|
|
70
|
+
type StoreShape = CollectionsState & {
|
|
71
|
+
actions: CollectionsActions;
|
|
72
|
+
};
|
|
73
|
+
export declare const collectionsStore: import('zustand').StoreApi<StoreShape>;
|
|
74
|
+
export declare const useCollectionsStore: {
|
|
75
|
+
(): StoreShape;
|
|
76
|
+
<T>(selector: (state: StoreShape) => T): T;
|
|
77
|
+
};
|
|
78
|
+
export {};
|