@smartnet360/svelte-components 0.0.128 → 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.
|
@@ -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
|
}
|