intable 0.0.8 → 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 (208) 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/tree.d.ts +1 -0
  79. package/dist/tree.js +12 -0
  80. package/dist/types/auto-imports.d.js +0 -0
  81. package/dist/utils.d.ts +31 -0
  82. package/dist/utils.js +71 -0
  83. package/dist/wc.d.ts +1 -0
  84. package/dist/wc.js +21 -0
  85. package/dist/web-component.d.ts +1 -0
  86. package/dist/web-component.js +2 -0
  87. package/dist/x.js +6 -0
  88. package/package.json +38 -35
  89. package/.github/copilot-instructions.md +0 -102
  90. package/docs/index-BaMALNy6.css +0 -1
  91. package/docs/index-CDN48t9E.js +0 -3
  92. package/docs/index-Cc4RNkLY.css +0 -1
  93. package/docs/index-MRnbkYmU.js +0 -3
  94. package/docs/index.html +0 -15
  95. package/docs/vite.svg +0 -1
  96. package/index.html +0 -13
  97. package/packages/intable/README.md +0 -379
  98. package/packages/intable/package.json +0 -51
  99. package/packages/intable/src/assets/ClearFormat.svg +0 -3
  100. package/packages/intable/src/assets/Forms.svg +0 -4
  101. package/packages/intable/src/assets/MergeCell.svg +0 -4
  102. package/packages/intable/src/assets/SplitCell.svg +0 -4
  103. package/packages/intable/src/assets/gap.svg +0 -3
  104. package/packages/intable/src/assets/loading.svg +0 -12
  105. package/packages/intable/src/assets/paint.svg +0 -9
  106. package/packages/intable/src/assets/solid.svg +0 -1
  107. package/packages/intable/src/components/Columns.tsx +0 -86
  108. package/packages/intable/src/components/DocTree.tsx +0 -36
  109. package/packages/intable/src/components/Menu.tsx +0 -109
  110. package/packages/intable/src/components/Popover.tsx +0 -55
  111. package/packages/intable/src/components/RecycleList.tsx +0 -99
  112. package/packages/intable/src/components/Render.tsx +0 -26
  113. package/packages/intable/src/components/Split.tsx +0 -56
  114. package/packages/intable/src/components/Tree.tsx +0 -115
  115. package/packages/intable/src/components/utils.tsx +0 -12
  116. package/packages/intable/src/hooks/index.ts +0 -200
  117. package/packages/intable/src/hooks/useDir.ts +0 -78
  118. package/packages/intable/src/hooks/useSelector.ts +0 -91
  119. package/packages/intable/src/hooks/useSort.tsx +0 -118
  120. package/packages/intable/src/hooks/useVirtualizer.ts +0 -180
  121. package/packages/intable/src/index.tsx +0 -489
  122. package/packages/intable/src/plugins/CellChangeHighlightPlugin.tsx +0 -5
  123. package/packages/intable/src/plugins/CellMergePlugin.tsx +0 -153
  124. package/packages/intable/src/plugins/CellSelectionPlugin.tsx +0 -175
  125. package/packages/intable/src/plugins/CommandPlugin.tsx +0 -74
  126. package/packages/intable/src/plugins/CopyPastePlugin.tsx +0 -99
  127. package/packages/intable/src/plugins/DiffPlugin.tsx +0 -120
  128. package/packages/intable/src/plugins/DragPlugin.tsx +0 -81
  129. package/packages/intable/src/plugins/EditablePlugin.tsx +0 -252
  130. package/packages/intable/src/plugins/ExpandPlugin.tsx +0 -80
  131. package/packages/intable/src/plugins/HeaderGroup.tsx +0 -289
  132. package/packages/intable/src/plugins/HistoryPlugin.tsx +0 -49
  133. package/packages/intable/src/plugins/MenuPlugin.tsx +0 -195
  134. package/packages/intable/src/plugins/RenderPlugin/components.tsx +0 -51
  135. package/packages/intable/src/plugins/RenderPlugin/index.tsx +0 -81
  136. package/packages/intable/src/plugins/ResizePlugin.tsx +0 -122
  137. package/packages/intable/src/plugins/RowGroupPlugin.tsx +0 -122
  138. package/packages/intable/src/plugins/RowSelectionPlugin.tsx +0 -65
  139. package/packages/intable/src/plugins/TreePlugin.tsx +0 -212
  140. package/packages/intable/src/plugins/VirtualScrollPlugin.tsx +0 -190
  141. package/packages/intable/src/plugins/ZodValidatorPlugin.tsx +0 -61
  142. package/packages/intable/src/style.scss +0 -244
  143. package/packages/intable/src/tree.ts +0 -13
  144. package/packages/intable/src/types/auto-imports.d.ts +0 -13
  145. package/packages/intable/src/utils.ts +0 -122
  146. package/packages/intable/src/wc.tsx +0 -35
  147. package/packages/intable/src/web-component.ts +0 -1
  148. package/packages/react/package.json +0 -36
  149. package/packages/react/src/index.ts +0 -44
  150. package/packages/react/src/plugins/antd.ts +0 -94
  151. package/packages/react/src/style.scss +0 -12
  152. package/packages/react/src/types/auto-imports.d.ts +0 -10
  153. package/packages/vue/package.json +0 -34
  154. package/packages/vue/src/index.ts +0 -63
  155. package/packages/vue/src/plugins/element-plus.ts +0 -69
  156. package/packages/vue/src/style.scss +0 -12
  157. package/packages/vue/src/types/auto-imports.d.ts +0 -10
  158. package/pnpm-workspace.yaml +0 -2
  159. package/public/vite.svg +0 -1
  160. package/scripts/build.js +0 -184
  161. package/scripts/publish.js +0 -95
  162. package/src/assets/ClearFormat.svg +0 -3
  163. package/src/assets/Forms.svg +0 -4
  164. package/src/assets/MergeCell.svg +0 -4
  165. package/src/assets/SplitCell.svg +0 -4
  166. package/src/assets/gap.svg +0 -3
  167. package/src/assets/loading.svg +0 -12
  168. package/src/assets/paint.svg +0 -9
  169. package/src/assets/solid.svg +0 -1
  170. package/src/demo-vue.ts +0 -54
  171. package/src/index.scss +0 -105
  172. package/src/index.tsx +0 -20
  173. package/src/pages/demo/BasicDemo.tsx +0 -19
  174. package/src/pages/demo/CellMergeDemo.tsx +0 -41
  175. package/src/pages/demo/CellSelectionDemo.tsx +0 -24
  176. package/src/pages/demo/CompositeDemo.tsx +0 -60
  177. package/src/pages/demo/CopyPasteDemo.tsx +0 -26
  178. package/src/pages/demo/DiffDemo.tsx +0 -33
  179. package/src/pages/demo/DragDemo.tsx +0 -25
  180. package/src/pages/demo/EditableDemo.tsx +0 -58
  181. package/src/pages/demo/ExpandDemo.tsx +0 -32
  182. package/src/pages/demo/HeaderGroupDemo.tsx +0 -36
  183. package/src/pages/demo/HistoryDemo.tsx +0 -28
  184. package/src/pages/demo/ReactDemo.tsx +0 -59
  185. package/src/pages/demo/ResizeDemo.tsx +0 -24
  186. package/src/pages/demo/RowGroupDemo.tsx +0 -43
  187. package/src/pages/demo/RowSelectionDemo.tsx +0 -27
  188. package/src/pages/demo/TreeDemo.tsx +0 -45
  189. package/src/pages/demo/VirtualScrollDemo.tsx +0 -21
  190. package/src/pages/demo/helpers.tsx +0 -39
  191. package/src/pages/demo/index.tsx +0 -180
  192. package/src/pages/index.tsx +0 -2
  193. package/src/pages/website.scss +0 -37
  194. package/src/pages/website.tsx +0 -651
  195. package/src/styles/index.scss +0 -172
  196. package/src/types/auto-imports.d.ts +0 -13
  197. package/stats.html +0 -4949
  198. package/tsconfig.app.json +0 -34
  199. package/tsconfig.json +0 -7
  200. package/tsconfig.node.json +0 -26
  201. package/vite.config.ts +0 -70
  202. /package/{packages/intable/src → dist}/theme/antd.scss +0 -0
  203. /package/{packages/intable/src → dist}/theme/dark.scss +0 -0
  204. /package/{packages/intable/src → dist}/theme/element-plus.scss +0 -0
  205. /package/{packages/intable/src → dist}/theme/github.scss +0 -0
  206. /package/{packages/intable/src → dist}/theme/material.scss +0 -0
  207. /package/{packages/intable/src → dist}/theme/shadcn.scss +0 -0
  208. /package/{packages/intable/src → dist}/theme/stripe.scss +0 -0
@@ -1,195 +0,0 @@
1
- import { batch, createEffect, createMemo, createSignal, mapArray, on } from 'solid-js'
2
- import { combineProps } from '@solid-primitives/props'
3
- import { createEventListener } from '@solid-primitives/event-listener'
4
- import { delay, range, remove } from 'es-toolkit'
5
- import { autoPlacement, computePosition } from '@floating-ui/dom'
6
- import { type Plugin, type TableStore } from '..'
7
- import { useMemoAsync, useTinykeys } from '../hooks'
8
- import { Menu } from '../components/Menu'
9
- import { tree } from '../utils'
10
-
11
- declare module '../index' {
12
- interface TableProps {
13
-
14
- }
15
- interface TableStore {
16
-
17
- }
18
- interface Plugin {
19
- menus?: (store: TableStore) => any[]
20
- }
21
- interface Commands {
22
- rowEquals: (a, b) => boolean
23
- rowIndexOf: (data: any[], row) => number
24
- rowChange: (row, i?) => void
25
- //
26
- addRows: (i: number, rows: any[], before?: boolean) => void
27
- deleteRows: (i: number[]) => void
28
- moveRows: (ii: number[], to: number) => void
29
- }
30
- }
31
-
32
- export const MenuPlugin: Plugin = {
33
- name: 'menu',
34
- priority: Infinity,
35
- store: (store) => ({
36
-
37
- }),
38
- rewriteProps: {
39
- Table: ({ Table }, { store }) => o => {
40
- const [menuEl, setMenuEl] = createSignal<HTMLElement>()
41
-
42
- const _menus = mapArray(() => store.plugins || [], plugin => createMemo(() => plugin.menus?.(store)))
43
- const menus = createMemo(() => _menus().flatMap(e => e() || []))
44
-
45
- const [pos, setPos] = createSignal<{ x: number; y: number }>()
46
- function onContextMenu(e: PointerEvent) {
47
- e.preventDefault()
48
- setPos({ x: e.x, y: e.y })
49
- }
50
-
51
- createEventListener(document, 'pointerdown', e => {
52
- menuEl()?.contains(e.target as Element) || setPos()
53
- })
54
-
55
- const style = useMemoAsync(() => {
56
- const mel = menuEl()
57
- if (!mel) return
58
- return computePosition({ getBoundingClientRect: () => DOMRect.fromRect(pos()) }, mel, {
59
- strategy: 'fixed',
60
- placement: 'top-start',
61
- middleware: [autoPlacement({ boundary: document.body, alignment: 'start' })]
62
- })
63
- .then(({ x, y }) => ({
64
- position: 'fixed',
65
- transform: `translate(${x}px, ${y}px)`,
66
- top: 0,
67
- left: 0,
68
- 'z-index': 10
69
- }))
70
- })
71
-
72
- o = combineProps({ tabindex: -1, onContextMenu }, o)
73
- return (
74
- <Table {...o}>
75
- {pos() && <Menu ref={setMenuEl} style={style() || 'position: fixed'} items={menus()} onAction={() => setPos()} />}
76
- {o.children}
77
- </Table>
78
- )
79
- },
80
- },
81
- menus: (store) => [
82
- { label: '新增行 ↑', cb: () => store.commands.addRows(store.selected.end[1], [store.props!.newRow(store.selected.end[1])]) },
83
- { label: '新增行 ↓', cb: () => store.commands.addRows(store.selected.end[1], [store.props!.newRow(store.selected.end[1])], false) },
84
- { label: '删除行', cb: () => store.commands.deleteRows(range(...(e => [e[0], e[1] + 1])([store.selected.start[1], store.selected.end[1]].sort((a, b) => a - b)) as [number, number])) },
85
- ],
86
- commands: (store) => ({
87
- rowEquals(a, b) {
88
- // return a[store.props!.rowKey] == b[store.props!.rowKey]
89
- return a == b
90
- },
91
- rowIndexOf(data, row) {
92
- return data.findIndex(e => store.commands.rowEquals(e, row))
93
- },
94
- rowChange(row, i) {
95
- const data = [...store.rawProps.data || []]
96
- i = i != null
97
- ? data.findIndex(ee => ee == store.props!.data[i])
98
- : store.commands.rowIndexOf(data, row)
99
- if (i > -1) {
100
- data[i] = row
101
- store.props!.onDataChange?.(data)
102
- }
103
- },
104
- addRows(i, rows, before = true) {
105
- addRows(store, i, rows, before)
106
- },
107
- deleteRows(ii) {
108
- const { rowKey, data } = store.props!
109
- const val = [...store.rawProps.data || []]
110
- // const ids = new Set(data.filter((e, i) => ii.includes(i)).map(e => e[rowKey]))
111
- // remove(val, e => ids.has(e[rowKey]))
112
- const ids = new Set(ii.map(i => data[i]))
113
- remove(val, e => ids.has(e))
114
- store.props?.onDataChange?.(val)
115
- },
116
- moveRows(ii, to) {
117
- const { data: flatData } = store.props!
118
-
119
- // Collect the actual row objects, skipping internal/system rows
120
- const rows = ii.map(i => flatData[i]).filter(r => r && !r?.[store.internal])
121
- if (!rows.length) return
122
-
123
- // Destination row — undefined means "append to end"
124
- const destRow = to >= 0 && to < flatData.length ? flatData[to] : null
125
-
126
- const { rowKey } = store.props
127
- const childrenField = store.props.tree?.children || Symbol()
128
- const movedKeys = new Set(rows.map((r: any) => r[rowKey]))
129
-
130
- // 1. Remove moved nodes from wherever they live in the nested tree, preserving their original objects (no clone) so children are kept.
131
- const removed: any[] = []
132
- function removeNodes(nodes: any[]): any[] {
133
- return nodes.reduce((acc: any[], node: any) => {
134
- if (movedKeys.has(node[rowKey])) {
135
- removed.push(node)
136
- return acc
137
- }
138
- if (Array.isArray(node[childrenField]) && node[childrenField].length) {
139
- const newChildren = removeNodes(node[childrenField])
140
- node = newChildren.length !== node[childrenField].length
141
- ? { ...node, [childrenField]: newChildren }
142
- : node
143
- }
144
- acc.push(node)
145
- return acc
146
- }, [])
147
- }
148
- const rawData = removeNodes([...(store.rawProps.data || [])])
149
-
150
- // 2. Insert removed nodes just before the destination node in the tree.
151
- const list = tree.findParent(rawData, e => e[rowKey] === destRow?.[rowKey])?.children ?? rawData
152
- const index = destRow ? list.findIndex(e => e[rowKey] === destRow[rowKey]) : -1
153
- if (index > -1) list.splice(index, 0, removed)
154
- else list.push(...removed)
155
-
156
- // 3. Update selection to the new flat position (best-effort: use to - ii.length)
157
- if (store.selected) {
158
- const newIdx = Math.max(0, to - rows.length)
159
- store.selected.start = [0, newIdx]
160
- store.selected.end = [Infinity, newIdx + removed.length - 1]
161
- }
162
-
163
- store.props?.onDataChange?.(rawData)
164
- }
165
- })
166
- }
167
-
168
- function addRows(store: TableStore, i: number, rows: any[], before: boolean) {
169
- const { data } = store.props!
170
- const prev = i => {
171
- before = false
172
- while (--i >= 0 && data[i]?.[store.internal]) { }
173
- return i >= 0 ? data[i] : null
174
- }
175
- const next = i => {
176
- before = true
177
- while (++i < data.length && data[i]?.[store.internal]) { }
178
- return i < data.length ? data[i] : null
179
- }
180
- const anchor = !data[i]?.[store.internal] ? data[i] : before ? prev(i) || next(i) : next(i) || prev(i)
181
- if (anchor) {
182
- batch(() => {
183
- i = store.commands.rowIndexOf(data, anchor)
184
- if (!store.selected) return
185
- store.selected.start = [0, i + (before ? 0 : 1)]
186
- store.selected.end = [Infinity, i + rows.length - 1 + (before ? 0 : 1)]
187
- })
188
- }
189
- ; (() => {
190
- const data = [...store.rawProps.data || []]
191
- const i = anchor ? store.commands.rowIndexOf(data, anchor) + (before ? 0 : 1) : data.length
192
- data.splice(i, 0, ...rows)
193
- store.props?.onDataChange?.(data)
194
- })()
195
- }
@@ -1,51 +0,0 @@
1
- import { For } from 'solid-js'
2
- import { component } from 'undestructure-macros'
3
- import { combineProps } from '@solid-primitives/props'
4
-
5
- export const Checkbox = component(({ value, onChange, ...props }) => {
6
- props = combineProps({ get class() { return `you-checkbox ${value && 'checked'}` } }, props)
7
- return (
8
- <input checked={value || false} onChange={(e) => onChange?.(e.currentTarget.checked)} type="checkbox" {...props} />
9
- )
10
- })
11
-
12
- export const Files = component(({ ...props }) => {
13
- return (
14
- <Tags {...props} />
15
- )
16
- })
17
-
18
- export const Tags = component(({ value, children, disabled, onChange, onAdd, ...props }) => {
19
- props = combineProps({ class: 'flex flex-wrap items-center gap-2 h-full' }, props)
20
- const toarr = v => Array.isArray(v) ? v : (v != null ? [v] : [])
21
- return (
22
- <div {...props}>
23
- <For each={toarr(value)}>{e => (
24
- <Tag style={`background: ${e.color}`} disabled={disabled} onDel={() => onChange(toarr(value).filter(e2 => e2 != e))}>
25
- {children ? children(e) : (e?.text ?? e?.label ?? e?.name ?? e)}
26
- </Tag>
27
- )}</For>
28
- {!disabled && <Tag disabled onClick={onAdd}><ILucidePlus /></Tag>}
29
- </div>
30
- )
31
- })
32
-
33
- export const Tag = component(({ disabled, children, onDel, ...props }) => {
34
- props = combineProps({ class: 'flex items-center px-2 py-1 rd-sm bg-gray/20 text-3.5 lh-[1]' }, props)
35
- return (
36
- <div {...props}>
37
- {children}
38
- {!disabled && <ILucideX class='icon-clickable flex-shrink-0 size-4! ml-1 mr--1 op-75' onClick={onDel} />}
39
- </div>
40
- )
41
- })
42
-
43
- // 评估公式
44
- export const evaluateFormula = (formula: string, data: any) => {
45
- try {
46
- const ctx = { data }
47
- return (new Function(...Object.keys(ctx), `return ` + formula))(...Object.values(ctx))
48
- } catch (error) {
49
- return '公式错误'
50
- }
51
- }
@@ -1,81 +0,0 @@
1
- import { mergeProps, type JSX } from 'solid-js'
2
- import { component } from 'undestructure-macros'
3
- import { type Plugin, type TD } from '../..'
4
- import { Checkbox, Files } from './components'
5
- import { resolveOptions } from '../../utils'
6
- import { renderComponent, solidComponent } from '../../components/utils'
7
-
8
- declare module '../../index' {
9
- interface TableProps {
10
-
11
- }
12
- interface TableColumn {
13
- // render?: string | Render
14
- render?: Render
15
- enum?: Record<string, any> | { label?: string; value: any }[]
16
- }
17
- interface TableStore {
18
- renders: { [key: string]: Render }
19
- }
20
- }
21
-
22
- export type RenderProps = Parameters<TD>[0] & { onChange: (v) => void }
23
- export type Render = (props: RenderProps) => JSX.Element | any
24
-
25
- export const RenderPlugin: Plugin = {
26
- name: 'render',
27
- priority: -Infinity,
28
- store: () => ({
29
- renders: { ...renders }
30
- }),
31
- rewriteProps: {
32
- Td: ({ Td }, { store }) => o => {
33
- return (
34
- <Td {...o}>
35
- {(() => {
36
- let Comp = (e => typeof e == 'string' ? store.renders[e] : e)(o.col.render) || text
37
- return renderComponent(Comp, mergeProps(o, { onChange: v => store.commands.rowChange({ ...o.data, [o.col.id]: v }, o.y) }), store.props!.renderer!)
38
- })()}
39
- </Td>
40
- )
41
- }
42
- }
43
- }
44
-
45
- const text: Render = component(({ data, col, onChange }) => {
46
- return <>{
47
- (v =>
48
- col.enum ? resolveOptions(col.enum).find(e => e.value == v)?.label ?? v : v
49
- )(data[col.id])
50
- }</>
51
- })
52
-
53
- const number = text
54
-
55
- const date = text
56
-
57
- const checkbox: Render = component(({ data, col, onChange }) => {
58
- return (
59
- <div class='flex items-center h-full'>
60
- <Checkbox class='' value={data[col.id]} onChange={onChange} />
61
- </div>
62
- )
63
- })
64
-
65
- const file: Render = component(({ data, col, onChange }) => {
66
- return (
67
- <Files value={data[col.id]} onChange={onChange} disabled />
68
- )
69
- })
70
-
71
- export const renders = {
72
- text,
73
- number,
74
- date,
75
- checkbox,
76
- file
77
- }
78
-
79
- for (const k in renders) {
80
- renders[k] = solidComponent(renders[k])
81
- }
@@ -1,122 +0,0 @@
1
- import { batch, untrack, useContext } from 'solid-js'
2
- import { combineProps } from '@solid-primitives/props'
3
- import { clamp } from 'es-toolkit'
4
- import { defaultsDeep } from 'es-toolkit/compat'
5
- import { usePointerDrag } from '../hooks'
6
-
7
- import { Ctx, type Plugin, type TableColumn, type TDProps, type THProps } from "../index"
8
- import { log, unFn } from '../utils'
9
- import { createEventListener } from '@solid-primitives/event-listener'
10
- import { reconcile } from 'solid-js/store'
11
-
12
- declare module '../index' {
13
- interface TableProps {
14
- resizable?: {
15
- col?: Partial<{ enable: boolean; min: number; max: number }>
16
- row?: Partial<{ enable: boolean; min: number; max: number }>
17
- }
18
- onColumnsChange?: (columns: TableColumn[]) => void
19
- }
20
- interface TableColumn {
21
- resizable?: boolean
22
- onWidthChange?: (width: number) => void
23
- }
24
- interface TableStore {
25
-
26
- }
27
- interface Commands {
28
-
29
- }
30
- }
31
-
32
- const COL = Symbol('col_size')
33
- const ROW = Symbol('row_size')
34
-
35
- const ColHandle = (o: THProps) => {
36
- const { props, store } = useContext(Ctx)
37
- let el!: HTMLDivElement
38
- usePointerDrag(() => el, {
39
- start(e, move, end) {
40
- e.stopPropagation()
41
- const i = o.x
42
- const { min, max } = props.resizable!.col
43
- const th = el.parentElement as HTMLTableColElement
44
- const sw = th.offsetWidth
45
- move((e, { ox }) => store[COL][o.x] = clamp(sw + ox, min, max))
46
- end(() => {
47
- const col = props.columns[i]
48
- const cols = [...store.rawProps.columns || []]
49
- const index = cols.indexOf(col[store.raw] ?? col)
50
- if (index > -1) {
51
- cols[index] = { ...cols[index], width: th.offsetWidth }
52
- props.onColumnsChange?.(cols)
53
- }
54
- col.onWidthChange?.(th.offsetWidth)
55
- })
56
- },
57
- })
58
- return <div ref={el} class={`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`} />
59
- }
60
-
61
- const RowHandle = (o: TDProps) => {
62
- const { props, store } = useContext(Ctx)
63
- let el!: HTMLDivElement
64
- usePointerDrag(() => el, {
65
- start(e, move, end) {
66
- e.stopPropagation()
67
- const i = o.y
68
- const { min, max } = props.resizable!.row
69
- const th = el.parentElement as HTMLTableColElement
70
- const sh = th.offsetHeight
71
- move((e, { oy }) => store[ROW][o.y] = clamp(sh + oy, min, max))
72
- end(() => {
73
- const row = props.data[i]
74
- const data = [...store.rawProps.data || []]
75
- const index = data.indexOf(row[store.raw] ?? row)
76
- if (index > -1) {
77
- // todo
78
- }
79
- })
80
- },
81
- })
82
- createEventListener(() => el, 'dblclick', () => o.data[COL]= void 0)
83
- return <div ref={el} class={`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`} />
84
- }
85
-
86
- export const ResizePlugin: Plugin = {
87
- name: 'resize',
88
- priority: -Infinity,
89
- store: () => ({
90
- [COL]: [],
91
- [ROW]: []
92
- }),
93
- rewriteProps: {
94
- resizable: ({ resizable }) => defaultsDeep(resizable, {
95
- col: { enable: true, min: 45, max: 800 },
96
- row: { enable: false, min: 20, max: 400 }
97
- }),
98
- columns: ({ columns }, { store }) => (
99
- columns = columns.map((e, i) => ({ ...e, [store.raw]: e[store.raw] ?? e })),
100
- columns = columns.map(e => e.resizable === void 0 ? { ...e, resizable: store.props?.resizable?.col.enable, [store.raw]: e[store.raw] ?? e } : e),
101
- columns = columns.map((e, i) => store[COL][i] ? { ...e, width: store[COL][i], [store.raw]: e[store.raw] ?? e } : e),
102
- untrack(() => batch(() => reconcile(columns, { key: store.raw })(store.__resize__cols ??= [])))
103
- ),
104
- Th: ({ Th }, { store }) => o => {
105
- o = combineProps({ class: 'relative' }, o)
106
- return <Th {...o}>
107
- {o.children}
108
- {o.col.resizable && <ColHandle {...o} />}
109
- </Th>
110
- },
111
- Td: ({ Td }, { store }) => !store.props?.resizable?.row.enable ? Td : o => {
112
- o = combineProps({ class: 'relative' }, o)
113
- return <Td {...o}>
114
- {o.children}
115
- {o.x == 0 && store.props?.resizable?.row.enable && <RowHandle {...o} />}
116
- </Td>
117
- },
118
- cellStyle: ({ cellStyle }, { store }) => o => {
119
- return `${unFn(cellStyle, o)};` + (store[ROW][o.y] ? `height: ${store[ROW][o.y]}px` : '')
120
- }
121
- }
122
- }
@@ -1,122 +0,0 @@
1
- import { groupBy, zipObject } from 'es-toolkit'
2
- import { findLast } from 'es-toolkit/compat'
3
- import { Ctx, type Plugin } from '..'
4
- import { batch, createMemo, useContext } from 'solid-js'
5
- import type { TableStore } from '..'
6
-
7
- declare module '../index' {
8
- interface TableProps {
9
- rowGroup?: {
10
- fields?: string[]
11
- }
12
- }
13
- interface TableStore {
14
- rowGroup: {
15
- /** Plain-object map used as Set<string>; property access is tracked by createMutable */
16
- expandKeys: Record<string, true | undefined>
17
- isExpand: (data) => boolean
18
- expand: (data, r?) => void
19
- toggleExpand: (data) => void
20
- }
21
- }
22
- }
23
-
24
- /** Serialize a group path to a plain string key for O(1) Set-style lookup */
25
- const pathKey = (path: any[]): string => path.join('\0')
26
-
27
- export const RowGroupPlugin: Plugin = {
28
- priority: -Infinity,
29
- store: (store) => ({
30
- rowGroup: {
31
- // Plain object acts as a reactive Map<string, true> inside createMutable.
32
- // Property reads are tracked by SolidJS; O(1) vs previous O(n) isEqual scan.
33
- expandKeys: {} as Record<string, true | undefined>,
34
- isExpand: data => !!store.rowGroup.expandKeys[pathKey(data[GROUP].path)],
35
- expand: (data, r) => batch(() =>
36
- r
37
- ? data[GROUP].path2.forEach(e => { store.rowGroup.expandKeys[pathKey(e[GROUP].path)] = true })
38
- : (store.rowGroup.expandKeys[pathKey(data[GROUP].path)] = true)
39
- ),
40
- toggleExpand: data => {
41
- const k = pathKey(data[GROUP].path)
42
- store.rowGroup.expandKeys[k] ? delete store.rowGroup.expandKeys[k] : (store.rowGroup.expandKeys[k] = true)
43
- }
44
- }
45
- }),
46
- commands: (store, { addRows }) => ({
47
- addRows(i, rows, before) {
48
- const { data, rowGroup, rowKey } = store.props!
49
- if (rowGroup?.fields?.length) {
50
- const group = findLast(data, e => e[GROUP], i)
51
- if (group) {
52
- if (data[i][GROUP]) {
53
- const leaf = (function r(group) { return group[GROUP]?.children[0]?.[GROUP] ? r(group[GROUP].children[0]) : group })(group)
54
- store.rowGroup.expand(leaf, true)
55
- const anchor = leaf[GROUP].children[0]
56
- i = store.props!.data.indexOf(anchor)
57
- before = true
58
- }
59
- }
60
- addRows?.(i, rows, before)
61
- } else {
62
- addRows?.(...arguments)
63
- }
64
- },
65
- }),
66
- rewriteProps: {
67
- data: ({ data }, { store }) => (
68
- store.props?.rowGroup?.fields?.length
69
- ? expandData(data, store)
70
- : data
71
- ),
72
- newRow: ({ newRow }, { store }) => function (i) {
73
- const row = newRow(...arguments)
74
- const { data, rowGroup } = store.props!
75
- if (rowGroup?.fields?.length) {
76
- const group = findLast(data, e => e[GROUP], i)
77
- if (group) {
78
- const leaf = (function r(group) { return group[GROUP]?.children[0]?.[GROUP] ? r(group[GROUP].children[0]) : group })(group)
79
- const extra = zipObject(rowGroup!.fields!, leaf[GROUP].path)
80
- Object.assign(row, extra)
81
- }
82
- }
83
- return row
84
- },
85
- Td: ({ Td }, { store }) => o => {
86
- if (!o.data?.[GROUP]) return <Td {...o} />
87
-
88
- const { props } = useContext(Ctx)
89
- const show = createMemo(() => store.rowGroup.isExpand(o.data))
90
-
91
- return (
92
- <Td {...o}>
93
- {props.columns?.findIndex(e => !e[store.internal]) == o.x ? (
94
- <div class='flex items-center' style={`padding-left: ${(o.data[GROUP].path.length - 1) * 16}px`} onDblClick={() => store.rowGroup.toggleExpand(o.data)}>
95
- <ILucideChevronRight class='icon-clickable mr-2' style={`transform: rotate(${show() ? 90 : 0}deg); opacity: .6`} onClick={() => store.rowGroup.toggleExpand(o.data)} />
96
- {o.data[GROUP].value}
97
- </div>
98
- ) : o.children}
99
- </Td>
100
- )
101
- },
102
- },
103
- }
104
-
105
- const GROUP = Symbol('row-group')
106
-
107
- const expandData = (data, store: TableStore, path2 = [] as any[]) => {
108
- const fields = store.props!.rowGroup!.fields!
109
- const col = store.props!.columns.find(e => !e[store.internal])
110
- if (!col) return data
111
- if (fields.length == path2.length) return data
112
- const path = path2[path2.length - 1]?.[GROUP].path || []
113
- const obj = groupBy(data, e => e[fields[path.length]])
114
- return Object.keys(obj).flatMap(k => {
115
- const group = { [col.id]: k, [store.internal]: 1 } as any
116
- const ps = [...path2, group]
117
- group[GROUP] = { path: [...path, k], value: k, path2: ps }
118
- group[GROUP].children = expandData(obj[k], store, ps)
119
- const arr = store.rowGroup.isExpand(group) ? group[GROUP].children : []
120
- return [group, ...arr]
121
- })
122
- }
@@ -1,65 +0,0 @@
1
- import { createEffect, createMemo, createRenderEffect, mergeProps, on } from 'solid-js'
2
- import { createMutable, reconcile } from 'solid-js/store'
3
- import { keyBy } from 'es-toolkit'
4
- import { defaultsDeep, isEqual } from 'es-toolkit/compat'
5
- import { type Commands, type Plugin, type TableColumn, type TableProps } from '..'
6
- import { Checkbox } from './RenderPlugin/components'
7
- import { solidComponent } from '../components/utils'
8
- import { useSelector } from '../hooks/useSelector'
9
-
10
- declare module '../index' {
11
- interface TableProps {
12
- rowSelection?: {
13
- enable?: boolean
14
- multiple?: boolean
15
- value?: any
16
- selectable?: (row) => boolean
17
- onChange?: (selected) => void
18
- }
19
- }
20
- interface TableStore {
21
- rowSelectionCol: TableColumn
22
- }
23
- interface Commands {
24
- rowSelector: ReturnType<typeof useSelector>
25
- }
26
- }
27
-
28
- export const RowSelectionPlugin: Plugin = {
29
- name: 'row-selection',
30
- priority: -Infinity,
31
- store: (store) => ({
32
- rowSelectionCol: {
33
- [store.internal]: 1,
34
- id: Symbol('row-selection'),
35
- fixed: 'left',
36
- class: 'row-selection',
37
- width: 45,
38
- resizable: false,
39
- render: solidComponent((o) => (
40
- <label>
41
- <Checkbox
42
- style='position: absolute'
43
- value={store.commands.rowSelector.has(o.data)}
44
- onChange={v => v ? store.commands.rowSelector.add(o.data) : store.commands.rowSelector.del(o.data)}
45
- disabled={!store.props?.rowSelection?.selectable?.(o.data)}
46
- />
47
- </label>
48
- ))
49
- } as TableColumn,
50
- }),
51
- commands: (store) => ({
52
- rowSelector: useSelector(mergeProps(() => ({ ...store.props?.rowSelection })))
53
- }),
54
- rewriteProps: {
55
- rowSelection: ({ rowSelection }) => defaultsDeep(rowSelection, {
56
- enable: false,
57
- multiple: false,
58
- selectable: () => true,
59
- } as TableProps['rowSelection']),
60
-
61
- columns: ({ columns }, { store }) => store.props?.rowSelection?.enable
62
- ? [store.rowSelectionCol, ...columns]
63
- : columns
64
- }
65
- }