antd-solid 0.0.2 → 0.0.4
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/dist/index.css +69 -0
- package/dist/index.esm.js +2369 -0
- package/dist/index.umd.js +1 -0
- package/package.json +32 -14
- package/src/index.ts +12 -5
- package/.eslintrc.cjs +0 -36
- package/.prettierrc +0 -11
- package/.vscode/settings.json +0 -13
- package/docs/.vitepress/components/Code.vue +0 -59
- package/docs/.vitepress/config.ts +0 -49
- package/docs/.vitepress/theme/index.css +0 -15
- package/docs/.vitepress/theme/index.ts +0 -13
- package/docs/components/Button.tsx +0 -20
- package/docs/components/Table.tsx +0 -34
- package/docs/components/button.md +0 -23
- package/docs/components/table.md +0 -23
- package/docs/index.md +0 -28
- package/rollup.config.js +0 -25
- package/src/Button.css +0 -14
- package/src/Button.tsx +0 -86
- package/src/ColorPicker.tsx +0 -66
- package/src/DatePicker.tsx +0 -12
- package/src/Form.tsx +0 -98
- package/src/Image.tsx +0 -29
- package/src/Input.tsx +0 -110
- package/src/InputNumber.test.tsx +0 -46
- package/src/InputNumber.tsx +0 -119
- package/src/Modal.tsx +0 -168
- package/src/Popconfirm.tsx +0 -73
- package/src/Popover.tsx +0 -30
- package/src/Progress.tsx +0 -4
- package/src/Radio.tsx +0 -132
- package/src/Result.tsx +0 -38
- package/src/Select.tsx +0 -6
- package/src/Skeleton.tsx +0 -14
- package/src/Spin.tsx +0 -23
- package/src/Switch.tsx +0 -34
- package/src/Table.tsx +0 -46
- package/src/Tabs.tsx +0 -88
- package/src/Timeline.tsx +0 -33
- package/src/Tooltip.tsx +0 -209
- package/src/Tree.tsx +0 -246
- package/src/Upload.tsx +0 -10
- package/src/hooks/createControllableValue.ts +0 -65
- package/src/hooks/createUpdateEffect.ts +0 -16
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useClickAway.ts +0 -18
- package/src/hooks/useSize.ts +0 -26
- package/src/index.css +0 -21
- package/src/utils/ReactToSolid.tsx +0 -38
- package/src/utils/SolidToReact.tsx +0 -27
- package/src/utils/array.ts +0 -21
- package/src/utils/component.tsx +0 -85
- package/src/utils/solid.ts +0 -48
- package/tsconfig.json +0 -23
- package/unocss.config.ts +0 -92
package/src/Tooltip.tsx
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { compact } from 'lodash-es'
|
|
2
|
-
import {
|
|
3
|
-
type Component,
|
|
4
|
-
type JSXElement,
|
|
5
|
-
children,
|
|
6
|
-
createEffect,
|
|
7
|
-
Show,
|
|
8
|
-
mergeProps,
|
|
9
|
-
onCleanup,
|
|
10
|
-
createMemo,
|
|
11
|
-
} from 'solid-js'
|
|
12
|
-
import { Portal } from 'solid-js/web'
|
|
13
|
-
import cs from 'classnames'
|
|
14
|
-
import createControllableValue from './hooks/createControllableValue'
|
|
15
|
-
import { useClickAway } from './hooks'
|
|
16
|
-
|
|
17
|
-
type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu'
|
|
18
|
-
type TooltipPlacement =
|
|
19
|
-
| 'top'
|
|
20
|
-
| 'left'
|
|
21
|
-
| 'right'
|
|
22
|
-
| 'bottom'
|
|
23
|
-
| 'topLeft'
|
|
24
|
-
| 'topRight'
|
|
25
|
-
| 'bottomLeft'
|
|
26
|
-
| 'bottomRight'
|
|
27
|
-
| 'leftTop'
|
|
28
|
-
| 'leftBottom'
|
|
29
|
-
| 'rightTop'
|
|
30
|
-
| 'rightBottom'
|
|
31
|
-
|
|
32
|
-
export interface TooltipProps {
|
|
33
|
-
/**
|
|
34
|
-
* 默认: hover
|
|
35
|
-
*/
|
|
36
|
-
trigger?: ActionType
|
|
37
|
-
/**
|
|
38
|
-
* 默认: top
|
|
39
|
-
*/
|
|
40
|
-
placement?: TooltipPlacement
|
|
41
|
-
content?: JSXElement | ((close: () => void) => JSXElement)
|
|
42
|
-
children?: JSXElement
|
|
43
|
-
open?: boolean
|
|
44
|
-
onOpenChange?: (open: boolean) => void
|
|
45
|
-
/**
|
|
46
|
-
* 默认: dark
|
|
47
|
-
*/
|
|
48
|
-
mode?: 'dark' | 'light'
|
|
49
|
-
/**
|
|
50
|
-
* 默认: true
|
|
51
|
-
*/
|
|
52
|
-
arrow?: boolean | { pointAtCenter: boolean }
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const Content: Component<{
|
|
56
|
-
content: TooltipProps['content']
|
|
57
|
-
close: () => void
|
|
58
|
-
}> = props => {
|
|
59
|
-
return (
|
|
60
|
-
<Show when={typeof props.content === 'function'} fallback={props.content as JSXElement}>
|
|
61
|
-
{typeof props.content === 'function' && props.content(props.close)}
|
|
62
|
-
</Show>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const Tooltip: Component<TooltipProps> = _props => {
|
|
67
|
-
const props = mergeProps(
|
|
68
|
-
{
|
|
69
|
-
trigger: 'hover',
|
|
70
|
-
placement: 'top',
|
|
71
|
-
mode: 'dark',
|
|
72
|
-
arrow: true,
|
|
73
|
-
} as TooltipProps,
|
|
74
|
-
_props,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const resolvedChildren = children(() => _props.children)
|
|
78
|
-
let contentWrap: HTMLDivElement
|
|
79
|
-
let arrow: HTMLDivElement
|
|
80
|
-
const [open, setOpen] = createControllableValue(_props, {
|
|
81
|
-
defaultValue: false,
|
|
82
|
-
valuePropName: 'open',
|
|
83
|
-
trigger: 'onOpenChange',
|
|
84
|
-
})
|
|
85
|
-
const reverseOpen = () => setOpen(v => !v)
|
|
86
|
-
|
|
87
|
-
createEffect(() => {
|
|
88
|
-
const _children = resolvedChildren() as Element
|
|
89
|
-
switch (props.trigger) {
|
|
90
|
-
case 'hover':
|
|
91
|
-
_children.addEventListener('mouseenter', reverseOpen)
|
|
92
|
-
onCleanup(() => {
|
|
93
|
-
_children.removeEventListener('mouseenter', reverseOpen)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
_children.addEventListener('mouseleave', reverseOpen)
|
|
97
|
-
onCleanup(() => {
|
|
98
|
-
_children.removeEventListener('mouseleave', reverseOpen)
|
|
99
|
-
})
|
|
100
|
-
break
|
|
101
|
-
case 'click':
|
|
102
|
-
_children.addEventListener('click', reverseOpen)
|
|
103
|
-
onCleanup(() => {
|
|
104
|
-
_children.removeEventListener('click', reverseOpen)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
useClickAway(
|
|
108
|
-
() => setOpen(false),
|
|
109
|
-
() => compact([contentWrap, _children]),
|
|
110
|
-
)
|
|
111
|
-
break
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
createEffect(() => {
|
|
116
|
-
if (open()) {
|
|
117
|
-
const _children = resolvedChildren() as Element
|
|
118
|
-
const childrenRect = _children.getBoundingClientRect()
|
|
119
|
-
const pointAtCenter = typeof props.arrow === 'object' ? props.arrow.pointAtCenter : false
|
|
120
|
-
const arrowOffset = 8
|
|
121
|
-
|
|
122
|
-
switch (props.placement) {
|
|
123
|
-
case 'top':
|
|
124
|
-
contentWrap.style.top = `${childrenRect.top}px`
|
|
125
|
-
contentWrap.style.left = `${childrenRect.left + childrenRect.width / 2}px`
|
|
126
|
-
contentWrap.style.transform = 'translate(-50%, -100%)'
|
|
127
|
-
break
|
|
128
|
-
case 'topRight':
|
|
129
|
-
contentWrap.style.top = `${childrenRect.top}px`
|
|
130
|
-
contentWrap.style.left = `${childrenRect.right}px`
|
|
131
|
-
contentWrap.style.transform = 'translate(-100%, -100%)'
|
|
132
|
-
if (arrow) arrow.style.right = `${arrowOffset}px`
|
|
133
|
-
break
|
|
134
|
-
case 'bottom':
|
|
135
|
-
contentWrap.style.top = `${childrenRect.top + childrenRect.height}px`
|
|
136
|
-
contentWrap.style.left = `${childrenRect.left + childrenRect.width / 2}px`
|
|
137
|
-
contentWrap.style.transform = 'translate(-50%, 0)'
|
|
138
|
-
break
|
|
139
|
-
case 'bottomLeft':
|
|
140
|
-
contentWrap.style.top = `${childrenRect.top + childrenRect.height}px`
|
|
141
|
-
contentWrap.style.left = `${childrenRect.left}px`
|
|
142
|
-
if (arrow) arrow.style.left = `${arrowOffset}px`
|
|
143
|
-
break
|
|
144
|
-
case 'bottomRight':
|
|
145
|
-
contentWrap.style.top = `${childrenRect.top + childrenRect.height}px`
|
|
146
|
-
contentWrap.style.left = `${childrenRect.right + (pointAtCenter ? arrowOffset : 0)}px`
|
|
147
|
-
contentWrap.style.transform = 'translate(-100%, 0)'
|
|
148
|
-
if (arrow) arrow.style.right = `${arrowOffset}px`
|
|
149
|
-
break
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
const direction = createMemo(() => {
|
|
155
|
-
if (props.placement?.startsWith('top')) return 'top'
|
|
156
|
-
if (props.placement?.startsWith('bottom')) return 'bottom'
|
|
157
|
-
if (props.placement?.startsWith('left')) return 'left'
|
|
158
|
-
if (props.placement?.startsWith('right')) return 'right'
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<>
|
|
163
|
-
{resolvedChildren}
|
|
164
|
-
|
|
165
|
-
<Show when={open()}>
|
|
166
|
-
<Portal>
|
|
167
|
-
{/* Portal 存在缺陷,onClick 依然会沿着 solid 的组件树向上传播,因此需要 stopPropagation */}
|
|
168
|
-
<div
|
|
169
|
-
ref={contentWrap!}
|
|
170
|
-
class={cs(
|
|
171
|
-
'ant-z-1000 ant-fixed after:ant-content-empty',
|
|
172
|
-
props.arrow ? '[--padding:8px]' : '[--padding:4px]',
|
|
173
|
-
direction() === 'top' && 'ant-pb-[var(--padding)]',
|
|
174
|
-
direction() === 'bottom' && 'ant-pt-[var(--padding)]',
|
|
175
|
-
)}
|
|
176
|
-
onClick={e => {
|
|
177
|
-
e.stopPropagation()
|
|
178
|
-
}}
|
|
179
|
-
>
|
|
180
|
-
<div
|
|
181
|
-
class={cs(
|
|
182
|
-
'ant-p-12px ant-rounded-8px ant-[box-shadow:0_6px_16px_0_rgba(0,0,0,0.08),0_3px_6px_-4px_rgba(0,0,0,0.12),0_9px_28px_8px_rgba(0,0,0,0.05)]',
|
|
183
|
-
props.mode === 'dark' ? 'ant-bg-[rgba(0,0,0,0.85)] ant-text-white' : 'ant-bg-white',
|
|
184
|
-
)}
|
|
185
|
-
>
|
|
186
|
-
<Content content={props.content} close={() => setOpen(false)} />
|
|
187
|
-
</div>
|
|
188
|
-
<Show when={props.arrow}>
|
|
189
|
-
<div
|
|
190
|
-
ref={arrow!}
|
|
191
|
-
class={cs(
|
|
192
|
-
'ant-w-8px ant-h-8px ant-rotate-45 ant-absolute',
|
|
193
|
-
props.mode === 'dark' ? 'ant-bg-[rgba(0,0,0,0.85)]' : 'ant-bg-white',
|
|
194
|
-
direction() === 'top' &&
|
|
195
|
-
'ant-bottom-0 -ant-translate-x-1/2 -ant-translate-y-1/2 ant-[filter:drop-shadow(3px_2px_2px_rgba(0,0,0,0.08))]',
|
|
196
|
-
direction() === 'bottom' &&
|
|
197
|
-
'ant-top-0 -ant-translate-x-1/2 ant-translate-y-1/2 ant-[filter:drop-shadow(-3px_-2px_2px_rgba(0,0,0,0.08))]',
|
|
198
|
-
(props.placement === 'top' || props.placement === 'bottom') && 'left-1/2',
|
|
199
|
-
)}
|
|
200
|
-
/>
|
|
201
|
-
</Show>
|
|
202
|
-
</div>
|
|
203
|
-
</Portal>
|
|
204
|
-
</Show>
|
|
205
|
-
</>
|
|
206
|
-
)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export default Tooltip
|
package/src/Tree.tsx
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { isEmpty } from 'lodash-es'
|
|
2
|
-
import {
|
|
3
|
-
type Accessor,
|
|
4
|
-
createContext,
|
|
5
|
-
createSignal,
|
|
6
|
-
Index,
|
|
7
|
-
type JSXElement,
|
|
8
|
-
type Setter,
|
|
9
|
-
Show,
|
|
10
|
-
untrack,
|
|
11
|
-
useContext,
|
|
12
|
-
createSelector,
|
|
13
|
-
} from 'solid-js'
|
|
14
|
-
import cs from 'classnames'
|
|
15
|
-
|
|
16
|
-
export interface TreeProps<T extends {} = {}> {
|
|
17
|
-
class?: string
|
|
18
|
-
defaultSelectedNodes?: T[]
|
|
19
|
-
treeData?: T[]
|
|
20
|
-
/**
|
|
21
|
-
* 是否节点占据一行
|
|
22
|
-
*/
|
|
23
|
-
blockNode?: boolean
|
|
24
|
-
defaultExpandAll?: boolean
|
|
25
|
-
/**
|
|
26
|
-
* 设置节点可拖拽
|
|
27
|
-
*/
|
|
28
|
-
draggable?: boolean
|
|
29
|
-
titleRender: (
|
|
30
|
-
node: T,
|
|
31
|
-
info: {
|
|
32
|
-
indexes: number[]
|
|
33
|
-
},
|
|
34
|
-
) => JSXElement
|
|
35
|
-
children: (node: T) => T[] | undefined
|
|
36
|
-
onSelect?: (node: T) => void
|
|
37
|
-
onDrop?: (info: {
|
|
38
|
-
dragNode: T
|
|
39
|
-
targetNode: T
|
|
40
|
-
dragIndexes: number[]
|
|
41
|
-
targetIndexes: number[]
|
|
42
|
-
}) => void
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface SingleLevelTreeProps<T extends {} = {}> extends Omit<TreeProps<T>, 'class'> {
|
|
46
|
-
indent: number
|
|
47
|
-
parentIndexes?: number[]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const TreeContext = createContext(
|
|
51
|
-
{} as unknown as {
|
|
52
|
-
selectedNodes: Accessor<Array<{}>>
|
|
53
|
-
setSelectedNodes: Setter<Array<{}>>
|
|
54
|
-
draggableNode: Accessor<{} | null>
|
|
55
|
-
setDraggableNode: Setter<{} | null>
|
|
56
|
-
draggableIndexes: Accessor<number[] | null>
|
|
57
|
-
setDraggableIndexes: Setter<number[] | null>
|
|
58
|
-
isDraggable: (key: {} | null) => boolean
|
|
59
|
-
targetNode: Accessor<{} | null>
|
|
60
|
-
setTargetNode: Setter<{} | null>
|
|
61
|
-
targetIndexes: Accessor<number[] | null>
|
|
62
|
-
setTargetIndexes: Setter<number[] | null>
|
|
63
|
-
isTarget: (key: {} | null) => boolean
|
|
64
|
-
draggable: TreeProps['draggable'] | undefined
|
|
65
|
-
onDrop: TreeProps['onDrop'] | undefined
|
|
66
|
-
},
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 单层级 tree
|
|
71
|
-
*/
|
|
72
|
-
function SingleLevelTree<T extends {} = {}>(props: SingleLevelTreeProps<T>) {
|
|
73
|
-
const [expanded, setExpanded] = createSignal(props.defaultExpandAll)
|
|
74
|
-
const {
|
|
75
|
-
selectedNodes,
|
|
76
|
-
setSelectedNodes,
|
|
77
|
-
draggableNode,
|
|
78
|
-
setDraggableNode,
|
|
79
|
-
draggableIndexes,
|
|
80
|
-
setDraggableIndexes,
|
|
81
|
-
isDraggable,
|
|
82
|
-
targetNode,
|
|
83
|
-
setTargetNode,
|
|
84
|
-
targetIndexes,
|
|
85
|
-
setTargetIndexes,
|
|
86
|
-
isTarget,
|
|
87
|
-
draggable,
|
|
88
|
-
onDrop,
|
|
89
|
-
} = useContext(TreeContext)
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<Index each={props.treeData}>
|
|
93
|
-
{(item, i) => {
|
|
94
|
-
const indexes = [...(props.parentIndexes ?? []), i]
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<>
|
|
98
|
-
<div
|
|
99
|
-
class={cs(
|
|
100
|
-
'ant-flex ant-items-center ant-h-28px ant-pb-4px',
|
|
101
|
-
isDraggable(item()) && 'ant-[border:1px_solid_var(--primary-color)] ant-bg-white',
|
|
102
|
-
draggableNode() && 'child[]:ant-pointer-events-none',
|
|
103
|
-
)}
|
|
104
|
-
draggable={draggable}
|
|
105
|
-
onDragStart={() => {
|
|
106
|
-
setDraggableNode(item() as {})
|
|
107
|
-
setDraggableIndexes(indexes)
|
|
108
|
-
}}
|
|
109
|
-
onDragEnter={() => {
|
|
110
|
-
if (item() !== draggableNode()) {
|
|
111
|
-
setTargetNode(item() as {})
|
|
112
|
-
setTargetIndexes(indexes)
|
|
113
|
-
}
|
|
114
|
-
}}
|
|
115
|
-
onDragLeave={e => {
|
|
116
|
-
if (item() === targetNode() && e.relatedTarget) {
|
|
117
|
-
setTargetNode(null)
|
|
118
|
-
setTargetIndexes(null)
|
|
119
|
-
}
|
|
120
|
-
}}
|
|
121
|
-
onDragEnd={() => {
|
|
122
|
-
onDrop?.({
|
|
123
|
-
dragNode: draggableNode()!,
|
|
124
|
-
dragIndexes: draggableIndexes()!,
|
|
125
|
-
targetNode: targetNode()!,
|
|
126
|
-
targetIndexes: targetIndexes()!,
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
setDraggableNode(null)
|
|
130
|
-
setDraggableIndexes(null)
|
|
131
|
-
setTargetNode(null)
|
|
132
|
-
setTargetIndexes(null)
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
<div class="flex-shrink-0" role={'indent' as any}>
|
|
136
|
-
{/* eslint-disable-next-line solid/prefer-for */}
|
|
137
|
-
{Array(props.indent)
|
|
138
|
-
.fill(0)
|
|
139
|
-
.map(() => (
|
|
140
|
-
<span class="ant-inline-block ant-w-24px" />
|
|
141
|
-
))}
|
|
142
|
-
</div>
|
|
143
|
-
<div class="ant-flex-shrink-0 ant-w-24px ant-h-24px ant-flex ant-items-center ant-justify-center">
|
|
144
|
-
<span class="i-ant-design:holder-outlined" />
|
|
145
|
-
</div>
|
|
146
|
-
<div
|
|
147
|
-
class={cs(
|
|
148
|
-
'ant-flex-shrink-0 ant-w-24px ant-h-24px ant-flex ant-items-center ant-justify-center ant-cursor-pointer',
|
|
149
|
-
isEmpty(props.children(item())) && 'opacity-0',
|
|
150
|
-
)}
|
|
151
|
-
>
|
|
152
|
-
<Show
|
|
153
|
-
when={expanded()}
|
|
154
|
-
fallback={
|
|
155
|
-
<span
|
|
156
|
-
class={'i-ant-design:plus-square-outlined'}
|
|
157
|
-
onClick={[setExpanded, true]}
|
|
158
|
-
/>
|
|
159
|
-
}
|
|
160
|
-
>
|
|
161
|
-
<span
|
|
162
|
-
class={'i-ant-design:minus-square-outlined'}
|
|
163
|
-
onClick={[setExpanded, false]}
|
|
164
|
-
/>
|
|
165
|
-
</Show>
|
|
166
|
-
</div>
|
|
167
|
-
<div
|
|
168
|
-
class={cs(
|
|
169
|
-
'ant-h-full ant-leading-24px ant-hover:bg-[rgba(0,0,0,.04)] ant-rounded-1 ant-px-1 ant-cursor-pointer ant-relative',
|
|
170
|
-
props.blockNode && 'w-full',
|
|
171
|
-
selectedNodes()?.includes(item()) && '!ant-bg-[var(--active-bg-color)]',
|
|
172
|
-
isTarget(item()) &&
|
|
173
|
-
"before:ant-content-[''] before:ant-inline-block before:ant-w-8px before:ant-h-8px before:ant-absolute before:ant-bottom-0 before:ant-left-0 before:-ant-translate-x-full before:ant-translate-y-1/2 before:ant-rounded-1/2 before:ant-[border:2px_solid_var(--primary-color)] after:ant-content-[''] after:ant-inline-block after:ant-h-2px after:ant-absolute after:ant-left-0 after:ant-right-0 after:ant-bottom--1px after:ant-bg-[var(--primary-color)]",
|
|
174
|
-
)}
|
|
175
|
-
onClick={() => {
|
|
176
|
-
setSelectedNodes([item()])
|
|
177
|
-
props.onSelect?.(item())
|
|
178
|
-
}}
|
|
179
|
-
>
|
|
180
|
-
{props.titleRender(item(), { indexes })}
|
|
181
|
-
</div>
|
|
182
|
-
</div>
|
|
183
|
-
|
|
184
|
-
<Show when={expanded() && !isEmpty(props.children(item()))}>
|
|
185
|
-
<SingleLevelTree
|
|
186
|
-
treeData={props.children(item())}
|
|
187
|
-
indent={props.indent + 1}
|
|
188
|
-
parentIndexes={indexes}
|
|
189
|
-
blockNode={props.blockNode}
|
|
190
|
-
defaultExpandAll={props.defaultExpandAll}
|
|
191
|
-
titleRender={props.titleRender}
|
|
192
|
-
children={props.children}
|
|
193
|
-
onSelect={node => untrack(() => props.onSelect?.(node))}
|
|
194
|
-
/>
|
|
195
|
-
</Show>
|
|
196
|
-
</>
|
|
197
|
-
)
|
|
198
|
-
}}
|
|
199
|
-
</Index>
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function Tree<T extends {} = {}>(props: TreeProps<T>) {
|
|
204
|
-
const [selectedNodes, setSelectedNodes] = createSignal<T[]>(props.defaultSelectedNodes ?? [])
|
|
205
|
-
|
|
206
|
-
const [draggableNode, setDraggableNode] = createSignal<T | null>(null)
|
|
207
|
-
const isDraggable = createSelector<T | null, T | null>(draggableNode)
|
|
208
|
-
const [draggableIndexes, setDraggableIndexes] = createSignal<number[] | null>(null)
|
|
209
|
-
|
|
210
|
-
const [targetNode, setTargetNode] = createSignal<T | null>(null)
|
|
211
|
-
const isTarget = createSelector<T | null, T | null>(targetNode)
|
|
212
|
-
const [targetIndexes, setTargetIndexes] = createSignal<number[] | null>(null)
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<TreeContext.Provider
|
|
216
|
-
value={{
|
|
217
|
-
selectedNodes,
|
|
218
|
-
setSelectedNodes,
|
|
219
|
-
draggableNode,
|
|
220
|
-
setDraggableNode,
|
|
221
|
-
draggableIndexes,
|
|
222
|
-
setDraggableIndexes,
|
|
223
|
-
isDraggable,
|
|
224
|
-
targetNode,
|
|
225
|
-
setTargetNode,
|
|
226
|
-
targetIndexes,
|
|
227
|
-
setTargetIndexes,
|
|
228
|
-
isTarget,
|
|
229
|
-
draggable: props.draggable,
|
|
230
|
-
onDrop: props.onDrop,
|
|
231
|
-
}}
|
|
232
|
-
>
|
|
233
|
-
<SingleLevelTree
|
|
234
|
-
treeData={props.treeData}
|
|
235
|
-
indent={0}
|
|
236
|
-
blockNode={props.blockNode}
|
|
237
|
-
defaultExpandAll={props.defaultExpandAll}
|
|
238
|
-
titleRender={props.titleRender}
|
|
239
|
-
children={props.children}
|
|
240
|
-
onSelect={node => untrack(() => props.onSelect?.(node))}
|
|
241
|
-
/>
|
|
242
|
-
</TreeContext.Provider>
|
|
243
|
-
)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export default Tree
|
package/src/Upload.tsx
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { reactToSolidComponent, replaceChildren, replaceClassName } from './utils/component'
|
|
2
|
-
import { Upload as UploadAntd } from 'antd'
|
|
3
|
-
|
|
4
|
-
export type { UploadFile } from 'antd/es/upload'
|
|
5
|
-
|
|
6
|
-
const Upload = replaceChildren(replaceClassName(reactToSolidComponent(UploadAntd)))
|
|
7
|
-
|
|
8
|
-
export type UploadProps = Parameters<typeof Upload>[0]
|
|
9
|
-
|
|
10
|
-
export default Upload
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Setter, Signal, createSignal } from 'solid-js'
|
|
2
|
-
import createUpdateEffect from './createUpdateEffect'
|
|
3
|
-
|
|
4
|
-
export interface Options<T> {
|
|
5
|
-
defaultValue?: T
|
|
6
|
-
defaultValuePropName?: string
|
|
7
|
-
valuePropName?: string
|
|
8
|
-
trigger?: string | undefined
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type Props = Record<string, any>
|
|
12
|
-
|
|
13
|
-
export interface StandardProps<T> {
|
|
14
|
-
value: T
|
|
15
|
-
defaultValue?: T
|
|
16
|
-
onChange: (val: T) => void
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function createControllableValue<T = any>(props: StandardProps<T>): Signal<T>
|
|
20
|
-
function createControllableValue<T = any>(props: Props, options?: Options<T>): Signal<T>
|
|
21
|
-
function createControllableValue<T = any>(props: Props, options: Options<T> = {}) {
|
|
22
|
-
const {
|
|
23
|
-
defaultValuePropName = 'defaultValue',
|
|
24
|
-
valuePropName = 'value',
|
|
25
|
-
trigger = 'onChange',
|
|
26
|
-
} = options
|
|
27
|
-
|
|
28
|
-
const getValue = () => props[valuePropName] as T
|
|
29
|
-
// 为什么不使用 Object.hasOwn?
|
|
30
|
-
// solid 的 proxy 对象对于任何 key,都会返回 true
|
|
31
|
-
const isControlled = () => Object.keys(props).includes(valuePropName)
|
|
32
|
-
|
|
33
|
-
let defaultValue = options.defaultValue
|
|
34
|
-
if (isControlled()) {
|
|
35
|
-
defaultValue = getValue()
|
|
36
|
-
} else if (Object.keys(props).includes(defaultValuePropName)) {
|
|
37
|
-
defaultValue = props[defaultValuePropName]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const [value, _setValue] = createSignal(defaultValue)
|
|
41
|
-
|
|
42
|
-
createUpdateEffect(getValue, () => {
|
|
43
|
-
if (!isControlled()) return
|
|
44
|
-
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
_setValue(getValue())
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const setValue: Setter<T> = (v => {
|
|
50
|
-
const newValue = _setValue(v)
|
|
51
|
-
|
|
52
|
-
if (trigger) {
|
|
53
|
-
const onChange = props[trigger]
|
|
54
|
-
if (typeof onChange === 'function') {
|
|
55
|
-
onChange(newValue)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return newValue
|
|
60
|
-
}) as Setter<T>
|
|
61
|
-
|
|
62
|
-
return [value, setValue] as Signal<T>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default createControllableValue
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createEffect, on } from 'solid-js'
|
|
2
|
-
import type { Accessor, AccessorArray, NoInfer, OnEffectFunction } from 'solid-js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 等同于 createEffect,但是会忽略首次执行,只在依赖更新时执行。
|
|
6
|
-
*/
|
|
7
|
-
export default function createUpdateEffect<S, Next extends Prev, Prev = Next>(
|
|
8
|
-
deps: AccessorArray<S> | Accessor<S>,
|
|
9
|
-
fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>,
|
|
10
|
-
) {
|
|
11
|
-
createEffect(
|
|
12
|
-
on(deps, fn, {
|
|
13
|
-
defer: true,
|
|
14
|
-
}),
|
|
15
|
-
)
|
|
16
|
-
}
|
package/src/hooks/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type Accessor, onCleanup } from 'solid-js'
|
|
2
|
-
import { toArray } from '../utils/array'
|
|
3
|
-
|
|
4
|
-
export default function useClickAway<T extends Event = Event>(
|
|
5
|
-
onClickAway: (event: T) => void,
|
|
6
|
-
target?: Accessor<Element | Element[]>,
|
|
7
|
-
) {
|
|
8
|
-
const onClick = (event: Event) => {
|
|
9
|
-
const targets = target ? toArray(target()) : []
|
|
10
|
-
if (targets.every(item => !item.contains(event.target as Node))) {
|
|
11
|
-
onClickAway(event as T)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
document.body.addEventListener('click', onClick)
|
|
15
|
-
onCleanup(() => {
|
|
16
|
-
document.body.removeEventListener('click', onClick)
|
|
17
|
-
})
|
|
18
|
-
}
|
package/src/hooks/useSize.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Accessor, createSignal, onCleanup, onMount } from 'solid-js'
|
|
2
|
-
|
|
3
|
-
function getTarget(target: Element | Accessor<Element>) {
|
|
4
|
-
return target instanceof Element ? target : target()
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default function useSize(target: Element | Accessor<Element>) {
|
|
8
|
-
const [size, setSize] = createSignal<{
|
|
9
|
-
width: number
|
|
10
|
-
height: number
|
|
11
|
-
}>()
|
|
12
|
-
|
|
13
|
-
onMount(() => {
|
|
14
|
-
const _target = getTarget(target)
|
|
15
|
-
const ro = new ResizeObserver(() => {
|
|
16
|
-
setSize({
|
|
17
|
-
width: _target.clientWidth,
|
|
18
|
-
height: _target.clientHeight,
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
ro.observe(_target)
|
|
22
|
-
onCleanup(() => ro.disconnect())
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return size
|
|
26
|
-
}
|
package/src/index.css
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
--primary-color: #52c41a;
|
|
3
|
-
--light-primary-color: #95de64;
|
|
4
|
-
--dark-primary-color: #237804;
|
|
5
|
-
--active-bg-color: #d9f7be;
|
|
6
|
-
|
|
7
|
-
--error-color: #ff4d4f;
|
|
8
|
-
--warning-color: #faad14;
|
|
9
|
-
|
|
10
|
-
--border-color: #d9d9d9;
|
|
11
|
-
--secondary-border-color: #f0f0f0;
|
|
12
|
-
|
|
13
|
-
--light-color: rgba(0, 0, 0, 0.45);
|
|
14
|
-
--dark-color: rgba(0, 0, 0, 0.88);
|
|
15
|
-
|
|
16
|
-
--light-bg-color: #fafafa;
|
|
17
|
-
|
|
18
|
-
--secondary-border-color: #f0f0f0;
|
|
19
|
-
|
|
20
|
-
font-size: 14px;
|
|
21
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { createRoot, type Root } from 'react-dom/client'
|
|
3
|
-
// import { renderToString } from 'react-dom/server'
|
|
4
|
-
import { onMount, onCleanup, createEffect, createMemo } from 'solid-js'
|
|
5
|
-
|
|
6
|
-
interface ReactToSolidProps<P extends {} = {}> {
|
|
7
|
-
component: React.FunctionComponent<P> | React.ComponentClass<P>
|
|
8
|
-
props: P
|
|
9
|
-
container?: Element
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function ReactToSolid<P extends {} = {}>(props: ReactToSolidProps<P>) {
|
|
13
|
-
let root: Root
|
|
14
|
-
|
|
15
|
-
const rootEle = createMemo(
|
|
16
|
-
() => props.container ?? ((<div role={'ReactToSolid' as any} />) as Element),
|
|
17
|
-
)
|
|
18
|
-
onMount(() => {
|
|
19
|
-
root = createRoot(rootEle())
|
|
20
|
-
onCleanup(() => {
|
|
21
|
-
root.unmount()
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
createEffect(() => {
|
|
26
|
-
root.render(React.createElement(props.component, { ...props.props }))
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
// if (import.meta.env.SSR) {
|
|
30
|
-
// // eslint-disable-next-line solid/reactivity
|
|
31
|
-
// const node = React.createElement(props.component, { ...props.props })
|
|
32
|
-
// // eslint-disable-next-line solid/components-return-once, solid/no-innerhtml
|
|
33
|
-
// return <div innerHTML={renderToString(node)} />
|
|
34
|
-
// }
|
|
35
|
-
return <>{rootEle}</>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default ReactToSolid
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React, { type FunctionComponent, type ReactElement, useEffect, useRef } from 'react'
|
|
2
|
-
import { type JSX } from 'solid-js'
|
|
3
|
-
import { render } from 'solid-js/web'
|
|
4
|
-
|
|
5
|
-
export interface SolidToReactProps {
|
|
6
|
-
children?: JSX.Element
|
|
7
|
-
container?: ReactElement
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const SolidToReact: FunctionComponent<SolidToReactProps> = ({ children, container }) => {
|
|
11
|
-
const ref = useRef<HTMLDivElement>()
|
|
12
|
-
|
|
13
|
-
useEffect(() => render(() => children, ref.current!), [])
|
|
14
|
-
|
|
15
|
-
// if (import.meta.env.SSR) {
|
|
16
|
-
// return React.createElement('div', {
|
|
17
|
-
// dangerouslySetInnerHTML: { __html: renderToString(() => children) },
|
|
18
|
-
// })
|
|
19
|
-
// }
|
|
20
|
-
return container
|
|
21
|
-
? React.cloneElement(container, {
|
|
22
|
-
ref,
|
|
23
|
-
})
|
|
24
|
-
: React.createElement('div', { ref, role: 'SolidToReact' })
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default SolidToReact
|