add saving text
This commit is contained in:
parent
0b14a1525d
commit
a860f8d093
@ -26,12 +26,16 @@ export class Formula extends ExcelComponent {
|
|||||||
|
|
||||||
this.formulaInput = this.$root.find('#formula-input');
|
this.formulaInput = this.$root.find('#formula-input');
|
||||||
|
|
||||||
this.$on('table:input', text => {
|
// this.$on('table:input', text => {
|
||||||
this.formulaInput.text = text;
|
// this.formulaInput.text = text;
|
||||||
});
|
// });
|
||||||
this.$on('table:select-cell', text => {
|
this.$on('table:select-cell', text => {
|
||||||
this.formulaInput.text = text;
|
this.formulaInput.text = text;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.$subscribe(state => {
|
||||||
|
this.formulaInput.text = state.currentText;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onInput(event: Event) {
|
onInput(event: Event) {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ export class Table extends ExcelComponent {
|
|||||||
|
|
||||||
this.$on('formula:input', (data) => {
|
this.$on('formula:input', (data) => {
|
||||||
this.selection.current.text = data;
|
this.selection.current.text = data;
|
||||||
|
this.updateCurrentTextInStore(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$on('formula:enter-press', () => {
|
this.$on('formula:enter-press', () => {
|
||||||
@ -46,8 +47,12 @@ export class Table extends ExcelComponent {
|
|||||||
// this.$subscribe(state => {
|
// this.$subscribe(state => {
|
||||||
// console.log('State in Table', state);
|
// console.log('State in Table', state);
|
||||||
// });
|
// });
|
||||||
|
this.initTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
initTable() {
|
||||||
this.initTableSize();
|
this.initTableSize();
|
||||||
|
this.initTableContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
initTableSize() {
|
initTableSize() {
|
||||||
@ -66,6 +71,13 @@ export class Table extends ExcelComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initTableContent() {
|
||||||
|
const tableContent = this.store.getState().dataState;
|
||||||
|
Object.keys(tableContent).forEach(cellId => {
|
||||||
|
this.$root.find(`[data-id="${cellId}"]`).text = tableContent[cellId] || '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
emitSelectCallback() {
|
emitSelectCallback() {
|
||||||
this.$emit('table:select-cell', this.selection.current.text);
|
this.$emit('table:select-cell', this.selection.current.text);
|
||||||
}
|
}
|
||||||
@ -73,13 +85,19 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateCurrentTextInStore(text: string) {
|
||||||
|
this.$dispatch(actions.changeText({
|
||||||
|
text,
|
||||||
|
id: this.selection.current.data.id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
onMousedown(event: MouseEvent) {
|
onMousedown(event: MouseEvent) {
|
||||||
selectHandler(event, this.selection, this.emitSelectCallback.bind(this));
|
selectHandler(event, this.selection, this.emitSelectCallback.bind(this));
|
||||||
this.resizeTable(event);
|
this.resizeTable(event);
|
||||||
@ -90,7 +108,6 @@ export class Table extends ExcelComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onInput(event: InputEvent) {
|
onInput(event: InputEvent) {
|
||||||
const inputText = (event.target as HTMLElement).textContent.trim();
|
this.updateCurrentTextInStore((event.target as HTMLElement).textContent.trim());
|
||||||
this.$emit('table:input', inputText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import { storage } from './utils';
|
|||||||
const initialState: StateType = {
|
const initialState: StateType = {
|
||||||
colState: {},
|
colState: {},
|
||||||
rowState: {},
|
rowState: {},
|
||||||
|
dataState: {},
|
||||||
|
currentText: '',
|
||||||
...storage('excel-state'),
|
...storage('excel-state'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { TABLE_RESIZE } from './constants';
|
import { CHANGE_TEXT, TABLE_RESIZE } from './constants';
|
||||||
|
|
||||||
export function tableResize(resizeData: any) {
|
export function tableResize(resizeData: any) {
|
||||||
return {
|
return {
|
||||||
@ -6,3 +6,10 @@ export function tableResize(resizeData: any) {
|
|||||||
...resizeData,
|
...resizeData,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function changeText(data: { text: string, id: string }) {
|
||||||
|
return {
|
||||||
|
type: CHANGE_TEXT,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
export const TABLE_RESIZE = 'TABLE_RESIZE';
|
export const TABLE_RESIZE = 'TABLE_RESIZE';
|
||||||
|
export const CHANGE_TEXT = 'CHANGE_TEXT';
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { TABLE_RESIZE } from './constants';
|
import { CHANGE_TEXT, TABLE_RESIZE } from './constants';
|
||||||
import { ActionType, StateType } from './types';
|
import { ActionType, StateType } from './types';
|
||||||
|
|
||||||
export function rootReducer(state: StateType, action: ActionType) {
|
export function rootReducer(state: StateType, action: ActionType) {
|
||||||
@ -12,6 +12,14 @@ export function rootReducer(state: StateType, action: ActionType) {
|
|||||||
return { ...state, ...newState };
|
return { ...state, ...newState };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case CHANGE_TEXT: {
|
||||||
|
const newState: StateType = state.dataState || {};
|
||||||
|
|
||||||
|
newState[action.data.id] = action.data.text;
|
||||||
|
|
||||||
|
return { ...state, currentText: action?.data?.text, dataState: newState };
|
||||||
|
}
|
||||||
|
|
||||||
default: return state;
|
default: return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user