index.js 14 KB

123456789
  1. (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),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","@univerjs/sheets","@univerjs/sheets-ui"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverSheetsCrosshairHighlight={},c.UniverCore,c.UniverEngineRender,c.UniverUi,c.rxjs,c.React,c.UniverSheets,c.UniverSheetsUi))})(this,function(c,o,p,H,_,R,w,P){"use strict";var be=Object.defineProperty;var Oe=(c,o,p)=>o in c?be(c,o,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[o]=p;var u=(c,o,p)=>Oe(c,typeof o!="symbol"?o+"":o,p);var T;const J="sheets-crosshair-highlight.config",A={};var d=function(){return d=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},d.apply(this,arguments)},X=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(t[n[i]]=r[n[i]]);return t},L=R.forwardRef(function(r,e){var t=r.icon,n=r.id,i=r.className,s=r.extend,a=X(r,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),l=R.useRef("_".concat(Q()));return U(t,"".concat(n),{defIds:t.defIds,idSuffix:l.current},d({ref:e,className:h},a),s)});function U(r,e,t,n,i){return R.createElement(r.tag,d(d({key:e},K(r,t,i)),n),(z(r,t).children||[]).map(function(s,a){return U(s,"".concat(e,"-").concat(r.tag,"-").concat(a),t,void 0,i)}))}function K(r,e,t){var n=d({},r.attrs);t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1);var i=e.defIds;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],h=s[1];typeof h=="string"&&(n[a]=h.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function z(r,e){var t,n=e.defIds;return!n||n.length===0?r:r.tag==="defs"&&(!((t=r.children)===null||t===void 0)&&t.length)?d(d({},r),{children:r.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?d(d({},i),{attrs:d(d({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):r}function Q(){return Math.random().toString(36).substring(2,8)}L.displayName="UniverIcon";var ee={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=R.forwardRef(function(r,e){return R.createElement(L,Object.assign({},r,{id:"cross-highlighting-single",ref:e,icon:ee}))});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 S extends o.Disposable{constructor(){super(...arguments);u(this,"_enabled$",new _.BehaviorSubject(!1));u(this,"enabled$",this._enabled$.asObservable());u(this,"_color$",new _.BehaviorSubject(M[0]));u(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:o.CommandType.OPERATION,handler(r){const e=r.get(S),t=e.enabled;return e.setEnabled(!t),!0}},j={id:"sheet.operation.set-crosshair-highlight-color",type:o.CommandType.OPERATION,handler(r,{value:e}){const t=r.get(S);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},D={id:"sheet.operation.enable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(S);return e.enabled?!1:(e.setEnabled(!0),!0)}},Y={id:"sheet.operation.disable-crosshair-highlight",type:o.CommandType.OPERATION,handler(r){const e=r.get(S);return e.enabled?(e.setEnabled(!1),!0):!1}};var N={exports:{}},b={};/**
  2. * @license React
  3. * react-jsx-runtime.production.min.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */var k;function te(){if(k)return b;k=1;var r=R,e=Symbol.for("react.element"),t=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(h,l,C){var g,v={},m=null,f=null;C!==void 0&&(m=""+C),l.key!==void 0&&(m=""+l.key),l.ref!==void 0&&(f=l.ref);for(g in l)n.call(l,g)&&!s.hasOwnProperty(g)&&(v[g]=l[g]);if(h&&h.defaultProps)for(g in l=h.defaultProps,l)v[g]===void 0&&(v[g]=l[g]);return{$$typeof:e,type:h,key:m,ref:f,props:v,_owner:i.current}}return b.Fragment=t,b.jsx=a,b.jsxs=a,b}var B;function ne(){return B||(B=1,N.exports=te()),N.exports}var Z=ne();function F(r){var e,t,n="";if(typeof r=="string"||typeof r=="number")n+=r;else if(typeof r=="object")if(Array.isArray(r)){var i=r.length;for(e=0;e<i;e++)r[e]&&(t=F(r[e]))&&(n&&(n+=" "),n+=t)}else for(t in r)r[t]&&(n&&(n+=" "),n+=t);return n}function re(){for(var r,e,t=0,n="",i=arguments.length;t<i;t++)(r=arguments[t])&&(e=F(r))&&(n&&(n+=" "),n+=e);return n}const x={crosshairHighlightOverlay:"univer-crosshair-highlight-overlay",crosshairHighlightItem:"univer-crosshair-highlight-item",crosshairHighlightItemSelected:"univer-crosshair-highlight-item-selected"};function ie(r){const{onChange:e}=r,t=o.useDependency(S),n=o.useObservable(t.color$),i=R.useCallback(s=>{e==null||e(s)},[e]);return Z.jsx("div",{className:x.crosshairHighlightOverlay,children:M.map(s=>Z.jsx("div",{className:re(x.crosshairHighlightItem,{[x.crosshairHighlightItemSelected]:s===n}),style:{backgroundColor:s},onClick:()=>i(s)},s))})}const W="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function se(r){const e=r.get(S);return{id:I.id,tooltip:"crosshair.button.tooltip",type:H.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingSingle",selections:[{label:{name:W,hoverable:!1}}],selectionsCommandId:j.id,activated$:e.enabled$,hidden$:H.getMenuHiddenObservable(r,o.UniverInstanceType.UNIVER_SHEET)}}const oe={[H.ContextMenuPosition.FOOTER_MENU]:{[H.ContextMenuGroup.OTHERS]:{[I.id]:{order:0,menuItemFactory:se}}}};var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,he=(r,e,t,n)=>{for(var i=n>1?void 0:n?ce(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&ae(e,t,i),i},$=(r,e)=>(t,n)=>e(t,n,r);let y=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(){[I,j,D,Y].forEach(r=>this._cmdSrv.registerCommand(r))}_initMenus(){this._menuManagerService.mergeMenu(oe)}_initComponents(){this._componentMgr.register(W,ie),this._componentMgr.register("CrossHighlightingSingle",G)}};y=he([$(0,o.Inject(H.ComponentManager)),$(1,H.IMenuManagerService),$(2,o.ICommandService)],y);const le=1;class ge{constructor(){u(this,"_selectedRanges",[]);u(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),n=this._getSplitRanges(e,t);n.length>0&&this._ranges.push(...n)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let n=[e];for(const i of t.concat(this._selectedRanges)){const s=[];for(const a of n){const h=o.Rectangle.subtract(a,i);h&&h.length>0&&s.push(...h)}n=s}return n.filter(i=>i.startRow<=i.endRow&&i.startColumn<=i.endColumn)}_getIntersects(e){const t=[];for(const n of this._ranges){const i=o.Rectangle.getIntersects(n,e);i&&t.push(i)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class ue extends p.Shape{constructor(t,n){super(t,n);u(this,"_color");n&&this.setShapeProps(n)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${this._color.a})`;p.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:void 0,strokeWidth:0,evented:!1})}}var de=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,_e=(r,e,t,n)=>{for(var i=n>1?void 0:n?fe(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&de(e,t,i),i},O=(r,e)=>(t,n)=>e(t,n,r);let E=class extends o.Disposable{constructor(e,t,n,i,s,a){super();u(this,"_shapes",[]);u(this,"_rangeCollection",new ge);u(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=n,this._sheetsCrosshairHighlightService=i,this._contextService=s,this._refSelectionsService=a,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const n=t.getRowCount(),i=t.getColumnCount(),s=[];for(const a of e){const{startRow:h,endRow:l,startColumn:C,endColumn:g}=a.range;l-h+1===n||g-C+1===i||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(_.combineLatest([this._contextService.subscribeContextValue$(w.REF_SELECTIONS_ENABLED).pipe(_.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(_.tap(t=>this._color=t)),_.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(_.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),_.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(_.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,n,i,s,a,h])=>{if(this._clear(),!i)return;const l=t?h:a;this._rangeCollection.reset(),this._transformSelection(l,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 n=t.getRowCount(),i=t.getColumnCount(),{startRow:s,endRow:a,startColumn:h,endColumn:l}=e,C={startRow:s,endRow:a,startColumn:0,endColumn:h-1},g={startRow:s,endRow:a,startColumn:l+1,endColumn:i},v={startRow:0,endRow:s-1,startColumn:h,endColumn:l},m={startRow:a+1,endRow:n,startColumn:h,endColumn:l};for(const f of[C,g,v,m])f.startRow<=f.endRow&&f.startColumn<=f.endColumn&&this._rangeCollection.addRange(f)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,n,i){const{startRow:s,endRow:a,startColumn:h,endColumn:l}=e,C=P.getCoordByCell(s,h,n,i),g=P.getCoordByCell(a,l,n,i),{startX:v,startY:m}=C,{endX:f,endY:Ce}=g,me=f-v,Re=Ce-m,He={left:v,top:m,color:new o.ColorKit(this._color).toRgb(),width:me,height:Re,zIndex:le,evented:!1},q=new ue(`crosshair-${t}`,He);this._shapes.push(q),n.addObject(q)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:n}=this._context;this._clear();for(let i=0;i<e.length;i++){const s=e[i];this._addShapes(s,i,n,t)}n.makeDirty(!0)}async dispose(){super.dispose()}};E=_e([O(1,o.Inject(P.SheetSkeletonManagerService)),O(2,o.Inject(w.SheetsSelectionsService)),O(3,o.Inject(S)),O(4,o.Inject(o.IContextService)),O(5,w.IRefSelectionsService)],E);var Se=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,pe=(r,e,t,n)=>{for(var i=n>1?void 0:n?ve(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&Se(e,t,i),i},V=(r,e)=>(t,n)=>e(t,n,r);c.UniverSheetsCrosshairHighlightPlugin=(T=class extends o.Plugin{constructor(e=A,t,n,i){super(),this._config=e,this._injector=t,this._renderManagerService=n,this._configService=i;const{...s}=o.merge({},A,this._config);this._configService.setConfig(J,s)}onStarting(){[[S],[y]].forEach(e=>this._injector.add(e))}onReady(){[[E]].forEach(e=>this._injector.add(e)),this._injector.get(y),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[E])}},u(T,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),u(T,"type",o.UniverInstanceType.UNIVER_SHEET),T),c.UniverSheetsCrosshairHighlightPlugin=pe([V(1,o.Inject(o.Injector)),V(2,p.IRenderManagerService),V(3,o.IConfigService)],c.UniverSheetsCrosshairHighlightPlugin),c.CROSSHAIR_HIGHLIGHT_COLORS=M,c.DisableCrosshairHighlightOperation=Y,c.EnableCrosshairHighlightOperation=D,c.SetCrosshairHighlightColorOperation=j,c.SheetsCrosshairHighlightService=S,c.ToggleCrosshairHighlightOperation=I,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});