@@ -8,14 +8,11 @@ import {
88 type CellValue ,
99 CellValueType ,
1010 type ICellData ,
11- ICommandInfo ,
1211 type IObjectMatrixPrimitiveType ,
1312 type IStyleData ,
1413 type IWorkbookData ,
1514 type IWorksheetData ,
1615 LocaleType ,
17- Nullable ,
18- Tools ,
1916 Univer ,
2017 UniverInstanceType ,
2118 type Workbook ,
@@ -64,9 +61,14 @@ function setupUniver(component_index: number) {
6461}
6562
6663function setupErrorModal ( component_index : number ) {
67- const resp_modal = document . getElementById ( `errorModal_${ component_index } ` ) ! ;
68- const resp_modal_body = resp_modal . querySelector ( ".modal-body" ) ! ;
69- const Modal = window [ "bootstrap" ] . Modal ;
64+ const resp_modal = document . getElementById ( `errorModal_${ component_index } ` ) ;
65+ if ( ! resp_modal ) throw new Error ( `errorModal_${ component_index } not found` ) ;
66+ const resp_modal_body = resp_modal . querySelector ( ".modal-body" ) ;
67+ if ( ! resp_modal_body )
68+ throw new Error ( `errorModal_${ component_index } not found` ) ;
69+ // @ts -ignore : bootstrap is included separately by sqlpage, and available globally
70+ const Modal = window ?. bootstrap ?. Modal ;
71+ if ( ! Modal ) throw new Error ( "bootstrap.Modal not found" ) ;
7072 return { resp_modal, resp_modal_body, Modal } ;
7173}
7274
@@ -75,7 +77,7 @@ async function handleUpdate(
7577 x : number ,
7678 y : number ,
7779 value : CellValue | null ,
78- custom : any ,
80+ custom : Record < string , unknown > ,
7981 errorModal : ReturnType < typeof setupErrorModal > ,
8082) {
8183 if ( ! update_link ) return ;
@@ -87,7 +89,7 @@ async function handleUpdate(
8789 formData . append ( "y" , y . toString ( ) ) ;
8890 if ( value != null )
8991 formData . append ( "value" , value == null ? "" : value . toString ( ) ) ;
90- if ( custom && custom . id !== null ) formData . append ( "id" , custom . id ) ;
92+ if ( typeof custom . id === "string" ) formData . append ( "id" , custom . id ) ;
9193 const r = await fetch ( url , { method : "POST" , body : formData } ) ;
9294 let resp_html = await r . text ( ) ;
9395 if ( r . status !== 200 && ! resp_html ) resp_html = r . statusText ;
@@ -97,7 +99,9 @@ async function handleUpdate(
9799 }
98100}
99101
100- function cellFromProps ( props : any [ ] ) : Partial < IStyleData & { id : string } > {
102+ function cellFromProps (
103+ props : ( string | number ) [ ] ,
104+ ) : Partial < IStyleData & { id : string } > {
101105 const s : Partial < IStyleData & { id : string } > = { } ;
102106 for ( let i = 0 ; i < props . length ; i ++ ) {
103107 const n = props [ i ] ;
@@ -107,30 +111,35 @@ function cellFromProps(props: any[]): Partial<IStyleData & { id: string }> {
107111 const color = props [ ++ i ] ;
108112 s . bg = {
109113 rgb : getComputedStyle ( document . documentElement ) . getPropertyValue (
110- " --tblr-" + color ,
114+ ` --tblr-${ color } ` ,
111115 ) ,
112116 } ;
113117 } else if ( n === 4 ) s . ht = 2 ;
114118 else if ( n === 5 ) s . ht = 3 ;
115119 else if ( n === 6 ) {
116- const pattern = props [ ++ i ] ;
120+ const pattern = props [ ++ i ] . toString ( ) ;
117121 s . n = { pattern } ;
118- } else if ( n === 7 ) s . id = props [ ++ i ] ;
122+ } else if ( n === 7 ) s . id = props [ ++ i ] . toString ( ) ;
119123 }
120124 return s ;
121125}
122126
123127/**
124128 * [colIdx, rowIdx, value, ...props]
125129 */
126- type DataArray = [ number , number , string | number | null , ...any [ ] ] ;
130+ type DataArray = [
131+ number ,
132+ number ,
133+ string | number | null ,
134+ ...( string | number ) [ ] ,
135+ ] ;
127136
128137function generateWorkSheet ( dataArray : DataArray [ ] ) : Partial < IWorksheetData > {
129138 const cellData : IObjectMatrixPrimitiveType < ICellData > = { } ;
130139 let rowCount = 1000 ;
131140 let columnCount = 26 ;
132141
133- dataArray . forEach ( ( [ colIdx , rowIdx , value , ...props ] ) => {
142+ for ( const [ colIdx , rowIdx , value , ...props ] of dataArray ) {
134143 const cell : Partial < ICellData > = { v : value } ;
135144 const style = props . length ? cellFromProps ( props ) : null ;
136145 cell . s = style ;
@@ -141,7 +150,7 @@ function generateWorkSheet(dataArray: DataArray[]): Partial<IWorksheetData> {
141150 else cellData [ rowIdx ] = { [ colIdx ] : cell } ;
142151 rowCount = Math . max ( rowCount , rowIdx ) ;
143152 columnCount = Math . max ( columnCount , colIdx ) ;
144- } ) ;
153+ }
145154
146155 return {
147156 id : "sqlpage" ,
@@ -152,7 +161,7 @@ function generateWorkSheet(dataArray: DataArray[]): Partial<IWorksheetData> {
152161 } ;
153162}
154163
155- function createWorkbook ( univer : Univer , data : any [ ] ) : Workbook {
164+ function createWorkbook ( univer : Univer , data : DataArray [ ] ) : Workbook {
156165 return univer . createUnit < IWorkbookData , Workbook > (
157166 UniverInstanceType . UNIVER_SHEET ,
158167 {
@@ -191,6 +200,12 @@ async function renderSpreadsheet({
191200 freeze_y,
192201 component_index,
193202 data,
203+ } : {
204+ update_link : string ;
205+ freeze_x : number ;
206+ freeze_y : number ;
207+ component_index : number ;
208+ data : DataArray [ ] ;
194209} ) {
195210 const errorModal = setupErrorModal ( component_index ) ;
196211 const univer = setupUniver ( component_index ) ;
@@ -216,7 +231,7 @@ async function renderSpreadsheet({
216231 Number . parseInt ( col ) ,
217232 Number . parseInt ( row ) ,
218233 cell . v as V ,
219- cell . custom ,
234+ cell . custom || { } ,
220235 errorModal ,
221236 ) ;
222237 }
0 commit comments