Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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%';
}
}
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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: [
Expand All @@ -142,6 +161,7 @@ export function handleVRectImport({ rect, pNode }) {
attrs: {
spacing: Object.keys(spacing).length > 0 ? spacing : undefined,
rsidRDefault: pNode.attributes?.['w:rsidRDefault'],
indent,
},
};
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/super-editor/src/extensions/linked-styles/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/super-editor/src/tests/import/rectImporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
});

Expand Down Expand Up @@ -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
});
});
Expand Down
Loading