react-toolkits 0.1.0 → 0.1.2

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 (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.css +1 -251
  3. package/dist/index.css.map +1 -1
  4. package/dist/index.d.mts +1 -1
  5. package/dist/index.esm.js +14 -3569
  6. package/dist/index.esm.js.map +1 -1
  7. package/package.json +11 -5
  8. package/.eslintignore +0 -2
  9. package/.eslintrc.js +0 -4
  10. package/.turbo/turbo-build.log +0 -20
  11. package/postcss.config.js +0 -9
  12. package/src/assets/512_orange_nobackground.png +0 -0
  13. package/src/components/DynamicTags/index.tsx +0 -160
  14. package/src/components/FilterForm/index.tsx +0 -63
  15. package/src/components/FormModal/hooks.tsx +0 -47
  16. package/src/components/FormModal/index.tsx +0 -137
  17. package/src/components/GameSelect/index.tsx +0 -82
  18. package/src/components/Highlight/index.tsx +0 -51
  19. package/src/components/Layout/index.tsx +0 -90
  20. package/src/components/NavMenu/index.tsx +0 -142
  21. package/src/components/PermissionButton/index.tsx +0 -36
  22. package/src/components/QueryList/index.tsx +0 -152
  23. package/src/components/ReactToolkitsProvider/context.ts +0 -76
  24. package/src/components/ReactToolkitsProvider/index.tsx +0 -23
  25. package/src/components/UserWidget/index.tsx +0 -46
  26. package/src/components/index.ts +0 -51
  27. package/src/constants/index.ts +0 -1
  28. package/src/features/permission/components/PermissionCollapse/index.tsx +0 -121
  29. package/src/features/permission/components/PermissionList/index.tsx +0 -28
  30. package/src/features/permission/components/PermissionListV1/index.tsx +0 -42
  31. package/src/features/permission/components/PermissionListV2/index.tsx +0 -146
  32. package/src/features/permission/hooks/index.ts +0 -140
  33. package/src/features/permission/index.ts +0 -5
  34. package/src/features/permission/types/index.ts +0 -40
  35. package/src/hooks/index.ts +0 -2
  36. package/src/hooks/use-http-client.tsx +0 -85
  37. package/src/hooks/use-permission.tsx +0 -75
  38. package/src/index.ts +0 -7
  39. package/src/pages/base/Login/default.tsx +0 -864
  40. package/src/pages/base/Login/index.tsx +0 -101
  41. package/src/pages/base/NotFound/index.tsx +0 -27
  42. package/src/pages/base/index.tsx +0 -20
  43. package/src/pages/index.ts +0 -4
  44. package/src/pages/permission/RoleDetail/index.tsx +0 -40
  45. package/src/pages/permission/RoleList/index.tsx +0 -251
  46. package/src/pages/permission/UserList/index.tsx +0 -236
  47. package/src/pages/permission/index.tsx +0 -56
  48. package/src/shims.d.ts +0 -20
  49. package/src/stores/index.ts +0 -2
  50. package/src/stores/query-list.ts +0 -61
  51. package/src/stores/token.ts +0 -39
  52. package/src/styles/index.css +0 -5
  53. package/src/types/index.ts +0 -10
  54. package/tailwind.config.js +0 -5
  55. package/tsconfig.json +0 -11
  56. package/tsup.config.ts +0 -27
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "react-toolkits",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ],
7
7
  "module": "./dist/index.esm.js",
8
8
  "typings": "./dist/index.d.mts",
9
+ "files": [
10
+ "README.md",
11
+ "CHANGELOG.md",
12
+ "dist/"
13
+ ],
9
14
  "exports": {
10
15
  ".": "./dist/index.esm.js",
11
16
  "./style.css": "./dist/index.css"
@@ -30,7 +35,6 @@
30
35
  "dayjs": "^1.11.9",
31
36
  "jwt-decode": "^3.1.2",
32
37
  "lodash-es": "^4.17.21",
33
- "react-router-dom": "^6.14.2",
34
38
  "swr": "^2.2.0",
35
39
  "zustand": "^4.3.9"
36
40
  },
@@ -44,17 +48,19 @@
44
48
  "prettier": "^3.0.0",
45
49
  "react": "^18.2.0",
46
50
  "react-dom": "^18.2.0",
51
+ "react-router-dom": "^6.14.2",
47
52
  "tailwindcss": "^3.3.3",
48
53
  "ts-essentials": "^9.3.2",
49
54
  "tsup": "^7.1.0",
50
55
  "typescript": "^5.1.6",
51
- "@flow97/eslint-config-mono": "0.0.2",
52
56
  "tailwind-config": "0.0.1",
53
- "tsconfig": "0.0.1"
57
+ "tsconfig": "0.0.1",
58
+ "@flow97/eslint-config-mono": "0.0.2"
54
59
  },
55
60
  "peerDependencies": {
56
61
  "react": "^18.2.0",
57
- "react-dom": "^18.2.0"
62
+ "react-dom": "^18.2.0",
63
+ "react-router-dom": "^6.14.2"
58
64
  },
59
65
  "scripts": {
60
66
  "build": "tsup",
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- dist
2
- public
package/.eslintrc.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: [require.resolve('@flow97/eslint-config-mono/react')],
4
- }
@@ -1,20 +0,0 @@
1
-
2
- > react-toolkits@0.1.0 build /home/runner/work/everythingflow/everythingflow/packages/react-toolkits
3
- > tsup
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v7.1.0
8
- CLI Using tsup config: /home/runner/work/everythingflow/everythingflow/packages/react-toolkits/tsup.config.ts
9
- CLI Target: es6
10
- CLI Cleaning output folder
11
- ESM Build start
12
- DTS Build start
13
- ESM dist/512_orange_nobackground-L6MFCL6M.png 9.49 KB
14
- ESM dist/index.css 4.74 KB
15
- ESM dist/index.css.map 8.08 KB
16
- ESM dist/index.esm.js 139.24 KB
17
- ESM dist/index.esm.js.map 188.23 KB
18
- ESM ⚡️ Build success in 1656ms
19
- DTS ⚡️ Build success in 7161ms
20
- DTS dist/index.d.mts 8.72 KB
package/postcss.config.js DELETED
@@ -1,9 +0,0 @@
1
- // If you want to use other PostCSS plugins, see the following:
2
- // https://tailwindcss.com/docs/using-with-preprocessors
3
-
4
- module.exports = {
5
- plugins: {
6
- tailwindcss: {},
7
- autoprefixer: {},
8
- },
9
- }
@@ -1,160 +0,0 @@
1
- import { PlusOutlined } from '@ant-design/icons'
2
- import type { InputRef } from 'antd'
3
- import { Input, Space, Tag, theme } from 'antd'
4
- import type { FC } from 'react'
5
- import { useEffect, useRef, useState } from 'react'
6
-
7
- export interface DynamicTagsProps {
8
- initialTags?: string[]
9
- addable?: boolean
10
- removable?: boolean
11
- // 返回 Promise。如果返回 Promise.resolve(true),则添加; 如果返回 Promise.resolve(false) 或 Promise.reject,则不添加
12
- addCallback?: (addedTag: string) => Promise<boolean>
13
- // 返回 Promise。如果返回 Promise.resolve(true),则删除; 如果返回 Promise.resolve(false) 或 Promise.reject,则不删除
14
- removeCallback?: (removedTag: string) => Promise<boolean>
15
- }
16
-
17
- const DynamicTags: FC<DynamicTagsProps> = props => {
18
- const { initialTags, addable, removable, addCallback, removeCallback } = props
19
- const { token } = theme.useToken()
20
- const [tags, setTags] = useState<string[]>([])
21
- const [inputVisible, setInputVisible] = useState(false)
22
- const [inputValue, setInputValue] = useState('')
23
- const [editInputIndex, setEditInputIndex] = useState(-1)
24
- const [editInputValue, setEditInputValue] = useState<string>('')
25
- const inputRef = useRef<InputRef>(null)
26
- const editInputRef = useRef<InputRef>(null)
27
-
28
- useEffect(() => {
29
- setTags(initialTags ?? [])
30
- }, [initialTags])
31
-
32
- useEffect(() => {
33
- if (inputVisible) {
34
- inputRef.current?.focus()
35
- }
36
- }, [inputVisible])
37
-
38
- useEffect(() => {
39
- editInputRef.current?.focus()
40
- }, [inputValue])
41
-
42
- const handleClose = async (removedTag: string) => {
43
- const success = await removeCallback?.(removedTag)
44
-
45
- if (success) {
46
- const newTags = tags.filter(tag => tag !== removedTag)
47
- setTags(newTags)
48
- }
49
- }
50
-
51
- const showInput = () => {
52
- setInputVisible(true)
53
- }
54
-
55
- const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
56
- setInputValue(e.target.value)
57
- }
58
-
59
- const handleInputConfirm = async () => {
60
- if (inputValue && tags.indexOf(inputValue) === -1) {
61
- const success = await addCallback?.(inputValue)
62
-
63
- if (success) {
64
- setTags([...tags, inputValue])
65
- }
66
- }
67
-
68
- setInputVisible(false)
69
- setInputValue('')
70
- }
71
-
72
- const handleEditInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
73
- setEditInputValue(e.target.value)
74
- }
75
-
76
- const handleEditInputConfirm = () => {
77
- const newTags = [...tags]
78
- newTags[editInputIndex] = editInputValue
79
- setTags(newTags)
80
- setEditInputIndex(-1)
81
- setInputValue('')
82
- }
83
-
84
- const tagInputStyle: React.CSSProperties = {
85
- width: 78,
86
- verticalAlign: 'top',
87
- }
88
-
89
- const tagPlusStyle: React.CSSProperties = {
90
- background: token.colorBgContainer,
91
- borderStyle: 'dashed',
92
- }
93
-
94
- return (
95
- <Space wrap size={[0, 8]}>
96
- <Space wrap size={[0, 8]}>
97
- {tags.map((tag, index) => {
98
- if (editInputIndex === index) {
99
- return (
100
- <Input
101
- ref={editInputRef}
102
- key={tag}
103
- size="small"
104
- style={tagInputStyle}
105
- value={editInputValue}
106
- onChange={handleEditInputChange}
107
- onBlur={handleEditInputConfirm}
108
- onPressEnter={handleEditInputConfirm}
109
- />
110
- )
111
- }
112
-
113
- return (
114
- <Tag
115
- key={tag}
116
- closable={removable}
117
- style={{ userSelect: 'none' }}
118
- onClose={async e => {
119
- e.preventDefault()
120
- await handleClose(tag)
121
- }}
122
- >
123
- <span
124
- onDoubleClick={e => {
125
- if (index !== 0) {
126
- setEditInputIndex(index)
127
- setEditInputValue(tag)
128
- e.preventDefault()
129
- }
130
- }}
131
- >
132
- {tag}
133
- </span>
134
- </Tag>
135
- )
136
- })}
137
- </Space>
138
- {addable &&
139
- (inputVisible ? (
140
- <Input
141
- ref={inputRef}
142
- type="text"
143
- size="small"
144
- style={tagInputStyle}
145
- value={inputValue}
146
- onChange={handleInputChange}
147
- onBlur={handleInputConfirm}
148
- onPressEnter={handleInputConfirm}
149
- />
150
- ) : (
151
- <Tag style={tagPlusStyle} onClick={showInput}>
152
- <PlusOutlined />
153
- &nbsp;添加
154
- </Tag>
155
- ))}
156
- </Space>
157
- )
158
- }
159
-
160
- export default DynamicTags
@@ -1,63 +0,0 @@
1
- import type { FormInstance, FormProps } from 'antd'
2
- import { Button, Col, Form, Row, Space, theme } from 'antd'
3
- import type { PropsWithChildren } from 'react'
4
- import * as React from 'react'
5
-
6
- export interface FilterFormProps<Values>
7
- extends Pick<
8
- FormProps<Values>,
9
- | 'initialValues'
10
- | 'requiredMark'
11
- | 'onError'
12
- | 'onChange'
13
- | 'onValuesChange'
14
- | 'onFinish'
15
- | 'onFinishFailed'
16
- | 'layout'
17
- | 'labelCol'
18
- > {
19
- form?: FormInstance<Values>
20
- onReset?: () => void
21
- confirmText?: React.ReactNode
22
- }
23
-
24
- const FilterForm = <Values = unknown,>(props: PropsWithChildren<FilterFormProps<Values>>) => {
25
- const { children, confirmText, form, onReset, ...restProps } = props
26
- const { token } = theme.useToken()
27
-
28
- const formStyle = {
29
- maxWidth: 'none',
30
- background: token.colorFillAlter,
31
- borderWidth: token.lineWidth,
32
- borderStyle: token.lineType,
33
- borderColor: token.colorBorder,
34
- borderRadius: token.borderRadiusLG,
35
- padding: 24,
36
- marginBottom: 24,
37
- }
38
-
39
- return (
40
- <Form {...restProps} form={form} autoComplete="off">
41
- {children && (
42
- <div style={formStyle}>
43
- <Row gutter={18}>
44
- {children}
45
- <Col flex="auto" />
46
- <Col flex="auto" span={24} style={{ textAlign: 'right' }}>
47
- <Space>
48
- <Button type="primary" htmlType="submit">
49
- {confirmText || '查询'}
50
- </Button>
51
- <Button htmlType="reset" onClick={onReset}>
52
- 重置
53
- </Button>
54
- </Space>
55
- </Col>
56
- </Row>
57
- </div>
58
- )}
59
- </Form>
60
- )
61
- }
62
-
63
- export default FilterForm
@@ -1,47 +0,0 @@
1
- import type { FormModalProps, FormModalRef, RecursivePartial } from './index'
2
- import FormModal from './index'
3
- import { useCallback, useMemo, useRef, useState } from 'react'
4
- import type { Merge } from 'ts-essentials'
5
- import { createPortal } from 'react-dom'
6
-
7
- export type UseFormModalProps<T> = Merge<
8
- Omit<FormModalProps<T>, 'open' | 'onCancel' | 'closeFn' | 'children'>,
9
- {
10
- content: FormModalProps<T>['children']
11
- }
12
- >
13
-
14
- export function useFormModal<T extends object>(props: UseFormModalProps<T>) {
15
- const { content, onConfirm, ...restProps } = props
16
- const [open, setOpen] = useState(false)
17
- const [title, setTitle] = useState<FormModalProps<T>['title']>()
18
- const formRef = useRef<FormModalRef>(null)
19
-
20
- const showModal = (options?: { initialValues?: RecursivePartial<T>; title?: FormModalProps<T>['title'] }) => {
21
- setTitle(options?.title ?? restProps.title)
22
-
23
- if (options?.initialValues) {
24
- formRef.current?.setFieldsValue(options?.initialValues)
25
- }
26
-
27
- setOpen(true)
28
- }
29
-
30
- const closeModal = useCallback(() => {
31
- setOpen(false)
32
- }, [])
33
-
34
- const Modal = useMemo(() => {
35
- return (
36
- <FormModal ref={formRef} {...restProps} open={open} closeFn={closeModal} title={title} onConfirm={onConfirm}>
37
- {content}
38
- </FormModal>
39
- )
40
- }, [title, content, restProps, open, closeModal, onConfirm])
41
-
42
- return {
43
- Modal: createPortal(Modal, document.body),
44
- showModal,
45
- closeModal,
46
- }
47
- }
@@ -1,137 +0,0 @@
1
- import type { FormInstance, FormProps, ModalProps } from 'antd'
2
- import { Button, Form, Modal } from 'antd'
3
- import type { ForwardedRef, ReactElement } from 'react'
4
- import { forwardRef, useId, useImperativeHandle, useRef, useState } from 'react'
5
-
6
- type RenderChildren<T> = (props: {
7
- form: FormInstance<T>
8
- open?: boolean
9
- closeFn?: VoidFunction
10
- }) => JSX.Element | JSX.Element[]
11
-
12
- type ChildrenType<T> = RenderChildren<T> | JSX.Element | JSX.Element[]
13
-
14
- export type RecursivePartial<T> = T extends object
15
- ? {
16
- [P in keyof T]?: T[P] extends (infer U)[]
17
- ? RecursivePartial<U>[]
18
- : T[P] extends object
19
- ? RecursivePartial<T[P]>
20
- : T[P]
21
- }
22
- : unknown
23
-
24
- export interface FormModalProps<T>
25
- extends Pick<ModalProps, 'width' | 'title' | 'open' | 'afterClose' | 'bodyStyle' | 'maskClosable'>,
26
- Pick<FormProps, 'labelCol' | 'layout' | 'colon'> {
27
- children?: ChildrenType<T>
28
- footer?: ModalProps['footer']
29
- closeFn?: VoidFunction
30
- initialValues?: RecursivePartial<T>
31
- onConfirm?: (values: T) => Promise<void>
32
- }
33
-
34
- export interface FormModalRef<T = object> {
35
- setFieldsValue: (values: RecursivePartial<T>) => void
36
- }
37
-
38
- const InternalFormModal = <T extends object>(props: FormModalProps<T>, ref: ForwardedRef<FormModalRef<T>>) => {
39
- const {
40
- width,
41
- children,
42
- title,
43
- open,
44
- footer,
45
- layout,
46
- labelCol,
47
- bodyStyle,
48
- initialValues,
49
- maskClosable,
50
- closeFn,
51
- afterClose,
52
- onConfirm,
53
- } = props
54
- const id = useId()
55
- const [form] = Form.useForm<T>()
56
- const formRef = useRef<FormInstance<T>>(null)
57
- const isRenderProps = typeof children === 'function'
58
- const [confirmLoading, setConfirmLoading] = useState(false)
59
-
60
- useImperativeHandle(ref, () => {
61
- return {
62
- setFieldsValue(values) {
63
- formRef.current?.setFieldsValue(values)
64
- },
65
- }
66
- })
67
-
68
- return (
69
- <Modal
70
- destroyOnClose
71
- bodyStyle={bodyStyle}
72
- style={{ textAlign: 'start' }}
73
- width={width}
74
- open={open}
75
- title={title}
76
- forceRender={true}
77
- getContainer={false}
78
- maskClosable={maskClosable}
79
- footer={
80
- typeof footer === 'object'
81
- ? footer
82
- : [
83
- <Button
84
- key="cancel"
85
- onClick={() => {
86
- closeFn?.()
87
- }}
88
- >
89
- 取消
90
- </Button>,
91
- <Button form={id} key="submit" type="primary" htmlType="submit" loading={confirmLoading}>
92
- 确定
93
- </Button>,
94
- ]
95
- }
96
- afterClose={() => {
97
- afterClose?.()
98
- form.resetFields()
99
- }}
100
- onCancel={closeFn}
101
- >
102
- <Form
103
- form={form}
104
- ref={formRef}
105
- id={id}
106
- autoComplete="off"
107
- labelAlign="right"
108
- labelWrap={true}
109
- layout={layout}
110
- initialValues={initialValues}
111
- labelCol={
112
- labelCol || {
113
- flex: !layout || layout === 'horizontal' ? '120px' : '0',
114
- }
115
- }
116
- onFinish={async values => {
117
- try {
118
- setConfirmLoading(true)
119
- await onConfirm?.(values)
120
- closeFn?.()
121
- form.resetFields()
122
- } finally {
123
- setConfirmLoading(false)
124
- }
125
- }}
126
- >
127
- {isRenderProps ? children({ form, open, closeFn }) : children}
128
- </Form>
129
- </Modal>
130
- )
131
- }
132
-
133
- const FormModal = forwardRef(InternalFormModal) as <T extends object>(
134
- props: FormModalProps<T> & { ref?: ForwardedRef<FormModalRef<T>> },
135
- ) => ReactElement
136
-
137
- export default FormModal
@@ -1,82 +0,0 @@
1
- import { Select, Space, Typography } from 'antd'
2
- import { useCallback, useMemo } from 'react'
3
- import { useTokenStore } from '@/stores'
4
- import useSWRImmutable from 'swr/immutable'
5
- import { useReactToolkitsContext } from '@/components'
6
-
7
- const { Text } = Typography
8
-
9
- export interface GameType {
10
- id: string
11
- name: string
12
- area: 'cn' | 'global'
13
- Ctime: string
14
- }
15
-
16
- function useGames() {
17
- const { isPermissionV2, isGlobalNS } = useReactToolkitsContext(state => state)
18
- const user = useTokenStore(state => state.getUser())
19
-
20
- const { data, isLoading } = useSWRImmutable<GameType[]>(
21
- isPermissionV2 && !isGlobalNS && user
22
- ? {
23
- method: 'GET',
24
- url: '/api/usystem/game/all',
25
- params: { user: user.authorityId },
26
- headers: {
27
- 'App-ID': 'global',
28
- },
29
- }
30
- : null,
31
- )
32
-
33
- return {
34
- games: data,
35
- isLoading,
36
- }
37
- }
38
-
39
- const GameSelect = () => {
40
- const { game, setGame, isGlobalNS, isPermissionV2 } = useReactToolkitsContext(state => state)
41
- const { games, isLoading } = useGames()
42
-
43
- const options = useMemo(
44
- () =>
45
- games?.map(item => ({
46
- label: item.name,
47
- value: item.id,
48
- })),
49
- [games],
50
- )
51
-
52
- const onGameChange = useCallback(
53
- (id: string) => {
54
- const matchGame = (games ?? []).find(item => item.id === id) ?? null
55
- setGame(matchGame)
56
- // queryClient.clear()
57
- },
58
- [games, setGame],
59
- )
60
-
61
- if (!isPermissionV2 || isGlobalNS) {
62
- return null
63
- }
64
-
65
- return (
66
- <Space>
67
- <Text>当前游戏</Text>
68
- <Select
69
- showSearch
70
- optionFilterProp="label"
71
- value={game?.id}
72
- placeholder="请选择游戏"
73
- loading={isLoading}
74
- style={{ width: '200px' }}
75
- options={options}
76
- onChange={onGameChange}
77
- />
78
- </Space>
79
- )
80
- }
81
-
82
- export default GameSelect
@@ -1,51 +0,0 @@
1
- import type { PropsWithChildren, ReactNode } from 'react'
2
- import { useEffect, useState } from 'react'
3
- import { flushSync } from 'react-dom'
4
- import { createRoot } from 'react-dom/client'
5
-
6
- const splitByTags = (str: string) => {
7
- const regex = /(<[^>]*>)/
8
- return str.split(regex).filter(part => part !== '')
9
- }
10
-
11
- function renderToString(node: ReactNode): Promise<string> {
12
- const container = document.createElement('div')
13
- const root = createRoot(container)
14
-
15
- return new Promise(resolve => {
16
- setTimeout(() => {
17
- flushSync(() => {
18
- root.render(node)
19
- })
20
- resolve(container.innerHTML)
21
- })
22
- })
23
- }
24
-
25
- export interface HighlightTextsProps extends PropsWithChildren {
26
- texts: Array<string | number>
27
- }
28
-
29
- const Highlight = (props: HighlightTextsProps) => {
30
- const { texts, children } = props
31
- const [htmlString, setHtmlString] = useState<string>('')
32
-
33
- useEffect(() => {
34
- renderToString(children).then(str => {
35
- const result = splitByTags(str)
36
-
37
- for (const text of texts) {
38
- for (let index = 0; index < result.length; index++) {
39
- // TODO: 忽略 HTML tag
40
- result[index] = result[index].replace(String(text), `<span style='color: #DC143C;'>${text}</span>`)
41
- }
42
- }
43
-
44
- setHtmlString(result.join(''))
45
- })
46
- }, [children, texts])
47
-
48
- return <p dangerouslySetInnerHTML={{ __html: htmlString }}></p>
49
- }
50
-
51
- export default Highlight