@codemirror/tooltip
Advanced tools
Comparing version 0.19.8 to 0.19.9
@@ -0,1 +1,7 @@ | ||
## 0.19.9 (2021-11-22) | ||
### New features | ||
Add an option `tooltipSpace` to the `tooltips` function that allows configuring of the available space to show tooltips in. | ||
## 0.19.8 (2021-11-19) | ||
@@ -2,0 +8,0 @@ |
@@ -29,2 +29,15 @@ import { EditorView, ViewUpdate } from '@codemirror/view'; | ||
parent?: HTMLElement; | ||
/** | ||
By default, when figuring out whether there is room for a | ||
tooltip at a given position, the extension considers the entire | ||
space between 0,0 and `innerWidth`,`innerHeight` to be available | ||
for showing tooltips. You can provide a function here that | ||
returns an alternative rectangle. | ||
*/ | ||
tooltipSpace?: (view: EditorView) => { | ||
top: number; | ||
left: number; | ||
bottom: number; | ||
right: number; | ||
}; | ||
}): Extension; | ||
@@ -31,0 +44,0 @@ /** |
@@ -59,8 +59,12 @@ import { ViewPlugin, Direction, EditorView, logException } from '@codemirror/view'; | ||
} | ||
function windowSpace() { | ||
return { top: 0, left: 0, bottom: innerHeight, right: innerWidth }; | ||
} | ||
const tooltipConfig = /*@__PURE__*/Facet.define({ | ||
combine: values => { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
return ({ | ||
position: ios ? "absolute" : ((_a = values.find(conf => conf.position)) === null || _a === void 0 ? void 0 : _a.position) || "fixed", | ||
parent: ((_b = values.find(conf => conf.parent)) === null || _b === void 0 ? void 0 : _b.parent) || null | ||
parent: ((_b = values.find(conf => conf.parent)) === null || _b === void 0 ? void 0 : _b.parent) || null, | ||
tooltipSpace: ((_c = values.find(conf => conf.tooltipSpace)) === null || _c === void 0 ? void 0 : _c.tooltipSpace) || windowSpace, | ||
}); | ||
@@ -162,4 +166,3 @@ } | ||
size: this.manager.tooltipViews.map(({ dom }) => dom.getBoundingClientRect()), | ||
innerWidth: window.innerWidth, | ||
innerHeight: window.innerHeight | ||
space: this.view.state.facet(tooltipConfig).tooltipSpace(this.view), | ||
}; | ||
@@ -169,3 +172,3 @@ } | ||
this.lastLayoutWrite = Date.now(); | ||
let { editor } = measured; | ||
let { editor, space } = measured; | ||
let others = []; | ||
@@ -176,3 +179,6 @@ for (let i = 0; i < this.manager.tooltips.length; i++) { | ||
// Hide tooltips that are outside of the editor. | ||
if (!pos || pos.bottom <= editor.top || pos.top >= editor.bottom || pos.right <= editor.left || pos.left >= editor.right) { | ||
if (!pos || pos.bottom <= Math.max(editor.top, space.top) || | ||
pos.top >= Math.min(editor.bottom, space.bottom) || | ||
pos.right <= Math.max(editor.left, space.left) || | ||
pos.left >= Math.min(editor.right, space.right)) { | ||
dom.style.top = Outside; | ||
@@ -186,8 +192,8 @@ continue; | ||
let left = ltr | ||
? Math.min(pos.left - (arrow ? 14 /* Offset */ : 0) + offset.x, measured.innerWidth - width) | ||
: Math.max(0, pos.left - width + (arrow ? 14 /* Offset */ : 0) - offset.x); | ||
? Math.min(pos.left - (arrow ? 14 /* Offset */ : 0) + offset.x, space.right - width) | ||
: Math.max(space.left, pos.left - width + (arrow ? 14 /* Offset */ : 0) - offset.x); | ||
let above = !!tooltip.above; | ||
if (!tooltip.strictSide && (above | ||
? pos.top - (size.bottom - size.top) - offset.y < 0 | ||
: pos.bottom + (size.bottom - size.top) + offset.y > measured.innerHeight)) | ||
? pos.top - (size.bottom - size.top) - offset.y < space.top | ||
: pos.bottom + (size.bottom - size.top) + offset.y > space.bottom)) | ||
above = !above; | ||
@@ -194,0 +200,0 @@ let top = above ? pos.top - height - arrowHeight - offset.y : pos.bottom + arrowHeight + offset.y; |
{ | ||
"name": "@codemirror/tooltip", | ||
"version": "0.19.8", | ||
"version": "0.19.9", | ||
"description": "Tooltip support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53439
1186