@graphiql/plugin-history 0.2.1 → 0.2.2-canary-9bb08e5e.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 CHANGED
@@ -44,9 +44,7 @@ const HistoryContextProvider = (t0) => {
44
44
  children
45
45
  } = t0;
46
46
  const maxHistoryLength = t1 === void 0 ? 20 : t1;
47
- const {
48
- isFetching
49
- } = useExecutionStore();
47
+ const isFetching = useExecutionStore(_temp);
50
48
  const {
51
49
  tabs,
52
50
  activeTabIndex
@@ -111,15 +109,18 @@ const HistoryContextProvider = (t0) => {
111
109
  };
112
110
  const useHistoryStore = createBoundedUseStore(historyStore);
113
111
  const useHistory = () => {
114
- return useHistoryStore(_temp);
112
+ return useHistoryStore(_temp2);
115
113
  };
116
114
  const useHistoryActions = () => {
117
- return useHistoryStore(_temp2);
115
+ return useHistoryStore(_temp3);
118
116
  };
119
- function _temp(state) {
120
- return state.historyStorage.queries;
117
+ function _temp(store) {
118
+ return store.isFetching;
121
119
  }
122
120
  function _temp2(state) {
121
+ return state.historyStorage.queries;
122
+ }
123
+ function _temp3(state) {
123
124
  return state.actions;
124
125
  }
125
126
  export {
@@ -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();\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,QAAE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Af;AAAAe,WAAAgB;AAAAhB,WAAAiB;AAAAA,EAAAA,OAAA;AAAAD,SAAAhB,EAAA,CAAA;AAAAiB,SAAAjB,EAAA,CAAA;AAAA,EAAA;AAFnBmB,YAAUH,IAEPC,EAAgB;AAACG,MAAAA;AAAAC,MAAAA;AAAA,MAAArB,EAAAW,CAAAA,MAAAA,aAAAX,SAAAM,YAAA;AAEVc,SAAAA,MAAA;AAAA,UAAA,CACHd,YAAU;AAAA;AAAA,MAAA;AAGf,YAAA;AAAA,QAAAnB;AAAAA,MAAAA,IAAyBN,aAAAyC,SAAAA,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;"}
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(store => store.isFetching);\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","_temp","tabs","activeTabIndex","useEditorStore","activeTab","storage","useStorage","t2","HistoryStore","t3","t4","setState","useEffect","t5","t6","getState","query","variables","headers","operationName","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BF,gBAAAG,MAAqD;AAAC;AACjD,MAAMC,oBAAoBA,MAAA;AAAA,SAAMJ,gBAAAK,MAAsC;AAAC;AApCP,SAAAzB,MAAA0B,OAAA;AAAA,SAIvBA,MAAK5B;AAAA;AA8B3B,SAAAyB,OAAAI,OAAA;AAAA,SACCA,MAAKlD,eAAAmD;AAAA;AACC,SAAAH,OAAAE,OAAA;AAAA,SAA+BA,MAAKjD;AAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphiql/plugin-history",
3
- "version": "0.2.1",
3
+ "version": "0.2.2-canary-9bb08e5e.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.2",
44
- "@graphiql/react": "^0.34.0",
43
+ "@graphiql/toolkit": "^0.11.3-canary-9bb08e5e.0",
44
+ "@graphiql/react": "^0.35.0-canary-9bb08e5e.0",
45
45
  "zustand": "^5"
46
46
  },
47
47
  "devDependencies": {