-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ff286d
commit 97f31ba
Showing
5 changed files
with
105 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
export const partial = true; | ||
--- | ||
|
||
<div> | ||
<button onclick="fetchHome(this)">Env</button> | ||
<button>D1</button> | ||
</div> | ||
|
||
<script is:inline> | ||
var fetchHome = function (element) { | ||
console.log(element.getRootNode()); | ||
fetch('/_dev-toolbar-app/cloudflare/home') | ||
.then((res) => res.text()) | ||
.then((html) => { | ||
const el = document.createRange().createContextualFragment(html); | ||
element.getRootNode().querySelector('#target').replaceChildren(el); | ||
}); | ||
}; | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
export const partial = true; | ||
const { env } = Astro.locals.runtime; | ||
--- | ||
|
||
<pre onclick="me(this)"> | ||
{JSON.stringify(env, null, 2)} | ||
</pre> | ||
|
||
<script is:inline> | ||
var me = function (element) { | ||
console.log('me'); | ||
}; | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { DevToolbarApp } from 'astro'; | ||
|
||
const plugin: DevToolbarApp = { | ||
id: 'cloudflare-app', | ||
name: 'Cloudflare DevToolbarApp', | ||
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M10.715 14.32H5.442l-.64-1.203L13.673 0l1.397.579-1.752 9.112h5.24l.648 1.192L10.719 24l-1.412-.54ZM4.091 5.448a.579.579 0 1 1 0-1.157.579.579 0 0 1 0 1.157m1.543 0a.579.579 0 1 1 0-1.157.579.579 0 0 1 0 1.157m1.544 0a.579.579 0 1 1 0-1.157.579.579 0 0 1 0 1.157m8.657-2.7h5.424l.772.771v16.975l-.772.772h-7.392l.374-.579h6.779l.432-.432V3.758l-.432-.432h-4.676l-.552 2.85h-.59l.529-2.877.108-.552ZM2.74 21.265l-.772-.772V3.518l.772-.771h7.677l-.386.579H2.98l-.432.432v16.496l.432.432h5.586l-.092.579zm1.157-1.93h3.28l-.116.58h-3.55l-.192-.193v-3.473l.578 1.158zm13.117 0 .579.58H14.7l.385-.58z"/></svg>', | ||
init(canvas, eventTarget) { | ||
const page = ` | ||
<script> | ||
var loadTabs = function (element) { | ||
console.log(this); | ||
console.log(element); | ||
fetch('/_dev-toolbar-app/cloudflare/tabs') | ||
.then((res) => res.text()) | ||
.then((html) => { | ||
const el = document.createRange().createContextualFragment(html); | ||
element.getRootNode().querySelector('#tabs').replaceChildren(el); | ||
}); | ||
}; | ||
</script> | ||
<div id="tabs"></div> | ||
<div id="target"></div> | ||
`; | ||
|
||
const pageEl = document.createRange().createContextualFragment(page); | ||
const cfWindow = document.createElement('astro-dev-toolbar-window'); | ||
cfWindow.append(pageEl); | ||
|
||
canvas.appendChild(cfWindow); | ||
|
||
eventTarget.addEventListener('app-toggled', (event) => { | ||
// @ts-ignore | ||
if (event.detail.state === true) { | ||
console.log('The app is now enabled!'); | ||
// @ts-ignore | ||
loadTabs(cfWindow); | ||
} | ||
}); | ||
}, | ||
}; | ||
|
||
export default plugin; |
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