Ejemplo n.º 1
0
export const getActiveAlignment = (state): AlignmentState | undefined => {
    const node = findParentNodeOfType([state.schema.nodes.paragraph, state.schema.nodes.heading])(
        state.selection,
    )
    const getMark =
        node && node.node.marks.filter(mark => mark.type === state.schema.marks.alignment)[0]

    return (getMark && getMark.attrs.align) || "start"
}
Ejemplo n.º 2
0
                update: (view: EditorView, prevState: EditorState) => {
                    const {
                        state: {
                            selection,
                            schema: {
                                // tslint:disable-next-line:no-shadowed-variable
                                nodes: { codeBlock },
                            },
                        },
                    } = view
                    const pluginState = getPluginState(view.state)
                    const parentDOM = findParentDomRefOfType(codeBlock, view.domAtPos.bind(view))(
                        selection,
                    )
                    const parent = findParentNodeOfType(codeBlock)(selection)
                    let language

                    if (parent) {
                        language = parent.node.attrs.language
                    }

                    if (parentDOM !== pluginState.element || pluginState.language !== language) {
                        const newState: CodeBlockState = {
                            element: parentDOM as HTMLElement,
                            language,
                            toolbarVisible: !!parent,
                        }
                        setPluginState(newState)(view.state, view.dispatch)
                        return true
                    }

                    /** Plugin dispatch needed to reposition the toolbar */
                    dispatch(pluginKey, {
                        ...pluginState,
                        language,
                    })
                },