braid-text 0.2.108 → 0.2.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +7 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -927,7 +927,12 @@ function create_braid_text() {
927
927
  let og_patches = patches
928
928
  patches = patches.map((p) => ({
929
929
  ...p,
930
- range: p.range.match(/\d+/g).map((x) => parseInt(x)),
930
+ range: p.range.match(/-?\d+/g).map((x) => {
931
+ let n = parseInt(x)
932
+ // Handle negative indices (including -0) as offsets from max_pos
933
+ if (Object.is(n, -0) || n < 0) return max_pos + n
934
+ return n
935
+ }),
931
936
  content_codepoints: [...p.content],
932
937
  })).sort((a, b) => a.range[0] - b.range[0])
933
938
 
@@ -2530,7 +2535,7 @@ function create_braid_text() {
2530
2535
  if (typeof x != 'object') throw new Error(`invalid patch: not an object`)
2531
2536
  if (x.unit && x.unit !== 'text') throw new Error(`invalid patch unit '${x.unit}': only 'text' supported`)
2532
2537
  if (typeof x.range !== 'string') throw new Error(`invalid patch range: must be a string`)
2533
- if (!x.range.match(/^\s*\[\s*\d+\s*:\s*\d+\s*\]\s*$/)) throw new Error(`invalid patch range: ${x.range}`)
2538
+ if (!x.range.match(/^\s*\[\s*-?\d+\s*:\s*-?\d+\s*\]\s*$/)) throw new Error(`invalid patch range: ${x.range}`)
2534
2539
  if (typeof x.content !== 'string') throw new Error(`invalid patch content: must be a string`)
2535
2540
  }
2536
2541
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.108",
3
+ "version": "0.2.109",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",