@growgroup/visual-editor 0.1.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 (219) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +52 -0
  3. package/README.md +143 -0
  4. package/dist/editor.css +2 -0
  5. package/package.json +94 -0
  6. package/src/components/DeckSlideRender.tsx +21 -0
  7. package/src/components/SaveNote.tsx +21 -0
  8. package/src/components/auth/AuthProvider.tsx +44 -0
  9. package/src/components/ui/accordion.tsx +57 -0
  10. package/src/components/ui/alert-dialog.tsx +141 -0
  11. package/src/components/ui/badge.tsx +36 -0
  12. package/src/components/ui/button.tsx +56 -0
  13. package/src/components/ui/card.tsx +76 -0
  14. package/src/components/ui/checkbox.tsx +30 -0
  15. package/src/components/ui/collapsible.tsx +11 -0
  16. package/src/components/ui/context-menu.tsx +200 -0
  17. package/src/components/ui/dialog.tsx +122 -0
  18. package/src/components/ui/dropdown-menu.tsx +201 -0
  19. package/src/components/ui/input.tsx +22 -0
  20. package/src/components/ui/label.tsx +26 -0
  21. package/src/components/ui/popover.tsx +33 -0
  22. package/src/components/ui/scroll-area.tsx +48 -0
  23. package/src/components/ui/scrubbable-label.tsx +95 -0
  24. package/src/components/ui/select.tsx +159 -0
  25. package/src/components/ui/separator.tsx +31 -0
  26. package/src/components/ui/slider.tsx +28 -0
  27. package/src/components/ui/switch.tsx +29 -0
  28. package/src/components/ui/tabs.tsx +55 -0
  29. package/src/components/ui/textarea.tsx +22 -0
  30. package/src/components/ui/tooltip.tsx +32 -0
  31. package/src/components/viewer/useDeck.ts +58 -0
  32. package/src/editor/EditorContext.tsx +632 -0
  33. package/src/editor/EditorToolbar.tsx +446 -0
  34. package/src/editor/FrontendVisualEditor.tsx +2595 -0
  35. package/src/editor/autosave.ts +34 -0
  36. package/src/editor/components/AiPromptPopover.tsx +378 -0
  37. package/src/editor/components/BreakpointGuides.tsx +323 -0
  38. package/src/editor/components/BreakpointSelector.tsx +180 -0
  39. package/src/editor/components/ComponentPropertyEditor.tsx +426 -0
  40. package/src/editor/components/CssEditorDialog.tsx +168 -0
  41. package/src/editor/components/EditorCanvas.tsx +987 -0
  42. package/src/editor/components/EditorContextMenu.tsx +515 -0
  43. package/src/editor/components/EditorFooter.tsx +81 -0
  44. package/src/editor/components/EditorHeader.tsx +524 -0
  45. package/src/editor/components/EditorLayerPanel.tsx +1197 -0
  46. package/src/editor/components/EditorPropertyPanel.tsx +2996 -0
  47. package/src/editor/components/EditorSidebar.tsx +226 -0
  48. package/src/editor/components/FigmaColorPicker.tsx +1577 -0
  49. package/src/editor/components/HtmlEditorDialog.tsx +71 -0
  50. package/src/editor/components/HtmlImportDialog.tsx +346 -0
  51. package/src/editor/components/JsEditorDialog.tsx +175 -0
  52. package/src/editor/components/LayerTreeItem.tsx +494 -0
  53. package/src/editor/components/MasterComponentEditor.tsx +846 -0
  54. package/src/editor/components/MediaLibraryDialog.tsx +447 -0
  55. package/src/editor/components/PageSettingsDialog.tsx +776 -0
  56. package/src/editor/components/VariablePicker.tsx +355 -0
  57. package/src/editor/components/VariablesDialog.tsx +564 -0
  58. package/src/editor/components/VariantEditor.tsx +687 -0
  59. package/src/editor/components/VariantMatrix.tsx +507 -0
  60. package/src/editor/components/component-panel/CategoryAccordion.tsx +139 -0
  61. package/src/editor/components/component-panel/ComponentGrid.tsx +51 -0
  62. package/src/editor/components/component-panel/ComponentItem.tsx +368 -0
  63. package/src/editor/components/component-panel/ComponentPanel.tsx +275 -0
  64. package/src/editor/components/component-panel/ComponentSearch.tsx +82 -0
  65. package/src/editor/components/component-panel/VariantList.tsx +260 -0
  66. package/src/editor/components/component-panel/index.ts +12 -0
  67. package/src/editor/components/index.ts +48 -0
  68. package/src/editor/components/multi-page/CanvasZoomControls.tsx +71 -0
  69. package/src/editor/components/multi-page/InfiniteCanvas.tsx +95 -0
  70. package/src/editor/components/multi-page/MultiPageCanvasView.tsx +1404 -0
  71. package/src/editor/components/multi-page/PageFrameOverlay.tsx +76 -0
  72. package/src/editor/components/multi-page/PageLabel.tsx +34 -0
  73. package/src/editor/components/multi-page/PageLivePreview.tsx +242 -0
  74. package/src/editor/components/multi-page/PageThumbnail.tsx +59 -0
  75. package/src/editor/components/multi-page/index.ts +7 -0
  76. package/src/editor/components/ppt/PptChrome.tsx +2508 -0
  77. package/src/editor/components/ppt/PptComments.tsx +589 -0
  78. package/src/editor/components/ppt/PptDesignProposals.tsx +275 -0
  79. package/src/editor/components/ppt/PptFormatPane.tsx +320 -0
  80. package/src/editor/components/ppt/PptNotes.tsx +246 -0
  81. package/src/editor/components/property-panel/AlignmentPanel.tsx +110 -0
  82. package/src/editor/components/property-panel/AutoLayoutPanel.tsx +615 -0
  83. package/src/editor/components/property-panel/BorderSection.tsx +104 -0
  84. package/src/editor/components/property-panel/CompactNumberInput.tsx +237 -0
  85. package/src/editor/components/property-panel/CompactSizeInput.tsx +148 -0
  86. package/src/editor/components/property-panel/EffectSection.tsx +157 -0
  87. package/src/editor/components/property-panel/FillSection.tsx +69 -0
  88. package/src/editor/components/property-panel/GoogleFontPicker.tsx +192 -0
  89. package/src/editor/components/property-panel/ImageSection.tsx +206 -0
  90. package/src/editor/components/property-panel/ImgSrcSection.tsx +125 -0
  91. package/src/editor/components/property-panel/InstanceOverrideSection.tsx +413 -0
  92. package/src/editor/components/property-panel/LayoutSection.tsx +105 -0
  93. package/src/editor/components/property-panel/LinkSection.tsx +103 -0
  94. package/src/editor/components/property-panel/PropertyVariablePicker.tsx +311 -0
  95. package/src/editor/components/property-panel/ScalePanel.tsx +212 -0
  96. package/src/editor/components/property-panel/TypographySection.tsx +230 -0
  97. package/src/editor/components/property-panel/UnitAwareNumberInput.tsx +238 -0
  98. package/src/editor/components/property-panel/VariableAwareColorInput.tsx +477 -0
  99. package/src/editor/components/property-panel/VariableAwareInput.tsx +606 -0
  100. package/src/editor/components/property-panel/VariableAwareSizeInput.tsx +588 -0
  101. package/src/editor/components/property-panel/VariableAwareUnitInput.tsx +546 -0
  102. package/src/editor/components/property-panel/index.ts +24 -0
  103. package/src/editor/components/property-panel/unit-utils.ts +261 -0
  104. package/src/editor/components/shell/EditorTopBar.tsx +392 -0
  105. package/src/editor/components/shell/LeftPanel.tsx +47 -0
  106. package/src/editor/components/shell/PagesPanel.tsx +118 -0
  107. package/src/editor/components/variables-panel/ColorValueCell.tsx +165 -0
  108. package/src/editor/components/variables-panel/TextValueCell.tsx +116 -0
  109. package/src/editor/components/variables-panel/VariablesPanel.tsx +518 -0
  110. package/src/editor/components/variables-panel/index.ts +7 -0
  111. package/src/editor/constants.ts +468 -0
  112. package/src/editor/contexts/EditorArtboardContext.tsx +229 -0
  113. package/src/editor/contexts/EditorComponentsContext.tsx +1320 -0
  114. package/src/editor/contexts/EditorDocumentContext.tsx +113 -0
  115. package/src/editor/contexts/EditorHistoryContext.tsx +516 -0
  116. package/src/editor/contexts/EditorRefsContext.tsx +204 -0
  117. package/src/editor/contexts/EditorSelectionContext.tsx +54 -0
  118. package/src/editor/contexts/EditorToolContext.tsx +58 -0
  119. package/src/editor/contexts/EditorUIStateContext.tsx +122 -0
  120. package/src/editor/contexts/EditorVariablesContext.tsx +397 -0
  121. package/src/editor/contexts/EditorViewContext.tsx +101 -0
  122. package/src/editor/contexts/MultiPageCanvasContext.tsx +498 -0
  123. package/src/editor/contexts/index.ts +17 -0
  124. package/src/editor/editor-skin.css +122 -0
  125. package/src/editor/hooks/index.ts +38 -0
  126. package/src/editor/hooks/useAiReplace.ts +397 -0
  127. package/src/editor/hooks/useAltMeasure.ts +67 -0
  128. package/src/editor/hooks/useBrowserZoomPrevention.ts +121 -0
  129. package/src/editor/hooks/useCanvasControls.ts +1222 -0
  130. package/src/editor/hooks/useComponentEditMode.ts +658 -0
  131. package/src/editor/hooks/useComponentInstances.ts +515 -0
  132. package/src/editor/hooks/useContextMenuHandler.ts +157 -0
  133. package/src/editor/hooks/useCoordinateTransform.ts +207 -0
  134. package/src/editor/hooks/useDragResize.ts +1317 -0
  135. package/src/editor/hooks/useDrawingMode.ts +472 -0
  136. package/src/editor/hooks/useEditorColors.ts +144 -0
  137. package/src/editor/hooks/useEditorMessages.ts +108 -0
  138. package/src/editor/hooks/useElementActions.ts +1754 -0
  139. package/src/editor/hooks/useElementSelection.ts +1573 -0
  140. package/src/editor/hooks/useFocusManagement.ts +249 -0
  141. package/src/editor/hooks/useGoogleFonts.ts +305 -0
  142. package/src/editor/hooks/useIframeInitializer.ts +584 -0
  143. package/src/editor/hooks/useIframeSetup.ts +360 -0
  144. package/src/editor/hooks/useImageUpload.ts +270 -0
  145. package/src/editor/hooks/useInfiniteCanvas.ts +301 -0
  146. package/src/editor/hooks/useKeyboardShortcuts.ts +205 -0
  147. package/src/editor/hooks/useMarqueeSelection.ts +388 -0
  148. package/src/editor/hooks/useMediaLibrary.ts +129 -0
  149. package/src/editor/hooks/usePageSettingsManager.ts +739 -0
  150. package/src/editor/hooks/useResizablePanel.ts +163 -0
  151. package/src/editor/hooks/useRichPaste.ts +255 -0
  152. package/src/editor/hooks/useTouchGestures.ts +197 -0
  153. package/src/editor/index.ts +27 -0
  154. package/src/editor/types/page-settings.ts +513 -0
  155. package/src/editor/types.ts +382 -0
  156. package/src/editor/utils/align-elements.ts +169 -0
  157. package/src/editor/utils/api-json.ts +21 -0
  158. package/src/editor/utils/aspect-lock.ts +50 -0
  159. package/src/editor/utils/component-renderer.ts +702 -0
  160. package/src/editor/utils/component-sync.ts +845 -0
  161. package/src/editor/utils/crop-mode.ts +265 -0
  162. package/src/editor/utils/dom-utils.ts +2238 -0
  163. package/src/editor/utils/element-effects.ts +218 -0
  164. package/src/editor/utils/eyedropper.ts +35 -0
  165. package/src/editor/utils/figma-export.ts +560 -0
  166. package/src/editor/utils/figma-kiwi-decoder.ts +722 -0
  167. package/src/editor/utils/figma-kiwi-encoder.ts +583 -0
  168. package/src/editor/utils/figma-paste.ts +2262 -0
  169. package/src/editor/utils/flex-reorder.ts +231 -0
  170. package/src/editor/utils/flex-utils.ts +1230 -0
  171. package/src/editor/utils/geometry.ts +232 -0
  172. package/src/editor/utils/grid-layout.ts +210 -0
  173. package/src/editor/utils/html-utils.ts +470 -0
  174. package/src/editor/utils/index.ts +11 -0
  175. package/src/editor/utils/ink-style.ts +57 -0
  176. package/src/editor/utils/inline-format.ts +236 -0
  177. package/src/editor/utils/measure-distance.ts +120 -0
  178. package/src/editor/utils/override-apply.ts +526 -0
  179. package/src/editor/utils/override-detection.ts +613 -0
  180. package/src/editor/utils/paste-processors.ts +609 -0
  181. package/src/editor/utils/paste-sanitizer.ts +244 -0
  182. package/src/editor/utils/restore-flow.ts +188 -0
  183. package/src/editor/utils/shape-library.ts +171 -0
  184. package/src/editor/utils/slide-root.ts +29 -0
  185. package/src/editor/utils/smart-guides.ts +218 -0
  186. package/src/editor/utils/style-utils.ts +685 -0
  187. package/src/editor/utils/table-edit.ts +151 -0
  188. package/src/editor/utils/tailwind-mappings.ts +778 -0
  189. package/src/editor/utils/tailwind-utils.ts +804 -0
  190. package/src/editor/utils/text-highlight.ts +216 -0
  191. package/src/editor/utils/theme-to-variables.ts +341 -0
  192. package/src/editor/utils/variant-resolver.ts +456 -0
  193. package/src/editor/utils/viewport-utils.ts +295 -0
  194. package/src/hooks/useEditorHistory.ts +195 -0
  195. package/src/hooks/useEditorShortcuts.ts +260 -0
  196. package/src/index.ts +40 -0
  197. package/src/io.ts +134 -0
  198. package/src/lib/agent/slide-agent/types.ts +547 -0
  199. package/src/lib/agent/website-agent/types.ts +805 -0
  200. package/src/lib/api/auth-fetch.ts +58 -0
  201. package/src/lib/deck.ts +69 -0
  202. package/src/lib/export.ts +47 -0
  203. package/src/lib/firebase/config.ts +29 -0
  204. package/src/lib/firebase/css-variables.ts +378 -0
  205. package/src/lib/firebase/editor-components.ts +677 -0
  206. package/src/lib/firebase/storage.ts +469 -0
  207. package/src/lib/utils.ts +6 -0
  208. package/src/styles/editor.css +52 -0
  209. package/src/styles/skin.css +122 -0
  210. package/src/types/css-variables.ts +645 -0
  211. package/src/types/editor-components.ts +944 -0
  212. package/src/types/editor.ts +420 -0
  213. package/src/types/page-master.ts +197 -0
  214. package/src/types/page.ts +419 -0
  215. package/src/types/slide.ts +402 -0
  216. package/src/types/website-theme.ts +788 -0
  217. package/src/types/website.ts +374 -0
  218. package/src/vendor/firebase-firestore.ts +13 -0
  219. package/src/vendor/firebase-functions.ts +17 -0
@@ -0,0 +1,355 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * CSS変数選択ポップオーバー
5
+ * プロパティパネルから変数を選択・適用するためのUI
6
+ */
7
+
8
+ import { useState, useMemo, useCallback } from 'react';
9
+ import {
10
+ Popover,
11
+ PopoverContent,
12
+ PopoverTrigger,
13
+ } from '../../components/ui/popover';
14
+ import { Button } from '../../components/ui/button';
15
+ import { Input } from '../../components/ui/input';
16
+ import { ScrollArea } from '../../components/ui/scroll-area';
17
+ import {
18
+ Link2,
19
+ Link2Off,
20
+ Search,
21
+ Palette,
22
+ Ruler,
23
+ Type,
24
+ Square,
25
+ Layers,
26
+ Settings,
27
+ type LucideIcon,
28
+ } from 'lucide-react';
29
+ import { cn } from '../../lib/utils';
30
+ import type {
31
+ CSSVariableDefinition,
32
+ CSSVariableCategory,
33
+ CSSVariableGroup,
34
+ } from '../../types/css-variables';
35
+ import { CSS_VARIABLE_CATEGORIES, generateVarReference } from '../../types/css-variables';
36
+
37
+ // ============================================
38
+ // アイコンマッピング
39
+ // ============================================
40
+
41
+ const CATEGORY_ICONS: Record<string, LucideIcon> = {
42
+ Palette,
43
+ Ruler,
44
+ Type,
45
+ Square,
46
+ Layers,
47
+ Settings,
48
+ };
49
+
50
+ function getCategoryIcon(iconName: string): LucideIcon {
51
+ return CATEGORY_ICONS[iconName] ?? Settings;
52
+ }
53
+
54
+ // ============================================
55
+ // 型定義
56
+ // ============================================
57
+
58
+ interface VariablePickerProps {
59
+ /** 利用可能な変数リスト */
60
+ variables: CSSVariableDefinition[];
61
+ /** カテゴリでグループ化された変数 */
62
+ variableGroups: CSSVariableGroup[];
63
+ /** フィルタするカテゴリ(nullで全て表示) */
64
+ filterCategory?: CSSVariableCategory | null;
65
+ /** 現在の値(var(--xxx)形式の場合、リンク済みと判定) */
66
+ currentValue?: string;
67
+ /** 変数選択時のコールバック */
68
+ onSelectVariable: (variable: CSSVariableDefinition) => void;
69
+ /** リンク解除時のコールバック */
70
+ onUnlink?: () => void;
71
+ /** トリガーボタンのカスタムスタイル */
72
+ triggerClassName?: string;
73
+ /** ポップオーバーの配置 */
74
+ side?: 'top' | 'right' | 'bottom' | 'left';
75
+ /** ポップオーバーの整列 */
76
+ align?: 'start' | 'center' | 'end';
77
+ /** 無効状態 */
78
+ disabled?: boolean;
79
+ }
80
+
81
+ // ============================================
82
+ // 変数アイテム
83
+ // ============================================
84
+
85
+ interface VariableItemProps {
86
+ variable: CSSVariableDefinition;
87
+ isSelected: boolean;
88
+ onClick: () => void;
89
+ }
90
+
91
+ function VariableItem({ variable, isSelected, onClick }: VariableItemProps) {
92
+ return (
93
+ <button
94
+ type="button"
95
+ className={cn(
96
+ 'w-full flex items-center gap-2 px-2 py-1.5 text-left rounded-md text-sm',
97
+ 'hover:bg-gray-100 transition-colors',
98
+ isSelected && 'bg-blue-50 text-blue-700'
99
+ )}
100
+ onClick={onClick}
101
+ >
102
+ {/* カラープレビュー */}
103
+ {variable.category === 'color' ? (
104
+ <div
105
+ className="w-4 h-4 rounded border shadow-sm flex-shrink-0"
106
+ style={{ backgroundColor: variable.value }}
107
+ />
108
+ ) : (
109
+ <div className="w-4 h-4 rounded border bg-gray-100 flex items-center justify-center flex-shrink-0">
110
+ <span className="text-[6px] text-gray-500 font-mono">
111
+ {variable.value.slice(0, 2)}
112
+ </span>
113
+ </div>
114
+ )}
115
+
116
+ {/* 変数情報 */}
117
+ <div className="flex-1 min-w-0">
118
+ <span className="font-mono text-xs truncate block">{variable.name}</span>
119
+ </div>
120
+
121
+ {/* 値 */}
122
+ <span className="text-xs text-gray-400 font-mono truncate max-w-[80px]">
123
+ {variable.value}
124
+ </span>
125
+ </button>
126
+ );
127
+ }
128
+
129
+ // ============================================
130
+ // カテゴリグループ
131
+ // ============================================
132
+
133
+ interface CategoryGroupProps {
134
+ group: CSSVariableGroup;
135
+ selectedCssName: string | null;
136
+ onSelectVariable: (variable: CSSVariableDefinition) => void;
137
+ }
138
+
139
+ function CategoryGroup({ group, selectedCssName, onSelectVariable }: CategoryGroupProps) {
140
+ const config = CSS_VARIABLE_CATEGORIES.find(c => c.id === group.category);
141
+ const Icon = getCategoryIcon(config?.icon ?? 'Settings');
142
+
143
+ if (group.variables.length === 0) return null;
144
+
145
+ return (
146
+ <div className="space-y-1">
147
+ <div className="flex items-center gap-1.5 px-2 py-1 text-xs text-gray-500">
148
+ <Icon className="w-3 h-3" />
149
+ <span>{config?.label ?? group.category}</span>
150
+ </div>
151
+ <div className="space-y-0.5">
152
+ {group.variables.map(variable => (
153
+ <VariableItem
154
+ key={variable.id}
155
+ variable={variable}
156
+ isSelected={variable.cssName === selectedCssName}
157
+ onClick={() => onSelectVariable(variable)}
158
+ />
159
+ ))}
160
+ </div>
161
+ </div>
162
+ );
163
+ }
164
+
165
+ // ============================================
166
+ // メインコンポーネント
167
+ // ============================================
168
+
169
+ export function VariablePicker({
170
+ variables,
171
+ variableGroups,
172
+ filterCategory,
173
+ currentValue,
174
+ onSelectVariable,
175
+ onUnlink,
176
+ triggerClassName,
177
+ side = 'left',
178
+ align = 'start',
179
+ disabled = false,
180
+ }: VariablePickerProps) {
181
+ const [open, setOpen] = useState(false);
182
+ const [searchQuery, setSearchQuery] = useState('');
183
+
184
+ // 現在リンクされている変数を検出
185
+ const linkedVariable = useMemo(() => {
186
+ if (!currentValue) return null;
187
+ const match = currentValue.match(/^var\((--[a-z0-9-]+)\)$/i);
188
+ if (!match) return null;
189
+ return variables.find(v => v.cssName === match[1]) ?? null;
190
+ }, [currentValue, variables]);
191
+
192
+ const isLinked = linkedVariable !== null;
193
+
194
+ // フィルタされた変数グループ
195
+ const filteredGroups = useMemo(() => {
196
+ let groups = variableGroups;
197
+
198
+ // カテゴリフィルタ
199
+ if (filterCategory) {
200
+ groups = groups.filter(g => g.category === filterCategory);
201
+ }
202
+
203
+ // 検索フィルタ
204
+ if (searchQuery.trim()) {
205
+ const query = searchQuery.toLowerCase();
206
+ groups = groups.map(g => ({
207
+ ...g,
208
+ variables: g.variables.filter(v =>
209
+ v.name.toLowerCase().includes(query) ||
210
+ v.cssName.toLowerCase().includes(query) ||
211
+ v.value.toLowerCase().includes(query)
212
+ ),
213
+ })).filter(g => g.variables.length > 0);
214
+ }
215
+
216
+ return groups;
217
+ }, [variableGroups, filterCategory, searchQuery]);
218
+
219
+ // 変数選択ハンドラ
220
+ const handleSelect = useCallback((variable: CSSVariableDefinition) => {
221
+ onSelectVariable(variable);
222
+ setOpen(false);
223
+ setSearchQuery('');
224
+ }, [onSelectVariable]);
225
+
226
+ // リンク解除ハンドラ
227
+ const handleUnlink = useCallback(() => {
228
+ onUnlink?.();
229
+ setOpen(false);
230
+ }, [onUnlink]);
231
+
232
+ // 変数が0件の場合のUI
233
+ const isEmpty = variables.length === 0;
234
+ const noResults = filteredGroups.every(g => g.variables.length === 0);
235
+
236
+ return (
237
+ <Popover open={open} onOpenChange={setOpen}>
238
+ <PopoverTrigger asChild>
239
+ <Button
240
+ variant="ghost"
241
+ size="icon"
242
+ className={cn(
243
+ 'h-7 w-7',
244
+ isLinked
245
+ ? 'text-blue-500 hover:text-blue-600 bg-blue-50 hover:bg-blue-100'
246
+ : 'text-gray-400 hover:text-gray-600 hover:bg-gray-100',
247
+ triggerClassName
248
+ )}
249
+ disabled={disabled || isEmpty}
250
+ title={isLinked ? `リンク: ${linkedVariable?.cssName}` : '変数をリンク'}
251
+ >
252
+ {isLinked ? (
253
+ <Link2 className="h-3.5 w-3.5" />
254
+ ) : (
255
+ <Link2 className="h-3.5 w-3.5" />
256
+ )}
257
+ </Button>
258
+ </PopoverTrigger>
259
+
260
+ <PopoverContent
261
+ className="w-64 p-0"
262
+ side={side}
263
+ align={align}
264
+ >
265
+ <div className="p-2 border-b">
266
+ <div className="relative">
267
+ <Search className="absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-gray-400" />
268
+ <Input
269
+ value={searchQuery}
270
+ onChange={(e) => setSearchQuery(e.target.value)}
271
+ placeholder="変数を検索..."
272
+ className="h-8 pl-7 text-sm"
273
+ autoFocus
274
+ />
275
+ </div>
276
+ </div>
277
+
278
+ <ScrollArea className="h-[240px]">
279
+ <div className="p-2 space-y-3">
280
+ {noResults ? (
281
+ <div className="text-center py-8 text-sm text-gray-500">
282
+ {searchQuery ? '検索結果がありません' : '変数がありません'}
283
+ </div>
284
+ ) : (
285
+ filteredGroups.map(group => (
286
+ <CategoryGroup
287
+ key={group.category}
288
+ group={group}
289
+ selectedCssName={linkedVariable?.cssName ?? null}
290
+ onSelectVariable={handleSelect}
291
+ />
292
+ ))
293
+ )}
294
+ </div>
295
+ </ScrollArea>
296
+
297
+ {/* リンク解除ボタン */}
298
+ {isLinked && onUnlink && (
299
+ <div className="p-2 border-t">
300
+ <Button
301
+ variant="outline"
302
+ size="sm"
303
+ className="w-full text-red-600 hover:text-red-700 hover:bg-red-50"
304
+ onClick={handleUnlink}
305
+ >
306
+ <Link2Off className="h-3.5 w-3.5 mr-1.5" />
307
+ リンクを解除
308
+ </Button>
309
+ </div>
310
+ )}
311
+ </PopoverContent>
312
+ </Popover>
313
+ );
314
+ }
315
+
316
+ // ============================================
317
+ // シンプルなリンクボタン(インライン用)
318
+ // ============================================
319
+
320
+ interface VariableLinkButtonProps {
321
+ isLinked: boolean;
322
+ linkedVariableName?: string;
323
+ onClick: () => void;
324
+ disabled?: boolean;
325
+ className?: string;
326
+ }
327
+
328
+ export function VariableLinkButton({
329
+ isLinked,
330
+ linkedVariableName,
331
+ onClick,
332
+ disabled = false,
333
+ className,
334
+ }: VariableLinkButtonProps) {
335
+ return (
336
+ <Button
337
+ variant="ghost"
338
+ size="icon"
339
+ className={cn(
340
+ 'h-7 w-7',
341
+ isLinked
342
+ ? 'text-blue-500 hover:text-blue-600 bg-blue-50 hover:bg-blue-100'
343
+ : 'text-gray-400 hover:text-gray-600 hover:bg-gray-100',
344
+ className
345
+ )}
346
+ disabled={disabled}
347
+ onClick={onClick}
348
+ title={isLinked ? `リンク: ${linkedVariableName}` : '変数をリンク'}
349
+ >
350
+ <Link2 className="h-3.5 w-3.5" />
351
+ </Button>
352
+ );
353
+ }
354
+
355
+ export default VariablePicker;