@univerjs/sheets-zen-editor 0.1.3 → 0.1.5
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/README.md +2 -0
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +274 -272
- package/lib/types/commands/commands/zen-editor.command.d.ts +2 -16
- package/lib/types/commands/operations/zen-editor.operation.d.ts +2 -16
- package/lib/types/controllers/shortcuts/zen-editor.shortcut.d.ts +3 -17
- package/lib/types/controllers/zen-editor-ui.controller.d.ts +3 -17
- package/lib/types/controllers/zen-editor.controller.d.ts +7 -20
- package/lib/types/index.d.ts +1 -1
- package/lib/types/locale/en-US.d.ts +2 -16
- package/lib/types/plugin.d.ts +2 -16
- package/lib/types/services/zen-editor.service.d.ts +5 -19
- package/lib/types/views/menu.d.ts +2 -16
- package/lib/types/views/zen-editor/ZenEditor.d.ts +2 -16
- package/lib/umd/index.js +2 -2
- package/package.json +23 -18
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/packages/@univerjs/sheets-zen-editor)
|
|
4
4
|
[](https://img.shields.io/npm/l/@univerjs/sheets-zen-editor)
|
|
5
|
+

|
|
6
|
+

|
|
5
7
|
|
|
6
8
|
## Introduction
|
|
7
9
|
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ee=Object.defineProperty;var te=(i,t,n)=>t in i?ee(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n;var E=(i,t,n)=>(te(i,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),p=require("@wendellhu/redi"),C=require("@univerjs/docs"),z=require("@univerjs/engine-render"),N=require("@univerjs/sheets-ui"),v=require("@univerjs/ui"),W=require("rxjs"),g=require("react"),P=require("@wendellhu/redi/react-bindings"),V=require("clsx"),L={id:"zen-editor.operation.open-zen-editor",type:a.CommandType.OPERATION,handler:i=>!0};class ne{constructor(){E(this,"_position",null);E(this,"_position$",new W.BehaviorSubject(null));E(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 w=p.createIdentifier("univer.sheet-zen-editor-manager.service");var ie=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(i,t,n,e)=>{for(var r=e>1?void 0:e?re(t,n):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(t,n,r):s(r))||r);return e&&r&&ie(t,n,r),r},S=(i,t)=>(n,e)=>t(n,e,i);const h="__defaultDocumentZenEditorSpecialUnitId_20231218__";let b=class extends a.RxDisposable{constructor(t,n,e,r,o,s,c,d,l,u){super();E(this,"_zenEditorInitialState",!1);this._currentUniverService=t,this._zenEditorManagerService=n,this._renderManagerService=e,this._commandService=r,this._zenZoneService=o,this._editorBridgeService=s,this._undoRedoService=c,this._textSelectionManagerService=d,this._docSkeletonManagerService=l,this._docViewModelManagerService=u,this._initialize()}_initialize(){this._syncZenEditorSize(),this._commandExecutedListener()}_createZenEditorInstance(){const t={id:h,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{pageSize:{width:595,height:842},marginTop:50,marginBottom:50,marginRight:40,marginLeft:40,renderConfig:{vertexAngle:0,centerAngle:0}}};this._currentUniverService.createDoc(t)}_syncZenEditorSize(){this._zenEditorManagerService.position$.pipe(W.takeUntil(this.dispose$)).subscribe(t=>{var d;if(t==null)return;const n=N.getEditorObject(h,this._renderManagerService),e=this._currentUniverService.getUniverDocInstance(h);if(n==null||e==null)return;const{width:r,height:o}=t,{engine:s}=n,c=(d=this._docSkeletonManagerService.getSkeletonByUnitId(h))==null?void 0:d.skeleton;requestIdleCallback(()=>{s.resizeBySize(r,o),this._calculatePagePosition(n),c&&this._textSelectionManagerService.refreshSelection()})})}_handleOpenZenEditor(){this._zenEditorInitialState||(this._createZenEditorInstance(),this._zenEditorInitialState=!0),this._zenZoneService.open(),this._undoRedoService.clearUndoRedo(h),this._currentUniverService.focusUniverInstance(h),this._currentUniverService.setCurrentUniverDocInstance(h),this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:z.DeviceInputEventType.PointerDown});const n=this._editorBridgeService.getLatestEditCellState();if(n==null)return;this._editorSyncHandler(n);const e=[{startOffset:0,endOffset:0}];this._textSelectionManagerService.replaceTextRanges(e)}_editorSyncHandler(t){var s,c;const n=(s=t.documentLayoutObject.documentModel)==null?void 0:s.getBody(),e=n==null?void 0:n.dataStream,r=n==null?void 0:n.paragraphs;let o=[];e==null||r==null||((c=n==null?void 0:n.textRuns)!=null&&c.length&&(o=n==null?void 0:n.textRuns),this._syncContentAndRender(h,e,r,o))}_syncContentAndRender(t,n,e,r=[]){const o=[h,a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(t),c=this._currentUniverService.getUniverDocInstance(t),d=this._docViewModelManagerService.getViewModel(t);if(c==null||d==null||s==null)return;const l=c.getBody();l.dataStream=n,l.paragraphs=e,t===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(l.textRuns=[]),r.length>0&&(l.textRuns=r),d.reset(c);const{skeleton:u}=s,f=this._getDocObject();f!=null&&(u.calculate(),o.includes(t)&&f.document.makeDirty())}_calculatePagePosition(t){const{document:n,scene:e}=t,r=e==null?void 0:e.getParent(),{width:o,height:s,pageMarginLeft:c,pageMarginTop:d}=n;if(r==null||o===Number.POSITIVE_INFINITY||s===Number.POSITIVE_INFINITY)return;const{width:l,height:u}=r;let f=0,D=0,M=0,U=0,R=Number.POSITIVE_INFINITY;const{scaleX:O,scaleY:J}=e.getAncestorScale();l>(o+c*2)*O?(f=l/2-o*O/2,f/=O,M=(l-c*2)/O,R=0):(f=c,M=o+c*2,R=(M-l/O)/2),u>s?(D=u/2-s/2,U=(u-d*2)/J):(D=d,U=s+d*2),e.resize(M,U+200),n.translate(f,D);const j=e.getViewport(C.VIEWPORT_KEY.VIEW_MAIN);if(R!==Number.POSITIVE_INFINITY&&j!=null){const Q=j.getBarScroll(R,0).x;j.scrollTo({x:Q})}return this}_commandExecutedListener(){const t=[L.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{t.includes(e.id)&&this._handleOpenZenEditor()}));const n=[C.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(n.includes(e.id)){const r=e.params,{unitId:o}=r;if(o===h){const s=this._currentUniverService.getUniverDocInstance(o),c=s==null?void 0:s.getBody(),d=c==null?void 0:c.dataStream,l=c==null?void 0:c.paragraphs,u=c==null?void 0:c.textRuns;if(this._editorBridgeService.changeEditorDirty(!0),d==null||l==null)return;this._syncContentAndRender(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,d,l,u)}}}))}_getDocObject(){return C.getDocObject(this._currentUniverService,this._renderManagerService)}};b=oe([a.OnLifecycle(a.LifecycleStages.Steady,b),S(0,a.IUniverInstanceService),S(1,w),S(2,z.IRenderManagerService),S(3,a.ICommandService),S(4,v.IZenZoneService),S(5,N.IEditorBridgeService),S(6,a.IUndoRedoService),S(7,p.Inject(C.TextSelectionManagerService)),S(8,p.Inject(C.DocSkeletonManagerService)),S(9,p.Inject(C.DocViewModelManagerService))],b);const A={id:"zen-editor.command.cancel-zen-edit",type:a.CommandType.COMMAND,handler:async i=>{const t=i.get(v.IZenZoneService),n=i.get(N.IEditorBridgeService),e=i.get(a.IUniverInstanceService);n.isVisible().visible&&n.changeVisible({visible:!1,eventType:z.DeviceInputEventType.Keyboard,keycode:v.KeyCode.ESC}),t.close();const o=e.getCurrentUniverSheetInstance();return e.focusUniverInstance(o.getUnitId()),n.refreshEditCellState(),!0}},$={id:"zen-editor.command.confirm-zen-edit",type:a.CommandType.COMMAND,handler:async i=>{const t=i.get(v.IZenZoneService),n=i.get(N.IEditorBridgeService),e=i.get(a.IUniverInstanceService);n.isVisible().visible&&n.changeVisible({visible:!1,eventType:z.DeviceInputEventType.PointerDown}),t.close();const o=e.getCurrentUniverSheetInstance();return e.focusUniverInstance(o.getUnitId()),n.refreshEditCellState(),!0}};function se(){return{id:L.id,group:v.MenuGroup.CONTEXT_MENU_OTHERS,type:v.MenuItemType.BUTTON,title:"rightClick.zenEditor",icon:"AmplifySingle",positions:[v.MenuPosition.CONTEXT_MENU]}}var q={exports:{}},x={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ce=g,ae=Symbol.for("react.element"),de=Symbol.for("react.fragment"),le=Object.prototype.hasOwnProperty,ue=ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ve={key:!0,ref:!0,__self:!0,__source:!0};function F(i,t,n){var e,r={},o=null,s=null;n!==void 0&&(o=""+n),t.key!==void 0&&(o=""+t.key),t.ref!==void 0&&(s=t.ref);for(e in t)le.call(t,e)&&!ve.hasOwnProperty(e)&&(r[e]=t[e]);if(i&&i.defaultProps)for(e in t=i.defaultProps,t)r[e]===void 0&&(r[e]=t[e]);return{$$typeof:ae,type:i,key:o,ref:s,props:r,_owner:ue.current}}x.Fragment=de;x.jsx=F;x.jsxs=F;q.exports=x;var I=q.exports,_=function(){return _=Object.assign||function(i){for(var t,n=1,e=arguments.length;n<e;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},_.apply(this,arguments)},he=function(i,t){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&t.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(i);r<e.length;r++)t.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(i,e[r])&&(n[e[r]]=i[e[r]]);return n},B=g.forwardRef(function(i,t){var n=i.icon,e=i.id,r=i.className,o=i.extend,s=he(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),d=g.useRef("_".concat(Se()));return Y(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},_({ref:t,className:c},s),o)});function Y(i,t,n,e,r){return g.createElement(i.tag,_(_({key:t},_e(i,n,r)),e),(fe(i,n).children||[]).map(function(o,s){return Y(o,"".concat(t,"-").concat(i.tag,"-").concat(s),n,void 0,r)}))}function _e(i,t,n){var e=_({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+t.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),e}function fe(i,t){var n,e=t.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?_(_({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function Se(){return Math.random().toString(36).substring(2,8)}B.displayName="UniverIcon";var ge={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.44 3.57291C14.698 3.83093 14.698 4.24927 14.44 4.50729L6.44342 12.5037C6.28721 12.6599 6.03395 12.6599 5.87774 12.5037L1.55992 8.18578C1.3019 7.92776 1.3019 7.50942 1.55993 7.2514C1.81795 6.99338 2.23629 6.99338 2.49431 7.25141L6.01916 10.7763C6.09727 10.8544 6.2239 10.8544 6.30201 10.7763L13.5056 3.57291C13.7636 3.31489 14.1819 3.31489 14.44 3.57291Z",fillRule:"evenodd",clipRule:"evenodd"}}]},K=g.forwardRef(function(i,t){return g.createElement(B,Object.assign({},i,{id:"check-mark-single",ref:t,icon:ge}))});K.displayName="CheckMarkSingle";const pe=K;var Ie={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.57061 3.65132C4.31677 3.39748 3.90521 3.39748 3.65137 3.65132C3.39753 3.90516 3.39753 4.31672 3.65137 4.57056L7.08079 7.99998L3.65123 11.4295C3.39739 11.6834 3.39739 12.0949 3.65123 12.3488C3.90507 12.6026 4.31662 12.6026 4.57047 12.3488L8.00003 8.91921L11.4295 12.3487C11.6834 12.6026 12.0949 12.6026 12.3488 12.3487C12.6026 12.0949 12.6026 11.6833 12.3488 11.4295L8.91927 7.99998L12.3486 4.57061C12.6025 4.31677 12.6025 3.90521 12.3486 3.65137C12.0948 3.39753 11.6832 3.39753 11.4294 3.65137L8.00003 7.08074L4.57061 3.65132Z"}}]},H=g.forwardRef(function(i,t){return g.createElement(B,Object.assign({},i,{id:"close-single",ref:t,icon:Ie}))});H.displayName="CloseSingle";const me=H,Ee="univer-zen-editor",Ce="univer-zen-editor-icon-wrapper",Oe="univer-zen-editor-icon-container",ye="univer-zen-editor-icon-success",ze="univer-zen-editor-icon-error",Me="univer-zen-editor-canvas-container",m={zenEditor:Ee,zenEditorIconWrapper:Ce,zenEditorIconContainer:Oe,zenEditorIconSuccess:ye,zenEditorIconError:ze,zenEditorCanvasContainer:Me},Re="ZEN_EDITOR_PLUGIN_",be=`${Re}ZEN_EDITOR_COMPONENT`;function Te(){const i=g.useRef(null),t=P.useDependency(z.IRenderManagerService),n=P.useDependency(w),e=P.useDependency(a.ICommandService);g.useEffect(()=>{const s=i.current;if(!s)return;const c=t.currentRender$.subscribe(l=>{var f;if(l!==h)return;const u=(f=t.getRenderById(h))==null?void 0:f.engine;u==null||u.setContainer(s)}),d=new ResizeObserver(()=>{const l=s.getBoundingClientRect();n.setPosition(l)});return d.observe(s),()=>{d.unobserve(s),c.unsubscribe()}},[]);function r(){e.executeCommand(A.id)}function o(){e.executeCommand($.id)}return I.jsxs("div",{className:m.zenEditor,children:[I.jsxs("div",{className:m.zenEditorIconWrapper,children:[I.jsx("span",{className:V(m.zenEditorIconContainer,m.zenEditorIconError),onClick:r,children:I.jsx(me,{style:{fontSize:"22px"}})}),I.jsx("span",{className:V(m.zenEditorIconContainer,m.zenEditorIconSuccess),onClick:o,children:I.jsx(pe,{style:{fontSize:"22px"}})})]}),I.jsx("div",{className:m.zenEditorCanvasContainer,ref:i})]})}const Ne={id:$.id,description:"shortcut.sheet.zen-edit-confirm",group:"4_sheet-edit",preconditions:i=>X(i),binding:v.KeyCode.ENTER|v.MetaKeys.ALT},xe={id:A.id,description:"shortcut.sheet.zen-edit-cancel",group:"4_sheet-edit",preconditions:i=>X(i),binding:v.KeyCode.ESC};function X(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}var De=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,je=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ue(t,n):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(t,n,r):s(r))||r);return e&&r&&De(t,n,r),r},y=(i,t)=>(n,e)=>t(n,e,i);let T=class extends a.Disposable{constructor(i,t,n,e,r){super(),this._injector=i,this._zenZoneService=t,this._commandService=n,this._menuService=e,this._shortcutService=r,this._initialize()}_initialize(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts()}_initCustomComponents(){this.disposeWithMe(this._zenZoneService.set(be,Te))}_initCommands(){[L,A,$].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[se].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[Ne,xe].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}};T=je([a.OnLifecycle(a.LifecycleStages.Rendered,T),y(0,p.Inject(p.Injector)),y(1,v.IZenZoneService),y(2,a.ICommandService),y(3,v.IMenuService),y(4,v.IShortcutService)],T);const Pe={shortcut:{sheet:{"zen-edit-cancel":"Cancel Zen Edit","zen-edit-confirm":"Confirm Zen Edit"}}},Ze=Pe,Le={shortcut:{sheet:{"zen-edit-cancel":"取消编辑(禅模式状态)","zen-edit-confirm":"放弃编辑(禅模式状态)"}}},G=Le;var we=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,$e=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ae(t,n):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(t,n,r):s(r))||r);return e&&r&&we(t,n,r),r},k=(i,t)=>(n,e)=>t(n,e,i),Z;exports.UniverSheetsZenEditorPlugin=(Z=class extends a.Plugin{constructor(t,n,e){super("zen-editor"),this._injector=n,this._localeService=e,this._initialize(),this._initializeDependencies(this._injector)}_initialize(){this._localeService.load({zhCN:G})}_initializeDependencies(t){[[T],[b],[w,{useClass:ne}]].forEach(e=>t.add(e))}onRendered(){}onDestroy(){}},E(Z,"type",a.PluginType.Doc),Z);exports.UniverSheetsZenEditorPlugin=$e([k(1,p.Inject(p.Injector)),k(2,p.Inject(a.LocaleService))],exports.UniverSheetsZenEditorPlugin);exports.enUS=Ze;exports.zhCN=G;
|