@univerjs/sheets-conditional-formatting-ui 1.0.0-alpha.8 → 1.0.0-beta.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/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, InterceptorManager, LocaleService, ObjectMatrix, Plugin, Range, Rectangle, Tools, UniverInstanceType, createInterceptorKey, generateRandomId, get, merge, registerDependencies, set, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { AFTER_CELL_EDIT, AUTO_FILL_APPLY_TYPE, AutoFillTools, ClearSelectionAllCommand, ClearSelectionFormatCommand, IAutoFillService, INTERCEPTOR_POINT, RangeProtectionPermissionEditPoint, RemoveSheetMutation, SetSelectionsOperation, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, checkRangesEditablePermission, getSheetCommandTarget, rangeToDiscreteRange, setEndForRange } from "@univerjs/sheets";
3
3
  import { AddCfCommand, AddConditionalRuleMutation, AddConditionalRuleMutationUndoFactory, CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator, CFValueType, CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH, ClearRangeCfCommand, ClearWorksheetCfCommand, ConditionalFormattingRangeIndexModel, ConditionalFormattingRangeTransformService, ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingViewModel, DEFAULT_BG_COLOR, DEFAULT_FONT_COLOR, DEFAULT_PADDING, DEFAULT_WIDTH, DeleteCfCommand, DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, IIconSetType, MoveCfCommand, MoveConditionalRuleMutation, SHEET_CONDITIONAL_FORMATTING_PLUGIN, SetCfCommand, SetConditionalRuleMutation, UniverSheetsConditionalFormattingPlugin, compareWithNumber, createCfId, createDefaultRule, createDefaultValue, createDefaultValueByValueType, defaultDataBarNativeColor, defaultDataBarPositiveColor, getColorScaleFromValue, getOppositeOperator, iconGroup, iconMap, removeUndefinedAttr, setConditionalRuleMutationUndoFactory } from "@univerjs/sheets-conditional-formatting";
4
- import { ComponentManager, IMenuManagerService, ISidebarService, IconManager, MenuItemType, RibbonDataGroup, RibbonInsertGroup, UniverUIPlugin, getMenuHiddenObservable, useDependency, useObservable, useSidebarClick } from "@univerjs/ui";
4
+ import { ComponentManager, IMenuManagerService, ISidebarService, IconManager, MenuItemType, RibbonDataGroup, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable, useSidebarClick } from "@univerjs/ui";
5
5
  import { COPY_TYPE, FormatPainterStatus, IFormatPainterService, ISheetClipboardService, PREDEFINED_HOOK_NAME_PASTE, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, getCurrentRangeDisable$, getRepeatRange, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
6
6
  import { Observable, debounceTime, filter, map, merge as merge$1, share, startWith } from "rxjs";
7
7
  import { bufferTime, debounceTime as debounceTime$1, filter as filter$1 } from "rxjs/operators";
@@ -81,10 +81,9 @@ const AddDataBarConditionalRuleCommand = {
81
81
  type: CommandType.COMMAND,
82
82
  id: "sheet.command.add-data-bar-conditional-rule",
83
83
  handler(accessor, params) {
84
- var _params$ranges;
85
84
  if (!params) return false;
86
85
  const { min, max, nativeColor, positiveColor, isGradient, stopIfTrue, isShowValue } = params;
87
- const ranges = (_params$ranges = params.ranges) !== null && _params$ranges !== void 0 ? _params$ranges : accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
86
+ const ranges = params.ranges ?? accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
88
87
  if (!ranges.length) return false;
89
88
  const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel);
90
89
  const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
@@ -152,9 +151,8 @@ const AddIconSetConditionalRuleCommand = {
152
151
  type: CommandType.COMMAND,
153
152
  id: "sheet.command.add-icon-set-conditional-rule",
154
153
  handler(accessor, params) {
155
- var _params$ranges;
156
154
  if (!params) return false;
157
- const ranges = (_params$ranges = params.ranges) !== null && _params$ranges !== void 0 ? _params$ranges : accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
155
+ const ranges = params.ranges ?? accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
158
156
  if (!ranges.length) return false;
159
157
  const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
160
158
  if (!target) return false;
@@ -986,7 +984,7 @@ const menuSchema = {
986
984
  //#endregion
987
985
  //#region package.json
988
986
  var name = "@univerjs/sheets-conditional-formatting-ui";
989
- var version = "1.0.0-alpha.8";
987
+ var version = "1.0.0-beta.0";
990
988
 
991
989
  //#endregion
992
990
  //#region src/config/config.ts
@@ -1520,9 +1518,9 @@ let SheetsCfRenderController = class SheetsCfRenderController extends Disposable
1520
1518
  _collectDirtyRanges(items, unitId, subUnitId) {
1521
1519
  const ranges = [];
1522
1520
  items.forEach((item) => {
1523
- var _item$rule, _rule$ranges;
1521
+ var _rule$ranges;
1524
1522
  if (item.unitId !== unitId || item.subUnitId !== subUnitId) return;
1525
- const rule = (_item$rule = item.rule) !== null && _item$rule !== void 0 ? _item$rule : item.cfId ? this._conditionalFormattingRuleModel.getRule(unitId, subUnitId, item.cfId) : null;
1523
+ const rule = item.rule ?? (item.cfId ? this._conditionalFormattingRuleModel.getRule(unitId, subUnitId, item.cfId) : null);
1526
1524
  if (rule === null || rule === void 0 || (_rule$ranges = rule.ranges) === null || _rule$ranges === void 0 ? void 0 : _rule$ranges.length) ranges.push(...rule.ranges);
1527
1525
  });
1528
1526
  return ranges;
@@ -1552,13 +1550,12 @@ let SheetsCfRenderController = class SheetsCfRenderController extends Disposable
1552
1550
  render === null || render === void 0 || (_render$mainComponent = render.mainComponent) === null || _render$mainComponent === void 0 || _render$mainComponent.makeDirty();
1553
1551
  }
1554
1552
  _markActiveSheetRulesDirty() {
1555
- var _this$_conditionalFor;
1556
1553
  const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
1557
1554
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
1558
1555
  if (!workbook || !worksheet) return;
1559
1556
  const unitId = workbook.getUnitId();
1560
1557
  const subUnitId = worksheet.getSheetId();
1561
- const rules = (_this$_conditionalFor = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId)) !== null && _this$_conditionalFor !== void 0 ? _this$_conditionalFor : [];
1558
+ const rules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId) ?? [];
1562
1559
  if (!rules.length) return;
1563
1560
  this._markDirtySkeleton(rules.map((rule) => ({
1564
1561
  rule,
@@ -1865,10 +1862,9 @@ let ConditionalFormattingEditorController = class ConditionalFormattingEditorCon
1865
1862
  */
1866
1863
  _initInterceptorEditorEnd() {
1867
1864
  this.disposeWithMe(toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(AFTER_CELL_EDIT, { handler: (value, context, next) => {
1868
- var _result$style;
1869
1865
  if (!value) next(value);
1870
1866
  const result = this._conditionalFormattingService.composeStyle(context.unitId, context.subUnitId, context.row, context.col);
1871
- const cfStyle = (_result$style = result === null || result === void 0 ? void 0 : result.style) !== null && _result$style !== void 0 ? _result$style : {};
1867
+ const cfStyle = (result === null || result === void 0 ? void 0 : result.style) ?? {};
1872
1868
  const keys = Object.keys(cfStyle);
1873
1869
  if (value === null || value === void 0 ? void 0 : value.p) {
1874
1870
  var _value$p$body;
@@ -2032,7 +2028,6 @@ let ConditionalFormattingPainterController = class ConditionalFormattingPainterC
2032
2028
  });
2033
2029
  };
2034
2030
  const generalApplyFunc = (targetUnitId, targetSubUnitId, targetRange) => {
2035
- var _this$_conditionalFor;
2036
2031
  const { range: sourceRange, unitId: sourceUnitId, subUnitId: sourceSubUnitId } = this._painterConfig;
2037
2032
  const isSkipSheet = targetUnitId !== sourceUnitId || sourceSubUnitId !== targetSubUnitId;
2038
2033
  const rangeMap = /* @__PURE__ */ new Map();
@@ -2040,7 +2035,7 @@ let ConditionalFormattingPainterController = class ConditionalFormattingPainterC
2040
2035
  const redos = [];
2041
2036
  const undos = [];
2042
2037
  if (!targetUnitId || !targetSubUnitId || !sourceUnitId || !sourceSubUnitId) return noopReturnFunc();
2043
- const ruleList = (_this$_conditionalFor = this._conditionalFormattingRuleModel.getSubunitRules(sourceUnitId, sourceSubUnitId)) !== null && _this$_conditionalFor !== void 0 ? _this$_conditionalFor : [];
2038
+ const ruleList = this._conditionalFormattingRuleModel.getSubunitRules(sourceUnitId, sourceSubUnitId) ?? [];
2044
2039
  ruleList === null || ruleList === void 0 || ruleList.forEach((rule) => {
2045
2040
  const { ranges, cfId } = rule;
2046
2041
  if (ranges.some((range) => Rectangle.intersects(sourceRange, range))) rangeMap.set(cfId, isSkipSheet ? [] : ranges);
@@ -2294,7 +2289,6 @@ function Preview(props) {
2294
2289
  const previewClassName = "univer-pointer-events-none univer-flex univer-h-5 univer-min-w-[72px] univer-items-center univer-justify-center univer-text-xs";
2295
2290
  switch (rule.type) {
2296
2291
  case CFRuleType.dataBar: {
2297
- var _rule$config$nativeCo, _rule$config$positive;
2298
2292
  const { isGradient } = rule.config;
2299
2293
  const positiveColor = isGradient ? `linear-gradient(to right, ${rule.config.positiveColor || defaultDataBarPositiveColor}, rgb(255 255 255))` : rule.config.positiveColor;
2300
2294
  return /* @__PURE__ */ jsxs("div", {
@@ -2303,13 +2297,13 @@ function Preview(props) {
2303
2297
  className: "univer-h-full univer-w-1/2 univer-border univer-border-solid",
2304
2298
  style: {
2305
2299
  background: isGradient ? `linear-gradient(to right, rgb(255 255 255),${rule.config.nativeColor || defaultDataBarNativeColor})` : rule.config.nativeColor,
2306
- borderColor: (_rule$config$nativeCo = rule.config.nativeColor) !== null && _rule$config$nativeCo !== void 0 ? _rule$config$nativeCo : defaultDataBarNativeColor
2300
+ borderColor: rule.config.nativeColor ?? defaultDataBarNativeColor
2307
2301
  }
2308
2302
  }), /* @__PURE__ */ jsx("div", {
2309
2303
  className: "univer-h-full univer-w-1/2 univer-border univer-border-solid",
2310
2304
  style: {
2311
2305
  background: positiveColor,
2312
- borderColor: (_rule$config$positive = rule.config.positiveColor) !== null && _rule$config$positive !== void 0 ? _rule$config$positive : defaultDataBarPositiveColor
2306
+ borderColor: rule.config.positiveColor ?? defaultDataBarPositiveColor
2313
2307
  }
2314
2308
  })]
2315
2309
  });
@@ -2333,16 +2327,15 @@ function Preview(props) {
2333
2327
  }, index) : /* @__PURE__ */ jsx(SlashDoubleIcon, {}, index))
2334
2328
  });
2335
2329
  case CFRuleType.highlightCell: {
2336
- var _bg$rgb, _cl$rgb, _replace;
2337
2330
  const { ul, st, it, bl, bg, cl } = rule.style;
2338
2331
  const isUnderline = (ul === null || ul === void 0 ? void 0 : ul.s) === BooleanNumber.TRUE;
2339
2332
  const isStrikethrough = (st === null || st === void 0 ? void 0 : st.s) === BooleanNumber.TRUE;
2340
2333
  const isItalic = it === BooleanNumber.TRUE;
2341
2334
  const isBold = bl === BooleanNumber.TRUE;
2342
- const bgColor = (_bg$rgb = bg === null || bg === void 0 ? void 0 : bg.rgb) !== null && _bg$rgb !== void 0 ? _bg$rgb : DEFAULT_BG_COLOR;
2343
- const fontColor = (_cl$rgb = cl === null || cl === void 0 ? void 0 : cl.rgb) !== null && _cl$rgb !== void 0 ? _cl$rgb : DEFAULT_FONT_COLOR;
2335
+ const bgColor = (bg === null || bg === void 0 ? void 0 : bg.rgb) ?? DEFAULT_BG_COLOR;
2336
+ const fontColor = (cl === null || cl === void 0 ? void 0 : cl.rgb) ?? DEFAULT_FONT_COLOR;
2344
2337
  const style = {
2345
- textDecoration: (_replace = `${isUnderline ? "underline" : ""} ${isStrikethrough ? "line-through" : ""}`.replace(/^ /, "")) !== null && _replace !== void 0 ? _replace : void 0,
2338
+ textDecoration: `${isUnderline ? "underline" : ""} ${isStrikethrough ? "line-through" : ""}`.replace(/^ /, "") ?? void 0,
2346
2339
  backgroundColor: bgColor,
2347
2340
  color: fontColor
2348
2341
  };
@@ -3405,13 +3398,10 @@ const FormulaStyleEditor = (props) => {
3405
3398
  //#endregion
3406
3399
  //#region src/views/wrapper-error/WrapperError.tsx
3407
3400
  const WrapperError = (props) => {
3408
- return /* @__PURE__ */ jsxs("div", {
3409
- className: "univer-relative",
3410
- children: [/* @__PURE__ */ jsx("div", {
3411
- className: "univer-absolute univer-bottom-[-13px] univer-z-[999] univer-text-[10px] univer-text-red-500",
3412
- children: props.errorText
3413
- }), props.children]
3414
- });
3401
+ return /* @__PURE__ */ jsxs("div", { children: [props.children, props.errorText && /* @__PURE__ */ jsx("div", {
3402
+ className: "univer-mt-1 univer-text-xs univer-text-red-500",
3403
+ children: props.errorText
3404
+ })] });
3415
3405
  };
3416
3406
 
3417
3407
  //#endregion
@@ -3673,11 +3663,10 @@ const HighlightCellStyleEditor = (props) => {
3673
3663
  });
3674
3664
  const [style, setStyle] = useState({});
3675
3665
  const getResult = useMemo(() => (option) => {
3676
- var _option$subType, _option$operator, _option$value, _option$style;
3677
- const nextSubType = (_option$subType = option.subType) !== null && _option$subType !== void 0 ? _option$subType : subType;
3678
- const nextOperator = (_option$operator = option.operator) !== null && _option$operator !== void 0 ? _option$operator : operator;
3679
- const nextValue = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : value;
3680
- const nextStyle = (_option$style = option.style) !== null && _option$style !== void 0 ? _option$style : style;
3666
+ const nextSubType = option.subType ?? subType;
3667
+ const nextOperator = option.operator ?? operator;
3668
+ const nextValue = option.value ?? value;
3669
+ const nextStyle = option.style ?? style;
3681
3670
  switch (nextSubType) {
3682
3671
  case CFSubRuleType.duplicateValues: return {
3683
3672
  type: CFRuleType.highlightCell,
@@ -3828,7 +3817,7 @@ const TextInput = (props) => {
3828
3817
  children: type !== CFValueType.formula ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InputNumber, {
3829
3818
  className: clsx({ "univer-border-red-500": error }),
3830
3819
  value: Number(props.value) || 0,
3831
- onChange: (v) => onChange(v !== null && v !== void 0 ? v : 0)
3820
+ onChange: (v) => onChange(v ?? 0)
3832
3821
  }), error && /* @__PURE__ */ jsx("div", {
3833
3822
  className: "univer-absolute univer-text-xs univer-text-red-500",
3834
3823
  children: error
@@ -4498,7 +4487,7 @@ const getSubUnitId = (univerInstanceService) => {
4498
4487
  return (_getActiveSheet = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
4499
4488
  };
4500
4489
  const RuleEdit = (props) => {
4501
- var _props$rule$ranges, _props$rule, _props$rule5;
4490
+ var _props$rule, _props$rule5;
4502
4491
  const localeService = useDependency(LocaleService);
4503
4492
  const commandService = useDependency(ICommandService);
4504
4493
  const univerInstanceService = useDependency(IUniverInstanceService);
@@ -4507,14 +4496,14 @@ const RuleEdit = (props) => {
4507
4496
  const unitId = getUnitId(univerInstanceService);
4508
4497
  const subUnitId = getSubUnitId(univerInstanceService);
4509
4498
  const [errorText, setErrorText] = useState(void 0);
4510
- const rangeResult = useRef((_props$rule$ranges = (_props$rule = props.rule) === null || _props$rule === void 0 ? void 0 : _props$rule.ranges) !== null && _props$rule$ranges !== void 0 ? _props$rule$ranges : []);
4499
+ const rangeResult = useRef(((_props$rule = props.rule) === null || _props$rule === void 0 ? void 0 : _props$rule.ranges) ?? []);
4511
4500
  const rangeSelectorTouched = useRef(false);
4512
4501
  const rangeString = useMemo(() => {
4513
4502
  var _props$rule2;
4514
4503
  let ranges = (_props$rule2 = props.rule) === null || _props$rule2 === void 0 ? void 0 : _props$rule2.ranges;
4515
4504
  if (!(ranges === null || ranges === void 0 ? void 0 : ranges.length)) {
4516
- var _selectionManagerServ, _selectionManagerServ2;
4517
- ranges = (_selectionManagerServ = (_selectionManagerServ2 = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.map((s) => s.range)) !== null && _selectionManagerServ !== void 0 ? _selectionManagerServ : [];
4505
+ var _selectionManagerServ;
4506
+ ranges = ((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range)) ?? [];
4518
4507
  }
4519
4508
  rangeResult.current = ranges;
4520
4509
  if (!(ranges === null || ranges === void 0 ? void 0 : ranges.length)) return "";
@@ -4828,9 +4817,8 @@ function RuleList(props) {
4828
4817
  });
4829
4818
  };
4830
4819
  const handleDragStart = (_layout, from) => {
4831
- var _dragRule$cfId;
4832
4820
  const dragRule = ruleListByPermissionCheck[from.y];
4833
- setDraggingId((_dragRule$cfId = dragRule === null || dragRule === void 0 ? void 0 : dragRule.cfId) !== null && _dragRule$cfId !== void 0 ? _dragRule$cfId : "");
4821
+ setDraggingId((dragRule === null || dragRule === void 0 ? void 0 : dragRule.cfId) ?? "");
4834
4822
  };
4835
4823
  const handleDragStop = (_layout, from, to) => {
4836
4824
  var _getActiveSheet2, _ruleListByPermission, _ruleListByPermission2;
@@ -5133,7 +5121,7 @@ _defineProperty(UniverSheetsConditionalFormattingUIPlugin, "packageName", name);
5133
5121
  _defineProperty(UniverSheetsConditionalFormattingUIPlugin, "version", version);
5134
5122
  _defineProperty(UniverSheetsConditionalFormattingUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
5135
5123
  UniverSheetsConditionalFormattingUIPlugin = __decorate([
5136
- DependentOn(UniverRenderEnginePlugin, UniverSheetsPlugin, UniverUIPlugin, UniverSheetsFormulaPlugin, UniverSheetsConditionalFormattingPlugin, UniverSheetsUIPlugin),
5124
+ DependentOn(UniverRenderEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin, UniverSheetsConditionalFormattingPlugin, UniverSheetsUIPlugin),
5137
5125
  __decorateParam(1, Inject(Injector)),
5138
5126
  __decorateParam(2, Inject(ICommandService)),
5139
5127
  __decorateParam(3, IConfigService)