Enables ContextIsolation
This commit is contained in:
parent
4bbf5eb5d4
commit
9374832ea4
83 changed files with 1009 additions and 1073 deletions
78
ts/util/showConfirmationDialog.tsx
Normal file
78
ts/util/showConfirmationDialog.tsx
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Copyright 2015 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { ConfirmationDialog } from '../components/ConfirmationDialog';
|
||||
|
||||
type ConfirmationDialogViewProps = {
|
||||
onTopOfEverything?: boolean;
|
||||
dialogName: string;
|
||||
cancelText?: string;
|
||||
confirmStyle?: 'affirmative' | 'negative';
|
||||
message: string;
|
||||
okText: string;
|
||||
reject?: (error: Error) => void;
|
||||
resolve: () => void;
|
||||
};
|
||||
|
||||
let confirmationDialogViewNode: HTMLElement | undefined;
|
||||
let confirmationDialogPreviousFocus: HTMLElement | undefined;
|
||||
|
||||
function removeConfirmationDialog() {
|
||||
if (!confirmationDialogViewNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
unmountComponentAtNode(confirmationDialogViewNode);
|
||||
document.body.removeChild(confirmationDialogViewNode);
|
||||
|
||||
if (
|
||||
confirmationDialogPreviousFocus &&
|
||||
typeof confirmationDialogPreviousFocus.focus === 'function'
|
||||
) {
|
||||
confirmationDialogPreviousFocus.focus();
|
||||
}
|
||||
confirmationDialogViewNode = undefined;
|
||||
}
|
||||
|
||||
export function showConfirmationDialog(
|
||||
options: ConfirmationDialogViewProps
|
||||
): void {
|
||||
if (confirmationDialogViewNode) {
|
||||
removeConfirmationDialog();
|
||||
}
|
||||
|
||||
confirmationDialogViewNode = document.createElement('div');
|
||||
document.body.appendChild(confirmationDialogViewNode);
|
||||
|
||||
confirmationDialogPreviousFocus = document.activeElement as HTMLElement;
|
||||
|
||||
render(
|
||||
<ConfirmationDialog
|
||||
dialogName={options.dialogName}
|
||||
onTopOfEverything={options.onTopOfEverything}
|
||||
actions={[
|
||||
{
|
||||
action: () => {
|
||||
options.resolve();
|
||||
},
|
||||
style: options.confirmStyle,
|
||||
text: options.okText || window.i18n('ok'),
|
||||
},
|
||||
]}
|
||||
cancelText={options.cancelText || window.i18n('cancel')}
|
||||
i18n={window.i18n}
|
||||
onCancel={() => {
|
||||
if (options.reject) {
|
||||
options.reject(new Error('showConfirmationDialog: onCancel called'));
|
||||
}
|
||||
}}
|
||||
onClose={() => {
|
||||
removeConfirmationDialog();
|
||||
}}
|
||||
title={options.message}
|
||||
/>,
|
||||
confirmationDialogViewNode
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue