@nerd-bible/wordgard 0.6.2-beta7 → 0.6.2-beta9
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/collab.js +3 -0
- package/dist/command.js +6 -2
- package/dist/doc.d.ts +13 -2
- package/dist/doc.js +40 -18
- package/dist/editor.d.ts +16 -4
- package/dist/editor.js +188 -95
- package/dist/history.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/phrases.js +1 -0
- package/dist/schema.js +11 -8
- package/dist/set.js +11 -7
- package/dist/state.d.ts +49 -4
- package/dist/state.js +90 -31
- package/dist/table.d.ts +111 -1
- package/dist/table.js +32 -22
- package/package.json +1 -1
package/dist/table.d.ts
CHANGED
|
@@ -175,6 +175,116 @@ declare class CellSelection extends GardSelection {
|
|
|
175
175
|
static extension: GardState.Extension;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
A table map describes the structore of a given table.
|
|
180
|
+
*/
|
|
181
|
+
declare class TableMap {
|
|
182
|
+
/**
|
|
183
|
+
The start position of the table's content.
|
|
184
|
+
*/
|
|
185
|
+
readonly start: number;
|
|
186
|
+
/**
|
|
187
|
+
Get a table map for the given table node. Will reuse known
|
|
188
|
+
structure of unchanged tables across document changes.
|
|
189
|
+
*/
|
|
190
|
+
static get(table: Plot, start: number): TableMap;
|
|
191
|
+
private constructor();
|
|
192
|
+
/**
|
|
193
|
+
The number of columns in this table.
|
|
194
|
+
*/
|
|
195
|
+
get width(): number;
|
|
196
|
+
/**
|
|
197
|
+
The number of rows in the table.
|
|
198
|
+
*/
|
|
199
|
+
get height(): number;
|
|
200
|
+
/**
|
|
201
|
+
The table plot.
|
|
202
|
+
*/
|
|
203
|
+
get table(): Plot;
|
|
204
|
+
/**
|
|
205
|
+
The document position before the table.
|
|
206
|
+
*/
|
|
207
|
+
get tablePos(): number;
|
|
208
|
+
/**
|
|
209
|
+
Find the dimensions of the cell at the given position.
|
|
210
|
+
*/
|
|
211
|
+
cellRect(pos: number): TableMap.Rect;
|
|
212
|
+
/**
|
|
213
|
+
Find the end position of the given cell.
|
|
214
|
+
*/
|
|
215
|
+
cellEnd(pos: number): number;
|
|
216
|
+
/**
|
|
217
|
+
Get the rectangle spanning the two given cells.
|
|
218
|
+
*/
|
|
219
|
+
rectBetween(a: number, b: number): TableMap.Rect;
|
|
220
|
+
/**
|
|
221
|
+
Return the position of all cells that have their top start
|
|
222
|
+
corner in the given rectangle.
|
|
223
|
+
*/
|
|
224
|
+
cellsInRect(rect: TableMap.Rect): number[];
|
|
225
|
+
/**
|
|
226
|
+
Return the position of the cell that occupies the position at the
|
|
227
|
+
given row and column (which must be in bounds for the table).
|
|
228
|
+
*/
|
|
229
|
+
cellAt(col: number, row: number): number | null;
|
|
230
|
+
/**
|
|
231
|
+
Get the position at the start of the given row (which may be
|
|
232
|
+
`width` to query the position after the last row).
|
|
233
|
+
*/
|
|
234
|
+
rowPos(row: number): number;
|
|
235
|
+
/**
|
|
236
|
+
Get the position where a cell would have to be inserted to
|
|
237
|
+
appear at the given column and row.
|
|
238
|
+
*/
|
|
239
|
+
cellInsertionPos(col: number, row: number): number;
|
|
240
|
+
/**
|
|
241
|
+
Get the node for the cell at the given position.
|
|
242
|
+
*/
|
|
243
|
+
getCell(pos: number): Plot;
|
|
244
|
+
}
|
|
245
|
+
declare namespace TableMap {
|
|
246
|
+
/**
|
|
247
|
+
Data type used for a rectangular area in a table.
|
|
248
|
+
*/
|
|
249
|
+
class Rect {
|
|
250
|
+
/**
|
|
251
|
+
Starting column of the rectangle.
|
|
252
|
+
*/
|
|
253
|
+
readonly startCol: number;
|
|
254
|
+
/**
|
|
255
|
+
Starting row.
|
|
256
|
+
*/
|
|
257
|
+
readonly startRow: number;
|
|
258
|
+
/**
|
|
259
|
+
The end column. Non-inclusive. Always higher than
|
|
260
|
+
`startCol`.
|
|
261
|
+
*/
|
|
262
|
+
readonly endCol: number;
|
|
263
|
+
/**
|
|
264
|
+
The end row. Non-inclusive. Always higher than `startRow`.
|
|
265
|
+
*/
|
|
266
|
+
readonly endRow: number;
|
|
267
|
+
constructor(
|
|
268
|
+
/**
|
|
269
|
+
Starting column of the rectangle.
|
|
270
|
+
*/
|
|
271
|
+
startCol: number,
|
|
272
|
+
/**
|
|
273
|
+
Starting row.
|
|
274
|
+
*/
|
|
275
|
+
startRow: number,
|
|
276
|
+
/**
|
|
277
|
+
The end column. Non-inclusive. Always higher than
|
|
278
|
+
`startCol`.
|
|
279
|
+
*/
|
|
280
|
+
endCol: number,
|
|
281
|
+
/**
|
|
282
|
+
The end row. Non-inclusive. Always higher than `startRow`.
|
|
283
|
+
*/
|
|
284
|
+
endRow: number);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
178
288
|
declare const toggleHeaderCell: Command.Pure;
|
|
179
289
|
/**
|
|
180
290
|
Add a column at the given side of the selection. The selection may
|
|
@@ -213,4 +323,4 @@ declare const splitCell: Command.Pure;
|
|
|
213
323
|
*/
|
|
214
324
|
declare function handleTablePaste(state: GardState, slice: Slice, drop?: number): false | Transaction.Spec;
|
|
215
325
|
|
|
216
|
-
export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
|
326
|
+
export { CellSelection, TableMap, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
package/dist/table.js
CHANGED
|
@@ -5,18 +5,6 @@ import { Node, Slice, ValidationError, Token, ChangeSet } from 'wordgard/doc';
|
|
|
5
5
|
import { Command, moveByUnit, moveByWord, moveByLine, moveToLineSide, Menu } from 'wordgard/command';
|
|
6
6
|
import { tablePhrases } from 'wordgard/phrases';
|
|
7
7
|
|
|
8
|
-
class Rect {
|
|
9
|
-
startCol;
|
|
10
|
-
startRow;
|
|
11
|
-
endCol;
|
|
12
|
-
endRow;
|
|
13
|
-
constructor(startCol, startRow, endCol, endRow) {
|
|
14
|
-
this.startCol = startCol;
|
|
15
|
-
this.startRow = startRow;
|
|
16
|
-
this.endCol = endCol;
|
|
17
|
-
this.endRow = endRow;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
8
|
class MapData {
|
|
21
9
|
table;
|
|
22
10
|
width;
|
|
@@ -37,7 +25,15 @@ let cache = /*@__PURE__*/(() => new WeakMap())();
|
|
|
37
25
|
class TableMap {
|
|
38
26
|
start;
|
|
39
27
|
data;
|
|
40
|
-
|
|
28
|
+
static get(table, start) {
|
|
29
|
+
let data = cache.get(table);
|
|
30
|
+
if (!data)
|
|
31
|
+
cache.set(table, data = computeMap(table));
|
|
32
|
+
return new TableMap(start, data);
|
|
33
|
+
}
|
|
34
|
+
constructor(
|
|
35
|
+
start,
|
|
36
|
+
data) {
|
|
41
37
|
this.start = start;
|
|
42
38
|
this.data = data;
|
|
43
39
|
}
|
|
@@ -55,7 +51,7 @@ class TableMap {
|
|
|
55
51
|
endCol++;
|
|
56
52
|
for (let j = 1; endRow < height && map[i + (width * j)] == localPos; j++)
|
|
57
53
|
endRow++;
|
|
58
|
-
return new Rect(startCol, startRow, endCol, endRow);
|
|
54
|
+
return new TableMap.Rect(startCol, startRow, endCol, endRow);
|
|
59
55
|
}
|
|
60
56
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
61
57
|
}
|
|
@@ -87,7 +83,7 @@ class TableMap {
|
|
|
87
83
|
rectBetween(a, b) {
|
|
88
84
|
let { startCol: startColA, endCol: endColA, startRow: startRowA, endRow: endRowA } = this.cellRect(a);
|
|
89
85
|
let { startCol: startColB, endCol: endColB, startRow: startRowB, endRow: endRowB } = this.cellRect(b);
|
|
90
|
-
return new Rect(Math.min(startColA, startColB), Math.min(startRowA, startRowB), Math.max(endColA, endColB), Math.max(endRowA, endRowB));
|
|
86
|
+
return new TableMap.Rect(Math.min(startColA, startColB), Math.min(startRowA, startRowB), Math.max(endColA, endColB), Math.max(endRowA, endRowB));
|
|
91
87
|
}
|
|
92
88
|
cellsInRect(rect) {
|
|
93
89
|
let result = [], { map, width } = this.data;
|
|
@@ -148,13 +144,26 @@ class TableMap {
|
|
|
148
144
|
}
|
|
149
145
|
return false;
|
|
150
146
|
}
|
|
151
|
-
static get(table, start) {
|
|
152
|
-
let data = cache.get(table);
|
|
153
|
-
if (!data)
|
|
154
|
-
cache.set(table, data = computeMap(table));
|
|
155
|
-
return new TableMap(start, data);
|
|
156
|
-
}
|
|
157
147
|
}
|
|
148
|
+
;TableMap = /*@__PURE__*/(function (TableMap) {
|
|
149
|
+
class Rect {
|
|
150
|
+
startCol;
|
|
151
|
+
startRow;
|
|
152
|
+
endCol;
|
|
153
|
+
endRow;
|
|
154
|
+
constructor(
|
|
155
|
+
startCol,
|
|
156
|
+
startRow,
|
|
157
|
+
endCol,
|
|
158
|
+
endRow) {
|
|
159
|
+
this.startCol = startCol;
|
|
160
|
+
this.startRow = startRow;
|
|
161
|
+
this.endCol = endCol;
|
|
162
|
+
this.endRow = endRow;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
TableMap.Rect = Rect;
|
|
166
|
+
;return TableMap})(TableMap);
|
|
158
167
|
function sameCell(a, b) {
|
|
159
168
|
return a != 0 && a == b;
|
|
160
169
|
}
|
|
@@ -227,6 +236,7 @@ function growMap(map, width, height, count) {
|
|
|
227
236
|
}
|
|
228
237
|
|
|
229
238
|
const cellSelectionDeco = /*@__PURE__*/GardState.Field.define({
|
|
239
|
+
name: "cellSelectionDeco",
|
|
230
240
|
create: getCellDeco,
|
|
231
241
|
update: (deco, tr) => {
|
|
232
242
|
return tr.docChanged || tr.selection ? getCellDeco(tr.state) : deco;
|
|
@@ -1318,4 +1328,4 @@ function tables(config = {}) {
|
|
|
1318
1328
|
tables.dropHandler = tableDropHandler;
|
|
1319
1329
|
;return tables})(tables);
|
|
1320
1330
|
|
|
1321
|
-
export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
|
1331
|
+
export { CellSelection, TableMap, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|