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.3.8 to 0.3.9

168

./dist/prosemirror-flat-list.js

@@ -241,2 +241,17 @@ // src/commands/dedent-list.ts

// src/utils/patch-command.ts
function patchCommand(patch) {
const withPatch = (command) => {
const patchedCommand = (state, dispatch, view) => {
return command(
state,
dispatch ? (tr) => dispatch(patch(tr)) : void 0,
view
);
};
return patchedCommand;
};
return withPatch;
}
// src/utils/auto-fix-list.ts

@@ -310,12 +325,3 @@ function* getTransactionRanges(tr) {

}
function withAutoFixList(command) {
const wrappedCommand = (state, dispatch, view) => {
return command(
state,
dispatch && ((tr) => dispatch(fixList(tr))),
view
);
};
return wrappedCommand;
}
var withAutoFixList = patchCommand(fixList);

@@ -412,2 +418,74 @@ // src/utils/block-boundary.ts

// src/commands/set-safe-selection.ts
import { TextSelection } from "prosemirror-state";
// src/utils/is-collapsed-list-node.ts
function isCollapsedListNode(node) {
return !!(isListNode(node) && node.attrs.collapsed);
}
// src/utils/set-node-attributes.ts
function setNodeAttributes(tr, pos, oldAttrs, newAttrs) {
let needUpdate = false;
for (const key of Object.keys(newAttrs)) {
if (newAttrs[key] !== oldAttrs[key]) {
tr.setNodeAttribute(pos, key, newAttrs[key]);
needUpdate = true;
}
}
return needUpdate;
}
// src/utils/set-list-attributes.ts
function setListAttributes(tr, pos, attrs) {
const $pos = tr.doc.resolve(pos);
const node = $pos.nodeAfter;
if (node && isListNode(node)) {
const oldAttrs = node.attrs;
const newAttrs = { ...oldAttrs, ...attrs };
return setNodeAttributes(tr, pos, oldAttrs, newAttrs);
}
return false;
}
// src/commands/set-safe-selection.ts
function moveOutOfCollapsed($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
const before = $pos.posAtIndex(1, depth);
const $before = $pos.doc.resolve(before);
return TextSelection.near($before, -1);
}
}
return null;
}
function setSafeSelection(tr) {
const { $from, $to, to } = tr.selection;
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to));
if (selection) {
tr.setSelection(selection);
}
return tr;
}
var withSafeSelection = patchCommand(setSafeSelection);
function getCollapsedPosition($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
return $pos.before(depth);
}
}
return null;
}
function setVisibleSelection(tr) {
var _a;
const { $from, $to, to } = tr.selection;
const pos = (_a = getCollapsedPosition($from, 0)) != null ? _a : getCollapsedPosition($to, $from.sharedDepth(to));
if (pos != null) {
tr.doc.resolve(pos);
setListAttributes(tr, pos, { collapsed: false });
}
return tr;
}
var withVisibleSelection = patchCommand(setVisibleSelection);
// src/commands/dedent-list.ts

@@ -428,3 +506,3 @@ function createDedentListCommand(options) {

};
return withAutoFixList(dedentListCommand);
return withVisibleSelection(withAutoFixList(dedentListCommand));
}

@@ -641,3 +719,3 @@ function dedentRange(range, tr, startBoundary, endBoundary) {

};
return withAutoFixList(indentListCommand);
return withVisibleSelection(withAutoFixList(indentListCommand));
}

@@ -722,3 +800,3 @@ function indentRange(range, tr, startBoundary, endBoundary) {

// src/commands/join-collapsed-backward.ts
import { TextSelection as TextSelection2 } from "prosemirror-state";
import { TextSelection as TextSelection3 } from "prosemirror-state";

@@ -735,3 +813,3 @@ // src/utils/at-textblock-start.ts

import { Slice as Slice3 } from "prosemirror-model";
import { TextSelection } from "prosemirror-state";
import { TextSelection as TextSelection2 } from "prosemirror-state";
import { replaceStep, ReplaceStep } from "prosemirror-transform";

@@ -762,3 +840,3 @@ function joinTextblocksAround(tr, $cut, dispatch) {

tr.step(step);
tr.setSelection(TextSelection.create(tr.doc, beforePos));
tr.setSelection(TextSelection2.create(tr.doc, beforePos));
dispatch(tr.scrollIntoView());

@@ -785,3 +863,3 @@ }

const $insert = tr.doc.resolve(insert);
tr.setSelection(TextSelection2.near($insert));
tr.setSelection(TextSelection3.near($insert));
if (joinTextblocksAround(tr, $insert, dispatch)) {

@@ -862,7 +940,2 @@ return true;

// src/utils/is-collapsed-list-node.ts
function isCollapsedListNode(node) {
return !!(isListNode(node) && node.attrs.collapsed);
}
// src/commands/protect-collapsed.ts

@@ -894,3 +967,3 @@ var protectCollapsed = (state, dispatch) => {

import { NodeRange as NodeRange5 } from "prosemirror-model";
import { Selection } from "prosemirror-state";
import { Selection as Selection2 } from "prosemirror-state";
import { canSplit as canSplit2 } from "prosemirror-transform";

@@ -985,3 +1058,3 @@

tr.insert(pos, createAndFill(listType, newAttrs));
tr.setSelection(Selection.near(tr.doc.resolve(pos)));
tr.setSelection(Selection2.near(tr.doc.resolve(pos)));
dispatch(tr.scrollIntoView());

@@ -1098,23 +1171,2 @@ }

// src/commands/set-safe-selection.ts
import { TextSelection as TextSelection3 } from "prosemirror-state";
function moveOutOfCollapsed($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
const before = $pos.posAtIndex(1, depth);
const $before = $pos.doc.resolve(before);
return TextSelection3.near($before, -1);
}
}
return null;
}
function setSafeSelection(tr) {
const { $from, $to, to } = tr.selection;
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to));
if (selection) {
tr.setSelection(selection);
}
return tr;
}
// src/commands/toggle-collapsed.ts

@@ -1152,16 +1204,2 @@ function createToggleCollapsedCommand({

import { findWrapping } from "prosemirror-transform";
// src/utils/set-node-attributes.ts
function setNodeAttributes(tr, pos, oldAttrs, newAttrs) {
let needUpdate = false;
for (const key of Object.keys(newAttrs)) {
if (newAttrs[key] !== oldAttrs[key]) {
tr.setNodeAttribute(pos, key, newAttrs[key]);
needUpdate = true;
}
}
return needUpdate;
}
// src/commands/wrap-in-list.ts
function createWrapInListCommand(getAttrs) {

@@ -1235,3 +1273,9 @@ const wrapInList = (state, dispatch) => {

const pos = view.posAtDOM(target, -10, -10);
const tr = view.state.tr;
return handleMouseDown(pos, onListClick)(view.state, view.dispatch);
}
return false;
}
function handleMouseDown(pos, onListClick) {
const mouseDown = (state, dispatch) => {
const tr = state.tr;
const $pos = tr.doc.resolve(pos);

@@ -1245,7 +1289,7 @@ const list = $pos.parent;

if (setNodeAttributes(tr, listPos, list.attrs, attrs)) {
view.dispatch(setSafeSelection(tr));
dispatch == null ? void 0 : dispatch(tr);
}
return true;
}
return false;
};
return withSafeSelection(mouseDown);
}

@@ -1252,0 +1296,0 @@ var defaultListClickHandler = (node) => {

@@ -241,2 +241,17 @@ // src/commands/dedent-list.ts

// src/utils/patch-command.ts
function patchCommand(patch) {
const withPatch = (command) => {
const patchedCommand = (state, dispatch, view) => {
return command(
state,
dispatch ? (tr) => dispatch(patch(tr)) : void 0,
view
);
};
return patchedCommand;
};
return withPatch;
}
// src/utils/auto-fix-list.ts

@@ -310,12 +325,3 @@ function* getTransactionRanges(tr) {

}
function withAutoFixList(command) {
const wrappedCommand = (state, dispatch, view) => {
return command(
state,
dispatch && ((tr) => dispatch(fixList(tr))),
view
);
};
return wrappedCommand;
}
var withAutoFixList = patchCommand(fixList);

@@ -412,2 +418,74 @@ // src/utils/block-boundary.ts

// src/commands/set-safe-selection.ts
import { TextSelection } from "prosemirror-state";
// src/utils/is-collapsed-list-node.ts
function isCollapsedListNode(node) {
return !!(isListNode(node) && node.attrs.collapsed);
}
// src/utils/set-node-attributes.ts
function setNodeAttributes(tr, pos, oldAttrs, newAttrs) {
let needUpdate = false;
for (const key of Object.keys(newAttrs)) {
if (newAttrs[key] !== oldAttrs[key]) {
tr.setNodeAttribute(pos, key, newAttrs[key]);
needUpdate = true;
}
}
return needUpdate;
}
// src/utils/set-list-attributes.ts
function setListAttributes(tr, pos, attrs) {
const $pos = tr.doc.resolve(pos);
const node = $pos.nodeAfter;
if (node && isListNode(node)) {
const oldAttrs = node.attrs;
const newAttrs = { ...oldAttrs, ...attrs };
return setNodeAttributes(tr, pos, oldAttrs, newAttrs);
}
return false;
}
// src/commands/set-safe-selection.ts
function moveOutOfCollapsed($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
const before = $pos.posAtIndex(1, depth);
const $before = $pos.doc.resolve(before);
return TextSelection.near($before, -1);
}
}
return null;
}
function setSafeSelection(tr) {
const { $from, $to, to } = tr.selection;
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to));
if (selection) {
tr.setSelection(selection);
}
return tr;
}
var withSafeSelection = patchCommand(setSafeSelection);
function getCollapsedPosition($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
return $pos.before(depth);
}
}
return null;
}
function setVisibleSelection(tr) {
var _a;
const { $from, $to, to } = tr.selection;
const pos = (_a = getCollapsedPosition($from, 0)) != null ? _a : getCollapsedPosition($to, $from.sharedDepth(to));
if (pos != null) {
tr.doc.resolve(pos);
setListAttributes(tr, pos, { collapsed: false });
}
return tr;
}
var withVisibleSelection = patchCommand(setVisibleSelection);
// src/commands/dedent-list.ts

@@ -428,3 +506,3 @@ function createDedentListCommand(options) {

};
return withAutoFixList(dedentListCommand);
return withVisibleSelection(withAutoFixList(dedentListCommand));
}

@@ -641,3 +719,3 @@ function dedentRange(range, tr, startBoundary, endBoundary) {

};
return withAutoFixList(indentListCommand);
return withVisibleSelection(withAutoFixList(indentListCommand));
}

@@ -722,3 +800,3 @@ function indentRange(range, tr, startBoundary, endBoundary) {

// src/commands/join-collapsed-backward.ts
import { TextSelection as TextSelection2 } from "prosemirror-state";
import { TextSelection as TextSelection3 } from "prosemirror-state";

@@ -735,3 +813,3 @@ // src/utils/at-textblock-start.ts

import { Slice as Slice3 } from "prosemirror-model";
import { TextSelection } from "prosemirror-state";
import { TextSelection as TextSelection2 } from "prosemirror-state";
import { replaceStep, ReplaceStep } from "prosemirror-transform";

@@ -762,3 +840,3 @@ function joinTextblocksAround(tr, $cut, dispatch) {

tr.step(step);
tr.setSelection(TextSelection.create(tr.doc, beforePos));
tr.setSelection(TextSelection2.create(tr.doc, beforePos));
dispatch(tr.scrollIntoView());

@@ -785,3 +863,3 @@ }

const $insert = tr.doc.resolve(insert);
tr.setSelection(TextSelection2.near($insert));
tr.setSelection(TextSelection3.near($insert));
if (joinTextblocksAround(tr, $insert, dispatch)) {

@@ -862,7 +940,2 @@ return true;

// src/utils/is-collapsed-list-node.ts
function isCollapsedListNode(node) {
return !!(isListNode(node) && node.attrs.collapsed);
}
// src/commands/protect-collapsed.ts

@@ -894,3 +967,3 @@ var protectCollapsed = (state, dispatch) => {

import { NodeRange as NodeRange5 } from "prosemirror-model";
import { Selection } from "prosemirror-state";
import { Selection as Selection2 } from "prosemirror-state";
import { canSplit as canSplit2 } from "prosemirror-transform";

@@ -985,3 +1058,3 @@

tr.insert(pos, createAndFill(listType, newAttrs));
tr.setSelection(Selection.near(tr.doc.resolve(pos)));
tr.setSelection(Selection2.near(tr.doc.resolve(pos)));
dispatch(tr.scrollIntoView());

@@ -1098,23 +1171,2 @@ }

// src/commands/set-safe-selection.ts
import { TextSelection as TextSelection3 } from "prosemirror-state";
function moveOutOfCollapsed($pos, minDepth) {
for (let depth = minDepth; depth <= $pos.depth; depth++) {
if (isCollapsedListNode($pos.node(depth)) && $pos.index(depth) >= 1) {
const before = $pos.posAtIndex(1, depth);
const $before = $pos.doc.resolve(before);
return TextSelection3.near($before, -1);
}
}
return null;
}
function setSafeSelection(tr) {
const { $from, $to, to } = tr.selection;
const selection = moveOutOfCollapsed($from, 0) || moveOutOfCollapsed($to, $from.sharedDepth(to));
if (selection) {
tr.setSelection(selection);
}
return tr;
}
// src/commands/toggle-collapsed.ts

@@ -1152,16 +1204,2 @@ function createToggleCollapsedCommand({

import { findWrapping } from "prosemirror-transform";
// src/utils/set-node-attributes.ts
function setNodeAttributes(tr, pos, oldAttrs, newAttrs) {
let needUpdate = false;
for (const key of Object.keys(newAttrs)) {
if (newAttrs[key] !== oldAttrs[key]) {
tr.setNodeAttribute(pos, key, newAttrs[key]);
needUpdate = true;
}
}
return needUpdate;
}
// src/commands/wrap-in-list.ts
function createWrapInListCommand(getAttrs) {

@@ -1235,3 +1273,9 @@ const wrapInList = (state, dispatch) => {

const pos = view.posAtDOM(target, -10, -10);
const tr = view.state.tr;
return handleMouseDown(pos, onListClick)(view.state, view.dispatch);
}
return false;
}
function handleMouseDown(pos, onListClick) {
const mouseDown = (state, dispatch) => {
const tr = state.tr;
const $pos = tr.doc.resolve(pos);

@@ -1245,7 +1289,7 @@ const list = $pos.parent;

if (setNodeAttributes(tr, listPos, list.attrs, attrs)) {
view.dispatch(setSafeSelection(tr));
dispatch == null ? void 0 : dispatch(tr);
}
return true;
}
return false;
};
return withSafeSelection(mouseDown);
}

@@ -1252,0 +1296,0 @@ var defaultListClickHandler = (node) => {

{
"name": "prosemirror-flat-list",
"type": "module",
"version": "0.3.8",
"version": "0.3.9",
"description": "Powerful list support for ProseMirror",

@@ -53,4 +53,4 @@ "author": "ocavue <ocavue@gmail.com>",

"@types/dedent": "^0.7.0",
"@types/node": "^18.15.10",
"@vitest/coverage-c8": "^0.29.7",
"@types/node": "^18.15.11",
"@vitest/coverage-c8": "^0.30.1",
"dedent": "^0.7.0",

@@ -72,6 +72,6 @@ "execa": "^7.1.1",

"tsup": "^6.7.0",
"typescript": "^4.9.5",
"typescript": "^5.0.4",
"unified": "^10.1.2",
"vite": "^4.2.1",
"vitest": "^0.29.7"
"vitest": "^0.30.1"
},

@@ -78,0 +78,0 @@ "typedocOptions": {

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