intable 0.0.7 → 0.0.9

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.
Files changed (185) hide show
  1. package/README.md +263 -16
  2. package/dist/__uno.css +1 -0
  3. package/dist/chevron-right.js +6 -0
  4. package/dist/components/Columns.d.ts +3 -0
  5. package/dist/components/Columns.js +71 -0
  6. package/dist/components/DocTree.d.ts +4 -0
  7. package/dist/components/DocTree.js +32 -0
  8. package/dist/components/Menu.d.ts +1 -0
  9. package/dist/components/Menu.js +107 -0
  10. package/dist/components/Popover.d.ts +14 -0
  11. package/dist/components/Popover.js +41 -0
  12. package/dist/components/RecycleList.d.ts +26 -0
  13. package/dist/components/RecycleList.js +39 -0
  14. package/dist/components/Render.d.ts +4 -0
  15. package/dist/components/Render.js +20 -0
  16. package/dist/components/Split.d.ts +15 -0
  17. package/dist/components/Split.js +76 -0
  18. package/dist/components/Tree.d.ts +37 -0
  19. package/dist/components/Tree.js +82 -0
  20. package/dist/components/utils.d.ts +3 -0
  21. package/dist/components/utils.js +8 -0
  22. package/dist/hooks/index.d.ts +40 -0
  23. package/dist/hooks/index.js +157 -0
  24. package/dist/hooks/useDir.d.ts +11 -0
  25. package/dist/hooks/useDir.js +42 -0
  26. package/dist/hooks/useSelector.d.ts +16 -0
  27. package/dist/hooks/useSelector.js +69 -0
  28. package/dist/hooks/useSort.d.ts +18 -0
  29. package/dist/hooks/useSort.js +83 -0
  30. package/dist/hooks/useVirtualizer.d.ts +30 -0
  31. package/dist/hooks/useVirtualizer.js +97 -0
  32. package/dist/index.d.ts +147 -0
  33. package/dist/index.js +386 -0
  34. package/dist/loading.js +6 -0
  35. package/dist/plugins/CellChangeHighlightPlugin.d.ts +2 -0
  36. package/dist/plugins/CellChangeHighlightPlugin.js +4 -0
  37. package/dist/plugins/CellMergePlugin.d.ts +45 -0
  38. package/dist/plugins/CellMergePlugin.js +78 -0
  39. package/dist/plugins/CellSelectionPlugin.d.ts +15 -0
  40. package/dist/plugins/CellSelectionPlugin.js +113 -0
  41. package/dist/plugins/CommandPlugin.d.ts +14 -0
  42. package/dist/plugins/CommandPlugin.js +31 -0
  43. package/dist/plugins/CopyPastePlugin.d.ts +14 -0
  44. package/dist/plugins/CopyPastePlugin.js +47 -0
  45. package/dist/plugins/DiffPlugin.d.ts +29 -0
  46. package/dist/plugins/DiffPlugin.js +66 -0
  47. package/dist/plugins/DragPlugin.d.ts +14 -0
  48. package/dist/plugins/DragPlugin.js +47 -0
  49. package/dist/plugins/EditablePlugin.d.ts +51 -0
  50. package/dist/plugins/EditablePlugin.js +177 -0
  51. package/dist/plugins/ExpandPlugin.d.ts +18 -0
  52. package/dist/plugins/ExpandPlugin.js +46 -0
  53. package/dist/plugins/HeaderGroup.d.ts +11 -0
  54. package/dist/plugins/HeaderGroup.js +171 -0
  55. package/dist/plugins/HistoryPlugin.d.ts +10 -0
  56. package/dist/plugins/HistoryPlugin.js +27 -0
  57. package/dist/plugins/MenuPlugin.d.ts +19 -0
  58. package/dist/plugins/MenuPlugin.js +132 -0
  59. package/dist/plugins/RenderPlugin/components.d.ts +5 -0
  60. package/dist/plugins/RenderPlugin/components.js +87 -0
  61. package/dist/plugins/RenderPlugin/index.d.ts +30 -0
  62. package/dist/plugins/RenderPlugin/index.js +49 -0
  63. package/dist/plugins/ResizePlugin.d.ts +27 -0
  64. package/dist/plugins/ResizePlugin.js +82 -0
  65. package/dist/plugins/RowGroupPlugin.d.ts +18 -0
  66. package/dist/plugins/RowGroupPlugin.js +88 -0
  67. package/dist/plugins/RowSelectionPlugin.d.ts +20 -0
  68. package/dist/plugins/RowSelectionPlugin.js +42 -0
  69. package/dist/plugins/TreePlugin.d.ts +24 -0
  70. package/dist/plugins/TreePlugin.js +110 -0
  71. package/dist/plugins/VirtualScrollPlugin.d.ts +15 -0
  72. package/dist/plugins/VirtualScrollPlugin.js +123 -0
  73. package/dist/plugins/ZodValidatorPlugin.d.ts +38 -0
  74. package/dist/plugins/ZodValidatorPlugin.js +12 -0
  75. package/dist/plus.js +6 -0
  76. package/dist/rolldown_runtime.js +9 -0
  77. package/dist/style.css +3 -0
  78. package/dist/theme/dark.scss +46 -0
  79. package/dist/theme/github.scss +80 -0
  80. package/dist/theme/material.scss +73 -0
  81. package/dist/theme/shadcn.scss +66 -0
  82. package/dist/theme/stripe.scss +57 -0
  83. package/dist/tree.d.ts +1 -0
  84. package/dist/tree.js +12 -0
  85. package/dist/types/auto-imports.d.js +0 -0
  86. package/dist/utils.d.ts +31 -0
  87. package/dist/utils.js +71 -0
  88. package/dist/wc.d.ts +1 -0
  89. package/dist/wc.js +21 -0
  90. package/dist/web-component.d.ts +1 -0
  91. package/dist/web-component.js +2 -0
  92. package/dist/x.js +6 -0
  93. package/package.json +38 -30
  94. package/docs/index-BaMALNy6.css +0 -1
  95. package/docs/index-CDN48t9E.js +0 -3
  96. package/docs/index-Cc4RNkLY.css +0 -1
  97. package/docs/index-MRnbkYmU.js +0 -3
  98. package/docs/index.html +0 -15
  99. package/docs/vite.svg +0 -1
  100. package/index.html +0 -14
  101. package/packages/intable/README.md +0 -379
  102. package/packages/intable/package.json +0 -51
  103. package/packages/intable/src/assets/ClearFormat.svg +0 -3
  104. package/packages/intable/src/assets/Forms.svg +0 -4
  105. package/packages/intable/src/assets/MergeCell.svg +0 -4
  106. package/packages/intable/src/assets/SplitCell.svg +0 -4
  107. package/packages/intable/src/assets/gap.svg +0 -3
  108. package/packages/intable/src/assets/loading.svg +0 -12
  109. package/packages/intable/src/assets/paint.svg +0 -9
  110. package/packages/intable/src/assets/solid.svg +0 -1
  111. package/packages/intable/src/components/Columns.tsx +0 -86
  112. package/packages/intable/src/components/DocTree.tsx +0 -36
  113. package/packages/intable/src/components/Menu.tsx +0 -109
  114. package/packages/intable/src/components/Popover.tsx +0 -55
  115. package/packages/intable/src/components/RecycleList.tsx +0 -99
  116. package/packages/intable/src/components/Render.tsx +0 -26
  117. package/packages/intable/src/components/Split.tsx +0 -56
  118. package/packages/intable/src/components/Tree.tsx +0 -115
  119. package/packages/intable/src/components/utils.tsx +0 -12
  120. package/packages/intable/src/hooks/index.ts +0 -200
  121. package/packages/intable/src/hooks/useDir.ts +0 -78
  122. package/packages/intable/src/hooks/useSelector.ts +0 -91
  123. package/packages/intable/src/hooks/useSort.tsx +0 -118
  124. package/packages/intable/src/hooks/useVirtualizer.ts +0 -180
  125. package/packages/intable/src/index.tsx +0 -481
  126. package/packages/intable/src/plugins/CellChangeHighlightPlugin.tsx +0 -5
  127. package/packages/intable/src/plugins/CellMergePlugin.tsx +0 -153
  128. package/packages/intable/src/plugins/CellSelectionPlugin.tsx +0 -175
  129. package/packages/intable/src/plugins/CommandPlugin.tsx +0 -74
  130. package/packages/intable/src/plugins/CopyPastePlugin.tsx +0 -63
  131. package/packages/intable/src/plugins/DiffPlugin.tsx +0 -107
  132. package/packages/intable/src/plugins/DragPlugin.tsx +0 -81
  133. package/packages/intable/src/plugins/EditablePlugin.tsx +0 -252
  134. package/packages/intable/src/plugins/ExpandPlugin.tsx +0 -80
  135. package/packages/intable/src/plugins/HeaderGroup.tsx +0 -289
  136. package/packages/intable/src/plugins/HistoryPlugin.tsx +0 -49
  137. package/packages/intable/src/plugins/MenuPlugin.tsx +0 -195
  138. package/packages/intable/src/plugins/RenderPlugin/components.tsx +0 -51
  139. package/packages/intable/src/plugins/RenderPlugin/index.tsx +0 -81
  140. package/packages/intable/src/plugins/ResizePlugin.tsx +0 -122
  141. package/packages/intable/src/plugins/RowGroupPlugin.tsx +0 -122
  142. package/packages/intable/src/plugins/RowSelectionPlugin.tsx +0 -65
  143. package/packages/intable/src/plugins/TreePlugin.tsx +0 -212
  144. package/packages/intable/src/plugins/VirtualScrollPlugin.tsx +0 -190
  145. package/packages/intable/src/plugins/ZodValidatorPlugin.tsx +0 -61
  146. package/packages/intable/src/style.scss +0 -244
  147. package/packages/intable/src/tree.ts +0 -13
  148. package/packages/intable/src/types/auto-imports.d.ts +0 -13
  149. package/packages/intable/src/utils.ts +0 -122
  150. package/packages/intable/src/wc.tsx +0 -35
  151. package/packages/intable/src/web-component.ts +0 -1
  152. package/packages/react/package.json +0 -31
  153. package/packages/react/src/index.ts +0 -44
  154. package/packages/react/src/plugins/antd.ts +0 -94
  155. package/packages/react/src/style.scss +0 -12
  156. package/packages/react/src/types/auto-imports.d.ts +0 -10
  157. package/packages/vue/package.json +0 -34
  158. package/packages/vue/src/index.ts +0 -63
  159. package/packages/vue/src/plugins/element-plus.ts +0 -69
  160. package/packages/vue/src/style.scss +0 -12
  161. package/packages/vue/src/types/auto-imports.d.ts +0 -10
  162. package/pnpm-workspace.yaml +0 -2
  163. package/public/vite.svg +0 -1
  164. package/scripts/build.js +0 -184
  165. package/scripts/publish.js +0 -95
  166. package/src/assets/ClearFormat.svg +0 -3
  167. package/src/assets/Forms.svg +0 -4
  168. package/src/assets/MergeCell.svg +0 -4
  169. package/src/assets/SplitCell.svg +0 -4
  170. package/src/assets/gap.svg +0 -3
  171. package/src/assets/loading.svg +0 -12
  172. package/src/assets/paint.svg +0 -9
  173. package/src/assets/solid.svg +0 -1
  174. package/src/demo-vue.ts +0 -54
  175. package/src/demo.tsx +0 -107
  176. package/src/index.scss +0 -105
  177. package/src/styles/index.scss +0 -172
  178. package/src/types/auto-imports.d.ts +0 -13
  179. package/stats.html +0 -4949
  180. package/tsconfig.app.json +0 -34
  181. package/tsconfig.json +0 -7
  182. package/tsconfig.node.json +0 -26
  183. package/vite.config.ts +0 -63
  184. /package/{packages/intable/src → dist}/theme/antd.scss +0 -0
  185. /package/{packages/intable/src → dist}/theme/element-plus.scss +0 -0
@@ -0,0 +1,171 @@
1
+ import { Ctx } from "../index.js";
2
+ import { createComponent, memo, mergeProps } from "solid-js/web";
3
+ import { For, Show, createEffect, createMemo, createSignal, useContext } from "solid-js";
4
+ function leafCount(e) {
5
+ return e.children?.length ? e.children.reduce((e, t) => e + leafCount(t), 0) : 1;
6
+ }
7
+ function maxDepth(e) {
8
+ let t = 0;
9
+ for (let n of e) n.children?.length && (t = Math.max(t, maxDepth(n.children)));
10
+ return t + 1;
11
+ }
12
+ function flatLeaves(e, t = []) {
13
+ for (let n of e) n.children?.length ? flatLeaves(n.children, t) : t.push(n);
14
+ return t;
15
+ }
16
+ function buildFlatGrid(e, t, n, r, i, a) {
17
+ let o = n.length, s = Array.from({ length: t }, () => Array(o).fill(null)), c = 0;
18
+ function l(e, a) {
19
+ for (let o of e) {
20
+ let e = !!o.children?.length, d = leafCount(o), f = e ? 1 : t - a, p = e ? i[c] : o, m = r.get(p);
21
+ if (m == null) {
22
+ e || c++;
23
+ continue;
24
+ }
25
+ s[a][m] = {
26
+ kind: "anchor",
27
+ anchorCol: o,
28
+ colspan: d,
29
+ rowspan: f
30
+ };
31
+ for (let e = 1; e < d; e++) s[a][m + e] = {
32
+ kind: "colspan-hidden",
33
+ anchorCol: o,
34
+ colspan: d,
35
+ rowspan: f
36
+ };
37
+ for (let e = 1; e < f; e++) for (let t = 0; t < d; t++) s[a + e][m + t] = {
38
+ kind: "rowspan-hidden",
39
+ anchorCol: n[m + t],
40
+ colspan: 1,
41
+ rowspan: 1
42
+ };
43
+ e ? l(o.children, a + 1) : c++;
44
+ }
45
+ }
46
+ c = 0, l(e, 0);
47
+ for (let e = 0; e < o; e++) {
48
+ if (s[0][e] != null) continue;
49
+ let r = n[e];
50
+ if (r[a.internal]) {
51
+ s[0][e] = {
52
+ kind: "anchor",
53
+ anchorCol: r,
54
+ colspan: 1,
55
+ rowspan: t
56
+ };
57
+ for (let n = 1; n < t; n++) s[n][e] = {
58
+ kind: "rowspan-hidden",
59
+ anchorCol: r,
60
+ colspan: 1,
61
+ rowspan: 1
62
+ };
63
+ }
64
+ }
65
+ return s;
66
+ }
67
+ const HeaderGroupPlugin = {
68
+ name: "header-group",
69
+ store: (e) => ({ _headerGroupAnchors(t, n) {
70
+ let r = e.rawProps.columns || [];
71
+ if (!r.some((e) => e.children?.length) || maxDepth(r) <= 1) return [];
72
+ let i = e.props.columns || [], a = flatLeaves(r), o = /* @__PURE__ */ new Map();
73
+ for (let t = 0; t < i.length; t++) o.set(i[t][e.raw] || i[t], t);
74
+ let s = [], c = 0;
75
+ function l(e) {
76
+ for (let r of e) if (r.children?.length) {
77
+ let e = leafCount(r), i = a[c];
78
+ if (i) {
79
+ let r = o.get(i);
80
+ if (r != null) {
81
+ let i = r + e - 1;
82
+ r <= n && i >= t && s.push(r);
83
+ }
84
+ }
85
+ l(r.children);
86
+ } else c++;
87
+ }
88
+ return l(r), s;
89
+ } }),
90
+ rewriteProps: {
91
+ columns: ({ columns: e }) => flatLeaves(e),
92
+ Thead: ({ Thead: u }, { store: m }) => (h) => {
93
+ let { props: g } = useContext(Ctx), _ = createMemo(() => {
94
+ let e = m.rawProps.columns || [], t = maxDepth(e);
95
+ if (t <= 1) return null;
96
+ let n = g.columns || [], r = flatLeaves(e), i = /* @__PURE__ */ new Map();
97
+ for (let e = 0; e < n.length; e++) i.set(n[e][m.raw] || n[e], e);
98
+ return {
99
+ grid: buildFlatGrid(e, t, n, i, r, m),
100
+ depth: t
101
+ };
102
+ }), [v, y] = createSignal(24);
103
+ createEffect(() => {
104
+ let e = m.thead;
105
+ if (!e) return;
106
+ let t = e.querySelectorAll(":scope > tr"), n = t[t.length - 1];
107
+ n && y(n.offsetHeight || 24);
108
+ });
109
+ let b = () => !!m.virtualizerX;
110
+ return createComponent(Show, {
111
+ get when() {
112
+ return _();
113
+ },
114
+ get fallback() {
115
+ return createComponent(u, h);
116
+ },
117
+ children: (e) => createComponent(u, mergeProps(h, { get children() {
118
+ return createComponent(For, {
119
+ get each() {
120
+ return e().grid;
121
+ },
122
+ children: (r, i) => createComponent(g.Tr, {
123
+ get style() {
124
+ return memo(() => !!b())() ? `height:${v()}px;overflow:visible;position:relative;z-index:${e().depth - i()}` : "";
125
+ },
126
+ get children() {
127
+ return createComponent(g.EachCells, {
128
+ get each() {
129
+ return g.columns;
130
+ },
131
+ children: (e, i) => {
132
+ let a = () => r[i()];
133
+ if (!a()) return null;
134
+ let o = () => {
135
+ let e = a();
136
+ return e.kind === "anchor" ? b() && e.rowspan > 1 && v() ? `height:${e.rowspan * v()}px;position:relative;` : "" : e.kind === "colspan-hidden" ? "display:none" : e.kind === "rowspan-hidden" ? b() ? "visibility:hidden" : "display:none" : "";
137
+ }, s = () => a().kind === "anchor";
138
+ return createComponent(g.Th, {
139
+ get x() {
140
+ return i();
141
+ },
142
+ get col() {
143
+ return memo(() => !!s())() ? a().anchorCol : e();
144
+ },
145
+ get colspan() {
146
+ return memo(() => !!(s() && a().colspan > 1))() ? a().colspan : void 0;
147
+ },
148
+ get rowspan() {
149
+ return memo(() => !!(s() && a().rowspan > 1))() ? a().rowspan : void 0;
150
+ },
151
+ get style() {
152
+ return o();
153
+ },
154
+ get covered() {
155
+ return !s();
156
+ },
157
+ get children() {
158
+ return memo(() => !!s())() ? a().anchorCol.name : "";
159
+ }
160
+ });
161
+ }
162
+ });
163
+ }
164
+ })
165
+ });
166
+ } }))
167
+ });
168
+ }
169
+ }
170
+ };
171
+ export { HeaderGroupPlugin };
@@ -0,0 +1,10 @@
1
+ import { useHistory } from '../hooks';
2
+ import { type Plugin } from '..';
3
+ declare module '../index' {
4
+ interface TableProps {
5
+ }
6
+ interface TableStore {
7
+ history: ReturnType<typeof useHistory>;
8
+ }
9
+ }
10
+ export declare const HistoryPlugin: Plugin;
@@ -0,0 +1,27 @@
1
+ import { useHistory } from "../hooks/index.js";
2
+ import { createMemo } from "solid-js";
3
+ import { unwrap } from "solid-js/store";
4
+ import { combineProps } from "@solid-primitives/props";
5
+ import { captureStoreUpdates } from "@solid-primitives/deep";
6
+ const HistoryPlugin = {
7
+ store: (r) => {
8
+ let a = createMemo(() => captureStoreUpdates(r.rawProps.data || [])), o;
9
+ return { history: useHistory([() => {
10
+ let e = a()();
11
+ if (e.length) {
12
+ for (let { path: n, value: r } of e) if (n.length == 0) o = structuredClone(unwrap(r));
13
+ else {
14
+ let e = [...o];
15
+ n.reduce((e, i, a) => e[i] = a < n.length - 1 ? Array.isArray(e[i]) ? [...e[i]] : { ...e[i] } : structuredClone(unwrap(r)), e), o = e;
16
+ }
17
+ return o;
18
+ }
19
+ }, (e) => r.props.onDataChange?.(e)]) };
20
+ },
21
+ keybindings: (e) => ({
22
+ "$mod+Z": () => e.history.undo(),
23
+ "$mod+Y": () => e.history.redo()
24
+ }),
25
+ rewriteProps: { tdProps: ({ tdProps: e }, { store: n }) => (n) => combineProps(e?.(n) || {}, {}) }
26
+ };
27
+ export { HistoryPlugin };
@@ -0,0 +1,19 @@
1
+ import { type Plugin } from '..';
2
+ declare module '../index' {
3
+ interface TableProps {
4
+ }
5
+ interface TableStore {
6
+ }
7
+ interface Plugin {
8
+ menus?: (store: TableStore) => any[];
9
+ }
10
+ interface Commands {
11
+ rowEquals: (a: any, b: any) => boolean;
12
+ rowIndexOf: (data: any[], row: any) => number;
13
+ rowChange: (row: any, i?: any) => void;
14
+ addRows: (i: number, rows: any[], before?: boolean) => void;
15
+ deleteRows: (i: number[]) => void;
16
+ moveRows: (ii: number[], to: number) => void;
17
+ }
18
+ }
19
+ export declare const MenuPlugin: Plugin;
@@ -0,0 +1,132 @@
1
+ import { findParent } from "../tree.js";
2
+ import "../utils.js";
3
+ import { useMemoAsync } from "../hooks/index.js";
4
+ import { Menu } from "../components/Menu.js";
5
+ import { createComponent, memo, mergeProps } from "solid-js/web";
6
+ import { batch, createMemo, createSignal, mapArray } from "solid-js";
7
+ import { combineProps } from "@solid-primitives/props";
8
+ import { range, remove } from "es-toolkit";
9
+ import { createEventListener } from "@solid-primitives/event-listener";
10
+ import { autoPlacement, computePosition } from "@floating-ui/dom";
11
+ const MenuPlugin = {
12
+ name: "menu",
13
+ priority: Infinity,
14
+ store: (e) => ({}),
15
+ rewriteProps: { Table: ({ Table: e }, { store: s }) => (f) => {
16
+ let [p, g] = createSignal(), _ = mapArray(() => s.plugins || [], (e) => createMemo(() => e.menus?.(s))), v = createMemo(() => _().flatMap((e) => e() || [])), [y, b] = createSignal();
17
+ function x(e) {
18
+ e.preventDefault(), b({
19
+ x: e.x,
20
+ y: e.y
21
+ });
22
+ }
23
+ createEventListener(document, "pointerdown", (e) => {
24
+ p()?.contains(e.target) || b();
25
+ });
26
+ let S = useMemoAsync(() => {
27
+ let e = p();
28
+ if (e) return computePosition({ getBoundingClientRect: () => DOMRect.fromRect(y()) }, e, {
29
+ strategy: "fixed",
30
+ placement: "top-start",
31
+ middleware: [autoPlacement({
32
+ boundary: document.body,
33
+ alignment: "start"
34
+ })]
35
+ }).then(({ x: e, y: n }) => ({
36
+ position: "fixed",
37
+ transform: `translate(${e}px, ${n}px)`,
38
+ top: 0,
39
+ left: 0,
40
+ "z-index": 10
41
+ }));
42
+ });
43
+ return f = combineProps({
44
+ tabindex: -1,
45
+ onContextMenu: x
46
+ }, f), createComponent(e, mergeProps(f, { get children() {
47
+ return [memo(() => memo(() => !!y())() && createComponent(Menu, {
48
+ ref: g,
49
+ get style() {
50
+ return S() || "position: fixed";
51
+ },
52
+ get items() {
53
+ return v();
54
+ },
55
+ onAction: () => b()
56
+ })), memo(() => f.children)];
57
+ } }));
58
+ } },
59
+ menus: (e) => [
60
+ {
61
+ label: "新增行 ↑",
62
+ cb: () => e.commands.addRows(e.selected.end[1], [e.props.newRow(e.selected.end[1])])
63
+ },
64
+ {
65
+ label: "新增行 ↓",
66
+ cb: () => e.commands.addRows(e.selected.end[1], [e.props.newRow(e.selected.end[1])], !1)
67
+ },
68
+ {
69
+ label: "删除行",
70
+ cb: () => e.commands.deleteRows(range(...((e) => [e[0], e[1] + 1])([e.selected.start[1], e.selected.end[1]].sort((e, n) => e - n))))
71
+ }
72
+ ],
73
+ commands: (n) => ({
74
+ rowEquals(e, n) {
75
+ return e == n;
76
+ },
77
+ rowIndexOf(e, r) {
78
+ return e.findIndex((e) => n.commands.rowEquals(e, r));
79
+ },
80
+ rowChange(e, r) {
81
+ let i = [...n.rawProps.data || []];
82
+ r = r == null ? n.commands.rowIndexOf(i, e) : i.findIndex((e) => e == n.props.data[r]), r > -1 && (i[r] = e, n.props.onDataChange?.(i));
83
+ },
84
+ addRows(e, r, i = !0) {
85
+ addRows(n, e, r, i);
86
+ },
87
+ deleteRows(e) {
88
+ let { rowKey: r, data: i } = n.props, a = [...n.rawProps.data || []], o = new Set(e.map((e) => i[e]));
89
+ remove(a, (e) => o.has(e)), n.props?.onDataChange?.(a);
90
+ },
91
+ moveRows(r, i) {
92
+ let { data: a } = n.props, o = r.map((e) => a[e]).filter((e) => e && !e?.[n.internal]);
93
+ if (!o.length) return;
94
+ let s = i >= 0 && i < a.length ? a[i] : null, { rowKey: c } = n.props, l = n.props.tree?.children || Symbol(), u = new Set(o.map((e) => e[c])), d = [];
95
+ function f(e) {
96
+ return e.reduce((e, n) => {
97
+ if (u.has(n[c])) return d.push(n), e;
98
+ if (Array.isArray(n[l]) && n[l].length) {
99
+ let e = f(n[l]);
100
+ n = e.length === n[l].length ? n : {
101
+ ...n,
102
+ [l]: e
103
+ };
104
+ }
105
+ return e.push(n), e;
106
+ }, []);
107
+ }
108
+ let p = f([...n.rawProps.data || []]), m = findParent(p, (e) => e[c] === s?.[c])?.children ?? p, h = s ? m.findIndex((e) => e[c] === s[c]) : -1;
109
+ if (h > -1 ? m.splice(h, 0, d) : m.push(...d), n.selected) {
110
+ let e = Math.max(0, i - o.length);
111
+ n.selected.start = [0, e], n.selected.end = [Infinity, e + d.length - 1];
112
+ }
113
+ n.props?.onDataChange?.(p);
114
+ }
115
+ })
116
+ };
117
+ function addRows(e, n, r, i) {
118
+ let { data: a } = e.props, o = (n) => {
119
+ for (i = !1; --n >= 0 && a[n]?.[e.internal];);
120
+ return n >= 0 ? a[n] : null;
121
+ }, c = (n) => {
122
+ for (i = !0; ++n < a.length && a[n]?.[e.internal];);
123
+ return n < a.length ? a[n] : null;
124
+ }, l = a[n]?.[e.internal] ? i ? o(n) || c(n) : c(n) || o(n) : a[n];
125
+ l && batch(() => {
126
+ n = e.commands.rowIndexOf(a, l), e.selected && (e.selected.start = [0, n + (i ? 0 : 1)], e.selected.end = [Infinity, n + r.length - 1 + (i ? 0 : 1)]);
127
+ }), (() => {
128
+ let n = [...e.rawProps.data || []], a = l ? e.commands.rowIndexOf(n, l) + (i ? 0 : 1) : n.length;
129
+ n.splice(a, 0, ...r), e.props?.onDataChange?.(n);
130
+ })();
131
+ }
132
+ export { MenuPlugin };
@@ -0,0 +1,5 @@
1
+ export declare const Checkbox: import("solid-js").Component<Record<string, any>>;
2
+ export declare const Files: import("solid-js").Component<Record<string, any>>;
3
+ export declare const Tags: import("solid-js").Component<Record<string, any>>;
4
+ export declare const Tag: import("solid-js").Component<Record<string, any>>;
5
+ export declare const evaluateFormula: (formula: string, data: any) => any;
@@ -0,0 +1,87 @@
1
+ import plus_default from "../../plus.js";
2
+ import x_default from "../../x.js";
3
+ import { createComponent, insert, memo, mergeProps, spread, template } from "solid-js/web";
4
+ import { For, splitProps } from "solid-js";
5
+ import { combineProps } from "@solid-primitives/props";
6
+ var _tmpl$ = /* @__PURE__ */ template("<input type=checkbox>"), _tmpl$2 = /* @__PURE__ */ template("<div>");
7
+ const Checkbox = (e) => {
8
+ let f;
9
+ return [e, f] = splitProps(e, ["value", "onChange"]), f = combineProps({ get class() {
10
+ return `you-checkbox ${e.value && "checked"}`;
11
+ } }, f), (() => {
12
+ var p = _tmpl$();
13
+ return p.addEventListener("change", (f) => e.onChange?.(f.currentTarget.checked)), spread(p, mergeProps({ get checked() {
14
+ return e.value || !1;
15
+ } }, f), !1, !1), p;
16
+ })();
17
+ }, Files = (e) => {
18
+ let f;
19
+ return [e, f] = splitProps(e, []), createComponent(Tags, f);
20
+ }, Tags = (f) => {
21
+ let h;
22
+ [f, h] = splitProps(f, [
23
+ "value",
24
+ "children",
25
+ "disabled",
26
+ "onChange",
27
+ "onAdd"
28
+ ]), h = combineProps({ class: "flex flex-wrap items-center gap-2 h-full" }, h);
29
+ let g = (e) => Array.isArray(e) ? e : e == null ? [] : [e];
30
+ return (() => {
31
+ var _ = _tmpl$2();
32
+ return spread(_, h, !1, !0), insert(_, createComponent(For, {
33
+ get each() {
34
+ return g(f.value);
35
+ },
36
+ children: (e) => createComponent(Tag, {
37
+ get style() {
38
+ return `background: ${e.color}`;
39
+ },
40
+ get disabled() {
41
+ return f.disabled;
42
+ },
43
+ onDel: () => f.onChange(g(f.value).filter((f) => f != e)),
44
+ get children() {
45
+ return memo(() => !!f.children)() ? f.children(e) : e?.text ?? e?.label ?? e?.name ?? e;
46
+ }
47
+ })
48
+ }), null), insert(_, (() => {
49
+ var m = memo(() => !f.disabled);
50
+ return () => m() && createComponent(Tag, {
51
+ disabled: !0,
52
+ get onClick() {
53
+ return f.onAdd;
54
+ },
55
+ get children() {
56
+ return createComponent(plus_default, {});
57
+ }
58
+ });
59
+ })(), null), _;
60
+ })();
61
+ }, Tag = (e) => {
62
+ let h;
63
+ return [e, h] = splitProps(e, [
64
+ "disabled",
65
+ "children",
66
+ "onDel"
67
+ ]), h = combineProps({ class: "flex items-center px-2 py-1 rd-sm bg-gray/20 text-3.5 lh-[1]" }, h), (() => {
68
+ var g = _tmpl$2();
69
+ return spread(g, h, !1, !0), insert(g, () => e.children, null), insert(g, (() => {
70
+ var m = memo(() => !e.disabled);
71
+ return () => m() && createComponent(x_default, {
72
+ class: "icon-clickable flex-shrink-0 size-4! ml-1 mr--1 op-75",
73
+ get onClick() {
74
+ return e.onDel;
75
+ }
76
+ });
77
+ })(), null), g;
78
+ })();
79
+ }, evaluateFormula = (e, f) => {
80
+ try {
81
+ let p = { data: f };
82
+ return Function(...Object.keys(p), "return " + e)(...Object.values(p));
83
+ } catch {
84
+ return "公式错误";
85
+ }
86
+ };
87
+ export { Checkbox, Files, Tag, Tags, evaluateFormula };
@@ -0,0 +1,30 @@
1
+ import { type JSX } from 'solid-js';
2
+ import { type Plugin, type TD } from '../..';
3
+ declare module '../../index' {
4
+ interface TableProps {
5
+ }
6
+ interface TableColumn {
7
+ render?: Render;
8
+ enum?: Record<string, any> | {
9
+ label?: string;
10
+ value: any;
11
+ }[];
12
+ }
13
+ interface TableStore {
14
+ renders: {
15
+ [key: string]: Render;
16
+ };
17
+ }
18
+ }
19
+ export type RenderProps = Parameters<TD>[0] & {
20
+ onChange: (v: any) => void;
21
+ };
22
+ export type Render = (props: RenderProps) => JSX.Element | any;
23
+ export declare const RenderPlugin: Plugin;
24
+ export declare const renders: {
25
+ text: Render;
26
+ number: Render;
27
+ date: Render;
28
+ checkbox: Render;
29
+ file: Render;
30
+ };
@@ -0,0 +1,49 @@
1
+ import { resolveOptions } from "../../utils.js";
2
+ import { Checkbox, Files } from "./components.js";
3
+ import { renderComponent, solidComponent } from "../../components/utils.js";
4
+ import { createComponent, insert, memo, mergeProps, template } from "solid-js/web";
5
+ import { mergeProps as mergeProps$1 } from "solid-js";
6
+ var _tmpl$ = /* @__PURE__ */ template("<div class=\"flex items-center h-full\">");
7
+ const RenderPlugin = {
8
+ name: "render",
9
+ priority: -Infinity,
10
+ store: () => ({ renders: { ...renders } }),
11
+ rewriteProps: { Td: ({ Td: e }, { store: p }) => (m) => createComponent(e, mergeProps(m, { get children() {
12
+ return (() => {
13
+ let e = ((e) => typeof e == "string" ? p.renders[e] : e)(m.col.render) || text;
14
+ return renderComponent(e, mergeProps$1(m, { onChange: (e) => p.commands.rowChange({
15
+ ...m.data,
16
+ [m.col.id]: e
17
+ }, m.y) }), p.props.renderer);
18
+ })();
19
+ } })) }
20
+ };
21
+ var text = (p) => memo(() => ((m) => p.col.enum ? resolveOptions(p.col.enum).find((e) => e.value == m)?.label ?? m : m)(p.data[p.col.id]));
22
+ const renders = {
23
+ text,
24
+ number: text,
25
+ date: text,
26
+ checkbox: (e) => (() => {
27
+ var m = _tmpl$();
28
+ return insert(m, createComponent(Checkbox, {
29
+ class: "",
30
+ get value() {
31
+ return e.data[e.col.id];
32
+ },
33
+ get onChange() {
34
+ return e.onChange;
35
+ }
36
+ })), m;
37
+ })(),
38
+ file: (e) => createComponent(Files, {
39
+ get value() {
40
+ return e.data[e.col.id];
41
+ },
42
+ get onChange() {
43
+ return e.onChange;
44
+ },
45
+ disabled: !0
46
+ })
47
+ };
48
+ for (let e in renders) renders[e] = solidComponent(renders[e]);
49
+ export { RenderPlugin, renders };
@@ -0,0 +1,27 @@
1
+ import { type Plugin } from "../index";
2
+ declare module '../index' {
3
+ interface TableProps {
4
+ resizable?: {
5
+ col?: Partial<{
6
+ enable: boolean;
7
+ min: number;
8
+ max: number;
9
+ }>;
10
+ row?: Partial<{
11
+ enable: boolean;
12
+ min: number;
13
+ max: number;
14
+ }>;
15
+ };
16
+ onColumnsChange?: (columns: TableColumn[]) => void;
17
+ }
18
+ interface TableColumn {
19
+ resizable?: boolean;
20
+ onWidthChange?: (width: number) => void;
21
+ }
22
+ interface TableStore {
23
+ }
24
+ interface Commands {
25
+ }
26
+ }
27
+ export declare const ResizePlugin: Plugin;
@@ -0,0 +1,82 @@
1
+ import { unFn } from "../utils.js";
2
+ import { usePointerDrag } from "../hooks/index.js";
3
+ import { Ctx } from "../index.js";
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
+ import { combineProps } from "@solid-primitives/props";
8
+ import { clamp } from "es-toolkit";
9
+ import { createEventListener } from "@solid-primitives/event-listener";
10
+ import { defaultsDeep } from "es-toolkit/compat";
11
+ var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), ColHandle = (e) => {
12
+ let { props: g, store: v } = useContext(Ctx), y;
13
+ return usePointerDrag(() => y, { start(p, m, h) {
14
+ p.stopPropagation();
15
+ let _ = e.x, { min: b, max: x } = g.resizable.col, S = y.parentElement, C = S.offsetWidth;
16
+ m((p, { ox: m }) => v[COL][e.x] = clamp(C + m, b, x)), h(() => {
17
+ let e = g.columns[_], p = [...v.rawProps.columns || []], m = p.indexOf(e[v.raw] ?? e);
18
+ m > -1 && (p[m] = {
19
+ ...p[m],
20
+ width: S.offsetWidth
21
+ }, g.onColumnsChange?.(p)), e.onWidthChange?.(S.offsetWidth);
22
+ });
23
+ } }), (() => {
24
+ var p = _tmpl$(), m = y;
25
+ return typeof m == "function" ? use(m, p) : y = p, effect(() => className(p, `in-cell__resize-handle absolute top-0 right-0 flex justify-center w-10px! ${e.x == g.columns.length - 1 ? "justify-end!" : "w-10px! translate-x-1/2"} after:w-1 cursor-w-resize z-1`)), p;
26
+ })();
27
+ }, RowHandle = (e) => {
28
+ let { props: g, store: v } = useContext(Ctx), y;
29
+ return usePointerDrag(() => y, { start(p, m, h) {
30
+ p.stopPropagation();
31
+ let _ = e.y, { min: b, max: x } = g.resizable.row, S = y.parentElement.offsetHeight;
32
+ m((p, { oy: m }) => v[ROW][e.y] = clamp(S + m, b, x)), h(() => {
33
+ let e = g.data[_];
34
+ [...v.rawProps.data || []].indexOf(e[v.raw] ?? e);
35
+ });
36
+ } }), createEventListener(() => y, "dblclick", () => e.data[COL] = void 0), (() => {
37
+ var p = _tmpl$(), m = y;
38
+ return typeof m == "function" ? use(m, p) : y = p, effect(() => className(p, `in-cell__resize-handle absolute bottom-0 left-0 flex flex-col justify-center h-1! ${e.y == g.data.length - 1 ? "justify-end!" : ""} after:h-1 cursor-s-resize z-1`)), p;
39
+ })();
40
+ };
41
+ const ResizePlugin = {
42
+ name: "resize",
43
+ priority: -Infinity,
44
+ store: () => ({
45
+ [COL]: [],
46
+ [ROW]: []
47
+ }),
48
+ rewriteProps: {
49
+ resizable: ({ resizable: e }) => defaultsDeep(e, {
50
+ col: {
51
+ enable: !0,
52
+ min: 45,
53
+ max: 800
54
+ },
55
+ row: {
56
+ enable: !1,
57
+ min: 20,
58
+ max: 400
59
+ }
60
+ }),
61
+ columns: ({ columns: e }, { store: p }) => (e = e.map((e, m) => ({
62
+ ...e,
63
+ [p.raw]: e[p.raw] ?? e
64
+ })), e = e.map((e) => e.resizable === void 0 ? {
65
+ ...e,
66
+ resizable: p.props?.resizable?.col.enable,
67
+ [p.raw]: e[p.raw] ?? e
68
+ } : e), e = e.map((e, m) => p[COL][m] ? {
69
+ ...e,
70
+ width: p[COL][m],
71
+ [p.raw]: e[p.raw] ?? e
72
+ } : e), untrack(() => batch(() => reconcile(e, { key: p.raw })(p.__resize__cols ??= [])))),
73
+ Th: ({ Th: e }, { store: p }) => (p) => (p = combineProps({ class: "relative" }, p), createComponent(e, mergeProps(p, { get children() {
74
+ return [memo(() => p.children), memo(() => memo(() => !!p.col.resizable)() && createComponent(ColHandle, p))];
75
+ } }))),
76
+ Td: ({ Td: e }, { store: p }) => p.props?.resizable?.row.enable ? (m) => (m = combineProps({ class: "relative" }, m), createComponent(e, mergeProps(m, { get children() {
77
+ return [memo(() => m.children), memo(() => memo(() => !!(m.x == 0 && p.props?.resizable?.row.enable))() && createComponent(RowHandle, m))];
78
+ } }))) : e,
79
+ cellStyle: ({ cellStyle: p }, { store: m }) => (h) => `${unFn(p, h)};` + (m[ROW][h.y] ? `height: ${m[ROW][h.y]}px` : "")
80
+ }
81
+ };
82
+ export { ResizePlugin };
@@ -0,0 +1,18 @@
1
+ import { type Plugin } from '..';
2
+ declare module '../index' {
3
+ interface TableProps {
4
+ rowGroup?: {
5
+ fields?: string[];
6
+ };
7
+ }
8
+ interface TableStore {
9
+ rowGroup: {
10
+ /** Plain-object map used as Set<string>; property access is tracked by createMutable */
11
+ expandKeys: Record<string, true | undefined>;
12
+ isExpand: (data: any) => boolean;
13
+ expand: (data: any, r?: any) => void;
14
+ toggleExpand: (data: any) => void;
15
+ };
16
+ }
17
+ }
18
+ export declare const RowGroupPlugin: Plugin;