@cahyo-dimas/freeday 3.23.0 → 3.25.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/COMPONENTS.md +39 -0
  3. package/README.id.md +1 -1
  4. package/README.md +1 -1
  5. package/adapters/blazor/FdyAutocomplete.razor +1 -1
  6. package/adapters/blazor/FdyAutocomplete.razor.cs +34 -1
  7. package/adapters/blazor/FdyCascade.razor.cs +15 -1
  8. package/adapters/blazor/FdyCfl.razor.cs +44 -8
  9. package/adapters/blazor/FdyDateRange.razor +1 -1
  10. package/adapters/blazor/FdyDateRange.razor.cs +25 -1
  11. package/adapters/blazor/FdyDatepicker.razor.cs +15 -1
  12. package/adapters/blazor/FdyMonthpicker.razor.cs +15 -1
  13. package/adapters/blazor/FdyTable.razor.cs +23 -1
  14. package/adapters/blazor/FdyTimepicker.razor.cs +15 -1
  15. package/adapters/blazor/freeday-blazor.js +16 -2
  16. package/adapters/core/load-state.d.ts +17 -0
  17. package/adapters/core/load-state.js +37 -0
  18. package/adapters/react/components/FdyCfl.tsx +20 -5
  19. package/adapters/react/components/FdyDatepicker.tsx +10 -1
  20. package/adapters/react/components/FdyDrawer.tsx +8 -0
  21. package/adapters/react/components/FdyModal.tsx +11 -0
  22. package/adapters/react/components/FdyTable.tsx +28 -5
  23. package/adapters/react/index.d.ts +18 -0
  24. package/adapters/react/index.js +1 -0
  25. package/adapters/react/useLoad.js +53 -0
  26. package/adapters/vue/components/FdyCfl.vue +20 -6
  27. package/adapters/vue/components/FdyDatepicker.vue +10 -1
  28. package/adapters/vue/components/FdyDrawer.vue +10 -0
  29. package/adapters/vue/components/FdyModal.vue +12 -0
  30. package/adapters/vue/index.d.ts +18 -0
  31. package/adapters/vue/index.js +1 -0
  32. package/adapters/vue/useLoad.js +47 -0
  33. package/dist/freeday-autocomplete.js +43 -11
  34. package/dist/freeday-cascade.js +24 -8
  35. package/dist/freeday-datepicker.js +61 -1
  36. package/dist/freeday-form.js +3 -0
  37. package/dist/freeday-stepper.js +14 -5
  38. package/dist/freeday-table.js +5 -1
  39. package/dist/freeday-timepicker.js +12 -1
  40. package/dist/freeday-upload.js +17 -7
  41. package/dist/freeday.js +179 -34
  42. package/docs/getting-started.md +1 -1
  43. package/docs/screen-states.md +3 -0
  44. package/package.json +2 -2
@@ -306,14 +306,18 @@
306
306
  if (li) activate(opts.indexOf(li));
307
307
  });
308
308
 
309
- // Initial display: pre-selected leaf shows its full path, else placeholder.
310
- var initTrail = selectedValue ? pathTo(root, selectedValue, []) : null;
311
- if (initTrail) {
312
- valueSpan.textContent = initTrail.map(function (n) { return n.label; }).join(sep);
313
- } else {
314
- valueSpan.textContent = placeholder;
315
- valueSpan.classList.add('fdy-cascade__value--placeholder');
309
+ // The selected leaf shows its full path, else the placeholder. At init and on setValue alike.
310
+ function showValue() {
311
+ var trail = selectedValue ? pathTo(root, selectedValue, []) : null;
312
+ if (trail) {
313
+ valueSpan.textContent = trail.map(function (n) { return n.label; }).join(sep);
314
+ valueSpan.classList.remove('fdy-cascade__value--placeholder');
315
+ } else {
316
+ valueSpan.textContent = placeholder;
317
+ valueSpan.classList.add('fdy-cascade__value--placeholder');
318
+ }
316
319
  }
320
+ showValue();
317
321
 
318
322
  applyState();
319
323
  applyInvalid();
@@ -322,7 +326,15 @@
322
326
  wrap: wrap,
323
327
  setState: setState,
324
328
  getValue: function () { return selectedValue; },
325
- clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); }
329
+ clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); },
330
+ /* The host's own value, pushed in silently: no fdy-cascade-change, so a binding that set it
331
+ does not hear it back. A render-once host (Blazor) has no other way to change it. */
332
+ setValue: function (next) {
333
+ selectedValue = next || '';
334
+ wrap.setAttribute('data-value', selectedValue);
335
+ showValue();
336
+ if (!panel.hidden) render();
337
+ }
326
338
  };
327
339
  wrap._fdyCascade = api;
328
340
  return api;
@@ -348,6 +360,10 @@
348
360
  setState: function (root, state) {
349
361
  var api = root && root._fdyCascade ? root._fdyCascade : null;
350
362
  if (api && api.setState) api.setState(state);
363
+ },
364
+ setValue: function (root, value) {
365
+ var api = root && root._fdyCascade ? root._fdyCascade : null;
366
+ if (api) api.setValue(value);
351
367
  }
352
368
  };
353
369
  })();
@@ -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
 
@@ -785,6 +809,22 @@
785
809
  return selected ? (monthOnly ? toISOMonth(selected) : toISO(selected)) : '';
786
810
  },
787
811
  clear: function () { selected = null; selectedEnd = null; updateDisplay(); if (!panel.hidden) render(); },
812
+ /* The host's own value, pushed in silently: no change event, so a binding that set it does
813
+ not hear it back. A render-once host (Blazor) has no other way to change the shown date.
814
+ The single-field range takes "start/end", the form its data-value already has. */
815
+ setValue: function (next) {
816
+ if (rangeMode) {
817
+ var iv = parseInterval(next);
818
+ selected = iv.start;
819
+ selectedEnd = iv.end;
820
+ } else {
821
+ selected = parseVal(next);
822
+ }
823
+ anchor = null;
824
+ preview = null;
825
+ updateDisplay();
826
+ if (!panel.hidden) render();
827
+ },
788
828
  setMin: function (iso) { minDate = parseVal(iso); if (!panel.hidden) render(); },
789
829
  setMax: function (iso) { maxDate = parseVal(iso); if (!panel.hidden) render(); },
790
830
  setRange: function (fromIso, toIso) {
@@ -831,6 +871,15 @@
831
871
  if ((f === '') !== (t === '')) return;
832
872
  root.dispatchEvent(new CustomEvent('fdy-daterange-settled', { bubbles: true, detail: { from: f, to: t } }));
833
873
  }
874
+ /* Both ends from the host at once, then the same linking a pick gets: the end's minimum and the
875
+ band shading. Silent, like each picker's own setValue. */
876
+ root._fdyDr = {
877
+ setRange: function (f, t) {
878
+ fromApi.setValue(f || '');
879
+ toApi.setValue(t || '');
880
+ sync();
881
+ }
882
+ };
834
883
  fromEl.addEventListener('fdy-datepicker-change', function () {
835
884
  var f = fromApi.getValue(), t = toApi.getValue();
836
885
  if (f && t && t < f) clearEnd(toEl, toApi);
@@ -869,6 +918,17 @@
869
918
  setState: function (root, state) {
870
919
  var api = root && root._fdyDp ? root._fdyDp : null;
871
920
  if (api && api.setState) api.setState(state);
921
+ },
922
+ /* A picker's value from the host, silently: `YYYY-MM-DD`, `YYYY-MM` in month mode, or
923
+ "start/end" on a single-field range. */
924
+ setValue: function (root, value) {
925
+ var api = root && root._fdyDp ? root._fdyDp : null;
926
+ if (api) api.setValue(value);
927
+ },
928
+ /* Both ends of a two-picker range (the `data-fdy-daterange` root), relinked as after a pick. */
929
+ setRange: function (root, from, to) {
930
+ var dr = root && root._fdyDr ? root._fdyDr : null;
931
+ if (dr) dr.setRange(from, to);
872
932
  }
873
933
  };
874
934
  })();
@@ -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();
@@ -230,7 +230,14 @@
230
230
  wrap: wrap,
231
231
  getValue: function () { return value; },
232
232
  setState: setState,
233
- clear: function () { value = ''; for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', 'false'); updateDisplay(); }
233
+ clear: function () { value = ''; for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', 'false'); updateDisplay(); },
234
+ /* The host's own value, pushed in silently: no fdy-time-select, so a binding that set it does
235
+ not hear it back. A render-once host (Blazor) has no other way to change the shown time. */
236
+ setValue: function (next) {
237
+ value = norm(next);
238
+ for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', opts[i].getAttribute('data-value') === value ? 'true' : 'false');
239
+ updateDisplay();
240
+ }
234
241
  };
235
242
  wrap._fdyTp = api;
236
243
  return api;
@@ -256,6 +263,10 @@
256
263
  setState: function (root, state) {
257
264
  var api = root && root._fdyTp ? root._fdyTp : null;
258
265
  if (api && api.setState) api.setState(state);
266
+ },
267
+ setValue: function (root, value) {
268
+ var api = root && root._fdyTp ? root._fdyTp : null;
269
+ if (api) api.setValue(value);
259
270
  }
260
271
  };
261
272
  })();
@@ -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');