Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(popup): range popup position calc log (#6351)
WEI ZHANG7f18fce4e35a
diff --git a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-current-worksheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-current-worksheet-ci-chromium-linux.pngindex 278b5614d2..f0e41a0a1d 100644Binary files a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-current-worksheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-current-worksheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-other-worksheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-other-worksheet-ci-chromium-linux.pngindex eb68a95f13..a34a5c1ca4 100644Binary files a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-other-worksheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-filter-row-other-worksheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-hide-row-current-worksheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-hide-row-current-worksheet-ci-chromium-linux.pngindex 4367f2fdf0..d3f0b8ab41 100644Binary files a/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-hide-row-current-worksheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-formula-related.spec.ts-snapshots/formula-hide-row-current-worksheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.pngindex 47a8491eb1..dcc4820e9a 100644Binary files a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.pngindex f2787ebf2c..f4d1d810f8 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.pngindex cb5f97c159..e6f775a8be 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png differdiff --git a/examples/src/sheets/custom/simple-range-popup.tsx b/examples/src/sheets/custom/simple-range-popup.tsxnew file mode 100644index 0000000000..77248ca86a--- /dev/null+++ b/examples/src/sheets/custom/simple-range-popup.tsx@@ -0,0 +1,54 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Univer } from '@univerjs/core';+import type { FUniver } from '@univerjs/core/facade';+import { LifecycleStages } from '@univerjs/core';+import React from 'react';++export function simpleRangePopupDemo(univer: Univer, univerAPI: FUniver) {+ // Register a custom component+ univerAPI.registerComponent('MySimplePopup', () => (+ <div+ style={{+ padding: '8px',+ background: 'white',+ border: '1px solid #ccc',+ borderRadius: '4px',+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',+ color: '#333',+ }}+ >+ Hello from Range Popup!+ </div>+ ));++ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (params) => {+ if (params.stage === LifecycleStages.Rendered) {+ // Get the active sheet and a range+ const workbook = univerAPI.getActiveWorkbook();+ const worksheet = workbook!.getActiveSheet();+ const range = worksheet.getRange('B2:D100');++ // Attach the popup to the range+ range.attachRangePopup({+ componentKey: 'MySimplePopup',+ direction: 'right-bottom',+ offset: [0, 10],+ });+ }+ });+}diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 485a79e388..7c78d92109 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -54,6 +54,7 @@ import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-componimport { customRegisterEvent } from './custom/custom-register-event';import { UniverSheetsCustomShortcutPlugin } from './custom/custom-shortcut';import ImportCSVButtonPlugin from './custom/import-csv-button';+import { simpleRangePopupDemo } from './custom/simple-range-popup';import '@univerjs/sheets/facade';import '@univerjs/ui/facade';@@ -202,6 +203,7 @@ function createNewInstance() {customRegisterEvent(univer, window.univerAPI!);// customRangePopups(univer, window.univerAPI!);+ simpleRangePopupDemo(univer, window.univerAPI!);}createNewInstance();diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.tsindex 082fa3ed7d..8fae358394 100644--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts@@ -680,12 +680,14 @@ export class SheetCanvasPopManagerService extends Disposable {const { top, left, width } = canvasClientRect; // real width affected by scaleconst scaleAdjust = width / widthOfCanvas;- return {+ const result = {left: ((cellInfo.startX - scrollXY.x) * scaleAdjust * scaleX) + left,right: (cellInfo.endX - scrollXY.x) * scaleAdjust * scaleX + left,top: ((cellInfo.startY - scrollXY.y) * scaleAdjust * scaleY) + top,bottom: ((cellInfo.endY - scrollXY.y) * scaleAdjust * scaleY) + top,};++ return result;}// #endregion@@ -760,6 +762,7 @@ export class SheetCanvasPopManagerService extends Disposable {right: rightBottomCoord.right,bottom: rightBottomCoord.bottom,};+return {position$,position,diff --git a/packages/ui/src/views/components/popup/CanvasPopup.tsx b/packages/ui/src/views/components/popup/CanvasPopup.tsxindex 0935e27072..96dd3842ce 100644--- a/packages/ui/src/views/components/popup/CanvasPopup.tsx+++ b/packages/ui/src/views/components/popup/CanvasPopup.tsx@@ -60,10 +60,12 @@ export const SingleCanvasPopup = ({ popup, children }: ISingleCanvasPopupProps)const rectWidth = rectWithOffset.right - rectWithOffset.left;const isInHiddenRect = hiddenRects.some((hiddenRect) => {- return rectWithOffset.top >= (hiddenRect.top - (0.5 * rectHeight)) &&- rectWithOffset.bottom <= (hiddenRect.bottom + (0.5 * rectHeight)) &&- rectWithOffset.left >= (hiddenRect.left - (0.5 * rectWidth)) &&- rectWithOffset.right <= (hiddenRect.right + (0.5 * rectWidth));+ const bufferY = Math.min(0.5 * rectHeight, 10);+ const bufferX = Math.min(0.5 * rectWidth, 10);+ return rectWithOffset.top >= (hiddenRect.top - bufferY) &&+ rectWithOffset.bottom <= (hiddenRect.bottom + bufferY) &&+ rectWithOffset.left >= (hiddenRect.left - bufferX) &&+ rectWithOffset.right <= (hiddenRect.right + bufferX);});if (rectWithOffset.bottom < top || rectWithOffset.top > bottom || rectWithOffset.right < left || rectWithOffset.left > right || isInHiddenRect) {diff --git a/packages/ui/src/views/components/popup/RectPopup.tsx b/packages/ui/src/views/components/popup/RectPopup.tsxindex e510f8d5c7..999f8c3df8 100644--- a/packages/ui/src/views/components/popup/RectPopup.tsx+++ b/packages/ui/src/views/components/popup/RectPopup.tsx@@ -116,9 +116,9 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbeconst { left: startX, top: startY, right: endX, bottom: endY } = position;const verticalStyle = (direction === 'vertical' && endY > maxTop) || direction.indexOf('top') > -1// top- ? { top: Math.max(startY - height, minTop) }+ ? { top: Math.max(Math.min(startY - height, maxTop), minTop) }// bottom- : { top: Math.min(endY, maxTop) };+ : { top: Math.max(Math.min(endY, maxTop), minTop) };let horizontalStyle;@@ -130,16 +130,16 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe? { left: Math.max(Math.min(maxLeft, endX - width - offsetX), minLeft) }: { left: Math.max(minLeft, Math.min(startX + offsetX, maxLeft)) };} else if (direction.includes('right')) {- horizontalStyle = { left: Math.max(endX - width, minLeft) };+ horizontalStyle = { left: Math.max(Math.min(endX - width, maxLeft), minLeft) };} else if (direction.includes('left')) {- horizontalStyle = { left: Math.min(startX, maxLeft) };+ horizontalStyle = { left: Math.max(Math.min(startX, maxLeft), minLeft) };} else {// If the popup element exceed the visible area. We should "push" it back.horizontalStyle = (startX + width) > containerWidth? Math.max(endX - width, minLeft) < PUSHING_MINIMUM_GAP- ? { left: Math.min(startX, maxLeft) }- : { left: Math.max(endX - width, minLeft) } // on left- : { left: Math.min(startX, maxLeft) }; // on right+ ? { left: Math.max(Math.min(startX, maxLeft), minLeft) }+ : { left: Math.max(Math.min(endX - width, maxLeft), minLeft) } // on left+ : { left: Math.max(Math.min(startX, maxLeft), minLeft) }; // on right}return { ...verticalStyle, ...horizontalStyle };@@ -149,8 +149,8 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbeconst { left: startX, top: startY, right: endX, bottom: endY } = position;// const horizontalStyle = ((endX + width) > containerWidth || direction === 'left')const horizontalStyle = direction.includes('left')- ? { left: Math.max(startX - width, minLeft) } // on left- : { left: Math.min(endX, maxLeft) }; // on right+ ? { left: Math.max(Math.min(startX - width, maxLeft), minLeft) } // on left+ : { left: Math.max(Math.min(endX, maxLeft), minLeft) }; // on rightlet verticalStyle;@@ -163,19 +163,19 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe: { top: Math.max(minTop, Math.min(startY + offsetY, maxTop)) };} else if (direction.includes('top')) {verticalStyle = {- top: Math.min(startY, maxTop),+ top: Math.max(Math.min(startY, maxTop), minTop),};} else if (direction.includes('bottom')) {verticalStyle = {- top: Math.max(endY - height, minTop),+ top: Math.max(Math.min(endY - height, maxTop), minTop),};} else {// If the popup element exceed the visible area. We should "push" it back.verticalStyle = ((startY + height) > containerHeight)? Math.max(endY - height, minTop) < PUSHING_MINIMUM_GAP- ? { top: Math.min(startY, maxTop) }- : { top: Math.max(endY - height, minTop) } // on top- : { top: Math.min(startY, maxTop) }; // on bottom+ ? { top: Math.max(Math.min(startY, maxTop), minTop) }+ : { top: Math.max(Math.min(endY - height, maxTop), minTop) } // on top+ : { top: Math.max(Math.min(startY, maxTop), minTop) }; // on bottom}return { ...verticalStyle, ...horizontalStyle };diff --git a/packages/ui/src/views/workbench/Workbench.tsx b/packages/ui/src/views/workbench/Workbench.tsxindex f801118176..6f10857fdf 100644--- a/packages/ui/src/views/workbench/Workbench.tsx+++ b/packages/ui/src/views/workbench/Workbench.tsx@@ -211,7 +211,7 @@ export function DesktopWorkbenchContent(props: IUniverWorkbenchProps) {</section>- <aside data-u-comp="right-sidebar" className="univer-h-full">+ <aside data-u-comp="right-sidebar" className="univer-z-[100] univer-h-full"><Sidebar /></aside></div>