Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function liftToOuterList(
tr: Transform,
itemType: NodeType,
range: NodeRange,
) {
let end = range.end;
let endOfList = range.$to.end(range.depth);
if (end < endOfList) {
// There are siblings after the lifted items, which must become
// children of the last item
const frag = Fragment.from(itemType.create(null, range.parent.copy()));
const slice = new Slice(frag, 1, 0);
const step = new ReplaceAroundStep(
end - 1,
endOfList,
end,
endOfList,
slice,
1,
true,
);
tr = tr.step(step);
range = new NodeRange(
tr.doc.resolve(range.$from.pos),
tr.doc.resolve(endOfList),
range.depth,
);
}
return tr.lift(range, liftTarget(range));
tr = tr.delete(pos - 1, pos + 1);
}
let $start = tr.doc.resolve(range.start);
let item = $start.nodeAfter;
let atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount
let parent = $start.node(-1), indexBefore = $start.index(-1)
if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1,
item.content.append(atEnd ? Fragment.empty : Fragment.from(list)))) {
return tr;
}
let start = $start.pos, end = start + item.nodeSize
// Strip off the surrounding list. At the sides where we're not at
// the end of the list, the existing list is closed. At sides where
// this is the end, it is overwritten to its end.
tr = tr.step(new ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1,
new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty)))
.append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))),
atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1))
return tr;
}
private static liftToOuterList(
state: EditorState,
dispatch: DispatchFunc,
itemType: NodeType,
range: NodeRange
) {
const tr = state.tr,
end = range.end,
endOfList = range.$to.end(range.depth);
if (end < endOfList) {
// There are siblings after the lifted items, which must become
// children of the last item
tr.step(
new ReplaceAroundStep(
end - 1,
endOfList,
end,
endOfList,
new Slice(Fragment.from(itemType.create(undefined, range.parent.copy())), 1, 0),
1,
true
)
);
range = new NodeRange(
tr.doc.resolve(range.$from.pos),
tr.doc.resolve(endOfList),
range.depth
);
}
dispatch(tr.lift(range, liftTarget(range)!).scrollIntoView());
};
let nestedBefore =
nodeBefore.lastChild &&
nodeBefore.lastChild.type == parent.type;
let inner = Fragment.from(nestedBefore ? itemType.create() : null);
let slice = new Slice(
Fragment.from(itemType.create(null, Fragment.from(parent.copy(inner)))),
nestedBefore ? 3 : 1,
0,
);
let before = range.start;
let after = range.end
tr = tr.step(
new ReplaceAroundStep(
before - (nestedBefore ? 3 : 1),
after,
before,
after,
slice,
1,
true,
),
);
return tr;
}
wrappers: any,
doJoin: boolean,
nodeType: NodeType,
): Transform {
if (!wrappers) {
return tr;
}
let content = Fragment.empty;
for (let i = wrappers.length - 1; i >= 0; i--) {
content = Fragment.from(
wrappers[i].type.create(wrappers[i].attrs, content),
);
}
tr = tr.step(
new ReplaceAroundStep(range.start - (doJoin ? 2 : 0),
range.end,
range.start,
range.end,
new Slice(content, 0, 0), wrappers.length, true),
);
let found = 0
for (let i = 0; i < wrappers.length; i++) {
if (wrappers[i].type == nodeType) {
found = i + 1;
}
};
let splitDepth = wrappers.length - found;
let splitPos = range.start + wrappers.length - (doJoin ? 2 : 0);
let parent = range.parent;
function deleteBarrier(state, $cut, dispatch) {
let before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match
if (before.type.spec.isolating || after.type.spec.isolating) return false
if (joinMaybeClear(state, $cut, dispatch)) return true
if ($cut.parent.canReplace($cut.index(), $cut.index() + 1) &&
(conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) &&
match.matchType(conn[0] || after.type).validEnd) {
if (dispatch) {
let end = $cut.pos + after.nodeSize, wrap = Fragment.empty
for (let i = conn.length - 1; i >= 0; i--)
wrap = Fragment.from(conn[i].create(null, wrap))
wrap = Fragment.from(before.copy(wrap))
let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new Slice(wrap, 1, 0), conn.length, true))
let joinAt = end + 2 * conn.length
if (canJoin(tr.doc, joinAt)) tr.join(joinAt)
dispatch(tr.scrollIntoView())
}
return true
}
let selAfter = Selection.findFrom($cut, 1)
let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range)
if (target != null && target >= $cut.depth) {
if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
return true
}
return false
}