Skip to content

Commit 1375a21

Browse files
committed
Fixes for list item linked styles
1 parent 0c81f8e commit 1375a21

6 files changed

Lines changed: 69 additions & 99 deletions

File tree

packages/super-editor/src/core/super-converter/v2/importer/listImporter.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { carbonCopy } from '../../../utilities/carbonCopy.js';
22
import { hasTextNode, parseProperties } from './importerHelpers.js';
3-
import { preProcessNodesForFldChar, getParagraphSpacing } from './paragraphNodeImporter.js';
3+
import { preProcessNodesForFldChar, getParagraphSpacing, getParagraphIndent } from './paragraphNodeImporter.js';
44
import { mergeTextNodes } from './mergeTextNodes.js';
55
import { ErrorWithDetails } from '../../../helpers/ErrorWithDetails.js';
66
import { twipsToInches, twipsToPixels, twipsToLines } from '../../helpers.js';
@@ -178,17 +178,26 @@ function handleListNodes({
178178

179179
let parNode = {
180180
type: 'paragraph',
181-
content: nodeListHandler.handler({ ...params, nodes: [ attributes.paragraphProperties, ...elements ] })?.filter((n) => n),
181+
content: nodeListHandler.handler({ ...params, nodes: [ ...elements ] })?.filter((n) => n),
182182
};
183-
183+
184+
const parIndent = getParagraphIndent({
185+
elements: [attributes.paragraphProperties]
186+
}, docx, styleId);
187+
const parSpacing = getParagraphSpacing({
188+
elements: [attributes.paragraphProperties]
189+
}, docx, styleId);
190+
184191
// Normalize text nodes.
185192
if (parNode.content) {
186193
parNode = {
187194
...parNode,
188195
attrs: {
189196
textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
190197
rsidRDefault: attributes?.['w:rsidRDefault'] || null,
191-
styleId,
198+
hasParentIndent: Object.keys(parIndent).length > 0,
199+
hasParentSpacing: Object.keys(parSpacing).length > 0,
200+
...(styleId && { styleId })
192201
},
193202
content: mergeTextNodes(parNode.content),
194203
};

packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,12 @@ export const handleParagraphNode = (params) => {
134134
content: mergeTextNodes(schemaNode.content),
135135
};
136136
}
137-
137+
138138
return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
139139
};
140140

141141
export const getParagraphIndent = (node, docx, styleId = '') => {
142-
const indent = {
143-
left: 0,
144-
right: 0,
145-
firstLine: 0,
146-
hanging: 0,
147-
textIndent: 0,
148-
};
142+
const indent = {};
149143

150144
const { indent: pDefaultIndent = {} } = getDefaultParagraphStyle(docx, styleId);
151145

@@ -182,12 +176,7 @@ export const getParagraphIndent = (node, docx, styleId = '') => {
182176

183177
export const getParagraphSpacing = (node, docx, styleId = '', marks = []) => {
184178
// Check if we have default paragraph styles to override
185-
const spacing = {
186-
lineSpaceAfter: 0,
187-
lineSpaceBefore: 0,
188-
line: 0,
189-
lineRule: null,
190-
}
179+
const spacing = {};
191180

192181
const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
193182
let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;

packages/super-editor/src/extensions/linked-styles/linked-styles.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const LinkedStyles = Extension.create({
3434
tr.setNodeMarkup(pos, undefined, {
3535
...paragraphNode.attrs,
3636
styleId: style.id,
37+
3738
});
3839

3940
},
@@ -144,8 +145,8 @@ export const generateLinkedStyleString = (linkedStyle, node, parent, includeSpac
144145

145146
// Check if this node has the expected mark. If yes, we are not overriding it
146147
const mark = flattenedMarks.find((n) => n.key === key);
147-
const hasParentIndent = Object.keys(parent?.attrs.indent || {});
148-
const hasParentSpacing = Object.keys(parent?.attrs.spacing || {});
148+
const hasParentIndent = Object.keys(parent?.attrs.indent || {}).length > 0 || parent?.attrs.hasParentIndent;
149+
const hasParentSpacing = Object.keys(parent?.attrs.spacing || {}).length > 0 || parent?.attrs.hasParentSpacing;
149150

150151
// If no mark already in the node, we override the style
151152
if (!mark) {

packages/super-editor/src/extensions/paragraph/paragraph.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export const Paragraph = Node.create({
8888
keepNext: { rendered: false },
8989
paragraphProperties: { rendered: false },
9090
dropcap: { rendered: false },
91+
hasParentIndent: { rendered: false },
92+
hasParentSpacing: { rendered: false },
9193
};
9294
},
9395

packages/super-editor/src/tests/import/listImporter.test.js

Lines changed: 45 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ describe('custom nested list tests', () => {
304304
type: 'paragraph',
305305
attrs: {
306306
rsidRDefault: '007B64C8',
307-
textAlign: 'both'
307+
textAlign: 'both',
308+
hasParentIndent: true,
309+
hasParentSpacing: false,
308310
},
309311
content: [
310312
{
@@ -328,7 +330,9 @@ describe('custom nested list tests', () => {
328330
type: 'paragraph',
329331
attrs: {
330332
rsidRDefault: '007B64C8',
331-
textAlign: 'both'
333+
textAlign: 'both',
334+
hasParentIndent: true,
335+
hasParentSpacing: false,
332336
},
333337
content: [
334338
{
@@ -437,12 +441,7 @@ describe('custom nested list tests', () => {
437441
indent: { right: -8 },
438442
listLevel: [],
439443
listNumberingType: 'bullet',
440-
spacing: {
441-
line: 0,
442-
lineRule: null,
443-
lineSpaceAfter: 0,
444-
lineSpaceBefore: 0,
445-
},
444+
spacing: {},
446445
attributes: {
447446
parentAttributes: {
448447
'w14:paraId': '057544FE',
@@ -574,12 +573,7 @@ describe('custom nested list tests', () => {
574573
indent: { right: -8 },
575574
listLevel: [1],
576575
listNumberingType: 'decimal',
577-
spacing: {
578-
line: 0,
579-
lineRule: null,
580-
lineSpaceAfter: 0,
581-
lineSpaceBefore: 0,
582-
},
576+
spacing: {},
583577
attributes: {
584578
parentAttributes: {
585579
'w14:paraId': '3947758C',
@@ -641,7 +635,9 @@ describe('custom nested list tests', () => {
641635
type: 'paragraph',
642636
attrs: {
643637
rsidRDefault: '007B64C8',
644-
textAlign: 'both'
638+
textAlign: 'both',
639+
hasParentIndent: true,
640+
hasParentSpacing: false,
645641
},
646642
content: [
647643
{
@@ -665,7 +661,9 @@ describe('custom nested list tests', () => {
665661
type: 'paragraph',
666662
attrs: {
667663
rsidRDefault: '007B64C8',
668-
textAlign: null
664+
textAlign: null,
665+
hasParentIndent: true,
666+
hasParentSpacing: false,
669667
},
670668
content: [
671669
{
@@ -698,12 +696,7 @@ describe('custom nested list tests', () => {
698696
indent: { right: -8 },
699697
listLevel: [],
700698
listNumberingType: 'bullet',
701-
spacing: {
702-
line: 0,
703-
lineRule: null,
704-
lineSpaceAfter: 0,
705-
lineSpaceBefore: 0,
706-
},
699+
spacing: {},
707700
attributes: {
708701
parentAttributes: {
709702
'w14:paraId': '437AE2E1',
@@ -855,12 +848,7 @@ describe('custom nested list tests', () => {
855848
indent: { right: -8 },
856849
listLevel: [2],
857850
listNumberingType: 'decimal',
858-
spacing: {
859-
line: 0,
860-
lineRule: null,
861-
lineSpaceAfter: 0,
862-
lineSpaceBefore: 0,
863-
},
851+
spacing: {},
864852
attributes: {
865853
parentAttributes: {
866854
'w14:paraId': '1F70BFCD',
@@ -1168,7 +1156,9 @@ describe('custom nested list tests', () => {
11681156
attrs: {
11691157
rsidRDefault: '009F090C',
11701158
styleId: 'ListParagraph',
1171-
textAlign: null
1159+
textAlign: null,
1160+
hasParentIndent: false,
1161+
hasParentSpacing: false,
11721162
},
11731163
content: [
11741164
{
@@ -1199,7 +1189,9 @@ describe('custom nested list tests', () => {
11991189
attrs: {
12001190
rsidRDefault: '006B7646',
12011191
styleId: 'ListParagraph',
1202-
textAlign: null
1192+
textAlign: null,
1193+
hasParentIndent: false,
1194+
hasParentSpacing: false,
12031195
},
12041196
content: [
12051197
{
@@ -1233,12 +1225,7 @@ describe('custom nested list tests', () => {
12331225
lvlJc: undefined,
12341226
listLevel: [],
12351227
listNumberingType: 'bullet',
1236-
spacing: {
1237-
line: 0,
1238-
lineRule: null,
1239-
lineSpaceAfter: 0,
1240-
lineSpaceBefore: 0,
1241-
},
1228+
spacing: {},
12421229
attributes: {
12431230
parentAttributes: {
12441231
'w14:paraId': '2F6FAED3',
@@ -1350,12 +1337,7 @@ describe('custom nested list tests', () => {
13501337
lvlJc: undefined,
13511338
listLevel: [1],
13521339
listNumberingType: 'decimal',
1353-
spacing: {
1354-
line: 0,
1355-
lineRule: null,
1356-
lineSpaceAfter: 0,
1357-
lineSpaceBefore: 0,
1358-
},
1340+
spacing: {},
13591341
attributes: {
13601342
parentAttributes: {
13611343
'w14:paraId': '2D072E4D',
@@ -1411,7 +1393,9 @@ describe('custom nested list tests', () => {
14111393
attrs: {
14121394
rsidRDefault: '009F090C',
14131395
styleId: 'ListParagraph',
1414-
textAlign: null
1396+
textAlign: null,
1397+
hasParentIndent: false,
1398+
hasParentSpacing: false,
14151399
},
14161400
content: [
14171401
{
@@ -1436,7 +1420,9 @@ describe('custom nested list tests', () => {
14361420
attrs: {
14371421
rsidRDefault: '009F090C',
14381422
styleId: 'ListParagraph',
1439-
textAlign: null
1423+
textAlign: null,
1424+
hasParentIndent: false,
1425+
hasParentSpacing: false,
14401426
},
14411427
content: [
14421428
{
@@ -1470,12 +1456,7 @@ describe('custom nested list tests', () => {
14701456
lvlJc: undefined,
14711457
listLevel: [],
14721458
listNumberingType: 'bullet',
1473-
spacing: {
1474-
line: 0,
1475-
lineRule: null,
1476-
lineSpaceAfter: 0,
1477-
lineSpaceBefore: 0,
1478-
},
1459+
spacing: {},
14791460
attributes: {
14801461
parentAttributes: {
14811462
'w14:paraId': '2DBCC378',
@@ -1585,12 +1566,7 @@ describe('custom nested list tests', () => {
15851566
lvlJc: undefined,
15861567
listLevel: [2],
15871568
listNumberingType: 'decimal',
1588-
spacing: {
1589-
line: 0,
1590-
lineRule: null,
1591-
lineSpaceAfter: 0,
1592-
lineSpaceBefore: 0,
1593-
},
1569+
spacing: {},
15941570
attributes: {
15951571
parentAttributes: {
15961572
'w14:paraId': '45FC6897',
@@ -1645,7 +1621,9 @@ describe('custom nested list tests', () => {
16451621
attrs: {
16461622
rsidRDefault: '009F090C',
16471623
styleId: 'ListParagraph',
1648-
textAlign: null
1624+
textAlign: null,
1625+
hasParentIndent: false,
1626+
hasParentSpacing: false,
16491627
},
16501628
content: [
16511629
{
@@ -1670,7 +1648,9 @@ describe('custom nested list tests', () => {
16701648
attrs: {
16711649
rsidRDefault: '009F090C',
16721650
styleId: 'ListParagraph',
1673-
textAlign: null
1651+
textAlign: null,
1652+
hasParentIndent: false,
1653+
hasParentSpacing: false,
16741654
},
16751655
content: [
16761656
{
@@ -1704,12 +1684,7 @@ describe('custom nested list tests', () => {
17041684
lvlJc: undefined,
17051685
listLevel: [],
17061686
listNumberingType: 'bullet',
1707-
spacing: {
1708-
line: 0,
1709-
lineRule: null,
1710-
lineSpaceAfter: 0,
1711-
lineSpaceBefore: 0,
1712-
},
1687+
spacing: {},
17131688
attributes: {
17141689
parentAttributes: {
17151690
'w14:paraId': '4F17D13D',
@@ -1765,6 +1740,8 @@ describe('custom nested list tests', () => {
17651740
rsidRDefault: '009F090C',
17661741
textAlign: null,
17671742
styleId: 'ListParagraph',
1743+
hasParentIndent: false,
1744+
hasParentSpacing: false,
17681745
},
17691746
content: [
17701747
{
@@ -1798,12 +1775,7 @@ describe('custom nested list tests', () => {
17981775
lvlJc: undefined,
17991776
listLevel: [],
18001777
listNumberingType: 'bullet',
1801-
spacing: {
1802-
line: 0,
1803-
lineRule: null,
1804-
lineSpaceAfter: 0,
1805-
lineSpaceBefore: 0,
1806-
},
1778+
spacing: {},
18071779
attributes: {
18081780
parentAttributes: {
18091781
'w14:paraId': '01D254E6',
@@ -1913,12 +1885,7 @@ describe('custom nested list tests', () => {
19131885
lvlJc: undefined,
19141886
listLevel: [3],
19151887
listNumberingType: 'decimal',
1916-
spacing: {
1917-
line: 0,
1918-
lineRule: null,
1919-
lineSpaceAfter: 0,
1920-
lineSpaceBefore: 0,
1921-
},
1888+
spacing: {},
19221889
attributes: {
19231890
parentAttributes: {
19241891
'w14:paraId': '77BFBBFC',
@@ -2203,6 +2170,8 @@ describe('custom nested list tests', () => {
22032170
type: 'paragraph',
22042171
attrs: {
22052172
rsidRDefault: '00B266A8',
2173+
hasParentIndent: false,
2174+
hasParentSpacing: true,
22062175
textAlign: 'both'
22072176
},
22082177
content: [

0 commit comments

Comments
 (0)