@solidpepper/solidpepper-solidgeneration 0.1.5 → 0.1.6

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.
@@ -1794,19 +1794,30 @@ class DataSheetSVG {
1794
1794
  }
1795
1795
  }
1796
1796
  else {
1797
- if (tag.XmlTag.getAttribute('data-type') != null) {
1798
- if (tag.XmlTag.getAttribute('data-type').includes('dynamicImage')) {
1797
+ const dataType = tag.XmlTag.getAttribute('data-type');
1798
+ if (dataType != null) {
1799
+ if (dataType.includes('dynamicImage')) {
1799
1800
  tag.Image = true;
1800
1801
  tag.nbFieldToReplace = 1;
1801
1802
  }
1802
- else if (tag.XmlTag.getAttribute('data-type').includes('barcode')) {
1803
+ else if (dataType.includes('barcode')) {
1803
1804
  tag.Barcode = true;
1804
1805
  tag.nbFieldToReplace = 1;
1805
1806
  }
1806
- else if (tag.XmlTag.getAttribute('data-type').includes('qrcode')) {
1807
+ else if (dataType.includes('qrcode')) {
1807
1808
  tag.QRCode = true;
1808
1809
  tag.nbFieldToReplace = 1;
1809
1810
  }
1811
+ else if (dataType.includes('productTable')) {
1812
+ tag.ProductTable = true;
1813
+ tag.Image = false;
1814
+ tag.VariantsTable = false;
1815
+ }
1816
+ else if (dataType.includes('variantsTable')) {
1817
+ tag.VariantsTable = true;
1818
+ tag.Image = false;
1819
+ tag.ProductTable = false;
1820
+ }
1810
1821
  else {
1811
1822
  tag.nbFieldToReplace = 0;
1812
1823
  tag.TextToReplace = '';
@@ -3614,8 +3625,12 @@ class DataSheetSVG {
3614
3625
  let colors = [];
3615
3626
  // Foreach tags
3616
3627
  for (let tag of allTags) {
3617
- if ((tag.nbFieldToReplace > 0 || tag.VariantsTable == true) &&
3618
- !tag.XmlTag.outerHTML.includes('{{Page}}')) {
3628
+ if ((tag.nbFieldToReplace > 0 ||
3629
+ tag.VariantsTable == true ||
3630
+ tag.ProductTable == true) &&
3631
+ (!tag.XmlTag.outerHTML.includes('{{Page}}') ||
3632
+ tag.VariantsTable == true ||
3633
+ tag.ProductTable == true)) {
3619
3634
  oldVal = tag.XmlTag;
3620
3635
  this.GetRectPositions(tag, allTags);
3621
3636
  if (tag.VariantsTable == true) {
@@ -3713,6 +3728,10 @@ class DataSheetSVG {
3713
3728
  container.innerHTML = newVal;
3714
3729
  for (let i = 0; i < tag.IdVals.length; i++) {
3715
3730
  let idVal = tag.IdVals[i];
3731
+ if (idVal.toLowerCase() === 'page' ||
3732
+ idVal.toLowerCase() === 'pagetotal') {
3733
+ continue;
3734
+ }
3716
3735
  let field;
3717
3736
  if (idVal.toLowerCase().includes('sku')) {
3718
3737
  field = this.getPropertyOfField(idVal.replace('sku', ''));
@@ -3907,7 +3926,7 @@ class DataSheetSVG {
3907
3926
  newVal = await this.deleteLine(newVal);
3908
3927
  tag.XmlTag.innerHTML = newVal;
3909
3928
  if (tag.XmlTag.hasAttribute('data-type') &&
3910
- tag.XmlTag.getAttribute('data-type') === 'productTable') {
3929
+ tag.XmlTag.getAttribute('data-type').includes('productTable')) {
3911
3930
  // REPLACE TSPAN VARIABLES IN TABLE CELLS
3912
3931
  const cellTspans = tag.XmlTag.querySelectorAll('tspan');
3913
3932
  cellTspans.forEach((tspan) => {
@@ -3915,6 +3934,10 @@ class DataSheetSVG {
3915
3934
  const match = tspanText.match(/^\{\{([\w\W]+?)\}\}$/);
3916
3935
  if (match) {
3917
3936
  const idVal = match[1];
3937
+ if (idVal.toLowerCase() === 'page' ||
3938
+ idVal.toLowerCase() === 'pagetotal') {
3939
+ return;
3940
+ }
3918
3941
  let fieldForCell;
3919
3942
  if (idVal.toLowerCase().includes('sku')) {
3920
3943
  fieldForCell = this.getPropertyOfField(idVal.replace('sku', ''));
@@ -3933,8 +3956,20 @@ class DataSheetSVG {
3933
3956
  tspan.remove();
3934
3957
  }
3935
3958
  });
3959
+ // Un-wrap .cellContent and .cellcontent divs in the original XmlTag
3960
+ const cellContents = tag.XmlTag.querySelectorAll('.cellContent, .cellcontent');
3961
+ cellContents.forEach((cellContent) => {
3962
+ const parent = cellContent.parentNode;
3963
+ if (parent) {
3964
+ while (cellContent.firstChild) {
3965
+ parent.insertBefore(cellContent.firstChild, cellContent);
3966
+ }
3967
+ parent.removeChild(cellContent);
3968
+ }
3969
+ });
3936
3970
  // FIX THE SIZE (WIDTH & HEIGHT)
3937
3971
  const size = this.optimizeProductTable(tag.XmlTag, tpl);
3972
+ tag.XmlTag.style.setProperty('overflow', 'visible', 'important');
3938
3973
  if (size.height) {
3939
3974
  tag.XmlTag.setAttribute('height', String(size.height));
3940
3975
  }
@@ -4201,11 +4236,12 @@ class DataSheetSVG {
4201
4236
  gabaritSvgUpdated = gabaritSvgUpdated.replace(/<head.*?>|<\/head>/g, '');
4202
4237
  tpl = gabaritSvgUpdated;
4203
4238
  if (!keepAttributes) {
4204
- tpl = tpl.replace(/\{\{[^}]*\}\}/g, '');
4239
+ tpl = tpl.replace(/\{\{(?!(Page|PageTotal)\b)[^}]*\}\}/gi, '');
4205
4240
  }
4206
4241
  return tpl;
4207
4242
  }
4208
4243
  optimizeProductTable(foEl, tpl) {
4244
+ foEl.style.setProperty('overflow', 'visible', 'important');
4209
4245
  const table = foEl.querySelector('table');
4210
4246
  if (!table)
4211
4247
  return { width: 0, height: 0 };
@@ -4244,11 +4280,44 @@ class DataSheetSVG {
4244
4280
  document.body.removeChild(tempDiv);
4245
4281
  return { width: 0, height: 0 };
4246
4282
  }
4247
- tableElement.style.width = 'auto';
4248
- tableElement.style.maxWidth = foWidth ? `${foWidth}px` : 'none';
4249
- tableElement.style.minWidth = '0';
4250
- tableElement.style.height = 'auto';
4251
- // Mesurer les largeurs optimales des colonnes
4283
+ // Un-wrap .cellContent divs to prevent max-content / fit-content CSS styles from blocking wrapping
4284
+ const cellContents = tableElement.querySelectorAll('.cellContent, .cellcontent');
4285
+ cellContents.forEach((cellContent) => {
4286
+ const parent = cellContent.parentNode;
4287
+ if (parent) {
4288
+ while (cellContent.firstChild) {
4289
+ parent.insertBefore(cellContent.firstChild, cellContent);
4290
+ }
4291
+ parent.removeChild(cellContent);
4292
+ }
4293
+ });
4294
+ // 1. Lire le colgroup d'origine pour obtenir les largeurs fixes
4295
+ const originalColgroup = table.querySelector('colgroup');
4296
+ const originalCols = originalColgroup
4297
+ ? Array.from(originalColgroup.querySelectorAll('col'))
4298
+ : [];
4299
+ const originalColWidths = [];
4300
+ originalCols.forEach((col) => {
4301
+ let width = null;
4302
+ if (col) {
4303
+ let w = col.style.width || col.getAttribute('width');
4304
+ if (!w) {
4305
+ const styleAttr = col.getAttribute('style');
4306
+ if (styleAttr) {
4307
+ const matchWidth = styleAttr.match(/width:\s*([^;]+)/);
4308
+ if (matchWidth)
4309
+ w = matchWidth[1].trim();
4310
+ }
4311
+ }
4312
+ if (w) {
4313
+ const parsed = parseFloat(w);
4314
+ if (!isNaN(parsed) && parsed > 0) {
4315
+ width = parsed;
4316
+ }
4317
+ }
4318
+ }
4319
+ originalColWidths.push(width);
4320
+ });
4252
4321
  const thead = tableElement.querySelector('thead');
4253
4322
  const tbody = tableElement.querySelector('tbody');
4254
4323
  const rows = Array.from(tableElement.rows);
@@ -4257,52 +4326,134 @@ class DataSheetSVG {
4257
4326
  rows[0]?.cells.length ||
4258
4327
  0;
4259
4328
  const colWidths = new Array(colCount).fill(0);
4260
- // Mesurer depuis tbody ET thead
4329
+ for (let i = 0; i < colCount; i++) {
4330
+ if (i < originalColWidths.length &&
4331
+ originalColWidths[i] !== null &&
4332
+ originalColWidths[i] !== undefined) {
4333
+ colWidths[i] = originalColWidths[i];
4334
+ }
4335
+ }
4336
+ const totalOriginalWidth = originalColWidths.reduce((sum, w) => sum + (w || 0), 0);
4337
+ // 2. Définir le style initial du tableau dans le DOM temporaire pour éviter tout collapse/deformatage
4338
+ const hasAutoColumns = colCount > originalColWidths.length ||
4339
+ originalColWidths.some((w) => w === null || w === undefined);
4340
+ if (hasAutoColumns) {
4341
+ tableElement.style.tableLayout = 'auto';
4342
+ tableElement.style.width = foWidth ? `${foWidth}px` : '100%';
4343
+ tableElement.style.maxWidth = foWidth ? `${foWidth}px` : 'none';
4344
+ }
4345
+ else {
4346
+ tableElement.style.tableLayout = 'fixed';
4347
+ if (totalOriginalWidth > 0) {
4348
+ tableElement.style.width = `${totalOriginalWidth}px`;
4349
+ tableElement.style.maxWidth = `${totalOriginalWidth}px`;
4350
+ }
4351
+ else {
4352
+ tableElement.style.width = foWidth ? `${foWidth}px` : 'auto';
4353
+ tableElement.style.maxWidth = foWidth ? `${foWidth}px` : 'none';
4354
+ }
4355
+ }
4356
+ tableElement.style.minWidth = '0';
4357
+ tableElement.style.height = 'auto';
4358
+ // 3. Forcer le wrap automatique des longs textes sous Flexbox sur les colonnes fixes avant la mesure
4359
+ const forceWrapping = (row) => {
4360
+ Array.from(row.cells).forEach((cell, i) => {
4361
+ if (i < colCount) {
4362
+ const hasFixedWidth = i < originalColWidths.length &&
4363
+ originalColWidths[i] !== null &&
4364
+ originalColWidths[i] !== undefined;
4365
+ if (hasFixedWidth) {
4366
+ cell.style.setProperty('width', `${originalColWidths[i]}px`, 'important');
4367
+ cell.style.setProperty('max-width', `${originalColWidths[i]}px`, 'important');
4368
+ }
4369
+ cell.style.setProperty('min-width', '0', 'important');
4370
+ cell.style.setProperty('white-space', 'normal', 'important');
4371
+ cell.style.setProperty('word-break', 'break-word', 'important');
4372
+ cell.querySelectorAll('div').forEach((div) => {
4373
+ if (hasFixedWidth) {
4374
+ div.style.setProperty('width', '100%', 'important');
4375
+ div.style.setProperty('max-width', '100%', 'important');
4376
+ }
4377
+ div.style.setProperty('min-width', '0', 'important');
4378
+ div.style.setProperty('white-space', 'normal', 'important');
4379
+ div.style.setProperty('word-break', 'break-word', 'important');
4380
+ div.style.setProperty('overflow-wrap', 'break-word', 'important');
4381
+ });
4382
+ }
4383
+ });
4384
+ };
4385
+ tableElement
4386
+ .querySelectorAll('thead tr, tbody tr')
4387
+ .forEach((row) => forceWrapping(row));
4388
+ // 4. Mesurer depuis tbody ET thead (uniquement pour les colonnes fluides sans largeur fixe originale)
4261
4389
  Array.from(tableElement.querySelectorAll('tbody tr, thead tr')).forEach((row) => {
4262
4390
  Array.from(row.cells).forEach((cell, i) => {
4263
4391
  if (cell && i < colCount) {
4392
+ if (i < originalColWidths.length &&
4393
+ originalColWidths[i] !== null &&
4394
+ originalColWidths[i] !== undefined) {
4395
+ return; // Garder la largeur fixe d'origine déjà affectée
4396
+ }
4264
4397
  colWidths[i] = Math.max(colWidths[i], cell.getBoundingClientRect().width);
4265
4398
  }
4266
4399
  });
4267
4400
  });
4268
- // Création du colgroup avec largeurs fixes (pas d'auto)
4401
+ // 5. Création du colgroup final en préservant les attributs originaux
4269
4402
  let colgroup = tableElement.querySelector('colgroup');
4270
4403
  if (colgroup)
4271
4404
  colgroup.remove();
4272
4405
  colgroup = document.createElement('colgroup');
4273
- colWidths.forEach((width) => {
4406
+ colWidths.forEach((width, i) => {
4274
4407
  const col = document.createElement('col');
4408
+ const originalCol = i < originalCols.length ? originalCols[i] : null;
4409
+ if (originalCol && originalCol.attributes) {
4410
+ Array.from(originalCol.attributes).forEach((attr) => {
4411
+ col.setAttribute(attr.name, attr.value);
4412
+ });
4413
+ }
4275
4414
  col.style.width = `${width}px`;
4276
4415
  colgroup.appendChild(col);
4277
4416
  });
4278
4417
  tableElement.insertBefore(colgroup, tableElement.firstChild);
4279
- // Appliquer les largeurs fixes aux cellules (thead + tbody)
4418
+ // 6. Appliquer les largeurs finales sur chaque cellule
4280
4419
  const theadRows = tableElement.querySelectorAll('thead tr');
4281
4420
  theadRows.forEach((row) => {
4282
4421
  Array.from(row.cells).forEach((cell, i) => {
4283
- if (i < colCount)
4422
+ if (i < colCount) {
4284
4423
  cell.style.width = `${colWidths[i]}px`;
4424
+ cell.style.maxWidth = `${colWidths[i]}px`;
4425
+ }
4285
4426
  });
4286
4427
  });
4287
4428
  const tbodyRows = tableElement.querySelectorAll('tbody tr');
4288
4429
  tbodyRows.forEach((row) => {
4289
4430
  Array.from(row.cells).forEach((cell, i) => {
4290
- if (i < colCount)
4431
+ if (i < colCount) {
4291
4432
  cell.style.width = `${colWidths[i]}px`;
4433
+ cell.style.maxWidth = `${colWidths[i]}px`;
4434
+ }
4292
4435
  });
4293
4436
  });
4294
- // Re-mesurer après application des largeurs fixes
4295
- // On prend le max entre offsetHeight (inclut les bordures) et getBoundingClientRect pour être sûr
4437
+ // 7. Calculer la somme des largeurs calculées/fixes de ses colonnes
4438
+ const totalColsWidth = colWidths.reduce((sum, w) => sum + (w || 0), 0);
4439
+ if (totalColsWidth > 0) {
4440
+ tableElement.style.width = `${totalColsWidth}px`;
4441
+ tableElement.style.maxWidth = `${totalColsWidth}px`;
4442
+ tableElement.style.tableLayout = 'fixed';
4443
+ }
4444
+ // Re-mesurer précisément la hauteur de la table après wrap
4296
4445
  const rect = tableElement.getBoundingClientRect();
4297
4446
  const finalWidth = Math.ceil(rect.width);
4298
4447
  const finalHeight = Math.ceil(Math.max(rect.height, tableElement.offsetHeight));
4299
- // Appliquer max-width calculé à la table
4448
+ // Appliquer le résultat final sur le DOM
4300
4449
  tableElement.style.width = `${finalWidth}px`;
4301
4450
  tableElement.style.maxWidth = `${finalWidth}px`;
4451
+ tableElement.style.tableLayout = 'fixed';
4302
4452
  // Mettre à jour la table originale dans le foreignObject
4303
4453
  table.innerHTML = tableElement.innerHTML;
4304
4454
  table.style.width = `${finalWidth}px`;
4305
4455
  table.style.maxWidth = `${finalWidth}px`;
4456
+ table.style.tableLayout = 'fixed';
4306
4457
  document.body.removeChild(tempDiv);
4307
4458
  return { width: finalWidth, height: finalHeight };
4308
4459
  }