Skip to content

Commit e9367ce

Browse files
committed
fix: ooxml issues
1 parent 3c02b71 commit e9367ce

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

packages/super-editor/src/core/super-converter/v3/handlers/wp/helpers/chart-helpers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function parseChartXml(chartXml) {
158158

159159
const { element: chartTypeEl, chartType } = chartTypeEntry;
160160

161-
const subType = getAttr(chartTypeEl, 'val') || extractGrouping(chartTypeEl);
161+
const subType = extractGrouping(chartTypeEl);
162162
const barDirection = extractBarDirection(chartTypeEl);
163163
const series = parseSeries(chartTypeEl, chartType);
164164
const categoryAxis = parseAxis(plotArea, 'c:catAx');
@@ -398,7 +398,7 @@ function parseLegendPosition(chart) {
398398

399399
/**
400400
* Parse chart style ID from chartSpace.
401-
* Checks mc:AlternateContent for c14:style, then falls back to c:style.
401+
* Checks mc:AlternateContent for c14:style, then mc:Fallback c:style, then direct c:style.
402402
* @param {Object} chartSpace - c:chartSpace element
403403
* @returns {number|undefined}
404404
*/
@@ -410,6 +410,12 @@ function parseStyleId(chartSpace) {
410410
const c14Style = findChild(choice, 'c14:style');
411411
const val = getAttr(c14Style, 'val');
412412
if (val != null) return Number(val);
413+
414+
// Fallback branch for consumers that do not support c14
415+
const fallback = findChild(altContent, 'mc:Fallback');
416+
const fallbackStyle = findChild(fallback, 'c:style');
417+
const fallbackVal = getAttr(fallbackStyle, 'val');
418+
if (fallbackVal != null) return Number(fallbackVal);
413419
}
414420

415421
// Fallback to c:style

packages/super-editor/src/core/super-converter/v3/handlers/wp/helpers/chart-helpers.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,38 @@ describe('chart-helpers', () => {
230230
},
231231
{
232232
name: 'c:style',
233-
attributes: { val: '102' },
233+
attributes: { val: '2' },
234234
},
235235
],
236236
});
237237

238+
const makeBarChartXmlWithAlternateContentStyle = ({ choiceStyle, fallbackStyle }) => {
239+
const xml = makeBarChartXml();
240+
xml.elements = xml.elements.filter((el) => el.name !== 'c:style');
241+
242+
const altContent = {
243+
name: 'mc:AlternateContent',
244+
elements: [
245+
{
246+
name: 'mc:Choice',
247+
attributes: { Requires: 'c14' },
248+
elements: choiceStyle != null ? [{ name: 'c14:style', attributes: { val: String(choiceStyle) } }] : [],
249+
},
250+
...(fallbackStyle != null
251+
? [
252+
{
253+
name: 'mc:Fallback',
254+
elements: [{ name: 'c:style', attributes: { val: String(fallbackStyle) } }],
255+
},
256+
]
257+
: []),
258+
],
259+
};
260+
261+
xml.elements.unshift(altContent);
262+
return xml;
263+
};
264+
238265
it('parses a bar chart with series, categories, and values', () => {
239266
const result = parseChartXml(makeBarChartXml());
240267

@@ -257,9 +284,19 @@ describe('chart-helpers', () => {
257284

258285
it('parses style ID', () => {
259286
const result = parseChartXml(makeBarChartXml());
287+
expect(result.styleId).toBe(2);
288+
});
289+
290+
it('prefers c14 style in mc:AlternateContent when present', () => {
291+
const result = parseChartXml(makeBarChartXmlWithAlternateContentStyle({ choiceStyle: 102, fallbackStyle: 2 }));
260292
expect(result.styleId).toBe(102);
261293
});
262294

295+
it('falls back to mc:Fallback c:style when c14 style is missing', () => {
296+
const result = parseChartXml(makeBarChartXmlWithAlternateContentStyle({ choiceStyle: null, fallbackStyle: 3 }));
297+
expect(result.styleId).toBe(3);
298+
});
299+
263300
it('parses category axis orientation', () => {
264301
const result = parseChartXml(makeBarChartXml());
265302
expect(result.categoryAxis).toEqual({ orientation: 'minMax' });

0 commit comments

Comments
 (0)