@sepale/components 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +65 -3
- package/dist/components/Accordion.svelte +48 -0
- package/dist/components/Accordion.svelte.d.ts +24 -0
- package/dist/components/Alert.svelte +107 -0
- package/dist/components/Alert.svelte.d.ts +40 -0
- package/dist/components/Avatar.svelte +75 -0
- package/dist/components/Avatar.svelte.d.ts +37 -0
- package/dist/components/Badge.svelte +46 -0
- package/dist/components/Badge.svelte.d.ts +22 -0
- package/dist/components/Breadcrumbs.svelte +36 -0
- package/dist/components/Breadcrumbs.svelte.d.ts +18 -0
- package/dist/components/Bubble.svelte +43 -0
- package/dist/components/Bubble.svelte.d.ts +23 -0
- package/dist/components/Button.svelte +132 -0
- package/dist/components/Button.svelte.d.ts +40 -0
- package/dist/components/Calendar.svelte +193 -0
- package/dist/components/Calendar.svelte.d.ts +60 -0
- package/dist/components/Card.svelte +69 -0
- package/dist/components/Card.svelte.d.ts +37 -0
- package/dist/components/Carousel.svelte +550 -0
- package/dist/components/Carousel.svelte.d.ts +124 -0
- package/dist/components/Checkbox.svelte +48 -0
- package/dist/components/Checkbox.svelte.d.ts +26 -0
- package/dist/components/Chip.svelte +60 -0
- package/dist/components/Chip.svelte.d.ts +26 -0
- package/dist/components/ChipsInput.svelte +158 -0
- package/dist/components/ChipsInput.svelte.d.ts +64 -0
- package/dist/components/Collapse.svelte +101 -0
- package/dist/components/Collapse.svelte.d.ts +46 -0
- package/dist/components/ColorPicker.svelte +135 -0
- package/dist/components/ColorPicker.svelte.d.ts +44 -0
- package/dist/components/Combobox.svelte +496 -0
- package/dist/components/Combobox.svelte.d.ts +96 -0
- package/dist/components/DataControl.svelte +754 -0
- package/dist/components/DataControl.svelte.d.ts +143 -0
- package/dist/components/DataHandler.svelte +67 -0
- package/dist/components/DataHandler.svelte.d.ts +44 -0
- package/dist/components/DatePicker.svelte +185 -0
- package/dist/components/DatePicker.svelte.d.ts +56 -0
- package/dist/components/Dialog.svelte +194 -0
- package/dist/components/Dialog.svelte.d.ts +51 -0
- package/dist/components/Divider.svelte +54 -0
- package/dist/components/Divider.svelte.d.ts +27 -0
- package/dist/components/Dock.svelte +34 -0
- package/dist/components/Dock.svelte.d.ts +18 -0
- package/dist/components/Drawer.svelte +174 -0
- package/dist/components/Drawer.svelte.d.ts +51 -0
- package/dist/components/Dropdown.svelte +183 -0
- package/dist/components/Dropdown.svelte.d.ts +52 -0
- package/dist/components/Editable.svelte +292 -0
- package/dist/components/Editable.svelte.d.ts +113 -0
- package/dist/components/EmptyState.svelte +64 -0
- package/dist/components/EmptyState.svelte.d.ts +29 -0
- package/dist/components/Fieldset.svelte +42 -0
- package/dist/components/Fieldset.svelte.d.ts +20 -0
- package/dist/components/FileDropzone.svelte +154 -0
- package/dist/components/FileDropzone.svelte.d.ts +45 -0
- package/dist/components/FileExplorer.svelte +643 -0
- package/dist/components/FileExplorer.svelte.d.ts +114 -0
- package/dist/components/FileInput.svelte +125 -0
- package/dist/components/FileInput.svelte.d.ts +51 -0
- package/dist/components/FloatingLabel.svelte +38 -0
- package/dist/components/FloatingLabel.svelte.d.ts +24 -0
- package/dist/components/Footer.svelte +68 -0
- package/dist/components/Footer.svelte.d.ts +37 -0
- package/dist/components/Grid.svelte +122 -0
- package/dist/components/Grid.svelte.d.ts +72 -0
- package/dist/components/Hero.svelte +62 -0
- package/dist/components/Hero.svelte.d.ts +33 -0
- package/dist/components/Input.svelte +184 -0
- package/dist/components/Input.svelte.d.ts +65 -0
- package/dist/components/Join.svelte +38 -0
- package/dist/components/Join.svelte.d.ts +21 -0
- package/dist/components/Kanban.svelte +284 -0
- package/dist/components/Kanban.svelte.d.ts +93 -0
- package/dist/components/Label.svelte +32 -0
- package/dist/components/Label.svelte.d.ts +21 -0
- package/dist/components/LaptopFrame.svelte +44 -0
- package/dist/components/LaptopFrame.svelte.d.ts +21 -0
- package/dist/components/List.svelte +95 -0
- package/dist/components/List.svelte.d.ts +69 -0
- package/dist/components/Loading.svelte +37 -0
- package/dist/components/Loading.svelte.d.ts +17 -0
- package/dist/components/Menu.svelte +144 -0
- package/dist/components/Menu.svelte.d.ts +53 -0
- package/dist/components/MobileFrame.svelte +41 -0
- package/dist/components/MobileFrame.svelte.d.ts +21 -0
- package/dist/components/Navbar.svelte +49 -0
- package/dist/components/Navbar.svelte.d.ts +25 -0
- package/dist/components/NumberInput.svelte +255 -0
- package/dist/components/NumberInput.svelte.d.ts +68 -0
- package/dist/components/Pagination.svelte +169 -0
- package/dist/components/Pagination.svelte.d.ts +50 -0
- package/dist/components/Progress.svelte +65 -0
- package/dist/components/Progress.svelte.d.ts +28 -0
- package/dist/components/RadialProgress.svelte +48 -0
- package/dist/components/RadialProgress.svelte.d.ts +20 -0
- package/dist/components/Radio.svelte +50 -0
- package/dist/components/Radio.svelte.d.ts +28 -0
- package/dist/components/Range.svelte +53 -0
- package/dist/components/Range.svelte.d.ts +26 -0
- package/dist/components/Rating.svelte +90 -0
- package/dist/components/Rating.svelte.d.ts +41 -0
- package/dist/components/Select.svelte +338 -0
- package/dist/components/Select.svelte.d.ts +74 -0
- package/dist/components/Sidebar.svelte +100 -0
- package/dist/components/Sidebar.svelte.d.ts +54 -0
- package/dist/components/Skeleton.svelte +40 -0
- package/dist/components/Skeleton.svelte.d.ts +18 -0
- package/dist/components/Stat.svelte +71 -0
- package/dist/components/Stat.svelte.d.ts +35 -0
- package/dist/components/Stats.svelte +38 -0
- package/dist/components/Stats.svelte.d.ts +22 -0
- package/dist/components/Steps.svelte +204 -0
- package/dist/components/Steps.svelte.d.ts +66 -0
- package/dist/components/Subtitle.svelte +44 -0
- package/dist/components/Subtitle.svelte.d.ts +26 -0
- package/dist/components/Swatch.svelte +61 -0
- package/dist/components/Swatch.svelte.d.ts +27 -0
- package/dist/components/Switch.svelte +105 -0
- package/dist/components/Switch.svelte.d.ts +44 -0
- package/dist/components/Table.svelte +243 -0
- package/dist/components/Table.svelte.d.ts +121 -0
- package/dist/components/Tabs.svelte +142 -0
- package/dist/components/Tabs.svelte.d.ts +80 -0
- package/dist/components/Text.svelte +43 -0
- package/dist/components/Text.svelte.d.ts +25 -0
- package/dist/components/Textarea.svelte +76 -0
- package/dist/components/Textarea.svelte.d.ts +39 -0
- package/dist/components/Title.svelte +46 -0
- package/dist/components/Title.svelte.d.ts +29 -0
- package/dist/components/Toast.svelte +154 -0
- package/dist/components/Toast.svelte.d.ts +49 -0
- package/dist/components/Toggle.svelte +48 -0
- package/dist/components/Toggle.svelte.d.ts +25 -0
- package/dist/components/Tooltip.svelte +70 -0
- package/dist/components/Tooltip.svelte.d.ts +34 -0
- package/dist/components/WindowFrame.svelte +53 -0
- package/dist/components/WindowFrame.svelte.d.ts +24 -0
- package/dist/components/accordion-context.d.ts +8 -0
- package/dist/components/accordion-context.js +25 -0
- package/dist/components/color.d.ts +39 -0
- package/dist/components/color.js +92 -0
- package/dist/components/data-handler.svelte.d.ts +362 -0
- package/dist/components/data-handler.svelte.js +690 -0
- package/dist/components/file-icons.d.ts +25 -0
- package/dist/components/file-icons.js +46 -0
- package/dist/family-types.d.ts +45 -0
- package/dist/family-types.js +73 -0
- package/dist/generated/classes.d.ts +17 -0
- package/dist/generated/classes.js +2511 -0
- package/dist/generated/components.d.ts +39 -0
- package/dist/generated/components.js +28666 -0
- package/dist/generated/registry.d.ts +35 -0
- package/dist/generated/registry.js +2658 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +99 -0
- package/dist/sepale-types.d.ts +8 -0
- package/dist/sepale-types.js +200 -0
- package/dist/theme.d.ts +123 -0
- package/dist/theme.js +226 -0
- package/dist/variants.d.ts +124 -0
- package/dist/variants.js +70 -0
- package/dist/vendor/air-datepicker/LICENSE.md +21 -0
- package/dist/vendor/air-datepicker/README.md +19 -0
- package/dist/vendor/air-datepicker/buttonPresets.d.ts +13 -0
- package/dist/vendor/air-datepicker/buttonPresets.js +12 -0
- package/dist/vendor/air-datepicker/consts.d.ts +18 -0
- package/dist/vendor/air-datepicker/consts.js +35 -0
- package/dist/vendor/air-datepicker/datepicker.d.ts +289 -0
- package/dist/vendor/air-datepicker/datepicker.js +1435 -0
- package/dist/vendor/air-datepicker/datepickerBody.d.ts +46 -0
- package/dist/vendor/air-datepicker/datepickerBody.js +386 -0
- package/dist/vendor/air-datepicker/datepickerButtons.d.ts +25 -0
- package/dist/vendor/air-datepicker/datepickerButtons.js +85 -0
- package/dist/vendor/air-datepicker/datepickerCell.d.ts +35 -0
- package/dist/vendor/air-datepicker/datepickerCell.js +297 -0
- package/dist/vendor/air-datepicker/datepickerKeyboard.d.ts +26 -0
- package/dist/vendor/air-datepicker/datepickerKeyboard.js +207 -0
- package/dist/vendor/air-datepicker/datepickerNav.d.ts +31 -0
- package/dist/vendor/air-datepicker/datepickerNav.js +200 -0
- package/dist/vendor/air-datepicker/datepickerTime.d.ts +60 -0
- package/dist/vendor/air-datepicker/datepickerTime.js +276 -0
- package/dist/vendor/air-datepicker/defaults.d.ts +65 -0
- package/dist/vendor/air-datepicker/defaults.js +79 -0
- package/dist/vendor/air-datepicker/index.d.ts +168 -0
- package/dist/vendor/air-datepicker/index.js +3 -0
- package/dist/vendor/air-datepicker/locale/ar.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ar.js +14 -0
- package/dist/vendor/air-datepicker/locale/bg.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/bg.js +14 -0
- package/dist/vendor/air-datepicker/locale/ca.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ca.js +14 -0
- package/dist/vendor/air-datepicker/locale/cs.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/cs.js +14 -0
- package/dist/vendor/air-datepicker/locale/da.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/da.js +14 -0
- package/dist/vendor/air-datepicker/locale/de.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/de.js +14 -0
- package/dist/vendor/air-datepicker/locale/el.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/el.js +14 -0
- package/dist/vendor/air-datepicker/locale/en.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/en.js +14 -0
- package/dist/vendor/air-datepicker/locale/es.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/es.js +14 -0
- package/dist/vendor/air-datepicker/locale/eu.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/eu.js +14 -0
- package/dist/vendor/air-datepicker/locale/fi.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/fi.js +14 -0
- package/dist/vendor/air-datepicker/locale/fr.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/fr.js +14 -0
- package/dist/vendor/air-datepicker/locale/hr.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/hr.js +14 -0
- package/dist/vendor/air-datepicker/locale/hu.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/hu.js +14 -0
- package/dist/vendor/air-datepicker/locale/id.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/id.js +14 -0
- package/dist/vendor/air-datepicker/locale/it.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/it.js +14 -0
- package/dist/vendor/air-datepicker/locale/ja.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ja.js +14 -0
- package/dist/vendor/air-datepicker/locale/ko.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ko.js +14 -0
- package/dist/vendor/air-datepicker/locale/nb.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/nb.js +14 -0
- package/dist/vendor/air-datepicker/locale/nl.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/nl.js +14 -0
- package/dist/vendor/air-datepicker/locale/pl.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/pl.js +14 -0
- package/dist/vendor/air-datepicker/locale/pt-BR.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/pt-BR.js +14 -0
- package/dist/vendor/air-datepicker/locale/pt.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/pt.js +14 -0
- package/dist/vendor/air-datepicker/locale/ro.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ro.js +14 -0
- package/dist/vendor/air-datepicker/locale/ru.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/ru.js +14 -0
- package/dist/vendor/air-datepicker/locale/si.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/si.js +14 -0
- package/dist/vendor/air-datepicker/locale/sk.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/sk.js +14 -0
- package/dist/vendor/air-datepicker/locale/sl.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/sl.js +14 -0
- package/dist/vendor/air-datepicker/locale/sv.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/sv.js +14 -0
- package/dist/vendor/air-datepicker/locale/th.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/th.js +14 -0
- package/dist/vendor/air-datepicker/locale/tr.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/tr.js +16 -0
- package/dist/vendor/air-datepicker/locale/uk.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/uk.js +14 -0
- package/dist/vendor/air-datepicker/locale/zh.d.ts +4 -0
- package/dist/vendor/air-datepicker/locale/zh.js +14 -0
- package/dist/vendor/air-datepicker/typedefs.d.ts +3 -0
- package/dist/vendor/air-datepicker/typedefs.js +15 -0
- package/dist/vendor/air-datepicker/utils.d.ts +155 -0
- package/dist/vendor/air-datepicker/utils.js +395 -0
- package/dist/vendor/air-datepicker/withEvents.d.ts +1 -0
- package/dist/vendor/air-datepicker/withEvents.js +39 -0
- package/package.json +44 -3
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The data handler: the live state of one remote resource — the rows of the
|
|
3
|
+
* current page, the total, the search, the sort, the filter values, the
|
|
4
|
+
* selection, the pending edits and their history — and the requests that read
|
|
5
|
+
* and change it.
|
|
6
|
+
*
|
|
7
|
+
* It draws nothing. `DataHandler.svelte` hands an instance to its children;
|
|
8
|
+
* the same class can be used directly, `new DataHandlerState(…)`. Tables,
|
|
9
|
+
* grids and lists know nothing of it: they are given its rows as if they
|
|
10
|
+
* were static.
|
|
11
|
+
*
|
|
12
|
+
* Where the data comes from, in order:
|
|
13
|
+
* 1. the functions passed as `get` / `update` / `delete` — plain async
|
|
14
|
+
* functions, or SvelteKit remote functions, which are callable the same
|
|
15
|
+
* way;
|
|
16
|
+
* 2. otherwise `path`, a REST resource:
|
|
17
|
+
* GET path?filters…&search=&sort=id-asc&page=&limit= → { data, total }
|
|
18
|
+
* PATCH path/:id body: the changed fields
|
|
19
|
+
* DELETE path body: [ids]
|
|
20
|
+
* 3. otherwise the action is not available (`canUpdate`, `canDelete`).
|
|
21
|
+
*/
|
|
22
|
+
export type EntityFilter<ID extends string = string> = {
|
|
23
|
+
id: ID;
|
|
24
|
+
title: string;
|
|
25
|
+
type: 'entity';
|
|
26
|
+
/** The suggestions for what is being typed. */
|
|
27
|
+
items: (query: string) => PromiseLike<EntitySuggestion[]> | EntitySuggestion[];
|
|
28
|
+
/** The text of one suggestion, and of the value. Default: its `name`, else its `id`. */
|
|
29
|
+
show?: (suggestion: EntitySuggestion) => string;
|
|
30
|
+
/** Milliseconds without typing before `items` is asked. */
|
|
31
|
+
wait?: number;
|
|
32
|
+
/** What it picks, for whoever draws the entity (DataControl's `entity`). */
|
|
33
|
+
kind?: string;
|
|
34
|
+
};
|
|
35
|
+
export type NumberFilter<ID extends string = string> = {
|
|
36
|
+
id: ID;
|
|
37
|
+
title: string;
|
|
38
|
+
type: 'number';
|
|
39
|
+
min?: number;
|
|
40
|
+
max?: number;
|
|
41
|
+
step?: number;
|
|
42
|
+
};
|
|
43
|
+
export type DateFilter<ID extends string = string> = {
|
|
44
|
+
id: ID;
|
|
45
|
+
title: string;
|
|
46
|
+
type: 'date';
|
|
47
|
+
};
|
|
48
|
+
export type SelectFilter<ID extends string = string, V extends string = string> = {
|
|
49
|
+
id: ID;
|
|
50
|
+
title: string;
|
|
51
|
+
type: 'select';
|
|
52
|
+
options: {
|
|
53
|
+
name: string;
|
|
54
|
+
value: V;
|
|
55
|
+
}[];
|
|
56
|
+
multiple?: boolean;
|
|
57
|
+
nullable?: boolean;
|
|
58
|
+
/** In a `fields` control, show a choice among few options as a switch rather than a select. */
|
|
59
|
+
switch?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type BooleanFilter<ID extends string = string> = {
|
|
62
|
+
id: ID;
|
|
63
|
+
title: string;
|
|
64
|
+
type: 'boolean';
|
|
65
|
+
};
|
|
66
|
+
export type TextFilter<ID extends string = string> = {
|
|
67
|
+
id: ID;
|
|
68
|
+
title: string;
|
|
69
|
+
type: 'text';
|
|
70
|
+
};
|
|
71
|
+
export type Filter<ID extends string = string> = Readonly<EntityFilter<ID> | NumberFilter<ID> | DateFilter<ID> | SelectFilter<ID, string> | BooleanFilter<ID> | TextFilter<ID>>;
|
|
72
|
+
/** A picked entity: what the filter holds, and what the address bar writes. */
|
|
73
|
+
export type EntityValue = {
|
|
74
|
+
id: string;
|
|
75
|
+
name?: string;
|
|
76
|
+
};
|
|
77
|
+
/** A suggestion for an entity filter. A numeric id is written as text once picked. */
|
|
78
|
+
export type EntitySuggestion = {
|
|
79
|
+
id: string | number;
|
|
80
|
+
name?: string;
|
|
81
|
+
};
|
|
82
|
+
type FilterValueMap<V extends string = string> = {
|
|
83
|
+
text: string;
|
|
84
|
+
entity: EntityValue;
|
|
85
|
+
number: number;
|
|
86
|
+
date: Date;
|
|
87
|
+
select: V[];
|
|
88
|
+
boolean: boolean;
|
|
89
|
+
};
|
|
90
|
+
type ValueOf<F extends Filter> = F extends SelectFilter<string, infer V> ? FilterValueMap<V>[F['type']] : FilterValueMap[F['type']];
|
|
91
|
+
/** The value of every filter, by id. A filter without a value is absent. */
|
|
92
|
+
export type FilterValues<F extends readonly Filter[]> = {
|
|
93
|
+
[K in F[number]['id']]?: ValueOf<Extract<F[number], {
|
|
94
|
+
id: K;
|
|
95
|
+
}>>;
|
|
96
|
+
};
|
|
97
|
+
/** A filter as the handler holds it: shown or not, and maybe immutable. */
|
|
98
|
+
export type HandledFilter<F extends Filter = Filter> = F & {
|
|
99
|
+
/** On the page, with or without a value. */
|
|
100
|
+
shown: boolean;
|
|
101
|
+
/** Set by the page and never offered to the visitor. */
|
|
102
|
+
immutable: boolean;
|
|
103
|
+
};
|
|
104
|
+
/** One way to order the rows. `id` is what the server is sent. */
|
|
105
|
+
export type Sort = {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string;
|
|
108
|
+
value: 'asc' | 'desc';
|
|
109
|
+
};
|
|
110
|
+
export type GetParams<FV> = {
|
|
111
|
+
filters: FV;
|
|
112
|
+
search?: string;
|
|
113
|
+
sort?: {
|
|
114
|
+
id: string;
|
|
115
|
+
value: 'asc' | 'desc';
|
|
116
|
+
};
|
|
117
|
+
/** The handler always sends it; a direct call may leave it out. */
|
|
118
|
+
limit?: number;
|
|
119
|
+
/** From 1. The handler always sends it; a direct call may leave it out. */
|
|
120
|
+
page?: number;
|
|
121
|
+
};
|
|
122
|
+
export type GetResult<Model> = {
|
|
123
|
+
data?: Model[];
|
|
124
|
+
total?: number;
|
|
125
|
+
};
|
|
126
|
+
export type GetQuery<FV, Model> = (params: GetParams<FV>) => PromiseLike<GetResult<Model>>;
|
|
127
|
+
export type UpdateQuery<Model, Id> = (params: {
|
|
128
|
+
id: Id;
|
|
129
|
+
data: Partial<Model>;
|
|
130
|
+
}) => PromiseLike<unknown>;
|
|
131
|
+
export type DeleteQuery<Id> = (ids: Id[]) => PromiseLike<unknown>;
|
|
132
|
+
/** How a row is told apart: one of its keys, or a pair of functions. */
|
|
133
|
+
export type Identifier<Model, Id> = keyof Model | {
|
|
134
|
+
to: (row: Model, index: number) => string;
|
|
135
|
+
from: (id: string) => Id;
|
|
136
|
+
};
|
|
137
|
+
/** How the query is written to the address bar. Default: the History API. */
|
|
138
|
+
export type Navigation = {
|
|
139
|
+
push: (url: string, state: Record<string, unknown>) => void;
|
|
140
|
+
replace: (url: string, state: Record<string, unknown>) => void;
|
|
141
|
+
};
|
|
142
|
+
/** What `confirmDiscard` may answer. */
|
|
143
|
+
export type DiscardChoice = 'save' | 'discard' | 'stay';
|
|
144
|
+
/** Every text the handler writes, for `onlog` and `onerror`. */
|
|
145
|
+
export type DataHandlerMessages = {
|
|
146
|
+
loadFailed: string;
|
|
147
|
+
saveFailed: string;
|
|
148
|
+
deleteFailed: string;
|
|
149
|
+
discarded: (count: number) => string;
|
|
150
|
+
saved: (count: number) => string;
|
|
151
|
+
deleted: (count: number) => string;
|
|
152
|
+
exportEmpty: string;
|
|
153
|
+
};
|
|
154
|
+
export type DataHandlerOptions<F extends readonly Filter[], Model, Id> = {
|
|
155
|
+
/** How a row is told apart. A key of the model, or `{ to, from }`. */
|
|
156
|
+
identifier: Identifier<Model, Id>;
|
|
157
|
+
/** Fetch one page. A plain async function or a SvelteKit remote function. */
|
|
158
|
+
get?: GetQuery<FilterValues<F>, Model>;
|
|
159
|
+
/** Save the changed fields of one row. */
|
|
160
|
+
update?: UpdateQuery<Model, Id>;
|
|
161
|
+
/** Delete rows. */
|
|
162
|
+
delete?: DeleteQuery<Id>;
|
|
163
|
+
/** A REST resource standing in for whichever of the three is missing. */
|
|
164
|
+
path?: string;
|
|
165
|
+
/** The fetch `path` goes through. Default: the global one. */
|
|
166
|
+
fetch?: typeof fetch;
|
|
167
|
+
/** The filters the visitor may use. */
|
|
168
|
+
filters?: F;
|
|
169
|
+
/** The orders the visitor may pick. */
|
|
170
|
+
sorts?: readonly Sort[];
|
|
171
|
+
/** The starting order. Default: the first of `sorts`. */
|
|
172
|
+
sort?: Sort;
|
|
173
|
+
/** Filters set by the page and never shown. */
|
|
174
|
+
immutableFilters?: F[number]['id'][];
|
|
175
|
+
/** The starting search. */
|
|
176
|
+
search?: string;
|
|
177
|
+
/** The starting filter values. */
|
|
178
|
+
filterValues?: FilterValues<F>;
|
|
179
|
+
/** Rows already loaded (by a server load), so the first fetch is skipped. */
|
|
180
|
+
init?: GetResult<Model>;
|
|
181
|
+
/** Rows per page. Default 10. */
|
|
182
|
+
limit?: number;
|
|
183
|
+
/** The starting page, from 1. */
|
|
184
|
+
page?: number;
|
|
185
|
+
/** Write the query to the address bar after every fetch. Default false. */
|
|
186
|
+
history?: boolean;
|
|
187
|
+
/** How to write it. In SvelteKit, pass `{ push: pushState, replace: replaceState }`. */
|
|
188
|
+
navigation?: Navigation;
|
|
189
|
+
/** Asked before deleting. `false` cancels. Without it, the rows go at once. */
|
|
190
|
+
confirmDelete?: (ids: string[]) => Promise<boolean>;
|
|
191
|
+
/** Asked before a fetch would drop unsaved changes. Without it, they are dropped and logged. */
|
|
192
|
+
confirmDiscard?: (count: number) => Promise<DiscardChoice>;
|
|
193
|
+
/** Something happened worth telling the visitor. */
|
|
194
|
+
onlog?: (message: string) => void;
|
|
195
|
+
/** Something failed. Without it, the error goes to the console. */
|
|
196
|
+
onerror?: (message: string, error?: unknown) => void;
|
|
197
|
+
/** The texts written to `onlog` and `onerror`. */
|
|
198
|
+
messages?: Partial<DataHandlerMessages>;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* One row as the handler hands it out: the data, and what can be done to it.
|
|
202
|
+
* `value` is what to draw; `init` is what the server last said; `updated`
|
|
203
|
+
* holds the fields that differ.
|
|
204
|
+
*/
|
|
205
|
+
export type DataRow<Model> = {
|
|
206
|
+
id: string;
|
|
207
|
+
init: Model;
|
|
208
|
+
value: Model;
|
|
209
|
+
updated: Partial<Model>;
|
|
210
|
+
selected: boolean;
|
|
211
|
+
/** Changed and not yet saved. */
|
|
212
|
+
readonly dirty: boolean;
|
|
213
|
+
select: () => void;
|
|
214
|
+
unselect: () => void;
|
|
215
|
+
toggle: () => void;
|
|
216
|
+
/** Change fields: an object of new values, or a function of the current value. */
|
|
217
|
+
update: (patch: Partial<Model> | ((value: Model) => Partial<Model>)) => void;
|
|
218
|
+
/** Take back this row's last change. */
|
|
219
|
+
undo: () => void;
|
|
220
|
+
/** Drop every change to this row. Undoable. */
|
|
221
|
+
reset: () => void;
|
|
222
|
+
save: () => Promise<void>;
|
|
223
|
+
delete: () => Promise<void>;
|
|
224
|
+
};
|
|
225
|
+
/** Filter values out of a query string — to start a handler where the URL left it. */
|
|
226
|
+
export declare function parseFilterValues<const F extends readonly Filter[]>(params: URLSearchParams, filters: F): FilterValues<F>;
|
|
227
|
+
/** Filter values into a query string. */
|
|
228
|
+
export declare function filterValuesToParams<const F extends readonly Filter[]>(values: FilterValues<F>, filters: F): URLSearchParams;
|
|
229
|
+
/** Everything a handler can start from that a URL can carry. */
|
|
230
|
+
export declare function parseQuery<const F extends readonly Filter[]>(params: URLSearchParams, filters: F, sorts?: readonly Sort[]): {
|
|
231
|
+
filterValues: FilterValues<F>;
|
|
232
|
+
search?: string;
|
|
233
|
+
sort?: Sort;
|
|
234
|
+
page?: number;
|
|
235
|
+
limit?: number;
|
|
236
|
+
};
|
|
237
|
+
export declare class DataHandlerState<const F extends readonly Filter[] = Filter[], Model extends Record<string, any> = Record<string, any>, Id = string> {
|
|
238
|
+
#private;
|
|
239
|
+
/** A fetch is running. */
|
|
240
|
+
loading: boolean;
|
|
241
|
+
/** The rows of the current page. */
|
|
242
|
+
rows: DataRow<Model>[];
|
|
243
|
+
/** How many rows match, over every page. `undefined` until known. */
|
|
244
|
+
total: number | undefined;
|
|
245
|
+
/** Every filter the handler knows, shown or not. */
|
|
246
|
+
filters: HandledFilter<F[number]>[];
|
|
247
|
+
/** The value of each filter. */
|
|
248
|
+
filterValues: FilterValues<F>;
|
|
249
|
+
search: string;
|
|
250
|
+
sort: Sort | undefined;
|
|
251
|
+
/** From 1. */
|
|
252
|
+
page: number;
|
|
253
|
+
limit: number;
|
|
254
|
+
readonly sorts: readonly Sort[];
|
|
255
|
+
/** The keys of the selected rows. */
|
|
256
|
+
selection: string[];
|
|
257
|
+
/** The rows changed and not yet saved. */
|
|
258
|
+
changed: string[];
|
|
259
|
+
/** Something is changed and not yet saved. */
|
|
260
|
+
dirty: boolean;
|
|
261
|
+
/** The filters on the page. */
|
|
262
|
+
shownFilters: HandledFilter<F[number]>[];
|
|
263
|
+
/** The filters that could be added to the page. */
|
|
264
|
+
availableFilters: HandledFilter<F[number]>[];
|
|
265
|
+
/** How many pages there are, once the total is known. */
|
|
266
|
+
pages: number | undefined;
|
|
267
|
+
canUndo: boolean;
|
|
268
|
+
canRedo: boolean;
|
|
269
|
+
readonly identifier: {
|
|
270
|
+
to: (row: Model, index: number) => string;
|
|
271
|
+
from: (id: string) => Id;
|
|
272
|
+
};
|
|
273
|
+
readonly options: DataHandlerOptions<F, Model, Id>;
|
|
274
|
+
readonly messages: DataHandlerMessages;
|
|
275
|
+
constructor(options: DataHandlerOptions<F, Model, Id>);
|
|
276
|
+
get canUpdate(): boolean;
|
|
277
|
+
get canDelete(): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Fetch the current page. Unsaved changes are put to `confirmDiscard`
|
|
280
|
+
* first; "stay" puts the query back where the last fetch left it.
|
|
281
|
+
* `delay` debounces (a search being typed); `replace` rewrites the
|
|
282
|
+
* address bar entry instead of adding one; `typing` names the field being
|
|
283
|
+
* typed in, whose changes in a row make a single entry.
|
|
284
|
+
*/
|
|
285
|
+
load(options?: {
|
|
286
|
+
delay?: number;
|
|
287
|
+
replace?: boolean;
|
|
288
|
+
typing?: string;
|
|
289
|
+
}): Promise<void>;
|
|
290
|
+
/** Fetch again, as is: after a change made elsewhere. */
|
|
291
|
+
reload(): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Go back to a query the address bar holds, when the visitor walks the
|
|
294
|
+
* browser history: fetches it without adding an entry. Filters holding a
|
|
295
|
+
* value are shown, the others are not; immutable ones keep their value. On
|
|
296
|
+
* "stay", the address is written back to the rows still on screen.
|
|
297
|
+
*/
|
|
298
|
+
restore(params: URLSearchParams): Promise<void>;
|
|
299
|
+
/** The query, as the address bar and the REST path write it. */
|
|
300
|
+
toSearchParams(): URLSearchParams;
|
|
301
|
+
changePage(page: number): Promise<void>;
|
|
302
|
+
changeLimit(limit: number): Promise<void>;
|
|
303
|
+
changeSort(sort: Sort | undefined): Promise<void>;
|
|
304
|
+
/** A new search, fetched once the typing pauses (`delay`, default 300 ms). */
|
|
305
|
+
changeSearch(search: string, delay?: number): Promise<void>;
|
|
306
|
+
changeFilter<K extends F[number]['id']>(id: K, value: FilterValues<F>[K] | undefined, delay?: number): Promise<void>;
|
|
307
|
+
/** Put a filter on the page, without a value yet. */
|
|
308
|
+
showFilter(id: F[number]['id']): void;
|
|
309
|
+
/** Take a filter off the page, and its value with it. */
|
|
310
|
+
removeFilter(id: F[number]['id']): Promise<void> | undefined;
|
|
311
|
+
/** Select one row, or every row of the page. */
|
|
312
|
+
select(id?: string): void;
|
|
313
|
+
/** Unselect one row, or every row. */
|
|
314
|
+
unselect(id?: string): void;
|
|
315
|
+
/** Every row of the page is selected. */
|
|
316
|
+
get allSelected(): boolean;
|
|
317
|
+
/** Change fields of one row. */
|
|
318
|
+
update(id: string, patch: Partial<Model> | ((value: Model) => Partial<Model>)): void;
|
|
319
|
+
/** Take back the last change, of the whole page or of one row. */
|
|
320
|
+
undo(id?: string): void;
|
|
321
|
+
/** Put back the last change undone. */
|
|
322
|
+
redo(): void;
|
|
323
|
+
/** Drop every unsaved change — of one row, or of the page. One undoable step. */
|
|
324
|
+
reset(id?: string): void;
|
|
325
|
+
/** Send the changes — of one row, or of every changed row. */
|
|
326
|
+
save(id?: string): Promise<void>;
|
|
327
|
+
/** Delete one row, or the selection. Asks `confirmDelete` first. */
|
|
328
|
+
delete(id?: string): Promise<void>;
|
|
329
|
+
/**
|
|
330
|
+
* Every row matching the current query, fetched by batches, as a CSV file
|
|
331
|
+
* the browser downloads. Returns the file's content, or `undefined` when
|
|
332
|
+
* there was nothing to export.
|
|
333
|
+
*
|
|
334
|
+
* The file is written for a spreadsheet: a UTF-8 BOM (without it Excel
|
|
335
|
+
* reads ANSI and mangles accents), CRLF line ends (RFC 4180), and text
|
|
336
|
+
* starting with `= + - @` prefixed with `'`, so that a cell coming from a
|
|
337
|
+
* user is never run as a formula.
|
|
338
|
+
*/
|
|
339
|
+
export(options?: {
|
|
340
|
+
/** The file name. Default `export.csv`. */
|
|
341
|
+
name?: string;
|
|
342
|
+
/** At most this many rows. */
|
|
343
|
+
max?: number;
|
|
344
|
+
/** Rows per request. Default 100. */
|
|
345
|
+
batch?: number;
|
|
346
|
+
/** The columns, in order. Default: every key of the widest row. */
|
|
347
|
+
columns?: {
|
|
348
|
+
key: string;
|
|
349
|
+
label?: string;
|
|
350
|
+
}[];
|
|
351
|
+
/** A row as the CSV writes it. Default: the row itself. */
|
|
352
|
+
format?: (row: Model) => Record<string, unknown>;
|
|
353
|
+
/** The cell separator. Default `;`. */
|
|
354
|
+
separator?: string;
|
|
355
|
+
/** The decimal mark of numbers. Default `,` with a `;` separator (how
|
|
356
|
+
* a spreadsheet in a comma-decimal locale reads it), `.` otherwise. */
|
|
357
|
+
decimal?: string;
|
|
358
|
+
/** Build the CSV without downloading it. */
|
|
359
|
+
download?: boolean;
|
|
360
|
+
}): Promise<string | undefined>;
|
|
361
|
+
}
|
|
362
|
+
export {};
|