Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mount a directory from the browser (#1482)
## Motivation for the change, related issues We would like to enable developers to mount local directories into their Playground-based projects by prompting users to select a directory. After the directory is selected the folder can be mounted into Playground and used by it. For example, this could be used to load local plugins and themes into Playground. ## Implementation details This PR adds a window message listener that takes the provided directory handle and mounts it to the mountpoint. ```javascript window.showDirectoryPicker().then(function (directoryHandle) { window.parent.postMessage({ type: 'mount-directory-handle', directoryHandle, mountpoint: '/wordpress/wp-content/uploads/markdown/', }); }); ``` ## Testing Instructions (or ideally a Blueprint) - Add this code after line 280 in `packages/playground/remote/src/lib/worker-thread.ts` ``` primaryPhp.writeFile( '/wordpress/mount.php', `<!DOCTYPE html> <html> <head> <title>Directory picker</title> </head> <body> <button id="pick">Pick directory</button> <script> document.getElementById('pick').addEventListener('click', function() { if (!('showDirectoryPicker' in window)) { alert('Your browser does not support the Directory Picker API'); return; } window.showDirectoryPicker().then(function(directoryHandle) { window.parent.postMessage( { type: 'mount-directory-handle', directoryHandle, mountpoint: '/wordpress/wp-content/uploads/markdown/', } ); }); }); </script> </body> </html>` ); ``` - open this blueprint http://localhost:5400/website-server/?url=/mount.php - Click the button and select a local folder that contains an HTML file - Change the URL in the Playground header to `/wp-content/uploads/markdown/YOUR-HTML-FILE.html` - Confirm that your file was loaded
- Loading branch information