@solidpepper/solidpepper-solidgeneration 0.2.8 → 0.3.0
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.
|
@@ -419,6 +419,56 @@ class DataSheetSingleton {
|
|
|
419
419
|
this.callouts = {};
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
+
async getAttributesSimplified(attributesGroupType = 'skus,publications') {
|
|
423
|
+
if (!this.token || !this.apiUrl) {
|
|
424
|
+
throw new Error('DataSheetSingleton: token or apiUrl not set');
|
|
425
|
+
}
|
|
426
|
+
const headers = {
|
|
427
|
+
Authorization: `bearer ${this.token}`,
|
|
428
|
+
};
|
|
429
|
+
// 1. Try dedicated simplified endpoint
|
|
430
|
+
try {
|
|
431
|
+
const url = `${this.apiUrl}Attributes/simplified?attributesGroupType=${attributesGroupType}`;
|
|
432
|
+
const response = await fetch(url, { headers });
|
|
433
|
+
if (response.ok) {
|
|
434
|
+
const json = await response.json();
|
|
435
|
+
const list = json?.Attributes || json?.attributes || json;
|
|
436
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
437
|
+
return list;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
catch (_) {
|
|
442
|
+
// fallback below
|
|
443
|
+
}
|
|
444
|
+
// 2. Fallback to querying SKUs and Publications attributes
|
|
445
|
+
const fetchGroup = async (groupType) => {
|
|
446
|
+
try {
|
|
447
|
+
const url = `${this.apiUrl}Attributes?attributesGroupGuid=&attributesGroupType=${groupType}&attributesGroupIsSystem=false`;
|
|
448
|
+
const res = await fetch(url, { headers });
|
|
449
|
+
if (res.ok) {
|
|
450
|
+
const data = await res.json();
|
|
451
|
+
const items = data?.Attributes || data?.attributes || data || [];
|
|
452
|
+
if (Array.isArray(items)) {
|
|
453
|
+
return items.map((a) => ({
|
|
454
|
+
attributeGuid: a.attributeGuid,
|
|
455
|
+
attributeName: a.attributeName,
|
|
456
|
+
attributeType: a.attributeType,
|
|
457
|
+
attributesGroupGuid: a.attributesGroupGuid,
|
|
458
|
+
attributeOptions: a.attributeOptions,
|
|
459
|
+
}));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (_) { }
|
|
464
|
+
return [];
|
|
465
|
+
};
|
|
466
|
+
const [skus, pubs] = await Promise.all([
|
|
467
|
+
fetchGroup('skus'),
|
|
468
|
+
fetchGroup('publications'),
|
|
469
|
+
]);
|
|
470
|
+
return [...skus, ...pubs];
|
|
471
|
+
}
|
|
422
472
|
async getAttributesByType(attributeType, attributeGroup = '') {
|
|
423
473
|
if (!this.token || !this.apiUrl) {
|
|
424
474
|
throw new Error('DataSheetSingleton: token or apiUrl not set');
|
|
@@ -451,23 +501,13 @@ class DataSheetSingleton {
|
|
|
451
501
|
if (this.attributes && this.attributes.length > 0) {
|
|
452
502
|
return this.attributes;
|
|
453
503
|
}
|
|
454
|
-
//console.log('Fetching new attributes and fields for DataSheetSingleton...');
|
|
455
504
|
try {
|
|
456
|
-
const [
|
|
457
|
-
this.
|
|
458
|
-
this.getAttributesByType('multiSelect', 'skus'),
|
|
459
|
-
this.getAttributesByType('radio', 'skus'),
|
|
460
|
-
this.getAttributesByType('checkbox', 'skus'),
|
|
461
|
-
this.getAttributesByType('dropDown', 'publications'),
|
|
462
|
-
this.getAttributesByType('multiSelect', 'publications'),
|
|
463
|
-
this.getAttributesByType('radio', 'publications'),
|
|
464
|
-
this.getAttributesByType('checkbox', 'publications'),
|
|
505
|
+
const [simplifiedAttrs, resFields] = await Promise.all([
|
|
506
|
+
this.getAttributesSimplified(),
|
|
465
507
|
this.getFields(),
|
|
466
508
|
]);
|
|
467
|
-
|
|
468
|
-
this.
|
|
469
|
-
this.fields = resFields['fields'];
|
|
470
|
-
//console.log('Attributes and fields successfully fetched and cached in singleton.');
|
|
509
|
+
this.attributes = simplifiedAttrs || [];
|
|
510
|
+
this.fields = resFields?.['fields'] || [];
|
|
471
511
|
return this.attributes;
|
|
472
512
|
}
|
|
473
513
|
catch (error) {
|
|
@@ -516,8 +556,7 @@ class DataSheetSVG {
|
|
|
516
556
|
this.DataSheet.publicationTemplateHeight = parsedH;
|
|
517
557
|
}
|
|
518
558
|
}
|
|
519
|
-
const widthAttr = element.getAttribute('width') ||
|
|
520
|
-
element.getAttribute('data-width');
|
|
559
|
+
const widthAttr = element.getAttribute('width') || element.getAttribute('data-width');
|
|
521
560
|
if (widthAttr) {
|
|
522
561
|
const parsedW = parseFloat(widthAttr);
|
|
523
562
|
if (!isNaN(parsedW) && parsedW > 0) {
|
|
@@ -592,7 +631,8 @@ class DataSheetSVG {
|
|
|
592
631
|
this.DataSheet.publicationTemplateBackgroundRightMargin =
|
|
593
632
|
parsedMarginRight;
|
|
594
633
|
this.DataSheet.publicationTemplateBackgroundMarginX =
|
|
595
|
-
(this.DataSheet.publicationTemplateWidth || 793) -
|
|
634
|
+
(this.DataSheet.publicationTemplateWidth || 793) -
|
|
635
|
+
parsedMarginRight;
|
|
596
636
|
}
|
|
597
637
|
else if (!this.DataSheet.publicationTemplateBackgroundRightMargin) {
|
|
598
638
|
this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
|
|
@@ -2757,6 +2797,194 @@ class DataSheetSVG {
|
|
|
2757
2797
|
return null;
|
|
2758
2798
|
}
|
|
2759
2799
|
}
|
|
2800
|
+
getAttributeLabel(idVal, field, rowToUse) {
|
|
2801
|
+
const rawLang = this.DataSheet?.language || this.languagePreviewSelected || 'fr';
|
|
2802
|
+
const lang = String(rawLang).toLowerCase().trim();
|
|
2803
|
+
const shortLang = lang.split(/[-_]/)[0];
|
|
2804
|
+
const cleanId = (idVal || '').replace(/^sku/i, '').trim();
|
|
2805
|
+
const searchKeys = [idVal, cleanId, field].filter((k) => Boolean(k && k.trim()));
|
|
2806
|
+
const normSearchKeys = searchKeys.map((k) => k.toLowerCase().trim());
|
|
2807
|
+
const parseAttributeName = (name) => {
|
|
2808
|
+
if (!name)
|
|
2809
|
+
return null;
|
|
2810
|
+
if (typeof name === 'object')
|
|
2811
|
+
return name;
|
|
2812
|
+
if (typeof name === 'string' && name.trim().startsWith('{')) {
|
|
2813
|
+
try {
|
|
2814
|
+
return JSON.parse(name);
|
|
2815
|
+
}
|
|
2816
|
+
catch (_) {
|
|
2817
|
+
return name;
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
return name;
|
|
2821
|
+
};
|
|
2822
|
+
const extractLocalizedName = (attrNameObj) => {
|
|
2823
|
+
const parsed = parseAttributeName(attrNameObj);
|
|
2824
|
+
if (!parsed)
|
|
2825
|
+
return null;
|
|
2826
|
+
if (typeof parsed === 'string' && !parsed.trim().startsWith('{')) {
|
|
2827
|
+
return parsed;
|
|
2828
|
+
}
|
|
2829
|
+
if (typeof parsed === 'object') {
|
|
2830
|
+
const val = parsed[lang] ||
|
|
2831
|
+
parsed[shortLang] ||
|
|
2832
|
+
parsed['fr'] ||
|
|
2833
|
+
parsed['en'] ||
|
|
2834
|
+
Object.values(parsed)[0];
|
|
2835
|
+
if (typeof val === 'string' && val.trim() !== '')
|
|
2836
|
+
return val;
|
|
2837
|
+
}
|
|
2838
|
+
return null;
|
|
2839
|
+
};
|
|
2840
|
+
const matchAttribute = (attr) => {
|
|
2841
|
+
if (!attr)
|
|
2842
|
+
return false;
|
|
2843
|
+
const getStrings = (v) => {
|
|
2844
|
+
if (!v)
|
|
2845
|
+
return [];
|
|
2846
|
+
if (typeof v === 'string')
|
|
2847
|
+
return [v.toLowerCase().trim()];
|
|
2848
|
+
const parsed = parseAttributeName(v);
|
|
2849
|
+
if (typeof parsed === 'object' && parsed) {
|
|
2850
|
+
return Object.values(parsed)
|
|
2851
|
+
.filter((x) => typeof x === 'string')
|
|
2852
|
+
.map((x) => x.toLowerCase().trim());
|
|
2853
|
+
}
|
|
2854
|
+
return [String(v).toLowerCase().trim()];
|
|
2855
|
+
};
|
|
2856
|
+
const candidates = [
|
|
2857
|
+
...getStrings(attr.attributeGuid),
|
|
2858
|
+
...getStrings(attr.attributeName),
|
|
2859
|
+
...getStrings(attr.name),
|
|
2860
|
+
...getStrings(attr.key),
|
|
2861
|
+
];
|
|
2862
|
+
return candidates.some((cand) => normSearchKeys.includes(cand));
|
|
2863
|
+
};
|
|
2864
|
+
// 1. Search in rowToUse (pageAttributes, attributePublication, attributes, attributeObject)
|
|
2865
|
+
if (rowToUse) {
|
|
2866
|
+
if (Array.isArray(rowToUse.pageAttributes)) {
|
|
2867
|
+
for (const group of rowToUse.pageAttributes) {
|
|
2868
|
+
if (group && Array.isArray(group.attributes)) {
|
|
2869
|
+
for (const attr of group.attributes) {
|
|
2870
|
+
if (matchAttribute(attr)) {
|
|
2871
|
+
const loc = extractLocalizedName(attr.attributeName || attr.name);
|
|
2872
|
+
if (loc) {
|
|
2873
|
+
return loc;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
if (Array.isArray(rowToUse.attributePublication)) {
|
|
2881
|
+
for (const item of rowToUse.attributePublication) {
|
|
2882
|
+
if (item && Array.isArray(item.attributes)) {
|
|
2883
|
+
for (const attr of item.attributes) {
|
|
2884
|
+
if (matchAttribute(attr)) {
|
|
2885
|
+
const loc = extractLocalizedName(attr.attributeName || attr.name);
|
|
2886
|
+
if (loc) {
|
|
2887
|
+
return loc;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
if (matchAttribute(item)) {
|
|
2893
|
+
const loc = extractLocalizedName(item.attributeName || item.name);
|
|
2894
|
+
if (loc) {
|
|
2895
|
+
return loc;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
if (Array.isArray(rowToUse.attributes)) {
|
|
2901
|
+
for (const attr of rowToUse.attributes) {
|
|
2902
|
+
if (matchAttribute(attr)) {
|
|
2903
|
+
const loc = extractLocalizedName(attr.attributeName || attr.name);
|
|
2904
|
+
if (loc) {
|
|
2905
|
+
return loc;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
if (Array.isArray(rowToUse.attributeObject)) {
|
|
2911
|
+
for (const attr of rowToUse.attributeObject) {
|
|
2912
|
+
if (matchAttribute(attr)) {
|
|
2913
|
+
const loc = extractLocalizedName(attr.attributeName || attr.name);
|
|
2914
|
+
if (loc) {
|
|
2915
|
+
return loc;
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
// 2. Search in publication publicationAttributes
|
|
2922
|
+
const pub = this.DataSheet?.publication ||
|
|
2923
|
+
this.publication ||
|
|
2924
|
+
this.dataSheetsController?.publication;
|
|
2925
|
+
const pubAttrs = pub?.publicationAttributes;
|
|
2926
|
+
if (Array.isArray(pubAttrs)) {
|
|
2927
|
+
for (const info of pubAttrs) {
|
|
2928
|
+
if (info && Array.isArray(info.attributes)) {
|
|
2929
|
+
for (const attr of info.attributes) {
|
|
2930
|
+
if (matchAttribute(attr)) {
|
|
2931
|
+
const loc = extractLocalizedName(attr.attributeName || attr.name);
|
|
2932
|
+
if (loc) {
|
|
2933
|
+
return loc;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
// 3. Search in this.DataSheet.attributes & DataSheetSingleton.attributes
|
|
2941
|
+
const allAttrs = (this.DataSheet && this.DataSheet.attributes) ||
|
|
2942
|
+
DataSheetSingleton.getInstance().attributes ||
|
|
2943
|
+
[];
|
|
2944
|
+
if (allAttrs && Array.isArray(allAttrs)) {
|
|
2945
|
+
for (const a of allAttrs) {
|
|
2946
|
+
if (matchAttribute(a)) {
|
|
2947
|
+
const loc = extractLocalizedName(a.attributeName || a.name);
|
|
2948
|
+
if (loc) {
|
|
2949
|
+
return loc;
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
// 4. Search in this.DataSheet.fields & DataSheetSingleton.fields
|
|
2955
|
+
const fieldsGroups = (this.DataSheet && this.DataSheet.fields) ||
|
|
2956
|
+
DataSheetSingleton.getInstance().fields ||
|
|
2957
|
+
[];
|
|
2958
|
+
if (fieldsGroups && Array.isArray(fieldsGroups)) {
|
|
2959
|
+
for (const group of fieldsGroups) {
|
|
2960
|
+
const fields = group && group.fields;
|
|
2961
|
+
if (fields && Array.isArray(fields)) {
|
|
2962
|
+
for (const f of fields) {
|
|
2963
|
+
if (!f)
|
|
2964
|
+
continue;
|
|
2965
|
+
const fKey = f.key ? String(f.key).toLowerCase().trim() : '';
|
|
2966
|
+
const fValues = Object.entries(f)
|
|
2967
|
+
.filter(([k]) => k !== 'key' && k !== 'id' && k !== 'guid')
|
|
2968
|
+
.map(([_, v]) => typeof v === 'string' ? v.toLowerCase().trim() : '');
|
|
2969
|
+
const isMatch = normSearchKeys.includes(fKey) ||
|
|
2970
|
+
fValues.some((v) => v && normSearchKeys.includes(v));
|
|
2971
|
+
if (isMatch) {
|
|
2972
|
+
const loc = extractLocalizedName(f.attributeName || f.name) ||
|
|
2973
|
+
f[lang] ||
|
|
2974
|
+
f[shortLang] ||
|
|
2975
|
+
f['fr'] ||
|
|
2976
|
+
f['en'] ||
|
|
2977
|
+
Object.values(f).find((v) => typeof v === 'string' && v.trim() !== '');
|
|
2978
|
+
if (loc) {
|
|
2979
|
+
return loc;
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
return idVal;
|
|
2987
|
+
}
|
|
2760
2988
|
async getNewValTable(jRowSku, tag, svgContent, allBlocksHeight, blockWidth, nbBlockInRow, keepAttributes = false) {
|
|
2761
2989
|
if (!jRowSku.hasOwnProperty('skus')) {
|
|
2762
2990
|
return [];
|
|
@@ -4678,6 +4906,8 @@ class DataSheetSVG {
|
|
|
4678
4906
|
if (tspan.textContent?.trim() === `{{${idVal}}}`) {
|
|
4679
4907
|
const innerHTML = tspan.innerHTML;
|
|
4680
4908
|
const placeholder = `{{${idVal}}}`;
|
|
4909
|
+
const showLabel = tspan.hasAttribute('data-show-label') &&
|
|
4910
|
+
tspan.getAttribute('data-show-label') !== 'false';
|
|
4681
4911
|
const showText = tspan.getAttribute('data-show-text') || 'true';
|
|
4682
4912
|
const showPicto = tspan.getAttribute('data-show-picto') || 'false';
|
|
4683
4913
|
const separator = tspan.getAttribute('data-separator') || ', ';
|
|
@@ -4695,7 +4925,9 @@ class DataSheetSVG {
|
|
|
4695
4925
|
}
|
|
4696
4926
|
}
|
|
4697
4927
|
}
|
|
4698
|
-
let valueToInsert =
|
|
4928
|
+
let valueToInsert = showLabel
|
|
4929
|
+
? this.getAttributeLabel(idVal, field, rowToUse)
|
|
4930
|
+
: this.getNewVal(field, rowToUse, idVal, tag, showText === 'true', showPicto === 'true', separator, keepAttributes);
|
|
4699
4931
|
valueToInsert = this.applyTextTransform(valueToInsert, textTransform);
|
|
4700
4932
|
const isValEmpty = valueToInsert === null ||
|
|
4701
4933
|
valueToInsert === undefined ||
|
|
@@ -5196,11 +5428,15 @@ class DataSheetSVG {
|
|
|
5196
5428
|
else {
|
|
5197
5429
|
fieldForCell = this.getPropertyOfField(idVal);
|
|
5198
5430
|
}
|
|
5431
|
+
const showLabel = tspan.hasAttribute('data-show-label') &&
|
|
5432
|
+
tspan.getAttribute('data-show-label') !== 'false';
|
|
5199
5433
|
const showText = tspan.getAttribute('data-show-text') || 'true';
|
|
5200
5434
|
const showPicto = tspan.getAttribute('data-show-picto') || 'false';
|
|
5201
5435
|
const separator = tspan.getAttribute('data-separator') || ', ';
|
|
5202
5436
|
const textTransform = tspan.getAttribute('data-text-transform');
|
|
5203
|
-
let cellVal =
|
|
5437
|
+
let cellVal = showLabel
|
|
5438
|
+
? this.getAttributeLabel(idVal, fieldForCell, jRowSku)
|
|
5439
|
+
: this.getNewVal(fieldForCell || '', jRowSku, idVal, tag, showText === 'true', showPicto === 'true', separator, keepAttributes);
|
|
5204
5440
|
cellVal = this.applyTextTransform(cellVal, textTransform);
|
|
5205
5441
|
const isEmpty = cellVal === null ||
|
|
5206
5442
|
cellVal === undefined ||
|
|
@@ -5341,7 +5577,8 @@ class DataSheetSVG {
|
|
|
5341
5577
|
? this.DataSheet.publicationTemplateBackgroundFooterY
|
|
5342
5578
|
: this.DataSheet.publicationTemplateHeight > 0
|
|
5343
5579
|
? this.DataSheet.publicationTemplateHeight -
|
|
5344
|
-
(this.DataSheet
|
|
5580
|
+
(this.DataSheet
|
|
5581
|
+
.publicationTemplateBackgroundHeightFooter || 0)
|
|
5345
5582
|
: this.DataSheet.backgroundHeight > 0
|
|
5346
5583
|
? this.DataSheet.backgroundHeight -
|
|
5347
5584
|
(this.DataSheet.backgroundMarginBottom || 0)
|
|
@@ -5663,6 +5900,50 @@ class DataSheetSVG {
|
|
|
5663
5900
|
}
|
|
5664
5901
|
index++;
|
|
5665
5902
|
}
|
|
5903
|
+
// 0. Assainir les zones interactives : déballer toute balise <a> enveloppante (héritée d'anciennes versions)
|
|
5904
|
+
// et transférer les métadonnées (data-*, title, etc.) directement sur le <rect>.
|
|
5905
|
+
const legacyInteractiveAnchors = Array.from(domSVG.querySelectorAll("a[data-type='interactive'], a[data-interactive='true'], a:has(> rect[data-type='interactive']), a:has(> rect[data-interactive='true'])"));
|
|
5906
|
+
legacyInteractiveAnchors.forEach((aEl) => {
|
|
5907
|
+
const childRect = aEl.querySelector('rect');
|
|
5908
|
+
if (childRect) {
|
|
5909
|
+
['data-type', 'data-interactive', 'data-show-box', 'data-color', 'data-url', 'data-href', 'title', 'data-target', 'data-name'].forEach((attr) => {
|
|
5910
|
+
const val = aEl.getAttribute(attr);
|
|
5911
|
+
if (val && !childRect.hasAttribute(attr)) {
|
|
5912
|
+
childRect.setAttribute(attr, val);
|
|
5913
|
+
}
|
|
5914
|
+
});
|
|
5915
|
+
const aHref = aEl.getAttribute('href') || aEl.getAttribute('xlink:href');
|
|
5916
|
+
if (aHref && aHref !== '#' && !childRect.hasAttribute('data-href')) {
|
|
5917
|
+
childRect.setAttribute('data-href', aHref);
|
|
5918
|
+
}
|
|
5919
|
+
aEl.parentNode?.replaceChild(childRect, aEl);
|
|
5920
|
+
}
|
|
5921
|
+
});
|
|
5922
|
+
const allInteractiveRects = Array.from(domSVG.querySelectorAll("rect[data-type='interactive'], rect[data-interactive='true']"));
|
|
5923
|
+
allInteractiveRects.forEach((rect) => {
|
|
5924
|
+
let p = rect.parentElement;
|
|
5925
|
+
while (p && p.tagName.toLowerCase() === 'a') {
|
|
5926
|
+
const grandParent = p.parentElement;
|
|
5927
|
+
const currentAnchor = p;
|
|
5928
|
+
if (grandParent) {
|
|
5929
|
+
['data-type', 'data-interactive', 'data-show-box', 'data-color', 'data-url', 'data-href', 'title', 'data-target', 'data-name'].forEach((attr) => {
|
|
5930
|
+
const val = currentAnchor.getAttribute(attr);
|
|
5931
|
+
if (val && !rect.hasAttribute(attr)) {
|
|
5932
|
+
rect.setAttribute(attr, val);
|
|
5933
|
+
}
|
|
5934
|
+
});
|
|
5935
|
+
const aHref = currentAnchor.getAttribute('href') || currentAnchor.getAttribute('xlink:href');
|
|
5936
|
+
if (aHref && aHref !== '#' && !rect.hasAttribute('data-href')) {
|
|
5937
|
+
rect.setAttribute('data-href', aHref);
|
|
5938
|
+
}
|
|
5939
|
+
grandParent.replaceChild(rect, currentAnchor);
|
|
5940
|
+
p = rect.parentElement;
|
|
5941
|
+
}
|
|
5942
|
+
else {
|
|
5943
|
+
break;
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
});
|
|
5666
5947
|
// Récupérer tous les objets ayant data-url
|
|
5667
5948
|
let urlToWork = domSVG.querySelectorAll('[data-url]');
|
|
5668
5949
|
urlToWork.forEach((element) => {
|
|
@@ -5676,7 +5957,27 @@ class DataSheetSVG {
|
|
|
5676
5957
|
firstDiv.insertAdjacentHTML('beforeend', `<a xmlns="http://www.w3.org/1999/xhtml" href="${url}" target="_blank" contenteditable="false" style="width: 100%; height: 100%; position: absolute; text-decoration: none;"> </a>`);
|
|
5677
5958
|
}
|
|
5678
5959
|
}
|
|
5960
|
+
else if (element.getAttribute('data-type') === 'interactive' ||
|
|
5961
|
+
element.getAttribute('data-interactive') === 'true') {
|
|
5962
|
+
// Pour les zones interactives : conserver uniquement le rect et lui assigner directement data-href !
|
|
5963
|
+
element.setAttribute('data-href', url);
|
|
5964
|
+
}
|
|
5679
5965
|
else {
|
|
5966
|
+
// Si l'élément est une zone interactive ou à l'intérieur d'une zone interactive, ne jamais l'envelopper dans un <a> !
|
|
5967
|
+
if (element.getAttribute('data-type') === 'interactive' ||
|
|
5968
|
+
element.getAttribute('data-interactive') === 'true' ||
|
|
5969
|
+
element.closest("[data-type='interactive'], [data-interactive='true']")) {
|
|
5970
|
+
return;
|
|
5971
|
+
}
|
|
5972
|
+
// Éviter la duplication si l'élément est déjà une ancre <a> ou dans une ancre <a>
|
|
5973
|
+
if (element.tagName.toLowerCase() === 'a') {
|
|
5974
|
+
element.setAttribute('href', url);
|
|
5975
|
+
return;
|
|
5976
|
+
}
|
|
5977
|
+
if (element.parentElement?.tagName.toLowerCase() === 'a') {
|
|
5978
|
+
element.parentElement.setAttribute('href', url);
|
|
5979
|
+
return;
|
|
5980
|
+
}
|
|
5680
5981
|
let svgNS = 'http://www.w3.org/2000/svg';
|
|
5681
5982
|
//let xlinkNS = "http://www.w3.org/1999/xlink";
|
|
5682
5983
|
let link = document.createElementNS(svgNS, 'a');
|
|
@@ -5762,12 +6063,9 @@ class DataSheetSVG {
|
|
|
5762
6063
|
return String(val.fr).toLowerCase().trim();
|
|
5763
6064
|
return String(val).toLowerCase().trim();
|
|
5764
6065
|
};
|
|
5765
|
-
const matchedAttr = allAttrs.find((a) => (a &&
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
(a &&
|
|
5769
|
-
a.attributeGuid &&
|
|
5770
|
-
getAttrString(a.attributeGuid) === normAttr) ||
|
|
6066
|
+
const matchedAttr = allAttrs.find((a) => (a &&
|
|
6067
|
+
a.attributeGuid &&
|
|
6068
|
+
getAttrString(a.attributeGuid) === normAttr) ||
|
|
5771
6069
|
(a &&
|
|
5772
6070
|
a.attributeName &&
|
|
5773
6071
|
getAttrString(a.attributeName) === normAttr) ||
|
|
@@ -5817,6 +6115,13 @@ class DataSheetSVG {
|
|
|
5817
6115
|
}
|
|
5818
6116
|
});
|
|
5819
6117
|
this.resolveAnchors(domSVG, originalTpl);
|
|
6118
|
+
// Masquage visuel des zones interactives pour le rendu final / prévisualisation
|
|
6119
|
+
if (!keepAttributes) {
|
|
6120
|
+
const interactiveToHide = domSVG.querySelectorAll("rect[data-type='interactive'], rect[data-interactive='true'], [data-type='interactive'], [data-interactive='true']");
|
|
6121
|
+
interactiveToHide.forEach((el) => {
|
|
6122
|
+
el.setAttribute('opacity', '0');
|
|
6123
|
+
});
|
|
6124
|
+
}
|
|
5820
6125
|
let gabaritSvgUpdated = domSVG.documentElement.innerHTML;
|
|
5821
6126
|
// Supprimer les balises inutiles (<html>, <body>, <head>)
|
|
5822
6127
|
gabaritSvgUpdated = gabaritSvgUpdated.replace(/<html.*?>|<\/html>/g, '');
|
|
@@ -7613,8 +7918,17 @@ class DataSheetPublication {
|
|
|
7613
7918
|
throw new Error('DataSheet instance is required to create a DataSheetSVG');
|
|
7614
7919
|
}
|
|
7615
7920
|
this.DataSheet = dataSheet;
|
|
7921
|
+
if (dataSheet.language) {
|
|
7922
|
+
this.languagePreviewSelected = dataSheet.language;
|
|
7923
|
+
}
|
|
7616
7924
|
this.DataSheetSVG = dataSheetSVG;
|
|
7617
7925
|
this.publication = publication;
|
|
7926
|
+
if (dataSheetSVG) {
|
|
7927
|
+
dataSheetSVG.publication = publication;
|
|
7928
|
+
}
|
|
7929
|
+
if (dataSheet) {
|
|
7930
|
+
dataSheet.publication = publication;
|
|
7931
|
+
}
|
|
7618
7932
|
this.sectionActiveObject = sectionActiveObject;
|
|
7619
7933
|
this.skusSection = skusSection;
|
|
7620
7934
|
}
|
|
@@ -8336,26 +8650,46 @@ class DataSheetController {
|
|
|
8336
8650
|
// Prépare (= 25% of progress : attributes + fields + prices + gabarits + backgrounds each one : 5%)
|
|
8337
8651
|
dataSheet.attributes = json.attributes;
|
|
8338
8652
|
if (!dataSheet.attributes || dataSheet.attributes.length === 0) {
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8653
|
+
try {
|
|
8654
|
+
let fetched = [];
|
|
8655
|
+
try {
|
|
8656
|
+
const res = await this._attributes
|
|
8657
|
+
.getAttributesSimplified('skus,publications')
|
|
8658
|
+
.toPromise();
|
|
8659
|
+
fetched =
|
|
8660
|
+
res?.Attributes ||
|
|
8661
|
+
res?.attributes ||
|
|
8662
|
+
(Array.isArray(res) ? res : []);
|
|
8663
|
+
}
|
|
8664
|
+
catch (_) { }
|
|
8665
|
+
if (!fetched || fetched.length === 0) {
|
|
8666
|
+
// Fallback to querying full skus and publications attributes
|
|
8667
|
+
const [resSkus, resPubs] = await Promise.all([
|
|
8668
|
+
this._attributes.getAttributesByGroupsType('', 'skus').toPromise(),
|
|
8669
|
+
this._attributes
|
|
8670
|
+
.getAttributesByGroupsType('', 'publications')
|
|
8671
|
+
.toPromise(),
|
|
8672
|
+
]);
|
|
8673
|
+
const skusList = resSkus?.Attributes ||
|
|
8674
|
+
resSkus?.attributes ||
|
|
8675
|
+
(Array.isArray(resSkus) ? resSkus : []);
|
|
8676
|
+
const pubsList = resPubs?.Attributes ||
|
|
8677
|
+
resPubs?.attributes ||
|
|
8678
|
+
(Array.isArray(resPubs) ? resPubs : []);
|
|
8679
|
+
fetched = [...skusList, ...pubsList].map((a) => ({
|
|
8680
|
+
attributeGuid: a.attributeGuid || a.attributeguid,
|
|
8681
|
+
attributeName: a.attributeName || a.attributename,
|
|
8682
|
+
attributeType: a.attributeType || a.attributetype,
|
|
8683
|
+
attributesGroupGuid: a.attributesGroupGuid || a.attributesgroupguid,
|
|
8684
|
+
attributeOptions: a.attributeOptions || a.attributeoptions,
|
|
8685
|
+
}));
|
|
8686
|
+
}
|
|
8687
|
+
dataSheet.attributes = fetched;
|
|
8688
|
+
DataSheetSingleton.getInstance().attributes = fetched;
|
|
8689
|
+
}
|
|
8690
|
+
catch (e) {
|
|
8691
|
+
console.error('Error fetching attributes for generation:', e);
|
|
8692
|
+
}
|
|
8359
8693
|
}
|
|
8360
8694
|
dataSheet.progress += 5;
|
|
8361
8695
|
dataSheet.fields = json.fields;
|
|
@@ -8523,13 +8857,21 @@ class DataSheetController {
|
|
|
8523
8857
|
dataSheet.progress = 25;
|
|
8524
8858
|
let files = [];
|
|
8525
8859
|
switch (source) {
|
|
8526
|
-
case 1: // All SKUS
|
|
8860
|
+
case 1: // All SKUS or Selected SKUS Batch
|
|
8527
8861
|
//console.log('[PDF] Fetching SKU list for global batch generation...');
|
|
8528
8862
|
try {
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
.
|
|
8532
|
-
|
|
8863
|
+
let skuGuids = [];
|
|
8864
|
+
if (Array.isArray(json.sourceGuid) &&
|
|
8865
|
+
json.sourceGuid.length > 0 &&
|
|
8866
|
+
json.sourceGuid[0] !== 'all') {
|
|
8867
|
+
skuGuids = json.sourceGuid;
|
|
8868
|
+
}
|
|
8869
|
+
else {
|
|
8870
|
+
const res = await this._generationService
|
|
8871
|
+
.getSkusDatas(json.language, json.attributeSkuGuid, templateGuid, json.onlyNeedRegeneration)
|
|
8872
|
+
.toPromise();
|
|
8873
|
+
skuGuids = res.skuGuids || [];
|
|
8874
|
+
}
|
|
8533
8875
|
const concurrencyLimit = 5;
|
|
8534
8876
|
let currentIndex = 0;
|
|
8535
8877
|
const executeTask = async () => {
|
|
@@ -9100,7 +9442,10 @@ function calculateBlockDimension(pageSize, pageMarginStart, pageMarginEnd, gap,
|
|
|
9100
9442
|
function simulateProductBlocks(pageWidth, pageHeight, pageMarginTop, pageMarginBottom, pageMarginLeft, pageMarginRight, blockWidth, blockHeight, verticalGap, horizontalGap) {
|
|
9101
9443
|
const innerWidth = pageWidth - pageMarginLeft - pageMarginRight;
|
|
9102
9444
|
const innerHeight = pageHeight - pageMarginTop - pageMarginBottom;
|
|
9103
|
-
if (innerWidth <= 0 ||
|
|
9445
|
+
if (innerWidth <= 0 ||
|
|
9446
|
+
innerHeight <= 0 ||
|
|
9447
|
+
blockWidth <= 0 ||
|
|
9448
|
+
blockHeight <= 0) {
|
|
9104
9449
|
return { blocksPerRow: 0, blocksPerColumn: 0, blocks: [] };
|
|
9105
9450
|
}
|
|
9106
9451
|
// Calculate maximum columns and rows that can fit physically using pure mathematical formulas.
|