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";
11 import {$getTableCellColumnWidth, $getTableCellsFromSelection, $setTableCellColumnWidth} from "../../../utils/tables";
12 import {formatSizeValue} from "../../../utils/dom";
14 const borderStyleInput: EditorSelectFormFieldDefinition = {
15 label: 'Border style',
33 const borderColorInput: EditorFormFieldDefinition = {
34 label: 'Border color',
39 const backgroundColorInput: EditorFormFieldDefinition = {
40 label: 'Background color',
41 name: 'background_color',
45 const alignmentInput: EditorSelectFormFieldDefinition = {
57 export function $showCellPropertiesForm(cell: CustomTableCellNode, context: EditorUiContext): EditorFormModal {
58 const styles = cell.getStyles();
59 const modalForm = context.manager.createModal('cell_properties');
61 width: $getTableCellColumnWidth(context.editor, cell),
62 height: styles.get('height') || '',
64 h_align: cell.getFormatType(),
65 v_align: styles.get('vertical-align') || '',
66 border_width: styles.get('border-width') || '',
67 border_style: styles.get('border-style') || '',
68 border_color: styles.get('border-color') || '',
69 background_color: styles.get('background-color') || '',
74 export const cellProperties: EditorFormDefinition = {
76 async action(formData, context: EditorUiContext) {
77 context.editor.update(() => {
78 const cells = $getTableCellsFromSelection($getSelection());
79 for (const cell of cells) {
80 const width = formData.get('width')?.toString() || '';
82 $setTableCellColumnWidth(cell, width);
83 cell.updateTag(formData.get('type')?.toString() || '');
84 cell.setFormat((formData.get('h_align')?.toString() || '') as ElementFormatType);
86 const styles = cell.getStyles();
87 styles.set('height', formatSizeValue(formData.get('height')?.toString() || ''));
88 styles.set('vertical-align', formData.get('v_align')?.toString() || '');
89 styles.set('border-width', formatSizeValue(formData.get('border_width')?.toString() || ''));
90 styles.set('border-style', formData.get('border_style')?.toString() || '');
91 styles.set('border-color', formData.get('border_color')?.toString() || '');
92 styles.set('background-color', formData.get('background_color')?.toString() || '');
94 cell.setStyles(styles);
103 const generalFields: EditorFormFieldDefinition[] = [
105 label: 'Width', // Colgroup width
110 label: 'Height', // inline-style: height
115 label: 'Cell type', // element
122 } as EditorSelectFormFieldDefinition,
124 ...alignmentInput, // class: 'align-right/left/center'
125 label: 'Horizontal align',
129 label: 'Vertical align', // inline-style: vertical-align
138 } as EditorSelectFormFieldDefinition,
141 const advancedFields: EditorFormFieldDefinition[] = [
143 label: 'Border width', // inline-style: border-width
144 name: 'border_width',
147 borderStyleInput, // inline-style: border-style
148 borderColorInput, // inline-style: border-color
149 backgroundColorInput, // inline-style: background-color
152 return new EditorFormTabs([
155 contents: generalFields,
159 contents: advancedFields,
167 export const rowProperties: EditorFormDefinition = {
169 async action(formData, context: EditorUiContext) {
175 // Removed 'Row Type' as we don't currently support thead/tfoot elements
176 // TinyMCE would move rows up/down into these parents when set
177 // Removed 'Alignment' since this was broken in our editor (applied alignment class to whole parent table)
179 label: 'Height', // style on tr: height
183 borderStyleInput, // style on tr: height
184 borderColorInput, // style on tr: height
185 backgroundColorInput, // style on tr: height
188 export const tableProperties: EditorFormDefinition = {
190 async action(formData, context: EditorUiContext) {
197 const generalFields: EditorFormFieldDefinition[] = [
209 label: 'Cell spacing',
210 name: 'cell_spacing',
214 label: 'Cell padding',
215 name: 'cell_padding',
219 label: 'Border width',
220 name: 'border_width',
226 type: 'text', // TODO -
231 const advancedFields: EditorFormFieldDefinition[] = [
234 backgroundColorInput,
237 return new EditorFormTabs([
240 contents: generalFields,
244 contents: advancedFields,