intable 0.0.33 → 0.0.35
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 +2 -456
- package/dist/__uno.css +1 -1
- package/dist/components/Filter.js +1 -3
- package/dist/components/Popover.d.ts +2 -2
- package/dist/components/Popover.js +28 -17
- package/dist/components/Textarea.d.ts +14 -0
- package/dist/components/Textarea.js +68 -0
- package/dist/components/Tooltip.d.ts +19 -0
- package/dist/components/Tooltip.js +26 -0
- package/dist/hooks/useSelector.d.ts +2 -0
- package/dist/hooks/useSelector.js +4 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -5
- package/dist/plugins/AutoFillPlugin.js +6 -5
- package/dist/plugins/EditablePlugin.js +66 -61
- package/dist/plugins/RowSelectionPlugin.js +22 -10
- package/dist/plugins/SortPlugin.d.ts +2 -2
- package/dist/plugins/SortPlugin.js +49 -47
- package/dist/plugins/TooltipPlugin.d.ts +13 -0
- package/dist/plugins/TooltipPlugin.js +40 -0
- package/dist/plugins/ValidatorPlugin.js +0 -1
- package/dist/style.css +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mergeProps, spread, template, use } from "solid-js/web";
|
|
2
|
+
import { createEffect, createSignal, mergeProps as mergeProps$1, splitProps } from "solid-js";
|
|
3
|
+
var _tmpl$ = /* @__PURE__ */ template("<textarea>");
|
|
4
|
+
function getLineHeight(e) {
|
|
5
|
+
let o = getComputedStyle(e), s = parseFloat(o.lineHeight);
|
|
6
|
+
if (Number.isFinite(s)) return s;
|
|
7
|
+
let c = parseFloat(o.fontSize);
|
|
8
|
+
return Number.isFinite(c) ? c * 1.2 : 20;
|
|
9
|
+
}
|
|
10
|
+
function normalizeAutoSize(e) {
|
|
11
|
+
return e ? e === !0 ? {
|
|
12
|
+
minRows: void 0,
|
|
13
|
+
maxRows: void 0
|
|
14
|
+
} : e : null;
|
|
15
|
+
}
|
|
16
|
+
const Textarea = (s) => {
|
|
17
|
+
let d = mergeProps$1({
|
|
18
|
+
defaultValue: "",
|
|
19
|
+
autosize: !1
|
|
20
|
+
}, s), [f, p] = splitProps(d, [
|
|
21
|
+
"value",
|
|
22
|
+
"defaultValue",
|
|
23
|
+
"autosize",
|
|
24
|
+
"ref",
|
|
25
|
+
"onInput",
|
|
26
|
+
"onChange"
|
|
27
|
+
]), [m, h] = createSignal(f.value ?? f.defaultValue ?? ""), g, _ = () => {
|
|
28
|
+
if (!g) return;
|
|
29
|
+
let e = normalizeAutoSize(f.autosize);
|
|
30
|
+
if (!e) return;
|
|
31
|
+
let o = getComputedStyle(g), s = parseFloat(o.borderTopWidth || "0") + parseFloat(o.borderBottomWidth || "0"), c = parseFloat(o.paddingTop || "0") + parseFloat(o.paddingBottom || "0"), l = getLineHeight(g);
|
|
32
|
+
g.style.height = "";
|
|
33
|
+
let u = g.scrollHeight;
|
|
34
|
+
if (e.minRows) {
|
|
35
|
+
let o = e.minRows * l + c + s;
|
|
36
|
+
u = Math.max(u, o);
|
|
37
|
+
}
|
|
38
|
+
if (e.maxRows) {
|
|
39
|
+
let o = e.maxRows * l + c + s;
|
|
40
|
+
u = Math.min(u, o), g.style.overflowY = g.scrollHeight > o ? "auto" : "hidden";
|
|
41
|
+
} else g.style.overflowY = "hidden";
|
|
42
|
+
g.style.height = `${Math.ceil(u)}px`;
|
|
43
|
+
};
|
|
44
|
+
return createEffect(() => {
|
|
45
|
+
let e = f.value;
|
|
46
|
+
e != null && h(e);
|
|
47
|
+
}), createEffect(() => {
|
|
48
|
+
m(), f.autosize, queueMicrotask(_);
|
|
49
|
+
}), (() => {
|
|
50
|
+
var s = _tmpl$();
|
|
51
|
+
return use((e) => {
|
|
52
|
+
g = e, typeof f.ref == "function" && f.ref(e), queueMicrotask(_);
|
|
53
|
+
}, s), spread(s, mergeProps(p, {
|
|
54
|
+
get value() {
|
|
55
|
+
return m();
|
|
56
|
+
},
|
|
57
|
+
onInput: (e) => {
|
|
58
|
+
let o = e.currentTarget.value;
|
|
59
|
+
f.value ?? h(o), f.onInput?.(o), queueMicrotask(_);
|
|
60
|
+
},
|
|
61
|
+
onChange: (e) => {
|
|
62
|
+
f.onChange?.(e.currentTarget.value);
|
|
63
|
+
}
|
|
64
|
+
}), !1, !1), s;
|
|
65
|
+
})();
|
|
66
|
+
};
|
|
67
|
+
var Textarea_default = Textarea;
|
|
68
|
+
export { Textarea, Textarea_default as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type JSX } from 'solid-js';
|
|
2
|
+
import { type FloatingProps } from './Popover';
|
|
3
|
+
import type { Placement } from '@floating-ui/dom';
|
|
4
|
+
export type TooltipProps = {
|
|
5
|
+
/** Tooltip body — plain text or JSX */
|
|
6
|
+
content: JSX.Element;
|
|
7
|
+
placement?: Placement;
|
|
8
|
+
children: JSX.Element;
|
|
9
|
+
} & Partial<FloatingProps>;
|
|
10
|
+
/**
|
|
11
|
+
* Wraps any element and shows a small floating tooltip on hover.
|
|
12
|
+
*
|
|
13
|
+
* ```jsx
|
|
14
|
+
* <Tooltip content="Save file">
|
|
15
|
+
* <button>💾</button>
|
|
16
|
+
* </Tooltip>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function Tooltip(props: TooltipProps): JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Popover } from "./Popover.js";
|
|
2
|
+
import { createComponent, insert, mergeProps, template } from "solid-js/web";
|
|
3
|
+
import { offset } from "floating-ui-solid";
|
|
4
|
+
var _tmpl$ = /* @__PURE__ */ template("<div class=tt-tooltip>");
|
|
5
|
+
function Tooltip(s) {
|
|
6
|
+
return createComponent(Popover, mergeProps({
|
|
7
|
+
trigger: "hover",
|
|
8
|
+
get placement() {
|
|
9
|
+
return s.placement ?? "top";
|
|
10
|
+
},
|
|
11
|
+
get middleware() {
|
|
12
|
+
return [offset({ mainAxis: 6 })];
|
|
13
|
+
}
|
|
14
|
+
}, s, {
|
|
15
|
+
get reference() {
|
|
16
|
+
return s.children;
|
|
17
|
+
},
|
|
18
|
+
get floating() {
|
|
19
|
+
return (() => {
|
|
20
|
+
var e = _tmpl$();
|
|
21
|
+
return insert(e, () => s.content), e;
|
|
22
|
+
})();
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
export { Tooltip };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import './plugins/ValidatorPlugin';
|
|
|
20
20
|
import './plugins/AggregatePlugin';
|
|
21
21
|
import './plugins/AutoFillPlugin';
|
|
22
22
|
import './plugins/FilterPlugin';
|
|
23
|
+
import './plugins/TooltipPlugin';
|
|
23
24
|
export declare const Ctx: import("solid-js").Context<{
|
|
24
25
|
props: TableProps2;
|
|
25
26
|
store: TableStore;
|
|
@@ -53,7 +54,7 @@ export interface Plugin {
|
|
|
53
54
|
*/
|
|
54
55
|
keybindings?: (store: TableStore) => Record<string, (e?: KeyboardEvent) => void>;
|
|
55
56
|
}
|
|
56
|
-
export type Plugin$0 = Plugin | ((store: TableStore) => Plugin);
|
|
57
|
+
export type Plugin$0 = Plugin | Plugin[] | ((store: TableStore) => Plugin);
|
|
57
58
|
export interface TableProps {
|
|
58
59
|
store?: {
|
|
59
60
|
value: TableStore;
|
|
@@ -125,7 +126,7 @@ export type TDProps = {
|
|
|
125
126
|
type Obj = Record<string | symbol, any>;
|
|
126
127
|
export interface TableColumn extends Obj {
|
|
127
128
|
id: any;
|
|
128
|
-
name?:
|
|
129
|
+
name?: any;
|
|
129
130
|
width?: number;
|
|
130
131
|
fixed?: 'left' | 'right';
|
|
131
132
|
class?: any;
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { AggregatePlugin } from "./plugins/AggregatePlugin.js";
|
|
|
22
22
|
import { AutoFillPlugin } from "./plugins/AutoFillPlugin.js";
|
|
23
23
|
import { FilterPlugin } from "./plugins/FilterPlugin.js";
|
|
24
24
|
import { ImportExportPlugin } from "./plugins/ImportExportPlugin.js";
|
|
25
|
+
import { TooltipPlugin } from "./plugins/TooltipPlugin.js";
|
|
25
26
|
import loading_bold_default from "./loading-bold.js";
|
|
26
27
|
import { createComponent, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
27
28
|
import { $PROXY, For, batch, createComputed, createContext, createEffect, createMemo, createSignal, getOwner, mapArray, mergeProps as mergeProps$1, on, onCleanup, onMount, runWithOwner, untrack, useContext } from "solid-js";
|
|
@@ -30,7 +31,7 @@ import { combineProps } from "@solid-primitives/props";
|
|
|
30
31
|
import { createLazyMemo } from "@solid-primitives/memo";
|
|
31
32
|
import { createElementSize, createResizeObserver, makeResizeObserver } from "@solid-primitives/resize-observer";
|
|
32
33
|
import { createScrollPosition } from "@solid-primitives/scroll";
|
|
33
|
-
import { difference, isEqual, memoize, sumBy } from "es-toolkit";
|
|
34
|
+
import { difference, isEqual, memoize, sumBy, uniq } from "es-toolkit";
|
|
34
35
|
var _tmpl$ = /* @__PURE__ */ template("<div>"), _tmpl$2 = /* @__PURE__ */ template("<table>"), _tmpl$3 = /* @__PURE__ */ template("<thead>"), _tmpl$4 = /* @__PURE__ */ template("<tbody>"), _tmpl$5 = /* @__PURE__ */ template("<tr>"), _tmpl$6 = /* @__PURE__ */ template("<th>"), _tmpl$7 = /* @__PURE__ */ template("<td>"), _tmpl$8 = /* @__PURE__ */ template("<div class=data-table__layers>"), _tmpl$9 = /* @__PURE__ */ template("<div class=\"data-table--scroll-view h-full max-h-inherit\">"), _tmpl$0 = /* @__PURE__ */ template("<div class=data-table__empty>No data"), _tmpl$1 = /* @__PURE__ */ template("<div class=data-table__loading>");
|
|
35
36
|
const Ctx = createContext({
|
|
36
37
|
props: {},
|
|
@@ -46,11 +47,11 @@ const Ctx = createContext({
|
|
|
46
47
|
},
|
|
47
48
|
owner: getOwner()
|
|
48
49
|
}), Y = memoize((_) => runWithOwner(K, () => unFn(_, J))), X = createMemo((q) => {
|
|
49
|
-
let X = [
|
|
50
|
+
let X = uniq([
|
|
50
51
|
...defaultsPlugins,
|
|
51
52
|
..._.plugins || [],
|
|
52
53
|
RenderPlugin
|
|
53
|
-
].map(Y).sort((_, K) => (K.priority || 0) - (_.priority || 0)), Q = difference(X, q);
|
|
54
|
+
].flat().map(Y).sort((_, K) => (K.priority || 0) - (_.priority || 0))), Q = difference(X, q);
|
|
54
55
|
return runWithOwner(K, () => {
|
|
55
56
|
Q.forEach((_) => Object.assign(J, _.store?.(J)));
|
|
56
57
|
}), X;
|
|
@@ -395,6 +396,7 @@ const defaultsPlugins = [
|
|
|
395
396
|
} }),
|
|
396
397
|
rewriteProps: { columns: ({ columns: _ }, { store: K }) => K.props?.index ? [K.$index, ..._ || []] : _ }
|
|
397
398
|
},
|
|
399
|
+
FilterPlugin,
|
|
398
400
|
SortPlugin,
|
|
399
401
|
ValidatorPlugin,
|
|
400
402
|
EditablePlugin,
|
|
@@ -423,7 +425,7 @@ const defaultsPlugins = [
|
|
|
423
425
|
ResizePlugin,
|
|
424
426
|
AggregatePlugin,
|
|
425
427
|
AutoFillPlugin,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
+
ImportExportPlugin,
|
|
429
|
+
TooltipPlugin
|
|
428
430
|
];
|
|
429
431
|
export { Ctx, Intable, src_default as default, defaultsPlugins };
|
|
@@ -73,11 +73,12 @@ const AutoFillPlugin = {
|
|
|
73
73
|
rowB: (e) => l(e) + (t[e]?.height ?? 28)
|
|
74
74
|
};
|
|
75
75
|
}), g = createMemo(() => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
let e = p();
|
|
77
|
+
if (!e) return;
|
|
78
|
+
let { xs: t, ys: r } = e;
|
|
79
|
+
if (n.props.columns[t[1]]?.[n.internal] || n.props.data[r[1]]?.[n.internal]) return;
|
|
80
|
+
let i = n.props.autoFill;
|
|
81
|
+
return i === !0 || i?.enable === !0;
|
|
81
82
|
}), [_, v] = createSignal(null), y = createMemo(() => {
|
|
82
83
|
let e = _(), t = p();
|
|
83
84
|
if (!e || !t || !e.delta) return "display:none;position:absolute";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { chooseFile, resolveOptions, unFn } from "../utils.js";
|
|
2
2
|
import { Checkbox, Files } from "./RenderPlugin/components.js";
|
|
3
|
+
import Textarea_default from "../components/Textarea.js";
|
|
3
4
|
import { Ctx } from "../index.js";
|
|
4
5
|
import { addEventListener, createComponent, delegateEvents, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
5
6
|
import { createComputed, createEffect, createMemo, createRoot, createSignal, on, onCleanup, useContext } from "solid-js";
|
|
@@ -7,41 +8,41 @@ import { createMutable } from "solid-js/store";
|
|
|
7
8
|
import { combineProps } from "@solid-primitives/props";
|
|
8
9
|
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
9
10
|
import { delay } from "es-toolkit";
|
|
10
|
-
var _tmpl$ = /* @__PURE__ */ template("<div class=in-cell-edit-wrapper tabindex=-1>"), _tmpl$2 = /* @__PURE__ */ template("<span class=cell-validating>"), _tmpl$3 = /* @__PURE__ */ template("<input style=position:absolute;margin-top:1em;width:0;height:0;pointer-events:none;opacity:0>"), _tmpl$4 = /* @__PURE__ */ template("<input>"), _tmpl$5 = /* @__PURE__ */ template("<
|
|
11
|
+
var _tmpl$ = /* @__PURE__ */ template("<div class=in-cell-edit-wrapper tabindex=-1>"), _tmpl$2 = /* @__PURE__ */ template("<span class=cell-validating>"), _tmpl$3 = /* @__PURE__ */ template("<input style=position:absolute;margin-top:1em;width:0;height:0;pointer-events:none;opacity:0>"), _tmpl$4 = /* @__PURE__ */ template("<input>"), _tmpl$5 = /* @__PURE__ */ template("<label class=\"h-full flex items-center\">"), _tmpl$6 = /* @__PURE__ */ template("<select><option value>-"), _tmpl$7 = /* @__PURE__ */ template("<option>");
|
|
11
12
|
const EditablePlugin = {
|
|
12
13
|
name: "editable",
|
|
13
14
|
store: () => ({ editors: { ...editors } }),
|
|
14
15
|
rewriteProps: {
|
|
15
|
-
editable: ({ editable: e }, { store:
|
|
16
|
-
let
|
|
17
|
-
return !!
|
|
16
|
+
editable: ({ editable: e }, { store: y }) => (x) => {
|
|
17
|
+
let S = [x.col.editable, e].filter((e) => e != null);
|
|
18
|
+
return !!S.length && S.every((e) => unFn(e, x)) && !x.data[y.internal] && !x.col[y.internal];
|
|
18
19
|
},
|
|
19
|
-
Td: ({ Td: e }, { store:
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
22
|
-
let e = !1,
|
|
23
|
-
props:
|
|
24
|
-
col:
|
|
25
|
-
eventKey:
|
|
26
|
-
data:
|
|
27
|
-
value:
|
|
20
|
+
Td: ({ Td: e }, { store: y }) => (x) => {
|
|
21
|
+
let S, { props: C } = useContext(Ctx), [E, D] = createSignal(!1), k = "", A = () => unFn(C.editable, x), M = () => (([e, y]) => x.x == e && x.y == y)(y.selected.start || []), N = () => M() && A() && !E(), [P, F] = createSignal(!1), I = createAsyncMemo(() => {
|
|
22
|
+
if (E()) {
|
|
23
|
+
let e = !1, b = x.data[x.col.id], S = ((e) => typeof e == "string" ? y.editors[e] : e)(x.col.editor ?? x.col.type ?? (x.col.enum ? "select" : "text")), w = {
|
|
24
|
+
props: x.col.editorProps,
|
|
25
|
+
col: x.col,
|
|
26
|
+
eventKey: k,
|
|
27
|
+
data: x.data,
|
|
28
|
+
value: b,
|
|
28
29
|
ok: async () => {
|
|
29
|
-
await L(
|
|
30
|
+
await L(T.getValue()), D(!1);
|
|
30
31
|
},
|
|
31
32
|
cancel: () => (e = !0, D(!1)),
|
|
32
|
-
onChange: (e) =>
|
|
33
|
-
},
|
|
33
|
+
onChange: (e) => E() && L(e).catch(() => {})
|
|
34
|
+
}, T = S(w);
|
|
34
35
|
return onCleanup(() => {
|
|
35
|
-
!e &&
|
|
36
|
-
...
|
|
37
|
-
[
|
|
38
|
-
}), e || L(
|
|
39
|
-
}), [
|
|
36
|
+
!e && T.getValue() !== b && y.commands.rowChange({
|
|
37
|
+
...C.data[x.y],
|
|
38
|
+
[x.col.id]: T.getValue()
|
|
39
|
+
}), e || L(T.getValue()).catch(() => {}), k = "", T.destroy();
|
|
40
|
+
}), [w, T];
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
async function L(e) {
|
|
43
44
|
try {
|
|
44
|
-
F(!0), await
|
|
45
|
+
F(!0), await y.validateCell(e, x.data, x.col);
|
|
45
46
|
} finally {
|
|
46
47
|
F(!1);
|
|
47
48
|
}
|
|
@@ -49,8 +50,8 @@ const EditablePlugin = {
|
|
|
49
50
|
createEffect(() => {
|
|
50
51
|
I()?.[1]?.focus?.();
|
|
51
52
|
}), createEffect(() => {
|
|
52
|
-
if (
|
|
53
|
-
let e = createMemo(() => JSON.stringify(
|
|
53
|
+
if (E()) {
|
|
54
|
+
let e = createMemo(() => JSON.stringify(y.selected ?? "{}"));
|
|
54
55
|
createEffect(on(e, () => D(!1), { defer: !0 }));
|
|
55
56
|
}
|
|
56
57
|
});
|
|
@@ -58,32 +59,32 @@ const EditablePlugin = {
|
|
|
58
59
|
w: 0,
|
|
59
60
|
h: 0
|
|
60
61
|
});
|
|
61
|
-
return createComputed(() =>
|
|
62
|
-
ref: (e) =>
|
|
62
|
+
return createComputed(() => E() && (z.w = S.getBoundingClientRect().width, z.h = S.getBoundingClientRect().height)), x = combineProps(x, {
|
|
63
|
+
ref: (e) => S = e,
|
|
63
64
|
get class() {
|
|
64
|
-
return
|
|
65
|
+
return E() ? "is-editing" : "";
|
|
65
66
|
},
|
|
66
67
|
get style() {
|
|
67
|
-
return
|
|
68
|
+
return E() ? `width: ${z.w}px; height: ${z.h}px; padding: 0; ` : "";
|
|
68
69
|
},
|
|
69
70
|
onClick: () => R?.focus?.(),
|
|
70
|
-
onDblClick: () => D(
|
|
71
|
+
onDblClick: () => D(A()),
|
|
71
72
|
onKeyDown: (e) => e.key == "Escape" && I()?.[0].cancel()
|
|
72
|
-
}), createComponent(e, mergeProps(
|
|
73
|
+
}), createComponent(e, mergeProps(x, { get children() {
|
|
73
74
|
return [memo(() => memo(() => !!I()?.[1]?.el)() ? (() => {
|
|
74
75
|
var e = _tmpl$();
|
|
75
76
|
return addEventListener(e, "keydown", (e) => {
|
|
76
|
-
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && I()?.[0].ok(), e.key == "Escape" && I()?.[0].cancel();
|
|
77
|
+
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && (I()?.[0].ok(), e.preventDefault()), e.key == "Escape" && I()?.[0].cancel();
|
|
77
78
|
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () => I()?.[1]?.el, null), insert(e, (() => {
|
|
78
79
|
var e = memo(() => !!P());
|
|
79
80
|
return () => e() && _tmpl$2();
|
|
80
81
|
})(), null), e;
|
|
81
|
-
})() :
|
|
82
|
+
})() : x.children), memo(() => memo(() => !!N())() && (() => {
|
|
82
83
|
var e = _tmpl$3();
|
|
83
84
|
return e.addEventListener("compositionend", () => {
|
|
84
85
|
D(!0);
|
|
85
86
|
}), e.$$input = (e) => {
|
|
86
|
-
|
|
87
|
+
k = e.target.value, D(!e.isComposing);
|
|
87
88
|
}, e.$$keydown = (e) => {
|
|
88
89
|
e.key == " " && e.preventDefault();
|
|
89
90
|
}, use((e) => {
|
|
@@ -94,35 +95,39 @@ const EditablePlugin = {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
};
|
|
97
|
-
var createEditor = (e,
|
|
98
|
-
let [
|
|
98
|
+
var createEditor = (e, b, x) => ({ eventKey: S, value: C, col: w, ok: T, cancel: E, props: D, onChange: O }) => createRoot((E) => {
|
|
99
|
+
let [k, A] = createSignal(S || C), j;
|
|
99
100
|
return createComponent(e, mergeProps({
|
|
100
|
-
ref: (e) =>
|
|
101
|
+
ref: (e) => j = e,
|
|
101
102
|
class: "relative block px-2 size-full z-9 box-border resize-none outline-0",
|
|
102
103
|
get value() {
|
|
103
|
-
return
|
|
104
|
+
return k();
|
|
104
105
|
},
|
|
105
|
-
onInput: (e) => (
|
|
106
|
-
onChange: (e) => (
|
|
106
|
+
onInput: (e) => (A(e instanceof Event ? e.target.value : e), O?.(k())),
|
|
107
|
+
onChange: (e) => (A(e instanceof Event ? e.target.value : e), O?.(k()), x && T()),
|
|
107
108
|
get options() {
|
|
108
|
-
return memo(() => !!
|
|
109
|
+
return memo(() => !!w.enum)() ? resolveOptions(w.enum ?? []) : void 0;
|
|
109
110
|
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
}, b, D)), setTimeout(() => {
|
|
112
|
+
x && j?.showPicker?.();
|
|
113
|
+
}, 0), {
|
|
114
|
+
el: j,
|
|
115
|
+
getValue: k,
|
|
116
|
+
focus: () => j.focus(),
|
|
117
|
+
destroy: E
|
|
115
118
|
};
|
|
116
119
|
}), Input = (e) => (() => {
|
|
117
|
-
var
|
|
118
|
-
return spread(
|
|
120
|
+
var y = _tmpl$4();
|
|
121
|
+
return spread(y, e, !1, !1), y;
|
|
119
122
|
})();
|
|
120
123
|
const editors = {
|
|
121
124
|
text: createEditor(Input),
|
|
122
|
-
textarea: createEditor((e) => ((
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
125
|
+
textarea: createEditor((e) => createComponent(Textarea_default, mergeProps({ autosize: {
|
|
126
|
+
minRows: 2,
|
|
127
|
+
maxRows: 3
|
|
128
|
+
} }, e, { get class() {
|
|
129
|
+
return `${e.class} bg-[--table-bg] outline-1.5px outline-solid outline-[--c-primary]`;
|
|
130
|
+
} }))),
|
|
126
131
|
number: createEditor(Input, { type: "number" }),
|
|
127
132
|
range: createEditor(Input, { type: "range" }),
|
|
128
133
|
date: createEditor(Input, { type: "date" }, !0),
|
|
@@ -131,27 +136,27 @@ const editors = {
|
|
|
131
136
|
color: createEditor(Input, { type: "color" }),
|
|
132
137
|
tel: createEditor(Input, { type: "tel" }),
|
|
133
138
|
password: createEditor(Input, { type: "password" }),
|
|
134
|
-
file: createEditor((
|
|
139
|
+
file: createEditor((y) => createComponent(Files, mergeProps(y, {
|
|
135
140
|
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
136
|
-
onAdd: () => chooseFile({ multiple: !0 }).then((e) =>
|
|
141
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => y.onChange([...y.value || [], ...e.map((e) => ({
|
|
137
142
|
name: e.name,
|
|
138
143
|
size: e.size
|
|
139
144
|
}))]))
|
|
140
145
|
}))),
|
|
141
146
|
checkbox: createEditor((e) => (() => {
|
|
142
|
-
var
|
|
143
|
-
return typeof
|
|
147
|
+
var y = _tmpl$5(), b = e.ref;
|
|
148
|
+
return typeof b == "function" ? use(b, y) : e.ref = y, insert(y, createComponent(Checkbox, mergeProps(e, {
|
|
144
149
|
ref: () => {},
|
|
145
150
|
onInput: () => {},
|
|
146
151
|
class: "mx-3!"
|
|
147
|
-
}))),
|
|
152
|
+
}))), y;
|
|
148
153
|
})()),
|
|
149
154
|
select: createEditor((e) => (() => {
|
|
150
|
-
var
|
|
151
|
-
return spread(
|
|
152
|
-
var
|
|
153
|
-
return insert(
|
|
154
|
-
})())),
|
|
155
|
+
var y = _tmpl$6();
|
|
156
|
+
return y.firstChild, spread(y, e, !1, !0), insert(y, () => e.options?.map((y) => (() => {
|
|
157
|
+
var b = _tmpl$7();
|
|
158
|
+
return insert(b, () => y.label), effect(() => b.selected = y.value === e.value), effect(() => b.value = y.value), b;
|
|
159
|
+
})()), null), y;
|
|
155
160
|
})(), {}, !0)
|
|
156
161
|
};
|
|
157
162
|
delegateEvents(["keydown", "input"]);
|
|
@@ -4,29 +4,41 @@ import { useSelector } from "../hooks/useSelector.js";
|
|
|
4
4
|
import { createComponent, insert, template } from "solid-js/web";
|
|
5
5
|
import { mergeProps as mergeProps$1 } from "solid-js";
|
|
6
6
|
import { defaultsDeep } from "es-toolkit/compat";
|
|
7
|
-
var _tmpl$ = /* @__PURE__ */ template("<label>");
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template("<label class=\"flex items-center justify-center w-full h-full\">"), _tmpl$2 = /* @__PURE__ */ template("<label>");
|
|
8
8
|
const RowSelectionPlugin = {
|
|
9
9
|
name: "row-selection",
|
|
10
10
|
priority: -Infinity,
|
|
11
|
-
store: (
|
|
12
|
-
[
|
|
11
|
+
store: (l) => ({ rowSelectionCol: {
|
|
12
|
+
[l.internal]: 1,
|
|
13
13
|
id: Symbol("row-selection"),
|
|
14
14
|
fixed: "left",
|
|
15
15
|
class: "row-selection",
|
|
16
16
|
width: 45,
|
|
17
17
|
resizable: !1,
|
|
18
|
+
name: solidComponent((e) => l.props.rowSelection?.multiple && (() => {
|
|
19
|
+
var e = _tmpl$();
|
|
20
|
+
return insert(e, createComponent(Checkbox, {
|
|
21
|
+
get value() {
|
|
22
|
+
return l.commands.rowSelector.isAll(l.props.data);
|
|
23
|
+
},
|
|
24
|
+
onChange: (e) => e ? l.commands.rowSelector.selectAll(l.props.data) : l.commands.rowSelector.clear(),
|
|
25
|
+
get disabled() {
|
|
26
|
+
return !l.props?.data?.length;
|
|
27
|
+
}
|
|
28
|
+
})), e;
|
|
29
|
+
})()),
|
|
18
30
|
render: solidComponent((e) => (() => {
|
|
19
|
-
var
|
|
20
|
-
return insert(
|
|
31
|
+
var u = _tmpl$2();
|
|
32
|
+
return insert(u, createComponent(Checkbox, {
|
|
21
33
|
style: "position: absolute",
|
|
22
34
|
get value() {
|
|
23
|
-
return
|
|
35
|
+
return l.commands.rowSelector.has(e.data);
|
|
24
36
|
},
|
|
25
|
-
onChange: (
|
|
37
|
+
onChange: (c) => c ? l.commands.rowSelector.add(e.data) : l.commands.rowSelector.del(e.data),
|
|
26
38
|
get disabled() {
|
|
27
|
-
return !
|
|
39
|
+
return !l.props?.rowSelection?.selectable?.(e.data);
|
|
28
40
|
}
|
|
29
|
-
})),
|
|
41
|
+
})), u;
|
|
30
42
|
})())
|
|
31
43
|
} }),
|
|
32
44
|
commands: (e) => ({ rowSelector: useSelector(mergeProps$1(() => ({ ...e.props?.rowSelection }))) }),
|
|
@@ -36,7 +48,7 @@ const RowSelectionPlugin = {
|
|
|
36
48
|
multiple: !1,
|
|
37
49
|
selectable: () => !0
|
|
38
50
|
}),
|
|
39
|
-
columns: ({ columns: e }, { store:
|
|
51
|
+
columns: ({ columns: e }, { store: c }) => c.props?.rowSelection?.enable ? [c.rowSelectionCol, ...e] : e
|
|
40
52
|
}
|
|
41
53
|
};
|
|
42
54
|
export { RowSelectionPlugin };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Plugin } from '..';
|
|
1
|
+
import { type Plugin$0 } from '..';
|
|
2
2
|
import { useControlled } from '../hooks/useControlled';
|
|
3
3
|
export type SortOrder = 'asc' | 'desc';
|
|
4
4
|
export interface SortKey {
|
|
@@ -37,4 +37,4 @@ declare module '../index' {
|
|
|
37
37
|
sort: ReturnType<typeof useControlled<Exclude<TableProps['sort'], undefined>>>;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
export declare const SortPlugin: Plugin;
|
|
40
|
+
export declare const SortPlugin: Plugin$0;
|
|
@@ -28,7 +28,7 @@ function applySort(e, c, l) {
|
|
|
28
28
|
}) : e;
|
|
29
29
|
}
|
|
30
30
|
var IconUnsorted = () => _tmpl$(), IconAsc = () => _tmpl$2(), IconDesc = () => _tmpl$3();
|
|
31
|
-
const SortPlugin = {
|
|
31
|
+
const SortPlugin = [{
|
|
32
32
|
name: "sort",
|
|
33
33
|
priority: -1,
|
|
34
34
|
rewriteProps: {
|
|
@@ -42,53 +42,55 @@ const SortPlugin = {
|
|
|
42
42
|
if (!l.value?.length || !l.autoSort) return e;
|
|
43
43
|
let u = Object.fromEntries(c.props.columns.map((e) => [e.id, e]));
|
|
44
44
|
return applySort(e, l.value, u);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} else d = [...h.value, {
|
|
62
|
-
field: e,
|
|
63
|
-
order: "asc"
|
|
64
|
-
}];
|
|
65
|
-
else d = l ? [{
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
name: "sort-th",
|
|
49
|
+
rewriteProps: { Th: ({ Th: e }, { store: f }) => (m) => {
|
|
50
|
+
let h = f.props.sort, g = () => !!m.col.sortable && !m.col[f.internal], _ = () => g() ? h.value.find((e) => e.field === m.col.id) : void 0, v = combineProps(m, {
|
|
51
|
+
get class() {
|
|
52
|
+
return g() ? "cursor-pointer select-none" : "";
|
|
53
|
+
},
|
|
54
|
+
onClick: () => {
|
|
55
|
+
if (!g()) return;
|
|
56
|
+
let e = m.col.id, c = _(), l = c ? c.order === "asc" ? "desc" : null : "asc", u = h.multiple, d = [...h.value];
|
|
57
|
+
if (u) if (l === null) d = h.value.filter((c) => c.field !== e);
|
|
58
|
+
else if (c) {
|
|
59
|
+
let c = h.value.findIndex((c) => c.field === e);
|
|
60
|
+
d[c] = h.value[c] = {
|
|
66
61
|
field: e,
|
|
67
62
|
order: l
|
|
68
|
-
}
|
|
69
|
-
|
|
63
|
+
};
|
|
64
|
+
} else d = [...h.value, {
|
|
65
|
+
field: e,
|
|
66
|
+
order: "asc"
|
|
67
|
+
}];
|
|
68
|
+
else d = l ? [{
|
|
69
|
+
field: e,
|
|
70
|
+
order: l
|
|
71
|
+
}] : [];
|
|
72
|
+
h.onChange([...d]);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return createComponent(e, mergeProps(v, { get children() {
|
|
76
|
+
var e = _tmpl$4();
|
|
77
|
+
return insert(e, () => m.children, null), insert(e, createComponent(Show, {
|
|
78
|
+
get when() {
|
|
79
|
+
return g();
|
|
80
|
+
},
|
|
81
|
+
get children() {
|
|
82
|
+
return createComponent(Show, {
|
|
83
|
+
get when() {
|
|
84
|
+
return _();
|
|
85
|
+
},
|
|
86
|
+
get fallback() {
|
|
87
|
+
return createComponent(IconUnsorted, {});
|
|
88
|
+
},
|
|
89
|
+
children: (e) => memo(() => memo(() => e().order == "asc")() ? createComponent(IconAsc, {}) : createComponent(IconDesc, {}))
|
|
90
|
+
});
|
|
70
91
|
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
get when() {
|
|
76
|
-
return g();
|
|
77
|
-
},
|
|
78
|
-
get children() {
|
|
79
|
-
return createComponent(Show, {
|
|
80
|
-
get when() {
|
|
81
|
-
return _();
|
|
82
|
-
},
|
|
83
|
-
get fallback() {
|
|
84
|
-
return createComponent(IconUnsorted, {});
|
|
85
|
-
},
|
|
86
|
-
children: (e) => memo(() => memo(() => e().order == "asc")() ? createComponent(IconAsc, {}) : createComponent(IconDesc, {}))
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}), null), e;
|
|
90
|
-
} }));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
92
|
+
}), null), e;
|
|
93
|
+
} }));
|
|
94
|
+
} }
|
|
95
|
+
}];
|
|
94
96
|
export { SortPlugin };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from '..';
|
|
2
|
+
declare module '..' {
|
|
3
|
+
interface TableColumn {
|
|
4
|
+
/**
|
|
5
|
+
* Show a floating tooltip on cell hover.
|
|
6
|
+
* - `boolean` → display the cell value as-is
|
|
7
|
+
* - `string` → always show this fixed string
|
|
8
|
+
* - `function`→ compute from `(o: TDProps) => string | undefined`
|
|
9
|
+
*/
|
|
10
|
+
tooltip?: boolean | string | ((o: TDProps) => any);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare const TooltipPlugin: Plugin;
|