Browse Source

输入款永远在下方

feature/new_node
TianYun 1 month ago
parent
commit
438e03861b
  1. 4
      src/components/__tests__/GenerationComposer.test.tsx
  2. 13
      src/components/composer/GenerationComposer.tsx

4
src/components/__tests__/GenerationComposer.test.tsx

@ -381,7 +381,7 @@ describe("GenerationComposer", () => {
expect(screen.getByPlaceholderText(/Describe what you want to generate/)).toHaveClass("h-36");
});
it("places the selected node editor above the node when below would leave the viewport", () => {
it("keeps the selected node editor below the node when below would leave the viewport", () => {
const originalInnerHeight = window.innerHeight;
const originalInnerWidth = window.innerWidth;
Object.defineProperty(window, "innerHeight", { configurable: true, value: 500 });
@ -400,7 +400,7 @@ describe("GenerationComposer", () => {
expect(screen.getByTestId("node-inline-composer")).toHaveStyle({
left: "16px",
top: "104px",
top: "536px",
});
Object.defineProperty(window, "innerHeight", { configurable: true, value: originalInnerHeight });
Object.defineProperty(window, "innerWidth", { configurable: true, value: originalInnerWidth });

13
src/components/composer/GenerationComposer.tsx

@ -124,8 +124,6 @@ const MAX_REFERENCE_IMAGE_BYTES = 10 * 1024 * 1024;
const COMPOSER_VIEWPORT_MARGIN = 16;
const COMPOSER_EXPANDED_WIDTH = 640;
const COMPOSER_COLLAPSED_WIDTH = 560;
const COMPOSER_EXPANDED_HEIGHT_ESTIMATE = 300;
const COMPOSER_COLLAPSED_HEIGHT_ESTIMATE = 80;
const DEFAULT_IMAGE_COUNT_OPTIONS: ImageGenerationCount[] = [1, 2, 4];
interface SchemaSelectOption {
@ -1408,16 +1406,10 @@ export function GenerationComposer() {
);
const safeZoom = zoom > 0 ? zoom : 1;
const viewportWidth = typeof window === "undefined" ? Number.POSITIVE_INFINITY : window.innerWidth;
const viewportHeight = typeof window === "undefined" ? Number.POSITIVE_INFINITY : window.innerHeight;
const visibleLeft = -viewportX / safeZoom;
const visibleRight = (viewportWidth - viewportX) / safeZoom;
const visibleTop = -viewportY / safeZoom;
const visibleBottom = (viewportHeight - viewportY) / safeZoom;
const composerWidth = isComposerCollapsed ? COMPOSER_COLLAPSED_WIDTH : COMPOSER_EXPANDED_WIDTH;
const composerFlowWidth = composerWidth / safeZoom;
const composerHeightEstimate = isComposerCollapsed
? COMPOSER_COLLAPSED_HEIGHT_ESTIMATE
: COMPOSER_EXPANDED_HEIGHT_ESTIMATE;
const viewportMargin = COMPOSER_VIEWPORT_MARGIN / safeZoom;
const inlineComposerPosition = context.node && selectedNodeDimensions
? (() => {
@ -1428,13 +1420,10 @@ export function GenerationComposer() {
? Math.min(Math.max(centeredLeft, minLeft), maxLeft)
: minLeft;
const belowTop = context.node.position.y + selectedNodeDimensions.height + viewportMargin;
const aboveTop = context.node.position.y - composerHeightEstimate / safeZoom - viewportMargin;
const belowFits = belowTop + composerHeightEstimate / safeZoom <= visibleBottom - viewportMargin;
const aboveFits = aboveTop >= visibleTop + viewportMargin;
return {
left,
top: belowFits || !aboveFits ? belowTop : aboveTop,
top: belowTop,
};
})()
: null;

Loading…
Cancel
Save