@likable-hair/svelte 4.2.5 → 4.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 (117) hide show
  1. package/dist/components/composed/buttons/ActivableButton.svelte +25 -7
  2. package/dist/components/composed/common/HeadersDrawer.svelte +66 -28
  3. package/dist/components/composed/common/HeadersDrawer.svelte.d.ts +22 -12
  4. package/dist/components/composed/common/MenuOrDrawer.svelte +40 -12
  5. package/dist/components/composed/common/MenuOrDrawerOptions.svelte +51 -27
  6. package/dist/components/composed/common/MenuOrDrawerOptions.svelte.d.ts +15 -10
  7. package/dist/components/composed/common/QuickActions.svelte +59 -23
  8. package/dist/components/composed/common/ToolTip.svelte +51 -32
  9. package/dist/components/composed/dashboard/DashboardShaper.svelte +280 -147
  10. package/dist/components/composed/dashboard/DashboardShaper.svelte.d.ts +54 -45
  11. package/dist/components/composed/forms/AsyncAutocomplete.svelte +81 -30
  12. package/dist/components/composed/forms/AsyncAutocomplete.svelte.d.ts +12 -5
  13. package/dist/components/composed/forms/AvatarDropdown.svelte +146 -70
  14. package/dist/components/composed/forms/AvatarDropdown.svelte.d.ts +27 -22
  15. package/dist/components/composed/forms/ConfirmOrCancelButtons.svelte +65 -19
  16. package/dist/components/composed/forms/CountriesAutocomplete.svelte +33 -4
  17. package/dist/components/composed/forms/DatePickerTextField.svelte +266 -161
  18. package/dist/components/composed/forms/Dropdown.svelte +88 -21
  19. package/dist/components/composed/forms/Dropdown.svelte.d.ts +18 -13
  20. package/dist/components/composed/forms/IconsDropdown.svelte +85 -40
  21. package/dist/components/composed/forms/IconsDropdown.svelte.d.ts +15 -8
  22. package/dist/components/composed/forms/LabelAndSelect.svelte +46 -5
  23. package/dist/components/composed/forms/LabelAndTextField.svelte +56 -3
  24. package/dist/components/composed/forms/PeriodPicker.svelte +38 -18
  25. package/dist/components/composed/forms/PeriodPicker.svelte.d.ts +32 -7
  26. package/dist/components/composed/forms/PeriodSelector.svelte +427 -312
  27. package/dist/components/composed/forms/PeriodSelector.svelte.d.ts +20 -13
  28. package/dist/components/composed/forms/ToggleList.svelte +71 -37
  29. package/dist/components/composed/forms/ToggleList.svelte.d.ts +14 -7
  30. package/dist/components/composed/forms/YearPickerTextField.svelte +154 -82
  31. package/dist/components/composed/list/DynamicTable.svelte +1372 -809
  32. package/dist/components/composed/list/DynamicTable.svelte.d.ts +85 -70
  33. package/dist/components/composed/list/EnhancedPaginatedTable.svelte +75 -32
  34. package/dist/components/composed/list/EnhancedPaginatedTable.svelte.d.ts +16 -6
  35. package/dist/components/composed/list/PaginatedTable.svelte +324 -116
  36. package/dist/components/composed/list/PaginatedTable.svelte.d.ts +26 -22
  37. package/dist/components/composed/progress/HorizontalStackedProgress.svelte +67 -29
  38. package/dist/components/composed/search/DynamicFilters.svelte +126 -91
  39. package/dist/components/composed/search/FilterEditor.svelte +169 -109
  40. package/dist/components/composed/search/Filters.svelte +385 -275
  41. package/dist/components/composed/search/GlobalSearchTextField.svelte +102 -42
  42. package/dist/components/composed/search/GlobalSearchTextField.svelte.d.ts +23 -20
  43. package/dist/components/composed/search/MobileFilterEditor.svelte +174 -120
  44. package/dist/components/composed/search/QuickFilters.svelte +124 -75
  45. package/dist/components/composed/search/SearchBar.svelte +42 -3
  46. package/dist/components/composed/search/SearchResults.svelte +48 -5
  47. package/dist/components/composed/search/SearchResults.svelte.d.ts +17 -17
  48. package/dist/components/layouts/CollapsibleSideBarLayout.svelte +100 -24
  49. package/dist/components/layouts/StableDividedSideBarLayout.svelte +74 -24
  50. package/dist/components/layouts/UnstableDividedSideBarLayout.svelte +140 -57
  51. package/dist/components/simple/buttons/Button.svelte +86 -36
  52. package/dist/components/simple/buttons/LinkButton.svelte +81 -25
  53. package/dist/components/simple/charts/BarChart.svelte +137 -105
  54. package/dist/components/simple/charts/LineChart.svelte +124 -92
  55. package/dist/components/simple/charts/PieChart.svelte +51 -23
  56. package/dist/components/simple/common/CollapsibleDivider.svelte +58 -26
  57. package/dist/components/simple/common/Divider.svelte +2 -1
  58. package/dist/components/simple/common/InfiniteScroll.svelte +60 -34
  59. package/dist/components/simple/common/MediaQuery.svelte +28 -3
  60. package/dist/components/simple/common/Menu.svelte +516 -371
  61. package/dist/components/simple/common/NoData.svelte +18 -4
  62. package/dist/components/simple/common/VerticalDraggableList.svelte +52 -26
  63. package/dist/components/simple/common/VerticalDraggableList.svelte.d.ts +20 -9
  64. package/dist/components/simple/dashboards/DashboardGridShaper.svelte +28 -22
  65. package/dist/components/simple/dates/Calendar.svelte +142 -72
  66. package/dist/components/simple/dates/DatePicker.svelte +138 -71
  67. package/dist/components/simple/dates/MonthSelector.svelte +49 -13
  68. package/dist/components/simple/dates/YearSelector.svelte +73 -30
  69. package/dist/components/simple/dialogs/Dialog.svelte +109 -59
  70. package/dist/components/simple/forms/Autocomplete.svelte +341 -164
  71. package/dist/components/simple/forms/Autocomplete.svelte.d.ts +27 -20
  72. package/dist/components/simple/forms/Checkbox.svelte +57 -29
  73. package/dist/components/simple/forms/FileInput.svelte +103 -58
  74. package/dist/components/simple/forms/FileInputList.svelte +115 -51
  75. package/dist/components/simple/forms/RadioButton.svelte +36 -3
  76. package/dist/components/simple/forms/Select.svelte +30 -3
  77. package/dist/components/simple/forms/SimpleTextField.svelte +94 -4
  78. package/dist/components/simple/forms/Switch.svelte +33 -11
  79. package/dist/components/simple/forms/Textarea.svelte +22 -5
  80. package/dist/components/simple/forms/VerticalSwitch.svelte +19 -2
  81. package/dist/components/simple/forms/VerticalTextSwitch.svelte +35 -3
  82. package/dist/components/simple/lists/BoxList.svelte +42 -11
  83. package/dist/components/simple/lists/ColorInvertedSelector.svelte +83 -25
  84. package/dist/components/simple/lists/HierarchyMenu.svelte +55 -20
  85. package/dist/components/simple/lists/Paginator.svelte +53 -34
  86. package/dist/components/simple/lists/SelectableMenuList.svelte +52 -16
  87. package/dist/components/simple/lists/SelectableVerticalList.svelte +169 -85
  88. package/dist/components/simple/lists/SelectableVerticalList.svelte.d.ts +21 -14
  89. package/dist/components/simple/lists/SidebarMenuList.svelte +127 -79
  90. package/dist/components/simple/lists/SimpleTable.svelte +442 -245
  91. package/dist/components/simple/lists/SimpleTable.svelte.d.ts +31 -22
  92. package/dist/components/simple/loaders/CircularLoader.css +1 -1
  93. package/dist/components/simple/loaders/CircularLoader.svelte +11 -3
  94. package/dist/components/simple/loaders/Skeleton.svelte +3 -2
  95. package/dist/components/simple/media/Avatar.svelte +35 -15
  96. package/dist/components/simple/media/DescriptiveAvatar.svelte +30 -4
  97. package/dist/components/simple/media/FlagIcon.svelte +13 -3
  98. package/dist/components/simple/media/Icon.svelte +21 -6
  99. package/dist/components/simple/navigation/Breadcrumb.svelte +41 -9
  100. package/dist/components/simple/navigation/Chip.svelte +65 -29
  101. package/dist/components/simple/navigation/Drawer.svelte +132 -71
  102. package/dist/components/simple/navigation/HeaderMenu.svelte +69 -25
  103. package/dist/components/simple/navigation/Navigator.svelte +45 -11
  104. package/dist/components/simple/navigation/TabSwitcher.svelte +60 -19
  105. package/dist/components/simple/notifiers/AlertBanner.svelte +59 -11
  106. package/dist/components/simple/progress/ProgressBar.svelte +26 -10
  107. package/dist/components/simple/timeline/SimpleTimeLine.svelte +52 -5
  108. package/dist/components/simple/timeline/SimpleTimeLine.svelte.d.ts +16 -9
  109. package/dist/components/simple/typography/Code.svelte +41 -12
  110. package/dist/stores/layouts/unstableSidebarOpened.d.ts +1 -1
  111. package/dist/stores/layouts/unstableSidebarOpened.js +1 -1
  112. package/dist/stores/theme.js +2 -2
  113. package/dist/utils/filters/builder.d.ts +2 -2
  114. package/dist/utils/filters/builder.js +7 -7
  115. package/dist/utils/filters/modifiers/where.d.ts +1 -1
  116. package/dist/utils/teleporter.js +4 -4
  117. package/package.json +39 -33
@@ -1,287 +1,484 @@
1
- <script module lang="ts">export {};
1
+ <script module lang="ts">
2
+ export type HeaderType = ColumnBoolean |
3
+ ColumnString |
4
+ ColumnNumber |
5
+ ColumnDate |
6
+ ColumnIcon |
7
+ ColumnCheckBox |
8
+ ColumnCustom
9
+
10
+ export type Header<Data = any> = {
11
+ value: string
12
+ label: string
13
+ type: HeaderType
14
+ width?: string
15
+ minWidth?: string
16
+ maxWidth?: string
17
+ sortable?: boolean
18
+ icon?: string
19
+ pinned?: boolean
20
+ locked?: boolean
21
+ sortModify?: (params: { builder: FilterBuilder, sortDirection: 'asc' | 'desc' }) => FilterBuilder
22
+ data?: Data
23
+ };
24
+
25
+ export type CalculateRowStyles<T> = (item: T) => {
26
+ backgroundColor?: string;
27
+ color?: string;
28
+ fontWeight?: string;
29
+ };
30
+
31
+ export type CalculateRowClasses<T> = (item: T) => string | undefined;
2
32
  </script>
3
33
 
4
- <script lang="ts" generics="Item extends {[key: string]: any}, Data">import '../../../css/main.css';
5
- import './SimpleTable.css';
6
- import Icon from '../media/Icon.svelte';
7
- import { onMount, tick } from 'svelte';
8
- import NoData from '../common/NoData.svelte';
9
- let { headers = [], items = [], sortedBy = $bindable(undefined), sortDirection = $bindable("asc"), resizableColumns = false, resizedColumnSizeWithPadding = $bindable({}), pointerOnRowHover = false, lang = 'en', doubleClickActive = false, doubleClickDelay = 250, noItemsText, loading, calculateRowStyles = undefined, calculateRowClasses = undefined, stickyMinContainerWidth = 1024, oncolumnResize, onrowClick, onrowDoubleClick, onsort, headerSnippet, headerLabelSnippet, appendSnippet, prependSnippet, stickyAppendSnippet, customSnippet, noDataSnippet, class: clazz = {}, } = $props();
10
- if (!onrowClick && !!onrowDoubleClick) {
11
- throw new Error('cannot define an onrowDoubleClick event without defining an onrowClick event');
12
- }
13
- let clickTimeout = undefined, sortModify, tableContainer = $state(), mainHeader = $state(), remainingWidth = $state(0), containerWidth = $state(0), totalStickyWidth = $state(0), resizeObserver, headersHTML = $state({}), tableHTML = $state(), resizing = false, colspan = $derived.by(() => {
14
- return headers.length +
15
- (appendSnippet || stickyAppendSnippet ? 1 : 0) +
34
+ <script lang="ts" generics="Item extends {[key: string]: any}, Data">
35
+ import '../../../css/main.css'
36
+ import './SimpleTable.css'
37
+ import Icon from '../media/Icon.svelte';
38
+ import { onMount, tick, type Snippet } from 'svelte';
39
+ import type { DateTime } from 'luxon';
40
+ import type { ColumnBoolean, ColumnCheckBox, ColumnCustom, ColumnDate, ColumnIcon, ColumnNumber, ColumnString } from './columnTypes';
41
+ import NoData from '../common/NoData.svelte';
42
+ import type { FilterBuilder } from '../../..';
43
+
44
+ type TableHeader = Header<Data>
45
+
46
+ interface Props {
47
+ headers: TableHeader[];
48
+ items: Item[];
49
+ sortedBy?: string;
50
+ sortDirection?: "asc" | "desc";
51
+ resizableColumns?: boolean;
52
+ resizedColumnSizeWithPadding?: { [value: string]: number };
53
+ pointerOnRowHover?: boolean;
54
+ lang?: 'it' | 'en'
55
+ noItemsText?: string
56
+ loading?: boolean
57
+ doubleClickActive?: boolean,
58
+ doubleClickDelay?: number;
59
+ calculateRowStyles?: CalculateRowStyles<Item> | undefined
60
+ calculateRowClasses?: CalculateRowClasses<Item> | undefined
61
+ stickyMinContainerWidth?: number;
62
+ onsort?: (event: {
63
+ detail: {
64
+ sortedBy: string | undefined,
65
+ sortDirection: string,
66
+ sortModify: Header['sortModify']
67
+ }
68
+ }) => void
69
+ onrowClick?: (event: {
70
+ detail: {
71
+ item: Item
72
+ }
73
+ }) => void
74
+ onrowDoubleClick?: (event: {
75
+ detail: {
76
+ item: Item
77
+ }
78
+ }) => void
79
+ oncolumnResize?: (event: {
80
+ detail: {
81
+ id: string,
82
+ newWidthPx: number
83
+ }
84
+ }) => void
85
+ headerSnippet?: Snippet<[{
86
+ head: TableHeader
87
+ }]>
88
+ headerLabelSnippet?: Snippet<[{
89
+ head: TableHeader
90
+ }]>
91
+ appendSnippet?: Snippet<[{
92
+ index: number
93
+ item?: Item
94
+ }]>
95
+ prependSnippet?: Snippet<[{
96
+ index: number
97
+ item?: Item
98
+ }]>
99
+ stickyAppendSnippet?: Snippet<[]>
100
+ customSnippet?: Snippet<[{
101
+ index: number
102
+ columnIndex: number
103
+ header: TableHeader
104
+ item: Item
105
+ }]>
106
+ noDataSnippet?: Snippet<[]>
107
+ class?:{
108
+ container?: string;
109
+ header?: string;
110
+ row?: string;
111
+ cell?: string;
112
+ }
113
+ }
114
+
115
+ let {
116
+ headers = [],
117
+ items = [],
118
+ sortedBy = $bindable(undefined),
119
+ sortDirection = $bindable("asc"),
120
+ resizableColumns = false,
121
+ resizedColumnSizeWithPadding = $bindable({}),
122
+ pointerOnRowHover = false,
123
+ lang = 'en',
124
+ doubleClickActive = false,
125
+ doubleClickDelay = 250,
126
+ noItemsText,
127
+ loading,
128
+ calculateRowStyles = undefined,
129
+ calculateRowClasses = undefined,
130
+ stickyMinContainerWidth = 1024,
131
+ oncolumnResize,
132
+ onrowClick,
133
+ onrowDoubleClick,
134
+ onsort,
135
+ headerSnippet,
136
+ headerLabelSnippet,
137
+ appendSnippet,
138
+ prependSnippet,
139
+ stickyAppendSnippet,
140
+ customSnippet,
141
+ noDataSnippet,
142
+ class: clazz = {},
143
+ }: Props = $props();
144
+
145
+ if(!onrowClick && !!onrowDoubleClick) {
146
+ throw new Error('cannot define an onrowDoubleClick event without defining an onrowClick event')
147
+ }
148
+
149
+ let clickTimeout: NodeJS.Timeout | undefined = undefined,
150
+ sortModify: Header['sortModify'],
151
+ tableContainer: HTMLElement | undefined = $state(),
152
+ mainHeader: HTMLElement | undefined = $state(),
153
+ remainingWidth: number = $state(0),
154
+ containerWidth: number = $state(0),
155
+ totalStickyWidth: number = $state(0),
156
+ resizeObserver: ResizeObserver,
157
+ headersHTML: { [value: string]: HTMLElement } = $state({}),
158
+ tableHTML: HTMLElement | undefined = $state(),
159
+ resizing = false,
160
+ colspan = $derived.by(() => {
161
+ return headers.length +
162
+ (appendSnippet || stickyAppendSnippet ? 1 : 0) +
16
163
  (prependSnippet ? 1 : 0) +
17
164
  (remainingWidth ? 1 : 0);
18
- });
19
- let stickyEnabled = $derived.by(() => {
20
- if (containerWidth <= stickyMinContainerWidth)
21
- return false;
22
- if (totalStickyWidth >= containerWidth)
23
- return false;
165
+ })
166
+
167
+ let stickyEnabled = $derived.by(() => {
168
+ if (containerWidth <= stickyMinContainerWidth) return false;
169
+ if (totalStickyWidth >= containerWidth) return false;
170
+
24
171
  return true;
25
- });
26
- const DEFAULT_MIN_WIDTH_PX = 60, DEFAULT_MAX_WIDTH_PX = 400;
27
- onMount(() => {
172
+ });
173
+
174
+ const DEFAULT_MIN_WIDTH_PX = 60,
175
+ DEFAULT_MAX_WIDTH_PX = 400
176
+
177
+ onMount(() => {
28
178
  (async () => {
29
- await tick();
30
- resizeObserver = new ResizeObserver(() => {
31
- if (tableContainer) {
32
- const rect = tableContainer.getBoundingClientRect();
33
- containerWidth = rect.width;
34
- }
35
- calculateStickyMetrics();
36
- updateRemainingWidth();
37
- });
179
+ await tick()
180
+
181
+ resizeObserver = new ResizeObserver(() => {
38
182
  if (tableContainer) {
39
- resizeObserver.observe(tableContainer);
183
+ const rect = tableContainer.getBoundingClientRect();
184
+ containerWidth = rect.width;
40
185
  }
41
- resizeRowAppendHeader();
42
- for (const head of headers) {
43
- let th = headersHTML[head.value];
44
- if (!!th) {
45
- resizeHeader(th, head);
46
- }
186
+
187
+ calculateStickyMetrics();
188
+ updateRemainingWidth();
189
+ });
190
+
191
+ if(tableContainer){
192
+ resizeObserver.observe(tableContainer);
193
+ }
194
+
195
+ resizeRowAppendHeader()
196
+
197
+ for(const head of headers) {
198
+ let th = headersHTML[head.value]
199
+ if(!!th) {
200
+ resizeHeader(th, head)
47
201
  }
48
- return () => {
49
- resizeObserver?.disconnect();
50
- };
51
- })();
52
- });
53
- function calculateStickyMetrics() {
202
+ }
203
+
204
+
205
+ return () => {
206
+ resizeObserver?.disconnect();
207
+ };
208
+ })()
209
+ })
210
+
211
+ function calculateStickyMetrics() {
54
212
  let width = 0;
213
+
55
214
  if (prependSnippet && headersHTML['prepend']) {
56
- width += headersHTML['prepend'].getBoundingClientRect().width;
215
+ width += headersHTML['prepend'].getBoundingClientRect().width;
57
216
  }
217
+
58
218
  headers.forEach(head => {
59
- if (head.pinned) {
60
- const stored = resizedColumnSizeWithPadding[head.value];
61
- if (stored) {
62
- width += stored;
63
- }
64
- else if (headersHTML[head.value]) {
65
- width += headersHTML[head.value].getBoundingClientRect().width;
66
- }
219
+ if (head.pinned) {
220
+ const stored = resizedColumnSizeWithPadding[head.value];
221
+ if (stored) {
222
+ width += stored;
223
+ } else if (headersHTML[head.value]) {
224
+ width += headersHTML[head.value].getBoundingClientRect().width;
67
225
  }
226
+ }
68
227
  });
228
+
69
229
  if (stickyAppendSnippet && headersHTML['row-append-header']) {
70
- width += headersHTML['row-append-header'].getBoundingClientRect().width;
230
+ width += headersHTML['row-append-header'].getBoundingClientRect().width;
71
231
  }
232
+
72
233
  totalStickyWidth = width;
73
- }
74
- function handleHeaderClick(header) {
75
- if (header.sortable && !resizing) {
76
- if (!!sortedBy && header.value == sortedBy) {
77
- if (sortDirection == 'asc')
78
- sortDirection = 'desc';
79
- else if (sortDirection == 'desc') {
80
- sortedBy = undefined;
81
- sortModify = undefined;
82
- }
83
- }
84
- else {
85
- sortedBy = header.value;
86
- sortDirection = 'asc';
87
- sortModify = header.sortModify;
88
- }
89
- if (onsort) {
90
- onsort({
91
- detail: {
92
- sortedBy,
93
- sortDirection,
94
- sortModify
95
- }
96
- });
234
+ }
235
+
236
+ function handleHeaderClick(header: TableHeader) {
237
+ if(header.sortable && !resizing) {
238
+ if(!!sortedBy && header.value == sortedBy) {
239
+ if(sortDirection == 'asc') sortDirection = 'desc'
240
+ else if(sortDirection == 'desc') {
241
+ sortedBy = undefined
242
+ sortModify = undefined
97
243
  }
244
+ } else {
245
+ sortedBy = header.value
246
+ sortDirection = 'asc'
247
+ sortModify = header.sortModify
248
+ }
249
+ if(onsort) {
250
+ onsort({
251
+ detail: {
252
+ sortedBy,
253
+ sortDirection,
254
+ sortModify
255
+ }
256
+ })
257
+ }
98
258
  }
99
- }
100
- function handleRowClick(item) {
101
- if (doubleClickActive) {
102
- if (clickTimeout) {
103
- clearTimeout(clickTimeout);
104
- clickTimeout = undefined;
105
- if (onrowDoubleClick) {
106
- onrowDoubleClick({
107
- detail: {
108
- item
109
- }
110
- });
259
+ }
260
+
261
+ function handleRowClick(item: Item) {
262
+ if(doubleClickActive) {
263
+ if (clickTimeout) {
264
+ clearTimeout(clickTimeout);
265
+ clickTimeout = undefined;
266
+
267
+ if(onrowDoubleClick) {
268
+ onrowDoubleClick({
269
+ detail: {
270
+ item
111
271
  }
272
+ })
112
273
  }
113
- else {
114
- clickTimeout = setTimeout(() => {
115
- if (onrowClick) {
116
- onrowClick({
117
- detail: {
118
- item
119
- }
120
- });
121
- }
122
- clickTimeout = undefined;
123
- }, doubleClickDelay);
124
- }
125
- }
126
- else {
127
- if (onrowClick) {
274
+ } else {
275
+ clickTimeout = setTimeout(() => {
276
+ if(onrowClick) {
128
277
  onrowClick({
129
- detail: {
130
- item
131
- }
132
- });
133
- }
278
+ detail: {
279
+ item
280
+ }
281
+ })
282
+ }
283
+ clickTimeout = undefined;
284
+ }, doubleClickDelay);
285
+ }
286
+ } else {
287
+ if(onrowClick) {
288
+ onrowClick({
289
+ detail: {
290
+ item
291
+ }
292
+ })
293
+ }
134
294
  }
135
- }
136
- function formatDate(dateTime, dateFormat) {
137
- return dateTime.setLocale(dateFormat.locale).toFormat(dateFormat.format);
138
- }
139
- function resize(node) {
140
- let th = node.parentElement;
141
- let resizingInner = false;
142
- if (!!th) {
143
- let { width } = th.getBoundingClientRect();
144
- function mouseMoveHandler(e) {
145
- if (resizingInner && !!th && !!tableContainer) {
146
- width += e.movementX;
147
- const { paddingLeft, paddingRight } = getComputedStyle(th);
148
- const minWidth = headers.find(h => h.value === th.id)?.minWidth;
149
- let minWidthPx;
150
- if (!!minWidth && minWidth.endsWith('px')) {
151
- minWidthPx = parseInt(minWidth, 10);
152
- }
153
- const maxWidth = headers.find(h => h.value === th.id)?.maxWidth;
154
- let maxWidthPx;
155
- if (!!maxWidth && maxWidth.endsWith('px')) {
156
- maxWidthPx = parseInt(maxWidth, 10);
157
- }
158
- const actualMinWidth = (minWidthPx || DEFAULT_MIN_WIDTH_PX) - parseFloat(paddingLeft) - parseFloat(paddingRight);
159
- const actualMaxWidth = (maxWidthPx || DEFAULT_MAX_WIDTH_PX) - parseFloat(paddingLeft) - parseFloat(paddingRight);
160
- if (width > actualMinWidth && width < actualMaxWidth) {
161
- th.style.width = width + 'px';
162
- resizedColumnSizeWithPadding[th.id] = th.getBoundingClientRect().width;
163
- resizedColumnSizeWithPadding = {
164
- ...resizedColumnSizeWithPadding,
165
- };
166
- calculateStickyMetrics();
167
- }
295
+ }
296
+
297
+ function formatDate(dateTime: DateTime, dateFormat: ColumnDate['params']): string {
298
+ return dateTime.setLocale(dateFormat.locale).toFormat(dateFormat.format)
299
+ }
300
+
301
+
302
+ function resize(node: HTMLElement) {
303
+ let th: HTMLElement | null = node.parentElement
304
+ let resizingInner = false
305
+
306
+ if(!!th) {
307
+ let { width } = th.getBoundingClientRect()
308
+
309
+ function mouseMoveHandler(e: MouseEvent) {
310
+ if (resizingInner && !!th && !!tableContainer) {
311
+ width += e.movementX;
312
+ const { paddingLeft, paddingRight } = getComputedStyle(th);
313
+
314
+ const minWidth: string | undefined = headers.find(h => h.value === th.id)?.minWidth;
315
+ let minWidthPx: number | undefined;
316
+ if (!!minWidth && minWidth.endsWith('px')) {
317
+ minWidthPx = parseInt(minWidth, 10);
318
+ }
319
+
320
+ const maxWidth: string | undefined = headers.find(h => h.value === th.id)?.maxWidth;
321
+ let maxWidthPx: number | undefined;
322
+ if (!!maxWidth && maxWidth.endsWith('px')) {
323
+ maxWidthPx = parseInt(maxWidth, 10);
324
+ }
325
+
326
+ const actualMinWidth = (minWidthPx || DEFAULT_MIN_WIDTH_PX) - parseFloat(paddingLeft) - parseFloat(paddingRight);
327
+ const actualMaxWidth = (maxWidthPx || DEFAULT_MAX_WIDTH_PX) - parseFloat(paddingLeft) - parseFloat(paddingRight);
328
+
329
+ if (width > actualMinWidth && width < actualMaxWidth) {
330
+ th.style.width = width + 'px';
331
+ resizedColumnSizeWithPadding[th.id] = th.getBoundingClientRect().width;
332
+ resizedColumnSizeWithPadding = {
333
+ ...resizedColumnSizeWithPadding,
168
334
  }
335
+ calculateStickyMetrics();
336
+ }
169
337
  }
170
- function mouseUpHandler(e, setResize = true) {
171
- if (!!th) {
172
- resizingInner = false;
173
- let { paddingLeft, paddingRight } = getComputedStyle(th);
174
- width = th.getBoundingClientRect().width - parseFloat(paddingLeft) - parseFloat(paddingRight);
175
- if (setResize) {
176
- setTimeout(() => resizing = false, 20);
177
- }
178
- if (oncolumnResize) {
179
- oncolumnResize({
180
- detail: {
181
- id: th.id,
182
- newWidthPx: width
183
- }
184
- });
185
- }
186
- calculateStickyMetrics();
187
- }
338
+ }
339
+
340
+
341
+ function mouseUpHandler(e: MouseEvent, setResize: boolean = true) {
342
+ if(!!th) {
343
+ resizingInner = false
344
+ let { paddingLeft, paddingRight } = getComputedStyle(th)
345
+ width = th.getBoundingClientRect().width - parseFloat(paddingLeft) - parseFloat(paddingRight)
346
+ if(setResize){
347
+ setTimeout(() => resizing = false, 20)
348
+ }
349
+ if(oncolumnResize){
350
+ oncolumnResize({
351
+ detail: {
352
+ id: th.id,
353
+ newWidthPx: width
354
+ }
355
+ })
356
+ }
357
+ calculateStickyMetrics();
188
358
  }
189
- function mouseDownHandler(e) {
190
- if (!!th) {
191
- resizing = true;
192
- resizingInner = true;
193
- let { paddingLeft, paddingRight } = getComputedStyle(th);
194
- width = th.getBoundingClientRect().width - parseFloat(paddingLeft) - parseFloat(paddingRight);
195
- }
359
+ }
360
+
361
+ function mouseDownHandler(e: MouseEvent) {
362
+ if(!!th) {
363
+ resizing = true
364
+ resizingInner = true
365
+ let { paddingLeft, paddingRight } = getComputedStyle(th)
366
+ width = th.getBoundingClientRect().width - parseFloat(paddingLeft) - parseFloat(paddingRight)
196
367
  }
197
- node.addEventListener('mousedown', mouseDownHandler);
198
- document.addEventListener('mouseup', mouseUpHandler);
199
- document.addEventListener('mousemove', mouseMoveHandler);
200
- return {
201
- destroy() {
202
- node.removeEventListener('mousedown', mouseDownHandler);
203
- document.removeEventListener('mouseup', mouseUpHandler);
204
- document.removeEventListener('mousemove', mouseMoveHandler);
205
- }
206
- };
368
+ }
369
+
370
+ node.addEventListener('mousedown', mouseDownHandler)
371
+ document.addEventListener('mouseup', mouseUpHandler)
372
+ document.addEventListener('mousemove', mouseMoveHandler)
373
+
374
+
375
+ return {
376
+ destroy() {
377
+ node.removeEventListener('mousedown', mouseDownHandler)
378
+ document.removeEventListener('mouseup', mouseUpHandler)
379
+ document.removeEventListener('mousemove', mouseMoveHandler)
380
+ }
381
+ }
207
382
  }
208
- }
209
- $effect(() => {
210
- headers;
383
+ }
384
+
385
+ $effect(() => {
386
+ headers;
211
387
  resizedColumnSizeWithPadding;
388
+
212
389
  tick().then(() => {
213
- calculateStickyMetrics();
214
- updateRemainingWidth();
390
+ calculateStickyMetrics();
391
+ updateRemainingWidth();
215
392
  });
216
- });
217
- async function updateRemainingWidth() {
218
- if (tableContainer != null && !!tableContainer && mainHeader) {
219
- const containerWidth = tableContainer?.getBoundingClientRect().width;
220
- const scrollbarWidth = tableContainer.offsetWidth - tableContainer.clientWidth;
221
- if (containerWidth) {
222
- const totalResizableWidth = headers.reduce((sum, head) => {
223
- let th = headersHTML[head.value];
224
- if (!!th) {
225
- resizeHeader(th, head);
226
- }
227
- const width = th?.getBoundingClientRect().width || 0;
228
- return sum + width;
229
- }, 0);
230
- resizeRowAppendHeader();
231
- const extraStaticWidth = Array.from(mainHeader.querySelectorAll('th.non-resizable, th.row-append-header'))
232
- .reduce((sum, th) => sum + th.getBoundingClientRect().width, 0);
233
- remainingWidth = Math.max(0, containerWidth - scrollbarWidth - totalResizableWidth - extraStaticWidth);
234
- }
393
+ });
394
+
395
+ async function updateRemainingWidth() {
396
+ if(tableContainer != null && !!tableContainer && mainHeader) {
397
+ const containerWidth = tableContainer?.getBoundingClientRect().width;
398
+ const scrollbarWidth = tableContainer.offsetWidth - tableContainer.clientWidth
399
+
400
+ if(containerWidth){
401
+ const totalResizableWidth = headers.reduce((sum, head) => {
402
+ let th = headersHTML[head.value]
403
+ if(!!th) {
404
+ resizeHeader(th, head)
405
+ }
406
+ const width = th?.getBoundingClientRect().width || 0
407
+ return sum + width;
408
+ }, 0);
409
+
410
+ resizeRowAppendHeader()
411
+
412
+ const extraStaticWidth = Array.from(mainHeader.querySelectorAll('th.non-resizable, th.row-append-header'))
413
+ .reduce((sum, th) => sum + th.getBoundingClientRect().width, 0);
414
+
415
+ remainingWidth = Math.max(0, containerWidth - scrollbarWidth - totalResizableWidth - extraStaticWidth);
416
+ }
235
417
  }
236
- }
237
- function resizeRowAppendHeader() {
418
+ }
419
+
420
+ function resizeRowAppendHeader() {
238
421
  if ((appendSnippet || stickyAppendSnippet) && headersHTML['row-append-header']) {
239
- if (!!headersHTML['row-append-header'].style.width && headersHTML['row-append-header'].style.width != "0px") {
240
- return;
241
- }
242
- if (tableHTML) {
243
- tableHTML.style.tableLayout = 'auto';
244
- }
245
- let widthWithPadding = headersHTML['row-append-header'].scrollWidth;
246
- if (tableHTML) {
247
- tableHTML.style.tableLayout = 'fixed';
248
- }
249
- headersHTML['row-append-header'].style.width = `${widthWithPadding}px`;
250
- headersHTML['row-append-header'].style.minWidth = `${widthWithPadding}px`;
422
+ if(!!headersHTML['row-append-header'].style.width && headersHTML['row-append-header'].style.width != "0px") {
423
+ return
424
+ }
425
+
426
+ if (tableHTML) {
427
+ tableHTML.style.tableLayout = 'auto'
428
+ }
429
+
430
+ let widthWithPadding = headersHTML['row-append-header'].scrollWidth
431
+
432
+ if (tableHTML) {
433
+ tableHTML.style.tableLayout = 'fixed'
434
+ }
435
+
436
+ headersHTML['row-append-header'].style.width = `${widthWithPadding}px`;
437
+ headersHTML['row-append-header'].style.minWidth = `${widthWithPadding}px`;
251
438
  }
252
- }
253
- function resizeHeader(th, header) {
439
+ }
440
+
441
+ function resizeHeader(th: HTMLElement, header: { value: string, minWidth?: string, maxWidth?: string }){
254
442
  if (!resizedColumnSizeWithPadding[header.value]) {
255
- if (tableHTML) {
256
- tableHTML.style.tableLayout = 'auto';
257
- }
258
- let widthWithPadding = th.scrollWidth;
259
- if (widthWithPadding == 0) {
260
- return;
261
- }
262
- if (tableHTML) {
263
- tableHTML.style.tableLayout = 'fixed';
264
- }
265
- let minWidth = header.minWidth, minWidthPx = DEFAULT_MIN_WIDTH_PX;
266
- if (!!minWidth && minWidth.endsWith('px')) {
267
- minWidthPx = parseInt(minWidth, 10);
268
- }
269
- if (widthWithPadding < minWidthPx) {
270
- widthWithPadding = minWidthPx;
271
- }
272
- let maxWidth = header.maxWidth, maxWidthPx = DEFAULT_MAX_WIDTH_PX;
273
- if (!!maxWidth && maxWidth.endsWith('px')) {
274
- maxWidthPx = parseInt(maxWidth, 10);
275
- }
276
- if (widthWithPadding > maxWidthPx) {
277
- widthWithPadding = maxWidthPx;
278
- }
279
- resizedColumnSizeWithPadding[header.value] = widthWithPadding;
443
+ if (tableHTML) {
444
+ tableHTML.style.tableLayout = 'auto'
445
+ }
446
+
447
+ let widthWithPadding = th.scrollWidth
448
+
449
+ if (widthWithPadding == 0) {
450
+ return
451
+ }
452
+
453
+ if (tableHTML) {
454
+ tableHTML.style.tableLayout = 'fixed'
455
+ }
456
+
457
+ let minWidth = header.minWidth,
458
+ minWidthPx = DEFAULT_MIN_WIDTH_PX
459
+ if (!!minWidth && minWidth.endsWith('px')) {
460
+ minWidthPx = parseInt(minWidth, 10);
461
+ }
462
+ if(widthWithPadding < minWidthPx) {
463
+ widthWithPadding = minWidthPx
464
+ }
465
+
466
+ let maxWidth = header.maxWidth,
467
+ maxWidthPx = DEFAULT_MAX_WIDTH_PX
468
+ if (!!maxWidth && maxWidth.endsWith('px')) {
469
+ maxWidthPx = parseInt(maxWidth, 10);
470
+ }
471
+ if(widthWithPadding > maxWidthPx) {
472
+ widthWithPadding = maxWidthPx
473
+ }
474
+
475
+ resizedColumnSizeWithPadding[header.value] = widthWithPadding;
280
476
  }
281
477
  let { paddingLeft, paddingRight } = getComputedStyle(th);
282
478
  let width = resizedColumnSizeWithPadding[header.value] - parseFloat(paddingLeft) - parseFloat(paddingRight);
283
- th.style.width = `${width}px`;
284
- }
479
+ th.style.width = `${width}px`
480
+ }
481
+
285
482
  </script>
286
483
 
287
484
  {#if !!items && Array.isArray(items)}