staffa 0.4.0 → 0.4.2
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/README.md +34 -29
- package/dist/components/autocomplete.d.ts +9 -2
- package/dist/components/autocomplete.js +9 -2
- package/dist/components/box.d.ts +1 -0
- package/dist/components/box.js +1 -0
- package/dist/components/button.d.ts +1 -0
- package/dist/components/button.js +5 -5
- package/dist/components/buttonGroup.d.ts +5 -3
- package/dist/components/buttonGroup.js +5 -3
- package/dist/components/checkbox.d.ts +1 -0
- package/dist/components/checkbox.js +1 -0
- package/dist/components/dialog.d.ts +3 -3
- package/dist/components/dialog.js +3 -3
- package/dist/components/form.d.ts +3 -2
- package/dist/components/form.js +3 -2
- package/dist/components/main.d.ts +5 -1
- package/dist/components/main.js +5 -1
- package/dist/components/menu.d.ts +39 -5
- package/dist/components/menu.js +45 -5
- package/dist/components/tabs.d.ts +2 -2
- package/dist/components/tabs.js +2 -2
- package/dist/components/textarea.d.ts +3 -2
- package/dist/components/textarea.js +3 -2
- package/dist/components/textline.d.ts +1 -0
- package/dist/components/textline.js +1 -0
- package/dist/components/toast.d.ts +1 -2
- package/dist/components/toast.js +4 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +4 -2
- package/dist/core.d.ts +10 -5
- package/dist/core.js +11 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/staffa.esm.js +1 -1
- package/package.json +1 -1
- package/src/components/autocomplete.ts +9 -2
- package/src/components/box.ts +1 -0
- package/src/components/button.ts +5 -5
- package/src/components/buttonGroup.ts +5 -3
- package/src/components/checkbox.ts +1 -0
- package/src/components/dialog.ts +3 -3
- package/src/components/form.ts +3 -2
- package/src/components/main.ts +5 -1
- package/src/components/menu.ts +50 -5
- package/src/components/tabs.ts +2 -2
- package/src/components/textarea.ts +3 -2
- package/src/components/textline.ts +1 -0
- package/src/components/toast.ts +3 -2
- package/src/components/tooltip.ts +4 -2
- package/src/core.ts +11 -9
- package/src/index.ts +1 -1
package/src/components/toast.ts
CHANGED
|
@@ -54,6 +54,8 @@ let toastCount = 0;
|
|
|
54
54
|
const toasts = A.proxy({} as Record<number, ToastEntry>);
|
|
55
55
|
|
|
56
56
|
mountPortal(() => {
|
|
57
|
+
// Only redraws when emptiness flips, keeping the DOM clean while no toasts show.
|
|
58
|
+
if (A.isEmpty(toasts)) return;
|
|
57
59
|
A("div.s-toasts aria-live=polite aria-atomic=false", () => {
|
|
58
60
|
A.onEach(toasts, (entry) => {
|
|
59
61
|
const { opts } = entry;
|
|
@@ -92,8 +94,7 @@ function dismiss(id: number): void {
|
|
|
92
94
|
* S.toast({ message: "Saved!", type: "success" });
|
|
93
95
|
* S.toast({ title: "Error", message: "Upload failed.", type: "danger", duration: 0 });
|
|
94
96
|
* const off = S.toast({ message: "Uploading…", duration: 0, dismissible: false });
|
|
95
|
-
* //
|
|
96
|
-
* off();
|
|
97
|
+
* setTimeout(off, 3000); // Later..
|
|
97
98
|
* ```
|
|
98
99
|
*/
|
|
99
100
|
export function toast(opts: ToastOptions): () => void {
|
|
@@ -113,11 +113,13 @@ mountPortal(() => {
|
|
|
113
113
|
*
|
|
114
114
|
* @example
|
|
115
115
|
* ```ts
|
|
116
|
-
*
|
|
116
|
+
* S.button(() => {
|
|
117
|
+
* A("#Save");
|
|
117
118
|
* S.addTooltip({ tip: "Saves your work to the cloud" });
|
|
118
119
|
* });
|
|
119
120
|
*
|
|
120
|
-
*
|
|
121
|
+
* S.button(() => {
|
|
122
|
+
* A(".danger#Delete");
|
|
121
123
|
* S.addTooltip({ tip: "Dangerous — cannot be undone", placement: "bottom" });
|
|
122
124
|
* });
|
|
123
125
|
* ```
|
package/src/core.ts
CHANGED
|
@@ -71,15 +71,17 @@ export function drawSlot<Args extends unknown[] = []>(slot: Slot<Args> | undefin
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Mount a portal (tooltip, toast, menu, dialog, …)
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
74
|
+
* Mount a portal (tooltip, toast, menu, dialog, …) directly into `<body>`.
|
|
75
|
+
* Must be called at module top level, where Aberdeen's root scope (whose
|
|
76
|
+
* element is `document.body`) is current. Separate `A.mount`s sharing a parent
|
|
77
|
+
* can't tell their nodes apart, but sibling scopes within the root scope track
|
|
78
|
+
* their positions, so portals coexist without wrapper elements and add nothing
|
|
79
|
+
* to the DOM while they draw nothing.
|
|
80
|
+
*
|
|
81
|
+
* Scope creation is deferred a microtask so that an app drawing into `<body>`
|
|
82
|
+
* at module top level gets its content *before* the portals, keeping overlays
|
|
83
|
+
* at the end of the document.
|
|
79
84
|
*/
|
|
80
85
|
export function mountPortal(draw: () => void): void {
|
|
81
|
-
|
|
82
|
-
container.style.display = "contents";
|
|
83
|
-
document.body.appendChild(container);
|
|
84
|
-
A.mount(container, draw);
|
|
86
|
+
queueMicrotask(() => A(draw));
|
|
85
87
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export { buttonGroup, type ButtonGroupOptions } from "./components/buttonGroup.j
|
|
|
41
41
|
export { checkbox, type CheckboxOptions } from "./components/checkbox.js";
|
|
42
42
|
export { form, type FormOptions } from "./components/form.js";
|
|
43
43
|
export { main, type MainOptions } from "./components/main.js";
|
|
44
|
-
export { menuButton, showFloatingMenu, type MenuOptions, type MenuEntry, type MenuItem, type MenuSeparator, type FloatingMenuOptions } from "./components/menu.js";
|
|
44
|
+
export { menuButton, showFloatingMenu, addContextMenu, type MenuOptions, type MenuEntry, type MenuItem, type MenuSeparator, type FloatingMenuOptions, type ContextMenuOptions } from "./components/menu.js";
|
|
45
45
|
export { dialog, alert, confirm, prompt, type DialogOptions } from "./components/dialog.js";
|
|
46
46
|
export { select, type SelectOptions, type SelectOptionInput } from "./components/select.js";
|
|
47
47
|
export { tabs, type Tab, type TabsOptions } from "./components/tabs.js";
|