@graphiql/plugin-doc-explorer 0.4.3 → 1.0.0-beta.1
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/components/arguments-list.d.ts +12 -0
- package/dist/components/arguments-list.js +248 -0
- package/dist/components/arguments-list.js.map +1 -0
- package/dist/components/breadcrumb.d.ts +8 -0
- package/dist/components/breadcrumb.js +54 -0
- package/dist/components/breadcrumb.js.map +1 -0
- package/dist/components/doc-explorer.js +172 -123
- package/dist/components/doc-explorer.js.map +1 -1
- package/dist/components/field-card.d.ts +7 -0
- package/dist/components/field-card.js +102 -0
- package/dist/components/field-card.js.map +1 -0
- package/dist/components/field-documentation.js +76 -110
- package/dist/components/field-documentation.js.map +1 -1
- package/dist/components/fields-list.d.ts +8 -0
- package/dist/components/fields-list.js +235 -0
- package/dist/components/fields-list.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/schema-documentation.js +170 -98
- package/dist/components/schema-documentation.js.map +1 -1
- package/dist/components/search-row.d.ts +2 -0
- package/dist/components/search-row.js +282 -0
- package/dist/components/search-row.js.map +1 -0
- package/dist/components/search.js +76 -52
- package/dist/components/search.js.map +1 -1
- package/dist/components/section.js +1 -1
- package/dist/components/section.js.map +1 -1
- package/dist/components/type-card.d.ts +7 -0
- package/dist/components/type-card.js +112 -0
- package/dist/components/type-card.js.map +1 -0
- package/dist/components/type-documentation.d.ts +6 -0
- package/dist/components/type-documentation.js +11 -9
- package/dist/components/type-documentation.js.map +1 -1
- package/dist/components/type-link.js +2 -1
- package/dist/components/type-link.js.map +1 -1
- package/dist/context.js +60 -40
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/stories/doc-explorer.stories.d.ts +12 -0
- package/dist/style.css +691 -131
- package/package.json +9 -3
- package/dist/deprecated.d.ts +0 -11
- package/dist/deprecated.js +0 -24
- package/dist/deprecated.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
+
import { typeCategory } from "@graphiql/react";
|
|
3
4
|
import { useDocExplorerActions } from "../context.js";
|
|
4
5
|
import { renderType } from "./utils.js";
|
|
5
6
|
/* empty css */
|
|
@@ -13,7 +14,7 @@ const TypeLink = (t0) => {
|
|
|
13
14
|
} = useDocExplorerActions();
|
|
14
15
|
let t1;
|
|
15
16
|
if ($[0] !== push) {
|
|
16
|
-
t1 = (def) => /* @__PURE__ */ jsx("a", { className: "graphiql-doc-explorer-type-name", onClick: (event) => {
|
|
17
|
+
t1 = (def) => /* @__PURE__ */ jsx("a", { className: "graphiql-doc-explorer-type-name", "data-type-kind": typeCategory(def), onClick: (event) => {
|
|
17
18
|
event.preventDefault();
|
|
18
19
|
push({
|
|
19
20
|
name: def.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-link.js","sources":["../../src/components/type-link.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport type { GraphQLType } from 'graphql';\nimport { useDocExplorerActions } from '../context';\nimport { renderType } from './utils';\nimport './type-link.css';\n\ntype TypeLinkProps = {\n /**\n * The type that should be linked to.\n */\n type: GraphQLType;\n};\n\nexport const TypeLink: FC<TypeLinkProps> = ({ type }) => {\n const { push } = useDocExplorerActions();\n\n return renderType(type, def => (\n <a\n className=\"graphiql-doc-explorer-type-name\"\n onClick={event => {\n event.preventDefault();\n push({ name: def.name, def });\n }}\n href=\"#\"\n >\n {def.name}\n </a>\n ));\n};\n"],"names":["TypeLink","t0","$","_c","type","push","useDocExplorerActions","t1","def","event","preventDefault","name","t2","renderType"],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-link.js","sources":["../../src/components/type-link.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport type { GraphQLType } from 'graphql';\nimport { typeCategory } from '@graphiql/react';\nimport { useDocExplorerActions } from '../context';\nimport { renderType } from './utils';\nimport './type-link.css';\n\ntype TypeLinkProps = {\n /**\n * The type that should be linked to.\n */\n type: GraphQLType;\n};\n\nexport const TypeLink: FC<TypeLinkProps> = ({ type }) => {\n const { push } = useDocExplorerActions();\n\n return renderType(type, def => (\n <a\n className=\"graphiql-doc-explorer-type-name\"\n data-type-kind={typeCategory(def)}\n onClick={event => {\n event.preventDefault();\n push({ name: def.name, def });\n }}\n href=\"#\"\n >\n {def.name}\n </a>\n ));\n};\n"],"names":["TypeLink","t0","$","_c","type","push","useDocExplorerActions","t1","def","typeCategory","event","preventDefault","name","t2","renderType"],"mappings":";;;;;;AAcO,MAAMA,WAA8BC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AAC1C,QAAA;AAAA,IAAAI;AAAAA,MAAiBC,sBAAsB;AAAEC,MAAAA;AAAAL,MAAAA,SAAAG,MAAA;AAEjBG,SAAAA,CAAAA,QACtB,oBAAA,KAAA,EACY,WAAA,mCACM,kBAAAC,aAAaD,GAAG,GACvB,SAAAE,CAAA,UAAA;AACPA,YAAKC,eAAgB;AACjB,WAAA;AAAA,QAAAC,MAASJ,IAAGI;AAAAA,QAAAJ;AAAAA,MAAAA,CAAY;AAAA,IAEzB,GAAA,MAAA,KAEJA,UAAAA,IAAGI,KACN,CAAA;AACDV,WAAAG;AAAAH,WAAAK;AAAAA,EAAAA,OAAA;AAAAA,SAAAL,EAAA,CAAA;AAAA,EAAA;AAAAW,MAAAA;AAAA,MAAAX,EAAAK,CAAAA,MAAAA,MAAAL,SAAAE,MAAA;AAZMU,SAAAA,WAAWV,MAAMG,EAYvB;AAACL,WAAAK;AAAAL,WAAAE;AAAAF,WAAAW;AAAAA,EAAAA,OAAA;AAAAA,SAAAX,EAAA,CAAA;AAAA,EAAA;AAZKW,SAAAA;AAYL;"}
|
package/dist/context.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import { isNamedType, isObjectType, isInputObjectType, isScalarType, isEnumType, isInterfaceType, isUnionType } from "graphql";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
|
-
import { pick, useGraphiQL, createBoundedUseStore, DocsFilledIcon, DocsIcon, isMacOs } from "@graphiql/react";
|
|
5
|
+
import { pick, useGraphiQL, useGraphiQLActions, createBoundedUseStore, DocsFilledIcon, DocsIcon, isMacOs } from "@graphiql/react";
|
|
6
6
|
import { createStore } from "zustand";
|
|
7
7
|
import { getSchemaReference } from "./schema-reference.js";
|
|
8
8
|
import { DocExplorer } from "./components/doc-explorer.js";
|
|
@@ -15,9 +15,9 @@ const DOC_EXPLORER_PLUGIN = {
|
|
|
15
15
|
content: DocExplorer
|
|
16
16
|
};
|
|
17
17
|
const INITIAL_NAV_STACK = [{
|
|
18
|
-
name: "
|
|
18
|
+
name: "Root"
|
|
19
19
|
}];
|
|
20
|
-
const docExplorerStore = createStore((set
|
|
20
|
+
const docExplorerStore = createStore((set) => ({
|
|
21
21
|
explorerNavStack: INITIAL_NAV_STACK,
|
|
22
22
|
actions: {
|
|
23
23
|
push(item) {
|
|
@@ -63,12 +63,10 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
63
63
|
if (!ref) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const
|
|
67
|
-
push
|
|
68
|
-
} = get().actions;
|
|
66
|
+
const items = [];
|
|
69
67
|
switch (ref.kind) {
|
|
70
68
|
case "Type": {
|
|
71
|
-
push({
|
|
69
|
+
items.push({
|
|
72
70
|
name: ref.type.name,
|
|
73
71
|
def: ref.type
|
|
74
72
|
});
|
|
@@ -76,12 +74,12 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
76
74
|
}
|
|
77
75
|
case "Field": {
|
|
78
76
|
if (ref.type) {
|
|
79
|
-
push({
|
|
77
|
+
items.push({
|
|
80
78
|
name: ref.type.name,
|
|
81
79
|
def: ref.type
|
|
82
80
|
});
|
|
83
81
|
}
|
|
84
|
-
push({
|
|
82
|
+
items.push({
|
|
85
83
|
name: ref.field.name,
|
|
86
84
|
def: ref.field
|
|
87
85
|
});
|
|
@@ -89,7 +87,7 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
89
87
|
}
|
|
90
88
|
case "Argument": {
|
|
91
89
|
if (ref.field) {
|
|
92
|
-
push({
|
|
90
|
+
items.push({
|
|
93
91
|
name: ref.field.name,
|
|
94
92
|
def: ref.field
|
|
95
93
|
});
|
|
@@ -98,7 +96,7 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
98
96
|
}
|
|
99
97
|
case "EnumValue": {
|
|
100
98
|
if (ref.type) {
|
|
101
|
-
push({
|
|
99
|
+
items.push({
|
|
102
100
|
name: ref.type.name,
|
|
103
101
|
def: ref.type
|
|
104
102
|
});
|
|
@@ -106,6 +104,11 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
106
104
|
break;
|
|
107
105
|
}
|
|
108
106
|
}
|
|
107
|
+
if (items.length > 0) {
|
|
108
|
+
set({
|
|
109
|
+
explorerNavStack: [INITIAL_NAV_STACK[0], ...items]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
109
112
|
},
|
|
110
113
|
rebuildNavStackWithSchema(schema) {
|
|
111
114
|
set((state) => {
|
|
@@ -168,8 +171,21 @@ const docExplorerStore = createStore((set, get) => ({
|
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
}));
|
|
174
|
+
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
|
+
});
|
|
186
|
+
}
|
|
171
187
|
const DocExplorerStore = (t0) => {
|
|
172
|
-
const $ = c(
|
|
188
|
+
const $ = c(11);
|
|
173
189
|
const {
|
|
174
190
|
children
|
|
175
191
|
} = t0;
|
|
@@ -185,6 +201,9 @@ const DocExplorerStore = (t0) => {
|
|
|
185
201
|
validationErrors,
|
|
186
202
|
schemaReference
|
|
187
203
|
} = useGraphiQL(t1);
|
|
204
|
+
const {
|
|
205
|
+
setVisiblePlugin
|
|
206
|
+
} = useGraphiQLActions();
|
|
188
207
|
let t2;
|
|
189
208
|
let t3;
|
|
190
209
|
if ($[1] !== schemaReference) {
|
|
@@ -228,45 +247,46 @@ const DocExplorerStore = (t0) => {
|
|
|
228
247
|
}
|
|
229
248
|
useEffect(t4, t5);
|
|
230
249
|
let t6;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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;
|
|
234
272
|
} else {
|
|
235
|
-
t6 = $[
|
|
273
|
+
t6 = $[9];
|
|
274
|
+
t7 = $[10];
|
|
236
275
|
}
|
|
237
|
-
useEffect(
|
|
276
|
+
useEffect(t6, t7);
|
|
238
277
|
return children;
|
|
239
278
|
};
|
|
240
279
|
const useDocExplorerStore = createBoundedUseStore(docExplorerStore);
|
|
241
280
|
const useDocExplorer = () => {
|
|
242
|
-
return useDocExplorerStore(
|
|
281
|
+
return useDocExplorerStore(_temp);
|
|
243
282
|
};
|
|
244
283
|
const useDocExplorerActions = () => {
|
|
245
|
-
return useDocExplorerStore(
|
|
284
|
+
return useDocExplorerStore(_temp2);
|
|
246
285
|
};
|
|
247
|
-
function _temp() {
|
|
248
|
-
const el = document.querySelector(".graphiql-doc-explorer-search-input");
|
|
249
|
-
el == null ? void 0 : el.click();
|
|
250
|
-
}
|
|
251
|
-
function _temp2() {
|
|
252
|
-
const handleKeyDown = function handleKeyDown2(event) {
|
|
253
|
-
const shouldFocusInput = event.altKey && event[isMacOs ? "metaKey" : "ctrlKey"] && event.code === "KeyK";
|
|
254
|
-
if (!shouldFocusInput) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
const button = document.querySelector('.graphiql-sidebar button[aria-label="Show Documentation Explorer"]');
|
|
258
|
-
button == null ? void 0 : button.click();
|
|
259
|
-
requestAnimationFrame(_temp);
|
|
260
|
-
};
|
|
261
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
262
|
-
return () => {
|
|
263
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
function _temp3(state) {
|
|
286
|
+
function _temp(state) {
|
|
267
287
|
return state.explorerNavStack;
|
|
268
288
|
}
|
|
269
|
-
function
|
|
289
|
+
function _temp2(state) {
|
|
270
290
|
return state.actions;
|
|
271
291
|
}
|
|
272
292
|
export {
|
package/dist/context.js.map
CHANGED
|
@@ -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 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: 'Docs' }];\n\nexport const docExplorerStore = createStore<DocExplorerStoreType>(\n (set, get) => ({\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 const { push } = get().actions;\n switch (ref.kind) {\n case 'Type': {\n 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 push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n push({\n name: ref.field.name,\n def: ref.field,\n });\n break;\n }\n case 'Argument': {\n if (ref.field) {\n push({\n name: ref.field.name,\n def: ref.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (ref.type) {\n push({\n name: ref.type.name,\n def: ref.type,\n });\n }\n break;\n }\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\nexport const DocExplorerStore: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { schema, validationErrors, schemaReference } = useGraphiQL(\n pick('schema', 'validationErrors', 'schemaReference'),\n );\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 shouldFocusInput =\n // Use an additional `Alt` key instead of `Cmd/Ctrl+K` because monaco-editor has a built-in\n // shortcut for `Cmd/Ctrl+K`\n event.altKey &&\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 (!shouldFocusInput) {\n return;\n }\n const button = document.querySelector<HTMLButtonElement>(\n '.graphiql-sidebar button[aria-label=\"Show Documentation Explorer\"]',\n );\n button?.click();\n // Execute on next tick when doc explorer is opened and input exists in DOM\n requestAnimationFrame(() => {\n const el = document.querySelector<HTMLDivElement>(\n '.graphiql-doc-explorer-search-input',\n );\n el?.click();\n });\n }\n\n window.addEventListener('keydown', handleKeyDown);\n return () => {\n window.removeEventListener('keydown', handleKeyDown);\n };\n }, []);\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","get","explorerNavStack","actions","push","item","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","typeInfo","ref","getSchemaReference","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","DocExplorerStore","t0","$","_c","children","t1","Symbol","for","pick","validationErrors","t2","t3","getState","useEffect","t4","t5","t6","_temp2","useDocExplorerStore","createBoundedUseStore","useDocExplorer","_temp3","useDocExplorerActions","_temp4","_temp","el","document","querySelector","click","handleKeyDown","event","shouldFocusInput","altKey","isMacOs","code","button","requestAnimationFrame","addEventListener","removeEventListener"],"mappings":";;;;;;;;AA+BO,MAAMA,sBAAsC;AAAA,EACjDC,OAAO;AAAA,EACPC,MAAM,SAASC,OAAO;AACpB,UAAMC,gBAAgBC,YAAYC,CAASA,UAAAA,MAAMF,aAAa;AAC9D,WAAOA,kBAAkBJ,sBACvB,oBAAC,gBAAiB,CAAA,CAAA,wBAEjB,UACF,EAAA;AAAA,EACH;AAAA,EACAO,SAASC;AACX;AAwDA,MAAMC,oBAAyC,CAAC;AAAA,EAAEC,MAAM;AAAO,CAAC;AAEzD,MAAMC,mBAAmBC,YAC9B,CAACC,KAAKC,SAAS;AAAA,EACbC,kBAAkBN;AAAAA,EAClBO,SAAS;AAAA,IACPC,KAAKC,MAAM;AACTL,UAAIP,CAAS,UAAA;AACX,cAAMa,OAAOb,MAAMS;AACbK,cAAAA,WAAWD,KAAKE,GAAG,EAAE;AACrBN,cAAAA;AAAAA;AAAAA,UAEJK,SAASE,QAAQJ,KAAKI,MAAMH,OAAO,CAAC,GAAGA,MAAMD,IAAI;AAAA;AAE5C,eAAA;AAAA,UAAEH;AAAAA,QAAiB;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACAQ,MAAM;AACJV,UAAIP,CAAS,UAAA;AACX,cAAMa,OAAOb,MAAMS;AAEbA,cAAAA,mBACJI,KAAKK,SAAS,IAAKL,KAAKM,MAAM,GAAG,EAAE,IAA4BN;AAE1D,eAAA;AAAA,UAAEJ;AAAAA,QAAiB;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACAW,QAAQ;AACNb,UAAIP,CAAS,UAAA;AACX,cAAMa,OAAOb,MAAMS;AACnB,cAAMA,mBA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AAAtE,OAAA;AAAA,SACNA,MAAKU;AAAA;"}
|
|
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,sBAAsC;AAAA,EACjDC,OAAO;AAAA,EACPC,MAAM,SAASC,OAAO;AACpB,UAAMC,gBAAgBC,YAAYC,CAASA,UAAAA,MAAMF,aAAa;AAC9D,WAAOA,kBAAkBJ,sBACvB,oBAAC,gBAAiB,CAAA,CAAA,wBAEjB,UACF,EAAA;AAAA,EACH;AAAA,EACAO,SAASC;AACX;AAwDA,MAAMC,oBAAyC,CAAC;AAAA,EAAEC,MAAM;AAAO,CAAC;AAEnDC,MAAAA,mBAAmBC,YAAkCC,CAAQ,SAAA;AA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er, useDocExplorerActions } from "./context.js";
|
|
2
|
-
import { useExplorerContext } from "./deprecated.js";
|
|
3
2
|
import { Argument } from "./components/argument.js";
|
|
3
|
+
import { ArgumentsList } from "./components/arguments-list.js";
|
|
4
|
+
import { Breadcrumb } from "./components/breadcrumb.js";
|
|
4
5
|
import { DefaultValue } from "./components/default-value.js";
|
|
5
6
|
import { DeprecationReason } from "./components/deprecation-reason.js";
|
|
6
7
|
import { Directive } from "./components/directive.js";
|
|
7
8
|
import { DocExplorer } from "./components/doc-explorer.js";
|
|
9
|
+
import { FieldCard } from "./components/field-card.js";
|
|
8
10
|
import { FieldDocumentation } from "./components/field-documentation.js";
|
|
9
11
|
import { FieldLink } from "./components/field-link.js";
|
|
12
|
+
import { FieldsList } from "./components/fields-list.js";
|
|
10
13
|
import { SchemaDocumentation } from "./components/schema-documentation.js";
|
|
11
14
|
import { Search } from "./components/search.js";
|
|
15
|
+
import { SearchRow } from "./components/search-row.js";
|
|
12
16
|
import { ExplorerSection } from "./components/section.js";
|
|
17
|
+
import { TypeCard } from "./components/type-card.js";
|
|
13
18
|
import { TypeDocumentation } from "./components/type-documentation.js";
|
|
14
19
|
import { TypeLink } from "./components/type-link.js";
|
|
15
20
|
export {
|
|
16
21
|
Argument,
|
|
22
|
+
ArgumentsList,
|
|
23
|
+
Breadcrumb,
|
|
17
24
|
DOC_EXPLORER_PLUGIN,
|
|
18
25
|
DefaultValue,
|
|
19
26
|
DeprecationReason,
|
|
@@ -21,14 +28,17 @@ export {
|
|
|
21
28
|
DocExplorer,
|
|
22
29
|
DocExplorerStore,
|
|
23
30
|
ExplorerSection,
|
|
31
|
+
FieldCard,
|
|
24
32
|
FieldDocumentation,
|
|
25
33
|
FieldLink,
|
|
34
|
+
FieldsList,
|
|
26
35
|
SchemaDocumentation,
|
|
27
36
|
Search,
|
|
37
|
+
SearchRow,
|
|
38
|
+
TypeCard,
|
|
28
39
|
TypeDocumentation,
|
|
29
40
|
TypeLink,
|
|
30
41
|
useDocExplorer,
|
|
31
|
-
useDocExplorerActions
|
|
32
|
-
useExplorerContext
|
|
42
|
+
useDocExplorerActions
|
|
33
43
|
};
|
|
34
44
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
declare const meta: Meta;
|
|
3
|
+
export default meta;
|
|
4
|
+
type Story = StoryObj;
|
|
5
|
+
export declare const SchemaOverview: Story;
|
|
6
|
+
export declare const TypeDetailObject: Story;
|
|
7
|
+
export declare const TypeDetailInterface: Story;
|
|
8
|
+
export declare const TypeDetailInput: Story;
|
|
9
|
+
export declare const TypeDetailEnum: Story;
|
|
10
|
+
export declare const FieldDetail: Story;
|
|
11
|
+
export declare const BreadcrumbNav: Story;
|
|
12
|
+
export declare const TokenColors: Story;
|