Skip to content

Commit f4c7854

Browse files
committed
format
1 parent e425732 commit f4c7854

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

src/lib/Functions/handleCopy.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import { ClipboardEvent } from "../Model/domEventsTypes";
2-
import { State } from "../Model/State";
3-
import { getDataToCopy } from "./getDataToCopy";
4-
import { getActiveSelectedRange } from "./getActiveSelectedRange";
5-
import { isBrowserSafari } from "./safari";
1+
import { ClipboardEvent } from '../Model/domEventsTypes';
2+
import { State } from '../Model/State';
3+
import { getDataToCopy } from './getDataToCopy';
4+
import { getActiveSelectedRange } from './getActiveSelectedRange';
5+
import { isBrowserSafari } from './safari';
66

77
export function handleCopy(event: ClipboardEvent, state: State, removeValues = false): State {
8-
const activeSelectedRange = getActiveSelectedRange(state);
9-
if (!activeSelectedRange) {
10-
return state;
11-
}
12-
const { div } = getDataToCopy(state, activeSelectedRange, removeValues);
13-
copyDataCommands(event, state, div);
14-
return { ...state, copyRange: activeSelectedRange };
8+
const activeSelectedRange = getActiveSelectedRange(state);
9+
if (!activeSelectedRange) {
10+
return state;
11+
}
12+
const { div } = getDataToCopy(state, activeSelectedRange, removeValues);
13+
copyDataCommands(event, state, div);
14+
return { ...state, copyRange: activeSelectedRange };
1515
}
1616

1717
export function copyDataCommands(event: ClipboardEvent, state: State, div: HTMLDivElement): void {
18-
// how document.execCommand is deprecated, we need try use Clipboard API if is available
19-
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
20-
const supportNavigatorClipboard = !!navigator?.clipboard?.write;
18+
// how document.execCommand is deprecated, we need try use Clipboard API if is available
19+
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
20+
const supportNavigatorClipboard = !!navigator?.clipboard?.write;
2121

22-
if (isBrowserSafari()) {
23-
event.clipboardData.setData("text/html", div.innerHTML);
24-
} else if (supportNavigatorClipboard) {
25-
const clipboardItemData = {
26-
"text/html": div.innerHTML,
27-
};
28-
const clipboardItem = new ClipboardItem(clipboardItemData);
29-
navigator.clipboard.write([clipboardItem]).then(() => ({}));
30-
} else {
31-
document.body.appendChild(div);
32-
div.focus();
33-
document.execCommand("selectAll", false);
34-
document.execCommand("copy");
35-
document.body.removeChild(div);
36-
}
22+
if (isBrowserSafari()) {
23+
event.clipboardData.setData('text/html', div.innerHTML);
24+
} else if (supportNavigatorClipboard) {
25+
const clipboardItemData = {
26+
'text/html': div.innerHTML,
27+
};
28+
const clipboardItem = new ClipboardItem(clipboardItemData);
29+
navigator.clipboard.write([clipboardItem]).then(() => ({}));
30+
} else {
31+
document.body.appendChild(div);
32+
div.focus();
33+
document.execCommand('selectAll', false);
34+
document.execCommand('copy');
35+
document.body.removeChild(div);
36+
}
3737

38-
state.hiddenFocusElement?.focus({ preventScroll: true });
39-
event.preventDefault();
38+
state.hiddenFocusElement?.focus({ preventScroll: true });
39+
event.preventDefault();
4040
}

0 commit comments

Comments
 (0)