@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/lib/es/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 { DeleteTextCommand, DocSelectionManagerService, DocSkeletonManagerService, InsertTextCommand, RichTextEditingMutation } from "@univerjs/docs";
3
- import { BulletListCommand, CutContentCommand, DeleteLeftCommand, DocCanvasPopManagerService, DocCreateTableOperation, DocEventManagerService, HorizontalLineCommand, IMEInputCommand, MoveCursorOperation, NodePositionConvertToCursor, OrderListCommand, getAnchorBounding } from "@univerjs/docs-ui";
4
- import { ComponentManager, ILayoutService, IShortcutService, IconManager, KeyCode, UniverUIPlugin, useDependency, useEvent, useObservable } from "@univerjs/ui";
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 { useCallback, useEffect, useMemo, useRef, useState } from "react";
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, onFocusedMenuIndexChange, onFocusedMenuChange, onSelect } = props;
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
- onFocusedMenuChange(focusedMenu);
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
- onFocusedMenuChange
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 ? iconManager.get(iconKey) : null;
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.137.0/helpers/esm/typeof.js
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.137.0/helpers/esm/toPrimitive.js
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.137.0/helpers/esm/toPropertyKey.js
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.137.0/helpers/esm/defineProperty.js
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.137.0/helpers/esm/decorateParam.js
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.137.0/helpers/esm/decorate.js
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 = /* @__PURE__ */ new Set([
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 === InsertTextCommand.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 === DeleteTextCommand.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/components.controller.ts
985
- /**
986
- * Copyright 2023-present DreamNum Co., Ltd.
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._iconManager = _iconManager;
1005
- this._registerIcons();
1006
- this._registerComponents();
957
+ this._initCommands();
958
+ this._initComponents();
959
+ this._initMenus();
1007
960
  }
1008
- _registerIcons() {
1009
- this.disposeWithMe(this._iconManager.register({
1010
- DividerIcon,
1011
- TextIcon
1012
- }));
961
+ _initCommands() {
962
+ [
963
+ DeleteSearchKeyCommand,
964
+ ShowQuickInsertPopupOperation,
965
+ CloseQuickInsertPopupOperation
966
+ ].forEach((operation) => {
967
+ this.disposeWithMe(this._commandService.registerCommand(operation));
968
+ });
1013
969
  }
1014
- _registerComponents() {
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
- ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
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],