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.
- package/README.md +263 -16
- package/dist/__uno.css +1 -0
- package/dist/chevron-right.js +6 -0
- package/dist/components/Columns.d.ts +3 -0
- package/dist/components/Columns.js +71 -0
- package/dist/components/DocTree.d.ts +4 -0
- package/dist/components/DocTree.js +32 -0
- package/dist/components/Menu.d.ts +1 -0
- package/dist/components/Menu.js +107 -0
- package/dist/components/Popover.d.ts +14 -0
- package/dist/components/Popover.js +41 -0
- package/dist/components/RecycleList.d.ts +26 -0
- package/dist/components/RecycleList.js +39 -0
- package/dist/components/Render.d.ts +4 -0
- package/dist/components/Render.js +20 -0
- package/dist/components/Split.d.ts +15 -0
- package/dist/components/Split.js +76 -0
- package/dist/components/Tree.d.ts +37 -0
- package/dist/components/Tree.js +82 -0
- package/dist/components/utils.d.ts +3 -0
- package/dist/components/utils.js +8 -0
- package/dist/hooks/index.d.ts +40 -0
- package/dist/hooks/index.js +157 -0
- package/dist/hooks/useDir.d.ts +11 -0
- package/dist/hooks/useDir.js +42 -0
- package/dist/hooks/useSelector.d.ts +16 -0
- package/dist/hooks/useSelector.js +69 -0
- package/dist/hooks/useSort.d.ts +18 -0
- package/dist/hooks/useSort.js +83 -0
- package/dist/hooks/useVirtualizer.d.ts +30 -0
- package/dist/hooks/useVirtualizer.js +97 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +386 -0
- package/dist/loading.js +6 -0
- package/dist/plugins/CellChangeHighlightPlugin.d.ts +2 -0
- package/dist/plugins/CellChangeHighlightPlugin.js +4 -0
- package/dist/plugins/CellMergePlugin.d.ts +45 -0
- package/dist/plugins/CellMergePlugin.js +78 -0
- package/dist/plugins/CellSelectionPlugin.d.ts +15 -0
- package/dist/plugins/CellSelectionPlugin.js +113 -0
- package/dist/plugins/CommandPlugin.d.ts +14 -0
- package/dist/plugins/CommandPlugin.js +31 -0
- package/dist/plugins/CopyPastePlugin.d.ts +14 -0
- package/dist/plugins/CopyPastePlugin.js +47 -0
- package/dist/plugins/DiffPlugin.d.ts +29 -0
- package/dist/plugins/DiffPlugin.js +66 -0
- package/dist/plugins/DragPlugin.d.ts +14 -0
- package/dist/plugins/DragPlugin.js +47 -0
- package/dist/plugins/EditablePlugin.d.ts +51 -0
- package/dist/plugins/EditablePlugin.js +177 -0
- package/dist/plugins/ExpandPlugin.d.ts +18 -0
- package/dist/plugins/ExpandPlugin.js +46 -0
- package/dist/plugins/HeaderGroup.d.ts +11 -0
- package/dist/plugins/HeaderGroup.js +171 -0
- package/dist/plugins/HistoryPlugin.d.ts +10 -0
- package/dist/plugins/HistoryPlugin.js +27 -0
- package/dist/plugins/MenuPlugin.d.ts +19 -0
- package/dist/plugins/MenuPlugin.js +132 -0
- package/dist/plugins/RenderPlugin/components.d.ts +5 -0
- package/dist/plugins/RenderPlugin/components.js +87 -0
- package/dist/plugins/RenderPlugin/index.d.ts +30 -0
- package/dist/plugins/RenderPlugin/index.js +49 -0
- package/dist/plugins/ResizePlugin.d.ts +27 -0
- package/dist/plugins/ResizePlugin.js +82 -0
- package/dist/plugins/RowGroupPlugin.d.ts +18 -0
- package/dist/plugins/RowGroupPlugin.js +88 -0
- package/dist/plugins/RowSelectionPlugin.d.ts +20 -0
- package/dist/plugins/RowSelectionPlugin.js +42 -0
- package/dist/plugins/TreePlugin.d.ts +24 -0
- package/dist/plugins/TreePlugin.js +110 -0
- package/dist/plugins/VirtualScrollPlugin.d.ts +15 -0
- package/dist/plugins/VirtualScrollPlugin.js +123 -0
- package/dist/plugins/ZodValidatorPlugin.d.ts +38 -0
- package/dist/plugins/ZodValidatorPlugin.js +12 -0
- package/dist/plus.js +6 -0
- package/dist/rolldown_runtime.js +9 -0
- package/dist/style.css +3 -0
- package/dist/theme/dark.scss +46 -0
- package/dist/theme/github.scss +80 -0
- package/dist/theme/material.scss +73 -0
- package/dist/theme/shadcn.scss +66 -0
- package/dist/theme/stripe.scss +57 -0
- package/dist/tree.d.ts +1 -0
- package/dist/tree.js +12 -0
- package/dist/types/auto-imports.d.js +0 -0
- package/dist/utils.d.ts +31 -0
- package/dist/utils.js +71 -0
- package/dist/wc.d.ts +1 -0
- package/dist/wc.js +21 -0
- package/dist/web-component.d.ts +1 -0
- package/dist/web-component.js +2 -0
- package/dist/x.js +6 -0
- package/package.json +38 -30
- package/docs/index-BaMALNy6.css +0 -1
- package/docs/index-CDN48t9E.js +0 -3
- package/docs/index-Cc4RNkLY.css +0 -1
- package/docs/index-MRnbkYmU.js +0 -3
- package/docs/index.html +0 -15
- package/docs/vite.svg +0 -1
- package/index.html +0 -14
- package/packages/intable/README.md +0 -379
- package/packages/intable/package.json +0 -51
- package/packages/intable/src/assets/ClearFormat.svg +0 -3
- package/packages/intable/src/assets/Forms.svg +0 -4
- package/packages/intable/src/assets/MergeCell.svg +0 -4
- package/packages/intable/src/assets/SplitCell.svg +0 -4
- package/packages/intable/src/assets/gap.svg +0 -3
- package/packages/intable/src/assets/loading.svg +0 -12
- package/packages/intable/src/assets/paint.svg +0 -9
- package/packages/intable/src/assets/solid.svg +0 -1
- package/packages/intable/src/components/Columns.tsx +0 -86
- package/packages/intable/src/components/DocTree.tsx +0 -36
- package/packages/intable/src/components/Menu.tsx +0 -109
- package/packages/intable/src/components/Popover.tsx +0 -55
- package/packages/intable/src/components/RecycleList.tsx +0 -99
- package/packages/intable/src/components/Render.tsx +0 -26
- package/packages/intable/src/components/Split.tsx +0 -56
- package/packages/intable/src/components/Tree.tsx +0 -115
- package/packages/intable/src/components/utils.tsx +0 -12
- package/packages/intable/src/hooks/index.ts +0 -200
- package/packages/intable/src/hooks/useDir.ts +0 -78
- package/packages/intable/src/hooks/useSelector.ts +0 -91
- package/packages/intable/src/hooks/useSort.tsx +0 -118
- package/packages/intable/src/hooks/useVirtualizer.ts +0 -180
- package/packages/intable/src/index.tsx +0 -481
- package/packages/intable/src/plugins/CellChangeHighlightPlugin.tsx +0 -5
- package/packages/intable/src/plugins/CellMergePlugin.tsx +0 -153
- package/packages/intable/src/plugins/CellSelectionPlugin.tsx +0 -175
- package/packages/intable/src/plugins/CommandPlugin.tsx +0 -74
- package/packages/intable/src/plugins/CopyPastePlugin.tsx +0 -63
- package/packages/intable/src/plugins/DiffPlugin.tsx +0 -107
- package/packages/intable/src/plugins/DragPlugin.tsx +0 -81
- package/packages/intable/src/plugins/EditablePlugin.tsx +0 -252
- package/packages/intable/src/plugins/ExpandPlugin.tsx +0 -80
- package/packages/intable/src/plugins/HeaderGroup.tsx +0 -289
- package/packages/intable/src/plugins/HistoryPlugin.tsx +0 -49
- package/packages/intable/src/plugins/MenuPlugin.tsx +0 -195
- package/packages/intable/src/plugins/RenderPlugin/components.tsx +0 -51
- package/packages/intable/src/plugins/RenderPlugin/index.tsx +0 -81
- package/packages/intable/src/plugins/ResizePlugin.tsx +0 -122
- package/packages/intable/src/plugins/RowGroupPlugin.tsx +0 -122
- package/packages/intable/src/plugins/RowSelectionPlugin.tsx +0 -65
- package/packages/intable/src/plugins/TreePlugin.tsx +0 -212
- package/packages/intable/src/plugins/VirtualScrollPlugin.tsx +0 -190
- package/packages/intable/src/plugins/ZodValidatorPlugin.tsx +0 -61
- package/packages/intable/src/style.scss +0 -244
- package/packages/intable/src/tree.ts +0 -13
- package/packages/intable/src/types/auto-imports.d.ts +0 -13
- package/packages/intable/src/utils.ts +0 -122
- package/packages/intable/src/wc.tsx +0 -35
- package/packages/intable/src/web-component.ts +0 -1
- package/packages/react/package.json +0 -31
- package/packages/react/src/index.ts +0 -44
- package/packages/react/src/plugins/antd.ts +0 -94
- package/packages/react/src/style.scss +0 -12
- package/packages/react/src/types/auto-imports.d.ts +0 -10
- package/packages/vue/package.json +0 -34
- package/packages/vue/src/index.ts +0 -63
- package/packages/vue/src/plugins/element-plus.ts +0 -69
- package/packages/vue/src/style.scss +0 -12
- package/packages/vue/src/types/auto-imports.d.ts +0 -10
- package/pnpm-workspace.yaml +0 -2
- package/public/vite.svg +0 -1
- package/scripts/build.js +0 -184
- package/scripts/publish.js +0 -95
- package/src/assets/ClearFormat.svg +0 -3
- package/src/assets/Forms.svg +0 -4
- package/src/assets/MergeCell.svg +0 -4
- package/src/assets/SplitCell.svg +0 -4
- package/src/assets/gap.svg +0 -3
- package/src/assets/loading.svg +0 -12
- package/src/assets/paint.svg +0 -9
- package/src/assets/solid.svg +0 -1
- package/src/demo-vue.ts +0 -54
- package/src/demo.tsx +0 -107
- package/src/index.scss +0 -105
- package/src/styles/index.scss +0 -172
- package/src/types/auto-imports.d.ts +0 -13
- package/stats.html +0 -4949
- package/tsconfig.app.json +0 -34
- package/tsconfig.json +0 -7
- package/tsconfig.node.json +0 -26
- package/vite.config.ts +0 -63
- /package/{packages/intable/src → dist}/theme/antd.scss +0 -0
- /package/{packages/intable/src → dist}/theme/element-plus.scss +0 -0
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './wc'
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
|
@@ -1,94 +0,0 @@
|
|
|
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)
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
}
|
package/pnpm-workspace.yaml
DELETED
package/public/vite.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
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>
|