3 EditorFormFieldDefinition,
5 EditorSelectFormFieldDefinition
6 } from "../../framework/forms";
7 import {EditorUiContext} from "../../framework/core";
8 import {CustomTableCellNode} from "../../../nodes/custom-table-cell";
9 import {EditorFormModal} from "../../framework/modals";
10 import {$getSelection, ElementFormatType} from "lexical";
12 $getTableCellColumnWidth,
13 $getTableCellsFromSelection,
14 $getTableRowsFromSelection,
15 $setTableCellColumnWidth
16 } from "../../../utils/tables";
17 import {formatSizeValue} from "../../../utils/dom";
18 import {CustomTableRowNode} from "../../../nodes/custom-table-row";
20 const borderStyleInput: EditorSelectFormFieldDefinition = {
21 label: 'Border style',
39 const borderColorInput: EditorFormFieldDefinition = {
40 label: 'Border color',
45 const backgroundColorInput: EditorFormFieldDefinition = {
46 label: 'Background color',
47 name: 'background_color',
51 const alignmentInput: EditorSelectFormFieldDefinition = {
63 export function $showCellPropertiesForm(cell: CustomTableCellNode, context: EditorUiContext): EditorFormModal {
64 const styles = cell.getStyles();
65 const modalForm = context.manager.createModal('cell_properties');
67 width: $getTableCellColumnWidth(context.editor, cell),
68 height: styles.get('height') || '',
70 h_align: cell.getFormatType(),
71 v_align: styles.get('vertical-align') || '',
72 border_width: styles.get('border-width') || '',
73 border_style: styles.get('border-style') || '',
74 border_color: styles.get('border-color') || '',
75 background_color: styles.get('background-color') || '',
80 export const cellProperties: EditorFormDefinition = {
82 async action(formData, context: EditorUiContext) {
83 context.editor.update(() => {
84 const cells = $getTableCellsFromSelection($getSelection());
85 for (const cell of cells) {
86 const width = formData.get('width')?.toString() || '';
88 $setTableCellColumnWidth(cell, width);
89 cell.updateTag(formData.get('type')?.toString() || '');
90 cell.setFormat((formData.get('h_align')?.toString() || '') as ElementFormatType);
92 const styles = cell.getStyles();
93 styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
94 styles.set('vertical-align', formData.get('v_align')?.toString() || '');
95 styles.set('border-width', formatSizeValue(formData.get('border_width')?.toString() || ''));
96 styles.set('border-style', formData.get('border_style')?.toString() || '');
97 styles.set('border-color', formData.get('border_color')?.toString() || '');
98 styles.set('background-color', formData.get('background_color')?.toString() || '');
100 cell.setStyles(styles);
109 const generalFields: EditorFormFieldDefinition[] = [
111 label: 'Width', // Colgroup width
116 label: 'Height', // inline-style: height
121 label: 'Cell type', // element
128 } as EditorSelectFormFieldDefinition,
130 ...alignmentInput, // class: 'align-right/left/center'
131 label: 'Horizontal align',
135 label: 'Vertical align', // inline-style: vertical-align
144 } as EditorSelectFormFieldDefinition,
147 const advancedFields: EditorFormFieldDefinition[] = [
149 label: 'Border width', // inline-style: border-width
150 name: 'border_width',
153 borderStyleInput, // inline-style: border-style
154 borderColorInput, // inline-style: border-color
155 backgroundColorInput, // inline-style: background-color
158 return new EditorFormTabs([
161 contents: generalFields,
165 contents: advancedFields,
173 export function $showRowPropertiesForm(row: CustomTableRowNode, context: EditorUiContext): EditorFormModal {
174 const styles = row.getStyles();
175 const modalForm = context.manager.createModal('row_properties');
177 height: styles.get('height') || '',
178 border_style: styles.get('border-style') || '',
179 border_color: styles.get('border-color') || '',
180 background_color: styles.get('background-color') || '',
185 export const rowProperties: EditorFormDefinition = {
187 async action(formData, context: EditorUiContext) {
188 context.editor.update(() => {
189 const rows = $getTableRowsFromSelection($getSelection());
190 for (const row of rows) {
191 const styles = row.getStyles();
192 styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
193 styles.set('border-style', formData.get('border_style')?.toString() || '');
194 styles.set('border-color', formData.get('border_color')?.toString() || '');
195 styles.set('background-color', formData.get('background_color')?.toString() || '');
196 row.setStyles(styles);
203 // Removed 'Row Type' as we don't currently support thead/tfoot elements
204 // TinyMCE would move rows up/down into these parents when set
205 // Removed 'Alignment' since this was broken in our editor (applied alignment class to whole parent table)
207 label: 'Height', // style on tr: height
211 borderStyleInput, // style on tr: height
212 borderColorInput, // style on tr: height
213 backgroundColorInput, // style on tr: height
216 export const tableProperties: EditorFormDefinition = {
218 async action(formData, context: EditorUiContext) {
225 const generalFields: EditorFormFieldDefinition[] = [
237 label: 'Cell spacing',
238 name: 'cell_spacing',
242 label: 'Cell padding',
243 name: 'cell_padding',
247 label: 'Border width',
248 name: 'border_width',
254 type: 'text', // TODO -
259 const advancedFields: EditorFormFieldDefinition[] = [
262 backgroundColorInput,
265 return new EditorFormTabs([
268 contents: generalFields,
272 contents: advancedFields,