UNPKG

879 BJavaScriptView Raw
1/* eslint-disable new-cap */
2import EditList from "slate-edit-list";
3import {
4 OL_LIST,
5 UL_LIST,
6 LIST_ITEM,
7 PARAGRAPH
8} from "@canner/slate-constant/lib/blocks";
9
10export const DEFAULT = {
11 types: [OL_LIST, UL_LIST],
12 typeItem: LIST_ITEM,
13 typeDefault: PARAGRAPH,
14 ordered: true
15};
16
17export default (change, opt = DEFAULT) => {
18 const options = Object.assign({}, DEFAULT, opt);
19 const { types, ordered } = options;
20 const { utils, changes } = EditList(options);
21 const currentType = ordered ? types[0] : types[1];
22 let newChange;
23
24 if (utils.isSelectionInList(change.value)) {
25 if (utils.getCurrentList(change.value).type !== currentType) {
26 newChange = changes.wrapInList(change, currentType);
27 } else {
28 newChange = changes.unwrapList(change);
29 }
30 } else {
31 newChange = changes.wrapInList(change, currentType);
32 }
33
34 return newChange;
35};