1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-27 04:58:30 +00:00
This update includes a dependency update to version 2 of PopperJS, the library we use for tool-tips. Hopefully this fixes flickering issues with tool-tips. Some tool-tips may have issues after the update. If something doesn't look right, please ask.

* Fixed: Chat lines not showing replies.
* API Fixed: `setChildren` now supports variables that are not `Node`s or `string`s, and does so by casting other types to `string`s. Makes it easy to include numbers and other variables when using JSX.
* Maintenance: Update to PopperJS v2.
This commit is contained in:
SirStendec 2021-11-10 18:27:52 -05:00
parent 1c3e73e143
commit 958a3956f1
12 changed files with 107 additions and 79 deletions

View file

@ -9,9 +9,9 @@
// ============================================================================
import {createElement, setChildren} from 'utilities/dom';
import {maybe_call, debounce} from 'utilities/object';
import {maybe_call, debounce, has} from 'utilities/object';
import Popper from 'popper.js';
import {createPopper} from '@popperjs/core';
let last_id = 0;
@ -347,15 +347,24 @@ export class Tooltip {
const use_html = maybe_call(opts.html, null, target, tip),
setter = use_html ? 'innerHTML' : 'textContent';
let pop_opts = Object.assign({
modifiers: {
flip: {
behavior: ['top', 'bottom', 'left', 'right']
}
const modifiers = {
flip: {
behavior: ['top', 'bottom', 'left', 'right']
},
arrowElement: arrow
offset: {
offset: [0, 10]
},
arrow: {
element: arrow
}
};
let pop_opts = Object.assign({
modifiers
}, opts.popper);
pop_opts.modifiers = Object.assign(modifiers, pop_opts.modifiers);
if ( opts.popperConfig )
pop_opts = opts.popperConfig(target, tip, pop_opts) ?? pop_opts;
@ -370,9 +379,7 @@ export class Tooltip {
tip._update = () => {
if ( tip.popper ) {
tip.popper.update();
/*tip.popper.destroy();
tip.popper = new Popper(popper_target, el, pop_opts);*/
tip.popper.forceUpdate();
}
}
@ -413,9 +420,11 @@ export class Tooltip {
inner[setter] = content;
}
// Format the modifiers how Popper wants them now.
pop_opts.modifiers = normalizeModifiers(pop_opts.modifiers);
// Add everything to the DOM and create the Popper instance.
tip.popper = new Popper(popper_target, el, pop_opts);
tip.popper = createPopper(popper_target, el, pop_opts);
this.container.appendChild(el);
tip.visible = true;
@ -465,6 +474,30 @@ export class Tooltip {
export default Tooltip;
export function normalizeModifiers(input) {
const output = [];
for(const [key, val] of Object.entries(input)) {
const thing = {
name: key
};
if (val && typeof val === 'object' && ! Array.isArray(val)) {
if (has(val, 'enabled'))
thing.enabled = val.enabled;
const keys = Object.keys(val);
if (keys.length > 1 || (keys.length === 1 && keys[0] !== 'enabled'))
thing.options = val;
}
output.push(thing);
}
return output;
}
export function makeReference(x, y, height=0, width=0) {
if ( x instanceof Node ) {
const rect = x.getBoundingClientRect();