Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump squire-rte from 1.11.3 to 2.2.2 #5442

Merged
merged 9 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion conf/tsconfig.content_scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"paths": {
"dompurify": ["types/purify.d.ts"],
"openpgp": ["../node_modules/openpgp/openpgp.d.ts"],
"@openpgp/web-stream-tools": ["../node_modules/@openpgp/web-stream-tools/types/index.v4.9.d.ts"]
"@openpgp/web-stream-tools": ["../node_modules/@openpgp/web-stream-tools/types/index.v4.9.d.ts"],
"squire-rte": ["../node_modules/squire-rte/dist/types/Squire.d.ts"]
},
"typeRoots": ["../extension/types", "../extension/js/common/core/types"]
},
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/dev/ci_unit_test.htm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 id="h1">loading..</h1>
<script src="/lib/openpgp.js"></script>
<script src="/lib/jquery.min.js"></script>
<script src="/lib/sweetalert2.js"></script>
<script src="/lib/squire-raw.js"></script>
<script src="/lib/squire.js"></script>
<script src="/lib/emailjs/punycode.js"></script>
<script src="/lib/emailjs/emailjs-stringencoding.js"></script>
<script src="/lib/emailjs/emailjs-mime-codec.js"></script>
Expand Down
66 changes: 46 additions & 20 deletions extension/chrome/elements/compose-modules/compose-input-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

import { NewMsgData, ValidRecipientElement } from './compose-types.js';
import { CursorEvent, SquireEditor, WillPasteEvent } from '../../../types/squire.js';
import Squire from 'squire-rte';

import { Catch } from '../../../js/common/platform/catch.js';
import { ParsedRecipients } from '../../../js/common/api/email-provider/email-provider-api.js';
Expand All @@ -14,21 +14,31 @@ import { Ui } from '../../../js/common/browser/ui.js';
import { ComposeView } from '../compose.js';
import { Lang } from '../../../js/common/lang.js';

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/naming-convention
Squire: typeof Squire;
}
}

interface SquireWillPasteEvent extends Event {
fragment: DocumentFragment;
}

export class ComposeInputModule extends ViewModule<ComposeView> {
public squire = new window.Squire(this.view.S.cached('input_text').get(0) as HTMLElement);
public squire!: Squire;

public constructor(view: ComposeView) {
super(view);
this.initSquire(false);
}

public setHandlers = () => {
this.view.S.cached('add_intro').on(
'click',
this.view.setHandler(el => this.actionAddIntroHandler(el), this.view.errModule.handle(`add intro`))
);
this.handlePaste();
this.handlePasteImages();
this.initShortcuts();
this.resizeReplyBox();
this.scrollIntoView();
this.handleRTL();
this.squire.setConfig({ addLinks: this.isRichText() });
this.initSquire(this.isRichText());
// Set lastDraftBody to current empty squire content ex: <div><br></div>)
// https://github.com/FlowCrypt/flowcrypt-browser/issues/5184
this.view.draftModule.setLastDraftBody(this.squire.getHTML());
Expand All @@ -38,12 +48,11 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
};

public addRichTextFormatting = () => {
this.squire.setConfig({ addLinks: true });
this.initSquire(true);
};

public removeRichTextFormatting = () => {
this.squire.setHTML(Xss.htmlSanitizeAndStripAllTags(this.squire.getHTML(), '<br>'));
this.squire.setConfig({ addLinks: false });
this.initSquire(false, true);
};

public inputTextHtmlSetSafely = (html: string) => {
Expand Down Expand Up @@ -92,13 +101,30 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
return isInputLimitExceeded;
};

private initSquire = (addLinks: boolean, removeExistingLinks = false) => {
sosnovsky marked this conversation as resolved.
Show resolved Hide resolved
const squireHtml = this.squire?.getHTML();
const el = this.view.S.cached('input_text').get(0) as HTMLElement;
this.squire?.destroy();
this.squire = new window.Squire(el, { addLinks });
this.initShortcuts();
this.handlePaste();
this.handlePasteImages();
this.resizeReplyBox();
this.scrollIntoView();
this.handleRTL();
if (squireHtml) {
const processedHtml = removeExistingLinks ? Xss.htmlSanitizeAndStripAllTags(squireHtml, '<br>', false) : squireHtml;
this.squire.setHTML(processedHtml);
}
};

private handlePaste = () => {
this.squire.addEventListener('willPaste', async (e: WillPasteEvent) => {
this.squire.addEventListener('willPaste', async (e: SquireWillPasteEvent) => {
const div = document.createElement('div');
div.appendChild(e.fragment);
const html = div.innerHTML;
const sanitized = this.isRichText() ? Xss.htmlSanitizeKeepBasicTags(html, 'IMG-KEEP') : Xss.htmlSanitizeAndStripAllTags(html, '<br>', false);
if (this.willInputLimitBeExceeded(sanitized, this.squire.getRoot(), () => this.squire.getSelectedText().length)) {
if (this.willInputLimitBeExceeded(sanitized, this.squire.getRoot(), () => this.squire.getSelectedText().length as number)) {
e.preventDefault();
await Ui.modal.warning(Lang.compose.inputLimitExceededOnPaste);
return;
Expand All @@ -121,7 +147,7 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
const reader = new FileReader();
reader.onload = () => {
try {
this.squire.insertImage(reader.result as ArrayBuffer, { name: file.name, title: file.name });
this.squire.insertImage(reader.result?.toString() ?? '', { name: file.name, title: file.name });
this.view.draftModule.draftSave().catch(Catch.reportErr);
} catch (e) {
Catch.reportErr(e);
Expand Down Expand Up @@ -162,9 +188,9 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
private initShortcuts = () => {
try {
const isMac = /Mac OS X/.test(navigator.userAgent);
const ctrlKey = isMac ? 'meta-' : 'ctrl-';
const ctrlKey = isMac ? 'Meta-' : 'Ctrl-';
const mapKeyToFormat = (tag: string) => {
return (self: SquireEditor, event: Event) => {
return (self: Squire, event: Event) => {
try {
event.preventDefault();
if (!this.isRichText()) {
Expand All @@ -181,10 +207,10 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
}
};
};
const noop = (self: SquireEditor, event: Event) => {
const noop = (_self: Squire, event: Event) => {
event.preventDefault();
};
const removeFormatting = (self: SquireEditor) => {
const removeFormatting = (self: Squire) => {
self.removeAllFormatting();
};
this.squire.setKeyHandler(ctrlKey + 'b', mapKeyToFormat('B'));
Expand All @@ -204,7 +230,7 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
};

private resizeReplyBox = () => {
this.squire.addEventListener('cursor', (e: CursorEvent) => {
this.squire.addEventListener('cursor', (e: Event & { range: Range }) => {
if (this.view.isReplyBox) {
const cursorContainer = e.range.commonAncestorContainer as HTMLElement;
this.view.sizeModule.resizeComposeBox(0, cursorContainer?.offsetTop);
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/elements/compose.htm
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h1 id="header_title" data-test="header-title">New Secure Message</h1>
<script src="/lib/openpgp.js"></script>
<script src="/lib/jquery.min.js"></script>
<script src="/lib/sweetalert2.js"></script>
<script src="/lib/squire-raw.js"></script>
<script src="/lib/squire.js"></script>
<script src="/lib/emailjs/punycode.js"></script>
<script src="/lib/emailjs/emailjs-stringencoding.js"></script>
<script src="/lib/emailjs/emailjs-mime-codec.js"></script>
Expand Down
83 changes: 0 additions & 83 deletions extension/types/squire.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"linkifyjs": "^4.1.1",
"node-forge": "1.3.1",
"postcss-html": "^1.5.0",
"squire-rte": "1.11.3",
"squire-rte": "2.2.4",
"sweetalert2": "11.7.31",
"tap-xunit": "^2.4.1",
"zxcvbn": "4.4.2"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ copy_dependencies() {
cp node_modules/sweetalert2/dist/sweetalert2.css $OUTPUT_DIRECTORY/css/sweetalert2.css
cp node_modules/iso-8859-2/iso-8859-2.js $OUTPUT_DIRECTORY/lib/iso-8859-2.js
cp node_modules/zxcvbn/dist/zxcvbn.js $OUTPUT_DIRECTORY/lib/zxcvbn.js
cp node_modules/squire-rte/build/squire-raw.js $OUTPUT_DIRECTORY/lib/squire-raw.js
cp node_modules/squire-rte/dist/squire.js $OUTPUT_DIRECTORY/lib/squire.js
cp node_modules/clipboard/dist/clipboard.js $OUTPUT_DIRECTORY/lib/clipboard.js
cp node_modules/@flowcrypt/fine-uploader/fine-uploader/fine-uploader.js $OUTPUT_DIRECTORY/lib/fine-uploader.js
cp node_modules/filesize/dist/filesize.js $OUTPUT_DIRECTORY/lib/filesize.js
Expand Down
2 changes: 1 addition & 1 deletion test/source/tests/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te
expect(await composePage.read('.swal2-html-container')).to.include('Send empty message?');
await composePage.waitAndClick('.swal2-cancel');
const footer = await composePage.read('@input-body');
expect(footer).to.eq('\n\n\n--\nflowcrypt.compatibility test footer with an img\nand second line');
expect(footer).to.eq('\n\n\n\n--\n\nflowcrypt.compatibility test footer with an img\n\nand second line\n');
await composePage.waitAndClick(`@action-send`);
expect(await composePage.read('.swal2-html-container')).to.include('Send empty message?');
await composePage.waitAndClick('.swal2-cancel');
Expand Down
2 changes: 1 addition & 1 deletion test/source/tests/page-recipe/compose-page-recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class ComposePageRecipe extends PageRecipe {
if (inputMethod === 'mouse') {
await passPhraseFrame.waitAndClick('@action-cancel-pass-phrase-entry');
} else if (inputMethod === 'keyboard') {
await page.press('Escape');
await passPhraseFrame.keyboard().press('Escape');
}
await page.waitTillGone('@dialog-passphrase');
expect(passPhraseFrame.frame.isDetached()).to.equal(true);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"jquery": ["lib/jquery.min.js", "COMMENT"],
"sweetalert2": ["lib/sweetalert2.js", "COMMENT"],
"openpgp": ["../node_modules/openpgp/openpgp.d.js", "lib/openpgp.js", "COMMENT"],
"squire-rte": ["../node_modules/squire-rte/dist/types/Squire.d.ts"],
"@openpgp/web-stream-tools": ["../node_modules/@openpgp/web-stream-tools/types/index.v4.9.d.ts", "lib/streams/streams.js"],
"dompurify": ["types/purify.d.ts", "lib/purify.js", "COMMENT"],
"fine-uploader": ["lib/fine-uploader.js", "COMMENT"],
Expand Down
Loading