@wzyjs/uis 0.3.9 → 0.3.16

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 (45) hide show
  1. package/package.json +2 -2
  2. package/src/antd/form/FileUploader/index.tsx +163 -0
  3. package/src/antd/form/RadioButton/index.tsx +3 -1
  4. package/src/antd/form/index.ts +1 -0
  5. package/src/antd/index.ts +2 -0
  6. package/src/components/Crud/components/CardList/index.tsx +174 -0
  7. package/src/components/Crud/components/CreateUpdate/index.tsx +99 -0
  8. package/src/components/Crud/components/Provider/index.tsx +73 -0
  9. package/src/components/Crud/components/Remove/index.tsx +56 -0
  10. package/src/components/Crud/components/index.ts +4 -0
  11. package/src/components/Crud/hooks/index.ts +4 -0
  12. package/src/components/Crud/hooks/useColumns.tsx +169 -0
  13. package/src/components/Crud/hooks/useList.ts +54 -0
  14. package/src/components/Crud/hooks/useOrderable.tsx +107 -0
  15. package/src/components/Crud/hooks/useRequest.ts +41 -0
  16. package/src/components/Crud/index.tsx +91 -0
  17. package/src/components/Crud/types/index.ts +188 -0
  18. package/src/components/Crud/utils/index.ts +87 -0
  19. package/src/components/MindMap/context.tsx +29 -0
  20. package/src/components/MindMap/hooks/useAlignmentSnap.ts +220 -0
  21. package/src/components/MindMap/hooks/useCopyPaste.ts +272 -0
  22. package/src/components/MindMap/hooks/useDropToReparent.ts +288 -0
  23. package/src/components/MindMap/hooks/useExpandCollapse.ts +146 -0
  24. package/src/components/MindMap/hooks/useMoveDescendants.ts +136 -0
  25. package/src/components/MindMap/hooks/useUndoRedo.ts +232 -0
  26. package/src/components/MindMap/index.tsx +117 -0
  27. package/src/components/ProgressButton/index.module.scss +65 -0
  28. package/src/components/ProgressButton/index.tsx +96 -0
  29. package/src/components/TimelineBar/components/CurrentWeekHighlight/index.tsx +64 -0
  30. package/src/components/TimelineBar/components/Guides/index.tsx +61 -0
  31. package/src/components/TimelineBar/components/Ticks/index.tsx +56 -0
  32. package/src/components/TimelineBar/components/TodayIndicator/index.tsx +54 -0
  33. package/src/components/TimelineBar/components/index.ts +4 -0
  34. package/src/components/TimelineBar/const.ts +3 -0
  35. package/src/components/TimelineBar/hooks/index.ts +5 -0
  36. package/src/components/TimelineBar/hooks/useHighlightRange.ts +21 -0
  37. package/src/components/TimelineBar/hooks/useMonthGuides.ts +40 -0
  38. package/src/components/TimelineBar/hooks/useTickValues.ts +18 -0
  39. package/src/components/TimelineBar/hooks/useVisibleRange.ts +43 -0
  40. package/src/components/TimelineBar/hooks/useWeekGuides.ts +39 -0
  41. package/src/components/TimelineBar/index.tsx +63 -0
  42. package/src/components/TimelineBar/utils.ts +27 -0
  43. package/src/components/index.ts +4 -0
  44. package/src/rn.ts +1 -0
  45. package/src/rns/index.ts +0 -0
@@ -0,0 +1,54 @@
1
+ import React from 'react'
2
+ import type { ReactElement } from 'react'
3
+
4
+ import { dayjs } from '@/utils'
5
+ import { calcOffsetByTime } from '../../utils'
6
+
7
+ interface TodayIndicatorProps {
8
+ originTime: number
9
+ timePxPerDay: number
10
+ }
11
+
12
+ export const TodayIndicator = (props: TodayIndicatorProps): ReactElement | null => {
13
+ const { originTime, timePxPerDay } = props
14
+
15
+ const offset = calcOffsetByTime({
16
+ originTime,
17
+ timePxPerDay,
18
+ time: dayjs().startOf('day').valueOf(),
19
+ })
20
+
21
+ return (
22
+ <>
23
+ <div
24
+ style={{
25
+ position: 'absolute',
26
+ top: 1,
27
+ left: offset + (timePxPerDay - 30) / 2,
28
+ width: 30,
29
+ fontSize: 8,
30
+ lineHeight: '12px',
31
+ textAlign: 'center',
32
+ borderRadius: 999,
33
+ background: '#0ea5e9',
34
+ color: '#fff',
35
+ whiteSpace: 'nowrap',
36
+ pointerEvents: 'none',
37
+ }}
38
+ >
39
+ 今天
40
+ </div>
41
+ <div
42
+ style={{
43
+ position: 'absolute',
44
+ left: offset + (timePxPerDay - 7) / 2,
45
+ bottom: 0,
46
+ borderLeft: '4px solid transparent',
47
+ borderRight: '4px solid transparent',
48
+ borderBottom: '7px solid #0ea5e9',
49
+ pointerEvents: 'none',
50
+ }}
51
+ />
52
+ </>
53
+ )
54
+ }
@@ -0,0 +1,4 @@
1
+ export * from './Ticks'
2
+ export * from './Guides'
3
+ export * from './TodayIndicator'
4
+ export * from './CurrentWeekHighlight'
@@ -0,0 +1,3 @@
1
+ export const HEIGHT = 50
2
+ export const ONE_DAY_MS = 24 * 60 * 60 * 1000
3
+ export const WEEKDAY_LABELS = ['日', '一', '二', '三', '四', '五', '六']
@@ -0,0 +1,5 @@
1
+ export * from './useTickValues'
2
+ export * from './useVisibleRange'
3
+ export * from './useMonthGuides'
4
+ export * from './useWeekGuides'
5
+ export * from './useHighlightRange'
@@ -0,0 +1,21 @@
1
+ import { calcOffsetByTime } from '../utils'
2
+
3
+ interface HighlightRangeOption {
4
+ originTime: number
5
+ startTime: number
6
+ endTime: number
7
+ timePxPerDay: number
8
+ }
9
+
10
+ export const useHighlightRange = (option: HighlightRangeOption) => {
11
+ const { originTime, startTime, endTime, timePxPerDay } = option
12
+
13
+ const start = calcOffsetByTime({ originTime, time: startTime, timePxPerDay })
14
+ const end = calcOffsetByTime({ originTime, time: endTime, timePxPerDay })
15
+
16
+ const safeLeft = start
17
+ const safeRight = Math.max(safeLeft, end)
18
+ const safeWidth = Math.max(0, safeRight - safeLeft)
19
+
20
+ return { left: safeLeft, width: safeWidth }
21
+ }
@@ -0,0 +1,40 @@
1
+ import { dayjs } from '@/utils'
2
+ import { calcOffsetByTime } from '../utils'
3
+
4
+ interface GuideLine {
5
+ key: string
6
+ offset: number
7
+ }
8
+
9
+ interface MonthGuidesOption {
10
+ originTime: number
11
+ visibleDates: Date[]
12
+ timePxPerDay: number
13
+ }
14
+
15
+ export const useMonthGuides = (option: MonthGuidesOption): GuideLine[] => {
16
+ const { originTime, visibleDates, timePxPerDay } = option
17
+
18
+ if (!visibleDates.length) {
19
+ return []
20
+ }
21
+
22
+ const result: GuideLine[] = []
23
+
24
+ for (const date of visibleDates) {
25
+ const d = dayjs(date)
26
+ if (d.date() !== 1) {
27
+ continue
28
+ }
29
+
30
+ const time: number = d.startOf('month').startOf('day').valueOf()
31
+ const offset = calcOffsetByTime({ originTime, time, timePxPerDay })
32
+
33
+ result.push({
34
+ key: `${d.format('YYYY-MM')}-start`,
35
+ offset,
36
+ })
37
+ }
38
+
39
+ return result
40
+ }
@@ -0,0 +1,18 @@
1
+ import { dayjs } from '@/utils'
2
+
3
+ interface TickValuesOption {
4
+ visibleStart: number
5
+ visibleEnd: number
6
+ }
7
+
8
+ export const useTickValues = (option: TickValuesOption) => {
9
+ const { visibleStart, visibleEnd } = option
10
+
11
+ const start = dayjs(visibleStart).startOf('day')
12
+ const end = dayjs(visibleEnd).endOf('day')
13
+ const days = end.diff(start, 'day') + 1
14
+
15
+ return Array.from({ length: days }).map((_, i: number) => (
16
+ start.add(i, 'day').toDate()
17
+ ))
18
+ }
@@ -0,0 +1,43 @@
1
+ import { useTickValues } from '../hooks'
2
+ import { calcTimeByScreenOffset } from '.././utils'
3
+
4
+ interface VisibleRangeOption {
5
+ x: number
6
+ originTime: number
7
+ containerWidth: number
8
+ timePxPerDay: number
9
+ minTime?: number
10
+ maxTime?: number
11
+ }
12
+
13
+ export const useVisibleRange = (option: VisibleRangeOption) => {
14
+ const { x, originTime, containerWidth, timePxPerDay, minTime, maxTime } = option
15
+
16
+ const lower: number = typeof minTime === 'number' ? minTime : Number.NEGATIVE_INFINITY
17
+ const upper: number = typeof maxTime === 'number' ? maxTime : Number.POSITIVE_INFINITY
18
+ const safeLower: number = Math.min(lower, upper)
19
+ const safeUpper: number = Math.max(lower, upper)
20
+
21
+ const rawVisibleStart: number = calcTimeByScreenOffset({ screenOffset: 0, x, originTime, timePxPerDay })
22
+ const rawVisibleEnd: number = calcTimeByScreenOffset({ screenOffset: containerWidth, x, originTime, timePxPerDay })
23
+
24
+ const visibleStart: number = Math.min(
25
+ safeUpper,
26
+ Math.max(safeLower, Math.min(rawVisibleStart, rawVisibleEnd)),
27
+ )
28
+ const visibleEnd: number = Math.max(
29
+ visibleStart,
30
+ Math.min(safeUpper, Math.max(safeLower, Math.max(rawVisibleStart, rawVisibleEnd))),
31
+ )
32
+
33
+ const visibleDates = useTickValues({
34
+ visibleStart,
35
+ visibleEnd,
36
+ })
37
+
38
+ return {
39
+ visibleStart,
40
+ visibleEnd,
41
+ visibleDates,
42
+ }
43
+ }
@@ -0,0 +1,39 @@
1
+ import { dayjs } from '@/utils'
2
+ import { calcOffsetByTime } from '../utils'
3
+
4
+ interface GuideLine {
5
+ key: string
6
+ offset: number
7
+ }
8
+
9
+ interface WeekGuidesOption {
10
+ originTime: number
11
+ visibleDates: Date[]
12
+ timePxPerDay: number
13
+ }
14
+
15
+ export const useWeekGuides = (option: WeekGuidesOption): GuideLine[] => {
16
+ const { originTime, visibleDates, timePxPerDay } = option
17
+
18
+ if (!visibleDates.length) {
19
+ return []
20
+ }
21
+
22
+ const result: GuideLine[] = []
23
+
24
+ for (const date of visibleDates) {
25
+ const d = dayjs(date)
26
+ if (d.day() !== 1) {
27
+ continue
28
+ }
29
+
30
+ const time: number = d.startOf('day').valueOf()
31
+ const offset = calcOffsetByTime({ originTime, time, timePxPerDay })
32
+ result.push({
33
+ key: d.format('YYYY-MM-DD'),
34
+ offset,
35
+ })
36
+ }
37
+
38
+ return result
39
+ }
@@ -0,0 +1,63 @@
1
+ import { Ticks, Guides, TodayIndicator, CurrentWeekHighlight } from './components'
2
+
3
+ import { useElement } from '@/hooks'
4
+ import { useVisibleRange } from './hooks'
5
+
6
+ import { HEIGHT } from './const'
7
+
8
+ interface TimelineBarProps {
9
+ x?: number
10
+ minTime?: number
11
+ maxTime?: number
12
+ originTime: number
13
+ timePxPerDay?: number
14
+ }
15
+
16
+ export const TimelineBar = (props: TimelineBarProps) => {
17
+ const { originTime, x = 0, timePxPerDay = 30, minTime, maxTime } = props
18
+
19
+ const { elementRef, elementStyles } = useElement()
20
+
21
+ const { visibleDates } = useVisibleRange({
22
+ x,
23
+ originTime,
24
+ minTime,
25
+ maxTime,
26
+ timePxPerDay,
27
+ containerWidth: Number(elementStyles?.width),
28
+ })
29
+
30
+ return (
31
+ <div ref={elementRef} className='w-full border-b border-gray-200 bg-white/90 backdrop-blur overflow-hidden'>
32
+ <div
33
+ style={{
34
+ transform: `translateX(${x}px)`,
35
+ height: HEIGHT,
36
+ width: elementStyles?.width
37
+ }}
38
+ >
39
+ <Ticks
40
+ originTime={originTime}
41
+ timePxPerDay={timePxPerDay}
42
+ visibleDates={visibleDates}
43
+ />
44
+
45
+ <TodayIndicator
46
+ originTime={originTime}
47
+ timePxPerDay={timePxPerDay}
48
+ />
49
+
50
+ <Guides
51
+ originTime={originTime}
52
+ timePxPerDay={timePxPerDay}
53
+ visibleDates={visibleDates}
54
+ />
55
+
56
+ <CurrentWeekHighlight
57
+ originTime={originTime}
58
+ timePxPerDay={timePxPerDay}
59
+ />
60
+ </div>
61
+ </div>
62
+ )
63
+ }
@@ -0,0 +1,27 @@
1
+ import { ONE_DAY_MS } from './const'
2
+
3
+ interface ScreenOffsetOption {
4
+ x: number
5
+ screenOffset: number
6
+ originTime: number
7
+ timePxPerDay: number
8
+ }
9
+
10
+ export const calcTimeByScreenOffset = (option: ScreenOffsetOption): number => {
11
+ const { screenOffset, x, originTime, timePxPerDay } = option
12
+ const center = screenOffset - x
13
+ const diffDays = center / timePxPerDay
14
+ return originTime + diffDays * ONE_DAY_MS
15
+ }
16
+
17
+ interface TimeToOffsetOption {
18
+ time: number
19
+ originTime: number
20
+ timePxPerDay: number
21
+ }
22
+
23
+ export const calcOffsetByTime = (option: TimeToOffsetOption): number => {
24
+ const { originTime, time, timePxPerDay } = option
25
+ const diffDays = (time - originTime) / ONE_DAY_MS
26
+ return diffDays * timePxPerDay
27
+ }
@@ -16,6 +16,10 @@ export * from './Markdown'
16
16
  export * from './DynamicSelect'
17
17
  export * from './JsonRenderer'
18
18
  export * from './EnumTag'
19
+ export * from './MindMap'
20
+ export * from './ProgressButton'
21
+ export * from './TimelineBar'
22
+ export * from './Crud'
19
23
 
20
24
  // export * from './JsonView'
21
25
 
package/src/rn.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './rns';
File without changes