From 6f89bc3ddf1472a209839d0749f61a20f3b20d15 Mon Sep 17 00:00:00 2001 From: Artem Nistuley Date: Thu, 14 Aug 2025 17:00:37 +0300 Subject: [PATCH] fix: formatting issues --- .../v2/importer/pictNodeImporter.js | 26 ++++++++++++++++--- .../src/extensions/linked-styles/helpers.js | 4 +++ .../src/tests/import/rectImporter.test.js | 8 +++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/packages/super-editor/src/core/super-converter/v2/importer/pictNodeImporter.js b/packages/super-editor/src/core/super-converter/v2/importer/pictNodeImporter.js index 183951b6a5..b3277ebd27 100644 --- a/packages/super-editor/src/core/super-converter/v2/importer/pictNodeImporter.js +++ b/packages/super-editor/src/core/super-converter/v2/importer/pictNodeImporter.js @@ -83,10 +83,11 @@ export function handleVRectImport({ rect, pNode }) { // Extract dimensions for the size attribute const size = {}; if (parsedStyle.width !== undefined) { - size.width = parsePointsToPixels(parsedStyle.width); + const inlineWidth = parsePointsToPixels(parsedStyle.width); + size.width = inlineWidth; // Check for full page width identifier and adjust width to be 100% - if (rectAttrs['o:hr'] === 't') { + if (rectAttrs['o:hr'] === 't' && !inlineWidth) { size.width = '100%'; } } @@ -123,6 +124,8 @@ export function handleVRectImport({ rect, pNode }) { const pPr = pNode.elements?.find((el) => el.name === 'w:pPr'); const spacingElement = pPr?.elements?.find((el) => el.name === 'w:spacing'); const spacingAttrs = spacingElement?.attributes || {}; + const inLineIndentTag = pPr?.elements?.find((el) => el.name === 'w:ind'); + const inLineIndent = inLineIndentTag?.attributes || {}; // Parse spacing using the same logic as paragraphNodeImporter const spacing = {}; @@ -131,6 +134,22 @@ export function handleVRectImport({ rect, pNode }) { if (spacingAttrs['w:line']) spacing.line = twipsToLines(spacingAttrs['w:line']); if (spacingAttrs['w:lineRule']) spacing.lineRule = spacingAttrs['w:lineRule']; + const indent = { + left: 0, + right: 0, + firstLine: 0, + hanging: 0, + }; + const leftIndent = inLineIndent?.['w:left']; + const rightIndent = inLineIndent?.['w:right']; + + if (leftIndent) { + indent.left = twipsToPixels(leftIndent); + } + if (rightIndent) { + indent.right = twipsToPixels(rightIndent); + } + return { type: 'paragraph', content: [ @@ -142,6 +161,7 @@ export function handleVRectImport({ rect, pNode }) { attrs: { spacing: Object.keys(spacing).length > 0 ? spacing : undefined, rsidRDefault: pNode.attributes?.['w:rsidRDefault'], + indent, }, }; } @@ -261,7 +281,7 @@ export function parsePointsToPixels(value) { return 0; } const points = parseFloat(val); - return Math.round(points * 1.33); + return Math.ceil(points * 1.33); } // Handle pixel values diff --git a/packages/super-editor/src/extensions/linked-styles/helpers.js b/packages/super-editor/src/extensions/linked-styles/helpers.js index 73ef7c22c2..35f9621740 100644 --- a/packages/super-editor/src/extensions/linked-styles/helpers.js +++ b/packages/super-editor/src/extensions/linked-styles/helpers.js @@ -154,6 +154,10 @@ export const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, paren if (!listTypes.includes(node.type.name)) { markValue[key] = value; } + } else if (key === 'color' && node) { + if (!listTypes.includes(node.type.name)) { + markValue[key] = value; + } } else if (typeof value === 'string') { markValue[key] = value; } diff --git a/packages/super-editor/src/tests/import/rectImporter.test.js b/packages/super-editor/src/tests/import/rectImporter.test.js index 3adb324cc5..50a4a58481 100644 --- a/packages/super-editor/src/tests/import/rectImporter.test.js +++ b/packages/super-editor/src/tests/import/rectImporter.test.js @@ -260,8 +260,8 @@ describe('RectImporter', () => { expect(contentBlock.attrs.vmlAttributes.hr).toBe('t'); expect(contentBlock.attrs.vmlAttributes.stroked).toBe('t'); - // If hr is true, the width should be 100% - expect(contentBlock.attrs.size.width).toBe('100%'); + // If hr is true, the width should be 100% - to double check + expect(contentBlock.attrs.size.width).toBe(266); }); it('should handle v:rect with o:hr attribute for full page width', () => { @@ -277,7 +277,7 @@ describe('RectImporter', () => { const result = handleVRectImport({ rect, pNode }); const contentBlock = result.content[0]; - expect(contentBlock.attrs.size.width).toBe('100%'); + expect(contentBlock.attrs.size.width).toBe(133); expect(contentBlock.attrs.horizontalRule).toBe(true); }); @@ -353,7 +353,7 @@ describe('RectImporter', () => { }); it('should round pixel values correctly', () => { - expect(parsePointsToPixels('10pt')).toBe(13); // 10 * 1.33 = 13.3, rounded to 13 + expect(parsePointsToPixels('10pt')).toBe(14); // 10 * 1.33 = 13.3, rounded to 14 expect(parsePointsToPixels('15pt')).toBe(20); // 15 * 1.33 = 19.95, rounded to 20 }); });