Skip to content

Commit 66f51bb

Browse files
authored
Revert "Implement backward and forward navigation options to iframed window" (#187)
* Revert "feat: implement backward/forward navigation options to iframed window (#181)" This reverts commit 8ff785c. * finish merge * fix * tidy up * tidy up * oops
1 parent 00892b4 commit 66f51bb

File tree

5 files changed

+23
-137
lines changed

5 files changed

+23
-137
lines changed

pnpm-lock.yaml

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

src/lib/icons/chevron.svg

Lines changed: 1 addition & 9 deletions
Loading

src/lib/icons/refresh.svg

Lines changed: 3 additions & 5 deletions
Loading
Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
11
<script>
22
import { createEventDispatcher } from 'svelte';
3-
import chevron from '$lib/icons/chevron.svg';
43
import refresh from '$lib/icons/refresh.svg';
54
65
/** @type {string} */
76
export let path;
87
9-
/** @type {string[]} */
10-
export let history_bwd = [];
11-
12-
/** @type {string[]} */
13-
export let history_fwd = [];
14-
158
/** @type {boolean} */
169
export let loading;
1710
1811
const dispatch = createEventDispatcher();
19-
20-
$: [disabledBwd, disabledFwd] = [loading || !history_bwd.length, loading || !history_fwd.length];
2112
</script>
2213

2314
<div class="chrome">
24-
<button disabled={disabledBwd} on:click={() => dispatch('back')} aria-label="go back">
25-
<img src={chevron} alt="Back icon" />
26-
</button>
27-
<button disabled={disabledFwd} on:click={() => dispatch('forward')} aria-label="go forward">
28-
<img src={chevron} style="transform: rotate(180deg)" alt="Forward icon" />
29-
</button>
30-
<button
31-
class="refresh"
32-
disabled={loading}
33-
on:click={() => dispatch('refresh')}
34-
aria-label="reload"
35-
>
15+
<button disabled={loading} on:click={() => dispatch('refresh')} aria-label="reload">
3616
<img src={refresh} alt="Reload icon" />
3717
</button>
3818

@@ -63,11 +43,11 @@
6343
.chrome button img {
6444
width: 2rem;
6545
height: 2rem;
66-
transition: transform 0.2s ease-out, opacity 0.1s ease-out;
46+
transition: 0.2s ease-out;
6747
transform: none;
6848
}
6949
70-
.chrome button.refresh:active img {
50+
.chrome button:active img {
7151
transform: rotate(-360deg);
7252
transition: none;
7353
}
@@ -91,26 +71,4 @@
9171
outline: none;
9272
border: 2px solid var(--sk-theme-3);
9373
}
94-
95-
.chrome button {
96-
user-select: none;
97-
}
98-
99-
.chrome button[disabled] {
100-
opacity: 1;
101-
}
102-
103-
.chrome button[disabled] img {
104-
opacity: 0.5;
105-
}
106-
107-
.chrome button img {
108-
opacity: 0.8;
109-
}
110-
111-
.chrome button:hover img,
112-
.chrome button:active img,
113-
.chrome button:focus-visible img {
114-
opacity: 1;
115-
}
11674
</style>

src/routes/tutorial/[slug]/Output.svelte

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
2424
/** @type {import('$lib/types').Adapter} Will be defined after first afterNavigate */
2525
let adapter;
26-
/** @type {string[]} */
27-
let history_bwd = [];
28-
/** @type {string[]} */
29-
let history_fwd = [];
30-
let ignore_path_change = false;
31-
32-
function reset_history() {
33-
history_bwd = [];
34-
history_fwd = [];
35-
}
3626
3727
onMount(() => {
3828
const unsub = state.subscribe(async (state) => {
@@ -57,25 +47,19 @@
5747
}
5848
});
5949
60-
function on_iframe_load() {
61-
iframe.classList.add('loaded');
62-
}
6350
function destroy() {
64-
iframe.removeEventListener('load', on_iframe_load);
6551
unsub();
6652
if (adapter) {
6753
adapter.destroy();
6854
}
6955
}
7056
7157
document.addEventListener('pagehide', destroy);
72-
iframe.addEventListener('load', on_iframe_load);
7358
return destroy;
7459
});
7560
7661
afterNavigate(() => {
7762
clearTimeout(timeout);
78-
reset_history();
7963
});
8064
8165
/**
@@ -155,16 +139,7 @@
155139
if (e.origin !== adapter.base) return;
156140
157141
if (e.data.type === 'ping') {
158-
const new_path = e.data.data.path ?? path;
159-
if (path !== new_path) {
160-
// skip `nav_to` step if triggered by bwd/fwd action
161-
if (ignore_path_change) {
162-
ignore_path_change = false;
163-
} else {
164-
nav_to();
165-
}
166-
path = new_path;
167-
}
142+
path = e.data.data.path ?? path;
168143
169144
clearTimeout(timeout);
170145
timeout = setTimeout(() => {
@@ -186,59 +161,26 @@
186161
// change the src without adding a history entry, which
187162
// would make back/forward traversal very annoying
188163
const parentNode = /** @type {HTMLElement} */ (iframe.parentNode);
189-
iframe.classList.remove('loaded');
190164
parentNode?.removeChild(iframe);
191165
iframe.src = src;
192166
parentNode?.appendChild(iframe);
193167
}
194-
195-
/** @param {string} path */
196-
function route_to(path) {
197-
const url = new URL(path, adapter.base);
198-
path = url.pathname + url.search + url.hash;
199-
set_iframe_src(adapter.base + path);
200-
}
201-
202-
/** @param {string | null} new_path */
203-
function nav_to(new_path = null) {
204-
if (path !== history_bwd[history_bwd.length - 1]) {
205-
history_bwd = [...history_bwd, path];
206-
}
207-
history_fwd = [];
208-
if (new_path) route_to(new_path);
209-
}
210-
211-
function go_bwd() {
212-
const new_path = history_bwd[history_bwd.length - 1];
213-
if (new_path) {
214-
ignore_path_change = true;
215-
[history_bwd, history_fwd] = [history_bwd.slice(0, -1), [path, ...history_fwd]];
216-
route_to(new_path);
217-
}
218-
}
219-
220-
function go_fwd() {
221-
const new_path = history_fwd[0];
222-
if (new_path) {
223-
ignore_path_change = true;
224-
[history_bwd, history_fwd] = [[...history_bwd, path], history_fwd.slice(1)];
225-
route_to(new_path);
226-
}
227-
}
228168
</script>
229169
230170
<svelte:window on:message={handle_message} />
231171
<Chrome
232-
{history_bwd}
233-
{history_fwd}
234172
{path}
235173
{loading}
236174
on:refresh={() => {
237175
set_iframe_src(adapter.base + path);
238176
}}
239-
on:change={(e) => nav_to(e.detail.value)}
240-
on:back={go_bwd}
241-
on:forward={go_fwd}
177+
on:change={(e) => {
178+
if (adapter) {
179+
const url = new URL(e.detail.value, adapter.base);
180+
path = url.pathname + url.search + url.hash;
181+
set_iframe_src(adapter.base + path);
182+
}
183+
}}
242184
/>
243185
244186
<div class="content">
@@ -272,8 +214,4 @@
272214
border: none;
273215
background: var(--sk-back-2);
274216
}
275-
276-
iframe:not(.loaded) {
277-
display: none;
278-
}
279217
</style>

0 commit comments

Comments
 (0)