@gez/date-time-kit
Version:
42 lines (41 loc) • 1.43 kB
JavaScript
import {
Ele as PopoverEle
} from "./index.mjs";
export const popoverAttrKeys = [
"pop-disabled",
"pop-open",
"pop-placement",
"pop-strategy",
"pop-offset"
];
export const isPopoverAttrKey = (name) => popoverAttrKeys.includes(name);
export const parentPopAttrSync2PopEle = (name, oldValue, newValue, popEle) => {
if (oldValue === newValue) return true;
const key = name.replace("pop-", "");
if (newValue === null) popEle.removeAttribute(key);
else popEle.setAttribute(key, newValue);
return true;
};
const eleClearupFns = /* @__PURE__ */ new WeakMap();
export const popEleAttrSync2Parent = (parent, popEle) => {
if (eleClearupFns.has(parent)) return;
const onAttrChanged = (evt) => {
if (!(evt.target instanceof PopoverEle)) return;
const { name, oldValue, newValue } = evt.detail;
if (newValue === oldValue) return;
const popName = "pop-" + name;
if (!isPopoverAttrKey(popName)) return;
if (newValue === null) parent.removeAttribute(popName);
else parent.setAttribute(popName, newValue);
};
popEle.addEventListener("dt-attribute-changed", onAttrChanged);
const clearup = () => {
popEle.removeEventListener("dt-attribute-changed", onAttrChanged);
eleClearupFns.delete(parent);
};
eleClearupFns.set(parent, clearup);
};
export const clearupPopEleAttrSync2Parent = (parent) => {
var _a;
return (_a = eleClearupFns.get(parent)) == null ? void 0 : _a();
};