@univerjs_sheets-data-validation_facade.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. import {
  2. S,
  3. f,
  4. m as m2
  5. } from "./chunk-CLOCSTN3.js";
  6. import {
  7. Ea,
  8. F,
  9. Ma,
  10. Oe,
  11. Ra,
  12. Sa,
  13. Va,
  14. pa,
  15. va
  16. } from "./chunk-Q35HEJKG.js";
  17. import "./chunk-ALDCSYO3.js";
  18. import "./chunk-BW43Z7N3.js";
  19. import {
  20. ys
  21. } from "./chunk-QRYBFJ3R.js";
  22. import {
  23. H,
  24. m
  25. } from "./chunk-757T4GCY.js";
  26. import {
  27. El,
  28. Il,
  29. Pt,
  30. Ze,
  31. _l,
  32. _n,
  33. filter,
  34. hi,
  35. pi,
  36. qt,
  37. xf
  38. } from "./chunk-23V3HWTR.js";
  39. import "./chunk-GNR2UJZM.js";
  40. import "./chunk-2LSFTFF7.js";
  41. // 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
  42. var j = Object.defineProperty;
  43. var q = (c, e, t) => e in c ? j(c, e, { enumerable: true, configurable: true, writable: true, value: t }) : c[e] = t;
  44. var f2 = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
  45. var D = class _D {
  46. constructor(e) {
  47. f2(this, "_rule");
  48. this._rule = e != null ? e : {
  49. uid: qt(),
  50. ranges: void 0,
  51. type: Il.CUSTOM
  52. };
  53. }
  54. /**
  55. * Builds an FDataValidation instance based on the _rule property of the current class
  56. * @returns {FDataValidation} A new instance of the FDataValidation class
  57. * @example
  58. * ```typescript
  59. * const builder = univerAPI.newDataValidation();
  60. * const validation = builder.requireNumberBetween(1, 10).build();
  61. * ```
  62. */
  63. build() {
  64. return new m3(this._rule);
  65. }
  66. /**
  67. * Creates a duplicate of the current DataValidationBuilder object
  68. * @returns {FDataValidationBuilder} A new instance of the DataValidationBuilder class
  69. * @example
  70. * ```typescript
  71. * const builder = univerAPI.newDataValidation();
  72. * const copy = builder.requireNumberBetween(1, 10).copy();
  73. * ```
  74. */
  75. copy() {
  76. return new _D({
  77. ...this._rule,
  78. uid: qt()
  79. });
  80. }
  81. /**
  82. * Determines whether invalid data is allowed
  83. * @returns {boolean} True if invalid data is allowed, False otherwise
  84. * @example
  85. * ```typescript
  86. * const builder = univerAPI.newDataValidation();
  87. * const allowsInvalid = builder.getAllowInvalid();
  88. * ```
  89. */
  90. getAllowInvalid() {
  91. return this._rule.errorStyle !== _l.STOP;
  92. }
  93. /**
  94. * Gets the data validation type of the rule
  95. * @returns {DataValidationType | string} The data validation type
  96. * @example
  97. * ```typescript
  98. * const builder = univerAPI.newDataValidation();
  99. * const type = builder.getCriteriaType();
  100. * ```
  101. */
  102. getCriteriaType() {
  103. return this._rule.type;
  104. }
  105. /**
  106. * Gets the values used for criteria evaluation
  107. * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
  108. * @example
  109. * ```typescript
  110. * const builder = univerAPI.newDataValidation();
  111. * const [operator, formula1, formula2] = builder.getCriteriaValues();
  112. * ```
  113. */
  114. getCriteriaValues() {
  115. return [this._rule.operator, this._rule.formula1, this._rule.formula2];
  116. }
  117. /**
  118. * Gets the help text information, which is used to provide users with guidance and support
  119. * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
  120. * @example
  121. * ```typescript
  122. * const builder = univerAPI.newDataValidation();
  123. * const helpText = builder.getHelpText();
  124. * ```
  125. */
  126. getHelpText() {
  127. return this._rule.error;
  128. }
  129. /**
  130. * Sets the data validation type to CHECKBOX and sets the checked and unchecked values
  131. * @param {string} [checkedValue] - The value when the checkbox is checked
  132. * @param {string} [uncheckedValue] - The value when the checkbox is unchecked
  133. * @returns {FDataValidationBuilder} The current instance for method chaining
  134. * @example
  135. * ```typescript
  136. * const builder = univerAPI.newDataValidation();
  137. * const rule = builder.requireCheckbox('Yes', 'No').build();
  138. * ```
  139. */
  140. requireCheckbox(e, t) {
  141. return this._rule.type = Il.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
  142. }
  143. /**
  144. * Set the data validation type to DATE and configure the validation rules to be after a specific date
  145. * @param {Date} date - The date to compare against
  146. * @returns {FDataValidationBuilder} The current instance for method chaining
  147. * @example
  148. * ```typescript
  149. * const builder = univerAPI.newDataValidation();
  150. * const rule = builder.requireDateAfter(new Date('2024-01-01')).build();
  151. * ```
  152. */
  153. requireDateAfter(e) {
  154. return this._rule.type = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = El.GREATER_THAN, this;
  155. }
  156. /**
  157. * Set the data validation type to DATE and configure the validation rules to be before a specific date
  158. * @param {Date} date - The date to compare against
  159. * @returns {FDataValidationBuilder} The current instance for method chaining
  160. * @example
  161. * ```typescript
  162. * const builder = univerAPI.newDataValidation();
  163. * const rule = builder.requireDateBefore(new Date('2024-12-31')).build();
  164. * ```
  165. */
  166. requireDateBefore(e) {
  167. return this._rule.type = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.LESS_THAN, this;
  168. }
  169. /**
  170. * Set the data validation type to DATE and configure the validation rules to be within a specific date range
  171. * @param {Date} start - The starting date of the range
  172. * @param {Date} end - The ending date of the range
  173. * @returns {FDataValidationBuilder} The current instance for method chaining
  174. * @example
  175. * ```typescript
  176. * const builder = univerAPI.newDataValidation();
  177. * const rule = builder
  178. * .requireDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
  179. * .build();
  180. * ```
  181. */
  182. requireDateBetween(e, t) {
  183. return this._rule.type = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = El.BETWEEN, this;
  184. }
  185. /**
  186. * Set the data validation type to DATE and configure the validation rules to be equal to a specific date
  187. * @param {Date} date - The date to compare against
  188. * @returns {FDataValidationBuilder} The current instance for method chaining
  189. * @example
  190. * ```typescript
  191. * const builder = univerAPI.newDataValidation();
  192. * const rule = builder.requireDateEqualTo(new Date('2024-01-01')).build();
  193. * ```
  194. */
  195. requireDateEqualTo(e) {
  196. return this._rule.type = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = El.EQUAL, this;
  197. }
  198. /**
  199. * Set the data validation type to DATE and configure the validation rules to be not within a specific date range
  200. * @param {Date} start - The starting date of the date range
  201. * @param {Date} end - The ending date of the date range
  202. * @returns {FDataValidationBuilder} The current instance for method chaining
  203. * @example
  204. * ```typescript
  205. * const builder = univerAPI.newDataValidation();
  206. * const rule = builder
  207. * .requireDateNotBetween(new Date('2024-01-01'), new Date('2024-12-31'))
  208. * .build();
  209. * ```
  210. */
  211. requireDateNotBetween(e, t) {
  212. return this._rule.type = Il.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = El.NOT_BETWEEN, this;
  213. }
  214. /**
  215. * Set the data validation type to DATE and configure the validation rules to be on or after a specific date
  216. * @param {Date} date - The date to compare against
  217. * @returns {FDataValidationBuilder} The current instance for method chaining
  218. * @example
  219. * ```typescript
  220. * const builder = univerAPI.newDataValidation();
  221. * const rule = builder.requireDateOnOrAfter(new Date('2024-01-01')).build();
  222. * ```
  223. */
  224. requireDateOnOrAfter(e) {
  225. 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;
  226. }
  227. /**
  228. * Set the data validation type to DATE and configure the validation rules to be on or before a specific date
  229. * @param {Date} date - The date to compare against
  230. * @returns {FDataValidationBuilder} The current instance for method chaining
  231. * @example
  232. * ```typescript
  233. * const builder = univerAPI.newDataValidation();
  234. * const rule = builder.requireDateOnOrBefore(new Date('2024-12-31')).build();
  235. * ```
  236. */
  237. requireDateOnOrBefore(e) {
  238. 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;
  239. }
  240. /**
  241. * Requires that a custom formula be satisfied
  242. * @param {string} formula - The formula string that needs to be satisfied
  243. * @returns {FDataValidationBuilder} The current instance for method chaining
  244. * @example
  245. * ```typescript
  246. * const builder = univerAPI.newDataValidation();
  247. * const rule = builder.requireFormulaSatisfied('=A1>0').build();
  248. * ```
  249. */
  250. requireFormulaSatisfied(e) {
  251. return this._rule.type = Il.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
  252. }
  253. /**
  254. * Requires the user to enter a number within a specific range, which can be integer or decimal
  255. * @param {number} start - The starting value of the number range
  256. * @param {number} end - The ending value of the number range
  257. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  258. * @returns {FDataValidationBuilder} The current instance for method chaining
  259. * @example
  260. * ```typescript
  261. * const builder = univerAPI.newDataValidation();
  262. * const rule = builder.requireNumberBetween(1, 10).build();
  263. * ```
  264. */
  265. requireNumberBetween(e, t, r) {
  266. return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = El.BETWEEN, this._rule.type = r ? Il.WHOLE : Il.DECIMAL, this;
  267. }
  268. /**
  269. * Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
  270. * @param {number} num - The number to which the entered number should be equal
  271. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  272. * @returns {FDataValidationBuilder} The current instance for method chaining
  273. * @example
  274. * ```typescript
  275. * const builder = univerAPI.newDataValidation();
  276. * const rule = builder.requireNumberEqualTo(10).build();
  277. * ```
  278. */
  279. requireNumberEqualTo(e, t) {
  280. return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = El.EQUAL, this._rule.type = t ? Il.WHOLE : Il.DECIMAL, this;
  281. }
  282. /**
  283. * Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
  284. * @param {number} num - The number to which the entered number should be greater
  285. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  286. * @returns {FDataValidationBuilder} The current instance for method chaining
  287. * @example
  288. * ```typescript
  289. * const builder = univerAPI.newDataValidation();
  290. * const rule = builder.requireNumberGreaterThan(10).build();
  291. * ```
  292. */
  293. requireNumberGreaterThan(e, t) {
  294. 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;
  295. }
  296. /**
  297. * 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
  298. * @param {number} num - The number to which the entered number should be greater than or equal
  299. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  300. * @returns {FDataValidationBuilder} The current instance for method chaining
  301. * @example
  302. * ```typescript
  303. * const builder = univerAPI.newDataValidation();
  304. * const rule = builder.requireNumberGreaterThanOrEqualTo(10).build();
  305. * ```
  306. */
  307. requireNumberGreaterThanOrEqualTo(e, t) {
  308. 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;
  309. }
  310. /**
  311. * Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
  312. * @param {number} num - The number to which the entered number should be less
  313. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  314. * @returns {FDataValidationBuilder} The current instance for method chaining
  315. * @example
  316. * ```typescript
  317. * const builder = univerAPI.newDataValidation();
  318. * const rule = builder.requireNumberLessThan(10).build();
  319. * ```
  320. */
  321. requireNumberLessThan(e, t) {
  322. 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;
  323. }
  324. /**
  325. * Sets the data validation rule to require a number less than or equal to a specified value
  326. * The specified value can be an integer or a decimal
  327. * @param {number} num - The number to which the entered number should be less than or equal
  328. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  329. * @returns {FDataValidationBuilder} The current instance for method chaining
  330. * @example
  331. * ```typescript
  332. * const builder = univerAPI.newDataValidation();
  333. * const rule = builder.requireNumberLessThanOrEqualTo(10).build();
  334. * ```
  335. */
  336. requireNumberLessThanOrEqualTo(e, t) {
  337. 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;
  338. }
  339. /**
  340. * Sets a data validation rule that requires the user to enter a number outside a specified range
  341. * The specified range includes all integers and decimals
  342. * @param {number} start - The starting point of the specified range
  343. * @param {number} end - The end point of the specified range
  344. * @param {boolean} [isInteger] - Optional parameter, indicating whether the number to be verified is an integer
  345. * @returns {FDataValidationBuilder} The current instance for method chaining
  346. * @example
  347. * ```typescript
  348. * const builder = univerAPI.newDataValidation();
  349. * const rule = builder.requireNumberNotBetween(1, 10).build();
  350. * ```
  351. */
  352. requireNumberNotBetween(e, t, r) {
  353. return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = El.NOT_BETWEEN, this._rule.type = r ? Il.WHOLE : Il.DECIMAL, this;
  354. }
  355. /**
  356. * Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
  357. * The specific value can be an integer or a decimal
  358. * @param {number} num - The number to which the entered number should not be equal
  359. * @param {boolean} [isInteger] - Indicates whether the required number is an integer
  360. * @returns {FDataValidationBuilder} The current instance for method chaining
  361. * @example
  362. * ```typescript
  363. * const builder = univerAPI.newDataValidation();
  364. * const rule = builder.requireNumberNotEqualTo(10).build();
  365. * ```
  366. */
  367. requireNumberNotEqualTo(e, t) {
  368. 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;
  369. }
  370. /**
  371. * Sets a data validation rule that requires the user to enter a value from a list of specific values
  372. * The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
  373. * @param {string[]} values - An array containing the specific values that the user can enter
  374. * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
  375. * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
  376. * @returns {FDataValidationBuilder} The current instance for method chaining
  377. * @example
  378. * ```typescript
  379. * const builder = univerAPI.newDataValidation();
  380. * const rule = builder.requireValueInList(['Yes', 'No']).build();
  381. * ```
  382. */
  383. requireValueInList(e, t, r) {
  384. 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;
  385. }
  386. /**
  387. * Sets a data validation rule that requires the user to enter a value within a specific range
  388. * The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
  389. * @param {FRange} range - An FRange object representing the range of values that the user can enter
  390. * @param {boolean} [multiple] - Optional parameter indicating whether the user can select multiple values
  391. * @param {boolean} [showDropdown] - Optional parameter indicating whether to display the list in a dropdown
  392. * @returns {FDataValidationBuilder} The current instance for method chaining
  393. * @example
  394. * ```typescript
  395. * const builder = univerAPI.newDataValidation();
  396. * const range = FRange.create('Sheet1', 'B1:B10');
  397. * const rule = builder.requireValueInRange(range).build();
  398. * ```
  399. */
  400. requireValueInRange(e, t, r) {
  401. return this._rule.type = t ? Il.LIST_MULTIPLE : Il.LIST, this._rule.formula1 = `=${ys({
  402. unitId: e.getUnitId(),
  403. sheetName: e.getSheetName(),
  404. range: e.getRange()
  405. })}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : true, this;
  406. }
  407. /**
  408. * Sets whether to allow invalid data and configures the error style
  409. * If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error
  410. * 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
  411. * @param {boolean} allowInvalidData - Whether to allow invalid data
  412. * @returns {FDataValidationBuilder} The current instance for method chaining
  413. * @example
  414. * ```typescript
  415. * const builder = univerAPI.newDataValidation();
  416. * const rule = builder.setAllowInvalid(true).build();
  417. * ```
  418. */
  419. setAllowInvalid(e) {
  420. return this._rule.errorStyle = e ? _l.WARNING : _l.STOP, this;
  421. }
  422. /**
  423. * Sets whether to allow blank values
  424. * @param {boolean} allowBlank - Whether to allow blank values
  425. * @returns {FDataValidationBuilder} The current instance for method chaining
  426. * @example
  427. * ```typescript
  428. * const builder = univerAPI.newDataValidation();
  429. * const rule = builder.setAllowBlank(true).build();
  430. * ```
  431. */
  432. setAllowBlank(e) {
  433. return this._rule.allowBlank = e, this;
  434. }
  435. /**
  436. * Sets the options for the data validation rule
  437. * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
  438. * @returns {FDataValidationBuilder} The current instance for method chaining
  439. * @example
  440. * ```typescript
  441. * const builder = univerAPI.newDataValidation();
  442. * const rule = builder.setOptions({
  443. * allowBlank: true,
  444. * showErrorMessage: true,
  445. * error: 'Please enter a valid value'
  446. * }).build();
  447. * ```
  448. */
  449. setOptions(e) {
  450. return Object.assign(this._rule, e), this;
  451. }
  452. };
  453. var m3 = class {
  454. constructor(e, t, r) {
  455. f2(this, "rule");
  456. f2(this, "_worksheet");
  457. f2(this, "_injector");
  458. this._injector = r, this.rule = e, this._worksheet = t;
  459. }
  460. /**
  461. * Gets whether invalid data is allowed based on the error style value
  462. * @returns {boolean} true if invalid data is allowed, false otherwise
  463. * @example
  464. * ```typescript
  465. * const dataValidation = univerAPI
  466. * .getActiveWorkbook()
  467. * .getActiveWorksheet()
  468. * .getActiveRange()
  469. * .getDataValidation();
  470. * const allowsInvalid = dataValidation.getAllowInvalid();
  471. * ```
  472. */
  473. getAllowInvalid() {
  474. return this.rule.errorStyle !== _l.STOP;
  475. }
  476. /**
  477. * Gets the data validation type of the rule
  478. * @returns {DataValidationType | string} The data validation type
  479. * @example
  480. * ```typescript
  481. * const dataValidation = univerAPI
  482. * .getActiveWorkbook()
  483. * .getActiveWorksheet()
  484. * .getActiveRange()
  485. * .getDataValidation();
  486. * const type = dataValidation.getCriteriaType();
  487. * ```
  488. */
  489. getCriteriaType() {
  490. return this.rule.type;
  491. }
  492. /**
  493. * Gets the values used for criteria evaluation
  494. * @returns {[string | undefined, string | undefined, string | undefined]} An array containing the operator, formula1, and formula2 values
  495. * @example
  496. * ```typescript
  497. * const dataValidation = univerAPI
  498. * .getActiveWorkbook()
  499. * .getActiveWorksheet()
  500. * .getActiveRange()
  501. * .getDataValidation();
  502. * const [operator, formula1, formula2] = dataValidation.getCriteriaValues();
  503. * ```
  504. */
  505. getCriteriaValues() {
  506. return [this.rule.operator, this.rule.formula1, this.rule.formula2];
  507. }
  508. /**
  509. * Gets the help text information, which is used to provide users with guidance and support
  510. * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value
  511. * @example
  512. * ```typescript
  513. * const dataValidation = univerAPI
  514. * .getActiveWorkbook()
  515. * .getActiveWorksheet()
  516. * .getActiveRange()
  517. * .getDataValidation();
  518. * const helpText = dataValidation.getHelpText();
  519. * ```
  520. */
  521. getHelpText() {
  522. return this.rule.error;
  523. }
  524. /**
  525. * Creates a new instance of FDataValidationBuilder using the current rule object
  526. * @returns {FDataValidationBuilder} A new FDataValidationBuilder instance with the same rule configuration
  527. * @example
  528. * ```typescript
  529. * const dataValidation = univerAPI
  530. * .getActiveWorkbook()
  531. * .getActiveWorksheet()
  532. * .getActiveRange()
  533. * .getDataValidation();
  534. * const builder = dataValidation.copy();
  535. * const newRule = builder.setAllowInvalid(true).build();
  536. * ```
  537. */
  538. copy() {
  539. return new D(this.rule);
  540. }
  541. /**
  542. * Gets whether the data validation rule is applied to the worksheet
  543. * @returns {boolean} true if the rule is applied, false otherwise
  544. * @example
  545. * ```typescript
  546. * const dataValidation = univerAPI
  547. * .getActiveWorkbook()
  548. * .getActiveWorksheet()
  549. * .getActiveRange()
  550. * .getDataValidation();
  551. * const isApplied = dataValidation.getApplied();
  552. * ```
  553. */
  554. getApplied() {
  555. if (!this._worksheet)
  556. return false;
  557. const t = this._injector.get(m).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
  558. return !!(t && t.ranges.length);
  559. }
  560. /**
  561. * Gets the ranges to which the data validation rule is applied
  562. * @returns {FRange[]} An array of FRange objects representing the ranges to which the data validation rule is applied
  563. * @example
  564. * ```typescript
  565. * const dataValidation = univerAPI
  566. * .getActiveWorkbook()
  567. * .getActiveWorksheet()
  568. * .getActiveRange()
  569. * .getDataValidation();
  570. * const ranges = dataValidation.getRanges();
  571. * ```
  572. */
  573. getRanges() {
  574. if (!this.getApplied())
  575. return [];
  576. const e = this._injector.get(_n).getUnit(this._worksheet.getUnitId());
  577. return this.rule.ranges.map((t) => this._injector.createInstance(S, e, this._worksheet, t));
  578. }
  579. /**
  580. * Gets the unit ID of the worksheet
  581. * @returns {string | undefined} The unit ID of the worksheet
  582. * @example
  583. * ```typescript
  584. * const dataValidation = univerAPI
  585. * .getActiveWorkbook()
  586. * .getActiveWorksheet()
  587. * .getActiveRange()
  588. * .getDataValidation();
  589. * const unitId = dataValidation.getUnitId();
  590. * ```
  591. */
  592. getUnitId() {
  593. var e;
  594. return (e = this._worksheet) == null ? void 0 : e.getUnitId();
  595. }
  596. /**
  597. * Gets the sheet ID of the worksheet
  598. * @returns {string | undefined} The sheet ID of the worksheet
  599. * @example
  600. * ```typescript
  601. * const dataValidation = univerAPI
  602. * .getActiveWorkbook()
  603. * .getActiveWorksheet()
  604. * .getActiveRange()
  605. * .getDataValidation();
  606. * const sheetId = dataValidation.getSheetId();
  607. * ```
  608. */
  609. getSheetId() {
  610. var e;
  611. return (e = this._worksheet) == null ? void 0 : e.getSheetId();
  612. }
  613. /**
  614. * Set Criteria for the data validation rule
  615. * @param {DataValidationType} type - The type of data validation criteria
  616. * @param {[DataValidationOperator, string, string]} values - An array containing the operator, formula1, and formula2 values
  617. * @param {boolean} [allowBlank] - Whether to allow blank values
  618. * @returns {FDataValidation} The current instance for method chaining
  619. * @example
  620. * ```typescript
  621. * const dataValidation = univerAPI
  622. * .getActiveWorkbook()
  623. * .getActiveWorksheet()
  624. * .getActiveRange()
  625. * .getDataValidation();
  626. * dataValidation.setCriteria(
  627. * DataValidationType.DECIMAL,
  628. * [DataValidationOperator.BETWEEN, '1', '10'],
  629. * true
  630. * );
  631. * ```
  632. */
  633. setCriteria(e, t, r = true) {
  634. if (this.getApplied() && !this._injector.get(Pt).syncExecuteCommand(Sa.id, {
  635. unitId: this.getUnitId(),
  636. subUnitId: this.getSheetId(),
  637. ruleId: this.rule.uid,
  638. setting: {
  639. operator: t[0],
  640. formula1: t[1],
  641. formula2: t[2],
  642. type: this.rule.type,
  643. allowBlank: r
  644. }
  645. }))
  646. throw new Error("setCriteria failed");
  647. 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;
  648. }
  649. /**
  650. * Set the options for the data validation rule
  651. * @param {Partial<IDataValidationRuleOptions>} options - The options to set for the data validation rule
  652. * @returns {FDataValidation} The current instance for method chaining
  653. * @example
  654. * ```typescript
  655. * const dataValidation = univerAPI
  656. * .getActiveWorkbook()
  657. * .getActiveWorksheet()
  658. * .getActiveRange()
  659. * .getDataValidation();
  660. * dataValidation.setOptions({
  661. * allowBlank: true,
  662. * showErrorMessage: true,
  663. * error: 'Please enter a valid value'
  664. * });
  665. * ```
  666. */
  667. setOptions(e) {
  668. if (this.getApplied() && !this._injector.get(Pt).syncExecuteCommand(va.id, {
  669. unitId: this.getUnitId(),
  670. subUnitId: this.getSheetId(),
  671. ruleId: this.rule.uid,
  672. options: {
  673. ...H(this.rule),
  674. ...e
  675. }
  676. }))
  677. throw new Error("setOptions failed");
  678. return Object.assign(this.rule, e), this;
  679. }
  680. /**
  681. * Set the ranges to the data validation rule
  682. * @param {FRange[]} ranges - New ranges array
  683. * @returns {FDataValidation} The current instance for method chaining
  684. * @example
  685. * ```typescript
  686. * const dataValidation = univerAPI
  687. * .getActiveWorkbook()
  688. * .getActiveWorksheet()
  689. * .getActiveRange()
  690. * .getDataValidation();
  691. * const range = FRange.create('Sheet1', 'A1:B10');
  692. * dataValidation.setRanges([range]);
  693. * ```
  694. */
  695. setRanges(e) {
  696. if (this.getApplied() && !this._injector.get(Pt).syncExecuteCommand(pa.id, {
  697. unitId: this.getUnitId(),
  698. subUnitId: this.getSheetId(),
  699. ruleId: this.rule.uid,
  700. ranges: e.map((a) => a.getRange())
  701. }))
  702. throw new Error("setRanges failed");
  703. return this.rule.ranges = e.map((t) => t.getRange()), this;
  704. }
  705. /**
  706. * Delete the data validation rule from the worksheet
  707. * @returns {boolean} true if the rule is deleted successfully, false otherwise
  708. * @example
  709. * ```typescript
  710. * const dataValidation = univerAPI
  711. * .getActiveWorkbook()
  712. * .getActiveWorksheet()
  713. * .getActiveRange()
  714. * .getDataValidation();
  715. * const isDeleted = dataValidation.delete();
  716. * ```
  717. */
  718. delete() {
  719. return this.getApplied() ? this._injector.get(Pt).syncExecuteCommand(Ea.id, {
  720. unitId: this.getUnitId(),
  721. subUnitId: this.getSheetId(),
  722. ruleId: this.rule.uid
  723. }) : false;
  724. }
  725. };
  726. var G = class extends S {
  727. setDataValidation(e) {
  728. if (!e)
  729. return this._commandService.syncExecuteCommand(Va.id, {
  730. unitId: this._workbook.getUnitId(),
  731. subUnitId: this._worksheet.getSheetId(),
  732. ranges: [this._range]
  733. }), this;
  734. const t = {
  735. unitId: this._workbook.getUnitId(),
  736. subUnitId: this._worksheet.getSheetId(),
  737. rule: {
  738. ...e.rule,
  739. ranges: [this._range]
  740. }
  741. };
  742. return this._commandService.syncExecuteCommand(Ra.id, t), this;
  743. }
  744. getDataValidation() {
  745. const t = this._injector.get(Oe).getDataValidation(
  746. this._workbook.getUnitId(),
  747. this._worksheet.getSheetId(),
  748. [this._range]
  749. );
  750. return t && new m3(t, this._worksheet, this._injector);
  751. }
  752. getDataValidations() {
  753. return this._injector.get(Oe).getDataValidations(
  754. this._workbook.getUnitId(),
  755. this._worksheet.getSheetId(),
  756. [this._range]
  757. ).map((t) => new m3(t, this._worksheet, this._injector));
  758. }
  759. async getValidatorStatus() {
  760. return this._injector.get(Oe).validatorRanges(
  761. this._workbook.getUnitId(),
  762. this._worksheet.getSheetId(),
  763. [this._range]
  764. );
  765. }
  766. };
  767. S.extend(G);
  768. var Q = class extends pi {
  769. // eslint-disable-next-line jsdoc/require-returns
  770. /**
  771. /**
  772. * @deprecated use `univerAPI.newDataValidation()` as instead.
  773. */
  774. static newDataValidation() {
  775. return new D();
  776. }
  777. /**
  778. * Creates a new instance of FDataValidationBuilder
  779. * @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
  780. * @example
  781. * ```ts
  782. * const rule = FUnvier.newDataValidation();
  783. * cell.setDataValidation(rule.requireValueInRange(range));
  784. * ```
  785. */
  786. newDataValidation() {
  787. return new D();
  788. }
  789. // eslint-disable-next-line max-lines-per-function
  790. _initialize(e) {
  791. if (!e.has(F))
  792. return;
  793. const t = e.get(F), r = e.get(Pt);
  794. this.disposeWithMe(t.ruleChange$.subscribe((a) => {
  795. const { unitId: i, subUnitId: n, rule: d, oldRule: u, type: s } = a, l = this.getSheetTarget(i, n);
  796. if (!l)
  797. return;
  798. const { workbook: I, worksheet: k } = l, E = new m3(d, k.getSheet(), this._injector);
  799. this.fireEvent(this.Event.SheetDataValidationChanged, {
  800. origin: a,
  801. worksheet: k,
  802. workbook: I,
  803. changeType: s,
  804. oldRule: u,
  805. rule: E
  806. });
  807. })), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
  808. const { unitId: i, subUnitId: n, ruleId: d, status: u, row: s, col: l } = a, I = this.getSheetTarget(i, n);
  809. if (!I)
  810. return;
  811. const { workbook: k, worksheet: E } = I, L = E.getDataValidation(d);
  812. L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
  813. workbook: k,
  814. worksheet: E,
  815. row: s,
  816. column: l,
  817. rule: L,
  818. status: u
  819. });
  820. })), this.disposeWithMe(r.beforeCommandExecuted((a) => {
  821. switch (a.id) {
  822. case Ra.id: {
  823. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  824. if (!n)
  825. return;
  826. const { workbook: d, worksheet: u } = n, s = {
  827. worksheet: u,
  828. workbook: d,
  829. rule: i.rule
  830. };
  831. if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, s), s.cancel)
  832. throw new xf();
  833. break;
  834. }
  835. case Sa.id: {
  836. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  837. if (!n)
  838. return;
  839. const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
  840. if (!s)
  841. return;
  842. const l = {
  843. worksheet: u,
  844. workbook: d,
  845. rule: s,
  846. ruleId: i.ruleId,
  847. newCriteria: i.setting
  848. };
  849. if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, l), l.cancel)
  850. throw new xf();
  851. break;
  852. }
  853. case pa.id: {
  854. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  855. if (!n)
  856. return;
  857. const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
  858. if (!s)
  859. return;
  860. const l = {
  861. worksheet: u,
  862. workbook: d,
  863. rule: s,
  864. ruleId: i.ruleId,
  865. newRanges: i.ranges
  866. };
  867. if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, l), l.cancel)
  868. throw new xf();
  869. break;
  870. }
  871. case va.id: {
  872. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  873. if (!n)
  874. return;
  875. const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
  876. if (!s)
  877. return;
  878. const l = {
  879. worksheet: u,
  880. workbook: d,
  881. rule: s,
  882. ruleId: i.ruleId,
  883. newOptions: i.options
  884. };
  885. if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, l), l.cancel)
  886. throw new xf();
  887. break;
  888. }
  889. case Ea.id: {
  890. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  891. if (!n)
  892. return;
  893. const { workbook: d, worksheet: u } = n, s = u.getDataValidation(i.ruleId);
  894. if (!s)
  895. return;
  896. const l = {
  897. worksheet: u,
  898. workbook: d,
  899. rule: s,
  900. ruleId: i.ruleId
  901. };
  902. if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, l), l.cancel)
  903. throw new xf();
  904. break;
  905. }
  906. case Ma.id: {
  907. const i = a.params, n = this.getSheetTarget(i.unitId, i.subUnitId);
  908. if (!n)
  909. return;
  910. const { workbook: d, worksheet: u } = n, s = {
  911. worksheet: u,
  912. workbook: d,
  913. rules: u.getDataValidations()
  914. };
  915. if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, s), s.cancel)
  916. throw new xf();
  917. break;
  918. }
  919. }
  920. }));
  921. }
  922. };
  923. pi.extend(Q);
  924. var z = class extends f {
  925. _initialize() {
  926. Object.defineProperty(this, "_dataValidationModel", {
  927. get() {
  928. return this._injector.get(F);
  929. }
  930. });
  931. }
  932. getValidatorStatus() {
  933. return this._injector.get(Oe).validatorWorkbook(this._workbook.getUnitId());
  934. }
  935. // region DataValidationHooks
  936. onDataValidationChange(e) {
  937. return Ze(this._dataValidationModel.ruleChange$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
  938. }
  939. onDataValidationStatusChange(e) {
  940. return Ze(this._dataValidationModel.validStatusChange$.pipe(filter((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
  941. }
  942. onBeforeAddDataValidation(e) {
  943. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  944. const a = t.params;
  945. if (t.id === Ra.id) {
  946. if (a.unitId !== this._workbook.getUnitId())
  947. return;
  948. if (e(a, r) === false)
  949. throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
  950. }
  951. }));
  952. }
  953. onBeforeUpdateDataValidationCriteria(e) {
  954. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  955. const a = t.params;
  956. if (t.id === Sa.id) {
  957. if (a.unitId !== this._workbook.getUnitId())
  958. return;
  959. if (e(a, r) === false)
  960. throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
  961. }
  962. }));
  963. }
  964. onBeforeUpdateDataValidationRange(e) {
  965. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  966. const a = t.params;
  967. if (t.id === pa.id) {
  968. if (a.unitId !== this._workbook.getUnitId())
  969. return;
  970. if (e(a, r) === false)
  971. throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
  972. }
  973. }));
  974. }
  975. onBeforeUpdateDataValidationOptions(e) {
  976. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  977. const a = t.params;
  978. if (t.id === va.id) {
  979. if (a.unitId !== this._workbook.getUnitId())
  980. return;
  981. if (e(a, r) === false)
  982. throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
  983. }
  984. }));
  985. }
  986. onBeforeDeleteDataValidation(e) {
  987. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  988. const a = t.params;
  989. if (t.id === Ea.id) {
  990. if (a.unitId !== this._workbook.getUnitId())
  991. return;
  992. if (e(a, r) === false)
  993. throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
  994. }
  995. }));
  996. }
  997. onBeforeDeleteAllDataValidation(e) {
  998. return Ze(this._commandService.beforeCommandExecuted((t, r) => {
  999. const a = t.params;
  1000. if (t.id === Ma.id) {
  1001. if (a.unitId !== this._workbook.getUnitId())
  1002. return;
  1003. if (e(a, r) === false)
  1004. throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
  1005. }
  1006. }));
  1007. }
  1008. };
  1009. f.extend(z);
  1010. var K = class extends m2 {
  1011. getDataValidations() {
  1012. return this._injector.get(m).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m3(t, this._worksheet, this._injector));
  1013. }
  1014. getValidatorStatus() {
  1015. return this._injector.get(Oe).validatorWorksheet(
  1016. this._workbook.getUnitId(),
  1017. this._worksheet.getSheetId()
  1018. );
  1019. }
  1020. getValidatorStatusAsync() {
  1021. return this.getValidatorStatus();
  1022. }
  1023. getDataValidation(e) {
  1024. const r = this._injector.get(m).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
  1025. return r ? new m3(r, this._worksheet, this._injector) : null;
  1026. }
  1027. };
  1028. m2.extend(K);
  1029. var X = class {
  1030. get SheetDataValidationChanged() {
  1031. return "SheetDataValidationChanged";
  1032. }
  1033. get SheetDataValidatorStatusChanged() {
  1034. return "SheetDataValidatorStatusChanged";
  1035. }
  1036. get BeforeSheetDataValidationAdd() {
  1037. return "BeforeSheetDataValidationAdd";
  1038. }
  1039. get BeforeSheetDataValidationDelete() {
  1040. return "BeforeSheetDataValidationDelete";
  1041. }
  1042. get BeforeSheetDataValidationDeleteAll() {
  1043. return "BeforeSheetDataValidationDeleteAll";
  1044. }
  1045. get BeforeSheetDataValidationCriteriaUpdate() {
  1046. return "BeforeSheetDataValidationCriteriaUpdate";
  1047. }
  1048. get BeforeSheetDataValidationRangeUpdate() {
  1049. return "BeforeSheetDataValidationRangeUpdate";
  1050. }
  1051. get BeforeSheetDataValidationOptionsUpdate() {
  1052. return "BeforeSheetDataValidationOptionsUpdate";
  1053. }
  1054. };
  1055. hi.extend(X);
  1056. export {
  1057. m3 as FDataValidation,
  1058. D as FDataValidationBuilder
  1059. };
  1060. //# sourceMappingURL=@univerjs_sheets-data-validation_facade.js.map