@duskmoon-dev/components 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/classes/index.d.ts +0 -1
  2. package/dist/classes/index.js +96 -31
  3. package/dist/components/alert/Alert.types.d.ts +1 -1
  4. package/dist/components/alert/index.js +6 -0
  5. package/dist/components/auto-complete/AutoComplete.types.d.ts +1 -1
  6. package/dist/components/auto-complete/index.js +3 -0
  7. package/dist/components/badge/Badge.types.d.ts +1 -1
  8. package/dist/components/badge/index.js +4 -0
  9. package/dist/components/button/Button.types.d.ts +1 -1
  10. package/dist/components/button/index.js +3 -0
  11. package/dist/components/checkbox/Checkbox.types.d.ts +1 -1
  12. package/dist/components/checkbox/index.js +8 -1
  13. package/dist/components/divider/Divider.types.d.ts +1 -1
  14. package/dist/components/divider/index.js +8 -2
  15. package/dist/components/dm-drawer/index.js +3 -0
  16. package/dist/components/dm-page-header/index.js +3 -0
  17. package/dist/components/dm-pro-table/DmProTable.d.ts +1 -1
  18. package/dist/components/dm-pro-table/DmProTable.types.d.ts +3 -2
  19. package/dist/components/dm-pro-table/index.js +11 -20
  20. package/dist/components/dm-query/index.js +3 -0
  21. package/dist/components/dm-search/index.js +3 -0
  22. package/dist/components/dm-table/index.js +3 -0
  23. package/dist/components/dm-toolbar/index.js +3 -0
  24. package/dist/components/dropdown/index.js +3 -0
  25. package/dist/components/popconfirm/index.js +3 -0
  26. package/dist/components/progress/Progress.types.d.ts +1 -1
  27. package/dist/components/progress/index.js +6 -3
  28. package/dist/components/radio/Radio.types.d.ts +1 -1
  29. package/dist/components/radio/index.js +8 -1
  30. package/dist/components/rate/Rate.types.d.ts +1 -1
  31. package/dist/components/rate/index.js +8 -2
  32. package/dist/components/slider/Slider.types.d.ts +1 -1
  33. package/dist/components/slider/index.js +9 -2
  34. package/dist/components/switch/Switch.types.d.ts +1 -1
  35. package/dist/components/switch/index.js +8 -1
  36. package/dist/components/tag/Tag.types.d.ts +1 -1
  37. package/dist/components/tag/index.js +5 -2
  38. package/dist/components/timeline/Timeline.types.d.ts +1 -1
  39. package/dist/components/timeline/index.js +6 -1
  40. package/dist/components/tour/index.js +3 -0
  41. package/dist/generated/version.d.ts +1 -1
  42. package/dist/index.d.ts +0 -1
  43. package/dist/index.js +432 -377
  44. package/dist/infrastructure.js +1 -1
  45. package/dist/styles.css +502 -0
  46. package/package.json +1 -5
  47. package/dist/classes/dm-pro-table-inner.d.ts +0 -1
  48. package/dist/components/dm-pro-table-inner/DmProTableInner.d.ts +0 -7
  49. package/dist/components/dm-pro-table-inner/DmProTableInner.types.d.ts +0 -5
  50. package/dist/components/dm-pro-table-inner/index.d.ts +0 -2
  51. package/dist/components/dm-pro-table-inner/index.js +0 -2622
@@ -1,2622 +0,0 @@
1
- "use client";
2
-
3
- // ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
4
- function r(e) {
5
- var t, f, n = "";
6
- if (typeof e == "string" || typeof e == "number")
7
- n += e;
8
- else if (typeof e == "object")
9
- if (Array.isArray(e)) {
10
- var o = e.length;
11
- for (t = 0;t < o; t++)
12
- e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
13
- } else
14
- for (f in e)
15
- e[f] && (n && (n += " "), n += f);
16
- return n;
17
- }
18
- function clsx() {
19
- for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
20
- (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
21
- return n;
22
- }
23
-
24
- // src/utils/cn.ts
25
- function cn(...inputs) {
26
- return clsx(inputs);
27
- }
28
- // src/classes/button.ts
29
- var buttonBaseClass = "btn";
30
- var buttonColorClasses = {
31
- primary: "btn-primary",
32
- secondary: "btn-secondary",
33
- tertiary: "btn-tertiary",
34
- info: "btn-info",
35
- success: "btn-success",
36
- warning: "btn-warning",
37
- error: "btn-error"
38
- };
39
- var buttonAppearanceClasses = {
40
- filled: "",
41
- outline: "btn-outline",
42
- tonal: "btn-tonal",
43
- ghost: "btn-ghost",
44
- text: "btn-text"
45
- };
46
- var buttonShapeClasses = {
47
- rect: "",
48
- circle: "btn-circle",
49
- square: "btn-square"
50
- };
51
- var buttonSizeClasses = {
52
- xs: "btn-xs",
53
- sm: "btn-sm",
54
- md: "btn-md",
55
- lg: "btn-lg"
56
- };
57
- var buttonBlockClass = "btn-block";
58
- var buttonIsLoadingClass = "btn-loading";
59
- function getButtonClasses({
60
- color = "primary",
61
- appearance = "filled",
62
- shape = "rect",
63
- size = "md",
64
- block,
65
- isLoading,
66
- className
67
- }) {
68
- return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
69
- }
70
-
71
- // src/components/button/Button.tsx
72
- import { jsx, jsxs } from "react/jsx-runtime";
73
- function Button({
74
- color = "primary",
75
- appearance = "filled",
76
- shape = "rect",
77
- size = "md",
78
- block,
79
- isLoading,
80
- leftIcon,
81
- rightIcon,
82
- className,
83
- children,
84
- disabled,
85
- ref,
86
- ...props
87
- }) {
88
- const classes = getButtonClasses({
89
- color,
90
- appearance,
91
- shape,
92
- size,
93
- block,
94
- isLoading,
95
- className
96
- });
97
- return /* @__PURE__ */ jsxs("button", {
98
- ref,
99
- className: classes,
100
- disabled: disabled || isLoading,
101
- "aria-busy": isLoading,
102
- "aria-disabled": disabled || isLoading,
103
- ...props,
104
- children: [
105
- isLoading && /* @__PURE__ */ jsx("span", {
106
- className: "btn-spinner"
107
- }),
108
- !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
109
- className: "btn-icon-left",
110
- children: leftIcon
111
- }),
112
- /* @__PURE__ */ jsx("span", {
113
- className: "btn-content",
114
- children
115
- }),
116
- !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
117
- className: "btn-icon-right",
118
- children: rightIcon
119
- })
120
- ]
121
- });
122
- }
123
- // src/classes/card.ts
124
- var cardBaseClass = "card";
125
- var cardAppearanceClasses = {
126
- elevated: "card-elevated",
127
- outline: "card-outline",
128
- filled: "card-filled"
129
- };
130
- var cardPaddingClasses = {
131
- none: "card-padding-none",
132
- sm: "card-padding-sm",
133
- md: "card-padding-md",
134
- lg: "card-padding-lg"
135
- };
136
- function getCardClasses({
137
- appearance = "elevated",
138
- padding = "md",
139
- className
140
- }) {
141
- return cn(cardBaseClass, cardAppearanceClasses[appearance], cardPaddingClasses[padding], className);
142
- }
143
-
144
- // src/components/card/Card.tsx
145
- import { jsx as jsx2 } from "react/jsx-runtime";
146
- function Card({
147
- appearance = "elevated",
148
- padding = "md",
149
- className,
150
- children,
151
- ref,
152
- ...props
153
- }) {
154
- const classes = getCardClasses({
155
- appearance,
156
- padding,
157
- className
158
- });
159
- return /* @__PURE__ */ jsx2("div", {
160
- ref,
161
- className: classes,
162
- ...props,
163
- children
164
- });
165
- }
166
- // src/components/date-picker/DatePicker.tsx
167
- import { forwardRef, useMemo, useState } from "react";
168
-
169
- // src/classes/date-picker.ts
170
- var datePickerBaseClass = "datepicker";
171
- var datePickerInputClass = "datepicker-input";
172
- var datePickerIconClass = "datepicker-icon";
173
- var datePickerDropdownClass = "datepicker-dropdown";
174
- var datePickerDropdownOpenClass = "datepicker-dropdown-open";
175
- var datePickerFooterClass = "datepicker-footer";
176
- var datePickerPresetClass = "datepicker-preset";
177
- var datePickerRangeClass = "datepicker-range";
178
- var datePickerSeparatorClass = "datepicker-range-separator";
179
- var datePickerClearClass = "datepicker-clear";
180
- var datePickerSizeClasses = {
181
- sm: "datepicker-sm",
182
- md: "",
183
- lg: "datepicker-lg"
184
- };
185
- var datePickerStatusClasses = {
186
- error: "datepicker-error",
187
- success: "datepicker-success"
188
- };
189
- var datePickerPickerClasses = {
190
- date: "",
191
- week: "datepicker-week",
192
- month: "datepicker-month-picker",
193
- quarter: "datepicker-quarter-picker",
194
- year: "datepicker-year-picker",
195
- time: "datepicker-time-picker"
196
- };
197
- function getDatePickerClasses({
198
- size = "md",
199
- status,
200
- picker = "date",
201
- open,
202
- disabled,
203
- range,
204
- className
205
- }) {
206
- return cn(datePickerBaseClass, datePickerSizeClasses[size], status && datePickerStatusClasses[status], datePickerPickerClasses[picker], open && "datepicker-open", disabled && "datepicker-disabled", range && datePickerRangeClass, className);
207
- }
208
- function getDatePickerDropdownClasses({
209
- open,
210
- className
211
- }) {
212
- return cn(datePickerDropdownClass, open && datePickerDropdownOpenClass, className);
213
- }
214
-
215
- // src/components/date-picker/DatePicker.tsx
216
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
217
- function todayValue(picker) {
218
- const today = new Date;
219
- const year = today.getFullYear();
220
- const month = String(today.getMonth() + 1).padStart(2, "0");
221
- const day = String(today.getDate()).padStart(2, "0");
222
- if (picker === "month")
223
- return `${year}-${month}`;
224
- if (picker === "year")
225
- return String(year);
226
- if (picker === "time")
227
- return "00:00";
228
- return `${year}-${month}-${day}`;
229
- }
230
- function inputTypeForPicker(picker) {
231
- if (picker === "month")
232
- return "month";
233
- if (picker === "week")
234
- return "week";
235
- if (picker === "time")
236
- return "time";
237
- return picker === "year" || picker === "quarter" ? "text" : "date";
238
- }
239
- function placeholderForPicker(picker) {
240
- if (picker === "month")
241
- return "Select month";
242
- if (picker === "week")
243
- return "Select week";
244
- if (picker === "quarter")
245
- return "Select quarter";
246
- if (picker === "year")
247
- return "Select year";
248
- if (picker === "time")
249
- return "Select time";
250
- return "Select date";
251
- }
252
- function normalizeDateValue(value) {
253
- return typeof value === "string" && value.length > 0 ? value : undefined;
254
- }
255
- var DatePickerRoot = forwardRef(({
256
- allowClear,
257
- className,
258
- defaultOpen,
259
- defaultValue,
260
- disabled,
261
- disabledDate,
262
- onBlur,
263
- onChange,
264
- onFocus,
265
- onOpenChange,
266
- open,
267
- picker = "date",
268
- placeholder,
269
- presets,
270
- showNow,
271
- size = "md",
272
- status,
273
- value,
274
- ...props
275
- }, ref) => {
276
- const isValueControlled = value !== undefined;
277
- const isOpenControlled = open !== undefined;
278
- const [innerValue, setInnerValue] = useState(() => normalizeDateValue(defaultValue));
279
- const [innerOpen, setInnerOpen] = useState(Boolean(defaultOpen));
280
- const currentValue = isValueControlled ? normalizeDateValue(value) : innerValue;
281
- const visible = isOpenControlled ? Boolean(open) : innerOpen;
282
- const inputType = inputTypeForPicker(picker);
283
- function setVisible(nextOpen) {
284
- if (!isOpenControlled) {
285
- setInnerOpen(nextOpen);
286
- }
287
- onOpenChange?.(nextOpen);
288
- }
289
- function emitChange(nextValue) {
290
- if (nextValue && disabledDate?.(nextValue)) {
291
- return;
292
- }
293
- if (!isValueControlled) {
294
- setInnerValue(nextValue);
295
- }
296
- onChange?.(nextValue, nextValue ?? "");
297
- }
298
- const presetItems = useMemo(() => presets ?? [], [presets]);
299
- return /* @__PURE__ */ jsxs2("div", {
300
- ...props,
301
- ref,
302
- className: getDatePickerClasses({
303
- size,
304
- status,
305
- picker,
306
- open: visible,
307
- disabled,
308
- className
309
- }),
310
- children: [
311
- /* @__PURE__ */ jsx3("input", {
312
- className: datePickerInputClass,
313
- disabled,
314
- type: inputType,
315
- value: currentValue ?? "",
316
- placeholder: placeholder ?? placeholderForPicker(picker),
317
- onFocus: (event) => {
318
- onFocus?.(event);
319
- setVisible(true);
320
- },
321
- onBlur: (event) => {
322
- onBlur?.(event);
323
- setVisible(false);
324
- },
325
- onChange: (event) => emitChange(event.currentTarget.value || undefined)
326
- }),
327
- allowClear && currentValue && !disabled ? /* @__PURE__ */ jsx3("button", {
328
- type: "button",
329
- className: datePickerClearClass,
330
- "aria-label": "Clear date",
331
- onMouseDown: (event) => event.preventDefault(),
332
- onClick: () => emitChange(undefined),
333
- children: "x"
334
- }) : null,
335
- /* @__PURE__ */ jsx3("span", {
336
- className: datePickerIconClass,
337
- "aria-hidden": "true"
338
- }),
339
- (presetItems.length > 0 || showNow) && visible ? /* @__PURE__ */ jsxs2("div", {
340
- className: getDatePickerDropdownClasses({ open: visible }),
341
- children: [
342
- presetItems.map((preset, index) => /* @__PURE__ */ jsx3("button", {
343
- type: "button",
344
- className: datePickerPresetClass,
345
- onMouseDown: (event) => event.preventDefault(),
346
- onClick: () => emitChange(preset.value),
347
- children: preset.label
348
- }, index)),
349
- showNow ? /* @__PURE__ */ jsx3("div", {
350
- className: datePickerFooterClass,
351
- children: /* @__PURE__ */ jsx3("button", {
352
- type: "button",
353
- onMouseDown: (event) => event.preventDefault(),
354
- onClick: () => emitChange(todayValue(picker)),
355
- children: "Now"
356
- })
357
- }) : null
358
- ]
359
- }) : null
360
- ]
361
- });
362
- });
363
- DatePickerRoot.displayName = "DatePicker";
364
- var RangePicker = forwardRef(({
365
- allowClear,
366
- className,
367
- defaultValue,
368
- disabled,
369
- disabledDate,
370
- onChange,
371
- picker = "date",
372
- placeholder,
373
- separator = "-",
374
- size = "md",
375
- status,
376
- value,
377
- ...props
378
- }, ref) => {
379
- const isControlled = value !== undefined;
380
- const [innerValue, setInnerValue] = useState(defaultValue ?? [undefined, undefined]);
381
- const currentValue = isControlled ? value : innerValue;
382
- const inputType = inputTypeForPicker(picker);
383
- function emitChange(nextValue) {
384
- if (nextValue.some((item) => item !== undefined && Boolean(disabledDate?.(item)))) {
385
- return;
386
- }
387
- if (!isControlled) {
388
- setInnerValue(nextValue);
389
- }
390
- onChange?.(nextValue, [nextValue[0] ?? "", nextValue[1] ?? ""]);
391
- }
392
- function updateIndex(index, nextItem) {
393
- emitChange(index === 0 ? [nextItem, currentValue?.[1]] : [currentValue?.[0], nextItem]);
394
- }
395
- return /* @__PURE__ */ jsxs2("div", {
396
- ...props,
397
- ref,
398
- className: getDatePickerClasses({
399
- size,
400
- status,
401
- picker,
402
- disabled,
403
- range: true,
404
- className
405
- }),
406
- children: [
407
- /* @__PURE__ */ jsx3("input", {
408
- className: datePickerInputClass,
409
- disabled,
410
- type: inputType,
411
- value: currentValue?.[0] ?? "",
412
- placeholder: Array.isArray(placeholder) ? placeholder[0] : "Start date",
413
- onChange: (event) => updateIndex(0, event.currentTarget.value || undefined)
414
- }),
415
- /* @__PURE__ */ jsx3("span", {
416
- className: datePickerSeparatorClass,
417
- children: separator
418
- }),
419
- /* @__PURE__ */ jsx3("input", {
420
- className: datePickerInputClass,
421
- disabled,
422
- type: inputType,
423
- value: currentValue?.[1] ?? "",
424
- placeholder: Array.isArray(placeholder) ? placeholder[1] : "End date",
425
- onChange: (event) => updateIndex(1, event.currentTarget.value || undefined)
426
- }),
427
- allowClear && (currentValue?.[0] || currentValue?.[1]) && !disabled ? /* @__PURE__ */ jsx3("button", {
428
- type: "button",
429
- className: datePickerClearClass,
430
- "aria-label": "Clear date range",
431
- onClick: () => emitChange([undefined, undefined]),
432
- children: "x"
433
- }) : null
434
- ]
435
- });
436
- });
437
- RangePicker.displayName = "DatePicker.RangePicker";
438
- function withPicker(picker, displayName) {
439
- const Picker = forwardRef((props, ref) => /* @__PURE__ */ jsx3(DatePickerRoot, {
440
- ...props,
441
- ref,
442
- picker
443
- }));
444
- Picker.displayName = displayName;
445
- return Picker;
446
- }
447
- var DatePicker = Object.assign(DatePickerRoot, {
448
- RangePicker,
449
- WeekPicker: withPicker("week", "DatePicker.WeekPicker"),
450
- MonthPicker: withPicker("month", "DatePicker.MonthPicker"),
451
- QuarterPicker: withPicker("quarter", "DatePicker.QuarterPicker"),
452
- YearPicker: withPicker("year", "DatePicker.YearPicker")
453
- });
454
- // src/components/pagination/Pagination.tsx
455
- import {
456
- forwardRef as forwardRef2,
457
- useMemo as useMemo2,
458
- useState as useState2
459
- } from "react";
460
-
461
- // src/classes/pagination.ts
462
- var paginationBaseClass = "pagination";
463
- var paginationItemClass = "pagination-item";
464
- var paginationItemActiveClass = "pagination-item-active";
465
- var paginationItemDisabledClass = "pagination-item-disabled";
466
- var paginationPrevClass = "pagination-prev";
467
- var paginationNextClass = "pagination-next";
468
- var paginationEllipsisClass = "pagination-ellipsis";
469
- var paginationCompactClass = "pagination-compact";
470
- var paginationInfoClass = "pagination-info";
471
- var paginationInfoTextClass = "pagination-info-text";
472
- var paginationInputClass = "pagination-input";
473
- var paginationResponsiveClass = "pagination-responsive";
474
- var paginationSizeClasses = {
475
- sm: "pagination-sm",
476
- md: "",
477
- lg: "pagination-lg"
478
- };
479
- function getPaginationClasses({
480
- size = "md",
481
- compact,
482
- className
483
- }) {
484
- return cn(paginationBaseClass, paginationResponsiveClass, paginationSizeClasses[size], compact && paginationCompactClass, className);
485
- }
486
- function getPaginationItemClasses({
487
- active,
488
- disabled
489
- }) {
490
- return cn(paginationItemClass, active && paginationItemActiveClass, disabled && paginationItemDisabledClass);
491
- }
492
-
493
- // src/components/pagination/Pagination.tsx
494
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
495
- var defaultPageSizeOptions = [10, 20, 50, 100];
496
- function toPositiveInteger(value, fallback) {
497
- if (!Number.isFinite(value) || value === undefined) {
498
- return fallback;
499
- }
500
- return Math.max(1, Math.floor(value));
501
- }
502
- function clampPage(page, pageCount) {
503
- return Math.min(pageCount, Math.max(1, Math.floor(page)));
504
- }
505
- function getPageCount(total, pageSize) {
506
- return Math.max(1, Math.ceil(Math.max(0, total) / pageSize));
507
- }
508
- function getRange(current, pageSize, total) {
509
- if (total <= 0) {
510
- return [0, 0];
511
- }
512
- const start = (current - 1) * pageSize + 1;
513
- const end = Math.min(total, current * pageSize);
514
- return [start, end];
515
- }
516
- function getPageTokens(current, pageCount) {
517
- if (pageCount <= 7) {
518
- return Array.from({ length: pageCount }, (_, index) => index + 1);
519
- }
520
- const pages = new Set([1, pageCount, current - 1, current, current + 1]);
521
- if (current <= 4) {
522
- [2, 3, 4, 5].forEach((page) => pages.add(page));
523
- }
524
- if (current >= pageCount - 3) {
525
- [pageCount - 4, pageCount - 3, pageCount - 2, pageCount - 1].forEach((page) => pages.add(page));
526
- }
527
- const sortedPages = Array.from(pages).filter((page) => page >= 1 && page <= pageCount).sort((first, second) => first - second);
528
- return sortedPages.reduce((tokens, page) => {
529
- const previous = tokens[tokens.length - 1];
530
- if (typeof previous === "number") {
531
- const gap = page - previous;
532
- if (gap === 2) {
533
- tokens.push(previous + 1);
534
- } else if (gap > 2) {
535
- tokens.push("ellipsis");
536
- }
537
- }
538
- tokens.push(page);
539
- return tokens;
540
- }, []);
541
- }
542
- function getSizeOptions(pageSize) {
543
- return Array.from(new Set([...defaultPageSizeOptions, pageSize])).sort((first, second) => first - second);
544
- }
545
- var Pagination = forwardRef2(({
546
- current,
547
- defaultCurrent = 1,
548
- pageSize,
549
- defaultPageSize = 10,
550
- total = 0,
551
- onChange,
552
- disabled,
553
- simple,
554
- showSizeChanger,
555
- showQuickJumper,
556
- showTotal,
557
- size = "md",
558
- className,
559
- ...props
560
- }, ref) => {
561
- const isCurrentControlled = current !== undefined;
562
- const isPageSizeControlled = pageSize !== undefined;
563
- const [internalCurrent, setInternalCurrent] = useState2(defaultCurrent);
564
- const [internalPageSize, setInternalPageSize] = useState2(defaultPageSize);
565
- const [quickJumpValue, setQuickJumpValue] = useState2("");
566
- const mergedPageSize = toPositiveInteger(pageSize ?? internalPageSize, defaultPageSize);
567
- const pageCount = getPageCount(total, mergedPageSize);
568
- const mergedCurrent = clampPage(toPositiveInteger(current ?? internalCurrent, defaultCurrent), pageCount);
569
- const pageTokens = useMemo2(() => getPageTokens(mergedCurrent, pageCount), [mergedCurrent, pageCount]);
570
- const range = getRange(mergedCurrent, mergedPageSize, total);
571
- function changePage(nextPage, nextPageSize = mergedPageSize) {
572
- const nextPageCount = getPageCount(total, nextPageSize);
573
- const normalizedPage = clampPage(nextPage, nextPageCount);
574
- if (!isCurrentControlled) {
575
- setInternalCurrent(normalizedPage);
576
- }
577
- if (!isPageSizeControlled) {
578
- setInternalPageSize(nextPageSize);
579
- }
580
- onChange?.(normalizedPage, nextPageSize);
581
- }
582
- function handlePageSizeChange(event) {
583
- const nextPageSize = toPositiveInteger(Number(event.currentTarget.value), mergedPageSize);
584
- const nextPage = clampPage(mergedCurrent, getPageCount(total, nextPageSize));
585
- changePage(nextPage, nextPageSize);
586
- }
587
- function jumpToInputPage(value) {
588
- const nextPage = Number(value);
589
- if (!Number.isFinite(nextPage)) {
590
- return;
591
- }
592
- changePage(nextPage);
593
- setQuickJumpValue("");
594
- }
595
- function handleQuickJumpKeyDown(event) {
596
- if (event.key !== "Enter") {
597
- return;
598
- }
599
- jumpToInputPage(event.currentTarget.value);
600
- }
601
- const previousDisabled = disabled || mergedCurrent <= 1;
602
- const nextDisabled = disabled || mergedCurrent >= pageCount;
603
- return /* @__PURE__ */ jsxs3("nav", {
604
- ...props,
605
- ref,
606
- className: getPaginationClasses({ size, compact: simple, className }),
607
- children: [
608
- showTotal ? /* @__PURE__ */ jsx4("div", {
609
- className: paginationInfoClass,
610
- children: /* @__PURE__ */ jsx4("span", {
611
- className: paginationInfoTextClass,
612
- children: showTotal(total, range)
613
- })
614
- }) : null,
615
- /* @__PURE__ */ jsx4("button", {
616
- type: "button",
617
- className: paginationPrevClass,
618
- disabled: previousDisabled,
619
- "aria-label": "Previous page",
620
- onClick: () => changePage(mergedCurrent - 1),
621
- children: "Prev"
622
- }),
623
- simple ? /* @__PURE__ */ jsxs3("div", {
624
- className: paginationInputClass,
625
- children: [
626
- /* @__PURE__ */ jsx4("input", {
627
- "aria-label": "Current page",
628
- type: "number",
629
- min: 1,
630
- max: pageCount,
631
- value: quickJumpValue || String(mergedCurrent),
632
- disabled,
633
- onChange: (event) => setQuickJumpValue(event.currentTarget.value),
634
- onKeyDown: handleQuickJumpKeyDown,
635
- onBlur: (event) => {
636
- if (event.currentTarget.value !== String(mergedCurrent)) {
637
- jumpToInputPage(event.currentTarget.value);
638
- }
639
- }
640
- }),
641
- /* @__PURE__ */ jsxs3("span", {
642
- className: paginationInfoTextClass,
643
- children: [
644
- "/ ",
645
- pageCount
646
- ]
647
- })
648
- ]
649
- }) : pageTokens.map((pageToken, index) => pageToken === "ellipsis" ? /* @__PURE__ */ jsx4("span", {
650
- "aria-hidden": "true",
651
- className: paginationEllipsisClass
652
- }, `ellipsis-${index}`) : /* @__PURE__ */ jsx4("button", {
653
- type: "button",
654
- className: getPaginationItemClasses({
655
- active: pageToken === mergedCurrent,
656
- disabled
657
- }),
658
- disabled,
659
- "aria-current": pageToken === mergedCurrent ? "page" : undefined,
660
- "aria-label": `Page ${pageToken}`,
661
- onClick: () => changePage(pageToken),
662
- children: pageToken
663
- }, pageToken)),
664
- /* @__PURE__ */ jsx4("button", {
665
- type: "button",
666
- className: paginationNextClass,
667
- disabled: nextDisabled,
668
- "aria-label": "Next page",
669
- onClick: () => changePage(mergedCurrent + 1),
670
- children: "Next"
671
- }),
672
- showSizeChanger ? /* @__PURE__ */ jsx4("div", {
673
- className: paginationInputClass,
674
- children: /* @__PURE__ */ jsx4("select", {
675
- "aria-label": "Page size",
676
- value: mergedPageSize,
677
- disabled,
678
- onChange: handlePageSizeChange,
679
- children: getSizeOptions(mergedPageSize).map((option) => /* @__PURE__ */ jsxs3("option", {
680
- value: option,
681
- children: [
682
- option,
683
- " / page"
684
- ]
685
- }, option))
686
- })
687
- }) : null,
688
- showQuickJumper && !simple ? /* @__PURE__ */ jsx4("div", {
689
- className: paginationInputClass,
690
- children: /* @__PURE__ */ jsx4("input", {
691
- "aria-label": "Jump to page",
692
- type: "number",
693
- min: 1,
694
- max: pageCount,
695
- value: quickJumpValue,
696
- disabled,
697
- onChange: (event) => setQuickJumpValue(event.currentTarget.value),
698
- onKeyDown: handleQuickJumpKeyDown
699
- })
700
- }) : null
701
- ]
702
- });
703
- });
704
- Pagination.displayName = "Pagination";
705
- // src/components/dm-pagination/DmPagination.tsx
706
- import {
707
- forwardRef as forwardRef3,
708
- useEffect,
709
- useMemo as useMemo3,
710
- useRef,
711
- useState as useState3
712
- } from "react";
713
-
714
- // src/classes/dm-pagination.ts
715
- var dmPaginationBaseClass = "dm-pagination";
716
- var dmPaginationHiddenClass = "dm-pagination-hidden";
717
- var dmPaginationPagerClass = "dm-pagination-pager";
718
- var dmPaginationRefreshClass = "dm-pagination-refresh";
719
- var dmPaginationRefreshLoadingClass = "dm-pagination-refresh-loading";
720
- var dmPaginationSelectedClass = "dm-pagination-selected";
721
- var dmPaginationAlignClasses = {
722
- left: "dm-pagination-left",
723
- center: "dm-pagination-center",
724
- right: "dm-pagination-right"
725
- };
726
- function getDmPaginationClasses({
727
- align = "right",
728
- hidden,
729
- className
730
- }) {
731
- return cn(dmPaginationBaseClass, dmPaginationAlignClasses[align], hidden && dmPaginationHiddenClass, className);
732
- }
733
- function getDmPaginationRefreshClasses({
734
- loading,
735
- className
736
- }) {
737
- return cn(dmPaginationRefreshClass, loading && dmPaginationRefreshLoadingClass, className);
738
- }
739
-
740
- // src/components/dm-pagination/DmPagination.tsx
741
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
742
- var defaultLocale = {
743
- refresh: "Refresh",
744
- showTotal: (total, range) => `${range[0]}-${range[1]} of ${total}`,
745
- showTotalSimple: (total, range) => `${range[0]}-${range[1]} / ${total}`,
746
- selected: (selectedTotal) => `, ${selectedTotal} selected`
747
- };
748
- function getResponsiveSimple({
749
- width,
750
- total,
751
- showRefresh,
752
- showSizeChanger
753
- }) {
754
- let reservedWidth = 0;
755
- if (!showRefresh)
756
- reservedWidth += 100;
757
- if (!showSizeChanger)
758
- reservedWidth += 100;
759
- if (width < 900 - reservedWidth)
760
- return total >= 100;
761
- if (width < 1100 - reservedWidth)
762
- return total >= 1000;
763
- if (width < 1220 - reservedWidth)
764
- return total >= 99999;
765
- if (width < 1300 - reservedWidth)
766
- return total >= 999999;
767
- if (width < 1450 - reservedWidth)
768
- return total >= 9999999;
769
- return false;
770
- }
771
- function useElementWidth() {
772
- const ref = useRef(null);
773
- const [width, setWidth] = useState3(1000);
774
- useEffect(() => {
775
- const element = ref.current;
776
- if (!element || typeof ResizeObserver === "undefined")
777
- return;
778
- const observer = new ResizeObserver(([entry]) => {
779
- setWidth(entry?.contentRect.width || element.getBoundingClientRect().width);
780
- });
781
- observer.observe(element);
782
- return () => observer.disconnect();
783
- }, []);
784
- return [ref, width];
785
- }
786
- function renderSelected(selectedTotal, locale) {
787
- if (!selectedTotal)
788
- return null;
789
- return /* @__PURE__ */ jsx5("span", {
790
- className: dmPaginationSelectedClass,
791
- children: locale.selected(selectedTotal)
792
- });
793
- }
794
- var DmPagination = forwardRef3(({
795
- selectedTotal = 0,
796
- loading = false,
797
- total = 0,
798
- showRefresh = true,
799
- showPagination = true,
800
- wrapperStyle,
801
- className,
802
- align = "right",
803
- showTotalFullMessage = false,
804
- showSizeChanger = true,
805
- responsiveSimple = true,
806
- refresh,
807
- simple,
808
- showQuickJumper,
809
- showTotal,
810
- locale,
811
- ...props
812
- }, ref) => {
813
- const [measureRef, width] = useElementWidth();
814
- const mergedLocale = useMemo3(() => ({ ...defaultLocale, ...locale }), [locale]);
815
- const isRefreshVisible = showRefresh && Boolean(refresh);
816
- const shouldRender = showPagination || isRefreshVisible;
817
- const responsiveSimpleMode = responsiveSimple ? getResponsiveSimple({
818
- width,
819
- total,
820
- showRefresh,
821
- showSizeChanger
822
- }) : false;
823
- const mergedSimple = simple ?? responsiveSimpleMode;
824
- const mergedShowQuickJumper = showQuickJumper ?? !mergedSimple;
825
- const totalRenderer = useMemo3(() => {
826
- if (showTotal)
827
- return showTotal;
828
- return (nextTotal, range) => {
829
- if (Number(nextTotal) === 0)
830
- return "";
831
- const selected = renderSelected(selectedTotal, mergedLocale);
832
- const message = mergedSimple && !showTotalFullMessage ? mergedLocale.showTotalSimple(nextTotal, range, selectedTotal) : mergedLocale.showTotal(nextTotal, range, selectedTotal);
833
- return /* @__PURE__ */ jsxs4("span", {
834
- title: `${mergedLocale.showTotal(nextTotal, range, selectedTotal)}${selectedTotal ? mergedLocale.selected(selectedTotal) : ""}`,
835
- children: [
836
- message,
837
- selected
838
- ]
839
- });
840
- };
841
- }, [
842
- mergedLocale,
843
- mergedSimple,
844
- selectedTotal,
845
- showTotal,
846
- showTotalFullMessage
847
- ]);
848
- if (!shouldRender)
849
- return null;
850
- return /* @__PURE__ */ jsxs4("div", {
851
- ref: (element) => {
852
- measureRef.current = element;
853
- if (typeof ref === "function") {
854
- ref(element);
855
- } else if (ref) {
856
- ref.current = element;
857
- }
858
- },
859
- className: getDmPaginationClasses({ align, className }),
860
- style: wrapperStyle,
861
- children: [
862
- showPagination ? /* @__PURE__ */ jsx5("div", {
863
- className: dmPaginationPagerClass,
864
- children: /* @__PURE__ */ jsx5(Pagination, {
865
- ...props,
866
- total,
867
- simple: mergedSimple,
868
- showQuickJumper: mergedShowQuickJumper,
869
- showSizeChanger,
870
- showTotal: totalRenderer
871
- })
872
- }) : null,
873
- isRefreshVisible ? /* @__PURE__ */ jsxs4("button", {
874
- type: "button",
875
- className: getDmPaginationRefreshClasses({ loading }),
876
- disabled: loading || props.disabled,
877
- "aria-busy": loading || undefined,
878
- onClick: refresh,
879
- children: [
880
- /* @__PURE__ */ jsx5("span", {
881
- "aria-hidden": "true",
882
- children: "Reload"
883
- }),
884
- /* @__PURE__ */ jsx5("span", {
885
- children: mergedLocale.refresh
886
- })
887
- ]
888
- }) : null
889
- ]
890
- });
891
- });
892
- DmPagination.displayName = "DmPagination";
893
- // src/components/input/Input.tsx
894
- import {
895
- forwardRef as forwardRef4,
896
- useImperativeHandle,
897
- useRef as useRef2,
898
- useState as useState4
899
- } from "react";
900
-
901
- // src/classes/input.ts
902
- var inputBaseClass = "input";
903
- var inputWrapperClass = "input-wrapper";
904
- var inputAffixWrapperClass = "input-affix-wrapper";
905
- var inputPrefixClass = "input-prefix";
906
- var inputSuffixClass = "input-suffix";
907
- var inputClearClass = "input-clear";
908
- var inputSearchClass = "input-search";
909
- var inputSearchButtonClass = "input-search-button";
910
- var inputPasswordClass = "input-password";
911
- var inputPasswordToggleClass = "input-password-toggle";
912
- var inputGroupClass = "input-group";
913
- var textAreaBaseClass = "textarea";
914
- var textAreaWrapperClass = "textarea-wrapper";
915
- var textAreaCountClass = "textarea-counter";
916
- var textAreaCountExceededClass = "textarea-counter-exceeded";
917
- var textAreaAutoSizeClass = "textarea-auto-resize";
918
- var inputVariantClasses = {
919
- filled: "input-filled",
920
- outlined: "input-outlined"
921
- };
922
- var inputSizeClasses = {
923
- sm: "input-sm",
924
- md: "input-md",
925
- lg: "input-lg"
926
- };
927
- var inputStatusClasses = {
928
- error: "input-error",
929
- success: "input-success"
930
- };
931
- var textAreaVariantClasses = {
932
- filled: "textarea-filled",
933
- outlined: "textarea-outlined"
934
- };
935
- var textAreaSizeClasses = {
936
- sm: "textarea-sm",
937
- md: "",
938
- lg: "textarea-lg"
939
- };
940
- var textAreaStatusClasses = {
941
- error: "textarea-error",
942
- success: "textarea-success"
943
- };
944
- var textAreaResizeClasses = {
945
- none: "textarea-resize-none",
946
- both: "textarea-resize-both",
947
- horizontal: "textarea-resize-horizontal",
948
- vertical: "textarea-resize-vertical"
949
- };
950
- function getInputClasses({
951
- size = "md",
952
- status,
953
- variant = "outlined",
954
- className
955
- }) {
956
- return cn(inputBaseClass, inputVariantClasses[variant], inputSizeClasses[size], status && inputStatusClasses[status], className);
957
- }
958
- function getInputWrapperClasses({
959
- affixed,
960
- className
961
- }) {
962
- return cn(inputWrapperClass, affixed && inputAffixWrapperClass, className);
963
- }
964
- function getSearchWrapperClasses({ className }) {
965
- return cn(inputSearchClass, className);
966
- }
967
- function getPasswordWrapperClasses({
968
- className
969
- }) {
970
- return cn(inputPasswordClass, className);
971
- }
972
- function getTextAreaClasses({
973
- size = "md",
974
- status,
975
- variant = "outlined",
976
- resize = "vertical",
977
- autoSize,
978
- className
979
- }) {
980
- return cn(textAreaBaseClass, textAreaVariantClasses[variant], textAreaSizeClasses[size], status && textAreaStatusClasses[status], textAreaResizeClasses[resize], autoSize && textAreaAutoSizeClass, className);
981
- }
982
- function getTextAreaCountClasses({ exceeded }) {
983
- return cn(textAreaCountClass, exceeded && textAreaCountExceededClass);
984
- }
985
-
986
- // src/components/input/Input.tsx
987
- import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
988
- function toTextValue(value) {
989
- if (Array.isArray(value)) {
990
- return value.join(",");
991
- }
992
- return value == null ? "" : String(value);
993
- }
994
- var InputRoot = forwardRef4(({
995
- allowClear,
996
- className,
997
- defaultValue,
998
- disabled,
999
- onChange,
1000
- prefix,
1001
- size = "md",
1002
- status,
1003
- suffix,
1004
- type = "text",
1005
- value,
1006
- variant = "outlined",
1007
- ...props
1008
- }, ref) => {
1009
- const inputRef = useRef2(null);
1010
- const [internalValue, setInternalValue] = useState4(() => toTextValue(defaultValue));
1011
- const isControlled = value !== undefined;
1012
- const currentValue = isControlled ? toTextValue(value) : internalValue;
1013
- const hasAffix = prefix != null || suffix != null || allowClear;
1014
- useImperativeHandle(ref, () => inputRef.current);
1015
- function handleChange(event) {
1016
- if (!isControlled) {
1017
- setInternalValue(event.currentTarget.value);
1018
- }
1019
- onChange?.(event);
1020
- }
1021
- function handleClear() {
1022
- const input = inputRef.current;
1023
- if (!input || disabled) {
1024
- return;
1025
- }
1026
- input.value = "";
1027
- if (!isControlled) {
1028
- setInternalValue("");
1029
- }
1030
- onChange?.({
1031
- currentTarget: input,
1032
- target: input,
1033
- type: "change"
1034
- });
1035
- input.focus();
1036
- }
1037
- const control = /* @__PURE__ */ jsx6("input", {
1038
- ...props,
1039
- ref: inputRef,
1040
- type,
1041
- className: getInputClasses({ size, status, variant, className }),
1042
- disabled,
1043
- value: currentValue,
1044
- onChange: handleChange
1045
- });
1046
- if (!hasAffix) {
1047
- return control;
1048
- }
1049
- const showClear = allowClear && !disabled && currentValue.length > 0;
1050
- return /* @__PURE__ */ jsxs5("span", {
1051
- className: getInputWrapperClasses({ affixed: hasAffix }),
1052
- children: [
1053
- prefix != null ? /* @__PURE__ */ jsx6("span", {
1054
- className: inputPrefixClass,
1055
- children: prefix
1056
- }) : null,
1057
- control,
1058
- showClear ? /* @__PURE__ */ jsx6("button", {
1059
- type: "button",
1060
- className: inputClearClass,
1061
- "aria-label": "Clear input",
1062
- onClick: handleClear,
1063
- children: "x"
1064
- }) : null,
1065
- suffix != null ? /* @__PURE__ */ jsx6("span", {
1066
- className: inputSuffixClass,
1067
- children: suffix
1068
- }) : null
1069
- ]
1070
- });
1071
- });
1072
- InputRoot.displayName = "Input";
1073
- var Search = forwardRef4(({
1074
- className,
1075
- disabled,
1076
- enterButton,
1077
- loading,
1078
- onKeyDown,
1079
- onSearch,
1080
- ...props
1081
- }, ref) => {
1082
- const inputRef = useRef2(null);
1083
- useImperativeHandle(ref, () => inputRef.current);
1084
- function emitSearch(event) {
1085
- onSearch?.(inputRef.current?.value ?? "", event);
1086
- }
1087
- function handleKeyDown(event) {
1088
- onKeyDown?.(event);
1089
- if (!event.defaultPrevented && event.key === "Enter") {
1090
- emitSearch(event);
1091
- }
1092
- }
1093
- const buttonContent = enterButton === true ? "Search" : enterButton ?? "Search";
1094
- return /* @__PURE__ */ jsxs5("span", {
1095
- className: getSearchWrapperClasses({ className }),
1096
- children: [
1097
- /* @__PURE__ */ jsx6(InputRoot, {
1098
- ...props,
1099
- ref: inputRef,
1100
- disabled,
1101
- onKeyDown: handleKeyDown
1102
- }),
1103
- enterButton || loading ? /* @__PURE__ */ jsx6("button", {
1104
- type: "button",
1105
- className: inputSearchButtonClass,
1106
- disabled: disabled || loading,
1107
- "aria-busy": loading || undefined,
1108
- onClick: emitSearch,
1109
- children: loading ? "Loading" : buttonContent
1110
- }) : null
1111
- ]
1112
- });
1113
- });
1114
- Search.displayName = "Input.Search";
1115
- var Password = forwardRef4(({ className, disabled, visibilityToggle = true, ...props }, ref) => {
1116
- const [visible, setVisible] = useState4(false);
1117
- const type = visible ? "text" : "password";
1118
- const toggle = visibilityToggle ? /* @__PURE__ */ jsx6("button", {
1119
- type: "button",
1120
- className: inputPasswordToggleClass,
1121
- disabled,
1122
- "aria-label": visible ? "Hide password" : "Show password",
1123
- onClick: () => {
1124
- setVisible((current) => !current);
1125
- },
1126
- children: visible ? "Hide" : "Show"
1127
- }) : undefined;
1128
- return /* @__PURE__ */ jsx6("span", {
1129
- className: getPasswordWrapperClasses({ className }),
1130
- children: /* @__PURE__ */ jsx6(InputRoot, {
1131
- ...props,
1132
- ref,
1133
- disabled,
1134
- type,
1135
- suffix: toggle
1136
- })
1137
- });
1138
- });
1139
- Password.displayName = "Input.Password";
1140
- var TextArea = forwardRef4(({
1141
- autoSize,
1142
- className,
1143
- defaultValue,
1144
- maxLength,
1145
- onChange,
1146
- resize = "vertical",
1147
- showCount,
1148
- size = "md",
1149
- status,
1150
- value,
1151
- variant = "outlined",
1152
- ...props
1153
- }, ref) => {
1154
- const [internalValue, setInternalValue] = useState4(() => toTextValue(defaultValue));
1155
- const isControlled = value !== undefined;
1156
- const currentValue = isControlled ? toTextValue(value) : internalValue;
1157
- const count = currentValue.length;
1158
- const exceeded = maxLength !== undefined && count > maxLength;
1159
- function handleChange(event) {
1160
- if (!isControlled) {
1161
- setInternalValue(event.currentTarget.value);
1162
- }
1163
- onChange?.(event);
1164
- }
1165
- const control = /* @__PURE__ */ jsx6("textarea", {
1166
- ...props,
1167
- ref,
1168
- className: getTextAreaClasses({
1169
- size,
1170
- status,
1171
- variant,
1172
- resize,
1173
- autoSize: Boolean(autoSize),
1174
- className
1175
- }),
1176
- maxLength,
1177
- value: currentValue,
1178
- onChange: handleChange
1179
- });
1180
- if (!showCount) {
1181
- return control;
1182
- }
1183
- return /* @__PURE__ */ jsxs5("span", {
1184
- className: textAreaWrapperClass,
1185
- children: [
1186
- control,
1187
- /* @__PURE__ */ jsxs5("span", {
1188
- className: getTextAreaCountClasses({ exceeded }),
1189
- children: [
1190
- count,
1191
- maxLength !== undefined ? ` / ${maxLength}` : null
1192
- ]
1193
- })
1194
- ]
1195
- });
1196
- });
1197
- TextArea.displayName = "Input.TextArea";
1198
- var Group = forwardRef4(({ className, children, ...props }, ref) => /* @__PURE__ */ jsx6("div", {
1199
- ...props,
1200
- ref,
1201
- className: cn(inputGroupClass, className),
1202
- children
1203
- }));
1204
- Group.displayName = "Input.Group";
1205
- var Input = Object.assign(InputRoot, {
1206
- Search,
1207
- Password,
1208
- TextArea,
1209
- Group
1210
- });
1211
- // src/components/select/Select.tsx
1212
- import React5, { forwardRef as forwardRef5, useMemo as useMemo4, useState as useState5 } from "react";
1213
-
1214
- // src/classes/select.ts
1215
- var selectContainerClass = "select-container";
1216
- var selectBaseClass = "select";
1217
- var selectIconClass = "select-icon";
1218
- var selectOpenClass = "select-open";
1219
- var selectLoadingClass = "select-loading";
1220
- var selectFullClass = "select-full";
1221
- var selectOptionClass = "select-option";
1222
- var selectOptionSelectedClass = "select-option-selected";
1223
- var selectOptionDisabledClass = "select-option-disabled";
1224
- var selectDropdownClass = "select-dropdown";
1225
- var selectSearchClass = "select-search";
1226
- var selectSelectionClass = "select-selection";
1227
- var selectTagClass = "select-tag";
1228
- var selectClearClass = "select-clear";
1229
- var selectPlaceholderClass = "select-placeholder";
1230
- var selectEmptyClass = "select-empty";
1231
- var selectGroupClass = "select-group";
1232
- var selectGroupLabelClass = "select-group-label";
1233
- var selectSizeClasses = {
1234
- sm: "select-sm",
1235
- md: "",
1236
- lg: "select-lg"
1237
- };
1238
- var selectStatusClasses = {
1239
- error: "select-error",
1240
- success: "select-success"
1241
- };
1242
- function getSelectContainerClasses({
1243
- open,
1244
- loading,
1245
- disabled,
1246
- full,
1247
- className
1248
- }) {
1249
- return cn(selectContainerClass, open && selectOpenClass, loading && selectLoadingClass, disabled && "select-disabled", full && selectFullClass, className);
1250
- }
1251
- function getSelectClasses({
1252
- size = "md",
1253
- status,
1254
- disabled,
1255
- className
1256
- }) {
1257
- return cn(selectBaseClass, selectSizeClasses[size], status && selectStatusClasses[status], disabled && "select-disabled", className);
1258
- }
1259
- function getSelectOptionClasses({
1260
- selected,
1261
- disabled,
1262
- className
1263
- }) {
1264
- return cn(selectOptionClass, selected && selectOptionSelectedClass, disabled && selectOptionDisabledClass, className);
1265
- }
1266
-
1267
- // src/components/select/Select.tsx
1268
- import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1269
- function isGroup(option) {
1270
- return "options" in option;
1271
- }
1272
- function optionLabel(option) {
1273
- return option.label ?? option.value;
1274
- }
1275
- function valueKey(value) {
1276
- return String(value);
1277
- }
1278
- function normalizeSingleValue(value) {
1279
- if (Array.isArray(value)) {
1280
- return value[0];
1281
- }
1282
- return typeof value === "string" || typeof value === "number" ? value : undefined;
1283
- }
1284
- function normalizeMultiValue(value) {
1285
- if (Array.isArray(value)) {
1286
- return value.filter((item) => typeof item === "string" || typeof item === "number");
1287
- }
1288
- const single = normalizeSingleValue(value);
1289
- return single === undefined ? [] : [single];
1290
- }
1291
- function optionsFromChildren(children) {
1292
- const result = [];
1293
- React5.Children.forEach(children, (child) => {
1294
- if (!React5.isValidElement(child)) {
1295
- return;
1296
- }
1297
- if (child.type === Option) {
1298
- const props = child.props;
1299
- result.push({
1300
- value: props.value,
1301
- label: props.children,
1302
- disabled: props.disabled,
1303
- className: props.className
1304
- });
1305
- return;
1306
- }
1307
- if (child.type === OptGroup) {
1308
- const props = child.props;
1309
- result.push({
1310
- label: props.label,
1311
- className: props.className,
1312
- options: optionsFromChildren(props.children).filter((option) => !isGroup(option))
1313
- });
1314
- }
1315
- });
1316
- return result;
1317
- }
1318
- function flattenOptions(options) {
1319
- return options.flatMap((option) => isGroup(option) ? option.options : option);
1320
- }
1321
- function matchesOption(option, searchValue, filterOption) {
1322
- if (!searchValue || filterOption === false) {
1323
- return true;
1324
- }
1325
- if (typeof filterOption === "function") {
1326
- return filterOption(searchValue, option);
1327
- }
1328
- const label = optionLabel(option);
1329
- const text = typeof label === "string" || typeof label === "number" ? String(label) : String(option.value);
1330
- return text.toLowerCase().includes(searchValue.toLowerCase());
1331
- }
1332
- function filterOptions(options, searchValue, filterOption) {
1333
- return options.map((option) => {
1334
- if (!isGroup(option)) {
1335
- return matchesOption(option, searchValue, filterOption) ? option : null;
1336
- }
1337
- const groupOptions = option.options.filter((child) => matchesOption(child, searchValue, filterOption));
1338
- return groupOptions.length > 0 ? { ...option, options: groupOptions } : null;
1339
- }).filter((option) => option !== null);
1340
- }
1341
- function renderValue(option) {
1342
- return option ? optionLabel(option) : null;
1343
- }
1344
- var Option = forwardRef5(({ children, ...props }, ref) => /* @__PURE__ */ jsx7("div", {
1345
- ...props,
1346
- ref,
1347
- children
1348
- }));
1349
- Option.displayName = "Select.Option";
1350
- var OptGroup = forwardRef5(({ children, ...props }, ref) => /* @__PURE__ */ jsx7("div", {
1351
- ...props,
1352
- ref,
1353
- children
1354
- }));
1355
- OptGroup.displayName = "Select.OptGroup";
1356
- var SelectRoot = forwardRef5(({
1357
- allowClear,
1358
- children,
1359
- className,
1360
- defaultValue,
1361
- disabled,
1362
- filterOption,
1363
- loading,
1364
- mode,
1365
- onChange,
1366
- options,
1367
- placeholder,
1368
- showSearch,
1369
- size = "md",
1370
- status,
1371
- value,
1372
- ...props
1373
- }, ref) => {
1374
- const multiple = mode === "multiple" || mode === "tags";
1375
- const sourceOptions = useMemo4(() => options ?? optionsFromChildren(children), [children, options]);
1376
- const flatOptions = useMemo4(() => flattenOptions(sourceOptions), [sourceOptions]);
1377
- const [open, setOpen] = useState5(false);
1378
- const [searchValue, setSearchValue] = useState5("");
1379
- const [internalValue, setInternalValue] = useState5(multiple ? normalizeMultiValue(defaultValue) : normalizeSingleValue(defaultValue));
1380
- const controlled = value !== undefined;
1381
- const currentValue = controlled ? value : internalValue;
1382
- const selectedValues = multiple ? normalizeMultiValue(currentValue) : normalizeSingleValue(currentValue) === undefined ? [] : [normalizeSingleValue(currentValue)];
1383
- const selectedKeys = new Set(selectedValues.map(valueKey));
1384
- const selectedOptions = selectedValues.map((selectedValue) => flatOptions.find((option) => option.value === selectedValue) ?? {
1385
- value: selectedValue,
1386
- label: selectedValue
1387
- });
1388
- const visibleOptions = filterOptions(sourceOptions, searchValue, filterOption);
1389
- const hasValue = selectedValues.length > 0;
1390
- const searchable = showSearch || mode === "tags";
1391
- function emitChange(nextValue) {
1392
- if (!controlled) {
1393
- setInternalValue(nextValue);
1394
- }
1395
- const nextValues = Array.isArray(nextValue) ? nextValue : nextValue === undefined ? [] : [nextValue];
1396
- const nextOptions = nextValues.map((next) => flatOptions.find((option) => option.value === next) ?? {
1397
- value: next,
1398
- label: next
1399
- });
1400
- onChange?.(nextValue, multiple ? nextOptions : nextOptions[0]);
1401
- }
1402
- function selectOption(option) {
1403
- if (disabled || loading || option.disabled) {
1404
- return;
1405
- }
1406
- if (multiple) {
1407
- const optionKey = valueKey(option.value);
1408
- const nextValues = selectedKeys.has(optionKey) ? selectedValues.filter((item) => valueKey(item) !== optionKey) : [...selectedValues, option.value];
1409
- emitChange(nextValues);
1410
- } else {
1411
- emitChange(option.value);
1412
- setOpen(false);
1413
- }
1414
- setSearchValue("");
1415
- }
1416
- function clearValue(event) {
1417
- event.stopPropagation();
1418
- if (disabled || loading) {
1419
- return;
1420
- }
1421
- emitChange(multiple ? [] : undefined);
1422
- setSearchValue("");
1423
- }
1424
- function addTag() {
1425
- const tag = searchValue.trim();
1426
- if (mode !== "tags" || tag.length === 0) {
1427
- return;
1428
- }
1429
- if (!selectedKeys.has(tag)) {
1430
- emitChange([...selectedValues, tag]);
1431
- }
1432
- setSearchValue("");
1433
- }
1434
- function renderOption(option) {
1435
- const selected = selectedKeys.has(valueKey(option.value));
1436
- return /* @__PURE__ */ jsx7("button", {
1437
- type: "button",
1438
- role: "option",
1439
- "aria-selected": selected,
1440
- disabled: disabled || option.disabled,
1441
- className: getSelectOptionClasses({
1442
- selected,
1443
- disabled: disabled || option.disabled,
1444
- className: option.className
1445
- }),
1446
- onClick: () => selectOption(option),
1447
- children: optionLabel(option)
1448
- }, valueKey(option.value));
1449
- }
1450
- function renderOptions(optionItems) {
1451
- return optionItems.map((option, index) => {
1452
- if (!isGroup(option)) {
1453
- return renderOption(option);
1454
- }
1455
- return /* @__PURE__ */ jsxs6("div", {
1456
- className: cn(selectGroupClass, option.className),
1457
- role: "group",
1458
- children: [
1459
- /* @__PURE__ */ jsx7("div", {
1460
- className: selectGroupLabelClass,
1461
- children: option.label
1462
- }),
1463
- option.options.map(renderOption)
1464
- ]
1465
- }, `group-${index}`);
1466
- });
1467
- }
1468
- const selection = multiple ? selectedOptions.map((option) => /* @__PURE__ */ jsx7("span", {
1469
- className: selectTagClass,
1470
- children: renderValue(option)
1471
- }, valueKey(option.value))) : renderValue(selectedOptions[0]);
1472
- return /* @__PURE__ */ jsxs6("div", {
1473
- ...props,
1474
- ref,
1475
- className: getSelectContainerClasses({
1476
- open,
1477
- loading,
1478
- disabled,
1479
- full: true,
1480
- className
1481
- }),
1482
- children: [
1483
- /* @__PURE__ */ jsxs6("button", {
1484
- type: "button",
1485
- className: getSelectClasses({ size, status, disabled }),
1486
- disabled: disabled || loading,
1487
- "aria-haspopup": "listbox",
1488
- "aria-expanded": open,
1489
- onClick: () => setOpen((current) => !current),
1490
- children: [
1491
- /* @__PURE__ */ jsx7("span", {
1492
- className: selectSelectionClass,
1493
- children: hasValue ? selection : /* @__PURE__ */ jsx7("span", {
1494
- className: selectPlaceholderClass,
1495
- children: placeholder
1496
- })
1497
- }),
1498
- /* @__PURE__ */ jsx7("span", {
1499
- className: selectIconClass,
1500
- "aria-hidden": "true",
1501
- children: "v"
1502
- })
1503
- ]
1504
- }),
1505
- allowClear && hasValue && !disabled && !loading ? /* @__PURE__ */ jsx7("button", {
1506
- type: "button",
1507
- className: selectClearClass,
1508
- "aria-label": "Clear selection",
1509
- onClick: clearValue,
1510
- children: "x"
1511
- }) : null,
1512
- open ? /* @__PURE__ */ jsxs6("div", {
1513
- className: selectDropdownClass,
1514
- role: "listbox",
1515
- "aria-multiselectable": multiple || undefined,
1516
- children: [
1517
- searchable ? /* @__PURE__ */ jsx7("input", {
1518
- className: selectSearchClass,
1519
- value: searchValue,
1520
- placeholder: typeof placeholder === "string" ? placeholder : undefined,
1521
- onChange: (event) => setSearchValue(event.currentTarget.value),
1522
- onKeyDown: (event) => {
1523
- if (event.key === "Enter") {
1524
- event.preventDefault();
1525
- addTag();
1526
- }
1527
- }
1528
- }) : null,
1529
- visibleOptions.length > 0 ? renderOptions(visibleOptions) : /* @__PURE__ */ jsx7("div", {
1530
- className: selectEmptyClass,
1531
- children: "No data"
1532
- })
1533
- ]
1534
- }) : null
1535
- ]
1536
- });
1537
- });
1538
- SelectRoot.displayName = "Select";
1539
- var Select = SelectRoot;
1540
- Select.Option = Option;
1541
- Select.OptGroup = OptGroup;
1542
- // src/components/dm-search/DmSearch.tsx
1543
- import {
1544
- forwardRef as forwardRef6,
1545
- useEffect as useEffect2,
1546
- useImperativeHandle as useImperativeHandle2,
1547
- useMemo as useMemo5,
1548
- useState as useState6
1549
- } from "react";
1550
-
1551
- // src/classes/dm-search.ts
1552
- var dmSearchBaseClass = "dm-search";
1553
- var dmSearchCompactClass = "dm-search-compact";
1554
- var dmSearchCollapsedClass = "dm-search-collapsed";
1555
- var dmSearchFieldsClass = "dm-search-fields";
1556
- var dmSearchFieldClass = "dm-search-field";
1557
- var dmSearchActionsClass = "dm-search-actions";
1558
- var dmSearchFastFilterClass = "dm-search-fast-filter";
1559
- function getDmSearchClasses({
1560
- compact,
1561
- collapsed,
1562
- className
1563
- }) {
1564
- return cn(dmSearchBaseClass, compact && dmSearchCompactClass, collapsed && dmSearchCollapsedClass, className);
1565
- }
1566
-
1567
- // src/components/dm-search/DmSearch.tsx
1568
- import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1569
- function initialValues(items, searchParams, useSearchParams = true) {
1570
- return items.reduce((acc, item) => {
1571
- const defaultValue = item.search.extraProps?.value ?? item.search.formProps?.initialValue;
1572
- acc[item.dataIndex] = useSearchParams && searchParams && item.dataIndex in searchParams ? searchParams[item.dataIndex] : defaultValue;
1573
- return acc;
1574
- }, {});
1575
- }
1576
- function optionList(extraProps) {
1577
- return Array.isArray(extraProps?.options) ? extraProps.options : [];
1578
- }
1579
- function renderField({
1580
- item,
1581
- value,
1582
- setValue,
1583
- loading,
1584
- enableDefaultPlaceHolder
1585
- }) {
1586
- const extraProps = item.search.extraProps ?? {};
1587
- const placeholder = extraProps.placeholder ?? (enableDefaultPlaceHolder ? item.search.type === "select" ? "Please select" : "Please enter" : undefined);
1588
- if (item.search.type === "custom") {
1589
- return item.search.render?.(value, setValue, item) ?? null;
1590
- }
1591
- if (item.search.type === "select") {
1592
- return /* @__PURE__ */ jsx8(Select, {
1593
- ...extraProps,
1594
- disabled: Boolean(loading || extraProps.disabled),
1595
- value,
1596
- placeholder,
1597
- onChange: (nextValue) => setValue(nextValue)
1598
- });
1599
- }
1600
- if (item.search.type === "dateRange") {
1601
- return /* @__PURE__ */ jsx8(DatePicker.RangePicker, {
1602
- ...extraProps,
1603
- value,
1604
- onChange: (nextValue) => setValue(nextValue)
1605
- });
1606
- }
1607
- if (item.search.type === "date") {
1608
- return /* @__PURE__ */ jsx8(DatePicker, {
1609
- ...extraProps,
1610
- value,
1611
- onChange: (nextValue) => setValue(nextValue)
1612
- });
1613
- }
1614
- if (item.search.type === "radio" || item.search.type === "checkbox") {
1615
- return /* @__PURE__ */ jsx8("div", {
1616
- role: item.search.type === "radio" ? "radiogroup" : "group",
1617
- children: optionList(extraProps).map((option) => /* @__PURE__ */ jsxs7("label", {
1618
- children: [
1619
- /* @__PURE__ */ jsx8("input", {
1620
- type: item.search.type,
1621
- disabled: loading,
1622
- checked: item.search.type === "checkbox" ? Array.isArray(value) && value.includes(option.value) : value === option.value,
1623
- onChange: (event) => {
1624
- if (item.search.type === "radio") {
1625
- setValue(option.value);
1626
- return;
1627
- }
1628
- const current = Array.isArray(value) ? value : [];
1629
- setValue(event.currentTarget.checked ? [...current, option.value] : current.filter((entry) => entry !== option.value));
1630
- }
1631
- }),
1632
- option.label ?? option.value
1633
- ]
1634
- }, String(option.value)))
1635
- });
1636
- }
1637
- return /* @__PURE__ */ jsx8(Input, {
1638
- ...extraProps,
1639
- type: item.search.type === "input-number" ? "number" : "text",
1640
- disabled: Boolean(loading || extraProps.disabled),
1641
- placeholder,
1642
- value: value == null ? "" : String(value),
1643
- onChange: (event) => setValue(event.currentTarget.value),
1644
- onKeyDown: (event) => {
1645
- if (event.key === "Enter") {
1646
- event.currentTarget.form?.requestSubmit();
1647
- }
1648
- }
1649
- });
1650
- }
1651
- var DmSearch = forwardRef6(({
1652
- items = [],
1653
- onSearch,
1654
- extra,
1655
- fastFilterItem,
1656
- defaultCollapsed = true,
1657
- hideCollapseBtn = false,
1658
- compact = false,
1659
- searchParams,
1660
- loading = false,
1661
- enableDefaultPlaceHolder = false,
1662
- className
1663
- }, ref) => {
1664
- const allItems = useMemo5(() => fastFilterItem ? [fastFilterItem, ...items] : items, [fastFilterItem, items]);
1665
- const [collapsed, setCollapsed] = useState6(defaultCollapsed);
1666
- const [values, setValues] = useState6(() => initialValues(allItems, searchParams));
1667
- const visibleItems = collapsed ? allItems.slice(0, 1) : allItems;
1668
- useEffect2(() => {
1669
- setValues(initialValues(allItems, searchParams));
1670
- }, [allItems, searchParams]);
1671
- function reset(useSearchParams = false) {
1672
- const nextValues = initialValues(allItems, searchParams, useSearchParams);
1673
- setValues(nextValues);
1674
- return nextValues;
1675
- }
1676
- useImperativeHandle2(ref, () => ({
1677
- onReset: () => {
1678
- reset(false);
1679
- }
1680
- }));
1681
- return /* @__PURE__ */ jsxs7("form", {
1682
- id: "searchForm",
1683
- className: getDmSearchClasses({ compact, collapsed, className }),
1684
- onSubmit: (event) => {
1685
- event.preventDefault();
1686
- onSearch?.(values);
1687
- },
1688
- children: [
1689
- fastFilterItem ? /* @__PURE__ */ jsx8("div", {
1690
- className: dmSearchFastFilterClass,
1691
- children: fastFilterItem.title
1692
- }) : null,
1693
- /* @__PURE__ */ jsx8("div", {
1694
- className: dmSearchFieldsClass,
1695
- children: visibleItems.map((item) => /* @__PURE__ */ jsxs7("label", {
1696
- className: dmSearchFieldClass,
1697
- children: [
1698
- compact ? null : /* @__PURE__ */ jsx8("span", {
1699
- children: item.title
1700
- }),
1701
- renderField({
1702
- item,
1703
- value: values[item.dataIndex],
1704
- loading,
1705
- enableDefaultPlaceHolder,
1706
- setValue: (value) => setValues((current) => ({
1707
- ...current,
1708
- [item.dataIndex]: value
1709
- }))
1710
- })
1711
- ]
1712
- }, item.key))
1713
- }),
1714
- /* @__PURE__ */ jsxs7("div", {
1715
- className: dmSearchActionsClass,
1716
- children: [
1717
- /* @__PURE__ */ jsx8(Button, {
1718
- type: "submit",
1719
- isLoading: loading,
1720
- children: "Search"
1721
- }),
1722
- /* @__PURE__ */ jsx8(Button, {
1723
- type: "button",
1724
- color: "secondary",
1725
- appearance: "outline",
1726
- onClick: () => onSearch?.(reset(false)),
1727
- children: "Reset"
1728
- }),
1729
- !hideCollapseBtn && allItems.length > 1 ? /* @__PURE__ */ jsx8(Button, {
1730
- type: "button",
1731
- color: "secondary",
1732
- appearance: "text",
1733
- onClick: () => {
1734
- setCollapsed((current) => !current);
1735
- setValues(initialValues(allItems, searchParams));
1736
- },
1737
- children: collapsed ? "Expand" : "Collapse"
1738
- }) : null,
1739
- extra
1740
- ]
1741
- })
1742
- ]
1743
- });
1744
- });
1745
- DmSearch.displayName = "DmSearch";
1746
- // src/components/table/Table.tsx
1747
- import React7, {
1748
- forwardRef as forwardRef7,
1749
- useMemo as useMemo6,
1750
- useState as useState7
1751
- } from "react";
1752
-
1753
- // src/classes/table.ts
1754
- var tableWrapperClass = "table-wrapper";
1755
- var tableBaseClass = "table";
1756
- var tableBorderedClass = "table-bordered";
1757
- var tableLoadingClass = "table-loading";
1758
- var tableSmallClass = "table-sm";
1759
- var tableLargeClass = "table-lg";
1760
- var tableHeaderCellClass = "table-header-cell";
1761
- var tableCellClass = "table-cell";
1762
- var tableRowClass = "table-row";
1763
- var tableRowSelectedClass = "table-row-selected";
1764
- var tableRowExpandedClass = "table-row-expanded";
1765
- var tableEmptyClass = "table-empty";
1766
- var tableLoadingIndicatorClass = "table-loading-indicator";
1767
- var tableSorterClass = "table-sorter";
1768
- var tableSorterActiveClass = "table-sorter-active";
1769
- var tableFilterClass = "table-filter";
1770
- var tableSelectionCellClass = "table-selection-cell";
1771
- var tableExpandCellClass = "table-expand-cell";
1772
- var tableExpandButtonClass = "table-expand-button";
1773
- var tablePaginationClass = "table-pagination";
1774
- var tablePaginationButtonClass = "table-pagination-button";
1775
- var tablePaginationInfoClass = "table-pagination-info";
1776
- function getTableWrapperClasses({
1777
- loading,
1778
- className
1779
- }) {
1780
- return cn(tableWrapperClass, loading && tableLoadingClass, className);
1781
- }
1782
- function getTableClasses({
1783
- bordered,
1784
- size
1785
- }) {
1786
- return cn(tableBaseClass, bordered && tableBorderedClass, size === "small" && tableSmallClass, size === "large" && tableLargeClass);
1787
- }
1788
- function getTableRowClasses({
1789
- selected,
1790
- expanded,
1791
- className
1792
- }) {
1793
- return cn(tableRowClass, selected && tableRowSelectedClass, expanded && tableRowExpandedClass, className);
1794
- }
1795
- function getTableSorterClasses(active) {
1796
- return cn(tableSorterClass, active && tableSorterActiveClass);
1797
- }
1798
-
1799
- // src/components/table/Table.tsx
1800
- import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
1801
- import { createElement } from "react";
1802
- var defaultPageSize = 10;
1803
- var defaultSortDirections = ["ascend", "descend", null];
1804
- function hasNode(node) {
1805
- return node !== undefined && node !== null && node !== false;
1806
- }
1807
- function textFromNode(node, fallback) {
1808
- return typeof node === "string" || typeof node === "number" ? String(node) : fallback;
1809
- }
1810
- function dataIndexKey(dataIndex) {
1811
- if (dataIndex === undefined) {
1812
- return;
1813
- }
1814
- return typeof dataIndex === "string" || typeof dataIndex === "number" ? dataIndex : Array.from(dataIndex).join(".");
1815
- }
1816
- function getValue(record, dataIndex) {
1817
- if (dataIndex === undefined) {
1818
- return;
1819
- }
1820
- const path = Array.isArray(dataIndex) ? dataIndex : [dataIndex];
1821
- return path.reduce((current, key) => {
1822
- if (current === null || current === undefined) {
1823
- return;
1824
- }
1825
- return current[key];
1826
- }, record);
1827
- }
1828
- function getRecordKey(record, index, rowKey) {
1829
- if (typeof rowKey === "function") {
1830
- return rowKey(record, index);
1831
- }
1832
- if (rowKey) {
1833
- const key2 = record[rowKey];
1834
- return typeof key2 === "string" || typeof key2 === "number" ? key2 : index;
1835
- }
1836
- const key = record.key;
1837
- return typeof key === "string" || typeof key === "number" ? key : index;
1838
- }
1839
- function normalizeKeys(keys) {
1840
- return keys?.map(String) ?? [];
1841
- }
1842
- function normalizeColumns(columns, prefix = "column") {
1843
- return columns.map((column, index) => {
1844
- const rawKey = column.key ?? dataIndexKey(column.dataIndex) ?? `${prefix}-${index}`;
1845
- return {
1846
- ...column,
1847
- columnKey: rawKey,
1848
- children: column.children ? normalizeColumns(column.children, String(rawKey)) : undefined
1849
- };
1850
- });
1851
- }
1852
- function leafColumns(columns) {
1853
- return columns.flatMap((column) => column.children?.length ? leafColumns(column.children) : [column]);
1854
- }
1855
- function getDepth(columns) {
1856
- if (columns.length === 0) {
1857
- return 1;
1858
- }
1859
- return Math.max(...columns.map((column) => column.children?.length ? 1 + getDepth(column.children) : 1));
1860
- }
1861
- function getLeafCount(column) {
1862
- return column.children?.length ? column.children.reduce((count, child) => count + getLeafCount(child), 0) : 1;
1863
- }
1864
- function buildHeaderRows(columns, depth, level = 0, rows = []) {
1865
- rows[level] ??= [];
1866
- columns.forEach((column) => {
1867
- const grouped = Boolean(column.children?.length);
1868
- rows[level].push({
1869
- column,
1870
- colSpan: grouped ? getLeafCount(column) : 1,
1871
- rowSpan: grouped ? 1 : depth - level
1872
- });
1873
- if (column.children?.length) {
1874
- buildHeaderRows(column.children, depth, level + 1, rows);
1875
- }
1876
- });
1877
- return rows;
1878
- }
1879
- function optionValues(filters) {
1880
- return (filters ?? []).flatMap((filter) => [
1881
- filter,
1882
- ...filter.children ?? []
1883
- ]);
1884
- }
1885
- function sortCompare(sorter) {
1886
- if (typeof sorter === "function") {
1887
- return sorter;
1888
- }
1889
- if (typeof sorter === "object" && sorter.compare) {
1890
- return sorter.compare;
1891
- }
1892
- return;
1893
- }
1894
- function sortOrderFor(column, sortStates) {
1895
- if (column.sortOrder !== undefined) {
1896
- return column.sortOrder;
1897
- }
1898
- return sortStates[String(column.columnKey)] ?? column.defaultSortOrder;
1899
- }
1900
- function filterValueFor(column, filterStates) {
1901
- if (column.filteredValue !== undefined) {
1902
- return column.filteredValue;
1903
- }
1904
- const state = filterStates[String(column.columnKey)];
1905
- return state !== undefined ? state : column.defaultFilteredValue;
1906
- }
1907
- function nextSortOrder(column, current) {
1908
- const directions = column.sortDirections ?? defaultSortDirections;
1909
- const index = directions.findIndex((order) => order === (current ?? null));
1910
- return directions[(index + 1) % directions.length] ?? null;
1911
- }
1912
- function selectedRowsForKeys(data, keys, rowKey) {
1913
- const keySet = new Set(normalizeKeys(keys));
1914
- return data.filter((record, index) => keySet.has(String(getRecordKey(record, index, rowKey))));
1915
- }
1916
- var Column = forwardRef7(() => null);
1917
- Column.displayName = "Table.Column";
1918
- var ColumnGroup = forwardRef7(() => null);
1919
- ColumnGroup.displayName = "Table.ColumnGroup";
1920
- var SummaryRow = forwardRef7((props, ref) => /* @__PURE__ */ jsx9("tr", {
1921
- ...props,
1922
- ref
1923
- }));
1924
- SummaryRow.displayName = "Table.Summary.Row";
1925
- var SummaryCell = forwardRef7(({ index, ...props }, ref) => {
1926
- return /* @__PURE__ */ jsx9("td", {
1927
- ...props,
1928
- ref
1929
- });
1930
- });
1931
- SummaryCell.displayName = "Table.Summary.Cell";
1932
- var Summary = Object.assign(forwardRef7(({ fixed, ...props }, ref) => {
1933
- return /* @__PURE__ */ jsx9("tfoot", {
1934
- ...props,
1935
- ref
1936
- });
1937
- }), {
1938
- Row: SummaryRow,
1939
- Cell: SummaryCell
1940
- });
1941
- Summary.displayName = "Table.Summary";
1942
- function columnsFromChildren(children) {
1943
- return React7.Children.toArray(children).flatMap((child) => {
1944
- if (!React7.isValidElement(child)) {
1945
- return [];
1946
- }
1947
- if (child.type === Column) {
1948
- const props = child.props;
1949
- const { children: columnChildren, ...column } = props;
1950
- return [column];
1951
- }
1952
- if (child.type === ColumnGroup) {
1953
- const props = child.props;
1954
- const { children: groupChildren, ...column } = props;
1955
- return [
1956
- {
1957
- ...column,
1958
- children: columnsFromChildren(groupChildren)
1959
- }
1960
- ];
1961
- }
1962
- return [];
1963
- });
1964
- }
1965
- function renderSummary(summary, pageData, colSpan) {
1966
- if (!summary) {
1967
- return null;
1968
- }
1969
- const node = summary(pageData);
1970
- if (React7.isValidElement(node) && node.type === Summary) {
1971
- return node;
1972
- }
1973
- return /* @__PURE__ */ jsx9("tfoot", {
1974
- children: /* @__PURE__ */ jsx9("tr", {
1975
- children: /* @__PURE__ */ jsx9("td", {
1976
- className: tableCellClass,
1977
- colSpan,
1978
- children: node
1979
- })
1980
- })
1981
- });
1982
- }
1983
- function resolvePagination(pagination, total) {
1984
- if (pagination === false) {
1985
- return null;
1986
- }
1987
- const config = pagination ?? {};
1988
- return {
1989
- current: config.current,
1990
- defaultCurrent: config.defaultCurrent ?? 1,
1991
- pageSize: config.pageSize,
1992
- defaultPageSize: config.defaultPageSize ?? defaultPageSize,
1993
- total: config.total ?? total,
1994
- disabled: config.disabled,
1995
- hideOnSinglePage: config.hideOnSinglePage,
1996
- showTotal: config.showTotal,
1997
- onChange: config.onChange
1998
- };
1999
- }
2000
- function TableRoot({
2001
- columns,
2002
- dataSource = [],
2003
- rowKey,
2004
- loading,
2005
- bordered,
2006
- size = "middle",
2007
- pagination,
2008
- rowSelection,
2009
- expandable,
2010
- summary,
2011
- locale,
2012
- tableLayout,
2013
- scroll,
2014
- onChange,
2015
- children,
2016
- className,
2017
- ...props
2018
- }, ref) {
2019
- const childColumns = useMemo6(() => columnsFromChildren(children), [children]);
2020
- const normalizedColumns = useMemo6(() => normalizeColumns(columns ?? childColumns), [childColumns, columns]);
2021
- const leaves = useMemo6(() => leafColumns(normalizedColumns), [normalizedColumns]);
2022
- const headerRows = useMemo6(() => buildHeaderRows(normalizedColumns, getDepth(normalizedColumns)), [normalizedColumns]);
2023
- const [sortStates, setSortStates] = useState7({});
2024
- const [filterStates, setFilterStates] = useState7({});
2025
- const [internalCurrent, setInternalCurrent] = useState7(1);
2026
- const [internalPageSize, setInternalPageSize] = useState7(defaultPageSize);
2027
- const [internalSelectedKeys, setInternalSelectedKeys] = useState7(rowSelection?.defaultSelectedRowKeys ?? []);
2028
- const [internalExpandedKeys, setInternalExpandedKeys] = useState7(expandable?.defaultExpandedRowKeys ?? []);
2029
- const spinning = typeof loading === "object" ? loading.spinning : Boolean(loading);
2030
- const activeFilters = useMemo6(() => {
2031
- return leaves.reduce((result, column) => {
2032
- const value = filterValueFor(column, filterStates) ?? null;
2033
- if (value !== null) {
2034
- result[String(column.columnKey)] = value;
2035
- }
2036
- return result;
2037
- }, {});
2038
- }, [filterStates, leaves]);
2039
- const activeSorter = useMemo6(() => {
2040
- const column = leaves.find((item) => sortOrderFor(item, sortStates));
2041
- if (!column) {
2042
- return {};
2043
- }
2044
- return {
2045
- column,
2046
- columnKey: column.columnKey,
2047
- field: column.dataIndex,
2048
- order: sortOrderFor(column, sortStates) ?? null
2049
- };
2050
- }, [leaves, sortStates]);
2051
- const filteredData = useMemo6(() => {
2052
- return leaves.reduce((records, column) => {
2053
- const values = filterValueFor(column, filterStates);
2054
- if (!values?.length || !column.onFilter) {
2055
- return records;
2056
- }
2057
- return records.filter((record) => values.some((value) => column.onFilter?.(value, record)));
2058
- }, dataSource);
2059
- }, [dataSource, filterStates, leaves]);
2060
- const sortedData = useMemo6(() => {
2061
- const sorterColumn = leaves.find((column) => sortOrderFor(column, sortStates));
2062
- const order = sorterColumn ? sortOrderFor(sorterColumn, sortStates) : null;
2063
- const compare = sorterColumn ? sortCompare(sorterColumn.sorter) : undefined;
2064
- if (!sorterColumn || !order || !compare) {
2065
- return filteredData;
2066
- }
2067
- return [...filteredData].sort((first, second) => {
2068
- const result = compare(first, second);
2069
- return order === "descend" ? -result : result;
2070
- });
2071
- }, [filteredData, leaves, sortStates]);
2072
- const paginationConfig = resolvePagination(pagination, sortedData.length);
2073
- const pageSize = Math.max(1, Math.floor(paginationConfig?.pageSize ?? (internalPageSize === defaultPageSize ? paginationConfig?.defaultPageSize : internalPageSize) ?? defaultPageSize));
2074
- const pageCount = paginationConfig ? Math.max(1, Math.ceil(Math.max(0, paginationConfig.total ?? sortedData.length) / pageSize)) : 1;
2075
- const current = paginationConfig ? Math.min(pageCount, Math.max(1, Math.floor(paginationConfig.current ?? internalCurrent ?? paginationConfig.defaultCurrent ?? 1))) : 1;
2076
- const pageData = paginationConfig ? sortedData.slice((current - 1) * pageSize, current * pageSize) : sortedData;
2077
- const selectedKeys = rowSelection?.selectedRowKeys ?? internalSelectedKeys;
2078
- const selectedKeySet = new Set(normalizeKeys(selectedKeys));
2079
- const expandedKeys = expandable?.expandedRowKeys ?? internalExpandedKeys;
2080
- const expandedKeySet = new Set(normalizeKeys(expandedKeys));
2081
- const hasSelection = Boolean(rowSelection);
2082
- const hasExpandable = Boolean(expandable?.expandedRowRender);
2083
- const structuralColumnCount = leaves.length + (hasSelection ? 1 : 0) + (hasExpandable ? 1 : 0);
2084
- const bodyEmpty = pageData.length === 0;
2085
- function emitTableChange(nextPagination, nextFilters, nextSorter, action) {
2086
- onChange?.(nextPagination, nextFilters, nextSorter, {
2087
- currentDataSource: sortedData,
2088
- action
2089
- });
2090
- }
2091
- function changePage(nextPage, nextPageSize = pageSize) {
2092
- if (!paginationConfig || paginationConfig.disabled) {
2093
- return;
2094
- }
2095
- const nextPageCount = Math.max(1, Math.ceil((paginationConfig.total ?? sortedData.length) / nextPageSize));
2096
- const normalizedPage = Math.min(nextPageCount, Math.max(1, nextPage));
2097
- if (paginationConfig.current === undefined) {
2098
- setInternalCurrent(normalizedPage);
2099
- }
2100
- if (paginationConfig.pageSize === undefined) {
2101
- setInternalPageSize(nextPageSize);
2102
- }
2103
- paginationConfig.onChange?.(normalizedPage, nextPageSize);
2104
- emitTableChange({ ...paginationConfig, current: normalizedPage, pageSize: nextPageSize }, activeFilters, activeSorter, "paginate");
2105
- }
2106
- function changeSorter(column) {
2107
- if (!column.sorter) {
2108
- return;
2109
- }
2110
- const nextOrder = nextSortOrder(column, sortOrderFor(column, sortStates));
2111
- const nextSortStates = { [String(column.columnKey)]: nextOrder };
2112
- const nextSorter = nextOrder ? {
2113
- column,
2114
- columnKey: column.columnKey,
2115
- field: column.dataIndex,
2116
- order: nextOrder
2117
- } : {};
2118
- setSortStates(nextSortStates);
2119
- setInternalCurrent(1);
2120
- emitTableChange({ ...paginationConfig ?? {}, current: 1, pageSize }, activeFilters, nextSorter, "sort");
2121
- }
2122
- function changeFilter(column, event) {
2123
- const selected = Array.from(event.currentTarget.selectedOptions).map((option) => option.value).filter((value) => value !== "");
2124
- const nextValue = selected.length > 0 ? selected : null;
2125
- const nextFilters = {
2126
- ...activeFilters,
2127
- [String(column.columnKey)]: nextValue
2128
- };
2129
- if (nextValue === null) {
2130
- delete nextFilters[String(column.columnKey)];
2131
- }
2132
- setFilterStates((currentFilters) => ({
2133
- ...currentFilters,
2134
- [String(column.columnKey)]: nextValue
2135
- }));
2136
- setInternalCurrent(1);
2137
- emitTableChange({ ...paginationConfig ?? {}, current: 1, pageSize }, nextFilters, activeSorter, "filter");
2138
- }
2139
- function commitSelection(nextKeys, nativeEvent, changedRecord, selected, changedRows) {
2140
- if (!rowSelection) {
2141
- return;
2142
- }
2143
- const normalizedNextKeys = Array.from(new Set(nextKeys.map(String)));
2144
- const originalKeys = normalizedNextKeys.map((key) => {
2145
- const index = dataSource.findIndex((record, itemIndex) => String(getRecordKey(record, itemIndex, rowKey)) === key);
2146
- return index >= 0 ? getRecordKey(dataSource[index], index, rowKey) : key;
2147
- });
2148
- const selectedRows = selectedRowsForKeys(dataSource, originalKeys, rowKey);
2149
- if (rowSelection.selectedRowKeys === undefined) {
2150
- setInternalSelectedKeys(originalKeys);
2151
- }
2152
- rowSelection.onChange?.(originalKeys, selectedRows);
2153
- if (changedRecord && selected !== undefined) {
2154
- rowSelection.onSelect?.(changedRecord, selected, selectedRows, nativeEvent);
2155
- }
2156
- if (changedRows) {
2157
- rowSelection.onSelectAll?.(Boolean(selected), selectedRows, changedRows);
2158
- }
2159
- }
2160
- function toggleRowSelection(record, index, event) {
2161
- if (!rowSelection) {
2162
- return;
2163
- }
2164
- const key = getRecordKey(record, index, rowKey);
2165
- const keyString = String(key);
2166
- const checked = event.currentTarget.checked;
2167
- const nextKeys = rowSelection.type === "radio" ? checked ? [key] : [] : checked ? [...selectedKeys, key] : selectedKeys.filter((selectedKey) => String(selectedKey) !== keyString);
2168
- commitSelection(nextKeys, event.nativeEvent, record, checked);
2169
- }
2170
- function toggleAllRows(event) {
2171
- if (!rowSelection) {
2172
- return;
2173
- }
2174
- const checked = event.currentTarget.checked;
2175
- const selectableRows = pageData.filter((record, index) => {
2176
- const checkboxProps = rowSelection.getCheckboxProps?.(record);
2177
- return !checkboxProps?.disabled && getRecordKey(record, index, rowKey) !== undefined;
2178
- });
2179
- const pageKeys = selectableRows.map((record, index) => getRecordKey(record, index, rowKey));
2180
- const pageKeySet = new Set(normalizeKeys(pageKeys));
2181
- const nextKeys = checked ? [...selectedKeys, ...pageKeys] : selectedKeys.filter((key) => !pageKeySet.has(String(key)));
2182
- commitSelection(nextKeys, event.nativeEvent, undefined, checked, selectableRows);
2183
- }
2184
- function toggleExpand(record, index) {
2185
- if (!expandable?.expandedRowRender) {
2186
- return;
2187
- }
2188
- const key = getRecordKey(record, index, rowKey);
2189
- const keyString = String(key);
2190
- const expanded = !expandedKeySet.has(keyString);
2191
- const nextKeys = expanded ? [...expandedKeys, key] : expandedKeys.filter((expandedKey) => String(expandedKey) !== keyString);
2192
- if (expandable.expandedRowKeys === undefined) {
2193
- setInternalExpandedKeys(nextKeys);
2194
- }
2195
- expandable.onExpand?.(expanded, record);
2196
- expandable.onExpandedRowsChange?.(nextKeys);
2197
- }
2198
- function renderSelectionHeader() {
2199
- if (!rowSelection) {
2200
- return null;
2201
- }
2202
- if (rowSelection.type === "radio" || rowSelection.hideSelectAll) {
2203
- return /* @__PURE__ */ jsx9("th", {
2204
- className: cn(tableHeaderCellClass, tableSelectionCellClass),
2205
- children: rowSelection.columnTitle
2206
- });
2207
- }
2208
- const pageKeys = pageData.map((record, index) => getRecordKey(record, index, rowKey));
2209
- const allSelected = pageKeys.length > 0 && pageKeys.every((key) => selectedKeySet.has(String(key)));
2210
- return /* @__PURE__ */ jsx9("th", {
2211
- className: cn(tableHeaderCellClass, tableSelectionCellClass),
2212
- children: /* @__PURE__ */ jsxs8("label", {
2213
- children: [
2214
- /* @__PURE__ */ jsx9("input", {
2215
- type: "checkbox",
2216
- "aria-label": "Select all rows",
2217
- checked: allSelected,
2218
- onChange: toggleAllRows
2219
- }),
2220
- hasNode(rowSelection.columnTitle) ? rowSelection.columnTitle : null
2221
- ]
2222
- })
2223
- });
2224
- }
2225
- function renderHeaderCell(cell, index) {
2226
- const { column } = cell;
2227
- const title = column.title ?? dataIndexKey(column.dataIndex) ?? index + 1;
2228
- const sortOrder = sortOrderFor(column, sortStates);
2229
- const headerProps = column.onHeaderCell?.(column) ?? {};
2230
- return /* @__PURE__ */ createElement("th", {
2231
- ...headerProps,
2232
- key: String(column.columnKey),
2233
- className: cn(tableHeaderCellClass, column.className, headerProps.className),
2234
- colSpan: cell.colSpan,
2235
- rowSpan: cell.rowSpan,
2236
- style: {
2237
- width: column.width,
2238
- textAlign: column.align,
2239
- ...headerProps.style
2240
- }
2241
- }, /* @__PURE__ */ jsx9("span", {
2242
- children: title
2243
- }), column.sorter ? /* @__PURE__ */ jsx9("button", {
2244
- type: "button",
2245
- className: getTableSorterClasses(Boolean(sortOrder)),
2246
- "aria-label": `Sort ${textFromNode(title, String(column.columnKey))}`,
2247
- onClick: () => changeSorter(column),
2248
- children: sortOrder === "ascend" ? "Asc" : sortOrder === "descend" ? "Desc" : "Sort"
2249
- }) : null, column.filters?.length ? /* @__PURE__ */ jsxs8("select", {
2250
- className: tableFilterClass,
2251
- "aria-label": `Filter ${textFromNode(title, String(column.columnKey))}`,
2252
- multiple: column.filterMultiple !== false,
2253
- value: column.filterMultiple === false ? String((filterValueFor(column, filterStates) ?? [])[0] ?? "") : (filterValueFor(column, filterStates) ?? []).map(String),
2254
- onChange: (event) => changeFilter(column, event),
2255
- children: [
2256
- column.filterMultiple === false ? /* @__PURE__ */ jsx9("option", {
2257
- value: "",
2258
- children: "All"
2259
- }) : null,
2260
- optionValues(column.filters).map((filter) => /* @__PURE__ */ jsx9("option", {
2261
- value: String(filter.value),
2262
- children: filter.text
2263
- }, String(filter.value)))
2264
- ]
2265
- }) : null);
2266
- }
2267
- function renderCell(record, recordIndex, column) {
2268
- const value = getValue(record, column.dataIndex);
2269
- const rendered = column.render ? column.render(value, record, recordIndex) : value;
2270
- const cellProps = column.onCell?.(record, recordIndex) ?? {};
2271
- return /* @__PURE__ */ createElement("td", {
2272
- ...cellProps,
2273
- key: String(column.columnKey),
2274
- className: cn(tableCellClass, column.className, cellProps.className),
2275
- style: { textAlign: column.align, ...cellProps.style }
2276
- }, hasNode(rendered) ? rendered : null);
2277
- }
2278
- function renderSelectionCell(record, index) {
2279
- if (!rowSelection) {
2280
- return null;
2281
- }
2282
- const key = getRecordKey(record, index, rowKey);
2283
- const checked = selectedKeySet.has(String(key));
2284
- const checkboxProps = rowSelection.getCheckboxProps?.(record) ?? {};
2285
- const originNode = /* @__PURE__ */ jsx9("input", {
2286
- ...checkboxProps,
2287
- type: rowSelection.type === "radio" ? "radio" : "checkbox",
2288
- "aria-label": `Select row ${index + 1}`,
2289
- checked,
2290
- onChange: (event) => toggleRowSelection(record, index, event)
2291
- });
2292
- return /* @__PURE__ */ jsx9("td", {
2293
- className: cn(tableCellClass, tableSelectionCellClass),
2294
- children: rowSelection.renderCell ? rowSelection.renderCell(checked, record, index, originNode) : originNode
2295
- });
2296
- }
2297
- function renderExpandCell(record, index) {
2298
- if (!expandable?.expandedRowRender) {
2299
- return null;
2300
- }
2301
- const key = getRecordKey(record, index, rowKey);
2302
- const expanded = expandedKeySet.has(String(key));
2303
- const expandableRow = expandable.rowExpandable?.(record) ?? true;
2304
- return /* @__PURE__ */ jsx9("td", {
2305
- className: cn(tableCellClass, tableExpandCellClass),
2306
- children: expandableRow ? /* @__PURE__ */ jsx9("button", {
2307
- type: "button",
2308
- className: tableExpandButtonClass,
2309
- "aria-label": `${expanded ? "Collapse" : "Expand"} row ${index + 1}`,
2310
- onClick: () => toggleExpand(record, index),
2311
- children: expanded ? "-" : "+"
2312
- }) : null
2313
- });
2314
- }
2315
- function renderRow(record, index) {
2316
- const key = getRecordKey(record, index, rowKey);
2317
- const expanded = expandedKeySet.has(String(key));
2318
- const selected = selectedKeySet.has(String(key));
2319
- const row = /* @__PURE__ */ jsxs8("tr", {
2320
- className: getTableRowClasses({ selected, expanded }),
2321
- onClick: () => {
2322
- if (expandable?.expandRowByClick) {
2323
- toggleExpand(record, index);
2324
- }
2325
- },
2326
- children: [
2327
- renderSelectionCell(record, index),
2328
- renderExpandCell(record, index),
2329
- leaves.map((column) => renderCell(record, index, column))
2330
- ]
2331
- }, String(key));
2332
- if (!expanded || !expandable?.expandedRowRender) {
2333
- return row;
2334
- }
2335
- return /* @__PURE__ */ jsxs8(React7.Fragment, {
2336
- children: [
2337
- row,
2338
- /* @__PURE__ */ jsx9("tr", {
2339
- className: "table-expanded-row",
2340
- children: /* @__PURE__ */ jsx9("td", {
2341
- className: tableCellClass,
2342
- colSpan: structuralColumnCount,
2343
- children: expandable.expandedRowRender(record, index, 0, expanded)
2344
- })
2345
- })
2346
- ]
2347
- }, String(key));
2348
- }
2349
- const tableNode = /* @__PURE__ */ jsxs8("table", {
2350
- className: getTableClasses({ bordered, size }),
2351
- style: { tableLayout },
2352
- children: [
2353
- /* @__PURE__ */ jsx9("thead", {
2354
- children: headerRows.map((row, rowIndex) => /* @__PURE__ */ jsxs8("tr", {
2355
- children: [
2356
- rowIndex === 0 ? renderSelectionHeader() : null,
2357
- rowIndex === 0 && hasExpandable ? /* @__PURE__ */ jsx9("th", {
2358
- className: cn(tableHeaderCellClass, tableExpandCellClass),
2359
- children: expandable?.columnTitle
2360
- }) : null,
2361
- row.map(renderHeaderCell)
2362
- ]
2363
- }, rowIndex))
2364
- }),
2365
- /* @__PURE__ */ jsx9("tbody", {
2366
- children: bodyEmpty ? /* @__PURE__ */ jsx9("tr", {
2367
- children: /* @__PURE__ */ jsx9("td", {
2368
- className: tableEmptyClass,
2369
- colSpan: structuralColumnCount,
2370
- children: locale?.emptyText ?? "No data"
2371
- })
2372
- }) : pageData.map(renderRow)
2373
- }),
2374
- renderSummary(summary, pageData, structuralColumnCount)
2375
- ]
2376
- });
2377
- return /* @__PURE__ */ jsxs8("div", {
2378
- ...props,
2379
- ref,
2380
- className: getTableWrapperClasses({ loading: spinning, className }),
2381
- children: [
2382
- scroll?.x || scroll?.y ? /* @__PURE__ */ jsx9("div", {
2383
- style: {
2384
- overflow: "auto",
2385
- maxHeight: scroll.y,
2386
- width: scroll.x === true ? "100%" : scroll.x
2387
- },
2388
- children: tableNode
2389
- }) : tableNode,
2390
- spinning ? /* @__PURE__ */ jsx9("div", {
2391
- className: tableLoadingIndicatorClass,
2392
- role: "status",
2393
- children: typeof loading === "object" && loading.indicator ? loading.indicator : "Loading"
2394
- }) : null,
2395
- paginationConfig && !(paginationConfig.hideOnSinglePage && pageCount <= 1) ? /* @__PURE__ */ jsxs8("nav", {
2396
- className: tablePaginationClass,
2397
- "aria-label": "Table pagination",
2398
- children: [
2399
- /* @__PURE__ */ jsx9("button", {
2400
- type: "button",
2401
- className: tablePaginationButtonClass,
2402
- disabled: paginationConfig.disabled || current <= 1,
2403
- onClick: () => changePage(current - 1),
2404
- children: "Previous"
2405
- }),
2406
- /* @__PURE__ */ jsx9("span", {
2407
- className: tablePaginationInfoClass,
2408
- children: paginationConfig.showTotal ? paginationConfig.showTotal(paginationConfig.total ?? sortedData.length, [
2409
- bodyEmpty ? 0 : (current - 1) * pageSize + 1,
2410
- Math.min(current * pageSize, sortedData.length)
2411
- ]) : `${current} / ${pageCount}`
2412
- }),
2413
- /* @__PURE__ */ jsx9("button", {
2414
- type: "button",
2415
- className: tablePaginationButtonClass,
2416
- disabled: paginationConfig.disabled || current >= pageCount,
2417
- onClick: () => changePage(current + 1),
2418
- children: "Next"
2419
- })
2420
- ]
2421
- }) : null
2422
- ]
2423
- });
2424
- }
2425
- var TableWithRef = forwardRef7(TableRoot);
2426
- var Table = Object.assign(TableWithRef, {
2427
- Column,
2428
- ColumnGroup,
2429
- Summary,
2430
- SELECTION_ALL: "SELECT_ALL",
2431
- SELECTION_INVERT: "SELECT_INVERT",
2432
- SELECTION_NONE: "SELECT_NONE",
2433
- SELECTION_COLUMN: "SELECTION_COLUMN",
2434
- EXPAND_COLUMN: "EXPAND_COLUMN"
2435
- });
2436
- Table.displayName = "Table";
2437
- // src/components/dm-table/DmTable.tsx
2438
- import { useMemo as useMemo7, useState as useState8 } from "react";
2439
-
2440
- // src/classes/dm-table.ts
2441
- var dmTableBaseClass = "dm-table";
2442
- var dmTableSearchClass = "dm-table-search";
2443
- var dmTableCardClass = "dm-table-card";
2444
- var dmTableHeaderClass = "dm-table-header";
2445
- var dmTableTitleClass = "dm-table-title";
2446
- var dmTableExtraClass = "dm-table-extra";
2447
- var dmTableIndicatorsClass = "dm-table-indicators";
2448
- var dmTableTableExtraClass = "dm-table-table-extra";
2449
- var dmTableColumnSettingClass = "dm-table-column-setting";
2450
- var dmTablePaginationClass = "dm-table-pagination";
2451
- function getDmTableClasses({ className }) {
2452
- return cn(dmTableBaseClass, className);
2453
- }
2454
-
2455
- // src/components/dm-table/DmTable.tsx
2456
- import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
2457
- function mapAndFilter(list, mapper) {
2458
- return list.map(mapper).filter((item) => item !== false && item != null);
2459
- }
2460
- function filterDmTableColumn(column) {
2461
- if (column.onlySearch || column.hideInTable)
2462
- return false;
2463
- if (Array.isArray(column.children)) {
2464
- const children = mapAndFilter(column.children, filterDmTableColumn);
2465
- return children.length > 0 ? { ...column, children } : null;
2466
- }
2467
- return column;
2468
- }
2469
- function filterSearchColumn(column) {
2470
- if (Array.isArray(column.children)) {
2471
- const children = mapAndFilter(column.children, filterSearchColumn);
2472
- return children.length > 0 ? { ...column, children } : null;
2473
- }
2474
- return column.search ? column : false;
2475
- }
2476
- function flattenSearchColumns(column) {
2477
- return Array.isArray(column.children) ? column.children.flatMap(flattenSearchColumns) : [column];
2478
- }
2479
- function searchItems(columns) {
2480
- return mapAndFilter(columns, filterSearchColumn).flatMap(flattenSearchColumns).map((column) => ({
2481
- key: String(column.key ?? column.dataIndex),
2482
- title: column.title,
2483
- dataIndex: String(column.dataIndex ?? column.key),
2484
- search: column.search || {
2485
- type: "input",
2486
- extraProps: {},
2487
- formProps: {}
2488
- }
2489
- }));
2490
- }
2491
- function DmTable({
2492
- name,
2493
- extra,
2494
- indicators,
2495
- pagination,
2496
- columns: inputColumns,
2497
- columnSettingVisible = true,
2498
- onColumnsChange,
2499
- columnState,
2500
- searchProps,
2501
- tableExtra,
2502
- className,
2503
- dataSource,
2504
- rowSelection,
2505
- ...props
2506
- }) {
2507
- const tableColumns = useMemo7(() => mapAndFilter(inputColumns, filterDmTableColumn), [inputColumns]);
2508
- const [columns, setColumns] = useState8(tableColumns);
2509
- const [columnSettingsOpen, setColumnSettingsOpen] = useState8(false);
2510
- const items = searchProps?.items?.length ? searchProps.items : searchItems(inputColumns);
2511
- const paginationObj = typeof pagination === "object" ? pagination : undefined;
2512
- const paginationProps = paginationObj ? Object.fromEntries(Object.entries(paginationObj).filter(([key]) => key !== "ref")) : {};
2513
- const total = paginationObj?.total ?? dataSource?.length ?? 0;
2514
- const selectedTotal = rowSelection?.selectedRowKeys?.length ?? 0;
2515
- function resetColumns() {
2516
- setColumns(tableColumns);
2517
- onColumnsChange?.(tableColumns);
2518
- if (columnState?.persistenceKey) {
2519
- globalThis.localStorage?.removeItem(columnState.persistenceKey);
2520
- }
2521
- }
2522
- return /* @__PURE__ */ jsxs9("div", {
2523
- className: getDmTableClasses({ className }),
2524
- children: [
2525
- items.length > 0 || searchProps?.fastFilterItem ? /* @__PURE__ */ jsx10(Card, {
2526
- className: dmTableSearchClass,
2527
- padding: "md",
2528
- children: /* @__PURE__ */ jsx10(DmSearch, {
2529
- ...searchProps,
2530
- items
2531
- })
2532
- }) : null,
2533
- indicators ? /* @__PURE__ */ jsx10("div", {
2534
- className: dmTableIndicatorsClass,
2535
- children: indicators
2536
- }) : null,
2537
- /* @__PURE__ */ jsxs9(Card, {
2538
- className: dmTableCardClass,
2539
- padding: "md",
2540
- children: [
2541
- name || extra || columnSettingVisible ? /* @__PURE__ */ jsxs9("div", {
2542
- className: dmTableHeaderClass,
2543
- children: [
2544
- /* @__PURE__ */ jsx10("div", {
2545
- className: dmTableTitleClass,
2546
- children: name
2547
- }),
2548
- /* @__PURE__ */ jsxs9("div", {
2549
- className: dmTableExtraClass,
2550
- children: [
2551
- extra,
2552
- columnSettingVisible ? /* @__PURE__ */ jsx10(Button, {
2553
- type: "button",
2554
- color: "secondary",
2555
- appearance: "outline",
2556
- className: dmTableColumnSettingClass,
2557
- onClick: () => setColumnSettingsOpen((open) => !open),
2558
- children: "Columns"
2559
- }) : null
2560
- ]
2561
- })
2562
- ]
2563
- }) : null,
2564
- columnSettingsOpen ? /* @__PURE__ */ jsx10("div", {
2565
- role: "dialog",
2566
- "aria-label": "Column settings",
2567
- children: /* @__PURE__ */ jsx10(Button, {
2568
- type: "button",
2569
- onClick: resetColumns,
2570
- children: "Reset columns"
2571
- })
2572
- }) : null,
2573
- tableExtra ? /* @__PURE__ */ jsx10("div", {
2574
- className: dmTableTableExtraClass,
2575
- children: tableExtra
2576
- }) : null,
2577
- /* @__PURE__ */ jsx10(Table, {
2578
- ...props,
2579
- dataSource,
2580
- rowSelection,
2581
- size: props.size ?? "small",
2582
- scroll: props.scroll ?? { x: 680 },
2583
- columns,
2584
- pagination: pagination ? {
2585
- current: paginationObj?.current,
2586
- defaultCurrent: paginationObj?.defaultCurrent,
2587
- pageSize: paginationObj?.pageSize,
2588
- defaultPageSize: paginationObj?.defaultPageSize,
2589
- total,
2590
- onChange: paginationObj?.onChange
2591
- } : false
2592
- }),
2593
- pagination ? /* @__PURE__ */ jsx10(DmPagination, {
2594
- ...paginationProps,
2595
- className: dmTablePaginationClass,
2596
- total,
2597
- selectedTotal,
2598
- showSizeChanger: true
2599
- }) : null
2600
- ]
2601
- })
2602
- ]
2603
- });
2604
- }
2605
- DmTable.displayName = "DmTable";
2606
- // src/components/dm-pro-table-inner/DmProTableInner.tsx
2607
- import { jsx as jsx11 } from "react/jsx-runtime";
2608
- function DmProTableInner({
2609
- rowData,
2610
- className,
2611
- ...props
2612
- }) {
2613
- return /* @__PURE__ */ jsx11(DmTable, {
2614
- ...props,
2615
- className: getDmTableClasses({ className }),
2616
- dataSource: rowData
2617
- });
2618
- }
2619
- DmProTableInner.displayName = "DmProTableInner";
2620
- export {
2621
- DmProTableInner
2622
- };