@univerjs/sheets-zen-editor 0.6.10 → 0.7.0-beta.0

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/umd/index.js CHANGED
@@ -1 +1,10 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("react/jsx-runtime"),require("@univerjs/design"),require("react"),require("rxjs"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/ui","react/jsx-runtime","@univerjs/design","react","rxjs","@univerjs/sheets"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverSheetsZenEditor={},c.UniverCore,c.UniverDocsUi,c.UniverEngineRender,c.UniverSheetsUi,c.UniverUi,c.React,c.UniverDesign,c.React,c.rxjs,c.UniverSheets))})(this,function(c,o,g,A,_,l,S,L,E,D,y){"use strict";var _e=Object.defineProperty;var Se=(c,o,g)=>o in c?_e(c,o,{enumerable:!0,configurable:!0,writable:!0,value:g}):c[o]=g;var N=(c,o,g)=>Se(c,typeof o!="symbol"?o+"":o,g);var U;const z={id:"zen-editor.command.open-zen-editor",type:o.CommandType.COMMAND,handler:async e=>{var w;const t=e.get(l.IZenZoneService),i=e.get(g.IEditorService),n=e.get(_.IEditorBridgeService),r=e.get(o.IUniverInstanceService),a=e.get(l.ISidebarService);a.visible&&(a.close(),await o.delayAnimationFrame()),t.open();const s=i.getEditor(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(s==null)return!1;const d=n.getLatestEditCellState();if(d==null)return!1;const u=(w=d.documentLayoutObject.documentModel)==null?void 0:w.getSnapshot();if(u==null)return!1;r.focusUnit(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const{body:I,drawings:p,drawingsOrder:v,tableSource:m,settings:O}=o.Tools.deepClone(u),T={...s.getDocumentData(),body:I,drawings:p,drawingsOrder:v,tableSource:m,settings:O},C=[{startOffset:0,endOffset:0,collapsed:!0}];return s.focus(),s.setDocumentData(T,C),s.clearUndoRedoHistory(),!0}},b={id:"zen-editor.command.cancel-zen-edit",type:o.CommandType.COMMAND,handler:async e=>{const t=e.get(l.IZenZoneService),i=e.get(_.IEditorBridgeService),n=e.get(o.IUniverInstanceService),r=e.get(l.ISidebarService);r.visible&&(r.close(),await o.delayAnimationFrame()),t.close();const a=n.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);return a?(n.focusUnit(a.getUnitId()),i.refreshEditCellState(),!0):!1}},M={id:"zen-editor.command.confirm-zen-edit",type:o.CommandType.COMMAND,handler:async e=>{var I;const t=e.get(l.IZenZoneService),i=e.get(_.IEditorBridgeService),n=e.get(o.IUniverInstanceService),r=e.get(g.IEditorService),a=e.get(l.ISidebarService);a.visible&&(a.close(),await o.delayAnimationFrame()),t.close();const s=r.getEditor(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(s==null)return!1;const d=e.get(A.IRenderManagerService),u=n.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(u){const p=u.getUnitId(),v=(I=d.getRenderById(p))==null?void 0:I.with(_.EditingRenderController);if(v){const m=o.Tools.deepClone(s.getDocumentData());m.documentStyle.documentFlavor=o.DocumentFlavor.UNSPECIFIED,v.submitCellData(new o.DocumentDataModel(m))}return n.focusUnit(u.getUnitId()),i.refreshEditCellState(),!0}return!1}},H="sheets-zen-editor.config",F={};var f=function(){return f=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++){t=arguments[i];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},f.apply(this,arguments)},G=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(i[n[r]]=e[n[r]]);return i},x=E.forwardRef(function(e,t){var i=e.icon,n=e.id,r=e.className,a=e.extend,s=G(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),u=E.useRef("_".concat(Q()));return $(i,"".concat(n),{defIds:i.defIds,idSuffix:u.current},f({ref:t,className:d},s),a)});function $(e,t,i,n,r){return E.createElement(e.tag,f(f({key:t},X(e,i,r)),n),(J(e,i).children||[]).map(function(a,s){return $(a,"".concat(t,"-").concat(e.tag,"-").concat(s),i,void 0,r)}))}function X(e,t,i){var n=f({},e.attrs);i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(a){var s=a[0],d=a[1];s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(a){var s=a[0],d=a[1];typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function J(e,t){var i,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((i=e.children)===null||i===void 0)&&i.length)?f(f({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?f(f({},r),{attrs:f(f({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function Q(){return Math.random().toString(36).substring(2,8)}x.displayName="UniverIcon";var ee={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},V=E.forwardRef(function(e,t){return E.createElement(x,Object.assign({},e,{id:"check-mark-single",ref:t,icon:ee}))});V.displayName="CheckMarkSingle";var ne={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Y=E.forwardRef(function(e,t){return E.createElement(x,Object.assign({},e,{id:"close-single",ref:t,icon:ne}))});Y.displayName="CloseSingle";class te{constructor(){N(this,"_position",null);N(this,"_position$",new D.BehaviorSubject(null));N(this,"position$",this._position$.asObservable())}dispose(){this._position$.complete(),this._position=null}setPosition(t){this._position=t,this._refresh(t)}getPosition(){return this._position}_refresh(t){this._position$.next(t)}}const k=o.createIdentifier("univer.sheet-zen-editor-manager.service"),h={zenEditor:"univer-zen-editor",zenEditorIconWrapper:"univer-zen-editor-icon-wrapper",zenEditorIconContainer:"univer-zen-editor-icon-container",zenEditorIconSuccess:"univer-zen-editor-icon-success",zenEditorIconError:"univer-zen-editor-icon-error",zenEditorCanvasContainer:"univer-zen-editor-canvas-container"},ie="ZEN_EDITOR_PLUGIN_ZEN_EDITOR_COMPONENT",re={id:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,body:{dataStream:`${o.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],tables:[],customBlocks:[],paragraphs:[{startIndex:0}],sectionBreaks:[{startIndex:1}]},tableSource:{},documentStyle:{pageSize:{width:595,height:Number.POSITIVE_INFINITY},documentFlavor:o.DocumentFlavor.MODERN,marginTop:0,marginBottom:0,marginRight:0,marginLeft:0,renderConfig:{vertexAngle:0,centerAngle:0}},drawings:{},drawingsOrder:[]};function oe(){const e=E.useRef(null),t=l.useDependency(k),i=l.useDependency(g.IEditorService),n=l.useDependency(o.ICommandService);E.useEffect(()=>{const s=e.current;if(!s)return;const d=i.register({editorUnitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,initialSnapshot:re,scrollBar:!0,backScrollOffset:100},s),u=new ResizeObserver(()=>{t.setPosition(s.getBoundingClientRect())});return u.observe(s),()=>{d.dispose(),u.unobserve(s)}},[]);function r(){const s=i.getEditor(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);s==null||s.blur(),n.executeCommand(b.id)}function a(){const s=i.getEditor(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);s==null||s.blur(),n.executeCommand(M.id)}return S.jsxs("div",{className:h.zenEditor,children:[S.jsxs("div",{className:h.zenEditorIconWrapper,children:[S.jsx("span",{className:L.clsx(h.zenEditorIconContainer,h.zenEditorIconError),onClick:r,children:S.jsx(Y,{style:{fontSize:"22px"}})}),S.jsx("span",{className:L.clsx(h.zenEditorIconContainer,h.zenEditorIconSuccess),onClick:a,children:S.jsx(V,{style:{fontSize:"22px"}})})]}),S.jsx("div",{className:h.zenEditorCanvasContainer,ref:e})]})}function se(e){const t=e.get(_.IEditorBridgeService);return{id:z.id,type:l.MenuItemType.BUTTON,title:"rightClick.zenEditor",icon:"AmplifySingle",hidden$:_.getCurrentExclusiveRangeInterest$(e),disabled$:t.currentEditCell$.pipe(D.switchMap(i=>_.getCurrentRangeDisable$(e,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission,y.WorksheetSetCellValuePermission,y.WorksheetSetCellStylePermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]}).pipe(D.map(n=>{var r,a,s,d;return n||((d=(s=(a=(r=i==null?void 0:i.documentLayoutObject.documentModel)==null?void 0:r.getBody())==null?void 0:a.customBlocks)==null?void 0:s.length)!=null?d:0)>0}))))}}const ae={[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[z.id]:{order:2,menuItemFactory:se}}}},ce={id:M.id,description:"shortcut.sheet.zen-edit-confirm",group:"4_sheet-edit",preconditions:e=>W(e),binding:l.KeyCode.ENTER|l.MetaKeys.ALT},de={id:b.id,description:"shortcut.sheet.zen-edit-cancel",group:"4_sheet-edit",preconditions:e=>W(e),binding:l.KeyCode.ESC};function W(e){return e.getContextValue(o.FOCUSING_DOC)&&e.getContextValue(o.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(o.EDITOR_ACTIVATED)&&!e.getContextValue(o.FOCUSING_EDITOR_STANDALONE)}var le=Object.getOwnPropertyDescriptor,ue=(e,t,i,n)=>{for(var r=n>1?void 0:n?le(t,i):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=s(r)||r);return r},R=(e,t)=>(i,n)=>t(i,n,e);let Z=class extends o.Disposable{constructor(e,t,i,n){super(),this._zenZoneService=e,this._commandService=t,this._menuManagerService=i,this._shortcutService=n,this._initialize()}_initialize(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts()}_initCustomComponents(){this.disposeWithMe(this._zenZoneService.set(ie,oe))}_initCommands(){[z,b,M].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(ae)}_initShortcuts(){[ce,de].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}};Z=ue([R(0,l.IZenZoneService),R(1,o.ICommandService),R(2,l.IMenuManagerService),R(3,l.IShortcutService)],Z);var fe=Object.getOwnPropertyDescriptor,ge=(e,t,i,n)=>{for(var r=n>1?void 0:n?fe(t,i):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=s(r)||r);return r},K=(e,t)=>(i,n)=>t(i,n,e);let P=class extends o.RxDisposable{constructor(e,t){super(),this._zenEditorManagerService=e,this._renderManagerService=t,this._initialize()}_initialize(){this._syncZenEditorSize()}_syncZenEditorSize(){this._zenEditorManagerService.position$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{width:t,height:i}=e,n=_.getEditorObject(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,this._renderManagerService);n!=null&&requestIdleCallback(()=>{n.engine.resizeBySize(t,i),this._calculatePagePosition(n),this._scrollToTop()})})}_calculatePagePosition(e){const{document:t,scene:i,docBackground:n}=e,r=i==null?void 0:i.getParent(),{width:a,height:s,pageMarginLeft:d,pageMarginTop:u}=t;if(r==null||a===Number.POSITIVE_INFINITY||s===Number.POSITIVE_INFINITY)return;const{width:I,height:p}=r;let v=0;const m=u;let O=0,j=0,T=Number.POSITIVE_INFINITY;const{scaleX:C,scaleY:w}=i.getAncestorScale();I>(a+d*2)*C?(v=I/2-a*C/2,v/=C,O=(I-d*2)/C,T=0):(v=d,O=a+d*2,T=(O-I/C)/2),p>s?j=(p-u*2)/w:j=s+u*2,i.resize(O,j),t.translate(v,m),n.translate(v,m);const B=i.getViewport(g.VIEWPORT_KEY.VIEW_MAIN);if(T!==Number.POSITIVE_INFINITY&&B!=null){const Ie=B.transScroll2ViewportScrollValue(T,0).x;B.scrollToBarPos({x:Ie})}return this}_scrollToTop(){var i;const e=(i=this._renderManagerService.getRenderById(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(g.DocBackScrollRenderController),t={startOffset:0,endOffset:0};e&&e.scrollToRange(t)}};P=ge([K(0,k),K(1,A.IRenderManagerService)],P);var ve=Object.getOwnPropertyDescriptor,Ee=(e,t,i,n)=>{for(var r=n>1?void 0:n?ve(t,i):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=s(r)||r);return r},q=(e,t)=>(i,n)=>t(i,n,e);c.UniverSheetsZenEditorPlugin=(U=class extends o.Plugin{constructor(t=F,i,n){super(),this._config=t,this._injector=i,this._configService=n;const{menu:r,...a}=o.merge({},F,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(H,a),this._initializeDependencies(this._injector)}_initializeDependencies(t){[[Z],[P],[k,{useClass:te}]].forEach(n=>t.add(n))}onReady(){this._injector.get(Z)}onSteady(){this._injector.get(P)}},N(U,"pluginName","SHEET_ZEN_EDITOR_PLUGIN"),N(U,"type",o.UniverInstanceType.UNIVER_SHEET),U),c.UniverSheetsZenEditorPlugin=Ee([q(1,o.Inject(o.Injector)),q(2,o.IConfigService)],c.UniverSheetsZenEditorPlugin),c.CancelZenEditCommand=b,c.ConfirmZenEditCommand=M,c.OpenZenEditorCommand=z,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("react/jsx-runtime"),require("@univerjs/design"),require("react"),require("rxjs"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/ui","react/jsx-runtime","@univerjs/design","react","rxjs","@univerjs/sheets"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.UniverSheetsZenEditor={},d.UniverCore,d.UniverDocsUi,d.UniverEngineRender,d.UniverSheetsUi,d.UniverUi,d.React,d.UniverDesign,d.React,d.rxjs,d.UniverSheets))})(this,function(d,s,g,B,S,l,I,A,h,y,T){"use strict";var he=Object.defineProperty;var Se=(d,s,g)=>s in d?he(d,s,{enumerable:!0,configurable:!0,writable:!0,value:g}):d[s]=g;var N=(d,s,g)=>Se(d,typeof s!="symbol"?s+"":s,g);var U;const D={id:"zen-editor.command.open-zen-editor",type:s.CommandType.COMMAND,handler:async e=>{var w;const n=e.get(l.IZenZoneService),i=e.get(g.IEditorService),t=e.get(S.IEditorBridgeService),r=e.get(s.IUniverInstanceService),o=e.get(l.ISidebarService);o.visible&&(o.close(),await s.delayAnimationFrame()),n.open();const a=i.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(a==null)return!1;const c=t.getLatestEditCellState();if(c==null)return!1;const u=(w=c.documentLayoutObject.documentModel)==null?void 0:w.getSnapshot();if(u==null)return!1;r.focusUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const{body:f,drawings:C,drawingsOrder:_,tableSource:m,settings:p}=s.Tools.deepClone(u),O={...a.getDocumentData(),body:f,drawings:C,drawingsOrder:_,tableSource:m,settings:p},E=[{startOffset:0,endOffset:0,collapsed:!0}];return a.focus(),a.setDocumentData(O,E),a.clearUndoRedoHistory(),!0}},b={id:"zen-editor.command.cancel-zen-edit",type:s.CommandType.COMMAND,handler:async e=>{const n=e.get(l.IZenZoneService),i=e.get(S.IEditorBridgeService),t=e.get(s.IUniverInstanceService),r=e.get(l.ISidebarService);r.visible&&(r.close(),await s.delayAnimationFrame()),n.close();const o=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);return o?(t.focusUnit(o.getUnitId()),i.refreshEditCellState(),!0):!1}},M={id:"zen-editor.command.confirm-zen-edit",type:s.CommandType.COMMAND,handler:async e=>{var f;const n=e.get(l.IZenZoneService),i=e.get(S.IEditorBridgeService),t=e.get(s.IUniverInstanceService),r=e.get(g.IEditorService),o=e.get(l.ISidebarService);o.visible&&(o.close(),await s.delayAnimationFrame()),n.close();const a=r.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(a==null)return!1;const c=e.get(B.IRenderManagerService),u=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(u){const C=u.getUnitId(),_=(f=c.getRenderById(C))==null?void 0:f.with(S.EditingRenderController);if(_){const m=s.Tools.deepClone(a.getDocumentData());m.documentStyle.documentFlavor=s.DocumentFlavor.UNSPECIFIED,_.submitCellData(new s.DocumentDataModel(m))}return t.focusUnit(u.getUnitId()),i.refreshEditCellState(),!0}return!1}},q="sheets-zen-editor.config",L={};var v=function(){return v=Object.assign||function(e){for(var n,i=1,t=arguments.length;i<t;i++){n=arguments[i];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},v.apply(this,arguments)},H=function(e,n){var i={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(i[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(i[t[r]]=e[t[r]]);return i},x=h.forwardRef(function(e,n){var i=e.icon,t=e.id,r=e.className,o=e.extend,a=H(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),u=h.useRef("_".concat(J()));return F(i,"".concat(t),{defIds:i.defIds,idSuffix:u.current},v({ref:n,className:c},a),o)});function F(e,n,i,t,r){return h.createElement(e.tag,v(v({key:n},G(e,i,r)),t),(X(e,i).children||[]).map(function(o,a){return F(o,"".concat(n,"-").concat(e.tag,"-").concat(a),i,void 0,r)}))}function G(e,n,i){var t=v({},e.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1),e.tag==="mask"&&t.id&&(t.id=t.id+n.idSuffix),Object.entries(t).forEach(function(o){var a=o[0],c=o[1];a==="mask"&&typeof c=="string"&&(t[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(t[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function X(e,n){var i,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((i=e.children)===null||i===void 0)&&i.length)?v(v({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?v(v({},r),{attrs:v(v({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function J(){return Math.random().toString(36).substring(2,8)}x.displayName="UniverIcon";var Q={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},$=h.forwardRef(function(e,n){return h.createElement(x,Object.assign({},e,{id:"check-mark-single",ref:n,icon:Q}))});$.displayName="CheckMarkSingle";var ee={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},V=h.forwardRef(function(e,n){return h.createElement(x,Object.assign({},e,{id:"close-single",ref:n,icon:ee}))});V.displayName="CloseSingle";class te{constructor(){N(this,"_position",null);N(this,"_position$",new y.BehaviorSubject(null));N(this,"position$",this._position$.asObservable())}dispose(){this._position$.complete(),this._position=null}setPosition(n){this._position=n,this._refresh(n)}getPosition(){return this._position}_refresh(n){this._position$.next(n)}}const z=s.createIdentifier("univer.sheet-zen-editor-manager.service"),ne="ZEN_EDITOR_PLUGIN_ZEN_EDITOR_COMPONENT",ie={id:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,body:{dataStream:`${s.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],tables:[],customBlocks:[],paragraphs:[{startIndex:0}],sectionBreaks:[{startIndex:1}]},tableSource:{},documentStyle:{pageSize:{width:595,height:Number.POSITIVE_INFINITY},documentFlavor:s.DocumentFlavor.MODERN,marginTop:0,marginBottom:0,marginRight:0,marginLeft:0,renderConfig:{vertexAngle:0,centerAngle:0}},drawings:{},drawingsOrder:[]};function re(){const e=h.useRef(null),n=l.useDependency(z),i=l.useDependency(g.IEditorService),t=l.useDependency(s.ICommandService);h.useEffect(()=>{const c=e.current;if(!c)return;const u=i.register({editorUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,initialSnapshot:ie,scrollBar:!0,backScrollOffset:100},c),f=new ResizeObserver(()=>{n.setPosition(c.getBoundingClientRect())});return f.observe(c),()=>{u.dispose(),f.unobserve(c)}},[]);function r(){const c=i.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);c==null||c.blur(),t.executeCommand(b.id)}function o(){const c=i.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);c==null||c.blur(),t.executeCommand(M.id)}const a="univer-flex univer-w-7 univer-cursor-pointer univer-items-center univer-justify-center univer-transition-colors";return I.jsxs("div",{className:"univer-absolute univer-inset-0 univer-size-full univer-bg-white",children:[I.jsxs("div",{className:`
2
+ univer-absolute univer-right-6 univer-top-2 univer-z-10 univer-flex univer-items-center
3
+ univer-justify-center
4
+ `,children:[I.jsx("span",{className:A.clsx(a,`
5
+ univer-text-red-500
6
+ hover:univer-text-red-600
7
+ `),onClick:r,children:I.jsx(V,{className:"univer-size-5"})}),I.jsx("span",{className:A.clsx(a,`
8
+ univer-text-green-500
9
+ hover:univer-text-green-600
10
+ `),onClick:o,children:I.jsx($,{className:"univer-size-5"})})]}),I.jsx("div",{ref:e,className:"univer-absolute univer-inset-0 univer-size-full"})]})}function se(e){const n=e.get(S.IEditorBridgeService);return{id:D.id,type:l.MenuItemType.BUTTON,title:"rightClick.zenEditor",icon:"AmplifySingle",hidden$:S.getCurrentExclusiveRangeInterest$(e),disabled$:n.currentEditCell$.pipe(y.switchMap(i=>S.getCurrentRangeDisable$(e,{workbookTypes:[T.WorkbookEditablePermission],worksheetTypes:[T.WorksheetEditPermission,T.WorksheetSetCellValuePermission,T.WorksheetSetCellStylePermission],rangeTypes:[T.RangeProtectionPermissionEditPoint]}).pipe(y.map(t=>{var r,o,a,c;return t||((c=(a=(o=(r=i==null?void 0:i.documentLayoutObject.documentModel)==null?void 0:r.getBody())==null?void 0:o.customBlocks)==null?void 0:a.length)!=null?c:0)>0}))))}}const oe={[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[D.id]:{order:2,menuItemFactory:se}}}},ae={id:M.id,description:"shortcut.sheet.zen-edit-confirm",group:"4_sheet-edit",preconditions:e=>Y(e),binding:l.KeyCode.ENTER|l.MetaKeys.ALT},ce={id:b.id,description:"shortcut.sheet.zen-edit-cancel",group:"4_sheet-edit",preconditions:e=>Y(e),binding:l.KeyCode.ESC};function Y(e){return e.getContextValue(s.FOCUSING_DOC)&&e.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(s.EDITOR_ACTIVATED)&&!e.getContextValue(s.FOCUSING_EDITOR_STANDALONE)}var de=Object.getOwnPropertyDescriptor,le=(e,n,i,t)=>{for(var r=t>1?void 0:t?de(n,i):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},R=(e,n)=>(i,t)=>n(i,t,e);let Z=class extends s.Disposable{constructor(e,n,i,t){super(),this._zenZoneService=e,this._commandService=n,this._menuManagerService=i,this._shortcutService=t,this._initialize()}_initialize(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts()}_initCustomComponents(){this.disposeWithMe(this._zenZoneService.set(ne,re))}_initCommands(){[D,b,M].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(oe)}_initShortcuts(){[ae,ce].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}};Z=le([R(0,l.IZenZoneService),R(1,s.ICommandService),R(2,l.IMenuManagerService),R(3,l.IShortcutService)],Z);var ue=Object.getOwnPropertyDescriptor,ve=(e,n,i,t)=>{for(var r=t>1?void 0:t?ue(n,i):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},K=(e,n)=>(i,t)=>n(i,t,e);let P=class extends s.RxDisposable{constructor(e,n){super(),this._zenEditorManagerService=e,this._renderManagerService=n,this._initialize()}_initialize(){this._syncZenEditorSize()}_syncZenEditorSize(){this._zenEditorManagerService.position$.pipe(y.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{width:n,height:i}=e,t=S.getEditorObject(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,this._renderManagerService);t!=null&&requestIdleCallback(()=>{t.engine.resizeBySize(n,i),this._calculatePagePosition(t),this._scrollToTop()})})}_calculatePagePosition(e){const{document:n,scene:i,docBackground:t}=e,r=i==null?void 0:i.getParent(),{width:o,height:a,pageMarginLeft:c,pageMarginTop:u}=n;if(r==null||o===Number.POSITIVE_INFINITY||a===Number.POSITIVE_INFINITY)return;const{width:f,height:C}=r;let _=0;const m=u;let p=0,j=0,O=Number.POSITIVE_INFINITY;const{scaleX:E,scaleY:w}=i.getAncestorScale();f>(o+c*2)*E?(_=f/2-o*E/2,_/=E,p=(f-c*2)/E,O=0):(_=c,p=o+c*2,O=(p-f/E)/2),C>a?j=(C-u*2)/w:j=a+u*2,i.resize(p,j),n.translate(_,m),t.translate(_,m);const k=i.getViewport(g.VIEWPORT_KEY.VIEW_MAIN);if(O!==Number.POSITIVE_INFINITY&&k!=null){const _e=k.transScroll2ViewportScrollValue(O,0).x;k.scrollToBarPos({x:_e})}return this}_scrollToTop(){var i;const e=(i=this._renderManagerService.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(g.DocBackScrollRenderController),n={startOffset:0,endOffset:0};e&&e.scrollToRange(n)}};P=ve([K(0,z),K(1,B.IRenderManagerService)],P);var fe=Object.getOwnPropertyDescriptor,ge=(e,n,i,t)=>{for(var r=t>1?void 0:t?fe(n,i):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},W=(e,n)=>(i,t)=>n(i,t,e);d.UniverSheetsZenEditorPlugin=(U=class extends s.Plugin{constructor(n=L,i,t){super(),this._config=n,this._injector=i,this._configService=t;const{menu:r,...o}=s.merge({},L,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(q,o),this._initializeDependencies(this._injector)}_initializeDependencies(n){[[Z],[P],[z,{useClass:te}]].forEach(t=>n.add(t))}onReady(){this._injector.get(Z)}onSteady(){this._injector.get(P)}},N(U,"pluginName","SHEET_ZEN_EDITOR_PLUGIN"),N(U,"type",s.UniverInstanceType.UNIVER_SHEET),U),d.UniverSheetsZenEditorPlugin=ge([W(1,s.Inject(s.Injector)),W(2,s.IConfigService)],d.UniverSheetsZenEditorPlugin),d.CancelZenEditCommand=b,d.ConfirmZenEditCommand=M,d.OpenZenEditorCommand=D,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-zen-editor",
3
- "version": "0.6.10",
3
+ "version": "0.7.0-beta.0",
4
4
  "private": false,
5
5
  "description": "Zen Editor plugin for Univer Sheets.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -64,15 +64,15 @@
64
64
  "rxjs": ">=7.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@univerjs/icons": "^0.3.2",
68
- "@univerjs/core": "0.6.10",
69
- "@univerjs/design": "0.6.10",
70
- "@univerjs/docs-ui": "0.6.10",
71
- "@univerjs/docs": "0.6.10",
72
- "@univerjs/engine-render": "0.6.10",
73
- "@univerjs/sheets": "0.6.10",
74
- "@univerjs/ui": "0.6.10",
75
- "@univerjs/sheets-ui": "0.6.10"
67
+ "@univerjs/icons": "^0.3.22",
68
+ "@univerjs/core": "0.7.0-beta.0",
69
+ "@univerjs/design": "0.7.0-beta.0",
70
+ "@univerjs/docs": "0.7.0-beta.0",
71
+ "@univerjs/docs-ui": "0.7.0-beta.0",
72
+ "@univerjs/engine-render": "0.7.0-beta.0",
73
+ "@univerjs/sheets": "0.7.0-beta.0",
74
+ "@univerjs/ui": "0.7.0-beta.0",
75
+ "@univerjs/sheets-ui": "0.7.0-beta.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "less": "^4.3.0",
@@ -81,9 +81,9 @@
81
81
  "rxjs": "^7.8.1",
82
82
  "tailwindcss": "^3.4.17",
83
83
  "typescript": "^5.8.3",
84
- "vite": "^6.3.0",
85
- "vitest": "^3.1.1",
86
- "@univerjs-infra/shared": "0.6.10"
84
+ "vite": "^6.3.3",
85
+ "vitest": "^3.1.2",
86
+ "@univerjs-infra/shared": "0.7.0-beta.0"
87
87
  },
88
88
  "scripts": {
89
89
  "test": "vitest run",