Skip to content

Commit

Permalink
hot bug 造成的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbunny committed Jul 21, 2017
1 parent e56cf05 commit 7ff5aac
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 85 deletions.
68 changes: 56 additions & 12 deletions dist/spreadsheet-0.5.1-debug.js → dist/spreadsheet-0.5.2-debug.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/spreadsheet-0.5.1.css → dist/spreadsheet-0.5.2.css

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions dist/spreadsheet-0.5.1.js → dist/spreadsheet-0.5.2.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ var jsfileHeader = ['/*!',
' * @license <%= pkg.license %>',
' * ',
' * Build on: <%= date %>',
' * - handsontable-lnsoft version: <%= pkg.vendors.handsontable %>',
' * - formulajs version: <%= pkg.dependencies.formulajs %>',
' * - moment version: <%= pkg.vendors.moment %>',
' * - numbro version: <%= pkg.vendors.numbro %>',
' * - pikaday version: <%= pkg.vendors.pikaday %>',
' * - zeroclipboard version: <%= pkg.vendors.zeroclipboard %>',
' * - handsontable version: <%= pkg.vendors.handsontable %>',
' * - formulajs version: <%= pkg.dependencies.formulajs %>',
' * - moment version: <%= pkg.vendors.moment %>',
' * - numbro version: <%= pkg.vendors.numbro %>',
' * - pikaday version: <%= pkg.vendors.pikaday %>',
' * - zeroclipboard version: <%= pkg.vendors.zeroclipboard %>',
' * ',
' * See also https://github.com/ssbunny/handsontable',
' */',
''].join('\n');

Expand Down
105 changes: 101 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,106 @@
var container = document.getElementById('designer');

var ss = {}
var ss = {
"workbook": {
"activeSheet": "工作表1",
"sheets": [{
"name": "工作表1",
"selection": {"row": 0, "col": 1, "endRow": 0, "endCol": 1},
"data": [["2", "3", null, "3"], ["1", "3", "", "3"], ["=SUM(A1:B2)", null, null, "3"]],
"rowHeights": [129, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
"colWidths": [50, 50, 50, 50, 131, 87, 97, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],
"mergeCells": null,
"cellMetas": [[{
"row": 0,
"col": 0,
"isFormula": false,
"sourceValue": "2",
"value": "2",
"dataType": {"typeName": "text"}
}, {
"row": 0,
"col": 1,
"isFormula": false,
"sourceValue": "3",
"value": "3",
"styles": {"alignments": ["Bottom"], "fontSize": "40px"},
"dataType": {"typeName": "text"}
}, {
"row": 0,
"col": 2,
"isFormula": false,
"sourceValue": null,
"value": null,
"dataType": {"typeName": "text"}
}, {
"row": 0,
"col": 3,
"isFormula": false,
"sourceValue": "3",
"value": "3",
"dataType": {"typeName": "text"}
}], [{
"row": 1,
"col": 0,
"isFormula": false,
"sourceValue": "1",
"value": "1",
"dataType": {"typeName": "text"}
}, {
"row": 1,
"col": 1,
"isFormula": false,
"sourceValue": "3",
"value": "3",
"dataType": {"typeName": "text"}
}, {
"row": 1,
"col": 2,
"isFormula": false,
"sourceValue": "",
"value": "",
"dataType": {"typeName": "text"}
}, {
"row": 1,
"col": 3,
"isFormula": false,
"sourceValue": "3",
"value": "3",
"dataType": {"typeName": "text"}
}], [{
"row": 2,
"col": 0,
"isFormula": true,
"sourceValue": "=SUM(A1:B2)",
"value": 9,
"dataType": {"typeName": "text"}
}, {
"row": 2,
"col": 1,
"isFormula": false,
"sourceValue": null,
"value": null,
"dataType": {"typeName": "text"}
}, {
"row": 2,
"col": 2,
"isFormula": false,
"sourceValue": null,
"value": null,
"dataType": {"typeName": "text"}
}, {
"row": 2,
"col": 3,
"isFormula": false,
"sourceValue": "3",
"value": "3",
"dataType": {"typeName": "text"}
}]]
}]
}, "id": "brick-ssd-1-b02335e7ef7db982"
}

var foo = new BrickSpreadSheet(
container,
);
var foo = new BrickSpreadSheet(container, ss);

var wb = foo.getWorkbookInstance();
var sheet = wb.getActiveSheet();
Expand All @@ -16,6 +112,7 @@ function save() {
}

function test() {
sheet.setFontSize('40px')
}


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spreadsheet",
"version": "0.5.1",
"version": "0.5.2",
"description": "A JavaScript spreedsheet designer based on Handsontable.",
"main": "gulpfile.js",
"scripts": {
Expand Down
64 changes: 32 additions & 32 deletions pro/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@
</style>
</head>
<body>
<input type="button" value="button" onclick="buttonClick()"/>

<input type="button" value="button" id="button"/>
<div id="designer"></div>

<script>
var container = document.getElementById('designer');

var hot = new Handsontable(container, {
data: [
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7]
],
colHeaders: true,
rowHeaders: true,
customBorders: true,
contextMenu: ['borders', 'alignment'],
cell: [
{row: 0, col: 0, type: 'numeric', format: '0.00'}
]
});
document.addEventListener("DOMContentLoaded", function () {

var container = document.getElementById('designer');
var button = document.getElementById('button');

var hot = new Handsontable(container, {
data: [
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7]
],
colHeaders: true,
rowHeaders: true,
contextMenu: ['remove_col'],
manualColumnResize: true
});


hot.addHook('beforeRemoveCol', (index, amount) => {
const mcr = hot.getPlugin('manualColumnResize');
let colWidths = [];
let i = index + amount;
let len = hot.countCols();
for (; i < len; ++i) {
colWidths.push(hot.getColWidth(i));
}
for (i = 0, j = index, len = colWidths.length; i < len; ++i, ++j) {
mcr.setManualSize(j, colWidths[i]);
}
});

hot.setCellMetaObject(0, 0, {
type: 'date',
dateFormat: 'YYYY/MM/DD'
});
hot.setCellMetaObject(0, 1, {
type: 'date',
dateFormat: 'YYYY/MM/DD'
});
hot.render();


function buttonClick() {

}
</script>

</body>
Expand Down
29 changes: 22 additions & 7 deletions src/designer/ConfigTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ConfigTranslator {
constructor(config, sheet) {
this.initialConfig = config;
this.sheet = sheet;
this.spreadSheet = sheet.workbook.spreadSheet;
}


Expand Down Expand Up @@ -144,18 +145,19 @@ class ConfigTranslator {
// 使用 hot API 完成上述功能
settings.minRows = this.sheet.initRows;
settings.minCols = this.sheet.initCols;

settings.data = s;
}
}

// 列宽
_transColWidths(settings) {
var w = this.initialConfig.colWidths;
if (w) {
settings.colWidths = w;
}
}
// NOTE: Handsontable 的 colWidths 有 BUG,设定后将不可以手工改变列宽,
// 试图使用 manualColumnResize 在表格初始化之后来改宽度
// _transColWidths(settings) {
// var w = this.initialConfig.colWidths;
// if (w) {
// settings.colWidths = w;
// }
// }

// 行高
_transRowHeights(settings) {
Expand Down Expand Up @@ -193,6 +195,19 @@ class ConfigTranslator {
}
}

// 列宽
_initColWidths() {
const w = this.initialConfig.colWidths;
const mcr = this.sheet.handsontable.getPlugin('manualColumnResize');
let i, len;

if (w && w.length) {
for (i = 0, len = w.length; i < len; ++i) {
mcr.setManualSize(i, w[i]);
}
}
}

}

export default ConfigTranslator;
1 change: 1 addition & 0 deletions src/designer/HotTableAdaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class HotTableAdaptor extends Handsontable {
TD.style.color = cellProperties._style_color || '';
TD.style.fontFamily = cellProperties._style_fontFamily || '';
TD.style.fontSize = cellProperties._style_fontSize || '';
cellProperties._style_fontSize && (TD.style.lineHeight = cellProperties._style_fontSize);
TD.style.backgroundColor = cellProperties._style_backgroundColor || '';
}, this);

Expand Down
1 change: 1 addition & 0 deletions src/designer/Sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Sheet extends Mixin {
_sheet: this
}, this);
this.handsontable._translator.initSheetState();
this._hack();
this.$$view.hideContent(this.getName());
}

Expand Down
24 changes: 22 additions & 2 deletions src/designer/ext/Sheet_helper.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
export const SheetHelper = Sup => {
return class extends Sup {

// 这个方法用来完成一些填坑操作
_hack() {
var hot = this.handsontable;

// BUG FIXED -> https://github.com/handsontable/handsontable/issues/4375
hot.addHook('beforeRemoveCol', (index, amount) => {
const mcr = hot.getPlugin('manualColumnResize');
let colWidths = [];
let i = index + amount, j;
let len = hot.countCols();
for (; i < len; ++i) {
colWidths.push(hot.getColWidth(i));
}
for (i = 0, j = index, len = colWidths.length; i < len; ++i, ++j) {
mcr.setManualSize(j, colWidths[i]);
}
});
}

// 选区默认值
// 1. 选区可能从右下往左上选,此时 row > endRow
// 2. endRow 及 endCol 可能不存在
//(不需要关注选区方向时调用此方法进行预处理)
_defaultSelection(s) {
s.row > s.endRow && (s.row=[s.endRow, s.endRow=s.row][0]);
s.col > s.endCol && (s.col=[s.endCol, s.endCol=s.col][0]);
s.row > s.endRow && (s.row = [s.endRow, s.endRow = s.row][0]);
s.col > s.endCol && (s.col = [s.endCol, s.endCol = s.col][0]);

return {
startRow: s.row,
Expand Down Expand Up @@ -58,6 +77,7 @@ export const SheetHelper = Sup => {
}


//noinspection JSUnusedGlobalSymbols
_walkonSelection(selection, callback) {
let {startRow, endRow, startCol, endCol} = this._defaultSelection(selection);
for (let i = startRow; i <= endRow; ++i) {
Expand Down
1 change: 0 additions & 1 deletion src/designer/frame/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ ContextMenu.prototype._init = function () {
this.register('row_resize', rowResize, rowResizeHandler);
this.register('col_resize', colResize, colResizeHandler);


this.register('hsep_bt_format', SEP);

this.register('q_merge_cells', mergeCells, mergeCellsHandler);
Expand Down
4 changes: 1 addition & 3 deletions src/designer/frame/ContextMenu_rowOrColumnResize.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,4 @@ function setColWidths(sheet, start, end, value) {
colWidths[i] = value;
}
sheet.handsontable.updateSettings({colWidths: colWidths});
}


}

0 comments on commit 7ff5aac

Please sign in to comment.