@graphiql/plugin-history 0.3.0-rc.1 → 0.3.0-rc.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/context.d.ts +4 -0
- package/dist/context.js +7 -5
- package/dist/context.js.map +1 -1
- package/package.json +2 -2
package/dist/context.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ declare type HistoryStoreProps = {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare const HistoryStore: FC<HistoryStoreProps>;
|
|
18
18
|
export declare const useHistory: () => QueryStoreItem[];
|
|
19
|
+
/**
|
|
20
|
+
* Actions are functions used to update values in your store. They are static and never change.
|
|
21
|
+
* @see https://tkdodo.eu/blog/working-with-zustand#separate-actions-from-state
|
|
22
|
+
*/
|
|
19
23
|
export declare const useHistoryActions: () => {
|
|
20
24
|
/**
|
|
21
25
|
* Add an operation to the history.
|
package/dist/context.js
CHANGED
|
@@ -10,21 +10,21 @@ const historyStore = createStore((set, get) => ({
|
|
|
10
10
|
const {
|
|
11
11
|
historyStorage
|
|
12
12
|
} = get();
|
|
13
|
-
historyStorage.updateHistory(operation);
|
|
13
|
+
historyStorage == null ? void 0 : historyStorage.updateHistory(operation);
|
|
14
14
|
set({});
|
|
15
15
|
},
|
|
16
16
|
editLabel(operation, index) {
|
|
17
17
|
const {
|
|
18
18
|
historyStorage
|
|
19
19
|
} = get();
|
|
20
|
-
historyStorage.editLabel(operation, index);
|
|
20
|
+
historyStorage == null ? void 0 : historyStorage.editLabel(operation, index);
|
|
21
21
|
set({});
|
|
22
22
|
},
|
|
23
23
|
toggleFavorite(operation) {
|
|
24
24
|
const {
|
|
25
25
|
historyStorage
|
|
26
26
|
} = get();
|
|
27
|
-
historyStorage.toggleFavorite(operation);
|
|
27
|
+
historyStorage == null ? void 0 : historyStorage.toggleFavorite(operation);
|
|
28
28
|
set({});
|
|
29
29
|
},
|
|
30
30
|
setActive: (item) => item,
|
|
@@ -32,7 +32,7 @@ const historyStore = createStore((set, get) => ({
|
|
|
32
32
|
const {
|
|
33
33
|
historyStorage
|
|
34
34
|
} = get();
|
|
35
|
-
historyStorage.deleteHistory(item, clearFavorites);
|
|
35
|
+
historyStorage == null ? void 0 : historyStorage.deleteHistory(item, clearFavorites);
|
|
36
36
|
set({});
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -115,6 +115,7 @@ const HistoryStore = (t0) => {
|
|
|
115
115
|
return children;
|
|
116
116
|
};
|
|
117
117
|
const useHistoryStore = createBoundedUseStore(historyStore);
|
|
118
|
+
const EMPTY_ARRAY = [];
|
|
118
119
|
const useHistory = () => {
|
|
119
120
|
return useHistoryStore(_temp);
|
|
120
121
|
};
|
|
@@ -122,7 +123,8 @@ const useHistoryActions = () => {
|
|
|
122
123
|
return useHistoryStore(_temp2);
|
|
123
124
|
};
|
|
124
125
|
function _temp(state) {
|
|
125
|
-
|
|
126
|
+
var _a;
|
|
127
|
+
return ((_a = state.historyStorage) == null ? void 0 : _a.queries) ?? EMPTY_ARRAY;
|
|
126
128
|
}
|
|
127
129
|
function _temp2(state) {
|
|
128
130
|
return state.actions;
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["// eslint-disable-next-line react/jsx-filename-extension -- TODO\nimport { FC, ReactElement, ReactNode, useEffect } from 'react';\nimport { createStore } from 'zustand';\nimport {\n HistoryStore as ToolkitHistoryStore,\n QueryStoreItem,\n} from '@graphiql/toolkit';\nimport {\n useGraphiQL,\n pick,\n useStorage,\n createBoundedUseStore,\n} from '@graphiql/react';\n\nconst historyStore = createStore<HistoryStoreType>((set, get) => ({\n historyStorage: null
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["// eslint-disable-next-line react/jsx-filename-extension -- TODO\nimport { FC, ReactElement, ReactNode, useEffect } from 'react';\nimport { createStore } from 'zustand';\nimport {\n HistoryStore as ToolkitHistoryStore,\n QueryStoreItem,\n} from '@graphiql/toolkit';\nimport {\n useGraphiQL,\n pick,\n useStorage,\n createBoundedUseStore,\n} from '@graphiql/react';\n\nconst historyStore = createStore<HistoryStoreType>((set, get) => ({\n historyStorage: null,\n actions: {\n addToHistory(operation) {\n const { historyStorage } = get();\n historyStorage?.updateHistory(operation);\n set({}); // trigger rerender\n },\n editLabel(operation, index) {\n const { historyStorage } = get();\n historyStorage?.editLabel(operation, index);\n set({}); // trigger rerender\n },\n toggleFavorite(operation) {\n const { historyStorage } = get();\n historyStorage?.toggleFavorite(operation);\n set({}); // trigger rerender\n },\n setActive: item => item,\n deleteFromHistory(item, clearFavorites) {\n const { historyStorage } = get();\n historyStorage?.deleteHistory(item, clearFavorites);\n set({}); // trigger rerender\n },\n },\n}));\n\ntype HistoryStoreType = {\n // Can be `null` if History plugin saved in `localStorage` as `visiblePlugin`\n historyStorage: ToolkitHistoryStore | null;\n actions: {\n /**\n * Add an operation to the history.\n * @param operation The operation that was executed, consisting of the query,\n * variables, headers, and operation name.\n */\n addToHistory(operation: {\n query?: string;\n variables?: string;\n headers?: string;\n operationName?: string;\n }): void;\n /**\n * Change the custom label of an item from the history.\n * @param args An object containing the label (`undefined` if it should be\n * unset) and properties that identify the history item that the label should\n * be applied to. (This can result in the label being applied to multiple\n * history items.)\n * @param index Index to edit. Without it, will look for the first index matching the\n * operation, which may lead to misleading results if multiple items have the same label\n */\n editLabel(\n args: {\n query?: string;\n variables?: string;\n headers?: string;\n operationName?: string;\n label?: string;\n favorite?: boolean;\n },\n index?: number,\n ): void;\n /**\n * Toggle the favorite state of an item from the history.\n * @param args An object containing the favorite state (`undefined` if it\n * should be unset) and properties that identify the history item that the\n * label should be applied to. (This can result in the label being applied\n * to multiple history items.)\n */\n toggleFavorite(args: {\n query?: string;\n variables?: string;\n headers?: string;\n operationName?: string;\n label?: string;\n favorite?: boolean;\n }): void;\n /**\n * Delete an operation from the history.\n * @param args The operation that was executed, consisting of the query,\n * variables, headers, and operation name.\n * @param clearFavorites This is only if you press the 'clear' button\n */\n deleteFromHistory(args: QueryStoreItem, clearFavorites?: boolean): void;\n /**\n * If you need to know when an item in history is set as active to customize\n * your application.\n */\n setActive(args: QueryStoreItem): void;\n };\n};\n\ntype HistoryStoreProps = {\n children: ReactNode;\n /**\n * The maximum number of executed operations to store.\n * @default 20\n */\n maxHistoryLength?: number;\n};\n\n/**\n * The functions send the entire operation so users can customize their own application and get\n * access to the operation plus any additional props they added for their needs (i.e., build their\n * own functions that may save to a backend instead of localStorage and might need an id property\n * added to the `QueryStoreItem`)\n */\nexport const HistoryStore: FC<HistoryStoreProps> = ({\n maxHistoryLength = 20,\n children,\n}) => {\n const { isFetching, tabs, activeTabIndex } = useGraphiQL(\n pick('isFetching', 'tabs', 'activeTabIndex'),\n );\n const activeTab = tabs[activeTabIndex]!;\n const storage = useStorage();\n\n const historyStorage = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, code is optimized by React Compiler\n new ToolkitHistoryStore(storage, maxHistoryLength);\n\n useEffect(() => {\n historyStore.setState({ historyStorage });\n }, [historyStorage]);\n\n useEffect(() => {\n if (!isFetching) {\n return;\n }\n const { addToHistory } = historyStore.getState().actions;\n addToHistory({\n query: activeTab.query ?? undefined,\n variables: activeTab.variables ?? undefined,\n headers: activeTab.headers ?? undefined,\n operationName: activeTab.operationName ?? undefined,\n });\n }, [isFetching, activeTab]);\n\n return children as ReactElement;\n};\n\nconst useHistoryStore = createBoundedUseStore(historyStore);\n\nconst EMPTY_ARRAY: QueryStoreItem[] = [];\n\nexport const useHistory = () =>\n useHistoryStore(state => state.historyStorage?.queries ?? EMPTY_ARRAY);\n\n/**\n * Actions are functions used to update values in your store. They are static and never change.\n * @see https://tkdodo.eu/blog/working-with-zustand#separate-actions-from-state\n */\nexport const useHistoryActions = () => useHistoryStore(state => state.actions);\n"],"names":["historyStore","createStore","set","get","historyStorage","actions","addToHistory","operation","updateHistory","editLabel","index","toggleFavorite","setActive","item","deleteFromHistory","clearFavorites","deleteHistory","HistoryStore","t0","$","_c","maxHistoryLength","t1","children","undefined","t2","Symbol","for","pick","isFetching","tabs","activeTabIndex","useGraphiQL","activeTab","storage","useStorage","t3","ToolkitHistoryStore","t4","t5","setState","useEffect","t6","t7","getState","query","variables","headers","operationName","useHistoryStore","createBoundedUseStore","EMPTY_ARRAY","useHistory","_temp","useHistoryActions","_temp2","state","queries"],"mappings":";;;;;AAcA,MAAMA,eAAeC,YAA8B,CAACC,KAAKC,SAAS;AAAA,EAChEC,gBAAgB;AAAA,EAChBC,SAAS;AAAA,IACPC,aAAaC,WAAW;AAChB,YAAA;AAAA,QAAEH;AAAAA,UAAmBD,IAAI;AAC/BC,uDAAgBI,cAAcD;AAC9BL,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAO,UAAUF,WAAWG,OAAO;AACpB,YAAA;AAAA,QAAEN;AAAAA,UAAmBD,IAAI;AACfM,uDAAAA,UAAUF,WAAWG;AACrCR,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAS,eAAeJ,WAAW;AAClB,YAAA;AAAA,QAAEH;AAAAA,UAAmBD,IAAI;AAC/BC,uDAAgBO,eAAeJ;AAC/BL,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAU,WAAWC,CAAQA,SAAAA;AAAAA,IACnBC,kBAAkBD,MAAME,gBAAgB;AAChC,YAAA;AAAA,QAAEX;AAAAA,UAAmBD,IAAI;AACfa,uDAAAA,cAAcH,MAAME;AACpCb,UAAI,CAAA,CAAE;AAAA,IAAA;AAAA,EACR;AAEJ,EAAE;AAkFK,MAAMe,eAAsCC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA;AAAC,QAAA;AAAA,IAAAC,kBAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAAAL;AAClDG,QAAAA,mBAAAC,OAAqBE,cAArBF;AAAqBG,MAAAA;AAAA,MAAAN,EAAA,CAAA,MAAAO,OAAAC,IAAA,2BAAA,GAAA;AAInBC,SAAAA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AAAA,CACzB;AAAA,IAAC;AACD,SAAA,CAACK,YAAYI,SAAS;AAACd,WAAAc;AAAAd,WAAAU;AAAAV,WAAAuB;AAAAvB,YAAAwB;AAAAA,EAAAA,OAAA;AAAAD,SAAAvB,EAAA,CAAA;AAAAwB,SAAAxB,EAAA,EAAA;AAAA,EAAA;AAX1BsB,YAAUC,IAWPC,EAAuB;AAEnBpB,SAAAA;AAAwB;AAGjC,MAAM0B,kBAAkBC,sBAAsBlD,YAAY;AAE1D,MAAMmD,cAAgC,CAAE;AAEjC,MAAMC,aAAaA,MAAA;AAAA,SACxBH,gBAAAI,KAAqE;AAAC;AAMjE,MAAMC,oBAAoBA,MAAA;AAAA,SAAML,gBAAAM,MAAsC;AAAC;AAPpD,SAAAF,MAAAG,OAAA;;AACCA,WAAAA,WAAKpD,mBAALoD,mBAAKC,YAAAN;AAAuC;AAMtC,SAAAI,OAAAC,OAAA;AAAA,SAA+BA,MAAKnD;AAAA;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-history",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react-dom": "^18 || ^19"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@graphiql/react": "^0.35.0-rc.
|
|
42
|
+
"@graphiql/react": "^0.35.0-rc.4",
|
|
43
43
|
"@graphiql/toolkit": "^0.11.3",
|
|
44
44
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
45
45
|
"zustand": "^5"
|