@poirazis/supercomponents-shared 0.0.1

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/index.js +30635 -0
  4. package/dist/index.umd.cjs +12 -0
  5. package/dist/style.css +1 -0
  6. package/package.json +117 -0
  7. package/src/index.js +29 -0
  8. package/src/index.ts +31 -0
  9. package/src/lib/Actions/autoresize_textarea.js +14 -0
  10. package/src/lib/Actions/click_outside.js +80 -0
  11. package/src/lib/Actions/index.js +4 -0
  12. package/src/lib/Actions/position_dropdown.js +129 -0
  13. package/src/lib/SuperButton/SuperButton.svelte +341 -0
  14. package/src/lib/SuperFieldLabel/SuperFieldLabel.svelte +91 -0
  15. package/src/lib/SuperFieldsCommon.css +54 -0
  16. package/src/lib/SuperList/SuperList.svelte +308 -0
  17. package/src/lib/SuperList/drag-handle.svelte +31 -0
  18. package/src/lib/SuperPopover/SuperPopover.svelte +134 -0
  19. package/src/lib/SuperTable/SuperTable.css +410 -0
  20. package/src/lib/SuperTable/SuperTable.svelte +1332 -0
  21. package/src/lib/SuperTable/constants.js +85 -0
  22. package/src/lib/SuperTable/controls/ColumnsSection.svelte +34 -0
  23. package/src/lib/SuperTable/controls/ControlSection.svelte +3 -0
  24. package/src/lib/SuperTable/controls/RowButtonsColumn.svelte +169 -0
  25. package/src/lib/SuperTable/controls/SelectionColumn.svelte +174 -0
  26. package/src/lib/SuperTable/controls/SuperTableWelcome.svelte +58 -0
  27. package/src/lib/SuperTable/overlays/AddNewRowOverlay.svelte +52 -0
  28. package/src/lib/SuperTable/overlays/EmptyResultSetOverlay.svelte +13 -0
  29. package/src/lib/SuperTable/overlays/LoadingOverlay.svelte +3 -0
  30. package/src/lib/SuperTable/overlays/RowContextMenu copy.svelte +57 -0
  31. package/src/lib/SuperTable/overlays/RowContextMenu.svelte +58 -0
  32. package/src/lib/SuperTable/overlays/ScrollbarsOverlay.svelte +184 -0
  33. package/src/lib/SuperTable/overlays/SelectedActionsOverlay.svelte +64 -0
  34. package/src/lib/SuperTable/state/API.js +0 -0
  35. package/src/lib/SuperTable/state/SuperTableStateMachine.js +0 -0
  36. package/src/lib/SuperTable/types.js +0 -0
  37. package/src/lib/SuperTableCells/CellAttachment.svelte +288 -0
  38. package/src/lib/SuperTableCells/CellBoolean.svelte +158 -0
  39. package/src/lib/SuperTableCells/CellColor.svelte +460 -0
  40. package/src/lib/SuperTableCells/CellCommon.css +319 -0
  41. package/src/lib/SuperTableCells/CellDatetime.svelte +180 -0
  42. package/src/lib/SuperTableCells/CellIcon.svelte +627 -0
  43. package/src/lib/SuperTableCells/CellJSON.svelte +297 -0
  44. package/src/lib/SuperTableCells/CellLink.svelte +274 -0
  45. package/src/lib/SuperTableCells/CellLinkAdvanced.svelte +298 -0
  46. package/src/lib/SuperTableCells/CellLinkPickerSelect.svelte +355 -0
  47. package/src/lib/SuperTableCells/CellLinkPickerTable.svelte +91 -0
  48. package/src/lib/SuperTableCells/CellLinkPickerTree.svelte +226 -0
  49. package/src/lib/SuperTableCells/CellNumber.svelte +179 -0
  50. package/src/lib/SuperTableCells/CellNumberSimple.svelte +56 -0
  51. package/src/lib/SuperTableCells/CellOptions.svelte +631 -0
  52. package/src/lib/SuperTableCells/CellOptionsAdvanced.svelte +684 -0
  53. package/src/lib/SuperTableCells/CellSkeleton.svelte +59 -0
  54. package/src/lib/SuperTableCells/CellString.svelte +178 -0
  55. package/src/lib/SuperTableCells/CellStringSimple.svelte +55 -0
  56. package/src/lib/SuperTableCells/index.js +21 -0
  57. package/src/lib/SuperTableCells/remixIcons.js +6772 -0
  58. package/src/lib/SuperTableColumn/SuperTableColumn.svelte +392 -0
  59. package/src/lib/SuperTableColumn/index.js +9 -0
  60. package/src/lib/SuperTableColumn/parts/SuperColumnBody.svelte +57 -0
  61. package/src/lib/SuperTableColumn/parts/SuperColumnFooter.svelte +14 -0
  62. package/src/lib/SuperTableColumn/parts/SuperColumnHeader.svelte +228 -0
  63. package/src/lib/SuperTableColumn/parts/SuperColumnRow.svelte +142 -0
  64. package/src/lib/SuperTableColumn/parts/SuperColumnRowNew.svelte +34 -0
  65. package/src/lib/SuperTree/SuperTree.svelte +117 -0
  66. package/src/types/svelte-portal.d.ts +1 -0
@@ -0,0 +1,392 @@
1
+ <script>
2
+ import { getContext, setContext, onMount, onDestroy } from "svelte";
3
+ import fsm from "svelte-fsm";
4
+
5
+ const { memo, derivedMemo, processStringSync, builderStore } =
6
+ getContext("sdk");
7
+
8
+ import SuperColumnHeader from "./parts/SuperColumnHeader.svelte";
9
+ import SuperColumnBody from "./parts/SuperColumnBody.svelte";
10
+ import SuperColumnFooter from "./parts/SuperColumnFooter.svelte";
11
+
12
+ import CellOptions from "../SuperTableCells/CellOptions.svelte";
13
+ import CellString from "../SuperTableCells/CellString.svelte";
14
+ import CellNumber from "../SuperTableCells/CellNumber.svelte";
15
+ import CellBoolean from "../SuperTableCells/CellBoolean.svelte";
16
+ import CellDatetime from "../SuperTableCells/CellDatetime.svelte";
17
+ import CellLink from "../SuperTableCells/CellLink.svelte";
18
+ import CellJSON from "../SuperTableCells/CellJSON.svelte";
19
+ import CellAttachment from "../SuperTableCells/CellAttachment.svelte";
20
+
21
+ import CellStringSimple from "../SuperTableCells/CellStringSimple.svelte";
22
+
23
+ const stbData = getContext("stbData");
24
+ const stbSettings = getContext("stbSettings");
25
+ const stbSortColumn = getContext("stbSortColumn");
26
+ const stbSortOrder = getContext("stbSortOrder");
27
+ const stbHovered = getContext("stbHovered");
28
+ const stbEditing = getContext("stbEditing");
29
+ const stbState = getContext("stbState");
30
+ const stbAPI = getContext("stbAPI");
31
+
32
+ // Cell Components Map
33
+ const cellComponents = {
34
+ string: CellString,
35
+ longform: CellString,
36
+ number: CellNumber,
37
+ bigint: CellNumber,
38
+ options: CellOptions,
39
+ array: CellOptions,
40
+ jsonarray: CellOptions,
41
+ boolean: CellBoolean,
42
+ datetime: CellDatetime,
43
+ link: CellLink,
44
+ json: CellJSON,
45
+ attachment_single: CellAttachment,
46
+ attachment: CellAttachment,
47
+ bb_reference_single: CellLink,
48
+ bb_reference: CellLink,
49
+ };
50
+
51
+ const headerComponents = {
52
+ string: CellString,
53
+ number: CellNumber,
54
+ bigint: CellNumber,
55
+ options: CellOptions,
56
+ array: CellOptions,
57
+ jsonarray: CellOptions,
58
+ boolean: CellBoolean,
59
+ datetime: CellDatetime,
60
+ link: CellString,
61
+ json: CellJSON,
62
+ attachment_single: null,
63
+ attachment: null,
64
+ bb_reference_single: CellString,
65
+ bb_reference: CellString,
66
+ };
67
+
68
+ // Props
69
+ export let columnOptions;
70
+ export let sticky;
71
+ export let scrollPos;
72
+
73
+ // Internal Variables
74
+ let id = Math.random() * 100;
75
+ let resizing;
76
+ let considerResizing;
77
+ let startPoint;
78
+ let startWidth = 0;
79
+ let width;
80
+
81
+ let lockWidth = memo(0);
82
+
83
+ let sorted;
84
+ let viewport;
85
+
86
+ $: inBuilder = $builderStore?.inBuilder;
87
+ $: columnOptionsStore.set({
88
+ ...columnOptions,
89
+ inBuilder,
90
+ cellComponent: getCellComponent(columnOptions.schema),
91
+ headerComponent:
92
+ headerComponents[columnOptions?.schema?.type] ?? CellString,
93
+ background:
94
+ sticky && scrollPos
95
+ ? "var(--spectrum-global-color-gray-75)"
96
+ : columnOptions.quiet
97
+ ? "transparent"
98
+ : columnOptions.background,
99
+ });
100
+
101
+ $: maxWidth = getMaxWidth($lockWidth, $columnOptionsStore);
102
+ $: minWidth = getMinWidth($lockWidth, $columnOptionsStore);
103
+
104
+ $: footerLabel = $columnOptionsStore.footerTemplate
105
+ ? processStringSync($columnOptionsStore.footerTemplate, {
106
+ values,
107
+ })
108
+ : undefined;
109
+
110
+ $: values = $stbData?.rows?.map((row) =>
111
+ deepGet(row, $columnOptionsStore.name)
112
+ );
113
+
114
+ $: if ($stbSortColumn == $columnOptionsStore.name) {
115
+ sorted = $stbSortOrder;
116
+ } else if ($stbSortColumn != $columnOptionsStore.name && sorted) {
117
+ sorted = undefined;
118
+ }
119
+
120
+ const columnOptionsStore = memo({
121
+ ...columnOptions,
122
+ cellComponent: cellComponents[columnOptions?.schema?.type] ?? CellString,
123
+ headerComponent:
124
+ headerComponents[columnOptions?.schema?.type] ?? CellString,
125
+ });
126
+
127
+ const rowCellOptions = derivedMemo(
128
+ columnOptionsStore,
129
+ ($columnOptionsStore) => {
130
+ return {
131
+ role: "tableCell",
132
+ showDirty: true,
133
+ readonly: !$columnOptionsStore.canEdit,
134
+ align: $columnOptionsStore.align,
135
+ template: $columnOptionsStore.template,
136
+ optionsViewMode: $columnOptionsStore.optionsViewMode,
137
+ relViewMode: $columnOptionsStore.relViewMode,
138
+ padding: $columnOptionsStore.isFirst ? "1rem" : "0.5rem",
139
+ };
140
+ }
141
+ );
142
+
143
+ const headerCellOptions = derivedMemo(
144
+ columnOptionsStore,
145
+ ($columnOptionsStore) => {
146
+ return {
147
+ align: $columnOptionsStore?.align,
148
+ color: $columnOptionsStore?.color,
149
+ background: "var(--spectrum-global-color-gray-50)",
150
+ fontWeight: $columnOptionsStore?.fontWeight,
151
+ padding: $columnOptionsStore?.cellPadding,
152
+ placeholder: $columnOptionsStore.defaultFilteringOperator,
153
+ clearValueIcon: true,
154
+ optionsViewMode: "text",
155
+ optionsSource: "schema",
156
+ debounce: 250,
157
+ controlType: "select",
158
+ initialState: "Editing",
159
+ role: "inlineInput",
160
+ };
161
+ }
162
+ );
163
+
164
+ // Allow the Super Table to bind to the Super Column State Machine to control it
165
+ export const columnState = fsm("Idle", {
166
+ "*": {
167
+ reset() {
168
+ return "Idle";
169
+ },
170
+ headerClicked() {
171
+ if ($columnOptionsStore.canFilter) this.filter();
172
+ else this.sort();
173
+ },
174
+ sort() {
175
+ if (columnOptions.canSort) {
176
+ stbState.sortBy(
177
+ columnOptions.name,
178
+ sorted == "ascending" ? "descending" : "ascending"
179
+ );
180
+ sorted = "ascending" ? "descending" : "ascending";
181
+ }
182
+ },
183
+ lockWidth() {
184
+ if (!resizing) $lockWidth = viewport.clientWidth;
185
+ },
186
+ unlockWidth() {
187
+ if (resizing) return;
188
+ $lockWidth = 0;
189
+ },
190
+ startResizing(e) {
191
+ e.stopPropagation();
192
+ e.preventDefault();
193
+ resizing = true;
194
+ startPoint = e.clientX;
195
+ startWidth = viewport.clientWidth;
196
+ $lockWidth = startWidth;
197
+ },
198
+ resize(e) {
199
+ $lockWidth = startWidth + e.clientX - startPoint;
200
+ },
201
+ stopResizing(e) {
202
+ e.preventDefault();
203
+ e.stopPropagation();
204
+ resizing = false;
205
+ startPoint = undefined;
206
+ width = $lockWidth;
207
+ },
208
+ resetSize(e) {
209
+ e.preventDefault();
210
+ e.stopPropagation();
211
+ $lockWidth = 0;
212
+ width = 0;
213
+ },
214
+ },
215
+ Idle: {
216
+ _enter() {
217
+ $lockWidth = 0;
218
+ },
219
+ filter() {
220
+ return columnOptions.canFilter ? "Entering" : "Idle";
221
+ },
222
+ enteredit(index) {
223
+ if (inBuilder) return;
224
+ $stbEditing = index;
225
+ stbState.edit();
226
+ return "EditingCell";
227
+ },
228
+ addRow() {
229
+ return "Inserting";
230
+ },
231
+ },
232
+ Entering: {
233
+ _enter() {
234
+ $lockWidth = viewport.clientWidth;
235
+ },
236
+ filter(filterObj) {
237
+ stbState.addFilter({ ...filterObj, id: id });
238
+ return "Filtered";
239
+ },
240
+ cancel() {
241
+ return "Idle";
242
+ },
243
+ clear() {
244
+ return "Idle";
245
+ },
246
+ },
247
+ Filtered: {
248
+ filter(filterObj) {
249
+ stbState.removeFilter(id);
250
+ stbState.addFilter({ ...filterObj, id: id });
251
+ },
252
+ clear() {
253
+ stbState.clearFilter(id);
254
+ return "Entering";
255
+ },
256
+ },
257
+ EditingCell: {
258
+ _enter() {
259
+ $lockWidth = viewport.clientWidth;
260
+ stbState.edit.debounce(30);
261
+ },
262
+ patchRow(index, id, rev, field, change) {
263
+ stbState.patchRow(index, id, rev, field, change);
264
+ },
265
+ exitedit(index) {
266
+ $stbEditing = -1;
267
+ stbState.endEdit.debounce(50);
268
+ return "Idle";
269
+ },
270
+ },
271
+ Inserting: {
272
+ _enter() {
273
+ $lockWidth = viewport.clientWidth;
274
+ },
275
+ _exit() {
276
+ $lockWidth = 0;
277
+ },
278
+ cancelAddRow() {
279
+ return "Idle";
280
+ },
281
+ },
282
+ });
283
+
284
+ const deepGet = (obj, path) => {
285
+ if (obj && path.includes(".")) {
286
+ for (var i = 0, path = path.split("."), len = path.length; i < len; i++) {
287
+ if (obj[path[i]]) obj = obj[path[i]];
288
+ else {
289
+ obj = null;
290
+ break;
291
+ }
292
+ }
293
+ return obj;
294
+ } else return obj[path] ?? undefined;
295
+ };
296
+
297
+ const getMinWidth = (val, options) => {
298
+ if (val > 0) return val;
299
+ if (options.widthOverride) return options.widthOverride;
300
+
301
+ return options.sizing == "fixed" ? options.fixedWidth : options.minWidth;
302
+ };
303
+
304
+ const getMaxWidth = (val, options) => {
305
+ if (val > 0) return val;
306
+ if (options.widthOverride) return options.widthOverride;
307
+
308
+ return options.sizing == "fixed" ? options.fixedWidth : "unset";
309
+ };
310
+
311
+ const getCellComponent = (columnSchema) => {
312
+ let comp;
313
+ let editable = columnOptions.canEdit;
314
+
315
+ if (columnSchema.type == "json") {
316
+ comp = cellComponents[columnSchema.type] || CellString;
317
+ } else {
318
+ comp = cellComponents[columnSchema.type] || CellString;
319
+ }
320
+
321
+ if (comp == CellString && !editable) comp = CellStringSimple;
322
+
323
+ return comp;
324
+ };
325
+
326
+ setContext("stColumnOptions", columnOptionsStore);
327
+ setContext("stRowCellOptions", rowCellOptions);
328
+ setContext("stHeaderCellOptions", headerCellOptions);
329
+ setContext("stColumnState", columnState);
330
+
331
+ onMount(() => {
332
+ stbAPI?.registerSuperColumn(id, columnState);
333
+ });
334
+
335
+ onDestroy(() => {
336
+ stbAPI?.unregisterSuperColumn(id);
337
+ });
338
+ </script>
339
+
340
+ <svelte:window
341
+ on:mouseup={(e) => {
342
+ if (resizing) columnState.stopResizing(e);
343
+ }}
344
+ on:mousemove={(e) => {
345
+ if (resizing) columnState.resize(e);
346
+ }}
347
+ />
348
+
349
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
350
+ <div
351
+ bind:this={viewport}
352
+ class="super-column"
353
+ class:sticky={sticky && scrollPos}
354
+ class:resizing
355
+ class:considerResizing={considerResizing && !resizing}
356
+ class:isLast={$columnOptionsStore.isLast}
357
+ style:max-width={maxWidth}
358
+ style:min-width={minWidth}
359
+ on:mouseleave={() => ($stbHovered = null)}
360
+ >
361
+ {#if $columnOptionsStore.showHeader && $columnOptionsStore.canResize}
362
+ <div
363
+ class="grabber"
364
+ style:height={$columnOptionsStore.headerHeight - 16}
365
+ on:mousedown={columnState.startResizing}
366
+ on:dblclick={columnState.resetSize}
367
+ on:mouseenter={() => (considerResizing = true)}
368
+ on:mouseleave={() => (considerResizing = false)}
369
+ />
370
+ {/if}
371
+
372
+ {#if $columnOptionsStore.showHeader}
373
+ <SuperColumnHeader {sorted} />
374
+ {/if}
375
+
376
+ <SuperColumnBody
377
+ rows={$stbData.rows}
378
+ rowHeight={$stbSettings.appearance.rowHeight}
379
+ field={$columnOptionsStore.name}
380
+ idField={$stbSettings.data.idColumn}
381
+ zebra={$stbSettings.appearance.zebraColors}
382
+ isLast={$columnOptionsStore.isLast}
383
+ isFirst={$columnOptionsStore.isFirst}
384
+ canInsert={$stbSettings.features.canInsert}
385
+ >
386
+ <slot />
387
+ </SuperColumnBody>
388
+
389
+ {#if $columnOptionsStore.showFooter}
390
+ <SuperColumnFooter {footerLabel} />
391
+ {/if}
392
+ </div>
@@ -0,0 +1,9 @@
1
+ // Export main SuperTableColumn component
2
+ export { default as SuperTableColumn } from './SuperTableColumn.svelte';
3
+
4
+ // Export parts components
5
+ export { default as SuperColumnBody } from './parts/SuperColumnBody.svelte';
6
+ export { default as SuperColumnFooter } from './parts/SuperColumnFooter.svelte';
7
+ export { default as SuperColumnHeader } from './parts/SuperColumnHeader.svelte';
8
+ export { default as SuperColumnRow } from './parts/SuperColumnRow.svelte';
9
+ export { default as SuperColumnRowNew } from './parts/SuperColumnRowNew.svelte';
@@ -0,0 +1,57 @@
1
+ <script>
2
+ import { getContext } from "svelte";
3
+ import SuperColumnRow from "./SuperColumnRow.svelte";
4
+ import SuperColumnRowNew from "./SuperColumnRowNew.svelte";
5
+ const columnSettings = getContext("stColumnOptions");
6
+ const columnState = getContext("stColumnState");
7
+ const stbVisibleRows = getContext("stbVisibleRows");
8
+ const stbState = getContext("stbState");
9
+
10
+ export let field;
11
+ export let idField;
12
+ export let isLast;
13
+ export let isFirst;
14
+ export let zebra;
15
+ export let rowHeight;
16
+ export let rows;
17
+
18
+ $: inserting = $columnState == "Inserting";
19
+ $: quiet = $columnSettings.quiet;
20
+ $: editing =
21
+ $columnState == "EditingCell" &&
22
+ ($columnSettings.highlighters == "vertical" ||
23
+ $columnSettings.highlighters == "both");
24
+ </script>
25
+
26
+ <div
27
+ class="super-column-body"
28
+ style:margin-top={"var(--super-column-top-offset)"}
29
+ tabindex="-1"
30
+ class:quiet
31
+ class:zebra
32
+ class:inserting
33
+ class:filtered={$columnState == "Filtered"}
34
+ class:is-editing={editing}
35
+ >
36
+ {#if rows?.length}
37
+ {#each $stbVisibleRows as index}
38
+ {#if rows[index]}
39
+ <SuperColumnRow
40
+ {isLast}
41
+ {index}
42
+ row={rows[index]}
43
+ {field}
44
+ {idField}
45
+ disabled={inserting}
46
+ {rowHeight}
47
+ on:resize={(e) => stbState.resizeRow(index, e.detail)}
48
+ >
49
+ <slot />
50
+ </SuperColumnRow>
51
+ {/if}
52
+ {/each}
53
+ {/if}
54
+ {#if inserting}
55
+ <SuperColumnRowNew {isFirst} {isLast} />
56
+ {/if}
57
+ </div>
@@ -0,0 +1,14 @@
1
+ <script>
2
+ import { getContext } from "svelte";
3
+ const columnOptions = getContext("stColumnOptions");
4
+ export let footerLabel;
5
+ </script>
6
+
7
+ <div
8
+ class="super-column-footer"
9
+ style:justify-content={$columnOptions?.headerAlign}
10
+ >
11
+ <span>
12
+ {footerLabel || $columnOptions.displayName || $columnOptions.name}
13
+ </span>
14
+ </div>
@@ -0,0 +1,228 @@
1
+ <script>
2
+ import { getContext } from "svelte";
3
+ import SuperPopover from "../../SuperPopover/SuperPopover.svelte";
4
+
5
+ const columnOptions = getContext("stColumnOptions");
6
+ const cellOptions = getContext("stHeaderCellOptions");
7
+ const columnState = getContext("stColumnState");
8
+ const { API } = getContext("sdk");
9
+
10
+ export let sorted;
11
+
12
+ let headerAnchor;
13
+ let showFilteringOptions = false;
14
+ let filterValue;
15
+ let filterOperator = $columnOptions.defaultFilteringOperator;
16
+ let schema;
17
+ let filterColumn;
18
+ let hovered;
19
+
20
+ $: isLink = $columnOptions.schema.type == "link";
21
+ $: if (isLink && !schema && $columnOptions.canFilter)
22
+ fetchDefinition($columnOptions.schema.tableId);
23
+
24
+ $: if (isLink && schema) {
25
+ filterColumn = "1:" + $columnOptions.name + "." + schema?.primaryDisplay;
26
+ } else {
27
+ filterColumn = $columnOptions.name;
28
+ }
29
+
30
+ $: isEntering = $columnState == "Entering";
31
+
32
+ const handleValueChange = (e) => {
33
+ if (e.detail != undefined && e.detail != null && e.detail != "") {
34
+ filterValue = e.detail;
35
+ if ($columnOptions.schema.type == "boolean" && filterValue === false) {
36
+ columnState.filter(buildFilter("notEqual", true));
37
+ } else if (Array.isArray(e.detail) && e.detail.length == 0) {
38
+ columnState.clear();
39
+ } else {
40
+ columnState.filter(buildFilter(filterOperator, filterValue));
41
+ }
42
+ } else {
43
+ showFilteringOptions = false;
44
+ filterValue = null;
45
+ columnState.clear();
46
+ }
47
+ };
48
+
49
+ const buildFilter = (operator, value) => {
50
+ let temp;
51
+ if (operator == "oneOf" && !Array.isArray(value)) {
52
+ temp = value.split(",");
53
+ } else if (
54
+ operator != "oneOf" &&
55
+ operator != "containsAny" &&
56
+ Array.isArray(value)
57
+ ) {
58
+ temp = value[0];
59
+ filterValue = temp;
60
+ } else {
61
+ temp = value;
62
+ }
63
+
64
+ return {
65
+ field: filterColumn,
66
+ operator: operator,
67
+ value: temp,
68
+ type: isLink ? "string" : $columnOptions.schema.type,
69
+ valueType: "Value",
70
+ };
71
+ };
72
+
73
+ const handleOperatorChange = (op) => {
74
+ filterOperator = op;
75
+ if (filterValue || op == "empty" || op == "notEmpty")
76
+ columnState.filter(buildFilter(filterOperator, filterValue ?? ""));
77
+
78
+ showFilteringOptions = false;
79
+ };
80
+
81
+ const handleBlur = (e) => {
82
+ if (headerAnchor.matches(":focus-within")) return;
83
+ columnState.cancel();
84
+ };
85
+
86
+ const fetchDefinition = async (tableId) => {
87
+ if (tableId) {
88
+ schema = await API.fetchTableDefinition(tableId);
89
+ }
90
+ };
91
+ </script>
92
+
93
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
94
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
95
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
96
+ <div
97
+ bind:this={headerAnchor}
98
+ class="super-column-header"
99
+ class:isEntering
100
+ class:filtered={$columnState == "Filtered"}
101
+ class:idle={$columnState != "Entering" && $columnState != "Filtered"}
102
+ style:padding-left={$cellOptions.padding}
103
+ style:padding-right={$cellOptions.padding}
104
+ on:mouseenter={() => (hovered = true)}
105
+ on:mouseleave={() => (hovered = false)}
106
+ >
107
+ {#if $columnState == "Entering" || $columnState == "Filtered"}
108
+ {#if $columnOptions.canFilter == "advanced"}
109
+ <i
110
+ class="ri-filter-3-line"
111
+ tabindex="0"
112
+ style="align-self: center; font-size: 14px;"
113
+ on:click|preventDefault={() =>
114
+ (showFilteringOptions = !showFilteringOptions)}
115
+ />
116
+ {/if}
117
+ <svelte:component
118
+ this={$columnOptions.headerComponent}
119
+ cellOptions={{
120
+ ...$cellOptions,
121
+ placeholder: filterOperator,
122
+ disabled: filterOperator == "empty" || filterOperator == "notEmpty",
123
+ }}
124
+ value={filterValue}
125
+ fieldSchema={$columnOptions.schema}
126
+ multi={filterOperator == "containsAny" || filterOperator == "oneOf"}
127
+ on:change={handleValueChange}
128
+ on:cancel={columnState.cancel}
129
+ on:exitedit={handleBlur}
130
+ />
131
+ {:else}
132
+ <div
133
+ class="headerLabel"
134
+ style:justify-content={$columnOptions?.headerAlign}
135
+ on:click={columnState.headerClicked}
136
+ >
137
+ <div class="innerText" class:sortable={$columnOptions.canSort}>
138
+ {$columnOptions.displayName ?? $columnOptions.name}
139
+ </div>
140
+ </div>
141
+ {/if}
142
+
143
+ {#if $columnOptions.canSort && $columnState == "Idle"}
144
+ <span class="placeholder" on:click={columnState.sort}>
145
+ {#if hovered || sorted}
146
+ <i
147
+ class={sorted == "ascending" ? "ri-sort-asc" : "ri-sort-desc"}
148
+ class:sorted
149
+ />
150
+ {/if}
151
+ </span>
152
+ {/if}
153
+ </div>
154
+
155
+ {#if $columnOptions.canFilter == "advanced" && $columnState != "Idle"}
156
+ <SuperPopover
157
+ anchor={headerAnchor}
158
+ open={showFilteringOptions}
159
+ align={"left"}
160
+ minWidth={160}
161
+ on:close={() => {
162
+ showFilteringOptions = false;
163
+ handleBlur();
164
+ }}
165
+ >
166
+ <ul
167
+ class="spectrum-Menu"
168
+ role="menu"
169
+ style="background-color: var(--spectrum-global-color-gray-75 );"
170
+ >
171
+ {#each $columnOptions.filteringOperators as option}
172
+ <li
173
+ class="spectrum-Menu-item"
174
+ class:selected={option.value == filterOperator}
175
+ role="menuitem"
176
+ on:mousedown|preventDefault={() => handleOperatorChange(option.value)}
177
+ >
178
+ <span class="spectrum-Menu-itemLabel">{option.label}</span>
179
+ </li>
180
+ {/each}
181
+ </ul>
182
+ </SuperPopover>
183
+ {/if}
184
+
185
+ <style>
186
+ i {
187
+ &:hover {
188
+ cursor: pointer;
189
+ }
190
+ }
191
+ .isEntering {
192
+ gap: 0.5rem;
193
+ }
194
+
195
+ .placeholder {
196
+ min-width: 1rem;
197
+ height: 1rem;
198
+ display: flex;
199
+ align-items: center;
200
+ justify-content: center;
201
+ color: var(--spectrum-global-color-gray-500);
202
+ &:hover {
203
+ color: var(--spectrum-global-color-gray-800);
204
+ cursor: pointer;
205
+ }
206
+ }
207
+
208
+ .sorted {
209
+ color: var(--spectrum-global-color-gray-800);
210
+ }
211
+ .filtered {
212
+ gap: 0.5rem;
213
+ color: var(--spectrum-global-color-gray-800);
214
+ font-weight: 600;
215
+ background-color: var(--spectrum-global-color-gray-100);
216
+ }
217
+
218
+ .sortable {
219
+ cursor: pointer;
220
+ }
221
+ .sortable:hover {
222
+ filter: brightness(120%);
223
+ }
224
+ .selected {
225
+ color: var(--primaryColor);
226
+ background-color: var(--spectrum-global-color-gray-75);
227
+ }
228
+ </style>