@graphiql/plugin-history 0.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.
- package/README.md +1 -0
- package/dist/components.d.ts +10 -0
- package/dist/components.js +346 -0
- package/dist/components.js.map +1 -0
- package/dist/context.d.ts +91 -0
- package/dist/context.js +138 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +99 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@graphiql/plugin-history`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryStoreItem } from '@graphiql/toolkit';
|
|
2
|
+
export declare function History(): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare type QueryHistoryItemProps = {
|
|
4
|
+
item: QueryStoreItem & {
|
|
5
|
+
index?: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function HistoryItem(props: QueryHistoryItemProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function formatQuery(query?: string): string | undefined;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react-compiler-runtime";
|
|
3
|
+
import { useState, useEffect, useRef } from "react";
|
|
4
|
+
import { Button, useEditorContext, cn, UnStyledButton, CloseIcon, Tooltip, PenIcon, StarFilledIcon, StarIcon, TrashIcon } from "@graphiql/react";
|
|
5
|
+
import { useHistoryContext } from "./context.js";
|
|
6
|
+
function handleDelete(items, deleteFromHistory) {
|
|
7
|
+
for (const item of items) {
|
|
8
|
+
deleteFromHistory(item, true);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function History() {
|
|
12
|
+
const $ = c(14);
|
|
13
|
+
let t0;
|
|
14
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
15
|
+
t0 = {
|
|
16
|
+
nonNull: true
|
|
17
|
+
};
|
|
18
|
+
$[0] = t0;
|
|
19
|
+
} else {
|
|
20
|
+
t0 = $[0];
|
|
21
|
+
}
|
|
22
|
+
const {
|
|
23
|
+
items: all,
|
|
24
|
+
deleteFromHistory
|
|
25
|
+
} = useHistoryContext(t0);
|
|
26
|
+
let items;
|
|
27
|
+
items = all.slice().map(_temp).reverse();
|
|
28
|
+
const favorites = items.filter(_temp2);
|
|
29
|
+
if (favorites.length) {
|
|
30
|
+
items = items.filter(_temp3);
|
|
31
|
+
}
|
|
32
|
+
const [clearStatus, setClearStatus] = useState(null);
|
|
33
|
+
let t1;
|
|
34
|
+
let t2;
|
|
35
|
+
if ($[1] !== clearStatus) {
|
|
36
|
+
t1 = () => {
|
|
37
|
+
if (clearStatus) {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
setClearStatus(null);
|
|
40
|
+
}, 2e3);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
t2 = [clearStatus];
|
|
44
|
+
$[1] = clearStatus;
|
|
45
|
+
$[2] = t1;
|
|
46
|
+
$[3] = t2;
|
|
47
|
+
} else {
|
|
48
|
+
t1 = $[2];
|
|
49
|
+
t2 = $[3];
|
|
50
|
+
}
|
|
51
|
+
useEffect(t1, t2);
|
|
52
|
+
const handleClearStatus = () => {
|
|
53
|
+
try {
|
|
54
|
+
handleDelete(items, deleteFromHistory);
|
|
55
|
+
setClearStatus("success");
|
|
56
|
+
} catch {
|
|
57
|
+
setClearStatus("error");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const hasFavorites = Boolean(favorites.length);
|
|
61
|
+
const hasItems = Boolean(items.length);
|
|
62
|
+
const t3 = "History";
|
|
63
|
+
const t4 = "graphiql-history";
|
|
64
|
+
const t5 = (clearStatus || hasItems) && /* @__PURE__ */ jsx(Button, { type: "button", state: clearStatus || void 0, disabled: !items.length, onClick: handleClearStatus, children: {
|
|
65
|
+
success: "Cleared",
|
|
66
|
+
error: "Failed to Clear"
|
|
67
|
+
}[clearStatus] || "Clear" });
|
|
68
|
+
let t6;
|
|
69
|
+
if ($[4] !== t5) {
|
|
70
|
+
t6 = /* @__PURE__ */ jsxs("div", { className: "graphiql-history-header", children: [
|
|
71
|
+
"History",
|
|
72
|
+
t5
|
|
73
|
+
] });
|
|
74
|
+
$[4] = t5;
|
|
75
|
+
$[5] = t6;
|
|
76
|
+
} else {
|
|
77
|
+
t6 = $[5];
|
|
78
|
+
}
|
|
79
|
+
const t7 = hasFavorites && /* @__PURE__ */ jsx("ul", { className: "graphiql-history-items", children: favorites.map(_temp4) });
|
|
80
|
+
let t8;
|
|
81
|
+
if ($[6] !== hasFavorites || $[7] !== hasItems) {
|
|
82
|
+
t8 = hasFavorites && hasItems && /* @__PURE__ */ jsx("div", { className: "graphiql-history-item-spacer" });
|
|
83
|
+
$[6] = hasFavorites;
|
|
84
|
+
$[7] = hasItems;
|
|
85
|
+
$[8] = t8;
|
|
86
|
+
} else {
|
|
87
|
+
t8 = $[8];
|
|
88
|
+
}
|
|
89
|
+
const t9 = hasItems && /* @__PURE__ */ jsx("ul", { className: "graphiql-history-items", children: items.map(_temp5) });
|
|
90
|
+
let t10;
|
|
91
|
+
if ($[9] !== t6 || $[10] !== t7 || $[11] !== t8 || $[12] !== t9) {
|
|
92
|
+
t10 = /* @__PURE__ */ jsxs("section", { "aria-label": t3, className: t4, children: [
|
|
93
|
+
t6,
|
|
94
|
+
t7,
|
|
95
|
+
t8,
|
|
96
|
+
t9
|
|
97
|
+
] });
|
|
98
|
+
$[9] = t6;
|
|
99
|
+
$[10] = t7;
|
|
100
|
+
$[11] = t8;
|
|
101
|
+
$[12] = t9;
|
|
102
|
+
$[13] = t10;
|
|
103
|
+
} else {
|
|
104
|
+
t10 = $[13];
|
|
105
|
+
}
|
|
106
|
+
return t10;
|
|
107
|
+
}
|
|
108
|
+
function _temp5(item_3) {
|
|
109
|
+
return /* @__PURE__ */ jsx(HistoryItem, { item: item_3 }, item_3.index);
|
|
110
|
+
}
|
|
111
|
+
function _temp4(item_2) {
|
|
112
|
+
return /* @__PURE__ */ jsx(HistoryItem, { item: item_2 }, item_2.index);
|
|
113
|
+
}
|
|
114
|
+
function _temp3(item_1) {
|
|
115
|
+
return !item_1.favorite;
|
|
116
|
+
}
|
|
117
|
+
function _temp2(item_0) {
|
|
118
|
+
return item_0.favorite;
|
|
119
|
+
}
|
|
120
|
+
function _temp(item, i) {
|
|
121
|
+
return {
|
|
122
|
+
...item,
|
|
123
|
+
index: i
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function HistoryItem(props) {
|
|
127
|
+
const $ = c(40);
|
|
128
|
+
let t0;
|
|
129
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
130
|
+
t0 = {
|
|
131
|
+
nonNull: true,
|
|
132
|
+
caller: HistoryItem
|
|
133
|
+
};
|
|
134
|
+
$[0] = t0;
|
|
135
|
+
} else {
|
|
136
|
+
t0 = $[0];
|
|
137
|
+
}
|
|
138
|
+
const {
|
|
139
|
+
editLabel,
|
|
140
|
+
toggleFavorite,
|
|
141
|
+
deleteFromHistory,
|
|
142
|
+
setActive
|
|
143
|
+
} = useHistoryContext(t0);
|
|
144
|
+
let t1;
|
|
145
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
146
|
+
t1 = {
|
|
147
|
+
nonNull: true,
|
|
148
|
+
caller: HistoryItem
|
|
149
|
+
};
|
|
150
|
+
$[1] = t1;
|
|
151
|
+
} else {
|
|
152
|
+
t1 = $[1];
|
|
153
|
+
}
|
|
154
|
+
const {
|
|
155
|
+
headerEditor,
|
|
156
|
+
queryEditor,
|
|
157
|
+
variableEditor
|
|
158
|
+
} = useEditorContext(t1);
|
|
159
|
+
const inputRef = useRef(null);
|
|
160
|
+
const buttonRef = useRef(null);
|
|
161
|
+
const [isEditable, setIsEditable] = useState(false);
|
|
162
|
+
let t2;
|
|
163
|
+
let t3;
|
|
164
|
+
if ($[2] !== isEditable) {
|
|
165
|
+
t2 = () => {
|
|
166
|
+
var _a;
|
|
167
|
+
if (isEditable) {
|
|
168
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
t3 = [isEditable];
|
|
172
|
+
$[2] = isEditable;
|
|
173
|
+
$[3] = t2;
|
|
174
|
+
$[4] = t3;
|
|
175
|
+
} else {
|
|
176
|
+
t2 = $[3];
|
|
177
|
+
t3 = $[4];
|
|
178
|
+
}
|
|
179
|
+
useEffect(t2, t3);
|
|
180
|
+
let t4;
|
|
181
|
+
if ($[5] !== props.item.label || $[6] !== props.item.operationName || $[7] !== props.item.query) {
|
|
182
|
+
t4 = props.item.label || props.item.operationName || formatQuery(props.item.query);
|
|
183
|
+
$[5] = props.item.label;
|
|
184
|
+
$[6] = props.item.operationName;
|
|
185
|
+
$[7] = props.item.query;
|
|
186
|
+
$[8] = t4;
|
|
187
|
+
} else {
|
|
188
|
+
t4 = $[8];
|
|
189
|
+
}
|
|
190
|
+
const displayName = t4;
|
|
191
|
+
let t5;
|
|
192
|
+
if ($[9] !== editLabel || $[10] !== props.item) {
|
|
193
|
+
t5 = () => {
|
|
194
|
+
var _a;
|
|
195
|
+
setIsEditable(false);
|
|
196
|
+
const {
|
|
197
|
+
index,
|
|
198
|
+
...item
|
|
199
|
+
} = props.item;
|
|
200
|
+
editLabel({
|
|
201
|
+
...item,
|
|
202
|
+
label: (_a = inputRef.current) == null ? void 0 : _a.value
|
|
203
|
+
}, index);
|
|
204
|
+
};
|
|
205
|
+
$[9] = editLabel;
|
|
206
|
+
$[10] = props.item;
|
|
207
|
+
$[11] = t5;
|
|
208
|
+
} else {
|
|
209
|
+
t5 = $[11];
|
|
210
|
+
}
|
|
211
|
+
const handleSave = t5;
|
|
212
|
+
let t6;
|
|
213
|
+
if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
|
|
214
|
+
t6 = () => {
|
|
215
|
+
setIsEditable(false);
|
|
216
|
+
};
|
|
217
|
+
$[12] = t6;
|
|
218
|
+
} else {
|
|
219
|
+
t6 = $[12];
|
|
220
|
+
}
|
|
221
|
+
const handleClose = t6;
|
|
222
|
+
let t7;
|
|
223
|
+
if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
|
|
224
|
+
t7 = (e) => {
|
|
225
|
+
e.stopPropagation();
|
|
226
|
+
setIsEditable(true);
|
|
227
|
+
};
|
|
228
|
+
$[13] = t7;
|
|
229
|
+
} else {
|
|
230
|
+
t7 = $[13];
|
|
231
|
+
}
|
|
232
|
+
const handleEditLabel = t7;
|
|
233
|
+
let t8;
|
|
234
|
+
if ($[14] !== headerEditor || $[15] !== props.item || $[16] !== queryEditor || $[17] !== setActive || $[18] !== variableEditor) {
|
|
235
|
+
t8 = () => {
|
|
236
|
+
const {
|
|
237
|
+
query,
|
|
238
|
+
variables,
|
|
239
|
+
headers
|
|
240
|
+
} = props.item;
|
|
241
|
+
queryEditor == null ? void 0 : queryEditor.setValue(query ?? "");
|
|
242
|
+
variableEditor == null ? void 0 : variableEditor.setValue(variables ?? "");
|
|
243
|
+
headerEditor == null ? void 0 : headerEditor.setValue(headers ?? "");
|
|
244
|
+
setActive(props.item);
|
|
245
|
+
};
|
|
246
|
+
$[14] = headerEditor;
|
|
247
|
+
$[15] = props.item;
|
|
248
|
+
$[16] = queryEditor;
|
|
249
|
+
$[17] = setActive;
|
|
250
|
+
$[18] = variableEditor;
|
|
251
|
+
$[19] = t8;
|
|
252
|
+
} else {
|
|
253
|
+
t8 = $[19];
|
|
254
|
+
}
|
|
255
|
+
const handleHistoryItemClick = t8;
|
|
256
|
+
let t9;
|
|
257
|
+
if ($[20] !== deleteFromHistory || $[21] !== props.item) {
|
|
258
|
+
t9 = (e_0) => {
|
|
259
|
+
e_0.stopPropagation();
|
|
260
|
+
deleteFromHistory(props.item);
|
|
261
|
+
};
|
|
262
|
+
$[20] = deleteFromHistory;
|
|
263
|
+
$[21] = props.item;
|
|
264
|
+
$[22] = t9;
|
|
265
|
+
} else {
|
|
266
|
+
t9 = $[22];
|
|
267
|
+
}
|
|
268
|
+
const handleDeleteItemFromHistory = t9;
|
|
269
|
+
let t10;
|
|
270
|
+
if ($[23] !== props.item || $[24] !== toggleFavorite) {
|
|
271
|
+
t10 = (e_1) => {
|
|
272
|
+
e_1.stopPropagation();
|
|
273
|
+
toggleFavorite(props.item);
|
|
274
|
+
};
|
|
275
|
+
$[23] = props.item;
|
|
276
|
+
$[24] = toggleFavorite;
|
|
277
|
+
$[25] = t10;
|
|
278
|
+
} else {
|
|
279
|
+
t10 = $[25];
|
|
280
|
+
}
|
|
281
|
+
const handleToggleFavorite = t10;
|
|
282
|
+
const t11 = isEditable && "editable";
|
|
283
|
+
let t12;
|
|
284
|
+
if ($[26] !== t11) {
|
|
285
|
+
t12 = cn("graphiql-history-item", t11);
|
|
286
|
+
$[26] = t11;
|
|
287
|
+
$[27] = t12;
|
|
288
|
+
} else {
|
|
289
|
+
t12 = $[27];
|
|
290
|
+
}
|
|
291
|
+
let t13;
|
|
292
|
+
if ($[28] !== displayName || $[29] !== editLabel || $[30] !== handleDeleteItemFromHistory || $[31] !== handleHistoryItemClick || $[32] !== handleSave || $[33] !== handleToggleFavorite || $[34] !== isEditable || $[35] !== props.item) {
|
|
293
|
+
t13 = isEditable ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
294
|
+
/* @__PURE__ */ jsx("input", { type: "text", defaultValue: props.item.label, ref: inputRef, onKeyDown: (e_2) => {
|
|
295
|
+
if (e_2.key === "Esc") {
|
|
296
|
+
setIsEditable(false);
|
|
297
|
+
} else {
|
|
298
|
+
if (e_2.key === "Enter") {
|
|
299
|
+
setIsEditable(false);
|
|
300
|
+
editLabel({
|
|
301
|
+
...props.item,
|
|
302
|
+
label: e_2.currentTarget.value
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}, placeholder: "Type a label" }),
|
|
307
|
+
/* @__PURE__ */ jsx(UnStyledButton, { type: "button", ref: buttonRef, onClick: handleSave, children: "Save" }),
|
|
308
|
+
/* @__PURE__ */ jsx(UnStyledButton, { type: "button", ref: buttonRef, onClick: handleClose, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
309
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
310
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Set active", children: /* @__PURE__ */ jsx(UnStyledButton, { type: "button", className: "graphiql-history-item-label", onClick: handleHistoryItemClick, "aria-label": "Set active", children: displayName }) }),
|
|
311
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Edit label", children: /* @__PURE__ */ jsx(UnStyledButton, { type: "button", className: "graphiql-history-item-action", onClick: handleEditLabel, "aria-label": "Edit label", children: /* @__PURE__ */ jsx(PenIcon, { "aria-hidden": "true" }) }) }),
|
|
312
|
+
/* @__PURE__ */ jsx(Tooltip, { label: props.item.favorite ? "Remove favorite" : "Add favorite", children: /* @__PURE__ */ jsx(UnStyledButton, { type: "button", className: "graphiql-history-item-action", onClick: handleToggleFavorite, "aria-label": props.item.favorite ? "Remove favorite" : "Add favorite", children: props.item.favorite ? /* @__PURE__ */ jsx(StarFilledIcon, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(StarIcon, { "aria-hidden": "true" }) }) }),
|
|
313
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Delete from history", children: /* @__PURE__ */ jsx(UnStyledButton, { type: "button", className: "graphiql-history-item-action", onClick: handleDeleteItemFromHistory, "aria-label": "Delete from history", children: /* @__PURE__ */ jsx(TrashIcon, { "aria-hidden": "true" }) }) })
|
|
314
|
+
] });
|
|
315
|
+
$[28] = displayName;
|
|
316
|
+
$[29] = editLabel;
|
|
317
|
+
$[30] = handleDeleteItemFromHistory;
|
|
318
|
+
$[31] = handleHistoryItemClick;
|
|
319
|
+
$[32] = handleSave;
|
|
320
|
+
$[33] = handleToggleFavorite;
|
|
321
|
+
$[34] = isEditable;
|
|
322
|
+
$[35] = props.item;
|
|
323
|
+
$[36] = t13;
|
|
324
|
+
} else {
|
|
325
|
+
t13 = $[36];
|
|
326
|
+
}
|
|
327
|
+
let t14;
|
|
328
|
+
if ($[37] !== t12 || $[38] !== t13) {
|
|
329
|
+
t14 = /* @__PURE__ */ jsx("li", { className: t12, children: t13 });
|
|
330
|
+
$[37] = t12;
|
|
331
|
+
$[38] = t13;
|
|
332
|
+
$[39] = t14;
|
|
333
|
+
} else {
|
|
334
|
+
t14 = $[39];
|
|
335
|
+
}
|
|
336
|
+
return t14;
|
|
337
|
+
}
|
|
338
|
+
function formatQuery(query) {
|
|
339
|
+
return query == null ? void 0 : query.split("\n").map((line) => line.replace(/#(.*)/, "")).join(" ").replaceAll("{", " { ").replaceAll("}", " } ").replaceAll(/[\s]{2,}/g, " ");
|
|
340
|
+
}
|
|
341
|
+
export {
|
|
342
|
+
History,
|
|
343
|
+
HistoryItem,
|
|
344
|
+
formatQuery
|
|
345
|
+
};
|
|
346
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../src/components.tsx"],"sourcesContent":["import type { QueryStoreItem } from '@graphiql/toolkit';\nimport { MouseEventHandler, useEffect, useRef, useState } from 'react';\nimport {\n cn,\n CloseIcon,\n PenIcon,\n StarFilledIcon,\n StarIcon,\n TrashIcon,\n useEditorContext,\n Button,\n Tooltip,\n UnStyledButton,\n} from '@graphiql/react';\nimport { HistoryContextType, useHistoryContext } from './context';\n\n// Fix error from react-compiler\n// Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement\nfunction handleDelete(\n items: QueryStoreItem[],\n deleteFromHistory: HistoryContextType['deleteFromHistory'],\n) {\n for (const item of items) {\n deleteFromHistory(item, true);\n }\n}\n\nexport function History() {\n const { items: all, deleteFromHistory } = useHistoryContext({\n nonNull: true,\n });\n\n // Reverse items since we push them in so want the latest one at the top, and pass the\n // original index in case multiple items share the same label so we can edit correct item\n let items = all\n .slice()\n .map((item, i) => ({ ...item, index: i }))\n .reverse();\n const favorites = items.filter(item => item.favorite);\n if (favorites.length) {\n items = items.filter(item => !item.favorite);\n }\n\n const [clearStatus, setClearStatus] = useState<'success' | 'error' | null>(\n null,\n );\n useEffect(() => {\n if (clearStatus) {\n // reset the button after a couple seconds\n setTimeout(() => {\n setClearStatus(null);\n }, 2000);\n }\n }, [clearStatus]);\n\n const handleClearStatus = () => {\n try {\n handleDelete(items, deleteFromHistory);\n setClearStatus('success');\n } catch {\n setClearStatus('error');\n }\n };\n const hasFavorites = Boolean(favorites.length);\n const hasItems = Boolean(items.length);\n\n return (\n <section aria-label=\"History\" className=\"graphiql-history\">\n <div className=\"graphiql-history-header\">\n History\n {(clearStatus || hasItems) && (\n <Button\n type=\"button\"\n state={clearStatus || undefined}\n disabled={!items.length}\n onClick={handleClearStatus}\n >\n {{\n success: 'Cleared',\n error: 'Failed to Clear',\n }[clearStatus!] || 'Clear'}\n </Button>\n )}\n </div>\n\n {hasFavorites && (\n <ul className=\"graphiql-history-items\">\n {favorites.map(item => (\n <HistoryItem item={item} key={item.index} />\n ))}\n </ul>\n )}\n\n {hasFavorites && hasItems && (\n <div className=\"graphiql-history-item-spacer\" />\n )}\n\n {hasItems && (\n <ul className=\"graphiql-history-items\">\n {items.map(item => (\n <HistoryItem item={item} key={item.index} />\n ))}\n </ul>\n )}\n </section>\n );\n}\n\ntype QueryHistoryItemProps = {\n item: QueryStoreItem & { index?: number };\n};\n\nexport function HistoryItem(props: QueryHistoryItemProps) {\n const { editLabel, toggleFavorite, deleteFromHistory, setActive } =\n useHistoryContext({\n nonNull: true,\n caller: HistoryItem,\n });\n const { headerEditor, queryEditor, variableEditor } = useEditorContext({\n nonNull: true,\n caller: HistoryItem,\n });\n const inputRef = useRef<HTMLInputElement>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [isEditable, setIsEditable] = useState(false);\n\n useEffect(() => {\n if (isEditable) {\n inputRef.current?.focus();\n }\n }, [isEditable]);\n\n const displayName =\n props.item.label ||\n props.item.operationName ||\n formatQuery(props.item.query);\n\n const handleSave = () => {\n setIsEditable(false);\n const { index, ...item } = props.item;\n editLabel({ ...item, label: inputRef.current?.value }, index);\n };\n\n const handleClose = () => {\n setIsEditable(false);\n };\n\n const handleEditLabel: MouseEventHandler<HTMLButtonElement> = e => {\n e.stopPropagation();\n setIsEditable(true);\n };\n\n const handleHistoryItemClick: MouseEventHandler<HTMLButtonElement> = () => {\n const { query, variables, headers } = props.item;\n queryEditor?.setValue(query ?? '');\n variableEditor?.setValue(variables ?? '');\n headerEditor?.setValue(headers ?? '');\n setActive(props.item);\n };\n\n const handleDeleteItemFromHistory: MouseEventHandler<\n HTMLButtonElement\n > = e => {\n e.stopPropagation();\n deleteFromHistory(props.item);\n };\n\n const handleToggleFavorite: MouseEventHandler<HTMLButtonElement> = e => {\n e.stopPropagation();\n toggleFavorite(props.item);\n };\n\n return (\n <li className={cn('graphiql-history-item', isEditable && 'editable')}>\n {isEditable ? (\n <>\n <input\n type=\"text\"\n defaultValue={props.item.label}\n ref={inputRef}\n onKeyDown={e => {\n if (e.key === 'Esc') {\n setIsEditable(false);\n } else if (e.key === 'Enter') {\n setIsEditable(false);\n editLabel({ ...props.item, label: e.currentTarget.value });\n }\n }}\n placeholder=\"Type a label\"\n />\n <UnStyledButton type=\"button\" ref={buttonRef} onClick={handleSave}>\n Save\n </UnStyledButton>\n <UnStyledButton type=\"button\" ref={buttonRef} onClick={handleClose}>\n <CloseIcon />\n </UnStyledButton>\n </>\n ) : (\n <>\n <Tooltip label=\"Set active\">\n <UnStyledButton\n type=\"button\"\n className=\"graphiql-history-item-label\"\n onClick={handleHistoryItemClick}\n aria-label=\"Set active\"\n >\n {displayName}\n </UnStyledButton>\n </Tooltip>\n <Tooltip label=\"Edit label\">\n <UnStyledButton\n type=\"button\"\n className=\"graphiql-history-item-action\"\n onClick={handleEditLabel}\n aria-label=\"Edit label\"\n >\n <PenIcon aria-hidden=\"true\" />\n </UnStyledButton>\n </Tooltip>\n <Tooltip\n label={props.item.favorite ? 'Remove favorite' : 'Add favorite'}\n >\n <UnStyledButton\n type=\"button\"\n className=\"graphiql-history-item-action\"\n onClick={handleToggleFavorite}\n aria-label={\n props.item.favorite ? 'Remove favorite' : 'Add favorite'\n }\n >\n {props.item.favorite ? (\n <StarFilledIcon aria-hidden=\"true\" />\n ) : (\n <StarIcon aria-hidden=\"true\" />\n )}\n </UnStyledButton>\n </Tooltip>\n <Tooltip label=\"Delete from history\">\n <UnStyledButton\n type=\"button\"\n className=\"graphiql-history-item-action\"\n onClick={handleDeleteItemFromHistory}\n aria-label=\"Delete from history\"\n >\n <TrashIcon aria-hidden=\"true\" />\n </UnStyledButton>\n </Tooltip>\n </>\n )}\n </li>\n );\n}\n\nexport function formatQuery(query?: string) {\n return query\n ?.split('\\n')\n .map(line => line.replace(/#(.*)/, ''))\n .join(' ')\n .replaceAll('{', ' { ')\n .replaceAll('}', ' } ')\n .replaceAll(/[\\s]{2,}/g, ' ');\n}\n"],"names":["handleDelete","items","deleteFromHistory","item","History","$","_c","t0","Symbol","for","nonNull","all","useHistoryContext","slice","map","_temp","reverse","favorites","filter","_temp2","length","_temp3","clearStatus","setClearStatus","useState","t1","t2","setTimeout","useEffect","handleClearStatus","hasFavorites","Boolean","hasItems","t3","t4","t5","undefined","success","error","t6","t7","_temp4","t8","t9","_temp5","t10","item_3","index","item_2","item_1","favorite","item_0","i","HistoryItem","props","caller","editLabel","toggleFavorite","setActive","headerEditor","queryEditor","variableEditor","useEditorContext","inputRef","useRef","buttonRef","isEditable","setIsEditable","current","focus","label","operationName","query","formatQuery","displayName","value","handleSave","handleClose","e","stopPropagation","handleEditLabel","variables","headers","setValue","handleHistoryItemClick","e_0","handleDeleteItemFromHistory","e_1","handleToggleFavorite","t11","t12","cn","t13","e_2","key","currentTarget","t14","split","line","replace","join","replaceAll"],"mappings":";;;;;AAkBA,SAASA,aACPC,OACAC,mBACA;AACA,aAAWC,QA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,CAAA,GACF;AAAA,0BACC,SAAc,EAAA,OAAA,uBACb,UAAC,oBAAA,gBAAA,EACM,MAAA,UACK,WAAA,gCACDoC,SAA0B,6BACxB,cAAA,uBAEX,UAAA,oBAAC,aAAsB,eAAA,OAAM,CAAA,EAC/B,CAAA,EACF,CAAA;AAAA,IAAA,GAAU;AAEbjF,YAAAqE;AAAArE,YAAAmD;AAAAnD,YAAAiF;AAAAjF,YAAA+E;AAAA/E,YAAAuE;AAAAvE,YAAAmF;AAAAnF,YAAA6D;AAAA,MAAA,EAAA,IAAAZ,MAAAnD;AAAAE,YAAAuF;AAAAA,EAAAA,OAAA;AAAAA,UAAAvF,EAAA,EAAA;AAAA,EAAA;AAAA2F,MAAAA;AAAA,MAAA3F,EAAAqF,EAAAA,MAAAA,OAAArF,UAAAuF,KAAA;AA3EHI,UA4EK,oBAAA,MAAA,EA5EU,WAAAN,KACZE,UA2EH,KAAA;AAAKvF,YAAAqF;AAAArF,YAAAuF;AAAAvF,YAAA2F;AAAAA,EAAAA,OAAA;AAAAA,UAAA3F,EAAA,EAAA;AAAA,EAAA;AA5EL2F,SAAAA;AA4EK;AAIF,SAASvB,YAAYD,OAAgB;AACnCA,SAAAA,+BACHyB,MAAM,MACPnF,IAAIoF,UAAQA,KAAKC,QAAQ,SAAS,EAAE,GACpCC,KAAK,KACLC,WAAW,KAAK,OAChBA,WAAW,KAAK,OAChBA,WAAW,aAAa;AAC7B;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { QueryStoreItem } from '@graphiql/toolkit';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export declare type HistoryContextType = {
|
|
4
|
+
/**
|
|
5
|
+
* Add an operation to the history.
|
|
6
|
+
* @param operation The operation that was executed, consisting of the query,
|
|
7
|
+
* variables, headers, and operation name.
|
|
8
|
+
*/
|
|
9
|
+
addToHistory(operation: {
|
|
10
|
+
query?: string;
|
|
11
|
+
variables?: string;
|
|
12
|
+
headers?: string;
|
|
13
|
+
operationName?: string;
|
|
14
|
+
}): void;
|
|
15
|
+
/**
|
|
16
|
+
* Change the custom label of an item from the history.
|
|
17
|
+
* @param args An object containing the label (`undefined` if it should be
|
|
18
|
+
* unset) and properties that identify the history item that the label should
|
|
19
|
+
* be applied to. (This can result in the label being applied to multiple
|
|
20
|
+
* history items.)
|
|
21
|
+
* @param index Index to edit. Without it, will look for the first index matching the
|
|
22
|
+
* operation, which may lead to misleading results if multiple items have the same label
|
|
23
|
+
*/
|
|
24
|
+
editLabel(args: {
|
|
25
|
+
query?: string;
|
|
26
|
+
variables?: string;
|
|
27
|
+
headers?: string;
|
|
28
|
+
operationName?: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
favorite?: boolean;
|
|
31
|
+
}, index?: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* The list of history items.
|
|
34
|
+
*/
|
|
35
|
+
items: readonly QueryStoreItem[];
|
|
36
|
+
/**
|
|
37
|
+
* Toggle the favorite state of an item from the history.
|
|
38
|
+
* @param args An object containing the favorite state (`undefined` if it
|
|
39
|
+
* should be unset) and properties that identify the history item that the
|
|
40
|
+
* label should be applied to. (This can result in the label being applied
|
|
41
|
+
* to multiple history items.)
|
|
42
|
+
*/
|
|
43
|
+
toggleFavorite(args: {
|
|
44
|
+
query?: string;
|
|
45
|
+
variables?: string;
|
|
46
|
+
headers?: string;
|
|
47
|
+
operationName?: string;
|
|
48
|
+
label?: string;
|
|
49
|
+
favorite?: boolean;
|
|
50
|
+
}): void;
|
|
51
|
+
/**
|
|
52
|
+
* Delete an operation from the history.
|
|
53
|
+
* @param args The operation that was executed, consisting of the query,
|
|
54
|
+
* variables, headers, and operation name.
|
|
55
|
+
* @param clearFavorites This is only if you press the 'clear' button
|
|
56
|
+
*/
|
|
57
|
+
deleteFromHistory(args: QueryStoreItem, clearFavorites?: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* If you need to know when an item in history is set as active to customize
|
|
60
|
+
* your application.
|
|
61
|
+
*/
|
|
62
|
+
setActive(args: QueryStoreItem): void;
|
|
63
|
+
};
|
|
64
|
+
export declare const HistoryContext: import('react').Context<HistoryContextType | null>;
|
|
65
|
+
declare type HistoryContextProviderProps = {
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* The maximum number of executed operations to store.
|
|
69
|
+
* @default 20
|
|
70
|
+
*/
|
|
71
|
+
maxHistoryLength?: number;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The functions send the entire operation so users can customize their own application with
|
|
75
|
+
* <HistoryContext.Provider value={customizedFunctions} /> and get access to the operation plus
|
|
76
|
+
* any additional props they added for their needs (i.e., build their own functions that may save
|
|
77
|
+
* to a backend instead of localStorage and might need an id property added to the QueryStoreItem)
|
|
78
|
+
*/
|
|
79
|
+
export declare function HistoryContextProvider({ maxHistoryLength, children, }: HistoryContextProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
80
|
+
export declare const useHistoryContext: {
|
|
81
|
+
(options: {
|
|
82
|
+
nonNull: true;
|
|
83
|
+
caller?: Function | undefined;
|
|
84
|
+
}): HistoryContextType;
|
|
85
|
+
(options: {
|
|
86
|
+
nonNull?: boolean | undefined;
|
|
87
|
+
caller?: Function | undefined;
|
|
88
|
+
}): HistoryContextType | null;
|
|
89
|
+
(): HistoryContextType | null;
|
|
90
|
+
};
|
|
91
|
+
export {};
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react-compiler-runtime";
|
|
3
|
+
import { HistoryStore, StorageAPI } from "@graphiql/toolkit";
|
|
4
|
+
import { useState, useEffect } from "react";
|
|
5
|
+
import { createNullableContext, createContextHook, useStorageContext, useExecutionContext, useEditorContext } from "@graphiql/react";
|
|
6
|
+
const HistoryContext = createNullableContext("HistoryContext");
|
|
7
|
+
function HistoryContextProvider(t0) {
|
|
8
|
+
const $ = c(18);
|
|
9
|
+
const {
|
|
10
|
+
maxHistoryLength: t1,
|
|
11
|
+
children
|
|
12
|
+
} = t0;
|
|
13
|
+
const maxHistoryLength = t1 === void 0 ? DEFAULT_HISTORY_LENGTH : t1;
|
|
14
|
+
const storage = useStorageContext();
|
|
15
|
+
let t2;
|
|
16
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
17
|
+
t2 = {
|
|
18
|
+
nonNull: true
|
|
19
|
+
};
|
|
20
|
+
$[0] = t2;
|
|
21
|
+
} else {
|
|
22
|
+
t2 = $[0];
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
isFetching
|
|
26
|
+
} = useExecutionContext(t2);
|
|
27
|
+
let t3;
|
|
28
|
+
if ($[1] !== maxHistoryLength || $[2] !== storage) {
|
|
29
|
+
t3 = () => new HistoryStore(storage || new StorageAPI(null), maxHistoryLength);
|
|
30
|
+
$[1] = maxHistoryLength;
|
|
31
|
+
$[2] = storage;
|
|
32
|
+
$[3] = t3;
|
|
33
|
+
} else {
|
|
34
|
+
t3 = $[3];
|
|
35
|
+
}
|
|
36
|
+
const [historyStore] = useState(t3);
|
|
37
|
+
let t4;
|
|
38
|
+
if ($[4] !== historyStore.queries) {
|
|
39
|
+
t4 = () => historyStore.queries || [];
|
|
40
|
+
$[4] = historyStore.queries;
|
|
41
|
+
$[5] = t4;
|
|
42
|
+
} else {
|
|
43
|
+
t4 = $[5];
|
|
44
|
+
}
|
|
45
|
+
const [items, setItems] = useState(t4);
|
|
46
|
+
let t5;
|
|
47
|
+
if ($[6] !== historyStore || $[7] !== items) {
|
|
48
|
+
t5 = {
|
|
49
|
+
addToHistory(operation) {
|
|
50
|
+
historyStore.updateHistory(operation);
|
|
51
|
+
setItems(historyStore.queries);
|
|
52
|
+
},
|
|
53
|
+
editLabel(operation_0, index) {
|
|
54
|
+
historyStore.editLabel(operation_0, index);
|
|
55
|
+
setItems(historyStore.queries);
|
|
56
|
+
},
|
|
57
|
+
items,
|
|
58
|
+
toggleFavorite(operation_1) {
|
|
59
|
+
historyStore.toggleFavorite(operation_1);
|
|
60
|
+
setItems(historyStore.queries);
|
|
61
|
+
},
|
|
62
|
+
setActive: _temp,
|
|
63
|
+
deleteFromHistory(item_0, clearFavorites) {
|
|
64
|
+
historyStore.deleteHistory(item_0, clearFavorites);
|
|
65
|
+
setItems(historyStore.queries);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
$[6] = historyStore;
|
|
69
|
+
$[7] = items;
|
|
70
|
+
$[8] = t5;
|
|
71
|
+
} else {
|
|
72
|
+
t5 = $[8];
|
|
73
|
+
}
|
|
74
|
+
const value = t5;
|
|
75
|
+
let t6;
|
|
76
|
+
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
77
|
+
t6 = {
|
|
78
|
+
nonNull: true
|
|
79
|
+
};
|
|
80
|
+
$[9] = t6;
|
|
81
|
+
} else {
|
|
82
|
+
t6 = $[9];
|
|
83
|
+
}
|
|
84
|
+
const {
|
|
85
|
+
tabs,
|
|
86
|
+
activeTabIndex
|
|
87
|
+
} = useEditorContext(t6);
|
|
88
|
+
const activeTab = tabs[activeTabIndex];
|
|
89
|
+
const {
|
|
90
|
+
addToHistory
|
|
91
|
+
} = value;
|
|
92
|
+
let t7;
|
|
93
|
+
let t8;
|
|
94
|
+
if ($[10] !== activeTab || $[11] !== addToHistory || $[12] !== isFetching) {
|
|
95
|
+
t7 = () => {
|
|
96
|
+
if (!isFetching) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
addToHistory({
|
|
100
|
+
query: activeTab.query ?? void 0,
|
|
101
|
+
variables: activeTab.variables ?? void 0,
|
|
102
|
+
headers: activeTab.headers ?? void 0,
|
|
103
|
+
operationName: activeTab.operationName ?? void 0
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
t8 = [isFetching, activeTab, addToHistory];
|
|
107
|
+
$[10] = activeTab;
|
|
108
|
+
$[11] = addToHistory;
|
|
109
|
+
$[12] = isFetching;
|
|
110
|
+
$[13] = t7;
|
|
111
|
+
$[14] = t8;
|
|
112
|
+
} else {
|
|
113
|
+
t7 = $[13];
|
|
114
|
+
t8 = $[14];
|
|
115
|
+
}
|
|
116
|
+
useEffect(t7, t8);
|
|
117
|
+
let t9;
|
|
118
|
+
if ($[15] !== children || $[16] !== value) {
|
|
119
|
+
t9 = /* @__PURE__ */ jsx(HistoryContext.Provider, { value, children });
|
|
120
|
+
$[15] = children;
|
|
121
|
+
$[16] = value;
|
|
122
|
+
$[17] = t9;
|
|
123
|
+
} else {
|
|
124
|
+
t9 = $[17];
|
|
125
|
+
}
|
|
126
|
+
return t9;
|
|
127
|
+
}
|
|
128
|
+
function _temp(item) {
|
|
129
|
+
return item;
|
|
130
|
+
}
|
|
131
|
+
const useHistoryContext = createContextHook(HistoryContext);
|
|
132
|
+
const DEFAULT_HISTORY_LENGTH = 20;
|
|
133
|
+
export {
|
|
134
|
+
HistoryContext,
|
|
135
|
+
HistoryContextProvider,
|
|
136
|
+
useHistoryContext
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["import { HistoryStore, QueryStoreItem, StorageAPI } from '@graphiql/toolkit';\nimport { ReactNode, useEffect, useState } from 'react';\nimport {\n useStorageContext,\n createNullableContext,\n createContextHook,\n useExecutionContext,\n useEditorContext,\n} from '@graphiql/react';\n\nexport type HistoryContextType = {\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 * The list of history items.\n */\n items: readonly QueryStoreItem[];\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\nexport const HistoryContext =\n createNullableContext<HistoryContextType>('HistoryContext');\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 function HistoryContextProvider({\n maxHistoryLength = DEFAULT_HISTORY_LENGTH,\n children,\n}: HistoryContextProviderProps) {\n const storage = useStorageContext();\n const { isFetching } = useExecutionContext({ nonNull: true });\n const [historyStore] = useState(\n () =>\n // Fall back to a noop storage when the StorageContext is empty\n new HistoryStore(storage || new StorageAPI(null), maxHistoryLength),\n );\n const [items, setItems] = useState(() => historyStore.queries || []);\n\n const value: HistoryContextType = {\n addToHistory(operation) {\n historyStore.updateHistory(operation);\n setItems(historyStore.queries);\n },\n editLabel(operation, index) {\n historyStore.editLabel(operation, index);\n setItems(historyStore.queries);\n },\n items,\n toggleFavorite(operation) {\n historyStore.toggleFavorite(operation);\n setItems(historyStore.queries);\n },\n setActive: item => item,\n deleteFromHistory(item, clearFavorites) {\n historyStore.deleteHistory(item, clearFavorites);\n setItems(historyStore.queries);\n },\n };\n const { tabs, activeTabIndex } = useEditorContext({ nonNull: true });\n const activeTab = tabs[activeTabIndex];\n const { addToHistory } = value;\n\n useEffect(() => {\n if (!isFetching) {\n return;\n }\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, addToHistory]);\n\n return (\n <HistoryContext.Provider value={value}>{children}</HistoryContext.Provider>\n );\n}\n\nexport const useHistoryContext =\n createContextHook<HistoryContextType>(HistoryContext);\n\nconst DEFAULT_HISTORY_LENGTH = 20;\n"],"names":["HistoryContext","createNullableContext","HistoryContextProvider","t0","$","_c","maxHistoryLength","t1","children","undefined","DEFAULT_HISTORY_LENGTH","storage","useStorageContext","t2","Symbol","for","nonNull","isFetching","useExecutionContext","t3","HistoryStore","StorageAPI","historyStore","useState","t4","queries","items","setItems","t5","addToHistory","operation","updateHistory","editLabel","operation_0","index","toggleFavorite","operation_1","setActive","_temp","deleteFromHistory","item_0","clearFavorites","deleteHistory","item","value","t6","tabs","activeTabIndex","useEditorContext","activeTab","t7","t8","query","variables","headers","operationName","useEffect","t9","useHistoryContext","createContextHook"],"mappings":";;;;;AA2EaA,MAAAA,iBACXC,sBAA0C,gBAAgB;AAiBrD,SAAAC,uBAAAC,IAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA;AAAgC,QAAA;AAAA,IAAAC,kBAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAAAL;AACrCG,QAAAA,mBAAAC,OAAyCE,SAAAC,yBAAzCH;AAGA,QAAAI,UAAgBC,kBAAkB;AAAEC,MAAAA;AAAA,MAAAT,EAAA,CAAA,MAAAU,OAAAC,IAAA,2BAAA,GAAA;AACO,SAAA;AAAA,MAAAC,SAAA;AAAA,IAAA;AAAiBZ,WAAAS;AA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Ca,SAAA,oBAAA,eAAA,UAAA,EAAgCb,OAAQpC,UAAS;AAA0BJ,YAAAI;AAAAJ,YAAAwC;AAAAxC,YAAAqD;AAAAA,EAAAA,OAAA;AAAAA,SAAArD,EAAA,EAAA;AAAA,EAAA;AAA3EqD,SAAAA;AAA2E;AAlDxE,SAAAnB,MAAAK,MAAA;AA2BgBA,SAAAA;AAAI;AA2Bde,MAAAA,oBACXC,kBAAsC3D,cAAc;AAEtD,MAAMU,yBAAyB;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GraphiQLPlugin } from '@graphiql/react';
|
|
2
|
+
import { History } from './components';
|
|
3
|
+
export declare const HISTORY_PLUGIN: GraphiQLPlugin;
|
|
4
|
+
export { History };
|
|
5
|
+
export { HistoryContext, HistoryContextProvider, useHistoryContext, type HistoryContextType, } from './context';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HistoryIcon } from "@graphiql/react";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { History } from "./components.js";
|
|
4
|
+
import { HistoryContext, HistoryContextProvider, useHistoryContext } from "./context.js";
|
|
5
|
+
const HISTORY_PLUGIN = {
|
|
6
|
+
title: "History",
|
|
7
|
+
icon: HistoryIcon,
|
|
8
|
+
content: History
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
HISTORY_PLUGIN,
|
|
12
|
+
History,
|
|
13
|
+
HistoryContext,
|
|
14
|
+
HistoryContextProvider,
|
|
15
|
+
useHistoryContext
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { GraphiQLPlugin, HistoryIcon } from '@graphiql/react';\nimport './style.css';\n\nimport { History } from './components';\n\nexport const HISTORY_PLUGIN: GraphiQLPlugin = {\n title: 'History',\n icon: HistoryIcon,\n content: History,\n};\n\nexport { History };\n\nexport {\n HistoryContext,\n HistoryContextProvider,\n useHistoryContext,\n type HistoryContextType,\n} from './context';\n"],"names":["HISTORY_PLUGIN","title","icon","HistoryIcon","content","History"],"mappings":";;;;AAKO,MAAMA,iBAAiC;AAAA,EAC5CC,OAAO;AAAA,EACPC,MAAMC;AAAAA,EACNC,SAASC;AACX;"}
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
.graphiql-history-header {
|
|
2
|
+
font-size: var(--font-size-h2);
|
|
3
|
+
font-weight: var(--font-weight-medium);
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
align-items: center;
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.graphiql-history-header button {
|
|
10
|
+
font-size: var(--font-size-inline-code);
|
|
11
|
+
padding: var(--px-6) var(--px-10);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.graphiql-history-items {
|
|
15
|
+
margin: var(--px-16) 0 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
list-style: none;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.graphiql-history-item {
|
|
21
|
+
border-radius: var(--border-radius-4);
|
|
22
|
+
color: hsla(var(--color-neutral), var(--alpha-secondary));
|
|
23
|
+
font-size: var(--font-size-inline-code);
|
|
24
|
+
font-family: var(--font-family-mono);
|
|
25
|
+
height: 34px;
|
|
26
|
+
display: flex;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.graphiql-history-item:hover {
|
|
30
|
+
color: hsl(var(--color-neutral));
|
|
31
|
+
background-color: hsla(var(--color-neutral), var(--alpha-background-light));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.graphiql-history-item:not(:first-child) {
|
|
35
|
+
margin-top: var(--px-4);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.graphiql-history-item.editable {
|
|
39
|
+
background-color: hsla(var(--color-primary), var(--alpha-background-medium));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.graphiql-history-item.editable > input {
|
|
43
|
+
padding: 0 var(--px-10);
|
|
44
|
+
background: none;
|
|
45
|
+
border: none;
|
|
46
|
+
outline: none;
|
|
47
|
+
flex: 1;
|
|
48
|
+
width: 100%;
|
|
49
|
+
margin: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.graphiql-history-item.editable > input::placeholder {
|
|
53
|
+
color: hsla(var(--color-neutral), var(--alpha-secondary));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.graphiql-history-item.editable > button {
|
|
57
|
+
color: hsl(var(--color-primary));
|
|
58
|
+
padding: 0 var(--px-10);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.graphiql-history-item.editable > button:active {
|
|
62
|
+
background-color: hsla(var(--color-primary), var(--alpha-background-heavy));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.graphiql-history-item.editable > button:focus {
|
|
66
|
+
outline: hsl(var(--color-primary)) auto 1px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.graphiql-history-item.editable > button > svg {
|
|
70
|
+
display: block;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
button.graphiql-history-item-label {
|
|
74
|
+
padding: var(--px-8) var(--px-10);
|
|
75
|
+
text-overflow: ellipsis;
|
|
76
|
+
white-space: nowrap;
|
|
77
|
+
flex: 1;
|
|
78
|
+
overflow: hidden;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
button.graphiql-history-item-action {
|
|
82
|
+
color: hsla(var(--color-neutral), var(--alpha-secondary));
|
|
83
|
+
padding: var(--px-8) var(--px-6);
|
|
84
|
+
align-items: center;
|
|
85
|
+
display: flex;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
button.graphiql-history-item-action:hover {
|
|
89
|
+
color: hsl(var(--color-neutral));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
button.graphiql-history-item-action > svg {
|
|
93
|
+
width: 14px;
|
|
94
|
+
height: 14px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.graphiql-history-item-spacer {
|
|
98
|
+
height: var(--px-16);
|
|
99
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphiql/plugin-history",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/graphql/graphiql",
|
|
8
|
+
"directory": "packages/graphiql-plugin-history"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/graphql/graphiql/tree/master/packages/graphiql-plugin-history#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/graphql/graphiql/issues?q=issue+label:@graphiql/plugin-history"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
"./style.css": "./dist/style.css",
|
|
18
|
+
".": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"react",
|
|
23
|
+
"graphql",
|
|
24
|
+
"graphiql",
|
|
25
|
+
"plugin",
|
|
26
|
+
"history"
|
|
27
|
+
],
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite build --watch",
|
|
33
|
+
"build": "vite build",
|
|
34
|
+
"test": "vitest",
|
|
35
|
+
"types:check": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^18 || ^19",
|
|
39
|
+
"react-dom": "^18 || ^19"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"react-compiler-runtime": "19.1.0-rc.1",
|
|
43
|
+
"@graphiql/toolkit": "^0.11.2",
|
|
44
|
+
"@graphiql/react": "^0.30.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@testing-library/react": "^16.1.0",
|
|
48
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
49
|
+
"vite-plugin-dts": "^4.5.3",
|
|
50
|
+
"babel-plugin-react-compiler": "19.1.0-rc.1",
|
|
51
|
+
"react": "^19.1.0",
|
|
52
|
+
"react-dom": "^19.1.0",
|
|
53
|
+
"vite": "^6.3.4"
|
|
54
|
+
}
|
|
55
|
+
}
|