File size: 770 Bytes
f56a29b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import type { EditorView } from 'prosemirror-view';
import { isList } from '../utils';
type Style = Record<string, string>;
export const setListStyle = (view: EditorView, style: Style | Style[]) => {
const { state } = view;
const { schema, selection } = state;
const tr = state.tr.setSelection(selection);
const { doc } = tr;
if (!doc) return tr;
const { from, to } = selection;
doc.nodesBetween(from, to, (node, pos) => {
if (isList(node, schema)) {
if (from - 3 <= pos && to + 3 >= pos + node.nodeSize) {
const styles = Array.isArray(style) ? style : [style];
for (const style of styles) {
tr.setNodeAttribute(pos, style.key, style.value);
}
}
}
return false;
});
view.dispatch(tr);
};
|