@codemirror/view 6.23.0 → 6.23.1

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,11 @@
1
+ ## 6.23.1 (2024-01-24)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused `Tooltip.above` to not take effect for tooltips that were already present when the tooltip plugin is initialized.
6
+
7
+ Automatically reposition tooltips when their size changes.
8
+
1
9
  ## 6.23.0 (2023-12-28)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -9179,9 +9179,10 @@ function crosshairCursor(options = {}) {
9179
9179
 
9180
9180
  const Outside = "-10000px";
9181
9181
  class TooltipViewManager {
9182
- constructor(view, facet, createTooltipView) {
9182
+ constructor(view, facet, createTooltipView, removeTooltipView) {
9183
9183
  this.facet = facet;
9184
9184
  this.createTooltipView = createTooltipView;
9185
+ this.removeTooltipView = removeTooltipView;
9185
9186
  this.input = view.state.facet(facet);
9186
9187
  this.tooltips = this.input.filter(t => t);
9187
9188
  this.tooltipViews = this.tooltips.map(createTooltipView);
@@ -9221,7 +9222,7 @@ class TooltipViewManager {
9221
9222
  }
9222
9223
  for (let t of this.tooltipViews)
9223
9224
  if (tooltipViews.indexOf(t) < 0) {
9224
- t.dom.remove();
9225
+ this.removeTooltipView(t);
9225
9226
  (_a = t.destroy) === null || _a === void 0 ? void 0 : _a.call(t);
9226
9227
  }
9227
9228
  if (above) {
@@ -9269,7 +9270,13 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9269
9270
  this.classes = view.themeClasses;
9270
9271
  this.createContainer();
9271
9272
  this.measureReq = { read: this.readMeasure.bind(this), write: this.writeMeasure.bind(this), key: this };
9272
- this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t));
9273
+ this.resizeObserver = typeof ResizeObserver == "function" ? new ResizeObserver(() => this.measureSoon()) : null;
9274
+ this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t), t => {
9275
+ if (this.resizeObserver)
9276
+ this.resizeObserver.unobserve(t.dom);
9277
+ t.dom.remove();
9278
+ });
9279
+ this.above = this.manager.tooltips.map(t => !!t.above);
9273
9280
  this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver(entries => {
9274
9281
  if (Date.now() > this.lastTransaction - 50 &&
9275
9282
  entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1)
@@ -9347,10 +9354,12 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9347
9354
  this.container.appendChild(tooltipView.dom);
9348
9355
  if (tooltipView.mount)
9349
9356
  tooltipView.mount(this.view);
9357
+ if (this.resizeObserver)
9358
+ this.resizeObserver.observe(tooltipView.dom);
9350
9359
  return tooltipView;
9351
9360
  }
9352
9361
  destroy() {
9353
- var _a, _b;
9362
+ var _a, _b, _c;
9354
9363
  this.view.win.removeEventListener("resize", this.measureSoon);
9355
9364
  for (let tooltipView of this.manager.tooltipViews) {
9356
9365
  tooltipView.dom.remove();
@@ -9358,7 +9367,8 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9358
9367
  }
9359
9368
  if (this.parent)
9360
9369
  this.container.remove();
9361
- (_b = this.intersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9370
+ (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9371
+ (_c = this.intersectionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
9362
9372
  clearTimeout(this.measureTimeout);
9363
9373
  }
9364
9374
  readMeasure() {
@@ -9572,7 +9582,7 @@ class HoverTooltipHost {
9572
9582
  this.mounted = false;
9573
9583
  this.dom = document.createElement("div");
9574
9584
  this.dom.classList.add("cm-tooltip-hover");
9575
- this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t));
9585
+ this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t), t => t.dom.remove());
9576
9586
  }
9577
9587
  createHostedView(tooltip) {
9578
9588
  let hostedView = tooltip.create(this.view);
package/dist/index.js CHANGED
@@ -9174,9 +9174,10 @@ function crosshairCursor(options = {}) {
9174
9174
 
9175
9175
  const Outside = "-10000px";
9176
9176
  class TooltipViewManager {
9177
- constructor(view, facet, createTooltipView) {
9177
+ constructor(view, facet, createTooltipView, removeTooltipView) {
9178
9178
  this.facet = facet;
9179
9179
  this.createTooltipView = createTooltipView;
9180
+ this.removeTooltipView = removeTooltipView;
9180
9181
  this.input = view.state.facet(facet);
9181
9182
  this.tooltips = this.input.filter(t => t);
9182
9183
  this.tooltipViews = this.tooltips.map(createTooltipView);
@@ -9216,7 +9217,7 @@ class TooltipViewManager {
9216
9217
  }
9217
9218
  for (let t of this.tooltipViews)
9218
9219
  if (tooltipViews.indexOf(t) < 0) {
9219
- t.dom.remove();
9220
+ this.removeTooltipView(t);
9220
9221
  (_a = t.destroy) === null || _a === void 0 ? void 0 : _a.call(t);
9221
9222
  }
9222
9223
  if (above) {
@@ -9264,7 +9265,13 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9264
9265
  this.classes = view.themeClasses;
9265
9266
  this.createContainer();
9266
9267
  this.measureReq = { read: this.readMeasure.bind(this), write: this.writeMeasure.bind(this), key: this };
9267
- this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t));
9268
+ this.resizeObserver = typeof ResizeObserver == "function" ? new ResizeObserver(() => this.measureSoon()) : null;
9269
+ this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t), t => {
9270
+ if (this.resizeObserver)
9271
+ this.resizeObserver.unobserve(t.dom);
9272
+ t.dom.remove();
9273
+ });
9274
+ this.above = this.manager.tooltips.map(t => !!t.above);
9268
9275
  this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver(entries => {
9269
9276
  if (Date.now() > this.lastTransaction - 50 &&
9270
9277
  entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1)
@@ -9342,10 +9349,12 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9342
9349
  this.container.appendChild(tooltipView.dom);
9343
9350
  if (tooltipView.mount)
9344
9351
  tooltipView.mount(this.view);
9352
+ if (this.resizeObserver)
9353
+ this.resizeObserver.observe(tooltipView.dom);
9345
9354
  return tooltipView;
9346
9355
  }
9347
9356
  destroy() {
9348
- var _a, _b;
9357
+ var _a, _b, _c;
9349
9358
  this.view.win.removeEventListener("resize", this.measureSoon);
9350
9359
  for (let tooltipView of this.manager.tooltipViews) {
9351
9360
  tooltipView.dom.remove();
@@ -9353,7 +9362,8 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9353
9362
  }
9354
9363
  if (this.parent)
9355
9364
  this.container.remove();
9356
- (_b = this.intersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9365
+ (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9366
+ (_c = this.intersectionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
9357
9367
  clearTimeout(this.measureTimeout);
9358
9368
  }
9359
9369
  readMeasure() {
@@ -9567,7 +9577,7 @@ class HoverTooltipHost {
9567
9577
  this.mounted = false;
9568
9578
  this.dom = document.createElement("div");
9569
9579
  this.dom.classList.add("cm-tooltip-hover");
9570
- this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t));
9580
+ this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t), t => t.dom.remove());
9571
9581
  }
9572
9582
  createHostedView(tooltip) {
9573
9583
  let hostedView = tooltip.create(this.view);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.23.0",
3
+ "version": "6.23.1",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",