
// TODO import Raven and log messages


const hasClipboardAPI = () => {
    let result = false;

    try {
        result = document.queryCommandSupported &&
                 document.queryCommandSupported('copy');
    } catch (e) { }
    return result;
};

/**
 * Safely copies the contents of `element` argument to the clipboard.
 *
 * Uses approach seen in clipboard.js and copy-to-clipboard. Not all
 * elements will have a `select()` method, so it uses the range &
 * selection objects from `document` to achieve the text copy.
 *
 * @param element - DOM node to copy
 */
const copyElement = (element) => {
    let copied = false;
    if (hasClipboardAPI()) {
        let range = document.createRange(),
            selection = document.getSelection();

        try {
            // avoid potential 'Discontiguous selection is not supported'
            // error that is generated by an existing selection followed
            // by the "addRange" call below
            selection.removeAllRanges();

            // done for "none" text area or text field elements
            range.selectNode(element);
            selection.addRange(range);

            // this call the largest candidate for creating
            // an error to catch - we could slim it down
            // to just this call
            copied = document.execCommand('copy');

            // clean up selections ...
            selection.removeAllRanges();
        } catch (e) {

        }
    }

    return copied;
};

export { copyElement, hasClipboardAPI };


// TODO import Raven and log messages


const hasClipboardAPI = () => {
    let result = false;

    try {
        result = document.queryCommandSupported &&
                 document.queryCommandSupported('copy');
    } catch (e) { }
    return result;
};

/**
 * Safely copies the contents of `element` argument to the clipboard.
 *
 * Uses approach seen in clipboard.js and copy-to-clipboard. Not all
 * elements will have a `select()` method, so it uses the range &
 * selection objects from `document` to achieve the text copy.
 *
 * @param element - DOM node to copy
 */
const copyElement = (element) => {
    let copied = false;
    if (hasClipboardAPI()) {
        let range = document.createRange(),
            selection = document.getSelection();

        try {
            // avoid potential 'Discontiguous selection is not supported'
            // error that is generated by an existing selection followed
            // by the "addRange" call below
            selection.removeAllRanges();

            // done for "non"-textarea or textfield elements
            // - text DOM elements will have a `select()` method
            range.selectNode(element);
            selection.addRange(range);

            // this call the largest candidate for creating
            // an error to catch - we could slim it down
            // to just this call
            copied = document.execCommand('copy');

            // clean up selections ...
            selection.removeAllRanges();
        } catch (e) {

        }
    }

    return copied;
};

export { copyElement, hasClipboardAPI };

Clarify comment _phrasing_