@univerjs/docs-quick-insert-ui 0.25.0-insiders.20260623-012b5a8 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/lib/cjs/index.js +85 -103
- package/lib/es/index.js +89 -107
- package/lib/index.js +89 -107
- package/lib/types/controllers/{ui.controller.d.ts → doc-quick-insert-ui.controller.d.ts} +3 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/services/doc-quick-insert-popup.service.d.ts +2 -2
- package/lib/types/views/KeywordInputPlaceholder.d.ts +1 -1
- package/lib/types/views/QuickInsertButton.d.ts +1 -1
- package/lib/types/views/QuickInsertMenu.d.ts +6 -2
- package/lib/types/views/QuickInsertPlaceholder.d.ts +1 -1
- package/lib/types/views/QuickInsertPopup.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +14 -14
- package/lib/types/controllers/components.controller.d.ts +0 -24
- package/lib/types/locale/types.d.ts +0 -18
package/lib/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { CommandType, DeleteDirection, DependentOn, Direction, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RANGE_DIRECTION, UniverInstanceType, generateRandomId, merge, toDisposable } from "@univerjs/core";
|
|
2
|
-
import {
|
|
3
|
-
import { BulletListCommand, CutContentCommand, DeleteLeftCommand, DocCanvasPopManagerService, DocCreateTableOperation, DocEventManagerService, HorizontalLineCommand, IMEInputCommand, MoveCursorOperation, NodePositionConvertToCursor, OrderListCommand, getAnchorBounding } from "@univerjs/docs-ui";
|
|
4
|
-
import { ComponentManager, ILayoutService, IShortcutService,
|
|
2
|
+
import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from "@univerjs/docs";
|
|
3
|
+
import { BulletListCommand, CutContentCommand, DeleteCommand, DeleteLeftCommand, DocCanvasPopManagerService, DocCreateTableOperation, DocEventManagerService, HorizontalLineCommand, IMEInputCommand, InsertCommand, MoveCursorOperation, NodePositionConvertToCursor, OrderListCommand, getAnchorBounding } from "@univerjs/docs-ui";
|
|
4
|
+
import { ComponentManager, ILayoutService, IShortcutService, KeyCode, UniverUIPlugin, useDependency, useEvent, useObservable } from "@univerjs/ui";
|
|
5
5
|
import { IRenderManagerService, ptToPixel } from "@univerjs/engine-render";
|
|
6
6
|
import { BehaviorSubject, combineLatest, distinctUntilChanged, map, of, tap } from "rxjs";
|
|
7
|
-
import {
|
|
7
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { Tooltip, borderBottomClassName, borderClassName, clsx, scrollbarClassName } from "@univerjs/design";
|
|
10
10
|
import { InsertDocImageCommand, UniverDocsDrawingUIPlugin } from "@univerjs/docs-drawing-ui";
|
|
11
|
+
import { DividerIcon, IncreaseIcon, TextIcon } from "@univerjs/icons";
|
|
11
12
|
import { UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
|
|
12
13
|
import { UniverDrawingPlugin } from "@univerjs/drawing";
|
|
13
14
|
import { UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
|
|
14
|
-
import { DividerIcon, IncreaseIcon, TextIcon } from "@univerjs/icons";
|
|
15
15
|
|
|
16
16
|
//#region src/commands/commands/doc-quick-insert.command.ts
|
|
17
17
|
const DeleteSearchKeyCommand = {
|
|
@@ -98,33 +98,26 @@ function getQuickInsertMenuLeafCount(menus) {
|
|
|
98
98
|
return flattenMenuItems(menus).length;
|
|
99
99
|
}
|
|
100
100
|
function QuickInsertMenu(props) {
|
|
101
|
-
const { menus, focusedMenuIndex,
|
|
102
|
-
const iconManager = useDependency(IconManager);
|
|
101
|
+
const { menus, focusedMenuIndex, focusedMenuRef, menuNodeMapRef, componentManager, onFocusedMenuIndexChange, onSelect } = props;
|
|
103
102
|
const flatMenus = useMemo(() => flattenMenuItems(menus), [menus]);
|
|
104
|
-
const menuNodeMapRef = useRef(/* @__PURE__ */ new Map());
|
|
105
103
|
useEffect(() => {
|
|
106
104
|
var _flatMenus$focusedMen, _menuNodeMapRef$curre;
|
|
107
105
|
const focusedMenu = Number.isNaN(focusedMenuIndex) ? null : (_flatMenus$focusedMen = flatMenus[focusedMenuIndex]) !== null && _flatMenus$focusedMen !== void 0 ? _flatMenus$focusedMen : null;
|
|
108
|
-
|
|
106
|
+
focusedMenuRef.current = focusedMenu;
|
|
109
107
|
if (!focusedMenu) return;
|
|
110
108
|
(_menuNodeMapRef$curre = menuNodeMapRef.current.get(focusedMenu.id)) === null || _menuNodeMapRef$curre === void 0 || _menuNodeMapRef$curre.scrollIntoView({ block: "nearest" });
|
|
111
109
|
}, [
|
|
112
110
|
flatMenus,
|
|
113
111
|
focusedMenuIndex,
|
|
114
|
-
|
|
112
|
+
focusedMenuRef,
|
|
113
|
+
menuNodeMapRef
|
|
115
114
|
]);
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
const menuNodeMap = menuNodeMapRef.current;
|
|
118
|
-
return () => {
|
|
119
|
-
menuNodeMap.clear();
|
|
120
|
-
};
|
|
121
|
-
}, []);
|
|
122
115
|
const itemIndexRef = useRef(0);
|
|
123
116
|
itemIndexRef.current = 0;
|
|
124
117
|
function renderMenus(currentMenus) {
|
|
125
118
|
return currentMenus.map((menu, index) => {
|
|
126
119
|
const iconKey = menu.icon;
|
|
127
|
-
const Icon = iconKey ?
|
|
120
|
+
const Icon = iconKey ? componentManager.get(iconKey) : null;
|
|
128
121
|
if (isMenuGroup(menu)) return /* @__PURE__ */ jsxs("div", {
|
|
129
122
|
className: clsx("univer-grid univer-gap-1 univer-py-1", index !== currentMenus.length - 1 && borderBottomClassName),
|
|
130
123
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -185,6 +178,21 @@ function QuickInsertMenu(props) {
|
|
|
185
178
|
|
|
186
179
|
//#endregion
|
|
187
180
|
//#region src/views/QuickInsertPlaceholder.tsx
|
|
181
|
+
/**
|
|
182
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
183
|
+
*
|
|
184
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
185
|
+
* you may not use this file except in compliance with the License.
|
|
186
|
+
* You may obtain a copy of the License at
|
|
187
|
+
*
|
|
188
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
189
|
+
*
|
|
190
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
191
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
192
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
193
|
+
* See the License for the specific language governing permissions and
|
|
194
|
+
* limitations under the License.
|
|
195
|
+
*/
|
|
188
196
|
const QuickInsertPlaceholderComponentKey = "docs.quick.insert.placeholder";
|
|
189
197
|
const QuickInsertPlaceholder = () => {
|
|
190
198
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -256,9 +264,6 @@ const QuickInsertPopup = () => {
|
|
|
256
264
|
docQuickInsertPopupService.emitMenuSelected(menu);
|
|
257
265
|
commandService.executeCommand(CloseQuickInsertPopupOperation.id);
|
|
258
266
|
};
|
|
259
|
-
const handleFocusedMenuChange = useCallback((menu) => {
|
|
260
|
-
focusedMenuRef.current = menu;
|
|
261
|
-
}, []);
|
|
262
267
|
useEffect(() => {
|
|
263
268
|
/** Use up or down to navigate the focused menu instead of moving the cursor in documents. */
|
|
264
269
|
const disposableCollection = new DisposableCollection();
|
|
@@ -333,6 +338,12 @@ const QuickInsertPopup = () => {
|
|
|
333
338
|
useEffect(() => {
|
|
334
339
|
setFocusedMenuIndex(0);
|
|
335
340
|
}, [filteredMenus]);
|
|
341
|
+
const menuNodeMapRef = useRef(/* @__PURE__ */ new Map());
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
return () => {
|
|
344
|
+
menuNodeMapRef.current.clear();
|
|
345
|
+
};
|
|
346
|
+
}, []);
|
|
336
347
|
const hasMenus = filteredMenus.length > 0;
|
|
337
348
|
const Placeholder = (currentPopup === null || currentPopup === void 0 ? void 0 : currentPopup.popup.Placeholder) || componentManager.get(QuickInsertPlaceholder.componentKey);
|
|
338
349
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -340,8 +351,10 @@ const QuickInsertPopup = () => {
|
|
|
340
351
|
children: hasMenus ? /* @__PURE__ */ jsx(QuickInsertMenu, {
|
|
341
352
|
menus: filteredMenus,
|
|
342
353
|
focusedMenuIndex,
|
|
354
|
+
focusedMenuRef,
|
|
355
|
+
menuNodeMapRef,
|
|
356
|
+
componentManager,
|
|
343
357
|
onFocusedMenuIndexChange: setFocusedMenuIndex,
|
|
344
|
-
onFocusedMenuChange: handleFocusedMenuChange,
|
|
345
358
|
onSelect: handleMenuSelect
|
|
346
359
|
}) : Placeholder && /* @__PURE__ */ jsx(Placeholder, {})
|
|
347
360
|
});
|
|
@@ -349,7 +362,7 @@ const QuickInsertPopup = () => {
|
|
|
349
362
|
QuickInsertPopup.componentKey = "docs.quick.insert.popup";
|
|
350
363
|
|
|
351
364
|
//#endregion
|
|
352
|
-
//#region \0@oxc-project+runtime@0.
|
|
365
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
353
366
|
function _typeof(o) {
|
|
354
367
|
"@babel/helpers - typeof";
|
|
355
368
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -360,7 +373,7 @@ function _typeof(o) {
|
|
|
360
373
|
}
|
|
361
374
|
|
|
362
375
|
//#endregion
|
|
363
|
-
//#region \0@oxc-project+runtime@0.
|
|
376
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
364
377
|
function toPrimitive(t, r) {
|
|
365
378
|
if ("object" != _typeof(t) || !t) return t;
|
|
366
379
|
var e = t[Symbol.toPrimitive];
|
|
@@ -373,14 +386,14 @@ function toPrimitive(t, r) {
|
|
|
373
386
|
}
|
|
374
387
|
|
|
375
388
|
//#endregion
|
|
376
|
-
//#region \0@oxc-project+runtime@0.
|
|
389
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
377
390
|
function toPropertyKey(t) {
|
|
378
391
|
var i = toPrimitive(t, "string");
|
|
379
392
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
380
393
|
}
|
|
381
394
|
|
|
382
395
|
//#endregion
|
|
383
|
-
//#region \0@oxc-project+runtime@0.
|
|
396
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
384
397
|
function _defineProperty(e, r, t) {
|
|
385
398
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
386
399
|
value: t,
|
|
@@ -391,7 +404,7 @@ function _defineProperty(e, r, t) {
|
|
|
391
404
|
}
|
|
392
405
|
|
|
393
406
|
//#endregion
|
|
394
|
-
//#region \0@oxc-project+runtime@0.
|
|
407
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
395
408
|
function __decorateParam(paramIndex, decorator) {
|
|
396
409
|
return function(target, key) {
|
|
397
410
|
decorator(target, key, paramIndex);
|
|
@@ -399,7 +412,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
399
412
|
}
|
|
400
413
|
|
|
401
414
|
//#endregion
|
|
402
|
-
//#region \0@oxc-project+runtime@0.
|
|
415
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
403
416
|
function __decorate(decorators, target, key, desc) {
|
|
404
417
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
405
418
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -717,7 +730,7 @@ const builtInMenus = [{
|
|
|
717
730
|
imageMenu
|
|
718
731
|
]
|
|
719
732
|
}];
|
|
720
|
-
const builtInMenuCommandIds =
|
|
733
|
+
const builtInMenuCommandIds = new Set([
|
|
721
734
|
numberedListMenu.id,
|
|
722
735
|
bulletedListMenu.id,
|
|
723
736
|
dividerMenu.id,
|
|
@@ -749,7 +762,7 @@ let DocQuickInsertTriggerController = class DocQuickInsertTriggerController exte
|
|
|
749
762
|
const { _docQuickInsertPopupService, _textSelectionManagerService, _commandService } = this;
|
|
750
763
|
const documentDataModel = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
751
764
|
if (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDisabled()) return;
|
|
752
|
-
if (commandInfo.id ===
|
|
765
|
+
if (commandInfo.id === InsertCommand.id) {
|
|
753
766
|
const params = commandInfo.params;
|
|
754
767
|
if (_docQuickInsertPopupService.editPopup) {
|
|
755
768
|
_docQuickInsertPopupService.setInputOffset({
|
|
@@ -791,7 +804,7 @@ let DocQuickInsertTriggerController = class DocQuickInsertTriggerController exte
|
|
|
791
804
|
});
|
|
792
805
|
}
|
|
793
806
|
}
|
|
794
|
-
if (commandInfo.id ===
|
|
807
|
+
if (commandInfo.id === DeleteCommand.id) {
|
|
795
808
|
const params = commandInfo.params;
|
|
796
809
|
if (_docQuickInsertPopupService.editPopup && params.direction === DeleteDirection.LEFT) {
|
|
797
810
|
var _params$len;
|
|
@@ -828,53 +841,6 @@ DocQuickInsertTriggerController = __decorate([
|
|
|
828
841
|
__decorateParam(4, Inject(IUniverInstanceService))
|
|
829
842
|
], DocQuickInsertTriggerController);
|
|
830
843
|
|
|
831
|
-
//#endregion
|
|
832
|
-
//#region src/controllers/ui.controller.ts
|
|
833
|
-
let DocQuickInsertUIController = class DocQuickInsertUIController extends Disposable {
|
|
834
|
-
constructor(_commandService, _docQuickInsertPopupService) {
|
|
835
|
-
super();
|
|
836
|
-
this._commandService = _commandService;
|
|
837
|
-
this._docQuickInsertPopupService = _docQuickInsertPopupService;
|
|
838
|
-
this._initCommands();
|
|
839
|
-
this._initComponents();
|
|
840
|
-
this._initMenus();
|
|
841
|
-
}
|
|
842
|
-
_initCommands() {
|
|
843
|
-
[
|
|
844
|
-
DeleteSearchKeyCommand,
|
|
845
|
-
ShowQuickInsertPopupOperation,
|
|
846
|
-
CloseQuickInsertPopupOperation
|
|
847
|
-
].forEach((operation) => {
|
|
848
|
-
this.disposeWithMe(this._commandService.registerCommand(operation));
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
_initComponents() {
|
|
852
|
-
[{
|
|
853
|
-
keyword: "/",
|
|
854
|
-
menus$: of(builtInMenus),
|
|
855
|
-
preconditions: (params) => {
|
|
856
|
-
var _startNodePosition;
|
|
857
|
-
return ((_startNodePosition = params.range.startNodePosition) === null || _startNodePosition === void 0 ? void 0 : _startNodePosition.glyph) === 0;
|
|
858
|
-
}
|
|
859
|
-
}].forEach((popup) => {
|
|
860
|
-
this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(popup));
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
_initMenus() {}
|
|
864
|
-
};
|
|
865
|
-
DocQuickInsertUIController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(DocQuickInsertPopupService))], DocQuickInsertUIController);
|
|
866
|
-
|
|
867
|
-
//#endregion
|
|
868
|
-
//#region package.json
|
|
869
|
-
var name = "@univerjs/docs-quick-insert-ui";
|
|
870
|
-
var version = "0.25.0-insiders.20260623-012b5a8";
|
|
871
|
-
|
|
872
|
-
//#endregion
|
|
873
|
-
//#region src/config/config.ts
|
|
874
|
-
const DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY = "docs-quick-insert-ui.config";
|
|
875
|
-
const configSymbol = Symbol(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY);
|
|
876
|
-
const defaultPluginConfig = {};
|
|
877
|
-
|
|
878
844
|
//#endregion
|
|
879
845
|
//#region src/menu/doc-quick-insert-menu.controller.ts
|
|
880
846
|
let DocQuickInsertMenuController = class DocQuickInsertMenuController extends Disposable {
|
|
@@ -981,48 +947,66 @@ const QuickInsertButton = ({ className = "" }) => {
|
|
|
981
947
|
QuickInsertButton.componentKey = QuickInsertButtonComponentKey;
|
|
982
948
|
|
|
983
949
|
//#endregion
|
|
984
|
-
//#region src/controllers/
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
*
|
|
988
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
989
|
-
* you may not use this file except in compliance with the License.
|
|
990
|
-
* You may obtain a copy of the License at
|
|
991
|
-
*
|
|
992
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
993
|
-
*
|
|
994
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
995
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
996
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
997
|
-
* See the License for the specific language governing permissions and
|
|
998
|
-
* limitations under the License.
|
|
999
|
-
*/
|
|
1000
|
-
let ComponentsController = class ComponentsController extends Disposable {
|
|
1001
|
-
constructor(_componentManager, _iconManager) {
|
|
950
|
+
//#region src/controllers/doc-quick-insert-ui.controller.ts
|
|
951
|
+
let DocQuickInsertUIController = class DocQuickInsertUIController extends Disposable {
|
|
952
|
+
constructor(_commandService, _docQuickInsertPopupService, _componentManager) {
|
|
1002
953
|
super();
|
|
954
|
+
this._commandService = _commandService;
|
|
955
|
+
this._docQuickInsertPopupService = _docQuickInsertPopupService;
|
|
1003
956
|
this._componentManager = _componentManager;
|
|
1004
|
-
this.
|
|
1005
|
-
this.
|
|
1006
|
-
this.
|
|
957
|
+
this._initCommands();
|
|
958
|
+
this._initComponents();
|
|
959
|
+
this._initMenus();
|
|
1007
960
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
961
|
+
_initCommands() {
|
|
962
|
+
[
|
|
963
|
+
DeleteSearchKeyCommand,
|
|
964
|
+
ShowQuickInsertPopupOperation,
|
|
965
|
+
CloseQuickInsertPopupOperation
|
|
966
|
+
].forEach((operation) => {
|
|
967
|
+
this.disposeWithMe(this._commandService.registerCommand(operation));
|
|
968
|
+
});
|
|
1013
969
|
}
|
|
1014
|
-
|
|
970
|
+
_initComponents() {
|
|
1015
971
|
[
|
|
1016
972
|
[QuickInsertPopup.componentKey, QuickInsertPopup],
|
|
1017
973
|
[KeywordInputPlaceholder.componentKey, KeywordInputPlaceholder],
|
|
1018
974
|
[QuickInsertPlaceholder.componentKey, QuickInsertPlaceholder],
|
|
975
|
+
[DividerIcon.displayName, DividerIcon],
|
|
976
|
+
[TextIcon.displayName, TextIcon],
|
|
1019
977
|
[QuickInsertButton.componentKey, QuickInsertButton]
|
|
1020
978
|
].forEach(([key, comp]) => {
|
|
1021
979
|
if (key) this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1022
980
|
});
|
|
981
|
+
[{
|
|
982
|
+
keyword: "/",
|
|
983
|
+
menus$: of(builtInMenus),
|
|
984
|
+
preconditions: (params) => {
|
|
985
|
+
var _startNodePosition;
|
|
986
|
+
return ((_startNodePosition = params.range.startNodePosition) === null || _startNodePosition === void 0 ? void 0 : _startNodePosition.glyph) === 0;
|
|
987
|
+
}
|
|
988
|
+
}].forEach((popup) => {
|
|
989
|
+
this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(popup));
|
|
990
|
+
});
|
|
1023
991
|
}
|
|
992
|
+
_initMenus() {}
|
|
1024
993
|
};
|
|
1025
|
-
|
|
994
|
+
DocQuickInsertUIController = __decorate([
|
|
995
|
+
__decorateParam(0, ICommandService),
|
|
996
|
+
__decorateParam(1, Inject(DocQuickInsertPopupService)),
|
|
997
|
+
__decorateParam(2, Inject(ComponentManager))
|
|
998
|
+
], DocQuickInsertUIController);
|
|
999
|
+
|
|
1000
|
+
//#endregion
|
|
1001
|
+
//#region package.json
|
|
1002
|
+
var name = "@univerjs/docs-quick-insert-ui";
|
|
1003
|
+
var version = "0.25.1";
|
|
1004
|
+
|
|
1005
|
+
//#endregion
|
|
1006
|
+
//#region src/config/config.ts
|
|
1007
|
+
const DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY = "docs-quick-insert-ui.config";
|
|
1008
|
+
const configSymbol = Symbol(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY);
|
|
1009
|
+
const defaultPluginConfig = {};
|
|
1026
1010
|
|
|
1027
1011
|
//#endregion
|
|
1028
1012
|
//#region src/plugin.ts
|
|
@@ -1038,8 +1022,6 @@ let UniverDocsQuickInsertUIPlugin = class UniverDocsQuickInsertUIPlugin extends
|
|
|
1038
1022
|
this._configService.setConfig(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY, rest);
|
|
1039
1023
|
}
|
|
1040
1024
|
onStarting() {
|
|
1041
|
-
this._injector.add([ComponentsController]);
|
|
1042
|
-
this._injector.get(ComponentsController);
|
|
1043
1025
|
[
|
|
1044
1026
|
[DocQuickInsertUIController],
|
|
1045
1027
|
[DocQuickInsertTriggerController],
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Disposable, ICommandService } from '@univerjs/core';
|
|
17
|
+
import { ComponentManager } from '@univerjs/ui';
|
|
17
18
|
import { DocQuickInsertPopupService } from '../services/doc-quick-insert-popup.service';
|
|
18
19
|
export declare class DocQuickInsertUIController extends Disposable {
|
|
19
20
|
private readonly _commandService;
|
|
20
21
|
private readonly _docQuickInsertPopupService;
|
|
21
|
-
|
|
22
|
+
private readonly _componentManager;
|
|
23
|
+
constructor(_commandService: ICommandService, _docQuickInsertPopupService: DocQuickInsertPopupService, _componentManager: ComponentManager);
|
|
22
24
|
private _initCommands;
|
|
23
25
|
private _initComponents;
|
|
24
26
|
private _initMenus;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import './global.css';
|
|
17
17
|
export type { IUniverDocsQuickInsertUIConfig } from './config/config';
|
|
18
18
|
export { DocQuickInsertTriggerController } from './controllers/doc-quick-insert-trigger.controller';
|
|
19
|
-
export { DocQuickInsertUIController } from './controllers/ui.controller';
|
|
19
|
+
export { DocQuickInsertUIController } from './controllers/doc-quick-insert-ui.controller';
|
|
20
20
|
export { UniverDocsQuickInsertUIPlugin } from './plugin';
|
|
21
21
|
export type { DocPopupMenu, IDocPopup, IDocPopupGroupItem, IDocPopupMenuItem } from './services/doc-quick-insert-popup.service';
|
|
22
22
|
export { DocQuickInsertPopupService } from './services/doc-quick-insert-popup.service';
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { IDisposable, Nullable } from '@univerjs/core';
|
|
17
|
-
import type {
|
|
17
|
+
import type { IInsertCommandParams } from '@univerjs/docs-ui';
|
|
18
18
|
import type { Observable } from 'rxjs';
|
|
19
19
|
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
20
20
|
import { DocSelectionManagerService } from '@univerjs/docs';
|
|
@@ -37,7 +37,7 @@ export interface IDocPopup {
|
|
|
37
37
|
keyword: string;
|
|
38
38
|
menus$: Observable<DocPopupMenu[]>;
|
|
39
39
|
Placeholder?: React.ComponentType;
|
|
40
|
-
preconditions?: (params:
|
|
40
|
+
preconditions?: (params: IInsertCommandParams) => boolean;
|
|
41
41
|
}
|
|
42
42
|
export declare class DocQuickInsertPopupService extends Disposable {
|
|
43
43
|
private readonly _docCanvasPopupManagerService;
|
|
@@ -27,7 +27,7 @@ interface IKeywordInputPlaceholderExtraProps {
|
|
|
27
27
|
export declare const KeywordInputPlaceholder: {
|
|
28
28
|
({ popup }: {
|
|
29
29
|
popup: IPopup<IKeywordInputPlaceholderExtraProps>;
|
|
30
|
-
}): import("react").JSX.Element;
|
|
30
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
31
31
|
componentKey: string;
|
|
32
32
|
};
|
|
33
33
|
export {};
|
|
@@ -17,6 +17,6 @@ export declare const QuickInsertButtonComponentKey = "doc.quick-insert.button";
|
|
|
17
17
|
export declare const QuickInsertButton: {
|
|
18
18
|
({ className }: {
|
|
19
19
|
className?: string;
|
|
20
|
-
}): import("react").JSX.Element;
|
|
20
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
21
21
|
componentKey: string;
|
|
22
22
|
};
|
|
@@ -13,14 +13,18 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import type { ComponentManager } from '@univerjs/ui';
|
|
17
|
+
import type { MutableRefObject } from 'react';
|
|
16
18
|
import type { DocPopupMenu, IDocPopupMenuItem } from '../services/doc-quick-insert-popup.service';
|
|
17
19
|
interface IQuickInsertMenuProps {
|
|
18
20
|
menus: DocPopupMenu[];
|
|
19
21
|
focusedMenuIndex: number;
|
|
22
|
+
focusedMenuRef: MutableRefObject<IDocPopupMenuItem | null>;
|
|
23
|
+
menuNodeMapRef: MutableRefObject<Map<string, HTMLElement>>;
|
|
24
|
+
componentManager: ComponentManager;
|
|
20
25
|
onFocusedMenuIndexChange: (index: number) => void;
|
|
21
|
-
onFocusedMenuChange: (menu: IDocPopupMenuItem | null) => void;
|
|
22
26
|
onSelect: (menu: IDocPopupMenuItem) => void;
|
|
23
27
|
}
|
|
24
28
|
export declare function getQuickInsertMenuLeafCount(menus: DocPopupMenu[]): number;
|
|
25
|
-
export declare function QuickInsertMenu(props: IQuickInsertMenuProps): import("react").JSX.Element;
|
|
29
|
+
export declare function QuickInsertMenu(props: IQuickInsertMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
26
30
|
export {};
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const QuickInsertPlaceholderComponentKey = "docs.quick.insert.placeholder";
|
|
17
17
|
export declare const QuickInsertPlaceholder: {
|
|
18
|
-
(): import("react").JSX.Element;
|
|
18
|
+
(): import("react/jsx-runtime").JSX.Element;
|
|
19
19
|
componentKey: string;
|
|
20
20
|
};
|
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"),require("@univerjs/docs-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("rxjs"),require("react"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/docs-drawing-ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`,`@univerjs/design`,`@univerjs/docs-drawing-ui`,`@univerjs/docs-drawing`,`@univerjs/drawing`,`@univerjs/drawing-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsQuickInsertUi={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React,e.UniverDesign,e.UniverDocsDrawingUi,e.UniverDocsDrawing,e.UniverDrawing,e.UniverDrawingUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m={id:`doc.command.delete-search-key`,type:t.CommandType.COMMAND,handler:(e,n)=>{let i=e.get(t.ICommandService),{start:a,end:o}=n;return i.syncExecuteCommand(r.CutContentCommand.id,{segmentId:``,textRanges:[{startOffset:a,endOffset:a,collapsed:!0}],selections:[{startOffset:a,endOffset:o,collapsed:!1,direction:t.RANGE_DIRECTION.FORWARD}]})}},h=`docs.quick.insert.keyword-input-placeholder`;function g(e,t){if(typeof document>`u`)return e.length*11;let n=document.createElement(`canvas`).getContext(`2d`);return n?(n.font=t,Math.ceil(n.measureText(e).width)):e.length*11}let _=({popup:e})=>{var n,r,o,l,u,d,f,p,m,h,_;let v=(0,i.useDependency)(t.LocaleService).t(`docs-quick-insert-ui.keywordInputPlaceholder`),y=(0,a.ptToPixel)((n=(r=e.extraProps)==null?void 0:r.fontSize)==null?11:n),b=(o=(l=e.extraProps)==null?void 0:l.fontString)==null?`${y}px sans-serif`:o,x=(u=(d=e.extraProps)==null?void 0:d.ascent)==null?y:u,S=Math.max((f=(p=e.extraProps)==null?void 0:p.contentHeight)==null?y:f,y),C=(0,s.useMemo)(()=>g(v,b),[b,v]);return(0,c.jsx)(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:(0,c.jsx)(`svg`,{width:C,height:S,viewBox:`0 0 ${C} ${S}`,style:{overflow:`visible`,display:`block`},children:(0,c.jsx)(`text`,{x:0,y:x,fill:`currentColor`,style:{font:b,fontFamily:(m=e.extraProps)==null?void 0:m.fontFamily,fontStyle:(h=e.extraProps)==null?void 0:h.fontStyle,fontWeight:(_=e.extraProps)==null?void 0:_.fontWeight},children:v})})})};_.componentKey=h;function v(e){return`children`in e}function y(e){return e.flatMap(e=>v(e)?y(e.children):e)}function b(e){return y(e).length}function x(e){let{menus:t,focusedMenuIndex:n,onFocusedMenuIndexChange:r,onFocusedMenuChange:a,onSelect:o}=e,u=(0,i.useDependency)(i.IconManager),d=(0,s.useMemo)(()=>y(t),[t]),f=(0,s.useRef)(new Map);(0,s.useEffect)(()=>{var e,t;let r=Number.isNaN(n)||(e=d[n])==null?null:e;a(r),r&&((t=f.current.get(r.id))==null||t.scrollIntoView({block:`nearest`}))},[d,n,a]),(0,s.useEffect)(()=>{let e=f.current;return()=>{e.clear()}},[]);let p=(0,s.useRef)(0);p.current=0;function m(e){return e.map((t,i)=>{let a=t.icon,s=a?u.get(a):null;if(v(t))return(0,c.jsxs)(`div`,{className:(0,l.clsx)(`univer-grid univer-gap-1 univer-py-1`,i!==e.length-1&&l.borderBottomClassName),children:[(0,c.jsxs)(`div`,{className:`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2 univer-text-xs univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-300`,children:[s&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(s,{})}),(0,c.jsx)(`span`,{children:t.title})]}),(0,c.jsx)(`div`,{className:`univer-grid univer-gap-1`,children:m(t.children)})]},t.id);let d=p.current,h=n===d;return p.current+=1,(0,c.jsx)(`div`,{ref:e=>{if(e){f.current.set(t.id,e);return}f.current.delete(t.id)},role:`button`,tabIndex:-1,className:(0,l.clsx)(`univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900 univer-outline-none hover:univer-bg-gray-50 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,{"hover:univer-bg-transparent":!h,"univer-bg-gray-50 dark:!univer-bg-gray-600":h}),onMouseEnter:()=>r(d),onMouseLeave:()=>r(NaN),onClick:()=>o(t),children:(0,c.jsxs)(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[s&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(s,{})}),(0,c.jsx)(l.Tooltip,{showIfEllipsis:!0,title:t.title,placement:`right`,children:(0,c.jsx)(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return(0,c.jsx)(`div`,{className:(0,l.clsx)(`univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2 univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white`,l.borderClassName,l.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:m(t)})}let S=`docs.quick.insert.placeholder`,C=()=>(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg`,children:(0,c.jsx)(`span`,{children:(0,i.useDependency)(t.LocaleService).t(`docs-quick-insert-ui.placeholder`)})});C.componentKey=S;function w(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=w(e.children,t),e.children.length>0;let n=e.keywords;return n?n.some(e=>e.includes(t)):e.title.toLowerCase().includes(t)})}function ee(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=ee(n.children,t)),n.title=t.t(n.title),`keywords`in n&&(n.keywords=n.keywords.concat(n.title).map(e=>e.toLowerCase())),n})}let te=[i.KeyCode.ARROW_UP,i.KeyCode.ARROW_DOWN,i.KeyCode.ENTER],T=()=>{let e=(0,i.useDependency)(t.LocaleService),n=(0,i.useDependency)(N),r=(0,i.useDependency)(i.ComponentManager),a=(0,i.useDependency)(i.IShortcutService),o=(0,i.useDependency)(t.ICommandService),l=(0,s.useMemo)(()=>(0,t.generateRandomId)(),[]),[u,d]=(0,s.useState)(0),f=(0,s.useRef)(null),p=(0,i.useObservable)(n.filterKeyword$,``),m=(0,i.useObservable)(n.editPopup$),h=(0,i.useObservable)(m==null?void 0:m.popup.menus$,[]),g=(0,s.useMemo)(()=>ee(h,e),[h]),[_,v]=(0,s.useState)(()=>w(g,p.toLowerCase())),y=(0,s.useMemo)(()=>b(_),[_]),S=(0,s.useRef)(y);(0,s.useEffect)(()=>{S.current=y},[y]),(0,s.useEffect)(()=>{let e=requestIdleCallback(()=>{v(w(g,p.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[g,p]);let T=e=>{n.emitMenuSelected(e),o.executeCommand(F.id)},E=(0,s.useCallback)(e=>{f.current=e},[]);(0,s.useEffect)(()=>{let e=new t.DisposableCollection;a.getAllShortcuts().filter(e=>e.binding&&te.includes(e.binding)).forEach(n=>{let r=n.preconditions;n.preconditions=()=>!1,e.add((0,t.toDisposable)(()=>{n.preconditions=r}))});let n={id:`quick.insert.popup.enter.${l}`,type:t.CommandType.OPERATION,handler:()=>{let e=f.current;e&&T(e)}},r={id:`quick.insert.popup.move.cursor.up.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e-1;return t>=0?t:S.current-1})}},s={id:`quick.insert.popup.move.cursor.down.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e+1;return t<=S.current-1?t:0})}};return e.add(o.registerCommand(r)),e.add(o.registerCommand(s)),e.add(o.registerCommand(n)),e.add(a.registerShortcut({priority:1e3,id:r.id,binding:i.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:t.Direction.UP}})),e.add(a.registerShortcut({priority:1e3,id:s.id,binding:i.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:t.Direction.DOWN}})),e.add(a.registerShortcut({priority:1e3,id:n.id,binding:i.KeyCode.ENTER,preconditions:()=>!0})),()=>{e.dispose()}},[o,l,a]),(0,s.useEffect)(()=>{d(0)},[_]);let D=_.length>0,O=(m==null?void 0:m.popup.Placeholder)||r.get(C.componentKey);return(0,c.jsx)(`div`,{className:`univer-mt-2`,children:D?(0,c.jsx)(x,{menus:_,focusedMenuIndex:u,onFocusedMenuIndexChange:d,onFocusedMenuChange:E,onSelect:T}):O&&(0,c.jsx)(O,{})})};T.componentKey=`docs.quick.insert.popup`;function E(e){"@babel/helpers - typeof";return E=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},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(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 M={dispose:()=>{}},N=class extends t.Disposable{get popups(){return Array.from(this._popups)}get editPopup(){return this._editPopup$.value}get isComposing(){return this._isComposing$.value}setIsComposing(e){this._isComposing$.next(e)}get inputOffset(){return this._inputOffset$.value}setInputOffset(e){this._inputOffset$.next(e)}getDocEventManagerService(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(r.DocEventManagerService)}constructor(e,n,r,i,a){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=i,this._docSelectionManagerService=a,k(this,`_popups`,new Set),k(this,`_editPopup$`,new o.BehaviorSubject(void 0)),k(this,`editPopup$`,this._editPopup$.asObservable()),k(this,`_isComposing$`,new o.BehaviorSubject(!1)),k(this,`isComposing$`,this._isComposing$.asObservable()),k(this,`_inputOffset$`,new o.BehaviorSubject({start:0,end:0})),k(this,`inputOffset$`,this._inputOffset$.asObservable()),k(this,`filterKeyword$`,void 0),k(this,`_menuSelectedCallbacks`,new Set),k(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let s=(e,n)=>{var r;return(r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null||(r=r.getBody())==null?void 0:r.dataStream.slice(e,n)},c=``;this.filterKeyword$=this._inputOffset$.pipe((0,o.map)(e=>{var t;let n=s(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),(0,o.distinctUntilChanged)(),(0,o.tap)(e=>{c=e})),this.disposeWithMe((0,o.combineLatest)([this.filterKeyword$.pipe((0,o.tap)(e=>{if(e.length>0){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;(n=this._inputPlaceholderRenderRoot)==null||n.mount()}})),this.isComposing$.pipe((0,o.tap)(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;c.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe((0,o.tap)(e=>{if(!e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose(),this._inputPlaceholderRenderRoot=null}}))]).subscribe())}resolvePopup(e){return Array.from(this._popups).find(t=>t.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{isMounted:!1,mount(){if(this.isMounted)return;this.isMounted=!0;let t=e();this.unmount={dispose:()=>{t.dispose(),this.isMounted=!1}}}}}_getParagraphBound(e,t){var n,r;let i=this._univerInstanceService.getUnit(e),a=i==null||(n=i.getBody())==null||(n=n.paragraphs)==null?void 0:n.find(e=>e.startIndex>t);if(!a)return null;let o=this.getDocEventManagerService(e);return(r=o==null?void 0:o.findParagraphBoundByIndex(a.startIndex))==null?null:r}_getKeywordPlaceholderAnchorRect(e,t,n,i){let a=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!a)return i;let o=e.getOffsetConfig(),{contentBoxPointGroup:s}=new r.NodePositionConvertToCursor(o,t).getRangePointData(a,a);if(s.length===0)return i;let c=(0,r.getAnchorBounding)(s),l=c.left+o.docsLeft,u=c.top+o.docsTop;return{left:l,right:l,top:u,bottom:u+c.height}}_getKeywordPlaceholderExtraProps(e){var t,n,r,i,a,o,s,c,l,u,d,f,p;return{fontSize:(t=e.ts)==null?void 0:t.fs,fontString:(n=e.fontStyle)==null?void 0:n.fontString,fontFamily:(r=(i=(a=e.fontStyle)==null?void 0:a.fontFamily)==null?(o=e.ts)==null?void 0:o.ff:i)==null?void 0:r,fontStyle:(s=e.ts)!=null&&s.it?`italic`:`normal`,fontWeight:(c=e.ts)!=null&&c.bl?`bold`:`normal`,ascent:(l=e.bBox)==null?void 0:l.ba,contentHeight:((u=(d=e.bBox)==null?void 0:d.ba)==null?0:u)+((f=(p=e.bBox)==null?void 0:p.bd)==null?0:f)||void 0}}_mountInputPlaceholder(e,t){let r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(n.DocSkeletonManagerService),a=this._docSelectionManagerService.getActiveTextRange();if(!r||!i||!a)return M;let o=i.getSkeleton(),s=o.findNodeByCharIndex(a.startOffset,a.segmentId,a.segmentPage);if((s==null?void 0:s.content)!==`\r`||!s)return M;let c=r.mainComponent,l=this._getKeywordPlaceholderAnchorRect(c,o,a,t),u=this._getKeywordPlaceholderExtraProps(s),d=this._docCanvasPopupManagerService.attachPopupToRect(l,{componentKey:_.componentKey,extraProps:u,onClickOutside:()=>{d.dispose()},direction:`horizontal`},e);return d}showPopup(e){let{popup:t,index:n,unitId:r}=e;this.closePopup();let i=this._getParagraphBound(r,n);if(!i)return;this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>this._mountInputPlaceholder(r,i.firstLine)),this._inputPlaceholderRenderRoot.mount();let a=this._docCanvasPopupManagerService.attachPopupToRect(i.firstLine,{componentKey:T.componentKey,onClickOutside:()=>{this.closePopup()},direction:`bottom`},r);this._editPopup$.next({disposable:a,popup:t,anchor:n,unitId:r})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){let{start:t,end:n}=this.inputOffset;this._commandService.syncExecuteCommand(m.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};N=j([A(0,(0,t.Inject)(r.DocCanvasPopManagerService)),A(1,(0,t.Inject)(t.IUniverInstanceService)),A(2,(0,t.Inject)(t.ICommandService)),A(3,(0,t.Inject)(a.IRenderManagerService)),A(4,(0,t.Inject)(n.DocSelectionManagerService))],N);let P={type:t.CommandType.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(N);return t?(n.showPopup(t),!0):!1}},F={type:t.CommandType.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(N).closePopup(),!0}},ne={id:`quick-insert.text.menu`,title:`docs-quick-insert-ui.menu.text`,icon:`TextIcon`,keywords:[`text`]},I={id:r.OrderListCommand.id,title:`docs-quick-insert-ui.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},L={id:r.BulletListCommand.id,title:`docs-quick-insert-ui.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},R={id:r.HorizontalLineCommand.id,title:`docs-quick-insert-ui.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},z={id:r.DocCreateTableOperation.id,title:`docs-quick-insert-ui.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},B={id:u.InsertDocImageCommand.id,title:`docs-quick-insert-ui.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},re=[{title:`docs-quick-insert-ui.group.basics`,id:`quick.insert.group.basic`,children:[ne,I,L,R,z,B]}],ie=new Set([I.id,L.id,R.id,z.id,B.id]),V=class extends t.Disposable{constructor(e,t,n,r,a){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=a,this.disposeWithMe(this._shortcutService.registerShortcut({id:F.id,binding:i.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:i,_textSelectionManagerService:a,_commandService:o}=this,s=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(e.id===n.InsertTextCommand.id){let t=e.params;if(i.editPopup){i.setInputOffset({start:i.inputOffset.start,end:t.range.endOffset+1});return}let n=a.getActiveTextRange();if(!n)return;let r=i.resolvePopup(t.body.dataStream);if(!r||!(!r.preconditions||r.preconditions(t)))return;i.setInputOffset({start:n.startOffset-1,end:n.startOffset}),setTimeout(()=>{o.executeCommand(P.id,{index:n.startOffset-1,unitId:t.unitId,popup:r})},100)}if(e.id===r.IMEInputCommand.id){let t=e.params;!i.isComposing&&t.isCompositionStart&&i.setIsComposing(!0),i.isComposing&&t.isCompositionEnd&&i.setIsComposing(!1)}if(e.id===n.RichTextEditingMutation.id){let t=e.params;if(t.isCompositionEnd){var c;let e=(c=t.textRanges)==null||(c=c[0])==null?void 0:c.endOffset;e&&i.setInputOffset({start:i.inputOffset.start,end:e})}}if(e.id===n.DeleteTextCommand.id){let n=e.params;if(i.editPopup&&n.direction===t.DeleteDirection.LEFT){var l;let e=(l=n.len)==null?0:l;i.setInputOffset({start:i.inputOffset.start,end:n.range.endOffset-e})}}if(e.id===r.MoveCursorOperation.id){let n=e.params;(n.direction===t.Direction.LEFT||n.direction===t.Direction.RIGHT)&&i.editPopup&&o.executeCommand(F.id)}if(e.id===r.DeleteLeftCommand.id){let e=a.getActiveTextRange();if(!i.editPopup||!e)return;e.endOffset<=i.editPopup.anchor&&o.executeCommand(F.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==ne.id&&ie.has(e.id)&&this._commandService.executeCommand(e.id)}))}};V=j([A(0,t.ICommandService),A(1,(0,t.Inject)(n.DocSelectionManagerService)),A(2,(0,t.Inject)(N)),A(3,(0,t.Inject)(i.IShortcutService)),A(4,(0,t.Inject)(t.IUniverInstanceService))],V);let H=class extends t.Disposable{constructor(e,t){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[m,P,F].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[{keyword:`/`,menus$:(0,o.of)(re),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};H=j([A(0,t.ICommandService),A(1,(0,t.Inject)(N))],H);var ae=`@univerjs/docs-quick-insert-ui`,oe=`0.25.0-insiders.20260623-012b5a8`;let U={};function W({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${le()}`);return G(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function G(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...se(e,n,i),...r},(ce(e,n).children||[]).map((r,a)=>G(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function se(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 ce(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 le(){return Math.random().toString(36).substring(2,8)}W.displayName=`UniverIcon`;let ue={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:`M1.01953 3.13985C1.01953 2.77258 1.31726 2.47485 1.68453 2.47485H2.73713C3.1044 2.47485 3.40213 2.77258 3.40213 3.13985C3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.17734 3.13985C4.17734 2.77258 4.47507 2.47485 4.84234 2.47485H6.94754C7.31481 2.47485 7.61254 2.77258 7.61254 3.13985C7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.38775 3.13985C8.38775 2.77258 8.68548 2.47485 9.05275 2.47485H11.158C11.5252 2.47485 11.823 2.77258 11.823 3.13985C11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.5982 3.13985C12.5982 2.77258 12.8959 2.47485 13.2632 2.47485H14.3158C14.683 2.47485 14.9808 2.77258 14.9808 3.13985C14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.01953 7.99972C1.01953 7.63245 1.31726 7.33472 1.68453 7.33472H14.3158C14.683 7.33472 14.9808 7.63245 14.9808 7.99972C14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601C1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601C3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601C4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601C7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601C8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601C11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601C12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601C14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632Z`}}]},K=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(W,Object.assign({},e,{id:`divider-icon`,ref:t,icon:ue}))});K.displayName=`DividerIcon`;let de={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:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},q=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(W,Object.assign({},e,{id:`increase-icon`,ref:t,icon:de}))});q.displayName=`IncreaseIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{fill:`currentColor`,clipPath:`url(#text-icon_clip0_1293_26)`},children:[{tag:`path`,attrs:{d:`M2.22891 2.07227C1.89754 2.07227 1.62891 2.34089 1.62891 2.67227C1.62891 3.00364 1.89754 3.27227 2.22891 3.27227H6.29541V14.0056C6.29541 14.337 6.56404 14.6056 6.89541 14.6056C7.22678 14.6056 7.49541 14.337 7.49541 14.0056V3.27227H11.5622C11.8936 3.27227 12.1622 3.00364 12.1622 2.67227C12.1622 2.34089 11.8936 2.07227 11.5622 2.07227H2.22891Z`}},{tag:`path`,attrs:{d:`M10.2289 6.40552C9.89754 6.40552 9.62891 6.67415 9.62891 7.00552C9.62891 7.33689 9.89754 7.60552 10.2289 7.60552H12.2954V14.0055C12.2954 14.3369 12.564 14.6055 12.8954 14.6055C13.2268 14.6055 13.4954 14.3369 13.4954 14.0055V7.60552H15.5622C15.8936 7.60552 16.1622 7.33689 16.1622 7.00552C16.1622 6.67415 15.8936 6.40552 15.5622 6.40552H10.2289Z`}}]},{tag:`defs`,attrs:{},children:[{tag:`clipPath`,attrs:{id:`text-icon_clip0_1293_26`},children:[{tag:`path`,attrs:{fill:`white`,d:`M0 0H16V16H0z`,transform:`translate(.9)`}}]}]}],defIds:[`text-icon_clip0_1293_26`]},J=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(W,Object.assign({},e,{id:`text-icon`,ref:t,icon:fe}))});J.displayName=`TextIcon`;let Y=class extends t.Disposable{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,k(this,`_popup$`,new o.BehaviorSubject(null)),k(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe((0,o.combineLatest)([this._docEventManagerService.hoverParagraphLeftRealTime$,this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([e,t])=>{let n=e==null?t:e,r=this._context.unit.getDisabled();if(!n||r){this._hideMenu(!0);return}if(n.paragraphStart===n.paragraphEnd){var i;if(this._docQuickInsertPopupService.editPopup||n.startIndex===((i=this.popup)==null?void 0:i.startIndex))return;this._hideMenu(!0);let e=this._docCanvasPopManagerService.attachPopupToRect(n.firstLine,{componentKey:X,direction:`left-center`},this._context.unit.getUnitId());this._popup$.next({startIndex:n.startIndex,disposable:e})}else this._hideMenu(!0)}))}_hideMenu(e){this._docQuickInsertPopupService.editPopup||this.popup&&(e||this.popup.disposable.canDispose())&&(this.popup.disposable.dispose(),this._popup$.next(null))}};Y=j([A(1,(0,t.Inject)(r.DocEventManagerService)),A(2,(0,t.Inject)(N)),A(3,(0,t.Inject)(r.DocCanvasPopManagerService))],Y);let X=`doc.quick-insert.button`,Z=({className:e=``})=>{let r=(0,i.useDependency)(N),u=(0,i.useDependency)(t.IUniverInstanceService),d=(0,i.useDependency)(a.IRenderManagerService),f=(0,i.useObservable)((0,s.useMemo)(()=>u.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC),[u])),p=f&&d.getRenderById(f.getUnitId()),m=p==null?void 0:p.with(Y),h=(0,i.useDependency)(i.ILayoutService),g=(0,i.useDependency)(n.DocSelectionManagerService),_=(0,i.useObservable)(r.editPopup$),v=(0,i.useEvent)(()=>{var e;let t=m==null?void 0:m.popup;if(!t)return;let n=r.popups,i={keyword:``,menus$:(0,o.combineLatest)(n.map(e=>e.menus$)).pipe((0,o.map)(e=>e.flat()))};g.replaceDocRanges([{startOffset:t.startIndex,endOffset:t.startIndex}]),r.setInputOffset({start:t.startIndex-1,end:t.startIndex-1}),r.showPopup({popup:i,index:t.startIndex-1,unitId:(e=f==null?void 0:f.getUnitId())==null?``:e}),setTimeout(()=>{h.focus()})});return(0,c.jsx)(`div`,{className:(0,l.clsx)(`univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full univer-p-1.5 univer-shadow-sm hover:univer-bg-gray-100 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-700`,l.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":_,"univer-bg-white dark:!univer-bg-gray-900":!_},e),role:`button`,tabIndex:0,onClick:v,children:(0,c.jsx)(q,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};Z.componentKey=X;let Q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerIcons(),this._registerComponents()}_registerIcons(){this.disposeWithMe(this._iconManager.register({DividerIcon:K,TextIcon:J}))}_registerComponents(){[[T.componentKey,T],[_.componentKey,_],[C.componentKey,C],[Z.componentKey,Z]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))})}};Q=j([A(0,(0,t.Inject)(i.ComponentManager)),A(1,(0,t.Inject)(i.IconManager))],Q);let $=class extends t.Plugin{constructor(e=U,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},U,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-quick-insert-ui.config`,o)}onStarting(){this._injector.add([Q]),this._injector.get(Q),[[H],[V],[N]].forEach(e=>this._injector.add(e)),this._injector.get(H)}onRendered(){this._injector.get(V),this._injector.get(N),[[Y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};k($,`type`,t.UniverInstanceType.UNIVER_DOC),k($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),k($,`packageName`,ae),k($,`version`,oe),$=j([(0,t.DependentOn)(p.UniverDrawingUIPlugin,f.UniverDrawingPlugin,u.UniverDocsDrawingUIPlugin,d.UniverDocsDrawingPlugin,i.UniverUIPlugin),A(1,(0,t.Inject)(t.Injector)),A(2,(0,t.Inject)(a.IRenderManagerService)),A(3,t.IConfigService)],$),Object.defineProperty(e,"DocQuickInsertPopupService",{enumerable:!0,get:function(){return N}}),Object.defineProperty(e,"DocQuickInsertTriggerController",{enumerable:!0,get:function(){return V}}),Object.defineProperty(e,"DocQuickInsertUIController",{enumerable:!0,get:function(){return H}}),e.KeywordInputPlaceholderComponentKey=h,e.QuickInsertPlaceholderComponentKey=S,Object.defineProperty(e,"UniverDocsQuickInsertUIPlugin",{enumerable:!0,get:function(){return $}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("rxjs"),require("react"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/docs-drawing-ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`,`@univerjs/design`,`@univerjs/docs-drawing-ui`,`@univerjs/docs-drawing`,`@univerjs/drawing`,`@univerjs/drawing-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsQuickInsertUi={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React,e.UniverDesign,e.UniverDocsDrawingUi,e.UniverDocsDrawing,e.UniverDrawing,e.UniverDrawingUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m={id:`doc.command.delete-search-key`,type:t.CommandType.COMMAND,handler:(e,n)=>{let i=e.get(t.ICommandService),{start:a,end:o}=n;return i.syncExecuteCommand(r.CutContentCommand.id,{segmentId:``,textRanges:[{startOffset:a,endOffset:a,collapsed:!0}],selections:[{startOffset:a,endOffset:o,collapsed:!1,direction:t.RANGE_DIRECTION.FORWARD}]})}},h=`docs.quick.insert.keyword-input-placeholder`;function g(e,t){if(typeof document>`u`)return e.length*11;let n=document.createElement(`canvas`).getContext(`2d`);return n?(n.font=t,Math.ceil(n.measureText(e).width)):e.length*11}let _=({popup:e})=>{var n,r,o,l,u,d,f,p,m,h,_;let v=(0,i.useDependency)(t.LocaleService).t(`docs-quick-insert-ui.keywordInputPlaceholder`),y=(0,a.ptToPixel)((n=(r=e.extraProps)==null?void 0:r.fontSize)==null?11:n),b=(o=(l=e.extraProps)==null?void 0:l.fontString)==null?`${y}px sans-serif`:o,x=(u=(d=e.extraProps)==null?void 0:d.ascent)==null?y:u,S=Math.max((f=(p=e.extraProps)==null?void 0:p.contentHeight)==null?y:f,y),C=(0,s.useMemo)(()=>g(v,b),[b,v]);return(0,c.jsx)(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:(0,c.jsx)(`svg`,{width:C,height:S,viewBox:`0 0 ${C} ${S}`,style:{overflow:`visible`,display:`block`},children:(0,c.jsx)(`text`,{x:0,y:x,fill:`currentColor`,style:{font:b,fontFamily:(m=e.extraProps)==null?void 0:m.fontFamily,fontStyle:(h=e.extraProps)==null?void 0:h.fontStyle,fontWeight:(_=e.extraProps)==null?void 0:_.fontWeight},children:v})})})};_.componentKey=h;function v(e){return`children`in e}function y(e){return e.flatMap(e=>v(e)?y(e.children):e)}function b(e){return y(e).length}function x(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:o,onSelect:u}=e,d=(0,s.useMemo)(()=>y(t),[t]);(0,s.useEffect)(()=>{var e,t;let a=Number.isNaN(n)||(e=d[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[d,n,r,i]);let f=(0,s.useRef)(0);f.current=0;function p(e){return e.map((t,r)=>{let s=t.icon,d=s?a.get(s):null;if(v(t))return(0,c.jsxs)(`div`,{className:(0,l.clsx)(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&l.borderBottomClassName),children:[(0,c.jsxs)(`div`,{className:`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2 univer-text-xs univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-300`,children:[d&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(`span`,{children:t.title})]}),(0,c.jsx)(`div`,{className:`univer-grid univer-gap-1`,children:p(t.children)})]},t.id);let m=f.current,h=n===m;return f.current+=1,(0,c.jsx)(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:(0,l.clsx)(`univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900 univer-outline-none hover:univer-bg-gray-50 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,{"hover:univer-bg-transparent":!h,"univer-bg-gray-50 dark:!univer-bg-gray-600":h}),onMouseEnter:()=>o(m),onMouseLeave:()=>o(NaN),onClick:()=>u(t),children:(0,c.jsxs)(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(l.Tooltip,{showIfEllipsis:!0,title:t.title,placement:`right`,children:(0,c.jsx)(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return(0,c.jsx)(`div`,{className:(0,l.clsx)(`univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2 univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white`,l.borderClassName,l.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:p(t)})}let S=`docs.quick.insert.placeholder`,C=()=>(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg`,children:(0,c.jsx)(`span`,{children:(0,i.useDependency)(t.LocaleService).t(`docs-quick-insert-ui.placeholder`)})});C.componentKey=S;function w(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=w(e.children,t),e.children.length>0;let n=e.keywords;return n?n.some(e=>e.includes(t)):e.title.toLowerCase().includes(t)})}function T(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=T(n.children,t)),n.title=t.t(n.title),`keywords`in n&&(n.keywords=n.keywords.concat(n.title).map(e=>e.toLowerCase())),n})}let ee=[i.KeyCode.ARROW_UP,i.KeyCode.ARROW_DOWN,i.KeyCode.ENTER],E=()=>{let e=(0,i.useDependency)(t.LocaleService),n=(0,i.useDependency)(P),r=(0,i.useDependency)(i.ComponentManager),a=(0,i.useDependency)(i.IShortcutService),o=(0,i.useDependency)(t.ICommandService),l=(0,s.useMemo)(()=>(0,t.generateRandomId)(),[]),[u,d]=(0,s.useState)(0),f=(0,s.useRef)(null),p=(0,i.useObservable)(n.filterKeyword$,``),m=(0,i.useObservable)(n.editPopup$),h=(0,i.useObservable)(m==null?void 0:m.popup.menus$,[]),g=(0,s.useMemo)(()=>T(h,e),[h]),[_,v]=(0,s.useState)(()=>w(g,p.toLowerCase())),y=(0,s.useMemo)(()=>b(_),[_]),S=(0,s.useRef)(y);(0,s.useEffect)(()=>{S.current=y},[y]),(0,s.useEffect)(()=>{let e=requestIdleCallback(()=>{v(w(g,p.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[g,p]);let E=e=>{n.emitMenuSelected(e),o.executeCommand(I.id)};(0,s.useEffect)(()=>{let e=new t.DisposableCollection;a.getAllShortcuts().filter(e=>e.binding&&ee.includes(e.binding)).forEach(n=>{let r=n.preconditions;n.preconditions=()=>!1,e.add((0,t.toDisposable)(()=>{n.preconditions=r}))});let n={id:`quick.insert.popup.enter.${l}`,type:t.CommandType.OPERATION,handler:()=>{let e=f.current;e&&E(e)}},r={id:`quick.insert.popup.move.cursor.up.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e-1;return t>=0?t:S.current-1})}},s={id:`quick.insert.popup.move.cursor.down.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e+1;return t<=S.current-1?t:0})}};return e.add(o.registerCommand(r)),e.add(o.registerCommand(s)),e.add(o.registerCommand(n)),e.add(a.registerShortcut({priority:1e3,id:r.id,binding:i.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:t.Direction.UP}})),e.add(a.registerShortcut({priority:1e3,id:s.id,binding:i.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:t.Direction.DOWN}})),e.add(a.registerShortcut({priority:1e3,id:n.id,binding:i.KeyCode.ENTER,preconditions:()=>!0})),()=>{e.dispose()}},[o,l,a]),(0,s.useEffect)(()=>{d(0)},[_]);let D=(0,s.useRef)(new Map);(0,s.useEffect)(()=>()=>{D.current.clear()},[]);let O=_.length>0,k=(m==null?void 0:m.popup.Placeholder)||r.get(C.componentKey);return(0,c.jsx)(`div`,{className:`univer-mt-2`,children:O?(0,c.jsx)(x,{menus:_,focusedMenuIndex:u,focusedMenuRef:f,menuNodeMapRef:D,componentManager:r,onFocusedMenuIndexChange:d,onSelect:E}):k&&(0,c.jsx)(k,{})})};E.componentKey=`docs.quick.insert.popup`;function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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 N={dispose:()=>{}},P=class extends t.Disposable{get popups(){return Array.from(this._popups)}get editPopup(){return this._editPopup$.value}get isComposing(){return this._isComposing$.value}setIsComposing(e){this._isComposing$.next(e)}get inputOffset(){return this._inputOffset$.value}setInputOffset(e){this._inputOffset$.next(e)}getDocEventManagerService(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(r.DocEventManagerService)}constructor(e,n,r,i,a){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=i,this._docSelectionManagerService=a,A(this,`_popups`,new Set),A(this,`_editPopup$`,new o.BehaviorSubject(void 0)),A(this,`editPopup$`,this._editPopup$.asObservable()),A(this,`_isComposing$`,new o.BehaviorSubject(!1)),A(this,`isComposing$`,this._isComposing$.asObservable()),A(this,`_inputOffset$`,new o.BehaviorSubject({start:0,end:0})),A(this,`inputOffset$`,this._inputOffset$.asObservable()),A(this,`filterKeyword$`,void 0),A(this,`_menuSelectedCallbacks`,new Set),A(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let s=(e,n)=>{var r;return(r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null||(r=r.getBody())==null?void 0:r.dataStream.slice(e,n)},c=``;this.filterKeyword$=this._inputOffset$.pipe((0,o.map)(e=>{var t;let n=s(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),(0,o.distinctUntilChanged)(),(0,o.tap)(e=>{c=e})),this.disposeWithMe((0,o.combineLatest)([this.filterKeyword$.pipe((0,o.tap)(e=>{if(e.length>0){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;(n=this._inputPlaceholderRenderRoot)==null||n.mount()}})),this.isComposing$.pipe((0,o.tap)(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;c.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe((0,o.tap)(e=>{if(!e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose(),this._inputPlaceholderRenderRoot=null}}))]).subscribe())}resolvePopup(e){return Array.from(this._popups).find(t=>t.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{isMounted:!1,mount(){if(this.isMounted)return;this.isMounted=!0;let t=e();this.unmount={dispose:()=>{t.dispose(),this.isMounted=!1}}}}}_getParagraphBound(e,t){var n,r;let i=this._univerInstanceService.getUnit(e),a=i==null||(n=i.getBody())==null||(n=n.paragraphs)==null?void 0:n.find(e=>e.startIndex>t);if(!a)return null;let o=this.getDocEventManagerService(e);return(r=o==null?void 0:o.findParagraphBoundByIndex(a.startIndex))==null?null:r}_getKeywordPlaceholderAnchorRect(e,t,n,i){let a=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!a)return i;let o=e.getOffsetConfig(),{contentBoxPointGroup:s}=new r.NodePositionConvertToCursor(o,t).getRangePointData(a,a);if(s.length===0)return i;let c=(0,r.getAnchorBounding)(s),l=c.left+o.docsLeft,u=c.top+o.docsTop;return{left:l,right:l,top:u,bottom:u+c.height}}_getKeywordPlaceholderExtraProps(e){var t,n,r,i,a,o,s,c,l,u,d,f,p;return{fontSize:(t=e.ts)==null?void 0:t.fs,fontString:(n=e.fontStyle)==null?void 0:n.fontString,fontFamily:(r=(i=(a=e.fontStyle)==null?void 0:a.fontFamily)==null?(o=e.ts)==null?void 0:o.ff:i)==null?void 0:r,fontStyle:(s=e.ts)!=null&&s.it?`italic`:`normal`,fontWeight:(c=e.ts)!=null&&c.bl?`bold`:`normal`,ascent:(l=e.bBox)==null?void 0:l.ba,contentHeight:((u=(d=e.bBox)==null?void 0:d.ba)==null?0:u)+((f=(p=e.bBox)==null?void 0:p.bd)==null?0:f)||void 0}}_mountInputPlaceholder(e,t){let r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(n.DocSkeletonManagerService),a=this._docSelectionManagerService.getActiveTextRange();if(!r||!i||!a)return N;let o=i.getSkeleton(),s=o.findNodeByCharIndex(a.startOffset,a.segmentId,a.segmentPage);if((s==null?void 0:s.content)!==`\r`||!s)return N;let c=r.mainComponent,l=this._getKeywordPlaceholderAnchorRect(c,o,a,t),u=this._getKeywordPlaceholderExtraProps(s),d=this._docCanvasPopupManagerService.attachPopupToRect(l,{componentKey:_.componentKey,extraProps:u,onClickOutside:()=>{d.dispose()},direction:`horizontal`},e);return d}showPopup(e){let{popup:t,index:n,unitId:r}=e;this.closePopup();let i=this._getParagraphBound(r,n);if(!i)return;this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>this._mountInputPlaceholder(r,i.firstLine)),this._inputPlaceholderRenderRoot.mount();let a=this._docCanvasPopupManagerService.attachPopupToRect(i.firstLine,{componentKey:E.componentKey,onClickOutside:()=>{this.closePopup()},direction:`bottom`},r);this._editPopup$.next({disposable:a,popup:t,anchor:n,unitId:r})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){let{start:t,end:n}=this.inputOffset;this._commandService.syncExecuteCommand(m.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};P=M([j(0,(0,t.Inject)(r.DocCanvasPopManagerService)),j(1,(0,t.Inject)(t.IUniverInstanceService)),j(2,(0,t.Inject)(t.ICommandService)),j(3,(0,t.Inject)(a.IRenderManagerService)),j(4,(0,t.Inject)(n.DocSelectionManagerService))],P);let F={type:t.CommandType.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(P);return t?(n.showPopup(t),!0):!1}},I={type:t.CommandType.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(P).closePopup(),!0}},L={id:`quick-insert.text.menu`,title:`docs-quick-insert-ui.menu.text`,icon:`TextIcon`,keywords:[`text`]},R={id:r.OrderListCommand.id,title:`docs-quick-insert-ui.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},te={id:r.BulletListCommand.id,title:`docs-quick-insert-ui.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},z={id:r.HorizontalLineCommand.id,title:`docs-quick-insert-ui.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},B={id:r.DocCreateTableOperation.id,title:`docs-quick-insert-ui.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},V={id:u.InsertDocImageCommand.id,title:`docs-quick-insert-ui.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},ne=[{title:`docs-quick-insert-ui.group.basics`,id:`quick.insert.group.basic`,children:[L,R,te,z,B,V]}],re=new Set([R.id,te.id,z.id,B.id,V.id]),H=class extends t.Disposable{constructor(e,t,n,r,a){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=a,this.disposeWithMe(this._shortcutService.registerShortcut({id:I.id,binding:i.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:i,_textSelectionManagerService:a,_commandService:o}=this,s=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(e.id===r.InsertCommand.id){let t=e.params;if(i.editPopup){i.setInputOffset({start:i.inputOffset.start,end:t.range.endOffset+1});return}let n=a.getActiveTextRange();if(!n)return;let r=i.resolvePopup(t.body.dataStream);if(!r||!(!r.preconditions||r.preconditions(t)))return;i.setInputOffset({start:n.startOffset-1,end:n.startOffset}),setTimeout(()=>{o.executeCommand(F.id,{index:n.startOffset-1,unitId:t.unitId,popup:r})},100)}if(e.id===r.IMEInputCommand.id){let t=e.params;!i.isComposing&&t.isCompositionStart&&i.setIsComposing(!0),i.isComposing&&t.isCompositionEnd&&i.setIsComposing(!1)}if(e.id===n.RichTextEditingMutation.id){let t=e.params;if(t.isCompositionEnd){var c;let e=(c=t.textRanges)==null||(c=c[0])==null?void 0:c.endOffset;e&&i.setInputOffset({start:i.inputOffset.start,end:e})}}if(e.id===r.DeleteCommand.id){let n=e.params;if(i.editPopup&&n.direction===t.DeleteDirection.LEFT){var l;let e=(l=n.len)==null?0:l;i.setInputOffset({start:i.inputOffset.start,end:n.range.endOffset-e})}}if(e.id===r.MoveCursorOperation.id){let n=e.params;(n.direction===t.Direction.LEFT||n.direction===t.Direction.RIGHT)&&i.editPopup&&o.executeCommand(I.id)}if(e.id===r.DeleteLeftCommand.id){let e=a.getActiveTextRange();if(!i.editPopup||!e)return;e.endOffset<=i.editPopup.anchor&&o.executeCommand(I.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==L.id&&re.has(e.id)&&this._commandService.executeCommand(e.id)}))}};H=M([j(0,t.ICommandService),j(1,(0,t.Inject)(n.DocSelectionManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(i.IShortcutService)),j(4,(0,t.Inject)(t.IUniverInstanceService))],H);function U({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${oe()}`);return W(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function W(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...ie(e,n,i),...r},(ae(e,n).children||[]).map((r,a)=>W(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ie(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=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 ae(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 oe(){return Math.random().toString(36).substring(2,8)}U.displayName=`UniverIcon`;let se={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:`M1.01953 3.13985C1.01953 2.77258 1.31726 2.47485 1.68453 2.47485H2.73713C3.1044 2.47485 3.40213 2.77258 3.40213 3.13985C3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.17734 3.13985C4.17734 2.77258 4.47507 2.47485 4.84234 2.47485H6.94754C7.31481 2.47485 7.61254 2.77258 7.61254 3.13985C7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.38775 3.13985C8.38775 2.77258 8.68548 2.47485 9.05275 2.47485H11.158C11.5252 2.47485 11.823 2.77258 11.823 3.13985C11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.5982 3.13985C12.5982 2.77258 12.8959 2.47485 13.2632 2.47485H14.3158C14.683 2.47485 14.9808 2.77258 14.9808 3.13985C14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.01953 7.99972C1.01953 7.63245 1.31726 7.33472 1.68453 7.33472H14.3158C14.683 7.33472 14.9808 7.63245 14.9808 7.99972C14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601C1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601C3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601C4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601C7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601C8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601C11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601C12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601C14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632Z`}}]},G=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`divider-icon`,ref:t,icon:se}))});G.displayName=`DividerIcon`;let ce={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:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},K=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`increase-icon`,ref:t,icon:ce}))});K.displayName=`IncreaseIcon`;let le={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{fill:`currentColor`,clipPath:`url(#text-icon_clip0_1293_26)`},children:[{tag:`path`,attrs:{d:`M2.22891 2.07227C1.89754 2.07227 1.62891 2.34089 1.62891 2.67227C1.62891 3.00364 1.89754 3.27227 2.22891 3.27227H6.29541V14.0056C6.29541 14.337 6.56404 14.6056 6.89541 14.6056C7.22678 14.6056 7.49541 14.337 7.49541 14.0056V3.27227H11.5622C11.8936 3.27227 12.1622 3.00364 12.1622 2.67227C12.1622 2.34089 11.8936 2.07227 11.5622 2.07227H2.22891Z`}},{tag:`path`,attrs:{d:`M10.2289 6.40552C9.89754 6.40552 9.62891 6.67415 9.62891 7.00552C9.62891 7.33689 9.89754 7.60552 10.2289 7.60552H12.2954V14.0055C12.2954 14.3369 12.564 14.6055 12.8954 14.6055C13.2268 14.6055 13.4954 14.3369 13.4954 14.0055V7.60552H15.5622C15.8936 7.60552 16.1622 7.33689 16.1622 7.00552C16.1622 6.67415 15.8936 6.40552 15.5622 6.40552H10.2289Z`}}]},{tag:`defs`,attrs:{},children:[{tag:`clipPath`,attrs:{id:`text-icon_clip0_1293_26`},children:[{tag:`path`,attrs:{fill:`white`,d:`M0 0H16V16H0z`,transform:`translate(.9)`}}]}]}],defIds:[`text-icon_clip0_1293_26`]},q=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`text-icon`,ref:t,icon:le}))});q.displayName=`TextIcon`;let J=class extends t.Disposable{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,A(this,`_popup$`,new o.BehaviorSubject(null)),A(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe((0,o.combineLatest)([this._docEventManagerService.hoverParagraphLeftRealTime$,this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([e,t])=>{let n=e==null?t:e,r=this._context.unit.getDisabled();if(!n||r){this._hideMenu(!0);return}if(n.paragraphStart===n.paragraphEnd){var i;if(this._docQuickInsertPopupService.editPopup||n.startIndex===((i=this.popup)==null?void 0:i.startIndex))return;this._hideMenu(!0);let e=this._docCanvasPopManagerService.attachPopupToRect(n.firstLine,{componentKey:Y,direction:`left-center`},this._context.unit.getUnitId());this._popup$.next({startIndex:n.startIndex,disposable:e})}else this._hideMenu(!0)}))}_hideMenu(e){this._docQuickInsertPopupService.editPopup||this.popup&&(e||this.popup.disposable.canDispose())&&(this.popup.disposable.dispose(),this._popup$.next(null))}};J=M([j(1,(0,t.Inject)(r.DocEventManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(r.DocCanvasPopManagerService))],J);let Y=`doc.quick-insert.button`,X=({className:e=``})=>{let r=(0,i.useDependency)(P),u=(0,i.useDependency)(t.IUniverInstanceService),d=(0,i.useDependency)(a.IRenderManagerService),f=(0,i.useObservable)((0,s.useMemo)(()=>u.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC),[u])),p=f&&d.getRenderById(f.getUnitId()),m=p==null?void 0:p.with(J),h=(0,i.useDependency)(i.ILayoutService),g=(0,i.useDependency)(n.DocSelectionManagerService),_=(0,i.useObservable)(r.editPopup$),v=(0,i.useEvent)(()=>{var e;let t=m==null?void 0:m.popup;if(!t)return;let n=r.popups,i={keyword:``,menus$:(0,o.combineLatest)(n.map(e=>e.menus$)).pipe((0,o.map)(e=>e.flat()))};g.replaceDocRanges([{startOffset:t.startIndex,endOffset:t.startIndex}]),r.setInputOffset({start:t.startIndex-1,end:t.startIndex-1}),r.showPopup({popup:i,index:t.startIndex-1,unitId:(e=f==null?void 0:f.getUnitId())==null?``:e}),setTimeout(()=>{h.focus()})});return(0,c.jsx)(`div`,{className:(0,l.clsx)(`univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full univer-p-1.5 univer-shadow-sm hover:univer-bg-gray-100 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-700`,l.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":_,"univer-bg-white dark:!univer-bg-gray-900":!_},e),role:`button`,tabIndex:0,onClick:v,children:(0,c.jsx)(K,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};X.componentKey=Y;let Z=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[m,F,I].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[E.componentKey,E],[_.componentKey,_],[C.componentKey,C],[G.displayName,G],[q.displayName,q],[X.componentKey,X]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:(0,o.of)(ne),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Z=M([j(0,t.ICommandService),j(1,(0,t.Inject)(P)),j(2,(0,t.Inject)(i.ComponentManager))],Z);var ue=`@univerjs/docs-quick-insert-ui`,de=`0.25.1`;let Q={},$=class extends t.Plugin{constructor(e=Q,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},Q,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-quick-insert-ui.config`,o)}onStarting(){[[Z],[H],[P]].forEach(e=>this._injector.add(e)),this._injector.get(Z)}onRendered(){this._injector.get(H),this._injector.get(P),[[J]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};A($,`type`,t.UniverInstanceType.UNIVER_DOC),A($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),A($,`packageName`,ue),A($,`version`,de),$=M([(0,t.DependentOn)(p.UniverDrawingUIPlugin,f.UniverDrawingPlugin,u.UniverDocsDrawingUIPlugin,d.UniverDocsDrawingPlugin,i.UniverUIPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,(0,t.Inject)(a.IRenderManagerService)),j(3,t.IConfigService)],$),Object.defineProperty(e,"DocQuickInsertPopupService",{enumerable:!0,get:function(){return P}}),Object.defineProperty(e,"DocQuickInsertTriggerController",{enumerable:!0,get:function(){return H}}),Object.defineProperty(e,"DocQuickInsertUIController",{enumerable:!0,get:function(){return Z}}),e.KeywordInputPlaceholderComponentKey=h,e.QuickInsertPlaceholderComponentKey=S,Object.defineProperty(e,"UniverDocsQuickInsertUIPlugin",{enumerable:!0,get:function(){return $}})});
|