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

Commit

Permalink
feat(hook): add hook function
Browse files Browse the repository at this point in the history
1.add hook function:cellAllRenderBefore / updated 2.update docs
  • Loading branch information
mengshukeji committed Nov 20, 2020
1 parent 46684bb commit 215dec2
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 63 deletions.
8 changes: 0 additions & 8 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,6 @@ The hook functions are uniformly configured under ʻoptions.hook`, and configura
- Parameter:
- {Object} [book]:Configuration of the entire workbook (options)

------------
### updateBefore
- Type: Function
- Default: null
- Usage: The method executed before each operation in collaborative editing updates the data. When undoing and redoing, it is also an operation, of course, the hook function will be triggered.
- Parameter:
- {Object} [operate]: The history information of this operation will have different history records according to different operations. Refer to the source code [History](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/controlHistory.js )

------------
### updated
- Type: Function
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开

- 在第1列的位置插入3行空白行

`luckysheet.insertRow(0, { number: 3 })`
`luckysheet.insertColumn(0, { number: 3 })`

------------

Expand Down
23 changes: 13 additions & 10 deletions docs/zh/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ Luckysheet开放了更细致的自定义配置选项,分别有

钩子函数统一配置在`options.hook`下,可以分别针对单元格、sheet页、表格创建配置hook。

> 使用案例可参考源码 [src/index.html](https://github.com/mengshukeji/Luckysheet/blob/master/src/index.html)

## 单元格

### cellRenderBefore
Expand Down Expand Up @@ -643,6 +645,16 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- {Object} [ctx]: 当前画布的context

------------
### cellAllRenderBefore

- 类型:Function
- 默认值:null
- 作用:所有单元格渲染之前执行的方法。在内部,这个方法加在了`luckysheetDrawMain`渲染表格之前。
- 参数:
- {Object} [data]: 当前工作表二维数组数据
- {Object} [sheet]:当前sheet对象
- {Object} [ctx]: 当前画布的context
------------
### cellEditBefore
(TODO)
- 类型:Function
Expand Down Expand Up @@ -1217,18 +1229,9 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 参数:
- {Object} [book]: 整个工作簿的配置(options)

------------
### updateBefore
(TODO)
- 类型:Function
- 默认值:null
- 作用:协同编辑中的每次操作更新数据之前执行的方法,撤销重做时因为也算一次操作,也会触发此钩子函数。
- 参数:
- {Object} [operate]: 本次操作的历史记录信息,根据不同的操作,会有不同的历史记录,参考源码 [历史记录](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/controlHistory.js)

------------
### updated
(TODO)

- 类型:Function
- 默认值:null
- 作用:协同编辑中的每次操作后执行的方法,即客户端每执行一次表格操作,Luckysheet将这次操作存到历史记录中后触发,撤销重做时因为也算一次操作,也会触发此钩子函数。
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/alternateformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ const alternateformat = {
},
ref: function(historyRules, currentRules){
if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = {};
redo["type"] = "updateAF";
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/conditionformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ const conditionformat = {
},
ref: function(historyRules, currentRules){
if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = {};
redo["type"] = "updateCF";
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/controlHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { getSheetIndex } from '../methods/get';
import Store from '../store';
import { selectHightlightShow } from './select';
import method from '../global/method';

function formulaHistoryHanddler(ctr, type="redo"){
if(ctr==null){
Expand Down Expand Up @@ -426,6 +427,9 @@ const controlHistory = {
selectHightlightShow();
}
Store.clearjfundo = true;

// 钩子函数
method.createHookFunction('updated',ctr)
},
undo: function () {
if (Store.jfundo.length == 0) {
Expand Down Expand Up @@ -736,6 +740,7 @@ const controlHistory = {
selectHightlightShow();
}
Store.clearjfundo = true;

}
};

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/dataVerificationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ const dataVerificationCtrl = {
let _this = this;

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = {};
redo["type"] = "updateDataVerification";
Expand All @@ -1557,7 +1557,7 @@ const dataVerificationCtrl = {
let _this = this;

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = {};
redo["type"] = "updateDataVerificationOfCheckbox";
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ function initialFilterHandler(){
redo["caljs"] = caljs;
}

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down Expand Up @@ -1300,7 +1300,7 @@ function initialFilterHandler(){
});
redo["optiongroups"] = optiongroups;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);

$('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).remove();
Expand Down Expand Up @@ -1775,7 +1775,7 @@ function initialFilterHandler(){
redo["caljs"] = caljs;
}

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3634,7 +3634,7 @@ export default function luckysheetHandler() {
let images = imageCtrl.moveChangeSize("row", Store.luckysheet_rows_change_size_start[1], size);

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

Store.jfredo.push({
"type": "resize",
Expand Down Expand Up @@ -3736,7 +3736,7 @@ export default function luckysheetHandler() {
let images = imageCtrl.moveChangeSize("column", Store.luckysheet_cols_change_size_start[1], size);

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

Store.jfredo.push({
"type": "resize",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/hyperlinkCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ const hyperlinkCtrl = {
let _this = this;

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = {};
redo["type"] = "updateHyperlink";
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/imageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ const imageCtrl = {
let images = _this.images;

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

Store.jfredo.push({
"type": "imageCtrl",
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Monitor special variables
*/
import {createProxy} from '../utils/util'
import Store from '../store/index'
const initListener = function(){
createProxy(Store,['jfredo'])
}


export {
initListener
}
6 changes: 3 additions & 3 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ const menuButton = {
cfg["borderInfo"].push(borderInfo);

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = [];

Expand Down Expand Up @@ -1121,7 +1121,7 @@ const menuButton = {
cfg["borderInfo"].push(borderInfo);

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

let redo = [];

Expand Down Expand Up @@ -3356,7 +3356,7 @@ const menuButton = {
}

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push({
"type": "mergeChange",
"sheetIndex": Store.currentSheetIndex,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/pivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ const pivotTable = {
redo["pivotTablecur"] = pivotTable;

if(Store.clearjfundo){
Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/postil.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ const luckysheetPostil = {
},
ref: function(data, rc){
if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;

Store.jfredo.push({
"type": "postil",
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/rowColumnOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ export function rowColumnOperationInitial(){
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down Expand Up @@ -1621,7 +1621,7 @@ export function rowColumnOperationInitial(){
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down Expand Up @@ -1693,7 +1693,7 @@ export function rowColumnOperationInitial(){
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down Expand Up @@ -1733,7 +1733,7 @@ export function rowColumnOperationInitial(){
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}

Expand Down Expand Up @@ -1779,7 +1779,7 @@ export function rowColumnOperationInitial(){
// redo["config"] = $.extend(true, {}, Store.config);
// redo["curconfig"] = cfg;

// Store.jfundo = [];
// Store.jfundo.length = 0;
// Store.jfredo.push(redo);
// }

Expand Down Expand Up @@ -1821,7 +1821,7 @@ export function rowColumnOperationInitial(){
// redo["config"] = $.extend(true, {}, Store.config);
// redo["curconfig"] = cfg;

// Store.jfundo = [];
// Store.jfundo.length = 0;
// Store.jfredo.push(redo);
// }

Expand Down Expand Up @@ -1865,7 +1865,7 @@ export function rowColumnOperationInitial(){
// redo["config"] = $.extend(true, {}, Store.config);
// redo["curconfig"] = cfg;

// Store.jfundo = [];
// Store.jfundo.length = 0;
// Store.jfredo.push(redo);
// }

Expand Down Expand Up @@ -1907,7 +1907,7 @@ export function rowColumnOperationInitial(){
// redo["config"] = $.extend(true, {}, Store.config);
// redo["curconfig"] = cfg;

// Store.jfundo = [];
// Store.jfundo.length = 0;
// Store.jfredo.push(redo);
// }

Expand Down Expand Up @@ -2138,7 +2138,7 @@ export function rowColumnOperationInitial(){
}

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push({
"type": "resize",
"ctrlType": type,
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function showsheetconfigmenu() {
redo["oldcolor"] = oldcolor;
redo["color"] = color;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}
}
Expand All @@ -96,7 +96,7 @@ function showsheetconfigmenu() {
redo["oldcolor"] = oldcolor;
redo["color"] = null;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}
});
Expand Down Expand Up @@ -264,7 +264,7 @@ export function initialSheetBar(){
redo["oldtxt"] = oldtxt;
redo["txt"] = txt;

Store.jfundo = [];
Store.jfundo.length = 0;
Store.jfredo.push(redo);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const sheetmanage = {
server.saveParam("sha", null, $.extend(true, {}, sheetconfig));

if (Store.clearjfundo) {
Store.jfundo = [];
Store.jfundo.length = 0;
let redo = {};
redo["type"] = "addSheet";
redo["sheetconfig"] = $.extend(true, {}, sheetconfig);
Expand Down
2 changes: 2 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import * as api from './global/api';

import flatpickr from 'flatpickr'
import Mandarin from 'flatpickr/dist/l10n/zh.js'
import { initListener } from './controllers/listener';

let luckysheet = {};

Expand Down Expand Up @@ -181,6 +182,7 @@ function initialWorkBook(){
orderByInitial();//menu bar orderby function initialization
zoomInitial();//zoom method initialization
printInitial();//print initialization
initListener();
}

//获取所有表格数据
Expand Down
Loading

0 comments on commit 215dec2

Please sign in to comment.