| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- var J = Object.defineProperty;
- var z = (t, e, r) => e in t ? J(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
- var c = (t, e, r) => z(t, typeof e != "symbol" ? e + "" : e, r);
- import { Disposable as B, Tools as x, ILogService as N, Inject as O, UniverInstanceType as $, IResourceManagerService as K, IUniverInstanceService as Y, toDisposable as X, CommandType as E, ICommandService as T, IUndoRedoService as A, Plugin as Z, merge as k, Injector as G, IConfigService as ee, DataValidationOperator as s, LocaleService as te } from "@univerjs/core";
- import { Subject as ae, debounceTime as re, BehaviorSubject as oe } from "rxjs";
- function q(t) {
- return {
- type: t.type,
- operator: t.operator,
- formula1: t.formula1,
- formula2: t.formula2,
- allowBlank: t.allowBlank
- };
- }
- function H(t) {
- return {
- error: t.error,
- errorStyle: t.errorStyle,
- errorTitle: t.errorTitle,
- imeMode: t.imeMode,
- prompt: t.prompt,
- promptTitle: t.promptTitle,
- showDropDown: t.showDropDown,
- showErrorMessage: t.showErrorMessage,
- showInputMessage: t.showInputMessage,
- renderMode: t.renderMode,
- bizInfo: t.bizInfo
- };
- }
- var h = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(h || {}), ne = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, se = (t, e, r, a) => {
- for (var o = a > 1 ? void 0 : a ? ie(e, r) : e, n = t.length - 1, i; n >= 0; n--)
- (i = t[n]) && (o = (a ? i(e, r, o) : i(o)) || o);
- return a && o && ne(e, r, o), o;
- }, de = (t, e) => (r, a) => e(r, a, t);
- let m = class extends B {
- constructor(e) {
- super();
- c(this, "_model", /* @__PURE__ */ new Map());
- c(this, "_ruleChange$", new ae());
- c(this, "ruleChange$", this._ruleChange$.asObservable());
- c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(re(20)));
- this._logService = e, this.disposeWithMe({
- dispose: () => {
- this._ruleChange$.complete();
- }
- });
- }
- _ensureMap(e, r) {
- this._model.has(e) || this._model.set(e, /* @__PURE__ */ new Map());
- const a = this._model.get(e);
- if (a.has(r))
- return a.get(r);
- const o = { map: /* @__PURE__ */ new Map(), list: [] };
- return a.set(r, o), o;
- }
- _addSubUnitRule(e, r, a) {
- const { map: o, list: n } = e, l = (Array.isArray(r) ? r : [r]).filter((d) => !o.has(d.uid));
- typeof a == "number" && a < n.length ? n.splice(a, 0, ...l) : n.push(...l), l.forEach((d) => {
- o.set(d.uid, d);
- });
- }
- _removeSubUnitRule(e, r) {
- const { map: a, list: o } = e, n = o.findIndex((i) => i.uid === r);
- n > -1 && (o.splice(n, 1), a.delete(r));
- }
- _updateSubUnitRule(e, r, a) {
- const { map: o, list: n } = e, i = o.get(r), l = n.findIndex((u) => r === u.uid);
- if (!i)
- throw new Error(`Data validation rule is not found, ruleId: ${r}.`);
- const d = { ...i };
- switch (a.type) {
- case h.RANGE: {
- d.ranges = a.payload;
- break;
- }
- case h.SETTING: {
- Object.assign(d, q(a.payload));
- break;
- }
- case h.OPTIONS: {
- Object.assign(d, H(a.payload));
- break;
- }
- case h.ALL: {
- Object.assign(d, a.payload);
- break;
- }
- }
- return n[l] = d, o.set(r, d), d;
- }
- _addRuleSideEffect(e, r, a, o) {
- if (!this._ensureMap(e, r).map.get(a.uid))
- return {
- rule: a,
- type: "add",
- unitId: e,
- subUnitId: r,
- source: o
- };
- }
- addRule(e, r, a, o, n) {
- try {
- const i = this._ensureMap(e, r), d = (Array.isArray(a) ? a : [a]).map((u) => this._addRuleSideEffect(e, r, u, o));
- this._addSubUnitRule(i, a, n), d.forEach((u) => {
- u && this._ruleChange$.next(u);
- });
- } catch (i) {
- this._logService.error(i);
- }
- }
- updateRule(e, r, a, o, n) {
- try {
- const i = this._ensureMap(e, r), l = x.deepClone(i.map.get(a));
- if (!l)
- throw new Error(`Data validation rule is not found, ruleId: ${a}.`);
- const d = this._updateSubUnitRule(i, a, o);
- this._ruleChange$.next({
- rule: d,
- type: "update",
- unitId: e,
- subUnitId: r,
- source: n,
- updatePayload: o,
- oldRule: l
- });
- } catch (i) {
- this._logService.error(i);
- }
- }
- removeRule(e, r, a, o) {
- try {
- const n = this._ensureMap(e, r), i = n.map.get(a);
- i && (this._removeSubUnitRule(n, a), this._ruleChange$.next({
- rule: i,
- type: "remove",
- unitId: e,
- subUnitId: r,
- source: o
- }));
- } catch (n) {
- this._logService.error(n);
- }
- }
- getRuleById(e, r, a) {
- return this._ensureMap(e, r).map.get(a);
- }
- getRuleIndex(e, r, a) {
- return this._ensureMap(e, r).list.findIndex((n) => n.uid === a);
- }
- getRules(e, r) {
- return [...this._ensureMap(e, r).list];
- }
- getUnitRules(e) {
- const r = this._model.get(e);
- if (!r)
- return [];
- const a = [];
- return r.forEach((o, n) => {
- a.push([n, o.list]);
- }), a;
- }
- deleteUnitRules(e) {
- this._model.delete(e);
- }
- getSubUnitIds(e) {
- var r, a;
- return Array.from((a = (r = this._model.get(e)) == null ? void 0 : r.keys()) != null ? a : []);
- }
- getAll() {
- return Array.from(this._model.keys()).map((e) => [e, this.getUnitRules(e)]);
- }
- };
- m = se([
- de(0, N)
- ], m);
- var le = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, ce = (t, e, r, a) => {
- for (var o = a > 1 ? void 0 : a ? ue(e, r) : e, n = t.length - 1, i; n >= 0; n--)
- (i = t[n]) && (o = (a ? i(e, r, o) : i(o)) || o);
- return a && o && le(e, r, o), o;
- }, y = (t, e) => (r, a) => e(r, a, t);
- const pe = "SHEET_DATA_VALIDATION_PLUGIN";
- let I = class extends B {
- constructor(t, e, r) {
- super(), this._resourceManagerService = t, this._univerInstanceService = e, this._dataValidationModel = r, this._initSnapshot();
- }
- _initSnapshot() {
- const t = (r) => {
- const a = this._dataValidationModel.getUnitRules(r), o = {};
- return a ? (a.forEach(([n, i]) => {
- o[n] = i;
- }), JSON.stringify(o)) : "";
- }, e = (r) => {
- if (!r)
- return {};
- try {
- return JSON.parse(r);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- pluginName: pe,
- businesses: [$.UNIVER_SHEET],
- toJson: (r) => t(r),
- parseJson: (r) => e(r),
- onUnLoad: (r) => {
- this._dataValidationModel.deleteUnitRules(r);
- },
- onLoad: (r, a) => {
- Object.keys(a).forEach((o) => {
- a[o].forEach((i) => {
- this._dataValidationModel.addRule(r, o, i, "patched");
- });
- });
- }
- })
- );
- }
- };
- I = ce([
- y(0, K),
- y(1, Y),
- y(2, O(m))
- ], I);
- var me = /* @__PURE__ */ ((t) => (t.SHEET = "sheet", t))(me || {});
- class j {
- constructor() {
- c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
- c(this, "_validatorMap", /* @__PURE__ */ new Map());
- c(this, "_validatorsChange$", new oe(void 0));
- c(this, "validatorsChange$", this._validatorsChange$.asObservable());
- }
- _addValidatorToScope(e, r) {
- this._validatorByScopes.has(r) || this._validatorByScopes.set(r, []);
- const a = this._validatorByScopes.get(r);
- if (a.findIndex((o) => o.id === e.id) > -1)
- throw new Error(`Validator item with the same id ${e.id} has already been added!`);
- a.push(e);
- }
- _removeValidatorFromScope(e, r) {
- const a = this._validatorByScopes.get(r);
- if (!a)
- return;
- const o = a.findIndex((n) => n.id === e.id);
- o > -1 && a.splice(o, 1);
- }
- register(e) {
- return this._validatorMap.set(e.id, e), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
- this._addValidatorToScope(e, r);
- }) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(), X(() => {
- this._validatorMap.delete(e.id), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
- this._removeValidatorFromScope(e, r);
- }) : this._removeValidatorFromScope(e, e.scopes), this._validatorsChange$.next();
- });
- }
- getValidatorItem(e) {
- return this._validatorMap.get(e);
- }
- getValidatorsByScope(e) {
- return this._validatorByScopes.get(e);
- }
- }
- const S = {
- type: E.MUTATION,
- id: "data-validation.mutation.addRule",
- handler(t, e) {
- if (!e)
- return !1;
- const { unitId: r, subUnitId: a, rule: o, index: n, source: i = "command" } = e;
- return t.get(m).addRule(r, a, o, i, n), !0;
- }
- }, v = {
- type: E.MUTATION,
- id: "data-validation.mutation.removeRule",
- handler(t, e) {
- if (!e)
- return !1;
- const { unitId: r, subUnitId: a, ruleId: o, source: n = "command" } = e, i = t.get(m);
- return Array.isArray(o) ? o.forEach((l) => {
- i.removeRule(r, a, l, n);
- }) : i.removeRule(r, a, o, n), !0;
- }
- }, f = {
- type: E.MUTATION,
- id: "data-validation.mutation.updateRule",
- handler(t, e) {
- if (!e)
- return !1;
- const { unitId: r, subUnitId: a, ruleId: o, payload: n, source: i = "command" } = e;
- return t.get(m).updateRule(r, a, o, n, i), !0;
- }
- }, he = {
- type: E.COMMAND,
- id: "data-validation.command.addRule",
- async handler(t, e) {
- if (t.get(N).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
- return !1;
- const { rule: a, unitId: o, subUnitId: n } = e, i = t.get(T), l = t.get(A), d = {
- ...e,
- rule: {
- ...e.rule,
- ranges: [e.rule.range]
- }
- }, u = [{
- id: S.id,
- params: d
- }], p = [{
- id: v.id,
- params: {
- unitId: o,
- subUnitId: n,
- ruleId: a.uid
- }
- }];
- return l.pushUndoRedo({
- unitID: o,
- redoMutations: u,
- undoMutations: p
- }), await i.executeCommand(S.id, d), !0;
- }
- }, _e = {
- type: E.COMMAND,
- id: "data-validation.command.removeRule",
- handler(t, e) {
- if (t.get(N).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
- return !1;
- const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(T), l = t.get(A), d = t.get(m), u = [{
- id: v.id,
- params: e
- }], p = [{
- id: S.id,
- params: {
- unitId: a,
- subUnitId: o,
- rule: {
- ...d.getRuleById(a, o, n)
- },
- index: d.getRuleIndex(a, o, n)
- }
- }];
- return l.pushUndoRedo({
- undoMutations: p,
- redoMutations: u,
- unitID: e.unitId
- }), i.executeCommand(v.id, e), !0;
- }
- }, Ee = {
- type: E.COMMAND,
- id: "data-validation.command.updateDataValidationSetting",
- handler(t, e) {
- if (t.get(N).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
- return !1;
- const a = t.get(T), o = t.get(A), n = t.get(m), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, p = n.getRuleById(i, l, d);
- if (!p)
- return !1;
- const _ = {
- unitId: i,
- subUnitId: l,
- ruleId: d,
- payload: {
- type: h.OPTIONS,
- payload: u
- }
- }, g = [{
- id: f.id,
- params: _
- }], M = {
- unitId: i,
- subUnitId: l,
- ruleId: d,
- payload: {
- type: h.OPTIONS,
- payload: H(p)
- }
- }, R = [{
- id: f.id,
- params: M
- }];
- return o.pushUndoRedo({
- unitID: i,
- redoMutations: g,
- undoMutations: R
- }), a.executeCommand(f.id, _), !0;
- }
- }, ge = {
- type: E.COMMAND,
- id: "data-validation.command.updateDataValidationOptions",
- handler(t, e) {
- if (t.get(N).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
- return !1;
- const a = t.get(T), o = t.get(A), n = t.get(m), i = t.get(j), { unitId: l, subUnitId: d, ruleId: u, setting: p } = e, _ = i.getValidatorItem(p.type);
- if (!_)
- return !1;
- const g = n.getRuleById(l, d, u);
- if (!g)
- return !1;
- const M = { ...g, ...p };
- if (!_.validatorFormula(M, l, d).success)
- return !1;
- const R = {
- unitId: l,
- subUnitId: d,
- ruleId: u,
- payload: {
- type: h.SETTING,
- payload: {
- ...p,
- ..._.normalizeFormula(M, l, d)
- }
- }
- }, Q = [{
- id: f.id,
- params: R
- }], F = {
- unitId: l,
- subUnitId: d,
- ruleId: u,
- payload: {
- type: h.SETTING,
- payload: q(g)
- }
- }, W = [{
- id: f.id,
- params: F
- }];
- return o.pushUndoRedo({
- unitID: l,
- redoMutations: Q,
- undoMutations: W
- }), a.executeCommand(f.id, R), !0;
- }
- }, fe = {
- type: E.COMMAND,
- id: "data-validation.command.removeAll",
- handler(t, e) {
- if (t.get(N).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
- return !1;
- const { unitId: a, subUnitId: o } = e, n = t.get(T), i = t.get(m), l = t.get(A), d = [...i.getRules(a, o)], u = {
- unitId: a,
- subUnitId: o,
- ruleId: d.map((g) => g.uid)
- }, p = [{
- id: v.id,
- params: u
- }], _ = [{
- id: S.id,
- params: {
- unitId: a,
- subUnitId: o,
- rule: d
- }
- }];
- return l.pushUndoRedo({
- redoMutations: p,
- undoMutations: _,
- unitID: a
- }), n.executeCommand(v.id, u), !0;
- }
- }, ve = "data-validation.config", U = {};
- var Ne = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, Se = (t, e, r, a) => {
- for (var o = a > 1 ? void 0 : a ? Te(e, r) : e, n = t.length - 1, i; n >= 0; n--)
- (i = t[n]) && (o = (a ? i(e, r, o) : i(o)) || o);
- return a && o && Ne(e, r, o), o;
- }, L = (t, e) => (r, a) => e(r, a, t);
- const Ae = "UNIVER_DATA_VALIDATION_PLUGIN";
- var V;
- let D = (V = class extends Z {
- constructor(t = U, e, r, a) {
- super(), this._config = t, this._injector = e, this._commandService = r, this._configService = a;
- const { ...o } = k(
- {},
- U,
- this._config
- );
- this._configService.setConfig(ve, o);
- }
- onStarting() {
- [
- [m],
- [j],
- [I]
- ].forEach((t) => this._injector.add(t)), [
- // command
- he,
- fe,
- Ee,
- ge,
- _e,
- // mutation
- S,
- f,
- v
- ].forEach((t) => {
- this._commandService.registerCommand(t);
- });
- }
- onReady() {
- this._injector.get(I);
- }
- }, c(V, "pluginName", Ae), c(V, "type", $.UNIVER_SHEET), V);
- D = Se([
- L(1, O(G)),
- L(2, T),
- L(3, ee)
- ], D);
- s.BETWEEN + "", s.EQUAL + "", s.GREATER_THAN + "", s.GREATER_THAN_OR_EQUAL + "", s.LESS_THAN + "", s.LESS_THAN_OR_EQUAL + "", s.NOT_BETWEEN + "", s.NOT_EQUAL + "";
- const Me = {
- [s.BETWEEN]: "dataValidation.ruleName.between",
- [s.EQUAL]: "dataValidation.ruleName.equal",
- [s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
- [s.LESS_THAN]: "dataValidation.ruleName.lessThan",
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
- [s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
- [s.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
- }, Re = {
- [s.BETWEEN]: "dataValidation.errorMsg.between",
- [s.EQUAL]: "dataValidation.errorMsg.equal",
- [s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
- [s.LESS_THAN]: "dataValidation.errorMsg.lessThan",
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
- [s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
- [s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
- }, we = {
- [s.BETWEEN]: "dataValidation.textLength.errorMsg.between",
- [s.EQUAL]: "dataValidation.textLength.errorMsg.equal",
- [s.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual",
- [s.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan",
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
- [s.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
- [s.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
- }, be = [
- s.BETWEEN,
- s.NOT_BETWEEN
- ];
- var Ve = Object.defineProperty, Oe = Object.getOwnPropertyDescriptor, Ie = (t, e, r, a) => {
- for (var o = a > 1 ? void 0 : a ? Oe(e, r) : e, n = t.length - 1, i; n >= 0; n--)
- (i = t[n]) && (o = (a ? i(e, r, o) : i(o)) || o);
- return a && o && Ve(e, r, o), o;
- }, w = (t, e) => (r, a) => e(r, a, t);
- const b = "{FORMULA1}", C = "{FORMULA2}", ye = {
- [s.BETWEEN]: "dataValidation.operators.between",
- [s.EQUAL]: "dataValidation.operators.equal",
- [s.GREATER_THAN]: "dataValidation.operators.greaterThan",
- [s.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
- [s.LESS_THAN]: "dataValidation.operators.lessThan",
- [s.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
- [s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
- [s.NOT_EQUAL]: "dataValidation.operators.notEqual"
- };
- let P = class {
- // #endregion
- constructor(t, e) {
- c(this, "offsetFormulaByRange", !0);
- // #region UI related
- c(this, "formulaInput");
- c(this, "canvasRender", null);
- c(this, "dropdown");
- c(this, "optionsInput");
- c(this, "skipDefaultFontRender");
- this.localeService = t, this.injector = e;
- }
- get operatorNames() {
- return this.operators.map((t) => this.localeService.t(ye[t]));
- }
- get titleStr() {
- return this.localeService.t(this.title);
- }
- generateRuleName(t) {
- var r, a;
- if (!t.operator)
- return this.titleStr;
- const e = this.localeService.t(Me[t.operator]).replace(b, (r = t.formula1) != null ? r : "").replace(C, (a = t.formula2) != null ? a : "");
- return `${this.titleStr} ${e}`;
- }
- generateRuleErrorMessage(t, e) {
- var a, o;
- return t.operator ? `${this.localeService.t(Re[t.operator]).replace(b, (a = t.formula1) != null ? a : "").replace(C, (o = t.formula2) != null ? o : "")}` : this.titleStr;
- }
- getExtraStyle(t, e, r, a, o) {
- }
- getRuleFinalError(t, e) {
- return t.showErrorMessage && t.error ? t.error : this.generateRuleErrorMessage(t, e);
- }
- isEmptyCellValue(t) {
- return t === "" || t === void 0 || t === null;
- }
- normalizeFormula(t, e, r) {
- return {
- formula1: t.formula1,
- formula2: t.formula2
- };
- }
- async isValidType(t, e, r) {
- return !0;
- }
- transform(t, e, r) {
- return t;
- }
- async validatorIsEqual(t, e, r) {
- const { formula1: a } = e, { value: o } = t;
- return Number.isNaN(a) ? !0 : o === a;
- }
- async validatorIsNotEqual(t, e, r) {
- const { formula1: a } = e;
- return Number.isNaN(a) ? !0 : t.value !== a;
- }
- async validatorIsBetween(t, e, r) {
- const { formula1: a, formula2: o } = e;
- if (Number.isNaN(a) || Number.isNaN(o))
- return !0;
- const n = Math.min(a, o), i = Math.max(a, o);
- return t.value >= n && t.value <= i;
- }
- async validatorIsNotBetween(t, e, r) {
- const { formula1: a, formula2: o } = e;
- if (Number.isNaN(a) || Number.isNaN(o))
- return !0;
- const n = Math.min(a, o), i = Math.max(a, o);
- return t.value < n || t.value > i;
- }
- async validatorIsGreaterThan(t, e, r) {
- const { formula1: a } = e;
- return Number.isNaN(a) ? !0 : t.value > a;
- }
- async validatorIsGreaterThanOrEqual(t, e, r) {
- const { formula1: a } = e;
- return Number.isNaN(a) ? !0 : t.value >= a;
- }
- async validatorIsLessThan(t, e, r) {
- const { formula1: a } = e;
- return Number.isNaN(a) ? !0 : t.value < a;
- }
- async validatorIsLessThanOrEqual(t, e, r) {
- const { formula1: a } = e;
- return Number.isNaN(a) ? !0 : t.value <= a;
- }
- async validator(t, e) {
- const { value: r, unitId: a, subUnitId: o } = t, n = this.isEmptyCellValue(r), { allowBlank: i = !0, operator: l } = e;
- if (n)
- return i;
- const d = await this.parseFormula(e, a, o, t.row, t.column);
- if (!d.isFormulaValid || !await this.isValidType(t, d, e))
- return !1;
- if (!x.isDefine(l))
- return !0;
- const u = this.transform(t, d, e);
- switch (l) {
- case s.BETWEEN:
- return this.validatorIsBetween(u, d, e);
- case s.EQUAL:
- return this.validatorIsEqual(u, d, e);
- case s.GREATER_THAN:
- return this.validatorIsGreaterThan(u, d, e);
- case s.GREATER_THAN_OR_EQUAL:
- return this.validatorIsGreaterThanOrEqual(u, d, e);
- case s.LESS_THAN:
- return this.validatorIsLessThan(u, d, e);
- case s.LESS_THAN_OR_EQUAL:
- return this.validatorIsLessThanOrEqual(u, d, e);
- case s.NOT_BETWEEN:
- return this.validatorIsNotBetween(u, d, e);
- case s.NOT_EQUAL:
- return this.validatorIsNotEqual(u, d, e);
- default:
- throw new Error("Unknown operator.");
- }
- }
- };
- P = Ie([
- w(0, O(te)),
- w(1, O(G))
- ], P);
- export {
- S as AddDataValidationMutation,
- P as BaseDataValidator,
- m as DataValidationModel,
- I as DataValidationResourceController,
- me as DataValidatorRegistryScope,
- j as DataValidatorRegistryService,
- v as RemoveDataValidationMutation,
- be as TWO_FORMULA_OPERATOR_COUNT,
- we as TextLengthErrorTitleMap,
- D as UniverDataValidationPlugin,
- f as UpdateDataValidationMutation,
- h as UpdateRuleType,
- H as getRuleOptions,
- q as getRuleSetting
- };
|