From fa172459d169918fa6dc044f29a2d61034be6df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 28 Nov 2025 16:41:27 +0100 Subject: [PATCH] [Website] Blueprint Editor: Update the URL when typing --- .../public/blueprint-schema-validator.js | 32 +++++++++---------- .../site-manager/site-info-panel/index.tsx | 19 +++++++++++ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/packages/playground/blueprints/public/blueprint-schema-validator.js b/packages/playground/blueprints/public/blueprint-schema-validator.js index 65f1ac0c79..a3c79ce5e6 100644 --- a/packages/playground/blueprints/public/blueprint-schema-validator.js +++ b/packages/playground/blueprints/public/blueprint-schema-validator.js @@ -10340,7 +10340,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } var valid21 = @@ -11019,7 +11019,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } var valid27 = @@ -11435,7 +11435,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -11467,7 +11467,7 @@ function validate14( ? validate18.errors : vErrors.concat( validate18.errors - ); + ); errors = vErrors.length; } @@ -11553,7 +11553,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -12101,7 +12101,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -12133,7 +12133,7 @@ function validate14( ? validate18.errors : vErrors.concat( validate18.errors - ); + ); errors = vErrors.length; } @@ -12219,7 +12219,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -13969,7 +13969,7 @@ function validate14( ? validate30.errors : vErrors.concat( validate30.errors - ); + ); errors = vErrors.length; } var valid54 = @@ -15456,7 +15456,7 @@ function validate14( ? validate32.errors : vErrors.concat( validate32.errors - ); + ); errors = vErrors.length; } var valid68 = @@ -16180,7 +16180,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } var valid76 = @@ -16810,7 +16810,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } var valid83 = @@ -17589,7 +17589,7 @@ function validate14( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -18636,7 +18636,7 @@ function validate14( ? validate18.errors : vErrors.concat( validate18.errors - ); + ); errors = vErrors.length; } @@ -20513,7 +20513,7 @@ function validate11( ? validate12.errors : vErrors.concat( validate12.errors - ); + ); errors = vErrors.length; } @@ -21127,7 +21127,7 @@ function validate11( ? validate14.errors : vErrors.concat( validate14.errors - ); + ); errors = vErrors.length; } diff --git a/packages/playground/website/src/components/site-manager/site-info-panel/index.tsx b/packages/playground/website/src/components/site-manager/site-info-panel/index.tsx index b8d177013d..458f69e597 100644 --- a/packages/playground/website/src/components/site-manager/site-info-panel/index.tsx +++ b/packages/playground/website/src/components/site-manager/site-info-panel/index.tsx @@ -41,6 +41,7 @@ import { } from '@wp-playground/blueprints'; import { lazy, Suspense, useState, useEffect, useCallback } from 'react'; import { logger } from '@php-wasm/logger'; +import { encodeStringAsBase64 } from '../../../lib/base64'; const SiteFileBrowser = lazy(() => import('../site-file-browser').then((m) => ({ default: m.SiteFileBrowser })) @@ -187,6 +188,24 @@ export function SiteInfoPanel({ return () => clearTimeout(timeoutId); }, [blueprintCode, autoRecreate, isTemporary, handleRecreateFromBlueprint]); + // Update URL hash when blueprint changes for shareable URLs + useEffect(() => { + if (!isTemporary || !blueprintCode) { + return; + } + + try { + // Validate that it's valid JSON before updating the URL + JSON.parse(blueprintCode); + const encodedBlueprint = encodeStringAsBase64(blueprintCode); + const newUrl = new URL(window.location.href); + newUrl.hash = encodedBlueprint; + window.history.replaceState(null, '', newUrl.toString()); + } catch { + // Don't update URL if blueprint is invalid JSON + } + }, [blueprintCode, isTemporary]); + const removeSiteAndCloseMenu = async (onClose: () => void) => { // TODO: Replace with HTML-based dialog const proceed = window.confirm(