@graphiql/plugin-doc-explorer 0.0.2 → 0.0.3-canary-5d447953.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/default-value.d.ts +2 -2
- package/dist/components/default-value.js.map +1 -1
- package/dist/components/doc-explorer.js +118 -138
- package/dist/components/doc-explorer.js.map +1 -1
- package/dist/components/field-documentation.d.ts +2 -2
- package/dist/components/field-documentation.js.map +1 -1
- package/dist/components/field-link.d.ts +2 -2
- package/dist/components/field-link.js +17 -26
- package/dist/components/field-link.js.map +1 -1
- package/dist/components/search.d.ts +1 -1
- package/dist/components/search.js +115 -152
- package/dist/components/search.js.map +1 -1
- package/dist/components/type-documentation.js +17 -26
- package/dist/components/type-documentation.js.map +1 -1
- package/dist/components/type-link.js +17 -27
- package/dist/components/type-link.js.map +1 -1
- package/dist/context.d.ts +47 -26
- package/dist/context.js +194 -183
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
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} from 'graphql';\nimport {\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n isScalarType,\n isUnionType,\n} from 'graphql';\nimport { FC, ReactNode, useEffect, useState } from 'react';\nimport {\n useSchemaContext,\n createContextHook,\n createNullableContext,\n} from '@graphiql/react';\n\nexport type ExplorerFieldDef =\n | GraphQLField<unknown, unknown>\n | GraphQLInputField\n | GraphQLArgument;\n\nexport type ExplorerNavStackItem = {\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 | ExplorerFieldDef;\n};\n\n// There's always at least one item in the nav stack\nexport type ExplorerNavStack = [\n ExplorerNavStackItem,\n ...ExplorerNavStackItem[],\n];\n\nconst initialNavStackItem: ExplorerNavStackItem = { name: 'Docs' };\n\nexport type ExplorerContextType = {\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: ExplorerNavStack;\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: ExplorerNavStackItem): 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};\n\nexport const ExplorerContext =\n createNullableContext<ExplorerContextType>('ExplorerContext');\n\nexport const ExplorerContextProvider: FC<{\n children: ReactNode;\n}> = props => {\n const { schema, validationErrors, schemaReference } = useSchemaContext({\n nonNull: true,\n caller: ExplorerContextProvider,\n });\n\n const [navStack, setNavStack] = useState<ExplorerNavStack>([\n initialNavStackItem,\n ]);\n\n const push = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, variable is optimized by react-compiler, no need to wrap with useCallback\n (item: ExplorerNavStackItem) => {\n setNavStack(currentState => {\n const lastItem = currentState.at(-1)!;\n return lastItem.def === item.def\n ? // Avoid pushing duplicate items\n currentState\n : [...currentState, item];\n });\n };\n\n const pop = () => {\n setNavStack(currentState =>\n currentState.length > 1\n ? (currentState.slice(0, -1) as ExplorerNavStack)\n : currentState,\n );\n };\n\n const reset = () => {\n setNavStack(currentState =>\n currentState.length === 1 ? currentState : [initialNavStackItem],\n );\n };\n\n useEffect(() => {\n if (!schemaReference) {\n return;\n }\n switch (schemaReference.kind) {\n case 'Type': {\n push({ name: schemaReference.type.name, def: schemaReference.type });\n break;\n }\n case 'Field': {\n push({ name: schemaReference.field.name, def: schemaReference.field });\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({ name: schemaReference.type.name, def: schemaReference.type });\n }\n break;\n }\n }\n }, [schemaReference, push]);\n\n useEffect(() => {\n // Whenever the schema changes, we must revalidate/replace the nav stack.\n if (schema == null || validationErrors.length > 0) {\n reset();\n } else {\n // Replace the nav stack with an updated version using the new schema\n setNavStack(oldNavStack => {\n if (oldNavStack.length === 1) {\n return oldNavStack;\n }\n const newNavStack: ExplorerNavStack = [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 newNavStack;\n });\n }\n }, [schema, validationErrors]);\n\n const value: ExplorerContextType = {\n explorerNavStack: navStack,\n push,\n pop,\n reset,\n };\n\n return (\n <ExplorerContext.Provider value={value}>\n {props.children}\n </ExplorerContext.Provider>\n );\n};\n\nexport const useExplorerContext = createContextHook(ExplorerContext);\n"],"names":["initialNavStackItem","name","ExplorerContext","createNullableContext","ExplorerContextProvider","props","$","_c","t0","Symbol","for","nonNull","caller","schema","validationErrors","schemaReference","useSchemaContext","t1","navStack","setNavStack","useState","t2","item","currentState","lastItem","at","def","push","t3","_temp","pop","t4","_temp2","reset","t5","t6","kind","type","bb26","field","useEffect","t7","t8","length","oldNavStack","newNavStack","lastEntity","item_0","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","field_0","args","some","a","t9","explorerNavStack","value","t10","children","useExplorerContext","createContextHook","currentState_0","slice","currentState_1"],"mappings":";;;;;AA6CA,MAAMA,sBAA4C;AAAA,EAAEC,MAAM;AAAO;AAwBpDC,MAAAA,kBACXC,sBAA2C,iBAAiB;AAEvD,MAAMC,0BAERC,CAAA,UAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA;AAAAC,MAAAA;AAAA,MAAAF,EAAA,CAAA,MAAAG,OAAAC,IAAA,2BAAA,GAAA;AACoE,SAAA;AAAA,MAAAC,SAAA;AAAA,MAAAC,QAAAR;AAAAA,IAAA;AAGtEE,WAAAE;AAAAA,EAAAA,OAAA;AAAAA,SAAAF,EAAA,CAAA;AAAA,EAAA;AAHD,QAAA;AAAA,IAAAO;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAAsDC,iBAAiBR,EAGtE;AAAES,MAAAA;AAAA,MAAAX,EAAA,CAAA,MAAAG,OAAAC,IAAA,2BAAA,GAAA;AAEwDO,UAAAjB,mBAAA;AAE1DM,WAAAW;AAAAA,EAAAA,OAAA;AAAAA,SAAAX,EAAA,CAAA;AAAA,EAAA;AAFD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C;AAAAA,EAAAA,OAAA;AAAAD,SAAAnC,EAAA,EAAA;AAAAoC,SAAApC,EAAA,EAAA;AAAA,EAAA;AApF7BkC,YAAUC,IAoFPC,EAA0B;AAACoB,MAAAA;AAAAxD,MAAAA,UAAAY,UAAA;AAEK,SAAA;AAAA,MAAA6C,kBACf7C;AAAAA,MAAQS;AAAAA,MAAAG;AAAAA,MAAAG;AAAAA,IAAA;AAI3B3B,YAAAY;AAAAZ,YAAAwD;AAAAA,EAAAA,OAAA;AAAAA,SAAAxD,EAAA,EAAA;AAAA,EAAA;AALD,QAAA0D,QAAmCF;AAKjCG,MAAAA;AAAA3D,MAAAA,UAAAD,MAAA6D,YAAA5D,UAAA0D,OAAA;AAGAC,8BAAA,gBAAA,UAAA,EAAiCD,OAC9B3D,gBAAK6D,UACR;AAA2B,MAAA,EAAA,IAAA7D,MAAA6D;AAAA5D,YAAA0D;AAAA1D,YAAA2D;AAAAA,EAAAA,OAAA;AAAAA,UAAA3D,EAAA,EAAA;AAAA,EAAA;AAF3B2D,SAAAA;AAE2B;AAIlBE,MAAAA,qBAAqBC,kBAAkBlE,eAAe;AAtK9D,SAAA2B,MAAAwC,gBAAA;AAAA,SAuBC9C,eAAYoB,SAAA,IACPpB,eAAY+C,MAAY,GAAA,EAAA,IACzB/C;AAAY;AAzBjB,SAAAS,OAAAuC,gBAAA;AAAA,SA+BChD,eAAYoB,WAAA,IAAgBpB,iBAAY,CAAAvB,mBAAA;AAAwB;"}
|
|
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;A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EAAA;AAV7BY,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;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphiQLPlugin } from '@graphiql/react';
|
|
2
2
|
export * from './components';
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
3
|
+
export { DocExplorerContext, DocExplorerContextProvider, useDocExplorer, useDocExplorerActions, } from './context';
|
|
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 { usePluginContext, DocsFilledIcon, DocsIcon } from "@graphiql/react";
|
|
3
|
-
import {
|
|
3
|
+
import { DocExplorerContext, 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";
|
|
@@ -28,8 +28,8 @@ export {
|
|
|
28
28
|
DeprecationReason,
|
|
29
29
|
Directive,
|
|
30
30
|
DocExplorer,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
DocExplorerContext,
|
|
32
|
+
DocExplorerContextProvider,
|
|
33
33
|
ExplorerSection,
|
|
34
34
|
FieldDocumentation,
|
|
35
35
|
FieldLink,
|
|
@@ -37,6 +37,7 @@ export {
|
|
|
37
37
|
Search,
|
|
38
38
|
TypeDocumentation,
|
|
39
39
|
TypeLink,
|
|
40
|
-
|
|
40
|
+
useDocExplorer,
|
|
41
|
+
useDocExplorerActions
|
|
41
42
|
};
|
|
42
43
|
//# sourceMappingURL=index.js.map
|
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 usePluginContext,\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 usePluginContext,\n} from '@graphiql/react';\nimport { DocExplorer } from './components';\n\nexport * from './components';\n\nexport {\n DocExplorerContext,\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 pluginContext = usePluginContext();\n return pluginContext?.visiblePlugin === DOC_EXPLORER_PLUGIN ? (\n <DocsFilledIcon />\n ) : (\n <DocsIcon />\n );\n },\n content: DocExplorer,\n};\n"],"names":["DOC_EXPLORER_PLUGIN","title","icon","Icon","pluginContext","usePluginContext","visiblePlugin","content","DocExplorer"],"mappings":";;;;;;;;;;;;;;;AAwBO,MAAMA,sBAAsC;AAAA,EACjDC,OAAO;AAAA,EACPC,MAAM,SAASC,OAAO;AACpB,UAAMC,gBAAgBC,iBAAiB;AACvC,YAAOD,+CAAeE,mBAAkBN,0CACrC,gBAAiB,CAAA,CAAA,wBAEjB,UACF,EAAA;AAAA,EACH;AAAA,EACAO,SAASC;AACX;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-doc-explorer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-canary-5d447953.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
45
|
-
"@graphiql/react": "^0.
|
|
46
|
-
"@headlessui/react": "^2.2"
|
|
45
|
+
"@graphiql/react": "^0.33.0-canary-5d447953.0",
|
|
46
|
+
"@headlessui/react": "^2.2",
|
|
47
|
+
"zustand": "^5"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@vitejs/plugin-react": "^4.4.1",
|