@tooark/web-components 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +124 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +124 -87
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -2012,6 +2012,7 @@ class ArkCarousel extends HTMLElement {
|
|
|
2012
2012
|
this.currentIndex = 0;
|
|
2013
2013
|
this.autoplayId = null;
|
|
2014
2014
|
this.scrollTimer = null;
|
|
2015
|
+
this.mountFrame = null;
|
|
2015
2016
|
this.observer = null;
|
|
2016
2017
|
this.resizeObserver = null;
|
|
2017
2018
|
this.ownClasses = [];
|
|
@@ -2112,14 +2113,21 @@ class ArkCarousel extends HTMLElement {
|
|
|
2112
2113
|
});
|
|
2113
2114
|
this.resizeObserver.observe(this);
|
|
2114
2115
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2116
|
+
this.currentIndex = this.normalizeIndex(this.getStartIndex());
|
|
2117
|
+
// O offsetLeft dos slides so existe depois do layout, entao o posicionamento inicial espera um frame. Ele parte
|
|
2118
|
+
// do indice ATUAL, nao do start-index: um next()/click no primeiro frame ja mudou o indice e disparou o evento, e
|
|
2119
|
+
// voltar ao inicio aqui deixava a rolagem suave seguir sozinha ate o slide, com um segundo ark-slide-change.
|
|
2120
|
+
this.mountFrame = requestAnimationFrame(() => {
|
|
2121
|
+
this.mountFrame = null;
|
|
2122
|
+
this.goTo(this.currentIndex, { behavior: "auto" });
|
|
2119
2123
|
this.startAutoplay();
|
|
2120
2124
|
});
|
|
2121
2125
|
}
|
|
2122
2126
|
disconnectedCallback() {
|
|
2127
|
+
if (this.mountFrame !== null) {
|
|
2128
|
+
cancelAnimationFrame(this.mountFrame);
|
|
2129
|
+
this.mountFrame = null;
|
|
2130
|
+
}
|
|
2123
2131
|
this.stopAutoplay();
|
|
2124
2132
|
this.observer?.disconnect();
|
|
2125
2133
|
this.observer = null;
|
|
@@ -11426,6 +11434,9 @@ class ArkToaster extends HTMLElement {
|
|
|
11426
11434
|
this.timers.clear();
|
|
11427
11435
|
}
|
|
11428
11436
|
attributeChangedCallback() {
|
|
11437
|
+
// Posição, rich-colors, close-button, lang e testid mudam os cards já montados: recria todos (sem reanimar a
|
|
11438
|
+
// entrada, que `entered` lembra).
|
|
11439
|
+
this.root?.replaceChildren();
|
|
11429
11440
|
this.render();
|
|
11430
11441
|
}
|
|
11431
11442
|
toast(options) {
|
|
@@ -11436,6 +11447,11 @@ class ArkToaster extends HTMLElement {
|
|
|
11436
11447
|
createdAt: Date.now(),
|
|
11437
11448
|
type: options.type || "default"
|
|
11438
11449
|
};
|
|
11450
|
+
// Mesmo id: o card antigo sai e o toast volta ao topo como um novo.
|
|
11451
|
+
if (this.toasts.some((toast) => toast.id === id)) {
|
|
11452
|
+
this.cardOf(id)?.remove();
|
|
11453
|
+
this.entered.delete(id);
|
|
11454
|
+
}
|
|
11439
11455
|
this.toasts = [item, ...this.toasts.filter((toast) => toast.id !== id)];
|
|
11440
11456
|
const maxVisible = this.getMaxVisible();
|
|
11441
11457
|
if (this.toasts.length > maxVisible) {
|
|
@@ -11467,7 +11483,7 @@ class ArkToaster extends HTMLElement {
|
|
|
11467
11483
|
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
11468
11484
|
this.render();
|
|
11469
11485
|
};
|
|
11470
|
-
const card = this.
|
|
11486
|
+
const card = this.cardOf(id);
|
|
11471
11487
|
if (card) {
|
|
11472
11488
|
this.exiting.add(id);
|
|
11473
11489
|
core.arkExit(card, this.getExitPreset()).then(finalize);
|
|
@@ -11476,6 +11492,9 @@ class ArkToaster extends HTMLElement {
|
|
|
11476
11492
|
finalize();
|
|
11477
11493
|
}
|
|
11478
11494
|
}
|
|
11495
|
+
cardOf(id) {
|
|
11496
|
+
return this.root?.querySelector(`[data-toast-id="${CSS.escape(id)}"]`) ?? null;
|
|
11497
|
+
}
|
|
11479
11498
|
getPosition() {
|
|
11480
11499
|
const position = (this.getAttribute("position") || "bottom-right").toLowerCase();
|
|
11481
11500
|
if (position === "top-left" ||
|
|
@@ -11633,15 +11652,14 @@ class ArkToaster extends HTMLElement {
|
|
|
11633
11652
|
}
|
|
11634
11653
|
this.render();
|
|
11635
11654
|
}
|
|
11655
|
+
// Incremental: os cards da lista ficam onde estão (recriar um card focado jogaria o foco do teclado no body e
|
|
11656
|
+
// o leitor de tela perderia o toast que estava lendo, e um card em saída perderia a animação), os que saíram da
|
|
11657
|
+
// lista vão embora e só os novos são criados, cada um na posição da lista (o mais novo no topo).
|
|
11636
11658
|
render() {
|
|
11637
11659
|
if (!this.root)
|
|
11638
11660
|
return;
|
|
11639
|
-
const position = this.getPosition();
|
|
11640
|
-
const richColors = this.hasRichColors();
|
|
11641
|
-
const closeButton = this.hasCloseButton();
|
|
11642
11661
|
const palette = this.getPalette();
|
|
11643
|
-
this.root.className = `${palette.stack} ${this.getPositionClasses(
|
|
11644
|
-
this.root.innerHTML = "";
|
|
11662
|
+
this.root.className = `${palette.stack} ${this.getPositionClasses(this.getPosition())}`;
|
|
11645
11663
|
applyTestHooks(this, "toaster", this.root);
|
|
11646
11664
|
this.syncPopover();
|
|
11647
11665
|
const activeIds = new Set(this.toasts.map((toast) => toast.id));
|
|
@@ -11649,85 +11667,101 @@ class ArkToaster extends HTMLElement {
|
|
|
11649
11667
|
if (!activeIds.has(id))
|
|
11650
11668
|
this.entered.delete(id);
|
|
11651
11669
|
}
|
|
11652
|
-
|
|
11653
|
-
|
|
11654
|
-
card.
|
|
11655
|
-
|
|
11656
|
-
|
|
11657
|
-
applyTestHooks(this, "toaster", card, "toast");
|
|
11658
|
-
card.className = `${palette.toastBase} ${this.getToastTypeClasses(toast.type, richColors)}`.trim();
|
|
11659
|
-
const row = document.createElement("div");
|
|
11660
|
-
row.className = "ark:flex ark:items-start ark:gap-3";
|
|
11661
|
-
const icon = document.createElement("span");
|
|
11662
|
-
icon.className = `${palette.icon} ark:mt-0.5 ark:inline-flex ark:h-5 ark:w-5 ark:items-center ark:justify-center ark:rounded-full ark:border ark:border-current/20`;
|
|
11663
|
-
icon.textContent = this.getToastIcon(toast.type);
|
|
11664
|
-
const content = document.createElement("div");
|
|
11665
|
-
content.className = "ark:min-w-0 ark:flex-1";
|
|
11666
|
-
const title = document.createElement("h4");
|
|
11667
|
-
title.className = palette.title;
|
|
11668
|
-
applyTestHooks(this, "toaster", title, "toast-title");
|
|
11669
|
-
title.textContent = toast.title;
|
|
11670
|
-
content.appendChild(title);
|
|
11671
|
-
if (toast.description) {
|
|
11672
|
-
const description = document.createElement("p");
|
|
11673
|
-
description.className = palette.description;
|
|
11674
|
-
applyTestHooks(this, "toaster", description, "toast-description");
|
|
11675
|
-
description.textContent = toast.description;
|
|
11676
|
-
content.appendChild(description);
|
|
11677
|
-
}
|
|
11678
|
-
row.appendChild(icon);
|
|
11679
|
-
row.appendChild(content);
|
|
11680
|
-
if (closeButton) {
|
|
11681
|
-
const close = document.createElement("button");
|
|
11682
|
-
close.type = "button";
|
|
11683
|
-
close.className = palette.closeButton;
|
|
11684
|
-
applyTestHooks(this, "toaster", close, "toast-close");
|
|
11685
|
-
close.textContent = this.getCloseLabel();
|
|
11686
|
-
close.addEventListener("click", () => this.dismiss(toast.id));
|
|
11687
|
-
row.appendChild(close);
|
|
11688
|
-
}
|
|
11689
|
-
card.appendChild(row);
|
|
11690
|
-
if (toast.actionLabel || toast.cancelLabel) {
|
|
11691
|
-
const actions = document.createElement("div");
|
|
11692
|
-
actions.className = "ark:mt-3 ark:flex ark:items-center ark:justify-end ark:gap-2";
|
|
11693
|
-
if (toast.cancelLabel) {
|
|
11694
|
-
const cancel = document.createElement("button");
|
|
11695
|
-
cancel.type = "button";
|
|
11696
|
-
cancel.className = palette.cancelButton;
|
|
11697
|
-
applyTestHooks(this, "toaster", cancel, "toast-cancel");
|
|
11698
|
-
cancel.textContent = toast.cancelLabel;
|
|
11699
|
-
cancel.addEventListener("click", () => this.dismiss(toast.id));
|
|
11700
|
-
actions.appendChild(cancel);
|
|
11701
|
-
}
|
|
11702
|
-
if (toast.actionLabel) {
|
|
11703
|
-
const action = document.createElement("button");
|
|
11704
|
-
action.type = "button";
|
|
11705
|
-
action.className = palette.actionButton;
|
|
11706
|
-
applyTestHooks(this, "toaster", action, "toast-action");
|
|
11707
|
-
action.textContent = toast.actionLabel;
|
|
11708
|
-
action.addEventListener("click", () => {
|
|
11709
|
-
this.dispatchEvent(new CustomEvent("ark-toast-action", {
|
|
11710
|
-
detail: { id: toast.id, actionId: toast.actionId || null },
|
|
11711
|
-
bubbles: true,
|
|
11712
|
-
composed: true
|
|
11713
|
-
}));
|
|
11714
|
-
this.dismiss(toast.id);
|
|
11715
|
-
});
|
|
11716
|
-
actions.appendChild(action);
|
|
11717
|
-
}
|
|
11718
|
-
card.appendChild(actions);
|
|
11670
|
+
const existing = new Map();
|
|
11671
|
+
for (const card of Array.from(this.root.querySelectorAll("[data-toast-id]"))) {
|
|
11672
|
+
const id = card.dataset.toastId ?? "";
|
|
11673
|
+
if (activeIds.has(id)) {
|
|
11674
|
+
existing.set(id, card);
|
|
11719
11675
|
}
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
11723
|
-
|
|
11724
|
-
|
|
11676
|
+
else {
|
|
11677
|
+
card.remove();
|
|
11678
|
+
}
|
|
11679
|
+
}
|
|
11680
|
+
// Do mais antigo (fim da pilha) ao mais novo: um card novo entra antes do card do toast seguinte na lista.
|
|
11681
|
+
let next = null;
|
|
11682
|
+
for (let index = this.toasts.length - 1; index >= 0; index--) {
|
|
11683
|
+
const toast = this.toasts[index];
|
|
11684
|
+
let card = existing.get(toast.id);
|
|
11685
|
+
if (!card) {
|
|
11686
|
+
card = this.buildCard(toast, palette);
|
|
11687
|
+
this.root.insertBefore(card, next);
|
|
11688
|
+
if (!this.entered.has(toast.id)) {
|
|
11689
|
+
this.entered.add(toast.id);
|
|
11690
|
+
core.arkEnter(card, this.getEnterPreset());
|
|
11691
|
+
}
|
|
11725
11692
|
}
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11693
|
+
next = card;
|
|
11694
|
+
}
|
|
11695
|
+
}
|
|
11696
|
+
buildCard(toast, palette) {
|
|
11697
|
+
const card = document.createElement("section");
|
|
11698
|
+
card.setAttribute("part", "toast");
|
|
11699
|
+
card.dataset.toastId = toast.id;
|
|
11700
|
+
// Cada card compartilha o hook "toaster-toast"; desambigue via data-toast-id.
|
|
11701
|
+
applyTestHooks(this, "toaster", card, "toast");
|
|
11702
|
+
card.className = `${palette.toastBase} ${this.getToastTypeClasses(toast.type, this.hasRichColors())}`.trim();
|
|
11703
|
+
const row = document.createElement("div");
|
|
11704
|
+
row.className = "ark:flex ark:items-start ark:gap-3";
|
|
11705
|
+
const icon = document.createElement("span");
|
|
11706
|
+
icon.className = `${palette.icon} ark:mt-0.5 ark:inline-flex ark:h-5 ark:w-5 ark:items-center ark:justify-center ark:rounded-full ark:border ark:border-current/20`;
|
|
11707
|
+
icon.textContent = this.getToastIcon(toast.type);
|
|
11708
|
+
const content = document.createElement("div");
|
|
11709
|
+
content.className = "ark:min-w-0 ark:flex-1";
|
|
11710
|
+
const title = document.createElement("h4");
|
|
11711
|
+
title.className = palette.title;
|
|
11712
|
+
applyTestHooks(this, "toaster", title, "toast-title");
|
|
11713
|
+
title.textContent = toast.title;
|
|
11714
|
+
content.appendChild(title);
|
|
11715
|
+
if (toast.description) {
|
|
11716
|
+
const description = document.createElement("p");
|
|
11717
|
+
description.className = palette.description;
|
|
11718
|
+
applyTestHooks(this, "toaster", description, "toast-description");
|
|
11719
|
+
description.textContent = toast.description;
|
|
11720
|
+
content.appendChild(description);
|
|
11721
|
+
}
|
|
11722
|
+
row.appendChild(icon);
|
|
11723
|
+
row.appendChild(content);
|
|
11724
|
+
if (this.hasCloseButton()) {
|
|
11725
|
+
const close = document.createElement("button");
|
|
11726
|
+
close.type = "button";
|
|
11727
|
+
close.className = palette.closeButton;
|
|
11728
|
+
applyTestHooks(this, "toaster", close, "toast-close");
|
|
11729
|
+
close.textContent = this.getCloseLabel();
|
|
11730
|
+
close.addEventListener("click", () => this.dismiss(toast.id));
|
|
11731
|
+
row.appendChild(close);
|
|
11732
|
+
}
|
|
11733
|
+
card.appendChild(row);
|
|
11734
|
+
if (toast.actionLabel || toast.cancelLabel) {
|
|
11735
|
+
const actions = document.createElement("div");
|
|
11736
|
+
actions.className = "ark:mt-3 ark:flex ark:items-center ark:justify-end ark:gap-2";
|
|
11737
|
+
if (toast.cancelLabel) {
|
|
11738
|
+
const cancel = document.createElement("button");
|
|
11739
|
+
cancel.type = "button";
|
|
11740
|
+
cancel.className = palette.cancelButton;
|
|
11741
|
+
applyTestHooks(this, "toaster", cancel, "toast-cancel");
|
|
11742
|
+
cancel.textContent = toast.cancelLabel;
|
|
11743
|
+
cancel.addEventListener("click", () => this.dismiss(toast.id));
|
|
11744
|
+
actions.appendChild(cancel);
|
|
11745
|
+
}
|
|
11746
|
+
if (toast.actionLabel) {
|
|
11747
|
+
const action = document.createElement("button");
|
|
11748
|
+
action.type = "button";
|
|
11749
|
+
action.className = palette.actionButton;
|
|
11750
|
+
applyTestHooks(this, "toaster", action, "toast-action");
|
|
11751
|
+
action.textContent = toast.actionLabel;
|
|
11752
|
+
action.addEventListener("click", () => {
|
|
11753
|
+
this.dispatchEvent(new CustomEvent("ark-toast-action", {
|
|
11754
|
+
detail: { id: toast.id, actionId: toast.actionId || null },
|
|
11755
|
+
bubbles: true,
|
|
11756
|
+
composed: true
|
|
11757
|
+
}));
|
|
11758
|
+
this.dismiss(toast.id);
|
|
11759
|
+
});
|
|
11760
|
+
actions.appendChild(action);
|
|
11729
11761
|
}
|
|
11762
|
+
card.appendChild(actions);
|
|
11730
11763
|
}
|
|
11764
|
+
return card;
|
|
11731
11765
|
}
|
|
11732
11766
|
}
|
|
11733
11767
|
ArkToaster.tagName = "ark-toaster";
|
|
@@ -12049,8 +12083,11 @@ class ArkToggleGroup extends HTMLElement {
|
|
|
12049
12083
|
if (theme)
|
|
12050
12084
|
toggle.setAttribute("theme", theme);
|
|
12051
12085
|
if (disabled) {
|
|
12052
|
-
|
|
12053
|
-
toggle.
|
|
12086
|
+
// Um item já desabilitado por conta própria não leva a marca do grupo, senão ela apagaria o individual.
|
|
12087
|
+
if (!toggle.hasAttribute("disabled")) {
|
|
12088
|
+
toggle.setAttribute("disabled", "");
|
|
12089
|
+
toggle.dataset.groupDisabled = "true";
|
|
12090
|
+
}
|
|
12054
12091
|
}
|
|
12055
12092
|
else if (toggle.dataset.groupDisabled) {
|
|
12056
12093
|
// Só remove o "disabled" que o próprio grupo aplicou; preserva o individual.
|