@univerjs/docs-quick-insert-ui 0.25.1 → 1.0.0-alpha.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/cjs/index.js CHANGED
@@ -9,10 +9,10 @@ let react = require("react");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
10
  let _univerjs_design = require("@univerjs/design");
11
11
  let _univerjs_docs_drawing_ui = require("@univerjs/docs-drawing-ui");
12
- let _univerjs_icons = require("@univerjs/icons");
13
12
  let _univerjs_docs_drawing = require("@univerjs/docs-drawing");
14
13
  let _univerjs_drawing = require("@univerjs/drawing");
15
14
  let _univerjs_drawing_ui = require("@univerjs/drawing-ui");
15
+ let _univerjs_icons = require("@univerjs/icons");
16
16
 
17
17
  //#region src/commands/commands/doc-quick-insert.command.ts
18
18
  const DeleteSearchKeyCommand = {
@@ -99,26 +99,33 @@ function getQuickInsertMenuLeafCount(menus) {
99
99
  return flattenMenuItems(menus).length;
100
100
  }
101
101
  function QuickInsertMenu(props) {
102
- const { menus, focusedMenuIndex, focusedMenuRef, menuNodeMapRef, componentManager, onFocusedMenuIndexChange, onSelect } = props;
102
+ const { menus, focusedMenuIndex, onFocusedMenuIndexChange, onFocusedMenuChange, onSelect } = props;
103
+ const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
103
104
  const flatMenus = (0, react.useMemo)(() => flattenMenuItems(menus), [menus]);
105
+ const menuNodeMapRef = (0, react.useRef)(/* @__PURE__ */ new Map());
104
106
  (0, react.useEffect)(() => {
105
107
  var _flatMenus$focusedMen, _menuNodeMapRef$curre;
106
108
  const focusedMenu = Number.isNaN(focusedMenuIndex) ? null : (_flatMenus$focusedMen = flatMenus[focusedMenuIndex]) !== null && _flatMenus$focusedMen !== void 0 ? _flatMenus$focusedMen : null;
107
- focusedMenuRef.current = focusedMenu;
109
+ onFocusedMenuChange(focusedMenu);
108
110
  if (!focusedMenu) return;
109
111
  (_menuNodeMapRef$curre = menuNodeMapRef.current.get(focusedMenu.id)) === null || _menuNodeMapRef$curre === void 0 || _menuNodeMapRef$curre.scrollIntoView({ block: "nearest" });
110
112
  }, [
111
113
  flatMenus,
112
114
  focusedMenuIndex,
113
- focusedMenuRef,
114
- menuNodeMapRef
115
+ onFocusedMenuChange
115
116
  ]);
117
+ (0, react.useEffect)(() => {
118
+ const menuNodeMap = menuNodeMapRef.current;
119
+ return () => {
120
+ menuNodeMap.clear();
121
+ };
122
+ }, []);
116
123
  const itemIndexRef = (0, react.useRef)(0);
117
124
  itemIndexRef.current = 0;
118
125
  function renderMenus(currentMenus) {
119
126
  return currentMenus.map((menu, index) => {
120
127
  const iconKey = menu.icon;
121
- const Icon = iconKey ? componentManager.get(iconKey) : null;
128
+ const Icon = iconKey ? iconManager.get(iconKey) : null;
122
129
  if (isMenuGroup(menu)) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
123
130
  className: (0, _univerjs_design.clsx)("univer-grid univer-gap-1 univer-py-1", index !== currentMenus.length - 1 && _univerjs_design.borderBottomClassName),
124
131
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -179,21 +186,6 @@ function QuickInsertMenu(props) {
179
186
 
180
187
  //#endregion
181
188
  //#region src/views/QuickInsertPlaceholder.tsx
182
- /**
183
- * Copyright 2023-present DreamNum Co., Ltd.
184
- *
185
- * Licensed under the Apache License, Version 2.0 (the "License");
186
- * you may not use this file except in compliance with the License.
187
- * You may obtain a copy of the License at
188
- *
189
- * http://www.apache.org/licenses/LICENSE-2.0
190
- *
191
- * Unless required by applicable law or agreed to in writing, software
192
- * distributed under the License is distributed on an "AS IS" BASIS,
193
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194
- * See the License for the specific language governing permissions and
195
- * limitations under the License.
196
- */
197
189
  const QuickInsertPlaceholderComponentKey = "docs.quick.insert.placeholder";
198
190
  const QuickInsertPlaceholder = () => {
199
191
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -265,6 +257,9 @@ const QuickInsertPopup = () => {
265
257
  docQuickInsertPopupService.emitMenuSelected(menu);
266
258
  commandService.executeCommand(CloseQuickInsertPopupOperation.id);
267
259
  };
260
+ const handleFocusedMenuChange = (0, react.useCallback)((menu) => {
261
+ focusedMenuRef.current = menu;
262
+ }, []);
268
263
  (0, react.useEffect)(() => {
269
264
  /** Use up or down to navigate the focused menu instead of moving the cursor in documents. */
270
265
  const disposableCollection = new _univerjs_core.DisposableCollection();
@@ -339,12 +334,6 @@ const QuickInsertPopup = () => {
339
334
  (0, react.useEffect)(() => {
340
335
  setFocusedMenuIndex(0);
341
336
  }, [filteredMenus]);
342
- const menuNodeMapRef = (0, react.useRef)(/* @__PURE__ */ new Map());
343
- (0, react.useEffect)(() => {
344
- return () => {
345
- menuNodeMapRef.current.clear();
346
- };
347
- }, []);
348
337
  const hasMenus = filteredMenus.length > 0;
349
338
  const Placeholder = (currentPopup === null || currentPopup === void 0 ? void 0 : currentPopup.popup.Placeholder) || componentManager.get(QuickInsertPlaceholder.componentKey);
350
339
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -352,10 +341,8 @@ const QuickInsertPopup = () => {
352
341
  children: hasMenus ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuickInsertMenu, {
353
342
  menus: filteredMenus,
354
343
  focusedMenuIndex,
355
- focusedMenuRef,
356
- menuNodeMapRef,
357
- componentManager,
358
344
  onFocusedMenuIndexChange: setFocusedMenuIndex,
345
+ onFocusedMenuChange: handleFocusedMenuChange,
359
346
  onSelect: handleMenuSelect
360
347
  }) : Placeholder && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Placeholder, {})
361
348
  });
@@ -363,7 +350,7 @@ const QuickInsertPopup = () => {
363
350
  QuickInsertPopup.componentKey = "docs.quick.insert.popup";
364
351
 
365
352
  //#endregion
366
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
353
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
367
354
  function _typeof(o) {
368
355
  "@babel/helpers - typeof";
369
356
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -374,7 +361,7 @@ function _typeof(o) {
374
361
  }
375
362
 
376
363
  //#endregion
377
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
364
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
378
365
  function toPrimitive(t, r) {
379
366
  if ("object" != _typeof(t) || !t) return t;
380
367
  var e = t[Symbol.toPrimitive];
@@ -387,14 +374,14 @@ function toPrimitive(t, r) {
387
374
  }
388
375
 
389
376
  //#endregion
390
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
377
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
391
378
  function toPropertyKey(t) {
392
379
  var i = toPrimitive(t, "string");
393
380
  return "symbol" == _typeof(i) ? i : i + "";
394
381
  }
395
382
 
396
383
  //#endregion
397
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
384
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
398
385
  function _defineProperty(e, r, t) {
399
386
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
400
387
  value: t,
@@ -405,7 +392,7 @@ function _defineProperty(e, r, t) {
405
392
  }
406
393
 
407
394
  //#endregion
408
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
395
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
409
396
  function __decorateParam(paramIndex, decorator) {
410
397
  return function(target, key) {
411
398
  decorator(target, key, paramIndex);
@@ -413,7 +400,7 @@ function __decorateParam(paramIndex, decorator) {
413
400
  }
414
401
 
415
402
  //#endregion
416
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
403
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
417
404
  function __decorate(decorators, target, key, desc) {
418
405
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
419
406
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -731,7 +718,7 @@ const builtInMenus = [{
731
718
  imageMenu
732
719
  ]
733
720
  }];
734
- const builtInMenuCommandIds = new Set([
721
+ const builtInMenuCommandIds = /* @__PURE__ */ new Set([
735
722
  numberedListMenu.id,
736
723
  bulletedListMenu.id,
737
724
  dividerMenu.id,
@@ -763,7 +750,7 @@ let DocQuickInsertTriggerController = class DocQuickInsertTriggerController exte
763
750
  const { _docQuickInsertPopupService, _textSelectionManagerService, _commandService } = this;
764
751
  const documentDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
765
752
  if (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDisabled()) return;
766
- if (commandInfo.id === _univerjs_docs_ui.InsertCommand.id) {
753
+ if (commandInfo.id === _univerjs_docs.InsertTextCommand.id) {
767
754
  const params = commandInfo.params;
768
755
  if (_docQuickInsertPopupService.editPopup) {
769
756
  _docQuickInsertPopupService.setInputOffset({
@@ -805,7 +792,7 @@ let DocQuickInsertTriggerController = class DocQuickInsertTriggerController exte
805
792
  });
806
793
  }
807
794
  }
808
- if (commandInfo.id === _univerjs_docs_ui.DeleteCommand.id) {
795
+ if (commandInfo.id === _univerjs_docs.DeleteTextCommand.id) {
809
796
  const params = commandInfo.params;
810
797
  if (_docQuickInsertPopupService.editPopup && params.direction === _univerjs_core.DeleteDirection.LEFT) {
811
798
  var _params$len;
@@ -842,6 +829,53 @@ DocQuickInsertTriggerController = __decorate([
842
829
  __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
843
830
  ], DocQuickInsertTriggerController);
844
831
 
832
+ //#endregion
833
+ //#region src/controllers/ui.controller.ts
834
+ let DocQuickInsertUIController = class DocQuickInsertUIController extends _univerjs_core.Disposable {
835
+ constructor(_commandService, _docQuickInsertPopupService) {
836
+ super();
837
+ this._commandService = _commandService;
838
+ this._docQuickInsertPopupService = _docQuickInsertPopupService;
839
+ this._initCommands();
840
+ this._initComponents();
841
+ this._initMenus();
842
+ }
843
+ _initCommands() {
844
+ [
845
+ DeleteSearchKeyCommand,
846
+ ShowQuickInsertPopupOperation,
847
+ CloseQuickInsertPopupOperation
848
+ ].forEach((operation) => {
849
+ this.disposeWithMe(this._commandService.registerCommand(operation));
850
+ });
851
+ }
852
+ _initComponents() {
853
+ [{
854
+ keyword: "/",
855
+ menus$: (0, rxjs.of)(builtInMenus),
856
+ preconditions: (params) => {
857
+ var _startNodePosition;
858
+ return ((_startNodePosition = params.range.startNodePosition) === null || _startNodePosition === void 0 ? void 0 : _startNodePosition.glyph) === 0;
859
+ }
860
+ }].forEach((popup) => {
861
+ this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(popup));
862
+ });
863
+ }
864
+ _initMenus() {}
865
+ };
866
+ DocQuickInsertUIController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(DocQuickInsertPopupService))], DocQuickInsertUIController);
867
+
868
+ //#endregion
869
+ //#region package.json
870
+ var name = "@univerjs/docs-quick-insert-ui";
871
+ var version = "1.0.0-alpha.1";
872
+
873
+ //#endregion
874
+ //#region src/config/config.ts
875
+ const DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY = "docs-quick-insert-ui.config";
876
+ const configSymbol = Symbol(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY);
877
+ const defaultPluginConfig = {};
878
+
845
879
  //#endregion
846
880
  //#region src/menu/doc-quick-insert-menu.controller.ts
847
881
  let DocQuickInsertMenuController = class DocQuickInsertMenuController extends _univerjs_core.Disposable {
@@ -948,66 +982,48 @@ const QuickInsertButton = ({ className = "" }) => {
948
982
  QuickInsertButton.componentKey = QuickInsertButtonComponentKey;
949
983
 
950
984
  //#endregion
951
- //#region src/controllers/doc-quick-insert-ui.controller.ts
952
- let DocQuickInsertUIController = class DocQuickInsertUIController extends _univerjs_core.Disposable {
953
- constructor(_commandService, _docQuickInsertPopupService, _componentManager) {
985
+ //#region src/controllers/components.controller.ts
986
+ /**
987
+ * Copyright 2023-present DreamNum Co., Ltd.
988
+ *
989
+ * Licensed under the Apache License, Version 2.0 (the "License");
990
+ * you may not use this file except in compliance with the License.
991
+ * You may obtain a copy of the License at
992
+ *
993
+ * http://www.apache.org/licenses/LICENSE-2.0
994
+ *
995
+ * Unless required by applicable law or agreed to in writing, software
996
+ * distributed under the License is distributed on an "AS IS" BASIS,
997
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
998
+ * See the License for the specific language governing permissions and
999
+ * limitations under the License.
1000
+ */
1001
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
1002
+ constructor(_componentManager, _iconManager) {
954
1003
  super();
955
- this._commandService = _commandService;
956
- this._docQuickInsertPopupService = _docQuickInsertPopupService;
957
1004
  this._componentManager = _componentManager;
958
- this._initCommands();
959
- this._initComponents();
960
- this._initMenus();
1005
+ this._iconManager = _iconManager;
1006
+ this._registerIcons();
1007
+ this._registerComponents();
961
1008
  }
962
- _initCommands() {
963
- [
964
- DeleteSearchKeyCommand,
965
- ShowQuickInsertPopupOperation,
966
- CloseQuickInsertPopupOperation
967
- ].forEach((operation) => {
968
- this.disposeWithMe(this._commandService.registerCommand(operation));
969
- });
1009
+ _registerIcons() {
1010
+ this.disposeWithMe(this._iconManager.register({
1011
+ DividerIcon: _univerjs_icons.DividerIcon,
1012
+ TextIcon: _univerjs_icons.TextIcon
1013
+ }));
970
1014
  }
971
- _initComponents() {
1015
+ _registerComponents() {
972
1016
  [
973
1017
  [QuickInsertPopup.componentKey, QuickInsertPopup],
974
1018
  [KeywordInputPlaceholder.componentKey, KeywordInputPlaceholder],
975
1019
  [QuickInsertPlaceholder.componentKey, QuickInsertPlaceholder],
976
- [_univerjs_icons.DividerIcon.displayName, _univerjs_icons.DividerIcon],
977
- [_univerjs_icons.TextIcon.displayName, _univerjs_icons.TextIcon],
978
1020
  [QuickInsertButton.componentKey, QuickInsertButton]
979
1021
  ].forEach(([key, comp]) => {
980
1022
  if (key) this.disposeWithMe(this._componentManager.register(key, comp));
981
1023
  });
982
- [{
983
- keyword: "/",
984
- menus$: (0, rxjs.of)(builtInMenus),
985
- preconditions: (params) => {
986
- var _startNodePosition;
987
- return ((_startNodePosition = params.range.startNodePosition) === null || _startNodePosition === void 0 ? void 0 : _startNodePosition.glyph) === 0;
988
- }
989
- }].forEach((popup) => {
990
- this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(popup));
991
- });
992
1024
  }
993
- _initMenus() {}
994
1025
  };
995
- DocQuickInsertUIController = __decorate([
996
- __decorateParam(0, _univerjs_core.ICommandService),
997
- __decorateParam(1, (0, _univerjs_core.Inject)(DocQuickInsertPopupService)),
998
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
999
- ], DocQuickInsertUIController);
1000
-
1001
- //#endregion
1002
- //#region package.json
1003
- var name = "@univerjs/docs-quick-insert-ui";
1004
- var version = "0.25.1";
1005
-
1006
- //#endregion
1007
- //#region src/config/config.ts
1008
- const DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY = "docs-quick-insert-ui.config";
1009
- const configSymbol = Symbol(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY);
1010
- const defaultPluginConfig = {};
1026
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
1011
1027
 
1012
1028
  //#endregion
1013
1029
  //#region src/plugin.ts
@@ -1023,6 +1039,8 @@ let UniverDocsQuickInsertUIPlugin = class UniverDocsQuickInsertUIPlugin extends
1023
1039
  this._configService.setConfig(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY, rest);
1024
1040
  }
1025
1041
  onStarting() {
1042
+ this._injector.add([ComponentsController]);
1043
+ this._injector.get(ComponentsController);
1026
1044
  [
1027
1045
  [DocQuickInsertUIController],
1028
1046
  [DocQuickInsertTriggerController],