facade.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. var N = Object.defineProperty;
  2. var q = (u, e, t) => e in u ? N(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
  3. var b = (u, e, t) => q(u, typeof e != "symbol" ? e + "" : e, t);
  4. import { ColorKit as c, Tools as _, BooleanNumber as a, Rectangle as U, ColorBuilder as B } from "@univerjs/core";
  5. import { CFRuleType as n, CFNumberOperator as l, CFValueType as C, EMPTY_ICON_TYPE as f, CFSubRuleType as o, CFTextOperator as g, createCfId as T, iconMap as M, ConditionalFormattingRuleModel as x, AddConditionalRuleMutation as S, DeleteConditionalRuleMutation as I, MoveConditionalRuleMutation as E, SetConditionalRuleMutation as k } from "@univerjs/sheets-conditional-formatting";
  6. import { FRange as v, FWorkbook as F, FWorksheet as R } from "@univerjs/sheets/facade";
  7. class d {
  8. constructor(e = {}) {
  9. b(this, "_rule", {});
  10. this._rule = e, this._ensureAttr(this._rule, ["rule"]);
  11. }
  12. get _ruleConfig() {
  13. return this._rule.rule || null;
  14. }
  15. _getDefaultConfig(e = n.highlightCell) {
  16. switch (e) {
  17. case n.colorScale:
  18. return {
  19. type: e,
  20. config: [
  21. { index: 0, color: new c("").toRgbString(), value: { type: C.min } },
  22. { index: 0, color: new c("green").toRgbString(), value: { type: C.max } }
  23. ]
  24. };
  25. case n.dataBar:
  26. return {
  27. type: e,
  28. isShowValue: !0,
  29. config: { min: { type: C.min }, max: { type: C.max }, positiveColor: new c("green").toRgbString(), nativeColor: new c("").toRgbString(), isGradient: !1 }
  30. };
  31. case n.highlightCell:
  32. return {
  33. type: e,
  34. subType: o.text,
  35. operator: g.containsText,
  36. value: "abc",
  37. style: {}
  38. };
  39. case n.iconSet:
  40. return {
  41. type: e,
  42. isShowValue: !0,
  43. config: [
  44. {
  45. operator: l.greaterThanOrEqual,
  46. value: { type: C.min },
  47. iconType: f,
  48. iconId: ""
  49. },
  50. {
  51. operator: l.greaterThanOrEqual,
  52. value: { type: C.percentile, value: 0.5 },
  53. iconType: f,
  54. iconId: ""
  55. },
  56. {
  57. operator: l.lessThanOrEqual,
  58. value: { type: C.max },
  59. iconType: f,
  60. iconId: ""
  61. }
  62. ]
  63. };
  64. }
  65. }
  66. // eslint-disable-next-line ts/no-explicit-any
  67. _ensureAttr(e, t) {
  68. return t.reduce((r, s) => (r[s] || (r[s] = {}), r[s]), e), e;
  69. }
  70. build() {
  71. var r;
  72. this._rule.cfId || (this._rule.cfId = T()), this._rule.ranges || (this._rule.ranges = []), this._rule.stopIfTrue === void 0 && (this._rule.stopIfTrue = !1), (r = this._rule.rule) != null && r.type || (this._rule.rule.type = n.highlightCell, this._ensureAttr(this._rule, ["rule", "style"]));
  73. const e = this._getDefaultConfig(this._rule.rule.type);
  74. return { ...this._rule, rule: { ...e, ...this._rule.rule } };
  75. }
  76. /**
  77. * Deep clone a current builder.
  78. * @returns {*}
  79. * @memberof ConditionalFormatRuleBuilder
  80. */
  81. copy() {
  82. return new d(_.deepClone(this._rule));
  83. }
  84. /**
  85. * Gets the scope of the current conditional format
  86. * @returns {*}
  87. * @memberof ConditionalFormatRuleBuilder
  88. */
  89. getRanges() {
  90. return this._rule.ranges || [];
  91. }
  92. /**
  93. * Get the icon set mapping dictionary
  94. */
  95. getIconMap() {
  96. return M;
  97. }
  98. /**
  99. * Create a conditional format ID.
  100. * @returns {*}
  101. * @memberof ConditionalFormatRuleBuilder
  102. */
  103. createCfId() {
  104. return T();
  105. }
  106. /**
  107. * Sets the scope for conditional formatting
  108. * @param {IRange[]} ranges
  109. * @returns {*}
  110. * @memberof ConditionalFormatRuleBuilder
  111. */
  112. setRanges(e) {
  113. return this._rule.ranges = e, this;
  114. }
  115. }
  116. class i extends d {
  117. constructor(e = {}) {
  118. super(e), this._ensureAttr(this._rule, ["rule", "style"]);
  119. }
  120. copy() {
  121. return new i(_.deepClone(this._rule));
  122. }
  123. /**
  124. * Set average rule
  125. * @param {IAverageHighlightCell['operator']} operator
  126. * @memberof ConditionalFormatHighlightRuleBuilder
  127. */
  128. setAverage(e) {
  129. const t = this._ruleConfig;
  130. return t.type = n.highlightCell, t.subType = o.average, t.operator = e, this;
  131. }
  132. /**
  133. * Set uniqueValues rule
  134. * @memberof ConditionalFormatHighlightRuleBuilder
  135. */
  136. setUniqueValues() {
  137. const e = this._ruleConfig;
  138. return e.type = n.highlightCell, e.subType = o.uniqueValues, this;
  139. }
  140. /**
  141. * Set duplicateValues rule
  142. * @memberof ConditionalFormatHighlightRuleBuilder
  143. */
  144. setDuplicateValues() {
  145. const e = this._ruleConfig;
  146. return e.type = n.highlightCell, e.subType = o.duplicateValues, this;
  147. }
  148. /**
  149. * Set rank rule
  150. * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config
  151. * @param config.isBottom
  152. * @param config.isPercent
  153. * @param config.value
  154. * @memberof ConditionalFormatHighlightRuleBuilder
  155. */
  156. setRank(e) {
  157. const t = this._ruleConfig;
  158. return t.type = n.highlightCell, t.subType = o.rank, t.isBottom = e.isBottom, t.isPercent = e.isPercent, t.value = e.value, this;
  159. }
  160. /**
  161. * Sets the background color
  162. * @param {string} [color]
  163. * @returns {*}
  164. * @memberof ConditionalFormatRuleBuilder
  165. */
  166. setBackground(e) {
  167. var t;
  168. if (((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell)
  169. if (e) {
  170. this._ensureAttr(this._ruleConfig, ["style", "bg"]);
  171. const r = new c(e);
  172. this._ruleConfig.style.bg.rgb = r.toRgbString();
  173. } else
  174. delete this._ruleConfig.style.bg;
  175. return this;
  176. }
  177. /**
  178. * Set Bold
  179. * @param {boolean} isBold
  180. * @returns {*}
  181. * @memberof ConditionalFormatRuleBuilder
  182. */
  183. setBold(e) {
  184. var t;
  185. return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style"]), this._ruleConfig.style.bl = e ? a.TRUE : a.FALSE), this;
  186. }
  187. /**
  188. * Sets the font color
  189. * @param {string} [color]
  190. * @returns {*}
  191. * @memberof ConditionalFormatRuleBuilder
  192. */
  193. setFontColor(e) {
  194. var t;
  195. if (((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell)
  196. if (e) {
  197. const r = new c(e);
  198. this._ensureAttr(this._ruleConfig, ["style", "cl"]), this._ruleConfig.style.cl.rgb = r.toRgbString();
  199. } else
  200. delete this._ruleConfig.style.cl;
  201. return this;
  202. }
  203. /**
  204. * Set the text to italic
  205. * @param {boolean} isItalic
  206. * @returns {*}
  207. * @memberof ConditionalFormatRuleBuilder
  208. */
  209. setItalic(e) {
  210. var t;
  211. return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style"]), this._ruleConfig.style.it = e ? a.TRUE : a.FALSE), this;
  212. }
  213. /**
  214. * Set the strikethrough
  215. * @param {boolean} isStrikethrough
  216. * @returns {*}
  217. * @memberof ConditionalFormatRuleBuilder
  218. */
  219. setStrikethrough(e) {
  220. var t;
  221. return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style", "st"]), this._ruleConfig.style.st.s = e ? a.TRUE : a.FALSE), this;
  222. }
  223. /**
  224. * Set the underscore
  225. * @param {boolean} isUnderline
  226. * @returns {*}
  227. * @memberof ConditionalFormatRuleBuilder
  228. */
  229. setUnderline(e) {
  230. var t;
  231. return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style", "ul"]), this._ruleConfig.style.ul.s = e ? a.TRUE : a.FALSE), this;
  232. }
  233. /**
  234. * Sets the conditional formatting rule to fire when the cell is empty.
  235. */
  236. whenCellEmpty() {
  237. const e = this._ruleConfig;
  238. return e.type = n.highlightCell, e.subType = o.text, e.value = "", e.operator = g.equal, this;
  239. }
  240. /**
  241. * Sets the conditional formatting rule to fire when the cell is not empty
  242. * @returns {*}
  243. * @memberof ConditionalFormatRuleBuilder
  244. */
  245. whenCellNotEmpty() {
  246. const e = this._ruleConfig;
  247. return e.type = n.highlightCell, e.subType = o.text, e.value = "", e.operator = g.notEqual, this;
  248. }
  249. /**
  250. * Highlight when the date is in a time period, custom time is not supported.
  251. * @param {CFTimePeriodOperator} date
  252. * @returns {*}
  253. * @memberof ConditionalFormatRuleBuilder
  254. */
  255. whenDate(e) {
  256. const t = this._ruleConfig;
  257. return t.type = n.highlightCell, t.subType = o.timePeriod, t.operator = e, this;
  258. }
  259. /**
  260. * Sets a conditional formatting rule to fire when a given formula evaluates to true.
  261. * @param {string} formulaString formulaString start with' = '
  262. * @memberof ConditionalFormatRuleBuilder
  263. */
  264. whenFormulaSatisfied(e) {
  265. const t = this._ruleConfig;
  266. return t.type = n.highlightCell, t.subType = o.formula, t.value = e, this;
  267. }
  268. /**
  269. * Sets the conditional formatting rule to fire when a number is between two specified values or equal to one of them.
  270. * @param {number} start
  271. * @param {number} end
  272. * @memberof ConditionalFormatRuleBuilder
  273. */
  274. whenNumberBetween(e, t) {
  275. const r = Math.min(e, t), s = Math.max(e, t), h = this._ruleConfig;
  276. return h.type = n.highlightCell, h.subType = o.number, h.value = [r, s], h.operator = l.between, this;
  277. }
  278. /**
  279. * Sets the conditional formatting rule to fire when the number equals the given value
  280. * @param {number} value
  281. * @memberof ConditionalFormatRuleBuilder
  282. */
  283. whenNumberEqualTo(e) {
  284. const t = this._ruleConfig;
  285. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.equal, this;
  286. }
  287. /**
  288. * Sets the conditional formatting rule to fire when the number is greater than the given value
  289. * @param {number} value
  290. * @memberof ConditionalFormatRuleBuilder
  291. */
  292. whenNumberGreaterThan(e) {
  293. const t = this._ruleConfig;
  294. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.greaterThan, this;
  295. }
  296. /**
  297. * Sets a conditional formatting rule to fire when a number is greater than or equal to a given value.
  298. * @param {number} value
  299. * @memberof ConditionalFormatRuleBuilder
  300. */
  301. whenNumberGreaterThanOrEqualTo(e) {
  302. const t = this._ruleConfig;
  303. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.greaterThanOrEqual, this;
  304. }
  305. /**
  306. * Sets a conditional formatting rule to fire when the number is less than the given value.
  307. * @param {number} value
  308. * @memberof ConditionalFormatRuleBuilder
  309. */
  310. whenNumberLessThan(e) {
  311. const t = this._ruleConfig;
  312. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.lessThan, this;
  313. }
  314. /**
  315. * Sets the conditional formatting rule to fire when the value is less than or equal to the given value.
  316. * @param {number} value
  317. * @memberof ConditionalFormatRuleBuilder
  318. */
  319. whenNumberLessThanOrEqualTo(e) {
  320. const t = this._ruleConfig;
  321. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.lessThanOrEqual, this;
  322. }
  323. /**
  324. * Sets a conditional formatting rule to fire when a number is not between two specified values and is not equal to them.
  325. * @param {number} start
  326. * @param {number} end
  327. * @memberof ConditionalFormatRuleBuilder
  328. */
  329. whenNumberNotBetween(e, t) {
  330. const r = Math.min(e, t), s = Math.max(e, t), h = this._ruleConfig;
  331. return h.type = n.highlightCell, h.subType = o.number, h.value = [r, s], h.operator = l.notBetween, this;
  332. }
  333. /**
  334. * Sets the conditional formatting rule to fire when a number does not equal a given value.
  335. * @param value
  336. * @memberof ConditionalFormatRuleBuilder
  337. */
  338. whenNumberNotEqualTo(e) {
  339. const t = this._ruleConfig;
  340. return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.notEqual, this;
  341. }
  342. /**
  343. * Sets the conditional formatting rule to fire when the input contains the given value.
  344. * @param {string} text
  345. * @memberof ConditionalFormatRuleBuilder
  346. */
  347. whenTextContains(e) {
  348. const t = this._ruleConfig;
  349. return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.containsText, this;
  350. }
  351. /**
  352. * Sets a conditional formatting rule to fire when the input does not contain the given value.
  353. * @param {string} text
  354. * @memberof ConditionalFormatRuleBuilder
  355. */
  356. whenTextDoesNotContain(e) {
  357. const t = this._ruleConfig;
  358. return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.notContainsText, this;
  359. }
  360. /**
  361. * Sets a conditional formatting rule to fire when input ends with a specified value.
  362. * @param {string} text
  363. * @memberof ConditionalFormatRuleBuilder
  364. */
  365. whenTextEndsWith(e) {
  366. const t = this._ruleConfig;
  367. return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.endsWith, this;
  368. }
  369. /**
  370. * Sets the conditional formatting rule to fire when the input equals the given value.
  371. * @param {string} text
  372. * @memberof ConditionalFormatRuleBuilder
  373. */
  374. whenTextEqualTo(e) {
  375. const t = this._ruleConfig;
  376. return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.equal, this;
  377. }
  378. /**
  379. * Sets the conditional formatting rule to fire when the input value begins with the given value.
  380. * @param {string} text
  381. * @memberof ConditionalFormatRuleBuilder
  382. */
  383. whenTextStartsWith(e) {
  384. const t = this._ruleConfig;
  385. return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.beginsWith, this;
  386. }
  387. }
  388. class w extends d {
  389. copy() {
  390. return new w(_.deepClone(this._rule));
  391. }
  392. /**
  393. * Data bar settings
  394. * @param {{
  395. * min: IValueConfig;
  396. * max: IValueConfig;
  397. * isGradient?: boolean;
  398. * positiveColor: string;
  399. * nativeColor: string;
  400. * isShowValue?: boolean;
  401. * }} config
  402. * @param config.min
  403. * @param config.max
  404. * @param config.isGradient
  405. * @param config.positiveColor
  406. * @param config.nativeColor
  407. * @param config.isShowValue
  408. * @memberof ConditionalFormatRuleBuilder
  409. */
  410. setDataBar(e) {
  411. const t = this._ruleConfig;
  412. return t.type = n.dataBar, t.isShowValue = !!e.isShowValue, t.config = {
  413. min: e.min,
  414. max: e.max,
  415. positiveColor: e.positiveColor,
  416. nativeColor: e.nativeColor,
  417. isGradient: !!e.isGradient
  418. }, this;
  419. }
  420. }
  421. class p extends d {
  422. copy() {
  423. return new p(_.deepClone(this._rule));
  424. }
  425. /**
  426. * Color scale set
  427. * @param {{ index: number; color: string; value: IValueConfig }[]} config
  428. * @memberof ConditionalFormatRuleBuilder
  429. */
  430. setColorScale(e) {
  431. const t = this._ruleConfig;
  432. return t.type = n.colorScale, t.config = e, this;
  433. }
  434. }
  435. class y extends d {
  436. copy() {
  437. return new y(_.deepClone(this._rule));
  438. }
  439. /**
  440. *
  441. * Icon Set
  442. * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config
  443. * @param config.iconConfigs
  444. * @param config.isShowValue
  445. * @memberof ConditionalFormatRuleBuilder
  446. */
  447. setIconSet(e) {
  448. const t = this._ruleConfig;
  449. return t.type = n.iconSet, t.config = e.iconConfigs, t.isShowValue = e.isShowValue, this;
  450. }
  451. }
  452. class m {
  453. constructor(e = {}) {
  454. this._initConfig = e;
  455. }
  456. build() {
  457. return new d(this._initConfig).build();
  458. }
  459. /**
  460. * Set average rule
  461. * @param {IAverageHighlightCell['operator']} operator
  462. * @memberof ConditionalFormatHighlightRuleBuilder
  463. */
  464. setAverage(e) {
  465. return new i(this._initConfig).setAverage(e);
  466. }
  467. /**
  468. * Set uniqueValues rule
  469. * @memberof ConditionalFormatHighlightRuleBuilder
  470. */
  471. setUniqueValues() {
  472. return new i(this._initConfig).setUniqueValues();
  473. }
  474. /**
  475. * Set duplicateValues rule
  476. * @memberof ConditionalFormatHighlightRuleBuilder
  477. */
  478. setDuplicateValues() {
  479. return new i(this._initConfig).setDuplicateValues();
  480. }
  481. /**
  482. * Set rank rule
  483. * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config
  484. * @param config.isBottom
  485. * @param config.isPercent
  486. * @param config.value
  487. * @memberof ConditionalFormatHighlightRuleBuilder
  488. */
  489. setRank(e) {
  490. return new i(this._initConfig).setRank(e);
  491. }
  492. /**
  493. *
  494. * Set iconSet rule
  495. * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config
  496. * @param config.iconConfigs
  497. * @param config.isShowValue
  498. * @memberof ConditionalFormatRuleBuilder
  499. */
  500. setIconSet(e) {
  501. return new y(this._initConfig).setIconSet(e);
  502. }
  503. /**
  504. * Set colorScale rule
  505. * @param {{ index: number; color: string; value: IValueConfig }[]} config
  506. * @memberof ConditionalFormatRuleBuilder
  507. */
  508. setColorScale(e) {
  509. return new p(this._initConfig).setColorScale(e);
  510. }
  511. /**
  512. * Set dataBar rule
  513. * @param {{
  514. * min: IValueConfig;
  515. * max: IValueConfig;
  516. * isGradient?: boolean;
  517. * positiveColor: string;
  518. * nativeColor: string;
  519. * isShowValue?: boolean;
  520. * }} config
  521. * @param config.min
  522. * @param config.max
  523. * @param config.isGradient
  524. * @param config.positiveColor
  525. * @param config.nativeColor
  526. * @param config.isShowValue
  527. * @memberof ConditionalFormatRuleBuilder
  528. */
  529. setDataBar(e) {
  530. return new w(this._initConfig).setDataBar(e);
  531. }
  532. /**
  533. * Sets the background color
  534. * @param {string} [color]
  535. * @returns {*}
  536. * @memberof ConditionalFormatRuleBuilder
  537. */
  538. setBackground(e) {
  539. return new i(this._initConfig).setBackground(e);
  540. }
  541. /**
  542. * Set Bold
  543. * @param {boolean} isBold
  544. * @returns {*}
  545. * @memberof ConditionalFormatRuleBuilder
  546. */
  547. setBold(e) {
  548. return new i(this._initConfig).setBold(e);
  549. }
  550. /**
  551. * Sets the font color
  552. * @param {string} [color]
  553. * @returns {*}
  554. * @memberof ConditionalFormatRuleBuilder
  555. */
  556. setFontColor(e) {
  557. return new i(this._initConfig).setFontColor(e);
  558. }
  559. /**
  560. * Set the text to italic
  561. * @param {boolean} isItalic
  562. * @returns {*}
  563. * @memberof ConditionalFormatRuleBuilder
  564. */
  565. setItalic(e) {
  566. return new i(this._initConfig).setItalic(e);
  567. }
  568. /**
  569. * Set the strikethrough
  570. * @param {boolean} isStrikethrough
  571. * @returns {*}
  572. * @memberof ConditionalFormatRuleBuilder
  573. */
  574. setStrikethrough(e) {
  575. return new i(this._initConfig).setStrikethrough(e);
  576. }
  577. /**
  578. * Set the underscore
  579. * @param {boolean} isUnderline
  580. * @returns {*}
  581. * @memberof ConditionalFormatRuleBuilder
  582. */
  583. setUnderline(e) {
  584. return new i(this._initConfig).setUnderline(e);
  585. }
  586. /**
  587. * Sets the conditional formatting rule to fire when the cell is empty.
  588. */
  589. whenCellEmpty() {
  590. return new i(this._initConfig).whenCellEmpty();
  591. }
  592. /**
  593. * Sets the conditional formatting rule to fire when the cell is not empty
  594. * @returns {*}
  595. * @memberof ConditionalFormatRuleBuilder
  596. */
  597. whenCellNotEmpty() {
  598. return new i(this._initConfig).whenCellNotEmpty();
  599. }
  600. /**
  601. * Highlight when the date is in a time period, custom time is not supported.
  602. * @param {CFTimePeriodOperator} date
  603. * @returns {*}
  604. * @memberof ConditionalFormatRuleBuilder
  605. */
  606. whenDate(e) {
  607. return new i(this._initConfig).whenDate(e);
  608. }
  609. /**
  610. * Sets a conditional formatting rule to fire when a given formula evaluates to true.
  611. * @param {string} formulaString formulaString start with' = '
  612. * @memberof ConditionalFormatRuleBuilder
  613. */
  614. whenFormulaSatisfied(e) {
  615. return new i(this._initConfig).whenFormulaSatisfied(e);
  616. }
  617. /**
  618. * Sets the conditional formatting rule to fire when a number is between two specified values or equal to one of them.
  619. * @param {number} start
  620. * @param {number} end
  621. * @memberof ConditionalFormatRuleBuilder
  622. */
  623. whenNumberBetween(e, t) {
  624. return new i(this._initConfig).whenNumberBetween(e, t);
  625. }
  626. /**
  627. * Sets the conditional formatting rule to fire when the number equals the given value
  628. * @param {number} value
  629. * @memberof ConditionalFormatRuleBuilder
  630. */
  631. whenNumberEqualTo(e) {
  632. return new i(this._initConfig).whenNumberEqualTo(e);
  633. }
  634. /**
  635. * Sets the conditional formatting rule to fire when the number is greater than the given value
  636. * @param {number} value
  637. * @memberof ConditionalFormatRuleBuilder
  638. */
  639. whenNumberGreaterThan(e) {
  640. return new i(this._initConfig).whenNumberGreaterThan(e);
  641. }
  642. /**
  643. * Sets a conditional formatting rule to fire when a number is greater than or equal to a given value.
  644. * @param {number} value
  645. * @memberof ConditionalFormatRuleBuilder
  646. */
  647. whenNumberGreaterThanOrEqualTo(e) {
  648. return new i(this._initConfig).whenNumberGreaterThanOrEqualTo(e);
  649. }
  650. /**
  651. * Sets a conditional formatting rule to fire when the number is less than the given value.
  652. * @param {number} value
  653. * @memberof ConditionalFormatRuleBuilder
  654. */
  655. whenNumberLessThan(e) {
  656. return new i(this._initConfig).whenNumberLessThan(e);
  657. }
  658. /**
  659. * Sets the conditional formatting rule to fire when the value is less than or equal to the given value.
  660. * @param {number} value
  661. * @memberof ConditionalFormatRuleBuilder
  662. */
  663. whenNumberLessThanOrEqualTo(e) {
  664. return new i(this._initConfig).whenNumberLessThanOrEqualTo(e);
  665. }
  666. /**
  667. * Sets a conditional formatting rule to fire when a number is not between two specified values and is not equal to them.
  668. * @param {number} start
  669. * @param {number} end
  670. * @memberof ConditionalFormatRuleBuilder
  671. */
  672. whenNumberNotBetween(e, t) {
  673. return new i(this._initConfig).whenNumberNotBetween(e, t);
  674. }
  675. /**
  676. * Sets the conditional formatting rule to fire when a number does not equal a given value.
  677. * @param value
  678. * @memberof ConditionalFormatRuleBuilder
  679. */
  680. whenNumberNotEqualTo(e) {
  681. return new i(this._initConfig).whenNumberNotEqualTo(e);
  682. }
  683. /**
  684. * Sets the conditional formatting rule to fire when the input contains the given value.
  685. * @param {string} text
  686. * @memberof ConditionalFormatRuleBuilder
  687. */
  688. whenTextContains(e) {
  689. return new i(this._initConfig).whenTextContains(e);
  690. }
  691. /**
  692. * Sets a conditional formatting rule to fire when the input does not contain the given value.
  693. * @param {string} text
  694. * @memberof ConditionalFormatRuleBuilder
  695. */
  696. whenTextDoesNotContain(e) {
  697. return new i(this._initConfig).whenTextDoesNotContain(e);
  698. }
  699. /**
  700. * Sets a conditional formatting rule to fire when input ends with a specified value.
  701. * @param {string} text
  702. * @memberof ConditionalFormatRuleBuilder
  703. */
  704. whenTextEndsWith(e) {
  705. return new i(this._initConfig).whenTextEndsWith(e);
  706. }
  707. /**
  708. * Sets the conditional formatting rule to fire when the input equals the given value.
  709. * @param {string} text
  710. * @memberof ConditionalFormatRuleBuilder
  711. */
  712. whenTextEqualTo(e) {
  713. return new i(this._initConfig).whenTextEqualTo(e);
  714. }
  715. /**
  716. * Sets the conditional formatting rule to fire when the input value begins with the given value.
  717. * @param {string} text
  718. * @memberof ConditionalFormatRuleBuilder
  719. */
  720. whenTextStartsWith(e) {
  721. return new i(this._initConfig).whenTextStartsWith(e);
  722. }
  723. }
  724. class A extends v {
  725. _getConditionalFormattingRuleModel() {
  726. return this._injector.get(x);
  727. }
  728. getConditionalFormattingRules() {
  729. return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []].filter((t) => t.ranges.some((r) => U.intersects(r, this._range)));
  730. }
  731. createConditionalFormattingRule() {
  732. return new m({ ranges: [this._range] });
  733. }
  734. addConditionalFormattingRule(e) {
  735. const t = {
  736. rule: e,
  737. unitId: this._workbook.getUnitId(),
  738. subUnitId: this._worksheet.getSheetId()
  739. };
  740. return this._commandService.syncExecuteCommand(S.id, t), this;
  741. }
  742. deleteConditionalFormattingRule(e) {
  743. const t = {
  744. unitId: this._workbook.getUnitId(),
  745. subUnitId: this._worksheet.getSheetId(),
  746. cfId: e
  747. };
  748. return this._commandService.syncExecuteCommand(I.id, t), this;
  749. }
  750. moveConditionalFormattingRule(e, t, r = "after") {
  751. const s = {
  752. unitId: this._workbook.getUnitId(),
  753. subUnitId: this._worksheet.getSheetId(),
  754. start: { id: e, type: "self" },
  755. end: { id: t, type: r }
  756. };
  757. return this._commandService.syncExecuteCommand(E.id, s), this;
  758. }
  759. setConditionalFormattingRule(e, t) {
  760. const r = {
  761. unitId: this._workbook.getUnitId(),
  762. subUnitId: this._worksheet.getSheetId(),
  763. rule: t,
  764. cfId: e
  765. };
  766. return this._commandService.syncExecuteCommand(k.id, r), this;
  767. }
  768. }
  769. v.extend(A);
  770. class D extends F {
  771. newColor() {
  772. return new B();
  773. }
  774. }
  775. F.extend(D);
  776. class V extends R {
  777. _getConditionalFormattingRuleModel() {
  778. return this._injector.get(x);
  779. }
  780. getConditionalFormattingRules() {
  781. return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []];
  782. }
  783. createConditionalFormattingRule() {
  784. return new m();
  785. }
  786. newConditionalFormattingRule() {
  787. return new m();
  788. }
  789. addConditionalFormattingRule(e) {
  790. const t = {
  791. rule: e,
  792. unitId: this._workbook.getUnitId(),
  793. subUnitId: this._worksheet.getSheetId()
  794. };
  795. return this._commandService.syncExecuteCommand(S.id, t), this;
  796. }
  797. deleteConditionalFormattingRule(e) {
  798. const t = {
  799. unitId: this._workbook.getUnitId(),
  800. subUnitId: this._worksheet.getSheetId(),
  801. cfId: e
  802. };
  803. return this._commandService.syncExecuteCommand(I.id, t), this;
  804. }
  805. moveConditionalFormattingRule(e, t, r = "after") {
  806. const s = {
  807. unitId: this._workbook.getUnitId(),
  808. subUnitId: this._worksheet.getSheetId(),
  809. start: { id: e, type: "self" },
  810. end: { id: t, type: r }
  811. };
  812. return this._commandService.syncExecuteCommand(E.id, s), this;
  813. }
  814. setConditionalFormattingRule(e, t) {
  815. const r = {
  816. unitId: this._workbook.getUnitId(),
  817. subUnitId: this._worksheet.getSheetId(),
  818. rule: t,
  819. cfId: e
  820. };
  821. return this._commandService.syncExecuteCommand(k.id, r), this;
  822. }
  823. }
  824. R.extend(V);
  825. export {
  826. m as FConditionalFormattingBuilder
  827. };