Skip to content

Commit

Permalink
fix: set line font style
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jan 20, 2025
1 parent f1db115 commit bec8f43
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
57 changes: 55 additions & 2 deletions src/components/canvas/component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
buildSelectedDataFromCell,
buildSelectedDataFromCellRange,
buildSelectedDataFromLines,
getSelectedCellRange,
SelectedData,
} from './events'
Expand Down Expand Up @@ -157,12 +159,58 @@ const Internal: FC<CanvasProps> = observer((props: CanvasProps) => {
if (isDnd) return
}
store.selector.onMouseMove(startCell)
store.endCell = startCell
})
mouseUp$.pipe(take(1)).subscribe(() => {
store.type = undefined
store.dnd.onMouseUp()
store.selector.onMouseUp()
store.resizer.mouseup()
sub.unsubscribe()
if (!store.startCell) return
if (store.startCell?.type !== store.endCell?.type && store.endCell)
return

let data: SelectedData
const {startRow, startCol} = store.startCell.coordinate
const endRow = store.endCell
? store.endCell.coordinate.startRow
: startRow
const endCol = store.endCell
? store.endCell.coordinate.startCol
: startCol
if (store.startCell?.type === 'FixedLeftHeader') {
data = buildSelectedDataFromLines(
startRow,
endRow,
'row',
'none'
)
} else if (store.startCell?.type === 'FixedTopHeader') {
data = buildSelectedDataFromLines(
startCol,
endCol,
'col',
'none'
)
} else if (store.startCell?.type === 'Cell') {
if (store.endCell?.type === 'Cell') {
const {startRow: endRow, startCol: endCol} =
store.endCell.coordinate
data = buildSelectedDataFromCellRange(
startRow,
startCol,
endRow,
endCol,
'none'
)
} else {
data = buildSelectedDataFromCell(startRow, startCol, 'none')
}
} else {
return
}
selectedData$(data)
})

const isResize = store.resizer.mousedown(e.nativeEvent)
Expand All @@ -174,9 +222,14 @@ const Internal: FC<CanvasProps> = observer((props: CanvasProps) => {
const matchCell = store.match(e.clientX, e.clientY)
if (!matchCell) return
store.mousedown(e, matchCell)
if (matchCell?.type !== 'Cell') return
const {startRow: row, startCol: col} = matchCell.coordinate
const data = buildSelectedDataFromCell(row, col, 'none')
let data: SelectedData
if (matchCell?.type === 'FixedLeftHeader') {
data = buildSelectedDataFromLines(row, row, 'row', 'none')
} else if (matchCell?.type === 'FixedTopHeader') {
data = buildSelectedDataFromLines(col, col, 'col', 'none')
} else if (matchCell?.type !== 'Cell') return
data = buildSelectedDataFromCell(row, col, 'none')
selectedData$(data)
}

Expand Down
31 changes: 31 additions & 0 deletions src/components/canvas/events/selected-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,34 @@ export function buildSelectedDataFromCell(
},
}
}

export function buildSelectedDataFromCellRange(
startRow: number,
startCol: number,
endRow: number,
endCol: number,
source: 'editbar' | 'none'
): SelectedData {
return {
source,
data: {
ty: 'cellRange',
d: {startRow, endRow, startCol, endCol},
},
}
}

export function buildSelectedDataFromLines(
start: number,
end: number,
type: 'row' | 'col',
source: 'editbar' | 'none'
): SelectedData {
return {
source,
data: {
ty: 'line',
d: {start, end, type},
},
}
}
11 changes: 11 additions & 0 deletions src/components/canvas/store/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export class Selector {
this.startCell = startCell
}

@action
onMouseUp() {
if (!this.store.startCell) {
this.selector = undefined
return
}
this.selector = new SelectorProps()
this.updateSelector(this.startCell, this.endCell)
this._aftetUpdateSelector()
}

@action
onMouseDown() {
this.endCell = undefined
Expand Down
1 change: 1 addition & 0 deletions src/components/canvas/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class CanvasStore {
}
@observable.ref
startCell?: Cell
endCell?: Cell

type?: 'mousedown' | 'contextmenu'
/**
Expand Down

0 comments on commit bec8f43

Please sign in to comment.