@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.
- package/LICENSE +21 -0
- package/NOTICE +52 -0
- package/README.md +143 -0
- package/dist/editor.css +2 -0
- package/package.json +94 -0
- package/src/components/DeckSlideRender.tsx +21 -0
- package/src/components/SaveNote.tsx +21 -0
- package/src/components/auth/AuthProvider.tsx +44 -0
- package/src/components/ui/accordion.tsx +57 -0
- package/src/components/ui/alert-dialog.tsx +141 -0
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/button.tsx +56 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/collapsible.tsx +11 -0
- package/src/components/ui/context-menu.tsx +200 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/scrubbable-label.tsx +95 -0
- package/src/components/ui/select.tsx +159 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/slider.tsx +28 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/components/viewer/useDeck.ts +58 -0
- package/src/editor/EditorContext.tsx +632 -0
- package/src/editor/EditorToolbar.tsx +446 -0
- package/src/editor/FrontendVisualEditor.tsx +2595 -0
- package/src/editor/autosave.ts +34 -0
- package/src/editor/components/AiPromptPopover.tsx +378 -0
- package/src/editor/components/BreakpointGuides.tsx +323 -0
- package/src/editor/components/BreakpointSelector.tsx +180 -0
- package/src/editor/components/ComponentPropertyEditor.tsx +426 -0
- package/src/editor/components/CssEditorDialog.tsx +168 -0
- package/src/editor/components/EditorCanvas.tsx +987 -0
- package/src/editor/components/EditorContextMenu.tsx +515 -0
- package/src/editor/components/EditorFooter.tsx +81 -0
- package/src/editor/components/EditorHeader.tsx +524 -0
- package/src/editor/components/EditorLayerPanel.tsx +1197 -0
- package/src/editor/components/EditorPropertyPanel.tsx +2996 -0
- package/src/editor/components/EditorSidebar.tsx +226 -0
- package/src/editor/components/FigmaColorPicker.tsx +1577 -0
- package/src/editor/components/HtmlEditorDialog.tsx +71 -0
- package/src/editor/components/HtmlImportDialog.tsx +346 -0
- package/src/editor/components/JsEditorDialog.tsx +175 -0
- package/src/editor/components/LayerTreeItem.tsx +494 -0
- package/src/editor/components/MasterComponentEditor.tsx +846 -0
- package/src/editor/components/MediaLibraryDialog.tsx +447 -0
- package/src/editor/components/PageSettingsDialog.tsx +776 -0
- package/src/editor/components/VariablePicker.tsx +355 -0
- package/src/editor/components/VariablesDialog.tsx +564 -0
- package/src/editor/components/VariantEditor.tsx +687 -0
- package/src/editor/components/VariantMatrix.tsx +507 -0
- package/src/editor/components/component-panel/CategoryAccordion.tsx +139 -0
- package/src/editor/components/component-panel/ComponentGrid.tsx +51 -0
- package/src/editor/components/component-panel/ComponentItem.tsx +368 -0
- package/src/editor/components/component-panel/ComponentPanel.tsx +275 -0
- package/src/editor/components/component-panel/ComponentSearch.tsx +82 -0
- package/src/editor/components/component-panel/VariantList.tsx +260 -0
- package/src/editor/components/component-panel/index.ts +12 -0
- package/src/editor/components/index.ts +48 -0
- package/src/editor/components/multi-page/CanvasZoomControls.tsx +71 -0
- package/src/editor/components/multi-page/InfiniteCanvas.tsx +95 -0
- package/src/editor/components/multi-page/MultiPageCanvasView.tsx +1404 -0
- package/src/editor/components/multi-page/PageFrameOverlay.tsx +76 -0
- package/src/editor/components/multi-page/PageLabel.tsx +34 -0
- package/src/editor/components/multi-page/PageLivePreview.tsx +242 -0
- package/src/editor/components/multi-page/PageThumbnail.tsx +59 -0
- package/src/editor/components/multi-page/index.ts +7 -0
- package/src/editor/components/ppt/PptChrome.tsx +2508 -0
- package/src/editor/components/ppt/PptComments.tsx +589 -0
- package/src/editor/components/ppt/PptDesignProposals.tsx +275 -0
- package/src/editor/components/ppt/PptFormatPane.tsx +320 -0
- package/src/editor/components/ppt/PptNotes.tsx +246 -0
- package/src/editor/components/property-panel/AlignmentPanel.tsx +110 -0
- package/src/editor/components/property-panel/AutoLayoutPanel.tsx +615 -0
- package/src/editor/components/property-panel/BorderSection.tsx +104 -0
- package/src/editor/components/property-panel/CompactNumberInput.tsx +237 -0
- package/src/editor/components/property-panel/CompactSizeInput.tsx +148 -0
- package/src/editor/components/property-panel/EffectSection.tsx +157 -0
- package/src/editor/components/property-panel/FillSection.tsx +69 -0
- package/src/editor/components/property-panel/GoogleFontPicker.tsx +192 -0
- package/src/editor/components/property-panel/ImageSection.tsx +206 -0
- package/src/editor/components/property-panel/ImgSrcSection.tsx +125 -0
- package/src/editor/components/property-panel/InstanceOverrideSection.tsx +413 -0
- package/src/editor/components/property-panel/LayoutSection.tsx +105 -0
- package/src/editor/components/property-panel/LinkSection.tsx +103 -0
- package/src/editor/components/property-panel/PropertyVariablePicker.tsx +311 -0
- package/src/editor/components/property-panel/ScalePanel.tsx +212 -0
- package/src/editor/components/property-panel/TypographySection.tsx +230 -0
- package/src/editor/components/property-panel/UnitAwareNumberInput.tsx +238 -0
- package/src/editor/components/property-panel/VariableAwareColorInput.tsx +477 -0
- package/src/editor/components/property-panel/VariableAwareInput.tsx +606 -0
- package/src/editor/components/property-panel/VariableAwareSizeInput.tsx +588 -0
- package/src/editor/components/property-panel/VariableAwareUnitInput.tsx +546 -0
- package/src/editor/components/property-panel/index.ts +24 -0
- package/src/editor/components/property-panel/unit-utils.ts +261 -0
- package/src/editor/components/shell/EditorTopBar.tsx +392 -0
- package/src/editor/components/shell/LeftPanel.tsx +47 -0
- package/src/editor/components/shell/PagesPanel.tsx +118 -0
- package/src/editor/components/variables-panel/ColorValueCell.tsx +165 -0
- package/src/editor/components/variables-panel/TextValueCell.tsx +116 -0
- package/src/editor/components/variables-panel/VariablesPanel.tsx +518 -0
- package/src/editor/components/variables-panel/index.ts +7 -0
- package/src/editor/constants.ts +468 -0
- package/src/editor/contexts/EditorArtboardContext.tsx +229 -0
- package/src/editor/contexts/EditorComponentsContext.tsx +1320 -0
- package/src/editor/contexts/EditorDocumentContext.tsx +113 -0
- package/src/editor/contexts/EditorHistoryContext.tsx +516 -0
- package/src/editor/contexts/EditorRefsContext.tsx +204 -0
- package/src/editor/contexts/EditorSelectionContext.tsx +54 -0
- package/src/editor/contexts/EditorToolContext.tsx +58 -0
- package/src/editor/contexts/EditorUIStateContext.tsx +122 -0
- package/src/editor/contexts/EditorVariablesContext.tsx +397 -0
- package/src/editor/contexts/EditorViewContext.tsx +101 -0
- package/src/editor/contexts/MultiPageCanvasContext.tsx +498 -0
- package/src/editor/contexts/index.ts +17 -0
- package/src/editor/editor-skin.css +122 -0
- package/src/editor/hooks/index.ts +38 -0
- package/src/editor/hooks/useAiReplace.ts +397 -0
- package/src/editor/hooks/useAltMeasure.ts +67 -0
- package/src/editor/hooks/useBrowserZoomPrevention.ts +121 -0
- package/src/editor/hooks/useCanvasControls.ts +1222 -0
- package/src/editor/hooks/useComponentEditMode.ts +658 -0
- package/src/editor/hooks/useComponentInstances.ts +515 -0
- package/src/editor/hooks/useContextMenuHandler.ts +157 -0
- package/src/editor/hooks/useCoordinateTransform.ts +207 -0
- package/src/editor/hooks/useDragResize.ts +1317 -0
- package/src/editor/hooks/useDrawingMode.ts +472 -0
- package/src/editor/hooks/useEditorColors.ts +144 -0
- package/src/editor/hooks/useEditorMessages.ts +108 -0
- package/src/editor/hooks/useElementActions.ts +1754 -0
- package/src/editor/hooks/useElementSelection.ts +1573 -0
- package/src/editor/hooks/useFocusManagement.ts +249 -0
- package/src/editor/hooks/useGoogleFonts.ts +305 -0
- package/src/editor/hooks/useIframeInitializer.ts +584 -0
- package/src/editor/hooks/useIframeSetup.ts +360 -0
- package/src/editor/hooks/useImageUpload.ts +270 -0
- package/src/editor/hooks/useInfiniteCanvas.ts +301 -0
- package/src/editor/hooks/useKeyboardShortcuts.ts +205 -0
- package/src/editor/hooks/useMarqueeSelection.ts +388 -0
- package/src/editor/hooks/useMediaLibrary.ts +129 -0
- package/src/editor/hooks/usePageSettingsManager.ts +739 -0
- package/src/editor/hooks/useResizablePanel.ts +163 -0
- package/src/editor/hooks/useRichPaste.ts +255 -0
- package/src/editor/hooks/useTouchGestures.ts +197 -0
- package/src/editor/index.ts +27 -0
- package/src/editor/types/page-settings.ts +513 -0
- package/src/editor/types.ts +382 -0
- package/src/editor/utils/align-elements.ts +169 -0
- package/src/editor/utils/api-json.ts +21 -0
- package/src/editor/utils/aspect-lock.ts +50 -0
- package/src/editor/utils/component-renderer.ts +702 -0
- package/src/editor/utils/component-sync.ts +845 -0
- package/src/editor/utils/crop-mode.ts +265 -0
- package/src/editor/utils/dom-utils.ts +2238 -0
- package/src/editor/utils/element-effects.ts +218 -0
- package/src/editor/utils/eyedropper.ts +35 -0
- package/src/editor/utils/figma-export.ts +560 -0
- package/src/editor/utils/figma-kiwi-decoder.ts +722 -0
- package/src/editor/utils/figma-kiwi-encoder.ts +583 -0
- package/src/editor/utils/figma-paste.ts +2262 -0
- package/src/editor/utils/flex-reorder.ts +231 -0
- package/src/editor/utils/flex-utils.ts +1230 -0
- package/src/editor/utils/geometry.ts +232 -0
- package/src/editor/utils/grid-layout.ts +210 -0
- package/src/editor/utils/html-utils.ts +470 -0
- package/src/editor/utils/index.ts +11 -0
- package/src/editor/utils/ink-style.ts +57 -0
- package/src/editor/utils/inline-format.ts +236 -0
- package/src/editor/utils/measure-distance.ts +120 -0
- package/src/editor/utils/override-apply.ts +526 -0
- package/src/editor/utils/override-detection.ts +613 -0
- package/src/editor/utils/paste-processors.ts +609 -0
- package/src/editor/utils/paste-sanitizer.ts +244 -0
- package/src/editor/utils/restore-flow.ts +188 -0
- package/src/editor/utils/shape-library.ts +171 -0
- package/src/editor/utils/slide-root.ts +29 -0
- package/src/editor/utils/smart-guides.ts +218 -0
- package/src/editor/utils/style-utils.ts +685 -0
- package/src/editor/utils/table-edit.ts +151 -0
- package/src/editor/utils/tailwind-mappings.ts +778 -0
- package/src/editor/utils/tailwind-utils.ts +804 -0
- package/src/editor/utils/text-highlight.ts +216 -0
- package/src/editor/utils/theme-to-variables.ts +341 -0
- package/src/editor/utils/variant-resolver.ts +456 -0
- package/src/editor/utils/viewport-utils.ts +295 -0
- package/src/hooks/useEditorHistory.ts +195 -0
- package/src/hooks/useEditorShortcuts.ts +260 -0
- package/src/index.ts +40 -0
- package/src/io.ts +134 -0
- package/src/lib/agent/slide-agent/types.ts +547 -0
- package/src/lib/agent/website-agent/types.ts +805 -0
- package/src/lib/api/auth-fetch.ts +58 -0
- package/src/lib/deck.ts +69 -0
- package/src/lib/export.ts +47 -0
- package/src/lib/firebase/config.ts +29 -0
- package/src/lib/firebase/css-variables.ts +378 -0
- package/src/lib/firebase/editor-components.ts +677 -0
- package/src/lib/firebase/storage.ts +469 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/editor.css +52 -0
- package/src/styles/skin.css +122 -0
- package/src/types/css-variables.ts +645 -0
- package/src/types/editor-components.ts +944 -0
- package/src/types/editor.ts +420 -0
- package/src/types/page-master.ts +197 -0
- package/src/types/page.ts +419 -0
- package/src/types/slide.ts +402 -0
- package/src/types/website-theme.ts +788 -0
- package/src/types/website.ts +374 -0
- package/src/vendor/firebase-firestore.ts +13 -0
- 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;
|