@univerjs/sheets-conditional-formatting 0.5.1 → 0.5.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.
@@ -0,0 +1,116 @@
1
+ import { IAnchor, IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
2
+ import { FWorksheet } from '@univerjs/sheets/facade';
3
+ import { FConditionalFormattingBuilder } from './conditional-formatting-builder';
4
+ export interface IFWorksheetConditionalFormattingMixin {
5
+ /**
6
+ * Gets all the conditional formatting for the current sheet
7
+ * @return {*} {IConditionFormattingRule[]}
8
+ * @memberof IFWorksheetConditionalFormattingMixin
9
+ * @example
10
+ * ```ts
11
+ * univerAPI.getActiveWorkbook()?.getActiveSheet().getConditionalFormattingRules();
12
+ * ```
13
+ */
14
+ getConditionalFormattingRules(): IConditionFormattingRule[];
15
+ /**
16
+ * Creates a constructor for conditional formatting
17
+ * @return {*} {ConditionalFormatRuleBuilder}
18
+ * @memberof IFWorksheetConditionalFormattingMixin
19
+ * @example
20
+ * ```ts
21
+ * const workbook = univerAPI.getActiveWorkbook();
22
+ * const worksheet = workbook?.getActiveSheet();
23
+ * const rule = worksheet?.createConditionalFormattingRule()
24
+ * .whenCellNotEmpty()
25
+ * .setRanges([{ startRow: 0, endRow: 100, startColumn: 0, endColumn: 100 }])
26
+ * .setItalic(true)
27
+ * .setItalic(true)
28
+ * .setBackground('red')
29
+ * .setFontColor('green')
30
+ * .build();
31
+ * ```
32
+ */
33
+ createConditionalFormattingRule(): FConditionalFormattingBuilder;
34
+ /**
35
+ * Add a new conditional format
36
+ * @param {IConditionFormattingRule} rule
37
+ * @return {*} {Promise<boolean>}
38
+ * @memberof IFWorksheetConditionalFormattingMixin
39
+ * @example
40
+ * ```ts
41
+ * const workbook = univerAPI.getActiveWorkbook();
42
+ * const worksheet = workbook?.getActiveSheet();
43
+ * const rule = worksheet?.createConditionalFormattingRule()
44
+ * .whenCellNotEmpty()
45
+ * .setRanges([{ startRow: 0, endRow: 100, startColumn: 0, endColumn: 100 }])
46
+ * .setItalic(true)
47
+ * .setItalic(true)
48
+ * .setBackground('red')
49
+ * .setFontColor('green')
50
+ * .build();
51
+ * worksheet?.addConditionalFormattingRule(rule!);
52
+ * ```
53
+ */
54
+ addConditionalFormattingRule(rule: IConditionFormattingRule): Promise<boolean>;
55
+ /**
56
+ * Delete conditional format according to `cfId`
57
+ *
58
+ * @param {string} cfId
59
+ * @return {*} {Promise<boolean>}
60
+ * @memberof IFWorksheetConditionalFormattingMixin
61
+ * @example
62
+ * ```ts
63
+ * const workbook = univerAPI.getActiveWorkbook();
64
+ * const worksheet = workbook?.getActiveSheet();
65
+ * const rules = worksheet?.getConditionalFormattingRules();
66
+ * worksheet?.deleteConditionalFormattingRule(rules![0].cfId);
67
+ * ```
68
+ */
69
+ deleteConditionalFormattingRule(cfId: string): Promise<boolean>;
70
+ /**
71
+ * Modify the priority of the conditional format
72
+ * @param {string} cfId Rules that need to be moved
73
+ * @param {string} toCfId Target rule
74
+ * @param {IAnchor['type']} [type] After the default move to the destination rule, if type = before moves to the front, the default value is after
75
+ * @memberof FWorksheetConditionalFormattingMixin
76
+ * @example
77
+ * ```ts
78
+ * const workbook = univerAPI.getActiveWorkbook();
79
+ * const worksheet = workbook?.getActiveSheet();
80
+ * const rules = worksheet?.getConditionalFormattingRules()!;
81
+ * const rule = rules[2];
82
+ * const targetRule = rules[0];
83
+ * worksheet?.moveConditionalFormattingRule(rule.cfId, targetRule.cfId, 'before');
84
+ * ```
85
+ */
86
+ moveConditionalFormattingRule(cfId: string, toCfId: string, type?: IAnchor['type']): Promise<boolean>;
87
+ /**
88
+ * Set the conditional format according to `cfId`
89
+ * @param {string} cfId
90
+ * @param {IConditionFormattingRule} rule
91
+ * @return {*} {Promise<boolean>}
92
+ * @memberof IFWorksheetConditionalFormattingMixin
93
+ * @example
94
+ * ```ts
95
+ * const workbook = univerAPI.getActiveWorkbook();
96
+ * const worksheet = workbook?.getActiveSheet();
97
+ * const rules = worksheet?.getConditionalFormattingRules()!;
98
+ * const rule = rules[0];
99
+ * worksheet?.setConditionalFormattingRule(rule.cfId, { ...rule, ranges: [] });
100
+ * ```
101
+ */
102
+ setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): Promise<boolean>;
103
+ }
104
+ export declare class FWorksheetConditionalFormattingMixin extends FWorksheet implements IFWorksheetConditionalFormattingMixin {
105
+ private _getConditionalFormattingRuleModel;
106
+ getConditionalFormattingRules(): IConditionFormattingRule[];
107
+ createConditionalFormattingRule(): FConditionalFormattingBuilder;
108
+ addConditionalFormattingRule(rule: IConditionFormattingRule): Promise<boolean>;
109
+ deleteConditionalFormattingRule(cfId: string): Promise<boolean>;
110
+ moveConditionalFormattingRule(cfId: string, toCfId: string, type?: IAnchor['type']): Promise<boolean>;
111
+ setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): Promise<boolean>;
112
+ }
113
+ declare module '@univerjs/sheets/facade' {
114
+ interface FWorksheet extends IFWorksheetConditionalFormattingMixin {
115
+ }
116
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import './f-range';
17
+ import './f-workbook';
18
+ import './f-worksheet';
19
+ export { FConditionalFormattingBuilder } from './conditional-formatting-builder';
20
+ export type { IFRangeConditionalFormattingMixin } from './f-range';
21
+ export type { FWorkbookConditionalFormattingMixin } from './f-workbook';
22
+ export type { IFWorksheetConditionalFormattingMixin } from './f-worksheet';
@@ -0,0 +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 c=Object.defineProperty;var R=(i,r,u)=>r in i?c(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((n,s)=>(n[s]||(n[s]={}),n[s]),e),e}build(){var n;this._rule.cfId||(this._rule.cfId=u.createCfId()),this._rule.ranges||(this._rule.ranges=[]),this._rule.stopIfTrue===void 0&&(this._rule.stopIfTrue=!1),(n=this._rule.rule)!=null&&n.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 l extends o{constructor(e={}){super(e),this._ensureAttr(this._rule,["rule","style"])}copy(){return new l(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 n=new r.ColorKit(e);this._ruleConfig.style.bg.rgb=n.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 n=new r.ColorKit(e);this._ensureAttr(this._ruleConfig,["style","cl"]),this._ruleConfig.style.cl.rgb=n.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 n=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=[n,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 n=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=[n,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 C extends o{copy(){return new C(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 a extends o{copy(){return new a(r.Tools.deepClone(this._rule))}setColorScale(e){const t=this._ruleConfig;return t.type=u.CFRuleType.colorScale,t.config=e,this}}class g extends o{copy(){return new g(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 T{constructor(e={}){this._initConfig=e}build(){return new o(this._initConfig).build()}setAverage(e){return new l(this._initConfig).setAverage(e)}setUniqueValues(){return new l(this._initConfig).setUniqueValues()}setDuplicateValues(){return new l(this._initConfig).setDuplicateValues()}setRank(e){return new l(this._initConfig).setRank(e)}setIconSet(e){return new g(this._initConfig).setIconSet(e)}setColorScale(e){return new a(this._initConfig).setColorScale(e)}setDataBar(e){return new C(this._initConfig).setDataBar(e)}setBackground(e){return new l(this._initConfig).setBackground(e)}setBold(e){return new l(this._initConfig).setBold(e)}setFontColor(e){return new l(this._initConfig).setFontColor(e)}setItalic(e){return new l(this._initConfig).setItalic(e)}setStrikethrough(e){return new l(this._initConfig).setStrikethrough(e)}setUnderline(e){return new l(this._initConfig).setUnderline(e)}whenCellEmpty(){return new l(this._initConfig).whenCellEmpty()}whenCellNotEmpty(){return new l(this._initConfig).whenCellNotEmpty()}whenDate(e){return new l(this._initConfig).whenDate(e)}whenFormulaSatisfied(e){return new l(this._initConfig).whenFormulaSatisfied(e)}whenNumberBetween(e,t){return new l(this._initConfig).whenNumberBetween(e,t)}whenNumberEqualTo(e){return new l(this._initConfig).whenNumberEqualTo(e)}whenNumberGreaterThan(e){return new l(this._initConfig).whenNumberGreaterThan(e)}whenNumberGreaterThanOrEqualTo(e){return new l(this._initConfig).whenNumberGreaterThanOrEqualTo(e)}whenNumberLessThan(e){return new l(this._initConfig).whenNumberLessThan(e)}whenNumberLessThanOrEqualTo(e){return new l(this._initConfig).whenNumberLessThanOrEqualTo(e)}whenNumberNotBetween(e,t){return new l(this._initConfig).whenNumberNotBetween(e,t)}whenNumberNotEqualTo(e){return new l(this._initConfig).whenNumberNotEqualTo(e)}whenTextContains(e){return new l(this._initConfig).whenTextContains(e)}whenTextDoesNotContain(e){return new l(this._initConfig).whenTextDoesNotContain(e)}whenTextEndsWith(e){return new l(this._initConfig).whenTextEndsWith(e)}whenTextEqualTo(e){return new l(this._initConfig).whenTextEqualTo(e)}whenTextStartsWith(e){return new l(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(n=>r.Rectangle.intersects(n,this._range)))}createConditionalFormattingRule(){return new T({ranges:[this._range]})}addConditionalFormattingRule(e){const t={rule:e,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.executeCommand(u.AddConditionalRuleMutation.id,t)}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.executeCommand(u.DeleteConditionalRuleMutation.id,t)}moveConditionalFormattingRule(e,t,n="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:n}};return this._commandService.executeCommand(u.MoveConditionalRuleMutation.id,s)}setConditionalFormattingRule(e,t){const n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.executeCommand(u.SetConditionalRuleMutation.id,n)}}p.FRange.extend(f);class b extends p.FWorkbook{newColor(){return new r.ColorBuilder}}p.FWorkbook.extend(b);class w extends p.FWorksheet{_getConditionalFormattingRuleModel(){return this._injector.get(u.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]]}createConditionalFormattingRule(){return new T}addConditionalFormattingRule(e){const t={rule:e,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.executeCommand(u.AddConditionalRuleMutation.id,t)}deleteConditionalFormattingRule(e){const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.executeCommand(u.DeleteConditionalRuleMutation.id,t)}moveConditionalFormattingRule(e,t,n="after"){const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:"self"},end:{id:t,type:n}};return this._commandService.executeCommand(u.MoveConditionalRuleMutation.id,s)}setConditionalFormattingRule(e,t){const n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:t,cfId:e};return this._commandService.executeCommand(u.SetConditionalRuleMutation.id,n)}}p.FWorksheet.extend(w),i.FConditionalFormattingBuilder=T,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});