@univerjs/sheets-conditional-formatting 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.0

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.
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  | Package | UMD global | CSS | Locales | Facade entry |
12
12
  | --- | --- | :---: | :---: | :---: |
13
- | `@univerjs/sheets-conditional-formatting` | `UniverSheetsConditionalFormatting` | No | No | Yes |
13
+ | `@univerjs/sheets-conditional-formatting` | `UniverSheetsConditionalFormatting` | No | Yes | Yes |
14
14
 
15
15
  ## Installation
16
16
 
@@ -25,7 +25,16 @@ Keep all `@univerjs/*` packages on the same version.
25
25
  ## Usage
26
26
 
27
27
  ```ts
28
+ import { LocaleType, mergeLocales, Univer } from '@univerjs/core';
28
29
  import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
30
+ import EnUS from '@univerjs/sheets-conditional-formatting/locale/en-US';
31
+
32
+ const univer = new Univer({
33
+ locale: LocaleType.EN_US,
34
+ locales: {
35
+ [LocaleType.EN_US]: mergeLocales(EnUS),
36
+ },
37
+ });
29
38
 
30
39
  univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);
31
40
  ```
@@ -39,4 +48,3 @@ Use this package with `@univerjs/sheets-conditional-formatting-ui` when users ne
39
48
  - [Documentation](https://docs.univer.ai)
40
49
  - [NPM package](https://npmjs.com/package/@univerjs/sheets-conditional-formatting)
41
50
  - [GitHub repository](https://github.com/dream-num/univer)
42
-
package/lib/cjs/index.js CHANGED
@@ -1203,15 +1203,21 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
1203
1203
  super(..._args);
1204
1204
  _defineProperty(this, "_paddingRightAndLeft", 2);
1205
1205
  _defineProperty(this, "_paddingTopAndBottom", 2);
1206
+ _defineProperty(this, "_renderRangeResolver", null);
1206
1207
  _defineProperty(this, "uKey", dataBarUKey);
1207
1208
  _defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
1208
1209
  _defineProperty(this, "_radius", 1);
1209
1210
  }
1211
+ setRenderRangeResolver(resolver) {
1212
+ this._renderRangeResolver = resolver;
1213
+ }
1210
1214
  draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
1211
1215
  const { worksheet } = spreadsheetSkeleton;
1212
1216
  if (!worksheet) return false;
1213
1217
  const mergeCellRendered = /* @__PURE__ */ new Set();
1214
- const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
1218
+ const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
1219
+ const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
1220
+ if (!renderRanges.length) return;
1215
1221
  ctx.save();
1216
1222
  renderRanges.forEach((range) => {
1217
1223
  _univerjs_core.Range.foreach(range, (row, col) => {
@@ -1266,6 +1272,10 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
1266
1272
  });
1267
1273
  ctx.restore();
1268
1274
  }
1275
+ dispose() {
1276
+ this._renderRangeResolver = null;
1277
+ super.dispose();
1278
+ }
1269
1279
  _drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
1270
1280
  const radius = this._radius;
1271
1281
  if (!height || !width) return;
@@ -1629,7 +1639,7 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
1629
1639
  case "timePeriod": {
1630
1640
  const value = getCellValue(cellValue);
1631
1641
  if (isNullable(value) || Number.isNaN(Number(value)) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.NUMBER || !preComputingResult) return;
1632
- const v = serialTimeToTimestamp(Number(value));
1642
+ const v = serialTimeToTimestamp(Number(value), context.workbook.getDateSystem());
1633
1643
  const { start, end } = preComputingResult.value;
1634
1644
  return v >= start && v <= end;
1635
1645
  }
@@ -1800,7 +1810,9 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
1800
1810
  _defineProperty(this, "_calculateUnitManagers", /* @__PURE__ */ new Map());
1801
1811
  _defineProperty(this, "_cellCache", new _univerjs_core.LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
1802
1812
  _defineProperty(this, "_markDirty$", new rxjs.Subject());
1813
+ _defineProperty(this, "_cacheClear$", new rxjs.Subject());
1803
1814
  _defineProperty(this, "markDirty$", this._markDirty$.asObservable());
1815
+ _defineProperty(this, "cacheClear$", this._cacheClear$.asObservable());
1804
1816
  _defineProperty(this, "_markRuleDirtyAtOnce", (unitId, subUnitId, cfId, isNeedResetPreComputingCache = true) => {
1805
1817
  this._cellCache.clear();
1806
1818
  if (isNeedResetPreComputingCache) {
@@ -1886,6 +1898,7 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
1886
1898
  clearCache() {
1887
1899
  this._calculateUnitManagers.clear();
1888
1900
  this._cellCache.clear();
1901
+ this._cacheClear$.next();
1889
1902
  }
1890
1903
  _handleCustomFormulasSeparately() {
1891
1904
  this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe((e) => {
@@ -1999,54 +2012,10 @@ const getCellValue = (cell) => {
1999
2012
  const dataStream = (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.replace(/\r\n$/, "");
2000
2013
  return !isNullable(v) ? v : !isNullable(dataStream) ? dataStream : null;
2001
2014
  };
2002
- const DAY_SIZE = 86400;
2003
- function toYMD_1900(ord, leap1900 = true) {
2004
- if (leap1900 && ord >= 0) {
2005
- if (ord === 0) return [
2006
- 1900,
2007
- 1,
2008
- 0
2009
- ];
2010
- if (ord === 60) return [
2011
- 1900,
2012
- 2,
2013
- 29
2014
- ];
2015
- if (ord < 60) return [
2016
- 1900,
2017
- ord < 32 ? 1 : 2,
2018
- (ord - 1) % 31 + 1
2019
- ];
2020
- }
2021
- let l = ord + 68569 + 2415019;
2022
- const n = Math.floor(4 * l / 146097);
2023
- l = l - Math.floor((146097 * n + 3) / 4);
2024
- const i = Math.floor(4e3 * (l + 1) / 1461001);
2025
- l = l - Math.floor(1461 * i / 4) + 31;
2026
- const j = Math.floor(80 * l / 2447);
2027
- const nDay = l - Math.floor(2447 * j / 80);
2028
- l = Math.floor(j / 11);
2029
- const nMonth = j + 2 - 12 * l;
2030
- return [
2031
- 100 * (n - 49) + i + l | 0,
2032
- nMonth | 0,
2033
- nDay | 0
2034
- ];
2035
- }
2036
- const serialTimeToTimestamp = (value) => {
2037
- let date = value | 0;
2038
- const t = DAY_SIZE * (value - date);
2039
- let time = Math.floor(t);
2040
- if (t - time > .9999) {
2041
- time += 1;
2042
- if (time === DAY_SIZE) {
2043
- time = 0;
2044
- date += 1;
2045
- }
2046
- }
2047
- const x = time < 0 ? DAY_SIZE + time : time;
2048
- const [y, m, d] = toYMD_1900(value, true);
2049
- return (0, _univerjs_core.dateKit)(`${y}/${m}/${d} ${Math.floor(x / 60 / 60) % 60}:${Math.floor(x / 60) % 60}:${Math.floor(x) % 60}`).valueOf();
2015
+ const serialTimeToTimestamp = (value, dateSystem = _univerjs_core.DateSystem.Date1900) => {
2016
+ const utcDate = (0, _univerjs_core.excelSerialToDateTime)(value, dateSystem);
2017
+ if (Number.isNaN(utcDate.getTime())) return NaN;
2018
+ return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), utcDate.getUTCHours(), utcDate.getUTCMinutes(), utcDate.getUTCSeconds(), utcDate.getUTCMilliseconds()).getTime();
2050
2019
  };
2051
2020
  const getValueByType = (value, matrix, context) => {
2052
2021
  switch (value.type) {
@@ -2543,7 +2512,7 @@ for (const key in iconMap) {
2543
2512
  //#endregion
2544
2513
  //#region package.json
2545
2514
  var name = "@univerjs/sheets-conditional-formatting";
2546
- var version = "1.0.0-insiders.20260809-70eefdd";
2515
+ var version = "1.0.0-rc.0";
2547
2516
 
2548
2517
  //#endregion
2549
2518
  //#region src/config/config.ts
@@ -2568,14 +2537,28 @@ const defaultPluginConfig = {};
2568
2537
 
2569
2538
  //#endregion
2570
2539
  //#region src/services/conditional-formatting-style-composer.service.ts
2571
- let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer {
2540
+ let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer extends _univerjs_core.Disposable {
2572
2541
  constructor(_conditionalFormattingRuleModel, _conditionalFormattingViewModel) {
2542
+ super();
2573
2543
  this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel;
2574
2544
  this._conditionalFormattingViewModel = _conditionalFormattingViewModel;
2545
+ _defineProperty(this, "_cache", new _univerjs_core.LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
2546
+ this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe(() => this._cache.clear()));
2547
+ this.disposeWithMe(this._conditionalFormattingViewModel.markDirty$.subscribe(() => this._cache.clear()));
2548
+ this.disposeWithMe(this._conditionalFormattingViewModel.cacheClear$.subscribe(() => this._cache.clear()));
2549
+ }
2550
+ dispose() {
2551
+ this._cache.clear();
2552
+ super.dispose();
2575
2553
  }
2576
2554
  composeStyle(unitId, subUnitId, row, col) {
2555
+ const cacheKey = `${unitId}_${subUnitId}_${row}_${col}`;
2556
+ if (this._cache.has(cacheKey)) return this._cache.get(cacheKey) ?? null;
2577
2557
  const cellCfs = this._conditionalFormattingViewModel.getCellCfs(unitId, subUnitId, row, col);
2578
- if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length)) return null;
2558
+ if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length)) {
2559
+ this._cache.set(cacheKey, null);
2560
+ return null;
2561
+ }
2579
2562
  const matchedRules = [];
2580
2563
  let stopIfTrueIndex = -1;
2581
2564
  for (const cacheItem of cellCfs) {
@@ -2587,13 +2570,17 @@ let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleCompose
2587
2570
  });
2588
2571
  if (stopIfTrueIndex === -1 && rule.stopIfTrue && this._isRuleMatched(rule, cacheItem.result)) stopIfTrueIndex = matchedRules.length - 1;
2589
2572
  }
2590
- if (!matchedRules.length) return null;
2573
+ if (!matchedRules.length) {
2574
+ this._cache.set(cacheKey, null);
2575
+ return null;
2576
+ }
2591
2577
  const effectiveRules = stopIfTrueIndex > -1 ? matchedRules.slice(0, stopIfTrueIndex + 1) : matchedRules;
2592
2578
  const result = {};
2593
2579
  for (let i = effectiveRules.length - 1; i >= 0; i--) {
2594
2580
  const { rule, cacheItem } = effectiveRules[i];
2595
2581
  this._mergeComposeResult(result, rule, cacheItem.result);
2596
2582
  }
2583
+ this._cache.set(cacheKey, result);
2597
2584
  return result;
2598
2585
  }
2599
2586
  _mergeComposeResult(result, rule, ruleResult) {
@@ -2957,16 +2944,22 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
2957
2944
  _defineProperty(this, "_paddingRightAndLeft", 2);
2958
2945
  _defineProperty(this, "_width", 15);
2959
2946
  _defineProperty(this, "_imageMap", /* @__PURE__ */ new Map());
2947
+ _defineProperty(this, "_renderRangeResolver", null);
2960
2948
  _defineProperty(this, "uKey", IconUKey);
2961
2949
  _defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX);
2962
2950
  _defineProperty(this, "_radius", 1);
2963
2951
  this._init();
2964
2952
  }
2953
+ setRenderRangeResolver(resolver) {
2954
+ this._renderRangeResolver = resolver;
2955
+ }
2965
2956
  draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
2966
2957
  const { worksheet } = spreadsheetSkeleton;
2967
2958
  if (!worksheet) return false;
2968
2959
  const mergeCellRendered = /* @__PURE__ */ new Set();
2969
- const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
2960
+ const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
2961
+ const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
2962
+ if (!renderRanges.length) return;
2970
2963
  ctx.save();
2971
2964
  renderRanges.forEach((range) => {
2972
2965
  _univerjs_core.Range.foreach(range, (row, col) => {
@@ -2996,6 +2989,10 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
2996
2989
  });
2997
2990
  ctx.restore();
2998
2991
  }
2992
+ dispose() {
2993
+ this._renderRangeResolver = null;
2994
+ super.dispose();
2995
+ }
2999
2996
  _init() {
3000
2997
  for (const type in iconMap) iconMap[type].forEach((base64, index) => {
3001
2998
  const key = this._createKey(type, String(index));
@@ -3134,5 +3131,4 @@ exports.moveByAnchor = moveByAnchor;
3134
3131
  exports.removeUndefinedAttr = removeUndefinedAttr;
3135
3132
  exports.serialTimeToTimestamp = serialTimeToTimestamp;
3136
3133
  exports.setConditionalRuleMutationUndoFactory = setConditionalRuleMutationUndoFactory;
3137
- exports.toYMD_1900 = toYMD_1900;
3138
3134
  exports.transformSupportSymmetryAnchor = transformSupportSymmetryAnchor;
package/lib/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BooleanNumber, CellValueType, ColorKit, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LRUMap, ObjectMatrix, Plugin, RTree, Range, Rectangle, RefAlias, Tools, UniverInstanceType, dateKit, generateRandomId, getIntersectRange, isInternalEditorID, merge, sequenceExecute, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, CellValueType, ColorKit, CommandType, DateSystem, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LRUMap, ObjectMatrix, Plugin, RTree, Range, Rectangle, RefAlias, Tools, UniverInstanceType, dateKit, excelSerialToDateTime, generateRandomId, getIntersectRange, isInternalEditorID, merge, sequenceExecute, touchDependencies } from "@univerjs/core";
2
2
  import { CopySheetCommand, InsertColMutation, InsertRowMutation, MoveColsMutation, MoveRangeMutation, MoveRowsMutation, RemoveColMutation, RemoveRowMutation, RemoveSheetCommand, ReorderRangeMutation, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, getSheetCommandTarget } from "@univerjs/sheets";
3
3
  import { BehaviorSubject, Subject } from "rxjs";
4
4
  import { BooleanValue, ERROR_TYPE_SET, FormulaResultStatus, OtherFormulaBizType, RegisterOtherFormulaService, UniverFormulaEnginePlugin } from "@univerjs/engine-formula";
@@ -1202,15 +1202,21 @@ var DataBar = class extends SheetExtension {
1202
1202
  super(..._args);
1203
1203
  _defineProperty(this, "_paddingRightAndLeft", 2);
1204
1204
  _defineProperty(this, "_paddingTopAndBottom", 2);
1205
+ _defineProperty(this, "_renderRangeResolver", null);
1205
1206
  _defineProperty(this, "uKey", dataBarUKey);
1206
1207
  _defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
1207
1208
  _defineProperty(this, "_radius", 1);
1208
1209
  }
1210
+ setRenderRangeResolver(resolver) {
1211
+ this._renderRangeResolver = resolver;
1212
+ }
1209
1213
  draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
1210
1214
  const { worksheet } = spreadsheetSkeleton;
1211
1215
  if (!worksheet) return false;
1212
1216
  const mergeCellRendered = /* @__PURE__ */ new Set();
1213
- const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
1217
+ const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
1218
+ const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
1219
+ if (!renderRanges.length) return;
1214
1220
  ctx.save();
1215
1221
  renderRanges.forEach((range) => {
1216
1222
  Range.foreach(range, (row, col) => {
@@ -1265,6 +1271,10 @@ var DataBar = class extends SheetExtension {
1265
1271
  });
1266
1272
  ctx.restore();
1267
1273
  }
1274
+ dispose() {
1275
+ this._renderRangeResolver = null;
1276
+ super.dispose();
1277
+ }
1268
1278
  _drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
1269
1279
  const radius = this._radius;
1270
1280
  if (!height || !width) return;
@@ -1628,7 +1638,7 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
1628
1638
  case "timePeriod": {
1629
1639
  const value = getCellValue(cellValue);
1630
1640
  if (isNullable(value) || Number.isNaN(Number(value)) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== CellValueType.NUMBER || !preComputingResult) return;
1631
- const v = serialTimeToTimestamp(Number(value));
1641
+ const v = serialTimeToTimestamp(Number(value), context.workbook.getDateSystem());
1632
1642
  const { start, end } = preComputingResult.value;
1633
1643
  return v >= start && v <= end;
1634
1644
  }
@@ -1799,7 +1809,9 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
1799
1809
  _defineProperty(this, "_calculateUnitManagers", /* @__PURE__ */ new Map());
1800
1810
  _defineProperty(this, "_cellCache", new LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
1801
1811
  _defineProperty(this, "_markDirty$", new Subject());
1812
+ _defineProperty(this, "_cacheClear$", new Subject());
1802
1813
  _defineProperty(this, "markDirty$", this._markDirty$.asObservable());
1814
+ _defineProperty(this, "cacheClear$", this._cacheClear$.asObservable());
1803
1815
  _defineProperty(this, "_markRuleDirtyAtOnce", (unitId, subUnitId, cfId, isNeedResetPreComputingCache = true) => {
1804
1816
  this._cellCache.clear();
1805
1817
  if (isNeedResetPreComputingCache) {
@@ -1885,6 +1897,7 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
1885
1897
  clearCache() {
1886
1898
  this._calculateUnitManagers.clear();
1887
1899
  this._cellCache.clear();
1900
+ this._cacheClear$.next();
1888
1901
  }
1889
1902
  _handleCustomFormulasSeparately() {
1890
1903
  this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe((e) => {
@@ -1998,54 +2011,10 @@ const getCellValue = (cell) => {
1998
2011
  const dataStream = (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.replace(/\r\n$/, "");
1999
2012
  return !isNullable(v) ? v : !isNullable(dataStream) ? dataStream : null;
2000
2013
  };
2001
- const DAY_SIZE = 86400;
2002
- function toYMD_1900(ord, leap1900 = true) {
2003
- if (leap1900 && ord >= 0) {
2004
- if (ord === 0) return [
2005
- 1900,
2006
- 1,
2007
- 0
2008
- ];
2009
- if (ord === 60) return [
2010
- 1900,
2011
- 2,
2012
- 29
2013
- ];
2014
- if (ord < 60) return [
2015
- 1900,
2016
- ord < 32 ? 1 : 2,
2017
- (ord - 1) % 31 + 1
2018
- ];
2019
- }
2020
- let l = ord + 68569 + 2415019;
2021
- const n = Math.floor(4 * l / 146097);
2022
- l = l - Math.floor((146097 * n + 3) / 4);
2023
- const i = Math.floor(4e3 * (l + 1) / 1461001);
2024
- l = l - Math.floor(1461 * i / 4) + 31;
2025
- const j = Math.floor(80 * l / 2447);
2026
- const nDay = l - Math.floor(2447 * j / 80);
2027
- l = Math.floor(j / 11);
2028
- const nMonth = j + 2 - 12 * l;
2029
- return [
2030
- 100 * (n - 49) + i + l | 0,
2031
- nMonth | 0,
2032
- nDay | 0
2033
- ];
2034
- }
2035
- const serialTimeToTimestamp = (value) => {
2036
- let date = value | 0;
2037
- const t = DAY_SIZE * (value - date);
2038
- let time = Math.floor(t);
2039
- if (t - time > .9999) {
2040
- time += 1;
2041
- if (time === DAY_SIZE) {
2042
- time = 0;
2043
- date += 1;
2044
- }
2045
- }
2046
- const x = time < 0 ? DAY_SIZE + time : time;
2047
- const [y, m, d] = toYMD_1900(value, true);
2048
- return dateKit(`${y}/${m}/${d} ${Math.floor(x / 60 / 60) % 60}:${Math.floor(x / 60) % 60}:${Math.floor(x) % 60}`).valueOf();
2014
+ const serialTimeToTimestamp = (value, dateSystem = DateSystem.Date1900) => {
2015
+ const utcDate = excelSerialToDateTime(value, dateSystem);
2016
+ if (Number.isNaN(utcDate.getTime())) return NaN;
2017
+ return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), utcDate.getUTCHours(), utcDate.getUTCMinutes(), utcDate.getUTCSeconds(), utcDate.getUTCMilliseconds()).getTime();
2049
2018
  };
2050
2019
  const getValueByType = (value, matrix, context) => {
2051
2020
  switch (value.type) {
@@ -2542,7 +2511,7 @@ for (const key in iconMap) {
2542
2511
  //#endregion
2543
2512
  //#region package.json
2544
2513
  var name = "@univerjs/sheets-conditional-formatting";
2545
- var version = "1.0.0-insiders.20260809-70eefdd";
2514
+ var version = "1.0.0-rc.0";
2546
2515
 
2547
2516
  //#endregion
2548
2517
  //#region src/config/config.ts
@@ -2567,14 +2536,28 @@ const defaultPluginConfig = {};
2567
2536
 
2568
2537
  //#endregion
2569
2538
  //#region src/services/conditional-formatting-style-composer.service.ts
2570
- let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer {
2539
+ let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer extends Disposable {
2571
2540
  constructor(_conditionalFormattingRuleModel, _conditionalFormattingViewModel) {
2541
+ super();
2572
2542
  this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel;
2573
2543
  this._conditionalFormattingViewModel = _conditionalFormattingViewModel;
2544
+ _defineProperty(this, "_cache", new LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
2545
+ this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe(() => this._cache.clear()));
2546
+ this.disposeWithMe(this._conditionalFormattingViewModel.markDirty$.subscribe(() => this._cache.clear()));
2547
+ this.disposeWithMe(this._conditionalFormattingViewModel.cacheClear$.subscribe(() => this._cache.clear()));
2548
+ }
2549
+ dispose() {
2550
+ this._cache.clear();
2551
+ super.dispose();
2574
2552
  }
2575
2553
  composeStyle(unitId, subUnitId, row, col) {
2554
+ const cacheKey = `${unitId}_${subUnitId}_${row}_${col}`;
2555
+ if (this._cache.has(cacheKey)) return this._cache.get(cacheKey) ?? null;
2576
2556
  const cellCfs = this._conditionalFormattingViewModel.getCellCfs(unitId, subUnitId, row, col);
2577
- if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length)) return null;
2557
+ if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length)) {
2558
+ this._cache.set(cacheKey, null);
2559
+ return null;
2560
+ }
2578
2561
  const matchedRules = [];
2579
2562
  let stopIfTrueIndex = -1;
2580
2563
  for (const cacheItem of cellCfs) {
@@ -2586,13 +2569,17 @@ let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleCompose
2586
2569
  });
2587
2570
  if (stopIfTrueIndex === -1 && rule.stopIfTrue && this._isRuleMatched(rule, cacheItem.result)) stopIfTrueIndex = matchedRules.length - 1;
2588
2571
  }
2589
- if (!matchedRules.length) return null;
2572
+ if (!matchedRules.length) {
2573
+ this._cache.set(cacheKey, null);
2574
+ return null;
2575
+ }
2590
2576
  const effectiveRules = stopIfTrueIndex > -1 ? matchedRules.slice(0, stopIfTrueIndex + 1) : matchedRules;
2591
2577
  const result = {};
2592
2578
  for (let i = effectiveRules.length - 1; i >= 0; i--) {
2593
2579
  const { rule, cacheItem } = effectiveRules[i];
2594
2580
  this._mergeComposeResult(result, rule, cacheItem.result);
2595
2581
  }
2582
+ this._cache.set(cacheKey, result);
2596
2583
  return result;
2597
2584
  }
2598
2585
  _mergeComposeResult(result, rule, ruleResult) {
@@ -2956,16 +2943,22 @@ var ConditionalFormattingIcon = class extends SheetExtension {
2956
2943
  _defineProperty(this, "_paddingRightAndLeft", 2);
2957
2944
  _defineProperty(this, "_width", 15);
2958
2945
  _defineProperty(this, "_imageMap", /* @__PURE__ */ new Map());
2946
+ _defineProperty(this, "_renderRangeResolver", null);
2959
2947
  _defineProperty(this, "uKey", IconUKey);
2960
2948
  _defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX);
2961
2949
  _defineProperty(this, "_radius", 1);
2962
2950
  this._init();
2963
2951
  }
2952
+ setRenderRangeResolver(resolver) {
2953
+ this._renderRangeResolver = resolver;
2954
+ }
2964
2955
  draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
2965
2956
  const { worksheet } = spreadsheetSkeleton;
2966
2957
  if (!worksheet) return false;
2967
2958
  const mergeCellRendered = /* @__PURE__ */ new Set();
2968
- const renderRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
2959
+ const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
2960
+ const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
2961
+ if (!renderRanges.length) return;
2969
2962
  ctx.save();
2970
2963
  renderRanges.forEach((range) => {
2971
2964
  Range.foreach(range, (row, col) => {
@@ -2995,6 +2988,10 @@ var ConditionalFormattingIcon = class extends SheetExtension {
2995
2988
  });
2996
2989
  ctx.restore();
2997
2990
  }
2991
+ dispose() {
2992
+ this._renderRangeResolver = null;
2993
+ super.dispose();
2994
+ }
2998
2995
  _init() {
2999
2996
  for (const type in iconMap) iconMap[type].forEach((base64, index) => {
3000
2997
  const key = this._createKey(type, String(index));
@@ -3039,4 +3036,4 @@ function removeUndefinedAttr(obj) {
3039
3036
  }
3040
3037
 
3041
3038
  //#endregion
3042
- export { AddCfCommand, AddConditionalRuleMutation, AddConditionalRuleMutationUndoFactory, CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator, CFValueType, CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH, ClearRangeCfCommand, ClearWorksheetCfCommand, ConditionalFormattingFormulaService, ConditionalFormattingIcon, ConditionalFormattingRangeIndexModel, ConditionalFormattingRangeTransformService, ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingStyleComposer, ConditionalFormattingViewModel, DEFAULT_BG_COLOR, DEFAULT_FONT_COLOR, DEFAULT_PADDING, DEFAULT_WIDTH, DataBar, DeleteCfCommand, DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, IIconSetType, IconUKey, MoveCfCommand, MoveConditionalRuleMutation, MoveConditionalRuleMutationUndoFactory, SHEET_CONDITIONAL_FORMATTING_PLUGIN, SetCfCommand, SetConditionalRuleMutation, UniverSheetsConditionalFormattingPlugin, anchorUndoFactory, compareWithNumber, createCfId, createDefaultRule, createDefaultValue, createDefaultValueByValueType, dataBarUKey, defaultDataBarNativeColor, defaultDataBarPositiveColor, defaultPlaceholderColor, filterRange, findIndexByAnchor, getCacheStyleMatrix, getCellValue, getColorScaleFromValue, getMaxInFormulaResult, getOppositeOperator, getValueByType, iconGroup, iconMap, isAnchorEqual, isFloatsEqual, isNullable, moveByAnchor, removeUndefinedAttr, serialTimeToTimestamp, setConditionalRuleMutationUndoFactory, toYMD_1900, transformSupportSymmetryAnchor };
3039
+ export { AddCfCommand, AddConditionalRuleMutation, AddConditionalRuleMutationUndoFactory, CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator, CFValueType, CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH, ClearRangeCfCommand, ClearWorksheetCfCommand, ConditionalFormattingFormulaService, ConditionalFormattingIcon, ConditionalFormattingRangeIndexModel, ConditionalFormattingRangeTransformService, ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingStyleComposer, ConditionalFormattingViewModel, DEFAULT_BG_COLOR, DEFAULT_FONT_COLOR, DEFAULT_PADDING, DEFAULT_WIDTH, DataBar, DeleteCfCommand, DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, IIconSetType, IconUKey, MoveCfCommand, MoveConditionalRuleMutation, MoveConditionalRuleMutationUndoFactory, SHEET_CONDITIONAL_FORMATTING_PLUGIN, SetCfCommand, SetConditionalRuleMutation, UniverSheetsConditionalFormattingPlugin, anchorUndoFactory, compareWithNumber, createCfId, createDefaultRule, createDefaultValue, createDefaultValueByValueType, dataBarUKey, defaultDataBarNativeColor, defaultDataBarPositiveColor, defaultPlaceholderColor, filterRange, findIndexByAnchor, getCacheStyleMatrix, getCellValue, getColorScaleFromValue, getMaxInFormulaResult, getOppositeOperator, getValueByType, iconGroup, iconMap, isAnchorEqual, isFloatsEqual, isNullable, moveByAnchor, removeUndefinedAttr, serialTimeToTimestamp, setConditionalRuleMutationUndoFactory, transformSupportSymmetryAnchor };