@univerjs/sheets-data-validation 0.2.9 → 0.2.11
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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +30 -16
- package/lib/types/index.d.ts +1 -1
- package/lib/types/validators/date-validator.d.ts +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +25 -25
package/lib/es/index.js
CHANGED
|
@@ -2,9 +2,9 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import { DEFAULT_EMPTY_DOCUMENT_VALUE, useDependency, Inject, Disposable, UniverInstanceType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, IUniverInstanceService, toDisposable, CommandType, ICommandService, ObjectMatrix, Range, isFormulaString, ThemeService, VerticalAlign, HorizontalAlign, createInternalEditorID, LocaleService, OnLifecycle, LifecycleStages, IPermissionService, DataValidationType, Tools, DataValidationOperator, DataValidationErrorStyle, UndoCommand, RedoCommand, isUnitRangesEqual, isValidRange, debounce, shallowEqual, Injector, DataValidationRenderMode, numfmt, CellValueType, DEFAULT_STYLES, WrapStrategy, DocumentDataModel, BooleanNumber, Rectangle, IUndoRedoService, sequenceExecuteAsync, sequenceExecute, Optional, RxDisposable, DataValidationStatus, ILogService, isRangesEqual, queryObjectMatrix, IResourceManagerService, DependentOn, Plugin } from "@univerjs/core";
|
|
5
|
+
import { DEFAULT_EMPTY_DOCUMENT_VALUE, useDependency, Inject, Disposable, UniverInstanceType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, IUniverInstanceService, toDisposable, CommandType, ICommandService, ObjectMatrix, Range, isFormulaString, ThemeService, VerticalAlign, HorizontalAlign, createInternalEditorID, LocaleService, OnLifecycle, LifecycleStages, IPermissionService, DataValidationType, Tools, DataValidationOperator, DataValidationErrorStyle, UndoCommand, RedoCommand, isUnitRangesEqual, isValidRange, debounce, shallowEqual, Injector, DataValidationRenderMode, UNIVER_INTERNAL, numfmt, CellValueType, DEFAULT_STYLES, WrapStrategy, DocumentDataModel, BooleanNumber, Rectangle, IUndoRedoService, sequenceExecuteAsync, sequenceExecute, Optional, RxDisposable, DataValidationStatus, ILogService, isRangesEqual, queryObjectMatrix, IResourceManagerService, DependentOn, Plugin } from "@univerjs/core";
|
|
6
6
|
import { DataValidatorRegistryService, DataValidationModel, BaseDataValidator, DataValidatorRegistryScope, TWO_FORMULA_OPERATOR_COUNT as TWO_FORMULA_OPERATOR_COUNT$1, getRuleOptions, getRuleSetting, RemoveDataValidationCommand, createDefaultNewRule, RemoveAllDataValidationCommand, TextLengthErrorTitleMap, AddDataValidationMutation, RemoveDataValidationMutation, UpdateRuleType, UpdateDataValidationMutation, removeDataValidationUndoFactory, DataValidationManager, AddDataValidationCommand, UniverDataValidationPlugin } from "@univerjs/data-validation";
|
|
7
|
-
import { DataValidationModel as DataValidationModel2, RemoveDataValidationCommand as RemoveDataValidationCommand2 } from "@univerjs/data-validation";
|
|
7
|
+
import { DataValidationModel as DataValidationModel2, RemoveAllDataValidationCommand as RemoveAllDataValidationCommand2, RemoveDataValidationCommand as RemoveDataValidationCommand2 } from "@univerjs/data-validation";
|
|
8
8
|
import { SheetsSelectionsService, getSheetCommandTarget, SetRangeValuesCommand, WorksheetViewPermission, checkRangesEditablePermission, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, WorkbookEditablePermission, WorksheetSetCellStylePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, SheetInterceptorService, INTERCEPTOR_POINT, InterceptCellContentPriority, ClearSelectionAllCommand, RefRangeService, handleCommonDefaultRangeChangeWithEffectRefCommands, UniverSheetsPlugin } from "@univerjs/sheets";
|
|
9
9
|
import { SheetCanvasPopManagerService, IMarkSelectionService, IEditorBridgeService, getCurrentRangeDisable$, AutoHeightController, SheetSkeletonManagerService, HoverManagerService, CellAlertManagerService, CellAlertType, IAutoFillService, APPLY_TYPE, virtualizeDiscreteRanges, getAutoFillRepeatRange, COPY_TYPE, rangeToDiscreteRange, PREDEFINED_HOOK_NAME, getRepeatRange, ISheetClipboardService, SheetPermissionInterceptorBaseController, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
|
|
10
10
|
import { useObservable, ComponentManager, IZenZoneService, ISidebarService, TextEditor, useEvent, RangeSelector, KeyCode, IDialogService, MenuItemType, MenuPosition, MenuGroup, getMenuHiddenObservable, IMenuService } from "@univerjs/ui";
|
|
@@ -801,7 +801,7 @@ function getDataValidationCellValue(cellData) {
|
|
|
801
801
|
}
|
|
802
802
|
__name(getDataValidationCellValue, "getDataValidationCellValue");
|
|
803
803
|
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN", DROP_DOWN_DEFAULT_COLOR = "#ECECEC";
|
|
804
|
-
var
|
|
804
|
+
var P = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(P || {}), __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
805
805
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
806
806
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
807
807
|
return kind && result && __defProp$f(target, key, result), result;
|
|
@@ -834,7 +834,7 @@ let DataValidationFormulaController = (_a5 = class extends Disposable {
|
|
|
834
834
|
for (let i2 = startRow; i2 <= endRow; i2++)
|
|
835
835
|
for (let j = startColumn; j <= endColumn; j++) {
|
|
836
836
|
const permission = (_b = (_a22 = targetSheet.getCell(i2, j)) == null ? void 0 : _a22.selectionProtection) == null ? void 0 : _b[0];
|
|
837
|
-
if ((permission == null ? void 0 : permission[
|
|
837
|
+
if ((permission == null ? void 0 : permission[P.View]) === !1)
|
|
838
838
|
return !1;
|
|
839
839
|
}
|
|
840
840
|
}
|
|
@@ -1792,6 +1792,7 @@ let DataValidationRejectInputController = (_a6 = class extends Disposable {
|
|
|
1792
1792
|
this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT_ASYNC,
|
|
1793
1793
|
{
|
|
1794
1794
|
handler: /* @__PURE__ */ __name(async (cellPromise, context, next) => {
|
|
1795
|
+
var _a22, _b, _c;
|
|
1795
1796
|
const cell = await cellPromise, { worksheet, row, col, unitId, subUnitId, workbook } = context, manager = this._dataValidationModel.ensureManager(unitId, subUnitId), ruleId = manager.getRuleIdByLocation(row, col), rule = ruleId ? manager.getRuleById(ruleId) : void 0;
|
|
1796
1797
|
if (!rule || rule.errorStyle !== DataValidationErrorStyle.STOP)
|
|
1797
1798
|
return next(Promise.resolve(cell));
|
|
@@ -1799,7 +1800,7 @@ let DataValidationRejectInputController = (_a6 = class extends Disposable {
|
|
|
1799
1800
|
if (!validator || await validator.validator(
|
|
1800
1801
|
{
|
|
1801
1802
|
value: getCellValueOrigin(cell),
|
|
1802
|
-
interceptValue: getCellValueOrigin(cell),
|
|
1803
|
+
interceptValue: getCellValueOrigin((_c = (_b = (_a22 = cell == null ? void 0 : cell.custom) == null ? void 0 : _a22[UNIVER_INTERNAL]) == null ? void 0 : _b.origin) != null ? _c : cell),
|
|
1803
1804
|
row,
|
|
1804
1805
|
column: col,
|
|
1805
1806
|
unitId,
|
|
@@ -1882,7 +1883,7 @@ const transformDate = /* @__PURE__ */ __name((value) => {
|
|
|
1882
1883
|
if (value == null || typeof value == "boolean")
|
|
1883
1884
|
return;
|
|
1884
1885
|
if (typeof value == "number" || !Number.isNaN(+value))
|
|
1885
|
-
return dayjs(numfmt.format("yyyy-MM-dd HH:mm:ss", value));
|
|
1886
|
+
return dayjs(numfmt.format("yyyy-MM-dd HH:mm:ss", Number(value)));
|
|
1886
1887
|
const date = dayjs(value);
|
|
1887
1888
|
if (date.isValid())
|
|
1888
1889
|
return date;
|
|
@@ -2048,8 +2049,8 @@ const FORMULA1$1 = "{FORMULA1}", FORMULA2$1 = "{FORMULA2}", transformDate2Serial
|
|
|
2048
2049
|
};
|
|
2049
2050
|
}
|
|
2050
2051
|
async isValidType(info) {
|
|
2051
|
-
const { interceptValue } = info;
|
|
2052
|
-
return typeof interceptValue == "string" ? !!numfmt.parseDate(interceptValue) : !1;
|
|
2052
|
+
const { interceptValue, value } = info;
|
|
2053
|
+
return typeof value == "number" && typeof interceptValue == "string" ? !0 : typeof interceptValue == "string" ? !!numfmt.parseDate(interceptValue) : !1;
|
|
2053
2054
|
}
|
|
2054
2055
|
_validatorSingleFormula(formula) {
|
|
2055
2056
|
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) || !!formula && dayjs(formula).isValid());
|
|
@@ -3017,7 +3018,18 @@ const UpdateSheetDataValidationRangeCommand = {
|
|
|
3017
3018
|
type: CommandType.COMMAND,
|
|
3018
3019
|
id: "sheets.command.clear-range-data-validation",
|
|
3019
3020
|
handler(accessor, params) {
|
|
3020
|
-
|
|
3021
|
+
if (!params)
|
|
3022
|
+
return !1;
|
|
3023
|
+
const { unitId, subUnitId, ranges } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId }), dataValidationModel = accessor.get(DataValidationModel);
|
|
3024
|
+
if (!target) return !1;
|
|
3025
|
+
const undoRedoService = accessor.get(IUndoRedoService), manager = dataValidationModel.ensureManager(unitId, subUnitId), matrix = manager.getRuleObjectMatrix().clone();
|
|
3026
|
+
matrix.removeRange(ranges);
|
|
3027
|
+
const diffs = matrix.diff(manager.getDataValidations()), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
3028
|
+
return undoRedoService.pushUndoRedo({
|
|
3029
|
+
unitID: unitId,
|
|
3030
|
+
redoMutations,
|
|
3031
|
+
undoMutations
|
|
3032
|
+
}), sequenceExecute(redoMutations, commandService).result;
|
|
3021
3033
|
}
|
|
3022
3034
|
}, DataValidationIcon = "data-validation-single", DATA_VALIDATION_MENU_ID = "sheet.menu.data-validation";
|
|
3023
3035
|
function dataValidationMenuFactory(accessor) {
|
|
@@ -3144,7 +3156,7 @@ let SheetsDataValidationRenderController = (_a8 = class extends RxDisposable {
|
|
|
3144
3156
|
priority: InterceptCellContentPriority.DATA_VALIDATION,
|
|
3145
3157
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
3146
3158
|
handler: /* @__PURE__ */ __name((cell, pos, next) => {
|
|
3147
|
-
var _a22, _b, _c, _d, _e, _f;
|
|
3159
|
+
var _a22, _b, _c, _d, _e, _f, _g;
|
|
3148
3160
|
const { row, col, unitId, subUnitId, workbook, worksheet } = pos, manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
|
|
3149
3161
|
if (!manager)
|
|
3150
3162
|
return next(cell);
|
|
@@ -3202,13 +3214,14 @@ let SheetsDataValidationRenderController = (_a8 = class extends RxDisposable {
|
|
|
3202
3214
|
fontRenderExtension: {
|
|
3203
3215
|
// @ts-ignore
|
|
3204
3216
|
...cell == null ? void 0 : cell.fontRenderExtension,
|
|
3205
|
-
|
|
3217
|
+
// @ts-ignore
|
|
3218
|
+
isSkip: ((_f = cell == null ? void 0 : cell.fontRenderExtension) == null ? void 0 : _f.isSkip) || (validator == null ? void 0 : validator.skipDefaultFontRender(rule, cellValue, pos))
|
|
3206
3219
|
},
|
|
3207
3220
|
interceptorStyle: {
|
|
3208
3221
|
...cell == null ? void 0 : cell.interceptorStyle,
|
|
3209
3222
|
...extra.interceptorStyle
|
|
3210
3223
|
},
|
|
3211
|
-
|
|
3224
|
+
interceptorAutoHeight: /* @__PURE__ */ __name(() => {
|
|
3212
3225
|
var _a23, _b2, _c2, _d2;
|
|
3213
3226
|
const mergeCell = skeleton.mergeData.find((range) => {
|
|
3214
3227
|
const { startColumn, startRow, endColumn, endRow } = range;
|
|
@@ -3233,8 +3246,8 @@ let SheetsDataValidationRenderController = (_a8 = class extends RxDisposable {
|
|
|
3233
3246
|
worksheet
|
|
3234
3247
|
};
|
|
3235
3248
|
return (_d2 = (_c2 = validator == null ? void 0 : validator.canvasRender) == null ? void 0 : _c2.calcCellAutoHeight) == null ? void 0 : _d2.call(_c2, info);
|
|
3236
|
-
},
|
|
3237
|
-
coverable: ((
|
|
3249
|
+
}, "interceptorAutoHeight"),
|
|
3250
|
+
coverable: ((_g = cell == null ? void 0 : cell.coverable) != null ? _g : !0) && !(rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE)
|
|
3238
3251
|
});
|
|
3239
3252
|
}, "handler")
|
|
3240
3253
|
}
|
|
@@ -3364,7 +3377,7 @@ let SheetsDataValidationMobileRenderController = (_a9 = class extends RxDisposab
|
|
|
3364
3377
|
...cell == null ? void 0 : cell.interceptorStyle,
|
|
3365
3378
|
...extra.interceptorStyle
|
|
3366
3379
|
},
|
|
3367
|
-
|
|
3380
|
+
interceptorAutoHeight: /* @__PURE__ */ __name(() => {
|
|
3368
3381
|
var _a23, _b2, _c2, _d2;
|
|
3369
3382
|
const mergeCell = skeleton.mergeData.find((range) => {
|
|
3370
3383
|
const { startColumn, startRow, endColumn, endRow } = range;
|
|
@@ -3389,7 +3402,7 @@ let SheetsDataValidationMobileRenderController = (_a9 = class extends RxDisposab
|
|
|
3389
3402
|
workbook
|
|
3390
3403
|
};
|
|
3391
3404
|
return (_d2 = (_c2 = validator == null ? void 0 : validator.canvasRender) == null ? void 0 : _c2.calcCellAutoHeight) == null ? void 0 : _d2.call(_c2, info);
|
|
3392
|
-
}
|
|
3405
|
+
}, "interceptorAutoHeight")
|
|
3393
3406
|
});
|
|
3394
3407
|
}, "handler")
|
|
3395
3408
|
}
|
|
@@ -4869,6 +4882,7 @@ export {
|
|
|
4869
4882
|
DataValidationModel2 as DataValidationModel,
|
|
4870
4883
|
HideDataValidationDropdown,
|
|
4871
4884
|
OpenValidationPanelOperation,
|
|
4885
|
+
RemoveAllDataValidationCommand2 as RemoveSheetAllDataValidationCommand,
|
|
4872
4886
|
RemoveDataValidationCommand2 as RemoveSheetDataValidationCommand,
|
|
4873
4887
|
SheetDataValidationManager,
|
|
4874
4888
|
SheetsDataValidationValidatorService,
|
package/lib/types/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export { DataValidationFormulaService } from './services/dv-formula.service';
|
|
|
21
21
|
export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
|
|
22
22
|
export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
|
|
23
23
|
export { SheetsDataValidationValidatorService } from './services/dv-validator-service';
|
|
24
|
-
export { DataValidationModel } from '@univerjs/data-validation';
|
|
24
|
+
export { DataValidationModel, RemoveAllDataValidationCommand as RemoveSheetAllDataValidationCommand, type IRemoveAllDataValidationCommandParams as IRemoveSheetAllDataValidationCommandParams, } from '@univerjs/data-validation';
|
|
25
25
|
export { SheetDataValidationManager } from './models/sheet-data-validation-manager';
|
|
26
26
|
export { RemoveDataValidationCommand as RemoveSheetDataValidationCommand, type IRemoveDataValidationCommandParams as IRemoveSheetDataValidationCommandParams, } from '@univerjs/data-validation';
|
|
27
27
|
export { UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationSettingCommand, AddSheetDataValidationCommand, AddSheetDataValidationAndOpenCommand, ClearRangeDataValidationCommand, type IAddSheetDataValidationCommandParams, type IUpdateSheetDataValidationRangeCommandParams, type IUpdateSheetDataValidationOptionsCommandParams, type IUpdateSheetDataValidationSettingCommandParams, type IClearRangeDataValidationCommandParams, } from './commands/commands/data-validation.command';
|
|
@@ -11,8 +11,8 @@ export declare class DateValidator extends BaseDataValidator<number> {
|
|
|
11
11
|
private _formulaService;
|
|
12
12
|
parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<number | undefined>>;
|
|
13
13
|
parseFormulaSync(rule: IDataValidationRule, unitId: string, subUnitId: string): {
|
|
14
|
-
formula1:
|
|
15
|
-
formula2:
|
|
14
|
+
formula1: number | undefined;
|
|
15
|
+
formula2: number | undefined;
|
|
16
16
|
};
|
|
17
17
|
isValidType(info: IValidatorCellInfo): Promise<boolean>;
|
|
18
18
|
private _validatorSingleFormula;
|