UNPKG

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