intable 0.0.6 → 0.0.7

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 (169) hide show
  1. package/README.md +16 -263
  2. package/docs/index-BaMALNy6.css +1 -0
  3. package/docs/index-CDN48t9E.js +3 -0
  4. package/docs/index-Cc4RNkLY.css +1 -0
  5. package/docs/index-MRnbkYmU.js +3 -0
  6. package/docs/index.html +15 -0
  7. package/docs/vite.svg +1 -0
  8. package/index.html +14 -0
  9. package/package.json +30 -38
  10. package/packages/intable/README.md +379 -0
  11. package/packages/intable/package.json +51 -0
  12. package/packages/intable/src/assets/ClearFormat.svg +3 -0
  13. package/packages/intable/src/assets/Forms.svg +4 -0
  14. package/packages/intable/src/assets/MergeCell.svg +4 -0
  15. package/packages/intable/src/assets/SplitCell.svg +4 -0
  16. package/packages/intable/src/assets/gap.svg +3 -0
  17. package/packages/intable/src/assets/loading.svg +12 -0
  18. package/packages/intable/src/assets/paint.svg +9 -0
  19. package/packages/intable/src/assets/solid.svg +1 -0
  20. package/packages/intable/src/components/Columns.tsx +86 -0
  21. package/packages/intable/src/components/DocTree.tsx +36 -0
  22. package/packages/intable/src/components/Menu.tsx +109 -0
  23. package/packages/intable/src/components/Popover.tsx +55 -0
  24. package/packages/intable/src/components/RecycleList.tsx +99 -0
  25. package/packages/intable/src/components/Render.tsx +26 -0
  26. package/packages/intable/src/components/Split.tsx +56 -0
  27. package/packages/intable/src/components/Tree.tsx +115 -0
  28. package/packages/intable/src/components/utils.tsx +12 -0
  29. package/packages/intable/src/hooks/index.ts +200 -0
  30. package/packages/intable/src/hooks/useDir.ts +78 -0
  31. package/packages/intable/src/hooks/useSelector.ts +91 -0
  32. package/packages/intable/src/hooks/useSort.tsx +118 -0
  33. package/packages/intable/src/hooks/useVirtualizer.ts +180 -0
  34. package/packages/intable/src/index.tsx +481 -0
  35. package/packages/intable/src/plugins/CellChangeHighlightPlugin.tsx +5 -0
  36. package/packages/intable/src/plugins/CellMergePlugin.tsx +153 -0
  37. package/packages/intable/src/plugins/CellSelectionPlugin.tsx +175 -0
  38. package/packages/intable/src/plugins/CommandPlugin.tsx +74 -0
  39. package/packages/intable/src/plugins/CopyPastePlugin.tsx +63 -0
  40. package/packages/intable/src/plugins/DiffPlugin.tsx +107 -0
  41. package/packages/intable/src/plugins/DragPlugin.tsx +81 -0
  42. package/packages/intable/src/plugins/EditablePlugin.tsx +252 -0
  43. package/packages/intable/src/plugins/ExpandPlugin.tsx +80 -0
  44. package/packages/intable/src/plugins/HeaderGroup.tsx +289 -0
  45. package/packages/intable/src/plugins/HistoryPlugin.tsx +49 -0
  46. package/packages/intable/src/plugins/MenuPlugin.tsx +195 -0
  47. package/packages/intable/src/plugins/RenderPlugin/components.tsx +51 -0
  48. package/packages/intable/src/plugins/RenderPlugin/index.tsx +81 -0
  49. package/packages/intable/src/plugins/ResizePlugin.tsx +122 -0
  50. package/packages/intable/src/plugins/RowGroupPlugin.tsx +122 -0
  51. package/packages/intable/src/plugins/RowSelectionPlugin.tsx +65 -0
  52. package/packages/intable/src/plugins/TreePlugin.tsx +212 -0
  53. package/packages/intable/src/plugins/VirtualScrollPlugin.tsx +190 -0
  54. package/packages/intable/src/plugins/ZodValidatorPlugin.tsx +61 -0
  55. package/packages/intable/src/style.scss +244 -0
  56. package/{dist → packages/intable/src}/theme/antd.scss +14 -5
  57. package/{dist → packages/intable/src}/theme/element-plus.scss +6 -5
  58. package/packages/intable/src/tree.ts +13 -0
  59. package/packages/intable/src/types/auto-imports.d.ts +13 -0
  60. package/packages/intable/src/utils.ts +122 -0
  61. package/packages/intable/src/wc.tsx +35 -0
  62. package/packages/intable/src/web-component.ts +1 -0
  63. package/packages/react/package.json +31 -0
  64. package/packages/react/src/index.ts +44 -0
  65. package/packages/react/src/plugins/antd.ts +94 -0
  66. package/packages/react/src/style.scss +12 -0
  67. package/packages/react/src/types/auto-imports.d.ts +10 -0
  68. package/packages/vue/package.json +34 -0
  69. package/packages/vue/src/index.ts +63 -0
  70. package/packages/vue/src/plugins/element-plus.ts +69 -0
  71. package/packages/vue/src/style.scss +12 -0
  72. package/packages/vue/src/types/auto-imports.d.ts +10 -0
  73. package/pnpm-workspace.yaml +2 -0
  74. package/public/vite.svg +1 -0
  75. package/scripts/build.js +184 -0
  76. package/scripts/publish.js +95 -0
  77. package/src/assets/ClearFormat.svg +3 -0
  78. package/src/assets/Forms.svg +4 -0
  79. package/src/assets/MergeCell.svg +4 -0
  80. package/src/assets/SplitCell.svg +4 -0
  81. package/src/assets/gap.svg +3 -0
  82. package/src/assets/loading.svg +12 -0
  83. package/src/assets/paint.svg +9 -0
  84. package/src/assets/solid.svg +1 -0
  85. package/src/demo-vue.ts +54 -0
  86. package/src/demo.tsx +107 -0
  87. package/src/index.scss +105 -0
  88. package/src/styles/index.scss +172 -0
  89. package/src/types/auto-imports.d.ts +13 -0
  90. package/stats.html +4949 -0
  91. package/tsconfig.app.json +34 -0
  92. package/tsconfig.json +7 -0
  93. package/tsconfig.node.json +26 -0
  94. package/vite.config.ts +63 -0
  95. package/dist/__uno.css +0 -1
  96. package/dist/chevron-right.js +0 -6
  97. package/dist/components/Columns.d.ts +0 -3
  98. package/dist/components/Columns.js +0 -71
  99. package/dist/components/DocTree.d.ts +0 -4
  100. package/dist/components/DocTree.js +0 -32
  101. package/dist/components/Menu.d.ts +0 -1
  102. package/dist/components/Menu.js +0 -107
  103. package/dist/components/Popover.d.ts +0 -14
  104. package/dist/components/Popover.js +0 -41
  105. package/dist/components/Render.d.ts +0 -4
  106. package/dist/components/Render.js +0 -20
  107. package/dist/components/Split.d.ts +0 -15
  108. package/dist/components/Split.js +0 -76
  109. package/dist/components/Tree.d.ts +0 -37
  110. package/dist/components/Tree.js +0 -82
  111. package/dist/components/utils.d.ts +0 -3
  112. package/dist/components/utils.js +0 -8
  113. package/dist/hooks/index.d.ts +0 -40
  114. package/dist/hooks/index.js +0 -157
  115. package/dist/hooks/useDir.d.ts +0 -11
  116. package/dist/hooks/useDir.js +0 -42
  117. package/dist/hooks/useSelector.d.ts +0 -16
  118. package/dist/hooks/useSelector.js +0 -35
  119. package/dist/hooks/useSort.d.ts +0 -18
  120. package/dist/hooks/useSort.js +0 -83
  121. package/dist/hooks/useVirtualizer.d.ts +0 -25
  122. package/dist/hooks/useVirtualizer.js +0 -67
  123. package/dist/index.d.ts +0 -130
  124. package/dist/index.js +0 -347
  125. package/dist/loading.js +0 -6
  126. package/dist/plugins/CellChangeHighlightPlugin.d.ts +0 -2
  127. package/dist/plugins/CellChangeHighlightPlugin.js +0 -4
  128. package/dist/plugins/CellMergePlugin.d.ts +0 -12
  129. package/dist/plugins/CellMergePlugin.js +0 -2
  130. package/dist/plugins/CellSelectionPlugin.d.ts +0 -15
  131. package/dist/plugins/CellSelectionPlugin.js +0 -115
  132. package/dist/plugins/CommandPlugin.d.ts +0 -14
  133. package/dist/plugins/CommandPlugin.js +0 -12
  134. package/dist/plugins/CopyPastePlugin.d.ts +0 -14
  135. package/dist/plugins/CopyPastePlugin.js +0 -42
  136. package/dist/plugins/DiffPlugin.d.ts +0 -23
  137. package/dist/plugins/DiffPlugin.js +0 -56
  138. package/dist/plugins/DragPlugin.d.ts +0 -14
  139. package/dist/plugins/DragPlugin.js +0 -47
  140. package/dist/plugins/EditablePlugin.d.ts +0 -48
  141. package/dist/plugins/EditablePlugin.js +0 -141
  142. package/dist/plugins/ExpandPlugin.d.ts +0 -18
  143. package/dist/plugins/ExpandPlugin.js +0 -50
  144. package/dist/plugins/HistoryPlugin.d.ts +0 -10
  145. package/dist/plugins/HistoryPlugin.js +0 -30
  146. package/dist/plugins/MenuPlugin.d.ts +0 -18
  147. package/dist/plugins/MenuPlugin.js +0 -107
  148. package/dist/plugins/RenderPlugin/components.d.ts +0 -5
  149. package/dist/plugins/RenderPlugin/components.js +0 -87
  150. package/dist/plugins/RenderPlugin/index.d.ts +0 -30
  151. package/dist/plugins/RenderPlugin/index.js +0 -49
  152. package/dist/plugins/ResizePlugin.d.ts +0 -27
  153. package/dist/plugins/ResizePlugin.js +0 -81
  154. package/dist/plugins/RowGroupPlugin.d.ts +0 -17
  155. package/dist/plugins/RowGroupPlugin.js +0 -83
  156. package/dist/plugins/RowSelectionPlugin.d.ts +0 -20
  157. package/dist/plugins/RowSelectionPlugin.js +0 -42
  158. package/dist/plugins/VirtualScrollPlugin.d.ts +0 -15
  159. package/dist/plugins/VirtualScrollPlugin.js +0 -96
  160. package/dist/plus.js +0 -6
  161. package/dist/style.css +0 -3
  162. package/dist/types/auto-imports.d.js +0 -0
  163. package/dist/utils.d.ts +0 -30
  164. package/dist/utils.js +0 -70
  165. package/dist/wc.d.ts +0 -1
  166. package/dist/wc.js +0 -21
  167. package/dist/web-component.d.ts +0 -1
  168. package/dist/web-component.js +0 -2
  169. package/dist/x.js +0 -6
@@ -9,17 +9,25 @@
9
9
 
10
10
  --table-row-hover-bg: var(--ant-table-row-hover-bg, #fafafa);
11
11
 
12
- @apply text-[14px];
12
+ font-size: 14px;
13
13
 
14
14
  &:not(&--border) thead th {
15
- @apply relative;
15
+ position: relative;
16
16
  &:not(:last-child)::before {
17
- @apply content-[''] absolute top-1/2 right-0 h-[1.6em] w-[1px] bg-[--table-b-c] translate-y-[-50%];
17
+ content: '';
18
+ position: absolute;
19
+ top: 50%;
20
+ right: 0;
21
+ height: 1.6em;
22
+ width: 1px;
23
+ background-color: var(--table-b-c);
24
+ transform: translateY(-50%);
18
25
  }
19
26
  }
20
27
 
21
28
  th, td {
22
- @apply px-2 py-3 lh-[22px];
29
+ padding: 12px 8px;
30
+ line-height: 22px;
23
31
  }
24
32
 
25
33
  .row-selection {
@@ -28,7 +36,8 @@
28
36
 
29
37
  &--small {
30
38
  th, td {
31
- @apply px-2;
39
+ padding-left: 8px;
40
+ padding-right: 8px;
32
41
  }
33
42
  }
34
43
  }
@@ -14,14 +14,15 @@
14
14
 
15
15
  --table-row-hover-bg: var(--el-table-row-hover-bg-color, #f5f7fa);
16
16
 
17
- @apply lh-[23px] text-[14px];
17
+ line-height: 23px;
18
+ font-size: 14px;
18
19
 
19
20
  thead th {
20
- @apply font-600;
21
+ font-weight: 600;
21
22
  }
22
23
 
23
24
  th, td {
24
- @apply px-3 py-2;
25
+ padding: 8px 12px;
25
26
  }
26
27
 
27
28
  .row-selection {
@@ -29,10 +30,10 @@
29
30
  }
30
31
 
31
32
  &--small {
32
- @apply text-3;
33
+ font-size: 12px;
33
34
 
34
35
  th, td {
35
- @apply px-2 py-1;
36
+ padding: 4px 8px;
36
37
  }
37
38
  }
38
39
  }
@@ -0,0 +1,13 @@
1
+ export const findParent = (data: any[], cb, childrenField = 'children'): any => {
2
+ let parent = null
3
+ const stack = [...data]
4
+ while (stack.length) {
5
+ const node = stack.pop()
6
+ if (cb(node)) return parent
7
+ if (Array.isArray(node[childrenField])) {
8
+ stack.push(...node[childrenField])
9
+ parent = node
10
+ }
11
+ }
12
+ return null
13
+ }
@@ -0,0 +1,13 @@
1
+ /* eslint-disable */
2
+ /* prettier-ignore */
3
+ // @ts-nocheck
4
+ // noinspection JSUnusedGlobalSymbols
5
+ // Generated by unplugin-auto-import
6
+ // biome-ignore lint: disable
7
+ export {}
8
+ declare global {
9
+ const ILucideChevronRight: typeof import('~icons/lucide/chevron-right.jsx')['default']
10
+ const ILucidePlus: typeof import('~icons/lucide/plus.jsx')['default']
11
+ const ILucideX: typeof import('~icons/lucide/x.jsx')['default']
12
+ const IMyLoading: typeof import('~icons/my/loading.jsx')['default']
13
+ }
@@ -0,0 +1,122 @@
1
+ import { delay, isFunction, isPlainObject, isPromise } from "es-toolkit"
2
+ import { useMemoAsync } from "./hooks"
3
+
4
+ export * as tree from './tree'
5
+
6
+ export function file2base64(file: File) {
7
+ return new Promise<string>((resolve, reject) => {
8
+ const reader = new FileReader()
9
+ reader.readAsDataURL(file)
10
+ reader.onload = () => resolve(reader.result as string)
11
+ })
12
+ }
13
+
14
+ export function chooseFile(opts: { accept?: string; multiple?: false }): Promise<File>
15
+ export function chooseFile(opts: { accept?: string; multiple: true }): Promise<File[]>
16
+
17
+ export function chooseFile(opts?) {
18
+ return new Promise((resolve, reject) => {
19
+ const input = document.createElement('input')
20
+ input.type = 'file'
21
+ input.accept = opts?.accept
22
+ input.multiple = opts?.multiple
23
+ input.onchange = () => {
24
+ if (input.files && input.files.length > 0) {
25
+ resolve(input.multiple ? [...input.files] : input.files[0])
26
+ } else {}
27
+ }
28
+ input.oncancel = reject
29
+ input.click()
30
+ })
31
+ }
32
+
33
+ export function chooseImage() {
34
+ return chooseFile({ accept: 'image/*' })
35
+ }
36
+
37
+ // export async function html2docx(content: string) {
38
+ // const { inline, initWasm } = await import('@css-inline/css-inline-wasm')
39
+ // const wasm = fetch(await import('@css-inline/css-inline-wasm/index_bg.wasm?url').then((e) => e.default))
40
+ // await initWasm(wasm).catch(() => {})
41
+
42
+ // content = inline(content + getStyles())
43
+ // const blob = await import('html-docx-js-typescript').then((e) => e.asBlob(content))
44
+ // return blob as Blob
45
+ // }
46
+
47
+ export async function print(html: string) {
48
+ const iframe = document.createElement('iframe')
49
+ const styles = [...document.querySelectorAll('style'), ...document.querySelectorAll('link[rel="stylesheet"]')] as HTMLElement[]
50
+ iframe.srcdoc = `${styles.map(e => e.outerHTML).join('\n')}\n\n${html}`
51
+ Object.assign(iframe.style, { position: 'fixed', display: 'none' })
52
+ document.body.append(iframe)
53
+ await new Promise(resolve => iframe.contentWindow.addEventListener('load', resolve, { once: true }))
54
+ await delay(300)
55
+ iframe.contentWindow.print()
56
+ iframe.remove()
57
+ }
58
+
59
+ export function mergeRect(rect1: DOMRect, rect2: DOMRect) {
60
+ return DOMRect.fromRect({
61
+ x: Math.min(rect1.x, rect2.x),
62
+ y: Math.min(rect1.y, rect2.y),
63
+ width: Math.max(rect1.right, rect2.right) - Math.min(rect1.x, rect2.x),
64
+ height: Math.max(rect1.bottom, rect2.bottom) - Math.min(rect1.y, rect2.y),
65
+ })
66
+ }
67
+
68
+ export function getStyles(el = document as ParentNode) {
69
+ return [...el.querySelectorAll('style'), ...el.querySelectorAll('link[rel="stylesheet"]')].map(e => e.outerHTML).join('\n')
70
+ }
71
+
72
+ export const unFn = (fn, ...args) => typeof fn == 'function' ? fn(...args) : fn
73
+
74
+ export const log = (...args) => (console.log(...args), args[0])
75
+
76
+ export const toArr = v => Array.isArray(v) ? v : v != null ? [v] : []
77
+
78
+ export const parseStyle = s => s ? s.split(';').reduce((o, e) => ((([k, v]) => o[k.trim()] = v.trim())(e.split(':')), o), {}) : {}
79
+
80
+ export function findret<T, R>(arr: readonly T[], cb: (e: T, i: number) => R): R | undefined {
81
+ for (let i = 0; i < arr.length; i++) {
82
+ const ret = cb(arr[i], i)
83
+ if (ret != null) return ret
84
+ }
85
+ }
86
+
87
+ export function emptyObject(o) {
88
+ for (const k of Object.keys(o)) delete o[k]
89
+ return o
90
+ }
91
+
92
+ export async function findAsync<T>(arr: T[], cb: (e: T, i: number) => Promise<boolean> | boolean) {
93
+ for (let i = 0; i < arr.length; i++) {
94
+ if (await cb(arr[i], i)) return arr[i]
95
+ }
96
+ }
97
+
98
+ type Fnable<T> = T | (() => T)
99
+ type Awatable<T> = T | Promise<T>
100
+ type BaseType = string | number | boolean | null
101
+
102
+ const cache = new WeakMap
103
+
104
+ export function resolveOptions(opts: Fnable<Awatable<Record<string, any> | ({ label: any; value: any } | BaseType)[]>>): { label: any; value: any }[] {
105
+ let ret = opts
106
+ if (isFunction(ret)) ret = ret()
107
+ if (isPromise(ret)) {
108
+ if (cache.has(ret)) return cache.get(ret)()
109
+ cache.set(ret, useMemoAsync(() => ret.then(e => e.map(e => resolveOptions(e)))))
110
+ return cache.get(ret)()
111
+ }
112
+ if (isPlainObject(ret)) ret = Object.entries(ret).map(([k, v]) => ({ value: k, label: v, ...v }))
113
+ return (ret as any[])?.map(e => resolveOpt(e)) || []
114
+ }
115
+
116
+ function resolveOpt(opt) {
117
+ return (
118
+ isPlainObject(opt) ? opt :
119
+ Array.isArray(opt) ? { label: opt[0], value: opt[1] } :
120
+ { label: opt, value: opt }
121
+ )
122
+ }
@@ -0,0 +1,35 @@
1
+ /* @refresh reload */
2
+ import { batch, createEffect, createMemo, createSignal, untrack } from 'solid-js'
3
+ import { customElement, noShadowDOM } from 'solid-element'
4
+ import { createMutable } from 'solid-js/store'
5
+ import { Intable } from './'
6
+ import { useMemoState } from './hooks'
7
+
8
+ const PROPS = {
9
+ options: {},
10
+ css: { value: '', attribute: 'css', notify: true, reflect: false },
11
+ theme: '',
12
+ noShadow: true,
13
+ }
14
+
15
+ export const TableElement = customElement('wc-table', PROPS, (attrs, { element }) => {
16
+ attrs.noShadow && noShadowDOM()
17
+
18
+ const props = useMemoState(() => attrs.options)
19
+
20
+ return (
21
+ <Intable {...props} />
22
+ )
23
+ })
24
+
25
+ function memoAsync(fn) {
26
+ const ret = createSignal('')
27
+ let count = 0
28
+ createEffect(async () => {
29
+ const _count = ++count
30
+ let val = fn()
31
+ if (val instanceof Promise) val = await val
32
+ if (_count == count) ret[1](val)
33
+ })
34
+ return ret[0]
35
+ }
@@ -0,0 +1 @@
1
+ export * from './wc'
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@intable/react",
3
+ "version": "0.0.7",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./style.scss": "./dist/style.scss"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "intable": "workspace:^",
20
+ "solid-js": "^1.9.9"
21
+ },
22
+ "peerDependencies": {
23
+ "react": "^18 | ^19 | ^20",
24
+ "react-dom": "^18 | ^19 | ^20"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^18",
28
+ "@types/react-dom": "^18",
29
+ "antd": "^5.22.5"
30
+ }
31
+ }
@@ -0,0 +1,44 @@
1
+ import { useEffect, useRef, createElement as h, type FC } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { flushSync } from 'react-dom'
4
+ import { type TableProps } from 'intable'
5
+ import 'intable/wc'
6
+ // import './style.scss'
7
+
8
+ import { onCleanup } from 'solid-js'
9
+
10
+
11
+ export const Intable: FC<TableProps> = (props) => {
12
+ const ref = useRef<any>(null)
13
+
14
+ useEffect(() => {
15
+ if (ref.current) {
16
+ ref.current.options = {
17
+ ...props,
18
+ renderer: component,
19
+ plugins: [
20
+ ...(props.plugins || [])
21
+ ],
22
+ } as TableProps
23
+ }
24
+ }, [props])
25
+
26
+ return h('wc-table', { ref, style: { display: 'contents' } })
27
+ }
28
+
29
+
30
+ export const component = <T extends Record<string, any>>(Comp: FC<T>) => {
31
+ return (props: T) => {
32
+ // const el = document.createDocumentFragment()
33
+ const el = document.createElement('div')
34
+ el.remove ??= () => {}
35
+
36
+ const root = createRoot(el)
37
+ flushSync(() => root.render(h(Comp, props)))
38
+ onCleanup(() => root.unmount())
39
+
40
+ return el
41
+ }
42
+ }
43
+
44
+ export default Intable
@@ -0,0 +1,94 @@
1
+ import type { Plugin } from 'intable'
2
+ import type { Editor } from 'intable/plugins/EditablePlugin'
3
+ import { resolveOptions } from 'intable/utils'
4
+
5
+ import { Checkbox, ColorPicker, DatePicker, Input, InputNumber, Rate, Select, Switch, TimePicker } from 'antd'
6
+ import { useEffect, useRef, useState, createElement as h, type FC } from 'react'
7
+ import { createRoot } from 'react-dom/client'
8
+
9
+ export const AntdPlugin: Plugin = {
10
+ name: 'antd',
11
+ store(store) {
12
+ store.editors.text = editor(Input)
13
+ store.editors.number = editor(InputNumber)
14
+ store.editors.rate = editor(Rate)
15
+ store.editors.switch = editor(Switch)
16
+ store.editors.checkbox = editor(Checkbox)
17
+ store.editors.color = selector(ColorPicker, { transform: v => v?.toHexString?.() || v })
18
+ store.editors.select = selector(Select)
19
+ store.editors.date = selector(DatePicker)
20
+ store.editors.time = selector(TimePicker)
21
+ store.editors.datetime = selector(DatePicker, { showTime: true })
22
+ },
23
+ rewriteProps: {
24
+ class: ({ class: clazz }) => `antd ${clazz}`
25
+ }
26
+ }
27
+
28
+ const getEl = (el: any) => {
29
+ if (!el) return el
30
+ if (el instanceof Text) el = el.nextElementSibling
31
+ return el?.querySelector('input') ?? el?.querySelector('button') ?? el?.querySelector('[class*=trigger]') ?? el
32
+ }
33
+
34
+ const createEditor = (Comp: FC<any>, opts: any, isSelector?: boolean): Editor => (editorOpts) => {
35
+ const { eventKey, value, col, ok, cancel, props } = editorOpts
36
+ const container = document.createElement('div')
37
+ const root = createRoot(container)
38
+
39
+ let currentValue = eventKey || value
40
+ let elRef: any
41
+
42
+ const EditorComp = () => {
43
+ const [val, setVal] = useState(currentValue)
44
+ const ref = useRef<any>(null)
45
+
46
+ useEffect(() => {
47
+ elRef = ref.current
48
+ if (isSelector) {
49
+ setTimeout(() => (getEl(ref.current)?.click?.(), ref.current?.focus?.()), 0)
50
+ } else {
51
+ ref.current?.focus?.()
52
+ }
53
+ }, [])
54
+
55
+ const handleChange = (newVal: any) => {
56
+ currentValue = opts.transform ? opts.transform(newVal) : newVal
57
+ setVal(currentValue)
58
+ isSelector && setTimeout(ok, 100)
59
+ }
60
+
61
+ const handleKeyDown = (e: any) => {
62
+ e.stopPropagation()
63
+ if (e.key === 'Enter') ok()
64
+ if (e.key === 'Escape') cancel()
65
+ }
66
+
67
+ return h(Comp, {
68
+ ref,
69
+ value: val,
70
+ onChange: handleChange,
71
+ onPointerDown: (e: any) => e.stopPropagation(),
72
+ onKeyDown: handleKeyDown,
73
+ ...(col?.enum && { options: resolveOptions(col.enum) }),
74
+ ...opts,
75
+ ...props,
76
+ })
77
+ }
78
+
79
+ root.render(h(EditorComp))
80
+
81
+ const fragment = document.createDocumentFragment()
82
+ fragment.appendChild(container)
83
+
84
+ return {
85
+ el: fragment,
86
+ getValue: () => currentValue,
87
+ destroy: () => root.unmount(),
88
+ focus: () => (isSelector && getEl(elRef)?.click?.(), elRef?.focus?.()),
89
+ blur: () => elRef?.blur?.(),
90
+ }
91
+ }
92
+
93
+ const editor = (Comp: FC<any>, opts = {}) => createEditor(Comp, opts, false)
94
+ const selector = (Comp: FC<any>, opts = {}) => createEditor(Comp, opts, true)
@@ -0,0 +1,12 @@
1
+ .antd {
2
+ .is-editing {
3
+ & > .area { @apply hidden; }
4
+ }
5
+ .in-cell-edit-wrapper {
6
+ @apply flex items-center p-1;
7
+
8
+ > .ant-input-affix-wrapper > .ant-input-prefix {
9
+ @apply hidden;
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ /* eslint-disable */
2
+ /* prettier-ignore */
3
+ // @ts-nocheck
4
+ // noinspection JSUnusedGlobalSymbols
5
+ // Generated by unplugin-auto-import
6
+ // biome-ignore lint: disable
7
+ export {}
8
+ declare global {
9
+
10
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@intable/vue",
3
+ "version": "0.0.7",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./*": {
12
+ "import": "./dist/*.js",
13
+ "types": "./dist/*.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@vue/shared": "^3.5.27",
21
+ "intable": "workspace:^",
22
+ "solid-js": "^1.9.9"
23
+ },
24
+ "peerDependencies": {
25
+ "vue": "^3"
26
+ },
27
+ "devDependencies": {
28
+ "element-plus": "^2.13.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org/"
33
+ }
34
+ }
@@ -0,0 +1,63 @@
1
+ import { onCleanup, createRenderEffect } from 'solid-js'
2
+ import { type Plugin, type TableProps } from 'intable'
3
+ import 'intable/wc'
4
+ import './style.scss'
5
+
6
+ // import '../../intable/src/wc'
7
+
8
+ export type { TableProps } from 'intable'
9
+
10
+ import { h, normalizeClass, toRaw, render, type Component, type FunctionalComponent, type App } from 'vue'
11
+ import { stringifyStyle } from '@vue/shared'
12
+ import { mapValues } from 'es-toolkit'
13
+
14
+ export const Intable: FunctionalComponent<TableProps> = ((props) => (
15
+ props = mapValues(props, v => toRaw(v)),
16
+ h('wc-table', {
17
+ style: 'display: contents',
18
+ '.options': {
19
+ ...props,
20
+ class: normalizeClass(props.class),
21
+ style: stringifyStyle(props.style),
22
+ renderer: component,
23
+ plugins: [
24
+ VModelPlugin,
25
+ ...props.plugins || []
26
+ ]
27
+ } as TableProps
28
+ })
29
+ ))
30
+
31
+ Intable.inheritAttrs = false
32
+ Intable.__name = 'intable'
33
+ Intable.install = app => app.component(Intable.__name, Intable)
34
+
35
+ const VModelPlugin: Plugin = {
36
+ name: 'v-model',
37
+ rewriteProps: {
38
+ rowSelection: ({ rowSelection }, { store }) => ({
39
+ get value() { return store.props?.selected },
40
+ ...rowSelection,
41
+ onChange(selected) {
42
+ store.props!['onUpdate:selected']?.(selected)
43
+ rowSelection?.onChange?.(...arguments)
44
+ },
45
+ }),
46
+ onDataChange: ({ onDataChange }, { store }) => (data) => {
47
+ store.props!['onUpdate:data']?.(data)
48
+ onDataChange?.(data)
49
+ }
50
+ }
51
+ }
52
+
53
+ const component = <T extends Record<string, any>>(Comp: Component<T>) => {
54
+ return (props: T) => {
55
+ const root = document.createDocumentFragment()
56
+ root.remove ??= () => {}
57
+ createRenderEffect(() => render(h(Comp, { ...props }), root))
58
+ onCleanup(() => render(null, root))
59
+ return root
60
+ }
61
+ }
62
+
63
+ export default Intable
@@ -0,0 +1,69 @@
1
+ import type { Plugin } from 'intable'
2
+ import type { Editor } from 'intable/plugins/EditablePlugin'
3
+ import { resolveOptions } from 'intable/utils'
4
+
5
+ import { ElCheckbox, ElColorPicker, ElDatePicker, ElInput, ElInputNumber, ElRate, ElSelect, ElSwitch, ElTimePicker } from 'element-plus'
6
+ import { type Component, h, mergeProps, ref, render } from 'vue'
7
+
8
+ export const ElementPlusPlugin: Plugin = {
9
+ store(store) {
10
+ store.editors.text = createEditor(ElInput)
11
+ store.editors.number = createEditor(ElInputNumber)
12
+ store.editors.rate = createEditor(ElRate)
13
+ store.editors.switch = createEditor(ElSwitch)
14
+ store.editors.checkbox = createEditor(ElCheckbox)
15
+ store.editors.color = createEditor(ElColorPicker, {}, true)
16
+ store.editors.select = createEditor(ElSelect, {}, true)
17
+ store.editors.date = createEditor(ElDatePicker, { valueFormat: 'YYYY-MM-DD' }, true)
18
+ store.editors.time = createEditor(ElTimePicker, {}, true)
19
+ store.editors.datetime = createEditor(ElDatePicker, { type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm:ss' }, true)
20
+ },
21
+ rewriteProps: {
22
+ class: ({ class: clazz }) => `element-plus ${clazz}`
23
+ }
24
+ }
25
+
26
+ const getElement = (el: any) => {
27
+ if (!el) return el
28
+ if (el instanceof Text) el = el.nextElementSibling
29
+ return el.querySelector('input') ?? el.querySelector('button') ?? el.querySelector('[class*=__trigger]') ?? el
30
+ }
31
+
32
+ const createEditor = (Comp: Component, extra?, isSelector?): Editor => {
33
+ return ({ eventKey, value, col, ok, cancel, props }) => {
34
+ const v = ref(isSelector ? value : (eventKey || value))
35
+ const elref = ref()
36
+ const root = document.createDocumentFragment()
37
+ root.remove ??= () => {}
38
+
39
+ const App = () => h(Comp, mergeProps(extra, props, {
40
+ ref: elref,
41
+ modelValue: v.value,
42
+ 'onUpdate:modelValue': (val) => v.value = val,
43
+ onPointerdown: (e: Event) => e.stopPropagation(),
44
+ onMousedown: (e: Event) => e.stopPropagation(),
45
+ onKeydown: (e: KeyboardEvent) => {
46
+ e.stopPropagation()
47
+ if (e.key === 'Enter') ok()
48
+ if (e.key === 'Escape') cancel()
49
+ },
50
+ ...isSelector ? {
51
+ onChange: () => ok(),
52
+ options: resolveOptions(col.enum ?? []),
53
+ } : {}
54
+ }))
55
+
56
+ render(h(App), root)
57
+
58
+ return {
59
+ el: root,
60
+ getValue: () => v.value,
61
+ destroy: () => render(null, root),
62
+ focus: () => {
63
+ if (isSelector) getElement(elref.value?.$el)?.click()
64
+ elref.value?.focus?.()
65
+ },
66
+ blur: () => elref.value?.blur?.(),
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,12 @@
1
+ .element-plus {
2
+ .is-editing {
3
+ & > .area { @apply hidden; }
4
+ }
5
+ .in-cell-edit-wrapper {
6
+ @apply flex items-center p-1;
7
+
8
+ > .el-input > .el-input__wrapper > .el-input__prefix {
9
+ @apply hidden;
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ /* eslint-disable */
2
+ /* prettier-ignore */
3
+ // @ts-nocheck
4
+ // noinspection JSUnusedGlobalSymbols
5
+ // Generated by unplugin-auto-import
6
+ // biome-ignore lint: disable
7
+ export {}
8
+ declare global {
9
+
10
+ }
@@ -0,0 +1,2 @@
1
+ packages:
2
+ - 'packages/*'
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>