asma-ui-core 3.131.1 → 3.133.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/dist/asma-ui-core.css +1 -1
- package/dist/datetime/components/time-picker/StyledTimePicker.js +102 -88
- package/dist/datetime/components/time-picker/StyledTimePicker.module.js +6 -6
- package/dist/datetime/components/time-picker/TimePickerInput.js +44 -44
- package/dist/datetime/components/time-picker/TimePickerPopper.js +22 -20
- package/dist/datetime/components/time-picker/components/TimePickerBody.js +23 -19
- package/dist/datetime/components/time-picker/components/TimePickerColumn.js +25 -18
- package/dist/datetime/components/time-picker/components/TimePickerPanel.js +13 -11
- package/dist/datetime/components/time-picker/helpers/disabledTime.js +13 -0
- package/dist/src/datetime/components/time-picker/TimePickerInput.d.ts +2 -0
- package/dist/src/datetime/components/time-picker/components/TimePickerPanel.d.ts +4 -0
- package/dist/src/datetime/components/time-picker/helpers/disabledTime.d.ts +35 -0
- package/dist/src/datetime/components/time-picker/types.d.ts +20 -0
- package/dist/src/table/custom-features/order-columns/columnLayout.d.ts +37 -4
- package/dist/src/table/custom-features/order-columns/types.d.ts +23 -3
- package/dist/src/table/helpers/columnIds.d.ts +4 -0
- package/dist/src/table/helpers/tableStorage.d.ts +2 -1
- package/dist/src/table/hooks/useColumnLayoutPersistence.d.ts +77 -0
- package/dist/src/table/hooks/useColumnLayoutPersistence.test.d.ts +1 -0
- package/dist/src/table/types.d.ts +30 -0
- package/dist/table/custom-features/order-columns/columnLayout.js +26 -7
- package/dist/table/helpers/columnIds.js +12 -11
- package/dist/table/helpers/tableStorage.js +11 -10
- package/dist/table/hooks/useColumnLayoutPersistence.js +139 -0
- package/dist/table/hooks/useStyledTable.js +132 -95
- package/package.json +1 -1
|
@@ -8,5 +8,7 @@ export declare const TimePickerInput: React.FC<StyledTimePickerProps & {
|
|
|
8
8
|
isValidTime: boolean;
|
|
9
9
|
isValidEndTime: boolean;
|
|
10
10
|
isMissingTime?: boolean;
|
|
11
|
+
/** Set only while the current entry is one `isTimeDisabled` refuses; carries its reason. */
|
|
12
|
+
disabledTimeError?: React.ReactNode;
|
|
11
13
|
localValue: string;
|
|
12
14
|
}>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { TimePredicate } from '../helpers/disabledTime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
1
3
|
export interface TimePickerPanelProps {
|
|
2
4
|
dataTest: string;
|
|
3
5
|
value?: Date;
|
|
4
6
|
minTime?: Date;
|
|
7
|
+
isTimeDisabled?: TimePredicate;
|
|
8
|
+
disabledTimeReason?: ReactNode;
|
|
5
9
|
onSelect: (date: Date | undefined) => void;
|
|
6
10
|
handleClear: () => void;
|
|
7
11
|
onConfirm: () => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marking individual clock times unavailable, from a predicate the consumer owns.
|
|
3
|
+
*
|
|
4
|
+
* ## Why a predicate rather than a second bound
|
|
5
|
+
*
|
|
6
|
+
* `minTime` answers one shape of question — "nothing before this" — with a single `<` on day
|
|
7
|
+
* minutes. The question that needed answering here is a **band**, and the band that motivated it
|
|
8
|
+
* wraps midnight: a customer's quiet hours for patient SMS are typically `22:00–06:00`, where
|
|
9
|
+
* `start < end` is false and no pair of bounds expresses it. Mirroring `minTime` with a `maxTime`
|
|
10
|
+
* would have left the wrap rule implicit (`start > end` secretly meaning "inverted") and still only
|
|
11
|
+
* ever described one contiguous band.
|
|
12
|
+
*
|
|
13
|
+
* A predicate states the rule at the call site, where the domain lives, and this file stays a
|
|
14
|
+
* question of which *cells* that rule rejects.
|
|
15
|
+
*
|
|
16
|
+
* ## Only the clock time counts
|
|
17
|
+
*
|
|
18
|
+
* Same contract as {@link isBeforeMinTime}: the calendar day of the date handed to the predicate is
|
|
19
|
+
* the consumer's concern, never this picker's. Cells are probed on the day of the current value so
|
|
20
|
+
* a predicate that happens to read the date still sees a coherent instant.
|
|
21
|
+
*/
|
|
22
|
+
export type TimePredicate = (time: Date) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* An hour cell is unavailable only when **every** minute cell inside it is.
|
|
25
|
+
*
|
|
26
|
+
* This deliberately mirrors `isHourDisabled`'s rule for `minTime` rather than probing the hour on
|
|
27
|
+
* its own: an hour that is half available is still reachable, and greying it would strand the
|
|
28
|
+
* minutes the consumer does allow. Only the steps the minutes column actually offers are probed —
|
|
29
|
+
* checking all 60 would disable an hour the user can never select into anyway.
|
|
30
|
+
*/
|
|
31
|
+
export declare const isHourRejected: (hour: number, reference: Date, isTimeDisabled?: TimePredicate) => boolean;
|
|
32
|
+
/** A single minute cell, gated by the hour the minutes column is currently showing. */
|
|
33
|
+
export declare const isMinuteRejected: (hour: number, minute: number, reference: Date, isTimeDisabled?: TimePredicate) => boolean;
|
|
34
|
+
/** A complete time — what a typed entry or a stale panel pick has to be checked against. */
|
|
35
|
+
export declare const isTimeRejected: (time: Date | undefined, isTimeDisabled?: TimePredicate) => boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AriaAttributes, ReactNode } from 'react';
|
|
2
2
|
import { FieldWidth } from '../../../components/inputs/field-styles';
|
|
3
|
+
import { TimePredicate } from './helpers/disabledTime';
|
|
3
4
|
/**
|
|
4
5
|
* @param notBeforeTime - Start time of the range. Selected time must be after this value.
|
|
5
6
|
*/
|
|
@@ -31,6 +32,25 @@ export interface StyledTimePickerProps {
|
|
|
31
32
|
* Unlike `notBeforeTime`, it never shows an error.
|
|
32
33
|
*/
|
|
33
34
|
minTime?: Date;
|
|
35
|
+
/**
|
|
36
|
+
* @figmaProp none — behavioral; drives the Time item `State=Disabled` cells (node 15086-19871).
|
|
37
|
+
* Marks arbitrary clock times unavailable, including a band that wraps midnight, which no pair
|
|
38
|
+
* of bounds can express. An hour cell greys only when every minute cell inside it is rejected,
|
|
39
|
+
* matching `minTime`'s rule.
|
|
40
|
+
*
|
|
41
|
+
* Unlike `minTime`, a rejected time typed by hand **raises the error state** rather than
|
|
42
|
+
* silently reverting: the consumer asked for these times to be refused, so swallowing the entry
|
|
43
|
+
* would leave the author believing it was accepted.
|
|
44
|
+
*
|
|
45
|
+
* Pair it with {@link disabledTimeReason}; a disabled cell with no reason is a dead end.
|
|
46
|
+
*/
|
|
47
|
+
isTimeDisabled?: TimePredicate;
|
|
48
|
+
/**
|
|
49
|
+
* Why {@link isTimeDisabled} rejects what it rejects. Serves twice, so one string cannot drift
|
|
50
|
+
* from the other: the tooltip on a rejected cell, and the field error when a rejected time is
|
|
51
|
+
* typed. Copy stays with the consumer — this picker knows nothing about anyone's domain.
|
|
52
|
+
*/
|
|
53
|
+
disabledTimeReason?: ReactNode;
|
|
34
54
|
/**
|
|
35
55
|
* Extra ARIA attributes for the text input (e.g. `aria-label`, `aria-required`) — for a visible
|
|
36
56
|
* label rendered outside the picker. Without them the input is named by `title` or `label`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Table } from '@tanstack/react-table';
|
|
1
|
+
import { ColumnOrderState, Table, VisibilityState } from '@tanstack/react-table';
|
|
2
2
|
/**
|
|
3
3
|
* The leaf column ids of the table's current column definitions, in definition order (group columns
|
|
4
4
|
* flattened). Read live on every call: the column definitions may change while the table stays mounted, so
|
|
@@ -7,15 +7,48 @@ import { Table } from '@tanstack/react-table';
|
|
|
7
7
|
export declare const getDefinitionColumnOrder: <TData>(table: Table<TData>) => string[];
|
|
8
8
|
/** The leaf column ids as the table shows them now, with the saved column order applied. */
|
|
9
9
|
export declare const getEffectiveColumnOrder: <TData>(table: Table<TData>) => string[];
|
|
10
|
+
/**
|
|
11
|
+
* The order the table shows for a `columnOrder` state, the way TanStack applies it: the listed columns that exist, in the
|
|
12
|
+
* listed order, then every other column in definition order. `[]` is the definition order.
|
|
13
|
+
*/
|
|
14
|
+
export declare const effectiveColumnOrder: (order: ColumnOrderState, definitionIds: readonly string[]) => string[];
|
|
15
|
+
/**
|
|
16
|
+
* ASMA-8695, DEC-03: puts every column that a saved order does not list at its definition position, not at the end, which is
|
|
17
|
+
* where TanStack puts it. Each missing column goes right after the closest column before it in the definition that the order
|
|
18
|
+
* lists; with none before it, right before the closest one after it; with none at all, at the end. Ids that no column has are
|
|
19
|
+
* kept, so an order saved for columns that are not there at the moment survives (ASMA-8597, DEC-W).
|
|
20
|
+
*/
|
|
21
|
+
export declare const insertMissingColumns: (order: readonly string[], definitionIds: readonly string[]) => string[];
|
|
22
|
+
/**
|
|
23
|
+
* The order a table with `persistColumnLayout` opens with when the user has saved none: its `initialState.columnOrder`, with
|
|
24
|
+
* the columns that list does not name at their definition position (DEC-03), as in a saved order; `[]` stays `[]`, the
|
|
25
|
+
* definition order. Used for every comparison with "the default" (the dot, the storage rule, Reset), so the same list is the
|
|
26
|
+
* default everywhere (ASMA-8695, audit round 2).
|
|
27
|
+
*/
|
|
28
|
+
export declare const normalizeDefaultColumnOrder: (order: ColumnOrderState, definitionIds: readonly string[]) => string[];
|
|
29
|
+
/**
|
|
30
|
+
* What a `columnVisibility` state changes from the defaults: only the columns whose visibility differs, never an internal
|
|
31
|
+
* column (the select column is hidden unless the app shows it, and is not the user's to change). This is what a table saves
|
|
32
|
+
* (ASMA-8695, DEC-02), and a state with no difference is the default.
|
|
33
|
+
*/
|
|
34
|
+
export declare const diffColumnVisibility: (state: VisibilityState, defaults: VisibilityState) => Record<string, boolean>;
|
|
35
|
+
/** Same differences in any key order count as the same visibility. */
|
|
36
|
+
export declare const columnVisibilitySignature: (state: VisibilityState, defaults: VisibilityState) => string;
|
|
10
37
|
/** `true` when no column has been moved away from its definition position. */
|
|
11
38
|
export declare const isDefaultColumnOrder: <TData>(table: Table<TData>) => boolean;
|
|
12
39
|
/**
|
|
13
40
|
* `true` when the user has moved a column the popover lists. It compares the popover's columns in their
|
|
14
|
-
* effective order with the same columns in
|
|
15
|
-
* definitions shows nothing, and a column that disappeared from `columns` does not count as a move.
|
|
41
|
+
* effective order with the same columns in the default order, so a stored order that matches the current
|
|
42
|
+
* definitions shows nothing, and a column that disappeared from `columns` does not count as a move. The default order is the
|
|
43
|
+
* definition order, or on a table with `persistColumnLayout` the one its `initialState.columnOrder` declares (ASMA-8695).
|
|
16
44
|
*/
|
|
17
45
|
export declare const hasReorderedColumns: <TData>(table: Table<TData>) => boolean;
|
|
18
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* `true` when the user's visibility is not the default. A table with `persistColumnLayout` knows its defaults, so a column
|
|
48
|
+
* hidden by default is no change, while showing it, or hiding a column that is shown by default, is (ASMA-8695, Q10,
|
|
49
|
+
* DEC-05). Any other table has no known defaults, so a hidden column the user may hide is the change, as before. Internal
|
|
50
|
+
* columns and columns fixed visible never count.
|
|
51
|
+
*/
|
|
19
52
|
export declare const hasHiddenColumns: <TData>(table: Table<TData>) => boolean;
|
|
20
53
|
/**
|
|
21
54
|
* Whether the user's column layout differs from the table's defaults: a hidden column or a moved one. This
|
|
@@ -1,16 +1,36 @@
|
|
|
1
|
-
import { ColumnOrderState, OnChangeFn } from '@tanstack/react-table';
|
|
1
|
+
import { ColumnOrderState, OnChangeFn, VisibilityState } from '@tanstack/react-table';
|
|
2
2
|
export interface OrderedColumnsTableState {
|
|
3
3
|
columnOrder: ColumnOrderState;
|
|
4
4
|
}
|
|
5
5
|
export interface OrderedColumnsOptions {
|
|
6
6
|
onColumnOrderChange?: OnChangeFn<ColumnOrderState>;
|
|
7
|
+
/**
|
|
8
|
+
* Saves the column order under this key, unscoped: every user of a browser shares it, so give it only to a table that
|
|
9
|
+
* has no per-user option. A table with `persistColumnLayout` (ASMA-8695) saves the order under its own `uniqueKey`
|
|
10
|
+
* instead, and reads this key once, as the old entry to migrate, and then deletes it.
|
|
11
|
+
*/
|
|
7
12
|
persistColumnOrderKey?: string;
|
|
8
13
|
}
|
|
14
|
+
/** The layout a table opens with when it has no saved one: what the app's `initialState` declares (ASMA-8695). */
|
|
15
|
+
export interface ColumnLayoutDefaults {
|
|
16
|
+
/** `initialState.columnOrder`; `[]` is the definition order. */
|
|
17
|
+
order: ColumnOrderState;
|
|
18
|
+
/** The whole visibility state a table opens with, internal columns included; a column it does not list is visible. */
|
|
19
|
+
visibility: VisibilityState;
|
|
20
|
+
}
|
|
9
21
|
export interface ColumnSettingsInstance {
|
|
10
22
|
/**
|
|
11
23
|
* Reset columns (ASMA-8597): puts the column order and the widths back to the table's defaults, and the
|
|
12
|
-
* sorting too when the table has `persistSorting`. It
|
|
13
|
-
*
|
|
24
|
+
* sorting too when the table has `persistSorting`. It removes the saved entries of what it resets. On a table
|
|
25
|
+
* with `persistColumnLayout` (ASMA-8695, OQ-02) it also puts the visibility back to the default, unhiding what
|
|
26
|
+
* the user hid and hiding what is hidden by default; any other table never touches visibility. Set by
|
|
27
|
+
* `StyledTable`, which knows the defaults.
|
|
14
28
|
*/
|
|
15
29
|
resetColumnSettings: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Set by `StyledTable` on every render for a table with `persistColumnLayout`, and `undefined` for any other table
|
|
32
|
+
* (ASMA-8695, DEC-05): the column settings dot compares the layout with these defaults only where ui-core knows
|
|
33
|
+
* them. Some apps pass the user's current visibility as `initialState`, so elsewhere it cannot.
|
|
34
|
+
*/
|
|
35
|
+
columnLayoutDefaults?: ColumnLayoutDefaults | undefined;
|
|
16
36
|
}
|
|
@@ -7,6 +7,8 @@ export interface LeafColumnInfo {
|
|
|
7
7
|
id: string;
|
|
8
8
|
canSort: boolean;
|
|
9
9
|
canMultiSort: boolean;
|
|
10
|
+
/** Whether the column settings popover may hide it (ASMA-8695: a saved visibility never holds a column that cannot). */
|
|
11
|
+
canHide: boolean;
|
|
10
12
|
}
|
|
11
13
|
/** The parts of a TanStack column definition that decide a column's id and whether it can sort. */
|
|
12
14
|
export interface ColumnDefLike {
|
|
@@ -16,12 +18,14 @@ export interface ColumnDefLike {
|
|
|
16
18
|
header?: unknown;
|
|
17
19
|
enableSorting?: boolean;
|
|
18
20
|
enableMultiSort?: boolean;
|
|
21
|
+
enableHiding?: boolean;
|
|
19
22
|
columns?: readonly ColumnDefLike[];
|
|
20
23
|
}
|
|
21
24
|
export interface ColumnResolutionOptions {
|
|
22
25
|
defaultColumn?: ColumnDefLike;
|
|
23
26
|
enableSorting?: boolean;
|
|
24
27
|
enableMultiSort?: boolean;
|
|
28
|
+
enableHiding?: boolean;
|
|
25
29
|
}
|
|
26
30
|
/** Leaf columns in definition order (group columns flattened), with the ids TanStack gives them. */
|
|
27
31
|
export declare const getLeafColumnInfos: (columns: readonly ColumnDefLike[], options?: ColumnResolutionOptions) => LeafColumnInfo[];
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const tableStorage: {
|
|
7
7
|
get(key: string): string | null;
|
|
8
|
-
|
|
8
|
+
/** `true` when the value was written, `false` when storage refused it (quota, blocked): the setting stays in memory only. */
|
|
9
|
+
set(key: string, value: string): boolean;
|
|
9
10
|
remove(key: string): void;
|
|
10
11
|
};
|
|
11
12
|
/** Parses a saved value; anything that is not valid JSON counts as nothing saved. */
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ColumnOrderState, Table, VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import { LeafColumnInfo } from '../helpers/columnIds';
|
|
3
|
+
export declare const getColumnOrderStorageKey: (uniqueKey?: string) => string | undefined;
|
|
4
|
+
export declare const getColumnVisibilityStorageKey: (uniqueKey?: string) => string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Checks a parsed `:column-order` value. Ids that no column has are kept: an order saved for columns that are not there at
|
|
7
|
+
* the moment survives, and TanStack ignores them (ASMA-8597, DEC-W). `undefined` means nothing usable is saved.
|
|
8
|
+
*/
|
|
9
|
+
export declare const sanitizeColumnOrder: (raw: unknown) => string[] | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Checks a parsed `:column-visibility` value and returns the valid differences, or `undefined` when nothing usable is saved.
|
|
12
|
+
* Values that are not booleans are dropped, and so are the ids of internal columns and of columns that cannot hide; **ids of
|
|
13
|
+
* columns that are not there at the moment are kept** (DEC-W).
|
|
14
|
+
*/
|
|
15
|
+
export declare const sanitizeColumnVisibility: (raw: unknown, columns: readonly LeafColumnInfo[]) => Record<string, boolean> | undefined;
|
|
16
|
+
interface SavedColumnLayoutOptions {
|
|
17
|
+
/** `persistColumnLayout`. */
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
uniqueKey: string | undefined;
|
|
20
|
+
/** `persistColumnOrderKey`: where the order used to be saved, unscoped. */
|
|
21
|
+
legacyOrderKey: string | undefined;
|
|
22
|
+
legacyVisibilityKey: string | undefined;
|
|
23
|
+
/** The leaf columns of this render, in definition order. */
|
|
24
|
+
columns: readonly LeafColumnInfo[];
|
|
25
|
+
/** `initialState.columnOrder`, or `[]`. */
|
|
26
|
+
defaultOrder: ColumnOrderState;
|
|
27
|
+
/** The whole visibility state the table opens with. */
|
|
28
|
+
defaultVisibility: VisibilityState;
|
|
29
|
+
}
|
|
30
|
+
export interface SavedColumnLayout {
|
|
31
|
+
orderKey: string | undefined;
|
|
32
|
+
visibilityKey: string | undefined;
|
|
33
|
+
/** The saved order to open with, missing columns at their definition position (DEC-03), for the columns of this render. */
|
|
34
|
+
order: string[] | undefined;
|
|
35
|
+
/** The whole visibility state to open with: this render's defaults with the saved differences on top. */
|
|
36
|
+
visibility: VisibilityState | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads the saved layout of the table's current key, once per key, and migrates the old unscoped entries once (D-MIGRATE).
|
|
40
|
+
* Reading is pure; the migration's writes and deletes happen in an effect, and are idempotent, so StrictMode's second run
|
|
41
|
+
* changes nothing. **An old entry is deleted only after the entry that replaces it is written**: when storage refuses the
|
|
42
|
+
* write (it is full or blocked) the old layout stays, and the next visit tries again. Needs to run before the table is
|
|
43
|
+
* created, because the saved layout is part of its initial state.
|
|
44
|
+
*/
|
|
45
|
+
export declare const useSavedColumnLayout: (options: SavedColumnLayoutOptions) => SavedColumnLayout;
|
|
46
|
+
/**
|
|
47
|
+
* Keeps the table's state in step with the columns and the defaults of the current render (ASMA-8695, audit): the state was
|
|
48
|
+
* created from what the first render knew, and TanStack never revisits it.
|
|
49
|
+
*
|
|
50
|
+
* - **A new column** goes to its definition position in an order the user changed (DEC-03), as it does when a saved order is
|
|
51
|
+
* read; a user who has not moved anything stays on the definition order.
|
|
52
|
+
* - **A changed default** reaches the user who had not changed that column: the order follows the new `initialState.columnOrder`
|
|
53
|
+
* while the user is on the old default, and each column's visibility follows the new default unless the user changed it.
|
|
54
|
+
* What the user changed stays. Without this the dot would show a difference the user never made.
|
|
55
|
+
*
|
|
56
|
+
* Returns `true` for the render in which the state is not yet in step: the writers wait (nothing is saved for a state that is
|
|
57
|
+
* about to change), so a changed default is never saved as the user's choice.
|
|
58
|
+
*/
|
|
59
|
+
export declare const useColumnLayoutReconcile: <TData>(table: Table<TData>, options: {
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
definitionIds: readonly string[];
|
|
62
|
+
defaultOrder: ColumnOrderState;
|
|
63
|
+
defaultVisibility: VisibilityState;
|
|
64
|
+
controlledVisibility: boolean;
|
|
65
|
+
}) => boolean;
|
|
66
|
+
interface ColumnLayoutWriterOptions {
|
|
67
|
+
saved: SavedColumnLayout;
|
|
68
|
+
/** `true` in the render that finds new columns or defaults, before the state is brought in line: nothing is written yet. */
|
|
69
|
+
reconciling: boolean;
|
|
70
|
+
defaultOrder: ColumnOrderState;
|
|
71
|
+
defaultVisibility: VisibilityState;
|
|
72
|
+
/** The app owns `state.columnVisibility`: a key change blocks writes but does not set the state itself. */
|
|
73
|
+
controlledVisibility: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Saves the table's order and visibility under the keys of `saved`, by the storage rule of `usePersistedStateWriter`. */
|
|
76
|
+
export declare const useColumnLayoutWriter: <TData>(table: Table<TData>, options: ColumnLayoutWriterOptions) => void;
|
|
77
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -151,6 +151,36 @@ export type StyledTableProps<TData, TCustomData> = {
|
|
|
151
151
|
* makes `uniqueKey` alone enough and retires this prop (follow-up ASMA-8698).
|
|
152
152
|
*/
|
|
153
153
|
persistSorting?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Opt-in (ASMA-8695, D-OPTIN): save and restore this table's column order under `${uniqueKey}:column-order` and its
|
|
156
|
+
* column visibility under `${uniqueKey}:column-visibility`. Needs a per-user `uniqueKey` (`getTableSettingsKey` of
|
|
157
|
+
* asma-core-helpers); without one nothing is saved. Off by default: a table that does not set it behaves as before.
|
|
158
|
+
*
|
|
159
|
+
* Declare the layout the table opens with in `initialState.columnOrder` and `initialState.columnVisibility`; they are
|
|
160
|
+
* the defaults, so a column hidden by default is hidden for every user until one shows it. A saved layout beats them
|
|
161
|
+
* (the saved order and visibility, not `initialState`, decide what a user sees), the column settings dot follows the
|
|
162
|
+
* defaults (no dot for a column that is hidden by default), a column missing from a saved order appears at its
|
|
163
|
+
* definition position, and Reset columns also restores the default visibility.
|
|
164
|
+
*
|
|
165
|
+
* The table then owns visibility: do not pass `state.columnVisibility` or `onColumnVisibilityChange` (development builds
|
|
166
|
+
* warn). The old unscoped entries are migrated once, by the first user who opens the table on a browser, and then
|
|
167
|
+
* deleted (only after the user's own entry is written): `persistColumnOrderKey`'s order, and the visibility entry named by
|
|
168
|
+
* `legacyColumnVisibilityKey`. A table with this prop and no `uniqueKey` saves nothing and leaves the old entries alone.
|
|
169
|
+
*
|
|
170
|
+
* The table also keeps its state in step with its props: a column added later takes its definition position in an order
|
|
171
|
+
* the user changed, and a changed `initialState` default reaches the user who had not changed that column. A column that
|
|
172
|
+
* an order does not list, a saved one or `initialState.columnOrder`, appears at its definition position, not at the end
|
|
173
|
+
* (so a partial `initialState.columnOrder` no longer puts the listed columns first on a table that opts in).
|
|
174
|
+
*/
|
|
175
|
+
persistColumnLayout?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* The key an app used to save its column visibility under before it opted in with `persistColumnLayout`: a raw
|
|
178
|
+
* `{ [columnId]: boolean }` map of the whole visibility state. It is read once, to carry the user's layout over into the
|
|
179
|
+
* user's own entry, and deleted once that entry is written (if storage refuses the write the old entry stays, and the
|
|
180
|
+
* next visit tries again). Reset columns deletes it too. Used only by a table with `persistColumnLayout` **and** a
|
|
181
|
+
* `uniqueKey`; without a key the table neither reads nor deletes it (ASMA-8695, D-MIGRATE).
|
|
182
|
+
*/
|
|
183
|
+
legacyColumnVisibilityKey?: string;
|
|
154
184
|
/**
|
|
155
185
|
* Whether the table's columns can be resized with the pointer. **On by default** (ASMA-8597, UX round 4, D15): every data
|
|
156
186
|
* column has a handle, except ui-core's own columns (select, expand, actions, drag handle, show full text), a column that
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import { INTERNAL_COLUMN_IDS as
|
|
2
|
-
var
|
|
3
|
-
const r = new Set(e
|
|
4
|
-
return
|
|
5
|
-
},
|
|
1
|
+
import { INTERNAL_COLUMN_IDS as o } from "../../types.js";
|
|
2
|
+
var u = (e) => e.flatMap((s) => s.columns.length ? u(s.columns) : [s.id]), f = (e) => u(e.getAllColumns()), d = (e) => e.getAllLeafColumns().map((s) => s.id), c = (e, s) => e.length === s.length && e.every((r, t) => r === s[t]), m = (e, s) => {
|
|
3
|
+
const r = new Set(s), t = [...new Set(e)].filter((i) => r.has(i)), n = new Set(t);
|
|
4
|
+
return [...t, ...s.filter((i) => !n.has(i))];
|
|
5
|
+
}, C = (e, s) => {
|
|
6
|
+
const r = [...e];
|
|
7
|
+
return s.forEach((t, n) => {
|
|
8
|
+
if (r.includes(t)) return;
|
|
9
|
+
const i = s.slice(0, n).findLast((l) => r.includes(l)), a = s.slice(n + 1).find((l) => r.includes(l));
|
|
10
|
+
i !== void 0 ? r.splice(r.indexOf(i) + 1, 0, t) : a !== void 0 ? r.splice(r.indexOf(a), 0, t) : r.push(t);
|
|
11
|
+
}), r;
|
|
12
|
+
}, y = (e, s) => e.length > 0 ? C(e, s) : [], v = (e, s) => e[s] ?? !0, g = (e, s) => Object.fromEntries(Object.entries(e).filter(([r, t]) => !o.includes(r) && t !== v(s, r))), D = (e, s) => JSON.stringify(Object.entries(g(e, s)).sort(([r], [t]) => r < t ? -1 : 1)), S = (e) => c(d(e), f(e)), h = (e) => !o.includes(e.id) && !!e.columnDef.header, O = (e) => {
|
|
13
|
+
const s = new Set(e.getAllLeafColumns().filter(h).map((t) => t.id)), r = m(e.columnLayoutDefaults?.order ?? [], f(e));
|
|
14
|
+
return !c(d(e).filter((t) => s.has(t)), r.filter((t) => s.has(t)));
|
|
15
|
+
}, p = (e) => {
|
|
16
|
+
const s = e.columnLayoutDefaults?.visibility;
|
|
17
|
+
return e.getAllLeafColumns().some((r) => r.getCanHide() && !o.includes(r.id) && (s ? r.getIsVisible() !== v(s, r.id) : !r.getIsVisible()));
|
|
18
|
+
}, I = (e) => p(e) || O(e);
|
|
6
19
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
20
|
+
D as columnVisibilitySignature,
|
|
21
|
+
g as diffColumnVisibility,
|
|
22
|
+
m as effectiveColumnOrder,
|
|
23
|
+
f as getDefinitionColumnOrder,
|
|
24
|
+
I as hasChangedColumnLayout,
|
|
25
|
+
C as insertMissingColumns,
|
|
26
|
+
S as isDefaultColumnOrder,
|
|
27
|
+
y as normalizeDefaultColumnOrder
|
|
9
28
|
};
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l = (e) => {
|
|
2
2
|
const o = e.id ?? (typeof e.accessorKey == "string" && e.accessorKey ? e.accessorKey.replaceAll(".", "_") : void 0) ?? (typeof e.header == "string" ? e.header : void 0);
|
|
3
3
|
return o === void 0 || o === "" ? void 0 : o;
|
|
4
4
|
}, u = (e, o = {}) => {
|
|
5
|
-
const t = [],
|
|
6
|
-
for (const r of
|
|
5
|
+
const t = [], c = (i) => {
|
|
6
|
+
for (const r of i) {
|
|
7
7
|
if (r.columns?.length) {
|
|
8
|
-
|
|
8
|
+
c(r.columns);
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
11
|
const n = {
|
|
12
12
|
...o.defaultColumn,
|
|
13
13
|
...r
|
|
14
|
-
},
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
14
|
+
}, a = l(n);
|
|
15
|
+
if (a === void 0) continue;
|
|
16
|
+
const s = !!n.accessorFn || !!n.accessorKey;
|
|
17
17
|
t.push({
|
|
18
|
-
id:
|
|
19
|
-
canSort: (n.enableSorting ?? !0) && (o.enableSorting ?? !0) &&
|
|
20
|
-
canMultiSort: n.enableMultiSort ?? o.enableMultiSort ??
|
|
18
|
+
id: a,
|
|
19
|
+
canSort: (n.enableSorting ?? !0) && (o.enableSorting ?? !0) && s,
|
|
20
|
+
canMultiSort: n.enableMultiSort ?? o.enableMultiSort ?? s,
|
|
21
|
+
canHide: (n.enableHiding ?? !0) && (o.enableHiding ?? !0)
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
|
-
return
|
|
25
|
+
return c(e), t;
|
|
25
26
|
};
|
|
26
27
|
export {
|
|
27
28
|
u as getLeafColumnInfos
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
var e = {
|
|
2
|
-
get(
|
|
2
|
+
get(r) {
|
|
3
3
|
try {
|
|
4
|
-
return localStorage.getItem(
|
|
4
|
+
return localStorage.getItem(r);
|
|
5
5
|
} catch {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
8
|
},
|
|
9
|
-
set(
|
|
9
|
+
set(r, t) {
|
|
10
10
|
try {
|
|
11
|
-
localStorage.setItem(t,
|
|
11
|
+
return localStorage.setItem(r, t), !0;
|
|
12
12
|
} catch {
|
|
13
|
+
return !1;
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
|
-
remove(
|
|
16
|
+
remove(r) {
|
|
16
17
|
try {
|
|
17
|
-
localStorage.removeItem(
|
|
18
|
+
localStorage.removeItem(r);
|
|
18
19
|
} catch {
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
}, a = (
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
22
|
+
}, a = (r) => {
|
|
23
|
+
const t = e.get(r);
|
|
24
|
+
if (t)
|
|
24
25
|
try {
|
|
25
|
-
return JSON.parse(
|
|
26
|
+
return JSON.parse(t);
|
|
26
27
|
} catch {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { INTERNAL_COLUMN_IDS as N } from "../types.js";
|
|
2
|
+
import { readJson as O, tableStorage as v } from "../helpers/tableStorage.js";
|
|
3
|
+
import { columnVisibilitySignature as h, diffColumnVisibility as K, effectiveColumnOrder as m, getDefinitionColumnOrder as A, insertMissingColumns as j } from "../custom-features/order-columns/columnLayout.js";
|
|
4
|
+
import { usePersistedStateWriter as L } from "./usePersistedStateWriter.js";
|
|
5
|
+
import { useEffect as J, useLayoutEffect as R, useMemo as _ } from "react";
|
|
6
|
+
var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${F}` : void 0, E = (e) => e ? `${e}${M}` : void 0, S = (e) => typeof e == "object" && e !== null && !Array.isArray(e), C = (e) => [...new Set(e.filter((i) => typeof i == "string"))], D = (e) => {
|
|
7
|
+
if (!S(e) || e.v !== f || !Array.isArray(e.order)) return;
|
|
8
|
+
const i = C(e.order);
|
|
9
|
+
return i.length > 0 ? i : void 0;
|
|
10
|
+
}, p = (e, i) => !N.includes(e) && i.find((t) => t.id === e)?.canHide !== !1, $ = (e, i) => {
|
|
11
|
+
if (!S(e) || e.v !== f || !S(e.visibility)) return;
|
|
12
|
+
const t = Object.fromEntries(Object.entries(e.visibility).filter((r) => typeof r[1] == "boolean" && p(r[0], i)));
|
|
13
|
+
return Object.keys(t).length > 0 ? t : void 0;
|
|
14
|
+
}, x = (e) => {
|
|
15
|
+
if (!Array.isArray(e)) return;
|
|
16
|
+
const i = C(e);
|
|
17
|
+
return i.length > 0 ? i : void 0;
|
|
18
|
+
}, T = (e, i, t) => {
|
|
19
|
+
if (!S(e) || !Object.values(e).every((o) => typeof o == "boolean")) return;
|
|
20
|
+
const r = K(Object.fromEntries(Object.entries(e).filter(([o]) => p(o, i))), t);
|
|
21
|
+
return Object.keys(r).length > 0 ? r : void 0;
|
|
22
|
+
}, U = (e) => {
|
|
23
|
+
const { enabled: i, uniqueKey: t, legacyOrderKey: r, legacyVisibilityKey: o, columns: s, defaultOrder: g, defaultVisibility: d } = e, n = i ? k(t) : void 0, a = i ? E(t) : void 0, y = s.map((l) => l.id), c = [];
|
|
24
|
+
let b, u;
|
|
25
|
+
if (n) {
|
|
26
|
+
if (v.get(n) !== null) b = D(O(n));
|
|
27
|
+
else if (r && v.get(r) !== null) {
|
|
28
|
+
const l = x(O(r)), I = l === void 0 || m(j(l, y), y).join() === m(g, y).join();
|
|
29
|
+
l && !I && (b = l), c.push({
|
|
30
|
+
legacyKey: r,
|
|
31
|
+
...l && !I && { write: {
|
|
32
|
+
key: n,
|
|
33
|
+
value: JSON.stringify({
|
|
34
|
+
v: f,
|
|
35
|
+
order: l
|
|
36
|
+
})
|
|
37
|
+
} }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return a && (v.get(a) !== null ? u = $(O(a), s) : o && v.get(o) !== null && (u = T(O(o), s, d), c.push({
|
|
42
|
+
legacyKey: o,
|
|
43
|
+
...u && { write: {
|
|
44
|
+
key: a,
|
|
45
|
+
value: JSON.stringify({
|
|
46
|
+
v: f,
|
|
47
|
+
visibility: u
|
|
48
|
+
})
|
|
49
|
+
} }
|
|
50
|
+
}))), {
|
|
51
|
+
orderKey: n,
|
|
52
|
+
visibilityKey: a,
|
|
53
|
+
order: b,
|
|
54
|
+
visibility: u,
|
|
55
|
+
migration: c
|
|
56
|
+
};
|
|
57
|
+
}, W = (e, i, t) => {
|
|
58
|
+
const r = e.visibility && Object.fromEntries(Object.entries(e.visibility).filter(([o]) => p(o, i)));
|
|
59
|
+
return {
|
|
60
|
+
orderKey: e.orderKey,
|
|
61
|
+
visibilityKey: e.visibilityKey,
|
|
62
|
+
order: e.order && j(e.order, i.map((o) => o.id)),
|
|
63
|
+
visibility: r && Object.keys(r).length > 0 ? {
|
|
64
|
+
...t,
|
|
65
|
+
...r
|
|
66
|
+
} : void 0
|
|
67
|
+
};
|
|
68
|
+
}, P = (e) => {
|
|
69
|
+
const i = _(() => U(e), [
|
|
70
|
+
e.enabled ? k(e.uniqueKey) : void 0,
|
|
71
|
+
e.enabled ? E(e.uniqueKey) : void 0,
|
|
72
|
+
e.legacyOrderKey,
|
|
73
|
+
e.legacyVisibilityKey
|
|
74
|
+
]);
|
|
75
|
+
return J(() => {
|
|
76
|
+
for (const { legacyKey: t, write: r } of i.migration)
|
|
77
|
+
r && !v.set(r.key, r.value) || v.remove(t);
|
|
78
|
+
}, [i]), W(i, e.columns, e.defaultVisibility);
|
|
79
|
+
}, V = /* @__PURE__ */ new WeakMap(), Y = (e, i) => [.../* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(i)])].every((t) => (e[t] ?? !0) === (i[t] ?? !0)), G = (e, i) => {
|
|
80
|
+
const { enabled: t, definitionIds: r, defaultOrder: o, defaultVisibility: s, controlledVisibility: g } = i, d = {
|
|
81
|
+
signature: JSON.stringify([
|
|
82
|
+
r,
|
|
83
|
+
o,
|
|
84
|
+
Object.entries(s).sort()
|
|
85
|
+
]),
|
|
86
|
+
definitionIds: r,
|
|
87
|
+
defaultOrder: o,
|
|
88
|
+
defaultVisibility: s
|
|
89
|
+
}, n = V.get(e) ?? d, a = t && n.signature !== d.signature;
|
|
90
|
+
return R(() => {
|
|
91
|
+
const y = V.get(e);
|
|
92
|
+
if (V.set(e, d), !t || !y || y.signature === d.signature) return;
|
|
93
|
+
const c = e.getState().columnOrder, b = m(c, y.definitionIds).join() === m(y.defaultOrder, y.definitionIds).join() ? o : j(c, r);
|
|
94
|
+
if (e.setColumnOrder(b), !g) {
|
|
95
|
+
const u = e.getState().columnVisibility, l = {
|
|
96
|
+
...s,
|
|
97
|
+
...K(u, y.defaultVisibility)
|
|
98
|
+
};
|
|
99
|
+
Y(l, u) || e.setColumnVisibility(l);
|
|
100
|
+
}
|
|
101
|
+
}, [
|
|
102
|
+
e,
|
|
103
|
+
t,
|
|
104
|
+
d.signature
|
|
105
|
+
]), a;
|
|
106
|
+
}, Q = (e, i) => {
|
|
107
|
+
const { saved: t, reconciling: r, defaultOrder: o, defaultVisibility: s, controlledVisibility: g } = i, d = A(e);
|
|
108
|
+
L({
|
|
109
|
+
storageKey: t.orderKey,
|
|
110
|
+
state: e.getState().columnOrder,
|
|
111
|
+
defaultValue: o,
|
|
112
|
+
saved: t.order,
|
|
113
|
+
settled: !r,
|
|
114
|
+
toSignature: (n) => JSON.stringify(m(n, d)),
|
|
115
|
+
toStorage: (n) => JSON.stringify({
|
|
116
|
+
v: f,
|
|
117
|
+
order: C(n)
|
|
118
|
+
}),
|
|
119
|
+
applyState: (n) => e.setColumnOrder(n)
|
|
120
|
+
}), L({
|
|
121
|
+
storageKey: t.visibilityKey,
|
|
122
|
+
state: e.getState().columnVisibility,
|
|
123
|
+
defaultValue: s,
|
|
124
|
+
saved: t.visibility,
|
|
125
|
+
settled: !r,
|
|
126
|
+
controlled: g,
|
|
127
|
+
toSignature: (n) => h(n, s),
|
|
128
|
+
toStorage: (n) => JSON.stringify({
|
|
129
|
+
v: f,
|
|
130
|
+
visibility: K(n, s)
|
|
131
|
+
}),
|
|
132
|
+
applyState: (n) => e.setColumnVisibility(n)
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
export {
|
|
136
|
+
G as useColumnLayoutReconcile,
|
|
137
|
+
Q as useColumnLayoutWriter,
|
|
138
|
+
P as useSavedColumnLayout
|
|
139
|
+
};
|