@graphiql/plugin-doc-explorer 1.0.0-beta.1 → 1.0.0-beta.3

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/argument.js +88 -92
  3. package/dist/components/argument.js.map +1 -1
  4. package/dist/components/arguments-list.js +226 -237
  5. package/dist/components/arguments-list.js.map +1 -1
  6. package/dist/components/breadcrumb.js +59 -52
  7. package/dist/components/breadcrumb.js.map +1 -1
  8. package/dist/components/default-value.js +63 -74
  9. package/dist/components/default-value.js.map +1 -1
  10. package/dist/components/deprecation-reason.js +27 -21
  11. package/dist/components/deprecation-reason.js.map +1 -1
  12. package/dist/components/directive.js +20 -23
  13. package/dist/components/directive.js.map +1 -1
  14. package/dist/components/doc-explorer.js +219 -259
  15. package/dist/components/doc-explorer.js.map +1 -1
  16. package/dist/components/field-card.js +103 -97
  17. package/dist/components/field-card.js.map +1 -1
  18. package/dist/components/field-documentation.js +118 -135
  19. package/dist/components/field-documentation.js.map +1 -1
  20. package/dist/components/field-link.js +37 -39
  21. package/dist/components/field-link.js.map +1 -1
  22. package/dist/components/fields-list.js +216 -226
  23. package/dist/components/fields-list.js.map +1 -1
  24. package/dist/components/schema-documentation.js +263 -224
  25. package/dist/components/schema-documentation.js.map +1 -1
  26. package/dist/components/search-row.js +287 -268
  27. package/dist/components/search-row.js.map +1 -1
  28. package/dist/components/search.js +342 -345
  29. package/dist/components/search.js.map +1 -1
  30. package/dist/components/section.js +59 -69
  31. package/dist/components/section.js.map +1 -1
  32. package/dist/components/type-card.js +104 -107
  33. package/dist/components/type-card.js.map +1 -1
  34. package/dist/components/type-documentation.js +340 -363
  35. package/dist/components/type-documentation.js.map +1 -1
  36. package/dist/components/type-link.js +38 -39
  37. package/dist/components/type-link.js.map +1 -1
  38. package/dist/components/utils.js +15 -20
  39. package/dist/components/utils.js.map +1 -1
  40. package/dist/context.js +205 -285
  41. package/dist/context.js.map +1 -1
  42. package/dist/index.js +7 -31
  43. package/dist/schema-reference.js +48 -54
  44. package/dist/schema-reference.js.map +1 -1
  45. package/dist/style.css +24 -28
  46. package/package.json +25 -19
  47. package/dist/index.js.map +0 -1
package/dist/context.js CHANGED
@@ -1,299 +1,219 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { getSchemaReference } from "./schema-reference.js";
2
+ import { DocExplorer } from "./components/doc-explorer.js";
2
3
  import { c } from "react-compiler-runtime";
3
- import { isNamedType, isObjectType, isInputObjectType, isScalarType, isEnumType, isInterfaceType, isUnionType } from "graphql";
4
+ import { DocsFilledIcon, DocsIcon, createBoundedUseStore, isMacOs, pick, useGraphiQL, useGraphiQLActions } from "@graphiql/react";
5
+ import { isEnumType, isInputObjectType, isInterfaceType, isNamedType, isObjectType, isScalarType, isUnionType } from "graphql";
6
+ import { jsx } from "react/jsx-runtime";
4
7
  import { useEffect } from "react";
5
- import { pick, useGraphiQL, useGraphiQLActions, createBoundedUseStore, DocsFilledIcon, DocsIcon, isMacOs } from "@graphiql/react";
6
8
  import { createStore } from "zustand";
7
- import { getSchemaReference } from "./schema-reference.js";
8
- import { DocExplorer } from "./components/doc-explorer.js";
9
- const DOC_EXPLORER_PLUGIN = {
10
- title: "Documentation Explorer",
11
- icon: function Icon() {
12
- const visiblePlugin = useGraphiQL((state) => state.visiblePlugin);
13
- return visiblePlugin === DOC_EXPLORER_PLUGIN ? /* @__PURE__ */ jsx(DocsFilledIcon, {}) : /* @__PURE__ */ jsx(DocsIcon, {});
14
- },
15
- content: DocExplorer
9
+ //#region src/context.tsx
10
+ var DOC_EXPLORER_PLUGIN = {
11
+ title: "Documentation Explorer",
12
+ icon: function Icon() {
13
+ return useGraphiQL((state) => state.visiblePlugin) === DOC_EXPLORER_PLUGIN ? /* @__PURE__ */ jsx(DocsFilledIcon, {}) : /* @__PURE__ */ jsx(DocsIcon, {});
14
+ },
15
+ content: DocExplorer
16
16
  };
17
- const INITIAL_NAV_STACK = [{
18
- name: "Root"
19
- }];
20
- const docExplorerStore = createStore((set) => ({
21
- explorerNavStack: INITIAL_NAV_STACK,
22
- actions: {
23
- push(item) {
24
- set((state) => {
25
- const curr = state.explorerNavStack;
26
- const lastItem = curr.at(-1);
27
- const explorerNavStack = (
28
- // Avoid pushing duplicate items
29
- lastItem.def === item.def ? curr : [...curr, item]
30
- );
31
- return {
32
- explorerNavStack
33
- };
34
- });
35
- },
36
- pop() {
37
- set((state) => {
38
- const curr = state.explorerNavStack;
39
- const explorerNavStack = curr.length > 1 ? curr.slice(0, -1) : curr;
40
- return {
41
- explorerNavStack
42
- };
43
- });
44
- },
45
- reset() {
46
- set((state) => {
47
- const curr = state.explorerNavStack;
48
- const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;
49
- return {
50
- explorerNavStack
51
- };
52
- });
53
- },
54
- resolveSchemaReferenceToNavItem(schemaReference) {
55
- if (!schemaReference) {
56
- return;
57
- }
58
- const {
59
- kind,
60
- typeInfo
61
- } = schemaReference;
62
- const ref = getSchemaReference(kind, typeInfo);
63
- if (!ref) {
64
- return;
65
- }
66
- const items = [];
67
- switch (ref.kind) {
68
- case "Type": {
69
- items.push({
70
- name: ref.type.name,
71
- def: ref.type
72
- });
73
- break;
74
- }
75
- case "Field": {
76
- if (ref.type) {
77
- items.push({
78
- name: ref.type.name,
79
- def: ref.type
80
- });
81
- }
82
- items.push({
83
- name: ref.field.name,
84
- def: ref.field
85
- });
86
- break;
87
- }
88
- case "Argument": {
89
- if (ref.field) {
90
- items.push({
91
- name: ref.field.name,
92
- def: ref.field
93
- });
94
- }
95
- break;
96
- }
97
- case "EnumValue": {
98
- if (ref.type) {
99
- items.push({
100
- name: ref.type.name,
101
- def: ref.type
102
- });
103
- }
104
- break;
105
- }
106
- }
107
- if (items.length > 0) {
108
- set({
109
- explorerNavStack: [INITIAL_NAV_STACK[0], ...items]
110
- });
111
- }
112
- },
113
- rebuildNavStackWithSchema(schema) {
114
- set((state) => {
115
- const oldNavStack = state.explorerNavStack;
116
- if (oldNavStack.length === 1) {
117
- return state;
118
- }
119
- const newNavStack = [...INITIAL_NAV_STACK];
120
- let lastEntity = null;
121
- for (const item of oldNavStack) {
122
- if (item === INITIAL_NAV_STACK[0]) {
123
- continue;
124
- }
125
- if (item.def) {
126
- if (isNamedType(item.def)) {
127
- const newType = schema.getType(item.def.name);
128
- if (newType) {
129
- newNavStack.push({
130
- name: item.name,
131
- def: newType
132
- });
133
- lastEntity = newType;
134
- } else {
135
- break;
136
- }
137
- } else if (lastEntity === null) {
138
- break;
139
- } else if (isObjectType(lastEntity) || isInputObjectType(lastEntity)) {
140
- const field = lastEntity.getFields()[item.name];
141
- if (field) {
142
- newNavStack.push({
143
- name: item.name,
144
- def: field
145
- });
146
- } else {
147
- break;
148
- }
149
- } else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
150
- break;
151
- } else {
152
- const field = lastEntity;
153
- if (field.args.some((a) => a.name === item.name)) {
154
- newNavStack.push({
155
- name: item.name,
156
- def: field
157
- });
158
- } else {
159
- break;
160
- }
161
- }
162
- } else {
163
- lastEntity = null;
164
- newNavStack.push(item);
165
- }
166
- }
167
- return {
168
- explorerNavStack: newNavStack
169
- };
170
- });
171
- }
172
- }
17
+ var INITIAL_NAV_STACK = [{ name: "Root" }];
18
+ var docExplorerStore = createStore((set) => ({
19
+ explorerNavStack: INITIAL_NAV_STACK,
20
+ actions: {
21
+ push(item) {
22
+ set((state) => {
23
+ const curr = state.explorerNavStack;
24
+ return { explorerNavStack: curr.at(-1).def === item.def ? curr : [...curr, item] };
25
+ });
26
+ },
27
+ pop() {
28
+ set((state) => {
29
+ const curr = state.explorerNavStack;
30
+ return { explorerNavStack: curr.length > 1 ? curr.slice(0, -1) : curr };
31
+ });
32
+ },
33
+ reset() {
34
+ set((state) => {
35
+ const curr = state.explorerNavStack;
36
+ return { explorerNavStack: curr.length === 1 ? curr : INITIAL_NAV_STACK };
37
+ });
38
+ },
39
+ resolveSchemaReferenceToNavItem(schemaReference) {
40
+ if (!schemaReference) return;
41
+ const { kind, typeInfo } = schemaReference;
42
+ const ref = getSchemaReference(kind, typeInfo);
43
+ if (!ref) return;
44
+ const items = [];
45
+ switch (ref.kind) {
46
+ case "Type":
47
+ items.push({
48
+ name: ref.type.name,
49
+ def: ref.type
50
+ });
51
+ break;
52
+ case "Field":
53
+ if (ref.type) items.push({
54
+ name: ref.type.name,
55
+ def: ref.type
56
+ });
57
+ items.push({
58
+ name: ref.field.name,
59
+ def: ref.field
60
+ });
61
+ break;
62
+ case "Argument":
63
+ if (ref.field) items.push({
64
+ name: ref.field.name,
65
+ def: ref.field
66
+ });
67
+ break;
68
+ case "EnumValue": if (ref.type) items.push({
69
+ name: ref.type.name,
70
+ def: ref.type
71
+ });
72
+ }
73
+ if (items.length > 0) set({ explorerNavStack: [INITIAL_NAV_STACK[0], ...items] });
74
+ },
75
+ rebuildNavStackWithSchema(schema) {
76
+ set((state) => {
77
+ const oldNavStack = state.explorerNavStack;
78
+ if (oldNavStack.length === 1) return state;
79
+ const newNavStack = [...INITIAL_NAV_STACK];
80
+ let lastEntity = null;
81
+ for (const item of oldNavStack) {
82
+ if (item === INITIAL_NAV_STACK[0]) continue;
83
+ if (item.def) {
84
+ if (isNamedType(item.def)) {
85
+ const newType = schema.getType(item.def.name);
86
+ if (newType) {
87
+ newNavStack.push({
88
+ name: item.name,
89
+ def: newType
90
+ });
91
+ lastEntity = newType;
92
+ } else break;
93
+ } else if (lastEntity === null) break;
94
+ else if (isObjectType(lastEntity) || isInputObjectType(lastEntity)) {
95
+ const field = lastEntity.getFields()[item.name];
96
+ if (field) newNavStack.push({
97
+ name: item.name,
98
+ def: field
99
+ });
100
+ else break;
101
+ } else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) break;
102
+ else {
103
+ const field = lastEntity;
104
+ if (field.args.some((a) => a.name === item.name)) newNavStack.push({
105
+ name: item.name,
106
+ def: field
107
+ });
108
+ else break;
109
+ }
110
+ } else {
111
+ lastEntity = null;
112
+ newNavStack.push(item);
113
+ }
114
+ }
115
+ return { explorerNavStack: newNavStack };
116
+ });
117
+ }
118
+ }
173
119
  }));
174
120
  function focusSearchInputWhenMounted(framesLeft) {
175
- if (framesLeft <= 0) {
176
- return;
177
- }
178
- requestAnimationFrame(() => {
179
- const el = document.querySelector(".graphiql-doc-explorer-search-row-input");
180
- if (el) {
181
- el.click();
182
- } else {
183
- focusSearchInputWhenMounted(framesLeft - 1);
184
- }
185
- });
121
+ if (framesLeft <= 0) return;
122
+ requestAnimationFrame(() => {
123
+ const el = document.querySelector(".graphiql-doc-explorer-search-row-input");
124
+ if (el) el.click();
125
+ else focusSearchInputWhenMounted(framesLeft - 1);
126
+ });
186
127
  }
187
- const DocExplorerStore = (t0) => {
188
- const $ = c(11);
189
- const {
190
- children
191
- } = t0;
192
- let t1;
193
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
194
- t1 = pick("schema", "validationErrors", "schemaReference");
195
- $[0] = t1;
196
- } else {
197
- t1 = $[0];
198
- }
199
- const {
200
- schema,
201
- validationErrors,
202
- schemaReference
203
- } = useGraphiQL(t1);
204
- const {
205
- setVisiblePlugin
206
- } = useGraphiQLActions();
207
- let t2;
208
- let t3;
209
- if ($[1] !== schemaReference) {
210
- t2 = () => {
211
- const {
212
- resolveSchemaReferenceToNavItem
213
- } = docExplorerStore.getState().actions;
214
- resolveSchemaReferenceToNavItem(schemaReference);
215
- };
216
- t3 = [schemaReference];
217
- $[1] = schemaReference;
218
- $[2] = t2;
219
- $[3] = t3;
220
- } else {
221
- t2 = $[2];
222
- t3 = $[3];
223
- }
224
- useEffect(t2, t3);
225
- let t4;
226
- let t5;
227
- if ($[4] !== schema || $[5] !== validationErrors) {
228
- t4 = () => {
229
- const {
230
- reset,
231
- rebuildNavStackWithSchema
232
- } = docExplorerStore.getState().actions;
233
- if (schema == null || validationErrors.length > 0) {
234
- reset();
235
- } else {
236
- rebuildNavStackWithSchema(schema);
237
- }
238
- };
239
- t5 = [schema, validationErrors];
240
- $[4] = schema;
241
- $[5] = validationErrors;
242
- $[6] = t4;
243
- $[7] = t5;
244
- } else {
245
- t4 = $[6];
246
- t5 = $[7];
247
- }
248
- useEffect(t4, t5);
249
- let t6;
250
- let t7;
251
- if ($[8] !== setVisiblePlugin) {
252
- t6 = () => {
253
- const handleKeyDown = function handleKeyDown2(event) {
254
- const shouldOpenSearch = event[isMacOs ? "metaKey" : "ctrlKey"] && event.code === "KeyK";
255
- if (!shouldOpenSearch) {
256
- return;
257
- }
258
- event.preventDefault();
259
- event.stopPropagation();
260
- setVisiblePlugin(DOC_EXPLORER_PLUGIN);
261
- focusSearchInputWhenMounted(10);
262
- };
263
- window.addEventListener("keydown", handleKeyDown, true);
264
- return () => {
265
- window.removeEventListener("keydown", handleKeyDown, true);
266
- };
267
- };
268
- t7 = [setVisiblePlugin];
269
- $[8] = setVisiblePlugin;
270
- $[9] = t6;
271
- $[10] = t7;
272
- } else {
273
- t6 = $[9];
274
- t7 = $[10];
275
- }
276
- useEffect(t6, t7);
277
- return children;
128
+ var DocExplorerStore = (t0) => {
129
+ const $ = c(11);
130
+ const { children } = t0;
131
+ let t1;
132
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
133
+ t1 = pick("schema", "validationErrors", "schemaReference");
134
+ $[0] = t1;
135
+ } else t1 = $[0];
136
+ const { schema, validationErrors, schemaReference } = useGraphiQL(t1);
137
+ const { setVisiblePlugin } = useGraphiQLActions();
138
+ let t2;
139
+ let t3;
140
+ if ($[1] !== schemaReference) {
141
+ t2 = () => {
142
+ const { resolveSchemaReferenceToNavItem } = docExplorerStore.getState().actions;
143
+ resolveSchemaReferenceToNavItem(schemaReference);
144
+ };
145
+ t3 = [schemaReference];
146
+ $[1] = schemaReference;
147
+ $[2] = t2;
148
+ $[3] = t3;
149
+ } else {
150
+ t2 = $[2];
151
+ t3 = $[3];
152
+ }
153
+ useEffect(t2, t3);
154
+ let t4;
155
+ let t5;
156
+ if ($[4] !== schema || $[5] !== validationErrors) {
157
+ t4 = () => {
158
+ const { reset, rebuildNavStackWithSchema } = docExplorerStore.getState().actions;
159
+ if (schema == null || validationErrors.length > 0) reset();
160
+ else rebuildNavStackWithSchema(schema);
161
+ };
162
+ t5 = [schema, validationErrors];
163
+ $[4] = schema;
164
+ $[5] = validationErrors;
165
+ $[6] = t4;
166
+ $[7] = t5;
167
+ } else {
168
+ t4 = $[6];
169
+ t5 = $[7];
170
+ }
171
+ useEffect(t4, t5);
172
+ let t6;
173
+ let t7;
174
+ if ($[8] !== setVisiblePlugin) {
175
+ t6 = () => {
176
+ const handleKeyDown = function handleKeyDown(event) {
177
+ if (!(event[isMacOs ? "metaKey" : "ctrlKey"] && event.code === "KeyK")) return;
178
+ event.preventDefault();
179
+ event.stopPropagation();
180
+ setVisiblePlugin(DOC_EXPLORER_PLUGIN);
181
+ focusSearchInputWhenMounted(10);
182
+ };
183
+ window.addEventListener("keydown", handleKeyDown, true);
184
+ return () => {
185
+ window.removeEventListener("keydown", handleKeyDown, true);
186
+ };
187
+ };
188
+ t7 = [setVisiblePlugin];
189
+ $[8] = setVisiblePlugin;
190
+ $[9] = t6;
191
+ $[10] = t7;
192
+ } else {
193
+ t6 = $[9];
194
+ t7 = $[10];
195
+ }
196
+ useEffect(t6, t7);
197
+ return children;
278
198
  };
279
- const useDocExplorerStore = createBoundedUseStore(docExplorerStore);
280
- const useDocExplorer = () => {
281
- return useDocExplorerStore(_temp);
199
+ var useDocExplorerStore = createBoundedUseStore(docExplorerStore);
200
+ var useDocExplorer = () => {
201
+ return useDocExplorerStore(_temp);
282
202
  };
283
- const useDocExplorerActions = () => {
284
- return useDocExplorerStore(_temp2);
203
+ /**
204
+ * Actions are functions used to update values in your store. They are static and never change.
205
+ * @see https://tkdodo.eu/blog/working-with-zustand#separate-actions-from-state
206
+ */
207
+ var useDocExplorerActions = () => {
208
+ return useDocExplorerStore(_temp2);
285
209
  };
286
210
  function _temp(state) {
287
- return state.explorerNavStack;
211
+ return state.explorerNavStack;
288
212
  }
289
213
  function _temp2(state) {
290
- return state.actions;
214
+ return state.actions;
291
215
  }
292
- export {
293
- DOC_EXPLORER_PLUGIN,
294
- DocExplorerStore,
295
- docExplorerStore,
296
- useDocExplorer,
297
- useDocExplorerActions
298
- };
299
- //# sourceMappingURL=context.js.map
216
+ //#endregion
217
+ export { DOC_EXPLORER_PLUGIN, DocExplorerStore, docExplorerStore, useDocExplorer, useDocExplorerActions };
218
+
219
+ //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["import type {\n GraphQLArgument,\n GraphQLField,\n GraphQLInputField,\n GraphQLNamedType,\n GraphQLSchema,\n} from 'graphql';\nimport {\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n isScalarType,\n isUnionType,\n} from 'graphql';\nimport { FC, ReactElement, ReactNode, useEffect } from 'react';\nimport {\n SchemaReference,\n useGraphiQL,\n useGraphiQLActions,\n pick,\n createBoundedUseStore,\n GraphiQLPlugin,\n DocsFilledIcon,\n DocsIcon,\n isMacOs,\n} from '@graphiql/react';\nimport { createStore } from 'zustand';\nimport { getSchemaReference } from './schema-reference';\nimport { DocExplorer } from './components';\n\nexport const DOC_EXPLORER_PLUGIN: GraphiQLPlugin = {\n title: 'Documentation Explorer',\n icon: function Icon() {\n const visiblePlugin = useGraphiQL(state => state.visiblePlugin);\n return visiblePlugin === DOC_EXPLORER_PLUGIN ? (\n <DocsFilledIcon />\n ) : (\n <DocsIcon />\n );\n },\n content: DocExplorer,\n};\n\nexport type DocExplorerFieldDef =\n | GraphQLField<unknown, unknown>\n | GraphQLInputField\n | GraphQLArgument;\n\nexport type DocExplorerNavStackItem = {\n /**\n * The name of the item.\n */\n name: string;\n /**\n * The definition object of the item, this can be a named type, a field, an\n * input field or an argument.\n */\n def?: GraphQLNamedType | DocExplorerFieldDef;\n};\n\n// There's always at least one item in the nav stack\nexport type DocExplorerNavStack = [\n DocExplorerNavStackItem,\n ...DocExplorerNavStackItem[],\n];\n\nexport type DocExplorerStoreType = {\n /**\n * A stack of navigation items. The last item in the list is the current one.\n * This list always contains at least one item.\n */\n explorerNavStack: DocExplorerNavStack;\n actions: {\n /**\n * Push an item to the navigation stack.\n * @param item The item that should be pushed to the stack.\n */\n push(item: DocExplorerNavStackItem): void;\n /**\n * Pop the last item from the navigation stack.\n */\n pop(): void;\n /**\n * Reset the navigation stack to its initial state, this will remove all but\n * the initial stack item.\n */\n reset(): void;\n resolveSchemaReferenceToNavItem(\n schemaReference: SchemaReference | null,\n ): void;\n /**\n * Replace the nav stack with an updated version using the new schema.\n */\n rebuildNavStackWithSchema(schema: GraphQLSchema): void;\n };\n};\n\nconst INITIAL_NAV_STACK: DocExplorerNavStack = [{ name: 'Root' }];\n\nexport const docExplorerStore = createStore<DocExplorerStoreType>(set => ({\n explorerNavStack: INITIAL_NAV_STACK,\n actions: {\n push(item) {\n set(state => {\n const curr = state.explorerNavStack;\n const lastItem = curr.at(-1)!;\n const explorerNavStack: DocExplorerNavStack =\n // Avoid pushing duplicate items\n lastItem.def === item.def ? curr : [...curr, item];\n\n return { explorerNavStack };\n });\n },\n pop() {\n set(state => {\n const curr = state.explorerNavStack;\n\n const explorerNavStack =\n curr.length > 1 ? (curr.slice(0, -1) as DocExplorerNavStack) : curr;\n\n return { explorerNavStack };\n });\n },\n reset() {\n set(state => {\n const curr = state.explorerNavStack;\n const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;\n return { explorerNavStack };\n });\n },\n resolveSchemaReferenceToNavItem(schemaReference) {\n if (!schemaReference) {\n return;\n }\n const { kind, typeInfo } = schemaReference;\n const ref = getSchemaReference(kind, typeInfo);\n if (!ref) {\n return;\n }\n\n // Replace the current path with the path to the referenced item,\n // rather than appending to it; repeatedly clicking the same reference\n // must not grow the stack.\n const items: DocExplorerNavStackItem[] = [];\n switch (ref.kind) {\n case 'Type': {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n break;\n }\n case 'Field': {\n // Show a field type on stack\n if (ref.type) {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n items.push({\n name: ref.field.name,\n def: ref.field,\n });\n break;\n }\n case 'Argument': {\n if (ref.field) {\n items.push({\n name: ref.field.name,\n def: ref.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (ref.type) {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n break;\n }\n }\n if (items.length > 0) {\n set({ explorerNavStack: [INITIAL_NAV_STACK[0], ...items] });\n }\n },\n rebuildNavStackWithSchema(schema: GraphQLSchema) {\n set(state => {\n const oldNavStack = state.explorerNavStack;\n if (oldNavStack.length === 1) {\n return state;\n }\n // Spread is needed\n const newNavStack: DocExplorerNavStack = [...INITIAL_NAV_STACK];\n let lastEntity:\n | GraphQLNamedType\n | GraphQLField<unknown, unknown>\n | null = null;\n for (const item of oldNavStack) {\n if (item === INITIAL_NAV_STACK[0]) {\n // No need to copy the initial item\n continue;\n }\n if (item.def) {\n // If item.def isn't a named type, it must be a field, inputField, or argument\n if (isNamedType(item.def)) {\n // The type needs to be replaced with the new schema type of the same name\n const newType = schema.getType(item.def.name);\n if (newType) {\n newNavStack.push({\n name: item.name,\n def: newType,\n });\n lastEntity = newType;\n } else {\n // This type no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (lastEntity === null) {\n // We can't have a sub-entity if we have no entity; stop rebuilding the nav stack\n break;\n } else if (\n isObjectType(lastEntity) ||\n isInputObjectType(lastEntity)\n ) {\n // item.def must be a Field / input field; replace with the new field of the same name\n const field = lastEntity.getFields()[item.name];\n if (field) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This field no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (\n isScalarType(lastEntity) ||\n isEnumType(lastEntity) ||\n isInterfaceType(lastEntity) ||\n isUnionType(lastEntity)\n ) {\n // These don't (currently) have non-type sub-entries; something has gone wrong.\n // Handle gracefully by discontinuing rebuilding the stack.\n break;\n } else {\n // lastEntity must be a field (because it's not a named type)\n const field: GraphQLField<unknown, unknown> = lastEntity;\n // Thus item.def must be an argument, so find the same named argument in the new schema\n if (field.args.some(a => a.name === item.name)) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This argument no longer exists; the stack cannot be built beyond here\n break;\n }\n }\n } else {\n lastEntity = null;\n newNavStack.push(item);\n }\n }\n return { explorerNavStack: newNavStack };\n });\n },\n },\n}));\n\n// The doc-explorer panel (and its search input) mounts asynchronously after\n// `setVisiblePlugin` commits, which isn't guaranteed to land within a single\n// animation frame, so poll across a few frames rather than assuming one is\n// enough.\nfunction focusSearchInputWhenMounted(framesLeft: number) {\n if (framesLeft <= 0) {\n return;\n }\n requestAnimationFrame(() => {\n const el = document.querySelector<HTMLDivElement>(\n '.graphiql-doc-explorer-search-row-input',\n );\n if (el) {\n el.click();\n } else {\n focusSearchInputWhenMounted(framesLeft - 1);\n }\n });\n}\n\nexport const DocExplorerStore: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { schema, validationErrors, schemaReference } = useGraphiQL(\n pick('schema', 'validationErrors', 'schemaReference'),\n );\n const { setVisiblePlugin } = useGraphiQLActions();\n\n useEffect(() => {\n const { resolveSchemaReferenceToNavItem } =\n docExplorerStore.getState().actions;\n resolveSchemaReferenceToNavItem(schemaReference);\n }, [schemaReference]);\n\n useEffect(() => {\n const { reset, rebuildNavStackWithSchema } =\n docExplorerStore.getState().actions;\n\n // Whenever the schema changes, we must revalidate/replace the nav stack.\n if (schema == null || validationErrors.length > 0) {\n reset();\n } else {\n rebuildNavStackWithSchema(schema);\n }\n }, [schema, validationErrors]);\n\n useEffect(() => {\n function handleKeyDown(event: KeyboardEvent) {\n const shouldOpenSearch =\n event[isMacOs ? 'metaKey' : 'ctrlKey'] &&\n // Using `event.code` because `event.key` will trigger different character\n // in English `˚` and in French `È`\n event.code === 'KeyK';\n if (!shouldOpenSearch) {\n return;\n }\n // Take priority over monaco-editor's built-in `Cmd/Ctrl+K` binding even\n // when an editor pane has focus.\n event.preventDefault();\n event.stopPropagation();\n\n setVisiblePlugin(DOC_EXPLORER_PLUGIN);\n // The panel (and its search input) mounts after this state update\n // commits, which isn't guaranteed to land within a single animation\n // frame, so poll across a few frames rather than assuming one is enough.\n focusSearchInputWhenMounted(10);\n }\n\n window.addEventListener('keydown', handleKeyDown, true);\n return () => {\n window.removeEventListener('keydown', handleKeyDown, true);\n };\n }, [setVisiblePlugin]);\n\n return children as ReactElement;\n};\n\nconst useDocExplorerStore = createBoundedUseStore(docExplorerStore);\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\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 useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"names":["DOC_EXPLORER_PLUGIN","title","icon","Icon","visiblePlugin","useGraphiQL","state","content","DocExplorer","INITIAL_NAV_STACK","name","docExplorerStore","createStore","set","explorerNavStack","actions","push","item","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","typeInfo","ref","getSchemaReference","items","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","focusSearchInputWhenMounted","framesLeft","requestAnimationFrame","el","document","querySelector","click","DocExplorerStore","t0","$","_c","children","t1","Symbol","for","pick","validationErrors","setVisiblePlugin","useGraphiQLActions","t2","t3","getState","useEffect","t4","t5","t6","t7","handleKeyDown","event","shouldOpenSearch","isMacOs","code","preventDefault","stopPropagation","addEventListener","removeEventListener","useDocExplorerStore","createBoundedUseStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;;;;AAgCO,MAAMA,sBAAs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AA,SAC5BF,oBAAAG,KAAmD;AAAC;AAM/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCJ,oBAAAK,MAA0C;AAAC;AARf,SAAAF,MAAAtF,OAAA;AAAA,SACCA,MAAKQ;AAAA;AAMC,SAAAgF,OAAAxF,OAAA;AAAA,SACNA,MAAKS;AAAA;"}
1
+ {"version":3,"file":"context.js","names":["GraphQLArgument","GraphQLField","GraphQLInputField","GraphQLNamedType","GraphQLSchema","isEnumType","isInputObjectType","isInterfaceType","isNamedType","isObjectType","isScalarType","isUnionType","FC","ReactElement","ReactNode","useEffect","SchemaReference","useGraphiQL","useGraphiQLActions","pick","createBoundedUseStore","GraphiQLPlugin","DocsFilledIcon","DocsIcon","isMacOs","createStore","getSchemaReference","DocExplorer","DOC_EXPLORER_PLUGIN","title","icon","Icon","visiblePlugin","state","content","DocExplorerFieldDef","DocExplorerNavStackItem","name","def","DocExplorerNavStack","DocExplorerStoreType","explorerNavStack","actions","push","item","pop","reset","resolveSchemaReferenceToNavItem","schemaReference","rebuildNavStackWithSchema","schema","INITIAL_NAV_STACK","docExplorerStore","set","curr","lastItem","at","length","slice","kind","typeInfo","ref","items","type","field","oldNavStack","newNavStack","lastEntity","newType","getType","getFields","args","some","a","focusSearchInputWhenMounted","framesLeft","requestAnimationFrame","el","document","querySelector","HTMLDivElement","click","DocExplorerStore","children","t0","$","_c","t1","Symbol","for","validationErrors","setVisiblePlugin","t2","t3","getState","t4","t5","t6","t7","handleKeyDown","event","shouldOpenSearch","code","preventDefault","stopPropagation","window","addEventListener","removeEventListener","useDocExplorerStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"sources":["../src/context.tsx"],"sourcesContent":["import type {\n GraphQLArgument,\n GraphQLField,\n GraphQLInputField,\n GraphQLNamedType,\n GraphQLSchema,\n} from 'graphql';\nimport {\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n isScalarType,\n isUnionType,\n} from 'graphql';\nimport { FC, ReactElement, ReactNode, useEffect } from 'react';\nimport {\n SchemaReference,\n useGraphiQL,\n useGraphiQLActions,\n pick,\n createBoundedUseStore,\n GraphiQLPlugin,\n DocsFilledIcon,\n DocsIcon,\n isMacOs,\n} from '@graphiql/react';\nimport { createStore } from 'zustand';\nimport { getSchemaReference } from './schema-reference';\nimport { DocExplorer } from './components';\n\nexport const DOC_EXPLORER_PLUGIN: GraphiQLPlugin = {\n title: 'Documentation Explorer',\n icon: function Icon() {\n const visiblePlugin = useGraphiQL(state => state.visiblePlugin);\n return visiblePlugin === DOC_EXPLORER_PLUGIN ? (\n <DocsFilledIcon />\n ) : (\n <DocsIcon />\n );\n },\n content: DocExplorer,\n};\n\nexport type DocExplorerFieldDef =\n | GraphQLField<unknown, unknown>\n | GraphQLInputField\n | GraphQLArgument;\n\nexport type DocExplorerNavStackItem = {\n /**\n * The name of the item.\n */\n name: string;\n /**\n * The definition object of the item, this can be a named type, a field, an\n * input field or an argument.\n */\n def?: GraphQLNamedType | DocExplorerFieldDef;\n};\n\n// There's always at least one item in the nav stack\nexport type DocExplorerNavStack = [\n DocExplorerNavStackItem,\n ...DocExplorerNavStackItem[],\n];\n\nexport type DocExplorerStoreType = {\n /**\n * A stack of navigation items. The last item in the list is the current one.\n * This list always contains at least one item.\n */\n explorerNavStack: DocExplorerNavStack;\n actions: {\n /**\n * Push an item to the navigation stack.\n * @param item The item that should be pushed to the stack.\n */\n push(item: DocExplorerNavStackItem): void;\n /**\n * Pop the last item from the navigation stack.\n */\n pop(): void;\n /**\n * Reset the navigation stack to its initial state, this will remove all but\n * the initial stack item.\n */\n reset(): void;\n resolveSchemaReferenceToNavItem(\n schemaReference: SchemaReference | null,\n ): void;\n /**\n * Replace the nav stack with an updated version using the new schema.\n */\n rebuildNavStackWithSchema(schema: GraphQLSchema): void;\n };\n};\n\nconst INITIAL_NAV_STACK: DocExplorerNavStack = [{ name: 'Root' }];\n\nexport const docExplorerStore = createStore<DocExplorerStoreType>(set => ({\n explorerNavStack: INITIAL_NAV_STACK,\n actions: {\n push(item) {\n set(state => {\n const curr = state.explorerNavStack;\n const lastItem = curr.at(-1)!;\n const explorerNavStack: DocExplorerNavStack =\n // Avoid pushing duplicate items\n lastItem.def === item.def ? curr : [...curr, item];\n\n return { explorerNavStack };\n });\n },\n pop() {\n set(state => {\n const curr = state.explorerNavStack;\n\n const explorerNavStack =\n curr.length > 1 ? (curr.slice(0, -1) as DocExplorerNavStack) : curr;\n\n return { explorerNavStack };\n });\n },\n reset() {\n set(state => {\n const curr = state.explorerNavStack;\n const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;\n return { explorerNavStack };\n });\n },\n resolveSchemaReferenceToNavItem(schemaReference) {\n if (!schemaReference) {\n return;\n }\n const { kind, typeInfo } = schemaReference;\n const ref = getSchemaReference(kind, typeInfo);\n if (!ref) {\n return;\n }\n\n // Replace the current path with the path to the referenced item,\n // rather than appending to it; repeatedly clicking the same reference\n // must not grow the stack.\n const items: DocExplorerNavStackItem[] = [];\n switch (ref.kind) {\n case 'Type': {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n break;\n }\n case 'Field': {\n // Show a field type on stack\n if (ref.type) {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n items.push({\n name: ref.field.name,\n def: ref.field,\n });\n break;\n }\n case 'Argument': {\n if (ref.field) {\n items.push({\n name: ref.field.name,\n def: ref.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (ref.type) {\n items.push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n break;\n }\n }\n if (items.length > 0) {\n set({ explorerNavStack: [INITIAL_NAV_STACK[0], ...items] });\n }\n },\n rebuildNavStackWithSchema(schema: GraphQLSchema) {\n set(state => {\n const oldNavStack = state.explorerNavStack;\n if (oldNavStack.length === 1) {\n return state;\n }\n // Spread is needed\n const newNavStack: DocExplorerNavStack = [...INITIAL_NAV_STACK];\n let lastEntity:\n | GraphQLNamedType\n | GraphQLField<unknown, unknown>\n | null = null;\n for (const item of oldNavStack) {\n if (item === INITIAL_NAV_STACK[0]) {\n // No need to copy the initial item\n continue;\n }\n if (item.def) {\n // If item.def isn't a named type, it must be a field, inputField, or argument\n if (isNamedType(item.def)) {\n // The type needs to be replaced with the new schema type of the same name\n const newType = schema.getType(item.def.name);\n if (newType) {\n newNavStack.push({\n name: item.name,\n def: newType,\n });\n lastEntity = newType;\n } else {\n // This type no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (lastEntity === null) {\n // We can't have a sub-entity if we have no entity; stop rebuilding the nav stack\n break;\n } else if (\n isObjectType(lastEntity) ||\n isInputObjectType(lastEntity)\n ) {\n // item.def must be a Field / input field; replace with the new field of the same name\n const field = lastEntity.getFields()[item.name];\n if (field) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This field no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (\n isScalarType(lastEntity) ||\n isEnumType(lastEntity) ||\n isInterfaceType(lastEntity) ||\n isUnionType(lastEntity)\n ) {\n // These don't (currently) have non-type sub-entries; something has gone wrong.\n // Handle gracefully by discontinuing rebuilding the stack.\n break;\n } else {\n // lastEntity must be a field (because it's not a named type)\n const field: GraphQLField<unknown, unknown> = lastEntity;\n // Thus item.def must be an argument, so find the same named argument in the new schema\n if (field.args.some(a => a.name === item.name)) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This argument no longer exists; the stack cannot be built beyond here\n break;\n }\n }\n } else {\n lastEntity = null;\n newNavStack.push(item);\n }\n }\n return { explorerNavStack: newNavStack };\n });\n },\n },\n}));\n\n// The doc-explorer panel (and its search input) mounts asynchronously after\n// `setVisiblePlugin` commits, which isn't guaranteed to land within a single\n// animation frame, so poll across a few frames rather than assuming one is\n// enough.\nfunction focusSearchInputWhenMounted(framesLeft: number) {\n if (framesLeft <= 0) {\n return;\n }\n requestAnimationFrame(() => {\n const el = document.querySelector<HTMLDivElement>(\n '.graphiql-doc-explorer-search-row-input',\n );\n if (el) {\n el.click();\n } else {\n focusSearchInputWhenMounted(framesLeft - 1);\n }\n });\n}\n\nexport const DocExplorerStore: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { schema, validationErrors, schemaReference } = useGraphiQL(\n pick('schema', 'validationErrors', 'schemaReference'),\n );\n const { setVisiblePlugin } = useGraphiQLActions();\n\n useEffect(() => {\n const { resolveSchemaReferenceToNavItem } =\n docExplorerStore.getState().actions;\n resolveSchemaReferenceToNavItem(schemaReference);\n }, [schemaReference]);\n\n useEffect(() => {\n const { reset, rebuildNavStackWithSchema } =\n docExplorerStore.getState().actions;\n\n // Whenever the schema changes, we must revalidate/replace the nav stack.\n if (schema == null || validationErrors.length > 0) {\n reset();\n } else {\n rebuildNavStackWithSchema(schema);\n }\n }, [schema, validationErrors]);\n\n useEffect(() => {\n function handleKeyDown(event: KeyboardEvent) {\n const shouldOpenSearch =\n event[isMacOs ? 'metaKey' : 'ctrlKey'] &&\n // Using `event.code` because `event.key` will trigger different character\n // in English `˚` and in French `È`\n event.code === 'KeyK';\n if (!shouldOpenSearch) {\n return;\n }\n // Take priority over monaco-editor's built-in `Cmd/Ctrl+K` binding even\n // when an editor pane has focus.\n event.preventDefault();\n event.stopPropagation();\n\n setVisiblePlugin(DOC_EXPLORER_PLUGIN);\n // The panel (and its search input) mounts after this state update\n // commits, which isn't guaranteed to land within a single animation\n // frame, so poll across a few frames rather than assuming one is enough.\n focusSearchInputWhenMounted(10);\n }\n\n window.addEventListener('keydown', handleKeyDown, true);\n return () => {\n window.removeEventListener('keydown', handleKeyDown, true);\n };\n }, [setVisiblePlugin]);\n\n return children as ReactElement;\n};\n\nconst useDocExplorerStore = createBoundedUseStore(docExplorerStore);\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\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 useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"mappings":";;;;;;;;;AAgCA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,IAAaC,8BAAwB;CAAA,OACnCH,oBAAAI,MAA0C;AAAC;AARf,SAAAF,MAAA7E,OAAA;CAAA,OACCA,MAAKQ;AAAA;AAMC,SAAAuE,OAAA/E,OAAA;CAAA,OACNA,MAAKS;AAAA"}
package/dist/index.js CHANGED
@@ -1,44 +1,20 @@
1
+ import { DefaultValue } from "./components/default-value.js";
1
2
  import { DOC_EXPLORER_PLUGIN, DocExplorerStore, useDocExplorer, useDocExplorerActions } from "./context.js";
3
+ import { TypeLink } from "./components/type-link.js";
2
4
  import { Argument } from "./components/argument.js";
5
+ import { DeprecationReason } from "./components/deprecation-reason.js";
3
6
  import { ArgumentsList } from "./components/arguments-list.js";
4
7
  import { Breadcrumb } from "./components/breadcrumb.js";
5
- import { DefaultValue } from "./components/default-value.js";
6
- import { DeprecationReason } from "./components/deprecation-reason.js";
7
8
  import { Directive } from "./components/directive.js";
8
- import { DocExplorer } from "./components/doc-explorer.js";
9
9
  import { FieldCard } from "./components/field-card.js";
10
10
  import { FieldDocumentation } from "./components/field-documentation.js";
11
- import { FieldLink } from "./components/field-link.js";
12
11
  import { FieldsList } from "./components/fields-list.js";
13
12
  import { SchemaDocumentation } from "./components/schema-documentation.js";
14
13
  import { Search } from "./components/search.js";
15
14
  import { SearchRow } from "./components/search-row.js";
16
- import { ExplorerSection } from "./components/section.js";
17
15
  import { TypeCard } from "./components/type-card.js";
16
+ import { FieldLink } from "./components/field-link.js";
17
+ import { ExplorerSection } from "./components/section.js";
18
18
  import { TypeDocumentation } from "./components/type-documentation.js";
19
- import { TypeLink } from "./components/type-link.js";
20
- export {
21
- Argument,
22
- ArgumentsList,
23
- Breadcrumb,
24
- DOC_EXPLORER_PLUGIN,
25
- DefaultValue,
26
- DeprecationReason,
27
- Directive,
28
- DocExplorer,
29
- DocExplorerStore,
30
- ExplorerSection,
31
- FieldCard,
32
- FieldDocumentation,
33
- FieldLink,
34
- FieldsList,
35
- SchemaDocumentation,
36
- Search,
37
- SearchRow,
38
- TypeCard,
39
- TypeDocumentation,
40
- TypeLink,
41
- useDocExplorer,
42
- useDocExplorerActions
43
- };
44
- //# sourceMappingURL=index.js.map
19
+ import { DocExplorer } from "./components/doc-explorer.js";
20
+ export { Argument, ArgumentsList, Breadcrumb, DOC_EXPLORER_PLUGIN, DefaultValue, DeprecationReason, Directive, DocExplorer, DocExplorerStore, ExplorerSection, FieldCard, FieldDocumentation, FieldLink, FieldsList, SchemaDocumentation, Search, SearchRow, TypeCard, TypeDocumentation, TypeLink, useDocExplorer, useDocExplorerActions };