add row resize state
This commit is contained in:
parent
a8b9cbfb9f
commit
0b14a1525d
@ -51,10 +51,18 @@ export class Table extends ExcelComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initTableSize() {
|
initTableSize() {
|
||||||
const colSizes = this.store.getState()?.colState;
|
const size = {
|
||||||
Object.keys(colSizes).forEach(key => {
|
col: this.store.getState()?.colState,
|
||||||
|
row: this.store.getState()?.rowState,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(size.col).forEach(key => {
|
||||||
const cols = this.$root.findAll(`[data-col="${key}"]`);
|
const cols = this.$root.findAll(`[data-col="${key}"]`);
|
||||||
cols.forEach(el => $(el as HTMLElement).css({ width: `${colSizes[key]}px` }));
|
cols.forEach(el => $(el as HTMLElement).css({ width: `${size.col[key]}px` }));
|
||||||
|
});
|
||||||
|
Object.keys(size.row).forEach(key => {
|
||||||
|
const rows = this.$root.findAll(`[data-row="${key}"]`);
|
||||||
|
rows.forEach(el => $(el as HTMLElement).css({ height: `${size.row[key]}px` }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +73,7 @@ export class Table extends ExcelComponent {
|
|||||||
async resizeTable(event: MouseEvent) {
|
async resizeTable(event: MouseEvent) {
|
||||||
try {
|
try {
|
||||||
const resizeData = await resizeHandler(this.$root, event);
|
const resizeData = await resizeHandler(this.$root, event);
|
||||||
|
console.log('Resize data', resizeData);
|
||||||
this.$dispatch(actions.tableResize({ resizeData }));
|
this.$dispatch(actions.tableResize({ resizeData }));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Resize error', e.message);
|
console.warn('Resize error', e.message);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { $, Dom } from '../../../core/dom';
|
import { $, Dom } from '../../../core/dom';
|
||||||
|
|
||||||
type CustomElementType = Element & { css: any };
|
type CustomElementType = Element & { css: any };
|
||||||
type ResizeReturnDataType = { value: number, id: string };
|
type ResizeReturnDataType = { value: number, id: string, type: string };
|
||||||
|
|
||||||
export function resizeHandler($root: Dom, event: MouseEvent) {
|
export function resizeHandler($root: Dom, event: MouseEvent) {
|
||||||
return new Promise<ResizeReturnDataType>(res => {
|
return new Promise<ResizeReturnDataType>(res => {
|
||||||
@ -60,10 +60,12 @@ export function resizeHandler($root: Dom, event: MouseEvent) {
|
|||||||
document.body.style.userSelect = null;
|
document.body.style.userSelect = null;
|
||||||
|
|
||||||
let value: number;
|
let value: number;
|
||||||
|
// let id: string;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'col': {
|
case 'col': {
|
||||||
value = coords.width + delta;
|
value = coords.width + delta;
|
||||||
|
|
||||||
$parent.css({ width: `${value}px` });
|
$parent.css({ width: `${value}px` });
|
||||||
allCols.forEach((el: CustomElementType) => el.css({ width: `${coords.width + delta}px` }));
|
allCols.forEach((el: CustomElementType) => el.css({ width: `${coords.width + delta}px` }));
|
||||||
break;
|
break;
|
||||||
@ -71,6 +73,7 @@ export function resizeHandler($root: Dom, event: MouseEvent) {
|
|||||||
|
|
||||||
case 'row': {
|
case 'row': {
|
||||||
value = coords.height + delta;
|
value = coords.height + delta;
|
||||||
|
|
||||||
$parent.css({ height: `${value}px` });
|
$parent.css({ height: `${value}px` });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -78,10 +81,7 @@ export function resizeHandler($root: Dom, event: MouseEvent) {
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
res({
|
res({ value, id: $parent.data[type], type });
|
||||||
value,
|
|
||||||
id: type === 'col' ? $parent.data.col : null,
|
|
||||||
});
|
|
||||||
|
|
||||||
$resizer.css({ opacity: 0, bottom: 0, right: 0 });
|
$resizer.css({ opacity: 0, bottom: 0, right: 0 });
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,7 +9,6 @@ function createCell(cellContent = '', colIndex = 1, rowIndex = 1) {
|
|||||||
class="cell"
|
class="cell"
|
||||||
contenteditable
|
contenteditable
|
||||||
data-col="${colIndex}"
|
data-col="${colIndex}"
|
||||||
data-row=${rowIndex}
|
|
||||||
data-id="${rowIndex}:${colIndex}"
|
data-id="${rowIndex}:${colIndex}"
|
||||||
data-type="cell"
|
data-type="cell"
|
||||||
>
|
>
|
||||||
@ -28,9 +27,9 @@ function createCol(columnContent = '', index = 1) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRow(dataContent = '', infoContent = '', needResize = true) {
|
function createRow(dataContent = '', infoContent = '', needResize = true, rowIndex = -1) {
|
||||||
return `
|
return `
|
||||||
<div class="row" data-type="resizable">
|
<div class="row" data-type="resizable" data-row="${rowIndex}">
|
||||||
<div class="row-info">
|
<div class="row-info">
|
||||||
${infoContent}
|
${infoContent}
|
||||||
${needResize ? '<div class="row-resize" data-resize="row"></div>' : ''}
|
${needResize ? '<div class="row-resize" data-resize="row"></div>' : ''}
|
||||||
@ -58,7 +57,7 @@ export function createTable(rowsCount = 10, columnCount = 10) {
|
|||||||
.map((el, index) => createCell('', index, row))
|
.map((el, index) => createCell('', index, row))
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
rows.push(createRow(cells, `${row + 1}`));
|
rows.push(createRow(cells, `${row + 1}`, true, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows.join('');
|
return rows.join('');
|
||||||
|
|||||||
@ -4,9 +4,12 @@ import { ActionType, StateType } from './types';
|
|||||||
export function rootReducer(state: StateType, action: ActionType) {
|
export function rootReducer(state: StateType, action: ActionType) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case TABLE_RESIZE: {
|
case TABLE_RESIZE: {
|
||||||
const prevState = state.colState || {};
|
const newState: StateType = { ...state };
|
||||||
prevState[action.resizeData?.id] = action.resizeData?.value;
|
const fieldName = `${action.resizeData?.type}State`;
|
||||||
return { ...state, colState: prevState };
|
|
||||||
|
newState[fieldName][action.resizeData?.id] = action.resizeData?.value;
|
||||||
|
|
||||||
|
return { ...state, ...newState };
|
||||||
}
|
}
|
||||||
|
|
||||||
default: return state;
|
default: return state;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user