This commit is contained in:
2025-09-05 01:53:41 +10:00
parent bba8986c88
commit fb40c0a2ce
2 changed files with 35 additions and 28 deletions

View File

@@ -3,7 +3,14 @@
import Cell from '$lib/components/grid/cell.svelte';
import { onDestroy, onMount } from 'svelte';
import CellHeader from './cell-header.svelte';
import { fromGridRef, toColLetter, toGridRef, type CellData, type CellValue } from './utils';
import {
fromGridRef,
splitErrorString,
toColLetter,
toGridRef,
type CellData,
type CellValue
} from './utils';
let {
socket
@@ -11,27 +18,6 @@
socket: WebSocket;
} = $props();
function splitErrorString(errorString: string) {
// Remove the "ERR " prefix.
const content = errorString.substring(4);
// Find the index of the first colon.
const colonIndex = content.indexOf(':');
// If no colon is found, return the whole content as the first element.
if (colonIndex === -1) {
return [content.trim(), ''];
}
// Extract the part before the colon (the error type).
const errorType = content.substring(0, colonIndex).trim();
// Extract the part after the colon (the error message).
const errorMessage = content.substring(colonIndex + 1).trim();
return [errorType, errorMessage];
}
socket.onmessage = (msg: MessageEvent) => {
const input = msg.data.toString().trim();
@@ -87,8 +73,8 @@
}
};
let rows = 50;
let cols = 50;
let rows = 100;
let cols = 60;
let default_row_height = '30px';
let default_col_width = '60px';

View File

@@ -1,3 +1,10 @@
export type CellValue = number | string | undefined;
export interface CellData {
raw_val: string;
val: CellValue;
}
export function fromGridRef(ref: string): [number, number] {
const match = ref.match(/^([A-Z]+)([0-9]+)$/i);
if (!match) throw new Error('Invalid reference');
@@ -31,9 +38,23 @@ export function toGridRef(row: number, col: number): string {
return toColLetter(col) + row.toString();
}
export type CellValue = number | string | undefined;
export function splitErrorString(errorString: string) {
// Remove the "ERR " prefix.
const content = errorString.substring(4);
export interface CellData {
raw_val: string;
val: CellValue;
// Find the index of the first colon.
const colonIndex = content.indexOf(':');
// If no colon is found, return the whole content as the first element.
if (colonIndex === -1) {
return [content.trim(), ''];
}
// Extract the part before the colon (the error type).
const errorType = content.substring(0, colonIndex).trim();
// Extract the part after the colon (the error message).
const errorMessage = content.substring(colonIndex + 1).trim();
return [errorType, errorMessage];
}