Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(cell hooks add): go to document for detail
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Oct 30, 2020
1 parent f7c609e commit 927ff46
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 6 deletions.
149 changes: 149 additions & 0 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ export default function luckysheetHandler() {
y = mouse[1] + luckysheetFreezen.freezenhorizontaldata[2];
}

let sheetFile = sheetmanage.getSheetByIndex();
let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");

let row_location = rowLocation(y),
row = row_location[1],
row_pre = row_location[0],
Expand All @@ -335,6 +338,18 @@ export default function luckysheetHandler() {
col_index_ed = margeset.column[3];
}


//单元格单击之前
if(!method.createHookFunction("cellMousedownBefore", Store.flowdata[row_index][col_index], {
r:row_index,
c:col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile,luckysheetTableContent)){ return; }


//数据验证 单元格聚焦
dataVerificationCtrl.cellFocus(row_index, col_index, true);

Expand Down Expand Up @@ -1087,6 +1102,15 @@ export default function luckysheetHandler() {

luckysheetContainerFocus();

method.createHookFunction("cellMousedown", Store.flowdata[row_index][col_index], {
r:row_index,
c:col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile,luckysheetTableContent);

//$("#luckysheet-cols-h-c .luckysheet-cols-h-cells-c .luckysheet-cols-h-cells-clip .luckysheet-cols-h-cell-sel").removeClass("luckysheet-cols-h-cell-sel").addClass("luckysheet-cols-h-cell-nosel");

//$("#luckysheet-rows-h .luckysheet-rows-h-cells .luckysheet-rows-h-cells-c .luckysheet-rows-h-cells-clip .luckysheet-rows-h-cell-sel").removeClass("luckysheet-rows-h-cell-sel").addClass("luckysheet-rows-h-cell-nosel");
Expand Down Expand Up @@ -1344,6 +1368,68 @@ export default function luckysheetHandler() {
luckysheetPostil.overshow(event); //有批注显示

window.cancelAnimationFrame(Store.jfautoscrollTimeout);

if(luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMousemove){
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();

let row_location = rowLocation(y),
row = row_location[1],
row_pre = row_location[0],
row_index = row_location[2];
let col_location = colLocation(x),
col = col_location[1],
col_pre = col_location[0],
col_index = col_location[2];

let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
if (!!margeset) {
row = margeset.row[1];
row_pre = margeset.row[0];
row_index = margeset.row[2];

col = margeset.column[1];
col_pre = margeset.column[0];
col_index = margeset.column[2];
}


// if(Store.flowdata[row_index] && Store.flowdata[row_index][col_index]){
let sheetFile = sheetmanage.getSheetByIndex();

let moveState = {
functionResizeStatus:formula.functionResizeStatus,
horizontalmoveState:!!luckysheetFreezen.horizontalmovestate,
verticalmoveState:!!luckysheetFreezen.verticalmovestate,
pivotTableMoveState:!!pivotTable && pivotTable.movestate,
sheetMoveStatus:Store.luckysheet_sheet_move_status,
scrollStatus:!!Store.luckysheet_scroll_status,
selectStatus:!!Store.luckysheet_select_status,
rowsSelectedStatus:!!Store.luckysheet_rows_selected_status,
colsSelectedStatus:!!Store.luckysheet_cols_selected_status,
cellSelectedMove:!!Store.luckysheet_cell_selected_move,
cellSelectedExtend:!!Store.luckysheet_cell_selected_extend,
colsChangeSize:!!Store.luckysheet_cols_change_size,
rowsChangeSize:!!Store.luckysheet_rows_change_size,
chartMove:!!Store.chartparam.luckysheetCurrentChartMove,
chartResize:!!Store.chartparam.luckysheetCurrentChartResize,
rangeResize:!!formula.rangeResize ,
rangeMove:!!formula.rangeMove,
}

let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");

method.createHookFunction("sheetMousemove", Store.flowdata[row_index][col_index], {
r:row_index,
c:col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile,moveState,luckysheetTableContent);
// }
}

if(formula.functionResizeStatus){
let y = event.pageY;
Expand Down Expand Up @@ -3055,6 +3141,69 @@ export default function luckysheetHandler() {
});
//表格mouseup
$(document).on("mouseup.luckysheetEvent",function (event) {

if(luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMouseup){
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();

let row_location = rowLocation(y),
row = row_location[1],
row_pre = row_location[0],
row_index = row_location[2];
let col_location = colLocation(x),
col = col_location[1],
col_pre = col_location[0],
col_index = col_location[2];

let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
if (!!margeset) {
row = margeset.row[1];
row_pre = margeset.row[0];
row_index = margeset.row[2];

col = margeset.column[1];
col_pre = margeset.column[0];
col_index = margeset.column[2];
}


// if(Store.flowdata[row_index] && Store.flowdata[row_index][col_index]){
let sheetFile = sheetmanage.getSheetByIndex();

let moveState = {
functionResizeStatus:formula.functionResizeStatus,
horizontalmoveState:!!luckysheetFreezen.horizontalmovestate,
verticalmoveState:!!luckysheetFreezen.verticalmovestate,
pivotTableMoveState:!!pivotTable && pivotTable.movestate,
sheetMoveStatus:Store.luckysheet_sheet_move_status,
scrollStatus:!!Store.luckysheet_scroll_status,
selectStatus:!!Store.luckysheet_select_status,
rowsSelectedStatus:!!Store.luckysheet_rows_selected_status,
colsSelectedStatus:!!Store.luckysheet_cols_selected_status,
cellSelectedMove:!!Store.luckysheet_cell_selected_move,
cellSelectedExtend:!!Store.luckysheet_cell_selected_extend,
colsChangeSize:!!Store.luckysheet_cols_change_size,
rowsChangeSize:!!Store.luckysheet_rows_change_size,
chartMove:!!Store.chartparam.luckysheetCurrentChartMove,
chartResize:!!Store.chartparam.luckysheetCurrentChartResize,
rangeResize:!!formula.rangeResize ,
rangeMove:!!formula.rangeMove,
}

let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");

method.createHookFunction("sheetMouseup", Store.flowdata[row_index][col_index], {
r:row_index,
c:col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile,moveState,luckysheetTableContent);
// }
}

//数据窗格主体
if (Store.luckysheet_select_status) {
clearTimeout(Store.countfuncTimeout);
Expand Down
1 change: 1 addition & 0 deletions src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { renderChartShow } from '../expendPlugins/chart/plugin';
import {changeSheetContainerSize, menuToolBarWidth} from './resize';
import {zoomNumberDomBind} from './zoom';
import menuButton from './menuButton';
import method from '../global/method';

const sheetmanage = {
generateRandomSheetIndex: function(prefix) {
Expand Down
4 changes: 1 addition & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ luckysheet.create = function (setting) {
Store.lang = extendsetting.lang; //language
Store.allowEdit = extendsetting.allowEdit;
Store.fontList = extendsetting.fontList;
Store.defaultFontSize = extendsetting.defaultFontSize;
server.gridKey = extendsetting.gridKey;
server.loadUrl = extendsetting.loadUrl;
server.updateUrl = extendsetting.updateUrl;
Expand Down Expand Up @@ -105,15 +104,14 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.plugins = extendsetting.plugins;

luckysheetConfigsetting.rowHeaderWidth = extendsetting.rowHeaderWidth;
Store.rowHeaderWidth = extendsetting.rowHeaderWidth;
luckysheetConfigsetting.columeHeaderHeight = extendsetting.columeHeaderHeight;
Store.columeHeaderHeight = extendsetting.columeHeaderHeight;

luckysheetConfigsetting.defaultColWidth = extendsetting.defaultColWidth;
luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight;

luckysheetConfigsetting.title = extendsetting.title;
luckysheetConfigsetting.container = extendsetting.container;
luckysheetConfigsetting.hook = extendsetting.hook;

// Register plugins
initPlugins(extendsetting.plugins , extendsetting.data);
Expand Down
72 changes: 69 additions & 3 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { getBorderInfoCompute } from './border';
import { getSheetIndex } from '../methods/get';
import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util';
import { isInlineStringCell } from '../controllers/inlineString';
import method from './method';
import Store from '../store';
import locale from '../locale/locale';
import sheetmanage from '../controllers/sheetmanage';

function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) {
if (scrollHeight == null) {
Expand Down Expand Up @@ -79,14 +81,21 @@ function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) {
// if(end_r > scrollHeight + drawHeight){
// break;
// }
let firstOffset = (dataset_row_st==r)?-2:0;
let lastOffset = (dataset_row_ed==r)?-2:0;
//列标题单元格渲染前触发,return false 则不渲染该单元格
if(!method.createHookFunction("rowTitleCellRenderBefore", r+1, {
r:r,
top:(start_r + offsetTop + firstOffset),
width:Store.rowHeaderWidth -1,
height:(end_r - start_r + 1+lastOffset-firstOffset)
}, luckysheetTableContent)){ continue; }

if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {

}
else {
luckysheetTableContent.fillStyle = "#ffffff";
let firstOffset = (dataset_row_st==r)?-2:0;
let lastOffset = (dataset_row_ed==r)?-2:0;
luckysheetTableContent.fillRect(
0,
(start_r + offsetTop + firstOffset) ,
Expand Down Expand Up @@ -174,6 +183,14 @@ function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) {

preEndR = end_r;

//列标题单元格渲染前触发,return false 则不渲染该单元格
method.createHookFunction("rowTitleCellRenderAfter", r+1, {
r:r,
top:(start_r + offsetTop + firstOffset),
width:Store.rowHeaderWidth -1,
height:(end_r - start_r + 1+lastOffset-firstOffset)
}, luckysheetTableContent)

}

//行标题栏竖线
Expand Down Expand Up @@ -262,6 +279,14 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) {
// if(end_c > scrollWidth + drawWidth+1){
// break;
// }
let abc = chatatABC(c);
//列标题单元格渲染前触发,return false 则不渲染该单元格
if(!method.createHookFunction("columnTitleCellRenderBefore", abc, {
c:c,
left:(start_c + offsetLeft - 1),
width:(end_c - start_c),
height:Store.columeHeaderHeight -1
}, luckysheetTableContent)){ continue; }

if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) {

Expand All @@ -279,7 +304,7 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) {
//列标题栏序列号
luckysheetTableContent.save();//save scale before draw text
luckysheetTableContent.scale(Store.zoomRatio,Store.zoomRatio);
let abc = chatatABC(c);

let textMetrics = getMeasureText(abc, luckysheetTableContent);
//luckysheetTableContent.measureText(abc);

Expand Down Expand Up @@ -357,6 +382,13 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) {
luckysheetTableContent.closePath();

preEndC = end_c;

method.createHookFunction("columnTitleCellRenderAfter", abc, {
c:c,
left:(start_c + offsetLeft - 1),
width:(end_c - start_c),
height:Store.columeHeaderHeight -1
}, luckysheetTableContent)
}

//列标题栏横线
Expand Down Expand Up @@ -387,6 +419,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
return;
}

let sheetFile = sheetmanage.getSheetByIndex();

// console.trace();
clearTimeout(Store.measureTextCacheTimeOut);
Expand Down Expand Up @@ -571,6 +604,8 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
firstcolumnlen = Store.config["columnlen"][c];
}



if (Store.flowdata[r] != null && Store.flowdata[r][c] != null) {
let value = Store.flowdata[r][c];

Expand Down Expand Up @@ -617,6 +652,18 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
}
}
}
else{
//空单元格渲染前
if(!method.createHookFunction("cellRenderBefore", Store.flowdata[r][c], {
r:r,
c:c,
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
}, sheetFile,luckysheetTableContent)){ continue; }
}


cellupdate.push({
"r": r,
Expand Down Expand Up @@ -663,6 +710,16 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
if(Store.flowdata[r] == null){
continue;
}

//有值单元格渲染前
if(!method.createHookFunction("cellRenderBefore", Store.flowdata[r][c], {
r:r,
c:c,
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
}, sheetFile,luckysheetTableContent)){ continue; }

if(Store.flowdata[r][c] == null){ //空单元格
nullCellRender(r, c, start_r, start_c, end_r, end_c,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05);
Expand Down Expand Up @@ -700,6 +757,15 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
cellRender(r, c, start_r, start_c, end_r, end_c, value,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05);
}
}

method.createHookFunction("cellRenderAfter", Store.flowdata[r][c], {
r:r,
c:c,
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
}, sheetFile,luckysheetTableContent)
}

//合并单元格再处理
Expand Down
Loading

0 comments on commit 927ff46

Please sign in to comment.