This commit is contained in:
Tom Moor
2017-11-05 22:48:31 -08:00
parent 14326d89f2
commit 51bc705488
10 changed files with 252 additions and 203 deletions

View File

@ -0,0 +1,34 @@
// @flow
import EditList from './plugins/EditList';
import type { State } from './types';
const { transforms } = EditList;
type Options = {
type: string | Object,
wrapper?: string | Object,
append?: string | Object,
};
export function splitAndInsertBlock(state: State, options: Options) {
const { type, wrapper, append } = options;
let transform = state.transform();
const { document } = state;
const parent = document.getParent(state.startBlock.key);
// lists get some special treatment
if (parent && parent.type === 'list-item') {
transform = transforms.unwrapList(
transforms
.splitListItem(transform.collapseToStart())
.collapseToEndOfPreviousBlock()
);
}
transform = transform.insertBlock(type);
if (wrapper) transform = transform.wrapBlock(wrapper);
if (append) transform = transform.insertBlock(append);
return transform;
}