| 1 |
- "use strict";var y=Object.defineProperty;var c=(l,e,t)=>e in l?y(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t;var T=(l,e,t)=>c(l,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),n=require("@univerjs/sheets-conditional-formatting"),a=require("@univerjs/sheets/facade");class h{constructor(e={}){T(this,"_rule",{});this._rule=e,this._ensureAttr(this._rule,["rule"])}get _ruleConfig(){return this._rule.rule||null}_getDefaultConfig(e=n.CFRuleType.highlightCell){switch(e){case n.CFRuleType.colorScale:return{type:e,config:[{index:0,color:new o.ColorKit("").toRgbString(),value:{type:n.CFValueType.min}},{index:0,color:new o.ColorKit("green").toRgbString(),value:{type:n.CFValueType.max}}]};case n.CFRuleType.dataBar:return{type:e,isShowValue:!0,config:{min:{type:n.CFValueType.min},max:{type:n.CFValueType.max},positiveColor:new o.ColorKit("green").toRgbString(),nativeColor:new o.ColorKit("").toRgbString(),isGradient:!1}};case n.CFRuleType.highlightCell:return{type:e,subType:n.CFSubRuleType.text,operator:n.CFTextOperator.containsText,value:"abc",style:{}};case n.CFRuleType.iconSet:return{type:e,isShowValue:!0,config:[{operator:n.CFNumberOperator.greaterThanOrEqual,value:{type:n.CFValueType.min},iconType:n.EMPTY_ICON_TYPE,iconId:""},{operator:n.CFNumberOperator.greaterThanOrEqual,value:{type:n.CFValueType.percentile,value:.5},iconType:n.EMPTY_ICON_TYPE,iconId:""},{operator:n.CFNumberOperator.lessThanOrEqual,value:{type:n.CFValueType.max},iconType:n.EMPTY_ICON_TYPE,iconId:""}]}}}_ensureAttr(e,t){return t.reduce((r,u)=>(r[u]||(r[u]={}),r[u]),e),e}build(){var r;this._rule.cfId||(this._rule.cfId=n.createCfId()),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.CFRuleType.highlightCell,this._ensureAttr(this._rule,["rule","style"]));const e=this._getDefaultConfig(this._rule.rule.type);return{...this._rule,rule:{...e,...this._rule.rule}}}copy(){return new h(o.Tools.deepClone(this._rule))}getRanges(){return this._rule.ranges||[]}getIconMap(){return n.iconMap}createCfId(){return n.createCfId()}setRanges(e){return this._rule.ranges=e,this}}class i extends h{constructor(e={}){super(e),this._ensureAttr(this._rule,["rule","style"])}copy(){return new i(o.Tools.deepClone(this._rule))}setAverage(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.average,t.operator=e,this}setUniqueValues(){const e=this._ruleConfig;return e.type=n.CFRuleType.highlightCell,e.subType=n.CFSubRuleType.uniqueValues,this}setDuplicateValues(){const e=this._ruleConfig;return e.type=n.CFRuleType.highlightCell,e.subType=n.CFSubRuleType.duplicateValues,this}setRank(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.rank,t.isBottom=e.isBottom,t.isPercent=e.isPercent,t.value=e.value,this}setBackground(e){var t;if(((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell)if(e){this._ensureAttr(this._ruleConfig,["style","bg"]);const r=new o.ColorKit(e);this._ruleConfig.style.bg.rgb=r.toRgbString()}else delete this._ruleConfig.style.bg;return this}setBold(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.bl=e?o.BooleanNumber.TRUE:o.BooleanNumber.FALSE),this}setFontColor(e){var t;if(((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell)if(e){const r=new o.ColorKit(e);this._ensureAttr(this._ruleConfig,["style","cl"]),this._ruleConfig.style.cl.rgb=r.toRgbString()}else delete this._ruleConfig.style.cl;return this}setItalic(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.it=e?o.BooleanNumber.TRUE:o.BooleanNumber.FALSE),this}setStrikethrough(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","st"]),this._ruleConfig.style.st.s=e?o.BooleanNumber.TRUE:o.BooleanNumber.FALSE),this}setUnderline(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===n.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","ul"]),this._ruleConfig.style.ul.s=e?o.BooleanNumber.TRUE:o.BooleanNumber.FALSE),this}whenCellEmpty(){const e=this._ruleConfig;return e.type=n.CFRuleType.highlightCell,e.subType=n.CFSubRuleType.text,e.value="",e.operator=n.CFTextOperator.equal,this}whenCellNotEmpty(){const e=this._ruleConfig;return e.type=n.CFRuleType.highlightCell,e.subType=n.CFSubRuleType.text,e.value="",e.operator=n.CFTextOperator.notEqual,this}whenDate(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.timePeriod,t.operator=e,this}whenFormulaSatisfied(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.formula,t.value=e,this}whenNumberBetween(e,t){const r=Math.min(e,t),u=Math.max(e,t),s=this._ruleConfig;return s.type=n.CFRuleType.highlightCell,s.subType=n.CFSubRuleType.number,s.value=[r,u],s.operator=n.CFNumberOperator.between,this}whenNumberEqualTo(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.equal,this}whenNumberGreaterThan(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.greaterThan,this}whenNumberGreaterThanOrEqualTo(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.greaterThanOrEqual,this}whenNumberLessThan(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.lessThan,this}whenNumberLessThanOrEqualTo(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.lessThanOrEqual,this}whenNumberNotBetween(e,t){const r=Math.min(e,t),u=Math.max(e,t),s=this._ruleConfig;return s.type=n.CFRuleType.highlightCell,s.subType=n.CFSubRuleType.number,s.value=[r,u],s.operator=n.CFNumberOperator.notBetween,this}whenNumberNotEqualTo(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.number,t.value=e,t.operator=n.CFNumberOperator.notEqual,this}whenTextContains(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.text,t.value=e,t.operator=n.CFTextOperator.containsText,this}whenTextDoesNotContain(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.text,t.value=e,t.operator=n.CFTextOperator.notContainsText,this}whenTextEndsWith(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.text,t.value=e,t.operator=n.CFTextOperator.endsWith,this}whenTextEqualTo(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.text,t.value=e,t.operator=n.CFTextOperator.equal,this}whenTextStartsWith(e){const t=this._ruleConfig;return t.type=n.CFRuleType.highlightCell,t.subType=n.CFSubRuleType.text,t.value=e,t.operator=n.CFTextOperator.beginsWith,this}}class g extends h{copy(){return new g(o.Tools.deepClone(this._rule))}setDataBar(e){const t=this._ruleConfig;return t.type=n.CFRuleType.dataBar,t.isShowValue=!!e.isShowValue,t.config={min:e.min,max:e.max,positiveColor:e.positiveColor,nativeColor:e.nativeColor,isGradient:!!e.isGradient},this}}class p extends h{copy(){return new p(o.Tools.deepClone(this._rule))}setColorScale(e){const t=this._ruleConfig;return t.type=n.CFRuleType.colorScale,t.config=e,this}}class d extends h{copy(){return new d(o.Tools.deepClone(this._rule))}setIconSet(e){const t=this._ruleConfig;return t.type=n.CFRuleType.iconSet,t.config=e.iconConfigs,t.isShowValue=e.isShowValue,this}}class C{constructor(e={}){this._initConfig=e}build(){return new h(this._initConfig).build()}setAverage(e){return new i(this._initConfig).setAverage(e)}setUniqueValues(){return new i(this._initConfig).setUniqueValues()}setDuplicateValues(){return new i(this._initConfig).setDuplicateValues()}setRank(e){return new i(this._initConfig).setRank(e)}setIconSet(e){return new d(this._initConfig).setIconSet(e)}setColorScale(e){return new p(this._initConfig).setColorScale(e)}setDataBar(e){return new g(this._initConfig).setDataBar(e)}setBackground(e){return new i(this._initConfig).setBackground(e)}setBold(e){return new i(this._initConfig).setBold(e)}setFontColor(e){return new i(this._initConfig).setFontColor(e)}setItalic(e){return new i(this._initConfig).setItalic(e)}setStrikethrough(e){return new i(this._initConfig).setStrikethrough(e)}setUnderline(e){return new i(this._initConfig).setUnderline(e)}whenCellEmpty(){return new i(this._initConfig).whenCellEmpty()}whenCellNotEmpty(){return new i(this._initConfig).whenCellNotEmpty()}whenDate(e){return new i(this._initConfig).whenDate(e)}whenFormulaSatisfied(e){return new i(this._initConfig).whenFormulaSatisfied(e)}whenNumberBetween(e,t){return new i(this._initConfig).whenNumberBetween(e,t)}whenNumberEqualTo(e){return new i(this._initConfig).whenNumberEqualTo(e)}whenNumberGreaterThan(e){return new i(this._initConfig).whenNumberGreaterThan(e)}whenNumberGreaterThanOrEqualTo(e){return new i(this._initConfig).whenNumberGreaterThanOrEqualTo(e)}whenNumberLessThan(e){return new i(this._initConfig).whenNumberLessThan(e)}whenNumberLessThanOrEqualTo(e){return new i(this._initConfig).whenNumberLessThanOrEqualTo(e)}whenNumberNotBetween(e,t){return new i(this._initConfig).whenNumberNotBetween(e,t)}whenNumberNotEqualTo(e){return new i(this._initConfig).whenNumberNotEqualTo(e)}whenTextContains(e){return new i(this._initConfig).whenTextContains(e)}whenTextDoesNotContain(e){return new i(this._initConfig).whenTextDoesNotContain(e)}whenTextEndsWith(e){return new i(this._initConfig).whenTextEndsWith(e)}whenTextEqualTo(e){return new i(this._initConfig).whenTextEqualTo(e)}whenTextStartsWith(e){return new i(this._initConfig).whenTextStartsWith(e)}}class m extends a.FRange{_getConditionalFormattingRuleModel(){return this._injector.get(n.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]].filter(t=>t.ranges.some(r=>o.Rectangle.intersects(r,this._range)))}createConditionalFormattingRule(){return new C({ranges:[this._range]})}addConditionalFormattingRule(e){const t={rule:e,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.syncExecuteCommand(n.AddConditionalRuleMutation.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(n.DeleteConditionalRuleMutation.id,t),this}moveConditionalFormattingRule(e,t,r="after"){const u={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:r}};return this._commandService.syncExecuteCommand(n.MoveConditionalRuleMutation.id,u),this}setConditionalFormattingRule(e,t){const r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.syncExecuteCommand(n.SetConditionalRuleMutation.id,r),this}}a.FRange.extend(m);class _ extends a.FWorkbook{newColor(){return new o.ColorBuilder}}a.FWorkbook.extend(_);class f extends a.FWorksheet{_getConditionalFormattingRuleModel(){return this._injector.get(n.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]]}createConditionalFormattingRule(){return new C}newConditionalFormattingRule(){return new C}addConditionalFormattingRule(e){const t={rule:e,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.syncExecuteCommand(n.AddConditionalRuleMutation.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(n.DeleteConditionalRuleMutation.id,t),this}moveConditionalFormattingRule(e,t,r="after"){const u={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:r}};return this._commandService.syncExecuteCommand(n.MoveConditionalRuleMutation.id,u),this}setConditionalFormattingRule(e,t){const r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.syncExecuteCommand(n.SetConditionalRuleMutation.id,r),this}}a.FWorksheet.extend(f);exports.FConditionalFormattingBuilder=C;
|