@cahyo-dimas/freeday 3.24.0 → 3.26.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.
- package/CHANGELOG.md +60 -0
- package/COMPONENTS.md +14 -0
- package/README.id.md +1 -1
- package/README.md +1 -1
- package/adapters/blazor/FdyAutocomplete.razor +1 -1
- package/adapters/blazor/FdyAutocomplete.razor.cs +34 -1
- package/adapters/blazor/FdyCascade.razor.cs +37 -1
- package/adapters/blazor/FdyDateRange.razor +1 -1
- package/adapters/blazor/FdyDateRange.razor.cs +25 -1
- package/adapters/blazor/FdyDatepicker.razor.cs +15 -1
- package/adapters/blazor/FdyMonthpicker.razor.cs +15 -1
- package/adapters/blazor/FdyTimepicker.razor.cs +15 -1
- package/dist/freeday-autocomplete.js +43 -11
- package/dist/freeday-cascade.js +52 -8
- package/dist/freeday-datepicker.js +36 -0
- package/dist/freeday-timepicker.js +12 -1
- package/dist/freeday.js +143 -20
- package/docs/getting-started.md +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,66 @@ benar. Perubahan seperti itu ditulis di bawah `### Changed: BREAKING (types)`
|
|
|
9
9
|
lama → tipe baru, dan cara menyempitkannya — bukan di bawah `### Added`, betapapun aditifnya dari
|
|
10
10
|
sisi kit.
|
|
11
11
|
|
|
12
|
+
## [3.26.0] - 2026-11-27
|
|
13
|
+
|
|
14
|
+
**Pohon `FdyCascade` Blazor mengikuti host** (`#123`), butir terakhir kelas "nilai dan opsi dari host"
|
|
15
|
+
yang 3.25.0 tutup untuk nilai di enam wrapper dan opsi autocomplete.
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- **`FreedayCascade.setNodes(root, tree)`**, dengan pohon `[{ value, label, children }]` yang dibaca
|
|
19
|
+
seperti `<ul>` seed: nilai kosong jatuh ke label, tanpa anak berarti daun. Tampilan kembali ke
|
|
20
|
+
tingkat atas dan jalur nilai terpilih dicari ulang; nilai yang tidak ada di pohon baru menampilkan
|
|
21
|
+
placeholder sampai host menyetel yang ada.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- **`FdyCascade` Blazor mendorong `Nodes` yang berubah sesudah render pertama.** Enhancer menelan
|
|
25
|
+
`<ul>` seed saat init, jadi pohon yang diganti host tidak pernah tampil. Pohon dibandingkan menurut
|
|
26
|
+
isi (kesetaraan record C# membandingkan `Children` per referensi), dan didorong sebelum `Value`,
|
|
27
|
+
supaya nilai yang hanya ada di pohon baru menemukan jalurnya.
|
|
28
|
+
|
|
29
|
+
### Catatan
|
|
30
|
+
- Diuji: 2 bUnit dan 1 uji peramban baru, merah pada kode lama.
|
|
31
|
+
|
|
32
|
+
## [3.25.0] - 2026-11-27
|
|
33
|
+
|
|
34
|
+
**Nilai dari host sampai ke layar, di setiap wrapper Blazor** (`#123`, sisa audit 3.24.0). Wrapper
|
|
35
|
+
yang menyerahkan DOM-nya ke enhancer me-render seed-nya sekali. Selama ini hanya state
|
|
36
|
+
(`Disabled`, `Readonly`, `Invalid`, `Required`) yang didorong sesudahnya, jadi `Value` yang diubah
|
|
37
|
+
host, misalnya tombol "bulan ini" atau formulir yang dimuat ulang, tidak pernah tampil. `FdyCombo`
|
|
38
|
+
satu-satunya yang benar. Diukur sebagai kelas, bukan tiga komponen yang dilaporkan: enam wrapper.
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- **`setValue(root, value)`** di `FreedayDatepicker`, `FreedayTimepicker`, `FreedayCascade` dan
|
|
42
|
+
`FreedayAutocomplete`, **`FreedayDatepicker.setRange(root, from, to)`** untuk rentang dua picker,
|
|
43
|
+
dan **`FreedayAutocomplete.setOptions(root, labels)`**. Semuanya senyap: tidak ada event
|
|
44
|
+
perubahan, jadi binding yang menyetel nilai tidak mendengarnya kembali sebagai pilihan. Datepicker
|
|
45
|
+
menerima `YYYY-MM-DD`, `YYYY-MM` di mode bulan, dan `"awal/akhir"` di rentang satu kolom.
|
|
46
|
+
`setRange` menautkan ulang batas akhir seperti sesudah memilih. String kosong mengosongkan.
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
- **`FdyDatepicker`, `FdyMonthpicker`, `FdyTimepicker`, `FdyCascade`, `FdyAutocomplete` dan
|
|
50
|
+
`FdyDateRange` Blazor mendorong `Value` / `From` / `To` yang berubah sesudah render pertama.**
|
|
51
|
+
Nilai yang dipilih pengguna tidak didorong balik.
|
|
52
|
+
- **`FdyAutocomplete` Blazor mendorong `Options` yang berubah**, dibandingkan menurut isi, jadi host
|
|
53
|
+
yang membuat list baru dengan isi yang sama di setiap render tidak memicu apa pun.
|
|
54
|
+
- **`FdyAutocomplete` Blazor melaporkan teks bebas saat diketik**, sama seperti Vue dan React.
|
|
55
|
+
Sebelumnya hanya pilihan yang sampai ke `ValueChanged`, jadi teks yang tidak cocok dengan saran
|
|
56
|
+
tampil di isian sementara `Value` memegang nilai lama.
|
|
57
|
+
- **Autocomplete jalur mentah membaca opsinya dari daftar setiap kali dipakai.** Opsi yang
|
|
58
|
+
di-render app sesudah init tidak pernah terlihat, dan flag ready menolak init ulang.
|
|
59
|
+
|
|
60
|
+
### Catatan
|
|
61
|
+
- **`Nodes` `FdyCascade` Blazor belum didorong.** Enhancer cascade menelan `<ul>` seed-nya dan tidak
|
|
62
|
+
punya API untuk mengganti pohonnya; dicatat di `NEXT-UP.md` §1.
|
|
63
|
+
- Diuji: 9 bUnit (`FdyValuePushTests`) dan 3 uji peramban (`browser/set-value.mjs`), semuanya merah
|
|
64
|
+
pada kode lama.
|
|
65
|
+
- **Harness peramban: halaman diserahkan ke uji sesudah fixture-nya termuat** (`browser/harness.mjs`).
|
|
66
|
+
Chrome dibuka dengan fixture sebagai halaman awal, dan soket CDP bisa tersambung saat tab masih
|
|
67
|
+
`about:blank`, yang `readyState`-nya sudah `complete`. `palette-os-dark` gagal begitu di jalanan
|
|
68
|
+
rilis ini: `document.documentElement` terbaca `null` saat dokumen fixture menggantikannya. Tujuh
|
|
69
|
+
spesifikasi menunggu dengan cara yang sama. Balapannya bergantung waktu, jadi tidak bisa dibuktikan
|
|
70
|
+
merah secara deterministik; yang diukur adalah ketujuhnya hijau dan suite penuh hijau sesudahnya.
|
|
71
|
+
|
|
12
72
|
## [3.24.0] - 2026-11-27
|
|
13
73
|
|
|
14
74
|
**Satu keadaan, satu pintu.** Audit state machine implisit di kit (dan di app ronda yang memakainya)
|
package/COMPONENTS.md
CHANGED
|
@@ -140,6 +140,20 @@ the states, `data-fdy-no-icon` drops the trailing icon, and a `<template data-fd
|
|
|
140
140
|
replaces it. `readonly` is **not** `disabled`: full contrast, still focusable and copyable, opening
|
|
141
141
|
is a no-op.
|
|
142
142
|
|
|
143
|
+
**A host that renders its markup once sets the value through the enhancer**, silently: no change
|
|
144
|
+
event, so the binding that set it does not hear it back as a pick. `FreedayCombo.setValue(root, v)`,
|
|
145
|
+
`FreedayDatepicker.setValue(root, v)` (`YYYY-MM-DD`, `YYYY-MM` in month mode, `"start/end"` on a
|
|
146
|
+
single-field range), `FreedayDatepicker.setRange(root, from, to)` on a two-picker
|
|
147
|
+
`data-fdy-daterange` root (it relinks the end's minimum as a pick would), `FreedayTimepicker.setValue`,
|
|
148
|
+
`FreedayCascade.setValue` with `FreedayCascade.setNodes(root, tree)` (`[{ value, label, children }]`,
|
|
149
|
+
read as the seed `<ul>` is: an empty value falls back to the label, no children means a leaf), and
|
|
150
|
+
`FreedayAutocomplete.setValue(root, text)` with `FreedayAutocomplete.setOptions(root, labels)`. An
|
|
151
|
+
empty string clears. The Blazor wrappers call these when a bound `Value`, `From`, `To`, `Options` or
|
|
152
|
+
`Nodes` changes after the first render, comparing lists and trees by content; before 3.25.0 only
|
|
153
|
+
`FdyCombo` did, and the others kept showing their first value. The autocomplete also reads its
|
|
154
|
+
options from the list each time it uses them, so options an app renders later are filtered like the
|
|
155
|
+
rest.
|
|
156
|
+
|
|
143
157
|
**State classes** the enhancers set (read them, don't hand-author them): `is-active`,
|
|
144
158
|
`is-complete`, `is-open`, `is-selected`, `is-highlighted`, `is-filled`, `is-today`, `is-dragover`,
|
|
145
159
|
`is-leaving`, `is-error`, `is-disabled`, `is-hidden`, `is-visible`, `is-outside`.
|
package/README.id.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> **Lebih banyak _free day_ buat dev. UI kit-nya sudah siap pakai.**
|
|
6
6
|
|
|
7
7
|
[](https://cahyo-dimas.github.io/freeday-ui-kit/)
|
|
8
|
-
[](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.26.0)
|
|
9
9
|
|
|
10
10
|
UI KIT yang token-driven & framework-agnostic. Satu sumber kebenaran untuk warna, tipografi,
|
|
11
11
|
spasi, dan komponen. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> **More free days for devs. The UI kit is ready to use.**
|
|
6
6
|
|
|
7
7
|
[](https://cahyo-dimas.github.io/freeday-ui-kit/)
|
|
8
|
-
[](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.26.0)
|
|
9
9
|
|
|
10
10
|
A token-driven, framework-agnostic UI kit. One source of truth for color, typography,
|
|
11
11
|
spacing, and components. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
hydration (ShouldRender => false); the initial value seeds the input. *@
|
|
8
8
|
<div @ref="Root" data-fdy-autocomplete class="@RootClass" style="@RootStyle">
|
|
9
9
|
<input @attributes="InputAttributes" class="fdy-input" role="combobox" aria-expanded="false" aria-autocomplete="list"
|
|
10
|
-
aria-controls="@_listId" autocomplete="off" value="@Value"
|
|
10
|
+
aria-controls="@_listId" autocomplete="off" value="@Value" @oninput="OnInputAsync"
|
|
11
11
|
placeholder="@Placeholder" aria-label="@AriaLabel"
|
|
12
12
|
id="@Id" aria-labelledby="@AriaLabelledby" aria-describedby="@Describedby"
|
|
13
13
|
disabled="@Disabled" readonly="@Readonly" required="@Required"
|
|
@@ -66,9 +66,30 @@ public partial class FdyAutocomplete
|
|
|
66
66
|
|
|
67
67
|
protected override bool ShouldRender() => !Hydrated;
|
|
68
68
|
|
|
69
|
+
/* What the seed shows until hydration, then what was last pushed, typed or picked. The seed is
|
|
70
|
+
rendered once, so Value and Options the host changed afterwards reached nothing (#123). */
|
|
71
|
+
private string? _shownValue;
|
|
72
|
+
private IReadOnlyList<string> _shownOptions = Array.Empty<string>();
|
|
73
|
+
|
|
69
74
|
protected override async Task OnParametersSetAsync()
|
|
70
75
|
{
|
|
71
|
-
if (!Hydrated)
|
|
76
|
+
if (!Hydrated)
|
|
77
|
+
{
|
|
78
|
+
_shownValue = Value;
|
|
79
|
+
_shownOptions = Options;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
/* Compared by content: a host that rebuilds the same list on every render is not a change. */
|
|
83
|
+
if (!_shownOptions.SequenceEqual(Options))
|
|
84
|
+
{
|
|
85
|
+
_shownOptions = Options;
|
|
86
|
+
await JS.InvokeVoidAsync("FreedayAutocomplete.setOptions", Root, Options);
|
|
87
|
+
}
|
|
88
|
+
if (Value != _shownValue)
|
|
89
|
+
{
|
|
90
|
+
_shownValue = Value;
|
|
91
|
+
await JS.InvokeVoidAsync("FreedayAutocomplete.setValue", Root, Value ?? string.Empty);
|
|
92
|
+
}
|
|
72
93
|
await JS.InvokeVoidAsync("FreedayAutocomplete.setState", Root,
|
|
73
94
|
new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
|
|
74
95
|
}
|
|
@@ -78,9 +99,21 @@ public partial class FdyAutocomplete
|
|
|
78
99
|
public async Task OnSelect(SelectDetail detail)
|
|
79
100
|
{
|
|
80
101
|
Value = detail.Value;
|
|
102
|
+
_shownValue = detail.Value;
|
|
81
103
|
await ValueChanged.InvokeAsync(detail.Value);
|
|
82
104
|
}
|
|
83
105
|
|
|
106
|
+
/// <summary>Free text, reported as it is typed, the same as the Vue and React components. Only a
|
|
107
|
+
/// pick used to reach <c>ValueChanged</c>, so a typed value that matched no suggestion showed in
|
|
108
|
+
/// the field while <c>Value</c> kept the old one.</summary>
|
|
109
|
+
private async Task OnInputAsync(ChangeEventArgs e)
|
|
110
|
+
{
|
|
111
|
+
string? text = e.Value?.ToString();
|
|
112
|
+
Value = text;
|
|
113
|
+
_shownValue = text;
|
|
114
|
+
await ValueChanged.InvokeAsync(text);
|
|
115
|
+
}
|
|
116
|
+
|
|
84
117
|
/// <summary>The (DOM-safe) detail of the enhancer's <c>fdy-autocomplete-select</c> event.</summary>
|
|
85
118
|
public sealed record SelectDetail(string? Value);
|
|
86
119
|
}
|
|
@@ -55,11 +55,46 @@ public partial class FdyCascade
|
|
|
55
55
|
|
|
56
56
|
protected override bool ShouldRender() => !Hydrated;
|
|
57
57
|
|
|
58
|
+
private string? _shownValue;
|
|
59
|
+
private IReadOnlyList<FdyCascadeNode> _shownNodes = Array.Empty<FdyCascadeNode>();
|
|
60
|
+
|
|
61
|
+
/// <summary>The same tree by content. Record equality compares <c>Children</c> by reference, so a
|
|
62
|
+
/// host that rebuilds an identical tree on every render would otherwise push it every time.</summary>
|
|
63
|
+
private static bool SameTree(IReadOnlyList<FdyCascadeNode>? a, IReadOnlyList<FdyCascadeNode>? b)
|
|
64
|
+
{
|
|
65
|
+
int countA = a?.Count ?? 0, countB = b?.Count ?? 0;
|
|
66
|
+
if (countA != countB) return false;
|
|
67
|
+
for (int i = 0; i < countA; i++)
|
|
68
|
+
{
|
|
69
|
+
FdyCascadeNode x = a![i], y = b![i];
|
|
70
|
+
if (x.Value != y.Value || x.Label != y.Label || !SameTree(x.Children, y.Children)) return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
/* Pushed, not re-rendered: the seed's <ul> is consumed and removed by the enhancer, so this
|
|
59
76
|
component can never render again. */
|
|
60
77
|
protected override async Task OnParametersSetAsync()
|
|
61
78
|
{
|
|
62
|
-
|
|
79
|
+
/* What the seed shows until hydration, then what was last pushed or picked. The seed is
|
|
80
|
+
rendered once, so a Value the host changes afterwards reached nothing (#123). */
|
|
81
|
+
if (!Hydrated)
|
|
82
|
+
{
|
|
83
|
+
_shownValue = Value;
|
|
84
|
+
_shownNodes = Nodes;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
/* The tree before the value, so a value that only exists in the new tree finds its path. */
|
|
88
|
+
if (!SameTree(_shownNodes, Nodes))
|
|
89
|
+
{
|
|
90
|
+
_shownNodes = Nodes;
|
|
91
|
+
await JS.InvokeVoidAsync("FreedayCascade.setNodes", Root, Nodes);
|
|
92
|
+
}
|
|
93
|
+
if (Value != _shownValue)
|
|
94
|
+
{
|
|
95
|
+
_shownValue = Value;
|
|
96
|
+
await JS.InvokeVoidAsync("FreedayCascade.setValue", Root, Value ?? string.Empty);
|
|
97
|
+
}
|
|
63
98
|
await JS.InvokeVoidAsync("FreedayCascade.setState", Root,
|
|
64
99
|
new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
|
|
65
100
|
}
|
|
@@ -69,6 +104,7 @@ public partial class FdyCascade
|
|
|
69
104
|
public async Task OnChange(ChangeDetail detail)
|
|
70
105
|
{
|
|
71
106
|
Value = detail.Value;
|
|
107
|
+
_shownValue = detail.Value;
|
|
72
108
|
await ValueChanged.InvokeAsync(detail.Value);
|
|
73
109
|
}
|
|
74
110
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
else
|
|
29
29
|
{
|
|
30
|
-
<div data-fdy-daterange role="group" aria-label="@AriaLabel">
|
|
30
|
+
<div @ref="_splitEl" data-fdy-daterange role="group" aria-label="@AriaLabel">
|
|
31
31
|
<div @ref="_fromEl" data-fdy-datepicker data-role="from" data-fdy-required="@(Required ? "" : null)"
|
|
32
32
|
data-value="@From" data-placeholder="@FromPlaceholder" data-min="@Min" data-max="@Max"
|
|
33
33
|
data-fdy-text-prev-month="@PrevMonthLabel"
|
|
@@ -68,6 +68,12 @@ public partial class FdyDateRange
|
|
|
68
68
|
private ElementReference _fromEl;
|
|
69
69
|
private ElementReference _toEl;
|
|
70
70
|
private ElementReference _singleEl;
|
|
71
|
+
private ElementReference _splitEl;
|
|
72
|
+
|
|
73
|
+
/* What the seed shows until hydration, then what was last pushed or picked. The seed is
|
|
74
|
+
rendered once, so From and To the host changed afterwards reached nothing (#123). */
|
|
75
|
+
private string? _shownFrom;
|
|
76
|
+
private string? _shownTo;
|
|
71
77
|
|
|
72
78
|
/// <summary>"from/to" (ISO 8601 interval), the one <c>data-value</c> the single field reads,
|
|
73
79
|
/// or null while either end is missing: the field never shows half a range.</summary>
|
|
@@ -90,7 +96,21 @@ public partial class FdyDateRange
|
|
|
90
96
|
|
|
91
97
|
protected override async Task OnParametersSetAsync()
|
|
92
98
|
{
|
|
93
|
-
if (!Hydrated)
|
|
99
|
+
if (!Hydrated)
|
|
100
|
+
{
|
|
101
|
+
_shownFrom = From;
|
|
102
|
+
_shownTo = To;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (From != _shownFrom || To != _shownTo)
|
|
106
|
+
{
|
|
107
|
+
_shownFrom = From;
|
|
108
|
+
_shownTo = To;
|
|
109
|
+
if (Layout == FdyDateRangeLayout.Single)
|
|
110
|
+
await JS.InvokeVoidAsync("FreedayDatepicker.setValue", _singleEl, SeedInterval ?? string.Empty);
|
|
111
|
+
else
|
|
112
|
+
await JS.InvokeVoidAsync("FreedayDatepicker.setRange", _splitEl, From ?? string.Empty, To ?? string.Empty);
|
|
113
|
+
}
|
|
94
114
|
if (Layout == FdyDateRangeLayout.Single)
|
|
95
115
|
{
|
|
96
116
|
await JS.InvokeVoidAsync("FreedayDatepicker.setState", _singleEl, new { required = Required });
|
|
@@ -107,11 +127,13 @@ public partial class FdyDateRange
|
|
|
107
127
|
if (detail.Role == "from")
|
|
108
128
|
{
|
|
109
129
|
From = detail.Value;
|
|
130
|
+
_shownFrom = detail.Value;
|
|
110
131
|
await FromChanged.InvokeAsync(detail.Value);
|
|
111
132
|
}
|
|
112
133
|
else if (detail.Role == "to")
|
|
113
134
|
{
|
|
114
135
|
To = detail.Value;
|
|
136
|
+
_shownTo = detail.Value;
|
|
115
137
|
await ToChanged.InvokeAsync(detail.Value);
|
|
116
138
|
}
|
|
117
139
|
if (string.IsNullOrEmpty(From) == string.IsNullOrEmpty(To))
|
|
@@ -127,6 +149,8 @@ public partial class FdyDateRange
|
|
|
127
149
|
{
|
|
128
150
|
From = detail.From;
|
|
129
151
|
To = detail.To;
|
|
152
|
+
_shownFrom = detail.From;
|
|
153
|
+
_shownTo = detail.To;
|
|
130
154
|
await FromChanged.InvokeAsync(detail.From);
|
|
131
155
|
await ToChanged.InvokeAsync(detail.To);
|
|
132
156
|
await Settled.InvokeAsync(new SettledRange(From, To));
|
|
@@ -89,12 +89,25 @@ public partial class FdyDatepicker
|
|
|
89
89
|
// The enhancer owns the built trigger + calendar; never let Blazor re-render the seed.
|
|
90
90
|
protected override bool ShouldRender() => !Hydrated;
|
|
91
91
|
|
|
92
|
+
private string? _shownValue;
|
|
93
|
+
|
|
92
94
|
/* Which is exactly why the three states are pushed rather than re-rendered: the seed above is
|
|
93
95
|
written once, so a page that disables this field later would otherwise be ignored in
|
|
94
96
|
silence. */
|
|
95
97
|
protected override async Task OnParametersSetAsync()
|
|
96
98
|
{
|
|
97
|
-
|
|
99
|
+
/* What the seed shows until hydration, then what was last pushed or picked. The seed is
|
|
100
|
+
rendered once, so a Value the host changes afterwards reached nothing (#123). */
|
|
101
|
+
if (!Hydrated)
|
|
102
|
+
{
|
|
103
|
+
_shownValue = Value;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (Value != _shownValue)
|
|
107
|
+
{
|
|
108
|
+
_shownValue = Value;
|
|
109
|
+
await JS.InvokeVoidAsync("FreedayDatepicker.setValue", Root, Value ?? string.Empty);
|
|
110
|
+
}
|
|
98
111
|
await JS.InvokeVoidAsync("FreedayDatepicker.setState", Root,
|
|
99
112
|
new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
|
|
100
113
|
}
|
|
@@ -104,6 +117,7 @@ public partial class FdyDatepicker
|
|
|
104
117
|
public async Task OnChange(ChangeDetail detail)
|
|
105
118
|
{
|
|
106
119
|
Value = detail.Value;
|
|
120
|
+
_shownValue = detail.Value;
|
|
107
121
|
await ValueChanged.InvokeAsync(detail.Value);
|
|
108
122
|
}
|
|
109
123
|
|
|
@@ -87,11 +87,24 @@ public partial class FdyMonthpicker
|
|
|
87
87
|
// The enhancer owns the built trigger + calendar; never let Blazor re-render the seed.
|
|
88
88
|
protected override bool ShouldRender() => !Hydrated;
|
|
89
89
|
|
|
90
|
+
private string? _shownValue;
|
|
91
|
+
|
|
90
92
|
/* Which is why the three states are pushed rather than re-rendered: the seed is written once,
|
|
91
93
|
so a page that disables this field later would otherwise be ignored in silence. */
|
|
92
94
|
protected override async Task OnParametersSetAsync()
|
|
93
95
|
{
|
|
94
|
-
|
|
96
|
+
/* What the seed shows until hydration, then what was last pushed or picked. The seed is
|
|
97
|
+
rendered once, so a Value the host changes afterwards reached nothing (#123). */
|
|
98
|
+
if (!Hydrated)
|
|
99
|
+
{
|
|
100
|
+
_shownValue = Value;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (Value != _shownValue)
|
|
104
|
+
{
|
|
105
|
+
_shownValue = Value;
|
|
106
|
+
await JS.InvokeVoidAsync("FreedayDatepicker.setValue", Root, Value ?? string.Empty);
|
|
107
|
+
}
|
|
95
108
|
await JS.InvokeVoidAsync("FreedayDatepicker.setState", Root,
|
|
96
109
|
new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
|
|
97
110
|
}
|
|
@@ -101,6 +114,7 @@ public partial class FdyMonthpicker
|
|
|
101
114
|
public async Task OnChange(ChangeDetail detail)
|
|
102
115
|
{
|
|
103
116
|
Value = detail.Value;
|
|
117
|
+
_shownValue = detail.Value;
|
|
104
118
|
await ValueChanged.InvokeAsync(detail.Value);
|
|
105
119
|
}
|
|
106
120
|
|
|
@@ -64,11 +64,24 @@ public partial class FdyTimepicker
|
|
|
64
64
|
// The enhancer owns the built trigger + listbox; never let Blazor re-render the seed.
|
|
65
65
|
protected override bool ShouldRender() => !Hydrated;
|
|
66
66
|
|
|
67
|
+
private string? _shownValue;
|
|
68
|
+
|
|
67
69
|
/* Which is exactly why the three states are pushed rather than re-rendered: the seed above is
|
|
68
70
|
written once, so a page that disables this field later would otherwise be ignored. */
|
|
69
71
|
protected override async Task OnParametersSetAsync()
|
|
70
72
|
{
|
|
71
|
-
|
|
73
|
+
/* What the seed shows until hydration, then what was last pushed or picked. The seed is
|
|
74
|
+
rendered once, so a Value the host changes afterwards reached nothing (#123). */
|
|
75
|
+
if (!Hydrated)
|
|
76
|
+
{
|
|
77
|
+
_shownValue = Value;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (Value != _shownValue)
|
|
81
|
+
{
|
|
82
|
+
_shownValue = Value;
|
|
83
|
+
await JS.InvokeVoidAsync("FreedayTimepicker.setValue", Root, Value ?? string.Empty);
|
|
84
|
+
}
|
|
72
85
|
await JS.InvokeVoidAsync("FreedayTimepicker.setState", Root,
|
|
73
86
|
new { disabled = Disabled, @readonly = Readonly, invalid = Invalid, required = Required });
|
|
74
87
|
}
|
|
@@ -78,6 +91,7 @@ public partial class FdyTimepicker
|
|
|
78
91
|
public async Task OnSelect(SelectDetail detail)
|
|
79
92
|
{
|
|
80
93
|
Value = detail.Value;
|
|
94
|
+
_shownValue = detail.Value;
|
|
81
95
|
await ValueChanged.InvokeAsync(detail.Value);
|
|
82
96
|
}
|
|
83
97
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* Freeday, autocomplete enhancer (optional, zero-dependency).
|
|
2
2
|
* Editable combobox (WAI-ARIA APG): a text input filters a role="listbox" of role="option"
|
|
3
3
|
* items as you type; select fills the input. Auto-inits [data-fdy-autocomplete]. Options are
|
|
4
|
-
*
|
|
4
|
+
* markup filtered client-side and read from the list each time they are used, so an app that
|
|
5
|
+
* re-renders them (after a server-side search) is heard without re-initialising. A host that
|
|
6
|
+
* renders once uses FreedayAutocomplete.setOptions(root, labels).
|
|
5
7
|
*
|
|
6
8
|
* Markup: <div data-fdy-autocomplete class="fdy-autocomplete">
|
|
7
9
|
* <input class="fdy-input" role="combobox" aria-expanded="false" aria-autocomplete="list"
|
|
@@ -25,19 +27,24 @@
|
|
|
25
27
|
root._fdyInvalid = !!input && input.getAttribute('aria-invalid') === 'true';
|
|
26
28
|
var listbox = root.querySelector('[role="listbox"]');
|
|
27
29
|
if (!input || !listbox) return;
|
|
28
|
-
var options = Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]'));
|
|
29
30
|
var emptyEl = listbox.querySelector('.fdy-autocomplete__empty');
|
|
30
31
|
var active = -1;
|
|
31
32
|
|
|
32
|
-
options
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/* Read from the list every time, not captured once at init: options rendered later were never
|
|
34
|
+
seen, and the ready flag refused the re-init that would have found them (#123). */
|
|
35
|
+
function allOptions() {
|
|
36
|
+
return Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]')).map(function (o) {
|
|
37
|
+
if (!o.id) { seq += 1; o.id = 'fdy-ac-opt-' + seq; }
|
|
38
|
+
o.dataset.label = o.textContent.trim();
|
|
39
|
+
return o;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
allOptions();
|
|
36
43
|
listbox.hidden = true;
|
|
37
44
|
input.setAttribute('aria-expanded', 'false');
|
|
38
45
|
|
|
39
|
-
function visible() { return
|
|
40
|
-
function clearHighlight() {
|
|
46
|
+
function visible() { return allOptions().filter(function (o) { return !o.hidden; }); }
|
|
47
|
+
function clearHighlight() { allOptions().forEach(function (o) { o.classList.remove('is-highlighted'); }); }
|
|
41
48
|
|
|
42
49
|
var _pop = null;
|
|
43
50
|
function popCtl() { if (_pop === null && window.FreedayPopover) _pop = window.FreedayPopover.attach(listbox, input); return _pop; }
|
|
@@ -76,6 +83,7 @@
|
|
|
76
83
|
a saved record) is not a query, and filtering by it opened a one-item list that looked broken
|
|
77
84
|
(#115). Reset on close, so the arrow keys reopen it whole as well. */
|
|
78
85
|
function showAll() {
|
|
86
|
+
var options = allOptions();
|
|
79
87
|
options.forEach(function (o) { o.hidden = false; });
|
|
80
88
|
if (emptyEl) emptyEl.hidden = options.length !== 0;
|
|
81
89
|
}
|
|
@@ -83,7 +91,7 @@
|
|
|
83
91
|
function applyFilter() {
|
|
84
92
|
var q = input.value.trim().toLowerCase();
|
|
85
93
|
var shown = 0;
|
|
86
|
-
|
|
94
|
+
allOptions().forEach(function (o) {
|
|
87
95
|
var match = !q || o.dataset.label.toLowerCase().indexOf(q) !== -1;
|
|
88
96
|
o.hidden = !match;
|
|
89
97
|
if (match) shown++;
|
|
@@ -97,7 +105,7 @@
|
|
|
97
105
|
|
|
98
106
|
function choose(opt) {
|
|
99
107
|
input.value = opt.dataset.label;
|
|
100
|
-
|
|
108
|
+
allOptions().forEach(function (o) { o.setAttribute('aria-selected', o === opt ? 'true' : 'false'); });
|
|
101
109
|
close();
|
|
102
110
|
root.dispatchEvent(new CustomEvent('fdy-autocomplete-select', { bubbles: true, detail: { value: opt.dataset.label, option: opt } }));
|
|
103
111
|
}
|
|
@@ -137,6 +145,27 @@
|
|
|
137
145
|
var opt = e.target.closest('[role="option"]');
|
|
138
146
|
if (opt && !opt.hidden) choose(opt);
|
|
139
147
|
});
|
|
148
|
+
|
|
149
|
+
/* For a host that renders its markup once (Blazor): the list and the text are pushed in, silently.
|
|
150
|
+
New options are filtered by what is typed if the list is open, and shown whole otherwise. */
|
|
151
|
+
root._fdyAc = {
|
|
152
|
+
setOptions: function (labels) {
|
|
153
|
+
allOptions().forEach(function (o) { o.remove(); });
|
|
154
|
+
(labels || []).forEach(function (label) {
|
|
155
|
+
var li = document.createElement('li');
|
|
156
|
+
li.className = 'fdy-autocomplete__option';
|
|
157
|
+
li.setAttribute('role', 'option');
|
|
158
|
+
li.textContent = label;
|
|
159
|
+
listbox.insertBefore(li, emptyEl);
|
|
160
|
+
});
|
|
161
|
+
allOptions();
|
|
162
|
+
if (listbox.hidden) showAll(); else applyFilter();
|
|
163
|
+
},
|
|
164
|
+
setValue: function (text) {
|
|
165
|
+
input.value = text || '';
|
|
166
|
+
allOptions().forEach(function (o) { o.setAttribute('aria-selected', o.dataset.label === input.value ? 'true' : 'false'); });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
140
169
|
}
|
|
141
170
|
|
|
142
171
|
function initAll(context) {
|
|
@@ -169,5 +198,8 @@
|
|
|
169
198
|
if (state.required != null) input.required = !!state.required;
|
|
170
199
|
}
|
|
171
200
|
|
|
172
|
-
|
|
201
|
+
function setValue(root, text) { if (root && root._fdyAc) root._fdyAc.setValue(text); }
|
|
202
|
+
function setOptions(root, labels) { if (root && root._fdyAc) root._fdyAc.setOptions(labels); }
|
|
203
|
+
|
|
204
|
+
window.FreedayAutocomplete = { init: initAutocomplete, initAll: initAll, setState: setState, setValue: setValue, setOptions: setOptions };
|
|
173
205
|
})();
|
package/dist/freeday-cascade.js
CHANGED
|
@@ -42,6 +42,18 @@
|
|
|
42
42
|
});
|
|
43
43
|
return nodes;
|
|
44
44
|
}
|
|
45
|
+
/* A tree from a host, in the shape parse() produces: an empty value falls back to the label, and
|
|
46
|
+
a node with no children (or an empty list) is a leaf. */
|
|
47
|
+
function normalize(list) {
|
|
48
|
+
return (list || []).map(function (n) {
|
|
49
|
+
var label = String(n.label == null ? '' : n.label);
|
|
50
|
+
return {
|
|
51
|
+
label: label,
|
|
52
|
+
value: n.value != null && n.value !== '' ? String(n.value) : label,
|
|
53
|
+
children: n.children && n.children.length ? normalize(n.children) : null
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
45
57
|
// Depth-first search for the stack of labels leading to a leaf value.
|
|
46
58
|
function pathTo(nodes, value, trail) {
|
|
47
59
|
for (var i = 0; i < nodes.length; i++) {
|
|
@@ -306,14 +318,18 @@
|
|
|
306
318
|
if (li) activate(opts.indexOf(li));
|
|
307
319
|
});
|
|
308
320
|
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
321
|
+
// The selected leaf shows its full path, else the placeholder. At init and on setValue alike.
|
|
322
|
+
function showValue() {
|
|
323
|
+
var trail = selectedValue ? pathTo(root, selectedValue, []) : null;
|
|
324
|
+
if (trail) {
|
|
325
|
+
valueSpan.textContent = trail.map(function (n) { return n.label; }).join(sep);
|
|
326
|
+
valueSpan.classList.remove('fdy-cascade__value--placeholder');
|
|
327
|
+
} else {
|
|
328
|
+
valueSpan.textContent = placeholder;
|
|
329
|
+
valueSpan.classList.add('fdy-cascade__value--placeholder');
|
|
330
|
+
}
|
|
316
331
|
}
|
|
332
|
+
showValue();
|
|
317
333
|
|
|
318
334
|
applyState();
|
|
319
335
|
applyInvalid();
|
|
@@ -322,7 +338,26 @@
|
|
|
322
338
|
wrap: wrap,
|
|
323
339
|
setState: setState,
|
|
324
340
|
getValue: function () { return selectedValue; },
|
|
325
|
-
clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); }
|
|
341
|
+
clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); },
|
|
342
|
+
/* The host's own value, pushed in silently: no fdy-cascade-change, so a binding that set it
|
|
343
|
+
does not hear it back. A render-once host (Blazor) has no other way to change it. */
|
|
344
|
+
setValue: function (next) {
|
|
345
|
+
selectedValue = next || '';
|
|
346
|
+
wrap.setAttribute('data-value', selectedValue);
|
|
347
|
+
showValue();
|
|
348
|
+
if (!panel.hidden) render();
|
|
349
|
+
},
|
|
350
|
+
/* A new tree from the host. The seed <ul> was consumed at init, so this is the only way a
|
|
351
|
+
render-once host (Blazor) can change the options (#123). The view goes back to the top
|
|
352
|
+
level, and the value's path is looked up again: a value the new tree lacks shows the
|
|
353
|
+
placeholder until the host sets one it has. */
|
|
354
|
+
setNodes: function (tree) {
|
|
355
|
+
root = normalize(tree);
|
|
356
|
+
stack = [];
|
|
357
|
+
current = root;
|
|
358
|
+
showValue();
|
|
359
|
+
if (!panel.hidden) render();
|
|
360
|
+
}
|
|
326
361
|
};
|
|
327
362
|
wrap._fdyCascade = api;
|
|
328
363
|
return api;
|
|
@@ -348,6 +383,15 @@
|
|
|
348
383
|
setState: function (root, state) {
|
|
349
384
|
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
350
385
|
if (api && api.setState) api.setState(state);
|
|
386
|
+
},
|
|
387
|
+
setValue: function (root, value) {
|
|
388
|
+
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
389
|
+
if (api) api.setValue(value);
|
|
390
|
+
},
|
|
391
|
+
/* The options as a tree, [{ value, label, children }], replacing the one the seed gave. */
|
|
392
|
+
setNodes: function (root, tree) {
|
|
393
|
+
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
394
|
+
if (api) api.setNodes(tree);
|
|
351
395
|
}
|
|
352
396
|
};
|
|
353
397
|
})();
|
|
@@ -809,6 +809,22 @@
|
|
|
809
809
|
return selected ? (monthOnly ? toISOMonth(selected) : toISO(selected)) : '';
|
|
810
810
|
},
|
|
811
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
|
+
},
|
|
812
828
|
setMin: function (iso) { minDate = parseVal(iso); if (!panel.hidden) render(); },
|
|
813
829
|
setMax: function (iso) { maxDate = parseVal(iso); if (!panel.hidden) render(); },
|
|
814
830
|
setRange: function (fromIso, toIso) {
|
|
@@ -855,6 +871,15 @@
|
|
|
855
871
|
if ((f === '') !== (t === '')) return;
|
|
856
872
|
root.dispatchEvent(new CustomEvent('fdy-daterange-settled', { bubbles: true, detail: { from: f, to: t } }));
|
|
857
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
|
+
};
|
|
858
883
|
fromEl.addEventListener('fdy-datepicker-change', function () {
|
|
859
884
|
var f = fromApi.getValue(), t = toApi.getValue();
|
|
860
885
|
if (f && t && t < f) clearEnd(toEl, toApi);
|
|
@@ -893,6 +918,17 @@
|
|
|
893
918
|
setState: function (root, state) {
|
|
894
919
|
var api = root && root._fdyDp ? root._fdyDp : null;
|
|
895
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);
|
|
896
932
|
}
|
|
897
933
|
};
|
|
898
934
|
})();
|
|
@@ -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
|
})();
|
package/dist/freeday.js
CHANGED
|
@@ -230,7 +230,9 @@
|
|
|
230
230
|
/* Freeday, autocomplete enhancer (optional, zero-dependency).
|
|
231
231
|
* Editable combobox (WAI-ARIA APG): a text input filters a role="listbox" of role="option"
|
|
232
232
|
* items as you type; select fills the input. Auto-inits [data-fdy-autocomplete]. Options are
|
|
233
|
-
*
|
|
233
|
+
* markup filtered client-side and read from the list each time they are used, so an app that
|
|
234
|
+
* re-renders them (after a server-side search) is heard without re-initialising. A host that
|
|
235
|
+
* renders once uses FreedayAutocomplete.setOptions(root, labels).
|
|
234
236
|
*
|
|
235
237
|
* Markup: <div data-fdy-autocomplete class="fdy-autocomplete">
|
|
236
238
|
* <input class="fdy-input" role="combobox" aria-expanded="false" aria-autocomplete="list"
|
|
@@ -254,19 +256,24 @@
|
|
|
254
256
|
root._fdyInvalid = !!input && input.getAttribute('aria-invalid') === 'true';
|
|
255
257
|
var listbox = root.querySelector('[role="listbox"]');
|
|
256
258
|
if (!input || !listbox) return;
|
|
257
|
-
var options = Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]'));
|
|
258
259
|
var emptyEl = listbox.querySelector('.fdy-autocomplete__empty');
|
|
259
260
|
var active = -1;
|
|
260
261
|
|
|
261
|
-
options
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
/* Read from the list every time, not captured once at init: options rendered later were never
|
|
263
|
+
seen, and the ready flag refused the re-init that would have found them (#123). */
|
|
264
|
+
function allOptions() {
|
|
265
|
+
return Array.prototype.slice.call(listbox.querySelectorAll('[role="option"]')).map(function (o) {
|
|
266
|
+
if (!o.id) { seq += 1; o.id = 'fdy-ac-opt-' + seq; }
|
|
267
|
+
o.dataset.label = o.textContent.trim();
|
|
268
|
+
return o;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
allOptions();
|
|
265
272
|
listbox.hidden = true;
|
|
266
273
|
input.setAttribute('aria-expanded', 'false');
|
|
267
274
|
|
|
268
|
-
function visible() { return
|
|
269
|
-
function clearHighlight() {
|
|
275
|
+
function visible() { return allOptions().filter(function (o) { return !o.hidden; }); }
|
|
276
|
+
function clearHighlight() { allOptions().forEach(function (o) { o.classList.remove('is-highlighted'); }); }
|
|
270
277
|
|
|
271
278
|
var _pop = null;
|
|
272
279
|
function popCtl() { if (_pop === null && window.FreedayPopover) _pop = window.FreedayPopover.attach(listbox, input); return _pop; }
|
|
@@ -305,6 +312,7 @@
|
|
|
305
312
|
a saved record) is not a query, and filtering by it opened a one-item list that looked broken
|
|
306
313
|
(#115). Reset on close, so the arrow keys reopen it whole as well. */
|
|
307
314
|
function showAll() {
|
|
315
|
+
var options = allOptions();
|
|
308
316
|
options.forEach(function (o) { o.hidden = false; });
|
|
309
317
|
if (emptyEl) emptyEl.hidden = options.length !== 0;
|
|
310
318
|
}
|
|
@@ -312,7 +320,7 @@
|
|
|
312
320
|
function applyFilter() {
|
|
313
321
|
var q = input.value.trim().toLowerCase();
|
|
314
322
|
var shown = 0;
|
|
315
|
-
|
|
323
|
+
allOptions().forEach(function (o) {
|
|
316
324
|
var match = !q || o.dataset.label.toLowerCase().indexOf(q) !== -1;
|
|
317
325
|
o.hidden = !match;
|
|
318
326
|
if (match) shown++;
|
|
@@ -326,7 +334,7 @@
|
|
|
326
334
|
|
|
327
335
|
function choose(opt) {
|
|
328
336
|
input.value = opt.dataset.label;
|
|
329
|
-
|
|
337
|
+
allOptions().forEach(function (o) { o.setAttribute('aria-selected', o === opt ? 'true' : 'false'); });
|
|
330
338
|
close();
|
|
331
339
|
root.dispatchEvent(new CustomEvent('fdy-autocomplete-select', { bubbles: true, detail: { value: opt.dataset.label, option: opt } }));
|
|
332
340
|
}
|
|
@@ -366,6 +374,27 @@
|
|
|
366
374
|
var opt = e.target.closest('[role="option"]');
|
|
367
375
|
if (opt && !opt.hidden) choose(opt);
|
|
368
376
|
});
|
|
377
|
+
|
|
378
|
+
/* For a host that renders its markup once (Blazor): the list and the text are pushed in, silently.
|
|
379
|
+
New options are filtered by what is typed if the list is open, and shown whole otherwise. */
|
|
380
|
+
root._fdyAc = {
|
|
381
|
+
setOptions: function (labels) {
|
|
382
|
+
allOptions().forEach(function (o) { o.remove(); });
|
|
383
|
+
(labels || []).forEach(function (label) {
|
|
384
|
+
var li = document.createElement('li');
|
|
385
|
+
li.className = 'fdy-autocomplete__option';
|
|
386
|
+
li.setAttribute('role', 'option');
|
|
387
|
+
li.textContent = label;
|
|
388
|
+
listbox.insertBefore(li, emptyEl);
|
|
389
|
+
});
|
|
390
|
+
allOptions();
|
|
391
|
+
if (listbox.hidden) showAll(); else applyFilter();
|
|
392
|
+
},
|
|
393
|
+
setValue: function (text) {
|
|
394
|
+
input.value = text || '';
|
|
395
|
+
allOptions().forEach(function (o) { o.setAttribute('aria-selected', o.dataset.label === input.value ? 'true' : 'false'); });
|
|
396
|
+
}
|
|
397
|
+
};
|
|
369
398
|
}
|
|
370
399
|
|
|
371
400
|
function initAll(context) {
|
|
@@ -398,7 +427,10 @@
|
|
|
398
427
|
if (state.required != null) input.required = !!state.required;
|
|
399
428
|
}
|
|
400
429
|
|
|
401
|
-
|
|
430
|
+
function setValue(root, text) { if (root && root._fdyAc) root._fdyAc.setValue(text); }
|
|
431
|
+
function setOptions(root, labels) { if (root && root._fdyAc) root._fdyAc.setOptions(labels); }
|
|
432
|
+
|
|
433
|
+
window.FreedayAutocomplete = { init: initAutocomplete, initAll: initAll, setState: setState, setValue: setValue, setOptions: setOptions };
|
|
402
434
|
})();
|
|
403
435
|
|
|
404
436
|
/* Freeday, breakpoint provider (optional, zero-dependency).
|
|
@@ -819,6 +851,18 @@
|
|
|
819
851
|
});
|
|
820
852
|
return nodes;
|
|
821
853
|
}
|
|
854
|
+
/* A tree from a host, in the shape parse() produces: an empty value falls back to the label, and
|
|
855
|
+
a node with no children (or an empty list) is a leaf. */
|
|
856
|
+
function normalize(list) {
|
|
857
|
+
return (list || []).map(function (n) {
|
|
858
|
+
var label = String(n.label == null ? '' : n.label);
|
|
859
|
+
return {
|
|
860
|
+
label: label,
|
|
861
|
+
value: n.value != null && n.value !== '' ? String(n.value) : label,
|
|
862
|
+
children: n.children && n.children.length ? normalize(n.children) : null
|
|
863
|
+
};
|
|
864
|
+
});
|
|
865
|
+
}
|
|
822
866
|
// Depth-first search for the stack of labels leading to a leaf value.
|
|
823
867
|
function pathTo(nodes, value, trail) {
|
|
824
868
|
for (var i = 0; i < nodes.length; i++) {
|
|
@@ -1083,14 +1127,18 @@
|
|
|
1083
1127
|
if (li) activate(opts.indexOf(li));
|
|
1084
1128
|
});
|
|
1085
1129
|
|
|
1086
|
-
//
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1130
|
+
// The selected leaf shows its full path, else the placeholder. At init and on setValue alike.
|
|
1131
|
+
function showValue() {
|
|
1132
|
+
var trail = selectedValue ? pathTo(root, selectedValue, []) : null;
|
|
1133
|
+
if (trail) {
|
|
1134
|
+
valueSpan.textContent = trail.map(function (n) { return n.label; }).join(sep);
|
|
1135
|
+
valueSpan.classList.remove('fdy-cascade__value--placeholder');
|
|
1136
|
+
} else {
|
|
1137
|
+
valueSpan.textContent = placeholder;
|
|
1138
|
+
valueSpan.classList.add('fdy-cascade__value--placeholder');
|
|
1139
|
+
}
|
|
1093
1140
|
}
|
|
1141
|
+
showValue();
|
|
1094
1142
|
|
|
1095
1143
|
applyState();
|
|
1096
1144
|
applyInvalid();
|
|
@@ -1099,7 +1147,26 @@
|
|
|
1099
1147
|
wrap: wrap,
|
|
1100
1148
|
setState: setState,
|
|
1101
1149
|
getValue: function () { return selectedValue; },
|
|
1102
|
-
clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); }
|
|
1150
|
+
clear: function () { selectedValue = ''; valueSpan.textContent = placeholder; valueSpan.classList.add('fdy-cascade__value--placeholder'); },
|
|
1151
|
+
/* The host's own value, pushed in silently: no fdy-cascade-change, so a binding that set it
|
|
1152
|
+
does not hear it back. A render-once host (Blazor) has no other way to change it. */
|
|
1153
|
+
setValue: function (next) {
|
|
1154
|
+
selectedValue = next || '';
|
|
1155
|
+
wrap.setAttribute('data-value', selectedValue);
|
|
1156
|
+
showValue();
|
|
1157
|
+
if (!panel.hidden) render();
|
|
1158
|
+
},
|
|
1159
|
+
/* A new tree from the host. The seed <ul> was consumed at init, so this is the only way a
|
|
1160
|
+
render-once host (Blazor) can change the options (#123). The view goes back to the top
|
|
1161
|
+
level, and the value's path is looked up again: a value the new tree lacks shows the
|
|
1162
|
+
placeholder until the host sets one it has. */
|
|
1163
|
+
setNodes: function (tree) {
|
|
1164
|
+
root = normalize(tree);
|
|
1165
|
+
stack = [];
|
|
1166
|
+
current = root;
|
|
1167
|
+
showValue();
|
|
1168
|
+
if (!panel.hidden) render();
|
|
1169
|
+
}
|
|
1103
1170
|
};
|
|
1104
1171
|
wrap._fdyCascade = api;
|
|
1105
1172
|
return api;
|
|
@@ -1125,6 +1192,15 @@
|
|
|
1125
1192
|
setState: function (root, state) {
|
|
1126
1193
|
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
1127
1194
|
if (api && api.setState) api.setState(state);
|
|
1195
|
+
},
|
|
1196
|
+
setValue: function (root, value) {
|
|
1197
|
+
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
1198
|
+
if (api) api.setValue(value);
|
|
1199
|
+
},
|
|
1200
|
+
/* The options as a tree, [{ value, label, children }], replacing the one the seed gave. */
|
|
1201
|
+
setNodes: function (root, tree) {
|
|
1202
|
+
var api = root && root._fdyCascade ? root._fdyCascade : null;
|
|
1203
|
+
if (api) api.setNodes(tree);
|
|
1128
1204
|
}
|
|
1129
1205
|
};
|
|
1130
1206
|
})();
|
|
@@ -2968,6 +3044,22 @@
|
|
|
2968
3044
|
return selected ? (monthOnly ? toISOMonth(selected) : toISO(selected)) : '';
|
|
2969
3045
|
},
|
|
2970
3046
|
clear: function () { selected = null; selectedEnd = null; updateDisplay(); if (!panel.hidden) render(); },
|
|
3047
|
+
/* The host's own value, pushed in silently: no change event, so a binding that set it does
|
|
3048
|
+
not hear it back. A render-once host (Blazor) has no other way to change the shown date.
|
|
3049
|
+
The single-field range takes "start/end", the form its data-value already has. */
|
|
3050
|
+
setValue: function (next) {
|
|
3051
|
+
if (rangeMode) {
|
|
3052
|
+
var iv = parseInterval(next);
|
|
3053
|
+
selected = iv.start;
|
|
3054
|
+
selectedEnd = iv.end;
|
|
3055
|
+
} else {
|
|
3056
|
+
selected = parseVal(next);
|
|
3057
|
+
}
|
|
3058
|
+
anchor = null;
|
|
3059
|
+
preview = null;
|
|
3060
|
+
updateDisplay();
|
|
3061
|
+
if (!panel.hidden) render();
|
|
3062
|
+
},
|
|
2971
3063
|
setMin: function (iso) { minDate = parseVal(iso); if (!panel.hidden) render(); },
|
|
2972
3064
|
setMax: function (iso) { maxDate = parseVal(iso); if (!panel.hidden) render(); },
|
|
2973
3065
|
setRange: function (fromIso, toIso) {
|
|
@@ -3014,6 +3106,15 @@
|
|
|
3014
3106
|
if ((f === '') !== (t === '')) return;
|
|
3015
3107
|
root.dispatchEvent(new CustomEvent('fdy-daterange-settled', { bubbles: true, detail: { from: f, to: t } }));
|
|
3016
3108
|
}
|
|
3109
|
+
/* Both ends from the host at once, then the same linking a pick gets: the end's minimum and the
|
|
3110
|
+
band shading. Silent, like each picker's own setValue. */
|
|
3111
|
+
root._fdyDr = {
|
|
3112
|
+
setRange: function (f, t) {
|
|
3113
|
+
fromApi.setValue(f || '');
|
|
3114
|
+
toApi.setValue(t || '');
|
|
3115
|
+
sync();
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3017
3118
|
fromEl.addEventListener('fdy-datepicker-change', function () {
|
|
3018
3119
|
var f = fromApi.getValue(), t = toApi.getValue();
|
|
3019
3120
|
if (f && t && t < f) clearEnd(toEl, toApi);
|
|
@@ -3052,6 +3153,17 @@
|
|
|
3052
3153
|
setState: function (root, state) {
|
|
3053
3154
|
var api = root && root._fdyDp ? root._fdyDp : null;
|
|
3054
3155
|
if (api && api.setState) api.setState(state);
|
|
3156
|
+
},
|
|
3157
|
+
/* A picker's value from the host, silently: `YYYY-MM-DD`, `YYYY-MM` in month mode, or
|
|
3158
|
+
"start/end" on a single-field range. */
|
|
3159
|
+
setValue: function (root, value) {
|
|
3160
|
+
var api = root && root._fdyDp ? root._fdyDp : null;
|
|
3161
|
+
if (api) api.setValue(value);
|
|
3162
|
+
},
|
|
3163
|
+
/* Both ends of a two-picker range (the `data-fdy-daterange` root), relinked as after a pick. */
|
|
3164
|
+
setRange: function (root, from, to) {
|
|
3165
|
+
var dr = root && root._fdyDr ? root._fdyDr : null;
|
|
3166
|
+
if (dr) dr.setRange(from, to);
|
|
3055
3167
|
}
|
|
3056
3168
|
};
|
|
3057
3169
|
})();
|
|
@@ -5902,7 +6014,14 @@
|
|
|
5902
6014
|
wrap: wrap,
|
|
5903
6015
|
getValue: function () { return value; },
|
|
5904
6016
|
setState: setState,
|
|
5905
|
-
clear: function () { value = ''; for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', 'false'); updateDisplay(); }
|
|
6017
|
+
clear: function () { value = ''; for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', 'false'); updateDisplay(); },
|
|
6018
|
+
/* The host's own value, pushed in silently: no fdy-time-select, so a binding that set it does
|
|
6019
|
+
not hear it back. A render-once host (Blazor) has no other way to change the shown time. */
|
|
6020
|
+
setValue: function (next) {
|
|
6021
|
+
value = norm(next);
|
|
6022
|
+
for (var i = 0; i < opts.length; i++) opts[i].setAttribute('aria-selected', opts[i].getAttribute('data-value') === value ? 'true' : 'false');
|
|
6023
|
+
updateDisplay();
|
|
6024
|
+
}
|
|
5906
6025
|
};
|
|
5907
6026
|
wrap._fdyTp = api;
|
|
5908
6027
|
return api;
|
|
@@ -5928,6 +6047,10 @@
|
|
|
5928
6047
|
setState: function (root, state) {
|
|
5929
6048
|
var api = root && root._fdyTp ? root._fdyTp : null;
|
|
5930
6049
|
if (api && api.setState) api.setState(state);
|
|
6050
|
+
},
|
|
6051
|
+
setValue: function (root, value) {
|
|
6052
|
+
var api = root && root._fdyTp ? root._fdyTp : null;
|
|
6053
|
+
if (api) api.setValue(value);
|
|
5931
6054
|
}
|
|
5932
6055
|
};
|
|
5933
6056
|
})();
|
package/docs/getting-started.md
CHANGED
|
@@ -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.
|
|
201
|
+
Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.26.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`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cahyo-dimas/freeday",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.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/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",
|
|
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/set-value.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",
|