@lofcz/platejs-table 52.0.11
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/LICENSE +24 -0
- package/README.md +11 -0
- package/dist/constants-B6Sm9BNa.js +2536 -0
- package/dist/constants-B6Sm9BNa.js.map +1 -0
- package/dist/index-CbSGuAlP.d.ts +638 -0
- package/dist/index-CbSGuAlP.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +157 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +879 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
import { B as getTableOverriddenColSizes, Q as isSelectedCellBorder, V as getTableGridAbove, Y as getTableCellBorders, Z as getSelectedCellsBorders, _ as setTableMarginLeft, a as BaseTableRowPlugin, dt as getColSpan, g as setTableRowSize, i as BaseTablePlugin, j as isTableRectangular, lt as getCellIndices, n as BaseTableCellHeaderPlugin, nt as getSelectedCellsBoundingBox, ot as getLeftTableCell, r as BaseTableCellPlugin, rt as getRowSpan, st as getCellTypes, t as KEY_SHIFT_EDGES, tt as getTopTableCell, ut as computeCellIndices, v as setTableColSize, x as moveSelectionFromCell, y as setBorderSize } from "../constants-B6Sm9BNa.js";
|
|
2
|
+
import { Hotkeys, KEYS, PathApi } from "platejs";
|
|
3
|
+
import { atom, createAtomStore, toPlatePlugin, useEditorPlugin, useEditorRef, useEditorSelection, useEditorSelector, useElement, useElementSelector, usePluginOption, useReadOnly, useSelected } from "platejs/react";
|
|
4
|
+
import { c } from "react-compiler-runtime";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { resizeLengthClampStatic } from "@platejs/resizable";
|
|
7
|
+
|
|
8
|
+
//#region src/react/onKeyDownTable.ts
|
|
9
|
+
const onKeyDownTable = ({ editor, event }) => {
|
|
10
|
+
if (event.defaultPrevented) return;
|
|
11
|
+
if (event.which === 229 && editor.selection && editor.api.isExpanded()) {
|
|
12
|
+
if (Array.from(editor.api.nodes({
|
|
13
|
+
at: editor.selection,
|
|
14
|
+
match: { type: getCellTypes(editor) }
|
|
15
|
+
})).length > 1) {
|
|
16
|
+
editor.tf.collapse({ edge: "end" });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const isKeyDown = {
|
|
21
|
+
"shift+down": Hotkeys.isExtendDownward(event),
|
|
22
|
+
"shift+left": Hotkeys.isExtendBackward(event),
|
|
23
|
+
"shift+right": Hotkeys.isExtendForward(event),
|
|
24
|
+
"shift+up": Hotkeys.isExtendUpward(event)
|
|
25
|
+
};
|
|
26
|
+
Object.keys(isKeyDown).forEach((key) => {
|
|
27
|
+
if (isKeyDown[key] && moveSelectionFromCell(editor, {
|
|
28
|
+
edge: KEY_SHIFT_EDGES[key],
|
|
29
|
+
reverse: key === "shift+up"
|
|
30
|
+
})) {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/react/TablePlugin.tsx
|
|
39
|
+
const TableRowPlugin = toPlatePlugin(BaseTableRowPlugin);
|
|
40
|
+
const TableCellPlugin = toPlatePlugin(BaseTableCellPlugin);
|
|
41
|
+
const TableCellHeaderPlugin = toPlatePlugin(BaseTableCellHeaderPlugin);
|
|
42
|
+
/** Enables support for tables with React-specific features. */
|
|
43
|
+
const TablePlugin = toPlatePlugin(BaseTablePlugin, {
|
|
44
|
+
handlers: { onKeyDown: onKeyDownTable },
|
|
45
|
+
plugins: [
|
|
46
|
+
TableRowPlugin,
|
|
47
|
+
TableCellPlugin,
|
|
48
|
+
TableCellHeaderPlugin
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/react/components/TableCellElement/getOnSelectTableBorderFactory.ts
|
|
54
|
+
/** Helper: sets one cell's specific border(s) to `size`. */
|
|
55
|
+
function setCellBorderSize(editor, cell, directions, size) {
|
|
56
|
+
const at = editor.api.findPath(cell);
|
|
57
|
+
if (!at) return;
|
|
58
|
+
if (directions === "all") setBorderSize(editor, size, {
|
|
59
|
+
at,
|
|
60
|
+
border: "all"
|
|
61
|
+
});
|
|
62
|
+
else for (const dir of directions) setBorderSize(editor, size, {
|
|
63
|
+
at,
|
|
64
|
+
border: dir
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Toggle logic for `'none'`, `'outer'`, `'top'|'bottom'|'left'|'right'`.
|
|
69
|
+
* `'none'` toggles no borders ↔ all borders, `'outer'` toggles the bounding
|
|
70
|
+
* rectangle's outer edges on/off, `'top'|'bottom'|'left'|'right'` toggles only
|
|
71
|
+
* that side of the bounding rect.
|
|
72
|
+
*/
|
|
73
|
+
function setSelectedCellsBorder(editor, { border, cells }) {
|
|
74
|
+
if (cells.length === 0) return;
|
|
75
|
+
if (border === "none") {
|
|
76
|
+
const { none: allNone } = getSelectedCellsBorders(editor, cells);
|
|
77
|
+
const newSize$1 = allNone ? 1 : 0;
|
|
78
|
+
for (const cell of cells) {
|
|
79
|
+
const cellPath = editor.api.findPath(cell);
|
|
80
|
+
if (!cellPath) continue;
|
|
81
|
+
const { col, row } = getCellIndices(editor, cell);
|
|
82
|
+
const edges = [];
|
|
83
|
+
if (row === 0) edges.push("top");
|
|
84
|
+
if (col === 0) edges.push("left");
|
|
85
|
+
edges.push("bottom", "right");
|
|
86
|
+
if (row > 0) {
|
|
87
|
+
const cellAboveEntry = getTopTableCell(editor, { at: cellPath });
|
|
88
|
+
if (cellAboveEntry) {
|
|
89
|
+
const [cellAbove] = cellAboveEntry;
|
|
90
|
+
setCellBorderSize(editor, cellAbove, ["bottom"], newSize$1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (col > 0) {
|
|
94
|
+
const prevCellEntry = getLeftTableCell(editor, { at: cellPath });
|
|
95
|
+
if (prevCellEntry) {
|
|
96
|
+
const [prevCell] = prevCellEntry;
|
|
97
|
+
setCellBorderSize(editor, prevCell, ["right"], newSize$1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (edges.length > 0) setCellBorderSize(editor, cell, edges, newSize$1);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (border === "outer") {
|
|
105
|
+
const { outer: allOut } = getSelectedCellsBorders(editor, cells);
|
|
106
|
+
const newSize$1 = allOut ? 0 : 1;
|
|
107
|
+
const { maxCol: maxCol$1, maxRow: maxRow$1, minCol: minCol$1, minRow: minRow$1 } = getSelectedCellsBoundingBox(editor, cells);
|
|
108
|
+
for (const cell of cells) {
|
|
109
|
+
const { col, row } = getCellIndices(editor, cell);
|
|
110
|
+
const cSpan = getColSpan(cell);
|
|
111
|
+
const rSpan = getRowSpan(cell);
|
|
112
|
+
for (let rr = row; rr < row + rSpan; rr++) for (let cc = col; cc < col + cSpan; cc++) {
|
|
113
|
+
const edges = [];
|
|
114
|
+
if (rr === minRow$1) edges.push("top");
|
|
115
|
+
if (rr === maxRow$1) edges.push("bottom");
|
|
116
|
+
if (cc === minCol$1) edges.push("left");
|
|
117
|
+
if (cc === maxCol$1) edges.push("right");
|
|
118
|
+
if (edges.length > 0) setCellBorderSize(editor, cell, edges, newSize$1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const newSize = isSelectedCellBorder(editor, cells, border) ? 0 : 1;
|
|
124
|
+
const { maxCol, maxRow, minCol, minRow } = getSelectedCellsBoundingBox(editor, cells);
|
|
125
|
+
for (const cell of cells) {
|
|
126
|
+
const { col, row } = getCellIndices(editor, cell);
|
|
127
|
+
const cSpan = getColSpan(cell);
|
|
128
|
+
const rSpan = getRowSpan(cell);
|
|
129
|
+
const cellPath = editor.api.findPath(cell);
|
|
130
|
+
if (!cellPath) continue;
|
|
131
|
+
const edges = [];
|
|
132
|
+
if (border === "top" && row === minRow) if (row === 0) edges.push("top");
|
|
133
|
+
else {
|
|
134
|
+
const cellAboveEntry = getTopTableCell(editor, { at: cellPath });
|
|
135
|
+
if (cellAboveEntry) {
|
|
136
|
+
const [cellAbove] = cellAboveEntry;
|
|
137
|
+
setCellBorderSize(editor, cellAbove, ["bottom"], newSize);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (border === "bottom" && row + rSpan - 1 === maxRow) edges.push("bottom");
|
|
141
|
+
if (border === "left" && col === minCol) if (col === 0) edges.push("left");
|
|
142
|
+
else {
|
|
143
|
+
const prevCellEntry = getLeftTableCell(editor, { at: cellPath });
|
|
144
|
+
if (prevCellEntry) {
|
|
145
|
+
const [prevCell] = prevCellEntry;
|
|
146
|
+
setCellBorderSize(editor, prevCell, ["right"], newSize);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (border === "right" && col + cSpan - 1 === maxCol) edges.push("right");
|
|
150
|
+
if (edges.length > 0) setCellBorderSize(editor, cell, edges, newSize);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns a function that sets borders on the selection with toggling logic. If
|
|
155
|
+
* selection has one or many cells, it's the same approach: we read the bounding
|
|
156
|
+
* rectangle, then decide which edges to flip on/off.
|
|
157
|
+
*/
|
|
158
|
+
const getOnSelectTableBorderFactory = (editor, selectedCells) => (border) => () => {
|
|
159
|
+
let cells = selectedCells;
|
|
160
|
+
if (!cells || cells.length === 0) {
|
|
161
|
+
const cell = editor.api.block({ match: { type: getCellTypes(editor) } });
|
|
162
|
+
if (cell) cells = [cell[0]];
|
|
163
|
+
else return;
|
|
164
|
+
}
|
|
165
|
+
setSelectedCellsBorder(editor, {
|
|
166
|
+
border,
|
|
167
|
+
cells: cells.map((v) => v)
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/react/components/TableCellElement/roundCellSizeToStep.ts
|
|
173
|
+
/**
|
|
174
|
+
* Rounds a cell size to the nearest step, or returns the size if the step is
|
|
175
|
+
* not set.
|
|
176
|
+
*/
|
|
177
|
+
const roundCellSizeToStep = (size, step) => step ? Math.round(size / step) * step : size;
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/react/components/TableCellElement/useIsCellSelected.ts
|
|
181
|
+
const useIsCellSelected = (element) => {
|
|
182
|
+
const $ = c(3);
|
|
183
|
+
const selectedCells = usePluginOption(TablePlugin, "selectedCells");
|
|
184
|
+
let t0;
|
|
185
|
+
if ($[0] !== element || $[1] !== selectedCells) {
|
|
186
|
+
t0 = selectedCells?.includes(element);
|
|
187
|
+
$[0] = element;
|
|
188
|
+
$[1] = selectedCells;
|
|
189
|
+
$[2] = t0;
|
|
190
|
+
} else t0 = $[2];
|
|
191
|
+
return !!t0;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/react/components/TableCellElement/useTableBordersDropdownMenuContentState.ts
|
|
196
|
+
const useTableBordersDropdownMenuContentState = (t0) => {
|
|
197
|
+
const $ = c(18);
|
|
198
|
+
let t1;
|
|
199
|
+
if ($[0] !== t0) {
|
|
200
|
+
t1 = t0 === void 0 ? {} : t0;
|
|
201
|
+
$[0] = t0;
|
|
202
|
+
$[1] = t1;
|
|
203
|
+
} else t1 = $[1];
|
|
204
|
+
const { element: el } = t1;
|
|
205
|
+
const { editor } = useEditorPlugin(TablePlugin);
|
|
206
|
+
const element = useElement() ?? el;
|
|
207
|
+
const selectedCells = usePluginOption(TablePlugin, "selectedCells");
|
|
208
|
+
let t2;
|
|
209
|
+
if ($[2] !== selectedCells) {
|
|
210
|
+
t2 = (editor_0) => getSelectedCellsBorders(editor_0, selectedCells);
|
|
211
|
+
$[2] = selectedCells;
|
|
212
|
+
$[3] = t2;
|
|
213
|
+
} else t2 = $[3];
|
|
214
|
+
let t3;
|
|
215
|
+
if ($[4] !== element || $[5] !== selectedCells) {
|
|
216
|
+
t3 = [selectedCells, element];
|
|
217
|
+
$[4] = element;
|
|
218
|
+
$[5] = selectedCells;
|
|
219
|
+
$[6] = t3;
|
|
220
|
+
} else t3 = $[6];
|
|
221
|
+
const borderStates = useEditorSelector(t2, t3);
|
|
222
|
+
let t4;
|
|
223
|
+
if ($[7] !== editor || $[8] !== selectedCells) {
|
|
224
|
+
t4 = getOnSelectTableBorderFactory(editor, selectedCells);
|
|
225
|
+
$[7] = editor;
|
|
226
|
+
$[8] = selectedCells;
|
|
227
|
+
$[9] = t4;
|
|
228
|
+
} else t4 = $[9];
|
|
229
|
+
let t5;
|
|
230
|
+
if ($[10] !== borderStates.bottom || $[11] !== borderStates.left || $[12] !== borderStates.none || $[13] !== borderStates.outer || $[14] !== borderStates.right || $[15] !== borderStates.top || $[16] !== t4) {
|
|
231
|
+
t5 = {
|
|
232
|
+
getOnSelectTableBorder: t4,
|
|
233
|
+
hasBottomBorder: borderStates.bottom,
|
|
234
|
+
hasLeftBorder: borderStates.left,
|
|
235
|
+
hasNoBorders: borderStates.none,
|
|
236
|
+
hasOuterBorders: borderStates.outer,
|
|
237
|
+
hasRightBorder: borderStates.right,
|
|
238
|
+
hasTopBorder: borderStates.top
|
|
239
|
+
};
|
|
240
|
+
$[10] = borderStates.bottom;
|
|
241
|
+
$[11] = borderStates.left;
|
|
242
|
+
$[12] = borderStates.none;
|
|
243
|
+
$[13] = borderStates.outer;
|
|
244
|
+
$[14] = borderStates.right;
|
|
245
|
+
$[15] = borderStates.top;
|
|
246
|
+
$[16] = t4;
|
|
247
|
+
$[17] = t5;
|
|
248
|
+
} else t5 = $[17];
|
|
249
|
+
return t5;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/react/hooks/useCellIndices.ts
|
|
254
|
+
const useCellIndices = () => {
|
|
255
|
+
const $ = c(5);
|
|
256
|
+
const { editor } = useEditorPlugin(TablePlugin);
|
|
257
|
+
const element = useElement();
|
|
258
|
+
const cellIndices = usePluginOption(TablePlugin, "cellIndices", element.id);
|
|
259
|
+
let t0;
|
|
260
|
+
bb0: {
|
|
261
|
+
if (!cellIndices) {
|
|
262
|
+
let t1$1;
|
|
263
|
+
if ($[0] !== editor || $[1] !== element) {
|
|
264
|
+
t1$1 = computeCellIndices(editor, { cellNode: element }) ?? {
|
|
265
|
+
col: 0,
|
|
266
|
+
row: 0
|
|
267
|
+
};
|
|
268
|
+
$[0] = editor;
|
|
269
|
+
$[1] = element;
|
|
270
|
+
$[2] = t1$1;
|
|
271
|
+
} else t1$1 = $[2];
|
|
272
|
+
t0 = t1$1;
|
|
273
|
+
break bb0;
|
|
274
|
+
}
|
|
275
|
+
let t1;
|
|
276
|
+
if ($[3] !== cellIndices) {
|
|
277
|
+
t1 = cellIndices ?? {
|
|
278
|
+
col: 0,
|
|
279
|
+
row: 0
|
|
280
|
+
};
|
|
281
|
+
$[3] = cellIndices;
|
|
282
|
+
$[4] = t1;
|
|
283
|
+
} else t1 = $[4];
|
|
284
|
+
t0 = t1;
|
|
285
|
+
}
|
|
286
|
+
return t0;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/react/components/TableCellElement/useTableCellBorders.ts
|
|
291
|
+
function useTableCellBorders(t0) {
|
|
292
|
+
const $ = c(6);
|
|
293
|
+
let t1;
|
|
294
|
+
if ($[0] !== t0) {
|
|
295
|
+
t1 = t0 === void 0 ? {} : t0;
|
|
296
|
+
$[0] = t0;
|
|
297
|
+
$[1] = t1;
|
|
298
|
+
} else t1 = $[1];
|
|
299
|
+
const { element: el } = t1;
|
|
300
|
+
const { editor } = useEditorPlugin(TablePlugin);
|
|
301
|
+
const element = useElement() ?? el;
|
|
302
|
+
const cellIndices = useCellIndices();
|
|
303
|
+
let t2;
|
|
304
|
+
if ($[2] !== cellIndices || $[3] !== editor || $[4] !== element) {
|
|
305
|
+
t2 = getTableCellBorders(editor, {
|
|
306
|
+
cellIndices,
|
|
307
|
+
element
|
|
308
|
+
});
|
|
309
|
+
$[2] = cellIndices;
|
|
310
|
+
$[3] = editor;
|
|
311
|
+
$[4] = element;
|
|
312
|
+
$[5] = t2;
|
|
313
|
+
} else t2 = $[5];
|
|
314
|
+
return t2;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/react/stores/useTableStore.ts
|
|
319
|
+
const { TableProvider, tableStore, useTableSet, useTableState, useTableStore, useTableValue } = createAtomStore({
|
|
320
|
+
colSizeOverrides: atom(/* @__PURE__ */ new Map()),
|
|
321
|
+
marginLeftOverride: null,
|
|
322
|
+
rowSizeOverrides: atom(/* @__PURE__ */ new Map())
|
|
323
|
+
}, { name: "table" });
|
|
324
|
+
const useOverrideSizeFactory = (setOverrides) => {
|
|
325
|
+
const $ = c(2);
|
|
326
|
+
let t0;
|
|
327
|
+
if ($[0] !== setOverrides) {
|
|
328
|
+
t0 = (index, size) => {
|
|
329
|
+
setOverrides((overrides) => {
|
|
330
|
+
const newOverrides = new Map(overrides);
|
|
331
|
+
if (size === null) newOverrides.delete(index);
|
|
332
|
+
else newOverrides.set(index, size);
|
|
333
|
+
return newOverrides;
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
$[0] = setOverrides;
|
|
337
|
+
$[1] = t0;
|
|
338
|
+
} else t0 = $[1];
|
|
339
|
+
return t0;
|
|
340
|
+
};
|
|
341
|
+
const useOverrideColSize = () => {
|
|
342
|
+
return useOverrideSizeFactory(useTableSet("colSizeOverrides"));
|
|
343
|
+
};
|
|
344
|
+
const useOverrideRowSize = () => {
|
|
345
|
+
return useOverrideSizeFactory(useTableSet("rowSizeOverrides"));
|
|
346
|
+
};
|
|
347
|
+
const useOverrideMarginLeft = () => {
|
|
348
|
+
return useTableSet("marginLeftOverride");
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/react/components/TableElement/useSelectedCells.ts
|
|
353
|
+
/**
|
|
354
|
+
* Many grid cells above and diff -> set No many grid cells above and diff ->
|
|
355
|
+
* unset No selection -> unset
|
|
356
|
+
*/
|
|
357
|
+
const useSelectedCells = () => {
|
|
358
|
+
const $ = c(20);
|
|
359
|
+
const readOnly = useReadOnly();
|
|
360
|
+
const selected = useSelected();
|
|
361
|
+
const editor = useEditorRef();
|
|
362
|
+
const selection = useEditorSelection();
|
|
363
|
+
const { setOption } = useEditorPlugin(TablePlugin);
|
|
364
|
+
const selectedCells = usePluginOption(TablePlugin, "selectedCells");
|
|
365
|
+
let t0;
|
|
366
|
+
if ($[0] !== readOnly || $[1] !== selected || $[2] !== setOption) {
|
|
367
|
+
t0 = () => {
|
|
368
|
+
if (!selected || readOnly) {
|
|
369
|
+
setOption("selectedCells", null);
|
|
370
|
+
setOption("selectedTables", null);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
$[0] = readOnly;
|
|
374
|
+
$[1] = selected;
|
|
375
|
+
$[2] = setOption;
|
|
376
|
+
$[3] = t0;
|
|
377
|
+
} else t0 = $[3];
|
|
378
|
+
let t1;
|
|
379
|
+
if ($[4] !== editor || $[5] !== readOnly || $[6] !== selected || $[7] !== setOption) {
|
|
380
|
+
t1 = [
|
|
381
|
+
selected,
|
|
382
|
+
editor,
|
|
383
|
+
readOnly,
|
|
384
|
+
setOption
|
|
385
|
+
];
|
|
386
|
+
$[4] = editor;
|
|
387
|
+
$[5] = readOnly;
|
|
388
|
+
$[6] = selected;
|
|
389
|
+
$[7] = setOption;
|
|
390
|
+
$[8] = t1;
|
|
391
|
+
} else t1 = $[8];
|
|
392
|
+
React.useEffect(t0, t1);
|
|
393
|
+
let t2;
|
|
394
|
+
if ($[9] !== editor || $[10] !== readOnly || $[11] !== selectedCells || $[12] !== setOption) {
|
|
395
|
+
t2 = () => {
|
|
396
|
+
if (readOnly) return;
|
|
397
|
+
const tableEntries = getTableGridAbove(editor, { format: "table" });
|
|
398
|
+
const cellEntries = getTableGridAbove(editor, { format: "cell" });
|
|
399
|
+
if (cellEntries?.length > 1) {
|
|
400
|
+
const cells = cellEntries.map(_temp$3);
|
|
401
|
+
const tables = tableEntries.map(_temp2);
|
|
402
|
+
if (JSON.stringify(cells) !== JSON.stringify(selectedCells)) {
|
|
403
|
+
setOption("selectedCells", cells);
|
|
404
|
+
setOption("selectedTables", tables);
|
|
405
|
+
}
|
|
406
|
+
} else if (selectedCells) {
|
|
407
|
+
setOption("selectedCells", null);
|
|
408
|
+
setOption("selectedTables", null);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
$[9] = editor;
|
|
412
|
+
$[10] = readOnly;
|
|
413
|
+
$[11] = selectedCells;
|
|
414
|
+
$[12] = setOption;
|
|
415
|
+
$[13] = t2;
|
|
416
|
+
} else t2 = $[13];
|
|
417
|
+
let t3;
|
|
418
|
+
if ($[14] !== editor || $[15] !== readOnly || $[16] !== selectedCells || $[17] !== selection || $[18] !== setOption) {
|
|
419
|
+
t3 = [
|
|
420
|
+
editor,
|
|
421
|
+
selection,
|
|
422
|
+
readOnly,
|
|
423
|
+
selectedCells,
|
|
424
|
+
setOption
|
|
425
|
+
];
|
|
426
|
+
$[14] = editor;
|
|
427
|
+
$[15] = readOnly;
|
|
428
|
+
$[16] = selectedCells;
|
|
429
|
+
$[17] = selection;
|
|
430
|
+
$[18] = setOption;
|
|
431
|
+
$[19] = t3;
|
|
432
|
+
} else t3 = $[19];
|
|
433
|
+
React.useEffect(t2, t3);
|
|
434
|
+
};
|
|
435
|
+
function _temp$3(entry) {
|
|
436
|
+
return entry[0];
|
|
437
|
+
}
|
|
438
|
+
function _temp2(entry_0) {
|
|
439
|
+
return entry_0[0];
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/react/components/TableElement/useTableColSizes.ts
|
|
444
|
+
/**
|
|
445
|
+
* Returns colSizes with overrides applied. Unset node.colSizes if `colCount`
|
|
446
|
+
* updates to 1.
|
|
447
|
+
*/
|
|
448
|
+
const useTableColSizes = (t0) => {
|
|
449
|
+
const $ = c(8);
|
|
450
|
+
let t1;
|
|
451
|
+
if ($[0] !== t0) {
|
|
452
|
+
t1 = t0 === void 0 ? {} : t0;
|
|
453
|
+
$[0] = t0;
|
|
454
|
+
$[1] = t1;
|
|
455
|
+
} else t1 = $[1];
|
|
456
|
+
const { disableOverrides: t2, transformColSizes } = t1;
|
|
457
|
+
const disableOverrides = t2 === void 0 ? false : t2;
|
|
458
|
+
const colSizeOverrides = useTableValue("colSizeOverrides");
|
|
459
|
+
let t3;
|
|
460
|
+
let t4;
|
|
461
|
+
if ($[2] !== colSizeOverrides || $[3] !== disableOverrides || $[4] !== transformColSizes) {
|
|
462
|
+
t3 = (t5$1) => {
|
|
463
|
+
const [tableNode] = t5$1;
|
|
464
|
+
const colSizes = getTableOverriddenColSizes(tableNode, disableOverrides ? void 0 : colSizeOverrides);
|
|
465
|
+
if (transformColSizes) return transformColSizes(colSizes);
|
|
466
|
+
return colSizes;
|
|
467
|
+
};
|
|
468
|
+
t4 = [
|
|
469
|
+
disableOverrides,
|
|
470
|
+
colSizeOverrides,
|
|
471
|
+
transformColSizes
|
|
472
|
+
];
|
|
473
|
+
$[2] = colSizeOverrides;
|
|
474
|
+
$[3] = disableOverrides;
|
|
475
|
+
$[4] = transformColSizes;
|
|
476
|
+
$[5] = t3;
|
|
477
|
+
$[6] = t4;
|
|
478
|
+
} else {
|
|
479
|
+
t3 = $[5];
|
|
480
|
+
t4 = $[6];
|
|
481
|
+
}
|
|
482
|
+
let t5;
|
|
483
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
484
|
+
t5 = {
|
|
485
|
+
key: KEYS.table,
|
|
486
|
+
equalityFn: _temp$2
|
|
487
|
+
};
|
|
488
|
+
$[7] = t5;
|
|
489
|
+
} else t5 = $[7];
|
|
490
|
+
return useElementSelector(t3, t4, t5);
|
|
491
|
+
};
|
|
492
|
+
function _temp$2(a, b) {
|
|
493
|
+
return !!a && !!b && PathApi.equals(a, b);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/react/components/TableElement/useTableElement.ts
|
|
498
|
+
const useTableElement = () => {
|
|
499
|
+
const $ = c(7);
|
|
500
|
+
const { editor, getOptions } = useEditorPlugin(TablePlugin);
|
|
501
|
+
const { disableMarginLeft } = getOptions();
|
|
502
|
+
const element = useElement();
|
|
503
|
+
const selectedCells = usePluginOption(TablePlugin, "selectedCells");
|
|
504
|
+
const marginLeftOverride = useTableValue("marginLeftOverride");
|
|
505
|
+
const marginLeft = disableMarginLeft ? 0 : marginLeftOverride ?? element.marginLeft ?? 0;
|
|
506
|
+
useSelectedCells();
|
|
507
|
+
const t0 = !!selectedCells;
|
|
508
|
+
let t1;
|
|
509
|
+
if ($[0] !== editor || $[1] !== selectedCells) {
|
|
510
|
+
t1 = { onMouseDown: () => {
|
|
511
|
+
if (selectedCells) editor.tf.collapse();
|
|
512
|
+
} };
|
|
513
|
+
$[0] = editor;
|
|
514
|
+
$[1] = selectedCells;
|
|
515
|
+
$[2] = t1;
|
|
516
|
+
} else t1 = $[2];
|
|
517
|
+
let t2;
|
|
518
|
+
if ($[3] !== marginLeft || $[4] !== t0 || $[5] !== t1) {
|
|
519
|
+
t2 = {
|
|
520
|
+
isSelectingCell: t0,
|
|
521
|
+
marginLeft,
|
|
522
|
+
props: t1
|
|
523
|
+
};
|
|
524
|
+
$[3] = marginLeft;
|
|
525
|
+
$[4] = t0;
|
|
526
|
+
$[5] = t1;
|
|
527
|
+
$[6] = t2;
|
|
528
|
+
} else t2 = $[6];
|
|
529
|
+
return t2;
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/react/components/TableCellElement/useTableCellSize.ts
|
|
534
|
+
function useTableCellSize(t0) {
|
|
535
|
+
const $ = c(10);
|
|
536
|
+
let t1;
|
|
537
|
+
if ($[0] !== t0) {
|
|
538
|
+
t1 = t0 === void 0 ? {} : t0;
|
|
539
|
+
$[0] = t0;
|
|
540
|
+
$[1] = t1;
|
|
541
|
+
} else t1 = $[1];
|
|
542
|
+
const { element: el } = t1;
|
|
543
|
+
const { api } = useEditorPlugin(TablePlugin);
|
|
544
|
+
const element = useElement() ?? el;
|
|
545
|
+
const colSizes = useTableColSizes();
|
|
546
|
+
const cellIndices = useCellIndices();
|
|
547
|
+
let t2;
|
|
548
|
+
let t3;
|
|
549
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
550
|
+
t2 = [];
|
|
551
|
+
t3 = { key: KEYS.tr };
|
|
552
|
+
$[2] = t2;
|
|
553
|
+
$[3] = t3;
|
|
554
|
+
} else {
|
|
555
|
+
t2 = $[2];
|
|
556
|
+
t3 = $[3];
|
|
557
|
+
}
|
|
558
|
+
const rowSize = useElementSelector(_temp$1, t2, t3);
|
|
559
|
+
let t4;
|
|
560
|
+
if ($[4] !== api.table || $[5] !== cellIndices || $[6] !== colSizes || $[7] !== element || $[8] !== rowSize) {
|
|
561
|
+
t4 = api.table.getCellSize({
|
|
562
|
+
cellIndices,
|
|
563
|
+
colSizes,
|
|
564
|
+
element,
|
|
565
|
+
rowSize
|
|
566
|
+
});
|
|
567
|
+
$[4] = api.table;
|
|
568
|
+
$[5] = cellIndices;
|
|
569
|
+
$[6] = colSizes;
|
|
570
|
+
$[7] = element;
|
|
571
|
+
$[8] = rowSize;
|
|
572
|
+
$[9] = t4;
|
|
573
|
+
} else t4 = $[9];
|
|
574
|
+
return t4;
|
|
575
|
+
}
|
|
576
|
+
function _temp$1(t0) {
|
|
577
|
+
const [node] = t0;
|
|
578
|
+
return node.size;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region src/react/components/TableCellElement/useTableCellElement.ts
|
|
583
|
+
const useTableCellElement = () => {
|
|
584
|
+
const { api, setOption } = useEditorPlugin(TablePlugin);
|
|
585
|
+
const element = useElement();
|
|
586
|
+
const isCellSelected = useIsCellSelected(element);
|
|
587
|
+
const selectedCells = usePluginOption(TablePlugin, "selectedCells");
|
|
588
|
+
React.useEffect(() => {
|
|
589
|
+
if (selectedCells?.some((v) => v.id === element.id && element !== v)) setOption("selectedCells", selectedCells.map((v) => v.id === element.id ? element : v));
|
|
590
|
+
}, [element]);
|
|
591
|
+
const rowSizeOverrides = useTableValue("rowSizeOverrides");
|
|
592
|
+
const { minHeight, width } = useTableCellSize({ element });
|
|
593
|
+
const borders = useTableCellBorders({ element });
|
|
594
|
+
/**
|
|
595
|
+
* Row size: if rowSpan > 1, we might look up the rowSize for the bottom row
|
|
596
|
+
* or you can do something simpler if row-spanning is unusual in your app.
|
|
597
|
+
*/
|
|
598
|
+
const { col, row } = useCellIndices();
|
|
599
|
+
const colSpan = api.table.getColSpan(element);
|
|
600
|
+
const endingRowIndex = row + api.table.getRowSpan(element) - 1;
|
|
601
|
+
return {
|
|
602
|
+
borders,
|
|
603
|
+
colIndex: col + colSpan - 1,
|
|
604
|
+
colSpan,
|
|
605
|
+
isSelectingCell: !!selectedCells,
|
|
606
|
+
minHeight: rowSizeOverrides.get?.(endingRowIndex) ?? minHeight,
|
|
607
|
+
rowIndex: endingRowIndex,
|
|
608
|
+
selected: isCellSelected,
|
|
609
|
+
width
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
//#endregion
|
|
614
|
+
//#region src/react/components/TableCellElement/useTableCellElementResizable.ts
|
|
615
|
+
const useTableCellElementResizable = (t0) => {
|
|
616
|
+
const $ = c(57);
|
|
617
|
+
const { colIndex, colSpan, rowIndex, step, stepX: t1, stepY: t2 } = t0;
|
|
618
|
+
const stepX = t1 === void 0 ? step : t1;
|
|
619
|
+
const stepY = t2 === void 0 ? step : t2;
|
|
620
|
+
const { editor, getOptions } = useEditorPlugin(TablePlugin);
|
|
621
|
+
const element = useElement();
|
|
622
|
+
let t3;
|
|
623
|
+
if ($[0] !== getOptions) {
|
|
624
|
+
t3 = getOptions();
|
|
625
|
+
$[0] = getOptions;
|
|
626
|
+
$[1] = t3;
|
|
627
|
+
} else t3 = $[1];
|
|
628
|
+
const { disableMarginLeft, minColumnWidth: t4 } = t3;
|
|
629
|
+
const minColumnWidth = t4 === void 0 ? 0 : t4;
|
|
630
|
+
let t5;
|
|
631
|
+
let t6;
|
|
632
|
+
if ($[2] !== colIndex || $[3] !== colSpan) {
|
|
633
|
+
t5 = (t7$1) => {
|
|
634
|
+
const [node] = t7$1;
|
|
635
|
+
return colSpan > 1 ? node.colSizes?.[colIndex] : void 0;
|
|
636
|
+
};
|
|
637
|
+
t6 = [colSpan, colIndex];
|
|
638
|
+
$[2] = colIndex;
|
|
639
|
+
$[3] = colSpan;
|
|
640
|
+
$[4] = t5;
|
|
641
|
+
$[5] = t6;
|
|
642
|
+
} else {
|
|
643
|
+
t5 = $[4];
|
|
644
|
+
t6 = $[5];
|
|
645
|
+
}
|
|
646
|
+
let t7;
|
|
647
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
648
|
+
t7 = { key: KEYS.table };
|
|
649
|
+
$[6] = t7;
|
|
650
|
+
} else t7 = $[6];
|
|
651
|
+
const initialWidth = useElementSelector(t5, t6, t7);
|
|
652
|
+
let t8;
|
|
653
|
+
let t9;
|
|
654
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
655
|
+
t8 = [];
|
|
656
|
+
t9 = { key: KEYS.table };
|
|
657
|
+
$[7] = t8;
|
|
658
|
+
$[8] = t9;
|
|
659
|
+
} else {
|
|
660
|
+
t8 = $[7];
|
|
661
|
+
t9 = $[8];
|
|
662
|
+
}
|
|
663
|
+
const marginLeft = useElementSelector(_temp, t8, t9);
|
|
664
|
+
let t10;
|
|
665
|
+
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
666
|
+
t10 = { disableOverrides: true };
|
|
667
|
+
$[9] = t10;
|
|
668
|
+
} else t10 = $[9];
|
|
669
|
+
const colSizesWithoutOverrides = useTableColSizes(t10);
|
|
670
|
+
const colSizesWithoutOverridesRef = React.useRef(colSizesWithoutOverrides);
|
|
671
|
+
let t11;
|
|
672
|
+
let t12;
|
|
673
|
+
if ($[10] !== colSizesWithoutOverrides) {
|
|
674
|
+
t11 = () => {
|
|
675
|
+
colSizesWithoutOverridesRef.current = colSizesWithoutOverrides;
|
|
676
|
+
};
|
|
677
|
+
t12 = [colSizesWithoutOverrides];
|
|
678
|
+
$[10] = colSizesWithoutOverrides;
|
|
679
|
+
$[11] = t11;
|
|
680
|
+
$[12] = t12;
|
|
681
|
+
} else {
|
|
682
|
+
t11 = $[11];
|
|
683
|
+
t12 = $[12];
|
|
684
|
+
}
|
|
685
|
+
React.useEffect(t11, t12);
|
|
686
|
+
const overrideColSize = useOverrideColSize();
|
|
687
|
+
const overrideRowSize = useOverrideRowSize();
|
|
688
|
+
const overrideMarginLeft = useOverrideMarginLeft();
|
|
689
|
+
let t13;
|
|
690
|
+
if ($[13] !== editor || $[14] !== element || $[15] !== overrideColSize) {
|
|
691
|
+
t13 = (colIndex_0, width) => {
|
|
692
|
+
setTableColSize(editor, {
|
|
693
|
+
colIndex: colIndex_0,
|
|
694
|
+
width
|
|
695
|
+
}, { at: element });
|
|
696
|
+
setTimeout(() => overrideColSize(colIndex_0, null), 0);
|
|
697
|
+
};
|
|
698
|
+
$[13] = editor;
|
|
699
|
+
$[14] = element;
|
|
700
|
+
$[15] = overrideColSize;
|
|
701
|
+
$[16] = t13;
|
|
702
|
+
} else t13 = $[16];
|
|
703
|
+
const setColSize = t13;
|
|
704
|
+
let t14;
|
|
705
|
+
if ($[17] !== editor || $[18] !== element || $[19] !== overrideRowSize) {
|
|
706
|
+
t14 = (rowIndex_0, height) => {
|
|
707
|
+
setTableRowSize(editor, {
|
|
708
|
+
height,
|
|
709
|
+
rowIndex: rowIndex_0
|
|
710
|
+
}, { at: element });
|
|
711
|
+
setTimeout(() => overrideRowSize(rowIndex_0, null), 0);
|
|
712
|
+
};
|
|
713
|
+
$[17] = editor;
|
|
714
|
+
$[18] = element;
|
|
715
|
+
$[19] = overrideRowSize;
|
|
716
|
+
$[20] = t14;
|
|
717
|
+
} else t14 = $[20];
|
|
718
|
+
const setRowSize = t14;
|
|
719
|
+
let t15;
|
|
720
|
+
if ($[21] !== editor || $[22] !== element || $[23] !== overrideMarginLeft) {
|
|
721
|
+
t15 = (marginLeft_0) => {
|
|
722
|
+
setTableMarginLeft(editor, { marginLeft: marginLeft_0 }, { at: element });
|
|
723
|
+
setTimeout(() => overrideMarginLeft(null), 0);
|
|
724
|
+
};
|
|
725
|
+
$[21] = editor;
|
|
726
|
+
$[22] = element;
|
|
727
|
+
$[23] = overrideMarginLeft;
|
|
728
|
+
$[24] = t15;
|
|
729
|
+
} else t15 = $[24];
|
|
730
|
+
const setMarginLeft = t15;
|
|
731
|
+
let t16;
|
|
732
|
+
if ($[25] !== colIndex || $[26] !== minColumnWidth || $[27] !== overrideColSize || $[28] !== setColSize || $[29] !== stepX) {
|
|
733
|
+
t16 = (t17$1) => {
|
|
734
|
+
const { delta, finished, initialSize: currentInitial } = t17$1;
|
|
735
|
+
const nextInitial = colSizesWithoutOverridesRef.current[colIndex + 1];
|
|
736
|
+
const complement = (width_0) => currentInitial + nextInitial - width_0;
|
|
737
|
+
const currentNew = roundCellSizeToStep(resizeLengthClampStatic(currentInitial + delta, {
|
|
738
|
+
max: nextInitial ? complement(minColumnWidth) : void 0,
|
|
739
|
+
min: minColumnWidth
|
|
740
|
+
}), stepX);
|
|
741
|
+
const nextNew = nextInitial ? complement(currentNew) : void 0;
|
|
742
|
+
const fn = finished ? setColSize : overrideColSize;
|
|
743
|
+
fn(colIndex, currentNew);
|
|
744
|
+
if (nextNew) fn(colIndex + 1, nextNew);
|
|
745
|
+
};
|
|
746
|
+
$[25] = colIndex;
|
|
747
|
+
$[26] = minColumnWidth;
|
|
748
|
+
$[27] = overrideColSize;
|
|
749
|
+
$[28] = setColSize;
|
|
750
|
+
$[29] = stepX;
|
|
751
|
+
$[30] = t16;
|
|
752
|
+
} else t16 = $[30];
|
|
753
|
+
const handleResizeRight = t16;
|
|
754
|
+
let t17;
|
|
755
|
+
if ($[31] !== overrideRowSize || $[32] !== rowIndex || $[33] !== setRowSize || $[34] !== stepY) {
|
|
756
|
+
t17 = (event) => {
|
|
757
|
+
const newHeight = roundCellSizeToStep(event.initialSize + event.delta, stepY);
|
|
758
|
+
if (event.finished) setRowSize(rowIndex, newHeight);
|
|
759
|
+
else overrideRowSize(rowIndex, newHeight);
|
|
760
|
+
};
|
|
761
|
+
$[31] = overrideRowSize;
|
|
762
|
+
$[32] = rowIndex;
|
|
763
|
+
$[33] = setRowSize;
|
|
764
|
+
$[34] = stepY;
|
|
765
|
+
$[35] = t17;
|
|
766
|
+
} else t17 = $[35];
|
|
767
|
+
const handleResizeBottom = t17;
|
|
768
|
+
let t18;
|
|
769
|
+
if ($[36] !== colIndex || $[37] !== marginLeft || $[38] !== minColumnWidth || $[39] !== overrideColSize || $[40] !== overrideMarginLeft || $[41] !== setColSize || $[42] !== setMarginLeft || $[43] !== stepX) {
|
|
770
|
+
t18 = (event_0) => {
|
|
771
|
+
const initial = colSizesWithoutOverridesRef.current[colIndex];
|
|
772
|
+
const complement_0 = (width_1) => initial + marginLeft - width_1;
|
|
773
|
+
const newMargin = roundCellSizeToStep(resizeLengthClampStatic(marginLeft + event_0.delta, {
|
|
774
|
+
max: complement_0(minColumnWidth),
|
|
775
|
+
min: 0
|
|
776
|
+
}), stepX);
|
|
777
|
+
const newWidth = complement_0(newMargin);
|
|
778
|
+
if (event_0.finished) {
|
|
779
|
+
setMarginLeft(newMargin);
|
|
780
|
+
setColSize(colIndex, newWidth);
|
|
781
|
+
} else {
|
|
782
|
+
overrideMarginLeft(newMargin);
|
|
783
|
+
overrideColSize(colIndex, newWidth);
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
$[36] = colIndex;
|
|
787
|
+
$[37] = marginLeft;
|
|
788
|
+
$[38] = minColumnWidth;
|
|
789
|
+
$[39] = overrideColSize;
|
|
790
|
+
$[40] = overrideMarginLeft;
|
|
791
|
+
$[41] = setColSize;
|
|
792
|
+
$[42] = setMarginLeft;
|
|
793
|
+
$[43] = stepX;
|
|
794
|
+
$[44] = t18;
|
|
795
|
+
} else t18 = $[44];
|
|
796
|
+
const handleResizeLeft = t18;
|
|
797
|
+
const hasLeftHandle = colIndex === 0 && !disableMarginLeft;
|
|
798
|
+
let t19;
|
|
799
|
+
if ($[45] !== handleResizeBottom) {
|
|
800
|
+
t19 = { options: {
|
|
801
|
+
direction: "bottom",
|
|
802
|
+
onResize: handleResizeBottom
|
|
803
|
+
} };
|
|
804
|
+
$[45] = handleResizeBottom;
|
|
805
|
+
$[46] = t19;
|
|
806
|
+
} else t19 = $[46];
|
|
807
|
+
const t20 = t19;
|
|
808
|
+
const t21 = !hasLeftHandle;
|
|
809
|
+
let t22;
|
|
810
|
+
if ($[47] !== handleResizeLeft) {
|
|
811
|
+
t22 = { options: {
|
|
812
|
+
direction: "left",
|
|
813
|
+
onResize: handleResizeLeft
|
|
814
|
+
} };
|
|
815
|
+
$[47] = handleResizeLeft;
|
|
816
|
+
$[48] = t22;
|
|
817
|
+
} else t22 = $[48];
|
|
818
|
+
const t23 = t22;
|
|
819
|
+
let t24;
|
|
820
|
+
if ($[49] !== handleResizeRight || $[50] !== initialWidth) {
|
|
821
|
+
t24 = { options: {
|
|
822
|
+
direction: "right",
|
|
823
|
+
initialSize: initialWidth,
|
|
824
|
+
onResize: handleResizeRight
|
|
825
|
+
} };
|
|
826
|
+
$[49] = handleResizeRight;
|
|
827
|
+
$[50] = initialWidth;
|
|
828
|
+
$[51] = t24;
|
|
829
|
+
} else t24 = $[51];
|
|
830
|
+
const t25 = t24;
|
|
831
|
+
let t26;
|
|
832
|
+
if ($[52] !== t20 || $[53] !== t21 || $[54] !== t23 || $[55] !== t25) {
|
|
833
|
+
t26 = {
|
|
834
|
+
bottomProps: t20,
|
|
835
|
+
hiddenLeft: t21,
|
|
836
|
+
leftProps: t23,
|
|
837
|
+
rightProps: t25
|
|
838
|
+
};
|
|
839
|
+
$[52] = t20;
|
|
840
|
+
$[53] = t21;
|
|
841
|
+
$[54] = t23;
|
|
842
|
+
$[55] = t25;
|
|
843
|
+
$[56] = t26;
|
|
844
|
+
} else t26 = $[56];
|
|
845
|
+
return t26;
|
|
846
|
+
};
|
|
847
|
+
function _temp(t0) {
|
|
848
|
+
const [node_0] = t0;
|
|
849
|
+
return node_0.marginLeft ?? 0;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/react/hooks/useTableMergeState.ts
|
|
854
|
+
const useTableMergeState = () => {
|
|
855
|
+
const { api, getOptions } = useEditorPlugin(TablePlugin);
|
|
856
|
+
const { disableMerge } = getOptions();
|
|
857
|
+
if (disableMerge) return {
|
|
858
|
+
canMerge: false,
|
|
859
|
+
canSplit: false
|
|
860
|
+
};
|
|
861
|
+
const readOnly = useReadOnly();
|
|
862
|
+
const someTable = useEditorSelector((editor) => editor.api.some({ match: { type: KEYS.table } }), []);
|
|
863
|
+
const selectionExpanded = useEditorSelector((editor) => editor.api.isExpanded(), []);
|
|
864
|
+
const collapsed = !readOnly && someTable && !selectionExpanded;
|
|
865
|
+
const selectedTable = usePluginOption(TablePlugin, "selectedTables")?.[0];
|
|
866
|
+
const selectedCellEntries = useEditorSelector((editor) => getTableGridAbove(editor, { format: "cell" }), []);
|
|
867
|
+
if (!selectedCellEntries) return {
|
|
868
|
+
canMerge: false,
|
|
869
|
+
canSplit: false
|
|
870
|
+
};
|
|
871
|
+
return {
|
|
872
|
+
canMerge: !readOnly && someTable && selectionExpanded && selectedCellEntries.length > 1 && isTableRectangular(selectedTable),
|
|
873
|
+
canSplit: collapsed && selectedCellEntries.length === 1 && (api.table.getColSpan(selectedCellEntries[0][0]) > 1 || api.table.getRowSpan(selectedCellEntries[0][0]) > 1)
|
|
874
|
+
};
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
//#endregion
|
|
878
|
+
export { TableCellHeaderPlugin, TableCellPlugin, TablePlugin, TableProvider, TableRowPlugin, getOnSelectTableBorderFactory, onKeyDownTable, roundCellSizeToStep, setSelectedCellsBorder, tableStore, useCellIndices, useIsCellSelected, useOverrideColSize, useOverrideMarginLeft, useOverrideRowSize, useSelectedCells, useTableBordersDropdownMenuContentState, useTableCellBorders, useTableCellElement, useTableCellElementResizable, useTableCellSize, useTableColSizes, useTableElement, useTableMergeState, useTableSet, useTableState, useTableStore, useTableValue };
|
|
879
|
+
//# sourceMappingURL=index.js.map
|