@univerjs/ui 1.0.0-alpha.2 → 1.0.0-alpha.3

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.
Files changed (28) hide show
  1. package/lib/cjs/facade.js +2 -0
  2. package/lib/cjs/index.js +567 -224
  3. package/lib/es/facade.js +2 -0
  4. package/lib/es/index.js +559 -225
  5. package/lib/facade.js +2 -0
  6. package/lib/index.css +5 -12
  7. package/lib/index.js +559 -225
  8. package/lib/types/facade/f-menu-builder.d.ts +2 -0
  9. package/lib/types/index.d.ts +6 -2
  10. package/lib/types/services/contextmenu/contextmenu.service.d.ts +6 -3
  11. package/lib/types/services/dom/canvas-dom-layer.service.d.ts +52 -1
  12. package/lib/types/services/menu/menu-manager.service.d.ts +1 -0
  13. package/lib/types/services/popup/canvas-popup.service.d.ts +2 -1
  14. package/lib/types/services/ribbon/ribbon-override.service.d.ts +42 -0
  15. package/lib/types/services/runtime-scope/ui-runtime-scope.service.d.ts +32 -0
  16. package/lib/types/services/shortcut/shortcut.service.d.ts +2 -1
  17. package/lib/types/utils/embed-boundary.d.ts +23 -0
  18. package/lib/types/utils/index.d.ts +1 -0
  19. package/lib/types/views/components/context-menu/AnchoredContextMenu.d.ts +4 -0
  20. package/lib/types/views/components/context-menu/ContextMenuPanel.d.ts +4 -0
  21. package/lib/types/views/components/dom/FloatDom.d.ts +11 -0
  22. package/lib/types/views/components/dom/float-dom-layout.d.ts +35 -0
  23. package/lib/types/views/components/ribbon/Ribbon.d.ts +2 -0
  24. package/lib/types/views/components/ribbon/TooltipButtonWrapper.d.ts +6 -1
  25. package/lib/types/views/emoji-picker/emoji-picker-utils.d.ts +1 -1
  26. package/lib/types/views/menu/mobile/MobileMenu.d.ts +2 -0
  27. package/lib/umd/index.js +15 -22
  28. package/package.json +8 -8
package/lib/cjs/index.js CHANGED
@@ -625,6 +625,47 @@ function fromGlobalEvent(type, listener, options) {
625
625
  return (0, _univerjs_core.toDisposable)(() => window.removeEventListener(type, listener, options));
626
626
  }
627
627
 
628
+ //#endregion
629
+ //#region src/utils/embed-boundary.ts
630
+ /**
631
+ * Copyright 2023-present DreamNum Co., Ltd.
632
+ *
633
+ * Licensed under the Apache License, Version 2.0 (the "License");
634
+ * you may not use this file except in compliance with the License.
635
+ * You may obtain a copy of the License at
636
+ *
637
+ * http://www.apache.org/licenses/LICENSE-2.0
638
+ *
639
+ * Unless required by applicable law or agreed to in writing, software
640
+ * distributed under the License is distributed on an "AS IS" BASIS,
641
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
642
+ * See the License for the specific language governing permissions and
643
+ * limitations under the License.
644
+ */
645
+ const EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE = "data-embed-interaction-boundary-owner";
646
+ function getEmbedBoundaryOwner(target) {
647
+ var _ref, _getAttributeValue;
648
+ if (!hasClosest(target)) return;
649
+ const ownerElement = target.closest(`[${EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE}]`);
650
+ return (_ref = (_getAttributeValue = getAttributeValue(target, "data-embed-interaction-boundary-owner")) !== null && _getAttributeValue !== void 0 ? _getAttributeValue : getAttributeValue(ownerElement, "data-embed-interaction-boundary-owner")) !== null && _ref !== void 0 ? _ref : void 0;
651
+ }
652
+ function isEmbedBoundaryTarget(target) {
653
+ return hasClosest(target) && target.closest(`[${"data-embed-interaction-boundary-owner"}]`) != null;
654
+ }
655
+ function keepInteractionInsideSameEmbedBoundary(event) {
656
+ const owner = getEmbedBoundaryOwner(event.currentTarget);
657
+ if (!owner) return;
658
+ if (getEmbedBoundaryOwner(event.target) === owner) event.preventDefault();
659
+ }
660
+ function hasClosest(target) {
661
+ return !!target && typeof target.closest === "function";
662
+ }
663
+ function getAttributeValue(target, name) {
664
+ var _getAttribute$call;
665
+ const getAttribute = target === null || target === void 0 ? void 0 : target.getAttribute;
666
+ return typeof getAttribute === "function" ? (_getAttribute$call = getAttribute.call(target, name)) !== null && _getAttribute$call !== void 0 ? _getAttribute$call : void 0 : void 0;
667
+ }
668
+
628
669
  //#endregion
629
670
  //#region src/services/layout/layout.service.ts
630
671
  const FOCUSING_UNIVER = "FOCUSING_UNIVER";
@@ -705,8 +746,15 @@ let DesktopLayoutService = class DesktopLayoutService extends _univerjs_core.Dis
705
746
  this.disposeWithMe((0, rxjs.fromEvent)(window, "focusin").subscribe((event) => {
706
747
  var _this$_rootContainerE;
707
748
  const target = event.target;
708
- if (((_this$_rootContainerE = this._rootContainerElement) === null || _this$_rootContainerE === void 0 ? void 0 : _this$_rootContainerE.contains(target)) && givingBackFocusElements.some((item) => target.dataset.uComp === item)) {
709
- queueMicrotask(() => this.focus());
749
+ if (((_this$_rootContainerE = this._rootContainerElement) === null || _this$_rootContainerE === void 0 ? void 0 : _this$_rootContainerE.contains(target)) && givingBackFocusElements.some((item) => target.dataset.uComp === item) && !isEmbedBoundaryTarget(target)) {
750
+ queueMicrotask(() => {
751
+ const targetUnitId = getFocusUnitIdFromElement(target);
752
+ if (targetUnitId && this._univerInstanceService.getUnit(targetUnitId)) this._univerInstanceService.focusUnit(targetUnitId);
753
+ this.focus();
754
+ this._isFocused = true;
755
+ this._contextService.setContextValue(FOCUSING_UNIVER, this._isFocused);
756
+ this._contextService.setContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR, getFocusingUniverEditorStatus());
757
+ });
710
758
  return;
711
759
  }
712
760
  if (target && this.checkElementInCurrentContainers(target)) this._isFocused = true;
@@ -724,6 +772,9 @@ function getFocusingUniverEditorStatus() {
724
772
  var _document$activeEleme;
725
773
  return ((_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.dataset.uComp) === "editor";
726
774
  }
775
+ function getFocusUnitIdFromElement(target) {
776
+ return target.dataset.uUnitId;
777
+ }
727
778
 
728
779
  //#endregion
729
780
  //#region src/services/platform/platform.service.ts
@@ -845,6 +896,7 @@ let ShortcutService = class ShortcutService extends _univerjs_core.Disposable {
845
896
  if (this._layoutService && !this._layoutService.checkElementInCurrentContainers(e.target)) return;
846
897
  const binding = this._deriveBindingFromEvent(e);
847
898
  if (binding === null) return;
899
+ if (this._shouldLetEmbedTextEditorHandleNativeShortcut(e, binding)) return;
848
900
  const shortcuts = this._shortCutMapping.get(binding);
849
901
  if (shortcuts === void 0) return;
850
902
  return Array.from(shortcuts).sort((s1, s2) => {
@@ -870,6 +922,12 @@ let ShortcutService = class ShortcutService extends _univerjs_core.Disposable {
870
922
  if (this._platformService.isMac && e.ctrlKey) binding |= 8192;
871
923
  return binding;
872
924
  }
925
+ _shouldLetEmbedTextEditorHandleNativeShortcut(e, binding) {
926
+ if (binding !== (65 | 4096)) return false;
927
+ const target = e.target;
928
+ if (!(target instanceof HTMLElement)) return false;
929
+ return (target.isContentEditable || target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) && isEmbedBoundaryTarget(target);
930
+ }
873
931
  };
874
932
  ShortcutService = __decorate([
875
933
  __decorateParam(0, _univerjs_core.ICommandService),
@@ -1051,8 +1109,9 @@ let ContextMenuGroup = /* @__PURE__ */ function(ContextMenuGroup) {
1051
1109
 
1052
1110
  //#endregion
1053
1111
  //#region src/services/menu/menu-manager.service.ts
1112
+ var _MenuManagerService;
1054
1113
  const IMenuManagerService = (0, _univerjs_core.createIdentifier)("univer.menu-manager-service");
1055
- let MenuManagerService = class MenuManagerService extends _univerjs_core.Disposable {
1114
+ let MenuManagerService = _MenuManagerService = class MenuManagerService extends _univerjs_core.Disposable {
1056
1115
  constructor(_injector, _configService) {
1057
1116
  super();
1058
1117
  this._injector = _injector;
@@ -1186,6 +1245,21 @@ let MenuManagerService = class MenuManagerService extends _univerjs_core.Disposa
1186
1245
  this._menu = (0, _univerjs_core.merge)({}, this._menu, source);
1187
1246
  this.menuChanged$.next();
1188
1247
  }
1248
+ createScoped(injector) {
1249
+ const root = this;
1250
+ const createScopedBuilder = () => {
1251
+ const service = new _MenuManagerService(injector, root._configService);
1252
+ service._menu = root._menu;
1253
+ return service;
1254
+ };
1255
+ return {
1256
+ menuChanged$: root.menuChanged$,
1257
+ mergeMenu: (source, target) => root.mergeMenu(source, target),
1258
+ appendRootMenu: (source) => root.appendRootMenu(source),
1259
+ getMenuByPositionKey: (position) => createScopedBuilder().getMenuByPositionKey(position),
1260
+ getFlatMenuByPositionKey: (position) => createScopedBuilder().getFlatMenuByPositionKey(position)
1261
+ };
1262
+ }
1189
1263
  _buildMenuSchema(data) {
1190
1264
  const result = [];
1191
1265
  for (const [key, value] of Object.entries(data)) {
@@ -1225,6 +1299,7 @@ let MenuManagerService = class MenuManagerService extends _univerjs_core.Disposa
1225
1299
  * @returns Menu schema array or empty array if not found
1226
1300
  */
1227
1301
  getMenuByPositionKey(key) {
1302
+ var _findKey;
1228
1303
  const findKey = (obj) => {
1229
1304
  if (key in obj) return this._buildMenuSchema(obj[key]);
1230
1305
  for (const k in obj) {
@@ -1235,7 +1310,7 @@ let MenuManagerService = class MenuManagerService extends _univerjs_core.Disposa
1235
1310
  }
1236
1311
  }
1237
1312
  };
1238
- return findKey(this._menu);
1313
+ return (_findKey = findKey(this._menu)) !== null && _findKey !== void 0 ? _findKey : [];
1239
1314
  }
1240
1315
  /**
1241
1316
  * Get flat menu schema by position key
@@ -1257,7 +1332,7 @@ let MenuManagerService = class MenuManagerService extends _univerjs_core.Disposa
1257
1332
  return flatMenuItems(menu);
1258
1333
  }
1259
1334
  };
1260
- MenuManagerService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, _univerjs_core.IConfigService)], MenuManagerService);
1335
+ MenuManagerService = _MenuManagerService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, _univerjs_core.IConfigService)], MenuManagerService);
1261
1336
  function normalizeMenuOrder(order) {
1262
1337
  return order !== null && order !== void 0 ? order : 0;
1263
1338
  }
@@ -1334,11 +1409,14 @@ const undoRedoDisableFactory$ = (accessor, isUndo) => {
1334
1409
  return undoDisable || contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED) || contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
1335
1410
  }));
1336
1411
  };
1412
+ const rtlIconFactory$ = (accessor, ltrIcon, rtlIcon) => {
1413
+ return accessor.get(_univerjs_core.LocaleService).direction$.pipe((0, rxjs_operators.map)((direction) => direction === "rtl" ? rtlIcon : ltrIcon));
1414
+ };
1337
1415
  function UndoMenuItemFactory(accessor) {
1338
1416
  return {
1339
1417
  id: _univerjs_core.UndoCommand.id,
1340
1418
  type: 0,
1341
- icon: "UndoIcon",
1419
+ icon: rtlIconFactory$(accessor, "UndoIcon", "RedoIcon"),
1342
1420
  title: "ui.shortcut.undo",
1343
1421
  tooltip: "ui.shortcut.undo",
1344
1422
  disabled$: undoRedoDisableFactory$(accessor, true)
@@ -1348,7 +1426,7 @@ function RedoMenuItemFactory(accessor) {
1348
1426
  return {
1349
1427
  id: _univerjs_core.RedoCommand.id,
1350
1428
  type: 0,
1351
- icon: "RedoIcon",
1429
+ icon: rtlIconFactory$(accessor, "RedoIcon", "UndoIcon"),
1352
1430
  title: "ui.shortcut.redo",
1353
1431
  tooltip: "ui.shortcut.redo",
1354
1432
  disabled$: undoRedoDisableFactory$(accessor, false)
@@ -1469,8 +1547,15 @@ function useObservableRef(observable, defaultValue) {
1469
1547
 
1470
1548
  //#endregion
1471
1549
  //#region src/services/dom/canvas-dom-layer.service.ts
1472
- var CanvasFloatDomService = class {
1473
- constructor() {
1550
+ function shouldForwardFloatDomEvents(layer) {
1551
+ return layer.eventPassThrough !== false;
1552
+ }
1553
+ function shouldRenderFloatDomLayer(layer, currentUnitId) {
1554
+ return layer.unitId === currentUnitId || layer.preserveOnFocusChange === true;
1555
+ }
1556
+ var CanvasFloatDomService = class extends _univerjs_core.Disposable {
1557
+ constructor(..._args) {
1558
+ super(..._args);
1474
1559
  _defineProperty(this, "_domLayerMap", /* @__PURE__ */ new Map());
1475
1560
  _defineProperty(this, "_domLayers$", new rxjs.BehaviorSubject([]));
1476
1561
  _defineProperty(this, "domLayers$", this._domLayers$.asObservable());
@@ -1501,68 +1586,131 @@ var CanvasFloatDomService = class {
1501
1586
  this._domLayerMap.clear();
1502
1587
  this._notice();
1503
1588
  }
1589
+ dispose() {
1590
+ this._domLayerMap.clear();
1591
+ this._domLayers$.next([]);
1592
+ this._domLayers$.complete();
1593
+ super.dispose();
1594
+ }
1595
+ };
1596
+ var CanvasFloatDomPreviewService = class extends _univerjs_core.Disposable {
1597
+ constructor(..._args2) {
1598
+ super(..._args2);
1599
+ _defineProperty(this, "previewUpdated$", new rxjs.Subject());
1600
+ _defineProperty(this, "previewRequested$", new rxjs.Subject());
1601
+ _defineProperty(this, "_previewMap", /* @__PURE__ */ new Map());
1602
+ _defineProperty(this, "_requestMap", /* @__PURE__ */ new Map());
1603
+ }
1604
+ getPreview(id) {
1605
+ return this._previewMap.get(id);
1606
+ }
1607
+ getPendingRequests() {
1608
+ return Array.from(this._requestMap.values());
1609
+ }
1610
+ setPreview(preview) {
1611
+ this._previewMap.set(preview.id, preview);
1612
+ this._requestMap.delete(preview.id);
1613
+ this.previewUpdated$.next(preview);
1614
+ }
1615
+ removePreview(id) {
1616
+ this._previewMap.delete(id);
1617
+ this._requestMap.delete(id);
1618
+ }
1619
+ requestPreview(request) {
1620
+ this._requestMap.set(request.id, request);
1621
+ this.previewRequested$.next(request);
1622
+ }
1623
+ dispose() {
1624
+ this._previewMap.clear();
1625
+ this._requestMap.clear();
1626
+ this.previewUpdated$.complete();
1627
+ this.previewRequested$.complete();
1628
+ super.dispose();
1629
+ }
1504
1630
  };
1505
1631
 
1632
+ //#endregion
1633
+ //#region src/views/components/dom/float-dom-layout.ts
1634
+ const LEGACY_WRAPPER_INSET = 2;
1635
+ const LEGACY_CONTENT_INSET = 4;
1636
+ function resolveFloatDomLayout(position, contentBox) {
1637
+ var _contentBox$wrapperIn, _contentBox$contentIn, _position$opacity;
1638
+ const wrapperInset = (_contentBox$wrapperIn = contentBox === null || contentBox === void 0 ? void 0 : contentBox.wrapperInset) !== null && _contentBox$wrapperIn !== void 0 ? _contentBox$wrapperIn : LEGACY_WRAPPER_INSET;
1639
+ const contentInset = (_contentBox$contentIn = contentBox === null || contentBox === void 0 ? void 0 : contentBox.contentInset) !== null && _contentBox$contentIn !== void 0 ? _contentBox$contentIn : LEGACY_CONTENT_INSET;
1640
+ return {
1641
+ wrapper: {
1642
+ top: position.startY,
1643
+ left: position.startX,
1644
+ width: Math.max(position.endX - position.startX - wrapperInset, 0),
1645
+ height: Math.max(position.endY - position.startY - wrapperInset, 0),
1646
+ transform: `rotate(${position.rotate}deg)`,
1647
+ opacity: (_position$opacity = position.opacity) !== null && _position$opacity !== void 0 ? _position$opacity : 1
1648
+ },
1649
+ inner: {
1650
+ width: position.width - contentInset,
1651
+ height: position.height - contentInset,
1652
+ left: position.absolute.left ? 0 : "auto",
1653
+ top: position.absolute.top ? 0 : "auto",
1654
+ right: position.absolute.left ? "auto" : 0,
1655
+ bottom: position.absolute.top ? "auto" : 0
1656
+ }
1657
+ };
1658
+ }
1659
+
1506
1660
  //#endregion
1507
1661
  //#region src/views/components/dom/FloatDom.tsx
1662
+ function applyFloatDomLayout(wrapper, inner, layout) {
1663
+ const { wrapper: wrapperLayout, inner: innerLayout } = layout;
1664
+ const wrapperStyle = wrapper.style;
1665
+ wrapperStyle.top = `${wrapperLayout.top}px`;
1666
+ wrapperStyle.left = `${wrapperLayout.left}px`;
1667
+ wrapperStyle.width = `${wrapperLayout.width}px`;
1668
+ wrapperStyle.height = `${wrapperLayout.height}px`;
1669
+ wrapperStyle.transform = wrapperLayout.transform;
1670
+ wrapperStyle.opacity = `${wrapperLayout.opacity}`;
1671
+ const innerStyle = inner.style;
1672
+ innerStyle.width = `${innerLayout.width}px`;
1673
+ innerStyle.height = `${innerLayout.height}px`;
1674
+ innerStyle.left = innerLayout.left === "auto" ? "auto" : `${innerLayout.left}px`;
1675
+ innerStyle.top = innerLayout.top === "auto" ? "auto" : `${innerLayout.top}px`;
1676
+ innerStyle.right = innerLayout.right === "auto" ? "auto" : `${innerLayout.right}px`;
1677
+ innerStyle.bottom = innerLayout.bottom === "auto" ? "auto" : `${innerLayout.bottom}px`;
1678
+ }
1508
1679
  const FloatDomSingle = (0, react.memo)((props) => {
1509
- var _position$startY, _position$startX;
1680
+ var _layer$contentBox, _layer$contentBox2;
1510
1681
  const { layer, id } = props;
1511
- const size$ = (0, react.useMemo)(() => layer.position$.pipe((0, rxjs.distinctUntilChanged)((prev, curr) => prev.absolute.left === curr.absolute.left && prev.absolute.top === curr.absolute.top && prev.endX - prev.startX === curr.endX - curr.startX && prev.endY - prev.startY === curr.endY - curr.startY)), [layer.position$]);
1512
1682
  const univerInstanceService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.IUniverInstanceService);
1513
1683
  const position = (0, _wendellhu_redi_react_bindings.useObservable)((0, react.useMemo)(() => layer.position$.pipe((0, rxjs.first)()), [layer.position$]));
1514
1684
  const domRef = (0, react.useRef)(null);
1515
1685
  const innerDomRef = (0, react.useRef)(null);
1516
- const transformRef = (0, react.useRef)(`transform: rotate(${position === null || position === void 0 ? void 0 : position.rotate}deg) translate(${position === null || position === void 0 ? void 0 : position.startX}px, ${position === null || position === void 0 ? void 0 : position.startY}px)`);
1517
- const topRef = (0, react.useRef)((_position$startY = position === null || position === void 0 ? void 0 : position.startY) !== null && _position$startY !== void 0 ? _position$startY : 0);
1518
- const leftRef = (0, react.useRef)((_position$startX = position === null || position === void 0 ? void 0 : position.startX) !== null && _position$startX !== void 0 ? _position$startX : 0);
1519
- const innerStyle = (0, react.useRef)({});
1520
1686
  const Component = typeof layer.componentKey === "string" ? (0, _wendellhu_redi_react_bindings.useDependency)(ComponentManager).get(layer.componentKey) : layer.componentKey;
1521
1687
  const layerProps = (0, react.useMemo)(() => ({
1522
1688
  data: layer.data,
1523
- ...layer.props
1524
- }), [layer.data, layer.props]);
1689
+ ...layer.props,
1690
+ hostFloatDomLayout$: layer.position$
1691
+ }), [
1692
+ layer.data,
1693
+ layer.position$,
1694
+ layer.props
1695
+ ]);
1696
+ const floatDomOverflow = resolveFloatDomOverflow(layerProps);
1697
+ const wrapperInset = (_layer$contentBox = layer.contentBox) === null || _layer$contentBox === void 0 ? void 0 : _layer$contentBox.wrapperInset;
1698
+ const contentInset = (_layer$contentBox2 = layer.contentBox) === null || _layer$contentBox2 === void 0 ? void 0 : _layer$contentBox2.contentInset;
1525
1699
  (0, react.useEffect)(() => {
1526
1700
  const subscription = layer.position$.subscribe((position) => {
1527
- transformRef.current = `rotate(${position.rotate}deg)`;
1528
- topRef.current = position.startY;
1529
- leftRef.current = position.startX;
1530
- if (domRef.current) {
1531
- var _position$opacity;
1532
- domRef.current.style.transform = transformRef.current;
1533
- domRef.current.style.top = `${topRef.current}px`;
1534
- domRef.current.style.left = `${leftRef.current}px`;
1535
- domRef.current.style.opacity = `${(_position$opacity = position.opacity) !== null && _position$opacity !== void 0 ? _position$opacity : 1}`;
1536
- }
1537
- });
1538
- const sizeSubscription = size$.subscribe((size) => {
1539
- if (domRef.current) {
1540
- domRef.current.style.width = `${Math.max(size.endX - size.startX - 2, 0)}px`;
1541
- domRef.current.style.height = `${Math.max(size.endY - size.startY - 2, 0)}px`;
1542
- }
1543
- if (innerDomRef.current) {
1544
- const style = {
1545
- width: `${size.width - 4}px`,
1546
- height: `${size.height - 4}px`,
1547
- left: `${size.absolute.left ? 0 : "auto"}`,
1548
- top: `${size.absolute.top ? 0 : "auto"}`,
1549
- right: `${size.absolute.left ? "auto" : 0}`,
1550
- bottom: `${size.absolute.top ? "auto" : 0}`
1551
- };
1552
- innerDomRef.current.style.width = style.width;
1553
- innerDomRef.current.style.height = style.height;
1554
- innerDomRef.current.style.left = style.left;
1555
- innerDomRef.current.style.top = style.top;
1556
- innerDomRef.current.style.right = style.right;
1557
- innerDomRef.current.style.bottom = style.bottom;
1558
- innerStyle.current = style;
1559
- }
1701
+ if (domRef.current && innerDomRef.current) applyFloatDomLayout(domRef.current, innerDomRef.current, resolveFloatDomLayout(position, {
1702
+ wrapperInset,
1703
+ contentInset
1704
+ }));
1560
1705
  });
1561
1706
  return () => {
1562
1707
  subscription.unsubscribe();
1563
- sizeSubscription.unsubscribe();
1564
1708
  };
1565
- }, [layer.position$, size$]);
1709
+ }, [
1710
+ contentInset,
1711
+ layer.position$,
1712
+ wrapperInset
1713
+ ]);
1566
1714
  const instance = univerInstanceService.getUnit(layer.unitId);
1567
1715
  const docDisabled = instance instanceof _univerjs_core.DocumentDataModel ? instance.getDisabled() : void 0;
1568
1716
  const component = (0, react.useMemo)(() => Component ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
@@ -1576,36 +1724,34 @@ const FloatDomSingle = (0, react.memo)((props) => {
1576
1724
  }
1577
1725
  }) : null, [Component, layerProps]);
1578
1726
  if (!position) return null;
1727
+ const layout = resolveFloatDomLayout(position, layer.contentBox);
1579
1728
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1580
1729
  ref: domRef,
1581
- className: "univer-z-10",
1730
+ className: "univer-absolute univer-z-10 univer-origin-center",
1582
1731
  style: {
1583
- position: "absolute",
1584
- top: topRef.current,
1585
- left: leftRef.current,
1586
- width: Math.max(position.endX - position.startX - 2, 0),
1587
- height: Math.max(position.endY - position.startY - 2, 0),
1588
- transform: transformRef.current,
1589
- overflow: "hidden",
1590
- transformOrigin: "center center"
1732
+ ...layout.wrapper,
1733
+ overflow: floatDomOverflow.outerOverflow
1591
1734
  },
1592
1735
  onPointerMove: (e) => {
1593
- layer.onPointerMove(e.nativeEvent);
1736
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerMove(e.nativeEvent);
1594
1737
  },
1595
1738
  onPointerDown: (e) => {
1596
- layer.onPointerDown(e.nativeEvent);
1739
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerDown(e.nativeEvent);
1597
1740
  },
1598
1741
  onPointerUp: (e) => {
1599
- layer.onPointerUp(e.nativeEvent);
1742
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerUp(e.nativeEvent);
1600
1743
  },
1601
1744
  onWheel: (e) => {
1602
- layer.onWheel(e.nativeEvent);
1745
+ if (shouldForwardFloatDomEvents(layer)) layer.onWheel(e.nativeEvent);
1603
1746
  },
1604
1747
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1605
1748
  id,
1606
1749
  ref: innerDomRef,
1607
1750
  className: "univer-absolute univer-overflow-hidden",
1608
- style: { ...innerStyle.current },
1751
+ style: {
1752
+ ...layout.inner,
1753
+ overflow: floatDomOverflow.innerOverflow
1754
+ },
1609
1755
  children: component
1610
1756
  })
1611
1757
  });
@@ -1614,9 +1760,8 @@ const FloatDom = ({ unitId }) => {
1614
1760
  var _layers$filter;
1615
1761
  const instanceService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.IUniverInstanceService);
1616
1762
  const layers = (0, _wendellhu_redi_react_bindings.useObservable)((0, _wendellhu_redi_react_bindings.useDependency)(CanvasFloatDomService).domLayers$);
1617
- const focusUnit = (0, _wendellhu_redi_react_bindings.useObservable)(instanceService.focused$);
1618
- const currentUnitId = unitId || focusUnit;
1619
- return layers === null || layers === void 0 || (_layers$filter = layers.filter((layer) => layer[1].unitId === currentUnitId)) === null || _layers$filter === void 0 ? void 0 : _layers$filter.map((layer) => {
1763
+ const currentUnitId = resolveFloatDomCurrentUnitId(unitId, (0, _wendellhu_redi_react_bindings.useObservable)(instanceService.focused$));
1764
+ return layers === null || layers === void 0 || (_layers$filter = layers.filter((layer) => shouldRenderFloatDomLayer(layer[1], currentUnitId))) === null || _layers$filter === void 0 ? void 0 : _layers$filter.map((layer) => {
1620
1765
  var _layer$1$domId;
1621
1766
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FloatDomSingle, {
1622
1767
  id: (_layer$1$domId = layer[1].domId) !== null && _layer$1$domId !== void 0 ? _layer$1$domId : layer[0],
@@ -1624,6 +1769,27 @@ const FloatDom = ({ unitId }) => {
1624
1769
  }, layer[0]);
1625
1770
  });
1626
1771
  };
1772
+ function resolveFloatDomCurrentUnitId(unitId, focusedUnit) {
1773
+ if (typeof unitId === "string") return unitId;
1774
+ if (typeof focusedUnit === "string") return focusedUnit;
1775
+ if (focusedUnit != null && typeof focusedUnit === "object" && "getUnitId" in focusedUnit && typeof focusedUnit.getUnitId === "function") {
1776
+ const focusedUnitId = focusedUnit.getUnitId();
1777
+ return typeof focusedUnitId === "string" ? focusedUnitId : null;
1778
+ }
1779
+ return null;
1780
+ }
1781
+ function resolveFloatDomOverflow(props) {
1782
+ var _viewport$bleedWidth;
1783
+ const viewport = props.customBlockRenderViewport;
1784
+ if (!(Number.isFinite(viewport === null || viewport === void 0 ? void 0 : viewport.bleedWidth) && ((_viewport$bleedWidth = viewport === null || viewport === void 0 ? void 0 : viewport.bleedWidth) !== null && _viewport$bleedWidth !== void 0 ? _viewport$bleedWidth : 0) > 0)) return {
1785
+ outerOverflow: "hidden",
1786
+ innerOverflow: "hidden"
1787
+ };
1788
+ return {
1789
+ outerOverflow: "visible",
1790
+ innerOverflow: "visible"
1791
+ };
1792
+ }
1627
1793
 
1628
1794
  //#endregion
1629
1795
  //#region src/services/popup/canvas-popup.service.ts
@@ -1930,13 +2096,41 @@ function CanvasPopup() {
1930
2096
  return (0, _wendellhu_redi_react_bindings.useObservable)(popupService.popups$, void 0, true).map((item) => {
1931
2097
  const [key, popup] = item;
1932
2098
  const Component = componentManager.get(popup.componentKey);
2099
+ const PopupComponent = Component && popup.connectorInjector ? (0, _wendellhu_redi_react_bindings.connectInjector)(Component, popup.connectorInjector) : Component;
1933
2100
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SingleCanvasPopup, {
1934
2101
  popup,
1935
- children: Component ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { popup }) : null
2102
+ children: PopupComponent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopupComponent, { popup })
1936
2103
  }, key);
1937
2104
  });
1938
2105
  }
1939
2106
 
2107
+ //#endregion
2108
+ //#region src/services/ribbon/ribbon-override.service.ts
2109
+ const IRibbonOverrideService = (0, _univerjs_core.createIdentifier)("univer.ribbon-override-service");
2110
+ var RibbonOverrideService = class extends _univerjs_core.Disposable {
2111
+ constructor(..._args) {
2112
+ super(..._args);
2113
+ _defineProperty(this, "_override$", new rxjs.BehaviorSubject(null));
2114
+ _defineProperty(this, "override$", this._override$.asObservable());
2115
+ }
2116
+ getOverride() {
2117
+ return this._override$.getValue();
2118
+ }
2119
+ activate(override) {
2120
+ this._override$.next(override);
2121
+ }
2122
+ clear(id) {
2123
+ const current = this.getOverride();
2124
+ if (!current) return;
2125
+ if (!id || current.id === id) this._override$.next(null);
2126
+ }
2127
+ dispose() {
2128
+ this._override$.next(null);
2129
+ this._override$.complete();
2130
+ super.dispose();
2131
+ }
2132
+ };
2133
+
1940
2134
  //#endregion
1941
2135
  //#region src/services/ribbon/ribbon.service.ts
1942
2136
  const IRibbonService = (0, _univerjs_core.createIdentifier)("univer.ribbon-service");
@@ -2419,39 +2613,52 @@ const TooltipWrapperContext = (0, react.createContext)({
2419
2613
  dropdownVisible: false,
2420
2614
  setDropdownVisible: (_visible) => {}
2421
2615
  });
2616
+ const ToolbarDropdownContext = (0, react.createContext)(null);
2617
+ function ToolbarDropdownProvider(props) {
2618
+ const [openDropdownKey, setOpenDropdownKey] = (0, react.useState)(null);
2619
+ const contextValue = (0, react.useMemo)(() => ({
2620
+ openDropdownKey,
2621
+ setOpenDropdownKey
2622
+ }), [openDropdownKey]);
2623
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarDropdownContext.Provider, {
2624
+ value: contextValue,
2625
+ children: props.children
2626
+ });
2627
+ }
2422
2628
  const TooltipWrapper = (0, react.forwardRef)((props, ref) => {
2423
- const { children, ...tooltipProps } = props;
2629
+ const { children, dropdownKey, ...tooltipProps } = props;
2424
2630
  const spanRef = (0, react.useRef)(null);
2425
2631
  const [tooltipVisible, setTooltipVisible] = (0, react.useState)(false);
2426
- const [dropdownVisible, setDropdownVisible] = (0, react.useState)(false);
2632
+ const [localDropdownVisible, setLocalDropdownVisible] = (0, react.useState)(false);
2633
+ const toolbarDropdownContext = (0, react.useContext)(ToolbarDropdownContext);
2634
+ const dropdownVisible = dropdownKey && toolbarDropdownContext ? toolbarDropdownContext.openDropdownKey === dropdownKey : localDropdownVisible;
2427
2635
  function handleChangeTooltipVisible(visible) {
2428
2636
  if (dropdownVisible) setTooltipVisible(false);
2429
2637
  else setTooltipVisible(visible);
2430
2638
  }
2431
- function handleChangeDropdownVisible(visible) {
2432
- setDropdownVisible(visible);
2639
+ const handleChangeDropdownVisible = (0, react.useCallback)((visible) => {
2640
+ if (dropdownKey && toolbarDropdownContext) toolbarDropdownContext.setOpenDropdownKey(visible ? dropdownKey : null);
2641
+ else setLocalDropdownVisible(visible);
2433
2642
  setTooltipVisible(false);
2434
- }
2643
+ }, [dropdownKey, toolbarDropdownContext]);
2435
2644
  const contextValue = (0, react.useMemo)(() => ({
2436
2645
  dropdownVisible,
2437
2646
  setDropdownVisible: handleChangeDropdownVisible
2438
- }), [dropdownVisible]);
2647
+ }), [dropdownVisible, handleChangeDropdownVisible]);
2439
2648
  (0, react.useImperativeHandle)(ref, () => ({ el: spanRef.current }));
2649
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2650
+ ref: spanRef,
2651
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipWrapperContext.Provider, {
2652
+ value: contextValue,
2653
+ children
2654
+ })
2655
+ });
2440
2656
  return tooltipProps.title ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
2441
2657
  visible: tooltipVisible,
2442
2658
  onVisibleChange: handleChangeTooltipVisible,
2443
2659
  ...tooltipProps,
2444
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2445
- ref: spanRef,
2446
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipWrapperContext.Provider, {
2447
- value: contextValue,
2448
- children
2449
- })
2450
- })
2451
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2452
- ref: spanRef,
2453
- children
2454
- });
2660
+ children: content
2661
+ }) : content;
2455
2662
  });
2456
2663
  function DropdownWrapper(props) {
2457
2664
  const { children, overlay, disabled, align = "start" } = props;
@@ -2504,6 +2711,10 @@ function DropdownMenuLabel({ icon, value, option, onOptionSelect }) {
2504
2711
  })]
2505
2712
  });
2506
2713
  }
2714
+ function getOptionKey(option) {
2715
+ var _ref, _ref2, _option$id, _option$label2;
2716
+ return String((_ref = (_ref2 = (_option$id = option.id) !== null && _option$id !== void 0 ? _option$id : option.commandId) !== null && _ref2 !== void 0 ? _ref2 : option.value) !== null && _ref !== void 0 ? _ref : typeof option.label === "string" ? option.label : (_option$label2 = option.label) === null || _option$label2 === void 0 ? void 0 : _option$label2.name);
2717
+ }
2507
2718
  function DropdownMenuWrapper({ menuId, slot, value, options, children, disabled, onOptionSelect }) {
2508
2719
  const { dropdownVisible, setDropdownVisible } = (0, react.useContext)(TooltipWrapperContext);
2509
2720
  const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
@@ -2532,6 +2743,9 @@ function DropdownMenuWrapper({ menuId, slot, value, options, children, disabled,
2532
2743
  function handleVisibleChange(visible) {
2533
2744
  setDropdownVisible(visible);
2534
2745
  }
2746
+ function handleEmbedBoundaryFocusOutside(event) {
2747
+ keepInteractionInsideSameEmbedBoundary(event);
2748
+ }
2535
2749
  function handleOptionSelect(option) {
2536
2750
  onOptionSelect(option);
2537
2751
  setDropdownVisible(false);
@@ -2571,19 +2785,19 @@ function DropdownMenuWrapper({ menuId, slot, value, options, children, disabled,
2571
2785
  }, [menuItems]);
2572
2786
  if (slot) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownWrapper, {
2573
2787
  disabled,
2574
- overlay: options.map((option, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuLabel, {
2788
+ overlay: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuLabel, {
2575
2789
  value,
2576
2790
  option,
2577
2791
  onOptionSelect: handleOptionSelect
2578
- }, index)),
2792
+ }, getOptionKey(option))),
2579
2793
  children
2580
2794
  });
2581
2795
  if (options === null || options === void 0 ? void 0 : options.length) {
2582
2796
  const items = options.map((option) => {
2583
- var _option$label2;
2797
+ var _option$label3;
2584
2798
  return {
2585
2799
  type: "item",
2586
- className: (0, _univerjs_design.clsx)({ "focus:univer-bg-white": typeof option.label !== "string" && ((_option$label2 = option.label) === null || _option$label2 === void 0 ? void 0 : _option$label2.hoverable) === false }),
2800
+ className: (0, _univerjs_design.clsx)({ "focus:univer-bg-white": typeof option.label !== "string" && ((_option$label3 = option.label) === null || _option$label3 === void 0 ? void 0 : _option$label3.hoverable) === false }),
2587
2801
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuLabel, {
2588
2802
  icon: option.icon,
2589
2803
  value,
@@ -2626,6 +2840,8 @@ function DropdownMenuWrapper({ menuId, slot, value, options, children, disabled,
2626
2840
  disabled,
2627
2841
  open: dropdownVisible,
2628
2842
  onOpenChange: handleVisibleChange,
2843
+ onFocusOutside: handleEmbedBoundaryFocusOutside,
2844
+ onInteractOutside: handleEmbedBoundaryFocusOutside,
2629
2845
  children
2630
2846
  });
2631
2847
  } else {
@@ -2660,6 +2876,8 @@ function DropdownMenuWrapper({ menuId, slot, value, options, children, disabled,
2660
2876
  disabled,
2661
2877
  open: dropdownVisible,
2662
2878
  onOpenChange: handleVisibleChange,
2879
+ onFocusOutside: handleEmbedBoundaryFocusOutside,
2880
+ onInteractOutside: handleEmbedBoundaryFocusOutside,
2663
2881
  children
2664
2882
  });
2665
2883
  }
@@ -2896,6 +3114,7 @@ const ToolbarItem = (0, react.forwardRef)((props, ref) => {
2896
3114
  ref,
2897
3115
  title: tooltipTitle,
2898
3116
  placement: "bottom",
3117
+ dropdownKey: id,
2899
3118
  children: renderItem()
2900
3119
  });
2901
3120
  });
@@ -2903,15 +3122,20 @@ const ToolbarItem = (0, react.forwardRef)((props, ref) => {
2903
3122
  //#endregion
2904
3123
  //#region src/views/components/ribbon/Ribbon.tsx
2905
3124
  function Ribbon(props) {
2906
- const { ribbonType, headerMenuComponents, headerMenu = true } = props;
2907
- const ribbonService = (0, _wendellhu_redi_react_bindings.useDependency)(IRibbonService);
3125
+ var _ribbonOverride$ribbo;
3126
+ const { ribbonType, headerMenuComponents, headerMenu = true, toolbarOnly = false, headerClassName } = props;
3127
+ const defaultRibbonService = (0, _wendellhu_redi_react_bindings.useDependency)(IRibbonService);
3128
+ const ribbonOverrideService = (0, _wendellhu_redi_react_bindings.useDependency)(IRibbonOverrideService);
2908
3129
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
3130
+ const ribbonOverride = (0, _wendellhu_redi_react_bindings.useObservable)(ribbonOverrideService.override$, ribbonOverrideService.getOverride());
3131
+ const ribbonService = (_ribbonOverride$ribbo = ribbonOverride === null || ribbonOverride === void 0 ? void 0 : ribbonOverride.ribbonService) !== null && _ribbonOverride$ribbo !== void 0 ? _ribbonOverride$ribbo : defaultRibbonService;
2909
3132
  const containerRef = (0, react.useRef)(null);
2910
3133
  const toolbarItemRefs = (0, react.useRef)({});
2911
3134
  const ribbonData = (0, _wendellhu_redi_react_bindings.useObservable)(ribbonService.ribbon$, []);
2912
3135
  const activatedTab = (0, _wendellhu_redi_react_bindings.useObservable)(ribbonService.activatedTab$, "ribbon.start");
2913
3136
  const collapsedIds = (0, _wendellhu_redi_react_bindings.useObservable)(ribbonService.collapsedIds$, []);
2914
3137
  const fakeToolbarVisible = (0, _wendellhu_redi_react_bindings.useObservable)(ribbonService.fakeToolbarVisible$, false);
3138
+ const hideToolbar = (ribbonOverride === null || ribbonOverride === void 0 ? void 0 : ribbonOverride.hideToolbar) === true;
2915
3139
  const ribbon = (0, react.useMemo)(() => {
2916
3140
  if (ribbonType === "simple") {
2917
3141
  const simpleRibbon = [{
@@ -2937,7 +3161,7 @@ function Ribbon(props) {
2937
3161
  const handleSelectTab = (0, react.useCallback)((group) => {
2938
3162
  toolbarItemRefs.current = {};
2939
3163
  ribbonService.setActivatedTab(group.key);
2940
- }, []);
3164
+ }, [ribbonService]);
2941
3165
  const activeGroup = (0, react.useMemo)(() => {
2942
3166
  var _ribbon$find$children, _ribbon$find2;
2943
3167
  const allGroups = (_ribbon$find$children = (_ribbon$find2 = ribbon.find((group) => group.key === activatedTab)) === null || _ribbon$find2 === void 0 ? void 0 : _ribbon$find2.children) !== null && _ribbon$find$children !== void 0 ? _ribbon$find$children : [];
@@ -2965,6 +3189,13 @@ function Ribbon(props) {
2965
3189
  activatedTab
2966
3190
  ]);
2967
3191
  (0, react.useEffect)(() => {
3192
+ if (hideToolbar) {
3193
+ toolbarItemRefs.current = {};
3194
+ ribbonService.setCollapsedIds([]);
3195
+ ribbonService.setFakeToolbarVisible(false);
3196
+ return;
3197
+ }
3198
+ if (!containerRef.current) return;
2968
3199
  let timer = null;
2969
3200
  const observer = new ResizeObserver((0, _univerjs_core.throttle)((entries) => {
2970
3201
  for (const entry of entries) {
@@ -2994,7 +3225,12 @@ function Ribbon(props) {
2994
3225
  timer && cancelAnimationFrame(timer);
2995
3226
  observer.disconnect();
2996
3227
  };
2997
- }, [ribbon, activatedTab]);
3228
+ }, [
3229
+ hideToolbar,
3230
+ ribbon,
3231
+ activatedTab,
3232
+ ribbonService
3233
+ ]);
2998
3234
  const fakeToolbar = (0, react.useMemo)(() => {
2999
3235
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3000
3236
  "aria-hidden": "true",
@@ -3019,75 +3255,117 @@ function Ribbon(props) {
3019
3255
  })
3020
3256
  });
3021
3257
  }, [activeGroup.allGroups, fakeToolbarVisible]);
3022
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
3023
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3024
- "data-u-comp": "ribbon-header-menu",
3025
- className: (0, _univerjs_design.clsx)("univer-relative univer-select-none", { "univer-h-9": ribbonType === "classic" || headerMenuComponents && headerMenuComponents.size > 0 }),
3026
- children: [ribbonType === "classic" && ribbon.length >= 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClassicMenu, {
3027
- ribbon,
3028
- activatedTab,
3029
- onSelectTab: handleSelectTab
3030
- }), headerMenu && headerMenuComponents && headerMenuComponents.size > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3031
- className: "univer-absolute univer-right-2 univer-top-0 univer-flex univer-h-full univer-flex-row univer-items-center univer-gap-2 rtl:univer-left-2 rtl:univer-right-auto [&>*]:univer-inline-flex [&>*]:univer-h-6 [&>*]:univer-items-center [&>*]:univer-rounded [&>*]:univer-px-1 [&>*]:univer-transition-colors hover:[&>*]:univer-bg-gray-100",
3032
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComponentContainer, { components: headerMenuComponents })
3033
- })]
3034
- }),
3035
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3036
- className: (0, _univerjs_design.clsx)("univer-box-border univer-grid univer-h-10 univer-grid-flow-col univer-items-center univer-px-3 univer-text-sm", {
3037
- "univer-grid-cols-[1fr] univer-justify-center": ribbonType === "classic" || ribbon.length === 1,
3038
- "univer-grid-cols-[auto,1fr]": ribbon.length > 1 && ribbonType !== "classic"
3039
- }, _univerjs_design.borderBottomClassName),
3040
- children: [ribbonType === "collapsed" && ribbon.length >= 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultMenu, {
3041
- ribbon,
3042
- activatedTab,
3043
- onSelectTab: handleSelectTab
3044
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3045
- "data-u-comp": "ribbon-toolbar",
3046
- ref: containerRef,
3047
- className: (0, _univerjs_design.clsx)("univer-flex univer-overflow-hidden rtl:univer-divide-x-reverse", _univerjs_design.divideXClassName, { "univer-justify-center": ribbonType === "classic" }),
3048
- role: "toolbar",
3049
- "aria-label": localeService.t(activatedTabTitle),
3050
- children: [activeGroup.visibleGroups.map((groupItem) => {
3051
- var _groupItem$children3, _groupItem$children4;
3052
- return (((_groupItem$children3 = groupItem.children) === null || _groupItem$children3 === void 0 ? void 0 : _groupItem$children3.length) || groupItem.item) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3053
- className: "univer-grid univer-shrink-0 univer-grid-flow-col univer-gap-2 univer-px-2 empty:univer-hidden",
3054
- children: groupItem.children && ((_groupItem$children4 = groupItem.children) === null || _groupItem$children4 === void 0 ? void 0 : _groupItem$children4.map((child) => child.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...child.item }, child.key)))
3055
- }) }, groupItem.key);
3056
- }), collapsedIds.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3057
- "data-u-comp": "ribbon-toolbar-more",
3058
- className: "univer-pl-2 rtl:univer-pr-2",
3059
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
3060
- collisionPadding: {
3061
- right: 12,
3062
- left: 12
3063
- },
3064
- onOpenAutoFocus: (e) => e.preventDefault(),
3065
- overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3066
- className: "univer-box-border univer-grid univer-max-w-[--radix-popper-available-width] univer-gap-2 univer-p-2",
3067
- children: activeGroup.hiddenGroups.map((groupItem) => {
3068
- var _groupItem$children5;
3069
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3070
- className: "univer-flex univer-items-center univer-gap-2",
3071
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3072
- className: "univer-flex univer-flex-wrap univer-gap-2",
3073
- children: groupItem.children ? (_groupItem$children5 = groupItem.children) === null || _groupItem$children5 === void 0 ? void 0 : _groupItem$children5.map((child) => child.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...child.item }, child.key)) : groupItem.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...groupItem.item }, groupItem.key)
3074
- })
3075
- }, groupItem.key);
3076
- })
3077
- }),
3078
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3079
- type: "button",
3080
- className: toolbarButtonClassName,
3081
- "aria-label": localeService.t("ui.ribbon.more"),
3082
- "aria-haspopup": "true",
3083
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreVerticalIcon, {})
3258
+ const embedRibbonOverrideAttributes = ribbonOverride ? {
3259
+ "data-embed-ribbon-override": "true",
3260
+ "data-embed-id": ribbonOverride.id
3261
+ } : {};
3262
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RibbonOverrideRuntimeProvider, {
3263
+ override: ribbonOverride,
3264
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
3265
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3266
+ "data-u-comp": "ribbon-header-menu",
3267
+ ...embedRibbonOverrideAttributes,
3268
+ className: (0, _univerjs_design.clsx)("univer-relative univer-select-none", headerClassName, {
3269
+ "univer-hidden": toolbarOnly,
3270
+ "univer-h-9": !toolbarOnly && (ribbonType === "classic" || headerMenuComponents && headerMenuComponents.size > 0)
3271
+ }),
3272
+ children: [
3273
+ !toolbarOnly && (ribbonOverride === null || ribbonOverride === void 0 ? void 0 : ribbonOverride.placeholderTitle) && ribbon.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3274
+ className: (0, _univerjs_design.clsx)("univer-flex univer-h-9 univer-items-end univer-px-3", { "univer-justify-center": hideToolbar }),
3275
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3276
+ className: "univer-relative univer-inline-flex univer-h-8 univer-items-center univer-justify-center univer-rounded-t univer-bg-primary-50 univer-px-3 univer-text-sm univer-font-medium univer-text-primary-600",
3277
+ children: ribbonOverride.placeholderTitle
3084
3278
  })
3279
+ }),
3280
+ !toolbarOnly && ribbonType === "classic" && ribbon.length >= 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClassicMenu, {
3281
+ ribbon,
3282
+ activatedTab,
3283
+ onSelectTab: handleSelectTab
3284
+ }),
3285
+ headerMenu && headerMenuComponents && headerMenuComponents.size > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3286
+ className: "univer-absolute univer-right-2 univer-top-0 univer-flex univer-h-full univer-flex-row univer-items-center univer-gap-2 rtl:univer-left-2 rtl:univer-right-auto [&>*]:univer-inline-flex [&>*]:univer-h-6 [&>*]:univer-items-center [&>*]:univer-rounded [&>*]:univer-px-1 [&>*]:univer-transition-colors hover:[&>*]:univer-bg-gray-100",
3287
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComponentContainer, { components: headerMenuComponents })
3085
3288
  })
3289
+ ]
3290
+ }),
3291
+ !hideToolbar && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3292
+ ...embedRibbonOverrideAttributes,
3293
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-grid univer-h-10 univer-grid-flow-col univer-items-center univer-px-3 univer-text-sm", {
3294
+ "univer-grid-cols-[1fr] univer-justify-center": ribbonType === "classic" || ribbon.length === 1,
3295
+ "univer-grid-cols-[auto,1fr]": ribbon.length > 1 && ribbonType !== "classic"
3296
+ }, _univerjs_design.borderBottomClassName),
3297
+ children: [ribbonType === "collapsed" && ribbon.length >= 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultMenu, {
3298
+ ribbon,
3299
+ activatedTab,
3300
+ onSelectTab: handleSelectTab
3301
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3302
+ "data-u-comp": "ribbon-toolbar",
3303
+ ref: containerRef,
3304
+ className: (0, _univerjs_design.clsx)("univer-flex univer-overflow-hidden", _univerjs_design.divideXClassName, { "univer-justify-center": ribbonType === "classic" }),
3305
+ role: "toolbar",
3306
+ "aria-label": localeService.t(activatedTabTitle),
3307
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarDropdownProvider, { children: [activeGroup.visibleGroups.map((groupItem) => {
3308
+ var _groupItem$children3, _groupItem$children4;
3309
+ return (((_groupItem$children3 = groupItem.children) === null || _groupItem$children3 === void 0 ? void 0 : _groupItem$children3.length) || groupItem.item) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3310
+ className: "univer-grid univer-shrink-0 univer-grid-flow-col univer-gap-2 univer-px-2 empty:univer-hidden",
3311
+ children: groupItem.children && ((_groupItem$children4 = groupItem.children) === null || _groupItem$children4 === void 0 ? void 0 : _groupItem$children4.map((child) => child.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...child.item }, child.key)))
3312
+ }) }, groupItem.key);
3313
+ }), collapsedIds.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3314
+ className: "univer-pl-2 rtl:univer-pr-2",
3315
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
3316
+ collisionPadding: {
3317
+ right: 12,
3318
+ left: 12
3319
+ },
3320
+ onOpenAutoFocus: (e) => e.preventDefault(),
3321
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3322
+ className: "univer-box-border univer-grid univer-max-w-[--radix-popper-available-width] univer-gap-2 univer-p-2",
3323
+ children: activeGroup.hiddenGroups.map((groupItem) => {
3324
+ var _groupItem$children5;
3325
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3326
+ className: "univer-flex univer-items-center univer-gap-2",
3327
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3328
+ className: "univer-flex univer-flex-wrap univer-gap-2",
3329
+ children: groupItem.children ? (_groupItem$children5 = groupItem.children) === null || _groupItem$children5 === void 0 ? void 0 : _groupItem$children5.map((child) => child.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...child.item }, child.key)) : groupItem.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...groupItem.item }, groupItem.key)
3330
+ })
3331
+ }, groupItem.key);
3332
+ })
3333
+ }),
3334
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3335
+ type: "button",
3336
+ className: toolbarButtonClassName,
3337
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreVerticalIcon, {})
3338
+ })
3339
+ })
3340
+ })] }, activatedTab)
3086
3341
  })]
3087
- })]
3088
- }),
3089
- fakeToolbar
3090
- ] });
3342
+ }),
3343
+ fakeToolbar
3344
+ ] })
3345
+ });
3346
+ }
3347
+ function RibbonOverrideRuntimeProvider(props) {
3348
+ var _override$portalConta;
3349
+ const { override, children } = props;
3350
+ const config = (0, react.useContext)(_univerjs_design.ConfigContext);
3351
+ const injector = override === null || override === void 0 ? void 0 : override.injector;
3352
+ const ConnectedRibbonOverrideConfigProvider = (0, react.useMemo)(() => injector ? (0, _wendellhu_redi_react_bindings.connectInjector)(RibbonOverrideConfigProvider, injector) : null, [injector]);
3353
+ if (!override || !ConnectedRibbonOverrideConfigProvider) return children;
3354
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectedRibbonOverrideConfigProvider, {
3355
+ locale: config.locale,
3356
+ direction: config.direction,
3357
+ mountContainer: (_override$portalConta = override.portalContainer) !== null && _override$portalConta !== void 0 ? _override$portalConta : config.mountContainer,
3358
+ children
3359
+ });
3360
+ }
3361
+ function RibbonOverrideConfigProvider(props) {
3362
+ const { children, locale, direction, mountContainer } = props;
3363
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ConfigProvider, {
3364
+ locale,
3365
+ direction,
3366
+ mountContainer,
3367
+ children
3368
+ });
3091
3369
  }
3092
3370
 
3093
3371
  //#endregion
@@ -3143,11 +3421,11 @@ var ContextMenuService = class extends _univerjs_core.Disposable {
3143
3421
  enable() {
3144
3422
  this.disabled = false;
3145
3423
  }
3146
- triggerContextMenu(event, menuType) {
3424
+ triggerContextMenu(event, menuType, context) {
3147
3425
  var _this$_currentHandler3;
3148
3426
  event.stopPropagation();
3149
3427
  if (this.disabled) return;
3150
- (_this$_currentHandler3 = this._currentHandler) === null || _this$_currentHandler3 === void 0 || _this$_currentHandler3.handleContextMenu(event, menuType);
3428
+ (_this$_currentHandler3 = this._currentHandler) === null || _this$_currentHandler3 === void 0 || _this$_currentHandler3.handleContextMenu(event, menuType, context);
3151
3429
  }
3152
3430
  hideContextMenu() {
3153
3431
  var _this$_currentHandler4;
@@ -3160,6 +3438,25 @@ var ContextMenuService = class extends _univerjs_core.Disposable {
3160
3438
  }
3161
3439
  };
3162
3440
 
3441
+ //#endregion
3442
+ //#region src/services/runtime-scope/ui-runtime-scope.service.ts
3443
+ const IUIRuntimeScopeService = (0, _univerjs_core.createIdentifier)("ui.runtime-scope.service");
3444
+ var UIRuntimeScopeService = class extends _univerjs_core.Disposable {
3445
+ constructor(..._args) {
3446
+ super(..._args);
3447
+ _defineProperty(this, "_scopes", /* @__PURE__ */ new Map());
3448
+ }
3449
+ register(scope) {
3450
+ this._scopes.set(scope.unitId, scope);
3451
+ return (0, _univerjs_core.toDisposable)(() => {
3452
+ if (this._scopes.get(scope.unitId) === scope) this._scopes.delete(scope.unitId);
3453
+ });
3454
+ }
3455
+ get(unitId) {
3456
+ return unitId ? this._scopes.get(unitId) : void 0;
3457
+ }
3458
+ };
3459
+
3163
3460
  //#endregion
3164
3461
  //#region src/services/contextmenu/contextmenu-host.service.ts
3165
3462
  const IContextMenuHostService = (0, _univerjs_core.createIdentifier)("ui.contextmenu.host.service");
@@ -3864,9 +4161,11 @@ function getContextMenuSubmenuPanelClassName(sizeVariant) {
3864
4161
  }
3865
4162
  function ContextMenuPanel(props) {
3866
4163
  var _layoutService$rootCo, _layoutService$rootCo2;
3867
- const { menuType, menuSessionVersion = 0, className, activeItemIds, hiddenItemIds, sizeVariant = "default", autoFocus, autoFocusTarget = "first-item", suppressHoverUntilPointerMove = false, onCancel, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect } = props;
3868
- const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
3869
- const layoutService = (0, _wendellhu_redi_react_bindings.useDependency)(ILayoutService);
4164
+ const { menuType, menuManagerService: providedMenuManagerService, layoutService: providedLayoutService, menuSessionVersion = 0, className, activeItemIds, hiddenItemIds, sizeVariant = "default", autoFocus, autoFocusTarget = "first-item", suppressHoverUntilPointerMove = false, onCancel, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect } = props;
4165
+ const rootMenuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
4166
+ const rootLayoutService = (0, _wendellhu_redi_react_bindings.useDependency)(ILayoutService);
4167
+ const menuManagerService = providedMenuManagerService !== null && providedMenuManagerService !== void 0 ? providedMenuManagerService : rootMenuManagerService;
4168
+ const layoutService = providedLayoutService !== null && providedLayoutService !== void 0 ? providedLayoutService : rootLayoutService;
3870
4169
  const [menuElement, setMenuElement] = (0, react.useState)(null);
3871
4170
  const [maxMenuHeight, setMaxMenuHeight] = (0, react.useState)(() => {
3872
4171
  if (typeof window === "undefined") return 240;
@@ -3969,6 +4268,7 @@ function ContextMenuPanel(props) {
3969
4268
  onWheel: (event) => event.stopPropagation(),
3970
4269
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenu, {
3971
4270
  menuSchemas: menuItems,
4271
+ menuManagerService,
3972
4272
  menuSessionVersion,
3973
4273
  submenuPortalContainer,
3974
4274
  rootMenuElement: menuElement,
@@ -3984,7 +4284,7 @@ function ContextMenuPanel(props) {
3984
4284
  });
3985
4285
  }
3986
4286
  function ContextMenuMenu(props) {
3987
- const { menuSchemas, menuSessionVersion, submenuPortalContainer, rootMenuElement, activeItemIds, hiddenItemIds, hoverSuppressed, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect, maxMenuHeight } = props;
4287
+ const { menuSchemas, menuManagerService, menuSessionVersion, submenuPortalContainer, rootMenuElement, activeItemIds, hiddenItemIds, hoverSuppressed, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect, maxMenuHeight } = props;
3988
4288
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
3989
4289
  const hiddenGroupStates = useContextGroupHiddenStates$1(menuSchemas);
3990
4290
  const [activeSubmenuKey, setActiveSubmenuKey] = (0, react.useState)(null);
@@ -4030,6 +4330,7 @@ function ContextMenuMenu(props) {
4030
4330
  if (menuSchema.item) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenuItem, {
4031
4331
  menuKey: menuSchema.key,
4032
4332
  menuItem: menuSchema.item,
4333
+ menuManagerService,
4033
4334
  menuSessionVersion,
4034
4335
  submenuPortalContainer,
4035
4336
  rootMenuElement,
@@ -4050,6 +4351,7 @@ function ContextMenuMenu(props) {
4050
4351
  children: menuSchema.children.map((childSchema) => childSchema.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenuItem, {
4051
4352
  menuKey: childSchema.key,
4052
4353
  menuItem: childSchema.item,
4354
+ menuManagerService,
4053
4355
  menuSessionVersion,
4054
4356
  submenuPortalContainer,
4055
4357
  rootMenuElement,
@@ -4071,6 +4373,7 @@ function ContextMenuMenu(props) {
4071
4373
  children: [titleNode, menuSchema.children.map((childSchema) => childSchema.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenuItem, {
4072
4374
  menuKey: childSchema.key,
4073
4375
  menuItem: childSchema.item,
4376
+ menuManagerService,
4074
4377
  menuSessionVersion,
4075
4378
  submenuPortalContainer,
4076
4379
  rootMenuElement,
@@ -4099,6 +4402,7 @@ function ContextMenuMenu(props) {
4099
4402
  children: [titleContent, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenuItem, {
4100
4403
  menuKey: `${menuSchema.key}-header-action`,
4101
4404
  menuItem: menuSchema.headerActionItem,
4405
+ menuManagerService,
4102
4406
  menuSessionVersion,
4103
4407
  submenuPortalContainer,
4104
4408
  rootMenuElement,
@@ -4119,10 +4423,9 @@ function ContextMenuMenu(props) {
4119
4423
  }
4120
4424
  }
4121
4425
  function ContextMenuMenuItem(props) {
4122
- const { menuKey, menuItem, menuSessionVersion, submenuPortalContainer, rootMenuElement, maxMenuHeight, activeSubmenuKey, setActiveSubmenuKey, activeItemIds, hiddenItemIds = [], hoverSuppressed = false, compact = false, headerAction = false, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect } = props;
4426
+ const { menuKey, menuItem, menuManagerService, menuSessionVersion, submenuPortalContainer, rootMenuElement, maxMenuHeight, activeSubmenuKey, setActiveSubmenuKey, activeItemIds, hiddenItemIds = [], hoverSuppressed = false, compact = false, headerAction = false, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect } = props;
4123
4427
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
4124
4428
  const direction = (0, _wendellhu_redi_react_bindings.useObservable)(localeService.direction$);
4125
- const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
4126
4429
  const disabled = (0, _wendellhu_redi_react_bindings.useObservable)(menuItem.disabled$, false);
4127
4430
  const activated = (0, _wendellhu_redi_react_bindings.useObservable)(menuItem.activated$, false);
4128
4431
  const hidden = (0, _wendellhu_redi_react_bindings.useObservable)(menuItem.hidden$, false);
@@ -4254,6 +4557,7 @@ function ContextMenuMenuItem(props) {
4254
4557
  });
4255
4558
  const canExecuteItem = menuItem.type === 0 || menuItem.type === 2;
4256
4559
  const renderAsContainer = isNonSelectableLabel(menuItem.label);
4560
+ const SubmenuAffordanceIcon = direction === "rtl" ? _univerjs_icons.MoreLeftIcon : _univerjs_icons.MoreRightIcon;
4257
4561
  const interactiveItemClassName = (0, _univerjs_design.clsx)(itemClassName, isNonHoverableLabel(menuItem.label) && "hover:univer-bg-transparent dark:hover:!univer-bg-transparent");
4258
4562
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4259
4563
  ref: menuItemElementRef,
@@ -4282,7 +4586,7 @@ function ContextMenuMenuItem(props) {
4282
4586
  children: [renderAsContainer ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4283
4587
  className: interactiveItemClassName,
4284
4588
  "aria-disabled": disabled,
4285
- children: [contentNode, hasSubmenu && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, { className: `
4589
+ children: [contentNode, hasSubmenu && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SubmenuAffordanceIcon, { className: `
4286
4590
  ${sizeVariant === "paragraph-t" ? "univer-size-4" : "univer-size-3.5"}
4287
4591
  univer-text-gray-400
4288
4592
  dark:!univer-text-gray-200
@@ -4325,7 +4629,7 @@ function ContextMenuMenuItem(props) {
4325
4629
  label: menuKey
4326
4630
  });
4327
4631
  },
4328
- children: [contentNode, hasSubmenu && !compact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, { className: `
4632
+ children: [contentNode, hasSubmenu && !compact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SubmenuAffordanceIcon, { className: `
4329
4633
  ${sizeVariant === "paragraph-t" ? "univer-size-4" : "univer-size-3.5"}
4330
4634
  univer-text-gray-400
4331
4635
  dark:!univer-text-gray-200
@@ -4372,7 +4676,7 @@ function ContextMenuMenuItem(props) {
4372
4676
  const optionSelected = typeof inputValue !== "undefined" && String(inputValue) === String(option.value);
4373
4677
  const optionSelectable = !isNonSelectableLabel(option.label);
4374
4678
  const optionHoverable = !isNonHoverableLabel(option.label);
4375
- const optionClassName = (0, _univerjs_design.clsx)(sizeVariant === "paragraph-t" ? "univer-relative univer-box-border univer-flex univer-min-h-10 univer-w-full univer-items-center univer-rounded-lg univer-border-none univer-bg-transparent univer-px-3 univer-text-left univer-text-base dark:!univer-text-white" : "univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-items-center univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm dark:!univer-text-white", option.disabled ? "univer-cursor-not-allowed univer-opacity-60" : optionHoverable && "univer-cursor-pointer hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600");
4679
+ const optionClassName = (0, _univerjs_design.clsx)(optionSelectable ? sizeVariant === "paragraph-t" ? "univer-relative univer-box-border univer-flex univer-min-h-10 univer-w-full univer-items-center univer-rounded-lg univer-border-none univer-bg-transparent univer-px-3 univer-text-left univer-text-base dark:!univer-text-white" : "univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-items-center univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm dark:!univer-text-white" : "univer-relative univer-box-border univer-block univer-w-full univer-border-none univer-bg-transparent univer-p-0", option.disabled ? "univer-cursor-not-allowed univer-opacity-60" : optionHoverable && "univer-cursor-pointer hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600");
4376
4680
  const optionContentNode = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [optionSelectable && optionSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: (0, _univerjs_design.clsx)("univer-absolute univer-left-0 univer-text-primary-600", sizeVariant === "paragraph-t" ? "univer-size-5" : "univer-size-4") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4377
4681
  className: (0, _univerjs_design.clsx)(getContextMenuContentClassName(sizeVariant), optionSelectable && optionSelected && "univer-pl-4"),
4378
4682
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CustomLabel, {
@@ -4414,6 +4718,7 @@ function ContextMenuMenuItem(props) {
4414
4718
  })
4415
4719
  }), hasSubItemSubmenu && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuMenu, {
4416
4720
  menuSchemas: subMenuItems,
4721
+ menuManagerService,
4417
4722
  menuSessionVersion,
4418
4723
  submenuPortalContainer,
4419
4724
  rootMenuElement,
@@ -4458,7 +4763,7 @@ function useContextGroupHiddenStates$1(menuSchemas) {
4458
4763
  //#endregion
4459
4764
  //#region src/views/components/context-menu/AnchoredContextMenu.tsx
4460
4765
  function AnchoredContextMenu(props) {
4461
- const { hostId, visible, anchorRect, menuType, anchorVertical = "bottom", menuOffset = 0, onRequestClose, onOptionSelect } = props;
4766
+ const { hostId, visible, anchorRect, menuType, anchorVertical = "bottom", menuOffset = 0, menuManagerService, layoutService, onRequestClose, onOptionSelect } = props;
4462
4767
  const contentRef = (0, react.useRef)(null);
4463
4768
  const contextMenuHostService = (0, _wendellhu_redi_react_bindings.useDependency)(IContextMenuHostService);
4464
4769
  const onRequestCloseRef = (0, react.useRef)(onRequestClose);
@@ -4547,6 +4852,8 @@ function AnchoredContextMenu(props) {
4547
4852
  ref: contentRef,
4548
4853
  children: menuType && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenuPanel, {
4549
4854
  menuType,
4855
+ menuManagerService,
4856
+ layoutService,
4550
4857
  menuSessionVersion: menuSessionVersionRef.current,
4551
4858
  onOptionSelect
4552
4859
  })
@@ -4561,10 +4868,13 @@ function DesktopContextMenu() {
4561
4868
  const [visible, setVisible] = (0, react.useState)(false);
4562
4869
  const [menuType, setMenuType] = (0, react.useState)("");
4563
4870
  const [anchorRect, setAnchorRect] = (0, react.useState)(null);
4871
+ const [menuContext, setMenuContext] = (0, react.useState)();
4564
4872
  const visibleRef = (0, react.useRef)(visible);
4565
4873
  const contextMenuService = (0, _wendellhu_redi_react_bindings.useDependency)(IContextMenuService);
4566
4874
  const commandService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.ICommandService);
4567
- const injector = (0, _wendellhu_redi_react_bindings.useInjector)();
4875
+ const layoutService = (0, _wendellhu_redi_react_bindings.useDependency)(ILayoutService);
4876
+ const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
4877
+ const runtimeScopeService = (0, _wendellhu_redi_react_bindings.useDependency)(IUIRuntimeScopeService);
4568
4878
  visibleRef.current = visible;
4569
4879
  (0, react.useEffect)(() => {
4570
4880
  const disposables = contextMenuService.registerContextMenuHandler({
@@ -4581,10 +4891,11 @@ function DesktopContextMenu() {
4581
4891
  };
4582
4892
  }, [contextMenuService]);
4583
4893
  /** A function to open context menu with given position and menu type. */
4584
- function handleContextMenu(event, menuType) {
4894
+ function handleContextMenu(event, menuType, context) {
4585
4895
  setVisible(false);
4586
4896
  requestAnimationFrame(() => {
4587
4897
  setMenuType(menuType);
4898
+ setMenuContext(context);
4588
4899
  setAnchorRect({
4589
4900
  left: event.clientX,
4590
4901
  top: event.clientY,
@@ -4596,18 +4907,24 @@ function DesktopContextMenu() {
4596
4907
  function handleClose() {
4597
4908
  setVisible(false);
4598
4909
  }
4910
+ const activeScope = runtimeScopeService.get(menuContext === null || menuContext === void 0 ? void 0 : menuContext.unitId);
4911
+ const activeMenuManagerService = (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(IMenuManagerService)) ? activeScope.get(IMenuManagerService) : menuManagerService;
4912
+ const activeCommandService = (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(_univerjs_core.ICommandService)) ? activeScope.get(_univerjs_core.ICommandService) : commandService;
4913
+ const activeLayoutService = (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(ILayoutService)) ? activeScope.get(ILayoutService) : layoutService;
4599
4914
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AnchoredContextMenu, {
4600
4915
  hostId: DESKTOP_CONTEXT_MENU_HOST_ID,
4601
4916
  visible,
4602
4917
  anchorRect,
4603
4918
  menuType,
4919
+ menuManagerService: activeMenuManagerService,
4920
+ layoutService: activeLayoutService,
4604
4921
  onRequestClose: handleClose,
4605
4922
  onOptionSelect: (params) => {
4606
4923
  const { label: id, commandId, value } = params;
4607
4924
  const rawParams = typeof params.params === "function" ? params.params() : params.params;
4608
4925
  const commandParams = typeof rawParams === "undefined" ? { value } : rawParams;
4609
- if (commandService) commandService.executeCommand(commandId !== null && commandId !== void 0 ? commandId : id, commandParams);
4610
- injector.get(ILayoutService).focus();
4926
+ if (activeCommandService) activeCommandService.executeCommand(commandId !== null && commandId !== void 0 ? commandId : id, commandParams);
4927
+ activeLayoutService.focus();
4611
4928
  handleClose();
4612
4929
  }
4613
4930
  });
@@ -5183,7 +5500,9 @@ var SingleUnitUIController = class extends _univerjs_core.Disposable {
5183
5500
  }));
5184
5501
  }
5185
5502
  _changeRenderUnit(rendererId, contentElement) {
5503
+ var _this$_instanceServic2;
5186
5504
  if (this._currentRenderId === rendererId) return false;
5505
+ if ((_this$_instanceServic2 = this._instanceService.getUnitCreateOptions(rendererId)) === null || _this$_instanceServic2 === void 0 ? void 0 : _this$_instanceServic2.embeddedRender) return false;
5187
5506
  const renderer = this._renderManagerService.getRenderById(rendererId);
5188
5507
  if (!renderer || !renderer.unitId || (0, _univerjs_core.isInternalEditorID)(renderer.unitId)) return false;
5189
5508
  const currentRenderer = this._currentRenderId ? this._renderManagerService.getRenderById(this._currentRenderId) : null;
@@ -5261,7 +5580,7 @@ const IUIController = (0, _univerjs_core.createIdentifier)("univer.ui.ui-control
5261
5580
  //#endregion
5262
5581
  //#region package.json
5263
5582
  var name = "@univerjs/ui";
5264
- var version = "1.0.0-alpha.2";
5583
+ var version = "1.0.0-alpha.3";
5265
5584
 
5266
5585
  //#endregion
5267
5586
  //#region src/views/color-picker/interface.ts
@@ -20291,15 +20610,13 @@ function EmojiPicker(props) {
20291
20610
  children: [
20292
20611
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20293
20612
  className: "univer-flex univer-items-center univer-gap-1 univer-px-3 univer-pb-2 univer-pt-3",
20294
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
20295
- className: "univer-flex univer-h-8 univer-flex-1 univer-items-center univer-gap-1 univer-rounded-lg univer-border univer-border-solid univer-border-primary-500 univer-px-2 univer-text-gray-500 dark:!univer-border-primary-600 dark:!univer-text-gray-400",
20296
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SearchIcon, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
20297
- "aria-label": localeService.t("ui.emojiPicker.search"),
20298
- placeholder: localeService.t("ui.emojiPicker.search"),
20299
- className: "univer-min-w-0 univer-flex-1",
20300
- value: query,
20301
- onChange: setQuery
20302
- })]
20613
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
20614
+ "aria-label": localeService.t("ui.emojiPicker.search"),
20615
+ placeholder: localeService.t("ui.emojiPicker.search"),
20616
+ className: "univer-min-w-0 univer-flex-1",
20617
+ value: query,
20618
+ onChange: setQuery,
20619
+ slot: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SearchIcon, { className: "univer-size-4 univer-text-gray-500 dark:!univer-text-gray-400" })
20303
20620
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
20304
20621
  type: "button",
20305
20622
  "aria-label": localeService.t("ui.emojiPicker.random"),
@@ -20333,12 +20650,12 @@ function EmojiPicker(props) {
20333
20650
  className: (0, _univerjs_design.clsx)("univer-flex univer-h-10 univer-shrink-0 univer-items-center univer-border-gray-200 univer-px-2.5 dark:!univer-border-gray-600 [&_svg]:univer-size-5", _univerjs_design.borderTopClassName),
20334
20651
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CategoryButton, {
20335
20652
  selected: !isSearching && activeTab === "recent",
20336
- title: localeService.t("ui.emojiPicker.recents"),
20653
+ titleKey: "ui.emojiPicker.recents",
20337
20654
  onClick: () => scrollToSection("recent"),
20338
20655
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.RecentIcon, {})
20339
20656
  }), EMOJI_CATEGORIES.map((category) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CategoryButton, {
20340
20657
  selected: !isSearching && activeTab === category.key,
20341
- title: localeService.t(category.titleKey),
20658
+ titleKey: category.titleKey,
20342
20659
  onClick: () => scrollToSection(category.key),
20343
20660
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CategoryIcon, { category: category.key })
20344
20661
  }, category.key))]
@@ -20379,11 +20696,12 @@ function EmojiGrid(props) {
20379
20696
  });
20380
20697
  }
20381
20698
  function CategoryButton(props) {
20699
+ const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
20382
20700
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
20383
20701
  type: "button",
20384
- "aria-label": props.title,
20702
+ "aria-label": localeService.t(props.titleKey),
20385
20703
  "aria-selected": props.selected,
20386
- title: props.title,
20704
+ title: localeService.t(props.titleKey),
20387
20705
  className: (0, _univerjs_design.clsx)("univer-flex univer-h-[30px] univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent univer-p-0 univer-text-gray-500 dark:!univer-text-gray-400", props.selected ? "univer-bg-primary-50 univer-text-primary-500 dark:!univer-bg-gray-800 dark:!univer-text-primary-400" : "hover:univer-bg-gray-50 hover:univer-text-gray-700 dark:hover:!univer-bg-gray-800 dark:hover:!univer-text-gray-300"),
20388
20706
  onClick: props.onClick,
20389
20707
  children: props.children
@@ -20653,11 +20971,13 @@ const FontFamily = ({ className, disabled: disabledProp, value, disabled$, onCha
20653
20971
  const FONT_FAMILY_ITEM_COMPONENT = "UI_FONT_FAMILY_ITEM_COMPONENT";
20654
20972
  const FontFamilyItem = ({ value, onChange }) => {
20655
20973
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
20974
+ const direction = (0, _wendellhu_redi_react_bindings.useObservable)(localeService.direction$, localeService.getDirection());
20656
20975
  const { fonts, fontService } = useFontList();
20657
20976
  function handleSelectFont(nextValue) {
20658
20977
  onChange(nextValue);
20659
20978
  }
20660
20979
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
20980
+ dir: direction,
20661
20981
  className: "univer-m-0 univer-list-none univer-p-0 univer-text-sm",
20662
20982
  style: { fontFamily: value },
20663
20983
  children: fonts.map((font) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
@@ -20677,6 +20997,8 @@ const FontFamilyItem = ({ value, onChange }) => {
20677
20997
  //#region src/views/font-family/FontFamilyDropdown.tsx
20678
20998
  function FontFamilyDropdown(props) {
20679
20999
  const { value, onChange, ariaLabel, className, disabled: disabledProp, disabled$, inputClassName, popupClassName, popupDataComponent, title, onMouseDown, onPointerDown } = props;
21000
+ const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
21001
+ const direction = (0, _wendellhu_redi_react_bindings.useObservable)(localeService.direction$, localeService.getDirection());
20680
21002
  const disabledObservableValue = (0, _wendellhu_redi_react_bindings.useObservable)(disabled$);
20681
21003
  const disabled = Boolean(disabledProp || disabledObservableValue);
20682
21004
  const [open, setOpen] = (0, react.useState)(false);
@@ -20690,6 +21012,7 @@ function FontFamilyDropdown(props) {
20690
21012
  open,
20691
21013
  onOpenChange: setOpen,
20692
21014
  overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
21015
+ dir: direction,
20693
21016
  className: (0, _univerjs_design.clsx)("univer-max-h-72 univer-min-w-44 univer-overflow-y-auto univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-white univer-p-1 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900", popupClassName),
20694
21017
  ...popupDataAttributes,
20695
21018
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontFamilyItem, {
@@ -20701,6 +21024,7 @@ function FontFamilyDropdown(props) {
20701
21024
  "aria-disabled": disabled,
20702
21025
  "aria-expanded": open,
20703
21026
  "aria-label": ariaLabel,
21027
+ dir: direction,
20704
21028
  className: (0, _univerjs_design.clsx)("univer-flex univer-h-6 univer-min-w-0 univer-cursor-default univer-items-center univer-justify-between univer-gap-1 univer-rounded-md univer-px-1.5 univer-text-sm univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-cursor-not-allowed univer-opacity-60": disabled }, className),
20705
21029
  role: "combobox",
20706
21030
  tabIndex: disabled ? -1 : 0,
@@ -21188,14 +21512,6 @@ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)
21188
21512
  //#endregion
21189
21513
  //#region src/views/components/ribbon/MobileRibbon.tsx
21190
21514
  const toolbarScrollOffset = 168;
21191
- const nestedControlResetClassName = `
21192
- [&_button]:!univer-m-0 [&_button]:!univer-appearance-none [&_button]:!univer-border-0
21193
- [&_button]:!univer-bg-transparent [&_button]:!univer-p-0 [&_button]:!univer-leading-none
21194
- [&_button]:!univer-outline-none
21195
- [&_input]:!univer-m-0 [&_input]:!univer-appearance-none [&_input]:!univer-border-0
21196
- [&_input]:!univer-bg-transparent [&_input]:!univer-p-0 [&_input]:!univer-leading-none
21197
- [&_input]:!univer-outline-none
21198
- `;
21199
21515
  function MobileRibbon(props) {
21200
21516
  var _activeGroup$children;
21201
21517
  const { headerMenuComponents, headerMenu = true } = props;
@@ -21335,7 +21651,7 @@ function MobileRibbon(props) {
21335
21651
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
21336
21652
  className: (0, _univerjs_design.clsx)("univer-flex univer-shrink-0 univer-items-center univer-gap-0.5 univer-pr-1.5 rtl:univer-pl-1.5 rtl:univer-pr-0", { [_univerjs_design.borderRightClassName]: groupIndex !== activeGroups.length - 1 }),
21337
21653
  children: groupItems.map((child) => child.item && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
21338
- className: (0, _univerjs_design.clsx)("[&_button]:!univer-font-inherit univer-flex univer-h-8 univer-shrink-0 univer-items-center univer-rounded-md [&_*]:univer-box-border [&_.univer-custom-label]:univer-text-sm [&_.univer-custom-label]:univer-leading-none [&_.univer-toolbar-button-selector-main]:!univer-h-8 [&_.univer-toolbar-button-selector-main]:!univer-rounded-none [&_.univer-toolbar-button-selector-main]:!univer-rounded-l-md [&_.univer-toolbar-button-selector-main]:!univer-px-1.5 [&_.univer-toolbar-button-selector-root]:!univer-h-8 [&_.univer-toolbar-button-selector-root]:univer-overflow-hidden [&_.univer-toolbar-button-selector-root]:!univer-rounded-md [&_.univer-toolbar-button-selector-root]:!univer-pr-0 [&_.univer-toolbar-button-selector-trigger]:!univer-static [&_.univer-toolbar-button-selector-trigger]:!univer-h-8 [&_.univer-toolbar-button-selector-trigger]:!univer-w-6 [&_.univer-toolbar-button-selector-trigger]:!univer-rounded-none [&_.univer-toolbar-button-selector-trigger]:!univer-rounded-r-md [&_.univer-toolbar-selector-root]:!univer-h-8 [&_.univer-toolbar-selector-root]:!univer-gap-1 [&_.univer-toolbar-selector-root]:!univer-rounded-md [&_.univer-toolbar-selector-root]:!univer-px-1.5 [&_.univer-toolbar-selector-trigger]:!univer-pl-0.5 [&_.univer-tooltip]:univer-inline-flex [&_.univer-tooltip]:univer-h-full [&_.univer-tooltip]:univer-items-center [&_[data-u-command]]:!univer-h-8 [&_[data-u-command]]:!univer-min-h-8 [&_[data-u-command]]:!univer-rounded-md [&_[data-u-command]]:!univer-px-1.5 [&_button]:!univer-h-8 [&_button]:!univer-min-w-8 [&_button]:!univer-rounded-md [&_button]:!univer-px-1.5", nestedControlResetClassName),
21654
+ className: (0, _univerjs_design.clsx)("[&_button]:!univer-font-inherit univer-flex univer-h-8 univer-shrink-0 univer-items-center univer-rounded-md [&_*]:univer-box-border [&_.univer-custom-label]:univer-text-sm [&_.univer-custom-label]:univer-leading-none [&_.univer-toolbar-button-selector-main]:!univer-h-8 [&_.univer-toolbar-button-selector-main]:!univer-rounded-none [&_.univer-toolbar-button-selector-main]:!univer-rounded-l-md [&_.univer-toolbar-button-selector-main]:!univer-px-1.5 [&_.univer-toolbar-button-selector-root]:!univer-h-8 [&_.univer-toolbar-button-selector-root]:univer-overflow-hidden [&_.univer-toolbar-button-selector-root]:!univer-rounded-md [&_.univer-toolbar-button-selector-root]:!univer-pr-0 [&_.univer-toolbar-button-selector-trigger]:!univer-static [&_.univer-toolbar-button-selector-trigger]:!univer-h-8 [&_.univer-toolbar-button-selector-trigger]:!univer-w-6 [&_.univer-toolbar-button-selector-trigger]:!univer-rounded-none [&_.univer-toolbar-button-selector-trigger]:!univer-rounded-r-md [&_.univer-toolbar-selector-root]:!univer-h-8 [&_.univer-toolbar-selector-root]:!univer-gap-1 [&_.univer-toolbar-selector-root]:!univer-rounded-md [&_.univer-toolbar-selector-root]:!univer-px-1.5 [&_.univer-toolbar-selector-trigger]:!univer-pl-0.5 [&_.univer-tooltip]:univer-inline-flex [&_.univer-tooltip]:univer-h-full [&_.univer-tooltip]:univer-items-center [&_[data-u-command]]:!univer-h-8 [&_[data-u-command]]:!univer-min-h-8 [&_[data-u-command]]:!univer-rounded-md [&_[data-u-command]]:!univer-px-1.5 [&_button]:!univer-m-0 [&_button]:!univer-h-8 [&_button]:!univer-min-w-8 [&_button]:!univer-appearance-none [&_button]:!univer-rounded-md [&_button]:!univer-border-0 [&_button]:!univer-bg-transparent [&_button]:!univer-p-0 [&_button]:!univer-px-1.5 [&_button]:!univer-leading-none [&_button]:!univer-outline-none [&_input]:!univer-m-0 [&_input]:!univer-appearance-none [&_input]:!univer-border-0 [&_input]:!univer-bg-transparent [&_input]:!univer-p-0 [&_input]:!univer-leading-none [&_input]:!univer-outline-none"),
21339
21655
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarItem, { ...child.item })
21340
21656
  }, child.key))
21341
21657
  }, groupItem.key);
@@ -21362,8 +21678,9 @@ function MobileRibbon(props) {
21362
21678
  //#region src/views/menu/mobile/MobileMenu.tsx
21363
21679
  function MobileMenu(props) {
21364
21680
  var _viewStack;
21365
- const { menuType, onOptionSelect, schemas: providedSchemas } = props;
21366
- const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
21681
+ const { menuType, onOptionSelect, schemas: providedSchemas, menuManagerService: providedMenuManagerService } = props;
21682
+ const rootMenuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
21683
+ const menuManagerService = providedMenuManagerService !== null && providedMenuManagerService !== void 0 ? providedMenuManagerService : rootMenuManagerService;
21367
21684
  const [viewStack, setViewStack] = (0, react.useState)([]);
21368
21685
  const menuSchemas = (0, react.useMemo)(() => {
21369
21686
  if (providedSchemas) return providedSchemas;
@@ -21411,6 +21728,7 @@ function MobileMenu(props) {
21411
21728
  className: "univer-overflow-hidden univer-rounded-2xl univer-bg-white",
21412
21729
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MobileSchemaList, {
21413
21730
  schemas: (currentView === null || currentView === void 0 ? void 0 : currentView.kind) === "schema" ? currentView.schemas : menuSchemas,
21731
+ menuManagerService,
21414
21732
  menuType,
21415
21733
  onExecute: onOptionSelect,
21416
21734
  onOpenView: openView
@@ -21429,7 +21747,7 @@ function MobileMenu(props) {
21429
21747
  });
21430
21748
  }
21431
21749
  function MobileSchemaList(props) {
21432
- const { schemas, menuType, onExecute, onOpenView } = props;
21750
+ const { schemas, menuManagerService, menuType, onExecute, onOpenView } = props;
21433
21751
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
21434
21752
  const hiddenGroupStates = useContextGroupHiddenStates(schemas);
21435
21753
  const visibleSchemas = (0, react.useMemo)(() => {
@@ -21443,6 +21761,7 @@ function MobileSchemaList(props) {
21443
21761
  var _schema$children2;
21444
21762
  if (schema.item) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MobileSchemaRow, {
21445
21763
  schema,
21764
+ menuManagerService,
21446
21765
  menuType,
21447
21766
  onExecute,
21448
21767
  onOpenView,
@@ -21456,6 +21775,7 @@ function MobileSchemaList(props) {
21456
21775
  children: localeService.t(schema.title)
21457
21776
  }), schema.children.map((childSchema, childIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MobileSchemaRow, {
21458
21777
  schema: childSchema,
21778
+ menuManagerService,
21459
21779
  menuType,
21460
21780
  onExecute,
21461
21781
  onOpenView,
@@ -21465,9 +21785,10 @@ function MobileSchemaList(props) {
21465
21785
  }) });
21466
21786
  }
21467
21787
  function MobileSchemaRow(props) {
21468
- const { schema, menuType, onExecute, onOpenView, bordered } = props;
21788
+ const { schema, menuManagerService, menuType, onExecute, onOpenView, bordered } = props;
21469
21789
  const interaction = useMobileSchemaInteraction({
21470
21790
  schema,
21791
+ menuManagerService,
21471
21792
  menuType,
21472
21793
  onOpenView
21473
21794
  });
@@ -21542,8 +21863,7 @@ function MobileSelectionOptionRow(props) {
21542
21863
  }
21543
21864
  function useMobileSchemaInteraction(props) {
21544
21865
  var _schema$children3;
21545
- const { schema, menuType, onOpenView } = props;
21546
- const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
21866
+ const { schema, menuManagerService, menuType, onOpenView } = props;
21547
21867
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
21548
21868
  const menuItem = schema.item;
21549
21869
  const selectorItem = menuItem;
@@ -21664,11 +21984,14 @@ const MOBILE_CONTEXT_MENU_HOST_ID = "mobile-context-menu";
21664
21984
  function MobileContextMenu() {
21665
21985
  const [visible, setVisible] = (0, react.useState)(false);
21666
21986
  const [menuType, setMenuType] = (0, react.useState)("");
21987
+ const [menuContext, setMenuContext] = (0, react.useState)();
21667
21988
  const visibleRef = (0, react.useRef)(visible);
21668
21989
  const contextMenuHostService = (0, _wendellhu_redi_react_bindings.useDependency)(IContextMenuHostService);
21669
21990
  const contextMenuService = (0, _wendellhu_redi_react_bindings.useDependency)(IContextMenuService);
21670
21991
  const commandService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.ICommandService);
21671
21992
  const layoutService = (0, _wendellhu_redi_react_bindings.useDependency)(ILayoutService);
21993
+ const menuManagerService = (0, _wendellhu_redi_react_bindings.useDependency)(IMenuManagerService);
21994
+ const runtimeScopeService = (0, _wendellhu_redi_react_bindings.useDependency)(IUIRuntimeScopeService);
21672
21995
  const localeService = (0, _wendellhu_redi_react_bindings.useDependency)(_univerjs_core.LocaleService);
21673
21996
  const direction = (0, _wendellhu_redi_react_bindings.useObservable)(localeService.direction$);
21674
21997
  const { mountContainer } = (0, react.useContext)(_univerjs_design.ConfigContext);
@@ -21692,9 +22015,10 @@ function MobileContextMenu() {
21692
22015
  contextMenuHostService.deactivateMenu(MOBILE_CONTEXT_MENU_HOST_ID);
21693
22016
  };
21694
22017
  }, [contextMenuHostService, contextMenuService]);
21695
- function handleContextMenu(_event, nextMenuType) {
22018
+ function handleContextMenu(_event, nextMenuType, context) {
21696
22019
  contextMenuHostService.activateMenu(MOBILE_CONTEXT_MENU_HOST_ID);
21697
22020
  setMenuType(nextMenuType);
22021
+ setMenuContext(context);
21698
22022
  setVisible(true);
21699
22023
  }
21700
22024
  function handleClose() {
@@ -21709,6 +22033,23 @@ function MobileContextMenu() {
21709
22033
  }
21710
22034
  }, [localeService, menuType]);
21711
22035
  if (!mountContainer || !visible) return null;
22036
+ const activeScope = runtimeScopeService.get(menuContext === null || menuContext === void 0 ? void 0 : menuContext.unitId);
22037
+ const activeCommandService = (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(_univerjs_core.ICommandService)) ? activeScope.get(_univerjs_core.ICommandService) : commandService;
22038
+ const activeLayoutService = (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(ILayoutService)) ? activeScope.get(ILayoutService) : layoutService;
22039
+ const menu = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MobileMenu, {
22040
+ menuType,
22041
+ menuManagerService: (activeScope === null || activeScope === void 0 ? void 0 : activeScope.has(IMenuManagerService)) ? activeScope.get(IMenuManagerService) : menuManagerService,
22042
+ onOptionSelect: (params) => {
22043
+ var _ref, _params$commandId;
22044
+ const commandId = (_ref = (_params$commandId = params.commandId) !== null && _params$commandId !== void 0 ? _params$commandId : params.id) !== null && _ref !== void 0 ? _ref : params.label;
22045
+ const fallbackParams = typeof params.params === "function" ? params.params() : params.params;
22046
+ const commandParams = typeof params.value === "undefined" ? fallbackParams : { value: params.value };
22047
+ if (!commandId) return;
22048
+ activeLayoutService.focus();
22049
+ activeCommandService.executeCommand(commandId, commandParams);
22050
+ handleClose();
22051
+ }
22052
+ });
21712
22053
  return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
21713
22054
  dir: direction,
21714
22055
  className: "univer-fixed univer-inset-0 univer-z-[1080] univer-flex univer-items-end",
@@ -21742,19 +22083,7 @@ function MobileContextMenu() {
21742
22083
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CloseIcon, { className: "univer-size-4 univer-text-current" })
21743
22084
  })]
21744
22085
  })]
21745
- }), menuType && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MobileMenu, {
21746
- menuType,
21747
- onOptionSelect: (params) => {
21748
- var _ref, _params$commandId;
21749
- const commandId = (_ref = (_params$commandId = params.commandId) !== null && _params$commandId !== void 0 ? _params$commandId : params.id) !== null && _ref !== void 0 ? _ref : params.label;
21750
- const fallbackParams = typeof params.params === "function" ? params.params() : params.params;
21751
- const commandParams = typeof params.value === "undefined" ? fallbackParams : { value: params.value };
21752
- if (!commandId) return;
21753
- layoutService.focus();
21754
- commandService.executeCommand(commandId, commandParams);
21755
- handleClose();
21756
- }
21757
- })]
22086
+ }), menuType && menu]
21758
22087
  })]
21759
22088
  }), mountContainer);
21760
22089
  }
@@ -23119,6 +23448,7 @@ let UniverMobileUIPlugin = class UniverMobileUIPlugin extends _univerjs_core.Plu
23119
23448
  [IMenuManagerService, { useClass: MenuManagerService }],
23120
23449
  [IContextMenuHostService, { useClass: ContextMenuHostService }],
23121
23450
  [IContextMenuService, { useClass: ContextMenuService }],
23451
+ [IUIRuntimeScopeService, { useClass: UIRuntimeScopeService }],
23122
23452
  [IClipboardInterfaceService, {
23123
23453
  useClass: BrowserClipboardService,
23124
23454
  lazy: true
@@ -23156,6 +23486,7 @@ let UniverMobileUIPlugin = class UniverMobileUIPlugin extends _univerjs_core.Plu
23156
23486
  [ICanvasPopupService, { useClass: CanvasPopupService }],
23157
23487
  [IFontService, { useClass: FontService }],
23158
23488
  [CanvasFloatDomService],
23489
+ [CanvasFloatDomPreviewService],
23159
23490
  [IUIController, {
23160
23491
  useFactory: (injector) => injector.createInstance(MobileUIController, this._config),
23161
23492
  deps: [_univerjs_core.Injector]
@@ -23213,11 +23544,13 @@ let UniverUIPlugin = class UniverUIPlugin extends _univerjs_core.Plugin {
23213
23544
  [IUIPartsService, { useClass: UIPartsService }],
23214
23545
  [ILayoutService, { useClass: DesktopLayoutService }],
23215
23546
  [IRibbonService, { useClass: DesktopRibbonService }],
23547
+ [IRibbonOverrideService, { useClass: RibbonOverrideService }],
23216
23548
  [IShortcutService, { useClass: ShortcutService }],
23217
23549
  [IPlatformService, { useClass: PlatformService }],
23218
23550
  [IMenuManagerService, { useClass: MenuManagerService }],
23219
23551
  [IContextMenuHostService, { useClass: ContextMenuHostService }],
23220
23552
  [IContextMenuService, { useClass: ContextMenuService }],
23553
+ [IUIRuntimeScopeService, { useClass: UIRuntimeScopeService }],
23221
23554
  [IClipboardInterfaceService, {
23222
23555
  useClass: BrowserClipboardService,
23223
23556
  lazy: true
@@ -23255,6 +23588,7 @@ let UniverUIPlugin = class UniverUIPlugin extends _univerjs_core.Plugin {
23255
23588
  [ICanvasPopupService, { useClass: CanvasPopupService }],
23256
23589
  [IFontService, { useClass: FontService }],
23257
23590
  [CanvasFloatDomService],
23591
+ [CanvasFloatDomPreviewService],
23258
23592
  [IUIController, {
23259
23593
  useFactory: (injector) => injector.createInstance(DesktopUIController, this._config),
23260
23594
  deps: [_univerjs_core.Injector]
@@ -23968,16 +24302,16 @@ const PrintFloatDomSingle = (0, react.memo)((props) => {
23968
24302
  transform: transformRef.current
23969
24303
  },
23970
24304
  onPointerMove: (e) => {
23971
- layer.onPointerMove(e.nativeEvent);
24305
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerMove(e.nativeEvent);
23972
24306
  },
23973
24307
  onPointerDown: (e) => {
23974
- layer.onPointerDown(e.nativeEvent);
24308
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerDown(e.nativeEvent);
23975
24309
  },
23976
24310
  onPointerUp: (e) => {
23977
- layer.onPointerUp(e.nativeEvent);
24311
+ if (shouldForwardFloatDomEvents(layer)) layer.onPointerUp(e.nativeEvent);
23978
24312
  },
23979
24313
  onWheel: (e) => {
23980
- layer.onWheel(e.nativeEvent);
24314
+ if (shouldForwardFloatDomEvents(layer)) layer.onWheel(e.nativeEvent);
23981
24315
  },
23982
24316
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23983
24317
  ref: innerDomRef,
@@ -24082,6 +24416,7 @@ Object.defineProperty(exports, 'BrowserClipboardService', {
24082
24416
  exports.BuiltInUIPart = BuiltInUIPart;
24083
24417
  exports.COLOR_PICKER_COMPONENT = COLOR_PICKER_COMPONENT;
24084
24418
  exports.COMMON_LABEL_COMPONENT = COMMON_LABEL_COMPONENT;
24419
+ exports.CanvasFloatDomPreviewService = CanvasFloatDomPreviewService;
24085
24420
  exports.CanvasFloatDomService = CanvasFloatDomService;
24086
24421
  exports.CanvasPopup = CanvasPopup;
24087
24422
  exports.CanvasPopupService = CanvasPopupService;
@@ -24162,6 +24497,7 @@ Object.defineProperty(exports, 'DesktopUIController', {
24162
24497
  return DesktopUIController;
24163
24498
  }
24164
24499
  });
24500
+ exports.EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE = EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE;
24165
24501
  exports.EMOJI_CATEGORIES = EMOJI_CATEGORIES;
24166
24502
  exports.EMOJI_PICKER_COMPONENT = EMOJI_PICKER_COMPONENT;
24167
24503
  exports.EMOJI_RECENT_LIMIT = EMOJI_RECENT_LIMIT;
@@ -24212,11 +24548,13 @@ exports.IMenuManagerService = IMenuManagerService;
24212
24548
  exports.IMessageService = IMessageService;
24213
24549
  exports.INotificationService = INotificationService;
24214
24550
  exports.IPlatformService = IPlatformService;
24551
+ exports.IRibbonOverrideService = IRibbonOverrideService;
24215
24552
  exports.IRibbonService = IRibbonService;
24216
24553
  exports.IShortcutService = IShortcutService;
24217
24554
  exports.ISidebarService = ISidebarService;
24218
24555
  exports.IUIController = IUIController;
24219
24556
  exports.IUIPartsService = IUIPartsService;
24557
+ exports.IUIRuntimeScopeService = IUIRuntimeScopeService;
24220
24558
  Object.defineProperty(exports, 'IconManager', {
24221
24559
  enumerable: true,
24222
24560
  get: function () {
@@ -24265,6 +24603,7 @@ exports.RibbonDataGroup = RibbonDataGroup;
24265
24603
  exports.RibbonFormulasGroup = RibbonFormulasGroup;
24266
24604
  exports.RibbonInsertGroup = RibbonInsertGroup;
24267
24605
  exports.RibbonOthersGroup = RibbonOthersGroup;
24606
+ exports.RibbonOverrideService = RibbonOverrideService;
24268
24607
  exports.RibbonPosition = RibbonPosition;
24269
24608
  exports.RibbonStartGroup = RibbonStartGroup;
24270
24609
  exports.RibbonViewGroup = RibbonViewGroup;
@@ -24298,6 +24637,7 @@ exports.ToolbarButton = ToolbarButton;
24298
24637
  exports.ToolbarItem = ToolbarItem;
24299
24638
  exports.UIMenuSchema = menuSchema;
24300
24639
  exports.UIPartsService = UIPartsService;
24640
+ exports.UIRuntimeScopeService = UIRuntimeScopeService;
24301
24641
  exports.UI_PLUGIN_CONFIG_KEY = UI_PLUGIN_CONFIG_KEY;
24302
24642
  exports.UNI_DISABLE_CHANGING_FOCUS_KEY = UNI_DISABLE_CHANGING_FOCUS_KEY;
24303
24643
  exports.UndoShortcutItem = UndoShortcutItem;
@@ -24334,6 +24674,7 @@ Object.defineProperty(exports, 'connectInjector', {
24334
24674
  });
24335
24675
  exports.getAllEmojis = getAllEmojis;
24336
24676
  exports.getDefaultRecentEmojis = getDefaultRecentEmojis;
24677
+ exports.getEmbedBoundaryOwner = getEmbedBoundaryOwner;
24337
24678
  exports.getEmojiLocaleData = getEmojiLocaleData;
24338
24679
  exports.getHeaderFooterMenuHiddenObservable = getHeaderFooterMenuHiddenObservable;
24339
24680
  exports.getLocalizedEmojiTitle = getLocalizedEmojiTitle;
@@ -24348,6 +24689,8 @@ exports.handleTableColgroup = handleTableColgroup;
24348
24689
  exports.handleTableMergeData = handleTableMergeData;
24349
24690
  exports.handleTableRowGroup = handleTableRowGroup;
24350
24691
  exports.imageMimeTypeSet = imageMimeTypeSet;
24692
+ exports.isEmbedBoundaryTarget = isEmbedBoundaryTarget;
24693
+ exports.keepInteractionInsideSameEmbedBoundary = keepInteractionInsideSameEmbedBoundary;
24351
24694
  exports.mergeMenuConfigs = mergeMenuConfigs;
24352
24695
  exports.parseHtmlDocument = parseHtmlDocument;
24353
24696
  exports.parseHtmlFragment = parseHtmlFragment;