-
-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sheet): support range theme style
- Loading branch information
1 parent
ca69841
commit a77fb5b
Showing
11 changed files
with
626 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/sheets/src/commands/commands/add-worksheet-range-theme.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { IAccessor, ICommand } from '@univerjs/core'; | ||
|
||
import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface'; | ||
import { | ||
CommandType, | ||
ICommandService, | ||
IUndoRedoService, | ||
} from '@univerjs/core'; | ||
import { SetWorksheetRangeThemeStyleMutation, SetWorksheetRangeThemeStyleMutationFactory } from '../mutations/add-worksheet-range-theme.mutation'; | ||
import { DeleteWorksheetRangeThemeStyleMutation } from '../mutations/delete-worksheet-range-theme.mutation'; | ||
|
||
export const SetWorksheetRangeThemeStyleCommand: ICommand = { | ||
type: CommandType.COMMAND, | ||
id: 'sheet.command.set-worksheet-range-theme-style', | ||
handler: (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => { | ||
const commandService = accessor.get(ICommandService); | ||
const undoRedoService = accessor.get(IUndoRedoService); | ||
|
||
const { unitId } = params; | ||
|
||
const undoMutationParams = SetWorksheetRangeThemeStyleMutationFactory(accessor, params); | ||
|
||
const result = commandService.syncExecuteCommand(SetWorksheetRangeThemeStyleMutation.id, params); | ||
|
||
if (result) { | ||
undoRedoService.pushUndoRedo({ | ||
unitID: unitId, | ||
undoMutations: [{ id: DeleteWorksheetRangeThemeStyleMutation.id, params: undoMutationParams }], | ||
redoMutations: [{ id: SetWorksheetRangeThemeStyleMutation.id, params }], | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
}; |
69 changes: 69 additions & 0 deletions
69
packages/sheets/src/commands/commands/delete-worksheet-range-theme.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { IAccessor, ICommand } from '@univerjs/core'; | ||
|
||
import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface'; | ||
import { | ||
CommandType, | ||
ICommandService, | ||
IUndoRedoService, | ||
} from '@univerjs/core'; | ||
import { SetWorksheetRangeThemeStyleMutation } from '../mutations/add-worksheet-range-theme.mutation'; | ||
import { DeleteWorksheetRangeThemeStyleMutation, DeleteWorksheetRangeThemeStyleMutationFactory } from '../mutations/delete-worksheet-range-theme.mutation'; | ||
|
||
export const DeleteWorksheetRangeThemeStyleCommand: ICommand = { | ||
type: CommandType.COMMAND, | ||
id: 'sheet.command.remove-worksheet-range-theme-style', | ||
handler: (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => { | ||
const commandService = accessor.get(ICommandService); | ||
const undoRedoService = accessor.get(IUndoRedoService); | ||
|
||
const { unitId } = params; | ||
|
||
const undoMutationParams = DeleteWorksheetRangeThemeStyleMutationFactory(accessor, params); | ||
|
||
const result = commandService.syncExecuteCommand(DeleteWorksheetRangeThemeStyleMutation.id, params); | ||
|
||
if (result) { | ||
undoRedoService.pushUndoRedo({ | ||
unitID: unitId, | ||
undoMutations: [{ id: SetWorksheetRangeThemeStyleMutation.id, params: undoMutationParams }], | ||
redoMutations: [{ id: DeleteWorksheetRangeThemeStyleMutation.id, params }], | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { IAccessor, IMutation } from '@univerjs/core'; | ||
import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface'; | ||
import { CommandType, IUniverInstanceService } from '@univerjs/core'; | ||
import { SheetRangeThemeModel } from '../../model/range-theme-model'; | ||
import { getSheetCommandTarget, getSheetMutationTarget } from '../commands/utils/target-util'; | ||
|
||
export const SetWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeThemeStyleMutationParams> = { | ||
id: 'sheet.mutation.set-worksheet-range-theme-style', | ||
type: CommandType.MUTATION, | ||
handler: (accessor, params) => { | ||
const { unitId, subUnitId, range, themeName } = params; | ||
const univerInstanceService = accessor.get(IUniverInstanceService); | ||
const target = getSheetCommandTarget(univerInstanceService); | ||
const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel); | ||
if (!target) return false; | ||
|
||
const { worksheet } = target; | ||
if (!worksheet) { | ||
return false; | ||
} | ||
sheetRangeThemeModel.registerRangeThemeRule(themeName, { range, unitId, subUnitId }); | ||
return true; | ||
}, | ||
}; | ||
|
||
export const SetWorksheetRangeThemeStyleMutationFactory = (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => { | ||
const target = getSheetMutationTarget(accessor.get(IUniverInstanceService), params); | ||
if (!target) { | ||
throw new Error('[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!'); | ||
} | ||
|
||
const { worksheet } = target; | ||
return { | ||
unitId: params.unitId, | ||
subUnitId: worksheet.getSheetId(), | ||
range: params.range, | ||
themeName: params.themeName, | ||
}; | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { IAccessor, IMutation } from '@univerjs/core'; | ||
import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface'; | ||
import { CommandType, IUniverInstanceService } from '@univerjs/core'; | ||
import { SheetRangeThemeModel } from '../../model/range-theme-model'; | ||
import { getSheetCommandTarget, getSheetMutationTarget } from '../commands/utils/target-util'; | ||
|
||
export const DeleteWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeThemeStyleMutationParams> = { | ||
id: 'sheet.mutation.remove-worksheet-range-theme-style', | ||
type: CommandType.MUTATION, | ||
handler: (accessor, params) => { | ||
const { unitId, subUnitId, range, themeName } = params; | ||
const univerInstanceService = accessor.get(IUniverInstanceService); | ||
const target = getSheetCommandTarget(univerInstanceService); | ||
const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel); | ||
if (!target) return false; | ||
|
||
const { worksheet } = target; | ||
if (!worksheet) { | ||
return false; | ||
} | ||
sheetRangeThemeModel.removeRangeThemeRule(themeName, { range, unitId, subUnitId }); | ||
return true; | ||
}, | ||
}; | ||
|
||
export const DeleteWorksheetRangeThemeStyleMutationFactory = (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => { | ||
const target = getSheetMutationTarget(accessor.get(IUniverInstanceService), params); | ||
if (!target) { | ||
throw new Error('[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!'); | ||
} | ||
|
||
const { worksheet } = target; | ||
return { | ||
unitId: params.unitId, | ||
subUnitId: worksheet.getSheetId(), | ||
range: params.range, | ||
themeName: params.themeName, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.