Skip to content

Commit d40249f

Browse files
authored
Remove the need to load WordPress (#9)
1 parent 24ab8b7 commit d40249f

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/share.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { useState } from 'react';
55

66
export function SharePopover() {
77
const [copied, setCopied] = useState(false);
8-
const { url, props: { url: shareUrl } } = usePage();
8+
const {
9+
url,
10+
props: { url: shareUrl },
11+
} = usePage();
912
const [show, setShow] = useState(true);
1013

1114
const created = url.includes('created=1');
@@ -18,13 +21,7 @@ export function SharePopover() {
1821
<div aria-live="assertive" className="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6">
1922
<div className="flex w-full flex-col items-center space-y-4 sm:items-end">
2023
<Transition show={show}>
21-
<div className="
22-
pointer-events-auto
23-
w-full max-w-sm overflow-hidden
24-
bg-white dark:bg-gray-400 dark:ring-gray-900/20
25-
rounded-lg
26-
shadow-lg ring-1 ring-black/5 transition
27-
data-[closed]:opacity-0 data-[enter]:transform data-[enter]:duration-300 data-[enter]:ease-out data-[closed]:data-[enter]:translate-y-2 data-[leave]:duration-100 data-[leave]:ease-in data-[closed]:data-[enter]:sm:translate-x-2 data-[closed]:data-[enter]:sm:translate-y-0 ">
24+
<div className="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black/5 transition data-[closed]:opacity-0 data-[enter]:transform data-[enter]:duration-300 data-[enter]:ease-out data-[closed]:data-[enter]:translate-y-2 data-[leave]:duration-100 data-[leave]:ease-in data-[closed]:data-[enter]:sm:translate-x-2 data-[closed]:data-[enter]:sm:translate-y-0 dark:bg-gray-400 dark:ring-gray-900/20">
2825
<div className="p-4">
2926
<div className="flex items-start">
3027
<div className="ml-3 w-0 flex-1 pt-0.5">

resources/js/context/context.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export const DEFAULT_CODE = `<?php
2727
-- Alley (https://alley.com/)
2828
*/
2929
30-
// Load WordPress to get access to its functions.
31-
require_once 'wordpress/wp-load.php';
32-
3330
// Output a simple message to the browser.
3431
echo "Hello, World!";
3532
`;

resources/js/hooks/use-run-code.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function useRunCode() {
88
} = usePlaygroundState();
99

1010
return async (code: string) => {
11-
console.log('run code', code);
1211
if (!playgroundClient) {
1312
dispatch(actionSetError('Playground client is not initialized.'));
1413
dispatch(actionSetOutput(''));
@@ -22,6 +21,9 @@ export function useRunCode() {
2221
return;
2322
}
2423

24+
// Inject the WordPress loader into the code.
25+
code = code.replace(/<\?php/, "<?php require_once 'wordpress/wp-load.php';");
26+
2527
try {
2628
const startTime = performance.now();
2729
const response = await playgroundClient.run({ code });

0 commit comments

Comments
 (0)