| 62 | } |
| 63 | |
| 64 | update(update: ViewUpdate) { |
| 65 | if (update.focusChanged && !update.view.hasFocus) { |
| 66 | const input = update.state.facet(this.facet); |
| 67 | for (const t of this.tooltipViews) |
| 68 | t.dom.remove(); |
| 69 | this.input = input; |
| 70 | this.tooltips = []; |
| 71 | this.tooltipViews = []; |
| 72 | return true; |
| 73 | } |
| 74 | const input = update.state.facet(this.facet); |
| 75 | const tooltips = input.filter((x) => x) as Tooltip[]; |
| 76 | if (input === this.input) { |
| 77 | for (const t of this.tooltipViews) if (t.update) t.update(update); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | const tooltipViews = []; |
| 82 | for (let i = 0; i < tooltips.length; i++) { |
| 83 | const tip = tooltips[i] |
| 84 | let known = -1; |
| 85 | if (!tip) continue; |
| 86 | for (let i = 0; i < this.tooltips.length; i++) { |
| 87 | const other = this.tooltips[i]; |
| 88 | if (other && other.create == tip.create) known = i; |
| 89 | } |
| 90 | if (known < 0) { |
| 91 | tooltipViews[i] = this.createTooltipView(tip); |
| 92 | } else { |
| 93 | const tooltipView = (tooltipViews[i] = this.tooltipViews[known]); |
| 94 | if (tooltipView.update) tooltipView.update(update); |
| 95 | } |
| 96 | } |
| 97 | for (const t of this.tooltipViews) |
| 98 | if (tooltipViews.indexOf(t) < 0) t.dom.remove(); |
| 99 | |
| 100 | this.input = input; |
| 101 | this.tooltips = tooltips; |
| 102 | this.tooltipViews = tooltipViews; |
| 103 | return true; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /// Return an extension that configures tooltip behavior. |