@loke/ui
Version:
To install dependencies:
99 lines (96 loc) • 3.63 kB
JavaScript
var __create = Object.create;
var { getPrototypeOf: __getProtoOf, defineProperty: __defProp, getOwnPropertyNames: __getOwnPropNames, getOwnPropertyDescriptor: __getOwnPropDesc } = Object, __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
return this[key];
}
var __toESMCache_node, __toESMCache_esm, __toESM = (mod, isNodeMode, target) => {
var canCache = mod != null && typeof mod === "object";
if (canCache) {
var cache = isNodeMode ? __toESMCache_node ??= /* @__PURE__ */ new WeakMap : __toESMCache_esm ??= /* @__PURE__ */ new WeakMap, cached = cache.get(mod);
if (cached)
return cached;
}
target = mod != null ? __create(__getProtoOf(mod)) : {};
let to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target;
if (mod && typeof mod === "object" || typeof mod === "function") {
for (let key of __getOwnPropNames(mod))
if (!__hasOwnProp.call(to, key))
__defProp(to, key, {
get: __accessProp.bind(mod, key),
enumerable: !0
});
}
if (canCache)
cache.set(mod, to);
return to;
}, __toCommonJS = (from) => {
var entry = (__moduleCache ??= /* @__PURE__ */ new WeakMap).get(from), desc;
if (entry)
return entry;
if (entry = __defProp({}, "__esModule", { value: !0 }), from && typeof from === "object" || typeof from === "function") {
for (var key of __getOwnPropNames(from))
if (!__hasOwnProp.call(entry, key))
__defProp(entry, key, {
get: __accessProp.bind(from, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return __moduleCache.set(from, entry), entry;
}, __moduleCache;
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {
get: all[name],
enumerable: !0,
configurable: !0,
set: __exportSetter.bind(all, name)
});
};
// src/lib/compose-refs/index.ts
var exports_compose_refs = {};
__export(exports_compose_refs, {
composeRefs: () => composeRefs,
useComposedRefs: () => useComposedRefs
});
module.exports = __toCommonJS(exports_compose_refs);
// src/lib/compose-refs/compose-refs.tsx
var import_react = __toESM(require("react"), 1), useReactRef = import_react.default[" useRef ".trim().toString()];
function setRef(ref, value) {
if (typeof ref === "function")
return ref(value);
if (ref !== null && ref !== void 0)
ref.current = value;
}
function composeRefs(...refs) {
return (node) => {
let hasCleanup = !1, cleanups = refs.map((ref) => {
let cleanup = setRef(ref, node);
if (!hasCleanup && typeof cleanup === "function")
hasCleanup = !0;
return cleanup;
});
if (hasCleanup)
return () => {
for (let i = 0;i < cleanups.length; i++) {
let cleanup = cleanups[i];
if (typeof cleanup === "function")
cleanup();
else
setRef(refs[i], null);
}
};
};
}
var useComposedRefs = typeof useReactRef === "function" ? function(...refs) {
let composedRef = useReactRef(void 0), current = composedRef.current;
if (current !== void 0 && refs.length === current.refs.length && refs.every((ref, index) => ref === current.refs[index]))
return current.callback;
let callback = composeRefs(...refs);
return composedRef.current = { callback, refs }, callback;
} : function(...refs) {
return composeRefs(...refs);
};