@graphiql/plugin-doc-explorer 0.0.2 → 0.0.3-canary-1be1da67.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 +114 -124
- 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.js +113 -137
- package/dist/components/search.js.map +1 -1
- 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 +204 -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.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { GraphQLArgument, GraphQLField, GraphQLInputField, GraphQLNamedType } from 'graphql';
|
|
2
|
-
import { FC, ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { GraphQLArgument, GraphQLField, GraphQLInputField, GraphQLNamedType, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { FC, ReactNode, RefObject } from 'react';
|
|
3
|
+
import { SchemaContextType } from '@graphiql/react';
|
|
4
|
+
import { StoreApi } from 'zustand';
|
|
5
|
+
export declare type DocExplorerFieldDef = GraphQLField<unknown, unknown> | GraphQLInputField | GraphQLArgument;
|
|
6
|
+
export declare type DocExplorerNavStackItem = {
|
|
5
7
|
/**
|
|
6
8
|
* The name of the item.
|
|
7
9
|
*/
|
|
@@ -10,23 +12,52 @@ export declare type ExplorerNavStackItem = {
|
|
|
10
12
|
* The definition object of the item, this can be a named type, a field, an
|
|
11
13
|
* input field or an argument.
|
|
12
14
|
*/
|
|
13
|
-
def?: GraphQLNamedType |
|
|
15
|
+
def?: GraphQLNamedType | DocExplorerFieldDef;
|
|
14
16
|
};
|
|
15
|
-
export declare type
|
|
16
|
-
|
|
17
|
-
...
|
|
17
|
+
export declare type DocExplorerNavStack = [
|
|
18
|
+
DocExplorerNavStackItem,
|
|
19
|
+
...DocExplorerNavStackItem[]
|
|
18
20
|
];
|
|
19
|
-
export declare type
|
|
21
|
+
export declare type DocExplorerContextType = {
|
|
20
22
|
/**
|
|
21
23
|
* A stack of navigation items. The last item in the list is the current one.
|
|
22
24
|
* This list always contains at least one item.
|
|
23
25
|
*/
|
|
24
|
-
explorerNavStack:
|
|
26
|
+
explorerNavStack: DocExplorerNavStack;
|
|
27
|
+
actions: {
|
|
28
|
+
/**
|
|
29
|
+
* Push an item to the navigation stack.
|
|
30
|
+
* @param item The item that should be pushed to the stack.
|
|
31
|
+
*/
|
|
32
|
+
push(item: DocExplorerNavStackItem): void;
|
|
33
|
+
/**
|
|
34
|
+
* Pop the last item from the navigation stack.
|
|
35
|
+
*/
|
|
36
|
+
pop(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Reset the navigation stack to its initial state, this will remove all but
|
|
39
|
+
* the initial stack item.
|
|
40
|
+
*/
|
|
41
|
+
reset(): void;
|
|
42
|
+
resolveSchemaReferenceToNavItem(schemaReference: SchemaContextType['schemaReference']): void;
|
|
43
|
+
/**
|
|
44
|
+
* Replace the nav stack with an updated version using the new schema.
|
|
45
|
+
*/
|
|
46
|
+
rebuildNavStackWithSchema(schema: GraphQLSchema): void;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export declare function createDocExplorerStore(initialNavStackItem?: DocExplorerNavStackItem): StoreApi<DocExplorerContextType>;
|
|
50
|
+
export declare const DocExplorerContext: import('react').Context<RefObject<StoreApi<DocExplorerContextType>> | null>;
|
|
51
|
+
export declare const DocExplorerContextProvider: FC<{
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useDocExplorer: () => DocExplorerNavStack;
|
|
55
|
+
export declare const useDocExplorerActions: () => {
|
|
25
56
|
/**
|
|
26
57
|
* Push an item to the navigation stack.
|
|
27
58
|
* @param item The item that should be pushed to the stack.
|
|
28
59
|
*/
|
|
29
|
-
push(item:
|
|
60
|
+
push(item: DocExplorerNavStackItem): void;
|
|
30
61
|
/**
|
|
31
62
|
* Pop the last item from the navigation stack.
|
|
32
63
|
*/
|
|
@@ -36,19 +67,9 @@ export declare type ExplorerContextType = {
|
|
|
36
67
|
* the initial stack item.
|
|
37
68
|
*/
|
|
38
69
|
reset(): void;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export declare const useExplorerContext: {
|
|
45
|
-
(options: {
|
|
46
|
-
nonNull: true;
|
|
47
|
-
caller?: Function | undefined;
|
|
48
|
-
}): ExplorerContextType;
|
|
49
|
-
(options: {
|
|
50
|
-
nonNull?: boolean | undefined;
|
|
51
|
-
caller?: Function | undefined;
|
|
52
|
-
}): ExplorerContextType | null;
|
|
53
|
-
(): ExplorerContextType | null;
|
|
70
|
+
resolveSchemaReferenceToNavItem(schemaReference: SchemaContextType['schemaReference']): void;
|
|
71
|
+
/**
|
|
72
|
+
* Replace the nav stack with an updated version using the new schema.
|
|
73
|
+
*/
|
|
74
|
+
rebuildNavStackWithSchema(schema: GraphQLSchema): void;
|
|
54
75
|
};
|
package/dist/context.js
CHANGED
|
@@ -1,234 +1,255 @@
|
|
|
1
1
|
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
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { createContext, useRef, useEffect, useContext } from "react";
|
|
5
|
+
import { useSchemaContext } from "@graphiql/react";
|
|
6
|
+
import { createStore, useStore } from "zustand";
|
|
7
|
+
function createDocExplorerStore(initialNavStackItem = {
|
|
7
8
|
name: "Docs"
|
|
8
|
-
}
|
|
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
|
-
}
|
|
47
|
-
const push = t2;
|
|
48
|
-
let t3;
|
|
49
|
-
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
50
|
-
t3 = () => {
|
|
51
|
-
setNavStack(_temp);
|
|
52
|
-
};
|
|
53
|
-
$[3] = t3;
|
|
54
|
-
} else {
|
|
55
|
-
t3 = $[3];
|
|
56
|
-
}
|
|
57
|
-
const pop = t3;
|
|
58
|
-
let t4;
|
|
59
|
-
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
60
|
-
t4 = () => {
|
|
61
|
-
setNavStack(_temp2);
|
|
62
|
-
};
|
|
63
|
-
$[4] = t4;
|
|
64
|
-
} else {
|
|
65
|
-
t4 = $[4];
|
|
66
|
-
}
|
|
67
|
-
const reset = t4;
|
|
68
|
-
let t5;
|
|
69
|
-
let t6;
|
|
70
|
-
if ($[5] !== schemaReference) {
|
|
71
|
-
t5 = () => {
|
|
72
|
-
if (!schemaReference) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
bb26: switch (schemaReference.kind) {
|
|
76
|
-
case "Type": {
|
|
77
|
-
push({
|
|
78
|
-
name: schemaReference.type.name,
|
|
79
|
-
def: schemaReference.type
|
|
80
|
-
});
|
|
81
|
-
break bb26;
|
|
82
|
-
}
|
|
83
|
-
case "Field": {
|
|
84
|
-
push({
|
|
85
|
-
name: schemaReference.field.name,
|
|
86
|
-
def: schemaReference.field
|
|
87
|
-
});
|
|
88
|
-
break bb26;
|
|
9
|
+
}) {
|
|
10
|
+
return createStore((set, get) => ({
|
|
11
|
+
explorerNavStack: [initialNavStackItem],
|
|
12
|
+
actions: {
|
|
13
|
+
push(item) {
|
|
14
|
+
set((state) => {
|
|
15
|
+
const curr = state.explorerNavStack;
|
|
16
|
+
const lastItem = curr.at(-1);
|
|
17
|
+
const explorerNavStack = (
|
|
18
|
+
// Avoid pushing duplicate items
|
|
19
|
+
lastItem.def === item.def ? curr : [...curr, item]
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
explorerNavStack
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
pop() {
|
|
27
|
+
set((state) => {
|
|
28
|
+
const curr = state.explorerNavStack;
|
|
29
|
+
const explorerNavStack = curr.length > 1 ? curr.slice(0, -1) : curr;
|
|
30
|
+
return {
|
|
31
|
+
explorerNavStack
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
reset() {
|
|
36
|
+
set((state) => {
|
|
37
|
+
const curr = state.explorerNavStack;
|
|
38
|
+
const explorerNavStack = curr.length === 1 ? curr : [initialNavStackItem];
|
|
39
|
+
return {
|
|
40
|
+
explorerNavStack
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
resolveSchemaReferenceToNavItem(schemaReference) {
|
|
45
|
+
if (!schemaReference) {
|
|
46
|
+
return;
|
|
89
47
|
}
|
|
90
|
-
|
|
91
|
-
|
|
48
|
+
const {
|
|
49
|
+
push
|
|
50
|
+
} = get().actions;
|
|
51
|
+
switch (schemaReference.kind) {
|
|
52
|
+
case "Type": {
|
|
92
53
|
push({
|
|
93
|
-
name: schemaReference.
|
|
94
|
-
def: schemaReference.
|
|
54
|
+
name: schemaReference.type.name,
|
|
55
|
+
def: schemaReference.type
|
|
95
56
|
});
|
|
57
|
+
break;
|
|
96
58
|
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
case "EnumValue": {
|
|
100
|
-
if (schemaReference.type) {
|
|
59
|
+
case "Field": {
|
|
101
60
|
push({
|
|
102
|
-
name: schemaReference.
|
|
103
|
-
def: schemaReference.
|
|
61
|
+
name: schemaReference.field.name,
|
|
62
|
+
def: schemaReference.field
|
|
104
63
|
});
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "Argument": {
|
|
67
|
+
if (schemaReference.field) {
|
|
68
|
+
push({
|
|
69
|
+
name: schemaReference.field.name,
|
|
70
|
+
def: schemaReference.field
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "EnumValue": {
|
|
76
|
+
if (schemaReference.type) {
|
|
77
|
+
push({
|
|
78
|
+
name: schemaReference.type.name,
|
|
79
|
+
def: schemaReference.type
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
105
83
|
}
|
|
106
84
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
$[6] = t5;
|
|
112
|
-
$[7] = t6;
|
|
113
|
-
} else {
|
|
114
|
-
t5 = $[6];
|
|
115
|
-
t6 = $[7];
|
|
116
|
-
}
|
|
117
|
-
useEffect(t5, t6);
|
|
118
|
-
let t7;
|
|
119
|
-
let t8;
|
|
120
|
-
if ($[8] !== schema || $[9] !== validationErrors) {
|
|
121
|
-
t7 = () => {
|
|
122
|
-
if (schema == null || validationErrors.length > 0) {
|
|
123
|
-
reset();
|
|
124
|
-
} else {
|
|
125
|
-
setNavStack((oldNavStack) => {
|
|
85
|
+
},
|
|
86
|
+
rebuildNavStackWithSchema(schema) {
|
|
87
|
+
set((state) => {
|
|
88
|
+
const oldNavStack = state.explorerNavStack;
|
|
126
89
|
if (oldNavStack.length === 1) {
|
|
127
90
|
return oldNavStack;
|
|
128
91
|
}
|
|
129
92
|
const newNavStack = [initialNavStackItem];
|
|
130
93
|
let lastEntity = null;
|
|
131
|
-
for (const
|
|
132
|
-
if (
|
|
94
|
+
for (const item of oldNavStack) {
|
|
95
|
+
if (item === initialNavStackItem) {
|
|
133
96
|
continue;
|
|
134
97
|
}
|
|
135
|
-
if (
|
|
136
|
-
if (isNamedType(
|
|
137
|
-
const newType = schema.getType(
|
|
98
|
+
if (item.def) {
|
|
99
|
+
if (isNamedType(item.def)) {
|
|
100
|
+
const newType = schema.getType(item.def.name);
|
|
138
101
|
if (newType) {
|
|
139
102
|
newNavStack.push({
|
|
140
|
-
name:
|
|
103
|
+
name: item.name,
|
|
141
104
|
def: newType
|
|
142
105
|
});
|
|
143
106
|
lastEntity = newType;
|
|
144
107
|
} else {
|
|
145
108
|
break;
|
|
146
109
|
}
|
|
147
|
-
} else {
|
|
148
|
-
|
|
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 {
|
|
149
120
|
break;
|
|
121
|
+
}
|
|
122
|
+
} else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
123
|
+
break;
|
|
124
|
+
} else {
|
|
125
|
+
const field = lastEntity;
|
|
126
|
+
if (field.args.some((a) => a.name === item.name)) {
|
|
127
|
+
newNavStack.push({
|
|
128
|
+
name: item.name,
|
|
129
|
+
def: field
|
|
130
|
+
});
|
|
150
131
|
} else {
|
|
151
|
-
|
|
152
|
-
const field = lastEntity.getFields()[item_0.name];
|
|
153
|
-
if (field) {
|
|
154
|
-
newNavStack.push({
|
|
155
|
-
name: item_0.name,
|
|
156
|
-
def: field
|
|
157
|
-
});
|
|
158
|
-
} else {
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
163
|
-
break;
|
|
164
|
-
} else {
|
|
165
|
-
const field_0 = lastEntity;
|
|
166
|
-
if (field_0.args.some((a) => a.name === item_0.name)) {
|
|
167
|
-
newNavStack.push({
|
|
168
|
-
name: item_0.name,
|
|
169
|
-
def: field_0
|
|
170
|
-
});
|
|
171
|
-
} else {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
132
|
+
break;
|
|
176
133
|
}
|
|
177
134
|
}
|
|
178
135
|
} else {
|
|
179
136
|
lastEntity = null;
|
|
180
|
-
newNavStack.push(
|
|
137
|
+
newNavStack.push(item);
|
|
181
138
|
}
|
|
182
139
|
}
|
|
183
|
-
return
|
|
140
|
+
return {
|
|
141
|
+
explorerNavStack: newNavStack
|
|
142
|
+
};
|
|
184
143
|
});
|
|
185
144
|
}
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
const DocExplorerContext = createContext(null);
|
|
149
|
+
const DocExplorerContextProvider = (props) => {
|
|
150
|
+
const $ = c(11);
|
|
151
|
+
let t0;
|
|
152
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
153
|
+
t0 = {
|
|
154
|
+
nonNull: true,
|
|
155
|
+
caller: DocExplorerContextProvider
|
|
156
|
+
};
|
|
157
|
+
$[0] = t0;
|
|
158
|
+
} else {
|
|
159
|
+
t0 = $[0];
|
|
160
|
+
}
|
|
161
|
+
const {
|
|
162
|
+
schema,
|
|
163
|
+
validationErrors,
|
|
164
|
+
schemaReference
|
|
165
|
+
} = useSchemaContext(t0);
|
|
166
|
+
const storeRef = useRef(null);
|
|
167
|
+
if (storeRef.current === null) {
|
|
168
|
+
let t12;
|
|
169
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
170
|
+
t12 = createDocExplorerStore();
|
|
171
|
+
$[1] = t12;
|
|
172
|
+
} else {
|
|
173
|
+
t12 = $[1];
|
|
174
|
+
}
|
|
175
|
+
storeRef.current = t12;
|
|
176
|
+
}
|
|
177
|
+
let t1;
|
|
178
|
+
let t2;
|
|
179
|
+
if ($[2] !== schemaReference) {
|
|
180
|
+
t1 = () => {
|
|
181
|
+
const {
|
|
182
|
+
resolveSchemaReferenceToNavItem
|
|
183
|
+
} = storeRef.current.getState().actions;
|
|
184
|
+
resolveSchemaReferenceToNavItem(schemaReference);
|
|
186
185
|
};
|
|
187
|
-
|
|
188
|
-
$[
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
191
|
-
$[11] = t8;
|
|
186
|
+
t2 = [schemaReference];
|
|
187
|
+
$[2] = schemaReference;
|
|
188
|
+
$[3] = t1;
|
|
189
|
+
$[4] = t2;
|
|
192
190
|
} else {
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
t1 = $[3];
|
|
192
|
+
t2 = $[4];
|
|
195
193
|
}
|
|
196
|
-
useEffect(
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
194
|
+
useEffect(t1, t2);
|
|
195
|
+
let t3;
|
|
196
|
+
let t4;
|
|
197
|
+
if ($[5] !== schema || $[6] !== validationErrors) {
|
|
198
|
+
t3 = () => {
|
|
199
|
+
const {
|
|
200
|
+
reset,
|
|
201
|
+
rebuildNavStackWithSchema
|
|
202
|
+
} = storeRef.current.getState().actions;
|
|
203
|
+
if (schema == null || validationErrors.length > 0) {
|
|
204
|
+
reset();
|
|
205
|
+
} else {
|
|
206
|
+
rebuildNavStackWithSchema(schema);
|
|
207
|
+
}
|
|
204
208
|
};
|
|
205
|
-
|
|
206
|
-
$[
|
|
209
|
+
t4 = [schema, validationErrors];
|
|
210
|
+
$[5] = schema;
|
|
211
|
+
$[6] = validationErrors;
|
|
212
|
+
$[7] = t3;
|
|
213
|
+
$[8] = t4;
|
|
207
214
|
} else {
|
|
208
|
-
|
|
215
|
+
t3 = $[7];
|
|
216
|
+
t4 = $[8];
|
|
209
217
|
}
|
|
210
|
-
|
|
211
|
-
let
|
|
212
|
-
if ($[
|
|
213
|
-
|
|
214
|
-
$[
|
|
215
|
-
$[
|
|
216
|
-
$[16] = t10;
|
|
218
|
+
useEffect(t3, t4);
|
|
219
|
+
let t5;
|
|
220
|
+
if ($[9] !== props.children) {
|
|
221
|
+
t5 = /* @__PURE__ */ jsx(DocExplorerContext.Provider, { value: storeRef, children: props.children });
|
|
222
|
+
$[9] = props.children;
|
|
223
|
+
$[10] = t5;
|
|
217
224
|
} else {
|
|
218
|
-
|
|
225
|
+
t5 = $[10];
|
|
226
|
+
}
|
|
227
|
+
return t5;
|
|
228
|
+
};
|
|
229
|
+
function useDocExplorerStore(selector) {
|
|
230
|
+
const store = useContext(DocExplorerContext);
|
|
231
|
+
if (!store) {
|
|
232
|
+
throw new Error("Missing `DocExplorerContextProvider` in the tree");
|
|
219
233
|
}
|
|
220
|
-
return
|
|
234
|
+
return useStore(store.current, selector);
|
|
235
|
+
}
|
|
236
|
+
const useDocExplorer = () => {
|
|
237
|
+
return useDocExplorerStore(_temp);
|
|
238
|
+
};
|
|
239
|
+
const useDocExplorerActions = () => {
|
|
240
|
+
return useDocExplorerStore(_temp2);
|
|
221
241
|
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return currentState_0.length > 1 ? currentState_0.slice(0, -1) : currentState_0;
|
|
242
|
+
function _temp(state) {
|
|
243
|
+
return state.explorerNavStack;
|
|
225
244
|
}
|
|
226
|
-
function _temp2(
|
|
227
|
-
return
|
|
245
|
+
function _temp2(state) {
|
|
246
|
+
return state.actions;
|
|
228
247
|
}
|
|
229
248
|
export {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
249
|
+
DocExplorerContext,
|
|
250
|
+
DocExplorerContextProvider,
|
|
251
|
+
createDocExplorerStore,
|
|
252
|
+
useDocExplorer,
|
|
253
|
+
useDocExplorerActions
|
|
233
254
|
};
|
|
234
255
|
//# sourceMappingURL=context.js.map
|
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,QAAA,CAAAY,UAAAC,WAAA,IAAgCC,SAA2BH,EAE1D;AAAEI,MAAAA;AAAA,MAAAf,EAAA,CAAA,MAAAG,OAAAC,IAAA,2BAAA,GAAA;AAGDW,SAAAC,CAAA,SAAA;AACEH,kBAAWI,CAAA,iBAAA;AACTC,cAAAA,WAAiBD,aAAYE,KAAM;AAC5BD,eAAAA,SAAQE,QAASJ,KAAII,MAExBH,eAAY,CAAA,GACRA,cAAcD,IAAI;AAAA,MAAA,CAC3B;AAAA,IAAC;AACHhB,WAAAe;AAAAA,EAAAA,OAAA;AAAAA,SAAAf,EAAA,CAAA;AAAA,EAAA;AATH,QAAAqB,OACEN;AAQE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D,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, useSchemaContext } 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 } = useSchemaContext({\n nonNull: true,\n caller: DocExplorerContextProvider,\n });\n\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","t0","Symbol","for","nonNull","caller","validationErrors","useSchemaContext","storeRef","useRef","current","t1","t2","getState","useEffect","t3","t4","t5","children","useDocExplorerStore","selector","store","useContext","Error","useStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;;AAkFO,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UAAA,EAAoCT,OAAO,UACxCV,gBAAKoB,UACR;AAA8B,MAAA,CAAA,IAAApB,MAAAoB;AAAAnB,YAAAkB;AAAAA,EAAAA,OAAA;AAAAA,SAAAlB,EAAA,EAAA;AAAA,EAAA;AAF9BkB,SAAAA;AAE8B;AAIlC,SAAAE,oBAAAC,UAAA;AAGEC,QAAAA,QAAcC,WAAA3B,kBAA6B;AAAE,MAAA,CACxC0B,OAAK;AAAAE,UAAAA,IAAAA,MACQ,kDAAkD;AAAA,EAAA;AAE7DC,SAAAA,SAASH,MAAKX,SAAUU,QAAQ;AAAC;AAGnC,MAAMK,iBAAiBA,MAAA;AAAA,SAC5BN,oBAAAO,KAAmD;AAAC;AAC/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCR,oBAAAS,MAA0C;AAAC;AAHf,SAAAF,MAAA/D,OAAA;AAAA,SACCA,MAAKJ;AAAA;AACC,SAAAqE,OAAAjE,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;"}
|