-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add opt/alt+click to open a source file at the element
- Loading branch information
Showing
10 changed files
with
90 additions
and
265 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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import { getEnv } from "../lib/env.ts"; | ||
import type { RequestProps } from "../lib/types.ts"; | ||
|
||
export interface DevScriptProps { | ||
req: Request; | ||
src: string; | ||
envVar?: string; | ||
params?: Record<string, string | undefined>; | ||
} | ||
|
||
export function DevScript( | ||
{ req, src, envVar }: RequestProps & { src: string; envVar: string }, | ||
{ req, src, envVar, params }: DevScriptProps, | ||
) { | ||
const enable = getEnv(envVar, req) === "true"; | ||
const enable = envVar && getEnv(envVar, req) === "true"; | ||
|
||
if (params) { | ||
const url = new URL(src, "dummy:/"); | ||
Object.entries(params).forEach(([key, val]) => { | ||
if (val !== undefined) { | ||
url.searchParams.set(key, val); | ||
} | ||
}); | ||
src = url.protocol === "dummy:" | ||
? `${url.pathname}${url.search}${url.hash}` | ||
: url.href; | ||
} | ||
|
||
return enable ? <script src={src} type="module" /> : null; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
app/routes/auto-refresh/_browser/dev.ts → app/routes/dev/auto-refresh/_browser/dev.ts
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
File renamed without changes.
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,27 @@ | ||
// deno-lint-ignore-file no-window no-window-prefix | ||
/** | ||
* Enable Option/Alt clicking on an element to open the source link in vscode | ||
*/ | ||
function enableSrcLinks() { | ||
const attr = new URL(import.meta.url).searchParams.get("attr") ?? "jsx-src"; | ||
|
||
console.log(`%cENABLE SRC LINKS: ${attr}`, "color: green"); | ||
|
||
window.addEventListener("click", (event) => { | ||
const el = event.target as (Element | null); | ||
if (event.altKey && el?.hasAttribute(attr)) { | ||
const src = el.getAttribute(attr); | ||
let url = URL.parse(src ?? ""); | ||
if (url?.protocol === "file:") { | ||
const hash = url.hash.replace(/^#/, ":"); | ||
url = new URL(`vscode://file${url.pathname}${hash}`); | ||
} | ||
if (url) { | ||
console.log("OPEN SRC LINK:", url.href); | ||
window.open(url, "_blank"); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
enableSrcLinks(); |
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
Oops, something went wrong.