Skip to content

Commit 17b4609

Browse files
YousefEDareknawo
authored andcommitted
fixes
1 parent c6b49bb commit 17b4609

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

packages/xl-odt-exporter/src/odt/defaultSchema/blocks.tsx

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ODTExporter } from "../odtExporter.js";
77
import {
88
DrawFrame,
99
DrawImage,
10-
StyleBackgroundFill,
10+
LoextGraphicProperties,
1111
StyleParagraphProperties,
1212
StyleStyle,
1313
StyleTableCellProperties,
@@ -32,7 +32,8 @@ const createParagraphStyle = (
3232
parentStyleName?: string
3333
) => {
3434
const styles: Record<string, string> = {};
35-
const children: React.ReactNode[] = [];
35+
const styleChildren: React.ReactNode[] = [];
36+
const paragraphChildren: React.ReactNode[] = [];
3637

3738
if (props.textAlignment && props.textAlignment !== "left") {
3839
const alignmentMap = {
@@ -50,7 +51,12 @@ const createParagraphStyle = (
5051
exporter.options.colors[
5152
props.backgroundColor as keyof typeof exporter.options.colors
5253
].background;
53-
children.push(<StyleBackgroundFill color={color} />);
54+
styleChildren.push(
55+
<>
56+
<LoextGraphicProperties draw:fill="solid" draw:fill-color={color} />
57+
<StyleParagraphProperties fo:background-color={color} />
58+
</>
59+
);
5460
}
5561

5662
if (props.textColor && props.textColor !== "default") {
@@ -61,7 +67,11 @@ const createParagraphStyle = (
6167
styles["fo:color"] = color;
6268
}
6369

64-
if (Object.keys(styles).length === 0 && children.length === 0) {
70+
if (
71+
Object.keys(styles).length === 0 &&
72+
styleChildren.length === 0
73+
// && paragraphChildren.length === 0
74+
) {
6575
return parentStyleName;
6676
}
6777

@@ -70,9 +80,13 @@ const createParagraphStyle = (
7080
style:family="paragraph"
7181
style:name={name}
7282
style:parent-style-name={parentStyleName}>
73-
<StyleParagraphProperties {...styles}>
74-
{children}
75-
</StyleParagraphProperties>
83+
{styleChildren}
84+
{paragraphChildren.length > 0 ||
85+
(Object.keys(styles).length > 0 && (
86+
<StyleParagraphProperties {...styles}>
87+
{paragraphChildren}
88+
</StyleParagraphProperties>
89+
))}
7690
</StyleStyle>
7791
));
7892
};
@@ -118,7 +132,7 @@ export const odtBlockMappingForDefaultSchema: BlockMapping<
118132
const customStyleName = createParagraphStyle(
119133
exporter as ODTExporter<any, any, any>,
120134
block.props,
121-
"Heading" + block.props.level
135+
"Heading_20_" + block.props.level
122136
);
123137
const styleName = customStyleName;
124138

@@ -131,15 +145,15 @@ export const odtBlockMappingForDefaultSchema: BlockMapping<
131145
},
132146

133147
bulletListItem: (block, exporter) => (
134-
<TextList text:style-name="LFO1">
148+
<TextList text:style-name="WWNum1">
135149
<TextListItem>
136150
<TextP>{exporter.transformInlineContent(block.content)}</TextP>
137151
</TextListItem>
138152
</TextList>
139153
),
140154

141155
numberedListItem: (block, exporter) => (
142-
<TextList text:style-name="LFO3">
156+
<TextList text:style-name="No_20_List">
143157
<TextListItem>
144158
<TextP>{exporter.transformInlineContent(block.content)}</TextP>
145159
</TextListItem>
@@ -163,10 +177,35 @@ export const odtBlockMappingForDefaultSchema: BlockMapping<
163177
},
164178

165179
table: (block, exporter) => {
166-
const styleName = createTableStyle(exporter as ODTExporter<any, any, any>);
180+
const ex = exporter as ODTExporter<any, any, any>;
181+
const styleName = createTableStyle(ex);
167182

168183
return (
169184
<Table>
185+
{block.content.rows[0]?.cells.map((el, i) => {
186+
let width: any = block.content.columnWidths[i];
187+
188+
if (!width) {
189+
// width = "3in";
190+
} else {
191+
width = "5in";
192+
}
193+
if (width) {
194+
const style = ex.registerStyle((name) => (
195+
<StyleStyle style:name={name} style:family="table-column">
196+
<style:table-column-properties style:column-width={width} />
197+
</StyleStyle>
198+
));
199+
return <table:table-column table:style-name={style} />;
200+
} else {
201+
const style = ex.registerStyle((name) => (
202+
<StyleStyle style:name={name} style:family="table-column">
203+
<style:table-column-properties style:use-optimal-column-width="true" />
204+
</StyleStyle>
205+
));
206+
return <table:table-column table:style-name={style} />;
207+
}
208+
})}
170209
{block.content.rows.map((row) => (
171210
<TableRow>
172211
{row.cells.map((cell) => (

packages/xl-odt-exporter/src/odt/odtExporter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class ODTExporter<
9090
return styledText.text;
9191
}
9292

93-
const styleName = `T${++this.styleCounter}`;
93+
const styleName = `BN_T${++this.styleCounter}`;
9494

9595
// Store the complete style element
9696
this.automaticStyles.set(
@@ -183,7 +183,7 @@ export class ODTExporter<
183183
}
184184

185185
public registerStyle(style: (name: string) => React.ReactNode): string {
186-
const styleName = `S${++this.styleCounter}`;
186+
const styleName = `BN_S${++this.styleCounter}`;
187187
this.automaticStyles.set(styleName, style(styleName));
188188
return styleName;
189189
}

packages/xl-odt-exporter/src/odt/util/components.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const OfficeDocument = ({ children, ...props }: Props) =>
1717
"xmlns:xlink": "http://www.w3.org/1999/xlink",
1818
"xmlns:style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
1919
"xmlns:fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
20+
"xmlns:loext":
21+
"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0",
2022
...props,
2123
},
2224
children
@@ -117,8 +119,8 @@ export const StyleBackgroundFill = ({
117119
export const StyleParagraphProperties = ({ children, ...props }: Props) =>
118120
createElement("style:paragraph-properties", props, children);
119121

120-
export const StyleTableProperties = ({ children, ...props }: Props) =>
121-
createElement("style:table-properties", props, children);
122+
export const LoextGraphicProperties = ({ children, ...props }: Props) =>
123+
createElement("loext:graphic-properties", props, children);
122124

123125
export const StyleTableCellProperties = ({ children, ...props }: Props) =>
124126
createElement("style:table-cell-properties", props, children);

shared/testDocument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const testDocument = partialBlocksToBlocksForTesting(
1515
content: [
1616
{
1717
type: "text",
18-
text: "Welcome to this",
18+
text: "Welcome to this ",
1919
styles: {
2020
italic: true,
2121
},

0 commit comments

Comments
 (0)