events on Tabs

This commit is contained in:
2026-04-13 22:23:10 +02:00
parent 3c3938b354
commit a29963563e
8 changed files with 804 additions and 885 deletions

416
dist/sigpro-ui.esm.js vendored
View File

@@ -10,62 +10,81 @@ var __export = (target, all) => {
};
// src/sigpro.js
var isFunc = (fn) => typeof fn === "function";
var isFunc = (f) => typeof f === "function";
var isObj = (o) => o && typeof o === "object";
var isArr = Array.isArray;
var doc = typeof document !== "undefined" ? document : null;
var ensureNode = (node) => node?._isRuntime ? node.container : node instanceof Node ? node : doc.createTextNode(node == null ? "" : String(node));
var ensureNode = (n) => n?._isRuntime ? n.container : n instanceof Node ? n : doc.createTextNode(n == null ? "" : String(n));
var activeEffect = null;
var activeOwner = null;
var isFlushing = false;
var effectQueue = new Set;
var MOUNTED_NODES = new WeakMap;
var dispose = (effect) => {
if (!effect || effect._disposed)
var dispose = (eff) => {
if (!eff || eff._disposed)
return;
effect._disposed = true;
const stack = [effect];
eff._disposed = true;
const stack = [eff];
while (stack.length) {
const eff = stack.pop();
if (eff._cleanups) {
eff._cleanups.forEach((fn) => fn());
eff._cleanups.clear();
const e = stack.pop();
if (e._cleanups) {
e._cleanups.forEach((fn) => fn());
e._cleanups.clear();
}
if (eff._children) {
eff._children.forEach((child) => stack.push(child));
eff._children.clear();
if (e._children) {
e._children.forEach((child) => stack.push(child));
e._children.clear();
}
if (eff._deps) {
eff._deps.forEach((depSet) => depSet.delete(eff));
eff._deps.clear();
if (e._deps) {
e._deps.forEach((depSet) => depSet.delete(e));
e._deps.clear();
}
}
};
var onMount = (fn) => {
if (activeOwner)
(activeOwner._mounts ||= []).push(fn);
};
var onUnmount = (fn) => {
if (activeOwner)
(activeOwner._cleanups ||= new Set).add(fn);
};
var onMount = (fn) => {
if (activeOwner)
(activeOwner._mounts ||= []).push(fn);
var set = (signal, path, value) => {
if (value === undefined)
return signal(isFunc(path) ? path(signal()) : path);
const keys = path.split("."), root = { ...signal() };
let acc = root, k;
for (k of keys.slice(0, -1))
acc = acc[k] = { ...acc[k] || {} };
acc[keys.at(-1)] = value;
signal(root);
};
var untrack = (fn) => {
const p = activeEffect;
activeEffect = null;
try {
return fn();
} finally {
activeEffect = p;
}
};
var createEffect = (fn, isComputed = false) => {
const effect = () => {
if (effect._disposed)
return;
if (effect._deps)
effect._deps.forEach((depSet) => depSet.delete(effect));
effect._deps.forEach((s) => s.delete(effect));
if (effect._cleanups) {
effect._cleanups.forEach((cleanup) => cleanup());
effect._cleanups.forEach((c) => c());
effect._cleanups.clear();
}
const prevEffect = activeEffect;
const prevOwner = activeOwner;
activeEffect = activeOwner = effect;
try {
const res = isComputed ? fn() : (fn(), undefined);
if (!isComputed)
effect._result = res;
return res;
return effect._result = fn();
} catch (e) {
console.error("[SigPro]", e);
} finally {
activeEffect = prevEffect;
activeOwner = prevOwner;
@@ -87,9 +106,9 @@ var flush = () => {
isFlushing = true;
const sorted = Array.from(effectQueue).sort((a, b) => a._depth - b._depth);
effectQueue.clear();
for (const eff of sorted)
if (!eff._disposed)
eff();
for (const e of sorted)
if (!e._disposed)
e();
isFlushing = false;
};
var trackUpdate = (subs, trigger = false) => {
@@ -98,15 +117,15 @@ var trackUpdate = (subs, trigger = false) => {
(activeEffect._deps ||= new Set).add(subs);
} else if (trigger) {
let hasQueue = false;
subs.forEach((eff) => {
if (eff === activeEffect || eff._disposed)
subs.forEach((e) => {
if (e === activeEffect || e._disposed)
return;
if (eff._isComputed) {
eff._dirty = true;
if (eff._subs)
trackUpdate(eff._subs, true);
if (e._isComputed) {
e._dirty = true;
if (e._subs)
trackUpdate(e._subs, true);
} else {
effectQueue.add(eff);
effectQueue.add(e);
hasQueue = true;
}
});
@@ -114,25 +133,16 @@ var trackUpdate = (subs, trigger = false) => {
queueMicrotask(flush);
}
};
var untrack = (fn) => {
const prev = activeEffect;
activeEffect = null;
try {
return fn();
} finally {
activeEffect = prev;
}
};
var $2 = (initialValue, storageKey = null) => {
var $2 = (val, key = null) => {
const subs = new Set;
if (isFunc(initialValue)) {
if (isFunc(val)) {
let cache, dirty = true;
const computed = () => {
if (dirty) {
const prev = activeEffect;
activeEffect = computed;
try {
const next = initialValue();
const next = val();
if (!Object.is(cache, next)) {
cache = next;
dirty = false;
@@ -165,33 +175,33 @@ var $2 = (initialValue, storageKey = null) => {
onUnmount(computed.stop);
return computed;
}
if (storageKey)
if (key)
try {
initialValue = JSON.parse(localStorage.getItem(storageKey)) ?? initialValue;
val = JSON.parse(localStorage.getItem(key)) ?? val;
} catch (e) {}
return (...args) => {
if (args.length) {
const next = isFunc(args[0]) ? args[0](initialValue) : args[0];
if (!Object.is(initialValue, next)) {
initialValue = next;
if (storageKey)
localStorage.setItem(storageKey, JSON.stringify(initialValue));
const next = isFunc(args[0]) ? args[0](val) : args[0];
if (!Object.is(val, next)) {
val = next;
if (key)
localStorage.setItem(key, JSON.stringify(val));
trackUpdate(subs, true);
}
}
trackUpdate(subs);
return initialValue;
return val;
};
};
var Watch2 = (sources, callback) => {
if (callback === undefined) {
var Watch2 = (sources, cb) => {
if (cb === undefined) {
const effect2 = createEffect(sources);
effect2();
return () => dispose(effect2);
}
const effect = createEffect(() => {
const vals = isArr(sources) ? sources.map((src) => src()) : sources();
untrack(() => callback(vals));
const vals = Array.isArray(sources) ? sources.map((s) => s()) : sources();
untrack(() => cb(vals));
});
effect();
return () => dispose(effect);
@@ -208,36 +218,20 @@ var cleanupNode = (node) => {
};
var DANGEROUS_PROTOCOL = /^\s*(javascript|data|vbscript):/i;
var isDangerousAttr = (key) => key === "src" || key === "href" || key.startsWith("on");
var applyProp = (elem, key, value, isSVG) => {
if (value == null || value === false) {
if (key === "class" || key === "className")
elem.className = "";
else if (key in elem && !isSVG)
elem[key] = "";
else
elem.removeAttribute(key);
return;
}
if (key === "class" || key === "className") {
elem.className = value;
} else if (key === "style" && typeof value === "object") {
Object.assign(elem.style, value);
} else if (key in elem && !isSVG) {
elem[key] = value;
} else if (isSVG) {
if (key.startsWith("xlink:")) {
elem.setAttributeNS("http://www.w3.org/1999/xlink", key, value);
} else if (key === "xmlns" || key.startsWith("xmlns:")) {
elem.setAttributeNS("http://www.w3.org/2000/xmlns/", key, value);
} else {
elem.setAttribute(key, value === true ? "" : value);
var validateAttr = (key, val) => {
if (val == null || val === false)
return null;
if (isDangerousAttr(key)) {
const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) {
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`);
return "#";
}
} else {
elem.setAttribute(key, value === true ? "" : value);
}
return val;
};
var Tag2 = (tag, props = {}, children = []) => {
if (props instanceof Node || isArr(props) || props && typeof props !== "object") {
if (props instanceof Node || isArr(props) || !isObj(props)) {
children = props;
props = {};
}
@@ -252,71 +246,75 @@ var Tag2 = (tag, props = {}, children = []) => {
return result2;
});
effect();
ctx._mounts = effect._mounts || [];
ctx._cleanups = effect._cleanups || new Set;
const result = effect._result;
const attach = (node) => {
if (node && typeof node === "object" && !node._isRuntime) {
node._mounts = ctx._mounts;
node._cleanups = ctx._cleanups;
node._ownerEffect = effect;
}
};
isArr(result) ? result.forEach(attach) : attach(result);
if (result == null)
return null;
if (result instanceof Node || isArr(result) && result.every((n) => n instanceof Node))
return result;
return doc.createTextNode(String(result));
const node = result instanceof Node || isArr(result) && result.every((n) => n instanceof Node) ? result : doc.createTextNode(String(result));
const attach = (n) => {
if (isObj(n) && !n._isRuntime) {
n._mounts = effect._mounts || [];
n._cleanups = effect._cleanups || new Set;
n._ownerEffect = effect;
}
};
isArr(node) ? node.forEach(attach) : attach(node);
return node;
}
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use|image|ellipse|foreignObject|linearGradient|radialGradient|stop|pattern|mask|clipPath|filter|feColorMatrix|feBlend|feGaussianBlur|animate|animateTransform|set|metadata|desc|title|symbol|marker|view)$/i.test(tag);
const elem = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag);
elem._cleanups = new Set;
for (let key in props) {
if (!props.hasOwnProperty(key))
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(tag);
const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag);
el._cleanups = new Set;
for (let k in props) {
if (!props.hasOwnProperty(k))
continue;
let value = props[key];
if (key === "ref") {
isFunc(value) ? value(elem) : value.current = elem;
let v = props[k];
if (k === "ref") {
isFunc(v) ? v(el) : v.current = el;
continue;
}
if (key.startsWith("on")) {
const event = key.slice(2).toLowerCase();
elem.addEventListener(event, value);
const off = () => elem.removeEventListener(event, value);
elem._cleanups.add(off);
if (k.startsWith("on")) {
const ev = k.slice(2).toLowerCase();
el.addEventListener(ev, v);
const off = () => el.removeEventListener(ev, v);
el._cleanups.add(off);
onUnmount(off);
} else if (isFunc(value)) {
} else if (isFunc(v)) {
const effect = createEffect(() => {
let val = value();
if (isDangerousAttr(key) && DANGEROUS_PROTOCOL.test(String(val)))
val = "#";
applyProp(elem, key, val, isSVG);
const val = validateAttr(k, v());
if (k === "class")
el.className = val || "";
else if (val == null)
el.removeAttribute(k);
else if (k in el && !isSVG)
el[k] = val;
else
el.setAttribute(k, val === true ? "" : val);
});
effect();
elem._cleanups.add(() => dispose(effect));
el._cleanups.add(() => dispose(effect));
onUnmount(() => dispose(effect));
if (/^(INPUT|TEXTAREA|SELECT)$/.test(elem.tagName) && (key === "value" || key === "checked")) {
const eventType = key === "checked" ? "change" : "input";
elem.addEventListener(eventType, (ev) => value(ev.target[key]));
if (/^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) && (k === "value" || k === "checked")) {
const evType = k === "checked" ? "change" : "input";
el.addEventListener(evType, (ev) => v(ev.target[k]));
}
} else {
let val = value;
if (isDangerousAttr(key) && DANGEROUS_PROTOCOL.test(String(val)))
val = "#";
if (val != null)
applyProp(elem, key, val, isSVG);
const val = validateAttr(k, v);
if (val != null) {
if (k in el && !isSVG)
el[k] = val;
else
el.setAttribute(k, val === true ? "" : val);
}
}
}
const mountChild = (child) => {
if (isArr(child))
return child.forEach(mountChild);
if (isFunc(child)) {
const append = (c) => {
if (isArr(c))
return c.forEach(append);
if (isFunc(c)) {
const anchor = doc.createTextNode("");
elem.appendChild(anchor);
el.appendChild(anchor);
let currentNodes = [];
const effect = createEffect(() => {
const res = child();
const res = c();
const next = (isArr(res) ? res : [res]).map(ensureNode);
currentNodes.forEach((n) => {
if (n._isRuntime)
@@ -338,55 +336,46 @@ var Tag2 = (tag, props = {}, children = []) => {
currentNodes = next;
});
effect();
elem._cleanups.add(() => dispose(effect));
el._cleanups.add(() => dispose(effect));
onUnmount(() => dispose(effect));
} else {
const node = ensureNode(child);
elem.appendChild(node);
const node = ensureNode(c);
el.appendChild(node);
if (node._mounts)
node._mounts.forEach((fn) => fn());
}
};
mountChild(children);
return elem;
append(children);
return el;
};
var createView = (renderFn) => {
var Render = (renderFn) => {
const cleanups = new Set;
const mounts = [];
const previousOwner = activeOwner;
activeOwner = { _cleanups: cleanups, _mounts: mounts };
const result = renderFn({ onCleanup: (fn) => cleanups.add(fn) });
activeOwner = previousOwner;
if (result == null)
return null;
if (result instanceof Node) {
mounts.forEach((fn) => fn());
return {
_isRuntime: true,
container: result,
destroy: () => {
cleanups.forEach((fn) => fn());
cleanupNode(result);
result.remove();
}
};
}
const previousEffect = activeEffect;
const container = doc.createElement("div");
container.style.display = "contents";
container.setAttribute("role", "presentation");
const process = (node) => {
if (!node)
activeOwner = { _cleanups: cleanups, _mounts: mounts };
activeEffect = null;
const processResult = (result) => {
if (!result)
return;
if (node._isRuntime) {
cleanups.add(node.destroy);
container.appendChild(node.container);
} else if (isArr(node)) {
node.forEach(process);
if (result._isRuntime) {
cleanups.add(result.destroy);
container.appendChild(result.container);
} else if (isArr(result)) {
result.forEach(processResult);
} else {
container.appendChild(node instanceof Node ? node : doc.createTextNode(String(node)));
container.appendChild(result instanceof Node ? result : doc.createTextNode(String(result == null ? "" : result)));
}
};
process(result);
try {
processResult(renderFn({ onCleanup: (fn) => cleanups.add(fn) }));
} finally {
activeOwner = previousOwner;
activeEffect = previousEffect;
}
mounts.forEach((fn) => fn());
return {
_isRuntime: true,
@@ -428,7 +417,7 @@ var If2 = (cond, ifYes, ifNot = null, trans = null) => {
}
const content = show ? ifYes : ifNot;
if (content) {
currentView = createView(() => isFunc(content) ? content() : content);
currentView = Render(() => isFunc(content) ? content() : content);
root.insertBefore(currentView.container, anchor);
if (trans?.in)
trans.in(currentView.container);
@@ -449,7 +438,7 @@ var For2 = (src, itemFn, keyFn) => {
const key = keyFn ? keyFn(item, i) : item?.id ?? i;
let view = cache.get(key);
if (!view)
view = createView(() => itemFn(item, i));
view = Render(() => itemFn(item, i));
else
cache.delete(key);
nextCache.set(key, view);
@@ -474,14 +463,14 @@ var Router = (routes) => {
const handler = () => path(getHash());
window.addEventListener("hashchange", handler);
onUnmount(() => window.removeEventListener("hashchange", handler));
const outlet = Tag2("div", { class: "router-outlet" });
const hook = Tag2("div", { class: "router-hook" });
let currentView = null;
Watch2([path], () => {
const cur = path();
const route = routes.find((r) => {
const rParts = r.path.split("/").filter(Boolean);
const curParts = cur.split("/").filter(Boolean);
return rParts.length === curParts.length && rParts.every((p, i) => p[0] === ":" || p === curParts[i]);
const p1 = r.path.split("/").filter(Boolean);
const p2 = cur.split("/").filter(Boolean);
return p1.length === p2.length && p1.every((p, i) => p[0] === ":" || p === p2[i]);
}) || routes.find((r) => r.path === "*");
if (route) {
currentView?.destroy();
@@ -491,14 +480,14 @@ var Router = (routes) => {
params[p.slice(1)] = cur.split("/").filter(Boolean)[i];
});
Router.params(params);
currentView = createView(() => isFunc(route.component) ? route.component(params) : route.component);
outlet.replaceChildren(currentView.container);
currentView = Render(() => isFunc(route.component) ? route.component(params) : route.component);
hook.replaceChildren(currentView.container);
}
});
return outlet;
return hook;
};
Router.params = $2({});
Router.to = (path) => window.location.hash = path.replace(/^#?\/?/, "#/");
Router.to = (p) => window.location.hash = p.replace(/^#?\/?/, "#/");
Router.back = () => window.history.back();
Router.path = () => window.location.hash.replace(/^#/, "") || "/";
var Mount2 = (comp, target) => {
@@ -507,24 +496,12 @@ var Mount2 = (comp, target) => {
return;
if (MOUNTED_NODES.has(t))
MOUNTED_NODES.get(t).destroy();
const inst = createView(() => isFunc(comp) ? comp() : comp);
const inst = Render(isFunc(comp) ? comp : () => comp);
t.replaceChildren(inst.container);
MOUNTED_NODES.set(t, inst);
return inst;
};
var set = (signal, path, value) => {
if (value === undefined) {
signal(isFunc(path) ? path(signal()) : path);
} else {
const keys = path.split(".");
const last = keys.pop();
const current = signal();
const obj = keys.reduce((o, k) => ({ ...o, [k]: { ...o[k] } }), { ...current });
obj[last] = value;
signal(obj);
}
};
var SigPro = Object.freeze({ $: $2, Watch: Watch2, Tag: Tag2, If: If2, For: For2, Router, Mount: Mount2, onMount, onUnmount, set });
var SigPro = Object.freeze({ $: $2, Watch: Watch2, Tag: Tag2, Render, If: If2, For: For2, Router, Mount: Mount2, onMount, onUnmount, set });
if (typeof window !== "undefined") {
Object.assign(window, SigPro);
"div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer ul ol li a em strong pre code form label input textarea select button img svg".split(" ").forEach((t) => window[t[0].toUpperCase() + t.slice(1)] = (p, c) => SigPro.Tag(t, p, c));
@@ -579,11 +556,11 @@ var exports_utils = {};
__export(exports_utils, {
val: () => val,
ui: () => ui,
getIcon: () => getIcon2
getIcon: () => getIcon
});
var val = (t) => typeof t === "function" ? t() : t;
var ui = (baseClass, additionalClassOrFn) => typeof additionalClassOrFn === "function" ? () => `${baseClass} ${additionalClassOrFn() || ""}`.trim() : `${baseClass} ${additionalClassOrFn || ""}`.trim();
var getIcon2 = (icon) => {
var getIcon = (icon) => {
if (!icon)
return null;
if (typeof icon === "function") {
@@ -644,7 +621,7 @@ var Alert = (props, children) => {
role: "alert",
class: ui("alert", allClasses)
}, () => [
getIcon2(iconMap[type]),
getIcon(iconMap[type]),
Tag("div", { class: "flex-1" }, [
Tag("span", {}, [typeof content === "function" ? content() : content])
]),
@@ -713,8 +690,8 @@ var Input = (props) => {
tel: "icon-[lucide--phone]",
url: "icon-[lucide--link]"
};
const leftIcon = icon ? getIcon2(icon) : iconMap[type] ? getIcon2(iconMap[type]) : null;
const getPasswordIcon = () => getIcon2(visible() ? "icon-[lucide--eye-off]" : "icon-[lucide--eye]");
const leftIcon = icon ? getIcon(icon) : iconMap[type] ? getIcon(iconMap[type]) : null;
const getPasswordIcon = () => getIcon(visible() ? "icon-[lucide--eye-off]" : "icon-[lucide--eye]");
const paddingLeft = leftIcon ? "pl-10" : "";
const paddingRight = isPassword ? "pr-10" : "";
const buttonSize = () => {
@@ -871,7 +848,7 @@ __export(exports_Button, {
});
var Button = (props, children) => {
const { class: className, loading, icon, ...rest } = props;
const iconEl = getIcon2(icon);
const iconEl = getIcon(icon);
return Tag("button", {
...rest,
class: ui("btn", className),
@@ -1067,7 +1044,7 @@ var Datepicker = (props) => {
placeholder: placeholder || (isRangeMode() ? "Seleccionar rango..." : "Seleccionar fecha..."),
value: displayValue,
readonly: true,
icon: getIcon2("icon-[lucide--calendar]"),
icon: getIcon("icon-[lucide--calendar]"),
onclick: (e) => {
e.stopPropagation();
isOpen(!isOpen());
@@ -1080,15 +1057,15 @@ var Datepicker = (props) => {
}, [
Tag("div", { class: "flex justify-between items-center mb-4 gap-1" }, [
Tag("div", { class: "flex gap-0.5" }, [
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(-1) }, getIcon2("icon-[lucide--chevrons-left]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(-1) }, getIcon2("icon-[lucide--chevron-left]"))
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(-1) }, getIcon("icon-[lucide--chevrons-left]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(-1) }, getIcon("icon-[lucide--chevron-left]"))
]),
Tag("span", { class: "font-bold uppercase flex-1 text-center" }, [
() => internalDate().toLocaleString("es-ES", { month: "short", year: "numeric" })
]),
Tag("div", { class: "flex gap-0.5" }, [
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(1) }, getIcon2("icon-[lucide--chevron-right]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(1) }, getIcon2("icon-[lucide--chevrons-right]"))
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(1) }, getIcon("icon-[lucide--chevron-right]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(1) }, getIcon("icon-[lucide--chevrons-right]"))
])
]),
Tag("div", { class: "grid grid-cols-7 gap-1", onmouseleave: () => hoverDate(null) }, [
@@ -1296,7 +1273,7 @@ var Fab = (props) => {
role: "button",
class: "btn btn-lg btn-circle btn-primary shadow-2xl"
}, [
icon ? getIcon2(icon) : null,
icon ? getIcon(icon) : null,
!icon && label ? label : null
]),
...val(actions).map((act) => Tag("div", { class: "flex items-center gap-3 transition-all duration-300" }, [
@@ -1308,7 +1285,7 @@ var Fab = (props) => {
e.stopPropagation();
act.onclick?.(e);
}
}, [act.icon ? getIcon2(act.icon) : act.text || ""])
}, [act.icon ? getIcon(act.icon) : act.text || ""])
]))
]);
};
@@ -1383,7 +1360,7 @@ var Fileinput = (props) => {
}
}, [
Tag("div", { class: "flex items-center gap-3 w-full" }, [
getIcon2("icon-[lucide--upload]"),
getIcon("icon-[lucide--upload]"),
Tag("span", { class: "text-sm opacity-70 truncate grow text-left" }, "Arrastra o selecciona archivos..."),
Tag("span", { class: "text-[10px] opacity-40 shrink-0" }, `Máx ${max}MB`)
]),
@@ -1412,7 +1389,7 @@ var Fileinput = (props) => {
e.stopPropagation();
removeFile(index);
}
}, [getIcon2("icon-[lucide--x]")])
}, [getIcon("icon-[lucide--x]")])
]), (file) => file.name + file.lastModified)
]))
]);
@@ -1760,10 +1737,10 @@ __export(exports_Tabs, {
Tabs: () => Tabs
});
var Tabs = (props) => {
const { items, class: className, ...rest } = props;
const { items, class: className, onTabClose, ...rest } = props;
const itemsSignal = typeof items === "function" ? items : () => items || [];
const activeIndex = $(0);
Watch(() => {
const activeIndex = $2(0);
Watch2(() => {
const list = itemsSignal();
const idx = list.findIndex((it) => val(it.active) === true);
if (idx !== -1 && activeIndex() !== idx) {
@@ -1772,7 +1749,9 @@ var Tabs = (props) => {
});
const removeTab = (indexToRemove, item) => {
if (item.onClose)
item.onClose();
item.onClose(item);
if (onTabClose)
onTabClose(item, indexToRemove);
const currentItems = itemsSignal();
const newItems = currentItems.filter((_, idx) => idx !== indexToRemove);
const isWritableSignal = typeof items === "function" && !items._isComputed;
@@ -1790,7 +1769,7 @@ var Tabs = (props) => {
newActive = Math.min(newActive, newItems.length - 1);
activeIndex(newActive);
};
return Tag("div", { ...rest, class: ui("tabs", className) }, () => {
return Tag2("div", { ...rest, class: ui("tabs", className) }, () => {
const list = itemsSignal();
const elements = [];
for (let i = 0;i < list.length; i++) {
@@ -1805,16 +1784,13 @@ var Tabs = (props) => {
e.stopPropagation();
removeTab(i, item);
};
const wrapper = Tag("span", { class: "flex items-center" }, [labelNode, closeIcon]);
const wrapper = Tag2("span", { class: "flex items-center" }, [labelNode, closeIcon]);
buttonChildren.push(wrapper);
} else {
buttonChildren.push(labelNode);
}
const button = Tag("button", {
class: () => {
const isActive = activeIndex() === i;
return ui("tab", isActive ? "tab-active" : "");
},
const buttonBase = Tag2("button", {
class: () => ui("tab", activeIndex() === i ? "tab-active" : ""),
onclick: (e) => {
e.preventDefault();
if (!val(item.disabled)) {
@@ -1822,9 +1798,9 @@ var Tabs = (props) => {
item.onclick();
activeIndex(i);
}
},
title: item.tip || ""
}
}, buttonChildren);
const button = item.tip ? Tag2("div", { class: "tooltip", "data-tip": item.tip }, buttonBase) : buttonBase;
elements.push(button);
let contentNode;
const rawContent = val(item.content);
@@ -1835,8 +1811,8 @@ var Tabs = (props) => {
} else {
contentNode = document.createTextNode(String(rawContent));
}
const inner = Tag("div", { class: "tab-content-inner" }, contentNode);
const panel = Tag("div", {
const inner = Tag2("div", { class: "tab-content-inner" }, contentNode);
const panel = Tag2("div", {
class: "tab-content bg-base-100 border-base-300 p-6",
style: () => activeIndex() === i ? "display: block" : "display: none"
}, inner);
@@ -1875,7 +1851,7 @@ var Timeline = (props) => {
!isFirst ? Tag("hr", { class: () => prevCompleted() ? "bg-primary" : "" }) : null,
Tag("div", { class: "timeline-start" }, [() => renderSlot(item.title)]),
Tag("div", { class: "timeline-middle" }, [
() => item.icon ? getIcon2(item.icon) : getIcon2(iconMap[itemType] || iconMap.success)
() => item.icon ? getIcon(item.icon) : getIcon(iconMap[itemType] || iconMap.success)
]),
Tag("div", { class: "timeline-end timeline-box shadow-sm" }, [() => renderSlot(item.detail)]),
!isLast ? Tag("hr", { class: () => isCompleted() ? "bg-primary" : "" }) : null
@@ -1918,7 +1894,7 @@ var Toast = (message, type = "alert-success", duration = 3500) => {
}
};
const ToastComponent = () => {
const closeIcon = getIcon2("icon-[lucide--x]");
const closeIcon = getIcon("icon-[lucide--x]");
const el = Tag("div", {
class: `alert alert-soft ${type} shadow-lg transition-all duration-300 translate-x-10 opacity-0 pointer-events-auto`
}, [
@@ -2029,7 +2005,7 @@ export {
val,
ui,
tt,
getIcon2 as getIcon,
getIcon,
Watch2 as Watch,
Tooltip,
Toast,

File diff suppressed because one or more lines are too long

416
dist/sigpro-ui.js vendored
View File

@@ -33,7 +33,7 @@
val: () => val,
ui: () => ui,
tt: () => tt,
getIcon: () => getIcon2,
getIcon: () => getIcon,
Watch: () => Watch2,
Tooltip: () => Tooltip,
Toast: () => Toast,
@@ -76,62 +76,81 @@
});
// src/sigpro.js
var isFunc = (fn) => typeof fn === "function";
var isFunc = (f) => typeof f === "function";
var isObj = (o) => o && typeof o === "object";
var isArr = Array.isArray;
var doc = typeof document !== "undefined" ? document : null;
var ensureNode = (node) => node?._isRuntime ? node.container : node instanceof Node ? node : doc.createTextNode(node == null ? "" : String(node));
var ensureNode = (n) => n?._isRuntime ? n.container : n instanceof Node ? n : doc.createTextNode(n == null ? "" : String(n));
var activeEffect = null;
var activeOwner = null;
var isFlushing = false;
var effectQueue = new Set;
var MOUNTED_NODES = new WeakMap;
var dispose = (effect) => {
if (!effect || effect._disposed)
var dispose = (eff) => {
if (!eff || eff._disposed)
return;
effect._disposed = true;
const stack = [effect];
eff._disposed = true;
const stack = [eff];
while (stack.length) {
const eff = stack.pop();
if (eff._cleanups) {
eff._cleanups.forEach((fn) => fn());
eff._cleanups.clear();
const e = stack.pop();
if (e._cleanups) {
e._cleanups.forEach((fn) => fn());
e._cleanups.clear();
}
if (eff._children) {
eff._children.forEach((child) => stack.push(child));
eff._children.clear();
if (e._children) {
e._children.forEach((child) => stack.push(child));
e._children.clear();
}
if (eff._deps) {
eff._deps.forEach((depSet) => depSet.delete(eff));
eff._deps.clear();
if (e._deps) {
e._deps.forEach((depSet) => depSet.delete(e));
e._deps.clear();
}
}
};
var onMount = (fn) => {
if (activeOwner)
(activeOwner._mounts ||= []).push(fn);
};
var onUnmount = (fn) => {
if (activeOwner)
(activeOwner._cleanups ||= new Set).add(fn);
};
var onMount = (fn) => {
if (activeOwner)
(activeOwner._mounts ||= []).push(fn);
var set = (signal, path, value) => {
if (value === undefined)
return signal(isFunc(path) ? path(signal()) : path);
const keys = path.split("."), root = { ...signal() };
let acc = root, k;
for (k of keys.slice(0, -1))
acc = acc[k] = { ...acc[k] || {} };
acc[keys.at(-1)] = value;
signal(root);
};
var untrack = (fn) => {
const p = activeEffect;
activeEffect = null;
try {
return fn();
} finally {
activeEffect = p;
}
};
var createEffect = (fn, isComputed = false) => {
const effect = () => {
if (effect._disposed)
return;
if (effect._deps)
effect._deps.forEach((depSet) => depSet.delete(effect));
effect._deps.forEach((s) => s.delete(effect));
if (effect._cleanups) {
effect._cleanups.forEach((cleanup) => cleanup());
effect._cleanups.forEach((c) => c());
effect._cleanups.clear();
}
const prevEffect = activeEffect;
const prevOwner = activeOwner;
activeEffect = activeOwner = effect;
try {
const res = isComputed ? fn() : (fn(), undefined);
if (!isComputed)
effect._result = res;
return res;
return effect._result = fn();
} catch (e) {
console.error("[SigPro]", e);
} finally {
activeEffect = prevEffect;
activeOwner = prevOwner;
@@ -153,9 +172,9 @@
isFlushing = true;
const sorted = Array.from(effectQueue).sort((a, b) => a._depth - b._depth);
effectQueue.clear();
for (const eff of sorted)
if (!eff._disposed)
eff();
for (const e of sorted)
if (!e._disposed)
e();
isFlushing = false;
};
var trackUpdate = (subs, trigger = false) => {
@@ -164,15 +183,15 @@
(activeEffect._deps ||= new Set).add(subs);
} else if (trigger) {
let hasQueue = false;
subs.forEach((eff) => {
if (eff === activeEffect || eff._disposed)
subs.forEach((e) => {
if (e === activeEffect || e._disposed)
return;
if (eff._isComputed) {
eff._dirty = true;
if (eff._subs)
trackUpdate(eff._subs, true);
if (e._isComputed) {
e._dirty = true;
if (e._subs)
trackUpdate(e._subs, true);
} else {
effectQueue.add(eff);
effectQueue.add(e);
hasQueue = true;
}
});
@@ -180,25 +199,16 @@
queueMicrotask(flush);
}
};
var untrack = (fn) => {
const prev = activeEffect;
activeEffect = null;
try {
return fn();
} finally {
activeEffect = prev;
}
};
var $2 = (initialValue, storageKey = null) => {
var $2 = (val, key = null) => {
const subs = new Set;
if (isFunc(initialValue)) {
if (isFunc(val)) {
let cache, dirty = true;
const computed = () => {
if (dirty) {
const prev = activeEffect;
activeEffect = computed;
try {
const next = initialValue();
const next = val();
if (!Object.is(cache, next)) {
cache = next;
dirty = false;
@@ -231,33 +241,33 @@
onUnmount(computed.stop);
return computed;
}
if (storageKey)
if (key)
try {
initialValue = JSON.parse(localStorage.getItem(storageKey)) ?? initialValue;
val = JSON.parse(localStorage.getItem(key)) ?? val;
} catch (e) {}
return (...args) => {
if (args.length) {
const next = isFunc(args[0]) ? args[0](initialValue) : args[0];
if (!Object.is(initialValue, next)) {
initialValue = next;
if (storageKey)
localStorage.setItem(storageKey, JSON.stringify(initialValue));
const next = isFunc(args[0]) ? args[0](val) : args[0];
if (!Object.is(val, next)) {
val = next;
if (key)
localStorage.setItem(key, JSON.stringify(val));
trackUpdate(subs, true);
}
}
trackUpdate(subs);
return initialValue;
return val;
};
};
var Watch2 = (sources, callback) => {
if (callback === undefined) {
var Watch2 = (sources, cb) => {
if (cb === undefined) {
const effect2 = createEffect(sources);
effect2();
return () => dispose(effect2);
}
const effect = createEffect(() => {
const vals = isArr(sources) ? sources.map((src) => src()) : sources();
untrack(() => callback(vals));
const vals = Array.isArray(sources) ? sources.map((s) => s()) : sources();
untrack(() => cb(vals));
});
effect();
return () => dispose(effect);
@@ -274,36 +284,20 @@
};
var DANGEROUS_PROTOCOL = /^\s*(javascript|data|vbscript):/i;
var isDangerousAttr = (key) => key === "src" || key === "href" || key.startsWith("on");
var applyProp = (elem, key, value, isSVG) => {
if (value == null || value === false) {
if (key === "class" || key === "className")
elem.className = "";
else if (key in elem && !isSVG)
elem[key] = "";
else
elem.removeAttribute(key);
return;
}
if (key === "class" || key === "className") {
elem.className = value;
} else if (key === "style" && typeof value === "object") {
Object.assign(elem.style, value);
} else if (key in elem && !isSVG) {
elem[key] = value;
} else if (isSVG) {
if (key.startsWith("xlink:")) {
elem.setAttributeNS("http://www.w3.org/1999/xlink", key, value);
} else if (key === "xmlns" || key.startsWith("xmlns:")) {
elem.setAttributeNS("http://www.w3.org/2000/xmlns/", key, value);
} else {
elem.setAttribute(key, value === true ? "" : value);
var validateAttr = (key, val) => {
if (val == null || val === false)
return null;
if (isDangerousAttr(key)) {
const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) {
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`);
return "#";
}
} else {
elem.setAttribute(key, value === true ? "" : value);
}
return val;
};
var Tag2 = (tag, props = {}, children = []) => {
if (props instanceof Node || isArr(props) || props && typeof props !== "object") {
if (props instanceof Node || isArr(props) || !isObj(props)) {
children = props;
props = {};
}
@@ -318,71 +312,75 @@
return result2;
});
effect();
ctx._mounts = effect._mounts || [];
ctx._cleanups = effect._cleanups || new Set;
const result = effect._result;
const attach = (node) => {
if (node && typeof node === "object" && !node._isRuntime) {
node._mounts = ctx._mounts;
node._cleanups = ctx._cleanups;
node._ownerEffect = effect;
}
};
isArr(result) ? result.forEach(attach) : attach(result);
if (result == null)
return null;
if (result instanceof Node || isArr(result) && result.every((n) => n instanceof Node))
return result;
return doc.createTextNode(String(result));
const node = result instanceof Node || isArr(result) && result.every((n) => n instanceof Node) ? result : doc.createTextNode(String(result));
const attach = (n) => {
if (isObj(n) && !n._isRuntime) {
n._mounts = effect._mounts || [];
n._cleanups = effect._cleanups || new Set;
n._ownerEffect = effect;
}
};
isArr(node) ? node.forEach(attach) : attach(node);
return node;
}
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use|image|ellipse|foreignObject|linearGradient|radialGradient|stop|pattern|mask|clipPath|filter|feColorMatrix|feBlend|feGaussianBlur|animate|animateTransform|set|metadata|desc|title|symbol|marker|view)$/i.test(tag);
const elem = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag);
elem._cleanups = new Set;
for (let key in props) {
if (!props.hasOwnProperty(key))
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(tag);
const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag);
el._cleanups = new Set;
for (let k in props) {
if (!props.hasOwnProperty(k))
continue;
let value = props[key];
if (key === "ref") {
isFunc(value) ? value(elem) : value.current = elem;
let v = props[k];
if (k === "ref") {
isFunc(v) ? v(el) : v.current = el;
continue;
}
if (key.startsWith("on")) {
const event = key.slice(2).toLowerCase();
elem.addEventListener(event, value);
const off = () => elem.removeEventListener(event, value);
elem._cleanups.add(off);
if (k.startsWith("on")) {
const ev = k.slice(2).toLowerCase();
el.addEventListener(ev, v);
const off = () => el.removeEventListener(ev, v);
el._cleanups.add(off);
onUnmount(off);
} else if (isFunc(value)) {
} else if (isFunc(v)) {
const effect = createEffect(() => {
let val = value();
if (isDangerousAttr(key) && DANGEROUS_PROTOCOL.test(String(val)))
val = "#";
applyProp(elem, key, val, isSVG);
const val = validateAttr(k, v());
if (k === "class")
el.className = val || "";
else if (val == null)
el.removeAttribute(k);
else if (k in el && !isSVG)
el[k] = val;
else
el.setAttribute(k, val === true ? "" : val);
});
effect();
elem._cleanups.add(() => dispose(effect));
el._cleanups.add(() => dispose(effect));
onUnmount(() => dispose(effect));
if (/^(INPUT|TEXTAREA|SELECT)$/.test(elem.tagName) && (key === "value" || key === "checked")) {
const eventType = key === "checked" ? "change" : "input";
elem.addEventListener(eventType, (ev) => value(ev.target[key]));
if (/^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) && (k === "value" || k === "checked")) {
const evType = k === "checked" ? "change" : "input";
el.addEventListener(evType, (ev) => v(ev.target[k]));
}
} else {
let val = value;
if (isDangerousAttr(key) && DANGEROUS_PROTOCOL.test(String(val)))
val = "#";
if (val != null)
applyProp(elem, key, val, isSVG);
const val = validateAttr(k, v);
if (val != null) {
if (k in el && !isSVG)
el[k] = val;
else
el.setAttribute(k, val === true ? "" : val);
}
}
}
const mountChild = (child) => {
if (isArr(child))
return child.forEach(mountChild);
if (isFunc(child)) {
const append = (c) => {
if (isArr(c))
return c.forEach(append);
if (isFunc(c)) {
const anchor = doc.createTextNode("");
elem.appendChild(anchor);
el.appendChild(anchor);
let currentNodes = [];
const effect = createEffect(() => {
const res = child();
const res = c();
const next = (isArr(res) ? res : [res]).map(ensureNode);
currentNodes.forEach((n) => {
if (n._isRuntime)
@@ -404,55 +402,46 @@
currentNodes = next;
});
effect();
elem._cleanups.add(() => dispose(effect));
el._cleanups.add(() => dispose(effect));
onUnmount(() => dispose(effect));
} else {
const node = ensureNode(child);
elem.appendChild(node);
const node = ensureNode(c);
el.appendChild(node);
if (node._mounts)
node._mounts.forEach((fn) => fn());
}
};
mountChild(children);
return elem;
append(children);
return el;
};
var createView = (renderFn) => {
var Render = (renderFn) => {
const cleanups = new Set;
const mounts = [];
const previousOwner = activeOwner;
activeOwner = { _cleanups: cleanups, _mounts: mounts };
const result = renderFn({ onCleanup: (fn) => cleanups.add(fn) });
activeOwner = previousOwner;
if (result == null)
return null;
if (result instanceof Node) {
mounts.forEach((fn) => fn());
return {
_isRuntime: true,
container: result,
destroy: () => {
cleanups.forEach((fn) => fn());
cleanupNode(result);
result.remove();
}
};
}
const previousEffect = activeEffect;
const container = doc.createElement("div");
container.style.display = "contents";
container.setAttribute("role", "presentation");
const process = (node) => {
if (!node)
activeOwner = { _cleanups: cleanups, _mounts: mounts };
activeEffect = null;
const processResult = (result) => {
if (!result)
return;
if (node._isRuntime) {
cleanups.add(node.destroy);
container.appendChild(node.container);
} else if (isArr(node)) {
node.forEach(process);
if (result._isRuntime) {
cleanups.add(result.destroy);
container.appendChild(result.container);
} else if (isArr(result)) {
result.forEach(processResult);
} else {
container.appendChild(node instanceof Node ? node : doc.createTextNode(String(node)));
container.appendChild(result instanceof Node ? result : doc.createTextNode(String(result == null ? "" : result)));
}
};
process(result);
try {
processResult(renderFn({ onCleanup: (fn) => cleanups.add(fn) }));
} finally {
activeOwner = previousOwner;
activeEffect = previousEffect;
}
mounts.forEach((fn) => fn());
return {
_isRuntime: true,
@@ -494,7 +483,7 @@
}
const content = show ? ifYes : ifNot;
if (content) {
currentView = createView(() => isFunc(content) ? content() : content);
currentView = Render(() => isFunc(content) ? content() : content);
root.insertBefore(currentView.container, anchor);
if (trans?.in)
trans.in(currentView.container);
@@ -515,7 +504,7 @@
const key = keyFn ? keyFn(item, i) : item?.id ?? i;
let view = cache.get(key);
if (!view)
view = createView(() => itemFn(item, i));
view = Render(() => itemFn(item, i));
else
cache.delete(key);
nextCache.set(key, view);
@@ -540,14 +529,14 @@
const handler = () => path(getHash());
window.addEventListener("hashchange", handler);
onUnmount(() => window.removeEventListener("hashchange", handler));
const outlet = Tag2("div", { class: "router-outlet" });
const hook = Tag2("div", { class: "router-hook" });
let currentView = null;
Watch2([path], () => {
const cur = path();
const route = routes.find((r) => {
const rParts = r.path.split("/").filter(Boolean);
const curParts = cur.split("/").filter(Boolean);
return rParts.length === curParts.length && rParts.every((p, i) => p[0] === ":" || p === curParts[i]);
const p1 = r.path.split("/").filter(Boolean);
const p2 = cur.split("/").filter(Boolean);
return p1.length === p2.length && p1.every((p, i) => p[0] === ":" || p === p2[i]);
}) || routes.find((r) => r.path === "*");
if (route) {
currentView?.destroy();
@@ -557,14 +546,14 @@
params[p.slice(1)] = cur.split("/").filter(Boolean)[i];
});
Router.params(params);
currentView = createView(() => isFunc(route.component) ? route.component(params) : route.component);
outlet.replaceChildren(currentView.container);
currentView = Render(() => isFunc(route.component) ? route.component(params) : route.component);
hook.replaceChildren(currentView.container);
}
});
return outlet;
return hook;
};
Router.params = $2({});
Router.to = (path) => window.location.hash = path.replace(/^#?\/?/, "#/");
Router.to = (p) => window.location.hash = p.replace(/^#?\/?/, "#/");
Router.back = () => window.history.back();
Router.path = () => window.location.hash.replace(/^#/, "") || "/";
var Mount2 = (comp, target) => {
@@ -573,24 +562,12 @@
return;
if (MOUNTED_NODES.has(t))
MOUNTED_NODES.get(t).destroy();
const inst = createView(() => isFunc(comp) ? comp() : comp);
const inst = Render(isFunc(comp) ? comp : () => comp);
t.replaceChildren(inst.container);
MOUNTED_NODES.set(t, inst);
return inst;
};
var set = (signal, path, value) => {
if (value === undefined) {
signal(isFunc(path) ? path(signal()) : path);
} else {
const keys = path.split(".");
const last = keys.pop();
const current = signal();
const obj = keys.reduce((o, k) => ({ ...o, [k]: { ...o[k] } }), { ...current });
obj[last] = value;
signal(obj);
}
};
var SigPro = Object.freeze({ $: $2, Watch: Watch2, Tag: Tag2, If: If2, For: For2, Router, Mount: Mount2, onMount, onUnmount, set });
var SigPro = Object.freeze({ $: $2, Watch: Watch2, Tag: Tag2, Render, If: If2, For: For2, Router, Mount: Mount2, onMount, onUnmount, set });
if (typeof window !== "undefined") {
Object.assign(window, SigPro);
"div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer ul ol li a em strong pre code form label input textarea select button img svg".split(" ").forEach((t) => window[t[0].toUpperCase() + t.slice(1)] = (p, c) => SigPro.Tag(t, p, c));
@@ -645,11 +622,11 @@
__export(exports_utils, {
val: () => val,
ui: () => ui,
getIcon: () => getIcon2
getIcon: () => getIcon
});
var val = (t) => typeof t === "function" ? t() : t;
var ui = (baseClass, additionalClassOrFn) => typeof additionalClassOrFn === "function" ? () => `${baseClass} ${additionalClassOrFn() || ""}`.trim() : `${baseClass} ${additionalClassOrFn || ""}`.trim();
var getIcon2 = (icon) => {
var getIcon = (icon) => {
if (!icon)
return null;
if (typeof icon === "function") {
@@ -710,7 +687,7 @@
role: "alert",
class: ui("alert", allClasses)
}, () => [
getIcon2(iconMap[type]),
getIcon(iconMap[type]),
Tag("div", { class: "flex-1" }, [
Tag("span", {}, [typeof content === "function" ? content() : content])
]),
@@ -779,8 +756,8 @@
tel: "icon-[lucide--phone]",
url: "icon-[lucide--link]"
};
const leftIcon = icon ? getIcon2(icon) : iconMap[type] ? getIcon2(iconMap[type]) : null;
const getPasswordIcon = () => getIcon2(visible() ? "icon-[lucide--eye-off]" : "icon-[lucide--eye]");
const leftIcon = icon ? getIcon(icon) : iconMap[type] ? getIcon(iconMap[type]) : null;
const getPasswordIcon = () => getIcon(visible() ? "icon-[lucide--eye-off]" : "icon-[lucide--eye]");
const paddingLeft = leftIcon ? "pl-10" : "";
const paddingRight = isPassword ? "pr-10" : "";
const buttonSize = () => {
@@ -937,7 +914,7 @@
});
var Button = (props, children) => {
const { class: className, loading, icon, ...rest } = props;
const iconEl = getIcon2(icon);
const iconEl = getIcon(icon);
return Tag("button", {
...rest,
class: ui("btn", className),
@@ -1133,7 +1110,7 @@
placeholder: placeholder || (isRangeMode() ? "Seleccionar rango..." : "Seleccionar fecha..."),
value: displayValue,
readonly: true,
icon: getIcon2("icon-[lucide--calendar]"),
icon: getIcon("icon-[lucide--calendar]"),
onclick: (e) => {
e.stopPropagation();
isOpen(!isOpen());
@@ -1146,15 +1123,15 @@
}, [
Tag("div", { class: "flex justify-between items-center mb-4 gap-1" }, [
Tag("div", { class: "flex gap-0.5" }, [
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(-1) }, getIcon2("icon-[lucide--chevrons-left]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(-1) }, getIcon2("icon-[lucide--chevron-left]"))
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(-1) }, getIcon("icon-[lucide--chevrons-left]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(-1) }, getIcon("icon-[lucide--chevron-left]"))
]),
Tag("span", { class: "font-bold uppercase flex-1 text-center" }, [
() => internalDate().toLocaleString("es-ES", { month: "short", year: "numeric" })
]),
Tag("div", { class: "flex gap-0.5" }, [
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(1) }, getIcon2("icon-[lucide--chevron-right]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(1) }, getIcon2("icon-[lucide--chevrons-right]"))
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => move(1) }, getIcon("icon-[lucide--chevron-right]")),
Tag("button", { type: "button", class: "btn btn-ghost btn-xs px-1", onclick: () => moveYear(1) }, getIcon("icon-[lucide--chevrons-right]"))
])
]),
Tag("div", { class: "grid grid-cols-7 gap-1", onmouseleave: () => hoverDate(null) }, [
@@ -1362,7 +1339,7 @@
role: "button",
class: "btn btn-lg btn-circle btn-primary shadow-2xl"
}, [
icon ? getIcon2(icon) : null,
icon ? getIcon(icon) : null,
!icon && label ? label : null
]),
...val(actions).map((act) => Tag("div", { class: "flex items-center gap-3 transition-all duration-300" }, [
@@ -1374,7 +1351,7 @@
e.stopPropagation();
act.onclick?.(e);
}
}, [act.icon ? getIcon2(act.icon) : act.text || ""])
}, [act.icon ? getIcon(act.icon) : act.text || ""])
]))
]);
};
@@ -1449,7 +1426,7 @@
}
}, [
Tag("div", { class: "flex items-center gap-3 w-full" }, [
getIcon2("icon-[lucide--upload]"),
getIcon("icon-[lucide--upload]"),
Tag("span", { class: "text-sm opacity-70 truncate grow text-left" }, "Arrastra o selecciona archivos..."),
Tag("span", { class: "text-[10px] opacity-40 shrink-0" }, `Máx ${max}MB`)
]),
@@ -1478,7 +1455,7 @@
e.stopPropagation();
removeFile(index);
}
}, [getIcon2("icon-[lucide--x]")])
}, [getIcon("icon-[lucide--x]")])
]), (file) => file.name + file.lastModified)
]))
]);
@@ -1826,10 +1803,10 @@
Tabs: () => Tabs
});
var Tabs = (props) => {
const { items, class: className, ...rest } = props;
const { items, class: className, onTabClose, ...rest } = props;
const itemsSignal = typeof items === "function" ? items : () => items || [];
const activeIndex = $(0);
Watch(() => {
const activeIndex = $2(0);
Watch2(() => {
const list = itemsSignal();
const idx = list.findIndex((it) => val(it.active) === true);
if (idx !== -1 && activeIndex() !== idx) {
@@ -1838,7 +1815,9 @@
});
const removeTab = (indexToRemove, item) => {
if (item.onClose)
item.onClose();
item.onClose(item);
if (onTabClose)
onTabClose(item, indexToRemove);
const currentItems = itemsSignal();
const newItems = currentItems.filter((_, idx) => idx !== indexToRemove);
const isWritableSignal = typeof items === "function" && !items._isComputed;
@@ -1856,7 +1835,7 @@
newActive = Math.min(newActive, newItems.length - 1);
activeIndex(newActive);
};
return Tag("div", { ...rest, class: ui("tabs", className) }, () => {
return Tag2("div", { ...rest, class: ui("tabs", className) }, () => {
const list = itemsSignal();
const elements = [];
for (let i = 0;i < list.length; i++) {
@@ -1871,16 +1850,13 @@
e.stopPropagation();
removeTab(i, item);
};
const wrapper = Tag("span", { class: "flex items-center" }, [labelNode, closeIcon]);
const wrapper = Tag2("span", { class: "flex items-center" }, [labelNode, closeIcon]);
buttonChildren.push(wrapper);
} else {
buttonChildren.push(labelNode);
}
const button = Tag("button", {
class: () => {
const isActive = activeIndex() === i;
return ui("tab", isActive ? "tab-active" : "");
},
const buttonBase = Tag2("button", {
class: () => ui("tab", activeIndex() === i ? "tab-active" : ""),
onclick: (e) => {
e.preventDefault();
if (!val(item.disabled)) {
@@ -1888,9 +1864,9 @@
item.onclick();
activeIndex(i);
}
},
title: item.tip || ""
}
}, buttonChildren);
const button = item.tip ? Tag2("div", { class: "tooltip", "data-tip": item.tip }, buttonBase) : buttonBase;
elements.push(button);
let contentNode;
const rawContent = val(item.content);
@@ -1901,8 +1877,8 @@
} else {
contentNode = document.createTextNode(String(rawContent));
}
const inner = Tag("div", { class: "tab-content-inner" }, contentNode);
const panel = Tag("div", {
const inner = Tag2("div", { class: "tab-content-inner" }, contentNode);
const panel = Tag2("div", {
class: "tab-content bg-base-100 border-base-300 p-6",
style: () => activeIndex() === i ? "display: block" : "display: none"
}, inner);
@@ -1941,7 +1917,7 @@
!isFirst ? Tag("hr", { class: () => prevCompleted() ? "bg-primary" : "" }) : null,
Tag("div", { class: "timeline-start" }, [() => renderSlot(item.title)]),
Tag("div", { class: "timeline-middle" }, [
() => item.icon ? getIcon2(item.icon) : getIcon2(iconMap[itemType] || iconMap.success)
() => item.icon ? getIcon(item.icon) : getIcon(iconMap[itemType] || iconMap.success)
]),
Tag("div", { class: "timeline-end timeline-box shadow-sm" }, [() => renderSlot(item.detail)]),
!isLast ? Tag("hr", { class: () => isCompleted() ? "bg-primary" : "" }) : null
@@ -1984,7 +1960,7 @@
}
};
const ToastComponent = () => {
const closeIcon = getIcon2("icon-[lucide--x]");
const closeIcon = getIcon("icon-[lucide--x]");
const el = Tag("div", {
class: `alert alert-soft ${type} shadow-lg transition-all duration-300 translate-x-10 opacity-0 pointer-events-auto`
}, [

File diff suppressed because one or more lines are too long