Skip to content

Commit 7384236

Browse files
authored
Revert "feat: implement backward/forward navigation options to iframed window (#181)"
This reverts commit 8ff785c.
1 parent 450199e commit 7384236

File tree

5 files changed

+26
-142
lines changed

5 files changed

+26
-142
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/routes/tutorial/[slug]/+page.svelte

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,15 @@
9595
9696
/** @type {import('$lib/types').Adapter | undefined} */
9797
let adapter;
98-
/** @type {string[]} */
99-
let history_bwd = [];
100-
/** @type {string[]} */
101-
let history_fwd = [];
102-
let ignore_path_change = false;
103-
104-
function reset_history() {
105-
history_bwd = [];
106-
history_fwd = [];
107-
}
10898
10999
onMount(() => {
110-
function on_iframe_load() {
111-
iframe.classList.add('loaded');
112-
}
113100
function destroy() {
114-
iframe.removeEventListener('load', on_iframe_load);
115101
if (adapter) {
116102
adapter.destroy();
117103
}
118104
}
119105
120106
document.addEventListener('pagehide', destroy);
121-
iframe.addEventListener('load', on_iframe_load);
122107
return destroy;
123108
});
124109
@@ -137,7 +122,6 @@
137122
loading = true;
138123
139124
reset_complete_states();
140-
reset_history();
141125
142126
await reset_adapter($files);
143127
@@ -270,16 +254,7 @@
270254
if (e.origin !== adapter.base) return;
271255
272256
if (e.data.type === 'ping') {
273-
const new_path = e.data.data.path ?? path;
274-
if (path !== new_path) {
275-
// skip `nav_to` step if triggered by bwd/fwd action
276-
if (ignore_path_change) {
277-
ignore_path_change = false;
278-
} else {
279-
nav_to();
280-
}
281-
path = new_path;
282-
}
257+
path = e.data.data.path ?? path;
283258
284259
clearTimeout(timeout);
285260
timeout = setTimeout(() => {
@@ -322,47 +297,10 @@
322297
// change the src without adding a history entry, which
323298
// would make back/forward traversal very annoying
324299
const parentNode = /** @type {HTMLElement} */ (iframe.parentNode);
325-
iframe.classList.remove('loaded');
326300
parentNode?.removeChild(iframe);
327301
iframe.src = src;
328302
parentNode?.appendChild(iframe);
329303
}
330-
331-
/** @param {string} path */
332-
function route_to(path) {
333-
if (adapter) {
334-
const url = new URL(path, adapter.base);
335-
path = url.pathname + url.search + url.hash;
336-
set_iframe_src(adapter.base + path);
337-
}
338-
}
339-
340-
/** @param {string | null} new_path */
341-
function nav_to(new_path = null) {
342-
if (path !== history_bwd[history_bwd.length - 1]) {
343-
history_bwd = [...history_bwd, path];
344-
}
345-
history_fwd = [];
346-
if (new_path) route_to(new_path);
347-
}
348-
349-
function go_bwd() {
350-
const new_path = history_bwd[history_bwd.length - 1];
351-
if (new_path) {
352-
ignore_path_change = true;
353-
[history_bwd, history_fwd] = [history_bwd.slice(0, -1), [path, ...history_fwd]];
354-
route_to(new_path);
355-
}
356-
}
357-
358-
function go_fwd() {
359-
const new_path = history_fwd[0];
360-
if (new_path) {
361-
ignore_path_change = true;
362-
[history_bwd, history_fwd] = [[...history_bwd, path], history_fwd.slice(1)];
363-
route_to(new_path);
364-
}
365-
}
366304
</script>
367305
368306
<svelte:window on:message={handle_message} bind:innerWidth={width} />
@@ -462,18 +400,20 @@
462400
463401
<section slot="b" class="preview">
464402
<Chrome
465-
{history_bwd}
466-
{history_fwd}
467403
{path}
468404
{loading}
469405
on:refresh={() => {
470406
if (adapter) {
471407
set_iframe_src(adapter.base + path);
472408
}
473409
}}
474-
on:change={(e) => nav_to(e.detail.value)}
475-
on:back={go_bwd}
476-
on:forward={go_fwd}
410+
on:change={(e) => {
411+
if (adapter) {
412+
const url = new URL(e.detail.value, adapter.base);
413+
path = url.pathname + url.search + url.hash;
414+
set_iframe_src(adapter.base + path);
415+
}
416+
}}
477417
/>
478418
479419
<div class="content">
@@ -503,7 +443,6 @@
503443
.content {
504444
display: flex;
505445
flex-direction: column;
506-
position: relative;
507446
min-height: 0;
508447
height: 100%;
509448
max-height: 100%;
@@ -546,6 +485,10 @@
546485
flex-direction: column;
547486
}
548487
488+
.content {
489+
position: relative;
490+
}
491+
549492
iframe {
550493
width: 100%;
551494
height: 100%;
@@ -556,10 +499,6 @@
556499
background: var(--sk-back-2);
557500
}
558501
559-
iframe:not(.loaded) {
560-
display: none;
561-
}
562-
563502
.editor-container {
564503
position: relative;
565504
background-color: var(--sk-back-3);
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 './chevron.svg';
43
import refresh from './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]/chevron.svg

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Loading

0 commit comments

Comments
 (0)