@graphiql/plugin-doc-explorer 0.1.1-canary-059ebca8.0 → 0.1.1-canary-db8bf69b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/type-documentation.js +2 -2
- package/dist/components/type-documentation.js.map +1 -1
- package/dist/context.d.ts +2 -4
- package/dist/context.js +157 -183
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -299,7 +299,7 @@ const EnumValue = (t0) => {
|
|
|
299
299
|
}
|
|
300
300
|
let t2;
|
|
301
301
|
if ($[2] !== value.description) {
|
|
302
|
-
t2 = value.description
|
|
302
|
+
t2 = value.description && /* @__PURE__ */ jsx(MarkdownContent, { type: "description", children: value.description });
|
|
303
303
|
$[2] = value.description;
|
|
304
304
|
$[3] = t2;
|
|
305
305
|
} else {
|
|
@@ -307,7 +307,7 @@ const EnumValue = (t0) => {
|
|
|
307
307
|
}
|
|
308
308
|
let t3;
|
|
309
309
|
if ($[4] !== value.deprecationReason) {
|
|
310
|
-
t3 = value.deprecationReason
|
|
310
|
+
t3 = value.deprecationReason && /* @__PURE__ */ jsx(MarkdownContent, { type: "deprecation", children: value.deprecationReason });
|
|
311
311
|
$[4] = value.deprecationReason;
|
|
312
312
|
$[5] = t3;
|
|
313
313
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-documentation.js","sources":["../../src/components/type-documentation.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport {\n GraphQLEnumValue,\n GraphQLNamedType,\n isAbstractType,\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n} from 'graphql';\nimport { useSchemaStore, Button, MarkdownContent } from '@graphiql/react';\nimport { DocExplorerFieldDef } from '../context';\nimport { Argument } from './argument';\nimport { DefaultValue } from './default-value';\nimport { DeprecationReason } from './deprecation-reason';\nimport { FieldLink } from './field-link';\nimport { ExplorerSection } from './section';\nimport { TypeLink } from './type-link';\nimport './type-documentation.css';\n\ntype TypeDocumentationProps = {\n /**\n * The type that should be rendered.\n */\n type: GraphQLNamedType;\n};\n\nexport const TypeDocumentation: FC<TypeDocumentationProps> = ({ type }) => {\n return isNamedType(type) ? (\n <>\n {type.description ? (\n <MarkdownContent type=\"description\">{type.description}</MarkdownContent>\n ) : null}\n <ImplementsInterfaces type={type} />\n <Fields type={type} />\n <EnumValues type={type} />\n <PossibleTypes type={type} />\n </>\n ) : null;\n};\n\nconst ImplementsInterfaces: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n if (!isObjectType(type)) {\n return null;\n }\n const interfaces = type.getInterfaces();\n return interfaces.length > 0 ? (\n <ExplorerSection title=\"Implements\">\n {type.getInterfaces().map(implementedInterface => (\n <div key={implementedInterface.name}>\n <TypeLink type={implementedInterface} />\n </div>\n ))}\n </ExplorerSection>\n ) : null;\n};\n\nconst Fields: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (\n !isObjectType(type) &&\n !isInterfaceType(type) &&\n !isInputObjectType(type)\n ) {\n return null;\n }\n\n const fieldMap = type.getFields();\n\n const fields: DocExplorerFieldDef[] = [];\n const deprecatedFields: DocExplorerFieldDef[] = [];\n\n for (const field of Object.keys(fieldMap).map(name => fieldMap[name])) {\n if (field.deprecationReason) {\n deprecatedFields.push(field);\n } else {\n fields.push(field);\n }\n }\n\n return (\n <>\n {fields.length > 0 ? (\n <ExplorerSection title=\"Fields\">\n {fields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedFields.length > 0 ? (\n showDeprecated || fields.length === 0 ? (\n <ExplorerSection title=\"Deprecated Fields\">\n {deprecatedFields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Fields\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst Field: FC<{ field: DocExplorerFieldDef }> = ({ field }) => {\n const args =\n 'args' in field ? field.args.filter(arg => !arg.deprecationReason) : [];\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div>\n <FieldLink field={field} />\n {args.length > 0 ? (\n <>\n (\n <span>\n {args.map(arg =>\n args.length === 1 ? (\n <Argument key={arg.name} arg={arg} inline />\n ) : (\n <div\n key={arg.name}\n className=\"graphiql-doc-explorer-argument-multiple\"\n >\n <Argument arg={arg} inline />\n </div>\n ),\n )}\n </span>\n )\n </>\n ) : null}\n {': '}\n <TypeLink type={field.type} />\n <DefaultValue field={field} />\n </div>\n {field.description ? (\n <MarkdownContent type=\"description\" onlyShowFirstChild>\n {field.description}\n </MarkdownContent>\n ) : null}\n <DeprecationReason>{field.deprecationReason}</DeprecationReason>\n </div>\n );\n};\n\nconst EnumValues: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (!isEnumType(type)) {\n return null;\n }\n\n const values: GraphQLEnumValue[] = [];\n const deprecatedValues: GraphQLEnumValue[] = [];\n for (const value of type.getValues()) {\n if (value.deprecationReason) {\n deprecatedValues.push(value);\n } else {\n values.push(value);\n }\n }\n\n return (\n <>\n {values.length > 0 ? (\n <ExplorerSection title=\"Enum Values\">\n {values.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedValues.length > 0 ? (\n showDeprecated || values.length === 0 ? (\n <ExplorerSection title=\"Deprecated Enum Values\">\n {deprecatedValues.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Values\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst EnumValue: FC<{ value: GraphQLEnumValue }> = ({ value }) => {\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div className=\"graphiql-doc-explorer-enum-value\">{value.name}</div>\n {value.description ? (\n <MarkdownContent type=\"description\">\n {value.description}\n </MarkdownContent>\n ) : null}\n {value.deprecationReason ? (\n <MarkdownContent type=\"deprecation\">\n {value.deprecationReason}\n </MarkdownContent>\n ) : null}\n </div>\n );\n};\n\nconst PossibleTypes: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const { schema } = useSchemaStore();\n if (!schema || !isAbstractType(type)) {\n return null;\n }\n return (\n <ExplorerSection\n title={isInterfaceType(type) ? 'Implementations' : 'Possible Types'}\n >\n {schema.getPossibleTypes(type).map(possibleType => (\n <div key={possibleType.name}>\n <TypeLink type={possibleType} />\n </div>\n ))}\n </ExplorerSection>\n );\n};\n"],"names":["TypeDocumentation","t0","$","_c","type","t1","isNamedType","description","ImplementsInterfaces","isObjectType","getInterfaces","interfaces","t2","length","map","_temp","Fields","showDeprecated","setShowDeprecated","useState","Symbol","for","handleShowDeprecated","isInterfaceType","isInputObjectType","deprecatedFields","fields","fieldMap","getFields","field","Object","keys","name","deprecationReason","push","_temp2","t3","_temp3","t4","Field","args","filter","_temp4","arg_0","arg","t5","t6","t7","t8","t9","EnumValues","isEnumType","deprecatedValues","values","value","getValues","_temp5","_temp6","EnumValue","PossibleTypes","schema","useSchemaStore","isAbstractType","getPossibleTypes","_temp7","implementedInterface","field_0","field_1","value_0","value_1","possibleType"],"mappings":";;;;;;;;;;;;AA4BO,MAAMA,oBAAgDC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AAAQI,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAC7DE,SAAAA,YAAYF,IAAI,IAElBA,qBAAAA,UAAAA,EAAAA,UAAAA;AAAAA,MAAAA,KAAIG,cACF,oBAAA,iBAAA,EAAqB,MAAA,eAAeH,UAAAA,KAAIG,a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BA,QAAKtB,IAAuB;AAAA;AAzBL,SAAAyB,OAAAY,SAAA;AAAA,SAiCpC,oBAAA,WAAA,EAAkCf,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AA+BJ,SAAAgC,OAAAM,cAAA;AAU9C,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,mBAAY,CAAA,KADpBA,aAAYtC,IAEtB;AAAM;"}
|
|
1
|
+
{"version":3,"file":"type-documentation.js","sources":["../../src/components/type-documentation.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport {\n GraphQLEnumValue,\n GraphQLNamedType,\n isAbstractType,\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n} from 'graphql';\nimport { useSchemaStore, Button, MarkdownContent } from '@graphiql/react';\nimport { DocExplorerFieldDef } from '../context';\nimport { Argument } from './argument';\nimport { DefaultValue } from './default-value';\nimport { DeprecationReason } from './deprecation-reason';\nimport { FieldLink } from './field-link';\nimport { ExplorerSection } from './section';\nimport { TypeLink } from './type-link';\nimport './type-documentation.css';\n\ntype TypeDocumentationProps = {\n /**\n * The type that should be rendered.\n */\n type: GraphQLNamedType;\n};\n\nexport const TypeDocumentation: FC<TypeDocumentationProps> = ({ type }) => {\n return isNamedType(type) ? (\n <>\n {type.description ? (\n <MarkdownContent type=\"description\">{type.description}</MarkdownContent>\n ) : null}\n <ImplementsInterfaces type={type} />\n <Fields type={type} />\n <EnumValues type={type} />\n <PossibleTypes type={type} />\n </>\n ) : null;\n};\n\nconst ImplementsInterfaces: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n if (!isObjectType(type)) {\n return null;\n }\n const interfaces = type.getInterfaces();\n return interfaces.length > 0 ? (\n <ExplorerSection title=\"Implements\">\n {type.getInterfaces().map(implementedInterface => (\n <div key={implementedInterface.name}>\n <TypeLink type={implementedInterface} />\n </div>\n ))}\n </ExplorerSection>\n ) : null;\n};\n\nconst Fields: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (\n !isObjectType(type) &&\n !isInterfaceType(type) &&\n !isInputObjectType(type)\n ) {\n return null;\n }\n\n const fieldMap = type.getFields();\n\n const fields: DocExplorerFieldDef[] = [];\n const deprecatedFields: DocExplorerFieldDef[] = [];\n\n for (const field of Object.keys(fieldMap).map(name => fieldMap[name])) {\n if (field.deprecationReason) {\n deprecatedFields.push(field);\n } else {\n fields.push(field);\n }\n }\n\n return (\n <>\n {fields.length > 0 ? (\n <ExplorerSection title=\"Fields\">\n {fields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedFields.length > 0 ? (\n showDeprecated || fields.length === 0 ? (\n <ExplorerSection title=\"Deprecated Fields\">\n {deprecatedFields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Fields\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst Field: FC<{ field: DocExplorerFieldDef }> = ({ field }) => {\n const args =\n 'args' in field ? field.args.filter(arg => !arg.deprecationReason) : [];\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div>\n <FieldLink field={field} />\n {args.length > 0 ? (\n <>\n (\n <span>\n {args.map(arg =>\n args.length === 1 ? (\n <Argument key={arg.name} arg={arg} inline />\n ) : (\n <div\n key={arg.name}\n className=\"graphiql-doc-explorer-argument-multiple\"\n >\n <Argument arg={arg} inline />\n </div>\n ),\n )}\n </span>\n )\n </>\n ) : null}\n {': '}\n <TypeLink type={field.type} />\n <DefaultValue field={field} />\n </div>\n {field.description ? (\n <MarkdownContent type=\"description\" onlyShowFirstChild>\n {field.description}\n </MarkdownContent>\n ) : null}\n <DeprecationReason>{field.deprecationReason}</DeprecationReason>\n </div>\n );\n};\n\nconst EnumValues: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (!isEnumType(type)) {\n return null;\n }\n\n const values: GraphQLEnumValue[] = [];\n const deprecatedValues: GraphQLEnumValue[] = [];\n for (const value of type.getValues()) {\n if (value.deprecationReason) {\n deprecatedValues.push(value);\n } else {\n values.push(value);\n }\n }\n\n return (\n <>\n {values.length > 0 ? (\n <ExplorerSection title=\"Enum Values\">\n {values.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedValues.length > 0 ? (\n showDeprecated || values.length === 0 ? (\n <ExplorerSection title=\"Deprecated Enum Values\">\n {deprecatedValues.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Values\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst EnumValue: FC<{ value: GraphQLEnumValue }> = ({ value }) => {\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div className=\"graphiql-doc-explorer-enum-value\">{value.name}</div>\n {value.description && (\n <MarkdownContent type=\"description\">\n {value.description}\n </MarkdownContent>\n )}\n {value.deprecationReason && (\n <MarkdownContent type=\"deprecation\">\n {value.deprecationReason}\n </MarkdownContent>\n )}\n </div>\n );\n};\n\nconst PossibleTypes: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const { schema } = useSchemaStore();\n if (!schema || !isAbstractType(type)) {\n return null;\n }\n return (\n <ExplorerSection\n title={isInterfaceType(type) ? 'Implementations' : 'Possible Types'}\n >\n {schema.getPossibleTypes(type).map(possibleType => (\n <div key={possibleType.name}>\n <TypeLink type={possibleType} />\n </div>\n ))}\n </ExplorerSection>\n );\n};\n"],"names":["TypeDocumentation","t0","$","_c","type","t1","isNamedType","description","ImplementsInterfaces","isObjectType","getInterfaces","interfaces","t2","length","map","_temp","Fields","showDeprecated","setShowDeprecated","useState","Symbol","for","handleShowDeprecated","isInterfaceType","isInputObjectType","deprecatedFields","fields","fieldMap","getFields","field","Object","keys","name","deprecationReason","push","_temp2","t3","_temp3","t4","Field","args","filter","_temp4","arg_0","arg","t5","t6","t7","t8","t9","EnumValues","isEnumType","deprecatedValues","values","value","getValues","_temp5","_temp6","EnumValue","PossibleTypes","schema","useSchemaStore","isAbstractType","getPossibleTypes","_temp7","implementedInterface","field_0","field_1","value_0","value_1","possibleType"],"mappings":";;;;;;;;;;;;AA4BO,MAAMA,oBAAgDC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AAAQI,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAC7DE,SAAAA,YAAYF,IAAI,IAElBA,qBAAAA,UAAAA,EAAAA,UAAAA;AAAAA,MAAAA,KAAIG,cACF,oBAAA,iBAAA,EAAqB,MAAA,eAAeH,UAAAA,KAAIG,aAAa,IACjD;AAAA,MACP,oBAAC,wBAA2BH,MAAI;AAAA,MAChC,oBAAC,UAAaA,MAAI;AAAA,MAClB,oBAAC,cAAiBA,MAAI;AAAA,MACtB,oBAAC,iBAAoBA,KAAI,CAAA;AAAA,IAAA,EAAA,CAAI,IAEzB;AAAAF,WAAAE;AAAAF,WAAAG;AAAAA,EAAAA,OAAA;AAAAA,SAAAH,EAAA,CAAA;AAAA,EAAA;AAVDG,SAAAA;AAUC;AAGV,MAAMG,uBAAuDP,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AACvDQ,MAAAA,CAAAA,aAAaL,IAAI,GAAC;AAAA,WAAA;AAAA,EAAA;AAAAC,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAGJC,SAAAD,KAAIM,cAAe;AAACR,WAAAE;AAAAF,WAAAG;AAAAA,EAAAA,OAAA;AAAAA,SAAAH,EAAA,CAAA;AAAA,EAAA;AAAvC,QAAAS,aAAmBN;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AA,OAAA;AAAAA,SAAAlC,EAAA,CAAA;AAAA,EAAA;AARlBkC,SAAAA;AAQkB;AA5LuC,SAAArB,MAAAkD,sBAAA;AAQrD,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,2BAAoB,CAAA,KAD5BA,qBAAoBjC,IAE9B;AAAM;AAMiC,SAAAG,OAAA+B,SAAA;AAAA,SAgClC,oBAAA,OAAA,EAA8BrC,OAAAA,QAAAA,GAAnBA,QAAKG,IAAuB;AAAA;AAhCL,SAAAK,OAAA8B,SAAA;AAAA,SAwChC,oBAAA,OAAA,EAA8BtC,OAAAA,QAAAA,GAAnBA,QAAKG,IAAuB;AAAA;AAaJ,SAAAU,OAAAE,KAAA;AAAA,SAEFA,CAAAA,IAAGX;AAAA;AAuCA,SAAAuB,OAAAY,SAAA;AAAA,SAyBtC,oBAAA,WAAA,EAAkCd,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AAzBL,SAAAyB,OAAAY,SAAA;AAAA,SAiCpC,oBAAA,WAAA,EAAkCf,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AA+BJ,SAAAgC,OAAAM,cAAA;AAU9C,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,mBAAY,CAAA,KADpBA,aAAYtC,IAEtB;AAAM;"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GraphQLArgument, GraphQLField, GraphQLInputField, GraphQLNamedType, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { FC, ReactNode
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
3
|
import { SchemaContextType } from '@graphiql/react';
|
|
4
|
-
import { StoreApi } from 'zustand';
|
|
5
4
|
export declare type DocExplorerFieldDef = GraphQLField<unknown, unknown> | GraphQLInputField | GraphQLArgument;
|
|
6
5
|
export declare type DocExplorerNavStackItem = {
|
|
7
6
|
/**
|
|
@@ -46,8 +45,7 @@ export declare type DocExplorerContextType = {
|
|
|
46
45
|
rebuildNavStackWithSchema(schema: GraphQLSchema): void;
|
|
47
46
|
};
|
|
48
47
|
};
|
|
49
|
-
export declare
|
|
50
|
-
export declare const DocExplorerContext: import('react').Context<RefObject<StoreApi<DocExplorerContextType>> | null>;
|
|
48
|
+
export declare const docExplorerStore: import('zustand').StoreApi<DocExplorerContextType>;
|
|
51
49
|
export declare const DocExplorerContextProvider: FC<{
|
|
52
50
|
children: ReactNode;
|
|
53
51
|
}>;
|
package/dist/context.js
CHANGED
|
@@ -1,228 +1,203 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
import { c } from "react-compiler-runtime";
|
|
3
2
|
import { isNamedType, isObjectType, isInputObjectType, isScalarType, isEnumType, isInterfaceType, isUnionType } from "graphql";
|
|
4
|
-
import {
|
|
5
|
-
import { useSchemaStore } from "@graphiql/react";
|
|
6
|
-
import { createStore
|
|
7
|
-
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { useSchemaStore, createBoundedUseStore } from "@graphiql/react";
|
|
5
|
+
import { createStore } from "zustand";
|
|
6
|
+
const INITIAL_NAV_STACK = [{
|
|
8
7
|
name: "Docs"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
}];
|
|
9
|
+
const docExplorerStore = createStore((set, get) => ({
|
|
10
|
+
explorerNavStack: INITIAL_NAV_STACK,
|
|
11
|
+
actions: {
|
|
12
|
+
push(item) {
|
|
13
|
+
set((state) => {
|
|
14
|
+
const curr = state.explorerNavStack;
|
|
15
|
+
const lastItem = curr.at(-1);
|
|
16
|
+
const explorerNavStack = (
|
|
17
|
+
// Avoid pushing duplicate items
|
|
18
|
+
lastItem.def === item.def ? curr : [...curr, item]
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
explorerNavStack
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
pop() {
|
|
26
|
+
set((state) => {
|
|
27
|
+
const curr = state.explorerNavStack;
|
|
28
|
+
const explorerNavStack = curr.length > 1 ? curr.slice(0, -1) : curr;
|
|
29
|
+
return {
|
|
30
|
+
explorerNavStack
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
reset() {
|
|
35
|
+
set((state) => {
|
|
36
|
+
const curr = state.explorerNavStack;
|
|
37
|
+
const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;
|
|
38
|
+
return {
|
|
39
|
+
explorerNavStack
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
resolveSchemaReferenceToNavItem(schemaReference) {
|
|
44
|
+
if (!schemaReference) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const {
|
|
48
|
+
push
|
|
49
|
+
} = get().actions;
|
|
50
|
+
switch (schemaReference.kind) {
|
|
51
|
+
case "Type": {
|
|
52
|
+
push({
|
|
53
|
+
name: schemaReference.type.name,
|
|
54
|
+
def: schemaReference.type
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
push
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case "Field": {
|
|
58
|
+
case "Field": {
|
|
59
|
+
push({
|
|
60
|
+
name: schemaReference.field.name,
|
|
61
|
+
def: schemaReference.field
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "Argument": {
|
|
66
|
+
if (schemaReference.field) {
|
|
60
67
|
push({
|
|
61
68
|
name: schemaReference.field.name,
|
|
62
69
|
def: schemaReference.field
|
|
63
70
|
});
|
|
64
|
-
break;
|
|
65
71
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
case "EnumValue": {
|
|
76
|
-
if (schemaReference.type) {
|
|
77
|
-
push({
|
|
78
|
-
name: schemaReference.type.name,
|
|
79
|
-
def: schemaReference.type
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "EnumValue": {
|
|
75
|
+
if (schemaReference.type) {
|
|
76
|
+
push({
|
|
77
|
+
name: schemaReference.type.name,
|
|
78
|
+
def: schemaReference.type
|
|
79
|
+
});
|
|
83
80
|
}
|
|
81
|
+
break;
|
|
84
82
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
rebuildNavStackWithSchema(schema) {
|
|
86
|
+
set((state) => {
|
|
87
|
+
const oldNavStack = state.explorerNavStack;
|
|
88
|
+
if (oldNavStack.length === 1) {
|
|
89
|
+
return oldNavStack;
|
|
90
|
+
}
|
|
91
|
+
const newNavStack = [...INITIAL_NAV_STACK];
|
|
92
|
+
let lastEntity = null;
|
|
93
|
+
for (const item of oldNavStack) {
|
|
94
|
+
if (item === INITIAL_NAV_STACK[0]) {
|
|
95
|
+
continue;
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
newNavStack.push({
|
|
103
|
-
name: item.name,
|
|
104
|
-
def: newType
|
|
105
|
-
});
|
|
106
|
-
lastEntity = newType;
|
|
107
|
-
} else {
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
} else if (lastEntity === null) {
|
|
111
|
-
break;
|
|
112
|
-
} else if (isObjectType(lastEntity) || isInputObjectType(lastEntity)) {
|
|
113
|
-
const field = lastEntity.getFields()[item.name];
|
|
114
|
-
if (field) {
|
|
115
|
-
newNavStack.push({
|
|
116
|
-
name: item.name,
|
|
117
|
-
def: field
|
|
118
|
-
});
|
|
119
|
-
} else {
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
} else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
97
|
+
if (item.def) {
|
|
98
|
+
if (isNamedType(item.def)) {
|
|
99
|
+
const newType = schema.getType(item.def.name);
|
|
100
|
+
if (newType) {
|
|
101
|
+
newNavStack.push({
|
|
102
|
+
name: item.name,
|
|
103
|
+
def: newType
|
|
104
|
+
});
|
|
105
|
+
lastEntity = newType;
|
|
106
|
+
} else {
|
|
123
107
|
break;
|
|
108
|
+
}
|
|
109
|
+
} else if (lastEntity === null) {
|
|
110
|
+
break;
|
|
111
|
+
} else if (isObjectType(lastEntity) || isInputObjectType(lastEntity)) {
|
|
112
|
+
const field = lastEntity.getFields()[item.name];
|
|
113
|
+
if (field) {
|
|
114
|
+
newNavStack.push({
|
|
115
|
+
name: item.name,
|
|
116
|
+
def: field
|
|
117
|
+
});
|
|
124
118
|
} else {
|
|
125
|
-
|
|
126
|
-
if (field.args.some((a) => a.name === item.name)) {
|
|
127
|
-
newNavStack.push({
|
|
128
|
-
name: item.name,
|
|
129
|
-
def: field
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
119
|
+
break;
|
|
134
120
|
}
|
|
121
|
+
} else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
122
|
+
break;
|
|
135
123
|
} else {
|
|
136
|
-
|
|
137
|
-
|
|
124
|
+
const field = lastEntity;
|
|
125
|
+
if (field.args.some((a) => a.name === item.name)) {
|
|
126
|
+
newNavStack.push({
|
|
127
|
+
name: item.name,
|
|
128
|
+
def: field
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
138
133
|
}
|
|
134
|
+
} else {
|
|
135
|
+
lastEntity = null;
|
|
136
|
+
newNavStack.push(item);
|
|
139
137
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
explorerNavStack: newNavStack
|
|
141
|
+
};
|
|
142
|
+
});
|
|
145
143
|
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
const DocExplorerContextProvider = (t0) => {
|
|
147
|
+
const $ = c(7);
|
|
148
|
+
const {
|
|
149
|
+
children
|
|
150
|
+
} = t0;
|
|
151
151
|
const {
|
|
152
152
|
schema,
|
|
153
153
|
validationErrors,
|
|
154
154
|
schemaReference
|
|
155
155
|
} = useSchemaStore();
|
|
156
|
-
const storeRef = useRef(null);
|
|
157
|
-
if (storeRef.current === null) {
|
|
158
|
-
let t02;
|
|
159
|
-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
160
|
-
t02 = createDocExplorerStore();
|
|
161
|
-
$[0] = t02;
|
|
162
|
-
} else {
|
|
163
|
-
t02 = $[0];
|
|
164
|
-
}
|
|
165
|
-
storeRef.current = t02;
|
|
166
|
-
}
|
|
167
|
-
let t0;
|
|
168
156
|
let t1;
|
|
169
|
-
|
|
170
|
-
|
|
157
|
+
let t2;
|
|
158
|
+
if ($[0] !== schemaReference) {
|
|
159
|
+
t1 = () => {
|
|
171
160
|
const {
|
|
172
161
|
resolveSchemaReferenceToNavItem
|
|
173
|
-
} =
|
|
162
|
+
} = docExplorerStore.getState().actions;
|
|
174
163
|
resolveSchemaReferenceToNavItem(schemaReference);
|
|
175
164
|
};
|
|
176
|
-
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
165
|
+
t2 = [schemaReference];
|
|
166
|
+
$[0] = schemaReference;
|
|
167
|
+
$[1] = t1;
|
|
168
|
+
$[2] = t2;
|
|
180
169
|
} else {
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
t1 = $[1];
|
|
171
|
+
t2 = $[2];
|
|
183
172
|
}
|
|
184
|
-
useEffect(
|
|
185
|
-
let t2;
|
|
173
|
+
useEffect(t1, t2);
|
|
186
174
|
let t3;
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
let t4;
|
|
176
|
+
if ($[3] !== schema || $[4] !== validationErrors) {
|
|
177
|
+
t3 = () => {
|
|
189
178
|
const {
|
|
190
179
|
reset,
|
|
191
180
|
rebuildNavStackWithSchema
|
|
192
|
-
} =
|
|
181
|
+
} = docExplorerStore.getState().actions;
|
|
193
182
|
if (schema == null || validationErrors.length > 0) {
|
|
194
183
|
reset();
|
|
195
184
|
} else {
|
|
196
185
|
rebuildNavStackWithSchema(schema);
|
|
197
186
|
}
|
|
198
187
|
};
|
|
199
|
-
|
|
200
|
-
$[
|
|
201
|
-
$[
|
|
202
|
-
$[
|
|
203
|
-
$[
|
|
188
|
+
t4 = [schema, validationErrors];
|
|
189
|
+
$[3] = schema;
|
|
190
|
+
$[4] = validationErrors;
|
|
191
|
+
$[5] = t3;
|
|
192
|
+
$[6] = t4;
|
|
204
193
|
} else {
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
t3 = $[5];
|
|
195
|
+
t4 = $[6];
|
|
207
196
|
}
|
|
208
|
-
useEffect(
|
|
209
|
-
|
|
210
|
-
if ($[8] !== props.children) {
|
|
211
|
-
t4 = /* @__PURE__ */ jsx(DocExplorerContext.Provider, { value: storeRef, children: props.children });
|
|
212
|
-
$[8] = props.children;
|
|
213
|
-
$[9] = t4;
|
|
214
|
-
} else {
|
|
215
|
-
t4 = $[9];
|
|
216
|
-
}
|
|
217
|
-
return t4;
|
|
197
|
+
useEffect(t3, t4);
|
|
198
|
+
return children;
|
|
218
199
|
};
|
|
219
|
-
|
|
220
|
-
const store = useContext(DocExplorerContext);
|
|
221
|
-
if (!store) {
|
|
222
|
-
throw new Error("Missing `DocExplorerContextProvider` in the tree");
|
|
223
|
-
}
|
|
224
|
-
return useStore(store.current, selector);
|
|
225
|
-
}
|
|
200
|
+
const useDocExplorerStore = createBoundedUseStore(docExplorerStore);
|
|
226
201
|
const useDocExplorer = () => {
|
|
227
202
|
return useDocExplorerStore(_temp);
|
|
228
203
|
};
|
|
@@ -236,9 +211,8 @@ function _temp2(state) {
|
|
|
236
211
|
return state.actions;
|
|
237
212
|
}
|
|
238
213
|
export {
|
|
239
|
-
DocExplorerContext,
|
|
240
214
|
DocExplorerContextProvider,
|
|
241
|
-
|
|
215
|
+
docExplorerStore,
|
|
242
216
|
useDocExplorer,
|
|
243
217
|
useDocExplorerActions
|
|
244
218
|
};
|
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 {\n createContext,\n FC,\n ReactNode,\n RefObject,\n useContext,\n useEffect,\n useRef,\n} from 'react';\nimport { SchemaContextType, useSchemaStore } from '@graphiql/react';\nimport { createStore, StoreApi, useStore } from 'zustand';\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 DocExplorerContextType = {\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: SchemaContextType['schemaReference'],\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\nexport function createDocExplorerStore(\n initialNavStackItem: DocExplorerNavStackItem = { name: 'Docs' },\n) {\n return createStore<DocExplorerContextType>((set, get) => ({\n explorerNavStack: [initialNavStackItem],\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: DocExplorerNavStack =\n curr.length === 1 ? curr : [initialNavStackItem];\n return { explorerNavStack };\n });\n },\n resolveSchemaReferenceToNavItem(schemaReference) {\n if (!schemaReference) {\n return;\n }\n const { push } = get().actions;\n switch (schemaReference.kind) {\n case 'Type': {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n break;\n }\n case 'Field': {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n break;\n }\n case 'Argument': {\n if (schemaReference.field) {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (schemaReference.type) {\n push({\n name: schemaReference.type.name,\n def: schemaReference.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 oldNavStack;\n }\n const newNavStack: DocExplorerNavStack = [initialNavStackItem];\n let lastEntity:\n | GraphQLNamedType\n | GraphQLField<unknown, unknown>\n | null = null;\n for (const item of oldNavStack) {\n if (item === initialNavStackItem) {\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 DocExplorerContext = createContext<RefObject<\n StoreApi<DocExplorerContextType>\n> | null>(null);\n\nexport const DocExplorerContextProvider: FC<{\n children: ReactNode;\n}> = props => {\n const { schema, validationErrors, schemaReference } = useSchemaStore();\n const storeRef = useRef<StoreApi<DocExplorerContextType>>(null!);\n\n if (storeRef.current === null) {\n storeRef.current = createDocExplorerStore();\n }\n\n useEffect(() => {\n const { resolveSchemaReferenceToNavItem } =\n storeRef.current.getState().actions;\n resolveSchemaReferenceToNavItem(schemaReference);\n }, [schemaReference]);\n\n useEffect(() => {\n const { reset, rebuildNavStackWithSchema } =\n storeRef.current.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 return (\n <DocExplorerContext.Provider value={storeRef}>\n {props.children}\n </DocExplorerContext.Provider>\n );\n};\n\nfunction useDocExplorerStore<T>(\n selector: (state: DocExplorerContextType) => T,\n): T {\n const store = useContext(DocExplorerContext);\n if (!store) {\n throw new Error('Missing `DocExplorerContextProvider` in the tree');\n }\n return useStore(store.current, selector);\n}\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\nexport const useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"names":["createDocExplorerStore","initialNavStackItem","name","createStore","set","get","explorerNavStack","actions","push","item","state","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","DocExplorerContext","createContext","DocExplorerContextProvider","props","$","_c","validationErrors","useSchemaStore","storeRef","useRef","current","t0","Symbol","for","t1","getState","useEffect","t2","t3","t4","children","useDocExplorerStore","selector","store","useContext","Error","useStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;;AAkFO,SAASA,uBACdC,sBAA+C;AAAA,EAAEC,MAAM;AAAO,GAC9D;AACOC,SAAAA,YAAoC,CAACC,KAAKC,SAAS;AAAA,IACxDC,kBAAkB,CAACL,mBAAmB;AAAA,IACtCM,SAAS;AAAA,MACPC,KAAKC,MAAM;AACTL,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ;AACbM,gBAAAA,WAAWD,KAAKE,GAAG,EAAE;AACrBP,gBAAAA;AAAAA;AAAAA,YAEJM,SAASE,QAAQL,KAAKK,MAAMH,OAAO,CAAC,GAAGA,MAAMF,IAAI;AAAA;AAE5C,iBAAA;AAAA,YAAEH;AAAAA,UAAiB;AAAA,QAAA,CAC3B;AAAA,MACH;AAAA,MACAS,MAAM;AACJX,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ;AAEbA,gBAAAA,mBACJK,KAAKK,SAAS,IAAKL,KAAKM,MAAM,GAAG,EAAE,IAA4BN;AAE1D,iBAAA;AAAA,YAAEL;AAAAA,UAAiB;AAAA,QAAA,CAC3B;AAAA,MACH;AAAA,MACAY,QAAQ;AACNd,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ;AACnB,gBAAMA,mBACJK,KAAKK,WAAW,IAAIL,OAAO,CAACV,mBAAmB;AAC1C,iBAAA;AAAA,YAAEK;AAAAA,UAAiB;AAAA,QAAA,CAC3B;AAAA,MAC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AV7BY,YAAUC,IAUPC,EAA0B;AAACC,MAAAA;AAAA,MAAAf,EAAA,CAAA,MAAAD,MAAAiB,UAAA;AAG5BD,6BAAA,mBAAA,UAAA,EAAoCX,OAAO,UACxCL,gBAAKiB,UACR;AAA8B,MAAA,CAAA,IAAAjB,MAAAiB;AAAAhB,WAAAe;AAAAA,EAAAA,OAAA;AAAAA,SAAAf,EAAA,CAAA;AAAA,EAAA;AAF9Be,SAAAA;AAE8B;AAIlC,SAAAE,oBAAAC,UAAA;AAGEC,QAAAA,QAAcC,WAAAxB,kBAA6B;AAAE,MAAA,CACxCuB,OAAK;AAAAE,UAAAA,IAAAA,MACQ,kDAAkD;AAAA,EAAA;AAE7DC,SAAAA,SAASH,MAAKb,SAAUY,QAAQ;AAAC;AAGnC,MAAMK,iBAAiBA,MAAA;AAAA,SAC5BN,oBAAAO,KAAmD;AAAC;AAC/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCR,oBAAAS,MAA0C;AAAC;AAHf,SAAAF,MAAA5D,OAAA;AAAA,SACCA,MAAKJ;AAAA;AACC,SAAAkE,OAAA9D,OAAA;AAAA,SACNA,MAAKH;AAAA;"}
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.ts"],"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 SchemaContextType,\n useSchemaStore,\n createBoundedUseStore,\n} from '@graphiql/react';\nimport { createStore } from 'zustand';\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 DocExplorerContextType = {\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: SchemaContextType['schemaReference'],\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<DocExplorerContextType>(\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 { push } = get().actions;\n switch (schemaReference.kind) {\n case 'Type': {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n break;\n }\n case 'Field': {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n break;\n }\n case 'Argument': {\n if (schemaReference.field) {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (schemaReference.type) {\n push({\n name: schemaReference.type.name,\n def: schemaReference.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 oldNavStack;\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 DocExplorerContextProvider: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { schema, validationErrors, schemaReference } = useSchemaStore();\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 return children as ReactElement;\n};\n\nconst useDocExplorerStore = createBoundedUseStore(docExplorerStore);\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\nexport const useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"names":["INITIAL_NAV_STACK","name","docExplorerStore","createStore","set","get","explorerNavStack","actions","push","item","state","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","DocExplorerContextProvider","t0","$","_c","children","validationErrors","useSchemaStore","t1","t2","getState","useEffect","t3","t4","useDocExplorerStore","createBoundedUseStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;AA8EA,MAAMA,oBAAyC,CAAC;AAAA,EAAEC,MAAM;AAAO,CAAC;AAEzD,MAAMC,mBAAmBC,YAC9B,CAACC,KAAKC,SAAS;AAAA,EACbC,kBAAkBN;AAAAA,EAClBO,SAAS;AAAA,IACPC,KAAK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;AACR,YAAA;AAAA,QAAAnC;AAAAA,QAAAM;AAAAA,MAAAA,IACEtB,iBAAAiD,SAAAA,EAA2B5C;AAAS,UAGlCkB,UAAc,QAAIsB,iBAAgB/B,SAAW,GAAA;AACzC,cAAA;AAAA,MAAA,OAAC;AAEPQ,kCAA0BC,MAAM;AAAA,MAAA;AAAA,IAAC;AAElC,SAAA,CAACA,QAAQsB,gBAAgB;AAACH,WAAAnB;AAAAmB,WAAAG;AAAAH,WAAAS;AAAAT,WAAAU;AAAAA,EAAAA,OAAA;AAAAD,SAAAT,EAAA,CAAA;AAAAU,SAAAV,EAAA,CAAA;AAAA,EAAA;AAV7BQ,YAAUC,IAUPC,EAA0B;AAEtBR,SAAAA;AAAwB;AAGjC,MAAMS,sBAAsBC,sBAAsBtD,gBAAgB;AAE3D,MAAMuD,iBAAiBA,MAAA;AAAA,SAC5BF,oBAAAG,KAAmD;AAAC;AAC/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCJ,oBAAAK,MAA0C;AAAC;AAHf,SAAAF,MAAAhD,OAAA;AAAA,SACCA,MAAKJ;AAAA;AACC,SAAAsD,OAAAlD,OAAA;AAAA,SACNA,MAAKH;AAAA;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphiQLPlugin } from '@graphiql/react';
|
|
2
2
|
export * from './components';
|
|
3
|
-
export {
|
|
3
|
+
export { DocExplorerContextProvider, useDocExplorer, useDocExplorerActions, } from './context';
|
|
4
4
|
export type { DocExplorerContextType, DocExplorerFieldDef, DocExplorerNavStack, DocExplorerNavStackItem, } from './context';
|
|
5
5
|
export declare const DOC_EXPLORER_PLUGIN: GraphiQLPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { usePluginStore, DocsFilledIcon, DocsIcon } from "@graphiql/react";
|
|
3
|
-
import {
|
|
3
|
+
import { DocExplorerContextProvider, useDocExplorer, useDocExplorerActions } from "./context.js";
|
|
4
4
|
import { DocExplorer } from "./components/doc-explorer.js";
|
|
5
5
|
import { Argument } from "./components/argument.js";
|
|
6
6
|
import { DefaultValue } from "./components/default-value.js";
|
|
@@ -30,7 +30,6 @@ export {
|
|
|
30
30
|
DeprecationReason,
|
|
31
31
|
Directive,
|
|
32
32
|
DocExplorer,
|
|
33
|
-
DocExplorerContext,
|
|
34
33
|
DocExplorerContextProvider,
|
|
35
34
|
ExplorerSection,
|
|
36
35
|
FieldDocumentation,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import {\n DocsFilledIcon,\n DocsIcon,\n GraphiQLPlugin,\n usePluginStore,\n} from '@graphiql/react';\nimport { DocExplorer } from './components';\n\nexport * from './components';\n\nexport {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import {\n DocsFilledIcon,\n DocsIcon,\n GraphiQLPlugin,\n usePluginStore,\n} from '@graphiql/react';\nimport { DocExplorer } from './components';\n\nexport * from './components';\n\nexport {\n DocExplorerContextProvider,\n useDocExplorer,\n useDocExplorerActions,\n} from './context';\n\nexport type {\n DocExplorerContextType,\n DocExplorerFieldDef,\n DocExplorerNavStack,\n DocExplorerNavStackItem,\n} from './context';\n\nexport const DOC_EXPLORER_PLUGIN: GraphiQLPlugin = {\n title: 'Documentation Explorer',\n icon: function Icon() {\n const { visiblePlugin } = usePluginStore();\n return visiblePlugin === DOC_EXPLORER_PLUGIN ? (\n <DocsFilledIcon />\n ) : (\n <DocsIcon />\n );\n },\n content: DocExplorer,\n};\n"],"names":["DOC_EXPLORER_PLUGIN","title","icon","Icon","visiblePlugin","usePluginStore","content","DocExplorer"],"mappings":";;;;;;;;;;;;;;;AAuBO,MAAMA,sBAAsC;AAAA,EACjDC,OAAO;AAAA,EACPC,MAAM,SAASC,OAAO;AACd,UAAA;AAAA,MAAEC;AAAAA,QAAkBC,eAAe;AACzC,WAAOD,kBAAkBJ,sBACvB,oBAAC,gBAAiB,CAAA,CAAA,wBAEjB,UACF,EAAA;AAAA,EACH;AAAA,EACAM,SAASC;AACX;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-doc-explorer",
|
|
3
|
-
"version": "0.1.1-canary-
|
|
3
|
+
"version": "0.1.1-canary-db8bf69b.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
45
|
-
"@graphiql/react": "^0.33.0-canary-
|
|
45
|
+
"@graphiql/react": "^0.33.0-canary-db8bf69b.0",
|
|
46
46
|
"@headlessui/react": "^2.2",
|
|
47
47
|
"zustand": "^5"
|
|
48
48
|
},
|