Socket
Socket
Sign inDemoInstall

prosemirror-transform

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-transform - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

10

CHANGELOG.md

@@ -0,1 +1,11 @@

## 1.6.0 (2022-06-01)
### Bug fixes
Allow replace steps to be mapped through changes that delete content next to their start and end points, as long as no delete spans across those points.
### New features
`MapResult` objects now provide information about whether the tokens before, after, and around the position were deleted.
## 1.5.0 (2022-05-30)

@@ -2,0 +12,0 @@

21

dist/index.d.ts

@@ -35,6 +35,21 @@ import { Node, Schema, Slice, Fragment, NodeRange, NodeType, Attrs, Mark, MarkType, ContentMatch } from 'prosemirror-model';

/**
Tells you whether the position was deleted, that is, whether
the step removed its surroundings from the document.
Tells you whether the position was deleted, that is, whether the
step removed the token on the side queried (via the `assoc`)
argument from the document.
*/
readonly deleted: boolean;
get deleted(): boolean;
/**
Tells you whether the token before the mapped position was deleted.
*/
get deletedBefore(): boolean;
/**
True when the token after the mapped position was deleted.
*/
get deletedAfter(): boolean;
/**
Tells whether any of the steps mapped through deletes across the
position (including both the token before and after the
position).
*/
get deletedAcross(): boolean;
}

@@ -41,0 +56,0 @@ /**

2

package.json
{
"name": "prosemirror-transform",
"version": "1.5.0",
"version": "1.6.0",
"description": "ProseMirror document transformations",

@@ -5,0 +5,0 @@ "type": "module",

@@ -36,2 +36,4 @@ /// There are several things that positions can be mapped through.

const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8
/// An object representing a mapped position with extra

@@ -44,8 +46,23 @@ /// information.

readonly pos: number,
/// Tells you whether the position was deleted, that is, whether
/// the step removed its surroundings from the document.
readonly deleted: boolean = false,
/// @internal
readonly recover: number | null = null
readonly delInfo: number,
/// @internal
readonly recover: number | null
) {}
/// Tells you whether the position was deleted, that is, whether the
/// step removed the token on the side queried (via the `assoc`)
/// argument from the document.
get deleted() { return (this.delInfo & DEL_SIDE) > 0 }
/// Tells you whether the token before the mapped position was deleted.
get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0 }
/// True when the token after the mapped position was deleted.
get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0 }
/// Tells whether any of the steps mapped through deletes across the
/// position (including both the token before and after the
/// position).
get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0 }
}

@@ -94,7 +111,9 @@

let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start)
return new MapResult(result, assoc < 0 ? pos != start : pos != end, recover)
let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS
if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE
return new MapResult(result, del, recover)
}
diff += newSize - oldSize
}
return simple ? pos + diff : new MapResult(pos + diff)
return simple ? pos + diff : new MapResult(pos + diff, 0, null)
}

@@ -240,3 +259,3 @@

_map(pos: number, assoc: number, simple: boolean) {
let deleted = false
let delInfo = 0

@@ -254,8 +273,8 @@ for (let i = this.from; i < this.to; i++) {

if (result.deleted) deleted = true
delInfo |= result.delInfo
pos = result.pos
}
return simple ? pos : new MapResult(pos, deleted)
return simple ? pos : new MapResult(pos, delInfo, null)
}
}

@@ -44,3 +44,3 @@ import {Slice, Node, Schema} from "prosemirror-model"

let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1)
if (from.deleted && to.deleted) return null
if (from.deletedAcross && to.deletedAcross) return null
return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice)

@@ -139,3 +139,3 @@ }

let gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1)
if ((from.deleted && to.deleted) || gapFrom < from.pos || gapTo > to.pos) return null
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos) return null
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure)

@@ -142,0 +142,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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