-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Joe Fusco <[email protected]>
- Loading branch information
1 parent
9139dce
commit 35ffe7a
Showing
5 changed files
with
43 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
/* global WPGRAPHQL_IDE_DATA */ | ||
import { GraphiQL } from 'graphiql'; | ||
import 'graphiql/graphiql.min.css'; | ||
|
||
const fetcher = async (graphQLParams) => { | ||
const { graphqlEndpoint } = WPGRAPHQL_IDE_DATA; | ||
const fetcher = async ( graphQLParams ) => { | ||
const { graphqlEndpoint } = WPGRAPHQL_IDE_DATA; | ||
|
||
const response = await fetch(graphqlEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'same-origin' // or 'include' if your endpoint is on a different domain | ||
}); | ||
const response = await fetch( graphqlEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify( graphQLParams ), | ||
credentials: 'same-origin', // or 'include' if your endpoint is on a different domain | ||
} ); | ||
|
||
return response.json(); | ||
return response.json(); | ||
}; | ||
|
||
export function Editor() { | ||
return ( | ||
<> | ||
<GraphiQL | ||
fetcher={fetcher} | ||
/> | ||
</> | ||
) | ||
} | ||
return ( | ||
<> | ||
<GraphiQL fetcher={ fetcher } /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { Drawer as VaulDrawer } from 'vaul'; | ||
|
||
export function EditorDrawer({ shouldScaleBackground = false, children }) { | ||
export function EditorDrawer( { shouldScaleBackground = false, children } ) { | ||
const buttonLabel = 'GraphQL IDE'; | ||
|
||
return ( | ||
return ( | ||
<div className="EditorDrawerRoot"> | ||
<VaulDrawer.Root shouldScaleBackground={shouldScaleBackground}> | ||
<VaulDrawer.Root shouldScaleBackground={ shouldScaleBackground }> | ||
<VaulDrawer.Trigger className="EditorDrawerButton"> | ||
<span className="ab-icon" aria-hidden="true"></span>{buttonLabel} | ||
<span className="ab-icon" aria-hidden="true"></span> | ||
{ buttonLabel } | ||
</VaulDrawer.Trigger> | ||
<VaulDrawer.Portal> | ||
<VaulDrawer.Content> | ||
{children} | ||
</VaulDrawer.Content> | ||
<VaulDrawer.Content>{ children }</VaulDrawer.Content> | ||
<VaulDrawer.Overlay /> | ||
</VaulDrawer.Portal> | ||
</VaulDrawer.Root> | ||
</div> | ||
); | ||
}; | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
/* global WPGRAPHQL_IDE_DATA */ | ||
import { createRoot } from '@wordpress/element'; | ||
import { App } from './App'; | ||
|
||
/** | ||
* Get the ID of the HTML element where the React app will be placed. | ||
* | ||
* @const {string} rootElementId - The ID of the HTML element. | ||
* @constant {string} rootElementId - The ID of the HTML element. | ||
* | ||
* Localized in wpgraphql-ide.php | ||
*/ | ||
const { rootElementId } = WPGRAPHQL_IDE_DATA; | ||
|
||
const rootElement = document.getElementById(rootElementId); | ||
const rootElement = document.getElementById( rootElementId ); | ||
|
||
if (rootElement) { | ||
const root = createRoot(rootElement); | ||
root.render(<App />); | ||
if ( rootElement ) { | ||
const root = createRoot( rootElement ); | ||
root.render( <App /> ); | ||
} | ||
|
||
// Expose app as a global variable to utilize in gutenberg. | ||
window.WPGraphQLIDE = App; | ||
window.WPGraphQLIDE = App; |