@codemirror/view 6.42.1 → 6.43.0

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 6.43.0 (2026-05-14)
2
+
3
+ ### New features
4
+
5
+ Block wrappers can now be given a rank to set a specific nesting order for wrappers coming from the same source.
6
+
1
7
  ## 6.42.1 (2026-05-07)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -395,10 +395,23 @@ widget that starts inside its range, including blocks starting
395
395
  directly at `from` but not including `to`.
396
396
  */
397
397
  class BlockWrapper extends state.RangeValue {
398
- constructor(tagName, attributes) {
398
+ constructor(
399
+ /**
400
+ @internal
401
+ */
402
+ tagName,
403
+ /**
404
+ @internal
405
+ */
406
+ attributes,
407
+ /**
408
+ @internal
409
+ */
410
+ rank) {
399
411
  super();
400
412
  this.tagName = tagName;
401
413
  this.attributes = attributes;
414
+ this.rank = rank;
402
415
  }
403
416
  eq(other) {
404
417
  return other == this ||
@@ -409,7 +422,7 @@ class BlockWrapper extends state.RangeValue {
409
422
  attributes.
410
423
  */
411
424
  static create(spec) {
412
- return new BlockWrapper(spec.tagName, spec.attributes || noAttrs);
425
+ return new BlockWrapper(spec.tagName, spec.attributes || noAttrs, spec.rank == null ? 50 : Math.max(0, Math.min(spec.rank, 100)));
413
426
  }
414
427
  /**
415
428
  Create a range set from the given block wrapper ranges.
@@ -2410,7 +2423,8 @@ class TileBuilder {
2410
2423
  this.wrappers.splice(i, 1);
2411
2424
  for (let cur = this.blockWrappers; cur.value && cur.from <= this.pos; cur.next())
2412
2425
  if (cur.to >= this.pos) {
2413
- let wrap = new OpenWrapper(cur.from, cur.to, cur.value, cur.rank), i = this.wrappers.length;
2426
+ let rank = (cur.rank * 102) + cur.value.rank;
2427
+ let wrap = new OpenWrapper(cur.from, cur.to, cur.value, rank), i = this.wrappers.length;
2414
2428
  while (i > 0 && (this.wrappers[i - 1].rank - wrap.rank || this.wrappers[i - 1].to - wrap.to) < 0)
2415
2429
  i--;
2416
2430
  this.wrappers.splice(i, 0, wrap);
package/dist/index.d.cts CHANGED
@@ -366,6 +366,13 @@ interface BlockWrapperSpec {
366
366
  attributes?: {
367
367
  [key: string]: string;
368
368
  };
369
+ /**
370
+ When multiple overlapping block wrappers are produced by the
371
+ same source, this determines their relative precedence. Lower
372
+ rank wrappers are nested inside higher-rank ones. Should be
373
+ a number between 0 and 100.
374
+ */
375
+ rank?: number;
369
376
  }
370
377
  /**
371
378
  A block wrapper defines a DOM node that wraps lines or other block
@@ -374,8 +381,6 @@ widget that starts inside its range, including blocks starting
374
381
  directly at `from` but not including `to`.
375
382
  */
376
383
  declare class BlockWrapper extends RangeValue {
377
- readonly tagName: string;
378
- readonly attributes: Attrs;
379
384
  private constructor();
380
385
  eq(other: RangeValue): boolean;
381
386
  /**
package/dist/index.d.ts CHANGED
@@ -366,6 +366,13 @@ interface BlockWrapperSpec {
366
366
  attributes?: {
367
367
  [key: string]: string;
368
368
  };
369
+ /**
370
+ When multiple overlapping block wrappers are produced by the
371
+ same source, this determines their relative precedence. Lower
372
+ rank wrappers are nested inside higher-rank ones. Should be
373
+ a number between 0 and 100.
374
+ */
375
+ rank?: number;
369
376
  }
370
377
  /**
371
378
  A block wrapper defines a DOM node that wraps lines or other block
@@ -374,8 +381,6 @@ widget that starts inside its range, including blocks starting
374
381
  directly at `from` but not including `to`.
375
382
  */
376
383
  declare class BlockWrapper extends RangeValue {
377
- readonly tagName: string;
378
- readonly attributes: Attrs;
379
384
  private constructor();
380
385
  eq(other: RangeValue): boolean;
381
386
  /**
package/dist/index.js CHANGED
@@ -392,10 +392,23 @@ widget that starts inside its range, including blocks starting
392
392
  directly at `from` but not including `to`.
393
393
  */
394
394
  class BlockWrapper extends RangeValue {
395
- constructor(tagName, attributes) {
395
+ constructor(
396
+ /**
397
+ @internal
398
+ */
399
+ tagName,
400
+ /**
401
+ @internal
402
+ */
403
+ attributes,
404
+ /**
405
+ @internal
406
+ */
407
+ rank) {
396
408
  super();
397
409
  this.tagName = tagName;
398
410
  this.attributes = attributes;
411
+ this.rank = rank;
399
412
  }
400
413
  eq(other) {
401
414
  return other == this ||
@@ -406,7 +419,7 @@ class BlockWrapper extends RangeValue {
406
419
  attributes.
407
420
  */
408
421
  static create(spec) {
409
- return new BlockWrapper(spec.tagName, spec.attributes || noAttrs);
422
+ return new BlockWrapper(spec.tagName, spec.attributes || noAttrs, spec.rank == null ? 50 : Math.max(0, Math.min(spec.rank, 100)));
410
423
  }
411
424
  /**
412
425
  Create a range set from the given block wrapper ranges.
@@ -2406,7 +2419,8 @@ class TileBuilder {
2406
2419
  this.wrappers.splice(i, 1);
2407
2420
  for (let cur = this.blockWrappers; cur.value && cur.from <= this.pos; cur.next())
2408
2421
  if (cur.to >= this.pos) {
2409
- let wrap = new OpenWrapper(cur.from, cur.to, cur.value, cur.rank), i = this.wrappers.length;
2422
+ let rank = (cur.rank * 102) + cur.value.rank;
2423
+ let wrap = new OpenWrapper(cur.from, cur.to, cur.value, rank), i = this.wrappers.length;
2410
2424
  while (i > 0 && (this.wrappers[i - 1].rank - wrap.rank || this.wrappers[i - 1].to - wrap.to) < 0)
2411
2425
  i--;
2412
2426
  this.wrappers.splice(i, 0, wrap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.42.1",
3
+ "version": "6.43.0",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",