Skip to content

Commit

Permalink
Next job on the list is selection and general UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
set authored and J-Cake committed Sep 16, 2024
1 parent b22047e commit a35bf1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class SpreadsheetPlugin extends obs.Plugin {
// TODO: Handle existing files
const newFile = path.join(obs.normalizePath(file.path ?? this.app.vault.getRoot()), 'sheet.csv');

const tfile = await this.app.vault.create(newFile, ';\n;');
const tfile = await this.app.vault.create(newFile, 'Column 1;\n;');
await this.app.workspace.getLeaf(false).openFile(tfile);
}))));
}
Expand Down
38 changes: 19 additions & 19 deletions src/spreadsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as obs from "obsidian";
import * as React from "react";
import * as rdom from "react-dom/client";

import Table, {DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, MIN_COLUMN_WIDTH, MIN_ROW_HEIGHT} from "./table.js";
import FormulaBar, {CellRenderer, renderers} from "./formula.js";
import Table, { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, MIN_COLUMN_WIDTH, MIN_ROW_HEIGHT } from "./table.js";
import FormulaBar, { CellRenderer, renderers } from "./formula.js";

export const SPREADSHEET_VIEW = "spreadsheet-view";

Expand Down Expand Up @@ -195,7 +195,7 @@ export default class Spreadsheet extends obs.TextFileView {
}));

const prevRaw = [...this.raw];
const prevProps = {...this.documentProperties};
const prevProps = { ...this.documentProperties };
this.raw = [];

for (const [cells, row] of rows.map((i, row) => [i.split(separator), row] as const)) {
Expand Down Expand Up @@ -304,7 +304,7 @@ export default class Spreadsheet extends obs.TextFileView {

protected async onOpen(): Promise<void> {
(this.root = rdom.createRoot(this.contentEl))
.render(<Ui sheet={this}/>);
.render(<Ui sheet={this} />);
}

protected async onClose(): Promise<void> {
Expand Down Expand Up @@ -344,27 +344,27 @@ export function Ui(props: { sheet: Spreadsheet }) {
onResize: prev.onResize
};
})}
onMouseUp={() => setResize({isResizing: false})}>
onMouseUp={() => setResize({ isResizing: false })}>

{/*<SelectionBar/>*/}

<FormulaBar activeCell={active}/>
<FormulaBar activeCell={active} />

<Table raw={props.sheet.raw}
columnWidths={documentProperties.columnWidths}
rowHeights={documentProperties.rowHeights}
mouseUp={(row, col) => setActive(props.sheet.raw[row][col])}
mouseDown={(row, col) => setActive(props.sheet.raw[row][col])}>
columnWidths={documentProperties.columnWidths}
rowHeights={documentProperties.rowHeights}
mouseUp={(row, col) => setActive(props.sheet.raw[row][col])}
mouseDown={(row, col) => setActive(props.sheet.raw[row][col])}>

<>
{documentProperties.columnTitles.map((column, col) =>
<div className={"table-header-cell"}
key={`table-header-${col}`}
style={{
gridColumn: col + 2,
gridRow: 1
}}
onContextMenu={e => columnContextMenu(e, col, props.sheet, setIsRenamingColumn)}
key={`table-header-${col}`}
style={{
gridColumn: col + 2,
gridRow: 1
}}
onContextMenu={e => columnContextMenu(e, col, props.sheet, setIsRenamingColumn)}
onDoubleClick={e => setIsRenamingColumn(col)}>
<div className={"column-title"}>
{isRenamingColumn == col ? <input
Expand All @@ -377,7 +377,7 @@ export function Ui(props: { sheet: Spreadsheet }) {
onKeyUp={e => ["Tab", "Enter"].includes(e.key) && setIsRenamingColumn(null)}
onChange={e => props.sheet.updateDocumentProperties(prev => ({
columnTitles: prev.columnTitles.with(col, e.currentTarget.value)
}))}/> : column}
}))} /> : column}
{props.sheet.columnType(col) != 'raw' ?
<div className={"nav-file-tag"}>
{props.sheet.columnType(col)}
Expand All @@ -396,7 +396,7 @@ export function Ui(props: { sheet: Spreadsheet }) {
onResize: size => props.sheet.updateDocumentProperties(prev => ({
columnWidths: prev.columnWidths.with(col, Math.max(size.width, MIN_COLUMN_WIDTH))
}))
})}/>
})} />
</div>)}
</>
<>
Expand Down Expand Up @@ -424,7 +424,7 @@ export function Ui(props: { sheet: Spreadsheet }) {
onResize: size => props.sheet.updateDocumentProperties(prev => ({
rowHeights: prev.rowHeights.with(row, Math.max(size.height, MIN_ROW_HEIGHT))
}))
})}/>
})} />
</div>)}
</>

Expand Down
2 changes: 1 addition & 1 deletion src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TableProps {
columnWidths: number[],
rowHeights: number[],
mouseUp: (row: number, col: number) => void
mouseDown: (row: number, col: number) => void
mouseDown: (row: number, col: number) => void,
}

export default function Table(props: TableProps) {
Expand Down
2 changes: 0 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ textarea {
.table-container {
grid-area: table;

background: var(--table-background);
border-collapse: collapse;
box-sizing: border-box;

Expand Down Expand Up @@ -147,7 +146,6 @@ textarea {
overflow: hidden;
white-space: nowrap;

background: var(--table-background);
cursor: crosshair;

display: flex;
Expand Down

0 comments on commit a35bf1e

Please sign in to comment.