@univerjs/docs-hyper-link-ui 1.0.0-alpha.2 → 1.0.0-alpha.4

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 CHANGED
@@ -1,27 +1,16 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let _univerjs_core = require("@univerjs/core");
3
- let _univerjs_docs_hyper_link = require("@univerjs/docs-hyper-link");
4
- let _univerjs_engine_render = require("@univerjs/engine-render");
5
- let _univerjs_icons = require("@univerjs/icons");
2
+ let _univerjs_docs_ui = require("@univerjs/docs-ui");
6
3
  let _univerjs_ui = require("@univerjs/ui");
7
- let _univerjs_design = require("@univerjs/design");
4
+ let _univerjs_core = require("@univerjs/core");
8
5
  let _univerjs_docs = require("@univerjs/docs");
9
- let react = require("react");
10
- let _univerjs_docs_ui = require("@univerjs/docs-ui");
11
6
  let rxjs = require("rxjs");
7
+ let _univerjs_design = require("@univerjs/design");
8
+ let react = require("react");
12
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ let _univerjs_icons = require("@univerjs/icons");
11
+ let _univerjs_docs_hyper_link = require("@univerjs/docs-hyper-link");
12
+ let _univerjs_engine_render = require("@univerjs/engine-render");
13
13
 
14
- //#region package.json
15
- var name = "@univerjs/docs-hyper-link-ui";
16
- var version = "1.0.0-alpha.2";
17
-
18
- //#endregion
19
- //#region src/config/config.ts
20
- const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
21
- const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
22
- const defaultPluginConfig = {};
23
-
24
- //#endregion
25
14
  //#region src/commands/commands/add-link.command.ts
26
15
  const AddDocHyperLinkCommand = {
27
16
  type: _univerjs_core.CommandType.COMMAND,
@@ -85,6 +74,142 @@ const UpdateDocHyperLinkCommand = {
85
74
  }
86
75
  };
87
76
 
77
+ //#endregion
78
+ //#region src/views/hyper-link-edit/utils.ts
79
+ /**
80
+ * Copyright 2023-present DreamNum Co., Ltd.
81
+ *
82
+ * Licensed under the Apache License, Version 2.0 (the "License");
83
+ * you may not use this file except in compliance with the License.
84
+ * You may obtain a copy of the License at
85
+ *
86
+ * http://www.apache.org/licenses/LICENSE-2.0
87
+ *
88
+ * Unless required by applicable law or agreed to in writing, software
89
+ * distributed under the License is distributed on an "AS IS" BASIS,
90
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91
+ * See the License for the specific language governing permissions and
92
+ * limitations under the License.
93
+ */
94
+ function isBlankInput(value) {
95
+ return value.trim().length === 0;
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/views/DocHyperLinkEdit.tsx
100
+ function hasProtocol(urlString) {
101
+ return /^[a-zA-Z]+:\/\//.test(urlString);
102
+ }
103
+ function isEmail(url) {
104
+ return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
105
+ }
106
+ function transformUrl(urlStr) {
107
+ return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
108
+ }
109
+ const DocHyperLinkEdit = () => {
110
+ const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
111
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
112
+ const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$);
113
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
114
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
115
+ const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
116
+ const [link, setLink] = (0, react.useState)("");
117
+ const [label, setLabel] = (0, react.useState)("");
118
+ const [showError, setShowError] = (0, react.useState)(false);
119
+ const isLegal = _univerjs_core.Tools.isLegalUrl(link);
120
+ const doc = editing ? univerInstanceService.getUnit(editing.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
121
+ (0, react.useEffect)(() => {
122
+ var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
123
+ const activeRange = docSelectionManagerService.getActiveTextRange();
124
+ if (!activeRange) return;
125
+ if (editing) {
126
+ var _doc$getSelfOrHeaderF, _body$customRanges;
127
+ const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
128
+ const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
129
+ if (doc && matchedRange) {
130
+ var _matchedRange$propert, _matchedRange$propert2;
131
+ setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
132
+ setLabel(_univerjs_core.BuildTextUtils.transform.getPlainText((0, _univerjs_core.getBodySlice)(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
133
+ }
134
+ return;
135
+ }
136
+ const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
137
+ const selection = body ? activeRange : null;
138
+ const matchedRange = selection && ((_BuildTextUtils$custo = _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges2 = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges2 !== void 0 ? _body$customRanges2 : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
139
+ if (doc && matchedRange) {
140
+ var _matchedRange$propert3, _matchedRange$propert4;
141
+ setLink((_matchedRange$propert3 = matchedRange === null || matchedRange === void 0 || (_matchedRange$propert4 = matchedRange.properties) === null || _matchedRange$propert4 === void 0 ? void 0 : _matchedRange$propert4.url) !== null && _matchedRange$propert3 !== void 0 ? _matchedRange$propert3 : "");
142
+ }
143
+ }, [
144
+ doc,
145
+ editing,
146
+ docSelectionManagerService,
147
+ univerInstanceService
148
+ ]);
149
+ const handleCancel = () => {
150
+ hyperLinkService.hideEditPopup();
151
+ };
152
+ const handleConfirm = () => {
153
+ setShowError(true);
154
+ if (!isLegal || !doc) return;
155
+ const linkFinal = transformUrl(link);
156
+ if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
157
+ unitId: doc.getUnitId(),
158
+ payload: linkFinal
159
+ });
160
+ else {
161
+ if (isBlankInput(label)) return;
162
+ commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
163
+ unitId: doc.getUnitId(),
164
+ payload: linkFinal,
165
+ linkId: editing.linkId,
166
+ label,
167
+ segmentId: editing.segmentId
168
+ });
169
+ }
170
+ hyperLinkService.hideEditPopup();
171
+ };
172
+ if (!doc) return;
173
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
174
+ className: (0, _univerjs_design.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", _univerjs_design.borderClassName),
175
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
176
+ label: localeService.t("docs-hyper-link-ui.edit.label"),
177
+ error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
178
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
179
+ value: label,
180
+ onChange: setLabel,
181
+ autoFocus: true,
182
+ onKeyDown: (evt) => {
183
+ if (evt.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
184
+ }
185
+ })
186
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
187
+ label: localeService.t("docs-hyper-link-ui.edit.address"),
188
+ error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
189
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
190
+ value: link,
191
+ onChange: setLink,
192
+ autoFocus: true,
193
+ onKeyDown: (evt) => {
194
+ if (evt.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
195
+ }
196
+ })
197
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
198
+ className: "univer-flex univer-justify-end univer-gap-3",
199
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
200
+ onClick: handleCancel,
201
+ children: localeService.t("docs-hyper-link-ui.edit.cancel")
202
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
203
+ variant: "primary",
204
+ disabled: isBlankInput(link),
205
+ onClick: handleConfirm,
206
+ children: localeService.t("docs-hyper-link-ui.edit.confirm")
207
+ })]
208
+ })]
209
+ });
210
+ };
211
+ DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
212
+
88
213
  //#endregion
89
214
  //#region src/commands/commands/delete-link.command.ts
90
215
  const DeleteDocHyperLinkCommand = {
@@ -104,61 +229,6 @@ const DeleteDocHyperLinkCommand = {
104
229
  }
105
230
  };
106
231
 
107
- //#endregion
108
- //#region src/commands/operations/popup.operation.ts
109
- const shouldDisableAddLink = (accessor) => {
110
- const textSelectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
111
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
112
- const textRanges = textSelectionService.getTextRanges();
113
- if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
114
- const activeRange = textRanges[0];
115
- if (!univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed) return true;
116
- return false;
117
- };
118
- const ShowDocHyperLinkEditPopupOperation = {
119
- type: _univerjs_core.CommandType.OPERATION,
120
- id: "doc.operation.show-hyper-link-edit-popup",
121
- handler(accessor, params) {
122
- var _univerInstanceServic;
123
- const linkInfo = params === null || params === void 0 ? void 0 : params.link;
124
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
125
- if (shouldDisableAddLink(accessor) && !linkInfo) return false;
126
- const hyperLinkService = accessor.get(DocHyperLinkPopupService);
127
- const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
128
- if (!unitId) return false;
129
- hyperLinkService.showEditPopup(unitId, linkInfo);
130
- return true;
131
- }
132
- };
133
- const ToggleDocHyperLinkInfoPopupOperation = {
134
- type: _univerjs_core.CommandType.OPERATION,
135
- id: "doc.operation.toggle-hyper-link-info-popup",
136
- handler(accessor, params) {
137
- const hyperLinkService = accessor.get(DocHyperLinkPopupService);
138
- if (!params) {
139
- hyperLinkService.hideInfoPopup();
140
- return true;
141
- }
142
- hyperLinkService.showInfoPopup(params);
143
- return true;
144
- }
145
- };
146
- const ClickDocHyperLinkOperation = {
147
- type: _univerjs_core.CommandType.OPERATION,
148
- id: "doc.operation.click-hyper-link",
149
- handler(accessor, params) {
150
- var _doc$getSelfOrHeaderF, _body$customRanges;
151
- if (!params) return false;
152
- const { unitId, linkId, segmentId } = params;
153
- const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
154
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
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;
156
- if (!(0, _univerjs_core.isSafeUrl)(link)) return false;
157
- window.open(link, "_blank", "noopener noreferrer");
158
- return true;
159
- }
160
- };
161
-
162
232
  //#endregion
163
233
  //#region src/views/DocLinkPopup.tsx
164
234
  const DocLinkPopup = () => {
@@ -408,140 +478,124 @@ DocHyperLinkPopupService = __decorate([
408
478
  ], DocHyperLinkPopupService);
409
479
 
410
480
  //#endregion
411
- //#region src/views/hyper-link-edit/utils.ts
412
- /**
413
- * Copyright 2023-present DreamNum Co., Ltd.
414
- *
415
- * Licensed under the Apache License, Version 2.0 (the "License");
416
- * you may not use this file except in compliance with the License.
417
- * You may obtain a copy of the License at
418
- *
419
- * http://www.apache.org/licenses/LICENSE-2.0
420
- *
421
- * Unless required by applicable law or agreed to in writing, software
422
- * distributed under the License is distributed on an "AS IS" BASIS,
423
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
424
- * See the License for the specific language governing permissions and
425
- * limitations under the License.
426
- */
427
- function isBlankInput(value) {
428
- return value.trim().length === 0;
429
- }
481
+ //#region src/commands/operations/popup.operation.ts
482
+ const shouldDisableAddLink = (accessor) => {
483
+ const textSelectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
484
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
485
+ const textRanges = textSelectionService.getTextRanges();
486
+ if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
487
+ const activeRange = textRanges[0];
488
+ if (!univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed) return true;
489
+ return false;
490
+ };
491
+ const ShowDocHyperLinkEditPopupOperation = {
492
+ type: _univerjs_core.CommandType.OPERATION,
493
+ id: "doc.operation.show-hyper-link-edit-popup",
494
+ handler(accessor, params) {
495
+ var _univerInstanceServic;
496
+ const linkInfo = params === null || params === void 0 ? void 0 : params.link;
497
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
498
+ if (shouldDisableAddLink(accessor) && !linkInfo) return false;
499
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService);
500
+ const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
501
+ if (!unitId) return false;
502
+ hyperLinkService.showEditPopup(unitId, linkInfo);
503
+ return true;
504
+ }
505
+ };
506
+ const ToggleDocHyperLinkInfoPopupOperation = {
507
+ type: _univerjs_core.CommandType.OPERATION,
508
+ id: "doc.operation.toggle-hyper-link-info-popup",
509
+ handler(accessor, params) {
510
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService);
511
+ if (!params) {
512
+ hyperLinkService.hideInfoPopup();
513
+ return true;
514
+ }
515
+ hyperLinkService.showInfoPopup(params);
516
+ return true;
517
+ }
518
+ };
519
+ const ClickDocHyperLinkOperation = {
520
+ type: _univerjs_core.CommandType.OPERATION,
521
+ id: "doc.operation.click-hyper-link",
522
+ handler(accessor, params) {
523
+ var _doc$getSelfOrHeaderF, _body$customRanges;
524
+ if (!params) return false;
525
+ const { unitId, linkId, segmentId } = params;
526
+ const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
527
+ const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
528
+ 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;
529
+ if (!(0, _univerjs_core.isSafeUrl)(link)) return false;
530
+ window.open(link, "_blank", "noopener noreferrer");
531
+ return true;
532
+ }
533
+ };
430
534
 
431
535
  //#endregion
432
- //#region src/views/DocHyperLinkEdit.tsx
433
- function hasProtocol(urlString) {
434
- return /^[a-zA-Z]+:\/\//.test(urlString);
435
- }
436
- function isEmail(url) {
437
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
438
- }
439
- function transformUrl(urlStr) {
440
- return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
441
- }
442
- const DocHyperLinkEdit = () => {
443
- const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
444
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
445
- const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$);
446
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
447
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
448
- const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
449
- const [link, setLink] = (0, react.useState)("");
450
- const [label, setLabel] = (0, react.useState)("");
451
- const [showError, setShowError] = (0, react.useState)(false);
452
- const isLegal = _univerjs_core.Tools.isLegalUrl(link);
453
- const doc = editing ? univerInstanceService.getUnit(editing.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
454
- (0, react.useEffect)(() => {
455
- var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
456
- const activeRange = docSelectionManagerService.getActiveTextRange();
457
- if (!activeRange) return;
458
- if (editing) {
459
- var _doc$getSelfOrHeaderF, _body$customRanges;
460
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
461
- const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
462
- if (doc && matchedRange) {
463
- var _matchedRange$propert, _matchedRange$propert2;
464
- setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
465
- setLabel(_univerjs_core.BuildTextUtils.transform.getPlainText((0, _univerjs_core.getBodySlice)(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
466
- }
467
- return;
468
- }
469
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
470
- const selection = body ? activeRange : null;
471
- const matchedRange = selection && ((_BuildTextUtils$custo = _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges2 = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges2 !== void 0 ? _body$customRanges2 : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
472
- if (doc && matchedRange) {
473
- var _matchedRange$propert3, _matchedRange$propert4;
474
- setLink((_matchedRange$propert3 = matchedRange === null || matchedRange === void 0 || (_matchedRange$propert4 = matchedRange.properties) === null || _matchedRange$propert4 === void 0 ? void 0 : _matchedRange$propert4.url) !== null && _matchedRange$propert3 !== void 0 ? _matchedRange$propert3 : "");
475
- }
476
- }, [
477
- doc,
478
- editing,
479
- docSelectionManagerService,
480
- univerInstanceService
481
- ]);
482
- const handleCancel = () => {
483
- hyperLinkService.hideEditPopup();
484
- };
485
- const handleConfirm = () => {
486
- setShowError(true);
487
- if (!isLegal || !doc) return;
488
- const linkFinal = transformUrl(link);
489
- if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
490
- unitId: doc.getUnitId(),
491
- payload: linkFinal
492
- });
493
- else {
494
- if (isBlankInput(label)) return;
495
- commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
496
- unitId: doc.getUnitId(),
497
- payload: linkFinal,
498
- linkId: editing.linkId,
499
- label,
500
- segmentId: editing.segmentId
536
+ //#region src/menu/menu.ts
537
+ function AddHyperLinkMenuItemFactory(accessor) {
538
+ return {
539
+ id: ShowDocHyperLinkEditPopupOperation.id,
540
+ type: _univerjs_ui.MenuItemType.BUTTON,
541
+ icon: "LinkIcon",
542
+ title: "docs-hyper-link-ui.menu.tooltip",
543
+ tooltip: "docs-hyper-link-ui.menu.tooltip",
544
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC),
545
+ disabled$: new rxjs.Observable(function(subscribe) {
546
+ const observer = accessor.get(_univerjs_docs.DocSelectionManagerService).textSelection$.pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
547
+ subscribe.next(shouldDisableAddLink(accessor));
501
548
  });
502
- }
503
- hyperLinkService.hideEditPopup();
549
+ return () => {
550
+ observer.unsubscribe();
551
+ };
552
+ })
504
553
  };
505
- if (!doc) return;
506
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
507
- className: (0, _univerjs_design.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", _univerjs_design.borderClassName),
508
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
509
- label: localeService.t("docs-hyper-link-ui.edit.label"),
510
- error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
511
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
512
- value: label,
513
- onChange: setLabel,
514
- autoFocus: true,
515
- onKeyDown: (evt) => {
516
- if (evt.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
517
- }
518
- })
519
- }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
520
- label: localeService.t("docs-hyper-link-ui.edit.address"),
521
- error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
522
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
523
- value: link,
524
- onChange: setLink,
525
- autoFocus: true,
526
- onKeyDown: (evt) => {
527
- if (evt.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
528
- }
529
- })
530
- })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
531
- className: "univer-flex univer-justify-end univer-gap-3",
532
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
533
- onClick: handleCancel,
534
- children: localeService.t("docs-hyper-link-ui.edit.cancel")
535
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
536
- variant: "primary",
537
- disabled: isBlankInput(link),
538
- onClick: handleConfirm,
539
- children: localeService.t("docs-hyper-link-ui.edit.confirm")
540
- })]
541
- })]
542
- });
554
+ }
555
+ const addLinkShortcut = {
556
+ id: ShowDocHyperLinkEditPopupOperation.id,
557
+ binding: _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.KeyCode.K,
558
+ description: "docs-hyper-link-ui.menu.tooltip",
559
+ preconditions: _univerjs_docs_ui.whenDocAndEditorFocused
560
+ };
561
+
562
+ //#endregion
563
+ //#region src/menu/schema.ts
564
+ const menuSchema = {
565
+ [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
566
+ order: 1,
567
+ menuItemFactory: AddHyperLinkMenuItemFactory
568
+ } },
569
+ [_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
570
+ order: 20,
571
+ menuItemFactory: AddHyperLinkMenuItemFactory
572
+ } },
573
+ [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
574
+ order: 0,
575
+ menuItemFactory: AddHyperLinkMenuItemFactory
576
+ } } },
577
+ [_univerjs_ui.ContextMenuPosition.PARAGRAPH]: {
578
+ [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [_univerjs_docs_ui.INSERT_BELLOW_MENU_ID]: { [ShowDocHyperLinkEditPopupOperation.id]: {
579
+ order: 6,
580
+ menuItemFactory: AddHyperLinkMenuItemFactory
581
+ } } },
582
+ [_univerjs_docs_ui.EMPTY_PARAGRAPH_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [ShowDocHyperLinkEditPopupOperation.id]: {
583
+ order: 6,
584
+ menuItemFactory: AddHyperLinkMenuItemFactory
585
+ } } }
586
+ }
543
587
  };
544
- DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
588
+
589
+ //#endregion
590
+ //#region package.json
591
+ var name = "@univerjs/docs-hyper-link-ui";
592
+ var version = "1.0.0-alpha.4";
593
+
594
+ //#endregion
595
+ //#region src/config/config.ts
596
+ const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
597
+ const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
598
+ const defaultPluginConfig = {};
545
599
 
546
600
  //#endregion
547
601
  //#region src/controllers/components.controller.ts
@@ -733,60 +787,6 @@ DocHyperLinkRenderController = __decorate([
733
787
  __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocRenderController))
734
788
  ], DocHyperLinkRenderController);
735
789
 
736
- //#endregion
737
- //#region src/menu/menu.ts
738
- function AddHyperLinkMenuItemFactory(accessor) {
739
- return {
740
- id: ShowDocHyperLinkEditPopupOperation.id,
741
- type: _univerjs_ui.MenuItemType.BUTTON,
742
- icon: "LinkIcon",
743
- title: "docs-hyper-link-ui.menu.tooltip",
744
- tooltip: "docs-hyper-link-ui.menu.tooltip",
745
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC),
746
- disabled$: new rxjs.Observable(function(subscribe) {
747
- const observer = accessor.get(_univerjs_docs.DocSelectionManagerService).textSelection$.pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
748
- subscribe.next(shouldDisableAddLink(accessor));
749
- });
750
- return () => {
751
- observer.unsubscribe();
752
- };
753
- })
754
- };
755
- }
756
- const addLinkShortcut = {
757
- id: ShowDocHyperLinkEditPopupOperation.id,
758
- binding: _univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.KeyCode.K,
759
- description: "docs-hyper-link-ui.menu.tooltip",
760
- preconditions: _univerjs_docs_ui.whenDocAndEditorFocused
761
- };
762
-
763
- //#endregion
764
- //#region src/menu/schema.ts
765
- const menuSchema = {
766
- [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
767
- order: 1,
768
- menuItemFactory: AddHyperLinkMenuItemFactory
769
- } },
770
- [_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
771
- order: 20,
772
- menuItemFactory: AddHyperLinkMenuItemFactory
773
- } },
774
- [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
775
- order: 0,
776
- menuItemFactory: AddHyperLinkMenuItemFactory
777
- } } },
778
- [_univerjs_ui.ContextMenuPosition.PARAGRAPH]: {
779
- [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [_univerjs_docs_ui.INSERT_BELLOW_MENU_ID]: { [ShowDocHyperLinkEditPopupOperation.id]: {
780
- order: 6,
781
- menuItemFactory: AddHyperLinkMenuItemFactory
782
- } } },
783
- [_univerjs_docs_ui.EMPTY_PARAGRAPH_MENU_ID]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: { [ShowDocHyperLinkEditPopupOperation.id]: {
784
- order: 6,
785
- menuItemFactory: AddHyperLinkMenuItemFactory
786
- } } }
787
- }
788
- };
789
-
790
790
  //#endregion
791
791
  //#region src/controllers/ui.controller.ts
792
792
  let DocHyperLinkUIController = class DocHyperLinkUIController extends _univerjs_core.Disposable {
@@ -895,6 +895,7 @@ UniverDocsHyperLinkUIPlugin = __decorate([
895
895
  ], UniverDocsHyperLinkUIPlugin);
896
896
 
897
897
  //#endregion
898
+ exports.DocsHyperLinkUIMenuSchema = menuSchema;
898
899
  Object.defineProperty(exports, 'UniverDocsHyperLinkUIPlugin', {
899
900
  enumerable: true,
900
901
  get: function () {