@diegopluna/narvi 0.5.5 → 0.5.7
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/components/toast/Toaster.svelte +25 -4
- package/dist/internal/clock.js +11 -7
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +1 -1
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
Built on ui-sdk's toast region. It sits in the top layer, so toasts stay above
|
|
5
5
|
dialogs, and ui-sdk keeps them usable while a modal dialog is open. A menu, a
|
|
6
|
-
popover or anything else that opens later
|
|
7
|
-
a new toast comes over everything again. Each
|
|
6
|
+
popover or anything else not modal that opens later opens over them, inside a
|
|
7
|
+
modal dialog too, and a new toast comes over everything again. Each
|
|
8
8
|
toast waits while the pointer or focus is on the stack, while the window is
|
|
9
9
|
hidden or in the background, so none goes unread.
|
|
10
10
|
-->
|
|
@@ -204,7 +204,8 @@
|
|
|
204
204
|
// seen and used; over anything else, what the person opened last is on top. So the region
|
|
205
205
|
// steps out of the top layer, back into the page at its `zIndex`, as a popup that is not modal
|
|
206
206
|
// opens, before ui-sdk raises it (on the document, after the window's capture), and goes back
|
|
207
|
-
// in as a modal opens or a toast arrives.
|
|
207
|
+
// in as a modal opens or a toast arrives. While a modal is open the region stays in, so the
|
|
208
|
+
// popup is raised back over it instead.
|
|
208
209
|
$effect(() => {
|
|
209
210
|
const region = document.querySelector<HTMLElement>(`[data-narvi-toaster="${id}"]`);
|
|
210
211
|
if (!region || typeof region.showPopover !== 'function') return;
|
|
@@ -214,12 +215,32 @@
|
|
|
214
215
|
[...document.querySelectorAll(':popover-open, :modal')].some(
|
|
215
216
|
(element) => element !== region && isModal(element)
|
|
216
217
|
);
|
|
218
|
+
// Popups this raised back over the region, whose own toggle event is still to come
|
|
219
|
+
const raised = new WeakSet<Element>();
|
|
217
220
|
const onToggle = (event: Event) => {
|
|
218
221
|
const opened = event.target;
|
|
219
|
-
|
|
222
|
+
const { oldState, newState } = event as ToggleEvent;
|
|
223
|
+
if (!(opened instanceof HTMLElement) || newState !== 'open') return;
|
|
220
224
|
if (opened === region || region.contains(opened)) return;
|
|
225
|
+
if (raised.delete(opened) && oldState === 'open') {
|
|
226
|
+
// The toggle of that raise, which changes nothing: ui-sdk would raise the region again
|
|
227
|
+
event.stopImmediatePropagation();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
221
230
|
if (isModal(opened)) raise(region);
|
|
222
231
|
else if (!modalOpen()) lower(region);
|
|
232
|
+
else {
|
|
233
|
+
// ui-sdk raises the region over the popup on the document; once it has, at the
|
|
234
|
+
// popup itself, the popup goes back on top
|
|
235
|
+
opened.addEventListener(
|
|
236
|
+
'toggle',
|
|
237
|
+
() => {
|
|
238
|
+
raised.add(opened);
|
|
239
|
+
raise(opened);
|
|
240
|
+
},
|
|
241
|
+
{ once: true }
|
|
242
|
+
);
|
|
243
|
+
}
|
|
223
244
|
};
|
|
224
245
|
window.addEventListener('toggle', onToggle, true);
|
|
225
246
|
return () => window.removeEventListener('toggle', onToggle, true);
|
package/dist/internal/clock.js
CHANGED
|
@@ -19,9 +19,9 @@ import { BROWSER } from 'esm-env';
|
|
|
19
19
|
import { onPageShown, pageShown } from './visible.js';
|
|
20
20
|
const FOCUSED_RATE = 30;
|
|
21
21
|
const UNFOCUSED_RATE = 10;
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
const EARLY =
|
|
22
|
+
// The timer wakes this long before a frame is due, and the frame is drawn on the display's
|
|
23
|
+
// next beat: every fourth at 120Hz for a 30-a-second clock, every second at 60Hz
|
|
24
|
+
const EARLY = 8;
|
|
25
25
|
/** What draws on the next frame: everything subscribed, less what is out of view. */
|
|
26
26
|
const drawing = new Set();
|
|
27
27
|
/** What draws while an element is in view, and whether it is. */
|
|
@@ -34,9 +34,13 @@ let listening = false;
|
|
|
34
34
|
const interval = () => 1000 / (document.hasFocus() ? FOCUSED_RATE : UNFOCUSED_RATE);
|
|
35
35
|
function tick(time) {
|
|
36
36
|
request = undefined;
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// Measured as the timer is, when the callback runs: a frame's callbacks can run well after
|
|
38
|
+
// its start, so by its `time` a frame just drawn could already look overdue. Every wake-up
|
|
39
|
+
// draws on the first frame after it; half an interval only keeps a stray request from
|
|
40
|
+
// drawing twice in a row.
|
|
41
|
+
const now = performance.now();
|
|
42
|
+
if (now - last >= interval() / 2) {
|
|
43
|
+
last = now;
|
|
40
44
|
for (const draw of drawing) {
|
|
41
45
|
try {
|
|
42
46
|
draw(time);
|
|
@@ -61,7 +65,7 @@ function schedule() {
|
|
|
61
65
|
if (timer !== undefined || request !== undefined)
|
|
62
66
|
return;
|
|
63
67
|
// A little before the frame is due, so the beat it is drawn on is not the one after
|
|
64
|
-
const delay = last + interval() - EARLY
|
|
68
|
+
const delay = last + interval() - EARLY - performance.now();
|
|
65
69
|
if (delay <= 0) {
|
|
66
70
|
request = requestAnimationFrame(tick);
|
|
67
71
|
return;
|
package/package.json
CHANGED
package/skills/markdown/SKILL.md
CHANGED
package/skills/setup/SKILL.md
CHANGED
package/skills/styling/SKILL.md
CHANGED
package/skills/theming/SKILL.md
CHANGED