Working
This commit is contained in:
34
app/components/Editor/transforms.js
Normal file
34
app/components/Editor/transforms.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user