@univerjs/sheets-crosshair-highlight 0.20.0 → 0.20.1

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/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`rxjs`),n=require(`@univerjs/engine-render`),r=require(`@univerjs/icons`),i=require(`@univerjs/ui`),a=require(`@univerjs/design`),o=require(`react`),s=require(`react/jsx-runtime`),c=require(`@univerjs/sheets`),l=require(`@univerjs/sheets-ui`);function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const m=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var h=class extends e.Disposable{constructor(...e){super(...e),p(this,`_enabled$`,new t.BehaviorSubject(!1)),p(this,`enabled$`,this._enabled$.asObservable()),p(this,`_color$`,new t.BehaviorSubject(m[0])),p(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const g={id:`sheet.operation.toggle-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h),n=t.enabled;return t.setEnabled(!n),!0}},_={id:`sheet.operation.set-crosshair-highlight-color`,type:e.CommandType.OPERATION,handler(e,{value:t}){let n=e.get(h);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},v={id:`sheet.operation.enable-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?!1:(t.setEnabled(!0),!0)}},y={id:`sheet.operation.disable-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?(t.setEnabled(!1),!0):!1}};var b=`@univerjs/sheets-crosshair-highlight`,x=`0.20.0`;const S=`sheets-crosshair-highlight.config`;Symbol(S);const C={},w=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function T(t){let n=t.get(h);return{id:g.id,tooltip:`crosshair.button.tooltip`,type:i.MenuItemType.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:w,hoverable:!1,selectable:!1}}],selectionsCommandId:_.id,activated$:n.enabled$,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET)}}const E={[i.ContextMenuPosition.FOOTER_MENU]:{[i.ContextMenuGroup.OTHERS]:{[g.id]:{order:0,menuItemFactory:T}}}};function D(e){let{onChange:t}=e,n=(0,i.useObservable)((0,i.useDependency)(h).color$),r=(0,o.useCallback)(e=>{t==null||t(e)},[t]);return(0,s.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:m.map(e=>(0,s.jsx)(`div`,{className:(0,a.clsx)(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,a.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends e.Disposable{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[g,_,v,y].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(E)}_initComponents(){this._componentMgr.register(w,D),this._componentMgr.register(`CrossHighlightingIcon`,r.CrossHighlightingIcon)}};A=k([O(0,(0,e.Inject)(i.ComponentManager)),O(1,i.IMenuManagerService),O(2,e.ICommandService)],A);var j=class{constructor(){p(this,`_selectedRanges`,[]),p(this,`_ranges`,[])}addRange(t){if(t.rangeType===e.RANGE_TYPE.COLUMN||t.rangeType===e.RANGE_TYPE.ROW||t.rangeType===e.RANGE_TYPE.ALL)return;let n=this._getIntersects(t),r=this._getSplitRanges(t,n);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(t,n){let r=[t];for(let t of n.concat(this._selectedRanges)){let n=[];for(let i of r){let r=e.Rectangle.subtract(i,t);r&&r.length>0&&n.push(...r)}r=n}return r.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(t){let n=[];for(let r of this._ranges){let i=e.Rectangle.getIntersects(r,t);i&&n.push(i)}return n}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},M=class extends n.Shape{constructor(e,t){super(e,t),p(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,r;let i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(r=this._color)==null?void 0:r.a)==null?.5:t})`;n.Rect.drawWith(e,{width:this.width,height:this.height,fill:i,stroke:void 0,strokeWidth:0,evented:!1})}};let N=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,p(this,`_shapes`,[]),p(this,`_rangeCollection`,new j),p(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe((0,t.combineLatest)([this._contextService.subscribeContextValue$(c.REF_SELECTIONS_ENABLED).pipe((0,t.startWith)(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe((0,t.tap)(e=>this._color=e)),(0,t.merge)(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,t.map)(()=>this._sheetsSelectionsService.getCurrentSelections()))),(0,t.merge)(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,t.map)(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(t,n){if(t.rangeType===e.RANGE_TYPE.COLUMN||t.rangeType===e.RANGE_TYPE.ROW||t.rangeType===e.RANGE_TYPE.ALL)return;let r=n.getRowCount(),i=n.getColumnCount(),{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l={startRow:a,endRow:o,startColumn:0,endColumn:s-1},u={startRow:a,endRow:o,startColumn:c+1,endColumn:i},d={startRow:0,endRow:a-1,startColumn:s,endColumn:c},f={startRow:o+1,endRow:r,startColumn:s,endColumn:c};for(let e of[l,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,u=(0,l.getCoordByCell)(a,s,r,i),d=(0,l.getCoordByCell)(o,c,r,i),{startX:f,startY:p}=u,{endX:m,endY:h}=d,g=m-f,_=h-p,v={left:f,top:p,color:new e.ColorKit(this._color).toRgb(),width:g,height:_,zIndex:1,evented:!1},y=new M(`crosshair-${n}`,v);this._shapes.push(y),r.addObject(y)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};N=k([O(1,(0,e.Inject)(l.SheetSkeletonManagerService)),O(2,(0,e.Inject)(c.SheetsSelectionsService)),O(3,(0,e.Inject)(h)),O(4,(0,e.Inject)(e.IContextService)),O(5,c.IRefSelectionsService)],N);let P=class extends e.Plugin{constructor(t=C,n,r,i){super(),this._config=t,this._injector=n,this._renderManagerService=r,this._configService=i;let{...a}=(0,e.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){[[h],[A]].forEach(e=>this._injector.add(e))}onReady(){[[N]].forEach(e=>this._injector.add(e)),this._injector.get(A),this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,[N])}};p(P,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),p(P,`packageName`,b),p(P,`version`,x),p(P,`type`,e.UniverInstanceType.UNIVER_SHEET),P=k([O(1,(0,e.Inject)(e.Injector)),O(2,n.IRenderManagerService),O(3,e.IConfigService)],P),exports.CROSSHAIR_HIGHLIGHT_COLORS=m,exports.DisableCrosshairHighlightOperation=y,exports.EnableCrosshairHighlightOperation=v,exports.SetCrosshairHighlightColorOperation=_,exports.SheetsCrosshairHighlightService=h,exports.ToggleCrosshairHighlightOperation=g,Object.defineProperty(exports,`UniverSheetsCrosshairHighlightPlugin`,{enumerable:!0,get:function(){return P}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`rxjs`),n=require(`@univerjs/engine-render`),r=require(`@univerjs/icons`),i=require(`@univerjs/ui`),a=require(`@univerjs/design`),o=require(`react`),s=require(`react/jsx-runtime`),c=require(`@univerjs/sheets`),l=require(`@univerjs/sheets-ui`);function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const m=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var h=class extends e.Disposable{constructor(...e){super(...e),p(this,`_enabled$`,new t.BehaviorSubject(!1)),p(this,`enabled$`,this._enabled$.asObservable()),p(this,`_color$`,new t.BehaviorSubject(m[0])),p(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const g={id:`sheet.operation.toggle-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h),n=t.enabled;return t.setEnabled(!n),!0}},_={id:`sheet.operation.set-crosshair-highlight-color`,type:e.CommandType.OPERATION,handler(e,{value:t}){let n=e.get(h);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},v={id:`sheet.operation.enable-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?!1:(t.setEnabled(!0),!0)}},y={id:`sheet.operation.disable-crosshair-highlight`,type:e.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?(t.setEnabled(!1),!0):!1}};var b=`@univerjs/sheets-crosshair-highlight`,x=`0.20.1`;const S=`sheets-crosshair-highlight.config`;Symbol(S);const C={},w=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function T(t){let n=t.get(h);return{id:g.id,tooltip:`crosshair.button.tooltip`,type:i.MenuItemType.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:w,hoverable:!1,selectable:!1}}],selectionsCommandId:_.id,activated$:n.enabled$,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET)}}const E={[i.ContextMenuPosition.FOOTER_MENU]:{[i.ContextMenuGroup.OTHERS]:{[g.id]:{order:0,menuItemFactory:T}}}};function D(e){let{onChange:t}=e,n=(0,i.useObservable)((0,i.useDependency)(h).color$),r=(0,o.useCallback)(e=>{t==null||t(e)},[t]);return(0,s.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:m.map(e=>(0,s.jsx)(`div`,{className:(0,a.clsx)(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,a.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends e.Disposable{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[g,_,v,y].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(E)}_initComponents(){this._componentMgr.register(w,D),this._componentMgr.register(`CrossHighlightingIcon`,r.CrossHighlightingIcon)}};A=k([O(0,(0,e.Inject)(i.ComponentManager)),O(1,i.IMenuManagerService),O(2,e.ICommandService)],A);var j=class{constructor(){p(this,`_selectedRanges`,[]),p(this,`_ranges`,[])}addRange(t){if(t.rangeType===e.RANGE_TYPE.COLUMN||t.rangeType===e.RANGE_TYPE.ROW||t.rangeType===e.RANGE_TYPE.ALL)return;let n=this._getIntersects(t),r=this._getSplitRanges(t,n);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(t,n){let r=[t];for(let t of n.concat(this._selectedRanges)){let n=[];for(let i of r){let r=e.Rectangle.subtract(i,t);r&&r.length>0&&n.push(...r)}r=n}return r.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(t){let n=[];for(let r of this._ranges){let i=e.Rectangle.getIntersects(r,t);i&&n.push(i)}return n}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},M=class extends n.Shape{constructor(e,t){super(e,t),p(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,r;let i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(r=this._color)==null?void 0:r.a)==null?.5:t})`;n.Rect.drawWith(e,{width:this.width,height:this.height,fill:i,stroke:void 0,strokeWidth:0,evented:!1})}};let N=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,p(this,`_shapes`,[]),p(this,`_rangeCollection`,new j),p(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe((0,t.combineLatest)([this._contextService.subscribeContextValue$(c.REF_SELECTIONS_ENABLED).pipe((0,t.startWith)(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe((0,t.tap)(e=>this._color=e)),(0,t.merge)(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,t.map)(()=>this._sheetsSelectionsService.getCurrentSelections()))),(0,t.merge)(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,t.map)(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(t,n){if(t.rangeType===e.RANGE_TYPE.COLUMN||t.rangeType===e.RANGE_TYPE.ROW||t.rangeType===e.RANGE_TYPE.ALL)return;let r=n.getRowCount(),i=n.getColumnCount(),{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l={startRow:a,endRow:o,startColumn:0,endColumn:s-1},u={startRow:a,endRow:o,startColumn:c+1,endColumn:i},d={startRow:0,endRow:a-1,startColumn:s,endColumn:c},f={startRow:o+1,endRow:r,startColumn:s,endColumn:c};for(let e of[l,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,u=(0,l.getCoordByCell)(a,s,r,i),d=(0,l.getCoordByCell)(o,c,r,i),{startX:f,startY:p}=u,{endX:m,endY:h}=d,g=m-f,_=h-p,v={left:f,top:p,color:new e.ColorKit(this._color).toRgb(),width:g,height:_,zIndex:1,evented:!1},y=new M(`crosshair-${n}`,v);this._shapes.push(y),r.addObject(y)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};N=k([O(1,(0,e.Inject)(l.SheetSkeletonManagerService)),O(2,(0,e.Inject)(c.SheetsSelectionsService)),O(3,(0,e.Inject)(h)),O(4,(0,e.Inject)(e.IContextService)),O(5,c.IRefSelectionsService)],N);let P=class extends e.Plugin{constructor(t=C,n,r,i){super(),this._config=t,this._injector=n,this._renderManagerService=r,this._configService=i;let{...a}=(0,e.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){[[h],[A]].forEach(e=>this._injector.add(e))}onReady(){[[N]].forEach(e=>this._injector.add(e)),this._injector.get(A),this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,[N])}};p(P,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),p(P,`packageName`,b),p(P,`version`,x),p(P,`type`,e.UniverInstanceType.UNIVER_SHEET),P=k([O(1,(0,e.Inject)(e.Injector)),O(2,n.IRenderManagerService),O(3,e.IConfigService)],P),exports.CROSSHAIR_HIGHLIGHT_COLORS=m,exports.DisableCrosshairHighlightOperation=y,exports.EnableCrosshairHighlightOperation=v,exports.SetCrosshairHighlightColorOperation=_,exports.SheetsCrosshairHighlightService=h,exports.ToggleCrosshairHighlightOperation=g,Object.defineProperty(exports,`UniverSheetsCrosshairHighlightPlugin`,{enumerable:!0,get:function(){return P}});
package/lib/es/index.js CHANGED
@@ -1 +1 @@
1
- import{ColorKit as e,CommandType as t,Disposable as n,ICommandService as r,IConfigService as i,IContextService as a,Inject as o,Injector as s,Plugin as c,RANGE_TYPE as l,Rectangle as u,UniverInstanceType as d,merge as f}from"@univerjs/core";import{BehaviorSubject as p,combineLatest as m,map as h,merge as g,startWith as _,tap as v}from"rxjs";import{IRenderManagerService as y,Rect as b,Shape as ee}from"@univerjs/engine-render";import{CrossHighlightingIcon as x}from"@univerjs/icons";import{ComponentManager as te,ContextMenuGroup as S,ContextMenuPosition as C,IMenuManagerService as w,MenuItemType as T,getMenuHiddenObservable as E,useDependency as D,useObservable as O}from"@univerjs/ui";import{borderClassName as k,clsx as A}from"@univerjs/design";import{useCallback as ne}from"react";import{jsx as j}from"react/jsx-runtime";import{IRefSelectionsService as re,REF_SELECTIONS_ENABLED as ie,SheetsSelectionsService as ae}from"@univerjs/sheets";import{SheetSkeletonManagerService as oe,getCoordByCell as M}from"@univerjs/sheets-ui";function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function P(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function F(e){var t=P(e,`string`);return N(t)==`symbol`?t:t+``}function I(e,t,n){return(t=F(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const L=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var R=class extends n{constructor(...e){super(...e),I(this,`_enabled$`,new p(!1)),I(this,`enabled$`,this._enabled$.asObservable()),I(this,`_color$`,new p(L[0])),I(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const z={id:`sheet.operation.toggle-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R),n=t.enabled;return t.setEnabled(!n),!0}},B={id:`sheet.operation.set-crosshair-highlight-color`,type:t.OPERATION,handler(e,{value:t}){let n=e.get(R);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},V={id:`sheet.operation.enable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?!1:(t.setEnabled(!0),!0)}},H={id:`sheet.operation.disable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?(t.setEnabled(!1),!0):!1}};var U=`@univerjs/sheets-crosshair-highlight`,W=`0.20.0`;const G=`sheets-crosshair-highlight.config`;Symbol(G);const K={},q=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function se(e){let t=e.get(R);return{id:z.id,tooltip:`crosshair.button.tooltip`,type:T.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:q,hoverable:!1,selectable:!1}}],selectionsCommandId:B.id,activated$:t.enabled$,hidden$:E(e,d.UNIVER_SHEET)}}const J={[C.FOOTER_MENU]:{[S.OTHERS]:{[z.id]:{order:0,menuItemFactory:se}}}};function ce(e){let{onChange:t}=e,n=O(D(R).color$),r=ne(e=>{t==null||t(e)},[t]);return j(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:L.map(e=>j(`div`,{className:A(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,k,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function Y(e,t){return function(n,r){t(n,r,e)}}function X(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Z=class extends n{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[z,B,V,H].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(J)}_initComponents(){this._componentMgr.register(q,ce),this._componentMgr.register(`CrossHighlightingIcon`,x)}};Z=X([Y(0,o(te)),Y(1,w),Y(2,r)],Z);var le=class{constructor(){I(this,`_selectedRanges`,[]),I(this,`_ranges`,[])}addRange(e){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let t=this._getIntersects(e),n=this._getSplitRanges(e,t);n.length>0&&this._ranges.push(...n)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let n=[e];for(let e of t.concat(this._selectedRanges)){let t=[];for(let r of n){let n=u.subtract(r,e);n&&n.length>0&&t.push(...n)}n=t}return n.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let t=[];for(let n of this._ranges){let r=u.getIntersects(n,e);r&&t.push(r)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},ue=class extends ee{constructor(e,t){super(e,t),I(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;b.drawWith(e,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}};let Q=class extends n{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,I(this,`_shapes`,[]),I(this,`_rangeCollection`,new le),I(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe(m([this._contextService.subscribeContextValue$(ie).pipe(_(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(v(e=>this._color=e)),g(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._sheetsSelectionsService.getCurrentSelections()))),g(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let n=t.getRowCount(),r=t.getColumnCount(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=e,c={startRow:i,endRow:a,startColumn:0,endColumn:o-1},u={startRow:i,endRow:a,startColumn:s+1,endColumn:r},d={startRow:0,endRow:i-1,startColumn:o,endColumn:s},f={startRow:a+1,endRow:n,startColumn:o,endColumn:s};for(let e of[c,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l=M(a,s,r,i),u=M(o,c,r,i),{startX:d,startY:f}=l,{endX:p,endY:m}=u,h=p-d,g=m-f,_={left:d,top:f,color:new e(this._color).toRgb(),width:h,height:g,zIndex:1,evented:!1},v=new ue(`crosshair-${n}`,_);this._shapes.push(v),r.addObject(v)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};Q=X([Y(1,o(oe)),Y(2,o(ae)),Y(3,o(R)),Y(4,o(a)),Y(5,re)],Q);let $=class extends c{constructor(e=K,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerService=n,this._configService=r;let{...i}=f({},K,this._config);this._configService.setConfig(G,i)}onStarting(){[[R],[Z]].forEach(e=>this._injector.add(e))}onReady(){[[Q]].forEach(e=>this._injector.add(e)),this._injector.get(Z),this._renderManagerService.registerRenderModule(d.UNIVER_SHEET,[Q])}};I($,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),I($,`packageName`,U),I($,`version`,W),I($,`type`,d.UNIVER_SHEET),$=X([Y(1,o(s)),Y(2,y),Y(3,i)],$);export{L as CROSSHAIR_HIGHLIGHT_COLORS,H as DisableCrosshairHighlightOperation,V as EnableCrosshairHighlightOperation,B as SetCrosshairHighlightColorOperation,R as SheetsCrosshairHighlightService,z as ToggleCrosshairHighlightOperation,$ as UniverSheetsCrosshairHighlightPlugin};
1
+ import{ColorKit as e,CommandType as t,Disposable as n,ICommandService as r,IConfigService as i,IContextService as a,Inject as o,Injector as s,Plugin as c,RANGE_TYPE as l,Rectangle as u,UniverInstanceType as d,merge as f}from"@univerjs/core";import{BehaviorSubject as p,combineLatest as m,map as h,merge as g,startWith as _,tap as v}from"rxjs";import{IRenderManagerService as y,Rect as b,Shape as ee}from"@univerjs/engine-render";import{CrossHighlightingIcon as x}from"@univerjs/icons";import{ComponentManager as te,ContextMenuGroup as S,ContextMenuPosition as C,IMenuManagerService as w,MenuItemType as T,getMenuHiddenObservable as E,useDependency as D,useObservable as O}from"@univerjs/ui";import{borderClassName as k,clsx as A}from"@univerjs/design";import{useCallback as ne}from"react";import{jsx as j}from"react/jsx-runtime";import{IRefSelectionsService as re,REF_SELECTIONS_ENABLED as ie,SheetsSelectionsService as ae}from"@univerjs/sheets";import{SheetSkeletonManagerService as oe,getCoordByCell as M}from"@univerjs/sheets-ui";function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function P(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function F(e){var t=P(e,`string`);return N(t)==`symbol`?t:t+``}function I(e,t,n){return(t=F(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const L=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var R=class extends n{constructor(...e){super(...e),I(this,`_enabled$`,new p(!1)),I(this,`enabled$`,this._enabled$.asObservable()),I(this,`_color$`,new p(L[0])),I(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const z={id:`sheet.operation.toggle-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R),n=t.enabled;return t.setEnabled(!n),!0}},B={id:`sheet.operation.set-crosshair-highlight-color`,type:t.OPERATION,handler(e,{value:t}){let n=e.get(R);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},V={id:`sheet.operation.enable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?!1:(t.setEnabled(!0),!0)}},H={id:`sheet.operation.disable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?(t.setEnabled(!1),!0):!1}};var U=`@univerjs/sheets-crosshair-highlight`,W=`0.20.1`;const G=`sheets-crosshair-highlight.config`;Symbol(G);const K={},q=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function se(e){let t=e.get(R);return{id:z.id,tooltip:`crosshair.button.tooltip`,type:T.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:q,hoverable:!1,selectable:!1}}],selectionsCommandId:B.id,activated$:t.enabled$,hidden$:E(e,d.UNIVER_SHEET)}}const J={[C.FOOTER_MENU]:{[S.OTHERS]:{[z.id]:{order:0,menuItemFactory:se}}}};function ce(e){let{onChange:t}=e,n=O(D(R).color$),r=ne(e=>{t==null||t(e)},[t]);return j(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:L.map(e=>j(`div`,{className:A(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,k,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function Y(e,t){return function(n,r){t(n,r,e)}}function X(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Z=class extends n{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[z,B,V,H].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(J)}_initComponents(){this._componentMgr.register(q,ce),this._componentMgr.register(`CrossHighlightingIcon`,x)}};Z=X([Y(0,o(te)),Y(1,w),Y(2,r)],Z);var le=class{constructor(){I(this,`_selectedRanges`,[]),I(this,`_ranges`,[])}addRange(e){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let t=this._getIntersects(e),n=this._getSplitRanges(e,t);n.length>0&&this._ranges.push(...n)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let n=[e];for(let e of t.concat(this._selectedRanges)){let t=[];for(let r of n){let n=u.subtract(r,e);n&&n.length>0&&t.push(...n)}n=t}return n.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let t=[];for(let n of this._ranges){let r=u.getIntersects(n,e);r&&t.push(r)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},ue=class extends ee{constructor(e,t){super(e,t),I(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;b.drawWith(e,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}};let Q=class extends n{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,I(this,`_shapes`,[]),I(this,`_rangeCollection`,new le),I(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe(m([this._contextService.subscribeContextValue$(ie).pipe(_(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(v(e=>this._color=e)),g(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._sheetsSelectionsService.getCurrentSelections()))),g(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let n=t.getRowCount(),r=t.getColumnCount(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=e,c={startRow:i,endRow:a,startColumn:0,endColumn:o-1},u={startRow:i,endRow:a,startColumn:s+1,endColumn:r},d={startRow:0,endRow:i-1,startColumn:o,endColumn:s},f={startRow:a+1,endRow:n,startColumn:o,endColumn:s};for(let e of[c,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l=M(a,s,r,i),u=M(o,c,r,i),{startX:d,startY:f}=l,{endX:p,endY:m}=u,h=p-d,g=m-f,_={left:d,top:f,color:new e(this._color).toRgb(),width:h,height:g,zIndex:1,evented:!1},v=new ue(`crosshair-${n}`,_);this._shapes.push(v),r.addObject(v)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};Q=X([Y(1,o(oe)),Y(2,o(ae)),Y(3,o(R)),Y(4,o(a)),Y(5,re)],Q);let $=class extends c{constructor(e=K,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerService=n,this._configService=r;let{...i}=f({},K,this._config);this._configService.setConfig(G,i)}onStarting(){[[R],[Z]].forEach(e=>this._injector.add(e))}onReady(){[[Q]].forEach(e=>this._injector.add(e)),this._injector.get(Z),this._renderManagerService.registerRenderModule(d.UNIVER_SHEET,[Q])}};I($,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),I($,`packageName`,U),I($,`version`,W),I($,`type`,d.UNIVER_SHEET),$=X([Y(1,o(s)),Y(2,y),Y(3,i)],$);export{L as CROSSHAIR_HIGHLIGHT_COLORS,H as DisableCrosshairHighlightOperation,V as EnableCrosshairHighlightOperation,B as SetCrosshairHighlightColorOperation,R as SheetsCrosshairHighlightService,z as ToggleCrosshairHighlightOperation,$ as UniverSheetsCrosshairHighlightPlugin};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{ColorKit as e,CommandType as t,Disposable as n,ICommandService as r,IConfigService as i,IContextService as a,Inject as o,Injector as s,Plugin as c,RANGE_TYPE as l,Rectangle as u,UniverInstanceType as d,merge as f}from"@univerjs/core";import{BehaviorSubject as p,combineLatest as m,map as h,merge as g,startWith as _,tap as v}from"rxjs";import{IRenderManagerService as y,Rect as b,Shape as ee}from"@univerjs/engine-render";import{CrossHighlightingIcon as x}from"@univerjs/icons";import{ComponentManager as te,ContextMenuGroup as S,ContextMenuPosition as C,IMenuManagerService as w,MenuItemType as T,getMenuHiddenObservable as E,useDependency as D,useObservable as O}from"@univerjs/ui";import{borderClassName as k,clsx as A}from"@univerjs/design";import{useCallback as ne}from"react";import{jsx as j}from"react/jsx-runtime";import{IRefSelectionsService as re,REF_SELECTIONS_ENABLED as ie,SheetsSelectionsService as ae}from"@univerjs/sheets";import{SheetSkeletonManagerService as oe,getCoordByCell as M}from"@univerjs/sheets-ui";function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function P(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function F(e){var t=P(e,`string`);return N(t)==`symbol`?t:t+``}function I(e,t,n){return(t=F(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const L=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var R=class extends n{constructor(...e){super(...e),I(this,`_enabled$`,new p(!1)),I(this,`enabled$`,this._enabled$.asObservable()),I(this,`_color$`,new p(L[0])),I(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const z={id:`sheet.operation.toggle-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R),n=t.enabled;return t.setEnabled(!n),!0}},B={id:`sheet.operation.set-crosshair-highlight-color`,type:t.OPERATION,handler(e,{value:t}){let n=e.get(R);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},V={id:`sheet.operation.enable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?!1:(t.setEnabled(!0),!0)}},H={id:`sheet.operation.disable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?(t.setEnabled(!1),!0):!1}};var U=`@univerjs/sheets-crosshair-highlight`,W=`0.20.0`;const G=`sheets-crosshair-highlight.config`;Symbol(G);const K={},q=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function se(e){let t=e.get(R);return{id:z.id,tooltip:`crosshair.button.tooltip`,type:T.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:q,hoverable:!1,selectable:!1}}],selectionsCommandId:B.id,activated$:t.enabled$,hidden$:E(e,d.UNIVER_SHEET)}}const J={[C.FOOTER_MENU]:{[S.OTHERS]:{[z.id]:{order:0,menuItemFactory:se}}}};function ce(e){let{onChange:t}=e,n=O(D(R).color$),r=ne(e=>{t==null||t(e)},[t]);return j(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:L.map(e=>j(`div`,{className:A(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,k,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function Y(e,t){return function(n,r){t(n,r,e)}}function X(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Z=class extends n{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[z,B,V,H].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(J)}_initComponents(){this._componentMgr.register(q,ce),this._componentMgr.register(`CrossHighlightingIcon`,x)}};Z=X([Y(0,o(te)),Y(1,w),Y(2,r)],Z);var le=class{constructor(){I(this,`_selectedRanges`,[]),I(this,`_ranges`,[])}addRange(e){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let t=this._getIntersects(e),n=this._getSplitRanges(e,t);n.length>0&&this._ranges.push(...n)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let n=[e];for(let e of t.concat(this._selectedRanges)){let t=[];for(let r of n){let n=u.subtract(r,e);n&&n.length>0&&t.push(...n)}n=t}return n.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let t=[];for(let n of this._ranges){let r=u.getIntersects(n,e);r&&t.push(r)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},ue=class extends ee{constructor(e,t){super(e,t),I(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;b.drawWith(e,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}};let Q=class extends n{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,I(this,`_shapes`,[]),I(this,`_rangeCollection`,new le),I(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe(m([this._contextService.subscribeContextValue$(ie).pipe(_(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(v(e=>this._color=e)),g(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._sheetsSelectionsService.getCurrentSelections()))),g(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let n=t.getRowCount(),r=t.getColumnCount(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=e,c={startRow:i,endRow:a,startColumn:0,endColumn:o-1},u={startRow:i,endRow:a,startColumn:s+1,endColumn:r},d={startRow:0,endRow:i-1,startColumn:o,endColumn:s},f={startRow:a+1,endRow:n,startColumn:o,endColumn:s};for(let e of[c,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l=M(a,s,r,i),u=M(o,c,r,i),{startX:d,startY:f}=l,{endX:p,endY:m}=u,h=p-d,g=m-f,_={left:d,top:f,color:new e(this._color).toRgb(),width:h,height:g,zIndex:1,evented:!1},v=new ue(`crosshair-${n}`,_);this._shapes.push(v),r.addObject(v)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};Q=X([Y(1,o(oe)),Y(2,o(ae)),Y(3,o(R)),Y(4,o(a)),Y(5,re)],Q);let $=class extends c{constructor(e=K,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerService=n,this._configService=r;let{...i}=f({},K,this._config);this._configService.setConfig(G,i)}onStarting(){[[R],[Z]].forEach(e=>this._injector.add(e))}onReady(){[[Q]].forEach(e=>this._injector.add(e)),this._injector.get(Z),this._renderManagerService.registerRenderModule(d.UNIVER_SHEET,[Q])}};I($,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),I($,`packageName`,U),I($,`version`,W),I($,`type`,d.UNIVER_SHEET),$=X([Y(1,o(s)),Y(2,y),Y(3,i)],$);export{L as CROSSHAIR_HIGHLIGHT_COLORS,H as DisableCrosshairHighlightOperation,V as EnableCrosshairHighlightOperation,B as SetCrosshairHighlightColorOperation,R as SheetsCrosshairHighlightService,z as ToggleCrosshairHighlightOperation,$ as UniverSheetsCrosshairHighlightPlugin};
1
+ import{ColorKit as e,CommandType as t,Disposable as n,ICommandService as r,IConfigService as i,IContextService as a,Inject as o,Injector as s,Plugin as c,RANGE_TYPE as l,Rectangle as u,UniverInstanceType as d,merge as f}from"@univerjs/core";import{BehaviorSubject as p,combineLatest as m,map as h,merge as g,startWith as _,tap as v}from"rxjs";import{IRenderManagerService as y,Rect as b,Shape as ee}from"@univerjs/engine-render";import{CrossHighlightingIcon as x}from"@univerjs/icons";import{ComponentManager as te,ContextMenuGroup as S,ContextMenuPosition as C,IMenuManagerService as w,MenuItemType as T,getMenuHiddenObservable as E,useDependency as D,useObservable as O}from"@univerjs/ui";import{borderClassName as k,clsx as A}from"@univerjs/design";import{useCallback as ne}from"react";import{jsx as j}from"react/jsx-runtime";import{IRefSelectionsService as re,REF_SELECTIONS_ENABLED as ie,SheetsSelectionsService as ae}from"@univerjs/sheets";import{SheetSkeletonManagerService as oe,getCoordByCell as M}from"@univerjs/sheets-ui";function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function P(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function F(e){var t=P(e,`string`);return N(t)==`symbol`?t:t+``}function I(e,t,n){return(t=F(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const L=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var R=class extends n{constructor(...e){super(...e),I(this,`_enabled$`,new p(!1)),I(this,`enabled$`,this._enabled$.asObservable()),I(this,`_color$`,new p(L[0])),I(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};const z={id:`sheet.operation.toggle-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R),n=t.enabled;return t.setEnabled(!n),!0}},B={id:`sheet.operation.set-crosshair-highlight-color`,type:t.OPERATION,handler(e,{value:t}){let n=e.get(R);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},V={id:`sheet.operation.enable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?!1:(t.setEnabled(!0),!0)}},H={id:`sheet.operation.disable-crosshair-highlight`,type:t.OPERATION,handler(e){let t=e.get(R);return t.enabled?(t.setEnabled(!1),!0):!1}};var U=`@univerjs/sheets-crosshair-highlight`,W=`0.20.1`;const G=`sheets-crosshair-highlight.config`;Symbol(G);const K={},q=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function se(e){let t=e.get(R);return{id:z.id,tooltip:`crosshair.button.tooltip`,type:T.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:q,hoverable:!1,selectable:!1}}],selectionsCommandId:B.id,activated$:t.enabled$,hidden$:E(e,d.UNIVER_SHEET)}}const J={[C.FOOTER_MENU]:{[S.OTHERS]:{[z.id]:{order:0,menuItemFactory:se}}}};function ce(e){let{onChange:t}=e,n=O(D(R).color$),r=ne(e=>{t==null||t(e)},[t]);return j(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:L.map(e=>j(`div`,{className:A(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,k,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function Y(e,t){return function(n,r){t(n,r,e)}}function X(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Z=class extends n{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[z,B,V,H].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(J)}_initComponents(){this._componentMgr.register(q,ce),this._componentMgr.register(`CrossHighlightingIcon`,x)}};Z=X([Y(0,o(te)),Y(1,w),Y(2,r)],Z);var le=class{constructor(){I(this,`_selectedRanges`,[]),I(this,`_ranges`,[])}addRange(e){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let t=this._getIntersects(e),n=this._getSplitRanges(e,t);n.length>0&&this._ranges.push(...n)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let n=[e];for(let e of t.concat(this._selectedRanges)){let t=[];for(let r of n){let n=u.subtract(r,e);n&&n.length>0&&t.push(...n)}n=t}return n.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let t=[];for(let n of this._ranges){let r=u.getIntersects(n,e);r&&t.push(r)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},ue=class extends ee{constructor(e,t){super(e,t),I(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;b.drawWith(e,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}};let Q=class extends n{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,I(this,`_shapes`,[]),I(this,`_rangeCollection`,new le),I(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe(m([this._contextService.subscribeContextValue$(ie).pipe(_(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(v(e=>this._color=e)),g(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._sheetsSelectionsService.getCurrentSelections()))),g(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(h(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===l.COLUMN||e.rangeType===l.ROW||e.rangeType===l.ALL)return;let n=t.getRowCount(),r=t.getColumnCount(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=e,c={startRow:i,endRow:a,startColumn:0,endColumn:o-1},u={startRow:i,endRow:a,startColumn:s+1,endColumn:r},d={startRow:0,endRow:i-1,startColumn:o,endColumn:s},f={startRow:a+1,endRow:n,startColumn:o,endColumn:s};for(let e of[c,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(t,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=t,l=M(a,s,r,i),u=M(o,c,r,i),{startX:d,startY:f}=l,{endX:p,endY:m}=u,h=p-d,g=m-f,_={left:d,top:f,color:new e(this._color).toRgb(),width:h,height:g,zIndex:1,evented:!1},v=new ue(`crosshair-${n}`,_);this._shapes.push(v),r.addObject(v)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};Q=X([Y(1,o(oe)),Y(2,o(ae)),Y(3,o(R)),Y(4,o(a)),Y(5,re)],Q);let $=class extends c{constructor(e=K,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerService=n,this._configService=r;let{...i}=f({},K,this._config);this._configService.setConfig(G,i)}onStarting(){[[R],[Z]].forEach(e=>this._injector.add(e))}onReady(){[[Q]].forEach(e=>this._injector.add(e)),this._injector.get(Z),this._renderManagerService.registerRenderModule(d.UNIVER_SHEET,[Q])}};I($,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),I($,`packageName`,U),I($,`version`,W),I($,`type`,d.UNIVER_SHEET),$=X([Y(1,o(s)),Y(2,y),Y(3,i)],$);export{L as CROSSHAIR_HIGHLIGHT_COLORS,H as DisableCrosshairHighlightOperation,V as EnableCrosshairHighlightOperation,B as SetCrosshairHighlightColorOperation,R as SheetsCrosshairHighlightService,z as ToggleCrosshairHighlightOperation,$ as UniverSheetsCrosshairHighlightPlugin};
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`),require(`@univerjs/engine-render`),require(`react`),require(`@univerjs/ui`),require(`@univerjs/design`),require(`react/jsx-runtime`),require(`@univerjs/sheets`),require(`@univerjs/sheets-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`@univerjs/design`,`react/jsx-runtime`,`@univerjs/sheets`,`@univerjs/sheets-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsCrosshairHighlight={},e.UniverCore,e.rxjs,e.UniverEngineRender,e.React,e.UniverUi,e.UniverDesign,e.React,e.UniverSheets,e.UniverSheetsUi))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let m=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var h=class extends t.Disposable{constructor(...e){super(...e),p(this,`_enabled$`,new n.BehaviorSubject(!1)),p(this,`enabled$`,this._enabled$.asObservable()),p(this,`_color$`,new n.BehaviorSubject(m[0])),p(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};let g={id:`sheet.operation.toggle-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h),n=t.enabled;return t.setEnabled(!n),!0}},_={id:`sheet.operation.set-crosshair-highlight-color`,type:t.CommandType.OPERATION,handler(e,{value:t}){let n=e.get(h);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},v={id:`sheet.operation.enable-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?!1:(t.setEnabled(!0),!0)}},y={id:`sheet.operation.disable-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?(t.setEnabled(!1),!0):!1}};var b=`@univerjs/sheets-crosshair-highlight`,x=`0.20.0`;let S=`sheets-crosshair-highlight.config`;Symbol(S);let C={};function w({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${O()}`);return T(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function T(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...E(e,n,a),...r},(D(e,n).children||[]).map((r,i)=>T(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function E(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function D(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function O(){return Math.random().toString(36).substring(2,8)}w.displayName=`UniverIcon`;let k={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.6498 1.05005C2.21386 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V3.65005C14.9498 2.21411 13.7857 1.05005 12.3498 1.05005H3.6498ZM5.4002 2.25005H3.6498C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V5.40002H5.4002V2.25005ZM2.2498 10.6V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H5.4002V10.6H2.2498ZM6.60019 13.75H9.4002V9.40002H13.7498V6.60002H9.4002V2.25005H6.60019V6.60002H2.25029V9.40002H6.60019V13.75ZM10.6002 2.25005V5.40002H13.7498V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H10.6002ZM13.7498 10.6H10.6002V13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.6Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},A=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(w,Object.assign({},e,{id:`cross-highlighting-icon`,ref:t,icon:k}))});A.displayName=`CrossHighlightingIcon`;let j=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function M(e){let n=e.get(h);return{id:g.id,tooltip:`crosshair.button.tooltip`,type:a.MenuItemType.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:j,hoverable:!1,selectable:!1}}],selectionsCommandId:_.id,activated$:n.enabled$,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}let N={[a.ContextMenuPosition.FOOTER_MENU]:{[a.ContextMenuGroup.OTHERS]:{[g.id]:{order:0,menuItemFactory:M}}}};function P(e){let{onChange:t}=e,n=(0,a.useObservable)((0,a.useDependency)(h).color$),r=(0,i.useCallback)(e=>{t==null||t(e)},[t]);return(0,s.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:m.map(e=>(0,s.jsx)(`div`,{className:(0,o.clsx)(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,o.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function F(e,t){return function(n,r){t(n,r,e)}}function I(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let L=class extends t.Disposable{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[g,_,v,y].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(N)}_initComponents(){this._componentMgr.register(j,P),this._componentMgr.register(`CrossHighlightingIcon`,A)}};L=I([F(0,(0,t.Inject)(a.ComponentManager)),F(1,a.IMenuManagerService),F(2,t.ICommandService)],L);var R=class{constructor(){p(this,`_selectedRanges`,[]),p(this,`_ranges`,[])}addRange(e){if(e.rangeType===t.RANGE_TYPE.COLUMN||e.rangeType===t.RANGE_TYPE.ROW||e.rangeType===t.RANGE_TYPE.ALL)return;let n=this._getIntersects(e),r=this._getSplitRanges(e,n);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,n){let r=[e];for(let e of n.concat(this._selectedRanges)){let n=[];for(let i of r){let r=t.Rectangle.subtract(i,e);r&&r.length>0&&n.push(...r)}r=n}return r.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let n=[];for(let r of this._ranges){let i=t.Rectangle.getIntersects(r,e);i&&n.push(i)}return n}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},z=class extends r.Shape{constructor(e,t){super(e,t),p(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:i,stroke:void 0,strokeWidth:0,evented:!1})}};let B=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,p(this,`_shapes`,[]),p(this,`_rangeCollection`,new R),p(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe((0,n.combineLatest)([this._contextService.subscribeContextValue$(c.REF_SELECTIONS_ENABLED).pipe((0,n.startWith)(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe((0,n.tap)(e=>this._color=e)),(0,n.merge)(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,n.map)(()=>this._sheetsSelectionsService.getCurrentSelections()))),(0,n.merge)(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,n.map)(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,n){if(e.rangeType===t.RANGE_TYPE.COLUMN||e.rangeType===t.RANGE_TYPE.ROW||e.rangeType===t.RANGE_TYPE.ALL)return;let r=n.getRowCount(),i=n.getColumnCount(),{startRow:a,endRow:o,startColumn:s,endColumn:c}=e,l={startRow:a,endRow:o,startColumn:0,endColumn:s-1},u={startRow:a,endRow:o,startColumn:c+1,endColumn:i},d={startRow:0,endRow:a-1,startColumn:s,endColumn:c},f={startRow:o+1,endRow:r,startColumn:s,endColumn:c};for(let e of[l,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=e,u=(0,l.getCoordByCell)(a,s,r,i),d=(0,l.getCoordByCell)(o,c,r,i),{startX:f,startY:p}=u,{endX:m,endY:h}=d,g=m-f,_=h-p,v={left:f,top:p,color:new t.ColorKit(this._color).toRgb(),width:g,height:_,zIndex:1,evented:!1},y=new z(`crosshair-${n}`,v);this._shapes.push(y),r.addObject(y)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};B=I([F(1,(0,t.Inject)(l.SheetSkeletonManagerService)),F(2,(0,t.Inject)(c.SheetsSelectionsService)),F(3,(0,t.Inject)(h)),F(4,(0,t.Inject)(t.IContextService)),F(5,c.IRefSelectionsService)],B);let V=class extends t.Plugin{constructor(e=C,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{...a}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){[[h],[L]].forEach(e=>this._injector.add(e))}onReady(){[[B]].forEach(e=>this._injector.add(e)),this._injector.get(L),this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[B])}};p(V,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),p(V,`packageName`,b),p(V,`version`,x),p(V,`type`,t.UniverInstanceType.UNIVER_SHEET),V=I([F(1,(0,t.Inject)(t.Injector)),F(2,r.IRenderManagerService),F(3,t.IConfigService)],V),e.CROSSHAIR_HIGHLIGHT_COLORS=m,e.DisableCrosshairHighlightOperation=y,e.EnableCrosshairHighlightOperation=v,e.SetCrosshairHighlightColorOperation=_,e.SheetsCrosshairHighlightService=h,e.ToggleCrosshairHighlightOperation=g,Object.defineProperty(e,`UniverSheetsCrosshairHighlightPlugin`,{enumerable:!0,get:function(){return V}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`),require(`@univerjs/engine-render`),require(`react`),require(`@univerjs/ui`),require(`@univerjs/design`),require(`react/jsx-runtime`),require(`@univerjs/sheets`),require(`@univerjs/sheets-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`@univerjs/design`,`react/jsx-runtime`,`@univerjs/sheets`,`@univerjs/sheets-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsCrosshairHighlight={},e.UniverCore,e.rxjs,e.UniverEngineRender,e.React,e.UniverUi,e.UniverDesign,e.React,e.UniverSheets,e.UniverSheetsUi))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let m=[`rgba(158, 109, 227, 0.3)`,`rgba(254, 75, 75, 0.3)`,`rgba(255, 140, 81, 0.3)`,`rgba(164, 220, 22, 0.3)`,`rgba(45, 174, 255, 0.3)`,`rgba(58, 96, 247, 0.3)`,`rgba(242, 72, 166, 0.3)`,`rgba(153, 153, 153, 0.3)`,`rgba(158, 109, 227, 0.15)`,`rgba(254, 75, 75, 0.15)`,`rgba(255, 140, 81, 0.15)`,`rgba(164, 220, 22, 0.15)`,`rgba(45, 174, 255, 0.15)`,`rgba(58, 96, 247, 0.15)`,`rgba(242, 72, 166, 0.15)`,`rgba(153, 153, 153, 0.15)`];var h=class extends t.Disposable{constructor(...e){super(...e),p(this,`_enabled$`,new n.BehaviorSubject(!1)),p(this,`enabled$`,this._enabled$.asObservable()),p(this,`_color$`,new n.BehaviorSubject(m[0])),p(this,`color$`,this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(e){this._enabled$.next(e)}setColor(e){this._color$.next(e)}};let g={id:`sheet.operation.toggle-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h),n=t.enabled;return t.setEnabled(!n),!0}},_={id:`sheet.operation.set-crosshair-highlight-color`,type:t.CommandType.OPERATION,handler(e,{value:t}){let n=e.get(h);return n.enabled||n.setEnabled(!0),n.setColor(t),!0}},v={id:`sheet.operation.enable-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?!1:(t.setEnabled(!0),!0)}},y={id:`sheet.operation.disable-crosshair-highlight`,type:t.CommandType.OPERATION,handler(e){let t=e.get(h);return t.enabled?(t.setEnabled(!1),!0):!1}};var b=`@univerjs/sheets-crosshair-highlight`,x=`0.20.1`;let S=`sheets-crosshair-highlight.config`;Symbol(S);let C={};function w({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${O()}`);return T(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function T(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...E(e,n,a),...r},(D(e,n).children||[]).map((r,i)=>T(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function E(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function D(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function O(){return Math.random().toString(36).substring(2,8)}w.displayName=`UniverIcon`;let k={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.6498 1.05005C2.21386 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V3.65005C14.9498 2.21411 13.7857 1.05005 12.3498 1.05005H3.6498ZM5.4002 2.25005H3.6498C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V5.40002H5.4002V2.25005ZM2.2498 10.6V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H5.4002V10.6H2.2498ZM6.60019 13.75H9.4002V9.40002H13.7498V6.60002H9.4002V2.25005H6.60019V6.60002H2.25029V9.40002H6.60019V13.75ZM10.6002 2.25005V5.40002H13.7498V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H10.6002ZM13.7498 10.6H10.6002V13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.6Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},A=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(w,Object.assign({},e,{id:`cross-highlighting-icon`,ref:t,icon:k}))});A.displayName=`CrossHighlightingIcon`;let j=`CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT`;function M(e){let n=e.get(h);return{id:g.id,tooltip:`crosshair.button.tooltip`,type:a.MenuItemType.BUTTON_SELECTOR,icon:`CrossHighlightingIcon`,selections:[{label:{name:j,hoverable:!1,selectable:!1}}],selectionsCommandId:_.id,activated$:n.enabled$,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}let N={[a.ContextMenuPosition.FOOTER_MENU]:{[a.ContextMenuGroup.OTHERS]:{[g.id]:{order:0,menuItemFactory:M}}}};function P(e){let{onChange:t}=e,n=(0,a.useObservable)((0,a.useDependency)(h).color$),r=(0,i.useCallback)(e=>{t==null||t(e)},[t]);return(0,s.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3`,children:m.map(e=>(0,s.jsx)(`div`,{className:(0,o.clsx)(`hover:univer-ring-primary-600/40 univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow hover:univer-ring-[1.5px]`,o.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":e===n}),style:{backgroundColor:e},onClick:()=>r(e)},e))})}function F(e,t){return function(n,r){t(n,r,e)}}function I(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let L=class extends t.Disposable{constructor(e,t,n){super(),this._componentMgr=e,this._menuManagerService=t,this._cmdSrv=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[g,_,v,y].forEach(e=>this._cmdSrv.registerCommand(e))}_initMenus(){this._menuManagerService.mergeMenu(N)}_initComponents(){this._componentMgr.register(j,P),this._componentMgr.register(`CrossHighlightingIcon`,A)}};L=I([F(0,(0,t.Inject)(a.ComponentManager)),F(1,a.IMenuManagerService),F(2,t.ICommandService)],L);var R=class{constructor(){p(this,`_selectedRanges`,[]),p(this,`_ranges`,[])}addRange(e){if(e.rangeType===t.RANGE_TYPE.COLUMN||e.rangeType===t.RANGE_TYPE.ROW||e.rangeType===t.RANGE_TYPE.ALL)return;let n=this._getIntersects(e),r=this._getSplitRanges(e,n);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,n){let r=[e];for(let e of n.concat(this._selectedRanges)){let n=[];for(let i of r){let r=t.Rectangle.subtract(i,e);r&&r.length>0&&n.push(...r)}r=n}return r.filter(e=>e.startRow<=e.endRow&&e.startColumn<=e.endColumn)}_getIntersects(e){let n=[];for(let r of this._ranges){let i=t.Rectangle.getIntersects(r,e);i&&n.push(i)}return n}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}},z=class extends r.Shape{constructor(e,t){super(e,t),p(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){var t,n;let i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(t=(n=this._color)==null?void 0:n.a)==null?.5:t})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:i,stroke:void 0,strokeWidth:0,evented:!1})}};let B=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=r,this._contextService=i,this._refSelectionsService=a,p(this,`_shapes`,[]),p(this,`_rangeCollection`,new R),p(this,`_color`,`rgba(255,0,0,0.5)`),this._initRenderListener()}_transformSelection(e,t){if(!e)return;let n=t.getRowCount(),r=t.getColumnCount(),i=[];for(let t of e){let{startRow:e,endRow:a,startColumn:o,endColumn:s}=t.range;a-e+1===n||s-o+1===r||i.push(t.range)}this._rangeCollection.setSelectedRanges(i);for(let e of i)this.addSelection(e,t)}_initRenderListener(){let e=this._context.unit;this.disposeWithMe((0,n.combineLatest)([this._contextService.subscribeContextValue$(c.REF_SELECTIONS_ENABLED).pipe((0,n.startWith)(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe((0,n.tap)(e=>this._color=e)),(0,n.merge)(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,n.map)(()=>this._sheetsSelectionsService.getCurrentSelections()))),(0,n.merge)(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe((0,n.map)(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,r,i,a,o])=>{if(this._clear(),!r)return;let s=t?o:a;this._rangeCollection.reset(),this._transformSelection(s,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,n){if(e.rangeType===t.RANGE_TYPE.COLUMN||e.rangeType===t.RANGE_TYPE.ROW||e.rangeType===t.RANGE_TYPE.ALL)return;let r=n.getRowCount(),i=n.getColumnCount(),{startRow:a,endRow:o,startColumn:s,endColumn:c}=e,l={startRow:a,endRow:o,startColumn:0,endColumn:s-1},u={startRow:a,endRow:o,startColumn:c+1,endColumn:i},d={startRow:0,endRow:a-1,startColumn:s,endColumn:c},f={startRow:o+1,endRow:r,startColumn:s,endColumn:c};for(let e of[l,u,d,f])e.startRow<=e.endRow&&e.startColumn<=e.endColumn&&this._rangeCollection.addRange(e)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,n,r,i){let{startRow:a,endRow:o,startColumn:s,endColumn:c}=e,u=(0,l.getCoordByCell)(a,s,r,i),d=(0,l.getCoordByCell)(o,c,r,i),{startX:f,startY:p}=u,{endX:m,endY:h}=d,g=m-f,_=h-p,v={left:f,top:p,color:new t.ColorKit(this._color).toRgb(),width:g,height:_,zIndex:1,evented:!1},y=new z(`crosshair-${n}`,v);this._shapes.push(y),r.addObject(y)}render(e){let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let{scene:n}=this._context;this._clear();for(let r=0;r<e.length;r++){let i=e[r];this._addShapes(i,r,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};B=I([F(1,(0,t.Inject)(l.SheetSkeletonManagerService)),F(2,(0,t.Inject)(c.SheetsSelectionsService)),F(3,(0,t.Inject)(h)),F(4,(0,t.Inject)(t.IContextService)),F(5,c.IRefSelectionsService)],B);let V=class extends t.Plugin{constructor(e=C,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{...a}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){[[h],[L]].forEach(e=>this._injector.add(e))}onReady(){[[B]].forEach(e=>this._injector.add(e)),this._injector.get(L),this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[B])}};p(V,`pluginName`,`SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN`),p(V,`packageName`,b),p(V,`version`,x),p(V,`type`,t.UniverInstanceType.UNIVER_SHEET),V=I([F(1,(0,t.Inject)(t.Injector)),F(2,r.IRenderManagerService),F(3,t.IConfigService)],V),e.CROSSHAIR_HIGHLIGHT_COLORS=m,e.DisableCrosshairHighlightOperation=y,e.EnableCrosshairHighlightOperation=v,e.SetCrosshairHighlightColorOperation=_,e.SheetsCrosshairHighlightService=h,e.ToggleCrosshairHighlightOperation=g,Object.defineProperty(e,`UniverSheetsCrosshairHighlightPlugin`,{enumerable:!0,get:function(){return V}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-crosshair-highlight",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -63,12 +63,12 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@univerjs/icons": "^1.1.1",
66
- "@univerjs/core": "0.20.0",
67
- "@univerjs/engine-render": "0.20.0",
68
- "@univerjs/sheets": "0.20.0",
69
- "@univerjs/ui": "0.20.0",
70
- "@univerjs/sheets-ui": "0.20.0",
71
- "@univerjs/design": "0.20.0"
66
+ "@univerjs/design": "0.20.1",
67
+ "@univerjs/engine-render": "0.20.1",
68
+ "@univerjs/sheets-ui": "0.20.1",
69
+ "@univerjs/core": "0.20.1",
70
+ "@univerjs/sheets": "0.20.1",
71
+ "@univerjs/ui": "0.20.1"
72
72
  },
73
73
  "devDependencies": {
74
74
  "postcss": "^8.5.8",
@@ -77,7 +77,7 @@
77
77
  "tailwindcss": "3.4.18",
78
78
  "typescript": "^6.0.2",
79
79
  "vitest": "^4.1.1",
80
- "@univerjs-infra/shared": "0.20.0"
80
+ "@univerjs-infra/shared": "0.20.1"
81
81
  },
82
82
  "scripts": {
83
83
  "test": "vitest run",