@poirazis/supercomponents-shared 1.0.9 → 1.0.18

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.
@@ -3,6 +3,7 @@
3
3
  import fsm from "svelte-fsm";
4
4
  import { writable } from "svelte/store";
5
5
 
6
+ import "./SuperTable.css";
6
7
  import {
7
8
  sizingMap,
8
9
  defaultOperatorMap,
@@ -290,11 +291,14 @@
290
291
  $: cumulativeHeights = derivedMemo(
291
292
  [stbRowMetadata, stbSettings],
292
293
  ([$meta, $settings]) => {
293
- const defaultRowHeight = $settings.appearance?.rowHeight || 36; // Fallback if undefined
294
+ const defaultRowHeight = $settings.appearance?.rowHeight || 36;
294
295
  return $meta.map((_, i) =>
295
296
  $meta
296
297
  .slice(0, i + 1)
297
- .reduce((sum, meta) => sum + (meta.height || defaultRowHeight), 0)
298
+ .reduce(
299
+ (sum, meta) => sum + Math.max(meta.height || defaultRowHeight, 0),
300
+ 0
301
+ )
298
302
  );
299
303
  }
300
304
  );
@@ -703,11 +707,10 @@
703
707
  if (!rows?.length || !viewport || !$cumulativeHeights.length) return;
704
708
 
705
709
  const defaultRowHeight = $stbSettings.appearance.rowHeight;
706
- let start = $stbVisibleRows?.length ? $stbVisibleRows[0] - 1 : 0;
707
- start = Math.max(0, start); // Ensure start doesn't go negative
708
- let end = 0;
710
+ let start = 0,
711
+ end = rows.length;
709
712
 
710
- // Find start index using cumulativeHeights
713
+ // Find start index
711
714
  for (let i = 0; i < rows.length; i++) {
712
715
  if ($cumulativeHeights[i] > $stbScrollPos) {
713
716
  start = i;
@@ -715,45 +718,30 @@
715
718
  }
716
719
  }
717
720
 
718
- // Find end index using cumulativeHeights
721
+ // Find end index
719
722
  for (let i = start; i < rows.length; i++) {
720
- if (
721
- $cumulativeHeights[i] >=
722
- $stbScrollPos + maxBodyHeight - defaultRowHeight
723
- ) {
723
+ if ($cumulativeHeights[i] >= $stbScrollPos + maxBodyHeight) {
724
724
  end = i + 1;
725
725
  break;
726
726
  }
727
727
  }
728
728
 
729
- // Ensure all rows are included when at the bottom
730
- end = end || rows.length;
731
-
732
729
  // Update visible rows
733
730
  $stbVisibleRows = $stbData?.rows
734
- ?.slice(start, end)
731
+ .slice(start, end)
735
732
  .map((_, i) => i + start);
736
733
 
737
- // Calculate scroll offset for rendering
734
+ // Calculate scroll offset
738
735
  const startHeight = start > 0 ? $cumulativeHeights[start - 1] : 0;
739
736
  $stbScrollOffset = $stbScrollPos - startHeight;
740
737
 
741
- // Ensure offset doesn't exceed bounds at the end
742
- if ($stbScrollPos >= scrollHeight - maxBodyHeight) {
743
- $stbScrollPos = Math.max(0, scrollHeight - maxBodyHeight);
744
- $stbScrollOffset = Math.min(
745
- $stbScrollOffset,
746
- maxBodyHeight - defaultRowHeight
747
- );
748
- }
749
-
750
- // Fetch more rows if nearing the end of loaded data
738
+ // Fetch more rows if nearing the end
751
739
  if (fetchOnScroll && rows.length > 0) {
752
740
  const loadedHeight = $cumulativeHeights[rows.length - 1];
753
741
  const remainingHeight =
754
742
  loadedHeight - ($stbScrollPos + maxBodyHeight);
755
- if (remainingHeight < maxBodyHeight && rows.length == _limit) {
756
- stbState.fetchMoreRows.debounce(200, 100); // Debounced fetch call
743
+ if (remainingHeight < maxBodyHeight && rows.length === _limit) {
744
+ stbState.fetchMoreRows.debounce(200, 100); // Debounced fetch
757
745
  }
758
746
  }
759
747
  },
@@ -769,11 +757,7 @@
769
757
  scrollHeight > maxBodyHeight
770
758
  ? $stbScrollPos / (scrollHeight - maxBodyHeight)
771
759
  : 0;
772
- $stbScrollOffset = Math.floor(
773
- $stbScrollPos % $stbSettings.appearance.rowHeight
774
- );
775
-
776
- this.calculateRowBoundaries.debounce(1);
760
+ window.requestAnimationFrame(() => this.calculateRowBoundaries());
777
761
  },
778
762
  handleWheel(e) {
779
763
  if ($stbState == "Inserting") {
@@ -1194,8 +1178,6 @@
1194
1178
  $: console.log("Table Filters : ", stbColumnFilters);
1195
1179
  $: console.log("Table Settings : ", $stbSettings);
1196
1180
  */
1197
-
1198
- $: console.log($stbSchema);
1199
1181
  </script>
1200
1182
 
1201
1183
  <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -205,6 +205,8 @@
205
205
  color: var(--spectrum-global-color-gray-800);
206
206
  border: 1px solid var(--spectrum-global-color-gray-300);
207
207
  background: var(--spectrum-global-color-gray-50);
208
+ min-height: 2rem;
209
+ max-height: 2rem;
208
210
 
209
211
  &:focus-within {
210
212
  border: 1px solid var(--spectrum-global-color-blue-400) !important;
@@ -180,7 +180,6 @@
180
180
  class:readonly
181
181
  on:click={!readonly
182
182
  ? () => {
183
- console.log(open);
184
183
  open = !open;
185
184
  }
186
185
  : null}
@@ -1,5 +1,10 @@
1
1
  <script>
2
- import { createEventDispatcher, getContext, onMount } from "svelte";
2
+ import {
3
+ createEventDispatcher,
4
+ getContext,
5
+ onMount,
6
+ onDestroy,
7
+ } from "svelte";
3
8
  import fsm from "svelte-fsm";
4
9
  const dispatch = createEventDispatcher();
5
10
  const { processStringSync } = getContext("sdk");
@@ -28,6 +33,7 @@
28
33
  reset() {
29
34
  localValue = value;
30
35
  lastEdit = undefined;
36
+ return "View";
31
37
  },
32
38
  },
33
39
  View: {
@@ -109,6 +115,11 @@
109
115
  cellState.focus();
110
116
  }, 50);
111
117
  });
118
+
119
+ onDestroy(() => {
120
+ clearTimeout(timer);
121
+ cellState.reset();
122
+ });
112
123
  </script>
113
124
 
114
125
  <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
@@ -11,11 +11,11 @@
11
11
  };
12
12
 
13
13
  $: formattedValue =
14
- !formattedValue && cellOptions?.template
14
+ cellOptions?.template
15
15
  ? processStringSync(cellOptions.template, {
16
16
  value,
17
17
  })
18
- : formattedValue;
18
+ : undefined;;
19
19
 
20
20
  $: placeholder =
21
21
  cellOptions.readonly || cellOptions.disabled
@@ -34,7 +34,7 @@
34
34
  class:is-editing={editing}
35
35
  >
36
36
  {#if rows?.length}
37
- {#each $stbVisibleRows as index}
37
+ {#each $stbVisibleRows as index (index)}
38
38
  {#if rows[index]}
39
39
  <SuperColumnRow
40
40
  {isLast}
@@ -1,7 +1,13 @@
1
1
  <script>
2
- import { getContext, createEventDispatcher, onMount, tick } from "svelte";
2
+ import {
3
+ getContext,
4
+ createEventDispatcher,
5
+ onMount,
6
+ tick,
7
+ onDestroy,
8
+ } from "svelte";
3
9
 
4
- const { Provider, processStringSync, ContextScopes } = getContext("sdk");
10
+ const { Provider, ContextScopes } = getContext("sdk");
5
11
 
6
12
  const dispatch = createEventDispatcher();
7
13
  const columnSettings = getContext("stColumnOptions");
@@ -10,6 +16,7 @@
10
16
  const rowMetadata = getContext("stbRowMetadata");
11
17
  const stbHovered = getContext("stbHovered");
12
18
  const stbSelected = getContext("stbSelected");
19
+ const stbEditing = getContext("stbEditing");
13
20
  const stbAPI = getContext("stbAPI");
14
21
  const stbState = getContext("stbState");
15
22
  const stbMenuID = getContext("stbMenuID");
@@ -34,12 +41,6 @@
34
41
  $: isSelected = $stbSelected.includes(id);
35
42
  $: hasChildren = $columnSettings.hasChildren > 0;
36
43
 
37
- const getCellValue = (value) => {
38
- return $columnSettings.template
39
- ? processStringSync($columnSettings.template, { value })
40
- : undefined;
41
- };
42
-
43
44
  const patchRow = async (change) => {
44
45
  let patch = {
45
46
  ...row,
@@ -88,6 +89,12 @@
88
89
  } else return obj[path] ?? undefined;
89
90
  };
90
91
  onMount(() => (mounted = $columnSettings.superColumn));
92
+
93
+ onDestroy(() => {
94
+ if ($stbEditing == index) {
95
+ columnState.exitedit();
96
+ }
97
+ });
91
98
  </script>
92
99
 
93
100
  <!-- svelte-ignore a11y-click-events-have-key-events -->