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

Javascript #1273

Merged
merged 145 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
1d598dd
initial work on js/ts
davidfig Apr 6, 2024
e7a0590
cleaning up
davidfig Apr 7, 2024
ef8d056
working through messaging for js
davidfig Apr 7, 2024
30b8a28
Merge branch 'core-web-worker' into javascript
davidfig Apr 7, 2024
ec17cd5
Basic JS working
davidfig Apr 7, 2024
2ca4246
working through javascript
davidfig Apr 8, 2024
8b01efe
javascript with getCells
davidfig Apr 9, 2024
a0b5c25
better error messages with error line location properly mapped
davidfig Apr 9, 2024
ee457d4
catch import statements and display error
davidfig Apr 10, 2024
60f78d4
fix capitalization of worker name
davidfig Apr 10, 2024
35133b1
add code highlighting for typescript/javascript
davidfig Apr 10, 2024
cc8aad5
Adding hinting for using javascript
davidfig Apr 10, 2024
366516d
include imported libraries for monaco highlighting
davidfig Apr 10, 2024
1039d98
improve warnings and log messages
davidfig Apr 10, 2024
8753564
better typign
davidfig Apr 10, 2024
920eaf5
added return type to code editor
davidfig Apr 10, 2024
06edf5d
Merge branch 'core-web-worker' into javascript
davidfig Apr 12, 2024
a8f64b7
Merge branch 'core-web-worker' into javascript
davidfig Apr 13, 2024
4cf21f6
Merge branch 'javascript' of https://github.com/quadratichq/quadratic…
davidfig Apr 13, 2024
cbffee5
adding more JS functions
davidfig Apr 13, 2024
ab59b90
working through pos() issues
davidfig Apr 14, 2024
49f9845
fix run_python with pos() and rc()
davidfig Apr 14, 2024
694a727
Merge branch 'core-web-worker' into javascript
davidfig Apr 14, 2024
2378f1b
attempting to get python working properly in this branch
davidfig Apr 14, 2024
d7ec734
fix bug with python
davidfig Apr 14, 2024
6ef5fb6
javascript has parity with python
davidfig Apr 14, 2024
c826e52
fix javascript compile errors
davidfig Apr 14, 2024
8cb621b
Merge branch 'core-web-worker' into javascript
davidfig Apr 15, 2024
5a6c17f
fix problems with add/delete sheet and updating sheet bar
davidfig Apr 15, 2024
b77f8ef
add JS logo to code editor
davidfig Apr 16, 2024
4638fd7
adding JS icon to code cells
davidfig Apr 16, 2024
8ac0877
better console log support
davidfig Apr 17, 2024
3d29014
Fix cell type menu
davidfig Apr 17, 2024
0586425
fixed error formatting; moved some fn to utils
davidfig Apr 17, 2024
c59c2de
handle bigint, null, and undefined for console.log
davidfig Apr 17, 2024
31403bf
Merge branch 'core-web-worker' into javascript
davidfig Apr 17, 2024
1f64c86
add spelling words
davidfig Apr 17, 2024
3a5d9af
return null if returning an array.length = 0
davidfig Apr 17, 2024
41aa079
improved return type message
davidfig Apr 17, 2024
4a36f17
removing console.logs
davidfig Apr 17, 2024
8f434db
Merge branch 'core-web-worker' into javascript
davidfig Apr 18, 2024
44ec2fa
empty array prints to the same line in console
davidfig Apr 18, 2024
094ff3f
Merge branch 'core-web-worker' into javascript
davidfig Apr 18, 2024
69159e6
working through javascript syntax highlighting bug
davidfig Apr 18, 2024
5ae6ea3
JS output types
davidfig Apr 18, 2024
0704aab
fix: update javascript colors and cell type menu
jimniels Apr 18, 2024
41cd3d5
update js cell color
jimniels Apr 18, 2024
7f1ba3b
tweak cursor cell interaction color/outline
jimniels Apr 18, 2024
a0eaf93
Merge branch 'main' into javascript
davidfig Apr 19, 2024
3da8d75
cleaning up
davidfig Apr 19, 2024
0b788cb
improving javascript flow
davidfig Apr 20, 2024
2bdf425
javascript with esm import
davidfig Apr 20, 2024
ab4de1a
fix empty console output
davidfig Apr 21, 2024
9d70e46
adding boolean support for getCells
davidfig Apr 21, 2024
e1e8aed
code documentation
davidfig Apr 21, 2024
32a914b
line numbers are back; wrote script to handle javascript functions
davidfig Apr 21, 2024
ca266d4
remove placeholder typescript files
davidfig Apr 21, 2024
97c4412
working on outputing an image blob
davidfig Apr 21, 2024
600ac67
all images are broadcast to the client on file load
davidfig Apr 22, 2024
bb1084e
update to getCells
davidfig Apr 22, 2024
28886c5
image properly updates when codeRun is finalized
davidfig Apr 22, 2024
3f830df
CellValue::Image with resizing
davidfig Apr 23, 2024
b43973c
fix fading in/out
davidfig Apr 23, 2024
c7244f0
cell images are now in front of gridLines
davidfig Apr 23, 2024
00ab0ae
don't show lineNumber in JS results when we don't have it
davidfig Apr 24, 2024
cac4ad0
fix line number = 0
davidfig Apr 24, 2024
1df3a64
Merge branch 'main' into javascript
davidfig Apr 24, 2024
0d87f27
fixing merge conflicts
davidfig Apr 24, 2024
6d66514
fixing more merge conflicts
davidfig Apr 24, 2024
99dd098
allow corner resizing for images
davidfig Apr 24, 2024
90425a8
return canvas works instead of canvas.convertToBlob()
davidfig Apr 24, 2024
f87ffce
add tests for getCells without y1
davidfig Apr 24, 2024
d1a8b9a
fix getCells when h is not defined
davidfig Apr 24, 2024
5392493
getCellsWithHeadings also supports no y1
davidfig Apr 24, 2024
f11adc4
fix lint:clippy
davidfig Apr 24, 2024
bcf3df2
prettier ignore JS generated files
davidfig Apr 24, 2024
3e302ac
Merge branch 'main' into javascript
davidfig Apr 24, 2024
b98d254
removed console.log
davidfig Apr 24, 2024
127a14c
minor fixes
davidfig Apr 30, 2024
2088e08
fix errors where the stack is not returned
davidfig Apr 30, 2024
7a318d0
Merge branch 'main' into javascript
davidfig May 1, 2024
ed0f0d5
added JS snippets
davidfig May 1, 2024
5906458
javascript library has proper documentation in editor
davidfig May 1, 2024
4f9cd64
add documentation link for JS
davidfig May 1, 2024
867b780
add learn more link to empty return in JS
davidfig May 1, 2024
cb4a009
let the user knows when it looks like they returned a promise instead…
davidfig May 1, 2024
7e3f053
fixing urls
davidfig May 1, 2024
efce8c6
javascript's cells_accessed properly highlights
davidfig May 1, 2024
9b0b92f
better error handling when using the quadratic API in JS
davidfig May 2, 2024
912e3db
console.log no longer adds a space
davidfig May 2, 2024
08d6db2
Merge branch 'main' into javascript
davidfig May 2, 2024
bc1ee3f
adding more aliases to the API
davidfig May 2, 2024
0077e2c
Merge branch 'javascript' of https://github.com/quadratichq/quadratic…
davidfig May 2, 2024
297e5d7
can return output as an array of objects
davidfig May 2, 2024
0def9cd
changed Blob/image to OffscreenCanvas
davidfig May 2, 2024
8f44edf
2d array with different sized rows will use the longest row size
davidfig May 2, 2024
ac31f40
fix bug with the [object] checking on javascriptOutput
davidfig May 3, 2024
b4bc008
Update snippetsJavascript.ts
jimniels May 3, 2024
2891502
Delete quadratic-client/src/app/LICENSE
jimniels May 3, 2024
58fbc73
Update CellTypeMenu.tsx
jimniels May 3, 2024
29519d1
JS now has state for showing when the cell is running
davidfig May 6, 2024
03b4a16
remove typescript as a dep for quadratic-client
davidfig May 6, 2024
46b27a5
JS can be cancelled
davidfig May 6, 2024
16543c3
rename JS icon; add link to JS menu entry in code type menu
davidfig May 6, 2024
799ed6b
Merge branch 'main' into javascript
davidfig May 7, 2024
c90f0da
Merge branch 'clippy-fixes-may' into javascript
davidfig May 7, 2024
fc5cc49
fix rust test
davidfig May 7, 2024
36f397c
basic kernel menu
davidfig May 10, 2024
7351006
kernel messaging
davidfig May 10, 2024
e3a0137
Merge branch 'select-column-row' into javascript
davidfig Jun 19, 2024
311baf3
fix migration bugs
davidfig Jun 19, 2024
abb34e7
ensure Monaco's webworkers are properly initalized
davidfig Jun 19, 2024
993cd70
Merge branch 'select-column-row' into javascript
davidfig Jun 19, 2024
2b91faf
tests for execute_formats.ts
davidfig Jun 19, 2024
c5f18da
fix tests
davidfig Jun 19, 2024
6a26a43
Merge branch 'select-column-row' into javascript
davidfig Jun 19, 2024
3bf868c
Merge branch 'select-column-row' into javascript
davidfig Jun 20, 2024
05a2048
Merge branch 'main' into javascript
davidfig Jun 25, 2024
16bfc90
move kernel menu
davidfig Jun 25, 2024
5e69f0c
fix insert cell reference for JS
davidfig Jun 26, 2024
93a3d4f
Merge branch 'main' into javascript
davidfig Jun 26, 2024
74c7aab
clean up
davidfig Jun 26, 2024
f24aa6c
fix relative cells in both python and JS
davidfig Jun 26, 2024
5139f12
Merge branch 'main' into javascript
davidkircos Jun 26, 2024
f3476c2
searching js in cell type menu shows JavaScript
davidkircos Jun 26, 2024
fcbdfaa
update js docs urls
davidkircos Jun 27, 2024
521fdeb
simplify all docs url links
davidkircos Jun 27, 2024
e5246f8
fix rel_cells await insertion
davidfig Jun 27, 2024
7beb0c3
fixed error line number
davidfig Jun 27, 2024
e465811
fix JS snippet
davidfig Jun 27, 2024
9830ca4
ensure snippets run (or at least compile)
davidfig Jun 27, 2024
ff34055
hide autocomplete when code editor is open
davidfig Jun 27, 2024
fd16ccf
fix bug with insertCellRef for JS; also made insertText work better w…
davidfig Jun 27, 2024
e10fa32
fixes line numbers for lines with comments
davidfig Jun 27, 2024
f045514
better tracking of line numbers when comments // and multi-line comme…
davidfig Jun 27, 2024
c74ff57
fixed positioning of JS image for code cell with error
davidfig Jun 27, 2024
964c646
ensured JS image placement is only changed for error
davidfig Jun 27, 2024
4599d9c
remove alpha for code cell border when editing
davidfig Jun 27, 2024
151833c
add a few more tests
davidfig Jun 27, 2024
045194b
fix clippy
davidfig Jun 27, 2024
d9902df
update ai
davidkircos Jun 27, 2024
23e6369
update prompt
davidkircos Jun 27, 2024
bc08d62
Merge pull request #1485 from quadratichq/javascript-update-ai
davidkircos Jun 27, 2024
72d2e41
Merge branch 'main' into javascript
davidkircos Jun 27, 2024
a6fc7ce
align codeCursor better
davidkircos Jun 27, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"docker:up": "docker compose up -d --wait && npm run prisma:migrate --workspace=quadratic-api",
"docker:down": "docker compose down",
"docker:down:kill-volumes": "docker compose down -v",
"copy:esbuild": "cp -f node_modules/esbuild-wasm/esbuild.wasm quadratic-client/public/",
"gen:pyright:initialization": "npm run gen:pyright:worker --workspace=quadratic-kernels/python-wasm",
"gen:pyright:worker": "npm run gen:pyright:worker --workspace=quadratic-kernels/python-wasm"
},
Expand Down
3 changes: 2 additions & 1 deletion quadratic-client/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ src/shared/shadcn/ui
src/app/web-workers/pythonLanguageServer/pyright-initialization.json
src/app/quadratic-core
src/app/quadratic-core-types
src/app/quadratic-rust-client
src/app/quadratic-rust-client
src/app/web-workers/javascriptWebWorker/worker/javascript/runner
1 change: 1 addition & 0 deletions quadratic-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"clsx": "^2.0.0",
"cmdk": "^1.0.0",
"color": "^4.2.3",
"esbuild-wasm": "^0.20.2",
"eventemitter3": "^5.0.1",
"fontfaceobserver": "^2.3.0",
"fuzzysort": "^2.0.4",
Expand Down
Binary file added quadratic-client/public/esbuild.wasm
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions quadratic-client/src/app/atoms/useJavascriptState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { events } from '@/app/events/events';
import { javascriptWebWorker } from '@/app/web-workers/javascriptWebWorker/javascriptWebWorker';
import { LanguageState } from '@/app/web-workers/languageTypes';
import { useEffect, useState } from 'react';

export const useJavascriptState = (): LanguageState => {
const [state, setState] = useState<LanguageState>(javascriptWebWorker.state);

useEffect(() => {
const updatePythonState = (state: LanguageState) => setState(state);
events.on('javascriptState', updatePythonState);
return () => {
events.off('javascriptState', updatePythonState);
};
}, []);

return state;
};
8 changes: 4 additions & 4 deletions quadratic-client/src/app/atoms/usePythonState.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { events } from '@/app/events/events';
import { PythonStateType } from '@/app/web-workers/pythonWebWorker/pythonClientMessages';
import { LanguageState } from '@/app/web-workers/languageTypes';
import { pythonWebWorker } from '@/app/web-workers/pythonWebWorker/pythonWebWorker';
import { useEffect, useState } from 'react';

export const usePythonState = (): { pythonState: PythonStateType; version?: string } => {
const [pythonState, setPythonState] = useState<PythonStateType>(pythonWebWorker.state);
export const usePythonState = (): { pythonState: LanguageState; version?: string } => {
const [pythonState, setPythonState] = useState<LanguageState>(pythonWebWorker.state);
const [version, setVersion] = useState<string | undefined>(undefined);

useEffect(() => {
const updatePythonVersion = (version: string) => setVersion(version);
const updatePythonState = (state: PythonStateType) => {
const updatePythonState = (state: LanguageState) => {
setPythonState(state);
};
events.on('pythonInit', updatePythonVersion);
Expand Down
10 changes: 8 additions & 2 deletions quadratic-client/src/app/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
SheetBounds,
SheetInfo,
} from '@/app/quadratic-core-types';
import { LanguageState } from '@/app/web-workers/languageTypes';
import { MultiplayerState } from '@/app/web-workers/multiplayerWebWorker/multiplayerClientMessages';
import { CellEdit, MultiplayerUser } from '@/app/web-workers/multiplayerWebWorker/multiplayerTypes';
import { CodeRun, PythonStateType } from '@/app/web-workers/pythonWebWorker/pythonClientMessages';
import { CodeRun } from '@/app/web-workers/pythonWebWorker/pythonClientMessages';
import {
CoreClientImage,
CoreClientImportProgress,
CoreClientTransactionProgress,
CoreClientTransactionStart,
Expand Down Expand Up @@ -56,14 +58,18 @@ interface EventTypes {
renderCodeCells: (sheetId: string, codeCells: JsRenderCodeCell[]) => void;

pythonInit: (version: string) => void;
pythonState: (state: PythonStateType, current?: CodeRun, awaitingExecution?: CodeRun[]) => void;
pythonState: (state: LanguageState, current?: CodeRun, awaitingExecution?: CodeRun[]) => void;
javascriptInit: (version: string) => void;
javascriptState: (state: LanguageState, current?: CodeRun, awaitingExecution?: CodeRun[]) => void;

updateCodeCell: (options: {
sheetId: string;
x: number;
y: number;
codeCell?: JsCodeCell;
renderCodeCell?: JsRenderCodeCell;
}) => void;
updateImage: (message: CoreClientImage) => void;

importProgress: (message: CoreClientImportProgress) => void;
transactionStart: (message: CoreClientTransactionStart) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { events } from '@/app/events/events';
import { sheets } from '@/app/grid/controller/Sheets';
import { LanguageState } from '@/app/web-workers/languageTypes';
import { MultiplayerUser } from '@/app/web-workers/multiplayerWebWorker/multiplayerTypes';
import { CodeRun, PythonStateType } from '@/app/web-workers/pythonWebWorker/pythonClientMessages';
import { CodeRun } from '@/app/web-workers/pythonWebWorker/pythonClientMessages';
import { CircularProgress } from '@mui/material';
import { useEffect, useState } from 'react';
import './CodeRunning.css';
Expand All @@ -23,7 +24,7 @@ export const CodeRunning = () => {

// update player's code runs
useEffect(() => {
const updatePythonState = (_state: PythonStateType, current?: CodeRun, awaitingExecution?: CodeRun[]) => {
const updateRunningState = (_state: LanguageState, current?: CodeRun, awaitingExecution?: CodeRun[]) => {
const code: Code[] = [];
if (current) {
const rectangle = sheets.sheet.getCellOffsets(current.sheetPos.x, current.sheetPos.y);
Expand All @@ -47,7 +48,8 @@ export const CodeRunning = () => {
});
setPlayerCode(code);
};
events.on('pythonState', updatePythonState);
events.on('pythonState', updateRunningState);
events.on('javascriptState', updateRunningState);
}, []);

// update multiplayer's code runs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { inlineEditorKeyboard } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineE
import { CURSOR_THICKNESS } from '@/app/gridGL/UI/Cursor';
import { provideCompletionItems, provideHover } from '@/app/quadratic-rust-client/quadratic_rust_client';
import { FormulaLanguageConfig, FormulaTokenizerConfig } from '@/app/ui/menus/CodeEditor/FormulaLanguageModel';
import * as monaco from 'monaco-editor';
import { editor } from 'monaco-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import * as monaco from 'monaco-editor';
import DefaultEditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import TsEditorWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';

const theme: editor.IStandaloneThemeData = {
base: 'vs',
Expand All @@ -17,11 +18,17 @@ const theme: editor.IStandaloneThemeData = {
};
monaco.editor.defineTheme('inline-editor', theme);

// We are only defining the worker for the editor itself. We may need other
// types down the road, however.
// This is where we globally define worker types for Monaco. See
// https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md
window.MonacoEnvironment = {
getWorker(_, label) {
return new editorWorker();
switch (label) {
case 'typescript':
case 'javascript':
return new TsEditorWorker({ name: label });
default:
return new DefaultEditorWorker({ name: label });
}
},
};

Expand Down
21 changes: 11 additions & 10 deletions quadratic-client/src/app/gridGL/UI/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ export class Cursor extends Graphics {
const editor_selected_cell = editorInteractionState.selectedCell;

// draw cursor but leave room for cursor indicator if needed
const indicatorSize = hasPermissionToEditFile(pixiAppSettings.editorInteractionState.permissions)
? Math.max(INDICATOR_SIZE / viewport.scale.x, 4)
: 0;
const indicatorSize =
hasPermissionToEditFile(pixiAppSettings.editorInteractionState.permissions) &&
(!pixiAppSettings.editorInteractionState.showCodeEditor ||
cursor.cursorPosition.x !== editor_selected_cell.x ||
cursor.cursorPosition.y !== editor_selected_cell.y)
? Math.max(INDICATOR_SIZE / viewport.scale.x, 4)
: 0;
this.indicator.width = this.indicator.height = indicatorSize;
const indicatorPadding = Math.max(INDICATOR_PADDING / viewport.scale.x, 1);
let indicatorOffset = 0;
Expand Down Expand Up @@ -169,12 +173,7 @@ export class Cursor extends Graphics {
editor_selected_cell.x === cell.x &&
editor_selected_cell.y === cell.y)
)
color =
editorInteractionState.mode === 'Python'
? colors.cellColorUserPython
: editorInteractionState.mode === 'Formula'
? colors.cellColorUserFormula
: colors.cursorCell;
color = colors.cursorCell;
davidfig marked this conversation as resolved.
Show resolved Hide resolved
this.beginFill(color).drawShape(this.indicator).endFill();
}
}
Expand All @@ -198,11 +197,13 @@ export class Cursor extends Graphics {
? colors.cellColorUserPython
: editorInteractionState.mode === 'Formula'
? colors.cellColorUserFormula
: editorInteractionState.mode === 'Javascript'
? colors.cellColorUserJavascript
: colors.independence;
}
if (!color || !offsets) return;
this.lineStyle({
width: CURSOR_THICKNESS * 1.5,
width: CURSOR_THICKNESS * 1,
color,
alignment: 0.5,
});
Expand Down
143 changes: 143 additions & 0 deletions quadratic-client/src/app/gridGL/UI/UICellImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { events } from '@/app/events/events';
import { convertColorStringToTint } from '@/app/helpers/convertColor';
import { colors } from '@/app/theme/colors';
import { Container, Graphics } from 'pixi.js';
import { CellsImage } from '../cells/cellsImages/CellsImage';
import { pixiApp } from '../pixiApp/PixiApp';

// These should be consistent with ResizeControl.tsx
export const IMAGE_BORDER_WIDTH = 5;
export const IMAGE_BORDER_OFFSET = 2;
const TRANSITION_DELAY_MS = 200;
const TRANSITION_TIME_MS = 300;

export class UICellImages extends Container {
private borders: Graphics;
private resizing: Graphics;

private active?: CellsImage;
private animationState?: 'delay-enter' | 'delay-exit' | 'enter' | 'exit';
private animationTime = 0;
private animationLastTime = 0;

dirtyBorders = false;
dirtyResizing = false;

constructor() {
super();
this.borders = this.addChild(new Graphics());
this.resizing = this.addChild(new Graphics());
events.on('changeSheet', this.changeSheet);
}

private changeSheet = () => {
this.active = undefined;
this.dirtyBorders = true;
this.dirtyResizing = true;
};

activate(sprite?: CellsImage) {
if (!sprite && this.active) {
this.active = undefined;
this.animationState = 'delay-exit';
this.animationLastTime = Date.now();
this.animationTime = 0;
} else if (this.active !== sprite) {
this.active = sprite;
this.dirtyResizing = true;
this.animationTime = 0;
this.animationState = 'delay-enter';
this.resizing.alpha = 0;
this.animationLastTime = Date.now();
}
}

drawBorders(): boolean {
if (this.dirtyBorders) {
this.dirtyBorders = false;
this.borders.clear();
const images = pixiApp.cellsSheets.current?.getCellsImages();
if (!images) return true;
const color = convertColorStringToTint(colors.quadraticPrimary);
this.borders.lineStyle({ color, width: 1 });
images.forEach((image) => {
this.borders.drawRect(image.x, image.y, image.width, image.height);
});
return true;
}
return false;
}

drawResizing(): boolean {
if (this.dirtyResizing) {
this.dirtyResizing = false;

this.resizing.clear();
if (this.active) {
const color = convertColorStringToTint(colors.quadraticPrimary);
this.resizing.lineStyle({ color, width: IMAGE_BORDER_WIDTH });

// vertical line on the right
this.resizing.moveTo(this.active.x + this.active.width + IMAGE_BORDER_OFFSET, this.active.y);
this.resizing.lineTo(
this.active.x + this.active.width,
this.active.y + this.active.height + IMAGE_BORDER_OFFSET
);

// horizontal line on the bottom
this.resizing.moveTo(this.active.x, this.active.y + this.active.height + IMAGE_BORDER_OFFSET);
this.resizing.lineTo(
this.active.x + this.active.width + IMAGE_BORDER_OFFSET,
this.active.y + this.active.height
);
}
return true;
}
return false;
}

private easeInOutSine(time: number, duration: number): number {
let t = time / duration;
return 0.5 * (1 - Math.cos(t * Math.PI));
}

get dirty(): boolean {
return !!this.animationState || this.dirtyBorders || this.dirtyResizing;
}

update(): boolean {
if (this.animationState) {
const now = Date.now();
this.animationTime += now - this.animationLastTime;
this.animationLastTime = now;
if (this.animationState.includes('delay')) {
if (this.animationTime > TRANSITION_DELAY_MS) {
this.animationState = this.animationState.replace('delay-', '') as 'enter' | 'exit';
this.animationTime -= TRANSITION_DELAY_MS;
}
}
if (this.animationState === 'enter') {
if (this.animationTime > TRANSITION_TIME_MS) {
this.animationState = undefined;
this.resizing.alpha = 1;
} else {
this.resizing.alpha = this.easeInOutSine(this.animationTime, TRANSITION_TIME_MS) as number;
}
} else if (this.animationState === 'exit') {
if (this.animationTime > TRANSITION_TIME_MS) {
this.animationState = undefined;
this.resizing.alpha = 0;
} else {
this.resizing.alpha = (1 - this.easeInOutSine(this.animationTime, TRANSITION_TIME_MS)) as number;
}
}
this.drawBorders();
this.drawResizing();
return true;
} else {
let rendered = this.drawBorders();
if (this.drawResizing()) return true;
return rendered;
}
}
}
2 changes: 1 addition & 1 deletion quadratic-client/src/app/gridGL/UI/drawCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const drawMultiCursor = (g: Graphics, color: number, alpha: number, recta
const sheet = sheets.sheet;
g.lineStyle(1, color, 1, 0, true);
g.beginFill(color, alpha);
rectangles.forEach((rectangle, index) => {
rectangles.forEach((rectangle) => {
const rect = sheet.getScreenRectangle(rectangle.x, rectangle.y, rectangle.width - 1, rectangle.height - 1);
g.drawShape(rect);
});
Expand Down
Loading
Loading