Skip to content

Commit 3799e82

Browse files
authored
DEV-26894 Add height to table row properties (#76)
1 parent 860bc28 commit 3799e82

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

lib/properties/src/table-row-properties.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ export type TableRowProperties = {
2626
* The distance between cells.
2727
*/
2828
cellSpacing?: null | Length;
29+
/**
30+
* The height of the row. Corresponds to `w:trHeight` in OOXML.
31+
*
32+
* - `value`: the height of the row.
33+
* - `rule`: how the height is applied:
34+
* - `'auto'` (default when omitted): the row height is determined by the content.
35+
* - `'atLeast'`: the row height is at least the specified value.
36+
* - `'exact'`: the row height is exactly the specified value regardless of content.
37+
*/
38+
height?: null | {
39+
value: Length;
40+
rule?: null | 'auto' | 'atLeast' | 'exact';
41+
};
2942
/**
3043
* A property used to indicate when a table row property has changed. This will appear as a tracked
3144
* change in Word's track changes feature.
@@ -66,6 +79,10 @@ export function tableRowPropertiesFromNode(
6679
"isHeaderRow": docxml:ct-on-off(./${QNS.w}tblHeader),
6780
"isUnsplittable": docxml:ct-on-off(./${QNS.w}cantSplit),
6881
"cellSpacing": docxml:length(${QNS.w}tblCellSpacing[not(@${QNS.w}type = 'nil')]/@${QNS.w}w, 'twip'),
82+
"height": ./${QNS.w}trHeight/map {
83+
"value": docxml:length(@${QNS.w}val, 'twip'),
84+
"rule": @${QNS.w}hRule/string()
85+
},
6986
"change": ./${QNS.w}trPrChange/map {
7087
"id": @${QNS.w}id/number(),
7188
"author": @${QNS.w}author/string(),
@@ -84,7 +101,7 @@ export function tableRowPropertiesFromNode(
84101
}
85102
}`,
86103
node
87-
) || {}
104+
) || {}
88105
: {};
89106
// Convert the date string to a Date object.
90107
if (props.change) {
@@ -132,6 +149,10 @@ export async function tableRowPropertiesToNode(
132149
attribute ${QNS.w}w { round($cellSpacing('twip')) },
133150
attribute ${QNS.w}type { "dxa" }
134151
} else (),
152+
if (exists($height)) then element ${QNS.w}trHeight {
153+
attribute ${QNS.w}val { round($height('twip')) },
154+
if (exists($heightRule)) then attribute ${QNS.w}hRule { $heightRule } else ()
155+
} else (),
135156
if (exists($change)) then element ${QNS.w}trPrChange {
136157
attribute ${QNS.w}id { $change('id') },
137158
if ($change('author')) then attribute ${QNS.w}author { $change('author') } else (),
@@ -145,6 +166,8 @@ export async function tableRowPropertiesToNode(
145166
isHeaderRow: trpr.isHeaderRow || false,
146167
isUnsplittable: trpr.isUnsplittable || false,
147168
cellSpacing: trpr.cellSpacing || null,
169+
height: trpr.height?.value || null,
170+
heightRule: trpr.height?.rule || null,
148171
change: trpr.change
149172
? {
150173
id: trpr.change.id,
@@ -155,7 +178,7 @@ export async function tableRowPropertiesToNode(
155178
? new Date(trpr.change.date).toISOString()
156179
: undefined,
157180
node: await tableRowPropertiesToNode(trpr.change),
158-
}
181+
}
159182
: null,
160183
insertion: trpr.insertion
161184
? await new Insertion(trpr.insertion).toNode([])

lib/properties/test/table-row-properties.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe } from 'std/testing/bdd';
22

3-
import { pt } from '../../utilities/src/length.ts';
3+
import { pt, twip } from '../../utilities/src/length.ts';
44
import { ALL_NAMESPACE_DECLARATIONS } from '../../utilities/src/namespaces.ts';
55
import { createXmlRoundRobinTest } from '../../utilities/src/tests.ts';
66
import {
@@ -65,3 +65,23 @@ describe('Table row deletion', () => {
6565
}
6666
);
6767
});
68+
69+
describe('Table row height', () => {
70+
test(
71+
`<w:trPr ${ALL_NAMESPACE_DECLARATIONS}>
72+
<w:trHeight w:val="949" w:hRule="exact"/>
73+
</w:trPr>`,
74+
{
75+
height: { value: twip(949), rule: 'exact' },
76+
}
77+
);
78+
79+
test(
80+
`<w:trPr ${ALL_NAMESPACE_DECLARATIONS}>
81+
<w:trHeight w:val="560"/>
82+
</w:trPr>`,
83+
{
84+
height: { value: twip(560) },
85+
}
86+
);
87+
});

0 commit comments

Comments
 (0)