@gopherium/godmin 0.14.1 → 0.16.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/README.md +9 -4
- package/dist/avatar.d.ts +4 -2
- package/dist/avatar.js +18 -3
- package/dist/base.css +48 -0
- package/dist/bulk.d.ts +45 -0
- package/dist/bulk.js +56 -0
- package/dist/confirm.d.ts +23 -0
- package/dist/confirm.js +12 -0
- package/dist/file-button.d.ts +24 -0
- package/dist/file-button.js +25 -0
- package/dist/frame.d.ts +2 -0
- package/dist/frame.js +9 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +8 -2
- package/dist/list-chrome/es-ES.js +48 -34
- package/dist/list-empty.d.ts +16 -0
- package/dist/list-empty.js +11 -0
- package/dist/list-view.d.ts +114 -0
- package/dist/list-view.js +246 -0
- package/dist/page-tabs.d.ts +1 -1
- package/dist/page-tabs.js +106 -7
- package/dist/rename.d.ts +24 -0
- package/dist/rename.js +20 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/server-page.d.ts +63 -0
- package/dist/server-page.js +58 -0
- package/dist/testing.d.ts +21 -1
- package/dist/testing.js +37 -0
- package/dist/toaster.d.ts +6 -2
- package/dist/toaster.js +26 -3
- package/package.json +14 -13
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
const catalog = {
|
|
4
4
|
'': { lang: 'es-ES', 'plural-forms': 'nplurals=2; plural=(n != 1);' },
|
|
5
5
|
'%1$d of %2$d Item': ['%1$d de %2$d elemento', '%1$d de %2$d elementos'],
|
|
6
|
+
'%1$s, %2$s': ['%1$s, %2$s'],
|
|
6
7
|
'%1$s: %2$s': ['%1$s: %2$s'],
|
|
7
8
|
'%d Item': ['%d elemento', '%d elementos'],
|
|
8
9
|
'%d Item selected': ['%d elemento seleccionado', '%d elementos seleccionados'],
|
|
10
|
+
'%s, selected': ['%s, seleccionado'],
|
|
9
11
|
'%s: <groupName />': ['%s: <groupName />'],
|
|
10
12
|
'(no title)': ['(sin título)'],
|
|
11
13
|
'<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>': [
|
|
@@ -18,46 +20,46 @@ const catalog = {
|
|
|
18
20
|
'<Name>%1$s no contiene: </Name><Value>%2$s</Value>',
|
|
19
21
|
],
|
|
20
22
|
'<Name>%1$s includes all: </Name><Value>%2$s</Value>': [
|
|
21
|
-
'<Name>%1$s incluye
|
|
23
|
+
'<Name>%1$s incluye todo: </Name><Value>%2$s</Value>',
|
|
22
24
|
],
|
|
23
25
|
'<Name>%1$s includes: </Name><Value>%2$s</Value>': [
|
|
24
26
|
'<Name>%1$s incluye: </Name><Value>%2$s</Value>',
|
|
25
27
|
],
|
|
26
28
|
'<Name>%1$s is after: </Name><Value>%2$s</Value>': [
|
|
27
|
-
'<Name>%1$s es
|
|
29
|
+
'<Name>%1$s es después de: </Name><Value>%2$s</Value>',
|
|
28
30
|
],
|
|
29
31
|
'<Name>%1$s is before: </Name><Value>%2$s</Value>': [
|
|
30
|
-
'<Name>%1$s es
|
|
32
|
+
'<Name>%1$s es antes de: </Name><Value>%2$s</Value>',
|
|
31
33
|
],
|
|
32
34
|
'<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>': [
|
|
33
|
-
'<Name>%1$s
|
|
35
|
+
'<Name>%1$s superior o igual a: </Name><Value>%2$s</Value>',
|
|
34
36
|
],
|
|
35
37
|
'<Name>%1$s is greater than: </Name><Value>%2$s</Value>': [
|
|
36
|
-
'<Name>%1$s
|
|
38
|
+
'<Name>%1$s mayor que: </Name><Value>%2$s</Value>',
|
|
37
39
|
],
|
|
38
40
|
'<Name>%1$s is in the past: </Name><Value>%2$s</Value>': [
|
|
39
|
-
'<Name>%1$s en
|
|
41
|
+
'<Name>%1$s está en el pasado: </Name><Value>%2$s</Value>',
|
|
40
42
|
],
|
|
41
43
|
'<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>': [
|
|
42
|
-
'<Name>%1$s
|
|
44
|
+
'<Name>%1$s menor o igual a: </Name><Value>%2$s</Value>',
|
|
43
45
|
],
|
|
44
46
|
'<Name>%1$s is less than: </Name><Value>%2$s</Value>': [
|
|
45
47
|
'<Name>%1$s es menor que: </Name><Value>%2$s</Value>',
|
|
46
48
|
],
|
|
47
49
|
'<Name>%1$s is none of: </Name><Value>%2$s</Value>': [
|
|
48
|
-
'<Name>%1$s no es ninguno de: </Name><Value>%2$s</Value>',
|
|
50
|
+
'<Name>%1$s no es ninguno de los siguientes: </Name><Value>%2$s</Value>',
|
|
49
51
|
],
|
|
50
52
|
'<Name>%1$s is not: </Name><Value>%2$s</Value>': [
|
|
51
53
|
'<Name>%1$s no es: </Name><Value>%2$s</Value>',
|
|
52
54
|
],
|
|
53
55
|
'<Name>%1$s is on or after: </Name><Value>%2$s</Value>': [
|
|
54
|
-
'<Name>%1$s es
|
|
56
|
+
'<Name>%1$s es o es después de: </Name><Value>%2$s</Value>',
|
|
55
57
|
],
|
|
56
58
|
'<Name>%1$s is on or before: </Name><Value>%2$s</Value>': [
|
|
57
|
-
'<Name>%1$s es
|
|
59
|
+
'<Name>%1$s es o es antes de: </Name><Value>%2$s</Value>',
|
|
58
60
|
],
|
|
59
61
|
'<Name>%1$s is over: </Name><Value>%2$s</Value>': [
|
|
60
|
-
'<Name>%1$s
|
|
62
|
+
'<Name>%1$s ha terminado: </Name><Value>%2$s</Value>',
|
|
61
63
|
],
|
|
62
64
|
'<Name>%1$s is: </Name><Value>%2$s</Value>': [
|
|
63
65
|
'<Name>%1$s es: </Name><Value>%2$s</Value>',
|
|
@@ -68,34 +70,38 @@ const catalog = {
|
|
|
68
70
|
Actions: ['Acciones'],
|
|
69
71
|
Activity: ['Actividad'],
|
|
70
72
|
'Add filter': ['Añadir filtro'],
|
|
71
|
-
After: ['Después
|
|
72
|
-
'After (inc)': ['Después
|
|
73
|
+
After: ['Después'],
|
|
74
|
+
'After (inc)': ['Después (incl.)'],
|
|
73
75
|
Appearance: ['Apariencia'],
|
|
74
76
|
'Automatically load more content as you scroll, instead of showing pagination links.': [
|
|
75
|
-
'Carga más contenido
|
|
77
|
+
'Carga automáticamente más contenido a medida que navegas, en lugar de mostrar enlaces de paginación.',
|
|
76
78
|
],
|
|
77
|
-
Before: ['Antes
|
|
78
|
-
'Before (inc)': ['Antes
|
|
79
|
+
Before: ['Antes'],
|
|
80
|
+
'Before (inc)': ['Antes (incl.)'],
|
|
79
81
|
'Between (inc)': ['Entre (incl.)'],
|
|
80
82
|
Cancel: ['Cancelar'],
|
|
81
83
|
Close: ['Cerrar'],
|
|
82
84
|
Conditions: ['Condiciones'],
|
|
83
85
|
Contains: ['Contiene'],
|
|
86
|
+
'Coordinated Universal Time': ['Hora universal coordinada'],
|
|
84
87
|
'Current page': ['Página actual'],
|
|
88
|
+
'Date calendar': ['Calendario de fechas'],
|
|
89
|
+
'Date range calendar': ['Calendario de rango de fechas'],
|
|
90
|
+
'Date time': ['Fecha y hora'],
|
|
85
91
|
Density: ['Densidad'],
|
|
86
|
-
'Density option for DataView layout\u0004Balanced': ['
|
|
87
|
-
'Density option for DataView layout\u0004Comfortable': ['
|
|
88
|
-
'Density option for DataView layout\u0004Compact': ['
|
|
89
|
-
'Deselect all': ['
|
|
92
|
+
'Density option for DataView layout\u0004Balanced': ['Equilibrado'],
|
|
93
|
+
'Density option for DataView layout\u0004Comfortable': ['Cómodo'],
|
|
94
|
+
'Density option for DataView layout\u0004Compact': ['Compacto'],
|
|
95
|
+
'Deselect all': ['Anular selección de todo'],
|
|
90
96
|
"Doesn't contain": ['No contiene'],
|
|
91
97
|
'Enable infinite scroll': ['Activar el desplazamiento infinito'],
|
|
92
98
|
False: ['Falso'],
|
|
93
99
|
'Filter by: %1$s': ['Filtrar por: %1$s'],
|
|
94
100
|
'Greater than': ['Mayor que'],
|
|
95
|
-
'Greater than or equal': ['
|
|
101
|
+
'Greater than or equal': ['Superior a o igual'],
|
|
96
102
|
Grid: ['Cuadrícula'],
|
|
97
103
|
'Hide column': ['Ocultar columna'],
|
|
98
|
-
'In the past': ['En
|
|
104
|
+
'In the past': ['En el pasado'],
|
|
99
105
|
Includes: ['Incluye'],
|
|
100
106
|
'Includes all': ['Incluye todos'],
|
|
101
107
|
'Insert left': ['Insertar a la izquierda'],
|
|
@@ -104,31 +110,36 @@ const catalog = {
|
|
|
104
110
|
'Is none of': ['No es ninguno de'],
|
|
105
111
|
'Is not': ['No es'],
|
|
106
112
|
'Items per page': ['Elementos por página'],
|
|
107
|
-
Layout: ['
|
|
113
|
+
Layout: ['Estructura'],
|
|
108
114
|
'Less than': ['Menor que'],
|
|
109
|
-
'Less than or equal': ['
|
|
115
|
+
'Less than or equal': ['Inferior a o igual'],
|
|
110
116
|
List: ['Lista'],
|
|
111
117
|
'List of: %1$s': ['Lista de: %1$s'],
|
|
112
118
|
'Move left': ['Mover a la izquierda'],
|
|
113
119
|
'Move right': ['Mover a la derecha'],
|
|
114
|
-
'Navigate to item': ['
|
|
120
|
+
'Navigate to item': ['Navegar hasta el elemento'],
|
|
121
|
+
'Navigation bar': ['Barra de navegación'],
|
|
122
|
+
'Next month': ['Mes siguiente'],
|
|
115
123
|
'Next page': ['Página siguiente'],
|
|
116
124
|
'No elements found': ['No se han encontrado elementos'],
|
|
117
|
-
'No results': ['
|
|
118
|
-
'No results found': ['No se
|
|
119
|
-
'Not on': ['No
|
|
120
|
-
On: ['
|
|
125
|
+
'No results': ['No hay resultados'],
|
|
126
|
+
'No results found': ['No se encontraron resultados'],
|
|
127
|
+
'Not on': ['No el'],
|
|
128
|
+
On: ['El'],
|
|
129
|
+
Optional: ['Opcional'],
|
|
121
130
|
Order: ['Orden'],
|
|
122
131
|
'Original aspect ratio': ['Proporción original'],
|
|
123
132
|
Over: ['Hace más de'],
|
|
124
133
|
'Page %1$d of %2$d': ['Página %1$d de %2$d'],
|
|
125
134
|
'Preview size': ['Tamaño de la vista previa'],
|
|
135
|
+
'Previous month': ['Mes anterior'],
|
|
126
136
|
'Previous page': ['Página anterior'],
|
|
127
137
|
Properties: ['Propiedades'],
|
|
128
|
-
Remove: ['
|
|
138
|
+
Remove: ['Eliminar'],
|
|
139
|
+
Required: ['Obligatorio'],
|
|
129
140
|
Reset: ['Restablecer'],
|
|
130
141
|
'Reset search': ['Restablecer la búsqueda'],
|
|
131
|
-
'Reset view': ['Restablecer
|
|
142
|
+
'Reset view': ['Restablecer vista'],
|
|
132
143
|
'Row %d': ['Fila %d'],
|
|
133
144
|
Search: ['Buscar'],
|
|
134
145
|
'Search items': ['Buscar elementos'],
|
|
@@ -136,11 +147,14 @@ const catalog = {
|
|
|
136
147
|
'Sort ascending': ['Orden ascendente'],
|
|
137
148
|
'Sort by': ['Ordenar por'],
|
|
138
149
|
'Sort descending': ['Orden descendente'],
|
|
139
|
-
'Starts with': ['Empieza
|
|
150
|
+
'Starts with': ['Empieza con'],
|
|
140
151
|
Table: ['Tabla'],
|
|
152
|
+
'Timezone: %s': ['Zona horaria: %s'],
|
|
153
|
+
'Today, %s': ['Hoy, %s'],
|
|
154
|
+
'Today, %s, selected': ['Hoy, %s, seleccionado'],
|
|
141
155
|
True: ['Verdadero'],
|
|
142
|
-
'Unknown status for %1$s': ['Estado desconocido
|
|
143
|
-
'View is used as a noun\u0004View options': ['
|
|
156
|
+
'Unknown status for %1$s': ['Estado desconocido para %1$s'],
|
|
157
|
+
'View is used as a noun\u0004View options': ['Ver opciones'],
|
|
144
158
|
'paging\u0004<div>Page</div>%1$s<div>of %2$d</div>': ['<div>Página</div>%1$s<div>de %2$d</div>'],
|
|
145
159
|
'verb\u0004Filter': ['Filtrar'],
|
|
146
160
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EmptyState } from '@wordpress/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
export interface ListEmptyProps {
|
|
4
|
+
/** The icon drawn above the title, from `@wordpress/icons`. */
|
|
5
|
+
icon: ComponentProps<typeof EmptyState.Icon>['icon'];
|
|
6
|
+
/** The sentence saying the list is empty. */
|
|
7
|
+
title: string;
|
|
8
|
+
/** The line under the title, such as what to do to fill the list. */
|
|
9
|
+
hint?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders what a list shows when it has no rows: an icon, a title and an optional hint.
|
|
13
|
+
* @param props - The icon, the title and the hint.
|
|
14
|
+
* @returns The empty state element.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ListEmpty({ icon, title, hint }: ListEmptyProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { EmptyState } from '@wordpress/ui';
|
|
4
|
+
/**
|
|
5
|
+
* Renders what a list shows when it has no rows: an icon, a title and an optional hint.
|
|
6
|
+
* @param props - The icon, the title and the hint.
|
|
7
|
+
* @returns The empty state element.
|
|
8
|
+
*/
|
|
9
|
+
export function ListEmpty({ icon, title, hint }) {
|
|
10
|
+
return (_jsxs(EmptyState.Root, { className: "godmin-empty", children: [_jsx(EmptyState.Icon, { icon: icon }), _jsx(EmptyState.Title, { children: title }), hint === undefined ? null : _jsx(EmptyState.Description, { children: hint })] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** The direction the rows of a list are sorted in. */
|
|
2
|
+
export type ListSortDirection = 'asc' | 'desc';
|
|
3
|
+
/** A filter narrowing the rows of a list, as a DataViews view holds it. */
|
|
4
|
+
export interface ListFilter {
|
|
5
|
+
/** The field the filter reads. */
|
|
6
|
+
field: string;
|
|
7
|
+
/** How the field is compared, such as isAny. */
|
|
8
|
+
operator: string;
|
|
9
|
+
/** The value the field is compared with. */
|
|
10
|
+
value?: unknown;
|
|
11
|
+
}
|
|
12
|
+
/** The parts of a list view the hook reads and writes, as a DataViews view holds them. */
|
|
13
|
+
export interface ListViewShape {
|
|
14
|
+
/** The layout the list is drawn in. */
|
|
15
|
+
type: string;
|
|
16
|
+
/** The words the list is searched for. */
|
|
17
|
+
search?: string;
|
|
18
|
+
/** The filters narrowing the rows. */
|
|
19
|
+
filters?: ListFilter[];
|
|
20
|
+
/** The field and direction the rows are sorted by. */
|
|
21
|
+
sort?: {
|
|
22
|
+
field: string;
|
|
23
|
+
direction: ListSortDirection;
|
|
24
|
+
};
|
|
25
|
+
/** The page shown, counted from one. */
|
|
26
|
+
page?: number;
|
|
27
|
+
/** How many rows a page holds. */
|
|
28
|
+
perPage?: number;
|
|
29
|
+
/** The fields shown beside the title. */
|
|
30
|
+
fields?: string[];
|
|
31
|
+
}
|
|
32
|
+
/** The part of a list view the address carries. */
|
|
33
|
+
export interface ListSearch {
|
|
34
|
+
/** The words the list is searched for. */
|
|
35
|
+
search?: string;
|
|
36
|
+
/** The page shown, counted from one. */
|
|
37
|
+
page?: number;
|
|
38
|
+
/** How many rows a page holds. */
|
|
39
|
+
perPage?: number;
|
|
40
|
+
/** The field the rows are sorted by. */
|
|
41
|
+
sort?: string;
|
|
42
|
+
/** The direction the rows are sorted in. */
|
|
43
|
+
order?: ListSortDirection;
|
|
44
|
+
/** The filters narrowing the rows. */
|
|
45
|
+
filters?: ListFilter[];
|
|
46
|
+
}
|
|
47
|
+
/** What one layout opens on, as DataViews takes it for each of its layouts. */
|
|
48
|
+
export interface LayoutDefaults {
|
|
49
|
+
/** The fields the layout shows, over the list fields. */
|
|
50
|
+
fields?: string[];
|
|
51
|
+
/** The settings of the layout, such as the preview size of a grid. */
|
|
52
|
+
layout?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
/** What a list opens on when the address says nothing. */
|
|
55
|
+
export interface ListDefaults {
|
|
56
|
+
/** The fields shown beside the title. */
|
|
57
|
+
fields: string[];
|
|
58
|
+
/** The fields the phone layout shows beside the title, the list fields when absent. */
|
|
59
|
+
phoneFields?: string[];
|
|
60
|
+
/** The field that links to the record. */
|
|
61
|
+
titleField?: string;
|
|
62
|
+
/** The field shown under the title, none when absent. */
|
|
63
|
+
descriptionField?: string;
|
|
64
|
+
/** The field drawn before the title, such as an avatar, none when absent. */
|
|
65
|
+
mediaField?: string;
|
|
66
|
+
/** The order a list opens in. */
|
|
67
|
+
sort: {
|
|
68
|
+
field: string;
|
|
69
|
+
direction: ListSortDirection;
|
|
70
|
+
};
|
|
71
|
+
/** How many rows a page holds when the address names none, every row while it is unknown. */
|
|
72
|
+
perPage?: number;
|
|
73
|
+
/** The one layout offered from 640px and the one below it, table and list when absent. */
|
|
74
|
+
layouts?: {
|
|
75
|
+
wide: string;
|
|
76
|
+
phone: string;
|
|
77
|
+
};
|
|
78
|
+
/** What each layout opens on, such as the preview size of a grid. */
|
|
79
|
+
layoutSettings?: Record<string, LayoutDefaults>;
|
|
80
|
+
}
|
|
81
|
+
/** The view the address holds beside the controls DataViews takes. */
|
|
82
|
+
export interface ListView<V extends ListViewShape> {
|
|
83
|
+
/** The view the address holds, laid out for the viewport. */
|
|
84
|
+
view: V;
|
|
85
|
+
/** Writes a changed view into the address, holding the parts it leaves out in memory. */
|
|
86
|
+
onChangeView: (view: V) => void;
|
|
87
|
+
/** The one layout the viewport takes, with what it opens on. */
|
|
88
|
+
defaultLayouts: Record<string, LayoutDefaults>;
|
|
89
|
+
/** The rows ticked in the wide layout, always none in the phone layout. */
|
|
90
|
+
selection: string[];
|
|
91
|
+
/** Holds the rows ticked in the wide layout, and drops the tap the phone layout reports. */
|
|
92
|
+
onChangeSelection: (selection: string[]) => void;
|
|
93
|
+
/** Whether the viewport takes the phone layout. */
|
|
94
|
+
phone: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Keeps the parts of a list view an address may carry, dropping anything malformed.
|
|
98
|
+
* @param raw - The search the router parsed from the address.
|
|
99
|
+
* @returns The list search.
|
|
100
|
+
*/
|
|
101
|
+
export declare function listSearch(raw: Record<string, unknown>): ListSearch;
|
|
102
|
+
/**
|
|
103
|
+
* Holds a list view in the address, one layout per side of the phone breakpoint, and its columns in memory.
|
|
104
|
+
* @param defaults - What the list opens on.
|
|
105
|
+
* @returns The view beside the controls DataViews takes.
|
|
106
|
+
*/
|
|
107
|
+
export declare function useListView<V extends ListViewShape>(defaults: ListDefaults): ListView<V>;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the selection handler a list hands DataViews, opening the record a tap lands on in the phone layout.
|
|
110
|
+
* @param list - The list view the screen holds.
|
|
111
|
+
* @param open - Opens the record with the given id.
|
|
112
|
+
* @returns The handler.
|
|
113
|
+
*/
|
|
114
|
+
export declare function openOnTap<V extends ListViewShape>(list: ListView<V>, open: (id: string) => void): (selection: string[]) => void;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { useMatch, useNavigate, useSearch } from '@tanstack/react-router';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { DENSE_BREAKPOINT } from './breakpoints.js';
|
|
5
|
+
import { useMediaQuery } from './use-media-query.js';
|
|
6
|
+
/** The layouts a list takes when it names none. */
|
|
7
|
+
const TABLE_AND_LIST = { wide: 'table', phone: 'list' };
|
|
8
|
+
/** The selection a list opens on and the one a phone layout always holds. */
|
|
9
|
+
const NO_SELECTION = [];
|
|
10
|
+
/** The selection of a phone layout, always none and never changed. */
|
|
11
|
+
const INERT = { selection: NO_SELECTION, onChangeSelection: () => { } };
|
|
12
|
+
/** The viewports that take the phone layout. */
|
|
13
|
+
const PHONE_QUERY = `(max-width: ${DENSE_BREAKPOINT - 1}px)`;
|
|
14
|
+
/** The parts of a view the address or the viewport decides. */
|
|
15
|
+
const ADDRESSED = new Set(['type', 'search', 'filters', 'sort', 'page', 'perPage']);
|
|
16
|
+
/** The address keys a list view owns. */
|
|
17
|
+
const LIST_KEYS = new Set(['search', 'page', 'perPage', 'sort', 'order', 'filters']);
|
|
18
|
+
/** The shape each side holds before a reader changes one. */
|
|
19
|
+
const NO_SHAPES = { wide: {}, phone: {} };
|
|
20
|
+
/**
|
|
21
|
+
* Returns the part of a view the address leaves out.
|
|
22
|
+
* @param view - The view the list shows.
|
|
23
|
+
* @returns The columns, layout settings and every other part the reader changed.
|
|
24
|
+
*/
|
|
25
|
+
function shapeOf(view) {
|
|
26
|
+
return Object.fromEntries(Object.entries(view).filter(([key]) => !ADDRESSED.has(key)));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the value when it is a whole number above zero.
|
|
30
|
+
* @param value - The raw address value.
|
|
31
|
+
* @returns The number, or undefined.
|
|
32
|
+
*/
|
|
33
|
+
function positive(value) {
|
|
34
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the value when it is a string holding something.
|
|
38
|
+
* @param value - The raw address value.
|
|
39
|
+
* @returns The string, or undefined.
|
|
40
|
+
*/
|
|
41
|
+
function filled(value) {
|
|
42
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the value when it names a sort direction.
|
|
46
|
+
* @param value - The raw address value.
|
|
47
|
+
* @returns The direction, or undefined.
|
|
48
|
+
*/
|
|
49
|
+
function direction(value) {
|
|
50
|
+
return value === 'asc' || value === 'desc' ? value : undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reports whether one raw entry is a filter a list can apply.
|
|
54
|
+
* @param entry - One raw entry of the address filters.
|
|
55
|
+
* @returns Whether it names a field and an operator.
|
|
56
|
+
*/
|
|
57
|
+
function isFilter(entry) {
|
|
58
|
+
const held = entry;
|
|
59
|
+
return typeof held?.field === 'string' && typeof held.operator === 'string';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the filters an address value holds, keeping only the ones a list can apply.
|
|
63
|
+
* @param value - The raw address value.
|
|
64
|
+
* @returns The filters, or undefined when none remain.
|
|
65
|
+
*/
|
|
66
|
+
function filtersOf(value) {
|
|
67
|
+
if (!Array.isArray(value)) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const kept = value.filter(isFilter).map(({ field, operator, value: chosen }) => ({ field, operator, value: chosen }));
|
|
71
|
+
return kept.length > 0 ? kept : undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the search without its undefined entries.
|
|
75
|
+
* @param search - The search with possibly undefined entries.
|
|
76
|
+
* @returns The search holding only what was set.
|
|
77
|
+
*/
|
|
78
|
+
function withoutGaps(search) {
|
|
79
|
+
return Object.fromEntries(Object.entries(search).filter(([, value]) => value !== undefined));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Keeps the parts of a list view an address may carry, dropping anything malformed.
|
|
83
|
+
* @param raw - The search the router parsed from the address.
|
|
84
|
+
* @returns The list search.
|
|
85
|
+
*/
|
|
86
|
+
export function listSearch(raw) {
|
|
87
|
+
return withoutGaps({
|
|
88
|
+
search: filled(raw.search),
|
|
89
|
+
page: positive(raw.page),
|
|
90
|
+
perPage: positive(raw.perPage),
|
|
91
|
+
sort: filled(raw.sort),
|
|
92
|
+
order: direction(raw.order),
|
|
93
|
+
filters: filtersOf(raw.filters),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns what a layout opens on.
|
|
98
|
+
* @param defaults - What the list opens on.
|
|
99
|
+
* @param layout - The layout the viewport takes.
|
|
100
|
+
* @returns The fields and settings the list names for the layout, or nothing.
|
|
101
|
+
*/
|
|
102
|
+
function settingsOf(defaults, layout) {
|
|
103
|
+
return defaults.layoutSettings?.[layout] ?? {};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns the fields a list opens on beside the title on one side of the phone breakpoint.
|
|
107
|
+
* @param defaults - What the list opens on.
|
|
108
|
+
* @param side - The side the viewport sits on.
|
|
109
|
+
* @returns The fields shown beside the title.
|
|
110
|
+
*/
|
|
111
|
+
function fieldsFor(defaults, side) {
|
|
112
|
+
return side === 'phone' ? (defaults.phoneFields ?? defaults.fields) : defaults.fields;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds the view a list shows from its address, the reader's other changes and its defaults.
|
|
116
|
+
* @param search - The list search the address carries.
|
|
117
|
+
* @param defaults - What the list opens on.
|
|
118
|
+
* @param shape - The part of the view the reader changed that the address leaves out.
|
|
119
|
+
* @param side - The side of the phone breakpoint the viewport sits on.
|
|
120
|
+
* @param layout - The layout the viewport takes.
|
|
121
|
+
* @returns The view.
|
|
122
|
+
*/
|
|
123
|
+
function viewOf(search, defaults, shape, side, layout) {
|
|
124
|
+
return {
|
|
125
|
+
fields: fieldsFor(defaults, side),
|
|
126
|
+
titleField: defaults.titleField,
|
|
127
|
+
descriptionField: defaults.descriptionField,
|
|
128
|
+
mediaField: defaults.mediaField,
|
|
129
|
+
...settingsOf(defaults, layout),
|
|
130
|
+
...shape,
|
|
131
|
+
type: layout,
|
|
132
|
+
search: search.search ?? '',
|
|
133
|
+
filters: search.filters ?? [],
|
|
134
|
+
sort: { field: search.sort ?? defaults.sort.field, direction: search.order ?? defaults.sort.direction },
|
|
135
|
+
page: search.page ?? 1,
|
|
136
|
+
perPage: search.perPage ?? defaults.perPage,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the value unless it matches what the list opens on.
|
|
141
|
+
* @param value - The value the view holds.
|
|
142
|
+
* @param opening - The value the list opens on.
|
|
143
|
+
* @returns The value, or undefined when it is the opening one.
|
|
144
|
+
*/
|
|
145
|
+
function unlessOpening(value, opening) {
|
|
146
|
+
return value === opening ? undefined : value;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Builds the address search a view is written to, leaving out what matches the defaults.
|
|
150
|
+
* @param view - The view the list shows.
|
|
151
|
+
* @param defaults - What the list opens on.
|
|
152
|
+
* @returns The list search.
|
|
153
|
+
*/
|
|
154
|
+
function searchOf(view, defaults) {
|
|
155
|
+
const sort = view.sort ?? defaults.sort;
|
|
156
|
+
return withoutGaps({
|
|
157
|
+
search: filled(view.search),
|
|
158
|
+
page: unlessOpening(view.page, 1),
|
|
159
|
+
perPage: unlessOpening(view.perPage, defaults.perPage),
|
|
160
|
+
sort: unlessOpening(sort.field, defaults.sort.field),
|
|
161
|
+
order: unlessOpening(sort.direction, defaults.sort.direction),
|
|
162
|
+
filters: filtersOf(view.filters),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the address search without the keys a list view owns.
|
|
167
|
+
* @param held - The search the address holds.
|
|
168
|
+
* @returns The choices of the screen around the list.
|
|
169
|
+
*/
|
|
170
|
+
function besideList(held) {
|
|
171
|
+
return Object.fromEntries(Object.entries(held).filter(([key]) => !LIST_KEYS.has(key)));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Holds the rows ticked in the wide layout, none on a phone, and drops them when the layout or the list changes.
|
|
175
|
+
* @param phone - Whether the viewport takes the phone layout.
|
|
176
|
+
* @param list - The address of the list the screen shows.
|
|
177
|
+
* @returns The selection beside the control that changes it.
|
|
178
|
+
*/
|
|
179
|
+
function useSelection(phone, list) {
|
|
180
|
+
const [ticked, setTicked] = useState(NO_SELECTION);
|
|
181
|
+
const [tickedFor, setTickedFor] = useState({ phone, list });
|
|
182
|
+
if (tickedFor.phone !== phone || tickedFor.list !== list) {
|
|
183
|
+
setTickedFor({ phone, list });
|
|
184
|
+
setTicked(NO_SELECTION);
|
|
185
|
+
}
|
|
186
|
+
return phone ? INERT : { selection: ticked, onChangeSelection: setTicked };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Holds the columns a reader picked on each side of the phone breakpoint, and forgets them when the list changes.
|
|
190
|
+
* @param list - The address of the list the screen shows.
|
|
191
|
+
* @returns The picked columns beside the setter that changes them.
|
|
192
|
+
*/
|
|
193
|
+
function useShapes(list) {
|
|
194
|
+
const [shapes, setShapes] = useState(NO_SHAPES);
|
|
195
|
+
const [shapedFor, setShapedFor] = useState(list);
|
|
196
|
+
if (shapedFor !== list) {
|
|
197
|
+
setShapedFor(list);
|
|
198
|
+
setShapes(NO_SHAPES);
|
|
199
|
+
}
|
|
200
|
+
return [shapes, setShapes];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Holds a list view in the address, one layout per side of the phone breakpoint, and its columns in memory.
|
|
204
|
+
* @param defaults - What the list opens on.
|
|
205
|
+
* @returns The view beside the controls DataViews takes.
|
|
206
|
+
*/
|
|
207
|
+
export function useListView(defaults) {
|
|
208
|
+
const raw = useSearch({ strict: false });
|
|
209
|
+
const navigate = useNavigate();
|
|
210
|
+
const phone = useMediaQuery(PHONE_QUERY);
|
|
211
|
+
const side = phone ? 'phone' : 'wide';
|
|
212
|
+
const layout = (defaults.layouts ?? TABLE_AND_LIST)[side];
|
|
213
|
+
const list = useMatch({ strict: false, select: (match) => match.pathname });
|
|
214
|
+
const [shapes, setShapes] = useShapes(list);
|
|
215
|
+
const selection = useSelection(phone, list);
|
|
216
|
+
return {
|
|
217
|
+
view: viewOf(listSearch(raw), defaults, shapes[side], side, layout),
|
|
218
|
+
onChangeView: (view) => {
|
|
219
|
+
setShapes((held) => ({ ...held, [side]: shapeOf(view) }));
|
|
220
|
+
void navigate({
|
|
221
|
+
to: '.',
|
|
222
|
+
search: (held) => ({ ...besideList(held), ...searchOf(view, defaults) }),
|
|
223
|
+
replace: true,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
defaultLayouts: { [layout]: settingsOf(defaults, layout) },
|
|
227
|
+
phone,
|
|
228
|
+
...selection,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns the selection handler a list hands DataViews, opening the record a tap lands on in the phone layout.
|
|
233
|
+
* @param list - The list view the screen holds.
|
|
234
|
+
* @param open - Opens the record with the given id.
|
|
235
|
+
* @returns The handler.
|
|
236
|
+
*/
|
|
237
|
+
export function openOnTap(list, open) {
|
|
238
|
+
if (!list.phone) {
|
|
239
|
+
return list.onChangeSelection;
|
|
240
|
+
}
|
|
241
|
+
return ([id]) => {
|
|
242
|
+
if (id !== undefined) {
|
|
243
|
+
open(id);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
package/dist/page-tabs.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface PageTabsProps {
|
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Renders the tabs of a page as a navigation region of links.
|
|
9
|
+
* Renders the tabs of a page as a navigation region of links that scrolls to the current tab and fades a cut edge.
|
|
10
10
|
* @param props - The navigation name and the tabs.
|
|
11
11
|
* @returns The tab navigation element.
|
|
12
12
|
*/
|