Fix tooltips sometimes causing issues with cyclical dependencies

This commit is contained in:
thepaperpilot 2022-04-24 16:44:37 -05:00
parent eb06435821
commit 819c3c674a

View file

@ -15,7 +15,7 @@ import {
ProcessedComputable ProcessedComputable
} from "util/computed"; } from "util/computed";
import { VueFeature } from "util/vue"; import { VueFeature } from "util/vue";
import { Ref, unref } from "vue"; import { nextTick, Ref, unref } from "vue";
import { persistent } from "game/persistence"; import { persistent } from "game/persistence";
declare module "@vue/runtime-dom" { declare module "@vue/runtime-dom" {
@ -73,18 +73,6 @@ export function addTooltip<T extends TooltipOptions>(
element: VueFeature, element: VueFeature,
options: T & ThisType<Tooltip<T>> & Partial<BaseTooltip> options: T & ThisType<Tooltip<T>> & Partial<BaseTooltip>
): Tooltip<T> { ): Tooltip<T> {
if (options.pinnable) {
if ("pinned" in element) {
console.error(
"Cannot add pinnable tooltip to element that already has a property called 'pinned'"
);
options.pinnable = false;
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(element as any).pinned = options.pinned = persistent<boolean>(false);
}
}
processComputable(options as T, "display"); processComputable(options as T, "display");
processComputable(options as T, "classes"); processComputable(options as T, "classes");
processComputable(options as T, "style"); processComputable(options as T, "style");
@ -93,25 +81,39 @@ export function addTooltip<T extends TooltipOptions>(
processComputable(options as T, "xoffset"); processComputable(options as T, "xoffset");
processComputable(options as T, "yoffset"); processComputable(options as T, "yoffset");
const elementComponent = element[Component]; nextTick(() => {
element[Component] = TooltipComponent; if (options.pinnable) {
const elementGratherProps = element[GatherProps].bind(element); if ("pinned" in element) {
element[GatherProps] = function gatherTooltipProps(this: GenericTooltip) { console.error(
const { display, classes, style, direction, xoffset, yoffset, pinned } = this; "Cannot add pinnable tooltip to element that already has a property called 'pinned'"
return { );
element: { options.pinnable = false;
[Component]: elementComponent, } else {
[GatherProps]: elementGratherProps // eslint-disable-next-line @typescript-eslint/no-explicit-any
}, (element as any).pinned = options.pinned = persistent<boolean>(false);
display, }
classes, }
style: unref(style),
direction, const elementComponent = element[Component];
xoffset, element[Component] = TooltipComponent;
yoffset, const elementGratherProps = element[GatherProps].bind(element);
pinned element[GatherProps] = function gatherTooltipProps(this: GenericTooltip) {
}; const { display, classes, style, direction, xoffset, yoffset, pinned } = this;
}.bind(options as GenericTooltip); return {
element: {
[Component]: elementComponent,
[GatherProps]: elementGratherProps
},
display,
classes,
style: unref(style),
direction,
xoffset,
yoffset,
pinned
};
}.bind(options as GenericTooltip);
});
return options as unknown as Tooltip<T>; return options as unknown as Tooltip<T>;
} }