@smartnet360/svelte-components 0.0.127 → 0.0.128

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.
@@ -2,10 +2,13 @@
2
2
  * Custom Cell Sets Store
3
3
  *
4
4
  * Manages multiple custom cell sets, each loaded from a CSV file.
5
- * Resolves cell data from the parent CellDataStore.
5
+ * Resolves cell data from a provided cell array.
6
6
  */
7
+ import type { Cell } from '../../types';
7
8
  import type { CellDataStore } from '../../stores/cell.data.svelte';
8
9
  import type { CustomCellSet, CustomCellImportResult } from '../types';
10
+ /** Function that returns the current cells array */
11
+ type CellsGetter = () => Cell[];
9
12
  /**
10
13
  * Store for managing custom cell sets
11
14
  */
@@ -14,11 +17,16 @@ export declare class CustomCellSetsStore {
14
17
  sets: CustomCellSet[];
15
18
  /** Version counter for reactivity */
16
19
  version: number;
17
- /** Reference to parent cell data store */
18
- private cellDataStore;
20
+ /** Function to get current cells */
21
+ private getCells;
19
22
  /** Storage key for persistence */
20
23
  private storageKey;
21
- constructor(cellDataStore: CellDataStore, namespace?: string);
24
+ /**
25
+ * Create a new CustomCellSetsStore
26
+ * @param cells - Either a Cell array or a getter function that returns cells
27
+ * @param namespace - Storage namespace for persistence
28
+ */
29
+ constructor(cells: Cell[] | CellsGetter, namespace?: string);
22
30
  /**
23
31
  * Import a CSV file and create a new custom cell set
24
32
  */
@@ -74,5 +82,8 @@ export declare class CustomCellSetsStore {
74
82
  }
75
83
  /**
76
84
  * Factory function to create a custom cell sets store
85
+ * @param cells - Cell array, getter function, or CellDataStore
86
+ * @param namespace - Storage namespace for persistence
77
87
  */
78
- export declare function createCustomCellSetsStore(cellDataStore: CellDataStore, namespace?: string): CustomCellSetsStore;
88
+ export declare function createCustomCellSetsStore(cells: Cell[] | CellsGetter | CellDataStore, namespace?: string): CustomCellSetsStore;
89
+ export {};
@@ -2,7 +2,7 @@
2
2
  * Custom Cell Sets Store
3
3
  *
4
4
  * Manages multiple custom cell sets, each loaded from a CSV file.
5
- * Resolves cell data from the parent CellDataStore.
5
+ * Resolves cell data from a provided cell array.
6
6
  */
7
7
  import { browser } from '$app/environment';
8
8
  import { CUSTOM_CELL_PALETTE } from '../types';
@@ -21,12 +21,18 @@ export class CustomCellSetsStore {
21
21
  sets = $state([]);
22
22
  /** Version counter for reactivity */
23
23
  version = $state(0);
24
- /** Reference to parent cell data store */
25
- cellDataStore;
24
+ /** Function to get current cells */
25
+ getCells;
26
26
  /** Storage key for persistence */
27
27
  storageKey;
28
- constructor(cellDataStore, namespace = 'default') {
29
- this.cellDataStore = cellDataStore;
28
+ /**
29
+ * Create a new CustomCellSetsStore
30
+ * @param cells - Either a Cell array or a getter function that returns cells
31
+ * @param namespace - Storage namespace for persistence
32
+ */
33
+ constructor(cells, namespace = 'default') {
34
+ // Normalize to a getter function
35
+ this.getCells = typeof cells === 'function' ? cells : () => cells;
30
36
  this.storageKey = `${namespace}:custom-cell-sets`;
31
37
  if (browser) {
32
38
  this.load();
@@ -36,14 +42,15 @@ export class CustomCellSetsStore {
36
42
  const _v = this.version;
37
43
  this.save();
38
44
  });
39
- // Re-resolve cells when main cell data changes
45
+ // Re-resolve cells when cell data changes (only works if getter is reactive)
40
46
  $effect(() => {
41
- const cellCount = this.cellDataStore.rawCells.length;
47
+ const currentCells = this.getCells();
48
+ const cellCount = currentCells.length;
42
49
  if (cellCount > 0 && this.sets.length > 0) {
43
50
  // Check if any cells need resolution
44
51
  const needsResolution = this.sets.some(set => set.cells.some(c => !c.resolvedCell));
45
52
  if (needsResolution) {
46
- console.log('[CustomCellSetsStore] Re-resolving cells after main data loaded');
53
+ console.log('[CustomCellSetsStore] Re-resolving cells after data loaded');
47
54
  this.refreshResolutions();
48
55
  }
49
56
  }
@@ -54,8 +61,8 @@ export class CustomCellSetsStore {
54
61
  * Import a CSV file and create a new custom cell set
55
62
  */
56
63
  importFromCsv(csvContent, fileName) {
57
- // Build lookup from all cells (unfiltered)
58
- const cellLookup = buildCellLookup(this.cellDataStore.rawCells);
64
+ // Build lookup from all cells
65
+ const cellLookup = buildCellLookup(this.getCells());
59
66
  // Parse CSV
60
67
  const result = parseCustomCellsCsv(csvContent, cellLookup);
61
68
  return result;
@@ -180,7 +187,7 @@ export class CustomCellSetsStore {
180
187
  * Re-resolve cells after main cell data changes
181
188
  */
182
189
  refreshResolutions() {
183
- const cellLookup = buildCellLookup(this.cellDataStore.rawCells);
190
+ const cellLookup = buildCellLookup(this.getCells());
184
191
  for (const set of this.sets) {
185
192
  for (const cell of set.cells) {
186
193
  cell.resolvedCell = cellLookup.get(cell.txId);
@@ -236,7 +243,13 @@ export class CustomCellSetsStore {
236
243
  }
237
244
  /**
238
245
  * Factory function to create a custom cell sets store
246
+ * @param cells - Cell array, getter function, or CellDataStore
247
+ * @param namespace - Storage namespace for persistence
239
248
  */
240
- export function createCustomCellSetsStore(cellDataStore, namespace = 'default') {
241
- return new CustomCellSetsStore(cellDataStore, namespace);
249
+ export function createCustomCellSetsStore(cells, namespace = 'default') {
250
+ // Handle CellDataStore by extracting a getter
251
+ if (cells && typeof cells === 'object' && 'rawCells' in cells) {
252
+ return new CustomCellSetsStore(() => cells.rawCells, namespace);
253
+ }
254
+ return new CustomCellSetsStore(cells, namespace);
242
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartnet360/svelte-components",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",