@dinachi/cli 0.12.0 → 1.0.0

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 (46) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/dist/index.js +73 -7
  3. package/package.json +1 -1
  4. package/templates/accordion/accordion.tsx +66 -12
  5. package/templates/agent/agent.tsx +1865 -0
  6. package/templates/agent/index.ts +52 -0
  7. package/templates/alert-dialog/alert-dialog.tsx +46 -17
  8. package/templates/alert-dialog/index.ts +2 -0
  9. package/templates/animated-tabs/animated-tabs.tsx +65 -5
  10. package/templates/autocomplete/autocomplete.tsx +174 -18
  11. package/templates/carousel/carousel.tsx +102 -24
  12. package/templates/checkbox/checkbox.tsx +60 -4
  13. package/templates/checkbox-group/checkbox-group.tsx +82 -8
  14. package/templates/collapsible/collapsible.tsx +13 -4
  15. package/templates/combobox/combobox.tsx +297 -23
  16. package/templates/compare-slider/compare-slider.tsx +103 -28
  17. package/templates/compare-slider/index.ts +1 -1
  18. package/templates/context-menu/context-menu.tsx +37 -15
  19. package/templates/dialog/dialog.tsx +41 -12
  20. package/templates/drawer/drawer.tsx +18 -3
  21. package/templates/expandable-card/expandable-card.tsx +65 -42
  22. package/templates/field/field.tsx +2 -0
  23. package/templates/hold-to-confirm/hold-to-confirm.tsx +99 -16
  24. package/templates/hold-to-confirm/index.ts +1 -1
  25. package/templates/input/input.tsx +59 -1
  26. package/templates/menu/menu.tsx +26 -9
  27. package/templates/menubar/menubar.tsx +26 -8
  28. package/templates/navigation-menu/navigation-menu.tsx +67 -23
  29. package/templates/number-field/index.ts +1 -0
  30. package/templates/number-field/number-field.tsx +71 -2
  31. package/templates/otp-field/otp-field.tsx +57 -11
  32. package/templates/popover/popover.tsx +18 -3
  33. package/templates/preview-card/preview-card.tsx +16 -2
  34. package/templates/radio/radio.tsx +71 -6
  35. package/templates/select/select.tsx +223 -10
  36. package/templates/slider/slider.tsx +77 -8
  37. package/templates/sortable/sortable.tsx +76 -9
  38. package/templates/swipeable-row/index.ts +1 -1
  39. package/templates/swipeable-row/swipeable-row.tsx +125 -41
  40. package/templates/switch/switch.tsx +41 -4
  41. package/templates/tabs/tabs.tsx +74 -10
  42. package/templates/textarea/index.ts +1 -1
  43. package/templates/textarea/textarea.tsx +70 -4
  44. package/templates/toast/toast.tsx +3 -1
  45. package/templates/toggle/toggle.tsx +39 -7
  46. package/templates/toggle-group/toggle-group.tsx +96 -18
@@ -5,6 +5,33 @@ import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group
5
5
  import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
6
6
  import { cva } from "class-variance-authority"
7
7
  import { cn } from "@/lib/utils"
8
+ import {
9
+ agentChoicesOf,
10
+ changeAsAgent,
11
+ matchAgentChoice,
12
+ sameAgentValue,
13
+ useAgentControl,
14
+ useAgentItem,
15
+ useAgentState,
16
+ useHasAgent,
17
+ useMergedRef,
18
+ type AgentChoice,
19
+ type AgentItems,
20
+ } from "@/components/ui/agent"
21
+
22
+ type ToggleItems = AgentItems<string>
23
+
24
+ const ToggleAgentContext = React.createContext<ToggleItems | null>(null)
25
+
26
+ function matchAll(choices: AgentChoice[], wanted: unknown): string[] | string {
27
+ const values: string[] = []
28
+ for (const one of Array.isArray(wanted) ? wanted : [wanted]) {
29
+ const match = matchAgentChoice(choices, one)
30
+ if (typeof match === "string") return match
31
+ values.push(match.value as string)
32
+ }
33
+ return values
34
+ }
8
35
 
9
36
  type ToggleGroupItemProps = React.ComponentPropsWithoutRef<typeof TogglePrimitive> & {
10
37
  variant?: "default" | "outline"
@@ -43,29 +70,80 @@ const toggleGroupItemVariants = cva(
43
70
  const ToggleGroup = React.forwardRef<
44
71
  React.ComponentRef<typeof ToggleGroupPrimitive>,
45
72
  React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive>
46
- >(({ className, ...props }, ref) => (
47
- <ToggleGroupPrimitive
48
- ref={ref}
49
- className={cn(
50
- "inline-flex items-center justify-center gap-1",
51
- "data-[orientation=vertical]:flex-col",
52
- className
53
- )}
54
- {...props}
55
- />
56
- ))
73
+ >(({ className, value: valueProp, defaultValue, onValueChange, ...props }, ref) => {
74
+ const [value, change] = useAgentState<readonly string[], ToggleGroupPrimitive.ChangeEventDetails>(
75
+ valueProp,
76
+ defaultValue ?? [],
77
+ onValueChange as ((value: readonly string[], details: ToggleGroupPrimitive.ChangeEventDetails) => void) | undefined
78
+ )
79
+ const element = React.useRef<HTMLDivElement | null>(null)
80
+ const mergedRef = useMergedRef(ref, element)
81
+ const [items] = React.useState<ToggleItems>(() => new Map())
82
+
83
+ const pick = (wanted: unknown, add: boolean) => {
84
+ const values = matchAll(agentChoicesOf(items), wanted)
85
+ if (typeof values === "string") return values
86
+ const fresh = values.filter((v) => !value.some((w) => sameAgentValue(v, w)))
87
+ if (!fresh.length && (add || values.length === value.length)) return undefined
88
+ return changeAsAgent(change, add ? [...value, ...fresh] : values)
89
+ }
90
+
91
+ const add = (wanted: unknown) => pick(wanted, true)
92
+ const replace = (wanted: unknown) => pick(wanted, false)
93
+ const actions: Record<string, typeof add> = props.multiple ? { select: add, setValue: replace } : { select: replace }
94
+
95
+ useAgentControl(() => {
96
+ const choices = agentChoicesOf(items)
97
+ const labels = value.map((v) => choices.find((c) => sameAgentValue(c.value, v))?.label ?? String(v))
98
+ return {
99
+ kind: "toggle-group",
100
+ element: choices.length ? element.current : null,
101
+ value: props.multiple ? labels : (labels[0] ?? ""),
102
+ items: choices.map((c) => c.label),
103
+ multiple: props.multiple || undefined,
104
+ disabled: props.disabled,
105
+ actions,
106
+ }
107
+ })
108
+
109
+ return (
110
+ <ToggleAgentContext.Provider value={useHasAgent() ? items : null}>
111
+ <ToggleGroupPrimitive
112
+ ref={mergedRef}
113
+ className={cn(
114
+ "inline-flex items-center justify-center gap-1",
115
+ "data-[orientation=vertical]:flex-col",
116
+ className
117
+ )}
118
+ {...props}
119
+ value={value}
120
+ onValueChange={change}
121
+ />
122
+ </ToggleAgentContext.Provider>
123
+ )
124
+ })
57
125
  ToggleGroup.displayName = "ToggleGroup"
58
126
 
59
127
  const ToggleGroupItem = React.forwardRef<
60
128
  React.ComponentRef<typeof TogglePrimitive>,
61
129
  ToggleGroupItemProps
62
- >(({ className, variant = "outline", size = "sm", ...props }, ref) => (
63
- <TogglePrimitive
64
- ref={ref}
65
- className={cn(toggleGroupItemVariants({ variant, size }), className)}
66
- {...props}
67
- />
68
- ))
130
+ >(({ className, variant = "outline", size = "sm", ...props }, ref) => {
131
+ const items = React.useContext(ToggleAgentContext)
132
+ const element = React.useRef<HTMLButtonElement | null>(null)
133
+ const mergedRef = useMergedRef(ref, element)
134
+ useAgentItem(items, element, props.value as string | undefined)
135
+
136
+ // Inside AgentProvider the group reports its items, so the buttons stay out of the
137
+ // snapshot rather than appearing twice.
138
+ return (
139
+ <TogglePrimitive
140
+ ref={mergedRef}
141
+ data-agent-part={items ? "" : undefined}
142
+ className={cn(toggleGroupItemVariants({ variant, size }), className)}
143
+ {...props}
144
+ />
145
+ )
146
+ })
69
147
  ToggleGroupItem.displayName = "ToggleGroupItem"
70
148
 
71
149
  export { ToggleGroup, ToggleGroupItem }