Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

30 lines
770 B
TypeScript

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);
};