3 EditorFormFieldDefinition,
5 EditorSelectFormFieldDefinition
6 } from "../../framework/forms";
7 import {EditorUiContext} from "../../framework/core";
8 import {CustomTableCellNode} from "../../../nodes/custom-table-cell-node";
9 import {EditorFormModal} from "../../framework/modals";
10 import {$getSelection, ElementFormatType} from "lexical";
11 import {$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');
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) {
176 const generalFields: EditorFormFieldDefinition[] = [
186 } as EditorSelectFormFieldDefinition,
195 const advancedFields: EditorFormFieldDefinition[] = [
198 backgroundColorInput,
201 return new EditorFormTabs([
204 contents: generalFields,
208 contents: advancedFields,
215 export const tableProperties: EditorFormDefinition = {
217 async action(formData, context: EditorUiContext) {
224 const generalFields: EditorFormFieldDefinition[] = [
236 label: 'Cell spacing',
237 name: 'cell_spacing',
241 label: 'Cell padding',
242 name: 'cell_padding',
246 label: 'Border width',
247 name: 'border_width',
253 type: 'text', // TODO -
258 const advancedFields: EditorFormFieldDefinition[] = [
261 backgroundColorInput,
264 return new EditorFormTabs([
267 contents: generalFields,
271 contents: advancedFields,