@univerjs/docs-hyper-link-ui 1.0.0-alpha.0 → 1.0.0-alpha.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/lib/cjs/index.js +9 -7
- package/lib/es/index.js +9 -7
- package/lib/index.js +9 -7
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
package/lib/cjs/index.js
CHANGED
|
@@ -13,7 +13,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
13
13
|
|
|
14
14
|
//#region package.json
|
|
15
15
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
16
|
-
var version = "1.0.0-alpha.
|
|
16
|
+
var version = "1.0.0-alpha.2";
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/config/config.ts
|
|
@@ -48,7 +48,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
48
48
|
id: "docs.command.update-hyper-link",
|
|
49
49
|
type: _univerjs_core.CommandType.COMMAND,
|
|
50
50
|
handler(accessor, params) {
|
|
51
|
-
var
|
|
51
|
+
var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
|
|
52
52
|
if (!params) return false;
|
|
53
53
|
const { unitId, payload, segmentId, linkId } = params;
|
|
54
54
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
@@ -56,7 +56,9 @@ const UpdateDocHyperLinkCommand = {
|
|
|
56
56
|
const currentSelection = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
|
|
57
57
|
const doc = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
58
58
|
if (!currentSelection || !doc) return false;
|
|
59
|
-
const
|
|
59
|
+
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
60
|
+
if (!oldBody) return false;
|
|
61
|
+
const textRun = (_getBodySlice$textRun = (0, _univerjs_core.getBodySlice)(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
|
|
60
62
|
if (textRun) textRun.ed = params.label.length + 1;
|
|
61
63
|
const replaceSelection = (0, _univerjs_docs.replaceSelectionFactory)(accessor, {
|
|
62
64
|
unitId,
|
|
@@ -145,11 +147,11 @@ const ClickDocHyperLinkOperation = {
|
|
|
145
147
|
type: _univerjs_core.CommandType.OPERATION,
|
|
146
148
|
id: "doc.operation.click-hyper-link",
|
|
147
149
|
handler(accessor, params) {
|
|
148
|
-
var _body$customRanges;
|
|
150
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
149
151
|
if (!params) return false;
|
|
150
152
|
const { unitId, linkId, segmentId } = params;
|
|
151
153
|
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
152
|
-
const body = doc === null || doc === void 0
|
|
154
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
153
155
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
|
|
154
156
|
if (!(0, _univerjs_core.isSafeUrl)(link)) return false;
|
|
155
157
|
window.open(link, "_blank", "noopener noreferrer");
|
|
@@ -160,7 +162,7 @@ const ClickDocHyperLinkOperation = {
|
|
|
160
162
|
//#endregion
|
|
161
163
|
//#region src/views/DocLinkPopup.tsx
|
|
162
164
|
const DocLinkPopup = () => {
|
|
163
|
-
var _body$customRanges, _link$properties;
|
|
165
|
+
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
|
|
164
166
|
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
165
167
|
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
166
168
|
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
@@ -170,7 +172,7 @@ const DocLinkPopup = () => {
|
|
|
170
172
|
if (!currentPopup) return null;
|
|
171
173
|
const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
|
|
172
174
|
const doc = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
173
|
-
const body = doc === null || doc === void 0
|
|
175
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
174
176
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
|
|
175
177
|
if (!link) return null;
|
|
176
178
|
const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
|
package/lib/es/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
|
|
13
13
|
//#region package.json
|
|
14
14
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
15
|
-
var version = "1.0.0-alpha.
|
|
15
|
+
var version = "1.0.0-alpha.2";
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/config/config.ts
|
|
@@ -47,7 +47,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
47
47
|
id: "docs.command.update-hyper-link",
|
|
48
48
|
type: CommandType.COMMAND,
|
|
49
49
|
handler(accessor, params) {
|
|
50
|
-
var
|
|
50
|
+
var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
|
|
51
51
|
if (!params) return false;
|
|
52
52
|
const { unitId, payload, segmentId, linkId } = params;
|
|
53
53
|
const commandService = accessor.get(ICommandService);
|
|
@@ -55,7 +55,9 @@ const UpdateDocHyperLinkCommand = {
|
|
|
55
55
|
const currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange();
|
|
56
56
|
const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
57
57
|
if (!currentSelection || !doc) return false;
|
|
58
|
-
const
|
|
58
|
+
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
59
|
+
if (!oldBody) return false;
|
|
60
|
+
const textRun = (_getBodySlice$textRun = getBodySlice(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
|
|
59
61
|
if (textRun) textRun.ed = params.label.length + 1;
|
|
60
62
|
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
61
63
|
unitId,
|
|
@@ -144,11 +146,11 @@ const ClickDocHyperLinkOperation = {
|
|
|
144
146
|
type: CommandType.OPERATION,
|
|
145
147
|
id: "doc.operation.click-hyper-link",
|
|
146
148
|
handler(accessor, params) {
|
|
147
|
-
var _body$customRanges;
|
|
149
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
148
150
|
if (!params) return false;
|
|
149
151
|
const { unitId, linkId, segmentId } = params;
|
|
150
152
|
const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
151
|
-
const body = doc === null || doc === void 0
|
|
153
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
152
154
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
|
|
153
155
|
if (!isSafeUrl(link)) return false;
|
|
154
156
|
window.open(link, "_blank", "noopener noreferrer");
|
|
@@ -159,7 +161,7 @@ const ClickDocHyperLinkOperation = {
|
|
|
159
161
|
//#endregion
|
|
160
162
|
//#region src/views/DocLinkPopup.tsx
|
|
161
163
|
const DocLinkPopup = () => {
|
|
162
|
-
var _body$customRanges, _link$properties;
|
|
164
|
+
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
|
|
163
165
|
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
164
166
|
const commandService = useDependency(ICommandService);
|
|
165
167
|
const messageService = useDependency(IMessageService);
|
|
@@ -169,7 +171,7 @@ const DocLinkPopup = () => {
|
|
|
169
171
|
if (!currentPopup) return null;
|
|
170
172
|
const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
|
|
171
173
|
const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
172
|
-
const body = doc === null || doc === void 0
|
|
174
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
173
175
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
|
|
174
176
|
if (!link) return null;
|
|
175
177
|
const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
|
package/lib/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
|
|
13
13
|
//#region package.json
|
|
14
14
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
15
|
-
var version = "1.0.0-alpha.
|
|
15
|
+
var version = "1.0.0-alpha.2";
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/config/config.ts
|
|
@@ -47,7 +47,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
47
47
|
id: "docs.command.update-hyper-link",
|
|
48
48
|
type: CommandType.COMMAND,
|
|
49
49
|
handler(accessor, params) {
|
|
50
|
-
var
|
|
50
|
+
var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
|
|
51
51
|
if (!params) return false;
|
|
52
52
|
const { unitId, payload, segmentId, linkId } = params;
|
|
53
53
|
const commandService = accessor.get(ICommandService);
|
|
@@ -55,7 +55,9 @@ const UpdateDocHyperLinkCommand = {
|
|
|
55
55
|
const currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange();
|
|
56
56
|
const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
57
57
|
if (!currentSelection || !doc) return false;
|
|
58
|
-
const
|
|
58
|
+
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
59
|
+
if (!oldBody) return false;
|
|
60
|
+
const textRun = (_getBodySlice$textRun = getBodySlice(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
|
|
59
61
|
if (textRun) textRun.ed = params.label.length + 1;
|
|
60
62
|
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
61
63
|
unitId,
|
|
@@ -144,11 +146,11 @@ const ClickDocHyperLinkOperation = {
|
|
|
144
146
|
type: CommandType.OPERATION,
|
|
145
147
|
id: "doc.operation.click-hyper-link",
|
|
146
148
|
handler(accessor, params) {
|
|
147
|
-
var _body$customRanges;
|
|
149
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
148
150
|
if (!params) return false;
|
|
149
151
|
const { unitId, linkId, segmentId } = params;
|
|
150
152
|
const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
151
|
-
const body = doc === null || doc === void 0
|
|
153
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
152
154
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
|
|
153
155
|
if (!isSafeUrl(link)) return false;
|
|
154
156
|
window.open(link, "_blank", "noopener noreferrer");
|
|
@@ -159,7 +161,7 @@ const ClickDocHyperLinkOperation = {
|
|
|
159
161
|
//#endregion
|
|
160
162
|
//#region src/views/DocLinkPopup.tsx
|
|
161
163
|
const DocLinkPopup = () => {
|
|
162
|
-
var _body$customRanges, _link$properties;
|
|
164
|
+
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
|
|
163
165
|
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
164
166
|
const commandService = useDependency(ICommandService);
|
|
165
167
|
const messageService = useDependency(IMessageService);
|
|
@@ -169,7 +171,7 @@ const DocLinkPopup = () => {
|
|
|
169
171
|
if (!currentPopup) return null;
|
|
170
172
|
const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
|
|
171
173
|
const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
172
|
-
const body = doc === null || doc === void 0
|
|
174
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
173
175
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
|
|
174
176
|
if (!link) return null;
|
|
175
177
|
const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render"),require("react"),require("@univerjs/ui"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs-hyper-link`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/docs-ui`,`rxjs`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverCore,e.UniverDocsHyperLink,e.UniverEngineRender,e.React,e.UniverUi,e.UniverDesign,e.UniverDocs,e.UniverDocsUi,e.rxjs,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var d=`@univerjs/docs-hyper-link-ui`,f=`1.0.0-alpha.0`;let p={};function m({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${v()}`);return h(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...g(e,n,a),...r},(_(e,n).children||[]).map((r,i)=>h(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let y={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},b=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`copy-icon`,ref:t,icon:y}))});b.displayName=`CopyIcon`;let x={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z`}}]},S=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`link-icon`,ref:t,icon:x}))});S.displayName=`LinkIcon`;let C={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z`}}]},w=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:C}))});w.displayName=`UnlinkIcon`;let T={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z`}}]},E=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`write-icon`,ref:t,icon:T}))});E.displayName=`WriteIcon`;let D={type:t.CommandType.COMMAND,id:`docs.command.add-hyper-link`,async handler(e,n){if(!n)return!1;let{payload:r,unitId:i,selections:a}=n,o=e.get(t.ICommandService),c=(0,s.addCustomRangeBySelectionFactory)(e,{rangeId:(0,t.generateRandomId)(),rangeType:t.CustomRangeType.HYPERLINK,properties:{url:r},unitId:i,selections:a});return c?o.syncExecuteCommand(c.id,c.params):!1}},O={id:`docs.command.update-hyper-link`,type:t.CommandType.COMMAND,handler(e,n){var r;if(!n)return!1;let{unitId:i,payload:a,segmentId:o,linkId:c}=n,l=e.get(t.ICommandService),u=e.get(t.IUniverInstanceService),d=e.get(s.DocSelectionManagerService).getActiveTextRange(),f=u.getUnit(i,t.UniverInstanceType.UNIVER_DOC);if(!d||!f)return!1;let p=(r=(0,t.getBodySlice)(f.getSelfOrHeaderFooterModel(o).getBody(),d.startOffset,d.endOffset).textRuns)==null?void 0:r[0];p&&(p.ed=n.label.length+1);let m=(0,s.replaceSelectionFactory)(e,{unitId:i,body:{dataStream:`${n.label}`,customRanges:[{rangeId:c,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:n.label.length+1,properties:{url:a}}],textRuns:p?[p]:void 0},selection:{startOffset:d.startOffset,endOffset:d.endOffset,collapsed:!1,segmentId:o}});return m?l.syncExecuteCommand(m.id,m.params):!1}},k={type:t.CommandType.COMMAND,id:`docs.command.delete-hyper-link`,async handler(e,n){if(!n)return!1;let{unitId:r,linkId:i,segmentId:a}=n,o=e.get(t.ICommandService),c=(0,s.deleteCustomRangeFactory)(e,{unitId:r,rangeId:i,segmentId:a});return c?await o.syncExecuteCommand(c.id,c.params):!1}},A=e=>{let n=e.get(s.DocSelectionManagerService),r=e.get(t.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;let a=i[0];return!!(!r.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC)||!a||a.collapsed)},j={type:t.CommandType.OPERATION,id:`doc.operation.show-hyper-link-edit-popup`,handler(e,n){var r;let i=n==null?void 0:n.link,a=e.get(t.IUniverInstanceService);if(A(e)&&!i)return!1;let o=e.get(V),s=(i==null?void 0:i.unitId)||((r=a.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null?void 0:r.getUnitId());return s?(o.showEditPopup(s,i),!0):!1}},M={type:t.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(V);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},N={type:t.CommandType.OPERATION,id:`doc.operation.click-hyper-link`,handler(e,n){var r;if(!n)return!1;let{unitId:i,linkId:a,segmentId:o}=n,s=e.get(t.IUniverInstanceService).getUnit(i,t.UniverInstanceType.UNIVER_DOC),c=s==null?void 0:s.getSelfOrHeaderFooterModel(o).getBody(),l=c==null||(r=c.customRanges)==null||(r=r.find(e=>e.rangeId===a&&e.rangeType===t.CustomRangeType.HYPERLINK))==null||(r=r.properties)==null?void 0:r.url;return(0,t.isSafeUrl)(l)?(window.open(l,`_blank`,`noopener noreferrer`),!0):!1}},P=()=>{var e,n;let r=(0,a.useDependency)(V),i=(0,a.useDependency)(t.ICommandService),s=(0,a.useDependency)(a.IMessageService),c=(0,a.useDependency)(t.LocaleService),l=(0,a.useObservable)(r.showingLink$),d=(0,a.useDependency)(t.IUniverInstanceService);if(!l)return null;let{unitId:f,linkId:p,segmentId:m,startIndex:h,endIndex:g}=l,_=d.getUnit(f,t.UniverInstanceType.UNIVER_DOC),v=_==null?void 0:_.getSelfOrHeaderFooterModel(m).getBody(),y=v==null||(e=v.customRanges)==null?void 0:e.find(e=>e.rangeId===p&&e.rangeType===t.CustomRangeType.HYPERLINK&&e.startIndex===h&&e.endIndex===g);if(!y)return null;let x=(n=y.properties)==null?void 0:n.url;return(0,u.jsxs)(`div`,{className:(0,o.clsx)(`univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900`,o.borderClassName),onClick:()=>{r.hideInfoPopup()},children:[(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500`,onClick:()=>window.open(x,void 0,`noopener noreferrer`),children:[(0,u.jsx)(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white`,children:(0,u.jsx)(S,{})}),(0,u.jsx)(o.Tooltip,{showIfEllipsis:!0,title:x,children:(0,u.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:x})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{navigator.clipboard.writeText(x),s.show({content:c.t(`docs-hyper-link-ui.info.coped`),type:o.MessageType.Info})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:c.t(`docs-hyper-link-ui.info.copy`),children:(0,u.jsx)(b,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{i.executeCommand(j.id,{link:l})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:c.t(`docs-hyper-link-ui.info.edit`),children:(0,u.jsx)(E,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{i.executeCommand(k.id,{unitId:f,linkId:y.rangeId,segmentId:m})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:c.t(`docs-hyper-link-ui.info.cancel`),children:(0,u.jsx)(w,{})})})]})]})};P.componentKey=`univer.doc.link-info-popup`;function F(e){"@babel/helpers - typeof";return F=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},F(e)}function I(e,t){if(F(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(F(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function L(e){var t=I(e,`string`);return F(t)==`symbol`?t:t+``}function R(e,t,n){return(t=L(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function z(e,t){return function(n,r){t(n,r,e)}}function B(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 V=class extends t.Disposable{constructor(e,t,n){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,R(this,`_editingLink$`,new l.BehaviorSubject(null)),R(this,`_showingLink$`,new l.BehaviorSubject(null)),R(this,`editingLink$`,this._editingLink$.asObservable()),R(this,`showingLink$`,this._showingLink$.asObservable()),R(this,`_editPopup`,null),R(this,`_infoPopup`,null),this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);let n=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e}),r=n==null?void 0:n[n.length-1];if(t){let{segmentId:e,segmentPage:n,startIndex:i,endIndex:a}=t;r={collapsed:!1,startOffset:i,endOffset:a+1,segmentId:e,segmentPage:n},this._textSelectionManagerService.replaceDocRanges([{startOffset:i,endOffset:a+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:K.componentKey,direction:`bottom`},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var n,r,i,a,o,s;let{linkId:c,unitId:l,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}=e;if(!(((n=this.showing)==null?void 0:n.linkId)===c&&((r=this.showing)==null?void 0:r.unitId)===l&&((i=this.showing)==null?void 0:i.segmentId)===u&&((a=this.showing)==null?void 0:a.segmentPage)===d&&((o=this.showing)==null?void 0:o.startIndex)===f&&((s=this.showing)==null?void 0:s.endIndex)===p)&&(this._infoPopup&&this._infoPopup.dispose(),this._univerInstanceService.getUnit(l,t.UniverInstanceType.UNIVER_DOC)))return this._showingLink$.next({unitId:l,linkId:c,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:f,endOffset:p+1,segmentId:u,segmentPage:d},{componentKey:P.componentKey,direction:`top-center`,multipleDirection:`top`,onClickOutside:()=>{this.hideInfoPopup()}},l),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};V=B([z(0,(0,t.Inject)(c.DocCanvasPopManagerService)),z(1,(0,t.Inject)(s.DocSelectionManagerService)),z(2,t.IUniverInstanceService)],V);function H(e){return e.trim().length===0}function U(e){return/^[a-zA-Z]+:\/\//.test(e)}function W(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function G(e){return U(e)?e:W(e)?`mailto://${e}`:`https://${e}`}let K=()=>{let e=(0,a.useDependency)(V),n=(0,a.useDependency)(t.LocaleService),r=(0,a.useObservable)(e.editingLink$),c=(0,a.useDependency)(t.ICommandService),l=(0,a.useDependency)(t.IUniverInstanceService),d=(0,a.useDependency)(s.DocSelectionManagerService),[f,p]=(0,i.useState)(``),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(!1),v=t.Tools.isLegalUrl(f),y=r?l.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC):l.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);(0,i.useEffect)(()=>{var e,n,i;let a=d.getActiveTextRange();if(!a)return;if(r){var o,s;let e=y==null||(o=y.getSelfOrHeaderFooterModel(r.segmentId))==null?void 0:o.getBody(),n=e==null||(s=e.customRanges)==null?void 0:s.find(e=>(r==null?void 0:r.linkId)===e.rangeId&&e.startIndex===r.startIndex&&e.endIndex===r.endIndex);if(y&&n){var c,l;p((c=(l=n.properties)==null?void 0:l.url)==null?``:c),h(t.BuildTextUtils.transform.getPlainText((0,t.getBodySlice)(e,n.startIndex,n.endIndex+1).dataStream))}return}let u=y==null||(e=y.getSelfOrHeaderFooterModel(a.segmentId))==null?void 0:e.getBody(),f=u?a:null,m=f&&((n=t.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(f,(i=u==null?void 0:u.customRanges)==null?[]:i))==null?void 0:n[0]);if(y&&m){var g,_;p((g=m==null||(_=m.properties)==null?void 0:_.url)==null?``:g)}},[y,r,d,l]);let b=()=>{e.hideEditPopup()},x=()=>{if(_(!0),!v||!y)return;let t=G(f);if(!r)c.executeCommand(D.id,{unitId:y.getUnitId(),payload:t});else{if(H(m))return;c.executeCommand(O.id,{unitId:y.getUnitId(),payload:t,linkId:r.linkId,label:m,segmentId:r.segmentId})}e.hideEditPopup()};if(y)return(0,u.jsxs)(`div`,{className:(0,o.clsx)(`univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900`,o.borderClassName),children:[(0,u.jsxs)(`div`,{children:[r?(0,u.jsx)(o.FormLayout,{label:n.t(`docs-hyper-link-ui.edit.label`),error:g&&H(m)?n.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,u.jsx)(o.Input,{value:m,onChange:h,autoFocus:!0,onKeyDown:e=>{e.keyCode===a.KeyCode.ENTER&&x()}})}):null,(0,u.jsx)(o.FormLayout,{label:n.t(`docs-hyper-link-ui.edit.address`),error:g&&!v?n.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,u.jsx)(o.Input,{value:f,onChange:p,autoFocus:!0,onKeyDown:e=>{e.keyCode===a.KeyCode.ENTER&&x()}})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,u.jsx)(o.Button,{onClick:b,children:n.t(`docs-hyper-link-ui.edit.cancel`)}),(0,u.jsx)(o.Button,{variant:`primary`,disabled:H(f),onClick:x,children:n.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};K.componentKey=`docs-hyper-link-edit`;let q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[K.componentKey,K],[P.componentKey,P]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:S}))}};q=B([z(0,(0,t.Inject)(a.ComponentManager)),z(1,(0,t.Inject)(a.IconManager))],q);let J=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._docHyperLinkService=n,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetTextSelectionsOperation.id){let{unitId:i,ranges:a,segmentId:o}=e.params,s=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_DOC),c=a[0];if(c&&s){var n;let{startOffset:e,endOffset:t,collapsed:a,segmentPage:l}=c,u=(n=s.getSelfOrHeaderFooterModel(o))==null||(n=n.getBody())==null?void 0:n.customRanges;if(a){var r;let n=(r=u==null?void 0:u.findIndex(n=>n.startIndex<e&&n.endIndex>t-1))==null?-1:r;if(n>-1){let e=u[n];this._docHyperLinkService.showInfoPopup({unitId:i,linkId:e.rangeId,segmentId:o,segmentPage:l,startIndex:e.startIndex,endIndex:e.endIndex});return}}else if(u!=null&&u.find(n=>n.startIndex<=e&&n.endIndex>=t-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};J=B([z(0,t.ICommandService),z(1,t.IUniverInstanceService),z(2,(0,t.Inject)(V))],J);let Y=class extends t.Disposable{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,n,r,i,a,o){super(),this._context=e,this._docEventManagerService=n,this._commandService=r,this._hyperLinkPopupService=i,this._docSkeletonManagerService=a,this._docSelectionManagerService=o,this._context.unitId!==t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&(this._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(M.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(e=>{var n,r;let i=e.find(e=>e.range.rangeType===t.CustomRangeType.HYPERLINK),a=this._docSelectionManagerService.getTextRanges(),o=a==null||(n=a[0])==null?void 0:n.segmentId;if(((r=i==null?void 0:i.segmentId)==null?``:r)!==o){this._hideInfoPopup();return}i?this._commandService.executeCommand(M.id,{unitId:this._context.unitId,linkId:i.range.rangeId,segmentId:i.segmentId,segmentPage:i.segmentPageIndex,rangeId:i.range.rangeId,startIndex:i.range.startIndex,endIndex:i.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;t&&this._commandService.executeCommand(N.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}))}};Y=B([z(1,(0,t.Inject)(c.DocEventManagerService)),z(2,t.ICommandService),z(3,(0,t.Inject)(V)),z(4,(0,t.Inject)(s.DocSkeletonManagerService)),z(5,(0,t.Inject)(s.DocSelectionManagerService))],Y);let X=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._docInterceptorService=t,this._hyperLinkService=n,this._docRenderController=r,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(s.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i}=t,a=this._hyperLinkService.showing;if(!a)return n({...e,active:!1});let{linkId:o,unitId:s,startIndex:c,endIndex:l}=a,u=s===r&&e.rangeId===o&&i>=c&&i<=l;return n({...e,active:u})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe((0,l.distinctUntilChanged)((e,t)=>(e==null?void 0:e.linkId)===(t==null?void 0:t.linkId)&&(e==null?void 0:e.unitId)===(t==null?void 0:t.unitId)&&(e==null?void 0:e.startIndex)===(t==null?void 0:t.startIndex)),(0,l.pairwise)()).subscribe(([e,t])=>{t?t.unitId===this._context.unitId&&this._docRenderController.reRender(t.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};X=B([z(1,(0,t.Inject)(s.DocInterceptorService)),z(2,(0,t.Inject)(V)),z(3,(0,t.Inject)(c.DocRenderController))],X);function Z(e){return{id:j.id,type:a.MenuItemType.BUTTON,icon:`LinkIcon`,title:`docs-hyper-link-ui.menu.tooltip`,tooltip:`docs-hyper-link-ui.menu.tooltip`,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC),disabled$:new l.Observable(function(t){let n=e.get(s.DocSelectionManagerService).textSelection$.pipe((0,l.debounceTime)(16)).subscribe(()=>{t.next(A(e))});return()=>{n.unsubscribe()}})}}let ee={id:j.id,binding:a.MetaKeys.CTRL_COMMAND|a.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:c.whenDocAndEditorFocused},te={[a.RibbonInsertGroup.MEDIA]:{[j.id]:{order:1,menuItemFactory:Z}},[c.FLOAT_TOOLBAR_MENU_POSITION]:{[j.id]:{order:20,menuItemFactory:Z}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[j.id]:{order:0,menuItemFactory:Z}}},[a.ContextMenuPosition.PARAGRAPH]:{[a.ContextMenuGroup.LAYOUT]:{[c.INSERT_BELLOW_MENU_ID]:{[j.id]:{order:6,menuItemFactory:Z}}},[c.EMPTY_PARAGRAPH_MENU_ID]:{[a.ContextMenuGroup.LAYOUT]:{[j.id]:{order:6,menuItemFactory:Z}}}}},Q=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._shortcutService=n,this._initCommands(),this._initMenus(),this._initShortcut()}_initCommands(){[D,O,k,j,M,N].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[ee].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[c.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(te)}};Q=B([z(0,t.ICommandService),z(1,a.IMenuManagerService),z(2,a.IShortcutService)],Q);let $=class extends t.Plugin{constructor(e=p,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},p,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-hyper-link-ui.config`,o)}onStarting(){this._injector.add([q]),this._injector.get(q),[[V],[Q],[J]].forEach(e=>{this._injector.add(e)}),this._injector.get(Q)}onReady(){this._injector.get(J)}onRendered(){this._initRenderModule()}_initRenderModule(){[[X],[Y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};R($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),R($,`packageName`,d),R($,`version`,f),R($,`type`,t.UniverInstanceType.UNIVER_DOC),$=B([(0,t.DependentOn)(n.UniverDocsHyperLinkPlugin),z(1,(0,t.Inject)(t.Injector)),z(2,r.IRenderManagerService),z(3,t.IConfigService)],$),Object.defineProperty(e,"UniverDocsHyperLinkUIPlugin",{enumerable:!0,get:function(){return $}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render"),require("react"),require("@univerjs/ui"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs-hyper-link`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/docs-ui`,`rxjs`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverCore,e.UniverDocsHyperLink,e.UniverEngineRender,e.React,e.UniverUi,e.UniverDesign,e.UniverDocs,e.UniverDocsUi,e.rxjs,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var d=`@univerjs/docs-hyper-link-ui`,f=`1.0.0-alpha.2`;let p={};function m({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${v()}`);return h(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...g(e,n,a),...r},(_(e,n).children||[]).map((r,i)=>h(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let y={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},b=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`copy-icon`,ref:t,icon:y}))});b.displayName=`CopyIcon`;let x={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z`}}]},S=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`link-icon`,ref:t,icon:x}))});S.displayName=`LinkIcon`;let C={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z`}}]},w=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:C}))});w.displayName=`UnlinkIcon`;let T={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z`}}]},E=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(m,Object.assign({},e,{id:`write-icon`,ref:t,icon:T}))});E.displayName=`WriteIcon`;let D={type:t.CommandType.COMMAND,id:`docs.command.add-hyper-link`,async handler(e,n){if(!n)return!1;let{payload:r,unitId:i,selections:a}=n,o=e.get(t.ICommandService),c=(0,s.addCustomRangeBySelectionFactory)(e,{rangeId:(0,t.generateRandomId)(),rangeType:t.CustomRangeType.HYPERLINK,properties:{url:r},unitId:i,selections:a});return c?o.syncExecuteCommand(c.id,c.params):!1}},O={id:`docs.command.update-hyper-link`,type:t.CommandType.COMMAND,handler(e,n){var r,i;if(!n)return!1;let{unitId:a,payload:o,segmentId:c,linkId:l}=n,u=e.get(t.ICommandService),d=e.get(t.IUniverInstanceService),f=e.get(s.DocSelectionManagerService).getActiveTextRange(),p=d.getUnit(a,t.UniverInstanceType.UNIVER_DOC);if(!f||!p)return!1;let m=(r=p.getSelfOrHeaderFooterModel(c))==null?void 0:r.getBody();if(!m)return!1;let h=(i=(0,t.getBodySlice)(m,f.startOffset,f.endOffset).textRuns)==null?void 0:i[0];h&&(h.ed=n.label.length+1);let g=(0,s.replaceSelectionFactory)(e,{unitId:a,body:{dataStream:`${n.label}`,customRanges:[{rangeId:l,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:n.label.length+1,properties:{url:o}}],textRuns:h?[h]:void 0},selection:{startOffset:f.startOffset,endOffset:f.endOffset,collapsed:!1,segmentId:c}});return g?u.syncExecuteCommand(g.id,g.params):!1}},k={type:t.CommandType.COMMAND,id:`docs.command.delete-hyper-link`,async handler(e,n){if(!n)return!1;let{unitId:r,linkId:i,segmentId:a}=n,o=e.get(t.ICommandService),c=(0,s.deleteCustomRangeFactory)(e,{unitId:r,rangeId:i,segmentId:a});return c?await o.syncExecuteCommand(c.id,c.params):!1}},A=e=>{let n=e.get(s.DocSelectionManagerService),r=e.get(t.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;let a=i[0];return!!(!r.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC)||!a||a.collapsed)},j={type:t.CommandType.OPERATION,id:`doc.operation.show-hyper-link-edit-popup`,handler(e,n){var r;let i=n==null?void 0:n.link,a=e.get(t.IUniverInstanceService);if(A(e)&&!i)return!1;let o=e.get(V),s=(i==null?void 0:i.unitId)||((r=a.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null?void 0:r.getUnitId());return s?(o.showEditPopup(s,i),!0):!1}},M={type:t.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(V);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},N={type:t.CommandType.OPERATION,id:`doc.operation.click-hyper-link`,handler(e,n){var r,i;if(!n)return!1;let{unitId:a,linkId:o,segmentId:s}=n,c=e.get(t.IUniverInstanceService).getUnit(a,t.UniverInstanceType.UNIVER_DOC),l=c==null||(r=c.getSelfOrHeaderFooterModel(s))==null?void 0:r.getBody(),u=l==null||(i=l.customRanges)==null||(i=i.find(e=>e.rangeId===o&&e.rangeType===t.CustomRangeType.HYPERLINK))==null||(i=i.properties)==null?void 0:i.url;return(0,t.isSafeUrl)(u)?(window.open(u,`_blank`,`noopener noreferrer`),!0):!1}},P=()=>{var e,n,r;let i=(0,a.useDependency)(V),s=(0,a.useDependency)(t.ICommandService),c=(0,a.useDependency)(a.IMessageService),l=(0,a.useDependency)(t.LocaleService),d=(0,a.useObservable)(i.showingLink$),f=(0,a.useDependency)(t.IUniverInstanceService);if(!d)return null;let{unitId:p,linkId:m,segmentId:h,startIndex:g,endIndex:_}=d,v=f.getUnit(p,t.UniverInstanceType.UNIVER_DOC),y=v==null||(e=v.getSelfOrHeaderFooterModel(h))==null?void 0:e.getBody(),x=y==null||(n=y.customRanges)==null?void 0:n.find(e=>e.rangeId===m&&e.rangeType===t.CustomRangeType.HYPERLINK&&e.startIndex===g&&e.endIndex===_);if(!x)return null;let C=(r=x.properties)==null?void 0:r.url;return(0,u.jsxs)(`div`,{className:(0,o.clsx)(`univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900`,o.borderClassName),onClick:()=>{i.hideInfoPopup()},children:[(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500`,onClick:()=>window.open(C,void 0,`noopener noreferrer`),children:[(0,u.jsx)(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white`,children:(0,u.jsx)(S,{})}),(0,u.jsx)(o.Tooltip,{showIfEllipsis:!0,title:C,children:(0,u.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:C})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{navigator.clipboard.writeText(C),c.show({content:l.t(`docs-hyper-link-ui.info.coped`),type:o.MessageType.Info})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:l.t(`docs-hyper-link-ui.info.copy`),children:(0,u.jsx)(b,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{s.executeCommand(j.id,{link:d})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:l.t(`docs-hyper-link-ui.info.edit`),children:(0,u.jsx)(E,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{s.executeCommand(k.id,{unitId:p,linkId:x.rangeId,segmentId:h})},children:(0,u.jsx)(o.Tooltip,{placement:`bottom`,title:l.t(`docs-hyper-link-ui.info.cancel`),children:(0,u.jsx)(w,{})})})]})]})};P.componentKey=`univer.doc.link-info-popup`;function F(e){"@babel/helpers - typeof";return F=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},F(e)}function I(e,t){if(F(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(F(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function L(e){var t=I(e,`string`);return F(t)==`symbol`?t:t+``}function R(e,t,n){return(t=L(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function z(e,t){return function(n,r){t(n,r,e)}}function B(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 V=class extends t.Disposable{constructor(e,t,n){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,R(this,`_editingLink$`,new l.BehaviorSubject(null)),R(this,`_showingLink$`,new l.BehaviorSubject(null)),R(this,`editingLink$`,this._editingLink$.asObservable()),R(this,`showingLink$`,this._showingLink$.asObservable()),R(this,`_editPopup`,null),R(this,`_infoPopup`,null),this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);let n=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e}),r=n==null?void 0:n[n.length-1];if(t){let{segmentId:e,segmentPage:n,startIndex:i,endIndex:a}=t;r={collapsed:!1,startOffset:i,endOffset:a+1,segmentId:e,segmentPage:n},this._textSelectionManagerService.replaceDocRanges([{startOffset:i,endOffset:a+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:K.componentKey,direction:`bottom`},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var n,r,i,a,o,s;let{linkId:c,unitId:l,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}=e;if(!(((n=this.showing)==null?void 0:n.linkId)===c&&((r=this.showing)==null?void 0:r.unitId)===l&&((i=this.showing)==null?void 0:i.segmentId)===u&&((a=this.showing)==null?void 0:a.segmentPage)===d&&((o=this.showing)==null?void 0:o.startIndex)===f&&((s=this.showing)==null?void 0:s.endIndex)===p)&&(this._infoPopup&&this._infoPopup.dispose(),this._univerInstanceService.getUnit(l,t.UniverInstanceType.UNIVER_DOC)))return this._showingLink$.next({unitId:l,linkId:c,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:f,endOffset:p+1,segmentId:u,segmentPage:d},{componentKey:P.componentKey,direction:`top-center`,multipleDirection:`top`,onClickOutside:()=>{this.hideInfoPopup()}},l),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};V=B([z(0,(0,t.Inject)(c.DocCanvasPopManagerService)),z(1,(0,t.Inject)(s.DocSelectionManagerService)),z(2,t.IUniverInstanceService)],V);function H(e){return e.trim().length===0}function U(e){return/^[a-zA-Z]+:\/\//.test(e)}function W(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function G(e){return U(e)?e:W(e)?`mailto://${e}`:`https://${e}`}let K=()=>{let e=(0,a.useDependency)(V),n=(0,a.useDependency)(t.LocaleService),r=(0,a.useObservable)(e.editingLink$),c=(0,a.useDependency)(t.ICommandService),l=(0,a.useDependency)(t.IUniverInstanceService),d=(0,a.useDependency)(s.DocSelectionManagerService),[f,p]=(0,i.useState)(``),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(!1),v=t.Tools.isLegalUrl(f),y=r?l.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC):l.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);(0,i.useEffect)(()=>{var e,n,i;let a=d.getActiveTextRange();if(!a)return;if(r){var o,s;let e=y==null||(o=y.getSelfOrHeaderFooterModel(r.segmentId))==null?void 0:o.getBody(),n=e==null||(s=e.customRanges)==null?void 0:s.find(e=>(r==null?void 0:r.linkId)===e.rangeId&&e.startIndex===r.startIndex&&e.endIndex===r.endIndex);if(y&&n){var c,l;p((c=(l=n.properties)==null?void 0:l.url)==null?``:c),h(t.BuildTextUtils.transform.getPlainText((0,t.getBodySlice)(e,n.startIndex,n.endIndex+1).dataStream))}return}let u=y==null||(e=y.getSelfOrHeaderFooterModel(a.segmentId))==null?void 0:e.getBody(),f=u?a:null,m=f&&((n=t.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(f,(i=u==null?void 0:u.customRanges)==null?[]:i))==null?void 0:n[0]);if(y&&m){var g,_;p((g=m==null||(_=m.properties)==null?void 0:_.url)==null?``:g)}},[y,r,d,l]);let b=()=>{e.hideEditPopup()},x=()=>{if(_(!0),!v||!y)return;let t=G(f);if(!r)c.executeCommand(D.id,{unitId:y.getUnitId(),payload:t});else{if(H(m))return;c.executeCommand(O.id,{unitId:y.getUnitId(),payload:t,linkId:r.linkId,label:m,segmentId:r.segmentId})}e.hideEditPopup()};if(y)return(0,u.jsxs)(`div`,{className:(0,o.clsx)(`univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900`,o.borderClassName),children:[(0,u.jsxs)(`div`,{children:[r?(0,u.jsx)(o.FormLayout,{label:n.t(`docs-hyper-link-ui.edit.label`),error:g&&H(m)?n.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,u.jsx)(o.Input,{value:m,onChange:h,autoFocus:!0,onKeyDown:e=>{e.keyCode===a.KeyCode.ENTER&&x()}})}):null,(0,u.jsx)(o.FormLayout,{label:n.t(`docs-hyper-link-ui.edit.address`),error:g&&!v?n.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,u.jsx)(o.Input,{value:f,onChange:p,autoFocus:!0,onKeyDown:e=>{e.keyCode===a.KeyCode.ENTER&&x()}})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,u.jsx)(o.Button,{onClick:b,children:n.t(`docs-hyper-link-ui.edit.cancel`)}),(0,u.jsx)(o.Button,{variant:`primary`,disabled:H(f),onClick:x,children:n.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};K.componentKey=`docs-hyper-link-edit`;let q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[K.componentKey,K],[P.componentKey,P]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:S}))}};q=B([z(0,(0,t.Inject)(a.ComponentManager)),z(1,(0,t.Inject)(a.IconManager))],q);let J=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._docHyperLinkService=n,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetTextSelectionsOperation.id){let{unitId:i,ranges:a,segmentId:o}=e.params,s=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_DOC),c=a[0];if(c&&s){var n;let{startOffset:e,endOffset:t,collapsed:a,segmentPage:l}=c,u=(n=s.getSelfOrHeaderFooterModel(o))==null||(n=n.getBody())==null?void 0:n.customRanges;if(a){var r;let n=(r=u==null?void 0:u.findIndex(n=>n.startIndex<e&&n.endIndex>t-1))==null?-1:r;if(n>-1){let e=u[n];this._docHyperLinkService.showInfoPopup({unitId:i,linkId:e.rangeId,segmentId:o,segmentPage:l,startIndex:e.startIndex,endIndex:e.endIndex});return}}else if(u!=null&&u.find(n=>n.startIndex<=e&&n.endIndex>=t-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};J=B([z(0,t.ICommandService),z(1,t.IUniverInstanceService),z(2,(0,t.Inject)(V))],J);let Y=class extends t.Disposable{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,n,r,i,a,o){super(),this._context=e,this._docEventManagerService=n,this._commandService=r,this._hyperLinkPopupService=i,this._docSkeletonManagerService=a,this._docSelectionManagerService=o,this._context.unitId!==t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&(this._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(M.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(e=>{var n,r;let i=e.find(e=>e.range.rangeType===t.CustomRangeType.HYPERLINK),a=this._docSelectionManagerService.getTextRanges(),o=a==null||(n=a[0])==null?void 0:n.segmentId;if(((r=i==null?void 0:i.segmentId)==null?``:r)!==o){this._hideInfoPopup();return}i?this._commandService.executeCommand(M.id,{unitId:this._context.unitId,linkId:i.range.rangeId,segmentId:i.segmentId,segmentPage:i.segmentPageIndex,rangeId:i.range.rangeId,startIndex:i.range.startIndex,endIndex:i.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;t&&this._commandService.executeCommand(N.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}))}};Y=B([z(1,(0,t.Inject)(c.DocEventManagerService)),z(2,t.ICommandService),z(3,(0,t.Inject)(V)),z(4,(0,t.Inject)(s.DocSkeletonManagerService)),z(5,(0,t.Inject)(s.DocSelectionManagerService))],Y);let X=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._docInterceptorService=t,this._hyperLinkService=n,this._docRenderController=r,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(s.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i}=t,a=this._hyperLinkService.showing;if(!a)return n({...e,active:!1});let{linkId:o,unitId:s,startIndex:c,endIndex:l}=a,u=s===r&&e.rangeId===o&&i>=c&&i<=l;return n({...e,active:u})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe((0,l.distinctUntilChanged)((e,t)=>(e==null?void 0:e.linkId)===(t==null?void 0:t.linkId)&&(e==null?void 0:e.unitId)===(t==null?void 0:t.unitId)&&(e==null?void 0:e.startIndex)===(t==null?void 0:t.startIndex)),(0,l.pairwise)()).subscribe(([e,t])=>{t?t.unitId===this._context.unitId&&this._docRenderController.reRender(t.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};X=B([z(1,(0,t.Inject)(s.DocInterceptorService)),z(2,(0,t.Inject)(V)),z(3,(0,t.Inject)(c.DocRenderController))],X);function Z(e){return{id:j.id,type:a.MenuItemType.BUTTON,icon:`LinkIcon`,title:`docs-hyper-link-ui.menu.tooltip`,tooltip:`docs-hyper-link-ui.menu.tooltip`,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC),disabled$:new l.Observable(function(t){let n=e.get(s.DocSelectionManagerService).textSelection$.pipe((0,l.debounceTime)(16)).subscribe(()=>{t.next(A(e))});return()=>{n.unsubscribe()}})}}let ee={id:j.id,binding:a.MetaKeys.CTRL_COMMAND|a.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:c.whenDocAndEditorFocused},te={[a.RibbonInsertGroup.MEDIA]:{[j.id]:{order:1,menuItemFactory:Z}},[c.FLOAT_TOOLBAR_MENU_POSITION]:{[j.id]:{order:20,menuItemFactory:Z}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[j.id]:{order:0,menuItemFactory:Z}}},[a.ContextMenuPosition.PARAGRAPH]:{[a.ContextMenuGroup.LAYOUT]:{[c.INSERT_BELLOW_MENU_ID]:{[j.id]:{order:6,menuItemFactory:Z}}},[c.EMPTY_PARAGRAPH_MENU_ID]:{[a.ContextMenuGroup.LAYOUT]:{[j.id]:{order:6,menuItemFactory:Z}}}}},Q=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._shortcutService=n,this._initCommands(),this._initMenus(),this._initShortcut()}_initCommands(){[D,O,k,j,M,N].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[ee].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[c.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(te)}};Q=B([z(0,t.ICommandService),z(1,a.IMenuManagerService),z(2,a.IShortcutService)],Q);let $=class extends t.Plugin{constructor(e=p,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},p,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-hyper-link-ui.config`,o)}onStarting(){this._injector.add([q]),this._injector.get(q),[[V],[Q],[J]].forEach(e=>{this._injector.add(e)}),this._injector.get(Q)}onReady(){this._injector.get(J)}onRendered(){this._initRenderModule()}_initRenderModule(){[[X],[Y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};R($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),R($,`packageName`,d),R($,`version`,f),R($,`type`,t.UniverInstanceType.UNIVER_DOC),$=B([(0,t.DependentOn)(n.UniverDocsHyperLinkPlugin),z(1,(0,t.Inject)(t.Injector)),z(2,r.IRenderManagerService),z(3,t.IConfigService)],$),Object.defineProperty(e,"UniverDocsHyperLinkUIPlugin",{enumerable:!0,get:function(){return $}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-hyper-link-ui",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Hyperlink editing UI for Univer Docs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,23 +58,23 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/icons": "1.
|
|
62
|
-
"@univerjs/core": "1.0.0-alpha.
|
|
63
|
-
"@univerjs/design": "1.0.0-alpha.
|
|
64
|
-
"@univerjs/docs": "1.0.0-alpha.
|
|
65
|
-
"@univerjs/docs-ui": "1.0.0-alpha.
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
61
|
+
"@univerjs/icons": "1.16.0",
|
|
62
|
+
"@univerjs/core": "1.0.0-alpha.2",
|
|
63
|
+
"@univerjs/design": "1.0.0-alpha.2",
|
|
64
|
+
"@univerjs/docs": "1.0.0-alpha.2",
|
|
65
|
+
"@univerjs/docs-ui": "1.0.0-alpha.2",
|
|
66
|
+
"@univerjs/engine-render": "1.0.0-alpha.2",
|
|
67
|
+
"@univerjs/ui": "1.0.0-alpha.2",
|
|
68
|
+
"@univerjs/docs-hyper-link": "1.0.0-alpha.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"postcss": "^8.5.
|
|
71
|
+
"postcss": "^8.5.16",
|
|
72
72
|
"react": "18.3.1",
|
|
73
73
|
"rxjs": "^7.8.2",
|
|
74
74
|
"tailwindcss": "3.4.18",
|
|
75
75
|
"typescript": "^6.0.3",
|
|
76
76
|
"vitest": "^4.1.9",
|
|
77
|
-
"@univerjs-infra/shared": "1.0.0-alpha.
|
|
77
|
+
"@univerjs-infra/shared": "1.0.0-alpha.2"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"test": "vitest run",
|