@univerjs/sheets-zen-editor 0.10.12 → 0.10.13-nightly.202510290902
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 +3 -3
- package/lib/es/index.js +233 -199
- package/lib/index.js +233 -199
- package/lib/umd/index.js +3 -3
- package/package.json +13 -13
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var W=Object.defineProperty;var q=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var C=(e,t,n)=>q(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),N=require("@univerjs/docs-ui"),A=require("@univerjs/engine-render"),h=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),v=require("react/jsx-runtime"),$=require("@univerjs/design"),_=require("react"),b=require("rxjs"),p=require("@univerjs/sheets"),U={id:"zen-editor.command.open-zen-editor",type:s.CommandType.COMMAND,handler:async e=>{var O;const t=e.get(d.IZenZoneService),n=e.get(N.IEditorService),i=e.get(h.IEditorBridgeService),r=e.get(s.IUniverInstanceService),o=e.get(d.ISidebarService);o.visible&&(o.close(),await s.delayAnimationFrame()),t.open();const c=n.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(c==null)return!1;const a=i.getLatestEditCellState();if(a==null)return!1;const l=(O=a.documentLayoutObject.documentModel)==null?void 0:O.getSnapshot();if(l==null)return!1;r.focusUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const{body:u,drawings:m,drawingsOrder:g,tableSource:I,settings:S}=s.Tools.deepClone(l),E={...c.getDocumentData(),body:u,drawings:m,drawingsOrder:g,tableSource:I,settings:S},f=[{startOffset:0,endOffset:0,collapsed:!0}];return c.focus(),c.setDocumentData(E,f),c.clearUndoRedoHistory(),!0}},Z={id:"zen-editor.command.cancel-zen-edit",type:s.CommandType.COMMAND,handler:async e=>{const t=e.get(d.IZenZoneService),n=e.get(h.IEditorBridgeService),i=e.get(s.IUniverInstanceService),r=e.get(d.ISidebarService);r.visible&&(r.close(),await s.delayAnimationFrame()),t.close();const o=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);return o?(i.focusUnit(o.getUnitId()),n.refreshEditCellState(),!0):!1}},w={id:"zen-editor.command.confirm-zen-edit",type:s.CommandType.COMMAND,handler:async e=>{var u;const t=e.get(d.IZenZoneService),n=e.get(h.IEditorBridgeService),i=e.get(s.IUniverInstanceService),r=e.get(N.IEditorService),o=e.get(d.ISidebarService);o.visible&&(o.close(),await s.delayAnimationFrame()),t.close();const c=r.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);if(c==null)return!1;const a=e.get(A.IRenderManagerService),l=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(l){const m=l.getUnitId(),g=(u=a.getRenderById(m))==null?void 0:u.with(h.EditingRenderController);if(g){const I=s.Tools.deepClone(c.getDocumentData());I.documentStyle.documentFlavor=s.DocumentFlavor.UNSPECIFIED,g.submitCellData(new s.DocumentDataModel(I))}return i.focusUnit(l.getUnitId()),n.refreshEditCellState(),!0}return!1}},H="sheets-zen-editor.config",k={};function P({ref:e,...t}){const{icon:n,id:i,className:r,extend:o,...c}=t,a=`univerjs-icon univerjs-icon-${i} ${r||""}`.trim(),l=_.useRef(`_${J()}`);return L(n,`${i}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:a,...c},o)}function L(e,t,n,i,r){return _.createElement(e.tag,{key:t,...G(e,n,r),...i},(X(e,n).children||[]).map((o,c)=>L(o,`${t}-${e.tag}-${c}`,n,void 0,r)))}function G(e,t,n){const i={...e.attrs};n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),e.tag==="mask"&&i.id&&(i.id=i.id+t.idSuffix),Object.entries(i).forEach(([o,c])=>{o==="mask"&&typeof c=="string"&&(i[o]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+t.idSuffix),Object.entries(i).forEach(([o,c])=>{typeof c=="string"&&(i[o]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),i}function X(e,t){var i;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((i=e.children)!=null&&i.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&n&&n.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function J(){return Math.random().toString(36).substring(2,8)}P.displayName="UniverIcon";const Q={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"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"}}]},F=_.forwardRef(function(t,n){return _.createElement(P,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:Q}))});F.displayName="CheckMarkIcon";const ee={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.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=_.forwardRef(function(t,n){return _.createElement(P,Object.assign({},t,{id:"close-icon",ref:n,icon:ee}))});V.displayName="CloseIcon";class te{constructor(){C(this,"_position",null);C(this,"_position$",new b.BehaviorSubject(null));C(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 z=s.createIdentifier("univer.sheet-zen-editor-manager.service"),ne="ZEN_EDITOR_PLUGIN_",ie=`${ne}ZEN_EDITOR_COMPONENT`,re={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 oe(){const e=_.useRef(null),t=d.useDependency(z),n=d.useDependency(N.IEditorService),i=d.useDependency(s.ICommandService);_.useEffect(()=>{const a=e.current;if(!a)return;const l=n.register({editorUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,initialSnapshot:re,scrollBar:!0,backScrollOffset:100},a),u=new ResizeObserver(()=>{t.setPosition(a.getBoundingClientRect())});return u.observe(a),()=>{l.dispose(),u.unobserve(a)}},[]);function r(){const a=n.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);a==null||a.blur(),i.executeCommand(Z.id)}function o(){const a=n.getEditor(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);a==null||a.blur(),i.executeCommand(w.id)}const c="univer-flex univer-w-7 univer-cursor-pointer univer-items-center univer-justify-center univer-transition-colors";return v.jsxs("div",{className:"univer-absolute univer-inset-0 univer-size-full univer-bg-white dark:!univer-bg-gray-800",children:[v.jsxs("div",{className:"univer-absolute univer-right-6 univer-top-2 univer-z-10 univer-flex univer-items-center univer-justify-center",children:[v.jsx("span",{className:$.clsx(c,`
|
|
2
2
|
univer-text-red-500
|
|
3
3
|
hover:univer-text-red-600
|
|
4
|
-
`),onClick:r,children:
|
|
4
|
+
`),onClick:r,children:v.jsx(V,{className:"univer-size-5"})}),v.jsx("span",{className:$.clsx(c,`
|
|
5
5
|
univer-text-green-500
|
|
6
6
|
hover:univer-text-green-600
|
|
7
|
-
`),onClick:o,children:
|
|
7
|
+
`),onClick:o,children:v.jsx(F,{className:"univer-size-5"})})]}),v.jsx("div",{ref:e,className:"univer-absolute univer-inset-0 univer-size-full"})]})}function se(e){const t=e.get(h.IEditorBridgeService);return{id:U.id,type:d.MenuItemType.BUTTON,title:"rightClick.zenEditor",icon:"AmplifyIcon",hidden$:h.getCurrentExclusiveRangeInterest$(e),disabled$:t.currentEditCell$.pipe(b.switchMap(n=>h.getCurrentRangeDisable$(e,{workbookTypes:[p.WorkbookEditablePermission],worksheetTypes:[p.WorksheetEditPermission,p.WorksheetSetCellValuePermission,p.WorksheetSetCellStylePermission],rangeTypes:[p.RangeProtectionPermissionEditPoint]}).pipe(b.map(i=>{var r,o,c,a;return i||((a=(c=(o=(r=n==null?void 0:n.documentLayoutObject.documentModel)==null?void 0:r.getBody())==null?void 0:o.customBlocks)==null?void 0:c.length)!=null?a:0)>0}))))}}const ce={[d.ContextMenuPosition.MAIN_AREA]:{[d.ContextMenuGroup.OTHERS]:{[U.id]:{order:2,menuItemFactory:se}}}},ae={id:w.id,description:"shortcut.sheet.zen-edit-confirm",group:"4_sheet-edit",preconditions:e=>Y(e),binding:d.KeyCode.ENTER|d.MetaKeys.ALT},de={id:Z.id,description:"shortcut.sheet.zen-edit-cancel",group:"4_sheet-edit",preconditions:e=>Y(e),binding:d.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 le=Object.getOwnPropertyDescriptor,ue=(e,t,n,i)=>{for(var r=i>1?void 0:i?le(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},D=(e,t)=>(n,i)=>t(n,i,e);let R=class extends s.Disposable{constructor(e,t,n,i){super(),this._zenZoneService=e,this._commandService=t,this._menuManagerService=n,this._shortcutService=i,this._initialize()}_initialize(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts()}_initCustomComponents(){this.disposeWithMe(this._zenZoneService.set(ie,oe))}_initCommands(){[U,Z,w].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(ce)}_initShortcuts(){[ae,de].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}};R=ue([D(0,d.IZenZoneService),D(1,s.ICommandService),D(2,d.IMenuManagerService),D(3,d.IShortcutService)],R);var ge=Object.getOwnPropertyDescriptor,he=(e,t,n,i)=>{for(var r=i>1?void 0:i?ge(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},j=(e,t)=>(n,i)=>t(n,i,e);let M=class extends s.RxDisposable{constructor(e,t){super(),this._zenEditorManagerService=e,this._renderManagerService=t,this._initialize()}_initialize(){this._syncZenEditorSize()}_syncZenEditorSize(){this._zenEditorManagerService.position$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{width:t,height:n}=e,i=h.getEditorObject(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,this._renderManagerService);i!=null&&requestIdleCallback(()=>{i.engine.resizeBySize(t,n),this._calculatePagePosition(i),this._scrollToTop()})})}_calculatePagePosition(e){const{document:t,scene:n,docBackground:i}=e,r=n==null?void 0:n.getParent(),{width:o,height:c,pageMarginLeft:a,pageMarginTop:l}=t;if(r==null||o===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:u,height:m}=r;let g=0;const I=l;let S=0,T=0,E=Number.POSITIVE_INFINITY;const{scaleX:f,scaleY:O}=n.getAncestorScale();u>(o+a*2)*f?(g=u/2-o*f/2,g/=f,S=(u-a*2)/f,E=0):(g=a,S=o+a*2,E=(S-u/f)/2),m>c?T=(m-l*2)/O:T=c+l*2,n.resize(S,T),t.translate(g,I),i.translate(g,I);const x=n.getViewport(N.VIEWPORT_KEY.VIEW_MAIN);if(E!==Number.POSITIVE_INFINITY&&x!=null){const K=x.transScroll2ViewportScrollValue(E,0).x;x.scrollToBarPos({x:K})}return this}_scrollToTop(){var n;const e=(n=this._renderManagerService.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:n.with(N.DocBackScrollRenderController),t={startOffset:0,endOffset:0};e&&e.scrollToRange(t)}};M=he([j(0,z),j(1,A.IRenderManagerService)],M);var _e=Object.getOwnPropertyDescriptor,Ie=(e,t,n,i)=>{for(var r=i>1?void 0:i?_e(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},B=(e,t)=>(n,i)=>t(n,i,e),y;exports.UniverSheetsZenEditorPlugin=(y=class extends s.Plugin{constructor(t=k,n,i){super(),this._config=t,this._injector=n,this._configService=i;const{menu:r,...o}=s.merge({},k,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(H,o),this._initializeDependencies(this._injector)}_initializeDependencies(t){[[R],[M],[z,{useClass:te}]].forEach(i=>t.add(i))}onReady(){this._injector.get(R)}onSteady(){this._injector.get(M)}},C(y,"pluginName","SHEET_ZEN_EDITOR_PLUGIN"),C(y,"type",s.UniverInstanceType.UNIVER_SHEET),y);exports.UniverSheetsZenEditorPlugin=Ie([B(1,s.Inject(s.Injector)),B(2,s.IConfigService)],exports.UniverSheetsZenEditorPlugin);exports.CancelZenEditCommand=Z;exports.ConfirmZenEditCommand=w;exports.OpenZenEditorCommand=U;
|