Skip to content

Commit

Permalink
bottombar bugfix and rename sheet-name
Browse files Browse the repository at this point in the history
  • Loading branch information
myliang committed Feb 25, 2020
1 parent 5b4e736 commit 28c210e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/component/bottombar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { h } from './element';
import { bindClickoutside, unbindClickoutside } from './event';
import { cssPrefix } from '../config';
import Icon from './icon';
import FormInput from './form_input';
import Dropdown from './dropdown';
import { xtoast } from './message';
import { tf } from '../locale/locale';
Expand Down Expand Up @@ -69,8 +70,12 @@ class ContextMenu {
}

export default class Bottombar {
constructor(addFunc = () => {}, swapFunc = () => {}, deleteFunc = () => {}) {
constructor(addFunc = () => {},
swapFunc = () => {},
deleteFunc = () => {},
updateFunc = () => {}) {
this.swapFunc = swapFunc;
this.updateFunc = updateFunc;
this.dataNames = [];
this.activeEl = null;
this.deleteEl = null;
Expand All @@ -97,8 +102,7 @@ export default class Bottombar {
);
}

addItem(data, active) {
const { name } = data;
addItem(name, active) {
this.dataNames.push(name);
const item = h('li', active ? 'active' : '').child(name);
item.on('click', () => {
Expand All @@ -107,6 +111,20 @@ export default class Bottombar {
const { offsetLeft, offsetHeight } = evt.target;
this.contextMenu.setOffset({ left: offsetLeft, bottom: offsetHeight + 1 });
this.deleteEl = item;
}).on('dblclick', () => {
const v = item.html();
const input = new FormInput('auto', '');
input.val(v);
input.input.on('blur', ({ target }) => {
const { value } = target;
const nindex = this.dataNames.findIndex(it => it === v);
this.dataNames.splice(nindex, 1, value);
this.moreEl.reset(this.dataNames);
item.html('').child(value);
this.updateFunc(nindex, value);
});
item.html('').child(input.el);
input.focus();
});
if (active) {
this.clickSwap(item);
Expand All @@ -123,6 +141,7 @@ export default class Bottombar {
this.items.splice(index, 1);
this.dataNames.splice(index, 1);
this.menuEl.removeChild(deleteEl.el);
this.moreEl.reset(this.dataNames);
if (activeEl === deleteEl) {
const [f] = this.items;
this.activeEl = f;
Expand Down
6 changes: 6 additions & 0 deletions src/component/form_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default class FormInput {
this.el.child(this.input);
}

focus() {
setTimeout(() => {
this.input.el.focus();
}, 10);
}

hint(v) {
this.input.attr('placeholder', v);
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Spreadsheet {
}, () => {
const newd = this.deleteSheet();
if (newd !== null) this.sheet.resetData(newd);
}, (index, value) => {
this.datas[index].name = value;
});
this.data = this.addSheet();
const rootEl = h('div', `${cssPrefix}`)
Expand All @@ -41,7 +43,7 @@ class Spreadsheet {
const d = new DataProxy(n, this.options);
this.datas.push(d);
// console.log('d:', n, d, this.datas);
this.bottombar.addItem(d, true);
this.bottombar.addItem(n, true);
this.sheetIndex += 1;
return d;
}
Expand Down

0 comments on commit 28c210e

Please sign in to comment.