@univerjs/sheets-conditional-formatting-ui 0.2.6 → 0.2.7
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/es/index.js
CHANGED
|
@@ -2,9 +2,9 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import { CommandType, ICommandService, IUniverInstanceService, IUndoRedoService, ObjectMatrix, Range, sequenceExecute, UniverInstanceType, Rectangle, ColorKit, BooleanNumber, Disposable, OnLifecycle, LifecycleStages, Inject, LocaleService, useDependency, createInterceptorKey, createInternalEditorID, Tools, InterceptorManager,
|
|
6
|
-
import { ConditionalFormattingRuleModel, CFRuleType, CFSubRuleType, AddConditionalRuleMutation, CFNumberOperator, setConditionalRuleMutationUndoFactory, SetConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, DeleteConditionalRuleMutation, MoveConditionalRuleMutation, transformSupportSymmetryAnchor, MoveConditionalRuleMutationUndoFactory, getColorScaleFromValue, iconMap, DEFAULT_BG_COLOR, DEFAULT_FONT_COLOR, AddConditionalRuleMutationUndoFactory, CFValueType, createDefaultValueByValueType, SHEET_CONDITIONAL_FORMATTING_PLUGIN, removeUndefinedAttr, createDefaultValue, CFTextOperator, CFTimePeriodOperator, iconGroup, getOppositeOperator, compareWithNumber, EMPTY_ICON_TYPE, createDefaultRule, DEFAULT_PADDING, DEFAULT_WIDTH, ConditionalFormattingService, ConditionalFormattingViewModel, isRangesEqual, UniverSheetsConditionalFormattingPlugin, getStringFromDataStream } from "@univerjs/sheets-conditional-formatting";
|
|
7
|
-
import { getSheetCommandTarget, SheetsSelectionsService, findAllRectangle, createTopMatrixFromMatrix, SetWorksheetActiveOperation, WorkbookEditablePermission, WorksheetSetCellStylePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, SetSelectionsOperation, RemoveSheetMutation, setEndForRange, INTERCEPTOR_POINT, SheetInterceptorService, RefRangeService, handleDefaultRangeChangeWithEffectRefCommands, ClearSelectionFormatCommand, ClearSelectionAllCommand, RangeMergeUtil } from "@univerjs/sheets";
|
|
5
|
+
import { CommandType, ICommandService, IUniverInstanceService, IUndoRedoService, ObjectMatrix, Range, sequenceExecute, UniverInstanceType, Rectangle, ColorKit, BooleanNumber, Disposable, OnLifecycle, LifecycleStages, Inject, LocaleService, useDependency, Injector, createInterceptorKey, createInternalEditorID, Tools, InterceptorManager, toDisposable, Plugin, DependentOn } from "@univerjs/core";
|
|
6
|
+
import { ConditionalFormattingRuleModel, CFRuleType, CFSubRuleType, AddConditionalRuleMutation, CFNumberOperator, setConditionalRuleMutationUndoFactory, SetConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory, DeleteConditionalRuleMutation, MoveConditionalRuleMutation, transformSupportSymmetryAnchor, MoveConditionalRuleMutationUndoFactory, getColorScaleFromValue, iconMap, DEFAULT_BG_COLOR, DEFAULT_FONT_COLOR, defaultDataBarPositiveColor, defaultDataBarNativeColor, AddConditionalRuleMutationUndoFactory, CFValueType, createDefaultValueByValueType, SHEET_CONDITIONAL_FORMATTING_PLUGIN, removeUndefinedAttr, createDefaultValue, CFTextOperator, CFTimePeriodOperator, iconGroup, getOppositeOperator, compareWithNumber, EMPTY_ICON_TYPE, createDefaultRule, DEFAULT_PADDING, DEFAULT_WIDTH, ConditionalFormattingService, ConditionalFormattingViewModel, isRangesEqual, UniverSheetsConditionalFormattingPlugin, getStringFromDataStream } from "@univerjs/sheets-conditional-formatting";
|
|
7
|
+
import { getSheetCommandTarget, SheetsSelectionsService, findAllRectangle, createTopMatrixFromMatrix, SetWorksheetActiveOperation, checkRangesEditablePermission, WorkbookEditablePermission, WorksheetSetCellStylePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, SetSelectionsOperation, RemoveSheetMutation, setEndForRange, INTERCEPTOR_POINT, SheetInterceptorService, RefRangeService, handleDefaultRangeChangeWithEffectRefCommands, ClearSelectionFormatCommand, ClearSelectionAllCommand, RangeMergeUtil } from "@univerjs/sheets";
|
|
8
8
|
import { MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, useObservable, ComponentManager, TextEditor, ILayoutService, useScrollYOverContainer, RangeSelector, IMenuService, ISidebarService } from "@univerjs/ui";
|
|
9
9
|
import { Observable, merge, debounceTime as debounceTime$1 } from "rxjs";
|
|
10
10
|
import { debounceTime, bufferTime, filter } from "rxjs/operators";
|
|
@@ -288,9 +288,7 @@ const AddAverageCfCommand = {
|
|
|
288
288
|
undoMutations: undos
|
|
289
289
|
}), result;
|
|
290
290
|
}
|
|
291
|
-
}
|
|
292
|
-
var P = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(P || {});
|
|
293
|
-
const commandList = [SetWorksheetActiveOperation.id, AddConditionalRuleMutation.id, SetConditionalRuleMutation.id, DeleteConditionalRuleMutation.id, MoveConditionalRuleMutation.id], FactoryManageConditionalFormattingRule = /* @__PURE__ */ __name((accessor) => {
|
|
291
|
+
}, commandList = [SetWorksheetActiveOperation.id, AddConditionalRuleMutation.id, SetConditionalRuleMutation.id, DeleteConditionalRuleMutation.id, MoveConditionalRuleMutation.id], FactoryManageConditionalFormattingRule = /* @__PURE__ */ __name((accessor) => {
|
|
294
292
|
const commonSelections = [
|
|
295
293
|
{
|
|
296
294
|
label: "sheet.cf.ruleType.highlightCell",
|
|
@@ -349,20 +347,17 @@ const commandList = [SetWorksheetActiveOperation.id, AddConditionalRuleMutation.
|
|
|
349
347
|
if (!workbook) return;
|
|
350
348
|
const worksheet = workbook.getActiveSheet();
|
|
351
349
|
if (!worksheet) return;
|
|
352
|
-
const
|
|
353
|
-
subscriber.next(
|
|
350
|
+
const hasPermission = (conditionalFormattingRuleModel.getSubunitRules(workbook.getUnitId(), worksheet.getSheetId()) || []).filter((rule) => rule.ranges.some((ruleRange2) => ranges.some((range) => Rectangle.intersects(range, ruleRange2)))).map((rule) => rule.ranges).every((ranges2) => checkRangesEditablePermission(accessor, workbook.getUnitId(), worksheet.getSheetId(), ranges2));
|
|
351
|
+
subscriber.next(hasPermission);
|
|
354
352
|
})), clearSheetEnable$ = new Observable(
|
|
355
|
-
(subscriber) =>
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return () => disposable.dispose();
|
|
364
|
-
})
|
|
365
|
-
).pipe(debounceTime(16)).subscribe(() => {
|
|
353
|
+
(subscriber) => new Observable((commandSubscribe) => {
|
|
354
|
+
const disposable = commandService.onCommandExecuted((commandInfo) => {
|
|
355
|
+
var _a13;
|
|
356
|
+
const { id, params } = commandInfo, unitId = (_a13 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a13.getUnitId();
|
|
357
|
+
commandList.includes(id) && params.unitId === unitId && commandSubscribe.next(null);
|
|
358
|
+
});
|
|
359
|
+
return () => disposable.dispose();
|
|
360
|
+
}).pipe(debounceTime(16)).subscribe(() => {
|
|
366
361
|
const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
367
362
|
if (!workbook) return;
|
|
368
363
|
const worksheet = workbook.getActiveSheet();
|
|
@@ -370,18 +365,8 @@ const commandList = [SetWorksheetActiveOperation.id, AddConditionalRuleMutation.
|
|
|
370
365
|
const allRule = conditionalFormattingRuleModel.getSubunitRules(workbook.getUnitId(), worksheet.getSheetId()) || [];
|
|
371
366
|
if (!allRule.length)
|
|
372
367
|
return subscriber.next(!1), !1;
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const { startRow, startColumn, endRow, endColumn } = range;
|
|
376
|
-
for (let row = startRow; row <= endRow; row++)
|
|
377
|
-
for (let col = startColumn; col <= endColumn; col++) {
|
|
378
|
-
const permission = (_b = (_a13 = worksheet.getCell(row, col)) == null ? void 0 : _a13.selectionProtection) == null ? void 0 : _b[0];
|
|
379
|
-
if ((permission == null ? void 0 : permission[P.Edit]) === !1 || (permission == null ? void 0 : permission[P.View]) === !1)
|
|
380
|
-
return !0;
|
|
381
|
-
}
|
|
382
|
-
return !1;
|
|
383
|
-
}));
|
|
384
|
-
subscriber.next(!hasNotPermission);
|
|
368
|
+
const hasPermission = allRule.map((rule) => rule.ranges).every((ranges) => checkRangesEditablePermission(accessor, workbook.getUnitId(), worksheet.getSheetId(), ranges));
|
|
369
|
+
subscriber.next(hasPermission);
|
|
385
370
|
})
|
|
386
371
|
), selections$ = new Observable((subscriber) => {
|
|
387
372
|
clearRangeEnable$.subscribe((v) => {
|
|
@@ -4635,10 +4620,10 @@ const GridLayout = /* @__PURE__ */ getDefaultExportFromCjs(reactGridLayoutExport
|
|
|
4635
4620
|
}, [rule]);
|
|
4636
4621
|
switch (rule.type) {
|
|
4637
4622
|
case CFRuleType.dataBar: {
|
|
4638
|
-
const { isGradient } = rule.config, commonStyle = { width: "50%", height: "100%" }, positiveColor = isGradient ? `linear-gradient(to right, ${rule.config.positiveColor}, rgb(255 255 255))` : rule.config.positiveColor, nativeColor = isGradient ? `linear-gradient(to right, rgb(255 255 255),${rule.config.nativeColor})` : rule.config.nativeColor;
|
|
4623
|
+
const { isGradient } = rule.config, commonStyle = { width: "50%", height: "100%" }, positiveColor = isGradient ? `linear-gradient(to right, ${rule.config.positiveColor || defaultDataBarPositiveColor}, rgb(255 255 255))` : rule.config.positiveColor, nativeColor = isGradient ? `linear-gradient(to right, rgb(255 255 255),${rule.config.nativeColor || defaultDataBarNativeColor})` : rule.config.nativeColor;
|
|
4639
4624
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$4.cfPreview, children: [
|
|
4640
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { ...commonStyle, background: nativeColor, border: `1px solid ${rule.config.nativeColor}` } }),
|
|
4641
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { ...commonStyle, background: positiveColor, border: `1px solid ${rule.config.positiveColor}` } })
|
|
4625
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { ...commonStyle, background: nativeColor, border: `1px solid ${rule.config.nativeColor || defaultDataBarNativeColor}` } }),
|
|
4626
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { ...commonStyle, background: positiveColor, border: `1px solid ${rule.config.positiveColor || defaultDataBarPositiveColor}` } })
|
|
4642
4627
|
] });
|
|
4643
4628
|
}
|
|
4644
4629
|
case CFRuleType.colorScale:
|
|
@@ -4764,7 +4749,7 @@ const cfRuleList = "univer-cf-rule-list", ruleSelector = "univer-rule-selector",
|
|
|
4764
4749
|
}, "getRuleDescribe");
|
|
4765
4750
|
let defaultWidth = 0;
|
|
4766
4751
|
const RuleList = /* @__PURE__ */ __name((props) => {
|
|
4767
|
-
const { onClick } = props, conditionalFormattingRuleModel = useDependency(ConditionalFormattingRuleModel), univerInstanceService = useDependency(IUniverInstanceService), selectionManagerService = useDependency(SheetsSelectionsService), commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), conditionalFormattingI18nController = useDependency(ConditionalFormattingI18nController), workbook = useObservable(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), void 0, void 0, []), unitId = workbook.getUnitId(), worksheet = workbook.getActiveSheet();
|
|
4752
|
+
const { onClick } = props, conditionalFormattingRuleModel = useDependency(ConditionalFormattingRuleModel), univerInstanceService = useDependency(IUniverInstanceService), selectionManagerService = useDependency(SheetsSelectionsService), commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useDependency(Injector), conditionalFormattingI18nController = useDependency(ConditionalFormattingI18nController), workbook = useObservable(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), void 0, void 0, []), unitId = workbook.getUnitId(), worksheet = workbook.getActiveSheet();
|
|
4768
4753
|
if (!worksheet)
|
|
4769
4754
|
throw new Error("No active sheet found");
|
|
4770
4755
|
const subUnitId = worksheet.getSheetId(), [currentRuleRanges, currentRuleRangesSet] = useState([]), [selectValue, selectValueSet] = useState("2"), [fetchRuleListId, fetchRuleListIdSet] = useState(0), [draggingId, draggingIdSet] = useState(-1), [layoutWidth, layoutWidthSet] = useState(defaultWidth), layoutContainerRef = useRef(null), selectOption = [
|
|
@@ -4781,25 +4766,9 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
4781
4766
|
const range = selection.range;
|
|
4782
4767
|
return ruleList2.filter((rule) => rule.ranges.some((ruleRange2) => Rectangle.intersects(ruleRange2, range)));
|
|
4783
4768
|
} else if (selectValue === "2")
|
|
4784
|
-
return ruleList2;
|
|
4769
|
+
return [...ruleList2];
|
|
4785
4770
|
return [];
|
|
4786
|
-
}, "getRuleList"),
|
|
4787
|
-
const worksheet2 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getActiveSheet();
|
|
4788
|
-
return rules.map((rule) => {
|
|
4789
|
-
const ranges = rule.ranges;
|
|
4790
|
-
return (ranges == null ? void 0 : ranges.some((range) => {
|
|
4791
|
-
var _a13, _b;
|
|
4792
|
-
const { startRow, startColumn, endRow, endColumn } = range;
|
|
4793
|
-
for (let row = startRow; row <= endRow; row++)
|
|
4794
|
-
for (let col = startColumn; col <= endColumn; col++) {
|
|
4795
|
-
const permission = (_b = (_a13 = worksheet2 == null ? void 0 : worksheet2.getCell(row, col)) == null ? void 0 : _a13.selectionProtection) == null ? void 0 : _b[0];
|
|
4796
|
-
if ((permission == null ? void 0 : permission[P.Edit]) === !1 || (permission == null ? void 0 : permission[P.View]) === !1)
|
|
4797
|
-
return !0;
|
|
4798
|
-
}
|
|
4799
|
-
return !1;
|
|
4800
|
-
})) ? { ...rule, disable: !0 } : { ...rule };
|
|
4801
|
-
});
|
|
4802
|
-
}, "getConditionalFormattingRulesByPermissionCorrect"), [ruleList, ruleListSet] = useState(getRuleList);
|
|
4771
|
+
}, "getRuleList"), [ruleList, ruleListSet] = useState(getRuleList);
|
|
4803
4772
|
useHighlightRange(currentRuleRanges), useEffect(() => {
|
|
4804
4773
|
const disposable = commandService.onCommandExecuted((commandInfo) => {
|
|
4805
4774
|
commandInfo.id === SetWorksheetActiveOperation.id && fetchRuleListIdSet(Math.random());
|
|
@@ -4879,7 +4848,19 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
4879
4848
|
selectValue === "2" ? commandService.executeCommand(ClearWorksheetCfCommand.id) : selectValue === "1" && ruleList.map((rule) => ({ unitId, subUnitId, cfId: rule.cfId })).forEach((config) => {
|
|
4880
4849
|
commandService.executeCommand(DeleteCfCommand.id, config);
|
|
4881
4850
|
});
|
|
4882
|
-
}, "handleClear"),
|
|
4851
|
+
}, "handleClear"), ruleListByPermissionCheck = useMemo(() => {
|
|
4852
|
+
const workbook2 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2.getActiveSheet();
|
|
4853
|
+
return ruleList.filter((rule) => {
|
|
4854
|
+
const ranges = rule.ranges;
|
|
4855
|
+
return checkRangesEditablePermission(injector, workbook2.getUnitId(), worksheet2.getSheetId(), ranges);
|
|
4856
|
+
});
|
|
4857
|
+
}, [ruleList]), layout = ruleListByPermissionCheck.map((rule, index2) => ({ i: rule.cfId, x: 0, w: 12, y: index2, h: 1, isResizable: !1 })), isHasAllRuleEditPermission = useMemo(() => {
|
|
4858
|
+
const workbook2 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2.getActiveSheet();
|
|
4859
|
+
return ruleList.every((rule) => {
|
|
4860
|
+
const ranges = rule.ranges;
|
|
4861
|
+
return checkRangesEditablePermission(injector, workbook2.getUnitId(), worksheet2.getSheetId(), ranges);
|
|
4862
|
+
});
|
|
4863
|
+
}, [ruleList]);
|
|
4883
4864
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$3.cfRuleList, children: [
|
|
4884
4865
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$3.ruleSelector, children: [
|
|
4885
4866
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: conditionalFormattingI18nController.tWithReactNode(
|
|
@@ -4890,7 +4871,7 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
4890
4871
|
).map((ele, index2) => /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: ele }, index2)) }),
|
|
4891
4872
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$3.btnList, children: [
|
|
4892
4873
|
/* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { title: localeService.t("sheet.cf.panel.createRule"), placement: "bottom", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${styles$3.icon}`, onClick: handleCreate, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IncreaseSingle, {}) }) }),
|
|
4893
|
-
ruleList.length &&
|
|
4874
|
+
ruleList.length && isHasAllRuleEditPermission ? /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { title: localeService.t("sheet.cf.panel.clear"), placement: "bottom", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${styles$3.gap} ${styles$3.icon}`, onClick: handleClear, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteSingle, {}) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${styles$3.gap} ${styles$3.disabled}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteSingle, {}) })
|
|
4894
4875
|
] })
|
|
4895
4876
|
] }),
|
|
4896
4877
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: layoutContainerRef, className: styles$3.gridLayoutWrap, children: layoutWidth ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
@@ -4912,7 +4893,7 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
4912
4893
|
}, "onMouseMove"),
|
|
4913
4894
|
onMouseLeave: /* @__PURE__ */ __name(() => currentRuleRangesSet([]), "onMouseLeave"),
|
|
4914
4895
|
onClick: /* @__PURE__ */ __name(() => {
|
|
4915
|
-
|
|
4896
|
+
onClick(rule);
|
|
4916
4897
|
}, "onClick"),
|
|
4917
4898
|
className: `${styles$3.ruleItem} ${draggingId === index2 ? styles$3.active : ""}`,
|
|
4918
4899
|
children: [
|
|
@@ -4929,7 +4910,7 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
4929
4910
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$3.ruleRange, children: rule.ranges.map((range) => serializeRange(range)).join(",") })
|
|
4930
4911
|
] }),
|
|
4931
4912
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$3.preview, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Preview, { rule: rule.rule }) }),
|
|
4932
|
-
|
|
4913
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
4933
4914
|
"div",
|
|
4934
4915
|
{
|
|
4935
4916
|
className: `${styles$3.deleteItem} ${draggingId === index2 ? styles$3.active : ""}`,
|
|
@@ -5265,12 +5246,10 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
5265
5246
|
return rule ? (_a14 = rule.config) != null && _a14.isGradient ? "1" : "0" : defaultV;
|
|
5266
5247
|
}), [positiveColor, positiveColorSet] = useState(() => {
|
|
5267
5248
|
var _a14;
|
|
5268
|
-
|
|
5269
|
-
return rule && ((_a14 = rule.config) == null ? void 0 : _a14.positiveColor) || defaultV;
|
|
5249
|
+
return rule ? ((_a14 = rule.config) == null ? void 0 : _a14.positiveColor) || defaultDataBarPositiveColor : defaultDataBarPositiveColor;
|
|
5270
5250
|
}), [nativeColor, nativeColorSet] = useState(() => {
|
|
5271
5251
|
var _a14;
|
|
5272
|
-
|
|
5273
|
-
return rule && ((_a14 = rule.config) == null ? void 0 : _a14.nativeColor) || defaultV;
|
|
5252
|
+
return rule ? ((_a14 = rule.config) == null ? void 0 : _a14.nativeColor) || defaultDataBarNativeColor : defaultDataBarNativeColor;
|
|
5274
5253
|
}), commonOptions = [createOptionItem$1(CFValueType.num, localeService), createOptionItem$1(CFValueType.percent, localeService), createOptionItem$1(CFValueType.percentile, localeService), createOptionItem$1(CFValueType.formula, localeService)], minOptions = [createOptionItem$1(CFValueType.min, localeService), ...commonOptions], maxOptions = [createOptionItem$1(CFValueType.max, localeService), ...commonOptions], [minValueType, minValueTypeSet] = useState(() => {
|
|
5275
5254
|
var _a14;
|
|
5276
5255
|
const defaultV = minOptions[0].value;
|
|
@@ -5295,8 +5274,8 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
5295
5274
|
min: { type: option.minValueType, value: option.minValue },
|
|
5296
5275
|
max: { type: option.maxValueType, value: option.maxValue },
|
|
5297
5276
|
isGradient: option.isGradient === "1",
|
|
5298
|
-
positiveColor: option.positiveColor,
|
|
5299
|
-
nativeColor: option.nativeColor
|
|
5277
|
+
positiveColor: option.positiveColor || defaultDataBarPositiveColor,
|
|
5278
|
+
nativeColor: option.nativeColor || defaultDataBarNativeColor
|
|
5300
5279
|
}, type: CFRuleType.dataBar, isShowValue: option.isShowValue }), "getResult");
|
|
5301
5280
|
useEffect(() => interceptorManager.intercept(interceptorManager.getInterceptPoints().submit, {
|
|
5302
5281
|
handler() {
|
|
@@ -5864,11 +5843,9 @@ const RuleList = /* @__PURE__ */ __name((props) => {
|
|
|
5864
5843
|
handler() {
|
|
5865
5844
|
return getResult({ style, formula });
|
|
5866
5845
|
}
|
|
5867
|
-
}), [style, formula, interceptorManager]), useEffect(() => {
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
});
|
|
5871
|
-
}, [formula]);
|
|
5846
|
+
}), [style, formula, interceptorManager]), useEffect(() => interceptorManager.intercept(interceptorManager.getInterceptPoints().beforeSubmit, {
|
|
5847
|
+
handler: /* @__PURE__ */ __name((v, _c, next) => !formula || formula.length === 1 || !formula.startsWith("=") ? (formulaErrorSet(localeService.t("sheet.cf.errorMessage.formulaError")), !1) : next(v), "handler")
|
|
5848
|
+
}), [formula]);
|
|
5872
5849
|
const _onChange = /* @__PURE__ */ __name((config) => {
|
|
5873
5850
|
onChange(getResult(config));
|
|
5874
5851
|
}, "_onChange");
|
|
@@ -6970,7 +6947,7 @@ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPrope
|
|
|
6970
6947
|
}, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index2, decorator) => (target, key) => decorator(target, key, index2), "__decorateParam$8"), _a4;
|
|
6971
6948
|
let SheetsCfRenderController = (_a4 = class extends Disposable {
|
|
6972
6949
|
constructor(_sheetInterceptorService, _conditionalFormattingService, _univerInstanceService, _renderManagerService, _conditionalFormattingViewModel, _conditionalFormattingRuleModel) {
|
|
6973
|
-
super(), this._sheetInterceptorService = _sheetInterceptorService, this._conditionalFormattingService = _conditionalFormattingService, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._conditionalFormattingViewModel = _conditionalFormattingViewModel, this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel, this._initViewModelInterceptor(), this._initSkeleton();
|
|
6950
|
+
super(), this._sheetInterceptorService = _sheetInterceptorService, this._conditionalFormattingService = _conditionalFormattingService, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._conditionalFormattingViewModel = _conditionalFormattingViewModel, this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel, this._initViewModelInterceptor(), this._initSkeleton(), this._initVmEffectByRule();
|
|
6974
6951
|
}
|
|
6975
6952
|
_initSkeleton() {
|
|
6976
6953
|
const markDirtySkeleton = /* @__PURE__ */ __name(() => {
|
|
@@ -6995,6 +6972,65 @@ let SheetsCfRenderController = (_a4 = class extends Disposable {
|
|
|
6995
6972
|
return worksheet ? v.filter((item2) => item2.unitId === workbook.getUnitId() && item2.subUnitId === worksheet.getSheetId()).length > 0 : !1;
|
|
6996
6973
|
})).subscribe(markDirtySkeleton));
|
|
6997
6974
|
}
|
|
6975
|
+
_initVmEffectByRule() {
|
|
6976
|
+
this.disposeWithMe(
|
|
6977
|
+
this._conditionalFormattingRuleModel.$ruleChange.subscribe((config) => {
|
|
6978
|
+
const { rule, unitId, subUnitId } = config;
|
|
6979
|
+
switch (config.type) {
|
|
6980
|
+
case "add": {
|
|
6981
|
+
const cfPriorityMap = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId).map((item2) => item2.cfId).reduce((map, cur, index2) => (map.set(cur, index2), map), /* @__PURE__ */ new Map());
|
|
6982
|
+
rule.ranges.forEach((range) => {
|
|
6983
|
+
Range.foreach(range, (row, col) => {
|
|
6984
|
+
this._conditionalFormattingViewModel.pushCellCf(unitId, subUnitId, row, col, rule.cfId), this._conditionalFormattingViewModel.sortCellCf(unitId, subUnitId, row, col, cfPriorityMap);
|
|
6985
|
+
});
|
|
6986
|
+
}), this._conditionalFormattingViewModel.markRuleDirty(unitId, subUnitId, rule);
|
|
6987
|
+
return;
|
|
6988
|
+
}
|
|
6989
|
+
case "delete": {
|
|
6990
|
+
rule.ranges.forEach((range) => {
|
|
6991
|
+
Range.foreach(range, (row, col) => {
|
|
6992
|
+
this._conditionalFormattingViewModel.deleteCellCf(unitId, subUnitId, row, col, rule.cfId);
|
|
6993
|
+
});
|
|
6994
|
+
}), this._conditionalFormattingViewModel.markRuleDirty(unitId, subUnitId, rule);
|
|
6995
|
+
return;
|
|
6996
|
+
}
|
|
6997
|
+
case "set": {
|
|
6998
|
+
const oldRule = config.oldRule, cfPriorityMap = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId).map((item2) => item2.cfId).reduce((map, cur, index2) => (map.set(cur, index2), map), /* @__PURE__ */ new Map()), dispose = this._conditionalFormattingService.interceptorManager.intercept(this._conditionalFormattingService.interceptorManager.getInterceptPoints().beforeUpdateRuleResult, {
|
|
6999
|
+
handler: /* @__PURE__ */ __name((config2, _, next) => {
|
|
7000
|
+
if (unitId === (config2 == null ? void 0 : config2.unitId) && subUnitId === config2.subUnitId && oldRule.cfId === config2.cfId) {
|
|
7001
|
+
oldRule.ranges.forEach((range) => {
|
|
7002
|
+
Range.foreach(range, (row, col) => {
|
|
7003
|
+
this._conditionalFormattingViewModel.deleteCellCf(unitId, subUnitId, row, col, oldRule.cfId);
|
|
7004
|
+
});
|
|
7005
|
+
}), rule.ranges.forEach((range) => {
|
|
7006
|
+
Range.foreach(range, (row, col) => {
|
|
7007
|
+
this._conditionalFormattingViewModel.pushCellCf(unitId, subUnitId, row, col, oldRule.cfId), this._conditionalFormattingViewModel.sortCellCf(unitId, subUnitId, row, col, cfPriorityMap);
|
|
7008
|
+
});
|
|
7009
|
+
}), dispose();
|
|
7010
|
+
return;
|
|
7011
|
+
}
|
|
7012
|
+
next(config2);
|
|
7013
|
+
}, "handler")
|
|
7014
|
+
});
|
|
7015
|
+
rule.ranges.forEach((range) => {
|
|
7016
|
+
Range.foreach(range, (row, col) => {
|
|
7017
|
+
this._conditionalFormattingViewModel.pushCellCf(unitId, subUnitId, row, col, oldRule.cfId);
|
|
7018
|
+
});
|
|
7019
|
+
}), this._conditionalFormattingViewModel.markRuleDirty(unitId, subUnitId, rule);
|
|
7020
|
+
return;
|
|
7021
|
+
}
|
|
7022
|
+
case "sort": {
|
|
7023
|
+
const cfPriorityMap = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId).map((item2) => item2.cfId).reduce((map, cur, index2) => (map.set(cur, index2), map), /* @__PURE__ */ new Map());
|
|
7024
|
+
rule.ranges.forEach((range) => {
|
|
7025
|
+
Range.foreach(range, (row, col) => {
|
|
7026
|
+
this._conditionalFormattingViewModel.sortCellCf(unitId, subUnitId, row, col, cfPriorityMap);
|
|
7027
|
+
});
|
|
7028
|
+
});
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
})
|
|
7032
|
+
);
|
|
7033
|
+
}
|
|
6998
7034
|
_initViewModelInterceptor() {
|
|
6999
7035
|
this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
7000
7036
|
handler: /* @__PURE__ */ __name((cell, context, next) => {
|
|
@@ -7009,7 +7045,7 @@ let SheetsCfRenderController = (_a4 = class extends Disposable {
|
|
|
7009
7045
|
}
|
|
7010
7046
|
}, __name(_a4, "SheetsCfRenderController"), _a4);
|
|
7011
7047
|
SheetsCfRenderController = __decorateClass$8([
|
|
7012
|
-
OnLifecycle(LifecycleStages.
|
|
7048
|
+
OnLifecycle(LifecycleStages.Starting, SheetsCfRenderController),
|
|
7013
7049
|
__decorateParam$8(0, Inject(SheetInterceptorService)),
|
|
7014
7050
|
__decorateParam$8(1, Inject(ConditionalFormattingService)),
|
|
7015
7051
|
__decorateParam$8(2, Inject(IUniverInstanceService)),
|
|
@@ -7517,36 +7553,25 @@ let ConditionalFormattingClearController = (_a11 = class extends Disposable {
|
|
|
7517
7553
|
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet = workbook.getActiveSheet();
|
|
7518
7554
|
if (!worksheet)
|
|
7519
7555
|
return defaultV;
|
|
7520
|
-
const
|
|
7556
|
+
const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId(), allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);
|
|
7521
7557
|
if (!allRules || !allRules.length)
|
|
7522
7558
|
return defaultV;
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
if (mergeRanges.length) {
|
|
7526
|
-
const redo = {
|
|
7527
|
-
id: SetConditionalRuleMutation.id,
|
|
7528
|
-
params: {
|
|
7529
|
-
unitId: workbook.getUnitId(),
|
|
7530
|
-
subUnitId: worksheet.getSheetId(),
|
|
7531
|
-
rule: { ...rule, ranges: mergeRanges }
|
|
7532
|
-
}
|
|
7533
|
-
}, undo = setConditionalRuleMutationUndoFactory(this._injector, redo.params);
|
|
7534
|
-
redos.push(redo), undos.push(...undo);
|
|
7535
|
-
} else {
|
|
7536
|
-
const redo = {
|
|
7537
|
-
id: DeleteConditionalRuleMutation.id,
|
|
7538
|
-
params: {
|
|
7539
|
-
unitId: workbook.getUnitId(),
|
|
7540
|
-
subUnitId: worksheet.getSheetId(),
|
|
7541
|
-
cfId: rule.cfId
|
|
7542
|
-
}
|
|
7543
|
-
}, undo = DeleteConditionalRuleMutationUndoFactory(this._injector, redo.params);
|
|
7544
|
-
redos.push(redo), undos.push(...undo);
|
|
7545
|
-
}
|
|
7546
|
-
});
|
|
7559
|
+
const { redos: interceptRedos, undos: interceptUndos } = generateClearCfMutations(this._injector, allRules, ranges, unitId, subUnitId);
|
|
7560
|
+
redos.push(...interceptRedos), undos.push(...interceptUndos);
|
|
7547
7561
|
}
|
|
7548
7562
|
return defaultV;
|
|
7549
7563
|
}, "getMutations")
|
|
7564
|
+
})), this.disposeWithMe(this._sheetInterceptorService.interceptRanges({
|
|
7565
|
+
getMutations: /* @__PURE__ */ __name(({ unitId, subUnitId, ranges }) => {
|
|
7566
|
+
const redos = [], undos = [], emptyInterceptorArr = { redos, undos };
|
|
7567
|
+
if (!ranges || !ranges.length)
|
|
7568
|
+
return emptyInterceptorArr;
|
|
7569
|
+
const allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);
|
|
7570
|
+
if (!allRules || !allRules.length)
|
|
7571
|
+
return emptyInterceptorArr;
|
|
7572
|
+
const { redos: interceptRedos, undos: interceptUndos } = generateClearCfMutations(this._injector, allRules, ranges, unitId, subUnitId);
|
|
7573
|
+
return redos.push(...interceptRedos), undos.push(...interceptUndos), emptyInterceptorArr;
|
|
7574
|
+
}, "getMutations")
|
|
7550
7575
|
}));
|
|
7551
7576
|
}
|
|
7552
7577
|
}, __name(_a11, "ConditionalFormattingClearController"), _a11);
|
|
@@ -7558,6 +7583,34 @@ ConditionalFormattingClearController = __decorateClass$1([
|
|
|
7558
7583
|
__decorateParam$1(3, Inject(SheetsSelectionsService)),
|
|
7559
7584
|
__decorateParam$1(4, Inject(ConditionalFormattingRuleModel))
|
|
7560
7585
|
], ConditionalFormattingClearController);
|
|
7586
|
+
function generateClearCfMutations(injector, allRules, ranges, unitId, subUnitId) {
|
|
7587
|
+
const redos = [], undos = [];
|
|
7588
|
+
return allRules.filter((rule) => ranges.some((range) => rule.ranges.some((ruleRange2) => Rectangle.getIntersects(ruleRange2, range)))).forEach((rule) => {
|
|
7589
|
+
const mergeRanges = new RangeMergeUtil().add(...rule.ranges).subtract(...ranges).merge();
|
|
7590
|
+
if (mergeRanges.length) {
|
|
7591
|
+
const redo = {
|
|
7592
|
+
id: SetConditionalRuleMutation.id,
|
|
7593
|
+
params: {
|
|
7594
|
+
unitId,
|
|
7595
|
+
subUnitId,
|
|
7596
|
+
rule: { ...rule, ranges: mergeRanges }
|
|
7597
|
+
}
|
|
7598
|
+
}, undo = setConditionalRuleMutationUndoFactory(injector, redo.params);
|
|
7599
|
+
redos.push(redo), undos.push(...undo);
|
|
7600
|
+
} else {
|
|
7601
|
+
const redo = {
|
|
7602
|
+
id: DeleteConditionalRuleMutation.id,
|
|
7603
|
+
params: {
|
|
7604
|
+
unitId,
|
|
7605
|
+
subUnitId,
|
|
7606
|
+
cfId: rule.cfId
|
|
7607
|
+
}
|
|
7608
|
+
}, undo = DeleteConditionalRuleMutationUndoFactory(injector, redo.params);
|
|
7609
|
+
redos.push(redo), undos.push(...undo);
|
|
7610
|
+
}
|
|
7611
|
+
}), { redos, undos };
|
|
7612
|
+
}
|
|
7613
|
+
__name(generateClearCfMutations, "generateClearCfMutations");
|
|
7561
7614
|
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
7562
7615
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7563
7616
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Disposable, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { Disposable, Injector, IUniverInstanceService, IMutationInfo, IRange } from '@univerjs/core';
|
|
2
2
|
import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
|
|
3
|
-
import { ConditionalFormattingRuleModel } from '@univerjs/sheets-conditional-formatting';
|
|
3
|
+
import { ConditionalFormattingRuleModel, IConditionalFormattingRuleConfig, IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
|
|
4
4
|
|
|
5
5
|
export declare class ConditionalFormattingClearController extends Disposable {
|
|
6
6
|
private _injector;
|
|
@@ -11,3 +11,7 @@ export declare class ConditionalFormattingClearController extends Disposable {
|
|
|
11
11
|
constructor(_injector: Injector, _univerInstanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _selectionManagerService: SheetsSelectionsService, _conditionalFormattingRuleModel: ConditionalFormattingRuleModel);
|
|
12
12
|
private _init;
|
|
13
13
|
}
|
|
14
|
+
export declare function generateClearCfMutations(injector: Injector, allRules: IConditionFormattingRule<IConditionalFormattingRuleConfig>[], ranges: IRange[], unitId: string, subUnitId: string): {
|
|
15
|
+
redos: IMutationInfo<object>[];
|
|
16
|
+
undos: IMutationInfo<object>[];
|
|
17
|
+
};
|
|
@@ -12,5 +12,6 @@ export declare class SheetsCfRenderController extends Disposable {
|
|
|
12
12
|
private _conditionalFormattingRuleModel;
|
|
13
13
|
constructor(_sheetInterceptorService: SheetInterceptorService, _conditionalFormattingService: ConditionalFormattingService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _conditionalFormattingViewModel: ConditionalFormattingViewModel, _conditionalFormattingRuleModel: ConditionalFormattingRuleModel);
|
|
14
14
|
private _initSkeleton;
|
|
15
|
+
private _initVmEffectByRule;
|
|
15
16
|
private _initViewModelInterceptor;
|
|
16
17
|
}
|