@cahyo-dimas/freeday 3.22.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.
- package/CHANGELOG.md +112 -0
- package/COMPONENTS.md +77 -2
- package/README.id.md +1 -1
- package/README.md +1 -1
- package/adapters/blazor/FdyCfl.razor.cs +44 -8
- package/adapters/blazor/FdyTable.razor.cs +23 -1
- package/adapters/blazor/freeday-blazor.js +16 -2
- package/adapters/core/load-state.d.ts +17 -0
- package/adapters/core/load-state.js +37 -0
- package/adapters/react/components/FdyCfl.tsx +20 -5
- package/adapters/react/components/FdyDatepicker.tsx +10 -1
- package/adapters/react/components/FdyDrawer.tsx +8 -0
- package/adapters/react/components/FdyModal.tsx +11 -0
- package/adapters/react/components/FdyTable.tsx +28 -5
- package/adapters/react/index.d.ts +18 -0
- package/adapters/react/index.js +1 -0
- package/adapters/react/useFreeday.js +31 -0
- package/adapters/react/useLoad.js +53 -0
- package/adapters/vue/components/FdyCfl.vue +20 -6
- package/adapters/vue/components/FdyDatepicker.vue +10 -1
- package/adapters/vue/components/FdyDrawer.vue +10 -0
- package/adapters/vue/components/FdyModal.vue +12 -0
- package/adapters/vue/index.d.ts +18 -0
- package/adapters/vue/index.js +1 -0
- package/adapters/vue/useFreeday.js +32 -1
- package/adapters/vue/useLoad.js +47 -0
- package/dist/freeday-datepicker.js +25 -1
- package/dist/freeday-form.js +3 -0
- package/dist/freeday-stepper.js +14 -5
- package/dist/freeday-table.js +5 -1
- package/dist/freeday-tabs.js +76 -0
- package/dist/freeday-upload.js +17 -7
- package/dist/freeday.bundle.css +53 -0
- package/dist/freeday.css +53 -0
- package/dist/freeday.js +140 -14
- package/docs/getting-started.md +1 -1
- package/docs/reference-screen.html +1 -1
- package/docs/screen-states.md +3 -0
- package/package.json +2 -2
- package/src/components/link.css +14 -0
- package/src/components/tabs.css +38 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CSSProperties, JSX, ReactNode } from 'react';
|
|
2
|
-
import { Fragment, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
cellValue,
|
|
5
5
|
cellText,
|
|
@@ -154,6 +154,19 @@ export interface FdyTableProps<Row extends object> {
|
|
|
154
154
|
pageLabel?: string;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/** The same rows in the same order: one page, compared element by element. */
|
|
158
|
+
function sameRows<Row>(a: ReadonlyArray<Row>, b: ReadonlyArray<Row>): boolean {
|
|
159
|
+
if (a.length !== b.length) return false;
|
|
160
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* One empty filter map for every render. A server-paged table with no `filters` prop counts as
|
|
165
|
+
filter-controlled and used to read `props.filters ?? {}`: a NEW object each render, which broke
|
|
166
|
+
every memo after it, handed onProcess a new array on every commit, and looped any parent that put
|
|
167
|
+
that array in state (measured 8,625 reports in half a second). */
|
|
168
|
+
const NO_FILTERS: FdyFilterMap = Object.freeze({}) as FdyFilterMap;
|
|
169
|
+
|
|
157
170
|
export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Element {
|
|
158
171
|
const serverPaged: boolean = props.page != null;
|
|
159
172
|
const sortControlled: boolean = serverPaged || props.sort !== undefined;
|
|
@@ -175,7 +188,7 @@ export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Ele
|
|
|
175
188
|
}
|
|
176
189
|
|
|
177
190
|
const effectiveSort: FdySortState | null = sortControlled ? (props.sort ?? null) : internalSort;
|
|
178
|
-
const effectiveFilters: FdyFilterMap = filtersControlled ? (props.filters ??
|
|
191
|
+
const effectiveFilters: FdyFilterMap = filtersControlled ? (props.filters ?? NO_FILTERS) : internalFilters;
|
|
179
192
|
|
|
180
193
|
// Enum options: explicit (server mode) or distinct values across the current rows (client mode).
|
|
181
194
|
const enumOptionsMap: Record<string, ReadonlyArray<string>> = useMemo(() => {
|
|
@@ -229,10 +242,20 @@ export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Ele
|
|
|
229
242
|
|
|
230
243
|
// Surface the processed page + total to the parent (both modes), so the same result can drive a
|
|
231
244
|
// responsive card list / summary / export without re-implementing filter/sort/paginate.
|
|
232
|
-
|
|
245
|
+
/* Reported when what the parent would SEE changes: the total, or any row on the page. Identity is
|
|
246
|
+
not that. A parent writing `columns={[...]}` or `page={{...}}` inline hands over new objects on
|
|
247
|
+
every render, the memos above recompute, and the page comes out as a new array of the same rows;
|
|
248
|
+
a parent that stored it in state then rendered again, without end. The callback itself is read
|
|
249
|
+
through a ref for the same reason: an inline arrow is a new function every render. */
|
|
250
|
+
const onProcessRef = useRef(props.onProcess);
|
|
251
|
+
onProcessRef.current = props.onProcess;
|
|
252
|
+
const lastReportRef = useRef<{ rows: Row[]; total: number } | null>(null);
|
|
233
253
|
useEffect((): void => {
|
|
234
|
-
|
|
235
|
-
|
|
254
|
+
const last = lastReportRef.current;
|
|
255
|
+
if (last !== null && last.total === totalCount && sameRows(last.rows, displayRows)) return;
|
|
256
|
+
lastReportRef.current = { rows: displayRows, total: totalCount };
|
|
257
|
+
onProcessRef.current?.({ rows: displayRows, total: totalCount });
|
|
258
|
+
}, [displayRows, totalCount]);
|
|
236
259
|
|
|
237
260
|
function ariaSortOf(col: FdyTableColumn<Row>): 'ascending' | 'descending' | undefined {
|
|
238
261
|
if (effectiveSort === null || effectiveSort.key !== col.key) return undefined;
|
|
@@ -39,6 +39,24 @@ export interface UseThemeReturn {
|
|
|
39
39
|
*/
|
|
40
40
|
export declare function useTheme(rootRef?: RefObject<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: 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
|
/** `event.detail` shapes for the bubbling `fdy-*` CustomEvents. */
|
|
43
61
|
export interface FdyChangeDetail { value: string }
|
|
44
62
|
export interface FdyAutocompleteSelectDetail { value: string }
|
package/adapters/react/index.js
CHANGED
|
@@ -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 { FdyCombo } from './components/FdyCombo.tsx';
|
|
5
6
|
export { FdyDatepicker } from './components/FdyDatepicker.tsx';
|
|
@@ -47,8 +47,19 @@ var EMPTY_REF = 'Freeday: useFreeday(ref) got a ref that is still null after the
|
|
|
47
47
|
+ 'element that is not rendered yet (a condition). Put the ref on an element that is always rendered, or '
|
|
48
48
|
+ 'call useFreeday() with no argument if the whole document is what you mean.';
|
|
49
49
|
|
|
50
|
+
/* True when a batch of mutation records added at least one element. Text edits and removals cannot
|
|
51
|
+
bring a new enhancer hook into the tree, so they do not cost a scan. */
|
|
52
|
+
function addedElement(records) {
|
|
53
|
+
for (var i = 0; i < records.length; i++) {
|
|
54
|
+
var nodes = records[i].addedNodes;
|
|
55
|
+
for (var j = 0; j < nodes.length; j++) if (nodes[j].nodeType === 1) return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
export function useFreeday(rootRef) {
|
|
51
61
|
var checked = useRef(false);
|
|
62
|
+
var observerRef = useRef(null);
|
|
52
63
|
var rehydrate = useCallback(function () {
|
|
53
64
|
var el = rootRef && rootRef.current ? rootRef.current : undefined;
|
|
54
65
|
var apis = freedayApis();
|
|
@@ -62,6 +73,26 @@ export function useFreeday(rootRef) {
|
|
|
62
73
|
if (rootRef && !rootRef.current) console.warn(EMPTY_REF);
|
|
63
74
|
}
|
|
64
75
|
rehydrate();
|
|
76
|
+
if (observerRef.current) observerRef.current.takeRecords();
|
|
65
77
|
});
|
|
78
|
+
/* DOM a CHILD component commits later is hydrated too. The effect above runs when THIS component
|
|
79
|
+
commits, and a child that renders a form behind its own state never makes the parent commit, so
|
|
80
|
+
the form's `data-fdy-validate` silently did nothing (CATATAN-FREEDAY §29). The observer rehydrates
|
|
81
|
+
in its callback, a microtask, so the widget is enhanced before the browser paints it raw, and
|
|
82
|
+
takeRecords() drops what the enhancers just built, so one rehydrate never schedules the next. */
|
|
83
|
+
useEffect(function () {
|
|
84
|
+
var target = rootRef && rootRef.current ? rootRef.current : document.body;
|
|
85
|
+
var observer = new MutationObserver(function (records) {
|
|
86
|
+
if (!addedElement(records)) return;
|
|
87
|
+
rehydrate();
|
|
88
|
+
observer.takeRecords();
|
|
89
|
+
});
|
|
90
|
+
observerRef.current = observer;
|
|
91
|
+
observer.observe(target, { childList: true, subtree: true });
|
|
92
|
+
return function () {
|
|
93
|
+
observer.disconnect();
|
|
94
|
+
observerRef.current = null;
|
|
95
|
+
};
|
|
96
|
+
}, [rehydrate]);
|
|
66
97
|
return { rehydrate: rehydrate };
|
|
67
98
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* Freeday. useLoad for React: one data load as one state, with superseded requests cancelled.
|
|
2
|
+
*
|
|
3
|
+
* const { state, load } = useLoad((signal) => fetchInvoices(month, signal));
|
|
4
|
+
* useEffect(() => { void load(); }, [month, load]);
|
|
5
|
+
*
|
|
6
|
+
* state.status === 'loading' loading (state.previous: what was shown before)
|
|
7
|
+
* state.status === 'error' load error, never rendered as empty
|
|
8
|
+
* state.status === 'ready' state.data
|
|
9
|
+
*
|
|
10
|
+
* `load` is stable across renders and always calls the LATEST fetcher, so the fetcher may be an
|
|
11
|
+
* inline arrow over current props. It aborts the request before it (the fetcher gets an
|
|
12
|
+
* AbortSignal) and ignores any answer that arrives after a newer load started, so a quick change of
|
|
13
|
+
* filter can never leave the older result on screen. It returns a promise that settles when this
|
|
14
|
+
* load does and never rejects: the error is in `state`. Unmounting aborts whatever is in flight. See
|
|
15
|
+
* adapters/core/load-state.js for why the states are one value.
|
|
16
|
+
*/
|
|
17
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
18
|
+
import { IDLE, failedFrom, loadingFrom, readyWith } from '../core/load-state.js';
|
|
19
|
+
|
|
20
|
+
export function useLoad(fetcher) {
|
|
21
|
+
var pair = useState(IDLE);
|
|
22
|
+
var state = pair[0];
|
|
23
|
+
var setState = pair[1];
|
|
24
|
+
var fetcherRef = useRef(fetcher);
|
|
25
|
+
fetcherRef.current = fetcher;
|
|
26
|
+
var tokenRef = useRef(0);
|
|
27
|
+
var controllerRef = useRef(null);
|
|
28
|
+
|
|
29
|
+
var load = useCallback(function () {
|
|
30
|
+
if (controllerRef.current) controllerRef.current.abort();
|
|
31
|
+
var controller = new AbortController();
|
|
32
|
+
controllerRef.current = controller;
|
|
33
|
+
var mine = ++tokenRef.current;
|
|
34
|
+
setState(function (s) { return loadingFrom(s); });
|
|
35
|
+
return Promise.resolve()
|
|
36
|
+
.then(function () { return fetcherRef.current(controller.signal); })
|
|
37
|
+
.then(function (data) {
|
|
38
|
+
if (mine === tokenRef.current) setState(readyWith(data));
|
|
39
|
+
}, function (err) {
|
|
40
|
+
var error = err instanceof Error ? err : new Error(String(err));
|
|
41
|
+
if (mine === tokenRef.current) setState(function (s) { return failedFrom(s, error); });
|
|
42
|
+
});
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
return function () {
|
|
47
|
+
tokenRef.current += 1;
|
|
48
|
+
if (controllerRef.current) controllerRef.current.abort();
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
return { state: state, load: load };
|
|
53
|
+
}
|
|
@@ -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
|
-
|
|
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">
|
package/adapters/vue/index.d.ts
CHANGED
|
@@ -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
|
package/adapters/vue/index.js
CHANGED
|
@@ -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';
|
|
@@ -21,11 +21,16 @@
|
|
|
21
21
|
* mount. Pass no argument, useFreeday(), when the whole document is what you mean; and put the ref
|
|
22
22
|
* on an element that is always rendered, not one behind v-if.
|
|
23
23
|
*
|
|
24
|
+
* DOM a CHILD component mounts later is hydrated too. Vue calls onUpdated on the component whose
|
|
25
|
+
* render changed, so a form behind a v-if in a child never reached the parent's hook, and its
|
|
26
|
+
* `data-fdy-validate` silently did nothing (CATATAN-FREEDAY §29). A MutationObserver on the subtree
|
|
27
|
+
* closes that: any element added under it triggers one rehydrate.
|
|
28
|
+
*
|
|
24
29
|
* Events come straight through as native bubbling CustomEvents, bind them with
|
|
25
30
|
* plain v-on (e.g. @fdy-cascade-change) and read event.detail. See index.d.ts
|
|
26
31
|
* for the detail types.
|
|
27
32
|
*/
|
|
28
|
-
import { onMounted, onUpdated, nextTick } from 'vue';
|
|
33
|
+
import { onBeforeUnmount, onMounted, onUpdated, nextTick } from 'vue';
|
|
29
34
|
|
|
30
35
|
// Discover Freeday enhancer namespaces once (all registered by the time an app
|
|
31
36
|
// mounts, since `import 'freeday'` runs first). Each exposes initAll(el?).
|
|
@@ -47,17 +52,43 @@ var EMPTY_REF = 'Freeday: useFreeday(ref) got a ref that is still null after mou
|
|
|
47
52
|
+ 'that is not rendered yet (v-if). Put the ref on an element that is always rendered, or call useFreeday() '
|
|
48
53
|
+ 'with no argument if the whole document is what you mean.';
|
|
49
54
|
|
|
55
|
+
/* True when a batch of mutation records added at least one element. Text edits and removals cannot
|
|
56
|
+
bring a new enhancer hook into the tree, so they do not cost a scan. */
|
|
57
|
+
function addedElement(records) {
|
|
58
|
+
for (var i = 0; i < records.length; i++) {
|
|
59
|
+
var nodes = records[i].addedNodes;
|
|
60
|
+
for (var j = 0; j < nodes.length; j++) if (nodes[j].nodeType === 1) return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
export function useFreeday(rootRef) {
|
|
51
66
|
var apis = null;
|
|
67
|
+
var observer = null;
|
|
52
68
|
function rehydrate() {
|
|
53
69
|
if (!apis) apis = freedayApis();
|
|
54
70
|
var el = rootRef && 'value' in rootRef ? (rootRef.value || undefined) : undefined;
|
|
55
71
|
for (var i = 0; i < apis.length; i++) apis[i].initAll(el);
|
|
72
|
+
/* Whatever the enhancers just built is in the observer's queue now. Dropping it here is what
|
|
73
|
+
keeps one rehydrate from scheduling the next: initAll is synchronous, so every record it
|
|
74
|
+
caused is already queued when it returns. */
|
|
75
|
+
if (observer) observer.takeRecords();
|
|
56
76
|
}
|
|
57
77
|
onMounted(function () {
|
|
58
78
|
if (rootRef && 'value' in rootRef && !rootRef.value) console.warn(EMPTY_REF);
|
|
59
79
|
rehydrate();
|
|
80
|
+
/* In the callback itself rather than a frame later: the callback is a microtask, so a child's
|
|
81
|
+
widget is enhanced before the browser paints it raw. */
|
|
82
|
+
var target = rootRef && 'value' in rootRef && rootRef.value ? rootRef.value : document.body;
|
|
83
|
+
observer = new MutationObserver(function (records) {
|
|
84
|
+
if (addedElement(records)) rehydrate();
|
|
85
|
+
});
|
|
86
|
+
observer.observe(target, { childList: true, subtree: true });
|
|
60
87
|
});
|
|
61
88
|
onUpdated(function () { nextTick(rehydrate); });
|
|
89
|
+
onBeforeUnmount(function () {
|
|
90
|
+
if (observer) observer.disconnect();
|
|
91
|
+
observer = null;
|
|
92
|
+
});
|
|
62
93
|
return { rehydrate: rehydrate };
|
|
63
94
|
}
|
|
@@ -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
|
-
|
|
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
|
|
package/dist/freeday-form.js
CHANGED
|
@@ -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
|
}
|
package/dist/freeday-stepper.js
CHANGED
|
@@ -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
|
-
|
|
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);
|
package/dist/freeday-table.js
CHANGED
|
@@ -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
|
|
585
|
+
if (e.key !== 'Escape' || !openPopover) return;
|
|
586
|
+
e.preventDefault();
|
|
587
|
+
closePopover(true);
|
|
584
588
|
});
|
|
585
589
|
|
|
586
590
|
buildColumnFilters();
|