@graphiql/plugin-history 0.2.1-canary-7ff4d2d9.0 → 0.2.1-canary-56bcac6c.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.
- package/dist/context.js +7 -8
- package/dist/context.js.map +1 -1
- package/package.json +3 -3
package/dist/context.js
CHANGED
|
@@ -44,7 +44,9 @@ const HistoryContextProvider = (t0) => {
|
|
|
44
44
|
children
|
|
45
45
|
} = t0;
|
|
46
46
|
const maxHistoryLength = t1 === void 0 ? 20 : t1;
|
|
47
|
-
const
|
|
47
|
+
const {
|
|
48
|
+
isFetching
|
|
49
|
+
} = useExecutionStore();
|
|
48
50
|
const {
|
|
49
51
|
tabs,
|
|
50
52
|
activeTabIndex
|
|
@@ -109,18 +111,15 @@ const HistoryContextProvider = (t0) => {
|
|
|
109
111
|
};
|
|
110
112
|
const useHistoryStore = createBoundedUseStore(historyStore);
|
|
111
113
|
const useHistory = () => {
|
|
112
|
-
return useHistoryStore(
|
|
114
|
+
return useHistoryStore(_temp);
|
|
113
115
|
};
|
|
114
116
|
const useHistoryActions = () => {
|
|
115
|
-
return useHistoryStore(
|
|
117
|
+
return useHistoryStore(_temp2);
|
|
116
118
|
};
|
|
117
|
-
function _temp(
|
|
118
|
-
return store.isFetching;
|
|
119
|
-
}
|
|
120
|
-
function _temp2(state) {
|
|
119
|
+
function _temp(state) {
|
|
121
120
|
return state.historyStorage.queries;
|
|
122
121
|
}
|
|
123
|
-
function
|
|
122
|
+
function _temp2(state) {
|
|
124
123
|
return state.actions;
|
|
125
124
|
}
|
|
126
125
|
export {
|
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 { HistoryStore, QueryStoreItem } from '@graphiql/toolkit';\nimport {\n useExecutionStore,\n useEditorStore,\n useStorage,\n createBoundedUseStore,\n} from '@graphiql/react';\n\nconst historyStore = createStore<HistoryContextType>((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 HistoryContextType = {\n historyStorage: HistoryStore;\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 HistoryContextProviderProps = {\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 with\n * <HistoryContext.Provider value={customizedFunctions} /> and get access to the operation plus\n * any additional props they added for their needs (i.e., build their own functions that may save\n * to a backend instead of localStorage and might need an id property added to the QueryStoreItem)\n */\nexport const HistoryContextProvider: FC<HistoryContextProviderProps> = ({\n maxHistoryLength = 20,\n children,\n}) => {\n const isFetching = useExecutionStore(
|
|
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 { HistoryStore, QueryStoreItem } from '@graphiql/toolkit';\nimport {\n useExecutionStore,\n useEditorStore,\n useStorage,\n createBoundedUseStore,\n} from '@graphiql/react';\n\nconst historyStore = createStore<HistoryContextType>((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 HistoryContextType = {\n historyStorage: HistoryStore;\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 HistoryContextProviderProps = {\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 with\n * <HistoryContext.Provider value={customizedFunctions} /> and get access to the operation plus\n * any additional props they added for their needs (i.e., build their own functions that may save\n * to a backend instead of localStorage and might need an id property added to the QueryStoreItem)\n */\nexport const HistoryContextProvider: FC<HistoryContextProviderProps> = ({\n maxHistoryLength = 20,\n children,\n}) => {\n const { isFetching } = useExecutionStore();\n const { tabs, activeTabIndex } = useEditorStore();\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 HistoryStore(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\nexport const useHistory = () =>\n useHistoryStore(state => state.historyStorage.queries);\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","HistoryContextProvider","t0","$","_c","maxHistoryLength","t1","children","undefined","isFetching","useExecutionStore","tabs","activeTabIndex","useEditorStore","activeTab","storage","useStorage","t2","HistoryStore","t3","t4","setState","useEffect","t5","t6","getState","query","variables","headers","operationName","useHistoryStore","createBoundedUseStore","useHistory","_temp","useHistoryActions","_temp2","state","queries"],"mappings":";;;;;AAWA,MAAMA,eAAeC,YAAgC,CAACC,KAAKC,SAAS;AAAA,EAClEC,gBAAgB;AAAA,EAChBC,SAAS;AAAA,IACPC,aAAaC,WAAW;AAChB,YAAA;AAAA,QAAEH;AAAAA,UAAmBD,IAAI;AAC/BC,qBAAeI,cAAcD,SAAS;AACtCL,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAO,UAAUF,WAAWG,OAAO;AACpB,YAAA;AAAA,QAAEN;AAAAA,UAAmBD,IAAI;AAChBM,qBAAAA,UAAUF,WAAWG,KAAK;AACzCR,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAS,eAAeJ,WAAW;AAClB,YAAA;AAAA,QAAEH;AAAAA,UAAmBD,IAAI;AAC/BC,qBAAeO,eAAeJ,SAAS;AACvCL,UAAI,CAAA,CAAE;AAAA,IACR;AAAA,IACAU,WAAWC,CAAQA,SAAAA;AAAAA,IACnBC,kBAAkBD,MAAME,gBAAgB;AAChC,YAAA;AAAA,QAAEX;AAAAA,UAAmBD,IAAI;AAChBa,qBA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EAAuBpC;AACpC,mBAAA;AAAA,QAAAqC,OACHZ,UAASY,SAAAlB;AAAAA,QAAmBmB,WACxBb,UAASa,aAAAnB;AAAAA,QAAuBoB,SAClCd,UAASc,WAAApB;AAAAA,QAAqBqB,eACxBf,UAASe,iBAAArB;AAAAA,MAAAA,CACzB;AAAA,IAAC;AACD,SAAA,CAACC,YAAYK,SAAS;AAACX,WAAAW;AAAAX,WAAAM;AAAAN,WAAAoB;AAAApB,WAAAqB;AAAAA,EAAAA,OAAA;AAAAD,SAAApB,EAAA,CAAA;AAAAqB,SAAArB,EAAA,CAAA;AAAA,EAAA;AAX1BmB,YAAUC,IAWPC,EAAuB;AAEnBjB,SAAAA;AAAwB;AAGjC,MAAMuB,kBAAkBC,sBAAsB/C,YAAY;AAEnD,MAAMgD,aAAaA,MAAA;AAAA,SACxBF,gBAAAG,KAAqD;AAAC;AACjD,MAAMC,oBAAoBA,MAAA;AAAA,SAAMJ,gBAAAK,MAAsC;AAAC;AAFpD,SAAAF,MAAAG,OAAA;AAAA,SACCA,MAAKhD,eAAAiD;AAAA;AACC,SAAAF,OAAAC,OAAA;AAAA,SAA+BA,MAAK/C;AAAA;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-history",
|
|
3
|
-
"version": "0.2.1-canary-
|
|
3
|
+
"version": "0.2.1-canary-56bcac6c.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
43
|
-
"@graphiql/toolkit": "^0.11.
|
|
44
|
-
"@graphiql/react": "^0.34.0-canary-
|
|
43
|
+
"@graphiql/toolkit": "^0.11.2",
|
|
44
|
+
"@graphiql/react": "^0.34.0-canary-56bcac6c.0",
|
|
45
45
|
"zustand": "^5"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|