@blocknote/core 0.24.2 → 0.25.0
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.
- package/dist/blocknote.cjs +12 -0
- package/dist/blocknote.cjs.map +1 -0
- package/dist/blocknote.js +4754 -3514
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs +2 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.js +593 -0
- package/dist/comments.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +39 -26
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +1022 -378
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +730 -270
- package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +3100 -1260
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +438 -162
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +1168 -432
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +930 -378
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2485 -1015
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +28 -1
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +1 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +292 -108
- package/src/api/blockManipulation/setupTestEnv.ts +14 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1987 -0
- package/src/api/blockManipulation/tables/tables.ts +887 -0
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteImage.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteTable.html +132 -48
- package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +136 -44
- package/src/api/clipboard/toClipboard/copyExtension.ts +2 -3
- package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +1 -0
- package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +4 -0
- package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +4 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +5 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +985 -20
- package/src/api/nodeConversions/blockToNode.ts +63 -20
- package/src/api/nodeConversions/nodeToBlock.ts +75 -13
- package/src/api/parsers/html/__snapshots__/parse-notion-html.json +145 -54
- package/src/api/testUtil/cases/defaultSchema.ts +782 -9
- package/src/api/testUtil/partialBlockTestUtil.ts +39 -4
- package/src/blocks/TableBlockContent/TableBlockContent.ts +11 -5
- package/src/blocks/defaultBlockTypeGuards.ts +8 -0
- package/src/comments/index.ts +9 -0
- package/src/comments/models/User.ts +8 -0
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +106 -0
- package/src/comments/threadstore/ThreadStore.ts +134 -0
- package/src/comments/threadstore/ThreadStoreAuth.ts +13 -0
- package/src/comments/threadstore/TipTapThreadStore.ts +292 -0
- package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +144 -0
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +294 -0
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +340 -0
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +48 -0
- package/src/comments/threadstore/yjs/yjsHelpers.ts +121 -0
- package/src/comments/types.ts +117 -0
- package/src/editor/Block.css +16 -8
- package/src/editor/BlockNoteEditor.ts +269 -92
- package/src/editor/BlockNoteExtensions.ts +24 -1
- package/src/editor/BlockNoteTipTapEditor.ts +5 -1
- package/src/editor/editor.css +17 -0
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
- package/src/extensions/Comments/CommentMark.ts +61 -0
- package/src/extensions/Comments/CommentsPlugin.ts +301 -0
- package/src/extensions/Comments/userstore/UserStore.ts +72 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +9 -5
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +3 -3
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +52 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +409 -57
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +2 -0
- package/src/extensions/TextColor/TextColorExtension.ts +1 -1
- package/src/i18n/locales/ar.ts +23 -0
- package/src/i18n/locales/de.ts +15 -0
- package/src/i18n/locales/en.ts +25 -1
- package/src/i18n/locales/es.ts +16 -1
- package/src/i18n/locales/fr.ts +23 -0
- package/src/i18n/locales/hr.ts +18 -0
- package/src/i18n/locales/is.ts +24 -1
- package/src/i18n/locales/it.ts +15 -0
- package/src/i18n/locales/ja.ts +23 -0
- package/src/i18n/locales/ko.ts +23 -0
- package/src/i18n/locales/nl.ts +23 -0
- package/src/i18n/locales/no.ts +23 -0
- package/src/i18n/locales/pl.ts +23 -0
- package/src/i18n/locales/pt.ts +23 -0
- package/src/i18n/locales/ru.ts +23 -0
- package/src/i18n/locales/uk.ts +23 -0
- package/src/i18n/locales/vi.ts +23 -0
- package/src/i18n/locales/zh.ts +23 -0
- package/src/index.ts +6 -4
- package/src/schema/blocks/types.ts +32 -2
- package/src/util/browser.ts +1 -1
- package/src/util/table.ts +107 -0
- package/types/src/api/blockManipulation/tables/tables.d.ts +343 -0
- package/types/src/api/blockManipulation/tables/tables.test.d.ts +1 -0
- package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +1 -1
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +1 -2
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +3 -0
- package/types/src/comments/index.d.ts +9 -0
- package/types/src/comments/models/User.d.ts +8 -0
- package/types/src/comments/threadstore/DefaultThreadStoreAuth.d.ts +47 -0
- package/types/src/comments/threadstore/ThreadStore.d.ts +121 -0
- package/types/src/comments/threadstore/ThreadStoreAuth.d.ts +12 -0
- package/types/src/comments/threadstore/TipTapThreadStore.d.ts +97 -0
- package/types/src/comments/threadstore/yjs/RESTYjsThreadStore.d.ts +83 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStore.d.ts +79 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStore.test.d.ts +1 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/comments/threadstore/yjs/yjsHelpers.d.ts +13 -0
- package/types/src/comments/types.d.ts +109 -0
- package/types/src/editor/BlockNoteEditor.d.ts +146 -66
- package/types/src/editor/BlockNoteExtensions.d.ts +4 -0
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +1 -1
- package/types/src/extensions/Comments/CommentMark.d.ts +2 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +49 -0
- package/types/src/extensions/Comments/userstore/UserStore.d.ts +31 -0
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +15 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +66 -1
- package/types/src/i18n/locales/de.d.ts +15 -0
- package/types/src/i18n/locales/en.d.ts +20 -0
- package/types/src/i18n/locales/es.d.ts +15 -0
- package/types/src/i18n/locales/hr.d.ts +18 -0
- package/types/src/i18n/locales/it.d.ts +15 -0
- package/types/src/index.d.ts +5 -4
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
- package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
- package/types/src/schema/blocks/types.d.ts +23 -2
- package/types/src/util/browser.d.ts +1 -1
- package/types/src/util/table.d.ts +12 -0
- package/dist/blocknote.umd.cjs +0 -11
- package/dist/blocknote.umd.cjs.map +0 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { DefaultBlockSchema } from "../../../blocks/defaultBlocks.js";
|
|
2
|
+
import { BlockFromConfigNoChildren, TableCell, TableContent } from "../../../schema/blocks/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Here be dragons.
|
|
5
|
+
*
|
|
6
|
+
* Tables are complex because of rowspan and colspan behavior.
|
|
7
|
+
* The majority of this file is concerned with translating between "relative" and "absolute" indices.
|
|
8
|
+
*
|
|
9
|
+
* The following diagram may help explain the relationship between the different indices:
|
|
10
|
+
*
|
|
11
|
+
* One-based indexing of rows and columns in a table:
|
|
12
|
+
* | 1-1 | 1-2 | 1-3 |
|
|
13
|
+
* | 2-1 | 2-2 | 2-3 |
|
|
14
|
+
* | 3-1 | 3-2 | 3-3 |
|
|
15
|
+
*
|
|
16
|
+
* A complicated table with colspans and rowspans:
|
|
17
|
+
* | 1-1 | 1-2 | 1-2 |
|
|
18
|
+
* | 2-1 | 2-1 | 2-2 |
|
|
19
|
+
* | 2-1 | 2-1 | 3-1 |
|
|
20
|
+
*
|
|
21
|
+
* You can see here that we have:
|
|
22
|
+
* - two cells that contain the value "1-2", because it has a colspan of 2.
|
|
23
|
+
* - four cells that contain the value "2-1", because it has a rowspan of 2 and a colspan of 2.
|
|
24
|
+
*
|
|
25
|
+
* This would be represented in block note json (roughly) as:
|
|
26
|
+
* [
|
|
27
|
+
* {
|
|
28
|
+
* "cells": [
|
|
29
|
+
* {
|
|
30
|
+
* "type": "tableCell",
|
|
31
|
+
* "content": ["1,1"],
|
|
32
|
+
* "props": {
|
|
33
|
+
* "colspan": 1,
|
|
34
|
+
* "rowspan": 1
|
|
35
|
+
* },
|
|
36
|
+
* },
|
|
37
|
+
* {
|
|
38
|
+
* "type": "tableCell",
|
|
39
|
+
* "content": ["1,2"],
|
|
40
|
+
* "props": {
|
|
41
|
+
* "colspan": 2,
|
|
42
|
+
* "rowspan": 1
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ],
|
|
46
|
+
* },
|
|
47
|
+
* {
|
|
48
|
+
* "cells": [
|
|
49
|
+
* {
|
|
50
|
+
* "type": "tableCell",
|
|
51
|
+
* "content": ["2,1"],
|
|
52
|
+
* "props": {
|
|
53
|
+
* "colspan": 2,
|
|
54
|
+
* "rowspan": 2
|
|
55
|
+
* }
|
|
56
|
+
* },
|
|
57
|
+
* {
|
|
58
|
+
* "type": "tableCell",
|
|
59
|
+
* "content": ["2,2"],
|
|
60
|
+
* "props": {
|
|
61
|
+
* "colspan": 1,
|
|
62
|
+
* "rowspan": 1
|
|
63
|
+
* }
|
|
64
|
+
* ],
|
|
65
|
+
* },
|
|
66
|
+
* {
|
|
67
|
+
* "cells": [
|
|
68
|
+
* {
|
|
69
|
+
* "type": "tableCell",
|
|
70
|
+
* "content": ["3,1"],
|
|
71
|
+
* "props": {
|
|
72
|
+
* "colspan": 1,
|
|
73
|
+
* "rowspan": 1,
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ]
|
|
77
|
+
* }
|
|
78
|
+
* ]
|
|
79
|
+
*
|
|
80
|
+
* Which maps cleanly to the following HTML:
|
|
81
|
+
*
|
|
82
|
+
* <table>
|
|
83
|
+
* <tr>
|
|
84
|
+
* <td>1-1</td>
|
|
85
|
+
* <td colspan="2">1-2</td>
|
|
86
|
+
* </tr>
|
|
87
|
+
* <tr>
|
|
88
|
+
* <td rowspan="2" colspan="2">2-1</td>
|
|
89
|
+
* <td>2-2</td>
|
|
90
|
+
* </tr>
|
|
91
|
+
* <tr>
|
|
92
|
+
* <td>3-1</td>
|
|
93
|
+
* </tr>
|
|
94
|
+
* </table>
|
|
95
|
+
*
|
|
96
|
+
* We have a problem though, from the block json, there is no way to tell that the cell "2-1" is the second cell in the second row.
|
|
97
|
+
* To resolve this, we created the occupancy grid, which is a grid of all the cells in the table, as though they were only 1x1 cells.
|
|
98
|
+
* See {@link OccupancyGrid} for more information.
|
|
99
|
+
*
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* Relative cell indices are relative to the table block's content.
|
|
103
|
+
*
|
|
104
|
+
* This is a sparse representation of the table and is how HTML and BlockNote JSON represent tables.
|
|
105
|
+
*
|
|
106
|
+
* For example, if we have a table with a rowspan of 2, the second row may only have 1 element in a 2x2 table.
|
|
107
|
+
*
|
|
108
|
+
* ```
|
|
109
|
+
* // Visual representation of the table
|
|
110
|
+
* | 1-1 | 1-2 | // has 2 cells
|
|
111
|
+
* | 1-1 | 2-2 | // has only 1 cell
|
|
112
|
+
* // Relative cell indices
|
|
113
|
+
* [{ row: 1, col: 1, rowspan: 2 }, { row: 1, col: 2 }] // has 2 cells
|
|
114
|
+
* [{ row: 1, col: 2 }] // has only 1 cell
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export type RelativeCellIndices = {
|
|
118
|
+
row: number;
|
|
119
|
+
col: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Absolute cell indices are relative to the table's layout (it's {@link OccupancyGrid}).
|
|
123
|
+
*
|
|
124
|
+
* It is as though the table is a grid of 1x1 cells, and any colspan or rowspan results in multiple 1x1 cells being occupied.
|
|
125
|
+
*
|
|
126
|
+
* For example, if we have a table with a colspan of 2, it will occupy 2 cells in the layout grid.
|
|
127
|
+
*
|
|
128
|
+
* ```
|
|
129
|
+
* // Visual representation of the table
|
|
130
|
+
* | 1-1 | 1-1 | // has 2 cells
|
|
131
|
+
* | 2-1 | 2-2 | // has 2 cell
|
|
132
|
+
* // Absolute cell indices
|
|
133
|
+
* [{ row: 1, col: 1, colspan: 2 }, { row: 1, col: 2, colspan: 2 }] // has 2 cells
|
|
134
|
+
* [{ row: 1, col: 1 }, { row: 1, col: 2 }] // has 2 cells
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export type AbsoluteCellIndices = {
|
|
138
|
+
row: number;
|
|
139
|
+
col: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* An occupancy grid is a grid of the occupied cells in the table.
|
|
143
|
+
* It is used to track the occupied cells in the table to know where to place the next cell.
|
|
144
|
+
*
|
|
145
|
+
* Since it allows us to resolve cell indices both {@link RelativeCellIndices} and {@link AbsoluteCellIndices}, it is the core data structure for table operations.
|
|
146
|
+
*/
|
|
147
|
+
type OccupancyGrid = (RelativeCellIndices & {
|
|
148
|
+
/**
|
|
149
|
+
* The rowspan of the cell.
|
|
150
|
+
*/
|
|
151
|
+
rowspan: number;
|
|
152
|
+
/**
|
|
153
|
+
* The colspan of the cell.
|
|
154
|
+
*/
|
|
155
|
+
colspan: number;
|
|
156
|
+
/**
|
|
157
|
+
* The cell.
|
|
158
|
+
*/
|
|
159
|
+
cell: TableCell<any, any>;
|
|
160
|
+
})[][];
|
|
161
|
+
/**
|
|
162
|
+
* This will return the {@link OccupancyGrid} of the table.
|
|
163
|
+
* By laying out the table as though it were a grid of 1x1 cells, we can easily track where the cells are located (both relatively and absolutely).
|
|
164
|
+
*
|
|
165
|
+
* @returns an {@link OccupancyGrid}
|
|
166
|
+
*/
|
|
167
|
+
export declare function getTableCellOccupancyGrid(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>): OccupancyGrid;
|
|
168
|
+
/**
|
|
169
|
+
* Given an {@link OccupancyGrid}, this will return the {@link TableContent} rows.
|
|
170
|
+
*
|
|
171
|
+
* @note This will remove duplicates from the occupancy grid. And does no bounds checking for validity of the occupancy grid.
|
|
172
|
+
*/
|
|
173
|
+
export declare function getTableRowsFromOccupancyGrid(occupancyGrid: OccupancyGrid): TableContent<any, any>["rows"];
|
|
174
|
+
/**
|
|
175
|
+
* This will resolve the relative cell indices within the table block to the absolute cell indices within the table, accounting for colspan and rowspan.
|
|
176
|
+
*
|
|
177
|
+
* @note It will return only the first cell (i.e. top-left) that matches the relative cell indices. To find the other absolute cell indices this cell occupies, you can assume it is the rowspan and colspan number of cells away from the top-left cell.
|
|
178
|
+
*
|
|
179
|
+
* @returns The {@link AbsoluteCellIndices} and the {@link TableCell} at the absolute position.
|
|
180
|
+
*/
|
|
181
|
+
export declare function getAbsoluteTableCells(
|
|
182
|
+
/**
|
|
183
|
+
* The relative position of the cell in the table.
|
|
184
|
+
*/
|
|
185
|
+
relativeCellIndices: RelativeCellIndices,
|
|
186
|
+
/**
|
|
187
|
+
* The table block containing the cell.
|
|
188
|
+
*/
|
|
189
|
+
block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
|
|
190
|
+
/**
|
|
191
|
+
* The occupancy grid of the table.
|
|
192
|
+
*/
|
|
193
|
+
occupancyGrid?: OccupancyGrid): AbsoluteCellIndices & {
|
|
194
|
+
cell: TableCell<any, any>;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* This will get the dimensions of the table block.
|
|
198
|
+
*
|
|
199
|
+
* @returns The height and width of the table.
|
|
200
|
+
*/
|
|
201
|
+
export declare function getDimensionsOfTable(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>): {
|
|
202
|
+
/**
|
|
203
|
+
* The number of rows in the table.
|
|
204
|
+
*/
|
|
205
|
+
height: number;
|
|
206
|
+
/**
|
|
207
|
+
* The number of columns in the table.
|
|
208
|
+
*/
|
|
209
|
+
width: number;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* This will resolve the absolute cell indices within the table block to the relative cell indices within the table, accounting for colspan and rowspan.
|
|
213
|
+
*
|
|
214
|
+
* @returns The {@link RelativeCellIndices} and the {@link TableCell} at the relative position.
|
|
215
|
+
*/
|
|
216
|
+
export declare function getRelativeTableCells(
|
|
217
|
+
/**
|
|
218
|
+
* The {@link AbsoluteCellIndices} of the cell in the table.
|
|
219
|
+
*/
|
|
220
|
+
absoluteCellIndices: AbsoluteCellIndices,
|
|
221
|
+
/**
|
|
222
|
+
* The table block containing the cell.
|
|
223
|
+
*/
|
|
224
|
+
block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
|
|
225
|
+
/**
|
|
226
|
+
* The occupancy grid of the table.
|
|
227
|
+
*/
|
|
228
|
+
occupancyGrid?: OccupancyGrid): (RelativeCellIndices & {
|
|
229
|
+
cell: TableContent<any, any>["rows"][number]["cells"][number];
|
|
230
|
+
}) | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* This will get all the cells within a relative row of a table block.
|
|
233
|
+
*
|
|
234
|
+
* This method always starts the search for the row at the first column of the table.
|
|
235
|
+
*
|
|
236
|
+
* ```
|
|
237
|
+
* // Visual representation of a table
|
|
238
|
+
* | A | B | C |
|
|
239
|
+
* | | D | E |
|
|
240
|
+
* | F | G | H |
|
|
241
|
+
* // "A" has a rowspan of 2
|
|
242
|
+
*
|
|
243
|
+
* // getCellsAtRowHandle(0)
|
|
244
|
+
* // returns [
|
|
245
|
+
* { row: 0, col: 0, cell: "A" },
|
|
246
|
+
* { row: 0, col: 1, cell: "B" },
|
|
247
|
+
* { row: 0, col: 2, cell: "C" },
|
|
248
|
+
* ]
|
|
249
|
+
*
|
|
250
|
+
* // getCellsAtColumnHandle(1)
|
|
251
|
+
* // returns [
|
|
252
|
+
* { row: 1, col: 0, cell: "F" },
|
|
253
|
+
* { row: 1, col: 1, cell: "G" },
|
|
254
|
+
* { row: 1, col: 2, cell: "H" },
|
|
255
|
+
* ]
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* As you can see, you may not be able to retrieve all nodes given a relative row index, as cells can span multiple rows.
|
|
259
|
+
*
|
|
260
|
+
* @returns All of the cells associated with the relative row of the table. (All cells that have the same relative row index)
|
|
261
|
+
*/
|
|
262
|
+
export declare function getCellsAtRowHandle(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, relativeRowIndex: RelativeCellIndices["row"]): (RelativeCellIndices & {
|
|
263
|
+
cell: TableCell<any, any>;
|
|
264
|
+
})[];
|
|
265
|
+
/**
|
|
266
|
+
* This will get all the cells within a relative column of a table block.
|
|
267
|
+
*
|
|
268
|
+
* This method always starts the search for the column at the first row of the table.
|
|
269
|
+
*
|
|
270
|
+
* ```
|
|
271
|
+
* // Visual representation of a table
|
|
272
|
+
* | A | B |
|
|
273
|
+
* | C | D | E |
|
|
274
|
+
* | F | G | H |
|
|
275
|
+
* // "A" has a colspan of 2
|
|
276
|
+
*
|
|
277
|
+
* // getCellsAtColumnHandle(0)
|
|
278
|
+
* // returns [
|
|
279
|
+
* { row: 0, col: 0, cell: "A" },
|
|
280
|
+
* { row: 1, col: 0, cell: "C" },
|
|
281
|
+
* { row: 2, col: 0, cell: "F" },
|
|
282
|
+
* ]
|
|
283
|
+
*
|
|
284
|
+
* // getCellsAtColumnHandle(1)
|
|
285
|
+
* // returns [
|
|
286
|
+
* { row: 0, col: 1, cell: "B" },
|
|
287
|
+
* { row: 1, col: 2, cell: "E" },
|
|
288
|
+
* { row: 2, col: 2, cell: "F" },
|
|
289
|
+
* ]
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* As you can see, you may not be able to retrieve all nodes given a relative column index, as cells can span multiple columns.
|
|
293
|
+
*
|
|
294
|
+
* @returns All of the cells associated with the relative column of the table. (All cells that have the same relative column index)
|
|
295
|
+
*/
|
|
296
|
+
export declare function getCellsAtColumnHandle(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, relativeColumnIndex: RelativeCellIndices["col"]): (RelativeCellIndices & {
|
|
297
|
+
cell: TableCell<any, any>;
|
|
298
|
+
})[];
|
|
299
|
+
/**
|
|
300
|
+
* This moves a column from one index to another.
|
|
301
|
+
*
|
|
302
|
+
* @note This is a destructive operation, it will modify the provided {@link OccupancyGrid} in place.
|
|
303
|
+
*/
|
|
304
|
+
export declare function moveColumn(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, fromColIndex: RelativeCellIndices["col"], toColIndex: RelativeCellIndices["col"], occupancyGrid?: OccupancyGrid): TableContent<any, any>["rows"];
|
|
305
|
+
/**
|
|
306
|
+
* This moves a row from one index to another.
|
|
307
|
+
*
|
|
308
|
+
* @note This is a destructive operation, it will modify the {@link OccupancyGrid} in place.
|
|
309
|
+
*/
|
|
310
|
+
export declare function moveRow(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, fromRowIndex: RelativeCellIndices["row"], toRowIndex: RelativeCellIndices["row"], occupancyGrid?: OccupancyGrid): TableContent<any, any>["rows"];
|
|
311
|
+
/**
|
|
312
|
+
* This will remove empty rows or columns from the table.
|
|
313
|
+
*
|
|
314
|
+
* @note This is a destructive operation, it will modify the {@link OccupancyGrid} in place.
|
|
315
|
+
*/
|
|
316
|
+
export declare function cropEmptyRowsOrColumns(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, removeEmpty: "columns" | "rows", occupancyGrid?: OccupancyGrid): TableContent<any, any>["rows"];
|
|
317
|
+
/**
|
|
318
|
+
* This will add a specified number of rows or columns to the table (filling with empty cells).
|
|
319
|
+
*
|
|
320
|
+
* @note This is a destructive operation, it will modify the {@link OccupancyGrid} in place.
|
|
321
|
+
*/
|
|
322
|
+
export declare function addRowsOrColumns(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, addType: "columns" | "rows",
|
|
323
|
+
/**
|
|
324
|
+
* The number of rows or columns to add.
|
|
325
|
+
*
|
|
326
|
+
* @note if negative, it will remove rows or columns.
|
|
327
|
+
*/
|
|
328
|
+
numToAdd: number, occupancyGrid?: OccupancyGrid): TableContent<any, any>["rows"];
|
|
329
|
+
/**
|
|
330
|
+
* Checks if a row can be safely dropped at the target row index without splitting merged cells.
|
|
331
|
+
*/
|
|
332
|
+
export declare function canRowBeDraggedInto(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, draggingIndex: RelativeCellIndices["row"], targetRowIndex: RelativeCellIndices["row"]): boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Checks if a column can be safely dropped at the target column index without splitting merged cells.
|
|
335
|
+
*/
|
|
336
|
+
export declare function canColumnBeDraggedInto(block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, draggingIndex: RelativeCellIndices["col"], targetColumnIndex: RelativeCellIndices["col"]): boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Checks if two cells are in the same column.
|
|
339
|
+
*
|
|
340
|
+
* @returns True if the cells are in the same column, false otherwise.
|
|
341
|
+
*/
|
|
342
|
+
export declare function areInSameColumn(from: RelativeCellIndices, to: RelativeCellIndices, block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>): boolean;
|
|
343
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { EditorView } from "prosemirror-view";
|
|
2
|
+
import type { EditorView } from "prosemirror-view";
|
|
3
3
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
4
4
|
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema/index.js";
|
|
5
5
|
export declare function selectedFragmentToHTML<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(view: EditorView, editor: BlockNoteEditor<BSchema, I, S>): {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Node } from "@tiptap/core";
|
|
2
1
|
export declare const tablePropSchema: {
|
|
3
2
|
textColor: {
|
|
4
3
|
default: "default";
|
|
5
4
|
};
|
|
6
5
|
};
|
|
7
|
-
export declare const TableBlockContent: Node<any, any> & {
|
|
6
|
+
export declare const TableBlockContent: import("@tiptap/core").Node<any, any> & {
|
|
8
7
|
name: "table";
|
|
9
8
|
config: {
|
|
10
9
|
content: "tableRow+";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { CellSelection } from "prosemirror-tables";
|
|
1
2
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
2
3
|
import { BlockFromConfig, BlockSchema, FileBlockConfig, InlineContentSchema, StyleSchema } from "../schema/index.js";
|
|
3
4
|
import { Block, DefaultBlockSchema, DefaultInlineContentSchema } from "./defaultBlocks.js";
|
|
4
5
|
import { defaultProps } from "./defaultProps.js";
|
|
6
|
+
import { Selection } from "prosemirror-state";
|
|
5
7
|
export declare function checkDefaultBlockTypeInSchema<BlockType extends keyof DefaultBlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blockType: BlockType, editor: BlockNoteEditor<any, I, S>): editor is BlockNoteEditor<{
|
|
6
8
|
Type: DefaultBlockSchema[BlockType];
|
|
7
9
|
}, I, S>;
|
|
@@ -30,3 +32,4 @@ export declare function checkBlockHasDefaultProp<Prop extends keyof typeof defau
|
|
|
30
32
|
};
|
|
31
33
|
content: "table" | "inline" | "none";
|
|
32
34
|
}, I, S>;
|
|
35
|
+
export declare function isTableCellSelection(selection: Selection): selection is CellSelection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./models/User.js";
|
|
2
|
+
export * from "./threadstore/DefaultThreadStoreAuth.js";
|
|
3
|
+
export * from "./threadstore/ThreadStore.js";
|
|
4
|
+
export * from "./threadstore/ThreadStoreAuth.js";
|
|
5
|
+
export * from "./threadstore/TipTapThreadStore.js";
|
|
6
|
+
export * from "./threadstore/yjs/RESTYjsThreadStore.js";
|
|
7
|
+
export * from "./threadstore/yjs/YjsThreadStore.js";
|
|
8
|
+
export * from "./threadstore/yjs/YjsThreadStoreBase.js";
|
|
9
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CommentData, ThreadData } from "../types.js";
|
|
2
|
+
import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
|
|
3
|
+
export declare class DefaultThreadStoreAuth extends ThreadStoreAuth {
|
|
4
|
+
private readonly userId;
|
|
5
|
+
private readonly role;
|
|
6
|
+
constructor(userId: string, role: "comment" | "editor");
|
|
7
|
+
/**
|
|
8
|
+
* Auth: should be possible by anyone with comment access
|
|
9
|
+
*/
|
|
10
|
+
canCreateThread(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Auth: should be possible by anyone with comment access
|
|
13
|
+
*/
|
|
14
|
+
canAddComment(_thread: ThreadData): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Auth: should only be possible by the comment author
|
|
17
|
+
*/
|
|
18
|
+
canUpdateComment(comment: CommentData): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Auth: should be possible by the comment author OR an editor of the document
|
|
21
|
+
*/
|
|
22
|
+
canDeleteComment(comment: CommentData): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Auth: should only be possible by an editor of the document
|
|
25
|
+
*/
|
|
26
|
+
canDeleteThread(_thread: ThreadData): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Auth: should be possible by anyone with comment access
|
|
29
|
+
*/
|
|
30
|
+
canResolveThread(_thread: ThreadData): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Auth: should be possible by anyone with comment access
|
|
33
|
+
*/
|
|
34
|
+
canUnresolveThread(_thread: ThreadData): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Auth: should be possible by anyone with comment access
|
|
37
|
+
*
|
|
38
|
+
* Note: will also check if the user has already reacted with the same emoji. TBD: is that a nice design or should this responsibility be outside of auth?
|
|
39
|
+
*/
|
|
40
|
+
canAddReaction(comment: CommentData, emoji?: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Auth: should be possible by anyone with comment access
|
|
43
|
+
*
|
|
44
|
+
* Note: will also check if the user has already reacted with the same emoji. TBD: is that a nice design or should this responsibility be outside of auth?
|
|
45
|
+
*/
|
|
46
|
+
canDeleteReaction(comment: CommentData, emoji?: string): boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { CommentBody, CommentData, ThreadData } from "../types.js";
|
|
2
|
+
import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
|
|
3
|
+
/**
|
|
4
|
+
* ThreadStore is an abstract class that defines the interface
|
|
5
|
+
* to read / add / update / delete threads and comments.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class ThreadStore {
|
|
8
|
+
readonly auth: ThreadStoreAuth;
|
|
9
|
+
constructor(auth: ThreadStoreAuth);
|
|
10
|
+
/**
|
|
11
|
+
* A "thread" in the ThreadStore only contains information about the content
|
|
12
|
+
* of the thread / comments. It does not contain information about the position.
|
|
13
|
+
*
|
|
14
|
+
* This function can be implemented to store the thread in the document (by creating a mark)
|
|
15
|
+
* If not implemented, default behavior will apply (creating the mark via TipTap)
|
|
16
|
+
* See CommentsPlugin.ts for more details.
|
|
17
|
+
*/
|
|
18
|
+
abstract addThreadToDocument?(options: {
|
|
19
|
+
threadId: string;
|
|
20
|
+
selection: {
|
|
21
|
+
prosemirror: {
|
|
22
|
+
head: number;
|
|
23
|
+
anchor: number;
|
|
24
|
+
};
|
|
25
|
+
yjs: {
|
|
26
|
+
head: any;
|
|
27
|
+
anchor: any;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new thread with an initial comment.
|
|
33
|
+
*/
|
|
34
|
+
abstract createThread(options: {
|
|
35
|
+
initialComment: {
|
|
36
|
+
body: CommentBody;
|
|
37
|
+
metadata?: any;
|
|
38
|
+
};
|
|
39
|
+
metadata?: any;
|
|
40
|
+
}): Promise<ThreadData>;
|
|
41
|
+
/**
|
|
42
|
+
* Adds a comment to a thread.
|
|
43
|
+
*/
|
|
44
|
+
abstract addComment(options: {
|
|
45
|
+
comment: {
|
|
46
|
+
body: CommentBody;
|
|
47
|
+
metadata?: any;
|
|
48
|
+
};
|
|
49
|
+
threadId: string;
|
|
50
|
+
}): Promise<CommentData>;
|
|
51
|
+
/**
|
|
52
|
+
* Updates a comment in a thread.
|
|
53
|
+
*/
|
|
54
|
+
abstract updateComment(options: {
|
|
55
|
+
comment: {
|
|
56
|
+
body: CommentBody;
|
|
57
|
+
metadata?: any;
|
|
58
|
+
};
|
|
59
|
+
threadId: string;
|
|
60
|
+
commentId: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Deletes a comment from a thread.
|
|
64
|
+
*/
|
|
65
|
+
abstract deleteComment(options: {
|
|
66
|
+
threadId: string;
|
|
67
|
+
commentId: string;
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Deletes a thread.
|
|
71
|
+
*/
|
|
72
|
+
abstract deleteThread(options: {
|
|
73
|
+
threadId: string;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Marks a thread as resolved.
|
|
77
|
+
*/
|
|
78
|
+
abstract resolveThread(options: {
|
|
79
|
+
threadId: string;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Marks a thread as unresolved.
|
|
83
|
+
*/
|
|
84
|
+
abstract unresolveThread(options: {
|
|
85
|
+
threadId: string;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Adds a reaction to a comment.
|
|
89
|
+
*
|
|
90
|
+
* Auth: should be possible by anyone with comment access
|
|
91
|
+
*/
|
|
92
|
+
abstract addReaction(options: {
|
|
93
|
+
threadId: string;
|
|
94
|
+
commentId: string;
|
|
95
|
+
emoji: string;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Deletes a reaction from a comment.
|
|
99
|
+
*
|
|
100
|
+
* Auth: should be possible by the reaction author
|
|
101
|
+
*/
|
|
102
|
+
abstract deleteReaction(options: {
|
|
103
|
+
threadId: string;
|
|
104
|
+
commentId: string;
|
|
105
|
+
emoji: string;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieve data for a specific thread.
|
|
109
|
+
*/
|
|
110
|
+
abstract getThread(threadId: string): ThreadData;
|
|
111
|
+
/**
|
|
112
|
+
* Retrieve all threads.
|
|
113
|
+
*/
|
|
114
|
+
abstract getThreads(): Map<string, ThreadData>;
|
|
115
|
+
/**
|
|
116
|
+
* Subscribe to changes in the thread store.
|
|
117
|
+
*
|
|
118
|
+
* @returns a function to unsubscribe from the thread store
|
|
119
|
+
*/
|
|
120
|
+
abstract subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void;
|
|
121
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommentData, ThreadData } from "../types.js";
|
|
2
|
+
export declare abstract class ThreadStoreAuth {
|
|
3
|
+
abstract canCreateThread(): boolean;
|
|
4
|
+
abstract canAddComment(thread: ThreadData): boolean;
|
|
5
|
+
abstract canUpdateComment(comment: CommentData): boolean;
|
|
6
|
+
abstract canDeleteComment(comment: CommentData): boolean;
|
|
7
|
+
abstract canDeleteThread(thread: ThreadData): boolean;
|
|
8
|
+
abstract canResolveThread(thread: ThreadData): boolean;
|
|
9
|
+
abstract canUnresolveThread(thread: ThreadData): boolean;
|
|
10
|
+
abstract canAddReaction(comment: CommentData, emoji?: string): boolean;
|
|
11
|
+
abstract canDeleteReaction(comment: CommentData, emoji?: string): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { TiptapCollabProvider } from "@hocuspocus/provider";
|
|
2
|
+
import { CommentBody, ThreadData } from "../types.js";
|
|
3
|
+
import { ThreadStore } from "./ThreadStore.js";
|
|
4
|
+
import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `TiptapThreadStore` integrates with Tiptap's collaboration provider for comment management.
|
|
7
|
+
* You can pass a `TiptapCollabProvider` to the constructor which takes care of storing the comments.
|
|
8
|
+
*
|
|
9
|
+
* Under the hood, this actually works similarly to the `YjsThreadStore` implementation. (comments are stored in the Yjs document)
|
|
10
|
+
*/
|
|
11
|
+
export declare class TiptapThreadStore extends ThreadStore {
|
|
12
|
+
private readonly userId;
|
|
13
|
+
private readonly provider;
|
|
14
|
+
constructor(userId: string, provider: TiptapCollabProvider, auth: ThreadStoreAuth);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new thread with an initial comment.
|
|
17
|
+
*/
|
|
18
|
+
createThread(options: {
|
|
19
|
+
initialComment: {
|
|
20
|
+
body: CommentBody;
|
|
21
|
+
metadata?: any;
|
|
22
|
+
};
|
|
23
|
+
metadata?: any;
|
|
24
|
+
}): Promise<ThreadData>;
|
|
25
|
+
addThreadToDocument: undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Adds a comment to a thread.
|
|
28
|
+
*/
|
|
29
|
+
addComment(options: {
|
|
30
|
+
comment: {
|
|
31
|
+
body: CommentBody;
|
|
32
|
+
metadata?: any;
|
|
33
|
+
};
|
|
34
|
+
threadId: string;
|
|
35
|
+
}): Promise<CommentBody>;
|
|
36
|
+
/**
|
|
37
|
+
* Updates a comment in a thread.
|
|
38
|
+
*/
|
|
39
|
+
updateComment(options: {
|
|
40
|
+
comment: {
|
|
41
|
+
body: CommentBody;
|
|
42
|
+
metadata?: any;
|
|
43
|
+
};
|
|
44
|
+
threadId: string;
|
|
45
|
+
commentId: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
private tiptapCommentToCommentData;
|
|
48
|
+
private tiptapThreadToThreadData;
|
|
49
|
+
/**
|
|
50
|
+
* Deletes a comment from a thread.
|
|
51
|
+
*/
|
|
52
|
+
deleteComment(options: {
|
|
53
|
+
threadId: string;
|
|
54
|
+
commentId: string;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Deletes a thread.
|
|
58
|
+
*/
|
|
59
|
+
deleteThread(options: {
|
|
60
|
+
threadId: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Marks a thread as resolved.
|
|
64
|
+
*/
|
|
65
|
+
resolveThread(options: {
|
|
66
|
+
threadId: string;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Marks a thread as unresolved.
|
|
70
|
+
*/
|
|
71
|
+
unresolveThread(options: {
|
|
72
|
+
threadId: string;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Adds a reaction to a comment.
|
|
76
|
+
*
|
|
77
|
+
* Auth: should be possible by anyone with comment access
|
|
78
|
+
*/
|
|
79
|
+
addReaction(options: {
|
|
80
|
+
threadId: string;
|
|
81
|
+
commentId: string;
|
|
82
|
+
emoji: string;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes a reaction from a comment.
|
|
86
|
+
*
|
|
87
|
+
* Auth: should be possible by the reaction author
|
|
88
|
+
*/
|
|
89
|
+
deleteReaction(options: {
|
|
90
|
+
threadId: string;
|
|
91
|
+
commentId: string;
|
|
92
|
+
emoji: string;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
getThread(threadId: string): ThreadData;
|
|
95
|
+
getThreads(): Map<string, ThreadData>;
|
|
96
|
+
subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void;
|
|
97
|
+
}
|