@krak-stack/registry 0.11.5 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/components/audit-log-table/classes.d.ts +1 -0
- package/dist/components/audit-log-table/html.d.ts +158 -0
- package/dist/components/audit-log-table/html.js +3260 -0
- package/dist/components/audit-log-table/index.d.ts +37 -0
- package/dist/components/audit-log-table/react.d.ts +3 -51
- package/dist/components/audit-log-table/react.js +246 -92
- package/dist/components/audit-log-table/schema.d.ts +122 -0
- package/dist/components/copy-button/html.d.ts +2 -2
- package/dist/components/danger-confirmation/index.d.ts +2 -2
- package/dist/components/data-table/classes.d.ts +10 -3
- package/dist/components/data-table/html.d.ts +93 -21
- package/dist/components/data-table/html.js +122 -32
- package/dist/components/data-table/index.d.ts +97 -9
- package/dist/components/data-table/react.d.ts +14 -3
- package/dist/components/data-table/react.js +162 -19
- package/dist/components/data-table/schema.d.ts +175 -16
- package/dist/components/date-input/html.d.ts +2 -2
- package/dist/components/docs/html.js +1 -1
- package/dist/components/editable-text/html.d.ts +2 -2
- package/dist/components/editable-text/index.d.ts +4 -4
- package/dist/components/editing-locale-switcher/html.d.ts +2 -2
- package/dist/components/email-editor/legacy-editor.html.d.ts +6 -6
- package/dist/components/form/react.d.ts +5 -5
- package/dist/components/locale-switcher/html.d.ts +2 -2
- package/dist/components/map-menu/html.d.ts +4 -4
- package/dist/components/presence-transition/index.d.ts +2 -2
- package/dist/components/select-with-custom-input/html.d.ts +2 -2
- package/dist/components/sidebar-layout/html.js +1 -1
- package/dist/components/switch/react.d.ts +14 -0
- package/dist/components/switch/react.js +55 -0
- package/dist/components/theme-switcher/html.d.ts +2 -2
- package/dist/components/tracking-notice/classes.d.ts +6 -0
- package/dist/components/tracking-notice/html.d.ts +85 -0
- package/dist/components/tracking-notice/html.js +354 -0
- package/dist/components/tracking-notice/index.d.ts +95 -0
- package/dist/components/tracking-notice/react.d.ts +5 -27
- package/dist/components/tracking-notice/react.js +189 -59
- package/dist/components/tracking-notice/schema.d.ts +45 -0
- package/dist/components/upload-attachment/html.d.ts +4 -4
- package/dist/components/virtualized-combobox/html.d.ts +3 -3
- package/dist/components/webhook-delivery-table/html.js +122 -32
- package/dist/components/webhook-delivery-table/react.js +162 -19
- package/dist/services/events/browser.js +39 -26
- package/dist/services/events/index.js +23 -19
- package/dist/services/opentelemetry/web-vitals.js +27 -23
- package/package.json +9 -1
|
@@ -0,0 +1,3260 @@
|
|
|
1
|
+
// ../../src/components/audit-log-table/html.ts
|
|
2
|
+
import { Schema as Schema11 } from "effect";
|
|
3
|
+
import { Component as Component3, UiSchema as UiSchema4 } from "effect/ui";
|
|
4
|
+
import { Html as Html3 } from "effect/ui/html";
|
|
5
|
+
|
|
6
|
+
// ../../src/components/data-table/html.ts
|
|
7
|
+
import { Array as Arr, Schema as Schema6, Stream as Stream2 } from "effect";
|
|
8
|
+
import { Mount, UiSchema as UiSchema3 } from "effect/ui";
|
|
9
|
+
import { Html as Html2 } from "effect/ui/html";
|
|
10
|
+
import { Checkbox, Menu, Menubar, Select as Select2, VirtualList } from "effect/ui/kit";
|
|
11
|
+
import { Button as Button2, buttonVariants } from "@/components/effectcn/button";
|
|
12
|
+
import {
|
|
13
|
+
CheckboxIndicator,
|
|
14
|
+
CheckboxRoot
|
|
15
|
+
} from "@/components/effectcn/checkbox";
|
|
16
|
+
import { Input } from "@/components/effectcn/input";
|
|
17
|
+
import {
|
|
18
|
+
MenuCheckboxItem,
|
|
19
|
+
MenuEmpty,
|
|
20
|
+
MenuInput,
|
|
21
|
+
MenuItem,
|
|
22
|
+
MenuPopup,
|
|
23
|
+
MenuPositioner,
|
|
24
|
+
MenuRadioItem,
|
|
25
|
+
MenuSeparator,
|
|
26
|
+
MenuSubTrigger
|
|
27
|
+
} from "@/components/effectcn/menu";
|
|
28
|
+
import { MenubarRoot, MenubarTrigger } from "@/components/effectcn/menubar";
|
|
29
|
+
import {
|
|
30
|
+
SelectIcon as SelectIcon2,
|
|
31
|
+
SelectItem as SelectItem2,
|
|
32
|
+
SelectItemIndicator as SelectItemIndicator2,
|
|
33
|
+
SelectItemText as SelectItemText2,
|
|
34
|
+
SelectLabel as SelectLabel2,
|
|
35
|
+
SelectList as SelectList2,
|
|
36
|
+
SelectPopup as SelectPopup2,
|
|
37
|
+
SelectPositioner as SelectPositioner2,
|
|
38
|
+
SelectTrigger as SelectTrigger2,
|
|
39
|
+
SelectValue as SelectValue2
|
|
40
|
+
} from "@/components/effectcn/select";
|
|
41
|
+
import { krakstackLocaleRead as krakstackLocaleRead2 } from "@krak-stack/registry/krakstack-provider/html";
|
|
42
|
+
|
|
43
|
+
// ../../src/components/pagination/html.ts
|
|
44
|
+
import { Html } from "effect/ui/html";
|
|
45
|
+
import { Select } from "effect/ui/kit";
|
|
46
|
+
import { Button } from "@/components/effectcn/button";
|
|
47
|
+
import {
|
|
48
|
+
SelectIcon,
|
|
49
|
+
SelectItem,
|
|
50
|
+
SelectItemIndicator,
|
|
51
|
+
SelectItemText,
|
|
52
|
+
SelectLabel,
|
|
53
|
+
SelectList,
|
|
54
|
+
SelectPopup,
|
|
55
|
+
SelectPositioner,
|
|
56
|
+
SelectScrollDownArrow,
|
|
57
|
+
SelectScrollUpArrow,
|
|
58
|
+
SelectTrigger,
|
|
59
|
+
SelectValue
|
|
60
|
+
} from "@/components/effectcn/select";
|
|
61
|
+
import { krakstackLocaleRead } from "@krak-stack/registry/krakstack-provider/html";
|
|
62
|
+
import {
|
|
63
|
+
ChevronLeft,
|
|
64
|
+
ChevronRight,
|
|
65
|
+
ChevronsLeft,
|
|
66
|
+
ChevronsRight
|
|
67
|
+
} from "@krak-stack/registry/lucide-effect";
|
|
68
|
+
|
|
69
|
+
// ../../src/lib/utils.ts
|
|
70
|
+
import { cn } from "cn";
|
|
71
|
+
|
|
72
|
+
// ../../src/components/pagination/classes.ts
|
|
73
|
+
var paginationClasses = {
|
|
74
|
+
root: "flex flex-col gap-3 px-2 sm:flex-row sm:items-center sm:justify-between",
|
|
75
|
+
summary: "text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-sm",
|
|
76
|
+
controls: "flex items-center gap-4 sm:justify-end",
|
|
77
|
+
controlGroup: "flex items-center gap-2",
|
|
78
|
+
navigation: "flex items-center gap-1",
|
|
79
|
+
compactRoot: "gap-2 px-0 sm:flex-col sm:items-stretch",
|
|
80
|
+
compactControls: "flex-wrap justify-between gap-2 sm:justify-between"
|
|
81
|
+
};
|
|
82
|
+
var resolvePaginationClasses = (overrides) => ({
|
|
83
|
+
...paginationClasses,
|
|
84
|
+
...overrides
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ../../src/components/pagination/index.ts
|
|
88
|
+
import { Schema as Schema2 } from "effect";
|
|
89
|
+
import { Component, UiSchema } from "effect/ui";
|
|
90
|
+
|
|
91
|
+
// ../../src/components/pagination/schema.ts
|
|
92
|
+
import { Schema, Struct } from "effect";
|
|
93
|
+
var Labels = Schema.Struct({
|
|
94
|
+
pageSize: Schema.optional(Schema.String),
|
|
95
|
+
goToFirstPage: Schema.optional(Schema.String),
|
|
96
|
+
goToPreviousPage: Schema.optional(Schema.String),
|
|
97
|
+
goToNextPage: Schema.optional(Schema.String),
|
|
98
|
+
goToLastPage: Schema.optional(Schema.String)
|
|
99
|
+
}).annotate({ identifier: "PaginationLabelOverrides" });
|
|
100
|
+
var Translations = Schema.Record(Schema.String, Schema.UndefinedOr(Labels));
|
|
101
|
+
var PaginationClassesOverridesSchema = Schema.Record(Schema.Literals(Struct.keys(paginationClasses)), Schema.optionalKey(Schema.String)).annotate({ identifier: "PaginationClassesOverrides" });
|
|
102
|
+
var PaginationPropsSchema = Schema.Struct({
|
|
103
|
+
classes: Schema.optional(PaginationClassesOverridesSchema),
|
|
104
|
+
className: Schema.optional(Schema.String),
|
|
105
|
+
pageSizeContentClassName: Schema.optional(Schema.String),
|
|
106
|
+
compact: Schema.optional(Schema.Boolean),
|
|
107
|
+
locale: Schema.optional(Schema.String),
|
|
108
|
+
messages: Schema.optional(Translations),
|
|
109
|
+
page: Schema.Int,
|
|
110
|
+
pageCount: Schema.Int,
|
|
111
|
+
pageSize: Schema.Int,
|
|
112
|
+
pageSizes: Schema.optional(Schema.Array(Schema.Int)),
|
|
113
|
+
selectedRows: Schema.optional(Schema.Int),
|
|
114
|
+
showResults: Schema.optional(Schema.Boolean),
|
|
115
|
+
totalRows: Schema.Int
|
|
116
|
+
}).annotate({ identifier: "PaginationProps" });
|
|
117
|
+
|
|
118
|
+
// ../../src/components/pagination/index.ts
|
|
119
|
+
var PaginationMessage = UiSchema.TaggedEnum({
|
|
120
|
+
Opened: {},
|
|
121
|
+
Closed: {},
|
|
122
|
+
PageRequested: { page: Schema2.Int },
|
|
123
|
+
SizeRequested: { pageSize: Schema2.Int }
|
|
124
|
+
}).annotate({ identifier: "PaginationMessage" });
|
|
125
|
+
var PaginationEvents = UiSchema.TaggedEnum({
|
|
126
|
+
PageChanged: { page: Schema2.Int },
|
|
127
|
+
PageSizeChanged: { pageSize: Schema2.Int }
|
|
128
|
+
}).annotate({ identifier: "PaginationEvents" });
|
|
129
|
+
var paginationOptions = {
|
|
130
|
+
name: "Pagination",
|
|
131
|
+
props: PaginationPropsSchema,
|
|
132
|
+
model: Schema2.Boolean,
|
|
133
|
+
message: PaginationMessage,
|
|
134
|
+
events: PaginationEvents,
|
|
135
|
+
restore: false
|
|
136
|
+
};
|
|
137
|
+
var update = Component.define(paginationOptions).update({
|
|
138
|
+
Opened: () => true,
|
|
139
|
+
Closed: () => false,
|
|
140
|
+
PageRequested: ($, { page }) => $.set($.model).emit(PaginationEvents.PageChanged({ page })),
|
|
141
|
+
SizeRequested: ($, { pageSize }) => $.set(false).emit(PaginationEvents.PageSizeChanged({ pageSize }))
|
|
142
|
+
});
|
|
143
|
+
var paginationBehaviours = {
|
|
144
|
+
init: () => false,
|
|
145
|
+
update
|
|
146
|
+
};
|
|
147
|
+
var messages = {
|
|
148
|
+
en: {
|
|
149
|
+
pageSize: "Page size",
|
|
150
|
+
results: (count) => `${count} results`,
|
|
151
|
+
selectedOf: (selected, total) => `${selected} of ${total}`,
|
|
152
|
+
pageOf: (page, total) => `Page ${page} of ${total}`,
|
|
153
|
+
goToFirstPage: "Go to first page",
|
|
154
|
+
goToPreviousPage: "Go to previous page",
|
|
155
|
+
goToNextPage: "Go to next page",
|
|
156
|
+
goToLastPage: "Go to last page"
|
|
157
|
+
},
|
|
158
|
+
fr: {
|
|
159
|
+
pageSize: "Taille de la page",
|
|
160
|
+
results: (count) => `${count} résultats`,
|
|
161
|
+
selectedOf: (selected, total) => `${selected} sur ${total}`,
|
|
162
|
+
pageOf: (page, total) => `Page ${page} sur ${total}`,
|
|
163
|
+
goToFirstPage: "Aller à la première page",
|
|
164
|
+
goToPreviousPage: "Aller à la page précédente",
|
|
165
|
+
goToNextPage: "Aller à la page suivante",
|
|
166
|
+
goToLastPage: "Aller à la dernière page"
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var paginationMessages = (locale = "en", translations) => ({
|
|
170
|
+
...locale.startsWith("fr") ? messages.fr : messages.en,
|
|
171
|
+
...translations?.[locale.split("-")[0] ?? locale],
|
|
172
|
+
...translations?.[locale]
|
|
173
|
+
});
|
|
174
|
+
var defaultPageSizes = [20, 50, 100];
|
|
175
|
+
var paginationPageLabel = (page, pageCount, pageOf) => pageCount > 0 ? pageOf(page + 1, pageCount) : undefined;
|
|
176
|
+
var paginationNavigation = (page, pageCount) => ({
|
|
177
|
+
goToFirstPage: {
|
|
178
|
+
page: 0,
|
|
179
|
+
disabled: pageCount <= 0 || page <= 0,
|
|
180
|
+
edge: true
|
|
181
|
+
},
|
|
182
|
+
goToPreviousPage: {
|
|
183
|
+
page: page - 1,
|
|
184
|
+
disabled: pageCount <= 0 || page <= 0,
|
|
185
|
+
edge: false
|
|
186
|
+
},
|
|
187
|
+
goToNextPage: {
|
|
188
|
+
page: page + 1,
|
|
189
|
+
disabled: pageCount <= 0 || page + 1 >= pageCount,
|
|
190
|
+
edge: false
|
|
191
|
+
},
|
|
192
|
+
goToLastPage: {
|
|
193
|
+
page: pageCount - 1,
|
|
194
|
+
disabled: pageCount <= 0 || page + 1 >= pageCount,
|
|
195
|
+
edge: true
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// ../../src/components/pagination/html.ts
|
|
200
|
+
var icons = {
|
|
201
|
+
goToFirstPage: ChevronsLeft,
|
|
202
|
+
goToPreviousPage: ChevronLeft,
|
|
203
|
+
goToNextPage: ChevronRight,
|
|
204
|
+
goToLastPage: ChevronsRight
|
|
205
|
+
};
|
|
206
|
+
var Pagination = Html.component({
|
|
207
|
+
...paginationOptions,
|
|
208
|
+
reads: { localeConfig: krakstackLocaleRead }
|
|
209
|
+
}).make({
|
|
210
|
+
...paginationBehaviours,
|
|
211
|
+
view: (h, open) => {
|
|
212
|
+
const paginationClasses = resolvePaginationClasses(h.props.classes);
|
|
213
|
+
const {
|
|
214
|
+
compact,
|
|
215
|
+
page,
|
|
216
|
+
pageCount,
|
|
217
|
+
pageSize,
|
|
218
|
+
pageSizes = defaultPageSizes,
|
|
219
|
+
selectedRows = 0,
|
|
220
|
+
showResults = true,
|
|
221
|
+
totalRows
|
|
222
|
+
} = h.props;
|
|
223
|
+
const labels = paginationMessages(h.props.locale ?? h.reads.localeConfig?.locale, h.props.messages);
|
|
224
|
+
const navigation = paginationNavigation(page, pageCount);
|
|
225
|
+
const pageLabel = paginationPageLabel(page, pageCount, labels.pageOf);
|
|
226
|
+
const items = pageSizes.map((size) => ({
|
|
227
|
+
value: String(size),
|
|
228
|
+
label: String(size)
|
|
229
|
+
}));
|
|
230
|
+
return h.div.attr("data-slot", "pagination").class(cn(paginationClasses.root, compact && paginationClasses.compactRoot, h.props.className)).children(showResults && h.div.class(paginationClasses.summary).children(h.span.children(labels.results(totalRows)), selectedRows > 0 && h.span.children(labels.selectedOf(selectedRows, totalRows))), h.div.class(cn(paginationClasses.controls, compact && paginationClasses.compactControls)).children(Select(h, {
|
|
231
|
+
props: {
|
|
232
|
+
open,
|
|
233
|
+
items,
|
|
234
|
+
value: items.some(({ value }) => value === String(pageSize)) ? String(pageSize) : null,
|
|
235
|
+
placeholder: String(pageSize),
|
|
236
|
+
side: "top",
|
|
237
|
+
alignItemWithTrigger: false
|
|
238
|
+
},
|
|
239
|
+
onEmit: {
|
|
240
|
+
RequestedOpen: () => PaginationMessage.Opened(),
|
|
241
|
+
RequestedClose: () => PaginationMessage.Closed(),
|
|
242
|
+
Picked: ({ value }) => {
|
|
243
|
+
const selected = pageSizes.find((size) => String(size) === value);
|
|
244
|
+
return selected === undefined ? undefined : PaginationMessage.SizeRequested({ pageSize: selected });
|
|
245
|
+
},
|
|
246
|
+
Settled: () => {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
view: (select) => h.div.class(paginationClasses.controlGroup).children(SelectLabel(h, select, {
|
|
251
|
+
class: cn("mb-0", !compact && "sr-only sm:not-sr-only")
|
|
252
|
+
}).children(labels.pageSize), SelectTrigger(h, select, {
|
|
253
|
+
size: "sm",
|
|
254
|
+
class: "min-w-0"
|
|
255
|
+
}).children(SelectValue(h, select), SelectIcon(h, select)), SelectPositioner(h, select).children(SelectPopup(h, select, {
|
|
256
|
+
size: "sm",
|
|
257
|
+
class: h.props.pageSizeContentClassName
|
|
258
|
+
}).children(SelectScrollUpArrow(h, select), SelectList(h, select).children(...items.map(({ value, label }) => SelectItem(h, select, { value }).children(SelectItemText(h, select).children(label), SelectItemIndicator(h, select, { value })))), SelectScrollDownArrow(h, select))))
|
|
259
|
+
}), h.div.class(paginationClasses.controlGroup).children(pageLabel !== undefined && h.div.class("text-sm font-medium").children(pageLabel), h.div.class(paginationClasses.navigation).children(...[
|
|
260
|
+
"goToFirstPage",
|
|
261
|
+
"goToPreviousPage",
|
|
262
|
+
"goToNextPage",
|
|
263
|
+
"goToLastPage"
|
|
264
|
+
].map((key) => {
|
|
265
|
+
const Icon = icons[key];
|
|
266
|
+
const control = navigation[key];
|
|
267
|
+
return Button(h, {
|
|
268
|
+
size: "icon-sm",
|
|
269
|
+
class: control.edge ? compact ? "hidden" : "hidden lg:inline-flex" : undefined,
|
|
270
|
+
props: { type: "button", disabled: control.disabled },
|
|
271
|
+
onPress: PaginationMessage.PageRequested({ page: control.page })
|
|
272
|
+
}).key(key).attr("aria-label", labels[key]).children(Icon(h));
|
|
273
|
+
})))));
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ../../src/lib/query.ts
|
|
278
|
+
import {
|
|
279
|
+
DateTime,
|
|
280
|
+
Effect,
|
|
281
|
+
Option,
|
|
282
|
+
Schema as Schema3,
|
|
283
|
+
SchemaGetter,
|
|
284
|
+
SchemaIssue,
|
|
285
|
+
SchemaTransformation
|
|
286
|
+
} from "effect";
|
|
287
|
+
var parseSortParam = (sort) => {
|
|
288
|
+
const id = sort.startsWith("-") ? sort.slice(1) : sort;
|
|
289
|
+
if (!id || id.includes(",") || id.includes(":")) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
|
|
293
|
+
};
|
|
294
|
+
var SortDirection = Schema3.Union([
|
|
295
|
+
Schema3.Literal("asc"),
|
|
296
|
+
Schema3.Literal("desc")
|
|
297
|
+
]).pipe(Schema3.annotate({
|
|
298
|
+
identifier: "SortDirection",
|
|
299
|
+
title: "Sort Direction",
|
|
300
|
+
description: "Sort direction for list query results.",
|
|
301
|
+
examples: ["asc", "desc"]
|
|
302
|
+
}));
|
|
303
|
+
var SortParam = Schema3.Struct({
|
|
304
|
+
id: Schema3.NonEmptyString,
|
|
305
|
+
direction: SortDirection
|
|
306
|
+
}).pipe(Schema3.annotate({
|
|
307
|
+
identifier: "SortParam",
|
|
308
|
+
title: "Sort Parameter",
|
|
309
|
+
description: "Decoded sort parameter with a field id and direction.",
|
|
310
|
+
examples: [{ id: "publicName", direction: "asc" }]
|
|
311
|
+
}));
|
|
312
|
+
var SortParamFromString = Schema3.String.pipe(Schema3.decodeTo(SortParam, SchemaTransformation.transformEffect({
|
|
313
|
+
decode: (sort) => {
|
|
314
|
+
const sortParam = parseSortParam(sort);
|
|
315
|
+
if (!sortParam) {
|
|
316
|
+
return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field" or "-field"' }, sort));
|
|
317
|
+
}
|
|
318
|
+
return Effect.succeed(sortParam);
|
|
319
|
+
},
|
|
320
|
+
encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id)
|
|
321
|
+
})), Schema3.annotate({
|
|
322
|
+
identifier: "SortParamFromString",
|
|
323
|
+
title: "Sort Parameter From String",
|
|
324
|
+
description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
|
|
325
|
+
examples: [{ id: "publicName", direction: "asc" }]
|
|
326
|
+
}));
|
|
327
|
+
var SortParamsFromString = Schema3.String.pipe(Schema3.decodeTo(Schema3.Array(SortParam), SchemaTransformation.transformEffect({
|
|
328
|
+
decode: (sort) => {
|
|
329
|
+
if (sort === "")
|
|
330
|
+
return Effect.succeed([]);
|
|
331
|
+
const parts = sort.split(",");
|
|
332
|
+
const sortParams = [];
|
|
333
|
+
for (const part of parts) {
|
|
334
|
+
const sortParam = parseSortParam(part);
|
|
335
|
+
if (!sortParam) {
|
|
336
|
+
return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field,-otherField"' }, sort));
|
|
337
|
+
}
|
|
338
|
+
sortParams.push(sortParam);
|
|
339
|
+
}
|
|
340
|
+
return Effect.succeed(sortParams);
|
|
341
|
+
},
|
|
342
|
+
encode: (sort) => Effect.succeed(sort.map((part) => Schema3.encodeSync(SortParamFromString)(part)).join(","))
|
|
343
|
+
})), Schema3.annotate({
|
|
344
|
+
identifier: "SortParamsFromString",
|
|
345
|
+
title: "Sort Parameters From String",
|
|
346
|
+
description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
|
|
347
|
+
examples: [
|
|
348
|
+
[
|
|
349
|
+
{ id: "name", direction: "desc" },
|
|
350
|
+
{ id: "age", direction: "asc" }
|
|
351
|
+
]
|
|
352
|
+
]
|
|
353
|
+
}));
|
|
354
|
+
var SortParamsArray = Schema3.Array(SortParam);
|
|
355
|
+
var SortParams = Schema3.declare(Schema3.is(SortParamsArray), {
|
|
356
|
+
identifier: "SortParams",
|
|
357
|
+
toCodec: () => Schema3.link()(SortParamsArray, SchemaTransformation.passthrough()),
|
|
358
|
+
toCodecStringTree: () => Schema3.link()(SortParamsFromString, SchemaTransformation.passthrough())
|
|
359
|
+
});
|
|
360
|
+
var TextFilterOperator = Schema3.Literals([
|
|
361
|
+
"contains",
|
|
362
|
+
"equals",
|
|
363
|
+
"startsWith",
|
|
364
|
+
"endsWith"
|
|
365
|
+
]).annotate({ identifier: "TextFilterOperator" });
|
|
366
|
+
var FilterCalendarDate = Schema3.String.check(Schema3.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema3.makeFilter((value) => Option.exists(DateTime.make(value), (date) => DateTime.formatIsoDateUtc(date) === value))).annotate({ identifier: "FilterCalendarDate" });
|
|
367
|
+
var ColumnFilter = Schema3.Union([
|
|
368
|
+
Schema3.Struct({
|
|
369
|
+
id: Schema3.NonEmptyString,
|
|
370
|
+
kind: Schema3.Literal("text"),
|
|
371
|
+
operator: TextFilterOperator,
|
|
372
|
+
value: Schema3.NonEmptyString
|
|
373
|
+
}),
|
|
374
|
+
Schema3.Struct({
|
|
375
|
+
id: Schema3.NonEmptyString,
|
|
376
|
+
kind: Schema3.Literal("number"),
|
|
377
|
+
min: Schema3.optional(Schema3.Finite),
|
|
378
|
+
max: Schema3.optional(Schema3.Finite)
|
|
379
|
+
}).check(Schema3.makeFilter((range) => (range.min !== undefined || range.max !== undefined) && (range.min === undefined || range.max === undefined || range.min <= range.max))),
|
|
380
|
+
Schema3.Struct({
|
|
381
|
+
id: Schema3.NonEmptyString,
|
|
382
|
+
kind: Schema3.Literal("date"),
|
|
383
|
+
from: Schema3.optional(FilterCalendarDate),
|
|
384
|
+
to: Schema3.optional(FilterCalendarDate)
|
|
385
|
+
}).check(Schema3.makeFilter((range) => (range.from !== undefined || range.to !== undefined) && (range.from === undefined || range.to === undefined || range.from <= range.to))),
|
|
386
|
+
Schema3.Struct({
|
|
387
|
+
id: Schema3.NonEmptyString,
|
|
388
|
+
kind: Schema3.Literal("boolean"),
|
|
389
|
+
value: Schema3.Boolean
|
|
390
|
+
}),
|
|
391
|
+
Schema3.Struct({
|
|
392
|
+
id: Schema3.NonEmptyString,
|
|
393
|
+
kind: Schema3.Literal("values"),
|
|
394
|
+
values: Schema3.NonEmptyArray(Schema3.String)
|
|
395
|
+
})
|
|
396
|
+
]).annotate({ identifier: "ColumnFilter" });
|
|
397
|
+
var ColumnFiltersArray = Schema3.Array(ColumnFilter);
|
|
398
|
+
var ColumnFilters = Schema3.declare(Schema3.is(ColumnFiltersArray), {
|
|
399
|
+
identifier: "ColumnFilters",
|
|
400
|
+
toCodec: () => Schema3.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
|
|
401
|
+
toCodecStringTree: () => Schema3.link()(Schema3.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
|
|
402
|
+
});
|
|
403
|
+
var DEFAULT_PAGE_SIZE = 100;
|
|
404
|
+
var Query = Schema3.Struct({
|
|
405
|
+
page: Schema3.optional(Schema3.Union([Schema3.Finite, Schema3.FiniteFromString]).check(Schema3.isInt(), Schema3.isGreaterThanOrEqualTo(0))).pipe(Schema3.decodeTo(Schema3.Int.check(Schema3.isGreaterThanOrEqualTo(0)), {
|
|
406
|
+
decode: SchemaGetter.withDefault(Effect.succeed(0)),
|
|
407
|
+
encode: SchemaGetter.transformOptional(Option.filter((page) => page !== 0))
|
|
408
|
+
})),
|
|
409
|
+
pageSize: Schema3.optional(Schema3.Union([Schema3.Finite, Schema3.FiniteFromString]).check(Schema3.isInt(), Schema3.isBetween({ minimum: 1, maximum: 100 }))).pipe(Schema3.decodeTo(Schema3.Int.check(Schema3.isBetween({ minimum: 1, maximum: 100 })), {
|
|
410
|
+
decode: SchemaGetter.withDefault(Effect.succeed(DEFAULT_PAGE_SIZE)),
|
|
411
|
+
encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== DEFAULT_PAGE_SIZE))
|
|
412
|
+
})),
|
|
413
|
+
globalFilter: Schema3.optional(Schema3.String),
|
|
414
|
+
sort: Schema3.optional(SortParams),
|
|
415
|
+
filters: Schema3.optional(ColumnFilters)
|
|
416
|
+
}).annotate({
|
|
417
|
+
identifier: "Query",
|
|
418
|
+
title: "Query",
|
|
419
|
+
description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
|
|
420
|
+
examples: [
|
|
421
|
+
{
|
|
422
|
+
page: 0,
|
|
423
|
+
pageSize: DEFAULT_PAGE_SIZE,
|
|
424
|
+
globalFilter: "housing",
|
|
425
|
+
sort: [
|
|
426
|
+
{ id: "publicName", direction: "desc" },
|
|
427
|
+
{ id: "createdAt", direction: "asc" }
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
]
|
|
431
|
+
});
|
|
432
|
+
var QueryStandard = Schema3.toStandardSchemaV1(Query);
|
|
433
|
+
var PaginationMeta = Schema3.Struct({
|
|
434
|
+
page: Schema3.Int,
|
|
435
|
+
pageSize: Schema3.Int,
|
|
436
|
+
total: Schema3.Int,
|
|
437
|
+
pageCount: Schema3.Int
|
|
438
|
+
}).pipe(Schema3.annotate({
|
|
439
|
+
identifier: "PaginationMeta",
|
|
440
|
+
title: "Pagination Metadata",
|
|
441
|
+
description: "Pagination metadata returned with a paginated list response.",
|
|
442
|
+
examples: [{ page: 0, pageSize: 20, total: 125, pageCount: 7 }]
|
|
443
|
+
}));
|
|
444
|
+
|
|
445
|
+
// ../../src/components/data-table/html.ts
|
|
446
|
+
import {
|
|
447
|
+
ArrowDown,
|
|
448
|
+
ArrowUp,
|
|
449
|
+
ChevronDown,
|
|
450
|
+
ChevronRight as ChevronRight2,
|
|
451
|
+
ChevronsUpDown,
|
|
452
|
+
Download,
|
|
453
|
+
Ellipsis,
|
|
454
|
+
EyeOff,
|
|
455
|
+
FileJson,
|
|
456
|
+
FileText,
|
|
457
|
+
GripVertical,
|
|
458
|
+
LayoutGrid,
|
|
459
|
+
ListFilter,
|
|
460
|
+
RefreshCw,
|
|
461
|
+
Rows3,
|
|
462
|
+
Search,
|
|
463
|
+
Settings2,
|
|
464
|
+
X
|
|
465
|
+
} from "@krak-stack/registry/lucide-effect";
|
|
466
|
+
|
|
467
|
+
// ../../src/components/data-table/index.ts
|
|
468
|
+
import { DateTime as DateTime3, Effect as Effect2, Option as Option3, Redacted, Schema as Schema5, Stream } from "effect";
|
|
469
|
+
import { Csv } from "effect/encoding";
|
|
470
|
+
import { Command, Component as Component2, Subscription, UiSchema as UiSchema2 } from "effect/ui";
|
|
471
|
+
|
|
472
|
+
// ../../src/components/data-table/schema.ts
|
|
473
|
+
import { DateTime as DateTime2, Option as Option2, Predicate, Schema as Schema4, Struct as Struct2, Tuple } from "effect";
|
|
474
|
+
|
|
475
|
+
// ../../src/components/data-table/classes.ts
|
|
476
|
+
var booleanCellControl = "flex min-h-16 w-full items-center justify-start px-2 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0 has-[:focus-visible]:outline-2 has-[:focus-visible]:-outline-offset-2 has-[:focus-visible]:outline-ring";
|
|
477
|
+
var cellTriggerFocus = "focus-visible:ring-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring";
|
|
478
|
+
var tableBadgeTones = {
|
|
479
|
+
success: "border-emerald-200 bg-emerald-100 text-emerald-900 dark:border-emerald-900/50 dark:bg-emerald-950/50 dark:text-emerald-200",
|
|
480
|
+
info: "border-blue-200 bg-blue-100 text-blue-900 dark:border-blue-900/50 dark:bg-blue-950/50 dark:text-blue-200",
|
|
481
|
+
muted: "border-muted bg-muted text-muted-foreground dark:bg-muted/50"
|
|
482
|
+
};
|
|
483
|
+
var tableClasses = {
|
|
484
|
+
selectionCell: "w-10 p-0 align-middle",
|
|
485
|
+
selectionCenter: "grid place-items-center",
|
|
486
|
+
count: "inline-flex min-w-5 shrink-0 items-center justify-center rounded-full bg-secondary px-1.5 py-0.5 text-xs font-medium tabular-nums text-secondary-foreground",
|
|
487
|
+
selectedTrigger: "bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground",
|
|
488
|
+
toolbar: "flex min-w-0 shrink-0 flex-wrap items-center gap-2",
|
|
489
|
+
toolbarSearch: "relative min-w-0 flex-[1_1_12rem]",
|
|
490
|
+
toolbarMenus: "w-max min-w-0 max-w-full",
|
|
491
|
+
menubar: "h-auto w-full flex-wrap justify-start border border-input bg-transparent",
|
|
492
|
+
cell: "overflow-hidden",
|
|
493
|
+
cellContent: "min-w-0 wrap-anywhere",
|
|
494
|
+
actionTrigger: `size-8 ${cellTriggerFocus}`,
|
|
495
|
+
actionsCell: "sticky right-0 z-20 w-10 min-w-10 cursor-default bg-background p-0 transition-colors group-hover/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))]",
|
|
496
|
+
actionsAlign: "flex min-h-12 items-center justify-end pe-1",
|
|
497
|
+
header: "relative h-12 p-0",
|
|
498
|
+
stickyHeader: "sticky top-0 z-30 bg-background",
|
|
499
|
+
stickyHeaderRule: "after:border-border after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:border-b",
|
|
500
|
+
headerTrigger: `absolute inset-0 h-full w-full min-w-0 justify-start rounded-none px-2 pe-4 ${cellTriggerFocus}`,
|
|
501
|
+
resizeHandle: "absolute inset-y-0 right-0 z-10 w-2 cursor-col-resize touch-none outline-none after:absolute after:inset-y-3 after:right-0 after:w-px after:bg-border hover:after:w-0.5 hover:after:bg-primary/60 focus-visible:after:w-0.5 focus-visible:after:bg-ring",
|
|
502
|
+
relationshipCell: "grid min-h-16 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0",
|
|
503
|
+
relationshipTrigger: `h-full w-full min-w-0 justify-between rounded-none px-2 text-start ${cellTriggerFocus}`,
|
|
504
|
+
reference: "flex min-w-0 items-center gap-2",
|
|
505
|
+
referenceAvatar: "relative grid size-8 shrink-0 place-items-center overflow-hidden bg-muted text-xs font-medium",
|
|
506
|
+
referenceText: "flex min-w-0 flex-col leading-tight",
|
|
507
|
+
group: "bg-muted/40 hover:bg-accent!",
|
|
508
|
+
groupContent: "flex min-w-0 items-center gap-2 py-2 pe-1 ps-2",
|
|
509
|
+
groupSticky: "sticky start-0 w-[100cqw] max-w-full",
|
|
510
|
+
groupTrigger: "flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-start font-medium",
|
|
511
|
+
referenceName: "truncate font-medium",
|
|
512
|
+
referenceDescription: "text-muted-foreground truncate text-xs"
|
|
513
|
+
};
|
|
514
|
+
var tableResultsFooterClass = "bg-background text-muted-foreground sticky bottom-0 z-30 shrink-0 border-t px-2 py-2 text-sm";
|
|
515
|
+
var resolveTableClasses = (overrides) => ({
|
|
516
|
+
...tableClasses,
|
|
517
|
+
...overrides
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
// ../../src/components/data-table/schema.ts
|
|
521
|
+
var TableClassesOverridesSchema = Schema4.Record(Schema4.Literals(Struct2.keys(tableClasses)), Schema4.optionalKey(Schema4.String)).annotate({ identifier: "TableClassesOverrides" });
|
|
522
|
+
var DataTableCommonPropsSchema = Schema4.Struct({
|
|
523
|
+
classes: Schema4.optional(TableClassesOverridesSchema),
|
|
524
|
+
className: Schema4.optionalKey(Schema4.String),
|
|
525
|
+
locale: Schema4.optionalKey(Schema4.String)
|
|
526
|
+
}).annotate({ identifier: "DataTableCommonProps" });
|
|
527
|
+
var DataTableSortSchema = Schema4.Struct({
|
|
528
|
+
id: Schema4.NonEmptyString,
|
|
529
|
+
direction: Schema4.Literals(["asc", "desc"])
|
|
530
|
+
}).annotate({ identifier: "DataTableSort" });
|
|
531
|
+
var queryFields = {
|
|
532
|
+
page: Schema4.Int.check(Schema4.isGreaterThanOrEqualTo(0)),
|
|
533
|
+
pageSize: Schema4.Int.check(Schema4.isBetween({ minimum: 1, maximum: 100 })),
|
|
534
|
+
globalFilter: Schema4.optional(Schema4.String),
|
|
535
|
+
sort: Schema4.optional(Schema4.Array(DataTableSortSchema)),
|
|
536
|
+
filters: Schema4.optional(Schema4.Array(ColumnFilter))
|
|
537
|
+
};
|
|
538
|
+
var DataTableQuerySchema = Schema4.Struct(queryFields).annotate({
|
|
539
|
+
identifier: "DataTableQuery"
|
|
540
|
+
});
|
|
541
|
+
var PageSizes = Schema4.NonEmptyArray(Schema4.Int.check(Schema4.isBetween({ minimum: 1, maximum: 100 })));
|
|
542
|
+
var DataTableCommonFeaturesSchema = Schema4.Struct({
|
|
543
|
+
search: Schema4.optionalKey(Schema4.Boolean),
|
|
544
|
+
filtering: Schema4.optionalKey(Schema4.Boolean),
|
|
545
|
+
sorting: Schema4.optionalKey(Schema4.Boolean),
|
|
546
|
+
columnVisibility: Schema4.optionalKey(Schema4.Boolean)
|
|
547
|
+
});
|
|
548
|
+
var PaginationSchema = Schema4.Union([
|
|
549
|
+
Schema4.Struct({
|
|
550
|
+
mode: Schema4.optionalKey(Schema4.Literal("client")),
|
|
551
|
+
pageSizes: Schema4.optionalKey(PageSizes)
|
|
552
|
+
}).annotate({ identifier: "DataTableClientPagination" }),
|
|
553
|
+
Schema4.Struct({
|
|
554
|
+
mode: Schema4.Literal("server"),
|
|
555
|
+
rowCount: Schema4.Int.check(Schema4.isGreaterThanOrEqualTo(0)),
|
|
556
|
+
pageSizes: Schema4.optionalKey(PageSizes)
|
|
557
|
+
}).annotate({ identifier: "DataTableServerPagination" })
|
|
558
|
+
]);
|
|
559
|
+
var DataTableItemSchema = Schema4.Struct({
|
|
560
|
+
value: Schema4.NonEmptyString,
|
|
561
|
+
label: Schema4.String
|
|
562
|
+
}).annotate({ identifier: "DataTableItem" });
|
|
563
|
+
var DataTableReferenceSchema = Schema4.Struct({
|
|
564
|
+
label: Schema4.String,
|
|
565
|
+
description: Schema4.optionalKey(Schema4.String),
|
|
566
|
+
imageSrc: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
|
|
567
|
+
}).annotate({ identifier: "DataTableReference" });
|
|
568
|
+
var CalendarDate = Schema4.String.check(Schema4.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema4.makeFilter((value) => Option2.exists(DateTime2.make(value), (date) => DateTime2.formatIsoDateUtc(date) === value))).annotate({ identifier: "DataTableCalendarDate" });
|
|
569
|
+
var isCalendarDate = Schema4.is(CalendarDate);
|
|
570
|
+
var InstantString = Schema4.String.check(Schema4.isPattern(/^\d{4}-\d{2}-\d{2}T(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/), Schema4.makeFilter((value) => isCalendarDate(value.slice(0, 10)))).annotate({ identifier: "DataTableInstantString" });
|
|
571
|
+
var DataTableDateInputSchema = Schema4.Union([
|
|
572
|
+
Schema4.Date,
|
|
573
|
+
Schema4.Int,
|
|
574
|
+
CalendarDate,
|
|
575
|
+
InstantString
|
|
576
|
+
]).annotate({ identifier: "DataTableDateInput" });
|
|
577
|
+
var DateStyle = Schema4.Literals(["full", "long", "medium", "short"]);
|
|
578
|
+
var DataTableDateFormatSchema = Schema4.Struct({
|
|
579
|
+
locale: Schema4.optionalKey(Schema4.String),
|
|
580
|
+
timeZone: Schema4.optionalKey(Schema4.String),
|
|
581
|
+
dateStyle: Schema4.optionalKey(DateStyle),
|
|
582
|
+
exportFormat: Schema4.optionalKey(Schema4.Literals(["iso", "formatted"]))
|
|
583
|
+
}).annotate({ identifier: "DataTableDateFormat" });
|
|
584
|
+
var DataTableDateTimeFormatSchema = Schema4.Struct({
|
|
585
|
+
...DataTableDateFormatSchema.fields,
|
|
586
|
+
timeStyle: Schema4.optionalKey(DateStyle),
|
|
587
|
+
hour12: Schema4.optionalKey(Schema4.Boolean)
|
|
588
|
+
}).annotate({ identifier: "DataTableDateTimeFormat" });
|
|
589
|
+
var DataTableCellValueSchema = Schema4.NullOr(Schema4.Union([
|
|
590
|
+
Schema4.String,
|
|
591
|
+
Schema4.Boolean,
|
|
592
|
+
Schema4.Finite,
|
|
593
|
+
Schema4.Array(DataTableItemSchema),
|
|
594
|
+
DataTableReferenceSchema
|
|
595
|
+
])).annotate({ identifier: "DataTableCellValue" });
|
|
596
|
+
var DataTableActionSchema = Schema4.Struct({
|
|
597
|
+
id: Schema4.NonEmptyString,
|
|
598
|
+
name: Schema4.String,
|
|
599
|
+
variant: Schema4.optionalKey(Schema4.Literals(["default", "destructive"])),
|
|
600
|
+
disabled: Schema4.optionalKey(Schema4.Boolean)
|
|
601
|
+
}).annotate({ identifier: "DataTableAction" });
|
|
602
|
+
var DataTableRowSchema = Schema4.Struct({
|
|
603
|
+
id: Schema4.NonEmptyString,
|
|
604
|
+
label: Schema4.String,
|
|
605
|
+
cells: Schema4.Record(Schema4.String, DataTableCellValueSchema),
|
|
606
|
+
actions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema)),
|
|
607
|
+
primaryActionId: Schema4.optionalKey(Schema4.String),
|
|
608
|
+
groups: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Array(Schema4.String))),
|
|
609
|
+
selectable: Schema4.optionalKey(Schema4.Boolean),
|
|
610
|
+
disabledColumnIds: Schema4.optionalKey(Schema4.Array(Schema4.String))
|
|
611
|
+
}).annotate({ identifier: "DataTableRow" });
|
|
612
|
+
var column = {
|
|
613
|
+
id: Schema4.NonEmptyString,
|
|
614
|
+
headerName: Schema4.String,
|
|
615
|
+
sortable: Schema4.optionalKey(Schema4.Boolean),
|
|
616
|
+
hideable: Schema4.optionalKey(Schema4.Boolean),
|
|
617
|
+
export: Schema4.optionalKey(Schema4.Boolean),
|
|
618
|
+
width: Schema4.optionalKey(Schema4.Number),
|
|
619
|
+
minWidth: Schema4.optionalKey(Schema4.Number),
|
|
620
|
+
maxWidth: Schema4.optionalKey(Schema4.Number),
|
|
621
|
+
resizable: Schema4.optionalKey(Schema4.Boolean),
|
|
622
|
+
truncate: Schema4.optionalKey(Schema4.Boolean),
|
|
623
|
+
searchable: Schema4.optionalKey(Schema4.Boolean),
|
|
624
|
+
filterable: Schema4.optionalKey(Schema4.Boolean),
|
|
625
|
+
emptyLabel: Schema4.optionalKey(Schema4.String),
|
|
626
|
+
nulls: Schema4.optionalKey(Schema4.Literals(["first", "last"]))
|
|
627
|
+
};
|
|
628
|
+
var DataTableBadgeOptionSchema = Schema4.Struct({
|
|
629
|
+
value: Schema4.NonEmptyString,
|
|
630
|
+
label: Schema4.optionalKey(Schema4.String),
|
|
631
|
+
variant: Schema4.optionalKey(Schema4.Literals([
|
|
632
|
+
"default",
|
|
633
|
+
"secondary",
|
|
634
|
+
"outline",
|
|
635
|
+
"destructive",
|
|
636
|
+
"success",
|
|
637
|
+
"info",
|
|
638
|
+
"muted"
|
|
639
|
+
]))
|
|
640
|
+
}).annotate({ identifier: "DataTableBadgeOption" });
|
|
641
|
+
var BadgeIcon = Schema4.declare((value) => Predicate.isFunction(value)).annotate({ identifier: "DataTableBadgeIcon" });
|
|
642
|
+
var DataTableBadgeOptionsSchema = Schema4.Struct({
|
|
643
|
+
options: Schema4.optionalKey(Schema4.Array(DataTableBadgeOptionSchema.mapFields((fields) => ({
|
|
644
|
+
...fields,
|
|
645
|
+
icon: Schema4.optionalKey(BadgeIcon)
|
|
646
|
+
}))))
|
|
647
|
+
}).annotate({ identifier: "DataTableBadgeOptions" });
|
|
648
|
+
var DataTableFieldSchema = Schema4.Union([
|
|
649
|
+
Schema4.Struct({
|
|
650
|
+
...column,
|
|
651
|
+
type: Schema4.Literal("text"),
|
|
652
|
+
display: Schema4.optionalKey(Schema4.Literal("badge")),
|
|
653
|
+
typeOptions: Schema4.optionalKey(DataTableBadgeOptionsSchema)
|
|
654
|
+
}),
|
|
655
|
+
Schema4.Struct({
|
|
656
|
+
...column,
|
|
657
|
+
type: Schema4.Literal("number"),
|
|
658
|
+
typeOptions: Schema4.optionalKey(Schema4.Struct({
|
|
659
|
+
locale: Schema4.optionalKey(Schema4.String),
|
|
660
|
+
style: Schema4.optionalKey(Schema4.Literals(["decimal", "percent", "currency", "unit"])),
|
|
661
|
+
currency: Schema4.optionalKey(Schema4.String),
|
|
662
|
+
unit: Schema4.optionalKey(Schema4.String),
|
|
663
|
+
notation: Schema4.optionalKey(Schema4.Literals(["standard", "scientific", "engineering", "compact"])),
|
|
664
|
+
minimumFractionDigits: Schema4.optionalKey(Schema4.Int.check(Schema4.isBetween({ minimum: 0, maximum: 20 }))),
|
|
665
|
+
maximumFractionDigits: Schema4.optionalKey(Schema4.Int.check(Schema4.isBetween({ minimum: 0, maximum: 20 }))),
|
|
666
|
+
exportFormat: Schema4.optionalKey(Schema4.Literals(["raw", "formatted"]))
|
|
667
|
+
}).annotate({ identifier: "DataTableNumberFormat" }))
|
|
668
|
+
}),
|
|
669
|
+
Schema4.Struct({ ...column, type: Schema4.Literal("reference") }),
|
|
670
|
+
Schema4.Struct({
|
|
671
|
+
...column,
|
|
672
|
+
type: Schema4.Literal("date"),
|
|
673
|
+
typeOptions: Schema4.optionalKey(DataTableDateFormatSchema)
|
|
674
|
+
}),
|
|
675
|
+
Schema4.Struct({
|
|
676
|
+
...column,
|
|
677
|
+
type: Schema4.Literal("dateTime"),
|
|
678
|
+
typeOptions: Schema4.optionalKey(DataTableDateTimeFormatSchema)
|
|
679
|
+
}),
|
|
680
|
+
Schema4.Struct({
|
|
681
|
+
...column,
|
|
682
|
+
type: Schema4.Literal("boolean"),
|
|
683
|
+
editable: Schema4.optionalKey(Schema4.Boolean),
|
|
684
|
+
typeOptions: Schema4.optionalKey(Schema4.Struct({
|
|
685
|
+
trueLabel: Schema4.optionalKey(Schema4.String),
|
|
686
|
+
falseLabel: Schema4.optionalKey(Schema4.String),
|
|
687
|
+
exportFormat: Schema4.optionalKey(Schema4.Literals(["raw", "formatted"]))
|
|
688
|
+
}).annotate({ identifier: "DataTableBooleanFormat" }))
|
|
689
|
+
}),
|
|
690
|
+
Schema4.Struct({
|
|
691
|
+
...column,
|
|
692
|
+
type: Schema4.Literal("list"),
|
|
693
|
+
filterOptions: Schema4.optionalKey(Schema4.Array(DataTableItemSchema)),
|
|
694
|
+
options: Schema4.optionalKey(Schema4.Array(DataTableItemSchema)),
|
|
695
|
+
allowRemove: Schema4.optionalKey(Schema4.Boolean),
|
|
696
|
+
itemActions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema)),
|
|
697
|
+
display: Schema4.optionalKey(Schema4.Literals(["list", "icon", "badge"])),
|
|
698
|
+
visibleCount: Schema4.optionalKey(Schema4.Int.check(Schema4.isGreaterThanOrEqualTo(0))),
|
|
699
|
+
actionsLabel: Schema4.optionalKey(Schema4.String),
|
|
700
|
+
manageLabel: Schema4.optionalKey(Schema4.String)
|
|
701
|
+
})
|
|
702
|
+
]).annotate({ identifier: "DataTableField" });
|
|
703
|
+
var DataTableColumnSchema = DataTableFieldSchema.mapMembers(Tuple.map(Schema4.fieldsAssign({
|
|
704
|
+
fields: Schema4.optionalKey(Schema4.Array(DataTableFieldSchema))
|
|
705
|
+
}))).annotate({ identifier: "DataTableColumn" });
|
|
706
|
+
var DataTableLabelsSchema = Schema4.Struct({
|
|
707
|
+
actions: Schema4.optionalKey(Schema4.String),
|
|
708
|
+
addItem: Schema4.optionalKey(Schema4.String),
|
|
709
|
+
listDetails: Schema4.optionalKey(Schema4.String),
|
|
710
|
+
empty: Schema4.optionalKey(Schema4.String),
|
|
711
|
+
filters: Schema4.optionalKey(Schema4.String),
|
|
712
|
+
filtersClear: Schema4.optionalKey(Schema4.String),
|
|
713
|
+
filterColumn: Schema4.optionalKey(Schema4.String),
|
|
714
|
+
filterClear: Schema4.optionalKey(Schema4.String),
|
|
715
|
+
filterApply: Schema4.optionalKey(Schema4.String),
|
|
716
|
+
filterValue: Schema4.optionalKey(Schema4.String),
|
|
717
|
+
filterOperator: Schema4.optionalKey(Schema4.String),
|
|
718
|
+
filterContains: Schema4.optionalKey(Schema4.String),
|
|
719
|
+
filterEquals: Schema4.optionalKey(Schema4.String),
|
|
720
|
+
filterStartsWith: Schema4.optionalKey(Schema4.String),
|
|
721
|
+
filterEndsWith: Schema4.optionalKey(Schema4.String),
|
|
722
|
+
filterMin: Schema4.optionalKey(Schema4.String),
|
|
723
|
+
filterMax: Schema4.optionalKey(Schema4.String),
|
|
724
|
+
filterFrom: Schema4.optionalKey(Schema4.String),
|
|
725
|
+
filterTo: Schema4.optionalKey(Schema4.String),
|
|
726
|
+
filterTrue: Schema4.optionalKey(Schema4.String),
|
|
727
|
+
filterFalse: Schema4.optionalKey(Schema4.String),
|
|
728
|
+
filterInvalid: Schema4.optionalKey(Schema4.String),
|
|
729
|
+
columns: Schema4.optionalKey(Schema4.String),
|
|
730
|
+
sortBy: Schema4.optionalKey(Schema4.String),
|
|
731
|
+
hideColumn: Schema4.optionalKey(Schema4.String),
|
|
732
|
+
loading: Schema4.optionalKey(Schema4.String),
|
|
733
|
+
removeItem: Schema4.optionalKey(Schema4.String),
|
|
734
|
+
search: Schema4.optionalKey(Schema4.String),
|
|
735
|
+
selectAllRows: Schema4.optionalKey(Schema4.String),
|
|
736
|
+
selectRow: Schema4.optionalKey(Schema4.String),
|
|
737
|
+
selected: Schema4.optionalKey(Schema4.String),
|
|
738
|
+
sortAsc: Schema4.optionalKey(Schema4.String),
|
|
739
|
+
sortDesc: Schema4.optionalKey(Schema4.String),
|
|
740
|
+
sortClear: Schema4.optionalKey(Schema4.String),
|
|
741
|
+
view: Schema4.optionalKey(Schema4.String),
|
|
742
|
+
tableView: Schema4.optionalKey(Schema4.String),
|
|
743
|
+
galleryView: Schema4.optionalKey(Schema4.String),
|
|
744
|
+
groupBy: Schema4.optionalKey(Schema4.String),
|
|
745
|
+
export: Schema4.optionalKey(Schema4.String),
|
|
746
|
+
exportFailed: Schema4.optionalKey(Schema4.String),
|
|
747
|
+
moveUp: Schema4.optionalKey(Schema4.String),
|
|
748
|
+
moveDown: Schema4.optionalKey(Schema4.String),
|
|
749
|
+
reorder: Schema4.optionalKey(Schema4.String),
|
|
750
|
+
refresh: Schema4.optionalKey(Schema4.String),
|
|
751
|
+
resize: Schema4.optionalKey(Schema4.String)
|
|
752
|
+
}).annotate({ identifier: "DataTableLabels" });
|
|
753
|
+
var DataTableViewSchema = Schema4.Literals(["table", "gallery"]);
|
|
754
|
+
var DataTablePreferencesSchema = Schema4.Struct({
|
|
755
|
+
columnVisibility: Schema4.Record(Schema4.String, Schema4.Boolean),
|
|
756
|
+
columnSizing: Schema4.Record(Schema4.String, Schema4.Finite),
|
|
757
|
+
grouping: Schema4.optionalKey(Schema4.Array(Schema4.String)),
|
|
758
|
+
view: DataTableViewSchema
|
|
759
|
+
}).annotate({ identifier: "DataTablePersistedUiState" });
|
|
760
|
+
var GroupField = Schema4.Struct({
|
|
761
|
+
id: Schema4.NonEmptyString,
|
|
762
|
+
label: Schema4.String,
|
|
763
|
+
actionsLabel: Schema4.optionalKey(Schema4.String),
|
|
764
|
+
groups: Schema4.optionalKey(Schema4.Array(Schema4.Struct({
|
|
765
|
+
id: Schema4.String,
|
|
766
|
+
label: Schema4.String,
|
|
767
|
+
empty: Schema4.optionalKey(Schema4.String)
|
|
768
|
+
}).annotate({ identifier: "DataTableGroupLabel" }))),
|
|
769
|
+
actions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema)),
|
|
770
|
+
movable: Schema4.optionalKey(Schema4.Boolean)
|
|
771
|
+
}).annotate({ identifier: "DataTableGroupField" });
|
|
772
|
+
var DataTablePropsSchema = Schema4.Struct({
|
|
773
|
+
...DataTableCommonPropsSchema.fields,
|
|
774
|
+
label: Schema4.String,
|
|
775
|
+
rowData: Schema4.Array(DataTableRowSchema),
|
|
776
|
+
rowActivation: Schema4.optionalKey(Schema4.Boolean),
|
|
777
|
+
columnDefs: Schema4.Array(DataTableColumnSchema),
|
|
778
|
+
status: Schema4.optionalKey(Schema4.Struct({
|
|
779
|
+
loading: Schema4.optionalKey(Schema4.Boolean),
|
|
780
|
+
empty: Schema4.optionalKey(Schema4.String),
|
|
781
|
+
error: Schema4.optionalKey(Schema4.String)
|
|
782
|
+
})),
|
|
783
|
+
sort: Schema4.optionalKey(Schema4.Array(DataTableSortSchema)),
|
|
784
|
+
sortMode: Schema4.optionalKey(Schema4.Literals(["client", "server"])),
|
|
785
|
+
search: Schema4.optionalKey(Schema4.Boolean),
|
|
786
|
+
columnFilters: Schema4.optionalKey(Schema4.Boolean),
|
|
787
|
+
state: Schema4.optionalKey(DataTableQuerySchema),
|
|
788
|
+
features: Schema4.optionalKey(Schema4.Struct({
|
|
789
|
+
...DataTableCommonFeaturesSchema.fields,
|
|
790
|
+
pagination: Schema4.optionalKey(Schema4.Union([Schema4.Literal(false), PaginationSchema])),
|
|
791
|
+
grouping: Schema4.optionalKey(Schema4.Struct({
|
|
792
|
+
initial: Schema4.optionalKey(Schema4.Array(Schema4.String)),
|
|
793
|
+
fields: Schema4.Array(GroupField)
|
|
794
|
+
}).annotate({ identifier: "DataTableGrouping" })),
|
|
795
|
+
gallery: Schema4.optionalKey(Schema4.Struct({
|
|
796
|
+
name: Schema4.String,
|
|
797
|
+
description: Schema4.optionalKey(Schema4.String),
|
|
798
|
+
image: Schema4.optionalKey(Schema4.String),
|
|
799
|
+
tags: Schema4.optionalKey(Schema4.Array(Schema4.String))
|
|
800
|
+
}).annotate({ identifier: "DataTableGallery" })),
|
|
801
|
+
reordering: Schema4.optionalKey(Schema4.Boolean),
|
|
802
|
+
export: Schema4.optionalKey(Schema4.Struct({
|
|
803
|
+
baseName: Schema4.String,
|
|
804
|
+
scope: Schema4.optionalKey(Schema4.Literals(["filteredRows", "currentPage"])),
|
|
805
|
+
builtIn: Schema4.optionalKey(Schema4.Boolean),
|
|
806
|
+
actions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema)),
|
|
807
|
+
pending: Schema4.optionalKey(Schema4.Boolean),
|
|
808
|
+
failed: Schema4.optionalKey(Schema4.Boolean)
|
|
809
|
+
}).annotate({ identifier: "DataTableExport" })),
|
|
810
|
+
refresh: Schema4.optionalKey(Schema4.Boolean),
|
|
811
|
+
virtualization: Schema4.optionalKey(Schema4.Union([
|
|
812
|
+
Schema4.Boolean,
|
|
813
|
+
Schema4.Struct({
|
|
814
|
+
scroll: Schema4.optionalKey(Schema4.Literals(["table", "internal", "page"])),
|
|
815
|
+
height: Schema4.optionalKey(Schema4.Int.check(Schema4.isGreaterThan(0))),
|
|
816
|
+
estimateRowHeight: Schema4.optionalKey(Schema4.Int.check(Schema4.isGreaterThan(0))),
|
|
817
|
+
overscan: Schema4.optionalKey(Schema4.Int.check(Schema4.isGreaterThanOrEqualTo(0)))
|
|
818
|
+
}).annotate({ identifier: "DataTableVirtualization" })
|
|
819
|
+
]))
|
|
820
|
+
}).annotate({ identifier: "DataTableHtmlFeatures" })),
|
|
821
|
+
initialState: Schema4.optionalKey(Schema4.Struct({
|
|
822
|
+
...queryFields,
|
|
823
|
+
page: Schema4.optional(queryFields.page),
|
|
824
|
+
pageSize: Schema4.optional(queryFields.pageSize),
|
|
825
|
+
columnVisibility: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Boolean)),
|
|
826
|
+
view: Schema4.optionalKey(DataTableViewSchema)
|
|
827
|
+
}).annotate({ identifier: "DataTableInitialQuery" })),
|
|
828
|
+
pagination: Schema4.optionalKey(PaginationSchema),
|
|
829
|
+
selection: Schema4.optionalKey(Schema4.Struct({
|
|
830
|
+
selectedRowIds: Schema4.optionalKey(Schema4.Array(Schema4.String)),
|
|
831
|
+
bulkActionsLabel: Schema4.optionalKey(Schema4.String),
|
|
832
|
+
bulkActions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema))
|
|
833
|
+
})),
|
|
834
|
+
messages: Schema4.optionalKey(Schema4.Record(Schema4.String, DataTableLabelsSchema))
|
|
835
|
+
}).annotate({ identifier: "DataTableProps" });
|
|
836
|
+
var DataTableFilterDraftSchema = Schema4.Struct({
|
|
837
|
+
id: Schema4.String,
|
|
838
|
+
primary: Schema4.String,
|
|
839
|
+
secondary: Schema4.String,
|
|
840
|
+
operator: TextFilterOperator,
|
|
841
|
+
values: Schema4.Array(Schema4.String)
|
|
842
|
+
}).annotate({ identifier: "DataTableFilterDraft" });
|
|
843
|
+
|
|
844
|
+
// ../../src/components/data-table/index.ts
|
|
845
|
+
var defaultMessages = {
|
|
846
|
+
en: {
|
|
847
|
+
actions: "Actions",
|
|
848
|
+
addItem: "Add item...",
|
|
849
|
+
listDetails: "View all items",
|
|
850
|
+
empty: "No results.",
|
|
851
|
+
filters: "Filters",
|
|
852
|
+
filtersClear: "Clear all filters",
|
|
853
|
+
filterColumn: "Column",
|
|
854
|
+
filterClear: "Clear filter",
|
|
855
|
+
filterApply: "Apply filter",
|
|
856
|
+
filterValue: "Value",
|
|
857
|
+
filterOperator: "Operator",
|
|
858
|
+
filterContains: "Contains",
|
|
859
|
+
filterEquals: "Equals",
|
|
860
|
+
filterStartsWith: "Starts with",
|
|
861
|
+
filterEndsWith: "Ends with",
|
|
862
|
+
filterMin: "Minimum",
|
|
863
|
+
filterMax: "Maximum",
|
|
864
|
+
filterFrom: "From (UTC)",
|
|
865
|
+
filterTo: "To (UTC)",
|
|
866
|
+
filterTrue: "True",
|
|
867
|
+
filterFalse: "False",
|
|
868
|
+
filterInvalid: "Enter a valid filter. Ranges must be in ascending order.",
|
|
869
|
+
columns: "Columns",
|
|
870
|
+
sortBy: "Sort by",
|
|
871
|
+
hideColumn: "Hide column",
|
|
872
|
+
loading: "Loading...",
|
|
873
|
+
removeItem: "Remove",
|
|
874
|
+
search: "Search",
|
|
875
|
+
selectAllRows: "Select all rows on this page",
|
|
876
|
+
selectRow: "Select row",
|
|
877
|
+
selected: "Selected",
|
|
878
|
+
sortAsc: "Ascending",
|
|
879
|
+
sortDesc: "Descending",
|
|
880
|
+
sortClear: "Clear sorting",
|
|
881
|
+
view: "View",
|
|
882
|
+
tableView: "Table",
|
|
883
|
+
galleryView: "Gallery",
|
|
884
|
+
groupBy: "Group by",
|
|
885
|
+
export: "Export",
|
|
886
|
+
exportFailed: "Export failed. Please try again.",
|
|
887
|
+
refresh: "Refresh",
|
|
888
|
+
moveUp: "Move up",
|
|
889
|
+
moveDown: "Move down",
|
|
890
|
+
reorder: "Drag to reorder",
|
|
891
|
+
resize: "Resize column"
|
|
892
|
+
},
|
|
893
|
+
fr: {
|
|
894
|
+
actions: "Actions",
|
|
895
|
+
addItem: "Ajouter un élément...",
|
|
896
|
+
listDetails: "Afficher tous les éléments",
|
|
897
|
+
empty: "Aucun résultat.",
|
|
898
|
+
filters: "Filtres",
|
|
899
|
+
filtersClear: "Effacer tous les filtres",
|
|
900
|
+
filterColumn: "Colonne",
|
|
901
|
+
filterClear: "Effacer le filtre",
|
|
902
|
+
filterApply: "Appliquer le filtre",
|
|
903
|
+
filterValue: "Valeur",
|
|
904
|
+
filterOperator: "Opérateur",
|
|
905
|
+
filterContains: "Contient",
|
|
906
|
+
filterEquals: "Égal à",
|
|
907
|
+
filterStartsWith: "Commence par",
|
|
908
|
+
filterEndsWith: "Se termine par",
|
|
909
|
+
filterMin: "Minimum",
|
|
910
|
+
filterMax: "Maximum",
|
|
911
|
+
filterFrom: "Du (UTC)",
|
|
912
|
+
filterTo: "Au (UTC)",
|
|
913
|
+
filterTrue: "Vrai",
|
|
914
|
+
filterFalse: "Faux",
|
|
915
|
+
filterInvalid: "Saisissez un filtre valide. Les bornes doivent être dans l’ordre croissant.",
|
|
916
|
+
columns: "Colonnes",
|
|
917
|
+
sortBy: "Trier par",
|
|
918
|
+
hideColumn: "Masquer la colonne",
|
|
919
|
+
loading: "Chargement...",
|
|
920
|
+
removeItem: "Retirer",
|
|
921
|
+
search: "Rechercher",
|
|
922
|
+
selectAllRows: "Sélectionner toutes les lignes de cette page",
|
|
923
|
+
selectRow: "Sélectionner la ligne",
|
|
924
|
+
selected: "Sélectionnés",
|
|
925
|
+
sortAsc: "Croissant",
|
|
926
|
+
sortDesc: "Décroissant",
|
|
927
|
+
sortClear: "Effacer le tri",
|
|
928
|
+
view: "Affichage",
|
|
929
|
+
tableView: "Tableau",
|
|
930
|
+
galleryView: "Galerie",
|
|
931
|
+
groupBy: "Grouper par",
|
|
932
|
+
export: "Exporter",
|
|
933
|
+
exportFailed: "L’exportation a échoué. Veuillez réessayer.",
|
|
934
|
+
refresh: "Rafraîchir",
|
|
935
|
+
moveUp: "Déplacer vers le haut",
|
|
936
|
+
moveDown: "Déplacer vers le bas",
|
|
937
|
+
reorder: "Glisser pour réorganiser",
|
|
938
|
+
resize: "Redimensionner la colonne"
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
var htmlDataTableMessages = (locale, messages) => {
|
|
942
|
+
const base = locale.split("-")[0] ?? "en";
|
|
943
|
+
return {
|
|
944
|
+
...defaultMessages[base === "fr" ? "fr" : "en"],
|
|
945
|
+
...messages?.[base],
|
|
946
|
+
...messages?.[locale]
|
|
947
|
+
};
|
|
948
|
+
};
|
|
949
|
+
var compareTableText = (left, right, locale) => left.localeCompare(right, locale, { numeric: true, sensitivity: "base" });
|
|
950
|
+
var isTableText = Schema5.is(Schema5.String);
|
|
951
|
+
var isTableNumber = Schema5.is(Schema5.Finite);
|
|
952
|
+
var isTableBoolean = Schema5.is(Schema5.Boolean);
|
|
953
|
+
var isTableReference = Schema5.is(DataTableReferenceSchema);
|
|
954
|
+
var isTableList = Schema5.is(Schema5.Array(DataTableItemSchema));
|
|
955
|
+
var tableInitials = (label) => label.trim().split(/\s+/).slice(0, 2).map((word) => word.slice(0, 1)).join("").toLocaleUpperCase();
|
|
956
|
+
var formatNumberValue = (value, options, defaultLocale = "en") => {
|
|
957
|
+
const { locale, ...format } = options ?? {};
|
|
958
|
+
return new Intl.NumberFormat(locale ?? defaultLocale, format).format(value);
|
|
959
|
+
};
|
|
960
|
+
var tableBooleanLabel = (value, options) => (value ? options?.trueLabel : options?.falseLabel) ?? String(value);
|
|
961
|
+
var decodeDateInput = Schema5.decodeUnknownOption(DataTableDateInputSchema);
|
|
962
|
+
var resolveDate = (value, type) => Option3.getOrUndefined(Option3.flatMap(decodeDateInput(value), (input) => {
|
|
963
|
+
const calendarOnly = isCalendarDate(input);
|
|
964
|
+
if (calendarOnly && type === "dateTime")
|
|
965
|
+
return Option3.none();
|
|
966
|
+
return Option3.map(DateTime3.make(input), (instant) => ({
|
|
967
|
+
instant,
|
|
968
|
+
calendarOnly
|
|
969
|
+
}));
|
|
970
|
+
}));
|
|
971
|
+
var formatDateValue = (date, column, locale = "en") => DateTime3.format(date.instant, {
|
|
972
|
+
locale: column.typeOptions?.locale ?? locale,
|
|
973
|
+
timeZone: date.calendarOnly ? "UTC" : column.typeOptions?.timeZone ?? "UTC",
|
|
974
|
+
dateStyle: column.typeOptions?.dateStyle ?? "medium",
|
|
975
|
+
timeStyle: column.type === "dateTime" ? column.typeOptions?.timeStyle ?? "short" : undefined,
|
|
976
|
+
hour12: column.type === "dateTime" ? column.typeOptions?.hour12 : undefined
|
|
977
|
+
});
|
|
978
|
+
var dateIsoValue = (date) => date.calendarOnly ? DateTime3.formatIsoDateUtc(date.instant) : DateTime3.formatIso(date.instant);
|
|
979
|
+
var matchesDateFilter = (date, filter) => {
|
|
980
|
+
if (!date)
|
|
981
|
+
return false;
|
|
982
|
+
const day = DateTime3.formatIsoDateUtc(date.instant);
|
|
983
|
+
return (filter.from === undefined || day >= filter.from) && (filter.to === undefined || day <= filter.to);
|
|
984
|
+
};
|
|
985
|
+
var matchesFilterText = (value, filter) => {
|
|
986
|
+
const text = value.toLocaleLowerCase();
|
|
987
|
+
const query = filter.value.toLocaleLowerCase();
|
|
988
|
+
switch (filter.operator) {
|
|
989
|
+
case "contains":
|
|
990
|
+
return text.includes(query);
|
|
991
|
+
case "equals":
|
|
992
|
+
return text === query;
|
|
993
|
+
case "startsWith":
|
|
994
|
+
return text.startsWith(query);
|
|
995
|
+
case "endsWith":
|
|
996
|
+
return text.endsWith(query);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
var tableFilterKind = (column, hasOptions = false) => hasOptions || column.type === "list" || column.display === "badge" ? "values" : column.type === "reference" ? "text" : column.type === "dateTime" ? "date" : column.type ?? "text";
|
|
1000
|
+
var tableBadgeValue = (value) => isTableText(value) && value !== "" ? value : null;
|
|
1001
|
+
var tableBadge = (input, config) => {
|
|
1002
|
+
const value = tableBadgeValue(input);
|
|
1003
|
+
if (value === null)
|
|
1004
|
+
return null;
|
|
1005
|
+
const option = config?.options?.find((option) => option.value === value);
|
|
1006
|
+
return {
|
|
1007
|
+
value,
|
|
1008
|
+
label: option?.label ?? value,
|
|
1009
|
+
variant: option?.variant ?? "secondary",
|
|
1010
|
+
option
|
|
1011
|
+
};
|
|
1012
|
+
};
|
|
1013
|
+
var tableBadgeFilterOptions = (values, config) => {
|
|
1014
|
+
const options = new Map(config?.options?.map(({ value, label }) => [value, label ?? value]));
|
|
1015
|
+
for (const input of values) {
|
|
1016
|
+
const value = tableBadgeValue(input);
|
|
1017
|
+
if (value !== null && !options.has(value))
|
|
1018
|
+
options.set(value, value);
|
|
1019
|
+
}
|
|
1020
|
+
return [...options].map(([value, label]) => ({ value, label }));
|
|
1021
|
+
};
|
|
1022
|
+
var tableBadgeSearchText = (value, config) => {
|
|
1023
|
+
const badge = tableBadge(value, config);
|
|
1024
|
+
return badge ? `${badge.label} ${badge.value}` : "";
|
|
1025
|
+
};
|
|
1026
|
+
var matchesTableFilter = (filter, value, type, text, values) => {
|
|
1027
|
+
switch (filter.kind) {
|
|
1028
|
+
case "text":
|
|
1029
|
+
return matchesFilterText(text(), filter);
|
|
1030
|
+
case "number":
|
|
1031
|
+
return isTableNumber(value) && (filter.min === undefined || value >= filter.min) && (filter.max === undefined || value <= filter.max);
|
|
1032
|
+
case "boolean":
|
|
1033
|
+
return value === filter.value;
|
|
1034
|
+
case "values":
|
|
1035
|
+
return values().some((value) => filter.values.includes(value));
|
|
1036
|
+
case "date":
|
|
1037
|
+
return matchesDateFilter(resolveDate(value, type === "dateTime" ? "dateTime" : "date"), filter);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
var tableDataColumns = (columns) => columns.flatMap((column) => column.fields?.length ? column.fields.map((field) => ({
|
|
1041
|
+
...field,
|
|
1042
|
+
id: `${column.id}.${field.id}`,
|
|
1043
|
+
headerName: `${column.headerName} / ${field.headerName}`,
|
|
1044
|
+
sortable: column.sortable === false ? false : field.sortable,
|
|
1045
|
+
searchable: column.searchable === false ? false : field.searchable,
|
|
1046
|
+
filterable: column.filterable === false ? false : field.filterable,
|
|
1047
|
+
export: column.export === false ? false : field.export
|
|
1048
|
+
})) : [column]);
|
|
1049
|
+
var tableFilterOptions = (rows, columnId, locale) => {
|
|
1050
|
+
const options = new Map;
|
|
1051
|
+
for (const row of rows) {
|
|
1052
|
+
const items = row.cells[columnId];
|
|
1053
|
+
if (isTableList(items)) {
|
|
1054
|
+
for (const item of items)
|
|
1055
|
+
options.set(item.value, item);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return [...options.values()].sort((a, b) => compareTableText(a.label, b.label, locale));
|
|
1059
|
+
};
|
|
1060
|
+
var filterTableColumns = (rows, columns, filters) => {
|
|
1061
|
+
const byId = new Map(columns.filter(({ filterable }) => filterable !== false).map((column) => [column.id, column]));
|
|
1062
|
+
const active = filters.filter((filter) => {
|
|
1063
|
+
const column = byId.get(filter.id);
|
|
1064
|
+
return column && tableFilterKind(column) === filter.kind;
|
|
1065
|
+
});
|
|
1066
|
+
if (!active.length)
|
|
1067
|
+
return rows;
|
|
1068
|
+
return rows.filter((row) => active.every((filter) => {
|
|
1069
|
+
const value = row.cells[filter.id];
|
|
1070
|
+
const column = byId.get(filter.id);
|
|
1071
|
+
return matchesTableFilter(filter, value, column?.type, () => isTableText(value) ? value : isTableReference(value) ? `${value.label} ${value.description ?? ""}`.trim() : "", () => {
|
|
1072
|
+
if (column?.type === "text" && column.display === "badge") {
|
|
1073
|
+
const key = tableBadgeValue(value);
|
|
1074
|
+
return key === null ? [] : [key];
|
|
1075
|
+
}
|
|
1076
|
+
return isTableList(value) ? value.map(({ value }) => value) : [];
|
|
1077
|
+
});
|
|
1078
|
+
}));
|
|
1079
|
+
};
|
|
1080
|
+
var columnValue = (column, value) => {
|
|
1081
|
+
switch (column.type) {
|
|
1082
|
+
case "text":
|
|
1083
|
+
return column.display === "badge" ? tableBadgeValue(value) : isTableText(value) ? value : null;
|
|
1084
|
+
case "number":
|
|
1085
|
+
case "boolean":
|
|
1086
|
+
case "date":
|
|
1087
|
+
case "dateTime":
|
|
1088
|
+
return tableSortScalar(column.type, value);
|
|
1089
|
+
case "reference":
|
|
1090
|
+
return isTableReference(value) ? value.label : null;
|
|
1091
|
+
case "list":
|
|
1092
|
+
return isTableList(value) ? value.map(({ label }) => label).join(", ") : null;
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
var tableSortScalar = (type, value) => {
|
|
1096
|
+
if (type === "number")
|
|
1097
|
+
return isTableNumber(value) ? value : null;
|
|
1098
|
+
if (type === "boolean")
|
|
1099
|
+
return isTableBoolean(value) ? Number(value) : null;
|
|
1100
|
+
const date = resolveDate(value, type);
|
|
1101
|
+
return date ? DateTime3.toEpochMillis(date.instant) : null;
|
|
1102
|
+
};
|
|
1103
|
+
var compareTableSortValues = (left, right, direction, nulls, locale) => {
|
|
1104
|
+
if (left === right)
|
|
1105
|
+
return 0;
|
|
1106
|
+
const nullOrder = nulls === "first" ? -1 : 1;
|
|
1107
|
+
if (left === null)
|
|
1108
|
+
return nullOrder;
|
|
1109
|
+
if (right === null)
|
|
1110
|
+
return -nullOrder;
|
|
1111
|
+
const comparison = isTableNumber(left) && isTableNumber(right) ? left - right : compareTableText(String(left), String(right), locale);
|
|
1112
|
+
return direction === "asc" ? comparison : -comparison;
|
|
1113
|
+
};
|
|
1114
|
+
var sortTableRows = (rows, columns, sort, locale) => {
|
|
1115
|
+
const byId = new Map(columns.map((column) => [column.id, column]));
|
|
1116
|
+
return rows.slice().sort((leftRow, rightRow) => {
|
|
1117
|
+
for (const { id, direction } of sort) {
|
|
1118
|
+
const column = byId.get(id);
|
|
1119
|
+
if (!column || column.sortable === false)
|
|
1120
|
+
continue;
|
|
1121
|
+
const left = columnValue(column, leftRow.cells[id]);
|
|
1122
|
+
const right = columnValue(column, rightRow.cells[id]);
|
|
1123
|
+
const comparison = compareTableSortValues(left, right, direction, column.nulls, locale);
|
|
1124
|
+
if (comparison !== 0)
|
|
1125
|
+
return comparison;
|
|
1126
|
+
}
|
|
1127
|
+
return 0;
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
var filterTableRows = (rows, columns, search, locale) => {
|
|
1131
|
+
const query = search.trim().toLocaleLowerCase(locale);
|
|
1132
|
+
if (!query)
|
|
1133
|
+
return rows;
|
|
1134
|
+
const searchable = columns.filter(({ searchable }) => searchable !== false);
|
|
1135
|
+
return rows.filter((row) => searchable.some((column) => {
|
|
1136
|
+
const value = row.cells[column.id];
|
|
1137
|
+
if (column.type === "text" && column.display === "badge")
|
|
1138
|
+
return tableBadgeSearchText(value, column.typeOptions).toLocaleLowerCase(locale).includes(query);
|
|
1139
|
+
if (column.type === "date" || column.type === "dateTime") {
|
|
1140
|
+
const date = resolveDate(value, column.type);
|
|
1141
|
+
return !!date && `${formatDateValue(date, column, locale)} ${dateIsoValue(date)}`.toLocaleLowerCase(locale).includes(query);
|
|
1142
|
+
}
|
|
1143
|
+
const text = column.type === "reference" && isTableReference(value) ? `${value.label} ${value.description ?? ""}` : column.type === "number" && isTableNumber(value) ? `${formatNumberValue(value, column.typeOptions, locale)} ${value}` : column.type === "boolean" && isTableBoolean(value) ? `${tableBooleanLabel(value, column.typeOptions)} ${value}` : String(columnValue(column, value) ?? "");
|
|
1144
|
+
return text.toLocaleLowerCase(locale).includes(query);
|
|
1145
|
+
}));
|
|
1146
|
+
};
|
|
1147
|
+
var updateSelectedRows = (selected, targets, checked) => {
|
|
1148
|
+
const next = new Set(selected);
|
|
1149
|
+
for (const id of targets) {
|
|
1150
|
+
if (checked)
|
|
1151
|
+
next.add(id);
|
|
1152
|
+
else
|
|
1153
|
+
next.delete(id);
|
|
1154
|
+
}
|
|
1155
|
+
return Array.from(next);
|
|
1156
|
+
};
|
|
1157
|
+
var resolveTablePage = (rowCount, query) => {
|
|
1158
|
+
const pageSize = Math.max(1, query.pageSize);
|
|
1159
|
+
const pageCount = Math.max(1, Math.ceil(rowCount / pageSize));
|
|
1160
|
+
const page = Math.min(pageCount - 1, Math.max(0, query.page));
|
|
1161
|
+
const start = page * pageSize;
|
|
1162
|
+
return { page, pageCount, start, end: start + pageSize };
|
|
1163
|
+
};
|
|
1164
|
+
var edit = UiSchema2.TaggedEnum({
|
|
1165
|
+
SetBoolean: { value: Schema5.Boolean },
|
|
1166
|
+
AddItem: { itemId: Schema5.String },
|
|
1167
|
+
RemoveItem: { itemId: Schema5.String }
|
|
1168
|
+
}).annotate({ identifier: "DataTableEdit" });
|
|
1169
|
+
var DataTableEdit = edit;
|
|
1170
|
+
var eventFields = {
|
|
1171
|
+
RowActivated: { rowId: Schema5.String },
|
|
1172
|
+
ItemActionRequested: {
|
|
1173
|
+
rowId: Schema5.String,
|
|
1174
|
+
columnId: Schema5.String,
|
|
1175
|
+
itemId: Schema5.String,
|
|
1176
|
+
actionId: Schema5.String
|
|
1177
|
+
},
|
|
1178
|
+
RefreshRequested: {},
|
|
1179
|
+
ExportRequested: { actionId: Schema5.String },
|
|
1180
|
+
GroupActionRequested: {
|
|
1181
|
+
fieldId: Schema5.String,
|
|
1182
|
+
groupId: Schema5.String,
|
|
1183
|
+
actionId: Schema5.String
|
|
1184
|
+
},
|
|
1185
|
+
GroupMoveRequested: {
|
|
1186
|
+
rowId: Schema5.String,
|
|
1187
|
+
fieldId: Schema5.String,
|
|
1188
|
+
groupId: Schema5.String
|
|
1189
|
+
},
|
|
1190
|
+
RowsReordered: { rowIds: Schema5.Array(Schema5.String) },
|
|
1191
|
+
StateChanged: { state: DataTableQuerySchema },
|
|
1192
|
+
SortChanged: { sort: Schema5.Array(DataTableSortSchema) },
|
|
1193
|
+
SelectionChanged: { selectedRowIds: Schema5.Array(Schema5.String) },
|
|
1194
|
+
CellEditRequested: { rowId: Schema5.String, columnId: Schema5.String, edit },
|
|
1195
|
+
RowActionRequested: { rowId: Schema5.String, actionId: Schema5.String },
|
|
1196
|
+
BulkActionRequested: {
|
|
1197
|
+
rowIds: Schema5.Array(Schema5.String),
|
|
1198
|
+
actionId: Schema5.String
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
var DataTableEvents = UiSchema2.TaggedEnum(eventFields).annotate({
|
|
1202
|
+
identifier: "DataTableEvents"
|
|
1203
|
+
});
|
|
1204
|
+
var DataTableMessage = UiSchema2.TaggedEnum({
|
|
1205
|
+
ReferenceImageFailed: { src: Schema5.String },
|
|
1206
|
+
RowActivated: eventFields.RowActivated,
|
|
1207
|
+
PreferencesLoaded: { preferences: Schema5.NullOr(DataTablePreferencesSchema) },
|
|
1208
|
+
ItemActionRequested: eventFields.ItemActionRequested,
|
|
1209
|
+
BuiltInExportRequested: {
|
|
1210
|
+
format: Schema5.Literals(["csv", "json"]),
|
|
1211
|
+
locale: Schema5.optionalKey(Schema5.String)
|
|
1212
|
+
},
|
|
1213
|
+
ExportStarted: {},
|
|
1214
|
+
ExportFinished: { failed: Schema5.Boolean },
|
|
1215
|
+
RefreshRequested: {},
|
|
1216
|
+
ExportRequested: eventFields.ExportRequested,
|
|
1217
|
+
GroupActionRequested: eventFields.GroupActionRequested,
|
|
1218
|
+
GroupMoveRequested: eventFields.GroupMoveRequested,
|
|
1219
|
+
ReorderRequested: {
|
|
1220
|
+
rowId: Schema5.String,
|
|
1221
|
+
targetId: Schema5.String,
|
|
1222
|
+
after: Schema5.Boolean
|
|
1223
|
+
},
|
|
1224
|
+
DragStarted: { rowId: Schema5.String },
|
|
1225
|
+
DragEnded: {},
|
|
1226
|
+
DragDropped: { targetId: Schema5.String },
|
|
1227
|
+
GroupDropped: { fieldId: Schema5.String, groupId: Schema5.String },
|
|
1228
|
+
ViewPicked: { view: DataTableViewSchema },
|
|
1229
|
+
GroupingToggled: { fieldId: Schema5.String },
|
|
1230
|
+
GroupToggled: { key: Schema5.String },
|
|
1231
|
+
ColumnResized: { id: Schema5.String, delta: Schema5.Finite },
|
|
1232
|
+
ColumnResizeReset: { id: Schema5.String },
|
|
1233
|
+
ResizeStarted: { id: Schema5.String, x: Schema5.Finite, pointerId: Schema5.Int },
|
|
1234
|
+
ResizeMoved: { x: Schema5.Finite, pointerId: Schema5.Int },
|
|
1235
|
+
ResizeEnded: { pointerId: Schema5.Int },
|
|
1236
|
+
ColumnFiltersCleared: { id: Schema5.String },
|
|
1237
|
+
ColumnSortCleared: { id: Schema5.String },
|
|
1238
|
+
CellEditRequested: eventFields.CellEditRequested,
|
|
1239
|
+
RowActionRequested: eventFields.RowActionRequested,
|
|
1240
|
+
MenuOpened: { key: Schema5.String },
|
|
1241
|
+
MenuClosed: { key: Schema5.String },
|
|
1242
|
+
MenuQueryChanged: { key: Schema5.String, query: Schema5.String },
|
|
1243
|
+
SubmenuOpened: {
|
|
1244
|
+
key: Schema5.String,
|
|
1245
|
+
filterColumnId: Schema5.optionalKey(Schema5.String)
|
|
1246
|
+
},
|
|
1247
|
+
SubmenuClosed: { key: Schema5.String },
|
|
1248
|
+
SearchChanged: { value: Schema5.String },
|
|
1249
|
+
FilterInputChanged: {
|
|
1250
|
+
field: Schema5.Literals(["primary", "secondary"]),
|
|
1251
|
+
value: Schema5.String
|
|
1252
|
+
},
|
|
1253
|
+
FilterOperatorChanged: { operator: TextFilterOperator },
|
|
1254
|
+
FilterValueToggled: { value: Schema5.String, checked: Schema5.Boolean },
|
|
1255
|
+
FilterApplied: {},
|
|
1256
|
+
ColumnFilterChanged: {
|
|
1257
|
+
id: Schema5.String,
|
|
1258
|
+
filter: Schema5.NullOr(ColumnFilter)
|
|
1259
|
+
},
|
|
1260
|
+
FilterCleared: {},
|
|
1261
|
+
FiltersCleared: {},
|
|
1262
|
+
PageRequested: { page: Schema5.Int },
|
|
1263
|
+
ServerPageInvalidated: {},
|
|
1264
|
+
PageSizeRequested: { pageSize: Schema5.Int },
|
|
1265
|
+
SortRequested: {
|
|
1266
|
+
columnId: Schema5.String,
|
|
1267
|
+
direction: Schema5.NullOr(DataTableSortSchema.fields.direction)
|
|
1268
|
+
},
|
|
1269
|
+
ColumnVisibilityChanged: { id: Schema5.String, visible: Schema5.Boolean },
|
|
1270
|
+
SelectionRequested: {
|
|
1271
|
+
rowIds: Schema5.Array(Schema5.String),
|
|
1272
|
+
checked: Schema5.Boolean
|
|
1273
|
+
},
|
|
1274
|
+
BulkActionRequested: { actionId: Schema5.String }
|
|
1275
|
+
}).annotate({ identifier: "DataTableMessage" });
|
|
1276
|
+
var dataTableOptions = {
|
|
1277
|
+
name: "DataTable",
|
|
1278
|
+
props: DataTablePropsSchema,
|
|
1279
|
+
model: Schema5.Struct({
|
|
1280
|
+
menu: Schema5.NullOr(Schema5.String),
|
|
1281
|
+
submenu: Schema5.NullOr(Schema5.String),
|
|
1282
|
+
menuQuery: Schema5.String,
|
|
1283
|
+
failedImages: Schema5.Array(Schema5.String),
|
|
1284
|
+
selectedRowIds: Schema5.Array(Schema5.String),
|
|
1285
|
+
query: DataTableQuerySchema,
|
|
1286
|
+
preferencesLoaded: Schema5.Boolean,
|
|
1287
|
+
columnVisibility: Schema5.Record(Schema5.String, Schema5.Boolean),
|
|
1288
|
+
columnSizing: Schema5.Record(Schema5.String, Schema5.Finite),
|
|
1289
|
+
view: DataTableViewSchema,
|
|
1290
|
+
grouping: Schema5.Array(Schema5.String),
|
|
1291
|
+
collapsedGroups: Schema5.Record(Schema5.String, Schema5.Boolean),
|
|
1292
|
+
dragging: Schema5.NullOr(Schema5.String),
|
|
1293
|
+
exporting: Schema5.Boolean,
|
|
1294
|
+
exportFailed: Schema5.Boolean,
|
|
1295
|
+
resizing: Schema5.NullOr(Schema5.Struct({
|
|
1296
|
+
id: Schema5.String,
|
|
1297
|
+
x: Schema5.Finite,
|
|
1298
|
+
width: Schema5.Finite,
|
|
1299
|
+
pointerId: Schema5.Int
|
|
1300
|
+
}).annotate({ identifier: "DataTableResizeSession" })),
|
|
1301
|
+
filterDraft: Schema5.NullOr(DataTableFilterDraftSchema),
|
|
1302
|
+
invalidFilter: Schema5.Boolean
|
|
1303
|
+
}).annotate({ identifier: "DataTableModel" }),
|
|
1304
|
+
message: DataTableMessage,
|
|
1305
|
+
events: DataTableEvents,
|
|
1306
|
+
restore: false
|
|
1307
|
+
};
|
|
1308
|
+
var available = (props) => props.status?.error === undefined && (!props.status?.loading || props.rowData.length > 0);
|
|
1309
|
+
var tableQuery = (props, model) => props.state ?? { ...model.query, sort: props.sort ?? model.query.sort };
|
|
1310
|
+
var tableFeatures = (props) => ({
|
|
1311
|
+
...props.features,
|
|
1312
|
+
search: props.features?.search ?? props.search ?? true,
|
|
1313
|
+
filtering: props.features?.filtering ?? props.columnFilters ?? true,
|
|
1314
|
+
sorting: props.features?.sorting ?? true,
|
|
1315
|
+
columnVisibility: props.features?.columnVisibility ?? true,
|
|
1316
|
+
pagination: props.features?.pagination ?? props.pagination
|
|
1317
|
+
});
|
|
1318
|
+
var tableSelectedRowIds = (props, model) => {
|
|
1319
|
+
const supplied = new Set(props.rowData.map(({ id }) => id));
|
|
1320
|
+
return [
|
|
1321
|
+
...new Set(props.selection?.selectedRowIds ?? model.selectedRowIds)
|
|
1322
|
+
].filter((id) => supplied.has(id));
|
|
1323
|
+
};
|
|
1324
|
+
var serverPageCorrection = (props, model) => {
|
|
1325
|
+
const pagination = tableFeatures(props).pagination;
|
|
1326
|
+
if (!pagination || pagination.mode !== "server")
|
|
1327
|
+
return;
|
|
1328
|
+
const query = tableQuery(props, model);
|
|
1329
|
+
const { page } = resolveTablePage(pagination.rowCount, query);
|
|
1330
|
+
if (query.page !== page)
|
|
1331
|
+
return { requested: query.page, page, size: query.pageSize };
|
|
1332
|
+
};
|
|
1333
|
+
var tablePreferencesKey = (pathname, columns, gallery) => `data-table:${pathname}:${columns.join(",")}:${gallery ? "gallery" : "table"}:ui`;
|
|
1334
|
+
var preferencesJson = Schema5.fromJsonString(DataTablePreferencesSchema);
|
|
1335
|
+
var decodePreferences = Schema5.decodeUnknownOption(preferencesJson);
|
|
1336
|
+
var encodePreferences = Schema5.encodeSync(preferencesJson);
|
|
1337
|
+
var readTablePreferences = (key, host = globalThis.window) => {
|
|
1338
|
+
try {
|
|
1339
|
+
return Option3.getOrNull(decodePreferences(host?.localStorage.getItem(key)));
|
|
1340
|
+
} catch {
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
var writeTablePreferences = (key, preferences, host = globalThis.window) => {
|
|
1345
|
+
try {
|
|
1346
|
+
host?.localStorage.setItem(key, encodePreferences(preferences));
|
|
1347
|
+
} catch {}
|
|
1348
|
+
};
|
|
1349
|
+
var tablePreferences = (model) => model.preferencesLoaded ? {
|
|
1350
|
+
columnVisibility: model.columnVisibility,
|
|
1351
|
+
columnSizing: model.columnSizing,
|
|
1352
|
+
grouping: model.grouping,
|
|
1353
|
+
view: model.view
|
|
1354
|
+
} : null;
|
|
1355
|
+
var tableVirtualization = (count, options, flat) => {
|
|
1356
|
+
if (!flat || (options === undefined ? count < 100 : !options))
|
|
1357
|
+
return;
|
|
1358
|
+
const config = typeof options === "object" ? options : undefined;
|
|
1359
|
+
const height = config?.height ?? 480;
|
|
1360
|
+
const itemSize = config?.estimateRowHeight ?? 64;
|
|
1361
|
+
const overscan = config?.overscan ?? 5;
|
|
1362
|
+
return {
|
|
1363
|
+
height,
|
|
1364
|
+
itemSize,
|
|
1365
|
+
overscan,
|
|
1366
|
+
initialCount: Math.min(count, Math.ceil(height / itemSize) + overscan),
|
|
1367
|
+
scroll: config?.scroll ?? "table"
|
|
1368
|
+
};
|
|
1369
|
+
};
|
|
1370
|
+
var tableRowActions = (row, siblings, reorder, labels) => {
|
|
1371
|
+
const index = siblings.findIndex(({ id }) => id === row.id);
|
|
1372
|
+
const actions = (row.actions ?? []).map((action) => ({
|
|
1373
|
+
...action,
|
|
1374
|
+
message: DataTableMessage.RowActionRequested({
|
|
1375
|
+
rowId: row.id,
|
|
1376
|
+
actionId: action.id
|
|
1377
|
+
})
|
|
1378
|
+
}));
|
|
1379
|
+
const moves = reorder && index >= 0 ? [
|
|
1380
|
+
{ target: siblings[index - 1], after: false, name: labels.moveUp },
|
|
1381
|
+
{ target: siblings[index + 1], after: true, name: labels.moveDown }
|
|
1382
|
+
].flatMap(({ target, after, name }) => target ? [
|
|
1383
|
+
{
|
|
1384
|
+
id: JSON.stringify(["move", after]),
|
|
1385
|
+
name,
|
|
1386
|
+
message: DataTableMessage.ReorderRequested({
|
|
1387
|
+
rowId: row.id,
|
|
1388
|
+
targetId: target.id,
|
|
1389
|
+
after
|
|
1390
|
+
})
|
|
1391
|
+
}
|
|
1392
|
+
] : []) : [];
|
|
1393
|
+
return [...moves, ...actions];
|
|
1394
|
+
};
|
|
1395
|
+
var tableColumnLimits = (column) => {
|
|
1396
|
+
const min = column.minWidth ?? 96;
|
|
1397
|
+
return { min, max: Math.max(min, column.maxWidth ?? 640) };
|
|
1398
|
+
};
|
|
1399
|
+
var clampTableWidth = (column, width = column.width ?? 208) => {
|
|
1400
|
+
const { min, max } = tableColumnLimits(column);
|
|
1401
|
+
return Math.min(max, Math.max(min, width));
|
|
1402
|
+
};
|
|
1403
|
+
var tableColumnWidth = (column, sizing) => clampTableWidth(column, sizing[column.id]);
|
|
1404
|
+
var tableLayoutWidth = (widths, utilityColumns) => widths.reduce((total, width) => total + width, utilityColumns * 40);
|
|
1405
|
+
var tableResizeStep = (key) => key === "ArrowLeft" ? -8 : key === "ArrowRight" ? 8 : 0;
|
|
1406
|
+
var activeTableGroups = (grouping, fields) => grouping.flatMap((id) => fields.find((field) => field.id === id) ?? []);
|
|
1407
|
+
var tableGrouping = (props, model) => activeTableGroups(model.grouping, props.features?.grouping?.fields ?? []);
|
|
1408
|
+
var canReorderTableRows = (props, model) => !!props.features?.reordering && !tableGrouping(props, model).length && !tableQuery(props, model).sort?.length;
|
|
1409
|
+
var partitionTableGroups = (rows, known, memberships) => {
|
|
1410
|
+
const groups = new Map(known.map((id) => [id, []]));
|
|
1411
|
+
for (const row of rows) {
|
|
1412
|
+
for (const id of new Set(memberships(row))) {
|
|
1413
|
+
const group = groups.get(id);
|
|
1414
|
+
if (group)
|
|
1415
|
+
group.push(row);
|
|
1416
|
+
else
|
|
1417
|
+
groups.set(id, [row]);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
return groups;
|
|
1421
|
+
};
|
|
1422
|
+
var tableGroupKey = (parent, fieldId, groupId) => `${parent ? `${parent}/` : ""}${encodeURIComponent(fieldId)}:${encodeURIComponent(groupId)}`;
|
|
1423
|
+
var reorderRows = ($, rowId, targetId, after) => {
|
|
1424
|
+
const rowIds = $.props.rowData.map(({ id }) => id);
|
|
1425
|
+
const next = $.evolve({ dragging: null });
|
|
1426
|
+
if (!available($.props) || !canReorderTableRows($.props, $.model) || rowId === targetId || !rowIds.includes(rowId) || !rowIds.includes(targetId))
|
|
1427
|
+
return next;
|
|
1428
|
+
const reordered = rowIds.filter((id) => id !== rowId);
|
|
1429
|
+
reordered.splice(reordered.indexOf(targetId) + Number(after), 0, rowId);
|
|
1430
|
+
return next.emit(DataTableEvents.RowsReordered({ rowIds: reordered }));
|
|
1431
|
+
};
|
|
1432
|
+
var moveGroup = ($, rowId, fieldId, groupId) => {
|
|
1433
|
+
const field = tableGrouping($.props, $.model).find(({ id }) => id === fieldId);
|
|
1434
|
+
const row = $.props.rowData.find(({ id }) => id === rowId);
|
|
1435
|
+
const next = $.evolve({ dragging: null });
|
|
1436
|
+
if (!available($.props) || !field?.movable || !row || row.groups?.[fieldId]?.includes(groupId))
|
|
1437
|
+
return next;
|
|
1438
|
+
if (!field.groups?.some(({ id }) => id === groupId) && !$.props.rowData.some((row) => row.groups?.[fieldId]?.includes(groupId)))
|
|
1439
|
+
return next;
|
|
1440
|
+
return next.emit(DataTableEvents.GroupMoveRequested({ rowId, fieldId, groupId }));
|
|
1441
|
+
};
|
|
1442
|
+
var changeQuery = ($, patch, ui = {}, legacy) => {
|
|
1443
|
+
const current = tableQuery($.props, $.model);
|
|
1444
|
+
const state = { ...current, ...patch };
|
|
1445
|
+
if (state.page === current.page && state.pageSize === current.pageSize && state.globalFilter === current.globalFilter && state.filters === current.filters && state.sort === current.sort)
|
|
1446
|
+
return $.evolve(ui);
|
|
1447
|
+
const step = $.evolve({
|
|
1448
|
+
...ui,
|
|
1449
|
+
query: $.props.state ? $.model.query : { ...state, sort: $.props.sort ? $.model.query.sort : state.sort }
|
|
1450
|
+
}).emit(DataTableEvents.StateChanged({ state }));
|
|
1451
|
+
return legacy ? step.emit(legacy) : step;
|
|
1452
|
+
};
|
|
1453
|
+
var tableFilterDraft = (id, current) => ({
|
|
1454
|
+
id,
|
|
1455
|
+
primary: current?.kind === "text" || current?.kind === "boolean" ? String(current.value) : current?.kind === "number" ? String(current.min ?? "") : current?.kind === "date" ? current.from ?? "" : "",
|
|
1456
|
+
secondary: current?.kind === "number" ? String(current.max ?? "") : current?.kind === "date" ? current.to ?? "" : "",
|
|
1457
|
+
operator: current?.kind === "text" ? current.operator : "contains",
|
|
1458
|
+
values: current?.kind === "values" ? current.values : []
|
|
1459
|
+
});
|
|
1460
|
+
var decodeFilter = Schema5.decodeUnknownOption(ColumnFilter);
|
|
1461
|
+
var decodeBound = Schema5.decodeOption(Schema5.FiniteFromString);
|
|
1462
|
+
var parseTableFilterDraft = (kind, {
|
|
1463
|
+
id,
|
|
1464
|
+
primary,
|
|
1465
|
+
secondary,
|
|
1466
|
+
operator,
|
|
1467
|
+
values
|
|
1468
|
+
}) => {
|
|
1469
|
+
switch (kind) {
|
|
1470
|
+
case "number": {
|
|
1471
|
+
const min = primary.trim() ? decodeBound(primary) : Option3.some(undefined);
|
|
1472
|
+
const max = secondary.trim() ? decodeBound(secondary) : Option3.some(undefined);
|
|
1473
|
+
return Option3.isNone(min) || Option3.isNone(max) ? Option3.none() : decodeFilter({ id, kind, min: min.value, max: max.value });
|
|
1474
|
+
}
|
|
1475
|
+
case "boolean":
|
|
1476
|
+
return decodeFilter({
|
|
1477
|
+
id,
|
|
1478
|
+
kind,
|
|
1479
|
+
value: primary === "true" ? true : primary === "false" ? false : undefined
|
|
1480
|
+
});
|
|
1481
|
+
case "values":
|
|
1482
|
+
return decodeFilter({ id, kind, values });
|
|
1483
|
+
case "date":
|
|
1484
|
+
return decodeFilter({
|
|
1485
|
+
id,
|
|
1486
|
+
kind,
|
|
1487
|
+
from: primary || undefined,
|
|
1488
|
+
to: secondary || undefined
|
|
1489
|
+
});
|
|
1490
|
+
case "text":
|
|
1491
|
+
return decodeFilter({ id, kind, operator, value: primary.trim() });
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
var changeColumnFilter = ($, id, filter, ui) => {
|
|
1495
|
+
const filters = (tableQuery($.props, $.model).filters ?? []).filter((current) => current.id !== id);
|
|
1496
|
+
if (filter)
|
|
1497
|
+
filters.push(filter);
|
|
1498
|
+
return changeQuery($, { filters: filters.length ? filters : undefined, page: 0 }, ui);
|
|
1499
|
+
};
|
|
1500
|
+
var projectDataTableRows = (source, query, {
|
|
1501
|
+
pagination,
|
|
1502
|
+
grouped,
|
|
1503
|
+
sortMode,
|
|
1504
|
+
search,
|
|
1505
|
+
filter,
|
|
1506
|
+
sort
|
|
1507
|
+
}) => {
|
|
1508
|
+
const server = pagination && pagination.mode === "server";
|
|
1509
|
+
const filtered = server ? source : filter(search(source, query.globalFilter ?? ""), query.filters ?? []);
|
|
1510
|
+
const ordered = !server && sortMode !== "server" && query.sort?.length ? sort(filtered, query.sort) : filtered;
|
|
1511
|
+
const { pageSize } = query;
|
|
1512
|
+
const totalRows = server ? pagination.rowCount : ordered.length;
|
|
1513
|
+
const { page, pageCount, start, end } = resolveTablePage(totalRows, query);
|
|
1514
|
+
const paginationVisible = !!pagination && (server || !grouped);
|
|
1515
|
+
const rows = paginationVisible && !server ? ordered.slice(start, end) : ordered;
|
|
1516
|
+
return {
|
|
1517
|
+
rows,
|
|
1518
|
+
filtered,
|
|
1519
|
+
ordered,
|
|
1520
|
+
pageSize,
|
|
1521
|
+
totalRows,
|
|
1522
|
+
pageCount,
|
|
1523
|
+
page,
|
|
1524
|
+
paginationVisible
|
|
1525
|
+
};
|
|
1526
|
+
};
|
|
1527
|
+
var dataTablePage = (props, model, locale) => {
|
|
1528
|
+
const pagination = tableFeatures(props).pagination;
|
|
1529
|
+
const columns = tableDataColumns(props.columnDefs);
|
|
1530
|
+
return {
|
|
1531
|
+
...projectDataTableRows(props.rowData, tableQuery(props, model), {
|
|
1532
|
+
pagination,
|
|
1533
|
+
grouped: tableGrouping(props, model).length > 0,
|
|
1534
|
+
sortMode: props.sortMode,
|
|
1535
|
+
search: (rows, value) => filterTableRows(rows, columns, value, locale),
|
|
1536
|
+
filter: (rows, filters) => filterTableColumns(rows, columns, filters),
|
|
1537
|
+
sort: (rows, sorting) => sortTableRows(rows, columns, sorting, locale)
|
|
1538
|
+
}),
|
|
1539
|
+
pageSizes: pagination && pagination.pageSizes || defaultPageSizes
|
|
1540
|
+
};
|
|
1541
|
+
};
|
|
1542
|
+
var encodeTableCsv = (headers, data) => Effect2.runSync(Stream.fromIterable([headers, ...data]).pipe(Stream.map((row) => row.map((value) => value == null ? "" : String(value))), Stream.pipeThroughChannel(Csv.encodeString({ newline: `
|
|
1543
|
+
` })), Stream.runCollect, Effect2.map((parts) => parts.join("").slice(0, -1))));
|
|
1544
|
+
var tableExportFilename = (name, extension) => name.includes(".") ? name.replace(/\.[^/.]+$/, `.${extension}`) : `${name}.${extension}`;
|
|
1545
|
+
var downloadTableBlob = (content, type, filename) => {
|
|
1546
|
+
const url = window.URL.createObjectURL(new Blob([content], { type }));
|
|
1547
|
+
const link = document.createElement("a");
|
|
1548
|
+
link.href = url;
|
|
1549
|
+
link.download = filename;
|
|
1550
|
+
document.body.appendChild(link);
|
|
1551
|
+
try {
|
|
1552
|
+
link.click();
|
|
1553
|
+
} finally {
|
|
1554
|
+
link.remove();
|
|
1555
|
+
requestAnimationFrame(() => window.URL.revokeObjectURL(url));
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
var tableExportValue = (column, row, locale) => {
|
|
1559
|
+
const value = row.cells[column.id];
|
|
1560
|
+
switch (column.type) {
|
|
1561
|
+
case "date":
|
|
1562
|
+
case "dateTime": {
|
|
1563
|
+
const date = resolveDate(value, column.type);
|
|
1564
|
+
return !date ? null : column.typeOptions?.exportFormat === "formatted" ? formatDateValue(date, column, locale) : dateIsoValue(date);
|
|
1565
|
+
}
|
|
1566
|
+
case "reference":
|
|
1567
|
+
return isTableReference(value) ? [value.label, value.description].filter(Boolean).join(" — ") : "";
|
|
1568
|
+
case "list":
|
|
1569
|
+
return isTableList(value) ? value.map(({ label }) => label).join(", ") : "";
|
|
1570
|
+
case "boolean":
|
|
1571
|
+
return !isTableBoolean(value) ? null : column.typeOptions?.exportFormat === "formatted" ? tableBooleanLabel(value, column.typeOptions) : value;
|
|
1572
|
+
case "number":
|
|
1573
|
+
return !isTableNumber(value) ? null : column.typeOptions?.exportFormat === "formatted" ? formatNumberValue(value, column.typeOptions, locale) : value;
|
|
1574
|
+
default:
|
|
1575
|
+
return columnValue(column, value);
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
var DownloadTable = Command.make("DataTable/Download", {
|
|
1579
|
+
args: {
|
|
1580
|
+
filename: Schema5.String,
|
|
1581
|
+
content: Schema5.Redacted(Schema5.String, { disallowJsonEncode: true }),
|
|
1582
|
+
type: Schema5.String
|
|
1583
|
+
}
|
|
1584
|
+
}, ({ filename, content, type }) => Effect2.try(() => downloadTableBlob(Redacted.value(content), type, filename)).pipe(Effect2.match({
|
|
1585
|
+
onSuccess: () => DataTableMessage.ExportFinished({ failed: false }),
|
|
1586
|
+
onFailure: () => DataTableMessage.ExportFinished({ failed: true })
|
|
1587
|
+
})));
|
|
1588
|
+
var update2 = Component2.define(dataTableOptions).update({
|
|
1589
|
+
ReferenceImageFailed: ($, { src }) => $.model.failedImages.includes(src) ? $.model : $.evolve({ failedImages: [...$.model.failedImages, src] }),
|
|
1590
|
+
RowActivated: ($, { rowId }) => $.props.rowActivation && available($.props) && $.props.rowData.some(({ id }) => id === rowId) ? $.emit(DataTableEvents.RowActivated({ rowId })) : $.model,
|
|
1591
|
+
PreferencesLoaded: ($, { preferences }) => $.model.preferencesLoaded ? $.model : $.evolve({
|
|
1592
|
+
preferencesLoaded: true,
|
|
1593
|
+
columnVisibility: {
|
|
1594
|
+
...$.model.columnVisibility,
|
|
1595
|
+
...preferences?.columnVisibility
|
|
1596
|
+
},
|
|
1597
|
+
columnSizing: preferences?.columnSizing ?? $.model.columnSizing,
|
|
1598
|
+
grouping: preferences?.grouping ?? $.model.grouping,
|
|
1599
|
+
view: $.props.features?.gallery ? preferences?.view ?? $.model.view : "table"
|
|
1600
|
+
}),
|
|
1601
|
+
ItemActionRequested: ($, request) => {
|
|
1602
|
+
const row = $.props.rowData.find(({ id }) => id === request.rowId);
|
|
1603
|
+
const column = $.props.columnDefs.find(({ id }) => id === request.columnId);
|
|
1604
|
+
const items = row?.cells[request.columnId];
|
|
1605
|
+
return available($.props) && column?.type === "list" && isTableList(items) && items.some(({ value }) => value === request.itemId) && column.itemActions?.some(({ id, disabled }) => id === request.actionId && !disabled) ? $.emit(DataTableEvents.ItemActionRequested(request)) : $.model;
|
|
1606
|
+
},
|
|
1607
|
+
ExportStarted: ($) => $.evolve({ exporting: true, exportFailed: false }),
|
|
1608
|
+
ExportFinished: ($, { failed }) => $.evolve({ exporting: false, exportFailed: failed }),
|
|
1609
|
+
BuiltInExportRequested: ($, { format, locale = $.props.locale ?? "en" }) => {
|
|
1610
|
+
const feature = $.props.features?.export;
|
|
1611
|
+
if (!feature || feature.pending || $.model.exporting || feature.builtIn === false || !available($.props))
|
|
1612
|
+
return $.model;
|
|
1613
|
+
const projection = dataTablePage($.props, $.model, locale);
|
|
1614
|
+
const rows = feature.scope === "currentPage" ? projection.rows : projection.ordered;
|
|
1615
|
+
if (!rows.length)
|
|
1616
|
+
return $.model;
|
|
1617
|
+
const columns = tableDataColumns($.props.columnDefs.filter(({ id, export: enabled }) => enabled !== false && $.model.columnVisibility[id] !== false)).filter(({ export: enabled }) => enabled !== false);
|
|
1618
|
+
const content = format === "csv" ? encodeTableCsv(columns.map(({ headerName }) => headerName), rows.map((row) => columns.map((column) => tableExportValue(column, row, locale)))) : JSON.stringify(rows.map((row) => Object.fromEntries(columns.map((column) => [
|
|
1619
|
+
column.id,
|
|
1620
|
+
tableExportValue(column, row, locale)
|
|
1621
|
+
]))), null, 2);
|
|
1622
|
+
return $.evolve({ menu: null, exporting: true, exportFailed: false }).run(DownloadTable.make({
|
|
1623
|
+
content: Redacted.make(content),
|
|
1624
|
+
filename: tableExportFilename(feature.baseName, format),
|
|
1625
|
+
type: format === "csv" ? "text/csv;charset=utf-8" : "application/json;charset=utf-8"
|
|
1626
|
+
}));
|
|
1627
|
+
},
|
|
1628
|
+
RefreshRequested: ($) => $.props.features?.refresh ? $.emit(DataTableEvents.RefreshRequested()) : $.model,
|
|
1629
|
+
ExportRequested: ($, { actionId }) => !$.props.features?.export?.pending && $.props.features?.export?.actions?.some(({ id, disabled }) => id === actionId && !disabled) ? $.emit(DataTableEvents.ExportRequested({ actionId })) : $.model,
|
|
1630
|
+
GroupActionRequested: ($, request) => available($.props) && $.props.features?.grouping?.fields.some(({ id, actions }) => id === request.fieldId && actions?.some(({ id, disabled }) => id === request.actionId && !disabled)) ? $.emit(DataTableEvents.GroupActionRequested(request)) : $.model,
|
|
1631
|
+
GroupMoveRequested: ($, { rowId, fieldId, groupId }) => moveGroup($, rowId, fieldId, groupId),
|
|
1632
|
+
ReorderRequested: ($, { rowId, targetId, after }) => reorderRows($, rowId, targetId, after),
|
|
1633
|
+
DragStarted: ($, { rowId }) => $.evolve({ dragging: rowId }),
|
|
1634
|
+
DragEnded: ($) => $.evolve({ dragging: null }),
|
|
1635
|
+
DragDropped: ($, { targetId }) => $.model.dragging === null ? $.model : reorderRows($, $.model.dragging, targetId, $.props.rowData.findIndex(({ id }) => id === $.model.dragging) < $.props.rowData.findIndex(({ id }) => id === targetId)),
|
|
1636
|
+
GroupDropped: ($, { fieldId, groupId }) => $.model.dragging === null ? $.model : moveGroup($, $.model.dragging, fieldId, groupId),
|
|
1637
|
+
ViewPicked: ($, { view }) => view === "table" || $.props.features?.gallery ? $.evolve({ view, menu: null }) : $.model,
|
|
1638
|
+
GroupingToggled: ($, { fieldId }) => $.props.features?.grouping?.fields.some(({ id }) => id === fieldId) ? $.evolve({
|
|
1639
|
+
grouping: updateSelectedRows($.model.grouping, [fieldId], !$.model.grouping.includes(fieldId))
|
|
1640
|
+
}) : $.model,
|
|
1641
|
+
GroupToggled: ($, { key }) => $.evolve({
|
|
1642
|
+
collapsedGroups: {
|
|
1643
|
+
...$.model.collapsedGroups,
|
|
1644
|
+
[key]: !$.model.collapsedGroups[key]
|
|
1645
|
+
}
|
|
1646
|
+
}),
|
|
1647
|
+
ColumnResized: ($, { id, delta }) => {
|
|
1648
|
+
const column = $.props.columnDefs.find((column) => column.id === id);
|
|
1649
|
+
if (!column || column.resizable === false)
|
|
1650
|
+
return $.model;
|
|
1651
|
+
const sizing = {
|
|
1652
|
+
...$.model.columnSizing,
|
|
1653
|
+
[id]: tableColumnWidth(column, $.model.columnSizing) + delta
|
|
1654
|
+
};
|
|
1655
|
+
return $.evolve({
|
|
1656
|
+
columnSizing: { ...sizing, [id]: tableColumnWidth(column, sizing) }
|
|
1657
|
+
});
|
|
1658
|
+
},
|
|
1659
|
+
ColumnResizeReset: ($, { id }) => {
|
|
1660
|
+
const column = $.props.columnDefs.find((column) => column.id === id);
|
|
1661
|
+
if (!column || column.resizable === false)
|
|
1662
|
+
return $.model;
|
|
1663
|
+
return $.evolve({
|
|
1664
|
+
columnSizing: {
|
|
1665
|
+
...$.model.columnSizing,
|
|
1666
|
+
[id]: clampTableWidth(column)
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
},
|
|
1670
|
+
ResizeStarted: ($, { id, x, pointerId }) => {
|
|
1671
|
+
const column = $.props.columnDefs.find((column) => column.id === id);
|
|
1672
|
+
return column && column.resizable !== false ? $.evolve({
|
|
1673
|
+
resizing: {
|
|
1674
|
+
id,
|
|
1675
|
+
x,
|
|
1676
|
+
pointerId,
|
|
1677
|
+
width: tableColumnWidth(column, $.model.columnSizing)
|
|
1678
|
+
}
|
|
1679
|
+
}) : $.model;
|
|
1680
|
+
},
|
|
1681
|
+
ResizeMoved: ($, { x, pointerId }) => {
|
|
1682
|
+
const resize = $.model.resizing;
|
|
1683
|
+
const column = resize && $.props.columnDefs.find(({ id }) => id === resize.id);
|
|
1684
|
+
if (!resize || resize.pointerId !== pointerId || !column || column.resizable === false)
|
|
1685
|
+
return $.model;
|
|
1686
|
+
return $.evolve({
|
|
1687
|
+
columnSizing: {
|
|
1688
|
+
...$.model.columnSizing,
|
|
1689
|
+
[resize.id]: tableColumnWidth(column, {
|
|
1690
|
+
[resize.id]: resize.width + x - resize.x
|
|
1691
|
+
})
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
},
|
|
1695
|
+
ResizeEnded: ($, { pointerId }) => $.model.resizing?.pointerId === pointerId ? $.evolve({ resizing: null }) : $.model,
|
|
1696
|
+
ColumnFiltersCleared: ($, { id }) => {
|
|
1697
|
+
const column = $.props.columnDefs.find((column) => column.id === id);
|
|
1698
|
+
if (!column || !tableFeatures($.props).filtering)
|
|
1699
|
+
return $.model;
|
|
1700
|
+
const owned = new Set([
|
|
1701
|
+
id,
|
|
1702
|
+
...tableDataColumns([column]).map(({ id }) => id)
|
|
1703
|
+
]);
|
|
1704
|
+
const filters = tableQuery($.props, $.model).filters?.filter(({ id }) => !owned.has(id));
|
|
1705
|
+
return changeQuery($, { filters: filters?.length ? filters : undefined, page: 0 }, { filterDraft: null, invalidFilter: false });
|
|
1706
|
+
},
|
|
1707
|
+
ColumnSortCleared: ($, { id }) => {
|
|
1708
|
+
const column = $.props.columnDefs.find((column) => column.id === id);
|
|
1709
|
+
if (!column || !tableFeatures($.props).sorting)
|
|
1710
|
+
return $.model;
|
|
1711
|
+
const owned = new Set([
|
|
1712
|
+
id,
|
|
1713
|
+
...tableDataColumns([column]).map(({ id }) => id)
|
|
1714
|
+
]);
|
|
1715
|
+
const sort = (tableQuery($.props, $.model).sort ?? []).filter(({ id }) => !owned.has(id));
|
|
1716
|
+
return changeQuery($, { sort }, {}, DataTableEvents.SortChanged({ sort }));
|
|
1717
|
+
},
|
|
1718
|
+
MenuOpened: ($, { key }) => $.evolve({ menu: key, submenu: null, menuQuery: "" }),
|
|
1719
|
+
MenuQueryChanged: ($, { key, query }) => $.model.menu === key ? $.evolve({ menuQuery: query }) : $.model,
|
|
1720
|
+
MenuClosed: ($, { key }) => $.model.menu === key ? $.evolve({ menu: null, submenu: null }) : $.model,
|
|
1721
|
+
SubmenuOpened: ($, { key, filterColumnId }) => $.evolve({
|
|
1722
|
+
submenu: key,
|
|
1723
|
+
menuQuery: "",
|
|
1724
|
+
...filterColumnId === undefined ? {} : {
|
|
1725
|
+
filterDraft: tableFilterDraft(filterColumnId, tableQuery($.props, $.model).filters?.find(({ id }) => id === filterColumnId)),
|
|
1726
|
+
invalidFilter: false
|
|
1727
|
+
}
|
|
1728
|
+
}),
|
|
1729
|
+
SubmenuClosed: ($, { key }) => $.model.submenu === key ? $.evolve({ submenu: null }) : $.model,
|
|
1730
|
+
SearchChanged: ($, { value }) => tableFeatures($.props).search ? changeQuery($, { globalFilter: value || undefined, page: 0 }, { menu: null }) : $.model,
|
|
1731
|
+
FilterInputChanged: ($, { field, value }) => {
|
|
1732
|
+
const draft = $.model.filterDraft;
|
|
1733
|
+
return draft ? $.evolve({
|
|
1734
|
+
filterDraft: { ...draft, [field]: value },
|
|
1735
|
+
invalidFilter: false
|
|
1736
|
+
}) : $.model;
|
|
1737
|
+
},
|
|
1738
|
+
FilterOperatorChanged: ($, { operator }) => {
|
|
1739
|
+
const draft = $.model.filterDraft;
|
|
1740
|
+
return draft ? $.evolve({
|
|
1741
|
+
filterDraft: { ...draft, operator },
|
|
1742
|
+
invalidFilter: false
|
|
1743
|
+
}) : $.model;
|
|
1744
|
+
},
|
|
1745
|
+
FilterValueToggled: ($, { value, checked }) => {
|
|
1746
|
+
const draft = $.model.filterDraft;
|
|
1747
|
+
return draft ? $.evolve({
|
|
1748
|
+
filterDraft: {
|
|
1749
|
+
...draft,
|
|
1750
|
+
values: updateSelectedRows(draft.values, [value], checked)
|
|
1751
|
+
},
|
|
1752
|
+
invalidFilter: false
|
|
1753
|
+
}) : $.model;
|
|
1754
|
+
},
|
|
1755
|
+
FilterApplied: ($) => {
|
|
1756
|
+
const draft = $.model.filterDraft;
|
|
1757
|
+
if (!tableFeatures($.props).filtering || !draft)
|
|
1758
|
+
return $.model;
|
|
1759
|
+
const column = tableDataColumns($.props.columnDefs).find(({ id, filterable }) => id === draft.id && filterable !== false);
|
|
1760
|
+
if (!column)
|
|
1761
|
+
return $.model;
|
|
1762
|
+
const decoded = parseTableFilterDraft(tableFilterKind(column), draft);
|
|
1763
|
+
return Option3.isNone(decoded) ? $.evolve({ invalidFilter: true }) : changeColumnFilter($, draft.id, decoded.value, {
|
|
1764
|
+
invalidFilter: false
|
|
1765
|
+
});
|
|
1766
|
+
},
|
|
1767
|
+
FilterCleared: ($) => {
|
|
1768
|
+
const draft = $.model.filterDraft;
|
|
1769
|
+
if (!draft)
|
|
1770
|
+
return $.model;
|
|
1771
|
+
return changeColumnFilter($, draft.id, null, {
|
|
1772
|
+
filterDraft: tableFilterDraft(draft.id),
|
|
1773
|
+
invalidFilter: false
|
|
1774
|
+
});
|
|
1775
|
+
},
|
|
1776
|
+
ColumnFilterChanged: ($, { id, filter }) => {
|
|
1777
|
+
if (!tableFeatures($.props).filtering || !tableDataColumns($.props.columnDefs).some((column) => column.id === id && column.filterable !== false) || filter && filter.id !== id)
|
|
1778
|
+
return $.model;
|
|
1779
|
+
return changeColumnFilter($, id, filter);
|
|
1780
|
+
},
|
|
1781
|
+
FiltersCleared: ($) => changeQuery($, { filters: undefined, page: 0 }, {
|
|
1782
|
+
filterDraft: null,
|
|
1783
|
+
invalidFilter: false
|
|
1784
|
+
}),
|
|
1785
|
+
PageRequested: ($, { page }) => tableFeatures($.props).pagination && page >= 0 ? changeQuery($, { page }, { menu: null }) : $.model,
|
|
1786
|
+
ServerPageInvalidated: ($) => {
|
|
1787
|
+
const correction = serverPageCorrection($.props, $.model);
|
|
1788
|
+
return correction ? changeQuery($, { page: correction.page }) : $.model;
|
|
1789
|
+
},
|
|
1790
|
+
PageSizeRequested: ($, { pageSize }) => {
|
|
1791
|
+
const pagination = tableFeatures($.props).pagination;
|
|
1792
|
+
return pagination && (pagination.pageSizes ?? defaultPageSizes).includes(pageSize) ? changeQuery($, { pageSize, page: 0 }, { menu: null }) : $.model;
|
|
1793
|
+
},
|
|
1794
|
+
SortRequested: ($, { columnId, direction }) => {
|
|
1795
|
+
if (!tableFeatures($.props).sorting || !tableDataColumns($.props.columnDefs).some(({ id, sortable }) => id === columnId && sortable !== false))
|
|
1796
|
+
return $.model;
|
|
1797
|
+
const sort = direction === null ? (tableQuery($.props, $.model).sort ?? []).filter(({ id }) => id !== columnId) : [{ id: columnId, direction }];
|
|
1798
|
+
return changeQuery($, { sort: sort.length ? sort : undefined, page: 0 }, {}, DataTableEvents.SortChanged({ sort }));
|
|
1799
|
+
},
|
|
1800
|
+
ColumnVisibilityChanged: ($, { id, visible }) => tableFeatures($.props).columnVisibility && $.props.columnDefs.some((column) => column.id === id && column.hideable !== false) ? $.evolve({
|
|
1801
|
+
columnVisibility: { ...$.model.columnVisibility, [id]: visible }
|
|
1802
|
+
}) : $.model,
|
|
1803
|
+
SelectionRequested: ($, { rowIds, checked }) => {
|
|
1804
|
+
if (!available($.props) || !$.props.selection)
|
|
1805
|
+
return $.model;
|
|
1806
|
+
const requested = new Set(rowIds);
|
|
1807
|
+
const targets = $.props.rowData.filter((row) => row.selectable !== false && requested.has(row.id)).map(({ id }) => id);
|
|
1808
|
+
if (targets.length === 0)
|
|
1809
|
+
return $.model;
|
|
1810
|
+
const controlled = $.props.selection.selectedRowIds;
|
|
1811
|
+
const selectedRowIds = updateSelectedRows(controlled ?? $.model.selectedRowIds, targets, checked);
|
|
1812
|
+
return $.evolve(controlled ? {} : { selectedRowIds }).emit(DataTableEvents.SelectionChanged({ selectedRowIds }));
|
|
1813
|
+
},
|
|
1814
|
+
CellEditRequested: ($, { rowId, columnId, edit }) => {
|
|
1815
|
+
if (!available($.props))
|
|
1816
|
+
return $.model;
|
|
1817
|
+
const row = $.props.rowData.find(({ id }) => id === rowId);
|
|
1818
|
+
const column = $.props.columnDefs.find(({ id }) => id === columnId);
|
|
1819
|
+
if (!row || !column || row.disabledColumnIds?.includes(columnId))
|
|
1820
|
+
return $.model;
|
|
1821
|
+
const value = row.cells[columnId];
|
|
1822
|
+
if (edit._tag === "SetBoolean") {
|
|
1823
|
+
if (column.type !== "boolean" || !column.editable || !isTableBoolean(value) || edit.value === value)
|
|
1824
|
+
return $.model;
|
|
1825
|
+
} else {
|
|
1826
|
+
if (column.type !== "list")
|
|
1827
|
+
return $.model;
|
|
1828
|
+
const items = isTableList(value) ? value : [];
|
|
1829
|
+
const contains = items.some(({ value }) => value === edit.itemId);
|
|
1830
|
+
if (edit._tag === "AddItem") {
|
|
1831
|
+
if (contains || !column.options?.some(({ value }) => value === edit.itemId))
|
|
1832
|
+
return $.model;
|
|
1833
|
+
} else if (!contains || !column.allowRemove)
|
|
1834
|
+
return $.model;
|
|
1835
|
+
}
|
|
1836
|
+
return $.emit(DataTableEvents.CellEditRequested({ rowId, columnId, edit }));
|
|
1837
|
+
},
|
|
1838
|
+
RowActionRequested: ($, { rowId, actionId }) => {
|
|
1839
|
+
const row = $.props.rowData.find(({ id }) => id === rowId);
|
|
1840
|
+
if (!available($.props) || !row?.actions?.some(({ id, disabled }) => id === actionId && !disabled))
|
|
1841
|
+
return $.model;
|
|
1842
|
+
return $.emit(DataTableEvents.RowActionRequested({ rowId, actionId }));
|
|
1843
|
+
},
|
|
1844
|
+
BulkActionRequested: ($, { actionId }) => {
|
|
1845
|
+
const selection = $.props.selection;
|
|
1846
|
+
if (!available($.props) || !selection?.bulkActions?.some(({ id, disabled }) => id === actionId && !disabled))
|
|
1847
|
+
return $.model;
|
|
1848
|
+
const rowIds = tableSelectedRowIds($.props, $.model);
|
|
1849
|
+
return rowIds.length > 0 ? $.emit(DataTableEvents.BulkActionRequested({ actionId, rowIds })) : $.model;
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
var dataTableBehaviours = {
|
|
1853
|
+
subscriptions: ({
|
|
1854
|
+
props,
|
|
1855
|
+
model
|
|
1856
|
+
}) => {
|
|
1857
|
+
const correction = serverPageCorrection(props, model);
|
|
1858
|
+
return correction ? [
|
|
1859
|
+
Subscription.make("reconcile-server-page", [correction.requested, correction.page, correction.size], () => Stream.make(DataTableMessage.ServerPageInvalidated()))
|
|
1860
|
+
] : [];
|
|
1861
|
+
},
|
|
1862
|
+
init: ({ props }) => ({
|
|
1863
|
+
menu: null,
|
|
1864
|
+
submenu: null,
|
|
1865
|
+
menuQuery: "",
|
|
1866
|
+
failedImages: [],
|
|
1867
|
+
selectedRowIds: [],
|
|
1868
|
+
query: {
|
|
1869
|
+
globalFilter: props.initialState?.globalFilter,
|
|
1870
|
+
filters: props.initialState?.filters,
|
|
1871
|
+
sort: props.initialState?.sort,
|
|
1872
|
+
page: props.initialState?.page ?? 0,
|
|
1873
|
+
pageSize: props.initialState?.pageSize ?? (props.pagination?.mode === undefined ? props.pagination?.pageSizes?.[0] : undefined) ?? DEFAULT_PAGE_SIZE
|
|
1874
|
+
},
|
|
1875
|
+
columnVisibility: props.initialState?.columnVisibility ?? {},
|
|
1876
|
+
preferencesLoaded: false,
|
|
1877
|
+
columnSizing: {},
|
|
1878
|
+
view: props.initialState?.view ?? "table",
|
|
1879
|
+
grouping: props.features?.grouping?.initial ?? [],
|
|
1880
|
+
collapsedGroups: {},
|
|
1881
|
+
dragging: null,
|
|
1882
|
+
exporting: false,
|
|
1883
|
+
exportFailed: false,
|
|
1884
|
+
resizing: null,
|
|
1885
|
+
filterDraft: null,
|
|
1886
|
+
invalidFilter: false
|
|
1887
|
+
}),
|
|
1888
|
+
update: update2
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
// ../../src/components/data-table/html.ts
|
|
1892
|
+
var keyOf = (...parts) => JSON.stringify(parts);
|
|
1893
|
+
var cellClass = "px-3 py-2 align-middle";
|
|
1894
|
+
var badgeVariants = {
|
|
1895
|
+
...tableBadgeTones,
|
|
1896
|
+
default: "bg-primary text-primary-foreground",
|
|
1897
|
+
secondary: "bg-secondary text-secondary-foreground",
|
|
1898
|
+
outline: "border-border text-foreground",
|
|
1899
|
+
destructive: "bg-destructive/10 text-destructive dark:bg-destructive/20"
|
|
1900
|
+
};
|
|
1901
|
+
var badgeClass = "inline-flex items-center gap-1 rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap";
|
|
1902
|
+
var isTextFilterOperator = Schema6.is(TextFilterOperator);
|
|
1903
|
+
var RowDrag = "application/x-krakstack-table-row";
|
|
1904
|
+
var PersistPreferences = Mount.makeStream("DataTable/PersistPreferences", {
|
|
1905
|
+
args: {
|
|
1906
|
+
columns: Schema6.Array(Schema6.String),
|
|
1907
|
+
gallery: Schema6.Boolean,
|
|
1908
|
+
preferences: Schema6.NullOr(DataTablePreferencesSchema)
|
|
1909
|
+
}
|
|
1910
|
+
}, (element, initial, changes) => Stream2.make(initial).pipe(Stream2.concat(changes), Stream2.map(({ columns, gallery, preferences }) => {
|
|
1911
|
+
const host = element.ownerDocument.defaultView;
|
|
1912
|
+
const storageKey = tablePreferencesKey(host?.location.pathname ?? "/", columns, gallery);
|
|
1913
|
+
if (preferences) {
|
|
1914
|
+
writeTablePreferences(storageKey, preferences, host);
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
return DataTableMessage.PreferencesLoaded({
|
|
1918
|
+
preferences: readTablePreferences(storageKey, host)
|
|
1919
|
+
});
|
|
1920
|
+
}), Stream2.filter((message) => message !== undefined)));
|
|
1921
|
+
var FilterSelectMessage = UiSchema3.TaggedEnum({
|
|
1922
|
+
OpenChanged: { open: Schema6.Boolean },
|
|
1923
|
+
Picked: { value: Schema6.String }
|
|
1924
|
+
});
|
|
1925
|
+
var FilterSelectEvent = UiSchema3.TaggedEnum({
|
|
1926
|
+
Changed: { value: Schema6.String }
|
|
1927
|
+
});
|
|
1928
|
+
var FilterSelect = Html2.component({
|
|
1929
|
+
name: "DataTableFilterSelect",
|
|
1930
|
+
props: Schema6.Struct({
|
|
1931
|
+
label: Schema6.String,
|
|
1932
|
+
value: Schema6.String,
|
|
1933
|
+
items: Schema6.Array(Schema6.Struct({ value: Schema6.String, label: Schema6.String }))
|
|
1934
|
+
}),
|
|
1935
|
+
model: Schema6.Boolean,
|
|
1936
|
+
message: FilterSelectMessage,
|
|
1937
|
+
events: FilterSelectEvent,
|
|
1938
|
+
restore: false
|
|
1939
|
+
}).make({
|
|
1940
|
+
init: () => false,
|
|
1941
|
+
update: {
|
|
1942
|
+
OpenChanged: ($, { open }) => $.set(open),
|
|
1943
|
+
Picked: ($, { value }) => $.set(false).emit(FilterSelectEvent.Changed({ value }))
|
|
1944
|
+
},
|
|
1945
|
+
view: (h, open) => Select2(h, {
|
|
1946
|
+
props: {
|
|
1947
|
+
open,
|
|
1948
|
+
items: h.props.items,
|
|
1949
|
+
value: h.props.value || null,
|
|
1950
|
+
placeholder: "—",
|
|
1951
|
+
alignItemWithTrigger: false
|
|
1952
|
+
},
|
|
1953
|
+
onEmit: {
|
|
1954
|
+
RequestedOpen: () => FilterSelectMessage.OpenChanged({ open: true }),
|
|
1955
|
+
RequestedClose: () => FilterSelectMessage.OpenChanged({ open: false }),
|
|
1956
|
+
Picked: ({ value }) => {
|
|
1957
|
+
const item = h.props.items.find((item) => item.value === value);
|
|
1958
|
+
return item && FilterSelectMessage.Picked({ value: item.value });
|
|
1959
|
+
},
|
|
1960
|
+
Settled: () => {
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
},
|
|
1964
|
+
view: (select) => h.div.class("grid gap-1").children(SelectLabel2(h, select, { class: "mb-0" }).children(h.props.label), SelectTrigger2(h, select, {
|
|
1965
|
+
size: "sm",
|
|
1966
|
+
class: "w-full min-w-0"
|
|
1967
|
+
}).children(SelectValue2(h, select), SelectIcon2(h, select)), SelectPositioner2(h, select).children(SelectPopup2(h, select, { size: "sm" }).children(SelectList2(h, select).children(h.props.items.map(({ value, label }) => SelectItem2(h, select, { value }).children(SelectItemText2(h, select).children(label), SelectItemIndicator2(h, select, { value })))))))
|
|
1968
|
+
})
|
|
1969
|
+
});
|
|
1970
|
+
var DataTable = Html2.component({
|
|
1971
|
+
...dataTableOptions,
|
|
1972
|
+
reads: { localeConfig: krakstackLocaleRead2 }
|
|
1973
|
+
}).make({
|
|
1974
|
+
...dataTableBehaviours,
|
|
1975
|
+
view: (h, model) => {
|
|
1976
|
+
const tableClasses = resolveTableClasses(h.props.classes);
|
|
1977
|
+
const props = h.props;
|
|
1978
|
+
const locale = props.locale ?? h.reads.localeConfig?.locale ?? "en";
|
|
1979
|
+
const copy = htmlDataTableMessages(locale, props.messages);
|
|
1980
|
+
const query = tableQuery(props, model);
|
|
1981
|
+
const features = tableFeatures(props);
|
|
1982
|
+
const columns = props.columnDefs.filter(({ id }) => model.columnVisibility[id] !== false);
|
|
1983
|
+
const dataColumns = tableDataColumns(props.columnDefs);
|
|
1984
|
+
const sortableColumns = dataColumns.filter(({ sortable }) => sortable !== false);
|
|
1985
|
+
const hideableColumns = props.columnDefs.filter(({ hideable }) => hideable !== false);
|
|
1986
|
+
const sort = query.sort ?? [];
|
|
1987
|
+
const selection = props.selection;
|
|
1988
|
+
const selected = new Set(tableSelectedRowIds(props, model));
|
|
1989
|
+
const selectedCount = selected.size;
|
|
1990
|
+
const {
|
|
1991
|
+
rows,
|
|
1992
|
+
page,
|
|
1993
|
+
pageSize,
|
|
1994
|
+
pageSizes,
|
|
1995
|
+
pageCount,
|
|
1996
|
+
totalRows,
|
|
1997
|
+
paginationVisible
|
|
1998
|
+
} = dataTablePage(props, model, locale);
|
|
1999
|
+
const grouping = tableGrouping(props, model);
|
|
2000
|
+
const gallery = model.view === "gallery" && features.gallery;
|
|
2001
|
+
const reorder = canReorderTableRows(props, model);
|
|
2002
|
+
const draggable = reorder || grouping.some(({ movable }) => movable);
|
|
2003
|
+
const dropOnRow = (rowId, group) => group ? DataTableMessage.GroupDropped(group) : reorder ? DataTableMessage.DragDropped({ targetId: rowId }) : undefined;
|
|
2004
|
+
const rowActions = reorder || props.rowData.some(({ actions }) => actions?.length);
|
|
2005
|
+
const span = Math.max(1, columns.length + Number(!!selection) + Number(rowActions) + Number(draggable));
|
|
2006
|
+
const virtualization = features.virtualization;
|
|
2007
|
+
const fillHeight = virtualization && virtualization !== true && virtualization.scroll === "internal";
|
|
2008
|
+
const virtual = tableVirtualization(rows.length, virtualization, !grouping.length && !gallery && !features.reordering && props.status?.error === undefined && rows.length > 0);
|
|
2009
|
+
const ids = rows.filter(({ selectable }) => selectable !== false).map(({ id }) => id);
|
|
2010
|
+
const selectedHere = ids.filter((id) => selected.has(id)).length;
|
|
2011
|
+
const status = props.status;
|
|
2012
|
+
const blocked = status?.error !== undefined || status?.loading === true && rows.length === 0;
|
|
2013
|
+
const widths = columns.map((column) => tableColumnWidth(column, model.columnSizing));
|
|
2014
|
+
const layoutWidth = tableLayoutWidth(widths, Number(!!selection) + Number(rowActions) + Number(draggable));
|
|
2015
|
+
const icons = {
|
|
2016
|
+
asc: ArrowUp,
|
|
2017
|
+
desc: ArrowDown,
|
|
2018
|
+
clear: X,
|
|
2019
|
+
filter: ListFilter,
|
|
2020
|
+
hide: EyeOff,
|
|
2021
|
+
sort: ChevronsUpDown,
|
|
2022
|
+
columns: Settings2,
|
|
2023
|
+
refresh: RefreshCw,
|
|
2024
|
+
table: Rows3,
|
|
2025
|
+
gallery: LayoutGrid,
|
|
2026
|
+
export: Download,
|
|
2027
|
+
csv: FileText,
|
|
2028
|
+
json: FileJson
|
|
2029
|
+
};
|
|
2030
|
+
const indicator = (icon) => icon ? icons[icon](h, { size: 16, className: "shrink-0" }) : undefined;
|
|
2031
|
+
const menu = (key, label, accessibleLabel, items, inBar = false, searchLabel, pending = false, presentation) => Menu(h, {
|
|
2032
|
+
key,
|
|
2033
|
+
props: {
|
|
2034
|
+
disabled: pending,
|
|
2035
|
+
open: model.menu === key,
|
|
2036
|
+
query: searchLabel ? model.menu === key ? model.menuQuery : "" : undefined,
|
|
2037
|
+
filter: searchLabel ? "contains" : undefined,
|
|
2038
|
+
items: items.map(({ id, name, disabled, checked }) => ({
|
|
2039
|
+
value: id,
|
|
2040
|
+
label: name,
|
|
2041
|
+
disabled,
|
|
2042
|
+
checked
|
|
2043
|
+
})),
|
|
2044
|
+
modal: false,
|
|
2045
|
+
align: presentation === "actions" || presentation && "selectedCount" in presentation ? "end" : "start",
|
|
2046
|
+
sideOffset: 4,
|
|
2047
|
+
locale
|
|
2048
|
+
},
|
|
2049
|
+
onEmit: {
|
|
2050
|
+
RequestedOpen: () => DataTableMessage.MenuOpened({ key }),
|
|
2051
|
+
RequestedClose: () => DataTableMessage.MenuClosed({ key }),
|
|
2052
|
+
Picked: ({ value }) => items.find(({ id, disabled }) => id === value && !disabled)?.message,
|
|
2053
|
+
Highlighted: () => {
|
|
2054
|
+
return;
|
|
2055
|
+
},
|
|
2056
|
+
RequestedQuery: ({ query }) => searchLabel ? DataTableMessage.MenuQueryChanged({ key, query }) : undefined,
|
|
2057
|
+
Settled: () => {
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
},
|
|
2061
|
+
view: (menu) => {
|
|
2062
|
+
const relationship = presentation && presentation !== "actions" && "relationship" in presentation;
|
|
2063
|
+
const showTitle = relationship || presentation === "actions" || presentation && "selectedCount" in presentation;
|
|
2064
|
+
return h.div.attr("data-slot", relationship ? "data-table-list-cell" : undefined).class(relationship ? tableClasses.relationshipCell : "").children((inBar ? MenubarTrigger(h, menu, accessibleLabel, presentation && presentation !== "actions" && "selectedCount" in presentation ? cn(tableClasses.selectedTrigger, "data-[popup-open]:bg-primary/90 data-[popup-open]:text-primary-foreground") : undefined) : menu.trigger({
|
|
2065
|
+
element: h.button.class(cn(buttonVariants({
|
|
2066
|
+
variant: "ghost",
|
|
2067
|
+
size: presentation === "actions" ? "icon" : "sm"
|
|
2068
|
+
}), presentation === "actions" && tableClasses.actionTrigger, presentation && presentation !== "actions" && "filtered" in presentation && tableClasses.headerTrigger, presentation && presentation !== "actions" && "relationship" in presentation && tableClasses.relationshipTrigger)).attr("aria-label", accessibleLabel)
|
|
2069
|
+
})).attr("aria-busy", pending ? "true" : undefined).attr("aria-description", presentation && presentation !== "actions" && "toolbarIcon" in presentation && presentation.filterCount ? `${copy.filters}: ${presentation.filterCount}` : presentation && presentation !== "actions" && ("filtered" in presentation) && presentation.filtered ? `${copy.filters}: ${presentation.filtered}` : undefined).children(presentation === "actions" ? Ellipsis(h, { size: 16 }) : presentation && ("selectedCount" in presentation) ? [
|
|
2070
|
+
copy.selected,
|
|
2071
|
+
h.span.class(tableClasses.count).children(String(presentation.selectedCount)),
|
|
2072
|
+
ChevronDown(h, { size: 16 })
|
|
2073
|
+
] : presentation && ("relationship" in presentation) ? [
|
|
2074
|
+
presentation.relationship,
|
|
2075
|
+
ChevronDown(h, { size: 16, className: "shrink-0" })
|
|
2076
|
+
] : presentation && ("toolbarIcon" in presentation) ? [
|
|
2077
|
+
indicator(presentation.toolbarIcon),
|
|
2078
|
+
label,
|
|
2079
|
+
!!presentation.filterCount && h.span.attr("data-slot", "badge").class(tableClasses.count).children(String(presentation.filterCount))
|
|
2080
|
+
] : presentation ? [
|
|
2081
|
+
h.span.class("truncate").children(label),
|
|
2082
|
+
presentation.filtered > 0 && indicator("filter"),
|
|
2083
|
+
indicator(presentation.sort)
|
|
2084
|
+
] : label), MenuPositioner(h, menu).children(MenuPopup(h, menu, {
|
|
2085
|
+
class: presentation === "actions" || presentation && "selectedCount" in presentation ? "w-max min-w-36" : presentation && ("filtered" in presentation) ? "w-48 min-w-0" : undefined
|
|
2086
|
+
}).children(showTitle && h.div.class("px-2 py-1.5 text-xs font-medium text-muted-foreground").children(label), showTitle && MenuSeparator(h, menu), searchLabel && MenuInput(h, menu, { placeholder: searchLabel }), searchLabel && MenuEmpty(h, menu)?.children(copy.empty), menu.list(h.div.class("outline-none")).children(items.map(({
|
|
2087
|
+
id,
|
|
2088
|
+
name,
|
|
2089
|
+
variant,
|
|
2090
|
+
checked,
|
|
2091
|
+
radio,
|
|
2092
|
+
children,
|
|
2093
|
+
filterEditor,
|
|
2094
|
+
filterColumnId,
|
|
2095
|
+
childSearch,
|
|
2096
|
+
icon,
|
|
2097
|
+
separatorBefore
|
|
2098
|
+
}) => {
|
|
2099
|
+
if (children || filterEditor) {
|
|
2100
|
+
const subitems = children ?? [];
|
|
2101
|
+
const subkey = keyOf(key, id);
|
|
2102
|
+
return Menu(h, {
|
|
2103
|
+
key: subkey,
|
|
2104
|
+
props: {
|
|
2105
|
+
parentItem: id,
|
|
2106
|
+
query: childSearch ? model.menuQuery : undefined,
|
|
2107
|
+
filter: childSearch ? "contains" : undefined,
|
|
2108
|
+
open: model.menu === key && model.submenu === subkey,
|
|
2109
|
+
items: subitems.map(({ id, name, disabled, checked }) => ({
|
|
2110
|
+
value: id,
|
|
2111
|
+
label: name,
|
|
2112
|
+
disabled,
|
|
2113
|
+
checked
|
|
2114
|
+
})),
|
|
2115
|
+
locale
|
|
2116
|
+
},
|
|
2117
|
+
onEmit: {
|
|
2118
|
+
RequestedOpen: () => DataTableMessage.SubmenuOpened({
|
|
2119
|
+
key: subkey,
|
|
2120
|
+
...filterEditor ? { filterColumnId: filterColumnId ?? id } : {}
|
|
2121
|
+
}),
|
|
2122
|
+
RequestedClose: () => DataTableMessage.SubmenuClosed({ key: subkey }),
|
|
2123
|
+
Picked: ({ value }) => subitems.find(({ id, disabled }) => id === value && !disabled)?.message,
|
|
2124
|
+
Highlighted: () => {
|
|
2125
|
+
return;
|
|
2126
|
+
},
|
|
2127
|
+
RequestedQuery: ({ query }) => childSearch ? DataTableMessage.MenuQueryChanged({ key, query }) : undefined,
|
|
2128
|
+
Settled: () => {
|
|
2129
|
+
return;
|
|
2130
|
+
}
|
|
2131
|
+
},
|
|
2132
|
+
view: (submenu) => h.div.children(separatorBefore && MenuSeparator(h, menu), MenuSubTrigger(h, menu, submenu, {
|
|
2133
|
+
value: id
|
|
2134
|
+
}).children(indicator(icon), name), MenuPositioner(h, submenu).children(MenuPopup(h, submenu).children(childSearch && MenuInput(h, submenu, {
|
|
2135
|
+
placeholder: copy.addItem
|
|
2136
|
+
}), childSearch && MenuEmpty(h, submenu)?.children(copy.empty), filterEditor && model.submenu === subkey && filterEditor(), submenu.list(h.div).children(subitems.map(({
|
|
2137
|
+
id,
|
|
2138
|
+
name,
|
|
2139
|
+
variant,
|
|
2140
|
+
keepOpen,
|
|
2141
|
+
icon,
|
|
2142
|
+
checked,
|
|
2143
|
+
radio,
|
|
2144
|
+
separatorBefore
|
|
2145
|
+
}) => {
|
|
2146
|
+
const options = {
|
|
2147
|
+
value: id,
|
|
2148
|
+
closeOnClick: keepOpen ? false : undefined
|
|
2149
|
+
};
|
|
2150
|
+
const part = radio ? MenuRadioItem(h, submenu, options) : checked !== undefined ? MenuCheckboxItem(h, submenu, options) : MenuItem(h, submenu, {
|
|
2151
|
+
...options,
|
|
2152
|
+
variant
|
|
2153
|
+
});
|
|
2154
|
+
const content = part.children(indicator(icon), name);
|
|
2155
|
+
return separatorBefore ? h.div.children(MenuSeparator(h, submenu), content) : content;
|
|
2156
|
+
})))))
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
const element = h.div.class(cn("data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex min-h-[30px] cursor-default items-center gap-2 rounded-sm px-2 whitespace-nowrap outline-none select-none data-[disabled]:opacity-45", variant === "destructive" && "text-destructive data-[highlighted]:bg-destructive/10 data-[highlighted]:text-destructive"));
|
|
2160
|
+
const part = radio ? menu.radioItem({ element, value: id }) : checked !== undefined ? menu.checkboxItem({
|
|
2161
|
+
element,
|
|
2162
|
+
value: id,
|
|
2163
|
+
closeOnClick: false
|
|
2164
|
+
}) : menu.item({
|
|
2165
|
+
element,
|
|
2166
|
+
value: id,
|
|
2167
|
+
closeOnClick: !searchLabel
|
|
2168
|
+
});
|
|
2169
|
+
const content = part.children(checked !== undefined && h.span.attr("aria-hidden", "true").class("w-3").children(checked ? "✓" : ""), indicator(icon), name);
|
|
2170
|
+
return separatorBefore ? h.div.children(MenuSeparator(h, menu), content) : content;
|
|
2171
|
+
})))));
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2174
|
+
const check = (key, label, checked, onToggle, options, inCell = false) => Checkbox(h, {
|
|
2175
|
+
key,
|
|
2176
|
+
props: { checked, ...options },
|
|
2177
|
+
onEmit: { Toggled: ({ checked }) => onToggle(checked) },
|
|
2178
|
+
view: (checkbox) => h.span.class("grid size-4 shrink-0 place-items-center").children(CheckboxRoot(h, checkbox, {
|
|
2179
|
+
class: inCell ? "focus-visible:outline-none" : undefined
|
|
2180
|
+
}).attr("aria-label", label).children(CheckboxIndicator(h, checkbox, {
|
|
2181
|
+
class: "pointer-events-none"
|
|
2182
|
+
})))
|
|
2183
|
+
});
|
|
2184
|
+
const filterColumns = dataColumns.filter(({ filterable }) => filterable !== false);
|
|
2185
|
+
const draft = model.filterDraft;
|
|
2186
|
+
const filterColumn = draft && filterColumns.find(({ id }) => id === draft.id);
|
|
2187
|
+
const filterKind = filterColumn && tableFilterKind(filterColumn);
|
|
2188
|
+
const activeFilters = (query.filters ?? []).filter((filter) => filterColumns.some((column) => column.id === filter.id && tableFilterKind(column) === filter.kind));
|
|
2189
|
+
const selectFilter = (label, value, options, change) => FilterSelect(h, {
|
|
2190
|
+
props: { label, value, items: options },
|
|
2191
|
+
onEmit: { Changed: ({ value }) => change(value) }
|
|
2192
|
+
});
|
|
2193
|
+
const filterInput = (label, field, value, type = "text") => h.label.class("grid gap-1 text-sm").children(label, Input(h, {
|
|
2194
|
+
element: type === "number" ? h.input.attrs({ type: "number", step: "any" }) : h.input.attr("type", type),
|
|
2195
|
+
props: { value },
|
|
2196
|
+
onUpdate: ({ value }) => DataTableMessage.FilterInputChanged({ field, value })
|
|
2197
|
+
}));
|
|
2198
|
+
const filterPanel = () => h.div.class("grid w-64 max-w-[80vw] gap-2 p-2").children(draft && filterColumn && h.div.key(filterColumn.id).class("grid gap-2").children(filterKind === "text" && [
|
|
2199
|
+
selectFilter(copy.filterOperator, draft.operator, [
|
|
2200
|
+
{ value: "contains", label: copy.filterContains },
|
|
2201
|
+
{ value: "equals", label: copy.filterEquals },
|
|
2202
|
+
{ value: "startsWith", label: copy.filterStartsWith },
|
|
2203
|
+
{ value: "endsWith", label: copy.filterEndsWith }
|
|
2204
|
+
], (operator) => isTextFilterOperator(operator) ? DataTableMessage.FilterOperatorChanged({ operator }) : undefined),
|
|
2205
|
+
filterInput(copy.filterValue, "primary", draft.primary)
|
|
2206
|
+
], filterKind === "number" && [
|
|
2207
|
+
filterInput(copy.filterMin, "primary", draft.primary, "number"),
|
|
2208
|
+
filterInput(copy.filterMax, "secondary", draft.secondary, "number")
|
|
2209
|
+
], filterKind === "date" && [
|
|
2210
|
+
filterInput(copy.filterFrom, "primary", draft.primary, "date"),
|
|
2211
|
+
filterInput(copy.filterTo, "secondary", draft.secondary, "date")
|
|
2212
|
+
], model.invalidFilter && h.p.attr("role", "alert").class("text-destructive text-sm").children(copy.filterInvalid), h.div.class("flex flex-wrap gap-2").children(Button2(h, {
|
|
2213
|
+
size: "sm",
|
|
2214
|
+
onPress: DataTableMessage.FilterApplied()
|
|
2215
|
+
}).children(copy.filterApply), Button2(h, {
|
|
2216
|
+
size: "sm",
|
|
2217
|
+
variant: "outline",
|
|
2218
|
+
onPress: DataTableMessage.FilterCleared()
|
|
2219
|
+
}).children(copy.filterClear))));
|
|
2220
|
+
const filterSubmenu = (column) => {
|
|
2221
|
+
const { id } = column;
|
|
2222
|
+
const current = activeFilters.find((filter) => filter.id === id);
|
|
2223
|
+
let children;
|
|
2224
|
+
if (column.type === "boolean") {
|
|
2225
|
+
children = [true, false].map((value) => ({
|
|
2226
|
+
id: String(value),
|
|
2227
|
+
name: value ? column.typeOptions?.trueLabel ?? copy.filterTrue : column.typeOptions?.falseLabel ?? copy.filterFalse,
|
|
2228
|
+
radio: true,
|
|
2229
|
+
checked: current?.kind === "boolean" && current.value === value,
|
|
2230
|
+
keepOpen: true,
|
|
2231
|
+
message: DataTableMessage.ColumnFilterChanged({
|
|
2232
|
+
id,
|
|
2233
|
+
filter: { id, kind: "boolean", value }
|
|
2234
|
+
})
|
|
2235
|
+
}));
|
|
2236
|
+
} else if (column.type === "list" || column.type === "text" && column.display === "badge") {
|
|
2237
|
+
const selected = current?.kind === "values" ? current.values : [];
|
|
2238
|
+
const options = column.type === "text" ? tableBadgeFilterOptions(props.rowData.map((row) => row.cells[id]), column.typeOptions) : column.filterOptions ?? tableFilterOptions(props.rowData, id, locale);
|
|
2239
|
+
children = options.map(({ value, label }) => {
|
|
2240
|
+
const checked = selected.includes(value);
|
|
2241
|
+
const values = updateSelectedRows(selected, [value], !checked);
|
|
2242
|
+
return {
|
|
2243
|
+
id: keyOf("option", value),
|
|
2244
|
+
name: label,
|
|
2245
|
+
checked,
|
|
2246
|
+
keepOpen: true,
|
|
2247
|
+
message: DataTableMessage.ColumnFilterChanged({
|
|
2248
|
+
id,
|
|
2249
|
+
filter: Arr.isArrayNonEmpty(values) ? { id, kind: "values", values } : null
|
|
2250
|
+
})
|
|
2251
|
+
};
|
|
2252
|
+
});
|
|
2253
|
+
} else {
|
|
2254
|
+
return { filterColumnId: id, filterEditor: filterPanel };
|
|
2255
|
+
}
|
|
2256
|
+
children.push({
|
|
2257
|
+
id: "clear",
|
|
2258
|
+
name: copy.filterClear,
|
|
2259
|
+
keepOpen: true,
|
|
2260
|
+
separatorBefore: children.length > 0,
|
|
2261
|
+
message: DataTableMessage.ColumnFilterChanged({ id, filter: null })
|
|
2262
|
+
});
|
|
2263
|
+
return { children };
|
|
2264
|
+
};
|
|
2265
|
+
const cell = (column, row) => {
|
|
2266
|
+
const value = row.cells[column.id];
|
|
2267
|
+
const empty = column.emptyLabel ?? "—";
|
|
2268
|
+
const disabled = row.disabledColumnIds?.includes(column.id);
|
|
2269
|
+
const edit = (edit) => DataTableMessage.CellEditRequested({ rowId: row.id, columnId: column.id, edit });
|
|
2270
|
+
switch (column.type) {
|
|
2271
|
+
case "text": {
|
|
2272
|
+
if (column.display !== "badge")
|
|
2273
|
+
return isTableText(value) ? value : empty;
|
|
2274
|
+
const badge = tableBadge(value, column.typeOptions);
|
|
2275
|
+
return badge ? h.span.class(cn(badgeClass, badgeVariants[badge.variant])).children(badge.option?.icon && h.span.attr("aria-hidden", "true").class("inline-flex shrink-0").children(badge.option.icon(h, { size: 12 })), badge.label) : empty;
|
|
2276
|
+
}
|
|
2277
|
+
case "number":
|
|
2278
|
+
return isTableNumber(value) ? formatNumberValue(value, column.typeOptions, locale) : empty;
|
|
2279
|
+
case "date":
|
|
2280
|
+
case "dateTime": {
|
|
2281
|
+
const date = resolveDate(value, column.type);
|
|
2282
|
+
return date ? h.time.attr("datetime", dateIsoValue(date)).children(formatDateValue(date, column, locale)) : empty;
|
|
2283
|
+
}
|
|
2284
|
+
case "boolean":
|
|
2285
|
+
return isTableBoolean(value) ? h.label.attr("data-slot", "data-table-boolean-cell").class(cn(booleanCellControl, column.editable && !disabled && "hover:bg-muted/50 cursor-pointer")).children(check(keyOf("edit", row.id, column.id), `${column.headerName}: ${row.label}`, value, (value) => edit(DataTableEdit.SetBoolean({ value })), { readOnly: !column.editable || disabled }, true)) : empty;
|
|
2286
|
+
case "reference":
|
|
2287
|
+
return isTableReference(value) ? h.div.class(tableClasses.reference).children(h.span.class(cn(tableClasses.referenceAvatar, "rounded-full")).children(h.span.attr("aria-hidden", "true").children(tableInitials(value.label)), value.imageSrc && !model.failedImages.includes(value.imageSrc) && h.img.attrs({
|
|
2288
|
+
src: value.imageSrc,
|
|
2289
|
+
alt: "",
|
|
2290
|
+
loading: "lazy"
|
|
2291
|
+
}).class("absolute inset-0 size-full object-cover").on("error", DataTableMessage.ReferenceImageFailed({ src: value.imageSrc }))), h.div.class(tableClasses.referenceText).children(h.span.class(tableClasses.referenceName).children(value.label), value.description && h.span.class(tableClasses.referenceDescription).children(value.description))) : empty;
|
|
2292
|
+
case "list": {
|
|
2293
|
+
const current = isTableList(value) ? value : [];
|
|
2294
|
+
const visible = current.slice(0, column.visibleCount ?? 3);
|
|
2295
|
+
const overflow = current.length - visible.length;
|
|
2296
|
+
const badgeSummary = () => h.span.class("inline-flex min-w-0 flex-wrap items-center gap-1").children(visible.map(({ value, label }) => h.span.key(value).class(cn(badgeClass, badgeVariants.secondary)).children(label)), overflow > 0 && h.span.class(cn(badgeClass, badgeVariants.secondary)).children(`+${overflow}`));
|
|
2297
|
+
if (column.manageLabel && !disabled && (column.options || column.allowRemove)) {
|
|
2298
|
+
const used = new Set(current.map(({ value }) => value));
|
|
2299
|
+
const available = (column.options ?? []).filter(({ value }) => !used.has(value));
|
|
2300
|
+
const items = current.map(({ value, label }) => ({
|
|
2301
|
+
id: keyOf("member", value),
|
|
2302
|
+
name: label,
|
|
2303
|
+
disabled: !column.allowRemove,
|
|
2304
|
+
...column.allowRemove ? {
|
|
2305
|
+
children: [
|
|
2306
|
+
{
|
|
2307
|
+
id: "remove",
|
|
2308
|
+
name: copy.removeItem,
|
|
2309
|
+
keepOpen: true,
|
|
2310
|
+
message: edit(DataTableEdit.RemoveItem({ itemId: value }))
|
|
2311
|
+
}
|
|
2312
|
+
]
|
|
2313
|
+
} : {}
|
|
2314
|
+
}));
|
|
2315
|
+
return h.div.class("min-w-0").children(menu(keyOf("manage", row.id, column.id), column.manageLabel, `${column.manageLabel}: ${row.label}`, [
|
|
2316
|
+
...items,
|
|
2317
|
+
...available.length ? [
|
|
2318
|
+
{
|
|
2319
|
+
id: "add",
|
|
2320
|
+
name: copy.addItem,
|
|
2321
|
+
childSearch: true,
|
|
2322
|
+
separatorBefore: items.length > 0,
|
|
2323
|
+
children: available.map(({ value, label }) => ({
|
|
2324
|
+
id: value,
|
|
2325
|
+
name: label,
|
|
2326
|
+
keepOpen: true,
|
|
2327
|
+
message: edit(DataTableEdit.AddItem({ itemId: value }))
|
|
2328
|
+
}))
|
|
2329
|
+
}
|
|
2330
|
+
] : []
|
|
2331
|
+
], false, undefined, false, {
|
|
2332
|
+
relationship: column.display === "badge" && current.length ? badgeSummary() : h.span.class("min-w-0 truncate").children(current.length ? `${current.slice(0, column.visibleCount ?? 3).map(({ label }) => label).join(", ")}${current.length > (column.visibleCount ?? 3) ? ` +${current.length - (column.visibleCount ?? 3)}` : ""}` : empty)
|
|
2333
|
+
}));
|
|
2334
|
+
}
|
|
2335
|
+
if (column.display && !column.options && !column.allowRemove) {
|
|
2336
|
+
const label = column.actionsLabel ?? (column.itemActions?.length ? copy.actions : copy.listDetails);
|
|
2337
|
+
const summary = column.display === "icon" ? h.span.class("flex min-w-0 items-center gap-1 overflow-hidden").children(visible.map(({ value, label }) => h.span.key(value).attr("title", label).class("inline-grid size-7 place-items-center rounded-full bg-muted text-xs").children(tableInitials(label))), overflow > 0 && `+${overflow}`) : column.display === "badge" ? badgeSummary() : h.span.class("min-w-0 truncate").children(`${visible.map(({ label }) => label).join(", ")}${overflow > 0 ? ` +${overflow}` : ""}`);
|
|
2338
|
+
return !current.length ? empty : h.div.class("min-w-0").children(menu(keyOf("items", row.id, column.id), label, `${label}: ${row.label}`, current.map(({ value, label }) => ({
|
|
2339
|
+
id: value,
|
|
2340
|
+
name: label,
|
|
2341
|
+
...column.itemActions?.length ? {
|
|
2342
|
+
children: column.itemActions.map((action) => ({
|
|
2343
|
+
...action,
|
|
2344
|
+
message: DataTableMessage.ItemActionRequested({
|
|
2345
|
+
rowId: row.id,
|
|
2346
|
+
columnId: column.id,
|
|
2347
|
+
itemId: value,
|
|
2348
|
+
actionId: action.id
|
|
2349
|
+
})
|
|
2350
|
+
}))
|
|
2351
|
+
} : { disabled: true }
|
|
2352
|
+
})), false, undefined, false, { relationship: summary }));
|
|
2353
|
+
}
|
|
2354
|
+
const used = new Set(current.map(({ value }) => value));
|
|
2355
|
+
const add = (column.options ?? []).filter(({ value }) => !used.has(value));
|
|
2356
|
+
return h.div.class("grid gap-1").children(current.length > 0 ? h.ul.class("flex flex-wrap gap-1").children(current.map(({ value, label }) => h.li.key(value).class(column.display === "badge" ? cn(badgeClass, badgeVariants.secondary) : "bg-muted rounded-sm ps-2 inline-flex items-center gap-1").children(label, !!column.itemActions?.length && menu(keyOf("item", row.id, column.id, value), copy.actions, `${copy.actions}: ${label} — ${row.label}`, column.itemActions.map((action) => ({
|
|
2357
|
+
...action,
|
|
2358
|
+
message: DataTableMessage.ItemActionRequested({
|
|
2359
|
+
rowId: row.id,
|
|
2360
|
+
columnId: column.id,
|
|
2361
|
+
itemId: value,
|
|
2362
|
+
actionId: action.id
|
|
2363
|
+
})
|
|
2364
|
+
}))), column.allowRemove && !disabled && Button2(h, {
|
|
2365
|
+
variant: "ghost",
|
|
2366
|
+
size: "sm",
|
|
2367
|
+
onPress: edit(DataTableEdit.RemoveItem({ itemId: value }))
|
|
2368
|
+
}).attr("aria-label", `${copy.removeItem}: ${label} — ${row.label}`).children("×")))) : empty, !disabled && add.length > 0 && menu(keyOf("add", row.id, column.id), copy.addItem, `${copy.addItem} ${column.headerName}: ${row.label}`, add.map(({ value, label }) => ({
|
|
2369
|
+
id: value,
|
|
2370
|
+
name: label,
|
|
2371
|
+
message: edit(DataTableEdit.AddItem({ itemId: value }))
|
|
2372
|
+
})), false, copy.addItem));
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
const dragHandle = (row) => draggable && h.span.attr("aria-hidden", "true").class("inline-flex size-8 cursor-grab items-center justify-center text-muted-foreground").draggable({ [RowDrag]: row.id }, { effectAllowed: "move" }).on("dragstart", DataTableMessage.DragStarted({ rowId: row.id })).on("dragend", DataTableMessage.DragEnded()).children(GripVertical(h, { size: 16 }));
|
|
2377
|
+
const rowControls = (row, siblings, key) => {
|
|
2378
|
+
const items = tableRowActions(row, siblings, reorder, copy);
|
|
2379
|
+
return items.length > 0 && menu(keyOf("row", key, row.id), copy.actions, `${copy.actions}: ${row.label}`, items, false, undefined, false, "actions");
|
|
2380
|
+
};
|
|
2381
|
+
const renderRow = (row, siblings, key, group) => {
|
|
2382
|
+
const primary = row.actions?.find(({ id, disabled }) => id === row.primaryActionId && !disabled);
|
|
2383
|
+
const activate = props.rowActivation ? DataTableMessage.RowActivated({ rowId: row.id }) : primary && DataTableMessage.RowActionRequested({ rowId: row.id, actionId: primary.id });
|
|
2384
|
+
const tr = h.tr.key(keyOf(key, row.id)).class(cn("group/row hover:bg-muted/50 data-[selected]:bg-muted/40 border-b last:border-0", props.rowActivation && "cursor-pointer")).attr("data-selected", selected.has(row.id) ? "" : undefined);
|
|
2385
|
+
const rowElement = props.rowActivation && activate ? tr.attr("tabindex", "0").on("click", activate).on("keydown", (event) => !event.repeat && !event.composing && (event.key === "Enter" || event.key === " ") ? activate : undefined, { preventDefault: true }) : tr;
|
|
2386
|
+
const ignoreActivation = () => {
|
|
2387
|
+
return;
|
|
2388
|
+
};
|
|
2389
|
+
const drop = dropOnRow(row.id, group);
|
|
2390
|
+
return (drop ? rowElement.dropTarget({ accepts: [RowDrag], dropEffect: "move" }).on("drop", drop) : rowElement).children(selection && h.td.class(tableClasses.selectionCell).on("click", ignoreActivation).on("keydown", ignoreActivation).children(h.div.class(tableClasses.selectionCenter).children(check(keyOf("select", key, row.id), `${copy.selectRow}: ${row.label}`, selected.has(row.id), (checked) => DataTableMessage.SelectionRequested({ rowIds: [row.id], checked }), { disabled: row.selectable === false }))), draggable && h.td.class("w-10 ps-1").on("click", ignoreActivation).on("keydown", ignoreActivation).children(dragHandle(row)), columns.map((column) => {
|
|
2391
|
+
const td = h.td.key(column.id).attr("data-slot", "table-cell").attr("data-column-id", column.id).class(cn(cellClass, tableClasses.cell, column.truncate ? "whitespace-nowrap" : "whitespace-normal", column.type === "list" && "p-0", column.type === "boolean" && "min-w-24 has-[[data-slot=data-table-boolean-cell]]:relative has-[[data-slot=data-table-boolean-cell]]:p-0", "has-[[data-slot=data-table-list-cell]]:relative has-[[data-slot=data-table-list-cell]]:h-16"));
|
|
2392
|
+
const content = () => h.div.class(cn(tableClasses.cellContent, column.truncate && "truncate")).children(cell(column, row));
|
|
2393
|
+
if (column.type === "list" || column.type === "boolean" && isTableBoolean(row.cells[column.id])) {
|
|
2394
|
+
return td.on("click", ignoreActivation).on("keydown", ignoreActivation).children(content());
|
|
2395
|
+
}
|
|
2396
|
+
return (!props.rowActivation && activate && column.type !== "boolean" ? td.class("cursor-pointer").on("click", activate) : td).children(content());
|
|
2397
|
+
}), rowActions && h.td.on("click", ignoreActivation).on("keydown", ignoreActivation).class(cn(tableClasses.actionsCell, "group-data-[selected]/row:bg-muted")).children(h.div.class(tableClasses.actionsAlign).children(primary && activate && Button2(h, {
|
|
2398
|
+
variant: primary.variant === "destructive" ? "destructive" : "ghost",
|
|
2399
|
+
size: "sm",
|
|
2400
|
+
onPress: activate
|
|
2401
|
+
}).attr("aria-label", `${primary.name}: ${row.label}`).children(primary.name), rowControls(row, siblings, key))));
|
|
2402
|
+
};
|
|
2403
|
+
const galleryValue = (id, row) => {
|
|
2404
|
+
const column = props.columnDefs.find((column) => column.id === id);
|
|
2405
|
+
return column ? cell(column, row) : "";
|
|
2406
|
+
};
|
|
2407
|
+
const renderCard = (row, siblings, key, group) => {
|
|
2408
|
+
if (!gallery)
|
|
2409
|
+
return h.div;
|
|
2410
|
+
const image = gallery.image && row.cells[gallery.image];
|
|
2411
|
+
const primary = row.actions?.find(({ id, disabled }) => row.primaryActionId === id && !disabled);
|
|
2412
|
+
const name = galleryValue(gallery.name, row) || row.label;
|
|
2413
|
+
const activate = props.rowActivation ? DataTableMessage.RowActivated({ rowId: row.id }) : primary && DataTableMessage.RowActionRequested({ rowId: row.id, actionId: primary.id });
|
|
2414
|
+
const card = h.article.key(keyOf(key, row.id)).class("grid content-start gap-2 rounded-lg border p-3");
|
|
2415
|
+
const drop = dropOnRow(row.id, group);
|
|
2416
|
+
return (drop ? card.dropTarget({ accepts: [RowDrag], dropEffect: "move" }).on("drop", drop) : card).children(isTableText(image) && h.img.attrs({ src: image, alt: "", loading: "lazy" }).class("aspect-video w-full rounded object-cover"), h.h3.class("font-medium").children(activate ? Button2(h, {
|
|
2417
|
+
variant: "ghost",
|
|
2418
|
+
onPress: activate
|
|
2419
|
+
}).children(name) : name), gallery.description && h.div.class("text-muted-foreground text-sm").children(galleryValue(gallery.description, row)), h.div.class("flex flex-wrap gap-2").children(gallery.tags?.map((id) => {
|
|
2420
|
+
const column = props.columnDefs.find((column) => column.id === id);
|
|
2421
|
+
if ((column?.type === "text" || column?.type === "list") && column.display === "badge")
|
|
2422
|
+
return h.div.key(id).children(cell(column, row));
|
|
2423
|
+
return h.span.key(id).class("bg-muted rounded px-2 py-1 text-xs").children(galleryValue(id, row));
|
|
2424
|
+
})), selection && check(keyOf("select", key, row.id), `${copy.selectRow}: ${row.label}`, selected.has(row.id), (checked) => DataTableMessage.SelectionRequested({ rowIds: [row.id], checked }), { disabled: row.selectable === false }), h.div.class("flex items-center justify-end gap-1").children(dragHandle(row), rowControls(row, siblings, key)));
|
|
2425
|
+
};
|
|
2426
|
+
const renderGroups = (members, depth, parent, parentTarget) => {
|
|
2427
|
+
const field = grouping[depth];
|
|
2428
|
+
if (!field)
|
|
2429
|
+
return members.map((row) => gallery ? renderCard(row, members, parent, parentTarget) : renderRow(row, members, parent, parentTarget));
|
|
2430
|
+
const groups = partitionTableGroups(members, field.groups?.map(({ id }) => id) ?? [], (row) => row.groups?.[field.id] ?? []);
|
|
2431
|
+
return [...groups].flatMap(([groupId, children]) => {
|
|
2432
|
+
const key = tableGroupKey(parent, field.id, groupId);
|
|
2433
|
+
const definition = field.groups?.find(({ id }) => id === groupId);
|
|
2434
|
+
const label = definition?.label ?? groupId;
|
|
2435
|
+
const open = !model.collapsedGroups[key];
|
|
2436
|
+
const title = h.div.class(cn(tableClasses.groupContent, !gallery && tableClasses.groupSticky)).children(h.button.attr("type", "button").class(tableClasses.groupTrigger).style({ paddingInlineStart: `${depth * 20}px` }).on("click", DataTableMessage.GroupToggled({ key })).attr("aria-expanded", open ? "true" : "false").attr("aria-label", label).children((open ? ChevronDown : ChevronRight2)(h, {
|
|
2437
|
+
size: 16,
|
|
2438
|
+
className: "shrink-0"
|
|
2439
|
+
}), h.span.class("min-w-0 flex-1 truncate").children(label), h.span.class(tableClasses.count).children(String(children.length))), !!field.actions?.length && menu(keyOf("group", key), field.actionsLabel ?? copy.actions, `${field.actionsLabel ?? copy.actions}: ${label}`, field.actions.map((action) => ({
|
|
2440
|
+
...action,
|
|
2441
|
+
message: DataTableMessage.GroupActionRequested({
|
|
2442
|
+
fieldId: field.id,
|
|
2443
|
+
groupId,
|
|
2444
|
+
actionId: action.id
|
|
2445
|
+
})
|
|
2446
|
+
})), false, undefined, false, "actions"));
|
|
2447
|
+
const header = gallery ? h.div.key(key).class(cn("col-span-full rounded-md border", tableClasses.group)).children(title) : h.tr.key(key).class(tableClasses.group).children(h.td.class("p-0").attr("colspan", String(span)).children(title));
|
|
2448
|
+
const groupTarget = field.movable ? { fieldId: field.id, groupId } : parentTarget;
|
|
2449
|
+
const target = groupTarget ? header.dropTarget({ accepts: [RowDrag], dropEffect: "move" }).on("drop", DataTableMessage.GroupDropped(groupTarget)) : header;
|
|
2450
|
+
const empty = definition?.empty ?? copy.empty;
|
|
2451
|
+
return [
|
|
2452
|
+
target,
|
|
2453
|
+
...open ? children.length ? renderGroups(children, depth + 1, key, groupTarget) : [
|
|
2454
|
+
gallery ? h.p.key(keyOf(key, "empty")).class("col-span-full text-sm").children(empty) : h.tr.key(keyOf(key, "empty")).children(h.td.attr("colspan", String(span)).class("p-3").children(empty))
|
|
2455
|
+
] : []
|
|
2456
|
+
];
|
|
2457
|
+
});
|
|
2458
|
+
};
|
|
2459
|
+
return h.section.class(cn("min-w-0 gap-2", fillHeight ? "flex min-h-0 flex-1 flex-col" : "grid", props.className)).onMount(PersistPreferences({
|
|
2460
|
+
columns: props.columnDefs.map(({ id }) => id),
|
|
2461
|
+
gallery: !!features.gallery,
|
|
2462
|
+
preferences: tablePreferences(model)
|
|
2463
|
+
})).children(h.div.class(tableClasses.toolbar).children(features.search && h.div.class(tableClasses.toolbarSearch).children(Search(h, {
|
|
2464
|
+
size: 16,
|
|
2465
|
+
className: "text-muted-foreground pointer-events-none absolute top-1/2 start-3 -translate-y-1/2"
|
|
2466
|
+
}), Input(h, {
|
|
2467
|
+
class: cn("ps-9", query.globalFilter && "pe-10"),
|
|
2468
|
+
element: h.input.attrs({
|
|
2469
|
+
type: "search",
|
|
2470
|
+
placeholder: copy.search
|
|
2471
|
+
}),
|
|
2472
|
+
props: { value: query.globalFilter ?? "" },
|
|
2473
|
+
onUpdate: ({ value }) => DataTableMessage.SearchChanged({ value })
|
|
2474
|
+
}).attr("aria-label", copy.search), !!query.globalFilter && Button2(h, {
|
|
2475
|
+
class: "absolute end-1 top-1/2 -translate-y-1/2",
|
|
2476
|
+
size: "icon-sm",
|
|
2477
|
+
variant: "ghost",
|
|
2478
|
+
onPress: DataTableMessage.SearchChanged({ value: "" })
|
|
2479
|
+
}).attr("aria-label", copy.search).children(X(h, { size: 16 }))), (features.filtering && filterColumns.length > 0 || features.sorting && sortableColumns.length > 0 || features.columnVisibility && hideableColumns.length > 0 || !blocked && selectedCount > 0 && !!selection?.bulkActions?.length || features.refresh || !!features.grouping?.fields.length || !!features.gallery || !!features.export) && Menubar(h, {
|
|
2480
|
+
props: { modal: false },
|
|
2481
|
+
view: (bar) => h.div.class(tableClasses.toolbarMenus).children(MenubarRoot(h, bar, tableClasses.menubar).children(!blocked && selectedCount > 0 && selection && selection.bulkActions && selection.bulkActions.length > 0 && menu(keyOf("bulk"), selection.bulkActionsLabel ?? copy.actions, `${copy.selected} ${selectedCount}`, selection.bulkActions.map((action) => ({
|
|
2482
|
+
...action,
|
|
2483
|
+
message: DataTableMessage.BulkActionRequested({
|
|
2484
|
+
actionId: action.id
|
|
2485
|
+
})
|
|
2486
|
+
})), true, undefined, false, { selectedCount }), features.filtering && filterColumns.length > 0 && menu(keyOf("filters"), copy.filters, copy.filters, [
|
|
2487
|
+
...filterColumns.map((column) => ({
|
|
2488
|
+
id: column.id,
|
|
2489
|
+
name: column.headerName,
|
|
2490
|
+
...filterSubmenu(column)
|
|
2491
|
+
})),
|
|
2492
|
+
...activeFilters.length > 0 ? [
|
|
2493
|
+
{
|
|
2494
|
+
id: keyOf("clear-filters"),
|
|
2495
|
+
name: copy.filtersClear,
|
|
2496
|
+
icon: "clear",
|
|
2497
|
+
message: DataTableMessage.FiltersCleared()
|
|
2498
|
+
}
|
|
2499
|
+
] : []
|
|
2500
|
+
], true, undefined, false, {
|
|
2501
|
+
toolbarIcon: "filter",
|
|
2502
|
+
filterCount: activeFilters.length
|
|
2503
|
+
}), features.sorting && sortableColumns.length > 0 && menu(keyOf("sort-toolbar"), copy.sortBy, copy.sortBy, sortableColumns.map((column) => ({
|
|
2504
|
+
id: column.id,
|
|
2505
|
+
name: column.headerName,
|
|
2506
|
+
children: ["asc", "desc", null].filter((direction) => direction !== null || sort.some(({ id }) => id === column.id)).map((direction) => ({
|
|
2507
|
+
id: keyOf(column.id, direction ?? "clear"),
|
|
2508
|
+
name: direction === "asc" ? copy.sortAsc : direction === "desc" ? copy.sortDesc : copy.sortClear,
|
|
2509
|
+
icon: direction ?? "clear",
|
|
2510
|
+
message: DataTableMessage.SortRequested({
|
|
2511
|
+
columnId: column.id,
|
|
2512
|
+
direction
|
|
2513
|
+
})
|
|
2514
|
+
}))
|
|
2515
|
+
})), true, undefined, false, { toolbarIcon: sort[0]?.direction ?? "sort" }), features.columnVisibility && hideableColumns.length > 0 && menu(keyOf("columns"), copy.columns, copy.columns, hideableColumns.map(({ id, headerName }) => ({
|
|
2516
|
+
id,
|
|
2517
|
+
name: headerName,
|
|
2518
|
+
checked: model.columnVisibility[id] !== false,
|
|
2519
|
+
message: DataTableMessage.ColumnVisibilityChanged({
|
|
2520
|
+
id,
|
|
2521
|
+
visible: model.columnVisibility[id] === false
|
|
2522
|
+
})
|
|
2523
|
+
})), true, undefined, false, { toolbarIcon: "columns" }), features.refresh && menu(keyOf("refresh"), copy.refresh, copy.refresh, [
|
|
2524
|
+
{
|
|
2525
|
+
id: "refresh",
|
|
2526
|
+
name: copy.refresh,
|
|
2527
|
+
icon: "refresh",
|
|
2528
|
+
message: DataTableMessage.RefreshRequested()
|
|
2529
|
+
}
|
|
2530
|
+
], true, undefined, false, { toolbarIcon: "refresh" }), features.grouping && features.grouping.fields.length > 0 && menu(keyOf("group-by"), copy.groupBy, copy.groupBy, features.grouping.fields.map(({ id, label }) => ({
|
|
2531
|
+
id,
|
|
2532
|
+
name: label,
|
|
2533
|
+
checked: model.grouping.includes(id),
|
|
2534
|
+
message: DataTableMessage.GroupingToggled({ fieldId: id })
|
|
2535
|
+
})), true, undefined, false, { toolbarIcon: "table" }), features.gallery && menu(keyOf("view"), copy.view, copy.view, [
|
|
2536
|
+
{
|
|
2537
|
+
id: "table",
|
|
2538
|
+
name: copy.tableView,
|
|
2539
|
+
icon: "table",
|
|
2540
|
+
checked: !gallery,
|
|
2541
|
+
radio: true,
|
|
2542
|
+
message: DataTableMessage.ViewPicked({ view: "table" })
|
|
2543
|
+
},
|
|
2544
|
+
{
|
|
2545
|
+
id: "gallery",
|
|
2546
|
+
name: copy.galleryView,
|
|
2547
|
+
icon: "gallery",
|
|
2548
|
+
checked: !!gallery,
|
|
2549
|
+
radio: true,
|
|
2550
|
+
message: DataTableMessage.ViewPicked({ view: "gallery" })
|
|
2551
|
+
}
|
|
2552
|
+
], true, undefined, false, { toolbarIcon: gallery ? "gallery" : "table" }), features.export && menu(keyOf("export"), copy.export, copy.export, [
|
|
2553
|
+
...features.export.builtIn === false ? [] : ["csv", "json"].map((format) => ({
|
|
2554
|
+
id: keyOf("built-in", format),
|
|
2555
|
+
name: format.toUpperCase(),
|
|
2556
|
+
icon: format,
|
|
2557
|
+
disabled: blocked || !rows.length,
|
|
2558
|
+
message: DataTableMessage.BuiltInExportRequested({
|
|
2559
|
+
format,
|
|
2560
|
+
locale
|
|
2561
|
+
})
|
|
2562
|
+
})),
|
|
2563
|
+
...(features.export.actions ?? []).map((action) => ({
|
|
2564
|
+
...action,
|
|
2565
|
+
id: keyOf("custom", action.id),
|
|
2566
|
+
message: DataTableMessage.ExportRequested({
|
|
2567
|
+
actionId: action.id
|
|
2568
|
+
})
|
|
2569
|
+
}))
|
|
2570
|
+
], true, undefined, features.export.pending || model.exporting, { toolbarIcon: "export" })))
|
|
2571
|
+
})), (model.exportFailed || features.export?.failed) && h.p.attr("role", "alert").class("text-destructive text-sm").children(copy.exportFailed), gallery ? h.div.class("grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3").children(blocked ? h.p.attr("role", status?.error !== undefined ? "alert" : "status").children(status?.error ?? copy.loading) : !rows.length && !grouping.length ? h.p.attr("role", "status").children(status?.empty ?? copy.empty) : renderGroups(rows, 0, "")) : (() => {
|
|
2572
|
+
const renderTable = (list) => {
|
|
2573
|
+
const table = h.table.class("table-fixed border-separate border-spacing-0 text-start text-sm").style({ width: "100%", minWidth: `${layoutWidth}px` }).attr("aria-busy", status?.loading ? "true" : undefined);
|
|
2574
|
+
return (list ? list.table(table) : table).children(h.caption.class("sr-only").children(props.label), h.thead.class(list ? cn(tableClasses.stickyHeader, tableClasses.stickyHeaderRule) : "[&_th]:border-b").children(h.tr.children(selection && h.th.attr("scope", "col").class(tableClasses.selectionCell).children(h.div.class(tableClasses.selectionCenter).children(check(keyOf("select-all"), copy.selectAllRows, selectedHere > 0 && selectedHere === ids.length, (checked) => DataTableMessage.SelectionRequested({
|
|
2575
|
+
rowIds: ids,
|
|
2576
|
+
checked
|
|
2577
|
+
}), {
|
|
2578
|
+
disabled: blocked || ids.length === 0,
|
|
2579
|
+
indeterminate: selectedHere > 0 && selectedHere < ids.length
|
|
2580
|
+
}))), draggable && h.th.attr("scope", "col").class("w-10"), columns.map((column, index) => {
|
|
2581
|
+
const fields = tableDataColumns([column]);
|
|
2582
|
+
const owns = (id) => id === column.id || fields.some((field) => field.id === id);
|
|
2583
|
+
const active = sort.find(({ id }) => owns(id))?.direction;
|
|
2584
|
+
const filtered = activeFilters.filter(({ id }) => owns(id)).length;
|
|
2585
|
+
const sorting = features.sorting && fields.some(({ sortable }) => sortable !== false);
|
|
2586
|
+
const filtering = features.filtering && fields.some(({ filterable }) => filterable !== false);
|
|
2587
|
+
const hiding = features.columnVisibility && column.hideable !== false;
|
|
2588
|
+
const width = widths[index] ?? tableColumnWidth(column, model.columnSizing);
|
|
2589
|
+
const { min, max } = tableColumnLimits(column);
|
|
2590
|
+
return h.th.key(column.id).class(cn(tableClasses.header, "text-start font-medium")).style({
|
|
2591
|
+
width: `${width}px`
|
|
2592
|
+
}).attrs({
|
|
2593
|
+
scope: "col",
|
|
2594
|
+
"aria-label": column.headerName,
|
|
2595
|
+
"aria-sort": active === "asc" ? "ascending" : active === "desc" ? "descending" : undefined
|
|
2596
|
+
}).children(!sorting && !filtering && !hiding ? h.div.class("truncate px-2 pe-4").children(column.headerName) : menu(keyOf("sort", column.id), column.headerName, column.headerName, [
|
|
2597
|
+
...sorting && column.fields?.length ? tableDataColumns([column]).filter(({ sortable }) => sortable !== false).map((field) => ({
|
|
2598
|
+
id: keyOf("sort", field.id),
|
|
2599
|
+
name: field.headerName,
|
|
2600
|
+
children: ["asc", "desc"].map((direction) => ({
|
|
2601
|
+
id: direction,
|
|
2602
|
+
name: direction === "asc" ? copy.sortAsc : direction === "desc" ? copy.sortDesc : copy.sortDesc,
|
|
2603
|
+
message: DataTableMessage.SortRequested({
|
|
2604
|
+
columnId: field.id,
|
|
2605
|
+
direction
|
|
2606
|
+
})
|
|
2607
|
+
}))
|
|
2608
|
+
})) : sorting ? [
|
|
2609
|
+
{
|
|
2610
|
+
id: "asc",
|
|
2611
|
+
name: copy.sortAsc,
|
|
2612
|
+
icon: "asc",
|
|
2613
|
+
message: DataTableMessage.SortRequested({
|
|
2614
|
+
columnId: column.id,
|
|
2615
|
+
direction: "asc"
|
|
2616
|
+
})
|
|
2617
|
+
},
|
|
2618
|
+
{
|
|
2619
|
+
id: "desc",
|
|
2620
|
+
name: copy.sortDesc,
|
|
2621
|
+
icon: "desc",
|
|
2622
|
+
message: DataTableMessage.SortRequested({
|
|
2623
|
+
columnId: column.id,
|
|
2624
|
+
direction: "desc"
|
|
2625
|
+
})
|
|
2626
|
+
}
|
|
2627
|
+
] : [],
|
|
2628
|
+
...sorting && active ? [
|
|
2629
|
+
{
|
|
2630
|
+
id: "clear-sort",
|
|
2631
|
+
name: copy.sortClear,
|
|
2632
|
+
icon: "clear",
|
|
2633
|
+
message: DataTableMessage.ColumnSortCleared({
|
|
2634
|
+
id: column.id
|
|
2635
|
+
})
|
|
2636
|
+
}
|
|
2637
|
+
] : [],
|
|
2638
|
+
...filtering ? tableDataColumns([column]).filter(({ filterable }) => filterable !== false).map((field, index) => ({
|
|
2639
|
+
id: keyOf("filter", field.id),
|
|
2640
|
+
name: column.fields?.length ? `${copy.filters}: ${field.headerName}` : copy.filters,
|
|
2641
|
+
...filterSubmenu(field),
|
|
2642
|
+
icon: "filter",
|
|
2643
|
+
separatorBefore: sorting && index === 0
|
|
2644
|
+
})) : [],
|
|
2645
|
+
...filtering && filtered ? [
|
|
2646
|
+
{
|
|
2647
|
+
id: "clear-filter",
|
|
2648
|
+
name: copy.filterClear,
|
|
2649
|
+
icon: "clear",
|
|
2650
|
+
message: DataTableMessage.ColumnFiltersCleared({
|
|
2651
|
+
id: column.id
|
|
2652
|
+
})
|
|
2653
|
+
}
|
|
2654
|
+
] : [],
|
|
2655
|
+
...hiding ? [
|
|
2656
|
+
{
|
|
2657
|
+
id: "hide",
|
|
2658
|
+
name: copy.hideColumn,
|
|
2659
|
+
icon: "hide",
|
|
2660
|
+
separatorBefore: sorting || filtering,
|
|
2661
|
+
message: DataTableMessage.ColumnVisibilityChanged({
|
|
2662
|
+
id: column.id,
|
|
2663
|
+
visible: false
|
|
2664
|
+
})
|
|
2665
|
+
}
|
|
2666
|
+
] : []
|
|
2667
|
+
], false, undefined, false, { filtered, sort: active }), column.resizable !== false && h.button.attr("type", "button").attr("role", "separator").attr("aria-orientation", "vertical").attr("aria-valuemin", String(min)).attr("aria-valuemax", String(max)).attr("aria-valuenow", String(width)).attr("aria-label", `${copy.resize}: ${column.headerName}`).class(tableClasses.resizeHandle).on("pointerdown", ({ x, button, pointerId }) => button === 0 ? DataTableMessage.ResizeStarted({
|
|
2668
|
+
id: column.id,
|
|
2669
|
+
x,
|
|
2670
|
+
pointerId
|
|
2671
|
+
}) : undefined, {
|
|
2672
|
+
capturePointer: true,
|
|
2673
|
+
preventDefault: true
|
|
2674
|
+
}).on("pointermove", ({ x, pointerId }) => model.resizing?.id === column.id ? DataTableMessage.ResizeMoved({ x, pointerId }) : undefined).on("pointerup", ({ pointerId }) => DataTableMessage.ResizeEnded({ pointerId })).on("pointercancel", ({ pointerId }) => DataTableMessage.ResizeEnded({ pointerId })).on("dblclick", DataTableMessage.ColumnResizeReset({
|
|
2675
|
+
id: column.id
|
|
2676
|
+
})).on("keydown", ({ key }) => {
|
|
2677
|
+
const delta = tableResizeStep(key);
|
|
2678
|
+
return delta ? DataTableMessage.ColumnResized({
|
|
2679
|
+
id: column.id,
|
|
2680
|
+
delta
|
|
2681
|
+
}) : undefined;
|
|
2682
|
+
}, { preventDefault: true }));
|
|
2683
|
+
}), rowActions && h.th.attr("scope", "col").class("w-10").attr("aria-label", copy.actions))), (list ? list.list(h.tbody) : h.tbody).children(blocked || rows.length === 0 && grouping.length === 0 ? h.tr.children(h.td.attr("colspan", String(span)).class("py-8 text-center").children(status?.error !== undefined ? h.p.attr("role", "alert").class("text-destructive").children(status.error) : h.p.attr("role", "status").children(status?.loading ? copy.loading : status?.empty ?? copy.empty))) : list ? list.items.flatMap((index) => {
|
|
2684
|
+
const row = rows[index];
|
|
2685
|
+
return row ? [
|
|
2686
|
+
list.item({
|
|
2687
|
+
element: renderRow(row, rows, ""),
|
|
2688
|
+
index
|
|
2689
|
+
})
|
|
2690
|
+
] : [];
|
|
2691
|
+
}) : renderGroups(rows, 0, "")));
|
|
2692
|
+
};
|
|
2693
|
+
const viewport = () => h.div.class(cn("@container overflow-auto", fillHeight && "min-h-0 flex-1"));
|
|
2694
|
+
if (!virtual)
|
|
2695
|
+
return viewport().children(renderTable());
|
|
2696
|
+
return VirtualList(h, {
|
|
2697
|
+
props: {
|
|
2698
|
+
keys: rows.map(({ id }) => id),
|
|
2699
|
+
count: rows.length,
|
|
2700
|
+
itemSize: virtual.itemSize,
|
|
2701
|
+
measure: true,
|
|
2702
|
+
overscan: virtual.overscan,
|
|
2703
|
+
initialCount: virtual.initialCount
|
|
2704
|
+
},
|
|
2705
|
+
view: (list) => virtual.scroll === "page" ? h.div.children(renderTable(list)) : list.viewport(fillHeight ? viewport() : viewport().style({
|
|
2706
|
+
maxHeight: `${virtual.height}px`
|
|
2707
|
+
})).children(renderTable(list))
|
|
2708
|
+
});
|
|
2709
|
+
})(), paginationVisible ? Pagination(h, {
|
|
2710
|
+
props: {
|
|
2711
|
+
locale,
|
|
2712
|
+
page,
|
|
2713
|
+
pageSize,
|
|
2714
|
+
pageSizes,
|
|
2715
|
+
pageCount,
|
|
2716
|
+
totalRows,
|
|
2717
|
+
selectedRows: selectedCount
|
|
2718
|
+
},
|
|
2719
|
+
onEmit: {
|
|
2720
|
+
PageChanged: ({ page }) => DataTableMessage.PageRequested({ page }),
|
|
2721
|
+
PageSizeChanged: ({ pageSize }) => DataTableMessage.PageSizeRequested({ pageSize })
|
|
2722
|
+
}
|
|
2723
|
+
}) : h.div.attr("role", "status").class(tableResultsFooterClass).children(paginationMessages(locale).results(totalRows)));
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2726
|
+
|
|
2727
|
+
// ../../src/components/audit-log-table/html.ts
|
|
2728
|
+
import { krakstackLocaleRead as krakstackLocaleRead3 } from "@krak-stack/registry/krakstack-provider/html";
|
|
2729
|
+
|
|
2730
|
+
// ../../src/services/events/schema.ts
|
|
2731
|
+
import { Effect as Effect3, Option as Option4, Schema as Schema8 } from "effect";
|
|
2732
|
+
|
|
2733
|
+
// ../../src/services/opentelemetry/schema.ts
|
|
2734
|
+
import { Schema as Schema7 } from "effect";
|
|
2735
|
+
var BrowserAnalyticsPreference = Schema7.Struct({
|
|
2736
|
+
version: Schema7.String,
|
|
2737
|
+
choice: Schema7.Literals(["accepted", "declined"]),
|
|
2738
|
+
revision: Schema7.String,
|
|
2739
|
+
issuedAt: Schema7.Finite,
|
|
2740
|
+
expiresAt: Schema7.Finite
|
|
2741
|
+
}).annotate({ identifier: "BrowserAnalyticsPreference" });
|
|
2742
|
+
var BrowserPrivacySignals = Schema7.Struct({
|
|
2743
|
+
globalPrivacyControl: Schema7.optional(Schema7.Boolean)
|
|
2744
|
+
}).annotate({ identifier: "BrowserPrivacySignals" });
|
|
2745
|
+
var BrowserWebVital = Schema7.Struct({
|
|
2746
|
+
name: Schema7.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
|
|
2747
|
+
id: Schema7.NonEmptyString.check(Schema7.isMaxLength(64)),
|
|
2748
|
+
value: Schema7.Finite.check(Schema7.isGreaterThanOrEqualTo(0)),
|
|
2749
|
+
delta: Schema7.Finite,
|
|
2750
|
+
rating: Schema7.Literals(["good", "needs-improvement", "poor"]),
|
|
2751
|
+
navigationType: Schema7.Literals([
|
|
2752
|
+
"navigate",
|
|
2753
|
+
"reload",
|
|
2754
|
+
"back-forward",
|
|
2755
|
+
"back-forward-cache",
|
|
2756
|
+
"prerender",
|
|
2757
|
+
"restore"
|
|
2758
|
+
])
|
|
2759
|
+
}).annotate({ identifier: "BrowserWebVital" });
|
|
2760
|
+
var EventAttributeValue = Schema7.Union([
|
|
2761
|
+
Schema7.String,
|
|
2762
|
+
Schema7.Finite,
|
|
2763
|
+
Schema7.Boolean,
|
|
2764
|
+
Schema7.Array(Schema7.String),
|
|
2765
|
+
Schema7.Array(Schema7.Finite),
|
|
2766
|
+
Schema7.Array(Schema7.Boolean)
|
|
2767
|
+
]);
|
|
2768
|
+
var EventAttributesSchema = Schema7.Record(Schema7.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
|
|
2769
|
+
var EventPropertiesSchema = Schema7.Record(Schema7.String, Schema7.Json).annotate({ identifier: "EventProperties" });
|
|
2770
|
+
var EventOptionsSchema = Schema7.Struct({
|
|
2771
|
+
userId: Schema7.optional(Schema7.NonEmptyString),
|
|
2772
|
+
anonymousId: Schema7.optional(Schema7.NonEmptyString),
|
|
2773
|
+
sessionId: Schema7.optional(Schema7.NonEmptyString),
|
|
2774
|
+
messageId: Schema7.optional(Schema7.NonEmptyString),
|
|
2775
|
+
timestamp: Schema7.optional(Schema7.DateTimeUtc),
|
|
2776
|
+
context: Schema7.optional(EventAttributesSchema)
|
|
2777
|
+
}).annotate({ identifier: "EventOptions" });
|
|
2778
|
+
var TelemetryEvent = Schema7.Struct({
|
|
2779
|
+
name: Schema7.NonEmptyString,
|
|
2780
|
+
properties: Schema7.optional(EventPropertiesSchema),
|
|
2781
|
+
options: Schema7.optional(EventOptionsSchema)
|
|
2782
|
+
}).annotate({ identifier: "TelemetryEvent" });
|
|
2783
|
+
|
|
2784
|
+
// ../../src/services/events/schema.ts
|
|
2785
|
+
var EventUuid = Schema8.String.check(Schema8.isUUID());
|
|
2786
|
+
var EventId = Schema8.NonEmptyString.check(Schema8.isMaxLength(100));
|
|
2787
|
+
var BrowserEventPath = Schema8.String.check(Schema8.isMaxLength(2048), Schema8.isPattern(/^\/(?!\/)[^?#]*$/));
|
|
2788
|
+
var EventIdentity = Schema8.Struct({
|
|
2789
|
+
userId: Schema8.optional(Schema8.NonEmptyString),
|
|
2790
|
+
organizationId: Schema8.optional(Schema8.NonEmptyString)
|
|
2791
|
+
}).annotate({ identifier: "EventIdentity" });
|
|
2792
|
+
var EventIpAddress = Schema8.String.check(Schema8.makeFilter((value) => Option4.isSome(Schema8.decodeOption(Schema8.IpAddressFromString)(value)) || "Invalid IP address")).annotate({ identifier: "EventIpAddress" });
|
|
2793
|
+
var EventCountry = Schema8.String.check(Schema8.isPattern(/^[A-Z]{2}$/), Schema8.makeFilter((value) => !["XX", "T1"].includes(value) || "Unknown country")).annotate({ identifier: "EventCountry" });
|
|
2794
|
+
var EventRegion = Schema8.String.check(Schema8.isPattern(/^[A-Z0-9]{1,3}$/)).annotate({ identifier: "EventRegion" });
|
|
2795
|
+
var EventCity = Schema8.NonEmptyString.check(Schema8.isMaxLength(128)).annotate({ identifier: "EventCity" });
|
|
2796
|
+
var EventGeolocation = Schema8.Struct({
|
|
2797
|
+
ip: Schema8.optional(EventIpAddress),
|
|
2798
|
+
country: Schema8.optional(EventCountry),
|
|
2799
|
+
region: Schema8.optional(EventRegion),
|
|
2800
|
+
city: Schema8.optional(EventCity)
|
|
2801
|
+
}).annotate({ identifier: "EventGeolocation" });
|
|
2802
|
+
|
|
2803
|
+
class EventGeolocationError extends Schema8.TaggedError()("EventGeolocationError", {}) {
|
|
2804
|
+
}
|
|
2805
|
+
var BrowserEventOptions = Schema8.Struct({
|
|
2806
|
+
messageId: Schema8.optional(EventId),
|
|
2807
|
+
timestamp: Schema8.optional(Schema8.DateTimeUtc),
|
|
2808
|
+
context: Schema8.optional(EventAttributesSchema)
|
|
2809
|
+
}).annotate({ identifier: "BrowserEventOptions" });
|
|
2810
|
+
var BrowserPage = Schema8.Struct({
|
|
2811
|
+
name: Schema8.optional(Schema8.NonEmptyString),
|
|
2812
|
+
category: Schema8.optional(Schema8.NonEmptyString),
|
|
2813
|
+
path: Schema8.optional(Schema8.NonEmptyString),
|
|
2814
|
+
properties: Schema8.optional(EventAttributesSchema),
|
|
2815
|
+
options: Schema8.optional(BrowserEventOptions)
|
|
2816
|
+
}).annotate({ identifier: "BrowserPage" });
|
|
2817
|
+
var AuditTarget = Schema8.Struct({
|
|
2818
|
+
id: Schema8.NonEmptyString.check(Schema8.isMaxLength(256)),
|
|
2819
|
+
name: Schema8.NonEmptyString.check(Schema8.isMaxLength(2048)),
|
|
2820
|
+
type: Schema8.NonEmptyString.check(Schema8.isMaxLength(128))
|
|
2821
|
+
}).annotate({ identifier: "AuditTarget" });
|
|
2822
|
+
var trackEventFields = {
|
|
2823
|
+
eventId: Schema8.optional(EventId),
|
|
2824
|
+
name: Schema8.NonEmptyString.check(Schema8.isMaxLength(128)),
|
|
2825
|
+
properties: Schema8.optional(EventPropertiesSchema),
|
|
2826
|
+
identity: Schema8.optional(EventIdentity),
|
|
2827
|
+
timestamp: Schema8.optional(Schema8.DateTimeUtc)
|
|
2828
|
+
};
|
|
2829
|
+
var TrackEvent = Schema8.Union([
|
|
2830
|
+
Schema8.Struct({
|
|
2831
|
+
...trackEventFields,
|
|
2832
|
+
category: Schema8.optional(Schema8.Literal("analytics"))
|
|
2833
|
+
}),
|
|
2834
|
+
Schema8.Struct({
|
|
2835
|
+
...trackEventFields,
|
|
2836
|
+
category: Schema8.Literal("audit"),
|
|
2837
|
+
target: AuditTarget
|
|
2838
|
+
})
|
|
2839
|
+
]).annotate({ identifier: "TrackEvent" });
|
|
2840
|
+
var EventInputProperties = Schema8.Record(Schema8.String, Schema8.Unknown).annotate({ identifier: "EventInputProperties" });
|
|
2841
|
+
var TrackEventInput = Schema8.Union([
|
|
2842
|
+
Schema8.Struct({
|
|
2843
|
+
...TrackEvent.members[0].fields,
|
|
2844
|
+
properties: Schema8.optional(EventInputProperties)
|
|
2845
|
+
}),
|
|
2846
|
+
Schema8.Struct({
|
|
2847
|
+
...TrackEvent.members[1].fields,
|
|
2848
|
+
properties: Schema8.optional(EventInputProperties)
|
|
2849
|
+
})
|
|
2850
|
+
]).annotate({ identifier: "TrackEventInput" });
|
|
2851
|
+
var EventSubscription = Schema8.Struct({
|
|
2852
|
+
name: Schema8.NonEmptyString.check(Schema8.isMaxLength(128)),
|
|
2853
|
+
events: Schema8.NonEmptyArray(trackEventFields.name)
|
|
2854
|
+
}).annotate({ identifier: "EventSubscription" });
|
|
2855
|
+
|
|
2856
|
+
class EventSubscriberError extends Schema8.TaggedError()("EventSubscriberError", { subscription: Schema8.String }) {
|
|
2857
|
+
}
|
|
2858
|
+
var EventActionFilter = Schema8.Struct({
|
|
2859
|
+
id: Schema8.Literal("eventName"),
|
|
2860
|
+
kind: Schema8.Literal("values"),
|
|
2861
|
+
values: Schema8.NonEmptyArray(trackEventFields.name)
|
|
2862
|
+
}).annotate({ identifier: "EventActionFilter" });
|
|
2863
|
+
var EventColumnFilter = ColumnFilter.check(Schema8.makeFilter((filter) => filter.id === "eventName" ? Schema8.is(EventActionFilter)(filter) : filter.id === "time" ? filter.kind === "date" : filter.id === "actor" || filter.id === "record" ? filter.kind === "text" : filter.id === "method" ? filter.kind === "values" && filter.values.every((value) => ["session", "api_key", "unknown"].includes(value)) : false)).annotate({ identifier: "EventColumnFilter" });
|
|
2864
|
+
var EventColumnFilters = ColumnFilters.check(Schema8.makeFilter((filters) => filters.every(Schema8.is(EventColumnFilter)))).annotate({ identifier: "EventColumnFilters" });
|
|
2865
|
+
var EventQuery = Schema8.Struct({
|
|
2866
|
+
...Query.fields,
|
|
2867
|
+
filters: Schema8.optional(EventColumnFilters),
|
|
2868
|
+
eventName: Schema8.optional(trackEventFields.name)
|
|
2869
|
+
}).annotate({ identifier: "EventQuery" });
|
|
2870
|
+
var EventQueryStandard = Schema8.toStandardSchemaV1(EventQuery);
|
|
2871
|
+
var ListEvents = Schema8.Struct({
|
|
2872
|
+
organizationId: Schema8.NonEmptyString,
|
|
2873
|
+
category: Schema8.Literals(["audit", "analytics"]),
|
|
2874
|
+
...EventQuery.fields
|
|
2875
|
+
}).annotate({ identifier: "ListEvents" });
|
|
2876
|
+
var AuditSortId = Schema8.Literals([
|
|
2877
|
+
"time",
|
|
2878
|
+
"eventName",
|
|
2879
|
+
"recordType",
|
|
2880
|
+
"record",
|
|
2881
|
+
"actorType",
|
|
2882
|
+
"actorId"
|
|
2883
|
+
]).annotate({ identifier: "AuditSortId" });
|
|
2884
|
+
var AuditCount = Schema8.Struct({ total: Schema8.Int }).annotate({
|
|
2885
|
+
identifier: "AuditCount"
|
|
2886
|
+
});
|
|
2887
|
+
var AuditAttribution = Schema8.Struct({
|
|
2888
|
+
"app.actor.type": Schema8.NonEmptyString,
|
|
2889
|
+
"app.actor.id": Schema8.NonEmptyString
|
|
2890
|
+
}).annotate({ identifier: "AuditAttribution" });
|
|
2891
|
+
var RequestActorAttribution = Schema8.Struct({
|
|
2892
|
+
...AuditAttribution.fields,
|
|
2893
|
+
"app.auth.method": Schema8.optional(Schema8.NonEmptyString),
|
|
2894
|
+
"app.auth.credential.id": Schema8.optional(Schema8.NonEmptyString),
|
|
2895
|
+
"app.auth.impersonator.id": Schema8.optional(Schema8.NonEmptyString),
|
|
2896
|
+
"user.roles": Schema8.optional(Schema8.Array(Schema8.String))
|
|
2897
|
+
}).annotate({ identifier: "RequestActorAttribution" });
|
|
2898
|
+
|
|
2899
|
+
class EventsPersistenceError extends Schema8.TaggedError()("EventsPersistenceError", { operation: Schema8.String }) {
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
class EventConflictError extends Schema8.TaggedError()("EventConflictError", { eventId: EventId }) {
|
|
2903
|
+
}
|
|
2904
|
+
var EventSource = Schema8.Literals(["browser", "server"]).annotate({
|
|
2905
|
+
identifier: "EventSource"
|
|
2906
|
+
});
|
|
2907
|
+
var ExistingEventRequest = Schema8.Struct({
|
|
2908
|
+
eventId: EventId,
|
|
2909
|
+
source: EventSource
|
|
2910
|
+
}).annotate({ identifier: "ExistingEventRequest" });
|
|
2911
|
+
var StoredEventRequest = Schema8.Struct({
|
|
2912
|
+
source: EventSource,
|
|
2913
|
+
event_id: EventId,
|
|
2914
|
+
event_name: Schema8.NonEmptyString,
|
|
2915
|
+
event_type: Schema8.Literals(["page", "track"]),
|
|
2916
|
+
occurred_at: Schema8.Finite,
|
|
2917
|
+
received_at: Schema8.Finite,
|
|
2918
|
+
organization_id: Schema8.NullOr(Schema8.NonEmptyString),
|
|
2919
|
+
user_id: Schema8.NullOr(Schema8.NonEmptyString),
|
|
2920
|
+
session_id: Schema8.NullOr(Schema8.NonEmptyString),
|
|
2921
|
+
anonymous_id: Schema8.NullOr(Schema8.NonEmptyString),
|
|
2922
|
+
payload_json: Schema8.String
|
|
2923
|
+
}).annotate({ identifier: "StoredEventRequest" });
|
|
2924
|
+
var StoredEventId = Schema8.Struct({
|
|
2925
|
+
event_id: EventId
|
|
2926
|
+
}).annotate({ identifier: "StoredEventId" });
|
|
2927
|
+
var PrimitiveValue = Schema8.Union([
|
|
2928
|
+
Schema8.Struct({ stringValue: Schema8.String.check(Schema8.isMaxLength(2048)) }),
|
|
2929
|
+
Schema8.Struct({
|
|
2930
|
+
intValue: Schema8.Union([
|
|
2931
|
+
Schema8.String.check(Schema8.isPattern(/^-?\d{1,20}$/)),
|
|
2932
|
+
Schema8.Int
|
|
2933
|
+
])
|
|
2934
|
+
}),
|
|
2935
|
+
Schema8.Struct({ doubleValue: Schema8.Finite }),
|
|
2936
|
+
Schema8.Struct({ boolValue: Schema8.Boolean })
|
|
2937
|
+
]);
|
|
2938
|
+
var AttributeValue = Schema8.Union([
|
|
2939
|
+
PrimitiveValue,
|
|
2940
|
+
Schema8.Struct({
|
|
2941
|
+
arrayValue: Schema8.Struct({
|
|
2942
|
+
values: Schema8.Array(PrimitiveValue).check(Schema8.isMaxLength(32))
|
|
2943
|
+
})
|
|
2944
|
+
})
|
|
2945
|
+
]);
|
|
2946
|
+
var EventAttribute = Schema8.Struct({
|
|
2947
|
+
key: Schema8.NonEmptyString.check(Schema8.isMaxLength(128)),
|
|
2948
|
+
value: Schema8.StructWithRest(Schema8.Struct({ stringValue: Schema8.optional(Schema8.String) }), [Schema8.Record(Schema8.String, Schema8.Json)])
|
|
2949
|
+
}).annotate({ identifier: "EventAttribute" });
|
|
2950
|
+
var EventLogRecord = Schema8.Struct({
|
|
2951
|
+
eventName: Schema8.NonEmptyString.check(Schema8.isMaxLength(128), Schema8.isPattern(/^[^\r\n]+$/)),
|
|
2952
|
+
timeUnixNano: Schema8.String.check(Schema8.isPattern(/^\d{1,20}$/)),
|
|
2953
|
+
observedTimeUnixNano: Schema8.optional(Schema8.String.check(Schema8.isPattern(/^\d{1,20}$/))),
|
|
2954
|
+
severityNumber: Schema8.optional(Schema8.Int),
|
|
2955
|
+
traceId: Schema8.optional(Schema8.String.check(Schema8.isPattern(/^[a-f0-9]{32}$/))),
|
|
2956
|
+
spanId: Schema8.optional(Schema8.String.check(Schema8.isPattern(/^[a-f0-9]{16}$/))),
|
|
2957
|
+
attributes: Schema8.Array(EventAttribute).check(Schema8.isMaxLength(64), Schema8.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
2958
|
+
}).annotate({ identifier: "EventLogRecord" });
|
|
2959
|
+
var BrowserEventLogRecord = Schema8.Struct({
|
|
2960
|
+
...EventLogRecord.fields,
|
|
2961
|
+
attributes: Schema8.Array(Schema8.Struct({
|
|
2962
|
+
key: EventAttribute.fields.key,
|
|
2963
|
+
value: AttributeValue
|
|
2964
|
+
})).check(Schema8.isMaxLength(64), Schema8.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
2965
|
+
}).annotate({ identifier: "BrowserEventLogRecord" });
|
|
2966
|
+
var extensions = Schema8.Record(Schema8.String, Schema8.Unknown);
|
|
2967
|
+
var OtlpLogs = Schema8.StructWithRest(Schema8.Struct({
|
|
2968
|
+
resourceLogs: Schema8.Array(Schema8.StructWithRest(Schema8.Struct({
|
|
2969
|
+
scopeLogs: Schema8.Array(Schema8.StructWithRest(Schema8.Struct({
|
|
2970
|
+
scope: Schema8.optional(Schema8.StructWithRest(Schema8.Struct({ name: Schema8.optional(Schema8.String) }), [extensions])),
|
|
2971
|
+
logRecords: Schema8.Array(Schema8.Unknown).pipe(Schema8.withDecodingDefaultKey(Effect3.succeed([])))
|
|
2972
|
+
}), [extensions])).pipe(Schema8.withDecodingDefaultKey(Effect3.succeed([])))
|
|
2973
|
+
}), [extensions])).pipe(Schema8.withDecodingDefaultKey(Effect3.succeed([])))
|
|
2974
|
+
}), [extensions]).annotate({ identifier: "EventsOtlpLogs" });
|
|
2975
|
+
var StoredEventPayload = Schema8.Struct({
|
|
2976
|
+
payload_json: Schema8.Union([OtlpLogs, Schema8.fromJsonString(OtlpLogs)])
|
|
2977
|
+
}).annotate({ identifier: "StoredEventPayload" });
|
|
2978
|
+
var VisitorEventsRequest = Schema8.Struct({
|
|
2979
|
+
visitorId: Schema8.NonEmptyString
|
|
2980
|
+
}).annotate({ identifier: "VisitorEventsRequest" });
|
|
2981
|
+
var VisitorEventSession = Schema8.Struct({
|
|
2982
|
+
event_id: EventId,
|
|
2983
|
+
session_id: Schema8.NullOr(Schema8.NonEmptyString),
|
|
2984
|
+
received_at: Schema8.Finite
|
|
2985
|
+
}).annotate({ identifier: "VisitorEventSession" });
|
|
2986
|
+
|
|
2987
|
+
// ../../src/components/audit-log-table/classes.ts
|
|
2988
|
+
var auditTableLayout = "flex min-h-0 flex-1 flex-col";
|
|
2989
|
+
|
|
2990
|
+
// ../../src/services/events/record.ts
|
|
2991
|
+
import { Option as Option5, Schema as Schema9 } from "effect";
|
|
2992
|
+
var TextValue = Schema9.Struct({ stringValue: Schema9.String }).annotate({
|
|
2993
|
+
identifier: "EventTextValue"
|
|
2994
|
+
});
|
|
2995
|
+
var TextArrayValue = Schema9.Struct({
|
|
2996
|
+
arrayValue: Schema9.Struct({ values: Schema9.Array(TextValue) })
|
|
2997
|
+
}).annotate({ identifier: "EventTextArrayValue" });
|
|
2998
|
+
var eventTextAttribute = (record, key) => Schema9.decodeUnknownOption(TextValue)(record.attributes.find((attribute) => attribute.key === key)?.value).pipe(Option5.map((value) => value.stringValue), Option5.getOrNull);
|
|
2999
|
+
|
|
3000
|
+
// ../../src/components/audit-log-table/index.ts
|
|
3001
|
+
var defaultMessages2 = {
|
|
3002
|
+
en: {
|
|
3003
|
+
title: "Activity history",
|
|
3004
|
+
event: "Action",
|
|
3005
|
+
allEvents: "All actions",
|
|
3006
|
+
time: "Time",
|
|
3007
|
+
action: "Action",
|
|
3008
|
+
target: "Target",
|
|
3009
|
+
actor: "Actor",
|
|
3010
|
+
method: "Method",
|
|
3011
|
+
actorMember: "Member",
|
|
3012
|
+
impersonatedBy: "Impersonated by",
|
|
3013
|
+
actorOrganization: "Organization",
|
|
3014
|
+
methodApiKey: "API Key",
|
|
3015
|
+
methodSession: "User session",
|
|
3016
|
+
methodUnknown: "Unknown"
|
|
3017
|
+
},
|
|
3018
|
+
fr: {
|
|
3019
|
+
title: "Historique d’activité",
|
|
3020
|
+
event: "Action",
|
|
3021
|
+
allEvents: "Toutes les actions",
|
|
3022
|
+
time: "Date",
|
|
3023
|
+
action: "Action",
|
|
3024
|
+
target: "Cible",
|
|
3025
|
+
actor: "Acteur",
|
|
3026
|
+
method: "Méthode",
|
|
3027
|
+
actorMember: "Membre",
|
|
3028
|
+
impersonatedBy: "Identité empruntée par",
|
|
3029
|
+
actorOrganization: "Organisation",
|
|
3030
|
+
methodApiKey: "Clé API",
|
|
3031
|
+
methodSession: "Session utilisateur",
|
|
3032
|
+
methodUnknown: "Inconnue"
|
|
3033
|
+
}
|
|
3034
|
+
};
|
|
3035
|
+
var auditLogMessages = (locale, messages) => {
|
|
3036
|
+
const base = locale.split("-")[0];
|
|
3037
|
+
return {
|
|
3038
|
+
...base === "fr" ? defaultMessages2.fr : defaultMessages2.en,
|
|
3039
|
+
...messages?.[base],
|
|
3040
|
+
...messages?.[locale]
|
|
3041
|
+
};
|
|
3042
|
+
};
|
|
3043
|
+
var auditTableState = (state) => state?.eventName && !state.filters?.some(({ id }) => id === "eventName") ? {
|
|
3044
|
+
...state,
|
|
3045
|
+
filters: [
|
|
3046
|
+
...state.filters ?? [],
|
|
3047
|
+
{ id: "eventName", kind: "values", values: [state.eventName] }
|
|
3048
|
+
]
|
|
3049
|
+
} : state;
|
|
3050
|
+
var auditRowId = (entry) => eventTextAttribute(entry, "log.record.uid") ?? `${entry.timeUnixNano}:${entry.eventName}`;
|
|
3051
|
+
var auditRowTime = (entry) => Number(BigInt(entry.timeUnixNano) / 1000000n);
|
|
3052
|
+
var auditActionLabel = (entry, events) => events.find(({ value }) => value === entry.eventName)?.label ?? entry.eventName;
|
|
3053
|
+
var auditActor = (entry, labels) => {
|
|
3054
|
+
const type = eventTextAttribute(entry, "app.actor.type");
|
|
3055
|
+
const userId = eventTextAttribute(entry, "user.id");
|
|
3056
|
+
const id = eventTextAttribute(entry, "app.actor.id") ?? userId;
|
|
3057
|
+
if (type === "organization")
|
|
3058
|
+
return { label: labels.actorOrganization, description: id ?? undefined };
|
|
3059
|
+
if (type === "user" || userId !== null) {
|
|
3060
|
+
const name = eventTextAttribute(entry, "user.full_name") || eventTextAttribute(entry, "user.name");
|
|
3061
|
+
const email = eventTextAttribute(entry, "user.email");
|
|
3062
|
+
return {
|
|
3063
|
+
label: name || email || labels.actorMember,
|
|
3064
|
+
description: (name ? email || id : id) ?? undefined
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
return { label: type ?? labels.actor, description: id ?? undefined };
|
|
3068
|
+
};
|
|
3069
|
+
var auditTarget = (entry, labels) => {
|
|
3070
|
+
const id = eventTextAttribute(entry, "app.audit.target.id");
|
|
3071
|
+
const name = eventTextAttribute(entry, "app.audit.target.name");
|
|
3072
|
+
const type = eventTextAttribute(entry, "app.audit.target.type");
|
|
3073
|
+
return id === null ? null : {
|
|
3074
|
+
label: name && name !== id ? name : type || labels.target,
|
|
3075
|
+
description: name && name !== id && type ? `${type} · ${id}` : id
|
|
3076
|
+
};
|
|
3077
|
+
};
|
|
3078
|
+
var auditImpersonation = (entry, labels) => {
|
|
3079
|
+
const id = eventTextAttribute(entry, "app.auth.impersonator.id");
|
|
3080
|
+
return id === null ? undefined : `${labels.impersonatedBy}: ${id}`;
|
|
3081
|
+
};
|
|
3082
|
+
var auditMethod = (entry) => {
|
|
3083
|
+
const method = eventTextAttribute(entry, "app.auth.method");
|
|
3084
|
+
return method === "session" || method === "api_key" ? method : "unknown";
|
|
3085
|
+
};
|
|
3086
|
+
var auditMethods = (labels) => ({
|
|
3087
|
+
session: labels.methodSession,
|
|
3088
|
+
api_key: labels.methodApiKey,
|
|
3089
|
+
unknown: labels.methodUnknown
|
|
3090
|
+
});
|
|
3091
|
+
|
|
3092
|
+
// ../../src/components/audit-log-table/schema.ts
|
|
3093
|
+
import { Schema as Schema10 } from "effect";
|
|
3094
|
+
var AuditLogMessagesSchema = Schema10.Struct({
|
|
3095
|
+
title: Schema10.String,
|
|
3096
|
+
event: Schema10.String,
|
|
3097
|
+
allEvents: Schema10.String,
|
|
3098
|
+
time: Schema10.String,
|
|
3099
|
+
action: Schema10.String,
|
|
3100
|
+
target: Schema10.String,
|
|
3101
|
+
actor: Schema10.String,
|
|
3102
|
+
method: Schema10.String,
|
|
3103
|
+
actorMember: Schema10.String,
|
|
3104
|
+
impersonatedBy: Schema10.String,
|
|
3105
|
+
actorOrganization: Schema10.String,
|
|
3106
|
+
methodApiKey: Schema10.String,
|
|
3107
|
+
methodSession: Schema10.String,
|
|
3108
|
+
methodUnknown: Schema10.String
|
|
3109
|
+
}).annotate({ identifier: "AuditLogMessages" });
|
|
3110
|
+
var AuditLogTablePropsSchema = Schema10.Struct({
|
|
3111
|
+
entries: Schema10.Array(EventLogRecord),
|
|
3112
|
+
rowCount: Schema10.Int.check(Schema10.isGreaterThanOrEqualTo(0)),
|
|
3113
|
+
events: Schema10.optionalKey(Schema10.Array(Schema10.Struct({ value: Schema10.String, label: Schema10.String }))),
|
|
3114
|
+
state: Schema10.optionalKey(EventQuery),
|
|
3115
|
+
timeZone: Schema10.optionalKey(Schema10.String),
|
|
3116
|
+
locale: Schema10.optionalKey(Schema10.String),
|
|
3117
|
+
messages: Schema10.optionalKey(Schema10.Record(Schema10.String, AuditLogMessagesSchema.mapFields((fields) => ({
|
|
3118
|
+
title: Schema10.optional(fields.title),
|
|
3119
|
+
event: Schema10.optional(fields.event),
|
|
3120
|
+
allEvents: Schema10.optional(fields.allEvents),
|
|
3121
|
+
time: Schema10.optional(fields.time),
|
|
3122
|
+
action: Schema10.optional(fields.action),
|
|
3123
|
+
target: Schema10.optional(fields.target),
|
|
3124
|
+
actor: Schema10.optional(fields.actor),
|
|
3125
|
+
method: Schema10.optional(fields.method),
|
|
3126
|
+
actorMember: Schema10.optional(fields.actorMember),
|
|
3127
|
+
impersonatedBy: Schema10.optional(fields.impersonatedBy),
|
|
3128
|
+
actorOrganization: Schema10.optional(fields.actorOrganization),
|
|
3129
|
+
methodApiKey: Schema10.optional(fields.methodApiKey),
|
|
3130
|
+
methodSession: Schema10.optional(fields.methodSession),
|
|
3131
|
+
methodUnknown: Schema10.optional(fields.methodUnknown)
|
|
3132
|
+
})))),
|
|
3133
|
+
loading: Schema10.optionalKey(Schema10.Boolean),
|
|
3134
|
+
error: Schema10.optionalKey(Schema10.String),
|
|
3135
|
+
empty: Schema10.optionalKey(Schema10.String)
|
|
3136
|
+
}).annotate({ identifier: "AuditLogTableProps" });
|
|
3137
|
+
|
|
3138
|
+
// ../../src/components/audit-log-table/html.ts
|
|
3139
|
+
var StateChanged = UiSchema4.TaggedEnum({
|
|
3140
|
+
StateChanged: { state: EventQuery }
|
|
3141
|
+
});
|
|
3142
|
+
var options = {
|
|
3143
|
+
name: "AuditLogTable",
|
|
3144
|
+
props: AuditLogTablePropsSchema,
|
|
3145
|
+
model: Schema11.Null,
|
|
3146
|
+
message: StateChanged,
|
|
3147
|
+
events: StateChanged,
|
|
3148
|
+
restore: false
|
|
3149
|
+
};
|
|
3150
|
+
var update3 = Component3.define(options).update({
|
|
3151
|
+
StateChanged: ($, { state: { eventName: _legacy, ...state } }) => $.emit(StateChanged.StateChanged({ state }))
|
|
3152
|
+
});
|
|
3153
|
+
var AuditLogTable = Html3.component({
|
|
3154
|
+
...options,
|
|
3155
|
+
reads: { locale: krakstackLocaleRead3 }
|
|
3156
|
+
}).make({
|
|
3157
|
+
init: () => null,
|
|
3158
|
+
update: update3,
|
|
3159
|
+
view: (h) => {
|
|
3160
|
+
const {
|
|
3161
|
+
entries,
|
|
3162
|
+
events = [],
|
|
3163
|
+
rowCount,
|
|
3164
|
+
timeZone = "America/New_York",
|
|
3165
|
+
state,
|
|
3166
|
+
loading,
|
|
3167
|
+
empty,
|
|
3168
|
+
error
|
|
3169
|
+
} = h.props;
|
|
3170
|
+
const locale = h.props.locale ?? h.reads.locale?.locale ?? "en";
|
|
3171
|
+
const labels = auditLogMessages(locale, h.props.messages);
|
|
3172
|
+
const methods = auditMethods(labels);
|
|
3173
|
+
const tableState = auditTableState(state);
|
|
3174
|
+
const actionOptions = new Map(events.map(({ value, label }) => [value, label]));
|
|
3175
|
+
const actionFilter = tableState?.filters?.find(({ id }) => id === "eventName");
|
|
3176
|
+
if (actionFilter?.kind === "values") {
|
|
3177
|
+
for (const value of actionFilter.values) {
|
|
3178
|
+
if (!actionOptions.has(value))
|
|
3179
|
+
actionOptions.set(value, value);
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
const columns = [
|
|
3183
|
+
{
|
|
3184
|
+
id: "time",
|
|
3185
|
+
headerName: labels.time,
|
|
3186
|
+
type: "dateTime",
|
|
3187
|
+
typeOptions: { timeZone }
|
|
3188
|
+
},
|
|
3189
|
+
{
|
|
3190
|
+
id: "eventName",
|
|
3191
|
+
headerName: labels.action,
|
|
3192
|
+
type: "list",
|
|
3193
|
+
filterOptions: Array.from(actionOptions, ([value, label]) => ({
|
|
3194
|
+
value,
|
|
3195
|
+
label
|
|
3196
|
+
})),
|
|
3197
|
+
filterable: actionOptions.size > 0
|
|
3198
|
+
},
|
|
3199
|
+
{ id: "record", headerName: labels.target, type: "reference" },
|
|
3200
|
+
{
|
|
3201
|
+
id: "actor",
|
|
3202
|
+
headerName: labels.actor,
|
|
3203
|
+
type: "reference",
|
|
3204
|
+
sortable: false
|
|
3205
|
+
},
|
|
3206
|
+
{
|
|
3207
|
+
id: "method",
|
|
3208
|
+
headerName: labels.method,
|
|
3209
|
+
type: "list",
|
|
3210
|
+
sortable: false,
|
|
3211
|
+
filterOptions: Object.entries(methods).map(([value, label]) => ({
|
|
3212
|
+
value,
|
|
3213
|
+
label
|
|
3214
|
+
}))
|
|
3215
|
+
}
|
|
3216
|
+
];
|
|
3217
|
+
return h.section.class(auditTableLayout).attr("aria-label", labels.title).children(DataTable(h, {
|
|
3218
|
+
props: {
|
|
3219
|
+
label: labels.title,
|
|
3220
|
+
locale,
|
|
3221
|
+
columnDefs: columns,
|
|
3222
|
+
state: tableState,
|
|
3223
|
+
status: { loading, error, empty },
|
|
3224
|
+
features: {
|
|
3225
|
+
filtering: state !== undefined,
|
|
3226
|
+
pagination: { mode: "server", rowCount },
|
|
3227
|
+
virtualization: { scroll: "internal" }
|
|
3228
|
+
},
|
|
3229
|
+
rowData: entries.map((entry) => {
|
|
3230
|
+
const actor = auditActor(entry, labels);
|
|
3231
|
+
const impersonation = auditImpersonation(entry, labels);
|
|
3232
|
+
const description = [actor.description, impersonation].filter(Boolean).join(" · ");
|
|
3233
|
+
const method = auditMethod(entry);
|
|
3234
|
+
const action = auditActionLabel(entry, events);
|
|
3235
|
+
return {
|
|
3236
|
+
id: auditRowId(entry),
|
|
3237
|
+
label: action,
|
|
3238
|
+
cells: {
|
|
3239
|
+
time: auditRowTime(entry),
|
|
3240
|
+
eventName: [
|
|
3241
|
+
{
|
|
3242
|
+
value: entry.eventName,
|
|
3243
|
+
label: action
|
|
3244
|
+
}
|
|
3245
|
+
],
|
|
3246
|
+
record: auditTarget(entry, labels),
|
|
3247
|
+
actor: description ? { label: actor.label, description } : { label: actor.label },
|
|
3248
|
+
method: [{ value: method, label: methods[method] }]
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
})
|
|
3252
|
+
},
|
|
3253
|
+
onEmit: (event) => event._tag === "StateChanged" ? StateChanged.StateChanged({ state: event.state }) : undefined
|
|
3254
|
+
}));
|
|
3255
|
+
}
|
|
3256
|
+
});
|
|
3257
|
+
export {
|
|
3258
|
+
EventQuery as AuditLogQuerySchema,
|
|
3259
|
+
AuditLogTable
|
|
3260
|
+
};
|