mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-22 02:34:05 +08:00
`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/(lib|utils)/*` into `discourse/lib/*`, adds shims for the imports, and updates existing uses in core.
37 lines
920 B
JavaScript
Vendored
37 lines
920 B
JavaScript
Vendored
import { registerDestructor } from "@ember/destroyable";
|
|
import { autoUpdate } from "@floating-ui/dom";
|
|
import Modifier from "ember-modifier";
|
|
import { bind } from "discourse/lib/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?.();
|
|
}
|
|
}
|