Replacing text with bullet list

Hi, I am very new to ProseMirror. I was trying to get the following working “Replace typed text with bullet lists”

I was able to replace text with paragraphs:

import { schema } from "prosemirror-schema-basic"
import { EditorState } from "prosemirror-state"
import { EditorView } from "prosemirror-view"
import './style.css';


let state = EditorState.create({ schema })

let view = new EditorView(document.body, {
    state,
    dispatchTransaction(transaction) {

        let n = schema.node("paragraph")
        transaction.selection.replaceWith(transaction, n)
        let newState = view.state.apply(transaction)
        view.updateState(newState)
    }
})

window.view = view;

I want to use a “bullet_list” type of node instead of paragraph. I was wondering if this possible?

Firstly, dispatchTransaction should not change the transaction it gets. You can add new transactions (first apply the argument, then apply your own transaction to the result) or entirely replace the transaction you get, but a dispatched transaction should not be further modified, because it may hold metadata that apply precisely to the changes inside of it, and thing like undo will break if its transaction is changed before it is applied. You can also use a plugin with an appendTransaction method for something like that.

Secondly, I’m not sure replacing the selection with an empty paragraph on every transaction is ever a useful thing to do. Maybe you’re looking for the wrapInList command?