@univerjs/sheets-conditional-formatting 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,5 +61,5 @@ export declare enum CFValueType {
61
61
  export declare const DEFAULT_BG_COLOR = "#fff";
62
62
  export declare const DEFAULT_FONT_COLOR = "#000000";
63
63
  export declare const createDefaultRule: () => IConditionFormattingRule;
64
- export declare const createDefaultValue: (subType: CFSubRuleType, operator: CFTextOperator | CFNumberOperator | CFTimePeriodOperator) => "" | 10 | [number, number];
64
+ export declare const createDefaultValue: (subType: CFSubRuleType, operator: CFTextOperator | CFNumberOperator | CFTimePeriodOperator) => 10 | "" | [number, number];
65
65
  export declare const createDefaultValueByValueType: (type: CFValueType, defaultValue?: number) => number | "" | "=";
@@ -0,0 +1,9 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { IConditionFormattingRule } from '../../models/type';
3
+ import { MakePropertyOptional } from '../../utils/type';
4
+ export interface IAddCfCommandParams {
5
+ unitId?: string;
6
+ subUnitId?: string;
7
+ rule: MakePropertyOptional<IConditionFormattingRule, 'cfId'>;
8
+ }
9
+ export declare const AddCfCommand: ICommand<IAddCfCommandParams>;
@@ -0,0 +1,7 @@
1
+ import { ICommand, IRange } from '@univerjs/core';
2
+ export interface IClearRangeCfParams {
3
+ ranges?: IRange[];
4
+ unitId?: string;
5
+ subUnitId?: string;
6
+ }
7
+ export declare const ClearRangeCfCommand: ICommand<IClearRangeCfParams>;
@@ -0,0 +1,6 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ export interface IClearWorksheetCfParams {
3
+ unitId?: string;
4
+ subUnitId?: string;
5
+ }
6
+ export declare const ClearWorksheetCfCommand: ICommand<IClearWorksheetCfParams>;
@@ -0,0 +1,7 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ export interface IDeleteCfCommandParams {
3
+ unitId?: string;
4
+ subUnitId?: string;
5
+ cfId: string;
6
+ }
7
+ export declare const DeleteCfCommand: ICommand<IDeleteCfCommandParams>;
@@ -0,0 +1,9 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { IAnchor } from '../../utils/anchor';
3
+ export interface IMoveCfCommandParams {
4
+ unitId?: string;
5
+ subUnitId?: string;
6
+ start: IAnchor;
7
+ end: IAnchor;
8
+ }
9
+ export declare const MoveCfCommand: ICommand<IMoveCfCommandParams>;
@@ -0,0 +1,9 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { IConditionFormattingRule } from '../../models/type';
3
+ export interface ISetCfCommandParams {
4
+ unitId?: string;
5
+ subUnitId?: string;
6
+ cfId?: string;
7
+ rule: IConditionFormattingRule;
8
+ }
9
+ export declare const SetCfCommand: ICommand<ISetCfCommandParams>;
@@ -10,7 +10,7 @@ declare class ConditionalFormatRuleBaseBuilder {
10
10
  protected _getDefaultConfig(type?: CFRuleType): IConditionalFormattingRuleConfig;
11
11
  constructor(initRule?: Partial<IConditionFormattingRule>);
12
12
  protected _ensureAttr(obj: Record<string, any>, keys: string[]): Record<string, any>;
13
- build(): IConditionFormattingRule<IConditionalFormattingRuleConfig>;
13
+ build(): IConditionFormattingRule;
14
14
  /**
15
15
  * Deep clone a current builder.
16
16
  * @returns {*}
@@ -283,7 +283,18 @@ export declare class FConditionalFormattingBuilder {
283
283
  constructor(_initConfig?: {
284
284
  ranges?: IRange[];
285
285
  });
286
- build(): IConditionFormattingRule<IConditionalFormattingRuleConfig>;
286
+ /**
287
+ * Constructs a conditional format rule from the settings applied to the builder.
288
+ * @returns {IConditionFormattingRule} The conditional format rule.
289
+ * @example
290
+ * ```typescript
291
+ * const fWorkbook = univerAPI.getActiveWorkbook();
292
+ * const fWorksheet = fWorkbook.getActiveSheet();
293
+ * const rule = fWorksheet.newConditionalFormattingRule().build();
294
+ * fWorksheet.setConditionalFormattingRules([rule]);
295
+ * ```
296
+ */
297
+ build(): IConditionFormattingRule;
287
298
  /**
288
299
  * Set average rule
289
300
  * @param {IAverageHighlightCell['operator']} operator
@@ -102,6 +102,12 @@ export interface IFRangeConditionalFormattingMixin {
102
102
  * ```
103
103
  */
104
104
  setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FRange;
105
+ /**
106
+ * Clear the conditional rules for the range.
107
+ * @returns {FRange} Returns the current range instance for method chaining
108
+ * @memberof IFRangeConditionalFormattingMixin
109
+ */
110
+ clearConditionalFormatRules(): FRange;
105
111
  }
106
112
  export declare class FRangeConditionalFormattingMixin extends FRange implements IFRangeConditionalFormattingMixin {
107
113
  private _getConditionalFormattingRuleModel;
@@ -111,6 +117,7 @@ export declare class FRangeConditionalFormattingMixin extends FRange implements
111
117
  deleteConditionalFormattingRule(cfId: string): FRange;
112
118
  moveConditionalFormattingRule(cfId: string, toCfId: string, type?: IAnchor['type']): FRange;
113
119
  setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FRange;
120
+ clearConditionalFormatRules(): FRange;
114
121
  }
115
122
  declare module '@univerjs/sheets/facade' {
116
123
  interface FRange extends IFRangeConditionalFormattingMixin {
@@ -138,6 +138,19 @@ export interface IFWorksheetConditionalFormattingMixin {
138
138
  * ```
139
139
  */
140
140
  setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FWorksheet;
141
+ /**
142
+ * Removes all conditional format rules from the sheet.
143
+ * @returns {FWorksheet} Returns the current worksheet instance for method chaining
144
+ * @memberof IFWorksheetConditionalFormattingMixin
145
+ * @example
146
+ * ```ts
147
+ * const fWorkbook = univerAPI.getActiveWorkbook();
148
+ * const fWorksheet = fWorkbook.getActiveSheet();
149
+ * fWorksheet.clearConditionalFormatRules();
150
+ * console.log(fWorksheet.getConditionalFormattingRules());
151
+ * ```
152
+ */
153
+ clearConditionalFormatRules(): FWorksheet;
141
154
  }
142
155
  export declare class FWorksheetConditionalFormattingMixin extends FWorksheet implements IFWorksheetConditionalFormattingMixin {
143
156
  private _getConditionalFormattingRuleModel;
@@ -148,6 +161,7 @@ export declare class FWorksheetConditionalFormattingMixin extends FWorksheet imp
148
161
  deleteConditionalFormattingRule(cfId: string): FWorksheet;
149
162
  moveConditionalFormattingRule(cfId: string, toCfId: string, type?: IAnchor['type']): FWorksheet;
150
163
  setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FWorksheet;
164
+ clearConditionalFormatRules(): FWorksheet;
151
165
  }
152
166
  declare module '@univerjs/sheets/facade' {
153
167
  interface FWorksheet extends IFWorksheetConditionalFormattingMixin {
@@ -30,6 +30,12 @@ export * from './utils/create-cf-id';
30
30
  export * from './utils/is-ranges-equal';
31
31
  export * from './utils/remove-undefined-attr';
32
32
  export * from './utils/type';
33
+ export { AddCfCommand, type IAddCfCommandParams, } from './commands/commands/add-cf.command';
34
+ export { ClearRangeCfCommand, type IClearRangeCfParams, } from './commands/commands/clear-range-cf.command';
35
+ export { ClearWorksheetCfCommand, type IClearWorksheetCfParams, } from './commands/commands/clear-worksheet-cf.command';
36
+ export { DeleteCfCommand, type IDeleteCfCommandParams, } from './commands/commands/delete-cf.command';
37
+ export { type IMoveCfCommandParams, MoveCfCommand, } from './commands/commands/move-cf.command';
38
+ export { type ISetCfCommandParams, SetCfCommand, } from './commands/commands/set-cf.command';
33
39
  export { AddConditionalRuleMutation, AddConditionalRuleMutationUndoFactory, type IAddConditionalRuleMutationParams, } from './commands/mutations/add-conditional-rule.mutation';
34
40
  export { DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, type IDeleteConditionalRuleMutationParams, } from './commands/mutations/delete-conditional-rule.mutation';
35
41
  export { ConditionalFormattingFormulaMarkDirty } from './commands/mutations/formula-mark-dirty.mutation';
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets-conditional-formatting"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-conditional-formatting","@univerjs/sheets/facade"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.UniverSheetsConditionalFormattingFacade={},i.UniverCore,i.UniverSheetsConditionalFormatting,i.UniverSheetsFacade))})(this,function(i,r,u,p){"use strict";var w=Object.defineProperty;var R=(i,r,u)=>r in i?w(i,r,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[r]=u;var _=(i,r,u)=>R(i,typeof r!="symbol"?r+"":r,u);class o{constructor(e={}){_(this,"_rule",{});this._rule=e,this._ensureAttr(this._rule,["rule"])}get _ruleConfig(){return this._rule.rule||null}_getDefaultConfig(e=u.CFRuleType.highlightCell){switch(e){case u.CFRuleType.colorScale:return{type:e,config:[{index:0,color:new r.ColorKit("").toRgbString(),value:{type:u.CFValueType.min}},{index:0,color:new r.ColorKit("green").toRgbString(),value:{type:u.CFValueType.max}}]};case u.CFRuleType.dataBar:return{type:e,isShowValue:!0,config:{min:{type:u.CFValueType.min},max:{type:u.CFValueType.max},positiveColor:new r.ColorKit("green").toRgbString(),nativeColor:new r.ColorKit("").toRgbString(),isGradient:!1}};case u.CFRuleType.highlightCell:return{type:e,subType:u.CFSubRuleType.text,operator:u.CFTextOperator.containsText,value:"abc",style:{}};case u.CFRuleType.iconSet:return{type:e,isShowValue:!0,config:[{operator:u.CFNumberOperator.greaterThanOrEqual,value:{type:u.CFValueType.min},iconType:u.EMPTY_ICON_TYPE,iconId:""},{operator:u.CFNumberOperator.greaterThanOrEqual,value:{type:u.CFValueType.percentile,value:.5},iconType:u.EMPTY_ICON_TYPE,iconId:""},{operator:u.CFNumberOperator.lessThanOrEqual,value:{type:u.CFValueType.max},iconType:u.EMPTY_ICON_TYPE,iconId:""}]}}}_ensureAttr(e,t){return t.reduce((l,s)=>(l[s]||(l[s]={}),l[s]),e),e}build(){var l;this._rule.cfId||(this._rule.cfId=u.createCfId()),this._rule.ranges||(this._rule.ranges=[]),this._rule.stopIfTrue===void 0&&(this._rule.stopIfTrue=!1),(l=this._rule.rule)!=null&&l.type||(this._rule.rule.type=u.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 o(r.Tools.deepClone(this._rule))}getRanges(){return this._rule.ranges||[]}getIconMap(){return u.iconMap}createCfId(){return u.createCfId()}setRanges(e){return this._rule.ranges=e,this}}class n extends o{constructor(e={}){super(e),this._ensureAttr(this._rule,["rule","style"])}copy(){return new n(r.Tools.deepClone(this._rule))}setAverage(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.average,t.operator=e,this}setUniqueValues(){const e=this._ruleConfig;return e.type=u.CFRuleType.highlightCell,e.subType=u.CFSubRuleType.uniqueValues,this}setDuplicateValues(){const e=this._ruleConfig;return e.type=u.CFRuleType.highlightCell,e.subType=u.CFSubRuleType.duplicateValues,this}setRank(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.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)===u.CFRuleType.highlightCell)if(e){this._ensureAttr(this._ruleConfig,["style","bg"]);const l=new r.ColorKit(e);this._ruleConfig.style.bg.rgb=l.toRgbString()}else delete this._ruleConfig.style.bg;return this}setBold(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===u.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.bl=e?r.BooleanNumber.TRUE:r.BooleanNumber.FALSE),this}setFontColor(e){var t;if(((t=this._ruleConfig)==null?void 0:t.type)===u.CFRuleType.highlightCell)if(e){const l=new r.ColorKit(e);this._ensureAttr(this._ruleConfig,["style","cl"]),this._ruleConfig.style.cl.rgb=l.toRgbString()}else delete this._ruleConfig.style.cl;return this}setItalic(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===u.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.it=e?r.BooleanNumber.TRUE:r.BooleanNumber.FALSE),this}setStrikethrough(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===u.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","st"]),this._ruleConfig.style.st.s=e?r.BooleanNumber.TRUE:r.BooleanNumber.FALSE),this}setUnderline(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===u.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","ul"]),this._ruleConfig.style.ul.s=e?r.BooleanNumber.TRUE:r.BooleanNumber.FALSE),this}whenCellEmpty(){const e=this._ruleConfig;return e.type=u.CFRuleType.highlightCell,e.subType=u.CFSubRuleType.text,e.value="",e.operator=u.CFTextOperator.equal,this}whenCellNotEmpty(){const e=this._ruleConfig;return e.type=u.CFRuleType.highlightCell,e.subType=u.CFSubRuleType.text,e.value="",e.operator=u.CFTextOperator.notEqual,this}whenDate(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.timePeriod,t.operator=e,this}whenFormulaSatisfied(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.formula,t.value=e,this}whenNumberBetween(e,t){const l=Math.min(e,t),s=Math.max(e,t),h=this._ruleConfig;return h.type=u.CFRuleType.highlightCell,h.subType=u.CFSubRuleType.number,h.value=[l,s],h.operator=u.CFNumberOperator.between,this}whenNumberEqualTo(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.equal,this}whenNumberGreaterThan(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.greaterThan,this}whenNumberGreaterThanOrEqualTo(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.greaterThanOrEqual,this}whenNumberLessThan(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.lessThan,this}whenNumberLessThanOrEqualTo(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.lessThanOrEqual,this}whenNumberNotBetween(e,t){const l=Math.min(e,t),s=Math.max(e,t),h=this._ruleConfig;return h.type=u.CFRuleType.highlightCell,h.subType=u.CFSubRuleType.number,h.value=[l,s],h.operator=u.CFNumberOperator.notBetween,this}whenNumberNotEqualTo(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.number,t.value=e,t.operator=u.CFNumberOperator.notEqual,this}whenTextContains(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.text,t.value=e,t.operator=u.CFTextOperator.containsText,this}whenTextDoesNotContain(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.text,t.value=e,t.operator=u.CFTextOperator.notContainsText,this}whenTextEndsWith(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.text,t.value=e,t.operator=u.CFTextOperator.endsWith,this}whenTextEqualTo(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.text,t.value=e,t.operator=u.CFTextOperator.equal,this}whenTextStartsWith(e){const t=this._ruleConfig;return t.type=u.CFRuleType.highlightCell,t.subType=u.CFSubRuleType.text,t.value=e,t.operator=u.CFTextOperator.beginsWith,this}}class a extends o{copy(){return new a(r.Tools.deepClone(this._rule))}setDataBar(e){const t=this._ruleConfig;return t.type=u.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 g extends o{copy(){return new g(r.Tools.deepClone(this._rule))}setColorScale(e){const t=this._ruleConfig;return t.type=u.CFRuleType.colorScale,t.config=e,this}}class T extends o{copy(){return new T(r.Tools.deepClone(this._rule))}setIconSet(e){const t=this._ruleConfig;return t.type=u.CFRuleType.iconSet,t.config=e.iconConfigs,t.isShowValue=e.isShowValue,this}}class C{constructor(e={}){this._initConfig=e}build(){return new o(this._initConfig).build()}setAverage(e){return new n(this._initConfig).setAverage(e)}setUniqueValues(){return new n(this._initConfig).setUniqueValues()}setDuplicateValues(){return new n(this._initConfig).setDuplicateValues()}setRank(e){return new n(this._initConfig).setRank(e)}setIconSet(e){return new T(this._initConfig).setIconSet(e)}setColorScale(e){return new g(this._initConfig).setColorScale(e)}setDataBar(e){return new a(this._initConfig).setDataBar(e)}setBackground(e){return new n(this._initConfig).setBackground(e)}setBold(e){return new n(this._initConfig).setBold(e)}setFontColor(e){return new n(this._initConfig).setFontColor(e)}setItalic(e){return new n(this._initConfig).setItalic(e)}setStrikethrough(e){return new n(this._initConfig).setStrikethrough(e)}setUnderline(e){return new n(this._initConfig).setUnderline(e)}whenCellEmpty(){return new n(this._initConfig).whenCellEmpty()}whenCellNotEmpty(){return new n(this._initConfig).whenCellNotEmpty()}whenDate(e){return new n(this._initConfig).whenDate(e)}whenFormulaSatisfied(e){return new n(this._initConfig).whenFormulaSatisfied(e)}whenNumberBetween(e,t){return new n(this._initConfig).whenNumberBetween(e,t)}whenNumberEqualTo(e){return new n(this._initConfig).whenNumberEqualTo(e)}whenNumberGreaterThan(e){return new n(this._initConfig).whenNumberGreaterThan(e)}whenNumberGreaterThanOrEqualTo(e){return new n(this._initConfig).whenNumberGreaterThanOrEqualTo(e)}whenNumberLessThan(e){return new n(this._initConfig).whenNumberLessThan(e)}whenNumberLessThanOrEqualTo(e){return new n(this._initConfig).whenNumberLessThanOrEqualTo(e)}whenNumberNotBetween(e,t){return new n(this._initConfig).whenNumberNotBetween(e,t)}whenNumberNotEqualTo(e){return new n(this._initConfig).whenNumberNotEqualTo(e)}whenTextContains(e){return new n(this._initConfig).whenTextContains(e)}whenTextDoesNotContain(e){return new n(this._initConfig).whenTextDoesNotContain(e)}whenTextEndsWith(e){return new n(this._initConfig).whenTextEndsWith(e)}whenTextEqualTo(e){return new n(this._initConfig).whenTextEqualTo(e)}whenTextStartsWith(e){return new n(this._initConfig).whenTextStartsWith(e)}}class f extends p.FRange{_getConditionalFormattingRuleModel(){return this._injector.get(u.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]].filter(t=>t.ranges.some(l=>r.Rectangle.intersects(l,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(u.AddConditionalRuleMutation.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(u.DeleteConditionalRuleMutation.id,t),this}moveConditionalFormattingRule(e,t,l="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:l}};return this._commandService.syncExecuteCommand(u.MoveConditionalRuleMutation.id,s),this}setConditionalFormattingRule(e,t){const l={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.syncExecuteCommand(u.SetConditionalRuleMutation.id,l),this}}p.FRange.extend(f);class c extends p.FWorkbook{newColor(){return new r.ColorBuilder}}p.FWorkbook.extend(c);class b extends p.FWorksheet{_getConditionalFormattingRuleModel(){return this._injector.get(u.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(u.AddConditionalRuleMutation.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(u.DeleteConditionalRuleMutation.id,t),this}moveConditionalFormattingRule(e,t,l="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:l}};return this._commandService.syncExecuteCommand(u.MoveConditionalRuleMutation.id,s),this}setConditionalFormattingRule(e,t){const l={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.syncExecuteCommand(u.SetConditionalRuleMutation.id,l),this}}p.FWorksheet.extend(b),i.FConditionalFormattingBuilder=C,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@univerjs/sheets-conditional-formatting"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-conditional-formatting","@univerjs/sheets/facade"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.UniverSheetsConditionalFormattingFacade={},l.UniverCore,l.UniverSheetsConditionalFormatting,l.UniverSheetsFacade))})(this,function(l,u,r,C){"use strict";var w=Object.defineProperty;var R=(l,u,r)=>u in l?w(l,u,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[u]=r;var _=(l,u,r)=>R(l,typeof u!="symbol"?u+"":u,r);class o{constructor(e={}){_(this,"_rule",{});this._rule=e,this._ensureAttr(this._rule,["rule"])}get _ruleConfig(){return this._rule.rule||null}_getDefaultConfig(e=r.CFRuleType.highlightCell){switch(e){case r.CFRuleType.colorScale:return{type:e,config:[{index:0,color:new u.ColorKit("").toRgbString(),value:{type:r.CFValueType.min}},{index:0,color:new u.ColorKit("green").toRgbString(),value:{type:r.CFValueType.max}}]};case r.CFRuleType.dataBar:return{type:e,isShowValue:!0,config:{min:{type:r.CFValueType.min},max:{type:r.CFValueType.max},positiveColor:new u.ColorKit("green").toRgbString(),nativeColor:new u.ColorKit("").toRgbString(),isGradient:!1}};case r.CFRuleType.highlightCell:return{type:e,subType:r.CFSubRuleType.text,operator:r.CFTextOperator.containsText,value:"abc",style:{}};case r.CFRuleType.iconSet:return{type:e,isShowValue:!0,config:[{operator:r.CFNumberOperator.greaterThanOrEqual,value:{type:r.CFValueType.min},iconType:r.EMPTY_ICON_TYPE,iconId:""},{operator:r.CFNumberOperator.greaterThanOrEqual,value:{type:r.CFValueType.percentile,value:.5},iconType:r.EMPTY_ICON_TYPE,iconId:""},{operator:r.CFNumberOperator.lessThanOrEqual,value:{type:r.CFValueType.max},iconType:r.EMPTY_ICON_TYPE,iconId:""}]}}}_ensureAttr(e,t){return t.reduce((i,s)=>(i[s]||(i[s]={}),i[s]),e),e}build(){var i;this._rule.cfId||(this._rule.cfId=r.createCfId()),this._rule.ranges||(this._rule.ranges=[]),this._rule.stopIfTrue===void 0&&(this._rule.stopIfTrue=!1),(i=this._rule.rule)!=null&&i.type||(this._rule.rule.type=r.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 o(u.Tools.deepClone(this._rule))}getRanges(){return this._rule.ranges||[]}getIconMap(){return r.iconMap}createCfId(){return r.createCfId()}setRanges(e){return this._rule.ranges=e,this}}class n extends o{constructor(e={}){super(e),this._ensureAttr(this._rule,["rule","style"])}copy(){return new n(u.Tools.deepClone(this._rule))}setAverage(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.average,t.operator=e,this}setUniqueValues(){const e=this._ruleConfig;return e.type=r.CFRuleType.highlightCell,e.subType=r.CFSubRuleType.uniqueValues,this}setDuplicateValues(){const e=this._ruleConfig;return e.type=r.CFRuleType.highlightCell,e.subType=r.CFSubRuleType.duplicateValues,this}setRank(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.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)===r.CFRuleType.highlightCell)if(e){this._ensureAttr(this._ruleConfig,["style","bg"]);const i=new u.ColorKit(e);this._ruleConfig.style.bg.rgb=i.toRgbString()}else delete this._ruleConfig.style.bg;return this}setBold(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===r.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.bl=e?u.BooleanNumber.TRUE:u.BooleanNumber.FALSE),this}setFontColor(e){var t;if(((t=this._ruleConfig)==null?void 0:t.type)===r.CFRuleType.highlightCell)if(e){const i=new u.ColorKit(e);this._ensureAttr(this._ruleConfig,["style","cl"]),this._ruleConfig.style.cl.rgb=i.toRgbString()}else delete this._ruleConfig.style.cl;return this}setItalic(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===r.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style"]),this._ruleConfig.style.it=e?u.BooleanNumber.TRUE:u.BooleanNumber.FALSE),this}setStrikethrough(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===r.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","st"]),this._ruleConfig.style.st.s=e?u.BooleanNumber.TRUE:u.BooleanNumber.FALSE),this}setUnderline(e){var t;return((t=this._ruleConfig)==null?void 0:t.type)===r.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,["style","ul"]),this._ruleConfig.style.ul.s=e?u.BooleanNumber.TRUE:u.BooleanNumber.FALSE),this}whenCellEmpty(){const e=this._ruleConfig;return e.type=r.CFRuleType.highlightCell,e.subType=r.CFSubRuleType.text,e.value="",e.operator=r.CFTextOperator.equal,this}whenCellNotEmpty(){const e=this._ruleConfig;return e.type=r.CFRuleType.highlightCell,e.subType=r.CFSubRuleType.text,e.value="",e.operator=r.CFTextOperator.notEqual,this}whenDate(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.timePeriod,t.operator=e,this}whenFormulaSatisfied(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.formula,t.value=e,this}whenNumberBetween(e,t){const i=Math.min(e,t),s=Math.max(e,t),h=this._ruleConfig;return h.type=r.CFRuleType.highlightCell,h.subType=r.CFSubRuleType.number,h.value=[i,s],h.operator=r.CFNumberOperator.between,this}whenNumberEqualTo(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.equal,this}whenNumberGreaterThan(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.greaterThan,this}whenNumberGreaterThanOrEqualTo(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.greaterThanOrEqual,this}whenNumberLessThan(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.lessThan,this}whenNumberLessThanOrEqualTo(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.lessThanOrEqual,this}whenNumberNotBetween(e,t){const i=Math.min(e,t),s=Math.max(e,t),h=this._ruleConfig;return h.type=r.CFRuleType.highlightCell,h.subType=r.CFSubRuleType.number,h.value=[i,s],h.operator=r.CFNumberOperator.notBetween,this}whenNumberNotEqualTo(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.number,t.value=e,t.operator=r.CFNumberOperator.notEqual,this}whenTextContains(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.text,t.value=e,t.operator=r.CFTextOperator.containsText,this}whenTextDoesNotContain(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.text,t.value=e,t.operator=r.CFTextOperator.notContainsText,this}whenTextEndsWith(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.text,t.value=e,t.operator=r.CFTextOperator.endsWith,this}whenTextEqualTo(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.text,t.value=e,t.operator=r.CFTextOperator.equal,this}whenTextStartsWith(e){const t=this._ruleConfig;return t.type=r.CFRuleType.highlightCell,t.subType=r.CFSubRuleType.text,t.value=e,t.operator=r.CFTextOperator.beginsWith,this}}class a extends o{copy(){return new a(u.Tools.deepClone(this._rule))}setDataBar(e){const t=this._ruleConfig;return t.type=r.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 g extends o{copy(){return new g(u.Tools.deepClone(this._rule))}setColorScale(e){const t=this._ruleConfig;return t.type=r.CFRuleType.colorScale,t.config=e,this}}class y extends o{copy(){return new y(u.Tools.deepClone(this._rule))}setIconSet(e){const t=this._ruleConfig;return t.type=r.CFRuleType.iconSet,t.config=e.iconConfigs,t.isShowValue=e.isShowValue,this}}class p{constructor(e={}){this._initConfig=e}build(){return new o(this._initConfig).build()}setAverage(e){return new n(this._initConfig).setAverage(e)}setUniqueValues(){return new n(this._initConfig).setUniqueValues()}setDuplicateValues(){return new n(this._initConfig).setDuplicateValues()}setRank(e){return new n(this._initConfig).setRank(e)}setIconSet(e){return new y(this._initConfig).setIconSet(e)}setColorScale(e){return new g(this._initConfig).setColorScale(e)}setDataBar(e){return new a(this._initConfig).setDataBar(e)}setBackground(e){return new n(this._initConfig).setBackground(e)}setBold(e){return new n(this._initConfig).setBold(e)}setFontColor(e){return new n(this._initConfig).setFontColor(e)}setItalic(e){return new n(this._initConfig).setItalic(e)}setStrikethrough(e){return new n(this._initConfig).setStrikethrough(e)}setUnderline(e){return new n(this._initConfig).setUnderline(e)}whenCellEmpty(){return new n(this._initConfig).whenCellEmpty()}whenCellNotEmpty(){return new n(this._initConfig).whenCellNotEmpty()}whenDate(e){return new n(this._initConfig).whenDate(e)}whenFormulaSatisfied(e){return new n(this._initConfig).whenFormulaSatisfied(e)}whenNumberBetween(e,t){return new n(this._initConfig).whenNumberBetween(e,t)}whenNumberEqualTo(e){return new n(this._initConfig).whenNumberEqualTo(e)}whenNumberGreaterThan(e){return new n(this._initConfig).whenNumberGreaterThan(e)}whenNumberGreaterThanOrEqualTo(e){return new n(this._initConfig).whenNumberGreaterThanOrEqualTo(e)}whenNumberLessThan(e){return new n(this._initConfig).whenNumberLessThan(e)}whenNumberLessThanOrEqualTo(e){return new n(this._initConfig).whenNumberLessThanOrEqualTo(e)}whenNumberNotBetween(e,t){return new n(this._initConfig).whenNumberNotBetween(e,t)}whenNumberNotEqualTo(e){return new n(this._initConfig).whenNumberNotEqualTo(e)}whenTextContains(e){return new n(this._initConfig).whenTextContains(e)}whenTextDoesNotContain(e){return new n(this._initConfig).whenTextDoesNotContain(e)}whenTextEndsWith(e){return new n(this._initConfig).whenTextEndsWith(e)}whenTextEqualTo(e){return new n(this._initConfig).whenTextEqualTo(e)}whenTextStartsWith(e){return new n(this._initConfig).whenTextStartsWith(e)}}class f extends C.FRange{_getConditionalFormattingRuleModel(){return this._injector.get(r.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]].filter(t=>t.ranges.some(i=>u.Rectangle.intersects(i,this._range)))}createConditionalFormattingRule(){return new p({ranges:[this._range]})}addConditionalFormattingRule(e){const t={rule:e,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.syncExecuteCommand(r.AddConditionalRuleMutation.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(r.DeleteConditionalRuleMutation.id,t),this}moveConditionalFormattingRule(e,t,i="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:i}};return this._commandService.syncExecuteCommand(r.MoveConditionalRuleMutation.id,s),this}setConditionalFormattingRule(e,t){const i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.syncExecuteCommand(r.SetConditionalRuleMutation.id,i),this}clearConditionalFormatRules(){const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]};return this._commandService.syncExecuteCommand(r.ClearRangeCfCommand.id,e),this}}C.FRange.extend(f);class c extends C.FWorkbook{newColor(){return new u.ColorBuilder}}C.FWorkbook.extend(c);class b extends C.FWorksheet{_getConditionalFormattingRuleModel(){return this._injector.get(r.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]]}createConditionalFormattingRule(){return new p}newConditionalFormattingRule(){return new p}addConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:e};return this._commandService.syncExecuteCommand(r.AddCfCommand.id,t),this}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(r.DeleteCfCommand.id,t),this}moveConditionalFormattingRule(e,t,i="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:i}};return this._commandService.syncExecuteCommand(r.MoveCfCommand.id,s),this}setConditionalFormattingRule(e,t){const i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e,rule:t};return this._commandService.syncExecuteCommand(r.SetCfCommand.id,i),this}clearConditionalFormatRules(){const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.syncExecuteCommand(r.ClearWorksheetCfCommand.id,e),this}}C.FWorksheet.extend(b),l.FConditionalFormattingBuilder=p,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});