@univerjs/sheets-crosshair-highlight 0.6.0 → 0.6.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
- "use strict";var F=Object.defineProperty;var X=(s,e,t)=>e in s?F(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var l=(s,e,t)=>X(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),w=require("@univerjs/engine-render"),f=require("@univerjs/ui"),u=require("rxjs"),j=require("react/jsx-runtime"),S=require("react"),M=require("@univerjs/sheets"),$=require("@univerjs/sheets-ui"),K="sheets-crosshair-highlight.config",V={};var h=function(){return h=Object.assign||function(s){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(s[n]=e[n])}return s},h.apply(this,arguments)},z=function(s,e){var t={};for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(s);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(s,r[n])&&(t[r[n]]=s[r[n]]);return t},A=S.forwardRef(function(s,e){var t=s.icon,r=s.id,n=s.className,i=s.extend,o=z(s,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(r," ").concat(n||"").trim(),g=S.useRef("_".concat(ee()));return L(t,"".concat(r),{defIds:t.defIds,idSuffix:g.current},h({ref:e,className:c},o),i)});function L(s,e,t,r,n){return S.createElement(s.tag,h(h({key:e},J(s,t,n)),r),(Q(s,t).children||[]).map(function(i,o){return L(i,"".concat(e,"-").concat(s.tag,"-").concat(o),t,void 0,n)}))}function J(s,e,t){var r=h({},s.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);var n=e.defIds;return!n||n.length===0||(s.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(i){var o=i[0],c=i[1];typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Q(s,e){var t,r=e.defIds;return!r||r.length===0?s:s.tag==="defs"&&(!((t=s.children)===null||t===void 0)&&t.length)?h(h({},s),{children:s.children.map(function(n){return typeof n.attrs.id=="string"&&r&&r.indexOf(n.attrs.id)>-1?h(h({},n),{attrs:h(h({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):s}function ee(){return Math.random().toString(36).substring(2,8)}A.displayName="UniverIcon";var te={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#E5E5E5",d:"M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z"}},{tag:"path",attrs:{fill:"#fff",d:"M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z"}},{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"}}]},G=S.forwardRef(function(s,e){return S.createElement(A,Object.assign({},s,{id:"cross-highlighting-single",ref:e,icon:te}))});G.displayName="CrossHighlightingSingle";const P=["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)"];class d extends a.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new u.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new u.BehaviorSubject(P[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(t){this._enabled$.next(t)}setColor(t){this._color$.next(t)}}const I={id:"sheet.operation.toggle-crosshair-highlight",type:a.CommandType.OPERATION,handler(s){const e=s.get(d),t=e.enabled;return e.setEnabled(!t),!0}},x={id:"sheet.operation.set-crosshair-highlight-color",type:a.CommandType.OPERATION,handler(s,{value:e}){const t=s.get(d);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},U={id:"sheet.operation.enable-crosshair-highlight",type:a.CommandType.OPERATION,handler(s){const e=s.get(d);return e.enabled?!1:(e.setEnabled(!0),!0)}},k={id:"sheet.operation.disable-crosshair-highlight",type:a.CommandType.OPERATION,handler(s){const e=s.get(d);return e.enabled?(e.setEnabled(!1),!0):!1}};function D(s){var e,t,r="";if(typeof s=="string"||typeof s=="number")r+=s;else if(typeof s=="object")if(Array.isArray(s)){var n=s.length;for(e=0;e<n;e++)s[e]&&(t=D(s[e]))&&(r&&(r+=" "),r+=t)}else for(t in s)s[t]&&(r&&(r+=" "),r+=t);return r}function re(){for(var s,e,t=0,r="",n=arguments.length;t<n;t++)(s=arguments[t])&&(e=D(s))&&(r&&(r+=" "),r+=e);return r}const se="univer-crosshair-highlight-overlay",ne="univer-crosshair-highlight-item",ie="univer-crosshair-highlight-item-selected",E={crosshairHighlightOverlay:se,crosshairHighlightItem:ne,crosshairHighlightItemSelected:ie};function oe(s){const{onChange:e}=s,t=f.useDependency(d),r=f.useObservable(t.color$),n=S.useCallback(i=>{e==null||e(i)},[e]);return j.jsx("div",{className:E.crosshairHighlightOverlay,children:P.map(i=>j.jsx("div",{className:re(E.crosshairHighlightItem,{[E.crosshairHighlightItemSelected]:i===r}),style:{backgroundColor:i},onClick:()=>n(i)},i))})}const Y="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function ae(s){const e=s.get(d);return{id:I.id,tooltip:"crosshair.button.tooltip",type:f.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingSingle",selections:[{label:{name:Y,hoverable:!1}}],selectionsCommandId:x.id,activated$:e.enabled$,hidden$:f.getMenuHiddenObservable(s,a.UniverInstanceType.UNIVER_SHEET)}}const ce={[f.ContextMenuPosition.FOOTER_MENU]:{[f.ContextMenuGroup.OTHERS]:{[I.id]:{order:0,menuItemFactory:ae}}}};var le=Object.getOwnPropertyDescriptor,he=(s,e,t,r)=>{for(var n=r>1?void 0:r?le(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},y=(s,e)=>(t,r)=>e(t,r,s);let b=class extends a.Disposable{constructor(s,e,t){super(),this._componentMgr=s,this._menuManagerService=e,this._cmdSrv=t,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[I,x,U,k].forEach(s=>this._cmdSrv.registerCommand(s))}_initMenus(){this._menuManagerService.mergeMenu(ce)}_initComponents(){this._componentMgr.register(Y,oe),this._componentMgr.register("CrossHighlightingSingle",G)}};b=he([y(0,a.Inject(f.ComponentManager)),y(1,f.IMenuManagerService),y(2,a.ICommandService)],b);const ge=1;class ue{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const t=this._getIntersects(e),r=this._getSplitRanges(e,t);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let r=[e];for(const n of t.concat(this._selectedRanges)){const i=[];for(const o of r){const c=a.Rectangle.subtract(o,n);c&&c.length>0&&i.push(...c)}r=i}return r.filter(n=>n.startRow<=n.endRow&&n.startColumn<=n.endColumn)}_getIntersects(e){const t=[];for(const r of this._ranges){const n=a.Rectangle.getIntersects(r,e);n&&t.push(n)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class de extends w.Shape{constructor(t,r){super(t,r);l(this,"_color");r&&this.setShapeProps(r)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${this._color.a})`;w.Rect.drawWith(t,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}}var fe=Object.getOwnPropertyDescriptor,_e=(s,e,t,r)=>{for(var n=r>1?void 0:r?fe(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},p=(s,e)=>(t,r)=>e(t,r,s);let O=class extends a.Disposable{constructor(e,t,r,n,i,o){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ue);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=r,this._sheetsCrosshairHighlightService=n,this._contextService=i,this._refSelectionsService=o,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const r=t.getRowCount(),n=t.getColumnCount(),i=[];for(const o of e){const{startRow:c,endRow:g,startColumn:v,endColumn:C}=o.range;g-c+1===r||C-v+1===n||i.push(o.range)}this._rangeCollection.setSelectedRanges(i);for(const o of i)this.addSelection(o,t)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(u.combineLatest([this._contextService.subscribeContextValue$(M.REF_SELECTIONS_ENABLED).pipe(u.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(u.tap(t=>this._color=t)),u.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),u.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,r,n,i,o,c])=>{if(this._clear(),!n)return;const g=t?c:o;this._rangeCollection.reset(),this._transformSelection(g,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const r=t.getRowCount(),n=t.getColumnCount(),{startRow:i,endRow:o,startColumn:c,endColumn:g}=e,v={startRow:i,endRow:o,startColumn:0,endColumn:c-1},C={startRow:i,endRow:o,startColumn:g+1,endColumn:n},m={startRow:0,endRow:i-1,startColumn:c,endColumn:g},H={startRow:o+1,endRow:r,startColumn:c,endColumn:g};for(const _ of[v,C,m,H])_.startRow<=_.endRow&&_.startColumn<=_.endColumn&&this._rangeCollection.addRange(_)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,r,n){const{startRow:i,endRow:o,startColumn:c,endColumn:g}=e,v=$.getCoordByCell(i,c,r,n),C=$.getCoordByCell(o,g,r,n),{startX:m,startY:H}=v,{endX:_,endY:B}=C,Z=_-m,q=B-H,W={left:m,top:H,color:new a.ColorKit(this._color).toRgb(),width:Z,height:q,zIndex:ge,evented:!1},N=new de(`crosshair-${t}`,W);this._shapes.push(N),r.addObject(N)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:r}=this._context;this._clear();for(let n=0;n<e.length;n++){const i=e[n];this._addShapes(i,n,r,t)}r.makeDirty(!0)}async dispose(){super.dispose()}};O=_e([p(1,a.Inject($.SheetSkeletonManagerService)),p(2,a.Inject(M.SheetsSelectionsService)),p(3,a.Inject(d)),p(4,a.Inject(a.IContextService)),p(5,M.IRefSelectionsService)],O);var Se=Object.getOwnPropertyDescriptor,ve=(s,e,t,r)=>{for(var n=r>1?void 0:r?Se(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},T=(s,e)=>(t,r)=>e(t,r,s),R;exports.UniverSheetsCrosshairHighlightPlugin=(R=class extends a.Plugin{constructor(e=V,t,r,n){super(),this._config=e,this._injector=t,this._renderManagerService=r,this._configService=n;const{...i}=a.merge({},V,this._config);this._configService.setConfig(K,i)}onStarting(){[[d],[b]].forEach(e=>this._injector.add(e))}onReady(){[[O]].forEach(e=>this._injector.add(e)),this._injector.get(b),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[O])}},l(R,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(R,"type",a.UniverInstanceType.UNIVER_SHEET),R);exports.UniverSheetsCrosshairHighlightPlugin=ve([T(1,a.Inject(a.Injector)),T(2,w.IRenderManagerService),T(3,a.IConfigService)],exports.UniverSheetsCrosshairHighlightPlugin);exports.CROSSHAIR_HIGHLIGHT_COLORS=P;exports.DisableCrosshairHighlightOperation=k;exports.EnableCrosshairHighlightOperation=U;exports.SetCrosshairHighlightColorOperation=x;exports.SheetsCrosshairHighlightService=d;exports.ToggleCrosshairHighlightOperation=I;
1
+ "use strict";var F=Object.defineProperty;var X=(i,e,t)=>e in i?F(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>X(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),w=require("@univerjs/engine-render"),f=require("@univerjs/ui"),u=require("rxjs"),j=require("react/jsx-runtime"),S=require("react"),M=require("@univerjs/sheets"),$=require("@univerjs/sheets-ui"),K="sheets-crosshair-highlight.config",V={};var h=function(){return h=Object.assign||function(i){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(i[s]=e[s])}return i},h.apply(this,arguments)},z=function(i,e){var t={};for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&e.indexOf(r)<0&&(t[r]=i[r]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(i);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(i,r[s])&&(t[r[s]]=i[r[s]]);return t},A=S.forwardRef(function(i,e){var t=i.icon,r=i.id,s=i.className,n=i.extend,o=z(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(r," ").concat(s||"").trim(),g=S.useRef("_".concat(ee()));return L(t,"".concat(r),{defIds:t.defIds,idSuffix:g.current},h({ref:e,className:c},o),n)});function L(i,e,t,r,s){return S.createElement(i.tag,h(h({key:e},J(i,t,s)),r),(Q(i,t).children||[]).map(function(n,o){return L(n,"".concat(e,"-").concat(i.tag,"-").concat(o),t,void 0,s)}))}function J(i,e,t){var r=h({},i.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),i.tag==="mask"&&r.id&&(r.id=r.id+e.idSuffix),Object.entries(r).forEach(function(n){var o=n[0],c=n[1];o==="mask"&&typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var s=e.defIds;return!s||s.length===0||(i.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(n){var o=n[0],c=n[1];typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Q(i,e){var t,r=e.defIds;return!r||r.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?h(h({},i),{children:i.children.map(function(s){return typeof s.attrs.id=="string"&&r&&r.indexOf(s.attrs.id)>-1?h(h({},s),{attrs:h(h({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):i}function ee(){return Math.random().toString(36).substring(2,8)}A.displayName="UniverIcon";var te={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#E5E5E5",d:"M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z"}},{tag:"path",attrs:{fill:"#fff",d:"M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z"}},{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"}}]},G=S.forwardRef(function(i,e){return S.createElement(A,Object.assign({},i,{id:"cross-highlighting-single",ref:e,icon:te}))});G.displayName="CrossHighlightingSingle";const x=["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)"];class d extends a.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new u.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new u.BehaviorSubject(x[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(t){this._enabled$.next(t)}setColor(t){this._color$.next(t)}}const I={id:"sheet.operation.toggle-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(d),t=e.enabled;return e.setEnabled(!t),!0}},N={id:"sheet.operation.set-crosshair-highlight-color",type:a.CommandType.OPERATION,handler(i,{value:e}){const t=i.get(d);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},k={id:"sheet.operation.enable-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(d);return e.enabled?!1:(e.setEnabled(!0),!0)}},U={id:"sheet.operation.disable-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(d);return e.enabled?(e.setEnabled(!1),!0):!1}};function D(i){var e,t,r="";if(typeof i=="string"||typeof i=="number")r+=i;else if(typeof i=="object")if(Array.isArray(i)){var s=i.length;for(e=0;e<s;e++)i[e]&&(t=D(i[e]))&&(r&&(r+=" "),r+=t)}else for(t in i)i[t]&&(r&&(r+=" "),r+=t);return r}function re(){for(var i,e,t=0,r="",s=arguments.length;t<s;t++)(i=arguments[t])&&(e=D(i))&&(r&&(r+=" "),r+=e);return r}const ie="univer-crosshair-highlight-overlay",se="univer-crosshair-highlight-item",ne="univer-crosshair-highlight-item-selected",E={crosshairHighlightOverlay:ie,crosshairHighlightItem:se,crosshairHighlightItemSelected:ne};function oe(i){const{onChange:e}=i,t=f.useDependency(d),r=f.useObservable(t.color$),s=S.useCallback(n=>{e==null||e(n)},[e]);return j.jsx("div",{className:E.crosshairHighlightOverlay,children:x.map(n=>j.jsx("div",{className:re(E.crosshairHighlightItem,{[E.crosshairHighlightItemSelected]:n===r}),style:{backgroundColor:n},onClick:()=>s(n)},n))})}const Y="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function ae(i){const e=i.get(d);return{id:I.id,tooltip:"crosshair.button.tooltip",type:f.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingSingle",selections:[{label:{name:Y,hoverable:!1}}],selectionsCommandId:N.id,activated$:e.enabled$,hidden$:f.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_SHEET)}}const ce={[f.ContextMenuPosition.FOOTER_MENU]:{[f.ContextMenuGroup.OTHERS]:{[I.id]:{order:0,menuItemFactory:ae}}}};var le=Object.getOwnPropertyDescriptor,he=(i,e,t,r)=>{for(var s=r>1?void 0:r?le(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},y=(i,e)=>(t,r)=>e(t,r,i);let R=class extends a.Disposable{constructor(i,e,t){super(),this._componentMgr=i,this._menuManagerService=e,this._cmdSrv=t,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[I,N,k,U].forEach(i=>this._cmdSrv.registerCommand(i))}_initMenus(){this._menuManagerService.mergeMenu(ce)}_initComponents(){this._componentMgr.register(Y,oe),this._componentMgr.register("CrossHighlightingSingle",G)}};R=he([y(0,a.Inject(f.ComponentManager)),y(1,f.IMenuManagerService),y(2,a.ICommandService)],R);const ge=1;class ue{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const t=this._getIntersects(e),r=this._getSplitRanges(e,t);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let r=[e];for(const s of t.concat(this._selectedRanges)){const n=[];for(const o of r){const c=a.Rectangle.subtract(o,s);c&&c.length>0&&n.push(...c)}r=n}return r.filter(s=>s.startRow<=s.endRow&&s.startColumn<=s.endColumn)}_getIntersects(e){const t=[];for(const r of this._ranges){const s=a.Rectangle.getIntersects(r,e);s&&t.push(s)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class de extends w.Shape{constructor(t,r){super(t,r);l(this,"_color");r&&this.setShapeProps(r)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){var s,n;const r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(n=(s=this._color)==null?void 0:s.a)!=null?n:.5})`;w.Rect.drawWith(t,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}}var fe=Object.getOwnPropertyDescriptor,_e=(i,e,t,r)=>{for(var s=r>1?void 0:r?fe(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},p=(i,e)=>(t,r)=>e(t,r,i);let O=class extends a.Disposable{constructor(e,t,r,s,n,o){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ue);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=r,this._sheetsCrosshairHighlightService=s,this._contextService=n,this._refSelectionsService=o,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const r=t.getRowCount(),s=t.getColumnCount(),n=[];for(const o of e){const{startRow:c,endRow:g,startColumn:v,endColumn:C}=o.range;g-c+1===r||C-v+1===s||n.push(o.range)}this._rangeCollection.setSelectedRanges(n);for(const o of n)this.addSelection(o,t)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(u.combineLatest([this._contextService.subscribeContextValue$(M.REF_SELECTIONS_ENABLED).pipe(u.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(u.tap(t=>this._color=t)),u.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),u.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,r,s,n,o,c])=>{if(this._clear(),!s)return;const g=t?c:o;this._rangeCollection.reset(),this._transformSelection(g,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const r=t.getRowCount(),s=t.getColumnCount(),{startRow:n,endRow:o,startColumn:c,endColumn:g}=e,v={startRow:n,endRow:o,startColumn:0,endColumn:c-1},C={startRow:n,endRow:o,startColumn:g+1,endColumn:s},m={startRow:0,endRow:n-1,startColumn:c,endColumn:g},H={startRow:o+1,endRow:r,startColumn:c,endColumn:g};for(const _ of[v,C,m,H])_.startRow<=_.endRow&&_.startColumn<=_.endColumn&&this._rangeCollection.addRange(_)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,r,s){const{startRow:n,endRow:o,startColumn:c,endColumn:g}=e,v=$.getCoordByCell(n,c,r,s),C=$.getCoordByCell(o,g,r,s),{startX:m,startY:H}=v,{endX:_,endY:B}=C,Z=_-m,q=B-H,W={left:m,top:H,color:new a.ColorKit(this._color).toRgb(),width:Z,height:q,zIndex:ge,evented:!1},P=new de(`crosshair-${t}`,W);this._shapes.push(P),r.addObject(P)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:r}=this._context;this._clear();for(let s=0;s<e.length;s++){const n=e[s];this._addShapes(n,s,r,t)}r.makeDirty(!0)}async dispose(){super.dispose()}};O=_e([p(1,a.Inject($.SheetSkeletonManagerService)),p(2,a.Inject(M.SheetsSelectionsService)),p(3,a.Inject(d)),p(4,a.Inject(a.IContextService)),p(5,M.IRefSelectionsService)],O);var Se=Object.getOwnPropertyDescriptor,ve=(i,e,t,r)=>{for(var s=r>1?void 0:r?Se(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},T=(i,e)=>(t,r)=>e(t,r,i),b;exports.UniverSheetsCrosshairHighlightPlugin=(b=class extends a.Plugin{constructor(e=V,t,r,s){super(),this._config=e,this._injector=t,this._renderManagerService=r,this._configService=s;const{...n}=a.merge({},V,this._config);this._configService.setConfig(K,n)}onStarting(){[[d],[R]].forEach(e=>this._injector.add(e))}onReady(){[[O]].forEach(e=>this._injector.add(e)),this._injector.get(R),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[O])}},l(b,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(b,"type",a.UniverInstanceType.UNIVER_SHEET),b);exports.UniverSheetsCrosshairHighlightPlugin=ve([T(1,a.Inject(a.Injector)),T(2,w.IRenderManagerService),T(3,a.IConfigService)],exports.UniverSheetsCrosshairHighlightPlugin);exports.CROSSHAIR_HIGHLIGHT_COLORS=x;exports.DisableCrosshairHighlightOperation=U;exports.EnableCrosshairHighlightOperation=k;exports.SetCrosshairHighlightColorOperation=N;exports.SheetsCrosshairHighlightService=d;exports.ToggleCrosshairHighlightOperation=I;
package/lib/es/index.js CHANGED
@@ -1,63 +1,66 @@
1
1
  var J = Object.defineProperty;
2
- var Q = (r, e, t) => e in r ? J(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var c = (r, e, t) => Q(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as w, CommandType as R, UniverInstanceType as E, Inject as u, ICommandService as ee, RANGE_TYPE as f, Rectangle as T, IContextService as te, ColorKit as re, Plugin as se, merge as ne, Injector as ie, IConfigService as oe } from "@univerjs/core";
2
+ var Q = (s, e, t) => e in s ? J(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var c = (s, e, t) => Q(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Disposable as w, CommandType as R, UniverInstanceType as E, Inject as u, ICommandService as ee, RANGE_TYPE as f, Rectangle as x, IContextService as te, ColorKit as re, Plugin as se, merge as ne, Injector as ie, IConfigService as oe } from "@univerjs/core";
5
5
  import { Shape as ae, Rect as ce, IRenderManagerService as le } from "@univerjs/engine-render";
6
6
  import { useDependency as he, useObservable as ge, getMenuHiddenObservable as de, MenuItemType as ue, ContextMenuPosition as fe, ContextMenuGroup as _e, ComponentManager as Se, IMenuManagerService as ve } from "@univerjs/ui";
7
- import { BehaviorSubject as x, combineLatest as me, merge as V, startWith as Ce, tap as pe, map as N } from "rxjs";
7
+ import { BehaviorSubject as T, combineLatest as me, merge as V, startWith as Ce, tap as pe, map as N } from "rxjs";
8
8
  import { jsx as P } from "react/jsx-runtime";
9
9
  import { forwardRef as k, useRef as He, createElement as G, useCallback as be } from "react";
10
10
  import { SheetsSelectionsService as Re, IRefSelectionsService as Oe, REF_SELECTIONS_ENABLED as Ie } from "@univerjs/sheets";
11
11
  import { SheetSkeletonManagerService as ye, getCoordByCell as j } from "@univerjs/sheets-ui";
12
12
  const Ee = "sheets-crosshair-highlight.config", L = {};
13
13
  var l = function() {
14
- return l = Object.assign || function(r) {
15
- for (var e, t = 1, s = arguments.length; t < s; t++) {
14
+ return l = Object.assign || function(s) {
15
+ for (var e, t = 1, r = arguments.length; t < r; t++) {
16
16
  e = arguments[t];
17
- for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = e[n]);
17
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && (s[n] = e[n]);
18
18
  }
19
- return r;
19
+ return s;
20
20
  }, l.apply(this, arguments);
21
- }, we = function(r, e) {
21
+ }, we = function(s, e) {
22
22
  var t = {};
23
- for (var s in r) Object.prototype.hasOwnProperty.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
24
- if (r != null && typeof Object.getOwnPropertySymbols == "function")
25
- for (var n = 0, s = Object.getOwnPropertySymbols(r); n < s.length; n++)
26
- e.indexOf(s[n]) < 0 && Object.prototype.propertyIsEnumerable.call(r, s[n]) && (t[s[n]] = r[s[n]]);
23
+ for (var r in s) Object.prototype.hasOwnProperty.call(s, r) && e.indexOf(r) < 0 && (t[r] = s[r]);
24
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
25
+ for (var n = 0, r = Object.getOwnPropertySymbols(s); n < r.length; n++)
26
+ e.indexOf(r[n]) < 0 && Object.prototype.propertyIsEnumerable.call(s, r[n]) && (t[r[n]] = s[r[n]]);
27
27
  return t;
28
- }, U = k(function(r, e) {
29
- var t = r.icon, s = r.id, n = r.className, i = r.extend, o = we(r, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(s, " ").concat(n || "").trim(), h = He("_".concat(Te()));
30
- return D(t, "".concat(s), { defIds: t.defIds, idSuffix: h.current }, l({ ref: e, className: a }, o), i);
28
+ }, U = k(function(s, e) {
29
+ var t = s.icon, r = s.id, n = s.className, i = s.extend, o = we(s, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(r, " ").concat(n || "").trim(), h = He("_".concat(xe()));
30
+ return D(t, "".concat(r), { defIds: t.defIds, idSuffix: h.current }, l({ ref: e, className: a }, o), i);
31
31
  });
32
- function D(r, e, t, s, n) {
33
- return G(r.tag, l(l({ key: e }, Me(r, t, n)), s), ($e(r, t).children || []).map(function(i, o) {
34
- return D(i, "".concat(e, "-").concat(r.tag, "-").concat(o), t, void 0, n);
32
+ function D(s, e, t, r, n) {
33
+ return G(s.tag, l(l({ key: e }, Me(s, t, n)), r), ($e(s, t).children || []).map(function(i, o) {
34
+ return D(i, "".concat(e, "-").concat(s.tag, "-").concat(o), t, void 0, n);
35
35
  }));
36
36
  }
37
- function Me(r, e, t) {
38
- var s = l({}, r.attrs);
39
- t != null && t.colorChannel1 && s.fill === "colorChannel1" && (s.fill = t.colorChannel1);
37
+ function Me(s, e, t) {
38
+ var r = l({}, s.attrs);
39
+ t != null && t.colorChannel1 && r.fill === "colorChannel1" && (r.fill = t.colorChannel1), s.tag === "mask" && r.id && (r.id = r.id + e.idSuffix), Object.entries(r).forEach(function(i) {
40
+ var o = i[0], a = i[1];
41
+ o === "mask" && typeof a == "string" && (r[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
42
+ });
40
43
  var n = e.defIds;
41
- return !n || n.length === 0 || (r.tag === "use" && s["xlink:href"] && (s["xlink:href"] = s["xlink:href"] + e.idSuffix), Object.entries(s).forEach(function(i) {
44
+ return !n || n.length === 0 || (s.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + e.idSuffix), Object.entries(r).forEach(function(i) {
42
45
  var o = i[0], a = i[1];
43
- typeof a == "string" && (s[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
44
- })), s;
46
+ typeof a == "string" && (r[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
47
+ })), r;
45
48
  }
46
- function $e(r, e) {
47
- var t, s = e.defIds;
48
- return !s || s.length === 0 ? r : r.tag === "defs" && (!((t = r.children) === null || t === void 0) && t.length) ? l(l({}, r), { children: r.children.map(function(n) {
49
- return typeof n.attrs.id == "string" && s && s.indexOf(n.attrs.id) > -1 ? l(l({}, n), { attrs: l(l({}, n.attrs), { id: n.attrs.id + e.idSuffix }) }) : n;
50
- }) }) : r;
49
+ function $e(s, e) {
50
+ var t, r = e.defIds;
51
+ return !r || r.length === 0 ? s : s.tag === "defs" && (!((t = s.children) === null || t === void 0) && t.length) ? l(l({}, s), { children: s.children.map(function(n) {
52
+ return typeof n.attrs.id == "string" && r && r.indexOf(n.attrs.id) > -1 ? l(l({}, n), { attrs: l(l({}, n.attrs), { id: n.attrs.id + e.idSuffix }) }) : n;
53
+ }) }) : s;
51
54
  }
52
- function Te() {
55
+ function xe() {
53
56
  return Math.random().toString(36).substring(2, 8);
54
57
  }
55
58
  U.displayName = "UniverIcon";
56
- var xe = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "#E5E5E5", d: "M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z" } }, { tag: "path", attrs: { fill: "#fff", d: "M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z" } }, { 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" } }] }, Z = k(function(r, e) {
57
- return G(U, Object.assign({}, r, {
59
+ var Te = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "#E5E5E5", d: "M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z" } }, { tag: "path", attrs: { fill: "#fff", d: "M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z" } }, { 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" } }] }, Z = k(function(s, e) {
60
+ return G(U, Object.assign({}, s, {
58
61
  id: "cross-highlighting-single",
59
62
  ref: e,
60
- icon: xe
63
+ icon: Te
61
64
  }));
62
65
  });
63
66
  Z.displayName = "CrossHighlightingSingle";
@@ -82,9 +85,9 @@ const B = [
82
85
  class g extends w {
83
86
  constructor() {
84
87
  super(...arguments);
85
- c(this, "_enabled$", new x(!1));
88
+ c(this, "_enabled$", new T(!1));
86
89
  c(this, "enabled$", this._enabled$.asObservable());
87
- c(this, "_color$", new x(B[0]));
90
+ c(this, "_color$", new T(B[0]));
88
91
  c(this, "color$", this._color$.asObservable());
89
92
  }
90
93
  get enabled() {
@@ -106,59 +109,59 @@ class g extends w {
106
109
  const M = {
107
110
  id: "sheet.operation.toggle-crosshair-highlight",
108
111
  type: R.OPERATION,
109
- handler(r) {
110
- const e = r.get(g), t = e.enabled;
112
+ handler(s) {
113
+ const e = s.get(g), t = e.enabled;
111
114
  return e.setEnabled(!t), !0;
112
115
  }
113
116
  }, W = {
114
117
  id: "sheet.operation.set-crosshair-highlight-color",
115
118
  type: R.OPERATION,
116
- handler(r, { value: e }) {
117
- const t = r.get(g);
119
+ handler(s, { value: e }) {
120
+ const t = s.get(g);
118
121
  return t.enabled || t.setEnabled(!0), t.setColor(e), !0;
119
122
  }
120
123
  }, Ve = {
121
124
  id: "sheet.operation.enable-crosshair-highlight",
122
125
  type: R.OPERATION,
123
- handler(r) {
124
- const e = r.get(g);
126
+ handler(s) {
127
+ const e = s.get(g);
125
128
  return e.enabled ? !1 : (e.setEnabled(!0), !0);
126
129
  }
127
130
  }, Ne = {
128
131
  id: "sheet.operation.disable-crosshair-highlight",
129
132
  type: R.OPERATION,
130
- handler(r) {
131
- const e = r.get(g);
133
+ handler(s) {
134
+ const e = s.get(g);
132
135
  return e.enabled ? (e.setEnabled(!1), !0) : !1;
133
136
  }
134
137
  };
135
- function Y(r) {
136
- var e, t, s = "";
137
- if (typeof r == "string" || typeof r == "number") s += r;
138
- else if (typeof r == "object") if (Array.isArray(r)) {
139
- var n = r.length;
140
- for (e = 0; e < n; e++) r[e] && (t = Y(r[e])) && (s && (s += " "), s += t);
141
- } else for (t in r) r[t] && (s && (s += " "), s += t);
142
- return s;
138
+ function Y(s) {
139
+ var e, t, r = "";
140
+ if (typeof s == "string" || typeof s == "number") r += s;
141
+ else if (typeof s == "object") if (Array.isArray(s)) {
142
+ var n = s.length;
143
+ for (e = 0; e < n; e++) s[e] && (t = Y(s[e])) && (r && (r += " "), r += t);
144
+ } else for (t in s) s[t] && (r && (r += " "), r += t);
145
+ return r;
143
146
  }
144
147
  function Pe() {
145
- for (var r, e, t = 0, s = "", n = arguments.length; t < n; t++) (r = arguments[t]) && (e = Y(r)) && (s && (s += " "), s += e);
146
- return s;
148
+ for (var s, e, t = 0, r = "", n = arguments.length; t < n; t++) (s = arguments[t]) && (e = Y(s)) && (r && (r += " "), r += e);
149
+ return r;
147
150
  }
148
151
  const je = "univer-crosshair-highlight-overlay", Le = "univer-crosshair-highlight-item", Ae = "univer-crosshair-highlight-item-selected", O = {
149
152
  crosshairHighlightOverlay: je,
150
153
  crosshairHighlightItem: Le,
151
154
  crosshairHighlightItemSelected: Ae
152
155
  };
153
- function ke(r) {
154
- const { onChange: e } = r, t = he(g), s = ge(t.color$), n = be((i) => {
156
+ function ke(s) {
157
+ const { onChange: e } = s, t = he(g), r = ge(t.color$), n = be((i) => {
155
158
  e == null || e(i);
156
159
  }, [e]);
157
160
  return /* @__PURE__ */ P("div", { className: O.crosshairHighlightOverlay, children: B.map((i) => /* @__PURE__ */ P(
158
161
  "div",
159
162
  {
160
163
  className: Pe(O.crosshairHighlightItem, {
161
- [O.crosshairHighlightItemSelected]: i === s
164
+ [O.crosshairHighlightItemSelected]: i === r
162
165
  }),
163
166
  style: { backgroundColor: i },
164
167
  onClick: () => n(i)
@@ -167,8 +170,8 @@ function ke(r) {
167
170
  )) });
168
171
  }
169
172
  const F = "CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";
170
- function Ge(r) {
171
- const e = r.get(g);
173
+ function Ge(s) {
174
+ const e = s.get(g);
172
175
  return {
173
176
  id: M.id,
174
177
  tooltip: "crosshair.button.tooltip",
@@ -184,7 +187,7 @@ function Ge(r) {
184
187
  ],
185
188
  selectionsCommandId: W.id,
186
189
  activated$: e.enabled$,
187
- hidden$: de(r, E.UNIVER_SHEET)
190
+ hidden$: de(s, E.UNIVER_SHEET)
188
191
  };
189
192
  }
190
193
  const Ue = {
@@ -197,14 +200,14 @@ const Ue = {
197
200
  }
198
201
  }
199
202
  };
200
- var De = Object.getOwnPropertyDescriptor, Ze = (r, e, t, s) => {
201
- for (var n = s > 1 ? void 0 : s ? De(e, t) : e, i = r.length - 1, o; i >= 0; i--)
202
- (o = r[i]) && (n = o(n) || n);
203
+ var De = Object.getOwnPropertyDescriptor, Ze = (s, e, t, r) => {
204
+ for (var n = r > 1 ? void 0 : r ? De(e, t) : e, i = s.length - 1, o; i >= 0; i--)
205
+ (o = s[i]) && (n = o(n) || n);
203
206
  return n;
204
- }, I = (r, e) => (t, s) => e(t, s, r);
207
+ }, I = (s, e) => (t, r) => e(t, r, s);
205
208
  let H = class extends w {
206
- constructor(r, e, t) {
207
- super(), this._componentMgr = r, this._menuManagerService = e, this._cmdSrv = t, this._initCommands(), this._initMenus(), this._initComponents();
209
+ constructor(s, e, t) {
210
+ super(), this._componentMgr = s, this._menuManagerService = e, this._cmdSrv = t, this._initCommands(), this._initMenus(), this._initComponents();
208
211
  }
209
212
  _initCommands() {
210
213
  [
@@ -212,7 +215,7 @@ let H = class extends w {
212
215
  W,
213
216
  Ve,
214
217
  Ne
215
- ].forEach((r) => this._cmdSrv.registerCommand(r));
218
+ ].forEach((s) => this._cmdSrv.registerCommand(s));
216
219
  }
217
220
  _initMenus() {
218
221
  this._menuManagerService.mergeMenu(Ue);
@@ -235,28 +238,28 @@ class We {
235
238
  addRange(e) {
236
239
  if (e.rangeType === f.COLUMN || e.rangeType === f.ROW || e.rangeType === f.ALL)
237
240
  return;
238
- const t = this._getIntersects(e), s = this._getSplitRanges(e, t);
239
- s.length > 0 && this._ranges.push(...s);
241
+ const t = this._getIntersects(e), r = this._getSplitRanges(e, t);
242
+ r.length > 0 && this._ranges.push(...r);
240
243
  }
241
244
  setSelectedRanges(e) {
242
245
  this._selectedRanges = e;
243
246
  }
244
247
  _getSplitRanges(e, t) {
245
- let s = [e];
248
+ let r = [e];
246
249
  for (const n of t.concat(this._selectedRanges)) {
247
250
  const i = [];
248
- for (const o of s) {
249
- const a = T.subtract(o, n);
251
+ for (const o of r) {
252
+ const a = x.subtract(o, n);
250
253
  a && a.length > 0 && i.push(...a);
251
254
  }
252
- s = i;
255
+ r = i;
253
256
  }
254
- return s.filter((n) => n.startRow <= n.endRow && n.startColumn <= n.endColumn);
257
+ return r.filter((n) => n.startRow <= n.endRow && n.startColumn <= n.endColumn);
255
258
  }
256
259
  _getIntersects(e) {
257
260
  const t = [];
258
- for (const s of this._ranges) {
259
- const n = T.getIntersects(s, e);
261
+ for (const r of this._ranges) {
262
+ const n = x.getIntersects(r, e);
260
263
  n && t.push(n);
261
264
  }
262
265
  return t;
@@ -269,11 +272,11 @@ class We {
269
272
  }
270
273
  }
271
274
  class Ye extends ae {
272
- constructor(t, s) {
273
- super(t, s);
275
+ constructor(t, r) {
276
+ super(t, r);
274
277
  // protected _showHighLight = false;
275
278
  c(this, "_color");
276
- s && this.setShapeProps(s);
279
+ r && this.setShapeProps(r);
277
280
  }
278
281
  setShapeProps(t) {
279
282
  typeof t.color < "u" && (this._color = t.color), this.transformByState({
@@ -282,37 +285,38 @@ class Ye extends ae {
282
285
  });
283
286
  }
284
287
  _draw(t) {
285
- const s = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${this._color.a})`;
288
+ var n, i;
289
+ const r = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(i = (n = this._color) == null ? void 0 : n.a) != null ? i : 0.5})`;
286
290
  ce.drawWith(t, {
287
291
  width: this.width,
288
292
  height: this.height,
289
- fill: s,
293
+ fill: r,
290
294
  stroke: void 0,
291
295
  strokeWidth: 0,
292
296
  evented: !1
293
297
  });
294
298
  }
295
299
  }
296
- var Fe = Object.getOwnPropertyDescriptor, Xe = (r, e, t, s) => {
297
- for (var n = s > 1 ? void 0 : s ? Fe(e, t) : e, i = r.length - 1, o; i >= 0; i--)
298
- (o = r[i]) && (n = o(n) || n);
300
+ var Fe = Object.getOwnPropertyDescriptor, Xe = (s, e, t, r) => {
301
+ for (var n = r > 1 ? void 0 : r ? Fe(e, t) : e, i = s.length - 1, o; i >= 0; i--)
302
+ (o = s[i]) && (n = o(n) || n);
299
303
  return n;
300
- }, v = (r, e) => (t, s) => e(t, s, r);
304
+ }, v = (s, e) => (t, r) => e(t, r, s);
301
305
  let b = class extends w {
302
- constructor(e, t, s, n, i, o) {
306
+ constructor(e, t, r, n, i, o) {
303
307
  super();
304
308
  c(this, "_shapes", []);
305
309
  c(this, "_rangeCollection", new We());
306
310
  c(this, "_color", "rgba(255,0,0,0.5)");
307
- this._context = e, this._sheetSkeletonManagerService = t, this._sheetsSelectionsService = s, this._sheetsCrosshairHighlightService = n, this._contextService = i, this._refSelectionsService = o, this._initRenderListener();
311
+ this._context = e, this._sheetSkeletonManagerService = t, this._sheetsSelectionsService = r, this._sheetsCrosshairHighlightService = n, this._contextService = i, this._refSelectionsService = o, this._initRenderListener();
308
312
  }
309
313
  _transformSelection(e, t) {
310
314
  if (!e)
311
315
  return;
312
- const s = t.getRowCount(), n = t.getColumnCount(), i = [];
316
+ const r = t.getRowCount(), n = t.getColumnCount(), i = [];
313
317
  for (const o of e) {
314
318
  const { startRow: a, endRow: h, startColumn: _, endColumn: S } = o.range;
315
- h - a + 1 === s || S - _ + 1 === n || i.push(o.range);
319
+ h - a + 1 === r || S - _ + 1 === n || i.push(o.range);
316
320
  }
317
321
  this._rangeCollection.setSelectedRanges(i);
318
322
  for (const o of i)
@@ -339,7 +343,7 @@ let b = class extends w {
339
343
  this._sheetsSelectionsService.selectionSet$,
340
344
  e.activeSheet$.pipe(N(() => this._refSelectionsService.getCurrentSelections()))
341
345
  )
342
- ]).subscribe(([t, s, n, i, o, a]) => {
346
+ ]).subscribe(([t, r, n, i, o, a]) => {
343
347
  if (this._clear(), !n) return;
344
348
  const h = t ? a : o;
345
349
  this._rangeCollection.reset(), this._transformSelection(h, e.getActiveSheet()), this.render(this._rangeCollection.getRanges());
@@ -348,7 +352,7 @@ let b = class extends w {
348
352
  addSelection(e, t) {
349
353
  if (e.rangeType === f.COLUMN || e.rangeType === f.ROW || e.rangeType === f.ALL)
350
354
  return;
351
- const s = t.getRowCount(), n = t.getColumnCount(), { startRow: i, endRow: o, startColumn: a, endColumn: h } = e, _ = {
355
+ const r = t.getRowCount(), n = t.getColumnCount(), { startRow: i, endRow: o, startColumn: a, endColumn: h } = e, _ = {
352
356
  startRow: i,
353
357
  endRow: o,
354
358
  startColumn: 0,
@@ -365,7 +369,7 @@ let b = class extends w {
365
369
  endColumn: h
366
370
  }, C = {
367
371
  startRow: o + 1,
368
- endRow: s,
372
+ endRow: r,
369
373
  startColumn: a,
370
374
  endColumn: h
371
375
  };
@@ -377,8 +381,8 @@ let b = class extends w {
377
381
  e.dispose();
378
382
  }), this._shapes = [];
379
383
  }
380
- _addShapes(e, t, s, n) {
381
- const { startRow: i, endRow: o, startColumn: a, endColumn: h } = e, _ = j(i, a, s, n), S = j(o, h, s, n), { startX: m, startY: C } = _, { endX: d, endY: X } = S, K = d - m, z = X - C, q = {
384
+ _addShapes(e, t, r, n) {
385
+ const { startRow: i, endRow: o, startColumn: a, endColumn: h } = e, _ = j(i, a, r, n), S = j(o, h, r, n), { startX: m, startY: C } = _, { endX: d, endY: X } = S, K = d - m, z = X - C, q = {
382
386
  left: m,
383
387
  top: C,
384
388
  color: new re(this._color).toRgb(),
@@ -387,19 +391,19 @@ let b = class extends w {
387
391
  zIndex: Be,
388
392
  evented: !1
389
393
  }, $ = new Ye(`crosshair-${t}`, q);
390
- this._shapes.push($), s.addObject($);
394
+ this._shapes.push($), r.addObject($);
391
395
  }
392
396
  render(e) {
393
397
  const t = this._sheetSkeletonManagerService.getCurrentSkeleton();
394
398
  if (!t)
395
399
  return;
396
- const { scene: s } = this._context;
400
+ const { scene: r } = this._context;
397
401
  this._clear();
398
402
  for (let n = 0; n < e.length; n++) {
399
403
  const i = e[n];
400
- this._addShapes(i, n, s, t);
404
+ this._addShapes(i, n, r, t);
401
405
  }
402
- s.makeDirty(!0);
406
+ r.makeDirty(!0);
403
407
  }
404
408
  async dispose() {
405
409
  super.dispose();
@@ -412,14 +416,14 @@ b = Xe([
412
416
  v(4, u(te)),
413
417
  v(5, Oe)
414
418
  ], b);
415
- var Ke = Object.getOwnPropertyDescriptor, ze = (r, e, t, s) => {
416
- for (var n = s > 1 ? void 0 : s ? Ke(e, t) : e, i = r.length - 1, o; i >= 0; i--)
417
- (o = r[i]) && (n = o(n) || n);
419
+ var Ke = Object.getOwnPropertyDescriptor, ze = (s, e, t, r) => {
420
+ for (var n = r > 1 ? void 0 : r ? Ke(e, t) : e, i = s.length - 1, o; i >= 0; i--)
421
+ (o = s[i]) && (n = o(n) || n);
418
422
  return n;
419
- }, y = (r, e) => (t, s) => e(t, s, r), p;
423
+ }, y = (s, e) => (t, r) => e(t, r, s), p;
420
424
  let A = (p = class extends se {
421
- constructor(r = L, e, t, s) {
422
- super(), this._config = r, this._injector = e, this._renderManagerService = t, this._configService = s;
425
+ constructor(s = L, e, t, r) {
426
+ super(), this._config = s, this._injector = e, this._renderManagerService = t, this._configService = r;
423
427
  const { ...n } = ne(
424
428
  {},
425
429
  L,
@@ -431,12 +435,12 @@ let A = (p = class extends se {
431
435
  [
432
436
  [g],
433
437
  [H]
434
- ].forEach((r) => this._injector.add(r));
438
+ ].forEach((s) => this._injector.add(s));
435
439
  }
436
440
  onReady() {
437
441
  [
438
442
  [b]
439
- ].forEach((r) => this._injector.add(r)), this._injector.get(H), this._renderManagerService.registerRenderModule(E.UNIVER_SHEET, [b]);
443
+ ].forEach((s) => this._injector.add(s)), this._injector.get(H), this._renderManagerService.registerRenderModule(E.UNIVER_SHEET, [b]);
440
444
  }
441
445
  }, c(p, "pluginName", "SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"), c(p, "type", E.UNIVER_SHEET), p);
442
446
  A = ze([
@@ -7,25 +7,29 @@ import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
7
7
  export interface IFSheetCrosshairHighlightEventMixin {
8
8
  /**
9
9
  * Triggered when the crosshair highlight is enabled or disabled.
10
+ * @see {@link ICrosshairHighlightEnabledChangedEvent}
10
11
  * @example
11
12
  * ```ts
12
- * univerAPI.addEvent(univerAPI.Event.CrosshairHighlightEnabledChanged, (event) => {
13
- * const enabled = event.enabled;
14
- * const workbook = event.workbook;
15
- * const worksheet = event.worksheet;
13
+ * const disposable = univerAPI.addEvent(univerAPI.Event.CrosshairHighlightEnabledChanged, (params) => {
14
+ * const { enabled, workbook, worksheet } = params;
15
+ * console.log(params);
16
16
  * });
17
+ *
18
+ * // Remove the event listener, use `disposable.dispose()`
17
19
  * ```
18
20
  */
19
21
  readonly CrosshairHighlightEnabledChanged: 'CrosshairHighlightEnabledChanged';
20
22
  /**
21
23
  * Triggered when the crosshair highlight color is changed.
24
+ * @see {@link ICrosshairHighlightColorChangedEvent}
22
25
  * @example
23
26
  * ```ts
24
- * univerAPI.addEvent(univerAPI.Event.CrosshairHighlightColorChanged, (event) => {
25
- * const color = event.color;
26
- * const workbook = event.workbook;
27
- * const worksheet = event.worksheet;
27
+ * const disposable = univerAPI.addEvent(univerAPI.Event.CrosshairHighlightColorChanged, (params) => {
28
+ * const { color, workbook, worksheet } = params;
29
+ * console.log(params);
28
30
  * });
31
+ *
32
+ * // Remove the event listener, use `disposable.dispose()`
29
33
  * ```
30
34
  */
31
35
  readonly CrosshairHighlightColorChanged: 'CrosshairHighlightColorChanged';
@@ -78,39 +82,41 @@ export interface ISheetCrosshairHighlightEventConfigs {
78
82
  export interface IFUniverCrosshairHighlightMixin {
79
83
  /**
80
84
  * Enable or disable crosshair highlight.
81
- * @param {boolean} enabled if crosshair highlight should be enabled
82
- * @returns {FUniver} the FUniver instance
85
+ * @param {boolean} enabled - Whether to enable the crosshair highlight
86
+ * @returns {FUniver} The FUniver instance for chaining
83
87
  * @example
84
88
  * ```ts
85
- * univer.setCrosshairHighlightEnabled(true);
89
+ * univerAPI.setCrosshairHighlightEnabled(true);
86
90
  * ```
87
91
  */
88
92
  setCrosshairHighlightEnabled(enabled: boolean): FUniver;
89
93
  /**
90
94
  * Set the color of the crosshair highlight.
91
- * @param {string} color the color of the crosshair highlight
92
- * @returns {FUniver} the FUniver instance
95
+ * @param {string} color - The color of the crosshair highlight, if the color not has alpha channel, the alpha channel will be set to 0.5
96
+ * @returns {FUniver} The FUniver instance for chaining
93
97
  * @example
94
98
  * ```ts
95
- * univer.setCrosshairHighlightColor('#FF0000');
99
+ * univerAPI.setCrosshairHighlightColor('#FF0000');
100
+ * // or
101
+ * univerAPI.setCrosshairHighlightColor('rgba(232, 11, 11, 0.2)');
96
102
  * ```
97
103
  */
98
104
  setCrosshairHighlightColor(color: string): FUniver;
99
105
  /**
100
106
  * Get whether the crosshair highlight is enabled.
101
- * @returns {boolean} whether the crosshair highlight is enabled
107
+ * @returns {boolean} Whether the crosshair highlight is enabled
102
108
  * @example
103
109
  * ```ts
104
- * const enabled = univer.getCrosshairHighlightEnabled();
110
+ * console.log(univerAPI.getCrosshairHighlightEnabled());
105
111
  * ```
106
112
  */
107
113
  getCrosshairHighlightEnabled(): boolean;
108
114
  /**
109
115
  * Get the color of the crosshair highlight.
110
- * @returns {string} the color of the crosshair highlight
116
+ * @returns {string} The color of the crosshair highlight
111
117
  * @example
112
118
  * ```ts
113
- * const color = univer.getCrosshairHighlightColor();
119
+ * console.log(univerAPI.getCrosshairHighlightColor());
114
120
  * ```
115
121
  */
116
122
  getCrosshairHighlightColor(): string;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react"),require("@univerjs/sheets"),require("@univerjs/sheets-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","react","@univerjs/sheets","@univerjs/sheets-ui"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.UniverSheetsCrosshairHighlight={},h.UniverCore,h.UniverEngineRender,h.UniverUi,h.rxjs,h.React,h.React,h.UniverSheets,h.UniverSheetsUi))})(this,function(h,o,_,S,d,V,C,T,w){"use strict";var fe=Object.defineProperty;var _e=(h,o,_)=>o in h?fe(h,o,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[o]=_;var l=(h,o,_)=>_e(h,typeof o!="symbol"?o+"":o,_);var I;const Z="sheets-crosshair-highlight.config",A={};var g=function(){return g=Object.assign||function(r){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},g.apply(this,arguments)},q=function(r,e){var t={};for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&e.indexOf(i)<0&&(t[i]=r[i]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(r);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(r,i[n])&&(t[i[n]]=r[i[n]]);return t},L=C.forwardRef(function(r,e){var t=r.icon,i=r.id,n=r.className,s=r.extend,a=q(r,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(n||"").trim(),u=C.useRef("_".concat(X()));return x(t,"".concat(i),{defIds:t.defIds,idSuffix:u.current},g({ref:e,className:c},a),s)});function x(r,e,t,i,n){return C.createElement(r.tag,g(g({key:e},W(r,t,n)),i),(F(r,t).children||[]).map(function(s,a){return x(s,"".concat(e,"-").concat(r.tag,"-").concat(a),t,void 0,n)}))}function W(r,e,t){var i=g({},r.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var n=e.defIds;return!n||n.length===0||(r.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(s){var a=s[0],c=s[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function F(r,e){var t,i=e.defIds;return!i||i.length===0?r:r.tag==="defs"&&(!((t=r.children)===null||t===void 0)&&t.length)?g(g({},r),{children:r.children.map(function(n){return typeof n.attrs.id=="string"&&i&&i.indexOf(n.attrs.id)>-1?g(g({},n),{attrs:g(g({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):r}function X(){return Math.random().toString(36).substring(2,8)}L.displayName="UniverIcon";var K={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#E5E5E5",d:"M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z"}},{tag:"path",attrs:{fill:"#fff",d:"M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z"}},{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"}}]},G=C.forwardRef(function(r,e){return C.createElement(L,Object.assign({},r,{id:"cross-highlighting-single",ref:e,icon:K}))});G.displayName="CrossHighlightingSingle";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)"];class f extends o.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new d.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new d.BehaviorSubject(M[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(t){this._enabled$.next(t)}setColor(t){this._color$.next(t)}}const R={id:"sheet.operation.toggle-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f),t=e.enabled;return e.setEnabled(!t),!0}},$={id:"sheet.operation.set-crosshair-highlight-color",type:o.CommandType.OPERATION,handler(r,{value:e}){const t=r.get(f);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},U={id:"sheet.operation.enable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f);return e.enabled?!1:(e.setEnabled(!0),!0)}},k={id:"sheet.operation.disable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f);return e.enabled?(e.setEnabled(!1),!0):!1}};function D(r){var e,t,i="";if(typeof r=="string"||typeof r=="number")i+=r;else if(typeof r=="object")if(Array.isArray(r)){var n=r.length;for(e=0;e<n;e++)r[e]&&(t=D(r[e]))&&(i&&(i+=" "),i+=t)}else for(t in r)r[t]&&(i&&(i+=" "),i+=t);return i}function z(){for(var r,e,t=0,i="",n=arguments.length;t<n;t++)(r=arguments[t])&&(e=D(r))&&(i&&(i+=" "),i+=e);return i}const j={crosshairHighlightOverlay:"univer-crosshair-highlight-overlay",crosshairHighlightItem:"univer-crosshair-highlight-item",crosshairHighlightItemSelected:"univer-crosshair-highlight-item-selected"};function J(r){const{onChange:e}=r,t=S.useDependency(f),i=S.useObservable(t.color$),n=C.useCallback(s=>{e==null||e(s)},[e]);return V.jsx("div",{className:j.crosshairHighlightOverlay,children:M.map(s=>V.jsx("div",{className:z(j.crosshairHighlightItem,{[j.crosshairHighlightItemSelected]:s===i}),style:{backgroundColor:s},onClick:()=>n(s)},s))})}const Y="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function Q(r){const e=r.get(f);return{id:R.id,tooltip:"crosshair.button.tooltip",type:S.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingSingle",selections:[{label:{name:Y,hoverable:!1}}],selectionsCommandId:$.id,activated$:e.enabled$,hidden$:S.getMenuHiddenObservable(r,o.UniverInstanceType.UNIVER_SHEET)}}const ee={[S.ContextMenuPosition.FOOTER_MENU]:{[S.ContextMenuGroup.OTHERS]:{[R.id]:{order:0,menuItemFactory:Q}}}};var te=Object.getOwnPropertyDescriptor,ie=(r,e,t,i)=>{for(var n=i>1?void 0:i?te(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},P=(r,e)=>(t,i)=>e(t,i,r);let b=class extends o.Disposable{constructor(r,e,t){super(),this._componentMgr=r,this._menuManagerService=e,this._cmdSrv=t,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[R,$,U,k].forEach(r=>this._cmdSrv.registerCommand(r))}_initMenus(){this._menuManagerService.mergeMenu(ee)}_initComponents(){this._componentMgr.register(Y,J),this._componentMgr.register("CrossHighlightingSingle",G)}};b=ie([P(0,o.Inject(S.ComponentManager)),P(1,S.IMenuManagerService),P(2,o.ICommandService)],b);const re=1;class ne{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===o.RANGE_TYPE.COLUMN||e.rangeType===o.RANGE_TYPE.ROW||e.rangeType===o.RANGE_TYPE.ALL)return;const t=this._getIntersects(e),i=this._getSplitRanges(e,t);i.length>0&&this._ranges.push(...i)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let i=[e];for(const n of t.concat(this._selectedRanges)){const s=[];for(const a of i){const c=o.Rectangle.subtract(a,n);c&&c.length>0&&s.push(...c)}i=s}return i.filter(n=>n.startRow<=n.endRow&&n.startColumn<=n.endColumn)}_getIntersects(e){const t=[];for(const i of this._ranges){const n=o.Rectangle.getIntersects(i,e);n&&t.push(n)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class se extends _.Shape{constructor(t,i){super(t,i);l(this,"_color");i&&this.setShapeProps(i)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${this._color.a})`;_.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:void 0,strokeWidth:0,evented:!1})}}var oe=Object.getOwnPropertyDescriptor,ae=(r,e,t,i)=>{for(var n=i>1?void 0:i?oe(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},p=(r,e)=>(t,i)=>e(t,i,r);let O=class extends o.Disposable{constructor(e,t,i,n,s,a){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ne);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=i,this._sheetsCrosshairHighlightService=n,this._contextService=s,this._refSelectionsService=a,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const i=t.getRowCount(),n=t.getColumnCount(),s=[];for(const a of e){const{startRow:c,endRow:u,startColumn:m,endColumn:H}=a.range;u-c+1===i||H-m+1===n||s.push(a.range)}this._rangeCollection.setSelectedRanges(s);for(const a of s)this.addSelection(a,t)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(d.combineLatest([this._contextService.subscribeContextValue$(T.REF_SELECTIONS_ENABLED).pipe(d.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(d.tap(t=>this._color=t)),d.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(d.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),d.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(d.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,i,n,s,a,c])=>{if(this._clear(),!n)return;const u=t?c:a;this._rangeCollection.reset(),this._transformSelection(u,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===o.RANGE_TYPE.COLUMN||e.rangeType===o.RANGE_TYPE.ROW||e.rangeType===o.RANGE_TYPE.ALL)return;const i=t.getRowCount(),n=t.getColumnCount(),{startRow:s,endRow:a,startColumn:c,endColumn:u}=e,m={startRow:s,endRow:a,startColumn:0,endColumn:c-1},H={startRow:s,endRow:a,startColumn:u+1,endColumn:n},E={startRow:0,endRow:s-1,startColumn:c,endColumn:u},y={startRow:a+1,endRow:i,startColumn:c,endColumn:u};for(const v of[m,H,E,y])v.startRow<=v.endRow&&v.startColumn<=v.endColumn&&this._rangeCollection.addRange(v)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,i,n){const{startRow:s,endRow:a,startColumn:c,endColumn:u}=e,m=w.getCoordByCell(s,c,i,n),H=w.getCoordByCell(a,u,i,n),{startX:E,startY:y}=m,{endX:v,endY:le}=H,ge=v-E,ue=le-y,de={left:E,top:y,color:new o.ColorKit(this._color).toRgb(),width:ge,height:ue,zIndex:re,evented:!1},B=new se(`crosshair-${t}`,de);this._shapes.push(B),i.addObject(B)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:i}=this._context;this._clear();for(let n=0;n<e.length;n++){const s=e[n];this._addShapes(s,n,i,t)}i.makeDirty(!0)}async dispose(){super.dispose()}};O=ae([p(1,o.Inject(w.SheetSkeletonManagerService)),p(2,o.Inject(T.SheetsSelectionsService)),p(3,o.Inject(f)),p(4,o.Inject(o.IContextService)),p(5,T.IRefSelectionsService)],O);var he=Object.getOwnPropertyDescriptor,ce=(r,e,t,i)=>{for(var n=i>1?void 0:i?he(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},N=(r,e)=>(t,i)=>e(t,i,r);h.UniverSheetsCrosshairHighlightPlugin=(I=class extends o.Plugin{constructor(e=A,t,i,n){super(),this._config=e,this._injector=t,this._renderManagerService=i,this._configService=n;const{...s}=o.merge({},A,this._config);this._configService.setConfig(Z,s)}onStarting(){[[f],[b]].forEach(e=>this._injector.add(e))}onReady(){[[O]].forEach(e=>this._injector.add(e)),this._injector.get(b),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[O])}},l(I,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(I,"type",o.UniverInstanceType.UNIVER_SHEET),I),h.UniverSheetsCrosshairHighlightPlugin=ce([N(1,o.Inject(o.Injector)),N(2,_.IRenderManagerService),N(3,o.IConfigService)],h.UniverSheetsCrosshairHighlightPlugin),h.CROSSHAIR_HIGHLIGHT_COLORS=M,h.DisableCrosshairHighlightOperation=k,h.EnableCrosshairHighlightOperation=U,h.SetCrosshairHighlightColorOperation=$,h.SheetsCrosshairHighlightService=f,h.ToggleCrosshairHighlightOperation=R,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react"),require("@univerjs/sheets"),require("@univerjs/sheets-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","react","@univerjs/sheets","@univerjs/sheets-ui"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.UniverSheetsCrosshairHighlight={},h.UniverCore,h.UniverEngineRender,h.UniverUi,h.rxjs,h.React,h.React,h.UniverSheets,h.UniverSheetsUi))})(this,function(h,o,_,S,d,V,C,T,w){"use strict";var fe=Object.defineProperty;var _e=(h,o,_)=>o in h?fe(h,o,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[o]=_;var l=(h,o,_)=>_e(h,typeof o!="symbol"?o+"":o,_);var I;const Z="sheets-crosshair-highlight.config",A={};var g=function(){return g=Object.assign||function(r){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},g.apply(this,arguments)},q=function(r,e){var i={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.indexOf(t)<0&&(i[t]=r[t]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(r);n<t.length;n++)e.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(r,t[n])&&(i[t[n]]=r[t[n]]);return i},x=C.forwardRef(function(r,e){var i=r.icon,t=r.id,n=r.className,s=r.extend,a=q(r,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(n||"").trim(),u=C.useRef("_".concat(X()));return L(i,"".concat(t),{defIds:i.defIds,idSuffix:u.current},g({ref:e,className:c},a),s)});function L(r,e,i,t,n){return C.createElement(r.tag,g(g({key:e},W(r,i,n)),t),(F(r,i).children||[]).map(function(s,a){return L(s,"".concat(e,"-").concat(r.tag,"-").concat(a),i,void 0,n)}))}function W(r,e,i){var t=g({},r.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1),r.tag==="mask"&&t.id&&(t.id=t.id+e.idSuffix),Object.entries(t).forEach(function(s){var a=s[0],c=s[1];a==="mask"&&typeof c=="string"&&(t[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var n=e.defIds;return!n||n.length===0||(r.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var a=s[0],c=s[1];typeof c=="string"&&(t[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function F(r,e){var i,t=e.defIds;return!t||t.length===0?r:r.tag==="defs"&&(!((i=r.children)===null||i===void 0)&&i.length)?g(g({},r),{children:r.children.map(function(n){return typeof n.attrs.id=="string"&&t&&t.indexOf(n.attrs.id)>-1?g(g({},n),{attrs:g(g({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):r}function X(){return Math.random().toString(36).substring(2,8)}x.displayName="UniverIcon";var K={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#E5E5E5",d:"M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z"}},{tag:"path",attrs:{fill:"#fff",d:"M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z"}},{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"}}]},G=C.forwardRef(function(r,e){return C.createElement(x,Object.assign({},r,{id:"cross-highlighting-single",ref:e,icon:K}))});G.displayName="CrossHighlightingSingle";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)"];class f extends o.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new d.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new d.BehaviorSubject(M[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(i){this._enabled$.next(i)}setColor(i){this._color$.next(i)}}const R={id:"sheet.operation.toggle-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f),i=e.enabled;return e.setEnabled(!i),!0}},$={id:"sheet.operation.set-crosshair-highlight-color",type:o.CommandType.OPERATION,handler(r,{value:e}){const i=r.get(f);return i.enabled||i.setEnabled(!0),i.setColor(e),!0}},U={id:"sheet.operation.enable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f);return e.enabled?!1:(e.setEnabled(!0),!0)}},k={id:"sheet.operation.disable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(f);return e.enabled?(e.setEnabled(!1),!0):!1}};function D(r){var e,i,t="";if(typeof r=="string"||typeof r=="number")t+=r;else if(typeof r=="object")if(Array.isArray(r)){var n=r.length;for(e=0;e<n;e++)r[e]&&(i=D(r[e]))&&(t&&(t+=" "),t+=i)}else for(i in r)r[i]&&(t&&(t+=" "),t+=i);return t}function z(){for(var r,e,i=0,t="",n=arguments.length;i<n;i++)(r=arguments[i])&&(e=D(r))&&(t&&(t+=" "),t+=e);return t}const j={crosshairHighlightOverlay:"univer-crosshair-highlight-overlay",crosshairHighlightItem:"univer-crosshair-highlight-item",crosshairHighlightItemSelected:"univer-crosshair-highlight-item-selected"};function J(r){const{onChange:e}=r,i=S.useDependency(f),t=S.useObservable(i.color$),n=C.useCallback(s=>{e==null||e(s)},[e]);return V.jsx("div",{className:j.crosshairHighlightOverlay,children:M.map(s=>V.jsx("div",{className:z(j.crosshairHighlightItem,{[j.crosshairHighlightItemSelected]:s===t}),style:{backgroundColor:s},onClick:()=>n(s)},s))})}const Y="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function Q(r){const e=r.get(f);return{id:R.id,tooltip:"crosshair.button.tooltip",type:S.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingSingle",selections:[{label:{name:Y,hoverable:!1}}],selectionsCommandId:$.id,activated$:e.enabled$,hidden$:S.getMenuHiddenObservable(r,o.UniverInstanceType.UNIVER_SHEET)}}const ee={[S.ContextMenuPosition.FOOTER_MENU]:{[S.ContextMenuGroup.OTHERS]:{[R.id]:{order:0,menuItemFactory:Q}}}};var te=Object.getOwnPropertyDescriptor,ie=(r,e,i,t)=>{for(var n=t>1?void 0:t?te(e,i):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},N=(r,e)=>(i,t)=>e(i,t,r);let b=class extends o.Disposable{constructor(r,e,i){super(),this._componentMgr=r,this._menuManagerService=e,this._cmdSrv=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[R,$,U,k].forEach(r=>this._cmdSrv.registerCommand(r))}_initMenus(){this._menuManagerService.mergeMenu(ee)}_initComponents(){this._componentMgr.register(Y,J),this._componentMgr.register("CrossHighlightingSingle",G)}};b=ie([N(0,o.Inject(S.ComponentManager)),N(1,S.IMenuManagerService),N(2,o.ICommandService)],b);const re=1;class ne{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===o.RANGE_TYPE.COLUMN||e.rangeType===o.RANGE_TYPE.ROW||e.rangeType===o.RANGE_TYPE.ALL)return;const i=this._getIntersects(e),t=this._getSplitRanges(e,i);t.length>0&&this._ranges.push(...t)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,i){let t=[e];for(const n of i.concat(this._selectedRanges)){const s=[];for(const a of t){const c=o.Rectangle.subtract(a,n);c&&c.length>0&&s.push(...c)}t=s}return t.filter(n=>n.startRow<=n.endRow&&n.startColumn<=n.endColumn)}_getIntersects(e){const i=[];for(const t of this._ranges){const n=o.Rectangle.getIntersects(t,e);n&&i.push(n)}return i}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class se extends _.Shape{constructor(i,t){super(i,t);l(this,"_color");t&&this.setShapeProps(t)}setShapeProps(i){typeof i.color<"u"&&(this._color=i.color),this.transformByState({width:i.width,height:i.height})}_draw(i){var n,s;const t=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(s=(n=this._color)==null?void 0:n.a)!=null?s:.5})`;_.Rect.drawWith(i,{width:this.width,height:this.height,fill:t,stroke:void 0,strokeWidth:0,evented:!1})}}var oe=Object.getOwnPropertyDescriptor,ae=(r,e,i,t)=>{for(var n=t>1?void 0:t?oe(e,i):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},p=(r,e)=>(i,t)=>e(i,t,r);let O=class extends o.Disposable{constructor(e,i,t,n,s,a){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ne);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=i,this._sheetsSelectionsService=t,this._sheetsCrosshairHighlightService=n,this._contextService=s,this._refSelectionsService=a,this._initRenderListener()}_transformSelection(e,i){if(!e)return;const t=i.getRowCount(),n=i.getColumnCount(),s=[];for(const a of e){const{startRow:c,endRow:u,startColumn:m,endColumn:H}=a.range;u-c+1===t||H-m+1===n||s.push(a.range)}this._rangeCollection.setSelectedRanges(s);for(const a of s)this.addSelection(a,i)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(d.combineLatest([this._contextService.subscribeContextValue$(T.REF_SELECTIONS_ENABLED).pipe(d.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(d.tap(i=>this._color=i)),d.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(d.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),d.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(d.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([i,t,n,s,a,c])=>{if(this._clear(),!n)return;const u=i?c:a;this._rangeCollection.reset(),this._transformSelection(u,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,i){if(e.rangeType===o.RANGE_TYPE.COLUMN||e.rangeType===o.RANGE_TYPE.ROW||e.rangeType===o.RANGE_TYPE.ALL)return;const t=i.getRowCount(),n=i.getColumnCount(),{startRow:s,endRow:a,startColumn:c,endColumn:u}=e,m={startRow:s,endRow:a,startColumn:0,endColumn:c-1},H={startRow:s,endRow:a,startColumn:u+1,endColumn:n},y={startRow:0,endRow:s-1,startColumn:c,endColumn:u},E={startRow:a+1,endRow:t,startColumn:c,endColumn:u};for(const v of[m,H,y,E])v.startRow<=v.endRow&&v.startColumn<=v.endColumn&&this._rangeCollection.addRange(v)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,i,t,n){const{startRow:s,endRow:a,startColumn:c,endColumn:u}=e,m=w.getCoordByCell(s,c,t,n),H=w.getCoordByCell(a,u,t,n),{startX:y,startY:E}=m,{endX:v,endY:le}=H,ge=v-y,ue=le-E,de={left:y,top:E,color:new o.ColorKit(this._color).toRgb(),width:ge,height:ue,zIndex:re,evented:!1},B=new se(`crosshair-${i}`,de);this._shapes.push(B),t.addObject(B)}render(e){const i=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!i)return;const{scene:t}=this._context;this._clear();for(let n=0;n<e.length;n++){const s=e[n];this._addShapes(s,n,t,i)}t.makeDirty(!0)}async dispose(){super.dispose()}};O=ae([p(1,o.Inject(w.SheetSkeletonManagerService)),p(2,o.Inject(T.SheetsSelectionsService)),p(3,o.Inject(f)),p(4,o.Inject(o.IContextService)),p(5,T.IRefSelectionsService)],O);var he=Object.getOwnPropertyDescriptor,ce=(r,e,i,t)=>{for(var n=t>1?void 0:t?he(e,i):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=a(n)||n);return n},P=(r,e)=>(i,t)=>e(i,t,r);h.UniverSheetsCrosshairHighlightPlugin=(I=class extends o.Plugin{constructor(e=A,i,t,n){super(),this._config=e,this._injector=i,this._renderManagerService=t,this._configService=n;const{...s}=o.merge({},A,this._config);this._configService.setConfig(Z,s)}onStarting(){[[f],[b]].forEach(e=>this._injector.add(e))}onReady(){[[O]].forEach(e=>this._injector.add(e)),this._injector.get(b),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[O])}},l(I,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(I,"type",o.UniverInstanceType.UNIVER_SHEET),I),h.UniverSheetsCrosshairHighlightPlugin=ce([P(1,o.Inject(o.Injector)),P(2,_.IRenderManagerService),P(3,o.IConfigService)],h.UniverSheetsCrosshairHighlightPlugin),h.CROSSHAIR_HIGHLIGHT_COLORS=M,h.DisableCrosshairHighlightOperation=k,h.EnableCrosshairHighlightOperation=U,h.SetCrosshairHighlightColorOperation=$,h.SheetsCrosshairHighlightService=f,h.ToggleCrosshairHighlightOperation=R,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-crosshair-highlight",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,24 +57,24 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/icons": "^0.2.15",
60
+ "@univerjs/icons": "^0.2.20",
61
61
  "clsx": "^2.1.1",
62
- "@univerjs/core": "0.6.0",
63
- "@univerjs/engine-render": "0.6.0",
64
- "@univerjs/sheets": "0.6.0",
65
- "@univerjs/sheets-ui": "0.6.0",
66
- "@univerjs/ui": "0.6.0"
62
+ "@univerjs/core": "0.6.1",
63
+ "@univerjs/sheets-ui": "0.6.1",
64
+ "@univerjs/sheets": "0.6.1",
65
+ "@univerjs/ui": "0.6.1",
66
+ "@univerjs/engine-render": "0.6.1"
67
67
  },
68
68
  "devDependencies": {
69
69
  "less": "^4.2.2",
70
- "postcss": "^8.5.2",
70
+ "postcss": "^8.5.3",
71
71
  "react": "18.3.1",
72
72
  "rxjs": "^7.8.1",
73
73
  "tailwindcss": "^3.4.17",
74
74
  "typescript": "^5.7.3",
75
- "vite": "^6.1.0",
76
- "vitest": "^3.0.5",
77
- "@univerjs-infra/shared": "0.6.0"
75
+ "vite": "^6.1.1",
76
+ "vitest": "^3.0.6",
77
+ "@univerjs-infra/shared": "0.6.1"
78
78
  },
79
79
  "scripts": {
80
80
  "test": "vitest run",