Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(sheets): add protectedRangeShadowStrategy for protection range (#6102)
WEI ZHANGdf08fc05cb10
diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.tsindex 37fdad0cf3..8bc9eed908 100644--- a/packages/sheets-ui/src/controllers/config.schema.ts+++ b/packages/sheets-ui/src/controllers/config.schema.ts@@ -79,10 +79,14 @@ export interface IUniverSheetsUIConfig {scrollConfig?: IScrollBarProps;/**- * Whether to show the protected range shadow.+ * Strategy for showing the protected range shadow.+ * - true or 'always': Show shadow for all protected ranges (default behavior)+ * - 'non-editable': Only show shadow for ranges that cannot be edited (Edit permission is false)+ * - 'non-viewable': Only show shadow for ranges that cannot be viewed (View permission is false)+ * - false or 'none': Never show shadow for protected ranges* @default true*/- protectedRangeShadow?: boolean;+ protectedRangeShadow?: boolean | 'always' | 'non-editable' | 'non-viewable' | 'none';/*** The custom component of the protected range user selector.@@ -116,3 +120,19 @@ export const defaultPluginConfig: IUniverSheetsUIConfig = {protectedRangeShadow: true,maxAutoHeightCount: 1000,};++/**+ * Convert the protectedRangeShadow config to shadow strategy+ * - true -> 'always'+ * - false -> 'none'+ * - string values remain unchanged+ * @param config The protectedRangeShadow config value+ * @returns The shadow strategy+ */+export function convertToShadowStrategy(+ config?: boolean | 'always' | 'non-editable' | 'non-viewable' | 'none'+): 'always' | 'non-editable' | 'non-viewable' | 'none' {+ if (config === true) return 'always';+ if (config === false) return 'none';+ return config || 'always';+}diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.tsindex 888d263838..35065c1657 100644--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts@@ -40,7 +40,7 @@ import { AlertDialog } from '../../views/permission/error-msg-dialog';import { UNIVER_SHEET_PERMISSION_ALERT_DIALOG } from '../../views/permission/error-msg-dialog/interface';import { RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY, RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY, RangeProtectionCanNotViewRenderExtension, RangeProtectionCanViewRenderExtension } from '../../views/permission/extensions/range-protection.render';import { worksheetProtectionKey, WorksheetProtectionRenderExtension } from '../../views/permission/extensions/worksheet-permission.render';-import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config.schema';+import { convertToShadowStrategy, SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config.schema';export interface IUniverSheetsPermissionMenuConfig {menu: MenuConfig;@@ -95,8 +95,8 @@ export class SheetPermissionRenderManagerController extends Disposable {}export class SheetPermissionRenderController extends Disposable implements IRenderModule {- private _rangeProtectionCanViewRenderExtension = new RangeProtectionCanViewRenderExtension();- private _rangeProtectionCanNotViewRenderExtension = new RangeProtectionCanNotViewRenderExtension();+ private _rangeProtectionCanViewRenderExtension: RangeProtectionCanViewRenderExtension;+ private _rangeProtectionCanNotViewRenderExtension: RangeProtectionCanNotViewRenderExtension;constructor(private readonly _context: IRenderContext,@@ -108,10 +108,15 @@ export class SheetPermissionRenderController extends Disposable implements IRendsuper();const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);++ // Get shadow strategy from config, default to 'always'+ const shadowStrategy = convertToShadowStrategy(config?.protectedRangeShadow);++ // Create render extensions with the shadow strategy+ this._rangeProtectionCanViewRenderExtension = new RangeProtectionCanViewRenderExtension(shadowStrategy);+ this._rangeProtectionCanNotViewRenderExtension = new RangeProtectionCanNotViewRenderExtension(shadowStrategy);+this._initSkeleton();- if (config?.protectedRangeShadow === false) {- return;- }this._initRender();this.disposeWithMe(this._rangeProtectionRuleModel.ruleChange$.subscribe((info) => {@@ -151,7 +156,8 @@ export class SheetPermissionRenderController extends Disposable implements IRend}export class WorksheetProtectionRenderController extends Disposable implements IRenderModule {- private _worksheetProtectionRenderExtension = new WorksheetProtectionRenderExtension();+ private _worksheetProtectionRenderExtension: WorksheetProtectionRenderExtension;+constructor(private readonly _context: IRenderContext,@Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,@@ -162,8 +168,15 @@ export class WorksheetProtectionRenderController extends Disposable implements Isuper();const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);++ // Get shadow strategy from config, default to 'always'+ const shadowStrategy = convertToShadowStrategy(config?.protectedRangeShadow);++ // Create render extension with the shadow strategy+ this._worksheetProtectionRenderExtension = new WorksheetProtectionRenderExtension(shadowStrategy);+this._initSkeleton();- if (config?.protectedRangeShadow === false) {+ if (shadowStrategy === 'none') {return;}diff --git a/packages/sheets-ui/src/facade/f-univer.ts b/packages/sheets-ui/src/facade/f-univer.tsindex 398bd75152..86232dcba0 100644--- a/packages/sheets-ui/src/facade/f-univer.ts+++ b/packages/sheets-ui/src/facade/f-univer.ts@@ -29,13 +29,14 @@ import type {import type { CommandListenerSkeletonChange } from '@univerjs/sheets';import type { IEditorBridgeServiceVisibleParam, ISetZoomRatioCommandParams, ISheetPasteByShortKeyParams, IViewportScrollState } from '@univerjs/sheets-ui';import type { FRange } from '@univerjs/sheets/facade';+import type { Observable } from 'rxjs';import type { IBeforeClipboardChangeParam, IBeforeClipboardPasteParam, IBeforeSheetEditEndEventParams, IBeforeSheetEditStartEventParams, ISheetEditChangingEventParams, ISheetEditEndedEventParams, ISheetEditStartedEventParams, ISheetZoomEvent } from './f-event';import { CanceledError, DisposableCollection, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, ILogService, IUniverInstanceService, LifecycleService, LifecycleStages, RichTextValue, toDisposable, UniverInstanceType } from '@univerjs/core';import { FUniver } from '@univerjs/core/facade';import { RichTextEditingMutation } from '@univerjs/docs';import { IRenderManagerService } from '@univerjs/engine-render';import { COMMAND_LISTENER_SKELETON_CHANGE, getSkeletonChangedEffectedRange, SheetsSelectionsService } from '@univerjs/sheets';-import { DragManagerService, HoverManagerService, IEditorBridgeService, ISheetClipboardService, SetCellEditVisibleOperation, SetZoomRatioCommand, SHEET_VIEW_KEY, SheetPasteShortKeyCommand, SheetScrollManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import { DragManagerService, HoverManagerService, IEditorBridgeService, ISheetClipboardService, SetCellEditVisibleOperation, SetZoomRatioCommand, SHEET_VIEW_KEY, SheetPasteShortKeyCommand, SheetPermissionRenderManagerService, SheetScrollManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { FSheetHooks } from '@univerjs/sheets/facade';import { CopyCommand, CutCommand, HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, KeyCode, PasteCommand, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, supportClipboardAPI } from '@univerjs/ui';import { combineLatest, filter } from 'rxjs';@@ -104,6 +105,59 @@ export interface IFUniverSheetsUIMixin {* ```*/pasteIntoSheet(htmlContent?: string, textContent?: string, files?: File[]): Promise<boolean>;++ /**+ * Set the global strategy for showing the protected range shadow.+ * This will apply to all workbooks in the current Univer instance.+ * @param {('always' | 'non-editable' | 'non-viewable' | 'none')} strategy - The shadow strategy to apply+ * - 'always': Show shadow for all protected ranges+ * - 'non-editable': Only show shadow for ranges that cannot be edited+ * - 'non-viewable': Only show shadow for ranges that cannot be viewed+ * - 'none': Never show shadow for protected ranges+ * @example+ * ```typescript+ * // Always show shadows (default)+ * univerAPI.setProtectedRangeShadowStrategy('always');+ *+ * // Only show shadows for non-editable ranges+ * univerAPI.setProtectedRangeShadowStrategy('non-editable');+ *+ * // Only show shadows for non-viewable ranges+ * univerAPI.setProtectedRangeShadowStrategy('non-viewable');+ *+ * // Never show shadows+ * univerAPI.setProtectedRangeShadowStrategy('none');+ * ```+ */+ setProtectedRangeShadowStrategy(strategy: 'always' | 'non-editable' | 'non-viewable' | 'none'): void;++ /**+ * Get the current global strategy for showing the protected range shadow.+ * @returns {('always' | 'non-editable' | 'non-viewable' | 'none')} The current shadow strategy+ * @example+ * ```typescript+ * const currentStrategy = univerAPI.getProtectedRangeShadowStrategy();+ * console.log(currentStrategy); // 'none', 'always', 'non-editable', or 'non-viewable'+ * ```+ */+ getProtectedRangeShadowStrategy(): 'always' | 'non-editable' | 'non-viewable' | 'none';++ /**+ * Get an observable of the global strategy for showing the protected range shadow.+ * This allows you to listen for strategy changes across all workbooks.+ * @returns {Observable<('always' | 'non-editable' | 'non-viewable' | 'none')>} An observable that emits the current shadow strategy+ * @example+ * ```typescript+ * const subscription = univerAPI.getProtectedRangeShadowStrategy$().subscribe((strategy) => {+ * console.log('Global strategy changed to:', strategy);+ * // Update UI or perform other actions+ * });+ *+ * // Later, unsubscribe to clean up+ * subscription.unsubscribe();+ * ```+ */+ getProtectedRangeShadowStrategy$(): Observable<'always' | 'non-editable' | 'non-viewable' | 'none'>;}export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixin {@@ -982,6 +1036,21 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixoverride pasteIntoSheet(htmlContent?: string, textContent?: string, files?: File[]): Promise<boolean> {return this._commandService.executeCommand(SheetPasteShortKeyCommand.id, { htmlContent, textContent, files });}++ override setProtectedRangeShadowStrategy(strategy: 'always' | 'non-editable' | 'non-viewable' | 'none'): void {+ const service = this._injector.get(SheetPermissionRenderManagerService);+ service.setProtectedRangeShadowStrategy(strategy);+ }++ override getProtectedRangeShadowStrategy(): 'always' | 'non-editable' | 'non-viewable' | 'none' {+ const service = this._injector.get(SheetPermissionRenderManagerService);+ return service.getProtectedRangeShadowStrategy();+ }++ override getProtectedRangeShadowStrategy$(): Observable<'always' | 'non-editable' | 'non-viewable' | 'none'> {+ const service = this._injector.get(SheetPermissionRenderManagerService);+ return service.getProtectedRangeShadowStrategy$();+ }}FUniver.extend(FUniverSheetsUIMixin);diff --git a/packages/sheets-ui/src/facade/f-workbook.ts b/packages/sheets-ui/src/facade/f-workbook.tsindex 3a362858c9..9d5fa971ef 100644--- a/packages/sheets-ui/src/facade/f-workbook.ts+++ b/packages/sheets-ui/src/facade/f-workbook.ts@@ -295,6 +295,7 @@ export interface IFWorkbookSheetsUIMixin {* ```*/showSelection(): FWorkbook;+}export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetsUIMixin {diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.tsindex b437816878..883d4d0374 100644--- a/packages/sheets-ui/src/index.ts+++ b/packages/sheets-ui/src/index.ts@@ -145,6 +145,7 @@ export type { IFormatPainterBeforeApplyHookParams, IFormatPainterHook } from './export { HoverManagerService } from './services/hover-manager.service';export type { ICellPosWithEvent, IHoverCellPosition, IHoverRichTextInfo, IHoverRichTextPosition } from './services/hover-manager.service';export { IMarkSelectionService, MarkSelectionService } from './services/mark-selection/mark-selection.service';+export { type ProtectedRangeShadowStrategy, SheetPermissionRenderManagerService } from './services/permission/sheet-permission-render-manager.service';export { SheetPermissionUserManagerService } from './services/permission/sheet-permission-user-list.service';export { SheetPrintInterceptorService } from './services/print-interceptor.service';export { SheetScrollManagerService } from './services/scroll-manager.service';diff --git a/packages/sheets-ui/src/plugin.ts b/packages/sheets-ui/src/plugin.tsindex d92dd3991f..199bc16316 100644--- a/packages/sheets-ui/src/plugin.ts+++ b/packages/sheets-ui/src/plugin.ts@@ -83,6 +83,7 @@ import { FormatPainterService, IFormatPainterService } from './services/format-pimport { HoverManagerService } from './services/hover-manager.service';import { IMarkSelectionService, MarkSelectionService } from './services/mark-selection/mark-selection.service';import { SheetPermissionPanelModel } from './services/permission/sheet-permission-panel.model';+import { SheetPermissionRenderManagerService } from './services/permission/sheet-permission-render-manager.service';import { SheetPermissionUserManagerService } from './services/permission/sheet-permission-user-list.service';import { SheetPrintInterceptorService } from './services/print-interceptor.service';import { SheetScrollManagerService } from './services/scroll-manager.service';@@ -181,6 +182,7 @@ export class UniverSheetsUIPlugin extends Plugin {[SheetPermissionPanelModel],[SheetPermissionInitUIController],[SheetPermissionUserManagerService],+ [SheetPermissionRenderManagerService],[SheetPermissionInterceptorClipboardController],[SheetPermissionCheckUIController],[SheetPermissionRenderManagerController],diff --git a/packages/sheets-ui/src/services/permission/sheet-permission-render-manager.service.ts b/packages/sheets-ui/src/services/permission/sheet-permission-render-manager.service.tsnew file mode 100644index 0000000000..7b9bbeeba0--- /dev/null+++ b/packages/sheets-ui/src/services/permission/sheet-permission-render-manager.service.ts@@ -0,0 +1,143 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { Spreadsheet } from '@univerjs/engine-render';+import type { Observable } from 'rxjs';+import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';+import { Disposable, IConfigService } from '@univerjs/core';+import { IRenderManagerService } from '@univerjs/engine-render';+import { BehaviorSubject } from 'rxjs';+import { convertToShadowStrategy, SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';+import { RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY, RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY } from '../../views/permission/extensions/range-protection.render';+import { worksheetProtectionKey } from '../../views/permission/extensions/worksheet-permission.render';++export type ProtectedRangeShadowStrategy = 'always' | 'non-editable' | 'non-viewable' | 'none';++/**+ * Interface for extensions that support shadow strategy+ */+interface IExtensionWithShadowStrategy {+ setShadowStrategy: (strategy: ProtectedRangeShadowStrategy) => void;+}++/**+ * Type guard to check if an extension supports shadow strategy+ */+function hasSetShadowStrategy(extension: unknown): extension is IExtensionWithShadowStrategy {+ return typeof (extension as IExtensionWithShadowStrategy).setShadowStrategy === 'function';+}++export interface ISheetPermissionRenderManagerService {+ /**+ * Set the global shadow strategy for protected ranges+ * This will apply to all workbooks+ * @param strategy The shadow strategy+ */+ setProtectedRangeShadowStrategy(strategy: ProtectedRangeShadowStrategy): void;++ /**+ * Get the current global shadow strategy+ */+ getProtectedRangeShadowStrategy(): ProtectedRangeShadowStrategy;++ /**+ * Get an observable of the global shadow strategy+ */+ getProtectedRangeShadowStrategy$(): Observable<ProtectedRangeShadowStrategy>;+}++/**+ * Service to manage the rendering of sheet permissions (range protection shadows)+ * This is a global service that applies the strategy to all workbooks+ */+export class SheetPermissionRenderManagerService extends Disposable implements ISheetPermissionRenderManagerService {+ private _currentStrategy: ProtectedRangeShadowStrategy;+ private _strategySubject: BehaviorSubject<ProtectedRangeShadowStrategy>;++ constructor(+ @IConfigService private readonly _configService: IConfigService,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService+ ) {+ super();++ const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);+ this._currentStrategy = convertToShadowStrategy(config?.protectedRangeShadow);+ this._strategySubject = new BehaviorSubject<ProtectedRangeShadowStrategy>(this._currentStrategy);++ this.disposeWithMe({+ dispose: () => {+ this._strategySubject.complete();+ },+ });+ }++ private _updateAllWorkbooks(strategy: ProtectedRangeShadowStrategy): void {+ // Get all renders (workbooks)+ const renders = this._renderManagerService.getRenderAll();++ renders.forEach((render) => {+ const spreadsheet = render.mainComponent as Spreadsheet;+ if (!spreadsheet) {+ return;+ }++ // Update all protection render extensions+ const extensions = [+ { key: RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY },+ { key: RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY },+ { key: worksheetProtectionKey },+ ];++ let updated = false;+ for (const { key } of extensions) {+ const extension = spreadsheet.getExtensionByKey(key);+ if (extension && hasSetShadowStrategy(extension)) {+ extension.setShadowStrategy(strategy);+ updated = true;+ }+ }++ if (updated) {+ // Mark canvas as dirty to trigger re-render+ spreadsheet.makeDirty(true);+ }+ });+ }++ setProtectedRangeShadowStrategy(strategy: ProtectedRangeShadowStrategy): void {+ // Update the current strategy+ this._currentStrategy = strategy;++ // Emit the new strategy to observers+ this._strategySubject.next(strategy);++ // Update all workbooks+ this._updateAllWorkbooks(strategy);+ }++ getProtectedRangeShadowStrategy(): ProtectedRangeShadowStrategy {+ return this._currentStrategy;+ }++ getProtectedRangeShadowStrategy$(): Observable<ProtectedRangeShadowStrategy> {+ return this._strategySubject.asObservable();+ }++ override dispose(): void {+ super.dispose();+ this._strategySubject.complete();+ }+}diff --git a/packages/sheets-ui/src/views/permission/extensions/range-protection.render.ts b/packages/sheets-ui/src/views/permission/extensions/range-protection.render.tsindex d68095e8f0..e233aed415 100644--- a/packages/sheets-ui/src/views/permission/extensions/range-protection.render.ts+++ b/packages/sheets-ui/src/views/permission/extensions/range-protection.render.ts@@ -36,16 +36,36 @@ export abstract class RangeProtectionRenderExtension extends SheetExtension {protected _pattern: CanvasPattern | null = null;protected _img = new Image();public renderCache = new Set<string>();+ protected _shadowStrategy: 'always' | 'non-editable' | 'non-viewable' | 'none' = 'always';- constructor() {+ constructor(shadowStrategy?: 'always' | 'non-editable' | 'non-viewable' | 'none') {super();this._img.src = base64;+ if (shadowStrategy) {+ this._shadowStrategy = shadowStrategy;+ }}override clearCache(): void {this.renderCache.clear();}+ /**+ * Set the shadow strategy for this extension+ * @param strategy The shadow strategy+ */+ setShadowStrategy(strategy: 'always' | 'non-editable' | 'non-viewable' | 'none'): void {+ this._shadowStrategy = strategy;+ this.clearCache();+ }++ /**+ * Get the current shadow strategy+ */+ getShadowStrategy(): 'always' | 'non-editable' | 'non-viewable' | 'none' {+ return this._shadowStrategy;+ }+protected abstract shouldRender(config: ICellPermission): boolean;override draw(@@ -100,11 +120,24 @@ export class RangeProtectionCanViewRenderExtension extends RangeProtectionRenderoverride uKey = RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY;override Z_INDEX = EXTENSION_CAN_VIEW_Z_INDEX;- constructor() {- super();+ constructor(shadowStrategy?: 'always' | 'non-editable' | 'non-viewable' | 'none') {+ super(shadowStrategy);}protected override shouldRender(config: ICellPermission): boolean {+ // If strategy is 'none', never show shadow+ if (this._shadowStrategy === 'none') {+ return false;+ }+ // If strategy is 'non-editable', only show shadow when edit permission is false+ if (this._shadowStrategy === 'non-editable') {+ return config?.[UnitAction.View] !== false && config?.[UnitAction.Edit] === false;+ }+ // If strategy is 'non-viewable', only show shadow when view permission is false+ if (this._shadowStrategy === 'non-viewable') {+ return config?.[UnitAction.View] === false;+ }+ // Otherwise ('always'), keep the original behavior - show shadow for all protected rangesreturn config?.[UnitAction.View] !== false;}}@@ -113,11 +146,17 @@ export class RangeProtectionCanNotViewRenderExtension extends RangeProtectionRenoverride uKey = RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY;override Z_INDEX = EXTENSION_CAN_NOT_VIEW_Z_INDEX;- constructor() {- super();+ constructor(shadowStrategy?: 'always' | 'non-editable' | 'non-viewable' | 'none') {+ super(shadowStrategy);}protected override shouldRender(config: ICellPermission): boolean {+ // If strategy is 'none', never show shadow+ if (this._shadowStrategy === 'none') {+ return false;+ }+ // This extension always handles the non-viewable case (View permission is false)+ // regardless of the strategy (except 'none')return config?.[UnitAction.View] === false;}}diff --git a/packages/sheets-ui/src/views/permission/extensions/worksheet-permission.render.ts b/packages/sheets-ui/src/views/permission/extensions/worksheet-permission.render.tsindex de550171f3..d50adf8a39 100644--- a/packages/sheets-ui/src/views/permission/extensions/worksheet-permission.render.ts+++ b/packages/sheets-ui/src/views/permission/extensions/worksheet-permission.render.ts@@ -32,10 +32,14 @@ export class WorksheetProtectionRenderExtension extends SheetExtension {private _pattern: CanvasPattern | null;private _img = new Image();+ protected _shadowStrategy: 'always' | 'non-editable' | 'non-viewable' | 'none' = 'always';- constructor() {+ constructor(shadowStrategy?: 'always' | 'non-editable' | 'non-viewable' | 'none') {super();this._img.src = base64;+ if (shadowStrategy) {+ this._shadowStrategy = shadowStrategy;+ }}override draw(@@ -73,13 +77,48 @@ export class WorksheetProtectionRenderExtension extends SheetExtension {}ctx.fillStyle = this._pattern;- if (hasWorksheetRule) {++ // Apply shadow strategy for worksheet protection+ let shouldRenderShadow = hasWorksheetRule;++ // If strategy is 'none', never show shadow+ if (this._shadowStrategy === 'none') {+ shouldRenderShadow = false;+ } else if (hasWorksheetRule && selectionProtection.length > 0) {+ const cellProtectionConfig = selectionProtection[0];++ if (this._shadowStrategy === 'non-editable') {+ // Only show shadow if edit permission is false+ shouldRenderShadow = cellProtectionConfig?.[UnitAction.Edit] === false;+ } else if (this._shadowStrategy === 'non-viewable') {+ // Only show shadow if view permission is false+ shouldRenderShadow = cellProtectionConfig?.[UnitAction.View] === false;+ }+ // For 'always' strategy, shouldRenderShadow remains true (hasWorksheetRule)+ }++ if (shouldRenderShadow) {ctx.fillRect(start.startX, start.startY, end.endX - start.startX, end.endY - start.startY);}ctx.restore();}+ /**+ * Set the shadow strategy for this extension+ * @param strategy The shadow strategy+ */+ setShadowStrategy(strategy: 'always' | 'non-editable' | 'non-viewable' | 'none'): void {+ this._shadowStrategy = strategy;+ }++ /**+ * Get the current shadow strategy+ */+ getShadowStrategy(): 'always' | 'non-editable' | 'non-viewable' | 'none' {+ return this._shadowStrategy;+ }+setZIndex(zIndex: number) {this.Z_INDEX = zIndex;}