@solidpepper/solidpepper-solidgeneration 0.1.4 → 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
|
-
|
|
1798
|
-
|
|
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 (
|
|
1803
|
+
else if (dataType.includes('barcode')) {
|
|
1803
1804
|
tag.Barcode = true;
|
|
1804
1805
|
tag.nbFieldToReplace = 1;
|
|
1805
1806
|
}
|
|
1806
|
-
else if (
|
|
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 = '';
|
|
@@ -2864,6 +2875,8 @@ class DataSheetSVG {
|
|
|
2864
2875
|
newVal = new Date().toLocaleDateString('fr-FR');
|
|
2865
2876
|
return newVal;
|
|
2866
2877
|
}
|
|
2878
|
+
const attrObj = jRowSku['attributeObject'] || [];
|
|
2879
|
+
const attrPub = jRowSku['attributePublication'] || [];
|
|
2867
2880
|
if (jRowSku.hasOwnProperty(field) &&
|
|
2868
2881
|
!idVal.toLowerCase().includes('sku images') &&
|
|
2869
2882
|
(tag == null || tag.Image == false)) {
|
|
@@ -2875,84 +2888,128 @@ class DataSheetSVG {
|
|
|
2875
2888
|
}
|
|
2876
2889
|
}
|
|
2877
2890
|
else if (tag != null && tag.Image == true) {
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2891
|
+
let index = parseInt(tag.XmlTag.getAttribute('number'));
|
|
2892
|
+
if (jRowSku[field] != null) {
|
|
2893
|
+
newVal = jRowSku[field];
|
|
2894
|
+
let valuePairs = new Map();
|
|
2895
|
+
let i = 0;
|
|
2896
|
+
newVal.split('#').forEach((asset) => {
|
|
2897
|
+
if (asset.trim() !== '') {
|
|
2898
|
+
valuePairs.set(i, asset);
|
|
2899
|
+
i += 1;
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
if (index !== 0) {
|
|
2903
|
+
if (valuePairs.has(index - 1)) {
|
|
2904
|
+
newVal = valuePairs.get(index - 1);
|
|
2905
|
+
}
|
|
2906
|
+
else {
|
|
2907
|
+
newVal = '';
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
else {
|
|
2911
|
+
if (valuePairs.has(index)) {
|
|
2912
|
+
newVal = valuePairs.get(index);
|
|
2913
|
+
}
|
|
2914
|
+
else {
|
|
2915
|
+
newVal = '';
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
else if (attrObj.filter((x) => x.hasOwnProperty(field)) != undefined &&
|
|
2920
|
+
attrObj.filter((x) => x.hasOwnProperty(field)) != null &&
|
|
2921
|
+
attrObj.find((obj) => obj.hasOwnProperty(field)) != undefined &&
|
|
2922
|
+
attrObj.find((obj) => obj.hasOwnProperty(field)) != null) {
|
|
2923
|
+
newVal = attrObj.find((obj) => obj.hasOwnProperty(field))[field];
|
|
2924
|
+
let valuePairs = new Map();
|
|
2925
|
+
let i = 0;
|
|
2926
|
+
if (newVal != null) {
|
|
2884
2927
|
newVal.split('#').forEach((asset) => {
|
|
2885
2928
|
if (asset.trim() !== '') {
|
|
2886
2929
|
valuePairs.set(i, asset);
|
|
2887
2930
|
i += 1;
|
|
2888
2931
|
}
|
|
2889
2932
|
});
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
else {
|
|
2895
|
-
newVal = '';
|
|
2896
|
-
}
|
|
2933
|
+
}
|
|
2934
|
+
if (index !== 0) {
|
|
2935
|
+
if (valuePairs.has(index - 1)) {
|
|
2936
|
+
newVal = valuePairs.get(index - 1);
|
|
2897
2937
|
}
|
|
2898
2938
|
else {
|
|
2899
|
-
|
|
2900
|
-
newVal = valuePairs.get(index);
|
|
2901
|
-
}
|
|
2902
|
-
else {
|
|
2903
|
-
newVal = '';
|
|
2904
|
-
}
|
|
2939
|
+
newVal = '';
|
|
2905
2940
|
}
|
|
2906
2941
|
}
|
|
2907
|
-
else
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
jRowSku['attributeObject'].find((obj) => obj.hasOwnProperty(field)) != null) {
|
|
2911
|
-
newVal = jRowSku['attributeObject'].find((obj) => obj.hasOwnProperty(field))[field];
|
|
2912
|
-
let valuePairs = new Map();
|
|
2913
|
-
let i = 0;
|
|
2914
|
-
if (newVal != null) {
|
|
2915
|
-
newVal.split('#').forEach((asset) => {
|
|
2916
|
-
if (asset.trim() !== '') {
|
|
2917
|
-
valuePairs.set(i, asset);
|
|
2918
|
-
i += 1;
|
|
2919
|
-
}
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
if (index !== 0) {
|
|
2923
|
-
if (valuePairs.has(index - 1)) {
|
|
2924
|
-
newVal = valuePairs.get(index - 1);
|
|
2925
|
-
}
|
|
2926
|
-
else {
|
|
2927
|
-
newVal = '';
|
|
2928
|
-
}
|
|
2942
|
+
else {
|
|
2943
|
+
if (valuePairs.has(index)) {
|
|
2944
|
+
newVal = valuePairs.get(index);
|
|
2929
2945
|
}
|
|
2930
2946
|
else {
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2947
|
+
newVal = '';
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
let urlBase = '';
|
|
2951
|
+
if (jRowSku['skuImagesDetail'] != null &&
|
|
2952
|
+
jRowSku['skuImagesDetail'] != '') {
|
|
2953
|
+
if (jRowSku['skuImagesDetail'][0] != null &&
|
|
2954
|
+
jRowSku['skuImagesDetail'][0] != '') {
|
|
2955
|
+
urlBase = jRowSku['skuImagesDetail'][0].assetUrlOriginal;
|
|
2956
|
+
urlBase = urlBase.substring(0, urlBase.lastIndexOf('/') + 1);
|
|
2937
2957
|
}
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2958
|
+
}
|
|
2959
|
+
if (urlBase != null &&
|
|
2960
|
+
urlBase != '' &&
|
|
2961
|
+
newVal != null &&
|
|
2962
|
+
newVal != '') {
|
|
2963
|
+
newVal = urlBase + newVal;
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
else if (attrPub.filter((x) => x.hasOwnProperty(field)) != undefined &&
|
|
2967
|
+
attrPub.filter((x) => x.hasOwnProperty(field)) != null &&
|
|
2968
|
+
attrPub.find((obj) => obj.hasOwnProperty(field)) != undefined &&
|
|
2969
|
+
attrPub.find((obj) => obj.hasOwnProperty(field)) != null) {
|
|
2970
|
+
//console.log('ON EST LA');
|
|
2971
|
+
newVal = attrPub.find((obj) => obj.hasOwnProperty(field))[field];
|
|
2972
|
+
console.log(newVal);
|
|
2973
|
+
let valuePairs = new Map();
|
|
2974
|
+
let i = 0;
|
|
2975
|
+
if (newVal != null) {
|
|
2976
|
+
newVal.split('#').forEach((asset) => {
|
|
2977
|
+
if (asset.trim() !== '') {
|
|
2978
|
+
valuePairs.set(i, asset);
|
|
2979
|
+
i += 1;
|
|
2945
2980
|
}
|
|
2981
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
if (index !== 0) {
|
|
2984
|
+
if (valuePairs.has(index - 1)) {
|
|
2985
|
+
newVal = valuePairs.get(index - 1);
|
|
2946
2986
|
}
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
newVal != null &&
|
|
2950
|
-
newVal != '') {
|
|
2951
|
-
newVal = urlBase + newVal;
|
|
2987
|
+
else {
|
|
2988
|
+
newVal = '';
|
|
2952
2989
|
}
|
|
2953
2990
|
}
|
|
2954
2991
|
else {
|
|
2955
|
-
|
|
2992
|
+
if (valuePairs.has(index)) {
|
|
2993
|
+
newVal = valuePairs.get(index);
|
|
2994
|
+
}
|
|
2995
|
+
else {
|
|
2996
|
+
newVal = '';
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
let urlBase = '';
|
|
3000
|
+
if (jRowSku['skuImagesDetail'] != null &&
|
|
3001
|
+
jRowSku['skuImagesDetail'] != '') {
|
|
3002
|
+
if (jRowSku['skuImagesDetail'][0] != null &&
|
|
3003
|
+
jRowSku['skuImagesDetail'][0] != '') {
|
|
3004
|
+
urlBase = jRowSku['skuImagesDetail'][0].assetUrlOriginal;
|
|
3005
|
+
urlBase = urlBase.substring(0, urlBase.lastIndexOf('/') + 1);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
if (urlBase != null &&
|
|
3009
|
+
urlBase != '' &&
|
|
3010
|
+
newVal != null &&
|
|
3011
|
+
newVal != '') {
|
|
3012
|
+
newVal = urlBase + newVal;
|
|
2956
3013
|
}
|
|
2957
3014
|
}
|
|
2958
3015
|
else {
|
|
@@ -3568,8 +3625,12 @@ class DataSheetSVG {
|
|
|
3568
3625
|
let colors = [];
|
|
3569
3626
|
// Foreach tags
|
|
3570
3627
|
for (let tag of allTags) {
|
|
3571
|
-
if ((tag.nbFieldToReplace > 0 ||
|
|
3572
|
-
|
|
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)) {
|
|
3573
3634
|
oldVal = tag.XmlTag;
|
|
3574
3635
|
this.GetRectPositions(tag, allTags);
|
|
3575
3636
|
if (tag.VariantsTable == true) {
|
|
@@ -3667,6 +3728,10 @@ class DataSheetSVG {
|
|
|
3667
3728
|
container.innerHTML = newVal;
|
|
3668
3729
|
for (let i = 0; i < tag.IdVals.length; i++) {
|
|
3669
3730
|
let idVal = tag.IdVals[i];
|
|
3731
|
+
if (idVal.toLowerCase() === 'page' ||
|
|
3732
|
+
idVal.toLowerCase() === 'pagetotal') {
|
|
3733
|
+
continue;
|
|
3734
|
+
}
|
|
3670
3735
|
let field;
|
|
3671
3736
|
if (idVal.toLowerCase().includes('sku')) {
|
|
3672
3737
|
field = this.getPropertyOfField(idVal.replace('sku', ''));
|
|
@@ -3861,7 +3926,7 @@ class DataSheetSVG {
|
|
|
3861
3926
|
newVal = await this.deleteLine(newVal);
|
|
3862
3927
|
tag.XmlTag.innerHTML = newVal;
|
|
3863
3928
|
if (tag.XmlTag.hasAttribute('data-type') &&
|
|
3864
|
-
tag.XmlTag.getAttribute('data-type')
|
|
3929
|
+
tag.XmlTag.getAttribute('data-type').includes('productTable')) {
|
|
3865
3930
|
// REPLACE TSPAN VARIABLES IN TABLE CELLS
|
|
3866
3931
|
const cellTspans = tag.XmlTag.querySelectorAll('tspan');
|
|
3867
3932
|
cellTspans.forEach((tspan) => {
|
|
@@ -3869,6 +3934,10 @@ class DataSheetSVG {
|
|
|
3869
3934
|
const match = tspanText.match(/^\{\{([\w\W]+?)\}\}$/);
|
|
3870
3935
|
if (match) {
|
|
3871
3936
|
const idVal = match[1];
|
|
3937
|
+
if (idVal.toLowerCase() === 'page' ||
|
|
3938
|
+
idVal.toLowerCase() === 'pagetotal') {
|
|
3939
|
+
return;
|
|
3940
|
+
}
|
|
3872
3941
|
let fieldForCell;
|
|
3873
3942
|
if (idVal.toLowerCase().includes('sku')) {
|
|
3874
3943
|
fieldForCell = this.getPropertyOfField(idVal.replace('sku', ''));
|
|
@@ -3887,8 +3956,20 @@ class DataSheetSVG {
|
|
|
3887
3956
|
tspan.remove();
|
|
3888
3957
|
}
|
|
3889
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
|
+
});
|
|
3890
3970
|
// FIX THE SIZE (WIDTH & HEIGHT)
|
|
3891
3971
|
const size = this.optimizeProductTable(tag.XmlTag, tpl);
|
|
3972
|
+
tag.XmlTag.style.setProperty('overflow', 'visible', 'important');
|
|
3892
3973
|
if (size.height) {
|
|
3893
3974
|
tag.XmlTag.setAttribute('height', String(size.height));
|
|
3894
3975
|
}
|
|
@@ -4155,14 +4236,20 @@ class DataSheetSVG {
|
|
|
4155
4236
|
gabaritSvgUpdated = gabaritSvgUpdated.replace(/<head.*?>|<\/head>/g, '');
|
|
4156
4237
|
tpl = gabaritSvgUpdated;
|
|
4157
4238
|
if (!keepAttributes) {
|
|
4158
|
-
tpl = tpl.replace(/\{\{[^}]*\}\}/
|
|
4239
|
+
tpl = tpl.replace(/\{\{(?!(Page|PageTotal)\b)[^}]*\}\}/gi, '');
|
|
4159
4240
|
}
|
|
4160
4241
|
return tpl;
|
|
4161
4242
|
}
|
|
4162
4243
|
optimizeProductTable(foEl, tpl) {
|
|
4244
|
+
foEl.style.setProperty('overflow', 'visible', 'important');
|
|
4163
4245
|
const table = foEl.querySelector('table');
|
|
4164
4246
|
if (!table)
|
|
4165
4247
|
return { width: 0, height: 0 };
|
|
4248
|
+
let tableId = table.getAttribute('id');
|
|
4249
|
+
if (!tableId) {
|
|
4250
|
+
tableId = 'generation-table-' + Math.random().toString(36).substr(2, 9);
|
|
4251
|
+
table.setAttribute('id', tableId);
|
|
4252
|
+
}
|
|
4166
4253
|
const foWidth = parseFloat(foEl.getAttribute('width')) ||
|
|
4167
4254
|
foEl.getBoundingClientRect().width ||
|
|
4168
4255
|
0;
|
|
@@ -4188,16 +4275,49 @@ class DataSheetSVG {
|
|
|
4188
4275
|
tempDiv.style.top = '-9999px';
|
|
4189
4276
|
tempDiv.style.width = 'auto';
|
|
4190
4277
|
document.body.appendChild(tempDiv);
|
|
4191
|
-
const tableElement = tempDiv.querySelector(
|
|
4278
|
+
const tableElement = tempDiv.querySelector(`#${tableId}`);
|
|
4192
4279
|
if (!tableElement) {
|
|
4193
4280
|
document.body.removeChild(tempDiv);
|
|
4194
4281
|
return { width: 0, height: 0 };
|
|
4195
4282
|
}
|
|
4196
|
-
|
|
4197
|
-
tableElement.
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
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
|
+
});
|
|
4201
4321
|
const thead = tableElement.querySelector('thead');
|
|
4202
4322
|
const tbody = tableElement.querySelector('tbody');
|
|
4203
4323
|
const rows = Array.from(tableElement.rows);
|
|
@@ -4206,52 +4326,134 @@ class DataSheetSVG {
|
|
|
4206
4326
|
rows[0]?.cells.length ||
|
|
4207
4327
|
0;
|
|
4208
4328
|
const colWidths = new Array(colCount).fill(0);
|
|
4209
|
-
|
|
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)
|
|
4210
4389
|
Array.from(tableElement.querySelectorAll('tbody tr, thead tr')).forEach((row) => {
|
|
4211
4390
|
Array.from(row.cells).forEach((cell, i) => {
|
|
4212
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
|
+
}
|
|
4213
4397
|
colWidths[i] = Math.max(colWidths[i], cell.getBoundingClientRect().width);
|
|
4214
4398
|
}
|
|
4215
4399
|
});
|
|
4216
4400
|
});
|
|
4217
|
-
// Création du colgroup
|
|
4401
|
+
// 5. Création du colgroup final en préservant les attributs originaux
|
|
4218
4402
|
let colgroup = tableElement.querySelector('colgroup');
|
|
4219
4403
|
if (colgroup)
|
|
4220
4404
|
colgroup.remove();
|
|
4221
4405
|
colgroup = document.createElement('colgroup');
|
|
4222
|
-
colWidths.forEach((width) => {
|
|
4406
|
+
colWidths.forEach((width, i) => {
|
|
4223
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
|
+
}
|
|
4224
4414
|
col.style.width = `${width}px`;
|
|
4225
4415
|
colgroup.appendChild(col);
|
|
4226
4416
|
});
|
|
4227
4417
|
tableElement.insertBefore(colgroup, tableElement.firstChild);
|
|
4228
|
-
// Appliquer les largeurs
|
|
4418
|
+
// 6. Appliquer les largeurs finales sur chaque cellule
|
|
4229
4419
|
const theadRows = tableElement.querySelectorAll('thead tr');
|
|
4230
4420
|
theadRows.forEach((row) => {
|
|
4231
4421
|
Array.from(row.cells).forEach((cell, i) => {
|
|
4232
|
-
if (i < colCount)
|
|
4422
|
+
if (i < colCount) {
|
|
4233
4423
|
cell.style.width = `${colWidths[i]}px`;
|
|
4424
|
+
cell.style.maxWidth = `${colWidths[i]}px`;
|
|
4425
|
+
}
|
|
4234
4426
|
});
|
|
4235
4427
|
});
|
|
4236
4428
|
const tbodyRows = tableElement.querySelectorAll('tbody tr');
|
|
4237
4429
|
tbodyRows.forEach((row) => {
|
|
4238
4430
|
Array.from(row.cells).forEach((cell, i) => {
|
|
4239
|
-
if (i < colCount)
|
|
4431
|
+
if (i < colCount) {
|
|
4240
4432
|
cell.style.width = `${colWidths[i]}px`;
|
|
4433
|
+
cell.style.maxWidth = `${colWidths[i]}px`;
|
|
4434
|
+
}
|
|
4241
4435
|
});
|
|
4242
4436
|
});
|
|
4243
|
-
//
|
|
4244
|
-
|
|
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
|
|
4245
4445
|
const rect = tableElement.getBoundingClientRect();
|
|
4246
4446
|
const finalWidth = Math.ceil(rect.width);
|
|
4247
4447
|
const finalHeight = Math.ceil(Math.max(rect.height, tableElement.offsetHeight));
|
|
4248
|
-
// Appliquer
|
|
4448
|
+
// Appliquer le résultat final sur le DOM
|
|
4249
4449
|
tableElement.style.width = `${finalWidth}px`;
|
|
4250
4450
|
tableElement.style.maxWidth = `${finalWidth}px`;
|
|
4451
|
+
tableElement.style.tableLayout = 'fixed';
|
|
4251
4452
|
// Mettre à jour la table originale dans le foreignObject
|
|
4252
4453
|
table.innerHTML = tableElement.innerHTML;
|
|
4253
4454
|
table.style.width = `${finalWidth}px`;
|
|
4254
4455
|
table.style.maxWidth = `${finalWidth}px`;
|
|
4456
|
+
table.style.tableLayout = 'fixed';
|
|
4255
4457
|
document.body.removeChild(tempDiv);
|
|
4256
4458
|
return { width: finalWidth, height: finalHeight };
|
|
4257
4459
|
}
|