Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Revert "Implement backward and forward navigation options to iframed window"#187

Merged
Rich-Harris merged 7 commits intomainfromrevert-181-main
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletionspnpm-lock.yaml
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

10 changes: 1 addition & 9 deletionssrc/lib/icons/chevron.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletionssrc/lib/icons/refresh.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletionssrc/routes/tutorial/[slug]/+page.svelte
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -160,20 +160,6 @@
flex-direction: column;
}

iframe {
width: 100%;
height: 100%;
flex: 1;
resize: none;
box-sizing: border-box;
border: none;
background: var(--sk-back-2);
}

iframe:not(.loaded) {
display: none;
}

.editor-container {
position: relative;
background-color: var(--sk-back-3);
Expand Down
48 changes: 3 additions & 45 deletionssrc/routes/tutorial/[slug]/Chrome.svelte
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
<script>
import { createEventDispatcher } from 'svelte';
import chevron from '$lib/icons/chevron.svg';
import refresh from '$lib/icons/refresh.svg';

/** @type {string} */
export let path;

/** @type {string[]} */
export let history_bwd = [];

/** @type {string[]} */
export let history_fwd = [];

/** @type {boolean} */
export let loading;

const dispatch = createEventDispatcher();

$: [disabledBwd, disabledFwd] = [loading || !history_bwd.length, loading || !history_fwd.length];
</script>

<div class="chrome">
<button disabled={disabledBwd} on:click={() => dispatch('back')} aria-label="go back">
<img src={chevron} alt="Back icon" />
</button>
<button disabled={disabledFwd} on:click={() => dispatch('forward')} aria-label="go forward">
<img src={chevron} style="transform: rotate(180deg)" alt="Forward icon" />
</button>
<button
class="refresh"
disabled={loading}
on:click={() => dispatch('refresh')}
aria-label="reload"
>
<button disabled={loading} on:click={() => dispatch('refresh')} aria-label="reload">
<img src={refresh} alt="Reload icon" />
</button>

Expand DownExpand Up@@ -63,11 +43,11 @@
.chrome button img {
width: 2rem;
height: 2rem;
transition:transform0.2s ease-out, opacity 0.1s ease-out;
transition: 0.2s ease-out;
transform: none;
}

.chrome button.refresh:active img {
.chrome button:active img {
transform: rotate(-360deg);
transition: none;
}
Expand All@@ -91,26 +71,4 @@
outline: none;
border: 2px solid var(--sk-theme-3);
}

.chrome button {
user-select: none;
}

.chrome button[disabled] {
opacity: 1;
}

.chrome button[disabled] img {
opacity: 0.5;
}

.chrome button img {
opacity: 0.8;
}

.chrome button:hover img,
.chrome button:active img,
.chrome button:focus-visible img {
opacity: 1;
}
</style>
78 changes: 8 additions & 70 deletionssrc/routes/tutorial/[slug]/Output.svelte
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,16 +23,6 @@

/** @type {import('$lib/types').Adapter} Will be defined after first afterNavigate */
let adapter;
/** @type {string[]} */
let history_bwd = [];
/** @type {string[]} */
let history_fwd = [];
let ignore_path_change = false;

function reset_history() {
history_bwd = [];
history_fwd = [];
}

onMount(() => {
const unsub = state.subscribe(async (state) => {
Expand All@@ -57,25 +47,19 @@
}
});

function on_iframe_load() {
iframe.classList.add('loaded');
}
function destroy() {
iframe.removeEventListener('load', on_iframe_load);
unsub();
if (adapter) {
adapter.destroy();
}
}

document.addEventListener('pagehide', destroy);
iframe.addEventListener('load', on_iframe_load);
return destroy;
});

afterNavigate(() => {
clearTimeout(timeout);
reset_history();
});

/**
Expand DownExpand Up@@ -155,16 +139,7 @@
if (e.origin !== adapter.base) return;

if (e.data.type === 'ping') {
const new_path = e.data.data.path ?? path;
if (path !== new_path) {
// skip `nav_to` step if triggered by bwd/fwd action
if (ignore_path_change) {
ignore_path_change = false;
} else {
nav_to();
}
path = new_path;
}
path = e.data.data.path ?? path;

clearTimeout(timeout);
timeout = setTimeout(() => {
Expand All@@ -186,59 +161,26 @@
// change the src without adding a history entry, which
// would make back/forward traversal very annoying
const parentNode = /** @type {HTMLElement} */ (iframe.parentNode);
iframe.classList.remove('loaded');
parentNode?.removeChild(iframe);
iframe.src = src;
parentNode?.appendChild(iframe);
}

/** @param {string} path */
function route_to(path) {
const url = new URL(path, adapter.base);
path = url.pathname + url.search + url.hash;
set_iframe_src(adapter.base + path);
}

/** @param {string | null} new_path */
function nav_to(new_path = null) {
if (path !== history_bwd[history_bwd.length - 1]) {
history_bwd = [...history_bwd, path];
}
history_fwd = [];
if (new_path) route_to(new_path);
}

function go_bwd() {
const new_path = history_bwd[history_bwd.length - 1];
if (new_path) {
ignore_path_change = true;
[history_bwd, history_fwd] = [history_bwd.slice(0, -1), [path, ...history_fwd]];
route_to(new_path);
}
}

function go_fwd() {
const new_path = history_fwd[0];
if (new_path) {
ignore_path_change = true;
[history_bwd, history_fwd] = [[...history_bwd, path], history_fwd.slice(1)];
route_to(new_path);
}
}
</script>

<svelte:window on:message={handle_message} />
<Chrome
{history_bwd}
{history_fwd}
{path}
{loading}
on:refresh={() => {
set_iframe_src(adapter.base + path);
}}
on:change={(e) => nav_to(e.detail.value)}
on:back={go_bwd}
on:forward={go_fwd}
on:change={(e) => {
if (adapter) {
const url = new URL(e.detail.value, adapter.base);
path = url.pathname + url.search + url.hash;
set_iframe_src(adapter.base + path);
}
}}
/>

<div class="content">
Expand DownExpand Up@@ -272,8 +214,4 @@
border: none;
background: var(--sk-back-2);
}

iframe:not(.loaded) {
display: none;
}
</style>

[8]ページ先頭

©2009-2025 Movatter.jp