antd-solid 0.0.11 → 0.0.13
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/css/index.css +10 -73
- package/dist/index.esm.js +7802 -2378
- package/dist/index.umd.js +1 -1
- package/es/Alert/index.d.ts +10 -0
- package/es/Alert/index.js +26 -0
- package/es/Button/index.d.ts +32 -0
- package/es/Button/index.js +123 -0
- package/es/Button/index.scss.js +6 -0
- package/es/Checkbox/Group.d.ts +19 -0
- package/es/Checkbox/Group.js +49 -0
- package/es/Checkbox/index.d.ts +15 -0
- package/es/Checkbox/index.js +60 -0
- package/es/CodeInput/index.d.ts +18 -0
- package/es/CodeInput/index.js +72 -0
- package/es/Collapse/Item.d.ts +46 -0
- package/es/Collapse/Item.js +130 -0
- package/es/Collapse/context.d.ts +5 -0
- package/es/Collapse/context.js +8 -0
- package/es/Collapse/index.d.ts +25 -10
- package/es/Collapse/index.js +95 -74
- package/es/Collapse/utils.d.ts +8 -0
- package/es/Collapse/utils.js +35 -0
- package/es/ColorPicker/ColorPickerInput.d.ts +3 -0
- package/es/ColorPicker/ColorPickerInput.js +250 -0
- package/es/ColorPicker/ColorPickerSelect.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSelect.js +71 -0
- package/es/ColorPicker/ColorPickerSlider.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSlider.js +115 -0
- package/es/ColorPicker/color.d.ts +24 -0
- package/es/ColorPicker/color.js +63 -0
- package/es/ColorPicker/context.d.ts +9 -0
- package/es/ColorPicker/context.js +5 -0
- package/es/ColorPicker/index.d.ts +31 -0
- package/es/ColorPicker/index.js +139 -0
- package/es/Command/context.d.ts +9 -0
- package/es/Command/context.js +11 -0
- package/es/Command/createCommand.d.ts +17 -0
- package/es/Command/createCommand.js +112 -0
- package/es/Command/index.d.ts +7 -0
- package/es/Command/index.js +9 -0
- package/es/Command/useCommandProps.d.ts +13 -0
- package/es/Command/useCommandProps.js +28 -0
- package/es/Compact/CompactContextIsolator.d.ts +3 -0
- package/es/Compact/CompactContextIsolator.js +15 -0
- package/es/Compact/context.d.ts +4 -0
- package/es/Compact/context.js +7 -0
- package/es/Compact/index.d.ts +14 -0
- package/es/Compact/index.js +32 -0
- package/es/Compact/index.scss.js +6 -0
- package/es/ConfigProvider/context.d.ts +11 -0
- package/es/ConfigProvider/context.js +15 -0
- package/es/ConfigProvider/dark/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/dark/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/dark/colors.d.ts +3 -0
- package/es/ConfigProvider/dark/colors.js +47 -0
- package/es/ConfigProvider/dark/index.d.ts +2 -0
- package/es/ConfigProvider/dark/index.js +11 -0
- package/es/ConfigProvider/index.d.ts +32 -0
- package/es/ConfigProvider/index.js +44 -0
- package/es/ConfigProvider/light/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/light/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/light/colors.d.ts +3 -0
- package/es/ConfigProvider/light/colors.js +45 -0
- package/es/ConfigProvider/light/index.d.ts +2 -0
- package/es/ConfigProvider/light/index.js +11 -0
- package/es/ConfigProvider/seed.d.ts +3 -0
- package/es/ConfigProvider/seed.js +22 -0
- package/es/ConfigProvider/types/index.d.ts +594 -0
- package/es/ConfigProvider/types/index.js +1 -0
- package/es/ConfigProvider/utils/genColorMapToken.d.ts +7 -0
- package/es/ConfigProvider/utils/genColorMapToken.js +85 -0
- package/es/ConfigProvider/utils/getAlphaColor.d.ts +2 -0
- package/es/ConfigProvider/utils/getAlphaColor.js +44 -0
- package/es/ConfigProvider/utils/index.d.ts +3 -0
- package/es/ConfigProvider/utils/index.js +181 -0
- package/es/ContextMenu/index.d.ts +8 -0
- package/es/ContextMenu/index.js +99 -0
- package/es/Cursor/index.d.ts +6 -0
- package/es/Cursor/index.js +71 -0
- package/es/DelayShow/index.d.ts +16 -0
- package/es/DelayShow/index.js +27 -0
- package/es/Divider/index.d.ts +17 -0
- package/es/Divider/index.js +71 -0
- package/es/Drawer/index.d.ts +20 -16
- package/es/Drawer/index.js +162 -112
- package/es/Drawer/index.scss.js +1 -1
- package/es/Dropdown/index.d.ts +16 -0
- package/es/Dropdown/index.js +47 -0
- package/es/Element/index.d.ts +10 -0
- package/es/Element/index.js +42 -0
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.d.ts +2 -1
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.js +25 -9
- package/es/Empty/assets/EmptySvg.js +1 -1
- package/es/Empty/assets/SimpleEmptySvg.js +1 -1
- package/es/Empty/index.d.ts +9 -3
- package/es/Empty/index.js +24 -9
- package/es/Form/Form.d.ts +8 -5
- package/es/Form/Form.js +50 -34
- package/es/Form/FormItem.d.ts +10 -5
- package/es/Form/FormItem.js +121 -104
- package/es/Form/context.d.ts +9 -9
- package/es/Form/context.js +4 -2
- package/es/Fragment/index.d.ts +4 -0
- package/es/Fragment/index.js +7 -0
- package/es/Image/index.d.ts +10 -0
- package/es/Image/index.js +37 -0
- package/es/Input/TextArea.d.ts +23 -0
- package/es/Input/TextArea.js +84 -0
- package/es/Input/index.d.ts +44 -0
- package/es/Input/index.js +213 -0
- package/es/Input/index.scss.js +6 -0
- package/es/InputNumber/index.d.ts +30 -0
- package/es/InputNumber/index.js +122 -0
- package/es/{InputNumber.test.js → InputNumber/index.test.js} +2 -1
- package/es/Menu/InternalMenu.d.ts +22 -0
- package/es/Menu/InternalMenu.js +196 -0
- package/es/Menu/index.d.ts +75 -0
- package/es/Menu/index.js +64 -0
- package/es/Message/Message.d.ts +9 -0
- package/es/Message/Message.js +34 -0
- package/es/Message/index.d.ts +12 -0
- package/es/Message/index.js +80 -0
- package/es/Message/index.scss.js +6 -0
- package/es/Message/useMessage.d.ts +6 -0
- package/es/Message/useMessage.js +54 -0
- package/es/Modal/index.d.ts +73 -0
- package/es/Modal/index.js +237 -0
- package/es/Modal/index.scss.js +6 -0
- package/es/Modal/useModal.d.ts +5 -0
- package/es/Modal/useModal.js +51 -0
- package/es/Modal/warning.d.ts +5 -0
- package/es/Modal/warning.js +43 -0
- package/es/{Popconfirm.d.ts → Popconfirm/index.d.ts} +2 -2
- package/es/Popconfirm/index.js +62 -0
- package/es/{Popover.d.ts → Popover/index.d.ts} +2 -2
- package/es/{Popover.js → Popover/index.js} +7 -12
- package/es/Progress/Circle.d.ts +16 -0
- package/es/Progress/Circle.js +122 -0
- package/es/Progress/index.d.ts +6 -4
- package/es/Progress/index.js +75 -60
- package/es/Radio/Button.d.ts +7 -0
- package/es/Radio/Button.js +72 -0
- package/es/Radio/Group.d.ts +18 -0
- package/es/Radio/Group.js +57 -0
- package/es/Radio/index.d.ts +14 -0
- package/es/Radio/index.js +68 -0
- package/es/RangeInput/index.d.ts +23 -0
- package/es/RangeInput/index.js +208 -0
- package/es/Result/index.js +49 -0
- package/es/Segmented/index.d.ts +10 -7
- package/es/Segmented/index.js +54 -53
- package/es/Select/index.d.ts +17 -0
- package/es/Select/index.js +75 -0
- package/es/SelectInput/index.d.ts +39 -0
- package/es/SelectInput/index.js +245 -0
- package/es/Slider/index.d.ts +47 -0
- package/es/Slider/index.js +177 -0
- package/es/Space/index.d.ts +13 -0
- package/es/Space/index.js +16 -0
- package/es/Spin/index.d.ts +19 -0
- package/es/Spin/index.js +82 -0
- package/es/{Switch.d.ts → Switch/index.d.ts} +9 -0
- package/es/Switch/index.js +41 -0
- package/es/{Table.d.ts → Table/index.d.ts} +6 -2
- package/es/Table/index.js +71 -0
- package/es/Tabs/index.d.ts +49 -0
- package/es/Tabs/index.js +256 -0
- package/es/Timeline/index.js +31 -0
- package/es/Tooltip/context.d.ts +5 -0
- package/es/Tooltip/context.js +5 -0
- package/es/Tooltip/index.d.ts +64 -0
- package/es/Tooltip/index.js +499 -0
- package/es/Transformer/index.d.ts +88 -0
- package/es/Transformer/index.js +882 -0
- package/es/Tree/SingleLevelTree.d.ts +28 -0
- package/es/Tree/SingleLevelTree.js +299 -0
- package/es/Tree/index.d.ts +83 -0
- package/es/Tree/index.js +197 -0
- package/es/TreeFor/index.d.ts +31 -0
- package/es/TreeFor/index.js +80 -0
- package/es/TreeSelect/index.d.ts +26 -0
- package/es/TreeSelect/index.js +98 -0
- package/es/Upload/index.d.ts +64 -0
- package/es/Upload/index.js +112 -0
- package/es/assets/svg/ColorPickUp.d.ts +4 -0
- package/es/assets/svg/ColorPickUp.js +25 -0
- package/es/assets/svg/Crosshair.d.ts +7 -0
- package/es/assets/svg/Crosshair.js +51 -0
- package/es/assets/svg/Resize.d.ts +4 -0
- package/es/assets/svg/Resize.js +25 -0
- package/es/assets/svg/Rotate.d.ts +4 -0
- package/es/assets/svg/Rotate.js +20 -0
- package/es/assets/svg/RotateArrow.d.ts +4 -0
- package/es/assets/svg/RotateArrow.js +21 -0
- package/es/assets/svg/common.d.ts +2 -0
- package/es/assets/svg/common.js +9 -0
- package/es/hooks/createControllableValue.d.ts +1 -1
- package/es/hooks/createControllableValue.js +16 -17
- package/es/hooks/createTransition.d.ts +6 -2
- package/es/hooks/createTransition.js +12 -8
- package/es/hooks/useClickAway.d.ts +1 -1
- package/es/hooks/useClickAway.js +4 -3
- package/es/hooks/useComponentSize.d.ts +3 -0
- package/es/hooks/useComponentSize.js +12 -0
- package/es/hooks/useCounter.d.ts +12 -0
- package/es/hooks/useCounter.js +30 -0
- package/es/hooks/useFocus.d.ts +2 -0
- package/es/hooks/useFocus.js +24 -0
- package/es/hooks/useHover.d.ts +2 -0
- package/es/hooks/useHover.js +33 -0
- package/es/hooks/useLocale.d.ts +1 -0
- package/es/hooks/useLocale.js +11 -0
- package/es/hooks/useMouse.d.ts +1 -0
- package/es/hooks/useMouse.js +18 -0
- package/es/hooks/useScroll.d.ts +2 -0
- package/es/hooks/useScroll.js +29 -0
- package/es/hooks/useSize.d.ts +8 -2
- package/es/hooks/useSize.js +25 -13
- package/es/hooks/useVirtualList.d.ts +14 -0
- package/es/hooks/useVirtualList.js +45 -0
- package/es/index.d.ts +59 -8
- package/es/index.js +53 -23
- package/es/locale/en_US.d.ts +3 -0
- package/es/locale/en_US.js +9 -0
- package/es/locale/index.d.ts +5 -0
- package/es/locale/index.js +1 -0
- package/es/locale/zh_CN.d.ts +3 -0
- package/es/locale/zh_CN.js +9 -0
- package/es/types/index.d.ts +11 -2
- package/es/utils/animation.d.ts +6 -0
- package/es/utils/animation.js +20 -0
- package/es/utils/array.d.ts +2 -1
- package/es/utils/array.js +5 -1
- package/es/utils/domPoint.d.ts +7 -0
- package/es/utils/domPoint.js +11 -0
- package/es/utils/math.d.ts +17 -0
- package/es/utils/math.js +25 -0
- package/es/utils/number.d.ts +1 -0
- package/es/utils/number.js +14 -0
- package/es/utils/setupGlobalDrag.d.ts +10 -0
- package/es/utils/setupGlobalDrag.js +38 -0
- package/es/utils/solid.d.ts +2 -2
- package/es/utils/solid.js +7 -8
- package/package.json +10 -11
- package/es/Button.d.ts +0 -19
- package/es/Button.js +0 -73
- package/es/ColorPicker.d.ts +0 -8
- package/es/ColorPicker.js +0 -6
- package/es/Compact.d.ts +0 -12
- package/es/Compact.js +0 -17
- package/es/DatePicker.d.ts +0 -19
- package/es/DatePicker.js +0 -9
- package/es/Image.d.ts +0 -9
- package/es/Image.js +0 -22
- package/es/Input.d.ts +0 -29
- package/es/Input.js +0 -144
- package/es/InputNumber.d.ts +0 -11
- package/es/InputNumber.js +0 -92
- package/es/Modal.d.ts +0 -48
- package/es/Modal.js +0 -209
- package/es/Popconfirm.js +0 -64
- package/es/Radio.d.ts +0 -27
- package/es/Radio.js +0 -93
- package/es/Result.js +0 -29
- package/es/Select.d.ts +0 -16
- package/es/Select.js +0 -113
- package/es/Skeleton.d.ts +0 -9
- package/es/Skeleton.js +0 -9
- package/es/Spin.d.ts +0 -9
- package/es/Spin.js +0 -22
- package/es/Switch.js +0 -30
- package/es/Table.js +0 -57
- package/es/Tabs.d.ts +0 -17
- package/es/Tabs.js +0 -117
- package/es/Timeline.js +0 -30
- package/es/Tooltip.d.ts +0 -34
- package/es/Tooltip.js +0 -302
- package/es/Tree.d.ts +0 -28
- package/es/Tree.js +0 -198
- package/es/Upload.d.ts +0 -11
- package/es/Upload.js +0 -6
- package/es/hooks/createUpdateEffect.d.ts +0 -5
- package/es/hooks/createUpdateEffect.js +0 -12
- package/es/utils/EventEmitter.d.ts +0 -7
- package/es/utils/EventEmitter.js +0 -13
- package/es/utils/ReactToSolid.d.ts +0 -8
- package/es/utils/ReactToSolid.js +0 -30
- package/es/utils/SolidToReact.d.ts +0 -8
- package/es/utils/SolidToReact.js +0 -23
- package/es/utils/component.d.ts +0 -31
- package/es/utils/component.js +0 -68
- package/es/utils/zh_CN.d.ts +0 -2
- package/es/utils/zh_CN.js +0 -236
- package/src/Button.tsx +0 -128
- package/src/Collapse/index.tsx +0 -86
- package/src/ColorPicker.tsx +0 -11
- package/src/Compact.tsx +0 -15
- package/src/DatePicker.tsx +0 -30
- package/src/Drawer/index.scss +0 -53
- package/src/Drawer/index.tsx +0 -212
- package/src/Empty/PRESENTED_IMAGE_SIMPLE.tsx +0 -15
- package/src/Empty/assets/EmptySvg.tsx +0 -43
- package/src/Empty/assets/SimpleEmptySvg.tsx +0 -16
- package/src/Empty/index.tsx +0 -20
- package/src/Form/Form.tsx +0 -94
- package/src/Form/FormItem.tsx +0 -141
- package/src/Form/context.ts +0 -16
- package/src/Form/index.ts +0 -13
- package/src/Image.tsx +0 -29
- package/src/Input.tsx +0 -202
- package/src/InputNumber.test.tsx +0 -46
- package/src/InputNumber.tsx +0 -125
- package/src/Modal.tsx +0 -220
- package/src/Popconfirm.tsx +0 -75
- package/src/Popover.tsx +0 -30
- package/src/Progress/index.tsx +0 -73
- package/src/Radio.tsx +0 -142
- package/src/Result.tsx +0 -38
- package/src/Segmented/index.tsx +0 -95
- package/src/Select.tsx +0 -128
- package/src/Skeleton.tsx +0 -14
- package/src/Spin.tsx +0 -23
- package/src/Switch.tsx +0 -34
- package/src/Table.tsx +0 -53
- package/src/Tabs.tsx +0 -131
- package/src/Timeline.tsx +0 -33
- package/src/Tooltip.tsx +0 -340
- package/src/Tree.tsx +0 -246
- package/src/Upload.tsx +0 -10
- package/src/hooks/createControllableValue.ts +0 -68
- package/src/hooks/createTransition.ts +0 -52
- 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.ts +0 -47
- package/src/types/index.ts +0 -5
- package/src/utils/EventEmitter.ts +0 -15
- 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 -61
- package/src/utils/zh_CN.ts +0 -236
- /package/es/{InputNumber.test.d.ts → InputNumber/index.test.d.ts} +0 -0
- /package/es/{Result.d.ts → Result/index.d.ts} +0 -0
- /package/es/{Timeline.d.ts → Timeline/index.d.ts} +0 -0
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 hover:ant-bg-[var(--hover-bg-color)] 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: setSelectedNodes as unknown as Setter<Array<{}>>,
|
|
219
|
-
draggableNode,
|
|
220
|
-
setDraggableNode: setDraggableNode as unknown as Setter<{} | null>,
|
|
221
|
-
draggableIndexes,
|
|
222
|
-
setDraggableIndexes,
|
|
223
|
-
isDraggable,
|
|
224
|
-
targetNode,
|
|
225
|
-
setTargetNode: setTargetNode as unknown as Setter<{} | null>,
|
|
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,68 +0,0 @@
|
|
|
1
|
-
import { type 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 | null
|
|
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
|
-
_setValue(getValue() as any)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const setValue = (v: ((prev: T) => T) | T | undefined) => {
|
|
49
|
-
const newValue = typeof v === 'function' ? (v as (prev: T) => T)(value()!) : v
|
|
50
|
-
|
|
51
|
-
if (!isControlled()) {
|
|
52
|
-
_setValue(newValue as any)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (trigger) {
|
|
56
|
-
const onChange = props[trigger]
|
|
57
|
-
if (typeof onChange === 'function') {
|
|
58
|
-
onChange(newValue)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return newValue
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return [value, setValue] as Signal<T>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default createControllableValue
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createEffect, type Accessor, on } from 'solid-js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* dom 节点显示或隐藏时的动画
|
|
5
|
-
* @param target
|
|
6
|
-
* @param when
|
|
7
|
-
* @param className 动画类名
|
|
8
|
-
*/
|
|
9
|
-
export default function createTransition(
|
|
10
|
-
target: Accessor<HTMLElement | undefined | null>,
|
|
11
|
-
when: Accessor<boolean>,
|
|
12
|
-
className: string,
|
|
13
|
-
) {
|
|
14
|
-
createEffect(
|
|
15
|
-
on(when, input => {
|
|
16
|
-
const targetValue = target()
|
|
17
|
-
if (!targetValue) return
|
|
18
|
-
|
|
19
|
-
if (input) {
|
|
20
|
-
targetValue.style.display = ''
|
|
21
|
-
targetValue.classList.add(
|
|
22
|
-
`${className}-enter-active`,
|
|
23
|
-
`${className}-enter`,
|
|
24
|
-
`${className}-enter-to`,
|
|
25
|
-
)
|
|
26
|
-
requestAnimationFrame(() => {
|
|
27
|
-
targetValue!.classList.remove(`${className}-enter`)
|
|
28
|
-
})
|
|
29
|
-
const onTransitionEnd = () => {
|
|
30
|
-
targetValue!.classList.remove(`${className}-enter-active`, `${className}-enter-to`)
|
|
31
|
-
targetValue!.removeEventListener('transitionend', onTransitionEnd)
|
|
32
|
-
}
|
|
33
|
-
targetValue.addEventListener('transitionend', onTransitionEnd)
|
|
34
|
-
} else {
|
|
35
|
-
targetValue.classList.add(
|
|
36
|
-
`${className}-exit-active`,
|
|
37
|
-
`${className}-exit`,
|
|
38
|
-
`${className}-exit-to`,
|
|
39
|
-
)
|
|
40
|
-
requestAnimationFrame(() => {
|
|
41
|
-
targetValue!.classList.remove(`${className}-exit`)
|
|
42
|
-
})
|
|
43
|
-
const onTransitionEnd = () => {
|
|
44
|
-
targetValue!.style.display = 'none'
|
|
45
|
-
targetValue!.classList.remove(`${className}-exit-active`, `${className}-exit-to`)
|
|
46
|
-
targetValue!.removeEventListener('transitionend', onTransitionEnd)
|
|
47
|
-
}
|
|
48
|
-
targetValue.addEventListener('transitionend', onTransitionEnd)
|
|
49
|
-
}
|
|
50
|
-
}),
|
|
51
|
-
)
|
|
52
|
-
}
|
|
@@ -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.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export { default as Button } from './Button'
|
|
2
|
-
export { default as Input } from './Input'
|
|
3
|
-
export type { InputProps } from './Input'
|
|
4
|
-
export { default as InputNumber } from './InputNumber'
|
|
5
|
-
export type { InputNumberProps } from './InputNumber'
|
|
6
|
-
export { default as Timeline } from './Timeline'
|
|
7
|
-
export { default as Modal } from './Modal'
|
|
8
|
-
export type { ModalInstance } from './Modal'
|
|
9
|
-
export { default as Drawer } from './Drawer'
|
|
10
|
-
export type { DrawerProps, DrawerInstance } from './Drawer'
|
|
11
|
-
export { default as DatePicker } from './DatePicker'
|
|
12
|
-
export { default as Select } from './Select'
|
|
13
|
-
export { default as Tree } from './Tree'
|
|
14
|
-
export type { TreeProps } from './Tree'
|
|
15
|
-
export { default as Popover } from './Popover'
|
|
16
|
-
export { default as Tooltip } from './Tooltip'
|
|
17
|
-
export { default as ColorPicker } from './ColorPicker'
|
|
18
|
-
export type { ColorPickerProps } from './ColorPicker'
|
|
19
|
-
export { default as Result } from './Result'
|
|
20
|
-
export { default as Progress } from './Progress'
|
|
21
|
-
export type { ProgressProps } from './Progress'
|
|
22
|
-
export { default as Tabs } from './Tabs'
|
|
23
|
-
export type { TabsProps, Tab } from './Tabs'
|
|
24
|
-
export { default as Popconfirm } from './Popconfirm'
|
|
25
|
-
export { default as Upload } from './Upload'
|
|
26
|
-
export type { UploadProps, UploadFile } from './Upload'
|
|
27
|
-
export { default as Radio } from './Radio'
|
|
28
|
-
export type { RadioProps, RadioGroupProps } from './Radio'
|
|
29
|
-
export { default as Form } from './Form'
|
|
30
|
-
export type { FormInstance, FormProps, FormItemProps, FormItemComponentProps } from './Form'
|
|
31
|
-
export { default as Switch } from './Switch'
|
|
32
|
-
export type { SwitchProps } from './Switch'
|
|
33
|
-
export { default as Skeleton } from './Skeleton'
|
|
34
|
-
export { default as Spin } from './Spin'
|
|
35
|
-
export { default as Image } from './Image'
|
|
36
|
-
export { default as Table } from './Table'
|
|
37
|
-
export type { TableProps, TableColumn } from './Table'
|
|
38
|
-
export { default as Compact } from './Compact'
|
|
39
|
-
export type { CollapseProps, CollapseItem } from './Collapse'
|
|
40
|
-
export { default as Collapse } from './Collapse'
|
|
41
|
-
export { default as Empty } from './Empty'
|
|
42
|
-
export type { SegmentedProps } from './Segmented'
|
|
43
|
-
export { default as Segmented } from './Segmented'
|
|
44
|
-
|
|
45
|
-
export { default as createControllableValue } from './hooks/createControllableValue'
|
|
46
|
-
|
|
47
|
-
export { message } from 'antd'
|
package/src/types/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type Subscription<T> = (val: T) => void
|
|
2
|
-
|
|
3
|
-
export default class EventEmitter<T> {
|
|
4
|
-
private readonly subscriptions = new Set<Subscription<T>>()
|
|
5
|
-
|
|
6
|
-
emit = (val: T) => {
|
|
7
|
-
for (const subscription of this.subscriptions) {
|
|
8
|
-
subscription(val)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
subscription = (callback: Subscription<T>) => {
|
|
13
|
-
this.subscriptions.add(callback)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -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
|
package/src/utils/array.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 如果传入一个非数组字段,则将其转化为数组
|
|
3
|
-
* @param value
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
|
-
export function toArray<T>(value: T | T[]) {
|
|
7
|
-
return Array.isArray(value) ? value : [value]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface StandardNode {
|
|
11
|
-
children?: this[]
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 将数组中每个对象的 children 拍扁后返回
|
|
15
|
-
* @param nodes
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
export function flatChildren<T extends StandardNode = StandardNode>(nodes: T[] | undefined): T[] {
|
|
19
|
-
if (!nodes) return []
|
|
20
|
-
return nodes.flatMap(node => [node, ...flatChildren(node.children)])
|
|
21
|
-
}
|
package/src/utils/component.tsx
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { type Component, createMemo, type JSXElement } from 'solid-js'
|
|
3
|
-
import { omit } from 'lodash-es'
|
|
4
|
-
import { solidToReact } from './solid'
|
|
5
|
-
import ReactToSolid from './ReactToSolid'
|
|
6
|
-
import { ConfigProvider } from 'antd'
|
|
7
|
-
import zhCN from './zh_CN'
|
|
8
|
-
import { type ConfigProviderProps } from 'antd/es/config-provider'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 将组件 props 中的 className 替换为 class
|
|
12
|
-
* @param C
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export function replaceClassName<
|
|
16
|
-
T extends { className?: string },
|
|
17
|
-
Target extends Omit<T, 'className'> & { class?: string },
|
|
18
|
-
>(C: Component<T>): Component<Target> {
|
|
19
|
-
return function (_props: Target) {
|
|
20
|
-
const props = createMemo(() => {
|
|
21
|
-
return {
|
|
22
|
-
...omit(_props, 'class'),
|
|
23
|
-
className: _props.class,
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
return <C {...(props() as unknown as T)} />
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 将组件 props 中的 children 替换为 JSXElement
|
|
32
|
-
* @param C
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
export function replaceChildren<
|
|
36
|
-
T extends { children?: React.ReactNode },
|
|
37
|
-
Target extends Omit<T, 'children'> & { children?: JSXElement },
|
|
38
|
-
>(C: Component<T>): Component<Target> {
|
|
39
|
-
return function (_props: Target) {
|
|
40
|
-
const props = createMemo(() => {
|
|
41
|
-
return {
|
|
42
|
-
..._props,
|
|
43
|
-
children: solidToReact(_props.children),
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
return <C {...(props() as unknown as T)} />
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function reactToSolidComponent<P extends {} = {}>(
|
|
51
|
-
component: React.FunctionComponent<P> | React.ComponentClass<P>,
|
|
52
|
-
container?: Element | (() => Element),
|
|
53
|
-
) {
|
|
54
|
-
return function (props: P) {
|
|
55
|
-
return (
|
|
56
|
-
<ReactToSolid
|
|
57
|
-
component={component}
|
|
58
|
-
props={props}
|
|
59
|
-
container={typeof container === 'function' ? container() : container}
|
|
60
|
-
/>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 返回被 ConfigProvider 包裹后的 component
|
|
67
|
-
* @param component
|
|
68
|
-
* @param configProviderProps
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
export function configProvider<P extends {} = {}>(
|
|
72
|
-
component: React.FunctionComponent<P> | React.ComponentClass<P>,
|
|
73
|
-
configProviderProps?: ConfigProviderProps,
|
|
74
|
-
) {
|
|
75
|
-
return function (props: P) {
|
|
76
|
-
return React.createElement(
|
|
77
|
-
ConfigProvider,
|
|
78
|
-
{
|
|
79
|
-
locale: zhCN,
|
|
80
|
-
...configProviderProps,
|
|
81
|
-
},
|
|
82
|
-
React.createElement(component, props),
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
}
|