12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061 |
- import {
- S,
- f,
- m as m2
- } from "./chunk-CLOCSTN3.js";
- import {
- Ea,
- F,
- Ma,
- Oe,
- Ra,
- Sa,
- Va,
- pa,
- va
- } from "./chunk-Q35HEJKG.js";
- import "./chunk-ALDCSYO3.js";
- import "./chunk-BW43Z7N3.js";
- import {
- ys
- } from "./chunk-QRYBFJ3R.js";
- import {
- H,
- m
- } from "./chunk-757T4GCY.js";
- import {
- El,
- Il,
- Pt,
- Ze,
- _l,
- _n,
- filter,
- hi,
- pi,
- qt,
- xf
- } from "./chunk-23V3HWTR.js";
- import "./chunk-GNR2UJZM.js";
- import "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/@univerjs+sheets-data-validation@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-data-validation/lib/es/facade.js
- var j = Object.defineProperty;
- var q = (c, e, t) => e in c ? j(c, e, { enumerable: true, configurable: true, writable: true, value: t }) : c[e] = t;
- var f2 = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
- var D = class _D {
- constructor(e) {
- f2(this, "_rule");
- this._rule = e != null ? e : {
- uid: qt(),
- ranges: void 0,
- type: Il.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 m3(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: qt()
- });
- }
- /**
- * 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 !== _l.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 = Il.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.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 = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.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 = Il.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 = El.BETWEEN, this._rule.type = r ? Il.WHOLE : Il.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 = El.EQUAL, this._rule.type = t ? Il.WHOLE : Il.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 = El.GREATER_THAN, this._rule.type = t ? Il.WHOLE : Il.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 = El.GREATER_THAN_OR_EQUAL, this._rule.type = t ? Il.WHOLE : Il.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 = El.LESS_THAN, this._rule.type = t ? Il.WHOLE : Il.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 = El.LESS_THAN_OR_EQUAL, this._rule.type = t ? Il.WHOLE : Il.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 = El.NOT_BETWEEN, this._rule.type = r ? Il.WHOLE : Il.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 = El.NOT_EQUAL, this._rule.type = t ? Il.WHOLE : Il.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 ? Il.LIST_MULTIPLE : Il.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : true, 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 ? Il.LIST_MULTIPLE : Il.LIST, this._rule.formula1 = `=${ys({
- unitId: e.getUnitId(),
- sheetName: e.getSheetName(),
- range: e.getRange()
- })}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : true, 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 ? _l.WARNING : _l.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;
- }
- };
- var m3 = class {
- constructor(e, t, r) {
- f2(this, "rule");
- f2(this, "_worksheet");
- f2(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 !== _l.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 false;
- const t = this._injector.get(m).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(_n).getUnit(this._worksheet.getUnitId());
- return this.rule.ranges.map((t) => this._injector.createInstance(S, 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 = true) {
- if (this.getApplied() && !this._injector.get(Pt).syncExecuteCommand(Sa.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(Pt).syncExecuteCommand(va.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid,
- options: {
- ...H(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(Pt).syncExecuteCommand(pa.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(Pt).syncExecuteCommand(Ea.id, {
- unitId: this.getUnitId(),
- subUnitId: this.getSheetId(),
- ruleId: this.rule.uid
- }) : false;
- }
- };
- var G = class extends S {
- setDataValidation(e) {
- if (!e)
- return this._commandService.syncExecuteCommand(Va.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(Ra.id, t), this;
- }
- getDataValidation() {
- const t = this._injector.get(Oe).getDataValidation(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- );
- return t && new m3(t, this._worksheet, this._injector);
- }
- getDataValidations() {
- return this._injector.get(Oe).getDataValidations(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- ).map((t) => new m3(t, this._worksheet, this._injector));
- }
- async getValidatorStatus() {
- return this._injector.get(Oe).validatorRanges(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- [this._range]
- );
- }
- };
- S.extend(G);
- var Q = class extends pi {
- // 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(F))
- return;
- const t = e.get(F), r = e.get(Pt);
- 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 m3(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 Ra.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 xf();
- break;
- }
- case Sa.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 xf();
- break;
- }
- case pa.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 xf();
- break;
- }
- case va.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 xf();
- break;
- }
- case Ea.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 xf();
- break;
- }
- case Ma.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 xf();
- break;
- }
- }
- }));
- }
- };
- pi.extend(Q);
- var z = class extends f {
- _initialize() {
- Object.defineProperty(this, "_dataValidationModel", {
- get() {
- return this._injector.get(F);
- }
- });
- }
- getValidatorStatus() {
- return this._injector.get(Oe).validatorWorkbook(this._workbook.getUnitId());
- }
- // region DataValidationHooks
- onDataValidationChange(e) {
- return Ze(this._dataValidationModel.ruleChange$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
- }
- onDataValidationStatusChange(e) {
- return Ze(this._dataValidationModel.validStatusChange$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
- }
- onBeforeAddDataValidation(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === Ra.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
- }
- }));
- }
- onBeforeUpdateDataValidationCriteria(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === Sa.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
- }
- }));
- }
- onBeforeUpdateDataValidationRange(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === pa.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
- }
- }));
- }
- onBeforeUpdateDataValidationOptions(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === va.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
- }
- }));
- }
- onBeforeDeleteDataValidation(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === Ea.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
- }
- }));
- }
- onBeforeDeleteAllDataValidation(e) {
- return Ze(this._commandService.beforeCommandExecuted((t, r) => {
- const a = t.params;
- if (t.id === Ma.id) {
- if (a.unitId !== this._workbook.getUnitId())
- return;
- if (e(a, r) === false)
- throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
- }
- }));
- }
- };
- f.extend(z);
- var K = class extends m2 {
- getDataValidations() {
- return this._injector.get(m).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m3(t, this._worksheet, this._injector));
- }
- getValidatorStatus() {
- return this._injector.get(Oe).validatorWorksheet(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId()
- );
- }
- getValidatorStatusAsync() {
- return this.getValidatorStatus();
- }
- getDataValidation(e) {
- const r = this._injector.get(m).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
- return r ? new m3(r, this._worksheet, this._injector) : null;
- }
- };
- m2.extend(K);
- var X = class {
- 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";
- }
- };
- hi.extend(X);
- export {
- m3 as FDataValidation,
- D as FDataValidationBuilder
- };
- //# sourceMappingURL=@univerjs_sheets-data-validation_facade.js.map
|