<commit_before>import {setBlockType, wrapIn, toggleMark} from "prosemirror-commands"
import {wrapInList} from "prosemirror-schema-list"
import {undo, redo, undoDepth, redoDepth} from "prosemirror-history"

import {CitationDialog, FigureDialog, LinkDialog, MathDialog} from "../../dialogs"
import {READ_ONLY_ROLES, COMMENT_ONLY_ROLES} from "../.."
import {randomHeadingId, randomAnchorId} from "../../../schema/common"


let setHeadlineBlock = function(editor, level) {
    let block = editor.currentView.state.schema.nodes['heading'],
        attrs = {level}

    if (
        editor.currentView.state.selection.$from.parent &&
        editor.currentView.state.selection.$from.parent.attrs &&
        editor.currentView.state.selection.$from.parent.attrs.id &&
        editor.currentView.state.selection.$from.parent.attrs.id.length
    ) {
        attrs.id = editor.currentView.state.selection.$from.parent.attrs.id
    } else {
        attrs.id = randomHeadingId()
    }

    let command = setBlockType(block, attrs)
    command(editor.currentView.state, tr => editor.currentView.dispatch(tr))
}


const PART_LABELS = {
    'title': gettext('Title'),
    'subtitle': gettext('Subtitle'),
    'authors': gettext('Authors'),
    'abstract': gettext('Abstract'),
    'keywords': gettext('Keywords'),
    'body': gettext('Body')
}

const BLOCK_LABELS = {
    'paragraph': gettext('Normal Text'),
    'heading_1': gettext('1st Heading'),
    'heading_2': gettext('2nd Heading'),
    'heading_3': gettext('3rd Heading'),
    'heading_4': gettext('4th Heading'),
    'heading_5': gettext('5th Heading'),
    'heading_6': gettext('6th Heading'),
    'code_block': gettext('Code'),
    'figure': gettext('Figure')
}

export const TEXT_ONLY_PARTS = ['title', 'subtitle', 'authors', 'keywords']

export let toolbarModel = {
    openMore: false, // whether 'more' menu is opened.
    content: [
        {
            type: 'button',
            title: gettext('Open/close header menu'),
            icon: editor => {
                if (editor.menu.headerbarModel.open) {
                    return 'angle-double-up'
                } else {
                    return 'angle-double-down'
                }
            },
            action: editor => {
                editor.menu.headerbarModel.open = !editor.menu.headerbarModel.open
                if (editor.menu.headerView) {
                    editor.menu.headerView.update()
                }
            },
            class: editor => {
                if (editor.menu.headerbarModel.open) {
                    return 'no-border'
                } else {
                    return 'no-border header-closed'
                }
            }
        },
        {
            type: 'info',
            show: editor => {
                if (editor.currentView !== editor.view) {
                    return gettext('Footnote')
                } else if (
                    editor.currentView.state.selection.$anchor.node(2) &&
                    editor.currentView.state.selection.$anchor.node(2) === editor.currentView.state.selection.$head.node(2)
                ) {
                    return PART_LABELS[editor.currentView.state.selection.$anchor.node(2).type.name]
                } else {
                    return ''
                }
            }

        },
        {
            type: 'dropdown',
            show: editor => {
                if (
                    editor.currentView.state.selection.$anchor.node(2) &&
                    TEXT_ONLY_PARTS.includes(
                        editor.currentView.state.selection.$anchor.node(2).type.name
                    )
                ) {
                    return ''
                }
                if (
                    editor.currentView.state.selection.jsonID === 'node' &&
                    editor.currentView.state.selection.node.isBlock
                ) {
                    let selectedNode = editor.currentView.state.selection.node
                    return BLOCK_LABELS[
                        selectedNode.type.name === 'heading' ?
                        `${selectedNode.type.name}_${selectedNode.attrs.level}` :
                        selectedNode.type.name
                    ]
                }
                let startElement = editor.currentView.state.selection.$anchor.parent,
                    endElement = editor.currentView.state.selection.$head.parent
                if (!startElement || !endElement) {
                    return ''
                } else if (startElement === endElement) {
                    let blockNodeType = startElement.type.name === 'heading' ?
                        `${startElement.type.name}_${startElement.attrs.level}` :
                        startElement.type.name
                    return BLOCK_LABELS[blockNodeType] ? BLOCK_LABELS[blockNodeType] : ''
                } else {
                    let blockNodeType = true
                    editor.currentView.state.doc.nodesBetween(
                        editor.currentView.state.selection.from,
                        editor.currentView.state.selection.to,
                        (node, pos, parent) => {
                            if (node.isTextblock) {
                                let nextBlockNodeType = node.type.name === 'heading' ?
                                    `${node.type.name}_${node.attrs.level}` :
                                    node.type.name
                                if (blockNodeType === true) {
                                    blockNodeType = nextBlockNodeType
                                }
                                if (blockNodeType !== nextBlockNodeType) {
                                    blockNodeType = false
                                }
                            }
                        }
                    )

                    if (blockNodeType) {
                        return BLOCK_LABELS[blockNodeType] ? BLOCK_LABELS[blockNodeType] : ''
                    } else {
                        return ''
                    }
                }

            },
            disabled: editor =>
                    READ_ONLY_ROLES.includes(editor.docInfo.access_rights) ||
                    COMMENT_ONLY_ROLES.includes(editor.docInfo.access_rights) ||
                    (
                        editor.currentView.state.selection.$anchor.node(2) &&
                        TEXT_ONLY_PARTS.includes(
                            editor.currentView.state.selection.$anchor.node(2).type.name
                        )
                    ) || (
                        editor.currentView.state.selection.jsonID === 'node' &&
                        editor.currentView.state.selection.node.isBlock &&
                        !editor.currentView.state.selection.node.isTextblock
                    ) ||
                        editor.currentView.state.selection.jsonID === 'gapcursor'
                    ,
            content: [
                {
                    title: BLOCK_LABELS['paragraph'],
                    action: editor => {
                        let block = editor.currentView.state.schema.nodes['paragraph']

                        let command = setBlockType(block)
                        command(editor.currentView.state, tr => editor.currentView.dispatch(tr))
                    }
                },
                {<commit_msg>temporarily turn off check for comment-only changes for commentators<commit_after>import {setBlockType, wrapIn, toggleMark} from "prosemirror-commands"
import {wrapInList} from "prosemirror-schema-list"
import {undo, redo, undoDepth, redoDepth} from "prosemirror-history"

import {CitationDialog, FigureDialog, LinkDialog, MathDialog} from "../../dialogs"
import {READ_ONLY_ROLES, COMMENT_ONLY_ROLES} from "../.."
import {randomHeadingId, randomAnchorId} from "../../../schema/common"


let setHeadlineBlock = function(editor, level) {
    let block = editor.currentView.state.schema.nodes['heading'],
        attrs = {level}

    if (
        editor.currentView.state.selection.$from.parent &&
        editor.currentView.state.selection.$from.parent.attrs &&
        editor.currentView.state.selection.$from.parent.attrs.id &&
        editor.currentView.state.selection.$from.parent.attrs.id.length
    ) {
        attrs.id = editor.currentView.state.selection.$from.parent.attrs.id
    } else {
        attrs.id = randomHeadingId()
    }

    let command = setBlockType(block, attrs)
    command(editor.currentView.state, tr => editor.currentView.dispatch(tr))
}


const PART_LABELS = {
    'title': gettext('Title'),
    'subtitle': gettext('Subtitle'),
    'authors': gettext('Authors'),
    'abstract': gettext('Abstract'),
    'keywords': gettext('Keywords'),
    'body': gettext('Body')
}

const BLOCK_LABELS = {
    'paragraph': gettext('Normal Text'),
    'heading_1': gettext('1st Heading'),
    'heading_2': gettext('2nd Heading'),
    'heading_3': gettext('3rd Heading'),
    'heading_4': gettext('4th Heading'),
    'heading_5': gettext('5th Heading'),
    'heading_6': gettext('6th Heading'),
    'code_block': gettext('Code'),
    'figure': gettext('Figure')
}

export const TEXT_ONLY_PARTS = ['title', 'subtitle', 'authors', 'keywords']

export let toolbarModel = {
    openMore: false, // whether 'more' menu is opened.
    content: [
        {
            type: 'button',
            title: gettext('Open/close header menu'),
            icon: editor => {
                if (editor.menu.headerbarModel.open) {
                    return 'angle-double-up'
                } else {
                    return 'angle-double-down'
                }
            },
            action: editor => {
                editor.menu.headerbarModel.open = !editor.menu.headerbarModel.open
                if (editor.menu.headerView) {
                    editor.menu.headerView.update()
                }
            },
            class: editor => {
                if (editor.menu.headerbarModel.open) {
                    return 'no-border'
                } else {
                    return 'no-border header-closed'
                }
            }
        },
        {
            type: 'info',
            show: editor => {
                if (editor.currentView !== editor.view) {
                    return gettext('Footnote')
                } else if (
                    editor.currentView.state.selection.$anchor.node(2) &&
                    editor.currentView.state.selection.$anchor.node(2) === editor.currentView.state.selection.$head.node(2)
                ) {
                    return PART_LABELS[editor.currentView.state.selection.$anchor.node(2).type.name]
                } else {
                    return ''
                }
            }

        },
        {
            type: 'dropdown',
            show: editor => {
                if (
                    editor.currentView.state.selection.$anchor.node(2) &&
                    TEXT_ONLY_PARTS.includes(
                        editor.currentView.state.selection.$anchor.node(2).type.name
                    )
                ) {
                    return ''
                }
                if (
                    editor.currentView.state.selection.jsonID === 'node' &&
                    editor.currentView.state.selection.node.isBlock
                ) {
                    let selectedNode = editor.currentView.state.selection.node
                    return BLOCK_LABELS[
                        selectedNode.type.name === 'heading' ?
                        `${selectedNode.type.name}_${selectedNode.attrs.level}` :
                        selectedNode.type.name
                    ]
                }
                let startElement = editor.currentView.state.selection.$anchor.parent,
                    endElement = editor.currentView.state.selection.$head.parent
                if (!startElement || !endElement) {
                    return ''
                } else if (startElement === endElement) {
                    let blockNodeType = startElement.type.name === 'heading' ?
                        `${startElement.type.name}_${startElement.attrs.level}` :
                        startElement.type.name
                    return BLOCK_LABELS[blockNodeType] ? BLOCK_LABELS[blockNodeType] : ''
                } else {
                    let blockNodeType = true
                    editor.currentView.state.doc.nodesBetween(
                        editor.currentView.state.selection.from,
                        editor.currentView.state.selection.to,
                        (node, pos, parent) => {
                            if (node.isTextblock) {
                                let nextBlockNodeType = node.type.name === 'heading' ?
                                    `${node.type.name}_${node.attrs.level}` :
                                    node.type.name
                                if (blockNodeType === true) {
                                    blockNodeType = nextBlockNodeType
                                }
                                if (blockNodeType !== nextBlockNodeType) {
                                    blockNodeType = false
                                }
                            }
                        }
                    )

                    if (blockNodeType) {
                        return BLOCK_LABELS[blockNodeType] ? BLOCK_LABELS[blockNodeType] : ''
                    } else {
                        return ''
                    }
                }

            },
            disabled: editor =>
                    READ_ONLY_ROLES.includes(editor.docInfo.access_rights) ||
                    COMMENT_ONLY_ROLES.includes(editor.docInfo.access_rights) ||
                    (
                        editor.currentView.state.selection.$anchor.node(2) &&
                        TEXT_ONLY_PARTS.includes(
                            editor.currentView.state.selection.$anchor.node(2).type.name
                        )
                    ) || (
                        editor.currentView.state.selection.jsonID === 'node' &&
                        editor.currentView.state.selection.node.isBlock &&
                        !editor.currentView.state.selection.node.isTextblock
                    ) ||
                        editor.currentView.state.selection.jsonID === 'gapcursor',
            content: [
                {
                    title: BLOCK_LABELS['paragraph'],
                    action: editor => {
                        let block = editor.currentView.state.schema.nodes['paragraph']

                        let command = setBlockType(block)
                        command(editor.currentView.state, tr => editor.currentView.dispatch(tr))
                    }
                },
                {
{'fraction_non_alphanumeric': 0.11111861659011078, 'fraction_numerical': 0.0027019724398811133, 'mean_word_length': 1.320896692271516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4738468', 'n_tokens_mistral': 3784, 'n_tokens_neox': 3575, 'n_words': 556}