@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.d.cts
CHANGED
|
@@ -220,6 +220,7 @@ declare class ArkCarousel extends HTMLElement {
|
|
|
220
220
|
private currentIndex;
|
|
221
221
|
private autoplayId;
|
|
222
222
|
private scrollTimer;
|
|
223
|
+
private mountFrame;
|
|
223
224
|
private observer;
|
|
224
225
|
private resizeObserver;
|
|
225
226
|
private ownClasses;
|
|
@@ -924,6 +925,7 @@ declare class ArkToaster extends HTMLElement {
|
|
|
924
925
|
attributeChangedCallback(): void;
|
|
925
926
|
toast(options: ArkToastOptions): string;
|
|
926
927
|
dismiss(id?: string): void;
|
|
928
|
+
private cardOf;
|
|
927
929
|
private readonly handleToast;
|
|
928
930
|
private readonly handleDismiss;
|
|
929
931
|
private getPosition;
|
|
@@ -944,6 +946,7 @@ declare class ArkToaster extends HTMLElement {
|
|
|
944
946
|
private getToastIcon;
|
|
945
947
|
private build;
|
|
946
948
|
private render;
|
|
949
|
+
private buildCard;
|
|
947
950
|
}
|
|
948
951
|
|
|
949
952
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -220,6 +220,7 @@ declare class ArkCarousel extends HTMLElement {
|
|
|
220
220
|
private currentIndex;
|
|
221
221
|
private autoplayId;
|
|
222
222
|
private scrollTimer;
|
|
223
|
+
private mountFrame;
|
|
223
224
|
private observer;
|
|
224
225
|
private resizeObserver;
|
|
225
226
|
private ownClasses;
|
|
@@ -924,6 +925,7 @@ declare class ArkToaster extends HTMLElement {
|
|
|
924
925
|
attributeChangedCallback(): void;
|
|
925
926
|
toast(options: ArkToastOptions): string;
|
|
926
927
|
dismiss(id?: string): void;
|
|
928
|
+
private cardOf;
|
|
927
929
|
private readonly handleToast;
|
|
928
930
|
private readonly handleDismiss;
|
|
929
931
|
private getPosition;
|
|
@@ -944,6 +946,7 @@ declare class ArkToaster extends HTMLElement {
|
|
|
944
946
|
private getToastIcon;
|
|
945
947
|
private build;
|
|
946
948
|
private render;
|
|
949
|
+
private buildCard;
|
|
947
950
|
}
|
|
948
951
|
|
|
949
952
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2010,6 +2010,7 @@ class ArkCarousel extends HTMLElement {
|
|
|
2010
2010
|
this.currentIndex = 0;
|
|
2011
2011
|
this.autoplayId = null;
|
|
2012
2012
|
this.scrollTimer = null;
|
|
2013
|
+
this.mountFrame = null;
|
|
2013
2014
|
this.observer = null;
|
|
2014
2015
|
this.resizeObserver = null;
|
|
2015
2016
|
this.ownClasses = [];
|
|
@@ -2110,14 +2111,21 @@ class ArkCarousel extends HTMLElement {
|
|
|
2110
2111
|
});
|
|
2111
2112
|
this.resizeObserver.observe(this);
|
|
2112
2113
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2114
|
+
this.currentIndex = this.normalizeIndex(this.getStartIndex());
|
|
2115
|
+
// O offsetLeft dos slides so existe depois do layout, entao o posicionamento inicial espera um frame. Ele parte
|
|
2116
|
+
// do indice ATUAL, nao do start-index: um next()/click no primeiro frame ja mudou o indice e disparou o evento, e
|
|
2117
|
+
// voltar ao inicio aqui deixava a rolagem suave seguir sozinha ate o slide, com um segundo ark-slide-change.
|
|
2118
|
+
this.mountFrame = requestAnimationFrame(() => {
|
|
2119
|
+
this.mountFrame = null;
|
|
2120
|
+
this.goTo(this.currentIndex, { behavior: "auto" });
|
|
2117
2121
|
this.startAutoplay();
|
|
2118
2122
|
});
|
|
2119
2123
|
}
|
|
2120
2124
|
disconnectedCallback() {
|
|
2125
|
+
if (this.mountFrame !== null) {
|
|
2126
|
+
cancelAnimationFrame(this.mountFrame);
|
|
2127
|
+
this.mountFrame = null;
|
|
2128
|
+
}
|
|
2121
2129
|
this.stopAutoplay();
|
|
2122
2130
|
this.observer?.disconnect();
|
|
2123
2131
|
this.observer = null;
|
|
@@ -11424,6 +11432,9 @@ class ArkToaster extends HTMLElement {
|
|
|
11424
11432
|
this.timers.clear();
|
|
11425
11433
|
}
|
|
11426
11434
|
attributeChangedCallback() {
|
|
11435
|
+
// Posição, rich-colors, close-button, lang e testid mudam os cards já montados: recria todos (sem reanimar a
|
|
11436
|
+
// entrada, que `entered` lembra).
|
|
11437
|
+
this.root?.replaceChildren();
|
|
11427
11438
|
this.render();
|
|
11428
11439
|
}
|
|
11429
11440
|
toast(options) {
|
|
@@ -11434,6 +11445,11 @@ class ArkToaster extends HTMLElement {
|
|
|
11434
11445
|
createdAt: Date.now(),
|
|
11435
11446
|
type: options.type || "default"
|
|
11436
11447
|
};
|
|
11448
|
+
// Mesmo id: o card antigo sai e o toast volta ao topo como um novo.
|
|
11449
|
+
if (this.toasts.some((toast) => toast.id === id)) {
|
|
11450
|
+
this.cardOf(id)?.remove();
|
|
11451
|
+
this.entered.delete(id);
|
|
11452
|
+
}
|
|
11437
11453
|
this.toasts = [item, ...this.toasts.filter((toast) => toast.id !== id)];
|
|
11438
11454
|
const maxVisible = this.getMaxVisible();
|
|
11439
11455
|
if (this.toasts.length > maxVisible) {
|
|
@@ -11465,7 +11481,7 @@ class ArkToaster extends HTMLElement {
|
|
|
11465
11481
|
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
11466
11482
|
this.render();
|
|
11467
11483
|
};
|
|
11468
|
-
const card = this.
|
|
11484
|
+
const card = this.cardOf(id);
|
|
11469
11485
|
if (card) {
|
|
11470
11486
|
this.exiting.add(id);
|
|
11471
11487
|
arkExit(card, this.getExitPreset()).then(finalize);
|
|
@@ -11474,6 +11490,9 @@ class ArkToaster extends HTMLElement {
|
|
|
11474
11490
|
finalize();
|
|
11475
11491
|
}
|
|
11476
11492
|
}
|
|
11493
|
+
cardOf(id) {
|
|
11494
|
+
return this.root?.querySelector(`[data-toast-id="${CSS.escape(id)}"]`) ?? null;
|
|
11495
|
+
}
|
|
11477
11496
|
getPosition() {
|
|
11478
11497
|
const position = (this.getAttribute("position") || "bottom-right").toLowerCase();
|
|
11479
11498
|
if (position === "top-left" ||
|
|
@@ -11631,15 +11650,14 @@ class ArkToaster extends HTMLElement {
|
|
|
11631
11650
|
}
|
|
11632
11651
|
this.render();
|
|
11633
11652
|
}
|
|
11653
|
+
// Incremental: os cards da lista ficam onde estão (recriar um card focado jogaria o foco do teclado no body e
|
|
11654
|
+
// 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
|
|
11655
|
+
// lista vão embora e só os novos são criados, cada um na posição da lista (o mais novo no topo).
|
|
11634
11656
|
render() {
|
|
11635
11657
|
if (!this.root)
|
|
11636
11658
|
return;
|
|
11637
|
-
const position = this.getPosition();
|
|
11638
|
-
const richColors = this.hasRichColors();
|
|
11639
|
-
const closeButton = this.hasCloseButton();
|
|
11640
11659
|
const palette = this.getPalette();
|
|
11641
|
-
this.root.className = `${palette.stack} ${this.getPositionClasses(
|
|
11642
|
-
this.root.innerHTML = "";
|
|
11660
|
+
this.root.className = `${palette.stack} ${this.getPositionClasses(this.getPosition())}`;
|
|
11643
11661
|
applyTestHooks(this, "toaster", this.root);
|
|
11644
11662
|
this.syncPopover();
|
|
11645
11663
|
const activeIds = new Set(this.toasts.map((toast) => toast.id));
|
|
@@ -11647,85 +11665,101 @@ class ArkToaster extends HTMLElement {
|
|
|
11647
11665
|
if (!activeIds.has(id))
|
|
11648
11666
|
this.entered.delete(id);
|
|
11649
11667
|
}
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
card.
|
|
11653
|
-
|
|
11654
|
-
|
|
11655
|
-
applyTestHooks(this, "toaster", card, "toast");
|
|
11656
|
-
card.className = `${palette.toastBase} ${this.getToastTypeClasses(toast.type, richColors)}`.trim();
|
|
11657
|
-
const row = document.createElement("div");
|
|
11658
|
-
row.className = "ark:flex ark:items-start ark:gap-3";
|
|
11659
|
-
const icon = document.createElement("span");
|
|
11660
|
-
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`;
|
|
11661
|
-
icon.textContent = this.getToastIcon(toast.type);
|
|
11662
|
-
const content = document.createElement("div");
|
|
11663
|
-
content.className = "ark:min-w-0 ark:flex-1";
|
|
11664
|
-
const title = document.createElement("h4");
|
|
11665
|
-
title.className = palette.title;
|
|
11666
|
-
applyTestHooks(this, "toaster", title, "toast-title");
|
|
11667
|
-
title.textContent = toast.title;
|
|
11668
|
-
content.appendChild(title);
|
|
11669
|
-
if (toast.description) {
|
|
11670
|
-
const description = document.createElement("p");
|
|
11671
|
-
description.className = palette.description;
|
|
11672
|
-
applyTestHooks(this, "toaster", description, "toast-description");
|
|
11673
|
-
description.textContent = toast.description;
|
|
11674
|
-
content.appendChild(description);
|
|
11675
|
-
}
|
|
11676
|
-
row.appendChild(icon);
|
|
11677
|
-
row.appendChild(content);
|
|
11678
|
-
if (closeButton) {
|
|
11679
|
-
const close = document.createElement("button");
|
|
11680
|
-
close.type = "button";
|
|
11681
|
-
close.className = palette.closeButton;
|
|
11682
|
-
applyTestHooks(this, "toaster", close, "toast-close");
|
|
11683
|
-
close.textContent = this.getCloseLabel();
|
|
11684
|
-
close.addEventListener("click", () => this.dismiss(toast.id));
|
|
11685
|
-
row.appendChild(close);
|
|
11686
|
-
}
|
|
11687
|
-
card.appendChild(row);
|
|
11688
|
-
if (toast.actionLabel || toast.cancelLabel) {
|
|
11689
|
-
const actions = document.createElement("div");
|
|
11690
|
-
actions.className = "ark:mt-3 ark:flex ark:items-center ark:justify-end ark:gap-2";
|
|
11691
|
-
if (toast.cancelLabel) {
|
|
11692
|
-
const cancel = document.createElement("button");
|
|
11693
|
-
cancel.type = "button";
|
|
11694
|
-
cancel.className = palette.cancelButton;
|
|
11695
|
-
applyTestHooks(this, "toaster", cancel, "toast-cancel");
|
|
11696
|
-
cancel.textContent = toast.cancelLabel;
|
|
11697
|
-
cancel.addEventListener("click", () => this.dismiss(toast.id));
|
|
11698
|
-
actions.appendChild(cancel);
|
|
11699
|
-
}
|
|
11700
|
-
if (toast.actionLabel) {
|
|
11701
|
-
const action = document.createElement("button");
|
|
11702
|
-
action.type = "button";
|
|
11703
|
-
action.className = palette.actionButton;
|
|
11704
|
-
applyTestHooks(this, "toaster", action, "toast-action");
|
|
11705
|
-
action.textContent = toast.actionLabel;
|
|
11706
|
-
action.addEventListener("click", () => {
|
|
11707
|
-
this.dispatchEvent(new CustomEvent("ark-toast-action", {
|
|
11708
|
-
detail: { id: toast.id, actionId: toast.actionId || null },
|
|
11709
|
-
bubbles: true,
|
|
11710
|
-
composed: true
|
|
11711
|
-
}));
|
|
11712
|
-
this.dismiss(toast.id);
|
|
11713
|
-
});
|
|
11714
|
-
actions.appendChild(action);
|
|
11715
|
-
}
|
|
11716
|
-
card.appendChild(actions);
|
|
11668
|
+
const existing = new Map();
|
|
11669
|
+
for (const card of Array.from(this.root.querySelectorAll("[data-toast-id]"))) {
|
|
11670
|
+
const id = card.dataset.toastId ?? "";
|
|
11671
|
+
if (activeIds.has(id)) {
|
|
11672
|
+
existing.set(id, card);
|
|
11717
11673
|
}
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
11674
|
+
else {
|
|
11675
|
+
card.remove();
|
|
11676
|
+
}
|
|
11677
|
+
}
|
|
11678
|
+
// Do mais antigo (fim da pilha) ao mais novo: um card novo entra antes do card do toast seguinte na lista.
|
|
11679
|
+
let next = null;
|
|
11680
|
+
for (let index = this.toasts.length - 1; index >= 0; index--) {
|
|
11681
|
+
const toast = this.toasts[index];
|
|
11682
|
+
let card = existing.get(toast.id);
|
|
11683
|
+
if (!card) {
|
|
11684
|
+
card = this.buildCard(toast, palette);
|
|
11685
|
+
this.root.insertBefore(card, next);
|
|
11686
|
+
if (!this.entered.has(toast.id)) {
|
|
11687
|
+
this.entered.add(toast.id);
|
|
11688
|
+
arkEnter(card, this.getEnterPreset());
|
|
11689
|
+
}
|
|
11723
11690
|
}
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11691
|
+
next = card;
|
|
11692
|
+
}
|
|
11693
|
+
}
|
|
11694
|
+
buildCard(toast, palette) {
|
|
11695
|
+
const card = document.createElement("section");
|
|
11696
|
+
card.setAttribute("part", "toast");
|
|
11697
|
+
card.dataset.toastId = toast.id;
|
|
11698
|
+
// Cada card compartilha o hook "toaster-toast"; desambigue via data-toast-id.
|
|
11699
|
+
applyTestHooks(this, "toaster", card, "toast");
|
|
11700
|
+
card.className = `${palette.toastBase} ${this.getToastTypeClasses(toast.type, this.hasRichColors())}`.trim();
|
|
11701
|
+
const row = document.createElement("div");
|
|
11702
|
+
row.className = "ark:flex ark:items-start ark:gap-3";
|
|
11703
|
+
const icon = document.createElement("span");
|
|
11704
|
+
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`;
|
|
11705
|
+
icon.textContent = this.getToastIcon(toast.type);
|
|
11706
|
+
const content = document.createElement("div");
|
|
11707
|
+
content.className = "ark:min-w-0 ark:flex-1";
|
|
11708
|
+
const title = document.createElement("h4");
|
|
11709
|
+
title.className = palette.title;
|
|
11710
|
+
applyTestHooks(this, "toaster", title, "toast-title");
|
|
11711
|
+
title.textContent = toast.title;
|
|
11712
|
+
content.appendChild(title);
|
|
11713
|
+
if (toast.description) {
|
|
11714
|
+
const description = document.createElement("p");
|
|
11715
|
+
description.className = palette.description;
|
|
11716
|
+
applyTestHooks(this, "toaster", description, "toast-description");
|
|
11717
|
+
description.textContent = toast.description;
|
|
11718
|
+
content.appendChild(description);
|
|
11719
|
+
}
|
|
11720
|
+
row.appendChild(icon);
|
|
11721
|
+
row.appendChild(content);
|
|
11722
|
+
if (this.hasCloseButton()) {
|
|
11723
|
+
const close = document.createElement("button");
|
|
11724
|
+
close.type = "button";
|
|
11725
|
+
close.className = palette.closeButton;
|
|
11726
|
+
applyTestHooks(this, "toaster", close, "toast-close");
|
|
11727
|
+
close.textContent = this.getCloseLabel();
|
|
11728
|
+
close.addEventListener("click", () => this.dismiss(toast.id));
|
|
11729
|
+
row.appendChild(close);
|
|
11730
|
+
}
|
|
11731
|
+
card.appendChild(row);
|
|
11732
|
+
if (toast.actionLabel || toast.cancelLabel) {
|
|
11733
|
+
const actions = document.createElement("div");
|
|
11734
|
+
actions.className = "ark:mt-3 ark:flex ark:items-center ark:justify-end ark:gap-2";
|
|
11735
|
+
if (toast.cancelLabel) {
|
|
11736
|
+
const cancel = document.createElement("button");
|
|
11737
|
+
cancel.type = "button";
|
|
11738
|
+
cancel.className = palette.cancelButton;
|
|
11739
|
+
applyTestHooks(this, "toaster", cancel, "toast-cancel");
|
|
11740
|
+
cancel.textContent = toast.cancelLabel;
|
|
11741
|
+
cancel.addEventListener("click", () => this.dismiss(toast.id));
|
|
11742
|
+
actions.appendChild(cancel);
|
|
11743
|
+
}
|
|
11744
|
+
if (toast.actionLabel) {
|
|
11745
|
+
const action = document.createElement("button");
|
|
11746
|
+
action.type = "button";
|
|
11747
|
+
action.className = palette.actionButton;
|
|
11748
|
+
applyTestHooks(this, "toaster", action, "toast-action");
|
|
11749
|
+
action.textContent = toast.actionLabel;
|
|
11750
|
+
action.addEventListener("click", () => {
|
|
11751
|
+
this.dispatchEvent(new CustomEvent("ark-toast-action", {
|
|
11752
|
+
detail: { id: toast.id, actionId: toast.actionId || null },
|
|
11753
|
+
bubbles: true,
|
|
11754
|
+
composed: true
|
|
11755
|
+
}));
|
|
11756
|
+
this.dismiss(toast.id);
|
|
11757
|
+
});
|
|
11758
|
+
actions.appendChild(action);
|
|
11727
11759
|
}
|
|
11760
|
+
card.appendChild(actions);
|
|
11728
11761
|
}
|
|
11762
|
+
return card;
|
|
11729
11763
|
}
|
|
11730
11764
|
}
|
|
11731
11765
|
ArkToaster.tagName = "ark-toaster";
|
|
@@ -12047,8 +12081,11 @@ class ArkToggleGroup extends HTMLElement {
|
|
|
12047
12081
|
if (theme)
|
|
12048
12082
|
toggle.setAttribute("theme", theme);
|
|
12049
12083
|
if (disabled) {
|
|
12050
|
-
|
|
12051
|
-
toggle.
|
|
12084
|
+
// Um item já desabilitado por conta própria não leva a marca do grupo, senão ela apagaria o individual.
|
|
12085
|
+
if (!toggle.hasAttribute("disabled")) {
|
|
12086
|
+
toggle.setAttribute("disabled", "");
|
|
12087
|
+
toggle.dataset.groupDisabled = "true";
|
|
12088
|
+
}
|
|
12052
12089
|
}
|
|
12053
12090
|
else if (toggle.dataset.groupDisabled) {
|
|
12054
12091
|
// Só remove o "disabled" que o próprio grupo aplicou; preserva o individual.
|