@cahyo-dimas/freeday 3.23.0 → 3.24.0

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.
@@ -161,10 +161,15 @@ let reqToken: number = 0;
161
161
  const cache: Map<string, CflPage> = new Map<string, CflPage>();
162
162
  let lastPage: number = 0;
163
163
  let lastAppend: boolean = false;
164
+ let lastQuery: string = '';
165
+ /* The query the rows on screen came from, which is not always the one in the search box: for 250 ms
166
+ after typing, the box holds a search that has not been sent. "Load more" appends to the ROWS, so it
167
+ asks for their query; reading the box appended page 1 of "ab" under page 0 of "a". */
168
+ let shownQuery: string = '';
164
169
  let searchTimer: ReturnType<typeof setTimeout> | null = null;
165
170
 
166
- async function loadPage(targetPage: number, append: boolean): Promise<void> {
167
- const q: string = query.value;
171
+ async function loadPage(q: string, targetPage: number, append: boolean): Promise<void> {
172
+ lastQuery = q;
168
173
  lastPage = targetPage;
169
174
  lastAppend = append;
170
175
  const token: number = ++reqToken;
@@ -178,11 +183,20 @@ async function loadPage(targetPage: number, append: boolean): Promise<void> {
178
183
  if (cached === undefined) cache.set(key, res);
179
184
  const copy: Row[] = res.rows.slice(); // never mutate the caller's array
180
185
  rows.value = append ? rows.value.concat(copy) : copy;
186
+ if (!append) shownQuery = q;
181
187
  hasMore.value = res.hasMore;
182
188
  page.value = targetPage;
183
189
  if (!append) activeIndex.value = rows.value.length > 0 ? 0 : -1;
184
190
  } catch (err: unknown) {
185
191
  if (token !== reqToken) return;
192
+ /* A new search that failed leaves no rows behind: the old ones answer a different query, and
193
+ under the new text they would read as its results. A failed NEXT page keeps the rows it was
194
+ adding to, which still belong to the query they say they do. */
195
+ if (!append) {
196
+ rows.value = [];
197
+ hasMore.value = false;
198
+ activeIndex.value = -1;
199
+ }
186
200
  error.value = err instanceof Error ? err : new Error(String(err));
187
201
  } finally {
188
202
  if (token === reqToken) loading.value = false;
@@ -190,19 +204,19 @@ async function loadPage(targetPage: number, append: boolean): Promise<void> {
190
204
  }
191
205
 
192
206
  function retry(): void {
193
- void loadPage(lastPage, lastAppend);
207
+ void loadPage(lastQuery, lastPage, lastAppend);
194
208
  }
195
209
 
196
210
  function loadMore(): void {
197
211
  if (loading.value || !hasMore.value) return;
198
- void loadPage(page.value + 1, true);
212
+ void loadPage(shownQuery, page.value + 1, true);
199
213
  }
200
214
 
201
215
  function onSearchInput(e: Event): void {
202
216
  query.value = (e.target as HTMLInputElement).value;
203
217
  if (searchTimer !== null) clearTimeout(searchTimer);
204
218
  searchTimer = setTimeout((): void => {
205
- void loadPage(0, false);
219
+ void loadPage(query.value, 0, false);
206
220
  }, 250);
207
221
  }
208
222
 
@@ -318,7 +332,7 @@ function openDialog(): void {
318
332
  picked.value = props.multiple === true ? [...currentRows.value] : [];
319
333
  dialogEl.value?.showModal();
320
334
  void nextTick((): void => searchEl.value?.focus());
321
- void loadPage(0, false);
335
+ void loadPage(query.value, 0, false);
322
336
  }
323
337
 
324
338
  function closeDialog(): void {
@@ -586,6 +586,14 @@ function onDocPointerDown(e: MouseEvent): void {
586
586
  * the grid, and with it the cell that had focus). That is not focus leaving the control, and
587
587
  * closing on it made the panel vanish mid-navigation. A pointer that really lands outside is
588
588
  * handled by the mousedown listener, which is the reliable path for that case. */
589
+ /* Escape from anywhere in the panel. The grids handle it first and say so with preventDefault; this
590
+ answers for the arrows and the title, where it used to do nothing. */
591
+ function onPanelKeydown(e: KeyboardEvent): void {
592
+ if (e.key !== 'Escape' || e.defaultPrevented) return;
593
+ e.preventDefault();
594
+ closePanel(true);
595
+ }
596
+
589
597
  function onFocusout(e: FocusEvent): void {
590
598
  const next: EventTarget | null = e.relatedTarget;
591
599
  if (next === null) return;
@@ -642,7 +650,8 @@ onBeforeUnmount((): void => {
642
650
  </svg>
643
651
  </button>
644
652
 
645
- <div ref="panelEl" class="fdy-datepicker__panel" role="dialog" aria-modal="false" popover="manual" :aria-labelledby="titleId" :hidden="!open">
653
+ <div ref="panelEl" class="fdy-datepicker__panel" role="dialog" aria-modal="false" popover="manual" :aria-labelledby="titleId" :hidden="!open"
654
+ @keydown="onPanelKeydown">
646
655
  <!-- ONE head for both modes on purpose: swapping it with v-if destroys the very button the user
647
656
  just pressed, focus falls to <body>, and the panel's own focusout handler closes it. The
648
657
  labels and handlers switch; the elements do not. -->
@@ -50,6 +50,15 @@ function onCancel(): void {
50
50
  function onClick(e: MouseEvent): void {
51
51
  if (dismissible.value && e.target === dialogEl.value) emit('close');
52
52
  }
53
+ /* The dialog closed while the app still says open: Chrome honours a prevented `cancel` once per user
54
+ activation, so a second Escape closes it regardless. Reported when the drawer is dismissible, shown
55
+ again when it is not; see FdyModal.vue. */
56
+ function onClose(): void {
57
+ const el: HTMLDialogElement | null = dialogEl.value;
58
+ if (!props.open || el === null) return;
59
+ if (dismissible.value) emit('close');
60
+ else el.showModal();
61
+ }
53
62
  </script>
54
63
 
55
64
  <template>
@@ -59,6 +68,7 @@ function onClick(e: MouseEvent): void {
59
68
  data-fdy-ignore
60
69
  :aria-labelledby="titleId"
61
70
  @cancel.prevent="onCancel"
71
+ @close="onClose"
62
72
  @click="onClick"
63
73
  >
64
74
  <div class="fdy-drawer__header">
@@ -54,6 +54,17 @@ function onCancel(): void {
54
54
  }
55
55
  // The ::backdrop is not a separate element, a click whose target is the dialog box itself (not its
56
56
  // content) is a backdrop click.
57
+ /* The dialog closed while the app still says open. Chrome's close watcher honours a prevented
58
+ `cancel` once per user activation, so a second Escape with no click between closes the dialog
59
+ regardless. Left alone, the app held open=true over a closed dialog and could not reopen it, since
60
+ the value never changed. A dismissible modal reports the close; one that may not be dismissed is
61
+ shown again, because that is what dismissible=false promises. */
62
+ function onClose(): void {
63
+ const el: HTMLDialogElement | null = dialogEl.value;
64
+ if (!props.open || el === null) return;
65
+ if (dismissible.value) emit('close');
66
+ else el.showModal();
67
+ }
57
68
  function onClick(e: MouseEvent): void {
58
69
  if (dismissible.value && e.target === dialogEl.value) emit('close');
59
70
  }
@@ -65,6 +76,7 @@ function onClick(e: MouseEvent): void {
65
76
  :class="modalClass"
66
77
  :aria-labelledby="titleId"
67
78
  @cancel.prevent="onCancel"
79
+ @close="onClose"
68
80
  @click="onClick"
69
81
  >
70
82
  <div class="fdy-modal__header">
@@ -39,6 +39,24 @@ export interface UseThemeReturn {
39
39
  */
40
40
  export declare function useTheme(rootRef?: Ref<HTMLElement | null>): UseThemeReturn;
41
41
 
42
+ export type { LoadState } from '../core/load-state';
43
+
44
+ export interface UseLoadReturn<T> {
45
+ /** The load, as one value: 'idle', 'loading' (with `previous`), 'ready' (with `data`) or 'error'
46
+ * (with `error` and `previous`). Narrow on `status` before reading the rest. */
47
+ state: Readonly<Ref<import('../core/load-state').LoadState<T>>>;
48
+ /** Starts a load, aborting the one before it. Settles when this load does; never rejects. */
49
+ load: () => Promise<void>;
50
+ }
51
+
52
+ /**
53
+ * One data load as one state. The fetcher receives an AbortSignal; a newer `load()` aborts the older
54
+ * request and discards its answer, so a quick change of filter can never leave the older result on
55
+ * screen. Unmounting aborts what is in flight. The states are those docs/screen-states.md lists for a
56
+ * data area: render loading, error and ready from `state.status`, and an error never as empty.
57
+ */
58
+ export declare function useLoad<T>(fetcher: (signal: AbortSignal) => Promise<T>): UseLoadReturn<T>;
59
+
42
60
  /**
43
61
  * Which of the panel's edges lines up with the trigger's. `'start'` (the default) puts the panel's
44
62
  * LEFT edge on the trigger's left edge, right for an input-shaped dropdown; `'end'` puts its RIGHT
@@ -1,5 +1,6 @@
1
1
  export { useFreeday } from './useFreeday.js';
2
2
  export { useTheme } from './useTheme.js';
3
+ export { useLoad } from './useLoad.js';
3
4
  export { usePopover } from './usePopover.ts';
4
5
  export { default as FdyCombo } from './components/FdyCombo.vue';
5
6
  export { default as FdyDatepicker } from './components/FdyDatepicker.vue';
@@ -0,0 +1,47 @@
1
+ /* Freeday. useLoad for Vue 3: one data load as one state, with superseded requests cancelled.
2
+ *
3
+ * const { state, load } = useLoad((signal) => fetchInvoices(month.value, signal));
4
+ * onMounted(load);
5
+ * watch(month, load);
6
+ *
7
+ * <p v-if="state.status === 'loading'" …> loading (state.previous: what was shown before)
8
+ * <div v-else-if="state.status === 'error'" …> load error, never rendered as empty
9
+ * <ul v-else-if="state.status === 'ready'" …> state.data
10
+ *
11
+ * `load()` aborts the request before it (the fetcher gets an AbortSignal) and ignores any answer
12
+ * that arrives after a newer load started, so a quick change of filter can never leave the older
13
+ * result on screen. It returns a promise that settles when this load does and never rejects: the
14
+ * error is in `state`. Unmounting aborts whatever is in flight. The states are the ones
15
+ * docs/screen-states.md lists for a data area; see adapters/core/load-state.js for why they are one
16
+ * value.
17
+ */
18
+ import { onBeforeUnmount, shallowRef } from 'vue';
19
+ import { IDLE, failedFrom, loadingFrom, readyWith } from '../core/load-state.js';
20
+
21
+ export function useLoad(fetcher) {
22
+ var state = shallowRef(IDLE);
23
+ var controller = null;
24
+ var token = 0;
25
+
26
+ function load() {
27
+ if (controller) controller.abort();
28
+ controller = new AbortController();
29
+ var signal = controller.signal;
30
+ var mine = ++token;
31
+ state.value = loadingFrom(state.value);
32
+ return Promise.resolve()
33
+ .then(function () { return fetcher(signal); })
34
+ .then(function (data) {
35
+ if (mine === token) state.value = readyWith(data);
36
+ }, function (err) {
37
+ if (mine === token) state.value = failedFrom(state.value, err instanceof Error ? err : new Error(String(err)));
38
+ });
39
+ }
40
+
41
+ onBeforeUnmount(function () {
42
+ token += 1;
43
+ if (controller) controller.abort();
44
+ });
45
+
46
+ return { state: state, load: load };
47
+ }
@@ -271,13 +271,24 @@
271
271
  return b;
272
272
  }
273
273
 
274
+ /* Every arrow rebuilds the panel, and with it the arrow that was pressed, so focus fell to <body>
275
+ and the next key press (another arrow, Escape) went nowhere. The arrow in the same place takes
276
+ focus back, unless the handler already moved it somewhere in the panel on purpose. */
274
277
  function navButton(glyph, aria, onClick) {
275
278
  var b = document.createElement('button');
276
279
  b.type = 'button';
277
280
  b.className = 'fdy-cal__nav';
278
281
  b.textContent = glyph;
279
282
  b.setAttribute('aria-label', aria);
280
- b.addEventListener('click', onClick);
283
+ var side = glyph === '‹' ? 'prev' : 'next';
284
+ b.setAttribute('data-fdy-nav', side);
285
+ b.addEventListener('click', function () {
286
+ onClick();
287
+ if (!panel.contains(document.activeElement)) {
288
+ var again = panel.querySelector('.fdy-cal__nav[data-fdy-nav="' + side + '"]');
289
+ if (again) again.focus();
290
+ }
291
+ });
281
292
  return b;
282
293
  }
283
294
 
@@ -771,6 +782,19 @@
771
782
  }
772
783
 
773
784
  trigger.addEventListener('click', function () { panel.hidden ? open() : close(true); });
785
+ /* Escape from anywhere in the panel. The grids handle it first and say so with preventDefault;
786
+ this answers for the arrows and the title, where it used to do nothing. */
787
+ panel.addEventListener('keydown', function (e) {
788
+ if (e.key !== 'Escape' || e.defaultPrevented) return;
789
+ e.preventDefault();
790
+ close(true);
791
+ });
792
+ /* Focus leaving the field closes it, as the Vue and React pickers always have. A null target is
793
+ a rebuilt panel taking the focused element with it, which is not focus leaving. */
794
+ wrap.addEventListener('focusout', function (e) {
795
+ var next = e.relatedTarget;
796
+ if (next && !wrap.contains(next)) close(false);
797
+ });
774
798
 
775
799
  updateDisplay();
776
800
 
@@ -286,6 +286,9 @@
286
286
  kitRoots(form).forEach(function (root) { paint(kitAria(root), ''); });
287
287
  }
288
288
  };
289
+ /* The form's own <button type="reset"> empties the fields; the messages about them went with it
290
+ only through api.reset(), so a reset form kept its red text and still counted as submitted. */
291
+ form.addEventListener('reset', function () { api.reset(); });
289
292
  form._fdyForm = api;
290
293
  return api;
291
294
  }
@@ -78,10 +78,10 @@
78
78
  var marker = s.querySelector('.fdy-step__marker');
79
79
  if (marker) marker.innerHTML = i < active ? CHECK : (marker.dataset.num || String(i + 1));
80
80
  var btn = s.querySelector('.fdy-step__btn');
81
- if (btn) btn.disabled = i > maxReached;
81
+ if (btn) btn.disabled = i > maxReached || deciding;
82
82
  });
83
83
  panels.forEach(function (p, i) { p.hidden = i !== active; });
84
- if (prevBtn) prevBtn.disabled = active === 0;
84
+ if (prevBtn) prevBtn.disabled = deciding || active === 0;
85
85
  if (nextBtn) nextBtn.textContent = active === steps.length - 1 ? textOf(root, 'done') : (nextLabel || textOf(root, 'next'));
86
86
  root.dispatchEvent(new CustomEvent('fdy-step-change', { bubbles: true, detail: { index: active } }));
87
87
  }
@@ -104,12 +104,19 @@
104
104
  * opinion about form libraries and this is the line that keeps it that way. */
105
105
  var deciding = false;
106
106
 
107
+ /* While a guard decides, nothing moves: Next, Back and the step headers alike. Only Next and Back
108
+ used to check, so a header click went through mid-decision, and the decision then landed on a
109
+ step it was never asked about. */
107
110
  function lock(on) {
108
111
  deciding = on;
109
112
  var list = root.querySelector('.fdy-stepper');
110
113
  if (list) { if (on) list.setAttribute('aria-busy', 'true'); else list.removeAttribute('aria-busy'); }
111
114
  if (prevBtn) prevBtn.disabled = on || active === 0;
112
115
  if (nextBtn) nextBtn.disabled = on;
116
+ steps.forEach(function (s, i) {
117
+ var btn = s.querySelector('.fdy-step__btn');
118
+ if (btn) btn.disabled = on || i > maxReached;
119
+ });
113
120
  }
114
121
 
115
122
  function request(to, onAllowed) {
@@ -134,16 +141,18 @@
134
141
  );
135
142
  }
136
143
 
137
- if (prevBtn) prevBtn.addEventListener('click', function () { go(active - 1); });
144
+ if (prevBtn) prevBtn.addEventListener('click', function () { if (!deciding) go(active - 1); });
138
145
  if (nextBtn) nextBtn.addEventListener('click', function () {
139
- if (active < steps.length - 1) request(active + 1, function () { go(active + 1); });
146
+ /* The target is fixed when asked: the guard approves THIS move, whatever happens meanwhile. */
147
+ var to = active + 1;
148
+ if (active < steps.length - 1) request(to, function () { go(to); });
140
149
  else request(active + 1, function () { root.dispatchEvent(new CustomEvent('fdy-step-finish', { bubbles: true })); });
141
150
  });
142
151
  steps.forEach(function (s, i) {
143
152
  var btn = s.querySelector('.fdy-step__btn');
144
153
  if (!btn) return;
145
154
  btn.addEventListener('click', function () {
146
- if (i > maxReached) return;
155
+ if (deciding || i > maxReached) return;
147
156
  // Going BACK is always allowed — nothing is being committed. Jumping forward to a step
148
157
  // already reached still leaves the current one behind, so it asks the guard like Next does.
149
158
  if (i <= active) go(i);
@@ -579,8 +579,12 @@
579
579
  closePopover();
580
580
  }
581
581
  });
582
+ /* preventDefault says the key was used. Without it a dialog's close watcher acted on the same
583
+ Escape, and a filter open in a table inside a modal closed the modal with it. */
582
584
  document.addEventListener('keydown', function (e) {
583
- if (e.key === 'Escape' && openPopover) closePopover(true);
585
+ if (e.key !== 'Escape' || !openPopover) return;
586
+ e.preventDefault();
587
+ closePopover(true);
584
588
  });
585
589
 
586
590
  buildColumnFilters();
@@ -144,6 +144,13 @@
144
144
  /* Back to a measured bar. While the indeterminate modifier is on it owns the bar's width, so an
145
145
  explicit one has to be restored when it comes off: .fdy-progress__bar is a plain block div, and
146
146
  with no width at all it fills the track, a full bar, which is the opposite of what 0% means. */
147
+ function showUploading() {
148
+ el.classList.remove('fdy-file--error', 'fdy-file--success');
149
+ icon.innerHTML = FILE_ICON;
150
+ sub.textContent = fmtSize(file.size) + ' · ' + textOf(zone, 'uploading');
151
+ ensureProgress();
152
+ determinate();
153
+ }
147
154
  function determinate() {
148
155
  progressEl.classList.remove('fdy-progress--indeterminate');
149
156
  if (!bar.style.width) bar.style.width = '0%';
@@ -161,13 +168,12 @@
161
168
  dropProgress();
162
169
  },
163
170
  uploading: function () {
164
- el.classList.remove('fdy-file--error', 'fdy-file--success');
165
- icon.innerHTML = FILE_ICON;
166
- sub.textContent = fmtSize(file.size) + ' · ' + textOf(zone, 'uploading');
167
- ensureProgress();
168
- determinate();
171
+ showUploading();
169
172
  },
170
173
  setProgress: function (pct) {
174
+ /* A percentage means the file is uploading again, whatever the row said before. A retry that
175
+ reported progress straight after done() or fail() painted "Uploaded" over a moving bar. */
176
+ if (el.classList.contains('fdy-file--success') || el.classList.contains('fdy-file--error')) showUploading();
171
177
  ensureProgress();
172
178
  determinate();
173
179
  var v = Math.max(0, Math.min(100, pct));
@@ -248,9 +254,13 @@
248
254
  ['dragenter', 'dragover'].forEach(function (ev) {
249
255
  zone.addEventListener(ev, function (e) { e.preventDefault(); zone.classList.add('is-dragover'); });
250
256
  });
251
- ['dragleave', 'dragend'].forEach(function (ev) {
252
- zone.addEventListener(ev, function (e) { if (e.target === zone) zone.classList.remove('is-dragover'); });
257
+ /* Off when the pointer has left the ZONE, read from where it went: dragleave fires on whichever
258
+ child it was over, so `e.target === zone` missed a drag that left through the icon, and the
259
+ highlight stayed. A null relatedTarget is the window, or a drag cancelled with Escape. */
260
+ zone.addEventListener('dragleave', function (e) {
261
+ if (!e.relatedTarget || !zone.contains(e.relatedTarget)) zone.classList.remove('is-dragover');
253
262
  });
263
+ zone.addEventListener('dragend', function () { zone.classList.remove('is-dragover'); });
254
264
  zone.addEventListener('drop', function (e) {
255
265
  e.preventDefault();
256
266
  zone.classList.remove('is-dragover');
package/dist/freeday.js CHANGED
@@ -2430,13 +2430,24 @@
2430
2430
  return b;
2431
2431
  }
2432
2432
 
2433
+ /* Every arrow rebuilds the panel, and with it the arrow that was pressed, so focus fell to <body>
2434
+ and the next key press (another arrow, Escape) went nowhere. The arrow in the same place takes
2435
+ focus back, unless the handler already moved it somewhere in the panel on purpose. */
2433
2436
  function navButton(glyph, aria, onClick) {
2434
2437
  var b = document.createElement('button');
2435
2438
  b.type = 'button';
2436
2439
  b.className = 'fdy-cal__nav';
2437
2440
  b.textContent = glyph;
2438
2441
  b.setAttribute('aria-label', aria);
2439
- b.addEventListener('click', onClick);
2442
+ var side = glyph === '‹' ? 'prev' : 'next';
2443
+ b.setAttribute('data-fdy-nav', side);
2444
+ b.addEventListener('click', function () {
2445
+ onClick();
2446
+ if (!panel.contains(document.activeElement)) {
2447
+ var again = panel.querySelector('.fdy-cal__nav[data-fdy-nav="' + side + '"]');
2448
+ if (again) again.focus();
2449
+ }
2450
+ });
2440
2451
  return b;
2441
2452
  }
2442
2453
 
@@ -2930,6 +2941,19 @@
2930
2941
  }
2931
2942
 
2932
2943
  trigger.addEventListener('click', function () { panel.hidden ? open() : close(true); });
2944
+ /* Escape from anywhere in the panel. The grids handle it first and say so with preventDefault;
2945
+ this answers for the arrows and the title, where it used to do nothing. */
2946
+ panel.addEventListener('keydown', function (e) {
2947
+ if (e.key !== 'Escape' || e.defaultPrevented) return;
2948
+ e.preventDefault();
2949
+ close(true);
2950
+ });
2951
+ /* Focus leaving the field closes it, as the Vue and React pickers always have. A null target is
2952
+ a rebuilt panel taking the focused element with it, which is not focus leaving. */
2953
+ wrap.addEventListener('focusout', function (e) {
2954
+ var next = e.relatedTarget;
2955
+ if (next && !wrap.contains(next)) close(false);
2956
+ });
2933
2957
 
2934
2958
  updateDisplay();
2935
2959
 
@@ -3459,6 +3483,9 @@
3459
3483
  kitRoots(form).forEach(function (root) { paint(kitAria(root), ''); });
3460
3484
  }
3461
3485
  };
3486
+ /* The form's own <button type="reset"> empties the fields; the messages about them went with it
3487
+ only through api.reset(), so a reset form kept its red text and still counted as submitted. */
3488
+ form.addEventListener('reset', function () { api.reset(); });
3462
3489
  form._fdyForm = api;
3463
3490
  return api;
3464
3491
  }
@@ -4652,10 +4679,10 @@
4652
4679
  var marker = s.querySelector('.fdy-step__marker');
4653
4680
  if (marker) marker.innerHTML = i < active ? CHECK : (marker.dataset.num || String(i + 1));
4654
4681
  var btn = s.querySelector('.fdy-step__btn');
4655
- if (btn) btn.disabled = i > maxReached;
4682
+ if (btn) btn.disabled = i > maxReached || deciding;
4656
4683
  });
4657
4684
  panels.forEach(function (p, i) { p.hidden = i !== active; });
4658
- if (prevBtn) prevBtn.disabled = active === 0;
4685
+ if (prevBtn) prevBtn.disabled = deciding || active === 0;
4659
4686
  if (nextBtn) nextBtn.textContent = active === steps.length - 1 ? textOf(root, 'done') : (nextLabel || textOf(root, 'next'));
4660
4687
  root.dispatchEvent(new CustomEvent('fdy-step-change', { bubbles: true, detail: { index: active } }));
4661
4688
  }
@@ -4678,12 +4705,19 @@
4678
4705
  * opinion about form libraries and this is the line that keeps it that way. */
4679
4706
  var deciding = false;
4680
4707
 
4708
+ /* While a guard decides, nothing moves: Next, Back and the step headers alike. Only Next and Back
4709
+ used to check, so a header click went through mid-decision, and the decision then landed on a
4710
+ step it was never asked about. */
4681
4711
  function lock(on) {
4682
4712
  deciding = on;
4683
4713
  var list = root.querySelector('.fdy-stepper');
4684
4714
  if (list) { if (on) list.setAttribute('aria-busy', 'true'); else list.removeAttribute('aria-busy'); }
4685
4715
  if (prevBtn) prevBtn.disabled = on || active === 0;
4686
4716
  if (nextBtn) nextBtn.disabled = on;
4717
+ steps.forEach(function (s, i) {
4718
+ var btn = s.querySelector('.fdy-step__btn');
4719
+ if (btn) btn.disabled = on || i > maxReached;
4720
+ });
4687
4721
  }
4688
4722
 
4689
4723
  function request(to, onAllowed) {
@@ -4708,16 +4742,18 @@
4708
4742
  );
4709
4743
  }
4710
4744
 
4711
- if (prevBtn) prevBtn.addEventListener('click', function () { go(active - 1); });
4745
+ if (prevBtn) prevBtn.addEventListener('click', function () { if (!deciding) go(active - 1); });
4712
4746
  if (nextBtn) nextBtn.addEventListener('click', function () {
4713
- if (active < steps.length - 1) request(active + 1, function () { go(active + 1); });
4747
+ /* The target is fixed when asked: the guard approves THIS move, whatever happens meanwhile. */
4748
+ var to = active + 1;
4749
+ if (active < steps.length - 1) request(to, function () { go(to); });
4714
4750
  else request(active + 1, function () { root.dispatchEvent(new CustomEvent('fdy-step-finish', { bubbles: true })); });
4715
4751
  });
4716
4752
  steps.forEach(function (s, i) {
4717
4753
  var btn = s.querySelector('.fdy-step__btn');
4718
4754
  if (!btn) return;
4719
4755
  btn.addEventListener('click', function () {
4720
- if (i > maxReached) return;
4756
+ if (deciding || i > maxReached) return;
4721
4757
  // Going BACK is always allowed — nothing is being committed. Jumping forward to a step
4722
4758
  // already reached still leaves the current one behind, so it asks the guard like Next does.
4723
4759
  if (i <= active) go(i);
@@ -5325,8 +5361,12 @@
5325
5361
  closePopover();
5326
5362
  }
5327
5363
  });
5364
+ /* preventDefault says the key was used. Without it a dialog's close watcher acted on the same
5365
+ Escape, and a filter open in a table inside a modal closed the modal with it. */
5328
5366
  document.addEventListener('keydown', function (e) {
5329
- if (e.key === 'Escape' && openPopover) closePopover(true);
5367
+ if (e.key !== 'Escape' || !openPopover) return;
5368
+ e.preventDefault();
5369
+ closePopover(true);
5330
5370
  });
5331
5371
 
5332
5372
  buildColumnFilters();
@@ -6434,6 +6474,13 @@
6434
6474
  /* Back to a measured bar. While the indeterminate modifier is on it owns the bar's width, so an
6435
6475
  explicit one has to be restored when it comes off: .fdy-progress__bar is a plain block div, and
6436
6476
  with no width at all it fills the track, a full bar, which is the opposite of what 0% means. */
6477
+ function showUploading() {
6478
+ el.classList.remove('fdy-file--error', 'fdy-file--success');
6479
+ icon.innerHTML = FILE_ICON;
6480
+ sub.textContent = fmtSize(file.size) + ' · ' + textOf(zone, 'uploading');
6481
+ ensureProgress();
6482
+ determinate();
6483
+ }
6437
6484
  function determinate() {
6438
6485
  progressEl.classList.remove('fdy-progress--indeterminate');
6439
6486
  if (!bar.style.width) bar.style.width = '0%';
@@ -6451,13 +6498,12 @@
6451
6498
  dropProgress();
6452
6499
  },
6453
6500
  uploading: function () {
6454
- el.classList.remove('fdy-file--error', 'fdy-file--success');
6455
- icon.innerHTML = FILE_ICON;
6456
- sub.textContent = fmtSize(file.size) + ' · ' + textOf(zone, 'uploading');
6457
- ensureProgress();
6458
- determinate();
6501
+ showUploading();
6459
6502
  },
6460
6503
  setProgress: function (pct) {
6504
+ /* A percentage means the file is uploading again, whatever the row said before. A retry that
6505
+ reported progress straight after done() or fail() painted "Uploaded" over a moving bar. */
6506
+ if (el.classList.contains('fdy-file--success') || el.classList.contains('fdy-file--error')) showUploading();
6461
6507
  ensureProgress();
6462
6508
  determinate();
6463
6509
  var v = Math.max(0, Math.min(100, pct));
@@ -6538,9 +6584,13 @@
6538
6584
  ['dragenter', 'dragover'].forEach(function (ev) {
6539
6585
  zone.addEventListener(ev, function (e) { e.preventDefault(); zone.classList.add('is-dragover'); });
6540
6586
  });
6541
- ['dragleave', 'dragend'].forEach(function (ev) {
6542
- zone.addEventListener(ev, function (e) { if (e.target === zone) zone.classList.remove('is-dragover'); });
6587
+ /* Off when the pointer has left the ZONE, read from where it went: dragleave fires on whichever
6588
+ child it was over, so `e.target === zone` missed a drag that left through the icon, and the
6589
+ highlight stayed. A null relatedTarget is the window, or a drag cancelled with Escape. */
6590
+ zone.addEventListener('dragleave', function (e) {
6591
+ if (!e.relatedTarget || !zone.contains(e.relatedTarget)) zone.classList.remove('is-dragover');
6543
6592
  });
6593
+ zone.addEventListener('dragend', function () { zone.classList.remove('is-dragover'); });
6544
6594
  zone.addEventListener('drop', function (e) {
6545
6595
  e.preventDefault();
6546
6596
  zone.classList.remove('is-dragover');
@@ -198,7 +198,7 @@ live docs also have a copy button per component.
198
198
  ```bash
199
199
  npm i @cahyo-dimas/freeday
200
200
  ```
201
- Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.23.0"` (public npm package). `dist/` is
201
+ Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.24.0"` (public npm package). `dist/` is
202
202
  committed and published → no build step; `npm ci` runs without auth.
203
203
 
204
204
  ### 2. Import the CSS + enhancers **once** in your entry (`src/main.ts`)
@@ -75,6 +75,9 @@ Notes:
75
75
  These replace one data area (a table, a list, a card), not the page. Put the `.fdy-state` inside
76
76
  the card or section it replaces, so the page header and its actions stay usable.
77
77
 
78
+ In Vue and React, `useLoad` holds which of these a data area is in, as one value; see `.fdy-state`
79
+ in COMPONENTS.md.
80
+
78
81
  ### 10. Ideal
79
82
 
80
83
  The data as designed. Design it last, after the four below, because those decide whether the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cahyo-dimas/freeday",
3
- "version": "3.23.0",
3
+ "version": "3.24.0",
4
4
  "description": "Freeday: token-driven, framework-agnostic UI KIT (design source-of-truth).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -97,7 +97,7 @@
97
97
  "scripts": {
98
98
  "build": "node tokens/build.mjs",
99
99
  "test": "node --test",
100
- "test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/axis-nesting.mjs browser/palette-os-dark.mjs browser/primary-fill.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/theme-pref.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/actionbar.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/daterange-single.mjs browser/child-hydration.mjs browser/tabs-picker.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/form-required-rest.mjs browser/autocomplete-open.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
100
+ "test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/axis-nesting.mjs browser/palette-os-dark.mjs browser/primary-fill.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/theme-pref.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/actionbar.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/daterange-single.mjs browser/child-hydration.mjs browser/tabs-picker.mjs browser/cfl-async.mjs browser/table-process.mjs browser/modal-locked.mjs browser/datepicker-escape.mjs browser/raw-escape-reset.mjs browser/use-load.mjs browser/upload-leftovers.mjs browser/stepper-pending.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/form-required-rest.mjs browser/autocomplete-open.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
101
101
  "prepack": "node tokens/build.mjs",
102
102
  "version": "node tokens/build.mjs && git add dist",
103
103
  "typecheck:react": "tsc -p adapters/react/tsconfig.json --noEmit",