3 EditorFormFieldDefinition,
5 EditorSelectFormFieldDefinition
6 } from "../../framework/forms";
7 import {EditorUiContext} from "../../framework/core";
8 import {$isCustomTableCellNode, CustomTableCellNode} from "../../../nodes/custom-table-cell-node";
9 import {EditorFormModal} from "../../framework/modals";
10 import {$getNodeFromSelection} from "../../../utils/selection";
11 import {$getSelection, ElementFormatType} from "lexical";
12 import {TableCellHeaderStates} from "@lexical/table";
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') || '',
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 // TODO - Set for cell selection range
78 context.editor.update(() => {
79 const cell = $getNodeFromSelection($getSelection(), $isCustomTableCellNode);
80 if ($isCustomTableCellNode(cell)) {
82 cell.setFormat((formData.get('h_align')?.toString() || '') as ElementFormatType);
83 cell.updateTag(formData.get('type')?.toString() || '');
85 const styles = cell.getStyles();
86 styles.set('height', formData.get('height')?.toString() || '');
87 styles.set('vertical-align', formData.get('v_align')?.toString() || '');
88 styles.set('border-width', formData.get('border_width')?.toString() || '');
89 styles.set('border-style', formData.get('border_style')?.toString() || '');
90 styles.set('border-color', formData.get('border_color')?.toString() || '');
91 styles.set('background-color', formData.get('background_color')?.toString() || '');
93 cell.setStyles(styles);
102 const generalFields: EditorFormFieldDefinition[] = [
104 label: 'Width', // Colgroup width
109 label: 'Height', // inline-style: height
114 label: 'Cell type', // element
121 } as EditorSelectFormFieldDefinition,
123 ...alignmentInput, // class: 'align-right/left/center'
124 label: 'Horizontal align',
128 label: 'Vertical align', // inline-style: vertical-align
137 } as EditorSelectFormFieldDefinition,
140 const advancedFields: EditorFormFieldDefinition[] = [
142 label: 'Border width', // inline-style: border-width
143 name: 'border_width',
146 borderStyleInput, // inline-style: border-style
147 borderColorInput, // inline-style: border-color
148 backgroundColorInput, // inline-style: background-color
151 return new EditorFormTabs([
154 contents: generalFields,
158 contents: advancedFields,
166 export const rowProperties: EditorFormDefinition = {
168 async action(formData, context: EditorUiContext) {
175 const generalFields: EditorFormFieldDefinition[] = [
185 } as EditorSelectFormFieldDefinition,
194 const advancedFields: EditorFormFieldDefinition[] = [
197 backgroundColorInput,
200 return new EditorFormTabs([
203 contents: generalFields,
207 contents: advancedFields,
214 export const tableProperties: EditorFormDefinition = {
216 async action(formData, context: EditorUiContext) {
223 const generalFields: EditorFormFieldDefinition[] = [
235 label: 'Cell spacing',
236 name: 'cell_spacing',
240 label: 'Cell padding',
241 name: 'cell_padding',
245 label: 'Border width',
246 name: 'border_width',
252 type: 'text', // TODO -
257 const advancedFields: EditorFormFieldDefinition[] = [
260 backgroundColorInput,
263 return new EditorFormTabs([
266 contents: generalFields,
270 contents: advancedFields,