@dou-ui/sheet 0.0.0-stage → 0.1.0-alpha.1

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 (262) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/dist/cell-types.js +20 -0
  4. package/dist/cell-types.js.map +1 -0
  5. package/dist/code/code-formula-bar.js +6 -0
  6. package/dist/code/code-formula-bar.js.map +1 -0
  7. package/dist/code/code-formula-bar.vue_vue_type_script_setup_true_lang.js +192 -0
  8. package/dist/code/code-formula-bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
  9. package/dist/code/index.js +12 -0
  10. package/dist/code/index.js.map +1 -0
  11. package/dist/code/language.js +51 -0
  12. package/dist/code/language.js.map +1 -0
  13. package/dist/code/style.d.ts +1 -0
  14. package/dist/code/style.js +2 -0
  15. package/dist/collaboration/anchor.js +143 -0
  16. package/dist/collaboration/anchor.js.map +1 -0
  17. package/dist/collaboration/index.js +770 -0
  18. package/dist/collaboration/index.js.map +1 -0
  19. package/dist/collaboration/peers.js +87 -0
  20. package/dist/collaboration/peers.js.map +1 -0
  21. package/dist/collaboration/shared.js +450 -0
  22. package/dist/collaboration/shared.js.map +1 -0
  23. package/dist/components/cell-panel.js +6 -0
  24. package/dist/components/cell-panel.js.map +1 -0
  25. package/dist/components/cell-panel.vue_vue_type_script_setup_true_lang.js +70 -0
  26. package/dist/components/cell-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  27. package/dist/components/cell-renders.js +40 -0
  28. package/dist/components/cell-renders.js.map +1 -0
  29. package/dist/components/date-panel.js +6 -0
  30. package/dist/components/date-panel.js.map +1 -0
  31. package/dist/components/date-panel.vue_vue_type_script_setup_true_lang.js +48 -0
  32. package/dist/components/date-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  33. package/dist/components/filter-panel.js +6 -0
  34. package/dist/components/filter-panel.js.map +1 -0
  35. package/dist/components/filter-panel.vue_vue_type_script_setup_true_lang.js +259 -0
  36. package/dist/components/filter-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  37. package/dist/components/format-dialog.js +6 -0
  38. package/dist/components/format-dialog.js.map +1 -0
  39. package/dist/components/format-dialog.vue_vue_type_script_setup_true_lang.js +432 -0
  40. package/dist/components/format-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
  41. package/dist/components/format-list.js +6 -0
  42. package/dist/components/format-list.js.map +1 -0
  43. package/dist/components/format-list.vue_vue_type_script_setup_true_lang.js +187 -0
  44. package/dist/components/format-list.vue_vue_type_script_setup_true_lang.js.map +1 -0
  45. package/dist/components/format-presets.js +97 -0
  46. package/dist/components/format-presets.js.map +1 -0
  47. package/dist/components/option-panel.js +6 -0
  48. package/dist/components/option-panel.js.map +1 -0
  49. package/dist/components/option-panel.vue_vue_type_script_setup_true_lang.js +117 -0
  50. package/dist/components/option-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  51. package/dist/components/sheet-comment.js +6 -0
  52. package/dist/components/sheet-comment.js.map +1 -0
  53. package/dist/components/sheet-comment.vue_vue_type_script_setup_true_lang.js +104 -0
  54. package/dist/components/sheet-comment.vue_vue_type_script_setup_true_lang.js.map +1 -0
  55. package/dist/components/sheet-formula-bar.js +6 -0
  56. package/dist/components/sheet-formula-bar.js.map +1 -0
  57. package/dist/components/sheet-formula-bar.vue_vue_type_script_setup_true_lang.js +124 -0
  58. package/dist/components/sheet-formula-bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
  59. package/dist/components/sheet-link.js +6 -0
  60. package/dist/components/sheet-link.js.map +1 -0
  61. package/dist/components/sheet-link.vue_vue_type_script_setup_true_lang.js +249 -0
  62. package/dist/components/sheet-link.vue_vue_type_script_setup_true_lang.js.map +1 -0
  63. package/dist/components/sheet-menu.js +6 -0
  64. package/dist/components/sheet-menu.js.map +1 -0
  65. package/dist/components/sheet-menu.vue_vue_type_script_setup_true_lang.js +115 -0
  66. package/dist/components/sheet-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
  67. package/dist/components/sheet-name-box.js +6 -0
  68. package/dist/components/sheet-name-box.js.map +1 -0
  69. package/dist/components/sheet-name-box.vue_vue_type_script_setup_true_lang.js +91 -0
  70. package/dist/components/sheet-name-box.vue_vue_type_script_setup_true_lang.js.map +1 -0
  71. package/dist/components/sheet-note.js +6 -0
  72. package/dist/components/sheet-note.js.map +1 -0
  73. package/dist/components/sheet-note.vue_vue_type_script_setup_true_lang.js +146 -0
  74. package/dist/components/sheet-note.vue_vue_type_script_setup_true_lang.js.map +1 -0
  75. package/dist/components/sheet-outline.js +6 -0
  76. package/dist/components/sheet-outline.js.map +1 -0
  77. package/dist/components/sheet-outline.vue_vue_type_script_setup_true_lang.js +237 -0
  78. package/dist/components/sheet-outline.vue_vue_type_script_setup_true_lang.js.map +1 -0
  79. package/dist/components/sheet-tabs.js +6 -0
  80. package/dist/components/sheet-tabs.js.map +1 -0
  81. package/dist/components/sheet-tabs.vue_vue_type_script_setup_true_lang.js +487 -0
  82. package/dist/components/sheet-tabs.vue_vue_type_script_setup_true_lang.js.map +1 -0
  83. package/dist/components/sheet-toolbar.js +6 -0
  84. package/dist/components/sheet-toolbar.js.map +1 -0
  85. package/dist/components/sheet-toolbar.vue_vue_type_script_setup_true_lang.js +1562 -0
  86. package/dist/components/sheet-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -0
  87. package/dist/components/validation-dialog.js +6 -0
  88. package/dist/components/validation-dialog.js.map +1 -0
  89. package/dist/components/validation-dialog.vue_vue_type_script_setup_true_lang.js +370 -0
  90. package/dist/components/validation-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
  91. package/dist/context.js +12 -0
  92. package/dist/context.js.map +1 -0
  93. package/dist/core/address.js +256 -0
  94. package/dist/core/address.js.map +1 -0
  95. package/dist/core/axis.js +72 -0
  96. package/dist/core/axis.js.map +1 -0
  97. package/dist/core/cell-type.js +30 -0
  98. package/dist/core/cell-type.js.map +1 -0
  99. package/dist/core/clipboard.js +141 -0
  100. package/dist/core/clipboard.js.map +1 -0
  101. package/dist/core/commands.js +63 -0
  102. package/dist/core/commands.js.map +1 -0
  103. package/dist/core/comments.js +74 -0
  104. package/dist/core/comments.js.map +1 -0
  105. package/dist/core/conditional.js +362 -0
  106. package/dist/core/conditional.js.map +1 -0
  107. package/dist/core/csv.js +191 -0
  108. package/dist/core/csv.js.map +1 -0
  109. package/dist/core/data.js +118 -0
  110. package/dist/core/data.js.map +1 -0
  111. package/dist/core/document.js +187 -0
  112. package/dist/core/document.js.map +1 -0
  113. package/dist/core/extension.js +60 -0
  114. package/dist/core/extension.js.map +1 -0
  115. package/dist/core/file.js +336 -0
  116. package/dist/core/file.js.map +1 -0
  117. package/dist/core/fill.js +153 -0
  118. package/dist/core/fill.js.map +1 -0
  119. package/dist/core/find.js +42 -0
  120. package/dist/core/find.js.map +1 -0
  121. package/dist/core/format.js +404 -0
  122. package/dist/core/format.js.map +1 -0
  123. package/dist/core/group.js +134 -0
  124. package/dist/core/group.js.map +1 -0
  125. package/dist/core/history.js +68 -0
  126. package/dist/core/history.js.map +1 -0
  127. package/dist/core/index.js +17 -0
  128. package/dist/core/link.js +34 -0
  129. package/dist/core/link.js.map +1 -0
  130. package/dist/core/merge.js +105 -0
  131. package/dist/core/merge.js.map +1 -0
  132. package/dist/core/model.js +48 -0
  133. package/dist/core/model.js.map +1 -0
  134. package/dist/core/nav.js +44 -0
  135. package/dist/core/nav.js.map +1 -0
  136. package/dist/core/paint.js +106 -0
  137. package/dist/core/paint.js.map +1 -0
  138. package/dist/core/plain-cell-types.js +54 -0
  139. package/dist/core/plain-cell-types.js.map +1 -0
  140. package/dist/core/protect.js +246 -0
  141. package/dist/core/protect.js.map +1 -0
  142. package/dist/core/selection.js +37 -0
  143. package/dist/core/selection.js.map +1 -0
  144. package/dist/core/transaction.js +1582 -0
  145. package/dist/core/transaction.js.map +1 -0
  146. package/dist/core/validation.js +135 -0
  147. package/dist/core/validation.js.map +1 -0
  148. package/dist/core/versions.js +161 -0
  149. package/dist/core/versions.js.map +1 -0
  150. package/dist/export/color.js +36 -0
  151. package/dist/export/color.js.map +1 -0
  152. package/dist/export/draw.js +316 -0
  153. package/dist/export/draw.js.map +1 -0
  154. package/dist/export/index.js +390 -0
  155. package/dist/export/index.js.map +1 -0
  156. package/dist/formula/edit.js +210 -0
  157. package/dist/formula/edit.js.map +1 -0
  158. package/dist/formula/engine.js +526 -0
  159. package/dist/formula/engine.js.map +1 -0
  160. package/dist/formula/error.js +39 -0
  161. package/dist/formula/error.js.map +1 -0
  162. package/dist/formula/functions.js +1493 -0
  163. package/dist/formula/functions.js.map +1 -0
  164. package/dist/formula/help.js +408 -0
  165. package/dist/formula/help.js.map +1 -0
  166. package/dist/formula/index.js +7 -0
  167. package/dist/formula/parse.js +369 -0
  168. package/dist/formula/parse.js.map +1 -0
  169. package/dist/formula/values.js +123 -0
  170. package/dist/formula/values.js.map +1 -0
  171. package/dist/formulas.js +30 -0
  172. package/dist/formulas.js.map +1 -0
  173. package/dist/index.js +39 -0
  174. package/dist/index.js.map +1 -0
  175. package/dist/locale.js +1312 -0
  176. package/dist/locale.js.map +1 -0
  177. package/dist/sheet.js +6 -0
  178. package/dist/sheet.js.map +1 -0
  179. package/dist/sheet.vue_vue_type_script_setup_true_lang.js +7166 -0
  180. package/dist/sheet.vue_vue_type_script_setup_true_lang.js.map +1 -0
  181. package/dist/style.css +1 -0
  182. package/dist/style.d.ts +1 -0
  183. package/dist/style.js +17 -0
  184. package/dist/types/cell-types.d.ts +2 -0
  185. package/dist/types/code/code-formula-bar.vue.d.ts +3 -0
  186. package/dist/types/code/index.d.ts +12 -0
  187. package/dist/types/code/language.d.ts +13 -0
  188. package/dist/types/collaboration/anchor.d.ts +65 -0
  189. package/dist/types/collaboration/index.d.ts +59 -0
  190. package/dist/types/collaboration/peers.d.ts +21 -0
  191. package/dist/types/collaboration/shared.d.ts +75 -0
  192. package/dist/types/components/cell-panel.vue.d.ts +20 -0
  193. package/dist/types/components/cell-renders.d.ts +9 -0
  194. package/dist/types/components/date-panel.vue.d.ts +9 -0
  195. package/dist/types/components/filter-panel.vue.d.ts +21 -0
  196. package/dist/types/components/format-dialog.vue.d.ts +24 -0
  197. package/dist/types/components/format-list.vue.d.ts +25 -0
  198. package/dist/types/components/format-presets.d.ts +30 -0
  199. package/dist/types/components/option-panel.vue.d.ts +13 -0
  200. package/dist/types/components/sheet-comment.vue.d.ts +29 -0
  201. package/dist/types/components/sheet-formula-bar.vue.d.ts +3 -0
  202. package/dist/types/components/sheet-link.vue.d.ts +32 -0
  203. package/dist/types/components/sheet-menu.vue.d.ts +20 -0
  204. package/dist/types/components/sheet-name-box.vue.d.ts +3 -0
  205. package/dist/types/components/sheet-note.vue.d.ts +22 -0
  206. package/dist/types/components/sheet-outline.vue.d.ts +36 -0
  207. package/dist/types/components/sheet-tabs.vue.d.ts +9 -0
  208. package/dist/types/components/sheet-toolbar.vue.d.ts +11 -0
  209. package/dist/types/components/validation-dialog.vue.d.ts +25 -0
  210. package/dist/types/context.d.ts +189 -0
  211. package/dist/types/core/address.d.ts +109 -0
  212. package/dist/types/core/axis.d.ts +23 -0
  213. package/dist/types/core/cell-type.d.ts +157 -0
  214. package/dist/types/core/clipboard.d.ts +48 -0
  215. package/dist/types/core/commands.d.ts +76 -0
  216. package/dist/types/core/comments.d.ts +22 -0
  217. package/dist/types/core/conditional.d.ts +114 -0
  218. package/dist/types/core/csv.d.ts +93 -0
  219. package/dist/types/core/data.d.ts +26 -0
  220. package/dist/types/core/document.d.ts +49 -0
  221. package/dist/types/core/extension.d.ts +177 -0
  222. package/dist/types/core/file.d.ts +301 -0
  223. package/dist/types/core/fill.d.ts +23 -0
  224. package/dist/types/core/find.d.ts +39 -0
  225. package/dist/types/core/format.d.ts +47 -0
  226. package/dist/types/core/group.d.ts +76 -0
  227. package/dist/types/core/history.d.ts +27 -0
  228. package/dist/types/core/index.d.ts +33 -0
  229. package/dist/types/core/link.d.ts +14 -0
  230. package/dist/types/core/merge.d.ts +26 -0
  231. package/dist/types/core/model.d.ts +363 -0
  232. package/dist/types/core/nav.d.ts +15 -0
  233. package/dist/types/core/paint.d.ts +19 -0
  234. package/dist/types/core/plain-cell-types.d.ts +6 -0
  235. package/dist/types/core/protect.d.ts +34 -0
  236. package/dist/types/core/selection.d.ts +25 -0
  237. package/dist/types/core/transaction.d.ts +470 -0
  238. package/dist/types/core/validation.d.ts +55 -0
  239. package/dist/types/core/versions.d.ts +38 -0
  240. package/dist/types/export/color.d.ts +7 -0
  241. package/dist/types/export/draw.d.ts +98 -0
  242. package/dist/types/export/index.d.ts +47 -0
  243. package/dist/types/formula/edit.d.ts +62 -0
  244. package/dist/types/formula/engine.d.ts +99 -0
  245. package/dist/types/formula/error.d.ts +30 -0
  246. package/dist/types/formula/functions.d.ts +62 -0
  247. package/dist/types/formula/help.d.ts +12 -0
  248. package/dist/types/formula/index.d.ts +13 -0
  249. package/dist/types/formula/parse.d.ts +92 -0
  250. package/dist/types/formula/values.d.ts +65 -0
  251. package/dist/types/formulas.d.ts +32 -0
  252. package/dist/types/index.d.ts +225 -0
  253. package/dist/types/locale.d.ts +531 -0
  254. package/dist/types/sheet.vue.d.ts +60 -0
  255. package/dist/types/types.d.ts +498 -0
  256. package/dist/types/use-comments.d.ts +47 -0
  257. package/dist/types/use-messages.d.ts +7 -0
  258. package/dist/use-comments.js +130 -0
  259. package/dist/use-comments.js.map +1 -0
  260. package/dist/use-messages.js +29 -0
  261. package/dist/use-messages.js.map +1 -0
  262. package/package.json +93 -4
@@ -0,0 +1,498 @@
1
+ import type { CommentAction, CommentAuthor, CommentThread } from 'dou-ui';
2
+ import type { Component } from 'vue';
3
+ import type { SheetCellTarget, SheetRange } from './core/address';
4
+ import type { SheetClip } from './core/clipboard';
5
+ import type { SheetCSVWriteOptions } from './core/csv';
6
+ import type { SheetCommands } from './core/commands';
7
+ import type { SheetCommentAnchor } from './core/comments';
8
+ import type { SheetSearchQuery, SheetMatch } from './core/find';
9
+ import type { SheetExtension } from './core/extension';
10
+ import type { SheetLinkTarget } from './core/link';
11
+ import type { SheetCSVExportOptions, SheetExporter, SheetExporterInfo, SheetExportScope, SheetImportResult, SheetImportWarning } from './core/file';
12
+ import type { SheetValidation, SheetWorkbook } from './core/model';
13
+ import type { SheetSelection } from './core/selection';
14
+ import type { SheetRef, SheetTransaction, SheetTransactionMeta } from './core/transaction';
15
+ import type { SheetMessagesOverride } from './locale';
16
+ export interface SheetProps {
17
+ /** The workbook. Changes come back through `update:modelValue`. */
18
+ modelValue: SheetWorkbook;
19
+ /** What is selected; bind with `v-model:selection`. */
20
+ selection?: SheetSelection;
21
+ /** The index of the sheet shown; bind with `v-model:activeSheet`. Defaults to 0. */
22
+ activeSheet?: number;
23
+ /**
24
+ * Show the cells without letting people change them in the grid;
25
+ * selecting still works. Changes made with `transact` still apply.
26
+ */
27
+ readonly?: boolean;
28
+ /** The default row height, in px. */
29
+ rowHeight?: number;
30
+ /** The default column width, in px. */
31
+ colWidth?: number;
32
+ /** Show the column letters and row numbers. */
33
+ headers?: boolean;
34
+ /**
35
+ * Show the outline of the groups beside the headers. Without it, groups
36
+ * stay folded or shown as they are, and fold from the menu and the keys.
37
+ */
38
+ outline?: boolean;
39
+ /** Draw lines between cells. */
40
+ gridlines?: boolean;
41
+ /** How many changes undo can go back. */
42
+ historyDepth?: number;
43
+ /** The grid's accessible name. */
44
+ ariaLabel?: string;
45
+ /** Texts to change. */
46
+ messages?: SheetMessagesOverride;
47
+ /**
48
+ * Changes the right-click menu: gets the items the grid would show and
49
+ * where the menu opened, and returns the items to show. Items can be
50
+ * removed, reordered, or added with a `run` of their own.
51
+ */
52
+ menu?: (items: SheetMenuItem[], context: SheetMenuContext) => SheetMenuItem[];
53
+ /**
54
+ * Extensions: cell types, keys, menu items, overlays and hooks. Create
55
+ * the list once, in `<script setup>`; arrays inside are flattened.
56
+ */
57
+ extensions?: (SheetExtension | SheetExtension[])[];
58
+ /**
59
+ * Reads a file dropped on the grid with the importers, putting its
60
+ * first sheet at the cell it was dropped on.
61
+ */
62
+ fileDrop?: boolean;
63
+ /**
64
+ * The comment threads, bound with `v-model:comments`; cells name theirs
65
+ * with `comment`. Without it (and without an extension that keeps them,
66
+ * such as `collaboration({ comments })`) cells can't be commented on.
67
+ */
68
+ comments?: CommentThread[];
69
+ /** Who is commenting. Without it, threads can be read but not written. */
70
+ author?: CommentAuthor;
71
+ /** The thread shown beside its cell, bound with `v-model:active-comment`. */
72
+ activeComment?: string | null;
73
+ /** Whether threads can be started and replied to, `readonly` or not. Defaults to `true`. */
74
+ commentable?: boolean;
75
+ /**
76
+ * An older version of the workbook, e.g. one the app saved. The grid then
77
+ * shows the workbook read-only, with the cells that changed since marked;
78
+ * pointing at one shows what it held.
79
+ */
80
+ compare?: SheetWorkbook | null;
81
+ }
82
+ /** Where `exportFile` takes the cells from, and what it passes the exporter. */
83
+ export interface SheetExportFileOptions<Options = any> {
84
+ /**
85
+ * Every sheet, the sheet shown (or `sheet`), or the selected cells; by
86
+ * default the first the exporter can do.
87
+ */
88
+ scope?: SheetExportScope;
89
+ /** The sheet, by index, `id` or name; the one shown by default. */
90
+ sheet?: SheetRef;
91
+ /** The cells to write, such as `'A1:F20'`; the selection for `'selection'`. */
92
+ range?: string;
93
+ /** Calls the export off; the exporter reads it as `source.signal`. */
94
+ signal?: AbortSignal;
95
+ /** Passed on to the exporter, such as CSV's `delimiter`. */
96
+ options?: Options;
97
+ }
98
+ /** `saveFile`'s options: `exportFile`'s, and the file's name. */
99
+ export interface SheetSaveFileOptions<Options = any> extends SheetExportFileOptions<Options> {
100
+ /** The file's name, with its extension; the exported sheet's name by default. */
101
+ fileName?: string;
102
+ }
103
+ /**
104
+ * The options of the exporters by name, for `exportFile('csv', { options })`.
105
+ * An extension adds its own by augmenting it:
106
+ *
107
+ * ```ts
108
+ * declare module '@dou-ui/sheet' {
109
+ * interface SheetExporterOptions { xlsx: XlsxOptions }
110
+ * }
111
+ * ```
112
+ */
113
+ export interface SheetExporterOptions {
114
+ csv: SheetCSVExportOptions;
115
+ png: SheetImageOptions;
116
+ svg: SheetExportOptions;
117
+ }
118
+ /** The options of an exporter named so, or anything for a name no one declared. */
119
+ export type SheetExporterOptionsOf<Name> = Name extends keyof SheetExporterOptions ? SheetExporterOptions[Name] : any;
120
+ /** An import or export that failed, for the `file-error` event. */
121
+ export interface SheetFileErrorEvent {
122
+ action: 'import' | 'export';
123
+ /** The file being read, for an import. */
124
+ file?: Blob;
125
+ /** The exporter's name, for an export. */
126
+ exporter?: string;
127
+ /** The importer's name, when one took the file. */
128
+ importer?: string;
129
+ /** What went wrong; for a file no importer takes, an error saying so. */
130
+ error: unknown;
131
+ /** What the grid tells the user, in its language, e.g. “不支持导入“报表.xlsx””. */
132
+ message: string;
133
+ defaultPrevented: boolean;
134
+ /** Keeps the grid from showing `message`, for a message of your own; screen readers still hear it. */
135
+ preventDefault: () => void;
136
+ }
137
+ /** How `importFile` writes what it read: as new sheets, instead of every sheet, or at the active cell. */
138
+ export type SheetImportMode = 'append' | 'replace' | 'insert';
139
+ export interface SheetImportFileOptions<Options = any> {
140
+ /** `'append'` by default. */
141
+ mode?: SheetImportMode;
142
+ /** The importer, by name; by default the first that takes the file. */
143
+ importer?: string;
144
+ /** Calls the import off: the importer reads it, and nothing is written once it is aborted. */
145
+ signal?: AbortSignal;
146
+ /** Passed on to the importer. */
147
+ options?: Options;
148
+ }
149
+ /**
150
+ * The `import` event, after a file is read and before it is written in.
151
+ * `book` can be changed, and `preventDefault()` stops it.
152
+ */
153
+ export interface SheetImportEvent {
154
+ file: Blob;
155
+ /** The name of the importer that read it. */
156
+ importer: string;
157
+ mode: SheetImportMode;
158
+ book: SheetWorkbook;
159
+ /** What the importer couldn't bring over. */
160
+ warnings: SheetImportWarning[];
161
+ defaultPrevented: boolean;
162
+ preventDefault: () => void;
163
+ /**
164
+ * Writes `book` in with `mode` after `preventDefault()`, e.g. once the
165
+ * user agrees. Returns whether anything was written.
166
+ */
167
+ apply: () => boolean;
168
+ }
169
+ /** An item of the right-click menu. */
170
+ export interface SheetMenuItem {
171
+ /** Unique within the menu. */
172
+ key: string;
173
+ /**
174
+ * The command it runs (see `commands`): its label, icon, shortcut and
175
+ * whether it can run now come from the command, unless given here.
176
+ */
177
+ command?: string;
178
+ /** Needed unless it has a `command`. */
179
+ label?: string;
180
+ icon?: Component;
181
+ /** The shortcut shown beside it, such as `mod+c`; hidden on touch screens. */
182
+ shortcut?: string;
183
+ tone?: 'neutral' | 'danger';
184
+ /** A line above it. */
185
+ divided?: boolean;
186
+ disabled?: boolean;
187
+ /** Items shown in a submenu; an item with them has no `run`. */
188
+ children?: SheetMenuItem[];
189
+ run?: () => void;
190
+ }
191
+ /** Where the menu opened. */
192
+ export interface SheetMenuContext {
193
+ /**
194
+ * What was pressed: a cell, a column or row header, or the corner. A
195
+ * selection of whole columns or rows counts as their header.
196
+ */
197
+ area: 'cell' | 'col' | 'row' | 'corner';
198
+ /** The selection the menu acts on. */
199
+ selection: SheetSelection;
200
+ /** The index of the sheet shown. */
201
+ sheet: number;
202
+ }
203
+ /**
204
+ * Before a link is followed, from its card, the menu, Ctrl / ⌘ + click or the
205
+ * `link.open` command. `preventDefault()` keeps the grid from opening a web
206
+ * address in a new tab or going to the cells, e.g. to use the app's router.
207
+ */
208
+ export interface SheetLinkOpenEvent {
209
+ link: string;
210
+ target: SheetLinkTarget;
211
+ /** The cell with the link: the sheet's index, its row and column. */
212
+ cell: {
213
+ sheet: number;
214
+ row: number;
215
+ col: number;
216
+ };
217
+ defaultPrevented: boolean;
218
+ preventDefault: () => void;
219
+ }
220
+ /**
221
+ * The `paste` event, before anything is written. `clip` can be changed or
222
+ * replaced, and `preventDefault()` stops the paste.
223
+ */
224
+ export interface SheetPasteEvent {
225
+ clip: SheetClip;
226
+ /** Where the clip goes: the first range when one cell fills several. */
227
+ range: SheetRange;
228
+ defaultPrevented: boolean;
229
+ preventDefault: () => void;
230
+ }
231
+ /**
232
+ * Room above and below the grid, for a toolbar or the sheet tabs. What is
233
+ * put there can use `useSheet()`.
234
+ */
235
+ export interface SheetSlots {
236
+ header?: () => unknown;
237
+ footer?: () => unknown;
238
+ }
239
+ /**
240
+ * A tool of `DouSheetToolbar`: `|` is a line between groups; `color` and
241
+ * `fill` are the text and fill colors, `align` left / center / right and
242
+ * `valign` top / middle / bottom; `format` is the number format menu and
243
+ * `decimals` the two buttons beside it.
244
+ */
245
+ export type SheetToolbarTool = 'undo' | 'redo' | 'format' | 'decimals' | 'bold' | 'italic' | 'underline' | 'strike' | 'color' | 'fill' | 'align' | 'valign' | 'wrap' | 'merge' | 'freeze' | 'sort' | 'filter' | 'conditional' | 'validation' | 'link' | 'protect' | 'clear' | 'export' | 'import' | '|';
246
+ /**
247
+ * A button of `DouSheetToolbar` added by an extension (its `toolbar`). With
248
+ * a `command`, it takes the label, icon, shortcut, state and action from
249
+ * the command; what is given here wins.
250
+ */
251
+ export interface SheetToolbarItem {
252
+ /** Unique within the toolbar; `tools` can name it. */
253
+ key: string;
254
+ command?: string;
255
+ /** Read out, and shown as the tooltip; shown in place of the icon when there is none. */
256
+ label?: string;
257
+ icon?: Component;
258
+ run?: () => void;
259
+ disabled?: boolean;
260
+ /** For a button that turns something on and off: whether it is on. */
261
+ pressed?: boolean;
262
+ /** The key that does the same, shown in the tooltip; only a hint. */
263
+ shortcut?: string;
264
+ /** Opens a menu of these instead of running anything. */
265
+ children?: SheetMenuItem[];
266
+ }
267
+ /** A number format offered in the toolbar's menu. */
268
+ export interface SheetFormatOption {
269
+ label: string;
270
+ /** The format; `undefined` for none. */
271
+ format: string | undefined;
272
+ /** A value shown beside it in that format. */
273
+ example?: string | number;
274
+ }
275
+ export interface SheetToolbarProps {
276
+ /**
277
+ * The tools, in order: built-in ones, the `key` of an extension's item,
278
+ * or the name of any command (e.g. `'print'`), shown as a button. By
279
+ * default every built-in tool, then the extensions' items.
280
+ */
281
+ tools?: (SheetToolbarTool | (string & {}))[];
282
+ /** The number formats in the menu, instead of the usual ones. */
283
+ formats?: SheetFormatOption[];
284
+ /**
285
+ * The name the export menu saves files as: a name the exporter's
286
+ * extension is added to, or a function giving the whole name. The
287
+ * exported sheet's name by default.
288
+ */
289
+ fileName?: string | ((exporter: SheetExporterInfo, scope: SheetExportScope) => string);
290
+ }
291
+ export interface SheetToolbarSlots {
292
+ /** More controls before the tools, and after them. They can use `useSheet()`. */
293
+ start?: () => unknown;
294
+ end?: () => unknown;
295
+ }
296
+ export interface SheetEmits {
297
+ 'update:modelValue': [value: SheetWorkbook];
298
+ 'update:selection': [value: SheetSelection];
299
+ 'update:activeSheet': [value: number];
300
+ /**
301
+ * Every change, after it is applied: undo, redo and edits alike.
302
+ * `tr.meta.action` says what made it.
303
+ */
304
+ transaction: [tr: SheetTransaction];
305
+ /**
306
+ * An extension's `transaction` hook cancelled a change, or a protected
307
+ * cell refused it; `tr.cancelReason` says why, and the grid shows it.
308
+ */
309
+ transactionCancel: [tr: SheetTransaction];
310
+ /** Before pasting: change what is pasted, or stop it. */
311
+ paste: [event: SheetPasteEvent];
312
+ /** Before a link is followed: take it over, or stop it. */
313
+ linkOpen: [event: SheetLinkOpenEvent];
314
+ /** After a file is read, before it is written in: change it, or stop it. */
315
+ import: [event: SheetImportEvent];
316
+ /** An import or export failed; the grid shows a short message too. */
317
+ fileError: [event: SheetFileErrorEvent];
318
+ 'update:comments': [threads: CommentThread[]];
319
+ 'update:activeComment': [id: string | null];
320
+ /** A change to the comments made here: to send to a server, notify people, keep a log. */
321
+ commentAction: [action: CommentAction];
322
+ }
323
+ export interface SheetExpose {
324
+ /** The commands, built in and added: run them, or read their state, e.g. from a menu bar outside the grid. */
325
+ commands: SheetCommands;
326
+ /**
327
+ * Makes a change: `run` adds steps to the transaction, which is applied
328
+ * and recorded for undo as one. Cells without a sheet (`'A5'`) are on
329
+ * the sheet shown. Returns it: `tr.changed` is `false` when nothing
330
+ * changed or the change was cancelled, and `tr.cancelled` says it was
331
+ * (`transactionCancel` tells why). Works on a `readonly` grid too: that
332
+ * only stops people using the grid. Protected cells still refuse it
333
+ * unless `meta.protection` or `meta.history` is `false`.
334
+ */
335
+ transact: (run: (tr: SheetTransaction) => void, meta?: SheetTransactionMeta) => SheetTransaction;
336
+ undo: () => boolean;
337
+ redo: () => boolean;
338
+ readonly canUndo: boolean;
339
+ readonly canRedo: boolean;
340
+ /** Selects a range (`'A1:C4'`, `'B2'`, a range or a whole selection) and scrolls it into view. */
341
+ select: (target: string | SheetRange | SheetSelection) => void;
342
+ /** Scrolls a cell into view. */
343
+ scrollTo: (cell: SheetCellTarget) => void;
344
+ /**
345
+ * Shows a sheet, by index, `id` or name; returns `false` when there is
346
+ * no such sheet.
347
+ */
348
+ showSheet: (sheet: SheetRef) => boolean;
349
+ /**
350
+ * The cells that match a query, in order of sheet, row and column, as
351
+ * the find panel finds them: hidden rows and columns are skipped.
352
+ */
353
+ findCells: (query: SheetSearchQuery) => SheetMatch[];
354
+ /**
355
+ * Opens the find panel (`Ctrl/⌘+F`), with a query put in; with `replace`
356
+ * in it, the replace box opens too, unless the sheet is read-only. Runs
357
+ * the `find` command, so an extension that overrides it is used; `false`
358
+ * when it refuses.
359
+ */
360
+ openSearch: (query?: Partial<SheetSearchQuery>) => boolean;
361
+ /** Closes the find panel; `false` when it was not open. */
362
+ closeSearch: () => boolean;
363
+ /**
364
+ * The sheet shown (or `sheet`) as CSV: values a spreadsheet can sort and
365
+ * add up by default (what formulas come to, cell types' `plain`), or with
366
+ * `text`, the text the cells show, as their formats and cell types write it.
367
+ */
368
+ toCSV: (options?: SheetCSVWriteOptions & {
369
+ sheet?: SheetRef;
370
+ }) => string;
371
+ /**
372
+ * The sheet shown (or `sheet`) as an SVG document, as the grid draws it,
373
+ * in the current theme.
374
+ */
375
+ exportSVG: (options?: SheetExportOptions) => string;
376
+ /** The sheet shown (or `sheet`) as a PNG image. */
377
+ exportPNG: (options?: SheetImageOptions) => Promise<Blob>;
378
+ /**
379
+ * Opens the browser's print dialog for the sheet shown (or `sheet`): on
380
+ * A4 pages, in the light theme, with the frozen rows and columns on
381
+ * every page.
382
+ */
383
+ print: (options?: SheetPrintOptions) => void;
384
+ /**
385
+ * Writes a file with an exporter (by name, such as `'csv'`, or itself):
386
+ * the workbook, a sheet or the selected cells.
387
+ */
388
+ exportFile: {
389
+ <Name extends string>(exporter: Name, options?: SheetExportFileOptions<SheetExporterOptionsOf<Name>>): Promise<Blob>;
390
+ <Options>(exporter: SheetExporter<Options>, options?: SheetExportFileOptions<Options>): Promise<Blob>;
391
+ };
392
+ /**
393
+ * Exports as `exportFile` does and saves the file in the downloads, as the
394
+ * toolbar does. A failure shows a short message over the grid and comes
395
+ * as `file-error`, and the promise rejects.
396
+ */
397
+ saveFile: {
398
+ <Name extends string>(exporter: Name, options?: SheetSaveFileOptions<SheetExporterOptionsOf<Name>>): Promise<void>;
399
+ <Options>(exporter: SheetExporter<Options>, options?: SheetSaveFileOptions<Options>): Promise<void>;
400
+ };
401
+ /**
402
+ * Reads a file into the workbook, as one change undo takes back. Returns
403
+ * what was read, or `null` when nothing was written (no importer takes
404
+ * the file, the grid is read-only, the `import` event stopped it, or it
405
+ * was aborted). A failure shows a short message over the grid and comes
406
+ * as `file-error`; an importer's error also rejects the promise.
407
+ */
408
+ importFile: (file: Blob, options?: SheetImportFileOptions) => Promise<SheetImportResult | null>;
409
+ /** Opens the editor on a cell, the active one by default. */
410
+ edit: (cell?: SheetCellTarget) => void;
411
+ /** Selects a cell, the active one by default, and opens the box to write its note. */
412
+ editNote: (cell?: SheetCellTarget) => void;
413
+ /** Selects a cell, the active one by default, and opens the box to write its link. */
414
+ editLink: (cell?: SheetCellTarget) => void;
415
+ focus: () => void;
416
+ /** Copies (or cuts) the selection to the system clipboard. */
417
+ copy: () => Promise<void>;
418
+ cut: () => Promise<void>;
419
+ /**
420
+ * Pastes at the selection: the given cells (e.g. from `parseClip`), or what
421
+ * is on the system clipboard when the browser allows reading it.
422
+ */
423
+ paste: (clip?: SheetClip) => Promise<void>;
424
+ /**
425
+ * The cells whose values break a validation rule, row by row: on every
426
+ * sheet, or on `sheet`. Use it to check a workbook before sending it.
427
+ */
428
+ findInvalid: (sheet?: SheetRef) => SheetInvalidCell[];
429
+ /**
430
+ * Opens the thread about a cell, the active one by default, or the box
431
+ * to start one; `false` when there is neither (no comments, or nobody to
432
+ * write it).
433
+ */
434
+ comment: (cell?: SheetCellTarget) => boolean;
435
+ /**
436
+ * Where each thread is, by thread id; `null` for one whose cell is gone.
437
+ * Read it again after `change` or `update:comments`.
438
+ */
439
+ getCommentAnchors: () => Record<string, SheetCommentAnchor | null>;
440
+ /**
441
+ * Replaces the workbook with `book`, e.g. an older version, as one change
442
+ * undo takes back. Only what differs is written, so with collaboration
443
+ * the others' work elsewhere stays. Threads stay on their cells. Like
444
+ * `transact` it works on a `readonly` grid, and it works while comparing;
445
+ * protection doesn't hold it. Returns `false` when nothing differs, or
446
+ * an extension cancelled it.
447
+ */
448
+ restore: (book: SheetWorkbook) => boolean;
449
+ /** With `compare`: selects the next changed cell, on any sheet; `false` when there is none. */
450
+ nextChange: () => boolean;
451
+ /** With `compare`: selects the changed cell before the active one. */
452
+ previousChange: () => boolean;
453
+ }
454
+ /** Options of `exportSVG` and `exportPNG`. */
455
+ export interface SheetExportOptions {
456
+ /** The sheet drawn, by index, `id` or name; the one shown by default. */
457
+ sheet?: SheetRef;
458
+ /**
459
+ * The cells drawn, such as `'A1:F20'` or `'A:D'`. By default from `A1`
460
+ * to the last row and column with data or a merge.
461
+ */
462
+ range?: string;
463
+ /** Draws the column letters and row numbers. */
464
+ headers?: boolean;
465
+ /** Draws the grid lines; by default as the grid shows them. */
466
+ gridlines?: boolean;
467
+ /** Fills the background; `false` leaves it see-through. Defaults to `true`. */
468
+ background?: boolean;
469
+ }
470
+ /** Options of `exportPNG`. */
471
+ export interface SheetImageOptions extends SheetExportOptions {
472
+ /** Image pixels per CSS pixel. Defaults to `2`; less for a sheet too big for that. */
473
+ pixelRatio?: number;
474
+ }
475
+ export interface SheetPrintOptions {
476
+ /** The sheet printed, by index, `id` or name; the one shown by default. */
477
+ sheet?: SheetRef;
478
+ /** The cells printed, as for `exportSVG`. */
479
+ range?: string;
480
+ /** Prints the column letters and row numbers. */
481
+ headers?: boolean;
482
+ /** Prints the grid lines; by default as the grid shows them. */
483
+ gridlines?: boolean;
484
+ /** A heading on every page. */
485
+ title?: string;
486
+ /** By default landscape when the cells are wider than a portrait page. */
487
+ orientation?: 'portrait' | 'landscape';
488
+ }
489
+ /** A cell whose value breaks a validation rule. */
490
+ export interface SheetInvalidCell {
491
+ /** The sheet's name. */
492
+ sheet: string;
493
+ /** Where the cell is, such as `'C4'`. */
494
+ cell: string;
495
+ rule: SheetValidation;
496
+ /** The rule in words: its `message`, or what it asks for. */
497
+ message: string;
498
+ }
@@ -0,0 +1,47 @@
1
+ import { type CommentAction, type CommentThread } from 'dou-ui';
2
+ import { type ComputedRef, type Ref } from 'vue';
3
+ import type { SheetPoint } from './core/address';
4
+ import { type SheetCommentAnchor } from './core/comments';
5
+ import type { SheetCommentsProvider } from './core/extension';
6
+ import type { SheetWorkbook } from './core/model';
7
+ import { type SheetTransaction, type SheetTransactionMeta } from './core/transaction';
8
+ import type { SheetEmits, SheetProps } from './types';
9
+ type Emit = <K extends keyof SheetEmits>(event: K, ...args: SheetEmits[K]) => void;
10
+ /** A cell of a sheet, by the sheet's key. */
11
+ export interface SheetCommentCell extends SheetPoint {
12
+ sheet: string;
13
+ }
14
+ /**
15
+ * The comment threads of a sheet: which one is open beside its cell, the
16
+ * cell a new one is being written for, and the changes made from the card.
17
+ */
18
+ export declare function useSheetComments(options: {
19
+ props: SheetProps;
20
+ emit: Emit;
21
+ provider: ComputedRef<SheetCommentsProvider | null>;
22
+ doc: Readonly<Ref<SheetWorkbook>>;
23
+ /** The cell a thread on `point` of the sheet shown goes on: a merge's top left. */
24
+ home: (point: SheetPoint) => SheetPoint;
25
+ /** The key of the sheet shown. */
26
+ shown: () => string;
27
+ transact: (run: (tr: SheetTransaction) => void, meta?: SheetTransactionMeta) => SheetTransaction | null;
28
+ }): {
29
+ enabled: ComputedRef<boolean>;
30
+ writable: ComputedRef<boolean>;
31
+ threads: ComputedRef<readonly CommentThread[]>;
32
+ byId: ComputedRef<Map<string, CommentThread>>;
33
+ active: ComputedRef<string | null>;
34
+ pending: import("vue").ShallowRef<SheetCommentCell | null, SheetCommentCell | null>;
35
+ cell: ComputedRef<SheetCommentCell | null>;
36
+ focusRequest: import("vue").ShallowRef<number, number>;
37
+ threadAt: (point: SheetPoint) => CommentThread | undefined;
38
+ isOpen: (thread: CommentThread | undefined) => boolean;
39
+ start: (point: SheetPoint) => boolean;
40
+ show: (point: SheetPoint) => void;
41
+ open: (id: string | null) => void;
42
+ close: () => void;
43
+ apply: (action: CommentAction) => void;
44
+ getAnchors: () => Record<string, SheetCommentAnchor | null>;
45
+ };
46
+ export type SheetComments = ReturnType<typeof useSheetComments>;
47
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type MaybeRefOrGetter } from 'vue';
2
+ import { type SheetMessages, type SheetMessagesOverride } from './locale';
3
+ /**
4
+ * The spreadsheet's texts, picked by the name of DouUI's current locale.
5
+ * Pass `messages` to override any of them.
6
+ */
7
+ export declare function useSheetMessages(override?: MaybeRefOrGetter<SheetMessagesOverride | undefined>): import("vue").ComputedRef<SheetMessages>;
@@ -0,0 +1,130 @@
1
+ import { sheetKey } from "./core/transaction.js";
2
+ import { sheetCommentAnchors } from "./core/comments.js";
3
+ import { applyCommentAction } from "dou-ui";
4
+ import { computed, onMounted, shallowRef, watch } from "vue";
5
+ // src/use-comments.ts
6
+ /** Whether a thread shows: known and not resolved. */
7
+ var isOpen = (thread) => !!thread && !thread.resolved;
8
+ /**
9
+ * The comment threads of a sheet: which one is open beside its cell, the
10
+ * cell a new one is being written for, and the changes made from the card.
11
+ */
12
+ function useSheetComments(options) {
13
+ const { props, emit, provider, doc, home, shown, transact } = options;
14
+ const threads = computed(() => provider.value?.threads.value ?? props.comments ?? []);
15
+ const enabled = computed(() => (!!provider.value || props.comments !== void 0) && !props.compare);
16
+ const writable = computed(() => enabled.value && !!props.author && props.commentable !== false);
17
+ const byId = computed(() => new Map(threads.value.map((thread) => [thread.id, thread])));
18
+ onMounted(() => watch(() => provider.value?.threads.value, (value) => value && emit("update:comments", [...value]), { immediate: true }));
19
+ const innerActive = shallowRef(null);
20
+ const active = computed(() => props.activeComment === void 0 ? innerActive.value : props.activeComment);
21
+ function open(id) {
22
+ if (id === active.value) return;
23
+ innerActive.value = id;
24
+ emit("update:activeComment", id);
25
+ }
26
+ /** The cell a new thread is being written for. */
27
+ const pending = shallowRef(null);
28
+ /** Bumped to put the cursor in the card's reply box. */
29
+ const focusRequest = shallowRef(0);
30
+ /** The thread a cell of the sheet shown names; `undefined` when it names none (or one not known). */
31
+ function threadAt(point) {
32
+ const at = home(point);
33
+ const cell = doc.value.sheets.find((sheet) => sheetKey(sheet) === shown())?.cells[at.row]?.[at.col];
34
+ const id = cell && typeof cell === "object" ? cell.comment : void 0;
35
+ return id ? byId.value.get(id) : void 0;
36
+ }
37
+ const anchors = computed(() => enabled.value ? sheetCommentAnchors(doc.value) : /* @__PURE__ */ new Map());
38
+ /** Where the card is: the cell being commented on, or the open thread's. */
39
+ const cell = computed(() => {
40
+ if (pending.value) return pending.value;
41
+ const id = active.value;
42
+ const anchor = id ? anchors.value.get(id) : void 0;
43
+ return anchor ? {
44
+ sheet: anchor.sheet,
45
+ row: anchor.row,
46
+ col: anchor.col
47
+ } : null;
48
+ });
49
+ /**
50
+ * The thread about a cell of the sheet shown, ready to reply to; or the
51
+ * box to start one. `false` when there is neither.
52
+ */
53
+ function start(point) {
54
+ if (!enabled.value) return false;
55
+ const at = home(point);
56
+ const thread = threadAt(at);
57
+ if (thread) {
58
+ pending.value = null;
59
+ open(thread.id);
60
+ focusRequest.value++;
61
+ return true;
62
+ }
63
+ if (!writable.value) return false;
64
+ open(null);
65
+ pending.value = {
66
+ sheet: shown(),
67
+ ...at
68
+ };
69
+ focusRequest.value++;
70
+ return true;
71
+ }
72
+ /** Opens the open thread on a cell just clicked, or closes the card when it has none. */
73
+ function show(point) {
74
+ if (!enabled.value) return;
75
+ const thread = threadAt(point);
76
+ pending.value = null;
77
+ open(isOpen(thread) ? thread.id : null);
78
+ }
79
+ function close() {
80
+ pending.value = null;
81
+ open(null);
82
+ }
83
+ const meta = {
84
+ history: false,
85
+ action: "comment"
86
+ };
87
+ function apply(action) {
88
+ if (action.type === "create") {
89
+ const at = pending.value;
90
+ if (!at) return;
91
+ transact((tr) => tr.setComment(at, action.thread.id), meta);
92
+ pending.value = null;
93
+ } else if (action.type === "remove") {
94
+ const anchor = anchors.value.get(action.threadId);
95
+ if (anchor) transact((tr) => tr.setComment(anchor, void 0), meta);
96
+ }
97
+ if (provider.value) provider.value.apply(action);
98
+ else emit("update:comments", applyCommentAction(threads.value, action));
99
+ emit("commentAction", action);
100
+ if (action.type === "create") {
101
+ open(action.thread.id);
102
+ focusRequest.value++;
103
+ } else if (action.type === "remove" || action.type === "resolve") open(null);
104
+ }
105
+ function getAnchors() {
106
+ const found = sheetCommentAnchors(doc.value);
107
+ return Object.fromEntries(threads.value.map((thread) => [thread.id, found.get(thread.id) ?? null]));
108
+ }
109
+ return {
110
+ enabled,
111
+ writable,
112
+ threads,
113
+ byId,
114
+ active,
115
+ pending,
116
+ cell,
117
+ focusRequest,
118
+ threadAt,
119
+ isOpen,
120
+ start,
121
+ show,
122
+ open,
123
+ close,
124
+ apply,
125
+ getAnchors
126
+ };
127
+ }
128
+ export { useSheetComments };
129
+
130
+ //# sourceMappingURL=use-comments.js.map