@coze-arch/cli 0.0.1-alpha.de5a13 → 0.0.1-alpha.deaedf
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/README.md +1 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/client/components/Screen.tsx +2 -2
- package/lib/__templates__/expo/client/eslint.config.mjs +7 -0
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +10 -10
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +8 -5
- package/lib/__templates__/expo/server/package.json +1 -1
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/.babelrc +3 -0
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +1 -2
- package/lib/__templates__/nextjs/package.json +3 -6
- package/lib/__templates__/nextjs/pnpm-lock.yaml +1036 -10
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +8 -2
- package/lib/__templates__/nextjs/scripts/start.sh +7 -1
- package/lib/__templates__/nextjs/src/app/layout.tsx +1 -1
- package/lib/__templates__/nextjs/src/app/page.tsx +1 -2
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/tsconfig.json +1 -1
- package/lib/__templates__/nuxt-vue/.coze +12 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/_npmrc +23 -0
- package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
- package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
- package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
- package/lib/__templates__/nuxt-vue/package.json +35 -0
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
- package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
- package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
- package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
- package/lib/__templates__/nuxt-vue/template.config.js +87 -0
- package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +107 -37
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
- package/lib/__templates__/taro/README.md +138 -62
- package/lib/__templates__/taro/config/index.ts +105 -41
- package/lib/__templates__/taro/config/prod.ts +4 -5
- package/lib/__templates__/taro/eslint.config.mjs +82 -4
- package/lib/__templates__/taro/package.json +23 -7
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +1198 -214
- package/lib/__templates__/taro/server/package.json +3 -1
- package/lib/__templates__/taro/src/app.css +140 -47
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
- package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
- package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
- package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
- package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
- package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
- package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
- package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
- package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
- package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
- package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
- package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
- package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
- package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
- package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
- package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
- package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
- package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
- package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
- package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
- package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
- package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
- package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
- package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
- package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
- package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
- package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
- package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
- package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
- package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
- package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
- package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
- package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
- package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
- package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
- package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
- package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
- package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
- package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
- package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
- package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
- package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
- package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
- package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
- package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
- package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
- package/lib/__templates__/taro/src/lib/measure.ts +115 -0
- package/lib/__templates__/taro/src/lib/platform.ts +12 -0
- package/lib/__templates__/taro/src/lib/utils.ts +6 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +238 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/templates.json +43 -0
- package/lib/__templates__/vite/README.md +190 -11
- package/lib/__templates__/vite/_gitignore +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +6 -1
- package/lib/__templates__/vite/package.json +14 -5
- package/lib/__templates__/vite/pnpm-lock.yaml +768 -24
- package/lib/__templates__/vite/scripts/build.sh +4 -1
- package/lib/__templates__/vite/scripts/dev.sh +9 -2
- package/lib/__templates__/vite/scripts/start.sh +9 -3
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +65 -0
- package/lib/__templates__/vite/server/vite.ts +67 -0
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +5 -0
- package/lib/cli.js +124 -103
- package/package.json +7 -3
- package/lib/__templates__/taro/src/app.ts +0 -14
- package/lib/__templates__/taro/src/utils/h5-styles.ts +0 -22
- package/lib/__templates__/taro/src/utils/wx-debug.ts +0 -23
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { View } from "@tarojs/components"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const Progress = React.forwardRef<
|
|
7
|
+
React.ElementRef<typeof View>,
|
|
8
|
+
React.ComponentPropsWithoutRef<typeof View> & {
|
|
9
|
+
value?: number | null
|
|
10
|
+
}
|
|
11
|
+
>(({ className, value, ...props }, ref) => (
|
|
12
|
+
<View
|
|
13
|
+
ref={ref}
|
|
14
|
+
className={cn(
|
|
15
|
+
"relative h-1 w-full overflow-hidden rounded-full bg-secondary",
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
>
|
|
20
|
+
<View
|
|
21
|
+
className="h-full w-full flex-1 bg-primary transition-all"
|
|
22
|
+
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
|
23
|
+
/>
|
|
24
|
+
</View>
|
|
25
|
+
))
|
|
26
|
+
Progress.displayName = "Progress"
|
|
27
|
+
|
|
28
|
+
export { Progress }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { View } from "@tarojs/components"
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const RadioGroupContext = React.createContext<{
|
|
6
|
+
value?: string
|
|
7
|
+
onValueChange?: (value: string) => void
|
|
8
|
+
} | null>(null)
|
|
9
|
+
|
|
10
|
+
const RadioGroup = React.forwardRef<
|
|
11
|
+
React.ElementRef<typeof View>,
|
|
12
|
+
React.ComponentPropsWithoutRef<typeof View> & {
|
|
13
|
+
value?: string
|
|
14
|
+
onValueChange?: (value: string) => void
|
|
15
|
+
defaultValue?: string
|
|
16
|
+
}
|
|
17
|
+
>(({ className, value: valueProp, defaultValue, onValueChange, ...props }, ref) => {
|
|
18
|
+
const [valueState, setValueState] = React.useState<string | undefined>(defaultValue)
|
|
19
|
+
const value = valueProp !== undefined ? valueProp : valueState
|
|
20
|
+
|
|
21
|
+
const handleValueChange = (newValue: string) => {
|
|
22
|
+
if (valueProp === undefined) {
|
|
23
|
+
setValueState(newValue)
|
|
24
|
+
}
|
|
25
|
+
onValueChange?.(newValue)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<RadioGroupContext.Provider value={{ value, onValueChange: handleValueChange }}>
|
|
30
|
+
<View
|
|
31
|
+
className={cn("grid gap-2", className)}
|
|
32
|
+
{...props}
|
|
33
|
+
ref={ref}
|
|
34
|
+
/>
|
|
35
|
+
</RadioGroupContext.Provider>
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
RadioGroup.displayName = "RadioGroup"
|
|
39
|
+
|
|
40
|
+
const RadioGroupItem = React.forwardRef<
|
|
41
|
+
React.ElementRef<typeof View>,
|
|
42
|
+
React.ComponentPropsWithoutRef<typeof View> & {
|
|
43
|
+
value: string
|
|
44
|
+
}
|
|
45
|
+
>(({ className, value, ...props }, ref) => {
|
|
46
|
+
const context = React.useContext(RadioGroupContext)
|
|
47
|
+
const checked = context?.value === value
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<View
|
|
51
|
+
ref={ref}
|
|
52
|
+
className={cn(
|
|
53
|
+
"aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
54
|
+
checked && "border-10",
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
57
|
+
onClick={() => context?.onValueChange?.(value)}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
RadioGroupItem.displayName = "RadioGroupItem"
|
|
63
|
+
|
|
64
|
+
export { RadioGroup, RadioGroupItem }
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { View } from "@tarojs/components"
|
|
3
|
+
import Taro from "@tarojs/taro"
|
|
4
|
+
import { GripVertical } from "lucide-react-taro"
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
import { isH5 } from "@/lib/platform"
|
|
7
|
+
|
|
8
|
+
type Direction = "horizontal" | "vertical"
|
|
9
|
+
|
|
10
|
+
function getPoint(e: any) {
|
|
11
|
+
const touch = e?.touches?.[0] || e?.changedTouches?.[0]
|
|
12
|
+
return touch || e
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const clamp = (v: number, min: number, max: number) => Math.min(Math.max(v, min), max)
|
|
16
|
+
|
|
17
|
+
const ResizablePanelGroup = ({
|
|
18
|
+
className,
|
|
19
|
+
children,
|
|
20
|
+
direction = "horizontal",
|
|
21
|
+
...props
|
|
22
|
+
}: React.ComponentPropsWithoutRef<typeof View> & {
|
|
23
|
+
direction?: Direction
|
|
24
|
+
}) => {
|
|
25
|
+
const idRef = React.useRef(`resizable-${Math.random().toString(36).slice(2, 11)}`)
|
|
26
|
+
const groupRef = React.useRef<any>(null)
|
|
27
|
+
const sizesRef = React.useRef<number[] | null>(null)
|
|
28
|
+
const [sizes, setSizes] = React.useState<number[] | null>(null)
|
|
29
|
+
|
|
30
|
+
const rectSizeRef = React.useRef<{ width: number; height: number } | null>(null)
|
|
31
|
+
const dragRef = React.useRef<{
|
|
32
|
+
axis: "x" | "y"
|
|
33
|
+
input: "mouse" | "touch"
|
|
34
|
+
leftIndex: number
|
|
35
|
+
startPos: number
|
|
36
|
+
startSizes: number[]
|
|
37
|
+
containerSize: number
|
|
38
|
+
} | null>(null)
|
|
39
|
+
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
sizesRef.current = sizes
|
|
42
|
+
}, [sizes])
|
|
43
|
+
|
|
44
|
+
const isPanelElement = React.useCallback((child: any) => {
|
|
45
|
+
return child?.type?.displayName === "ResizablePanel"
|
|
46
|
+
}, [])
|
|
47
|
+
|
|
48
|
+
const isHandleElement = React.useCallback((child: any) => {
|
|
49
|
+
return child?.type?.displayName === "ResizableHandle"
|
|
50
|
+
}, [])
|
|
51
|
+
|
|
52
|
+
const panels = React.useMemo(() => {
|
|
53
|
+
const out: React.ReactElement[] = []
|
|
54
|
+
React.Children.forEach(children as any, (child) => {
|
|
55
|
+
if (!React.isValidElement(child)) return
|
|
56
|
+
if (isPanelElement(child)) out.push(child as any)
|
|
57
|
+
})
|
|
58
|
+
return out
|
|
59
|
+
}, [children, isPanelElement])
|
|
60
|
+
|
|
61
|
+
const measure = React.useCallback(() => {
|
|
62
|
+
const el = groupRef.current
|
|
63
|
+
if (isH5() && typeof el?.getBoundingClientRect === "function") {
|
|
64
|
+
const rect = el.getBoundingClientRect()
|
|
65
|
+
const width = rect?.width
|
|
66
|
+
const height = rect?.height
|
|
67
|
+
if (typeof width === "number" && typeof height === "number") {
|
|
68
|
+
rectSizeRef.current = { width, height }
|
|
69
|
+
return Promise.resolve(rectSizeRef.current)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new Promise<{ width: number; height: number } | null>((resolve) => {
|
|
74
|
+
const query = Taro.createSelectorQuery()
|
|
75
|
+
query
|
|
76
|
+
.select(`#${idRef.current}`)
|
|
77
|
+
.boundingClientRect((res) => {
|
|
78
|
+
const r = Array.isArray(res) ? res[0] : res
|
|
79
|
+
const width = r?.width
|
|
80
|
+
const height = r?.height
|
|
81
|
+
if (typeof width === "number" && typeof height === "number") {
|
|
82
|
+
rectSizeRef.current = { width, height }
|
|
83
|
+
resolve(rectSizeRef.current)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
resolve(null)
|
|
87
|
+
})
|
|
88
|
+
.exec()
|
|
89
|
+
})
|
|
90
|
+
}, [])
|
|
91
|
+
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
const defaults = panels.map((p) => {
|
|
94
|
+
const v = (p.props as any)?.defaultSize
|
|
95
|
+
return typeof v === "number" && Number.isFinite(v) ? v : null
|
|
96
|
+
})
|
|
97
|
+
const hasAnyDefault = defaults.some((v) => v != null)
|
|
98
|
+
const next =
|
|
99
|
+
hasAnyDefault
|
|
100
|
+
? defaults.map((v) => (v == null ? 0 : v))
|
|
101
|
+
: panels.map(() => 100 / Math.max(1, panels.length))
|
|
102
|
+
const total = next.reduce((a, b) => a + b, 0) || 1
|
|
103
|
+
const normalized = next.map((v) => (v / total) * 100)
|
|
104
|
+
|
|
105
|
+
setSizes((prev) => {
|
|
106
|
+
if (prev && prev.length === normalized.length) return prev
|
|
107
|
+
return normalized
|
|
108
|
+
})
|
|
109
|
+
}, [panels])
|
|
110
|
+
|
|
111
|
+
React.useEffect(() => {
|
|
112
|
+
void measure()
|
|
113
|
+
if (!isH5() || typeof window === "undefined") return
|
|
114
|
+
const onResize = () => void measure()
|
|
115
|
+
window.addEventListener("resize", onResize)
|
|
116
|
+
return () => window.removeEventListener("resize", onResize)
|
|
117
|
+
}, [measure])
|
|
118
|
+
|
|
119
|
+
const applyMove = React.useCallback(
|
|
120
|
+
(e: any) => {
|
|
121
|
+
const drag = dragRef.current
|
|
122
|
+
const currentSizes = sizesRef.current
|
|
123
|
+
if (!drag || !currentSizes) return
|
|
124
|
+
const p = getPoint(e)
|
|
125
|
+
const pos = drag.axis === "x" ? p?.pageX : p?.pageY
|
|
126
|
+
if (typeof pos !== "number") return
|
|
127
|
+
if (!drag.containerSize) return
|
|
128
|
+
|
|
129
|
+
const deltaPercent = ((pos - drag.startPos) / drag.containerSize) * 100
|
|
130
|
+
const left = drag.leftIndex
|
|
131
|
+
const right = left + 1
|
|
132
|
+
const total = drag.startSizes[left] + drag.startSizes[right]
|
|
133
|
+
const min = 10
|
|
134
|
+
const nextLeft = clamp(drag.startSizes[left] + deltaPercent, min, total - min)
|
|
135
|
+
const next = drag.startSizes.slice()
|
|
136
|
+
next[left] = nextLeft
|
|
137
|
+
next[right] = total - nextLeft
|
|
138
|
+
setSizes(next)
|
|
139
|
+
},
|
|
140
|
+
[]
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
const endDrag = React.useCallback(() => {
|
|
144
|
+
dragRef.current = null
|
|
145
|
+
if (!isH5() || typeof document === "undefined") return
|
|
146
|
+
document.removeEventListener("mousemove", onDocumentMouseMove as any)
|
|
147
|
+
document.removeEventListener("mouseup", onDocumentMouseUp as any)
|
|
148
|
+
document.removeEventListener("touchmove", onDocumentTouchMove as any, { passive: false } as any)
|
|
149
|
+
document.removeEventListener("touchend", onDocumentTouchEnd as any)
|
|
150
|
+
document.removeEventListener("touchcancel", onDocumentTouchEnd as any)
|
|
151
|
+
}, [])
|
|
152
|
+
|
|
153
|
+
const onDocumentMouseMove = React.useCallback((e: any) => applyMove(e), [applyMove])
|
|
154
|
+
const onDocumentMouseUp = React.useCallback(() => endDrag(), [endDrag])
|
|
155
|
+
const onDocumentTouchMove = React.useCallback(
|
|
156
|
+
(e: any) => {
|
|
157
|
+
const drag = dragRef.current
|
|
158
|
+
if (!drag || drag.input !== "touch") return
|
|
159
|
+
e?.preventDefault?.()
|
|
160
|
+
applyMove(e)
|
|
161
|
+
},
|
|
162
|
+
[applyMove]
|
|
163
|
+
)
|
|
164
|
+
const onDocumentTouchEnd = React.useCallback(() => endDrag(), [endDrag])
|
|
165
|
+
|
|
166
|
+
React.useEffect(() => {
|
|
167
|
+
return () => endDrag()
|
|
168
|
+
}, [endDrag])
|
|
169
|
+
|
|
170
|
+
const startDrag = React.useCallback(
|
|
171
|
+
async (leftIndex: number, e: any) => {
|
|
172
|
+
const currentSizes = sizesRef.current
|
|
173
|
+
if (!currentSizes) return
|
|
174
|
+
if (leftIndex < 0 || leftIndex >= currentSizes.length - 1) return
|
|
175
|
+
|
|
176
|
+
const axis = direction === "horizontal" ? "x" : "y"
|
|
177
|
+
const p = getPoint(e)
|
|
178
|
+
const pos = axis === "x" ? p?.pageX : p?.pageY
|
|
179
|
+
if (typeof pos !== "number") return
|
|
180
|
+
const input: "mouse" | "touch" = (e as any)?.touches?.length ? "touch" : "mouse"
|
|
181
|
+
|
|
182
|
+
const rect = rectSizeRef.current || (await measure())
|
|
183
|
+
const containerSize = axis === "x" ? rect?.width : rect?.height
|
|
184
|
+
if (!containerSize) return
|
|
185
|
+
|
|
186
|
+
dragRef.current = {
|
|
187
|
+
axis,
|
|
188
|
+
input,
|
|
189
|
+
leftIndex,
|
|
190
|
+
startPos: pos,
|
|
191
|
+
startSizes: currentSizes.slice(),
|
|
192
|
+
containerSize,
|
|
193
|
+
}
|
|
194
|
+
e?.preventDefault?.()
|
|
195
|
+
|
|
196
|
+
if (isH5() && typeof document !== "undefined") {
|
|
197
|
+
if (input === "mouse") {
|
|
198
|
+
document.addEventListener("mousemove", onDocumentMouseMove as any)
|
|
199
|
+
document.addEventListener("mouseup", onDocumentMouseUp as any)
|
|
200
|
+
} else {
|
|
201
|
+
document.addEventListener("touchmove", onDocumentTouchMove as any, { passive: false } as any)
|
|
202
|
+
document.addEventListener("touchend", onDocumentTouchEnd as any)
|
|
203
|
+
document.addEventListener("touchcancel", onDocumentTouchEnd as any)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
[
|
|
208
|
+
direction,
|
|
209
|
+
measure,
|
|
210
|
+
onDocumentMouseMove,
|
|
211
|
+
onDocumentMouseUp,
|
|
212
|
+
onDocumentTouchEnd,
|
|
213
|
+
onDocumentTouchMove,
|
|
214
|
+
]
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
const onGroupTouchMove = React.useCallback(
|
|
218
|
+
(e: any) => {
|
|
219
|
+
const drag = dragRef.current
|
|
220
|
+
if (!drag || drag.input !== "touch") return
|
|
221
|
+
e?.preventDefault?.()
|
|
222
|
+
applyMove(e)
|
|
223
|
+
},
|
|
224
|
+
[applyMove]
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
const onGroupTouchEnd = React.useCallback(() => endDrag(), [endDrag])
|
|
228
|
+
|
|
229
|
+
let panelIndex = 0
|
|
230
|
+
let handleIndex = 0
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<View
|
|
234
|
+
id={idRef.current}
|
|
235
|
+
ref={groupRef}
|
|
236
|
+
className={cn(
|
|
237
|
+
"flex h-full w-full items-stretch overflow-hidden",
|
|
238
|
+
direction === "vertical" ? "flex-col" : "flex-row",
|
|
239
|
+
className
|
|
240
|
+
)}
|
|
241
|
+
{...props}
|
|
242
|
+
onTouchMove={onGroupTouchMove}
|
|
243
|
+
onTouchEnd={onGroupTouchEnd}
|
|
244
|
+
onTouchCancel={onGroupTouchEnd as any}
|
|
245
|
+
>
|
|
246
|
+
{React.Children.map(children as any, (child) => {
|
|
247
|
+
if (!React.isValidElement(child)) return child
|
|
248
|
+
|
|
249
|
+
if (isPanelElement(child)) {
|
|
250
|
+
const size = sizes?.[panelIndex]
|
|
251
|
+
const cloned = React.cloneElement(child as any, {
|
|
252
|
+
__size: typeof size === "number" ? size : undefined,
|
|
253
|
+
__direction: direction,
|
|
254
|
+
})
|
|
255
|
+
panelIndex += 1
|
|
256
|
+
return cloned
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (isHandleElement(child)) {
|
|
260
|
+
const leftIndex = panelIndex - 1
|
|
261
|
+
const cursorClass =
|
|
262
|
+
direction === "horizontal" ? "cursor-col-resize" : "cursor-row-resize"
|
|
263
|
+
const cloned = React.cloneElement(child as any, {
|
|
264
|
+
__direction: direction,
|
|
265
|
+
className: cn(cursorClass, (child.props as any)?.className),
|
|
266
|
+
onTouchStart: (e: any) => void startDrag(leftIndex, e),
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
onMouseDown: (e: any) => void startDrag(leftIndex, e),
|
|
269
|
+
"data-handle-index": handleIndex,
|
|
270
|
+
})
|
|
271
|
+
handleIndex += 1
|
|
272
|
+
return cloned
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return child
|
|
276
|
+
})}
|
|
277
|
+
</View>
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const ResizablePanel = ({
|
|
282
|
+
className,
|
|
283
|
+
children,
|
|
284
|
+
defaultSize,
|
|
285
|
+
__size,
|
|
286
|
+
__direction,
|
|
287
|
+
...props
|
|
288
|
+
}: React.ComponentPropsWithoutRef<typeof View> & {
|
|
289
|
+
defaultSize?: number
|
|
290
|
+
__size?: number
|
|
291
|
+
__direction?: Direction
|
|
292
|
+
}) => (
|
|
293
|
+
<View
|
|
294
|
+
{...props}
|
|
295
|
+
className={cn("flex min-h-0 min-w-0 flex-col overflow-hidden", className)}
|
|
296
|
+
style={{
|
|
297
|
+
flexBasis: 0,
|
|
298
|
+
flexGrow: __size ?? defaultSize ?? 1,
|
|
299
|
+
flexShrink: 1,
|
|
300
|
+
minWidth: 0,
|
|
301
|
+
minHeight: 0,
|
|
302
|
+
...(props as any)?.style,
|
|
303
|
+
}}
|
|
304
|
+
>
|
|
305
|
+
{children}
|
|
306
|
+
</View>
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
const ResizableHandle = ({
|
|
310
|
+
withHandle,
|
|
311
|
+
className,
|
|
312
|
+
__direction,
|
|
313
|
+
...props
|
|
314
|
+
}: React.ComponentPropsWithoutRef<typeof View> & {
|
|
315
|
+
withHandle?: boolean
|
|
316
|
+
__direction?: Direction
|
|
317
|
+
}) => (
|
|
318
|
+
<View
|
|
319
|
+
{...props}
|
|
320
|
+
className={cn(
|
|
321
|
+
"relative flex shrink-0 items-center justify-center bg-transparent",
|
|
322
|
+
__direction === "vertical" ? "h-3 self-stretch" : "w-3 self-stretch",
|
|
323
|
+
className
|
|
324
|
+
)}
|
|
325
|
+
>
|
|
326
|
+
<View
|
|
327
|
+
className={cn(
|
|
328
|
+
"absolute bg-border",
|
|
329
|
+
__direction === "vertical"
|
|
330
|
+
? "inset-x-0 top-1/2 -translate-y-1/2"
|
|
331
|
+
: "inset-y-0 left-1/2 -translate-x-1/2"
|
|
332
|
+
)}
|
|
333
|
+
style={__direction === "vertical" ? { height: "1PX" } : { width: "1PX" }}
|
|
334
|
+
/>
|
|
335
|
+
{withHandle && (
|
|
336
|
+
<View className="z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border">
|
|
337
|
+
<GripVertical className="h-3 w-3" />
|
|
338
|
+
</View>
|
|
339
|
+
)}
|
|
340
|
+
</View>
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
;(ResizablePanel as any).displayName = "ResizablePanel"
|
|
344
|
+
;(ResizableHandle as any).displayName = "ResizableHandle"
|
|
345
|
+
|
|
346
|
+
export { ResizablePanelGroup, ResizablePanel, ResizableHandle }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { ScrollView } from "@tarojs/components"
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const ScrollArea = React.forwardRef<
|
|
6
|
+
React.ElementRef<typeof ScrollView>,
|
|
7
|
+
React.ComponentPropsWithoutRef<typeof ScrollView> & {
|
|
8
|
+
orientation?: "vertical" | "horizontal" | "both"
|
|
9
|
+
}
|
|
10
|
+
>(({ className, children, orientation = "vertical", ...props }, ref) => {
|
|
11
|
+
const scrollX = orientation === "horizontal" || orientation === "both"
|
|
12
|
+
const scrollY = orientation === "vertical" || orientation === "both"
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ScrollView
|
|
16
|
+
ref={ref}
|
|
17
|
+
className={cn("relative", className)}
|
|
18
|
+
scrollY={scrollY}
|
|
19
|
+
scrollX={scrollX}
|
|
20
|
+
style={{
|
|
21
|
+
overflowX: scrollX ? 'auto' : 'hidden',
|
|
22
|
+
overflowY: scrollY ? 'auto' : 'hidden',
|
|
23
|
+
}}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</ScrollView>
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
ScrollArea.displayName = "ScrollArea"
|
|
31
|
+
|
|
32
|
+
const ScrollBar = () => null // Taro ScrollView handles scrollbars natively
|
|
33
|
+
|
|
34
|
+
export { ScrollArea, ScrollBar }
|