Apply review suggestions
This commit is contained in:
parent
c62210b07c
commit
7207329c15
14 changed files with 201 additions and 195 deletions
|
@ -25,6 +25,7 @@ import { Direction, MatrixClient } from "matrix-js-sdk";
|
|||
import { MutableRefObject } from "react";
|
||||
import JSZip from "jszip";
|
||||
import { saveAs } from "file-saver";
|
||||
import { _t } from "../../languageHandler";
|
||||
|
||||
type BlobFile = {
|
||||
name: string;
|
||||
|
@ -54,7 +55,7 @@ export default abstract class Exporter {
|
|||
|
||||
protected onBeforeUnload(e: BeforeUnloadEvent): string {
|
||||
e.preventDefault();
|
||||
return e.returnValue = "Are you sure you want to exit during this export?";
|
||||
return e.returnValue = _t("Are you sure you want to exit during this export?");
|
||||
}
|
||||
|
||||
protected updateProgress(progress: string, log = true, show = true): void {
|
||||
|
@ -70,7 +71,7 @@ export default abstract class Exporter {
|
|||
this.files.push(file);
|
||||
}
|
||||
|
||||
protected async downloadZIP(): Promise<string | null> {
|
||||
protected async downloadZIP(): Promise<string | void> {
|
||||
const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`;
|
||||
|
||||
const zip = new JSZip();
|
||||
|
|
|
@ -31,7 +31,6 @@ import EventTile, { haveTileForEvent } from "../../components/views/rooms/EventT
|
|||
import DateSeparator from "../../components/views/messages/DateSeparator";
|
||||
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
|
||||
import exportJS from "!!raw-loader!./exportJS";
|
||||
import exportIcons from "./exportIcons";
|
||||
import { ExportType } from "./exportUtils";
|
||||
import { IExportOptions } from "./exportUtils";
|
||||
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
||||
|
@ -294,6 +293,7 @@ export default class HTMLExporter extends Exporter {
|
|||
const mxc = mxEv.getContent().url || mxEv.getContent().file?.url;
|
||||
eventTileMarkup = eventTileMarkup.split(mxc).join(filePath);
|
||||
}
|
||||
eventTileMarkup = eventTileMarkup.replace(/<span class="mx_MFileBody_info_icon".*?>.*?<\/span>/, '');
|
||||
if (hasAvatar) {
|
||||
eventTileMarkup = eventTileMarkup.replace(
|
||||
encodeURI(this.getAvatarURL(mxEv)).replace(/&/g, '&'),
|
||||
|
@ -406,10 +406,6 @@ export default class HTMLExporter extends Exporter {
|
|||
this.addFile("css/style.css", new Blob([exportCSS]));
|
||||
this.addFile("js/script.js", new Blob([exportJS]));
|
||||
|
||||
for (const iconName in exportIcons) {
|
||||
this.addFile(`icons/${iconName}`, new Blob([exportIcons[iconName]]));
|
||||
}
|
||||
|
||||
await this.downloadZIP();
|
||||
|
||||
const exportEnd = performance.now();
|
||||
|
|
|
@ -16,33 +16,31 @@ limitations under the License.
|
|||
|
||||
/* eslint-disable max-len, camelcase */
|
||||
|
||||
declare const __webpack_hash__: string;
|
||||
|
||||
import ThemeWatcher from "../../settings/watchers/ThemeWatcher";
|
||||
|
||||
const getExportCSS = async (): Promise<string> => {
|
||||
const theme = new ThemeWatcher().getEffectiveTheme();
|
||||
const hash = __webpack_hash__;
|
||||
|
||||
const bundle = await fetch(`bundles/${hash}/bundle.css`);
|
||||
const bundleCSS = await bundle.text();
|
||||
let themeCSS: string;
|
||||
if (theme === 'light') {
|
||||
const res = await fetch(`bundles/${hash}/theme-light.css`);
|
||||
themeCSS = await res.text();
|
||||
} else {
|
||||
const res = await fetch(`bundles/${hash}/theme-dark.css`);
|
||||
themeCSS = await res.text();
|
||||
const stylesheets: string[] = [];
|
||||
document.querySelectorAll('link[rel="stylesheet"]').forEach((e: any) => {
|
||||
if (e.href.endsWith("bundle.css") || e.href.endsWith(`theme-${theme}.css`)) {
|
||||
stylesheets.push(e.href);
|
||||
}
|
||||
});
|
||||
let CSS: string;
|
||||
for (const stylesheet of stylesheets) {
|
||||
const res = await fetch(stylesheet);
|
||||
const innerText = await res.text();
|
||||
CSS += innerText;
|
||||
}
|
||||
const fontFaceRegex = /@font-face {.*?}/sg;
|
||||
|
||||
themeCSS = themeCSS.replace(fontFaceRegex, '');
|
||||
themeCSS = themeCSS.replace(
|
||||
CSS = CSS.replace(fontFaceRegex, '');
|
||||
CSS = CSS.replace(
|
||||
/font-family: Inter/g,
|
||||
`font-family: -apple-system, BlinkMacSystemFont, avenir next,
|
||||
avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif`,
|
||||
);
|
||||
themeCSS = themeCSS.replace(
|
||||
CSS = CSS.replace(
|
||||
/font-family: Inconsolata/g,
|
||||
"font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace",
|
||||
);
|
||||
|
@ -148,6 +146,10 @@ const getExportCSS = async (): Promise<string> => {
|
|||
top: 1px;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.mx_RedactedBody {
|
||||
padding-left: unset;
|
||||
}
|
||||
|
||||
img {
|
||||
white-space: nowrap;
|
||||
|
@ -155,7 +157,7 @@ const getExportCSS = async (): Promise<string> => {
|
|||
}
|
||||
`;
|
||||
|
||||
return themeCSS + bundleCSS + customCSS;
|
||||
return CSS + customCSS;
|
||||
};
|
||||
|
||||
export default getExportCSS;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import trashSVG from "!!raw-loader!../../../res/img/element-icons/trashcan.svg";
|
||||
import attachSVG from "!!raw-loader!../../../res/img/element-icons/room/composer/attach.svg";
|
||||
|
||||
export default {
|
||||
"trash.svg": trashSVG,
|
||||
"attach.svg": attachSVG,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue