Skip to content

Commit c027904

Browse files
committed
fix(text-editor tables): put repeated code in single function
1 parent df48a36 commit c027904

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/components/text-editor/prosemirror-adapter/plugins/table-plugin.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,23 @@ export const getTableEditingPlugins = (tablesEnabled: boolean): Plugin[] => {
99
return [];
1010
};
1111

12+
const createStyleAttribute = (cssProperty: string) => ({
13+
default: null,
14+
getFromDOM: (dom: HTMLElement) => dom.style[cssProperty] || null,
15+
setDOMAttr: (value: string, attrs: Record<string, any>) => {
16+
if (value) {
17+
attrs.style = (attrs.style || '') + `${cssProperty}: ${value};`;
18+
}
19+
},
20+
});
21+
1222
export const getTableNodes = () => {
1323
return tableNodes({
1424
tableGroup: 'block',
1525
cellContent: 'block+',
1626
cellAttributes: {
17-
background: {
18-
default: null,
19-
getFromDOM: (dom) => {
20-
return dom.style.backgroundColor || null;
21-
},
22-
setDOMAttr: (value: string, attrs: Record<string, string>) => {
23-
if (value) {
24-
attrs.style =
25-
(attrs.style || '') + `background-color: ${value};`;
26-
}
27-
},
28-
},
29-
color: {
30-
default: null,
31-
getFromDOM: (dom) => {
32-
return dom.style.color || null;
33-
},
34-
setDOMAttr: (value: string, attrs: Record<string, string>) => {
35-
if (value) {
36-
attrs.style = (attrs.style || '') + `color: ${value};`;
37-
}
38-
},
39-
},
27+
background: createStyleAttribute('background-color'),
28+
color: createStyleAttribute('color'),
4029
},
4130
});
4231
};

0 commit comments

Comments
 (0)