logisheets_controller 1.7.1

the core of LogiSheets
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
use crate::CellInfo;

use super::style::Style;
use gents_derives::TS;
use logisheets_base::{BlockId, SheetId};

use crate::block_manager::schema_manager::schema::RenderId;

#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_position.ts", rename_all = "camelCase")]
pub struct CellPosition {
    pub x: f64,
    pub y: f64,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_coordinate.ts", rename_all = "camelCase")]
pub struct CellCoordinate {
    pub x: usize,
    pub y: usize,
}

/// One exported block row: the field values in schema (column) order. Wrapping
/// the row in a struct keeps the exported matrix as `BlockDataRow[]` rather
/// than a nested `Value[][]`, which the TS binding generator can't render.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_data_row.ts", rename_all = "camelCase")]
pub struct BlockDataRow {
    pub cells: Vec<crate::Value>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_coordinate_with_sheet.ts", rename_all = "camelCase")]
pub struct CellCoordinateWithSheet {
    pub sheet_idx: usize,
    pub coordinate: CellCoordinate,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "shadow_cell_info.ts", rename_all = "camelCase")]
pub struct ShadowCellInfo {
    pub start_position: CellPosition,
    pub end_position: CellPosition,
    pub value: Value,
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "display_window.ts", rename_all = "camelCase")]
pub struct DisplayWindow {
    pub cells: Vec<CellInfo>,
    pub rows: Vec<RowInfo>,
    pub cols: Vec<ColInfo>,
    pub comments: Vec<Comment>,
    pub merge_cells: Vec<MergeCell>,
    pub blocks: Vec<BlockDisplayInfo>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_display_info.ts", rename_all = "camelCase")]
pub struct BlockDisplayInfo {
    pub info: BlockInfo,
    pub start_position: CellPosition,
    pub end_position: CellPosition,
}

#[derive(Debug, Clone, TS)]
#[ts(
    file_name = "display_window_with_start_point.ts",
    rename_all = "camelCase"
)]
pub struct DisplayWindowWithStartPoint {
    pub window: DisplayWindow,
    pub start_x: f64,
    pub start_y: f64,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_names.ts", rename_all = "camelCase")]
pub struct SheetNames {
    pub names: Vec<String>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_info.ts", rename_all = "camelCase")]
pub struct SheetInfo {
    pub name: String,
    pub id: SheetId,
    pub hidden: bool,
    pub tab_color: String,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_blocks.ts", rename_all = "camelCase")]
pub struct SheetBlocks {
    pub sheet_idx: usize,
    pub blocks: Vec<BlockInfo>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_info.ts", rename_all = "camelCase")]
pub struct BlockInfo {
    pub sheet_idx: usize,
    pub sheet_id: SheetId,
    pub block_id: BlockId,
    pub row_start: usize,
    pub row_cnt: usize,
    pub col_start: usize,
    pub col_cnt: usize,
    pub schema: Option<BlockSchema>,
    pub field_renders: Vec<FieldRenderEntry>,
    pub cells: Vec<BlockCellInfo>,
}

/// A range that is linked to a backing block: the *source* range (the cells the
/// user references, e.g. `A1:A10`) resolved to sheet coordinates, plus the block
/// id it redirects to. The app draws an outer border around the source range.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "link_info.ts", rename_all = "camelCase")]
pub struct LinkInfo {
    pub sheet_idx: usize,
    pub block_id: BlockId,
    pub start_row: usize,
    pub start_col: usize,
    pub end_row: usize,
    pub end_col: usize,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_schema.ts", rename_all = "camelCase")]
pub struct BlockSchema {
    pub name: String,
    pub schema_type: BlockSchemaType,
    pub keys: Vec<BlockSchemaKeyEntry>,
    pub fields: Vec<BlockSchemaFieldEntry>,
    pub random_entries: Vec<BlockSchemaRandomEntry>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_schema_type.ts", rename_all = "camelCase")]
pub enum BlockSchemaType {
    Row,
    Col,
    Random,
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_key_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaKeyEntry {
    pub key: String,
    pub idx: usize,
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_field_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaFieldEntry {
    pub field: String,
    pub idx: usize,
    pub render_id: RenderId,
    /// Raw value-formula template (e.g. `=#FIELD("qty")*#FIELD("price")`)
    /// or `None` for free-form fields. Engine-managed: writing a value
    /// to a templated cell is rejected.
    pub value_formula: Option<String>,
    /// Raw validation-formula template. Engine installs a
    /// `ShadowKind::Validation` shadow per row at bind / insert time;
    /// host UI reads the shadow to render warning markers.
    pub validation_formula: Option<String>,
    /// Raw editability-formula template. Engine installs a
    /// `ShadowKind::UserEditable` shadow per row at bind / insert time;
    /// host permission layer reads the shadow to gate writes.
    pub editability_formula: Option<String>,
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_random_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaRandomEntry {
    pub key: String,
    pub row: usize,
    pub col: usize,
    pub render_id: RenderId,
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "field_render_entry.ts", rename_all = "camelCase")]
pub struct FieldRenderEntry {
    pub render_id: RenderId,
    pub style: Option<Style>,
    pub diy_render: bool,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_cell_info.ts", rename_all = "camelCase")]
pub struct BlockCellInfo {
    pub value: Value,
    // None means that no shadow cell has been created
    pub shadow_value: Option<Value>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "display_window_request.ts", rename_all = "camelCase")]
pub struct DisplayWindowRequest {
    pub sheet_idx: usize,
    pub height: f64,
    pub width: f64,
    pub start_x: f64,
    pub start_y: f64,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_merge_cells.ts", rename_all = "camelCase")]
pub struct SheetMergeCells {
    pub sheet_idx: usize,
    pub merge_cells: Vec<MergeCell>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_comments.ts", rename_all = "camelCase")]
pub struct SheetComments {
    pub sheet_idx: usize,
    pub comments: Vec<Comment>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "merge_cell.ts", rename_all = "camelCase")]
pub struct MergeCell {
    pub start_row: usize,
    pub start_col: usize,
    pub end_row: usize,
    pub end_col: usize,
}

/// An image placed in a cell. `data` is the base64-encoded image bytes and
/// `format` is the bare file extension (e.g. `png`). Used by the frontend to
/// render the image on the canvas at the cell's position.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_image_info.ts", rename_all = "camelCase")]
pub struct CellImageInfo {
    pub row: usize,
    pub col: usize,
    pub id: String,
    pub format: String,
    pub data: String,
}

/// A person referenced by a comment (author or mention). Enterprise builds
/// populate `user_id` + `provider_id` from their directory; the `src` app
/// leaves them `None` and only sets `display_name`.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_person.ts", rename_all = "camelCase")]
pub struct CommentPerson {
    pub display_name: String,
    pub user_id: Option<String>,
    pub provider_id: Option<String>,
}

/// A resolved `@mention` span within a note's content.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_mention_info.ts", rename_all = "camelCase")]
pub struct CommentMentionInfo {
    pub start: usize,
    pub len: usize,
    pub person: CommentPerson,
}

/// A single note in a comment thread (root or reply).
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_note.ts", rename_all = "camelCase")]
pub struct CommentNote {
    pub id: String,
    pub author: CommentPerson,
    pub dt: String,
    pub content: String,
    pub parent_id: Option<String>,
    pub mentions: Vec<CommentMentionInfo>,
    pub resolved: bool,
}

/// A comment thread anchored at a cell. `notes` is ordered (root first, then
/// replies).
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment.ts", rename_all = "camelCase")]
pub struct Comment {
    pub row: usize,
    pub col: usize,
    pub notes: Vec<CommentNote>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_row_info.ts", rename_all = "camelCase")]
pub struct SheetRowInfo {
    pub sheet_idx: usize,
    pub info: Vec<RowInfo>,
    pub default_height: f64,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "row_info.ts", rename_all = "camelCase")]
pub struct RowInfo {
    pub idx: usize,
    pub height: f64,
    pub hidden: bool,
}

impl RowInfo {
    pub fn default(idx: usize) -> RowInfo {
        Self {
            idx,
            height: get_default_row_height(),
            hidden: false,
        }
    }
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_col_info.ts", rename_all = "camelCase")]
pub struct SheetColInfo {
    pub sheet_idx: usize,
    pub info: Vec<ColInfo>,
    pub default_width: f64,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "col_info.ts", rename_all = "camelCase")]
pub struct ColInfo {
    pub idx: usize,
    pub width: f64,
    pub hidden: bool,
}

impl ColInfo {
    pub fn default(idx: usize) -> Self {
        Self {
            idx,
            width: get_default_col_width(),
            hidden: false,
        }
    }
}

pub fn get_default_row_height() -> f64 {
    15.
}

pub fn get_default_col_width() -> f64 {
    8.43
}

#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "value.ts", tag = "type")]
pub enum Value {
    Str(String),
    Bool(bool),
    Number(f64),
    Error(String),
    #[default]
    Empty,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_formula_value.ts", rename_all = "camelCase")]
pub struct CellFormulaValue {
    pub row: usize,
    pub col: usize,
    pub formula: String,
    pub value: Value,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_values.ts", rename_all = "camelCase")]
pub struct SheetValues {
    pub sheet_idx: usize,
    pub values: Vec<CellFormulaValue>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_style.ts", rename_all = "camelCase")]
pub struct CellStyle {
    pub row: usize,
    pub col: usize,
    pub style: Style,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_styles.ts", rename_all = "camelCase")]
pub struct SheetStyles {
    pub sheet_idx: usize,
    pub styles: Vec<CellStyle>,
}

/// One cell that changed inside the active temp branch. `old_value` is
/// what's in the committed branch (the `fork_status` snapshot taken when
/// temp mode began); `new_value` is what the cell holds right now in the
/// live temp branch. Position is the *current* (post-temp) sheet row/col
/// — block inserts may shift earlier rows downward, so even cells that
/// didn't have a direct write may surface here with shifted positions.
#[derive(Debug, Clone, TS)]
#[ts(file_name = "temp_cell_change.ts", rename_all = "camelCase")]
pub struct TempCellChange {
    pub sheet_idx: usize,
    pub row: usize,
    pub col: usize,
    pub old_value: Value,
    pub new_value: Value,
}

/// Diff between the active temp branch and the committed branch.
/// Returned by `Workbook::get_temp_status_changes`; empty when no temp
/// branch is currently active.
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "temp_status_diff.ts", rename_all = "camelCase")]
pub struct TempStatusDiff {
    pub cells: Vec<TempCellChange>,
}

#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_field.ts", rename_all = "camelCase")]
pub struct BlockField {
    pub sheet_id: SheetId,
    pub block_id: BlockId,
    pub field_id: String,
}