@smartnet360/svelte-components 0.0.128 → 0.0.130

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,19 +2,26 @@
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
+ * Supports both comma (,) and semicolon (;) delimiters
7
8
  */
8
9
  import type { CustomCellImportResult } from '../types';
9
10
  import type { Cell } from '../../../../../shared/demo';
11
+ /**
12
+ * Supported delimiters
13
+ */
14
+ export type CsvDelimiter = ',' | ';' | 'auto';
10
15
  /**
11
16
  * Parse a CSV string into custom cells
12
17
  * @param csvContent Raw CSV content
13
- * @param cellLookup Map of txId -> Cell for resolving cell data
18
+ * @param cellLookup Map of cellName -> Cell for resolving cell data
19
+ * @param delimiter Delimiter to use: ',' (comma), ';' (semicolon), or 'auto' (detect)
14
20
  * @returns Import result with cells, unmatched IDs, groups, and extra columns
15
21
  */
16
- export declare function parseCustomCellsCsv(csvContent: string, cellLookup: Map<string, Cell>): CustomCellImportResult;
22
+ export declare function parseCustomCellsCsv(csvContent: string, cellLookup: Map<string, Cell>, delimiter?: CsvDelimiter): CustomCellImportResult;
17
23
  /**
18
24
  * Build a cell lookup map from an array of cells
25
+ * Creates lookups for both cellName and txId for flexible matching
19
26
  */
20
27
  export declare function buildCellLookup(cells: Cell[]): Map<string, Cell>;
@@ -2,26 +2,37 @@
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
+ * Supports both comma (,) and semicolon (;) delimiters
7
8
  */
8
9
  /**
9
10
  * Known/reserved column names
10
11
  */
11
- const RESERVED_COLUMNS = ['txId', 'txid', 'customGroup', 'customgroup', 'sizeFactor', 'sizefactor'];
12
+ const RESERVED_COLUMNS = ['cellname', 'txid', 'customgroup', 'sizefactor'];
12
13
  /**
13
14
  * Normalize column name for matching
14
15
  */
15
16
  function normalizeColumnName(name) {
16
17
  return name.trim().toLowerCase();
17
18
  }
19
+ /**
20
+ * Detect the delimiter used in CSV content
21
+ * Counts occurrences in the header line and picks the most common
22
+ */
23
+ function detectDelimiter(headerLine) {
24
+ const commaCount = (headerLine.match(/,/g) || []).length;
25
+ const semicolonCount = (headerLine.match(/;/g) || []).length;
26
+ return semicolonCount > commaCount ? ';' : ',';
27
+ }
18
28
  /**
19
29
  * Parse a CSV string into custom cells
20
30
  * @param csvContent Raw CSV content
21
- * @param cellLookup Map of txId -> Cell for resolving cell data
31
+ * @param cellLookup Map of cellName -> Cell for resolving cell data
32
+ * @param delimiter Delimiter to use: ',' (comma), ';' (semicolon), or 'auto' (detect)
22
33
  * @returns Import result with cells, unmatched IDs, groups, and extra columns
23
34
  */
24
- export function parseCustomCellsCsv(csvContent, cellLookup) {
35
+ export function parseCustomCellsCsv(csvContent, cellLookup, delimiter = 'auto') {
25
36
  const lines = csvContent.trim().split('\n');
26
37
  if (lines.length < 2) {
27
38
  return {
@@ -32,14 +43,21 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
32
43
  totalRows: 0
33
44
  };
34
45
  }
35
- // Parse header
46
+ // Detect or use specified delimiter
36
47
  const headerLine = lines[0];
37
- const headers = parseCSVLine(headerLine);
48
+ const actualDelimiter = delimiter === 'auto' ? detectDelimiter(headerLine) : delimiter;
49
+ // Parse header
50
+ const headers = parseCSVLine(headerLine, actualDelimiter);
38
51
  const normalizedHeaders = headers.map(normalizeColumnName);
39
- // Find required txId column
40
- const txIdIndex = normalizedHeaders.findIndex(h => h === 'txid');
41
- if (txIdIndex === -1) {
42
- throw new Error('CSV must contain a "txId" column');
52
+ // Find cell identifier column - prefer cellName, fallback to txId
53
+ let idIndex = normalizedHeaders.findIndex(h => h === 'cellname');
54
+ let usesCellName = true;
55
+ if (idIndex === -1) {
56
+ idIndex = normalizedHeaders.findIndex(h => h === 'txid');
57
+ usesCellName = false;
58
+ }
59
+ if (idIndex === -1) {
60
+ throw new Error('CSV must contain a "cellName" or "txId" column');
43
61
  }
44
62
  // Find optional columns
45
63
  const groupIndex = normalizedHeaders.findIndex(h => h === 'customgroup');
@@ -62,9 +80,9 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
62
80
  const line = lines[i].trim();
63
81
  if (!line)
64
82
  continue;
65
- const values = parseCSVLine(line);
66
- const txId = values[txIdIndex]?.trim();
67
- if (!txId)
83
+ const values = parseCSVLine(line, actualDelimiter);
84
+ const cellIdentifier = values[idIndex]?.trim();
85
+ if (!cellIdentifier)
68
86
  continue;
69
87
  // Get custom group (default to 'default')
70
88
  const customGroup = groupIndex !== -1
@@ -88,10 +106,10 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
88
106
  extraFields[extraColumns[i]] = isNaN(numValue) ? value : numValue;
89
107
  });
90
108
  // Resolve cell from lookup
91
- const resolvedCell = cellLookup.get(txId);
109
+ const resolvedCell = cellLookup.get(cellIdentifier);
92
110
  if (resolvedCell) {
93
111
  cells.push({
94
- txId,
112
+ txId: resolvedCell.txId, // Always store the txId from resolved cell
95
113
  customGroup,
96
114
  sizeFactor,
97
115
  extraFields,
@@ -99,7 +117,7 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
99
117
  });
100
118
  }
101
119
  else {
102
- unmatchedTxIds.push(txId);
120
+ unmatchedTxIds.push(cellIdentifier);
103
121
  }
104
122
  }
105
123
  return {
@@ -112,8 +130,10 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
112
130
  }
113
131
  /**
114
132
  * Parse a single CSV line, handling quoted fields
133
+ * @param line The CSV line to parse
134
+ * @param delimiter The field delimiter (',' or ';')
115
135
  */
116
- function parseCSVLine(line) {
136
+ function parseCSVLine(line, delimiter = ',') {
117
137
  const result = [];
118
138
  let current = '';
119
139
  let inQuotes = false;
@@ -138,7 +158,7 @@ function parseCSVLine(line) {
138
158
  if (char === '"') {
139
159
  inQuotes = true;
140
160
  }
141
- else if (char === ',') {
161
+ else if (char === delimiter) {
142
162
  result.push(current);
143
163
  current = '';
144
164
  }
@@ -152,10 +172,16 @@ function parseCSVLine(line) {
152
172
  }
153
173
  /**
154
174
  * Build a cell lookup map from an array of cells
175
+ * Creates lookups for both cellName and txId for flexible matching
155
176
  */
156
177
  export function buildCellLookup(cells) {
157
178
  const lookup = new Map();
158
179
  for (const cell of cells) {
180
+ // Primary: lookup by cellName
181
+ if (cell.cellName) {
182
+ lookup.set(cell.cellName, cell);
183
+ }
184
+ // Fallback: also allow lookup by txId for backwards compatibility
159
185
  if (cell.txId) {
160
186
  lookup.set(cell.txId, cell);
161
187
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Custom Cells Logic - Barrel Export
3
3
  */
4
- export { parseCustomCellsCsv, buildCellLookup } from './csv-parser';
4
+ export { parseCustomCellsCsv, buildCellLookup, type CsvDelimiter } from './csv-parser';
5
5
  export { buildCustomCellTree, getGroupCounts } from './tree-adapter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartnet360/svelte-components",
3
- "version": "0.0.128",
3
+ "version": "0.0.130",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",