diff --git a/packages/super-editor/src/core/super-converter/v2/importer/listImporter.js b/packages/super-editor/src/core/super-converter/v2/importer/listImporter.js index 4b9a70f90e..9167ad3fdd 100644 --- a/packages/super-editor/src/core/super-converter/v2/importer/listImporter.js +++ b/packages/super-editor/src/core/super-converter/v2/importer/listImporter.js @@ -1,6 +1,6 @@ import { carbonCopy } from '../../../utilities/carbonCopy.js'; import { hasTextNode, parseProperties } from './importerHelpers.js'; -import { preProcessNodesForFldChar, getParagraphSpacing } from './paragraphNodeImporter.js'; +import { preProcessNodesForFldChar, getParagraphSpacing, getParagraphIndent } from './paragraphNodeImporter.js'; import { mergeTextNodes } from './mergeTextNodes.js'; import { ErrorWithDetails } from '../../../helpers/ErrorWithDetails.js'; import { twipsToInches, twipsToPixels, twipsToLines } from '../../helpers.js'; @@ -178,9 +178,16 @@ function handleListNodes({ let parNode = { type: 'paragraph', - content: nodeListHandler.handler({ ...params, nodes: [ attributes.paragraphProperties, ...elements ] })?.filter((n) => n), + content: nodeListHandler.handler({ ...params, nodes: [ ...elements ] })?.filter((n) => n), }; - + + const parIndent = getParagraphIndent({ + elements: [attributes.paragraphProperties] + }, docx, styleId); + const parSpacing = getParagraphSpacing({ + elements: [attributes.paragraphProperties] + }, docx, styleId); + // Normalize text nodes. if (parNode.content) { parNode = { @@ -188,7 +195,9 @@ function handleListNodes({ attrs: { textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null, rsidRDefault: attributes?.['w:rsidRDefault'] || null, - styleId, + hasParentIndent: Object.keys(parIndent).length > 0, + hasParentSpacing: Object.keys(parSpacing).length > 0, + ...(styleId && { styleId }) }, content: mergeTextNodes(parNode.content), }; diff --git a/packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js b/packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js index 5f66da1725..0b2489a269 100644 --- a/packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js +++ b/packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js @@ -136,7 +136,6 @@ export const handleParagraphNode = (params) => { content: mergeTextNodes(schemaNode.content), }; } - // Pass through this paragraph's sectPr, if any const sectPr = pPr?.elements?.find((el) => el.name === 'w:sectPr'); if (sectPr) { @@ -144,18 +143,11 @@ export const handleParagraphNode = (params) => { schemaNode.attrs.paragraphProperties.sectPr = sectPr; schemaNode.attrs.pageBreakSource = 'sectPr'; }; - return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 }; }; export const getParagraphIndent = (node, docx, styleId = '') => { - const indent = { - left: 0, - right: 0, - firstLine: 0, - hanging: 0, - textIndent: 0, - }; + const indent = {}; const { indent: pDefaultIndent = {} } = getDefaultParagraphStyle(docx, styleId); @@ -192,12 +184,7 @@ export const getParagraphIndent = (node, docx, styleId = '') => { export const getParagraphSpacing = (node, docx, styleId = '', marks = []) => { // Check if we have default paragraph styles to override - const spacing = { - lineSpaceAfter: 0, - lineSpaceBefore: 0, - line: 0, - lineRule: null, - } + const spacing = {}; const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId); let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle; diff --git a/packages/super-editor/src/extensions/linked-styles/linked-styles.js b/packages/super-editor/src/extensions/linked-styles/linked-styles.js index 88b0ee67dd..cf5fe55cf4 100644 --- a/packages/super-editor/src/extensions/linked-styles/linked-styles.js +++ b/packages/super-editor/src/extensions/linked-styles/linked-styles.js @@ -34,6 +34,7 @@ export const LinkedStyles = Extension.create({ tr.setNodeMarkup(pos, undefined, { ...paragraphNode.attrs, styleId: style.id, + }); }, @@ -144,8 +145,8 @@ export const generateLinkedStyleString = (linkedStyle, node, parent, includeSpac // Check if this node has the expected mark. If yes, we are not overriding it const mark = flattenedMarks.find((n) => n.key === key); - const hasParentIndent = Object.keys(parent?.attrs?.indent || {}); - const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {}); + const hasParentIndent = Object.keys(parent?.attrs?.indent || {}).length > 0 || parent?.attrs?.hasParentIndent; + const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {}).length > 0 || parent?.attrs?.hasParentSpacing; // If no mark already in the node, we override the style if (!mark) { diff --git a/packages/super-editor/src/extensions/paragraph/paragraph.js b/packages/super-editor/src/extensions/paragraph/paragraph.js index 40c4434d3f..b9f5f0ac1f 100644 --- a/packages/super-editor/src/extensions/paragraph/paragraph.js +++ b/packages/super-editor/src/extensions/paragraph/paragraph.js @@ -88,6 +88,8 @@ export const Paragraph = Node.create({ keepNext: { rendered: false }, paragraphProperties: { rendered: false }, dropcap: { rendered: false }, + hasParentIndent: { rendered: false }, + hasParentSpacing: { rendered: false }, pageBreakSource: { rendered: false }, justify: { renderDOM: ({ justify }) => { diff --git a/packages/super-editor/src/tests/import/listImporter.test.js b/packages/super-editor/src/tests/import/listImporter.test.js index 255ec77802..f6c8340b4d 100644 --- a/packages/super-editor/src/tests/import/listImporter.test.js +++ b/packages/super-editor/src/tests/import/listImporter.test.js @@ -304,7 +304,9 @@ describe('custom nested list tests', () => { type: 'paragraph', attrs: { rsidRDefault: '007B64C8', - textAlign: 'both' + textAlign: 'both', + hasParentIndent: true, + hasParentSpacing: false, }, content: [ { @@ -328,7 +330,9 @@ describe('custom nested list tests', () => { type: 'paragraph', attrs: { rsidRDefault: '007B64C8', - textAlign: 'both' + textAlign: 'both', + hasParentIndent: true, + hasParentSpacing: false, }, content: [ { @@ -437,12 +441,7 @@ describe('custom nested list tests', () => { indent: { right: -8 }, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '057544FE', @@ -574,12 +573,7 @@ describe('custom nested list tests', () => { indent: { right: -8 }, listLevel: [1], listNumberingType: 'decimal', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '3947758C', @@ -641,7 +635,9 @@ describe('custom nested list tests', () => { type: 'paragraph', attrs: { rsidRDefault: '007B64C8', - textAlign: 'both' + textAlign: 'both', + hasParentIndent: true, + hasParentSpacing: false, }, content: [ { @@ -665,7 +661,9 @@ describe('custom nested list tests', () => { type: 'paragraph', attrs: { rsidRDefault: '007B64C8', - textAlign: null + textAlign: null, + hasParentIndent: true, + hasParentSpacing: false, }, content: [ { @@ -698,12 +696,7 @@ describe('custom nested list tests', () => { indent: { right: -8 }, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '437AE2E1', @@ -855,12 +848,7 @@ describe('custom nested list tests', () => { indent: { right: -8 }, listLevel: [2], listNumberingType: 'decimal', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '1F70BFCD', @@ -1168,7 +1156,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '009F090C', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1199,7 +1189,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '006B7646', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1233,12 +1225,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '2F6FAED3', @@ -1350,12 +1337,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [1], listNumberingType: 'decimal', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '2D072E4D', @@ -1411,7 +1393,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '009F090C', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1436,7 +1420,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '009F090C', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1470,12 +1456,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '2DBCC378', @@ -1585,12 +1566,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [2], listNumberingType: 'decimal', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '45FC6897', @@ -1645,7 +1621,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '009F090C', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1670,7 +1648,9 @@ describe('custom nested list tests', () => { attrs: { rsidRDefault: '009F090C', styleId: 'ListParagraph', - textAlign: null + textAlign: null, + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1704,12 +1684,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '4F17D13D', @@ -1765,6 +1740,8 @@ describe('custom nested list tests', () => { rsidRDefault: '009F090C', textAlign: null, styleId: 'ListParagraph', + hasParentIndent: false, + hasParentSpacing: false, }, content: [ { @@ -1798,12 +1775,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [], listNumberingType: 'bullet', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '01D254E6', @@ -1913,12 +1885,7 @@ describe('custom nested list tests', () => { lvlJc: undefined, listLevel: [3], listNumberingType: 'decimal', - spacing: { - line: 0, - lineRule: null, - lineSpaceAfter: 0, - lineSpaceBefore: 0, - }, + spacing: {}, attributes: { parentAttributes: { 'w14:paraId': '77BFBBFC', @@ -2203,6 +2170,8 @@ describe('custom nested list tests', () => { type: 'paragraph', attrs: { rsidRDefault: '00B266A8', + hasParentIndent: false, + hasParentSpacing: true, textAlign: 'both' }, content: [ diff --git a/packages/super-editor/src/tests/import/paragraphNodeImporter.test.js b/packages/super-editor/src/tests/import/paragraphNodeImporter.test.js index 5b4ec23c62..a8b7992765 100644 --- a/packages/super-editor/src/tests/import/paragraphNodeImporter.test.js +++ b/packages/super-editor/src/tests/import/paragraphNodeImporter.test.js @@ -57,8 +57,8 @@ describe('paragraph tests to check spacing', () => { const { spacing } = attrs; expect(spacing.line).toBe(1.15); - expect(spacing.lineSpaceAfter).toBe(0); - expect(spacing.lineSpaceBefore).toBe(0); + expect(spacing.lineSpaceAfter).toBeUndefined(); + expect(spacing.lineSpaceBefore).toBeUndefined(); }); it('correctly gets spacing around image in p [image_p_spacing]', async () => { @@ -130,7 +130,7 @@ describe('paragraph tests to check spacing', () => { const { attrs } = node; const { spacing } = attrs; expect(spacing.lineSpaceAfter).toBe(11); - expect(spacing.lineSpaceBefore).toBe(0); + expect(spacing.lineSpaceBefore).toBeUndefined(); }); it('correctly gets spacing from styles.xml by related styleId', async () => {