@univerjs/sheets-hyper-link 0.4.1-nightly.202410291304 → 0.4.2

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/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),rxjs=require("rxjs"),sheets=require("@univerjs/sheets"),engineFormula=require("@univerjs/engine-formula"),docs=require("@univerjs/docs"),sheetsHyperLink=require("@univerjs/sheets-hyper-link");var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5"),_a;exports.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);return!link||link.id!==id?link=position.link:matrix.realDeleteValue(position.row,position.column),Object.assign(link,payload),positionMap.set(id,{...payload,link}),matrix.setValue(payload.row,payload.column,link),this._linkUpdate$.next({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a7,_b,_c,_d,_e;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a7=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a7.getCellRaw(row,column),cellValueStr=((_e=(_d=cell==null?void 0:cell.v)!=null?_d:(_c=(_b=cell==null?void 0:cell.p)==null?void 0:_b.body)==null?void 0:_c.dataStream.slice(0,-2))!=null?_e:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a);exports.HyperLinkModel=__decorateClass$5([__decorateParam$5(0,core.IUniverInstanceService)],exports.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a2;let SheetsHyperLinkRefRangeController=(_a2=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a7,_b,_c;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a7=search.get("gid"))!=null?_a7:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{this._registerPosition(option.unitId,option.subUnitId,option.payload),this._watchPosition(option.unitId,option.subUnitId,option.payload),this._registerRange(option.unitId,option.payload.id,option.payload.payload);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_a2,"SheetsHyperLinkRefRangeController"),_a2);SheetsHyperLinkRefRangeController=__decorateClass$4([__decorateParam$4(0,core.Inject(sheets.RefRangeService)),__decorateParam$4(1,core.Inject(exports.HyperLinkModel)),__decorateParam$4(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$4(3,core.ICommandService)],SheetsHyperLinkRefRangeController);const AddHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),univerInstanceService=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),sheetInterceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId,workbook,worksheet}=target,{link}=params,{payload,display,row,column,id}=link,cellData=worksheet.getCell(row,column),doc=worksheet.getBlankCellDocumentModel(cellData),snapshot=doc.documentModel.getSnapshot(),body=core.Tools.deepClone(snapshot.body);if(!body)return!1;let textX;if(display?textX=core.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:body.dataStream.length-2,collapsed:!0},body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{startIndex:0,endIndex:display.length+1,rangeType:core.CustomRangeType.HYPERLINK,rangeId:id,properties:{url:payload}}]},doc:doc.documentModel}):textX=core.BuildTextUtils.customRange.add({body,range:{startOffset:0,endOffset:body.dataStream.length-2,collapsed:!1},rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:id}}),!textX)return!1;const newBody=core.TextX.apply(body,textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await sheetInterceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redoParams={unitId,subUnitId,cellValue:{[link.row]:{[link.column]:finalCellData}}},redo={id:sheets.SetRangeValuesMutation.id,params:redoParams},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redoParams),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},AddRichHyperLinkCommand={id:"sheets.command.add-rich-hyper-link",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{if(!params)return!1;const{documentId,link}=params,commandService=accessor.get(core.ICommandService),newId=core.generateRandomId(),{payload}=link,replaceSelection=docs.addCustomRangeBySelectionFactory(accessor,{unitId:documentId,rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:newId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")},CancelHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(accessor,params){var _a7,_b;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),target=sheets.getSheetCommandTarget(instanceSrv,params);if(!target)return!1;const{row,column,id}=params,{unitId,subUnitId,worksheet}=target,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=core.Tools.deepClone(doc.documentModel.getSnapshot());if(!((_b=(_a7=snapshot.body)==null?void 0:_a7.customRanges)==null?void 0:_b.find(range2=>range2.rangeId===id)))return!1;const textX=core.BuildTextUtils.customRange.delete(accessor,{documentDataModel:doc.documentModel,rangeId:id});if(!textX)return!1;const newBody=core.TextX.apply(snapshot.body,textX.serialize()),redos=[],undos=[],setRangeParams={unitId,subUnitId,cellValue:{[row]:{[column]:{p:{...snapshot,body:newBody},t:core.CellValueType.STRING}}}};redos.push({id:sheets.SetRangeValuesMutation.id,params:setRangeParams});const undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,setRangeParams);undos.push({id:sheets.SetRangeValuesMutation.id,params:undoParams});const link=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return link&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:{...link}}})),core.sequenceExecute(redos,commandService).result?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},CancelRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(accessor,params){var _a7,_b;if(!params)return!1;const{id:linkId,documentId}=params,commandService=accessor.get(core.ICommandService),doc=accessor.get(core.IUniverInstanceService).getUnit(documentId,core.UniverInstanceType.UNIVER_DOC),link=(_b=(_a7=doc==null?void 0:doc.getBody())==null?void 0:_a7.customRanges)==null?void 0:_b.find(i=>i.rangeId===linkId);let insert=null;link&&link.endIndex===doc.getBody().dataStream.length-3&&(insert={dataStream:" "});const doMutation=docs.deleteCustomRangeFactory(accessor,{unitId:documentId,rangeId:linkId,insert});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(accessor,params){var _a7,_b,_c;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),interceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(instanceSrv);if(!target)return!1;const{payload:link,row,column,id}=params,{workbook,worksheet,unitId,subUnitId}=target,{payload,display=""}=link,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=doc.documentModel.getSnapshot(),range=(_b=(_a7=snapshot.body)==null?void 0:_a7.customRanges)==null?void 0:_b.find(range2=>range2.rangeId===id);if(!range)return!1;const newId=core.generateRandomId(),textRun=(_c=core.getBodySlice(doc.documentModel.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_c[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length+1,properties:{url:payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc:doc.documentModel});if(!replaceSelection)return!1;const newBody=core.TextX.apply(core.Tools.deepClone(snapshot.body),replaceSelection.textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await interceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redo={id:sheets.SetRangeValuesMutation.id,params:{unitId,subUnitId,cellValue:{[row]:{[column]:finalCellData}}}},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redo.params),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},UpdateRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:__name((accessor,params)=>{var _a7,_b,_c,_d;if(!params)return!1;const{documentId:unitId,payload,id:rangeId}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return!1;const range=(_b=(_a7=doc.getBody())==null?void 0:_a7.customRanges)==null?void 0:_b.find(range2=>range2.rangeId===rangeId);if(!range)return!1;const display=(_c=params.payload.display)!=null?_c:"",newId=core.generateRandomId(),textRun=(_d=core.getBodySlice(doc.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_d[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length+1,properties:{url:payload.payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a3;let SheetsHyperLinkController=(_a3=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkCommand,UpdateHyperLinkCommand,CancelHyperLinkCommand,UpdateRichHyperLinkCommand,CancelRichHyperLinkCommand,AddRichHyperLinkCommand,AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_a3,"SheetsHyperLinkController"),_a3);SheetsHyperLinkController=__decorateClass$3([__decorateParam$3(0,core.ICommandService)],SheetsHyperLinkController);var R=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(R||{}),__defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a4;let SheetsHyperLinkResourceController=(_a4=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[R.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_a4,"SheetsHyperLinkResourceController"),_a4);SheetsHyperLinkResourceController=__decorateClass$2([__decorateParam$2(0,core.IResourceManagerService),__decorateParam$2(1,core.Inject(exports.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a5;exports.SheetsHyperLinkParserService=(_a5=class{constructor(_univerInstanceService,_localeService,_definedNamesService){this._univerInstanceService=_univerInstanceService,this._localeService=_localeService,this._definedNamesService=_definedNamesService}buildHyperLink(unitId,sheetId,range){return`#${SheetHyperLinkType.SHEET}=${sheetId}${range?`&${typeof range=="string"?SheetHyperLinkType.DEFINE_NAME:SheetHyperLinkType.RANGE}=${typeof range=="string"?range:engineFormula.serializeRange(range)}`:""}`}parseHyperLink(urlStr){var _a7,_b,_c,_d;if(urlStr.startsWith("#")){const search=new URLSearchParams(urlStr.slice(1)),searchObj={gid:(_a7=search.get("gid"))!=null?_a7:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:"",unitid:(_d=search.get("unitid"))!=null?_d:""},urlInfo=this._getURLName(searchObj);return{type:urlInfo.type,name:urlInfo.name,url:urlStr,searchObj}}else return{type:SheetHyperLinkType.URL,name:urlStr,url:urlStr,searchObj:null}}_getURLName(params){var _a7;const{gid,range,rangeid,unitid}=params,workbook=unitid?this._univerInstanceService.getUnit(unitid,core.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),invalidLink={type:SheetHyperLinkType.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!workbook)return invalidLink;const sheet=gid?workbook.getSheetBySheetId(gid):workbook.getActiveSheet(),sheetName=(_a7=sheet==null?void 0:sheet.getName())!=null?_a7:"";if(range){if(!sheet)return invalidLink;const rangeObj=engineFormula.deserializeRangeWithSheet(range).range;return core.isValidRange(rangeObj,sheet)&&range!==ERROR_RANGE?{type:SheetHyperLinkType.RANGE,name:engineFormula.serializeRangeWithSheet(sheetName,rangeObj)}:invalidLink}if(rangeid){const range2=this._definedNamesService.getValueById(workbook.getUnitId(),rangeid);return range2?{type:SheetHyperLinkType.DEFINE_NAME,name:range2.formulaOrRefString}:invalidLink}if(gid){const worksheet=workbook.getSheetBySheetId(gid);return worksheet?{type:SheetHyperLinkType.SHEET,name:worksheet.getName()}:invalidLink}return invalidLink}},__name(_a5,"SheetsHyperLinkParserService"),_a5);exports.SheetsHyperLinkParserService=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(core.LocaleService)),__decorateParam$1(2,engineFormula.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a6;exports.UniverSheetsHyperLinkPlugin=(_a6=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){core.registerDependencies(this._injector,[[exports.SheetsHyperLinkParserService],[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports.HyperLinkModel]]),core.touchDependencies(this._injector,[[SheetsHyperLinkRefRangeController],[SheetsHyperLinkResourceController],[SheetsHyperLinkController]])}},__name(_a6,"UniverSheetsHyperLinkPlugin"),_a6);__publicField2(exports.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN);__publicField2(exports.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=AddHyperLinkCommand;exports.AddHyperLinkMutation=AddHyperLinkMutation;exports.AddRichHyperLinkCommand=AddRichHyperLinkCommand;exports.CancelHyperLinkCommand=CancelHyperLinkCommand;exports.CancelRichHyperLinkCommand=CancelRichHyperLinkCommand;exports.ERROR_RANGE=ERROR_RANGE;exports.RemoveHyperLinkMutation=RemoveHyperLinkMutation;exports.SheetHyperLinkType=SheetHyperLinkType;exports.UpdateHyperLinkCommand=UpdateHyperLinkCommand;exports.UpdateHyperLinkMutation=UpdateHyperLinkMutation;exports.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation;exports.UpdateRichHyperLinkCommand=UpdateRichHyperLinkCommand;
1
+ "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),rxjs=require("rxjs"),sheets=require("@univerjs/sheets"),engineFormula=require("@univerjs/engine-formula");var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a;exports.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);return!link||link.id!==id?link=position.link:matrix.realDeleteValue(position.row,position.column),Object.assign(link,payload),positionMap.set(id,{...payload,link}),matrix.setValue(payload.row,payload.column,link),this._linkUpdate$.next({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a6,_b,_c,_d,_e;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a6=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a6.getCellRaw(row,column),cellValueStr=((_e=(_d=cell==null?void 0:cell.v)!=null?_d:(_c=(_b=cell==null?void 0:cell.p)==null?void 0:_b.body)==null?void 0:_c.dataStream.slice(0,-2))!=null?_e:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a);exports.HyperLinkModel=__decorateClass$4([__decorateParam$4(0,core.IUniverInstanceService)],exports.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a2;let SheetsHyperLinkRefRangeController=(_a2=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a6,_b,_c;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a6=search.get("gid"))!=null?_a6:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{this._registerPosition(option.unitId,option.subUnitId,option.payload),this._watchPosition(option.unitId,option.subUnitId,option.payload),this._registerRange(option.unitId,option.payload.id,option.payload.payload);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_a2,"SheetsHyperLinkRefRangeController"),_a2);SheetsHyperLinkRefRangeController=__decorateClass$3([__decorateParam$3(0,core.Inject(sheets.RefRangeService)),__decorateParam$3(1,core.Inject(exports.HyperLinkModel)),__decorateParam$3(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$3(3,core.ICommandService)],SheetsHyperLinkRefRangeController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a3;let SheetsHyperLinkController=(_a3=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_a3,"SheetsHyperLinkController"),_a3);SheetsHyperLinkController=__decorateClass$2([__decorateParam$2(0,core.ICommandService)],SheetsHyperLinkController);var _=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(_||{}),__defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a4;let SheetsHyperLinkResourceController=(_a4=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[_.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_a4,"SheetsHyperLinkResourceController"),_a4);SheetsHyperLinkResourceController=__decorateClass$1([__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a5;exports.UniverSheetsHyperLinkPlugin=(_a5=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports.HyperLinkModel]].forEach(dep=>{this._injector.add(dep)}),this._injector.get(SheetsHyperLinkRefRangeController),this._injector.get(SheetsHyperLinkResourceController),this._injector.get(SheetsHyperLinkController)}},__name(_a5,"UniverSheetsHyperLinkPlugin"),_a5);__publicField2(exports.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN);__publicField2(exports.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkMutation=AddHyperLinkMutation;exports.ERROR_RANGE=ERROR_RANGE;exports.RemoveHyperLinkMutation=RemoveHyperLinkMutation;exports.SheetHyperLinkType=SheetHyperLinkType;exports.UpdateHyperLinkMutation=UpdateHyperLinkMutation;exports.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation;
package/lib/es/index.js CHANGED
@@ -2,17 +2,15 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService, CommandType, Inject, ICommandService, sequenceExecuteAsync, isValidRange, toDisposable, IUndoRedoService, Tools, BuildTextUtils, DataStreamTreeTokenType, CustomRangeType, TextX, CellValueType, generateRandomId, sequenceExecute, getBodySlice, IResourceManagerService, LocaleService, DependentOn, Injector, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
5
+ import { Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService, CommandType, Inject, ICommandService, sequenceExecuteAsync, isValidRange, toDisposable, IResourceManagerService, DependentOn, Injector, Plugin, IConfigService } from "@univerjs/core";
6
6
  import { Subject } from "rxjs";
7
- import { RefRangeService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, SheetInterceptorService, getSheetCommandTarget, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, UniverSheetsPlugin } from "@univerjs/sheets";
8
- import { deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet, IDefinedNamesService } from "@univerjs/engine-formula";
9
- import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
10
- import { HyperLinkModel as HyperLinkModel$1, RemoveHyperLinkMutation as RemoveHyperLinkMutation$1, AddHyperLinkMutation as AddHyperLinkMutation$1 } from "@univerjs/sheets-hyper-link";
11
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
12
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
7
+ import { RefRangeService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, UniverSheetsPlugin } from "@univerjs/sheets";
8
+ import { deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
9
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
10
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
13
11
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
14
- return kind && result && __defProp$5(target, key, result), result;
15
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a;
12
+ return kind && result && __defProp$4(target, key, result), result;
13
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
16
14
  let HyperLinkModel = (_a = class extends Disposable {
17
15
  constructor(_univerInstanceService) {
18
16
  super();
@@ -102,8 +100,8 @@ let HyperLinkModel = (_a = class extends Disposable {
102
100
  return matrix.getValue(row, column);
103
101
  }
104
102
  getHyperLinkByLocationSync(unitId, subUnitId, row, column) {
105
- var _a7, _b, _c, _d, _e;
106
- const { matrix } = this._ensureMap(unitId, subUnitId), workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), cell = (_a7 = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId)) == null ? void 0 : _a7.getCellRaw(row, column), cellValueStr = ((_e = (_d = cell == null ? void 0 : cell.v) != null ? _d : (_c = (_b = cell == null ? void 0 : cell.p) == null ? void 0 : _b.body) == null ? void 0 : _c.dataStream.slice(0, -2)) != null ? _e : "").toString(), link = matrix.getValue(row, column);
103
+ var _a6, _b, _c, _d, _e;
104
+ const { matrix } = this._ensureMap(unitId, subUnitId), workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), cell = (_a6 = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId)) == null ? void 0 : _a6.getCellRaw(row, column), cellValueStr = ((_e = (_d = cell == null ? void 0 : cell.v) != null ? _d : (_c = (_b = cell == null ? void 0 : cell.p) == null ? void 0 : _b.body) == null ? void 0 : _c.dataStream.slice(0, -2)) != null ? _e : "").toString(), link = matrix.getValue(row, column);
107
105
  if (link)
108
106
  return {
109
107
  ...link,
@@ -139,8 +137,8 @@ let HyperLinkModel = (_a = class extends Disposable {
139
137
  return Array.from(this._linkMap.keys()).map((unitId) => this.getUnit(unitId));
140
138
  }
141
139
  }, __name(_a, "HyperLinkModel"), _a);
142
- HyperLinkModel = __decorateClass$5([
143
- __decorateParam$5(0, IUniverInstanceService)
140
+ HyperLinkModel = __decorateClass$4([
141
+ __decorateParam$4(0, IUniverInstanceService)
144
142
  ], HyperLinkModel);
145
143
  var SheetHyperLinkType = /* @__PURE__ */ ((SheetHyperLinkType2) => (SheetHyperLinkType2.SHEET = "gid", SheetHyperLinkType2.RANGE = "range", SheetHyperLinkType2.DEFINE_NAME = "rangeid", SheetHyperLinkType2.INVALID = "invalid", SheetHyperLinkType2.URL = "url", SheetHyperLinkType2))(SheetHyperLinkType || {});
146
144
  const PLUGIN_CONFIG_KEY = "sheets-hyper-link.config", defaultPluginConfig = {}, AddHyperLinkMutation = {
@@ -180,11 +178,11 @@ const PLUGIN_CONFIG_KEY = "sheets-hyper-link.config", defaultPluginConfig = {},
180
178
  return model.updateHyperLinkRef(unitId, subUnitId, id, { row, column }, silent);
181
179
  }
182
180
  }, SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN", ERROR_RANGE = "err";
183
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
184
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
181
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
182
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
185
183
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
186
- return kind && result && __defProp$4(target, key, result), result;
187
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a2;
184
+ return kind && result && __defProp$3(target, key, result), result;
185
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
188
186
  let SheetsHyperLinkRefRangeController = (_a2 = class extends Disposable {
189
187
  constructor(_refRangeService, _hyperLinkModel, _selectionManagerService, _commandService) {
190
188
  super();
@@ -282,10 +280,10 @@ let SheetsHyperLinkRefRangeController = (_a2 = class extends Disposable {
282
280
  disposable == null || disposable.dispose(), this._watchDisposableMap.delete(id);
283
281
  }
284
282
  _registerRange(unitId, id, payload, silent = !1) {
285
- var _a7, _b, _c;
283
+ var _a6, _b, _c;
286
284
  if (payload.startsWith("#")) {
287
285
  const search = new URLSearchParams(payload.slice(1)), searchObj = {
288
- gid: (_a7 = search.get("gid")) != null ? _a7 : "",
286
+ gid: (_a6 = search.get("gid")) != null ? _a6 : "",
289
287
  range: (_b = search.get("range")) != null ? _b : "",
290
288
  rangeid: (_c = search.get("rangeid")) != null ? _c : ""
291
289
  };
@@ -391,329 +389,23 @@ let SheetsHyperLinkRefRangeController = (_a2 = class extends Disposable {
391
389
  }));
392
390
  }
393
391
  }, __name(_a2, "SheetsHyperLinkRefRangeController"), _a2);
394
- SheetsHyperLinkRefRangeController = __decorateClass$4([
395
- __decorateParam$4(0, Inject(RefRangeService)),
396
- __decorateParam$4(1, Inject(HyperLinkModel)),
397
- __decorateParam$4(2, Inject(SheetsSelectionsService)),
398
- __decorateParam$4(3, ICommandService)
392
+ SheetsHyperLinkRefRangeController = __decorateClass$3([
393
+ __decorateParam$3(0, Inject(RefRangeService)),
394
+ __decorateParam$3(1, Inject(HyperLinkModel)),
395
+ __decorateParam$3(2, Inject(SheetsSelectionsService)),
396
+ __decorateParam$3(3, ICommandService)
399
397
  ], SheetsHyperLinkRefRangeController);
400
- const AddHyperLinkCommand = {
401
- type: CommandType.COMMAND,
402
- id: "sheets.command.add-hyper-link",
403
- // eslint-disable-next-line max-lines-per-function
404
- async handler(accessor, params) {
405
- if (!params) return !1;
406
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel$1), sheetInterceptorService = accessor.get(SheetInterceptorService), target = getSheetCommandTarget(univerInstanceService, params);
407
- if (!target) return !1;
408
- const { unitId, subUnitId, workbook, worksheet } = target, { link } = params, { payload, display, row, column, id } = link, cellData = worksheet.getCell(row, column), doc = worksheet.getBlankCellDocumentModel(cellData), snapshot = doc.documentModel.getSnapshot(), body = Tools.deepClone(snapshot.body);
409
- if (!body) return !1;
410
- let textX;
411
- if (display ? textX = BuildTextUtils.selection.replace({
412
- selection: {
413
- startOffset: 0,
414
- endOffset: body.dataStream.length - 2,
415
- collapsed: !0
416
- },
417
- body: {
418
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
419
- customRanges: [{
420
- startIndex: 0,
421
- endIndex: display.length + 1,
422
- rangeType: CustomRangeType.HYPERLINK,
423
- rangeId: id,
424
- properties: {
425
- url: payload
426
- // refId: id,
427
- }
428
- }]
429
- },
430
- doc: doc.documentModel
431
- }) : textX = BuildTextUtils.customRange.add({
432
- body,
433
- range: { startOffset: 0, endOffset: body.dataStream.length - 2, collapsed: !1 },
434
- rangeId: id,
435
- rangeType: CustomRangeType.HYPERLINK,
436
- properties: {
437
- url: payload,
438
- refId: id
439
- }
440
- }), !textX) return !1;
441
- const newBody = TextX.apply(body, textX.serialize()), newCellData = {
442
- p: {
443
- ...snapshot,
444
- body: newBody
445
- },
446
- t: CellValueType.STRING
447
- }, finalCellData = await sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redoParams = {
448
- unitId,
449
- subUnitId,
450
- cellValue: {
451
- [link.row]: {
452
- [link.column]: finalCellData
453
- }
454
- }
455
- }, redo = {
456
- id: SetRangeValuesMutation.id,
457
- params: redoParams
458
- }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams), undo = {
459
- id: SetRangeValuesMutation.id,
460
- params: undoParams
461
- }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
462
- return modelLink && (redos.push({
463
- id: RemoveHyperLinkMutation$1.id,
464
- params: {
465
- unitId,
466
- subUnitId,
467
- id: modelLink.id
468
- }
469
- }), undos.push({
470
- id: AddHyperLinkMutation$1.id,
471
- params: {
472
- unitId,
473
- subUnitId,
474
- link: modelLink
475
- }
476
- })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
477
- redoMutations: redos,
478
- undoMutations: undos,
479
- unitID: unitId
480
- }), !0) : !1;
481
- }
482
- }, AddRichHyperLinkCommand = {
483
- id: "sheets.command.add-rich-hyper-link",
484
- type: CommandType.COMMAND,
485
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
486
- if (!params)
487
- return !1;
488
- const { documentId, link } = params, commandService = accessor.get(ICommandService), newId = generateRandomId(), { payload } = link, replaceSelection = addCustomRangeBySelectionFactory(accessor, {
489
- unitId: documentId,
490
- rangeId: newId,
491
- rangeType: CustomRangeType.HYPERLINK,
492
- properties: {
493
- url: payload,
494
- refId: newId
495
- }
496
- });
497
- return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
498
- }, "handler")
499
- }, CancelHyperLinkCommand = {
500
- type: CommandType.COMMAND,
501
- id: "sheets.command.cancel-hyper-link",
502
- // eslint-disable-next-line max-lines-per-function
503
- handler(accessor, params) {
504
- var _a7, _b;
505
- if (!params) return !1;
506
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel$1), target = getSheetCommandTarget(instanceSrv, params);
507
- if (!target) return !1;
508
- const { row, column, id } = params, { unitId, subUnitId, worksheet } = target, cellData = worksheet.getCell(row, column);
509
- if (!cellData) return !1;
510
- const doc = worksheet.getCellDocumentModelWithFormula(cellData);
511
- if (!(doc != null && doc.documentModel)) return !1;
512
- const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
513
- if (!((_b = (_a7 = snapshot.body) == null ? void 0 : _a7.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === id))) return !1;
514
- const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
515
- if (!textX) return !1;
516
- const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
517
- unitId,
518
- subUnitId,
519
- cellValue: {
520
- [row]: {
521
- [column]: {
522
- p: {
523
- ...snapshot,
524
- body: newBody
525
- },
526
- t: CellValueType.STRING
527
- }
528
- }
529
- }
530
- };
531
- redos.push({
532
- id: SetRangeValuesMutation.id,
533
- params: setRangeParams
534
- });
535
- const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
536
- undos.push({
537
- id: SetRangeValuesMutation.id,
538
- params: undoParams
539
- });
540
- const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
541
- return link && (redos.push({
542
- id: RemoveHyperLinkMutation$1.id,
543
- params: {
544
- unitId,
545
- subUnitId,
546
- id
547
- }
548
- }), undos.push({
549
- id: AddHyperLinkMutation$1.id,
550
- params: {
551
- unitId,
552
- subUnitId,
553
- link: {
554
- ...link
555
- }
556
- }
557
- })), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
558
- redoMutations: redos,
559
- undoMutations: undos,
560
- unitID: unitId
561
- }), !0) : !1;
562
- }
563
- }, CancelRichHyperLinkCommand = {
564
- type: CommandType.COMMAND,
565
- id: "sheets.command.cancel-rich-hyper-link",
566
- handler(accessor, params) {
567
- var _a7, _b;
568
- if (!params)
569
- return !1;
570
- const { id: linkId, documentId } = params, commandService = accessor.get(ICommandService), doc = accessor.get(IUniverInstanceService).getUnit(documentId, UniverInstanceType.UNIVER_DOC), link = (_b = (_a7 = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _a7.customRanges) == null ? void 0 : _b.find((i) => i.rangeId === linkId);
571
- let insert = null;
572
- link && link.endIndex === doc.getBody().dataStream.length - 3 && (insert = {
573
- dataStream: " "
574
- });
575
- const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
576
- return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
577
- }
578
- }, UpdateHyperLinkCommand = {
579
- type: CommandType.COMMAND,
580
- id: "sheets.command.update-hyper-link",
581
- // eslint-disable-next-line max-lines-per-function
582
- async handler(accessor, params) {
583
- var _a7, _b, _c;
584
- if (!params) return !1;
585
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel$1), interceptorService = accessor.get(SheetInterceptorService), target = getSheetCommandTarget(instanceSrv);
586
- if (!target) return !1;
587
- const { payload: link, row, column, id } = params, { workbook, worksheet, unitId, subUnitId } = target, { payload, display = "" } = link, cellData = worksheet.getCell(row, column);
588
- if (!cellData) return !1;
589
- const doc = worksheet.getCellDocumentModelWithFormula(cellData);
590
- if (!(doc != null && doc.documentModel)) return !1;
591
- const snapshot = doc.documentModel.getSnapshot(), range = (_b = (_a7 = snapshot.body) == null ? void 0 : _a7.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === id);
592
- if (!range) return !1;
593
- const newId = generateRandomId(), textRun = (_c = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _c[0];
594
- textRun && (textRun.ed = display.length + 1);
595
- const replaceSelection = replaceSelectionFactory(accessor, {
596
- unitId,
597
- body: {
598
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
599
- customRanges: [{
600
- rangeId: newId,
601
- rangeType: CustomRangeType.HYPERLINK,
602
- startIndex: 0,
603
- endIndex: display.length + 1,
604
- properties: {
605
- url: payload
606
- }
607
- }],
608
- textRuns: textRun ? [textRun] : void 0
609
- },
610
- selection: {
611
- startOffset: range.startIndex,
612
- endOffset: range.endIndex + 1,
613
- collapsed: !1
614
- },
615
- doc: doc.documentModel
616
- });
617
- if (!replaceSelection)
618
- return !1;
619
- const newBody = TextX.apply(Tools.deepClone(snapshot.body), replaceSelection.textX.serialize()), newCellData = {
620
- p: {
621
- ...snapshot,
622
- body: newBody
623
- },
624
- t: CellValueType.STRING
625
- }, finalCellData = await interceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redo = {
626
- id: SetRangeValuesMutation.id,
627
- params: {
628
- unitId,
629
- subUnitId,
630
- cellValue: {
631
- [row]: {
632
- [column]: finalCellData
633
- }
634
- }
635
- }
636
- }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
637
- id: SetRangeValuesMutation.id,
638
- params: undoParams
639
- }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
640
- return modelLink && (redos.push({
641
- id: RemoveHyperLinkMutation$1.id,
642
- params: {
643
- unitId,
644
- subUnitId,
645
- id: modelLink.id
646
- }
647
- }), undos.push({
648
- id: AddHyperLinkMutation$1.id,
649
- params: {
650
- unitId,
651
- subUnitId,
652
- link: modelLink
653
- }
654
- })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
655
- redoMutations: redos,
656
- undoMutations: undos,
657
- unitID: unitId
658
- }), !0) : !1;
659
- }
660
- }, UpdateRichHyperLinkCommand = {
661
- type: CommandType.COMMAND,
662
- id: "sheets.command.update-rich-hyper-link",
663
- handler: /* @__PURE__ */ __name((accessor, params) => {
664
- var _a7, _b, _c, _d;
665
- if (!params)
666
- return !1;
667
- const { documentId: unitId, payload, id: rangeId } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
668
- if (!doc)
669
- return !1;
670
- const range = (_b = (_a7 = doc.getBody()) == null ? void 0 : _a7.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === rangeId);
671
- if (!range)
672
- return !1;
673
- const display = (_c = params.payload.display) != null ? _c : "", newId = generateRandomId(), textRun = (_d = getBodySlice(doc.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _d[0];
674
- textRun && (textRun.ed = display.length + 1);
675
- const replaceSelection = replaceSelectionFactory(accessor, {
676
- unitId,
677
- body: {
678
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
679
- customRanges: [{
680
- rangeId: newId,
681
- rangeType: CustomRangeType.HYPERLINK,
682
- startIndex: 0,
683
- endIndex: display.length + 1,
684
- properties: {
685
- url: payload.payload
686
- }
687
- }],
688
- textRuns: textRun ? [textRun] : void 0
689
- },
690
- selection: {
691
- startOffset: range.startIndex,
692
- endOffset: range.endIndex + 1,
693
- collapsed: !1
694
- },
695
- doc
696
- });
697
- return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
698
- }, "handler")
699
- };
700
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
701
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
398
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
399
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
702
400
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
703
- return kind && result && __defProp$3(target, key, result), result;
704
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a3;
401
+ return kind && result && __defProp$2(target, key, result), result;
402
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
705
403
  let SheetsHyperLinkController = (_a3 = class extends Disposable {
706
404
  constructor(_commandService) {
707
405
  super(), this._commandService = _commandService, this._registerCommands();
708
406
  }
709
407
  _registerCommands() {
710
408
  [
711
- AddHyperLinkCommand,
712
- UpdateHyperLinkCommand,
713
- CancelHyperLinkCommand,
714
- UpdateRichHyperLinkCommand,
715
- CancelRichHyperLinkCommand,
716
- AddRichHyperLinkCommand,
717
409
  AddHyperLinkMutation,
718
410
  UpdateHyperLinkMutation,
719
411
  RemoveHyperLinkMutation,
@@ -723,14 +415,14 @@ let SheetsHyperLinkController = (_a3 = class extends Disposable {
723
415
  });
724
416
  }
725
417
  }, __name(_a3, "SheetsHyperLinkController"), _a3);
726
- SheetsHyperLinkController = __decorateClass$3([
727
- __decorateParam$3(0, ICommandService)
418
+ SheetsHyperLinkController = __decorateClass$2([
419
+ __decorateParam$2(0, ICommandService)
728
420
  ], SheetsHyperLinkController);
729
- var R = /* @__PURE__ */ ((E) => (E[E.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", E[E.UNIVER_DOC = 1] = "UNIVER_DOC", E[E.UNIVER_SHEET = 2] = "UNIVER_SHEET", E[E.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", E[E.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(R || {}), __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
730
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
421
+ var _ = /* @__PURE__ */ ((E) => (E[E.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", E[E.UNIVER_DOC = 1] = "UNIVER_DOC", E[E.UNIVER_SHEET = 2] = "UNIVER_SHEET", E[E.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", E[E.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(_ || {}), __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
422
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
731
423
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
732
- return kind && result && __defProp$2(target, key, result), result;
733
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a4;
424
+ return kind && result && __defProp$1(target, key, result), result;
425
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a4;
734
426
  let SheetsHyperLinkResourceController = (_a4 = class extends Disposable {
735
427
  constructor(_resourceManagerService, _hyperLinkModel) {
736
428
  super(), this._resourceManagerService = _resourceManagerService, this._hyperLinkModel = _hyperLinkModel, this._initSnapshot();
@@ -753,7 +445,7 @@ let SheetsHyperLinkResourceController = (_a4 = class extends Disposable {
753
445
  this.disposeWithMe(
754
446
  this._resourceManagerService.registerPluginResource({
755
447
  pluginName: SHEET_HYPER_LINK_PLUGIN,
756
- businesses: [R.UNIVER_SHEET],
448
+ businesses: [_.UNIVER_SHEET],
757
449
  toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
758
450
  parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
759
451
  onUnLoad: /* @__PURE__ */ __name((unitID) => {
@@ -770,109 +462,32 @@ let SheetsHyperLinkResourceController = (_a4 = class extends Disposable {
770
462
  );
771
463
  }
772
464
  }, __name(_a4, "SheetsHyperLinkResourceController"), _a4);
773
- SheetsHyperLinkResourceController = __decorateClass$2([
774
- __decorateParam$2(0, IResourceManagerService),
775
- __decorateParam$2(1, Inject(HyperLinkModel))
465
+ SheetsHyperLinkResourceController = __decorateClass$1([
466
+ __decorateParam$1(0, IResourceManagerService),
467
+ __decorateParam$1(1, Inject(HyperLinkModel))
776
468
  ], SheetsHyperLinkResourceController);
777
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
778
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
779
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
780
- return kind && result && __defProp$1(target, key, result), result;
781
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
782
- let SheetsHyperLinkParserService = (_a5 = class {
783
- constructor(_univerInstanceService, _localeService, _definedNamesService) {
784
- this._univerInstanceService = _univerInstanceService, this._localeService = _localeService, this._definedNamesService = _definedNamesService;
785
- }
786
- buildHyperLink(unitId, sheetId, range) {
787
- return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
788
- }
789
- parseHyperLink(urlStr) {
790
- var _a7, _b, _c, _d;
791
- if (urlStr.startsWith("#")) {
792
- const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
793
- gid: (_a7 = search.get("gid")) != null ? _a7 : "",
794
- range: (_b = search.get("range")) != null ? _b : "",
795
- rangeid: (_c = search.get("rangeid")) != null ? _c : "",
796
- unitid: (_d = search.get("unitid")) != null ? _d : ""
797
- }, urlInfo = this._getURLName(searchObj);
798
- return {
799
- type: urlInfo.type,
800
- name: urlInfo.name,
801
- url: urlStr,
802
- searchObj
803
- };
804
- } else
805
- return {
806
- type: SheetHyperLinkType.URL,
807
- name: urlStr,
808
- url: urlStr,
809
- searchObj: null
810
- };
811
- }
812
- _getURLName(params) {
813
- var _a7;
814
- const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
815
- type: SheetHyperLinkType.INVALID,
816
- name: this._localeService.t("hyperLink.message.refError")
817
- };
818
- if (!workbook)
819
- return invalidLink;
820
- const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a7 = sheet == null ? void 0 : sheet.getName()) != null ? _a7 : "";
821
- if (range) {
822
- if (!sheet) return invalidLink;
823
- const rangeObj = deserializeRangeWithSheet(range).range;
824
- return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
825
- type: SheetHyperLinkType.RANGE,
826
- name: serializeRangeWithSheet(sheetName, rangeObj)
827
- } : invalidLink;
828
- }
829
- if (rangeid) {
830
- const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
831
- return range2 ? {
832
- type: SheetHyperLinkType.DEFINE_NAME,
833
- name: range2.formulaOrRefString
834
- } : invalidLink;
835
- }
836
- if (gid) {
837
- const worksheet = workbook.getSheetBySheetId(gid);
838
- return worksheet ? {
839
- type: SheetHyperLinkType.SHEET,
840
- name: worksheet.getName()
841
- } : invalidLink;
842
- }
843
- return invalidLink;
844
- }
845
- }, __name(_a5, "SheetsHyperLinkParserService"), _a5);
846
- SheetsHyperLinkParserService = __decorateClass$1([
847
- __decorateParam$1(0, IUniverInstanceService),
848
- __decorateParam$1(1, Inject(LocaleService)),
849
- __decorateParam$1(2, IDefinedNamesService)
850
- ], SheetsHyperLinkParserService);
851
469
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
852
470
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
853
471
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
854
472
  return kind && result && __defProp2(target, key, result), result;
855
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a6;
856
- let UniverSheetsHyperLinkPlugin = (_a6 = class extends Plugin {
473
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a5;
474
+ let UniverSheetsHyperLinkPlugin = (_a5 = class extends Plugin {
857
475
  constructor(_config = defaultPluginConfig, _injector, _configService) {
858
476
  super(), this._config = _config, this._injector = _injector, this._configService = _configService;
859
477
  const { ...rest } = this._config;
860
478
  this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
861
479
  }
862
480
  onStarting() {
863
- registerDependencies(this._injector, [
864
- [SheetsHyperLinkParserService],
481
+ [
865
482
  [SheetsHyperLinkResourceController],
866
483
  [SheetsHyperLinkController],
867
484
  [SheetsHyperLinkRefRangeController],
868
485
  [HyperLinkModel]
869
- ]), touchDependencies(this._injector, [
870
- [SheetsHyperLinkRefRangeController],
871
- [SheetsHyperLinkResourceController],
872
- [SheetsHyperLinkController]
873
- ]);
486
+ ].forEach((dep) => {
487
+ this._injector.add(dep);
488
+ }), this._injector.get(SheetsHyperLinkRefRangeController), this._injector.get(SheetsHyperLinkResourceController), this._injector.get(SheetsHyperLinkController);
874
489
  }
875
- }, __name(_a6, "UniverSheetsHyperLinkPlugin"), _a6);
490
+ }, __name(_a5, "UniverSheetsHyperLinkPlugin"), _a5);
876
491
  __publicField2(UniverSheetsHyperLinkPlugin, "pluginName", SHEET_HYPER_LINK_PLUGIN);
877
492
  __publicField2(UniverSheetsHyperLinkPlugin, "type", UniverInstanceType.UNIVER_SHEET);
878
493
  UniverSheetsHyperLinkPlugin = __decorateClass([
@@ -881,19 +496,12 @@ UniverSheetsHyperLinkPlugin = __decorateClass([
881
496
  __decorateParam(2, IConfigService)
882
497
  ], UniverSheetsHyperLinkPlugin);
883
498
  export {
884
- AddHyperLinkCommand,
885
499
  AddHyperLinkMutation,
886
- AddRichHyperLinkCommand,
887
- CancelHyperLinkCommand,
888
- CancelRichHyperLinkCommand,
889
500
  ERROR_RANGE,
890
501
  HyperLinkModel,
891
502
  RemoveHyperLinkMutation,
892
503
  SheetHyperLinkType,
893
- SheetsHyperLinkParserService,
894
504
  UniverSheetsHyperLinkPlugin,
895
- UpdateHyperLinkCommand,
896
505
  UpdateHyperLinkMutation,
897
- UpdateHyperLinkRefMutation,
898
- UpdateRichHyperLinkCommand
506
+ UpdateHyperLinkRefMutation
899
507
  };
@@ -17,11 +17,7 @@ export { HyperLinkModel } from './models/hyper-link.model';
17
17
  export { SheetHyperLinkType } from './types/enums/hyper-link-type';
18
18
  export { UniverSheetsHyperLinkPlugin } from './plugin';
19
19
  export type { ICellHyperLink, ICellLinkContent } from './types/interfaces/i-hyper-link';
20
- export { type ISheetHyperLinkInfo, type ISheetUrlParams, SheetsHyperLinkParserService } from './services/parser.service';
21
20
  export { ERROR_RANGE } from './types/const';
22
- export { AddHyperLinkCommand, AddRichHyperLinkCommand, type IAddHyperLinkCommandParams, type IAddRichHyperLinkCommandParams } from './commands/commands/add-hyper-link.command';
23
- export { CancelHyperLinkCommand, CancelRichHyperLinkCommand, type ICancelHyperLinkCommandParams, type ICancelRichHyperLinkCommandParams } from './commands/commands/remove-hyper-link.command';
24
- export { type IUpdateHyperLinkCommandParams, type IUpdateRichHyperLinkCommandParams, UpdateHyperLinkCommand, UpdateRichHyperLinkCommand } from './commands/commands/update-hyper-link.command';
25
21
  export { AddHyperLinkMutation, type IAddHyperLinkMutationParams } from './commands/mutations/add-hyper-link.mutation';
26
22
  export { type IRemoveHyperLinkMutationParams, RemoveHyperLinkMutation } from './commands/mutations/remove-hyper-link.mutation';
27
23
  export { type IUpdateHyperLinkMutationParams, type IUpdateHyperLinkRefMutationParams, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation, } from './commands/mutations/update-hyper-link.mutation';
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs"),require("@univerjs/sheets-hyper-link")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs","@univerjs/sheets-hyper-link"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsHyperLink={},global.UniverCore,global.rxjs,global.UniverSheets,global.UniverEngineFormula,global.UniverDocs,global.UniverSheetsHyperLink))})(this,function(exports2,core,rxjs,sheets,engineFormula,docs,sheetsHyperLink){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f;var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");exports2.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);return!link||link.id!==id?link=position.link:matrix.realDeleteValue(position.row,position.column),Object.assign(link,payload),positionMap.set(id,{...payload,link}),matrix.setValue(payload.row,payload.column,link),this._linkUpdate$.next({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a2,_b2,_c2,_d2,_e2;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a2=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a2.getCellRaw(row,column),cellValueStr=((_e2=(_d2=cell==null?void 0:cell.v)!=null?_d2:(_c2=(_b2=cell==null?void 0:cell.p)==null?void 0:_b2.body)==null?void 0:_c2.dataStream.slice(0,-2))!=null?_e2:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a),exports2.HyperLinkModel=__decorateClass$5([__decorateParam$5(0,core.IUniverInstanceService)],exports2.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");let SheetsHyperLinkRefRangeController=(_b=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a2,_b2,_c2;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a2=search.get("gid"))!=null?_a2:"",range:(_b2=search.get("range"))!=null?_b2:"",rangeid:(_c2=search.get("rangeid"))!=null?_c2:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{this._registerPosition(option.unitId,option.subUnitId,option.payload),this._watchPosition(option.unitId,option.subUnitId,option.payload),this._registerRange(option.unitId,option.payload.id,option.payload.payload);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_b,"SheetsHyperLinkRefRangeController"),_b);SheetsHyperLinkRefRangeController=__decorateClass$4([__decorateParam$4(0,core.Inject(sheets.RefRangeService)),__decorateParam$4(1,core.Inject(exports2.HyperLinkModel)),__decorateParam$4(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$4(3,core.ICommandService)],SheetsHyperLinkRefRangeController);const AddHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),univerInstanceService=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),sheetInterceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId,workbook,worksheet}=target,{link}=params,{payload,display,row,column,id}=link,cellData=worksheet.getCell(row,column),doc=worksheet.getBlankCellDocumentModel(cellData),snapshot=doc.documentModel.getSnapshot(),body=core.Tools.deepClone(snapshot.body);if(!body)return!1;let textX;if(display?textX=core.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:body.dataStream.length-2,collapsed:!0},body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{startIndex:0,endIndex:display.length+1,rangeType:core.CustomRangeType.HYPERLINK,rangeId:id,properties:{url:payload}}]},doc:doc.documentModel}):textX=core.BuildTextUtils.customRange.add({body,range:{startOffset:0,endOffset:body.dataStream.length-2,collapsed:!1},rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:id}}),!textX)return!1;const newBody=core.TextX.apply(body,textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await sheetInterceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redoParams={unitId,subUnitId,cellValue:{[link.row]:{[link.column]:finalCellData}}},redo={id:sheets.SetRangeValuesMutation.id,params:redoParams},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redoParams),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},AddRichHyperLinkCommand={id:"sheets.command.add-rich-hyper-link",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{if(!params)return!1;const{documentId,link}=params,commandService=accessor.get(core.ICommandService),newId=core.generateRandomId(),{payload}=link,replaceSelection=docs.addCustomRangeBySelectionFactory(accessor,{unitId:documentId,rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:newId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")},CancelHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(accessor,params){var _a2,_b2;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),target=sheets.getSheetCommandTarget(instanceSrv,params);if(!target)return!1;const{row,column,id}=params,{unitId,subUnitId,worksheet}=target,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=core.Tools.deepClone(doc.documentModel.getSnapshot());if(!((_b2=(_a2=snapshot.body)==null?void 0:_a2.customRanges)==null?void 0:_b2.find(range2=>range2.rangeId===id)))return!1;const textX=core.BuildTextUtils.customRange.delete(accessor,{documentDataModel:doc.documentModel,rangeId:id});if(!textX)return!1;const newBody=core.TextX.apply(snapshot.body,textX.serialize()),redos=[],undos=[],setRangeParams={unitId,subUnitId,cellValue:{[row]:{[column]:{p:{...snapshot,body:newBody},t:core.CellValueType.STRING}}}};redos.push({id:sheets.SetRangeValuesMutation.id,params:setRangeParams});const undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,setRangeParams);undos.push({id:sheets.SetRangeValuesMutation.id,params:undoParams});const link=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return link&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:{...link}}})),core.sequenceExecute(redos,commandService).result?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},CancelRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(accessor,params){var _a2,_b2;if(!params)return!1;const{id:linkId,documentId}=params,commandService=accessor.get(core.ICommandService),doc=accessor.get(core.IUniverInstanceService).getUnit(documentId,core.UniverInstanceType.UNIVER_DOC),link=(_b2=(_a2=doc==null?void 0:doc.getBody())==null?void 0:_a2.customRanges)==null?void 0:_b2.find(i=>i.rangeId===linkId);let insert=null;link&&link.endIndex===doc.getBody().dataStream.length-3&&(insert={dataStream:" "});const doMutation=docs.deleteCustomRangeFactory(accessor,{unitId:documentId,rangeId:linkId,insert});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(accessor,params){var _a2,_b2,_c2;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(sheetsHyperLink.HyperLinkModel),interceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(instanceSrv);if(!target)return!1;const{payload:link,row,column,id}=params,{workbook,worksheet,unitId,subUnitId}=target,{payload,display=""}=link,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=doc.documentModel.getSnapshot(),range=(_b2=(_a2=snapshot.body)==null?void 0:_a2.customRanges)==null?void 0:_b2.find(range2=>range2.rangeId===id);if(!range)return!1;const newId=core.generateRandomId(),textRun=(_c2=core.getBodySlice(doc.documentModel.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_c2[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length+1,properties:{url:payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc:doc.documentModel});if(!replaceSelection)return!1;const newBody=core.TextX.apply(core.Tools.deepClone(snapshot.body),replaceSelection.textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await interceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redo={id:sheets.SetRangeValuesMutation.id,params:{unitId,subUnitId,cellValue:{[row]:{[column]:finalCellData}}}},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redo.params),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:sheetsHyperLink.RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:sheetsHyperLink.AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},UpdateRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:__name((accessor,params)=>{var _a2,_b2,_c2,_d2;if(!params)return!1;const{documentId:unitId,payload,id:rangeId}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return!1;const range=(_b2=(_a2=doc.getBody())==null?void 0:_a2.customRanges)==null?void 0:_b2.find(range2=>range2.rangeId===rangeId);if(!range)return!1;const display=(_c2=params.payload.display)!=null?_c2:"",newId=core.generateRandomId(),textRun=(_d2=core.getBodySlice(doc.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_d2[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length+1,properties:{url:payload.payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let SheetsHyperLinkController=(_c=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkCommand,UpdateHyperLinkCommand,CancelHyperLinkCommand,UpdateRichHyperLinkCommand,CancelRichHyperLinkCommand,AddRichHyperLinkCommand,AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_c,"SheetsHyperLinkController"),_c);SheetsHyperLinkController=__decorateClass$3([__decorateParam$3(0,core.ICommandService)],SheetsHyperLinkController);var R=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(R||{}),__defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetsHyperLinkResourceController=(_d=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[R.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_d,"SheetsHyperLinkResourceController"),_d);SheetsHyperLinkResourceController=__decorateClass$2([__decorateParam$2(0,core.IResourceManagerService),__decorateParam$2(1,core.Inject(exports2.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsHyperLinkParserService=(_e=class{constructor(_univerInstanceService,_localeService,_definedNamesService){this._univerInstanceService=_univerInstanceService,this._localeService=_localeService,this._definedNamesService=_definedNamesService}buildHyperLink(unitId,sheetId,range){return`#${SheetHyperLinkType.SHEET}=${sheetId}${range?`&${typeof range=="string"?SheetHyperLinkType.DEFINE_NAME:SheetHyperLinkType.RANGE}=${typeof range=="string"?range:engineFormula.serializeRange(range)}`:""}`}parseHyperLink(urlStr){var _a2,_b2,_c2,_d2;if(urlStr.startsWith("#")){const search=new URLSearchParams(urlStr.slice(1)),searchObj={gid:(_a2=search.get("gid"))!=null?_a2:"",range:(_b2=search.get("range"))!=null?_b2:"",rangeid:(_c2=search.get("rangeid"))!=null?_c2:"",unitid:(_d2=search.get("unitid"))!=null?_d2:""},urlInfo=this._getURLName(searchObj);return{type:urlInfo.type,name:urlInfo.name,url:urlStr,searchObj}}else return{type:SheetHyperLinkType.URL,name:urlStr,url:urlStr,searchObj:null}}_getURLName(params){var _a2;const{gid,range,rangeid,unitid}=params,workbook=unitid?this._univerInstanceService.getUnit(unitid,core.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),invalidLink={type:SheetHyperLinkType.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!workbook)return invalidLink;const sheet=gid?workbook.getSheetBySheetId(gid):workbook.getActiveSheet(),sheetName=(_a2=sheet==null?void 0:sheet.getName())!=null?_a2:"";if(range){if(!sheet)return invalidLink;const rangeObj=engineFormula.deserializeRangeWithSheet(range).range;return core.isValidRange(rangeObj,sheet)&&range!==ERROR_RANGE?{type:SheetHyperLinkType.RANGE,name:engineFormula.serializeRangeWithSheet(sheetName,rangeObj)}:invalidLink}if(rangeid){const range2=this._definedNamesService.getValueById(workbook.getUnitId(),rangeid);return range2?{type:SheetHyperLinkType.DEFINE_NAME,name:range2.formulaOrRefString}:invalidLink}if(gid){const worksheet=workbook.getSheetBySheetId(gid);return worksheet?{type:SheetHyperLinkType.SHEET,name:worksheet.getName()}:invalidLink}return invalidLink}},__name(_e,"SheetsHyperLinkParserService"),_e),exports2.SheetsHyperLinkParserService=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(core.LocaleService)),__decorateParam$1(2,engineFormula.IDefinedNamesService)],exports2.SheetsHyperLinkParserService);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsHyperLinkPlugin=(_f=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){core.registerDependencies(this._injector,[[exports2.SheetsHyperLinkParserService],[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports2.HyperLinkModel]]),core.touchDependencies(this._injector,[[SheetsHyperLinkRefRangeController],[SheetsHyperLinkResourceController],[SheetsHyperLinkController]])}},__name(_f,"UniverSheetsHyperLinkPlugin"),_f),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsHyperLinkPlugin),exports2.AddHyperLinkCommand=AddHyperLinkCommand,exports2.AddHyperLinkMutation=AddHyperLinkMutation,exports2.AddRichHyperLinkCommand=AddRichHyperLinkCommand,exports2.CancelHyperLinkCommand=CancelHyperLinkCommand,exports2.CancelRichHyperLinkCommand=CancelRichHyperLinkCommand,exports2.ERROR_RANGE=ERROR_RANGE,exports2.RemoveHyperLinkMutation=RemoveHyperLinkMutation,exports2.SheetHyperLinkType=SheetHyperLinkType,exports2.UpdateHyperLinkCommand=UpdateHyperLinkCommand,exports2.UpdateHyperLinkMutation=UpdateHyperLinkMutation,exports2.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation,exports2.UpdateRichHyperLinkCommand=UpdateRichHyperLinkCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsHyperLink={},global.UniverCore,global.rxjs,global.UniverSheets,global.UniverEngineFormula))})(this,function(exports2,core,rxjs,sheets,engineFormula){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e;var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");exports2.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);return!link||link.id!==id?link=position.link:matrix.realDeleteValue(position.row,position.column),Object.assign(link,payload),positionMap.set(id,{...payload,link}),matrix.setValue(payload.row,payload.column,link),this._linkUpdate$.next({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a2,_b2,_c2,_d2,_e2;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a2=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a2.getCellRaw(row,column),cellValueStr=((_e2=(_d2=cell==null?void 0:cell.v)!=null?_d2:(_c2=(_b2=cell==null?void 0:cell.p)==null?void 0:_b2.body)==null?void 0:_c2.dataStream.slice(0,-2))!=null?_e2:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a),exports2.HyperLinkModel=__decorateClass$4([__decorateParam$4(0,core.IUniverInstanceService)],exports2.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let SheetsHyperLinkRefRangeController=(_b=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a2,_b2,_c2;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a2=search.get("gid"))!=null?_a2:"",range:(_b2=search.get("range"))!=null?_b2:"",rangeid:(_c2=search.get("rangeid"))!=null?_c2:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{this._registerPosition(option.unitId,option.subUnitId,option.payload),this._watchPosition(option.unitId,option.subUnitId,option.payload),this._registerRange(option.unitId,option.payload.id,option.payload.payload);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_b,"SheetsHyperLinkRefRangeController"),_b);SheetsHyperLinkRefRangeController=__decorateClass$3([__decorateParam$3(0,core.Inject(sheets.RefRangeService)),__decorateParam$3(1,core.Inject(exports2.HyperLinkModel)),__decorateParam$3(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$3(3,core.ICommandService)],SheetsHyperLinkRefRangeController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetsHyperLinkController=(_c=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_c,"SheetsHyperLinkController"),_c);SheetsHyperLinkController=__decorateClass$2([__decorateParam$2(0,core.ICommandService)],SheetsHyperLinkController);var _=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(_||{}),__defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let SheetsHyperLinkResourceController=(_d=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[_.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_d,"SheetsHyperLinkResourceController"),_d);SheetsHyperLinkResourceController=__decorateClass$1([__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports2.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsHyperLinkPlugin=(_e=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports2.HyperLinkModel]].forEach(dep=>{this._injector.add(dep)}),this._injector.get(SheetsHyperLinkRefRangeController),this._injector.get(SheetsHyperLinkResourceController),this._injector.get(SheetsHyperLinkController)}},__name(_e,"UniverSheetsHyperLinkPlugin"),_e),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsHyperLinkPlugin),exports2.AddHyperLinkMutation=AddHyperLinkMutation,exports2.ERROR_RANGE=ERROR_RANGE,exports2.RemoveHyperLinkMutation=RemoveHyperLinkMutation,exports2.SheetHyperLinkType=SheetHyperLinkType,exports2.UpdateHyperLinkMutation=UpdateHyperLinkMutation,exports2.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "0.4.1-nightly.202410291304",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -47,18 +47,17 @@
47
47
  "rxjs": ">=7.0.0"
48
48
  },
49
49
  "dependencies": {
50
- "@univerjs/protocol": "0.1.39-alpha.36",
51
- "@univerjs/core": "0.4.1-nightly.202410291304",
52
- "@univerjs/docs": "0.4.1-nightly.202410291304",
53
- "@univerjs/sheets": "0.4.1-nightly.202410291304",
54
- "@univerjs/engine-formula": "0.4.1-nightly.202410291304"
50
+ "@univerjs/protocol": "0.1.39-alpha.38",
51
+ "@univerjs/core": "0.4.2",
52
+ "@univerjs/sheets": "0.4.2",
53
+ "@univerjs/engine-formula": "0.4.2"
55
54
  },
56
55
  "devDependencies": {
57
56
  "rxjs": "^7.8.1",
58
57
  "typescript": "^5.6.3",
59
58
  "vite": "^5.4.8",
60
59
  "vitest": "^2.1.2",
61
- "@univerjs-infra/shared": "0.4.1"
60
+ "@univerjs-infra/shared": "0.4.2"
62
61
  },
63
62
  "univerSpace": {
64
63
  ".": {
@@ -1,19 +0,0 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ICellHyperLink } from '@univerjs/sheets-hyper-link';
3
- export interface IAddHyperLinkCommandParams {
4
- unitId: string;
5
- subUnitId: string;
6
- link: ICellHyperLink;
7
- }
8
- /**
9
- * Command for add hyperlink
10
- */
11
- export declare const AddHyperLinkCommand: ICommand<IAddHyperLinkCommandParams>;
12
- export interface IAddRichHyperLinkCommandParams {
13
- /**
14
- * url of link
15
- */
16
- documentId: string;
17
- link: ICellHyperLink;
18
- }
19
- export declare const AddRichHyperLinkCommand: ICommand<IAddRichHyperLinkCommandParams>;
@@ -1,19 +0,0 @@
1
- import { ICommand } from '@univerjs/core';
2
- export interface ICancelHyperLinkCommandParams {
3
- unitId: string;
4
- subUnitId: string;
5
- /**
6
- * id of link
7
- */
8
- id: string;
9
- row: number;
10
- column: number;
11
- }
12
- export declare const CancelHyperLinkCommand: ICommand<ICancelHyperLinkCommandParams>;
13
- export interface ICancelRichHyperLinkCommandParams extends ICancelHyperLinkCommandParams {
14
- /**
15
- * document id
16
- */
17
- documentId: string;
18
- }
19
- export declare const CancelRichHyperLinkCommand: ICommand<ICancelRichHyperLinkCommandParams>;
@@ -1,17 +0,0 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ICellLinkContent } from '@univerjs/sheets-hyper-link';
3
- export interface IUpdateHyperLinkCommandParams {
4
- unitId: string;
5
- subUnitId: string;
6
- id: string;
7
- payload: ICellLinkContent;
8
- row: number;
9
- column: number;
10
- }
11
- export declare const UpdateHyperLinkCommand: ICommand<IUpdateHyperLinkCommandParams>;
12
- export interface IUpdateRichHyperLinkCommandParams {
13
- documentId: string;
14
- id: string;
15
- payload: ICellLinkContent;
16
- }
17
- export declare const UpdateRichHyperLinkCommand: ICommand<IUpdateRichHyperLinkCommandParams>;
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export interface ICellHyperLink {
17
- id: string;
18
- startIndex: number;
19
- endIndex: number;
20
- url: string;
21
- label: string;
22
- }
23
- interface IFRangeHyperlinkMixin {
24
- /**
25
- * Get all hyperlinks in the cell in the range.
26
- * @returns hyperlinks
27
- */
28
- getHyperLinks(): ICellHyperLink[];
29
- /**
30
- * Update hyperlink in the cell in the range.
31
- * @param id id of the hyperlink
32
- * @param url url
33
- * @param label optional, label of the url
34
- * @returns success or not
35
- */
36
- updateHyperLink(id: string, url: string, label?: string): Promise<boolean>;
37
- /**
38
- * Cancel hyperlink in the cell in the range.
39
- * @param id id of the hyperlink
40
- * @returns success or not
41
- */
42
- cancelHyperLink(id: string): Promise<boolean>;
43
- }
44
- declare module '@univerjs/sheets/facade' {
45
- interface FRange extends IFRangeHyperlinkMixin {
46
- }
47
- }
48
- export {};
@@ -1,32 +0,0 @@
1
- import { IRange } from '@univerjs/core';
2
- import { ISheetHyperLinkInfo } from '../services/parser.service';
3
- import { FWorkbook } from '@univerjs/sheets/facade';
4
- interface IFWorkbookHyperlinkMixin {
5
- /**
6
- * create a hyperlink for the sheet
7
- * @param sheetId the sheet id to link
8
- * @param range the range to link, or define-name id
9
- * @returns the hyperlink string
10
- */
11
- createSheetHyperlink(this: FWorkbook, sheetId: string, range?: string | IRange): string;
12
- /**
13
- * parse the hyperlink string to get the hyperlink info
14
- * @param hyperlink the hyperlink string
15
- * @returns the hyperlink info
16
- */
17
- parseSheetHyperlink(this: FWorkbook, hyperlink: string): ISheetHyperLinkInfo;
18
- }
19
- export declare class FWorkbookHyperLinkMixin extends FWorkbook implements IFWorkbookHyperlinkMixin {
20
- createSheetHyperlink(sheetId: string, range?: string | IRange): string;
21
- /**
22
- * parse the hyperlink string to get the hyperlink info
23
- * @param hyperlink the hyperlink string
24
- * @returns the hyperlink info
25
- */
26
- parseSheetHyperlink(hyperlink: string): ISheetHyperLinkInfo;
27
- }
28
- declare module '@univerjs/sheets/facade' {
29
- interface FWorkbook extends IFWorkbookHyperlinkMixin {
30
- }
31
- }
32
- export {};
@@ -1 +0,0 @@
1
- export { FWorkbookHyperLinkMixin } from './f-workbook';
@@ -1,24 +0,0 @@
1
- import { IRange, Nullable, IUniverInstanceService, LocaleService } from '@univerjs/core';
2
- import { IDefinedNamesService } from '@univerjs/engine-formula';
3
- import { SheetHyperLinkType } from '../types/enums/hyper-link-type';
4
- export interface ISheetUrlParams {
5
- gid?: string;
6
- range?: string;
7
- rangeid?: string;
8
- unitid?: string;
9
- }
10
- export interface ISheetHyperLinkInfo {
11
- type: SheetHyperLinkType;
12
- name: string;
13
- url: string;
14
- searchObj: Nullable<ISheetUrlParams>;
15
- }
16
- export declare class SheetsHyperLinkParserService {
17
- private _univerInstanceService;
18
- private _localeService;
19
- private _definedNamesService;
20
- constructor(_univerInstanceService: IUniverInstanceService, _localeService: LocaleService, _definedNamesService: IDefinedNamesService);
21
- buildHyperLink(unitId: string, sheetId: string, range?: string | IRange): string;
22
- parseHyperLink(urlStr: string): ISheetHyperLinkInfo;
23
- private _getURLName;
24
- }