@fileverse-dev/fortune-core 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/context.d.ts CHANGED
@@ -169,6 +169,7 @@ export type Context = {
169
169
  zoomRatio: number;
170
170
  showGridLines: boolean;
171
171
  allowEdit: boolean;
172
+ isFlvReadOnly: boolean;
172
173
  fontList: any[];
173
174
  defaultFontSize: number;
174
175
  luckysheetPaintModelOn: boolean;
package/es/context.js CHANGED
@@ -235,6 +235,7 @@ export function defaultContext(refs) {
235
235
  zoomRatio: 1,
236
236
  showGridLines: true,
237
237
  allowEdit: true,
238
+ isFlvReadOnly: false,
238
239
  fontList: [],
239
240
  defaultFontSize: 10,
240
241
  luckysheetPaintModelOn: false,
@@ -12,6 +12,7 @@ import _ from "lodash";
12
12
  import { mergeBorder } from "./cell";
13
13
  import { getFlowdata } from "../context";
14
14
  import { colLocation, rowLocation } from "./location";
15
+ import { isAllowEdit } from "../utils";
15
16
  export function getArrowCanvasSize(fromX, fromY, toX, toY) {
16
17
  var left = toX - 5;
17
18
  if (fromX < toX) {
@@ -195,6 +196,8 @@ export function removeEditingComment(ctx, globalCache) {
195
196
  }
196
197
  export function newComment(ctx, globalCache, r, c) {
197
198
  var _a, _b;
199
+ var allowEdit = isAllowEdit(ctx);
200
+ if (!allowEdit) return;
198
201
  if (((_b = (_a = ctx.hooks).beforeInsertComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
199
202
  return;
200
203
  }
@@ -228,6 +231,8 @@ export function newComment(ctx, globalCache, r, c) {
228
231
  }
229
232
  export function editComment(ctx, globalCache, r, c) {
230
233
  var _a;
234
+ var allowEdit = isAllowEdit(ctx);
235
+ if (!allowEdit) return;
231
236
  var flowdata = getFlowdata(ctx);
232
237
  removeEditingComment(ctx, globalCache);
233
238
  var comment = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
@@ -246,6 +251,8 @@ export function editComment(ctx, globalCache, r, c) {
246
251
  }
247
252
  export function deleteComment(ctx, globalCache, r, c) {
248
253
  var _a, _b;
254
+ var allowEdit = isAllowEdit(ctx);
255
+ if (!allowEdit) return;
249
256
  if (((_b = (_a = ctx.hooks).beforeDeleteComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
250
257
  return;
251
258
  }
@@ -443,6 +450,7 @@ export function onCommentBoxResizeStart(ctx, globalCache, e, _a, resizingId, res
443
450
  }
444
451
  }
445
452
  export function onCommentBoxResize(ctx, globalCache, e) {
453
+ if (ctx.allowEdit === false) return false;
446
454
  var commentBox = globalCache === null || globalCache === void 0 ? void 0 : globalCache.commentBox;
447
455
  if ((commentBox === null || commentBox === void 0 ? void 0 : commentBox.resizingId) && commentBox.resizingSide) {
448
456
  var box = document.getElementById(commentBox.resizingId);
@@ -545,6 +553,8 @@ export function onCommentBoxMoveStart(ctx, globalCache, e, _a, movingId) {
545
553
  }
546
554
  }
547
555
  export function onCommentBoxMove(ctx, globalCache, e) {
556
+ var allowEdit = isAllowEdit(ctx);
557
+ if (!allowEdit) return false;
548
558
  var commentBox = globalCache === null || globalCache === void 0 ? void 0 : globalCache.commentBox;
549
559
  if (commentBox === null || commentBox === void 0 ? void 0 : commentBox.movingId) {
550
560
  var box = document.getElementById(commentBox.movingId);
@@ -1,4 +1,4 @@
1
- import { colLocationByIndex, diff, getcellrange, getCellValue, getFlowdata, getRangeByTxt, getSheetIndex, isAllowEdit, iscelldata, isdatetime, isRealNull, isRealNum, jfrefreshgrid, mergeBorder, rowLocationByIndex, setCellValue } from "..";
1
+ import { colLocationByIndex, diff, getcellrange, getCellValue, getFlowdata, getRangeByTxt, getSheetIndex, isAllowEdit, isAllowEditReadOnly, iscelldata, isdatetime, isRealNull, isRealNum, jfrefreshgrid, mergeBorder, rowLocationByIndex, setCellValue } from "..";
2
2
  export function dataRangeSelection(ctx, cache, rangT, type, value) {
3
3
  var _a, _b;
4
4
  ctx.rangeDialog.show = true;
@@ -496,7 +496,8 @@ export function getHintText(ctx, item) {
496
496
  export function cellFocus(ctx, r, c, clickMode) {
497
497
  var _a, _b;
498
498
  var allowEdit = isAllowEdit(ctx);
499
- if (!allowEdit) return;
499
+ var isReadOnly = isAllowEditReadOnly(ctx);
500
+ if (!allowEdit || isReadOnly) return;
500
501
  var showHintBox = document.getElementById("luckysheet-dataVerification-showHintBox");
501
502
  var dropDownBtn = document.getElementById("luckysheet-dataVerification-dropdown-btn");
502
503
  ctx.dataVerificationDropDownList = false;
@@ -2,7 +2,7 @@ import _ from "lodash";
2
2
  import dayjs from "dayjs";
3
3
  import { getFlowdata } from "../context";
4
4
  import { colLocation, rowLocation } from "./location";
5
- import { getSheetIndex, isAllowEdit } from "../utils";
5
+ import { getSheetIndex, isAllowEdit, isAllowEditReadOnly } from "../utils";
6
6
  import { getBorderInfoCompute } from "./border";
7
7
  import { genarate, update } from "./format";
8
8
  import * as formula from "./formula";
@@ -1766,7 +1766,8 @@ export function updateDropCell(ctx) {
1766
1766
  var _e, _f, _g;
1767
1767
  var d = getFlowdata(ctx);
1768
1768
  var allowEdit = isAllowEdit(ctx);
1769
- if (allowEdit === false || d == null) {
1769
+ var isReadOnly = isAllowEditReadOnly(ctx);
1770
+ if (allowEdit === false || d == null || isReadOnly) {
1770
1771
  return;
1771
1772
  }
1772
1773
  var index = getSheetIndex(ctx, ctx.currentSheetId);
@@ -16,3 +16,4 @@ export declare function replaceHtml(temp: string, dataarry: any): string;
16
16
  export declare function getRegExpStr(str: string): string;
17
17
  export declare function chatatABC(n: number): string;
18
18
  export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
19
+ export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
package/es/utils/index.js CHANGED
@@ -170,4 +170,29 @@ export function isAllowEdit(ctx, range) {
170
170
  }
171
171
  return true;
172
172
  }) && (_.isUndefined(ctx.allowEdit) ? true : ctx.allowEdit);
173
+ }
174
+ export function isAllowEditReadOnly(ctx, range) {
175
+ var cfg = ctx.config;
176
+ var judgeRange = _.isUndefined(range) ? ctx.luckysheet_select_save : range;
177
+ return _.every(judgeRange, function (selection) {
178
+ var _a, _b;
179
+ for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
180
+ if ((_a = cfg.rowReadOnly) === null || _a === void 0 ? void 0 : _a[r]) {
181
+ return false;
182
+ }
183
+ }
184
+ for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
185
+ if ((_b = cfg.colReadOnly) === null || _b === void 0 ? void 0 : _b[c]) {
186
+ return false;
187
+ }
188
+ }
189
+ for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
190
+ for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
191
+ if (checkCellIsLocked(ctx, r, c, ctx.currentSheetId)) {
192
+ return false;
193
+ }
194
+ }
195
+ }
196
+ return true;
197
+ }) && (_.isUndefined(ctx.isFlvReadOnly) ? true : ctx.isFlvReadOnly);
173
198
  }
package/lib/context.d.ts CHANGED
@@ -169,6 +169,7 @@ export type Context = {
169
169
  zoomRatio: number;
170
170
  showGridLines: boolean;
171
171
  allowEdit: boolean;
172
+ isFlvReadOnly: boolean;
172
173
  fontList: any[];
173
174
  defaultFontSize: number;
174
175
  luckysheetPaintModelOn: boolean;
package/lib/context.js CHANGED
@@ -247,6 +247,7 @@ function defaultContext(refs) {
247
247
  zoomRatio: 1,
248
248
  showGridLines: true,
249
249
  allowEdit: true,
250
+ isFlvReadOnly: false,
250
251
  fontList: [],
251
252
  defaultFontSize: 10,
252
253
  luckysheetPaintModelOn: false,
@@ -29,6 +29,7 @@ var _lodash = _interopRequireDefault(require("lodash"));
29
29
  var _cell = require("./cell");
30
30
  var _context = require("../context");
31
31
  var _location = require("./location");
32
+ var _utils = require("../utils");
32
33
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
34
  var __assign = void 0 && (void 0).__assign || function () {
34
35
  __assign = Object.assign || function (t) {
@@ -223,6 +224,8 @@ function removeEditingComment(ctx, globalCache) {
223
224
  }
224
225
  function newComment(ctx, globalCache, r, c) {
225
226
  var _a, _b;
227
+ var allowEdit = (0, _utils.isAllowEdit)(ctx);
228
+ if (!allowEdit) return;
226
229
  if (((_b = (_a = ctx.hooks).beforeInsertComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
227
230
  return;
228
231
  }
@@ -256,6 +259,8 @@ function newComment(ctx, globalCache, r, c) {
256
259
  }
257
260
  function editComment(ctx, globalCache, r, c) {
258
261
  var _a;
262
+ var allowEdit = (0, _utils.isAllowEdit)(ctx);
263
+ if (!allowEdit) return;
259
264
  var flowdata = (0, _context.getFlowdata)(ctx);
260
265
  removeEditingComment(ctx, globalCache);
261
266
  var comment = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r][c]) === null || _a === void 0 ? void 0 : _a.ps;
@@ -274,6 +279,8 @@ function editComment(ctx, globalCache, r, c) {
274
279
  }
275
280
  function deleteComment(ctx, globalCache, r, c) {
276
281
  var _a, _b;
282
+ var allowEdit = (0, _utils.isAllowEdit)(ctx);
283
+ if (!allowEdit) return;
277
284
  if (((_b = (_a = ctx.hooks).beforeDeleteComment) === null || _b === void 0 ? void 0 : _b.call(_a, r, c)) === false) {
278
285
  return;
279
286
  }
@@ -471,6 +478,7 @@ function onCommentBoxResizeStart(ctx, globalCache, e, _a, resizingId, resizingSi
471
478
  }
472
479
  }
473
480
  function onCommentBoxResize(ctx, globalCache, e) {
481
+ if (ctx.allowEdit === false) return false;
474
482
  var commentBox = globalCache === null || globalCache === void 0 ? void 0 : globalCache.commentBox;
475
483
  if ((commentBox === null || commentBox === void 0 ? void 0 : commentBox.resizingId) && commentBox.resizingSide) {
476
484
  var box = document.getElementById(commentBox.resizingId);
@@ -573,6 +581,8 @@ function onCommentBoxMoveStart(ctx, globalCache, e, _a, movingId) {
573
581
  }
574
582
  }
575
583
  function onCommentBoxMove(ctx, globalCache, e) {
584
+ var allowEdit = (0, _utils.isAllowEdit)(ctx);
585
+ if (!allowEdit) return false;
576
586
  var commentBox = globalCache === null || globalCache === void 0 ? void 0 : globalCache.commentBox;
577
587
  if (commentBox === null || commentBox === void 0 ? void 0 : commentBox.movingId) {
578
588
  var box = document.getElementById(commentBox.movingId);
@@ -511,7 +511,8 @@ function getHintText(ctx, item) {
511
511
  function cellFocus(ctx, r, c, clickMode) {
512
512
  var _a, _b;
513
513
  var allowEdit = (0, _.isAllowEdit)(ctx);
514
- if (!allowEdit) return;
514
+ var isReadOnly = (0, _.isAllowEditReadOnly)(ctx);
515
+ if (!allowEdit || isReadOnly) return;
515
516
  var showHintBox = document.getElementById("luckysheet-dataVerification-showHintBox");
516
517
  var dropDownBtn = document.getElementById("luckysheet-dataVerification-dropdown-btn");
517
518
  ctx.dataVerificationDropDownList = false;
@@ -1782,7 +1782,8 @@ function updateDropCell(ctx) {
1782
1782
  var _e, _f, _g;
1783
1783
  var d = (0, _context.getFlowdata)(ctx);
1784
1784
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
1785
- if (allowEdit === false || d == null) {
1785
+ var isReadOnly = (0, _utils.isAllowEditReadOnly)(ctx);
1786
+ if (allowEdit === false || d == null || isReadOnly) {
1786
1787
  return;
1787
1788
  }
1788
1789
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
@@ -16,3 +16,4 @@ export declare function replaceHtml(temp: string, dataarry: any): string;
16
16
  export declare function getRegExpStr(str: string): string;
17
17
  export declare function chatatABC(n: number): string;
18
18
  export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
19
+ export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
@@ -17,7 +17,8 @@ var _exportNames = {
17
17
  replaceHtml: true,
18
18
  getRegExpStr: true,
19
19
  chatatABC: true,
20
- isAllowEdit: true
20
+ isAllowEdit: true,
21
+ isAllowEditReadOnly: true
21
22
  };
22
23
  exports.chatatABC = chatatABC;
23
24
  exports.columnCharToIndex = columnCharToIndex;
@@ -31,6 +32,7 @@ exports.getSheetIdByName = getSheetIdByName;
31
32
  exports.getSheetIndex = getSheetIndex;
32
33
  exports.indexToColumnChar = indexToColumnChar;
33
34
  exports.isAllowEdit = isAllowEdit;
35
+ exports.isAllowEditReadOnly = isAllowEditReadOnly;
34
36
  exports.replaceHtml = replaceHtml;
35
37
  exports.rgbToHex = rgbToHex;
36
38
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -228,4 +230,29 @@ function isAllowEdit(ctx, range) {
228
230
  }
229
231
  return true;
230
232
  }) && (_lodash.default.isUndefined(ctx.allowEdit) ? true : ctx.allowEdit);
233
+ }
234
+ function isAllowEditReadOnly(ctx, range) {
235
+ var cfg = ctx.config;
236
+ var judgeRange = _lodash.default.isUndefined(range) ? ctx.luckysheet_select_save : range;
237
+ return _lodash.default.every(judgeRange, function (selection) {
238
+ var _a, _b;
239
+ for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
240
+ if ((_a = cfg.rowReadOnly) === null || _a === void 0 ? void 0 : _a[r]) {
241
+ return false;
242
+ }
243
+ }
244
+ for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
245
+ if ((_b = cfg.colReadOnly) === null || _b === void 0 ? void 0 : _b[c]) {
246
+ return false;
247
+ }
248
+ }
249
+ for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
250
+ for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
251
+ if ((0, _modules.checkCellIsLocked)(ctx, r, c, ctx.currentSheetId)) {
252
+ return false;
253
+ }
254
+ }
255
+ }
256
+ return true;
257
+ }) && (_lodash.default.isUndefined(ctx.isFlvReadOnly) ? true : ctx.isFlvReadOnly);
231
258
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",