Skip to content

Commit

Permalink
Merge branch 'ruilisi:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cybermerlin authored Feb 3, 2023
2 parents a313f9f + acd9d56 commit c8cf4b4
Show file tree
Hide file tree
Showing 23 changed files with 643 additions and 254 deletions.
26 changes: 24 additions & 2 deletions packages/core/src/api/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dataToCelldata, getSheet } from "./common";
import { Context } from "../context";
import { CellMatrix, CellWithRowAndCol, Sheet } from "../types";
import { getSheetIndex } from "../utils";
import { api, locale } from "..";
import { api, execfunction, insertUpdateFunctionGroup, locale } from "..";

export function getAllSheets(ctx: Context) {
return ctx.luckysheetfile;
Expand All @@ -29,7 +29,6 @@ export function initSheetData(
lastRowNum = Math.max(lastRowNum, draftCtx.defaultrowNum);
lastColNum = Math.max(lastColNum, draftCtx.defaultcolumnNum);
}
delete draftCtx.luckysheetfile[index]?.celldata;
if (lastRowNum && lastColNum) {
const expandedData: Sheet["data"] = _.times(lastRowNum, () =>
_.times(lastColNum, () => null)
Expand All @@ -39,9 +38,11 @@ export function initSheetData(
});
if (draftCtx.luckysheetfile[index] == null) {
newData.data = expandedData;
delete newData.celldata;
draftCtx.luckysheetfile.push(newData);
} else {
draftCtx.luckysheetfile[index].data = expandedData;
delete draftCtx.luckysheetfile[index].celldata;
}
return expandedData;
}
Expand Down Expand Up @@ -135,3 +136,24 @@ export function copySheet(ctx: Context, sheetId: string) {
] = order;
api.setSheetOrder(ctx, sheetOrderList);
}

export function calculateSheetFromula(ctx: Context, id: string) {
const index = getSheetIndex(ctx, id) as number;
if (!ctx.luckysheetfile[index].data) return;
for (let r = 0; r < ctx.luckysheetfile[index].data!.length; r += 1) {
for (let c = 0; c < ctx.luckysheetfile[index].data![r].length; c += 1) {
if (!ctx.luckysheetfile[index].data![r][c]?.f) {
continue;
}
const result = execfunction(
ctx,
ctx.luckysheetfile[index].data![r][c]?.f!,
r,
c,
id
);
api.setCellValue(ctx, r, c, result[1], null);
insertUpdateFunctionGroup(ctx, r, c, id);
}
}
}
126 changes: 48 additions & 78 deletions packages/core/src/events/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,16 @@ export function handleCellAreaMouseDown(
// $("#luckysheet-dataVerification-showHintBox").hide();

// 如果右键在选区内, 停止mousedown处理
let isInSelection = false;
_.forEach(ctx.luckysheet_select_save, (obj_s) => {
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.row != null &&
row_index >= obj_s.row[0] &&
row_index <= obj_s.row[1] &&
col_index >= obj_s.column[0] &&
col_index <= obj_s.column[1]
) {
isInSelection = true;
return false;
}
return true;
});

if (isInSelection) {
return;
}
);
if (isInSelection) return;
}

// //单元格数据下钻
Expand Down Expand Up @@ -1436,24 +1428,34 @@ export function handleContextMenu(
const col_pre = col_location[0];
const col_index = col_location[2];
// 如果右键点击在选区内则不做选区处理
let isInSelection = false;
ctx.luckysheet_select_save?.some((obj_s) => {
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.row != null &&
row_index >= obj_s.row[0] &&
row_index <= obj_s.row[1] &&
col_index >= obj_s.column[0] &&
col_index <= obj_s.column[1]
) {
isInSelection = true;
return false;
}
return true;
});

if (isInSelection) {
);
if (!isInSelection && (e.metaKey || e.ctrlKey)) {
// 选区添加
ctx.luckysheet_select_save?.push({
left: col_pre,
width: col - col_pre - 1,
top: row_pre,
height: row - row_pre - 1,
left_move: col_pre,
width_move: col - col_pre - 1,
top_move: row_pre,
height_move: row - row_pre - 1,
row: [row_index, row_index],
column: [col_index, col_index],
row_focus: row_index,
column_focus: col_index,
});
return;
}
if (isInSelection) return;
const row_index_ed = row_index;
const col_index_ed = col_index;
ctx.luckysheet_select_save = [
Expand All @@ -1480,22 +1482,15 @@ export function handleContextMenu(
const row_pre = row_location[0];
const row_index = row_location[2];
// 如果右键点击在选区内则不做选区处理
let isInSelection = false;
ctx.luckysheet_select_save?.some((obj_s) => {
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.row != null &&
row_index >= obj_s.row[0] &&
row_index <= obj_s.row[1]
) {
isInSelection = true;
return false;
}
return true;
});
);

if (isInSelection) {
return;
}
if (isInSelection) return;
const col_index = ctx.visibledatacolumn.length - 1;
const col = ctx.visibledatacolumn[col_index];
const col_pre = 0;
Expand Down Expand Up @@ -1532,22 +1527,15 @@ export function handleContextMenu(
const col_pre = col_location[0];
const col_index = col_location[2];
// 如果右键点击在选区内则不做选区处理
let isInSelection = false;
ctx.luckysheet_select_save?.some((obj_s) => {
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.row != null &&
col_index >= obj_s.column[0] &&
col_index <= obj_s.column[1]
) {
isInSelection = true;
return false;
}
return true;
});
);

if (isInSelection) {
return;
}
if (isInSelection) return;
const left = col_pre;
const width = col - col_pre - 1;
const columnseleted = [col_index, col_index];
Expand Down Expand Up @@ -4355,25 +4343,17 @@ export function handleRowHeaderMouseDown(
// mousedown是右键
if (e.button === 2) {
// 如果右键在选区内, 停止mousedown处理
let isInSelection = false;

const flowdata = getFlowdata(ctx);
_.forEach(ctx.luckysheet_select_save, (obj_s) => {
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.row != null &&
row_index >= obj_s.row[0] &&
row_index <= obj_s.row[1] &&
obj_s.column[0] === 0 &&
obj_s.column[1] === (flowdata?.[0]?.length ?? 0) - 1
) {
isInSelection = true;
return false;
}
return true;
});
if (isInSelection) {
return;
}
);
if (isInSelection) return;
}

let top = row_pre;
Expand Down Expand Up @@ -4687,7 +4667,7 @@ export function handleRowHeaderMouseDown(

ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
last;
} else if (e.ctrlKey) {
} else if (e.ctrlKey || e.metaKey) {
ctx.luckysheet_select_save?.push({
left: colLocationByIndex(0, ctx.visibledatacolumn)[0],
width:
Expand Down Expand Up @@ -4781,27 +4761,17 @@ export function handleColumnHeaderMouseDown(

// mousedown是右键
if (e.button === 2) {
let isInSelection = false;

const flowdata = getFlowdata(ctx);
_.forEach(ctx.luckysheet_select_save, (obj_s) => {
// 如果右键在选区内, 停止mousedown处理
if (
const isInSelection = _.some(
ctx.luckysheet_select_save,
(obj_s) =>
obj_s.column != null &&
col_index >= obj_s.column[0] &&
col_index <= obj_s.column[1] &&
obj_s.row[0] === 0 &&
obj_s.row[1] === (flowdata?.length ?? 0) - 1
) {
isInSelection = true;
return false;
}
return true;
});

if (isInSelection) {
return;
}
);
if (isInSelection) return;
}

let left = col_pre;
Expand Down Expand Up @@ -5093,7 +5063,7 @@ export function handleColumnHeaderMouseDown(

ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
last;
} else if (e.ctrlKey) {
} else if (e.ctrlKey || e.metaKey) {
// 选区添加
ctx.luckysheet_select_save?.push({
left,
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/locale/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
generalDialog: {
partiallyError: "Cannot perform this operation on partially merged cells",
readOnlyError: "Cannot perform this operation in read-only mode",
dataNullError: "Cannot perform this operation on data that does not exist",
},
functionlist: [
{
n: "SUMIF",
Expand Down Expand Up @@ -11493,6 +11498,8 @@ export default {
byRow: "By row",
byCol: "By column",
generateNewMatrix: "Generate new matrix",
noMulti:
"Cannot perform this operation on multiple selection areas, please select a single area",
},
comment: {
insert: "Insert",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/locale/es.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default {
generalDialog: {
partiallyError:
"No se puede realizar esta operación en celdas parcialmente unidas",
readOnlyError: "No se puede realizar esto en modo de solo lectura",
dataNullError: "No se puede hacer esto con datos que no existen",
},
functionlist: [
{
n: "SUMIF",
Expand Down Expand Up @@ -11467,6 +11473,8 @@ export default {
byRow: "Por fila",
byCol: "Por columna",
generateNewMatrix: "Generar nueva matriz",
noMulti:
"No se puede realizar esta operación en varias áreas de selección, selecciona una sola área",
},
comment: {
insert: "Insertar",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/locale/zh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
generalDialog: {
partiallyError: "无法对部分合并单元格执行此操作",
readOnlyError: "无法对只读模式执行此操作",
dataNullError: "无法对不存在的数据执行此操作",
},
functionlist: [
{
n: "SUMIF",
Expand Down Expand Up @@ -11528,6 +11533,7 @@ export default {
byRow: "按行",
byCol: "按列",
generateNewMatrix: "生成新矩阵",
noMulti: "无法对多重选择区域执行此操作,请选择单个区域",
},
comment: {
insert: "新建批注",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/locale/zh_tw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
generalDialog: {
partiallyError: "無法對部分合併儲存格執行此操作",
readOnlyError: "無法對只讀模式執行此操作",
dataNullError: "無法對不存在的數據執行此操作",
},
functionlist: [
{
n: "SUMIF",
Expand Down Expand Up @@ -11498,6 +11503,7 @@ export default {
byRow: "按行",
byCol: "按列",
generateNewMatrix: "生成新矩陣",
noMulti: "無法對多重選擇區域執行此操作,請選擇單個區域",
},
comment: {
insert: "新建批註",
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/modules/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,30 @@ export function luckysheetUpdateCell(
) {
ctx.luckysheetCellUpdate = [row_index, col_index];
}

export function getDataBySelectionNoCopy(ctx: Context, range: Selection) {
if (!range || !range.row || range.row.length === 0) return [];
const data = [];
const flowData = getFlowdata(ctx);
if (!flowData) return [];
for (let r = range.row[0]; r <= range.row[1]; r += 1) {
const row = [];
if (ctx.config.rowhidden != null && ctx.config.rowhidden[r] != null) {
continue;
}
for (let c = range.column[0]; c <= range.column[1]; c += 1) {
let value = null;
if (ctx.config.colhidden != null && ctx.config.colhidden[c] != null) {
continue;
}
if (flowData[r] != null && flowData[r][c] != null) {
value = flowData[r][c];
}

row.push(value);
}

data.push(row);
}
return data;
}
2 changes: 1 addition & 1 deletion packages/core/src/modules/formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ function checkBracketNum(fp: string) {
return true;
}

function insertUpdateFunctionGroup(
export function insertUpdateFunctionGroup(
ctx: Context,
r: number,
c: number,
Expand Down
Loading

0 comments on commit c8cf4b4

Please sign in to comment.