wireless-desc-converter 1.0.5 → 1.0.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.
@@ -451,13 +451,7 @@ function buildTextModule(params) {
451
451
  });
452
452
  }
453
453
 
454
- var sampleValues = [];
455
- if (images.length > 0) {
456
- sampleValues.push({
457
- props: [inputField('width'), inputField('url', images[0].url || ''), inputField('height')]
458
- });
459
- }
460
-
454
+ // sample(示意图)字段为可选,不传不报错,不生成可减少不必要字段
461
455
  // 当未传入显式 height 时,根据文本内容自动估算
462
456
  // 淘宝接口要求 textStyle.height 不能为空
463
457
  var textHeight = styles.height;
@@ -493,8 +487,8 @@ function buildTextModule(params) {
493
487
  singleCheckField('enable', 'true'),
494
488
  singleCheckField('countHeight', 'false'),
495
489
  inputField('id', groupId),
496
- { id: 'textStyle', type: 'complex', value: { props: textStyleProps } },
497
- { id: 'sample', type: 'multiComplex', values: sampleValues }
490
+ { id: 'textStyle', type: 'complex', value: { props: textStyleProps } }
491
+ // sample(示意图)不传:官方文档确认为可选字段,缺省不报错
498
492
  ]
499
493
  }
500
494
  };
@@ -693,9 +687,14 @@ async function htmlToWirelessDesc(html, options) {
693
687
  }
694
688
  }
695
689
 
690
+ // 只有在传入 textImage 合图函数时才生成 text 模块。
691
+ // 淘宝接口要求 text_N.images 不能为空,若无合图能力则跳过文字模块。
692
+ var hasTextResolver = typeof options.textImage === 'function';
693
+
696
694
  for (var i = 0; i < segments.length; i++) {
697
695
  var seg = segments[i];
698
696
  if (seg.type === 'text') {
697
+ if (!hasTextResolver) continue; // 无合图能力,跳过文字模块
699
698
  textCounter++;
700
699
  props.push(buildTextModule({ text: seg.content, styles: seg.styles, index: textCounter }));
701
700
  } else if (seg.type === 'image') {
@@ -714,7 +713,7 @@ async function htmlToWirelessDesc(html, options) {
714
713
 
715
714
  // 异步补全:图片尺寸 & 文字合图
716
715
  var hasImageResolver = typeof options.imageSize === 'function';
717
- var hasTextResolver = typeof options.textImage === 'function';
716
+ // hasTextResolver 已在上方声明,不再重复声明
718
717
 
719
718
  if (hasImageResolver || hasTextResolver) {
720
719
  var tasks = [];
@@ -750,8 +749,14 @@ async function htmlToWirelessDesc(html, options) {
750
749
  var images = await options.textImage({ text: text, styles: st, index: idx });
751
750
  if (Array.isArray(images) && images.length) {
752
751
  updateTextImages(mod, images);
752
+ } else {
753
+ var removeIdx = props.indexOf(mod);
754
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
753
755
  }
754
- } catch (e) {}
756
+ } catch (e) {
757
+ var removeIdx = props.indexOf(mod);
758
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
759
+ }
755
760
  })(module, textValue, styles, moduleIndex));
756
761
  }
757
762
  }
@@ -449,13 +449,7 @@ function buildTextModule(params) {
449
449
  });
450
450
  }
451
451
 
452
- var sampleValues = [];
453
- if (images.length > 0) {
454
- sampleValues.push({
455
- props: [inputField('width'), inputField('url', images[0].url || ''), inputField('height')]
456
- });
457
- }
458
-
452
+ // sample(示意图)字段为可选,不传不报错,不生成可减少不必要字段
459
453
  // 当未传入显式 height 时,根据文本内容自动估算
460
454
  // 淘宝接口要求 textStyle.height 不能为空
461
455
  var textHeight = styles.height;
@@ -491,8 +485,8 @@ function buildTextModule(params) {
491
485
  singleCheckField('enable', 'true'),
492
486
  singleCheckField('countHeight', 'false'),
493
487
  inputField('id', groupId),
494
- { id: 'textStyle', type: 'complex', value: { props: textStyleProps } },
495
- { id: 'sample', type: 'multiComplex', values: sampleValues }
488
+ { id: 'textStyle', type: 'complex', value: { props: textStyleProps } }
489
+ // sample(示意图)不传:官方文档确认为可选字段,缺省不报错
496
490
  ]
497
491
  }
498
492
  };
@@ -691,9 +685,14 @@ async function htmlToWirelessDesc(html, options) {
691
685
  }
692
686
  }
693
687
 
688
+ // 只有在传入 textImage 合图函数时才生成 text 模块。
689
+ // 淘宝接口要求 text_N.images 不能为空,若无合图能力则跳过文字模块。
690
+ var hasTextResolver = typeof options.textImage === 'function';
691
+
694
692
  for (var i = 0; i < segments.length; i++) {
695
693
  var seg = segments[i];
696
694
  if (seg.type === 'text') {
695
+ if (!hasTextResolver) continue; // 无合图能力,跳过文字模块
697
696
  textCounter++;
698
697
  props.push(buildTextModule({ text: seg.content, styles: seg.styles, index: textCounter }));
699
698
  } else if (seg.type === 'image') {
@@ -712,7 +711,7 @@ async function htmlToWirelessDesc(html, options) {
712
711
 
713
712
  // 异步补全:图片尺寸 & 文字合图
714
713
  var hasImageResolver = typeof options.imageSize === 'function';
715
- var hasTextResolver = typeof options.textImage === 'function';
714
+ // hasTextResolver 已在上方声明,不再重复声明
716
715
 
717
716
  if (hasImageResolver || hasTextResolver) {
718
717
  var tasks = [];
@@ -748,8 +747,14 @@ async function htmlToWirelessDesc(html, options) {
748
747
  var images = await options.textImage({ text: text, styles: st, index: idx });
749
748
  if (Array.isArray(images) && images.length) {
750
749
  updateTextImages(mod, images);
750
+ } else {
751
+ var removeIdx = props.indexOf(mod);
752
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
751
753
  }
752
- } catch (e) {}
754
+ } catch (e) {
755
+ var removeIdx = props.indexOf(mod);
756
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
757
+ }
753
758
  })(module, textValue, styles, moduleIndex));
754
759
  }
755
760
  }
@@ -455,13 +455,7 @@
455
455
  });
456
456
  }
457
457
 
458
- var sampleValues = [];
459
- if (images.length > 0) {
460
- sampleValues.push({
461
- props: [inputField('width'), inputField('url', images[0].url || ''), inputField('height')]
462
- });
463
- }
464
-
458
+ // sample(示意图)字段为可选,不传不报错,不生成可减少不必要字段
465
459
  // 当未传入显式 height 时,根据文本内容自动估算
466
460
  // 淘宝接口要求 textStyle.height 不能为空
467
461
  var textHeight = styles.height;
@@ -497,8 +491,8 @@
497
491
  singleCheckField('enable', 'true'),
498
492
  singleCheckField('countHeight', 'false'),
499
493
  inputField('id', groupId),
500
- { id: 'textStyle', type: 'complex', value: { props: textStyleProps } },
501
- { id: 'sample', type: 'multiComplex', values: sampleValues }
494
+ { id: 'textStyle', type: 'complex', value: { props: textStyleProps } }
495
+ // sample(示意图)不传:官方文档确认为可选字段,缺省不报错
502
496
  ]
503
497
  }
504
498
  };
@@ -697,9 +691,14 @@
697
691
  }
698
692
  }
699
693
 
694
+ // 只有在传入 textImage 合图函数时才生成 text 模块。
695
+ // 淘宝接口要求 text_N.images 不能为空,若无合图能力则跳过文字模块。
696
+ var hasTextResolver = typeof options.textImage === 'function';
697
+
700
698
  for (var i = 0; i < segments.length; i++) {
701
699
  var seg = segments[i];
702
700
  if (seg.type === 'text') {
701
+ if (!hasTextResolver) continue; // 无合图能力,跳过文字模块
703
702
  textCounter++;
704
703
  props.push(buildTextModule({ text: seg.content, styles: seg.styles, index: textCounter }));
705
704
  } else if (seg.type === 'image') {
@@ -718,7 +717,7 @@
718
717
 
719
718
  // 异步补全:图片尺寸 & 文字合图
720
719
  var hasImageResolver = typeof options.imageSize === 'function';
721
- var hasTextResolver = typeof options.textImage === 'function';
720
+ // hasTextResolver 已在上方声明,不再重复声明
722
721
 
723
722
  if (hasImageResolver || hasTextResolver) {
724
723
  var tasks = [];
@@ -754,8 +753,14 @@
754
753
  var images = await options.textImage({ text: text, styles: st, index: idx });
755
754
  if (Array.isArray(images) && images.length) {
756
755
  updateTextImages(mod, images);
756
+ } else {
757
+ var removeIdx = props.indexOf(mod);
758
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
757
759
  }
758
- } catch (e) {}
760
+ } catch (e) {
761
+ var removeIdx = props.indexOf(mod);
762
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
763
+ }
759
764
  })(module, textValue, styles, moduleIndex));
760
765
  }
761
766
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireless-desc-converter",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "淘宝新版图文编辑器 wirelessDesc 适配工具 - HTML 富文本转换为结构化 JSON",
5
5
  "type": "module",
6
6
  "main": "dist/wireless-desc-converter.umd.js",
package/src/index.js CHANGED
@@ -449,13 +449,7 @@ function buildTextModule(params) {
449
449
  });
450
450
  }
451
451
 
452
- var sampleValues = [];
453
- if (images.length > 0) {
454
- sampleValues.push({
455
- props: [inputField('width'), inputField('url', images[0].url || ''), inputField('height')]
456
- });
457
- }
458
-
452
+ // sample(示意图)字段为可选,不传不报错,不生成可减少不必要字段
459
453
  // 当未传入显式 height 时,根据文本内容自动估算
460
454
  // 淘宝接口要求 textStyle.height 不能为空
461
455
  var textHeight = styles.height;
@@ -491,8 +485,8 @@ function buildTextModule(params) {
491
485
  singleCheckField('enable', 'true'),
492
486
  singleCheckField('countHeight', 'false'),
493
487
  inputField('id', groupId),
494
- { id: 'textStyle', type: 'complex', value: { props: textStyleProps } },
495
- { id: 'sample', type: 'multiComplex', values: sampleValues }
488
+ { id: 'textStyle', type: 'complex', value: { props: textStyleProps } }
489
+ // sample(示意图)不传:官方文档确认为可选字段,缺省不报错
496
490
  ]
497
491
  }
498
492
  };
@@ -691,9 +685,15 @@ async function htmlToWirelessDesc(html, options) {
691
685
  }
692
686
  }
693
687
 
688
+ // 只有在传入 textImage 合图函数时才生成 text 模块。
689
+ // 淘宝接口要求 text_N.images 不能为空,若无合图能力则跳过文字模块,
690
+ // 避免提交时报 "text_N.images值不能为空" 错误。
691
+ var hasTextResolver = typeof options.textImage === 'function';
692
+
694
693
  for (var i = 0; i < segments.length; i++) {
695
694
  var seg = segments[i];
696
695
  if (seg.type === 'text') {
696
+ if (!hasTextResolver) continue; // 无合图能力,跳过文字模块
697
697
  textCounter++;
698
698
  props.push(buildTextModule({ text: seg.content, styles: seg.styles, index: textCounter }));
699
699
  } else if (seg.type === 'image') {
@@ -712,7 +712,6 @@ async function htmlToWirelessDesc(html, options) {
712
712
 
713
713
  // 异步补全:图片尺寸 & 文字合图
714
714
  var hasImageResolver = typeof options.imageSize === 'function';
715
- var hasTextResolver = typeof options.textImage === 'function';
716
715
 
717
716
  if (hasImageResolver || hasTextResolver) {
718
717
  var tasks = [];
@@ -748,8 +747,17 @@ async function htmlToWirelessDesc(html, options) {
748
747
  var images = await options.textImage({ text: text, styles: st, index: idx });
749
748
  if (Array.isArray(images) && images.length) {
750
749
  updateTextImages(mod, images);
750
+ } else {
751
+ // 合图失败或返回空数组 → 将该 text_N 模块从 props 中整体移除
752
+ // 淘宝要求 images 字段必须有实际数据(字段缺失/空数组均报错)
753
+ // 无法合图时唯一合法的处理是不提交该模块
754
+ var removeIdx = props.indexOf(mod);
755
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
751
756
  }
752
- } catch (e) {}
757
+ } catch (e) {
758
+ var removeIdx = props.indexOf(mod);
759
+ if (removeIdx !== -1) props.splice(removeIdx, 1);
760
+ }
753
761
  })(module, textValue, styles, moduleIndex));
754
762
  }
755
763
  }