import { BehaviorSubject, Bi, El, Fe, Mt, Ot, Pt, Ra, SE, Subject, Vr, Ze, _n, ar, cn, debounceTime, nt, nu, ot, re } from "./chunk-23V3HWTR.js"; // node_modules/.pnpm/@univerjs+data-validation@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/data-validation/lib/es/index.js var J = Object.defineProperty; var z = (t, e, r) => e in t ? J(t, e, { enumerable: true, configurable: true, writable: true, value: r }) : t[e] = r; var c = (t, e, r) => z(t, typeof e != "symbol" ? e + "" : e, r); 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 = ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(h || {}); var ne = Object.defineProperty; var ie = Object.getOwnPropertyDescriptor; var 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; }; var de = (t, e) => (r, a) => e(r, a, t); var m = class extends nt { constructor(e) { super(); c(this, "_model", /* @__PURE__ */ new Map()); c(this, "_ruleChange$", new Subject()); c(this, "ruleChange$", this._ruleChange$.asObservable()); c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(debounceTime(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 = re.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, Mt) ], m); var le = Object.defineProperty; var ue = Object.getOwnPropertyDescriptor; var 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; }; var y = (t, e) => (r, a) => e(r, a, t); var pe = "SHEET_DATA_VALIDATION_PLUGIN"; var I = class extends nt { 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: [Fe.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, Bi), y(1, _n), y(2, ot(m)) ], I); var me = ((t) => (t.SHEET = "sheet", t))(me || {}); var j = class { constructor() { c(this, "_validatorByScopes", /* @__PURE__ */ new Map()); c(this, "_validatorMap", /* @__PURE__ */ new Map()); c(this, "_validatorsChange$", new BehaviorSubject(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(), Ze(() => { 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); } }; var S = { type: ar.MUTATION, id: "data-validation.mutation.addRule", handler(t, e) { if (!e) return false; const { unitId: r, subUnitId: a, rule: o, index: n, source: i = "command" } = e; return t.get(m).addRule(r, a, o, i, n), true; } }; var v = { type: ar.MUTATION, id: "data-validation.mutation.removeRule", handler(t, e) { if (!e) return false; 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), true; } }; var f = { type: ar.MUTATION, id: "data-validation.mutation.updateRule", handler(t, e) { if (!e) return false; const { unitId: r, subUnitId: a, ruleId: o, payload: n, source: i = "command" } = e; return t.get(m).updateRule(r, a, o, n, i), true; } }; var he = { type: ar.COMMAND, id: "data-validation.command.addRule", async handler(t, e) { if (t.get(Mt).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e) return false; const { rule: a, unitId: o, subUnitId: n } = e, i = t.get(Pt), l = t.get(cn), 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), true; } }; var _e = { type: ar.COMMAND, id: "data-validation.command.removeRule", handler(t, e) { if (t.get(Mt).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e) return false; const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(Pt), l = t.get(cn), 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), true; } }; var Ee = { type: ar.COMMAND, id: "data-validation.command.updateDataValidationSetting", handler(t, e) { if (t.get(Mt).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e) return false; const a = t.get(Pt), o = t.get(cn), n = t.get(m), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, p = n.getRuleById(i, l, d); if (!p) return false; 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, _), true; } }; var ge = { type: ar.COMMAND, id: "data-validation.command.updateDataValidationOptions", handler(t, e) { if (t.get(Mt).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e) return false; const a = t.get(Pt), o = t.get(cn), n = t.get(m), i = t.get(j), { unitId: l, subUnitId: d, ruleId: u, setting: p } = e, _ = i.getValidatorItem(p.type); if (!_) return false; const g = n.getRuleById(l, d, u); if (!g) return false; const M = { ...g, ...p }; if (!_.validatorFormula(M, l, d).success) return false; 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), true; } }; var fe = { type: ar.COMMAND, id: "data-validation.command.removeAll", handler(t, e) { if (t.get(Mt).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e) return false; const { unitId: a, subUnitId: o } = e, n = t.get(Pt), i = t.get(m), l = t.get(cn), 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), true; } }; var ve = "data-validation.config"; var U = {}; var Ne = Object.defineProperty; var Te = Object.getOwnPropertyDescriptor; var 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; }; var L = (t, e) => (r, a) => e(r, a, t); var Ae = "UNIVER_DATA_VALIDATION_PLUGIN"; var V; var D = (V = class extends Ra { constructor(t = U, e, r, a) { super(), this._config = t, this._injector = e, this._commandService = r, this._configService = a; const { ...o } = nu( {}, 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", Fe.UNIVER_SHEET), V); D = Se([ L(1, ot(Ot)), L(2, Pt), L(3, SE) ], D); El.BETWEEN + "", El.EQUAL + "", El.GREATER_THAN + "", El.GREATER_THAN_OR_EQUAL + "", El.LESS_THAN + "", El.LESS_THAN_OR_EQUAL + "", El.NOT_BETWEEN + "", El.NOT_EQUAL + ""; var Me = { [El.BETWEEN]: "dataValidation.ruleName.between", [El.EQUAL]: "dataValidation.ruleName.equal", [El.GREATER_THAN]: "dataValidation.ruleName.greaterThan", [El.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual", [El.LESS_THAN]: "dataValidation.ruleName.lessThan", [El.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual", [El.NOT_BETWEEN]: "dataValidation.ruleName.notBetween", [El.NOT_EQUAL]: "dataValidation.ruleName.notEqual" }; var Re = { [El.BETWEEN]: "dataValidation.errorMsg.between", [El.EQUAL]: "dataValidation.errorMsg.equal", [El.GREATER_THAN]: "dataValidation.errorMsg.greaterThan", [El.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual", [El.LESS_THAN]: "dataValidation.errorMsg.lessThan", [El.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual", [El.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween", [El.NOT_EQUAL]: "dataValidation.errorMsg.notEqual" }; var we = { [El.BETWEEN]: "dataValidation.textLength.errorMsg.between", [El.EQUAL]: "dataValidation.textLength.errorMsg.equal", [El.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan", [El.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual", [El.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan", [El.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual", [El.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween", [El.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual" }; var be = [ El.BETWEEN, El.NOT_BETWEEN ]; var Ve = Object.defineProperty; var Oe = Object.getOwnPropertyDescriptor; var 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; }; var w = (t, e) => (r, a) => e(r, a, t); var b = "{FORMULA1}"; var C = "{FORMULA2}"; var ye = { [El.BETWEEN]: "dataValidation.operators.between", [El.EQUAL]: "dataValidation.operators.equal", [El.GREATER_THAN]: "dataValidation.operators.greaterThan", [El.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual", [El.LESS_THAN]: "dataValidation.operators.lessThan", [El.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual", [El.NOT_BETWEEN]: "dataValidation.operators.notBetween", [El.NOT_EQUAL]: "dataValidation.operators.notEqual" }; var P = class { // #endregion constructor(t, e) { c(this, "offsetFormulaByRange", true); 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 true; } transform(t, e, r) { return t; } async validatorIsEqual(t, e, r) { const { formula1: a } = e, { value: o } = t; return Number.isNaN(a) ? true : o === a; } async validatorIsNotEqual(t, e, r) { const { formula1: a } = e; return Number.isNaN(a) ? true : t.value !== a; } async validatorIsBetween(t, e, r) { const { formula1: a, formula2: o } = e; if (Number.isNaN(a) || Number.isNaN(o)) return true; 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 true; 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) ? true : t.value > a; } async validatorIsGreaterThanOrEqual(t, e, r) { const { formula1: a } = e; return Number.isNaN(a) ? true : t.value >= a; } async validatorIsLessThan(t, e, r) { const { formula1: a } = e; return Number.isNaN(a) ? true : t.value < a; } async validatorIsLessThanOrEqual(t, e, r) { const { formula1: a } = e; return Number.isNaN(a) ? true : t.value <= a; } async validator(t, e) { const { value: r, unitId: a, subUnitId: o } = t, n = this.isEmptyCellValue(r), { allowBlank: i = true, 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 false; if (!re.isDefine(l)) return true; const u = this.transform(t, d, e); switch (l) { case El.BETWEEN: return this.validatorIsBetween(u, d, e); case El.EQUAL: return this.validatorIsEqual(u, d, e); case El.GREATER_THAN: return this.validatorIsGreaterThan(u, d, e); case El.GREATER_THAN_OR_EQUAL: return this.validatorIsGreaterThanOrEqual(u, d, e); case El.LESS_THAN: return this.validatorIsLessThan(u, d, e); case El.LESS_THAN_OR_EQUAL: return this.validatorIsLessThanOrEqual(u, d, e); case El.NOT_BETWEEN: return this.validatorIsNotBetween(u, d, e); case El.NOT_EQUAL: return this.validatorIsNotEqual(u, d, e); default: throw new Error("Unknown operator."); } } }; P = Ie([ w(0, ot(Vr)), w(1, ot(Ot)) ], P); export { q, H, h, m, I, me, j, S, v, f, D, we, be, P }; //# sourceMappingURL=chunk-757T4GCY.js.map