@kopexa/extension-table 17.0.45 → 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
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
TableCell
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DR2GZJH6.mjs";
|
|
5
5
|
import {
|
|
6
6
|
TableHeader
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-POJFNXG7.mjs";
|
|
8
8
|
import {
|
|
9
9
|
TableRow
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HWVA6DOK.mjs";
|
|
11
11
|
import {
|
|
12
12
|
Table
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-LPHCE6EI.mjs";
|
|
14
14
|
|
|
15
15
|
// src/kit.ts
|
|
16
16
|
import { Extension } from "@tiptap/react";
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__publicField
|
|
4
4
|
} from "./chunk-WKV76XOR.mjs";
|
|
5
5
|
|
|
6
|
-
// src/table/table-controls.ts
|
|
6
|
+
// src/table/lib/table-controls.ts
|
|
7
7
|
import { findParentNode } from "@tiptap/core";
|
|
8
8
|
import {
|
|
9
9
|
Plugin,
|
|
@@ -28,7 +28,7 @@ function tableControls() {
|
|
|
28
28
|
mousemove: (view, event) => {
|
|
29
29
|
var _a;
|
|
30
30
|
const pluginState = key.getState(view.state);
|
|
31
|
-
if (!event.target.closest(".table-
|
|
31
|
+
if (!event.target.closest(".table-node-view") && pluginState.values.hoveredTable) {
|
|
32
32
|
return view.dispatch(
|
|
33
33
|
view.state.tr.setMeta(key, {
|
|
34
34
|
setHoveredTable: null,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/table-cell.ts
|
|
4
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
5
|
+
var TableCell = Node.create({
|
|
6
|
+
name: "tableCell",
|
|
7
|
+
content: "block+",
|
|
8
|
+
tableRole: "cell",
|
|
9
|
+
isolating: true,
|
|
10
|
+
addOptions() {
|
|
11
|
+
return {
|
|
12
|
+
HTMLAttributes: {}
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
parseHTML() {
|
|
16
|
+
return [{ tag: "td" }];
|
|
17
|
+
},
|
|
18
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
19
|
+
const attrs = {};
|
|
20
|
+
if (node.attrs.align) {
|
|
21
|
+
attrs["data-align"] = node.attrs.align;
|
|
22
|
+
attrs.style = `text-align: ${node.attrs.align}`;
|
|
23
|
+
}
|
|
24
|
+
if (node.attrs.backgroundColor) {
|
|
25
|
+
attrs["data-background-color"] = node.attrs.backgroundColor;
|
|
26
|
+
}
|
|
27
|
+
return [
|
|
28
|
+
"td",
|
|
29
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, attrs),
|
|
30
|
+
0
|
|
31
|
+
];
|
|
32
|
+
},
|
|
33
|
+
addAttributes() {
|
|
34
|
+
return {
|
|
35
|
+
colspan: {
|
|
36
|
+
default: 1,
|
|
37
|
+
parseHTML: (element) => {
|
|
38
|
+
const colspan = element.getAttribute("colspan");
|
|
39
|
+
return colspan ? Number.parseInt(colspan, 10) : 1;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
rowspan: {
|
|
43
|
+
default: 1,
|
|
44
|
+
parseHTML: (element) => {
|
|
45
|
+
const rowspan = element.getAttribute("rowspan");
|
|
46
|
+
return rowspan ? Number.parseInt(rowspan, 10) : 1;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
colwidth: {
|
|
50
|
+
default: null,
|
|
51
|
+
parseHTML: (element) => {
|
|
52
|
+
const colwidth = element.getAttribute("colwidth");
|
|
53
|
+
return colwidth ? colwidth.split(",").map((w) => Number.parseInt(w, 10)) : null;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
align: {
|
|
57
|
+
default: null,
|
|
58
|
+
parseHTML: (element) => element.getAttribute("data-align")
|
|
59
|
+
},
|
|
60
|
+
backgroundColor: {
|
|
61
|
+
default: null,
|
|
62
|
+
parseHTML: (element) => element.getAttribute("data-background-color")
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
TableCell
|
|
70
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
TableRowMenu
|
|
4
|
+
} from "./chunk-KNOMCS6F.mjs";
|
|
5
|
+
import {
|
|
6
|
+
TableColumnMenu
|
|
7
|
+
} from "./chunk-QHD3QTD2.mjs";
|
|
8
|
+
|
|
9
|
+
// src/table/views/table-node-view.tsx
|
|
10
|
+
import { TableMap, updateColumnsOnResize } from "@tiptap/pm/tables";
|
|
11
|
+
import {
|
|
12
|
+
NodeViewContent,
|
|
13
|
+
NodeViewWrapper,
|
|
14
|
+
useEditorState
|
|
15
|
+
} from "@tiptap/react";
|
|
16
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
function extractHoverInfo(decorations) {
|
|
19
|
+
const info = {};
|
|
20
|
+
for (const dec of decorations) {
|
|
21
|
+
const spec = dec.spec;
|
|
22
|
+
if ((spec == null ? void 0 : spec.hoveredCell) !== void 0)
|
|
23
|
+
info.hoveredCell = spec.hoveredCell;
|
|
24
|
+
if ((spec == null ? void 0 : spec.hoveredTable) !== void 0)
|
|
25
|
+
info.hoveredTable = spec.hoveredTable;
|
|
26
|
+
}
|
|
27
|
+
return info;
|
|
28
|
+
}
|
|
29
|
+
function TableNodeView({
|
|
30
|
+
editor,
|
|
31
|
+
node,
|
|
32
|
+
decorations,
|
|
33
|
+
getPos
|
|
34
|
+
}) {
|
|
35
|
+
const wrapperRef = useRef(null);
|
|
36
|
+
const scrollRef = useRef(null);
|
|
37
|
+
const isEditable = useEditorState({
|
|
38
|
+
editor,
|
|
39
|
+
selector: ({ editor: e }) => {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = e == null ? void 0 : e.isEditable) != null ? _a : false;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const cellMinWidth = useMemo(() => {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
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;
|
|
47
|
+
}, [editor]);
|
|
48
|
+
const map = useMemo(() => TableMap.get(node), [node]);
|
|
49
|
+
const [isSideHovered, setIsSideHovered] = useState(false);
|
|
50
|
+
const [isBottomHovered, setIsBottomHovered] = useState(false);
|
|
51
|
+
const { hoveredTable, hoveredCell } = useMemo(
|
|
52
|
+
() => extractHoverInfo(decorations),
|
|
53
|
+
[decorations]
|
|
54
|
+
);
|
|
55
|
+
const controlsDisabled = !hoveredTable || !hoveredCell;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
var _a;
|
|
58
|
+
const table = (_a = scrollRef.current) == null ? void 0 : _a.querySelector("table");
|
|
59
|
+
if (!table) return;
|
|
60
|
+
let colgroup = table.querySelector("colgroup");
|
|
61
|
+
if (!colgroup) {
|
|
62
|
+
colgroup = document.createElement("colgroup");
|
|
63
|
+
table.insertBefore(colgroup, table.firstChild);
|
|
64
|
+
}
|
|
65
|
+
const width = map.width;
|
|
66
|
+
while (colgroup.children.length < width) {
|
|
67
|
+
colgroup.appendChild(document.createElement("col"));
|
|
68
|
+
}
|
|
69
|
+
while (colgroup.children.length > width) {
|
|
70
|
+
if (colgroup.lastChild) colgroup.removeChild(colgroup.lastChild);
|
|
71
|
+
}
|
|
72
|
+
updateColumnsOnResize(node, colgroup, table, cellMinWidth);
|
|
73
|
+
}, [node, map.width, cellMinWidth]);
|
|
74
|
+
const [controlPos, setControlPos] = useState(null);
|
|
75
|
+
const updatePositions = useCallback(() => {
|
|
76
|
+
if (!hoveredCell || !wrapperRef.current) {
|
|
77
|
+
setControlPos(null);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const cellDom = editor.view.nodeDOM(hoveredCell.pos);
|
|
81
|
+
if (!cellDom) {
|
|
82
|
+
setControlPos(null);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const wrapperRect = wrapperRef.current.getBoundingClientRect();
|
|
86
|
+
const cellRect = cellDom.getBoundingClientRect();
|
|
87
|
+
setControlPos({
|
|
88
|
+
columnLeft: cellRect.left - wrapperRect.left,
|
|
89
|
+
columnWidth: cellRect.width,
|
|
90
|
+
rowTop: cellRect.top - wrapperRect.top,
|
|
91
|
+
rowHeight: cellRect.height
|
|
92
|
+
});
|
|
93
|
+
}, [hoveredCell, editor.view]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
updatePositions();
|
|
96
|
+
const scrollEl = scrollRef.current;
|
|
97
|
+
if (!scrollEl) return;
|
|
98
|
+
scrollEl.addEventListener("scroll", updatePositions, { passive: true });
|
|
99
|
+
return () => scrollEl.removeEventListener("scroll", updatePositions);
|
|
100
|
+
}, [updatePositions]);
|
|
101
|
+
const handleMouseMove = useCallback(
|
|
102
|
+
(e) => {
|
|
103
|
+
if (!isEditable) return;
|
|
104
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
105
|
+
const x = e.clientX - rect.left;
|
|
106
|
+
const y = e.clientY - rect.top;
|
|
107
|
+
const threshold = 50;
|
|
108
|
+
setIsSideHovered(x >= rect.width - threshold);
|
|
109
|
+
setIsBottomHovered(y >= rect.height - threshold);
|
|
110
|
+
},
|
|
111
|
+
[isEditable]
|
|
112
|
+
);
|
|
113
|
+
const handleMouseLeave = useCallback((e) => {
|
|
114
|
+
const relatedTarget = e.relatedTarget;
|
|
115
|
+
const currentTarget = e.currentTarget;
|
|
116
|
+
if (relatedTarget instanceof Node && currentTarget instanceof Node && currentTarget.contains(relatedTarget)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (wrapperRef.current && relatedTarget instanceof Node && wrapperRef.current.contains(relatedTarget)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
setIsSideHovered(false);
|
|
123
|
+
setIsBottomHovered(false);
|
|
124
|
+
}, []);
|
|
125
|
+
const focusTable = useCallback(() => {
|
|
126
|
+
const pos = getPos();
|
|
127
|
+
if (pos === void 0) return false;
|
|
128
|
+
try {
|
|
129
|
+
const resolvedPos = editor.state.doc.resolve(pos + 1);
|
|
130
|
+
const table = resolvedPos.node(1);
|
|
131
|
+
if ((table == null ? void 0 : table.type.name) === "table") {
|
|
132
|
+
let cellPos = pos + 1;
|
|
133
|
+
table.descendants((n, nodePos) => {
|
|
134
|
+
if (n.type.name === "tableCell" || n.type.name === "tableHeader") {
|
|
135
|
+
cellPos = pos + 1 + nodePos + 1;
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
140
|
+
editor.chain().focus().setTextSelection(cellPos).run();
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}, [editor, getPos]);
|
|
147
|
+
const handleAddColumn = useCallback(() => {
|
|
148
|
+
if (focusTable()) {
|
|
149
|
+
editor.chain().addColumnAfter().run();
|
|
150
|
+
} else {
|
|
151
|
+
editor.chain().focus().addColumnAfter().run();
|
|
152
|
+
}
|
|
153
|
+
}, [editor, focusTable]);
|
|
154
|
+
const handleAddRow = useCallback(() => {
|
|
155
|
+
if (focusTable()) {
|
|
156
|
+
editor.chain().addRowAfter().run();
|
|
157
|
+
} else {
|
|
158
|
+
editor.chain().focus().addRowAfter().run();
|
|
159
|
+
}
|
|
160
|
+
}, [editor, focusTable]);
|
|
161
|
+
return /* @__PURE__ */ jsxs(
|
|
162
|
+
NodeViewWrapper,
|
|
163
|
+
{
|
|
164
|
+
ref: wrapperRef,
|
|
165
|
+
className: [
|
|
166
|
+
"table-node-view pr-6 pb-6",
|
|
167
|
+
controlsDisabled ? "controls--disabled" : ""
|
|
168
|
+
].join(" "),
|
|
169
|
+
onMouseEnter: handleMouseMove,
|
|
170
|
+
onMouseMove: handleMouseMove,
|
|
171
|
+
onMouseLeave: handleMouseLeave,
|
|
172
|
+
"data-type": "table",
|
|
173
|
+
children: [
|
|
174
|
+
isEditable && /* @__PURE__ */ jsxs("div", { className: "table-controls", contentEditable: false, children: [
|
|
175
|
+
/* @__PURE__ */ jsx(
|
|
176
|
+
"div",
|
|
177
|
+
{
|
|
178
|
+
className: "rows-control",
|
|
179
|
+
style: controlPos ? {
|
|
180
|
+
top: `${controlPos.rowTop}px`,
|
|
181
|
+
height: `${controlPos.rowHeight}px`
|
|
182
|
+
} : void 0,
|
|
183
|
+
children: /* @__PURE__ */ jsx(TableRowMenu, { editor, cellPos: hoveredCell == null ? void 0 : hoveredCell.pos })
|
|
184
|
+
}
|
|
185
|
+
),
|
|
186
|
+
/* @__PURE__ */ jsx(
|
|
187
|
+
"div",
|
|
188
|
+
{
|
|
189
|
+
className: "columns-control",
|
|
190
|
+
style: controlPos ? {
|
|
191
|
+
left: `${controlPos.columnLeft}px`,
|
|
192
|
+
width: `${controlPos.columnWidth}px`
|
|
193
|
+
} : void 0,
|
|
194
|
+
children: /* @__PURE__ */ jsx(TableColumnMenu, { editor, cellPos: hoveredCell == null ? void 0 : hoveredCell.pos })
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
] }),
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
"div",
|
|
200
|
+
{
|
|
201
|
+
ref: scrollRef,
|
|
202
|
+
className: "table-wrapper horizontal-scrollbar scrollbar-md",
|
|
203
|
+
children: /* @__PURE__ */ jsx(NodeViewContent, { as: "table" })
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
isEditable && isSideHovered && /* @__PURE__ */ jsx(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
className: "absolute -right-6 top-0 h-full flex items-center",
|
|
210
|
+
contentEditable: false,
|
|
211
|
+
children: /* @__PURE__ */ jsx(
|
|
212
|
+
"button",
|
|
213
|
+
{
|
|
214
|
+
type: "button",
|
|
215
|
+
className: "w-4 h-full hover:bg-accent cursor-pointer flex items-center justify-center rounded-sm transition-colors text-muted-foreground text-xs",
|
|
216
|
+
onClick: handleAddColumn,
|
|
217
|
+
"aria-label": "Add column",
|
|
218
|
+
children: "+"
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
isEditable && isBottomHovered && /* @__PURE__ */ jsx(
|
|
224
|
+
"div",
|
|
225
|
+
{
|
|
226
|
+
className: "absolute -bottom-6 left-0 w-full flex justify-center",
|
|
227
|
+
contentEditable: false,
|
|
228
|
+
children: /* @__PURE__ */ jsx(
|
|
229
|
+
"button",
|
|
230
|
+
{
|
|
231
|
+
type: "button",
|
|
232
|
+
className: "h-4 w-full hover:bg-accent cursor-pointer flex items-center justify-center rounded-sm transition-colors text-muted-foreground text-xs",
|
|
233
|
+
onClick: handleAddRow,
|
|
234
|
+
"aria-label": "Add row",
|
|
235
|
+
children: "+"
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export {
|
|
246
|
+
TableNodeView
|
|
247
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/table-row.ts
|
|
4
|
+
import { TableRow as TiptapTableRow } from "@tiptap/extension-table";
|
|
5
|
+
var TableRow = TiptapTableRow.extend({
|
|
6
|
+
content: "(tableCell | tableHeader)*",
|
|
7
|
+
addOptions() {
|
|
8
|
+
var _a;
|
|
9
|
+
return {
|
|
10
|
+
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
11
|
+
HTMLAttributes: {
|
|
12
|
+
class: "min-w-full"
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
TableRow
|
|
20
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/table/views/table-row-menu.tsx
|
|
4
|
+
import { DropdownMenu } from "@kopexa/dropdown-menu";
|
|
5
|
+
import { toggleHeaderRow as pmToggleHeaderRow } from "@tiptap/pm/tables";
|
|
6
|
+
import { useCallback, useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function TableRowMenu({ editor, cellPos, style }) {
|
|
9
|
+
const [open, setOpen] = useState(false);
|
|
10
|
+
const chainAtCell = useCallback(() => {
|
|
11
|
+
const chain = editor.chain().focus();
|
|
12
|
+
if (cellPos != null) {
|
|
13
|
+
return chain.setTextSelection(cellPos + 1);
|
|
14
|
+
}
|
|
15
|
+
return chain;
|
|
16
|
+
}, [editor, cellPos]);
|
|
17
|
+
const handleToggleHeader = useCallback(() => {
|
|
18
|
+
chainAtCell().command(({ state, dispatch }) => pmToggleHeaderRow(state, dispatch)).run();
|
|
19
|
+
setOpen(false);
|
|
20
|
+
}, [chainAtCell]);
|
|
21
|
+
const handleAddAbove = useCallback(() => {
|
|
22
|
+
chainAtCell().addRowBefore().run();
|
|
23
|
+
setOpen(false);
|
|
24
|
+
}, [chainAtCell]);
|
|
25
|
+
const handleAddBelow = useCallback(() => {
|
|
26
|
+
chainAtCell().addRowAfter().run();
|
|
27
|
+
setOpen(false);
|
|
28
|
+
}, [chainAtCell]);
|
|
29
|
+
const handleDelete = useCallback(() => {
|
|
30
|
+
chainAtCell().deleteRow().run();
|
|
31
|
+
setOpen(false);
|
|
32
|
+
}, [chainAtCell]);
|
|
33
|
+
return /* @__PURE__ */ jsxs(DropdownMenu.Root, { open, onOpenChange: setOpen, children: [
|
|
34
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
35
|
+
"button",
|
|
36
|
+
{
|
|
37
|
+
type: "button",
|
|
38
|
+
className: "rows-control-div",
|
|
39
|
+
"aria-label": "Row actions",
|
|
40
|
+
style
|
|
41
|
+
}
|
|
42
|
+
) }),
|
|
43
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
44
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
|
|
45
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleToggleHeader, children: "Toggle header row" }),
|
|
46
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleAddAbove, children: "Insert row above" }),
|
|
47
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleAddBelow, children: "Insert row below" })
|
|
48
|
+
] }),
|
|
49
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
50
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { variant: "destructive", onSelect: handleDelete, children: "Delete row" })
|
|
51
|
+
] })
|
|
52
|
+
] });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
TableRowMenu
|
|
57
|
+
};
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
TableNodeView
|
|
4
|
+
} from "./chunk-GHOJLOCF.mjs";
|
|
5
5
|
import {
|
|
6
6
|
insertLineAboveTableAction
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3XEOCAHB.mjs";
|
|
8
8
|
import {
|
|
9
9
|
insertLineBelowTableAction
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-KLUH6EZS.mjs";
|
|
11
11
|
import {
|
|
12
12
|
tableControls
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BTJ3DCGC.mjs";
|
|
14
14
|
|
|
15
15
|
// src/table/table.ts
|
|
16
16
|
import { Table as TiptapTable } from "@tiptap/extension-table";
|
|
17
17
|
import { columnResizing, tableEditing } from "@tiptap/pm/tables";
|
|
18
|
+
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
18
19
|
var Table = TiptapTable.extend({
|
|
19
20
|
addOptions() {
|
|
20
21
|
var _a;
|
|
@@ -54,17 +55,16 @@ var Table = TiptapTable.extend({
|
|
|
54
55
|
};
|
|
55
56
|
},
|
|
56
57
|
addNodeView() {
|
|
57
|
-
return (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
58
|
+
return ReactNodeViewRenderer(TableNodeView, {
|
|
59
|
+
contentDOMElementTag: "tbody",
|
|
60
|
+
stopEvent: ({ event }) => {
|
|
61
|
+
const target = event.target;
|
|
62
|
+
if (target.closest("button, [role='button'], input, a")) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
68
|
},
|
|
69
69
|
addProseMirrorPlugins() {
|
|
70
70
|
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
@@ -79,7 +79,6 @@ var Table = TiptapTable.extend({
|
|
|
79
79
|
columnResizing({
|
|
80
80
|
handleWidth: this.options.handleWidth,
|
|
81
81
|
cellMinWidth: this.options.cellMinWidth,
|
|
82
|
-
// View: TableView,
|
|
83
82
|
lastColumnResizable: this.options.lastColumnResizable
|
|
84
83
|
})
|
|
85
84
|
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/table-header.ts
|
|
4
|
+
import { mergeAttributes } from "@tiptap/core";
|
|
5
|
+
import { TableHeader as TiptapTableHeader } from "@tiptap/extension-table";
|
|
6
|
+
var TableHeader = TiptapTableHeader.extend({
|
|
7
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
8
|
+
const attrs = {};
|
|
9
|
+
if (node.attrs.align) {
|
|
10
|
+
attrs["data-align"] = node.attrs.align;
|
|
11
|
+
attrs.style = `text-align: ${node.attrs.align}`;
|
|
12
|
+
}
|
|
13
|
+
return [
|
|
14
|
+
"th",
|
|
15
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, attrs),
|
|
16
|
+
0
|
|
17
|
+
];
|
|
18
|
+
},
|
|
19
|
+
addAttributes() {
|
|
20
|
+
return {
|
|
21
|
+
colspan: {
|
|
22
|
+
default: 1
|
|
23
|
+
},
|
|
24
|
+
rowspan: {
|
|
25
|
+
default: 1
|
|
26
|
+
},
|
|
27
|
+
colwidth: {
|
|
28
|
+
default: null,
|
|
29
|
+
parseHTML: (element) => {
|
|
30
|
+
const colwidth = element.getAttribute("colwidth");
|
|
31
|
+
return colwidth ? colwidth.split(",").map((w) => Number.parseInt(w, 10)) : null;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
align: {
|
|
35
|
+
default: null,
|
|
36
|
+
parseHTML: (element) => element.getAttribute("data-align")
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
TableHeader
|
|
44
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/table/views/table-column-menu.tsx
|
|
4
|
+
import { DropdownMenu } from "@kopexa/dropdown-menu";
|
|
5
|
+
import { toggleHeaderColumn as pmToggleHeaderColumn } from "@tiptap/pm/tables";
|
|
6
|
+
import { useCallback, useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function TableColumnMenu({
|
|
9
|
+
editor,
|
|
10
|
+
cellPos,
|
|
11
|
+
style
|
|
12
|
+
}) {
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
const chainAtCell = useCallback(() => {
|
|
15
|
+
const chain = editor.chain().focus();
|
|
16
|
+
if (cellPos != null) {
|
|
17
|
+
return chain.setTextSelection(cellPos + 1);
|
|
18
|
+
}
|
|
19
|
+
return chain;
|
|
20
|
+
}, [editor, cellPos]);
|
|
21
|
+
const handleToggleHeader = useCallback(() => {
|
|
22
|
+
chainAtCell().command(({ state, dispatch }) => pmToggleHeaderColumn(state, dispatch)).run();
|
|
23
|
+
setOpen(false);
|
|
24
|
+
}, [chainAtCell]);
|
|
25
|
+
const handleAddBefore = useCallback(() => {
|
|
26
|
+
chainAtCell().addColumnBefore().run();
|
|
27
|
+
setOpen(false);
|
|
28
|
+
}, [chainAtCell]);
|
|
29
|
+
const handleAddAfter = useCallback(() => {
|
|
30
|
+
chainAtCell().addColumnAfter().run();
|
|
31
|
+
setOpen(false);
|
|
32
|
+
}, [chainAtCell]);
|
|
33
|
+
const handleDelete = useCallback(() => {
|
|
34
|
+
chainAtCell().deleteColumn().run();
|
|
35
|
+
setOpen(false);
|
|
36
|
+
}, [chainAtCell]);
|
|
37
|
+
return /* @__PURE__ */ jsxs(DropdownMenu.Root, { open, onOpenChange: setOpen, children: [
|
|
38
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
39
|
+
"button",
|
|
40
|
+
{
|
|
41
|
+
type: "button",
|
|
42
|
+
className: "columns-control-div",
|
|
43
|
+
"aria-label": "Column actions",
|
|
44
|
+
style
|
|
45
|
+
}
|
|
46
|
+
) }),
|
|
47
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
48
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleToggleHeader, children: "Toggle header column" }),
|
|
50
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleAddBefore, children: "Insert column before" }),
|
|
51
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { onSelect: handleAddAfter, children: "Insert column after" })
|
|
52
|
+
] }),
|
|
53
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
54
|
+
/* @__PURE__ */ jsx(DropdownMenu.Item, { variant: "destructive", onSelect: handleDelete, children: "Delete column" })
|
|
55
|
+
] })
|
|
56
|
+
] });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
TableColumnMenu
|
|
61
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { TableKit, TableKitOptions } from './kit.mjs';
|
|
2
2
|
export { Table } from './table/table.mjs';
|
|
3
|
+
export { TableNodeView } from './table/views/table-node-view.mjs';
|
|
3
4
|
export { TableCell, TableCellOptions } from './table-cell.mjs';
|
|
4
5
|
export { TableHeader } from './table-header.mjs';
|
|
5
6
|
export { TableRow } from './table-row.mjs';
|
|
6
7
|
import '@tiptap/extension-table';
|
|
7
8
|
import '@tiptap/react';
|
|
8
9
|
import '@tiptap/core';
|
|
10
|
+
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { TableKit, TableKitOptions } from './kit.js';
|
|
2
2
|
export { Table } from './table/table.js';
|
|
3
|
+
export { TableNodeView } from './table/views/table-node-view.js';
|
|
3
4
|
export { TableCell, TableCellOptions } from './table-cell.js';
|
|
4
5
|
export { TableHeader } from './table-header.js';
|
|
5
6
|
export { TableRow } from './table-row.js';
|
|
6
7
|
import '@tiptap/extension-table';
|
|
7
8
|
import '@tiptap/react';
|
|
8
9
|
import '@tiptap/core';
|
|
10
|
+
import 'react/jsx-runtime';
|