intable 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -8
- package/dist/__uno.css +1 -0
- package/dist/components/Menu.js +1 -1
- package/dist/components/Render.d.ts +1 -1
- package/dist/components/Tree.d.ts +4 -4
- package/dist/hooks/index.d.ts +5 -4
- package/dist/hooks/index.js +6 -4
- package/dist/hooks/useSort.d.ts +18 -0
- package/dist/hooks/useSort.js +106 -0
- package/dist/index.d.ts +14 -7
- package/dist/index.js +53 -30
- package/dist/plugins/CellMergePlugin.d.ts +14 -0
- package/dist/plugins/CellMergePlugin.js +2 -0
- package/dist/plugins/CellSelectionPlugin.js +89 -85
- package/dist/plugins/DiffPlugin.js +1 -1
- package/dist/plugins/DragPlugin.d.ts +14 -0
- package/dist/plugins/DragPlugin.js +63 -0
- package/dist/plugins/EditablePlugin.d.ts +0 -1
- package/dist/plugins/EditablePlugin.js +2 -2
- package/dist/plugins/HistoryPlugin.d.ts +1 -1
- package/dist/plugins/MenuPlugin.js +1 -1
- package/dist/plugins/ResizePlugin.d.ts +3 -3
- package/dist/plugins/ResizePlugin.js +108 -95
- package/dist/plugins/RowSelectionPlugin.d.ts +1 -1
- package/dist/plugins/VirtualScrollPlugin.d.ts +1 -1
- package/dist/{intable.css → style.css} +38 -122
- package/dist/theme/antd.scss +34 -0
- package/dist/theme/element-plus.scss +33 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +4 -1
- package/dist/wc.js +2 -2
- package/package.json +4 -26
- package/dist/demo.d.ts +0 -2
- package/dist/demo.js +0 -64
- package/dist/vite.svg +0 -1
|
@@ -16,44 +16,6 @@ const CellSelectionPlugin = {
|
|
|
16
16
|
return store.props.data.slice(y1, y2 + 1);
|
|
17
17
|
} }),
|
|
18
18
|
rewriteProps: {
|
|
19
|
-
Th: ({ Th }, { store }) => (o) => {
|
|
20
|
-
const clazz = createMemo(() => {
|
|
21
|
-
const { start, end } = store.selected;
|
|
22
|
-
return inrange(o.x, ...[start[0], end[0]].sort((a, b) => a - b)) ? "col-range-highlight" : "";
|
|
23
|
-
});
|
|
24
|
-
const mo = combineProps(o, { get class() {
|
|
25
|
-
return clazz();
|
|
26
|
-
} });
|
|
27
|
-
return createComponent(Th, mergeProps(mo, { get children() {
|
|
28
|
-
return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
|
|
29
|
-
} }));
|
|
30
|
-
},
|
|
31
|
-
Td: ({ Td }, { store }) => (o) => {
|
|
32
|
-
const clazz = createMemo(() => {
|
|
33
|
-
let clazz$1 = "";
|
|
34
|
-
const { xs, ys } = store.cellSelectionRect();
|
|
35
|
-
const inx = inrange(o.x, xs[0], xs[1]);
|
|
36
|
-
const iny = inrange(o.y, ys[0], ys[1]);
|
|
37
|
-
if (inx && iny) {
|
|
38
|
-
clazz$1 += "range-selected ";
|
|
39
|
-
if (o.x == xs[0]) clazz$1 += "range-selected-l ";
|
|
40
|
-
if (o.x == xs[1]) clazz$1 += "range-selected-r ";
|
|
41
|
-
if (o.y == ys[0]) clazz$1 += "range-selected-t ";
|
|
42
|
-
if (o.y == ys[1]) clazz$1 += "range-selected-b ";
|
|
43
|
-
}
|
|
44
|
-
if (o.x == 0 && iny) clazz$1 += "row-range-highlight ";
|
|
45
|
-
return clazz$1;
|
|
46
|
-
});
|
|
47
|
-
const mo = combineProps(o, {
|
|
48
|
-
get class() {
|
|
49
|
-
return clazz();
|
|
50
|
-
},
|
|
51
|
-
tabindex: -1
|
|
52
|
-
});
|
|
53
|
-
return createComponent(Td, mergeProps(mo, { get children() {
|
|
54
|
-
return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
|
|
55
|
-
} }));
|
|
56
|
-
},
|
|
57
19
|
Table: ({ Table }, { store }) => (o) => {
|
|
58
20
|
const { props } = useContext(Ctx);
|
|
59
21
|
store.cellSelectionRect ??= createMemo(() => {
|
|
@@ -65,53 +27,56 @@ const CellSelectionPlugin = {
|
|
|
65
27
|
ys
|
|
66
28
|
};
|
|
67
29
|
});
|
|
68
|
-
usePointerDrag(() => store.table, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
30
|
+
usePointerDrag(() => store.table, {
|
|
31
|
+
preventDefault: false,
|
|
32
|
+
start(e, move, end) {
|
|
33
|
+
batch(() => {
|
|
34
|
+
const findCell = (e$1) => e$1.composedPath().find((e$2) => e$2.tagName == "TH" || e$2.tagName == "TD");
|
|
35
|
+
const getXY = (cell$1) => [cell$1.getAttribute("x"), cell$1.getAttribute("y")];
|
|
36
|
+
const cell = findCell(e);
|
|
37
|
+
if (!cell) return;
|
|
38
|
+
if (e.buttons != 1 && cell.classList.contains("range-selected")) return;
|
|
39
|
+
if (cell.tagName == "TH") {
|
|
40
|
+
const [x, y] = getXY(cell);
|
|
41
|
+
if (x == null) return;
|
|
42
|
+
store.selected.start = [+x, 0];
|
|
43
|
+
store.selected.end = [+x, Infinity];
|
|
44
|
+
move((e$1) => {
|
|
45
|
+
const cell$1 = findCell(e$1);
|
|
46
|
+
if (!cell$1) return;
|
|
47
|
+
const [x$1, y$1] = getXY(cell$1);
|
|
48
|
+
if (x$1 == null) return;
|
|
49
|
+
store.selected.end = [+x$1, Infinity];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (cell.classList.contains("index")) {
|
|
53
|
+
const [x, y] = getXY(cell);
|
|
54
|
+
if (x == null || y == null) return;
|
|
55
|
+
store.selected.start = [0, +y];
|
|
56
|
+
store.selected.end = [Infinity, +y];
|
|
57
|
+
move((e$1) => {
|
|
58
|
+
const cell$1 = findCell(e$1);
|
|
59
|
+
if (!cell$1) return;
|
|
60
|
+
const [x$1, y$1] = getXY(cell$1);
|
|
61
|
+
if (x$1 == null || y$1 == null) return;
|
|
62
|
+
store.selected.end = [Infinity, +y$1];
|
|
63
|
+
});
|
|
64
|
+
} else if (cell.tagName == "TD") {
|
|
65
|
+
const [x, y] = getXY(cell);
|
|
66
|
+
if (x == null || y == null) return;
|
|
67
|
+
store.selected.start = [+x, +y];
|
|
68
|
+
store.selected.end = [...store.selected.start];
|
|
69
|
+
move((e$1) => {
|
|
70
|
+
const cell$1 = findCell(e$1);
|
|
71
|
+
if (!cell$1) return;
|
|
72
|
+
const [x$1, y$1] = getXY(cell$1);
|
|
73
|
+
if (x$1 == null || y$1 == null) return;
|
|
74
|
+
store.selected.end = [+x$1, +y$1];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
115
80
|
useTinykeys(() => store.table, {
|
|
116
81
|
"ArrowLeft": () => {
|
|
117
82
|
const { start, end } = store.selected;
|
|
@@ -143,7 +108,46 @@ const CellSelectionPlugin = {
|
|
|
143
108
|
cell?.scrollIntoViewIfNeeded(false);
|
|
144
109
|
cell?.focus();
|
|
145
110
|
};
|
|
111
|
+
o = combineProps({ class: "select-none" }, o);
|
|
146
112
|
return createComponent(Table, o);
|
|
113
|
+
},
|
|
114
|
+
Th: ({ Th }, { store }) => (o) => {
|
|
115
|
+
const clazz = createMemo(() => {
|
|
116
|
+
const { start, end } = store.selected;
|
|
117
|
+
return inrange(o.x, ...[start[0], end[0]].sort((a, b) => a - b)) ? "col-range-highlight" : "";
|
|
118
|
+
});
|
|
119
|
+
const mo = combineProps(o, { get class() {
|
|
120
|
+
return clazz();
|
|
121
|
+
} });
|
|
122
|
+
return createComponent(Th, mergeProps(mo, { get children() {
|
|
123
|
+
return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
|
|
124
|
+
} }));
|
|
125
|
+
},
|
|
126
|
+
Td: ({ Td }, { store }) => (o) => {
|
|
127
|
+
const clazz = createMemo(() => {
|
|
128
|
+
let clazz$1 = "";
|
|
129
|
+
const { xs, ys } = store.cellSelectionRect();
|
|
130
|
+
const inx = inrange(o.x, xs[0], xs[1]);
|
|
131
|
+
const iny = inrange(o.y, ys[0], ys[1]);
|
|
132
|
+
if (inx && iny) {
|
|
133
|
+
clazz$1 += "range-selected ";
|
|
134
|
+
if (o.x == xs[0]) clazz$1 += "range-selected-l ";
|
|
135
|
+
if (o.x == xs[1]) clazz$1 += "range-selected-r ";
|
|
136
|
+
if (o.y == ys[0]) clazz$1 += "range-selected-t ";
|
|
137
|
+
if (o.y == ys[1]) clazz$1 += "range-selected-b ";
|
|
138
|
+
}
|
|
139
|
+
if (o.x == 0 && iny) clazz$1 += "row-range-highlight ";
|
|
140
|
+
return clazz$1;
|
|
141
|
+
});
|
|
142
|
+
const mo = combineProps(o, {
|
|
143
|
+
get class() {
|
|
144
|
+
return clazz();
|
|
145
|
+
},
|
|
146
|
+
tabindex: -1
|
|
147
|
+
});
|
|
148
|
+
return createComponent(Td, mergeProps(mo, { get children() {
|
|
149
|
+
return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
|
|
150
|
+
} }));
|
|
147
151
|
}
|
|
148
152
|
}
|
|
149
153
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useTinykeys } from "../hooks/index.js";
|
|
2
2
|
import { createComponent } from "solid-js/web";
|
|
3
3
|
import { unwrap } from "solid-js/store";
|
|
4
|
-
import { isEqual, keyBy } from "es-toolkit";
|
|
5
4
|
import { combineProps } from "@solid-primitives/props";
|
|
5
|
+
import { isEqual, keyBy } from "es-toolkit";
|
|
6
6
|
import { createLazyMemo } from "@solid-primitives/memo";
|
|
7
7
|
import { v4 } from "uuid";
|
|
8
8
|
import { diffArrays } from "diff";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Plugin } from "../index";
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface TableProps {
|
|
4
|
+
colDrag: boolean;
|
|
5
|
+
rowDrag: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface TableColumn {
|
|
8
|
+
}
|
|
9
|
+
interface TableStore {
|
|
10
|
+
}
|
|
11
|
+
interface Commands {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const DragPlugin: Plugin;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useSort } from "../hooks/useSort.js";
|
|
2
|
+
import { delay } from "es-toolkit";
|
|
3
|
+
import { isMatch } from "es-toolkit/compat";
|
|
4
|
+
const DragPlugin = {
|
|
5
|
+
rewriteProps: {
|
|
6
|
+
colDrag: ({ colDrag = false }) => colDrag,
|
|
7
|
+
rowDrag: ({ rowDrag = false }) => rowDrag
|
|
8
|
+
},
|
|
9
|
+
onMount(store) {
|
|
10
|
+
const colDrag = useSort(() => store.scroll_el, {
|
|
11
|
+
get enable() {
|
|
12
|
+
return store.props?.colDrag;
|
|
13
|
+
},
|
|
14
|
+
guideLine: { class: "col__guide-line" },
|
|
15
|
+
draggable: (el) => ((x, y) => el.tagName == "TH" && isMatch(store.selected, { start: [x, 0] }) && !store.props?.columns[x][store.internal] && store.thead.contains(el) && delay(300).then(() => true))(+el.getAttribute("x"), +el.getAttribute("y")),
|
|
16
|
+
dragover: (el) => el.tagName == "THEAD",
|
|
17
|
+
children: (el) => [...colDrag.drag.parentElement.children].filter((e) => !store.props?.columns[e.getAttribute("x")][store.internal]),
|
|
18
|
+
dragend: onColDragend
|
|
19
|
+
});
|
|
20
|
+
const rowDrag = useSort(() => store.scroll_el, {
|
|
21
|
+
get enable() {
|
|
22
|
+
return store.props?.rowDrag;
|
|
23
|
+
},
|
|
24
|
+
guideLine: { class: "row__guide-line" },
|
|
25
|
+
draggable: (el) => ((x, y) => el.tagName == "TD" && isMatch(store.selected, { start: [0, y] }) && x == 0 && !store.props?.data[y][store.internal] && store.tbody.contains(el) && delay(300).then(() => true))(+el.getAttribute("x"), +el.getAttribute("y")),
|
|
26
|
+
dragover: (el) => el.tagName == "TBODY",
|
|
27
|
+
children: (el) => [...rowDrag.over.children].filter((e) => !store.props.data[e.getAttribute("y")][store.internal]),
|
|
28
|
+
dragend: onRowDragend
|
|
29
|
+
});
|
|
30
|
+
async function onColDragend() {
|
|
31
|
+
if (colDrag.drag == colDrag.rel) return;
|
|
32
|
+
const [cols, rawCols] = [store.props.columns, [...store.rawProps.columns || []]];
|
|
33
|
+
const col1 = ((col) => col[store.raw] ?? col)(cols[colDrag.drag.getAttribute("x")]);
|
|
34
|
+
const col2 = ((col) => col[store.raw] ?? col)(cols[colDrag.rel.getAttribute("x")]);
|
|
35
|
+
const i1 = rawCols.indexOf(col1);
|
|
36
|
+
const i2 = rawCols.indexOf(col2);
|
|
37
|
+
if (i1 < 0 || i2 < 0) return;
|
|
38
|
+
rawCols[i1].fixed = rawCols[i2].fixed;
|
|
39
|
+
rawCols.splice(i2 - (i1 > i2 ? 0 : 1) + (colDrag.type == "before" ? 0 : 1), 0, rawCols.splice(i1, 1)[0]);
|
|
40
|
+
store.props.onColumnsChange?.(rawCols);
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
const i = store.props.columns.findIndex((e) => e == col1 || e[store.raw] == col1);
|
|
43
|
+
if (i < 0) return;
|
|
44
|
+
store.selected.start[0] = store.selected.end[0] = i;
|
|
45
|
+
}
|
|
46
|
+
async function onRowDragend() {
|
|
47
|
+
if (rowDrag.drag == rowDrag.rel) return;
|
|
48
|
+
const [data, rawData] = [store.props.data, [...store.rawProps.data || []]];
|
|
49
|
+
const data1 = ((row) => row[store.raw] ?? row)(data[rowDrag.drag.getAttribute("y")]);
|
|
50
|
+
const data2 = ((row) => row[store.raw] ?? row)(data[rowDrag.rel.getAttribute("y")]);
|
|
51
|
+
const i1 = rawData.indexOf(data1);
|
|
52
|
+
const i2 = rawData.indexOf(data2);
|
|
53
|
+
if (i1 < 0 || i2 < 0) return;
|
|
54
|
+
rawData.splice(i2 - (i1 > i2 ? 0 : 1) + (rowDrag.type == "before" ? 0 : 1), 0, rawData.splice(i1, 1)[0]);
|
|
55
|
+
store.props.onDataChange?.(rawData);
|
|
56
|
+
await Promise.resolve();
|
|
57
|
+
const i = store.props.data.findIndex((e) => e == data1 || e[store.raw] == data1);
|
|
58
|
+
if (i < 0) return;
|
|
59
|
+
store.selected.start[1] = store.selected.end[1] = i;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export { DragPlugin };
|
|
@@ -4,8 +4,8 @@ import { Ctx } from "../index.js";
|
|
|
4
4
|
import { createComponent, delegateEvents, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
5
5
|
import { createComputed, createEffect, createMemo, createRoot, createSignal, on, onCleanup, useContext } from "solid-js";
|
|
6
6
|
import { createMutable } from "solid-js/store";
|
|
7
|
-
import { delay } from "es-toolkit";
|
|
8
7
|
import { combineProps } from "@solid-primitives/props";
|
|
8
|
+
import { delay } from "es-toolkit";
|
|
9
9
|
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
10
10
|
var _tmpl$ = /* @__PURE__ */ template(`<input style=position:absolute;margin-top:1em;width:0;height:0;pointer-events:none;opacity:0>`), _tmpl$2 = /* @__PURE__ */ template(`<div class=in-cell-edit-wrapper>`), _tmpl$3 = /* @__PURE__ */ template(`<input>`), _tmpl$4 = /* @__PURE__ */ template(`<select>`), _tmpl$5 = /* @__PURE__ */ template(`<option>`), _tmpl$6 = /* @__PURE__ */ template(`<label class="h-full flex items-center">`);
|
|
11
11
|
const EditablePlugin = {
|
|
@@ -17,7 +17,7 @@ const EditablePlugin = {
|
|
|
17
17
|
const [editing, setEditing] = createSignal(false);
|
|
18
18
|
let eventKey = "";
|
|
19
19
|
const selected = createMemo(() => (([x, y]) => o.x == x && o.y == y)(store.selected.start || []));
|
|
20
|
-
const preEdit = createMemo(() => selected() && editable() && !editing()
|
|
20
|
+
const preEdit = createMemo(() => selected() && editable() && !editing());
|
|
21
21
|
const editorState = createAsyncMemo(async () => {
|
|
22
22
|
if (editing()) {
|
|
23
23
|
let canceled = false;
|
|
@@ -3,8 +3,8 @@ import { useMemoAsync } from "../hooks/index.js";
|
|
|
3
3
|
import { Menu } from "../components/Menu.js";
|
|
4
4
|
import { createComponent, memo, mergeProps } from "solid-js/web";
|
|
5
5
|
import { batch, createMemo, createSignal, mapArray } from "solid-js";
|
|
6
|
-
import { range, remove } from "es-toolkit";
|
|
7
6
|
import { combineProps } from "@solid-primitives/props";
|
|
7
|
+
import { range, remove } from "es-toolkit";
|
|
8
8
|
import { createEventListener } from "@solid-primitives/event-listener";
|
|
9
9
|
import { autoPlacement, computePosition } from "@floating-ui/dom";
|
|
10
10
|
const MenuPlugin = {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type Plugin } from "
|
|
1
|
+
import { type Plugin } from "../index";
|
|
2
2
|
declare module '../index' {
|
|
3
3
|
interface TableProps {
|
|
4
4
|
resizable?: {
|
|
5
|
-
col
|
|
5
|
+
col?: Partial<{
|
|
6
6
|
enable: boolean;
|
|
7
7
|
min: number;
|
|
8
8
|
max: number;
|
|
9
9
|
}>;
|
|
10
|
-
row
|
|
10
|
+
row?: Partial<{
|
|
11
11
|
enable: boolean;
|
|
12
12
|
min: number;
|
|
13
13
|
max: number;
|
|
@@ -1,103 +1,116 @@
|
|
|
1
|
+
import { unFn } from "../utils.js";
|
|
1
2
|
import { usePointerDrag } from "../hooks/index.js";
|
|
2
3
|
import { Ctx } from "../index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { clamp } from "es-toolkit";
|
|
4
|
+
import { className, createComponent, effect, memo, mergeProps, template, use } from "solid-js/web";
|
|
5
|
+
import { batch, untrack, useContext } from "solid-js";
|
|
6
|
+
import { reconcile } from "solid-js/store";
|
|
7
7
|
import { combineProps } from "@solid-primitives/props";
|
|
8
|
+
import { clamp } from "es-toolkit";
|
|
9
|
+
import { createEventListener } from "@solid-primitives/event-listener";
|
|
8
10
|
import { defaultsDeep } from "es-toolkit/compat";
|
|
9
|
-
var _tmpl$ = /* @__PURE__ */ template(`<div
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
dir: "x",
|
|
35
|
-
handle: (i) => createComponent(Handle, { i })
|
|
36
|
-
});
|
|
11
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
12
|
+
var COL = Symbol("col_size");
|
|
13
|
+
var ROW = Symbol("row_size");
|
|
14
|
+
var ColHandle = (o) => {
|
|
15
|
+
const { props, store } = useContext(Ctx);
|
|
16
|
+
let el;
|
|
17
|
+
usePointerDrag(() => el, { start(e, move, end) {
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
const i = o.x;
|
|
20
|
+
const { min, max } = props.resizable.col;
|
|
21
|
+
const th = el.parentElement;
|
|
22
|
+
const sw = th.offsetWidth;
|
|
23
|
+
move((e$1, { ox }) => store[COL][o.x] = clamp(sw + ox, min, max));
|
|
24
|
+
end(() => {
|
|
25
|
+
const col = props.columns[i];
|
|
26
|
+
const cols = [...store.rawProps.columns || []];
|
|
27
|
+
const index = cols.indexOf(col[store.raw] ?? col);
|
|
28
|
+
if (index > -1) {
|
|
29
|
+
cols[index] = {
|
|
30
|
+
...cols[index],
|
|
31
|
+
width: th.offsetWidth
|
|
32
|
+
};
|
|
33
|
+
props.onColumnsChange?.(cols);
|
|
34
|
+
}
|
|
35
|
+
col.onWidthChange?.(th.offsetWidth);
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return (() => {
|
|
60
|
-
var _el$ = _tmpl$();
|
|
61
|
-
var _ref$ = el;
|
|
62
|
-
typeof _ref$ === "function" ? use(_ref$, _el$) : el = _el$;
|
|
63
|
-
return _el$;
|
|
64
|
-
})();
|
|
65
|
-
};
|
|
66
|
-
o = combineProps({ ref: (e) => theadEl = e }, o);
|
|
67
|
-
return createComponent(Thead, o);
|
|
68
|
-
},
|
|
69
|
-
Tbody: ({ Tbody }, { store }) => (o) => {
|
|
70
|
-
let el;
|
|
71
|
-
const { props } = useContext(Ctx);
|
|
72
|
-
const tds = createMemo(() => store.trs.filter((e) => e != null).map((e) => e.firstElementChild));
|
|
73
|
-
onMount(() => {
|
|
74
|
-
useSplit({
|
|
75
|
-
container: el,
|
|
76
|
-
cells: tds,
|
|
77
|
-
size: 8,
|
|
78
|
-
trailing: true,
|
|
79
|
-
dir: "y",
|
|
80
|
-
handle: (i) => createComponent(Handle, { i })
|
|
81
|
-
});
|
|
37
|
+
} });
|
|
38
|
+
return (() => {
|
|
39
|
+
var _el$ = _tmpl$();
|
|
40
|
+
var _ref$ = el;
|
|
41
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : el = _el$;
|
|
42
|
+
effect(() => className(_el$, `in-cell__resize-handle absolute top-0 right-0 flex justify-center w-10px! ${o.x == props.columns.length - 1 ? "justify-end!" : "w-10px! translate-x-1/2"} after:w-1 cursor-w-resize z-1`));
|
|
43
|
+
return _el$;
|
|
44
|
+
})();
|
|
45
|
+
};
|
|
46
|
+
var RowHandle = (o) => {
|
|
47
|
+
const { props, store } = useContext(Ctx);
|
|
48
|
+
let el;
|
|
49
|
+
usePointerDrag(() => el, { start(e, move, end) {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
const i = o.y;
|
|
52
|
+
const { min, max } = props.resizable.row;
|
|
53
|
+
const sh = el.parentElement.offsetHeight;
|
|
54
|
+
move((e$1, { oy }) => store[ROW][o.y] = clamp(sh + oy, min, max));
|
|
55
|
+
end(() => {
|
|
56
|
+
const row = props.data[i];
|
|
57
|
+
if ([...store.rawProps.data || []].indexOf(row[store.raw] ?? row) > -1) {}
|
|
82
58
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
59
|
+
} });
|
|
60
|
+
createEventListener(() => el, "dblclick", () => o.data[COL] = void 0);
|
|
61
|
+
return (() => {
|
|
62
|
+
var _el$2 = _tmpl$();
|
|
63
|
+
var _ref$2 = el;
|
|
64
|
+
typeof _ref$2 === "function" ? use(_ref$2, _el$2) : el = _el$2;
|
|
65
|
+
effect(() => className(_el$2, `in-cell__resize-handle absolute bottom-0 left-0 flex flex-col justify-center h-1! ${o.y == props.data.length - 1 ? "justify-end!" : ""} after:h-1 cursor-s-resize z-1`));
|
|
66
|
+
return _el$2;
|
|
67
|
+
})();
|
|
68
|
+
};
|
|
69
|
+
const ResizePlugin = {
|
|
70
|
+
store: () => ({
|
|
71
|
+
[COL]: [],
|
|
72
|
+
[ROW]: []
|
|
73
|
+
}),
|
|
74
|
+
rewriteProps: {
|
|
75
|
+
resizable: ({ resizable }) => defaultsDeep(resizable, {
|
|
76
|
+
col: {
|
|
77
|
+
enable: true,
|
|
78
|
+
min: 45,
|
|
79
|
+
max: 800
|
|
80
|
+
},
|
|
81
|
+
row: {
|
|
82
|
+
enable: false,
|
|
83
|
+
min: 20,
|
|
84
|
+
max: 400
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
columns: ({ columns }, { store }) => (columns = columns.map((e, i) => ({
|
|
88
|
+
...e,
|
|
89
|
+
[store.raw]: e[store.raw] ?? e
|
|
90
|
+
})), columns = columns.map((e) => e.resizable === void 0 ? {
|
|
91
|
+
...e,
|
|
92
|
+
resizable: store.props?.resizable?.col.enable,
|
|
93
|
+
[store.raw]: e[store.raw] ?? e
|
|
94
|
+
} : e), columns = columns.map((e, i) => store[COL][i] ? {
|
|
95
|
+
...e,
|
|
96
|
+
width: store[COL][i],
|
|
97
|
+
[store.raw]: e[store.raw] ?? e
|
|
98
|
+
} : e), untrack(() => batch(() => reconcile(columns, { key: store.raw })(store.__resize__cols ??= [])))),
|
|
99
|
+
Th: ({ Th }, { store }) => (o) => {
|
|
100
|
+
o = combineProps({ class: "relative" }, o);
|
|
101
|
+
return createComponent(Th, mergeProps(o, { get children() {
|
|
102
|
+
return [memo(() => o.children), memo(() => memo(() => !!o.col.resizable)() && createComponent(ColHandle, o))];
|
|
103
|
+
} }));
|
|
104
|
+
},
|
|
105
|
+
Td: ({ Td }, { store }) => !store.props?.resizable?.row.enable ? Td : (o) => {
|
|
106
|
+
o = combineProps({ class: "relative" }, o);
|
|
107
|
+
return createComponent(Td, mergeProps(o, { get children() {
|
|
108
|
+
return [memo(() => o.children), memo(() => memo(() => !!(o.x == 0 && store.props?.resizable?.row.enable))() && createComponent(RowHandle, o))];
|
|
109
|
+
} }));
|
|
110
|
+
},
|
|
111
|
+
cellStyle: ({ cellStyle }, { store }) => (o) => {
|
|
112
|
+
return `${unFn(cellStyle, o)};` + (store[ROW][o.y] ? `height: ${store[ROW][o.y]}px` : "");
|
|
113
|
+
}
|
|
101
114
|
}
|
|
102
|
-
}
|
|
115
|
+
};
|
|
103
116
|
export { ResizePlugin };
|