| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023 |
- var j = Object.defineProperty;
- var q = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
- var f = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
- import { UpdateSheetDataValidationSettingCommand as U, UpdateSheetDataValidationOptionsCommand as v, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as T, ClearRangeDataValidationCommand as W, AddSheetDataValidationCommand as A, SheetsDataValidationValidatorService as S, SheetDataValidationModel as V, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
- import { FRange as y, FWorkbook as M, FWorksheet as N } from "@univerjs/sheets/facade";
- import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as h, IUniverInstanceService as H, ICommandService as p, FUniver as x, CanceledError as _, toDisposable as g, FEventName as $ } from "@univerjs/core";
- import { DataValidationModel as b, getRuleOptions as F } from "@univerjs/data-validation";
- import { serializeRangeToRefString as P } from "@univerjs/engine-formula";
- import { filter as R } from "rxjs";
- class D {
- constructor(e) {
- f(this, "_rule");
- this._rule = e != null ? e : {
- uid: B(),
- ranges: void 0,
- type: o.CUSTOM
- };
- }
- /**
- * Builds an FDataValidation instance based on the _rule property of the current class
- * @returns {FDataValidation} A new instance of the FDataValidation class
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const validation = builder.requireNumberBetween(1, 10).build();
- * ```
- */
- build() {
- return new m(this._rule);
- }
- /**
- * Creates a duplicate of the current DataValidationBuilder object
- * @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const copy = builder.requireNumberBetween(1, 10).copy();
- * ```
- */
- copy() {
- return new D({
- ...this._rule,
- uid: B()
- });
- }
- /**
- * Determines whether invalid data is allowed
- * @returns {boolean} True if invalid data is allowed, False otherwise
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const allowsInvalid = builder.getAllowInvalid();
- * ```
- */
- getAllowInvalid() {
- return this._rule.errorStyle !== w.STOP;
- }
- /**
- * Gets the data validation type of the rule
- * @returns {DataValidationType | string} The data validation type
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const type = builder.getCriteriaType();
- * ```
- */
- getCriteriaType() {
- return this._rule.type;
- }
- /**
- * Gets the values used for criteria evaluation
- * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const [operator, formula1, formula2] = builder.getCriteriaValues();
- * ```
- */
- getCriteriaValues() {
- return [this._rule.operator, this._rule.formula1, this._rule.formula2];
- }
- /**
- * Gets the help text information, which is used to provide users with guidance and support
- * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const helpText = builder.getHelpText();
- * ```
- */
- getHelpText() {
- return this._rule.error;
- }
- /**
- * Sets the data validation type to CHECKBOX and sets the checked and unchecked values
- * @param {string} [checkedValue] - The value when the checkbox is checked
- * @param {string} [uncheckedValue] - The value when the checkbox is unchecked
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireCheckbox('Yes', 'No').build();
- * ```
- */
- requireCheckbox(e, t) {
- return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be after a specific date
- * @param {Date} date - The date to compare against
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireDateAfter(new Date('2024-01-01')).build();
- * ```
- */
- requireDateAfter(e) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = h.GREATER_THAN, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be before a specific date
- * @param {Date} date - The date to compare against
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireDateBefore(new Date('2024-12-31')).build();
- * ```
- */
- requireDateBefore(e) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be within a specific date range
- * @param {Date} start - The starting date of the range
- * @param {Date} end - The ending date of the range
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder
- * .requireDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
- * .build();
- * ```
- */
- requireDateBetween(e, t) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.BETWEEN, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be equal to a specific date
- * @param {Date} date - The date to compare against
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireDateEqualTo(new Date('2024-01-01')).build();
- * ```
- */
- requireDateEqualTo(e) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be not within a specific date range
- * @param {Date} start - The starting date of the date range
- * @param {Date} end - The ending date of the date range
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder
- * .requireDateNotBetween(new Date('2024-01-01'), new Date('2024-12-31'))
- * .build();
- * ```
- */
- requireDateNotBetween(e, t) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.NOT_BETWEEN, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be on or after a specific date
- * @param {Date} date - The date to compare against
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireDateOnOrAfter(new Date('2024-01-01')).build();
- * ```
- */
- requireDateOnOrAfter(e) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this;
- }
- /**
- * Set the data validation type to DATE and configure the validation rules to be on or before a specific date
- * @param {Date} date - The date to compare against
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireDateOnOrBefore(new Date('2024-12-31')).build();
- * ```
- */
- requireDateOnOrBefore(e) {
- return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this;
- }
- /**
- * Requires that a custom formula be satisfied
- * @param {string} formula - The formula string that needs to be satisfied
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireFormulaSatisfied('=A1>0').build();
- * ```
- */
- requireFormulaSatisfied(e) {
- return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
- }
- /**
- * Requires the user to enter a number within a specific range, which can be integer or decimal
- * @param {number} start - The starting value of the number range
- * @param {number} end - The ending value of the number range
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberBetween(1, 10).build();
- * ```
- */
- requireNumberBetween(e, t, r) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
- * @param {number} num - The number to which the entered number should be equal
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberEqualTo(10).build();
- * ```
- */
- requireNumberEqualTo(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
- * @param {number} num - The number to which the entered number should be greater
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberGreaterThan(10).build();
- * ```
- */
- requireNumberGreaterThan(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal
- * @param {number} num - The number to which the entered number should be greater than or equal
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberGreaterThanOrEqualTo(10).build();
- * ```
- */
- requireNumberGreaterThanOrEqualTo(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
- * @param {number} num - The number to which the entered number should be less
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberLessThan(10).build();
- * ```
- */
- requireNumberLessThan(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Sets the data validation rule to require a number less than or equal to a specified value
- * The specified value can be an integer or a decimal
- * @param {number} num - The number to which the entered number should be less than or equal
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberLessThanOrEqualTo(10).build();
- * ```
- */
- requireNumberLessThanOrEqualTo(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Sets a data validation rule that requires the user to enter a number outside a specified range
- * The specified range includes all integers and decimals
- * @param {number} start - The starting point of the specified range
- * @param {number} end - The end point of the specified range
- * @param {boolean} [isInteger] - Optional parameter, indicating whether the number to be verified is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberNotBetween(1, 10).build();
- * ```
- */
- requireNumberNotBetween(e, t, r) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.NOT_BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
- * The specific value can be an integer or a decimal
- * @param {number} num - The number to which the entered number should not be equal
- * @param {boolean} [isInteger] - Indicates whether the required number is an integer
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireNumberNotEqualTo(10).build();
- * ```
- */
- requireNumberNotEqualTo(e, t) {
- return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
- }
- /**
- * Sets a data validation rule that requires the user to enter a value from a list of specific values
- * The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
- * @param {string[]} values - An array containing the specific values that the user can enter
- * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
- * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.requireValueInList(['Yes', 'No']).build();
- * ```
- */
- requireValueInList(e, t, r) {
- return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
- }
- /**
- * Sets a data validation rule that requires the user to enter a value within a specific range
- * The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
- * @param {FRange} range - An FRange object representing the range of values that the user can enter
- * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
- * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const range = FRange.create('Sheet1', 'B1:B10');
- * const rule = builder.requireValueInRange(range).build();
- * ```
- */
- requireValueInRange(e, t, r) {
- return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
- unitId: e.getUnitId(),
- sheetName: e.getSheetName(),
- range: e.getRange()
- })}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
- }
- /**
- * Sets whether to allow invalid data and configures the error style
- * If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
- * If invalid data is allowed, the error style will be set to WARNING, indicating that a warning will be displayed when invalid data is entered, but data entry can continue
- * @param {boolean} allowInvalidData - Whether to allow invalid data
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.setAllowInvalid(true).build();
- * ```
- */
- setAllowInvalid(e) {
- return this._rule.errorStyle = e ? w.WARNING : w.STOP, this;
- }
- /**
- * Sets whether to allow blank values
- * @param {boolean} allowBlank - Whether to allow blank values
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.setAllowBlank(true).build();
- * ```
- */
- setAllowBlank(e) {
- return this._rule.allowBlank = e, this;
- }
- /**
- * Sets the options for the data validation rule
- * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
- * @returns {FDataValidationBuilder} The current instance for method chaining
- * @example
- * ```typescript
- * const builder = univerAPI.newDataValidation();
- * const rule = builder.setOptions({
- * allowBlank: true,
- * showErrorMessage: true,
- * error: 'Please enter a valid value'
- * }).build();
- * ```
- */
- setOptions(e) {
- return Object.assign(this._rule, e), this;
- }
- }
- class m {
- constructor(e, t, r) {
- f(this, "rule");
- f(this, "_worksheet");
- f(this, "_injector");
- this._injector = r, this.rule = e, this._worksheet = t;
- }
- /**
- * Gets whether invalid data is allowed based on the error style value
- * @returns {boolean} true if invalid data is allowed, false otherwise
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const allowsInvalid = dataValidation.getAllowInvalid();
- * ```
- */
- getAllowInvalid() {
- return this.rule.errorStyle !== w.STOP;
- }
- /**
- * Gets the data validation type of the rule
- * @returns {DataValidationType | string} The data validation type
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const type = dataValidation.getCriteriaType();
- * ```
- */
- getCriteriaType() {
- return this.rule.type;
- }
- /**
- * Gets the values used for criteria evaluation
- * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
- * ```
- */
- getCriteriaValues() {
- return [this.rule.operator, this.rule.formula1, this.rule.formula2];
- }
- /**
- * Gets the help text information, which is used to provide users with guidance and support
- * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const helpText = dataValidation.getHelpText();
- * ```
- */
- getHelpText() {
- return this.rule.error;
- }
- /**
- * Creates a new instance of FDataValidationBuilder using the current rule object
- * @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const builder = dataValidation.copy();
- * const newRule = builder.setAllowInvalid(true).build();
- * ```
- */
- copy() {
- return new D(this.rule);
- }
- /**
- * Gets whether the data validation rule is applied to the worksheet
- * @returns {boolean} true if the rule is applied, false otherwise
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const isApplied = dataValidation.getApplied();
- * ```
- */
- getApplied() {
- if (!this._worksheet)
- return !1;
- const t = this._injector.get(b).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
- return !!(t && t.ranges.length);
- }
- /**
- * Gets the ranges to which the data validation rule is applied
- * @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const ranges = dataValidation.getRanges();
- * ```
- */
- getRanges() {
- if (!this.getApplied())
- return [];
- const e = this._injector.get(H).getUnit(this._worksheet.getUnitId());
- return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
- }
- /**
- * Gets the unit ID of the worksheet
- * @returns {string | undefined} The unit ID of the worksheet
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const unitId = dataValidation.getUnitId();
- * ```
- */
- getUnitId() {
- var e;
- return (e = this._worksheet) == null ? void 0 : e.getUnitId();
- }
- /**
- * Gets the sheet ID of the worksheet
- * @returns {string | undefined} The sheet ID of the worksheet
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const sheetId = dataValidation.getSheetId();
- * ```
- */
- getSheetId() {
- var e;
- return (e = this._worksheet) == null ? void 0 : e.getSheetId();
- }
- /**
- * Set Criteria for the data validation rule
- * @param {DataValidationType} type - The type of data validation criteria
- * @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
- * @param {boolean} [allowBlank] - Whether to allow blank values
- * @returns {FDataValidation} The current instance for method chaining
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * dataValidation.setCriteria(
- * DataValidationType.DECIMAL,
- * [DataValidationOperator.BETWEEN, '1', '10'],
- * true
- * );
- * ```
- */
- setCriteria(e, t, r = !0) {
- if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid,
- setting: {
- operator: t[0],
- formula1: t[1],
- formula2: t[2],
- type: this.rule.type,
- allowBlank: r
- }
- }))
- throw new Error("setCriteria failed");
- return this.rule.operator = t[0], this.rule.formula1 = t[1], this.rule.formula2 = t[2], this.rule.type = e, this.rule.allowBlank = r, this;
- }
- /**
- * Set the options for the data validation rule
- * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
- * @returns {FDataValidation} The current instance for method chaining
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * dataValidation.setOptions({
- * allowBlank: true,
- * showErrorMessage: true,
- * error: 'Please enter a valid value'
- * });
- * ```
- */
- setOptions(e) {
- if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid,
- options: {
- ...F(this.rule),
- ...e
- }
- }))
- throw new Error("setOptions failed");
- return Object.assign(this.rule, e), this;
- }
- /**
- * Set the ranges to the data validation rule
- * @param {FRange[]} ranges - New ranges array
- * @returns {FDataValidation} The current instance for method chaining
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const range = FRange.create('Sheet1', 'A1:B10');
- * dataValidation.setRanges([range]);
- * ```
- */
- setRanges(e) {
- if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid,
- ranges: e.map((a) => a.getRange())
- }))
- throw new Error("setRanges failed");
- return this.rule.ranges = e.map((t) => t.getRange()), this;
- }
- /**
- * Delete the data validation rule from the worksheet
- * @returns {boolean} true if the rule is deleted successfully, false otherwise
- * @example
- * ```typescript
- * const dataValidation = univerAPI
- * .getActiveWorkbook()
- * .getActiveWorksheet()
- * .getActiveRange()
- * .getDataValidation();
- * const isDeleted = dataValidation.delete();
- * ```
- */
- delete() {
- return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid
- }) : !1;
- }
- }
- class G extends y {
- setDataValidation(e) {
- if (!e)
- return this._commandService.syncExecuteCommand(W.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- ranges: [this._range]
- }), this;
- const t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- rule: {
- ...e.rule,
- ranges: [this._range]
- }
- };
- return this._commandService.syncExecuteCommand(A.id, t), this;
- }
- getDataValidation() {
- const t = this._injector.get(S).getDataValidation(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- );
- return t && new m(t, this._worksheet, this._injector);
- }
- getDataValidations() {
- return this._injector.get(S).getDataValidations(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- ).map((t) => new m(t, this._worksheet, this._injector));
- }
- async getValidatorStatus() {
- return this._injector.get(S).validatorRanges(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- );
- }
- }
- y.extend(G);
- class Q extends x {
- // eslint-disable-next-line jsdoc/require-returns
- /**
- /**
- * @deprecated use `univerAPI.newDataValidation()` as instead.
- */
- static newDataValidation() {
- return new D();
- }
- /**
- * Creates a new instance of FDataValidationBuilder
- * @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
- * @example
- * ```ts
- * const rule = FUnvier.newDataValidation();
- * cell.setDataValidation(rule.requireValueInRange(range));
- * ```
- */
- newDataValidation() {
- return new D();
- }
- // eslint-disable-next-line max-lines-per-function
- _initialize(e) {
- if (!e.has(V)) return;
- const t = e.get(V), r = e.get(p);
- this.disposeWithMe(t.ruleChange$.subscribe((a) => {
- const { unitId: i, subUnitId: n, rule: d, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
- if (!l)
- return;
- const { workbook: I, worksheet: k } = l, E = new m(d, k.getSheet(), this._injector);
- this.fireEvent(this.Event.SheetDataValidationChanged, {
- origin: a,
- worksheet: k,
- workbook: I,
- changeType: s,
- oldRule: u,
- rule: E
- });
- })), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
- const { unitId: i, subUnitId: n, ruleId: d, status: u, row: s, col: l } = a, I = this.getSheetTarget(i, n);
- if (!I)
- return;
- const { workbook: k, worksheet: E } = I, L = E.getDataValidation(d);
- L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
- workbook: k,
- worksheet: E,
- row: s,
- column: l,
- rule: L,
- status: u
- });
- })), this.disposeWithMe(r.beforeCommandExecuted((a) => {
- switch (a.id) {
- case A.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = {
- worksheet: u,
- workbook: d,
- rule: i.rule
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
- throw new _();
- break;
- }
- case U.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
- if (!s)
- return;
- const l = {
- worksheet: u,
- workbook: d,
- rule: s,
- ruleId: i.ruleId,
- newCriteria: i.setting
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, l), l.cancel)
- throw new _();
- break;
- }
- case C.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
- if (!s)
- return;
- const l = {
- worksheet: u,
- workbook: d,
- rule: s,
- ruleId: i.ruleId,
- newRanges: i.ranges
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, l), l.cancel)
- throw new _();
- break;
- }
- case v.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
- if (!s)
- return;
- const l = {
- worksheet: u,
- workbook: d,
- rule: s,
- ruleId: i.ruleId,
- newOptions: i.options
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, l), l.cancel)
- throw new _();
- break;
- }
- case T.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
- if (!s)
- return;
- const l = {
- worksheet: u,
- workbook: d,
- rule: s,
- ruleId: i.ruleId
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, l), l.cancel)
- throw new _();
- break;
- }
- case O.id: {
- const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
- if (!n)
- return;
- const { workbook: d, worksheet: u } = n, s = {
- worksheet: u,
- workbook: d,
- rules: u.getDataValidations()
- };
- if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
- throw new _();
- break;
- }
- }
- }));
- }
- }
- x.extend(Q);
- class z extends M {
- _initialize() {
- Object.defineProperty(this, "_dataValidationModel", {
- get() {
- return this._injector.get(V);
- }
- });
- }
- getValidatorStatus() {
- return this._injector.get(S).validatorWorkbook(this._workbook.getUnitId());
- }
- // region DataValidationHooks
- onDataValidationChange(e) {
- return g(this._dataValidationModel.ruleChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
- }
- onDataValidationStatusChange(e) {
- return g(this._dataValidationModel.validStatusChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
- }
- onBeforeAddDataValidation(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === A.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
- }
- }));
- }
- onBeforeUpdateDataValidationCriteria(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === U.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
- }
- }));
- }
- onBeforeUpdateDataValidationRange(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === C.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
- }
- }));
- }
- onBeforeUpdateDataValidationOptions(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === v.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
- }
- }));
- }
- onBeforeDeleteDataValidation(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === T.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
- }
- }));
- }
- onBeforeDeleteAllDataValidation(e) {
- return g(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === O.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === !1)
- throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
- }
- }));
- }
- }
- M.extend(z);
- class K extends N {
- getDataValidations() {
- return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
- }
- getValidatorStatus() {
- return this._injector.get(S).validatorWorksheet(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId()
- );
- }
- getValidatorStatusAsync() {
- return this.getValidatorStatus();
- }
- getDataValidation(e) {
- const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
- return r ? new m(r, this._worksheet, this._injector) : null;
- }
- }
- N.extend(K);
- class X {
- get SheetDataValidationChanged() {
- return "SheetDataValidationChanged";
- }
- get SheetDataValidatorStatusChanged() {
- return "SheetDataValidatorStatusChanged";
- }
- get BeforeSheetDataValidationAdd() {
- return "BeforeSheetDataValidationAdd";
- }
- get BeforeSheetDataValidationDelete() {
- return "BeforeSheetDataValidationDelete";
- }
- get BeforeSheetDataValidationDeleteAll() {
- return "BeforeSheetDataValidationDeleteAll";
- }
- get BeforeSheetDataValidationCriteriaUpdate() {
- return "BeforeSheetDataValidationCriteriaUpdate";
- }
- get BeforeSheetDataValidationRangeUpdate() {
- return "BeforeSheetDataValidationRangeUpdate";
- }
- get BeforeSheetDataValidationOptionsUpdate() {
- return "BeforeSheetDataValidationOptionsUpdate";
- }
- }
- $.extend(X);
- export {
- m as FDataValidation,
- D as FDataValidationBuilder
- };
|