Skip to content
Closed
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
@@ -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';
Expand Down Expand Up @@ -178,17 +178,26 @@ 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 = {
...parNode,
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),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,18 @@ 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) {
if (!schemaNode.attrs.paragraphProperties) schemaNode.attrs.paragraphProperties = {};
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);

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const LinkedStyles = Extension.create({
tr.setNodeMarkup(pos, undefined, {
...paragraphNode.attrs,
styleId: style.id,

});

},
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions packages/super-editor/src/extensions/paragraph/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
121 changes: 45 additions & 76 deletions packages/super-editor/src/tests/import/listImporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ describe('custom nested list tests', () => {
type: 'paragraph',
attrs: {
rsidRDefault: '007B64C8',
textAlign: 'both'
textAlign: 'both',
hasParentIndent: true,
hasParentSpacing: false,
},
content: [
{
Expand All @@ -328,7 +330,9 @@ describe('custom nested list tests', () => {
type: 'paragraph',
attrs: {
rsidRDefault: '007B64C8',
textAlign: 'both'
textAlign: 'both',
hasParentIndent: true,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -641,7 +635,9 @@ describe('custom nested list tests', () => {
type: 'paragraph',
attrs: {
rsidRDefault: '007B64C8',
textAlign: 'both'
textAlign: 'both',
hasParentIndent: true,
hasParentSpacing: false,
},
content: [
{
Expand All @@ -665,7 +661,9 @@ describe('custom nested list tests', () => {
type: 'paragraph',
attrs: {
rsidRDefault: '007B64C8',
textAlign: null
textAlign: null,
hasParentIndent: true,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1168,7 +1156,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '009F090C',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -1199,7 +1189,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '006B7646',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1411,7 +1393,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '009F090C',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand All @@ -1436,7 +1420,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '009F090C',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1645,7 +1621,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '009F090C',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand All @@ -1670,7 +1648,9 @@ describe('custom nested list tests', () => {
attrs: {
rsidRDefault: '009F090C',
styleId: 'ListParagraph',
textAlign: null
textAlign: null,
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1765,6 +1740,8 @@ describe('custom nested list tests', () => {
rsidRDefault: '009F090C',
textAlign: null,
styleId: 'ListParagraph',
hasParentIndent: false,
hasParentSpacing: false,
},
content: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -2203,6 +2170,8 @@ describe('custom nested list tests', () => {
type: 'paragraph',
attrs: {
rsidRDefault: '00B266A8',
hasParentIndent: false,
hasParentSpacing: true,
textAlign: 'both'
},
content: [
Expand Down
Loading
Loading