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

fixed sheet mutli-sheet rendering bug #920

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions quadratic-client/src/grid/controller/Grid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { htmlCellsHandler } from '@/gridGL/htmlCells/htmlCellsHandler';
import * as Sentry from '@sentry/react';
import { Point, Rectangle } from 'pixi.js';
import { debugMockLargeData } from '../../debugFlags';
Expand Down Expand Up @@ -105,6 +106,7 @@ export class Grid {
if (summary.offsets_modified.length) {
sheets.updateOffsets(summary.offsets_modified);
pixiApp.cellsSheets.updateBorders(summary.offsets_modified);
htmlCellsHandler.updateOffsets(summary.offsets_modified.map((offset) => offset.id));
}

if (summary.code_cells_modified.length) {
Expand Down
1 change: 1 addition & 0 deletions quadratic-client/src/grid/controller/Sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Sheets {
pixiAppSettings.changeInput(false);
pixiApp.cellsSheets.show(sheets.sheet.id);
this.updateSheetBar();
pixiApp.loadViewport();
}
}

Expand Down
1 change: 0 additions & 1 deletion quadratic-client/src/gridGL/cells/CellsSheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class CellsSheets extends Container<CellsSheet> {
if (this.current?.sheet.id !== child?.sheet.id) {
this.current = child;
child.show(pixiApp.viewport.getVisibleBounds());
pixiApp.loadViewport();
}
} else {
child.hide();
Expand Down
22 changes: 21 additions & 1 deletion quadratic-client/src/gridGL/htmlCells/HtmlCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CELL_HEIGHT, CELL_WIDTH } from '@/constants/gridConstants';
import { sheets } from '@/grid/controller/Sheets';
import { Sheet } from '@/grid/sheet/Sheet';
import { JsHtmlOutput } from '@/quadratic-core/types';
import { colors } from '@/theme/colors';
import { InteractionEvent } from 'pixi.js';
Expand All @@ -20,15 +21,22 @@ export class HtmlCell {
private resizing: HtmlCellResizing | undefined;
private hoverSide: 'right' | 'bottom' | 'corner' | undefined;

sheet: Sheet;

div: HTMLDivElement;

constructor(htmlCell: JsHtmlOutput) {
this.htmlCell = htmlCell;
const sheet = sheets.getById(htmlCell.sheet_id)!;
if (!sheet) {
throw new Error(`Expected to find sheet with id ${htmlCell.sheet_id}`);
}
this.sheet = sheet;

this.div = document.createElement('div');
this.div.className = 'html-cell';
this.div.style.border = `1px solid ${colors.cellColorUserPythonRgba}`;
const offset = sheets.sheet.getCellOffsets(Number(htmlCell.x), Number(htmlCell.y));
const offset = this.sheet.getCellOffsets(Number(htmlCell.x), Number(htmlCell.y));

// the 0.5 is adjustment for the border
this.div.style.left = `${offset.x - 0.5}px`;
Expand Down Expand Up @@ -57,6 +65,10 @@ export class HtmlCell {
} else {
this.iframe.addEventListener('load', this.afterLoad);
}

if (this.sheet.id !== sheets.sheet.id) {
this.div.style.visibility = 'hidden';
}
}

get x(): number {
Expand Down Expand Up @@ -253,4 +265,12 @@ export class HtmlCell {
setHeight(height: number) {
this.iframe.height = height.toString();
}

updateOffsets() {
const offset = this.sheet.getCellOffsets(this.x, this.y);

// the 0.5 is adjustment for the border
this.div.style.left = `${offset.x - 0.5}px`;
this.div.style.top = `${offset.y + offset.height - 0.5}px`;
}
}
7 changes: 7 additions & 0 deletions quadratic-client/src/gridGL/htmlCells/htmlCellsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class HTMLCellsHandler {
getCells(): HtmlCell[] {
return Array.from(this.cells.values());
}

// handle changes to offsets
updateOffsets(sheetIds: string[]) {
this.cells.forEach((cell) => {
if (sheetIds.includes(cell.sheet.id)) cell.updateOffsets();
});
}
}

export const htmlCellsHandler = new HTMLCellsHandler();
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { htmlCellsHandler } from '@/gridGL/htmlCells/htmlCellsHandler';
import { InteractivePointerEvent, Point } from 'pixi.js';
import { isEditorOrAbove } from '../../../actions';
import { CELL_TEXT_MARGIN_LEFT, CELL_WIDTH } from '../../../constants/gridConstants';
Expand Down Expand Up @@ -181,6 +182,7 @@ export class PointerHeading {
column: this.resizing.column,
delta: size - this.resizing.lastSize,
});
htmlCellsHandler.updateOffsets([sheets.sheet.id]);
this.resizing.lastSize = size;
}
} else if (this.resizing.row !== undefined) {
Expand Down
3 changes: 1 addition & 2 deletions scripts/run-ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ if [ "$VERCEL_ENV" == "preview" ]; then
echo "On preview branch. Setting VITE_QUADRATIC_API_URL to quadratic-api-dev-pr-$VERCEL_GIT_PULL_REQUEST_ID.herokuapp.com"
fi

cd ..

echo 'Installing rustup...'
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
Expand All @@ -23,4 +21,5 @@ cargo run --bin export_types
cd ../quadratic-client

echo 'Building front-end...'
npm ci
npm run build
5 changes: 5 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"buildCommand": "./scripts/run-ci-build.sh",
"installCommand": "npm install",
"outputDirectory": "build"
}