@univerjs/sheets-hyper-link 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/facade.js +1 -180
  4. package/lib/es/index.js +1 -1282
  5. package/lib/facade.js +1 -180
  6. package/lib/index.js +1 -1282
  7. package/lib/types/commands/commands/add-hyper-link.command.d.ts +17 -2
  8. package/lib/types/commands/commands/remove-hyper-link.command.d.ts +16 -1
  9. package/lib/types/commands/commands/update-hyper-link.command.d.ts +17 -2
  10. package/lib/types/commands/mutations/add-hyper-link.mutation.d.ts +17 -2
  11. package/lib/types/commands/mutations/remove-hyper-link.mutation.d.ts +16 -1
  12. package/lib/types/commands/mutations/update-hyper-link.mutation.d.ts +17 -2
  13. package/lib/types/controllers/ref-range.controller.d.ts +15 -0
  14. package/lib/types/controllers/remove-sheet.controller.d.ts +15 -0
  15. package/lib/types/controllers/rich-text-ref-range.controller.d.ts +15 -0
  16. package/lib/types/controllers/set-range.controller.d.ts +15 -0
  17. package/lib/types/controllers/sheet-hyper-link-resource.controller.d.ts +15 -0
  18. package/lib/types/controllers/sheet-hyper-link.controller.d.ts +15 -0
  19. package/lib/types/facade/f-event.d.ts +18 -3
  20. package/lib/types/facade/f-range.d.ts +15 -0
  21. package/lib/types/facade/f-univer.d.ts +16 -1
  22. package/lib/types/facade/f-workbook.d.ts +20 -3
  23. package/lib/types/facade/f-worksheet.d.ts +15 -0
  24. package/lib/types/models/hyper-link.model.d.ts +18 -3
  25. package/lib/types/plugin.d.ts +16 -1
  26. package/lib/types/services/parser.service.d.ts +17 -1
  27. package/lib/umd/facade.js +1 -1
  28. package/lib/umd/index.js +1 -1
  29. package/package.json +10 -9
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ISheetHyperLink } from '../../types/interfaces/i-hyper-link';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
17
+ import type { ISheetHyperLink } from '../../types/interfaces/i-hyper-link';
3
18
  export interface IAddHyperLinkCommandParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,4 +1,19 @@
1
- import { ICommand } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
2
17
  export interface ICancelHyperLinkCommandParams {
3
18
  unitId: string;
4
19
  subUnitId: string;
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
17
+ import type { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
3
18
  export interface IUpdateHyperLinkCommandParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ISheetHyperLink } from '../../types/interfaces/i-hyper-link';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
17
+ import type { ISheetHyperLink } from '../../types/interfaces/i-hyper-link';
3
18
  export interface IAddHyperLinkMutationParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,4 +1,19 @@
1
- import { ICommand } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
2
17
  export interface IRemoveHyperLinkMutationParams {
3
18
  unitId: string;
4
19
  subUnitId: string;
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
17
+ import type { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
3
18
  export interface IUpdateHyperLinkMutationParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService } from '@univerjs/core';
2
17
  import { RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
3
18
  import { HyperLinkModel } from '../models/hyper-link.model';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
2
17
  import { SheetInterceptorService } from '@univerjs/sheets';
3
18
  import { HyperLinkModel } from '../models/hyper-link.model';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
17
  import { RefRangeService } from '@univerjs/sheets';
3
18
  export declare class SheetsHyperLinkRichTextRefRangeController extends Disposable {
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
2
17
  import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
3
18
  import { HyperLinkModel } from '../models/hyper-link.model';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, IResourceManagerService } from '@univerjs/core';
2
17
  import { HyperLinkModel } from '../models/hyper-link.model';
3
18
  export declare class SheetsHyperLinkResourceController extends Disposable {
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService } from '@univerjs/core';
2
17
  export declare class SheetsHyperLinkController extends Disposable {
3
18
  private readonly _commandService;
@@ -1,6 +1,21 @@
1
- import { IEventBase } from '@univerjs/core/facade';
2
- import { ICellLinkContent, ISheetHyperLink } from '@univerjs/sheets-hyper-link';
3
- import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IEventBase } from '@univerjs/core/facade';
17
+ import type { ICellLinkContent, ISheetHyperLink } from '@univerjs/sheets-hyper-link';
18
+ import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
4
19
  /**
5
20
  * @ignore
6
21
  */
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { FRange } from '@univerjs/sheets/facade';
2
17
  export interface ICellHyperLink {
3
18
  id: string;
@@ -1,4 +1,19 @@
1
- import { Injector } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { Injector } from '@univerjs/core';
2
17
  import { FUniver } from '@univerjs/core/facade';
3
18
  export declare class FSheetLinkUniver extends FUniver {
4
19
  /**
@@ -1,6 +1,23 @@
1
- import { IRange } from '@univerjs/core';
2
- import { ISheetHyperLinkInfo, SheetsHyperLinkParserService } from '@univerjs/sheets-hyper-link';
3
- import { FRange, FWorkbook } from '@univerjs/sheets/facade';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IRange } from '@univerjs/core';
17
+ import type { ISheetHyperLinkInfo } from '@univerjs/sheets-hyper-link';
18
+ import type { FRange } from '@univerjs/sheets/facade';
19
+ import { SheetsHyperLinkParserService } from '@univerjs/sheets-hyper-link';
20
+ import { FWorkbook } from '@univerjs/sheets/facade';
4
21
  /**
5
22
  * @hideconstructor
6
23
  */
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { FWorksheet } from '@univerjs/sheets/facade';
2
17
  /**
3
18
  * @ignore
@@ -1,4 +1,19 @@
1
- import { ICellLinkContent, ISheetHyperLink } from '../types/interfaces/i-hyper-link';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICellLinkContent, ISheetHyperLink } from '../types/interfaces/i-hyper-link';
2
17
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
3
18
  type LinkUpdate = {
4
19
  type: 'add';
@@ -42,7 +57,7 @@ type LinkUpdate = {
42
57
  export declare class HyperLinkModel extends Disposable {
43
58
  private readonly _univerInstanceService;
44
59
  private _linkUpdate$;
45
- linkUpdate$: import('rxjs').Observable<LinkUpdate>;
60
+ linkUpdate$: import("rxjs").Observable<LinkUpdate>;
46
61
  private _linkMap;
47
62
  private _linkPositionMap;
48
63
  constructor(_univerInstanceService: IUniverInstanceService);
@@ -54,7 +69,7 @@ export declare class HyperLinkModel extends Disposable {
54
69
  column: number;
55
70
  }, silent?: boolean): boolean;
56
71
  removeHyperLink(unitId: string, subUnitId: string, id: string): boolean;
57
- getHyperLink(unitId: string, subUnitId: string, id: string): import('@univerjs/core').Nullable<ISheetHyperLink>;
72
+ getHyperLink(unitId: string, subUnitId: string, id: string): import("@univerjs/core").Nullable<ISheetHyperLink>;
58
73
  getHyperLinkByLocation(unitId: string, subUnitId: string, row: number, column: number): ISheetHyperLink | undefined;
59
74
  getHyperLinkByLocationSync(unitId: string, subUnitId: string, row: number, column: number): {
60
75
  display: string;
@@ -1,4 +1,19 @@
1
- import { IUniverSheetsHyperLinkConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IUniverSheetsHyperLinkConfig } from './config/config';
2
17
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  export declare class UniverSheetsHyperLinkPlugin extends Plugin {
4
19
  private readonly _config;
@@ -1,4 +1,20 @@
1
- import { IRange, Nullable, IUniverInstanceService, LocaleService } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IRange, Nullable } from '@univerjs/core';
17
+ import { IUniverInstanceService, LocaleService } from '@univerjs/core';
2
18
  import { IDefinedNamesService } from '@univerjs/engine-formula';
3
19
  import { SheetHyperLinkType } from '../types/enums/hyper-link-type';
4
20
  export interface ISheetUrlParams {
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets/facade"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-hyper-link","@univerjs/sheets/facade","@univerjs/core/facade"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsHyperLinkFacade={},h.UniverCore,h.UniverSheetsHyperLink,h.UniverSheetsFacade,h.UniverCoreFacade))})(this,(function(h,a,d,c,k){"use strict";var g=Object.getOwnPropertyDescriptor,w=(s,e,i,r)=>{for(var n=r>1?void 0:r?g(e,i):e,t=s.length-1,o;t>=0;t--)(o=s[t])&&(n=o(n)||n);return n},y=(s,e)=>(i,r)=>e(i,r,s);let p=class{constructor(s,e){this._workbook=s,this._parserService=e}getRangeUrl(s){return this._parserService.buildHyperLink(this._workbook.getId(),s.getSheetId(),s.getRange()),this}};p=w([y(1,a.Inject(d.SheetsHyperLinkParserService))],p);class l extends c.FWorkbook{createSheetHyperlink(e,i){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,i)}parseSheetHyperlink(e){return this._injector.get(d.SheetsHyperLinkParserService).parseHyperLink(e)}}c.FWorkbook.extend(l);class C extends c.FWorksheet{getUrl(){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}}c.FWorksheet.extend(C);class _ extends c.FRange{setHyperLink(e,i){const r={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:i,id:a.generateRandomId()}};return this._commandService.executeCommand(d.AddHyperLinkCommand.id,r)}getHyperLinks(){var i,r,n;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(n=(r=(i=e.p.body)==null?void 0:i.customRanges)==null?void 0:r.filter(t=>t.rangeType===a.CustomRangeType.HYPERLINK).map(t=>{var o,u,v,m,S;return{id:`${t.rangeId}`,startIndex:t.startIndex,endIndex:t.endIndex,url:(u=(o=t.properties)==null?void 0:o.url)!=null?u:"",label:(S=(m=(v=e.p)==null?void 0:v.body)==null?void 0:m.dataStream.slice(t.startIndex,t.endIndex+1).replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?S:""}}))!=null?n:[]:[]}updateHyperLink(e,i,r){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:i,display:r}};return this._commandService.executeCommand(d.UpdateHyperLinkCommand.id,n)}cancelHyperLink(e){const i={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.syncExecuteCommand(d.CancelHyperLinkCommand.id,i)}getUrl(){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}}c.FRange.extend(_);class f{get BeforeSheetLinkAdd(){return"BeforeSheetLinkAdd"}get BeforeSheetLinkCancel(){return"BeforeSheetLinkCancel"}get BeforeSheetLinkUpdate(){return"BeforeSheetLinkUpdate"}}k.FEventName.extend(f);class L extends k.FUniver{_initialize(e){const i=e.get(a.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.AddHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.link.row,col:t.link.column,link:t.link};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,o),o.cancel)throw new a.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.UpdateHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.row,column:t.column,id:t.id,payload:t.payload};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,o),o.cancel)throw new a.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.CancelHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.row,column:t.column,id:t.id};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,o),o.cancel)throw new a.CanceledError})))}}k.FUniver.extend(L),h.FWorkbookHyperLinkMixin=l,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-hyper-link`),require(`@univerjs/sheets/facade`),require(`@univerjs/core/facade`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-hyper-link`,`@univerjs/sheets/facade`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLinkFacade={},e.UniverCore,e.UniverSheetsHyperLink,e.UniverSheetsFacade,e.UniverCoreFacade))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,t){return function(n,r){t(n,r,e)}}function o(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let s=class{constructor(e,t){this._workbook=e,this._parserService=t}getRangeUrl(e){return this._parserService.buildHyperLink(this._workbook.getId(),e.getSheetId(),e.getRange()),this}};s=o([a(1,(0,t.Inject)(n.SheetsHyperLinkParserService))],s);var c=class extends r.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(n.SheetsHyperLinkParserService).parseHyperLink(e)}};r.FWorkbook.extend(c);var l=class extends r.FWorksheet{getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}};r.FWorksheet.extend(l);var u=class extends r.FRange{setHyperLink(e,r){let i={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:r,id:(0,t.generateRandomId)()}};return this._commandService.executeCommand(n.AddHyperLinkCommand.id,i)}getHyperLinks(){var e,n;let r=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return r!=null&&r.p?(e=(n=r.p.body)==null||(n=n.customRanges)==null?void 0:n.filter(e=>e.rangeType===t.CustomRangeType.HYPERLINK).map(e=>{var n,i,a,o;return{id:`${e.rangeId}`,startIndex:e.startIndex,endIndex:e.endIndex,url:(n=(i=e.properties)==null?void 0:i.url)==null?``:n,label:(a=(o=r.p)==null||(o=o.body)==null?void 0:o.dataStream.slice(e.startIndex,e.endIndex+1).replaceAll(t.DataStreamTreeTokenType.CUSTOM_RANGE_START,``).replaceAll(t.DataStreamTreeTokenType.CUSTOM_RANGE_END,``))==null?``:a}}))==null?[]:e:[]}updateHyperLink(e,t,r){let i={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:r}};return this._commandService.executeCommand(n.UpdateHyperLinkCommand.id,i)}cancelHyperLink(e){let t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.syncExecuteCommand(n.CancelHyperLinkCommand.id,t)}getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}};r.FRange.extend(u);var d=class{get BeforeSheetLinkAdd(){return`BeforeSheetLinkAdd`}get BeforeSheetLinkCancel(){return`BeforeSheetLinkCancel`}get BeforeSheetLinkUpdate(){return`BeforeSheetLinkUpdate`}};i.FEventName.extend(d);var f=class extends i.FUniver{_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>r.beforeCommandExecuted(e=>{if(e.id!==n.AddHyperLinkCommand.id)return;let r=this.getCommandSheetTarget(e);if(!r)return;let i=e.params,a={workbook:r.workbook,worksheet:r.worksheet,row:i.link.row,col:i.link.column,link:i.link};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,a),a.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id!==n.UpdateHyperLinkCommand.id)return;let r=this.getCommandSheetTarget(e);if(!r)return;let i=e.params,a={workbook:r.workbook,worksheet:r.worksheet,row:i.row,column:i.column,id:i.id,payload:i.payload};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,a),a.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>r.beforeCommandExecuted(e=>{if(e.id!==n.CancelHyperLinkCommand.id)return;let r=this.getCommandSheetTarget(e);if(!r)return;let i=e.params,a={workbook:r.workbook,worksheet:r.worksheet,row:i.row,column:i.column,id:i.id};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,a),a.cancel)throw new t.CanceledError})))}};i.FUniver.extend(f),e.FWorkbookHyperLinkMixin=c});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(p,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(p=typeof globalThis<"u"?globalThis:p||self,a(p.UniverSheetsHyperLink={},p.UniverCore,p.UniverDocs,p.UniverSheets,p.rxjs,p.UniverEngineFormula))})(this,(function(p,a,w,m,Ie,C){"use strict";var Ye=Object.defineProperty;var qe=(p,a,w)=>a in p?Ye(p,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):p[a]=w;var L=(p,a,w)=>qe(p,typeof a!="symbol"?a+"":a,w);var Re=Object.getOwnPropertyDescriptor,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ce=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Ie.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,a.IUniverInstanceService)],p.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},H={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},ae={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=g.getCell(_,v),I=g.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let T;if(h?T=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):T=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!T)return!1;const j=a.TextX.apply(M,T.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,g,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},se={id:m.SetRangeValuesMutation.id,params:V},Z=m.SetRangeValuesUndoMutationFactory(r,V),re={id:m.SetRangeValuesMutation.id,params:Z},A=[se],P=[re],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:H.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,g,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},oe={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const T=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:T});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:H.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(g=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ye,_e,ve;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(_e=(ye=R.body)==null?void 0:ye.customRanges)==null?void 0:_e.find(Se=>`${Se.rangeId}`===g);if(!M)return!1;const T=a.generateRandomId(),O=(ve=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:ve[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:T,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},se=o.onWriteCell(f,y,l,u,V),Z={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:se}}}},re=m.SetRangeValuesUndoMutationFactory(r,Z.params),A={id:m.SetRangeValuesMutation.id,params:re},P=[Z],D=[A],ee=s.getHyperLinkByLocation(h,_,l,u);return ee&&(P.push({id:H.id,params:{unitId:h,subUnitId:_,id:ee.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:ee}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},ue={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=w.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(_=(h=(y=g==null?void 0:g.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},pe={name:"@univerjs/sheets-hyper-link",version:"0.17.0"},ke="sheets-hyper-link.config",ge={},he="SHEET_HYPER_LINK_PLUGIN",$="err";var Le=Object.getOwnPropertyDescriptor,Ue=(r,t,e,n)=>{for(var i=n>1?void 0:n?Le(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:H.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(g)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Ue([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(p.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var we=Object.getOwnPropertyDescriptor,Ee=(r,t,e,n)=>{for(var i=n>1?void 0:n?we(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:H.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Ee([te(0,a.Inject(m.SheetInterceptorService)),te(1,a.IUniverInstanceService),te(2,a.Inject(p.HyperLinkModel))],Y);var He=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,o);g&&g.p&&this._registerRange(n,i,s,o,g.p)}}}))}};q=Te([ne(0,a.ICommandService),ne(1,a.IUniverInstanceService),ne(2,a.Inject(m.RefRangeService))],q);var be=Object.getOwnPropertyDescriptor,Pe=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:H.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService,r.params);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:H.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=a.Tools.normalizeUrl(r.v),c=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getSheetBySheetId(i);if(!l)return e(r);const u=l.getBlankCellDocumentModel(r,s,o);if(!u.documentModel)return e(r);const g=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:d}}]},doc:u.documentModel});if(!g)return e(r);const f=u.documentModel.getBody();return a.TextX.apply(f,g.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:f,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=Pe([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(p.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var De=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},me=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:he,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=Oe([me(0,a.IResourceManagerService),me(1,a.Inject(p.HyperLinkModel))],X);var Ne=Object.getOwnPropertyDescriptor,Ve=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},$e=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ae,le,de,ue,ce,oe,E,x,H,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ve([$e(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),je=Object.getOwnPropertyDescriptor,Ae=(r,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return a.isValidRange(g,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(o.getUnitId(),i);return g?{type:U.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=o.getSheetBySheetId(e);return g?{type:U.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=Ae([ie(0,a.IUniverInstanceService),ie(1,a.Inject(a.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var xe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(r,t,e)=>t in r?xe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ze=(r,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},fe=(r,t)=>(e,n)=>t(e,n,r),Q=(r,t,e)=>Be(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ge,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ge,this._config);this._configService.setConfig(ke,i)}onStarting(){a.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},Q(p.UniverSheetsHyperLinkPlugin,"pluginName",he),Q(p.UniverSheetsHyperLinkPlugin,"packageName",pe.name),Q(p.UniverSheetsHyperLinkPlugin,"version",pe.version),Q(p.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=ze([a.DependentOn(m.UniverSheetsPlugin),fe(1,a.Inject(a.Injector)),fe(2,a.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ae,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=oe,p.CancelHyperLinkCommand=de,p.CancelRichHyperLinkCommand=ce,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=H,p.SheetHyperLinkType=U,p.UpdateHyperLinkCommand=le,p.UpdateHyperLinkMutation=x,p.UpdateHyperLinkRefMutation=W,p.UpdateRichHyperLinkCommand=ue,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/docs`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLink={},e.UniverCore,e.UniverDocs,e.UniverSheets,e.rxjs,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e){super(),this._univerInstanceService=e,l(this,`_linkUpdate$`,new i.Subject),l(this,`linkUpdate$`,this._linkUpdate$.asObservable()),l(this,`_linkMap`,new Map),l(this,`_linkPositionMap`,new Map),this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let i=r.get(n);i||(i=new t.ObjectMatrix,r.set(n,i));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let o=a.get(n);return o||(o=new Map,a.set(n,o)),{matrix:i,positionMap:o}}addHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t);return r.setValue(n.row,n.column,n),i.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`}),!0}updateHyperLink(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return c?(Object.assign(c,r),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:{display:c.display,payload:c.payload},id:n,type:`update`,silent:i}),!0):!0}updateHyperLinkRef(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||c.id!==n?c=s.link:a.realDeleteValue(s.row,s.column),Object.assign(c,r),o.set(n,{...r,link:c}),a.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:r,id:n,type:`updateRef`,silent:i}),!0}removeHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(!a)return!1;i.delete(n);let o=r.getValue(a.row,a.column);return o&&o.id===n&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:a.link,type:`remove`}),!0}getHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,t,n,r){let{matrix:i}=this._ensureMap(e,t);return i.getValue(n,r)}getHyperLinkByLocationSync(e,n,r,i){var a,o,s,c;let{matrix:l}=this._ensureMap(e,n),u=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET),d=u==null||(a=u.getSheetBySheetId(n))==null?void 0:a.getCellRaw(r,i),f=((o=(s=d==null?void 0:d.v)==null?d==null||(c=d.p)==null||(c=c.body)==null?void 0:c.dataStream.slice(0,-2):s)==null?``:o).toString(),p=l.getValue(r,i);if(p)return{...p,display:f}}getSubUnit(e,t){let{matrix:n}=this._ensureMap(e,t),r=[];return n.forValue((e,t,n)=>{n&&r.push(n)}),r}getUnit(e){let t=this._linkMap.get(e);return t?Array.from(t.keys()).map(t=>({unitId:e,subUnitId:t,links:this.getSubUnit(e,t)})):[]}deleteUnit(e){let t=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:`unload`,unitId:e,unitLinks:t})}getAll(){return Array.from(this._linkMap.keys()).map(e=>this.getUnit(e))}};f=d([u(0,t.IUniverInstanceService)],f);let p={type:t.CommandType.MUTATION,id:`sheets.mutation.add-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,link:a}=t;return n.addHyperLink(r,i,a)}},m={type:t.CommandType.MUTATION,id:`sheets.mutation.remove-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a}=t;return n.removeHyperLink(r,i,a)}},h={type:t.CommandType.COMMAND,id:`sheets.command.add-hyper-link`,async handler(e,n){if(!n)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(t.IUniverInstanceService),s=e.get(f),c=e.get(r.SheetInterceptorService),l=(0,r.getSheetCommandTarget)(o,n);if(!l)return!1;let{unitId:u,subUnitId:d,workbook:h,worksheet:g}=l,{link:_}=n,{payload:v,display:y,row:b,column:x,id:S}=_,C=g.getCell(b,x),w=g.getBlankCellDocumentModel(C,b,x),T=w.documentModel.getSnapshot(),E=t.Tools.deepClone(T.body);if(!E)return!1;let D;if(D=y?t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:E.dataStream.length-2,collapsed:E.dataStream.length-2==0},body:{dataStream:`${y}`,customRanges:[{startIndex:0,endIndex:y.length-1,rangeType:t.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:v}}]},doc:w.documentModel}):t.BuildTextUtils.customRange.add({body:E,ranges:[{startOffset:0,endOffset:E.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:v,refId:S}}),!D)return!1;let O=t.TextX.apply(E,D.serialize()),k={p:{...T,body:O},t:t.CellValueType.STRING},A=c.onWriteCell(h,g,b,x,k),j={unitId:u,subUnitId:d,cellValue:{[_.row]:{[_.column]:A}}},M={id:r.SetRangeValuesMutation.id,params:j},N=(0,r.SetRangeValuesUndoMutationFactory)(e,j),P={id:r.SetRangeValuesMutation.id,params:N},F=[M],I=[P],L=s.getHyperLinkByLocation(u,d,b,x);return L&&(F.push({id:m.id,params:{unitId:u,subUnitId:d,id:L.id}}),I.push({id:p.id,params:{unitId:u,subUnitId:d,link:L}})),await(0,t.sequenceExecute)(F,i)?await c.onValidateCell(h,g,b,x)===!1?((0,t.sequenceExecute)(I,i),!1):(a.pushUndoRedo({redoMutations:F,undoMutations:I,unitID:u}),!0):!1}},g={id:`sheets.command.add-rich-hyper-link`,type:t.CommandType.COMMAND,handler:async(e,r)=>{if(!r)return!1;let{documentId:i,link:a}=r,o=e.get(t.ICommandService),s=(0,t.generateRandomId)(),{payload:c}=a,l=(0,n.addCustomRangeBySelectionFactory)(e,{unitId:i,rangeId:s,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c,refId:s}});return l?o.syncExecuteCommand(l.id,l.params):!1}},_={type:t.CommandType.COMMAND,id:`sheets.command.cancel-hyper-link`,handler(e,n){var i;if(!n)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),c=e.get(f),l=(0,r.getSheetCommandTarget)(s,n);if(!l)return!1;let{row:u,column:d,id:h}=n,{unitId:g,subUnitId:_,worksheet:v}=l,y=v.getCell(u,d);if(!y)return!1;let b=v.getCellDocumentModelWithFormula(y,u,d);if(!(b!=null&&b.documentModel))return!1;let x=t.Tools.deepClone(b.documentModel.getSnapshot()),S=(i=x.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===h);if(!S)return!1;let C=t.BuildTextUtils.customRange.delete({documentDataModel:b.documentModel,rangeId:S.rangeId});if(!C)return!1;let w=t.TextX.apply(x.body,C.serialize()),T=[],E=[],D={unitId:g,subUnitId:_,cellValue:{[u]:{[d]:{p:{...x,body:w},t:t.CellValueType.STRING}}}};T.push({id:r.SetRangeValuesMutation.id,params:D});let O=(0,r.SetRangeValuesUndoMutationFactory)(e,D);E.push({id:r.SetRangeValuesMutation.id,params:O});let k=c.getHyperLinkByLocation(g,_,u,d);return k&&(T.push({id:m.id,params:{unitId:g,subUnitId:_,id:h}}),E.push({id:p.id,params:{unitId:g,subUnitId:_,link:{...k}}})),(0,t.sequenceExecute)(T,a).result?(o.pushUndoRedo({redoMutations:T,undoMutations:E,unitID:g}),!0):!1}},v={type:t.CommandType.COMMAND,id:`sheets.command.cancel-rich-hyper-link`,handler(e,r){var i;if(!r)return!1;let{id:a,documentId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUniverInstanceService).getUnit(o,t.UniverInstanceType.UNIVER_DOC),l=c==null||(i=c.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===a),u=null;l&&l.endIndex===c.getBody().dataStream.length-3&&(u={dataStream:` `});let d=(0,n.deleteCustomRangeFactory)(e,{unitId:o,rangeId:a,insert:u});return d?s.syncExecuteCommand(d.id,d.params):!1}},y={type:t.CommandType.COMMAND,id:`sheets.command.update-hyper-link`,async handler(e,i){var a,o;if(!i)return!1;let s=e.get(t.ICommandService),c=e.get(t.IUndoRedoService),l=e.get(t.IUniverInstanceService),u=e.get(f),d=e.get(r.SheetInterceptorService),h=(0,r.getSheetCommandTarget)(l,{unitId:i.unitId,subUnitId:i.subUnitId});if(!h)return!1;let{payload:g,row:_,column:v,id:y}=i,{workbook:b,worksheet:x,unitId:S,subUnitId:C}=h,{payload:w,display:T=``}=g,E=x.getCell(_,v);if(!E)return!1;let D=x.getCellDocumentModelWithFormula(E,_,v);if(!(D!=null&&D.documentModel))return!1;let O=D.documentModel.getSnapshot(),k=(a=O.body)==null||(a=a.customRanges)==null?void 0:a.find(e=>`${e.rangeId}`===y);if(!k)return!1;let A=(0,t.generateRandomId)(),j=(o=(0,t.getBodySlice)(D.documentModel.getBody(),k.startIndex,k.endIndex+1).textRuns)==null?void 0:o[0];j&&(j.ed=T.length+1);let M=(0,n.replaceSelectionFactory)(e,{unitId:S,body:{dataStream:`${T}`,customRanges:[{rangeId:A,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:T.length-1,properties:{url:w}}],textRuns:j?[j]:void 0},selection:{startOffset:k.startIndex,endOffset:k.endIndex+1,collapsed:!1},doc:D.documentModel});if(!M)return!1;let N=t.TextX.apply(t.Tools.deepClone(O.body),M.textX.serialize()),P={p:{...O,body:N},t:t.CellValueType.STRING},F=d.onWriteCell(b,x,_,v,P),I={id:r.SetRangeValuesMutation.id,params:{unitId:S,subUnitId:C,cellValue:{[_]:{[v]:F}}}},L=(0,r.SetRangeValuesUndoMutationFactory)(e,I.params),R={id:r.SetRangeValuesMutation.id,params:L},z=[I],B=[R],V=u.getHyperLinkByLocation(S,C,_,v);return V&&(z.push({id:m.id,params:{unitId:S,subUnitId:C,id:V.id}}),B.push({id:p.id,params:{unitId:S,subUnitId:C,link:V}})),(0,t.sequenceExecute)(z,s)?await d.onValidateCell(b,x,_,v)===!1?((0,t.sequenceExecute)(B,s),!1):(c.pushUndoRedo({redoMutations:z,undoMutations:B,unitID:S}),!0):!1}},b={type:t.CommandType.COMMAND,id:`sheets.command.update-rich-hyper-link`,handler:(e,r)=>{var i,a,o;if(!r)return!1;let{documentId:s,payload:c,id:l}=r,u=e.get(t.IUniverInstanceService),d=e.get(t.ICommandService),f=u.getUnit(s,t.UniverInstanceType.UNIVER_DOC);if(!f)return!1;let p=(i=f.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===l);if(!p)return!1;let m=(a=r.payload.display)==null?``:a,h=(0,t.generateRandomId)(),g=(o=(0,t.getBodySlice)(f.getBody(),p.startIndex,p.endIndex+1).textRuns)==null?void 0:o[0];g&&(g.ed=m.length+1);let _=(0,n.replaceSelectionFactory)(e,{unitId:s,body:{dataStream:`${m}`,customRanges:[{rangeId:h,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:m.length-1,properties:{url:c.payload}}],textRuns:g?[g]:void 0},selection:{startOffset:p.startIndex,endOffset:p.endIndex+1,collapsed:!1},doc:f});return _?d.syncExecuteCommand(_.id,_.params):!1}},x={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,payload:a,id:o}=t;return n.updateHyperLink(r,i,o,a,!1)}},S={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link-ref`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a,row:o,column:s,silent:c}=t;return n.updateHyperLinkRef(r,i,a,{row:o,column:s},c)}},C={type:t.CommandType.MUTATION,id:`sheets.mutation.update-rich-hyper-link`,handler(e,n){var i;if(!n)return!1;let{unitId:a,subUnitId:o,row:s,col:c,id:l,url:u}=n,d=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:a,subUnitId:o});if(!d)return!1;let{worksheet:f}=d,p=f.getCellRaw(s,c),m=p==null||(i=p.p)==null||(i=i.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeType===t.CustomRangeType.HYPERLINK&&e.rangeId===l);return m&&(m.properties.url=u),!0}};var w=`@univerjs/sheets-hyper-link`,T=`0.18.0`;let E=`sheets-hyper-link.config`;Symbol(E);let D={},O=`SHEET_HYPER_LINK_PLUGIN`,k=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._commandService=r,l(this,`_disposableMap`,new Map),l(this,`_watchDisposableMap`,new Map),l(this,`_rangeDisableMap`,new Map),l(this,`_rangeWatcherMap`,new Map),l(this,`_handlePositionChange`,(e,t,n,r,i)=>{let a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:m.id,params:{unitId:e,subUnitId:t,id:n.id}}],undos:[{id:p.id,params:{unitId:e,subUnitId:t,link:n}}]}}),this._initData(),this._initRefRange()}_registerPosition(e,t,n){let i=n.id,a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(i,this._refRangeService.registerRefRange(a,i=>{let o=(0,r.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,t,n,s,!1)},e,t))}_watchPosition(e,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(e,n,a,(i,a)=>{let{redos:o}=this._handlePositionChange(e,n,r,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){let t=this._disposableMap.get(e);t==null||t.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){let t=this._watchDisposableMap.get(e);t==null||t.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,n,i,o=!1){if(i.startsWith(`#`)){var s,c,l;let u=new URLSearchParams(i.slice(1)),d={gid:(s=u.get(`gid`))==null?``:s,range:(c=u.get(`range`))==null?``:c,rangeid:(l=u.get(`rangeid`))==null?``:l};if(d.range&&d.gid){let s=d.gid,c=(0,a.deserializeRangeWithSheet)(d.range).range;(0,t.isValidRange)(c)&&d.range!==`err`&&(this._rangeDisableMap.set(n,this._refRangeService.registerRefRange(c,t=>{let o=(0,r.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests)(c,t,{selectionManagerService:this._selectionManagerService});return o&&(0,a.serializeRange)(o)===(0,a.serializeRange)(c)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:`#gid=${s}&range=${o?(0,a.serializeRange)(o):`err`}`}}}],undos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:i}}}]}},e,s)),o||this._rangeWatcherMap.set(n,this._refRangeService.watchRange(e,s,c,(t,r)=>{this._hyperLinkModel.updateHyperLink(e,s,n,{payload:`#gid=${s}&range=${r?(0,a.serializeRange)(r):`err`}`},!0)},!0)))}}}_unregisterRange(e){let t=this._rangeDisableMap.get(e);t==null||t.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){let t=this._rangeWatcherMap.get(e);t==null||t.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,links:r}=e;r.forEach(e=>{this._registerPosition(t,n,e),this._watchPosition(t,n,e),this._registerRange(t,e.id,e.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(e=>{switch(e.type){case`add`:this._registerPosition(e.unitId,e.subUnitId,e.payload),this._watchPosition(e.unitId,e.subUnitId,e.payload),this._registerRange(e.unitId,e.payload.id,e.payload.payload);break;case`remove`:this._unregisterPosition(e.payload.id),this._unwatchPosition(e.payload.id),this._unregisterRange(e.payload.id),this._unwatchRange(e.payload.id);break;case`updateRef`:{let{unitId:t,subUnitId:n,id:r,silent:i}=e,a=this._hyperLinkModel.getHyperLink(t,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(t,n,a),i||(this._unwatchPosition(r),this._watchPosition(t,n,a));break}case`unload`:{let{unitLinks:t}=e;t.forEach(e=>{let{links:t}=e;t.forEach(e=>{this._unregisterPosition(e.id),this._unwatchPosition(e.id),this._unregisterRange(e.id),this._unwatchRange(e.id)})});break}case`update`:e.silent||this._unwatchRange(e.id),this._unregisterRange(e.id),this._registerRange(e.unitId,e.id,e.payload.payload,e.silent);break}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};k=d([u(0,(0,t.Inject)(r.RefRangeService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.ICommandService)],k);let A=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._hyperLinkModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.RemoveSheetCommand.id){var n;let r=e.params,i=r.unitId?this._univerInstanceService.getUnit(r.unitId):this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!i)return{redos:[],undos:[]};let a=i.getUnitId(),o=r.subUnitId||((n=i.getActiveSheet())==null?void 0:n.getSheetId());if(!o)return{redos:[],undos:[]};let s=this._hyperLinkModel.getSubUnit(a,o);return{redos:s.map(e=>({id:m.id,params:{unitId:a,subUnitId:o,id:e.id}})),undos:s.map(e=>({id:p.id,params:{unitId:a,subUnitId:o,link:e}}))}}return{redos:[],undos:[]}}}))}};A=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],A);let j=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._refRangeService=n,l(this,`_refRangeMap`,new Map),this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(e,n){let r=this._refRangeMap.get(e);r||(r=new Map,this._refRangeMap.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}_isLegalRangeUrl(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)return null;if(n&&n.startsWith(`#`)){var i,o,s;let e=new URLSearchParams(n.slice(1)),c={gid:(i=e.get(`gid`))==null?``:i,range:(o=e.get(`range`))==null?``:o,rangeid:(s=e.get(`rangeid`))==null?``:s};if(c.range&&c.gid){let e=c.gid,n=r.getSheetBySheetId(e);if(!n)return null;let i=(0,a.deserializeRangeWithSheet)(c.range).range;if((0,t.isValidRange)(i,n)&&c.range!==`err`)return{range:i,worksheet:n}}}return null}_registerRange(e,n,i,o,s){var c;let l=this._enusreMap(e,n);if(!((c=s.body)==null||(c=c.customRanges)==null)&&c.some(n=>{var r;return n.rangeType===t.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(e,(r=n.properties)==null?void 0:r.url)})){var u;let c=new t.DisposableCollection,d=!1;(u=s.body)==null||(u=u.customRanges)==null||u.forEach(s=>{if(s.rangeType===t.CustomRangeType.HYPERLINK){var l;let u=(l=s.properties)==null?void 0:l.url,f=this._isLegalRangeUrl(e,u);if(f){let{range:l,worksheet:p}=f;d=!0,c.add(this._refRangeService.registerRefRange(l,c=>{let d=(0,r.handleDefaultRangeChangeWithEffectRefCommands)(l,c);return d&&t.Rectangle.equals(d,l)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:`#gid=${n}&range=${d?(0,a.serializeRange)(d):`err`}`}}],undos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:u}}],redos:[]}},p.getUnitId(),p.getSheetId()))}}}),d&&l.setValue(i,o,c)}}_initWorkbookLoad(){let e=e=>{let t=e.getUnitId();e.getSheets().forEach(e=>{let n=e.getSheetId(),r=this._enusreMap(t,n);e.getCellMatrix().forValue((e,i,a)=>{let o=r.getValue(e,i);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,i,a.p)})})};this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(t=>{e(t)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(n=>{n.type===t.UniverInstanceType.UNIVER_SHEET&&e(n)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{if(e.type===t.UniverInstanceType.UNIVER_SHEET){let t=e,n=t.getUnitId();t.getSheets().forEach(e=>{let t=e.getSheetId();this._enusreMap(n,t).forValue((e,t,n)=>{n&&n.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.SetRangeValuesMutation.id){let{unitId:n,subUnitId:r,cellValue:i}=e.params,a=this._enusreMap(n,r);i&&new t.ObjectMatrix(i).forValue((e,t,i)=>{let o=a.getValue(e,t);o&&o.dispose(),i&&i.p&&this._registerRange(n,r,e,t,i.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===C.id){let{unitId:t,subUnitId:n,row:i,col:a}=e.params,o=(0,r.getSheetCommandTarget)(this._univerInstanceService,{unitId:t,subUnitId:n}),s=this._enusreMap(t,n).getValue(i,a);if(s&&s.dispose(),o){let{worksheet:e}=o,r=e.getCellRaw(i,a);r&&r.p&&this._registerRange(t,n,i,a,r.p)}}}))}};j=d([u(0,t.ICommandService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(r.RefRangeService))],j);let M=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._univerInstanceService=r,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.SetRangeValuesCommand.id){let n=e.params,{unitId:r,subUnitId:i}=n,a=[],o=[];return n.cellValue&&new t.ObjectMatrix(n.cellValue).forValue((e,t)=>{let n=this._hyperLinkModel.getHyperLinkByLocation(r,i,e,t);n&&(a.push({id:m.id,params:{unitId:r,subUnitId:i,id:n.id}}),o.push({id:p.id,params:{unitId:r,subUnitId:i,link:n}}))}),{undos:o,redos:a}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.ClearSelectionContentCommand.id||e.id===r.ClearSelectionAllCommand.id||e.id===r.ClearSelectionFormatCommand.id){let n=[],i=[],a=this._selectionManagerService.getCurrentLastSelection(),o=(0,r.getSheetCommandTarget)(this._univerInstanceService,e.params);if(a&&o){let{unitId:e,subUnitId:r}=o;t.Range.foreach(a.range,(t,a)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(e,r,t,a);o&&(n.push({id:m.id,params:{unitId:e,subUnitId:r,id:o.id}}),i.push({id:p.id,params:{unitId:e,subUnitId:r,link:o}}))})}return{redos:n,undos:i}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.AFTER_CELL_EDIT,{handler:(e,n,r)=>{if(!e||e.p)return r(e);if(typeof e.v==`string`&&t.Tools.isLegalUrl(e.v)&&e.v[e.v.length-1]!==` `){let{unitId:i,subUnitId:a,row:o,col:s}=n,c=t.Tools.normalizeUrl(e.v),l=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(a);if(!u)return r(e);let d=u.getBlankCellDocumentModel(e,o,s);if(!d.documentModel)return r(e);let f=t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:e.v.length,collapsed:!1},body:{dataStream:`${e.v}`,customRanges:[{startIndex:0,endIndex:e.v.length-1,rangeId:(0,t.generateRandomId)(),rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c}}]},doc:d.documentModel});if(!f)return r(e);let p=d.documentModel.getBody();return t.TextX.apply(p,f.serialize()),r({...e,p:{id:t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return r(e)}}))}};M=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.IUniverInstanceService)],M);let N=class extends t.Disposable{constructor(e,t){super(),this._resourceManagerService=e,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._hyperLinkModel.getUnit(e),n={};return t?(t.forEach(e=>{n[e.subUnitId]=e.links.map(({display:e,...t})=>t)}),JSON.stringify(n)):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:O,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._hyperLinkModel.addHyperLink(e,n,t)})})}}))}};N=d([u(0,t.IResourceManagerService),u(1,(0,t.Inject)(f))],N);let P=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._registerCommands()}_registerCommands(){[h,y,_,b,v,g,p,x,m,S,C].forEach(e=>{this._commandService.registerCommand(e)})}};P=d([u(0,t.ICommandService)],P);let F=function(e){return e.SHEET=`gid`,e.RANGE=`range`,e.DEFINE_NAME=`rangeid`,e.INVALID=`invalid`,e.URL=`url`,e}({}),I=class{constructor(e,t,n){this._univerInstanceService=e,this._localeService=t,this._definedNamesService=n}buildHyperLink(e,t,n){return`#${F.SHEET}=${t}${n?`&${typeof n==`string`?F.DEFINE_NAME:F.RANGE}=${typeof n==`string`?n:(0,a.serializeRange)(n)}`:``}`}parseHyperLink(e){if(e.startsWith(`#`)){var t,n,r,i;let a=new URLSearchParams(e.slice(1)),o={gid:(t=a.get(`gid`))==null?``:t,range:(n=a.get(`range`))==null?``:n,rangeid:(r=a.get(`rangeid`))==null?``:r,unitid:(i=a.get(`unitid`))==null?``:i},s=this._getURLName(o);return{type:s.type,name:s.name,url:e,searchObj:o}}else return{type:F.URL,name:e,url:e,searchObj:null}}_getURLName(e){var n;let{gid:r,range:i,rangeid:o,unitid:s}=e,c=s?this._univerInstanceService.getUnit(s,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),l={type:F.INVALID,name:this._localeService.t(`hyperLink.message.refError`)};if(!c)return l;let u=r?c.getSheetBySheetId(r):c.getActiveSheet(),d=(n=u==null?void 0:u.getName())==null?``:n;if(i){if(!u)return l;let e=(0,a.deserializeRangeWithSheet)(i).range;return(0,t.isValidRange)(e,u)&&i!==`err`?{type:F.RANGE,name:(0,a.serializeRangeWithSheet)(d,e)}:l}if(o){let e=this._definedNamesService.getValueById(c.getUnitId(),o);return e?{type:F.DEFINE_NAME,name:e.formulaOrRefString}:l}if(r){let e=c.getSheetBySheetId(r);return e?{type:F.SHEET,name:e.getName()}:l}return l}};I=d([u(0,t.IUniverInstanceService),u(1,(0,t.Inject)(t.LocaleService)),u(2,a.IDefinedNamesService)],I);let L=class extends t.Plugin{constructor(e=D,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},D,this._config);this._configService.setConfig(E,i)}onStarting(){(0,t.registerDependencies)(this._injector,[[f],[I],[N],[P],[k],[M],[A],[j]]),(0,t.touchDependencies)(this._injector,[[k],[N],[P],[M],[A],[j]])}};l(L,`pluginName`,O),l(L,`packageName`,w),l(L,`version`,T),l(L,`type`,t.UniverInstanceType.UNIVER_SHEET),L=d([(0,t.DependentOn)(r.UniverSheetsPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,t.IConfigService)],L),e.AddHyperLinkCommand=h,e.AddHyperLinkMutation=p,e.AddRichHyperLinkCommand=g,e.CancelHyperLinkCommand=_,e.CancelRichHyperLinkCommand=v,e.ERROR_RANGE=`err`,Object.defineProperty(e,`HyperLinkModel`,{enumerable:!0,get:function(){return f}}),e.RemoveHyperLinkMutation=m,e.SheetHyperLinkType=F,Object.defineProperty(e,`SheetsHyperLinkParserService`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(e,`UniverSheetsHyperLinkPlugin`,{enumerable:!0,get:function(){return L}}),e.UpdateHyperLinkCommand=y,e.UpdateHyperLinkMutation=x,e.UpdateHyperLinkRefMutation=S,e.UpdateRichHyperLinkCommand=b});