discourse/app/assets/javascripts/float-kit/addon/modifiers/apply-floating-ui.js
David Taylor 48193767bf DEV: Sort imports
Automatically generated by `eslint --fix` to satisfy the updated configuration
2023-10-10 21:46:54 +01:00

38 lines
929 B
JavaScript

import { registerDestructor } from "@ember/destroyable";
import { autoUpdate } from "@floating-ui/dom";
import Modifier from "ember-modifier";
import { bind } from "discourse-common/utils/decorators";
import { updatePosition } from "float-kit/lib/update-position";
export default class FloatKitApplyFloatingUi extends Modifier {
constructor(owner, args) {
super(owner, args);
registerDestructor(this, (instance) => instance.teardown());
}
modify(element, [trigger, options, instance]) {
instance.content = element;
this.instance = instance;
this.options = options ?? {};
if (this.options.autoUpdate) {
this.cleanup = autoUpdate(trigger, element, this.update);
} else {
this.update();
}
}
@bind
async update() {
await updatePosition(
this.instance.trigger,
this.instance.content,
this.options
);
}
teardown() {
this.cleanup?.();
}
}