@nerd-bible/wordgard 0.3.3

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.
@@ -0,0 +1,215 @@
1
+ import * as wordgard_state from 'wordgard/state';
2
+ import { GardState, GardSelection, Transaction } from 'wordgard/state';
3
+ import { Menu, Command } from 'wordgard/command';
4
+ import { ChangeSet, Plot, Slice } from 'wordgard/doc';
5
+
6
+ /**
7
+ Enable table support with the given configuration. The returned
8
+ extension will include the necessary schema elements, the {@link
9
+ CellSelection cell selection}, {@link tables.correction correction},
10
+ {@link tables.pasteHandler paste} and {@link tables.dropHandler
11
+ drop} handlers, and {@link tableMenu menu items}.
12
+ */
13
+ declare function tables(config?: tables.Spec): GardState.Extension;
14
+ declare namespace tables {
15
+ /**
16
+ Configuration options for the {@link tables} function.
17
+ */
18
+ type Spec = {
19
+ /**
20
+ Controls whether headers cells are enabled. Defaults to true.
21
+ */
22
+ headerCells?: boolean;
23
+ /**
24
+ By default, cells can be {@link mergeCells merged}, making
25
+ them span more than one row or column. Set this to false to
26
+ disable that.
27
+ */
28
+ cellSpanning?: boolean;
29
+ /**
30
+ Determines whether cells contain inline content or block
31
+ content. Defaults to `"inline"`.
32
+ */
33
+ cellContent?: "inline" | "block";
34
+ };
35
+ /**
36
+ Correct tables where the cells do not form a proper rectangle.
37
+ */
38
+ const correction: wordgard_state.Correction;
39
+ /**
40
+ A paste handler that makes pasting into tables fill the entire
41
+ cell selection or, if table cell content is being pasted into a
42
+ cell, to expand the pasted region over the shape covered by the
43
+ pasted content.
44
+ */
45
+ const pasteHandler: GardState.Extension;
46
+ /**
47
+ A drop handler that overrides drops that move table cells.
48
+ */
49
+ const dropHandler: GardState.Extension;
50
+ }
51
+
52
+ /**
53
+ Returns the full table menu. This consists of two buttons that
54
+ look the same but behave differently. When the selection is not in
55
+ a table, {@link tableMenu.createTable} is shown, which provides an
56
+ interface for creating a new table. Otherwise, {@link
57
+ tableMenu.modifyTable} is visible, which contains menu items for
58
+ manipulating the current table.
59
+ */
60
+ declare function tableMenu(): GardState.Extension;
61
+ declare namespace tableMenu {
62
+ /**
63
+ A menu button that expands into a dimension picker when
64
+ activated, which inserts a table with the given dimensions when
65
+ confirmed.
66
+ */
67
+ const createTable: Menu.Submenu;
68
+ /**
69
+ A submenu with for table manipulation items.
70
+ */
71
+ const modifyTable: Menu.Submenu;
72
+ /**
73
+ A button that toggles the selected cells between header and
74
+ normal cells.
75
+ */
76
+ const toggleHeader: Menu.Button;
77
+ /**
78
+ Adds a row above the selected cell(s).
79
+ */
80
+ const addRowAbove: Menu.Button;
81
+ /**
82
+ Adds a row below the selected cell(s).
83
+ */
84
+ const addRowBelow: Menu.Button;
85
+ /**
86
+ Deletes the row(s) that hold the selection.
87
+ */
88
+ const deleteRow: Menu.Button;
89
+ /**
90
+ Button to insert a column before the selection.
91
+ */
92
+ const addColumnBefore: Menu.Button;
93
+ /**
94
+ Add a column after the selection.
95
+ */
96
+ const addColumnAfter: Menu.Button;
97
+ /**
98
+ Delete the selected column(s).
99
+ */
100
+ const deleteColumn: Menu.Button;
101
+ /**
102
+ When multiple cells are selected, merge them into a single cell.
103
+ */
104
+ const mergeCells: Menu.Button;
105
+ /**
106
+ When a merged cell is selected, split it into its smallest
107
+ elements again.
108
+ */
109
+ const splitCell: Menu.Button;
110
+ }
111
+
112
+ /**
113
+ A cell selection is a custom selection type that, instead of
114
+ spanning the range between two document positions, spans the
115
+ rectangle between two cells in the same table. It comes with
116
+ extensions that make sure it is drawn in a recognizeable way,
117
+ automatically created when a selection crosses cell boundaries,
118
+ and adjusted appropriately in response to keyboard and mouse
119
+ actions.
120
+ */
121
+ declare class CellSelection extends GardSelection {
122
+ /**
123
+ The position directly in front of the cell that acts as this
124
+ selection's anchor.
125
+ */
126
+ readonly anchorCell: number;
127
+ /**
128
+ The position directly in front of the cell acting as the
129
+ selection head.
130
+ */
131
+ readonly headCell: number;
132
+ private constructor();
133
+ get ranges(): readonly {
134
+ from: number;
135
+ to: number;
136
+ }[];
137
+ get replacementRange(): {
138
+ from: number;
139
+ to: number;
140
+ };
141
+ get domSelection(): {
142
+ readonly anchor: number;
143
+ readonly anchorSide: 1;
144
+ readonly head: number;
145
+ readonly headSide: -1;
146
+ };
147
+ eq(other: GardSelection): boolean;
148
+ map(changes: ChangeSet, cx: GardSelection.Context, assoc?: -1 | 1): GardSelection.Text | CellSelection;
149
+ /**
150
+ Move the head cell in the given direction, returning a new cell
151
+ selection if the selection can be extended that way.
152
+ */
153
+ moveHead(doc: Plot.Doc, dir: "up" | "down" | "forward" | "backward"): CellSelection | null;
154
+ /**
155
+ Create a table selection between the given points. They should
156
+ point before and after the first and last cell of the selection
157
+ (`anchor` may be before or after `head`, as long as the lower
158
+ sits before a cell and the higher after a cell). Returns `null`
159
+ if the given range does not wrap a range of cells in a single
160
+ table.
161
+ */
162
+ static between(doc: Plot.Doc, anchor: number, head: number): CellSelection | null;
163
+ /**
164
+ Given a selection, this returns null if that selection is valid
165
+ (is a cell selection, or a selection that starts and ends outside
166
+ of tables, or in the same table cell). Otherwise, it will expand a
167
+ selection within a single table to a cell selection, or expand a
168
+ selection that crosses table boundaries to cover the entire table(s).
169
+ */
170
+ static normalize(sel: GardSelection, doc: Plot.Doc): GardSelection | null;
171
+ /**
172
+ This object can be used as an extension to enable cell selection.
173
+ */
174
+ static extension: GardState.Extension;
175
+ }
176
+
177
+ declare const toggleHeaderCell: Command.Pure;
178
+ /**
179
+ Add a column at the given side of the selection. The selection may
180
+ either be a cell selection or another type of selection inside a
181
+ table cell.
182
+ */
183
+ declare const addColumn: Command.Pure<"before" | "after">;
184
+ /**
185
+ Delete the selected columns. Will act on a cell selection or
186
+ another type of selection inside a cell.
187
+ */
188
+ declare const deleteColumn: Command.Pure;
189
+ /**
190
+ Add a row next to the selected cells, on the side indicated.
191
+ */
192
+ declare const addRow: Command.Pure<"before" | "after">;
193
+ /**
194
+ Delete the selected row(s).
195
+ */
196
+ declare const deleteRow: Command.Pure;
197
+ /**
198
+ If the current selection is a multi-cell cell selection, merge the
199
+ cells into a single cell by giving it a {@link types.RowSpan}
200
+ and/or {@link types.ColSpan}. The content from the cells is all
201
+ put into the resulting merged cell.
202
+ */
203
+ declare const mergeCells: Command.Pure;
204
+ /**
205
+ When the selection is in or on a merged cell, split it again. Any
206
+ content is left in the first split-off cell.
207
+ */
208
+ declare const splitCell: Command.Pure;
209
+
210
+ /**
211
+ @hidden exported for testing
212
+ */
213
+ declare function handleTablePaste(state: GardState, slice: Slice, context: readonly Plot.Tag[], drop?: number): false | Transaction.Spec;
214
+
215
+ export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };