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

UI cell style #118

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
263998a
Merge branch 'core-cell-style' into ui-cell-style
rafinutshaw Mar 6, 2024
721b1b7
Merge branch 'main' into ui-cell-style
rafinutshaw Mar 17, 2024
13a3fc7
Merge branch 'main' into ui-cell-style
rafinutshaw Mar 20, 2024
bb77cfc
Add style initialization
rafinutshaw Mar 20, 2024
eb2037c
Merge branch 'main' into ui-cell-style
rafinutshaw Mar 28, 2024
bee91cc
Merge branch 'main' into ui-cell-style
rafinutshaw Apr 13, 2024
8779655
Merge branch 'main' into ui-cell-style
rafinutshaw Apr 14, 2024
2c37fe1
Fix lint
rafinutshaw Apr 14, 2024
103222d
Add styling functionality
rafinutshaw Apr 14, 2024
351264a
Add interface for formatter
rafinutshaw Apr 17, 2024
d36c7b0
Merge branch 'lightsheet-cell-formatting' into ui-cell-style
rafinutshaw Apr 17, 2024
6eba0b7
Add column styling
rafinutshaw Apr 18, 2024
089bdb6
Add row styling
rafinutshaw Apr 19, 2024
b63ed25
Fix lint
rafinutshaw Apr 19, 2024
097ede5
Add setCss interface
rafinutshaw Apr 19, 2024
bf94509
Fix lint
rafinutshaw Apr 19, 2024
8324a87
Fix tests
rafinutshaw Apr 19, 2024
c5e6b8e
Add formatter
rafinutshaw Apr 24, 2024
c0da8c5
Fix formatter
rafinutshaw Apr 24, 2024
3f6113f
Merge branch 'main' into ui-cell-style
rafinutshaw Apr 24, 2024
f7c180e
Add columnstyle and remove key from ui
rafinutshaw Apr 24, 2024
ac97b31
Add rowFormatter
rafinutshaw Apr 24, 2024
cf8d910
Fix tests
rafinutshaw Apr 24, 2024
f21a16c
Add clear style scaffold
rafinutshaw Apr 24, 2024
4bc350d
Add clear formatter feature
rafinutshaw Apr 28, 2024
faf1fff
Cleanup
rafinutshaw Apr 28, 2024
4a7f136
Remove coordinate and use indexInfo
rafinutshaw Apr 28, 2024
68105de
Remove unused import
rafinutshaw Apr 28, 2024
80ac0de
Merge branch 'main' into ui-cell-style
rafinutshaw Apr 29, 2024
ff19cfe
Fix lint
rafinutshaw Apr 29, 2024
52e409e
Fix merge error
rafinutshaw Apr 29, 2024
5ed3f7a
Fix tests
rafinutshaw Apr 29, 2024
2619d45
Add test and restructure files
rafinutshaw Apr 29, 2024
44b6f9f
Fix lint
rafinutshaw Apr 29, 2024
137a916
Cleanup
rafinutshaw Apr 29, 2024
8852e9c
Fix css import
rafinutshaw Apr 29, 2024
27c9eb8
Update initial table data
rafinutshaw Apr 29, 2024
1509930
Uncomment commented test
rafinutshaw Apr 29, 2024
0cb0017
Fix lint
rafinutshaw Apr 29, 2024
0db6a54
Rename event enums
rafinutshaw Apr 29, 2024
398f3c2
Rename cellstyle styling property to css
rafinutshaw Apr 29, 2024
ce8caf1
Rename type indexinfo and positioninfo to indexposition and keyposition
rafinutshaw Apr 29, 2024
8ff4da4
Fix duplicate code
rafinutshaw Apr 29, 2024
cce9b1d
Move indexposition type to common.types.ts
rafinutshaw Apr 29, 2024
0dfaecf
Fix eventtype import
rafinutshaw Apr 29, 2024
5347dba
Remove unused code
rafinutshaw Apr 29, 2024
9d4b76e
Cleaup
rafinutshaw Apr 29, 2024
db12afa
Improve emitSetStyleEvent
rafinutshaw Apr 29, 2024
5709af7
Remove getCellGroupByIndex
rafinutshaw Apr 30, 2024
b10b783
Fix based on feedback
rafinutshaw May 3, 2024
d842341
Merge branch 'main' into ui-cell-style
rafinutshaw May 3, 2024
8e07c44
Cleanup setCellGroupStyle
rafinutshaw May 3, 2024
1dee866
Fix lint
rafinutshaw May 3, 2024
1a3f260
Cleanup
rafinutshaw May 3, 2024
5043b44
Cleanup
rafinutshaw May 3, 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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="src/ui/ui.css" type="text/css" />
<link rel="stylesheet" href="src/view/view.css" type="text/css" />
<!--api for the icons in tool bar-->
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
27 changes: 22 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import Lightsheet from "./src/main.ts";
var data = [
["", "=1+2/3*6+A1+test(1,2)", "img/nophoto.jpg", "Marketing"],
["2", "Jorge", "img/nophoto.jpg", "Marketing", "3120"],
["3", "Jorge", "img/nophoto.jpg", "Marketing", "3120"],
["1", "=1+2/3*6+A1+test(1,2)", "img/nophoto.jpg", "Marketing"],
["2.44445", "400000.000000", "img/nophoto.jpg", "Marketing", "3120"],
["3.555555", "312", "43", "64", "3120"],
];

const toolbar = ["undo", "redo", "save"];

new Lightsheet(
{
sheetName: "Sheet1",
data,
onCellChange: (colIndex, rowIndex, newValue) => {
console.log(colIndex, rowIndex, newValue);
},
toolbarOptions: {
showToolbar: true,
showToolbar: false,
items: toolbar,
element: document.getElementById("toolbar-dom-id"),
},
style: [
{
position: "A",
css: "font-weight: bold;",
format: { type: "number", options: { decimal: 2 } },
},
{
position: "B2",
css: "background-color: yellow;",
format: { type: "number", options: { decimal: 2 } },
},
{
position: "3",
css: "background-color: gray;",
format: { type: "number", options: { decimal: 0 } },
},
],
},
document.getElementById("lightsheet"),
);
16 changes: 8 additions & 8 deletions src/core/evaluation/expressionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from "./expressionHandler.types.ts";

import { CellState } from "../structure/cell/cellState.ts";
import LightsheetHelper from "../../utils/helpers.ts";
import { Coordinate } from "../../utils/common.types.ts";
import { GenerateColumnLabel } from "../../utils/helpers.ts";
import { IndexPosition } from "../../utils/common.types.ts";
import { CellReference } from "../structure/cell/types.cell.ts";
import SheetHolder from "../structure/sheetHolder.ts";

Expand Down Expand Up @@ -86,16 +86,16 @@ export default class ExpressionHandler {
}
}

updatePositionalReferences(from: Coordinate, to: Coordinate) {
updatePositionalReferences(from: IndexPosition, to: IndexPosition) {
if (!this.rawValue.startsWith("=")) return this.rawValue;

const expression = this.rawValue.substring(1);
const parseResult = math.parse(expression);

const fromSymbol =
LightsheetHelper.generateColumnLabel(from.column + 1) + (from.row + 1);
GenerateColumnLabel(from.columnIndex! + 1) + (from.rowIndex! + 1);
const toSymbol =
LightsheetHelper.generateColumnLabel(to.column + 1) + (to.row + 1);
GenerateColumnLabel(to.columnIndex! + 1) + (to.rowIndex! + 1);

// Update each symbol in the expression.
const transform = parseResult.transform((node) =>
Expand Down Expand Up @@ -212,7 +212,7 @@ export default class ExpressionHandler {

this.cellRefHolder.push({
sheetKey: targetSheet.key,
position: { column: j, row: i },
position: { columnIndex: j, rowIndex: i },
});
values.push(cellInfo?.resolvedValue ?? "");
}
Expand All @@ -230,8 +230,8 @@ export default class ExpressionHandler {
this.cellRefHolder.push({
sheetKey: targetSheet.key,
position: {
column: colIndex,
row: rowIndex,
columnIndex: colIndex,
rowIndex: rowIndex,
},
});
return cellInfo?.resolvedValue ?? "";
Expand Down
4 changes: 2 additions & 2 deletions src/core/evaluation/expressionHandler.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IndexPosition } from "../../utils/common.types.ts";
import { SheetKey } from "../structure/key/keyTypes.ts";
import { Coordinate } from "../../utils/common.types.ts";

export type CellSheetPosition = {
sheetKey: SheetKey;
position: Coordinate;
position: IndexPosition;
};

export type EvaluationResult = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/event/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EventType from "./eventType";
import EventState from "./eventState";
import { EventType } from "./events.types";

export default class Event {
eventType: EventType;
Expand Down
6 changes: 0 additions & 6 deletions src/core/event/eventType.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/event/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventType from "./eventType";
import Event from "./event";
import EventState from "./eventState";
import { EventType } from "./events.types";

export type ListenerFunction = (event: Event) => void;

Expand Down
27 changes: 19 additions & 8 deletions src/core/event/events.types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import { PositionInfo } from "../structure/sheet.types.ts";
import { Coordinate } from "../../utils/common.types.ts";
import { IndexPosition } from "../../utils/common.types.ts";
import { KeyPosition } from "../structure/sheet.types.ts";

export type UISetCellPayload = {
keyPosition?: PositionInfo;
indexPosition?: Coordinate;
keyPosition?: KeyPosition;
indexPosition?: IndexPosition;
rawValue: string;
};

export type CoreSetCellPayload = {
keyPosition: PositionInfo;
indexPosition: Coordinate;
keyPosition?: KeyPosition;
indexPosition: IndexPosition;
rawValue: string;
formattedValue: string;

clearCell: boolean;
clearRow: boolean;
clearCell?: boolean;
clearRow?: boolean;
};

export type CoreSetStylePayload = {
indexPosition: IndexPosition;
value: string;
};

export enum EventType {
VIEW_SET_CELL = 0,
CORE_SET_CELL = 1,
VIEW_SET_STYLE = 2,
}
31 changes: 21 additions & 10 deletions src/core/structure/cellStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import Cloneable from "../cloneable.ts";

export default class CellStyle extends Cloneable<CellStyle> {
formatter: Formatter | null;
styling: Map<string, string>;
css: Map<string, string>;

constructor(
styling: Map<string, string> | null = null,
css: Map<string, string> | null = null,
formatter: Formatter | null = null,
) {
super();
this.formatter = formatter;
this.styling = new Map(styling);
this.css = new Map(css);
}

applyStylesOf(other: CellStyle | null): CellStyle {
if (!other) return this;

// If a style is set in other but not in this, apply it to this.
for (const [key, value] of other.styling) {
if (!this.styling.has(key)) {
this.styling.set(key, value);
for (const [key, value] of other.css) {
if (!this.css.has(key)) {
this.css.set(key, value);
}
}

Expand All @@ -31,19 +31,30 @@ export default class CellStyle extends Cloneable<CellStyle> {
return this;
}

applyCss(css: Map<string, string>): CellStyle {
// If a style is set in other but not in this, apply it to this.
for (const [key, value] of css) {
if (!this.css.has(key)) {
this.css.set(key, value);
}
}

return this;
}

clearStylingSetBy(other: CellStyle | null) {
if (!other) return false;
let isEmpty = true;

// If a property is set in other, clear it from this.
for (const key in other.styling) {
if (this.styling.has(key)) {
this.styling.delete(key);
for (const key in other.css) {
if (this.css.has(key)) {
this.css.delete(key);
}

if (other.formatter) this.formatter = null;

if (isEmpty && (this.styling.has(key) || this.formatter)) isEmpty = false;
if (isEmpty && (this.css.has(key) || this.formatter)) isEmpty = false;
}

return isEmpty;
Expand Down
Loading
Loading