@@ -19,10 +19,57 @@ index 109e4eb..4906be4 100644
1919 case 'jpg':
2020 case 'jpeg':
2121diff --git a/node_modules/@tutorialkit/react/dist/Panels/PreviewPanel.js b/node_modules/@tutorialkit/react/dist/Panels/PreviewPanel.js
22- index 8fe0723..c329c41 100644
22+ index 8fe0723..46d363c 100644
2323--- a/node_modules/@tutorialkit/react/dist/Panels/PreviewPanel.js
2424+++ b/node_modules/@tutorialkit/react/dist/Panels/PreviewPanel.js
25- @@ -88,11 +88,92 @@ function Preview({ preview, iframe, previewCount, first, last, toggleTerminal, i
25+ @@ -1,7 +1,7 @@
26+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27+ import { useStore } from '@nanostores/react';
28+ import { reloadPreview } from '@webcontainer/api/utils';
29+ - import { createElement, forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef } from 'react';
30+ + import { createElement, forwardRef, memo, useCallback, useState, useEffect, useImperativeHandle, useRef } from 'react';
31+ import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
32+ import { BootScreen } from '../BootScreen.js';
33+ import resizePanelStyles from '../styles/resize-panel.module.css';
34+ @@ -71,6 +71,8 @@ export const PreviewPanel = memo(forwardRef(({ showToggleTerminal, toggleTermina
35+ PreviewPanel.displayName = 'PreviewPanel';
36+ function Preview({ preview, iframe, previewCount, first, last, toggleTerminal, i18n }) {
37+ const previewContainerRef = useRef(null);
38+ + const [currentUrlPath, setCurrentUrlPath] = useState('');
39+ +
40+ useEffect(() => {
41+ if (!iframe.ref) {
42+ return;
43+ @@ -83,16 +85,122 @@ function Preview({ preview, iframe, previewCount, first, last, toggleTerminal, i
44+ iframe.ref.title = preview.title;
45+ }
46+ }, [preview.url, iframe.ref]);
47+ +
48+ + useEffect(() => {
49+ + if (!iframe.ref) {
50+ + return;
51+ + }
52+ +
53+ + const handleLoadMessage = (event) => {
54+ + if (event.data && event.data.type === '$locationChange') {
55+ + const iframeSrc = event.data.location.href;
56+ + if (iframeSrc) {
57+ + const url = new URL(iframeSrc);
58+ + const path = url.pathname.replace("/", "") + url.search;
59+ + setCurrentUrlPath(path);
60+ + }
61+ + }
62+ + };
63+ +
64+ + window.addEventListener('message', handleLoadMessage);
65+ +
66+ + return () => {
67+ + window.removeEventListener('message', handleLoadMessage);
68+ + };
69+ + }, [iframe.ref]);
70+ +
71+ function reload() {
72+ if (iframe.ref) {
2673 reloadPreview(iframe.ref);
2774 }
2875 }
@@ -35,15 +82,15 @@ index 8fe0723..c329c41 100644
3582+ function open(newPath) {
3683+ if (!preview.url) return;
3784+
38- + preview.path = newPath;
85+ + const baseUrl = new URL(preview.url);
86+ + const newUrl = new URL(newPath, baseUrl.origin);
87+ +
3988+ if (iframe.ref) {
40- + iframe.ref.src = preview.url ;
89+ + iframe.ref.src = newUrl.href ;
4190+ }
42- +
43- + reload();
4491+ }
4592+
46- + const urlPath = preview.url ? new URL(preview.url).pathname.replace("/", "") + new URL(preview.url).search : '';
93+ + const urlPath = currentUrlPath || ( preview.url ? new URL(preview.url).pathname.replace("/", "") + new URL(preview.url).search : '') ;
4794+
4895+ return (
4996+ _jsxs("div", {
@@ -80,7 +127,8 @@ index 8fe0723..c329c41 100644
80127+ }),
81128+ _jsx("input", {
82129+ type: "text",
83- + defaultValue: urlPath,
130+ + value: urlPath,
131+ + onChange: (e) => setCurrentUrlPath(e.target.value),
84132+ className: "bg-transparent border-none focus:outline-none text-sm flex-1",
85133+ onKeyDown: (e) => {
86134+ if (e.key === 'Enter') {
0 commit comments