Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-flat-list

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-flat-list - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

./dist/prosemirror-flat-list.js

206

dist/prosemirror-flat-list.js

@@ -6,3 +6,3 @@ // src/commands/dedent-list.ts

// src/utils/auto-join-list.ts
import { canJoin } from "prosemirror-transform";
import { canJoin, canSplit } from "prosemirror-transform";

@@ -45,2 +45,3 @@ // src/utils/parse-integer.ts

checked: checkbox.hasAttribute("checked")
// ...extra.parse(element),
};

@@ -52,2 +53,3 @@ }

checked: element.hasAttribute("data-checked")
// ...extra.parse(element),
};

@@ -59,2 +61,3 @@ }

collapsed: element.hasAttribute("data-list-collapsed")
// ...extra.parse(element),
};

@@ -65,2 +68,3 @@ }

type: "bullet"
// ...extra.parse(element),
};

@@ -74,5 +78,7 @@ }

type: "ordered"
// ...extra.parse(element),
};
}
}
// ...(override.parseDOM ?? []),
];

@@ -102,2 +108,4 @@ }

class: "list-marker list-marker-click-target",
// Set `contenteditable` to `false` so that the cursor won't be
// moved into the mark container when clicking on it.
contenteditable: "false"

@@ -198,15 +206,19 @@ },

// src/utils/auto-join-list.ts
function getTransactionRanges(tr) {
function* getTransactionRanges(tr) {
const ranges = [];
for (const map of tr.mapping.maps) {
for (let i = 0; i < ranges.length; i++) {
ranges[i] = map.map(ranges[i]);
let i = 0;
while (true) {
for (; i < tr.mapping.maps.length; i++) {
const map = tr.mapping.maps[i];
for (let j = 0; j < ranges.length; j++) {
ranges[j] = map.map(ranges[j]);
}
map.forEach(
(_oldStart, _oldEnd, newStart, newEnd) => ranges.push(newStart, newEnd)
);
}
map.forEach(
(_oldStart, _oldEnd, newStart, newEnd) => ranges.push(newStart, newEnd)
);
yield ranges;
}
return ranges;
}
function getJoinableBoundaries(positions, doc, isJoinable) {
function findBoundaries(positions, doc, prediction) {
const boundaries = /* @__PURE__ */ new Set();

@@ -230,3 +242,3 @@ const joinable = [];

continue;
if (before.type === after.type && isJoinable(before, after)) {
if (prediction(before, after, parent, index)) {
joinable.push(boundary);

@@ -236,11 +248,16 @@ }

}
return joinable;
return joinable.sort((a, b) => b - a);
}
function isListJoinable(before, after) {
return isListNode(before) && isListNode(after) && isListNode(after.firstChild);
}
function isListSplitable(before, after, parent, index) {
if (index === 1 && isListNode(parent) && isListNode(before) && !isListNode(after)) {
return true;
}
return false;
}
function autoJoinList(tr) {
const isListJoinable = (before, after) => {
return isListNode(before) && isListNode(after) && isListNode(after.firstChild);
};
const positions = getTransactionRanges(tr);
const joinable = getJoinableBoundaries(positions, tr.doc, isListJoinable);
joinable.sort((a, b) => b - a);
const ranges = getTransactionRanges(tr);
const joinable = findBoundaries(ranges.next().value, tr.doc, isListJoinable);
for (const pos of joinable) {

@@ -251,2 +268,8 @@ if (canJoin(tr.doc, pos)) {

}
const splitable = findBoundaries(ranges.next().value, tr.doc, isListSplitable);
for (const pos of splitable) {
if (canSplit(tr.doc, pos)) {
tr.split(pos);
}
}
}

@@ -353,4 +376,6 @@

if (dedentRange(range, tr)) {
autoJoinList(tr);
dispatch == null ? void 0 : dispatch(tr);
if (dispatch) {
autoJoinList(tr);
dispatch(tr);
}
return true;

@@ -435,14 +460,28 @@ }

const endOfParent = $to.end(depth);
if (end < endOfParent && isListNode(parent.maybeChild(endIndex - 1))) {
tr.step(
new ReplaceAroundStep(
end - 1,
endOfParent,
end,
endOfParent,
new Slice(Fragment.from(listType.create(null)), 1, 0),
0,
true
)
);
if (end < endOfParent) {
if (isListNode(parent.maybeChild(endIndex - 1))) {
tr.step(
new ReplaceAroundStep(
end - 1,
endOfParent,
end,
endOfParent,
new Slice(Fragment.from(listType.create(null)), 1, 0),
0,
true
)
);
} else {
tr.step(
new ReplaceAroundStep(
end,
endOfParent,
end,
endOfParent,
new Slice(Fragment.from(listType.create(null)), 0, 0),
1,
true
)
);
}
}

@@ -527,4 +566,6 @@ }

if (indentRange(range, tr)) {
autoJoinList(tr);
dispatch == null ? void 0 : dispatch(tr);
if (dispatch) {
autoJoinList(tr);
dispatch(tr);
}
return true;

@@ -621,52 +662,63 @@ }

const moveList = (state, dispatch) => {
const { $from, $to } = state.selection;
const range = findListsRange($from, $to);
if (!range)
return false;
const { parent, depth, startIndex, endIndex } = range;
if (direction === "up") {
if (startIndex > 0) {
const before = cutByIndex(parent.content, startIndex - 1, startIndex);
const selected = cutByIndex(parent.content, startIndex, endIndex);
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) {
if (dispatch) {
const tr = state.tr;
tr.insert($from.posAtIndex(endIndex, depth), before);
tr.delete(
$from.posAtIndex(startIndex - 1, depth),
$from.posAtIndex(startIndex, depth)
);
dispatch(tr);
}
return true;
} else {
return false;
const tr = state.tr;
if (doMoveList(state.tr, direction, true, !!dispatch)) {
if (dispatch) {
autoJoinList(tr);
dispatch(tr);
}
return true;
}
return false;
};
return moveList;
}
function doMoveList(tr, direction, canDedent, dispatch) {
const { $from, $to } = tr.selection;
const range = findListsRange($from, $to);
if (!range)
return false;
const { parent, depth, startIndex, endIndex } = range;
if (direction === "up") {
if (startIndex >= 2 || startIndex === 1 && isListNode(parent.child(0))) {
const before = cutByIndex(parent.content, startIndex - 1, startIndex);
const selected = cutByIndex(parent.content, startIndex, endIndex);
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) {
if (dispatch) {
tr.insert($from.posAtIndex(endIndex, depth), before);
tr.delete(
$from.posAtIndex(startIndex - 1, depth),
$from.posAtIndex(startIndex, depth)
);
}
return true;
} else {
return false;
}
} else if (canDedent && isListNode(parent)) {
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch);
} else {
if (endIndex < parent.childCount) {
const selected = cutByIndex(parent.content, startIndex, endIndex);
const after = cutByIndex(parent.content, endIndex, endIndex + 1);
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) {
if (dispatch) {
const tr = state.tr;
tr.delete(
$from.posAtIndex(endIndex, depth),
$from.posAtIndex(endIndex + 1, depth)
);
tr.insert($from.posAtIndex(startIndex, depth), after);
dispatch(tr);
}
return true;
} else {
return false;
return false;
}
} else {
if (endIndex < parent.childCount) {
const selected = cutByIndex(parent.content, startIndex, endIndex);
const after = cutByIndex(parent.content, endIndex, endIndex + 1);
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) {
if (dispatch) {
tr.delete(
$from.posAtIndex(endIndex, depth),
$from.posAtIndex(endIndex + 1, depth)
);
tr.insert($from.posAtIndex(startIndex, depth), after);
}
return true;
} else {
return false;
}
} else if (canDedent && isListNode(parent)) {
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch);
} else {
return false;
}
};
return moveList;
}
}

@@ -677,3 +729,3 @@

import { Selection } from "prosemirror-state";
import { canSplit } from "prosemirror-transform";
import { canSplit as canSplit2 } from "prosemirror-transform";

@@ -764,2 +816,4 @@ // src/utils/is-block-node-selection.ts

attrs: {
// We don't want to inherit all list attributes (e.g. checked) except
// for the list type
type: attrs.type

@@ -770,3 +824,3 @@ }

];
if (!canSplit(tr.doc, $from.pos, 2, typesAfter)) {
if (!canSplit2(tr.doc, $from.pos, 2, typesAfter)) {
return false;

@@ -773,0 +827,0 @@ }

{
"name": "prosemirror-flat-list",
"type": "module",
"version": "0.0.14",
"version": "0.0.15",
"description": "",

@@ -48,8 +48,8 @@ "author": "ocavue <ocavue@gmail.com>",

"@types/dedent": "^0.7.0",
"@types/node": "^18.11.18",
"@vitest/coverage-c8": "^0.28.3",
"@types/node": "^18.13.0",
"@vitest/coverage-c8": "^0.28.5",
"dedent": "^0.7.0",
"jest-prosemirror": "^2.1.1",
"jest-remirror": "^2.1.3",
"jsdom": "^21.0.0",
"jsdom": "^21.1.0",
"npm-run-all": "^4.1.5",

@@ -65,7 +65,7 @@ "postcss": "^8.4.21",

"remirror": "^2.0.24",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"tsup": "^6.6.2",
"typescript": "^4.9.5",
"unified": "^10.1.2",
"vite": "^4.0.4",
"vitest": "^0.27.2"
"vite": "^4.1.1",
"vitest": "^0.28.5"
},

@@ -72,0 +72,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc