`;
}
renderVerifyInfo() {
if (this.embed !== "replay-with-info") {
return "";
}
return html``;
}
dragStart() {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
replay.setDisablePointer(true);
}
}
dragEnd() {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
replay.setDisablePointer(false);
}
}
clickToDownload() {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
this.clickToDownloadMode = true;
replay.setClickToDownload();
}
return false;
}
cancelClickToDownload() {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
this.clickToDownloadMode = false;
replay.clearHilite(true);
}
return false;
}
renderItemInfo() {
if (!this.itemInfo)
return html`Archive info is not available
Please reload and try again.
`;
return html``;
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'isSidebar' implicitly has an 'any' type.
renderItemTabs(isSidebar) {
const isStory = this.hasStory && this.tabData.view === "story";
const isPages = this.tabData.view === "pages";
const isResources = this.tabData.view === "resources";
return html`
${isStory
? html` `
: ""}
${isResources
? html` `
: ""}
${isPages
? html` `
: ""}
`;
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
skipMenu(event) {
// This is a workaround, since this app's routing doesn't permit normal
// following of in-page anchors.
event.preventDefault();
this.renderRoot.querySelector("#skip-replay-target")?.focus();
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onKeyDown(event) {
if (event.key === "Esc" || event.key === "Escape") {
event.preventDefault();
event.currentTarget.value = this.url;
}
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onMenu(event) {
event.stopPropagation();
this.menuActive = !this.menuActive;
if (this.menuActive) {
document.addEventListener(
"click",
() => {
this.menuActive = false;
},
{ once: true },
);
}
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onFullscreenToggle(event) {
event.preventDefault();
this.menuActive = false;
if (!this.isFullscreen) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.requestFullscreen();
} else {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
document.exitFullscreen();
}
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onGoBack(event) {
event.preventDefault();
this.menuActive = false;
window.history.back();
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onGoForward(event) {
event.preventDefault();
this.menuActive = false;
window.history.forward();
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onShowPages(event) {
event.preventDefault();
// show sidebar for tablet or wider, or hide sidebar
if (this.showSidebar || document.documentElement.clientWidth >= 769) {
this.showSidebar = !this.showSidebar;
} else {
// otherwise, just go to full pages view
this.showSidebar = false;
this.updateTabData({ url: "", ts: "" });
}
if (!this.browsable) {
this.showSidebar = false;
}
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onFullPageView(event) {
event.preventDefault();
this.updateTabData({ url: "", ts: "" });
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onHideSidebar(event) {
event.preventDefault();
this.showSidebar = false;
}
async onReplayLoading(
event: CustomEvent<{ loading: boolean; replayNotFoundError?: boolean }>,
) {
const { loading, replayNotFoundError } = event.detail;
if (this.embed && window.parent !== window && this.isLoading !== loading) {
let loadingDetail: ReplayLoadingDetail;
if (loading) {
loadingDetail = {
loading,
};
} else {
loadingDetail = {
loading,
replayNotFoundError: replayNotFoundError ?? false,
};
}
const msg = {
...loadingDetail,
type: "page-loading",
url: this.tabData.url ?? "",
ts: this.tabData.ts ?? "",
} satisfies RwpPageLoadingEvent["detail"];
window.parent.postMessage(msg, "*");
}
this.isLoading = loading;
}
async onFavIcons(event: CustomEvent) {
if (this.embed && window.parent !== window) {
window.parent.postMessage({ type: "favicons", ...event.detail }, "*");
}
for (const icon of event.detail.icons) {
const resp = await fetch(icon.href);
if (resp.status === 200) {
const ct = resp.headers.get("Content-Type");
if (ct && !ct.startsWith("text/")) {
this.favIconUrl = icon.href;
return;
}
}
}
// not found
this.favIconUrl = "";
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onPurgeCache(event) {
event.preventDefault();
const reload =
event.detail && event.detail.reload !== undefined
? event.detail.reload
: true;
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-unsafe-argument
this.deleteFully(reload);
}
async deleteFully(reload = false) {
const deleteURL = this.itemInfo!.apiPrefix + (reload ? "?reload=1" : "");
const resp = await fetch(deleteURL, {
method: "DELETE",
});
if (resp.status !== 200) {
console.warn("purge failed: " + resp.status);
}
if (!reload && !this.embed) {
window.location.search = "";
return;
}
//window.location.hash = "";
window.location.reload();
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onSubmit(event) {
event.preventDefault();
const input = this.renderRoot.querySelector("input")!;
if (input.value) {
this.navigateTo(input.value);
} else {
input.value = this.url;
}
return false;
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onLostFocus(event) {
if (!event.currentTarget.value) {
event.currentTarget.value = this.url;
}
}
onTimestampDropdownBtnBlur(event: MouseEvent) {
const btn = event.currentTarget as HTMLButtonElement;
const dropdown = btn.closest("sl-dropdown");
const relatedTarget = event.relatedTarget as HTMLElement;
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (relatedTarget && dropdown?.contains(relatedTarget)) {
return;
}
if (dropdown?.open) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
dropdown.hide();
}
}
onSelectTimestamp(event: SlSelectEvent) {
const { item } = event.detail;
this.updateTabData({ ts: item.value });
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'value' implicitly has an 'any' type.
navigateTo(value) {
let data: TabData;
if (value.startsWith("http://") || value.startsWith("https://")) {
data = { url: value };
if (value === this.tabData.url) {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
replay.refresh();
}
return;
}
} else {
if (!value.startsWith(RWP_SCHEME)) {
data = { query: value, view: "pages" };
} else {
data = this._stringToParams(value);
}
}
this.updateTabData(data);
}
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'value' implicitly has an 'any' type.
_stringToParams(value) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const q = new URLSearchParams(value.slice(RWP_SCHEME.length));
const data: Partial = {};
data.url = "";
data.ts = "";
for (const param of [
"query",
"view",
"currList",
"currMime",
"urlSearchType",
]) {
if (q.has(param)) {
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Partial'.
data[param] = q.get(param);
}
}
return data;
}
_paramsToString(value: Record) {
const q = new URLSearchParams();
for (const param of [
"query",
"view",
"currList",
"currMime",
"urlSearchType",
]) {
if (param in value) {
q.set(param, String(value[param]));
}
}
return q.toString();
}
onRefresh(event: Event | null, replayOnly = false) {
if (event) {
event.preventDefault();
}
this.menuActive = false;
if (this.tabData.url) {
const replay = this.renderRoot.querySelector("wr-coll-replay");
if (replay) {
replay.refresh();
}
} else if (!replayOnly) {
window.location.reload();
}
}
onAbout() {
this.dispatchEvent(new CustomEvent("about-show"));
}
onShowInfoDialog() {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.archiveInfoDialog.value?.show();
}
onHideInfoDialog() {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.archiveInfoDialog.value?.hide();
}
}
customElements.define("wr-item", Item);
export { Item };