@haklex/rich-plugin-table 0.0.65 → 0.0.67
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/README.md +48 -17
- package/dist/TableCellResizerPlugin.d.ts.map +1 -1
- package/dist/TableRowColumnHandlesPlugin.d.ts.map +1 -1
- package/dist/index.mjs +71 -104
- package/package.json +17 -12
package/README.md
CHANGED
|
@@ -1,35 +1,66 @@
|
|
|
1
1
|
# @haklex/rich-plugin-table
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Table editing plugin with cell resizing and row/column manipulation.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add @haklex/rich-plugin-table
|
|
8
|
+
pnpm add @haklex/rich-plugin-table
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Peer Dependencies
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
| Package | Version |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `@lexical/react` | `^0.41.0` |
|
|
16
|
+
| `@lexical/table` | `^0.41.0` |
|
|
17
|
+
| `lexical` | `^0.41.0` |
|
|
18
|
+
| `lucide-react` | `^0.574.0` |
|
|
19
|
+
| `react` | `>= 19` |
|
|
20
|
+
| `react-dom` | `>= 19` |
|
|
17
21
|
|
|
18
|
-
##
|
|
22
|
+
## Usage
|
|
19
23
|
|
|
20
24
|
```tsx
|
|
21
|
-
import {
|
|
22
|
-
TableCellResizerPlugin,
|
|
23
|
-
TableRowColumnHandlesPlugin
|
|
25
|
+
import {
|
|
26
|
+
TableCellResizerPlugin,
|
|
27
|
+
TableRowColumnHandlesPlugin,
|
|
24
28
|
} from '@haklex/rich-plugin-table'
|
|
25
|
-
import
|
|
29
|
+
import '@haklex/rich-plugin-table/style.css'
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
function Editor() {
|
|
32
|
+
return (
|
|
33
|
+
<RichEditor>
|
|
34
|
+
<TableCellResizerPlugin />
|
|
35
|
+
<TableRowColumnHandlesPlugin />
|
|
36
|
+
</RichEditor>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
31
39
|
```
|
|
32
40
|
|
|
41
|
+
This plugin provides two complementary components:
|
|
42
|
+
|
|
43
|
+
- **TableCellResizerPlugin** -- Allows users to resize table columns by dragging cell borders.
|
|
44
|
+
- **TableRowColumnHandlesPlugin** -- Renders handles for inserting, deleting, and reordering rows and columns.
|
|
45
|
+
|
|
46
|
+
## Exports
|
|
47
|
+
|
|
48
|
+
| Export | Type | Description |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `TableCellResizerPlugin` | Component | Cell border drag-to-resize plugin |
|
|
51
|
+
| `TableRowColumnHandlesPlugin` | Component | Row/column insert, delete, and reorder handles |
|
|
52
|
+
|
|
53
|
+
## Sub-path Exports
|
|
54
|
+
|
|
55
|
+
| Path | Description |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `@haklex/rich-plugin-table` | Plugin components |
|
|
58
|
+
| `@haklex/rich-plugin-table/style.css` | Stylesheet |
|
|
59
|
+
|
|
60
|
+
## Part of Haklex
|
|
61
|
+
|
|
62
|
+
This package is part of the [Haklex](../../README.md) rich editor ecosystem.
|
|
63
|
+
|
|
33
64
|
## License
|
|
34
65
|
|
|
35
66
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableCellResizerPlugin.d.ts","sourceRoot":"","sources":["../src/TableCellResizerPlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TableCellResizerPlugin.d.ts","sourceRoot":"","sources":["../src/TableCellResizerPlugin.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqC,YAAY,EAAE,MAAM,OAAO,CAAC;AAiP7E,wBAAgB,sBAAsB,IAAI,YAAY,CAIrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRowColumnHandlesPlugin.d.ts","sourceRoot":"","sources":["../src/TableRowColumnHandlesPlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TableRowColumnHandlesPlugin.d.ts","sourceRoot":"","sources":["../src/TableRowColumnHandlesPlugin.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AA6X1C,wBAAgB,2BAA2B,IAAI,YAAY,CAI1D"}
|
package/dist/index.mjs
CHANGED
|
@@ -13,12 +13,8 @@ var rowColHandle = "t6ga9o3";
|
|
|
13
13
|
var rowColHandleVisible = "t6ga9o4";
|
|
14
14
|
var handleBtn = "t6ga9o5";
|
|
15
15
|
const RESIZER_HANDLE_ATTR = "data-table-resizer-handle";
|
|
16
|
-
function TableCellResizerInner({
|
|
17
|
-
|
|
18
|
-
}) {
|
|
19
|
-
const [activeCell, setActiveCell] = useState(
|
|
20
|
-
null
|
|
21
|
-
);
|
|
16
|
+
function TableCellResizerInner({ editor }) {
|
|
17
|
+
const [activeCell, setActiveCell] = useState(null);
|
|
22
18
|
const [resizing, setResizing] = useState(false);
|
|
23
19
|
const [direction, setDirection] = useState(null);
|
|
24
20
|
const [handlePos, setHandlePos] = useState({ right: null, bottom: null });
|
|
@@ -184,9 +180,9 @@ function TableCellResizerInner({
|
|
|
184
180
|
handlePos.right && /* @__PURE__ */ jsx(
|
|
185
181
|
"div",
|
|
186
182
|
{
|
|
187
|
-
"data-testid": "table-cell-resizer-right",
|
|
188
|
-
"data-table-resizer-handle": "true",
|
|
189
183
|
className: `${resizeHandle} ${direction === "right" ? resizeHandleActive : ""}`,
|
|
184
|
+
"data-table-resizer-handle": "true",
|
|
185
|
+
"data-testid": "table-cell-resizer-right",
|
|
190
186
|
style: {
|
|
191
187
|
top: handlePos.right.top,
|
|
192
188
|
left: handlePos.right.left,
|
|
@@ -201,9 +197,9 @@ function TableCellResizerInner({
|
|
|
201
197
|
handlePos.bottom && /* @__PURE__ */ jsx(
|
|
202
198
|
"div",
|
|
203
199
|
{
|
|
204
|
-
"data-testid": "table-cell-resizer-bottom",
|
|
205
|
-
"data-table-resizer-handle": "true",
|
|
206
200
|
className: `${resizeHandle} ${direction === "bottom" ? resizeHandleActive : ""}`,
|
|
201
|
+
"data-table-resizer-handle": "true",
|
|
202
|
+
"data-testid": "table-cell-resizer-bottom",
|
|
207
203
|
style: {
|
|
208
204
|
top: handlePos.bottom.top,
|
|
209
205
|
left: handlePos.bottom.left,
|
|
@@ -297,60 +293,57 @@ function TableRowColumnHandlesInner({
|
|
|
297
293
|
hoveringHandleRef.current = false;
|
|
298
294
|
scheduleHide();
|
|
299
295
|
}, [scheduleHide]);
|
|
300
|
-
const updateHandlesFromAnchor = useCallback(
|
|
301
|
-
(anchor)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
},
|
|
352
|
-
[]
|
|
353
|
-
);
|
|
296
|
+
const updateHandlesFromAnchor = useCallback((anchor) => {
|
|
297
|
+
if (anchor !== void 0) {
|
|
298
|
+
activeAnchorRef.current = anchor;
|
|
299
|
+
}
|
|
300
|
+
const activeAnchor = activeAnchorRef.current;
|
|
301
|
+
if (!activeAnchor) return;
|
|
302
|
+
const { table, rowIndex, colIndex } = activeAnchor;
|
|
303
|
+
if (!table.isConnected) {
|
|
304
|
+
activeAnchorRef.current = null;
|
|
305
|
+
setRowHandle((s) => ({ ...s, visible: false }));
|
|
306
|
+
setColHandle((s) => ({ ...s, visible: false }));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const rows = table.querySelectorAll("tr");
|
|
310
|
+
const row = rows[rowIndex];
|
|
311
|
+
if (!row) {
|
|
312
|
+
activeAnchorRef.current = null;
|
|
313
|
+
setRowHandle((s) => ({ ...s, visible: false }));
|
|
314
|
+
setColHandle((s) => ({ ...s, visible: false }));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const cells = row.querySelectorAll("td, th");
|
|
318
|
+
const cell = cells[colIndex] ?? cells[0];
|
|
319
|
+
if (!cell) {
|
|
320
|
+
activeAnchorRef.current = null;
|
|
321
|
+
setRowHandle((s) => ({ ...s, visible: false }));
|
|
322
|
+
setColHandle((s) => ({ ...s, visible: false }));
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
tableRef.current = table;
|
|
326
|
+
const resolvedColIndex = cell.cellIndex;
|
|
327
|
+
activeAnchorRef.current = { table, rowIndex, colIndex: resolvedColIndex };
|
|
328
|
+
const cellRect = cell.getBoundingClientRect();
|
|
329
|
+
const tableRect = table.getBoundingClientRect();
|
|
330
|
+
const cellPage = toPagePosition(cellRect);
|
|
331
|
+
const tablePage = toPagePosition(tableRect);
|
|
332
|
+
setRowHandle({
|
|
333
|
+
visible: true,
|
|
334
|
+
top: cellPage.top + cellRect.height / 2 - ROW_HANDLE_HEIGHT / 2,
|
|
335
|
+
left: tablePage.left - 38,
|
|
336
|
+
rowIndex,
|
|
337
|
+
colIndex: resolvedColIndex
|
|
338
|
+
});
|
|
339
|
+
setColHandle({
|
|
340
|
+
visible: true,
|
|
341
|
+
top: tablePage.top - 22,
|
|
342
|
+
left: cellPage.left + cellRect.width / 2 - COL_HANDLE_WIDTH / 2,
|
|
343
|
+
rowIndex,
|
|
344
|
+
colIndex: resolvedColIndex
|
|
345
|
+
});
|
|
346
|
+
}, []);
|
|
354
347
|
useEffect(() => {
|
|
355
348
|
const rootElement = editor.getRootElement();
|
|
356
349
|
if (!rootElement) return;
|
|
@@ -476,19 +469,10 @@ function TableRowColumnHandlesInner({
|
|
|
476
469
|
onMouseEnter: handleEnter,
|
|
477
470
|
onMouseLeave: handleLeave,
|
|
478
471
|
children: [
|
|
479
|
-
/* @__PURE__ */ jsx(
|
|
480
|
-
"button",
|
|
481
|
-
{
|
|
482
|
-
type: "button",
|
|
483
|
-
className: handleBtn,
|
|
484
|
-
onClick: addRowBelow,
|
|
485
|
-
"aria-label": "Add row",
|
|
486
|
-
children: /* @__PURE__ */ jsx(Plus, { size: ICON_SIZE })
|
|
487
|
-
}
|
|
488
|
-
),
|
|
472
|
+
/* @__PURE__ */ jsx("button", { "aria-label": "Add row", className: handleBtn, type: "button", onClick: addRowBelow, children: /* @__PURE__ */ jsx(Plus, { size: ICON_SIZE }) }),
|
|
489
473
|
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
490
474
|
/* @__PURE__ */ jsx(DropdownMenuTrigger, { className: handleBtn, children: /* @__PURE__ */ jsx(GripVertical, { size: ICON_SIZE }) }),
|
|
491
|
-
/* @__PURE__ */ jsxs(DropdownMenuContent, {
|
|
475
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", side: "right", sideOffset: 4, children: [
|
|
492
476
|
/* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: insertRowAbove, children: [
|
|
493
477
|
/* @__PURE__ */ jsx(ArrowUp, { size: 14 }),
|
|
494
478
|
"Insert row above"
|
|
@@ -498,17 +482,10 @@ function TableRowColumnHandlesInner({
|
|
|
498
482
|
"Insert row below"
|
|
499
483
|
] }),
|
|
500
484
|
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
501
|
-
/* @__PURE__ */ jsxs(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
onClick: deleteRow,
|
|
506
|
-
children: [
|
|
507
|
-
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
508
|
-
"Delete row"
|
|
509
|
-
]
|
|
510
|
-
}
|
|
511
|
-
)
|
|
485
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, { className: menuItemDestructive, onClick: deleteRow, children: [
|
|
486
|
+
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
487
|
+
"Delete row"
|
|
488
|
+
] })
|
|
512
489
|
] })
|
|
513
490
|
] })
|
|
514
491
|
]
|
|
@@ -525,16 +502,16 @@ function TableRowColumnHandlesInner({
|
|
|
525
502
|
/* @__PURE__ */ jsx(
|
|
526
503
|
"button",
|
|
527
504
|
{
|
|
528
|
-
|
|
505
|
+
"aria-label": "Add column",
|
|
529
506
|
className: handleBtn,
|
|
507
|
+
type: "button",
|
|
530
508
|
onClick: addColumnLeft,
|
|
531
|
-
"aria-label": "Add column",
|
|
532
509
|
children: /* @__PURE__ */ jsx(Plus, { size: ICON_SIZE })
|
|
533
510
|
}
|
|
534
511
|
),
|
|
535
512
|
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
536
513
|
/* @__PURE__ */ jsx(DropdownMenuTrigger, { className: handleBtn, children: /* @__PURE__ */ jsx(GripVertical, { size: ICON_SIZE }) }),
|
|
537
|
-
/* @__PURE__ */ jsxs(DropdownMenuContent, {
|
|
514
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", side: "bottom", sideOffset: 4, children: [
|
|
538
515
|
/* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: insertColumnLeft, children: [
|
|
539
516
|
/* @__PURE__ */ jsx(ArrowLeft, { size: 14 }),
|
|
540
517
|
"Insert column left"
|
|
@@ -544,17 +521,10 @@ function TableRowColumnHandlesInner({
|
|
|
544
521
|
"Insert column right"
|
|
545
522
|
] }),
|
|
546
523
|
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
547
|
-
/* @__PURE__ */ jsxs(
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
onClick: deleteColumn,
|
|
552
|
-
children: [
|
|
553
|
-
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
554
|
-
"Delete column"
|
|
555
|
-
]
|
|
556
|
-
}
|
|
557
|
-
)
|
|
524
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, { className: menuItemDestructive, onClick: deleteColumn, children: [
|
|
525
|
+
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
526
|
+
"Delete column"
|
|
527
|
+
] })
|
|
558
528
|
] })
|
|
559
529
|
] })
|
|
560
530
|
]
|
|
@@ -564,10 +534,7 @@ function TableRowColumnHandlesInner({
|
|
|
564
534
|
}
|
|
565
535
|
function TableRowColumnHandlesPlugin() {
|
|
566
536
|
const [editor] = useLexicalComposerContext();
|
|
567
|
-
return createPortal(
|
|
568
|
-
/* @__PURE__ */ jsx(TableRowColumnHandlesInner, { editor }),
|
|
569
|
-
document.body
|
|
570
|
-
);
|
|
537
|
+
return createPortal(/* @__PURE__ */ jsx(TableRowColumnHandlesInner, { editor }), document.body);
|
|
571
538
|
}
|
|
572
539
|
export {
|
|
573
540
|
TableCellResizerPlugin,
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-plugin-table",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.65",
|
|
3
|
+
"version": "0.0.67",
|
|
5
4
|
"description": "Table editing plugin",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Innei/haklex.git",
|
|
8
|
+
"directory": "packages/rich-plugin-table"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
14
|
"import": "./dist/index.mjs",
|
|
@@ -15,17 +20,9 @@
|
|
|
15
20
|
"files": [
|
|
16
21
|
"dist"
|
|
17
22
|
],
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"@lexical/react": "^0.41.0",
|
|
20
|
-
"@lexical/table": "^0.41.0",
|
|
21
|
-
"lexical": "^0.41.0",
|
|
22
|
-
"lucide-react": "^0.574.0",
|
|
23
|
-
"react": ">=19",
|
|
24
|
-
"react-dom": ">=19"
|
|
25
|
-
},
|
|
26
23
|
"dependencies": {
|
|
27
|
-
"@haklex/rich-
|
|
28
|
-
"@haklex/rich-
|
|
24
|
+
"@haklex/rich-editor-ui": "0.0.67",
|
|
25
|
+
"@haklex/rich-style-token": "0.0.67"
|
|
29
26
|
},
|
|
30
27
|
"devDependencies": {
|
|
31
28
|
"@lexical/react": "^0.41.0",
|
|
@@ -42,6 +39,14 @@
|
|
|
42
39
|
"vite": "^7.3.1",
|
|
43
40
|
"vite-plugin-dts": "^4.5.4"
|
|
44
41
|
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@lexical/react": "^0.41.0",
|
|
44
|
+
"@lexical/table": "^0.41.0",
|
|
45
|
+
"lexical": "^0.41.0",
|
|
46
|
+
"lucide-react": "^0.574.0",
|
|
47
|
+
"react": ">=19",
|
|
48
|
+
"react-dom": ">=19"
|
|
49
|
+
},
|
|
45
50
|
"publishConfig": {
|
|
46
51
|
"access": "public"
|
|
47
52
|
},
|