@poirazis/supercomponents-shared 1.2.11 → 1.2.13

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 (34) hide show
  1. package/dist/index.js +11081 -10997
  2. package/dist/index.umd.cjs +13 -13
  3. package/package.json +1 -1
  4. package/src/lib/SuperField/SuperField.svelte +1 -1
  5. package/src/lib/SuperForm/InnerForm.svelte +68 -19
  6. package/src/lib/SuperForm/SuperForm.svelte +13 -3
  7. package/src/lib/SuperTable/SuperTable.css +9 -6
  8. package/src/lib/SuperTable/SuperTable.svelte +207 -193
  9. package/src/lib/SuperTable/controls/ColumnsSection.svelte +11 -19
  10. package/src/lib/SuperTable/controls/RowButtonsColumn.svelte +4 -4
  11. package/src/lib/SuperTable/controls/SelectionColumn.svelte +9 -10
  12. package/src/lib/SuperTable/overlays/AddNewRowOverlay.svelte +1 -1
  13. package/src/lib/SuperTableCells/CellAttachmentExpanded.svelte +0 -1
  14. package/src/lib/SuperTableCells/CellAttachmentSlider.svelte +0 -1
  15. package/src/lib/SuperTableCells/CellBoolean.svelte +0 -1
  16. package/src/lib/SuperTableCells/CellCommon.css +60 -88
  17. package/src/lib/SuperTableCells/CellDateRange.svelte +6 -32
  18. package/src/lib/SuperTableCells/CellDatetime.svelte +3 -4
  19. package/src/lib/SuperTableCells/CellJSON.svelte +1 -4
  20. package/src/lib/SuperTableCells/CellLink.svelte +22 -21
  21. package/src/lib/SuperTableCells/CellLinkAdvanced.svelte +3 -7
  22. package/src/lib/SuperTableCells/CellLinkPickerSelect.svelte +7 -4
  23. package/src/lib/SuperTableCells/CellNumber.svelte +18 -23
  24. package/src/lib/SuperTableCells/CellOptions.svelte +39 -37
  25. package/src/lib/SuperTableCells/CellSQLLink.svelte +85 -66
  26. package/src/lib/SuperTableCells/CellSQLLinkPicker.svelte +66 -36
  27. package/src/lib/SuperTableCells/CellString.svelte +9 -25
  28. package/src/lib/SuperTableCells/CellStringMask.svelte +119 -26
  29. package/src/lib/SuperTableCells/CellStringSimple.svelte +6 -8
  30. package/src/lib/SuperTableColumn/SuperTableColumn.svelte +10 -10
  31. package/src/lib/SuperTableColumn/parts/SuperColumnHeader.svelte +4 -1
  32. package/src/lib/SuperTableColumn/parts/SuperColumnRow.svelte +25 -21
  33. package/src/lib/SuperTabs/SuperTabs.svelte +28 -23
  34. package/src/lib/SuperTable/controls/SuperTableWelcome.svelte +0 -58
@@ -2,12 +2,7 @@
2
2
  import { getContext, setContext, onDestroy, tick } from "svelte";
3
3
  import fsm from "svelte-fsm";
4
4
  import { writable } from "svelte/store";
5
- import type {
6
- LogicalOperator,
7
- EmptyFilterOption,
8
- SearchFilters,
9
- } from "@budibase/types";
10
-
5
+ import type { SearchFilters } from "@budibase/types";
11
6
  import {
12
7
  sizingMap,
13
8
  defaultOperatorMap,
@@ -66,7 +61,7 @@
66
61
  export let limit = 50;
67
62
 
68
63
  export let autoRefreshRate;
69
- export let paginate;
64
+ export let paginate = true;
70
65
  export let filter;
71
66
 
72
67
  export let columnList;
@@ -110,7 +105,7 @@
110
105
  export let footerColorTemplate, footerBGColorTemplate;
111
106
 
112
107
  export let useOptionColors = true;
113
- export let optionsViewMode = "colorText";
108
+ export let optionsViewMode = "bullets";
114
109
  export let relViewMode = "pills";
115
110
  export let zebraColors = false;
116
111
  export let quiet;
@@ -135,9 +130,10 @@
135
130
  const columnsStore = memo(columnList);
136
131
  const stbRowMetadata = writable([]);
137
132
  const filterStore = memo(filter);
133
+ const cachedRows = writable([]);
134
+ const loading = writable(false);
138
135
 
139
136
  $: dataSourceStore.set(dataSource);
140
- $: tableAPI.decidePagination($dataSourceStore);
141
137
  $: filterStore.set(filter);
142
138
  $: stbSchema.set($stbData?.definition?.schema);
143
139
 
@@ -148,7 +144,7 @@
148
144
  ? toNumber(
149
145
  processStringSync(rowHeight, {
150
146
  [comp_id]: { row: {} },
151
- })
147
+ }),
152
148
  ) || sizingMap[size].rowHeight
153
149
  : sizingMap[size].rowHeight;
154
150
 
@@ -156,7 +152,7 @@
156
152
  let tableId;
157
153
  let idColumn;
158
154
  let pagination;
159
- let fetchOnScroll = false;
155
+ let fetchOnScroll = true;
160
156
  let timer;
161
157
 
162
158
  let highlighted;
@@ -172,11 +168,11 @@
172
168
  let touchStartX = 0;
173
169
  let overflow;
174
170
  let isEmpty;
175
- let _limit = limit;
171
+
176
172
  let initializing = false;
173
+
177
174
  let initTimer;
178
- let start,
179
- end = 0;
175
+ let start, end;
180
176
 
181
177
  let stbData = writable({ rows: [], count: 0, definition: {} });
182
178
 
@@ -300,15 +296,8 @@
300
296
  });
301
297
 
302
298
  const createFetch = (datasource) => {
303
- if (datasource.parameters) {
304
- datasource = {
305
- ...datasource,
306
- queryParams: {
307
- ...datasource.queryParams,
308
- limit: limit,
309
- },
310
- };
311
- }
299
+ defaultQuery = QueryUtils.buildQuery($filterStore);
300
+ query = tableAPI.extendQuery(defaultQuery, queryExtensions);
312
301
 
313
302
  return fetchData({
314
303
  API,
@@ -318,7 +307,6 @@
318
307
  sortColumn,
319
308
  sortOrder,
320
309
  limit,
321
- paginate: true,
322
310
  },
323
311
  });
324
312
  };
@@ -387,7 +375,7 @@
387
375
  !specialColumns.includes(v) &&
388
376
  !schema[v].nestedJSON &&
389
377
  schema[v]?.visible != false &&
390
- v != idColumn
378
+ v != idColumn,
391
379
  )
392
380
  .map((v) => {
393
381
  return tableAPI.enrichColumn(schema, schema[v]);
@@ -471,7 +459,7 @@
471
459
  headerAlign: bbcolumn.align ? bbcolumn.align : "flex-start",
472
460
  type,
473
461
  displayName: tableAPI.beautifyLabel(
474
- bbcolumn.displayName ?? bbcolumn.name
462
+ bbcolumn.displayName ?? bbcolumn.name,
475
463
  ),
476
464
  schema: columnSchema,
477
465
  };
@@ -548,7 +536,7 @@
548
536
  }
549
537
  if (!conditions || conditions.length === 0) return true;
550
538
  const hasShow = conditions.some(
551
- (cond) => cond.action.toLowerCase() === "show"
539
+ (cond) => cond.action.toLowerCase() === "show",
552
540
  );
553
541
  let visible = !hasShow;
554
542
  for (const cond of conditions) {
@@ -566,7 +554,7 @@
566
554
  executeRowButtonAction: async (index, action) => {
567
555
  let cmd = enrichButtonActions(
568
556
  action,
569
- tableAPI.enrichContext($stbData?.rows[index])
557
+ tableAPI.enrichContext($cachedRows[index]),
570
558
  );
571
559
  await cmd?.();
572
560
  },
@@ -576,7 +564,7 @@
576
564
  executeCellOnClickAction: async (index, column, value, id) => {
577
565
  let cmd = enrichButtonActions(
578
566
  onCellClick,
579
- tableAPI.enrichContext($stbData?.rows[index])
567
+ tableAPI.enrichContext($cachedRows[index]),
580
568
  );
581
569
  await cmd?.({ column, value, id });
582
570
  },
@@ -596,7 +584,7 @@
596
584
  await tick();
597
585
  let cmd = enrichButtonActions(
598
586
  onRowSelect,
599
- tableAPI.enrichContext($stbData?.rows[index])
587
+ tableAPI.enrichContext($cachedRows[index]),
600
588
  );
601
589
  await cmd?.();
602
590
  },
@@ -618,7 +606,7 @@
618
606
  tableAPI.executeRowButtonAction(null, action);
619
607
  },
620
608
  selectRow: (index) => {
621
- let id = tableAPI.getRowId($stbData?.rows[index], index);
609
+ let id = tableAPI.getRowId($cachedRows[index], index);
622
610
  let disabled = $stbRowMetadata[index]["disabled"];
623
611
 
624
612
  if (maxSelected != 1) {
@@ -633,7 +621,7 @@
633
621
  "Cannot select more than " +
634
622
  maxSelected +
635
623
  " " +
636
- (entityPlural || "Rows")
624
+ (entityPlural || "Rows"),
637
625
  );
638
626
  }
639
627
  } else {
@@ -648,8 +636,8 @@
648
636
  if ($stbSelected.length) tableAPI.executeRowOnSelectAction(index);
649
637
  },
650
638
  selectAllRows: () => {
651
- if ($stbSelected.length != $stbData?.rows.length)
652
- $stbSelected = $stbData?.rows.map((x, i) => tableAPI.getRowId(x, i));
639
+ if ($stbSelected.length != $cachedRows.length)
640
+ $stbSelected = $cachedRows.map((x, i) => tableAPI.getRowId(x, i));
653
641
  else $stbSelected = [];
654
642
  },
655
643
  clearSelection: () => {
@@ -666,7 +654,7 @@
666
654
  try {
667
655
  saved_row = await API.saveRow(
668
656
  { ...$new_row, tableId },
669
- { suppressErrors: true }
657
+ { suppressErrors: true },
670
658
  );
671
659
 
672
660
  // Clear errors on success
@@ -709,7 +697,7 @@
709
697
  }
710
698
  },
711
699
  deleteRow: async (index) => {
712
- let row = $stbData?.rows[index];
700
+ let row = $cachedRows[index];
713
701
  $stbRowMetadata[index]["disabled"] = true;
714
702
  await tick();
715
703
  let id = row[idColumn];
@@ -736,13 +724,13 @@
736
724
  let cmd;
737
725
  let cmd_after = enrichButtonActions(
738
726
  afterDelete,
739
- tableAPI.enrichContext($stbData?.rows[index])
727
+ tableAPI.enrichContext($cachedRows[index]),
740
728
  );
741
729
 
742
730
  if (onDelete?.length) {
743
731
  cmd = enrichButtonActions(
744
732
  onDelete,
745
- tableAPI.enrichContext($stbData?.rows[index])
733
+ tableAPI.enrichContext($cachedRows[index]),
746
734
  );
747
735
  } else {
748
736
  cmd = enrichButtonActions(autoDelete, {});
@@ -755,13 +743,13 @@
755
743
  if ($stbSelected.includes(tableAPI.getRowId(row, index))) {
756
744
  $stbSelected.splice(
757
745
  $stbSelected.indexOf(tableAPI.getRowId(row, index)),
758
- 1
746
+ 1,
759
747
  );
760
748
  $stbSelected = $stbSelected;
761
749
  }
762
750
 
763
751
  // Refresh the dataset
764
- stbData.refresh();
752
+ stbState.refresh();
765
753
  },
766
754
  deleteSelectedRows: async () => {
767
755
  let rowsToDelete = $stbSelected
@@ -770,7 +758,7 @@
770
758
  let idsToDelete = rowsToDelete.map((row) => row._id);
771
759
 
772
760
  rowsToDelete.forEach((row) => {
773
- const rowIndex = $stbData.rows.indexOf(row);
761
+ const rowIndex = $cachedRows.indexOf(row);
774
762
  if (rowIndex !== -1) {
775
763
  $stbRowMetadata[rowIndex]["disabled"] = true;
776
764
  }
@@ -805,7 +793,7 @@
805
793
  await cmd?.();
806
794
  await cmd_after?.();
807
795
 
808
- stbData.refresh();
796
+ stbState.refresh();
809
797
  },
810
798
  patchRow: async (patch) => {
811
799
  // We can only patch tables
@@ -818,7 +806,7 @@
818
806
  tableId,
819
807
  ...patch,
820
808
  },
821
- true
809
+ true,
822
810
  );
823
811
 
824
812
  stbState.refresh();
@@ -839,32 +827,30 @@
839
827
  },
840
828
  getRowById: (id) => {
841
829
  if (idColumn) {
842
- return $stbData.rows.find((row) => row[idColumn]?.toString() === id);
830
+ return $cachedRows.find((row) => row[idColumn]?.toString() === id);
843
831
  } else {
844
- return $stbData.rows[parseInt(id)];
832
+ return $cachedRows[parseInt(id)];
845
833
  }
846
834
  },
847
835
  extendQuery: (
848
836
  defaultQuery: SearchFilters,
849
- extensions: Record<string, any>
837
+ extensions: Record<string, any>,
850
838
  ): SearchFilters => {
851
839
  if (!Object.keys(extensions).length) {
852
840
  return defaultQuery;
853
841
  }
854
842
  const extended: SearchFilters = {
855
- [LogicalOperator.AND]: {
843
+ ["$and"]: {
856
844
  conditions: [
857
845
  ...(defaultQuery ? [defaultQuery] : []),
858
846
  ...Object.values(extensions || {}),
859
847
  ],
860
848
  },
861
- onEmptyFilter: EmptyFilterOption.RETURN_NONE,
849
+ onEmptyFilter: "none",
862
850
  };
863
851
 
864
852
  // If there are no conditions applied at all, clear the request.
865
- return (extended[LogicalOperator.AND]?.conditions?.length ?? 0) > 0
866
- ? extended
867
- : {};
853
+ return (extended["$and"]?.conditions?.length ?? 0) > 0 ? extended : {};
868
854
  },
869
855
  addQueryExtension: (key, extension) => {
870
856
  if (!key || !extension) {
@@ -911,21 +897,6 @@
911
897
  ? [ids]
912
898
  : [];
913
899
  },
914
- decidePagination: (ds) => {
915
- if (!ds) {
916
- pagination = "none";
917
- return;
918
- }
919
-
920
- if (ds.parameters && ds.parameters.length) {
921
- const paramNames = ds.parameters.map((p) => p.name.toLowerCase());
922
- if (paramNames.includes("offset") && paramNames.includes("limit"))
923
- pagination = "limitOffset";
924
- } else if (dataSource.tableId) pagination = "cursor";
925
- else pagination = "none";
926
-
927
- fetchOnScroll = pagination == "cursor";
928
- },
929
900
  };
930
901
 
931
902
  // Super Table State Machine
@@ -934,27 +905,22 @@
934
905
  init() {
935
906
  return "Init";
936
907
  },
937
- refresh() {
938
- stbData?.refresh();
939
- },
940
908
  enrichRows(
941
- stbData,
909
+ cachedRows,
942
910
  rowBGColorTemplate,
943
911
  rowColorTemplate,
944
912
  rowHeight,
945
913
  rowDisabledTemplate,
946
- stbSelected
914
+ stbSelected,
947
915
  ) {
948
- if (stbData?.loading) return;
949
-
950
- $stbRowMetadata = stbData?.rows?.map((row, index) => {
916
+ $stbRowMetadata = cachedRows.map((row, index) => {
951
917
  return {
952
918
  height: rowHeight
953
919
  ? toNumber(
954
920
  processStringSync(rowHeight, {
955
921
  ...$context,
956
922
  [comp_id]: { row },
957
- })
923
+ }),
958
924
  ) || $stbSettings.appearance.rowHeight
959
925
  : $stbSettings.appearance.rowHeight,
960
926
  bgcolor: rowBGColorTemplate
@@ -1018,7 +984,7 @@
1018
984
  this.calculateRowBoundaries();
1019
985
  },
1020
986
  calculateBoundaries() {
1021
- let rows = $stbData?.rows;
987
+ let rows = $cachedRows;
1022
988
  if (!rows || !viewport) return;
1023
989
 
1024
990
  const defaultRowHeight = $stbSettings.appearance.rowHeight;
@@ -1050,10 +1016,13 @@
1050
1016
  this.calculateRowBoundaries();
1051
1017
  },
1052
1018
  calculateRowBoundaries() {
1053
- let start = 0;
1054
- let end = 0;
1055
- let rows = $stbData?.rows || [];
1019
+ let rows = $cachedRows || [];
1020
+ if (!rows.length) {
1021
+ $stbVisibleRows = [];
1022
+ return;
1023
+ }
1056
1024
 
1025
+ start = 0;
1057
1026
  end = rows.length;
1058
1027
 
1059
1028
  // Find start index
@@ -1073,7 +1042,7 @@
1073
1042
  }
1074
1043
 
1075
1044
  // Update visible rows
1076
- $stbVisibleRows = $stbData?.rows
1045
+ $stbVisibleRows = $cachedRows
1077
1046
  .slice(start, end)
1078
1047
  .map((_, i) => i + start);
1079
1048
 
@@ -1082,23 +1051,8 @@
1082
1051
  $stbScrollOffset = $stbScrollPos - startHeight;
1083
1052
 
1084
1053
  // Fetch more rows if nearing the end
1085
- if (fetchOnScroll && rows.length > 0) {
1086
- const loadedHeight = $cumulativeHeights[rows.length - 1];
1087
- const remainingHeight =
1088
- loadedHeight - ($stbScrollPos + maxBodyHeight);
1089
-
1090
- // Only fetch if we're actually scrolling near the end AND haven't loaded all possible rows
1091
- // Check if total rows loaded < total available (if known) or if remainingHeight indicates need
1092
- const hasMoreData =
1093
- !$stbData.info?.total || rows.length < $stbData.info.total;
1094
- if (
1095
- remainingHeight < maxBodyHeight &&
1096
- rows.length === _limit &&
1097
- hasMoreData &&
1098
- $stbScrollPos > 0
1099
- ) {
1100
- stbState.fetchMoreRows(limit); // Debounced fetch
1101
- }
1054
+ if (fetchOnScroll && $cachedRows.length - end < 10) {
1055
+ stbState.fetchMoreRows();
1102
1056
  }
1103
1057
  },
1104
1058
  handleVerticalScroll(delta) {
@@ -1108,9 +1062,9 @@
1108
1062
  $stbScrollPos = Math.max(
1109
1063
  Math.min(
1110
1064
  $stbScrollPos + delta,
1111
- Math.max(0, scrollHeight - maxBodyHeight)
1065
+ Math.max(0, scrollHeight - maxBodyHeight),
1112
1066
  ),
1113
- 0
1067
+ 0,
1114
1068
  );
1115
1069
  $stbScrollPercent =
1116
1070
  scrollHeight > maxBodyHeight
@@ -1232,16 +1186,13 @@
1232
1186
  _enter() {
1233
1187
  if (timer) clearInterval(timer);
1234
1188
  if (initTimer) clearTimeout(initTimer);
1235
- start = 0;
1236
- end = 0;
1237
1189
 
1238
1190
  $stbScrollPos = 0;
1239
1191
  $stbScrollOffset = 0;
1240
1192
  $stbHorizontalScrollPos = 0;
1241
1193
  $stbSelected = [];
1242
-
1194
+ $cachedRows = [];
1243
1195
  $stbVisibleRows = [];
1244
- if (_limit != limit) _limit = limit;
1245
1196
 
1246
1197
  stbData = createFetch($dataSourceStore);
1247
1198
 
@@ -1257,11 +1208,12 @@
1257
1208
  if (fetchState.loaded) {
1258
1209
  if (autoRefreshRate && !inBuilder) {
1259
1210
  timer = setInterval(() => {
1260
- if (!$stbData?.loading) stbData?.refresh();
1211
+ stbState.refresh();
1261
1212
  onRefresh?.();
1262
1213
  }, autoRefreshRate * 1000);
1263
1214
  }
1264
1215
 
1216
+ $cachedRows = [...fetchState.rows];
1265
1217
  return "Idle";
1266
1218
  }
1267
1219
  },
@@ -1270,26 +1222,61 @@
1270
1222
  _enter() {
1271
1223
  clearTimeout(initTimer);
1272
1224
  initializing = false;
1273
- isEmpty = $stbData?.rows.length < 1;
1274
- this.calculateRowBoundaries();
1225
+ isEmpty = $cachedRows.length < 1;
1275
1226
  },
1276
1227
  _exit() {},
1277
- synch(fetchState) {
1278
- if (fetchState.loading && !fetchState.loaded) return;
1279
- isEmpty = !$stbData?.rows.length;
1280
- if (fetchState.loaded) {
1281
- this.calculateRowBoundaries();
1282
- }
1283
- },
1284
1228
  addFilter(filterObj) {
1285
1229
  let extention = QueryUtils.buildQuery([{ ...filterObj }]);
1286
1230
  stbColumnFilters.add(filterObj.id);
1287
1231
  tableAPI.addQueryExtension(filterObj.id, extention);
1288
1232
  return "Filtered";
1289
1233
  },
1234
+ synch(fetchState) {
1235
+ if (fetchState.loading) return;
1236
+ if (fetchState.loaded) {
1237
+ isEmpty = fetchState.rows.length < 1;
1238
+ $cachedRows = [...fetchState.rows];
1239
+ this.calculateRowBoundaries();
1240
+ }
1241
+ },
1242
+ refresh() {
1243
+ if ($stbData?.loading) return;
1244
+
1245
+ if ($stbData.pageNumber > 0) {
1246
+ stbData.update({ limit: $cachedRows.length });
1247
+ } else {
1248
+ stbData.refresh();
1249
+ }
1250
+
1251
+ return "Refreshing";
1252
+ },
1290
1253
  fetchMoreRows(size) {
1291
- _limit = _limit + size;
1292
- stbData.update({ limit: _limit });
1254
+ if ($stbData.hasNextPage && !$stbData.loading) {
1255
+ stbData.nextPage();
1256
+ return "Fetching";
1257
+ }
1258
+ },
1259
+ },
1260
+ Refreshing: {
1261
+ _enter() {},
1262
+ _exit() {},
1263
+ synch(fetchState) {
1264
+ if (fetchState.loading) return;
1265
+ if (fetchState.loaded) {
1266
+ $cachedRows = [...fetchState.rows];
1267
+ return "Idle";
1268
+ }
1269
+ },
1270
+ },
1271
+ Fetching: {
1272
+ _enter() {},
1273
+ _exit() {},
1274
+ synch(fetchState) {
1275
+ if (!fetchState.loading) {
1276
+ isEmpty = fetchState.rows.length < 1;
1277
+ $cachedRows = [...$cachedRows, ...fetchState.rows];
1278
+ return "Idle";
1279
+ }
1293
1280
  },
1294
1281
  },
1295
1282
  Filtered: {
@@ -1308,24 +1295,51 @@
1308
1295
  clearFilter(id) {
1309
1296
  stbColumnFilters.delete(id);
1310
1297
  tableAPI.removeQueryExtension(id);
1311
- return "Idle";
1312
1298
  },
1313
1299
  clear() {
1314
- stbColumnFilters.forEach((id) => {
1315
- tableAPI.removeQueryExtension(id);
1316
- });
1317
- stbColumnFilters.clear();
1318
- columnStates.forEach(({ state }) => state.reset());
1319
- return "Idle";
1300
+ try {
1301
+ stbColumnFilters.forEach((id) => {
1302
+ tableAPI.removeQueryExtension(id);
1303
+ });
1304
+ stbColumnFilters.clear();
1305
+ columnStates.forEach(({ state }) => state.reset());
1306
+ } catch (e) {
1307
+ console.error("Error clearing filters:", e);
1308
+ } finally {
1309
+ return "Idle";
1310
+ }
1311
+ },
1312
+ refresh() {
1313
+ if ($stbData?.loading) return;
1314
+ stbData.refresh();
1320
1315
  },
1321
1316
  synch(fetchState) {
1317
+ if (fetchState.loading) return;
1322
1318
  if (fetchState.loaded) {
1323
1319
  isEmpty = fetchState.rows.length < 1;
1320
+ $cachedRows = [...fetchState.rows];
1324
1321
  this.calculateRowBoundaries();
1325
1322
  }
1326
1323
  },
1324
+ fetchMoreRows(size) {
1325
+ if ($stbData.hasNextPage && !$stbData.loading) {
1326
+ stbData.nextPage();
1327
+ return "Fetching";
1328
+ }
1329
+ },
1327
1330
  },
1328
1331
  Editing: {
1332
+ enter() {
1333
+ if (timer) clearInterval(timer);
1334
+ },
1335
+ _exit() {
1336
+ if (autoRefreshRate && !inBuilder) {
1337
+ timer = setInterval(() => {
1338
+ stbState.refresh();
1339
+ onRefresh?.();
1340
+ }, autoRefreshRate * 1000);
1341
+ }
1342
+ },
1329
1343
  async patchRow(index, id, rev, field, change) {
1330
1344
  let patch = { _id: id, _rev: rev, [field]: change };
1331
1345
  await tableAPI.patchRow(index, patch);
@@ -1377,80 +1391,27 @@
1377
1391
  },
1378
1392
  });
1379
1393
 
1380
- // Initialize and Enrich Rows
1381
- $: stbState.init($dataSourceStore);
1382
- $: stbState.synch($stbData);
1383
- $: stbState.enrichRows(
1384
- $stbData,
1385
- rowBGColorTemplate,
1386
- rowColorTemplate,
1387
- rowHeight,
1388
- rowDisabledTemplate,
1389
- $stbSelected
1390
- );
1391
-
1392
- $: stbSelectedRows = derivedMemo(
1393
- [stbData, stbSelected, maxSelectedStore],
1394
- ([$stbData, $stbSelected, $maxSelectedStore]) => {
1395
- if ($stbData?.rows) {
1396
- $stbSelected = $stbSelected.filter((id) =>
1397
- $stbData.rows.some((row, i) => tableAPI.getRowId(row, i) === id)
1398
- );
1399
- }
1400
- const selectedRows = $stbData?.rows?.filter((row, i) =>
1401
- $stbSelected?.includes(tableAPI.getRowId(row, i))
1402
- );
1403
- if ($maxSelectedStore === 1) {
1404
- return selectedRows.length > 0 ? selectedRows[0] : [];
1405
- }
1406
- return selectedRows;
1407
- }
1408
- );
1409
-
1410
- // Scroll to Top when filter changes
1411
- $: stbState.scrollToTop(query);
1412
-
1413
- // Data Related
1414
- $: defaultQuery = QueryUtils.buildQuery($filterStore);
1415
- $: query = tableAPI.extendQuery(defaultQuery, queryExtensions);
1416
- $: stbData?.update({
1417
- query,
1418
- sortColumn,
1419
- sortOrder,
1420
- });
1421
-
1422
1394
  // Derived Store with the columns to be rendered
1423
- $: superColumns = derivedMemo(
1395
+ const superColumns = derivedMemo(
1424
1396
  [stbSchema, columnsStore, stbSettings],
1425
1397
  ([$stbSchema, $columnsStore, $stbSettings]) => {
1426
1398
  return tableAPI.populateColumns(
1427
1399
  $stbSchema,
1428
1400
  $columnsStore,
1429
1401
  $stbSettings.showAutoColumns,
1430
- $stbSettings.showSpecialColumns
1402
+ $stbSettings.showSpecialColumns,
1431
1403
  );
1432
- }
1404
+ },
1433
1405
  );
1434
1406
 
1435
- $: cumulativeHeights = derivedMemo(stbRowMetadata, ($meta) => {
1407
+ const cumulativeHeights = derivedMemo(stbRowMetadata, ($meta) => {
1436
1408
  return $meta?.map((_, i) =>
1437
1409
  $meta
1438
1410
  .slice(0, i + 1)
1439
- .reduce((sum, meta) => sum + Math.max(meta.height, 0), 0)
1411
+ .reduce((sum, meta) => sum + Math.max(meta.height, 0), 0),
1440
1412
  );
1441
1413
  });
1442
1414
 
1443
- // Virtual List Capabilities reacting to viewport change
1444
- $: stbState.calculateBoundaries(
1445
- clientHeight,
1446
- canInsert,
1447
- $stbSortColumn,
1448
- fetchOnScroll,
1449
- $stbSortColumn,
1450
- $stbSortOrder,
1451
- $cumulativeHeights
1452
- );
1453
-
1454
1415
  // Derived Store with common column settings
1455
1416
  const commonColumnOptions = derivedMemo(stbSettings, ($stbSettings) => {
1456
1417
  return {
@@ -1490,6 +1451,61 @@
1490
1451
  footerHeight: $stbSettings.appearance?.footerHeight || "0px",
1491
1452
  }));
1492
1453
 
1454
+ // Initialize and Enrich Rows
1455
+ $: stbState.init($dataSourceStore);
1456
+ $: stbState.synch($stbData);
1457
+ $: stbState.enrichRows(
1458
+ $cachedRows,
1459
+ rowBGColorTemplate,
1460
+ rowColorTemplate,
1461
+ rowHeight,
1462
+ rowDisabledTemplate,
1463
+ $stbSelected,
1464
+ size,
1465
+ );
1466
+
1467
+ $: stbSelectedRows = derivedMemo(
1468
+ [cachedRows, stbSelected, maxSelectedStore],
1469
+ ([$cachedRows, $stbSelected, $maxSelectedStore]) => {
1470
+ if ($cachedRows.length) {
1471
+ $stbSelected = $stbSelected.filter((id) =>
1472
+ $cachedRows.some((row, i) => tableAPI.getRowId(row, i) === id),
1473
+ );
1474
+ }
1475
+ const selectedRows = $cachedRows?.filter((row, i) =>
1476
+ $stbSelected?.includes(tableAPI.getRowId(row, i)),
1477
+ );
1478
+ if ($maxSelectedStore === 1) {
1479
+ return selectedRows.length > 0 ? selectedRows[0] : [];
1480
+ }
1481
+ return selectedRows;
1482
+ },
1483
+ );
1484
+
1485
+ // Scroll to Top when filter changes
1486
+ $: stbState.scrollToTop(query);
1487
+
1488
+ // Data Related
1489
+ $: defaultQuery = QueryUtils.buildQuery($filterStore);
1490
+ $: query = tableAPI.extendQuery(defaultQuery, queryExtensions);
1491
+ $: stbData?.update({
1492
+ query,
1493
+ sortColumn,
1494
+ sortOrder,
1495
+ limit,
1496
+ });
1497
+
1498
+ // Virtual List Capabilities reacting to viewport change
1499
+ $: stbState.calculateBoundaries(
1500
+ clientHeight,
1501
+ canInsert,
1502
+ $stbSortColumn,
1503
+ fetchOnScroll,
1504
+ $stbSortColumn,
1505
+ $stbSortOrder,
1506
+ $cumulativeHeights,
1507
+ );
1508
+
1493
1509
  // Build our data and actions ontext
1494
1510
  $: actions = [
1495
1511
  {
@@ -1498,7 +1514,7 @@
1498
1514
  },
1499
1515
  {
1500
1516
  type: ActionTypes.RefreshDatasource,
1501
- callback: stbData?.refresh,
1517
+ callback: stbState.refresh,
1502
1518
  },
1503
1519
  {
1504
1520
  type: ActionTypes.AddDataProviderQueryExtension,
@@ -1512,9 +1528,9 @@
1512
1528
 
1513
1529
  // The "row" is dynamically enriched, but show the first one in the builder for preview
1514
1530
  $: dataContext = {
1515
- row: inBuilder ? $stbData?.rows[0] : {},
1531
+ row: inBuilder ? $cachedRows?.[0] : {},
1516
1532
  newRow: $new_row,
1517
- rows: $stbData?.rows,
1533
+ rows: $cachedRows,
1518
1534
  selectedRows: $stbSelectedRows,
1519
1535
  selectedIds: Array.isArray($stbSelectedRows)
1520
1536
  ? $stbSelectedRows.map((row) => row[idColumn])
@@ -1529,7 +1545,7 @@
1529
1545
  query: $stbData.query,
1530
1546
  },
1531
1547
  loaded: $stbData?.loaded,
1532
- rowsLength: $stbData?.rows.length,
1548
+ rowsLength: $cachedRows.length,
1533
1549
  pageNumber: $stbData?.pageNumber + 1,
1534
1550
  };
1535
1551
 
@@ -1554,11 +1570,9 @@
1554
1570
  setContext("stbVisibleRows", stbVisibleRows);
1555
1571
  setContext("stbRowMetadata", stbRowMetadata);
1556
1572
 
1557
- // Reactive Context
1558
-
1559
- $: setContext("stbData", stbData);
1560
- $: setContext("stbSchema", stbSchema);
1561
- $: setContext("new_row", new_row);
1573
+ setContext("data", cachedRows);
1574
+ setContext("stbSchema", stbSchema);
1575
+ setContext("new_row", new_row);
1562
1576
 
1563
1577
  function toNumber(input) {
1564
1578
  const num = Number(input);
@@ -1616,7 +1630,9 @@
1616
1630
  <Provider {actions} data={dataContext} />
1617
1631
 
1618
1632
  <ControlSection>
1619
- <SelectionColumn {stbData} {hideSelectionColumn} />
1633
+ <SelectionColumn
1634
+ hideSelectionColumn={hideSelectionColumn || $superColumns.length === 0}
1635
+ />
1620
1636
 
1621
1637
  {#if showButtonColumnLeft}
1622
1638
  <RowButtonsColumn {rowMenuItems} {menuItemsVisible} {rowMenu} />
@@ -1624,7 +1640,6 @@
1624
1640
 
1625
1641
  {#if stickFirstColumn && $superColumns.length > 1}
1626
1642
  <SuperTableColumn
1627
- {stbData}
1628
1643
  sticky={true}
1629
1644
  scrollPos={$stbHorizontalScrollPos}
1630
1645
  columnOptions={{
@@ -1640,7 +1655,6 @@
1640
1655
  </ControlSection>
1641
1656
 
1642
1657
  <ColumnsSection
1643
- {stbData}
1644
1658
  {stbSettings}
1645
1659
  {superColumns}
1646
1660
  {commonColumnOptions}
@@ -1652,7 +1666,7 @@
1652
1666
  {/key}
1653
1667
  </ColumnsSection>
1654
1668
 
1655
- {#if showButtonColumnRight && !isEmpty}
1669
+ {#if showButtonColumnRight && $superColumns.length > 0}
1656
1670
  <ControlSection>
1657
1671
  <RowButtonsColumn
1658
1672
  {rowMenuItems}