@canvas-components/print-design 0.1.4 → 0.1.5

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/index.cjs CHANGED
@@ -1209,11 +1209,12 @@ function resolveTableCells(element, rows, columns) {
1209
1209
  (cell) => ((cell.rowSpan ?? 1) > 1 || (cell.colSpan ?? 1) > 1) && row < cell.rowIndex + Math.max(1, cell.rowSpan ?? 1) && row + rowSpan > cell.rowIndex && column < cell.columnIndex + Math.max(1, cell.colSpan ?? 1) && column + colSpan > cell.columnIndex
1210
1210
  );
1211
1211
  const rowRule = rule.row;
1212
- if (rowRule?.keys?.length) {
1213
- const targets = rowRule.columns?.length ? rowRule.columns : rowRule.keys;
1214
- const groupKey = (row) => JSON.stringify(
1215
- rowRule.keys.map((key) => valueKey(readTableCell(row, key)))
1216
- );
1212
+ const hasPath = (path) => Array.isArray(path) ? path.length > 0 : String(path ?? "").trim().length > 0;
1213
+ const rowKeys = rowRule?.keys.filter(hasPath) ?? [];
1214
+ if (rowKeys.length) {
1215
+ const rowColumns = rowRule?.columns?.filter(hasPath) ?? [];
1216
+ const targets = rowColumns.length ? rowColumns : rowKeys;
1217
+ const groupKey = (row) => JSON.stringify(rowKeys.map((key) => valueKey(readTableCell(row, key))));
1217
1218
  for (const [columnIndex, column] of columns.entries()) {
1218
1219
  if (!targets.some((key) => samePath(column.dataIndex, key))) continue;
1219
1220
  let rowIndex = 0;
@@ -1240,12 +1241,13 @@ function resolveTableCells(element, rows, columns) {
1240
1241
  }
1241
1242
  }
1242
1243
  const columnRule = rule.column;
1243
- if (columnRule?.keys?.length) {
1244
+ const columnKeys = columnRule?.keys.filter(hasPath) ?? [];
1245
+ if (columnKeys.length) {
1244
1246
  for (const [rowIndex, row] of rows.entries()) {
1245
1247
  let columnIndex = 0;
1246
1248
  while (columnIndex < columns.length) {
1247
1249
  const column = columns[columnIndex];
1248
- if (!columnRule.keys.some((key) => samePath(column.dataIndex, key)) || overlaps(rowIndex, columnIndex, 1, 1)) {
1250
+ if (!columnKeys.some((key) => samePath(column.dataIndex, key)) || overlaps(rowIndex, columnIndex, 1, 1)) {
1249
1251
  columnIndex++;
1250
1252
  continue;
1251
1253
  }
@@ -1254,7 +1256,7 @@ function resolveTableCells(element, rows, columns) {
1254
1256
  while (columnIndex + colSpan < columns.length) {
1255
1257
  const nextIndex = columnIndex + colSpan;
1256
1258
  const next = columns[nextIndex];
1257
- if (!columnRule.keys.some((key) => samePath(next.dataIndex, key)) || valueKey(readTableCell(row, next.dataIndex)) !== current || overlaps(rowIndex, nextIndex, 1, 1))
1259
+ if (!columnKeys.some((key) => samePath(next.dataIndex, key)) || valueKey(readTableCell(row, next.dataIndex)) !== current || overlaps(rowIndex, nextIndex, 1, 1))
1258
1260
  break;
1259
1261
  colSpan++;
1260
1262
  }
@@ -6315,9 +6317,11 @@ function materializePackedReport(document, data) {
6315
6317
  const table = source.elements.find(
6316
6318
  (element) => element.type === "table" && !!element.packedReport
6317
6319
  );
6318
- if (!table?.packedReport || !table.dataPath) return [source];
6319
- const input = resolveTableDataSource(data, table.dataPath);
6320
- if (!Array.isArray(input) && table.fallbackToStatic) return [source];
6320
+ if (!table?.packedReport) return [source];
6321
+ if (table.dataMode === "binding" && !table.dataPath) return [source];
6322
+ const input = table.dataMode === "binding" ? resolveTableDataSource(data, table.dataPath) : table.dataSource;
6323
+ if (table.dataMode === "binding" && !Array.isArray(input) && table.fallbackToStatic)
6324
+ return [source];
6321
6325
  const records = (Array.isArray(input) ? input : []).filter(
6322
6326
  (item) => !!item && typeof item === "object" && !Array.isArray(item)
6323
6327
  );
package/dist/index.js CHANGED
@@ -1207,11 +1207,12 @@ function resolveTableCells(element, rows, columns) {
1207
1207
  (cell) => ((cell.rowSpan ?? 1) > 1 || (cell.colSpan ?? 1) > 1) && row < cell.rowIndex + Math.max(1, cell.rowSpan ?? 1) && row + rowSpan > cell.rowIndex && column < cell.columnIndex + Math.max(1, cell.colSpan ?? 1) && column + colSpan > cell.columnIndex
1208
1208
  );
1209
1209
  const rowRule = rule.row;
1210
- if (rowRule?.keys?.length) {
1211
- const targets = rowRule.columns?.length ? rowRule.columns : rowRule.keys;
1212
- const groupKey = (row) => JSON.stringify(
1213
- rowRule.keys.map((key) => valueKey(readTableCell(row, key)))
1214
- );
1210
+ const hasPath = (path) => Array.isArray(path) ? path.length > 0 : String(path ?? "").trim().length > 0;
1211
+ const rowKeys = rowRule?.keys.filter(hasPath) ?? [];
1212
+ if (rowKeys.length) {
1213
+ const rowColumns = rowRule?.columns?.filter(hasPath) ?? [];
1214
+ const targets = rowColumns.length ? rowColumns : rowKeys;
1215
+ const groupKey = (row) => JSON.stringify(rowKeys.map((key) => valueKey(readTableCell(row, key))));
1215
1216
  for (const [columnIndex, column] of columns.entries()) {
1216
1217
  if (!targets.some((key) => samePath(column.dataIndex, key))) continue;
1217
1218
  let rowIndex = 0;
@@ -1238,12 +1239,13 @@ function resolveTableCells(element, rows, columns) {
1238
1239
  }
1239
1240
  }
1240
1241
  const columnRule = rule.column;
1241
- if (columnRule?.keys?.length) {
1242
+ const columnKeys = columnRule?.keys.filter(hasPath) ?? [];
1243
+ if (columnKeys.length) {
1242
1244
  for (const [rowIndex, row] of rows.entries()) {
1243
1245
  let columnIndex = 0;
1244
1246
  while (columnIndex < columns.length) {
1245
1247
  const column = columns[columnIndex];
1246
- if (!columnRule.keys.some((key) => samePath(column.dataIndex, key)) || overlaps(rowIndex, columnIndex, 1, 1)) {
1248
+ if (!columnKeys.some((key) => samePath(column.dataIndex, key)) || overlaps(rowIndex, columnIndex, 1, 1)) {
1247
1249
  columnIndex++;
1248
1250
  continue;
1249
1251
  }
@@ -1252,7 +1254,7 @@ function resolveTableCells(element, rows, columns) {
1252
1254
  while (columnIndex + colSpan < columns.length) {
1253
1255
  const nextIndex = columnIndex + colSpan;
1254
1256
  const next = columns[nextIndex];
1255
- if (!columnRule.keys.some((key) => samePath(next.dataIndex, key)) || valueKey(readTableCell(row, next.dataIndex)) !== current || overlaps(rowIndex, nextIndex, 1, 1))
1257
+ if (!columnKeys.some((key) => samePath(next.dataIndex, key)) || valueKey(readTableCell(row, next.dataIndex)) !== current || overlaps(rowIndex, nextIndex, 1, 1))
1256
1258
  break;
1257
1259
  colSpan++;
1258
1260
  }
@@ -6313,9 +6315,11 @@ function materializePackedReport(document, data) {
6313
6315
  const table = source.elements.find(
6314
6316
  (element) => element.type === "table" && !!element.packedReport
6315
6317
  );
6316
- if (!table?.packedReport || !table.dataPath) return [source];
6317
- const input = resolveTableDataSource(data, table.dataPath);
6318
- if (!Array.isArray(input) && table.fallbackToStatic) return [source];
6318
+ if (!table?.packedReport) return [source];
6319
+ if (table.dataMode === "binding" && !table.dataPath) return [source];
6320
+ const input = table.dataMode === "binding" ? resolveTableDataSource(data, table.dataPath) : table.dataSource;
6321
+ if (table.dataMode === "binding" && !Array.isArray(input) && table.fallbackToStatic)
6322
+ return [source];
6319
6323
  const records = (Array.isArray(input) ? input : []).filter(
6320
6324
  (item) => !!item && typeof item === "object" && !Array.isArray(item)
6321
6325
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas-components/print-design",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Framework-agnostic Canvas print design engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "pnpm": ">=9.0.0"
27
27
  },
28
28
  "dependencies": {
29
- "@canvas-components/barcode": "0.2.3",
30
29
  "@canvas-components/chart": "0.3.9",
30
+ "@canvas-components/barcode": "0.2.3",
31
31
  "@canvas-components/qrcode": "0.2.3"
32
32
  },
33
33
  "scripts": {