@rainte/ant 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.editorconfig +9 -0
  2. package/.fatherrc.ts +15 -0
  3. package/.gitattributes +1 -0
  4. package/.prettierignore +7 -0
  5. package/.prettierrc +13 -0
  6. package/.umirc.ts +24 -0
  7. package/LICENSE +21 -0
  8. package/README.md +27 -0
  9. package/docs/index.md +9 -0
  10. package/es/components/Editor/index.d.ts +8 -0
  11. package/es/components/Editor/index.js +35 -0
  12. package/es/components/Editor/props.d.ts +13 -0
  13. package/es/components/Editor/props.js +12 -0
  14. package/es/components/Form/index.d.ts +8 -0
  15. package/es/components/Form/index.js +53 -0
  16. package/es/components/Image/index.d.ts +5 -0
  17. package/es/components/Image/index.js +14 -0
  18. package/es/components/Table/index.d.ts +9 -0
  19. package/es/components/Table/index.js +35 -0
  20. package/es/components/Tabs/index.d.ts +9 -0
  21. package/es/components/Tabs/index.js +22 -0
  22. package/es/components/ValueType/components/Cascader.d.ts +3 -0
  23. package/es/components/ValueType/components/Cascader.js +89 -0
  24. package/es/components/ValueType/components/Editor.d.ts +3 -0
  25. package/es/components/ValueType/components/Editor.js +18 -0
  26. package/es/components/ValueType/components/TreeSelect.d.ts +3 -0
  27. package/es/components/ValueType/components/TreeSelect.js +87 -0
  28. package/es/components/ValueType/components/Upload.d.ts +4 -0
  29. package/es/components/ValueType/components/Upload.js +73 -0
  30. package/es/components/ValueType/index.d.ts +15 -0
  31. package/es/components/ValueType/index.js +10 -0
  32. package/es/index.d.ts +11 -0
  33. package/es/index.js +6 -0
  34. package/es/utils/Swr.d.ts +1 -0
  35. package/es/utils/Swr.js +58 -0
  36. package/es/utils/Tree.d.ts +2 -0
  37. package/es/utils/Tree.js +65 -0
  38. package/lib/components/Editor/index.d.ts +8 -0
  39. package/lib/components/Editor/index.js +43 -0
  40. package/lib/components/Editor/props.d.ts +13 -0
  41. package/lib/components/Editor/props.js +19 -0
  42. package/lib/components/Form/index.d.ts +8 -0
  43. package/lib/components/Form/index.js +64 -0
  44. package/lib/components/Image/index.d.ts +5 -0
  45. package/lib/components/Image/index.js +22 -0
  46. package/lib/components/Table/index.d.ts +9 -0
  47. package/lib/components/Table/index.js +46 -0
  48. package/lib/components/Tabs/index.d.ts +9 -0
  49. package/lib/components/Tabs/index.js +30 -0
  50. package/lib/components/ValueType/components/Cascader.d.ts +3 -0
  51. package/lib/components/ValueType/components/Cascader.js +97 -0
  52. package/lib/components/ValueType/components/Editor.d.ts +3 -0
  53. package/lib/components/ValueType/components/Editor.js +26 -0
  54. package/lib/components/ValueType/components/TreeSelect.d.ts +3 -0
  55. package/lib/components/ValueType/components/TreeSelect.js +95 -0
  56. package/lib/components/ValueType/components/Upload.d.ts +4 -0
  57. package/lib/components/ValueType/components/Upload.js +82 -0
  58. package/lib/components/ValueType/index.d.ts +15 -0
  59. package/lib/components/ValueType/index.js +18 -0
  60. package/lib/index.d.ts +11 -0
  61. package/lib/index.js +41 -0
  62. package/lib/utils/Swr.d.ts +1 -0
  63. package/lib/utils/Swr.js +66 -0
  64. package/lib/utils/Tree.d.ts +2 -0
  65. package/lib/utils/Tree.js +73 -0
  66. package/package.json +52 -0
  67. package/src/components/Editor/index.md +8 -0
  68. package/src/components/Editor/index.tsx +20 -0
  69. package/src/components/Editor/props.ts +50 -0
  70. package/src/components/Form/index.md +132 -0
  71. package/src/components/Form/index.tsx +48 -0
  72. package/src/components/Image/index.md +8 -0
  73. package/src/components/Image/index.tsx +16 -0
  74. package/src/components/Table/index.md +80 -0
  75. package/src/components/Table/index.tsx +45 -0
  76. package/src/components/Tabs/index.md +24 -0
  77. package/src/components/Tabs/index.tsx +21 -0
  78. package/src/components/ValueType/components/Cascader.tsx +79 -0
  79. package/src/components/ValueType/components/Editor.tsx +18 -0
  80. package/src/components/ValueType/components/TreeSelect.tsx +74 -0
  81. package/src/components/ValueType/components/Upload.tsx +74 -0
  82. package/src/components/ValueType/index.ts +33 -0
  83. package/src/index.ts +12 -0
  84. package/src/utils/Swr.ts +29 -0
  85. package/src/utils/Tree.ts +51 -0
  86. package/tsconfig.json +31 -0
  87. package/typings.d.ts +4 -0
@@ -0,0 +1,74 @@
1
+ import React from 'react'
2
+ import {
3
+ Button,
4
+ Space,
5
+ Upload as AntUpload,
6
+ UploadProps,
7
+ Typography,
8
+ } from 'antd'
9
+ import { PlusOutlined, UploadOutlined } from '@ant-design/icons'
10
+ import { RenderProps, FieldProps } from '../index'
11
+
12
+ export const files = (e: any) => (Array.isArray(e) ? e : e && e.fileList)
13
+
14
+ const links = (text: any[], dom: any) => {
15
+ return text.map((item: any) => {
16
+ if (item && item.url) {
17
+ return (
18
+ <Typography.Link href={item.url} target="_blank" key={item.url}>
19
+ {item.url}
20
+ </Typography.Link>
21
+ )
22
+ }
23
+
24
+ return dom
25
+ })
26
+ }
27
+
28
+ const Upload: React.FC<UploadProps & { value?: any }> = props => {
29
+ const { value, ...attrs } = props
30
+ const fileList = files(value)
31
+ const length = Array.isArray(fileList) ? fileList.length : 0
32
+ const max = attrs.maxCount ?? 1
33
+
34
+ let button
35
+ if (length < max) {
36
+ if (props.listType === 'picture-card') {
37
+ button = <PlusOutlined />
38
+ } else {
39
+ button = <Button icon={<UploadOutlined />}>上传</Button>
40
+ }
41
+ }
42
+
43
+ return (
44
+ <AntUpload {...attrs} fileList={fileList}>
45
+ {button}
46
+ </AntUpload>
47
+ )
48
+ }
49
+
50
+ const Render: RenderProps = {
51
+ name: 'upload',
52
+ render: (text, props, dom) => {
53
+ const value = files(text)
54
+
55
+ if (Array.isArray(value) && value.length) {
56
+ return <Space>{links(value, dom)}</Space>
57
+ }
58
+
59
+ return <>{dom}</>
60
+ },
61
+ renderFormItem: (_, props: FieldProps) => {
62
+ return <Upload {...props.fieldProps} />
63
+ },
64
+ }
65
+
66
+ export default Render
67
+
68
+ Upload.defaultProps = {
69
+ listType: 'picture-card',
70
+ value: [],
71
+ maxCount: 1,
72
+ multiple: true,
73
+ showUploadList: true,
74
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ ProRenderFieldPropsType,
3
+ ProFieldFCRenderProps,
4
+ } from '@ant-design/pro-provider'
5
+
6
+ import Cascader from './components/Cascader'
7
+ import Editor from './components/Editor'
8
+ import TreeSelect from './components/TreeSelect'
9
+ import Upload from './components/Upload'
10
+
11
+ export type RenderProps = ProRenderFieldPropsType & { name: string }
12
+ export type FieldProps = ProFieldFCRenderProps & {
13
+ params?: any
14
+ request?: <T = any>(params: T, props: any) => Promise<any>
15
+ }
16
+ export type RequestProps = {
17
+ iParams?: any
18
+ iRequest?: <T = any>(params: T, props: any) => Promise<any>
19
+ }
20
+ export type ValueTypeEnum =
21
+ | 'text'
22
+ | 'cascader'
23
+ | 'editor'
24
+ | 'treeSelect'
25
+ | 'upload'
26
+
27
+ const modules = [Cascader, Editor, TreeSelect, Upload]
28
+ const ValueTypeMap: Record<string, ProRenderFieldPropsType> = {}
29
+ modules.forEach((module: any) => {
30
+ ValueTypeMap[module.name] = module as ProRenderFieldPropsType
31
+ })
32
+
33
+ export default ValueTypeMap
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /// <reference path="../typings.d.ts" />
2
+
3
+ export { default as Editor } from './components/Editor'
4
+ export type { EditorProps } from './components/Editor'
5
+ export { default as Form } from './components/Form'
6
+ export type { FormProps } from './components/Form'
7
+ export { default as Image } from './components/Image'
8
+ export type { ImageProps } from './components/Image'
9
+ export { default as Table } from './components/Table'
10
+ export type { TableProps } from './components/Table'
11
+ export { default as Tabs } from './components/Tabs'
12
+ export type { TabsProps } from './components/Tabs'
@@ -0,0 +1,29 @@
1
+ import { useMemo } from 'react'
2
+ import { v4 as uuid } from 'uuid'
3
+ import useSWR from 'swr'
4
+
5
+ const key = (request: any, params: any) => {
6
+ return useMemo(() => {
7
+ if (!request) {
8
+ return 'no-fetch'
9
+ }
10
+
11
+ if (!params) {
12
+ return uuid()
13
+ }
14
+
15
+ return JSON.stringify(params)
16
+ }, [params, request])
17
+ }
18
+
19
+ export const fetch = (request: any, params: any, props: any) => {
20
+ const fetcher = async () => (request ? await request(params, props) : [])
21
+
22
+ const { data } = useSWR(key(request, params), fetcher, {
23
+ revalidateOnFocus: false,
24
+ shouldRetryOnError: false,
25
+ revalidateOnReconnect: false,
26
+ })
27
+
28
+ return data
29
+ }
@@ -0,0 +1,51 @@
1
+ export const equal: any = (rows: any[], props: Record<string, any>) => {
2
+ for (const row of rows) {
3
+ let flag = true
4
+
5
+ for (const key in props) {
6
+ if (props[key] !== row[key]) {
7
+ flag = false
8
+ break
9
+ }
10
+ }
11
+
12
+ if (flag) {
13
+ return row
14
+ }
15
+
16
+ if (row.children) {
17
+ const node = equal(row.children, props)
18
+ if (node) {
19
+ return node
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ export const intact = (
26
+ rows: any[],
27
+ equal: Record<string, any>,
28
+ prop: string,
29
+ ) => {
30
+ for (const row of rows) {
31
+ let flag = true
32
+
33
+ for (const key in equal) {
34
+ if (equal[key] !== row[key]) {
35
+ flag = false
36
+ break
37
+ }
38
+ }
39
+
40
+ if (!flag && row.children) {
41
+ const sonids: any = intact(row.children, equal, prop)
42
+ if (sonids && Array.isArray(sonids)) {
43
+ return [row[prop], ...sonids]
44
+ }
45
+ }
46
+
47
+ if (flag) {
48
+ return [row[prop]]
49
+ }
50
+ }
51
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "baseUrl": "./",
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "importHelpers": true,
8
+ "jsx": "react",
9
+ "module": "esnext",
10
+ "moduleResolution": "node",
11
+ "skipLibCheck": true,
12
+ "sourceMap": true,
13
+ "strict": true,
14
+ "target": "esnext",
15
+ "paths": {
16
+ "@/*": ["src/*"],
17
+ "@@/*": ["src/.umi/*"]
18
+ }
19
+ },
20
+ "exclude": [
21
+ "node_modules",
22
+ "lib",
23
+ "es",
24
+ "dist",
25
+ "typings",
26
+ "**/__test__",
27
+ "test",
28
+ "docs",
29
+ "tests"
30
+ ]
31
+ }
package/typings.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module '*.css'
2
+ declare module '*.less'
3
+ declare module 'uuid'
4
+ declare module 'braft-extensions/dist/*'