@trebco/treb 23.6.5 → 25.0.0-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/.eslintignore +8 -0
  2. package/.eslintrc.js +164 -0
  3. package/README-shadow-DOM.md +88 -0
  4. package/README.md +37 -130
  5. package/api-config.json +29 -0
  6. package/api-generator/api-generator-types.ts +82 -0
  7. package/api-generator/api-generator.ts +1172 -0
  8. package/api-generator/package.json +3 -0
  9. package/build/treb-spreadsheet.mjs +14 -0
  10. package/{treb.d.ts → build/treb.d.ts} +323 -271
  11. package/esbuild-custom-element.mjs +336 -0
  12. package/esbuild.js +305 -0
  13. package/package.json +49 -14
  14. package/treb-base-types/package.json +5 -0
  15. package/treb-base-types/src/api_types.ts +36 -0
  16. package/treb-base-types/src/area.ts +583 -0
  17. package/treb-base-types/src/basic_types.ts +45 -0
  18. package/treb-base-types/src/cell.ts +612 -0
  19. package/treb-base-types/src/cells.ts +1066 -0
  20. package/treb-base-types/src/color.ts +124 -0
  21. package/treb-base-types/src/import.ts +71 -0
  22. package/treb-base-types/src/index-standalone.ts +29 -0
  23. package/treb-base-types/src/index.ts +42 -0
  24. package/treb-base-types/src/layout.ts +47 -0
  25. package/treb-base-types/src/localization.ts +187 -0
  26. package/treb-base-types/src/rectangle.ts +145 -0
  27. package/treb-base-types/src/render_text.ts +72 -0
  28. package/treb-base-types/src/style.ts +545 -0
  29. package/treb-base-types/src/table.ts +109 -0
  30. package/treb-base-types/src/text_part.ts +54 -0
  31. package/treb-base-types/src/theme.ts +608 -0
  32. package/treb-base-types/src/union.ts +152 -0
  33. package/treb-base-types/src/value-type.ts +164 -0
  34. package/treb-base-types/style/resizable.css +59 -0
  35. package/treb-calculator/modern.tsconfig.json +11 -0
  36. package/treb-calculator/package.json +5 -0
  37. package/treb-calculator/src/calculator.ts +2546 -0
  38. package/treb-calculator/src/complex-math.ts +558 -0
  39. package/treb-calculator/src/dag/array-vertex.ts +198 -0
  40. package/treb-calculator/src/dag/graph.ts +951 -0
  41. package/treb-calculator/src/dag/leaf_vertex.ts +118 -0
  42. package/treb-calculator/src/dag/spreadsheet_vertex.ts +327 -0
  43. package/treb-calculator/src/dag/spreadsheet_vertex_base.ts +44 -0
  44. package/treb-calculator/src/dag/vertex.ts +352 -0
  45. package/treb-calculator/src/descriptors.ts +162 -0
  46. package/treb-calculator/src/expression-calculator.ts +1069 -0
  47. package/treb-calculator/src/function-error.ts +103 -0
  48. package/treb-calculator/src/function-library.ts +103 -0
  49. package/treb-calculator/src/functions/base-functions.ts +1214 -0
  50. package/treb-calculator/src/functions/checkbox.ts +164 -0
  51. package/treb-calculator/src/functions/complex-functions.ts +253 -0
  52. package/treb-calculator/src/functions/finance-functions.ts +399 -0
  53. package/treb-calculator/src/functions/information-functions.ts +102 -0
  54. package/treb-calculator/src/functions/matrix-functions.ts +182 -0
  55. package/treb-calculator/src/functions/sparkline.ts +335 -0
  56. package/treb-calculator/src/functions/statistics-functions.ts +350 -0
  57. package/treb-calculator/src/functions/text-functions.ts +298 -0
  58. package/treb-calculator/src/index.ts +27 -0
  59. package/treb-calculator/src/notifier-types.ts +59 -0
  60. package/treb-calculator/src/primitives.ts +428 -0
  61. package/treb-calculator/src/utilities.ts +305 -0
  62. package/treb-charts/package.json +5 -0
  63. package/treb-charts/src/chart-functions.ts +156 -0
  64. package/treb-charts/src/chart-types.ts +230 -0
  65. package/treb-charts/src/chart.ts +1288 -0
  66. package/treb-charts/src/index.ts +24 -0
  67. package/treb-charts/src/main.ts +37 -0
  68. package/treb-charts/src/rectangle.ts +52 -0
  69. package/treb-charts/src/renderer.ts +1841 -0
  70. package/treb-charts/src/util.ts +122 -0
  71. package/treb-charts/style/charts.scss +221 -0
  72. package/treb-charts/style/old-charts.scss +250 -0
  73. package/treb-embed/markup/layout.html +137 -0
  74. package/treb-embed/markup/toolbar.html +175 -0
  75. package/treb-embed/modern.tsconfig.json +25 -0
  76. package/treb-embed/src/custom-element/content-types.d.ts +18 -0
  77. package/treb-embed/src/custom-element/global.d.ts +11 -0
  78. package/treb-embed/src/custom-element/spreadsheet-constructor.ts +1228 -0
  79. package/treb-embed/src/custom-element/treb-global.ts +44 -0
  80. package/treb-embed/src/custom-element/treb-spreadsheet-element.ts +52 -0
  81. package/treb-embed/src/embedded-spreadsheet.ts +5358 -0
  82. package/treb-embed/src/index.ts +16 -0
  83. package/treb-embed/src/language-model.ts +41 -0
  84. package/treb-embed/src/options.ts +298 -0
  85. package/treb-embed/src/progress-dialog.ts +228 -0
  86. package/treb-embed/src/selection-state.ts +16 -0
  87. package/treb-embed/src/spinner.ts +42 -0
  88. package/treb-embed/src/toolbar-message.ts +96 -0
  89. package/treb-embed/src/types.ts +167 -0
  90. package/treb-embed/style/autocomplete.scss +103 -0
  91. package/treb-embed/style/dark-theme.scss +114 -0
  92. package/treb-embed/style/defaults.scss +36 -0
  93. package/treb-embed/style/dialog.scss +181 -0
  94. package/treb-embed/style/dropdown-select.scss +101 -0
  95. package/treb-embed/style/formula-bar.scss +193 -0
  96. package/treb-embed/style/grid.scss +374 -0
  97. package/treb-embed/style/layout.scss +424 -0
  98. package/treb-embed/style/mouse-mask.scss +67 -0
  99. package/treb-embed/style/note.scss +92 -0
  100. package/treb-embed/style/overlay-editor.scss +102 -0
  101. package/treb-embed/style/spinner.scss +92 -0
  102. package/treb-embed/style/tab-bar.scss +228 -0
  103. package/treb-embed/style/table.scss +80 -0
  104. package/treb-embed/style/theme-defaults.scss +444 -0
  105. package/treb-embed/style/toolbar.scss +416 -0
  106. package/treb-embed/style/tooltip.scss +68 -0
  107. package/treb-embed/style/treb-icons.scss +130 -0
  108. package/treb-embed/style/treb-spreadsheet-element.scss +20 -0
  109. package/treb-embed/style/z-index.scss +43 -0
  110. package/treb-export/docs/charts.md +68 -0
  111. package/treb-export/modern.tsconfig.json +19 -0
  112. package/treb-export/package.json +4 -0
  113. package/treb-export/src/address-type.ts +77 -0
  114. package/treb-export/src/base-template.ts +22 -0
  115. package/treb-export/src/column-width.ts +85 -0
  116. package/treb-export/src/drawing2/chart-template-components2.ts +389 -0
  117. package/treb-export/src/drawing2/chart2.ts +282 -0
  118. package/treb-export/src/drawing2/column-chart-template2.ts +521 -0
  119. package/treb-export/src/drawing2/donut-chart-template2.ts +296 -0
  120. package/treb-export/src/drawing2/drawing2.ts +355 -0
  121. package/treb-export/src/drawing2/embedded-image.ts +71 -0
  122. package/treb-export/src/drawing2/scatter-chart-template2.ts +555 -0
  123. package/treb-export/src/export-worker/export-worker.ts +99 -0
  124. package/treb-export/src/export-worker/index-modern.ts +22 -0
  125. package/treb-export/src/export2.ts +2204 -0
  126. package/treb-export/src/import2.ts +882 -0
  127. package/treb-export/src/relationship.ts +36 -0
  128. package/treb-export/src/shared-strings2.ts +128 -0
  129. package/treb-export/src/template-2.ts +22 -0
  130. package/treb-export/src/unescape_xml.ts +47 -0
  131. package/treb-export/src/workbook-sheet2.ts +182 -0
  132. package/treb-export/src/workbook-style2.ts +1285 -0
  133. package/treb-export/src/workbook-theme2.ts +88 -0
  134. package/treb-export/src/workbook2.ts +491 -0
  135. package/treb-export/src/xml-utils.ts +201 -0
  136. package/treb-export/template/base/[Content_Types].xml +2 -0
  137. package/treb-export/template/base/_rels/.rels +2 -0
  138. package/treb-export/template/base/docProps/app.xml +2 -0
  139. package/treb-export/template/base/docProps/core.xml +12 -0
  140. package/treb-export/template/base/xl/_rels/workbook.xml.rels +2 -0
  141. package/treb-export/template/base/xl/sharedStrings.xml +2 -0
  142. package/treb-export/template/base/xl/styles.xml +2 -0
  143. package/treb-export/template/base/xl/theme/theme1.xml +2 -0
  144. package/treb-export/template/base/xl/workbook.xml +2 -0
  145. package/treb-export/template/base/xl/worksheets/sheet1.xml +2 -0
  146. package/treb-export/template/base.xlsx +0 -0
  147. package/treb-format/package.json +8 -0
  148. package/treb-format/src/format.test.ts +213 -0
  149. package/treb-format/src/format.ts +942 -0
  150. package/treb-format/src/format_cache.ts +199 -0
  151. package/treb-format/src/format_parser.ts +723 -0
  152. package/treb-format/src/index.ts +25 -0
  153. package/treb-format/src/number_format_section.ts +100 -0
  154. package/treb-format/src/value_parser.ts +337 -0
  155. package/treb-grid/package.json +5 -0
  156. package/treb-grid/src/editors/autocomplete.ts +394 -0
  157. package/treb-grid/src/editors/autocomplete_matcher.ts +260 -0
  158. package/treb-grid/src/editors/formula_bar.ts +473 -0
  159. package/treb-grid/src/editors/formula_editor_base.ts +910 -0
  160. package/treb-grid/src/editors/overlay_editor.ts +511 -0
  161. package/treb-grid/src/index.ts +37 -0
  162. package/treb-grid/src/layout/base_layout.ts +2618 -0
  163. package/treb-grid/src/layout/grid_layout.ts +299 -0
  164. package/treb-grid/src/layout/rectangle_cache.ts +86 -0
  165. package/treb-grid/src/render/selection-renderer.ts +414 -0
  166. package/treb-grid/src/render/svg_header_overlay.ts +93 -0
  167. package/treb-grid/src/render/svg_selection_block.ts +187 -0
  168. package/treb-grid/src/render/tile_renderer.ts +2122 -0
  169. package/treb-grid/src/types/annotation.ts +216 -0
  170. package/treb-grid/src/types/border_constants.ts +34 -0
  171. package/treb-grid/src/types/clipboard_data.ts +31 -0
  172. package/treb-grid/src/types/data_model.ts +334 -0
  173. package/treb-grid/src/types/drag_mask.ts +81 -0
  174. package/treb-grid/src/types/grid.ts +7743 -0
  175. package/treb-grid/src/types/grid_base.ts +3644 -0
  176. package/treb-grid/src/types/grid_command.ts +470 -0
  177. package/treb-grid/src/types/grid_events.ts +124 -0
  178. package/treb-grid/src/types/grid_options.ts +97 -0
  179. package/treb-grid/src/types/grid_selection.ts +60 -0
  180. package/treb-grid/src/types/named_range.ts +369 -0
  181. package/treb-grid/src/types/scale-control.ts +202 -0
  182. package/treb-grid/src/types/serialize_options.ts +72 -0
  183. package/treb-grid/src/types/set_range_options.ts +52 -0
  184. package/treb-grid/src/types/sheet.ts +3099 -0
  185. package/treb-grid/src/types/sheet_types.ts +95 -0
  186. package/treb-grid/src/types/tab_bar.ts +464 -0
  187. package/treb-grid/src/types/tile.ts +59 -0
  188. package/treb-grid/src/types/update_flags.ts +75 -0
  189. package/treb-grid/src/util/dom_utilities.ts +44 -0
  190. package/treb-grid/src/util/fontmetrics2.ts +179 -0
  191. package/treb-grid/src/util/ua.ts +104 -0
  192. package/treb-logo.svg +18 -0
  193. package/treb-parser/package.json +5 -0
  194. package/treb-parser/src/csv-parser.ts +122 -0
  195. package/treb-parser/src/index.ts +25 -0
  196. package/treb-parser/src/md-parser.ts +526 -0
  197. package/treb-parser/src/parser-types.ts +397 -0
  198. package/treb-parser/src/parser.test.ts +298 -0
  199. package/treb-parser/src/parser.ts +2673 -0
  200. package/treb-utils/package.json +5 -0
  201. package/treb-utils/src/dispatch.ts +57 -0
  202. package/treb-utils/src/event_source.ts +147 -0
  203. package/treb-utils/src/ievent_source.ts +33 -0
  204. package/treb-utils/src/index.ts +31 -0
  205. package/treb-utils/src/measurement.ts +174 -0
  206. package/treb-utils/src/resizable.ts +160 -0
  207. package/treb-utils/src/scale.ts +137 -0
  208. package/treb-utils/src/serialize_html.ts +124 -0
  209. package/treb-utils/src/template.ts +70 -0
  210. package/treb-utils/src/validate_uri.ts +61 -0
  211. package/tsconfig.json +10 -0
  212. package/tsproject.json +30 -0
  213. package/util/license-plugin-esbuild.js +86 -0
  214. package/util/list-css-vars.sh +46 -0
  215. package/README-esm.md +0 -37
  216. package/treb-bundle.css +0 -2
  217. package/treb-bundle.mjs +0 -15
@@ -0,0 +1,470 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
+ import type { ICellAddress, IArea, Style, CellValue, Table, TableSortType, TableTheme } from 'treb-base-types';
23
+ import type { ExpressionUnit } from 'treb-parser';
24
+ import type { BorderConstants } from './border_constants';
25
+
26
+ /**
27
+ * switching to an exec-command based model, so we can serialize
28
+ * data, layout and style changes; the intent is to support recording,
29
+ * replaying, and transmitting modifications.
30
+ *
31
+ * NOTE regarding commands: let's make them as explicit as possible
32
+ * (meaning fewer optional parameters). force callers to populate fields.
33
+ *
34
+ */
35
+
36
+ /**
37
+ * commands are symbolic for (hopefully) faster switching. we use a
38
+ * discriminated union for build-time parameter checks. see individual
39
+ * command interfaces for comments.
40
+ */
41
+ export enum CommandKey {
42
+
43
+ /** use an empty value so all commands are non-zero */
44
+ Null = 0,
45
+
46
+ InsertRows,
47
+ InsertColumns,
48
+ ResizeRows,
49
+ ResizeColumns,
50
+ Select,
51
+ SetRange,
52
+ UpdateStyle,
53
+ UpdateBorders,
54
+ MergeCells,
55
+ UnmergeCells,
56
+ Clear,
57
+ UpdateTheme,
58
+ SetNote,
59
+ SetLink,
60
+ Freeze,
61
+ SetName,
62
+ ShowHeaders,
63
+ AddSheet,
64
+ DuplicateSheet,
65
+ DeleteSheet,
66
+ ActivateSheet,
67
+ RenameSheet,
68
+ ReorderSheet,
69
+ ShowSheet,
70
+ DataValidation,
71
+ Reset,
72
+ SortTable,
73
+ InsertTable,
74
+ RemoveTable,
75
+
76
+ }
77
+
78
+ /** base type for sheet commands -- can select sheet by name, id or index */
79
+ export interface SheetSelection {
80
+ index?: number;
81
+ name?: string;
82
+ id?: number;
83
+ }
84
+
85
+ /**
86
+ * show or hide sheet.
87
+ */
88
+ export interface ShowSheetCommand extends SheetSelection {
89
+ key: CommandKey.ShowSheet;
90
+ show: boolean;
91
+ }
92
+
93
+ /*
94
+ export interface CommandBase {
95
+
96
+ / **
97
+ * support commands that are not added to any recording or log.
98
+ * this is for things like resizing rows/columns -- we don't necessarily
99
+ * want to transmit every event, and if we don't support ephemeral commands
100
+ * we will wind up working around the exec-command system, which I would
101
+ * like to avoid.
102
+ * /
103
+ ephemeral?: boolean;
104
+
105
+ }
106
+ */
107
+
108
+ /**
109
+ * insert a table at the given location
110
+ */
111
+ export interface InsertTableCommand {
112
+ key: CommandKey.InsertTable,
113
+ area: IArea,
114
+
115
+ /** optionally include a totals row */
116
+ totals?: boolean,
117
+
118
+ /**
119
+ * sortable. defaults to true. you can optionally
120
+ * disable sorting, if you want.
121
+ */
122
+ sortable?: boolean,
123
+
124
+ /**
125
+ * optional theme
126
+ */
127
+ theme?: TableTheme,
128
+
129
+ }
130
+
131
+ /**
132
+ * remove the table
133
+ */
134
+ export interface RemoveTableCommand {
135
+ key: CommandKey.RemoveTable,
136
+ table: Table,
137
+ }
138
+
139
+ /**
140
+ * sort a table. sorts are hard, meaning we actually move data around.
141
+ * use copy/paste semantics for handling relative references (seems strange
142
+ * to me, but hey).
143
+ */
144
+ export interface SortTableCommand {
145
+ key: CommandKey.SortTable,
146
+ table: Table,
147
+ column: number,
148
+ asc: boolean;
149
+ type: TableSortType,
150
+ }
151
+
152
+ /**
153
+ * resize row(s). undefined means "all rows". undefined height
154
+ * means "auto size".
155
+ *
156
+ * UPDATE: shrink is a flag you can set to prevent shrinking rows
157
+ * when (and only when) auto-sizing, i.e. height is undefined
158
+ */
159
+ export interface ResizeRowsCommand {
160
+ key: CommandKey.ResizeRows;
161
+ row?: number|number[];
162
+ height?: number;
163
+ shrink?: boolean;
164
+ sheet_id?: number;
165
+ }
166
+
167
+ /**
168
+ * resize columns(s). undefined means "all columns". undefined
169
+ * width means "auto size".
170
+ */
171
+ export interface ResizeColumnsCommand {
172
+ key: CommandKey.ResizeColumns;
173
+ column?: number|number[];
174
+ width?: number;
175
+ sheet_id?: number;
176
+ }
177
+
178
+ /** insert one or more rows at the given insert point */
179
+ export interface InsertRowsCommand {
180
+ key: CommandKey.InsertRows;
181
+ before_row: number;
182
+ count: number;
183
+ sheet_id?: number;
184
+ }
185
+
186
+ /** insert one or more columns at the given insert point */
187
+ export interface InsertColumnsCommand {
188
+ key: CommandKey.InsertColumns;
189
+ before_column: number;
190
+ count: number;
191
+ sheet_id?: number;
192
+ }
193
+
194
+ /** show or hide headers */
195
+ export interface ShowHeadersCommand {
196
+ key: CommandKey.ShowHeaders;
197
+ show: boolean;
198
+ }
199
+
200
+ /**
201
+ * set or clear name (omit range to clear)
202
+ *
203
+ * adding support for named expressions. you can pass either a range or
204
+ * an expression.
205
+ *
206
+ * if you use the same name more than once, it will overwrite the old name,
207
+ * even if you change types range/expression.
208
+ *
209
+ * passing neither will cause it to erase any existing named range OR named
210
+ * expression.
211
+ *
212
+ */
213
+ export interface SetNameCommand {
214
+ key: CommandKey.SetName;
215
+ name: string;
216
+ area?: IArea;
217
+ expression?: ExpressionUnit;
218
+ }
219
+
220
+ export interface DataValidationCommand {
221
+ key: CommandKey.DataValidation;
222
+ area: ICellAddress;
223
+ range?: IArea;
224
+ list?: CellValue[];
225
+ error?: boolean;
226
+ }
227
+
228
+ /**
229
+ * not sure if we should be serializing selections...
230
+ * we need some indication of primary/alternative
231
+ */
232
+ export interface SelectCommand {
233
+ key: CommandKey.Select;
234
+
235
+ /** missing area implies clear selection (-> no selection) */
236
+ area?: IArea;
237
+
238
+ /** missing target will set target as first cell of area */
239
+ target?: ICellAddress;
240
+ }
241
+
242
+ /** set data in cell or area */
243
+ export interface SetRangeCommand {
244
+ key: CommandKey.SetRange;
245
+ area: IArea|ICellAddress;
246
+
247
+ /** set as array (usually control-enter) */
248
+ array?: boolean;
249
+
250
+ /**
251
+ * support R1C1 notation, which can come from API only (atm). this
252
+ * flag does not mean the notation _is_ R1C1, just that we need to
253
+ * check for it and handle it if found.
254
+ */
255
+ r1c1?: boolean;
256
+
257
+ /** missing data implies clear cell(s) */
258
+ value?: CellValue|CellValue[][];
259
+ }
260
+
261
+ /** update borders for the given area. this is different than updating
262
+ * style, because borders have slightly different semantics -- when applied
263
+ * to an area, for example, "outside border" means the outside of the total
264
+ * area, not the outside of each cell.
265
+ */
266
+ export interface UpdateBordersCommand {
267
+ key: CommandKey.UpdateBorders;
268
+ area: IArea;
269
+ borders: BorderConstants;
270
+ // color?: string; // pending
271
+ color?: Style.Color;
272
+
273
+ /** defaults to one. optional for the case of "none" (remove borders) */
274
+ width?: number;
275
+ }
276
+
277
+ /** update style in area. area can be cell(s), sheet, row(s), column(s) */
278
+ export interface UpdateStyleCommand {
279
+ key: CommandKey.UpdateStyle;
280
+ area: IArea|ICellAddress;
281
+ style: Style.Properties;
282
+ delta?: boolean;
283
+ }
284
+
285
+ /** merge the given cells */
286
+ export interface MergeCellsCommand {
287
+ key: CommandKey.MergeCells;
288
+ area: IArea;
289
+ }
290
+
291
+ /**
292
+ * unmerge the given cells. if the passed area doesn't exactly match a
293
+ * merge area, we will look for merge areas inside the larger area and
294
+ * unmerge those (generally useful when working with selections).
295
+ */
296
+ export interface UnmergeCellsCommand {
297
+ key: CommandKey.UnmergeCells;
298
+ area: IArea;
299
+ }
300
+
301
+ /** set or clear note at given address. */
302
+ export interface SetNoteCommand {
303
+ key: CommandKey.SetNote;
304
+ area: ICellAddress;
305
+ note?: string;
306
+ }
307
+
308
+ export interface SetLinkCommand {
309
+ key: CommandKey.SetLink;
310
+ area: ICellAddress;
311
+ reference?: string;
312
+ }
313
+
314
+ /**
315
+ * clear an area, or the entire sheet.
316
+ *
317
+ * because this command can omit area (meaning entire sheet), to
318
+ * support remotes we need to add a separate parameter for sheet id.
319
+ *
320
+ * we could use infinite area as an indication it's a reset, but that's
321
+ * not really the same thing -- that would be more like select all / clear.
322
+ *
323
+ * not sure why clear doubled as reset, except that it probably dated
324
+ * from before we had multiple sheets. we're now splitting so there's an
325
+ * explicit reset event.
326
+ *
327
+ * now that we have a separate reset, clear requires an area.
328
+ *
329
+ */
330
+ export interface ClearCommand {
331
+ key: CommandKey.Clear;
332
+ area: IArea;
333
+ // sheet_id?: number;
334
+ }
335
+
336
+ /**
337
+ * reset everything.
338
+ */
339
+ export interface ResetCommand {
340
+ key: CommandKey.Reset;
341
+ }
342
+
343
+ /**
344
+ * set freeze area. set rows and columns to 0 to unfreeze.
345
+ * highlight defaults to TRUE.
346
+ */
347
+ export interface FreezeCommand {
348
+ key: CommandKey.Freeze;
349
+ rows: number;
350
+ columns: number;
351
+ highlight_transition?: boolean;
352
+ sheet_id?: number;
353
+ }
354
+
355
+ /**
356
+ * FIXME: should this command include theme properties, or can we
357
+ * base it on the local theme? (...) probably the former, otherwise
358
+ * you lose synchronization
359
+ * /
360
+ export interface UpdateThemeCommand {
361
+ key: CommandKey.UpdateTheme;
362
+ }
363
+ */
364
+
365
+ export interface NullCommand {
366
+ key: CommandKey.Null;
367
+ }
368
+
369
+ export interface AddSheetCommand {
370
+ key: CommandKey.AddSheet;
371
+ insert_index?: number;
372
+ name?: string;
373
+
374
+ /** switch to the sheet immediately */
375
+ show?: boolean;
376
+ }
377
+
378
+ export interface DuplicateSheetCommand extends SheetSelection {
379
+ key: CommandKey.DuplicateSheet;
380
+ new_name?: string;
381
+ insert_before?: string|number;
382
+ }
383
+
384
+ export interface DeleteSheetCommand extends SheetSelection {
385
+ key: CommandKey.DeleteSheet;
386
+ }
387
+
388
+ /**
389
+ * activate a sheet. there are a couple of options for selecting
390
+ * the sheet, defaulting to index (which defaults to 0) so if you
391
+ * pass no selector it will select index 0.
392
+ */
393
+ export interface ActivateSheetCommand extends SheetSelection {
394
+ key: CommandKey.ActivateSheet;
395
+
396
+ /** ... */
397
+ tab_bar_event?: boolean;
398
+
399
+ force?: boolean;
400
+ }
401
+
402
+ /**
403
+ * rename a sheet. options are like ActivateSheetCommand, except we
404
+ * have to be a little careful about name old/new
405
+ */
406
+ export interface RenameSheetCommand extends SheetSelection {
407
+ key: CommandKey.RenameSheet;
408
+ new_name: string; // required
409
+ }
410
+
411
+ /**
412
+ * reorder sheet; move sheet (X) before (Y). if (Y) is larger than the
413
+ * list length, moves to end.
414
+ */
415
+ export interface ReorderSheetCommand {
416
+ key: CommandKey.ReorderSheet;
417
+ index: number;
418
+ move_before: number;
419
+ }
420
+
421
+ /**
422
+ * ephemeral flag added to commands.
423
+ * /
424
+ export interface Ephemeral {
425
+ ephemeral?: boolean;
426
+ }
427
+ */
428
+
429
+ /**
430
+ * composite command type and ephemeral flag
431
+ */
432
+ export type Command =
433
+ ( NullCommand
434
+ | ClearCommand
435
+ | ResetCommand
436
+ | SelectCommand
437
+ | FreezeCommand
438
+ | SetNoteCommand
439
+ | SetLinkCommand
440
+ | SetNameCommand
441
+ | AddSheetCommand
442
+ | SetRangeCommand
443
+ | SortTableCommand
444
+ | ShowSheetCommand
445
+ | MergeCellsCommand
446
+ | ResizeRowsCommand
447
+ | InsertRowsCommand
448
+ | ShowHeadersCommand
449
+ | DeleteSheetCommand
450
+ | UpdateStyleCommand
451
+ | InsertTableCommand
452
+ | RemoveTableCommand
453
+ | RenameSheetCommand
454
+ | ReorderSheetCommand
455
+ | UnmergeCellsCommand
456
+ | ResizeColumnsCommand
457
+ | InsertColumnsCommand
458
+ | UpdateBordersCommand
459
+ | ActivateSheetCommand
460
+ | DataValidationCommand
461
+ | DuplicateSheetCommand
462
+ ) ; // & Ephemeral;
463
+
464
+ /**
465
+ * record type for recording/logging commands
466
+ */
467
+ export interface CommandRecord {
468
+ command: Command[];
469
+ timestamp: number;
470
+ }
@@ -0,0 +1,124 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
+ import type { GridSelection } from './grid_selection';
23
+ import type { Annotation } from './annotation';
24
+ import type { Sheet } from './sheet';
25
+ import type { Area } from 'treb-base-types';
26
+
27
+ export enum ErrorCode {
28
+
29
+ /** no error: zero so it's falsy */
30
+ none = 0,
31
+
32
+ /** placeholder for new errors */
33
+ unknown,
34
+
35
+ /** you can't change part of an array */
36
+ array,
37
+
38
+ /** invalid value (data validation) */
39
+ data_validation,
40
+
41
+ /** invalid area for insert table: there's a merge, array or existing table within the range */
42
+ invalid_area_for_table,
43
+
44
+ }
45
+
46
+ export interface SheetChangeEvent {
47
+ type: 'sheet-change';
48
+ activate: Sheet;
49
+ deactivate: Sheet;
50
+ }
51
+
52
+ export interface GridSelectionEvent {
53
+ type: 'selection';
54
+ selection: GridSelection;
55
+ }
56
+
57
+ export interface GridAlternateSelectionEvent {
58
+ type: 'alternate-selection';
59
+ selection: GridSelection;
60
+ }
61
+
62
+ /**
63
+ * we used to return strings here, changed to error codes for l10n
64
+ */
65
+ export interface GridErrorEvent {
66
+ type: 'error';
67
+ code: ErrorCode;
68
+ }
69
+
70
+ export interface StructureEvent {
71
+ type: 'structure';
72
+
73
+ /**
74
+ * this flag should be set if the structure change changes references,
75
+ * insert or delete events. resize events don't need to set it.
76
+ *
77
+ * FIXME: merge/unmerge? (...) I think yes
78
+ */
79
+ rebuild_required?: boolean;
80
+ }
81
+
82
+ export interface AnnotationEvent {
83
+ type: 'annotation';
84
+ annotation?: Annotation;
85
+ event?: 'move'|'resize'|'create'|'delete'|'update';
86
+ }
87
+
88
+ export interface CellEvent {
89
+ type: 'cell-event',
90
+ data?: any,
91
+ }
92
+
93
+ export interface DataEvent {
94
+ type: 'data';
95
+ area?: Area;
96
+ }
97
+
98
+ export interface FlushEvent {
99
+ type: 'flush';
100
+ }
101
+
102
+ export interface StyleEvent {
103
+ type: 'style';
104
+ area?: Area;
105
+ }
106
+
107
+ export interface ScaleEvent {
108
+ type: 'scale';
109
+ scale: number;
110
+ }
111
+
112
+ export type GridEvent
113
+ = DataEvent
114
+ | CellEvent
115
+ | StyleEvent
116
+ | FlushEvent
117
+ | ScaleEvent
118
+ | GridErrorEvent
119
+ | StructureEvent
120
+ | AnnotationEvent
121
+ | SheetChangeEvent
122
+ | GridSelectionEvent
123
+ | GridAlternateSelectionEvent
124
+ ;
@@ -0,0 +1,97 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
+ import type { CellValue } from 'treb-base-types';
23
+ import type { StatsEntry } from './tab_bar';
24
+
25
+ export type StatsFunction = (data: CellValue|CellValue[][]|undefined) => StatsEntry[];
26
+
27
+ export interface GridOptions {
28
+
29
+ /** can expand rows/columns */
30
+ expand?: boolean;
31
+
32
+ /**
33
+ * if you are running a calculator, you might not want the grid
34
+ * to repaint any time there's a data change (which is the default
35
+ * behavior).
36
+ */
37
+ repaint_on_cell_change?: boolean;
38
+
39
+ /** support in-cell editing */
40
+ in_cell_editor?: boolean;
41
+
42
+ /** show the formula bar (and allow editing; TODO: read-only option) */
43
+ formula_bar?: boolean;
44
+
45
+ /** show the tab bar */
46
+ tab_bar?: boolean|'auto';
47
+
48
+ /** scale controls. implies tab bar */
49
+ scale_control?: boolean;
50
+
51
+ /** stats panel. implies tab bar */
52
+ stats?: boolean|StatsFunction;
53
+
54
+ /** save/load scale to storage, with the given key */
55
+ persist_scale_key?: string;
56
+
57
+ /** allow add tab */
58
+ add_tab?: boolean;
59
+
60
+ /** show delete tab in the tab bar */
61
+ delete_tab?: boolean;
62
+
63
+ /** show the "insert function" button. requires formula bar. */
64
+ insert_function_button?: boolean;
65
+
66
+ /** button to increase/reduce size of formula editor */
67
+ expand_formula_button?: boolean;
68
+
69
+ /** scale (wip) */
70
+ // scale?: number;
71
+
72
+ /** enable scrolling (default true) */
73
+ scrollbars?: boolean;
74
+
75
+ /** always show grid, even if there is background color */
76
+ grid_over_background?: boolean;
77
+
78
+ /** initial scale for layout */
79
+ initial_scale?: number;
80
+
81
+ /** support MD formatting in text */
82
+ markdown?: boolean;
83
+
84
+ }
85
+
86
+ export const DefaultGridOptions: GridOptions = {
87
+ scrollbars: true,
88
+ in_cell_editor: true,
89
+ formula_bar: true,
90
+ add_tab: false,
91
+ tab_bar: 'auto',
92
+ insert_function_button: false,
93
+ expand_formula_button: false,
94
+ expand: true,
95
+ repaint_on_cell_change: true,
96
+ grid_over_background: false, // true,
97
+ };