@smartnet360/svelte-components 0.0.127 → 0.0.129
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.
- package/dist/map-v3/features/cells/custom/logic/csv-parser.d.ts +3 -2
- package/dist/map-v3/features/cells/custom/logic/csv-parser.js +23 -12
- package/dist/map-v3/features/cells/custom/stores/custom-cell-sets.svelte.d.ts +16 -5
- package/dist/map-v3/features/cells/custom/stores/custom-cell-sets.svelte.js +26 -13
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Custom Cells - CSV Parser
|
|
3
3
|
*
|
|
4
4
|
* Parses CSV files for custom cell sets.
|
|
5
|
-
* Required column: txId
|
|
5
|
+
* Required column: cellName (or txId for backwards compatibility)
|
|
6
6
|
* Optional columns: customGroup, sizeFactor, + any extras for tooltips
|
|
7
7
|
*/
|
|
8
8
|
import type { CustomCellImportResult } from '../types';
|
|
@@ -10,11 +10,12 @@ import type { Cell } from '../../../../../shared/demo';
|
|
|
10
10
|
/**
|
|
11
11
|
* Parse a CSV string into custom cells
|
|
12
12
|
* @param csvContent Raw CSV content
|
|
13
|
-
* @param cellLookup Map of
|
|
13
|
+
* @param cellLookup Map of cellName -> Cell for resolving cell data
|
|
14
14
|
* @returns Import result with cells, unmatched IDs, groups, and extra columns
|
|
15
15
|
*/
|
|
16
16
|
export declare function parseCustomCellsCsv(csvContent: string, cellLookup: Map<string, Cell>): CustomCellImportResult;
|
|
17
17
|
/**
|
|
18
18
|
* Build a cell lookup map from an array of cells
|
|
19
|
+
* Creates lookups for both cellName and txId for flexible matching
|
|
19
20
|
*/
|
|
20
21
|
export declare function buildCellLookup(cells: Cell[]): Map<string, Cell>;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Custom Cells - CSV Parser
|
|
3
3
|
*
|
|
4
4
|
* Parses CSV files for custom cell sets.
|
|
5
|
-
* Required column: txId
|
|
5
|
+
* Required column: cellName (or txId for backwards compatibility)
|
|
6
6
|
* Optional columns: customGroup, sizeFactor, + any extras for tooltips
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Known/reserved column names
|
|
10
10
|
*/
|
|
11
|
-
const RESERVED_COLUMNS = ['
|
|
11
|
+
const RESERVED_COLUMNS = ['cellname', 'txid', 'customgroup', 'sizefactor'];
|
|
12
12
|
/**
|
|
13
13
|
* Normalize column name for matching
|
|
14
14
|
*/
|
|
@@ -18,7 +18,7 @@ function normalizeColumnName(name) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Parse a CSV string into custom cells
|
|
20
20
|
* @param csvContent Raw CSV content
|
|
21
|
-
* @param cellLookup Map of
|
|
21
|
+
* @param cellLookup Map of cellName -> Cell for resolving cell data
|
|
22
22
|
* @returns Import result with cells, unmatched IDs, groups, and extra columns
|
|
23
23
|
*/
|
|
24
24
|
export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
@@ -36,10 +36,15 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
36
36
|
const headerLine = lines[0];
|
|
37
37
|
const headers = parseCSVLine(headerLine);
|
|
38
38
|
const normalizedHeaders = headers.map(normalizeColumnName);
|
|
39
|
-
// Find
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
// Find cell identifier column - prefer cellName, fallback to txId
|
|
40
|
+
let idIndex = normalizedHeaders.findIndex(h => h === 'cellname');
|
|
41
|
+
let usesCellName = true;
|
|
42
|
+
if (idIndex === -1) {
|
|
43
|
+
idIndex = normalizedHeaders.findIndex(h => h === 'txid');
|
|
44
|
+
usesCellName = false;
|
|
45
|
+
}
|
|
46
|
+
if (idIndex === -1) {
|
|
47
|
+
throw new Error('CSV must contain a "cellName" or "txId" column');
|
|
43
48
|
}
|
|
44
49
|
// Find optional columns
|
|
45
50
|
const groupIndex = normalizedHeaders.findIndex(h => h === 'customgroup');
|
|
@@ -63,8 +68,8 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
63
68
|
if (!line)
|
|
64
69
|
continue;
|
|
65
70
|
const values = parseCSVLine(line);
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
71
|
+
const cellIdentifier = values[idIndex]?.trim();
|
|
72
|
+
if (!cellIdentifier)
|
|
68
73
|
continue;
|
|
69
74
|
// Get custom group (default to 'default')
|
|
70
75
|
const customGroup = groupIndex !== -1
|
|
@@ -88,10 +93,10 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
88
93
|
extraFields[extraColumns[i]] = isNaN(numValue) ? value : numValue;
|
|
89
94
|
});
|
|
90
95
|
// Resolve cell from lookup
|
|
91
|
-
const resolvedCell = cellLookup.get(
|
|
96
|
+
const resolvedCell = cellLookup.get(cellIdentifier);
|
|
92
97
|
if (resolvedCell) {
|
|
93
98
|
cells.push({
|
|
94
|
-
txId,
|
|
99
|
+
txId: resolvedCell.txId, // Always store the txId from resolved cell
|
|
95
100
|
customGroup,
|
|
96
101
|
sizeFactor,
|
|
97
102
|
extraFields,
|
|
@@ -99,7 +104,7 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
99
104
|
});
|
|
100
105
|
}
|
|
101
106
|
else {
|
|
102
|
-
unmatchedTxIds.push(
|
|
107
|
+
unmatchedTxIds.push(cellIdentifier);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
return {
|
|
@@ -152,10 +157,16 @@ function parseCSVLine(line) {
|
|
|
152
157
|
}
|
|
153
158
|
/**
|
|
154
159
|
* Build a cell lookup map from an array of cells
|
|
160
|
+
* Creates lookups for both cellName and txId for flexible matching
|
|
155
161
|
*/
|
|
156
162
|
export function buildCellLookup(cells) {
|
|
157
163
|
const lookup = new Map();
|
|
158
164
|
for (const cell of cells) {
|
|
165
|
+
// Primary: lookup by cellName
|
|
166
|
+
if (cell.cellName) {
|
|
167
|
+
lookup.set(cell.cellName, cell);
|
|
168
|
+
}
|
|
169
|
+
// Fallback: also allow lookup by txId for backwards compatibility
|
|
159
170
|
if (cell.txId) {
|
|
160
171
|
lookup.set(cell.txId, cell);
|
|
161
172
|
}
|
|
@@ -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
|
|
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
|
-
/**
|
|
18
|
-
private
|
|
20
|
+
/** Function to get current cells */
|
|
21
|
+
private getCells;
|
|
19
22
|
/** Storage key for persistence */
|
|
20
23
|
private storageKey;
|
|
21
|
-
|
|
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(
|
|
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
|
|
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
|
-
/**
|
|
25
|
-
|
|
24
|
+
/** Function to get current cells */
|
|
25
|
+
getCells;
|
|
26
26
|
/** Storage key for persistence */
|
|
27
27
|
storageKey;
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
45
|
+
// Re-resolve cells when cell data changes (only works if getter is reactive)
|
|
40
46
|
$effect(() => {
|
|
41
|
-
const
|
|
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
|
|
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
|
|
58
|
-
const cellLookup = buildCellLookup(this.
|
|
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.
|
|
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(
|
|
241
|
-
|
|
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
|
}
|