Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(docs-ui): refactor to RenderUnit #2539

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/dev' into wzhudev/refactor/doc-r…
…ender-unit
  • Loading branch information
wzhudev committed Jun 19, 2024
commit 61fc0dce8e4abb59842658d63efc7d2ba9582dff
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jobs:
run: pnpm install cnpm -g

- name: 🐙 Sync to cnpm
run: pnpm sync-cnpm
run: pnpm sync:cnpm

build-storybook:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions common/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"./vite": "./vite/index.js"
},
"dependencies": {
"@typescript-eslint/parser": "^7.12.0",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-istanbul": "^1.6.0",
"happy-dom": "13.3.8",
"javascript-obfuscator": "^4.1.0",
"vite": "^5.2.13",
"javascript-obfuscator": "^4.1.1",
"vite": "^5.3.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0"
}
Expand Down
4 changes: 3 additions & 1 deletion common/shared/vite/auto-externalize-dependency-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ exports.autoExternalizeDependency = function autoExternalizeDependency() {
}
});

pkg.peerDependencies = peerDependencies;
if (Object.keys(peerDependencies).length) {
pkg.peerDependencies = peerDependencies;
}
if (optionalDependencies) {
pkg.optionalDependencies = optionalDependencies;
}
Expand Down
16 changes: 8 additions & 8 deletions common/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
},
"dependencies": {
"@chromatic-com/storybook": "^1.5.0",
"@storybook/addon-essentials": "8.1.6",
"@storybook/addon-interactions": "8.1.6",
"@storybook/addon-links": "8.1.6",
"@storybook/addon-essentials": "8.1.10",
"@storybook/addon-interactions": "8.1.10",
"@storybook/addon-links": "8.1.10",
"@storybook/addon-styling-webpack": "^1.0.0",
"@storybook/addon-webpack5-compiler-swc": "^1.0.3",
"@storybook/blocks": "8.1.6",
"@storybook/blocks": "8.1.10",
"@storybook/icons": "^1.2.9",
"@storybook/react": "8.1.6",
"@storybook/react-webpack5": "8.1.6",
"@storybook/types": "8.1.6",
"@storybook/react": "8.1.10",
"@storybook/react-webpack5": "8.1.10",
"@storybook/types": "8.1.10",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/ui": "workspace:*",
"@wendellhu/redi": "0.15.4",
"css-loader": "^6.10.0",
"less-loader": "^12.2.0",
"storybook": "8.1.6",
"storybook": "8.1.10",
"storybook-addon-swc": "^1.2.0",
"style-loader": "^3.3.4",
"tsconfig-paths-webpack-plugin": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/facade": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/icons": "^0.1.56",
"@univerjs/icons": "^0.1.57",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"lint:types": "turbo lint:types",
"test": "turbo test -- --passWithNoTests",
"coverage": "turbo coverage -- --passWithNoTests",
"build": "turbo build --filter=!./common/* && pnpm --filter @univerjs/umd build:umd",
"build:demo": "turbo build:demo",
"build": "turbo build --concurrency=50% --filter=!./common/* && pnpm --filter @univerjs/umd build:umd",
"build:demo": "pnpm --filter univer-examples build:demo",
"build:e2e": "pnpm --filter univer-examples build:e2e",
"serve:e2e": "serve ./examples/local",
"test:e2e": "playwright test",
Expand All @@ -46,34 +46,34 @@
"sync:cnpm": "turbo sync:cnpm"
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.0",
"@antfu/eslint-config": "^2.21.1",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint-react/eslint-plugin": "^1.5.15",
"@eslint-react/eslint-plugin": "^1.5.16",
"@playwright/test": "^1.44.1",
"@release-it-plugins/workspaces": "^4.2.0",
"@release-it/conventional-changelog": "^8.0.1",
"@storybook/react": "8.1.6",
"@types/node": "^20.14.2",
"@storybook/react": "8.1.10",
"@types/node": "^20.14.4",
"@types/react": "^18.3.3",
"@univerjs/design": "workspace:*",
"@univerjs/shared": "workspace:*",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "8.57.0",
"eslint-plugin-format": "^0.1.1",
"eslint-plugin-format": "^0.1.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-no-barrel-import": "^0.0.2",
"eslint-plugin-no-penetrating-import": "^0.0.1",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"lint-staged": "^15.2.7",
"react": "18.3.1",
"react-dom": "18.3.1",
"release-it": "^17.3.0",
"serve": "^14.2.3",
"turbo": "^2.0.3",
"turbo": "^2.0.4",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@wendellhu/redi": "0.15.4",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
40 changes: 25 additions & 15 deletions packages/core/src/shared/rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { IRange } from '../types/interfaces/i-range';
import type { IRange, IRectLTRB } from '../types/interfaces/i-range';
import { AbsoluteRefType, RANGE_TYPE } from '../types/interfaces/i-range';
import type { Nullable } from './types';

Expand Down Expand Up @@ -314,20 +314,7 @@ export class Rectangle {
return result;
}

static hasIntersectionBetweenTwoBounds(
rect1: {
left: number;
top: number;
right: number;
bottom: number;
},
rect2: {
left: number;
top: number;
right: number;
bottom: number;
}
) {
static hasIntersectionBetweenTwoRect(rect1: IRectLTRB, rect2: IRectLTRB) {
if (
rect1.left > rect2.right || // rect1 在 rect2 右侧
rect1.right < rect2.left || // rect1 在 rect2 左侧
Expand All @@ -339,4 +326,27 @@ export class Rectangle {

return true;
}

static getIntersectionBetweenTwoRect(rect1: IRectLTRB, rect2: IRectLTRB) {
// 计算两个矩形的交集部分的坐标
const left = Math.max(rect1.left, rect2.left);
const right = Math.min(rect1.right, rect2.right);
const top = Math.max(rect1.top, rect2.top);
const bottom = Math.min(rect1.bottom, rect2.bottom);

// 如果交集部分的宽度或高度小于等于 0,说明两个矩形不相交
if (right <= left || bottom <= top) {
return null;
}

// 返回交集部分的矩形
return {
left,
right,
top,
bottom,
width: right - left,
height: bottom - top,
} as Required<IRectLTRB>;
}
}
9 changes: 9 additions & 0 deletions packages/core/src/types/interfaces/i-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,12 @@ export interface IOptionData {
* Option of copyTo function
*/
export interface ICopyToOptionsData extends IOptionData {}

export interface IRectLTRB {
left: number;
top: number;
right: number;
bottom: number;
width?: number;
height?: number;
}
2 changes: 1 addition & 1 deletion packages/data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@wendellhu/redi": "0.15.4",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
2 changes: 1 addition & 1 deletion packages/debugger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@wendellhu/redi": "0.15.4",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0",
"vue": "^3.4.27"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@
"@rc-component/color-picker": "^1.5.3",
"@rc-component/trigger": "^2.2.0",
"@types/react-mentions": "^4.1.13",
"@univerjs/icons": "^0.1.56",
"@univerjs/icons": "^0.1.57",
"rc-dialog": "^9.5.2",
"rc-dropdown": "^4.2.0",
"rc-input": "^1.5.1",
"rc-input-number": "^9.1.0",
"rc-menu": "^9.14.0",
"rc-picker": "^4.5.0",
"rc-picker": "^4.6.3",
"rc-segmented": "^2.3.0",
"rc-select": "^14.14.0",
"rc-select": "^14.15.0",
"rc-textarea": "^1.7.0",
"rc-tooltip": "^6.2.0",
"rc-util": "^5.41.0",
"rc-util": "^5.43.0",
"react-draggable": "^4.4.6",
"react-grid-layout": "^1.4.4",
"react-mentions": "^4.4.10",
Expand All @@ -104,7 +104,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
49 changes: 23 additions & 26 deletions packages/design/src/components/popup/RectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ export interface IPopupLayoutInfo extends Pick<IRectPopupProps, 'direction'> {
}

/** The popup should have a minimum edge to the boundary. */
const PUSHING_MINIMUM_GAP = 4;
const PUSHING_MINIMUM_GAP = 8;

function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: number } {
const { position, width, height, containerHeight, containerWidth, direction = 'vertical' } = layout;

// In y-axis
if (direction === 'vertical' || direction === 'top' || direction === 'bottom') {
const { left: startX, top: startY, right: endX, bottom: endY } = position;
const verticalStyle = ((endY + height) > containerHeight || direction === 'top')
? { top: startY - height }
: { top: endY };
const verticalStyle = direction === 'top'
// const verticalStyle = ((endY + height) > containerHeight || direction === 'top')
? { top: Math.max(startY - height, PUSHING_MINIMUM_GAP) }
: { top: Math.min(endY, containerHeight - height - PUSHING_MINIMUM_GAP) };

// If the popup element exceed the visible area. We should "push" it back.
const horizontalStyle = (startX + width) > containerWidth
Expand All @@ -77,9 +78,10 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe

// In x-axis
const { left: startX, top: startY, right: endX, bottom: endY } = position;
const horizontalStyle = ((endX + width) > containerWidth || direction === 'left')
? { left: startX - width }
: { left: endX };
// const horizontalStyle = ((endX + width) > containerWidth || direction === 'left')
const horizontalStyle = direction === 'left'
? { left: Math.max(startX - width, PUSHING_MINIMUM_GAP) } // on left
: { left: Math.min(endX, containerWidth - width - PUSHING_MINIMUM_GAP) }; // on right

// If the popup element exceed the visible area. We should "push" it back.
const verticalStyle = ((startY + height) > containerHeight)
Expand All @@ -101,28 +103,23 @@ function RectPopup(props: IRectPopupProps) {
const style = useMemo(() => ({ ...position }), [position]);
useEffect(() => {
requestAnimationFrame(() => {
if (!nodeRef.current) {
return;
}
if (!nodeRef.current) return;

const { clientWidth, clientHeight } = nodeRef.current;
const parent = nodeRef.current.parentElement;
if (!parent) {
return;
}
const { clientWidth: innerWidth, clientHeight: innerHeight } = parent;
if (!parent) return;

setPosition(
calcPopupPosition(
{
position: anchorRect,
width: clientWidth,
height: clientHeight,
containerWidth: innerWidth,
containerHeight: innerHeight,
direction,
}
)
);
const { clientWidth: innerWidth, clientHeight: innerHeight } = parent;
setPosition(calcPopupPosition(
{
position: anchorRect,
width: clientWidth,
height: clientHeight,
containerWidth: innerWidth,
containerHeight: innerHeight,
direction,
}
));
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.56"
"@univerjs/icons": "^0.1.57"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand All @@ -98,7 +98,7 @@
"react": "18.3.1",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-drawing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@univerjs/shared": "workspace:*",
"@wendellhu/redi": "^0.15.4",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"react": "18.3.1",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@wendellhu/redi": "0.15.4",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"univerSpace": {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.