@kopexa/extension-table 17.0.44 → 17.0.46
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/{chunk-SNJF4UW6.mjs → chunk-2L3HZWWG.mjs} +4 -4
- package/dist/{chunk-BAQU2YT5.mjs → chunk-3XEOCAHB.mjs} +1 -1
- package/dist/{chunk-FKOIW52J.mjs → chunk-5W5ARI64.mjs} +1 -1
- package/dist/{chunk-IMRHHVEF.mjs → chunk-BTJ3DCGC.mjs} +2 -2
- package/dist/chunk-DR2GZJH6.mjs +70 -0
- package/dist/chunk-GHOJLOCF.mjs +247 -0
- package/dist/chunk-HWVA6DOK.mjs +20 -0
- package/dist/{chunk-DF6ZMJLL.mjs → chunk-KLUH6EZS.mjs} +1 -1
- package/dist/chunk-KNOMCS6F.mjs +57 -0
- package/dist/{chunk-OPDSKEZR.mjs → chunk-LPHCE6EI.mjs} +16 -17
- package/dist/chunk-POJFNXG7.mjs +44 -0
- package/dist/chunk-QHD3QTD2.mjs +61 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +456 -714
- package/dist/index.mjs +15 -12
- package/dist/kit.js +454 -714
- package/dist/kit.mjs +12 -12
- package/dist/table/index.d.mts +3 -0
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.js +411 -595
- package/dist/table/index.mjs +12 -9
- package/dist/table/{utilities → lib}/col-style.js +1 -1
- package/dist/{chunk-NTWXQSW6.mjs → table/lib/col-style.mjs} +2 -2
- package/dist/table/{utilities → lib}/delete-table-when-all-cells-selected.js +3 -3
- package/dist/table/{utilities → lib}/delete-table-when-all-cells-selected.mjs +2 -2
- package/dist/table/{utilities → lib}/get-table-node-types.js +1 -1
- package/dist/table/{utilities → lib}/get-table-node-types.mjs +1 -1
- package/dist/table/{icons.js → lib/icons.js} +1 -1
- package/dist/{chunk-7NEAULTF.mjs → table/lib/icons.mjs} +2 -2
- package/dist/table/{utilities → lib}/insert-line-above-table-action.js +1 -1
- package/dist/table/{utilities → lib}/insert-line-above-table-action.mjs +1 -1
- package/dist/table/{utilities → lib}/insert-line-below-table-action.js +1 -1
- package/dist/table/{utilities → lib}/insert-line-below-table-action.mjs +1 -1
- package/dist/table/{utilities → lib}/is-cell-selection.js +1 -1
- package/dist/table/{utilities → lib}/is-cell-selection.mjs +1 -1
- package/dist/table/{table-controls.js → lib/table-controls.js} +2 -2
- package/dist/table/lib/table-controls.mjs +8 -0
- package/dist/table/table.js +407 -593
- package/dist/table/table.mjs +7 -7
- package/dist/table/views/table-column-menu.d.mts +11 -0
- package/dist/table/views/table-column-menu.d.ts +11 -0
- package/dist/table/views/table-column-menu.js +84 -0
- package/dist/table/views/table-column-menu.mjs +8 -0
- package/dist/table/views/table-node-view.d.mts +25 -0
- package/dist/table/views/table-node-view.d.ts +25 -0
- package/dist/table/views/table-node-view.js +370 -0
- package/dist/table/views/table-node-view.mjs +10 -0
- package/dist/table/views/table-row-menu.d.mts +11 -0
- package/dist/table/views/table-row-menu.d.ts +11 -0
- package/dist/table/views/table-row-menu.js +80 -0
- package/dist/table/views/table-row-menu.mjs +8 -0
- package/dist/table-cell.js +18 -64
- package/dist/table-cell.mjs +1 -1
- package/dist/table-header.js +17 -54
- package/dist/table-header.mjs +1 -1
- package/dist/table-row.js +10 -1
- package/dist/table-row.mjs +1 -1
- package/package.json +10 -11
- package/dist/chunk-6NY5XWR7.mjs +0 -11
- package/dist/chunk-74O2ORPO.mjs +0 -81
- package/dist/chunk-ARSGMUXM.mjs +0 -116
- package/dist/chunk-GMNNSVR3.mjs +0 -540
- package/dist/table/icons.mjs +0 -8
- package/dist/table/table-controls.mjs +0 -8
- package/dist/table/table-view.d.mts +0 -43
- package/dist/table/table-view.d.ts +0 -43
- package/dist/table/table-view.js +0 -610
- package/dist/table/table-view.mjs +0 -12
- package/dist/table/utilities/col-style.mjs +0 -8
- /package/dist/{chunk-YSUOVRY4.mjs → chunk-RPPUD4R5.mjs} +0 -0
- /package/dist/table/{utilities → lib}/col-style.d.mts +0 -0
- /package/dist/table/{utilities → lib}/col-style.d.ts +0 -0
- /package/dist/table/{utilities → lib}/delete-table-when-all-cells-selected.d.mts +0 -0
- /package/dist/table/{utilities → lib}/delete-table-when-all-cells-selected.d.ts +0 -0
- /package/dist/table/{utilities → lib}/get-table-node-types.d.mts +0 -0
- /package/dist/table/{utilities → lib}/get-table-node-types.d.ts +0 -0
- /package/dist/table/{icons.d.mts → lib/icons.d.mts} +0 -0
- /package/dist/table/{icons.d.ts → lib/icons.d.ts} +0 -0
- /package/dist/table/{utilities → lib}/insert-line-above-table-action.d.mts +0 -0
- /package/dist/table/{utilities → lib}/insert-line-above-table-action.d.ts +0 -0
- /package/dist/table/{utilities → lib}/insert-line-below-table-action.d.mts +0 -0
- /package/dist/table/{utilities → lib}/insert-line-below-table-action.d.ts +0 -0
- /package/dist/table/{utilities → lib}/is-cell-selection.d.mts +0 -0
- /package/dist/table/{utilities → lib}/is-cell-selection.d.ts +0 -0
- /package/dist/table/{table-controls.d.mts → lib/table-controls.d.mts} +0 -0
- /package/dist/table/{table-controls.d.ts → lib/table-controls.d.ts} +0 -0
package/dist/table/index.js
CHANGED
|
@@ -23,15 +23,88 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23
23
|
// src/table/index.ts
|
|
24
24
|
var table_exports = {};
|
|
25
25
|
__export(table_exports, {
|
|
26
|
-
Table: () => Table
|
|
26
|
+
Table: () => Table,
|
|
27
|
+
TableNodeView: () => TableNodeView
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(table_exports);
|
|
29
30
|
|
|
30
31
|
// src/table/table.ts
|
|
31
32
|
var import_extension_table = require("@tiptap/extension-table");
|
|
32
|
-
var
|
|
33
|
+
var import_tables4 = require("@tiptap/pm/tables");
|
|
34
|
+
var import_react5 = require("@tiptap/react");
|
|
35
|
+
|
|
36
|
+
// src/table/lib/insert-line-above-table-action.ts
|
|
37
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
38
|
+
var insertLineAboveTableAction = ({
|
|
39
|
+
editor
|
|
40
|
+
}) => {
|
|
41
|
+
if (!editor.isActive("table")) return false;
|
|
42
|
+
try {
|
|
43
|
+
const { selection } = editor.state;
|
|
44
|
+
const tableNode = (0, import_editor_utils.findParentNodeOfType)(selection, "table");
|
|
45
|
+
if (!tableNode) return false;
|
|
46
|
+
const tablePos = tableNode.pos;
|
|
47
|
+
const firstRow = tableNode.node.child(0);
|
|
48
|
+
const selectionPath = selection.$anchor.path;
|
|
49
|
+
const selectionInFirstRow = selectionPath.includes(firstRow);
|
|
50
|
+
if (!selectionInFirstRow) return false;
|
|
51
|
+
if (tablePos === 0) {
|
|
52
|
+
editor.chain().insertContentAt(tablePos, { type: "paragraph" }).run();
|
|
53
|
+
editor.chain().setTextSelection(tablePos + 1).run();
|
|
54
|
+
} else {
|
|
55
|
+
const prevNodePos = tablePos - 1;
|
|
56
|
+
if (prevNodePos <= 0) return false;
|
|
57
|
+
const prevNode = editor.state.doc.nodeAt(prevNodePos - 1);
|
|
58
|
+
if (prevNode && prevNode.type.name === "paragraph") {
|
|
59
|
+
const endOfParagraphPos = tablePos - prevNode.nodeSize;
|
|
60
|
+
editor.chain().setTextSelection(endOfParagraphPos).run();
|
|
61
|
+
} else {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("failed to insert line above table", e);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/table/lib/insert-line-below-table-action.ts
|
|
73
|
+
var import_editor_utils2 = require("@kopexa/editor-utils");
|
|
74
|
+
var insertLineBelowTableAction = ({
|
|
75
|
+
editor
|
|
76
|
+
}) => {
|
|
77
|
+
if (!editor.isActive("table")) return false;
|
|
78
|
+
try {
|
|
79
|
+
const { selection } = editor.state;
|
|
80
|
+
const tableNode = (0, import_editor_utils2.findParentNodeOfType)(selection, "table");
|
|
81
|
+
if (!tableNode) return false;
|
|
82
|
+
const tablePos = tableNode.pos;
|
|
83
|
+
const table = tableNode.node;
|
|
84
|
+
const rowCount = table.childCount;
|
|
85
|
+
const lastRow = table.child(rowCount - 1);
|
|
86
|
+
const selectionPath = selection.$anchor.path;
|
|
87
|
+
const selectionInLastRow = selectionPath.includes(lastRow);
|
|
88
|
+
if (!selectionInLastRow) return false;
|
|
89
|
+
const nextNodePos = tablePos + table.nodeSize;
|
|
90
|
+
const nextNode = editor.state.doc.nodeAt(nextNodePos);
|
|
91
|
+
if (nextNode && nextNode.type.name === "paragraph") {
|
|
92
|
+
const endOfParagraphPos = nextNodePos + nextNode.nodeSize - 1;
|
|
93
|
+
editor.chain().setTextSelection(endOfParagraphPos).run();
|
|
94
|
+
} else if (!nextNode) {
|
|
95
|
+
editor.chain().insertContentAt(nextNodePos, { type: "paragraph" }).run();
|
|
96
|
+
editor.chain().setTextSelection(nextNodePos + 1).run();
|
|
97
|
+
} else {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error("failed to insert line above table", e);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
33
106
|
|
|
34
|
-
// src/table/table-controls.ts
|
|
107
|
+
// src/table/lib/table-controls.ts
|
|
35
108
|
var import_core = require("@tiptap/core");
|
|
36
109
|
var import_state = require("@tiptap/pm/state");
|
|
37
110
|
var import_view = require("@tiptap/pm/view");
|
|
@@ -52,7 +125,7 @@ function tableControls() {
|
|
|
52
125
|
mousemove: (view, event) => {
|
|
53
126
|
var _a;
|
|
54
127
|
const pluginState = key.getState(view.state);
|
|
55
|
-
if (!event.target.closest(".table-
|
|
128
|
+
if (!event.target.closest(".table-node-view") && pluginState.values.hoveredTable) {
|
|
56
129
|
return view.dispatch(
|
|
57
130
|
view.state.tr.setMeta(key, {
|
|
58
131
|
setHoveredTable: null,
|
|
@@ -132,603 +205,347 @@ var TableControlsState = class {
|
|
|
132
205
|
}
|
|
133
206
|
};
|
|
134
207
|
|
|
135
|
-
// src/table/table-view.tsx
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
// src/table/icons.ts
|
|
141
|
-
var icons = {
|
|
142
|
-
colorPicker: `<svg xmlns="http://www.w3.org/2000/svg" length="24" viewBox="0 0 24 24" style="transform: ;msFilter:;"><path fill="rgb(var(--color-text-300))" d="M20 14c-.092.064-2 2.083-2 3.5 0 1.494.949 2.448 2 2.5.906.044 2-.891 2-2.5 0-1.5-1.908-3.436-2-3.5zM9.586 20c.378.378.88.586 1.414.586s1.036-.208 1.414-.586l7-7-.707-.707L11 4.586 8.707 2.293 7.293 3.707 9.586 6 4 11.586c-.378.378-.586.88-.586 1.414s.208 1.036.586 1.414L9.586 20zM11 7.414 16.586 13H5.414L11 7.414z"></path></svg>`,
|
|
143
|
-
deleteColumn: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
|
|
144
|
-
deleteRow: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
|
|
145
|
-
insertLeftTableIcon: `<svg
|
|
146
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
147
|
-
length={12}
|
|
148
|
-
viewBox="0 -960 960 960"
|
|
149
|
-
>
|
|
150
|
-
<path
|
|
151
|
-
d="M224.617-140.001q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21H360q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H224.617Zm375.383 0q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21h135.383q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H600Zm147.691-607.69q0-4.616-3.846-8.463-3.846-3.846-8.462-3.846H600q-4.616 0-8.462 3.846-3.847 3.847-3.847 8.463v535.382q0 4.616 3.847 8.463Q595.384-200 600-200h135.383q4.616 0 8.462-3.846 3.846-3.847 3.846-8.463v-535.382ZM587.691-200h160-160Z"
|
|
152
|
-
fill="rgb(var(--color-text-300))"
|
|
153
|
-
/>
|
|
154
|
-
</svg>
|
|
155
|
-
`,
|
|
156
|
-
insertRightTableIcon: `<svg
|
|
157
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
158
|
-
length={12}
|
|
159
|
-
viewBox="0 -960 960 960"
|
|
160
|
-
>
|
|
161
|
-
<path
|
|
162
|
-
d="M600-140.001q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21h135.383q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H600Zm-375.383 0q-30.307 0-51.307-21-21-21-21-51.308v-535.382q0-30.308 21-51.308t51.307-21H360q30.307 0 51.307 21 21 21 21 51.308v535.382q0 30.308-21 51.308t-51.307 21H224.617Zm-12.308-607.69v535.382q0 4.616 3.846 8.463 3.846 3.846 8.462 3.846H360q4.616 0 8.462-3.846 3.847-3.847 3.847-8.463v-535.382q0-4.616-3.847-8.463Q364.616-760 360-760H224.617q-4.616 0-8.462 3.846-3.846 3.847-3.846 8.463Zm160 547.691h-160 160Z"
|
|
163
|
-
fill="rgb(var(--color-text-300))"
|
|
164
|
-
/>
|
|
165
|
-
</svg>
|
|
166
|
-
`,
|
|
167
|
-
insertTopTableIcon: `<svg
|
|
168
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
169
|
-
length={24}
|
|
170
|
-
viewBox="0 -960 960 960"
|
|
171
|
-
>
|
|
172
|
-
<path
|
|
173
|
-
d="M212.309-527.693q-30.308 0-51.308-21t-21-51.307v-135.383q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307V-600q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0 375.383q-30.308 0-51.308-21t-21-51.307V-360q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307v135.383q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0-59.999h535.382q4.616 0 8.463-3.846 3.846-3.846 3.846-8.462V-360q0-4.616-3.846-8.462-3.847-3.847-8.463-3.847H212.309q-4.616 0-8.463 3.847Q200-364.616 200-360v135.383q0 4.616 3.846 8.462 3.847 3.846 8.463 3.846Zm-12.309-160v160-160Z"
|
|
174
|
-
fill="rgb(var(--color-text-300))"
|
|
175
|
-
/>
|
|
176
|
-
</svg>
|
|
177
|
-
`,
|
|
178
|
-
toggleColumnHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
|
|
179
|
-
toggleRowHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
|
|
180
|
-
insertBottomTableIcon: `<svg
|
|
181
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
182
|
-
length={24}
|
|
183
|
-
viewBox="0 -960 960 960"
|
|
184
|
-
>
|
|
185
|
-
<path
|
|
186
|
-
d="M212.309-152.31q-30.308 0-51.308-21t-21-51.307V-360q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307v135.383q0 30.307-21 51.307-21 21-51.308 21H212.309Zm0-375.383q-30.308 0-51.308-21t-21-51.307v-135.383q0-30.307 21-51.307 21-21 51.308-21h535.382q30.308 0 51.308 21t21 51.307V-600q0 30.307-21 51.307-21 21-51.308 21H212.309Zm535.382-219.998H212.309q-4.616 0-8.463 3.846-3.846 3.846-3.846 8.462V-600q0 4.616 3.846 8.462 3.847 3.847 8.463 3.847h535.382q4.616 0 8.463-3.847Q760-595.384 760-600v-135.383q0-4.616-3.846-8.462-3.847-3.846-8.463-3.846ZM200-587.691v-160 160Z"
|
|
187
|
-
fill="rgb(var(--color-text-300))"
|
|
188
|
-
/>
|
|
189
|
-
</svg>
|
|
190
|
-
`
|
|
191
|
-
};
|
|
208
|
+
// src/table/views/table-node-view.tsx
|
|
209
|
+
var import_tables3 = require("@tiptap/pm/tables");
|
|
210
|
+
var import_react3 = require("@tiptap/react");
|
|
211
|
+
var import_react4 = require("react");
|
|
192
212
|
|
|
193
|
-
// src/table/table-
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
213
|
+
// src/table/views/table-column-menu.tsx
|
|
214
|
+
var import_dropdown_menu = require("@kopexa/dropdown-menu");
|
|
215
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
216
|
+
var import_react = require("react");
|
|
217
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
218
|
+
function TableColumnMenu({
|
|
219
|
+
editor,
|
|
220
|
+
cellPos,
|
|
221
|
+
style
|
|
222
|
+
}) {
|
|
223
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
224
|
+
const chainAtCell = (0, import_react.useCallback)(() => {
|
|
225
|
+
const chain = editor.chain().focus();
|
|
226
|
+
if (cellPos != null) {
|
|
227
|
+
return chain.setTextSelection(cellPos + 1);
|
|
228
|
+
}
|
|
229
|
+
return chain;
|
|
230
|
+
}, [editor, cellPos]);
|
|
231
|
+
const handleToggleHeader = (0, import_react.useCallback)(() => {
|
|
232
|
+
chainAtCell().command(({ state, dispatch }) => (0, import_tables.toggleHeaderColumn)(state, dispatch)).run();
|
|
233
|
+
setOpen(false);
|
|
234
|
+
}, [chainAtCell]);
|
|
235
|
+
const handleAddBefore = (0, import_react.useCallback)(() => {
|
|
236
|
+
chainAtCell().addColumnBefore().run();
|
|
237
|
+
setOpen(false);
|
|
238
|
+
}, [chainAtCell]);
|
|
239
|
+
const handleAddAfter = (0, import_react.useCallback)(() => {
|
|
240
|
+
chainAtCell().addColumnAfter().run();
|
|
241
|
+
setOpen(false);
|
|
242
|
+
}, [chainAtCell]);
|
|
243
|
+
const handleDelete = (0, import_react.useCallback)(() => {
|
|
244
|
+
chainAtCell().deleteColumn().run();
|
|
245
|
+
setOpen(false);
|
|
246
|
+
}, [chainAtCell]);
|
|
247
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Root, { open, onOpenChange: setOpen, children: [
|
|
248
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
249
|
+
"button",
|
|
250
|
+
{
|
|
251
|
+
type: "button",
|
|
252
|
+
className: "columns-control-div",
|
|
253
|
+
"aria-label": "Column actions",
|
|
254
|
+
style
|
|
202
255
|
}
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this.floating.setAttribute("role", "dialog");
|
|
215
|
-
this.floating.setAttribute("aria-modal", "false");
|
|
216
|
-
this.floating.style.position = "fixed";
|
|
217
|
-
this.floating.style.zIndex = "9999";
|
|
218
|
-
this.floating.style.display = "none";
|
|
219
|
-
this.floating.className = "rounded-md border bg-background px-2 py-2.5 text-xs shadow-sm min-w-[12rem] whitespace-nowrap";
|
|
220
|
-
this.floating.appendChild(content);
|
|
221
|
-
const host = (_a = opts.container) != null ? _a : document.body;
|
|
222
|
-
host.appendChild(this.floating);
|
|
223
|
-
this._placement = (_b = opts.placement) != null ? _b : "right";
|
|
224
|
-
this._offsetPx = (_c = opts.offsetPx) != null ? _c : 6;
|
|
225
|
-
this._interactive = (_d = opts.interactive) != null ? _d : true;
|
|
226
|
-
}
|
|
227
|
-
async _updatePosition() {
|
|
228
|
-
const { x, y } = await (0, import_dom.computePosition)(this.reference, this.floating, {
|
|
229
|
-
placement: this._placement,
|
|
230
|
-
middleware: [(0, import_dom.offset)(this._offsetPx), (0, import_dom.flip)(), (0, import_dom.shift)({ padding: 8 })]
|
|
231
|
-
});
|
|
232
|
-
Object.assign(this.floating.style, { left: `${x}px`, top: `${y}px` });
|
|
233
|
-
}
|
|
234
|
-
show() {
|
|
235
|
-
if (this.floating.style.display !== "none") return;
|
|
236
|
-
this.floating.style.display = "block";
|
|
237
|
-
this.cleanupAutoUpdate = (0, import_dom.autoUpdate)(
|
|
238
|
-
this.reference,
|
|
239
|
-
this.floating,
|
|
240
|
-
() => this._updatePosition()
|
|
241
|
-
);
|
|
242
|
-
document.addEventListener("keydown", this.onEsc, { passive: true });
|
|
243
|
-
document.addEventListener("mousedown", this.onDocClick, { capture: true });
|
|
244
|
-
requestAnimationFrame(() => this._updatePosition());
|
|
245
|
-
}
|
|
246
|
-
hide() {
|
|
247
|
-
var _a;
|
|
248
|
-
if (this.floating.style.display === "none") return;
|
|
249
|
-
this.floating.style.display = "none";
|
|
250
|
-
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
|
251
|
-
this.cleanupAutoUpdate = null;
|
|
252
|
-
document.removeEventListener("keydown", this.onEsc);
|
|
253
|
-
document.removeEventListener("mousedown", this.onDocClick, {
|
|
254
|
-
capture: true
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
toggle() {
|
|
258
|
-
if (this.floating.style.display === "none") this.show();
|
|
259
|
-
else this.hide();
|
|
260
|
-
}
|
|
261
|
-
destroy() {
|
|
262
|
-
this.hide();
|
|
263
|
-
this.floating.remove();
|
|
264
|
-
}
|
|
265
|
-
get el() {
|
|
266
|
-
return this.floating;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
function setCellsBackgroundColor(editor, color) {
|
|
270
|
-
return editor.chain().focus().updateAttributes("tableCell", {
|
|
271
|
-
background: color.backgroundColor,
|
|
272
|
-
textColor: color.textColor
|
|
273
|
-
}).run();
|
|
256
|
+
) }),
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Content, { children: [
|
|
258
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Group, { children: [
|
|
259
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Item, { onSelect: handleToggleHeader, children: "Toggle header column" }),
|
|
260
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Item, { onSelect: handleAddBefore, children: "Insert column before" }),
|
|
261
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Item, { onSelect: handleAddAfter, children: "Insert column after" })
|
|
262
|
+
] }),
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Separator, {}),
|
|
264
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Item, { variant: "destructive", onSelect: handleDelete, children: "Delete column" })
|
|
265
|
+
] })
|
|
266
|
+
] });
|
|
274
267
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
268
|
+
|
|
269
|
+
// src/table/views/table-row-menu.tsx
|
|
270
|
+
var import_dropdown_menu2 = require("@kopexa/dropdown-menu");
|
|
271
|
+
var import_tables2 = require("@tiptap/pm/tables");
|
|
272
|
+
var import_react2 = require("react");
|
|
273
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
274
|
+
function TableRowMenu({ editor, cellPos, style }) {
|
|
275
|
+
const [open, setOpen] = (0, import_react2.useState)(false);
|
|
276
|
+
const chainAtCell = (0, import_react2.useCallback)(() => {
|
|
277
|
+
const chain = editor.chain().focus();
|
|
278
|
+
if (cellPos != null) {
|
|
279
|
+
return chain.setTextSelection(cellPos + 1);
|
|
280
|
+
}
|
|
281
|
+
return chain;
|
|
282
|
+
}, [editor, cellPos]);
|
|
283
|
+
const handleToggleHeader = (0, import_react2.useCallback)(() => {
|
|
284
|
+
chainAtCell().command(({ state, dispatch }) => (0, import_tables2.toggleHeaderRow)(state, dispatch)).run();
|
|
285
|
+
setOpen(false);
|
|
286
|
+
}, [chainAtCell]);
|
|
287
|
+
const handleAddAbove = (0, import_react2.useCallback)(() => {
|
|
288
|
+
chainAtCell().addRowBefore().run();
|
|
289
|
+
setOpen(false);
|
|
290
|
+
}, [chainAtCell]);
|
|
291
|
+
const handleAddBelow = (0, import_react2.useCallback)(() => {
|
|
292
|
+
chainAtCell().addRowAfter().run();
|
|
293
|
+
setOpen(false);
|
|
294
|
+
}, [chainAtCell]);
|
|
295
|
+
const handleDelete = (0, import_react2.useCallback)(() => {
|
|
296
|
+
chainAtCell().deleteRow().run();
|
|
297
|
+
setOpen(false);
|
|
298
|
+
}, [chainAtCell]);
|
|
299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Root, { open, onOpenChange: setOpen, children: [
|
|
300
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
301
|
+
"button",
|
|
302
|
+
{
|
|
303
|
+
type: "button",
|
|
304
|
+
className: "rows-control-div",
|
|
305
|
+
"aria-label": "Row actions",
|
|
306
|
+
style
|
|
307
|
+
}
|
|
308
|
+
) }),
|
|
309
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Content, { children: [
|
|
310
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Group, { children: [
|
|
311
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Item, { onSelect: handleToggleHeader, children: "Toggle header row" }),
|
|
312
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Item, { onSelect: handleAddAbove, children: "Insert row above" }),
|
|
313
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Item, { onSelect: handleAddBelow, children: "Insert row below" })
|
|
314
|
+
] }),
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Separator, {}),
|
|
316
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Item, { variant: "destructive", onSelect: handleDelete, children: "Delete row" })
|
|
317
|
+
] })
|
|
318
|
+
] });
|
|
293
319
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
{
|
|
306
|
-
label: "Add column after",
|
|
307
|
-
icon: icons.insertRightTableIcon,
|
|
308
|
-
action: ({ editor }) => editor.chain().focus().addColumnAfter().run()
|
|
309
|
-
},
|
|
310
|
-
{ label: "Pick color", icon: "", action: () => {
|
|
311
|
-
} },
|
|
312
|
-
{
|
|
313
|
-
label: "Delete column",
|
|
314
|
-
icon: icons.deleteColumn,
|
|
315
|
-
action: ({ editor }) => editor.chain().focus().deleteColumn().run()
|
|
316
|
-
}
|
|
317
|
-
];
|
|
318
|
-
var rowsToolboxItems = [
|
|
319
|
-
{
|
|
320
|
-
label: "Toggle row header",
|
|
321
|
-
icon: icons.toggleRowHeader,
|
|
322
|
-
action: ({ editor }) => editor.chain().focus().toggleHeaderRow().run()
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
label: "Add row above",
|
|
326
|
-
icon: icons.insertTopTableIcon,
|
|
327
|
-
action: ({ editor }) => editor.chain().focus().addRowBefore().run()
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
label: "Add row below",
|
|
331
|
-
icon: icons.insertBottomTableIcon,
|
|
332
|
-
action: ({ editor }) => editor.chain().focus().addRowAfter().run()
|
|
333
|
-
},
|
|
334
|
-
{ label: "Pick color", icon: "", action: () => {
|
|
335
|
-
} },
|
|
336
|
-
{
|
|
337
|
-
label: "Delete row",
|
|
338
|
-
icon: icons.deleteRow,
|
|
339
|
-
action: ({ editor }) => editor.chain().focus().deleteRow().run()
|
|
320
|
+
|
|
321
|
+
// src/table/views/table-node-view.tsx
|
|
322
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
323
|
+
function extractHoverInfo(decorations) {
|
|
324
|
+
const info = {};
|
|
325
|
+
for (const dec of decorations) {
|
|
326
|
+
const spec = dec.spec;
|
|
327
|
+
if ((spec == null ? void 0 : spec.hoveredCell) !== void 0)
|
|
328
|
+
info.hoveredCell = spec.hoveredCell;
|
|
329
|
+
if ((spec == null ? void 0 : spec.hoveredTable) !== void 0)
|
|
330
|
+
info.hoveredTable = spec.hoveredTable;
|
|
340
331
|
}
|
|
341
|
-
|
|
342
|
-
function buildToolboxContent({
|
|
343
|
-
items,
|
|
344
|
-
onClickItem,
|
|
345
|
-
onSelectColor,
|
|
346
|
-
colors
|
|
347
|
-
}) {
|
|
348
|
-
return (0, import_jsx_dom_cjs.h)(
|
|
349
|
-
"div",
|
|
350
|
-
{ className: "space-y-2" },
|
|
351
|
-
items.map((item) => {
|
|
352
|
-
if (item.label === "Pick color") {
|
|
353
|
-
return (0, import_jsx_dom_cjs.h)("div", { className: "flex flex-col" }, [
|
|
354
|
-
(0, import_jsx_dom_cjs.h)("hr", { className: "!my-2 border" }),
|
|
355
|
-
(0, import_jsx_dom_cjs.h)("div", { className: "text-foreground text-sm" }, item.label),
|
|
356
|
-
(0, import_jsx_dom_cjs.h)(
|
|
357
|
-
"div",
|
|
358
|
-
{ className: "grid grid-cols-6 gap-x-1 gap-y-2.5 mt-2" },
|
|
359
|
-
Object.entries(colors).map(
|
|
360
|
-
([_, colorValue]) => {
|
|
361
|
-
var _a;
|
|
362
|
-
return (0, import_jsx_dom_cjs.h)("button", {
|
|
363
|
-
// @ts-expect-error JSX
|
|
364
|
-
type: "button",
|
|
365
|
-
className: "grid place-items-center size-6 rounded outline-none ring-offset-2 focus-visible:ring",
|
|
366
|
-
style: `background-color:${colorValue.backgroundColor};color:${colorValue.textColor || "inherit"};`,
|
|
367
|
-
innerHTML: (_a = colorValue.icon) != null ? _a : `<span class="text-md" style="color:${colorValue.textColor || "inherit"}">A</span>`,
|
|
368
|
-
onClick: (e) => {
|
|
369
|
-
e.stopPropagation();
|
|
370
|
-
onSelectColor(colorValue);
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
)
|
|
375
|
-
),
|
|
376
|
-
(0, import_jsx_dom_cjs.h)("hr", { className: "!my-2 border" })
|
|
377
|
-
]);
|
|
378
|
-
}
|
|
379
|
-
return (0, import_jsx_dom_cjs.h)(
|
|
380
|
-
"button",
|
|
381
|
-
{
|
|
382
|
-
// @ts-expect-error JSX
|
|
383
|
-
type: "button",
|
|
384
|
-
className: "w-full flex items-center gap-2 px-1 py-1.5 bg-background hover:bg-muted text-sm text-foreground rounded",
|
|
385
|
-
onClick: (e) => {
|
|
386
|
-
e.stopPropagation();
|
|
387
|
-
onClickItem(item);
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
[
|
|
391
|
-
(0, import_jsx_dom_cjs.h)("span", { className: "h-3 w-3 shrink-0", innerHTML: item.icon }),
|
|
392
|
-
(0, import_jsx_dom_cjs.h)("div", { className: "label" }, item.label)
|
|
393
|
-
]
|
|
394
|
-
);
|
|
395
|
-
})
|
|
396
|
-
);
|
|
332
|
+
return info;
|
|
397
333
|
}
|
|
398
|
-
function
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
colors,
|
|
404
|
-
appendTo
|
|
334
|
+
function TableNodeView({
|
|
335
|
+
editor,
|
|
336
|
+
node,
|
|
337
|
+
decorations,
|
|
338
|
+
getPos
|
|
405
339
|
}) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
});
|
|
415
|
-
const pop = new Popover(content, {
|
|
416
|
-
reference: triggerButton,
|
|
417
|
-
container: appendTo != null ? appendTo : void 0,
|
|
418
|
-
placement: "right",
|
|
419
|
-
offsetPx: 6,
|
|
420
|
-
interactive: true
|
|
340
|
+
const wrapperRef = (0, import_react4.useRef)(null);
|
|
341
|
+
const scrollRef = (0, import_react4.useRef)(null);
|
|
342
|
+
const isEditable = (0, import_react3.useEditorState)({
|
|
343
|
+
editor,
|
|
344
|
+
selector: ({ editor: e }) => {
|
|
345
|
+
var _a;
|
|
346
|
+
return (_a = e == null ? void 0 : e.isEditable) != null ? _a : false;
|
|
347
|
+
}
|
|
421
348
|
});
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
349
|
+
const cellMinWidth = (0, import_react4.useMemo)(() => {
|
|
350
|
+
var _a, _b, _c;
|
|
351
|
+
return (_c = (_b = (_a = editor.extensionManager.extensions.find((ext) => ext.name === "table")) == null ? void 0 : _a.options) == null ? void 0 : _b.cellMinWidth) != null ? _c : 100;
|
|
352
|
+
}, [editor]);
|
|
353
|
+
const map = (0, import_react4.useMemo)(() => import_tables3.TableMap.get(node), [node]);
|
|
354
|
+
const [isSideHovered, setIsSideHovered] = (0, import_react4.useState)(false);
|
|
355
|
+
const [isBottomHovered, setIsBottomHovered] = (0, import_react4.useState)(false);
|
|
356
|
+
const { hoveredTable, hoveredCell } = (0, import_react4.useMemo)(
|
|
357
|
+
() => extractHoverInfo(decorations),
|
|
358
|
+
[decorations]
|
|
359
|
+
);
|
|
360
|
+
const controlsDisabled = !hoveredTable || !hoveredCell;
|
|
361
|
+
(0, import_react4.useEffect)(() => {
|
|
362
|
+
var _a;
|
|
363
|
+
const table = (_a = scrollRef.current) == null ? void 0 : _a.querySelector("table");
|
|
364
|
+
if (!table) return;
|
|
365
|
+
let colgroup = table.querySelector("colgroup");
|
|
366
|
+
if (!colgroup) {
|
|
367
|
+
colgroup = document.createElement("colgroup");
|
|
368
|
+
table.insertBefore(colgroup, table.firstChild);
|
|
433
369
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
constructor(node, cellMinWidth, decorations, editor, getPos) {
|
|
438
|
-
__publicField(this, "node");
|
|
439
|
-
__publicField(this, "cellMinWidth");
|
|
440
|
-
__publicField(this, "decorations");
|
|
441
|
-
__publicField(this, "editor");
|
|
442
|
-
__publicField(this, "getPos");
|
|
443
|
-
__publicField(this, "hoveredCell", null);
|
|
444
|
-
__publicField(this, "map");
|
|
445
|
-
__publicField(this, "root");
|
|
446
|
-
__publicField(this, "table");
|
|
447
|
-
__publicField(this, "colgroup");
|
|
448
|
-
__publicField(this, "tbody");
|
|
449
|
-
__publicField(this, "rowsControl");
|
|
450
|
-
__publicField(this, "columnsControl");
|
|
451
|
-
__publicField(this, "columnsToolbox");
|
|
452
|
-
__publicField(this, "rowsToolbox");
|
|
453
|
-
__publicField(this, "controls");
|
|
454
|
-
var _a, _b, _c, _d;
|
|
455
|
-
this.node = node;
|
|
456
|
-
this.cellMinWidth = cellMinWidth;
|
|
457
|
-
this.decorations = decorations.slice();
|
|
458
|
-
this.editor = editor;
|
|
459
|
-
this.getPos = getPos;
|
|
460
|
-
this.hoveredCell = null;
|
|
461
|
-
this.map = import_tables.TableMap.get(node);
|
|
462
|
-
if (editor.isEditable) {
|
|
463
|
-
this.rowsControl = (0, import_jsx_dom_cjs.h)(
|
|
464
|
-
"div",
|
|
465
|
-
{ className: "rows-control" },
|
|
466
|
-
(0, import_jsx_dom_cjs.h)("button", {
|
|
467
|
-
// @ts-expect-error JSX
|
|
468
|
-
type: "button",
|
|
469
|
-
className: "rows-control-div",
|
|
470
|
-
onClick: () => this.selectRow(),
|
|
471
|
-
"aria-label": "Row actions"
|
|
472
|
-
})
|
|
473
|
-
);
|
|
474
|
-
this.columnsControl = (0, import_jsx_dom_cjs.h)(
|
|
475
|
-
"div",
|
|
476
|
-
{ className: "columns-control" },
|
|
477
|
-
(0, import_jsx_dom_cjs.h)("button", {
|
|
478
|
-
// @ts-expect-error JSX
|
|
479
|
-
type: "button",
|
|
480
|
-
className: "columns-control-div",
|
|
481
|
-
onClick: () => this.selectColumn(),
|
|
482
|
-
"aria-label": "Column actions"
|
|
483
|
-
})
|
|
484
|
-
);
|
|
485
|
-
this.controls = (0, import_jsx_dom_cjs.h)(
|
|
486
|
-
"div",
|
|
487
|
-
{ className: "table-controls", contentEditable: "false" },
|
|
488
|
-
this.rowsControl,
|
|
489
|
-
this.columnsControl
|
|
490
|
-
);
|
|
491
|
-
const palette = {
|
|
492
|
-
Blue: { backgroundColor: "#D9E4FF", textColor: "#171717" },
|
|
493
|
-
Orange: { backgroundColor: "#FFEDD5", textColor: "#171717" },
|
|
494
|
-
Grey: { backgroundColor: "#F1F1F1", textColor: "#171717" },
|
|
495
|
-
Yellow: { backgroundColor: "#FEF3C7", textColor: "#171717" },
|
|
496
|
-
Green: { backgroundColor: "#DCFCE7", textColor: "#171717" },
|
|
497
|
-
Red: { backgroundColor: "#FFDDDD", textColor: "#171717" },
|
|
498
|
-
Pink: { backgroundColor: "#FFE8FA", textColor: "#171717" },
|
|
499
|
-
Purple: { backgroundColor: "#E8DAFB", textColor: "#171717" },
|
|
500
|
-
None: {
|
|
501
|
-
backgroundColor: "transparent",
|
|
502
|
-
textColor: "inherit",
|
|
503
|
-
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="gray" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ban"><circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/></svg>`
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
this.columnsToolbox = createToolbox({
|
|
507
|
-
triggerButton: (_a = this.columnsControl) == null ? void 0 : _a.querySelector(
|
|
508
|
-
".columns-control-div"
|
|
509
|
-
),
|
|
510
|
-
items: columnsToolboxItems,
|
|
511
|
-
colors: palette,
|
|
512
|
-
appendTo: (_b = this.controls) != null ? _b : null,
|
|
513
|
-
onSelectColor: (color) => setCellsBackgroundColor(this.editor, color),
|
|
514
|
-
onClickItem: (item) => {
|
|
515
|
-
var _a2, _b2;
|
|
516
|
-
item.action({
|
|
517
|
-
editor: this.editor,
|
|
518
|
-
triggerButton: (_a2 = this.columnsControl) == null ? void 0 : _a2.firstElementChild,
|
|
519
|
-
controlsContainer: this.controls
|
|
520
|
-
});
|
|
521
|
-
(_b2 = this.columnsToolbox) == null ? void 0 : _b2.hide();
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
this.rowsToolbox = createToolbox({
|
|
525
|
-
triggerButton: (_c = this.rowsControl) == null ? void 0 : _c.querySelector(
|
|
526
|
-
".rows-control-div"
|
|
527
|
-
),
|
|
528
|
-
items: rowsToolboxItems,
|
|
529
|
-
colors: palette,
|
|
530
|
-
appendTo: (_d = this.controls) != null ? _d : null,
|
|
531
|
-
onSelectColor: (color) => setTableRowBackgroundColor(editor, color),
|
|
532
|
-
onClickItem: (item) => {
|
|
533
|
-
var _a2, _b2;
|
|
534
|
-
item.action({
|
|
535
|
-
editor: this.editor,
|
|
536
|
-
triggerButton: (_a2 = this.rowsControl) == null ? void 0 : _a2.firstElementChild,
|
|
537
|
-
controlsContainer: this.controls
|
|
538
|
-
});
|
|
539
|
-
(_b2 = this.rowsToolbox) == null ? void 0 : _b2.hide();
|
|
540
|
-
}
|
|
541
|
-
});
|
|
370
|
+
const width = map.width;
|
|
371
|
+
while (colgroup.children.length < width) {
|
|
372
|
+
colgroup.appendChild(document.createElement("col"));
|
|
542
373
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
null,
|
|
546
|
-
Array.from({ length: this.map.width }, () => 1).map(() => (0, import_jsx_dom_cjs.h)("col"))
|
|
547
|
-
);
|
|
548
|
-
this.tbody = (0, import_jsx_dom_cjs.h)("tbody");
|
|
549
|
-
this.table = (0, import_jsx_dom_cjs.h)(
|
|
550
|
-
"table",
|
|
551
|
-
null,
|
|
552
|
-
this.colgroup,
|
|
553
|
-
this.tbody
|
|
554
|
-
);
|
|
555
|
-
this.root = (0, import_jsx_dom_cjs.h)(
|
|
556
|
-
"div",
|
|
557
|
-
{
|
|
558
|
-
className: "table-wrapper horizontal-scrollbar scrollbar-md controls--disabled"
|
|
559
|
-
},
|
|
560
|
-
this.controls,
|
|
561
|
-
this.table
|
|
562
|
-
);
|
|
563
|
-
this.render();
|
|
564
|
-
}
|
|
565
|
-
get dom() {
|
|
566
|
-
return this.root;
|
|
567
|
-
}
|
|
568
|
-
get contentDOM() {
|
|
569
|
-
return this.tbody;
|
|
570
|
-
}
|
|
571
|
-
update(node, decorations) {
|
|
572
|
-
if (node.type !== this.node.type) return false;
|
|
573
|
-
this.node = node;
|
|
574
|
-
this.decorations = [...decorations];
|
|
575
|
-
this.map = import_tables.TableMap.get(this.node);
|
|
576
|
-
if (this.editor.isEditable) this.updateControls();
|
|
577
|
-
this.render();
|
|
578
|
-
return true;
|
|
579
|
-
}
|
|
580
|
-
render() {
|
|
581
|
-
if (this.colgroup.children.length !== this.map.width) {
|
|
582
|
-
const cols = Array.from({ length: this.map.width }, () => 1).map(
|
|
583
|
-
() => (0, import_jsx_dom_cjs.h)("col")
|
|
584
|
-
);
|
|
585
|
-
this.colgroup.replaceChildren(...cols);
|
|
374
|
+
while (colgroup.children.length > width) {
|
|
375
|
+
if (colgroup.lastChild) colgroup.removeChild(colgroup.lastChild);
|
|
586
376
|
}
|
|
587
|
-
(0,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
var _a;
|
|
599
|
-
const { hoveredTable: table, hoveredCell: cell } = Object.values(
|
|
600
|
-
this.decorations
|
|
601
|
-
).reduce(
|
|
602
|
-
(acc, curr) => {
|
|
603
|
-
if (curr.spec.hoveredCell !== void 0)
|
|
604
|
-
acc.hoveredCell = curr.spec.hoveredCell;
|
|
605
|
-
if (curr.spec.hoveredTable !== void 0)
|
|
606
|
-
acc.hoveredTable = curr.spec.hoveredTable;
|
|
607
|
-
return acc;
|
|
608
|
-
},
|
|
609
|
-
{}
|
|
610
|
-
);
|
|
611
|
-
if (table === void 0 || cell === void 0) {
|
|
612
|
-
this.root.classList.add("controls--disabled");
|
|
377
|
+
(0, import_tables3.updateColumnsOnResize)(node, colgroup, table, cellMinWidth);
|
|
378
|
+
}, [node, map.width, cellMinWidth]);
|
|
379
|
+
const [controlPos, setControlPos] = (0, import_react4.useState)(null);
|
|
380
|
+
const updatePositions = (0, import_react4.useCallback)(() => {
|
|
381
|
+
if (!hoveredCell || !wrapperRef.current) {
|
|
382
|
+
setControlPos(null);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const cellDom = editor.view.nodeDOM(hoveredCell.pos);
|
|
386
|
+
if (!cellDom) {
|
|
387
|
+
setControlPos(null);
|
|
613
388
|
return;
|
|
614
389
|
}
|
|
615
|
-
|
|
616
|
-
this.hoveredCell = cell;
|
|
617
|
-
const cellDom = this.editor.view.nodeDOM(cell.pos);
|
|
618
|
-
if (!this.table || !cellDom) return;
|
|
619
|
-
const tableRect = this.table.getBoundingClientRect();
|
|
390
|
+
const wrapperRect = wrapperRef.current.getBoundingClientRect();
|
|
620
391
|
const cellRect = cellDom.getBoundingClientRect();
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
392
|
+
setControlPos({
|
|
393
|
+
columnLeft: cellRect.left - wrapperRect.left,
|
|
394
|
+
columnWidth: cellRect.width,
|
|
395
|
+
rowTop: cellRect.top - wrapperRect.top,
|
|
396
|
+
rowHeight: cellRect.height
|
|
397
|
+
});
|
|
398
|
+
}, [hoveredCell, editor.view]);
|
|
399
|
+
(0, import_react4.useEffect)(() => {
|
|
400
|
+
updatePositions();
|
|
401
|
+
const scrollEl = scrollRef.current;
|
|
402
|
+
if (!scrollEl) return;
|
|
403
|
+
scrollEl.addEventListener("scroll", updatePositions, { passive: true });
|
|
404
|
+
return () => scrollEl.removeEventListener("scroll", updatePositions);
|
|
405
|
+
}, [updatePositions]);
|
|
406
|
+
const handleMouseMove = (0, import_react4.useCallback)(
|
|
407
|
+
(e) => {
|
|
408
|
+
if (!isEditable) return;
|
|
409
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
410
|
+
const x = e.clientX - rect.left;
|
|
411
|
+
const y = e.clientY - rect.top;
|
|
412
|
+
const threshold = 50;
|
|
413
|
+
setIsSideHovered(x >= rect.width - threshold);
|
|
414
|
+
setIsBottomHovered(y >= rect.height - threshold);
|
|
415
|
+
},
|
|
416
|
+
[isEditable]
|
|
417
|
+
);
|
|
418
|
+
const handleMouseLeave = (0, import_react4.useCallback)((e) => {
|
|
419
|
+
const relatedTarget = e.relatedTarget;
|
|
420
|
+
const currentTarget = e.currentTarget;
|
|
421
|
+
if (relatedTarget instanceof Node && currentTarget instanceof Node && currentTarget.contains(relatedTarget)) {
|
|
422
|
+
return;
|
|
624
423
|
}
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
this.rowsControl.style.height = `${cellRect.height}px`;
|
|
424
|
+
if (wrapperRef.current && relatedTarget instanceof Node && wrapperRef.current.contains(relatedTarget)) {
|
|
425
|
+
return;
|
|
628
426
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
);
|
|
650
|
-
const headCellPos = this.map.map[anchorCellIndex + (this.map.width - 1)] + (this.getPos() + 1);
|
|
651
|
-
const cellSelection = import_tables.CellSelection.create(
|
|
652
|
-
this.editor.state.doc,
|
|
653
|
-
anchorCellPos,
|
|
654
|
-
headCellPos
|
|
655
|
-
);
|
|
656
|
-
this.editor.view.dispatch(
|
|
657
|
-
this.editor.view.state.tr.setSelection(cellSelection)
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
// src/table/utilities/insert-line-above-table-action.ts
|
|
663
|
-
var import_editor_utils = require("@kopexa/editor-utils");
|
|
664
|
-
var insertLineAboveTableAction = ({
|
|
665
|
-
editor
|
|
666
|
-
}) => {
|
|
667
|
-
if (!editor.isActive("table")) return false;
|
|
668
|
-
try {
|
|
669
|
-
const { selection } = editor.state;
|
|
670
|
-
const tableNode = (0, import_editor_utils.findParentNodeOfType)(selection, "table");
|
|
671
|
-
if (!tableNode) return false;
|
|
672
|
-
const tablePos = tableNode.pos;
|
|
673
|
-
const firstRow = tableNode.node.child(0);
|
|
674
|
-
const selectionPath = selection.$anchor.path;
|
|
675
|
-
const selectionInFirstRow = selectionPath.includes(firstRow);
|
|
676
|
-
if (!selectionInFirstRow) return false;
|
|
677
|
-
if (tablePos === 0) {
|
|
678
|
-
editor.chain().insertContentAt(tablePos, { type: "paragraph" }).run();
|
|
679
|
-
editor.chain().setTextSelection(tablePos + 1).run();
|
|
680
|
-
} else {
|
|
681
|
-
const prevNodePos = tablePos - 1;
|
|
682
|
-
if (prevNodePos <= 0) return false;
|
|
683
|
-
const prevNode = editor.state.doc.nodeAt(prevNodePos - 1);
|
|
684
|
-
if (prevNode && prevNode.type.name === "paragraph") {
|
|
685
|
-
const endOfParagraphPos = tablePos - prevNode.nodeSize;
|
|
686
|
-
editor.chain().setTextSelection(endOfParagraphPos).run();
|
|
687
|
-
} else {
|
|
688
|
-
return false;
|
|
427
|
+
setIsSideHovered(false);
|
|
428
|
+
setIsBottomHovered(false);
|
|
429
|
+
}, []);
|
|
430
|
+
const focusTable = (0, import_react4.useCallback)(() => {
|
|
431
|
+
const pos = getPos();
|
|
432
|
+
if (pos === void 0) return false;
|
|
433
|
+
try {
|
|
434
|
+
const resolvedPos = editor.state.doc.resolve(pos + 1);
|
|
435
|
+
const table = resolvedPos.node(1);
|
|
436
|
+
if ((table == null ? void 0 : table.type.name) === "table") {
|
|
437
|
+
let cellPos = pos + 1;
|
|
438
|
+
table.descendants((n, nodePos) => {
|
|
439
|
+
if (n.type.name === "tableCell" || n.type.name === "tableHeader") {
|
|
440
|
+
cellPos = pos + 1 + nodePos + 1;
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
});
|
|
445
|
+
editor.chain().focus().setTextSelection(cellPos).run();
|
|
446
|
+
return true;
|
|
689
447
|
}
|
|
448
|
+
} catch {
|
|
690
449
|
}
|
|
691
|
-
return true;
|
|
692
|
-
} catch (e) {
|
|
693
|
-
console.error("failed to insert line above table", e);
|
|
694
450
|
return false;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
var import_editor_utils2 = require("@kopexa/editor-utils");
|
|
700
|
-
var insertLineBelowTableAction = ({
|
|
701
|
-
editor
|
|
702
|
-
}) => {
|
|
703
|
-
if (!editor.isActive("table")) return false;
|
|
704
|
-
try {
|
|
705
|
-
const { selection } = editor.state;
|
|
706
|
-
const tableNode = (0, import_editor_utils2.findParentNodeOfType)(selection, "table");
|
|
707
|
-
if (!tableNode) return false;
|
|
708
|
-
const tablePos = tableNode.pos;
|
|
709
|
-
const table = tableNode.node;
|
|
710
|
-
const rowCount = table.childCount;
|
|
711
|
-
const lastRow = table.child(rowCount - 1);
|
|
712
|
-
const selectionPath = selection.$anchor.path;
|
|
713
|
-
const selectionInLastRow = selectionPath.includes(lastRow);
|
|
714
|
-
if (!selectionInLastRow) return false;
|
|
715
|
-
const nextNodePos = tablePos + table.nodeSize;
|
|
716
|
-
const nextNode = editor.state.doc.nodeAt(nextNodePos);
|
|
717
|
-
if (nextNode && nextNode.type.name === "paragraph") {
|
|
718
|
-
const endOfParagraphPos = nextNodePos + nextNode.nodeSize - 1;
|
|
719
|
-
editor.chain().setTextSelection(endOfParagraphPos).run();
|
|
720
|
-
} else if (!nextNode) {
|
|
721
|
-
editor.chain().insertContentAt(nextNodePos, { type: "paragraph" }).run();
|
|
722
|
-
editor.chain().setTextSelection(nextNodePos + 1).run();
|
|
451
|
+
}, [editor, getPos]);
|
|
452
|
+
const handleAddColumn = (0, import_react4.useCallback)(() => {
|
|
453
|
+
if (focusTable()) {
|
|
454
|
+
editor.chain().addColumnAfter().run();
|
|
723
455
|
} else {
|
|
724
|
-
|
|
456
|
+
editor.chain().focus().addColumnAfter().run();
|
|
725
457
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
458
|
+
}, [editor, focusTable]);
|
|
459
|
+
const handleAddRow = (0, import_react4.useCallback)(() => {
|
|
460
|
+
if (focusTable()) {
|
|
461
|
+
editor.chain().addRowAfter().run();
|
|
462
|
+
} else {
|
|
463
|
+
editor.chain().focus().addRowAfter().run();
|
|
464
|
+
}
|
|
465
|
+
}, [editor, focusTable]);
|
|
466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
467
|
+
import_react3.NodeViewWrapper,
|
|
468
|
+
{
|
|
469
|
+
ref: wrapperRef,
|
|
470
|
+
className: [
|
|
471
|
+
"table-node-view pr-6 pb-6",
|
|
472
|
+
controlsDisabled ? "controls--disabled" : ""
|
|
473
|
+
].join(" "),
|
|
474
|
+
onMouseEnter: handleMouseMove,
|
|
475
|
+
onMouseMove: handleMouseMove,
|
|
476
|
+
onMouseLeave: handleMouseLeave,
|
|
477
|
+
"data-type": "table",
|
|
478
|
+
children: [
|
|
479
|
+
isEditable && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "table-controls", contentEditable: false, children: [
|
|
480
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
481
|
+
"div",
|
|
482
|
+
{
|
|
483
|
+
className: "rows-control",
|
|
484
|
+
style: controlPos ? {
|
|
485
|
+
top: `${controlPos.rowTop}px`,
|
|
486
|
+
height: `${controlPos.rowHeight}px`
|
|
487
|
+
} : void 0,
|
|
488
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TableRowMenu, { editor, cellPos: hoveredCell == null ? void 0 : hoveredCell.pos })
|
|
489
|
+
}
|
|
490
|
+
),
|
|
491
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
492
|
+
"div",
|
|
493
|
+
{
|
|
494
|
+
className: "columns-control",
|
|
495
|
+
style: controlPos ? {
|
|
496
|
+
left: `${controlPos.columnLeft}px`,
|
|
497
|
+
width: `${controlPos.columnWidth}px`
|
|
498
|
+
} : void 0,
|
|
499
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TableColumnMenu, { editor, cellPos: hoveredCell == null ? void 0 : hoveredCell.pos })
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
] }),
|
|
503
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
504
|
+
"div",
|
|
505
|
+
{
|
|
506
|
+
ref: scrollRef,
|
|
507
|
+
className: "table-wrapper horizontal-scrollbar scrollbar-md",
|
|
508
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react3.NodeViewContent, { as: "table" })
|
|
509
|
+
}
|
|
510
|
+
),
|
|
511
|
+
isEditable && isSideHovered && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
512
|
+
"div",
|
|
513
|
+
{
|
|
514
|
+
className: "absolute -right-6 top-0 h-full flex items-center",
|
|
515
|
+
contentEditable: false,
|
|
516
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
517
|
+
"button",
|
|
518
|
+
{
|
|
519
|
+
type: "button",
|
|
520
|
+
className: "w-4 h-full hover:bg-accent cursor-pointer flex items-center justify-center rounded-sm transition-colors text-muted-foreground text-xs",
|
|
521
|
+
onClick: handleAddColumn,
|
|
522
|
+
"aria-label": "Add column",
|
|
523
|
+
children: "+"
|
|
524
|
+
}
|
|
525
|
+
)
|
|
526
|
+
}
|
|
527
|
+
),
|
|
528
|
+
isEditable && isBottomHovered && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
529
|
+
"div",
|
|
530
|
+
{
|
|
531
|
+
className: "absolute -bottom-6 left-0 w-full flex justify-center",
|
|
532
|
+
contentEditable: false,
|
|
533
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
534
|
+
"button",
|
|
535
|
+
{
|
|
536
|
+
type: "button",
|
|
537
|
+
className: "h-4 w-full hover:bg-accent cursor-pointer flex items-center justify-center rounded-sm transition-colors text-muted-foreground text-xs",
|
|
538
|
+
onClick: handleAddRow,
|
|
539
|
+
"aria-label": "Add row",
|
|
540
|
+
children: "+"
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
)
|
|
545
|
+
]
|
|
546
|
+
}
|
|
547
|
+
);
|
|
548
|
+
}
|
|
732
549
|
|
|
733
550
|
// src/table/table.ts
|
|
734
551
|
var Table = import_extension_table.Table.extend({
|
|
@@ -770,32 +587,30 @@ var Table = import_extension_table.Table.extend({
|
|
|
770
587
|
};
|
|
771
588
|
},
|
|
772
589
|
addNodeView() {
|
|
773
|
-
return (
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
};
|
|
590
|
+
return (0, import_react5.ReactNodeViewRenderer)(TableNodeView, {
|
|
591
|
+
contentDOMElementTag: "tbody",
|
|
592
|
+
stopEvent: ({ event }) => {
|
|
593
|
+
const target = event.target;
|
|
594
|
+
if (target.closest("button, [role='button'], input, a")) {
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
});
|
|
784
600
|
},
|
|
785
601
|
addProseMirrorPlugins() {
|
|
786
602
|
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
787
603
|
const plugins = [
|
|
788
|
-
(0,
|
|
604
|
+
(0, import_tables4.tableEditing)({
|
|
789
605
|
allowTableNodeSelection: this.options.allowTableNodeSelection
|
|
790
606
|
}),
|
|
791
607
|
tableControls()
|
|
792
608
|
];
|
|
793
609
|
if (isResizable) {
|
|
794
610
|
plugins.unshift(
|
|
795
|
-
(0,
|
|
611
|
+
(0, import_tables4.columnResizing)({
|
|
796
612
|
handleWidth: this.options.handleWidth,
|
|
797
613
|
cellMinWidth: this.options.cellMinWidth,
|
|
798
|
-
// View: TableView,
|
|
799
614
|
lastColumnResizable: this.options.lastColumnResizable
|
|
800
615
|
})
|
|
801
616
|
);
|
|
@@ -805,5 +620,6 @@ var Table = import_extension_table.Table.extend({
|
|
|
805
620
|
});
|
|
806
621
|
// Annotate the CommonJS export names for ESM import in node:
|
|
807
622
|
0 && (module.exports = {
|
|
808
|
-
Table
|
|
623
|
+
Table,
|
|
624
|
+
TableNodeView
|
|
809
625
|
});
|